@straiffi/archon 1.10.2 → 1.10.3

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 (72) hide show
  1. package/dist/client/assets/{ActivityView-CdDT5tgr.js → ActivityView-B00t5YvM.js} +1 -1
  2. package/dist/client/assets/{GitHubActionsDialog-NdYtgMhg.js → GitHubActionsDialog-DL1RASVT.js} +1 -1
  3. package/dist/client/assets/{VerificationDialog-BfIKtVjt.js → VerificationDialog-CYCrlqmj.js} +1 -1
  4. package/dist/client/assets/{architectureDiagram-3BPJPVTR-C4zoWnXM.js → architectureDiagram-3BPJPVTR-D154Ue77.js} +1 -1
  5. package/dist/client/assets/{blockDiagram-GPEHLZMM-ZhRwV8ma.js → blockDiagram-GPEHLZMM-Bczo8yL4.js} +1 -1
  6. package/dist/client/assets/{c4Diagram-AAUBKEIU-CA2USxCJ.js → c4Diagram-AAUBKEIU-DhNO2xdU.js} +1 -1
  7. package/dist/client/assets/channel-UfTuRVnD.js +1 -0
  8. package/dist/client/assets/{chunk-2J33WTMH-CY32Brnt.js → chunk-2J33WTMH-C-9oXMQh.js} +1 -1
  9. package/dist/client/assets/{chunk-3OPIFGDE-H70UH7rH.js → chunk-3OPIFGDE-C0WrA6dp.js} +1 -1
  10. package/dist/client/assets/{chunk-5ZQYHXKU-DC1dllSt.js → chunk-5ZQYHXKU-DJ6o7jkk.js} +1 -1
  11. package/dist/client/assets/{chunk-727SXJPM-DVIgI7hM.js → chunk-727SXJPM-MjJ8OutE.js} +1 -1
  12. package/dist/client/assets/{chunk-AQP2D5EJ-gwSYEPou.js → chunk-AQP2D5EJ-HYanGaMO.js} +1 -1
  13. package/dist/client/assets/{chunk-CSCIHK7Q-Z1cfABPc.js → chunk-CSCIHK7Q-CNZTo9o2.js} +1 -1
  14. package/dist/client/assets/{chunk-KSCS5N6A-DFoW6dtq.js → chunk-KSCS5N6A-Dz-GLjci.js} +1 -1
  15. package/dist/client/assets/{chunk-L5ZTLDWV-CmQbbP8b.js → chunk-L5ZTLDWV-DgLLQVzW.js} +1 -1
  16. package/dist/client/assets/{chunk-LZXEDZCA-Ba16nX-R.js → chunk-LZXEDZCA-Da9lwzEw.js} +2 -2
  17. package/dist/client/assets/{chunk-ND2GUHAM-Bc7u1Zqm.js → chunk-ND2GUHAM-BPnz-91H.js} +1 -1
  18. package/dist/client/assets/{chunk-NZK2D7GU-DNXYx7JX.js → chunk-NZK2D7GU-BfIcF7tV.js} +1 -1
  19. package/dist/client/assets/{chunk-O5CBEL6O-Ba00cuZ5.js → chunk-O5CBEL6O-B3QOwsKP.js} +1 -1
  20. package/dist/client/assets/{chunk-WU5MYG2G-SJ_ny5dU.js → chunk-WU5MYG2G-BBED6bLU.js} +1 -1
  21. package/dist/client/assets/classDiagram-4FO5ZUOK-D3uRQkFY.js +1 -0
  22. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-Cf_xrP1l.js +1 -0
  23. package/dist/client/assets/{dagre-BM42HDAG-CL2dKbj9.js → dagre-BM42HDAG-Cwumk4ZR.js} +1 -1
  24. package/dist/client/assets/{diagram-2AECGRRQ-DQq1qZ0l.js → diagram-2AECGRRQ-ClslRirB.js} +1 -1
  25. package/dist/client/assets/{diagram-5GNKFQAL-Zf0YQuRe.js → diagram-5GNKFQAL-CzE9h3uR.js} +1 -1
  26. package/dist/client/assets/{diagram-KO2AKTUF-DcUxL9SG.js → diagram-KO2AKTUF-Drs_bJ92.js} +1 -1
  27. package/dist/client/assets/{diagram-LMA3HP47-BAIixEu7.js → diagram-LMA3HP47-CxxNSrFg.js} +1 -1
  28. package/dist/client/assets/{diagram-OG6HWLK6-Dhhjm84p.js → diagram-OG6HWLK6-BHHFOg_M.js} +1 -1
  29. package/dist/client/assets/{erDiagram-TEJ5UH35-BcQOacBP.js → erDiagram-TEJ5UH35-CLYVwEgc.js} +1 -1
  30. package/dist/client/assets/{flowDiagram-I6XJVG4X-BZIJqLp3.js → flowDiagram-I6XJVG4X-s3nCY3e0.js} +1 -1
  31. package/dist/client/assets/{ganttDiagram-6RSMTGT7-DFC6qgrY.js → ganttDiagram-6RSMTGT7-Bw1QcLzc.js} +1 -1
  32. package/dist/client/assets/{gitGraphDiagram-PVQCEYII-Ds0nwSU0.js → gitGraphDiagram-PVQCEYII-Bi7EO2ZX.js} +1 -1
  33. package/dist/client/assets/{index-D_KmViSu.js → index-XSKL8H3C.js} +5 -5
  34. package/dist/client/assets/{infoDiagram-5YYISTIA-DfDrR5Mz.js → infoDiagram-5YYISTIA-BamFbqOO.js} +1 -1
  35. package/dist/client/assets/{ishikawaDiagram-YF4QCWOH-B2v4Byji.js → ishikawaDiagram-YF4QCWOH-DH43ZIY5.js} +1 -1
  36. package/dist/client/assets/{journeyDiagram-JHISSGLW-CO6laklO.js → journeyDiagram-JHISSGLW-BPgBXUEQ.js} +1 -1
  37. package/dist/client/assets/{kanban-definition-UN3LZRKU-BziFO199.js → kanban-definition-UN3LZRKU-CjMJrDcd.js} +1 -1
  38. package/dist/client/assets/{line-Vb0A8-Oe.js → line-Btqc-Cax.js} +1 -1
  39. package/dist/client/assets/{mermaid-parser.core-Bm3Xv0Zt.js → mermaid-parser.core-Bl51lVG0.js} +1 -1
  40. package/dist/client/assets/{mermaid.core-DXBRp0XG.js → mermaid.core-s9FJYhni.js} +3 -3
  41. package/dist/client/assets/{mindmap-definition-RKZ34NQL-4GueJvPT.js → mindmap-definition-RKZ34NQL-kakxNN97.js} +1 -1
  42. package/dist/client/assets/{pieDiagram-4H26LBE5-Djy0sVJR.js → pieDiagram-4H26LBE5-BQYRlP-G.js} +1 -1
  43. package/dist/client/assets/{quadrantDiagram-W4KKPZXB-3rWAi4K5.js → quadrantDiagram-W4KKPZXB-DGJRVtrA.js} +1 -1
  44. package/dist/client/assets/{requirementDiagram-4Y6WPE33-D7-WCnjH.js → requirementDiagram-4Y6WPE33-BSUtkGbI.js} +1 -1
  45. package/dist/client/assets/{sankeyDiagram-5OEKKPKP-B4-3BUQ2.js → sankeyDiagram-5OEKKPKP-CN9oFkiG.js} +1 -1
  46. package/dist/client/assets/{sequenceDiagram-3UESZ5HK-DCWomuSc.js → sequenceDiagram-3UESZ5HK-Dv60bCDo.js} +1 -1
  47. package/dist/client/assets/{stateDiagram-AJRCARHV-DpsWWFaO.js → stateDiagram-AJRCARHV-C_YPsL77.js} +1 -1
  48. package/dist/client/assets/stateDiagram-v2-BHNVJYJU-fcBW8vtz.js +1 -0
  49. package/dist/client/assets/{timeline-definition-PNZ67QCA-B0Mh4MHF.js → timeline-definition-PNZ67QCA-Y5JAv2Im.js} +1 -1
  50. package/dist/client/assets/{vennDiagram-CIIHVFJN-Dpxr8LTG.js → vennDiagram-CIIHVFJN-CvVupaFs.js} +1 -1
  51. package/dist/client/assets/{wardleyDiagram-YWT4CUSO-BdAz5ERd.js → wardleyDiagram-YWT4CUSO-CXPkAtzZ.js} +1 -1
  52. package/dist/client/assets/{xychartDiagram-2RQKCTM6-BV9Ah-jk.js → xychartDiagram-2RQKCTM6-BOrLRJbu.js} +1 -1
  53. package/dist/client/index.html +1 -1
  54. package/dist/server/lib/checkExecutionEnvironment.js +1 -1
  55. package/dist/server/lib/checkRunner.js +11 -6
  56. package/dist/server/lib/checkRunner.js.map +1 -1
  57. package/dist/server/lib/checkRuns.js +1 -1
  58. package/dist/server/lib/executionEnvironmentValidation.js +9 -3
  59. package/dist/server/lib/executionEnvironmentValidation.js.map +1 -1
  60. package/dist/server/lib/run.js +15 -19
  61. package/dist/server/lib/run.js.map +1 -1
  62. package/dist/server/lib/shell.js +13 -0
  63. package/dist/server/lib/shell.js.map +1 -1
  64. package/dist/server/workers/repositoryGraphAnalyzer.js +3 -2
  65. package/dist/server/workers/repositoryGraphAnalyzer.js.map +1 -1
  66. package/dist/server/workers/repositoryGraphAnalyzerBootstrap.js +20 -0
  67. package/dist/server/workers/repositoryGraphAnalyzerBootstrap.js.map +1 -0
  68. package/package.json +1 -1
  69. package/dist/client/assets/channel-C4I-VlJu.js +0 -1
  70. package/dist/client/assets/classDiagram-4FO5ZUOK-Ca3KxBnW.js +0 -1
  71. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-CSpMessw.js +0 -1
  72. package/dist/client/assets/stateDiagram-v2-BHNVJYJU-BE_IAuYt.js +0 -1
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mermaid.core-DXBRp0XG.js","assets/chunk-O5CBEL6O-Ba00cuZ5.js","assets/src-BRjoYtUW.js","assets/chunk-BNv3lrIs.js","assets/chunk-5ZQYHXKU-DC1dllSt.js","assets/dist-CERhmQhR.js","assets/chunk-CSCIHK7Q-Z1cfABPc.js","assets/chunk-3OPIFGDE-H70UH7rH.js","assets/chunk-L5ZTLDWV-CmQbbP8b.js","assets/chunk-NZK2D7GU-DNXYx7JX.js","assets/rough.esm-BoTisKeL.js","assets/chunk-BSJP7CBP-DJ57XcV5.js","assets/chunk-KSCS5N6A-DFoW6dtq.js","assets/line-Vb0A8-Oe.js","assets/path-sMK4d_s9.js","assets/array-BNor45A1.js","assets/chunk-LZXEDZCA-Ba16nX-R.js","assets/chunk-WU5MYG2G-SJ_ny5dU.js","assets/chunk-XPW4576I-DObFPxjB.js","assets/VerificationDialog-BfIKtVjt.js","assets/GitHubActionsDialog-NdYtgMhg.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mermaid.core-s9FJYhni.js","assets/chunk-O5CBEL6O-B3QOwsKP.js","assets/src-BRjoYtUW.js","assets/chunk-BNv3lrIs.js","assets/chunk-5ZQYHXKU-DJ6o7jkk.js","assets/dist-CERhmQhR.js","assets/chunk-CSCIHK7Q-CNZTo9o2.js","assets/chunk-3OPIFGDE-C0WrA6dp.js","assets/chunk-L5ZTLDWV-DgLLQVzW.js","assets/chunk-NZK2D7GU-BfIcF7tV.js","assets/rough.esm-BoTisKeL.js","assets/chunk-BSJP7CBP-DJ57XcV5.js","assets/chunk-KSCS5N6A-Dz-GLjci.js","assets/line-Btqc-Cax.js","assets/path-sMK4d_s9.js","assets/array-BNor45A1.js","assets/chunk-LZXEDZCA-Da9lwzEw.js","assets/chunk-WU5MYG2G-BBED6bLU.js","assets/chunk-XPW4576I-DObFPxjB.js","assets/VerificationDialog-CYCrlqmj.js","assets/GitHubActionsDialog-DL1RASVT.js"])))=>i.map(i=>d[i]);
2
2
  import{a as e,i as t,n,r,t as i}from"./chunk-BNv3lrIs.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var a=i((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m)if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),o=i(((e,t)=>{t.exports=a()})),s=i((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.iterator;function m(e){return typeof e!=`object`||!e?null:(e=p&&e[p]||e[`@@iterator`],typeof e==`function`?e:null)}var h={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},g=Object.assign,_={};function v(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}v.prototype.isReactComponent={},v.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=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,e,t,`setState`)},v.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function y(){}y.prototype=v.prototype;function b(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}var x=b.prototype=new y;x.constructor=b,g(x,v.prototype),x.isPureReactComponent=!0;var S=Array.isArray;function C(){}var w={H:null,A:null,T:null,S:null},T=Object.prototype.hasOwnProperty;function E(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function D(e,t){return E(e.type,t,e.props)}function O(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function k(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var A=/\/+/g;function j(e,t){return typeof e==`object`&&e&&e.key!=null?k(``+e.key):t.toString(36)}function M(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(C,C):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function N(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,N(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+j(e,0):a,S(o)?(i=``,c!=null&&(i=c.replace(A,`$&/`)+`/`),N(o,r,i,``,function(e){return e})):o!=null&&(O(o)&&(o=D(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(A,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(S(e))for(var u=0;u<e.length;u++)a=e[u],s=l+j(a,u),c+=N(a,r,i,s,o);else if(u=m(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+j(a,u++),c+=N(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return N(M(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function P(e,t,n){if(e==null)return e;var r=[],i=0;return N(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function F(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var I=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)},L={map:P,forEach:function(e,t,n){P(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return P(e,function(){t++}),t},toArray:function(e){return P(e,function(e){return e})||[]},only:function(e){if(!O(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=L,e.Component=v,e.Fragment=r,e.Profiler=a,e.PureComponent=b,e.StrictMode=i,e.Suspense=l,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=w,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return w.H.useMemoCache(e)}},e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=g({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!T.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return E(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)T.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return E(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=O,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:F}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=w.T,n={};w.T=n;try{var r=e(),i=w.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(C,I)}catch(e){I(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),w.T=t}},e.unstable_useCacheRefresh=function(){return w.H.useCacheRefresh()},e.use=function(e){return w.H.use(e)},e.useActionState=function(e,t,n){return w.H.useActionState(e,t,n)},e.useCallback=function(e,t){return w.H.useCallback(e,t)},e.useContext=function(e){return w.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return w.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return w.H.useEffect(e,t)},e.useEffectEvent=function(e){return w.H.useEffectEvent(e)},e.useId=function(){return w.H.useId()},e.useImperativeHandle=function(e,t,n){return w.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return w.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return w.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return w.H.useMemo(e,t)},e.useOptimistic=function(e,t){return w.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return w.H.useReducer(e,t,n)},e.useRef=function(e){return w.H.useRef(e)},e.useState=function(e){return w.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return w.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return w.H.useTransition()},e.version=`19.2.5`})),c=i(((e,t)=>{t.exports=s()})),l=i((e=>{var t=c();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`);function o(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var s=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function l(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return o(e,t,null,r)},e.flushSync=function(e){var t=s.T,n=i.p;try{if(s.T=null,i.p=2,e)return e()}finally{s.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=l(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`)if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=l(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??i.d.M(e)},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=l(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`)if(t){var n=l(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else i.d.m(e)},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return s.H.useFormState(e,t,n)},e.useFormStatus=function(){return s.H.useHostTransitionStatus()},e.version=`19.2.5`})),u=i(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=l()})),d=i((e=>{var t=o(),n=c(),r=u();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function s(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function l(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function d(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function f(e){if(s(e)!==e)throw Error(i(188))}function p(e){var t=e.alternate;if(!t){if(t=s(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var o=a.alternate;if(o===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===o.child){for(o=a.child;o;){if(o===n)return f(a),e;if(o===r)return f(a),t;o=o.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=o;else{for(var c=!1,l=a.child;l;){if(l===n){c=!0,n=a,r=o;break}if(l===r){c=!0,r=a,n=o;break}l=l.sibling}if(!c){for(l=o.child;l;){if(l===n){c=!0,n=o,r=a;break}if(l===r){c=!0,r=o,n=a;break}l=l.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function m(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=m(e),t!==null)return t;e=e.sibling}return null}var h=Object.assign,g=Symbol.for(`react.element`),_=Symbol.for(`react.transitional.element`),v=Symbol.for(`react.portal`),y=Symbol.for(`react.fragment`),b=Symbol.for(`react.strict_mode`),x=Symbol.for(`react.profiler`),S=Symbol.for(`react.consumer`),C=Symbol.for(`react.context`),w=Symbol.for(`react.forward_ref`),T=Symbol.for(`react.suspense`),E=Symbol.for(`react.suspense_list`),D=Symbol.for(`react.memo`),O=Symbol.for(`react.lazy`),k=Symbol.for(`react.activity`),A=Symbol.for(`react.memo_cache_sentinel`),j=Symbol.iterator;function M(e){return typeof e!=`object`||!e?null:(e=j&&e[j]||e[`@@iterator`],typeof e==`function`?e:null)}var N=Symbol.for(`react.client.reference`);function P(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===N?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case y:return`Fragment`;case x:return`Profiler`;case b:return`StrictMode`;case T:return`Suspense`;case E:return`SuspenseList`;case k:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case v:return`Portal`;case C:return e.displayName||`Context`;case S:return(e._context.displayName||`Context`)+`.Consumer`;case w:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case D:return t=e.displayName||null,t===null?P(e.type)||`Memo`:t;case O:t=e._payload,e=e._init;try{return P(e(t))}catch{}}return null}var F=Array.isArray,I=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,L=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,R={pending:!1,data:null,method:null,action:null},z=[],ee=-1;function B(e){return{current:e}}function V(e){0>ee||(e.current=z[ee],z[ee]=null,ee--)}function H(e,t){ee++,z[ee]=e.current,e.current=t}var U=B(null),W=B(null),te=B(null),ne=B(null);function re(e,t){switch(H(te,t),H(W,e),H(U,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Ud(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Ud(t),e=Wd(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}V(U),H(U,e)}function ie(){V(U),V(W),V(te)}function ae(e){e.memoizedState!==null&&H(ne,e);var t=U.current,n=Wd(t,e.type);t!==n&&(H(W,e),H(U,n))}function G(e){W.current===e&&(V(U),V(W)),ne.current===e&&(V(ne),$f._currentValue=R)}var oe,se;function ce(e){if(oe===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);oe=t&&t[1]||``,se=-1<e.stack.indexOf(`
3
3
  at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
4
4
  `+oe+e+se}var le=!1;function ue(e,t){if(!e||le)return``;le=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,`props`,{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,`name`,{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
@@ -74,7 +74,7 @@ Minimum version required to store current data is: `+c+`.
74
74
  `),priority:e.priority,injectionMode:e.injection_mode}),vT=e=>({kind:`decision`,title:e.title,scope:e.scope??``,content:e.decision,rationale:e.rationale??``,implicationsText:e.implications.join(`
75
75
  `),stages:e.stages,pathGlobsText:(e.path_globs??[]).join(`
76
76
  `),componentTagsText:(e.component_tags??[]).join(`
77
- `),priority:`normal`,injectionMode:`relevant`}),yT=(e,t)=>e(t===`superseded`?`memory.savedStateLabels.superseded`:t===`archived`?`memory.savedStateLabels.archived`:`memory.savedStateLabels.active`),bT=e=>e!==`active`&&e!==`accepted`,xT=e=>{let t=e?.latest_attempt??e?.scan;return t?.status===`pending`||t?.status===`running`},ST=e=>e.trim().toLowerCase().replace(/_/g,` `).replace(/\s+/g,` `),CT=e=>[...e].sort((e,t)=>{let n=ST(e.title)===`architecture`||ST(e.kind)===`architecture`;return n===(ST(t.title)===`architecture`||ST(t.kind)===`architecture`)?0:n?-1:1}),wT=async(e,t)=>{let[n,r]=await Promise.all([wr(e,t),Or(e,t)]);return{context:n,artifacts:r.artifacts}},TT=e=>({id:e.id,project_id:e.project_id,title:e.title,scope:e.scope,instruction:e.content,rationale:e.rationale,stages:e.stages,path_globs:e.path_globs,component_tags:e.component_tags,priority:e.priority??`normal`,injection_mode:e.injection_mode??`relevant`,status:e.state===`archived`?`archived`:`active`,origin:e.origin??void 0,created_at:e.created_at,updated_at:e.updated_at}),ET=e=>{let t=e.state===`archived`?`archived`:e.state===`superseded`?`superseded`:`accepted`;return{id:e.id,project_id:e.project_id,title:e.title,scope:e.scope,decision:e.content,rationale:e.rationale,implications:e.implications,stages:e.stages,path_globs:e.path_globs,component_tags:e.component_tags,status:t,superseded_by_decision_id:null,origin:e.origin??void 0,created_at:e.created_at,updated_at:e.updated_at}},DT=e=>e.state===`suggested`,OT=async(e,t)=>{let n=await ar(e,t);return{conventions:pT(n.memories.filter(e=>e.kind===`convention`&&(e.state===`active`||e.state===`archived`)).map(TT)),decisions:mT(n.memories.filter(e=>e.kind===`decision`&&(e.state===`active`||e.state===`archived`||e.state===`superseded`)).map(ET)),suggestions:n.memories.filter(DT),generatedContext:n.generated_context}},kT=(e,t)=>t.conflicts.length===0?e(`memory.import.noTitleConflicts`):e(`memory.import.titleConflictCount`,{count:t.conflicts.length}),AT=async(e,t)=>typeof e.text==`function`?await e.text():await new Promise((n,r)=>{let i=new FileReader;i.onerror=()=>{r(Error(t))},i.onload=()=>{n(typeof i.result==`string`?i.result:``)},i.readAsText(e)}),jT=({value:e,onChange:t})=>{let{t:n}=q(`projects`);return(0,X.jsx)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:iT.map(r=>{let i=e.includes(r);return(0,X.jsxs)(`label`,{className:`flex min-w-0 items-start gap-2 rounded-xl border border-border/70 bg-background/30 px-3 py-2 text-sm text-foreground`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:i,className:`mt-0.5 shrink-0`,onChange:()=>{t(i?e.filter(e=>e!==r):[...e,r])}}),(0,X.jsx)(`span`,{className:`min-w-0 break-words leading-5`,children:sT(n,r)})]},r)})})},MT=({title:e,meta:t,preview:n,ariaLabel:r,onClick:i,archived:a=!1,accentClassName:o})=>(0,X.jsxs)(`button`,{type:`button`,onClick:i,"aria-label":r,className:Z(`group relative flex min-h-40 cursor-pointer flex-col justify-between overflow-hidden rounded-xl border border-border/80 bg-background/55 p-4 text-left transition hover:-translate-y-0.5 hover:border-foreground/20 hover:bg-background/72 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60`,a&&`border-border/55 bg-background/30`),children:[(0,X.jsx)(`span`,{className:Z(`absolute inset-y-0 left-0 w-px bg-border/70`,o)}),(0,X.jsxs)(`div`,{className:`space-y-3 pl-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 space-y-2`,children:[(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(e=>(0,X.jsx)(rC,{variant:`outline`,className:`h-5 rounded-md border-border/70 bg-background/80 px-1.5 text-[10px] uppercase tracking-[0.16em] text-muted-foreground`,children:e},e))}),(0,X.jsx)(`h4`,{className:`line-clamp-2 text-sm font-semibold leading-5 text-foreground`,children:e})]}),(0,X.jsx)(`span`,{className:`mt-0.5 rounded-md border border-border/70 bg-background/80 p-1.5 text-muted-foreground transition group-hover:border-foreground/20 group-hover:text-foreground`,children:(0,X.jsx)(yw,{className:`size-3.5`})})]}),(0,X.jsx)(`p`,{className:`line-clamp-2 whitespace-pre-wrap text-sm leading-5 text-muted-foreground`,children:n})]})]}),NT=({draft:e,onChange:t,onCancel:n,onSubmit:r,isSaving:i,submitLabel:a,layout:o=`inline`,supplementaryActions:s,allowKindChange:c=!0})=>{let{t:l}=q(`projects`),u=e.kind===`convention`,d=e.title.trim()?null:l(`memory.validation.titleRequired`),f=e.content.trim()?null:l(`memory.validation.contentRequired`),p=!d&&!f;return(0,X.jsxs)(`div`,{className:Z(`space-y-4`,o===`inline`&&`rounded-2xl border border-border/70 bg-background/25 p-4`),children:[(0,X.jsx)(dC,{label:l(`memory.editor.typeLabel`),children:(0,X.jsx)(pv,{label:``,triggerLabel:oT(l,e.kind),triggerAriaLabel:l(`memory.editor.typeAriaLabel`),selectId:`memory-type`,selectedValue:e.kind,onChange:n=>{c&&t({...fT(n),title:e.title,scope:e.scope,content:e.content,rationale:e.rationale})},disabled:!c,groups:[{label:``,options:[{value:`decision`,label:l(`memory.editor.decision`)},{value:`convention`,label:l(`memory.editor.convention`)}]}]})}),(0,X.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,X.jsx)(dC,{label:l(`memory.editor.titleLabel`),error:d,children:(0,X.jsx)(J_,{"aria-label":l(`memory.editor.titleAriaLabel`),"aria-invalid":!!d,value:e.title,maxLength:Cw.title,onChange:n=>t({...e,title:n.target.value}),placeholder:l(u?`memory.editor.titlePlaceholderConvention`:`memory.editor.titlePlaceholderDecision`)})}),(0,X.jsx)(dC,{label:l(`memory.editor.scopeLabel`),description:l(`memory.editor.scopeDescription`),children:(0,X.jsx)(J_,{"aria-label":l(`memory.editor.scopeAriaLabel`),value:e.scope,maxLength:Cw.scope,onChange:n=>t({...e,scope:n.target.value}),placeholder:l(u?`memory.editor.scopePlaceholderConvention`:`memory.editor.scopePlaceholderDecision`)})})]}),(0,X.jsx)(dC,{label:l(`memory.editor.contentLabel`),error:f,children:(0,X.jsx)(Y_,{"aria-label":l(`memory.editor.contentAriaLabel`),"aria-invalid":!!f,value:e.content,maxLength:Cw.content,onChange:n=>t({...e,content:n.target.value}),rows:3,placeholder:l(u?`memory.editor.contentPlaceholderConvention`:`memory.editor.contentPlaceholderDecision`)})}),(0,X.jsx)(dC,{label:l(`memory.editor.rationaleLabel`),description:l(`memory.editor.rationaleDescription`),children:(0,X.jsx)(Y_,{"aria-label":l(`memory.editor.rationaleAriaLabel`),value:e.rationale,maxLength:Cw.rationale,onChange:n=>t({...e,rationale:n.target.value}),rows:2,placeholder:l(u?`memory.editor.rationalePlaceholderConvention`:`memory.editor.rationalePlaceholderDecision`)})}),u?(0,X.jsxs)(`div`,{className:`grid gap-4 xl:grid-cols-2 xl:items-start`,children:[(0,X.jsx)(dC,{label:l(`memory.editor.priorityLabel`),children:(0,X.jsx)(pv,{label:``,triggerLabel:cT(l,e.priority),triggerAriaLabel:l(`memory.editor.priorityAriaLabel`),selectId:`memory-priority`,selectedValue:e.priority,onChange:n=>t({...e,priority:n}),groups:[{label:``,options:Sw.map(e=>({value:e,label:cT(l,e)}))}]})}),(0,X.jsx)(dC,{label:l(`memory.editor.injectionModeLabel`),children:(0,X.jsx)(pv,{label:``,triggerLabel:lT(l,e.injectionMode),triggerAriaLabel:l(`memory.editor.injectionModeAriaLabel`),selectId:`memory-injection-mode`,selectedValue:e.injectionMode,onChange:n=>t({...e,injectionMode:n}),groups:[{label:``,options:[`always`,`relevant`].map(e=>({value:e,label:lT(l,e)}))}]})})]}):(0,X.jsx)(dC,{label:l(`memory.editor.implicationsLabel`),description:l(`memory.editor.implicationsDescription`),children:(0,X.jsx)(Y_,{"aria-label":l(`memory.editor.implicationsAriaLabel`),value:e.implicationsText,onChange:n=>t({...e,implicationsText:n.target.value}),rows:3,placeholder:l(`memory.editor.implicationsPlaceholder`)})}),(0,X.jsx)(dC,{label:l(`memory.editor.stagesLabel`),description:l(`memory.editor.stagesDescription`),children:(0,X.jsx)(jT,{value:e.stages,onChange:n=>t({...e,stages:n})})}),(0,X.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,X.jsx)(dC,{label:l(`memory.editor.pathGlobsLabel`),description:l(`memory.editor.applicabilityDescription`),children:(0,X.jsx)(Y_,{"aria-label":l(`memory.editor.pathGlobsAriaLabel`),value:e.pathGlobsText,onChange:n=>t({...e,pathGlobsText:n.target.value}),rows:3})}),(0,X.jsx)(dC,{label:l(`memory.editor.componentTagsLabel`),description:l(`memory.editor.applicabilityDescription`),children:(0,X.jsx)(Y_,{"aria-label":l(`memory.editor.componentTagsAriaLabel`),value:e.componentTagsText,onChange:n=>t({...e,componentTagsText:n.target.value}),rows:3})})]}),s,o!==`dialog`&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,X.jsx)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 sm:flex-1`}),(0,X.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2`,children:[(0,X.jsx)(Q,{type:`button`,variant:`ghost`,onClick:n,children:l(`memory.editor.cancel`)}),(0,X.jsx)(Q,{type:`button`,variant:`success`,onClick:r,disabled:i||!p,children:i?l(`memory.editor.saving`):a})]})]})]})},PT=({origin:e,onNavigateToSource:t})=>{let{t:n}=q(`projects`);if(!e)return null;let r=e.accepted_at?new Date(e.accepted_at).toLocaleString():null;return(0,X.jsxs)(`div`,{className:`rounded-lg border border-border/60 bg-background/40 px-3 py-2 text-xs leading-5 text-muted-foreground`,children:[(0,X.jsx)(`p`,{className:`font-medium text-foreground`,children:uT(n,e)}),e.type===`agent_suggestion`&&e.source_type&&(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:n(`memory.provenance.source`)}),` `,dT(n,e.source_type),e.source_label?`: ${e.source_label}`:``]}),e.type===`agent_suggestion`&&e.source_stage&&(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:n(`memory.provenance.stage`)}),` `,sT(n,e.source_stage)]}),r&&(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:n(`memory.provenance.addedAt`)}),` `,r]}),e.type===`agent_suggestion`&&e.source_available&&t&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`mt-2`,onClick:()=>t(e),children:n(`memory.provenance.viewSource`)})]})},FT=({mode:e,projectId:t,memoryEnabled:n,persistedMemoryEnabled:r,onMemoryEnabledChange:i,scanIncludeGlobsText:a=``,scanExcludeGlobsText:o=``,onScanIncludeGlobsTextChange:s,onScanExcludeGlobsTextChange:c,showActivationControls:l=!0,archiveLayout:u=!1,onNavigateToSource:d})=>{let{t:f}=q(`projects`),[m,h]=(0,p.useState)(null),[g,_]=(0,p.useState)([]),[v,y]=(0,p.useState)([]),[b,x]=(0,p.useState)([]),[S,C]=(0,p.useState)(!1),[w,T]=(0,p.useState)(null),[E,D]=(0,p.useState)(fT),[O,k]=(0,p.useState)(!1),[A,j]=(0,p.useState)(Kw),[M,N]=(0,p.useState)(0),[P,F]=(0,p.useState)(null),[I,L]=(0,p.useState)([]),[R,z]=(0,p.useState)(!1),[ee,B]=(0,p.useState)(null),[V,H]=(0,p.useState)(!1),[U,W]=(0,p.useState)(!1),[te,ne]=(0,p.useState)(!1),[re,ie]=(0,p.useState)(null),[ae,G]=(0,p.useState)(``),[oe,se]=(0,p.useState)(!1),[ce,le]=(0,p.useState)(!1),[ue,de]=(0,p.useState)(``),fe=(0,p.useRef)(null),pe=(0,p.useRef)(JSON.stringify(fT())),me=u&&e===`edit`&&!!t&&n&&r,he=e===`edit`&&!!t,ge=e===`create`&&n,_e=e===`edit`&&n&&!r,ve=!n;(0,p.useEffect)(()=>{if(!me||!t){_([]),y([]),x([]),h(null),T(null),ie(null),F(null),L([]),B(null),z(!1);return}let e=new AbortController;return C(!0),z(!0),T(null),B(null),OT(t,e.signal).then(t=>{e.signal.aborted||(T(null),_(t.conventions),y(t.decisions),x(t.suggestions),F(t.generatedContext?.context??null),L(t.generatedContext?.artifacts??[]))}).catch(t=>{e.signal.aborted||T(t instanceof Error?t.message:f(`memory.messages.loadError`))}).finally(()=>{e.signal.aborted||(C(!1),z(!1))}),()=>{e.abort()}},[me,M,t,f]),(0,p.useEffect)(()=>{if(!t||!me||!xT(P))return;let e=null,n=new AbortController,r=()=>{z(!0),wT(t,n.signal).then(t=>{n.signal.aborted||(B(null),F(t.context),L(t.artifacts),xT(t.context)&&(e=window.setTimeout(r,aT)))}).catch(t=>{n.signal.aborted||(B(t instanceof Error?t.message:f(`memory.messages.refreshContextError`)),e=window.setTimeout(r,aT))}).finally(()=>{n.signal.aborted||z(!1)})};return e=window.setTimeout(r,aT),()=>{n.abort(),e!==null&&window.clearTimeout(e),z(!1)}},[me,P,t,f]);let ye=(0,p.useMemo)(()=>{let e=g.map(e=>tT({id:e.id,project_id:e.project_id,kind:`convention`,state:e.status===`active`?`active`:`archived`,title:e.title,scope:e.scope,content:e.instruction,rationale:e.rationale,implications:[],stages:e.stages,path_globs:e.path_globs,component_tags:e.component_tags,priority:e.priority,injection_mode:e.injection_mode,origin:e.origin,created_at:e.created_at,updated_at:e.updated_at})),t=v.map(e=>tT({id:e.id,project_id:e.project_id,kind:`decision`,state:e.status===`accepted`?`active`:e.status,title:e.title,scope:e.scope,content:e.decision,rationale:e.rationale,implications:e.implications,stages:e.stages,path_globs:e.path_globs,component_tags:e.component_tags,priority:null,injection_mode:null,origin:e.origin,created_at:e.created_at,updated_at:e.updated_at}));return[...e,...t]},[g,v]),be=(0,p.useMemo)(()=>$w(ye,A),[ye,A]),xe=(0,p.useMemo)(()=>{let e=be.filter(e=>e.kind===`convention`).map(e=>{let t=TT(e),n=[f(`memory.editor.convention`),cT(f,t.priority),lT(f,t.injection_mode),yT(f,t.status),uT(f,t.origin)];return t.stages.length>0&&n.push(t.stages.length===1?sT(f,t.stages[0]):f(`memory.archive.stageCount`,{count:t.stages.length})),{id:t.id,kind:`convention`,title:t.title,preview:t.instruction,meta:n,archived:bT(t.status),updatedAt:t.updated_at,origin:t.origin}}),t=be.filter(e=>e.kind===`decision`).map(e=>{let t=ET(e);return{id:t.id,kind:`decision`,title:t.title,preview:t.decision,meta:[f(`memory.editor.decision`),yT(f,t.status),uT(f,t.origin)],archived:bT(t.status),updatedAt:t.updated_at,origin:t.origin}}),n=new Map([...e,...t].map(e=>[e.id,e]));return be.map(e=>n.get(e.id)).filter(e=>!!e)},[be,f]),Se=(0,p.useMemo)(()=>b,[b]),Ce=(0,p.useMemo)(()=>rT(Se),[Se]),we=(0,p.useMemo)(()=>CT(I),[I]),Te=()=>{h(null),D(fT())},Ee=()=>{if(JSON.stringify(E)!==pe.current&&!O){se(!0);return}Te()},De=async()=>{if(!t||!E.title.trim()||!E.content.trim())return;let e=oie(E.implicationsText),n=Dw(E.pathGlobsText),r=Dw(E.componentTagsText),i=E.kind===`decision`?ww(e):null;if(i){$.error(f(`memory.validation.implications.${i}`,Cw),{id:`project-memory-save-error`});return}k(!0);try{if(E.kind===`convention`){let e={kind:`convention`,title:E.title.trim(),scope:E.scope.trim()||null,instruction:E.content.trim(),rationale:E.rationale.trim()||null,stages:E.stages,path_globs:n,component_tags:r,priority:E.priority,injection_mode:E.injectionMode},i=m?.id?await br(t,m.id,e):await yr(t,e);_(e=>hT(e,TT(i.memory)))}else{let i={kind:`decision`,title:E.title.trim(),scope:E.scope.trim()||null,decision:E.content.trim(),rationale:E.rationale.trim()||null,implications:e,stages:E.stages,path_globs:n,component_tags:r},a=m?.id?await br(t,m.id,i):await yr(t,i);y(e=>gT(e,ET(a.memory)))}Te(),de(f(`memory.workspace.status.saved`))}catch(e){$.error(e instanceof Error?e.message:f(`memory.messages.saveError`),{id:`project-memory-save-error`})}finally{k(!1)}},Oe=e=>{let t=_T(e);h({kind:`convention`,id:e.id}),D(t),pe.current=JSON.stringify(t)},ke=()=>{let e=fT(`decision`);h({kind:`decision`,id:null}),D(e),pe.current=JSON.stringify(e)},Ae=e=>{let t=vT(e);h({kind:`decision`,id:e.id}),D(t),pe.current=JSON.stringify(t)},je=async(e,n)=>{if(!t)return!1;try{let r=n===`archive`?await xr(t,e.id):await Sr(t,e.id).catch(async n=>{if(!Tw(n,f(`memory.messages.confirmConflicts`)))throw n;return Sr(t,e.id,!0)});return _(e=>hT(e,TT(r.memory))),de(f(`memory.workspace.status.${n===`archive`?`archived`:`restored`}`)),n===`archive`&&$.success(f(`memory.workspace.archiveUndoMessage`),{action:{label:f(`memory.workspace.undo`),onClick:()=>{je(TT(r.memory),`restore`)}}}),!0}catch(e){return $.error(e instanceof Error?e.message:f(n===`archive`?`memory.messages.archiveConventionError`:`memory.messages.restoreConventionError`),{id:n===`archive`?`project-memory-convention-archive-error`:`project-memory-convention-restore-error`}),!1}},Me=async(e,n)=>{if(!t)return!1;try{let r=n===`archive`?await xr(t,e.id):n===`supersede`?await Cr(t,e.id,ae):await Sr(t,e.id).catch(async n=>{if(!Tw(n,f(`memory.messages.confirmConflicts`)))throw n;return Sr(t,e.id,!0)});return y(e=>gT(e,ET(r.memory))),de(f(`memory.workspace.status.${n===`archive`?`archived`:n===`restore`?`restored`:`superseded`}`)),n===`archive`&&$.success(f(`memory.workspace.archiveUndoMessage`),{action:{label:f(`memory.workspace.undo`),onClick:()=>{Me(ET(r.memory),`restore`)}}}),!0}catch(e){let t=f(n===`archive`?`memory.messages.archiveDecisionError`:n===`supersede`?`memory.messages.supersedeDecisionError`:`memory.messages.restoreDecisionError`),r=n===`archive`?`project-memory-decision-archive-error`:n===`supersede`?`project-memory-decision-supersede-error`:`project-memory-decision-restore-error`;return $.error(e instanceof Error?e.message:t,{id:r}),!1}},Ne=m!==null,Pe=m?.kind===`convention`&&m.id?g.find(e=>e.id===m.id)??null:null,Fe=m?.kind===`decision`&&m.id?v.find(e=>e.id===m.id)??null:null,Ie=m?.id?ye.find(e=>e.id===m.id)??null:null,Le=xT(P),K=()=>{t&&(H(!0),B(null),Tr(t).then(async e=>{F(e),L((await Or(t)).artifacts),$.success(f(`memory.messages.scanStarted`),{id:`project-context-scan-started`}),de(f(`memory.workspace.status.scanStarted`))}).catch(async e=>{if(e instanceof Ge&&e.status===409){$.error(f(`memory.messages.scanConflict`),{id:`project-context-scan-conflict`});try{let e=await wT(t);F(e.context),L(e.artifacts)}catch(e){B(e instanceof Error?e.message:f(`memory.messages.refreshContextError`))}return}$.error(e instanceof Error?e.message:f(`memory.messages.scanStartError`),{id:`project-context-scan-error`})}).finally(()=>{H(!1)}))},Re=async()=>{if(t){W(!0);try{let{filename:e,archive:n}=await Fr(t),r=new Blob([JSON.stringify(n,null,2)],{type:`application/json;charset=utf-8`}),i=window.URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=e,a.click(),window.URL.revokeObjectURL(i),$.success(f(`memory.messages.exportSuccess`),{id:`project-memory-export-success`})}catch(e){$.error(e instanceof Error?e.message:f(`memory.messages.exportError`),{id:`project-memory-export-error`})}finally{W(!1)}}},ze=async e=>{if(!t){e.target.value=``;return}let n=e.target.files?.[0];if(e.target.value=``,n){ne(!0);try{let e=await Ir(t,JSON.parse(await AT(n,f(`memory.import.readFileError`))));if(me){let e=await OT(t);_(e.conventions),y(e.decisions),x(e.suggestions),F(e.generatedContext?.context??null),L(e.generatedContext?.artifacts??[]),T(null),B(null)}ie(e),$.success(f(`memory.messages.importSuccess`),{id:`project-memory-import-success`})}catch(e){$.error(e instanceof Error?e.message:f(`memory.messages.importError`),{id:`project-memory-import-error`})}finally{ne(!1)}}},Be=(0,X.jsxs)(`div`,{className:u?`rounded-lg border border-border/70 bg-background/35 p-4`:`rounded-2xl border border-border/70 bg-background/25 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h4`,{className:`text-sm font-semibold text-foreground`,children:f(`memory.transfer.title`)}),(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:f(`memory.transfer.description`)}),!he&&(0,X.jsx)(`p`,{className:`mt-2 text-xs leading-5 text-muted-foreground`,children:f(`memory.transfer.createProjectFirst`)})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 self-start`,children:[(0,X.jsxs)(Q,{type:`button`,variant:`outline`,onClick:()=>{Re()},disabled:!he||U||te,children:[(0,X.jsx)(aie,{className:`h-3.5 w-3.5`}),f(U?`memory.transfer.exporting`:`memory.transfer.export`)]}),(0,X.jsxs)(Q,{type:`button`,variant:`outline`,onClick:()=>{fe.current?.click()},disabled:!he||U||te,children:[(0,X.jsx)(bw,{className:`h-3.5 w-3.5`}),f(te?`memory.transfer.importing`:`memory.transfer.import`)]})]})]}),(0,X.jsx)(`input`,{ref:fe,type:`file`,accept:`application/json,.json`,className:`hidden`,"aria-label":f(`memory.transfer.importAriaLabel`),onChange:e=>{ze(e)}}),re&&(0,X.jsxs)(`div`,{className:`mt-4 grid gap-2 sm:grid-cols-2 xl:grid-cols-4`,children:[(0,X.jsx)(`div`,{className:`rounded-lg border border-border/60 bg-background/35 px-3 py-2 text-sm text-muted-foreground`,children:f(`memory.transfer.importedConventions`,{imported:re.summary.conventions_imported,skipped:re.summary.conventions_skipped})}),(0,X.jsx)(`div`,{className:`rounded-lg border border-border/60 bg-background/35 px-3 py-2 text-sm text-muted-foreground`,children:f(`memory.transfer.importedDecisions`,{imported:re.summary.decisions_imported,skipped:re.summary.decisions_skipped})}),(0,X.jsx)(`div`,{className:`rounded-lg border border-border/60 bg-background/35 px-3 py-2 text-sm text-muted-foreground`,children:f(`memory.transfer.importedScans`,{imported:re.summary.scans_imported,skipped:re.summary.scans_skipped})}),(0,X.jsx)(`div`,{className:`rounded-lg border border-border/60 bg-background/35 px-3 py-2 text-sm text-muted-foreground`,children:f(`memory.transfer.importedArtifacts`,{imported:re.summary.artifacts_imported,skipped:re.summary.artifacts_skipped})}),(0,X.jsx)(`div`,{className:`sm:col-span-2 xl:col-span-4 rounded-lg border border-border/60 bg-background/35 px-3 py-2 text-sm text-muted-foreground`,children:kT(f,re)})]})]}),Ve=(0,X.jsxs)(Q,{type:`button`,variant:`outline`,size:`sm`,className:`min-w-[7.5rem] shrink-0 justify-center`,disabled:V||Le,onClick:K,children:[V||Le?(0,X.jsx)(Ov,{className:`size-3.5 animate-spin`}):(0,X.jsx)(xw,{className:`size-3.5`}),f(V||Le?`memory.archive.scanning`:`memory.archive.scanNow`)]});return u?(0,X.jsxs)(`div`,{className:`space-y-5`,children:[(0,X.jsx)(`p`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:ue}),ve&&(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground`,children:f(`memory.archive.disabledNote`)}),ge&&(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground`,children:f(`memory.archive.createNote`)}),_e&&(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground`,children:f(`memory.archive.saveFirstNote`)}),me&&(0,X.jsxs)(LC,{defaultValue:`accepted`,className:`min-w-0 rounded-xl border border-border/70 bg-card/55 shadow-[0_18px_40px_rgba(0,0,0,0.16)]`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-4 border-b border-border/60 px-4 py-4 sm:px-5`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-lg font-semibold text-foreground`,children:f(`memory.archive.memoriesTitle`)}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:f(`memory.workspace.description`)})]}),(0,X.jsxs)(RC,{className:`grid w-full grid-cols-3 sm:w-auto`,children:[(0,X.jsxs)(zC,{value:`inbox`,children:[f(`memory.workspace.tabs.inbox`),` `,(0,X.jsx)(`span`,{className:`ml-1 text-xs`,children:Se.length})]}),(0,X.jsxs)(zC,{value:`accepted`,children:[f(`memory.workspace.tabs.accepted`),` `,(0,X.jsx)(`span`,{className:`ml-1 text-xs`,children:ye.length})]}),(0,X.jsx)(zC,{value:`context`,children:f(`memory.workspace.tabs.context`)})]})]}),w&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3 text-sm text-red-300 sm:flex-row sm:items-center sm:justify-between`,children:[(0,X.jsx)(`span`,{children:w}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>N(e=>e+1),children:f(`memory.workspace.retry`)})]})]}),(0,X.jsxs)(BC,{value:`inbox`,className:`space-y-5 p-4 sm:p-5`,children:[(0,X.jsx)(`h4`,{className:`text-sm font-semibold text-foreground`,children:f(`memory.archive.suggestedMemoriesTitle`)}),S?(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border px-4 py-4 text-sm text-muted-foreground`,children:f(`memory.archive.loadingSuggestedMemories`)}):Ce.length>0?Ce.map(e=>(0,X.jsxs)(`section`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-border/60 pb-2`,children:[(0,X.jsx)(`h4`,{className:`text-sm font-semibold text-foreground`,children:e.label??f(`memory.workspace.sources.${e.sourceType}`)}),(0,X.jsx)(rC,{variant:`outline`,children:f(`memory.archive.itemsCount`,{count:e.suggestions.length})})]}),(0,X.jsx)(Pw,{projectId:t??``,suggestions:e.suggestions,onNavigateToSource:e.sourceAvailable?d:void 0,onChanged:(e,t,n)=>{x(t=>t.filter(t=>t.id!==e)),t!==`dismiss`&&n?.memory.id&&(n.memory.kind===`decision`?y(e=>gT(e,ET(n.memory))):_(e=>hT(e,TT(n.memory))))}})]},e.key)):(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border px-4 py-8 text-center text-sm text-muted-foreground`,children:f(`memory.archive.noSuggestedMemories`)})]}),(0,X.jsxs)(BC,{value:`accepted`,className:`space-y-5 p-4 sm:p-5`,children:[(0,X.jsx)(`h4`,{className:`text-sm font-semibold text-foreground`,children:f(`memory.archive.savedMemoriesTitle`)}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-5`,children:[(0,X.jsxs)(`label`,{className:`space-y-1 text-xs font-medium text-muted-foreground sm:col-span-2 xl:col-span-2`,children:[(0,X.jsx)(`span`,{children:f(`memory.workspace.search`)}),(0,X.jsx)(J_,{value:A.search,onChange:e=>j(t=>({...t,search:e.target.value})),placeholder:f(`memory.workspace.searchPlaceholder`)})]}),[`kind`,`stage`,`source`,`injection`,`sort`].map(e=>(0,X.jsxs)(`label`,{className:`space-y-1 text-xs font-medium text-muted-foreground`,children:[(0,X.jsx)(`span`,{children:f(`memory.workspace.filters.${e}`)}),(0,X.jsx)(`select`,{value:A[e],onChange:t=>j(n=>({...n,[e]:t.target.value})),className:`h-9 w-full rounded-lg border border-border bg-background px-3 text-sm text-foreground`,children:(e===`kind`?[`all`,`decision`,`convention`]:e===`stage`?[`all`,...iT]:e===`source`?[`all`,`manual`,`ticket`,`chat`,`spec`]:e===`injection`?[`all`,`always`,`relevant`]:[`updated`,`title`,`kind`,`priority`]).map(e=>(0,X.jsx)(`option`,{value:e,children:f(`memory.workspace.options.${e}`)},e))})]},e))]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[eT(A)&&(0,X.jsx)(Q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>j(Kw),children:f(`memory.workspace.clearFilters`)}),(0,X.jsxs)(Q,{type:`button`,variant:`outline`,size:`sm`,onClick:ke,children:[(0,X.jsx)(xv,{className:`size-3.5`}),f(`memory.archive.newMemory`)]})]})]}),(0,X.jsxs)(`fieldset`,{className:`flex flex-wrap gap-4 rounded-lg border border-border/60 bg-background/30 px-3 py-2`,children:[(0,X.jsx)(`legend`,{className:`px-1 text-xs font-medium text-muted-foreground`,children:f(`memory.workspace.filters.status`)}),[`active`,`archived`,`superseded`].map(e=>(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:A.statuses.includes(e),onChange:()=>j(t=>({...t,statuses:t.statuses.includes(e)?t.statuses.filter(t=>t!==e):[...t.statuses,e]}))}),f(`memory.workspace.options.${e}`)]},e))]}),(0,X.jsx)(`div`,{className:`flex items-center justify-between gap-3 text-sm text-muted-foreground`,children:(0,X.jsx)(`span`,{children:f(`memory.workspace.resultCount`,{filtered:xe.length,total:ye.length})})}),S?(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border px-4 py-4 text-sm text-muted-foreground`,children:f(`memory.archive.loadingSavedMemories`)}):xe.length>0?(0,X.jsx)(`div`,{className:`grid gap-3 xl:grid-cols-2`,children:xe.map(e=>(0,X.jsx)(MT,{title:e.title,meta:e.meta,preview:e.preview,archived:e.archived,ariaLabel:f(`memory.archive.openMemoryAriaLabel`,{kind:e.kind,title:e.title}),onClick:()=>{if(e.kind===`convention`){let t=g.find(t=>t.id===e.id);t&&Oe(t)}else{let t=v.find(t=>t.id===e.id);t&&Ae(t)}},accentClassName:e.kind===`convention`?`bg-sky-300/50`:`bg-amber-300/45`},e.id))}):(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border px-4 py-8 text-center text-sm text-muted-foreground`,children:ye.length===0?f(`memory.archive.noSavedMemories`):f(`memory.workspace.noFilterResults`)})]}),(0,X.jsx)(BC,{value:`context`,className:`p-4 sm:p-5`,children:(0,X.jsx)(Gw,{projectId:t??``,summary:P,compatibilityArtifacts:we,isLoading:R,error:ee,scanAction:Ve,onRetry:()=>N(e=>e+1)})})]}),(0,X.jsx)(V_,{open:Ne,onOpenChange:e=>{e||Ee()},children:(0,X.jsx)(U_,{showCloseButton:!1,className:`max-h-[85vh] flex flex-col gap-0 overflow-hidden p-0 sm:max-w-3xl`,children:(0,X.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[(0,X.jsxs)(`div`,{className:`shrink-0 border-b border-border/70 px-5 py-4 sm:px-6`,children:[(0,X.jsxs)(W_,{children:[(0,X.jsx)(K_,{children:m?.id?f(`memory.archive.editMemory`):f(`memory.archive.createMemory`)}),(0,X.jsx)(q_,{children:f(`memory.archive.editorDescription`)})]}),(0,X.jsx)(H_,{asChild:!0,children:(0,X.jsxs)(Q,{variant:`ghost`,size:`icon-sm`,className:`absolute top-4 right-4`,children:[(0,X.jsx)(ax,{className:`size-4`}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Close`})]})})]}),(0,X.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4 sm:px-6`,children:[(0,X.jsx)(PT,{origin:Pe?.origin??Fe?.origin,onNavigateToSource:d}),t&&Ie&&(0,X.jsx)(Lw,{projectId:t,memory:Ie}),(0,X.jsx)(NT,{draft:E,onChange:D,onCancel:Ee,onSubmit:()=>{De()},isSaving:O,submitLabel:m?.id?f(`memory.archive.saveMemory`):f(`memory.archive.createMemory`),layout:`dialog`,allowKindChange:m?.id==null,supplementaryActions:Fe?.status===`accepted`&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,X.jsx)(pv,{label:f(`memory.archive.replacementDecision`),triggerLabel:v.find(e=>e.id===ae)?.title??f(`memory.archive.selectReplacementDecision`),triggerAriaLabel:f(`memory.archive.replacementDecision`),selectId:`memory-replacement-decision`,groups:[{label:``,options:v.filter(e=>e.status===`accepted`&&e.id!==Fe.id).map(e=>({value:e.id,label:e.title}))}],selectedValue:ae,onChange:G,className:`min-w-48 flex-1`,triggerClassName:`h-9`}),(0,X.jsx)(Q,{type:`button`,variant:`outline`,disabled:!ae,onClick:()=>le(!0),children:f(`memory.archive.supersede`)})]})})]}),(0,X.jsx)(`div`,{className:`shrink-0 border-t border-border/70 px-5 py-4 sm:px-6`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,X.jsx)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 sm:flex-1`,children:Pe?Pe.status===`active`?(0,X.jsx)(Q,{type:`button`,variant:`warning`,onClick:()=>{je(Pe,`archive`).then(e=>{e&&Te()})},children:f(`memory.archive.archive`)}):(0,X.jsx)(Q,{type:`button`,variant:`outline`,onClick:()=>{je(Pe,`restore`).then(e=>{e&&Te()})},children:f(`memory.archive.restore`)}):Fe?Fe.status===`accepted`?(0,X.jsx)(Q,{type:`button`,variant:`warning`,onClick:()=>{Me(Fe,`archive`).then(e=>{e&&Te()})},children:f(`memory.archive.archive`)}):(0,X.jsx)(Q,{type:`button`,variant:`outline`,onClick:()=>{Me(Fe,`restore`).then(e=>{e&&Te()})},children:f(`memory.archive.restore`)}):null}),(0,X.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2`,children:[(0,X.jsx)(Q,{type:`button`,variant:`ghost`,onClick:Ee,children:f(`memory.editor.cancel`)}),(0,X.jsx)(Q,{type:`button`,variant:`success`,onClick:()=>{De()},disabled:O||!E.title.trim()||!E.content.trim(),children:O?f(`memory.editor.saving`):m?.id?f(`memory.archive.saveMemory`):f(`memory.archive.createMemory`)})]})]})})]})})}),(0,X.jsx)(V_,{open:oe,onOpenChange:se,children:(0,X.jsxs)(U_,{className:`sm:max-w-md`,children:[(0,X.jsxs)(W_,{children:[(0,X.jsx)(K_,{children:f(`memory.workspace.dirtyCloseTitle`)}),(0,X.jsx)(q_,{children:f(`memory.workspace.dirtyCloseDescription`)})]}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,X.jsx)(Q,{type:`button`,variant:`ghost`,onClick:()=>se(!1),children:f(`memory.workspace.keepEditing`)}),(0,X.jsx)(Q,{type:`button`,variant:`warning`,onClick:()=>{se(!1),Te()},children:f(`memory.workspace.discardChanges`)})]})]})}),(0,X.jsx)(V_,{open:ce,onOpenChange:le,children:(0,X.jsxs)(U_,{className:`sm:max-w-md`,children:[(0,X.jsxs)(W_,{children:[(0,X.jsx)(K_,{children:f(`memory.workspace.supersedeTitle`)}),(0,X.jsx)(q_,{children:f(`memory.workspace.supersedeDescription`,{current:Fe?.title,replacement:v.find(e=>e.id===ae)?.title})})]}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,X.jsx)(Q,{type:`button`,variant:`ghost`,onClick:()=>le(!1),children:f(`memory.editor.cancel`)}),(0,X.jsx)(Q,{type:`button`,variant:`warning`,onClick:()=>{Fe&&Me(Fe,`supersede`).then(e=>{e&&(le(!1),Te())})},children:f(`memory.archive.supersede`)})]})]})})]}):(0,X.jsxs)(`div`,{className:`space-y-5`,children:[l&&(0,X.jsx)(`div`,{className:`rounded-2xl border border-border/70 bg-background/25 p-4`,children:(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:f(`memory.activation.title`)}),(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:f(`memory.activation.description`)})]}),(0,X.jsx)(nw,{"aria-label":f(`memory.activation.ariaLabel`),checked:n,onCheckedChange:i})]})}),l&&(0,X.jsxs)(`div`,{className:`space-y-4 rounded-2xl border border-border/70 bg-background/25 p-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:f(`memory.scanControls.title`)}),(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:f(`memory.scanControls.description`)})]}),(0,X.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,X.jsx)(dC,{label:f(`memory.scanControls.includeLabel`),description:f(`memory.scanControls.includeDescription`),children:(0,X.jsx)(Y_,{"aria-label":f(`memory.scanControls.includeAriaLabel`),value:a,rows:4,placeholder:f(`memory.scanControls.includePlaceholder`),onChange:e=>s?.(e.target.value)})}),(0,X.jsx)(dC,{label:f(`memory.scanControls.excludeLabel`),description:f(`memory.scanControls.excludeDescription`),children:(0,X.jsx)(Y_,{"aria-label":f(`memory.scanControls.excludeAriaLabel`),value:o,rows:4,placeholder:f(`memory.scanControls.excludePlaceholder`),onChange:e=>c?.(e.target.value)})})]}),(0,X.jsx)(`p`,{className:`text-xs leading-5 text-muted-foreground`,children:f(`memory.scanControls.disclosure`)})]}),Be]})},IT=e=>typeof e!=`string`&&e?.provider?.trim()?e.provider.trim().toLowerCase():(typeof e==`string`?e:e?.id)?.split(`/`)[0]?.trim().toLowerCase()||``,LT=(e,t)=>{if(!t)return e;let n=new Set(t.map(e=>e.trim().toLowerCase()));return e.filter(e=>n.has(IT(e)))},RT=/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/,zT=/^\d{1,3}(?:\.\d{1,3}){3}$/,BT=e=>e.trim().toLowerCase(),VT=e=>{let t=BT(e.host);if(!t)return`missing_host`;if(new TextEncoder().encode(t).length>253)return`invalid_host`;let n=t.startsWith(`*.`)?t.slice(2):t;return n.includes(`:`)||zT.test(n)||!RT.test(n)?`invalid_host`:e.port!==void 0&&(!Number.isInteger(e.port)||e.port<1||e.port>65535)?`invalid_port`:e.purpose!==void 0&&(e.purpose.trim().length===0||e.purpose.length>256)?`invalid_purpose`:null},HT=e=>e.mode===`unrestricted`?e.destinations.length===0:e.destinations.length>0&&e.destinations.length<=32&&e.destinations.every(e=>VT(e)===null),UT=e=>{if(e.trim()!==``)return Number(e)},WT=(e,t)=>({host:e.host,...t===void 0?{}:{port:t},...e.purpose===void 0?{}:{purpose:e.purpose}}),GT=(e,t)=>({host:e.host,...e.port===void 0?{}:{port:e.port},...t===void 0?{}:{purpose:t}}),KT=(e,t,n)=>{if(t)return{requested_mode:n??`unrestricted`,observed_global_posture:t.observed_global_posture,enforcement:t.enforcement,decisions:t.decisions};let r=e.flatMap(e=>e.kind!==`network`||typeof e.details?.network_target!=`string`?[]:[{target:e.details.network_target,decision:e.details.network_decision??`unknown`,state:e.state}]);return r.length===0&&n!==`allowlist`?{requested_mode:`unrestricted`,observed_global_posture:`none_initialized`,enforcement:`none`,decisions:[]}:r.length===0?{requested_mode:`allowlist`,observed_global_posture:`unknown`,enforcement:`unknown`,decisions:[]}:{requested_mode:n??`allowlist`,observed_global_posture:r.some(e=>e.decision===`deny`)?`mixed`:`unknown`,enforcement:`unknown`,decisions:r}},qT=({title:e,children:t,defaultOpen:n=!1})=>(0,X.jsxs)(SC,{defaultOpen:n,className:`mt-5 rounded-2xl border border-border/70 bg-background/25`,children:[(0,X.jsx)(CC,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,"aria-label":e,className:`group flex w-full items-center gap-2 rounded-2xl px-4 py-3 text-left outline-none transition-colors hover:bg-accent/40 focus-visible:ring-2 focus-visible:ring-ring/60`,children:[(0,X.jsx)(`span`,{className:`min-w-0 flex-1 text-sm font-semibold text-foreground`,children:e}),(0,X.jsx)(bv,{className:`size-4 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-180`})]})}),(0,X.jsx)(wC,{className:`border-t border-border/60 px-4 py-3`,children:t})]}),JT=[`host`,`docker_sandbox`],YT=({value:e,runtimeStatus:t,onChange:n})=>{let{t:r}=q(`projects`,{keyPrefix:`execution`});return(0,X.jsxs)(`fieldset`,{children:[(0,X.jsx)(`legend`,{className:`text-sm font-semibold text-foreground`,children:r(`provider.title`)}),(0,X.jsx)(`p`,{className:`mt-1 max-w-2xl text-sm text-muted-foreground`,children:r(`provider.description`)}),(0,X.jsx)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2`,children:JT.map(i=>(0,X.jsxs)(`label`,{className:Z(`flex min-w-0 cursor-pointer gap-3 rounded-2xl border p-4 transition-colors focus-within:ring-2 focus-within:ring-ring/60`,e===i?`border-sky-400/45 bg-sky-500/10`:`border-border/70 bg-card/40 hover:border-border`),children:[(0,X.jsx)(`input`,{type:`radio`,name:`build-execution-provider`,value:i,checked:e===i,onChange:()=>n(i),className:`mt-1 size-4 shrink-0 accent-sky-400`}),(0,X.jsxs)(`span`,{className:`min-w-0`,children:[(0,X.jsx)(`span`,{className:`block text-sm font-semibold text-foreground`,children:r(`provider.${i}.label`)}),(0,X.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-muted-foreground`,children:r(`provider.${i}.description`)}),i===`docker_sandbox`&&(0,X.jsx)(`span`,{role:`status`,className:Z(`mt-2 block text-xs font-medium`,t===`ready`||t===`eligible`?`text-emerald-200`:`text-amber-200`),children:r(`provider.docker_sandbox.status.${t}`)})]})]},i))})]})},XT=e=>({...e,eligible_workloads:[...e.eligible_workloads],check_template_policy:{...e.check_template_policy},workspace_access:{...e.workspace_access,additional_mounts:[]},credential_requirements:e.credential_requirements.map(e=>({...e})),network:{mode:e.network.mode,destinations:e.network.destinations.map(e=>({...e}))}}),ZT=(e,t)=>e!==null&&t!==null&&JSON.stringify(e)===JSON.stringify(t),QT=(e,t)=>{if(t===`docker_sandbox`)return{...e,compatibility:`governed`,provider_preference:t,isolation:`microvm_required`,fallback:`block`,credential_requirements:e.credential_requirements.map(e=>({...e,required_protection:`docker_brokered`}))};let n=e.compatibility===`legacy_host`?`legacy_host`:`governed`;return{...e,compatibility:n,provider_preference:t,isolation:`host_process_allowed`,fallback:`block`,credential_requirements:n===`legacy_host`?e.credential_requirements.map(e=>({...e,required_protection:`legacy_host_inheritance`})):[],network:{mode:`unrestricted`,destinations:[]}}},$T=e=>e.compatibility===`legacy_host`?e.provider_preference===`host`&&e.isolation===`host_process_allowed`&&e.fallback===`block`&&e.network.mode===`unrestricted`&&e.credential_requirements.every(e=>e.required_protection===`legacy_host_inheritance`):e.provider_preference===`host`?e.isolation===`host_process_allowed`&&e.credential_requirements.length===0&&e.network.mode===`unrestricted`:e.credential_requirements.every(e=>e.required_protection===`docker_brokered`)&&(e.fallback!==`explicit_host`||e.isolation===`host_process_allowed`),eE=(e,t)=>{let n=`${e}_model_auth`,r=n,i=2;for(;t.some(e=>e.id===r);)r=`${n}_${i}`,i+=1;return r},tE=({compatibility:e,index:t,provider:n,providers:r,requirement:i,onChange:a,onRemove:o})=>{let{t:s}=q(`projects`,{keyPrefix:`execution`}),c=n===`docker_sandbox`?`docker_brokered`:e===`legacy_host`?`legacy_host_inheritance`:null,l=Array.from(new Set([...i.model_provider?[i.model_provider]:[],...i.agent===`claude`?[`anthropic`]:r]));return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/60 bg-background/25 p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,X.jsx)(`p`,{className:`text-xs font-semibold text-foreground`,children:s(`profile.credential.item`,{count:t+1})}),(0,X.jsx)(Q,{type:`button`,size:`xs`,variant:`ghost`,onClick:o,children:s(`profile.credential.remove`)})]}),(0,X.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[s(`profile.credential.agent`),(0,X.jsxs)(`select`,{value:i.agent,onChange:e=>{let t=e.target.value;a({...i,agent:t,model_provider:t===`claude`?`anthropic`:r[0]??i.model_provider})},className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground`,children:[(0,X.jsx)(`option`,{value:`opencode`,children:s(`agent.opencode`)}),(0,X.jsx)(`option`,{value:`claude`,children:s(`agent.claude`)})]})]}),(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[s(`profile.credential.modelProvider`),(0,X.jsx)(`select`,{value:i.model_provider,onChange:e=>a({...i,model_provider:e.target.value}),disabled:i.agent===`claude`,className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground disabled:opacity-60`,children:l.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})]}),(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[s(`profile.credential.authentication`),(0,X.jsxs)(`select`,{value:i.authentication_mode,onChange:e=>a({...i,authentication_mode:e.target.value}),className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground`,children:[(0,X.jsx)(`option`,{value:`api_key`,children:s(`profile.authentication.api_key`)}),(0,X.jsx)(`option`,{value:`oauth`,children:s(`profile.authentication.oauth`)})]})]}),(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[s(`profile.credential.protection`),(0,X.jsxs)(`select`,{value:i.required_protection,onChange:e=>a({...i,required_protection:e.target.value}),disabled:!c,className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground disabled:opacity-60`,children:[(0,X.jsx)(`option`,{value:`docker_brokered`,disabled:c!==`docker_brokered`,children:s(`profile.protection.docker_brokered`)}),(0,X.jsx)(`option`,{value:`legacy_host_inheritance`,disabled:c!==`legacy_host_inheritance`,children:s(`profile.protection.legacy_host_inheritance`)})]})]})]})]})},nE=({index:e,destination:t,onChange:n,onRemove:r})=>{let{t:i}=q(`projects`,{keyPrefix:`execution`}),a=VT(t);return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/60 bg-background/25 p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,X.jsx)(`p`,{className:`text-xs font-semibold text-foreground`,children:i(`profile.network.destination.item`,{count:e+1})}),(0,X.jsx)(Q,{type:`button`,size:`xs`,variant:`ghost`,onClick:r,"aria-label":i(`profile.network.destination.removeAria`,{count:e+1}),children:i(`profile.credential.remove`)})]}),(0,X.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]`,children:[(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[i(`profile.network.destination.host`),(0,X.jsx)(`input`,{type:`text`,value:t.host,onChange:e=>n({...t,host:BT(e.target.value)}),placeholder:i(`profile.network.destination.hostPlaceholder`),"aria-label":i(`profile.network.destination.hostAria`,{count:e+1}),className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground`})]}),(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[i(`profile.network.destination.port`),(0,X.jsx)(`input`,{type:`number`,min:1,max:65535,step:1,value:t.port??``,onChange:e=>{n(WT(t,UT(e.target.value)))},placeholder:i(`profile.network.destination.portPlaceholder`),"aria-label":i(`profile.network.destination.portAria`,{count:e+1}),className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground`})]})]}),(0,X.jsxs)(`label`,{className:`mt-3 block text-xs text-muted-foreground`,children:[i(`profile.network.destination.purpose`),(0,X.jsx)(`input`,{type:`text`,value:t.purpose??``,onChange:e=>{n(GT(t,e.target.value.trim()===``?void 0:e.target.value))},"aria-label":i(`profile.network.destination.purposeAria`,{count:e+1}),className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground`})]}),a&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-red-300`,role:`alert`,children:i(`profile.network.error.${a}`)})]})},rE=({projectId:e,availableModels:t,dockerRuntimeReady:n,dockerRuntimeStatus:r,target:i,onDirtyChange:a,onDraftChange:o,onRevisionChange:s,onProviderSaved:c})=>{let{t:l}=q(`projects`,{keyPrefix:`execution`}),[u,d]=(0,p.useState)(null),[f,m]=(0,p.useState)(null),[h,g]=(0,p.useState)(null),[_,v]=(0,p.useState)(!1),y=(0,p.useRef)(e);y.current=e;let b=Array.from(new Set((t??[]).map(IT).filter(Boolean))),x=!!(u&&f&&!ZT(u.profile,f)),S=!!(f&&$T(f)),C=!!(f&&HT(f.network)),w=!!(f&&(f.provider_preference===`host`||n));(0,p.useEffect)(()=>{let t=new AbortController;return d(null),m(null),g(null),v(!1),Xb(e,t.signal).then(t=>{y.current===e&&(d(t.profile_revision),m(XT(t.profile_revision.profile)))}).catch(t=>{!Ye(t)&&y.current===e&&g(l(`profile.loadError`))}),()=>t.abort()},[e,l]),(0,p.useEffect)(()=>(a(x),()=>a(!1)),[x,a]),(0,p.useEffect)(()=>{f&&o(f.provider_preference,x)},[x,f,o]),(0,p.useEffect)(()=>(s(u?.fingerprint??null),()=>s(null)),[s,u?.fingerprint]);let T=e=>{m(t=>t&&{...t,...e}),g(null)},E=async()=>{if(!u||!f||!x||!S||!C||!w||_)return;v(!0),g(null);let t=e;try{let n=await Zb(e,f,u.id);y.current===t&&await c?.(n.profile_revision.profile.provider_preference),y.current===t&&(d(n.profile_revision),m(XT(n.profile_revision.profile)))}catch(e){if(!Ye(e)&&y.current===t){let t=e instanceof Ge&&typeof e.data==`object`&&e.data!==null?e.data:null;g(t?.reason===`stale_profile_revision`?l(`profile.staleError`):t?.reason===`payload_too_large`?l(`profile.payloadTooLargeError`):t?.reason===`invalid_profile`&&typeof t.error==`string`&&t.error?l(`profile.invalidDetailError`,{detail:t.error}):l(`profile.saveError`))}}finally{y.current===t&&v(!1)}};return!f||!u?(0,X.jsx)(`p`,{className:h?`text-sm text-red-300`:`text-sm text-muted-foreground`,role:h?`alert`:`status`,children:h??l(`profile.loading`)}):(0,X.jsxs)(`section`,{className:`space-y-4`,children:[(0,X.jsx)(YT,{value:f.provider_preference,runtimeStatus:r,onChange:e=>T(QT(f,e))}),(0,X.jsxs)(qT,{title:l(`advanced.title`),children:[(0,X.jsx)(`p`,{className:`max-w-2xl text-xs text-muted-foreground`,children:l(`advanced.description`)}),(0,X.jsxs)(`div`,{className:`mt-4 grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[l(`profile.isolation`),(0,X.jsxs)(`select`,{value:f.isolation,onChange:e=>{let t=e.target.value;T({isolation:t,fallback:t===`microvm_required`?`block`:f.fallback})},className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground`,children:[(0,X.jsx)(`option`,{value:`host_process_allowed`,children:l(`profile.isolationOption.host_process_allowed`)}),(0,X.jsx)(`option`,{value:`microvm_required`,disabled:f.provider_preference===`host`,children:l(`profile.isolationOption.microvm_required`)})]})]}),(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[l(`profile.fallback`),(0,X.jsxs)(`select`,{value:f.fallback,onChange:e=>T({fallback:e.target.value}),disabled:f.compatibility===`legacy_host`||f.isolation===`microvm_required`,className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground disabled:opacity-60`,children:[(0,X.jsx)(`option`,{value:`block`,children:l(`profile.fallbackOption.block`)}),(0,X.jsx)(`option`,{value:`explicit_host`,disabled:f.compatibility===`legacy_host`||f.isolation===`microvm_required`,children:l(`profile.fallbackOption.explicit_host`)})]})]})]}),(0,X.jsxs)(`fieldset`,{className:`mt-5 border-t border-border/60 pt-4`,children:[(0,X.jsx)(`legend`,{className:`text-sm font-semibold text-foreground`,children:l(`profile.credential.title`)}),(0,X.jsx)(`p`,{className:`mt-1 max-w-2xl text-xs text-muted-foreground`,children:l(`profile.credential.description`)}),(0,X.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[f.credential_requirements.map((e,t)=>(0,X.jsx)(tE,{compatibility:f.compatibility,index:t,provider:f.provider_preference,providers:b,requirement:e,onChange:t=>T({credential_requirements:f.credential_requirements.map(n=>n.id===e.id?t:n)}),onRemove:()=>T({credential_requirements:f.credential_requirements.filter(t=>t.id!==e.id)})},e.id)),f.credential_requirements.length===0&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`profile.credential.none`)}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,disabled:f.provider_preference===`host`&&f.compatibility===`governed`,onClick:()=>{let e=b.length>0?`opencode`:`claude`;T({credential_requirements:[...f.credential_requirements,{id:eE(e,f.credential_requirements),purpose:`model_authentication`,workload:`build`,agent:e,model_provider:b[0]??`anthropic`,authentication_mode:`api_key`,required_protection:f.provider_preference===`docker_sandbox`?`docker_brokered`:`legacy_host_inheritance`}]})},children:l(`profile.credential.add`)})]})]}),(0,X.jsxs)(`fieldset`,{className:`mt-5 border-t border-border/60 pt-4`,children:[(0,X.jsx)(`legend`,{className:`text-sm font-semibold text-foreground`,children:l(`profile.network.title`)}),(0,X.jsx)(`p`,{className:`mt-1 max-w-2xl text-xs text-muted-foreground`,children:l(`profile.network.description`)}),(0,X.jsxs)(`label`,{className:`mt-3 block max-w-xs text-xs text-muted-foreground`,children:[l(`profile.network.mode`),(0,X.jsxs)(`select`,{value:f.network.mode,onChange:e=>{let t=e.target.value;T({network:{mode:t,destinations:t===`allowlist`?f.network.destinations:[]}})},"aria-label":l(`profile.network.modeAria`),className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground`,children:[(0,X.jsx)(`option`,{value:`unrestricted`,children:l(`profile.network.modeOption.unrestricted`)}),(0,X.jsx)(`option`,{value:`allowlist`,disabled:f.provider_preference===`host`,children:l(`profile.network.modeOption.allowlist`)})]})]}),f.network.mode===`allowlist`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`mt-3 flex items-baseline justify-between gap-3`,children:[(0,X.jsx)(`p`,{className:`text-xs font-semibold text-foreground`,children:l(`profile.network.destination.title`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`profile.network.destination.count`,{count:f.network.destinations.length,max:32})})]}),(0,X.jsx)(`p`,{className:`mt-1 max-w-2xl text-xs text-muted-foreground`,children:l(`profile.network.destination.description`)}),(0,X.jsxs)(`div`,{className:`mt-3 max-h-96 space-y-3 overflow-y-auto pr-1`,children:[f.network.destinations.map((e,t)=>(0,X.jsx)(nE,{index:t,destination:e,onChange:e=>T({network:{mode:f.network.mode,destinations:f.network.destinations.map((n,r)=>r===t?e:n)}}),onRemove:()=>T({network:{mode:f.network.mode,destinations:f.network.destinations.filter((e,n)=>n!==t)}})},t)),f.network.destinations.length===0&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`profile.network.destination.none`)})]}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,disabled:f.network.destinations.length>=32,onClick:()=>T({network:{mode:f.network.mode,destinations:[...f.network.destinations,{host:``}]}}),children:l(`profile.network.destination.add`)}),f.network.destinations.length===0&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-red-300`,role:`alert`,children:l(`profile.network.error.empty_allowlist`)}),f.network.destinations.length>=32&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-amber-200`,role:`status`,children:l(`profile.network.limitReached`,{count:32})}),f.provider_preference===`host`&&(0,X.jsx)(`p`,{className:`mt-3 rounded-xl border border-amber-400/20 bg-amber-500/8 p-3 text-xs text-amber-100`,children:l(`profile.network.hostProviderWarning`)})]})]}),i&&(0,X.jsxs)(`section`,{className:`mt-5 border-t border-border/60 pt-4`,children:[(0,X.jsx)(`h4`,{className:`font-semibold text-foreground`,children:l(`target.title`)}),(0,X.jsxs)(`dl`,{className:`mt-3 grid gap-3 text-sm sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-xs text-muted-foreground`,children:l(`target.selected`)}),(0,X.jsxs)(`dd`,{className:`mt-1 break-words text-foreground`,children:[l(`target.kind.${i.kind}`,{defaultValue:i.kind}),`: `,i.label]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-xs text-muted-foreground`,children:l(`target.path`)}),(0,X.jsx)(`dd`,{className:`mt-1 break-all font-mono text-xs text-foreground`,children:i.workspace_path})]})]}),(0,X.jsx)(`p`,{className:`mt-3 rounded-xl border border-amber-400/20 bg-amber-500/8 p-3 text-xs text-amber-100`,children:l(`target.warning`)})]}),(0,X.jsx)(`p`,{className:`mt-4 break-all border-t border-border/60 pt-4 font-mono text-[11px] text-sky-200`,children:l(`profile.activeFingerprint`,{fingerprint:u.fingerprint})})]}),h&&(0,X.jsx)(`p`,{className:`text-xs text-red-300`,role:`alert`,children:h}),!S&&(0,X.jsx)(`p`,{className:`text-xs text-red-300`,role:`alert`,children:l(`profile.invalidCombination`)}),!C&&(0,X.jsx)(`p`,{className:`text-xs text-red-300`,role:`alert`,children:l(`profile.invalidNetwork`)}),!w&&(0,X.jsx)(`p`,{className:`text-xs text-amber-200`,role:`alert`,children:l(`profile.runtimeBlocked`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`profile.applyDescription`)}),x&&(0,X.jsx)(`p`,{className:`rounded-xl border border-amber-400/20 bg-amber-500/8 p-3 text-xs text-amber-100`,children:l(`profile.unsavedWarning`)}),(0,X.jsx)(Q,{type:`button`,size:`sm`,disabled:!x||!S||!C||!w||_,onClick:()=>void E(),children:l(_?`profile.saving`:`profile.save`)})]})},iE=({evidence:e,showLifecycle:t=!0,showDegraded:n=!0,className:r})=>{let{t:i}=q(`common`,{keyPrefix:`executionEnvironmentBadge`}),a=n&&e.blockingDegradation,o=a?`warning`:e.lifecycleState===`failed`||e.lifecycleState===`unavailable`?`destructive`:e.lifecycleState===`ready`||e.lifecycleState===`running`?`success`:`outline`,s=[i(`provider.${e.provider}`),i(`isolation.${e.isolation}`),...t?[i(`lifecycle.${e.lifecycleState}`)]:[],...a?[i(`degraded`)]:[]];return(0,X.jsx)(rC,{variant:o,className:`max-w-full flex-wrap justify-start whitespace-normal text-left ${r??``}`,"aria-label":i(`ariaLabel`,{evidence:s.join(`, `)}),children:s.join(` · `)})},aE=e=>e===`host`||e===`docker_sandbox`?e:`unknown`,oE=e=>e===`microvm`||e===`host_process`?e:e===`microvm_required`?`microvm`:e===`host_process_allowed`?`host_process`:`unknown`,sE=e=>{if(!e)return null;if(e.relationship===`validation`){let t=e.live_environment;return t?{provider:aE(t.provider_kind),providerVersion:t.provider_version,isolation:t.provider_kind===`docker_sandbox`?`microvm`:`unknown`,lifecycleState:t.lifecycle_state,degradationReasons:[],blockingDegradation:[`cleanup_pending`,`failed`,`unavailable`].includes(t.lifecycle_state),environmentRevision:t.environment_revision,targetKey:t.target_key,placementAvailable:!1}:null}let t=e.authority,n=t?.run_authority,r=aE(n?.effective.provider??t?.provider),i=n?.degradations??t?.degradation_reasons??[];return{provider:r,providerVersion:t?.provider_version??e.live_environment?.provider_version??null,isolation:oE(n?.effective.isolation??t?.capabilities?.isolation??(r===`host`?`host_process`:null)),lifecycleState:e.live_environment?.lifecycle_state??`unknown`,degradationReasons:i,blockingDegradation:i.length>0||r===`unknown`,environmentRevision:t?.environment_revision??e.live_environment?.environment_revision??null,targetKey:t?.target.key??e.live_environment?.target_key??null,placementAvailable:r===`host`||e.placement!==null}},cE=e=>({provider:aE(e.provider_kind),providerVersion:e.provider_version,isolation:oE(e.effective_isolation),lifecycleState:e.lifecycle_state,degradationReasons:e.failure_code?[e.failure_code]:[],blockingDegradation:!!e.failure_code||[`cleanup_pending`,`failed`,`unavailable`].includes(e.lifecycle_state),environmentRevision:e.environment_revision,targetKey:e.target_key,placementAvailable:e.lifecycle_state===`running`}),lE=(e,t)=>{let n=e.runtime_compatibility,r=e.batch_environment;if(!n||!r)return null;let i=aE(r.provider);return{provider:i,providerVersion:n.provider.version,isolation:i===`docker_sandbox`?`microvm`:`host_process`,lifecycleState:`unknown`,degradationReasons:[],blockingDegradation:i===`docker_sandbox`&&!!(t&&!t.placement),environmentRevision:r.environment_revision,targetKey:n.target.key,placementAvailable:i===`host`||!!t?.placement}},uE=[`opencode`,`claude`],dE=(e,t)=>t.target_kind===e.target.kind&&t.target_key===e.target.key&&t.target_workspace_path===e.target.workspace_path,fE=(e,t)=>e.environments.find(n=>n.is_reusable&&n.provider_kind===`docker_sandbox`&&n.agent_identity===t&&dE(e,n)&&n.compatible_agents.includes(t)&&[`ready`,`running`,`stopped`].includes(n.lifecycle_state))??null,pE=(e,t,n)=>n?e.environments.filter(r=>r.provider_kind===`docker_sandbox`&&r.agent_identity===t&&dE(e,r)&&r.execution_profile_fingerprint===n&&r.compatible_agents.includes(t)).sort((e,t)=>t.environment_revision-e.environment_revision)[0]??null:null,mE=(e,t)=>{let n=e.provider_validations?.[t];return n&&n.length>0?n:e.model_validations?.[t]??(e.validations[t]?[e.validations[t]]:[])},hE=(e,t,n)=>{let r=fE(e,t);if(!r)return null;let i=mE(r,t);return t===`opencode`?n?i.find(e=>(e.provider||IT(e.model))===n)??null:null:i[0]??null},gE=(e,t,n)=>{if(!e)return null;let r=mE(e,t);return t===`opencode`?n?r.find(e=>(e.provider||IT(e.model))===n)??null:null:r[0]??null},_E=(e,t,n)=>e.environments.filter(t=>dE(e,t)).flatMap(e=>mE(e,t).filter(e=>t!==`opencode`||!!(n&&(e.provider||IT(e.model))===n)).map(t=>({environment:e,validation:t}))).sort((e,t)=>Date.parse(t.validation.run.created_at)-Date.parse(e.validation.run.created_at))[0]??null,vE=(e,t,n,r)=>pE(e,t,n)??fE(e,t)??_E(e,t,r)?.environment??null,yE=({check:e,runId:t,correlationId:n})=>{let{t:r}=q(`projects`,{keyPrefix:`execution`});if(e.state!==`failed`||!e.evidence)return null;let i=e.details?.destination_reason,a=e.details?.reason,o=e.details?.provider_error;return(0,X.jsxs)(`div`,{className:`mt-2 rounded-lg border border-red-400/15 bg-red-500/5 p-2 text-xs`,children:[(0,X.jsx)(`p`,{className:`font-medium text-red-100`,children:r(`validation.evidence.title`,{check:r(`validation.checkKind.${e.kind}`)})}),a&&(0,X.jsx)(`p`,{className:`mt-1 text-red-200`,children:r(`validation.checkReason.${a}`,{defaultValue:a})}),i&&(0,X.jsx)(`p`,{className:`mt-1 text-red-200`,children:r(`validation.evidence.reason`,{reason:r(`validation.destinationReason.${i}`,{defaultValue:i})})}),o?.name&&(0,X.jsx)(`p`,{className:`mt-1 text-red-200`,children:r(`validation.evidence.providerName`,{name:o.name})}),o?.message&&(0,X.jsx)(`p`,{className:`mt-1 break-words text-red-100`,children:r(`validation.evidence.providerMessage`,{message:o.message})}),o?.reference&&(0,X.jsx)(`p`,{className:`mt-1 break-all font-mono text-red-100`,children:r(`validation.evidence.providerReference`,{reference:o.reference})}),o&&(0,X.jsx)(`p`,{className:`mt-1 break-all font-mono text-red-200/75`,children:r(`validation.evidence.runReference`,{runId:t,correlationId:n})}),(0,X.jsx)(`p`,{className:`mt-1 break-words font-mono text-red-100/85`,children:e.evidence.summary}),(0,X.jsxs)(`p`,{className:`mt-1 text-red-200/75`,children:[r(`validation.evidence.exitCode`,{code:e.evidence.exit_code??r(`validation.evidence.exitCodeUnknown`)}),e.evidence.truncated&&` ${r(`validation.evidence.truncated`)}`]})]})},bE={enforced_scoped:`text-sky-200`,declarative_only:`text-amber-200`,unknown:`text-amber-200`,none:`text-muted-foreground`},xE={allow:`text-sky-200`,deny:`text-red-200`,unknown:`text-amber-200`},SE=({validation:e})=>{let{t}=q(`projects`,{keyPrefix:`execution`}),n=KT(e.checks,e.network_evidence,e.requested_network_mode);return(0,X.jsxs)(`div`,{className:`mt-3 rounded-lg border border-border/60 bg-background/25 p-2`,children:[(0,X.jsx)(`p`,{className:`text-xs font-medium text-foreground`,children:t(`validation.network.title`)}),(0,X.jsxs)(`dl`,{className:`mt-1 grid gap-x-4 gap-y-1 text-xs sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`validation.network.modeLabel`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:t(`validation.network.mode.${n.requested_mode}`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`validation.network.postureLabel`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:t(`validation.network.posture.${n.observed_global_posture}`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`validation.network.enforcementLabel`)}),(0,X.jsx)(`dd`,{className:Z(`mt-0.5`,bE[n.enforcement]),children:t(`validation.network.enforcement.${n.enforcement}`)})]})]}),n.enforcement===`declarative_only`&&(0,X.jsx)(`p`,{className:`mt-1 text-xs text-amber-200`,children:t(`validation.network.enforcementNote.declarative_only`)}),n.enforcement===`unknown`&&(0,X.jsx)(`p`,{className:`mt-1 text-xs text-amber-200`,children:t(`validation.network.enforcementNote.unknown`)}),n.decisions.length>0&&(0,X.jsx)(`ul`,{className:`mt-2 max-h-40 space-y-1 overflow-y-auto pr-1 text-xs`,"aria-label":t(`validation.network.decisionsLabel`),children:n.decisions.map(e=>(0,X.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`break-all font-mono text-foreground`,children:e.target}),(0,X.jsx)(`span`,{className:xE[e.decision],children:t(`validation.network.decision.${e.decision}`)}),e.state===`cancelled`&&(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:t(`validation.network.staleDecision`)})]},`${e.target}:${e.state}`))}),n.decisions.some(e=>e.decision===`deny`)&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-amber-200`,children:t(`validation.network.degradation.denied`)}),n.enforcement===`unknown`&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:t(`validation.network.degradation.unknown`)})]})},CE=({environment:e})=>{let{t}=q(`projects`,{keyPrefix:`execution`}),n=e.disk_evidence;return(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(iE,{evidence:cE(e)}),(0,X.jsxs)(`dl`,{className:`grid gap-x-4 gap-y-2 text-xs sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`environment.lastUsed`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:e.last_used_at?new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e.last_used_at)):t(`unknown`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`environment.idlePolicy`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:e.idle_stop_at?t(`environment.idleScheduled`,{value:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e.idle_stop_at))}):t(`environment.idleOnRelease`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`environment.machineDisk`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:n?.machine_storage.state===`ready`?t(`environment.diskAvailable`,{value:(e=>e===null?t(`unknown`):new Intl.NumberFormat(void 0,{style:`unit`,unit:`gigabyte`,maximumFractionDigits:1}).format(e/1e9))(n.machine_storage.available_bytes)}):t(`environment.diskState.${n?.machine_storage.state??`unknown`}`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`environment.privateDisk`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 break-words text-foreground`,children:t(`environment.privateDiskUnsupported`)})]}),e.cleanup_retry_at&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`environment.cleanupRetry`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e.cleanup_retry_at))})]})]})]})},wE=({environment:e,isCurrent:t,validation:n})=>{let{t:r}=q(`projects`,{keyPrefix:`execution`}),i=new Map(n.checks.map(e=>[e.kind,e.state])),a=n.checks.find(e=>e.kind===`authentication`),o=i.get(`authentication`),s=a?.details?.credential_source,c=n.credential_capability?.classification,l=c?r(`credentialClassification.${c}`):s===`brokered`&&a?.details?.credential_service?r(`credentialSource.brokeredWithService`,{service:a.details.credential_service}):r(s?`credentialSource.${s}`:`unknown`),u=i.get(`destination`),d=i.get(`skills`),f=n.checks.find(e=>e.kind===`executable`)?.details?.runtime_version,p=n.checks.find(e=>e.kind===`skills`)?.details?.available_skills?.length??0;return(0,X.jsxs)(`div`,{className:`space-y-3`,children:[!t&&(0,X.jsx)(`p`,{className:`mb-3 rounded-lg border border-amber-400/20 bg-amber-500/8 p-2 text-xs text-amber-100`,children:r(`validation.stale`)}),(0,X.jsxs)(`dl`,{className:`grid gap-x-4 gap-y-2 text-xs sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.runState`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:r(`runState.${n.run.status}`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.provider`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 break-all font-mono text-foreground`,children:n.provider??r(`validation.providerNotSelected`)})]}),n.model&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.probeModel`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 break-all font-mono text-foreground`,children:n.model})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.isolation`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:r(`isolation.${e.effective_isolation}`,{defaultValue:e.effective_isolation})})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.template`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 break-all text-foreground`,children:e.template_identity??e.template_digest??r(`unknown`)})]}),f&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.runtimeVersion`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 font-mono text-foreground`,children:f})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.authentication`)}),(0,X.jsxs)(`dd`,{className:`mt-0.5 text-foreground`,children:[r(o?`checkState.${o}`:`unknown`),` (`,l,`)`]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.skills`)}),(0,X.jsxs)(`dd`,{className:`mt-0.5 text-foreground`,children:[r(d?`checkState.${d}`:`unknown`),` (`,p,`)`]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.destinations`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:r(u?`checkState.${u}`:`unknown`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.interruption`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:n.run.status===`interrupted`?r(`validation.interrupted`):r(`validation.notInterrupted`)})]})]}),(0,X.jsx)(SE,{validation:n}),n.run.failure&&(0,X.jsx)(`div`,{className:`mt-3 rounded-lg border border-red-400/25 bg-red-500/8 p-2`,children:(0,X.jsxs)(`p`,{className:`text-xs text-red-200`,children:[(0,X.jsxs)(`span`,{className:`font-medium`,children:[r(`validation.failure`),`: `]}),n.run.failure.code?`${n.run.failure.code}: `:``,n.run.failure.message]})}),n.checks.filter(e=>e.state===`failed`).map(e=>(0,X.jsx)(yE,{check:e,runId:n.run.id,correlationId:n.run.correlation_id},e.kind)),!n.run.status.match(/completed/)&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:r(`validation.remediation`)}),n.credential_capability&&!n.credential_capability.satisfies_requested_protection&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-amber-200`,children:r(`validation.unsupportedRequirement`)})]})},TE=({agent:e,errorMessage:t,isValidating:n,validationRequestActive:r,validationInProgressForOtherContext:i,onValidate:a,onLifecycleOperation:o,pendingOperation:s,state:c,activeProfileFingerprint:l,validationSelectionReady:u,validationProvider:d,validationModel:f,validationBlocked:p,onOpenExecutionRuntimes:m})=>{let{t:h}=q(`projects`,{keyPrefix:`execution`}),g=fE(c,e),_=pE(c,e,l),v=gE(_,e,d),y=_E(c,e,d),b=v&&_?{environment:_,validation:v}:y,x=!!(b&&_&&b.environment.id===_.id&&b.validation.environment_id===_.id),S=!!(x&&b?.validation.run.status===`completed`&&b.validation.run.domain_status===`ready`),C=e!==`opencode`||!!(b&&(b.validation.provider||IT(b.validation.model))===d&&b.validation.model===f),w=!!(x&&b&&C&&[`queued`,`running`,`waiting`].includes(b.validation.run.status)),T=!!(x&&b&&!C&&!S),E=!!(r||_&&mE(_,e).some(e=>[`queued`,`running`,`waiting`].includes(e.run.status))),D=i||!!(E&&!w&&!n),O=!!(t||x&&b&&!S&&!w&&!T),k=b?KT(b.validation.checks,b.validation.network_evidence??void 0,b.validation.requested_network_mode??void 0):null,A=!!(O&&k?.requested_mode===`allowlist`&&k.enforcement!==`enforced_scoped`),j=n||w?`validation.validating`:t?`validation.failed`:T||!b||!x?`validation.notValidated`:S?`validation.ready`:`validation.failed`,M=b?.validation.checks.find(e=>e.state===`failed`),N=M?.details?.destination_reason,P=M?.details?.reason,F=b?.validation.run.failure?.code===`docker_runtime_network_policy_not_ready`?b.validation.run.failure.message:null,I=b?.validation.credential_capability?.remediation??(N?h(`validation.destinationReason.${N}`,{defaultValue:h(`validation.remediation`)}):null)??(P?h(`validation.checkReason.${P}`,{defaultValue:h(`validation.remediation`)}):null)??F??h(`validation.remediation`),L=vE(c,e,l,d),R=s!==null||E||!!L?.operation_kind;return(0,X.jsxs)(`article`,{className:`p-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`h5`,{className:`font-semibold text-foreground`,children:h(`agent.${e}`)}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:h(j)}),t&&(0,X.jsx)(`p`,{className:`mt-2 max-w-2xl text-xs text-red-300`,role:`alert`,children:t}),D&&(0,X.jsx)(`p`,{className:`mt-2 max-w-2xl text-xs text-sky-200`,role:`status`,children:h(`validation.inProgressOtherContext`)}),O&&(0,X.jsx)(`p`,{className:`mt-2 max-w-2xl text-xs text-red-200`,children:h(`validation.failedSummary`)}),O&&(0,X.jsx)(`p`,{className:`mt-1 max-w-2xl text-xs text-muted-foreground`,children:I}),A&&(0,X.jsx)(`p`,{className:`mt-2 max-w-2xl rounded-lg border border-amber-400/20 bg-amber-500/8 p-2 text-xs text-amber-100`,children:h(`validation.network.contextualBlock`)})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,X.jsxs)(Q,{type:`button`,size:`sm`,disabled:p||E||s!==null||e===`opencode`&&!u,onClick:()=>a(g),children:[n&&(0,X.jsx)(ix,{className:`h-4 w-4 animate-spin`}),n?h(`validation.validating`):h(O?`validation.retry`:`validation.action`,{agent:h(`agent.${e}`)})]}),O&&m&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:m,children:h(`runtime.open`)})]})]}),(b||L)&&(0,X.jsxs)(qT,{title:h(S?`validation.details`:`validation.technicalDetails`),children:[L&&(0,X.jsx)(CE,{environment:L}),b&&(0,X.jsx)(wE,{environment:b.environment,validation:b.validation,isCurrent:x}),L&&(0,X.jsxs)(`div`,{className:`mt-4 border-t border-border/60 pt-3`,children:[L.lifecycle_state===`stopped`&&(0,X.jsx)(`p`,{className:`mb-3 text-xs text-muted-foreground`,children:h(`stop.reconnect`)}),(0,X.jsx)(`p`,{className:`mb-3 max-w-2xl text-xs text-amber-100`,children:h(`stop.wholeSandbox`)}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[[`ready`,`running`].includes(L.lifecycle_state)&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,disabled:R,onClick:()=>o(`stop`,L),children:h(s===`stop`?`stop.stopping`:`stop.action`)}),![`retired`,`retiring`,`cleanup_pending`].includes(L.lifecycle_state)&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,disabled:R,onClick:()=>o(`reset`,L),children:h(s===`reset`?`reset.resetting`:`reset.action`)}),![`retired`,`retiring`].includes(L.lifecycle_state)&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,disabled:R,onClick:()=>o(`retire`,L),children:h(s===`retire`?`retire.retiring`:`retire.action`)}),[`cleanup_pending`,`failed`,`unavailable`].includes(L.lifecycle_state)&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,disabled:R,onClick:()=>o(`cleanup_retry`,L),children:h(s===`cleanup_retry`?`cleanupRetry.retrying`:`cleanupRetry.action`)})]})]})]})]})},EE=(e,t,n,r,i)=>e.projectId===n&&(t!==`opencode`||e.provider===r&&e.model===i),DE=(e,t,n,r)=>({projectId:t,provider:e===`opencode`?n:null,model:e===`opencode`?r:null}),OE=(e,t)=>t?`error`:e?e.activation?.state??`blocked`:`loading`,kE=({projectId:e,buildExecutionProvider:t=`host`,onBuildExecutionProviderChange:n,onCreateBlockingChange:r,onOpenExecutionRuntimes:i,onValidationCompleted:a,availableValidationModels:o,isLoadingValidationModels:s=!1,onRetryValidationModels:c})=>{let{t:l}=q(`projects`,{keyPrefix:`execution`}),[u,d]=(0,p.useState)(null),[f,m]=(0,p.useState)(null),[h,g]=(0,p.useState)(null),[_,v]=(0,p.useState)(null),[y,b]=(0,p.useState)({}),[x,S]=(0,p.useState)({}),[C,w]=(0,p.useState)({}),[T,E]=(0,p.useState)({}),[D,O]=(0,p.useState)(``),[k,A]=(0,p.useState)(``),[j,M]=(0,p.useState)(!1),[N,P]=(0,p.useState)(t),[F,I]=(0,p.useState)(null),[L,R]=(0,p.useState)(t===`docker_sandbox`),z=(0,p.useRef)(e),ee=(0,p.useRef)(0),B=(0,p.useRef)(0),V=(0,p.useRef)({}),H=(0,p.useRef)({});z.current=e;let U=(0,p.useCallback)(e=>(g(null),v(null),Jb(e).then(g).catch(e=>{Ye(e)||v(l(`runtime.loadError`))})),[l]);(0,p.useEffect)(()=>{let e=new AbortController;return U(e.signal),()=>e.abort()},[U]);let W=u?.projectId===e?u.value:null,te=f?.projectId===e?f.value:null,ne={},re={};for(let t of uE){let n=y[t];n&&EE(n.context,t,e,D||null,k||null)&&(ne[t]=n.value);let r=x[t],i=W?vE(W,t,F,D||null):null;r&&r.projectId===e&&r.environmentId===i?.id&&(re[t]=r.value)}let ie=Array.from(new Set((o??[]).map(IT).filter(Boolean))),ae=o!==void 0,G=D||null,oe=G?(o??[]).filter(e=>IT(e)===G):[],se=oe.find(e=>e.id===k)??null,ce=!ae||s,le=ae&&!s&&(o?.length??0)===0,ue=!!(ae&&!s&&G&&se),de=e=>`${e}${W&&hE(W,`opencode`,e)?.run.status===`completed`?` - `+l(`validation.verifiedOption`):``}`;(0,p.useEffect)(()=>{if(!o||s)return;let e=new Set(o.map(IT).filter(Boolean));O(t=>e.has(t)?t:``),A(e=>e&&D&&o.some(t=>t.id===e&&IT(t)===D)?e:``)},[o,s,D]);let fe=(0,p.useCallback)(t=>{if(!e||z.current!==e)return Promise.resolve(!1);let n=ee.current+1;return ee.current=n,z.current===e&&m(null),Yb(e,t).then(t=>ee.current===n&&z.current===e?(d({projectId:e,value:t}),m(null),!0):!1).catch(t=>(!Ye(t)&&ee.current===n&&z.current===e&&m({projectId:e,value:l(`loadError`)}),!1))},[e,l]);(0,p.useEffect)(()=>{if(!e)return;let t=new AbortController;return fe(t.signal),()=>t.abort()},[fe,e]),(0,p.useEffect)(()=>(O(``),A(``),b({}),S({}),w({}),V.current={},H.current={},()=>{for(let e of uE)H.current[e]?.abort()}),[e]);let pe=async(t,n)=>{if(!e||j)return;let r=DE(t,e,G,se?.id??null);if(t===`opencode`&&(!ue||!r.provider||!r.model)||V.current[t]?.projectId===e)return;let i=B.current+1;B.current=i;let o={...r,requestId:i},s=new AbortController;H.current={...H.current,[t]:s},V.current={...V.current,[t]:o},w(e=>({...e,[t]:o})),b(e=>({...e,[t]:void 0}));try{await Qb(e,n?.id??null,t,r.provider,r.model,s.signal),z.current===e&&(await fe(),z.current===e&&a?.())}catch(n){if(!Ye(n)&&z.current===e){let e=n instanceof Ge&&n.message.trim()?n.message:l(`validation.error`,{agent:l(`agent.${t}`)});b(n=>({...n,[t]:{context:r,value:e}})),await fe()}}finally{V.current[t]?.requestId===i&&(V.current={...V.current,[t]:void 0}),H.current[t]===s&&(H.current={...H.current,[t]:void 0}),w(e=>e[t]?.requestId===i?{...e,[t]:void 0}:e)}},me=async(t,n,r)=>{if(!e||!window.confirm(l(`${n===`cleanup_retry`?`cleanupRetry`:n}.confirm`)))return;let i=B.current+1;B.current=i;let a={...DE(t,e,G,se?.id??null),requestId:i,operation:n};E(e=>({...e,[t]:a})),S(e=>({...e,[t]:void 0}));try{await(n===`stop`?tx:n===`retire`?nx:n===`cleanup_retry`?rx:$b)(e,r.id),z.current===e&&await fe()}catch(i){!Ye(i)&&z.current===e&&(S(i=>({...i,[t]:{projectId:e,environmentId:r.id,value:l(`${n===`cleanup_retry`?`cleanupRetry`:n}.error`)}})),await fe())}finally{E(e=>e[t]?.requestId===i?{...e,[t]:void 0}:e)}},he=OE(h,_),ge=he===`blocked`||he===`error`||he===`loading`,_e=e?N:t,ve=_e===`docker_sandbox`||L,ye=h?.observations?.filter(e=>e.state!==`ready`)??[];return(0,p.useEffect)(()=>(e||r?.(t===`docker_sandbox`&&ge),()=>r?.(!1)),[t,ge,r,e]),(0,p.useEffect)(()=>{P(t),R(t===`docker_sandbox`)},[t,e]),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[e&&(0,X.jsx)(`div`,{className:`rounded-2xl border border-border/70 bg-background/35 p-4`,children:(0,X.jsx)(rE,{projectId:e,availableModels:o,dockerRuntimeReady:!ge,dockerRuntimeStatus:he,target:W?.target,onDirtyChange:M,onDraftChange:e=>P(e),onRevisionChange:I,onProviderSaved:async t=>{n?.(t),d(t=>t?.projectId===e?null:t),await fe()}})}),!e&&(0,X.jsxs)(`div`,{className:`rounded-2xl border border-border/70 bg-background/35 p-4`,children:[(0,X.jsx)(YT,{value:t,runtimeStatus:he,onChange:e=>n?.(e)}),(0,X.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:l(`create.staged`)})]}),_e===`host`&&!L&&(0,X.jsxs)(`div`,{className:`rounded-2xl border border-sky-400/20 bg-sky-500/7 p-4`,children:[(0,X.jsx)(`h4`,{className:`font-semibold text-foreground`,children:l(`host.title`)}),(0,X.jsx)(`p`,{className:`mt-1 max-w-2xl text-sm text-muted-foreground`,children:l(`host.summary`)}),(0,X.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,X.jsx)(Q,{type:`button`,size:`sm`,onClick:()=>R(!0),children:l(`runtime.setup`)}),i&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:i,children:l(`runtime.open`)})]})]}),ve&&(0,X.jsxs)(`section`,{className:Z(`rounded-2xl border p-4`,ge?`border-amber-400/25 bg-amber-500/8`:`border-border/70 bg-background/35`),children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h4`,{className:`font-semibold text-foreground`,children:l(`runtime.setupTitle`)}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,role:`status`,children:l(`runtime.state.${he}`)})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(he===`error`||he===`blocked`)&&(0,X.jsx)(Q,{type:`button`,size:`sm`,onClick:()=>void U(),children:l(`runtime.retry`)}),i&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:i,children:l(`runtime.open`)})]})]}),ye.length>0&&(0,X.jsx)(`ul`,{className:`mt-3 space-y-2 text-xs text-amber-100`,children:ye.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`span`,{className:`font-medium`,children:e.summary}),e.remediation&&(0,X.jsx)(`span`,{className:`mt-0.5 block text-amber-100/80`,children:e.remediation})]},e.code))}),!e&&(0,X.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:l(`create.validationAfterCreate`)})]}),e&&!W&&ve&&(0,X.jsx)(`p`,{className:te?`text-sm text-red-300`:`text-sm text-muted-foreground`,role:te?`alert`:`status`,children:te??l(`loading`)}),W&&te&&ve&&(0,X.jsx)(`p`,{className:`rounded-xl border border-red-400/25 bg-red-500/8 p-3 text-sm text-red-200`,role:`alert`,children:te}),W&&ve&&(0,X.jsxs)(`div`,{className:`rounded-2xl border border-border/70 bg-background/35`,children:[(0,X.jsxs)(`div`,{className:`border-b border-border/60 p-4`,children:[(0,X.jsx)(`h4`,{className:`font-semibold text-foreground`,children:l(`validation.title`)}),(0,X.jsx)(`p`,{className:`mt-1 max-w-2xl text-xs text-muted-foreground`,children:l(`validation.environmentWillPrepare`)}),j&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-amber-200`,role:`status`,children:l(`validation.saveProfileFirst`)}),ae&&(0,X.jsxs)(`div`,{className:`mt-4 grid max-w-3xl gap-3 sm:grid-cols-[minmax(22rem,1.1fr)_minmax(0,1fr)]`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(pv,{label:l(`validation.providerLabel`),triggerLabel:G?de(G):l(s?`validation.providerLoading`:`validation.providerPlaceholder`),triggerAriaLabel:l(`validation.providerLabel`),selectId:`execution-validation-provider`,selectedValue:D,onChange:e=>{O(e),A((o??[]).find(t=>IT(t)===e)?.id??``)},disabled:s,contentClassName:`min-w-[22rem]`,groups:[{label:``,options:[{value:``,label:l(s?`validation.providerLoading`:`validation.providerPlaceholder`)},...ie.map(e=>({value:e,label:de(e)}))]}]}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:l(`validation.providerDescription`)}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-amber-200`,children:l(`validation.credentialDescription`)}),G&&(0,X.jsx)(`p`,{className:`mt-1 text-xs text-sky-200`,children:l(`validation.credentialSupportEvidence`)})]}),G&&oe.length>0&&!s&&(0,X.jsx)(pv,{label:l(`validation.modelLabel`),triggerLabel:se?.label??l(`validation.modelPlaceholder`),triggerAriaLabel:l(`validation.modelLabel`),selectId:`execution-validation-model`,selectedValue:k,onChange:A,groups:[{label:``,options:oe.map(e=>({value:e.id,label:e.label}))}]})]}),ce&&(0,X.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,role:`status`,children:l(`validation.modelCatalogLoading`)}),le&&(0,X.jsx)(`p`,{className:`mt-3 text-xs text-amber-200`,role:`status`,children:l(`validation.modelCatalogEmpty`)}),(ce||le)&&c&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`mt-3`,onClick:c,children:l(`validation.modelCatalogRetry`)}),ae&&!s&&!le&&ie.length>0&&!G&&(0,X.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,role:`status`,children:l(`validation.providerFirst`)}),G&&!s&&oe.length===0&&(0,X.jsx)(`p`,{className:`mt-3 text-xs text-amber-200`,role:`status`,children:l(`validation.modelUnavailable`)})]}),(0,X.jsx)(`div`,{className:`divide-y divide-border/60`,children:uE.map(t=>(0,X.jsx)(TE,{agent:t,errorMessage:re[t]??ne[t]??null,state:W,activeProfileFingerprint:F,validationRequestActive:C[t]?.projectId===e,validationInProgressForOtherContext:C[t]?.projectId===e&&t===`opencode`&&(C[t]?.provider!==G||C[t]?.model!==k),isValidating:C[t]?.projectId===e&&(t!==`opencode`||C[t]?.provider===G&&C[t]?.model===k),onValidate:e=>void pe(t,e),pendingOperation:T[t]?.projectId===e?T[t]?.operation??null:null,onLifecycleOperation:(e,n)=>void me(t,e,n),validationSelectionReady:t===`claude`||ue,validationProvider:t===`opencode`?G:`anthropic`,validationModel:t===`opencode`?se?.id??null:null,validationBlocked:j,onOpenExecutionRuntimes:i},t))})]})]})},AE=({title:e,description:t,headerAccessory:n,children:r})=>(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 border-b border-border/60 pb-4 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-lg font-semibold text-foreground`,children:e}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:t})]}),n]}),r]}),jE=({label:e,summary:t,tone:n=`default`})=>(0,X.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col items-start text-left`,children:(0,X.jsxs)(`div`,{className:`flex w-full items-start justify-between gap-3`,children:[(0,X.jsx)(`span`,{className:Z(`text-sm font-medium`,n===`danger`?`text-red-200`:`text-foreground`),children:e}),(0,X.jsx)(`span`,{className:Z(`shrink-0 text-[10px] font-semibold uppercase tracking-[0.18em]`,n===`danger`?`text-red-300/80`:`text-muted-foreground`),children:t})]})}),ME=()=>({name:``,cmd:``,cwd:``}),NE=()=>({source:``,target:``,mode:`copy`}),PE=e=>{let t=`check-${crypto.randomUUID()}`,n=0;for(;e.has(t)&&n<32;)t=`check-${crypto.randomUUID()}`,n+=1;if(e.has(t)){let n=1,r=t;for(;e.has(`${r}-${n}`);)n+=1;return`${r}-${n}`}return t},FE=(e=new Set)=>({id:PE(e),name:``,category:`test`,command:``,cwd:``,timeoutMs:String(HC),runner:`auto`,consequence:`ordinary`,required:!1,preReview:!1,postBuild:!1,autoFix:!1}),IE=()=>({name:``,repoPath:``,buildExecutionProvider:`host`,linkedProjectIds:[],runSetup:[],runServices:[],checkDefinitions:[],runIde:``,previewServiceName:``,previewPath:``,previewCapabilityMode:`auto`,helperModel:``,helperVariant:``,reviewerModel:``,reviewerVariant:``,commitMessageRules:``,commitAfterEachTicket:!1,autoParkStaleTickets:!1,memoryEnabled:!1,scanIncludeGlobs:[],scanExcludeGlobs:[],worktreeSync:[],specAwareCodeReviewEnabled:!1,automationDepth:`manual`,automationReviewFixEnabled:!1,automationPauseOnOpenQuestions:!1,automationReviewSeverity:`medium`,automationReviewMaxIterations:3}),LE=(e,t)=>({name:e.name,repoPath:e.repoPath,buildExecutionProvider:e.buildExecutionProvider??`host`,linkedProjectIds:e.linkedProjectIds,runSetupText:e.runSetup.join(`
77
+ `),priority:`normal`,injectionMode:`relevant`}),yT=(e,t)=>e(t===`superseded`?`memory.savedStateLabels.superseded`:t===`archived`?`memory.savedStateLabels.archived`:`memory.savedStateLabels.active`),bT=e=>e!==`active`&&e!==`accepted`,xT=e=>{let t=e?.latest_attempt??e?.scan;return t?.status===`pending`||t?.status===`running`},ST=e=>e.trim().toLowerCase().replace(/_/g,` `).replace(/\s+/g,` `),CT=e=>[...e].sort((e,t)=>{let n=ST(e.title)===`architecture`||ST(e.kind)===`architecture`;return n===(ST(t.title)===`architecture`||ST(t.kind)===`architecture`)?0:n?-1:1}),wT=async(e,t)=>{let[n,r]=await Promise.all([wr(e,t),Or(e,t)]);return{context:n,artifacts:r.artifacts}},TT=e=>({id:e.id,project_id:e.project_id,title:e.title,scope:e.scope,instruction:e.content,rationale:e.rationale,stages:e.stages,path_globs:e.path_globs,component_tags:e.component_tags,priority:e.priority??`normal`,injection_mode:e.injection_mode??`relevant`,status:e.state===`archived`?`archived`:`active`,origin:e.origin??void 0,created_at:e.created_at,updated_at:e.updated_at}),ET=e=>{let t=e.state===`archived`?`archived`:e.state===`superseded`?`superseded`:`accepted`;return{id:e.id,project_id:e.project_id,title:e.title,scope:e.scope,decision:e.content,rationale:e.rationale,implications:e.implications,stages:e.stages,path_globs:e.path_globs,component_tags:e.component_tags,status:t,superseded_by_decision_id:null,origin:e.origin??void 0,created_at:e.created_at,updated_at:e.updated_at}},DT=e=>e.state===`suggested`,OT=async(e,t)=>{let n=await ar(e,t);return{conventions:pT(n.memories.filter(e=>e.kind===`convention`&&(e.state===`active`||e.state===`archived`)).map(TT)),decisions:mT(n.memories.filter(e=>e.kind===`decision`&&(e.state===`active`||e.state===`archived`||e.state===`superseded`)).map(ET)),suggestions:n.memories.filter(DT),generatedContext:n.generated_context}},kT=(e,t)=>t.conflicts.length===0?e(`memory.import.noTitleConflicts`):e(`memory.import.titleConflictCount`,{count:t.conflicts.length}),AT=async(e,t)=>typeof e.text==`function`?await e.text():await new Promise((n,r)=>{let i=new FileReader;i.onerror=()=>{r(Error(t))},i.onload=()=>{n(typeof i.result==`string`?i.result:``)},i.readAsText(e)}),jT=({value:e,onChange:t})=>{let{t:n}=q(`projects`);return(0,X.jsx)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:iT.map(r=>{let i=e.includes(r);return(0,X.jsxs)(`label`,{className:`flex min-w-0 items-start gap-2 rounded-xl border border-border/70 bg-background/30 px-3 py-2 text-sm text-foreground`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:i,className:`mt-0.5 shrink-0`,onChange:()=>{t(i?e.filter(e=>e!==r):[...e,r])}}),(0,X.jsx)(`span`,{className:`min-w-0 break-words leading-5`,children:sT(n,r)})]},r)})})},MT=({title:e,meta:t,preview:n,ariaLabel:r,onClick:i,archived:a=!1,accentClassName:o})=>(0,X.jsxs)(`button`,{type:`button`,onClick:i,"aria-label":r,className:Z(`group relative flex min-h-40 cursor-pointer flex-col justify-between overflow-hidden rounded-xl border border-border/80 bg-background/55 p-4 text-left transition hover:-translate-y-0.5 hover:border-foreground/20 hover:bg-background/72 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60`,a&&`border-border/55 bg-background/30`),children:[(0,X.jsx)(`span`,{className:Z(`absolute inset-y-0 left-0 w-px bg-border/70`,o)}),(0,X.jsxs)(`div`,{className:`space-y-3 pl-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 space-y-2`,children:[(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(e=>(0,X.jsx)(rC,{variant:`outline`,className:`h-5 rounded-md border-border/70 bg-background/80 px-1.5 text-[10px] uppercase tracking-[0.16em] text-muted-foreground`,children:e},e))}),(0,X.jsx)(`h4`,{className:`line-clamp-2 text-sm font-semibold leading-5 text-foreground`,children:e})]}),(0,X.jsx)(`span`,{className:`mt-0.5 rounded-md border border-border/70 bg-background/80 p-1.5 text-muted-foreground transition group-hover:border-foreground/20 group-hover:text-foreground`,children:(0,X.jsx)(yw,{className:`size-3.5`})})]}),(0,X.jsx)(`p`,{className:`line-clamp-2 whitespace-pre-wrap text-sm leading-5 text-muted-foreground`,children:n})]})]}),NT=({draft:e,onChange:t,onCancel:n,onSubmit:r,isSaving:i,submitLabel:a,layout:o=`inline`,supplementaryActions:s,allowKindChange:c=!0})=>{let{t:l}=q(`projects`),u=e.kind===`convention`,d=e.title.trim()?null:l(`memory.validation.titleRequired`),f=e.content.trim()?null:l(`memory.validation.contentRequired`),p=!d&&!f;return(0,X.jsxs)(`div`,{className:Z(`space-y-4`,o===`inline`&&`rounded-2xl border border-border/70 bg-background/25 p-4`),children:[(0,X.jsx)(dC,{label:l(`memory.editor.typeLabel`),children:(0,X.jsx)(pv,{label:``,triggerLabel:oT(l,e.kind),triggerAriaLabel:l(`memory.editor.typeAriaLabel`),selectId:`memory-type`,selectedValue:e.kind,onChange:n=>{c&&t({...fT(n),title:e.title,scope:e.scope,content:e.content,rationale:e.rationale})},disabled:!c,groups:[{label:``,options:[{value:`decision`,label:l(`memory.editor.decision`)},{value:`convention`,label:l(`memory.editor.convention`)}]}]})}),(0,X.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,X.jsx)(dC,{label:l(`memory.editor.titleLabel`),error:d,children:(0,X.jsx)(J_,{"aria-label":l(`memory.editor.titleAriaLabel`),"aria-invalid":!!d,value:e.title,maxLength:Cw.title,onChange:n=>t({...e,title:n.target.value}),placeholder:l(u?`memory.editor.titlePlaceholderConvention`:`memory.editor.titlePlaceholderDecision`)})}),(0,X.jsx)(dC,{label:l(`memory.editor.scopeLabel`),description:l(`memory.editor.scopeDescription`),children:(0,X.jsx)(J_,{"aria-label":l(`memory.editor.scopeAriaLabel`),value:e.scope,maxLength:Cw.scope,onChange:n=>t({...e,scope:n.target.value}),placeholder:l(u?`memory.editor.scopePlaceholderConvention`:`memory.editor.scopePlaceholderDecision`)})})]}),(0,X.jsx)(dC,{label:l(`memory.editor.contentLabel`),error:f,children:(0,X.jsx)(Y_,{"aria-label":l(`memory.editor.contentAriaLabel`),"aria-invalid":!!f,value:e.content,maxLength:Cw.content,onChange:n=>t({...e,content:n.target.value}),rows:3,placeholder:l(u?`memory.editor.contentPlaceholderConvention`:`memory.editor.contentPlaceholderDecision`)})}),(0,X.jsx)(dC,{label:l(`memory.editor.rationaleLabel`),description:l(`memory.editor.rationaleDescription`),children:(0,X.jsx)(Y_,{"aria-label":l(`memory.editor.rationaleAriaLabel`),value:e.rationale,maxLength:Cw.rationale,onChange:n=>t({...e,rationale:n.target.value}),rows:2,placeholder:l(u?`memory.editor.rationalePlaceholderConvention`:`memory.editor.rationalePlaceholderDecision`)})}),u?(0,X.jsxs)(`div`,{className:`grid gap-4 xl:grid-cols-2 xl:items-start`,children:[(0,X.jsx)(dC,{label:l(`memory.editor.priorityLabel`),children:(0,X.jsx)(pv,{label:``,triggerLabel:cT(l,e.priority),triggerAriaLabel:l(`memory.editor.priorityAriaLabel`),selectId:`memory-priority`,selectedValue:e.priority,onChange:n=>t({...e,priority:n}),groups:[{label:``,options:Sw.map(e=>({value:e,label:cT(l,e)}))}]})}),(0,X.jsx)(dC,{label:l(`memory.editor.injectionModeLabel`),children:(0,X.jsx)(pv,{label:``,triggerLabel:lT(l,e.injectionMode),triggerAriaLabel:l(`memory.editor.injectionModeAriaLabel`),selectId:`memory-injection-mode`,selectedValue:e.injectionMode,onChange:n=>t({...e,injectionMode:n}),groups:[{label:``,options:[`always`,`relevant`].map(e=>({value:e,label:lT(l,e)}))}]})})]}):(0,X.jsx)(dC,{label:l(`memory.editor.implicationsLabel`),description:l(`memory.editor.implicationsDescription`),children:(0,X.jsx)(Y_,{"aria-label":l(`memory.editor.implicationsAriaLabel`),value:e.implicationsText,onChange:n=>t({...e,implicationsText:n.target.value}),rows:3,placeholder:l(`memory.editor.implicationsPlaceholder`)})}),(0,X.jsx)(dC,{label:l(`memory.editor.stagesLabel`),description:l(`memory.editor.stagesDescription`),children:(0,X.jsx)(jT,{value:e.stages,onChange:n=>t({...e,stages:n})})}),(0,X.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,X.jsx)(dC,{label:l(`memory.editor.pathGlobsLabel`),description:l(`memory.editor.applicabilityDescription`),children:(0,X.jsx)(Y_,{"aria-label":l(`memory.editor.pathGlobsAriaLabel`),value:e.pathGlobsText,onChange:n=>t({...e,pathGlobsText:n.target.value}),rows:3})}),(0,X.jsx)(dC,{label:l(`memory.editor.componentTagsLabel`),description:l(`memory.editor.applicabilityDescription`),children:(0,X.jsx)(Y_,{"aria-label":l(`memory.editor.componentTagsAriaLabel`),value:e.componentTagsText,onChange:n=>t({...e,componentTagsText:n.target.value}),rows:3})})]}),s,o!==`dialog`&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,X.jsx)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 sm:flex-1`}),(0,X.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2`,children:[(0,X.jsx)(Q,{type:`button`,variant:`ghost`,onClick:n,children:l(`memory.editor.cancel`)}),(0,X.jsx)(Q,{type:`button`,variant:`success`,onClick:r,disabled:i||!p,children:i?l(`memory.editor.saving`):a})]})]})]})},PT=({origin:e,onNavigateToSource:t})=>{let{t:n}=q(`projects`);if(!e)return null;let r=e.accepted_at?new Date(e.accepted_at).toLocaleString():null;return(0,X.jsxs)(`div`,{className:`rounded-lg border border-border/60 bg-background/40 px-3 py-2 text-xs leading-5 text-muted-foreground`,children:[(0,X.jsx)(`p`,{className:`font-medium text-foreground`,children:uT(n,e)}),e.type===`agent_suggestion`&&e.source_type&&(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:n(`memory.provenance.source`)}),` `,dT(n,e.source_type),e.source_label?`: ${e.source_label}`:``]}),e.type===`agent_suggestion`&&e.source_stage&&(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:n(`memory.provenance.stage`)}),` `,sT(n,e.source_stage)]}),r&&(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:n(`memory.provenance.addedAt`)}),` `,r]}),e.type===`agent_suggestion`&&e.source_available&&t&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`mt-2`,onClick:()=>t(e),children:n(`memory.provenance.viewSource`)})]})},FT=({mode:e,projectId:t,memoryEnabled:n,persistedMemoryEnabled:r,onMemoryEnabledChange:i,scanIncludeGlobsText:a=``,scanExcludeGlobsText:o=``,onScanIncludeGlobsTextChange:s,onScanExcludeGlobsTextChange:c,showActivationControls:l=!0,archiveLayout:u=!1,onNavigateToSource:d})=>{let{t:f}=q(`projects`),[m,h]=(0,p.useState)(null),[g,_]=(0,p.useState)([]),[v,y]=(0,p.useState)([]),[b,x]=(0,p.useState)([]),[S,C]=(0,p.useState)(!1),[w,T]=(0,p.useState)(null),[E,D]=(0,p.useState)(fT),[O,k]=(0,p.useState)(!1),[A,j]=(0,p.useState)(Kw),[M,N]=(0,p.useState)(0),[P,F]=(0,p.useState)(null),[I,L]=(0,p.useState)([]),[R,z]=(0,p.useState)(!1),[ee,B]=(0,p.useState)(null),[V,H]=(0,p.useState)(!1),[U,W]=(0,p.useState)(!1),[te,ne]=(0,p.useState)(!1),[re,ie]=(0,p.useState)(null),[ae,G]=(0,p.useState)(``),[oe,se]=(0,p.useState)(!1),[ce,le]=(0,p.useState)(!1),[ue,de]=(0,p.useState)(``),fe=(0,p.useRef)(null),pe=(0,p.useRef)(JSON.stringify(fT())),me=u&&e===`edit`&&!!t&&n&&r,he=e===`edit`&&!!t,ge=e===`create`&&n,_e=e===`edit`&&n&&!r,ve=!n;(0,p.useEffect)(()=>{if(!me||!t){_([]),y([]),x([]),h(null),T(null),ie(null),F(null),L([]),B(null),z(!1);return}let e=new AbortController;return C(!0),z(!0),T(null),B(null),OT(t,e.signal).then(t=>{e.signal.aborted||(T(null),_(t.conventions),y(t.decisions),x(t.suggestions),F(t.generatedContext?.context??null),L(t.generatedContext?.artifacts??[]))}).catch(t=>{e.signal.aborted||T(t instanceof Error?t.message:f(`memory.messages.loadError`))}).finally(()=>{e.signal.aborted||(C(!1),z(!1))}),()=>{e.abort()}},[me,M,t,f]),(0,p.useEffect)(()=>{if(!t||!me||!xT(P))return;let e=null,n=new AbortController,r=()=>{z(!0),wT(t,n.signal).then(t=>{n.signal.aborted||(B(null),F(t.context),L(t.artifacts),xT(t.context)&&(e=window.setTimeout(r,aT)))}).catch(t=>{n.signal.aborted||(B(t instanceof Error?t.message:f(`memory.messages.refreshContextError`)),e=window.setTimeout(r,aT))}).finally(()=>{n.signal.aborted||z(!1)})};return e=window.setTimeout(r,aT),()=>{n.abort(),e!==null&&window.clearTimeout(e),z(!1)}},[me,P,t,f]);let ye=(0,p.useMemo)(()=>{let e=g.map(e=>tT({id:e.id,project_id:e.project_id,kind:`convention`,state:e.status===`active`?`active`:`archived`,title:e.title,scope:e.scope,content:e.instruction,rationale:e.rationale,implications:[],stages:e.stages,path_globs:e.path_globs,component_tags:e.component_tags,priority:e.priority,injection_mode:e.injection_mode,origin:e.origin,created_at:e.created_at,updated_at:e.updated_at})),t=v.map(e=>tT({id:e.id,project_id:e.project_id,kind:`decision`,state:e.status===`accepted`?`active`:e.status,title:e.title,scope:e.scope,content:e.decision,rationale:e.rationale,implications:e.implications,stages:e.stages,path_globs:e.path_globs,component_tags:e.component_tags,priority:null,injection_mode:null,origin:e.origin,created_at:e.created_at,updated_at:e.updated_at}));return[...e,...t]},[g,v]),be=(0,p.useMemo)(()=>$w(ye,A),[ye,A]),xe=(0,p.useMemo)(()=>{let e=be.filter(e=>e.kind===`convention`).map(e=>{let t=TT(e),n=[f(`memory.editor.convention`),cT(f,t.priority),lT(f,t.injection_mode),yT(f,t.status),uT(f,t.origin)];return t.stages.length>0&&n.push(t.stages.length===1?sT(f,t.stages[0]):f(`memory.archive.stageCount`,{count:t.stages.length})),{id:t.id,kind:`convention`,title:t.title,preview:t.instruction,meta:n,archived:bT(t.status),updatedAt:t.updated_at,origin:t.origin}}),t=be.filter(e=>e.kind===`decision`).map(e=>{let t=ET(e);return{id:t.id,kind:`decision`,title:t.title,preview:t.decision,meta:[f(`memory.editor.decision`),yT(f,t.status),uT(f,t.origin)],archived:bT(t.status),updatedAt:t.updated_at,origin:t.origin}}),n=new Map([...e,...t].map(e=>[e.id,e]));return be.map(e=>n.get(e.id)).filter(e=>!!e)},[be,f]),Se=(0,p.useMemo)(()=>b,[b]),Ce=(0,p.useMemo)(()=>rT(Se),[Se]),we=(0,p.useMemo)(()=>CT(I),[I]),Te=()=>{h(null),D(fT())},Ee=()=>{if(JSON.stringify(E)!==pe.current&&!O){se(!0);return}Te()},De=async()=>{if(!t||!E.title.trim()||!E.content.trim())return;let e=oie(E.implicationsText),n=Dw(E.pathGlobsText),r=Dw(E.componentTagsText),i=E.kind===`decision`?ww(e):null;if(i){$.error(f(`memory.validation.implications.${i}`,Cw),{id:`project-memory-save-error`});return}k(!0);try{if(E.kind===`convention`){let e={kind:`convention`,title:E.title.trim(),scope:E.scope.trim()||null,instruction:E.content.trim(),rationale:E.rationale.trim()||null,stages:E.stages,path_globs:n,component_tags:r,priority:E.priority,injection_mode:E.injectionMode},i=m?.id?await br(t,m.id,e):await yr(t,e);_(e=>hT(e,TT(i.memory)))}else{let i={kind:`decision`,title:E.title.trim(),scope:E.scope.trim()||null,decision:E.content.trim(),rationale:E.rationale.trim()||null,implications:e,stages:E.stages,path_globs:n,component_tags:r},a=m?.id?await br(t,m.id,i):await yr(t,i);y(e=>gT(e,ET(a.memory)))}Te(),de(f(`memory.workspace.status.saved`))}catch(e){$.error(e instanceof Error?e.message:f(`memory.messages.saveError`),{id:`project-memory-save-error`})}finally{k(!1)}},Oe=e=>{let t=_T(e);h({kind:`convention`,id:e.id}),D(t),pe.current=JSON.stringify(t)},ke=()=>{let e=fT(`decision`);h({kind:`decision`,id:null}),D(e),pe.current=JSON.stringify(e)},Ae=e=>{let t=vT(e);h({kind:`decision`,id:e.id}),D(t),pe.current=JSON.stringify(t)},je=async(e,n)=>{if(!t)return!1;try{let r=n===`archive`?await xr(t,e.id):await Sr(t,e.id).catch(async n=>{if(!Tw(n,f(`memory.messages.confirmConflicts`)))throw n;return Sr(t,e.id,!0)});return _(e=>hT(e,TT(r.memory))),de(f(`memory.workspace.status.${n===`archive`?`archived`:`restored`}`)),n===`archive`&&$.success(f(`memory.workspace.archiveUndoMessage`),{action:{label:f(`memory.workspace.undo`),onClick:()=>{je(TT(r.memory),`restore`)}}}),!0}catch(e){return $.error(e instanceof Error?e.message:f(n===`archive`?`memory.messages.archiveConventionError`:`memory.messages.restoreConventionError`),{id:n===`archive`?`project-memory-convention-archive-error`:`project-memory-convention-restore-error`}),!1}},Me=async(e,n)=>{if(!t)return!1;try{let r=n===`archive`?await xr(t,e.id):n===`supersede`?await Cr(t,e.id,ae):await Sr(t,e.id).catch(async n=>{if(!Tw(n,f(`memory.messages.confirmConflicts`)))throw n;return Sr(t,e.id,!0)});return y(e=>gT(e,ET(r.memory))),de(f(`memory.workspace.status.${n===`archive`?`archived`:n===`restore`?`restored`:`superseded`}`)),n===`archive`&&$.success(f(`memory.workspace.archiveUndoMessage`),{action:{label:f(`memory.workspace.undo`),onClick:()=>{Me(ET(r.memory),`restore`)}}}),!0}catch(e){let t=f(n===`archive`?`memory.messages.archiveDecisionError`:n===`supersede`?`memory.messages.supersedeDecisionError`:`memory.messages.restoreDecisionError`),r=n===`archive`?`project-memory-decision-archive-error`:n===`supersede`?`project-memory-decision-supersede-error`:`project-memory-decision-restore-error`;return $.error(e instanceof Error?e.message:t,{id:r}),!1}},Ne=m!==null,Pe=m?.kind===`convention`&&m.id?g.find(e=>e.id===m.id)??null:null,Fe=m?.kind===`decision`&&m.id?v.find(e=>e.id===m.id)??null:null,Ie=m?.id?ye.find(e=>e.id===m.id)??null:null,Le=xT(P),K=()=>{t&&(H(!0),B(null),Tr(t).then(async e=>{F(e),L((await Or(t)).artifacts),$.success(f(`memory.messages.scanStarted`),{id:`project-context-scan-started`}),de(f(`memory.workspace.status.scanStarted`))}).catch(async e=>{if(e instanceof Ge&&e.status===409){$.error(f(`memory.messages.scanConflict`),{id:`project-context-scan-conflict`});try{let e=await wT(t);F(e.context),L(e.artifacts)}catch(e){B(e instanceof Error?e.message:f(`memory.messages.refreshContextError`))}return}$.error(e instanceof Error?e.message:f(`memory.messages.scanStartError`),{id:`project-context-scan-error`})}).finally(()=>{H(!1)}))},Re=async()=>{if(t){W(!0);try{let{filename:e,archive:n}=await Fr(t),r=new Blob([JSON.stringify(n,null,2)],{type:`application/json;charset=utf-8`}),i=window.URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=e,a.click(),window.URL.revokeObjectURL(i),$.success(f(`memory.messages.exportSuccess`),{id:`project-memory-export-success`})}catch(e){$.error(e instanceof Error?e.message:f(`memory.messages.exportError`),{id:`project-memory-export-error`})}finally{W(!1)}}},ze=async e=>{if(!t){e.target.value=``;return}let n=e.target.files?.[0];if(e.target.value=``,n){ne(!0);try{let e=await Ir(t,JSON.parse(await AT(n,f(`memory.import.readFileError`))));if(me){let e=await OT(t);_(e.conventions),y(e.decisions),x(e.suggestions),F(e.generatedContext?.context??null),L(e.generatedContext?.artifacts??[]),T(null),B(null)}ie(e),$.success(f(`memory.messages.importSuccess`),{id:`project-memory-import-success`})}catch(e){$.error(e instanceof Error?e.message:f(`memory.messages.importError`),{id:`project-memory-import-error`})}finally{ne(!1)}}},Be=(0,X.jsxs)(`div`,{className:u?`rounded-lg border border-border/70 bg-background/35 p-4`:`rounded-2xl border border-border/70 bg-background/25 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h4`,{className:`text-sm font-semibold text-foreground`,children:f(`memory.transfer.title`)}),(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:f(`memory.transfer.description`)}),!he&&(0,X.jsx)(`p`,{className:`mt-2 text-xs leading-5 text-muted-foreground`,children:f(`memory.transfer.createProjectFirst`)})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 self-start`,children:[(0,X.jsxs)(Q,{type:`button`,variant:`outline`,onClick:()=>{Re()},disabled:!he||U||te,children:[(0,X.jsx)(aie,{className:`h-3.5 w-3.5`}),f(U?`memory.transfer.exporting`:`memory.transfer.export`)]}),(0,X.jsxs)(Q,{type:`button`,variant:`outline`,onClick:()=>{fe.current?.click()},disabled:!he||U||te,children:[(0,X.jsx)(bw,{className:`h-3.5 w-3.5`}),f(te?`memory.transfer.importing`:`memory.transfer.import`)]})]})]}),(0,X.jsx)(`input`,{ref:fe,type:`file`,accept:`application/json,.json`,className:`hidden`,"aria-label":f(`memory.transfer.importAriaLabel`),onChange:e=>{ze(e)}}),re&&(0,X.jsxs)(`div`,{className:`mt-4 grid gap-2 sm:grid-cols-2 xl:grid-cols-4`,children:[(0,X.jsx)(`div`,{className:`rounded-lg border border-border/60 bg-background/35 px-3 py-2 text-sm text-muted-foreground`,children:f(`memory.transfer.importedConventions`,{imported:re.summary.conventions_imported,skipped:re.summary.conventions_skipped})}),(0,X.jsx)(`div`,{className:`rounded-lg border border-border/60 bg-background/35 px-3 py-2 text-sm text-muted-foreground`,children:f(`memory.transfer.importedDecisions`,{imported:re.summary.decisions_imported,skipped:re.summary.decisions_skipped})}),(0,X.jsx)(`div`,{className:`rounded-lg border border-border/60 bg-background/35 px-3 py-2 text-sm text-muted-foreground`,children:f(`memory.transfer.importedScans`,{imported:re.summary.scans_imported,skipped:re.summary.scans_skipped})}),(0,X.jsx)(`div`,{className:`rounded-lg border border-border/60 bg-background/35 px-3 py-2 text-sm text-muted-foreground`,children:f(`memory.transfer.importedArtifacts`,{imported:re.summary.artifacts_imported,skipped:re.summary.artifacts_skipped})}),(0,X.jsx)(`div`,{className:`sm:col-span-2 xl:col-span-4 rounded-lg border border-border/60 bg-background/35 px-3 py-2 text-sm text-muted-foreground`,children:kT(f,re)})]})]}),Ve=(0,X.jsxs)(Q,{type:`button`,variant:`outline`,size:`sm`,className:`min-w-[7.5rem] shrink-0 justify-center`,disabled:V||Le,onClick:K,children:[V||Le?(0,X.jsx)(Ov,{className:`size-3.5 animate-spin`}):(0,X.jsx)(xw,{className:`size-3.5`}),f(V||Le?`memory.archive.scanning`:`memory.archive.scanNow`)]});return u?(0,X.jsxs)(`div`,{className:`space-y-5`,children:[(0,X.jsx)(`p`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:ue}),ve&&(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground`,children:f(`memory.archive.disabledNote`)}),ge&&(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground`,children:f(`memory.archive.createNote`)}),_e&&(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground`,children:f(`memory.archive.saveFirstNote`)}),me&&(0,X.jsxs)(LC,{defaultValue:`accepted`,className:`min-w-0 rounded-xl border border-border/70 bg-card/55 shadow-[0_18px_40px_rgba(0,0,0,0.16)]`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-4 border-b border-border/60 px-4 py-4 sm:px-5`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-lg font-semibold text-foreground`,children:f(`memory.archive.memoriesTitle`)}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:f(`memory.workspace.description`)})]}),(0,X.jsxs)(RC,{className:`grid w-full grid-cols-3 sm:w-auto`,children:[(0,X.jsxs)(zC,{value:`inbox`,children:[f(`memory.workspace.tabs.inbox`),` `,(0,X.jsx)(`span`,{className:`ml-1 text-xs`,children:Se.length})]}),(0,X.jsxs)(zC,{value:`accepted`,children:[f(`memory.workspace.tabs.accepted`),` `,(0,X.jsx)(`span`,{className:`ml-1 text-xs`,children:ye.length})]}),(0,X.jsx)(zC,{value:`context`,children:f(`memory.workspace.tabs.context`)})]})]}),w&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3 text-sm text-red-300 sm:flex-row sm:items-center sm:justify-between`,children:[(0,X.jsx)(`span`,{children:w}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>N(e=>e+1),children:f(`memory.workspace.retry`)})]})]}),(0,X.jsxs)(BC,{value:`inbox`,className:`space-y-5 p-4 sm:p-5`,children:[(0,X.jsx)(`h4`,{className:`text-sm font-semibold text-foreground`,children:f(`memory.archive.suggestedMemoriesTitle`)}),S?(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border px-4 py-4 text-sm text-muted-foreground`,children:f(`memory.archive.loadingSuggestedMemories`)}):Ce.length>0?Ce.map(e=>(0,X.jsxs)(`section`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-border/60 pb-2`,children:[(0,X.jsx)(`h4`,{className:`text-sm font-semibold text-foreground`,children:e.label??f(`memory.workspace.sources.${e.sourceType}`)}),(0,X.jsx)(rC,{variant:`outline`,children:f(`memory.archive.itemsCount`,{count:e.suggestions.length})})]}),(0,X.jsx)(Pw,{projectId:t??``,suggestions:e.suggestions,onNavigateToSource:e.sourceAvailable?d:void 0,onChanged:(e,t,n)=>{x(t=>t.filter(t=>t.id!==e)),t!==`dismiss`&&n?.memory.id&&(n.memory.kind===`decision`?y(e=>gT(e,ET(n.memory))):_(e=>hT(e,TT(n.memory))))}})]},e.key)):(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border px-4 py-8 text-center text-sm text-muted-foreground`,children:f(`memory.archive.noSuggestedMemories`)})]}),(0,X.jsxs)(BC,{value:`accepted`,className:`space-y-5 p-4 sm:p-5`,children:[(0,X.jsx)(`h4`,{className:`text-sm font-semibold text-foreground`,children:f(`memory.archive.savedMemoriesTitle`)}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-5`,children:[(0,X.jsxs)(`label`,{className:`space-y-1 text-xs font-medium text-muted-foreground sm:col-span-2 xl:col-span-2`,children:[(0,X.jsx)(`span`,{children:f(`memory.workspace.search`)}),(0,X.jsx)(J_,{value:A.search,onChange:e=>j(t=>({...t,search:e.target.value})),placeholder:f(`memory.workspace.searchPlaceholder`)})]}),[`kind`,`stage`,`source`,`injection`,`sort`].map(e=>(0,X.jsxs)(`label`,{className:`space-y-1 text-xs font-medium text-muted-foreground`,children:[(0,X.jsx)(`span`,{children:f(`memory.workspace.filters.${e}`)}),(0,X.jsx)(`select`,{value:A[e],onChange:t=>j(n=>({...n,[e]:t.target.value})),className:`h-9 w-full rounded-lg border border-border bg-background px-3 text-sm text-foreground`,children:(e===`kind`?[`all`,`decision`,`convention`]:e===`stage`?[`all`,...iT]:e===`source`?[`all`,`manual`,`ticket`,`chat`,`spec`]:e===`injection`?[`all`,`always`,`relevant`]:[`updated`,`title`,`kind`,`priority`]).map(e=>(0,X.jsx)(`option`,{value:e,children:f(`memory.workspace.options.${e}`)},e))})]},e))]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[eT(A)&&(0,X.jsx)(Q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>j(Kw),children:f(`memory.workspace.clearFilters`)}),(0,X.jsxs)(Q,{type:`button`,variant:`outline`,size:`sm`,onClick:ke,children:[(0,X.jsx)(xv,{className:`size-3.5`}),f(`memory.archive.newMemory`)]})]})]}),(0,X.jsxs)(`fieldset`,{className:`flex flex-wrap gap-4 rounded-lg border border-border/60 bg-background/30 px-3 py-2`,children:[(0,X.jsx)(`legend`,{className:`px-1 text-xs font-medium text-muted-foreground`,children:f(`memory.workspace.filters.status`)}),[`active`,`archived`,`superseded`].map(e=>(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:A.statuses.includes(e),onChange:()=>j(t=>({...t,statuses:t.statuses.includes(e)?t.statuses.filter(t=>t!==e):[...t.statuses,e]}))}),f(`memory.workspace.options.${e}`)]},e))]}),(0,X.jsx)(`div`,{className:`flex items-center justify-between gap-3 text-sm text-muted-foreground`,children:(0,X.jsx)(`span`,{children:f(`memory.workspace.resultCount`,{filtered:xe.length,total:ye.length})})}),S?(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border px-4 py-4 text-sm text-muted-foreground`,children:f(`memory.archive.loadingSavedMemories`)}):xe.length>0?(0,X.jsx)(`div`,{className:`grid gap-3 xl:grid-cols-2`,children:xe.map(e=>(0,X.jsx)(MT,{title:e.title,meta:e.meta,preview:e.preview,archived:e.archived,ariaLabel:f(`memory.archive.openMemoryAriaLabel`,{kind:e.kind,title:e.title}),onClick:()=>{if(e.kind===`convention`){let t=g.find(t=>t.id===e.id);t&&Oe(t)}else{let t=v.find(t=>t.id===e.id);t&&Ae(t)}},accentClassName:e.kind===`convention`?`bg-sky-300/50`:`bg-amber-300/45`},e.id))}):(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border px-4 py-8 text-center text-sm text-muted-foreground`,children:ye.length===0?f(`memory.archive.noSavedMemories`):f(`memory.workspace.noFilterResults`)})]}),(0,X.jsx)(BC,{value:`context`,className:`p-4 sm:p-5`,children:(0,X.jsx)(Gw,{projectId:t??``,summary:P,compatibilityArtifacts:we,isLoading:R,error:ee,scanAction:Ve,onRetry:()=>N(e=>e+1)})})]}),(0,X.jsx)(V_,{open:Ne,onOpenChange:e=>{e||Ee()},children:(0,X.jsx)(U_,{showCloseButton:!1,className:`max-h-[85vh] flex flex-col gap-0 overflow-hidden p-0 sm:max-w-3xl`,children:(0,X.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[(0,X.jsxs)(`div`,{className:`shrink-0 border-b border-border/70 px-5 py-4 sm:px-6`,children:[(0,X.jsxs)(W_,{children:[(0,X.jsx)(K_,{children:m?.id?f(`memory.archive.editMemory`):f(`memory.archive.createMemory`)}),(0,X.jsx)(q_,{children:f(`memory.archive.editorDescription`)})]}),(0,X.jsx)(H_,{asChild:!0,children:(0,X.jsxs)(Q,{variant:`ghost`,size:`icon-sm`,className:`absolute top-4 right-4`,children:[(0,X.jsx)(ax,{className:`size-4`}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Close`})]})})]}),(0,X.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4 sm:px-6`,children:[(0,X.jsx)(PT,{origin:Pe?.origin??Fe?.origin,onNavigateToSource:d}),t&&Ie&&(0,X.jsx)(Lw,{projectId:t,memory:Ie}),(0,X.jsx)(NT,{draft:E,onChange:D,onCancel:Ee,onSubmit:()=>{De()},isSaving:O,submitLabel:m?.id?f(`memory.archive.saveMemory`):f(`memory.archive.createMemory`),layout:`dialog`,allowKindChange:m?.id==null,supplementaryActions:Fe?.status===`accepted`&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,X.jsx)(pv,{label:f(`memory.archive.replacementDecision`),triggerLabel:v.find(e=>e.id===ae)?.title??f(`memory.archive.selectReplacementDecision`),triggerAriaLabel:f(`memory.archive.replacementDecision`),selectId:`memory-replacement-decision`,groups:[{label:``,options:v.filter(e=>e.status===`accepted`&&e.id!==Fe.id).map(e=>({value:e.id,label:e.title}))}],selectedValue:ae,onChange:G,className:`min-w-48 flex-1`,triggerClassName:`h-9`}),(0,X.jsx)(Q,{type:`button`,variant:`outline`,disabled:!ae,onClick:()=>le(!0),children:f(`memory.archive.supersede`)})]})})]}),(0,X.jsx)(`div`,{className:`shrink-0 border-t border-border/70 px-5 py-4 sm:px-6`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,X.jsx)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 sm:flex-1`,children:Pe?Pe.status===`active`?(0,X.jsx)(Q,{type:`button`,variant:`warning`,onClick:()=>{je(Pe,`archive`).then(e=>{e&&Te()})},children:f(`memory.archive.archive`)}):(0,X.jsx)(Q,{type:`button`,variant:`outline`,onClick:()=>{je(Pe,`restore`).then(e=>{e&&Te()})},children:f(`memory.archive.restore`)}):Fe?Fe.status===`accepted`?(0,X.jsx)(Q,{type:`button`,variant:`warning`,onClick:()=>{Me(Fe,`archive`).then(e=>{e&&Te()})},children:f(`memory.archive.archive`)}):(0,X.jsx)(Q,{type:`button`,variant:`outline`,onClick:()=>{Me(Fe,`restore`).then(e=>{e&&Te()})},children:f(`memory.archive.restore`)}):null}),(0,X.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2`,children:[(0,X.jsx)(Q,{type:`button`,variant:`ghost`,onClick:Ee,children:f(`memory.editor.cancel`)}),(0,X.jsx)(Q,{type:`button`,variant:`success`,onClick:()=>{De()},disabled:O||!E.title.trim()||!E.content.trim(),children:O?f(`memory.editor.saving`):m?.id?f(`memory.archive.saveMemory`):f(`memory.archive.createMemory`)})]})]})})]})})}),(0,X.jsx)(V_,{open:oe,onOpenChange:se,children:(0,X.jsxs)(U_,{className:`sm:max-w-md`,children:[(0,X.jsxs)(W_,{children:[(0,X.jsx)(K_,{children:f(`memory.workspace.dirtyCloseTitle`)}),(0,X.jsx)(q_,{children:f(`memory.workspace.dirtyCloseDescription`)})]}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,X.jsx)(Q,{type:`button`,variant:`ghost`,onClick:()=>se(!1),children:f(`memory.workspace.keepEditing`)}),(0,X.jsx)(Q,{type:`button`,variant:`warning`,onClick:()=>{se(!1),Te()},children:f(`memory.workspace.discardChanges`)})]})]})}),(0,X.jsx)(V_,{open:ce,onOpenChange:le,children:(0,X.jsxs)(U_,{className:`sm:max-w-md`,children:[(0,X.jsxs)(W_,{children:[(0,X.jsx)(K_,{children:f(`memory.workspace.supersedeTitle`)}),(0,X.jsx)(q_,{children:f(`memory.workspace.supersedeDescription`,{current:Fe?.title,replacement:v.find(e=>e.id===ae)?.title})})]}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,X.jsx)(Q,{type:`button`,variant:`ghost`,onClick:()=>le(!1),children:f(`memory.editor.cancel`)}),(0,X.jsx)(Q,{type:`button`,variant:`warning`,onClick:()=>{Fe&&Me(Fe,`supersede`).then(e=>{e&&(le(!1),Te())})},children:f(`memory.archive.supersede`)})]})]})})]}):(0,X.jsxs)(`div`,{className:`space-y-5`,children:[l&&(0,X.jsx)(`div`,{className:`rounded-2xl border border-border/70 bg-background/25 p-4`,children:(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:f(`memory.activation.title`)}),(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:f(`memory.activation.description`)})]}),(0,X.jsx)(nw,{"aria-label":f(`memory.activation.ariaLabel`),checked:n,onCheckedChange:i})]})}),l&&(0,X.jsxs)(`div`,{className:`space-y-4 rounded-2xl border border-border/70 bg-background/25 p-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:f(`memory.scanControls.title`)}),(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:f(`memory.scanControls.description`)})]}),(0,X.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,X.jsx)(dC,{label:f(`memory.scanControls.includeLabel`),description:f(`memory.scanControls.includeDescription`),children:(0,X.jsx)(Y_,{"aria-label":f(`memory.scanControls.includeAriaLabel`),value:a,rows:4,placeholder:f(`memory.scanControls.includePlaceholder`),onChange:e=>s?.(e.target.value)})}),(0,X.jsx)(dC,{label:f(`memory.scanControls.excludeLabel`),description:f(`memory.scanControls.excludeDescription`),children:(0,X.jsx)(Y_,{"aria-label":f(`memory.scanControls.excludeAriaLabel`),value:o,rows:4,placeholder:f(`memory.scanControls.excludePlaceholder`),onChange:e=>c?.(e.target.value)})})]}),(0,X.jsx)(`p`,{className:`text-xs leading-5 text-muted-foreground`,children:f(`memory.scanControls.disclosure`)})]}),Be]})},IT=e=>typeof e!=`string`&&e?.provider?.trim()?e.provider.trim().toLowerCase():(typeof e==`string`?e:e?.id)?.split(`/`)[0]?.trim().toLowerCase()||``,LT=(e,t)=>{if(!t)return e;let n=new Set(t.map(e=>e.trim().toLowerCase()));return e.filter(e=>n.has(IT(e)))},RT=/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/,zT=/^\d{1,3}(?:\.\d{1,3}){3}$/,BT=e=>e.trim().toLowerCase(),VT=e=>{let t=BT(e.host);if(!t)return`missing_host`;if(new TextEncoder().encode(t).length>253)return`invalid_host`;let n=t.startsWith(`*.`)?t.slice(2):t;return n.includes(`:`)||zT.test(n)||!RT.test(n)?`invalid_host`:e.port!==void 0&&(!Number.isInteger(e.port)||e.port<1||e.port>65535)?`invalid_port`:e.purpose!==void 0&&(e.purpose.trim().length===0||e.purpose.length>256)?`invalid_purpose`:null},HT=e=>e.mode===`unrestricted`?e.destinations.length===0:e.destinations.length>0&&e.destinations.length<=32&&e.destinations.every(e=>VT(e)===null),UT=e=>{if(e.trim()!==``)return Number(e)},WT=(e,t)=>({host:e.host,...t===void 0?{}:{port:t},...e.purpose===void 0?{}:{purpose:e.purpose}}),GT=(e,t)=>({host:e.host,...e.port===void 0?{}:{port:e.port},...t===void 0?{}:{purpose:t}}),KT=(e,t,n)=>{if(t)return{requested_mode:n??`unrestricted`,observed_global_posture:t.observed_global_posture,enforcement:t.enforcement,decisions:t.decisions};let r=e.flatMap(e=>e.kind!==`network`||typeof e.details?.network_target!=`string`?[]:[{target:e.details.network_target,decision:e.details.network_decision??`unknown`,state:e.state}]);return r.length===0&&n!==`allowlist`?{requested_mode:`unrestricted`,observed_global_posture:`none_initialized`,enforcement:`none`,decisions:[]}:r.length===0?{requested_mode:`allowlist`,observed_global_posture:`unknown`,enforcement:`unknown`,decisions:[]}:{requested_mode:n??`allowlist`,observed_global_posture:r.some(e=>e.decision===`deny`)?`mixed`:`unknown`,enforcement:`unknown`,decisions:r}},qT=({title:e,children:t,defaultOpen:n=!1})=>(0,X.jsxs)(SC,{defaultOpen:n,className:`mt-5 rounded-2xl border border-border/70 bg-background/25`,children:[(0,X.jsx)(CC,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,"aria-label":e,className:`group flex w-full items-center gap-2 rounded-2xl px-4 py-3 text-left outline-none transition-colors hover:bg-accent/40 focus-visible:ring-2 focus-visible:ring-ring/60`,children:[(0,X.jsx)(`span`,{className:`min-w-0 flex-1 text-sm font-semibold text-foreground`,children:e}),(0,X.jsx)(bv,{className:`size-4 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-180`})]})}),(0,X.jsx)(wC,{className:`border-t border-border/60 px-4 py-3`,children:t})]}),JT=[`host`,`docker_sandbox`],YT=({value:e,runtimeStatus:t,onChange:n})=>{let{t:r}=q(`projects`,{keyPrefix:`execution`});return(0,X.jsxs)(`fieldset`,{children:[(0,X.jsx)(`legend`,{className:`text-sm font-semibold text-foreground`,children:r(`provider.title`)}),(0,X.jsx)(`p`,{className:`mt-1 max-w-2xl text-sm text-muted-foreground`,children:r(`provider.description`)}),(0,X.jsx)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2`,children:JT.map(i=>(0,X.jsxs)(`label`,{className:Z(`flex min-w-0 cursor-pointer gap-3 rounded-2xl border p-4 transition-colors focus-within:ring-2 focus-within:ring-ring/60`,e===i?`border-sky-400/45 bg-sky-500/10`:`border-border/70 bg-card/40 hover:border-border`),children:[(0,X.jsx)(`input`,{type:`radio`,name:`build-execution-provider`,value:i,checked:e===i,onChange:()=>n(i),className:`mt-1 size-4 shrink-0 accent-sky-400`}),(0,X.jsxs)(`span`,{className:`min-w-0`,children:[(0,X.jsx)(`span`,{className:`block text-sm font-semibold text-foreground`,children:r(`provider.${i}.label`)}),(0,X.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-muted-foreground`,children:r(`provider.${i}.description`)}),i===`docker_sandbox`&&(0,X.jsx)(`span`,{role:`status`,className:Z(`mt-2 block text-xs font-medium`,t===`ready`||t===`eligible`?`text-emerald-200`:`text-amber-200`),children:r(`provider.docker_sandbox.status.${t}`)})]})]},i))})]})},XT=e=>({...e,eligible_workloads:[...e.eligible_workloads],check_template_policy:{...e.check_template_policy},workspace_access:{...e.workspace_access,additional_mounts:[]},credential_requirements:e.credential_requirements.map(e=>({...e})),network:{mode:e.network.mode,destinations:e.network.destinations.map(e=>({...e}))}}),ZT=(e,t)=>e!==null&&t!==null&&JSON.stringify(e)===JSON.stringify(t),QT=(e,t)=>{if(t===`docker_sandbox`)return{...e,compatibility:`governed`,provider_preference:t,isolation:`microvm_required`,fallback:`block`,credential_requirements:e.credential_requirements.map(e=>({...e,required_protection:`docker_brokered`}))};let n=e.compatibility===`legacy_host`?`legacy_host`:`governed`;return{...e,compatibility:n,provider_preference:t,isolation:`host_process_allowed`,fallback:`block`,credential_requirements:n===`legacy_host`?e.credential_requirements.map(e=>({...e,required_protection:`legacy_host_inheritance`})):[],network:{mode:`unrestricted`,destinations:[]}}},$T=e=>e.compatibility===`legacy_host`?e.provider_preference===`host`&&e.isolation===`host_process_allowed`&&e.fallback===`block`&&e.network.mode===`unrestricted`&&e.credential_requirements.every(e=>e.required_protection===`legacy_host_inheritance`):e.provider_preference===`host`?e.isolation===`host_process_allowed`&&e.credential_requirements.length===0&&e.network.mode===`unrestricted`:e.credential_requirements.every(e=>e.required_protection===`docker_brokered`)&&(e.fallback!==`explicit_host`||e.isolation===`host_process_allowed`),eE=(e,t)=>{let n=`${e}_model_auth`,r=n,i=2;for(;t.some(e=>e.id===r);)r=`${n}_${i}`,i+=1;return r},tE=({compatibility:e,index:t,provider:n,providers:r,requirement:i,onChange:a,onRemove:o})=>{let{t:s}=q(`projects`,{keyPrefix:`execution`}),c=n===`docker_sandbox`?`docker_brokered`:e===`legacy_host`?`legacy_host_inheritance`:null,l=Array.from(new Set([...i.model_provider?[i.model_provider]:[],...i.agent===`claude`?[`anthropic`]:r]));return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/60 bg-background/25 p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,X.jsx)(`p`,{className:`text-xs font-semibold text-foreground`,children:s(`profile.credential.item`,{count:t+1})}),(0,X.jsx)(Q,{type:`button`,size:`xs`,variant:`ghost`,onClick:o,children:s(`profile.credential.remove`)})]}),(0,X.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[s(`profile.credential.agent`),(0,X.jsxs)(`select`,{value:i.agent,onChange:e=>{let t=e.target.value;a({...i,agent:t,model_provider:t===`claude`?`anthropic`:r[0]??i.model_provider})},className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground`,children:[(0,X.jsx)(`option`,{value:`opencode`,children:s(`agent.opencode`)}),(0,X.jsx)(`option`,{value:`claude`,children:s(`agent.claude`)})]})]}),(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[s(`profile.credential.modelProvider`),(0,X.jsx)(`select`,{value:i.model_provider,onChange:e=>a({...i,model_provider:e.target.value}),disabled:i.agent===`claude`,className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground disabled:opacity-60`,children:l.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})]}),(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[s(`profile.credential.authentication`),(0,X.jsxs)(`select`,{value:i.authentication_mode,onChange:e=>a({...i,authentication_mode:e.target.value}),className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground`,children:[(0,X.jsx)(`option`,{value:`api_key`,children:s(`profile.authentication.api_key`)}),(0,X.jsx)(`option`,{value:`oauth`,children:s(`profile.authentication.oauth`)})]})]}),(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[s(`profile.credential.protection`),(0,X.jsxs)(`select`,{value:i.required_protection,onChange:e=>a({...i,required_protection:e.target.value}),disabled:!c,className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground disabled:opacity-60`,children:[(0,X.jsx)(`option`,{value:`docker_brokered`,disabled:c!==`docker_brokered`,children:s(`profile.protection.docker_brokered`)}),(0,X.jsx)(`option`,{value:`legacy_host_inheritance`,disabled:c!==`legacy_host_inheritance`,children:s(`profile.protection.legacy_host_inheritance`)})]})]})]})]})},nE=({index:e,destination:t,onChange:n,onRemove:r})=>{let{t:i}=q(`projects`,{keyPrefix:`execution`}),a=VT(t);return(0,X.jsxs)(`div`,{className:`rounded-xl border border-border/60 bg-background/25 p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,X.jsx)(`p`,{className:`text-xs font-semibold text-foreground`,children:i(`profile.network.destination.item`,{count:e+1})}),(0,X.jsx)(Q,{type:`button`,size:`xs`,variant:`ghost`,onClick:r,"aria-label":i(`profile.network.destination.removeAria`,{count:e+1}),children:i(`profile.credential.remove`)})]}),(0,X.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]`,children:[(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[i(`profile.network.destination.host`),(0,X.jsx)(`input`,{type:`text`,value:t.host,onChange:e=>n({...t,host:BT(e.target.value)}),placeholder:i(`profile.network.destination.hostPlaceholder`),"aria-label":i(`profile.network.destination.hostAria`,{count:e+1}),className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground`})]}),(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[i(`profile.network.destination.port`),(0,X.jsx)(`input`,{type:`number`,min:1,max:65535,step:1,value:t.port??``,onChange:e=>{n(WT(t,UT(e.target.value)))},placeholder:i(`profile.network.destination.portPlaceholder`),"aria-label":i(`profile.network.destination.portAria`,{count:e+1}),className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground`})]})]}),(0,X.jsxs)(`label`,{className:`mt-3 block text-xs text-muted-foreground`,children:[i(`profile.network.destination.purpose`),(0,X.jsx)(`input`,{type:`text`,value:t.purpose??``,onChange:e=>{n(GT(t,e.target.value.trim()===``?void 0:e.target.value))},"aria-label":i(`profile.network.destination.purposeAria`,{count:e+1}),className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground`})]}),a&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-red-300`,role:`alert`,children:i(`profile.network.error.${a}`)})]})},rE=({projectId:e,availableModels:t,dockerRuntimeReady:n,dockerRuntimeStatus:r,target:i,onDirtyChange:a,onDraftChange:o,onRevisionChange:s,onProviderSaved:c})=>{let{t:l}=q(`projects`,{keyPrefix:`execution`}),[u,d]=(0,p.useState)(null),[f,m]=(0,p.useState)(null),[h,g]=(0,p.useState)(null),[_,v]=(0,p.useState)(!1),y=(0,p.useRef)(e);y.current=e;let b=Array.from(new Set((t??[]).map(IT).filter(Boolean))),x=!!(u&&f&&!ZT(u.profile,f)),S=!!(f&&$T(f)),C=!!(f&&HT(f.network)),w=!!(f&&(f.provider_preference===`host`||n));(0,p.useEffect)(()=>{let t=new AbortController;return d(null),m(null),g(null),v(!1),Xb(e,t.signal).then(t=>{y.current===e&&(d(t.profile_revision),m(XT(t.profile_revision.profile)))}).catch(t=>{!Ye(t)&&y.current===e&&g(l(`profile.loadError`))}),()=>t.abort()},[e,l]),(0,p.useEffect)(()=>(a(x),()=>a(!1)),[x,a]),(0,p.useEffect)(()=>{f&&o(f.provider_preference,x)},[x,f,o]),(0,p.useEffect)(()=>(s(u?.fingerprint??null),()=>s(null)),[s,u?.fingerprint]);let T=e=>{m(t=>t&&{...t,...e}),g(null)},E=async()=>{if(!u||!f||!x||!S||!C||!w||_)return;v(!0),g(null);let t=e;try{let n=await Zb(e,f,u.id);y.current===t&&await c?.(n.profile_revision.profile.provider_preference),y.current===t&&(d(n.profile_revision),m(XT(n.profile_revision.profile)))}catch(e){if(!Ye(e)&&y.current===t){let t=e instanceof Ge&&typeof e.data==`object`&&e.data!==null?e.data:null;g(t?.reason===`stale_profile_revision`?l(`profile.staleError`):t?.reason===`payload_too_large`?l(`profile.payloadTooLargeError`):t?.reason===`invalid_profile`&&typeof t.error==`string`&&t.error?l(`profile.invalidDetailError`,{detail:t.error}):l(`profile.saveError`))}}finally{y.current===t&&v(!1)}};return!f||!u?(0,X.jsx)(`p`,{className:h?`text-sm text-red-300`:`text-sm text-muted-foreground`,role:h?`alert`:`status`,children:h??l(`profile.loading`)}):(0,X.jsxs)(`section`,{className:`space-y-4`,children:[(0,X.jsx)(YT,{value:f.provider_preference,runtimeStatus:r,onChange:e=>T(QT(f,e))}),(0,X.jsxs)(qT,{title:l(`advanced.title`),children:[(0,X.jsx)(`p`,{className:`max-w-2xl text-xs text-muted-foreground`,children:l(`advanced.description`)}),(0,X.jsxs)(`div`,{className:`mt-4 grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[l(`profile.isolation`),(0,X.jsxs)(`select`,{value:f.isolation,onChange:e=>{let t=e.target.value;T({isolation:t,fallback:t===`microvm_required`?`block`:f.fallback})},className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground`,children:[(0,X.jsx)(`option`,{value:`host_process_allowed`,children:l(`profile.isolationOption.host_process_allowed`)}),(0,X.jsx)(`option`,{value:`microvm_required`,disabled:f.provider_preference===`host`,children:l(`profile.isolationOption.microvm_required`)})]})]}),(0,X.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[l(`profile.fallback`),(0,X.jsxs)(`select`,{value:f.fallback,onChange:e=>T({fallback:e.target.value}),disabled:f.compatibility===`legacy_host`||f.isolation===`microvm_required`,className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground disabled:opacity-60`,children:[(0,X.jsx)(`option`,{value:`block`,children:l(`profile.fallbackOption.block`)}),(0,X.jsx)(`option`,{value:`explicit_host`,disabled:f.compatibility===`legacy_host`||f.isolation===`microvm_required`,children:l(`profile.fallbackOption.explicit_host`)})]})]})]}),(0,X.jsxs)(`fieldset`,{className:`mt-5 border-t border-border/60 pt-4`,children:[(0,X.jsx)(`legend`,{className:`text-sm font-semibold text-foreground`,children:l(`profile.credential.title`)}),(0,X.jsx)(`p`,{className:`mt-1 max-w-2xl text-xs text-muted-foreground`,children:l(`profile.credential.description`)}),(0,X.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[f.credential_requirements.map((e,t)=>(0,X.jsx)(tE,{compatibility:f.compatibility,index:t,provider:f.provider_preference,providers:b,requirement:e,onChange:t=>T({credential_requirements:f.credential_requirements.map(n=>n.id===e.id?t:n)}),onRemove:()=>T({credential_requirements:f.credential_requirements.filter(t=>t.id!==e.id)})},e.id)),f.credential_requirements.length===0&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`profile.credential.none`)}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,disabled:f.provider_preference===`host`&&f.compatibility===`governed`,onClick:()=>{let e=b.length>0?`opencode`:`claude`;T({credential_requirements:[...f.credential_requirements,{id:eE(e,f.credential_requirements),purpose:`model_authentication`,workload:`build`,agent:e,model_provider:b[0]??`anthropic`,authentication_mode:`api_key`,required_protection:f.provider_preference===`docker_sandbox`?`docker_brokered`:`legacy_host_inheritance`}]})},children:l(`profile.credential.add`)})]})]}),(0,X.jsxs)(`fieldset`,{className:`mt-5 border-t border-border/60 pt-4`,children:[(0,X.jsx)(`legend`,{className:`text-sm font-semibold text-foreground`,children:l(`profile.network.title`)}),(0,X.jsx)(`p`,{className:`mt-1 max-w-2xl text-xs text-muted-foreground`,children:l(`profile.network.description`)}),(0,X.jsxs)(`label`,{className:`mt-3 block max-w-xs text-xs text-muted-foreground`,children:[l(`profile.network.mode`),(0,X.jsxs)(`select`,{value:f.network.mode,onChange:e=>{let t=e.target.value;T({network:{mode:t,destinations:t===`allowlist`?f.network.destinations:[]}})},"aria-label":l(`profile.network.modeAria`),className:`mt-1 h-10 w-full rounded-xl border border-border bg-card px-3 text-sm text-foreground`,children:[(0,X.jsx)(`option`,{value:`unrestricted`,children:l(`profile.network.modeOption.unrestricted`)}),(0,X.jsx)(`option`,{value:`allowlist`,disabled:f.provider_preference===`host`,children:l(`profile.network.modeOption.allowlist`)})]})]}),f.network.mode===`allowlist`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`mt-3 flex items-baseline justify-between gap-3`,children:[(0,X.jsx)(`p`,{className:`text-xs font-semibold text-foreground`,children:l(`profile.network.destination.title`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`profile.network.destination.count`,{count:f.network.destinations.length,max:32})})]}),(0,X.jsx)(`p`,{className:`mt-1 max-w-2xl text-xs text-muted-foreground`,children:l(`profile.network.destination.description`)}),(0,X.jsxs)(`div`,{className:`mt-3 max-h-96 space-y-3 overflow-y-auto pr-1`,children:[f.network.destinations.map((e,t)=>(0,X.jsx)(nE,{index:t,destination:e,onChange:e=>T({network:{mode:f.network.mode,destinations:f.network.destinations.map((n,r)=>r===t?e:n)}}),onRemove:()=>T({network:{mode:f.network.mode,destinations:f.network.destinations.filter((e,n)=>n!==t)}})},t)),f.network.destinations.length===0&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`profile.network.destination.none`)})]}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,disabled:f.network.destinations.length>=32,onClick:()=>T({network:{mode:f.network.mode,destinations:[...f.network.destinations,{host:``}]}}),children:l(`profile.network.destination.add`)}),f.network.destinations.length===0&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-red-300`,role:`alert`,children:l(`profile.network.error.empty_allowlist`)}),f.network.destinations.length>=32&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-amber-200`,role:`status`,children:l(`profile.network.limitReached`,{count:32})}),f.provider_preference===`host`&&(0,X.jsx)(`p`,{className:`mt-3 rounded-xl border border-amber-400/20 bg-amber-500/8 p-3 text-xs text-amber-100`,children:l(`profile.network.hostProviderWarning`)})]})]}),i&&(0,X.jsxs)(`section`,{className:`mt-5 border-t border-border/60 pt-4`,children:[(0,X.jsx)(`h4`,{className:`font-semibold text-foreground`,children:l(`target.title`)}),(0,X.jsxs)(`dl`,{className:`mt-3 grid gap-3 text-sm sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-xs text-muted-foreground`,children:l(`target.selected`)}),(0,X.jsxs)(`dd`,{className:`mt-1 break-words text-foreground`,children:[l(`target.kind.${i.kind}`,{defaultValue:i.kind}),`: `,i.label]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-xs text-muted-foreground`,children:l(`target.path`)}),(0,X.jsx)(`dd`,{className:`mt-1 break-all font-mono text-xs text-foreground`,children:i.workspace_path})]})]}),(0,X.jsx)(`p`,{className:`mt-3 rounded-xl border border-amber-400/20 bg-amber-500/8 p-3 text-xs text-amber-100`,children:l(`target.warning`)})]}),(0,X.jsx)(`p`,{className:`mt-4 break-all border-t border-border/60 pt-4 font-mono text-[11px] text-sky-200`,children:l(`profile.activeFingerprint`,{fingerprint:u.fingerprint})})]}),h&&(0,X.jsx)(`p`,{className:`text-xs text-red-300`,role:`alert`,children:h}),!S&&(0,X.jsx)(`p`,{className:`text-xs text-red-300`,role:`alert`,children:l(`profile.invalidCombination`)}),!C&&(0,X.jsx)(`p`,{className:`text-xs text-red-300`,role:`alert`,children:l(`profile.invalidNetwork`)}),!w&&(0,X.jsx)(`p`,{className:`text-xs text-amber-200`,role:`alert`,children:l(`profile.runtimeBlocked`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`profile.applyDescription`)}),x&&(0,X.jsx)(`p`,{className:`rounded-xl border border-amber-400/20 bg-amber-500/8 p-3 text-xs text-amber-100`,children:l(`profile.unsavedWarning`)}),(0,X.jsx)(Q,{type:`button`,size:`sm`,disabled:!x||!S||!C||!w||_,onClick:()=>void E(),children:l(_?`profile.saving`:`profile.save`)})]})},iE=({evidence:e,showLifecycle:t=!0,showDegraded:n=!0,className:r})=>{let{t:i}=q(`common`,{keyPrefix:`executionEnvironmentBadge`}),a=n&&e.blockingDegradation,o=t&&e.lifecycleState!==`unknown`,s=a?`warning`:e.lifecycleState===`failed`||e.lifecycleState===`unavailable`?`destructive`:e.lifecycleState===`ready`||e.lifecycleState===`running`?`success`:`outline`,c=[i(`provider.${e.provider}`),i(`isolation.${e.isolation}`),...o?[i(`lifecycle.${e.lifecycleState}`)]:[],...a?[i(`degraded`)]:[]];return(0,X.jsx)(rC,{variant:s,className:`max-w-full flex-wrap justify-start whitespace-normal text-left ${r??``}`,"aria-label":i(`ariaLabel`,{evidence:c.join(`, `)}),children:c.join(` · `)})},aE=e=>e===`host`||e===`docker_sandbox`?e:`unknown`,oE=e=>e===`microvm`||e===`host_process`?e:e===`microvm_required`?`microvm`:e===`host_process_allowed`?`host_process`:`unknown`,sE=e=>{if(!e)return null;if(e.relationship===`validation`){let t=e.live_environment;return t?{provider:aE(t.provider_kind),providerVersion:t.provider_version,isolation:t.provider_kind===`docker_sandbox`?`microvm`:`unknown`,lifecycleState:t.lifecycle_state,degradationReasons:[],blockingDegradation:[`cleanup_pending`,`failed`,`unavailable`].includes(t.lifecycle_state),environmentRevision:t.environment_revision,targetKey:t.target_key,placementAvailable:!1}:null}let t=e.authority,n=t?.run_authority,r=aE(n?.effective.provider??t?.provider),i=n?.degradations??t?.degradation_reasons??[];return{provider:r,providerVersion:t?.provider_version??e.live_environment?.provider_version??null,isolation:oE(n?.effective.isolation??t?.capabilities?.isolation??(r===`host`?`host_process`:null)),lifecycleState:e.live_environment?.lifecycle_state??`unknown`,degradationReasons:i,blockingDegradation:i.length>0||r===`unknown`,environmentRevision:t?.environment_revision??e.live_environment?.environment_revision??null,targetKey:t?.target.key??e.live_environment?.target_key??null,placementAvailable:r===`host`||e.placement!==null}},cE=e=>({provider:aE(e.provider_kind),providerVersion:e.provider_version,isolation:oE(e.effective_isolation),lifecycleState:e.lifecycle_state,degradationReasons:e.failure_code?[e.failure_code]:[],blockingDegradation:!!e.failure_code||[`cleanup_pending`,`failed`,`unavailable`].includes(e.lifecycle_state),environmentRevision:e.environment_revision,targetKey:e.target_key,placementAvailable:e.lifecycle_state===`running`}),lE=(e,t)=>{let n=e.runtime_compatibility,r=e.batch_environment;if(!n||!r)return null;let i=aE(r.provider);return{provider:i,providerVersion:n.provider.version,isolation:i===`docker_sandbox`?`microvm`:`host_process`,lifecycleState:`unknown`,degradationReasons:[],blockingDegradation:i===`docker_sandbox`&&!!(t&&!t.placement),environmentRevision:r.environment_revision,targetKey:n.target.key,placementAvailable:i===`host`||!!t?.placement}},uE=[`opencode`,`claude`],dE=(e,t)=>t.target_kind===e.target.kind&&t.target_key===e.target.key&&t.target_workspace_path===e.target.workspace_path,fE=(e,t)=>e.environments.find(n=>n.is_reusable&&n.provider_kind===`docker_sandbox`&&n.agent_identity===t&&dE(e,n)&&n.compatible_agents.includes(t)&&[`ready`,`running`,`stopped`].includes(n.lifecycle_state))??null,pE=(e,t,n)=>n?e.environments.filter(r=>r.provider_kind===`docker_sandbox`&&r.agent_identity===t&&dE(e,r)&&r.execution_profile_fingerprint===n&&r.compatible_agents.includes(t)).sort((e,t)=>t.environment_revision-e.environment_revision)[0]??null:null,mE=(e,t)=>{let n=e.provider_validations?.[t];return n&&n.length>0?n:e.model_validations?.[t]??(e.validations[t]?[e.validations[t]]:[])},hE=(e,t,n)=>{let r=fE(e,t);if(!r)return null;let i=mE(r,t);return t===`opencode`?n?i.find(e=>(e.provider||IT(e.model))===n)??null:null:i[0]??null},gE=(e,t,n)=>{if(!e)return null;let r=mE(e,t);return t===`opencode`?n?r.find(e=>(e.provider||IT(e.model))===n)??null:null:r[0]??null},_E=(e,t,n)=>e.environments.filter(t=>dE(e,t)).flatMap(e=>mE(e,t).filter(e=>t!==`opencode`||!!(n&&(e.provider||IT(e.model))===n)).map(t=>({environment:e,validation:t}))).sort((e,t)=>Date.parse(t.validation.run.created_at)-Date.parse(e.validation.run.created_at))[0]??null,vE=(e,t,n,r)=>pE(e,t,n)??fE(e,t)??_E(e,t,r)?.environment??null,yE=({check:e,runId:t,correlationId:n})=>{let{t:r}=q(`projects`,{keyPrefix:`execution`});if(e.state!==`failed`||!e.evidence)return null;let i=e.details?.destination_reason,a=e.details?.reason,o=e.details?.provider_error;return(0,X.jsxs)(`div`,{className:`mt-2 rounded-lg border border-red-400/15 bg-red-500/5 p-2 text-xs`,children:[(0,X.jsx)(`p`,{className:`font-medium text-red-100`,children:r(`validation.evidence.title`,{check:r(`validation.checkKind.${e.kind}`)})}),a&&(0,X.jsx)(`p`,{className:`mt-1 text-red-200`,children:r(`validation.checkReason.${a}`,{defaultValue:a})}),i&&(0,X.jsx)(`p`,{className:`mt-1 text-red-200`,children:r(`validation.evidence.reason`,{reason:r(`validation.destinationReason.${i}`,{defaultValue:i})})}),o?.name&&(0,X.jsx)(`p`,{className:`mt-1 text-red-200`,children:r(`validation.evidence.providerName`,{name:o.name})}),o?.message&&(0,X.jsx)(`p`,{className:`mt-1 break-words text-red-100`,children:r(`validation.evidence.providerMessage`,{message:o.message})}),o?.reference&&(0,X.jsx)(`p`,{className:`mt-1 break-all font-mono text-red-100`,children:r(`validation.evidence.providerReference`,{reference:o.reference})}),o&&(0,X.jsx)(`p`,{className:`mt-1 break-all font-mono text-red-200/75`,children:r(`validation.evidence.runReference`,{runId:t,correlationId:n})}),(0,X.jsx)(`p`,{className:`mt-1 break-words font-mono text-red-100/85`,children:e.evidence.summary}),(0,X.jsxs)(`p`,{className:`mt-1 text-red-200/75`,children:[r(`validation.evidence.exitCode`,{code:e.evidence.exit_code??r(`validation.evidence.exitCodeUnknown`)}),e.evidence.truncated&&` ${r(`validation.evidence.truncated`)}`]})]})},bE={enforced_scoped:`text-sky-200`,declarative_only:`text-amber-200`,unknown:`text-amber-200`,none:`text-muted-foreground`},xE={allow:`text-sky-200`,deny:`text-red-200`,unknown:`text-amber-200`},SE=({validation:e})=>{let{t}=q(`projects`,{keyPrefix:`execution`}),n=KT(e.checks,e.network_evidence,e.requested_network_mode);return(0,X.jsxs)(`div`,{className:`mt-3 rounded-lg border border-border/60 bg-background/25 p-2`,children:[(0,X.jsx)(`p`,{className:`text-xs font-medium text-foreground`,children:t(`validation.network.title`)}),(0,X.jsxs)(`dl`,{className:`mt-1 grid gap-x-4 gap-y-1 text-xs sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`validation.network.modeLabel`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:t(`validation.network.mode.${n.requested_mode}`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`validation.network.postureLabel`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:t(`validation.network.posture.${n.observed_global_posture}`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`validation.network.enforcementLabel`)}),(0,X.jsx)(`dd`,{className:Z(`mt-0.5`,bE[n.enforcement]),children:t(`validation.network.enforcement.${n.enforcement}`)})]})]}),n.enforcement===`declarative_only`&&(0,X.jsx)(`p`,{className:`mt-1 text-xs text-amber-200`,children:t(`validation.network.enforcementNote.declarative_only`)}),n.enforcement===`unknown`&&(0,X.jsx)(`p`,{className:`mt-1 text-xs text-amber-200`,children:t(`validation.network.enforcementNote.unknown`)}),n.decisions.length>0&&(0,X.jsx)(`ul`,{className:`mt-2 max-h-40 space-y-1 overflow-y-auto pr-1 text-xs`,"aria-label":t(`validation.network.decisionsLabel`),children:n.decisions.map(e=>(0,X.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`break-all font-mono text-foreground`,children:e.target}),(0,X.jsx)(`span`,{className:xE[e.decision],children:t(`validation.network.decision.${e.decision}`)}),e.state===`cancelled`&&(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:t(`validation.network.staleDecision`)})]},`${e.target}:${e.state}`))}),n.decisions.some(e=>e.decision===`deny`)&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-amber-200`,children:t(`validation.network.degradation.denied`)}),n.enforcement===`unknown`&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:t(`validation.network.degradation.unknown`)})]})},CE=({environment:e})=>{let{t}=q(`projects`,{keyPrefix:`execution`}),n=e.disk_evidence;return(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(iE,{evidence:cE(e)}),(0,X.jsxs)(`dl`,{className:`grid gap-x-4 gap-y-2 text-xs sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`environment.lastUsed`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:e.last_used_at?new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e.last_used_at)):t(`unknown`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`environment.idlePolicy`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:e.idle_stop_at?t(`environment.idleScheduled`,{value:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e.idle_stop_at))}):t(`environment.idleOnRelease`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`environment.machineDisk`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:n?.machine_storage.state===`ready`?t(`environment.diskAvailable`,{value:(e=>e===null?t(`unknown`):new Intl.NumberFormat(void 0,{style:`unit`,unit:`gigabyte`,maximumFractionDigits:1}).format(e/1e9))(n.machine_storage.available_bytes)}):t(`environment.diskState.${n?.machine_storage.state??`unknown`}`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`environment.privateDisk`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 break-words text-foreground`,children:t(`environment.privateDiskUnsupported`)})]}),e.cleanup_retry_at&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:t(`environment.cleanupRetry`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e.cleanup_retry_at))})]})]})]})},wE=({environment:e,isCurrent:t,validation:n})=>{let{t:r}=q(`projects`,{keyPrefix:`execution`}),i=new Map(n.checks.map(e=>[e.kind,e.state])),a=n.checks.find(e=>e.kind===`authentication`),o=i.get(`authentication`),s=a?.details?.credential_source,c=n.credential_capability?.classification,l=c?r(`credentialClassification.${c}`):s===`brokered`&&a?.details?.credential_service?r(`credentialSource.brokeredWithService`,{service:a.details.credential_service}):r(s?`credentialSource.${s}`:`unknown`),u=i.get(`destination`),d=i.get(`skills`),f=n.checks.find(e=>e.kind===`executable`)?.details?.runtime_version,p=n.checks.find(e=>e.kind===`skills`)?.details?.available_skills?.length??0;return(0,X.jsxs)(`div`,{className:`space-y-3`,children:[!t&&(0,X.jsx)(`p`,{className:`mb-3 rounded-lg border border-amber-400/20 bg-amber-500/8 p-2 text-xs text-amber-100`,children:r(`validation.stale`)}),(0,X.jsxs)(`dl`,{className:`grid gap-x-4 gap-y-2 text-xs sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.runState`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:r(`runState.${n.run.status}`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.provider`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 break-all font-mono text-foreground`,children:n.provider??r(`validation.providerNotSelected`)})]}),n.model&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.probeModel`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 break-all font-mono text-foreground`,children:n.model})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.isolation`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:r(`isolation.${e.effective_isolation}`,{defaultValue:e.effective_isolation})})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.template`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 break-all text-foreground`,children:e.template_identity??e.template_digest??r(`unknown`)})]}),f&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.runtimeVersion`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 font-mono text-foreground`,children:f})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.authentication`)}),(0,X.jsxs)(`dd`,{className:`mt-0.5 text-foreground`,children:[r(o?`checkState.${o}`:`unknown`),` (`,l,`)`]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.skills`)}),(0,X.jsxs)(`dd`,{className:`mt-0.5 text-foreground`,children:[r(d?`checkState.${d}`:`unknown`),` (`,p,`)`]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.destinations`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:r(u?`checkState.${u}`:`unknown`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:r(`validation.interruption`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 text-foreground`,children:n.run.status===`interrupted`?r(`validation.interrupted`):r(`validation.notInterrupted`)})]})]}),(0,X.jsx)(SE,{validation:n}),n.run.failure&&(0,X.jsx)(`div`,{className:`mt-3 rounded-lg border border-red-400/25 bg-red-500/8 p-2`,children:(0,X.jsxs)(`p`,{className:`text-xs text-red-200`,children:[(0,X.jsxs)(`span`,{className:`font-medium`,children:[r(`validation.failure`),`: `]}),n.run.failure.code?`${n.run.failure.code}: `:``,n.run.failure.message]})}),n.checks.filter(e=>e.state===`failed`).map(e=>(0,X.jsx)(yE,{check:e,runId:n.run.id,correlationId:n.run.correlation_id},e.kind)),!n.run.status.match(/completed/)&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:r(`validation.remediation`)}),n.credential_capability&&!n.credential_capability.satisfies_requested_protection&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-amber-200`,children:r(`validation.unsupportedRequirement`)})]})},TE=({agent:e,errorMessage:t,isValidating:n,validationRequestActive:r,validationInProgressForOtherContext:i,onValidate:a,onLifecycleOperation:o,pendingOperation:s,state:c,activeProfileFingerprint:l,validationSelectionReady:u,validationProvider:d,validationModel:f,validationBlocked:p,onOpenExecutionRuntimes:m})=>{let{t:h}=q(`projects`,{keyPrefix:`execution`}),g=fE(c,e),_=pE(c,e,l),v=gE(_,e,d),y=_E(c,e,d),b=v&&_?{environment:_,validation:v}:y,x=!!(b&&_&&b.environment.id===_.id&&b.validation.environment_id===_.id),S=!!(x&&b?.validation.run.status===`completed`&&b.validation.run.domain_status===`ready`),C=e!==`opencode`||!!(b&&(b.validation.provider||IT(b.validation.model))===d&&b.validation.model===f),w=!!(x&&b&&C&&[`queued`,`running`,`waiting`].includes(b.validation.run.status)),T=!!(x&&b&&!C&&!S),E=!!(r||_&&mE(_,e).some(e=>[`queued`,`running`,`waiting`].includes(e.run.status))),D=i||!!(E&&!w&&!n),O=!!(t||x&&b&&!S&&!w&&!T),k=b?KT(b.validation.checks,b.validation.network_evidence??void 0,b.validation.requested_network_mode??void 0):null,A=!!(O&&k?.requested_mode===`allowlist`&&k.enforcement!==`enforced_scoped`),j=n||w?`validation.validating`:t?`validation.failed`:T||!b||!x?`validation.notValidated`:S?`validation.ready`:`validation.failed`,M=b?.validation.checks.find(e=>e.state===`failed`),N=M?.details?.destination_reason,P=M?.details?.reason,F=b?.validation.run.failure?.code===`docker_runtime_network_policy_not_ready`?b.validation.run.failure.message:null,I=b?.validation.credential_capability?.remediation??(N?h(`validation.destinationReason.${N}`,{defaultValue:h(`validation.remediation`)}):null)??(P?h(`validation.checkReason.${P}`,{defaultValue:h(`validation.remediation`)}):null)??F??h(`validation.remediation`),L=vE(c,e,l,d),R=s!==null||E||!!L?.operation_kind;return(0,X.jsxs)(`article`,{className:`p-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`h5`,{className:`font-semibold text-foreground`,children:h(`agent.${e}`)}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:h(j)}),t&&(0,X.jsx)(`p`,{className:`mt-2 max-w-2xl text-xs text-red-300`,role:`alert`,children:t}),D&&(0,X.jsx)(`p`,{className:`mt-2 max-w-2xl text-xs text-sky-200`,role:`status`,children:h(`validation.inProgressOtherContext`)}),O&&(0,X.jsx)(`p`,{className:`mt-2 max-w-2xl text-xs text-red-200`,children:h(`validation.failedSummary`)}),O&&(0,X.jsx)(`p`,{className:`mt-1 max-w-2xl text-xs text-muted-foreground`,children:I}),A&&(0,X.jsx)(`p`,{className:`mt-2 max-w-2xl rounded-lg border border-amber-400/20 bg-amber-500/8 p-2 text-xs text-amber-100`,children:h(`validation.network.contextualBlock`)})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,X.jsxs)(Q,{type:`button`,size:`sm`,disabled:p||E||s!==null||e===`opencode`&&!u,onClick:()=>a(g),children:[n&&(0,X.jsx)(ix,{className:`h-4 w-4 animate-spin`}),n?h(`validation.validating`):h(O?`validation.retry`:`validation.action`,{agent:h(`agent.${e}`)})]}),O&&m&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:m,children:h(`runtime.open`)})]})]}),(b||L)&&(0,X.jsxs)(qT,{title:h(S?`validation.details`:`validation.technicalDetails`),children:[L&&(0,X.jsx)(CE,{environment:L}),b&&(0,X.jsx)(wE,{environment:b.environment,validation:b.validation,isCurrent:x}),L&&(0,X.jsxs)(`div`,{className:`mt-4 border-t border-border/60 pt-3`,children:[L.lifecycle_state===`stopped`&&(0,X.jsx)(`p`,{className:`mb-3 text-xs text-muted-foreground`,children:h(`stop.reconnect`)}),(0,X.jsx)(`p`,{className:`mb-3 max-w-2xl text-xs text-amber-100`,children:h(`stop.wholeSandbox`)}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[[`ready`,`running`].includes(L.lifecycle_state)&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,disabled:R,onClick:()=>o(`stop`,L),children:h(s===`stop`?`stop.stopping`:`stop.action`)}),![`retired`,`retiring`,`cleanup_pending`].includes(L.lifecycle_state)&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,disabled:R,onClick:()=>o(`reset`,L),children:h(s===`reset`?`reset.resetting`:`reset.action`)}),![`retired`,`retiring`].includes(L.lifecycle_state)&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,disabled:R,onClick:()=>o(`retire`,L),children:h(s===`retire`?`retire.retiring`:`retire.action`)}),[`cleanup_pending`,`failed`,`unavailable`].includes(L.lifecycle_state)&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,disabled:R,onClick:()=>o(`cleanup_retry`,L),children:h(s===`cleanup_retry`?`cleanupRetry.retrying`:`cleanupRetry.action`)})]})]})]})]})},EE=(e,t,n,r,i)=>e.projectId===n&&(t!==`opencode`||e.provider===r&&e.model===i),DE=(e,t,n,r)=>({projectId:t,provider:e===`opencode`?n:null,model:e===`opencode`?r:null}),OE=(e,t)=>t?`error`:e?e.activation?.state??`blocked`:`loading`,kE=({projectId:e,buildExecutionProvider:t=`host`,onBuildExecutionProviderChange:n,onCreateBlockingChange:r,onOpenExecutionRuntimes:i,onValidationCompleted:a,availableValidationModels:o,isLoadingValidationModels:s=!1,onRetryValidationModels:c})=>{let{t:l}=q(`projects`,{keyPrefix:`execution`}),[u,d]=(0,p.useState)(null),[f,m]=(0,p.useState)(null),[h,g]=(0,p.useState)(null),[_,v]=(0,p.useState)(null),[y,b]=(0,p.useState)({}),[x,S]=(0,p.useState)({}),[C,w]=(0,p.useState)({}),[T,E]=(0,p.useState)({}),[D,O]=(0,p.useState)(``),[k,A]=(0,p.useState)(``),[j,M]=(0,p.useState)(!1),[N,P]=(0,p.useState)(t),[F,I]=(0,p.useState)(null),[L,R]=(0,p.useState)(t===`docker_sandbox`),z=(0,p.useRef)(e),ee=(0,p.useRef)(0),B=(0,p.useRef)(0),V=(0,p.useRef)({}),H=(0,p.useRef)({});z.current=e;let U=(0,p.useCallback)(e=>(g(null),v(null),Jb(e).then(g).catch(e=>{Ye(e)||v(l(`runtime.loadError`))})),[l]);(0,p.useEffect)(()=>{let e=new AbortController;return U(e.signal),()=>e.abort()},[U]);let W=u?.projectId===e?u.value:null,te=f?.projectId===e?f.value:null,ne={},re={};for(let t of uE){let n=y[t];n&&EE(n.context,t,e,D||null,k||null)&&(ne[t]=n.value);let r=x[t],i=W?vE(W,t,F,D||null):null;r&&r.projectId===e&&r.environmentId===i?.id&&(re[t]=r.value)}let ie=Array.from(new Set((o??[]).map(IT).filter(Boolean))),ae=o!==void 0,G=D||null,oe=G?(o??[]).filter(e=>IT(e)===G):[],se=oe.find(e=>e.id===k)??null,ce=!ae||s,le=ae&&!s&&(o?.length??0)===0,ue=!!(ae&&!s&&G&&se),de=e=>`${e}${W&&hE(W,`opencode`,e)?.run.status===`completed`?` - `+l(`validation.verifiedOption`):``}`;(0,p.useEffect)(()=>{if(!o||s)return;let e=new Set(o.map(IT).filter(Boolean));O(t=>e.has(t)?t:``),A(e=>e&&D&&o.some(t=>t.id===e&&IT(t)===D)?e:``)},[o,s,D]);let fe=(0,p.useCallback)(t=>{if(!e||z.current!==e)return Promise.resolve(!1);let n=ee.current+1;return ee.current=n,z.current===e&&m(null),Yb(e,t).then(t=>ee.current===n&&z.current===e?(d({projectId:e,value:t}),m(null),!0):!1).catch(t=>(!Ye(t)&&ee.current===n&&z.current===e&&m({projectId:e,value:l(`loadError`)}),!1))},[e,l]);(0,p.useEffect)(()=>{if(!e)return;let t=new AbortController;return fe(t.signal),()=>t.abort()},[fe,e]),(0,p.useEffect)(()=>(O(``),A(``),b({}),S({}),w({}),V.current={},H.current={},()=>{for(let e of uE)H.current[e]?.abort()}),[e]);let pe=async(t,n)=>{if(!e||j)return;let r=DE(t,e,G,se?.id??null);if(t===`opencode`&&(!ue||!r.provider||!r.model)||V.current[t]?.projectId===e)return;let i=B.current+1;B.current=i;let o={...r,requestId:i},s=new AbortController;H.current={...H.current,[t]:s},V.current={...V.current,[t]:o},w(e=>({...e,[t]:o})),b(e=>({...e,[t]:void 0}));try{await Qb(e,n?.id??null,t,r.provider,r.model,s.signal),z.current===e&&(await fe(),z.current===e&&a?.())}catch(n){if(!Ye(n)&&z.current===e){let e=n instanceof Ge&&n.message.trim()?n.message:l(`validation.error`,{agent:l(`agent.${t}`)});b(n=>({...n,[t]:{context:r,value:e}})),await fe()}}finally{V.current[t]?.requestId===i&&(V.current={...V.current,[t]:void 0}),H.current[t]===s&&(H.current={...H.current,[t]:void 0}),w(e=>e[t]?.requestId===i?{...e,[t]:void 0}:e)}},me=async(t,n,r)=>{if(!e||!window.confirm(l(`${n===`cleanup_retry`?`cleanupRetry`:n}.confirm`)))return;let i=B.current+1;B.current=i;let a={...DE(t,e,G,se?.id??null),requestId:i,operation:n};E(e=>({...e,[t]:a})),S(e=>({...e,[t]:void 0}));try{await(n===`stop`?tx:n===`retire`?nx:n===`cleanup_retry`?rx:$b)(e,r.id),z.current===e&&await fe()}catch(i){!Ye(i)&&z.current===e&&(S(i=>({...i,[t]:{projectId:e,environmentId:r.id,value:l(`${n===`cleanup_retry`?`cleanupRetry`:n}.error`)}})),await fe())}finally{E(e=>e[t]?.requestId===i?{...e,[t]:void 0}:e)}},he=OE(h,_),ge=he===`blocked`||he===`error`||he===`loading`,_e=e?N:t,ve=_e===`docker_sandbox`||L,ye=h?.observations?.filter(e=>e.state!==`ready`)??[];return(0,p.useEffect)(()=>(e||r?.(t===`docker_sandbox`&&ge),()=>r?.(!1)),[t,ge,r,e]),(0,p.useEffect)(()=>{P(t),R(t===`docker_sandbox`)},[t,e]),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[e&&(0,X.jsx)(`div`,{className:`rounded-2xl border border-border/70 bg-background/35 p-4`,children:(0,X.jsx)(rE,{projectId:e,availableModels:o,dockerRuntimeReady:!ge,dockerRuntimeStatus:he,target:W?.target,onDirtyChange:M,onDraftChange:e=>P(e),onRevisionChange:I,onProviderSaved:async t=>{n?.(t),d(t=>t?.projectId===e?null:t),await fe()}})}),!e&&(0,X.jsxs)(`div`,{className:`rounded-2xl border border-border/70 bg-background/35 p-4`,children:[(0,X.jsx)(YT,{value:t,runtimeStatus:he,onChange:e=>n?.(e)}),(0,X.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:l(`create.staged`)})]}),_e===`host`&&!L&&(0,X.jsxs)(`div`,{className:`rounded-2xl border border-sky-400/20 bg-sky-500/7 p-4`,children:[(0,X.jsx)(`h4`,{className:`font-semibold text-foreground`,children:l(`host.title`)}),(0,X.jsx)(`p`,{className:`mt-1 max-w-2xl text-sm text-muted-foreground`,children:l(`host.summary`)}),(0,X.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,X.jsx)(Q,{type:`button`,size:`sm`,onClick:()=>R(!0),children:l(`runtime.setup`)}),i&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:i,children:l(`runtime.open`)})]})]}),ve&&(0,X.jsxs)(`section`,{className:Z(`rounded-2xl border p-4`,ge?`border-amber-400/25 bg-amber-500/8`:`border-border/70 bg-background/35`),children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h4`,{className:`font-semibold text-foreground`,children:l(`runtime.setupTitle`)}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,role:`status`,children:l(`runtime.state.${he}`)})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(he===`error`||he===`blocked`)&&(0,X.jsx)(Q,{type:`button`,size:`sm`,onClick:()=>void U(),children:l(`runtime.retry`)}),i&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:i,children:l(`runtime.open`)})]})]}),ye.length>0&&(0,X.jsx)(`ul`,{className:`mt-3 space-y-2 text-xs text-amber-100`,children:ye.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`span`,{className:`font-medium`,children:e.summary}),e.remediation&&(0,X.jsx)(`span`,{className:`mt-0.5 block text-amber-100/80`,children:e.remediation})]},e.code))}),!e&&(0,X.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:l(`create.validationAfterCreate`)})]}),e&&!W&&ve&&(0,X.jsx)(`p`,{className:te?`text-sm text-red-300`:`text-sm text-muted-foreground`,role:te?`alert`:`status`,children:te??l(`loading`)}),W&&te&&ve&&(0,X.jsx)(`p`,{className:`rounded-xl border border-red-400/25 bg-red-500/8 p-3 text-sm text-red-200`,role:`alert`,children:te}),W&&ve&&(0,X.jsxs)(`div`,{className:`rounded-2xl border border-border/70 bg-background/35`,children:[(0,X.jsxs)(`div`,{className:`border-b border-border/60 p-4`,children:[(0,X.jsx)(`h4`,{className:`font-semibold text-foreground`,children:l(`validation.title`)}),(0,X.jsx)(`p`,{className:`mt-1 max-w-2xl text-xs text-muted-foreground`,children:l(`validation.environmentWillPrepare`)}),j&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-amber-200`,role:`status`,children:l(`validation.saveProfileFirst`)}),ae&&(0,X.jsxs)(`div`,{className:`mt-4 grid max-w-3xl gap-3 sm:grid-cols-[minmax(22rem,1.1fr)_minmax(0,1fr)]`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(pv,{label:l(`validation.providerLabel`),triggerLabel:G?de(G):l(s?`validation.providerLoading`:`validation.providerPlaceholder`),triggerAriaLabel:l(`validation.providerLabel`),selectId:`execution-validation-provider`,selectedValue:D,onChange:e=>{O(e),A((o??[]).find(t=>IT(t)===e)?.id??``)},disabled:s,contentClassName:`min-w-[22rem]`,groups:[{label:``,options:[{value:``,label:l(s?`validation.providerLoading`:`validation.providerPlaceholder`)},...ie.map(e=>({value:e,label:de(e)}))]}]}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:l(`validation.providerDescription`)}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-amber-200`,children:l(`validation.credentialDescription`)}),G&&(0,X.jsx)(`p`,{className:`mt-1 text-xs text-sky-200`,children:l(`validation.credentialSupportEvidence`)})]}),G&&oe.length>0&&!s&&(0,X.jsx)(pv,{label:l(`validation.modelLabel`),triggerLabel:se?.label??l(`validation.modelPlaceholder`),triggerAriaLabel:l(`validation.modelLabel`),selectId:`execution-validation-model`,selectedValue:k,onChange:A,groups:[{label:``,options:oe.map(e=>({value:e.id,label:e.label}))}]})]}),ce&&(0,X.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,role:`status`,children:l(`validation.modelCatalogLoading`)}),le&&(0,X.jsx)(`p`,{className:`mt-3 text-xs text-amber-200`,role:`status`,children:l(`validation.modelCatalogEmpty`)}),(ce||le)&&c&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`mt-3`,onClick:c,children:l(`validation.modelCatalogRetry`)}),ae&&!s&&!le&&ie.length>0&&!G&&(0,X.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,role:`status`,children:l(`validation.providerFirst`)}),G&&!s&&oe.length===0&&(0,X.jsx)(`p`,{className:`mt-3 text-xs text-amber-200`,role:`status`,children:l(`validation.modelUnavailable`)})]}),(0,X.jsx)(`div`,{className:`divide-y divide-border/60`,children:uE.map(t=>(0,X.jsx)(TE,{agent:t,errorMessage:re[t]??ne[t]??null,state:W,activeProfileFingerprint:F,validationRequestActive:C[t]?.projectId===e,validationInProgressForOtherContext:C[t]?.projectId===e&&t===`opencode`&&(C[t]?.provider!==G||C[t]?.model!==k),isValidating:C[t]?.projectId===e&&(t!==`opencode`||C[t]?.provider===G&&C[t]?.model===k),onValidate:e=>void pe(t,e),pendingOperation:T[t]?.projectId===e?T[t]?.operation??null:null,onLifecycleOperation:(e,n)=>void me(t,e,n),validationSelectionReady:t===`claude`||ue,validationProvider:t===`opencode`?G:`anthropic`,validationModel:t===`opencode`?se?.id??null:null,validationBlocked:j,onOpenExecutionRuntimes:i},t))})]})]})},AE=({title:e,description:t,headerAccessory:n,children:r})=>(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 border-b border-border/60 pb-4 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-lg font-semibold text-foreground`,children:e}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:t})]}),n]}),r]}),jE=({label:e,summary:t,tone:n=`default`})=>(0,X.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col items-start text-left`,children:(0,X.jsxs)(`div`,{className:`flex w-full items-start justify-between gap-3`,children:[(0,X.jsx)(`span`,{className:Z(`text-sm font-medium`,n===`danger`?`text-red-200`:`text-foreground`),children:e}),(0,X.jsx)(`span`,{className:Z(`shrink-0 text-[10px] font-semibold uppercase tracking-[0.18em]`,n===`danger`?`text-red-300/80`:`text-muted-foreground`),children:t})]})}),ME=()=>({name:``,cmd:``,cwd:``}),NE=()=>({source:``,target:``,mode:`copy`}),PE=e=>{let t=`check-${crypto.randomUUID()}`,n=0;for(;e.has(t)&&n<32;)t=`check-${crypto.randomUUID()}`,n+=1;if(e.has(t)){let n=1,r=t;for(;e.has(`${r}-${n}`);)n+=1;return`${r}-${n}`}return t},FE=(e=new Set)=>({id:PE(e),name:``,category:`test`,command:``,cwd:``,timeoutMs:String(HC),runner:`auto`,consequence:`ordinary`,required:!1,preReview:!1,postBuild:!1,autoFix:!1}),IE=()=>({name:``,repoPath:``,buildExecutionProvider:`host`,linkedProjectIds:[],runSetup:[],runServices:[],checkDefinitions:[],runIde:``,previewServiceName:``,previewPath:``,previewCapabilityMode:`auto`,helperModel:``,helperVariant:``,reviewerModel:``,reviewerVariant:``,commitMessageRules:``,commitAfterEachTicket:!1,autoParkStaleTickets:!1,memoryEnabled:!1,scanIncludeGlobs:[],scanExcludeGlobs:[],worktreeSync:[],specAwareCodeReviewEnabled:!1,automationDepth:`manual`,automationReviewFixEnabled:!1,automationPauseOnOpenQuestions:!1,automationReviewSeverity:`medium`,automationReviewMaxIterations:3}),LE=(e,t)=>({name:e.name,repoPath:e.repoPath,buildExecutionProvider:e.buildExecutionProvider??`host`,linkedProjectIds:e.linkedProjectIds,runSetupText:e.runSetup.join(`
78
78
  `),runServices:e.runServices.length>0?e.runServices.map(e=>({name:e.name??``,cmd:e.cmd??``,cwd:e.cwd??``})):[],checkDefinitions:(e.checkDefinitions??[]).length>0?(e.checkDefinitions??[]).map(e=>({id:e.id,name:e.name??``,category:e.category,command:e.command??``,cwd:e.cwd??``,timeoutMs:e.timeoutMs,runner:e.runner??`auto`,consequence:e.consequence??`ordinary`,required:e.required,preReview:e.required?e.preReview:!1,postBuild:e.postBuild,autoFix:e.autoFix})):[],runIde:e.runIde,previewServiceName:e.previewServiceName??``,previewPath:e.previewPath??``,previewCapabilityMode:e.previewCapabilityMode??`auto`,helperModel:e.helperModel,helperVariant:e.helperVariant,helperModels:e.helperModels??tw({},t,{model:e.helperModel||null,variant:e.helperModel&&e.helperVariant||null}),reviewerModel:e.reviewerModel??``,reviewerVariant:e.reviewerVariant??``,reviewerModels:e.reviewerModels??tw({},t,{model:e.reviewerModel||null,variant:e.reviewerModel&&e.reviewerVariant||null}),commitMessageRules:e.commitMessageRules,commitAfterEachTicket:e.commitAfterEachTicket,autoParkStaleTickets:e.autoParkStaleTickets,memoryEnabled:e.memoryEnabled,scanIncludeGlobsText:(e.scanIncludeGlobs??[]).join(`
79
79
  `),scanExcludeGlobsText:(e.scanExcludeGlobs??[]).join(`
80
80
  `),worktreeSync:e.worktreeSync.length>0?e.worktreeSync.map(e=>({source:e.source??``,target:e.target??``,mode:e.mode})):[],specAwareCodeReviewEnabled:e.specAwareCodeReviewEnabled,automationDepth:e.automationDepth,automationReviewFixEnabled:e.automationReviewFixEnabled,automationPauseOnOpenQuestions:e.automationPauseOnOpenQuestions,automationReviewSeverity:e.automationReviewSeverity,automationReviewMaxIterations:e.automationReviewMaxIterations}),RE=(e,t,n)=>e(`modal.${t}`,n),zE=e=>e.split(`
@@ -144,7 +144,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
144
144
  `,inConstruct:`tableCell`},{atBreak:!0,character:`|`,after:`[ :-]`},{character:`|`,inConstruct:`tableCell`},{atBreak:!0,character:`:`,after:`-`},{atBreak:!0,character:`-`,after:`[:|-]`}],handlers:{inlineCode:f,table:o,tableCell:c,tableRow:s}};function o(e,t,n,r){return l(u(e,n,r),e.align)}function s(e,t,n,r){let i=l([d(e,n,r)]);return i.slice(0,i.indexOf(`
145
145
  `))}function c(e,t,n,r){let i=n.enter(`tableCell`),o=n.enter(`phrasing`),s=n.containerPhrasing(e,{...r,before:a,after:a});return o(),i(),s}function l(e,t){return CH(e,{align:t,alignDelimiters:r,padding:n,stringLength:i})}function u(e,t,n){let r=e.children,i=-1,a=[],o=t.enter(`table`);for(;++i<r.length;)a[i]=d(r[i],t,n);return o(),a}function d(e,t,n){let r=e.children,i=-1,a=[],o=t.enter(`tableRow`);for(;++i<r.length;)a[i]=c(r[i],e,t,n);return o(),a}function f(e,t,n){let r=bU.inlineCode(e,t,n);return n.stack.includes(`tableCell`)&&(r=r.replace(/\|/g,`\\$&`)),r}}function AU(){return{exit:{taskListCheckValueChecked:MU,taskListCheckValueUnchecked:MU,paragraph:NU}}}function jU(){return{unsafe:[{atBreak:!0,character:`-`,after:`[:|-]`}],handlers:{listItem:PU}}}function MU(e){let t=this.stack[this.stack.length-2];t.type,t.checked=e.type===`taskListCheckValueChecked`}function NU(e){let t=this.stack[this.stack.length-2];if(t&&t.type===`listItem`&&typeof t.checked==`boolean`){let e=this.stack[this.stack.length-1];e.type;let n=e.children[0];if(n&&n.type===`text`){let r=t.children,i=-1,a;for(;++i<r.length;){let e=r[i];if(e.type===`paragraph`){a=e;break}}a===e&&(n.value=n.value.slice(1),n.value.length===0?e.children.shift():e.position&&n.position&&typeof n.position.start.offset==`number`&&(n.position.start.column++,n.position.start.offset++,e.position.start=Object.assign({},n.position.start)))}}this.exit(e)}function PU(e,t,n,r){let i=e.children[0],a=typeof e.checked==`boolean`&&i&&i.type===`paragraph`,o=`[`+(e.checked?`x`:` `)+`] `,s=n.createTracker(r);a&&s.move(o);let c=bU.listItem(e,t,n,{...r,...s.current()});return a&&(c=c.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,l)),c;function l(e){return e+o}}function FU(){return[VV(),dH(),gH(),xU(),AU()]}function IU(e){return{extensions:[HV(),fH(e),_H(),kU(e),jU()]}}var LU={tokenize:ZU,partial:!0},RU={tokenize:QU,partial:!0},zU={tokenize:$U,partial:!0},BU={tokenize:eW,partial:!0},VU={tokenize:tW,partial:!0},HU={name:`wwwAutolink`,tokenize:YU,previous:nW},UU={name:`protocolAutolink`,tokenize:XU,previous:rW},WU={name:`emailAutolink`,tokenize:JU,previous:iW},GU={};function KU(){return{text:GU}}for(var qU=48;qU<123;)GU[qU]=WU,qU++,qU===58?qU=65:qU===91&&(qU=97);GU[43]=WU,GU[45]=WU,GU[46]=WU,GU[95]=WU,GU[72]=[WU,UU],GU[104]=[WU,UU],GU[87]=[WU,HU],GU[119]=[WU,HU];function JU(e,t,n){let r=this,i,a;return o;function o(t){return!aW(t)||!iW.call(r,r.previous)||oW(r.events)?n(t):(e.enter(`literalAutolink`),e.enter(`literalAutolinkEmail`),s(t))}function s(t){return aW(t)?(e.consume(t),s):t===64?(e.consume(t),c):n(t)}function c(t){return t===46?e.check(VU,u,l)(t):t===45||t===95||VI(t)?(a=!0,e.consume(t),c):u(t)}function l(t){return e.consume(t),i=!0,c}function u(o){return a&&i&&BI(r.previous)?(e.exit(`literalAutolinkEmail`),e.exit(`literalAutolink`),t(o)):n(o)}}function YU(e,t,n){let r=this;return i;function i(t){return t!==87&&t!==119||!nW.call(r,r.previous)||oW(r.events)?n(t):(e.enter(`literalAutolink`),e.enter(`literalAutolinkWww`),e.check(LU,e.attempt(RU,e.attempt(zU,a),n),n)(t))}function a(n){return e.exit(`literalAutolinkWww`),e.exit(`literalAutolink`),t(n)}}function XU(e,t,n){let r=this,i=``,a=!1;return o;function o(t){return(t===72||t===104)&&rW.call(r,r.previous)&&!oW(r.events)?(e.enter(`literalAutolink`),e.enter(`literalAutolinkHttp`),i+=String.fromCodePoint(t),e.consume(t),s):n(t)}function s(t){if(BI(t)&&i.length<5)return i+=String.fromCodePoint(t),e.consume(t),s;if(t===58){let n=i.toLowerCase();if(n===`http`||n===`https`)return e.consume(t),c}return n(t)}function c(t){return t===47?(e.consume(t),a?l:(a=!0,c)):n(t)}function l(t){return t===null||UI(t)||JI(t)||ZI(t)||XI(t)?n(t):e.attempt(RU,e.attempt(zU,u),n)(t)}function u(n){return e.exit(`literalAutolinkHttp`),e.exit(`literalAutolink`),t(n)}}function ZU(e,t,n){let r=0;return i;function i(t){return(t===87||t===119)&&r<3?(r++,e.consume(t),i):t===46&&r===3?(e.consume(t),a):n(t)}function a(e){return e===null?n(e):t(e)}}function QU(e,t,n){let r,i,a;return o;function o(t){return t===46||t===95?e.check(BU,c,s)(t):t===null||JI(t)||ZI(t)||t!==45&&XI(t)?c(t):(a=!0,e.consume(t),o)}function s(t){return t===95?r=!0:(i=r,r=void 0),e.consume(t),o}function c(e){return i||r||!a?n(e):t(e)}}function $U(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?a(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(BU,t,a)(o):o===null||JI(o)||ZI(o)?t(o):(e.consume(o),i)}function a(t){return t===41&&r++,e.consume(t),i}}function eW(e,t,n){return r;function r(o){return o===33||o===34||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===63||o===95||o===126?(e.consume(o),r):o===38?(e.consume(o),a):o===93?(e.consume(o),i):o===60||o===null||JI(o)||ZI(o)?t(o):n(o)}function i(e){return e===null||e===40||e===91||JI(e)||ZI(e)?t(e):r(e)}function a(e){return BI(e)?o(e):n(e)}function o(t){return t===59?(e.consume(t),r):BI(t)?(e.consume(t),o):n(t)}}function tW(e,t,n){return r;function r(t){return e.consume(t),i}function i(e){return VI(e)?n(e):t(e)}}function nW(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||JI(e)}function rW(e){return!BI(e)}function iW(e){return!(e===47||aW(e))}function aW(e){return e===43||e===45||e===46||e===95||VI(e)}function oW(e){let t=e.length,n=!1;for(;t--;){let r=e[t][1];if((r.type===`labelLink`||r.type===`labelImage`)&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}var sW={tokenize:hW,partial:!0};function cW(){return{document:{91:{name:`gfmFootnoteDefinition`,tokenize:fW,continuation:{tokenize:pW},exit:mW}},text:{91:{name:`gfmFootnoteCall`,tokenize:dW},93:{name:`gfmPotentialFootnoteCall`,add:`after`,tokenize:lW,resolveTo:uW}}}}function lW(e,t,n){let r=this,i=r.events.length,a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o;for(;i--;){let e=r.events[i][1];if(e.type===`labelImage`){o=e;break}if(e.type===`gfmFootnoteCall`||e.type===`labelLink`||e.type===`label`||e.type===`image`||e.type===`link`)break}return s;function s(i){if(!o||!o._balanced)return n(i);let s=zI(r.sliceSerialize({start:o.end,end:r.now()}));return s.codePointAt(0)!==94||!a.includes(s.slice(1))?n(i):(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(i),e.exit(`gfmFootnoteCallLabelMarker`),t(i))}}function uW(e,t){let n=e.length;for(;n--;)if(e[n][1].type===`labelImage`&&e[n][0]===`enter`){e[n][1];break}e[n+1][1].type=`data`,e[n+3][1].type=`gfmFootnoteCallLabelMarker`;let r={type:`gfmFootnoteCall`,start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:`gfmFootnoteCallMarker`,start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;let a={type:`gfmFootnoteCallString`,start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:`chunkString`,contentType:`string`,start:Object.assign({},a.start),end:Object.assign({},a.end)},s=[e[n+1],e[n+2],[`enter`,r,t],e[n+3],e[n+4],[`enter`,i,t],[`exit`,i,t],[`enter`,a,t],[`enter`,o,t],[`exit`,o,t],[`exit`,a,t],e[e.length-2],e[e.length-1],[`exit`,r,t]];return e.splice(n,e.length-n+1,...s),e}function dW(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a=0,o;return s;function s(t){return e.enter(`gfmFootnoteCall`),e.enter(`gfmFootnoteCallLabelMarker`),e.consume(t),e.exit(`gfmFootnoteCallLabelMarker`),c}function c(t){return t===94?(e.enter(`gfmFootnoteCallMarker`),e.consume(t),e.exit(`gfmFootnoteCallMarker`),e.enter(`gfmFootnoteCallString`),e.enter(`chunkString`).contentType=`string`,l):n(t)}function l(s){if(a>999||s===93&&!o||s===null||s===91||JI(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(zI(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return JI(s)||(o=!0),a++,e.consume(s),s===92?u:l}function u(t){return t===91||t===92||t===93?(e.consume(t),a++,l):l(t)}}function fW(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a,o=0,s;return c;function c(t){return e.enter(`gfmFootnoteDefinition`)._container=!0,e.enter(`gfmFootnoteDefinitionLabel`),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),l}function l(t){return t===94?(e.enter(`gfmFootnoteDefinitionMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionMarker`),e.enter(`gfmFootnoteDefinitionLabelString`),e.enter(`chunkString`).contentType=`string`,u):n(t)}function u(t){if(o>999||t===93&&!s||t===null||t===91||JI(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=zI(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return JI(t)||(s=!0),o++,e.consume(t),t===92?d:u}function d(t){return t===91||t===92||t===93?(e.consume(t),o++,u):u(t)}function f(t){return t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),i.includes(a)||i.push(a),eL(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function pW(e,t,n){return e.check(hL,t,e.attempt(sW,t,n))}function mW(e){e.exit(`gfmFootnoteDefinition`)}function hW(e,t,n){let r=this;return eL(e,i,`gfmFootnoteDefinitionIndent`,5);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`gfmFootnoteDefinitionIndent`&&i[2].sliceSerialize(i[1],!0).length===4?t(e):n(e)}}function gW(e){let t=(e||{}).singleTilde,n={name:`strikethrough`,tokenize:i,resolveAll:r};return t??=!0,{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function r(e,t){let n=-1;for(;++n<e.length;)if(e[n][0]===`enter`&&e[n][1].type===`strikethroughSequenceTemporary`&&e[n][1]._close){let r=n;for(;r--;)if(e[r][0]===`exit`&&e[r][1].type===`strikethroughSequenceTemporary`&&e[r][1]._open&&e[n][1].end.offset-e[n][1].start.offset===e[r][1].end.offset-e[r][1].start.offset){e[n][1].type=`strikethroughSequence`,e[r][1].type=`strikethroughSequence`;let i={type:`strikethrough`,start:Object.assign({},e[r][1].start),end:Object.assign({},e[n][1].end)},a={type:`strikethroughText`,start:Object.assign({},e[r][1].end),end:Object.assign({},e[n][1].start)},o=[[`enter`,i,t],[`enter`,e[r][1],t],[`exit`,e[r][1],t],[`enter`,a,t]],s=t.parser.constructs.insideSpan.null;s&&MI(o,o.length,0,cL(s,e.slice(r+1,n),t)),MI(o,o.length,0,[[`exit`,a,t],[`enter`,e[n][1],t],[`exit`,e[n][1],t],[`exit`,i,t]]),MI(e,r-1,n-r+3,o),n=r+o.length-2;break}}for(n=-1;++n<e.length;)e[n][1].type===`strikethroughSequenceTemporary`&&(e[n][1].type=`data`);return e}function i(e,n,r){let i=this.previous,a=this.events,o=0;return s;function s(t){return i===126&&a[a.length-1][1].type!==`characterEscape`?r(t):(e.enter(`strikethroughSequenceTemporary`),c(t))}function c(a){let s=sL(i);if(a===126)return o>1?r(a):(e.consume(a),o++,c);if(o<2&&!t)return r(a);let l=e.exit(`strikethroughSequenceTemporary`),u=sL(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var _W=class{constructor(){this.map=[]}add(e,t,n){vW(this,e,t,n)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0}};function vW(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function yW(e,t){let n=!1,r=[];for(;t<e.length;){let i=e[t];if(n){if(i[0]===`enter`)i[1].type===`tableContent`&&r.push(e[t+1][1].type===`tableDelimiterMarker`?`left`:`none`);else if(i[1].type===`tableContent`){if(e[t-1][1].type===`tableDelimiterMarker`){let e=r.length-1;r[e]=r[e]===`left`?`center`:`right`}}else if(i[1].type===`tableDelimiterRow`)break}else i[0]===`enter`&&i[1].type===`tableDelimiterRow`&&(n=!0);t+=1}return r}function bW(){return{flow:{null:{name:`table`,tokenize:xW,resolveAll:SW}}}}function xW(e,t,n){let r=this,i=0,a=0,o;return s;function s(e){let t=r.events.length-1;for(;t>-1;){let e=r.events[t][1].type;if(e===`lineEnding`||e===`linePrefix`)t--;else break}let i=t>-1?r.events[t][1].type:null,a=i===`tableHead`||i===`tableRow`?S:c;return a===S&&r.parser.lazy[r.now().line]?n(e):a(e)}function c(t){return e.enter(`tableHead`),e.enter(`tableRow`),l(t)}function l(e){return e===124?u(e):(o=!0,a+=1,u(e))}function u(t){return t===null?n(t):qI(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):YI(t)?eL(e,u,`whitespace`)(t):(a+=1,o&&(o=!1,i+=1),t===124?(e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),o=!0,u):(e.enter(`data`),d(t)))}function d(t){return t===null||t===124||JI(t)?(e.exit(`data`),u(t)):(e.consume(t),t===92?f:d)}function f(t){return t===92||t===124?(e.consume(t),d):d(t)}function p(t){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(t):(e.enter(`tableDelimiterRow`),o=!1,YI(t)?eL(e,m,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):m(t))}function m(t){return t===45||t===58?g(t):t===124?(o=!0,e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),h):x(t)}function h(t){return YI(t)?eL(e,g,`whitespace`)(t):g(t)}function g(t){return t===58?(a+=1,o=!0,e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),_):t===45?(a+=1,_(t)):t===null||qI(t)?b(t):x(t)}function _(t){return t===45?(e.enter(`tableDelimiterFiller`),v(t)):x(t)}function v(t){return t===45?(e.consume(t),v):t===58?(o=!0,e.exit(`tableDelimiterFiller`),e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),y):(e.exit(`tableDelimiterFiller`),y(t))}function y(t){return YI(t)?eL(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||qI(n)?!o||i!==a?x(n):(e.exit(`tableDelimiterRow`),e.exit(`tableHead`),t(n)):x(n)}function x(e){return n(e)}function S(t){return e.enter(`tableRow`),C(t)}function C(n){return n===124?(e.enter(`tableCellDivider`),e.consume(n),e.exit(`tableCellDivider`),C):n===null||qI(n)?(e.exit(`tableRow`),t(n)):YI(n)?eL(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||JI(t)?(e.exit(`data`),C(t)):(e.consume(t),t===92?T:w)}function T(t){return t===92||t===124?(e.consume(t),w):w(t)}}function SW(e,t){let n=-1,r=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],s=!1,c=0,l,u,d,f=new _W;for(;++n<e.length;){let p=e[n],m=p[1];p[0]===`enter`?m.type===`tableHead`?(s=!1,c!==0&&(wW(f,t,c,l,u),u=void 0,c=0),l={type:`table`,start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[[`enter`,l,t]])):m.type===`tableRow`||m.type===`tableDelimiterRow`?(r=!0,d=void 0,a=[0,0,0,0],o=[0,n+1,0,0],s&&(s=!1,u={type:`tableBody`,start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[[`enter`,u,t]])),i=m.type===`tableDelimiterRow`?2:u?3:1):i&&(m.type===`data`||m.type===`tableDelimiterMarker`||m.type===`tableDelimiterFiller`)?(r=!1,o[2]===0&&(a[1]!==0&&(o[0]=o[1],d=CW(f,t,a,i,void 0,d),a=[0,0,0,0]),o[2]=n)):m.type===`tableCellDivider`&&(r?r=!1:(a[1]!==0&&(o[0]=o[1],d=CW(f,t,a,i,void 0,d)),a=o,o=[a[1],n,0,0])):m.type===`tableHead`?(s=!0,c=n):m.type===`tableRow`||m.type===`tableDelimiterRow`?(c=n,a[1]===0?o[1]!==0&&(d=CW(f,t,o,i,n,d)):(o[0]=o[1],d=CW(f,t,a,i,n,d)),i=0):i&&(m.type===`data`||m.type===`tableDelimiterMarker`||m.type===`tableDelimiterFiller`)&&(o[3]=n)}for(c!==0&&wW(f,t,c,l,u),f.consume(t.events),n=-1;++n<t.events.length;){let e=t.events[n];e[0]===`enter`&&e[1].type===`table`&&(e[1]._align=yW(t.events,n))}return e}function CW(e,t,n,r,i,a){let o=r===1?`tableHeader`:r===2?`tableDelimiter`:`tableData`;n[0]!==0&&(a.end=Object.assign({},TW(t.events,n[0])),e.add(n[0],0,[[`exit`,a,t]]));let s=TW(t.events,n[1]);if(a={type:o,start:Object.assign({},s),end:Object.assign({},s)},e.add(n[1],0,[[`enter`,a,t]]),n[2]!==0){let i=TW(t.events,n[2]),a=TW(t.events,n[3]),o={type:`tableContent`,start:Object.assign({},i),end:Object.assign({},a)};if(e.add(n[2],0,[[`enter`,o,t]]),r!==2){let r=t.events[n[2]],i=t.events[n[3]];if(r[1].end=Object.assign({},i[1].end),r[1].type=`chunkText`,r[1].contentType=`text`,n[3]>n[2]+1){let t=n[2]+1,r=n[3]-n[2]-1;e.add(t,r,[])}}e.add(n[3]+1,0,[[`exit`,o,t]])}return i!==void 0&&(a.end=Object.assign({},TW(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function wW(e,t,n,r,i){let a=[],o=TW(t.events,n);i&&(i.end=Object.assign({},o),a.push([`exit`,i,t])),r.end=Object.assign({},o),a.push([`exit`,r,t]),e.add(n+1,0,a)}function TW(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var EW={name:`tasklistCheck`,tokenize:OW};function DW(){return{text:{91:EW}}}function OW(e,t,n){let r=this;return i;function i(t){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(t):(e.enter(`taskListCheck`),e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),a)}function a(t){return JI(t)?(e.enter(`taskListCheckValueUnchecked`),e.consume(t),e.exit(`taskListCheckValueUnchecked`),o):t===88||t===120?(e.enter(`taskListCheckValueChecked`),e.consume(t),e.exit(`taskListCheckValueChecked`),o):n(t)}function o(t){return t===93?(e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),e.exit(`taskListCheck`),s):n(t)}function s(r){return qI(r)?t(r):YI(r)?e.check({tokenize:kW},t,n)(r):n(r)}}function kW(e,t,n){return eL(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function AW(e){return FI([KU(),cW(),gW(e),bW(),DW()])}var jW={};function MW(e){let t=this,n=e||jW,r=t.data(),i=r.micromarkExtensions||=[],a=r.fromMarkdownExtensions||=[],o=r.toMarkdownExtensions||=[];i.push(AW(n)),a.push(FU()),o.push(IU(n))}function NW(e){FV(e,[/\r?\n|\r/g,PW])}function PW(){return{type:`break`}}function FW(){return function(e){NW(e)}}var IW=/^\[(?:X|x| )\]\s+/,LW=e=>{let t=e.split(`
146
146
  `).map(e=>e.trim()).filter(e=>e.length>0);return t.length>0&&t.every(e=>IW.test(e))},RW=e=>LW(e)?e.split(`
147
- `).map(e=>e.trim()).filter(e=>e.length>0):[],zW=`modulepreload`,BW=function(e){return`/`+e},VW={},HW=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}r=o(t.map(t=>{if(t=BW(t,n),t in VW)return;VW[t]=!0;let r=t.endsWith(`.css`),i=r?`[rel="stylesheet"]`:``;if(n)for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${t}"]${i}`))return;let o=document.createElement(`link`);if(o.rel=r?`stylesheet`:zW,r||(o.as=`script`),o.crossOrigin=``,o.href=t,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),r)return new Promise((e,n)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},UW=e=>e.replace(/\\"/g,`"`),WW=({mermaid:e,className:t,onClick:n})=>{let{t:r}=q(`common`),[i,a]=(0,p.useState)({kind:`loading`}),o=`mermaid-${(0,p.useId)().replace(/:/g,``)}`;(0,p.useEffect)(()=>{let t=!1;if(a({kind:`loading`}),!e){a({kind:`error`,rawText:``});return}return(async()=>{try{let n=await HW(()=>import(`./mermaid.core-DXBRp0XG.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]));if(t)return;let r=n.default;r.initialize({startOnLoad:!1,theme:`dark`,themeVariables:{primaryColor:`#8b5cf6`,primaryTextColor:`#e2e8f0`,lineColor:`#94a3b8`,secondaryColor:`#1e293b`,tertiaryColor:`#334155`}});let i=UW(e);if(await r.parse(i),t)return;let{svg:s}=await r.render(o,i);if(t)return;a({kind:`rendered`,svg:s})}catch{t||a({kind:`error`,rawText:e})}})(),()=>{t=!0}},[e,o]);let s=(0,p.useCallback)(()=>{i.kind===`rendered`&&n&&n()},[i,n]);return i.kind===`loading`?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-8 ${t??``}`,children:(0,X.jsx)(`div`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-violet-400 border-t-transparent`})}):i.kind===`error`?i.rawText?(0,X.jsxs)(`div`,{className:t,children:[(0,X.jsx)(`div`,{className:`mb-2 text-xs text-amber-400`,children:r(`specView.artifactPanel.mermaidParseError`)}),(0,X.jsx)(`pre`,{className:`overflow-auto rounded-md border border-border/50 bg-surface p-3 text-xs text-muted-foreground whitespace-pre-wrap`,children:i.rawText})]}):(0,X.jsx)(`div`,{className:`py-4 text-sm text-muted-foreground ${t??``}`,children:r(`specView.artifactPanel.noDiagram`)}):(0,X.jsx)(`div`,{className:`spec-mermaid-diagram flex justify-center ${n?`cursor-zoom-in`:``} ${t??``}`,dangerouslySetInnerHTML:{__html:i.svg},onClick:s,role:n?`button`:void 0,tabIndex:n?0:void 0,onKeyDown:n?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),s())}:void 0,"aria-label":n?r(`mermaidPreviewDialog.clickToExpand`):void 0})},GW=({className:e})=>(0,X.jsx)(kg,{"aria-hidden":`true`,className:e}),KW=24,qW=4,JW=1.25,YW=1,XW={width:800,height:600},ZW=e=>e.replace(/\\"/g,`"`),QW=e=>Number.isFinite(e)&&e>0,$W=e=>{if(!e||e.trim().endsWith(`%`))return null;let t=Number.parseFloat(e);return QW(t)?t:null},eG=e=>{let t=e.getAttribute(`viewBox`)?.trim().split(/[\s,]+/).map(Number);if(t?.length===4&&QW(t[2])&&QW(t[3]))return{width:t[2],height:t[3]};let n=$W(e.getAttribute(`width`)),r=$W(e.getAttribute(`height`));if(n&&r)return{width:n,height:r};let i=e.getBoundingClientRect();if(QW(i.width)&&QW(i.height))return{width:i.width,height:i.height};try{let t=e.getBBox();if(QW(t.width)&&QW(t.height))return{width:t.width,height:t.height}}catch{}return XW},tG=(e,t)=>{let n=Math.max(YW,t.width-KW*2),r=Math.max(YW,t.height-KW*2),i=Math.min(1,n/e.width,r/e.height);return QW(i)?i:1},nG=(e,t,n)=>{let r=e.width*n,i=e.height*n,a=Math.max(t.width,r+KW*2),o=Math.max(t.height,i+KW*2);return{width:a,height:o,diagramWidth:r,diagramHeight:i,diagramLeft:Math.max(KW,(a-r)/2),diagramTop:Math.max(KW,(o-i)/2)}},rG=(e,t,n)=>Math.min(n,Math.max(t,e)),iG=(0,p.memo)(({svg:e,stageRef:t})=>(0,X.jsx)(`div`,{ref:t,"data-testid":`mermaid-preview-stage`,className:`relative shrink-0`,dangerouslySetInnerHTML:{__html:e}})),aG=({mermaid:e,open:t,onClose:n})=>{let{t:r}=q(`common`),[i,a]=(0,p.useState)({kind:`loading`}),[o,s]=(0,p.useState)(null),[c,l]=(0,p.useState)(null),u=(0,p.useRef)(null),d=(0,p.useRef)(null),f=(0,p.useRef)(null),m=(0,p.useRef)(null),h=(0,p.useRef)(null),g=(0,p.useRef)(null),_=(0,p.useRef)(null),v=`mermaid-preview-${(0,p.useId)().replace(/:/g,``)}`,y=(0,p.useCallback)((e,t=!0)=>{let n=u.current,r=_.current;!r||e!==void 0&&r.pointerId!==e||(t&&n?.hasPointerCapture?.(r.pointerId)&&n.releasePointerCapture(r.pointerId),document.body.style.userSelect=r.previousUserSelect,n?.removeAttribute(`data-dragging`),_.current=null)},[]),b=(0,p.useCallback)((e,t=null)=>{let n=u.current,r=d.current,i=r?.querySelector(`svg`),a=f.current,o=m.current,c=g.current;if(!n||!r||!i||!a||!o||c===null)return;let p=rG(e,c,qW),_=nG(a,o,p);r.style.width=`${_.width}px`,r.style.height=`${_.height}px`,r.dataset.diagramWidth=`${_.diagramWidth}`,r.dataset.diagramHeight=`${_.diagramHeight}`,i.setAttribute(`width`,`${_.diagramWidth}`),i.setAttribute(`height`,`${_.diagramHeight}`),i.style.width=`${_.diagramWidth}px`,i.style.height=`${_.diagramHeight}px`,i.style.maxWidth=`none`,i.style.maxHeight=`none`,i.style.position=`absolute`,i.style.left=`${_.diagramLeft}px`,i.style.top=`${_.diagramTop}px`;let v=Math.max(0,_.width-o.width),y=Math.max(0,_.height-o.height),b=t?_.diagramLeft+t.x*p-o.width/2:v/2,x=t?_.diagramTop+t.y*p-o.height/2:y/2;n.scrollLeft=rG(b,0,v),n.scrollTop=rG(x,0,y),h.current=p,s(p),l(c)},[]),x=(0,p.useCallback)(()=>{let e=u.current,t=f.current,n=m.current,r=h.current;if(!e||!t||!n||r===null)return null;let i=nG(t,n,r);return{x:(e.scrollLeft+n.width/2-i.diagramLeft)/r,y:(e.scrollTop+n.height/2-i.diagramTop)/r}},[]),S=(0,p.useCallback)(()=>{let e=f.current,t=m.current;if(!e||!t)return;let n=tG(e,t);g.current=n,b(n)},[b]),C=e=>{let t=h.current;t!==null&&b(t*e,x())};(0,p.useEffect)(()=>{if(!t)return;let n=!1;return a({kind:`loading`}),(async()=>{try{let t=await HW(()=>import(`./mermaid.core-DXBRp0XG.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]));if(n)return;let r=t.default;r.initialize({startOnLoad:!1,theme:`dark`,themeVariables:{primaryColor:`#8b5cf6`,primaryTextColor:`#e2e8f0`,lineColor:`#94a3b8`,secondaryColor:`#1e293b`,tertiaryColor:`#334155`}});let i=ZW(e);if(await r.parse(i),n)return;let{svg:o}=await r.render(v,i);if(n)return;a({kind:`rendered`,svg:o})}catch{n||a({kind:`error`,rawText:e})}})(),()=>{n=!0}},[e,v,t]),(0,p.useLayoutEffect)(()=>{if(!t||i.kind!==`rendered`)return;let e=d.current?.querySelector(`svg`);if(!e)return;let n=eG(e);return f.current=n,e.dataset.intrinsicWidth=`${n.width}`,e.dataset.intrinsicHeight=`${n.height}`,m.current&&S(),()=>{y(),f.current=null,h.current=null,g.current=null,s(null),l(null)}},[y,t,S,i]),(0,p.useLayoutEffect)(()=>{if(!t||i.kind!==`rendered`)return;let e=u.current;if(!e)return;let n=()=>{let t=e.clientWidth,n=e.clientHeight;if(!QW(t)||!QW(n))return;let r=m.current,i=f.current,a=h.current,o=g.current,s=r&&i&&a!==null?x():null,c={width:t,height:n};if(m.current=c,!i)return;let l=tG(i,c);g.current=l;let u=a===null||o===null||Math.abs(a-o)<1e-4;b(u?l:a,u?null:s)},r=new ResizeObserver(n);return r.observe(e),n(),()=>{r.disconnect(),m.current=null}},[b,x,t,i.kind]),(0,p.useEffect)(()=>()=>{y()},[y]);let w=e=>{if(e.pointerType!==`mouse`||e.button!==0||o===null)return;let t=e.currentTarget;y(),_.current={pointerId:e.pointerId,clientX:e.clientX,clientY:e.clientY,scrollLeft:t.scrollLeft,scrollTop:t.scrollTop,previousUserSelect:document.body.style.userSelect},document.body.style.userSelect=`none`,t.dataset.dragging=`true`,t.setPointerCapture(e.pointerId),e.preventDefault()},T=e=>{let t=_.current,n=f.current,r=m.current,i=h.current;if(!t||t.pointerId!==e.pointerId||!n||!r||i===null)return;let a=nG(n,r,i);e.currentTarget.scrollLeft=rG(t.scrollLeft-(e.clientX-t.clientX),0,Math.max(0,a.width-r.width)),e.currentTarget.scrollTop=rG(t.scrollTop-(e.clientY-t.clientY),0,Math.max(0,a.height-r.height)),e.preventDefault()},E=e=>{y(e.pointerId)},D=e=>{y(e.pointerId,!1)},O=o===null?0:Math.round(o*100);return(0,X.jsx)(V_,{open:t,onOpenChange:e=>{e||n()},children:(0,X.jsxs)(U_,{showCloseButton:!1,overlayClassName:`bg-black/80`,className:`flex h-[calc(100vh-1rem)] max-h-[calc(100vh-1rem)] w-[calc(100vw-1rem)] max-w-[calc(100vw-1rem)] sm:max-w-[calc(100vw-1rem)] flex-col gap-0 overflow-hidden border-border/80 bg-background/95 p-0 shadow-2xl`,children:[(0,X.jsx)(K_,{className:`sr-only`,children:r(`mermaidPreviewDialog.title`)}),(0,X.jsx)(q_,{className:`sr-only`,children:r(`mermaidPreviewDialog.description`)}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-4 border-b border-border/70 px-4 py-2.5 sm:px-5`,children:[(0,X.jsx)(`p`,{className:`min-w-0 truncate text-sm font-semibold text-foreground sm:text-base`,children:r(`mermaidPreviewDialog.title`)}),(0,X.jsxs)(`nav`,{className:`flex shrink-0 items-center gap-1`,"aria-label":r(`mermaidPreviewDialog.controlsAriaLabel`),children:[o!==null&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Q,{type:`button`,"aria-label":r(`mermaidPreviewDialog.zoomOutAriaLabel`),variant:`ghost`,size:`icon-sm`,disabled:c!==null&&o<=c+1e-4,onClick:()=>C(1/JW),children:(0,X.jsx)(GW,{className:`h-4 w-4`})}),(0,X.jsx)(`span`,{className:`w-12 text-center text-xs tabular-nums text-muted-foreground`,"aria-live":`polite`,"aria-label":r(`mermaidPreviewDialog.zoomLevelAriaLabel`,{zoom:O}),children:r(`mermaidPreviewDialog.zoomLevel`,{zoom:O})}),(0,X.jsx)(Q,{type:`button`,"aria-label":r(`mermaidPreviewDialog.zoomInAriaLabel`),variant:`ghost`,size:`icon-sm`,disabled:o>=qW-1e-4,onClick:()=>C(JW),children:(0,X.jsx)(xv,{className:`h-4 w-4`})}),(0,X.jsx)(Q,{type:`button`,"aria-label":r(`mermaidPreviewDialog.resetViewAriaLabel`),variant:`ghost`,size:`icon-sm`,onClick:S,children:(0,X.jsx)(ix,{className:`h-4 w-4`})})]}),(0,X.jsx)(H_,{asChild:!0,children:(0,X.jsx)(Q,{type:`button`,"aria-label":r(`mermaidPreviewDialog.closeAriaLabel`),variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-foreground`,children:(0,X.jsx)(ax,{className:`h-4 w-4`})})})]})]}),(0,X.jsxs)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center bg-black/35 p-2 sm:p-3`,children:[i.kind===`loading`&&(0,X.jsx)(`div`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-violet-400 border-t-transparent`}),i.kind===`error`&&(0,X.jsx)(`pre`,{className:`max-h-full max-w-full overflow-auto rounded-md border border-border/50 bg-surface p-4 text-xs text-muted-foreground whitespace-pre-wrap`,children:i.rawText}),i.kind===`rendered`&&(0,X.jsx)(`div`,{ref:u,"data-testid":`mermaid-preview-viewport`,"aria-label":r(`mermaidPreviewDialog.canvasAriaLabel`),className:`h-full w-full cursor-grab overflow-auto data-[dragging=true]:cursor-grabbing`,onPointerDown:w,onPointerMove:T,onPointerUp:E,onPointerCancel:E,onLostPointerCapture:D,children:(0,X.jsx)(iG,{svg:i.svg,stageRef:d})})]})]})})},oG=`*, *::before, *::after { box-sizing: border-box; }
147
+ `).map(e=>e.trim()).filter(e=>e.length>0):[],zW=`modulepreload`,BW=function(e){return`/`+e},VW={},HW=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}r=o(t.map(t=>{if(t=BW(t,n),t in VW)return;VW[t]=!0;let r=t.endsWith(`.css`),i=r?`[rel="stylesheet"]`:``;if(n)for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${t}"]${i}`))return;let o=document.createElement(`link`);if(o.rel=r?`stylesheet`:zW,r||(o.as=`script`),o.crossOrigin=``,o.href=t,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),r)return new Promise((e,n)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},UW=e=>e.replace(/\\"/g,`"`),WW=({mermaid:e,className:t,onClick:n})=>{let{t:r}=q(`common`),[i,a]=(0,p.useState)({kind:`loading`}),o=`mermaid-${(0,p.useId)().replace(/:/g,``)}`;(0,p.useEffect)(()=>{let t=!1;if(a({kind:`loading`}),!e){a({kind:`error`,rawText:``});return}return(async()=>{try{let n=await HW(()=>import(`./mermaid.core-s9FJYhni.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]));if(t)return;let r=n.default;r.initialize({startOnLoad:!1,theme:`dark`,themeVariables:{primaryColor:`#8b5cf6`,primaryTextColor:`#e2e8f0`,lineColor:`#94a3b8`,secondaryColor:`#1e293b`,tertiaryColor:`#334155`}});let i=UW(e);if(await r.parse(i),t)return;let{svg:s}=await r.render(o,i);if(t)return;a({kind:`rendered`,svg:s})}catch{t||a({kind:`error`,rawText:e})}})(),()=>{t=!0}},[e,o]);let s=(0,p.useCallback)(()=>{i.kind===`rendered`&&n&&n()},[i,n]);return i.kind===`loading`?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-8 ${t??``}`,children:(0,X.jsx)(`div`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-violet-400 border-t-transparent`})}):i.kind===`error`?i.rawText?(0,X.jsxs)(`div`,{className:t,children:[(0,X.jsx)(`div`,{className:`mb-2 text-xs text-amber-400`,children:r(`specView.artifactPanel.mermaidParseError`)}),(0,X.jsx)(`pre`,{className:`overflow-auto rounded-md border border-border/50 bg-surface p-3 text-xs text-muted-foreground whitespace-pre-wrap`,children:i.rawText})]}):(0,X.jsx)(`div`,{className:`py-4 text-sm text-muted-foreground ${t??``}`,children:r(`specView.artifactPanel.noDiagram`)}):(0,X.jsx)(`div`,{className:`spec-mermaid-diagram flex justify-center ${n?`cursor-zoom-in`:``} ${t??``}`,dangerouslySetInnerHTML:{__html:i.svg},onClick:s,role:n?`button`:void 0,tabIndex:n?0:void 0,onKeyDown:n?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),s())}:void 0,"aria-label":n?r(`mermaidPreviewDialog.clickToExpand`):void 0})},GW=({className:e})=>(0,X.jsx)(kg,{"aria-hidden":`true`,className:e}),KW=24,qW=4,JW=1.25,YW=1,XW={width:800,height:600},ZW=e=>e.replace(/\\"/g,`"`),QW=e=>Number.isFinite(e)&&e>0,$W=e=>{if(!e||e.trim().endsWith(`%`))return null;let t=Number.parseFloat(e);return QW(t)?t:null},eG=e=>{let t=e.getAttribute(`viewBox`)?.trim().split(/[\s,]+/).map(Number);if(t?.length===4&&QW(t[2])&&QW(t[3]))return{width:t[2],height:t[3]};let n=$W(e.getAttribute(`width`)),r=$W(e.getAttribute(`height`));if(n&&r)return{width:n,height:r};let i=e.getBoundingClientRect();if(QW(i.width)&&QW(i.height))return{width:i.width,height:i.height};try{let t=e.getBBox();if(QW(t.width)&&QW(t.height))return{width:t.width,height:t.height}}catch{}return XW},tG=(e,t)=>{let n=Math.max(YW,t.width-KW*2),r=Math.max(YW,t.height-KW*2),i=Math.min(1,n/e.width,r/e.height);return QW(i)?i:1},nG=(e,t,n)=>{let r=e.width*n,i=e.height*n,a=Math.max(t.width,r+KW*2),o=Math.max(t.height,i+KW*2);return{width:a,height:o,diagramWidth:r,diagramHeight:i,diagramLeft:Math.max(KW,(a-r)/2),diagramTop:Math.max(KW,(o-i)/2)}},rG=(e,t,n)=>Math.min(n,Math.max(t,e)),iG=(0,p.memo)(({svg:e,stageRef:t})=>(0,X.jsx)(`div`,{ref:t,"data-testid":`mermaid-preview-stage`,className:`relative shrink-0`,dangerouslySetInnerHTML:{__html:e}})),aG=({mermaid:e,open:t,onClose:n})=>{let{t:r}=q(`common`),[i,a]=(0,p.useState)({kind:`loading`}),[o,s]=(0,p.useState)(null),[c,l]=(0,p.useState)(null),u=(0,p.useRef)(null),d=(0,p.useRef)(null),f=(0,p.useRef)(null),m=(0,p.useRef)(null),h=(0,p.useRef)(null),g=(0,p.useRef)(null),_=(0,p.useRef)(null),v=`mermaid-preview-${(0,p.useId)().replace(/:/g,``)}`,y=(0,p.useCallback)((e,t=!0)=>{let n=u.current,r=_.current;!r||e!==void 0&&r.pointerId!==e||(t&&n?.hasPointerCapture?.(r.pointerId)&&n.releasePointerCapture(r.pointerId),document.body.style.userSelect=r.previousUserSelect,n?.removeAttribute(`data-dragging`),_.current=null)},[]),b=(0,p.useCallback)((e,t=null)=>{let n=u.current,r=d.current,i=r?.querySelector(`svg`),a=f.current,o=m.current,c=g.current;if(!n||!r||!i||!a||!o||c===null)return;let p=rG(e,c,qW),_=nG(a,o,p);r.style.width=`${_.width}px`,r.style.height=`${_.height}px`,r.dataset.diagramWidth=`${_.diagramWidth}`,r.dataset.diagramHeight=`${_.diagramHeight}`,i.setAttribute(`width`,`${_.diagramWidth}`),i.setAttribute(`height`,`${_.diagramHeight}`),i.style.width=`${_.diagramWidth}px`,i.style.height=`${_.diagramHeight}px`,i.style.maxWidth=`none`,i.style.maxHeight=`none`,i.style.position=`absolute`,i.style.left=`${_.diagramLeft}px`,i.style.top=`${_.diagramTop}px`;let v=Math.max(0,_.width-o.width),y=Math.max(0,_.height-o.height),b=t?_.diagramLeft+t.x*p-o.width/2:v/2,x=t?_.diagramTop+t.y*p-o.height/2:y/2;n.scrollLeft=rG(b,0,v),n.scrollTop=rG(x,0,y),h.current=p,s(p),l(c)},[]),x=(0,p.useCallback)(()=>{let e=u.current,t=f.current,n=m.current,r=h.current;if(!e||!t||!n||r===null)return null;let i=nG(t,n,r);return{x:(e.scrollLeft+n.width/2-i.diagramLeft)/r,y:(e.scrollTop+n.height/2-i.diagramTop)/r}},[]),S=(0,p.useCallback)(()=>{let e=f.current,t=m.current;if(!e||!t)return;let n=tG(e,t);g.current=n,b(n)},[b]),C=e=>{let t=h.current;t!==null&&b(t*e,x())};(0,p.useEffect)(()=>{if(!t)return;let n=!1;return a({kind:`loading`}),(async()=>{try{let t=await HW(()=>import(`./mermaid.core-s9FJYhni.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]));if(n)return;let r=t.default;r.initialize({startOnLoad:!1,theme:`dark`,themeVariables:{primaryColor:`#8b5cf6`,primaryTextColor:`#e2e8f0`,lineColor:`#94a3b8`,secondaryColor:`#1e293b`,tertiaryColor:`#334155`}});let i=ZW(e);if(await r.parse(i),n)return;let{svg:o}=await r.render(v,i);if(n)return;a({kind:`rendered`,svg:o})}catch{n||a({kind:`error`,rawText:e})}})(),()=>{n=!0}},[e,v,t]),(0,p.useLayoutEffect)(()=>{if(!t||i.kind!==`rendered`)return;let e=d.current?.querySelector(`svg`);if(!e)return;let n=eG(e);return f.current=n,e.dataset.intrinsicWidth=`${n.width}`,e.dataset.intrinsicHeight=`${n.height}`,m.current&&S(),()=>{y(),f.current=null,h.current=null,g.current=null,s(null),l(null)}},[y,t,S,i]),(0,p.useLayoutEffect)(()=>{if(!t||i.kind!==`rendered`)return;let e=u.current;if(!e)return;let n=()=>{let t=e.clientWidth,n=e.clientHeight;if(!QW(t)||!QW(n))return;let r=m.current,i=f.current,a=h.current,o=g.current,s=r&&i&&a!==null?x():null,c={width:t,height:n};if(m.current=c,!i)return;let l=tG(i,c);g.current=l;let u=a===null||o===null||Math.abs(a-o)<1e-4;b(u?l:a,u?null:s)},r=new ResizeObserver(n);return r.observe(e),n(),()=>{r.disconnect(),m.current=null}},[b,x,t,i.kind]),(0,p.useEffect)(()=>()=>{y()},[y]);let w=e=>{if(e.pointerType!==`mouse`||e.button!==0||o===null)return;let t=e.currentTarget;y(),_.current={pointerId:e.pointerId,clientX:e.clientX,clientY:e.clientY,scrollLeft:t.scrollLeft,scrollTop:t.scrollTop,previousUserSelect:document.body.style.userSelect},document.body.style.userSelect=`none`,t.dataset.dragging=`true`,t.setPointerCapture(e.pointerId),e.preventDefault()},T=e=>{let t=_.current,n=f.current,r=m.current,i=h.current;if(!t||t.pointerId!==e.pointerId||!n||!r||i===null)return;let a=nG(n,r,i);e.currentTarget.scrollLeft=rG(t.scrollLeft-(e.clientX-t.clientX),0,Math.max(0,a.width-r.width)),e.currentTarget.scrollTop=rG(t.scrollTop-(e.clientY-t.clientY),0,Math.max(0,a.height-r.height)),e.preventDefault()},E=e=>{y(e.pointerId)},D=e=>{y(e.pointerId,!1)},O=o===null?0:Math.round(o*100);return(0,X.jsx)(V_,{open:t,onOpenChange:e=>{e||n()},children:(0,X.jsxs)(U_,{showCloseButton:!1,overlayClassName:`bg-black/80`,className:`flex h-[calc(100vh-1rem)] max-h-[calc(100vh-1rem)] w-[calc(100vw-1rem)] max-w-[calc(100vw-1rem)] sm:max-w-[calc(100vw-1rem)] flex-col gap-0 overflow-hidden border-border/80 bg-background/95 p-0 shadow-2xl`,children:[(0,X.jsx)(K_,{className:`sr-only`,children:r(`mermaidPreviewDialog.title`)}),(0,X.jsx)(q_,{className:`sr-only`,children:r(`mermaidPreviewDialog.description`)}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-4 border-b border-border/70 px-4 py-2.5 sm:px-5`,children:[(0,X.jsx)(`p`,{className:`min-w-0 truncate text-sm font-semibold text-foreground sm:text-base`,children:r(`mermaidPreviewDialog.title`)}),(0,X.jsxs)(`nav`,{className:`flex shrink-0 items-center gap-1`,"aria-label":r(`mermaidPreviewDialog.controlsAriaLabel`),children:[o!==null&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Q,{type:`button`,"aria-label":r(`mermaidPreviewDialog.zoomOutAriaLabel`),variant:`ghost`,size:`icon-sm`,disabled:c!==null&&o<=c+1e-4,onClick:()=>C(1/JW),children:(0,X.jsx)(GW,{className:`h-4 w-4`})}),(0,X.jsx)(`span`,{className:`w-12 text-center text-xs tabular-nums text-muted-foreground`,"aria-live":`polite`,"aria-label":r(`mermaidPreviewDialog.zoomLevelAriaLabel`,{zoom:O}),children:r(`mermaidPreviewDialog.zoomLevel`,{zoom:O})}),(0,X.jsx)(Q,{type:`button`,"aria-label":r(`mermaidPreviewDialog.zoomInAriaLabel`),variant:`ghost`,size:`icon-sm`,disabled:o>=qW-1e-4,onClick:()=>C(JW),children:(0,X.jsx)(xv,{className:`h-4 w-4`})}),(0,X.jsx)(Q,{type:`button`,"aria-label":r(`mermaidPreviewDialog.resetViewAriaLabel`),variant:`ghost`,size:`icon-sm`,onClick:S,children:(0,X.jsx)(ix,{className:`h-4 w-4`})})]}),(0,X.jsx)(H_,{asChild:!0,children:(0,X.jsx)(Q,{type:`button`,"aria-label":r(`mermaidPreviewDialog.closeAriaLabel`),variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-foreground`,children:(0,X.jsx)(ax,{className:`h-4 w-4`})})})]})]}),(0,X.jsxs)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center bg-black/35 p-2 sm:p-3`,children:[i.kind===`loading`&&(0,X.jsx)(`div`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-violet-400 border-t-transparent`}),i.kind===`error`&&(0,X.jsx)(`pre`,{className:`max-h-full max-w-full overflow-auto rounded-md border border-border/50 bg-surface p-4 text-xs text-muted-foreground whitespace-pre-wrap`,children:i.rawText}),i.kind===`rendered`&&(0,X.jsx)(`div`,{ref:u,"data-testid":`mermaid-preview-viewport`,"aria-label":r(`mermaidPreviewDialog.canvasAriaLabel`),className:`h-full w-full cursor-grab overflow-auto data-[dragging=true]:cursor-grabbing`,onPointerDown:w,onPointerMove:T,onPointerUp:E,onPointerCancel:E,onLostPointerCapture:D,children:(0,X.jsx)(iG,{svg:i.svg,stageRef:d})})]})]})})},oG=`*, *::before, *::after { box-sizing: border-box; }
148
148
  html, body {
149
149
  margin: 0;
150
150
  padding: 16px;
@@ -272,5 +272,5 @@ ${s.join(`
272
272
  `),r=Math.max(0,t-4),i=Math.min(n.length,t+3);return n.slice(r,i).map((e,t)=>`${r+t+1}: ${e}`).join(`
273
273
  `)},Npe=e=>e?.status?[qb.t(`common:chatChangesPanel.fileStatus.${e.status}`),e.staged&&qb.t(`common:chatChangesPanel.fileStatus.staged`),e.unstaged&&qb.t(`common:chatChangesPanel.fileStatus.unstaged`),e.conflicted&&qb.t(`common:chatChangesPanel.fileStatus.conflicted`)].filter(Boolean).join(`, `):B6(`tracked`),Ppe=({file:e,viewMode:t,comments:n,canComment:r,searchMatches:i,activeSearchMatchIndex:a,onAddComment:o})=>(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:Z(`flex min-h-0 flex-1 flex-col`,t===`preview`&&`hidden`),children:(0,X.jsx)(_pe,{file:e,comments:n,canComment:r,isActive:t===`source`,searchMatches:i,activeSearchMatchIndex:a,onAddComment:o})}),t===`preview`&&(0,X.jsx)(gpe,{content:e.content})]}),Fpe=({projectId:e,target:t,isActive:n,canAddComments:r,comments:i,onCommentsChange:a,requestedPath:o=null,onRequestedPathHandled:s,onViewChanges:c,headerControls:l})=>{let[u,d]=(0,p.useState)(null),[f,m]=(0,p.useState)(null),[h,g]=(0,p.useState)(!1),[_,v]=(0,p.useState)(``),y=(0,p.useDeferredValue)(_),[b,x]=(0,p.useState)(!1),[S,C]=(0,p.useState)(new Set),[w,T]=(0,p.useState)(null),[E,D]=(0,p.useState)(`source`),[O,k]=(0,p.useState)({kind:`empty`}),[A,j]=(0,p.useState)(!1),[M,N]=(0,p.useState)(``),[P,F]=(0,p.useState)(-1),I=(0,p.useRef)(new Map),L=(0,p.useRef)(null),R=(0,p.useRef)(null),z=(0,p.useRef)(o),ee=(0,p.useRef)(i),B=(0,p.useRef)(null),V=(0,p.useRef)(null),H=(0,p.useRef)(null),U=(0,p.useRef)(0),W=(0,p.useRef)(0),te=(0,p.useRef)(0),ne=(0,p.useRef)(null),re=(0,p.useRef)(null),ie=(0,p.useRef)(!1),ae=(0,p.useMemo)(()=>{if(!u)return[];let e=y.trim().toLocaleLowerCase();return u.entries.filter(t=>{let n=!e||t.path.toLocaleLowerCase().includes(e),r=!b||t.status!==null;return n&&r})},[u,y,b]);L.current=u,R.current=w,z.current=o,ee.current=i;let G=(0,p.useCallback)(e=>{ee.current=e,a(e)},[a]),oe=(0,p.useCallback)(()=>{j(!1),N(``),F(-1)},[]),se=e?R6(e,t):null;(0,p.useEffect)(()=>{if(!e||!se||B.current===se||(B.current=se,ee.current.length>0))return;let n=kpe(localStorage.getItem(se),t);n.length>0&&(G(n),z6(e,n).then(e=>{let t=new Map(e.map(e=>[e.id,e.stale])),n=ee.current,r=n.map(e=>{let n=t.get(e.id);return n===void 0?e:{...e,stale:n}});r.some((e,t)=>e.stale!==n[t]?.stale)&&G(r)}))},[G,e,se,t]),(0,p.useEffect)(()=>{if(se){if(i.length===0){localStorage.removeItem(se);return}localStorage.setItem(se,JSON.stringify(i))}},[i,se]);let ce=(0,p.useCallback)(async(n,r=!1)=>{if(!e)return;V.current?.abort(),W.current+=1;let i=W.current;if((L.current?.entries.find(e=>e.path===n)??null)?.status===`deleted`){k({kind:`unsupported`,path:n,reason:`deleted`,message:V6(`deleted`)});return}let a=I.current.get(n);if(a&&!r){k({kind:`content`,content:a});return}let o=new AbortController;V.current=o,k({kind:`loading`,path:n});try{let a=await D6(e,t,n,o.signal,r);if(i!==W.current)return;for(I.current.delete(n),I.current.set(n,a);I.current.size>Ape;){let e=I.current.keys().next().value;if(typeof e!=`string`)break;I.current.delete(e)}k({kind:`content`,content:a});let s=ee.current,c=s.map(e=>e.filePath===n?{...e,stale:e.contentSignature!==a.content_signature}:e);c.some((e,t)=>e.stale!==s[t]?.stale)&&G(c)}catch(e){if(i!==W.current||Ye(e))return;if(e instanceof Ge){let t=jpe(e);if(t){k({kind:`unsupported`,path:n,reason:t.reason,message:V6(t.reason)});return}}k({kind:`error`,path:n,message:e instanceof Error?e.message:B6(`contentError`)})}},[G,e,t]),le=(0,p.useCallback)(e=>{oe(),R.current=e,T(e),D(H6(e)?`preview`:`source`),ce(e)},[ce,oe]),ue=(0,p.useCallback)(async(n=!1)=>{if(!e){m(B6(`noProject`));return}let r=new AbortController;H.current?.abort(),H.current=r,U.current+=1;let i=U.current;g(!0),m(null);try{let a=await ope(e,t,r.signal,n);if(i!==U.current)return;let o=L.current?.workspace_signature,s=o!==void 0&&o!==a.workspace_signature;L.current=a,d(a),s&&I.current.clear();let c=R.current;if(!c){let e=a.entries.filter(e=>e.status!==`deleted`);!z.current&&e.length===1&&le(e[0].path);return}if(!a.entries.some(e=>e.path===c)){V.current?.abort(),W.current+=1,R.current=null,T(null),D(`source`),k({kind:`empty`}),oe();return}(s||n)&&(I.current.delete(c),ce(c,!0))}catch(e){i===U.current&&!Ye(e)&&m(e instanceof Error?e.message:B6(`manifestError`))}finally{i===U.current&&g(!1)}},[ce,e,oe,le,t]);(0,p.useEffect)(()=>{if(!n){H.current?.abort(),V.current?.abort(),U.current+=1,W.current+=1;return}ue(),ne.current?.focus()},[n,ue]),(0,p.useEffect)(()=>()=>{H.current?.abort(),V.current?.abort(),U.current+=1,W.current+=1},[]),(0,p.useEffect)(()=>{if(!o||!u)return;let e=u.entries.find(e=>e.path===o);if(!e||e.status===`deleted`){s?.(o);return}let t=o.split(`/`);C(e=>{let n=new Set(e);for(let e=1;e<t.length;e+=1)n.add(t.slice(0,e).join(`/`));return n}),le(o),s?.(o)},[u,s,o,le]),(0,p.useEffect)(()=>{ae.length===1&&w===null&&le(ae[0].path)},[ae,w,le]),(0,p.useEffect)(()=>{n&&!ie.current&&!o&&ne.current?.focus(),ie.current=n},[n,o]);let de=u?.entries.find(e=>e.path===w)??null,fe=H6(w)&&O.kind===`content`&&O.content.path===w,pe=fe&&O.content.content.length>1e5,me=pe?`source`:E,he=(0,p.useMemo)(()=>{if(!A||O.kind!==`content`||M.length===0||/[\r\n]/.test(M))return[];let e=M.toLocaleLowerCase(),t=[];return O.content.content.split(`
274
274
  `).forEach((n,r)=>{let i=n.toLocaleLowerCase(),a=i.indexOf(e);for(;a!==-1;)t.push({lineIndex:r,start:a,end:a+M.length}),a=i.indexOf(e,a+M.length)}),t},[M,O,A]),ge=he.length>0?Math.min(Math.max(P,0),he.length-1):-1,_e=(0,p.useMemo)(()=>i.filter(e=>e.filePath===w),[i,w]),ve=(0,p.useMemo)(()=>{let e=new Map;return i.forEach(t=>e.set(t.filePath,(e.get(t.filePath)??0)+1)),e},[i]),ye=(0,p.useCallback)((e,n)=>{if(O.kind!==`content`)return;let r=O.content.content.split(`
275
- `);te.current+=1,G([...ee.current,{kind:`source`,id:`${O.content.path}:${e}:${Date.now()}:${te.current}`,target:t,filePath:O.content.path,lineNumber:e,lineContent:r[e-1]??``,sourceContext:Mpe(O.content.content,e),contentSignature:O.content.content_signature,comment:n,stale:!1}])},[G,O,t]);(0,p.useEffect)(()=>{pe&&D(`source`)},[pe]);let be=(0,p.useCallback)(()=>{O.kind===`content`&&(D(`source`),j(!0))},[O.kind]),xe=(0,p.useCallback)(e=>{he.length!==0&&F(t=>((t<0?0:Math.min(t,he.length-1))+e+he.length)%he.length)},[he.length]);return(0,p.useEffect)(()=>{A&&re.current?.focus({preventScroll:!0})},[A]),(0,p.useEffect)(()=>{let e=e=>{if(!(!n||O.kind!==`content`||e.defaultPrevented)){if((e.ctrlKey||e.metaKey)&&!e.altKey&&e.key.toLocaleLowerCase()===`f`){e.preventDefault(),be(),requestAnimationFrame(()=>re.current?.focus({preventScroll:!0}));return}A&&e.key===`Escape`&&(e.preventDefault(),oe())}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[O.kind,n,A,be,oe]),(0,X.jsxs)(`section`,{className:`flex min-h-0 flex-1 overflow-hidden rounded-xl border border-border`,"aria-label":`Files mode`,children:[(0,X.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col border-r border-border bg-muted/10`,"aria-label":B6(`fileBrowser`),children:[(0,X.jsxs)(`div`,{className:`space-y-3 border-b border-border p-3`,children:[(0,X.jsxs)(`label`,{className:`block text-xs text-muted-foreground`,children:[B6(`searchFiles`),(0,X.jsx)(J_,{ref:ne,type:`search`,className:`mt-1 h-8`,value:_,onChange:e=>v(e.target.value),placeholder:B6(`searchPlaceholder`)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked)}),B6(`changedOnly`)]}),(0,X.jsx)(vv,{content:B6(`refreshFiles`),children:(0,X.jsx)(Q,{type:`button`,size:`icon-xs`,variant:`ghost`,"aria-label":B6(`refreshFiles`),disabled:h,onClick:()=>{ue(!0)},children:h?(0,X.jsx)(Ov,{className:`size-3.5 animate-spin`}):(0,X.jsx)(ix,{className:`size-3.5`})})})]})]}),h&&!u&&(0,X.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:B6(`loadingManifest`)}),f&&(0,X.jsxs)(`div`,{className:`space-y-3 p-4 text-sm text-destructive`,children:[(0,X.jsx)(`p`,{children:f}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>void ue(),children:B6(`retry`)})]}),u&&(0,X.jsxs)(X.Fragment,{children:[u.truncated&&(0,X.jsx)(`div`,{className:`border-b border-border px-3 py-2 text-xs text-amber-300`,children:B6(`truncated`)}),(0,X.jsx)(Dpe,{entries:u.entries,search:y,changedOnly:b,expandedPaths:S,selectedPath:w,commentCounts:ve,onExpandedPathsChange:C,onSelectPath:le})]})]}),(0,X.jsxs)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,X.jsxs)(`header`,{"data-testid":`workspace-file-header`,className:`flex min-h-12 shrink-0 flex-wrap items-center justify-between gap-2 border-b border-border px-4 py-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`truncate font-mono text-xs text-foreground`,children:w??B6(`selectFile`)}),de&&(0,X.jsx)(`div`,{className:`mt-0.5 text-[11px] capitalize text-muted-foreground`,children:Npe(de)})]}),(O.kind===`content`||fe||l||w&&de?.status&&c)&&(0,X.jsxs)(`div`,{"data-testid":`workspace-file-header-actions`,className:`flex shrink-0 flex-wrap items-center justify-end gap-2 pr-10`,children:[fe&&(0,X.jsxs)(`div`,{className:`flex items-center rounded-lg border border-border bg-muted/20 p-0.5`,role:`group`,"aria-label":B6(`viewMode.ariaLabel`),children:[(0,X.jsx)(Q,{type:`button`,size:`xs`,variant:me===`preview`?`secondary`:`ghost`,"aria-pressed":me===`preview`,disabled:pe,onClick:()=>{D(`preview`)},children:B6(`viewMode.preview`)}),(0,X.jsx)(Q,{type:`button`,size:`xs`,variant:me===`source`?`secondary`:`ghost`,"aria-pressed":me===`source`,onClick:()=>{D(`source`)},children:B6(`viewMode.source`)})]}),pe&&(0,X.jsx)(`p`,{className:`text-xs text-amber-200`,role:`status`,children:B6(`viewMode.sourceRequiredLargeFile`)}),O.kind===`content`&&!A&&(0,X.jsx)(vv,{content:B6(`source.search.open`),children:(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":B6(`source.search.open`),onClick:be,children:(0,X.jsx)(ape,{className:`size-4`})})}),O.kind===`content`&&A&&(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1 rounded-lg border border-border bg-muted/20 p-1`,role:`search`,children:[(0,X.jsx)(J_,{ref:re,type:`search`,className:`h-7 w-40 rounded-md px-2 text-xs sm:w-56`,"aria-label":B6(`source.search.inputLabel`),placeholder:B6(`source.search.placeholder`),value:M,onChange:e=>{N(e.target.value),F(0)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),xe(e.shiftKey?-1:1))}}),(0,X.jsx)(`output`,{className:`min-w-12 whitespace-nowrap px-1 text-center text-[11px] text-muted-foreground`,"aria-live":`polite`,children:he.length>0?B6(`source.search.matchCount`,{current:ge+1,total:he.length}):B6(`source.search.noMatches`)}),(0,X.jsx)(Q,{type:`button`,size:`icon-xs`,variant:`ghost`,"aria-label":B6(`source.search.previous`),disabled:he.length===0,onClick:()=>xe(-1),children:(0,X.jsx)(bv,{className:`size-3.5 rotate-180`})}),(0,X.jsx)(Q,{type:`button`,size:`icon-xs`,variant:`ghost`,"aria-label":B6(`source.search.next`),disabled:he.length===0,onClick:()=>xe(1),children:(0,X.jsx)(bv,{className:`size-3.5`})}),(0,X.jsx)(Q,{type:`button`,size:`icon-xs`,variant:`ghost`,"aria-label":B6(`source.search.close`),onClick:oe,children:(0,X.jsx)(ax,{className:`size-3.5`})})]}),w&&de?.status&&c&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>c(w),children:B6(`viewChanges`)}),l]})]}),O.kind===`empty`&&(0,X.jsx)(`div`,{className:`m-auto max-w-sm text-center text-sm text-muted-foreground`,children:B6(`empty`)}),O.kind===`loading`&&(0,X.jsx)(`div`,{className:`m-auto text-sm text-muted-foreground`,children:B6(`loadingFile`,{path:O.path})}),O.kind===`unsupported`&&(0,X.jsxs)(`div`,{className:`m-auto max-w-md space-y-2 text-center`,children:[(0,X.jsx)(rC,{variant:`outline`,className:`capitalize`,children:O.reason.replace(/_/g,` `)}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:O.message})]}),O.kind===`error`&&(0,X.jsxs)(`div`,{className:`m-auto max-w-md space-y-3 text-center`,children:[(0,X.jsx)(`p`,{className:`text-sm text-destructive`,children:O.message}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>void ce(O.path,!0),children:B6(`retry`)})]}),O.kind===`content`&&(0,X.jsx)(Ppe,{file:O.content,viewMode:me,comments:_e,canComment:r,searchMatches:he,activeSearchMatchIndex:ge,onAddComment:ye})]})]})},U6=r({WorkspaceReviewModal:()=>G6}),W6=e=>qb.t(`common:workspaceReviewModal.${e}`),Ipe=({activeMode:e,availableModes:t,onModeChange:n})=>(0,X.jsx)(`div`,{role:`tablist`,"aria-label":W6(`modeAriaLabel`),className:`flex items-center gap-1 rounded-lg border border-border/80 bg-muted/30 p-1`,children:t.map(t=>(0,X.jsxs)(Q,{type:`button`,role:`tab`,size:`sm`,variant:e===t?`secondary`:`ghost`,"aria-selected":e===t,"aria-controls":`workspace-review-${t}-panel`,onClick:()=>n(t),children:[t===`files`?(0,X.jsx)(Tv,{className:`h-4 w-4`}):(0,X.jsx)(Ev,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:W6(t)})]},t))}),G6=({target:e,initialMode:t=`changes`,reviewMode:n,onReviewModeChange:r,enabledModes:i=[`changes`],filesView:a,fileTarget:o,bundleTargetName:s=null,onClose:c,title:l,mode:u,onModeChange:d,canToggleMode:f=!1,...m})=>{let[h,g]=(0,p.useState)(t),_=n??h,v=i.includes(_)?i:[_,...i],[y]=(0,p.useState)(e),[b,x]=(0,p.useState)(null),[S,C]=(0,p.useState)(null),[w,T]=(0,p.useState)([]),[E,D]=(0,p.useState)([]),O=(0,p.useRef)(E),[k,A]=(0,p.useState)(null);O.current=E;let j=(0,p.useCallback)(e=>{O.current=e,D(e)},[]),M=(0,p.useCallback)(()=>{O.current=[],D([])},[]),N=v.length>1,P=N&&a===void 0,[F]=(0,p.useState)(s),[I]=(0,p.useState)(()=>o??(y.scope===`project_root`?m.targetKind===`bundle`&&m.reviewCommentsBundleId?{kind:`bundle`,bundle_id:m.reviewCommentsBundleId,ticket_id:null}:{kind:`repo_root`,bundle_id:null,ticket_id:null}:m.reviewCommentsBundleId?{kind:`bundle`,bundle_id:m.reviewCommentsBundleId,ticket_id:null}:{kind:`ticket`,bundle_id:null,ticket_id:y.ticketId})),L=I.kind===`repo_root`?qb.t(`common:workspaceFiles.repositoryRoot`):I.kind===`bundle`?qb.t(`common:workspaceFiles.bundleTarget`,{name:F||I.bundle_id}):qb.t(`common:workspaceFiles.ticketTarget`,{id:I.ticket_id}),R=I.kind===`ticket`?l:L,z=(0,p.useCallback)(async()=>{if(!m.projectId||E.length===0)return E;let e=await z6(m.projectId,E),t=new Map(e.map(e=>[e.id,e.stale])),n=O.current.map(e=>{let n=t.get(e.id);return n===void 0?e:{...e,stale:n}});return j(n),n},[m.projectId,E,j]),ee=(0,p.useCallback)(()=>{m.projectId&&localStorage.removeItem(R6(m.projectId,I)),M()},[m.projectId,M,I]),B=(0,p.useCallback)(e=>{r?.(e),n===void 0&&g(e)},[r,n]),V=(0,p.useCallback)(e=>{x(e),B(`changes`)},[B]),H=(0,p.useCallback)(e=>{C(e),B(`files`)},[B]),U=(0,p.useCallback)(e=>{x(t=>t===e?null:t)},[]),W=(0,p.useCallback)(e=>{C(t=>t===e?null:t)},[]),te=(0,p.useCallback)(e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[u!==void 0&&d&&(0,X.jsx)(HY,{value:u,disabled:!f||m.isUpdatingMode,onChange:d,planInactiveTooltip:(0,X.jsx)(QY,{label:qb.t(`common:ticketChangesModal.switchToPlan`)}),buildInactiveTooltip:(0,X.jsx)(QY,{label:qb.t(`common:ticketChangesModal.switchToBuild`)})}),(0,X.jsx)(A3,{reviewComments:w,reviewFindings:e.reviewFindings,githubComments:e.githubComments,pendingFixCount:e.pendingFixCount,canSendReview:e.canSendReview,isSubmittingReview:e.isSubmittingReview,reviewSubmitDisabledReason:e.reviewSubmitDisabledReason,onClearPendingFixes:e.onClearPendingFixes,onSubmitReview:e.onSubmitReview,onUpdateReviewComment:e.onUpdateReviewComment,onRemoveReviewComment:e.onRemoveReviewComment})]}),[f,m.isUpdatingMode,u,d,w]),ne=(0,p.useCallback)(()=>k?te(k):null,[te,k]);return(0,p.useEffect)(()=>{if(!d||u===void 0)return;let e=e=>{!YY(e)||!f||(e.preventDefault(),d(JY(u)))};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}},[f,u,d]),(0,X.jsx)(X.Fragment,{children:(0,X.jsx)(tC,{onClose:c,overlayClassName:`z-[70] bg-black/30 p-[5vh]`,panelClassName:`flex h-[92vh] w-full max-w-none flex-col overflow-hidden rounded-2xl border border-border bg-card p-6 shadow-2xl`,closeButtonLabel:W6(`closeAriaLabel`),renderContent:({closeButton:e})=>{let t=N?(0,X.jsx)(Ipe,{activeMode:_,availableModes:v,onModeChange:B}):null,n=N?(0,X.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:t}):null,r=y.scope===`ticket`?(0,X.jsx)(T6,{...m,...y,projectId:m.projectId,title:l,onClose:c,mode:u,onModeChange:d,canToggleMode:f,headerControls:n,isActive:_===`changes`,onPendingReviewCommentsChange:T,onReviewControlsStateChange:A,renderReviewControls:te,showReviewControls:!N||_===`changes`,sourceReviewComments:E,onSourceReviewCommentsChange:j,onClearSourceReviewComments:M,onSourceReviewCommentsSubmitted:ee,onValidateSourceReviewComments:z,requestedDiffPath:b,onRequestedDiffPathHandled:U,onViewCurrentFile:P?H:void 0}):(0,X.jsx)(T6,{...m,scope:`project_root`,projectId:m.projectId,title:l,onClose:c,mode:u,onModeChange:d,canToggleMode:f,headerControls:n,isActive:_===`changes`,onPendingReviewCommentsChange:T,onReviewControlsStateChange:A,renderReviewControls:te,showReviewControls:!N||_===`changes`,sourceReviewComments:E,onSourceReviewCommentsChange:j,onClearSourceReviewComments:M,onSourceReviewCommentsSubmitted:ee,onValidateSourceReviewComments:z,requestedDiffPath:b,onRequestedDiffPathHandled:U,onViewCurrentFile:P?H:void 0}),i=N?(0,X.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-hidden`,children:[_===`files`&&(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-4`,children:[(0,X.jsx)(`h2`,{className:`min-w-0 flex-1 truncate text-lg font-semibold text-foreground`,children:R}),(0,X.jsx)(`div`,{"data-testid":`workspace-review-files-header-actions`,className:`flex min-w-0 max-w-full items-center gap-2 pr-10`,children:(0,X.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center justify-end gap-2`,children:t})})]}),(0,X.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[(0,X.jsx)(`div`,{id:`workspace-review-changes-panel`,role:`tabpanel`,hidden:_!==`changes`,className:`min-h-0 flex-1 flex-col overflow-hidden data-[active=true]:flex`,"data-active":_===`changes`,children:r}),(0,X.jsx)(`div`,{id:`workspace-review-files-panel`,role:`tabpanel`,hidden:_!==`files`,className:`min-h-0 flex-1 flex-col overflow-hidden data-[active=true]:flex`,"data-active":_===`files`,children:a??(0,X.jsx)(Fpe,{projectId:m.projectId,target:I,isActive:_===`files`,canAddComments:m.canAddReviewComments??!1,comments:E,onCommentsChange:j,requestedPath:S,onRequestedPathHandled:W,onViewChanges:V,headerControls:_===`files`&&k?ne():void 0})})]})]}):r;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`absolute right-4 top-4 z-10 mt-2`,children:e}),i]})}})})},Lpe=e=>!(e instanceof Ge)||e.status!==409||typeof e.data!=`object`||e.data===null?!1:`code`in e.data&&e.data.code===`build_open_questions_changed`,Rpe=e=>{let t=new Map((e.execution_order_ticket_ids??[]).map((e,t)=>[e,t]));return e.tickets.map(e=>({ticket:e,questions:(e.build_open_questions??[]).filter(e=>e.status===`open`).sort((e,t)=>e.created_at.localeCompare(t.created_at))})).filter(e=>e.questions.length>0).sort((e,n)=>(t.get(e.ticket.id)??e.ticket.bundle_execution_position??2**53-1)-(t.get(n.ticket.id)??n.ticket.bundle_execution_position??2**53-1))},zpe=e=>e.flatMap(e=>e.questions.map(e=>`${e.id}:${e.updated_at}`)).join(`|`),Bpe=({details:e,onClose:t,onRefresh:n,onSubmit:r})=>{let{t:i}=q(`common`),a=(0,p.useMemo)(()=>Rpe(e),[e]),o=(0,p.useMemo)(()=>a.flatMap(e=>e.questions),[a]),s=(0,p.useMemo)(()=>zpe(a),[a]),c=(0,p.useRef)(s),[l,u]=(0,p.useState)(()=>Object.fromEntries(o.map(e=>[e.id,{mode:null,answer:``}]))),[d,f]=(0,p.useState)(!1),[m,h]=(0,p.useState)(!1),[g,_]=(0,p.useState)(null);(0,p.useEffect)(()=>{u(e=>Object.fromEntries(o.map(t=>[t.id,e[t.id]??{mode:null,answer:``}]))),c.current!==s&&(c.current=s,d||(h(!0),_(i(`buildOpenQuestionsDialog.refreshedError`))))},[d,o,s,i]);let v=o.length>0&&o.every(e=>{let t=l[e.id];return t?.mode===`dismiss`||t?.mode===`answer`&&t.answer.trim()!==``}),y=o.some(e=>l[e.id]?.mode===`answer`),b=o.length>0&&o.every(e=>l[e.id]?.mode===`dismiss`),x=(e,t)=>{u(n=>({...n,[e]:{...n[e]??{mode:null,answer:``},...t}})),_(null)};return(0,X.jsx)(V_,{open:!0,onOpenChange:e=>{e||t()},children:(0,X.jsx)(U_,{showCloseButton:!1,className:`flex max-h-[calc(100vh-2rem)] flex-col gap-0 overflow-hidden p-0 sm:max-w-3xl`,children:(0,X.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),!(!v||m||d)){f(!0),_(null);try{await r({resolutions:o.map(e=>{let t=l[e.id];return t.mode===`dismiss`?{question_id:e.id,dismiss:!0}:{question_id:e.id,answer:t.answer.trim()}})})}catch(e){if(Lpe(e)){try{await n()}catch{_(i(`buildOpenQuestionsDialog.refreshFailedError`))}h(!0),_(e=>e??i(`buildOpenQuestionsDialog.conflictError`))}else _(e instanceof Ge?e.message:i(`buildOpenQuestionsDialog.submitError`))}finally{f(!1)}}},className:`flex min-h-0 flex-col`,children:[(0,X.jsxs)(W_,{className:`border-b border-border/70 px-5 py-4 sm:px-6`,children:[(0,X.jsx)(K_,{children:i(`buildOpenQuestionsDialog.title`)}),(0,X.jsx)(q_,{children:i(`buildOpenQuestionsDialog.description`)})]}),(0,X.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4 sm:px-6`,children:[a.map(e=>(0,X.jsxs)(`section`,{"aria-labelledby":`build-question-ticket-${e.ticket.id}`,children:[(0,X.jsx)(`h3`,{id:`build-question-ticket-${e.ticket.id}`,className:`text-sm font-semibold text-foreground`,children:i(`buildOpenQuestionsDialog.ticketHeading`,{title:e.ticket.title})}),(0,X.jsx)(`div`,{className:`mt-2 space-y-3`,children:e.questions.map(e=>{let t=l[e.id]??{mode:null,answer:``};return(0,X.jsxs)(`article`,{className:`min-w-0 rounded-xl border border-border/70 bg-background/30 p-4`,children:[(0,X.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm leading-6 text-foreground`,children:e.question_text}),(0,X.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-x-5 gap-y-2`,children:[(0,X.jsxs)(iv,{className:`flex cursor-pointer items-center gap-2 text-sm`,children:[(0,X.jsx)(`input`,{type:`radio`,name:`decision-${e.id}`,checked:t.mode===`answer`,onChange:()=>x(e.id,{mode:`answer`})}),i(`buildOpenQuestionsDialog.answerOption`)]}),(0,X.jsxs)(iv,{className:`flex cursor-pointer items-center gap-2 text-sm`,children:[(0,X.jsx)(`input`,{type:`radio`,name:`decision-${e.id}`,checked:t.mode===`dismiss`,onChange:()=>x(e.id,{mode:`dismiss`})}),i(`buildOpenQuestionsDialog.dismissOption`)]})]}),t.mode===`answer`&&(0,X.jsxs)(`div`,{className:`mt-3`,children:[(0,X.jsx)(iv,{htmlFor:`answer-${e.id}`,className:`sr-only`,children:i(`buildOpenQuestionsDialog.answerLabel`,{question:e.question_text})}),(0,X.jsx)(Y_,{id:`answer-${e.id}`,value:t.answer,onChange:t=>x(e.id,{mode:`answer`,answer:t.target.value}),placeholder:i(`buildOpenQuestionsDialog.answerPlaceholder`),rows:3,className:`max-h-64 resize-y break-words`})]})]},e.id)})})]},e.ticket.id)),o.length===0&&!d&&(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`buildOpenQuestionsDialog.empty`)})]}),(0,X.jsxs)(G_,{className:`items-start border-t border-border/70 px-5 py-4 sm:items-center sm:px-6`,children:[(0,X.jsxs)(`div`,{className:`mr-auto min-w-0 text-xs leading-5 text-muted-foreground`,"aria-live":`polite`,children:[g&&(0,X.jsx)(`p`,{className:`text-destructive`,children:g}),!g&&b&&(0,X.jsx)(`p`,{children:i(`buildOpenQuestionsDialog.dismissSummary`)}),!g&&!y&&!b&&(0,X.jsx)(`p`,{children:i(`buildOpenQuestionsDialog.incompleteSummary`)})]}),m&&(0,X.jsx)(Q,{type:`button`,variant:`outline`,onClick:()=>{h(!1),_(null)},children:i(`buildOpenQuestionsDialog.reviewRefreshed`)}),(0,X.jsx)(Q,{type:`button`,variant:`ghost`,onClick:t,children:i(`buildOpenQuestionsDialog.cancel`)}),(0,X.jsx)(Q,{type:`submit`,disabled:!v||m||d,children:i(d?`buildOpenQuestionsDialog.submitting`:`buildOpenQuestionsDialog.submit`)})]})]})})})},K6={blocked:{className:`stroke-red-400/80`,markerId:`dependency-arrowhead-blocked`},ready:{className:`stroke-emerald-400/80`,markerId:`dependency-arrowhead-ready`},preview:{className:`stroke-amber-300/80`,markerId:`dependency-arrowhead-preview`}},Vpe=e=>qv(e)?`ready`:`blocked`,q6=180,Hpe=560,J6=88,Y6=12,X6=18,Z6=`dependency-overlay-clip`,Q6=(e,t,n)=>Math.min(Math.max(e,t),n),Upe=(e,t)=>{if(!e||e.width<=0||e.height<=0||t.length===0)return null;let n=`M 0 0 H ${e.width} V ${e.height} H 0 Z`,r=t.filter(e=>e.width>0&&e.height>0).map(e=>`M ${e.left} ${e.top} H ${e.left+e.width} V ${e.top+e.height} H ${e.left} Z`);return r.length===0?null:`${n} ${r.join(` `)}`},Wpe=(e,t,n)=>n&&n.width>0&&n.height>0?n:Object.values(e).reduce((e,t)=>({width:Math.max(e.width,t.left+t.width),height:Math.max(e.height,t.top+t.height)}),{width:t.x,height:t.y}),Gpe=(e,t)=>{let n=Q6(Math.round(e.length*7.2)+24,q6,Hpe),r=Math.max(q6,t-Y6*2);return Math.min(n,r)},Kpe=(e,t,n,r,i)=>{let a=n.get(e.blockerTicketId);if(!a)return null;let o=e.hoveredTicketId&&e.hoveredTicketId!==e.blockerTicketId?r[e.hoveredTicketId]:null,s=e.hoveredTicketId&&e.hoveredTicketId!==e.blockerTicketId?n.get(e.hoveredTicketId):null,c=s?`${a.title} is blocking ${s.title}`:`${a.title} is blocking...`,{start:l,end:u}=ty(t,o??{left:e.pointer.x,top:e.pointer.y,width:0,height:0}),d=Wpe(r,e.pointer,i),f=o&&s?{x:l.x+(u.x-l.x)*.6,y:l.y+(u.y-l.y)*.6-28}:{x:u.x,y:u.y-28},p=Gpe(c,d.width);return{text:c,x:o&&s?Q6(f.x-p/2,Y6,Math.max(Y6,d.width-p-Y6)):(()=>{let e=f.x+X6,t=f.x-X6-p;return e+p<=d.width-Y6?e:t>=Y6?t:Q6(e,Y6,Math.max(Y6,d.width-p-Y6))})(),y:Q6(f.y,Y6,Math.max(Y6,d.height-J6-Y6)),width:p}},$6=({blockerRect:e,dependentRect:t,className:n,testId:r,markerEnd:i})=>{let{start:a,end:o}=ty(e,t),{path:s}=ny(a,o);return(0,X.jsx)(`g`,{"data-testid":r,children:(0,X.jsx)(`path`,{d:s,className:n,fill:`none`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,markerEnd:i})})},qpe=({preview:e,cardRects:t,ticketsById:n,overlaySize:r})=>{if(!e)return null;let i=t[e.blockerTicketId];if(!i)return null;let a=(e.hoveredTicketId&&e.hoveredTicketId!==e.blockerTicketId&&t[e.hoveredTicketId]?t[e.hoveredTicketId]:null)??{left:e.pointer.x,top:e.pointer.y,width:0,height:0},o=Kpe(e,i,n,t,r);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)($6,{blockerRect:i,dependentRect:a,className:K6.preview.className,testId:`dependency-preview`,markerEnd:`url(#${K6.preview.markerId})`}),(e=>o?(0,X.jsx)(`foreignObject`,{x:o.x,y:o.y,width:o.width,height:J6,"data-testid":`dependency-preview-label`,children:e}):null)((0,X.jsx)(`div`,{className:`pointer-events-none flex h-full w-full items-start`,children:(0,X.jsx)(`div`,{className:`max-w-full rounded-md border border-amber-300/60 bg-stone-950/85 px-3 py-1.5 text-xs font-medium leading-5 text-amber-100 shadow-lg shadow-stone-950/20 whitespace-normal break-words`,children:o?.text})}))]})},Jpe=({dependencies:e,cardRects:t,clipRects:n=[],preview:r,ticketsById:i,overlaySize:a})=>{let o=Upe(a,n);return(0,X.jsxs)(`svg`,{className:`pointer-events-none absolute inset-0 z-10 h-full w-full overflow-visible`,children:[(0,X.jsxs)(`defs`,{children:[Object.values(K6).map(e=>(0,X.jsx)(`marker`,{id:e.markerId,markerWidth:`8`,markerHeight:`8`,refX:`7`,refY:`4`,orient:`auto`,markerUnits:`userSpaceOnUse`,children:(0,X.jsx)(`path`,{d:`M 0 0 L 8 4 L 0 8`,className:e.className,fill:`none`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`})},e.markerId)),o&&(0,X.jsx)(`clipPath`,{id:Z6,children:(0,X.jsx)(`path`,{d:o,clipRule:`evenodd`})})]}),(0,X.jsxs)(`g`,{"data-testid":`dependency-overlay-content`,clipPath:o?`url(#${Z6})`:void 0,children:[e.map(e=>{let n=i.get(e.blocker_ticket_id),r=i.get(e.dependent_ticket_id),a=t[e.blocker_ticket_id],o=t[e.dependent_ticket_id];if(n?.parked_at||r?.parked_at)return null;let s=K6[Vpe(n)];return!a||!o?null:(0,X.jsx)($6,{blockerRect:a,dependentRect:o,className:s.className,testId:`dependency-edge-${e.blocker_ticket_id}-${e.dependent_ticket_id}`,markerEnd:`url(#${s.markerId})`},`${e.blocker_ticket_id}:${e.dependent_ticket_id}`)}),(0,X.jsx)(qpe,{preview:r,cardRects:t,ticketsById:i,overlaySize:a})]})]})},Ype=({onOpenProjectExecutionSettings:e})=>{let{t}=q(`common`);return(0,X.jsxs)(`p`,{className:`mt-2 w-full max-w-none text-xs leading-relaxed text-amber-200/90`,role:`status`,children:[t(`modelSelector.dockerSandboxNotice`),e&&(0,X.jsx)(Q,{type:`button`,variant:`link`,size:`xs`,className:`ml-1 h-auto align-baseline px-0 text-xs font-medium text-amber-100`,onClick:e,children:t(`modelSelector.openExecutionSettings`)})]})},Xpe=({onSubmit:e,bundles:t,projectId:n=null,projectBranchState:r=null,tool:i,showModelSelector:a=!1,showSkillsSelector:o=!1,availableModels:s=[],availableSkills:c=[],initialModel:l=``,initialVariant:u=``,initialSkills:d=[],initialWorktreeBundleId:f=null,initialImportedDraft:p=null,onCreateBundle:m,onDeleteBundle:h,onRefreshBundles:g,showDockerSandboxModelNotice:_=!1,onOpenProjectExecutionSettings:v,onClose:y})=>{let{t:b}=q(`common`),{jiraImportState:x,importFromJira:S}=mw(n),{gitHubImportState:C,importFromGitHub:w}=IC(n),T=[{key:`jira`,label:b(`jiraImportField.label`),placeholder:b(`jiraImportField.placeholder`),state:x,onImport:S},{key:`github`,label:b(`githubImportField.label`),placeholder:b(`githubImportField.placeholder`),state:C,onImport:w}];return(0,X.jsx)(tC,{onClose:y,overlayClassName:`bg-black/70`,panelClassName:`h-[92vh] w-[96vw] max-w-6xl overflow-y-auto rounded-2xl border border-border bg-card p-4 shadow-2xl sm:p-5 lg:p-6`,renderContent:({closeButton:x})=>(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`absolute right-4 top-4 z-10 sm:right-5 sm:top-5 lg:right-6 lg:top-6`,children:x}),(0,X.jsx)(FY,{heading:b(`newTicketModal.heading`),bundles:t,showModelSelector:a,showSkillsSelector:o,availableModels:s,availableSkills:c,projectId:n,initialModel:l,initialVariant:u,initialSkills:d,initialWorktreeBundleId:f,initialImportedDraft:p,projectBranchState:r,externalImportProviders:T,onCancel:y,onCreateBundle:m,onDeleteBundle:h,onRefreshBundles:g,modelSelectorNotice:_?(0,X.jsx)(Ype,{onOpenProjectExecutionSettings:v}):void 0,titleInputId:`title`,descriptionInputId:`description`,bundleSelectId:`new-ticket-bundle`,modelSelectId:`new-model`,variantSelectId:`new-variant`,skillsSelectId:`new-skills`,showEmptyBundleOption:!0,planAction:i?{label:b(`newTicketModal.actions.plan`),onClick:async({title:t,description:n,model:r,variant:i,skills:a,worktree_bundle_id:o,external_source:s})=>{await e(t,n,`plan`,r,i,a,{worktree_bundle_id:o??void 0,...s?{external_source:s}:{}}),y()}}:void 0,primaryAction:{label:b(`newTicketModal.actions.createTicket`),variant:`subtle`,onClick:async({title:t,description:n,model:r,variant:i,skills:a,worktree_bundle_id:o,external_source:s})=>{await e(t,n,`create`,r,i,a,{worktree_bundle_id:o??void 0,...s?{external_source:s}:{}}),y()}},secondaryAction:{label:b(`newTicketModal.actions.createAndBuild`),variant:`brand`,showAdvanceIcon:!0,onClick:async({title:t,description:n,model:r,variant:i,skills:a,worktree_bundle_id:o,external_source:s})=>{await e(t,n,`build`,r,i,a,{worktree_bundle_id:o??void 0,...s?{external_source:s}:{}}),y()}}})]})})},Zpe=({className:e=``})=>{let{setNodeRef:t,isOver:n}=KP({id:`trash`});return(0,X.jsxs)(`div`,{ref:t,"data-testid":`delete-drop-zone`,className:`${e} flex min-w-[13rem] select-none items-center justify-between gap-4 rounded-2xl border px-4 py-3 backdrop-blur-sm transition-all duration-150 ${n?`scale-[1.02] border-red-400/70 bg-destructive/35 text-red-100 shadow-lg shadow-red-950/30`:`border-red-500/30 bg-background/82 text-red-200/85`}`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(rC,{variant:`destructive`,className:`text-[11px] uppercase tracking-[0.28em]`,children:`Delete`}),(0,X.jsx)(`div`,{className:`mt-1 text-sm font-medium`,children:n?`Release to delete`:`Drop here to delete`})]}),(0,X.jsx)(`div`,{className:`rounded-xl border p-2 transition-colors ${n?`border-red-400/60 bg-red-500/20`:`border-red-500/20 bg-background/60`}`,children:(0,X.jsx)(fC,{className:`h-5 w-5 transition-colors ${n?`text-red-100`:`text-red-300/70`}`})})]})},Qpe=(e,t)=>Y(Je(`/ticket-dependencies`,e),{signal:t}),$pe=(e,t)=>Y(Je(`/ticket-dependencies`,e),{method:`POST`,body:t,fallbackErrorMessage:`Unable to create the dependency right now.`}),eme=(e,t,n)=>Ze(Je(`/ticket-dependencies/${t}/${n}`,e),{method:`DELETE`,fallbackErrorMessage:`Unable to remove the dependency right now.`}),tme=(e,t)=>{let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n){let n=e[r],i=t[r];if(!n||!i||n.left!==i.left||n.top!==i.top||n.width!==i.width||n.height!==i.height)return!1}return!0},nme=(e,t)=>e.length===t.length?e.every((e,n)=>{let r=t[n];return r!==void 0&&e.left===r.left&&e.top===r.top&&e.width===r.width&&e.height===r.height}):!1,rme=(e,t)=>e===t?!0:!e||!t?!1:e.projectId===t.projectId&&e.blockerTicketId===t.blockerTicketId&&e.hoveredTicketId===t.hoveredTicketId&&e.pointer.x===t.pointer.x&&e.pointer.y===t.pointer.y,ime=({activeProjectId:e,tickets:t,dependencies:n,setDependencies:r,activeTicket:i,activeOverlayNode:a,dragOffset:o})=>{let[s,c]=(0,p.useState)({}),[l,u]=(0,p.useState)([]),[d,f]=(0,p.useState)({width:0,height:0}),[m,h]=(0,p.useState)(null),[g,_]=(0,p.useState)(null),v=(0,p.useRef)(null),y=(0,p.useRef)(null),b=(0,p.useRef)(null),x=(0,p.useRef)(new Map),S=(0,p.useRef)(new Map),C=(0,p.useRef)({}),w=(0,p.useRef)(null),T=(0,p.useRef)(null),E=(0,p.useRef)(null),D=(0,p.useRef)(null),O=(0,p.useRef)(null),k=(0,p.useRef)(null),A=(0,p.useRef)(null),j=(0,p.useMemo)(()=>new Map(t.map(e=>[e.id,e])),[t]);(0,p.useEffect)(()=>{O.current=g},[g]),(0,p.useLayoutEffect)(()=>{if(!i||!a||!y.current)return;let e=window.requestAnimationFrame(()=>{let e=y.current?.getBoundingClientRect(),t=a.getBoundingClientRect();e&&h({ticketId:i.id,rect:{left:t.left-e.left,top:t.top-e.top,width:t.width,height:t.height}})});return()=>{window.cancelAnimationFrame(e)}},[a,i,o.x,o.y]);let M=(0,p.useCallback)(()=>{w.current===null&&(w.current=window.requestAnimationFrame(()=>{w.current=null;let e=y.current;if(!e){b.current=null,C.current={},c({}),u([]),f({width:0,height:0});return}let t=e.getBoundingClientRect(),n={};b.current={left:t.left,top:t.top},f(e=>e.width===t.width&&e.height===t.height?e:{width:t.width,height:t.height});for(let[e,r]of x.current){let i=r.getBoundingClientRect();n[e]={left:i.left-t.left,top:i.top-t.top,width:i.width,height:i.height}}let r=Array.from(S.current.values()).flatMap(({columnNode:e,listNode:n})=>{let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),a=Math.max(0,i.top-r.top);return r.width<=0||a<=0?[]:[{left:r.left-t.left,top:r.top-t.top,width:r.width,height:a}]});u(e=>nme(e,r)?e:r),C.current=n,c(e=>tme(e,n)?e:n)}))},[]);(0,p.useEffect)(()=>{let e=v.current;if(!e)return;let t=()=>{M()};return e.addEventListener(`scroll`,t,!0),window.addEventListener(`resize`,t),()=>{e.removeEventListener(`scroll`,t,!0),window.removeEventListener(`resize`,t)}},[M]),(0,p.useEffect)(()=>{if(typeof ResizeObserver!=`function`)return;let e=new ResizeObserver(()=>{M()});T.current=e;for(let t of x.current.values())e.observe(t);return()=>{e.disconnect(),T.current===e&&(T.current=null)}},[M]),(0,p.useEffect)(()=>{if(typeof ResizeObserver!=`function`)return;let e=new ResizeObserver(()=>{M()});E.current=e;for(let t of S.current.values())e.observe(t.columnNode),e.observe(t.listNode);return()=>{e.disconnect(),E.current===e&&(E.current=null)}},[M]),(0,p.useEffect)(()=>{let e=v.current,t=y.current;if(!e&&!t)return;let n=new ResizeObserver(()=>{M()});return e&&n.observe(e),t&&t!==e&&n.observe(t),()=>{n.disconnect()}},[M]),(0,p.useEffect)(()=>(M(),()=>{w.current!==null&&(window.cancelAnimationFrame(w.current),w.current=null)}),[n,M,t]);let N=(0,p.useCallback)((e,t)=>{let n=x.current.get(e);if(t){if(n===t)return;x.current.set(e,t),T.current?.observe(t)}else{if(!n)return;x.current.delete(e),T.current?.unobserve(n)}M()},[M]),P=(0,p.useCallback)((e,t)=>{let n=S.current.get(e);if(t){if(n?.columnNode===t.columnNode&&n.listNode===t.listNode)return;n&&(E.current?.unobserve(n.columnNode),E.current?.unobserve(n.listNode)),S.current.set(e,t),E.current?.observe(t.columnNode),E.current?.observe(t.listNode)}else{if(!n)return;S.current.delete(e),E.current?.unobserve(n.columnNode),E.current?.unobserve(n.listNode)}M()},[M]),F=(0,p.useCallback)(e=>{rme(O.current,e)||(O.current=e,_(e))},[]),I=(0,p.useCallback)(()=>{k.current!==null&&(window.cancelAnimationFrame(k.current),k.current=null),A.current=null},[]),L=(0,p.useCallback)(e=>{A.current=e,k.current===null&&(k.current=window.requestAnimationFrame(()=>{k.current=null;let e=A.current;A.current=null,F(e)}))},[F]),R=(0,p.useCallback)((e,t)=>{let n=b.current;if(!n&&y.current){let e=y.current.getBoundingClientRect();n={left:e.left,top:e.top},b.current=n}return n?{x:e-n.left,y:t-n.top}:{x:e,y:t}},[]),z=(0,p.useCallback)((e,t,n)=>{for(let[r,i]of Object.entries(C.current))if(r!==n&&e>=i.left&&e<=i.left+i.width&&t>=i.top&&t<=i.top+i.height)return r;return null},[]),ee=(0,p.useCallback)(async t=>{if(e)try{await eme(e,t.blocker_ticket_id,t.dependent_ticket_id),r(e=>Gv(e,t.blocker_ticket_id,t.dependent_ticket_id))}catch(e){$.error(e instanceof Ge?e.message:`Unable to remove the dependency right now.`,{id:`board-dependency-error`})}},[e,r]),B=(0,p.useCallback)((t,i)=>{if(!e)return;i.preventDefault(),D.current?.();let a=(n,r,i=!1)=>{let a=R(n,r),o={projectId:e,blockerTicketId:t,hoveredTicketId:z(a.x,a.y,t),pointer:a};if(i){I(),F(o);return}L(o)};a(i.clientX,i.clientY,!0);let o=e=>{a(e.clientX,e.clientY)},s=async i=>{let a=R(i.clientX,i.clientY),o=z(a.x,a.y,t),s=o?Kv(n,t,o):null;if(D.current?.(),D.current=null,F(null),!(!o||!s)){if(!s.valid){$.error(dne(s.reason),{id:`board-dependency-error`});return}try{let n=await $pe(e,{blocker_ticket_id:t,dependent_ticket_id:o});r(e=>Wv(e,n))}catch(e){$.error(e instanceof Ge?e.message:`Unable to create the dependency right now.`,{id:`board-dependency-error`})}}};D.current=()=>{window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),I()},window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s,{once:!0})},[e,I,n,z,R,L,r,F]);(0,p.useEffect)(()=>{D.current?.(),D.current=null,I(),O.current=null},[e,I]),(0,p.useEffect)(()=>()=>{D.current?.(),k.current!==null&&(window.cancelAnimationFrame(k.current),k.current=null)},[]);let V=(0,p.useMemo)(()=>{let r=g?.blockerTicketId;if(!r||g.projectId!==e||!j.has(r))return null;let i=new Map;for(let e of t){if(e.id===r){i.set(e.id,`source`);continue}let t=Kv(n,r,e.id);i.set(e.id,t.valid?`valid`:`idle`)}return i},[e,n,g,j,t]),H=(0,p.useCallback)(e=>{if(!V||!g)return`idle`;let t=V.get(e)??`idle`;return e===g.hoveredTicketId&&t===`idle`?`invalid`:t},[V,g]),U=(0,p.useMemo)(()=>!g||g.projectId!==e||!j.has(g.blockerTicketId)?null:{blockerTicketId:g.blockerTicketId,hoveredTicketId:g.hoveredTicketId,pointer:g.pointer},[e,g,j]);return{boardViewportRef:v,boardContentRef:y,registerTicketNode:N,registerDependencyClipNodes:P,measuredCardRects:(0,p.useMemo)(()=>{if(!i)return s;let e=s[i.id];return e?m?.ticketId===i.id?{...s,[i.id]:m.rect}:{...s,[i.id]:{...e,left:e.left+o.x,top:e.top+o.y}}:s},[m,i,s,o.x,o.y]),dependencyClipRects:l,overlayPreview:U,overlaySize:d,getDependencyTargetState:H,handleDependencyStart:B,handleDeleteDependency:ee}},ame=`[data-terminal-pane="true"]`,ome=e=>{if(!(e instanceof HTMLElement))return!1;let t=e.tagName.toLowerCase();return t===`input`||t===`textarea`||e.isContentEditable},sme=e=>e instanceof HTMLElement?e.closest(ame)!==null:!1,cme=e=>ome(e)||sme(e),lme=(e,t={})=>{let{isBlocked:n}=t;(0,p.useEffect)(()=>{let t=t=>{if(t.defaultPrevented||t.repeat)return;let r=e.find(e=>!e.disabled&&e.key.toLowerCase()===t.key.toLowerCase()&&(e.ctrlKey??!1)===t.ctrlKey&&(e.altKey??!1)===t.altKey&&(e.metaKey??!1)===t.metaKey&&(e.shiftKey===void 0||e.shiftKey===t.shiftKey));r&&(n?.(document.activeElement)||(t.preventDefault(),r.onKeyDown()))};return window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`keydown`,t)}},[e,n])},e8=new Set([`queued`,`running`]),ume={check_batch:`checks`,check_repair:`auto_fix`,automation_review_fix:`auto_fix`,automation_commit:`commit`,automation_push:`push`,automation_pull_request:`pr`},t8=e=>{if(!e.id)return null;let t=Date.parse(e.updated_at);return Number.isFinite(t)?t:null},dme=e=>{let t=e.source_reference;if(e.kind!==`automation_progression`||e.status!==`waiting`&&!e8.has(e.status)||e.initiated_by!==`automation`&&e.initiated_by!==`recovery`||!t||typeof t!=`object`||t.kind!==`bundle`||typeof t.id!=`string`)return null;let n=t.id.trim(),r=t8(e);return!n||r===null?null:{bundleId:n,id:e.id,isActive:e8.has(e.status),updatedAt:r}},fme=e=>{let t=ume[e.kind],n=t8(e);return!t||!e8.has(e.status)||e.initiated_by!==`automation`||!e.parent_run_id||n===null?null:{id:e.id,parentRunId:e.parent_run_id,status:t,updatedAt:n}},n8=(e,t)=>e.updatedAt===t.updatedAt?e.id.localeCompare(t.id)>0:e.updatedAt>t.updatedAt,pme=e=>{let t=new Map,n=[];for(let r of e){if(!r||typeof r!=`object`)continue;let e=dme(r);if(e){let n=t.get(e.bundleId);(!n||n8(e,n))&&t.set(e.bundleId,e);continue}let i=fme(r);i&&n.push(i)}let r=new Map,i=new Map;for(let e of t.values())e.isActive&&(r.set(e.id,e.bundleId),i.set(e.bundleId,`automation`));let a=new Map;for(let e of n){let t=r.get(e.parentRunId);if(!t)continue;let n=a.get(t);(!n||n8(e,n))&&a.set(t,e)}for(let[e,t]of a)i.set(e,t.status);return i},r8=`archon.last-model-selection`,i8=`archon.last-variant-selection`,a8=`archon.last-skills-selection`,mme=()=>{try{let e=window.localStorage.getItem(a8),t=e?JSON.parse(e):[];return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}},o8=()=>({build:!1,stopBuild:!1,resumeBuild:!1,review:!1,undoReview:!1,run:!1,stop:!1,followUp:!1,bundleRefresh:!1}),hme=(e,t,n)=>{e?window.localStorage.setItem(r8,e):window.localStorage.removeItem(r8),t?window.localStorage.setItem(i8,t):window.localStorage.removeItem(i8),n.length>0?window.localStorage.setItem(a8,JSON.stringify(n)):window.localStorage.removeItem(a8)},s8=(e,t={})=>Vy(e,t),gme=()=>({model:window.localStorage.getItem(`archon.last-model-selection`)??``,variant:window.localStorage.getItem(`archon.last-variant-selection`)??``,skills:mme()}),c8={runs:[],events:[],isLoading:!1,isLoadingMore:!1,hasMoreRuns:!1,hasMoreEvents:!1,error:null},l8=(0,p.createContext)({state:new Map,loadMoreProject:()=>void 0,refreshProject:()=>void 0,subscribeProject:()=>()=>void 0}),_me=[`queued`,`waiting`,`running`],vme=(e,t,n,r)=>hue(e,{cursor:t,limit:200,signal:n,statuses:r}),yme=(e,t,n)=>gue(e,{cursor:t,limit:200,signal:n}),bme=(e,t)=>{let n=t.created_at.localeCompare(e.created_at);return n===0?t.id.localeCompare(e.id):n},xme=(e,t)=>{let n=t.created_at.localeCompare(e.created_at);if(n!==0)return n;let r=t.execution_run_id.localeCompare(e.execution_run_id);if(r!==0)return r;let i=t.sequence-e.sequence;return i===0?t.id.localeCompare(e.id):i},u8=(e,t)=>{let n=new Map(e.map(e=>[e.id,e]));for(let e of t){let t=n.get(e.id);(!t||e.updated_at>=t.updated_at)&&n.set(e.id,e)}return[...n.values()].sort(bme)},d8=(e,t)=>{let n=new Map(e.map(e=>[e.id,e]));for(let e of t)n.set(e.id,e);return[...n.values()].sort(xme)},Sme=async(e,t,n)=>{let r=null,i=[];do{let a=await e(t,r,n,_me);i=u8(i,a.runs),r=a.next_cursor}while(r);return i},Cme=({socket:e,fetchRunsPage:t,fetchEventsPage:n,children:r})=>{let i=uq(),a=e??i,o=t??vme,s=n??yme,[c,l]=(0,p.useState)(()=>new Map),u=(0,p.useRef)(new Map),d=(0,p.useRef)(new Map),f=(0,p.useRef)(new Map),m=(0,p.useRef)(new Map),h=(0,p.useCallback)(e=>{d.current.get(e)?.abort();let t=new AbortController;d.current.set(e,t),m.current.set(e,{runs:[],events:[]}),l(t=>{let n=new Map(t),r=n.get(e)??c8;return n.set(e,{...r,isLoading:!0,isLoadingMore:!1,error:null}),n}),Promise.all([o(e,null,t.signal),Sme(o,e,t.signal),s(e,null,t.signal)]).then(([n,r,i])=>{if(t.signal.aborted||d.current.get(e)!==t)return;f.current.set(e,{runs:n.next_cursor,events:i.next_cursor});let a=m.current.get(e)??{runs:[],events:[]};l(t=>{let o=new Map(t);return o.set(e,{runs:u8(u8(n.runs,r),a.runs),events:d8(i.events,a.events),isLoading:!1,isLoadingMore:!1,hasMoreRuns:!!n.next_cursor,hasMoreEvents:!!i.next_cursor,error:null}),o})}).catch(t=>{Ye(t)||l(n=>{let r=new Map(n),i=r.get(e)??c8;return r.set(e,{...i,isLoading:!1,isLoadingMore:!1,error:t instanceof Error?t.message:`Unable to load activity right now.`}),r})}).finally(()=>{d.current.get(e)===t&&(d.current.delete(e),m.current.delete(e))})},[s,o]),g=(0,p.useCallback)(e=>{if(d.current.has(e))return;let t=f.current.get(e);if(!t||!t.runs&&!t.events)return;let n=new AbortController;d.current.set(e,n),l(t=>{let n=new Map(t),r=n.get(e)??c8;return n.set(e,{...r,isLoadingMore:!0,error:null}),n}),Promise.all([t.runs?o(e,t.runs,n.signal):Promise.resolve({runs:[],next_cursor:null}),t.events?s(e,t.events,n.signal):Promise.resolve({events:[],next_cursor:null})]).then(([t,r])=>{n.signal.aborted||d.current.get(e)!==n||(f.current.set(e,{runs:t.next_cursor,events:r.next_cursor}),l(n=>{let i=new Map(n),a=i.get(e)??c8;return i.set(e,{...a,runs:u8(a.runs,t.runs),events:d8(a.events,r.events),isLoadingMore:!1,hasMoreRuns:!!t.next_cursor,hasMoreEvents:!!r.next_cursor,error:null}),i}))}).catch(t=>{Ye(t)||l(n=>{let r=new Map(n),i=r.get(e)??c8;return r.set(e,{...i,isLoadingMore:!1,error:t instanceof Error?t.message:`Unable to load more activity right now.`}),r})}).finally(()=>{d.current.get(e)===n&&d.current.delete(e)})},[s,o]),_=(0,p.useCallback)(e=>{let t=u.current.get(e)??0;return u.current.set(e,t+1),t===0&&h(e),()=>{let t=(u.current.get(e)??1)-1;if(t>0){u.current.set(e,t);return}u.current.delete(e),d.current.get(e)?.abort(),d.current.delete(e),f.current.delete(e),m.current.delete(e),l(t=>{let n=new Map(t);return n.delete(e),n})}},[h]),v=(0,p.useCallback)(e=>{if(!e||!u.current.has(e.project_id))return;let t=m.current.get(e.project_id);t&&(t.runs=u8(t.runs,[e])),l(t=>{let n=new Map(t),r=n.get(e.project_id)??c8;return n.set(e.project_id,{...r,runs:u8(r.runs,[e]),isLoading:!1}),n})},[]),y=(0,p.useCallback)(e=>{if(!e||!u.current.has(e.project_id))return;let t=m.current.get(e.project_id);t&&(t.events=d8(t.events,[e])),l(t=>{let n=new Map(t),r=n.get(e.project_id)??c8;return n.set(e.project_id,{...r,events:d8(r.events,[e]),isLoading:!1}),n})},[]),b=(0,p.useCallback)(()=>{for(let e of u.current.keys())h(e)},[h]);(0,p.useEffect)(()=>(a.on(`execution-run:updated`,v),a.on(`lifecycle-event:created`,y),a.on(`connect`,b),()=>{a.off(`execution-run:updated`,v),a.off(`lifecycle-event:created`,y),a.off(`connect`,b)}),[b,y,v,a]),(0,p.useEffect)(()=>()=>{for(let e of d.current.values())e.abort()},[]);let x=(0,p.useMemo)(()=>({state:c,loadMoreProject:g,refreshProject:h,subscribeProject:_}),[g,h,c,_]);return(0,X.jsx)(l8.Provider,{value:x,children:r})},f8=e=>{let{loadMoreProject:t,refreshProject:n,state:r,subscribeProject:i}=(0,p.useContext)(l8);(0,p.useEffect)(()=>{if(e)return i(e)},[e,i]);let a=(0,p.useCallback)(()=>{e&&n(e)},[e,n]),o=(0,p.useCallback)(()=>{e&&t(e)},[t,e]);return{...e?r.get(e)??c8:c8,loadMore:o,refresh:a}},p8=e=>({...e,messages:void 0,agent_log:void 0,streaming_response:void 0}),m8=(e,t)=>e?e.state!==t.state||e.parked_at!==t.parked_at||e.worktree_bundle_id!==t.worktree_bundle_id:!0,h8=(e,t)=>{if(!e)return t;let n=t.worktree_bundle_id!==null&&e.worktree_bundle_id===t.worktree_bundle_id,r=t.bundle??(n&&e.bundle?.id===t.worktree_bundle_id?e.bundle:null),i=t.bundle_execution_position??(n?e.bundle_execution_position??null:null);return{...e,...t,diff_stats:t.diff_stats===void 0?e.diff_stats:t.diff_stats,is_stale:t.is_stale===void 0?e.is_stale:t.is_stale,bundle:r,bundle_execution_position:i}},g8=(e,t)=>{let n=e=>gy(t)?gy(e):e.state===t.state&&!gy(e),r=e.findIndex(e=>n(e));if(r===-1)return[...e,t];let i=[...e];return i.splice(r,0,t),i},_8=(e,t)=>{let n=e.find(e=>e.id===t.id);return[n&&n.pull_request!==void 0&&t.pull_request===void 0?{...n,...t,pull_request:n.pull_request}:t,...e.filter(e=>e.id!==t.id)]},v8=(e,t)=>{let n=e.find(e=>e.id===t.id);if(!n)return[...e,t];let r=h8(n,t);return e.map(e=>e.id===t.id?r:e)},y8=(e,t)=>{let n=h8(e.find(e=>e.id===t.id),t);return g8(b8(e,t.id),n)},wme=(e,t)=>{if(e.length===0)return[...t];let n=[...e];for(let e of t)n=m8(n.find(t=>t.id===e.id),e)?y8(n,e):v8(n,e);let r=new Set(t.map(e=>e.id));return n.filter(e=>r.has(e.id))},b8=(e,t)=>e.filter(e=>e.id!==t),x8=(e,t,n,r={},i={})=>{let a=e.findIndex(e=>e.id===t);if(a===-1)return e;let o={...e[a],state:n,...r},s=b8(e,t);if(i.preferredIndex!==void 0){let e=Math.max(0,Math.min(i.preferredIndex,s.length));return s.splice(e,0,o),s}return g8(s,o)},S8=e=>e.state===`review`&&e.agent_status===`done`&&!!e.automation_progression_run_id,Tme=e=>S8(e)&&!e.automation_paused_at,Eme=15*1e3,Dme=1e3,Ome=async(e,t)=>{let n=bde({projectId:t,ticketId:e.id,agentMessageId:e.agent_message_id});if(!n)return;let r=e.worktree_bundle_id!==null&&e.state!==`plan`?{kind:`bundle`,projectId:t,bundleId:e.worktree_bundle_id}:{kind:`ticket`,projectId:t,ticketId:e.id};await i3({title:`Ticket done`,body:e.title,key:n,destination:r})},C8=e=>p8(e),kme=(e,t)=>t===`running`&&e.agent_status===`done`?`Finished ${e.state} for "${e.title}"`:t===`running`&&e.agent_status===`error`?`Failed ${e.state} for "${e.title}"`:t!==`running`&&e.agent_status===`running`?`Running ${e.state} for "${e.title}"`:null,Ame=({activeProjectId:e,refreshKey:t=0,onLoadedProjectIdChange:n,onProjectUsageChange:r,onBundlesChange:i,onBundlesLoadingChange:a,children:o})=>{let s=uq(),[c,l]=(0,p.useState)([]),[u,d]=(0,p.useState)([]),[f,m]=(0,p.useState)([]),[h,g]=(0,p.useState)([]),[_,v]=(0,p.useState)(null),[y,b]=(0,p.useState)(null),[x,S]=(0,p.useState)(null),[C,w]=(0,p.useState)(null),[T,E]=(0,p.useState)(null),[D,O]=(0,p.useState)(null),k=(0,p.useRef)(0),A=(0,p.useRef)(0),j=(0,p.useRef)(new Map),M=(0,p.useRef)(new Map),N=(0,p.useRef)([]),P=(0,p.useRef)(e),F=(0,p.useRef)(new Map),I=(0,p.useRef)(new Map),L=(0,p.useRef)(new Map),R=(0,p.useCallback)((e,t)=>{let n=I.current.get(t.id);return!n||!e||t.state===n?t:e},[]),z=(0,p.useCallback)((e,t)=>{if(e.length===0)return;let n=new Map(I.current);for(let r of e)n.set(r,t);I.current=n},[]),ee=(0,p.useCallback)(e=>{if(e.length===0||I.current.size===0)return;let t=new Map(I.current);for(let n of e)t.delete(n);I.current=t},[]),B=(0,p.useCallback)((e,t)=>{if(e.length===0)return;let n=new Map(L.current);for(let r of e)n.set(r,t);L.current=n},[]),V=(0,p.useCallback)(e=>{if(e.length===0||L.current.size===0)return;let t=new Map(L.current);for(let n of e)t.delete(n);L.current=t},[]),H=(0,p.useCallback)((e,t)=>{if(F.current.has(t.id))return null;let n=R(e,t);return L.current.has(t.id)?{...n,parked_at:L.current.get(t.id)??null}:n},[R]),U=(0,p.useCallback)((e,t)=>{if(F.current.size===0&&I.current.size===0&&L.current.size===0)return t;let n=new Map(e.map(e=>[e.id,e]));return t.flatMap(e=>{let t=H(n.get(e.id),e);return t?[t]:[]})},[H]),W=(0,p.useCallback)(async(e,t)=>{let n=await an(e,t,{detail:`board`});return Array.isArray(n)?(!t?.aborted&&P.current===e&&l(e=>wme(e,U(e,n).map(C8))),n):null},[U]),te=(0,p.useCallback)(async(e,t)=>{await W(e,t)},[W]),ne=(0,p.useCallback)(async(e,t)=>{let n=++A.current,r=await on(e,t);if(!Array.isArray(r)||t?.aborted||P.current!==e||A.current!==n)return;let i=new Map(r.map(e=>[e.id,e]));l(e=>e.map(e=>{let t=i.get(e.id);return t?{...e,diff_stats:t.diff_stats??null,is_stale:t.is_stale}:e}))},[]),re=(0,p.useCallback)(e=>e.some(e=>e.is_stale===void 0),[]),ie=(0,p.useCallback)(async e=>{let t=P.current;if(!t)return null;try{let n=await sn(e,t);if(P.current!==t)return null;let r=M.current.get(n.id),i=H(r,n);if(!i)return null;let a=C8(i),o=m8(r,a);return l(e=>o?y8(e,a):v8(e,a)),n}catch{return null}},[H]),ae=(0,p.useCallback)(async t=>{if(!e){m([]);return}m(await gt(e,t))},[e]),G=(0,p.useMemo)(()=>new Map(c.map(e=>[e.id,e])),[c]),oe=(0,p.useMemo)(()=>{let e=c.filter(e=>e.agent_status===`running`),t=new Set(e.map(e=>e.worktree_bundle_id).filter(e=>typeof e==`string`&&e.trim().length>0));return{total_running:e.length,running_plan_count:e.filter(e=>e.state===`plan`).length,running_build_count:e.filter(e=>e.state===`build`).length,running_review_count:e.filter(e=>e.state===`review`).length,active_bundle_count:t.size,latest_message:D}},[D,c]);(0,p.useEffect)(()=>{if(M.current=G,N.current.length===0)return;let e=[],t=[];for(let n of N.current){let r=G.get(n.blocker_ticket_id),i=G.get(n.dependent_ticket_id);r&&i&&r.project_id===P.current&&i.project_id===P.current?e.push(n):t.push(n)}N.current=t,e.length>0&&d(t=>e.reduce((e,t)=>Wv(e,t),t))},[G]),(0,p.useEffect)(()=>{P.current=e,F.current.clear(),N.current=[],I.current.clear(),L.current.clear(),O(null),v(null),j.current.clear()},[e]),(0,p.useEffect)(()=>{n?.(C?null:y)},[y,C,n]),(0,p.useEffect)(()=>{if(i){if(!e){i(null,[]);return}if(x!==e){i(e,[]);return}i(e,f)}},[e,f,x,i]),(0,p.useEffect)(()=>{if(a){if(!e){a(null,!1);return}a(e,T===e)}},[e,T,a]),(0,p.useEffect)(()=>{let t=new AbortController,n=++k.current,r=null,i=async()=>{try{if(!e){l([]),d([]),m([]),b(null),S(null),w(null);return}l([]),d([]),m([]),b(null),S(null),w(e),E(e);let i=W(e,t.signal).finally(()=>{!t.signal.aborted&&k.current===n&&(b(e),w(null))}),a=Qpe(e,t.signal).then(e=>(!t.signal.aborted&&k.current===n&&d(e),e)),o=gt(e,t.signal).then(e=>(!t.signal.aborted&&k.current===n&&m(e),e)).finally(()=>{!t.signal.aborted&&k.current===n&&(S(e),E(null))}),[s,c,u]=await Promise.allSettled([i,a,o]);if(t.signal.aborted)return;s.status!==`fulfilled`&&!Ye(s.reason)&&l([]),c.status===`fulfilled`?d(c.value):Ye(c.reason)||d([]),u.status===`fulfilled`?m(u.value):Ye(u.reason)||m([]),s.status===`fulfilled`&&s.value!==null&&re(s.value)&&(r=window.setTimeout(()=>{t.signal.aborted||ne(e,t.signal)},Dme))}finally{!t.signal.aborted&&k.current===n&&(w(null),E(null))}},a=t=>{t.project_id===e&&(v(t),!F.current.has(t.id)&&(t.bundle&&m(e=>_8(e,t.bundle)),l(e=>y8(e,C8(t)))))},o=t=>{if(t.project_id===e&&v(t),l(n=>{if(t.project_id!==e)return b8(n,t.id);let r=n.find(e=>e.id===t.id),i=H(r,t);if(!i)return n;let a=C8(i);return m8(r,a)?y8(n,a):v8(n,a)}),t.project_id!==e){d(e=>Uv(e,t.id));return}t.bundle&&m(e=>_8(e,t.bundle))},c=({id:e})=>{F.current.delete(e),L.current.delete(e),I.current.delete(e),l(t=>b8(t,e)),d(t=>Uv(t,e))},u=({project_id:e,bundle_id:t,pull_request:n})=>{e===P.current&&(m(e=>e.map(e=>e.id===t?{...e,pull_request:n}:e)),l(e=>e.map(e=>e.worktree_bundle_id!==t||!e.bundle?e:{...e,bundle:{...e.bundle,pull_request:n}})),v(e=>e?.worktree_bundle_id!==t||!e.bundle?e:{...e,bundle:{...e.bundle,pull_request:n}}))},f=e=>{if(!e)return;let t=M.current.get(e.blocker_ticket_id),n=M.current.get(e.dependent_ticket_id);if(!t||!n){N.current.push(e);return}t.project_id!==P.current||n.project_id!==P.current||d(t=>Wv(t,e))},p=e=>{d(t=>Gv(t,e.blocker_ticket_id,e.dependent_ticket_id))};return i(),s.on(`ticket:created`,a),s.on(`ticket:updated`,o),s.on(`ticket:deleted`,c),s.on(`bundle-pull-request:updated`,u),s.on(`ticket-dependency:created`,f),s.on(`ticket-dependency:deleted`,p),()=>{t.abort(),r!==null&&window.clearTimeout(r),s.off(`ticket:created`,a),s.off(`ticket:updated`,o),s.off(`ticket:deleted`,c),s.off(`bundle-pull-request:updated`,u),s.off(`ticket-dependency:created`,f),s.off(`ticket-dependency:deleted`,p)}},[e,ne,t,re,W,H,s]),(0,p.useEffect)(()=>{if(!e)return;let t=new AbortController,n=()=>{document.visibilityState===`visible`&&Promise.allSettled([W(e,t.signal),ae(t.signal)]).then(n=>{n[0]?.status===`fulfilled`&&n[0].value!==null&&re(n[0].value)&&ne(e,t.signal)}).catch(()=>{})},r=window.setInterval(n,Eme),i=hx(n);return()=>{t.abort(),window.clearInterval(r),i()}},[e,ae,ne,re,W]),(0,p.useEffect)(()=>{if(!e||!r||y!==e)return;let t=c.filter(e=>{let t=e.bundle?.branch??e.branch;return typeof t==`string`&&t.trim()!==``}).length;r({projectId:e,ticketCount:c.length,worktreeCount:t,repoPathLocked:c.length>0||t>0||f.length>0})},[e,f.length,y,r,c]),(0,p.useEffect)(()=>{if(e)for(let t of c){let n=j.current.get(t.id),r=S8(t),i=kme(t,n);i&&!r&&O(i),!r&&n!==void 0&&n===`running`&&t.agent_status===`done`&&(t.state===`plan`||t.state===`build`||t.state===`review`)&&Ome(t,e),r||j.current.set(t.id,t.agent_status)}},[e,c]);let se=(0,p.useCallback)(()=>{v(null)},[]),ce=(0,p.useMemo)(()=>({tickets:c,setTickets:l,dependencies:u,setDependencies:d,bundles:f,setBundles:m,pendingApprovalRequests:h,setPendingApprovalRequests:g,latestDetailedTicketUpdate:_,clearLatestDetailedTicketUpdate:se,loadedProjectId:y,bundlesLoadedProjectId:x,loadingProjectId:C,activeProjectIdRef:P,pendingDeletedTicketsRef:F,pendingOptimisticMovesRef:I,pendingParkedTicketsRef:L,refreshTickets:te,requestSingleTicketRefresh:ie,refreshBundles:ae,resolvePendingTicket:H,resolvePendingTickets:U,markPendingOptimisticMoves:z,clearPendingOptimisticMoves:ee,markPendingParkedTickets:B,clearPendingParkedTickets:V,liveActivity:oe}),[f,x,se,ee,V,u,oe,y,_,C,z,B,h,ae,te,ie,H,U,c]);return(0,X.jsx)(a3.Provider,{value:ce,children:o})},w8=(e,t)=>{let n=b8(e,t.ticket.id),r=Math.max(0,Math.min(t.index,n.length));return n.splice(r,0,t.ticket),n},T8=(0,p.lazy)(()=>HW(()=>import(`./VerificationDialog-BfIKtVjt.js`).then(e=>({default:e.VerificationDialog})),__vite__mapDeps([19,3]))),E8=[`plan`,`build`,`review`],D8=`done`,jme=({activeProjectId:e,activeProject:t=null,activeProjectBranchState:n=null,activeRun:r,activeTool:i,onPreviewReviewCapabilityChange:a,onRunStopped:o,onRunStatusChange:s,onViewSourceSpec:c,onNavigateToLifecycleSource:l,onStartChatFromBundle:u,refreshKey:d=0,boardFilterState:f,onBoardFilterStateChange:m,initialTicketId:h=null,onInitialTicketNavigationConsumed:g,onInitialTicketNavigationUnavailable:_,routedTicketId:v,routedModalStack:y=[],onTicketOpen:b,onTicketClose:x,routedBundleId:S,routedInspection:C=null,routedInspectionReviewCapability:w,inspectionOnly:T=!1,onBundleOpen:E,onBundleClose:D,onInspectionOpen:O,onInspectionModeChange:k,onInspectionClose:A,onInspectionUnavailable:j,initialImportedDraft:M=null,onInitialImportedDraftConsumed:N,onOpenProjectExecutionSettings:P})=>{let{t:F}=q(`common`),I=roe(noe(bP,{activationConstraint:{distance:5}})),{tickets:L,setTickets:R,dependencies:z,setDependencies:ee,bundles:B,setBundles:V,latestDetailedTicketUpdate:H,clearLatestDetailedTicketUpdate:U,loadedProjectId:W,bundlesLoadedProjectId:te,loadingProjectId:ne,activeProjectIdRef:re,pendingDeletedTicketsRef:ie,requestSingleTicketRefresh:ae,refreshBundles:G,resolvePendingTicket:oe,markPendingOptimisticMoves:se,clearPendingOptimisticMoves:ce,markPendingParkedTickets:le,clearPendingParkedTickets:ue}=o3(),{runs:de}=f8(e),fe=(0,p.useMemo)(()=>{let e=pme(de);for(let t of L)t.worktree_bundle_id&&t.automation_paused_reason&&e.delete(t.worktree_bundle_id);return e},[de,L]),[pe,me]=(0,p.useState)(null),[he,ge]=(0,p.useState)(null),[_e,ve]=(0,p.useState)(null),ye=(0,p.useCallback)(e=>ve(e),[]),[be,xe]=(0,p.useState)(null),[Se,Ce]=(0,p.useState)({x:0,y:0}),[we,Te]=(0,p.useState)(null),[Ee,De]=(0,p.useState)([]),[Oe,ke]=(0,p.useState)(null),Ae=QP(`opencode`),je=QP(`claude`),Me=(0,p.useMemo)(()=>({opencode:Ae.models,claude:je.models}),[Ae.models,je.models]),Ne={opencode:Ae.isLoading,claude:je.isLoading},Pe=(0,p.useCallback)(e=>{let n=Me[e]??[];return t?.build_execution_provider===`docker_sandbox`?LT(n,Oe?Oe.approved_providers?.[e]??[]:[]):n},[t?.build_execution_provider,Oe,Me]),Fe=(0,p.useMemo)(()=>({opencode:Pe(`opencode`),claude:Pe(`claude`)}),[Pe]);(0,p.useEffect)(()=>{if(!e||t?.build_execution_provider!==`docker_sandbox`){ke(null);return}let n=new AbortController;return ke(null),Yb(e,n.signal).then(e=>{n.signal.aborted||ke(e)}).catch(e=>{!Ye(e)&&!n.signal.aborted&&ke(null)}),()=>n.abort()},[t?.build_execution_provider,e]);let Ie=(0,p.useMemo)(()=>{if(t?.build_execution_provider!==`docker_sandbox`)return Ee;let e=Oe?.available_skills?.opencode;if(!e)return[];let n=new Map(Ee.map(e=>[e.name,e]));return e.map(e=>n.get(e)??{name:e,description:``})},[t?.build_execution_provider,Ee,Oe?.available_skills?.opencode]),[Le,K]=(0,p.useState)(!1),[Re,ze]=(0,p.useState)(!1),[Be,Ve]=(0,p.useState)(!1),[He,Ue]=(0,p.useState)(null),[We,Ke]=(0,p.useState)(null),[J,qe]=(0,p.useState)(null),Je=(0,p.useRef)(null),Xe=v===void 0?h:v,Ze=(0,p.useRef)(null),Y=(0,p.useRef)(null),[Qe,$e]=(0,p.useState)(null),et=(0,p.useRef)(null),[tt,nt]=(0,p.useState)(null),[rt,it]=(0,p.useState)(null),[at,ot]=(0,p.useState)(null),[st,ct]=(0,p.useState)(null),lt=(0,p.useRef)(0),[ut,dt]=(0,p.useState)(null),[ft,pt]=(0,p.useState)(null),[mt,ht]=(0,p.useState)(null),[gt,vt]=(0,p.useState)(!1),[yt,St]=(0,p.useState)(o8()),[Ct,wt]=(0,p.useState)(0),[At,jt]=(0,p.useState)(()=>({query:``,hideStaleTickets:!1,hideBundlesWithPullRequests:!1})),Mt=f??At,zt=e=>{let t={...Mt,...e};if(m){m(t);return}jt(t)},Bt=bF(i)||bF(J?.tool)||!!rt?.tickets.some(e=>bF(yF(e,i))),Vt=bF(i)&&(Pe(i).length>0||t?.build_execution_provider===`docker_sandbox`&&Me[i].length>0),Ht=bF(yF(J,i))&&Pe(yF(J,i)).length>0,Ut=!!rt?.tickets.some(e=>bF(yF(e,i)))&&(Fe.opencode.length>0||Fe.claude.length>0),Wt=(0,p.useRef)(null),[Gt,Kt]=(0,p.useState)(null),qt=L.find(e=>e.is_running)??null,Jt=qt?sy(qt):null,Yt=r?.context_key??null,Xt=r?.kind===`ticket`?cy(r,L)??Jt:Jt,Zt=r?.kind===`project`,Qt=Xt??Gt,$t=(0,p.useCallback)(e=>ly({bundleId:e,activeRunContextKey:Qt,isProjectRootRunActive:Zt}),[Qt,Zt]),en=pe!==null&&ky(pe,`trash`)||he!==null&&Cy(he),tn=ne===e,nn=(0,p.useMemo)(()=>t?KC(t):[],[t]),rn=(0,p.useMemo)(()=>YC(nn),[nn]),an=(0,p.useMemo)(()=>t?qC(t):[],[t]),on=(0,p.useMemo)(()=>t?JC(t):[],[t]),sn=rn.length>0,ln=(0,p.useMemo)(()=>new Map(L.map(e=>[e.id,e])),[L]);(0,p.useEffect)(()=>{Kt(null)},[e]),(0,p.useEffect)(()=>{Gt!==null&&(Zt||Xt!==null)&&Kt(null)},[Xt,Zt,Gt]),(0,p.useEffect)(()=>{if(!We){qe(null);return}let e=ln.get(We)??null;e&&qe(t=>!t||t.id!==We?e:dy(t,e))},[We,ln]),(0,p.useEffect)(()=>{H&&(qe(e=>!e||e.id!==H.id?e:dy(e,H)),it(e=>{if(!e)return e;let t=H.worktree_bundle_id;if(!t||e.bundle.id!==t)return e;let n=e.tickets.some(e=>e.id===H.id)?e.tickets.map(e=>e.id===H.id?dy(e,H):e):[...e.tickets,H];return{...e,tickets:n}}))},[H]),(0,p.useEffect)(()=>{H===null||We!==null||Qe!==null||U()},[U,H,Qe,We]);let dn=(0,p.useCallback)(async e=>{let t=await ae(e);if(!t)return null;let n=ln.get(e),r=n?dy(t,n):t;return qe(t=>t&&t.id!==e||We&&We!==e?t:r),r},[ae,We,ln]),fn=(0,p.useCallback)(e=>{qe(e),Ke(e.id),dn(e.id),b?.(e.id)},[b,dn]),pn=(0,p.useCallback)(()=>{et.current=null,$e(null),nt(null),it(null),vt(!1),St(o8())},[]),mn=(0,p.useMemo)(()=>new Map(B.map(e=>[e.id,e])),[B]),hn=(0,p.useMemo)(()=>{if(!rt)return null;let e=rt.bundle.id,t=H?.worktree_bundle_id===e?H:null,n=L.filter(t=>t.worktree_bundle_id===e),r=new Map(n.map(e=>[e.id,e])),i=rt.tickets.filter(e=>!ie.current.has(e.id)).map(e=>t&&e.id===t.id?dy(e,t):e);t&&!i.some(e=>e.id===t.id)&&!ie.current.has(t.id)&&i.push(t);let a=i.map(e=>dy(e,r.get(e.id)));for(let e of n)a.some(t=>t.id===e.id)||a.push(e);a=C3(a);let o=rt.execution_order_ticket_ids??[],s=a.map(e=>e.id),c=[...o,...s].filter((e,t,n)=>s.includes(e)&&n.indexOf(e)===t),l=n.some(e=>e.can_re_review!==void 0||e.has_completed_review!==void 0||e.has_follow_up_since_last_review!==void 0),u=n.some(e=>e.agent_status===`running`),d={has_completed_review:n.some(e=>e.has_completed_review===!0),has_follow_up_since_last_review:n.some(e=>e.has_follow_up_since_last_review===!0),can_re_review:!u&&n.some(e=>e.can_re_review===!0)},f=Iy(a),p=a.find(e=>e.id===rt.review_owner_ticket_id&&e.state===`review`)??null,m=Vy(a,{targetTicketId:rt.target_ticket_id,reviewOwnerTicketId:p?.id??rt.review_owner_ticket_id,latestSessionTicketId:f?.id??rt.latest_session_ticket_id});return{...rt,bundle:mn.get(e)??rt.bundle,tickets:a,execution_order_ticket_ids:c,latest_session_ticket_id:f?.id??null,latest_session_id:f?.session_id??null,review_owner_ticket_id:p?.id??null,target_ticket_id:m?.id??null,has_completed_review:l?d.has_completed_review:rt.has_completed_review,has_follow_up_since_last_review:l?d.has_follow_up_since_last_review:rt.has_follow_up_since_last_review,can_re_review:l?d.can_re_review:rt.can_re_review}},[mn,H,ie,rt,L]),gn=(0,p.useMemo)(()=>L.filter(e=>{if(Mt.hideStaleTickets&&vy(e))return!1;if(Mt.hideBundlesWithPullRequests&&e.worktree_bundle_id){let t=mn.get(e.worktree_bundle_id);if(t&&t.pull_request!==void 0?t.pull_request:e.bundle?.pull_request)return!1}return py(Mt.query,e)}),[Mt,mn,L]),_n=(0,p.useMemo)(()=>Wy(gn),[gn]),vn=(0,p.useMemo)(()=>gn.filter(e=>gy(e)),[gn]),yn=(0,p.useMemo)(()=>Hy(vn,B,D8),[B,vn]),{boardViewportRef:Fn,boardContentRef:Ln,registerTicketNode:Bn,registerDependencyClipNodes:Vn,measuredCardRects:Hn,dependencyClipRects:Un,overlayPreview:Wn,overlaySize:Gn,getDependencyTargetState:Kn,handleDependencyStart:qn,handleDeleteDependency:Jn}=ime({activeProjectId:e,tickets:L,dependencies:z,setDependencies:ee,activeTicket:pe,activeOverlayNode:be,dragOffset:Se}),Yn=gme(),Xn=!!t?.run_ide?.trim(),Zn=(0,p.useCallback)((e,t,n=L)=>{let r=Hy(n,B,t).find(t=>t.kind===`bundle`&&t.group.bundle.id===e);return r?.kind===`bundle`?r.group:null},[B,L]),Qn=(0,p.useCallback)(e=>{let n=yF(e,i);return(0,X.jsx)(h3,{ticket:e,allTickets:L,dependencies:z,bundles:B,projectMemoryEnabled:!!t?.memory_enabled,automationStatus:e.worktree_bundle_id?fe.get(e.worktree_bundle_id):null,overlay:!0,activeTool:i,showModelSelector:bF(n)&&Pe(n).length>0,availableModels:Pe(n),runDisabled:!0,hideBundleScopedControls:!0})},[t?.memory_enabled,i,fe,B,z,Pe,L]),$n=(0,p.useCallback)(t=>zy(t)?t.project_id===e?Xn:!!t.has_run_ide:!1,[Xn,e]),er=(0,p.useCallback)(e=>!!e.project_id&&!!(e.bundle?.branch??e.branch)&&zy(e),[]),tr=(0,p.useCallback)(e=>{let t=e?.tickets.find(t=>t.id===e.target_ticket_id)??e?.tickets.find(e=>e.has_worktree)??null;return t?$n(t):!1},[$n]),nr=(0,p.useCallback)(e=>{let t=C3(L.filter(t=>t.worktree_bundle_id===e));return rt?.bundle.id===e?s8(C3(rt.tickets.map(e=>t.find(t=>t.id===e.id)??e)),{targetTicketId:rt.target_ticket_id,reviewOwnerTicketId:rt.review_owner_ticket_id,latestSessionTicketId:rt.latest_session_ticket_id}):s8(t)},[rt,L]),rr=(0,p.useCallback)(e=>{let t=nr(e),n=B.some(t=>t.id===e&&t.has_prepared_worktree===!0)||L.some(t=>t.worktree_bundle_id===e&&zy(t))||!!(rt?.bundle.id===e&&rt.tickets.some(zy));return!!(t?.project_id&&(t.bundle?.branch??t.branch)&&n)},[B,nr,rt,L]),ir=(0,p.useCallback)(e=>{let t=mn.get(e),n=nr(e),r=rt?.bundle.id===e?[...L,...rt.tickets]:L;return!!(t&&n?.project_id&&By(t,r))},[mn,nr,rt,L]);(0,p.useEffect)(()=>{ze(!1),Ve(!1),dt(null),ht(null)},[e,d]),(0,p.useEffect)(()=>{if(!Bt){De([]);return}let t=new AbortController;return(async()=>{try{De(await $P(`opencode`,t.signal,e))}catch(e){Ye(e)||De([])}})(),()=>{t.abort()}},[e,Bt]);let ar=({active:e})=>{K(!1),xe(null),Ce({x:0,y:0}),ve(null);let t=Gy(String(e.id));if(t){ge(Zn(t.bundleId,t.column)),me(null);return}ge(null),me(L.find(t=>t.id===e.id)??null)},or=()=>{K(!1),xe(null),Ce({x:0,y:0}),me(null),ge(null),ve(null)},sr=(0,p.useCallback)(e=>{R(t=>e.reduce((e,t)=>y8(e,t),t))},[R]),cr=(0,p.useCallback)((e,t)=>{if(e.length===0)return;let n=e[0]?.state;n&&R(r=>e.reduce((e,r)=>x8(e,r.id,t,Oy(r,n,t)),r))},[R]),lr=(0,p.useCallback)((e,t=L)=>!e.worktree_bundle_id||!e.project_id||e.state!==`build`?[]:C3(t.filter(t=>t.project_id===e.project_id&&t.worktree_bundle_id===e.worktree_bundle_id&&t.state===`build`&&t.parked_at===null)),[L]),ur=async({active:e,over:t})=>{let n=Gy(String(e.id)),r=L.find(t=>t.id===e.id),i=n?Zn(n.bundleId,n.column):null,a=t?.id===`trash`&&(r!==void 0&&ky(r,`trash`)||i!==null&&Cy(i)),o=t?.id&&E8.includes(t.id)?t.id:null;if(K(a),xe(null),Ce({x:0,y:0}),me(null),ge(null),t){if(n){if(t.id===`trash`){if(!i||!Cy(i))return;await Sr(i);return}if(t.id===D8){if(!i||!wy(i))return;await yr(i);return}if(o){if(n.column===D8){if(!i||!Ty(i))return;await br(i);return}await ui(n.bundleId,n.column,o)}return}if(t.id===`trash`){if(!r||!ky(r,`trash`))return;wr(e.id);return}if(t.id===D8){if(!r||!ky(r,D8))return;await _r(e.id);return}if(o){if(r&&Sy(r,o)){await vr(e.id);return}if(!(!r||!ky(r,o)))try{await hr(r,o,{optimistic:!0})}catch(e){$.error(e instanceof Ge?e.message:F(`board.errors.moveTicket`),{id:`board-move-error`})}}}},dr=async(t,n,r,i,a,o,s)=>{let c=await cn({title:t,description:n,model:i,variant:a,skills:o,project_id:e,...s});if(hme(i,a,o),R(e=>y8(e,p8(c))),c.bundle&&V(e=>_8(e,c.bundle)),r===`build`)try{await hr(c,`build`)}catch(e){$.error(e instanceof Ge?e.message:F(`board.errors.moveTicket`),{id:`board-move-error`})}r===`plan`&&zn(c.id,c.project_id)},fr=async t=>{if(!e)throw Error(F(`board.errors.createBundleWithoutProject`));let n=await _t(e,{name:t,prepare:!0});return V(e=>_8(e,n)),n},pr=(0,p.useCallback)((e,t={})=>{let n=p8(e);R(e=>t.reorderInState?y8(e,n):v8(e,n)),qe(t=>!t||t.id!==e.id?t:dy(e,n)),e.bundle&&V(t=>_8(t,e.bundle))},[V,R]),mr=(0,p.useCallback)(e=>{V(t=>_8(t,e)),R(t=>t.map(t=>t.worktree_bundle_id===e.id?{...t,bundle:e}:t)),it(t=>!t||t.bundle.id!==e.id?t:{...t,bundle:e,tickets:t.tickets.map(t=>t.worktree_bundle_id===e.id?{...t,bundle:e}:t)})},[V,it,R]),hr=async(e,t,n={})=>{let r=L.findIndex(t=>t.id===e.id),i=t===`review`?lr(e):[],a=t===`review`&&i.length>1,o=n.optimistic?a?i.map(e=>e.id):[e.id]:[];n.optimistic&&(se(o,t),a?cr(i,t):R(n=>x8(n,e.id,t,Ey(e,t))));try{if(a&&e.project_id&&e.worktree_bundle_id){let t=await Et(e.project_id,e.worktree_bundle_id);Wr(t);let n=t.tickets.find(t=>t.id===e.id);if(!n)throw Error(F(`board.errors.missingBundleReviewTicket`));return ce(o),n}let n=await un(e.id,e.project_id,t);return R(r=>{let i=r.find(t=>t.id===e.id);return i?.state===t&&n.state===t&&i.agent_status!==n.agent_status&&n.agent_status===e.agent_status?r:m8(i,n)?y8(r,n):v8(r,n)}),n.bundle&&V(e=>_8(e,n.bundle)),ce(o),n}catch(t){throw n.optimistic&&(a?sr(i):R(t=>x8(t,e.id,e.state,{agent_status:e.agent_status,agent_log:e.agent_log,build_completed_at:e.build_completed_at},{preferredIndex:r})),ce(o)),t}},gr=(e,t)=>{R(n=>n.map(n=>n.id===e?{...n,...t}:n))},_r=async t=>{let n=L.find(e=>e.id===t);if(n)try{let r=new Date().toISOString();le([t],r),gr(t,{parked_at:r}),pr(await wn(t,n.project_id??e),{reorderInState:!0}),ue([t])}catch(e){ue([t]),gr(t,{parked_at:n.parked_at}),$.error(e instanceof Ge?e.message:F(`board.errors.parkTicket`),{id:`board-park-error`})}},vr=async t=>{let n=L.find(e=>e.id===t);if(n)try{le([t],null),gr(t,{parked_at:null}),pr(await Tn(t,n.project_id??e),{reorderInState:!0}),ue([t])}catch(e){ue([t]),gr(t,{parked_at:n.parked_at}),$.error(e instanceof Ge?e.message:F(`board.errors.returnTicket`),{id:`board-unpark-error`})}},yr=(0,p.useCallback)(async e=>{let t=new Set(e.tickets.map(e=>e.id)),n=e.tickets.map(e=>({id:e.id,parked_at:e.parked_at})),r=new Date().toISOString();le(e.tickets.map(e=>e.id),r),R(e=>e.map(e=>t.has(e.id)?{...e,parked_at:r}:e));let i=await Promise.allSettled(e.tickets.map(e=>wn(e.id,e.project_id??re.current))),a=new Set;if(i.forEach((t,n)=>{if(t.status===`fulfilled`){ue([t.value.id]),pr(t.value,{reorderInState:!0});return}let r=e.tickets[n];r&&a.add(r.id)}),a.size===0)return;ue([...a]),R(e=>e.map(e=>{if(!a.has(e.id))return e;let t=n.find(t=>t.id===e.id);return t?{...e,parked_at:t.parked_at}:e}));let o=i.find(e=>e.status===`rejected`),s=a.size===e.tickets.length?o?.reason instanceof Ge?o.reason.message:F(`board.errors.moveBundleToDone`):F(`board.toasts.movedBundleToDonePartial`,{movedCount:e.tickets.length-a.size,totalCount:e.tickets.length});$.error(s,{id:`board-bundle-park-error`})},[re,pr,ue,le,R,F]),br=(0,p.useCallback)(async e=>{let t=new Set(e.tickets.map(e=>e.id)),n=e.tickets.map(e=>({id:e.id,parked_at:e.parked_at}));le(e.tickets.map(e=>e.id),null),R(e=>e.map(e=>t.has(e.id)?{...e,parked_at:null}:e));let r=await Promise.allSettled(e.tickets.map(e=>Tn(e.id,e.project_id??re.current))),i=new Set;if(r.forEach((t,n)=>{if(t.status===`fulfilled`){ue([t.value.id]),pr(t.value,{reorderInState:!0});return}let r=e.tickets[n];r&&i.add(r.id)}),i.size===0)return;ue([...i]),R(e=>e.map(e=>{if(!i.has(e.id))return e;let t=n.find(t=>t.id===e.id);return t?{...e,parked_at:t.parked_at}:e}));let a=r.find(e=>e.status===`rejected`),o=i.size===e.tickets.length?a?.reason instanceof Ge?a.reason.message:F(`board.errors.restoreBundle`):F(`board.toasts.restoredBundlePartial`,{restoredCount:e.tickets.length-i.size,totalCount:e.tickets.length});$.error(o,{id:`board-bundle-unpark-error`})},[re,pr,ue,le,R,F]),xr=async t=>{if(!e)return;let n=await Ft(e,t);n.warning&&$.warning(n.warning,{id:`board-bundle-delete-warning`}),V(e=>e.filter(e=>e.id!==t))},Sr=(0,p.useCallback)(async t=>{let n=t.tickets.map(e=>({ticket:e,index:L.findIndex(t=>t.id===e.id)})).filter(e=>e.index!==-1);if(n.length===0)return;for(let e of n)ie.current.set(e.ticket.id,e);let r=new Set(n.map(e=>e.ticket.id));R(e=>e.filter(e=>!r.has(e.id))),ee(e=>e.filter(e=>!r.has(e.blocker_ticket_id)&&!r.has(e.dependent_ticket_id)));let i=await Promise.allSettled(n.map(async t=>(await Sn(t.ticket.id,t.ticket.project_id??e),ie.current.delete(t.ticket.id),t.ticket.id)));t.tickets.some(e=>e.project_id===re.current)&&G().catch(()=>{});let a=n.filter((e,t)=>i[t]?.status===`rejected`);if(a.length===0)return;for(let e of a)ie.current.delete(e.ticket.id);a.some(e=>e.ticket.project_id===re.current)&&R(e=>[...a].sort((e,t)=>e.index-t.index).reduce((e,t)=>w8(e,t),e));let o=i.find(e=>e.status===`rejected`),s=a.length===n.length?o?.reason instanceof Ge?o.reason.message:F(`board.errors.deleteBundleTickets`):F(`board.toasts.deletedBundleTicketsPartial`,{deletedCount:n.length-a.length,totalCount:n.length});$.error(s,{id:`board-delete-bundle-wrapper-error`})},[e,re,ie,G,ee,R,L,F]),Cr=e=>{let t=ln.get(e.id);pr(e,{reorderInState:t?t.state!==e.state||t.parked_at!==e.parked_at||t.worktree_bundle_id!==e.worktree_bundle_id:!1}),t?.worktree_bundle_id&&t.worktree_bundle_id!==e.worktree_bundle_id&&t.bundle?.ticket_count===1&&V(e=>e.filter(e=>e.id!==t.worktree_bundle_id)),(t?.worktree_bundle_id!==e.worktree_bundle_id||t?.bundle?.ticket_count!==e.bundle?.ticket_count)&&e.project_id===re.current&&G().catch(()=>{})},wr=async t=>{let n=L.find(e=>e.id===t),r=L.findIndex(e=>e.id===t);if(!(!n||r===-1)){ie.current.set(t,{ticket:n,index:r}),R(e=>b8(e,t)),ee(e=>Uv(e,t));try{await Sn(t,n.project_id??e),n.project_id===re.current&&G().catch(()=>{}),ie.current.delete(t)}catch(e){let n=ie.current.get(t);ie.current.delete(t),n&&n.ticket.project_id===re.current&&(R(e=>w8(e,n)),$.error(e instanceof Ge?e.message:F(`board.errors.deleteTicket`),{id:`board-delete-error`}))}}},Tr=async t=>{let n=L.find(e=>e.id===t);if(!n)return;let r=n.state===`review`?`review`:`build`;try{if(Ue(r),n.project_id&&n.worktree_bundle_id&&n.state===`review`){Wr(await Ot(n.project_id,n.worktree_bundle_id));return}pr(await Cn(t,n.project_id??e),{reorderInState:!0})}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.undoTicket`),{id:`board-undo-error`}),e}finally{Ue(e=>e===r?null:e)}},Er=async t=>{let n=L.find(e=>e.id===t);try{await Dn(t,n?.project_id??e)}catch(e){$.error(e instanceof Ge?e.message:F(`board.errors.retryTicket`),{id:`board-retry-error`})}},Dr=async t=>{let n=L.find(e=>e.id===t),r=n?sy(n):t;try{Kt(r),await On(t,n?.project_id??e),s?.()}catch(e){Kt(e=>e===r?null:e),$.error(e instanceof Ge?e.message:F(`board.errors.startRun`),{id:`board-run-error`})}},Or=(0,p.useCallback)(async t=>{let n=L.find(e=>e.id===t);try{await kn(t,n?.project_id??e)}catch(e){$.error(e instanceof Ge?e.message:F(`board.errors.openIde`),{id:`board-open-ide-error`})}},[e,F,L]),kr=async t=>{let n=L.find(e=>e.id===t),i=r?.kind===`ticket`&&n&&Xt===sy(n)?Yt:null;try{await An(t,n?.project_id??e),o?.(i),s?.()}catch{}},Ar=t=>{jn(t,L.find(e=>e.id===t)?.project_id??e).then(()=>{R(e=>e.map(e=>e.id===t?{...e,agent_status:`stopped`,is_running:!1}:e))})},jr=async t=>{let n=L.find(e=>e.id===t);try{await Mn(t,n?.project_id??e)}catch(e){$.error(e instanceof Error?e.message:F(`reviewInterrupt.error`))}},Mr=t=>{Nn(t,L.find(e=>e.id===t)?.project_id??e).then(()=>{R(e=>e.map(e=>e.id===t?{...e,agent_status:`running`}:e))})},Nr=(0,p.useCallback)(e=>{let t=nr(e);!t||!$n(t)||Or(t.id)},[$n,nr,Or]),Pr=(0,p.useCallback)((e,t)=>{let n=nr(e),r=t===`files`?ir(e):rr(e);if(!(!n||!r)){if(O){O({kind:`bundle`,bundleId:e},t);return}pt({target:{kind:`bundle`,bundleId:e,ticketId:n.id},projectId:n.project_id,title:n.bundle?Jy(n.bundle):n.title,bundleTargetName:n.bundle&&Jy(n.bundle)||null,initialMode:t,followUpMode:`build`})}},[ir,rr,nr,O]),Fr=(0,p.useCallback)((e,t)=>{let n=nr(e);if(!n?.project_id||!zy(n))return;let r=n.latest_check_gate_evaluation?.id??L.find(t=>t.worktree_bundle_id===e&&t.latest_check_gate_evaluation)?.latest_check_gate_evaluation?.id??null;if(nn.length===0&&!r)return;let i=B.find(t=>t.id===e)??n.bundle;i&&ht({bundleId:e,label:Jy(i),requestedInitialTab:t,gateEvaluationId:r,requiredCheckPolicy:i.required_check_policy??null})},[B,nr,nn.length,L]),Ir=(0,p.useCallback)((e,t)=>{let n=L.find(t=>t.id===e);if(!(!n||!er(n))){if(O){O({kind:`ticket`,ticketId:e},t);return}pt({target:{kind:`ticket`,ticketId:n.id},projectId:n.project_id,title:n.title,bundleTargetName:null,initialMode:t,followUpMode:`build`})}},[er,O,L]),Lr=(0,p.useCallback)(e=>Pr(e,`files`),[Pr]),Rr=(0,p.useCallback)(e=>Pr(e,`changes`),[Pr]),zr=(0,p.useCallback)(e=>Ir(e,`files`),[Ir]),Br=(0,p.useCallback)(e=>Ir(e,`changes`),[Ir]),Vr=(0,p.useCallback)(e=>{let t=L.find(t=>t.id===e);!t?.project_id||!zy(t)||dt({ticketId:t.id,label:t.title})},[L]),Hr=(0,p.useCallback)(async(t,n,r=`build`,i)=>{let a=L.find(e=>e.id===t);if(a)try{pr(a.state===`plan`?await Rn(t,a.project_id??e,n):await Pn(t,a.project_id??e,n,r,i))}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.sendFollowUp`),{id:`board-follow-up-error`}),e}},[e,pr,F,L]),Ur=(0,p.useCallback)(e=>{R(t=>e.reduce((e,t)=>{let n=e.find(e=>e.id===t.id),r=oe(n,t);if(!r)return e;let i=p8(n&&n.state===r.state&&n.agent_status===`running`&&r.agent_status===null?{...r,agent_status:n.agent_status,session_id:n.session_id,is_running:n.is_running}:r);return m8(n,i)?y8(e,i):v8(e,i)},t))},[oe,R]),Wr=(0,p.useCallback)(e=>{it(e),V(t=>_8(t,e.bundle)),Ur(e.tickets)},[Ur,V]),Gr=(0,p.useCallback)((e,t)=>{Array.isArray(t.tickets)&&it(n=>{if(!n||n.bundle.id!==e)return n;let r=fy(n.tickets,t.tickets),i=n.tickets.find(e=>e.id===n.review_owner_ticket_id&&e.state===`review`&&e.agent_status===`running`&&e.updated_at>=(t.tickets.find(t=>t.id===e.id)?.updated_at??``))??null;return{...n,tickets:r,execution_order_ticket_ids:t.execution_order_ticket_ids,latest_session_ticket_id:t.latest_session_ticket_id,latest_session_id:t.latest_session_id,review_owner_ticket_id:t.review_owner_ticket_id??i?.id??null,target_ticket_id:i?.id??t.target_ticket_id}})},[]),Kr=(0,p.useCallback)(async e=>{let t=re.current;if(!t)return null;let n=await bt(t,e);return re.current!==t||et.current!==e?null:(Wr(n),n)},[re,Wr]),qr=(0,p.useCallback)(async()=>{let e=st?.bundle.id,t=re.current;if(!e||!t)return null;let n=++lt.current,r=await bt(t,e);return n!==lt.current||re.current!==t?null:(Wr(r),ct(r),r)},[re,Wr,st?.bundle.id]),Jr=(0,p.useCallback)(async t=>{if(!e)return;ot(t),ct(null);let n=++lt.current;try{let r=await bt(e,t);if(re.current!==e||n!==lt.current)return;Wr(r),ct(r)}catch{if(n!==lt.current||re.current!==e)return;ot(null),$.error(F(`buildOpenQuestionsDialog.refreshFailedError`),{id:`board-build-open-questions-load-error`})}},[e,re,Wr,F]),Yr=(0,p.useCallback)(async t=>{let n=st?.bundle.id;if(!e||!n)return;let r=++lt.current;await Rt(e,n,t),r===lt.current&&(ot(null),ct(null))},[e,st?.bundle.id]),Xr=st?.bundle.id??null;(0,p.useEffect)(()=>{if(!Xr)return;let e=new Map(L.map(e=>[e.id,e])),t=B.find(e=>e.id===Xr);ct(n=>!n||n.bundle.id!==Xr?n:{...n,bundle:t?{...n.bundle,...t}:n.bundle,tickets:n.tickets.map(t=>{let n=e.get(t.id);return n?{...t,...n}:t})})},[B,Xr,L]);let Zr=(0,p.useCallback)(async e=>{let t=re.current;if(!t)return null;let n=await xt(t,e);return re.current!==t||et.current!==e?null:(Gr(e,n),n)},[re,Gr]),Qr=(0,p.useCallback)(async(e,t=null)=>{let n=re.current;if(!n)return;et.current=e,Ke(null),qe(null),$e(e),nt(t),St(o8());let r=mn.get(e)??null,i=L.filter(t=>t.worktree_bundle_id===e);if(r&&i.length>0){let e=Iy(i),t=Vy(i,{latestSessionTicketId:e?.id??null});it({bundle:r,tickets:i,latest_session_ticket_id:e?.id??null,latest_session_id:e?.session_id??null,review_owner_ticket_id:null,target_ticket_id:t?.id??null})}else it(null);vt(!0);try{await Zr(e)}catch(t){if(t instanceof Ge&&t.status===404&&S===e){pn(),j?.();return}}finally{re.current===n&&vt(!1)}},[re,mn,pn,j,Zr,S,L]),$r=(0,p.useCallback)((e,t=null)=>{Qr(e,t),E?.(e)},[E,Qr]),ei=(0,p.useCallback)(async(e,t)=>{St(t=>({...t,[e]:!0}));try{return await t()}finally{St(t=>({...t,[e]:!1}))}},[]),ti=(0,p.useCallback)(async t=>{await ei(`stopBuild`,async()=>{let n=L.find(e=>e.id===t);await jn(t,n?.project_id??e),R(e=>e.map(e=>e.id===t?{...e,agent_status:`stopped`,is_running:!1}:e)),n?.worktree_bundle_id&&await Kr(n.worktree_bundle_id)})},[e,Kr,ei,R,L]),ni=(0,p.useCallback)(async t=>{await ei(`stopBuild`,async()=>{let n=L.find(e=>e.id===t);try{await Mn(t,n?.project_id??e)}catch(e){$.error(e instanceof Error?e.message:F(`reviewInterrupt.error`))}})},[e,ei,F,L]),ri=(0,p.useCallback)(async t=>{await ei(`resumeBuild`,async()=>{let n=L.find(e=>e.id===t);await Nn(t,n?.project_id??e),R(e=>e.map(e=>e.id===t?{...e,agent_status:`running`}:e)),n?.worktree_bundle_id&&await Kr(n.worktree_bundle_id)})},[e,Kr,ei,R,L]),ii=(0,p.useCallback)(async t=>{if(e)try{Wr(await ei(`build`,()=>Tt(e,t))),Qe===t&&nt(`build`),s?.()}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.buildBundle`),{id:`board-bundle-build-error`}),e}},[e,Wr,s,ei,Qe,F]),ai=(0,p.useCallback)(async t=>{if(e)try{Wr(await ei(`review`,()=>Et(e,t))),Qe===t&&nt(`review`)}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.reviewBundle`),{id:`board-bundle-review-error`}),e}},[e,Wr,ei,Qe,F]),oi=(0,p.useCallback)(async t=>{if(e)try{Wr(await ei(`review`,()=>Dt(e,t))),Qe===t&&nt(`review`)}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.continueBundleReview`),{id:`board-bundle-continue-review-error`}),e}},[e,Wr,ei,Qe,F]),si=(0,p.useCallback)(async t=>{if(e)try{Ue(`review`),Wr(await ei(`undoReview`,()=>Ot(e,t))),Qe===t&&nt(`build`)}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.undoBundleReview`),{id:`board-bundle-undo-review-error`}),e}finally{Ue(e=>e===`review`?null:e)}},[e,Wr,ei,Qe,F]),ci=(0,p.useCallback)(async t=>{if(e)try{Wr(await It(e,t))}catch(e){$.error(e instanceof Ge?e.message:`Unable to resume the automation right now.`,{id:`board-bundle-resume-automation-error`})}},[e,Wr]),li=(0,p.useCallback)(async t=>{if(e)try{Wr(await Lt(e,t))}catch(e){$.error(e instanceof Ge?e.message:`Unable to dismiss the automation pause right now.`,{id:`board-bundle-dismiss-automation-error`})}},[e,Wr]),ui=(0,p.useCallback)(async(e,t,n)=>{if(t===D8||n===D8)return;let r=Dy(t,n);if(!r)return;let i=L.filter(n=>n.worktree_bundle_id===e&&n.state===t&&n.parked_at===null);if(i.length===0)return;let a=i.map(e=>e.id);se(a,n),cr(i,n);try{if(r===`build`){await ii(e),ce(a);return}if(r===`review`){await ai(e),ce(a);return}await si(e),ce(a)}catch(e){sr(i),ce(a),$.error(e instanceof Ge?e.message:F(`board.errors.moveBundle`),{id:`board-bundle-move-error`})}},[ce,ii,ai,si,se,cr,sr,L,F]),di=async t=>{e&&(Wr(await ei(`run`,()=>Nt(e,t))),s?.())},fi=async t=>{if(!e)return;let n=r?.kind===`ticket`&&Xt===t?Yt:null,i=await ei(`stop`,()=>Pt(e,t));o?.(n),Wr(i),s?.()},pi=(0,p.useCallback)(async(t,n,r=`build`,i)=>{e&&Wr(await ei(`followUp`,()=>kt(e,t,n,r,i)))},[e,Wr,ei]);(0,p.useEffect)(()=>()=>{a?.(null)},[a]),(0,p.useEffect)(()=>{if(!a)return;if(!r){a(null);return}if(r.kind===`project`){a({target:null,canSelect:!1,disabledReason:F(`board.preview.disabledProjectRoot`),submitPrompt:null});return}let e=L.find(e=>e.id===r.ticket_id);if(!e){a({target:null,canSelect:!1,disabledReason:F(`board.preview.disabledBuildCapable`),submitPrompt:null});return}if(e.state===`plan`){a({target:{kind:`ticket`,id:e.id},canSelect:!1,disabledReason:F(`board.preview.disabledPlanMode`),submitPrompt:null});return}if(e.worktree_bundle_id){a({target:{kind:`bundle`,id:e.worktree_bundle_id,ticket_id:e.id},canSelect:!0,disabledReason:null,promptPlaceholder:F(`board.preview.followUpBundlePlaceholder`),submitPrompt:t=>pi(e.worktree_bundle_id,t)});return}a({target:{kind:`ticket`,id:e.id},canSelect:!0,disabledReason:null,promptPlaceholder:F(`board.preview.followUpTicketPlaceholder`),submitPrompt:t=>Hr(e.id,t)})},[r,Hr,pi,a,F,L]);let mi=async t=>{let n=L.find(e=>e.id===t),r=n?ay(n.state):null;if(n)try{if(n.state===`review`&&n.can_re_review&&n.agent_status!==`running`){let t=await In(n.id,n.project_id??e);pr(t),t.worktree_bundle_id&&await Kr(t.worktree_bundle_id);return}if(!r)return;if(n.worktree_bundle_id&&r===`review`){await ai(n.worktree_bundle_id);return}await hr(n,r)}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.moveTicket`),{id:`board-move-error`}),e}},hi=async t=>{let n=L.find(e=>e.id===t);try{pr(await bn(t,n?.project_id??e))}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.startBuildChain`),{id:`board-build-chain-error`}),e}},gi=async t=>{let n=L.find(e=>e.id===t);try{await xn(t,n?.project_id??e)}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.stopBuildChain`),{id:`board-stop-build-chain-error`}),e}},_i=async()=>{if(!(!e||Be)){Ve(!0);try{let t=await En(e);R(e=>e.filter(e=>!t.deleted_ticket_ids.includes(e.id))),ee(e=>t.deleted_ticket_ids.reduce(Uv,e)),await G(),ze(!1),t.failed_count>0?$.error(F(`board.toasts.deleteDonePartial`,{count:t.deleted_count,deletedCount:t.deleted_count,failedCount:t.failed_count}),{id:`board-delete-parked-error`}):$.success(F(`board.toasts.deleteDoneSuccess`,{count:t.deleted_count}),{id:`board-delete-parked-success`})}catch(e){$.error(e instanceof Ge?e.message:F(`board.errors.emptyDone`),{id:`board-delete-parked-error`})}finally{Ve(!1)}}},vi=({delta:e})=>{Ce(e)},yi=(0,p.useCallback)((t=null)=>{e&&Te({initialWorktreeBundleId:t})},[e]);(0,p.useEffect)(()=>{!M||!e||(Te({initialWorktreeBundleId:null,initialImportedDraft:M}),N?.())},[M,e,N]),(0,p.useEffect)(()=>{if(!Xe||!e){Je.current=null;return}let t=`${e}:${Xe}`;if(W!==e||Je.current===t)return;Je.current=t;let n=ln.get(Xe);n?fn(n):_?.(),v===void 0&&g?.()},[e,W,g,_,fn,Xe,v,ln]),(0,p.useEffect)(()=>{v===void 0||v||!J||y.some(e=>e.kind===`ticket`&&e.ticketId===J.id)||(Ke(null),qe(null))},[y,v,J]),(0,p.useEffect)(()=>{!v||!e||W!==e||Je.current!==`${e}:${v}`||We!==v||ln.has(v)||(Ke(null),qe(null),_?.())},[e,W,_,v,We,ln]),(0,p.useEffect)(()=>{if(!S){let e=C?.target.kind===`bundle`?C.target.bundleId:null,t=e!==null&&et.current===e,n=et.current!==null&&y.some(e=>e.kind===`bundle`&&e.bundleId===et.current);Ze.current&&!t&&!n&&(Ze.current=null,e===null&&pn());return}let t=`${e}:${S}`;if(!(!e||W!==e||te!==e||Ze.current===t)){if(Ze.current=t,!mn.has(S)){j?.();return}Qr(S)}},[e,mn,te,pn,W,j,Qr,S,C,y,rt,Qe]),(0,p.useEffect)(()=>{!S||!e||W!==e||te!==e||Ze.current!==`${e}:${S}`||Qe!==S||mn.has(S)||(pn(),j?.())},[e,mn,te,pn,W,j,S,Qe]),(0,p.useEffect)(()=>{if(!C){Y.current=null,pt(e=>e?.isRouteOwned?null:e);return}let t=C?.target.kind===`bundle`?W===e&&te===e:W===e;if(!e||!t)return;let n=`${e}:${C.target.kind===`ticket`?`ticket:${C.target.ticketId}`:`bundle:${C.target.bundleId}`}`;if(Y.current===n)return;Y.current=n;let r=C.target,i=r.kind===`ticket`&&y.some(e=>e.kind===`ticket`&&e.ticketId===r.ticketId),a=y.some(e=>e.kind===`bundle`&&e.bundleId===(r.kind===`bundle`?r.bundleId:et.current));if(i||(Ke(null),qe(null)),!a&&r.kind===`ticket`&&pn(),pt(e=>e?.isRouteOwned?null:e),C.target.kind===`ticket`){let e=ln.get(C.target.ticketId);if(!e||!er(e)){j?.();return}pt({target:{kind:`ticket`,ticketId:e.id},projectId:e.project_id,title:e.title,bundleTargetName:null,initialMode:C.mode,followUpMode:`build`,isRouteOwned:!0});return}let{bundleId:o}=C.target,s=nr(o),c=C.mode===`files`?ir(o):rr(o);if(!s||!c){j?.();return}let l=mn.get(o)??s.bundle??null;pt({target:{kind:`bundle`,bundleId:o,ticketId:s.id},projectId:s.project_id,title:l?Jy(l):s.title,bundleTargetName:l&&Jy(l)||null,initialMode:C.mode,followUpMode:`build`,isRouteOwned:!0})},[e,mn,te,ir,rr,er,pn,nr,W,j,C,y,rt,Qe,ln]),(0,p.useEffect)(()=>{let t=C?.target.kind===`bundle`?W===e&&te===e:W===e;if(!C||!e||!t)return;let n=C.target.kind===`ticket`?`ticket:${C.target.ticketId}`:`bundle:${C.target.bundleId}`;if(Y.current!==`${e}:${n}`||!ft?.isRouteOwned)return;if(C.target.kind===`ticket`){if(ft.target.kind!==`ticket`||ft.target.ticketId!==C.target.ticketId)return;let e=ln.get(C.target.ticketId);(!e||!er(e))&&(pt(null),j?.());return}if(ft.target.kind!==`bundle`||ft.target.bundleId!==C.target.bundleId)return;let{bundleId:r}=C.target,i=nr(r),a=C.mode===`files`?ir(r):rr(r);if(!i||!a){pt(null),j?.();return}if(ft.target.ticketId!==i.id){let e=mn.get(r)??i.bundle??null;pt(t=>t?.isRouteOwned?{...t,target:{kind:`bundle`,bundleId:r,ticketId:i.id},projectId:i.project_id,title:e?Jy(e):i.title,bundleTargetName:e&&Jy(e)||null}:t)}},[e,mn,te,ir,rr,er,nr,W,j,C,ft,ln]);let bi=(0,p.useCallback)(()=>{Wt.current?.focus({preventScroll:!0})},[]);return lme([{key:`n`,onKeyDown:yi,disabled:!e},{key:`k`,ctrlKey:!0,onKeyDown:bi}],{isBlocked:cme}),(0,X.jsxs)(X.Fragment,{children:[!T&&(0,X.jsxs)(ase,{sensors:I,collisionDetection:poe,onDragStart:ar,onDragMove:vi,onDragCancel:or,onDragEnd:ur,children:[(0,X.jsx)(`div`,{className:`relative flex min-h-0 flex-1 overflow-hidden`,children:(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-4 overflow-hidden p-6`,children:[(0,X.jsx)(Mde,{query:Mt.query,inputRef:Wt,hideStaleTickets:Mt.hideStaleTickets,hideBundlesWithPullRequests:Mt.hideBundlesWithPullRequests,onQueryChange:e=>zt({query:e}),onClear:()=>{zt({query:``}),Wt.current?.focus()},onHideStaleTicketsChange:e=>zt({hideStaleTickets:e}),onHideBundlesWithPullRequestsChange:e=>zt({hideBundlesWithPullRequests:e})}),(0,X.jsx)(`div`,{ref:Fn,className:`flex min-h-0 flex-1 overflow-x-auto overflow-y-hidden`,children:(0,X.jsxs)(`div`,{ref:Ln,className:`relative flex min-h-0 w-max min-w-full gap-4`,children:[(0,X.jsx)(Jpe,{dependencies:z,cardRects:Hn,clipRects:Un,preview:Wn,ticketsById:ln,overlaySize:Gn}),E8.map(t=>{let n=L.filter(e=>e.state===t&&!gy(e)),r=gn.filter(e=>e.state===t&&!gy(e)),a=Hy(r,B,t),o=tn&&n.length===0?t===`plan`?1:t===`build`?2:0:0;return(0,X.jsx)(g3,{id:t,title:F(`card.columnLabels.${t}`),items:a,ticketCount:r.length,allTickets:L,dependencies:z,bundles:B,activeTool:i,modelsByTool:Fe,availableSkills:Ie,activeRunContextKey:Qt,automationStatuses:fe,isProjectRootRunActive:Zt,isBundleRunDisabled:$t,getDependencyTargetState:Kn,onDependencyStart:qn,onDeleteDependency:Jn,onRegisterTicketNode:Bn,onRegisterDependencyClipNodes:Vn,onAddTicket:t===`plan`&&e?yi:void 0,onCreateBundle:t===`plan`&&e?fr:void 0,onDeleteBundle:t===`plan`&&e?xr:void 0,onDeleteBundleWrapper:Sr,onRefreshBundles:t===`plan`&&e?G:void 0,onUpdateTicket:Cr,onDeleteTicket:wr,onUndoTicket:Tr,undoingColumn:He,onRetryTicket:Er,onAdvanceTicket:mi,onParkTicket:_r,onUnparkTicket:vr,onBuildChainTicket:hi,onRunTicket:Dr,onOpenVerificationTicket:nn.length>0?Vr:void 0,canOpenChangesForTicket:er,onOpenFilesTicket:zr,onOpenChangesTicket:Br,canOpenIdeForTicket:$n,onOpenIdeTicket:Or,onStopTicket:kr,onStopBuildTicket:Ar,onStopBuildChainTicket:gi,onResumeBuildTicket:Mr,onInterruptReviewTicket:jr,onOpenBundleFiles:Lr,onOpenBundleChanges:Rr,canOpenReviewForBundle:rr,canOpenFilesForBundle:ir,onOpenBundleVerification:nn.length>0?e=>Fr(e):void 0,onOpenBundleChecks:e=>Fr(e,`checks`),hasConfiguredChecks:nn.length>0,onOpenBundleIde:Nr,onAddTicketToBundle:yi,onStartChatFromBundle:u,onFollowUpTicket:Hr,bundleActionState:yt,onBuildBundle:ii,onReviewBundle:ai,onUndoBundleReview:si,onRunBundle:di,onStopBundle:fi,onParkBundleWrapper:yr,onUnparkBundleWrapper:br,onOpenTicketDetails:fn,onOpenBundleDetails:(e,t)=>{$r(e,t)},onRequestBundleRefresh:e=>{ei(`bundleRefresh`,()=>Kr(e))},onRequestTicketRefresh:ae,hoveredBundleId:_e,onHoverBundleChange:ye,multiColumnBundleIds:_n,onResumeBundleAutomation:ci,onDismissBundleAutomationPause:li,onOpenBuildQuestions:e=>{Jr(e)},loadingSkeletonCount:o},t)}),(0,X.jsx)(g3,{id:D8,title:F(`card.columnLabels.done`),items:yn,ticketCount:vn.length,allTickets:L,dependencies:z,activeTool:i,modelsByTool:Fe,availableSkills:Ie,bundles:B,activeRunContextKey:Qt,automationStatuses:fe,isProjectRootRunActive:Zt,isBundleRunDisabled:$t,getDependencyTargetState:Kn,onDependencyStart:qn,onDeleteDependency:Jn,onRegisterTicketNode:Bn,onRegisterDependencyClipNodes:Vn,onUpdateTicket:Cr,onDeleteTicket:wr,onUndoTicket:Tr,undoingColumn:He,onRetryTicket:Er,onAdvanceTicket:mi,onParkTicket:_r,onUnparkTicket:vr,onBuildChainTicket:hi,onRunTicket:Dr,onOpenVerificationTicket:nn.length>0?Vr:void 0,canOpenChangesForTicket:er,onOpenFilesTicket:zr,onOpenChangesTicket:Br,canOpenIdeForTicket:$n,onOpenIdeTicket:Or,onStopTicket:kr,onStopBuildTicket:Ar,onStopBuildChainTicket:gi,onResumeBuildTicket:Mr,onInterruptReviewTicket:jr,onOpenBundleFiles:Lr,onOpenBundleChanges:Rr,canOpenReviewForBundle:rr,canOpenFilesForBundle:ir,onOpenBundleVerification:nn.length>0?e=>Fr(e):void 0,onOpenBundleChecks:e=>Fr(e,`checks`),hasConfiguredChecks:nn.length>0,onOpenBundleIde:Nr,onAddTicketToBundle:yi,onStartChatFromBundle:u,onFollowUpTicket:Hr,bundleActionState:yt,onBuildBundle:ii,onReviewBundle:ai,onUndoBundleReview:si,onRunBundle:di,onStopBundle:fi,onParkBundleWrapper:yr,onUnparkBundleWrapper:br,onOpenTicketDetails:fn,onOpenBundleDetails:(e,t)=>{$r(e,t)},onRequestBundleRefresh:e=>{ei(`bundleRefresh`,()=>Kr(e))},onRequestTicketRefresh:ae,hoveredBundleId:_e,onHoverBundleChange:ye,multiColumnBundleIds:_n,onResumeBundleAutomation:ci,onDismissBundleAutomationPause:li,onOpenBuildQuestions:e=>{Jr(e)},className:`min-w-[272px] max-w-[272px] flex-[0.98] bg-card/65`,headerAccessory:(0,X.jsxs)(Q,{type:`button`,variant:`destructive`,size:`xs`,className:`gap-1.5`,disabled:vn.length===0||Be,onClick:()=>ze(!0),children:[(0,X.jsx)(fC,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{children:F(`board.doneColumn.emptyAction`)})]})})]})})]})}),(0,X.jsxs)(xse,{zIndex:5,dropAnimation:Le?null:void 0,children:[pe&&(0,X.jsx)(h3,{ticket:pe,allTickets:L,dependencies:z,bundles:B,projectMemoryEnabled:!!t?.memory_enabled,automationStatus:pe.worktree_bundle_id?fe.get(pe.worktree_bundle_id):null,overlay:!0,activeTool:i,showModelSelector:(()=>{let e=yF(pe,i);return bF(e)&&Pe(e).length>0})(),availableModels:Pe(yF(pe,i)),runDisabled:uy(pe,Qt,Zt,F(`board.errors.runBlockedByActive`))!==void 0,runDisabledReason:uy(pe,Qt,Zt,F(`board.errors.runBlockedByActive`)),onDependencyStart:qn,onDeleteDependency:Jn,onRegisterOverlayNode:xe,onCreateBundle:fr,onDeleteBundle:xr,onRefreshBundles:G,onUpdate:Cr,onDelete:()=>wr(pe.id),onUndo:()=>Tr(pe.id),undoInProgress:He===pe.state&&(pe.state===`build`||pe.state===`review`),onRetry:()=>Er(pe.id),onAdvance:()=>mi(pe.id),onPark:()=>_r(pe.id),onUnpark:()=>vr(pe.id),onBuildChain:()=>hi(pe.id),onRun:pe.worktree_bundle_id===null&&zy(pe)&&pe.has_run_config?()=>Dr(pe.id):void 0,onOpenIde:pe.worktree_bundle_id===null&&$n(pe)?()=>Or(pe.id):void 0,onStop:pe.worktree_bundle_id===null?()=>kr(pe.id):void 0,onStopBuild:()=>Ar(pe.id),onStopBuildChain:()=>gi(pe.id),onResumeBuild:()=>Mr(pe.id),onInterruptReview:()=>void jr(pe.id),onFollowUp:e=>Hr(pe.id,e),onRequestTicketRefresh:ae}),!pe&&he&&(0,X.jsx)(CF,{group:he,activeTool:i,modelsByTool:Fe,automationStatus:fe.get(he.bundle.id),overlay:!0,renderTicket:Qn})]}),en&&(0,X.jsx)(Zpe,{className:`pointer-events-auto fixed left-1/2 top-4 z-20 w-[min(14rem,calc(100vw-2rem))] -translate-x-1/2`})]}),we&&(()=>{let r=Pe(i),a=Vt&&Yn.model&&xF(Yn.model,r),o=a?Yn.model:``,s=a?Yn.variant:``;return(0,X.jsx)(Xpe,{onSubmit:dr,bundles:B,projectId:e,projectBranchState:n,tool:i,showModelSelector:Vt,showSkillsSelector:i===`opencode`,showDockerSandboxModelNotice:t?.build_execution_provider===`docker_sandbox`,onOpenProjectExecutionSettings:P,availableModels:r,availableSkills:Ie,initialModel:o,initialVariant:s,initialSkills:Vt&&i===`opencode`?Yn.skills:[],initialWorktreeBundleId:we.initialWorktreeBundleId,initialImportedDraft:we.initialImportedDraft,onCreateBundle:fr,onDeleteBundle:xr,onRefreshBundles:G,onClose:()=>Te(null)})})(),Re&&(0,X.jsx)(Nde,{ticketCount:vn.length,isDeleting:Be,onCancel:()=>ze(!1),onConfirm:()=>{_i()}}),J&&(0,X.jsx)(m3,{ticket:J,allTickets:L,dependencies:z,bundles:B,projectMemoryEnabled:!!t?.memory_enabled,automationStatus:J.automation_paused_reason?null:J.worktree_bundle_id?fe.get(J.worktree_bundle_id):null,projectBranchState:n,onClose:()=>{let e=J.id;Ke(null),qe(null),R(t=>t.map(t=>t.id===e?p8(t):t)),x?.()},showModelSelector:Ht,showSkillsSelector:yF(J,i)===`opencode`,activeTool:i,availableModels:Pe(yF(J,i)),availableReviewerModels:Me[i],isLoadingReviewerModels:Ne[i],availableSkills:Ie,runDisabled:uy(J,Qt,Zt,F(`board.errors.runBlockedByActive`))!==void 0,runDisabledReason:uy(J,Qt,Zt,F(`board.errors.runBlockedByActive`)),onDeleteDependency:Jn,onCreateBundle:fr,onDeleteBundle:xr,onRefreshBundles:G,onUpdate:Cr,onAdvance:()=>mi(J.id),onBuildChain:()=>hi(J.id),onRun:zy(J)&&J.has_run_config?()=>Dr(J.id):void 0,onOpenIde:$n(J)?()=>Or(J.id):void 0,onStop:()=>kr(J.id),onStopBuild:()=>Ar(J.id),onStopBuildChain:()=>gi(J.id),onResumeBuild:()=>Mr(J.id),onInterruptReview:()=>void jr(J.id),onFollowUp:(e,t)=>Hr(J.id,e,t),onReviewFollowUp:(e,t)=>J.worktree_bundle_id?pi(J.worktree_bundle_id,e,t,`changes`):Hr(J.id,e,t,`changes`),onProjectMemorySuggestionsChanged:()=>{wt(e=>e+1)},onRequestTicketRefresh:e=>{dn(e)},onWorkspaceReviewOpen:O?e=>{O({kind:`ticket`,ticketId:J.id},e)}:void 0,onViewSourceSpec:c,onNavigateToLifecycleSource:l,onOpenBuildQuestions:e=>{Jr(e)},onOpenChecks:J.worktree_bundle_id&&(nn.length>0||J.latest_check_gate_evaluation)?()=>{Fr(J.worktree_bundle_id,`checks`)}:void 0,onStopAutomation:J.worktree_bundle_id?()=>fi(J.worktree_bundle_id):void 0}),ut&&e&&t&&(()=>{let t=L.find(e=>e.id===ut.ticketId);if(!t)return null;let n=!!t.worktree_bundle_id,r=t.worktree_bundle_id?mn.get(t.worktree_bundle_id)?.required_check_policy??t.bundle?.required_check_policy:void 0,i=r?.required_check_definition_ids??an,a=r?.pre_review_check_definition_ids??on,o=n?{projectId:e,targetKind:`bundle`,targetBundleId:t.worktree_bundle_id}:null,s={scope:`ticket`,ticketId:t.id,projectId:t.project_id};return(0,X.jsx)(p.Suspense,{fallback:null,children:(0,X.jsx)(T8,{targetLabel:ut.label,definitions:nn,requiredDefinitionIds:i,preReviewDefinitionIds:a,checksTarget:o,testsTarget:s,onClose:()=>dt(null),requestedInitialTab:ut.requestedInitialTab})})})(),ft&&(()=>{let{target:e}=ft,t=L.find(t=>t.id===e.ticketId),n=e.kind===`bundle`,r=n?L.some(t=>t.worktree_bundle_id===e.bundleId):!!t,i=n?L.some(t=>t.worktree_bundle_id===e.bundleId&&t.agent_status===`running`):t?.agent_status===`running`,a=n?r&&!i:!!t&&!i,o=!!(ft.isRouteOwned&&w!==void 0),s=o?w:null,l=o?s?.canSubmitReviewPrompt??!1:a,u=i?F(`board.changes.reviewPromptDisabledReason`):r?!n&&t?u3(t).disabledReason??void 0:void 0:F(`board.changes.targetUnavailableReason`),d=!i&&(n||t?.state===`build`||t?.state===`review`),f=n?mn.get(e.bundleId):void 0;return(0,X.jsx)(G6,{target:{scope:`ticket`,ticketId:e.ticketId,onTicketUpdate:Cr,onRequestTicketRefresh:ae},initialMode:ft.initialMode,reviewMode:ft.isRouteOwned?C?.mode:void 0,onReviewModeChange:ft.isRouteOwned?k:void 0,enabledModes:[`changes`,`files`],projectId:ft.projectId,reviewCommentsBundleId:n?e.bundleId:null,title:ft.title,bundleTargetName:ft.bundleTargetName,fileTarget:f?.kind===`project_root`?{kind:`repo_root`,bundle_id:null,ticket_id:null}:void 0,onSubmitReviewPrompt:o?s?.submitPrompt:t=>n?pi(e.bundleId,t,ft.followUpMode,`changes`):Hr(e.ticketId,t,ft.followUpMode,`changes`),canSubmitReviewPrompt:l,reviewSubmitDisabledReason:o?s?.reviewSubmitDisabledReason??F(`workspaceReviewModal.chatRequired`):u,canAddReviewComments:l,canModifyChanges:a,changesDisabledReason:i?F(`board.changes.modifyChangesDisabledReason`):u,mode:o?s?.mode:ft.followUpMode,onModeChange:o?s?.onModeChange:e=>{pt(t=>t&&{...t,followUpMode:e})},canToggleMode:o?s?.canSubmitReviewPrompt??!1:d,isUpdatingMode:s?.isUpdatingMode??!1,onClose:()=>{if(pt(null),ft.isRouteOwned&&A?.(),n){Kr(e.bundleId);return}dn(e.ticketId)},onViewSourceSpec:c,originSpecSessionId:t?.origin_spec_session_id??null,originSpecSnapshotId:t?.origin_spec_snapshot_id??null})})(),mt&&e&&t&&(()=>{let t=mn.get(mt.bundleId)?.required_check_policy??mt.requiredCheckPolicy,n=t?.required_check_definition_ids??an,r=t?.pre_review_check_definition_ids??on;return(0,X.jsx)(p.Suspense,{fallback:null,children:(0,X.jsx)(T8,{targetLabel:mt.label,definitions:nn,requiredDefinitionIds:n,preReviewDefinitionIds:r,checksTarget:{projectId:e,targetKind:`bundle`,targetBundleId:mt.bundleId,gateEvaluationId:mt.gateEvaluationId},testsTarget:sn?{scope:`project`,projectId:e,targetKind:`bundle`,targetBundleId:mt.bundleId}:null,onClose:()=>ht(null),requestedInitialTab:mt.requestedInitialTab})})})(),Qe&&hn&&(0,X.jsx)(Wde,{details:hn,activeColumn:tt,isLoading:gt||yt.bundleRefresh,actionState:yt,canOpenIde:tr(hn),projectMemoryEnabled:!!t?.memory_enabled,memorySuggestionsRefreshKey:Ct,automationStatus:hn.tickets.some(e=>e.automation_paused_reason)?null:fe.get(hn.bundle.id),runDisabled:$t(hn.bundle.id),showModelSelector:Ut,activeTool:i,modelsByTool:Fe,modelsLoadingByTool:Ne,availableSkills:Ie,onClose:()=>{let e=hn.bundle.id;$e(null),nt(null),it(null),vt(!1),St(o8()),R(t=>t.map(t=>t.worktree_bundle_id===e&&t.id!==We?p8(t):t)),D?.()},onOpenTicketDetails:fn,onNavigateToLifecycleSource:l,onUpdateTicket:Cr,onOpenIde:()=>{let e=hn.tickets.find(e=>e.id===hn.target_ticket_id)??hn.tickets.find(e=>e.has_worktree);e&&Or(e.id)},onOpenVerification:nn.length>0?()=>{Fr(hn.bundle.id)}:void 0,onOpenChecks:nn.length>0||hn.tickets.some(e=>e.latest_check_gate_evaluation)?()=>{Fr(hn.bundle.id,`checks`)}:void 0,onRefresh:e=>ei(`bundleRefresh`,()=>Kr(e)).then(()=>void 0),onWorkspaceReviewOpen:O?e=>{O({kind:`bundle`,bundleId:hn.bundle.id},e)}:void 0,onUpdateBundle:mr,onBuildBundle:ii,onStopBuildTicket:ti,onResumeBuildTicket:ri,onInterruptReviewTicket:ni,onReviewBundle:ai,onContinueReviewBundle:oi,onUndoBundleReview:si,onRunBundle:di,onStopBundle:fi,onFollowUpBundle:pi,onOpenBuildQuestions:e=>{Jr(e)},onResumeBundleAutomation:ci,onDismissBundleAutomationPause:li}),at&&st&&(0,X.jsx)(Bpe,{details:st,onClose:()=>{lt.current+=1,ot(null),ct(null)},onRefresh:qr,onSubmit:Yr})]})},O8=({count:e,title:t,isDeleting:n,onConfirm:r,onCancel:i,labels:a})=>{let o=e>1;return(0,X.jsxs)(tC,{onClose:i,overlayClassName:`bg-black/70`,panelClassName:`max-w-sm rounded-2xl border border-border bg-card p-6 shadow-2xl`,children:[(0,X.jsx)(`h2`,{className:`mb-3 text-sm font-semibold uppercase tracking-widest text-muted-foreground`,children:o?a.bulkTitle:a.title}),t?(0,X.jsx)(`p`,{className:`mb-1 text-sm text-foreground`,children:t}):null,(0,X.jsx)(`p`,{className:`mb-6 text-xs text-muted-foreground`,children:o?a.bulkDescription(e):a.description}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,X.jsx)(Q,{type:`button`,variant:`ghost`,onClick:i,disabled:n,children:a.cancel}),(0,X.jsx)(Q,{type:`button`,variant:`destructive`,onClick:r,disabled:n,children:n?a.deleting:a.delete})]})]})},k8=({label:e})=>(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6 text-sm text-muted-foreground`,children:e}),A8=({label:e})=>(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6 text-sm text-muted-foreground`,children:e}),j8=({title:e,description:t,startNewSessionLabel:n,onStartNewSession:r,canStartNewSession:i})=>(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6`,children:(0,X.jsxs)(iC,{className:`w-full max-w-lg border-dashed border-border/70 bg-card/40`,children:[(0,X.jsxs)(aC,{children:[(0,X.jsx)(oC,{children:e}),(0,X.jsx)(sC,{children:t})]}),(0,X.jsx)(lC,{children:(0,X.jsx)(Q,{type:`button`,onClick:r,disabled:!i,children:n})})]})}),Mme=({className:e})=>(0,X.jsx)(Ug,{"aria-hidden":`true`,className:e}),Nme=({className:e})=>(0,X.jsx)(jg,{"aria-hidden":`true`,className:e}),Pme=({className:e})=>(0,X.jsx)(Mg,{"aria-hidden":`true`,className:e}),M8=({sessions:e,sessionGroups:t,activeSessionId:n,isDraftOpen:r,isLoadingSessions:i,isOpen:a,onToggleOpen:o,testId:s,railTestId:c,onDraftOpen:l,isCreatingSession:u,isSendingPrompt:d,newSessionShortcutHint:f,newSessionTooltip:m,isSelectionMode:h,selectedSessionIds:g,selectedSessionCount:_,hasDeletableSessions:v,deletingSessionIds:y,onEnterSelectionMode:b,onExitSelectionMode:x,onToggleSessionSelection:S,onSetSessionSelection:C,onConfirmDeleteSelectedSessions:w,selectionPresets:T,onSessionSelect:E,onConfirmDeleteSession:D,getSessionId:O,getSessionTitle:k,getDeleteDisabledReason:A,getActivityState:j,getRowAriaLabel:M,renderRowContent:N,labels:P})=>{let F=(0,p.useMemo)(()=>new Set(e.filter(e=>!A(e)&&!y.has(O(e))).map(e=>O(e))),[y,A,O,e]),I=(0,p.useMemo)(()=>T.map(t=>({...t,matchingSessionIds:new Set(e.filter(e=>F.has(O(e))&&t.matches(e)).map(O))})),[O,F,T,e]),L=(0,p.useRef)(null),R=(0,p.useRef)(!1),z=(0,p.useRef)(null),ee=(0,p.useCallback)(()=>{z.current!==null&&(window.clearTimeout(z.current),z.current=null)},[]),B=(0,p.useCallback)(()=>{ee(),z.current=window.setTimeout(()=>{R.current=!1,z.current=null},0)},[ee]),V=(0,p.useCallback)(()=>{L.current&&(L.current=null,B())},[B]),H=(0,p.useCallback)(e=>{let t=L.current;!t||t.visitedSessionIds.has(e)||!F.has(e)||(t.visitedSessionIds.add(e),C(e,t.mode===`select`))},[C,F]),U=(0,p.useCallback)(e=>{let t=L.current;!t||e.pointerId!==t.pointerId||V()},[V]);return(0,p.useEffect)(()=>{if(!h){V();return}return window.addEventListener(`pointerup`,U),window.addEventListener(`pointercancel`,U),()=>{window.removeEventListener(`pointerup`,U),window.removeEventListener(`pointercancel`,U),V(),ee()}},[ee,U,h,V]),(0,X.jsx)(`aside`,{"data-testid":s,"data-state":a?`expanded`:`collapsed`,"aria-label":P.ariaLabel,className:Z(`relative z-20 flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-background/40 transition-[width] duration-200 ease-out motion-reduce:transition-none`,a?`w-72`:`w-16`),children:a?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-start gap-2 border-b border-border/70 px-4 py-3.5`,children:[(0,X.jsxs)(Q,{type:`button`,size:`sm`,className:`gap-2`,onClick:l,disabled:u||d,children:[(0,X.jsx)(xv,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:P.newSession}),f]}),(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":P.collapseAriaLabel,"aria-expanded":a,className:`ml-auto`,onClick:o,children:(0,X.jsx)(Nme,{className:`h-4 w-4`})})]}),e.length>0?(0,X.jsx)(`div`,{className:`px-4 py-2.5`,children:h?(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 px-2 text-xs`,onClick:x,disabled:y.size>0,children:P.cancelSelection}),(0,X.jsxs)(eb,{children:[(0,X.jsx)(tb,{asChild:!0,children:(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 gap-1.5 px-2 text-xs`,children:P.addPreset})}),(0,X.jsx)(nb,{align:`start`,className:`w-44`,children:I.map(e=>(0,X.jsx)(rb,{disabled:e.matchingSessionIds.size===0,onSelect:()=>{for(let t of e.matchingSessionIds)C(t,!0)},children:e.label},e.key))})]}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`destructive`,className:`h-7 px-2 text-xs`,onClick:w,disabled:_===0||y.size>0,children:P.deleteSelected})]}),(0,X.jsx)(`div`,{className:`flex justify-end text-xs font-medium text-muted-foreground`,children:P.selectedCount(_)})]}):v?(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 gap-1.5 px-2 text-xs`,onClick:b,children:[(0,X.jsx)(Mme,{className:`h-3.5 w-3.5`}),P.select]}):null}):null,(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:i&&e.length===0?(0,X.jsx)(`div`,{className:`px-2 py-4 text-sm text-muted-foreground`,children:P.loadingSessions}):e.length===0?(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border/70 px-3 py-4 text-sm text-muted-foreground`,children:P.noSessions}):(0,X.jsx)(`div`,{className:`flex flex-col gap-3`,children:t.map(e=>(0,X.jsxs)(`section`,{"aria-label":e.label,className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(`div`,{className:`px-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground/80`,children:e.label}),e.sessions.map(e=>{let t=O(e),i=!r&&t===n,a=A(e),o=y.has(t),s=!!a||o,c=g.has(t),l=j(e,i);return(0,X.jsxs)(`div`,{"data-session-id":t,"data-session-selectable":s?`false`:`true`,className:Z(`group relative rounded-xl border transition-colors`,i?`border-sky-400/40 bg-sky-500/10 text-foreground ring-1 ring-sky-400/40`:`border-border/50 bg-card/35 text-muted-foreground hover:border-border/80 hover:bg-card/60 hover:text-foreground`),onPointerDownCapture:e=>{!h||s||e.pointerType&&e.pointerType!==`mouse`||typeof e.button==`number`&&e.button!==0||(e.preventDefault(),ee(),R.current=!0,L.current={pointerId:e.pointerId,mode:c?`deselect`:`select`,visitedSessionIds:new Set},H(t))},onPointerMove:e=>{let n=L.current;!n||n.pointerId!==e.pointerId||H(t)},children:[(0,X.jsx)(`button`,{type:`button`,"aria-label":M(e,l),className:`flex w-full min-w-0 cursor-pointer items-start gap-2 rounded-xl px-3 py-2 pr-11 text-left transition-colors focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:outline-none`,onClick:()=>{if(h){if(R.current){R.current=!1;return}if(s)return;S(t);return}E(e)},children:N({session:e,isActive:i,activityState:l,isSelectionMode:h})}),h?(0,X.jsx)(`div`,{className:`absolute top-2 right-2 flex h-7 w-7 items-center justify-center`,title:a??P.selectSessionTitle(k(e)),children:(0,X.jsx)(`input`,{type:`checkbox`,"aria-label":P.selectSessionAriaLabel(k(e)),checked:c,disabled:s,onClick:e=>{e.stopPropagation()},onChange:()=>{R.current||S(t)},className:`h-4 w-4 rounded border-border bg-background text-primary`})}):(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":P.deleteSessionAriaLabel,className:Z(`absolute top-2 right-2 h-7 w-7 shrink-0 rounded-md border border-transparent text-muted-foreground transition-all duration-150 hover:border-border/70 hover:bg-card/80 hover:text-foreground focus-visible:border-border/70 focus-visible:bg-card/80 focus-visible:text-foreground`,`opacity-100 sm:opacity-0 sm:pointer-events-none sm:group-hover:pointer-events-auto sm:group-focus-within:pointer-events-auto sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,s&&`sm:disabled:opacity-0 sm:group-hover:disabled:opacity-50 sm:group-focus-within:disabled:opacity-50`,(i||o)&&`sm:pointer-events-auto sm:opacity-100 sm:disabled:opacity-50`,a&&`cursor-not-allowed text-muted-foreground/50 hover:border-transparent hover:bg-transparent hover:text-muted-foreground/50 focus-visible:border-transparent focus-visible:bg-transparent focus-visible:text-muted-foreground/50`),title:a??P.deleteSessionTitle(k(e)),disabled:s,onClick:e=>{e.stopPropagation(),D(t)},children:(0,X.jsx)(fC,{className:`h-4 w-4`})})]},t)})]},e.key))})})]}):(0,X.jsxs)(`div`,{"data-testid":c,className:`flex h-full w-full flex-col items-center gap-2 bg-background/80 py-3`,children:[m?(0,X.jsx)(vv,{content:m,side:`right`,children:(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,"aria-label":P.newSession,className:`h-9 w-9`,onClick:l,disabled:u||d,children:(0,X.jsx)(xv,{className:`h-4 w-4`})})}):(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,"aria-label":P.newSession,className:`h-9 w-9`,onClick:l,disabled:u||d,children:(0,X.jsx)(xv,{className:`h-4 w-4`})}),(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":P.openAriaLabel,"aria-expanded":a,className:`h-9 w-9`,onClick:o,children:(0,X.jsx)(Pme,{className:`h-4 w-4`})})]})})},N8=({isInterrupting:e,onStop:t,interruptLabel:n,interruptingLabel:r})=>(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`gap-2`,disabled:e,onClick:t,children:[e?(0,X.jsx)(Ov,{className:`h-4 w-4 animate-spin`}):(0,X.jsx)(jv,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:e?r:n})]}),P8=4,Fme=5e3,F8=(e,t)=>qb.t(`common:chatChangesPanel.${e}`,t),I8=e=>e.replace(/^[ab]\//,``),L8=e=>{let t=`oldPath`in e&&typeof e.oldPath==`string`?I8(e.oldPath):``,n=`newPath`in e&&typeof e.newPath==`string`?I8(e.newPath):``;return[...new Set([n,t].filter(e=>e&&e!==`/dev/null`))]},R8=e=>{let[t,n]=L8(e);return!t&&!n?F8(`unknownFile`):t&&n&&t!==n?`${n} -> ${t}`:t??n??F8(`unknownFile`)},z8=e=>{let t=hG((()=>{let[t,n]=L8(e);return t??n??null})());if(!t)return null;try{return RM(e.hunks,{highlight:!0,refractor:uK.default,language:t,enhancers:[LM(e.hunks)]})}catch{return null}},B8=(e,t)=>e instanceof Error?e.message:t,Ime=(e,t)=>{if(!t)return e;let n=R8(t);return[t,...e.filter(e=>R8(e)!==n)]},Lme=e=>[...e].sort((e,t)=>{if(e.filePath!==t.filePath)return e.filePath.localeCompare(t.filePath);let n=e.newLineNumber??e.oldLineNumber??2**53-1,r=t.newLineNumber??t.oldLineNumber??2**53-1;return n===r?e.changeKey.localeCompare(t.changeKey):n-r}),Rme=({diffResponse:e,gitStatus:t})=>{let n=new Map;for(let t of e?.files??[])n.set(t.path,t);return t?t.files.map(e=>{let t=n.get(e.path)??(e.original_path?n.get(e.original_path):void 0);return{path:e.path,originalPath:e.original_path,status:e.status,staged:e.staged,unstaged:e.unstaged,conflicted:e.conflicted,additions:t?.additions??0,deletions:t?.deletions??0}}):(e?.files??[]).map(e=>({path:e.path,originalPath:null,status:null,staged:!1,unstaged:!1,conflicted:!1,additions:e.additions,deletions:e.deletions}))},V8=e=>{let t=e.split(/[\\/]/);return t[t.length-1]||e},zme={modified:`border-amber-500/40 bg-amber-500/10 text-amber-200`,added:`border-emerald-500/40 bg-emerald-500/10 text-emerald-200`,deleted:`border-rose-500/40 bg-rose-500/10 text-rose-200`,renamed:`border-sky-500/40 bg-sky-500/10 text-sky-200`,untracked:`border-violet-500/40 bg-violet-500/10 text-violet-200`,typechanged:`border-slate-500/40 bg-slate-500/10 text-slate-200`},Bme=e=>F8(`fileStatus.${e}`),Vme=({selectedDiffPath:e,sidebarFiles:t,diffStats:n,triggerMode:r=`full`,onSelectDiffPath:i})=>{let[a,o]=(0,p.useState)(!1),s=t.find(t=>t.path===e)??null,c=r===`compact`?e===`all`?F8(`picker.diff`):s?V8(s.path):F8(`picker.file`):e===`all`?F8(`picker.allChanges`):s?V8(s.path):e;return(0,X.jsxs)(av,{open:a,onOpenChange:o,children:[(0,X.jsx)(ov,{asChild:!0,children:(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,className:Z(`max-w-full gap-2`,r===`full`?`min-w-0 max-w-[18rem]`:`min-w-0 px-2.5`),"aria-label":F8(`picker.openChangedFilesAriaLabel`),title:e===`all`?void 0:s?.path??e,children:[(0,X.jsx)(`span`,{className:`truncate`,children:c}),r===`full`&&(0,X.jsx)(rC,{variant:`outline`,className:`shrink-0 text-[10px] uppercase tracking-wide`,children:F8(`picker.fileCount`,{count:t.length})}),(0,X.jsx)(bv,{className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,X.jsxs)(sv,{align:`start`,className:`z-[90] w-[28rem] max-w-[calc(100vw-2rem)] p-0`,children:[(0,X.jsx)(`div`,{className:`border-b border-border/80 px-4 py-3`,children:(0,X.jsx)(`div`,{className:`text-sm font-semibold text-foreground`,children:F8(`picker.title`)})}),(0,X.jsx)(`div`,{className:`max-h-[min(28rem,calc(100vh-10rem))] overflow-y-auto p-3`,children:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{i(`all`),o(!1)},className:Z(`flex w-full cursor-pointer items-start gap-3 rounded-xl border px-3 py-2.5 text-left transition-colors`,Z3(e===`all`),`justify-between`),children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:F8(`picker.allChanges`)}),(0,X.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground transition-colors group-hover:text-foreground/70`,children:F8(`picker.allChangesDescription`)})]}),n&&(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 text-[11px]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground transition-colors group-hover:text-foreground/70`,children:F8(`picker.fileCount`,{count:n.files_changed})}),(0,X.jsxs)(`span`,{className:`font-mono tabular-nums text-emerald-400`,children:[`+`,n.additions]}),(0,X.jsxs)(`span`,{className:`font-mono tabular-nums text-rose-400`,children:[`-`,n.deletions]})]})]}),t.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>{i(t.path),o(!1)},className:Z(`flex w-full cursor-pointer items-start gap-3 rounded-xl border px-3 py-2.5 text-left transition-colors`,Z3(e===t.path)),children:(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:V8(t.path)}),(0,X.jsx)(`div`,{className:`mt-0.5 break-all font-mono text-[11px] text-muted-foreground transition-colors group-hover:text-foreground/70`,children:t.path})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 text-[11px]`,children:[(0,X.jsxs)(`span`,{className:`font-mono tabular-nums text-emerald-400`,children:[`+`,t.additions]}),(0,X.jsxs)(`span`,{className:`font-mono tabular-nums text-rose-400`,children:[`-`,t.deletions]})]})]}),(0,X.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5 text-[11px]`,children:[t.status&&(0,X.jsx)(rC,{variant:`outline`,className:zme[t.status],children:Bme(t.status)}),t.staged&&(0,X.jsx)(rC,{variant:`outline`,children:F8(`fileStatus.staged`)}),t.unstaged&&(0,X.jsx)(rC,{variant:`outline`,children:F8(`fileStatus.unstaged`)}),t.conflicted&&(0,X.jsx)(rC,{variant:`destructive`,children:F8(`fileStatus.conflicted`)}),t.originalPath&&(0,X.jsx)(`span`,{className:`break-all font-mono text-[11px] text-muted-foreground transition-colors group-hover:text-foreground/70`,children:t.status===`renamed`?F8(`fileStatus.renamedFrom`,{path:t.originalPath}):t.originalPath})]})]})},`${t.path}:${t.originalPath??``}`))]})})]})]})},H8=(0,p.memo)(({projectId:e,chatSessionId:t=null,canSubmitReviewPrompt:n,reviewSubmitDisabledReason:r,onSubmitReviewPrompt:i,state:a,onStateChange:o,isResizing:s=!1,onClose:c,desktopWidth:l,panelElementRef:u})=>{let[d,f]=(0,p.useState)(null),[m,h]=(0,p.useState)(null),[g,_]=(0,p.useState)(null),[v,y]=(0,p.useState)(!1),[,b]=(0,p.useState)(!1),[x,S]=(0,p.useState)(new Map),[C,w]=(0,p.useState)(!1),T=(0,p.useRef)(0),E=(0,p.useRef)(0),D=(0,p.useRef)(null),O=(0,p.useRef)(null),k=a.selectedDiffPath,A=a.activeReviewTarget,j=a.editingReviewCommentKey,M=A?.commentKey??j??`chat`,N=a.reviewDraftInput,P=(0,p.useMemo)(()=>new Map(a.reviewComments.map(e=>[qM(e.filePath,e.changeKey),e])),[a.reviewComments]),F=(0,p.useCallback)(async()=>{if(!e)throw Error(`Project id is required`);return t?await kae(e,t):await rr(e)},[t,e]),I=(0,p.useCallback)(async()=>{if(!e)throw Error(`Project id is required`);return t?await Aae(e,t):await ur(e)},[t,e]);(0,p.useEffect)(()=>{D.current=d},[d]),(0,p.useEffect)(()=>{O.current=m},[m]);let L=(0,p.useCallback)(async()=>{if(!e){E.current+=1,f(null),h(null),_(null),y(!1),b(!1);return}let t=T.current+1,n=E.current+1;T.current=t,E.current=n,y(!0),b(!0);let r=F().then(e=>{T.current===t&&(D.current=e,f(e),_(null))}).catch(e=>{T.current===t&&_(B8(e,F8(`errors.loadDiff`)))}).finally(()=>{T.current===t&&E.current===n&&y(!1)}),i=I().then(e=>{T.current===t&&(O.current=e,h(e))}).catch(()=>{}).finally(()=>{T.current===t&&b(!1)});await Promise.allSettled([r,i])},[F,I,e]),R=(0,p.useCallback)(async(t={})=>{if(!e)return;let{broadcastOnSignatureChange:n=!1}=t,r=T.current+1;T.current=r,b(!0);try{let t=await I();if(T.current!==r)return;let i=O.current?.workspace_signature??null,a=t.workspace_signature??null,o=!D.current||i!==a;if(O.current=t,h(t),!o){E.current+=1,y(!1);return}let s=!D.current,c=E.current+1;E.current=c,s&&y(!0);try{let t=await F();if(T.current!==r)return;D.current=t,f(t),_(null),n&&i!==a&&i6(e)}catch(e){if(T.current!==r)return;D.current||_(B8(e,F8(`errors.loadDiff`)))}finally{s&&E.current===c&&y(!1)}}catch{D.current||(E.current+=1,y(!1));return}finally{T.current===r&&b(!1)}},[F,I,e]);(0,p.useEffect)(()=>{L()},[L]),(0,p.useEffect)(()=>{if(e)return a6(t=>{t===e&&R()})},[e,R]),(0,p.useEffect)(()=>{if(!e)return;let t=hx(()=>{document.visibilityState===`visible`&&R({broadcastOnSignatureChange:!0})});return()=>{t()}},[e,R]),(0,p.useEffect)(()=>{if(!e)return;let t=window.setInterval(()=>{document.visibilityState===`visible`&&R({broadcastOnSignatureChange:!0})},Fme);return()=>{window.clearInterval(t)}},[e,R]);let z=(0,p.useMemo)(()=>{let e=typeof d?.diff==`string`?d.diff:``;return e.trim()?tO(e,{nearbySequences:`zip`}).map(e=>({...e,pathCandidates:L8(e)})):[]},[d]),ee=(0,p.useMemo)(()=>{let e=new Map;for(let t of z)for(let n of t.pathCandidates)e.has(n)||e.set(n,t);return e},[z]),B=(0,p.useMemo)(()=>Rme({diffResponse:d,gitStatus:m}),[d,m]);(0,p.useEffect)(()=>{if(k!==`all`&&!(!d&&!m)){if(B.length===0){o(e=>({...e,selectedDiffPath:`all`}));return}B.some(e=>e.path===k)||o(e=>({...e,selectedDiffPath:`all`}))}},[d,m,o,k,B]);let V=k===`all`?null:ee.get(k)??null,H=(0,p.useMemo)(()=>Ime(z,V),[z,V]),U=(0,p.useMemo)(()=>k===`all`?z:V?[V]:[],[z,k,V]);(0,p.useEffect)(()=>{S(new Map)},[z]),(0,p.useEffect)(()=>{if(H.length===0)return;let e=!1,t=null,n=0,r=()=>{if(e)return;let i=H.slice(n,n+P8);i.length!==0&&(S(e=>{let t=new Map(e);for(let e of i){let n=R8(e);t.has(n)||t.set(n,z8(e))}return t}),n+=P8,n<H.length&&(t=window.setTimeout(r,0)))};return t=window.setTimeout(r,0),()=>{e=!0,t!==null&&window.clearTimeout(t)}},[H]);let W=(0,p.useMemo)(()=>{let e=new Map;for(let t of H.slice(0,P8))e.set(R8(t),z8(t));return e},[H]),te=(0,p.useMemo)(()=>U.map(e=>({...e,tokens:x.get(R8(e))??W.get(R8(e))??null})),[W,x,U]),ne=(0,p.useMemo)(()=>z.map(e=>({...e,tokens:null})),[z]),re=(0,p.useMemo)(()=>Lme(a.reviewComments),[a.reviewComments]),ie=re.length,ae=n&&!C&&ie>0,G=(0,p.useCallback)(()=>{o(e=>({...e,activeReviewTarget:null,editingReviewCommentKey:null,reviewDraftInput:``,reviewComments:[]}))},[o]),oe=(0,p.useCallback)(({filePath:e,changeKey:t,commentKey:r})=>{let i=P.get(r);if(i){o(e=>({...e,selectedDiffPath:i.filePath,activeReviewTarget:null,editingReviewCommentKey:r,reviewDraftInput:i.comment}));return}n&&o(n=>({...n,activeReviewTarget:{filePath:e,changeKey:t,commentKey:r},editingReviewCommentKey:null,reviewDraftInput:``}))},[n,o,P]),se=(0,p.useCallback)(()=>{o(e=>({...e,activeReviewTarget:null,editingReviewCommentKey:null,reviewDraftInput:``}))},[o]),ce=(0,p.useCallback)(e=>{let t=P.has(e.commentKey);if(!n&&!t)return;let r=N.trim();if(!r)return;let i=e.change.type===`insert`?null:`oldLineNumber`in e.change?e.change.oldLineNumber:e.change.lineNumber,a=e.change.type===`delete`?null:`newLineNumber`in e.change?e.change.newLineNumber:e.change.lineNumber;o(t=>{let n=new Map(t.reviewComments.map(e=>[qM(e.filePath,e.changeKey),e]));return n.set(e.commentKey,{scope:`uncommitted`,filePath:e.filePath,changeKey:e.changeKey,changeType:e.change.type,oldLineNumber:i,newLineNumber:a,hunkHeader:e.hunk.content,lineContent:e.change.content,diffSnippet:JM(e.hunk,e.change),comment:r}),{...t,activeReviewTarget:null,editingReviewCommentKey:null,reviewDraftInput:``,reviewComments:[...n.values()]}})},[n,o,P,N]),le=(0,p.useCallback)(e=>{let t=P.get(e);t&&o(n=>({...n,selectedDiffPath:t.filePath,activeReviewTarget:null,editingReviewCommentKey:e,reviewDraftInput:t.comment}))},[o,P]),ue=(0,p.useCallback)(e=>{o(t=>({...t,activeReviewTarget:t.activeReviewTarget?.commentKey===e?null:t.activeReviewTarget,editingReviewCommentKey:t.editingReviewCommentKey===e?null:t.editingReviewCommentKey,reviewDraftInput:t.activeReviewTarget?.commentKey===e||t.editingReviewCommentKey===e?``:t.reviewDraftInput,reviewComments:t.reviewComments.filter(t=>qM(t.filePath,t.changeKey)!==e)}))},[o]),de=(0,p.useCallback)(async()=>{if(!ae)return;w(!0);let e=QM({drafts:re,findings:[],githubComments:[],uncommittedFiles:z});try{await i(e),G(),$.success(F8(`toasts.sendChangesSuccess`),{id:`chat-diff-review-submit-success`})}catch(e){$.error(B8(e,F8(`errors.sendChanges`)),{id:`chat-diff-review-submit-error`})}finally{w(!1)}},[ae,G,i,z,re]),fe=(0,p.useCallback)(e=>(0,X.jsx)(A3,{reviewComments:re,pendingFixCount:ie,triggerMode:e===`wide`?`full`:`compact`,canSendReview:ae,isSubmittingReview:C,reviewSubmitDisabledReason:r??void 0,onClearPendingFixes:G,onSubmitReview:()=>{de()}}),[ae,G,de,C,ie,re,r]),pe=c?(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":F8(`closeAriaLabel`),className:`text-muted-foreground hover:text-foreground`,onClick:c,children:(0,X.jsx)(ax,{className:`h-4 w-4`})}):null,me=l?{"--chat-changes-panel-width":`${l}px`}:void 0;return(0,X.jsx)(`aside`,{"data-testid":`chat-changes-panel`,"data-desktop-width":l?String(l):void 0,ref:u,style:me,className:Z(`flex h-[26rem] min-h-0 w-full shrink-0 flex-col overflow-hidden border-t border-border/70 bg-background/20 xl:h-full xl:border-l xl:border-t-0`,l?`xl:w-[var(--chat-changes-panel-width)]`:`xl:w-[32rem]`),children:(0,X.jsx)(X3,{selectedDiffPath:k,sidebarFiles:B,diffResponse:d,isDiffLoading:v,diffError:g,allDiffFiles:ne,renderedFiles:te,viewType:`unified`,onViewTypeChange:()=>{},onRetry:()=>{L()},activeReviewTarget:A,editingReviewCommentKey:j,reviewDraftInstanceKey:M,reviewDraftInput:N,reviewComments:re,reviewFindings:[],githubComments:[],selectedReviewFindingIds:[],selectedGitHubCommentIds:[],canSelectReviewTarget:n,canEditActiveReviewDraft:n,reviewFindingsError:null,gitHubCommentsError:null,hasStaleReviewFindings:!1,onSelectReviewTarget:oe,onToggleReviewFindingSelection:()=>{},onToggleGitHubCommentSelection:()=>{},onReviewDraftInputChange:e=>{o(t=>({...t,reviewDraftInput:e}))},onCancelReviewDraft:se,onEditReviewDraft:le,onRemoveReviewDraft:ue,onSaveReviewDraft:ce,diffThemeClassName:Q3,resolveFilePath:R8,normalizeDiffPath:I8,emptyStateTitle:F8(`emptyStateTitle`),emptyStateDescription:F8(`emptyStateDescription`),filePickerControl:e=>(0,X.jsx)(Vme,{selectedDiffPath:k,sidebarFiles:B,diffStats:d?.stats??null,triggerMode:e===`wide`?`full`:`compact`,onSelectDiffPath:e=>{o(t=>({...t,selectedDiffPath:e}))}}),reviewSummaryControl:fe,extraHeaderControl:pe,surfaceVariant:`flat`,showViewTypeToggle:!1,gutterVariant:`compact`,isResizing:s,resizePlaceholderLineThreshold:200})})});H8.displayName=`ChatChangesPanel`;var U8=({projectId:e,agentRunParentType:t=null,agentRunParentId:n=null,messages:r,internalLog:i,currentThinkingMessageId:a=null,previousThinkingLog:o=null,previousThinkingMessageId:s=null,pendingAgentTitle:c,streamingResponse:l,isRunning:u,isLoading:d=!1,canShowComposer:f,cardClassName:p,isExternallyResizing:m=!1,pendingAgentRevealKey:h=null,pendingAgentRevealDelayMs:g=0,liveResponseTiming:_=null,composerFocusNonce:v=0,blurComposerOnSendStart:y=!1,hidePendingAgentTitle:b=!1,forceScrollToBottomKey:x,header:S,composerControls:C,composerInlineControls:w,composerTheme:T=`default`,layoutKey:E,scrollLayoutKey:D,followUpPrompt:O,draftAttachments:k=[],followUpPlaceholder:A,emptyStateText:j=null,renderMessageFooter:M,renderMessageBody:N,isSendingFollowUp:P,isComposerSubmitDisabled:F=!1,isUploadingAttachments:I=!1,canAttachImages:L=!1,followUpDisabledReason:R,postBuildCheck:z=null,onFollowUpPromptChange:ee,onFollowUpKeyDown:B,onFollowUpPaste:V,onUploadAttachments:H,onRemoveAttachment:U,onFollowUpSubmit:W})=>(0,X.jsx)(BJ,{projectId:e,agentRunParentType:t,agentRunParentId:n,messages:r,internalLog:i,currentThinkingMessageId:a,previousThinkingLog:o,previousThinkingMessageId:s,pendingAgentTitle:c,streamingResponse:l,isRunning:u,isLoading:d,autoScrollBehavior:`sticky`,surfaceVariant:`chat`,canShowComposer:f,cardClassName:p,header:S,composerControls:C,composerInlineControls:w,composerTheme:T,composerSize:`compact-on-laptop`,showThinkingPlacement:`header`,pinComposerToBottom:!0,isExternallyResizing:m,pendingAgentRevealKey:h,pendingAgentRevealDelayMs:g,liveResponseTiming:_,composerFocusNonce:v,blurComposerOnSendStart:y,forceScrollToBottomKey:x,layoutKey:E,scrollLayoutKey:D,followUpPrompt:O,draftAttachments:k,followUpPlaceholder:A,emptyStateText:j,autoFocusComposer:!0,renderMessageFooter:M,renderMessageBody:N,isSendingFollowUp:P,isComposerSubmitDisabled:F,isUploadingAttachments:I,canAttachImages:L,followUpDisabledReason:R,postBuildCheck:z,hidePendingAgentTitle:b,onFollowUpPromptChange:ee,onFollowUpKeyDown:B,onFollowUpPaste:V,onUploadAttachments:H,onRemoveAttachment:U,onFollowUpSubmit:W}),W8=({disabled:e=!1,onClick:t})=>{let n=qb.t(`chatView.startBuilding.label`);return(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`gap-2 border-emerald-400/40 bg-emerald-400/10 text-emerald-100 hover:bg-emerald-400/20 hover:text-white`,"aria-label":qb.t(`chatView.startBuilding.ariaLabel`),disabled:e,onClick:t,children:[(0,X.jsx)(kv,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:n})]})},Hme=`mt-1 flex min-h-5 flex-wrap items-center gap-2 text-xs text-muted-foreground`,Ume=({label:e})=>(0,X.jsx)(`div`,{className:`inline-flex items-center rounded-full border border-amber-500/30 bg-amber-500/10 px-2 py-0.5 text-[11px] font-medium text-amber-100`,children:e}),G8=({title:e,tool:t=null,modelLabel:n=null,interrupted:r=!1,interruptedLabel:i,usage:a=null,metadataExtra:o=null,actions:s=null,warnings:c=null})=>(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`h3`,{className:`truncate text-sm font-semibold text-foreground`,children:e}),(0,X.jsxs)(`div`,{className:Hme,children:[(0,X.jsx)(jF,{tool:t,className:`text-[11px]`}),n?(0,X.jsx)(`p`,{children:n}):null,r?(0,X.jsx)(Ume,{label:i}):null,a?(0,X.jsx)(MF,{totalTokens:a.totalTokens,contextWindow:a.contextWindow,cost:a.cost,tool:a.tool,model:a.model,availableModels:a.availableModels}):null,o]})]}),s]}),c]}),K8=({projectId:e,suggestions:t,title:n,description:r,emptyState:i=null,onSuggestionsChanged:a})=>(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(n||r)&&(0,X.jsxs)(`div`,{children:[n&&(0,X.jsx)(`h4`,{className:`text-xs font-semibold uppercase tracking-[0.2em] text-muted-foreground`,children:n}),r&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r})]}),t.length>0?(0,X.jsx)(Pw,{projectId:e,suggestions:t,onChanged:(e,t)=>a?.(e,t)}):i&&(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border/70 px-3 py-4 text-sm text-muted-foreground`,children:i})]}),q8=()=>({selectedDiffPath:`all`,activeReviewTarget:null,editingReviewCommentKey:null,reviewDraftInput:``,reviewComments:[]}),Wme=[{key:`today`,label:`Today`},{key:`yesterday`,label:`Yesterday`},{key:`last_7_days`,label:`Last 7 Days`},{key:`older`,label:`Older`}],Gme=e=>{if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t},J8=e=>e.activity_at??e.last_user_message_at??e.created_at,Kme=(e,t)=>{let n=J8(e),r=J8(t);return n===r?e.created_at===t.created_at?t.id.localeCompare(e.id):t.created_at.localeCompare(e.created_at):r.localeCompare(n)},Y8=e=>[...e].sort(Kme),qme=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),Jme=(e,t=new Date)=>{let n=Gme(J8(e));if(!n)return`older`;let r=qme(t),i=new Date(r);i.setDate(i.getDate()-1);let a=new Date(r);return a.setDate(a.getDate()-6),n>=r?`today`:n>=i?`yesterday`:n>=a?`last_7_days`:`older`},X8=(e,t=new Date)=>{let n=new Map;for(let r of Y8(e)){let e=Jme(r,t);n.set(e,[...n.get(e)??[],r])}return Wme.flatMap(e=>{let t=n.get(e.key)??[];return t.length===0?[]:[{key:e.key,label:e.label,sessions:t}]})},Z8=e=>{let t={...e};return delete t.messages,t.agent_log=null,t.agent_message_id=null,t.previous_agent_log=null,t.previous_agent_message_id=null,t.streaming_response=null,t},Q8=e=>e===`claude`?qb.t(`chatView.tool.claude`):qb.t(`chatView.tool.opencode`),$8=e=>new Map(e.map(e=>[e.id,e.label])),e5=({availableModelsById:e,model:t})=>t?e.get(t)??t:null,t5=({modelLabel:e,tool:t})=>e??Q8(t),n5=()=>qb.t(`chatView.user.you`),r5=`archon.chat-draft`,i5=({projectId:e,tool:t,chatSessionId:n})=>n?`${r5}:${e}:session:${n}`:`${r5}:${e}:draft:${t}`,a5=e=>{if(!e)return``;try{return window.localStorage.getItem(e)??``}catch{return``}},o5=({storageKey:e,value:t})=>{if(e)try{if(t){window.localStorage.setItem(e,t);return}window.localStorage.removeItem(e)}catch{}},s5=({activeProject:e,activeProjectBranchState:t,session:n})=>!e||n.target_available===!1?!1:n.target_kind===`bundle`?e.active_target_kind===`bundle`&&!!n.target_bundle_id&&e.active_target_bundle_id===n.target_bundle_id:e.active_target_kind===`bundle`?!1:!t||!n.target_branch_snapshot?!0:t.status!==`ready`||!t.branch?!1:t.branch===n.target_branch_snapshot,c5=({session:e,activeProject:t,activeProjectBranchState:n})=>e.target_kind===`bundle`?e.target_label_snapshot||qb.t(`common:chatView.targets.bundleFallback`):!t||t.active_target_kind===`bundle`||n?.status!==`ready`||!n.branch||!e.target_branch_snapshot||n.branch===e.target_branch_snapshot?null:qb.t(`common:chatView.targets.repoRootWithBranch`,{branch:e.target_branch_snapshot}),l5=e=>e.target_kind===`bundle`?e.target_label_snapshot||qb.t(`common:chatView.targets.bundleFallback`):e.target_branch_snapshot?qb.t(`common:chatView.targets.repoRootWithBranch`,{branch:e.target_branch_snapshot}):qb.t(`common:chatView.targets.repoRoot`),u5=({activeProject:e,activeProjectBranchState:t})=>e?e.active_target_kind===`bundle`?qb.t(`common:chatView.targets.selectedBundleTarget`):t?.branch?qb.t(`common:chatView.targets.repoRootWithBranch`,{branch:t.branch}):qb.t(`common:chatView.targets.repoRoot`):qb.t(`common:chatView.targets.currentTarget`),d5=(e,t)=>qb.t(`chatView.${e}`,t),Yme=1500,Xme=`archon.chat-run-config`,Zme=`archon.chat-changes-panel-layout`,Qme=`archon.chat-session-list-layout`,f5=512,p5=360,$me=.6,ehe=6,m5=`/`,the=`Slash`,nhe=`NumpadDivide`,rhe=600,h5=4,g5=(e,t)=>{let n=Number.isFinite(e)?Math.round(e):f5;if(!Number.isFinite(t))return Math.max(p5,n);let r=Math.max(p5,Math.round(t*$me));return Math.max(p5,Math.min(r,n))},ihe=e=>d5(e===`plan`?`mode.plan`:`mode.build`),_5=e=>d5(e===`plan`?`placeholders.plan`:`placeholders.build`),v5=e=>d5(`pendingMemorySuggestions`,{count:e}),ahe=e=>!e.defaultPrevented&&!e.altKey&&!e.repeat&&(e.ctrlKey||e.metaKey)&&(e.key===m5||e.code===the||e.code===nhe),y5=({modifierLabel:e,keys:t,ariaHidden:n=!1})=>(0,X.jsxs)(`span`,{"aria-hidden":n,className:`flex items-center gap-0.5 text-[10px] leading-none`,children:[(0,X.jsx)(UY,{"aria-hidden":n,children:e}),t.map(e=>(0,X.jsxs)(`span`,{className:`contents`,children:[(0,X.jsx)(`span`,{children:`+`}),(0,X.jsx)(UY,{"aria-hidden":n,children:e})]},e))]}),ohe=({label:e,modifierLabel:t,keys:n})=>(0,X.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{children:e}),(0,X.jsx)(y5,{modifierLabel:t,keys:n,ariaHidden:!0})]}),b5=({projectId:e,tool:t})=>`${Xme}:${e}:${t}`,x5=e=>`${Zme}:${e}`,S5=e=>`${Qme}:${e}`,she=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(Boolean).filter((e,t,n)=>n.indexOf(e)===t):[],C5=e=>{if(!e)return{isOpen:!0,width:f5};try{let t=window.localStorage.getItem(x5(e));if(!t)return{isOpen:!0,width:f5};let n=JSON.parse(t),r=typeof n.width==`number`&&Number.isFinite(n.width)?Math.max(p5,Math.round(n.width)):f5;return{isOpen:n.isOpen!==!1,width:r}}catch{return{isOpen:!0,width:f5}}},w5=e=>{if(!e)return{isOpen:!0};try{let t=window.localStorage.getItem(S5(e));return t?{isOpen:JSON.parse(t).isOpen!==!1}:{isOpen:!0}}catch{return{isOpen:!0}}},che=({projectId:e,isOpen:t,width:n})=>{if(e)try{window.localStorage.setItem(x5(e),JSON.stringify({isOpen:t,width:n}))}catch{}},lhe=({projectId:e,isOpen:t})=>{if(e)try{window.localStorage.setItem(S5(e),JSON.stringify({isOpen:t}))}catch{}},T5=({projectId:e,tool:t})=>{if(!e||t!==`opencode`&&t!==`claude`)return null;try{let n=window.localStorage.getItem(b5({projectId:e,tool:t}));if(!n)return null;let r=JSON.parse(n),i=(typeof r.model==`string`?r.model.trim():``)||null,a=r.mode===`plan`||r.mode===`build`?r.mode:null;return!i&&!a?null:{model:i,variant:i&&typeof r.variant==`string`&&r.variant.trim()||null,mode:a,skills:she(r.skills)}}catch{return null}},E5=({projectId:e,tool:t,model:n,variant:r,mode:i,skills:a})=>{if(!(!e||t!==`opencode`&&t!==`claude`||!n&&!i))try{window.localStorage.setItem(b5({projectId:e,tool:t}),JSON.stringify({model:n,variant:n?r:null,mode:i,skills:a}))}catch{}},uhe=({projectId:e,tool:t})=>{let n=T5({projectId:e,tool:t});!n||n.skills.length===0||E5({projectId:e,tool:t,...n,skills:[]})},D5=({projectId:e,tool:t})=>T5({projectId:e,tool:t})?.mode??`plan`,O5=({activeProjectId:e,helperModel:t,helperVariant:n,activeTool:r,availableModels:i,availableSkills:a})=>{let o=T5({projectId:e,tool:r}),s=t??``,c=o?.model??``,l=xF(c,i)?c:xF(s,i)?s:``,u=l===c?o?.variant??null:l&&l===s?n??null:null,d=i.find(e=>e.id===l)??null,f=d?d.variants.includes(u??``)?u??``:``:l?u??``:``,p=new Set(a.map(e=>e.name));return{model:l,variant:f,mode:o?.mode??`plan`,skills:r===`opencode`?(o?.skills??[]).filter(e=>p.has(e)):[]}},k5=e=>e&&e.replace(/\s+/g,` `).trim()||null,dhe=e=>{let t=k5(e.first_user_message_preview);if(t)return t;let n=e.messages?.find(e=>e.role===`user`)?.content;return k5(n)},fhe=({chatSessionId:e,instruction:t,attachments:n,createdAt:r})=>({id:`optimistic:${e}:${r}`,chat_session_id:e,role:`user`,kind:`prompt`,content:t,attachments:n,created_at:r}),phe=({session:e,instruction:t,attachments:n,createdAt:r})=>({...e,messages:[...e.messages??[],fhe({chatSessionId:e.id,instruction:t,attachments:n,createdAt:r})],activity_at:r,last_user_message_at:r,updated_at:r}),mhe=e=>!!(e.first_user_message_preview||e.last_user_message_at||e.messages?.some(e=>e.role===`user`)),A5=e=>e.agent_status===`running`?d5(`sidebar.deleteDisabledReason`):null,hhe=({proposals:e,isApplying:t,onApply:n})=>e.status===`applied`?(0,X.jsxs)(`div`,{className:`w-full rounded-md border border-emerald-500/30 bg-emerald-500/10 px-3 py-3 text-sm`,children:[(0,X.jsx)(`div`,{className:`font-medium text-foreground`,children:d5(`ticketProposal.createdTitle`)}),(0,X.jsx)(`div`,{className:`mt-1 text-muted-foreground`,children:d5(`ticketProposal.createdDescription`,{count:e.created_tickets.length})}),e.created_tickets.length>0?(0,X.jsx)(`ul`,{className:`mt-3 space-y-1 text-foreground`,children:e.created_tickets.map(e=>(0,X.jsx)(`li`,{children:e.title},e.ticket_id))}):null]}):(0,X.jsxs)(`div`,{className:`w-full rounded-md border border-sky-500/30 bg-sky-500/10 px-3 py-3 text-sm`,children:[(0,X.jsx)(`div`,{className:`font-medium text-foreground`,children:d5(`ticketProposal.proposedTitle`)}),(0,X.jsx)(`div`,{className:`mt-1 text-muted-foreground`,children:d5(`ticketProposal.proposedDescription`)}),(0,X.jsx)(`ul`,{className:`mt-3 space-y-3`,children:e.tickets.map(e=>(0,X.jsxs)(`li`,{className:`rounded border border-border/60 bg-background/80 px-3 py-2`,children:[(0,X.jsx)(`div`,{className:`font-medium text-foreground`,children:e.title}),(0,X.jsx)(`div`,{className:`mt-1 whitespace-pre-wrap text-muted-foreground`,children:e.description})]},e.key))}),e.dependencies.length>0?(0,X.jsx)(`div`,{className:`mt-3 text-muted-foreground`,children:d5(`ticketProposal.dependenciesLabel`,{value:e.dependencies.map(e=>`${e.blocker_key} -> ${e.dependent_key}`).join(`, `)})}):null,(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(Q,{type:`button`,size:`sm`,onClick:n,disabled:t,children:d5(t?`ticketProposal.creating`:`ticketProposal.create`)})})]}),ghe=({activeProjectId:e,activeProject:t,activeProjectBranchState:n=null,targetBundles:r=[],targetBranchSuggestions:i={current_branch:null,default_branch:null,previous_branch:null},isTargetBundleLoading:a=!1,isTargetSelectorLoading:o=!1,onTargetSelectorOpenChange:s,onSelectBundleTarget:c=async()=>!1,onSelectRepoRootTarget:l=async()=>!1,activeTool:u,routedChatSessionId:d,onRoutedChatNavigationUnavailable:f,onSessionNavigation:m,initialDraftOpen:h=!1,onInitialDraftOpenConsumed:g,initialSpecDraft:_=null,onInitialSpecDraftConsumed:v,onViewSourceSpec:y,onNavigateToLifecycleSource:b,onRestoreSessionTarget:x,onReviewCapabilityChange:S,isExternallyResizing:C=!1,showChangesPanel:w=!0})=>{let T=uq(),[E,D]=(0,p.useState)([]),[O,k]=(0,p.useState)(null),[A,j]=(0,p.useState)(null),M=pF(A?.post_build_check),[N,P]=(0,p.useState)(null),[F,I]=(0,p.useState)(!1),[L,R]=(0,p.useState)(null),[z,ee]=(0,p.useState)(()=>D5({projectId:e,tool:u})),[B,V]=(0,p.useState)({}),[H,U]=(0,p.useState)({}),[W,te]=(0,p.useState)({}),[ne,re]=(0,p.useState)([]),[ie,ae]=(0,p.useState)(``),[G,oe]=(0,p.useState)(``),[se,ce]=(0,p.useState)([]),[le,ue]=(0,p.useState)(!1),[de,fe]=(0,p.useState)(!1),[pe,me]=(0,p.useState)(!1),[he,ge]=(0,p.useState)(!1),[_e,ve]=(0,p.useState)(!1),[ye,be]=(0,p.useState)(null),[xe,Se]=(0,p.useState)([]),[Ce,we]=(0,p.useState)(()=>new Set),[Te,Ee]=(0,p.useState)(!1),[De,Oe]=(0,p.useState)(()=>new Set),[ke,Ae]=(0,p.useState)(!1),[je,Me]=(0,p.useState)(!1),[Ne,Pe]=(0,p.useState)(null),[Fe,Ie]=(0,p.useState)(null),[Le,K]=(0,p.useState)([]),[Re,ze]=(0,p.useState)(!1),[Be,Ve]=(0,p.useState)(!1),[He,q]=(0,p.useState)(0),[Ue,We]=(0,p.useState)(q8),[J,qe]=(0,p.useState)(()=>w5(e).isOpen),[Je,Xe]=(0,p.useState)(()=>C5(e).isOpen),[Ze,Y]=(0,p.useState)(!1),[Qe,$e]=(0,p.useState)(!1),[et,tt]=(0,p.useState)(()=>C5(e).width),[nt,rt]=(0,p.useState)(0),[it,at]=(0,p.useState)(null),[ot,st]=(0,p.useState)(()=>new Set),ct=(0,p.useRef)({model:``,variant:``,skills:[],showModelSelector:!1}),lt=(0,p.useRef)(!1),ut=(0,p.useRef)(L),dt=(0,p.useRef)(null),ft=(0,p.useRef)(null),pt=(0,p.useRef)(new Set),mt=(0,p.useRef)(0),ht=(0,p.useRef)(0),gt=(0,p.useRef)(d),_t=(0,p.useRef)(!1),vt=(0,p.useRef)(null),yt=(0,p.useRef)(null),bt=(0,p.useRef)(null),xt=(0,p.useRef)(null),St=(0,p.useRef)(null),Ct=(0,p.useRef)(null),wt=(0,p.useRef)(!1),Tt=(0,p.useRef)(!1),Et=(0,p.useRef)(0),Dt=(0,p.useRef)(f5),Ot=(0,p.useRef)(f5),kt=(0,p.useRef)(!1),At=(0,p.useRef)(0),jt=(0,p.useRef)({id:null,status:null}),Mt=(0,p.useRef)(new Map),Nt=(0,p.useRef)({}),Pt=(0,p.useRef)({}),Ft=(0,p.useRef)(new Set),It=(0,p.useRef)(!1),Lt=e?i5({projectId:e,tool:F?u:A?.tool??u,chatSessionId:F?null:O}):null,Rt=Lt?B[Lt]??``:``,zt=F?u:A?.tool??u,Bt=A?H[A.id]??[]:[],Vt=(A?W[A.id]??0:0)>0,{models:Ht,isLoading:Ut}=QP(zt),Wt=(0,p.useCallback)(()=>{ce([]),uhe({projectId:e,tool:u})},[e,u]);(0,p.useEffect)(()=>{lt.current=F},[F]),(0,p.useEffect)(()=>{Nt.current=B},[B]),(0,p.useEffect)(()=>{Pt.current=H},[H]),gt.current=d,(0,p.useEffect)(()=>{if(!(d===void 0||!de)){if(!d){lt.current||Wt(),P(null),be(null),k(null),j(null),I(!0);return}if(!(E.some(e=>e.id===d)||A?.id===d)){k(null),j(null),I(!1),f?.();return}O!==d&&(P(null),be(null),k(d),j(null),I(!1),kt.current=!0)}},[A?.id,O,de,f,Wt,d,E]),(0,p.useEffect)(()=>{if(!Lt||Ft.current.has(Lt))return;Ft.current.add(Lt);let e=a5(Lt);e&&V(t=>Object.prototype.hasOwnProperty.call(t,Lt)?t:{...t,[Lt]:e})},[Lt]),(0,p.useEffect)(()=>{!Lt||!Object.prototype.hasOwnProperty.call(B,Lt)||o5({storageKey:Lt,value:B[Lt]??``})},[Lt,B]),(0,p.useEffect)(()=>{if(!F){dt.current=null;return}let e=dt.current;!e||!Lt||Rt||V(t=>t[Lt]?t:{...t,[Lt]:e})},[F,Lt,Rt]),(0,p.useEffect)(()=>{ft.current=O},[O]),(0,p.useEffect)(()=>{ut.current=L},[L]);let Gt=(0,p.useCallback)(()=>{ht.current+=1},[]),Kt=(0,p.useCallback)(e=>{Gt(),j(e)},[Gt]);(0,p.useEffect)(()=>{if(!It.current){It.current=!0;return}let t=C5(e),n=w5(e);lt.current=!1,kt.current=!1,Ft.current=new Set,pt.current.clear(),k(null),Kt(null),I(!1),V({}),U({}),te({}),be(null),Se([]),we(new Set),Ee(!1),Oe(new Set),at(null),K([]),Ve(!1),fe(!1),We(q8()),st(new Set),Mt.current=new Map,Ot.current=t.width,qe(n.isOpen),tt(t.width),Xe(t.isOpen)},[e,Kt]),(0,p.useEffect)(()=>{Ze||(Ot.current=et,bt.current&&(bt.current.style.setProperty(`--chat-changes-panel-width`,`${et}px`),bt.current.setAttribute(`data-desktop-width`,String(et))))},[et,Ze]),(0,p.useEffect)(()=>{if(!w||!vt.current)return;let e=vt.current.getBoundingClientRect().width;if(e<=0)return;let t=g5(et,e);t!==et&&(Ot.current=t,tt(t))},[et,w]),(0,p.useEffect)(()=>{lhe({projectId:e,isOpen:J})},[e,J]),(0,p.useEffect)(()=>{w&&che({projectId:e,isOpen:Je,width:et})},[e,et,Je,w]),(0,p.useEffect)(()=>{Ve(!1)},[O,F]);let qt=(0,p.useCallback)(e=>{let t=Z8(e);D(e=>{let n=e.findIndex(e=>e.id===t.id);if(n===-1)return Y8([...e,t]);let r=[...e];return r[n]=t,Y8(r)})},[]),Jt=(0,p.useCallback)((t,n={})=>{let r=Array.from(new Set(t));if(r.length===0)return;let i=new Set(r),a=ft.current,o=n.preserveDraftRoute===!0,s=!!(o&&a&&i.has(a)&&gt.current===a),c=!!(!o&&a&&i.has(a)),l=c?E.find(e=>!i.has(e.id))??null:null;s&&(Wt(),m?.(null)),c&&(l||Wt(),m?.(l?.id??null));let d=e?r.map(t=>i5({projectId:e,tool:u,chatSessionId:t})):[];V(e=>{let t=d.filter(t=>Object.prototype.hasOwnProperty.call(e,t));if(t.length===0)return e;let n={...e};for(let e of t)delete n[e];return n}),U(e=>{let t={...e},n=!1;for(let e of r)Object.prototype.hasOwnProperty.call(t,e)&&(delete t[e],n=!0);return n?t:e}),te(e=>{let t={...e},n=!1;for(let e of r)Object.prototype.hasOwnProperty.call(t,e)&&(delete t[e],n=!0);return n?t:e});for(let e of d)o5({storageKey:e,value:``});D(e=>{let t=e.filter(e=>!i.has(e.id));if(a&&i.has(a)){if(gt.current===a)return o?(k(null),Kt(null),I(!0),t):(k(null),Kt(null),I(l===null),K([]),ze(!1),Ve(!1),t);let e=t[0]??null;k(e?.id??null),Kt(null),I(e===null),K([]),ze(!1),Ve(!1)}return t}),st(e=>{let t=new Set(e),n=!1;for(let e of r)t.delete(e)&&(n=!0);return n?t:e}),at(e=>e&&i.has(e.parentId)?null:e),be(e=>e&&i.has(e)?null:e),Se(e=>e.filter(e=>!i.has(e))),we(e=>{let t=new Set(e),n=!1;for(let e of r)t.delete(e)&&(n=!0);return n?t:e}),Oe(e=>{let t=new Set(e),n=!1;for(let e of r)t.delete(e)&&(n=!0);return n?t:e})},[e,u,m,Kt,Wt,E]),Yt=(0,p.useCallback)((e,t)=>{Jt([e],t)},[Jt]),Xt=(0,p.useCallback)((e,t)=>{e&&V(n=>n[e]===t?n:{...n,[e]:t})},[]),Zt=(0,p.useCallback)(e=>{e&&(V(t=>t[e]===``?t:{...t,[e]:``}),o5({storageKey:e,value:``}))},[]),Qt=(0,p.useCallback)((e,t)=>{U(n=>{if(t.length===0){if(!Object.prototype.hasOwnProperty.call(n,e))return n;let t={...n};return delete t[e],t}return{...n,[e]:t}})},[]),$t=(0,p.useCallback)(e=>{U(t=>{if(!Object.prototype.hasOwnProperty.call(t,e))return t;let n={...t};return delete n[e],n}),te(t=>{if(!Object.prototype.hasOwnProperty.call(t,e))return t;let n={...t};return delete n[e],n})},[]),en=(0,p.useCallback)((e,t)=>{te(n=>{let r=Math.max(0,(n[e]??0)+t);if(r===0){if(!Object.prototype.hasOwnProperty.call(n,e))return n;let t={...n};return delete t[e],t}return{...n,[e]:r}})},[]),tn=(0,p.useCallback)(({fromStorageKey:e,toStorageKey:t})=>{if(!e||!t||e===t)return;let n=Object.prototype.hasOwnProperty.call(Nt.current,e)?Nt.current[e]??``:a5(e);V(r=>{let i={...r,[t]:n};return delete i[e],i}),o5({storageKey:t,value:n}),o5({storageKey:e,value:``})},[]),nn=(0,p.useCallback)((e,t)=>{D(n=>{let r=n.findIndex(t=>t.id===e);if(r===-1)return n;let i=n[r];if(i.pending_memory_suggestion_count===t)return n;let a=[...n];return a[r]={...i,pending_memory_suggestion_count:t},a}),j(n=>!n||n.id!==e||n.pending_memory_suggestion_count===t?n:(ht.current+=1,{...n,pending_memory_suggestion_count:t}))},[]),rn=(0,p.useCallback)(async r=>{if(!e){D([]),k(null),Kt(null),I(!1),fe(!1);return}ue(!0);try{let i=await uN(e,r);if(r?.aborted)return;let a=Y8(i.map(Z8)),o=a[0]??null,s=t?.active_target_kind===`bundle`||n?.status!==`loading`;D(a),fe(!0),k(e=>d===void 0?lt.current?null:e&&a.some(t=>t.id===e)?e:e?a[0]?.id??null:kt.current?null:o?s?(kt.current=!0,s5({activeProject:t,activeProjectBranchState:n,session:o})?o.id:null):null:(kt.current=!0,null):e),a.length===0&&!d&&!lt.current&&(Wt(),I(!0))}catch(e){Ye(e)||$.error(e instanceof Error?e.message:d5(`errors.loadSessions`))}finally{r?.aborted||ue(!1)}},[t,n,e,Wt,Kt,d]),an=(0,p.useCallback)(async(t,n)=>{if(!e){Kt(null);return}me(!0);let r=mt.current+1;mt.current=r;let i=ht.current;try{let a=await dN(e,t,n);if(n?.aborted)return;let o=ht.current!==i,s=mt.current===r,c=ft.current===t&&!lt.current;if(!s||o||!c)return;Kt(a),qt(a)}catch(e){e instanceof Ge&&e.status===404&&gt.current===t&&ft.current===t?f?.():Ye(e)||$.error(e instanceof Error?e.message:d5(`errors.loadSession`))}finally{n?.aborted||me(!1)}},[e,f,Kt,qt]),on=(0,p.useCallback)(async(n,r)=>{if(!e||!t?.memory_enabled){K([]),ze(!1);return}ze(!0);try{let t=await Ar(e,null,r,n);if(r?.aborted)return;K(t.suggestions),nn(n,t.suggestions.length)}catch(e){Ye(e)||$.error(e instanceof Error?e.message:d5(`errors.loadMemorySuggestions`))}finally{r?.aborted||ze(!1)}},[t?.memory_enabled,e,nn]),sn=(0,p.useCallback)(e=>{K(t=>{let n=t.filter(t=>t.id!==e);return O&&nn(O,n.length),n}),q(e=>e+1),rn(),O&&an(O)},[O,an,rn,nn]);(0,p.useEffect)(()=>{let e=new AbortController;return rn(e.signal),()=>{e.abort()}},[rn]),(0,p.useEffect)(()=>{if(d!==void 0||lt.current||F||O||kt.current||E.length===0||t?.active_target_kind!==`bundle`&&n?.status===`loading`)return;kt.current=!0;let e=E[0]??null;e&&s5({activeProject:t,activeProjectBranchState:n,session:e})&&k(e.id)},[t,n,O,F,d,E]),(0,p.useEffect)(()=>{if(zt!==`opencode`&&zt!==`claude`){re([]),Me(!1);return}if(zt!==`opencode`){re([]);return}let t=new AbortController;return(async()=>{Me(!0);try{re(await $P(zt,t.signal,e))}catch(e){Ye(e)||re(e=>e)}finally{t.signal.aborted||Me(!1)}})(),()=>{t.abort()}},[e,zt]),(0,p.useEffect)(()=>{if(F||!O){Kt(null);return}if(A?.id===O)return;Kt(null);let e=new AbortController;return an(O,e.signal),()=>{e.abort()}},[A,O,F,an,Kt]),(0,p.useEffect)(()=>{if(!t?.memory_enabled||F||!O){K([]),ze(!1);return}let e=new AbortController;return on(O,e.signal),()=>{e.abort()}},[t?.memory_enabled,O,F,on,He]),(0,p.useEffect)(()=>{!Be||Re||Le.length>0||Ve(!1)},[Re,Be,Le.length]),(0,p.useEffect)(()=>{if(!O||A?.agent_status!==`running`)return;let e=new AbortController,t=window.setInterval(()=>{Promise.all([rn(e.signal),an(O,e.signal)])},Yme);return()=>{e.abort(),window.clearInterval(t)}},[A?.agent_status,O,an,rn]),(0,p.useEffect)(()=>{if(!e)return;let t=t=>{!t||t.project_id!==e||(t.id===O&&Kt(t),mhe(t)&&qt(t))},n=t=>{if(!t||t.project_id!==e)return;let n=pt.current.delete(t.id);Yt(t.id,n?{preserveDraftRoute:!0}:void 0)},r=()=>{rn();let e=ft.current;e&&!lt.current&&an(e)};return T.on(`connect`,r),T.on(`chat-session:created`,t),T.on(`chat-session:updated`,t),T.on(`chat-session:deleted`,n),()=>{T.off(`connect`,r),T.off(`chat-session:created`,t),T.off(`chat-session:updated`,t),T.off(`chat-session:deleted`,n)}},[e,O,an,rn,Yt,Kt,T,qt]),(0,p.useEffect)(()=>{F&&(ut.current||ee(D5({projectId:e,tool:u})))},[e,u,F]),(0,p.useEffect)(()=>{if(zt!==`opencode`&&zt!==`claude`){ae(``),oe(``),ce([]);return}if(F){let n=ew(t?.helper_models,zt),r=O5({activeProjectId:e,helperModel:n.model??(zt===`opencode`?t?.helper_model:null)??null,helperVariant:n.variant??(zt===`opencode`?t?.helper_variant:null)??null,activeTool:zt,availableModels:Ht,availableSkills:ne});ae(r.model),oe(r.variant),ce(r.skills);return}ae(A?.model??``),oe(A?.variant??``)},[e,t?.helper_model,t?.helper_models,t?.helper_variant,A?.id,A?.model,A?.variant,Ht,ne,zt,F]),(0,p.useEffect)(()=>{if(zt!==`opencode`){ce([]);return}F||ce(A?.skills??[])},[A?.skills,zt,F]),(0,p.useEffect)(()=>{let e=Ht.find(e=>e.id===ie)??null;oe(t=>e?e.variants.includes(t)?t:``:t)},[Ht,ie]),(0,p.useEffect)(()=>{if(zt!==`opencode`||!F||!ie||G)return;let n=ew(t?.helper_models,zt),r=O5({activeProjectId:e,helperModel:n.model??(zt===`opencode`?t?.helper_model:null)??null,helperVariant:n.variant??(zt===`opencode`?t?.helper_variant:null)??null,activeTool:zt,availableModels:Ht,availableSkills:ne});r.model===ie&&r.variant&&oe(r.variant)},[e,t?.helper_model,t?.helper_models,t?.helper_variant,zt,Ht,ne,F,ie,G]),(0,p.useEffect)(()=>{if(!ye)return;let e=A?.id===ye?A:E.find(e=>e.id===ye)??null;(!e||e.agent_status!==`running`)&&be(null)},[A,ye,E]),(0,p.useEffect)(()=>{let e=jt.current,n=A?.id??null,r=A?.agent_status??null;e.id===n&&e.status===`running`&&r===`done`&&t?.memory_enabled&&n&&q(e=>e+1),jt.current={id:n,status:r}},[t?.memory_enabled,e,A?.agent_status,A?.id,A?.title]),(0,p.useEffect)(()=>{O&&st(e=>{if(!e.has(O))return e;let t=new Set(e);return t.delete(O),t})},[O]),(0,p.useEffect)(()=>{it&&(it.parentId===O&&(_e||A?.agent_status===`running`)||at(null))},[A?.agent_status,O,_e,it]),(0,p.useEffect)(()=>{let e=Mt.current,t=new Map,n=[];for(let r of E){let i=e.get(r.id)??null,a=r.agent_status??null;i===`running`&&a===`done`&&r.id!==O&&n.push(r),t.set(r.id,a)}Mt.current=t,st(e=>{let t=new Set(e),r=!1,i=new Set(E.map(e=>e.id));for(let e of t)i.has(e)||(t.delete(e),r=!0);for(let e of E){let i=e.agent_status??null,a=n.some(t=>t.id===e.id);if((e.id===O||i!==`done`)&&t.delete(e.id)){r=!0;continue}a&&!t.has(e.id)&&(t.add(e.id),r=!0)}return r?t:e})},[e,O,E]);let cn=(0,p.useMemo)(()=>$8(Ht),[Ht]),ln=(0,p.useMemo)(()=>X8(E),[E]),un=(0,p.useMemo)(()=>{let e=new Set(ln.find(e=>e.key===`older`)?.sessions.map(e=>e.id)??[]);return[{key:`unavailable`,label:d5(`sidebar.presets.unavailable`),matches:e=>e.target_available===!1},{key:`older`,label:d5(`sidebar.presets.older`),matches:t=>e.has(t.id)}]},[ln]),dn=(0,p.useMemo)(()=>xe.length===0?[]:xe.flatMap(e=>{let t=E.find(t=>t.id===e)??(A?.id===e?A:null);return t?[t]:[]}),[A,xe,E]),fn=dn.length===1?dn[0]?.title??null:null;(0,p.useEffect)(()=>{xe.length>0&&dn.length!==xe.length&&Se(dn.map(e=>e.id))},[xe,dn]),(0,p.useEffect)(()=>{let e=new Set(E.filter(e=>!A5(e)&&!Ce.has(e.id)).map(e=>e.id));Oe(t=>{let n=new Set(Array.from(t).filter(t=>e.has(t)));return n.size===t.size?t:n})},[Ce,E]),(0,p.useEffect)(()=>{!Te||J||(Ee(!1),Oe(new Set))},[J,Te]);let pn=(0,p.useMemo)(()=>A?t5({modelLabel:e5({availableModelsById:cn,model:A.model}),tool:A.tool}):null,[A,cn]),mn=(0,p.useMemo)(()=>A?(A.messages??[]).map(e=>({id:e.id,role:e.role,kind:e.kind,content:e.content,attachments:e.attachments??[],ticket_proposals:e.ticket_proposals??null,transcript_runs:e.transcript_runs??null,metadata:e.metadata,responseTiming:e.response_timing?KK(e.response_timing):null,created_at:e.created_at,displayTitle:e.role===`assistant`?pn??Q8(A.tool):n5()})):[],[A,pn]),hn=(0,p.useMemo)(()=>[...A?.messages??[]].reverse().find(e=>e.metadata?.ask_question?.status===`pending`)??null,[A]),gn=!!hn,_n=(0,p.useCallback)(async(t,n)=>{if(!e||!A||Fe)return;let r=UJ({parentType:`chat`,parentId:A.id,setId:n.set_id});Ie(n.set_id);try{let r=await Tae(e,A.id,t,n);Kt(r),qt(r)}catch(e){if(e instanceof Ge&&e.status===409){GJ(r);let t=e.data&&typeof e.data==`object`&&`chat_session`in e.data?e.data.chat_session:null;t?(Kt(t),qt(t)):await an(A.id)}throw $.error(e instanceof Error?e.message:d5(`errors.resolveQuestions`)),e}finally{Ie(null)}},[e,A,an,Kt,Fe,qt]),vn=(0,p.useCallback)(e=>{let t=e.metadata?.ask_question;if(e.role!==`assistant`||!t||!A)return;let n=UJ({parentType:`chat`,parentId:A.id,setId:t.id});return(0,X.jsx)(QJ,{messageContent:e.content,questionSet:t,storageKey:n,isActive:t.status===`pending`&&hn?.id===e.id,isDisabled:A.agent_status===`running`||Fe===t.id,onResolve:t=>_n(e.id,t)})},[A,hn?.id,_n,Fe]),yn=A?.id&&A.agent_status===`running`&&it?.parentId===A.id?it.turnKey:null,bn=(zt===`opencode`||zt===`claude`)&&Ht.length>0,xn=(zt===`opencode`||zt===`claude`)&&!bn&&(je||Ut);(0,p.useEffect)(()=>{ct.current={model:ie,variant:G,skills:se,showModelSelector:bn}},[ie,se,G,bn]);let Sn=(0,p.useMemo)(()=>Ht.find(e=>e.id===ie)??null,[Ht,ie]),Cn=F?z:A?.mode??`build`,wn=F?d5(`composer.newChatTitle`):A?.title??d5(`composer.chatTitle`),Tn=F?u:A?.tool??u,En=(0,p.useMemo)(()=>qY(),[]),Dn=bn?ie||null:A?.model??null,On=Tn===`opencode`||Tn===`claude`,kn=e5({availableModelsById:cn,model:Dn}),An=F?`draft:${e??`none`}:${u}`:A?.id,jn=(0,p.useCallback)(({model:t=ie,variant:n=G,skills:r=se}={})=>{F&&E5({projectId:e,tool:u,model:bn&&t||null,variant:bn&&t&&n||null,mode:z,skills:bn&&u===`opencode`?r:[]})},[e,u,z,F,ie,se,G,bn]),Mn=(0,p.useCallback)(()=>{lt.current=!0,I(!0),Wt(),ee(D5({projectId:e,tool:u})),P(null),k(null),Kt(null),be(null),Ee(!1),Oe(new Set),at(null),R(null),dt.current=null,m?.(null)},[e,u,m,Kt,Wt]);(0,p.useEffect)(()=>{_&&(Mn(),ee(`build`),R({specSessionId:_.specSessionId,specSnapshotId:_.specSnapshotId}),dt.current=_.text,v?.())},[_,Mn,v]),(0,p.useEffect)(()=>{h&&(Mn(),g?.())},[h,Mn,g]);let Nn=(0,p.useCallback)((e,t=null)=>{lt.current=!1,I(!1),P(null),k(e),Kt(t),R(null),m?.(e)},[m,Kt]),Pn=(0,p.useCallback)(async()=>{if(!(!A||!x)){P(A.id);try{await x(A)}catch(e){$.error(e instanceof Error?e.message:d5(`errors.restoreTarget`))}finally{P(e=>e===A.id?null:e)}}},[A,x]),Fn=!!(A&&A.target_available!==!1&&!F&&!s5({activeProject:t,activeProjectBranchState:n,session:A})),In=Fn&&A?d5(`review.mismatchReason`,{sessionTarget:l5(A),currentTarget:u5({activeProject:t,activeProjectBranchState:n})}):null,Ln=Fn&&N===null,Rn=(0,p.useCallback)(async r=>{P(r.id);let i=r;if(e)try{let t=await dN(e,r.id);i=t,qt(t)}catch(e){$.error(e instanceof Error?e.message:d5(`errors.loadSession`)),P(e=>e===r.id?null:e);return}if(i.target_available===!1){Nn(i.id,i);return}if(!s5({activeProject:t,activeProjectBranchState:n,session:i})&&x)try{if(!await x(i)){P(e=>e===i.id?null:e);return}}catch(e){$.error(e instanceof Error?e.message:d5(`errors.restoreTarget`)),P(e=>e===i.id?null:e);return}Nn(i.id,i)},[t,n,e,x,Nn,qt]),zn=(0,p.useCallback)(()=>{rt(e=>e+1)},[]),Bn=(0,p.useCallback)(async t=>{if(F){let n=ct.current;return ee(t),E5({projectId:e,tool:u,model:n.showModelSelector&&n.model||null,variant:n.showModelSelector&&n.model&&n.variant||null,mode:t,skills:n.showModelSelector?n.skills:[]}),zn(),null}if(!e||!A||A.mode===t||ke||gn)return null;Ae(!0);try{let n=await Cae(e,A.id,{mode:t});return E5({projectId:e,tool:n.tool,model:n.model,variant:n.variant,mode:n.mode,skills:n.skills}),Kt(n),qt(n),zn(),n}catch(e){return $.error(e instanceof Error?e.message:d5(`errors.updateMode`)),null}finally{Ae(!1)}},[e,A,u,zn,gn,F,ke,Kt,qt]),Vn=(0,p.useCallback)(async({instruction:t,attachments:n,targetSession:r,startedAt:i})=>{if(!e)return null;let a=ct.current;At.current+=1;let o={parentType:`chat`,parentId:r.id,turnKey:`${r.id}:${At.current}`,startedAt:i};at(o);try{let i=await wae(e,r.id,{instruction:t,...n.length>0?{attachment_ids:n.map(e=>e.id)}:{},tool:r.tool,model:a.showModelSelector&&a.model||null,variant:a.showModelSelector&&a.model&&a.variant||null,skills:a.showModelSelector?a.skills:[]});return E5({projectId:e,tool:i.tool,model:i.model,variant:i.variant,mode:i.mode,skills:i.skills}),lt.current=!1,Kt(i),k(i.id),I(!1),qt(i),i}catch(e){throw at(e=>e?.turnKey===o.turnKey?null:e),e}},[e,Kt,qt]),Hn=(0,p.useCallback)(async({fromStorageKey:t})=>{if(!e)return null;let n=ct.current,r=ut.current,i=await xae(e,{mode:Cn,tool:u,model:n.showModelSelector&&n.model||null,variant:n.showModelSelector&&n.model&&n.variant||null,skills:n.showModelSelector?n.skills:[],originSpecSessionId:r?.specSessionId??null,originSpecSnapshotId:r?.specSnapshotId??null});lt.current=!1,I(!1),k(i.id),Kt(i),m?.(i.id),R(null);let a=i5({projectId:e,tool:i.tool,chatSessionId:i.id});return tn({fromStorageKey:t,toStorageKey:a}),{session:i,storageKey:a}},[e,u,Cn,tn,m,Kt]),Un=(0,p.useCallback)(async(t,n={})=>{let r=n.targetSession??A,i=!r||r.messages?.length===0;if(!e||_e||he||Vt||r?.agent_status===`running`||pF(r?.post_build_check)||r?.target_available===!1||Ln||gn)return!1;let a=t.trim(),o=n.preserveComposerDraft===!0,s=o?[]:r?Pt.current[r.id]??[]:[];if(!a&&s.length===0)return!1;ve(!0);let c=null,l=r,u=performance.now(),d=e&&r?i5({projectId:e,tool:r.tool,chatSessionId:r.id}):null,f=s;try{let t=r;if(!t){ge(!0);let e=await Hn({fromStorageKey:Lt});c=e?.session??null,t=c,d=e?.storageKey??null,f=c?Pt.current[c.id]??[]:[]}if(!t)return!1;o||Zt(d??Lt);let n=phe({session:t,instruction:a,attachments:f,createdAt:new Date().toISOString()});Kt(n),k(n.id),qt(n);let s=await Vn({instruction:a,attachments:f,targetSession:t,startedAt:u});return s&&i&&E5({projectId:e,tool:s.tool,model:s.model,variant:s.variant,mode:s.mode,skills:[]}),o||Zt(s&&e?i5({projectId:e,tool:s.tool,chatSessionId:s.id}):d),s&&!o&&$t(s.id),!0}catch(e){o||Xt(d??Lt,a);let t=Ke(e,`chat_session`);if(t?(lt.current=!1,Kt(t),k(t.id),I(!1),qt(t)):c?(Kt(c),k(c.id),I(!1),qt(c)):l&&(Kt(l),qt(l)),e instanceof Ge&&e.status===409&&!t){let e=c?.id??l?.id;e&&await an(e)}throw e}finally{ge(!1),ve(!1)}},[e,A,$t,Zt,Hn,Lt,gn,he,_e,Vt,an,Kt,Vn,Xt,Ln,qt]),Wn=(0,p.useCallback)(async()=>{if(!(!A||!KY(A,gn)||_t.current)){_t.current=!0;try{let e=await Bn(`build`);if(!e)return;await Un(GY,{preserveComposerDraft:!0,targetSession:e})}catch(e){$.error(e instanceof Error?e.message:d5(`errors.sendPrompt`))}finally{_t.current=!1}}},[A,Bn,gn,Un]),Gn=(0,p.useCallback)(e=>{lt.current=!0,I(!0),Wt(),ee(e),P(null),k(null),Kt(null),be(null),at(null)},[Kt,Wt]),Kn=(0,p.useCallback)(async t=>{if(e){pt.current.add(t.id);try{await fN(e,t.id),Yt(t.id,{preserveDraftRoute:!0}),Gn(t.mode)}catch(e){throw pt.current.delete(t.id),e}}},[e,Gn,Yt]),qn=(0,p.useCallback)(async t=>{if(!e||t.length===0||zt!==`opencode`&&zt!==`claude`)return;let n=t.slice(0,h5);if(n.length===0)return;let r=null,i=A;try{if(i||=(ge(!0),r=await Hn({fromStorageKey:Lt}),r?.session??null),!i)return;if((Pt.current[i.id]??[]).length+n.length>h5){$.error(`You can attach up to 4 images per turn.`);return}en(i.id,1);let t=await Eae(e,i.id,n),a=Pt.current[i.id]??[];Qt(i.id,[...a,...t.attachments])}catch(e){if(r&&!Rt.trim())try{await Kn(r.session)}catch{}$.error(e instanceof Error?e.message:d5(`errors.uploadAttachments`))}finally{i&&en(i.id,-1),ge(!1)}},[e,A,Hn,Kn,Rt,Lt,en,Qt,zt]),Jn=(0,p.useCallback)(async t=>{if(!e||!A)return;let n=(Pt.current[A.id]??[]).filter(e=>e.id!==t);try{await Dae(e,A.id,t),Qt(A.id,n),n.length===0&&!Rt.trim()&&(A.messages?.length??0)===0&&await Kn(A)}catch(e){$.error(e instanceof Error?e.message:d5(`errors.removeAttachment`))}},[e,A,Kn,Rt,Qt]),Yn=(0,p.useCallback)(e=>{if(zt!==`opencode`&&zt!==`claude`)return;let t=Array.from(e.clipboardData.items).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>e!==null);t.length!==0&&(e.preventDefault(),qn(t))},[zt,qn]),Xn=(0,p.useCallback)(async e=>{await Un(e)},[Un]),Zn=!!(e&&(F||A&&A.target_available!==!1&&!Ln)),Qn=A?.agent_status===`running`,$n=A?.agent_status===`stopped`,er=Qn&&ye===A?.id,tr=Zn&&!gn&&!Qn&&!M&&!_e&&!he&&!Vt,nr=Zn?A?.target_available===!1?A.target_unavailable_reason??d5(`review.unavailableTarget`):Ln?In??d5(`review.restoreTargetFallback`):gn?qb.t(`common:questionSet.waitForResolution`):Qn?d5(`review.waitTurn`):M?qb.t(`common:postBuildChecks.blockedReason`):Vt?d5(`review.waitUpload`):he||_e?d5(`review.waitPrompt`):null:d5(`review.missingTarget`),rr=(0,p.useCallback)(async()=>{if(!(!e||!A||A.agent_status!==`running`||er)){be(A.id);try{await Oae(e,A.id)}catch(e){be(e=>e===A.id?null:e),$.error(e instanceof Error?e.message:d5(`errors.interruptResponse`))}}},[e,A,er]),ir=(0,p.useCallback)(async()=>{if(!e||xe.length===0||Ce.size>0)return;let t=Array.from(new Set(xe)),n=Te||t.length>1;we(new Set(t));let r=await Promise.allSettled(t.map(async t=>(await fN(e,t),t))),i=[],a=[];for(let[e,n]of r.entries()){if(n.status===`fulfilled`){i.push(n.value);continue}a.push({sessionId:t[e]??``,message:n.reason instanceof Error?n.reason.message:null})}if(i.length>0&&Jt(i),we(new Set),a.length===0){Se([]),n&&(Ee(!1),Oe(new Set),$.success(d5(`toasts.deleteSelectedSuccess`,{count:i.length})));return}let o=a.map(e=>e.sessionId);if(Se(o),n&&Oe(new Set(o)),i.length>0){$.error(d5(`toasts.deleteSelectedPartial`,{count:i.length,deletedCount:i.length,failedCount:a.length}));return}$.error(a[0]?.message??d5(`errors.deleteSession`))},[e,xe,Ce,Te,Jt]),ar=(0,p.useMemo)(()=>E.some(e=>!A5(e)),[E]),or=(0,p.useCallback)((e,t)=>e.agent_status===`running`?`running`:e.agent_status===`stopped`?`interrupted`:!t&&ot.has(e.id)?`finished`:null,[ot]),sr=(0,p.useCallback)((e,n)=>[e.title,ihe(e.mode),Q8(e.tool),t?.memory_enabled&&e.pending_memory_suggestion_count>0?v5(e.pending_memory_suggestion_count):null,n===`running`?d5(`sidebar.running`):n===`interrupted`?d5(`sidebar.interrupted`):n===`finished`?d5(`sidebar.finished`):null].filter(Boolean).join(` `),[t]),cr=(0,p.useCallback)(({session:e,isActive:r,activityState:i})=>{let a=dhe(e),o=c5({session:e,activeProject:t,activeProjectBranchState:n}),s=i===`interrupted`?null:i;return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[o?(0,X.jsx)(`div`,{className:`mb-1 truncate text-[10px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75`,children:o}):null,(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`truncate text-[13px] font-medium leading-5`,children:e.title}),t?.memory_enabled&&e.pending_memory_suggestion_count>0?(0,X.jsx)(Ew,{tone:r?`default`:`muted`,className:`shrink-0`,"aria-label":v5(e.pending_memory_suggestion_count),title:v5(e.pending_memory_suggestion_count),children:e.pending_memory_suggestion_count}):null]}),a?(0,X.jsx)(`div`,{className:Z(`mt-0.5 line-clamp-1 text-xs leading-4`,r?`text-foreground/70`:`text-muted-foreground`),children:a}):null,e.target_available===!1?(0,X.jsx)(`div`,{className:`mt-1 line-clamp-1 text-[11px] leading-4 text-amber-200/90`,children:e.target_unavailable_reason??d5(`sidebar.targetUnavailable`)}):null]}),(0,X.jsx)(ib,{state:s,className:`mt-1`})]})},[t,n]),lr=(0,p.useMemo)(()=>({ariaLabel:d5(`sidebar.ariaLabel`),newSession:d5(`sidebar.newSession`),collapseAriaLabel:d5(`sidebar.collapseAriaLabel`),openAriaLabel:d5(`sidebar.openAriaLabel`),cancelSelection:d5(`sidebar.cancelSelection`),addPreset:d5(`sidebar.addPreset`),deleteSelected:d5(`sidebar.deleteSelected`),selectedCount:e=>d5(`sidebar.selectedCount`,{count:e}),select:d5(`sidebar.select`),loadingSessions:d5(`sidebar.loadingSessions`),noSessions:d5(`sidebar.noSessions`),deleteSessionAriaLabel:d5(`sidebar.deleteSessionAriaLabel`),selectSessionAriaLabel:e=>d5(`sidebar.selectSessionAriaLabel`,{title:e}),selectSessionTitle:e=>d5(`sidebar.selectSessionTitle`,{title:e}),deleteSessionTitle:e=>d5(`sidebar.deleteSessionTitle`,{title:e})}),[]),ur=(0,p.useMemo)(()=>({title:d5(`deleteSessionModal.title`),bulkTitle:d5(`deleteSessionModal.bulkTitle`),description:d5(`deleteSessionModal.description`),bulkDescription:e=>d5(`deleteSessionModal.bulkDescription`,{count:e}),cancel:d5(`deleteSessionModal.cancel`),delete:d5(`deleteSessionModal.delete`),deleting:d5(`deleteSessionModal.deleting`)}),[]),dr=(0,p.useMemo)(()=>(0,X.jsx)(y5,{modifierLabel:En,keys:[m5],ariaHidden:!0}),[En]),fr=(0,p.useMemo)(()=>(0,X.jsx)(ohe,{label:d5(`shortcuts.startNewSession`),modifierLabel:En,keys:[m5]}),[En]),pr=(0,p.useCallback)((e,t)=>{Oe(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]),mr=(0,p.useMemo)(()=>(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(HY,{value:Cn,planInactiveTooltip:(0,X.jsx)(QY,{label:d5(`shortcuts.switchToPlan`)}),buildInactiveTooltip:(0,X.jsx)(QY,{label:d5(`shortcuts.switchToBuild`)}),disabled:ke||gn,onChange:e=>{Bn(e)}}),Qn?(0,X.jsx)(N8,{isInterrupting:er,onStop:()=>{rr()},interruptLabel:d5(`review.interrupt`),interruptingLabel:d5(`review.interrupting`)}):null]}),[Cn,rr,Bn,gn,er,Qn,ke]),hr=(0,p.useMemo)(()=>(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(HY,{value:Cn,planInactiveTooltip:(0,X.jsx)(QY,{label:d5(`shortcuts.switchToPlan`)}),buildInactiveTooltip:(0,X.jsx)(QY,{label:d5(`shortcuts.switchToBuild`)}),disabled:ke||gn,onChange:e=>{Bn(e)}}),A&&KY(A,gn)&&(0,X.jsx)(W8,{disabled:_e||ke,onClick:()=>void Wn()}),F&&t&&(0,X.jsx)(Zy,{activeProject:t,branchState:n,bundles:r,branchSuggestions:i,isBundleLoading:a,isLoading:o,presentation:`composer`,closeAfterSelection:!0,triggerAriaLabel:qb.t(`common:projectTargetSelector.newChatAriaLabel`),onOpenChange:s,onSelectBundle:c,onSelectRepoRoot:l}),Qn&&(0,X.jsx)(N8,{isInterrupting:er,onStop:()=>{rr()},interruptLabel:d5(`review.interrupt`),interruptingLabel:d5(`review.interrupting`)})]}),[t,n,A,Cn,rr,Bn,Wn,gn,F,er,_e,Qn,a,o,ke,c,l,s,i,r]),gr=(0,p.useMemo)(()=>bn?(0,X.jsx)(_Y,{model:ie,variant:G,skills:se,showModelSelector:!0,showSkillsSelector:ne.length>0,availableModels:Ht,availableSkills:ne,selectedModel:Sn,onModelChange:e=>{let t=Ht.find(t=>t.id===e)??null,n=t&&t.variants.includes(G)?G:``;ae(e),oe(n),jn({model:e,variant:n})},onVariantChange:e=>{oe(e),jn({variant:e})},onSkillsChange:e=>{ce(e),jn({skills:e})},modelSelectId:`project-chat-model-selector`,variantSelectId:`project-chat-variant-selector`,skillsSelectId:`project-chat-skills-selector`,disabled:_e||he||A?.agent_status===`running`}):xn?(0,X.jsx)(gY,{dataTestId:`chat-model-selector-skeleton`}):null,[A?.agent_status,Ht,ne,he,_e,jn,Sn,ie,se,G,bn,xn]);(0,p.useEffect)(()=>{if(S)return()=>{S(null)}},[S]),(0,p.useEffect)(()=>{if(S){if(!e||!Zn){S(null);return}S({chatSessionId:A?.id??null,canSubmitReviewPrompt:tr,reviewSubmitDisabledReason:nr,mode:Cn,onModeChange:async e=>{await Bn(e)},isUpdatingMode:ke,promptPlaceholder:_5(Cn),promptComposerControls:mr,promptComposerInlineControls:gr,submitPrompt:Xn})}},[e,A,tr,Cn,Bn,Xn,Zn,ke,S,mr,gr,nr]);let _r=async()=>{if(!(!Rt.trim()&&Bt.length===0||Vt||gn||M))try{if(!await Un(Rt))return}catch(e){$.error(e instanceof Error?e.message:d5(`errors.sendPrompt`))}},vr=e=>{e.key!==`Enter`||e.shiftKey||A?.agent_status===`running`||M||he||_e||Vt||gn||(e.preventDefault(),_r())};(0,p.useEffect)(()=>{let t=t=>{if(ahe(t)){if(!e||he||_e)return;t.preventDefault(),Mn(),zn();return}YY(t)&&(!e||!F&&!A||(t.preventDefault(),Bn(JY(Cn))))};return window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`keydown`,t)}},[e,A,Cn,zn,Mn,Bn,he,F,_e]);let yr=(0,p.useCallback)(async t=>{if(!(!e||!A)){Pe(t);try{let n=await jae(e,A.id,t);Kt(n.chatSession),qt(n.chatSession),$.success(d5(`ticketProposal.createdFromChat`,{count:n.created_tickets.length}))}catch(e){$.error(e instanceof Error?e.message:d5(`errors.createTickets`))}finally{Pe(e=>e===t?null:e)}}},[e,A,Kt,qt]),br=(0,p.useCallback)(e=>e.ticket_proposals?(0,X.jsx)(hhe,{proposals:e.ticket_proposals,isApplying:Ne===e.id,onApply:()=>{yr(e.id)}}):null,[Ne,yr]),xr=(0,p.useCallback)(e=>{if(!vt.current)return;let t=vt.current.getBoundingClientRect().width,n=g5(e,t);Ot.current=n,bt.current&&(bt.current.style.setProperty(`--chat-changes-panel-width`,`${n}px`),bt.current.setAttribute(`data-desktop-width`,String(n)))},[]),Sr=(0,p.useCallback)(()=>{Ct.current?.(),Ct.current=null},[]),Cr=(0,p.useCallback)(e=>{let t=xt.current,n=St.current,r=wt.current;if(t!==null){if(xt.current=null,St.current=null,wt.current=!1,Y(!1),$e(!1),Sr(),e!==null&&typeof yt.current?.hasPointerCapture==`function`&&yt.current.hasPointerCapture(e)&&typeof yt.current.releasePointerCapture==`function`&&yt.current.releasePointerCapture(e),n===`collapsed`){if(!r)return;tt(Ot.current),Xe(!0);return}tt(Ot.current)}},[Sr]),wr=(0,p.useCallback)((e,t)=>{if(xt.current!==e)return;let n=t-Et.current,r=Dt.current-n;if(St.current===`collapsed`){if(!wt.current&&r<ehe)return;wt.current||(wt.current=!0,Tt.current=!0,$e(!0),Y(!0))}xr(r)},[xr]),Tr=(0,p.useCallback)((e,t)=>{if(xt.current===e){if(t!==null&&(St.current===`inline`||wt.current)){let e=t-Et.current;xr(Dt.current-e)}Cr(e)}},[Cr,xr]),Er=(0,p.useCallback)(e=>{if(!w)return;e.preventDefault(),xt.current=e.pointerId,St.current=Je?`inline`:`collapsed`,wt.current=!1,Tt.current=!1,Et.current=e.clientX,Dt.current=Je?Ot.current:0,Y(Je),Sr(),typeof e.currentTarget.setPointerCapture==`function`&&e.currentTarget.setPointerCapture(e.pointerId);let t=e=>{wr(e.pointerId,e.clientX)},n=e=>{Tr(e.pointerId,e.clientX)},r=e=>{Tr(e.pointerId,e.clientX)};window.addEventListener(`pointermove`,t),window.addEventListener(`pointerup`,n),window.addEventListener(`pointercancel`,r),Ct.current=()=>{window.removeEventListener(`pointermove`,t),window.removeEventListener(`pointerup`,n),window.removeEventListener(`pointercancel`,r)}},[Tr,wr,Je,w,Sr]),Dr=(0,p.useCallback)(e=>{wr(e.pointerId,e.clientX)},[wr]),Or=(0,p.useCallback)(e=>{Tr(e.pointerId,e.clientX)},[Tr]),kr=(0,p.useCallback)(e=>{Tr(e.pointerId,e.clientX)},[Tr]),jr=(0,p.useCallback)(e=>{xt.current===e.pointerId&&Cr(e.pointerId)},[Cr]),Mr=(0,p.useCallback)(()=>{if(Tt.current){Tt.current=!1;return}Xe(!0)},[]),Nr=(0,p.useCallback)(()=>{Xe(!1)},[]),Pr=(0,p.useCallback)(e=>{e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),Mr())},[Mr]);(0,p.useEffect)(()=>{w||(xt.current=null,St.current=null,wt.current=!1,Tt.current=!1,Y(!1),$e(!1),Sr())},[w,Sr]),(0,p.useEffect)(()=>()=>{Sr()},[Sr]);let Fr=!!O,Ir=A?.target_available===!1,Lr=Ir?A?.target_unavailable_reason??d5(`review.unavailableTarget`):null,Rr=F||!!(A&&A.target_available!==!1&&!Ln),zr=!!(t?.memory_enabled&&A&&(Le.length>0||Re)),Br=w&&(F||Fr)&&!Ir&&!Ln,Vr=Br&&!Je&&!Qe,Hr=Br&&(Je||Qe),Ur=`${An??`none`}:${Br?`changes-enabled`:`changes-disabled`}:${Hr?`panel-visible`:`panel-hidden`}`,Wr=(0,p.useCallback)(e=>{dt.current=null,Xt(Lt,e)},[Lt,Xt]),Gr=A||F?(0,X.jsx)(X.Fragment,{children:(0,X.jsx)(U8,{projectId:e,agentRunParentType:A?`chat`:null,agentRunParentId:A?.id??null,messages:A?mn:[],internalLog:A?.agent_log??null,currentThinkingMessageId:A?.agent_message_id??null,previousThinkingLog:A?.previous_agent_log??null,previousThinkingMessageId:A?.previous_agent_message_id??null,pendingAgentTitle:pn,streamingResponse:A?.streaming_response??null,isRunning:A?.agent_status===`running`,isLoading:!F&&pe,canShowComposer:Rr,cardClassName:`border-t-0`,isExternallyResizing:C||Ze,pendingAgentRevealKey:yn,pendingAgentRevealDelayMs:rhe,liveResponseTiming:it,composerFocusNonce:nt,header:(0,X.jsx)(G8,{title:wn,tool:F?null:A?.tool??null,modelLabel:kn,interrupted:$n,interruptedLabel:d5(`sidebar.interrupted`),usage:{totalTokens:A?.usage_snapshot_total_tokens??null,contextWindow:A?.usage_snapshot_context_window??null,cost:A?.usage_snapshot_cost??null,tool:Tn,model:Dn,availableModels:Ht},metadataExtra:(0,X.jsxs)(X.Fragment,{children:[A?.external_source?(0,X.jsx)(IF,{externalSource:A.external_source}):null,A?.origin_spec_session_id&&A.origin_spec_snapshot_id&&y?(0,X.jsx)(Q,{type:`button`,size:`xs`,variant:`ghost`,className:`h-6 px-2 text-[11px] text-violet-200 hover:text-violet-100`,onClick:()=>{y(A.origin_spec_session_id,A.origin_spec_snapshot_id)},children:qb.t(`common:specView.provenance.viewSourceSpec`)}):null]}),actions:A&&e?(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[zr&&(0,X.jsx)(Q,{type:`button`,size:`xs`,variant:`outline`,className:`gap-2`,onClick:()=>Ve(!0),children:Re?d5(`composer.loadingMemory`):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{children:d5(`composer.memorySuggestions`)}),(0,X.jsx)(Ew,{children:Le.length})]})}),(0,X.jsx)(V4,{projectId:e,scope:{type:`chat`,id:A.id},size:`xs`,onNavigateToLifecycleSource:b})]}):null,warnings:Ln&&In?(0,X.jsx)(`div`,{className:`w-fit max-w-md rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-50`,children:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{children:In}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`secondary`,onClick:()=>{Pn()},children:d5(`composer.switchBack`)}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`ghost`,onClick:Mn,children:d5(`composer.startNewSession`)})]})]})}):Ir&&Lr?(0,X.jsx)(`div`,{className:`w-fit max-w-md rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-50`,children:Lr}):null}),composerControls:hr,composerInlineControls:gr,composerTheme:Cn,layoutKey:An,scrollLayoutKey:Ur,followUpPrompt:Rt,draftAttachments:Bt,followUpPlaceholder:_5(Cn),emptyStateText:null,renderMessageFooter:br,renderMessageBody:vn,isSendingFollowUp:_e||he,isComposerSubmitDisabled:gn||M,postBuildCheck:A?.post_build_check,isUploadingAttachments:Vt,canAttachImages:On,followUpDisabledReason:Ir?Lr??void 0:A?.agent_status===`running`?d5(`review.waitTurnShort`):M?qb.t(`common:postBuildChecks.blockedReason`):Vt?d5(`review.waitUpload`):gn?qb.t(`common:questionSet.waitForResolution`):void 0,onFollowUpPromptChange:Wr,onFollowUpKeyDown:vr,onFollowUpPaste:Yn,onUploadAttachments:e=>{qn(e)},onRemoveAttachment:e=>{Jn(e)},onFollowUpSubmit:()=>{_r()}})}):Fr?(0,X.jsx)(k8,{label:d5(`composer.loadingSession`)}):!de||le?(0,X.jsx)(A8,{label:d5(`sidebar.loadingSessions`)}):(0,X.jsx)(j8,{title:d5(`composer.noSessionSelectedTitle`),description:d5(`composer.noSessionSelectedDescription`),startNewSessionLabel:d5(`composer.startNewSession`),onStartNewSession:Mn,canStartNewSession:!!e&&!he&&!_e}),Kr=Br?(0,X.jsx)(`div`,{ref:yt,"aria-label":d5(Vr?`composer.openDiff`:`composer.resizeDiffPanel`),"aria-orientation":Vr?void 0:`vertical`,className:Z(Vr?`group flex h-8 w-full shrink-0 touch-none select-none items-center justify-center border-t border-border/70 bg-background/90 text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground xl:h-auto xl:w-7 xl:cursor-col-resize xl:border-l xl:border-t-0`:`group hidden w-5 shrink-0 cursor-col-resize touch-none select-none items-center justify-center border-l border-border/70 bg-background/80 transition-colors xl:flex`,Ze&&!Vr&&`bg-background`),"data-testid":Vr?`collapsed-changes-rail`:void 0,onLostPointerCapture:jr,onPointerCancel:kr,onPointerDown:Er,onPointerMove:Dr,onPointerUp:Or,onClick:Vr?Mr:void 0,onKeyDown:Vr?Pr:void 0,role:Vr?`button`:`separator`,tabIndex:Vr?0:void 0,children:Vr?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`hidden h-full w-full items-center justify-center xl:flex`,children:(0,X.jsxs)(`span`,{className:`relative flex h-full w-full items-center justify-center`,children:[(0,X.jsx)(`span`,{className:`absolute top-1/2 left-1/2 flex -translate-x-1/2 -translate-y-[2.65rem] items-center justify-center text-sky-400/80 transition-colors group-hover:text-sky-300`,children:(0,X.jsx)(Ev,{className:`h-3 w-3 shrink-0`})}),(0,X.jsx)(`span`,{className:`absolute top-1/2 left-1/2 h-14 w-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-muted-foreground/70 transition-colors group-hover:bg-sky-300/90`})]})}),(0,X.jsxs)(`span`,{className:`flex items-center gap-2 text-xs font-medium xl:hidden`,children:[(0,X.jsx)(Ev,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{children:d5(`composer.diff`)})]})]}):(0,X.jsx)(`div`,{className:Z(`h-14 w-1.5 rounded-full transition-colors`,Ze?`bg-sky-300/90`:`bg-muted-foreground/70 group-hover:bg-sky-300/90`)})}):null,qr=Be&&e&&t?.memory_enabled?(0,X.jsx)(tC,{onClose:()=>Ve(!1),overlayClassName:`bg-background/75 p-4`,panelClassName:`w-full max-w-3xl`,renderContent:({closeButton:t})=>(0,X.jsxs)(iC,{size:`sm`,className:`max-h-[calc(100vh-2rem)] w-full gap-0 overflow-hidden border-border/80 bg-card/95 shadow-2xl`,children:[(0,X.jsxs)(aC,{className:`border-b border-border/80 pb-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(oC,{children:d5(`composer.memorySuggestionsTitle`)}),(0,X.jsx)(sC,{children:d5(`composer.memorySuggestionsDescription`)})]}),(0,X.jsx)(cC,{children:t})]}),(0,X.jsx)(lC,{className:`min-h-0 flex-1 overflow-y-auto pt-4`,children:(0,X.jsx)(K8,{projectId:e,suggestions:Le,emptyState:d5(`composer.memorySuggestionsEmpty`),onSuggestionsChanged:sn})})]}),closeButtonLabel:d5(`composer.closeMemorySuggestions`)}):null,Jr=dn.length>0?(0,X.jsx)(O8,{count:dn.length,title:fn,isDeleting:Ce.size>0,onConfirm:()=>{ir()},onCancel:()=>{Ce.size>0||Se([])},labels:ur}):null;return(0,X.jsxs)(`div`,{"data-testid":`chat-view-shell`,className:`relative flex min-h-0 flex-1 overflow-hidden border-t border-border/70`,children:[(0,X.jsx)(M8,{sessions:E,sessionGroups:ln,activeSessionId:O,isDraftOpen:F,isLoadingSessions:le,isOpen:J,onToggleOpen:()=>{qe(e=>!e)},testId:`chat-sessions-sidebar`,railTestId:`chat-sessions-rail`,onDraftOpen:Mn,isCreatingSession:he||!e,isSendingPrompt:_e,newSessionShortcutHint:dr,newSessionTooltip:fr,isSelectionMode:Te,selectedSessionIds:De,selectedSessionCount:De.size,hasDeletableSessions:ar,deletingSessionIds:Ce,onEnterSelectionMode:()=>{Ee(!0),Oe(new Set)},onExitSelectionMode:()=>{Ee(!1),Oe(new Set)},onToggleSessionSelection:e=>{Oe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},onSetSessionSelection:pr,onConfirmDeleteSelectedSessions:()=>{Se(Array.from(De))},selectionPresets:un,onSessionSelect:e=>{Rn(e)},onConfirmDeleteSession:e=>{Se([e])},getSessionId:e=>e.id,getSessionTitle:e=>e.title,getDeleteDisabledReason:A5,getActivityState:or,getRowAriaLabel:sr,renderRowContent:cr,labels:lr}),(0,X.jsxs)(`div`,{ref:vt,className:`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden xl:flex-row`,children:[(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:Gr}),Br?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(vv,{content:d5(`composer.openDiff`),disabled:!Vr,side:`left`,children:Kr}),Hr?(0,X.jsx)(H8,{projectId:e,chatSessionId:F?null:O,canSubmitReviewPrompt:tr,reviewSubmitDisabledReason:nr,onSubmitReviewPrompt:Xn,state:Ue,onStateChange:We,isResizing:Ze,onClose:Nr,desktopWidth:et,panelElementRef:bt}):null]}):null]}),qr,Jr]})},_he=({className:e})=>(0,X.jsx)(Ag,{"aria-hidden":`true`,className:e}),vhe=({activeProject:e,onNavigateToSource:t})=>{let{t:n}=q(`projects`);return e?(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-6 py-6`,children:(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-7xl flex-col gap-5`,children:[(0,X.jsx)(`div`,{className:`border-b border-border/60 pb-4`,children:(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`p`,{className:`text-[10px] font-semibold uppercase tracking-[0.24em] text-muted-foreground`,children:n(`memory.workspace.title`)}),(0,X.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:e.name})]})}),(0,X.jsx)(FT,{mode:`edit`,projectId:e.id,memoryEnabled:e.memory_enabled,persistedMemoryEnabled:e.memory_enabled,onMemoryEnabledChange:()=>{},showActivationControls:!1,archiveLayout:!0,onNavigateToSource:t})]})}):(0,X.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-sm text-muted-foreground`,children:n(`memory.workspace.selectProject`)})},yhe=(e,t,n,r)=>Y(J(`/projects/${e}/spec-sessions/${t}/snapshots/${n}/review`),{method:`POST`,body:r,fallbackErrorMessage:`Unable to start the spec review right now.`}),bhe=(e,t,n)=>Y(J(`/projects/${e}/spec-sessions/${t}/snapshots/${n}/review/stop`),{method:`POST`,fallbackErrorMessage:`Unable to stop the spec review right now.`}),j5=(e,t,n,r)=>Y(J(`/projects/${e}/spec-sessions/${t}/snapshots/${n}/review`),{signal:r,fallbackErrorMessage:`Unable to load the spec review right now.`}),xhe=(e,t,n,r)=>Y(J(`/projects/${e}/spec-sessions/${t}/snapshots/${n}/review-runs/${r}/revision-draft`),{method:`POST`,fallbackErrorMessage:`Unable to build the revision draft right now.`}),She=(e,t)=>!!t&&e===t,Che=({suggestion:e,isRecommended:t,recommendedLabel:n,onPick:r})=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{r(e.value)},className:Z(`inline-flex min-w-0 items-center gap-1.5 rounded-full border px-3 py-1.5 text-left text-xs font-medium transition-colors`,t?`border-amber-500/40 bg-amber-500/15 text-amber-200 hover:bg-amber-500/25 hover:text-amber-100`:`border-border/70 bg-background/70 text-foreground hover:border-border hover:bg-background`),children:[(0,X.jsx)(`span`,{className:`truncate`,children:e.label}),t?(0,X.jsx)(`span`,{className:`shrink-0 rounded-full bg-amber-500/30 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-amber-100`,children:n}):null]}),whe=({question:e,labels:t})=>(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm font-medium leading-relaxed text-foreground`,children:e.question}),e.rationale?(0,X.jsxs)(`p`,{className:`whitespace-pre-wrap break-words text-xs leading-relaxed text-muted-foreground`,children:[(0,X.jsxs)(`span`,{className:`font-semibold`,children:[t.rationaleLabel,`: `]}),e.rationale]}):null]}),M5=({question:e,isActive:t,isDisabled:n=!1,onSubmitAnswer:r,labels:i})=>{let[a,o]=(0,p.useState)(``),s=(0,p.useRef)(null);if((0,p.useEffect)(()=>{t&&o(``)},[e.question,t]),(0,p.useEffect)(()=>{s.current&&kD(s.current)},[a]),!t)return(0,X.jsx)(whe,{question:e,labels:i});let c=a.trim().length>0&&!n,l=e.suggestions.find(e=>e.recommended)?.id,u=e=>{o(e),requestAnimationFrame(()=>{s.current?.focus();let e=s.current;e&&e.setSelectionRange(e.value.length,e.value.length)})},d=()=>{let e=a.trim();!e||n||(r(e),o(``))};return(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(db,{className:`mt-0.5 h-4 w-4 flex-shrink-0 text-amber-300`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm font-medium leading-relaxed text-foreground`,children:e.question}),e.rationale?(0,X.jsxs)(`p`,{className:`mt-1 whitespace-pre-wrap break-words text-xs leading-relaxed text-muted-foreground`,children:[(0,X.jsxs)(`span`,{className:`font-semibold`,children:[i.rationaleLabel,`: `]}),e.rationale]}):null]})]}),e.suggestions.length>0?(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:i.suggestionsLabel}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.suggestions.map(e=>(0,X.jsx)(Che,{suggestion:e,isRecommended:She(e.id,l),recommendedLabel:i.recommendedSuggestionLabel,onPick:u},e.id))})]}):null,(0,X.jsx)(Y_,{ref:s,value:a,placeholder:i.answerPlaceholder,disabled:n,onChange:e=>{o(e.target.value)},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),d())}}),(0,X.jsx)(`div`,{className:`flex justify-end`,children:(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`secondary`,disabled:!c,onClick:d,children:n?i.submittingLabel:i.submitLabel})})]})},The=({className:e})=>(0,X.jsx)(fg,{"aria-hidden":`true`,className:e}),Ehe=[`h-10 w-10 px-0`,`border-amber-400/60 bg-amber-500/30 text-amber-100 shadow-[0_8px_24px_rgba(245,158,11,0.24)]`,`hover:bg-amber-500/45 hover:text-white hover:border-amber-300`,`focus-visible:border-ring/70 focus-visible:ring-2 focus-visible:ring-ring/20`].join(` `),Dhe=[`h-10 w-10 px-0 shadow-none`,`border-border/70 bg-transparent text-muted-foreground`,`hover:border-border hover:bg-background/60 hover:text-foreground`,`focus-visible:border-ring/70 focus-visible:ring-2 focus-visible:ring-ring/20`,`disabled:border-border/40 disabled:bg-transparent disabled:text-muted-foreground/50`].join(` `),N5=({on:e,disabled:t=!1,onToggle:n,tooltipContent:r,ariaLabelOn:i,ariaLabelOff:a,className:o})=>(0,X.jsx)(vv,{content:r,children:(0,X.jsx)(`span`,{className:`inline-flex`,children:(0,X.jsx)(Q,{type:`button`,size:`icon`,variant:e?`warning`:`ghost`,"aria-pressed":e,"aria-label":e?i:a,disabled:t,className:Z(e?Ehe:Dhe,o),onClick:()=>{t||n(!e)},children:(0,X.jsx)(The,{className:`h-5 w-5`})})})}),Ohe=({projectId:e,specSessionId:t,messages:n,internalLog:r,currentThinkingMessageId:i=null,previousThinkingLog:a=null,previousThinkingMessageId:o=null,pendingAgentTitle:s,streamingResponse:c,isRunning:l,isLoading:u=!1,canShowComposer:d,cardClassName:f,isExternallyResizing:p=!1,pendingAgentRevealKey:m=null,pendingAgentRevealDelayMs:h=0,liveResponseTiming:g=null,composerFocusNonce:_=0,blurComposerOnSendStart:v=!1,hidePendingAgentTitle:y=!1,forceScrollToBottomKey:b,header:x,composerControls:S,composerInlineControls:C,composerTheme:w=`default`,layoutKey:T,scrollLayoutKey:E,followUpPrompt:D,draftAttachments:O=[],followUpPlaceholder:k,emptyStateText:A=null,renderMessageFooter:j,renderMessageBody:M,isSendingFollowUp:N,isComposerSubmitDisabled:P=!1,isUploadingAttachments:F=!1,canAttachImages:I=!1,followUpDisabledReason:L,onFollowUpPromptChange:R,onFollowUpKeyDown:z,onFollowUpPaste:ee,onUploadAttachments:B,onRemoveAttachment:V,onFollowUpSubmit:H})=>(0,X.jsx)(BJ,{projectId:e,agentRunParentType:t?`spec`:null,agentRunParentId:t,messages:n,internalLog:r,currentThinkingMessageId:i,previousThinkingLog:a,previousThinkingMessageId:o,pendingAgentTitle:s,streamingResponse:c,isRunning:l||!!(N&&g),isLoading:u,autoScrollBehavior:`sticky`,surfaceVariant:`chat`,canShowComposer:d,cardClassName:f,header:x,composerControls:S,composerInlineControls:C,composerTheme:w,composerSize:`compact-on-laptop`,showThinkingPlacement:`header`,pinComposerToBottom:!0,isExternallyResizing:p,pendingAgentRevealKey:m,pendingAgentRevealDelayMs:h,liveResponseTiming:g,composerFocusNonce:_,blurComposerOnSendStart:v,forceScrollToBottomKey:b,layoutKey:T,scrollLayoutKey:E,followUpPrompt:D,draftAttachments:O,followUpPlaceholder:k,emptyStateText:A,autoFocusComposer:!0,renderMessageFooter:j,renderMessageBody:M,isSendingFollowUp:N,isComposerSubmitDisabled:P,isUploadingAttachments:F,canAttachImages:I,followUpDisabledReason:L,hidePendingAgentTitle:y,onFollowUpPromptChange:R,onFollowUpKeyDown:z,onFollowUpPaste:ee,onUploadAttachments:B,onRemoveAttachment:V,onFollowUpSubmit:H}),P5=e=>{let t={...e};return delete t.messages,t.agent_log=null,t.agent_message_id=null,t.previous_agent_log=null,t.previous_agent_message_id=null,t.streaming_response=null,t},F5=new Set([`deterministic`,`structural_heuristic`,`historical_heuristic`]),I5=e=>typeof e==`object`&&!!e&&!Array.isArray(e),khe=e=>I5(e)&&typeof e.seed_path==`string`&&typeof e.candidate_path==`string`&&F5.has(e.evidence_class)&&typeof e.depth==`number`&&Array.isArray(e.edge_ids),L5=e=>I5(e)&&typeof e.path==`string`&&typeof e.is_test==`boolean`&&F5.has(e.evidence_class)&&Array.isArray(e.chains)&&e.chains.length>0&&e.chains.every(khe),Ahe=e=>!I5(e)||e.version!==1||![`complete`,`stale`,`truncated`,`unavailable`].includes(e.capture_state)||!Array.isArray(e.affected_files)||!Array.isArray(e.affected_tests)||!e.affected_files.every(L5)||!e.affected_tests.every(L5)?null:e,jhe=e=>!!(e.likely_files.some(e=>e.origin!==`graph`)||e.file_relation_graph),R5=({evidenceClass:e})=>{let{t}=q(`common`);return(0,X.jsx)(rC,{variant:`outline`,className:`shrink-0 px-1.5 py-0 text-[10px] ${e===`deterministic`?`border-emerald-400/30 bg-emerald-500/10 text-emerald-200`:e===`structural_heuristic`?`border-amber-400/30 bg-amber-500/10 text-amber-200`:`border-sky-400/30 bg-sky-500/10 text-sky-200`}`,children:t(`specView.artifactPanel.repositoryEvidence.class.${e}`)})},Mhe=({candidate:e})=>{let{t}=q(`common`),n=e.chains.slice(0,2);return(0,X.jsxs)(`details`,{className:`group mt-2 border-t border-border/40 pt-2`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer list-none rounded-sm text-xs font-medium text-violet-300 outline-none hover:text-violet-200 focus-visible:ring-2 focus-visible:ring-ring/60 [&::-webkit-details-marker]:hidden`,children:t(`specView.artifactPanel.repositoryEvidence.showChains`,{count:n.length})}),(0,X.jsx)(`ol`,{className:`mt-2 space-y-2`,children:n.map((e,n)=>(0,X.jsxs)(`li`,{className:`min-w-0 rounded-md bg-background/35 px-2.5 py-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`text-[11px] font-medium text-foreground`,children:t(`specView.artifactPanel.repositoryEvidence.chainLabel`,{number:n+1})}),(0,X.jsx)(R5,{evidenceClass:e.evidence_class})]}),(0,X.jsx)(`p`,{className:`mt-1 break-words text-xs leading-relaxed text-muted-foreground`,children:t(`specView.artifactPanel.repositoryEvidence.chainSummary`,{seed:e.seed_path,candidate:e.candidate_path,count:e.depth})})]},`${e.seed_path}:${e.candidate_path}:${e.edge_ids.join(`:`)}`))})]})},Nhe=({row:e,affectedTest:t=!1})=>{let{t:n}=q(`common`);return(0,X.jsxs)(`li`,{className:`min-w-0 overflow-hidden rounded-md border border-border/50 bg-surface-hover px-3 py-2.5`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[(0,X.jsx)(`code`,{className:`min-w-0 break-all text-xs font-medium text-foreground`,children:e.path}),e.isNew&&(0,X.jsx)(rC,{variant:`success`,className:`shrink-0 px-1.5 py-0 text-[10px]`,children:n(`specView.artifactPanel.newFile`)})]}),(0,X.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,X.jsx)(`span`,{children:n(`specView.artifactPanel.repositoryEvidence.origin.${e.origin}`)}),t&&(0,X.jsx)(rC,{variant:`outline`,className:`px-1.5 py-0 text-[10px] text-violet-200`,children:n(`specView.artifactPanel.repositoryEvidence.affectedTest`)}),e.candidate&&(0,X.jsx)(R5,{evidenceClass:e.candidate.evidence_class})]}),e.reason&&(0,X.jsx)(`p`,{className:`mt-1 break-words text-xs leading-relaxed text-muted-foreground`,children:e.reason}),e.candidate&&(0,X.jsx)(Mhe,{candidate:e.candidate})]})},z5=e=>e.replace(/\\/g,`/`),Phe=({snapshot:e,onMermaidClick:t})=>{let{t:n}=q(`common`);Ahe(e.repository_evidence);let r=[],i=[],a=new Map(i.map(e=>[z5(e.path),e])),o=e.likely_files.filter(e=>e.origin!==`graph`),s=new Map(o.map(e=>[e.normalized_path??z5(e.path),e])),c=o.flatMap(e=>{let t=e.normalized_path??z5(e.path);return a.has(t)?[]:[{path:e.path,reason:e.reason||null,isNew:e.is_new,origin:e.origin??`planner`,candidate:null}]}),l=r.map(e=>{let t=s.get(z5(e.path));return{path:t?.path??e.path,reason:null,isNew:!1,origin:t?`both`:`graph`,candidate:e}}),u=new Set(r.map(e=>z5(e.path)));for(let t of e.likely_files.filter(e=>e.origin===`graph`)){let e=t.normalized_path??z5(t.path);u.has(e)||l.push({path:t.path,reason:t.reason||null,isNew:t.is_new,origin:`graph`,candidate:null})}return i.map(e=>{let t=s.get(z5(e.path));return{path:t?.path??e.path,reason:t?.reason??null,isNew:t?.is_new??!1,origin:t?`both`:`graph`,candidate:e}}),(0,X.jsxs)(`section`,{children:[c.length>0&&(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:c.map(e=>(0,X.jsx)(Nhe,{row:e},`${e.origin}:${e.path}`))}),!1,e.file_relation_graph&&(0,X.jsxs)(`section`,{className:`mt-4`,"aria-labelledby":`spec-file-relation-heading`,children:[(0,X.jsx)(`h3`,{id:`spec-file-relation-heading`,className:`text-xs font-semibold text-foreground`,children:n(`specView.artifactPanel.fileRelationGraph`)}),(0,X.jsx)(`p`,{className:`mb-2 mt-1 text-xs leading-relaxed text-muted-foreground`,children:n(`specView.artifactPanel.repositoryEvidence.diagramDescription`)}),(0,X.jsx)(`div`,{className:`overflow-auto rounded-md border border-border/50 bg-surface-hover p-3`,children:(0,X.jsx)(WW,{mermaid:e.file_relation_graph,onClick:()=>{t(e.file_relation_graph)}})})]})]})},B5=({className:e})=>(0,X.jsx)(Hg,{"aria-hidden":`true`,className:e}),Fhe=({className:e})=>(0,X.jsx)(Jh,{"aria-hidden":`true`,className:e}),V5=({className:e})=>(0,X.jsx)(ag,{"aria-hidden":`true`,className:e}),H5=({heading:e,open:t,onOpenChange:n,children:r})=>(0,X.jsxs)(SC,{open:t,onOpenChange:n,children:[(0,X.jsx)(CC,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-1.5 text-xs font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground transition-colors mb-2`,children:[(0,X.jsx)(bv,{className:`h-3 w-3 shrink-0 transition-transform ${t?``:`-rotate-90`}`}),e]})}),(0,X.jsx)(wC,{children:r})]}),Ihe=({actions:e})=>{let{t}=q(`common`);return e.hasExistingTicketsFromSnapshot?(0,X.jsxs)(`p`,{className:`flex w-full items-center justify-center gap-1.5 rounded-md px-3 py-1.5 text-sm font-medium text-muted-foreground`,children:[(0,X.jsx)(fb,{className:`h-3.5 w-3.5 text-emerald-400`}),t(`specView.actions.ticketsCreated`)]}):(0,X.jsxs)(Q,{type:`button`,size:`sm`,onClick:e.onCreateTickets,disabled:!!e.unavailableReason||e.isCreatingTickets||e.isImplementingInChat||e.isExporting,title:e.unavailableReason??void 0,className:`w-full justify-center gap-1.5 border-violet-300/70 bg-violet-500/15 text-violet-100 hover:bg-violet-500/25`,children:[(0,X.jsx)(B5,{className:`h-3.5 w-3.5`}),e.isCreatingTickets?t(`specView.actions.creatingTickets`):t(`specView.actions.createTickets`)]})},U5=({ticket:e})=>(0,X.jsxs)(`div`,{className:`min-w-0 rounded-md border border-border/50 bg-surface-hover px-3 py-2`,children:[(0,X.jsx)(`div`,{className:`break-words text-xs font-medium text-foreground`,children:e.title}),e.key&&(0,X.jsx)(`div`,{className:`mt-0.5 break-all text-xs text-violet-400`,children:e.key})]}),Lhe=({snapshot:e})=>{let{t}=q(`common`),n=new Map(e.tickets.map(e=>[e.key,e]));return(0,X.jsx)(`section`,{className:`space-y-2.5`,children:e.bundle_groups.map(e=>{let r=e.ticket_keys.map(e=>n.get(e)).filter(e=>e!==void 0);return(0,X.jsxs)(`article`,{className:`min-w-0 rounded-md border border-border/50 bg-surface px-3 py-2.5`,children:[(0,X.jsx)(`h4`,{className:`break-all text-sm font-semibold text-foreground`,children:e.name}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:t(`specView.artifactPanel.proposedTicketCount`,{count:r.length})}),r.length>0&&(0,X.jsx)(`ul`,{className:`mt-2 space-y-1.5`,children:r.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(U5,{ticket:e})},e.key))})]},e.key)})})},W5={high:0,medium:1,low:2},Rhe=e=>[...e].sort((e,t)=>{let n=W5[e.severity]??99,r=W5[t.severity]??99;return n===r?e.ordinal-t.ordinal:n-r}),zhe=e=>{let t={high:0,medium:0,low:0};for(let n of e)t[n.severity]+=1;return t},Bhe=({run:e})=>{let{t}=q(`common`),n=e.agent_status,r=t(`specView.review.status.${n}`,{defaultValue:n});return(0,X.jsx)(`span`,{className:`text-xs font-medium ${n===`running`?`text-violet-300`:n===`completed`?`text-emerald-300`:n===`error`||n===`parse_failed`?`text-rose-300`:`text-amber-300`}`,children:r})},Vhe=({review:e})=>{let{t}=q(`common`),[n,r]=(0,p.useState)(!0),i=e.review?.run??null,a=e.review?.findings??[],o=Rhe(a),s=zhe(a),c=e.isRunning||i?.agent_status===`running`,l=c,u=!!i&&!c&&i?.agent_status===`completed`&&a.length>0,d=i?.agent_status===`completed`?`specView.review.noFindings`:i?.agent_status===`stopped`?`specView.review.stoppedExplanation`:i?.agent_status===`error`?`specView.review.errorExplanation`:i?.agent_status===`parse_failed`?`specView.review.parseFailedExplanation`:null,f=(0,p.useMemo)(()=>new Map(e.availableModels.map(e=>[e.id,e.label])),[e.availableModels]),m=i?.model?e5({availableModelsById:f,model:i.model})??i.model:null,h=i?[m,t(`specView.review.findingsCount`,{count:a.length}),s.high>0?`${s.high} ${t(`specView.review.severity.high`)}`:null,s.medium>0?`${s.medium} ${t(`specView.review.severity.medium`)}`:null,s.low>0?`${s.low} ${t(`specView.review.severity.low`)}`:null].filter(Boolean).join(` · `):null;return(0,X.jsx)(H5,{heading:(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(V5,{className:`h-3.5 w-3.5`}),t(`specView.review.heading`)]}),open:n,onOpenChange:r,children:(0,X.jsxs)(`section`,{className:`rounded-md border border-border/50 bg-surface-hover px-3 py-3`,children:[i&&(0,X.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground`,children:[(0,X.jsx)(Bhe,{run:i}),c&&(0,X.jsx)(`span`,{className:`inline-flex items-center gap-1 text-violet-300`,"aria-hidden":`true`,children:(0,X.jsx)(`span`,{className:`h-3 w-3 animate-spin rounded-full border-2 border-violet-400 border-t-transparent`})}),h&&(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:h})]}),e.isLoading&&!i&&(0,X.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:t(`specView.review.loading`)}),o.length>0?(0,X.jsx)(`ul`,{className:`space-y-2`,children:o.map(e=>(0,X.jsxs)(`li`,{className:`rounded-md border border-border/40 bg-surface px-2.5 py-2`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`text-[0.65rem] font-bold uppercase tracking-wide ${e.severity===`high`?`text-rose-300`:e.severity===`medium`?`text-amber-300`:`text-sky-300`}`,children:e.severity}),(0,X.jsx)(`span`,{className:`min-w-0 break-words text-xs font-medium text-foreground`,children:e.title})]}),(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-foreground`,children:e.what_text}),e.why_text&&(0,X.jsxs)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:[(0,X.jsxs)(`span`,{className:`font-medium`,children:[t(`specView.review.why`),`:`]}),` `,e.why_text]}),e.suggestion_text&&(0,X.jsxs)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:[(0,X.jsxs)(`span`,{className:`font-medium`,children:[t(`specView.review.suggestion`),`:`]}),` `,e.suggestion_text]})]},e.id))}):d?(0,X.jsx)(`p`,{className:`text-xs ${i?.agent_status===`completed`?`text-emerald-300`:`text-muted-foreground`}`,children:t(d)}):null,l&&(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:e.onStopReview,className:`w-full justify-center gap-1.5`,children:[(0,X.jsx)(jv,{className:`h-3.5 w-3.5`}),t(`specView.review.stop`)]})}),u&&(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:e.onSendToPlanner,disabled:!!e.disabledReason||e.isSendingToPlanner,title:e.disabledReason??void 0,className:`w-full justify-center gap-1.5`,children:[(0,X.jsx)(vD,{className:`h-3.5 w-3.5`}),e.isSendingToPlanner?t(`specView.review.sendingToPlanner`):t(`specView.review.sendToPlanner`)]})})]})})},Hhe=({review:e})=>{let{t}=q(`common`),[n,r]=(0,p.useState)(!1),i=e.isRunning||e.review?.run?.agent_status===`running`,a=e.showModelSelector&&e.selectedDiscoveredModel!==null&&e.selectedDiscoveredModel.variants.length>0,o=t(i?`specView.review.running`:`specView.review.launch`);return(0,X.jsxs)(av,{open:n&&!i,onOpenChange:r,children:[(0,X.jsx)(ov,{asChild:!0,children:(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`ghost`,disabled:i||!!e.disabledReason,title:e.disabledReason??void 0,"aria-label":o,className:`gap-1.5 text-muted-foreground hover:text-foreground`,children:[(0,X.jsx)(V5,{className:`h-4 w-4`}),t(`specView.review.heading`)]})}),(0,X.jsx)(sv,{align:`end`,className:`w-72 max-w-[calc(100vw-2rem)] p-3`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-[0.22em] text-muted-foreground`,children:t(`specView.review.popoverTitle`)}),(0,X.jsx)(mv,{model:e.runConfigModel,showModelSelector:e.showModelSelector,availableModels:e.availableModels,onModelChange:e.onRunConfigModelChange,selectId:`spec-review-model`,label:t(`specView.review.model`)}),(0,X.jsx)(hv,{variant:e.runConfigVariant,selectedModel:e.selectedDiscoveredModel,showVariantSelector:a,onVariantChange:e.onRunConfigVariantChange,selectId:`spec-review-variant`,label:t(`specView.review.variant`)}),(0,X.jsxs)(Q,{type:`button`,size:`sm`,onClick:()=>{r(!1),e.onLaunchReview()},className:`w-full justify-center gap-1.5`,children:[(0,X.jsx)(V5,{className:`h-3.5 w-3.5`}),t(`specView.review.launchAction`)]})]})})]})},Uhe=(0,p.memo)((0,p.forwardRef)(({snapshot:e,isLoading:t,desktopWidth:n,onClose:r,actions:i,review:a,className:o},s)=>{let{t:c}=q(`common`),[l,u]=(0,p.useState)(null),[d,f]=(0,p.useState)(!1),[m,h]=(0,p.useState)(!0),[g,_]=(0,p.useState)(!0),[v,y]=(0,p.useState)(!0),[b,x]=(0,p.useState)(!0),[S,C]=(0,p.useState)(!0),[w,T]=(0,p.useState)(!0),[E,D]=(0,p.useState)(!0),[O,k]=(0,p.useState)(!0),[A,j]=(0,p.useState)(!0),M=(0,p.useCallback)(e=>{u(e)},[]),N=(0,p.useCallback)(()=>{f(!0)},[]),P=`flex h-[26rem] min-h-0 min-w-0 w-full shrink-0 flex-col overflow-hidden border-t border-border/70 bg-surface xl:h-full xl:border-l xl:border-t-0 ${o??``}`;if(t)return(0,X.jsxs)(`aside`,{ref:s,style:n?{"--spec-artifact-panel-width":`${n}px`}:void 0,className:n?`xl:w-[var(--spec-artifact-panel-width)] ${P}`:P,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/50 px-4 py-3`,children:[(0,X.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:c(`specView.artifactPanel.title`)}),(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,className:`text-muted-foreground hover:text-foreground`,"aria-label":c(`specView.artifactPanel.close`),onClick:r,children:(0,X.jsx)(ax,{className:`h-4 w-4`})})]}),(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,X.jsx)(`div`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-violet-400 border-t-transparent`})})]});if(!e)return(0,X.jsxs)(`aside`,{ref:s,style:n?{"--spec-artifact-panel-width":`${n}px`}:void 0,className:n?`xl:w-[var(--spec-artifact-panel-width)] ${P}`:P,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/50 px-4 py-3`,children:[(0,X.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:c(`specView.artifactPanel.title`)}),(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,className:`text-muted-foreground hover:text-foreground`,"aria-label":c(`specView.artifactPanel.close`),onClick:r,children:(0,X.jsx)(ax,{className:`h-4 w-4`})})]}),(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-4`,children:(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:c(`specView.artifactPanel.noSnapshot`)})})]});let F=jhe(e),I=e.tickets.length>0,L=e.bundle_groups.length>0,R=e.dependencies.length>0,z=e.open_questions.length>0,ee=e.assumptions.length>0;return(0,X.jsxs)(`aside`,{ref:s,style:n?{"--spec-artifact-panel-width":`${n}px`}:void 0,className:n?`xl:w-[var(--spec-artifact-panel-width)] ${P}`:P,children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b border-border/50 px-4 py-3`,children:[(0,X.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:c(`specView.artifactPanel.title`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[a&&(0,X.jsx)(Hhe,{review:a}),(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,className:`text-muted-foreground hover:text-foreground`,"aria-label":c(`specView.artifactPanel.close`),onClick:r,children:(0,X.jsx)(ax,{className:`h-4 w-4`})})]})]}),(0,X.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col gap-4 overflow-y-auto px-4 py-4`,children:[a&&(a.review?.run||a.isRunning)&&(0,X.jsx)(Vhe,{review:a}),(0,X.jsx)(H5,{heading:c(`specView.artifactPanel.summary`),open:m,onOpenChange:h,children:(0,X.jsx)(`section`,{className:`rounded-md border border-border/50 bg-surface-hover px-3 py-2`,children:(0,X.jsx)(`p`,{className:`text-sm leading-relaxed text-foreground whitespace-pre-wrap`,children:e.summary})})}),e.mermaid&&(0,X.jsx)(H5,{heading:c(`specView.artifactPanel.visualization`),open:g,onOpenChange:_,children:(0,X.jsx)(`section`,{className:`overflow-auto rounded-md border border-border/50 bg-surface-hover p-3`,children:(0,X.jsx)(WW,{mermaid:e.mermaid,onClick:()=>{M(e.mermaid)}})})}),e.mockup&&(0,X.jsx)(H5,{heading:(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(Fhe,{className:`h-3.5 w-3.5`}),c(`specView.artifactPanel.uiMockup`)]}),open:v,onOpenChange:y,children:(0,X.jsx)(`section`,{className:`rounded-md border border-border/50 bg-surface-hover p-3`,children:(0,X.jsx)(cG,{html:e.mockup,onClick:N})})}),F&&(0,X.jsx)(H5,{heading:(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(Tv,{className:`h-3.5 w-3.5`}),c(`specView.artifactPanel.likelyFiles`)]}),open:b,onOpenChange:x,children:(0,X.jsx)(Phe,{snapshot:e,onMermaidClick:M})}),I&&!L&&(0,X.jsx)(H5,{heading:(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(B5,{className:`h-3.5 w-3.5`}),c(`specView.artifactPanel.proposedTickets`)]}),open:S,onOpenChange:C,children:(0,X.jsx)(`section`,{children:(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:e.tickets.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(U5,{ticket:e})},e.key))})})}),L&&(0,X.jsx)(H5,{heading:(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(zv,{className:`h-3.5 w-3.5`}),c(`specView.artifactPanel.bundleGroups`)]}),open:w,onOpenChange:T,children:(0,X.jsx)(Lhe,{snapshot:e})}),R&&(0,X.jsx)(H5,{heading:(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(ow,{className:`h-3.5 w-3.5`}),c(`specView.artifactPanel.dependencies`)]}),open:E,onOpenChange:D,children:(0,X.jsx)(`section`,{children:(0,X.jsx)(`ul`,{className:`space-y-1`,children:e.dependencies.map((e,t)=>(0,X.jsxs)(`li`,{className:`flex min-w-0 flex-wrap items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`break-all font-mono text-violet-400`,children:e.blocker_key}),(0,X.jsx)(`span`,{children:`→`}),(0,X.jsx)(`span`,{className:`break-all font-mono text-violet-400`,children:e.dependent_key})]},t))})})}),z&&(0,X.jsx)(H5,{heading:c(`specView.artifactPanel.openQuestions`),open:O,onOpenChange:k,children:(0,X.jsx)(`section`,{children:(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:e.open_questions.map((e,t)=>(0,X.jsxs)(`li`,{className:`flex gap-2 text-sm text-amber-300`,children:[(0,X.jsx)(`span`,{className:`mt-0.5 shrink-0 text-amber-500`,children:`?`}),(0,X.jsx)(`span`,{className:`min-w-0 break-words`,children:e})]},t))})})}),ee&&(0,X.jsx)(H5,{heading:c(`specView.artifactPanel.assumptions`),open:A,onOpenChange:j,children:(0,X.jsx)(`section`,{children:(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:e.assumptions.map((e,t)=>(0,X.jsxs)(`li`,{className:`flex gap-2 text-sm text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`mt-0.5 shrink-0 text-violet-500`,children:`•`}),(0,X.jsx)(`span`,{className:`min-w-0 break-words`,children:e})]},t))})})})]}),i&&(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-t border-border/50 bg-surface/95 px-4 py-3 backdrop-blur`,children:[e.tickets.length>0&&(0,X.jsx)(Ihe,{actions:i}),(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:i.onImplementInChat,disabled:!!(i.unavailableReason||i.implementInChatUnavailableReason)||i.isCreatingTickets||i.isImplementingInChat||i.isExporting,title:i.unavailableReason??i.implementInChatUnavailableReason??void 0,className:`w-full justify-center gap-1.5`,children:[(0,X.jsx)(vD,{className:`h-3.5 w-3.5`}),i.isImplementingInChat?c(`specView.actions.startingImplementation`):c(`specView.actions.implementInChat`)]}),(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:i.onExport,disabled:!!i.unavailableReason||i.isCreatingTickets||i.isImplementingInChat||i.isExporting,title:i.unavailableReason??void 0,className:`w-full justify-center gap-1.5`,children:[(0,X.jsx)(mb,{className:`h-3.5 w-3.5`}),i.isExporting?c(`specView.actions.exportingSpec`):c(`specView.actions.exportSpec`)]})]}),l&&(0,X.jsx)(aG,{mermaid:l,open:!0,onClose:()=>{u(null)}}),e.mockup&&(0,X.jsx)(lG,{html:e.mockup,open:d,onClose:()=>{f(!1)}})]})})),G5=({className:e})=>(0,X.jsx)(pg,{"aria-hidden":`true`,className:e}),K5=(e,t)=>{if(!e||e.length===0)return!1;let n=e[e.length-1];return n?.kind===`grill-question`?t===null||n.created_at>t:!1},q5=(e,t)=>qb.t(`specView.${e}`,t),J5=e=>q5(`pendingMemorySuggestions`,{count:e}),Whe=1500,Y5=`archon.spec-draft`,X5=`archon.spec-run-config`,Z5=`archon.spec-review-run-config`,Q5=`archon.spec-session-list-layout`,$5=`archon.spec-artifact-panel-layout`,Ghe=`archon.spec-import-notice`,e7=420,t7=320,n7=.5,Khe=6,r7=`/`,qhe=`Slash`,Jhe=`NumpadDivide`,Yhe=e=>!e.defaultPrevented&&!e.altKey&&!e.repeat&&(e.ctrlKey||e.metaKey)&&(e.key===r7||e.code===qhe||e.code===Jhe),i7=({modifierLabel:e,keys:t,ariaHidden:n=!1})=>(0,X.jsxs)(`span`,{"aria-hidden":n,className:`flex items-center gap-0.5 text-[10px] leading-none`,children:[(0,X.jsx)(UY,{"aria-hidden":n,children:e}),t.map(e=>(0,X.jsxs)(`span`,{className:`contents`,children:[(0,X.jsx)(`span`,{children:`+`}),(0,X.jsx)(UY,{"aria-hidden":n,children:e})]},e))]}),Xhe=({label:e,modifierLabel:t,keys:n})=>(0,X.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{children:e}),(0,X.jsx)(i7,{modifierLabel:t,keys:n,ariaHidden:!0})]}),a7=({projectId:e,tool:t,sessionId:n=null})=>e?n?`${Y5}/${e}/sessions/${n}`:`${Y5}/${e}/draft/${t}`:null,o7=({projectId:e,sessionId:t})=>e&&t?`${Ghe}/${e}/${t}`:null,s7=({projectId:e,tool:t})=>{if(e)try{localStorage.setItem(`${Y5}/${e}/tool`,t)}catch{}},c7=e=>{if(!e)return{isOpen:!0};try{let t=localStorage.getItem(`${Q5}/${e}`);return{isOpen:(t?JSON.parse(t):null)?.isOpen??!0}}catch{return{isOpen:!0}}},Zhe=({projectId:e,isOpen:t})=>{if(e)try{localStorage.setItem(`${Q5}/${e}`,JSON.stringify({isOpen:t}))}catch{}},l7=(e,t)=>{let n=Number.isFinite(e)?Math.round(e):e7;if(!Number.isFinite(t))return Math.max(t7,n);let r=Math.max(t7,Math.round(t*n7));return Math.max(t7,Math.min(r,n))},u7=e=>{if(!e)return{isOpen:!1,width:e7};try{let t=localStorage.getItem(`${$5}/${e}`);if(!t)return{isOpen:!1,width:e7};let n=JSON.parse(t),r=typeof n.width==`number`&&Number.isFinite(n.width)?Math.max(t7,Math.round(n.width)):e7;return{isOpen:n.isOpen===!0,width:r}}catch{return{isOpen:!1,width:e7}}},Qhe=({projectId:e,isOpen:t,width:n})=>{if(e)try{localStorage.setItem(`${$5}/${e}`,JSON.stringify({isOpen:t,width:n}))}catch{}},$he=e=>{if(!e)return null;try{return localStorage.getItem(e)}catch{return null}},d7=({storageKey:e,value:t})=>{if(e)try{if(!t){localStorage.removeItem(e);return}localStorage.setItem(e,t)}catch{}},ege=e=>{if(!e)return null;try{let t=localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}},f7=({storageKey:e,notice:t})=>{if(e)try{if(!t){localStorage.removeItem(e);return}localStorage.setItem(e,JSON.stringify(t))}catch{}},tge=e=>{if(!e)return null;let t=e.skipped.reduce((e,t)=>e+t.count,0),n=e.skipped.map(e=>q5(`importNotice.skipReasons.${e.code}`,{count:e.count})).join(`, `);return e.imported_count>0&&t>0?q5(`importNotice.importedWithSkips`,{importedCount:e.imported_count,skippedCount:t,skippedSummary:n}):e.imported_count>0?q5(`importNotice.importedOnly`,{importedCount:e.imported_count}):t>0?q5(`importNotice.skippedOnly`,{skippedCount:t,skippedSummary:n}):null},p7=({keyPrefix:e,projectId:t,tool:n})=>`${e}:${t}:${n}`,nge=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(Boolean).filter((e,t,n)=>n.indexOf(e)===t):[],m7=({keyPrefix:e,projectId:t,tool:n})=>{if(!t||n!==`opencode`&&n!==`claude`)return null;try{let r=window.localStorage.getItem(p7({keyPrefix:e,projectId:t,tool:n}));if(!r)return null;let i=JSON.parse(r),a=(typeof i.model==`string`?i.model.trim():``)||null;return a?{model:a,variant:a&&typeof i.variant==`string`&&i.variant.trim()||null,skills:nge(i.skills)}:null}catch{return null}},h7=({keyPrefix:e,projectId:t,tool:n,model:r,variant:i,skills:a})=>{if(!(!t||n!==`opencode`&&n!==`claude`||!r))try{let o={model:r,variant:r?i:null,...a?{skills:a}:{}};window.localStorage.setItem(p7({keyPrefix:e,projectId:t,tool:n}),JSON.stringify(o))}catch{}},g7=({projectId:e,tool:t})=>m7({keyPrefix:X5,projectId:e,tool:t}),_7=({projectId:e,tool:t,model:n,variant:r,skills:i})=>h7({keyPrefix:X5,projectId:e,tool:t,model:n,variant:r,skills:i}),rge=({projectId:e,tool:t})=>{let n=g7({projectId:e,tool:t});!n||n.skills.length===0||_7({projectId:e,tool:t,...n,skills:[]})},ige=({projectId:e,tool:t})=>m7({keyPrefix:Z5,projectId:e,tool:t}),age=({projectId:e,tool:t,model:n,variant:r})=>h7({keyPrefix:Z5,projectId:e,tool:t,model:n,variant:r}),oge=({projectId:e,tool:t})=>{if(e)try{window.localStorage.removeItem(p7({keyPrefix:Z5,projectId:e,tool:t}))}catch{}},sge=`archon.spec-draft-grill`,v7=e=>e?`${sge}/${e}`:null,y7=e=>{let t=v7(e);if(!t)return!1;try{return window.localStorage.getItem(t)===`true`}catch{return!1}},b7=({projectId:e,grillOn:t})=>{let n=v7(e);if(n)try{t?window.localStorage.setItem(n,`true`):window.localStorage.removeItem(n)}catch{}},cge=({activeProjectId:e,activeProject:t=null,activeProjectBranchState:n=null,targetBundles:r=[],targetBranchSuggestions:i={current_branch:null,default_branch:null,previous_branch:null},isTargetBundleLoading:a=!1,isTargetSelectorLoading:o=!1,onTargetSelectorOpenChange:s,onSelectBundleTarget:c=async()=>!1,onSelectRepoRootTarget:l=async()=>!1,onRestoreSessionTarget:u,activeTool:d,routedSpecSessionId:f,routedSpecSnapshotId:m,initialIssueDraft:h=null,onRoutedSpecNavigationUnavailable:g,onSessionNavigation:_,onInitialIssueDraftConsumed:v,onImplementInChat:y,onNavigateToLifecycleSource:b})=>{let x=uq(),{t:S}=q(`common`),{jiraImportState:C,prepareSpecImportFromJira:w}=mw(e),{gitHubImportState:T,prepareSpecImportFromGitHub:E}=IC(e),[D,O]=(0,p.useState)([]),[k,A]=(0,p.useState)(null),[j,M]=(0,p.useState)(null),[N,P]=(0,p.useState)(null),[F,I]=(0,p.useState)(!1),[L,R]=(0,p.useState)(null),[z,ee]=(0,p.useState)({}),[B,V]=(0,p.useState)({}),[H,U]=(0,p.useState)(null),[W,te]=(0,p.useState)({}),[ne,re]=(0,p.useState)({}),[ie,ae]=(0,p.useState)([]),[G,oe]=(0,p.useState)(``),[se,ce]=(0,p.useState)(``),[le,ue]=(0,p.useState)([]),[de,fe]=(0,p.useState)(!1),[pe,me]=(0,p.useState)(!1),[he,ge]=(0,p.useState)(!1),[_e,ve]=(0,p.useState)(!1),[ye,be]=(0,p.useState)(!1),[xe,Se]=(0,p.useState)(null),[Ce,we]=(0,p.useState)([]),[Te,Ee]=(0,p.useState)(()=>new Set),[De,Oe]=(0,p.useState)(!1),[ke,Ae]=(0,p.useState)(()=>new Set),[je,Me]=(0,p.useState)(!1),[Ne,Pe]=(0,p.useState)(()=>c7(e).isOpen),[Fe,Ie]=(0,p.useState)(0),[Le,K]=(0,p.useState)(null),[Re,ze]=(0,p.useState)(()=>new Set),[Be,Ve]=(0,p.useState)(null),[He,Ue]=(0,p.useState)(null),[We,J]=(0,p.useState)(!1),[qe,Je]=(0,p.useState)(()=>u7(e).isOpen),[Xe,Ze]=(0,p.useState)(()=>u7(e).width),[Y,Qe]=(0,p.useState)(!1),[$e,et]=(0,p.useState)(!1),[tt,nt]=(0,p.useState)(!1),[rt,it]=(0,p.useState)(!1),[at,ot]=(0,p.useState)(!1),[st,ct]=(0,p.useState)(null),[lt,ut]=(0,p.useState)(!1),[dt,ft]=(0,p.useState)(null),[pt,mt]=(0,p.useState)(()=>y7(e)),[ht,gt]=(0,p.useState)(!1),[_t,vt]=(0,p.useState)([]),[yt,bt]=(0,p.useState)(!1),[xt,St]=(0,p.useState)(!1),[Ct,wt]=(0,p.useState)(0),[Tt,Et]=(0,p.useState)(null),[Dt,Ot]=(0,p.useState)(!1),[kt,At]=(0,p.useState)(!1),[jt,Mt]=(0,p.useState)(!1),[Nt,Pt]=(0,p.useState)(!1),[Ft,It]=(0,p.useState)(``),[Lt,Rt]=(0,p.useState)(``),[zt,Bt]=(0,p.useState)(!1),Vt=(0,p.useRef)(null),Ht=(0,p.useRef)(null),Ut=(0,p.useRef)(null),Wt=(0,p.useRef)(null),Gt=(0,p.useRef)(null),Kt=(0,p.useRef)(null),qt=(0,p.useRef)(!1),Jt=(0,p.useRef)(!1),Yt=(0,p.useRef)(0),Xt=(0,p.useRef)(e7),Zt=(0,p.useRef)(e7),Qt=(0,p.useRef)(null),$t=(0,p.useRef)(new Set),en=(0,p.useRef)(0),tn=(0,p.useRef)(0),nn=(0,p.useRef)(f),rn=(0,p.useRef)(!1),an=(0,p.useRef)(!1),on=(0,p.useRef)(!1),sn=(0,p.useRef)({}),cn=(0,p.useRef)({}),ln=(0,p.useRef)({}),un=(0,p.useRef)(new Set),dn=(0,p.useRef)(new Set),fn=(0,p.useRef)(0),pn=(0,p.useRef)({id:null,status:null}),mn=(0,p.useRef)(new Map),hn=(0,p.useRef)(!1),gn=(0,p.useRef)(!1),_n=(0,p.useRef)(()=>{}),vn=m===void 0?He:m;nn.current=f;let yn=e?a7({projectId:e,tool:F?d:j?.tool??d,sessionId:j?.id??null}):null,bn=o7({projectId:e,sessionId:j?.id??null}),xn=yn?z[yn]??``:``,Sn=j?B[bn??``]??null:H,Cn=F?d:j?.tool??d,wn=(0,p.useMemo)(()=>j?W[j.id]??[]:[],[j,W]),Tn=(0,p.useMemo)(()=>j?ne[j.id]??0:0,[j,ne])>0,{models:En,isLoading:Dn}=QP(Cn),On=(0,p.useCallback)(()=>{ue(e=>e.length===0?e:[]),rge({projectId:e,tool:d})},[e,d]);(0,p.useEffect)(()=>{rn.current=F},[F]),(0,p.useEffect)(()=>{sn.current=z},[z]),(0,p.useEffect)(()=>{cn.current=B},[B]),(0,p.useEffect)(()=>{ln.current=W},[W]),(0,p.useEffect)(()=>{if(!yn||un.current.has(yn))return;un.current.add(yn);let e=$he(yn);e&&ee(t=>Object.prototype.hasOwnProperty.call(t,yn)?t:{...t,[yn]:e})},[yn]),(0,p.useEffect)(()=>{if(!bn||dn.current.has(bn))return;dn.current.add(bn);let e=ege(bn);e&&V(t=>({...t,[bn]:e}))},[bn]),(0,p.useEffect)(()=>{!yn||!Object.prototype.hasOwnProperty.call(z,yn)||d7({storageKey:yn,value:z[yn]??``})},[yn,z]),(0,p.useEffect)(()=>{!bn||!Object.prototype.hasOwnProperty.call(B,bn)||f7({storageKey:bn,notice:B[bn]??null})},[bn,B]),(0,p.useEffect)(()=>{Qt.current=k},[k]),(0,p.useEffect)(()=>{let t=vn??j?.latest_snapshot_id;if(!j?.id||!t||!e){Ve(null),ut(!1),Je(!1);return}let n=!1;return J(!0),Rae(e,j.id,t).then(e=>{if(!n){if(vn&&e.spec_session_id!==j.id){Ve(null),ut(!1),g?.();return}Ve(e),ut((e.created_ticket_ids?.length??0)>0),Je(!0)}}).catch(e=>{n||(Ve(null),ut(!1),vn&&e instanceof Ge&&e.status===404?g?.():$.error(e instanceof Error?e.message:q5(`errors.loadSession`)))}).finally(()=>{n||J(!1)}),()=>{n=!0}},[j?.latest_snapshot_id,j?.id,e,vn,g]);let kn=Be?.id??null,An=j?.id??null;(0,p.useEffect)(()=>{if(!e||!An||!kn){Et(null);return}let t=!1;return Ot(!0),j5(e,An,kn).then(e=>{t||Et(e)}).catch(()=>{t||Et(null)}).finally(()=>{t||Ot(!1)}),()=>{t=!0}},[e,An,kn]);let jn=(0,p.useCallback)(()=>{!e||!An||!kn||j5(e,An,kn).then(Et).catch(()=>{})},[e,An,kn]);(0,p.useEffect)(()=>{Qhe({projectId:e,isOpen:qe,width:Xe})},[e,qe,Xe]),(0,p.useEffect)(()=>{if(!(f===void 0||!pe)){if(!f){rn.current||On(),Se(null),A(null),M(null),Ue(null),I(!0);return}if(!(D.some(e=>e.id===f)||j?.id===f)){$.error(q5(`errors.initialSessionMissing`)),an.current=!0,A(null),M(null),I(!1),g?.();return}k!==f&&(Se(null),A(f),M(null),I(!1),an.current=!0)}},[j?.id,k,pe,g,On,f,D]),(0,p.useEffect)(()=>{Y||(Zt.current=Xe,Ut.current&&(Ut.current.style.setProperty(`--spec-artifact-panel-width`,`${Xe}px`),Ut.current.setAttribute(`data-desktop-width`,String(Xe))))},[Xe,Y]);let Mn=(0,p.useCallback)(async t=>{if(!e){O([]),fe(!1);return}fe(!pe);try{let n=await pN(e,t);if(t?.aborted)return;O(Y8(n)),me(!0);let r=new Set(n.map(e=>e.id));ze(e=>{let t=new Set([...e].filter(e=>r.has(e)));return t.size===e.size?e:t})}catch(e){Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.loadSessions`))}finally{t?.aborted||fe(!1)}},[e,pe]);(0,p.useEffect)(()=>{let e=mn.current,t=new Map,n=[];for(let r of D){let i=e.get(r.id)??null,a=r.agent_status??null;i===`running`&&(a===`done`||a===`error`)&&r.id!==k&&n.push(r),t.set(r.id,a)}mn.current=t,ze(e=>{let t=new Set(e),r=!1,i=new Set(D.map(e=>e.id));for(let e of t)i.has(e)||(t.delete(e),r=!0);for(let e of D){let i=e.agent_status??null,a=n.some(t=>t.id===e.id);if((e.id===k||i!==`done`&&i!==`error`)&&t.delete(e.id)){r=!0;continue}a&&!t.has(e.id)&&(t.add(e.id),r=!0)}return r?t:e})},[e,k,D]);let Nn=(0,p.useCallback)(async(t,n)=>{if(!e)return;ge(!0);let r=en.current+1;en.current=r;let i=tn.current;try{let a=await hN(e,t,n);if(n?.aborted)return;let o=tn.current!==i,s=en.current===r,c=Qt.current===t&&!rn.current;if(!s||o||!c)return;M(a)}catch(e){e instanceof Ge&&e.status===404&&nn.current===t&&Qt.current===t?g?.():Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.loadSession`))}finally{n?.aborted||ge(!1)}},[e,g]),Pn=(0,p.useCallback)(e=>{O(t=>{let n=t.findIndex(t=>t.id===e.id);if(n===-1)return Y8([...t,P5(e)]);let r=t.slice();return r[n]=P5(e),Y8(r)})},[]),Fn=(0,p.useCallback)((e,t)=>{O(n=>{let r=n.findIndex(t=>t.id===e);if(r===-1)return n;let i=n[r];if(i.pending_memory_suggestion_count===t)return n;let a=[...n];return a[r]={...i,pending_memory_suggestion_count:t},a}),M(n=>!n||n.id!==e||n.pending_memory_suggestion_count===t?n:{...n,pending_memory_suggestion_count:t})},[]),In=(0,p.useCallback)(async(n,r)=>{if(!e||!t?.memory_enabled){vt([]),bt(!1);return}bt(!0);try{let t=await Ar(e,null,r,void 0,n);if(r?.aborted)return;vt(t.suggestions),Fn(n,t.suggestions.length)}catch(e){Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.loadMemorySuggestions`))}finally{r?.aborted||bt(!1)}},[t?.memory_enabled,e,Fn]),Ln=(0,p.useCallback)(e=>{vt(t=>{let n=t.filter(t=>t.id!==e);return k&&Fn(k,n.length),n}),wt(e=>e+1),Mn(),k&&Nn(k)},[k,Nn,Mn,Fn]),Rn=(0,p.useCallback)(e=>!!(e.first_user_message_preview||e.last_user_message_at||e.messages?.some(e=>e.role===`user`)),[]),zn=(0,p.useCallback)(()=>({tool:d,mode:pt?`grill`:`standard`,model:En.length>0&&G||null,variant:En.length>0&&se||null,skills:ie.length>0?le:[]}),[d,pt,En.length,G,se,ie.length,le]),Bn=(0,p.useCallback)(()=>{rn.current=!0,Qt.current=null,I(!0),On(),A(null),Ue(null),M(null),Ve(null),R(null),U(null),Se(null),K(null)},[On]),Vn=(0,p.useCallback)(()=>{_e||ye||(Bn(),_?.(null))},[_e,ye,_,Bn]),Hn=(0,p.useMemo)(()=>qY(),[]),Un=(0,p.useMemo)(()=>(0,X.jsx)(i7,{modifierLabel:Hn,keys:[r7],ariaHidden:!0}),[Hn]),Wn=(0,p.useMemo)(()=>(0,X.jsx)(Xhe,{label:q5(`sidebar.newSessionTooltip`),modifierLabel:Hn,keys:[r7]}),[Hn]);(0,p.useEffect)(()=>{let t=t=>{if(Yhe(t)){if(!e||_e||ye)return;t.preventDefault(),Vn(),Ie(e=>e+1);return}};return window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`keydown`,t)}},[e,_e,ye,Vn]);let Gn=(0,p.useCallback)(e=>{ye||(Se(null),A(e.id),Ue(null),I(!1),R(null),U(null),fn.current+=1,_?.(e.id))},[ye,_]),Kn=(0,p.useCallback)(async r=>{if(!e)return!1;ct(r.id);try{let i=await hN(e,r.id);return Pn(i),Qt.current===i.id&&M(i),i.target_available===!1?($.error(i.target_unavailable_reason??q5(`targets.unavailable`)),!1):!t||s5({activeProject:t,activeProjectBranchState:n,session:i})?!0:u?await u(i):!1}catch(e){return Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.restoreTarget`)),!1}finally{ct(e=>e===r.id?null:e)}},[t,n,e,u,Pn]),qn=(0,p.useCallback)(async t=>{if(e){Se(t);try{await Lae(e,t)}catch(e){Se(e=>e===t?null:e),Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.stopSession`))}}},[e]);(0,p.useEffect)(()=>{if(!xe)return;let e=j?.id===xe?j:D.find(e=>e.id===xe)??null;(!e||e.agent_status!==`running`)&&Se(null)},[j,xe,D]);let Jn=(0,p.useCallback)(async()=>{if(!(!e||!j||!Be)){nt(!0);try{if(!await Kn(j))return;let t=await Bae(e,j.id,Be.id);ut(!0),$.success(q5(`actions.createTicketsSuccess`,{count:t.tickets.length})),Mn()}catch(e){if(Ye(e))return;if(Ke(e,`existing_ticket_ids`)){ut(!0);return}$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{nt(!1)}}},[e,j,Be,Mn,Kn]),Yn=(0,p.useCallback)(()=>{Jn()},[Jn]),Xn=(0,p.useCallback)(async()=>{if(!(!e||!j||!Be)&&y){it(!0);try{if(!await Kn(j))return;let t=await Vae(e,j.id,Be.id);y(t.draft_text,t.spec_session_id,t.spec_snapshot_id)}catch(e){if(Ye(e))return;e instanceof Ge&&e.status===409&&await Nn(j.id),$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{it(!1)}}},[e,j,Be,Nn,y,Kn]),Zn=(0,p.useCallback)(async t=>{let n=t?.projectId??e,r=t?.sessionId??j?.id,i=t?.snapshotId??Be?.id;if(!(!n||!r||!i)){ot(!0);try{if(!j||j.id!==r||!await Kn(j))return;await zae(n,r,i,{overwrite:t?.overwrite}),ft(null),$.success(q5(`actions.exportSuccess`))}catch(e){if(Ye(e))return;if(e instanceof vN){ft({path:e.conflictingPath,projectId:n,sessionId:r,snapshotId:i});return}e instanceof Ge&&e.status===409&&j&&await Nn(j.id),$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{ot(!1)}}},[e,j,Be,Nn,Kn]),Qn=(0,p.useCallback)(()=>{Kt.current?.(),Kt.current=null},[]),$n=(0,p.useCallback)(e=>{if(!Vt.current)return;let t=Vt.current.getBoundingClientRect().width,n=l7(e,t);Zt.current=n,Ut.current&&(Ut.current.style.setProperty(`--spec-artifact-panel-width`,`${n}px`),Ut.current.setAttribute(`data-desktop-width`,String(n)))},[]),er=(0,p.useCallback)(e=>{let t=Wt.current,n=Gt.current,r=qt.current;if(t!==null){if(Wt.current=null,Gt.current=null,qt.current=!1,Qe(!1),et(!1),Qn(),e!==null&&typeof Ht.current?.hasPointerCapture==`function`&&Ht.current.hasPointerCapture(e)&&typeof Ht.current.releasePointerCapture==`function`&&Ht.current.releasePointerCapture(e),n===`collapsed`){if(!r)return;Ze(Zt.current),Je(!0);return}Ze(Zt.current)}},[Qn]),tr=(0,p.useCallback)((e,t)=>{if(Wt.current!==e)return;let n=t-Yt.current,r=Xt.current-n;if(Gt.current===`collapsed`){if(!qt.current&&r<Khe)return;qt.current||(qt.current=!0,Jt.current=!0,et(!0),Qe(!0))}$n(r)},[$n]),nr=(0,p.useCallback)((e,t)=>{if(Wt.current===e){if(t!==null&&(Gt.current===`inline`||qt.current)){let e=t-Yt.current;$n(Xt.current-e)}er(e)}},[er,$n]),rr=(0,p.useCallback)(e=>{e.preventDefault(),Wt.current=e.pointerId,Gt.current=qe?`inline`:`collapsed`,qt.current=!1,Jt.current=!1,Yt.current=e.clientX,Xt.current=qe?Zt.current:0,Qe(qe),Qn(),typeof e.currentTarget.setPointerCapture==`function`&&e.currentTarget.setPointerCapture(e.pointerId);let t=e=>{tr(e.pointerId,e.clientX)},n=e=>{nr(e.pointerId,e.clientX)},r=e=>{nr(e.pointerId,e.clientX)};window.addEventListener(`pointermove`,t),window.addEventListener(`pointerup`,n),window.addEventListener(`pointercancel`,r),Kt.current=()=>{window.removeEventListener(`pointermove`,t),window.removeEventListener(`pointerup`,n),window.removeEventListener(`pointercancel`,r)}},[nr,tr,qe,Qn]),ir=(0,p.useCallback)(e=>{tr(e.pointerId,e.clientX)},[tr]),ar=(0,p.useCallback)(e=>{nr(e.pointerId,e.clientX)},[nr]),or=(0,p.useCallback)(e=>{nr(e.pointerId,e.clientX)},[nr]),sr=(0,p.useCallback)(e=>{Wt.current===e.pointerId&&er(e.pointerId)},[er]),cr=(0,p.useCallback)(()=>{Je(!1)},[]),lr=(0,p.useCallback)(async()=>{if(!e||Ce.length===0)return;let t=Ce;Ee(e=>{let n=new Set(e);for(let e of t)n.add(e);return n});let n=[],r=[];for(let i of t)try{await _N(e,i),r.push(i)}catch(e){Ye(e)||n.push(e instanceof Error?e.message:q5(`errors.deleteSession`))}if(Ee(e=>{let n=new Set(e);for(let e of t)n.delete(e);return n}),we([]),_n.current(r),n.length>0){$.error(n.join(`
276
- `));return}De&&(Oe(!1),Ae(new Set),$.success(q5(`toasts.deleteSelectedSuccess`,{count:t.length})))},[e,Ce,De]),ur=(0,p.useCallback)((t,n={})=>{let r=new Set(t);if(r.size===0)return;let i=Qt.current,a=n.preserveDraftRoute===!0,o=!!(a&&i&&r.has(i)&&nn.current===i),s=!!(!a&&i&&r.has(i)),c=s?D.find(e=>!r.has(e.id))??null:null;o&&(On(),_?.(null)),s&&(c||On(),_?.(c?.id??null));for(let t of r)d7({storageKey:a7({projectId:e,tool:d,sessionId:t}),value:``}),f7({storageKey:o7({projectId:e,sessionId:t}),notice:null});te(e=>{let t={...e},n=!1;for(let e of r)Object.prototype.hasOwnProperty.call(t,e)&&(delete t[e],n=!0);return n?t:e}),V(t=>{let n={...t},i=!1;for(let t of r){let r=o7({projectId:e,sessionId:t});r&&Object.prototype.hasOwnProperty.call(n,r)&&(delete n[r],i=!0)}return i?n:t}),O(e=>{let t=e.filter(e=>!r.has(e.id));if(i&&r.has(i)){if(nn.current===i)return a?(A(null),M(null),Ue(null),I(!0),t):(A(null),M(null),Ue(null),I(c===null),t);let e=t[0]??null;A(e?.id??null),M(null),Ue(null),I(e===null)}return t}),ze(e=>{let t=new Set(e),n=!1;for(let e of r)t.delete(e)&&(n=!0);return n?t:e}),K(e=>e&&r.has(e.parentId)?null:e),Se(e=>e&&r.has(e)?null:e),we(e=>e.filter(e=>!r.has(e))),Ee(e=>{let t=new Set(e),n=!1;for(let e of r)t.delete(e)&&(n=!0);return n?t:e}),Ae(e=>{let t=new Set(e),n=!1;for(let e of r)t.delete(e)&&(n=!0);return n?t:e})},[e,d,_,On,D]),dr=(0,p.useCallback)((e,t)=>{ur([e],t)},[ur]);_n.current=ur;let fr=(0,p.useCallback)((e,t)=>{e&&ee(n=>n[e]===t?n:{...n,[e]:t})},[]),pr=(0,p.useCallback)((e,t)=>{te(n=>{if(t.length===0){if(!Object.prototype.hasOwnProperty.call(n,e))return n;let t={...n};return delete t[e],t}return{...n,[e]:t}})},[]),mr=(0,p.useCallback)(e=>{te(t=>{if(!Object.prototype.hasOwnProperty.call(t,e))return t;let n={...t};return delete n[e],n}),re(t=>{if(!Object.prototype.hasOwnProperty.call(t,e))return t;let n={...t};return delete n[e],n})},[]),hr=(0,p.useCallback)((e,t)=>{e&&V(n=>(n[e]??null)===t?n:{...n,[e]:t})},[]),gr=(0,p.useCallback)(e=>{e&&(V(t=>!Object.prototype.hasOwnProperty.call(t,e)||t[e]===null?t:{...t,[e]:null}),f7({storageKey:e,notice:null}))},[]),_r=(0,p.useCallback)(t=>{if(e){if(t.spec_session){let n=a7({projectId:e,tool:t.spec_session.tool,sessionId:t.spec_session.id}),r=o7({projectId:e,sessionId:t.spec_session.id});fr(n,t.prompt_text),hr(r,t.import_notice),pr(t.spec_session.id,t.imported_attachments),Pn(t.spec_session),M(t.spec_session),A(t.spec_session.id),I(!1),R(null),U(null),Ie(e=>e+1);return}R(t.external_source),U(t.import_notice),On(),I(!0),A(null),M(null),Ue(null),Ve(null),fr(a7({projectId:e,tool:d}),t.prompt_text),Ie(e=>e+1)}},[e,d,On,fr,hr,pr,Pn]),vr=(0,p.useCallback)(async({provider:e,issueReference:t})=>{let n=$.loading(q5(`toasts.importPreparing`));try{let r=e===`jira`?await w?.({issueReference:t,...zn()}):await E?.({issueReference:t,...zn()});if(!r)throw Error(q5(`toasts.importError`));return(r.import_notice?.skipped.reduce((e,t)=>e+t.count,0)??0)>0?$.warning(q5(`toasts.importPartialSuccess`),{id:n}):$.success(q5(`toasts.importSuccess`),{id:n}),r}catch(e){if(Ye(e))$.dismiss(n);else{let t=e instanceof Error&&e.message?e.message:q5(`toasts.importError`);$.error(t,{id:n})}throw e}},[zn,E,w]),yr=(0,p.useMemo)(()=>[{key:`jira`,label:S(`jiraImportField.label`),placeholder:S(`jiraImportField.placeholder`),state:C,onImport:e=>vr({provider:`jira`,issueReference:e})},{key:`github`,label:S(`githubImportField.label`),placeholder:S(`githubImportField.placeholder`),state:T,onImport:e=>vr({provider:`github`,issueReference:e})}],[S,C,T,vr]),br=yr.some(e=>e.state===`enabled`);(0,p.useEffect)(()=>{h&&(vr({provider:h.external_source.provider,issueReference:h.external_source.external_key}).then(_r).catch(()=>void 0),v?.())},[h,vr,_r,v]);let xr=(0,p.useCallback)(async()=>{if(!(!e||!j||!Be)){At(!0);try{await yhe(e,j.id,Be.id,{tool:j.tool,...zt?{model:Ft||null,variant:Lt||null}:{},skills:j.skills}),zt&&age({projectId:e,tool:j.tool,model:Ft||null,variant:Lt||null}),jn()}catch(e){if(Ye(e))return;e instanceof Ge&&e.status===409&&await Nn(j.id),$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{At(!1)}}},[e,j,Be,zt,Ft,Lt,jn,Nn]),Sr=(0,p.useCallback)(async()=>{if(!(!e||!j||!Be)){Mt(!0);try{await bhe(e,j.id,Be.id),jn()}catch(e){if(Ye(e))return;$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{Mt(!1)}}},[e,j,Be,jn]),Cr=(0,p.useCallback)(async()=>{if(!e||!j||!Be)return;let t=Tt?.run;if(t){Pt(!0);try{fr(yn,(await xhe(e,j.id,Be.id,t.id)).draft_text),Ie(e=>e+1)}catch(e){if(Ye(e))return;$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{Pt(!1)}}},[e,j,Be,Tt,fr,yn]),wr=(0,p.useCallback)(e=>{e&&(ee(t=>t[e]===``?t:{...t,[e]:``}),d7({storageKey:e,value:``}))},[]),Tr=(0,p.useCallback)((e,t)=>{re(n=>{let r=Math.max(0,(n[e]??0)+t);if(r===0){if(!Object.prototype.hasOwnProperty.call(n,e))return n;let t={...n};return delete t[e],t}return{...n,[e]:r}})},[]),Er=(0,p.useCallback)(async t=>{if(!(!e||ht||gn.current)&&!(j&&j.agent_status===`running`)){if(!k||!j){mt(t),b7({projectId:e,grillOn:t});return}if(j.mode===(t?`grill`:`standard`)){mt(t);return}gt(!0);try{let n=await Nae(e,j.id,{mode:t?`grill`:`standard`});M(n),Pn(n),mt(t),t||K5(n.messages,n.latest_snapshot_created_at)&&await gN(e,n.id,{instruction:q5(`grill.finalizePrompt`),tool:n.tool,model:En.length>0&&G||null,variant:En.length>0&&se||null,skills:ie.length>0?le:[]})}catch(e){Ye(e)||$.error(e instanceof Error?e.message:q5(`grill.updateModeError`))}finally{gt(!1)}}},[e,j,k,ht,Pn,En,G,se,ie,le]),Dr=(0,p.useCallback)(async()=>{if(!e||_e||ye||hn.current||gn.current||t&&j&&!s5({activeProject:t,activeProjectBranchState:n,session:j}))return;let r=xn.trim();if(!r&&wn.length===0)return;be(!0);let i=yn,a=performance.now();fn.current+=1;let o=`spec:${fn.current}`;try{let t=k,n=!t,s=n;if(t&&!j){let r=await hN(e,t);r?s=r.messages?.length===0:(n=!0,s=!0,t=null)}else j&&(s=j.messages?.length===0);if(n){ve(!0);let n=await mN(e,{tool:d,mode:pt?`grill`:`standard`,model:En.length>0&&G||null,variant:En.length>0&&se||null,skills:ie.length>0?le:[],external_source:L??null});t=n.id,A(t),M(n),I(!1),_?.(t),R(null),mt(!1),b7({projectId:e,grillOn:!1}),s7({projectId:e,tool:d}),ve(!1)}if(!t)throw Error(`Unable to resolve the spec session.`);Se(e=>e===t?null:e),K({parentType:`spec`,parentId:t,turnKey:o,startedAt:a});let c=wn.map(e=>e.id),l=await gN(e,t,{instruction:r,tool:j?.tool??d,model:G||null,variant:se||null,skills:le,attachment_ids:c.length>0?c:void 0});M(l),_7({projectId:e,tool:l.tool,model:l.model,variant:l.variant,skills:s?[]:l.skills}),Ie(e=>e+1),mr(t),wr(i),gr(o7({projectId:e,sessionId:t})),U(null)}catch(e){K(e=>e?.turnKey===o?null:e);let t=Ke(e,`spec_session`);t?(M(t),Pn(t)):e instanceof Ge&&e.status===409&&Qt.current&&await Nn(Qt.current),Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{be(!1),ve(!1)}},[t,n,e,_e,ye,xn,wn,yn,k,j,d,pt,En,G,se,ie,le,L,Nn,Pn,mr,wr,gr,_]),Or=(0,p.useCallback)(async t=>{if(e){$t.current.add(t.id);try{await _N(e,t.id),dr(t.id,{preserveDraftRoute:!0}),Bn()}catch(e){throw $t.current.delete(t.id),e}}},[e,Bn,dr]),kr=(0,p.useCallback)(async t=>{if(!e||Cn!==`opencode`&&Cn!==`claude`)return;let n=k,r=null;if(!n&&t.length>0)try{ve(!0);let t=await mN(e,{tool:d,mode:pt?`grill`:`standard`,model:En.length>0&&G||null,variant:En.length>0&&se||null,skills:ie.length>0?le:[],external_source:L??null});r=t,n=t.id,A(n),M(t),I(!1),_?.(n),s7({projectId:e,tool:d})}catch(e){Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.upload`));return}finally{ve(!1)}if(n){Tr(n,t.length);try{let r=await Fae(e,n,t),i=[...ln.current[n]??[],...r.attachments];pr(n,i)}catch(e){if(r&&!xn.trim())try{await Or(r)}catch{}Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.upload`))}finally{Tr(n,-t.length)}}},[e,k,d,Cn,En,G,se,ie,le,pt,L,xn,Or,Tr,_,pr]),jr=(0,p.useCallback)(async t=>{if(!e||!j)return;let n=j,r=n.id,i=(ln.current[r]??[]).filter(e=>e.id!==t);try{await Iae(e,r,t),pr(r,i),i.length===0&&!xn.trim()&&(n.messages?.length??0)===0&&await Or(n)}catch(e){Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.removeAttachment`))}},[e,j,Or,xn,pr]);(0,p.useEffect)(()=>{Le&&(Le.parentId===k&&(ye||j?.agent_status===`running`)||K(null))},[j?.agent_status,k,ye,Le]),(0,p.useEffect)(()=>{if(!on.current){on.current=!0;return}let t=c7(e),n=u7(e);rn.current=!1,an.current=!1,un.current=new Set,dn.current=new Set,A(null),M(null),Ue(null),Ve(null),I(!1),R(null),ee({}),V({}),U(null),te({}),re({}),$t.current.clear(),Se(null),we([]),Ee(new Set),Oe(!1),Ae(new Set),K(null),vt([]),bt(!1),St(!1),me(!1),ze(new Set),mn.current=new Map,Zt.current=n.width,Pe(t.isOpen),Ze(n.width),Je(n.isOpen),mt(y7(e)),gt(!1)},[e]);let Mr=(0,p.useCallback)((e,t)=>{Ae(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]);(0,p.useEffect)(()=>{let e=new AbortController;return Mn(e.signal),()=>{e.abort()}},[Mn]),(0,p.useEffect)(()=>{if(f!==void 0||rn.current||F||k||an.current||D.length===0||t?.active_target_kind!==`bundle`&&n?.status===`loading`)return;let e=t?D.find(e=>s5({activeProject:t,activeProjectBranchState:n,session:e}))??null:D[0]??null;an.current=!0,e&&A(e.id)},[t,n,k,F,f,D]),(0,p.useEffect)(()=>{if(Cn!==`opencode`&&Cn!==`claude`){ae([]),Me(!1);return}if(Cn!==`opencode`){ae([]);return}let t=new AbortController;return(async()=>{Me(!0);try{ae(await $P(Cn,t.signal,e))}catch(e){Ye(e)||ae(e=>e)}finally{t.signal.aborted||Me(!1)}})(),()=>{t.abort()}},[e,Cn]),(0,p.useEffect)(()=>{if(Cn!==`opencode`&&Cn!==`claude`){oe(``),ce(``),ue([]);return}if(F){let t=g7({projectId:e,tool:Cn}),n=new Set(En.map(e=>e.id)),r=t?.model??``,i=r&&(n.size===0||n.has(r)),a=En.find(e=>e.id===r)??null,o=t?.variant??``,s=!a||a.variants.includes(o),c=new Set(ie.map(e=>e.name));oe(i?r:``),ce(e=>!i||!s?``:o||e),ue(Cn===`opencode`?(t?.skills??[]).filter(e=>c.has(e)):[]);return}oe(j?.model??``),ce(j?.variant??``),ue(j?.skills??[])},[e,j?.id,j?.model,j?.skills,j?.variant,En,ie,Cn,F]),(0,p.useEffect)(()=>{if(F||!k){M(null);return}if(j?.id===k)return;M(null);let e=new AbortController;return Nn(k,e.signal),()=>{e.abort()}},[j,k,F,Nn]),(0,p.useEffect)(()=>{St(!1)},[k,F]),(0,p.useEffect)(()=>{if(!t?.memory_enabled||F||!k){vt([]),bt(!1);return}let e=new AbortController;return In(k,e.signal),()=>{e.abort()}},[t?.memory_enabled,k,F,In,Ct]),(0,p.useEffect)(()=>{!xt||yt||_t.length>0||St(!1)},[yt,xt,_t.length]),(0,p.useEffect)(()=>{let e=pn.current,n=j?.id??null,r=j?.agent_status??null;e.id===n&&e.status===`running`&&r===`done`&&t?.memory_enabled&&n&&wt(e=>e+1),pn.current={id:n,status:r}},[t?.memory_enabled,j?.agent_status,j?.id]),(0,p.useEffect)(()=>{if(!k||j?.agent_status!==`running`)return;let e=new AbortController,t=window.setInterval(()=>{Promise.all([Mn(e.signal),Nn(k,e.signal)])},Whe);return()=>{e.abort(),window.clearInterval(t)}},[j?.agent_status,k,Nn,Mn]),(0,p.useEffect)(()=>{if(!e)return;let t=t=>{!t||t.project_id!==e||(!F&&t.id===Qt.current&&(tn.current+=1,M(t)),Rn(t)&&Pn(t))},n=t=>{if(!t||t.project_id!==e)return;let n=$t.current.delete(t.id);dr(t.id,n?{preserveDraftRoute:!0}:void 0)},r=()=>{Mn();let e=Qt.current;e&&!rn.current&&Nn(e)};return x.on(`connect`,r),x.on(`spec-session:created`,t),x.on(`spec-session:updated`,t),x.on(`spec-session:deleted`,n),()=>{x.off(`connect`,r),x.off(`spec-session:created`,t),x.off(`spec-session:updated`,t),x.off(`spec-session:deleted`,n)}},[e,F,Nn,Mn,Rn,Pn,dr,x]),(0,p.useEffect)(()=>{if(!e||!kn)return;let t=e=>{!e||e.spec_snapshot_id!==kn||jn()};return x.on(`spec-review:updated`,t),()=>{x.off(`spec-review:updated`,t)}},[e,kn,jn,x]);let Nr=(0,p.useMemo)(()=>X8(D),[D]),Pr=(0,p.useMemo)(()=>{let e=new Set(Nr.find(e=>e.key===`older`)?.sessions.map(e=>e.id)??[]);return[{key:`unavailable`,label:q5(`sidebar.presets.unavailable`),matches:e=>e.target_available===!1},{key:`older`,label:q5(`sidebar.presets.older`),matches:t=>e.has(t.id)}]},[Nr]),Fr=(0,p.useCallback)(e=>{e.key!==`Enter`||e.shiftKey||j?.agent_status===`running`||_e||ye||Tn||hn.current||gn.current||(e.preventDefault(),Dr())},[Dr,j?.agent_status,_e,ye,Tn]),Ir=(0,p.useCallback)(t=>{if(!e||Cn!==`opencode`&&Cn!==`claude`)return;let n=Array.from(t.clipboardData.files).filter(e=>e.type.startsWith(`image/`));n.length!==0&&(t.preventDefault(),kr(n))},[e,Cn,kr]),Lr=(0,p.useMemo)(()=>$8(En),[En]),Rr=(0,p.useMemo)(()=>j?t5({modelLabel:e5({availableModelsById:Lr,model:j.model}),tool:j.tool}):null,[j,Lr]),zr=(0,p.useMemo)(()=>j?.messages?j.messages.map(e=>({id:e.id,role:e.role,kind:e.kind,content:e.content,attachments:e.attachments??[],responseTiming:e.response_timing?KK(e.response_timing):null,transcript_runs:e.transcript_runs??null,metadata:e.metadata,created_at:e.created_at,displayTitle:e.role===`assistant`?Rr??Q8(j.tool):n5()})):[],[j,Rr]),Br=k!==null||F,Vr=F?null:j,Hr=Vr?.target_available===!1,Ur=!!(t&&Vr&&!Hr&&!s5({activeProject:t,activeProjectBranchState:n,session:Vr})),Wr=Ur&&Vr?q5(`targets.mismatchReason`,{sessionTarget:l5(Vr),currentTarget:u5({activeProject:t,activeProjectBranchState:n})}):null,Gr=Hr?Vr?.target_unavailable_reason??q5(`targets.unavailable`):null,Kr=Hr||Ur,qr=Vr?.streaming_response??null,Jr=Vr?.agent_status===`running`,Yr=!!(ye&&Le?.parentType===`spec`&&Le.parentId===k),Xr=Jr||Yr,Zr=Xr?Rr:null,Qr=Jr&&xe===k,$r=!!e&&!_e&&(F||k!==null&&!Kr),ei=!!(t?.memory_enabled&&j&&!F&&(j.pending_memory_suggestion_count>0||yt)),ti=(Cn===`opencode`||Cn===`claude`)&&(F||k!==null)&&Vr?.agent_status!==`running`,ni=(0,p.useMemo)(()=>{if(!j?.messages)return null;for(let e=j.messages.length-1;e>=0;--e){let t=j.messages[e];if(t.kind===`grill-question`)return t.id}return null},[j]),ri=(0,p.useMemo)(()=>!j||j.mode!==`grill`?!1:K5(j.messages,j.latest_snapshot_created_at),[j]),ii=(0,p.useMemo)(()=>[...j?.messages??[]].reverse().find(e=>e.metadata?.ask_question?.status===`pending`)??null,[j]),ai=!!ii,oi=(0,p.useCallback)(async t=>{if(!e||!k||!j)return;be(!0),fn.current+=1;let n={parentType:`spec`,parentId:k,turnKey:`spec:${fn.current}`,startedAt:performance.now()};K(n);try{M(await gN(e,k,{instruction:t,tool:j.tool,model:En.length>0&&G||null,variant:En.length>0&&se||null,skills:ie.length>0?le:[]})),Ie(e=>e+1)}catch(e){K(e=>e?.turnKey===n.turnKey?null:e),Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{be(!1)}},[e,k,j,En,G,se,ie,le]),si=(0,p.useCallback)(async(t,n)=>{if(!e||!j||N)return;let r=UJ({parentType:`spec`,parentId:j.id,setId:n.set_id});P(n.set_id),be(!0),fn.current+=1;let i={parentType:`spec`,parentId:j.id,turnKey:`spec:${fn.current}`,startedAt:performance.now()};K(i);try{let r=await Pae(e,j.id,t,n);M(r),Pn(r)}catch(e){if(e instanceof Ge&&e.status===409){GJ(r);let t=e.data&&typeof e.data==`object`&&`spec_session`in e.data?e.data.spec_session:null;t?(M(t),Pn(t)):await Nn(j.id)}throw K(e=>e?.turnKey===i.turnKey?null:e),$.error(e instanceof Error?e.message:q5(`errors.resolveQuestions`)),e}finally{P(null),be(!1)}},[e,j,Nn,N,Pn]),ci=(0,p.useCallback)(e=>{if(e.role!==`assistant`)return;let t=e.metadata,n=t?.ask_question;if(n&&j)return(0,X.jsx)(QJ,{messageContent:e.content,questionSet:n,storageKey:UJ({parentType:`spec`,parentId:j.id,setId:n.id}),isActive:n.status===`pending`&&ii?.id===e.id,isDisabled:Kr||j.agent_status===`running`||N===n.id,onResolve:t=>si(e.id,t)});if(e.kind!==`grill-question`)return;let r=t?.grill_question;if(r)return(0,X.jsx)(M5,{question:r,isActive:Xr?!1:e.id===ni&&j?.agent_status!==`running`&&j?.mode===`grill`,isDisabled:Kr||ye||_e||ht,labels:{rationaleLabel:q5(`grill.rationaleLabel`),suggestionsLabel:q5(`grill.suggestionsLabel`),recommendedSuggestionLabel:q5(`grill.recommendedSuggestionLabel`),answerPlaceholder:q5(`grill.answerPlaceholder`),submitLabel:q5(`grill.submitLabel`),submittingLabel:q5(`grill.submittingLabel`)},onSubmitAnswer:e=>{oi(e)}})},[j,Xr,ye,_e,Kr,ht,ni,ii?.id,si,N,oi]),li=(Cn===`opencode`||Cn===`claude`)&&En.length>0,ui=Cn,di=F?q5(`composer.newSpecTitle`):j?.title??q5(`composer.specTitle`),fi=li?G||null:j?.model??null,pi=e5({availableModelsById:Lr,model:fi}),mi=j?.agent_status===`stopped`,hi=q5(`composer.placeholderSpec`),gi=D.some(e=>e.agent_status!==`running`),_i=(0,p.useMemo)(()=>({ariaLabel:q5(`sidebar.ariaLabel`),newSession:q5(`sidebar.newSession`),collapseAriaLabel:q5(`sidebar.collapseAriaLabel`),openAriaLabel:q5(`sidebar.openAriaLabel`),cancelSelection:q5(`sidebar.cancelSelection`),addPreset:q5(`sidebar.addPreset`),deleteSelected:q5(`sidebar.deleteSelected`),selectedCount:e=>`${e} selected`,select:q5(`sidebar.select`),loadingSessions:q5(`sidebar.loadingSessions`),noSessions:q5(`sidebar.noSessions`),deleteSessionAriaLabel:q5(`sidebar.deleteSessionAriaLabel`),selectSessionAriaLabel:e=>q5(`sidebar.selectSessionAriaLabel`,{title:e}),selectSessionTitle:e=>q5(`sidebar.selectSessionTitle`,{title:e}),deleteSessionTitle:e=>q5(`sidebar.deleteSessionTitle`,{title:e})}),[]),vi=(0,p.useMemo)(()=>({title:q5(`deleteModal.title`),bulkTitle:q5(`deleteModal.bulkTitle`),description:q5(`deleteModal.description`),bulkDescription:e=>q5(`deleteModal.bulkDescription`,{count:e}),cancel:q5(`deleteModal.cancel`),delete:q5(`deleteModal.delete`),deleting:q5(`deleteModal.deleting`)}),[]),yi=(0,p.useCallback)((e,t)=>e.agent_status===`running`?`running`:!t&&Re.has(e.id)?`finished`:null,[Re]),bi=(0,p.useCallback)(e=>e.agent_status===`running`?q5(`sidebar.cannotDeleteRunning`):null,[]),xi=!!(t?.memory_enabled&&k&&!F),Si=(0,p.useCallback)(e=>{let r=c5({session:e,activeProject:t,activeProjectBranchState:n}),i=xi&&e.pending_memory_suggestion_count>0?J5(e.pending_memory_suggestion_count):null,a=(e.linked_ticket_count??0)+(e.linked_chat_count??0);return a>0?[e.title,r,i,q5(`sidebar.linkedImplementationsAriaLabel`,{itemCount:a})].filter(Boolean).join(` `):e.has_completed_work===1?[e.title,r,i,q5(`sidebar.linkedImplementationsAriaLabelHistorical`)].filter(Boolean).join(` `):[e.title,r,i].filter(Boolean).join(` `)},[t,n,xi]),Ci=e=>{let t=e.first_user_message_preview??e.messages?.find(e=>e.role===`user`)?.content;return t&&t.replace(/\s+/g,` `).trim()||null},wi=(0,p.useCallback)(({session:e,activityState:r})=>{let i=Ci(e),a=c5({session:e,activeProject:t,activeProjectBranchState:n}),o=e.linked_ticket_count??0,s=e.linked_chat_count??0,c=o+s,l=e.has_completed_work===1||c>0,u=c>0,d=u?q5(`sidebar.linkedImplementationsTooltip`,{ticketCount:o,chatCount:s}):q5(`sidebar.linkedImplementationsTooltipHistorical`),f=xi&&e.pending_memory_suggestion_count>0;return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[a?(0,X.jsx)(`div`,{className:`mb-1 truncate text-[10px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75`,children:a}):null,(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 truncate text-[13px] font-medium leading-5`,children:[(0,X.jsx)(`span`,{className:`truncate`,children:e.title}),f?(0,X.jsx)(Ew,{tone:`muted`,className:`shrink-0`,"aria-label":J5(e.pending_memory_suggestion_count),title:J5(e.pending_memory_suggestion_count),children:e.pending_memory_suggestion_count}):null,l&&(0,X.jsx)(vv,{content:d,children:(0,X.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5 text-[11px] text-indigo-500 dark:text-indigo-400`,children:[(0,X.jsx)(wF,{className:`size-3`}),u&&(0,X.jsx)(`span`,{children:c})]})})]}),i?(0,X.jsx)(`div`,{className:`mt-0.5 line-clamp-1 text-xs leading-4 text-muted-foreground`,children:i}):null,e.target_available===!1?(0,X.jsx)(`div`,{className:`mt-1 line-clamp-1 text-[11px] leading-4 text-amber-200/90`,children:e.target_unavailable_reason??q5(`targets.unavailable`)}):null]}),(0,X.jsx)(ib,{state:r,className:`mt-1`})]})},[t,n,xi]),Ti=Jr?(0,X.jsx)(N8,{isInterrupting:Qr,onStop:()=>{k&&qn(k)},interruptLabel:q5(`composer.interrupt`),interruptingLabel:q5(`composer.interrupting`)}):null,Ei=(0,p.useMemo)(()=>En.find(e=>e.id===G)??null,[En,G]),Di=({model:t=G,variant:n=se,skills:r=le}={})=>{F&&_7({projectId:e,tool:d,model:t||null,variant:t&&n||null,skills:d===`opencode`?r:[]})},Oi=Cn===`opencode`||Cn===`claude`?je||Dn?(0,X.jsx)(gY,{}):En.length>0?(0,X.jsx)(_Y,{model:G,variant:se,skills:le,showModelSelector:!0,showSkillsSelector:ie.length>0,availableModels:En,availableSkills:ie,selectedModel:Ei,onModelChange:e=>{let t=En.find(t=>t.id===e)??null,n=t&&t.variants.includes(se)?se:``;oe(e),ce(n),Di({model:e,variant:n})},onVariantChange:e=>{ce(e),Di({variant:e})},onSkillsChange:e=>{ue(e),Di({skills:e})},modelSelectId:`spec-model-select`,variantSelectId:`spec-variant-select`,skillsSelectId:`spec-skills-select`}):null:null,ki=(0,p.useMemo)(()=>Ce.length===1?D.find(e=>e.id===Ce[0])?.title??``:``,[Ce,D]),Ai=(0,p.useMemo)(()=>D.filter(e=>Ce.includes(e.id)),[D,Ce]),ji=Br&&j!==null,Mi=ji&&!qe&&!$e,Ni=ji&&(qe||$e);(0,p.useEffect)(()=>{if(!Ni||Y||!Vt.current)return;let e=Vt.current,t=()=>{let t=e.getBoundingClientRect().width;if(t<=0)return;let n=l7(Xe,t);Zt.current=n,Ut.current&&(Ut.current.style.setProperty(`--spec-artifact-panel-width`,`${n}px`),Ut.current.setAttribute(`data-desktop-width`,String(n))),Ze(e=>e===n?e:n)};if(t(),typeof ResizeObserver!=`function`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[Xe,Ni,Y]);let Pi=j?.tool??d,Fi=Pi===`opencode`&&En.length>0,Ii=(0,p.useMemo)(()=>En.find(e=>e.id===Ft)??null,[En,Ft]),Li=Be&&ji?{review:Tt,isRunning:kt||jt,isLoading:Dt,availableModels:En,showModelSelector:Fi,runConfigTool:Pi,runConfigModel:Ft,runConfigVariant:Lt,selectedDiscoveredModel:Ii,onRunConfigModelChange:t=>{let n=En.find(e=>e.id===t)??null;It(t),Bt(!!t),t||oge({projectId:e,tool:Pi}),Rt(e=>n&&n.variants.includes(e)?e:``)},onRunConfigVariantChange:e=>{Rt(e),Bt(!!Ft)},onLaunchReview:()=>{xr()},onStopReview:()=>{Sr()},onSendToPlanner:()=>{Cr()},isSendingToPlanner:Nt,disabledReason:Gr??Wr}:void 0;(0,p.useEffect)(()=>{if(Pi!==`opencode`){It(``),Rt(``),Bt(!1);return}let t=ige({projectId:e,tool:Pi}),n=t?.model??``;It(n),Rt(n?t?.variant??``:``),Bt(!!n)},[e,Pi]),(0,p.useEffect)(()=>{ji||(Wt.current=null,Gt.current=null,qt.current=!1,Jt.current=!1,Qe(!1),et(!1),Qn())},[ji,Qn]),(0,p.useEffect)(()=>()=>{Qn()},[Qn]);let Ri=(0,X.jsx)(vv,{content:q5(`artifactPanel.open`),disabled:!Mi,side:`left`,children:(0,X.jsx)(`div`,{ref:Ht,className:Z(Mi?`group flex shrink-0 touch-none select-none items-center justify-center border-l border-border/70 bg-background/90 text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground xl:w-7 xl:cursor-col-resize`:`group hidden w-5 shrink-0 cursor-col-resize touch-none select-none items-center justify-center border-l border-border/70 bg-background/80 transition-colors xl:flex`,Y&&!Mi&&`bg-background`),role:Mi?`button`:`separator`,tabIndex:Mi?0:void 0,"aria-label":q5(Mi?`artifactPanel.open`:`artifactPanel.resize`),"aria-valuemin":Mi?void 0:t7,"aria-valuemax":Mi?void 0:Vt.current?Math.round(Vt.current.clientWidth*n7):800,"aria-valuenow":Mi?void 0:Xe,onClick:Mi?()=>{if(Jt.current){Jt.current=!1;return}Je(!0)}:void 0,onPointerDown:rr,onPointerMove:ir,onPointerUp:ar,onPointerCancel:or,onLostPointerCapture:sr,children:Mi?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`hidden h-full w-full items-center justify-center xl:flex`,children:(0,X.jsxs)(`span`,{className:`relative flex h-full w-full items-center justify-center`,children:[(0,X.jsx)(`span`,{className:`absolute top-1/2 left-1/2 flex -translate-x-1/2 -translate-y-[2.65rem] items-center justify-center text-sky-400/80 transition-colors group-hover:text-sky-300`,children:(0,X.jsx)(G5,{className:`h-3 w-3 shrink-0`})}),(0,X.jsx)(`span`,{className:`absolute top-1/2 left-1/2 h-14 w-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-muted-foreground/70 transition-colors group-hover:bg-sky-300/90`})]})}),(0,X.jsxs)(`span`,{className:`flex items-center gap-2 text-xs font-medium xl:hidden`,children:[(0,X.jsx)(G5,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{children:q5(`artifactPanel.title`)})]})]}):(0,X.jsx)(`div`,{className:Z(`h-14 w-1.5 rounded-full transition-colors`,Y?`bg-sky-300/90`:`bg-muted-foreground/70 group-hover:bg-sky-300/90`)})})}),zi=F&&br?(0,X.jsx)(kY,{providers:yr,onImported:_r,inputId:`spec-draft-external-import`,className:`max-w-md`,showImportSpinner:!0,showImportErrorToast:!1}):null,Bi=j?j.mode===`grill`:pt,Vi=ri;hn.current=Vi,gn.current=ai;let Hi=(0,X.jsx)(N5,{on:Bi,disabled:ht||Jr||_e||ye||ai||Kr,tooltipContent:q5(`grill.toggleTooltip`),ariaLabelOn:q5(`grill.toggleAriaLabelOn`),ariaLabelOff:q5(`grill.toggleAriaLabelOff`),onToggle:e=>{Er(e)}}),Ui=tge(Sn),Wi=(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[Ui?(0,X.jsxs)(`div`,{className:`rounded-md border border-sky-500/30 bg-sky-500/10 px-3 py-2 text-sm text-sky-950 dark:text-sky-100`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:q5(`importNotice.title`)}),(0,X.jsx)(`div`,{children:Ui})]}):null,(0,X.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[Hi,zi,Ti,F&&t&&(0,X.jsx)(Zy,{activeProject:t,branchState:n,bundles:r,branchSuggestions:i,isBundleLoading:a,isLoading:o,presentation:`composer`,closeAfterSelection:!0,triggerAriaLabel:qb.t(`common:projectTargetSelector.newSpecAriaLabel`),onOpenChange:s,onSelectBundle:c,onSelectRepoRoot:l})]})]}),Gi=Oi,Ki=(0,p.useCallback)(t=>{j?gr(o7({projectId:e,sessionId:j.id})):U(null),fr(yn,t)},[j,e,yn,fr,gr]),qi=(0,X.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:(0,X.jsx)(Ohe,{projectId:e,specSessionId:F?null:k,messages:zr,internalLog:Vr?.agent_log??null,currentThinkingMessageId:Vr?.agent_message_id??null,previousThinkingLog:Vr?.previous_agent_log??null,previousThinkingMessageId:Vr?.previous_agent_message_id??null,pendingAgentTitle:Zr,streamingResponse:qr,isRunning:Xr,isLoading:!F&&he,canShowComposer:$r,isExternallyResizing:Y,layoutKey:j?.id??`spec-draft`,scrollLayoutKey:ji?Ni?`artifact-visible`:`artifact-hidden`:`artifact-disabled`,header:(0,X.jsx)(G8,{title:di,tool:F?null:j?.tool??null,modelLabel:pi,interrupted:mi,interruptedLabel:q5(`sidebar.interrupted`),usage:{totalTokens:j?.usage_snapshot_total_tokens??null,contextWindow:j?.usage_snapshot_context_window??null,cost:j?.usage_snapshot_cost??null,tool:ui,model:fi,availableModels:En},metadataExtra:j?.external_source?(0,X.jsx)(IF,{externalSource:j.external_source}):null,actions:j&&e?(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[ei&&(0,X.jsx)(Q,{type:`button`,size:`xs`,variant:`outline`,className:`gap-2`,onClick:()=>St(!0),children:yt?q5(`composer.loadingMemory`):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{children:q5(`composer.memorySuggestions`)}),(0,X.jsx)(Ew,{children:_t.length})]})}),(0,X.jsx)(V4,{projectId:e,scope:{type:`spec`,id:j.id},size:`xs`,onNavigateToLifecycleSource:b})]}):null,warnings:Ur&&Wr?(0,X.jsx)(`div`,{className:`w-fit max-w-md rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-50`,children:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{children:Wr}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`secondary`,disabled:st===j?.id,onClick:()=>{j&&Kn(j)},children:st===j?.id?q5(`targets.switchingBack`):q5(`targets.switchBack`)}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`ghost`,onClick:Vn,children:q5(`composer.startNewSession`)})]})]})}):Hr&&Gr?(0,X.jsx)(`div`,{className:`w-fit max-w-md rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-50`,children:Gr}):null}),composerControls:Wi,composerInlineControls:Gi,composerTheme:`default`,composerFocusNonce:Fe,pendingAgentRevealKey:Xr&&Le?.parentId===k?Le?.turnKey??null:null,pendingAgentRevealDelayMs:Xr&&Le?.parentId===k?400:0,liveResponseTiming:Le,followUpPrompt:xn,draftAttachments:wn,followUpPlaceholder:hi,emptyStateText:null,isSendingFollowUp:ye||_e,isComposerSubmitDisabled:Vi||ai||Kr,isUploadingAttachments:Tn,canAttachImages:ti,followUpDisabledReason:Gr??Wr??(Vr?.agent_status===`running`?q5(`composer.waitTurn`):Tn?q5(`composer.waitUpload`):Vi?q5(`composer.waitGrill`):ai?qb.t(`common:questionSet.waitForResolution`):void 0),renderMessageBody:ci,onFollowUpPromptChange:Ki,onFollowUpKeyDown:Fr,onFollowUpPaste:Ir,onUploadAttachments:e=>{kr(e)},onRemoveAttachment:e=>{jr(e)},onFollowUpSubmit:()=>{Dr()}})}),Ji=!Br&&pe&&!de?(0,X.jsx)(j8,{title:q5(`composer.noSessionSelectedTitle`),description:q5(`composer.noSessionSelectedDescription`),startNewSessionLabel:q5(`composer.startNewSession`),onStartNewSession:Vn,canStartNewSession:!!e&&!_e&&!ye}):Br&&!F&&!he&&!j?(0,X.jsx)(k8,{label:q5(`composer.loadingSession`)}):!pe||de?(0,X.jsx)(A8,{label:q5(`sidebar.loadingSessions`)}):qi,Yi=xt&&e&&t?.memory_enabled?(0,X.jsx)(tC,{onClose:()=>St(!1),overlayClassName:`bg-background/75 p-4`,panelClassName:`w-full max-w-3xl`,renderContent:({closeButton:t})=>(0,X.jsxs)(iC,{size:`sm`,className:`max-h-[calc(100vh-2rem)] w-full gap-0 overflow-hidden border-border/80 bg-card/95 shadow-2xl`,children:[(0,X.jsxs)(aC,{className:`border-b border-border/80 pb-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(oC,{children:q5(`composer.memorySuggestionsTitle`)}),(0,X.jsx)(sC,{children:q5(`composer.memorySuggestionsDescription`)})]}),(0,X.jsx)(cC,{children:t})]}),(0,X.jsx)(lC,{className:`min-h-0 flex-1 overflow-y-auto pt-4`,children:(0,X.jsx)(K8,{projectId:e,suggestions:_t,emptyState:q5(`composer.memorySuggestionsEmpty`),onSuggestionsChanged:Ln})})]}),closeButtonLabel:q5(`composer.closeMemorySuggestions`)}):null,Xi=Ai.length>0?(0,X.jsx)(O8,{count:Ai.length,title:ki,isDeleting:Te.size>0,onConfirm:()=>{lr()},onCancel:()=>{Te.size>0||we([])},labels:vi}):null,Zi=dt===null?null:(0,X.jsx)(nC,{title:q5(`actions.exportConflictTitle`),description:q5(`actions.exportConflictDescription`,{path:dt.path}),confirmLabel:q5(`actions.exportConflictConfirm`),cancelLabel:q5(`actions.exportConflictCancel`),confirmVariant:`destructive`,onConfirm:()=>{ft(null),Zn({projectId:dt.projectId,sessionId:dt.sessionId,snapshotId:dt.snapshotId,overwrite:!0})},onCancel:()=>{ft(null)}});return(0,X.jsxs)(`div`,{"data-testid":`spec-view-shell`,className:`relative flex min-h-0 flex-1 overflow-hidden border-t border-border/70`,children:[(0,X.jsx)(M8,{sessions:D,sessionGroups:Nr,activeSessionId:k,isDraftOpen:F,isLoadingSessions:de,isOpen:Ne,onToggleOpen:()=>{Pe(t=>{let n=!t;return Zhe({projectId:e,isOpen:n}),n})},testId:`spec-sessions-sidebar`,railTestId:`spec-sessions-rail`,onDraftOpen:Vn,isCreatingSession:_e||!e,isSendingPrompt:ye,newSessionShortcutHint:Un,newSessionTooltip:Wn,isSelectionMode:De,selectedSessionIds:ke,selectedSessionCount:ke.size,hasDeletableSessions:gi,deletingSessionIds:Te,onEnterSelectionMode:()=>{Oe(!0),Ae(new Set)},onExitSelectionMode:()=>{Oe(!1),Ae(new Set)},onToggleSessionSelection:e=>{Ae(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},onSetSessionSelection:Mr,onConfirmDeleteSelectedSessions:()=>{we(Array.from(ke))},selectionPresets:Pr,onSessionSelect:e=>{Gn(e)},onConfirmDeleteSession:e=>{we([e])},getSessionId:e=>e.id,getSessionTitle:e=>e.title,getDeleteDisabledReason:bi,getActivityState:yi,getRowAriaLabel:Si,renderRowContent:wi,labels:_i}),(0,X.jsxs)(`div`,{"data-testid":`spec-artifact-split-pane`,ref:Vt,className:`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden xl:flex-row`,children:[(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:Ji}),ji?(0,X.jsxs)(X.Fragment,{children:[Ri,Ni?(0,X.jsx)(Uhe,{snapshot:Be,isLoading:We,desktopWidth:Xe,onClose:cr,ref:Ut,actions:Be?{onCreateTickets:Yn,onImplementInChat:()=>{Xn()},onExport:()=>{Zn()},isCreatingTickets:tt,isImplementingInChat:rt,isExporting:at,hasExistingTicketsFromSnapshot:lt,unavailableReason:Gr,implementInChatUnavailableReason:Be.bundle_groups.length>1?q5(`actions.implementInChatMultiBundleUnavailable`):null}:void 0,review:Li}):null]}):null]}),Yi,Xi,Zi]})},x7=()=>({hasRunning:!1,hasFinishedUnseen:!1,hasErrorUnseen:!1}),S7=()=>({board:x7(),chat:x7(),spec:x7(),memory:x7()}),C7=(e,t)=>{let n=e[t];return!n.hasFinishedUnseen&&!n.hasErrorUnseen?e:{...e,[t]:{...n,hasFinishedUnseen:!1,hasErrorUnseen:!1}}},lge=e=>({hasRunning:e.board.hasRunning||e.chat.hasRunning||e.spec.hasRunning,hasFinishedUnseen:e.board.hasFinishedUnseen||e.chat.hasFinishedUnseen||e.spec.hasFinishedUnseen,hasErrorUnseen:e.board.hasErrorUnseen||e.chat.hasErrorUnseen||e.spec.hasErrorUnseen}),w7=e=>e.hasErrorUnseen?`error`:e.hasRunning?`running`:e.hasFinishedUnseen?`finished`:null,uge=(e,t)=>t?null:w7(e),T7=320,dge=.7,fge=28,pge=6,mge=(e,t)=>{let n=Math.max(T7,Math.round(t*dge));return Math.max(T7,Math.min(n,Math.round(e)))},hge=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);if(n===-1)return[...e,t];let r=e.slice();return r[n]=t,r},gge=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);if(n===-1)return[...e,t];let r=e.slice();return r[n]=t,r},_ge=(e,t)=>{if(t.type===`reset`)return S7();if(t.type===`mark-workspace-visible`)return C7(e,t.workspace);let n=e[t.workspace],r={...n,hasRunning:t.activity.hasRunning,hasFinishedUnseen:t.visibleWorkspace===t.workspace?!1:n.hasFinishedUnseen||t.activity.didFinish,hasErrorUnseen:t.visibleWorkspace===t.workspace?!1:n.hasErrorUnseen||t.activity.didError};return n.hasRunning===r.hasRunning&&n.hasFinishedUnseen===r.hasFinishedUnseen&&n.hasErrorUnseen===r.hasErrorUnseen?e:{...e,[t.workspace]:r}},vge=({activeProjectId:e,onActivity:t})=>{let{tickets:n}=o3(),r=(0,p.useRef)(new Map);return(0,p.useEffect)(()=>{r.current=new Map},[e]),(0,p.useEffect)(()=>{let e=r.current,i=new Map,a=!1,o=!1;for(let t of n){let n=e.get(t.id)??null,r=t.agent_status??null,s=S8(t);!s&&n===`running`&&r===`done`&&(a=!0),n===`running`&&r===`error`&&(o=!0),i.set(t.id,s?n:r)}r.current=i,t({hasRunning:n.some(e=>e.agent_status===`running`||Tme(e)),didFinish:a,didError:o})},[t,n]),null},yge=({activeProjectId:e})=>{let{t}=q(`common`,{keyPrefix:`approvalRequest.notification`}),n=uq(),{setPendingApprovalRequests:r}=o3();return(0,p.useEffect)(()=>{if(!e){r([]);return}let i=new AbortController,a=0,o=async(n,r)=>{if(n.status!==`pending`||i.signal.aborted||r!==void 0&&r!==a)return;let o=(await bN(e,n.id,i.signal)).approval_request;o.status!==`pending`||i.signal.aborted||r!==void 0&&r!==a||await i3({title:t(`title`),body:t(o.action_kind===`git_push`?`forcePush`:`productionCheck`),key:Cde(o),destination:r3(o)})},s=()=>{let t=++a;(async()=>{let t=[],n;do{let r=await yN(e,{statuses:[`pending`],limit:200,cursor:n,signal:i.signal});t.push(...r.approval_requests),n=r.next_cursor??void 0}while(n);return t})().then(e=>{if(!(i.signal.aborted||t!==a))return r(e),Promise.allSettled(e.map(e=>o(e,t)))}).catch(e=>{Ye(e)})},c=t=>{if(!t||typeof t!=`object`)return;let n=t;n.project_id!==e||typeof n.id!=`string`||s()};return s(),n.on(`approval-request:created`,c),n.on(`approval-request:updated`,s),n.on(`connect`,s),()=>{i.abort(),n.off(`approval-request:created`,c),n.off(`approval-request:updated`,s),n.off(`connect`,s)}},[e,r,n,t]),null},bge=({activeProjectId:e,onActivity:t})=>{let n=uq(),[r,i]=(0,p.useState)([]),a=(0,p.useRef)(new Map);return(0,p.useEffect)(()=>{if(!e)return;let t=new AbortController;return(async()=>{try{let n=await uN(e,t.signal);if(t.signal.aborted)return;i(n)}catch(e){Ye(e)}})(),()=>{t.abort()}},[e,n]),(0,p.useEffect)(()=>{if(!e)return;let t=new AbortController,n=hx(()=>{document.visibilityState===`visible`&&uN(e,t.signal).then(e=>{t.signal.aborted||i(e)}).catch(e=>{Ye(e)})});return()=>{t.abort(),n()}},[e,n]),(0,p.useEffect)(()=>{if(!e)return;let t=t=>{!t||t.project_id!==e||i(e=>hge(e,t))},r=t=>{!t||t.project_id!==e||i(e=>e.filter(e=>e.id!==t.id))};return n.on(`chat-session:created`,t),n.on(`chat-session:updated`,t),n.on(`chat-session:deleted`,r),()=>{n.off(`chat-session:created`,t),n.off(`chat-session:updated`,t),n.off(`chat-session:deleted`,r)}},[e,n]),(0,p.useEffect)(()=>{let n=a.current,i=new Map,o=[],s=!1;for(let e of r){let t=n.get(e.id)??null,r=e.agent_status??null;t===`running`&&r===`done`&&o.push(e),t===`running`&&r===`error`&&(s=!0),i.set(e.id,r)}a.current=i;for(let e of o)if(e.title){let t=xde({projectId:e.project_id,chatSessionId:e.id,agentMessageId:e.agent_message_id});t&&i3({title:`Chat response ready`,body:e.title,key:t,destination:{kind:`chat-session`,projectId:e.project_id,chatSessionId:e.id}})}o.length>0&&e&&i6(e),t({hasRunning:r.some(e=>e.agent_status===`running`),didFinish:o.length>0,didError:s})},[e,t,r]),null},xge=({activeProjectId:e,onActivity:t})=>{let n=uq(),[r,i]=(0,p.useState)([]),a=(0,p.useRef)(new Map);return(0,p.useEffect)(()=>{if(!e)return;let t=new AbortController;return(async()=>{try{let n=await pN(e,t.signal);if(t.signal.aborted)return;i(n)}catch(e){Ye(e)}})(),()=>{t.abort()}},[e,n]),(0,p.useEffect)(()=>{if(!e)return;let t=new AbortController,n=hx(()=>{document.visibilityState===`visible`&&pN(e,t.signal).then(e=>{t.signal.aborted||i(e)}).catch(e=>{Ye(e)})});return()=>{t.abort(),n()}},[e,n]),(0,p.useEffect)(()=>{if(!e)return;let t=t=>{!t||t.project_id!==e||i(e=>gge(e,t))},r=t=>{!t||t.project_id!==e||i(e=>e.filter(e=>e.id!==t.id))};return n.on(`spec-session:created`,t),n.on(`spec-session:updated`,t),n.on(`spec-session:deleted`,r),()=>{n.off(`spec-session:created`,t),n.off(`spec-session:updated`,t),n.off(`spec-session:deleted`,r)}},[e,n]),(0,p.useEffect)(()=>{let e=a.current,n=new Map,i=[],o=!1;for(let t of r){let r=e.get(t.id)??null,a=t.agent_status??null;r===`running`&&a===`done`&&i.push(t),r===`running`&&a===`error`&&(o=!0),n.set(t.id,a)}a.current=n;for(let e of i)if(e.title){let t=Sde({projectId:e.project_id,specSessionId:e.id,agentMessageId:e.agent_message_id,latestSnapshotId:e.latest_snapshot_id});t&&i3({title:`Spec response ready`,body:e.title,key:t,destination:{kind:`spec-session`,projectId:e.project_id,specSessionId:e.id}})}t({hasRunning:r.some(e=>e.agent_status===`running`),didFinish:i.length>0,didError:o})},[e,t,r]),null},Sge=({activeProjectId:e,activeProject:t=null,activeProjectBranchState:n=null,targetBundles:r=[],targetBranchSuggestions:i={current_branch:null,default_branch:null,previous_branch:null},isTargetBundleLoading:a=!1,isTargetSelectorLoading:o=!1,onTargetSelectorOpenChange:s,onSelectBundleTarget:c,onSelectRepoRootTarget:l,activeRun:u,activeTool:d,onRestoreSessionTarget:f,onChatReviewCapabilityChange:m,routedInspectionReviewCapability:h,onPreviewReviewCapabilityChange:g,previewDisplayMode:_=`hidden`,previewPane:v=null,previewPaneWidth:y=480,isPreviewButtonDisabled:b=!1,previewButtonTitle:x,visibleWorkspace:S,onProjectUsageChange:C,onBundlesChange:w,onBundlesLoadingChange:T,onBoardLoadedProjectIdChange:E,onPreviewToggle:D,onPreviewPaneWidthChange:O,onRunStopped:k,onRunStatusChange:A,onWorkspaceActivityChange:j,onWorkspaceActivityEvent:M,pendingWorkspaceNavigation:N=null,onPendingWorkspaceNavigationConsumed:P,routedTicketId:F=null,routedModalStack:I=[],onRoutedTicketOpen:L,onRoutedTicketClose:R,onRoutedTicketUnavailable:z,routedBundleId:ee=null,routedChatSessionId:B,routedSpecSessionId:V,routedSpecSnapshotId:H,routedInspection:U=null,onRoutedBundleOpen:W,onRoutedBundleClose:te,onRoutedInspectionOpen:ne,onRoutedInspectionModeChange:re,onRoutedInspectionClose:ie,onChatSessionNavigation:ae,onSpecSessionNavigation:G,onRoutedEntityUnavailable:oe,onSpecImplementationChatReady:se,onViewSourceSpec:ce,onNavigateToLifecycleSource:le,onViewMemorySource:ue,onStartChatFromBundle:de,onOpenProjectExecutionSettings:fe,refreshKey:pe=0,boardFilterState:me,onBoardFilterStateChange:he})=>{let ge=(0,p.useRef)(null),_e=(0,p.useRef)(null),ve=(0,p.useRef)(null),ye=(0,p.useRef)(null),be=(0,p.useRef)(!1),xe=(0,p.useRef)(!1),Se=(0,p.useRef)(0),Ce=(0,p.useRef)(y),we=(0,p.useRef)(y),Te=S===`board`||S===`chat`,Ee=v!==null,[De,Oe]=(0,p.useState)(!1),[ke,Ae]=(0,p.useState)(!1),[je,Me]=(0,p.useState)(y),[Ne,Pe]=(0,p.useReducer)(_ge,void 0,S7),Fe=Te&&Ee&&_===`expanded`,Ie=Te&&Ee&&_===`inline`,Le=Te&&Ee&&_===`hidden`&&!ke,K=(Ie||ke)&&!Fe,Re=Fe||K,ze=Te&&Ee&&!Fe,Be=De?je:y,Ve=S!==`chat`||!K,He=e=>{let t=ve.current,n=ye.current,r=be.current;if(t!==null){if(ve.current=null,ye.current=null,be.current=!1,Oe(!1),Ae(!1),e!==null&&_e.current?.hasPointerCapture(e)&&_e.current.releasePointerCapture(e),n===`collapsed`){if(!r)return;O?.(we.current),D?.();return}O?.(we.current)}},q=e=>{if(!ge.current)return;let t=ge.current.getBoundingClientRect().width,n=mge(e,t);we.current=n,Me(n)},Ue=e=>{O&&(Le&&b||(e.preventDefault(),ve.current=e.pointerId,ye.current=Le?`collapsed`:`inline`,be.current=!1,xe.current=!1,Se.current=e.clientX,Ce.current=Le?0:we.current,Oe(!Le),e.currentTarget.setPointerCapture(e.pointerId)))},We=e=>{if(ve.current!==e.pointerId)return;let t=e.clientX-Se.current,n=Ce.current-t;if(ye.current===`collapsed`){if(!be.current&&n<pge)return;be.current||(be.current=!0,xe.current=!0,Ae(!0),Oe(!0))}q(n)},Ge=e=>{if(ve.current===e.pointerId){if(ye.current===`inline`||be.current){let t=e.clientX-Se.current;q(Ce.current-t)}He(e.pointerId)}},Ke=e=>{ve.current===e.pointerId&&He(e.pointerId)},J=(0,p.useCallback)((e,t)=>{M?.(e,t),Pe({type:`update-workspace`,workspace:e,activity:t,visibleWorkspace:S})},[M,S]);(0,p.useEffect)(()=>{Pe({type:`reset`})},[e]),(0,p.useEffect)(()=>{S!==`memory`&&Pe({type:`mark-workspace-visible`,workspace:S})},[S]),(0,p.useEffect)(()=>{j?.(Ne)},[j,Ne]),(0,p.useEffect)(()=>{De||(we.current=y),!Ee&&(ve.current=null,ye.current=null,be.current=!1,xe.current=!1,we.current=y)},[Ee,De,y]);let qe=()=>{if(xe.current){xe.current=!1;return}b||D?.()},Je=e=>{e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),qe())},Ye=(r=!1)=>(0,X.jsx)(jme,{activeProjectId:e,activeProject:t,activeProjectBranchState:n,activeRun:u,activeTool:d,inspectionOnly:r,onPreviewReviewCapabilityChange:r?void 0:g,onRunStopped:k,onRunStatusChange:A,onViewSourceSpec:ce,onNavigateToLifecycleSource:le,onStartChatFromBundle:de,onOpenProjectExecutionSettings:fe,refreshKey:pe,boardFilterState:me,onBoardFilterStateChange:he,onInitialTicketNavigationUnavailable:z,routedTicketId:F,routedModalStack:I,onTicketOpen:L,onTicketClose:R,routedBundleId:ee,routedInspection:U,routedInspectionReviewCapability:r&&S===`chat`?h:void 0,onBundleOpen:W,onBundleClose:te,onInspectionOpen:ne,onInspectionModeChange:re,onInspectionClose:ie,onInspectionUnavailable:oe,initialImportedDraft:N?.workspace===`board`&&`issueDraft`in N?N.draft:null,onInitialImportedDraftConsumed:P});return(0,X.jsx)(Ame,{activeProjectId:e,refreshKey:pe,onLoadedProjectIdChange:E,onProjectUsageChange:C,onBundlesChange:w,onBundlesLoadingChange:T,children:(0,X.jsxs)(`div`,{ref:ge,className:`flex min-h-0 flex-1 flex-col`,children:[(0,X.jsx)(vge,{activeProjectId:e,onActivity:e=>{J(`board`,e)}}),(0,X.jsx)(yge,{activeProjectId:e}),(0,X.jsx)(bge,{activeProjectId:e,onActivity:e=>{J(`chat`,e)}}),(0,X.jsx)(xge,{activeProjectId:e,onActivity:e=>{J(`spec`,e)}}),S===`spec`?(0,X.jsx)(`div`,{id:`project-workspace-panel-spec`,role:`tabpanel`,"aria-labelledby":`project-workspace-tab-spec`,className:`flex min-h-0 flex-1 flex-col`,children:(0,X.jsx)(cge,{activeProjectId:e,activeProject:t,activeProjectBranchState:n,targetBundles:r,targetBranchSuggestions:i,isTargetBundleLoading:a,isTargetSelectorLoading:o,onTargetSelectorOpenChange:s,onSelectBundleTarget:c,onSelectRepoRootTarget:l,onRestoreSessionTarget:f,activeTool:d,routedSpecSessionId:V,routedSpecSnapshotId:H,initialIssueDraft:N?.workspace===`spec`&&`issueDraft`in N?N.draft:null,onRoutedSpecNavigationUnavailable:oe,onSessionNavigation:G,onInitialIssueDraftConsumed:P,onImplementInChat:se,onNavigateToLifecycleSource:le})}):S===`memory`?(0,X.jsx)(`div`,{id:`project-workspace-panel-memory`,role:`tabpanel`,"aria-labelledby":`project-workspace-tab-memory`,className:`flex min-h-0 flex-1 flex-col`,children:(0,X.jsx)(vhe,{activeProject:t,onNavigateToSource:ue})}):(0,X.jsxs)(`div`,{id:S===`chat`?`project-workspace-panel-chat`:`project-workspace-panel-board`,role:`tabpanel`,"aria-labelledby":S===`chat`?`project-workspace-tab-chat`:`project-workspace-tab-board`,className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,X.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:S===`chat`?(0,X.jsx)(ghe,{activeProjectId:e,activeProject:t,activeProjectBranchState:n,targetBundles:r,targetBranchSuggestions:i,isTargetBundleLoading:a,isTargetSelectorLoading:o,onTargetSelectorOpenChange:s,onSelectBundleTarget:c,onSelectRepoRootTarget:l,activeTool:d,routedChatSessionId:B,initialDraftOpen:N?.workspace===`chat`&&`startNewDraft`in N,onInitialDraftOpenConsumed:P,initialSpecDraft:N?.workspace===`chat`&&`draft`in N?{text:N.draftText,specSessionId:N.specSessionId,specSnapshotId:N.specSnapshotId}:null,onInitialSpecDraftConsumed:P,onRoutedChatNavigationUnavailable:oe,onSessionNavigation:ae,onViewSourceSpec:ce,onNavigateToLifecycleSource:le,isExternallyResizing:De,onRestoreSessionTarget:f,onReviewCapabilityChange:m,showChangesPanel:Ve}):Ye()}),[ze?(0,X.jsx)(vv,{content:b?x??`Preview unavailable`:`Open preview`,disabled:!Le,side:`left`,children:(0,X.jsx)(`div`,{"aria-label":Le?x??`Show preview`:`Resize preview pane`,"aria-orientation":Le?void 0:`vertical`,className:Le?`group flex shrink-0 touch-none select-none items-center justify-center border-l border-border/70 bg-background/90 transition-colors ${b?`cursor-not-allowed text-muted-foreground/60`:`cursor-col-resize text-muted-foreground hover:bg-muted/50 hover:text-foreground`}`:`group flex w-5 shrink-0 cursor-col-resize touch-none select-none items-center justify-center border-l border-border/70 bg-background/80 ${De?`bg-background`:``}`,"data-preview-divider":`true`,"data-testid":Le?`collapsed-preview-rail`:void 0,onLostPointerCapture:Ke,onPointerCancel:Ge,onPointerDown:Ue,onPointerMove:We,onPointerUp:Ge,onClick:Le?qe:void 0,onKeyDown:Le?Je:void 0,ref:_e,role:Le?`button`:`separator`,style:Le?{width:`${fge}px`}:void 0,tabIndex:Le?b?-1:0:void 0,children:Le?(0,X.jsxs)(`span`,{className:`relative flex h-full w-full items-center justify-center`,children:[(0,X.jsx)(`span`,{className:`absolute top-1/2 left-1/2 flex -translate-x-1/2 -translate-y-[2.65rem] items-center justify-center text-sky-400/80 transition-colors group-hover:text-sky-300`,children:(0,X.jsx)(_he,{className:`h-3 w-3 shrink-0`})}),(0,X.jsx)(`span`,{className:`absolute top-1/2 left-1/2 h-14 w-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-muted-foreground/70 transition-colors group-hover:bg-sky-300/90`})]}):(0,X.jsx)(`div`,{className:`h-14 w-1.5 rounded-full transition-colors ${De?`bg-sky-300/90`:`bg-muted-foreground/70 group-hover:bg-sky-300/90`}`})})},`preview-divider`):null,Re?(0,X.jsx)(`div`,{className:Fe?`fixed inset-0 z-50 bg-black/70 p-4 sm:p-6`:`min-h-0 shrink-0 border-l border-border/70 bg-[#11131a]`,style:Fe?void 0:{width:`${Be}px`},children:(0,X.jsx)(`div`,{className:`h-full w-full`,children:v})},`preview-container`):null]]}),S!==`board`&&U&&Ye(!0)]})})},Cge=({isExpanded:e,isVisible:t,project:n,onClose:r,onToggleExpanded:i})=>(0,X.jsx)(`div`,{className:[`fixed inset-x-4 bottom-24 z-40`,e?`top-20`:`h-[min(28rem,calc(100vh-8rem))]`,t?`block`:`hidden`].join(` `),children:(0,X.jsx)(r4,{createSession:()=>Bse(n.id),isExpanded:e,isVisible:t,ariaLabel:`Project terminal for ${n.name}`,title:n.name,closeLabel:`Close terminal`,className:e?`h-full w-full rounded-2xl shadow-2xl`:`mx-auto h-full max-w-6xl shadow-2xl`,onClose:r,onToggleExpanded:i})}),wge=({activeWorkspace:e,activityByWorkspace:t,className:n,memoryEnabled:r=!1,onWorkspaceChange:i})=>{let{t:a}=q(`common`,{keyPrefix:`workspaceTabs`}),o=r?[`board`,`chat`,`spec`,`memory`]:[`board`,`chat`,`spec`],s={board:a(`board`),chat:a(`chat`),spec:a(`spec`),memory:a(`memory`)};return(0,X.jsx)(`div`,{className:Z(`min-w-0 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,n),children:(0,X.jsx)(`div`,{role:`tablist`,"aria-label":a(`ariaLabel`),className:`inline-flex min-w-max items-end gap-1 border-b border-border/70`,children:o.map(n=>{let r=e===n,a=uge(t[n],r),o=n===`board`?`border-sky-300/70 bg-sky-500/8 text-sky-200`:n===`spec`?`border-violet-300/70 bg-violet-500/8 text-violet-200`:n===`memory`?`border-amber-300/70 bg-amber-500/8 text-amber-200`:`border-emerald-300/70 bg-emerald-500/8 text-emerald-200`;return(0,X.jsx)(`button`,{id:`project-workspace-tab-${n}`,type:`button`,role:`tab`,"aria-selected":r,"aria-controls":`project-workspace-panel-${n}`,tabIndex:r?0:-1,className:Z(`cursor-pointer rounded-t-lg border-b-2 px-3 py-2 text-sm font-medium transition-colors duration-150 ease-out focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 sm:px-4 sm:py-2.5 sm:text-[15px]`,r?o:`border-transparent text-muted-foreground hover:border-border hover:bg-background/35 hover:text-foreground`),onClick:()=>i(n),children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[(0,X.jsx)(`span`,{children:s[n]}),(0,X.jsx)(ib,{state:a,className:`mt-0`})]})},n)})})})},E7=32,Tge=5.5,Ege=2,Dge=24,Oge=8,D7=new Map,kge={running:{fill:`#fcd34d`,stroke:`#f59e0b`},finished:{fill:`#34d399`,stroke:`#059669`},error:{fill:`#fb7185`,stroke:`#e11d48`}},O7=e=>e.replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`),k7=e=>{if(!e)return null;let t=e.trim().match(/^([0-9]+(?:\.[0-9]+)?)/);return t?Number(t[1]):null},A7=e=>{let t=new DOMParser().parseFromString(e,`image/svg+xml`);if(t.querySelector(`parsererror`))return null;let n=t.documentElement;if(n.nodeName.toLowerCase()!==`svg`)return null;let r=n.getAttribute(`viewBox`)?.trim(),i=k7(n.getAttribute(`width`)),a=k7(n.getAttribute(`height`)),o=r??(i&&a?`0 0 ${i} ${a}`:`0 0 ${E7} ${E7}`);return`<svg ${[Array.from(n.attributes).filter(e=>![`width`,`height`,`viewBox`,`x`,`y`,`preserveAspectRatio`].includes(e.name)).map(e=>`${e.name}="${O7(e.value)}"`).join(` `),`x="0"`,`y="0"`,`width="${E7}"`,`height="${E7}"`,`viewBox="${O7(o)}"`,`preserveAspectRatio="xMidYMid meet"`].filter(e=>e.length>0).join(` `)}>${n.innerHTML}</svg>`},Age=async e=>{if(!e)return null;let t=D7.get(e);if(t)return t;let n=(async()=>{try{if(e.startsWith(`data:image/svg+xml,`))return A7(decodeURIComponent(e.slice(19)));if(e.startsWith(`data:image/svg+xml;base64,`))return A7(atob(e.slice(26)));let t=await fetch(e);return t.ok?A7(await t.text()):null}catch{return null}})();return D7.set(e,n),n},jge=async(e,t)=>{let{fill:n,stroke:r}=kge[e],i=await Age(t);return i?[`<svg xmlns="http://www.w3.org/2000/svg" width="${E7}" height="${E7}" viewBox="0 0 ${E7} ${E7}">`,i,`<circle cx="${Dge}" cy="${Oge}" r="${Tge}" fill="${n}" stroke="${r}" stroke-width="${Ege}"/>`,`</svg>`].join(``):null},Mge=async(e,t)=>{if(!e)return t;let n=await jge(e,t);return n?`data:image/svg+xml,${encodeURIComponent(n)}`:t},Nge=()=>{let e=document.querySelector(`link[rel="icon"]`);if(e)return e;let t=document.createElement(`link`);return t.rel=`icon`,document.head.appendChild(t),t},j7=({defaultHref:e,state:t})=>{let n=Nge(),r=Number(n.dataset.browserTabActivityRequestId??`0`)+1;if(n.dataset.browserTabActivityState=t??`default`,n.dataset.browserTabActivityRequestId=String(r),!t){if(e){n.href=e;return}n.removeAttribute(`href`);return}Mge(t,e).then(e=>{if(n.dataset.browserTabActivityRequestId===String(r)){if(e){n.href=e;return}n.removeAttribute(`href`)}})},M7=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return t.archonDesktop===!0&&typeof t.modalHasParentEntry==`boolean`&&(t.modalParentDepth===void 0||Number.isInteger(t.modalParentDepth)&&t.modalParentDepth>0)&&(t.modalStack===void 0||Array.isArray(t.modalStack)&&t.modalStack.every(e=>!!e&&typeof e==`object`&&typeof e.kind==`string`&&typeof e.projectId==`string`))},N7=e=>!M7(e)||!e.modalHasParentEntry?0:e.modalParentDepth??1,P7=(e,t,n)=>!t||!n.isModal(t)?[]:M7(e)&&e.modalStack&&e.modalStack.length>0?e.modalStack:[t],F7=(e,t,n)=>({archonDesktop:!0,modalHasParentEntry:e,...t>1?{modalParentDepth:t}:{},...n.length>0?{modalStack:n}:{}}),Pge=(e=q4)=>{let[t,n]=(0,p.useState)(()=>e.parse(window.location.pathname)),[r,i]=(0,p.useState)(()=>{let t=e.parse(window.location.pathname);return t&&e.isModal(t)?[t]:[]}),[a,o]=(0,p.useState)(0),s=(0,p.useRef)(!1);(0,p.useEffect)(()=>{s.current||(s.current=!0,t&&e.isModal(t)&&window.history.replaceState(F7(!1,0,[t]),``,e.build(t)))},[e,t]),(0,p.useEffect)(()=>{let t=()=>{let t=e.parse(window.location.pathname);n(t),i(P7(window.history.state,t,e)),o(e=>e+1)};return window.addEventListener(`popstate`,t),()=>window.removeEventListener(`popstate`,t)},[e]);let c=(0,p.useCallback)(r=>{let a=e.isModal(r)?t&&e.isModal(t)?[...P7(window.history.state,t,e).slice(0,-1),r]:[r]:[],s=e.isModal(r)?N7(window.history.state):0,c=F7(s>0,s,a);window.history.replaceState(c,``,e.build(r)),n(r),i(a),o(e=>e+1)},[e,t]),l=(0,p.useCallback)(r=>{let a=e.isModal(r),s=a?t&&e.isModal(t)?[...P7(window.history.state,t,e),r]:[r]:[];window.history.pushState(F7(a,0,s),``,e.build(r)),n(r),i(s),o(e=>e+1)},[e,t]),u=(0,p.useCallback)(r=>{let a=N7(window.history.state);if(a===0){c(r);return}let s=a>0?a+1:0,l=P7(window.history.state,t,e),u=l.length>0?[...l.slice(0,-1),r]:[r],d=F7(s>0,s,u);window.history.pushState(d,``,e.build(r)),n(r),i(u),o(e=>e+1)},[e,c,t]);return{closeModal:(0,p.useCallback)((t,n)=>{let r=e.parse(window.location.pathname);if(!r||e.build(r)!==e.build(t))return;let i=N7(window.history.state);if(i===1){window.history.back();return}if(i>1){window.history.go(-i);return}let a=e.parent(t),o=n??a;o&&c(o)},[e,c]),modalStack:r,navigationVersion:a,push:l,pushModalSibling:u,replace:c,route:t}},I7=(e,t)=>qb.t(`common:projectFooter.${e}`,t),Fge=(e,t)=>{if(e?.kind===`activity-run`)return e;for(let e=t.length-1;e>=0;--e){let n=t[e];if(n.kind===`activity-run`)return n}return null},Ige=1e3,L7=`archon.active-project-id`,R7=`archon.workspace-by-project`,z7=`archon.preview-mode-by-project`,B7=`archon.dismissed-preview-run-context-by-project`,V7=5e3,H7=`archon.preview-pane-width`,U7=`archon.preview-viewport-preset`,W7=`archon.preview-zoom`,Lge=480,Rge=`responsive`,zge=1,G7={hasMounted:!1,isOpen:!1,isExpanded:!1},K7=`hidden`,Bge=(0,p.lazy)(()=>HW(()=>Promise.resolve().then(()=>U6).then(e=>({default:e.WorkspaceReviewModal})),void 0)),Vge=(0,p.lazy)(()=>HW(()=>import(`./VerificationDialog-BfIKtVjt.js`).then(e=>({default:e.VerificationDialog})),__vite__mapDeps([19,3]))),Hge=(0,p.lazy)(()=>HW(()=>import(`./GitHubActionsDialog-NdYtgMhg.js`).then(e=>({default:e.GitHubActionsDialog})),__vite__mapDeps([20,3]))),Uge=(0,p.lazy)(()=>HW(()=>import(`./ActivityView-CdDT5tgr.js`).then(e=>({default:e.ActivityView})),[])),q7=e=>{if(!e)return null;try{return JSON.parse(e)}catch{return null}},Wge=e=>{let t=e.startsWith(`/`)?e.slice(1).split(`/`):[];if(t[0]!==`app`||t[1]!==`projects`||!t[2])return null;try{return decodeURIComponent(t[2])||null}catch{return null}},Gge=e=>e?.kind===`workspace`?e.workspace:e?.kind===`chat-session`?`chat`:e?.kind===`spec-session`||e?.kind===`spec-snapshot`?`spec`:`board`,J7=e=>{let t=q7(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(e=>e.length>0):[]},Y7=e=>{let t=q7(e);return Array.isArray(t)?t.flatMap(e=>{if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e,n=typeof t.name==`string`?t.name:``,r=typeof t.cmd==`string`?t.cmd:``,i=typeof t.cwd==`string`?t.cwd:``;return n.trim()===``&&r.trim()===``&&i.trim()===``?[]:[{name:n,cmd:r,cwd:i}]}):[]},Kge=e=>{let t=q7(e);return Array.isArray(t)?t.flatMap(e=>{if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e,n=typeof t.source==`string`?t.source:``,r=typeof t.target==`string`?t.target:``,i=t.mode===`copy`||t.mode===`symlink`?t.mode:`copy`;return n.trim()===``&&r.trim()===``?[]:[{source:n,target:r,mode:i}]}):[]},qge=(e,t)=>{let n=new Set(qC(e)),r=new Set(JC(e)),i=new Set(Fre(e)),a=new Set(Ire(e));return{name:e.name,repoPath:e.repo_path,buildExecutionProvider:e.build_execution_provider??`host`,linkedProjectIds:e.linked_project_ids,runSetup:J7(e.run_setup),runServices:Y7(e.run_services),checkDefinitions:KC(e).map(e=>({id:e.id,name:e.name,category:e.category,command:e.command,cwd:e.cwd??``,timeoutMs:String(e.timeout_ms),runner:e.category===`test`?e.runner:`auto`,consequence:e.consequence??`ordinary`,required:n.has(e.id),preReview:n.has(e.id)&&r.has(e.id),postBuild:i.has(e.id),autoFix:a.has(e.id)})),runIde:e.run_ide??``,previewServiceName:e.preview_service_name??``,previewPath:e.preview_path??``,previewCapabilityMode:e.preview_capability_mode??`auto`,helperModel:e.helper_models?.[t]?.model??(t===`opencode`?e.helper_model:null)??``,helperVariant:e.helper_models?.[t]?.variant??(t===`opencode`?e.helper_variant:null)??``,helperModels:e.helper_models??{},reviewerModel:e.reviewer_models?.[t]?.model??(t===`opencode`?e.reviewer_model:null)??``,reviewerVariant:e.reviewer_models?.[t]?.variant??(t===`opencode`?e.reviewer_variant:null)??``,reviewerModels:e.reviewer_models??{},commitMessageRules:e.commit_message_rules??``,commitAfterEachTicket:e.commit_after_each_ticket,autoParkStaleTickets:e.auto_park_stale_tickets,memoryEnabled:e.memory_enabled,scanIncludeGlobs:e.scan_include_globs??[],scanExcludeGlobs:e.scan_exclude_globs??[],worktreeSync:Kge(e.worktree_sync),specAwareCodeReviewEnabled:e.spec_aware_code_review_enabled,automationDepth:e.automation_depth??`manual`,automationReviewFixEnabled:e.automation_review_fix_enabled??!1,automationPauseOnOpenQuestions:e.automation_pause_on_open_questions??!1,automationReviewSeverity:e.automation_review_severity??`medium`,automationReviewMaxIterations:e.automation_review_max_iterations??3}},X7=e=>{let t=e.previewServiceName?.trim()||null,n=e.previewPath?.trim()||``,r=n===``||n===`/`?null:n,i=t||r||e.previewCapabilityMode===`force_web`||e.previewCapabilityMode===`force_disabled`?e.previewCapabilityMode??`auto`:null;return{name:e.name,repo_path:e.repoPath,build_execution_provider:e.buildExecutionProvider??`host`,linked_project_ids:e.linkedProjectIds,run_setup:e.runSetup.length>0?e.runSetup:null,run_services:e.runServices.length>0?e.runServices.map(e=>({...e.name?{name:e.name}:{},cmd:e.cmd,...e.cwd?{cwd:e.cwd}:{}})):null,check_definitions:(e.checkDefinitions??[]).map(e=>e.category===`test`?{id:e.id,name:e.name,category:`test`,command:e.command,...e.cwd?{cwd:e.cwd}:{},timeout_ms:Number(e.timeoutMs),consequence:`ordinary`,runner:e.runner}:e.category===`custom`?{id:e.id,name:e.name,category:e.category,command:e.command,...e.cwd?{cwd:e.cwd}:{},timeout_ms:Number(e.timeoutMs),consequence:e.consequence??`ordinary`}:{id:e.id,name:e.name,category:e.category,command:e.command,...e.cwd?{cwd:e.cwd}:{},timeout_ms:Number(e.timeoutMs),consequence:`ordinary`}),required_check_definition_ids:(e.checkDefinitions??[]).filter(e=>e.required).map(e=>e.id).sort((e,t)=>e.localeCompare(t)),pre_review_check_definition_ids:(e.checkDefinitions??[]).filter(e=>e.required&&e.preReview).map(e=>e.id).sort((e,t)=>e.localeCompare(t)),post_build_check_definition_ids:(e.checkDefinitions??[]).filter(e=>e.postBuild).map(e=>e.id).sort((e,t)=>e.localeCompare(t)),auto_fix_check_definition_ids:(e.checkDefinitions??[]).filter(e=>e.autoFix).map(e=>e.id).sort((e,t)=>e.localeCompare(t)),run_ide:e.runIde||null,preview_service_name:t,preview_path:r,preview_capability_mode:i,helper_models:e.helperModels??{},reviewer_models:e.reviewerModels??{},commit_message_rules:e.commitMessageRules||null,commit_after_each_ticket:e.commitAfterEachTicket,auto_park_stale_tickets:e.autoParkStaleTickets,memory_enabled:e.memoryEnabled,scan_include_globs:e.scanIncludeGlobs??[],scan_exclude_globs:e.scanExcludeGlobs??[],worktree_sync:e.worktreeSync.length>0?e.worktreeSync.map(e=>({source:e.source,...e.target?{target:e.target}:{},mode:e.mode})):null,spec_aware_code_review_enabled:e.specAwareCodeReviewEnabled,automation_depth:e.automationDepth,automation_review_fix_enabled:e.automationReviewFixEnabled,automation_pause_on_open_questions:e.automationPauseOnOpenQuestions,automation_review_severity:e.automationReviewSeverity,automation_review_max_iterations:e.automationReviewMaxIterations}},Jge=e=>e?J7(e.run_setup).length>0||Y7(e.run_services).length>0||(e.run_ide?.trim().length??0)>0:!1,Z7=(e,t,n)=>`${e} ${e===1?t:n}`,Yge=e=>{if(!e.repo_path_locked)return null;let t=[];return e.ticket_count>0&&t.push(Z7(e.ticket_count,`ticket is attached`,`tickets are attached`)),e.worktree_count>0&&t.push(Z7(e.worktree_count,`worktree exists`,`worktrees exist`)),t.length===0?`Repository path is locked for this project.`:`Repository path is locked because ${t.join(` and `)}.`},Xge=(e,t)=>{if(t.length<=1)return`Keep at least one project in Archon.`;let n=[];e.ticket_count>0&&n.push(Z7(e.ticket_count,`ticket is attached`,`tickets are attached`)),e.worktree_count>0&&n.push(Z7(e.worktree_count,`worktree exists`,`worktrees exist`));let r=t.filter(t=>t.linked_project_ids.includes(e.id)).length;return r>0&&n.push(Z7(r,`project links to it`,`projects link to it`)),n.length===0?null:`This project can't be deleted while ${n.join(` and `)}.`},Zge=(e,t)=>e.id!==t.projectId||e.ticket_count===t.ticketCount&&e.worktree_count===t.worktreeCount&&e.repo_path_locked===t.repoPathLocked?e:{...e,ticket_count:t.ticketCount,worktree_count:t.worktreeCount,repo_path_locked:t.repoPathLocked},Qge=(e,t)=>({projectId:e,branch:t.branch,status:t.status,ahead:t.ahead??0,behind:t.behind??0,hasUpstream:t.has_upstream??!1,canPull:t.can_pull??!1,diffStats:t.diff_stats??null}),Q7=e=>({projectId:e,branch:null,status:`loading`,ahead:0,behind:0,hasUpstream:!1,canPull:!1,diffStats:null}),$7=(e,t)=>t?e[t]??G7:G7,e9=(e,t)=>t?e[t]??K7:K7,$ge=()=>{let e=window.localStorage.getItem(H7),t=Number(e);return Number.isFinite(t)&&t>=320?t:Lge},e_e=()=>{let e=window.localStorage.getItem(U7);return e===`phone`||e===`tablet`||e===`laptop`||e===`responsive`?e:Rge},t_e=()=>{let e=Number(window.localStorage.getItem(W7));return Number.isFinite(e)&&e>0?e:zge},n_e=()=>{let e=q7(window.localStorage.getItem(R7));return!e||typeof e!=`object`||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e).flatMap(([e,t])=>t===`activity`?[[e,`board`]]:t===`board`||t===`chat`||t===`spec`||t===`memory`?[[e,t]]:[]))},r_e=()=>{let e=q7(window.localStorage.getItem(z7));return!e||typeof e!=`object`||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e).filter(([,e])=>e===`hidden`||e===`inline`||e===`expanded`))},i_e=()=>{let e=q7(window.localStorage.getItem(B7));return!e||typeof e!=`object`||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e).filter(([,e])=>typeof e==`string`||e===null))},t9=e=>!!e?.preview_service_name?.trim()&&e?.preview_capability_mode!==`force_disabled`,a_e=({activeRun:e,project:t})=>{if(!e||e.kind!==`project`||!t)return!1;let n=t.active_target_kind??`repo_root`,r=t.active_target_bundle_id??null;return e.project_id===t.id&&(e.target_kind??`repo_root`)===n&&((e.target_kind??`repo_root`)!==`bundle`||e.target_bundle_id===r)},o_e=({activeRun:e,project:t,projectId:n})=>!e||!n?null:e.kind===`ticket`?e.project_id===n?e:null:a_e({activeRun:e,project:t})?e:null,n9=`Project root has uncommitted changes. Confirm branch switch to continue.`,s_e=({activeProject:e,activeProjectBranchState:t,nextTarget:n})=>e?n.kind===`bundle`?e.active_target_kind!==`bundle`||e.active_target_bundle_id!==n.bundleId:e.active_target_kind===`bundle`?!0:n.branch?t?.branch!==n.branch:!1:!1,c_e=()=>{let e=Pge(),t=uq(),{closeModal:n,modalStack:r,navigationVersion:i,push:a,pushModalSibling:o,replace:s,route:c}=e,l=Fge(c,r),[u,d]=(0,p.useState)(`opencode`),[f,m]=(0,p.useState)(Br),[h,g]=(0,p.useState)(!1),[_,v]=(0,p.useState)([]),[y,b]=(0,p.useState)(()=>window.localStorage.getItem(L7)),[x,S]=(0,p.useState)(null),[C,w]=(0,p.useState)(null),[T,E]=(0,p.useState)(null),[D,O]=(0,p.useState)({}),[k,A]=(0,p.useState)({}),[j,M]=(0,p.useState)({}),[N,P]=(0,p.useState)({}),[F,I]=(0,p.useState)({}),[L,R]=(0,p.useState)(r_e),[z,ee]=(0,p.useState)(i_e),[B,V]=(0,p.useState)($ge),[H,U]=(0,p.useState)(e_e),[W,te]=(0,p.useState)(t_e),[ne,re]=(0,p.useState)(null),[ie,ae]=(0,p.useState)({opencode:{models:[],loaded:!1},claude:{models:[],loaded:!1}}),[G,oe]=(0,p.useState)(0),[se,ce]=(0,p.useState)({opencode:{model:``,variant:``},claude:{model:``,variant:``}}),[le,ue]=(0,p.useState)(!1),[de,fe]=(0,p.useState)(null),[pe,me]=(0,p.useState)(`general`),[he,ge]=(0,p.useState)(null),[_e,ve]=(0,p.useState)(!1),[ye,be]=(0,p.useState)({}),[xe,Se]=(0,p.useState)(n_e),[Ce,we]=(0,p.useState)(null),[Te,Ee]=(0,p.useState)(()=>S7()),[De,Oe]=(0,p.useState)(()=>x7()),[ke,Ae]=(0,p.useState)(0),[je,Me]=(0,p.useState)(()=>({query:``,hideStaleTickets:!1,hideBundlesWithPullRequests:!1})),[Ne,Pe]=(0,p.useState)(null),[Fe,Ie]=(0,p.useState)(null),[Le,K]=(0,p.useState)({}),[Re,ze]=(0,p.useState)({}),[Be,Ve]=(0,p.useState)({}),[He,q]=(0,p.useState)({}),[Ue,We]=(0,p.useState)(!1),[Ke,J]=(0,p.useState)(!1),[qe,Je]=(0,p.useState)(!1),[Xe,Ze]=(0,p.useState)(!1),[Y,Qe]=(0,p.useState)(!1),[$e,et]=(0,p.useState)(!1),[tt,nt]=(0,p.useState)(`idle`),[rt,it]=(0,p.useState)(0),[ot,st]=(0,p.useState)(!1),{isGitHubConnected:ct,defaultBaseBranch:lt}=IC(y),[ut,dt]=(0,p.useState)(null),ft=(0,p.useRef)(null),pt=(0,p.useRef)(null),mt=(0,p.useRef)(null),ht=(0,p.useRef)(0),gt=(0,p.useRef)(-1),vt=(0,p.useRef)(!1),yt=(0,p.useRef)(0),bt=(0,p.useRef)(window.localStorage.getItem(L7)),xt=ie[u],St=xt.models,Ct=xt.loaded,wt=se[u].model,Tt=se[u].variant,Et=(0,p.useCallback)(()=>{ae(e=>({...e,[u]:{models:[],loaded:!1}})),oe(e=>e+1)},[u]),Dt=_.find(e=>e.id===y)??null,Ot=!!Dt?.memory_enabled,kt=y?xe[y]??`board`:`board`,At=kt===`memory`?Ot?`memory`:`board`:kt,jt=c?.projectId??Wge(window.location.pathname),Mt=jt?_.find(e=>e.id===jt)??null:null,Nt=c?.kind===`repository-inspection`?c:null,Pt=c?.kind===`workspace`&&c.workspace===`memory`&&Mt?.memory_enabled!==!0,It=tt===`error`,Lt=!!(c&&Mt&&y!==c.projectId),Rt=le&&window.location.pathname.startsWith(`/app`)&&(!c||!Mt||Pt||$e),Bt=_.find(e=>e.id===bt.current)??null,Vt=_[0]??null,Ht=(0,p.useCallback)(t=>{if(!y)return;Se(e=>({...e,[y]:t.workspace})),Ee(e=>C7(e,t.workspace));let n=t.workspace===`board`?{kind:`ticket`,projectId:y,ticketId:t.ticketId}:t.workspace===`chat`?{kind:`chat-session`,projectId:y,chatSessionId:t.chatSessionId}:t.specSnapshotId?{kind:`spec-snapshot`,projectId:y,specSessionId:t.specSessionId,specSnapshotId:t.specSnapshotId}:{kind:`spec-session`,projectId:y,specSessionId:t.specSessionId};if(c?.kind===`activity-run`){e.replace(n);return}e.push(n)},[y,e,c]),Ut=(0,p.useCallback)(t=>{y&&(Se(e=>({...e,[y]:t.workspace})),Ee(e=>C7(e,t.workspace)),we(t),e.push({kind:`workspace`,projectId:y,workspace:t.workspace}))},[y,e]),Gt=(0,p.useCallback)((e,t,n)=>{y&&Ut({workspace:`chat`,draft:!0,draftText:e,specSessionId:t,specSnapshotId:n})},[y,Ut]),Kt=(0,p.useCallback)((e,t)=>{Ht({workspace:`spec`,specSessionId:e,specSnapshotId:t})},[Ht]),Jt=(0,p.useCallback)(e=>{if(e.source_available){if(e.ticket_id){Ht({workspace:`board`,ticketId:e.ticket_id});return}if(e.chat_session_id){Ht({workspace:`chat`,chatSessionId:e.chat_session_id});return}e.spec_session_id&&Ht({workspace:`spec`,specSessionId:e.spec_session_id})}},[Ht]),Yt=(0,p.useCallback)(e=>{if(e.available){if(Je(!1),e.kind===`ticket`){Ht({workspace:`board`,ticketId:e.id});return}if(e.kind===`chat_session`){Ht({workspace:`chat`,chatSessionId:e.id});return}e.kind===`spec_session`&&Ht({workspace:`spec`,specSessionId:e.id})}},[Ht]),Xt=(0,p.useCallback)(e=>{Ut({workspace:`spec`,issueDraft:!0,draft:e})},[Ut]),Zt=(0,p.useCallback)(e=>{Ut({workspace:`board`,issueDraft:!0,draft:e})},[Ut]),Qt=(0,p.useCallback)(()=>{we(null)},[]),$t=Dt!==null,en=Jge(Dt),an=!!Dt?.run_ide?.trim(),on=y!==null&&C===y,sn=y!==null&&(!en||T===y),cn=y?D[y]??Q7(y):null,ln=y?k[y]??null:null,un=y?!!j[y]:!1,dn=y?N[y]??null:null,fn=(0,p.useMemo)(()=>y?Le[y]??[]:[],[y,Le]),pn=y?!!Re[y]:!1,mn=y?Be[y]??{current_branch:null,default_branch:null,previous_branch:null}:{current_branch:null,default_branch:null,previous_branch:null},hn=y?!!He[y]:!1,gn=y?F[y]??null:null,_n=e9(L,y),vn=_n!==`hidden`,yn=o_e({activeRun:x,project:Dt,projectId:y}),bn=yn?.context_key??null,xn=y?z[y]??null:null,Sn=t9(Dt),Cn=bn===ne,wn=(0,p.useMemo)(()=>lge(Te),[Te]),Tn=(0,p.useMemo)(()=>w7({hasRunning:wn.hasRunning,hasFinishedUnseen:De.hasFinishedUnseen,hasErrorUnseen:De.hasErrorUnseen}),[wn.hasRunning,De.hasErrorUnseen,De.hasFinishedUnseen]);(0,p.useEffect)(()=>{Pe(null),Ie(null),pt.current=null},[y]),(0,p.useEffect)(()=>{Ie(null)},[At]),(0,p.useEffect)(()=>{vn||(pt.current=null)},[vn]),(0,p.useEffect)(()=>{let e=Ne?.target?.kind??null;if(e===`ticket`||e===`bundle`){pt.current=Ne;return}(At===`board`||!vn)&&(pt.current=Ne)},[vn,Ne,At]),(0,p.useEffect)(()=>{Ee(S7())},[y]),(0,p.useEffect)(()=>{Oe(x7())},[y]),(0,p.useEffect)(()=>{if(!y||xx(y))return;let e=new AbortController;return at(y,e.signal).then(e=>{bx(y,e.connections)}).catch(e=>{Ye(e)}),()=>{e.abort()}},[y]);let En=(0,p.useCallback)((e,t)=>{document.visibilityState!==`visible`&&(!t.didFinish&&!t.didError||Oe(e=>{let n={...e,hasFinishedUnseen:e.hasFinishedUnseen||t.didFinish,hasErrorUnseen:e.hasErrorUnseen||t.didError};return e.hasFinishedUnseen===n.hasFinishedUnseen&&e.hasErrorUnseen===n.hasErrorUnseen?e:n}))},[]);(0,p.useEffect)(()=>{let e=()=>{document.visibilityState===`visible`&&Oe(e=>!e.hasFinishedUnseen&&!e.hasErrorUnseen?e:{...e,hasFinishedUnseen:!1,hasErrorUnseen:!1})};return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},[]),(0,p.useEffect)(()=>{let e=e=>{e.tool!==`claude`&&e.tool!==`opencode`||(ht.current+=1,d(e.tool),g(!0))};return t.on(`tool:updated`,e),()=>{t.off(`tool:updated`,e)}},[t]),(0,p.useEffect)(()=>(ft.current===null&&(ft.current=document.querySelector(`link[rel="icon"]`)?.getAttribute(`href`)??`/favicon.svg`),j7({defaultHref:ft.current,state:Tn}),()=>{j7({defaultHref:ft.current,state:null})}),[Tn]);let Dn=(0,p.useCallback)(async(e,t={})=>{let{refreshRemote:n=!1,signal:r}=t;try{let t=await $n(e,r,{refreshRemote:n});if(r?.aborted)return;O(n=>({...n,[e]:Qge(e,t)}))}catch(t){if(Ye(t))return;if(t instanceof Ge&&t.status===404){O(t=>({...t,[e]:{...Q7(e),status:`unknown`}}));return}O(t=>({...t,[e]:{projectId:e,branch:t[e]?.branch??null,status:`unknown`,ahead:t[e]?.ahead??0,behind:t[e]?.behind??0,hasUpstream:t[e]?.hasUpstream??!1,canPull:t[e]?.canPull??!1,diffStats:t[e]?.diffStats??null}}))}},[]),On=(0,p.useCallback)(async(e,t={})=>{let{refreshRemote:n=!1,signal:r,suppressLoading:i=!1}=t;i||M(t=>({...t,[e]:!0}));try{let t=await ur(e,{refreshRemote:n,signal:r});if(r?.aborted)return;A(n=>({...n,[e]:t}))}catch(t){if(Ye(t))return;t instanceof Ge&&t.status===404&&A(t=>({...t,[e]:null}))}finally{!r?.aborted&&!i&&M(t=>({...t,[e]:!1}))}},[]),kn=(0,p.useCallback)((e,t)=>{P(n=>({...n,[e]:t}))},[]),jn=(0,p.useCallback)(async(e,t)=>{A(n=>({...n,[e.id]:t})),e.active_target_kind!==`bundle`&&await Dn(e.id),i6(e.id)},[Dn]);(0,p.useEffect)(()=>{let e=new AbortController;return(async()=>{let t=ht.current;try{let{tool:n}=await Ur(e.signal);ht.current===t&&d(n)}catch(e){Ye(e)}finally{e.signal.aborted||g(!0)}})(),Hr(e.signal).then(t=>{e.signal.aborted||m(t.length>0?t:Br())}).catch(()=>{m(Br())}),()=>{e.abort()}},[]),(0,p.useEffect)(()=>{if(!le||_.length>0&&de===null||xt.loaded)return;let e=new AbortController;return(async()=>{try{let t=await Rr(u,e.signal);if(e.signal.aborted)return;ae(e=>({...e,[u]:{models:t,loaded:!0}}))}catch{}finally{e.signal.aborted||ae(e=>({...e,[u]:{...e[u],loaded:!0}}))}})(),()=>{e.abort()}},[xt.loaded,u,G,de,_.length,le]),(0,p.useEffect)(()=>{let e=new AbortController;return(async()=>{try{let t=await Vn(e.signal);if(e.signal.aborted)return;v(t)}catch(e){Ye(e)||v([])}finally{e.signal.aborted||ue(!0)}})(),()=>{e.abort()}},[]),(0,p.useEffect)(()=>{if(!le||gt.current===i)return;gt.current=i,et(!1),nt(`idle`),we(e=>e&&c?.kind===`workspace`&&c.workspace===e.workspace?e:null);let e=r.some(e=>e.kind===`activity-run`),t=r.some(e=>e.kind===`checks`);if(!e&&c?.kind!==`activity-run`&&!vt.current&&Je(!1),!t&&c?.kind!==`checks`&&ge(null),window.location.pathname===`/`){let e=_.find(e=>e.id===bt.current)??_[0]??null;if(!e){b(null);return}let t=xe[e.id]??`board`,n=t===`memory`&&!e.memory_enabled?`board`:t;b(e.id),Se(t=>({...t,[e.id]:n})),s({kind:`workspace`,projectId:e.id,workspace:n});return}if(!c)return;let n=_.find(e=>e.id===c.projectId);if(!n)return;b(n.id);let a=c.kind===`workspace`?c.workspace:c.kind===`ticket`||c.kind===`bundle`?`board`:c.kind===`repository-inspection`||c.kind===`bundle-inspection`||c.kind===`ticket-inspection`?xe[n.id]??`board`:c.kind===`chat-session`?`chat`:c.kind===`spec-session`||c.kind===`spec-snapshot`?`spec`:xe[n.id]??`board`;Se(e=>({...e,[n.id]:a})),vt.current&&c.kind!==`checks`&&(vt.current=!1,Je(!0)),(c.kind===`activity-run`||e)&&Je(!0),J4(c)!==window.location.pathname&&s(c)},[c,r,i,_,le,s,xe]),(0,p.useEffect)(()=>{if(c?.kind!==`checks`||!le)return;let e=_.find(e=>e.id===c.projectId);if(!e)return;let t=new AbortController,n=++yt.current;return nt(`loading`),qt(e.id,c.batchRunId,t.signal).then(({batch:r})=>{t.signal.aborted||yt.current!==n||(ge({projectId:e.id,targetKind:r.target_kind,targetBundleId:r.target_bundle_id,targetLabel:r.target_label??e.name,definitions:r.selected_definition_snapshots,requiredDefinitionIds:[],preReviewDefinitionIds:[]}),nt(`idle`))}).catch(e=>{if(!Ye(e)){if(e instanceof Ge&&e.status===404){et(!0);return}nt(`error`)}}),()=>t.abort()},[c,_,le,rt]),(0,p.useEffect)(()=>{if(st(!1),!y||!ct||Y)return;let e=new AbortController,t=async()=>{try{let t=await Wt(y,e.signal);e.signal.aborted||st(t.activeCount>0)}catch(e){Ye(e)}};t();let n=window.setInterval(()=>{t()},V7);return()=>{e.abort(),window.clearInterval(n)}},[y,Y,ct]),(0,p.useEffect)(()=>{if(le){if(y){bt.current=y,window.localStorage.setItem(L7,y);return}window.localStorage.removeItem(L7)}},[y,le]),(0,p.useEffect)(()=>{window.localStorage.setItem(R7,JSON.stringify(xe))},[xe]),(0,p.useEffect)(()=>{window.localStorage.setItem(z7,JSON.stringify(L))},[L]),(0,p.useEffect)(()=>{window.localStorage.setItem(B7,JSON.stringify(z))},[z]),(0,p.useEffect)(()=>{O(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)}),A(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)}),M(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)})},[_]),(0,p.useEffect)(()=>{be(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)})},[_]),(0,p.useEffect)(()=>{let e=new Set(_.map(e=>e.id));K(t=>Object.fromEntries(Object.entries(t).filter(([t])=>e.has(t)))),ze(t=>Object.fromEntries(Object.entries(t).filter(([t])=>e.has(t)))),Ve(t=>Object.fromEntries(Object.entries(t).filter(([t])=>e.has(t)))),q(t=>Object.fromEntries(Object.entries(t).filter(([t])=>e.has(t))))},[_]),(0,p.useEffect)(()=>{le&&(I(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)}),R(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)}),ee(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)}))},[_,le]),(0,p.useEffect)(()=>{le&&Se(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)})},[_,le]),(0,p.useEffect)(()=>{if(!le||!y||!$t)return;let e=!1,t=null,n=null;O(e=>e[y]?e:{...e,[y]:Q7(y)});let r=async(r=!1)=>{let i=r?`remote`:`local`;if(t){if(n===`remote`||n===i)return;t.abort()}let a=new AbortController;t=a,n=i;try{await Promise.all([Dn(y,{refreshRemote:r,signal:a.signal}),On(y,{refreshRemote:r,signal:a.signal})])}catch{if(e||a.signal.aborted)return}finally{t===a&&(t=null,n=null)}};r(!1);let i=hx(()=>{document.visibilityState===`visible`&&r(!1)});return()=>{e=!0,t?.abort(),i()}},[y,$t,le,Dn,On]),(0,p.useEffect)(()=>{if(y)return a6(e=>{e===y&&(Dn(e),On(e))})},[y,Dn,On]),(0,p.useEffect)(()=>{if(!y||!$t)return;let e=ln?.operation_state??`idle`;if(!(dn===`rebase`||e!==`idle`))return;let t=!1,n=null,r=null,i=async()=>{r?.abort(),r=new AbortController;try{await On(y,{signal:r.signal,suppressLoading:!0})}catch{}finally{t||(n=window.setTimeout(()=>{i()},Ige))}};return i(),()=>{t=!0,r?.abort(),n!==null&&window.clearTimeout(n)}},[dn,y,ln?.operation_state,$t,On]);let Mn=(0,p.useCallback)(async e=>{let t=y;if(!t){S(null),E(null);return}try{let n=await tn(t,e);e?.aborted||(S(n.active_run),E(t))}catch(e){Ye(e)}},[y]),Nn=(0,p.useCallback)(async e=>{let t=y;if(t)try{let n=await zt(t,e);e?.aborted||I(e=>({...e,[t]:n}))}catch(e){Ye(e)}},[y]);(0,p.useEffect)(()=>{if(!le)return;if(!en){S(null),E(null);return}if(!on)return;let e=new AbortController;E(null),Mn(e.signal);let t=window.setInterval(()=>{Mn(e.signal)},V7),n=hx(()=>{document.visibilityState===`visible`&&Mn(e.signal)});return()=>{e.abort(),window.clearInterval(t),n()}},[on,en,le,Mn]),(0,p.useEffect)(()=>{if(!le||!y||!on||!Sn)return;let e=new AbortController;Nn(e.signal);let t=window.setInterval(()=>{Nn(e.signal)},V7),n=hx(()=>{document.visibilityState===`visible`&&Nn(e.signal)});return()=>{e.abort(),window.clearInterval(t),n()}},[y,on,Sn,le,Nn]),(0,p.useEffect)(()=>{window.localStorage.setItem(H7,String(B))},[B]),(0,p.useEffect)(()=>{window.localStorage.setItem(U7,H)},[H]),(0,p.useEffect)(()=>{window.localStorage.setItem(W7,String(W))},[W]),(0,p.useEffect)(()=>{y&&bn&&ee(e=>{let t=e[y]??null;return!t||t===bn?e:{...e,[y]:null}})},[y,bn]),(0,p.useEffect)(()=>{!y||!yn||!t9(Dt)||xn!==yn.context_key&&R(e=>e9(e,y)===`hidden`?{...e,[y]:`inline`}:e)},[Dt,y,xn,yn]);let Pn=async e=>{let t=ht.current+1;ht.current=t;try{let n=await Wr(e);if(ht.current!==t)return;d(n.tool)}catch{}},Fn=(0,p.useCallback)(e=>{v(t=>t.map(t=>t.id===e.id?e:t))},[]),In=(0,p.useCallback)((e,t)=>{K(n=>{let r=[t,...(n[e]??[]).filter(e=>e.id!==t.id)];return{...n,[e]:r}})},[]),Ln=(0,p.useCallback)(async e=>{q(t=>({...t,[e]:!0}));try{let t=await qn(e);Ve(n=>({...n,[e]:t}))}catch(e){$.error(e instanceof Ge?e.message:`Unable to load the project target options right now.`,{id:`project-target-selector-load-error`})}finally{q(t=>({...t,[e]:!1}))}},[]),Rn=async e=>{try{let t=await Hn(X7(e));return v(e=>[...e,t]),b(t.id),s({kind:`workspace`,projectId:t.id,workspace:`board`}),fe(null),null}catch(e){return e instanceof Ge?e.message:`Unable to create the project right now.`}},zn=async e=>{if(!Dt)return`Select a project before editing settings.`;try{let t=X7(e);delete t.build_execution_provider;let n=await Un(Dt.id,t);return v(e=>e.map(e=>e.id===n.id?n:e)),Ae(e=>e+1),fe(null),null}catch(e){return e instanceof Ge?e.message:`Unable to update the project right now.`}},Bn=async()=>{if(!Dt)return`Select a project before deleting it.`;try{await Gn(Dt.id);let e=_.filter(e=>e.id!==Dt.id);return v(e),b(e[0]?.id??null),e[0]&&s({kind:`workspace`,projectId:e[0].id,workspace:`board`}),fe(null),null}catch(e){return e instanceof Ge?e.message:`Unable to delete the project right now.`}},Qn=(0,p.useCallback)(e=>{v(t=>t.map(t=>Zge(t,e)))},[]),rr=(0,p.useCallback)((e,t)=>{e&&K(n=>({...n,[e]:t}))},[]),ir=(0,p.useCallback)((e,t)=>{e&&ze(n=>({...n,[e]:t}))},[]),ar=async(e,t,n)=>await Yn({repo_path:e,tool:u,helper_models:tw({},u,{model:t||null,variant:t&&n||null})}),or=async()=>(await Xn()).repo_path,sr=(0,p.useCallback)(async e=>{let t=await Zn({repo_path:e});return{valid:t.valid,repoRoot:t.repo_root,error:t.error,willInitialize:t.will_initialize,hasInitialCommit:t.has_initial_commit}},[]),cr=(0,p.useCallback)(async()=>{if(!(!Dt||_e)){ve(!0);try{let e=await Wn(Dt.id);v(t=>t.map(t=>t.id===e.id?e:t)),$.success(`Initial commit created.`,{id:`project-initial-commit-success`}),Dn(e.id),On(e.id)}catch(e){$.error(e instanceof Ge?e.message:`Unable to create the initial commit right now.`,{id:`project-initial-commit-error`})}finally{ve(!1)}}},[Dt,_e,Dn,On]),lr=(0,p.useCallback)((e,t)=>{R(t=>({...t,[e]:`hidden`})),t&&ee(n=>({...n,[e]:t}))},[]),dr=(0,p.useCallback)(()=>{y&&lr(y,bn)},[y,lr,bn]),fr=(0,p.useCallback)(e=>{y&&(R(e=>({...e,[y]:`hidden`})),e&&S(t=>t?.context_key===e?null:t))},[y]),pr=(0,p.useCallback)(async()=>{if(!yn||ne===yn.context_key)return;let{context_key:e}=yn;re(e);try{yn.kind===`ticket`?await An(yn.ticket_id,yn.project_id):S((await rn(yn.project_id)).active_run),fr(e),await Promise.all([Mn(),Nn()])}catch(e){$.error(e instanceof Ge?e.message:`Unable to stop the preview run right now.`,{id:`app-preview-run-stop-error`})}finally{re(t=>t===e?null:t)}},[fr,yn,Nn,Mn,ne]),mr=(0,p.useCallback)(e=>{!e||!y||Ln(y)},[y,Ln]),hr=(0,p.useCallback)(e=>new Promise(t=>{mt.current=t,dt(e)}),[]),gr=(0,p.useCallback)(e=>{let t=mt.current;mt.current=null,dt(null),t?.(e)},[]),_r=(0,p.useCallback)(async e=>{if(!Dt||!y)throw Error(`Select a project first.`);if(!s_e({activeProject:Dt,activeProjectBranchState:cn,nextTarget:e})||!x||x.kind!==`project`||x.project_id!==Dt.id)return!0;if(!await hr({title:`Stop current run and switch target?`,description:`Switching targets will stop the current run and close its preview.`,confirmLabel:`Stop and switch`,cancelLabel:`Keep current target`,confirmVariant:`destructive`}))return!1;try{let e=x.context_key,t=await rn(Dt.id);return fr(e),S(t.active_run),await Nn(),!0}catch(e){return $.error(e instanceof Ge?e.message:`Unable to stop the project run right now.`,{id:`project-target-switch-stop-run-error`}),!1}},[Dt,cn,y,x,fr,Nn,hr]),vr=(0,p.useCallback)(async e=>{if(!y)throw Error(`Select a project first.`);return await _r({kind:`bundle`,bundleId:e})?(Fn(await Jn(y,{kind:`bundle`,bundle_id:e})),A(e=>({...e,[y]:null})),await Promise.all([Dn(y),On(y)]),!0):!1},[y,_r,Dn,On,Fn]),yr=(0,p.useCallback)(async(e,t={})=>{if(!y)throw Error(`Select a project first.`);if(!await _r({kind:`repo_root`,branch:e}))return!1;let n=n=>Jn(y,{kind:`repo_root`,...e?{branch:e}:{},...t.createBranch===!1?{create_branch:!1}:{},...n?{confirm_dirty_switch:!0}:{}}),r;try{r=await n(t.confirmDirtySwitch===!0)}catch(e){if(!t.confirmDirtySwitch&&e instanceof Ge&&e.status===409&&e.message===n9){if(!await hr({title:`Switch repo root branch?`,description:`${n9}\n\nSwitch anyway?`,confirmLabel:`Switch anyway`,cancelLabel:`Keep current branch`}))return!1;r=await n(!0)}else throw e}return Fn(r),A(e=>({...e,[y]:null})),await Promise.all([Dn(y),On(y),Ln(y)]),!0},[y,_r,Ln,Dn,On,Fn,hr]),br=(0,p.useCallback)(async e=>!e.target_kind||e.target_available===!1?!0:e.target_kind===`bundle`?e.target_bundle_id?await vr(e.target_bundle_id):!1:await yr(e.target_branch_snapshot??null,{createBranch:!1}),[vr,yr]),xr=(0,p.useCallback)(async e=>{y&&await vr(e)&&Ut({workspace:`chat`,startNewDraft:!0})},[y,vr,Ut]),Sr=(0,p.useCallback)(()=>{We(!0)},[]),Cr=(0,p.useCallback)(()=>{We(!1)},[]),wr=(0,p.useCallback)(e=>{if(e){vr(e);return}yr(null)},[vr,yr]),Tr=(0,p.useCallback)(async e=>{if(!y)throw Error(`Select a project first.`);let t=await _t(y,{name:e,prepare:!0});return In(y,t),Ae(e=>e+1),t},[y,In]),Er=(0,p.useCallback)(async e=>{if(!y)throw Error(`Select a project first.`);let t=await Ft(y,e);t.warning&&$.warning(t.warning,{id:`bundle-delete-warning`}),K(t=>({...t,[y]:(t[y]??[]).filter(t=>t.id!==e)})),Ae(e=>e+1)},[y]),Dr=(0,p.useCallback)(async()=>{if(!Dt)return;let e=Dt.active_target_kind??`repo_root`,t=Dt.active_target_bundle_id??null,n=x?.kind===`project`&&x.project_id===Dt.id&&(x.target_kind??`repo_root`)===e&&((x.target_kind??`repo_root`)!==`bundle`||x.target_bundle_id===t),r=n?x?.context_key??null:null,i=!n&&t9(Dt)&&_n===`hidden`;i&&(R(e=>({...e,[Dt.id]:`inline`})),ee(e=>({...e,[Dt.id]:null})));try{let e=n?await rn(Dt.id):await nn(Dt.id);n&&fr(r),S(e.active_run),Nn()}catch(e){i&&R(e=>({...e,[Dt.id]:`hidden`})),$.error(e instanceof Ge?e.message:`Unable to update the project run right now.`,{id:`app-project-run-error`})}},[_n,Dt,x,fr,Nn]),Or=(0,p.useCallback)(async()=>{if(!(!Dt||!an))try{await Kn(Dt.id)}catch(e){$.error(e instanceof Error?e.message:`Unable to open the IDE right now.`,{id:`app-project-open-ide-error`})}},[Dt,an]),kr=(0,p.useCallback)(async()=>{if(Dt){kn(Dt.id,`pull`);try{let e=await er(Dt.id);await jn(Dt,e),$.success(e.behind===0?I7(`branchSynced`):I7(`branchUpdated`),{id:`app-project-pull-success`})}catch(e){$.error(e instanceof Ge?e.message:I7(`syncFallbackError`),{id:`app-project-pull-error`})}finally{kn(Dt.id,null)}}},[Dt,jn,kn]),Ar=(0,p.useCallback)(async()=>{if(!Dt)return;let e=ln?.base_branch??null;kn(Dt.id,`rebase`);try{let t=await tr(Dt.id);await jn(Dt,t);let n=t.base_branch??e;$.success(n?I7(`branchRebasedOnto`,{branch:n}):I7(`branchRebased`),{id:`app-project-rebase-success`})}catch(e){await Promise.allSettled([Dn(Dt.id),On(Dt.id,{suppressLoading:!0})]),$.error(e instanceof Ge?e.message:I7(`rebaseFallbackError`),{id:`app-project-rebase-error`})}finally{kn(Dt.id,null)}},[Dt,ln?.base_branch,jn,Dn,On,kn]),jr=(0,p.useCallback)(async()=>{if(Dt){kn(Dt.id,`abort`);try{await jn(Dt,await nr(Dt.id)),$.success(I7(`gitOperationAborted`),{id:`app-project-abort-success`})}catch(e){$.error(e instanceof Ge?e.message:I7(`abortFallbackError`),{id:`app-project-abort-error`})}finally{kn(Dt.id,null)}}},[Dt,jn,kn]),Mr=(0,p.useCallback)(e=>{Dt&&a(Dt.active_target_kind===`bundle`&&Dt.active_target_bundle_id?{kind:`bundle-inspection`,projectId:Dt.id,bundleId:Dt.active_target_bundle_id,mode:e}:{kind:`repository-inspection`,projectId:Dt.id,mode:e})},[Dt,a]),Nr=(0,p.useCallback)(()=>{if(c?.kind!==`repository-inspection`)return;let{projectId:e}=c;n(c,{kind:`workspace`,projectId:e,workspace:`board`}),Dn(e),On(e)},[n,c,Dn,On]),Pr=(0,p.useCallback)(()=>{if(!Dt)return;let e=Dt.active_target_kind??`repo_root`,t=Dt.active_target_bundle_id??null,n=e===`bundle`?fn.find(e=>e.id===t):null,r=n?.required_check_policy;ge({projectId:Dt.id,targetKind:e,targetBundleId:t,targetLabel:n?Jy(n):Dt.name,definitions:KC(Dt),requiredDefinitionIds:r?.required_check_definition_ids??qC(Dt),preReviewDefinitionIds:r?.pre_review_check_definition_ids??JC(Dt)})},[Dt,fn]),Fr=(0,p.useCallback)(()=>{ge(null),c?.kind===`checks`&&n(c)},[n,c]),Ir=(0,p.useCallback)(()=>{Je(!1),ge(null),c?.kind===`activity-run`&&n(c)},[n,c]),Lr=(0,p.useCallback)(()=>{c?.kind===`activity-run`&&(vt.current=!0,n(c))},[n,c]),zr=(0,p.useCallback)(()=>{et(!0)},[]),Vr=(0,p.useCallback)((e,t)=>{if(!y)return;if(e.kind===`check_batch`){a({kind:`checks`,projectId:y,batchRunId:e.id});return}if(e.kind===`check_attempt`&&t){a({kind:`checks`,projectId:y,batchRunId:t,attemptRunId:e.id});return}let n={kind:`activity-run`,projectId:y,runId:e.id};c?.kind===`activity-run`?s(n):a(n)},[y,c,a,s]),Gr=(0,p.useCallback)(e=>{if(!y)return;if(e.kind===`source_batch`||e.kind===`verification_batch`||e.kind===`required_check_gate`){qe&&c?.kind!==`activity-run`&&(vt.current=!0),a({kind:`checks`,projectId:y,batchRunId:e.executionRunId});return}let t={kind:`activity-run`,projectId:y,runId:e.executionRunId};c?.kind===`activity-run`?s(t):a(t)},[y,c,qe,a,s]),Kr=(0,p.useCallback)((e,t)=>{if(!y)return;let n={kind:`checks`,projectId:y,batchRunId:e,attemptRunId:t};if(c?.kind===`checks`){J4(c)!==J4(n)&&s(n);return}a(n)},[y,c,a,s]),qr=$7(ye,y),Jr=Dt?XC(Dt).length>0:!1,Yr=Dt?KC(Dt).length>0:!1,Xr=At===`chat`?Fe:null,Zr=pt.current,Qr=Zr?.target?.kind??null,$r=At===`chat`?Qr===`ticket`||Qr===`bundle`?{target:Zr?.target??null,canSelect:!1,disabledReason:`This preview belongs to a ticket run. Return to Board to send preview comments.`,promptMode:Zr?.promptMode??null,onPromptModeChange:Zr?.onPromptModeChange??null,isUpdatingPromptMode:Zr?.isUpdatingPromptMode??!1,promptPlaceholder:Zr?.promptPlaceholder??null,promptComposerControls:Zr?.promptComposerControls,promptComposerInlineControls:Zr?.promptComposerInlineControls,submitPrompt:null}:Xr?{target:{kind:`chat_session`,id:Xr.chatSessionId??`draft:${y}`},canSelect:Xr.canSubmitReviewPrompt,disabledReason:Xr.canSubmitReviewPrompt?null:Xr.reviewSubmitDisabledReason??`Wait for the current chat turn to finish before sending preview comments.`,promptMode:Xr.mode,onPromptModeChange:Xr.onModeChange,isUpdatingPromptMode:Xr.isUpdatingMode,promptPlaceholder:Xr.promptPlaceholder,promptComposerControls:Xr.promptComposerControls,promptComposerInlineControls:Xr.promptComposerInlineControls,submitPrompt:Xr.canSubmitReviewPrompt?Xr.submitPrompt:null}:{target:null,canSelect:!1,disabledReason:`Select a chat session to send preview comments.`,submitPrompt:null}:Ne,ei=Xr?.canSubmitReviewPrompt??!1,ti=At===`chat`?Xr?Xr.reviewSubmitDisabledReason:`Select a chat session to send review comments.`:qb.t(`common:workspaceReviewModal.chatRequired`),ni=(0,p.useCallback)(()=>{y&&be(e=>{let t=e[y]??G7;return{...e,[y]:{hasMounted:!0,isOpen:!t.isOpen,isExpanded:t.isExpanded}}})},[y]),ri=(0,p.useCallback)(e=>{be(t=>{let n=t[e]??G7;return!n.hasMounted||!n.isOpen?t:{...t,[e]:G7}})},[]),ii=(0,p.useCallback)(e=>{be(t=>{let n=t[e]??G7;return{...t,[e]:{hasMounted:!0,isOpen:n.isOpen,isExpanded:!n.isExpanded}}})},[]),ai=(0,p.useCallback)(()=>{me(`general`),fe(`create`)},[]),oi=(0,p.useCallback)((e=`general`)=>{me(e),fe(`edit`)},[]),si=(0,p.useCallback)(e=>{let t=xe[e.id]??`board`,n=t===`memory`&&!e.memory_enabled?`board`:t;b(e.id),a({kind:`workspace`,projectId:e.id,workspace:n})},[a,xe]),ci=(0,p.useCallback)(e=>{y&&(c?.kind===`ticket`&&c.ticketId===e||a({kind:`ticket`,projectId:y,ticketId:e}))},[y,c,a]),li=(0,p.useCallback)(()=>{c?.kind===`ticket`&&n(c)},[n,c]),ui=(0,p.useCallback)(e=>{y&&(c?.kind===`bundle`&&c.bundleId===e||a({kind:`bundle`,projectId:y,bundleId:e}))},[y,c,a]),di=(0,p.useCallback)(()=>{c?.kind===`bundle`&&n(c)},[n,c]),fi=(0,p.useCallback)((e,t)=>{y&&a(e.kind===`ticket`?{kind:`ticket-inspection`,projectId:y,ticketId:e.ticketId,mode:t}:{kind:`bundle-inspection`,projectId:y,bundleId:e.bundleId,mode:t})},[y,a]),pi=(0,p.useCallback)(e=>{if(c?.kind===`repository-inspection`){if(c.mode===e)return;o({...c,mode:e});return}if(c?.kind===`ticket-inspection`||c?.kind===`bundle-inspection`){if(c.mode===e)return;o({...c,mode:e})}},[c,o]),mi=(0,p.useCallback)(()=>{c?.kind!==`ticket-inspection`&&c?.kind!==`bundle-inspection`||n(c)},[n,c]),hi=(0,p.useCallback)(e=>{if(!y)return;let t=e?{kind:`chat-session`,projectId:y,chatSessionId:e}:{kind:`workspace`,projectId:y,workspace:`chat`};c&&J4(c)===J4(t)||a(t)},[y,c,a]),gi=(0,p.useCallback)(e=>{if(!y)return;let t=e?{kind:`spec-session`,projectId:y,specSessionId:e}:{kind:`workspace`,projectId:y,workspace:`spec`};c&&J4(c)===J4(t)||a(t)},[y,c,a]),_i=(0,p.useCallback)(()=>{if(y){if(vn){dr();return}R(e=>({...e,[y]:`inline`})),ee(e=>({...e,[y]:null}))}},[y,dr,vn]),vi=(0,p.useCallback)(()=>{y&&R(e=>{let t=e9(e,y);return{...e,[y]:t===`expanded`?`inline`:`expanded`}})},[y]),yi=Dt?Dt.preview_service_name?.trim()?Dt.preview_capability_mode===`force_disabled`?`Preview is disabled for this project.`:gn?.state===`unsupported`?gn.message??`Preview is unavailable for this project.`:vn?`Hide preview`:`Show preview`:`Choose a named preview service in project settings first.`:`Select a project first.`,bi=!Dt||!Dt.preview_service_name?.trim()||Dt.preview_capability_mode===`force_disabled`||gn?.state===`unsupported`,xi=Dt&&Dt.preview_service_name?.trim()?(0,X.jsx)(bae,{project:Dt,mode:_n===`expanded`?`expanded`:`inline`,status:gn,viewportPreset:H,zoom:W,activeRun:yn,reviewCapability:$r,isStoppingActiveRun:Cn,onHide:dr,onStopActiveRun:()=>{pr()},onToggleExpanded:vi,onViewportPresetChange:U,onZoomChange:te}):null;return(0,X.jsxs)(`div`,{className:`flex h-screen flex-col overflow-hidden bg-[linear-gradient(180deg,_rgba(15,16,21,1),_rgba(9,10,14,1))] text-foreground`,children:[(0,X.jsx)(px,{}),_.length>0&&(0,X.jsx)(`header`,{className:`border-b border-border bg-background/95 px-6 py-3 backdrop-blur`,children:(0,X.jsxs)(`div`,{className:`grid items-start gap-3 [grid-template-columns:minmax(0,1fr)_auto] min-[1440px]:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] min-[1440px]:items-center`,children:[(0,X.jsx)(`div`,{className:`min-w-0`,children:(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`min-w-0 w-full sm:w-[20rem] sm:min-w-[20rem] sm:max-w-[20rem]`,children:(0,X.jsx)(Rte,{activeProjectId:y,onCreateProject:ai,projects:_,onEditProject:()=>oi(),onProjectChange:e=>{let t=_.find(t=>t.id===e);t&&si(t)}})}),y&&(0,X.jsx)(Ine,{projectId:y,onStartSpecFromDraft:Xt,onCreateTicketFromDraft:Zt})]})}),(0,X.jsx)(`div`,{className:`min-w-0 justify-self-end min-[1440px]:col-start-3 min-[1440px]:row-start-1`,children:(0,X.jsx)(Ub,{activeTool:u,agents:f,onMobileAccessOpen:()=>J(!0),onOpenActivity:()=>Je(!0),onOpenExecutionRuntimes:()=>Ze(!0),onToolChange:Pn,...ct?{hasActiveGitHubRuns:ot,onOpenGitHubActions:()=>Qe(!0)}:{}})}),y&&(0,X.jsx)(`div`,{className:`col-span-2 flex min-w-0 justify-center min-[1440px]:col-span-1 min-[1440px]:col-start-2 min-[1440px]:row-start-1 min-[1440px]:justify-self-center`,children:(0,X.jsx)(wge,{activeWorkspace:At,activityByWorkspace:Te,className:`w-fit max-w-full`,memoryEnabled:Ot,onWorkspaceChange:e=>{y&&(Se(t=>({...t,[y]:e})),Ee(t=>C7(t,e)),a({kind:`workspace`,projectId:y,workspace:e}))}})})]})}),!le||Lt?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:`Loading projects...`}):Rt||It?(0,X.jsx)(Ite,{isTransientError:It,requestedProjectExists:Mt!==null,retainedProject:Bt?.id===Mt?.id?null:Bt,defaultProject:Vt,onCreateProject:ai,onRetry:()=>it(e=>e+1),onOpenProject:e=>{let t=xe[e.id]??`board`,n=t===`memory`&&!e.memory_enabled?`board`:t;b(e.id),s({kind:`workspace`,projectId:e.id,workspace:n})},onOpenWorkspace:()=>{if(!Mt)return;let e=Gge(c),t=e===`memory`&&!Mt.memory_enabled?`board`:e;b(Mt.id),s({kind:`workspace`,projectId:Mt.id,workspace:t})}}):_.length===0?(0,X.jsx)(Fte,{activeTool:u,agents:f,availableHelperModels:St,helperModel:wt,helperVariant:Tt,isHelperModelsLoaded:Ct,isToolLoaded:h,onCreateProject:ai,onHelperModelChange:e=>{ce(t=>({...t,[u]:{model:e,variant:``}}))},onHelperVariantChange:e=>{ce(t=>({...t,[u]:{...t[u],variant:e}}))},onToolChange:Pn}):(0,X.jsxs)(X.Fragment,{children:[Dt?.has_initial_commit===!1&&(0,X.jsx)(Lne,{isSubmitting:_e,onCreateInitialCommit:()=>{cr()}}),(0,X.jsx)(Sge,{activeProjectId:y,activeProject:Dt,activeProjectBranchState:cn,targetBundles:fn,targetBranchSuggestions:mn,isTargetBundleLoading:pn,isTargetSelectorLoading:hn,onTargetSelectorOpenChange:mr,onSelectBundleTarget:vr,onSelectRepoRootTarget:yr,activeRun:x,activeTool:u,onOpenProjectExecutionSettings:()=>oi(`execution`),onRestoreSessionTarget:br,onChatReviewCapabilityChange:Ie,routedInspectionReviewCapability:At===`chat`?Fe:null,isPreviewButtonDisabled:bi,onPreviewReviewCapabilityChange:Pe,onPreviewToggle:_i,onRunStopped:fr,onWorkspaceActivityChange:Ee,onWorkspaceActivityEvent:En,pendingWorkspaceNavigation:Ce,onPendingWorkspaceNavigationConsumed:Qt,routedTicketId:c?.kind===`ticket`?c.ticketId:null,routedModalStack:r,onRoutedTicketOpen:ci,onRoutedTicketClose:li,onRoutedTicketUnavailable:zr,routedBundleId:c?.kind===`bundle`?c.bundleId:null,routedChatSessionId:c?.kind===`chat-session`?c.chatSessionId:void 0,routedSpecSessionId:c?.kind===`spec-session`||c?.kind===`spec-snapshot`?c.specSessionId:void 0,routedSpecSnapshotId:c?.kind===`spec-snapshot`?c.specSnapshotId:void 0,routedInspection:c?.kind===`ticket-inspection`?{target:{kind:`ticket`,ticketId:c.ticketId},mode:c.mode}:c?.kind===`bundle-inspection`?{target:{kind:`bundle`,bundleId:c.bundleId},mode:c.mode}:null,onRoutedBundleOpen:ui,onRoutedBundleClose:di,onRoutedInspectionOpen:fi,onRoutedInspectionModeChange:pi,onRoutedInspectionClose:mi,onChatSessionNavigation:hi,onSpecSessionNavigation:gi,onRoutedEntityUnavailable:zr,onSpecImplementationChatReady:Gt,onViewSourceSpec:Kt,onNavigateToLifecycleSource:Yt,onViewMemorySource:Jt,onStartChatFromBundle:xr,previewDisplayMode:_n,previewPane:xi,previewPaneWidth:B,previewButtonTitle:yi,visibleWorkspace:At,refreshKey:ke,boardFilterState:je,onBoardFilterStateChange:Me,onBoardLoadedProjectIdChange:w,onBundlesChange:rr,onBundlesLoadingChange:ir,onPreviewPaneWidthChange:V,onProjectUsageChange:Qn,onRunStatusChange:()=>{Mn(),Nn()}},y??`no-project`)]}),_.length>0&&(0,X.jsx)($y,{activeProject:Dt,activeRun:x,branchState:cn,targetGitStatus:ln,isBoardLoadedForActiveProject:on,activeProjectBranchAction:dn,isProjectIdeAvailable:an,isProjectRunAvailable:en,isRunStatusLoadedForActiveProject:sn,isTerminalOpen:qr.isOpen,targetBundles:fn,targetBranchSuggestions:mn,isTargetBundleLoading:pn,isTargetSelectorLoading:hn,isTargetGitStatusLoading:un,hasConfiguredTests:Jr,hasConfiguredChecks:Yr,onProjectIdeOpen:()=>{Or()},onProjectPull:()=>{kr()},onProjectRebase:Ar,onProjectAbortGitOperation:jr,onProjectRunToggle:()=>{Dr()},onProjectFilesOpen:()=>Mr(`files`),onProjectChangesOpen:()=>Mr(`changes`),onProjectVerificationOpen:Pr,onTerminalToggle:ni,onTargetSelectorOpenChange:mr,onSelectBundleTarget:vr,onSelectRepoRootTarget:yr,onManageBundles:Sr}),(0,X.jsx)(Dre,{activeProjectId:y,open:Ke,onOpenChange:J}),(qe||l)&&y&&!Rt&&(0,X.jsx)(p.Suspense,{fallback:null,children:(0,X.jsx)(Uge,{projectId:y,initialRunId:l?.runId??null,initialEventId:l?.eventId??null,onClose:Ir,onDetailsClose:Lr,onRunSelectionChange:Vr,onRelatedReferenceSelection:Gr,onUnavailable:c?.kind===`activity-run`?zr:void 0,onNavigateToLifecycleSource:Yt})}),Y&&y&&(0,X.jsx)(p.Suspense,{fallback:null,children:(0,X.jsx)(Hge,{projectId:y,defaultBranch:lt,onClose:()=>Qe(!1)})}),Ue&&Dt&&(0,X.jsx)(mC,{bundles:fn,selectedBundleId:Dt.active_target_kind===`bundle`?Dt.active_target_bundle_id??null:null,activeTargetBundleId:Dt.active_target_kind===`bundle`?Dt.active_target_bundle_id??null:null,onSelectBundle:wr,onCreateBundle:Tr,onDeleteBundle:Er,onClose:Cr}),ut&&(0,X.jsx)(nC,{title:ut.title,description:ut.description,confirmLabel:ut.confirmLabel,cancelLabel:ut.cancelLabel,confirmVariant:ut.confirmVariant,onConfirm:()=>gr(!0),onCancel:()=>gr(!1)}),_.map(e=>{let t=$7(ye,e.id);return t.hasMounted?(0,X.jsx)(Cge,{project:e,isExpanded:t.isExpanded,isVisible:e.id===y&&t.isOpen,onClose:()=>ri(e.id),onToggleExpanded:()=>ii(e.id)},e.id):null}),de&&(0,X.jsx)(eD,{activeTool:u,activeAgentName:f.find(e=>e.id===u)?.displayName??u,mode:de,initialSection:pe,projectId:de===`edit`&&Dt?Dt.id:null,availableHelperModels:St,isLoadingHelperModels:!Ct,onRetryValidationModels:Et,isAutoConfigReady:h,initialValues:de===`edit`&&Dt?qge(Dt,u):_.length===0?{name:``,repoPath:``,linkedProjectIds:[],runSetup:[],runServices:[],checkDefinitions:[],runIde:``,previewServiceName:``,previewPath:``,previewCapabilityMode:`auto`,helperModel:wt,helperVariant:Tt,helperModels:tw({},u,{model:wt||null,variant:wt&&Tt||null}),reviewerModels:{},commitMessageRules:``,commitAfterEachTicket:!1,autoParkStaleTickets:!1,memoryEnabled:!1,worktreeSync:[],specAwareCodeReviewEnabled:!1,automationDepth:`manual`,automationReviewFixEnabled:!1,automationPauseOnOpenQuestions:!1,automationReviewSeverity:`medium`,automationReviewMaxIterations:3}:void 0,linkedProjectOptions:_.filter(e=>e.id!==Dt?.id).map(e=>({id:e.id,name:e.name})),repoPathLocked:de===`edit`&&Dt?Dt.repo_path_locked:!1,repoPathLockedMessage:de===`edit`&&Dt?Yge(Dt):null,deleteBlockedMessage:de===`edit`&&Dt?Xge(Dt,_):null,onDelete:de===`edit`?Bn:void 0,onAutoConfig:ar,onBrowseRepoPath:or,onValidateRepoPath:sr,onOpenExecutionRuntimes:()=>Ze(!0),onExecutionProfileSaved:(e,t)=>{v(n=>n.map(n=>n.id===e?{...n,build_execution_provider:t}:n))},onClose:()=>fe(null),onSubmit:de===`edit`?zn:Rn}),Xe&&(0,X.jsx)(ux,{onClose:()=>Ze(!1)}),Nt&&Nt.projectId===y&&Dt&&cn?.status!==`loading`&&!Rt&&(0,X.jsx)(p.Suspense,{fallback:null,children:(0,X.jsx)(Bge,{target:{scope:`project_root`},initialMode:Nt.mode,reviewMode:Nt.mode,onReviewModeChange:pi,enabledModes:[`changes`,`files`],projectId:Nt.projectId,targetKind:`repo_root`,reviewCommentsBundleId:null,title:Dt.name,bundleTargetName:null,hasHelperModel:!!(Dt.helper_models?.[u]?.model??(u===`opencode`?Dt.helper_model:null)),repoRootDefaultBranch:mn.default_branch,onSubmitReviewPrompt:Xr?.submitPrompt,canSubmitReviewPrompt:ei,reviewSubmitDisabledReason:ti??void 0,canAddReviewComments:ei,canModifyChanges:!0,mode:Xr?.mode,onModeChange:Xr?.onModeChange,canToggleMode:!!Xr?.canSubmitReviewPrompt,isUpdatingMode:Xr?.isUpdatingMode??!1,onClose:Nr})}),he&&(!qe||c?.kind===`checks`)&&!Rt&&he.projectId===y&&(0,X.jsx)(p.Suspense,{fallback:null,children:(0,X.jsx)(Vge,{targetLabel:he.targetLabel,definitions:he.definitions,requiredDefinitionIds:he.requiredDefinitionIds,preReviewDefinitionIds:he.preReviewDefinitionIds,checksTarget:{projectId:he.projectId,targetKind:he.targetKind,targetBundleId:he.targetBundleId},requestedInitialTab:c?.kind===`checks`?`checks`:void 0,directBatchRunId:c?.kind===`checks`?c.batchRunId:null,directAttemptRunId:c?.kind===`checks`?c.attemptRunId:null,onCheckSelectionChange:c?.kind===`checks`?Kr:void 0,onUnavailable:c?.kind===`checks`?zr:void 0,testsTarget:{scope:`project`,projectId:he.projectId,targetKind:he.targetKind,targetBundleId:he.targetBundleId},onClose:Fr,onOpenActivity:()=>{if(yt.current+=1,ge(null),c?.kind===`checks`){r.some(e=>e.kind===`activity-run`)?(Je(!0),n(c)):(vt.current=!0,s({kind:`workspace`,projectId:c.projectId,workspace:`board`}));return}Je(!0)}})})]})},r9=`X-Archon-Mobile-CSRF`,l_e=async(e,t={})=>{let n=await fetch(e,{credentials:`include`,...t});if(!n.ok){let e=null;try{e=await n.clone().json()}catch{}throw new Ge(await Xe(n,`Mobile request failed.`),n.status,e)}return n},i9=async(e,t={})=>await(await l_e(e,t)).json(),a9=e=>i9(`/mobile/projects`,{signal:e}),u_e=e=>i9(`/mobile/tool`,{signal:e}),d_e=(e,t)=>i9(`/mobile/tool`,o9(t,{tool:e})),f_e=async e=>Vr(await i9(`/mobile/agents`,{signal:e,cache:`no-store`})),p_e=(e,t)=>i9(`/mobile/projects/${encodeURIComponent(e)}/summary`,{signal:t}),m_e=async(e,t)=>{let n=[],r=null;do{let i=r?`?cursor=${encodeURIComponent(r)}`:``,a=await i9(`/mobile/projects/${encodeURIComponent(e)}/approval-requests${i}`,{signal:t});n.push(...a.approval_requests),r=a.next_cursor}while(r);return{approval_requests:n,next_cursor:null}},h_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/approval-requests/${encodeURIComponent(t)}`,{signal:n}),g_e=(e,t,n,r,i)=>i9(`/mobile/projects/${encodeURIComponent(e)}/approval-requests/${encodeURIComponent(t.id)}/${n}`,o9(r,{expected_action_fingerprint:t.action_fingerprint,...i?.trim()?{reason:i.trim()}:{}})),__e=(e,t)=>i9(`/mobile/projects/${encodeURIComponent(e)}/target-options`,{signal:t}),v_e=(e,t)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions`,{signal:t}),y_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions/${encodeURIComponent(t)}`,{signal:n}),b_e=(e,t)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets`,{signal:t}),x_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}`,{signal:n}),S_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/agent-runs`,{signal:n}),C_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions/${encodeURIComponent(t)}/agent-runs`,{signal:n}),w_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions/${encodeURIComponent(t)}/agent-runs`,{signal:n}),T_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/bundles/${encodeURIComponent(t)}`,{signal:n}),E_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/bundles/${encodeURIComponent(t)}/build`,o9(n)),D_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/bundles/${encodeURIComponent(t)}/review`,o9(n)),o9=(e,t,n=`POST`)=>({method:n,headers:{"Content-Type":`application/json`,[r9]:e},body:t===void 0?void 0:JSON.stringify(t)}),O_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions`,o9(t,n)),k_e=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions/${encodeURIComponent(t)}/messages`,o9(n,r)),A_e=(e,t,n,r,i)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions/${encodeURIComponent(t)}/plan-questions/${encodeURIComponent(n)}/resolve`,o9(r,i)),j_e=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions/${encodeURIComponent(t)}`,o9(n,r,`PATCH`)),M_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions/${encodeURIComponent(t)}/stop`,o9(n)),N_e=(e,t)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions`,{signal:t}),P_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions/${encodeURIComponent(t)}`,{signal:n}),F_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions`,o9(t,n)),s9=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions/${encodeURIComponent(t)}/messages`,o9(n,r)),I_e=(e,t,n,r,i)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions/${encodeURIComponent(t)}/plan-questions/${encodeURIComponent(n)}/resolve`,o9(r,i)),L_e=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions/${encodeURIComponent(t)}`,o9(n,r,`PATCH`)),R_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions/${encodeURIComponent(t)}/stop`,o9(n)),c9=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/state`,o9(n,{state:r},`PATCH`)),z_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/run`,o9(n)),B_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/stop`,o9(n)),l9=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/stop-build`,o9(n)),u9=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/resume-build`,o9(n)),V_e=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}`,o9(n,r,`PATCH`)),H_e=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/plan-follow-up`,o9(n,{instruction:r})),U_e=(e,t,n,r,i)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/plan-questions/${encodeURIComponent(n)}/resolve`,o9(r,i)),W_e=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/follow-up`,o9(n,{instruction:r})),G_e=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/bundles/${encodeURIComponent(t)}/follow-up`,o9(n,{instruction:r})),d9=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/target`,o9(t,n)),K_e=(e,t)=>i9(`/mobile/models?tool=${encodeURIComponent(e)}`,{signal:t}),q_e=(e,t,n)=>{let r=new URLSearchParams({tool:e});return t&&r.set(`project_id`,t),i9(`/mobile/skills?${r.toString()}`,{signal:n})},J_e=({className:e})=>(0,X.jsx)(bg,{"aria-hidden":`true`,className:e}),f9=e=>qb.t(`common:mobileApp.${e}`),Y_e={key:`overview`,label:f9(`navigation.overview`),Icon:J_e},p9={key:`tickets`,label:f9(`navigation.tickets`),Icon:B5,ctaAriaLabel:f9(`overviewActions.ticketsAriaLabel`)},m9={key:`chats`,label:f9(`navigation.chats`),Icon:vD,ctaAriaLabel:f9(`overviewActions.chatsAriaLabel`)},h9={key:`spec`,label:f9(`navigation.spec`),Icon:JS,ctaAriaLabel:f9(`overviewActions.specAriaLabel`)},X_e=[Y_e,p9,m9,h9],Z_e=({children:e})=>(0,X.jsx)(`main`,{className:`min-h-screen bg-background text-foreground`,children:(0,X.jsx)(`div`,{className:`mx-auto flex min-h-screen w-full max-w-lg items-center px-4 py-8`,children:(0,X.jsx)(`div`,{className:`w-full`,children:e})})}),g9=({title:e,description:t,children:n})=>(0,X.jsx)(Z_e,{children:(0,X.jsxs)(iC,{className:`w-full border-border/80 bg-card/90 shadow-2xl shadow-black/20`,children:[(0,X.jsxs)(aC,{children:[(0,X.jsx)(oC,{children:e}),(0,X.jsx)(sC,{children:t})]}),n&&(0,X.jsx)(lC,{className:`space-y-4`,children:n})]})}),Q_e=e=>e===`connected`?{label:`Connected`,variant:`success`,indicatorState:`finished`}:e===`reconnecting`?{label:`Reconnecting`,variant:`warning`,indicatorState:`running`}:e===`unavailable`?{label:`Offline`,variant:`destructive`,indicatorState:`error`}:{label:`Connecting`,variant:`outline`,indicatorState:`running`},$_e=({status:e})=>{let t=Q_e(e);return(0,X.jsxs)(rC,{variant:t.variant,className:`gap-1.5 px-2.5 py-1 text-[11px] uppercase tracking-[0.14em]`,children:[(0,X.jsx)(ib,{state:t.indicatorState,className:`mt-0`}),t.label]})},eve=({status:e,onRetry:t})=>e===`connected`?null:e===`unavailable`?(0,X.jsx)(iC,{className:`border-red-500/25 bg-destructive/10 shadow-none`,children:(0,X.jsxs)(lC,{className:`flex flex-col gap-3 pt-5`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-red-100`,children:`Desktop Archon is currently unreachable.`}),(0,X.jsx)(`p`,{className:`text-sm text-red-200/85`,children:`Mobile access may have been disabled, the backend may have restarted, or this phone lost network access.`})]}),(0,X.jsx)(`div`,{children:(0,X.jsx)(Q,{variant:`warning`,onClick:t,children:`Retry connection`})})]})}):(0,X.jsx)(iC,{className:`border-amber-500/25 bg-amber-500/10 shadow-none`,children:(0,X.jsx)(lC,{className:`pt-5 text-sm text-amber-100`,children:e===`connecting`?`Connecting to live updates from desktop Archon...`:`Reconnecting to desktop Archon. Existing content stays visible while this phone reconnects.`})}),tve=({activeTool:e,agents:t,selectedProject:n,targetLabel:r,isTargetLoading:i,isTargetDisabled:a,connectionState:o,onOpenProjects:s,onOpenTargetSelector:c,onToolChange:l})=>(0,X.jsx)(`header`,{className:`sticky top-0 z-20 border-b border-border/70 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/85`,children:(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-6xl items-center justify-between gap-3 px-3 pb-3 pt-4 sm:px-4`,children:[(0,X.jsxs)(`button`,{type:`button`,"aria-label":`Choose project`,className:`min-w-0 flex-1 text-left`,onClick:s,children:[(0,X.jsx)(`div`,{className:`truncate text-base font-medium text-foreground`,children:n?.name??`Choose a project`}),(0,X.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:n?.repo_path??`Select a desktop project to continue`})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,X.jsx)(`select`,{"aria-label":qb.t(`common:mobileApp.agentSelector.ariaLabel`),className:`h-8 max-w-28 rounded-lg border border-border bg-background px-2 text-xs text-foreground outline-none focus-visible:ring-2 focus-visible:ring-ring`,value:e,onChange:e=>l(e.target.value),children:t.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.displayName},e.id))}),(0,X.jsx)($_e,{status:o}),(0,X.jsxs)(Q,{variant:`outline`,size:`sm`,"aria-label":`Choose target`,"data-testid":`mobile-target-trigger`,className:`h-8 max-w-32 gap-2 px-2.5 sm:max-w-40`,disabled:a,onClick:c,children:[(0,X.jsx)(zv,{className:`h-3.5 w-3.5 shrink-0`}),i?(0,X.jsx)(Sv,{className:`h-3.5 w-16`}):(0,X.jsx)(`span`,{className:`truncate text-xs sm:text-sm`,children:r})]}),(0,X.jsx)(Q,{variant:`outline`,size:`icon-sm`,"aria-label":`Choose project`,onClick:s,children:(0,X.jsx)(Tv,{className:`h-4 w-4`})})]})]})}),nve=({activeSection:e,onChange:t})=>(0,X.jsx)(`nav`,{className:`fixed inset-x-0 bottom-0 z-20 border-t border-border/70 bg-background/95 px-3 pb-[calc(env(safe-area-inset-bottom)+0.75rem)] pt-2 backdrop-blur supports-[backdrop-filter]:bg-background/85 sm:px-4 lg:hidden`,children:(0,X.jsx)(`div`,{className:`mx-auto flex max-w-6xl gap-2 overflow-x-auto [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,children:X_e.map(n=>{let r=n.key===e,i=n.Icon;return(0,X.jsxs)(Q,{type:`button`,variant:r?`secondary`:`ghost`,className:`h-11 shrink-0 gap-2 whitespace-nowrap`,"aria-current":r?`page`:void 0,onClick:()=>t(n.key),children:[(0,X.jsx)(i,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:n.label})]},n.key)})})}),_9=({title:e,description:t,action:n})=>(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none`,children:[(0,X.jsxs)(aC,{children:[(0,X.jsx)(oC,{children:e}),(0,X.jsx)(sC,{children:t})]}),n&&(0,X.jsx)(lC,{children:n})]}),v9=({text:e})=>(0,X.jsxs)(`div`,{"aria-live":`polite`,className:`flex items-center gap-2 px-1 py-3 text-sm text-muted-foreground`,role:`status`,children:[(0,X.jsx)(Ov,{className:`h-4 w-4 animate-spin`}),(0,X.jsx)(`span`,{children:e})]}),rve=e=>e?`Repo root (${e})`:`Repo root`,ive=e=>{if(!e)return`Repo root`;if(e.length<=20)return e;let t=e.split(`/`).filter(Boolean),n=t[t.length-1]??e;return n.length<=17?`.../${n}`:`${n.slice(0,16)}...`},y9=(e,t)=>{if(!e)return`Target`;if(e.active_target_kind===`bundle`&&e.active_target_bundle_id){let n=t?.bundles.find(t=>t.id===e.active_target_bundle_id)??null;return n?Jy(n):`Selected bundle`}return ive(t?.current_branch??null)},b9=({title:e,description:t,children:n})=>(0,X.jsxs)(`div`,{className:`flex max-h-[80vh] flex-col overflow-hidden`,children:[(0,X.jsxs)(W_,{className:`border-b border-border/70 px-4 py-4`,children:[(0,X.jsx)(K_,{children:e}),t&&(0,X.jsx)(q_,{children:t})]}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-4`,children:n})]}),ave=({projects:e,selectedProjectId:t,error:n,onSelectProject:r,onRetry:i})=>n?(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(`p`,{className:`text-sm text-red-200`,children:n}),(0,X.jsx)(Q,{variant:`warning`,onClick:i,children:`Retry projects`})]}):e?e.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No projects are available on the desktop instance yet.`}):(0,X.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>{let n=e.id===t;return(0,X.jsxs)(`button`,{type:`button`,className:Z(`w-full rounded-2xl border px-4 py-3 text-left transition-colors`,n?`border-primary/50 bg-primary/10`:`border-border/80 bg-card/60 hover:border-primary/30 hover:bg-accent/60`),onClick:()=>r(e.id),children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),(0,X.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.repo_path})]}),n&&(0,X.jsx)(rC,{variant:`info`,children:`Current`})]}),(0,X.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2 text-[11px] uppercase tracking-[0.14em] text-muted-foreground`,children:(0,X.jsxs)(`span`,{children:[e.ticket_count,` tickets`]})})]},e.id)})}):(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading projects...`}),ove=({open:e,projects:t,selectedProjectId:n,error:r,onOpenChange:i,onSelectProject:a,onRetry:o})=>(0,X.jsx)(V_,{open:e,onOpenChange:i,children:(0,X.jsx)(U_,{showCloseButton:!1,"aria-describedby":void 0,className:`top-auto right-0 bottom-0 left-0 max-w-none translate-x-0 translate-y-0 overflow-hidden rounded-t-3xl rounded-b-none border-x-0 border-b-0 p-0 sm:top-1/2 sm:right-auto sm:bottom-auto sm:left-1/2 sm:max-w-md sm:-translate-x-1/2 sm:-translate-y-1/2 sm:rounded-2xl sm:border sm:p-0`,children:(0,X.jsx)(b9,{title:`Projects`,children:(0,X.jsx)(ave,{projects:t,selectedProjectId:n,error:r,onSelectProject:e=>{a(e),i(!1)},onRetry:o})})})}),sve=({open:e,project:t,targetOptions:n,error:r,isLoading:i,isSubmitting:a,onOpenChange:o,onRetry:s,onSelectBundle:c,onSelectRepoRoot:l})=>{let[u,d]=(0,p.useState)(``);(0,p.useEffect)(()=>{e&&d(n?.current_branch??``)},[e,n?.current_branch]);let f=t?.active_target_kind!==`bundle`,m=Fy(n?.bundles??[]),h=[{key:`default`,label:`Default branch`,branch:n?.default_branch??null},{key:`previous`,label:`Previous branch`,branch:n?.previous_branch??null}].filter(e=>e.branch&&e.branch!==n?.current_branch).filter((e,t,n)=>n.findIndex(t=>t.branch===e.branch)===t),g=t?r?(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(`p`,{className:`text-sm text-red-200`,children:r}),(0,X.jsx)(Q,{variant:`warning`,onClick:s,children:`Retry target options`})]}):n?(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-sm font-semibold text-foreground`,children:`Project target`}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Choose the repo root or a prepared bundle for new chats and desktop work launched from this phone.`})]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(iv,{className:`text-xs font-medium text-muted-foreground`,children:`Target`}),(0,X.jsxs)(`div`,{className:`space-y-2 rounded-xl border border-border/70 bg-background/40 p-2`,children:[(0,X.jsx)(Q,{type:`button`,variant:f?`secondary`:`ghost`,className:`w-full justify-start`,disabled:a,onClick:()=>l(null),children:rve(n.current_branch)}),(0,X.jsxs)(`div`,{className:`relative min-h-10`,"data-testid":`mobile-target-options`,children:[i&&(0,X.jsx)(`div`,{className:`pointer-events-none absolute right-2 top-2 z-10 text-muted-foreground`,"data-testid":`mobile-target-options-spinner`,children:(0,X.jsx)(Ov,{className:`h-3.5 w-3.5 animate-spin`})}),(0,X.jsx)(`div`,{className:`max-h-40 overflow-y-auto pr-7`,children:m.length===0&&!i?(0,X.jsx)(`p`,{className:`px-2 py-2 text-xs text-muted-foreground`,children:`No prepared bundles are available yet.`}):m.map(e=>(0,X.jsx)(Q,{type:`button`,variant:t.active_target_kind===`bundle`&&t.active_target_bundle_id===e.id?`secondary`:`ghost`,className:`w-full justify-start`,disabled:a,onClick:()=>c(e.id),children:(0,X.jsx)(`span`,{className:`truncate`,children:Jy(e)})},e.id))})]})]})]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(iv,{className:`text-xs font-medium text-muted-foreground`,children:`Repo root branch`}),(0,X.jsxs)(`div`,{className:`space-y-2 rounded-xl border border-border/70 bg-background/40 p-3`,children:[(0,X.jsx)(`div`,{className:`space-y-2`,children:h.length>0?h.map(({key:e,label:t,branch:n})=>(0,X.jsxs)(Q,{type:`button`,variant:`outline`,className:`w-full justify-between gap-3`,disabled:!f||a||!n,onClick:()=>l(n),children:[(0,X.jsx)(`span`,{children:t}),(0,X.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:n})]},e)):(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i?`Loading branch suggestions...`:`No suggested branches available.`})}),(0,X.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,X.jsx)(iv,{htmlFor:`mobile-project-target-branch-input`,className:`text-xs text-muted-foreground`,children:`Switch or create branch`}),(0,X.jsx)(J_,{id:`mobile-project-target-branch-input`,value:u,disabled:!f||a,onChange:e=>d(e.target.value),placeholder:`feature/quick-fix`})]}),(0,X.jsx)(Q,{type:`button`,disabled:!f||!u.trim()||a,onClick:()=>l(u.trim()),children:`Switch`})]}),!f&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Switch to repo root to choose a branch.`})]})]})]}):(0,X.jsx)(v9,{text:`Loading target options...`}):(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Select a project before choosing a target.`});return(0,X.jsx)(V_,{open:e,onOpenChange:o,children:(0,X.jsx)(U_,{showCloseButton:!1,"aria-describedby":void 0,className:`top-auto right-0 bottom-0 left-0 max-w-none translate-x-0 translate-y-0 overflow-hidden rounded-t-3xl rounded-b-none border-x-0 border-b-0 p-0 sm:top-1/2 sm:right-auto sm:bottom-auto sm:left-1/2 sm:max-w-md sm:-translate-x-1/2 sm:-translate-y-1/2 sm:rounded-2xl sm:border sm:p-0`,children:(0,X.jsx)(b9,{title:`Target`,description:t?y9(t,n):void 0,children:g})})})},x9=e=>e.parked_at?`parked`:e.state,S9=e=>{let t=x9(e);return t===`parked`?`Done`:`${t.slice(0,1).toUpperCase()}${t.slice(1)}`},C9=e=>e===`plan`?`info`:e===`build`?`success`:e===`review`?`warning`:`outline`,w9=({ticket:e,isSelected:t,onSelectTicket:n,className:r})=>(0,X.jsxs)(`button`,{type:`button`,className:Z(`w-full rounded-2xl border px-4 py-3 text-left transition-colors`,t?`border-primary/50 bg-primary/10`:`border-border/70 bg-card/40 hover:border-primary/30 hover:bg-accent/50`,r),onClick:()=>n(e.id),children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e.title})}),(0,X.jsx)(rC,{variant:C9(x9(e)),children:S9(e)})]}),(0,X.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2 text-[11px] uppercase tracking-[0.14em] text-muted-foreground`,children:[e.agent_status&&(0,X.jsx)(`span`,{children:e.agent_status}),e.branch&&(0,X.jsx)(`span`,{children:e.branch}),e.bundle?.name&&(0,X.jsx)(`span`,{children:e.bundle.name})]})]}),cve=({group:e,selectedBundleId:t,selectedTicketId:n,onSelectBundle:r,onSelectTicket:i})=>{let a=e.bundle.id===t,o=e.tickets.some(e=>e.id===n),[s,c]=(0,p.useState)(o),l=Jy(e.bundle)||e.bundle.branch||e.bundle.name||`Bundle`,u=e.tickets.filter(e=>e.agent_status===`running`).length,d=a||o;return(0,p.useEffect)(()=>{o&&c(!0)},[o]),(0,X.jsxs)(SC,{open:s,onOpenChange:c,children:[(0,X.jsxs)(`div`,{className:Z(`flex items-start gap-2 rounded-2xl border px-4 py-3 transition-colors`,d?`border-primary/50 bg-primary/10`:`border-border/70 bg-card/40 hover:border-primary/30 hover:bg-accent/50`),children:[(0,X.jsx)(`button`,{type:`button`,className:`min-w-0 flex-1 text-left`,"aria-label":`Open bundle ${l}`,onClick:()=>r(e.bundle.id),children:(0,X.jsx)(`div`,{className:`flex items-start justify-between gap-3`,children:(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(rC,{variant:`outline`,children:`Bundle`}),(0,X.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:l})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[11px] uppercase tracking-[0.14em] text-muted-foreground`,children:[(0,X.jsxs)(`span`,{children:[e.tickets.length,` ticket`,e.tickets.length===1?``:`s`]}),u>0&&(0,X.jsxs)(`span`,{children:[u,` running`]}),e.bundle.branch&&(0,X.jsx)(`span`,{children:e.bundle.branch})]})]})})}),(0,X.jsx)(CC,{asChild:!0,children:(0,X.jsx)(Q,{type:`button`,variant:`ghost`,size:`icon-sm`,className:`mt-0.5 shrink-0`,"aria-label":`Toggle bundle tickets for ${l}`,children:(0,X.jsx)(bv,{className:Z(`h-4 w-4 transition-transform`,s&&`rotate-180`)})})})]}),(0,X.jsx)(wC,{className:`pt-2`,children:(0,X.jsx)(`div`,{className:`space-y-2 pl-3`,children:e.tickets.map(t=>(0,X.jsx)(w9,{ticket:t,isSelected:t.id===n,onSelectTicket:t=>i(t,e.bundle.id),className:`rounded-xl`},t.id))})})]})},T9=(e,t)=>Hy(e,[],t),lve=e=>[{key:`plan`,label:`Plan`,tickets:e.filter(e=>!e.parked_at&&e.state===`plan`),items:T9(e.filter(e=>!e.parked_at&&e.state===`plan`),`plan`)},{key:`build`,label:`Build`,tickets:e.filter(e=>!e.parked_at&&e.state===`build`),items:T9(e.filter(e=>!e.parked_at&&e.state===`build`),`build`)},{key:`review`,label:`Review`,tickets:e.filter(e=>!e.parked_at&&e.state===`review`),items:T9(e.filter(e=>!e.parked_at&&e.state===`review`),`review`)},{key:`parked`,label:`Done`,tickets:e.filter(e=>e.parked_at),items:T9(e.filter(e=>e.parked_at),`done`)}].filter(e=>e.tickets.length>0),E9=({selectedProjectId:e,tickets:t,selectedBundleId:n,selectedTicketId:r,error:i,onRetry:a,onSelectBundle:o,onSelectTicket:s})=>{if(!e)return(0,X.jsx)(_9,{title:`Choose a project`,description:`Select a project before browsing tickets from this phone.`});if(i)return(0,X.jsx)(_9,{title:`Tickets unavailable`,description:i,action:(0,X.jsx)(Q,{variant:`warning`,onClick:a,children:`Retry tickets`})});if(!t)return(0,X.jsx)(iC,{className:`border-border/80 bg-card/70 shadow-none`,children:(0,X.jsx)(lC,{className:`pt-5 text-sm text-muted-foreground`,children:`Loading tickets...`})});if(t.length===0)return(0,X.jsx)(_9,{title:`No tickets`,description:`This project does not have any tickets yet.`});let c=lve(t);return(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none lg:flex lg:min-h-0 lg:flex-col`,children:[(0,X.jsxs)(aC,{className:`border-b border-border/70 pb-4`,children:[(0,X.jsx)(oC,{children:`Tickets`}),(0,X.jsxs)(sC,{children:[t.length,` total`]})]}),(0,X.jsx)(lC,{className:`space-y-4 pt-5 lg:min-h-0 lg:flex-1 lg:overflow-y-auto`,children:c.map(e=>(0,X.jsxs)(`section`,{className:`space-y-2`,"aria-label":`${e.label} tickets`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground`,children:[(0,X.jsx)(`span`,{children:e.label}),(0,X.jsx)(`span`,{children:e.tickets.length})]}),(0,X.jsx)(`div`,{className:`space-y-2`,children:e.items.map(e=>e.kind===`bundle`?(0,X.jsx)(cve,{group:e.group,selectedBundleId:n,selectedTicketId:r,onSelectBundle:o,onSelectTicket:s},e.group.id):(0,X.jsx)(w9,{ticket:e.ticket,isSelected:e.ticket.id===r,onSelectTicket:e=>s(e,null)},e.ticket.id))})]},e.key))})]})},uve=e=>i9(`/mobile-auth/status`,{signal:e}),dve=(e,t)=>i9(`/mobile-auth/pair/preview`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:t}),fve=e=>i9(`/mobile-auth/pair`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}),pve=e=>i9(`/mobile-auth/logout`,{method:`POST`,headers:{[r9]:e}}),mve=()=>GS(window.location.origin,{withCredentials:!0}),D9=({label:e,value:t,mono:n=!1})=>t?(0,X.jsxs)(`div`,{className:`grid min-w-0 gap-1 border-b border-border/50 py-2 last:border-0`,children:[(0,X.jsx)(`dt`,{className:`text-xs text-muted-foreground`,children:e}),(0,X.jsx)(`dd`,{className:n?`min-w-0 break-all font-mono text-xs text-foreground`:`min-w-0 break-words text-sm text-foreground`,children:t})]}):null,hve=({projectId:e,csrfToken:t,socket:n,initialRequests:r,onRequestError:i})=>{let{t:a,i18n:o}=q(`common`,{keyPrefix:`mobileApp.approvals`}),[s,c]=(0,p.useState)(r),[l,u]=(0,p.useState)(null),[d,f]=(0,p.useState)(null),[m,h]=(0,p.useState)(!1),[g,_]=(0,p.useState)(``),[v,y]=(0,p.useState)(null),[b,x]=(0,p.useState)(null),[S,C]=(0,p.useState)(!1),[w,T]=(0,p.useState)(0),E=(0,p.useRef)(r);E.current=r;let D=l?`${e}:${l}`:null,O=(0,p.useRef)(D);O.current=D;let k=(0,p.useRef)(!0);(0,p.useEffect)(()=>(k.current=!0,()=>{k.current=!1}),[]),(0,p.useEffect)(()=>{c(E.current),u(null)},[e]),(0,p.useEffect)(()=>{let t=new AbortController,n=e;return m_e(e,t.signal).then(r=>{if(t.signal.aborted||n!==e)return;let i=r?.approval_requests??[];c(i),u(e=>e&&i.some(t=>t.id===e)?e:null),y(null)}).catch(e=>{Ye(e)||i(e)||y(e instanceof Ge?e.message:a(`loadError`))}),()=>t.abort()},[i,e,w,a]),(0,p.useEffect)(()=>{if(f(null),_(``),C(!1),x(null),!l){h(!1);return}let t=new AbortController,n=`${e}:${l}`;return h(!0),h_e(e,l,t.signal).then(t=>{O.current===n&&t.approval_request.project_id===e&&t.approval_request.id===l&&f(t)}).catch(e=>{if(!Ye(e)&&O.current===n){if(i(e))return;x(e instanceof Ge?e.message:a(`detailError`))}}).finally(()=>{!t.signal.aborted&&O.current===n&&h(!1)}),()=>t.abort()},[i,e,w,l,a]),(0,p.useEffect)(()=>{if(!n)return;let t=t=>{t&&typeof t==`object`&&`project_id`in t&&t.project_id!==e||T(e=>e+1)};return n.on(`approval-request:created`,t),n.on(`approval-request:updated`,t),n.on(`connect`,t),()=>{n.off(`approval-request:created`,t),n.off(`approval-request:updated`,t),n.off(`connect`,t)}},[e,n]);let A=d?.approval_request.project_id===e&&d.approval_request.id===l?d.approval_request:null,j=A?.action.kind===`custom_check`?A.action.target.batch_environment:A?.authority.environment,M=A?.action.kind===`custom_check`?A.action.target.attempt_placement:A?.authority.execution_boundary?.attempt_placement,N=A?.action.kind===`git_push`?A.action.target.degradations??[]:[],P=async n=>{if(!A||S)return;let r=`${e}:${A.id}`;C(!0),x(null);try{if(await g_e(e,A,n,t,g),!k.current||O.current!==r)return;_(``),T(e=>e+1)}catch(e){if(!k.current||O.current!==r||i(e))return;let t=Ke(e,`approval_request`);t&&(c(e=>e.map(e=>e.id===t.id?t:e).filter(e=>e.status===`pending`)),f(e=>e&&e.approval_request.id===t.id?{...e,approval_request:t}:e)),x(e instanceof Ge?e.message:a(`decisionError`))}finally{k.current&&O.current===r&&C(!1)}};return s.length===0&&!v&&!A&&!b?null:(0,X.jsxs)(`section`,{"aria-labelledby":`mobile-approvals-title`,className:`rounded-2xl border border-amber-300/30 bg-amber-500/5 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{id:`mobile-approvals-title`,className:`font-semibold text-foreground`,children:a(`title`)}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:a(`count`,{count:s.length})})]}),(0,X.jsx)(`span`,{className:`rounded-full bg-amber-400/15 px-2.5 py-1 text-sm font-semibold text-amber-100`,children:s.length})]}),v&&(0,X.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-red-200`,children:v}),(0,X.jsx)(`div`,{className:`mt-3 space-y-2`,children:s.map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>u(e.id),className:`w-full rounded-xl border border-border bg-card/70 p-3 text-left outline-none focus:ring-2 focus:ring-ring/50`,children:[(0,X.jsx)(`span`,{className:`block text-sm font-medium text-foreground`,children:a(`action.${e.action_kind}`)}),(0,X.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:a(`expires`,{value:new Intl.DateTimeFormat(o.language,{dateStyle:`short`,timeStyle:`short`}).format(new Date(e.expires_at))})})]},e.id))}),l&&m&&(0,X.jsx)(`p`,{className:`mt-4 border-t border-border/60 pt-4 text-sm text-muted-foreground`,children:a(`loadingDetail`)}),l&&b&&(0,X.jsx)(`p`,{role:`alert`,className:`mt-4 border-t border-border/60 pt-4 text-sm text-red-200`,children:b}),A&&(0,X.jsxs)(`div`,{className:`mt-4 border-t border-border/60 pt-4`,children:[(0,X.jsx)(`p`,{className:`text-sm text-foreground`,children:a(`impact.${A.action_kind}`)}),(0,X.jsxs)(`dl`,{className:`mt-3 max-h-72 overflow-y-auto rounded-xl border border-border/60 bg-background/35 px-3`,children:[(0,X.jsx)(D9,{label:a(`fields.action`),value:a(`action.${A.action_kind}`)}),(0,X.jsx)(D9,{label:a(`fields.target`),value:A.action.kind===`git_push`?`${A.action.target.remote_name} ${A.action.target.ref}`:`${A.action.target.scope_kind} ${A.action.target.scope_id}`}),(0,X.jsx)(D9,{label:a(`fields.command`),value:A.action.kind===`custom_check`?A.action.target.effective_command??A.action.target.definition_snapshot?.command:null,mono:!0}),(0,X.jsx)(D9,{label:a(`fields.cwd`),value:A.action.kind===`custom_check`?A.action.target.effective_cwd??A.action.workspace_git.workspace_path:A.action.workspace_git.workspace_path,mono:!0}),(0,X.jsx)(D9,{label:a(`fields.branch`),value:A.action.workspace_git.branch}),(0,X.jsx)(D9,{label:a(`fields.head`),value:A.action.workspace_git.head_sha,mono:!0}),(0,X.jsx)(D9,{label:a(`fields.remoteHead`),value:A.action.workspace_git.remote_head_sha,mono:!0}),(0,X.jsx)(D9,{label:a(`fields.profile`),value:A.authority.selected_profile?`${A.authority.selected_profile.revision_id} (r${A.authority.selected_profile.revision})`:null}),(0,X.jsx)(D9,{label:a(`fields.launcher`),value:A.action.kind===`custom_check`&&A.action.target.launcher?a(`values.launcher.${A.action.target.launcher}`):null}),(0,X.jsx)(D9,{label:a(`fields.environment`),value:j?`${j.id} (r${j.revision})`:A.authority.execution_boundary?.placement===`host`?a(`values.noHostEnvironment`):a(`none`),mono:!!j}),(0,X.jsx)(D9,{label:a(`fields.placement`),value:A.authority.execution_boundary?.placement===`host`?a(`values.hostPlacement`):M?.scope.kind===`exact-sandbox`?a(`values.sandboxPlacement`,{id:M.scope.externalId}):a(`values.sandboxPlacementUnavailable`),mono:!!M}),(0,X.jsx)(D9,{label:a(`fields.authority`),value:A.authority.effective_capabilities.join(`, `)||a(`none`)}),(0,X.jsx)(D9,{label:a(`fields.degradations`),value:N.join(`, `)}),(0,X.jsx)(D9,{label:a(`fields.secrets`),value:A.action.logical_secret_references.join(`, `)||a(`none`)}),(0,X.jsx)(D9,{label:a(`fields.expires`),value:new Intl.DateTimeFormat(o.language,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(A.expires_at))})]}),(0,X.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:a(`history`,{count:d?.events.length??0})}),!!d?.events.length&&(0,X.jsx)(`ol`,{className:`mt-2 max-h-36 space-y-1 overflow-y-auto text-xs text-muted-foreground`,children:d.events.map(e=>(0,X.jsxs)(`li`,{children:[a(`status.${e.to_status}`),` · `,new Intl.DateTimeFormat(o.language,{dateStyle:`short`,timeStyle:`short`}).format(new Date(e.created_at)),e.reason?` · ${e.reason}`:``]},e.id))}),A.status!==`pending`&&(0,X.jsx)(`p`,{className:`mt-3 text-sm text-muted-foreground`,children:a(`remediation.${A.status}`)}),A.status===`pending`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`label`,{className:`mt-3 block text-xs text-muted-foreground`,htmlFor:`mobile-approval-reason-${A.id}`,children:a(`reason`)}),(0,X.jsx)(`textarea`,{id:`mobile-approval-reason-${A.id}`,rows:2,maxLength:2e3,value:g,onChange:e=>_(c4(e.target.value)),className:`mt-1 w-full rounded-xl border border-border bg-card px-3 py-2 text-sm text-foreground outline-none focus:ring-2 focus:ring-ring/50`}),(0,X.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,X.jsx)(Q,{disabled:S,onClick:()=>void P(`approve`),children:a(`approve`)}),(0,X.jsx)(Q,{variant:`outline`,disabled:S,onClick:()=>void P(`deny`),children:a(`deny`)}),(0,X.jsx)(Q,{variant:`ghost`,disabled:S,onClick:()=>void P(`cancel`),children:a(`cancel`)})]})]})]})]})},O9=e=>qb.t(`common:mobileApp.${e}`),k9=({selectedProjectId:e,chatSessions:t,selectedChatSessionId:n,error:r,onRetry:i,onOpenNewChat:a,onSelectChat:o})=>e?r?(0,X.jsx)(_9,{title:`Chats unavailable`,description:r,action:(0,X.jsx)(Q,{variant:`warning`,onClick:i,children:`Retry chats`})}):(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none lg:flex lg:min-h-0 lg:flex-col`,children:[(0,X.jsxs)(aC,{className:`border-b border-border/70 pb-4`,children:[(0,X.jsx)(oC,{children:`Chats`}),(0,X.jsx)(sC,{children:t?`${t.length} recent`:`Loading chats...`}),(0,X.jsx)(cC,{children:(0,X.jsx)(Q,{variant:`outline`,size:`sm`,onClick:a,children:`New chat`})})]}),(0,X.jsx)(lC,{className:`space-y-2 pt-5 lg:min-h-0 lg:flex-1 lg:overflow-y-auto`,children:t?t.length===0?(0,X.jsx)(_9,{title:`No chats`,description:`Start a new chat to plan or build from this project.`,action:(0,X.jsx)(Q,{onClick:a,children:`Start a chat`})}):t.map(e=>(0,X.jsx)(`button`,{type:`button`,className:Z(`w-full rounded-xl border px-3 py-2.5 text-left transition-colors`,e.id===n?`border-primary/50 bg-primary/10`:`border-border/70 bg-card/40 hover:border-primary/30 hover:bg-accent/50`),onClick:()=>o(e.id),children:(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1 pr-2 text-sm font-medium text-foreground line-clamp-2 break-words`,children:e.title}),(0,X.jsx)(rC,{variant:e.agent_status===`running`?`warning`:e.mode===`plan`?`info`:`success`,children:e.agent_status??e.mode})]})},e.id)):(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading chats...`})})]}):(0,X.jsx)(_9,{title:`Choose a project`,description:`Select a project before browsing chats from this phone.`}),A9=({selectedProjectId:e,specSessions:t,selectedSpecSessionId:n,error:r,onRetry:i,onOpenNewSpec:a,onSelectSpec:o})=>e?r?(0,X.jsx)(_9,{title:O9(`specList.listError`),description:r,action:(0,X.jsx)(Q,{variant:`warning`,onClick:i,children:O9(`specList.retry`)})}):(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none lg:flex lg:min-h-0 lg:flex-col`,children:[(0,X.jsxs)(aC,{className:`border-b border-border/70 pb-4`,children:[(0,X.jsx)(oC,{children:O9(`specList.title`)}),(0,X.jsx)(sC,{children:t?`${t.length} recent`:O9(`specList.loading`)}),(0,X.jsx)(cC,{children:(0,X.jsx)(Q,{variant:`outline`,size:`sm`,onClick:a,children:O9(`specList.newSpec`)})})]}),(0,X.jsx)(lC,{className:`space-y-2 pt-5 lg:min-h-0 lg:flex-1 lg:overflow-y-auto`,children:t?t.length===0?(0,X.jsx)(_9,{title:O9(`specList.emptyTitle`),description:O9(`specList.emptyDescription`),action:(0,X.jsx)(Q,{onClick:a,children:O9(`specList.startSpec`)})}):t.map(e=>(0,X.jsx)(`button`,{type:`button`,className:Z(`w-full rounded-xl border px-3 py-2.5 text-left transition-colors`,e.id===n?`border-primary/50 bg-primary/10`:`border-border/70 bg-card/40 hover:border-primary/30 hover:bg-accent/50`),onClick:()=>o(e.id),children:(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1 pr-2 text-sm font-medium text-foreground line-clamp-2 break-words`,children:e.title}),(0,X.jsx)(rC,{variant:e.agent_status===`running`?`warning`:e.mode===`grill`?`info`:`success`,children:e.agent_status??e.mode})]})},e.id)):(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:O9(`specList.loading`)})})]}):(0,X.jsx)(_9,{title:O9(`specList.emptyTitle`),description:`Select a project before browsing specs from this phone.`}),j9=e=>{let t=e.tickets.filter(e=>!e.parked_at),n=t.filter(e=>e.state===`plan`),r=t.filter(e=>e.state===`build`),i=t.filter(e=>e.state===`review`),a=t.some(e=>e.agent_status===`running`),o=t.find(e=>my(e)&&e.agent_status===`running`&&!!e.session_id)??null,s=t.find(e=>my(e)&&e.agent_status===`stopped`&&!!e.session_id)??null,c=[];n.length>0&&c.push({id:`build`,label:`Build Bundle`,pendingLabel:`Building Bundle...`,ariaLabel:`Build Bundle`,disabled:!1,disabledReason:null});let l=r.length>0&&r.every(e=>e.agent_status===`done`),u=r.length===0&&i.length>0&&e.can_re_review===!0&&!a;return(l||u)&&c.push({id:`review`,label:u?`Re-run review`:`Review Bundle`,pendingLabel:`Reviewing Bundle...`,ariaLabel:u?`Re-run review`:`Review Bundle`,disabled:!1,disabledReason:null}),o&&c.push({id:`pause-build`,label:`Pause Build`,pendingLabel:`Pausing Build...`,ariaLabel:`Pause Build`,title:`Pause the build session. You can resume it later.`,disabled:!1,disabledReason:null}),!o&&s&&c.push({id:`resume-build`,label:`Resume`,pendingLabel:`Resuming...`,ariaLabel:`Resume`,disabled:!1,disabledReason:null}),{actions:c,runningBuildTicketId:o?.id??null,resumableBuildTicketId:s?.id??null}},M9=e=>[...e??[]].reverse().find(e=>e.metadata?.ask_question?.status===`pending`)??null,gve=({className:e})=>(0,X.jsx)(Tg,{"aria-hidden":`true`,className:e}),_ve=()=>{let[e,t]=(0,p.useState)(()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(min-width: 1024px)`).matches);return(0,p.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(min-width: 1024px)`),n=n=>{t(n?.matches??e.matches)};return n(),typeof e.addEventListener==`function`?(e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)):(e.addListener(n),()=>e.removeListener(n))},[]),e},N9=({label:e,value:t,accentClassName:n})=>(0,X.jsxs)(`div`,{className:`rounded-2xl border border-border/70 bg-card/70 p-3`,children:[(0,X.jsx)(`div`,{className:Z(`text-xl font-semibold text-foreground`,n),children:t}),(0,X.jsx)(`div`,{className:`mt-1 text-xs uppercase tracking-[0.14em] text-muted-foreground`,children:e})]}),P9=()=>(0,X.jsxs)(`div`,{className:`space-y-3`,"data-testid":`mobile-overview-skeleton`,children:[(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none`,children:[(0,X.jsx)(aC,{className:`border-b border-border/70 pb-4`,children:(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,X.jsx)(Sv,{className:`h-6 w-28`}),(0,X.jsx)(Sv,{className:`h-6 w-28 rounded-full`})]})}),(0,X.jsxs)(lC,{className:`space-y-4 pt-5`,children:[(0,X.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3`,children:Array.from({length:6},(e,t)=>(0,X.jsxs)(`div`,{className:`rounded-2xl border border-border/70 bg-card/70 p-3`,children:[(0,X.jsx)(Sv,{className:`h-6 w-10`}),(0,X.jsx)(Sv,{className:`mt-2 h-3 w-16`})]},t))}),(0,X.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,X.jsx)(Sv,{className:`h-10 w-full rounded-xl`}),(0,X.jsx)(Sv,{className:`h-10 w-full rounded-xl`})]})]})]}),(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none`,children:[(0,X.jsx)(aC,{children:(0,X.jsx)(Sv,{className:`h-6 w-20`})}),(0,X.jsx)(lC,{children:(0,X.jsx)(Sv,{className:`h-10 w-40 rounded-xl`})})]})]}),vve=({isLoggingOut:e,onLogout:t})=>(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none`,children:[(0,X.jsx)(aC,{children:(0,X.jsx)(oC,{children:`Session`})}),(0,X.jsx)(lC,{children:(0,X.jsxs)(Q,{variant:`destructive`,className:`gap-2`,disabled:e,onClick:t,children:[(0,X.jsx)(gve,{className:`h-4 w-4`}),e?`Logging out...`:`Log out this phone`]})})]}),yve=({activeRun:e,tickets:t,chatSessions:n,chatSessionDetail:r})=>{let i=r?.agent_status===`running`||!!n?.some(e=>e.agent_status===`running`);if(e?.kind===`ticket`)return{label:`Ticket run active`,variant:`success`};if(i)return{label:`Chat active`,variant:`success`};if(e)return{label:`Project run active`,variant:`success`};let a=t?.filter(e=>e.agent_status===`running`&&e.parked_at===null)??[],o=gF(a.filter(e=>e.state===`review`));return o===`building`?{label:qb.t(`common:statusBadge.building`),variant:`success`}:o===`reviewing`?{label:qb.t(`common:statusBadge.reviewing`),variant:`warning`}:a.some(e=>e.state===`build`)?{label:qb.t(`common:statusBadge.building`),variant:`success`}:a.some(e=>e.state===`plan`)?{label:`Planning`,variant:`info`}:{label:`Idle`,variant:`outline`}},bve=({activeRun:e,tickets:t,chatSessions:n,chatSessionDetail:r})=>{let i=yve({activeRun:e,tickets:t,chatSessions:n,chatSessionDetail:r});return(0,X.jsx)(rC,{variant:i.variant,children:i.label})},xve=({selectedProjectId:e,summary:t,tickets:n,error:r,chatSessions:i,chatSessionDetail:a,onRetry:o,onOpenTickets:s,onOpenChats:c,onOpenSpec:l})=>{let u=p9.Icon,d=m9.Icon,f=h9.Icon;return r?(0,X.jsx)(_9,{title:`Project summary unavailable`,description:r,action:(0,X.jsx)(Q,{variant:`warning`,onClick:o,children:`Retry summary`})}):e?!t||t.project.id!==e?(0,X.jsx)(iC,{className:`border-border/80 bg-card/70 shadow-none`,children:(0,X.jsx)(lC,{className:`pt-5 text-sm text-muted-foreground`,children:`Loading project summary...`})}):(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none`,children:[(0,X.jsxs)(aC,{className:`border-b border-border/70 pb-4`,children:[(0,X.jsx)(oC,{children:`Overview`}),(0,X.jsx)(cC,{children:(0,X.jsx)(bve,{activeRun:t.active_run,tickets:n,chatSessions:i,chatSessionDetail:a})})]}),(0,X.jsxs)(lC,{className:`space-y-4 pt-5`,children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3`,children:[(0,X.jsx)(N9,{label:`Tickets`,value:t.tickets.total}),(0,X.jsx)(N9,{label:`Plan`,value:t.tickets.plan,accentClassName:`text-sky-200`}),(0,X.jsx)(N9,{label:`Build`,value:t.tickets.build,accentClassName:`text-emerald-200`}),(0,X.jsx)(N9,{label:`Review`,value:t.tickets.review,accentClassName:`text-amber-200`}),(0,X.jsx)(N9,{label:`Done`,value:t.tickets.parked}),(0,X.jsx)(N9,{label:`Bundles`,value:t.project.bundle_count??0})]}),(0,X.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,X.jsxs)(Q,{variant:`outline`,className:`gap-2`,"aria-label":p9.ctaAriaLabel,onClick:s,children:[(0,X.jsx)(u,{className:`h-4 w-4`}),p9.label]}),(0,X.jsxs)(Q,{variant:`outline`,className:`gap-2`,"aria-label":m9.ctaAriaLabel,onClick:c,children:[(0,X.jsx)(d,{className:`h-4 w-4`}),m9.label]}),(0,X.jsxs)(Q,{variant:`outline`,className:`gap-2 sm:col-span-2`,"aria-label":h9.ctaAriaLabel,onClick:l,children:[(0,X.jsx)(f,{className:`h-4 w-4`}),h9.label]})]})]})]}):(0,X.jsx)(_9,{title:`Choose a project`,description:`Select a desktop project before opening tickets or chats from this phone.`})},Sve=({ticket:e})=>{let t=[{label:`State`,value:S9(e)},{label:`Tool`,value:yF(e,`opencode`)},{label:`Agent`,value:e.agent_status},{label:`Branch`,value:e.branch},{label:`Bundle`,value:e.bundle?.name??null},{label:`Model`,value:e.tool===`opencode`?e.model:null},{label:`Variant`,value:e.tool===`opencode`?e.variant:null}].filter(e=>!!e.value);return t.length===0?null:(0,X.jsxs)(`div`,{className:`min-w-0 space-y-2 rounded-xl border border-border/70 bg-background/40 px-3 py-3`,children:[(0,X.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,children:`Details`}),(0,X.jsx)(`dl`,{className:`grid gap-2 text-sm sm:grid-cols-2`,children:t.map(e=>(0,X.jsxs)(`div`,{className:`space-y-1 rounded-lg border border-border/60 bg-background/50 px-3 py-2`,children:[(0,X.jsx)(`dt`,{className:`text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,children:e.label}),(0,X.jsx)(`dd`,{className:`break-words text-foreground`,children:e.value})]},e.label))})]})},F9=({label:e,disabled:t,onClick:n})=>(0,X.jsx)(Q,{type:`button`,variant:`outline`,disabled:t,onClick:n,children:e}),Cve=({ticket:e,actionState:t,actionError:n,onAction:r})=>{let i=l3(e,{reviewLabel:e.worktree_bundle_id===null?`Review`:`Review Bundle`}),a=e.worktree_bundle_id===null&&e.state===`review`&&e.can_re_review===!0&&e.agent_status!==`running`&&!e.parked_at?[{id:`review`,label:`Re-run review`,pendingLabel:`Re-running review...`,ariaLabel:`Re-run review`,disabled:!1,disabledReason:null},...i]:i;return a.length===0?null:(0,X.jsx)(i4,{actions:a,activeAction:t,disableWhenActive:!0,className:`space-y-3`,heading:`Actions`,headingClassName:`text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,actionsClassName:`flex flex-wrap gap-2`,showDisabledReason:!0,disabledReasonClassName:`text-sm text-amber-200`,error:n,errorClassName:`text-sm text-red-200`,renderAction:({action:e,label:t,disabled:n})=>(0,X.jsx)(F9,{label:t,disabled:n,onClick:()=>r(e.id)},e.id)})},wve=({bundleDetail:e,actionState:t,actionError:n,onAction:r})=>{let{actions:i}=j9(e);return i.length===0?null:(0,X.jsx)(i4,{actions:i,activeAction:t,disableWhenActive:!0,className:`space-y-3`,heading:`Actions`,headingClassName:`text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,actionsClassName:`flex flex-wrap gap-2`,error:n,errorClassName:`text-sm text-red-200`,renderAction:({action:e,label:t,disabled:n})=>(0,X.jsx)(F9,{label:t,disabled:n,onClick:()=>r(e.id)},e.id)})},I9=(e,t)=>(e??[]).map(e=>({id:e.id,role:e.role,kind:e.kind,content:e.content,created_at:e.created_at,ticket_id:t??null,ticket_proposals:`ticket_proposals`in e?e.ticket_proposals??null:null,metadata:e.metadata,responseTiming:e.response_timing?KK(e.response_timing):null,transcript_runs:e.transcript_runs??null})),L9=({title:e,subtitle:t,badges:n,backLabel:r,onBack:i,action:a})=>(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[i?(0,X.jsxs)(Q,{variant:`ghost`,size:`sm`,className:`h-8 px-2.5 lg:hidden`,"aria-label":r,onClick:i,children:[(0,X.jsx)(cF,{className:`h-4 w-4`}),`Back`]}):null,(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e}),t?(0,X.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:t}):null]})]}),a?(0,X.jsx)(`div`,{className:`shrink-0`,children:a}):null]}),n?(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:n}):null]}),Tve=({title:e,backLabel:t,onBack:n,action:r})=>(0,X.jsxs)(`div`,{className:`-mx-3 flex shrink-0 items-center justify-between gap-3 border-b border-border/80 bg-background/95 px-3 py-2.5 backdrop-blur supports-[backdrop-filter]:bg-background/85 sm:-mx-4 sm:px-4 lg:hidden`,children:[(0,X.jsxs)(Q,{variant:`ghost`,size:`sm`,className:`h-8 px-2.5`,"aria-label":t,onClick:n,children:[(0,X.jsx)(cF,{className:`h-4 w-4`}),`Back`]}),(0,X.jsx)(`div`,{className:`min-w-0 flex-1 truncate text-sm font-medium text-foreground`,children:e}),(0,X.jsx)(`div`,{className:`shrink-0`,children:r})]}),R9=({title:e,backLabel:t,onBack:n,action:r,subheader:i,children:a})=>(0,X.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,X.jsx)(Tve,{title:e,backLabel:t,onBack:n,action:r}),i?(0,X.jsx)(`div`,{className:`shrink-0 border-b border-border/70 py-2 lg:hidden`,children:i}):null,(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:a})]}),z9=({value:e,onTranscript:t,onDetails:n})=>(0,X.jsxs)(`div`,{className:`flex gap-2 px-3 sm:px-0`,children:[(0,X.jsx)(Q,{type:`button`,variant:e===`transcript`?`secondary`:`ghost`,className:`h-9 flex-1`,"aria-pressed":e===`transcript`,onClick:t,children:`Transcript`}),(0,X.jsx)(Q,{type:`button`,variant:e===`details`?`secondary`:`ghost`,className:`h-9 flex-1`,"aria-pressed":e===`details`,onClick:n,children:`Details`})]}),B9=({controls:e})=>{let[t,n]=(0,p.useState)(!1);return(0,X.jsxs)(SC,{open:t,onOpenChange:n,children:[(0,X.jsx)(`div`,{className:`px-1 pb-1`,children:(0,X.jsx)(CC,{asChild:!0,children:(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 gap-1.5 px-2 text-xs text-muted-foreground`,children:[`Options`,(0,X.jsx)(bv,{className:Z(`h-3.5 w-3.5 transition-transform`,t&&`rotate-180`)})]})})}),(0,X.jsx)(wC,{className:`px-1 pb-1`,children:(0,X.jsx)(`div`,{className:`rounded-lg border border-border/70 bg-background/35 p-2`,children:e})})]})},V9=({ticket:e,badges:t,actionState:n,actionError:r,onAction:i,className:a})=>(0,X.jsxs)(iC,{className:Z(`flex min-h-0 min-w-0 flex-col border-border/80 bg-card/70 shadow-none`,a),children:[(0,X.jsx)(aC,{className:`min-w-0 pb-3`,children:(0,X.jsx)(L9,{title:e.title,badges:t})}),(0,X.jsxs)(lC,{className:`min-h-0 min-w-0 flex-1 space-y-3 overflow-y-auto pt-0`,children:[(0,X.jsx)(Cve,{ticket:e,actionState:n,actionError:r,onAction:i}),e.description?(0,X.jsxs)(`div`,{className:`min-w-0 space-y-2 rounded-xl border border-border/70 bg-background/40 px-3 py-3`,children:[(0,X.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,children:`Description`}),(0,X.jsx)(GK,{content:e.description,className:`min-w-0 text-foreground`})]}):null,(0,X.jsx)(Sve,{ticket:e})]})]}),H9=({bundleDetail:e,title:t,subtitle:n,badges:r,actionState:i,actionError:a,onAction:o,orderedTickets:s,highlightedTicketId:c,isTicketListOpen:l,onTicketListOpenChange:u,onSelectTicket:d,className:f,availableModels:p})=>(0,X.jsxs)(iC,{className:Z(`flex min-h-0 min-w-0 flex-col border-border/80 bg-card/70 shadow-none`,f),children:[(0,X.jsx)(aC,{className:`min-w-0 pb-3`,children:(0,X.jsx)(L9,{title:t,subtitle:n,badges:r})}),(0,X.jsxs)(lC,{className:`min-h-0 min-w-0 flex-1 space-y-3 overflow-y-auto pt-0`,children:[(0,X.jsx)(wve,{bundleDetail:e,actionState:i,actionError:a,onAction:o}),(0,X.jsxs)(SC,{open:l,onOpenChange:u,children:[(0,X.jsx)(CC,{asChild:!0,children:(0,X.jsxs)(Q,{type:`button`,variant:`ghost`,className:`h-8 gap-1.5 px-2 text-xs text-muted-foreground`,children:[`Tickets`,(0,X.jsx)(bv,{className:Z(`h-3.5 w-3.5 transition-transform`,l&&`rotate-180`)})]})}),(0,X.jsx)(wC,{className:`pt-2`,children:(0,X.jsx)(`div`,{className:`rounded-xl border border-border/70 bg-background/35 p-3`,children:(0,X.jsx)(v3,{tickets:s,highlightedTicketId:c,onOpenTicketDetails:e=>d(e.id,e.worktree_bundle_id),availableModels:p})})})]})]})]}),U9=({selectedProjectId:e,bundleId:t,bundleDetail:n,openNonce:r,mobileDetailView:i,error:a,actionState:o,actionError:s,followUpPrompt:c,isSendingFollowUp:l,followUpError:u,availableModels:d,onBack:f,onRetry:m,onAction:h,onDetailViewChange:g,onSelectTicket:_,onFollowUpPromptChange:v,onFollowUpKeyDown:y,onFollowUpSubmit:b,isLargeScreen:x})=>{let[S,C]=(0,p.useState)(!0);if((0,p.useEffect)(()=>{C(!0)},[t,r]),!e)return(0,X.jsx)(_9,{title:`Choose a project`,description:`Select a project before opening bundle details from this phone.`});if(!t)return(0,X.jsx)(_9,{title:`Choose a bundle`,description:`Open a bundle to review its transcript and grouped ticket progress.`});if(a)return(0,X.jsx)(R9,{title:`Bundle unavailable`,backLabel:`Back to tickets`,onBack:f,children:(0,X.jsx)(_9,{title:`Bundle unavailable`,description:a,action:(0,X.jsx)(Q,{variant:`warning`,onClick:m,children:`Retry bundle`})})});if(!n||n.bundle.id!==t)return(0,X.jsx)(R9,{title:`Loading bundle`,backLabel:`Back to tickets`,onBack:f,children:(0,X.jsx)(v9,{text:`Loading bundle details...`})});let w=Jy(n.bundle)||n.bundle.branch||n.bundle.name||`Bundle`,T=new Map(d.map(e=>[e.id,e.label])),E=S3(n.tickets,T),D=T3(n),O=C3(n.tickets,n.execution_order_ticket_ids),k=w3(n.tickets,T,E,n.execution_order_ticket_ids),A=vF(n.tickets,D?.state??null),j=n.tickets.find(e=>e.agent_status===`running`)??D,M=j??D??n.tickets[0]??null,N=j?.agent_status===`running`?E[j.id]??j.model??`Agent`:null,P=!!(D&&D.state!==`plan`&&zy(D)),F=n.tickets.some(e=>e.agent_status===`running`)?`Wait for all bundle tickets to finish building before sending a follow-up prompt.`:void 0,I=`mobile-bundle:${n.bundle.id}:${r}`,L=`${n.tickets.length} ticket${n.tickets.length===1?``:`s`}`,R=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(uF,{status:A}),(0,X.jsx)(rC,{variant:`outline`,children:L}),M?(0,X.jsxs)(rC,{variant:`outline`,children:[`Target: `,M.title]}):null]});return(0,X.jsx)(R9,{title:w,backLabel:`Back to tickets`,onBack:f,subheader:x?void 0:(0,X.jsx)(z9,{value:i,onTranscript:()=>g(`transcript`),onDetails:()=>g(`details`)}),children:x?(0,X.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col gap-3 overflow-hidden pt-3`,children:[(0,X.jsx)(H9,{bundleDetail:n,title:w,subtitle:n.bundle.branch,badges:R,actionState:o,actionError:s,onAction:h,orderedTickets:O,highlightedTicketId:n.target_ticket_id,isTicketListOpen:S,onTicketListOpenChange:C,onSelectTicket:_,className:`shrink-0`,availableModels:d}),(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,X.jsx)(_3,{projectId:e,followUpTicketId:n.target_ticket_id,messages:k,internalLog:j?.agent_log??null,currentThinkingMessageId:j?.agent_message_id??D?.agent_message_id??null,legacyThinkingTicketId:j?.id??D?.id??null,previousThinkingLog:j?.previous_agent_log??D?.previous_agent_log??null,previousThinkingMessageId:j?.previous_agent_message_id??D?.previous_agent_message_id??null,pendingAgentTitle:N,streamingResponse:j?.streaming_response??null,isRunning:n.tickets.some(e=>e.agent_status===`running`),canShowComposer:P,composerTheme:oy(D?.state??null),layoutKey:I,scrollLayoutKey:I,followUpPrompt:c,followUpPlaceholder:M?`Follow up on: ${M.title}`:`Follow up on this bundle`,isSendingFollowUp:l,followUpDisabledReason:F,onFollowUpPromptChange:v,onFollowUpKeyDown:y,onFollowUpSubmit:b},I)}),u?(0,X.jsx)(`p`,{className:`shrink-0 text-sm text-red-200`,children:u}):null]}):i===`details`?(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,X.jsx)(H9,{bundleDetail:n,title:w,subtitle:n.bundle.branch,badges:R,actionState:o,actionError:s,onAction:h,orderedTickets:O,highlightedTicketId:n.target_ticket_id,isTicketListOpen:S,onTicketListOpenChange:C,onSelectTicket:_,className:`h-full`,availableModels:d})}):(0,X.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,X.jsx)(_3,{projectId:e,followUpTicketId:n.target_ticket_id,messages:k,internalLog:j?.agent_log??null,currentThinkingMessageId:j?.agent_message_id??D?.agent_message_id??null,legacyThinkingTicketId:j?.id??D?.id??null,previousThinkingLog:j?.previous_agent_log??D?.previous_agent_log??null,previousThinkingMessageId:j?.previous_agent_message_id??D?.previous_agent_message_id??null,pendingAgentTitle:N,streamingResponse:j?.streaming_response??null,isRunning:n.tickets.some(e=>e.agent_status===`running`),canShowComposer:P,composerTheme:oy(D?.state??null),layoutKey:I,scrollLayoutKey:I,followUpPrompt:c,followUpPlaceholder:M?`Follow up on: ${M.title}`:`Follow up on this bundle`,isSendingFollowUp:l,followUpDisabledReason:F,onFollowUpPromptChange:v,onFollowUpKeyDown:y,onFollowUpSubmit:b},I),u?(0,X.jsx)(`p`,{className:`shrink-0 px-1 pt-2 text-sm text-red-200`,children:u}):null]})})},W9=({selectedProjectId:e,chatSession:t,chatSessionId:n,openNonce:r,error:i,isStopping:a,composerMode:o,composerTool:s,prompt:c,selectedModel:l,selectedVariant:u,selectedSkills:d,availableModels:f,availableSkills:p,isLoadingAgentSettings:m,isSending:h,isUpdatingMode:g,showStartBuilding:_,composerDisabledReason:v,onBack:y,onRetry:b,onStop:x,onModeChange:S,onStartBuilding:C,onPromptChange:w,onModelChange:T,onVariantChange:E,onSkillsChange:D,onPromptKeyDown:O,onSubmit:k,onResolveQuestionSet:A,liveResponseTiming:j,isLargeScreen:M})=>{if(!e)return(0,X.jsx)(_9,{title:`Choose a project`,description:`Select a project before opening the chat workspace.`});if(n&&i)return(0,X.jsx)(_9,{title:`Chat unavailable`,description:i,action:(0,X.jsx)(Q,{variant:`warning`,onClick:b,children:`Retry chat`})});if(n&&(!t||t.id!==n))return(0,X.jsx)(R9,{title:`Loading chat`,backLabel:`Back to chats`,onBack:y,children:(0,X.jsx)(v9,{text:`Loading chat transcript...`})});let N=t?.mode??o,P=f.length>0,F=f.find(e=>e.id===l)??null,I=I9(t?.messages),L=M9(t?.messages),R=!!L,z=pF(t?.post_build_check)?qb.t(`common:postBuildChecks.blockedReason`):R?qb.t(`common:questionSet.waitForResolution`):v,ee=t?.agent_status===`running`?(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`gap-2`,disabled:a,onClick:x,children:[a?(0,X.jsx)(Ov,{className:`h-4 w-4 animate-spin`}):(0,X.jsx)(jv,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:a?`Interrupting...`:`Interrupt`})]}):null,B=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(rC,{variant:N===`plan`?`info`:`success`,children:N}),(0,X.jsx)(rC,{variant:`outline`,children:t?.tool??s}),t?.agent_status?(0,X.jsx)(rC,{variant:`outline`,children:t.agent_status}):null]}),V=P?(0,X.jsx)(_Y,{model:l,variant:u,skills:d,showModelSelector:!0,showSkillsSelector:!0,availableModels:f,availableSkills:p,selectedModel:F,onModelChange:T,onVariantChange:E,onSkillsChange:D,modelSelectId:`mobile-chat-model-selector`,variantSelectId:`mobile-chat-variant-selector`,skillsSelectId:`mobile-chat-skills-selector`,disabled:!!z||h}):m?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading model controls...`}):null,H=!M&&V?(0,X.jsx)(B9,{controls:V}):V,U=(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(HY,{value:N,disabled:!!z||h||g,onChange:S}),_&&(0,X.jsx)(W8,{disabled:h||g,onClick:C})]}),W=t?(0,X.jsx)(`p`,{className:`text-xs leading-5 text-muted-foreground`,children:qb.t(`common:mobileApp.agentSelector.sessionLocked`,{agent:t.tool})}):null,te=M?void 0:({showThinkingControl:e})=>(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 py-1`,children:[U,(0,X.jsx)(`div`,{className:`ml-auto`,children:e})]}),ne=`mobile-chat:${n??`new`}:${r}`;return(0,X.jsx)(R9,{title:t?.title??`New chat`,backLabel:`Back to chats`,onBack:y,action:ee,children:(0,X.jsx)(U8,{projectId:e,agentRunParentType:t?`chat`:null,agentRunParentId:t?.id??null,messages:I,internalLog:t?.agent_log??null,currentThinkingMessageId:t?.agent_message_id??null,previousThinkingLog:t?.previous_agent_log??null,previousThinkingMessageId:t?.previous_agent_message_id??null,pendingAgentTitle:t?.title??`Archon`,streamingResponse:t?.streaming_response??null,isRunning:t?.agent_status===`running`,pendingAgentRevealKey:j?.turnKey??null,liveResponseTiming:j,canShowComposer:!0,header:M?(0,X.jsx)(L9,{title:t?.title??`New chat`,subtitle:t?.target_label_snapshot??`Project root`,badges:B}):te,composerControls:M?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[W,U]}):W,composerInlineControls:H,composerTheme:N,forceScrollToBottomKey:ne,layoutKey:ne,scrollLayoutKey:ne,composerFocusNonce:r,blurComposerOnSendStart:!M,followUpPrompt:c,followUpPlaceholder:n?`Continue this chat`:N===`plan`?`Ask Archon to scope or reason through project work`:`Ask Archon to build or verify something in this project`,emptyStateText:n?`No messages yet.`:`Start a new project chat from this phone.`,renderMessageBody:e=>{let n=e.metadata?.ask_question;if(!(e.role!==`assistant`||!n||!t))return(0,X.jsx)(QJ,{messageContent:e.content,questionSet:n,storageKey:UJ({parentType:`chat`,parentId:t.id,setId:n.id}),isActive:n.status===`pending`&&L?.id===e.id,isDisabled:t.agent_status===`running`||h||g,onResolve:t=>A(e.id,t)})},isSendingFollowUp:h,isComposerSubmitDisabled:!!z,postBuildCheck:t?.post_build_check,followUpDisabledReason:z??void 0,hidePendingAgentTitle:!M,onFollowUpPromptChange:w,onFollowUpKeyDown:O,onFollowUpSubmit:k},ne)})},Eve=e=>(e??[]).map(e=>({id:e.id,role:e.role,kind:e.kind,content:e.content,created_at:e.created_at,ticket_id:null,ticket_proposals:null,metadata:e.metadata,responseTiming:e.response_timing?KK(e.response_timing):null,transcript_runs:e.transcript_runs??null})),Dve=e=>{if(!e)return null;for(let t=e.length-1;t>=0;--t)if(e[t].kind===`grill-question`)return e[t].id;return null},G9=e=>qb.t(`common:mobileApp.${e}`),K9=({selectedProjectId:e,specSession:t,specSessionId:n,openNonce:r,error:i,isStopping:a,composerMode:o,composerTool:s,prompt:c,selectedModel:l,selectedVariant:u,selectedSkills:d,availableModels:f,availableSkills:p,isLoadingAgentSettings:m,isSending:h,isUpdatingMode:g,composerDisabledReason:_,targetWarning:v,targetActionLabel:y,targetActionError:b,isRestoringTarget:x,onBack:S,onRetry:C,onStop:w,onModeChange:T,onPromptChange:E,onModelChange:D,onVariantChange:O,onSkillsChange:k,onPromptKeyDown:A,onSubmit:j,onSubmitAnswer:M,onResolveQuestionSet:N,onRestoreTarget:P,liveResponseTiming:F,isLargeScreen:I})=>{if(!e)return(0,X.jsx)(_9,{title:G9(`specList.emptyTitle`),description:`Select a project before opening the spec workspace.`});if(n&&i)return(0,X.jsx)(_9,{title:G9(`specDetail.unavailableTitle`),description:i,action:(0,X.jsx)(Q,{variant:`warning`,onClick:C,children:G9(`specDetail.retry`)})});if(n&&(!t||t.id!==n))return(0,X.jsx)(R9,{title:G9(`specDetail.loadingTitle`),backLabel:G9(`specDetail.back`),onBack:S,children:(0,X.jsx)(v9,{text:G9(`specDetail.loading`)})});let L=t?.mode??o,R=f.length>0,z=f.find(e=>e.id===l)??null,ee=Eve(t?.messages),B=Dve(t?.messages),V=M9(t?.messages),H=V?qb.t(`common:questionSet.waitForResolution`):_,U=t?.agent_status===`running`,W=U?(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`gap-2`,disabled:a,onClick:w,children:[a?(0,X.jsx)(Ov,{className:`h-4 w-4 animate-spin`}):(0,X.jsx)(jv,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:G9(a?`specDetail.interrupting`:`specDetail.interrupt`)})]}):null,te=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(rC,{variant:L===`grill`?`info`:`success`,children:L}),(0,X.jsx)(rC,{variant:`outline`,children:t?.tool??s}),t?.agent_status?(0,X.jsx)(rC,{variant:`outline`,children:t.agent_status}):null]}),ne=R?(0,X.jsx)(_Y,{model:l,variant:u,skills:d,showModelSelector:!0,showSkillsSelector:!0,availableModels:f,availableSkills:p,selectedModel:z,onModelChange:D,onVariantChange:O,onSkillsChange:k,modelSelectId:`mobile-spec-model-selector`,variantSelectId:`mobile-spec-variant-selector`,skillsSelectId:`mobile-spec-skills-selector`,disabled:!!H||h}):s===`opencode`&&m?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading model controls...`}):null,re=!I&&ne?(0,X.jsx)(B9,{controls:ne}):ne,ie={rationaleLabel:qb.t(`common:specView.grill.rationaleLabel`),suggestionsLabel:qb.t(`common:specView.grill.suggestionsLabel`),recommendedSuggestionLabel:qb.t(`common:specView.grill.recommendedSuggestionLabel`),answerPlaceholder:qb.t(`common:specView.grill.answerPlaceholder`),submitLabel:qb.t(`common:specView.grill.submitLabel`),submittingLabel:qb.t(`common:specView.grill.submittingLabel`)},ae=e=>{if(e.role!==`assistant`)return;let n=e.metadata,r=n?.ask_question;if(r&&t)return(0,X.jsx)(QJ,{messageContent:e.content,questionSet:r,storageKey:UJ({parentType:`spec`,parentId:t.id,setId:r.id}),isActive:r.status===`pending`&&V?.id===e.id,isDisabled:!!v||U||h||g,onResolve:t=>N(e.id,t)});if(e.kind!==`grill-question`)return;let i=n?.grill_question;if(i)return(0,X.jsx)(M5,{question:i,isActive:U?!1:e.id===B&&t?.agent_status!==`running`&&t?.mode===`grill`,isDisabled:!!v||h||g,labels:ie,onSubmitAnswer:M})},G=(0,X.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:(0,X.jsx)(N5,{on:L===`grill`,disabled:!!H||h||g,onToggle:e=>T(e?`grill`:`standard`),tooltipContent:qb.t(`common:specView.grill.toggleTooltip`),ariaLabelOn:qb.t(`common:specView.grill.toggleAriaLabelOn`),ariaLabelOff:qb.t(`common:specView.grill.toggleAriaLabelOff`)})}),oe=t?(0,X.jsx)(`p`,{className:`text-xs leading-5 text-muted-foreground`,children:qb.t(`common:mobileApp.agentSelector.sessionLocked`,{agent:t.tool})}):null,se=I?void 0:({showThinkingControl:e})=>(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 py-1`,children:[G,(0,X.jsx)(`div`,{className:`ml-auto`,children:e})]}),ce=`mobile-spec:${n??`new`}:${r}`;return(0,X.jsxs)(R9,{title:t?.title??G9(`specDetail.newSpecTitle`),backLabel:G9(`specDetail.back`),onBack:S,action:W,children:[v&&(0,X.jsxs)(`div`,{className:`mb-3 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-sm text-amber-100`,children:[(0,X.jsx)(`p`,{children:v}),y&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`mt-2`,disabled:x,onClick:P,children:x?G9(`specDetail.switchingBack`):y}),b&&(0,X.jsx)(`p`,{className:`mt-2 text-red-200`,children:b})]}),(0,X.jsx)(U8,{projectId:e,agentRunParentType:n?`spec`:null,agentRunParentId:n,messages:ee,internalLog:t?.agent_log??null,currentThinkingMessageId:t?.agent_message_id??null,previousThinkingLog:t?.previous_agent_log??null,previousThinkingMessageId:t?.previous_agent_message_id??null,pendingAgentTitle:t?.title??G9(`specDetail.newSpecTitle`),streamingResponse:t?.streaming_response??null,isRunning:U,pendingAgentRevealKey:F?.turnKey??null,liveResponseTiming:F,canShowComposer:!0,header:I?(0,X.jsx)(L9,{title:t?.title??G9(`specDetail.newSpecTitle`),subtitle:t?.first_user_message_preview??null,badges:te}):se,composerControls:I?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[oe,G]}):oe,composerInlineControls:re,composerTheme:`default`,forceScrollToBottomKey:ce,layoutKey:ce,scrollLayoutKey:ce,composerFocusNonce:r,blurComposerOnSendStart:!I,followUpPrompt:c,followUpPlaceholder:G9(n?`specDetail.composerPlaceholder`:`specDetail.composerPlaceholderDraft`),emptyStateText:G9(n?`specDetail.emptyMessages`:`specDetail.emptyDraft`),renderMessageBody:ae,isSendingFollowUp:h,isComposerSubmitDisabled:!!H,followUpDisabledReason:H??void 0,hidePendingAgentTitle:!I,onFollowUpPromptChange:E,onFollowUpKeyDown:A,onFollowUpSubmit:j},ce)]})},q9=({selectedProjectId:e,ticketId:t,ticket:n,openNonce:r,error:i,actionState:a,actionError:o,followUpPrompt:s,followUpSelectedModel:c,followUpSelectedVariant:l,followUpSelectedSkills:u,availableModels:d,availableSkills:f,isLoadingAgentSettings:m,isSendingFollowUp:h,followUpError:g,onBack:_,onRetry:v,onAction:y,onFollowUpPromptChange:b,onFollowUpModelChange:x,onFollowUpVariantChange:S,onFollowUpSkillsChange:C,onFollowUpKeyDown:w,onFollowUpSubmit:T,onResolveQuestionSet:E,liveResponseTiming:D,isLargeScreen:O})=>{let[k,A]=(0,p.useState)(`transcript`);if((0,p.useEffect)(()=>{A(`transcript`)},[r,t]),!e)return(0,X.jsx)(_9,{title:`Choose a project`,description:`Select a project before opening ticket details from this phone.`});if(!t)return(0,X.jsx)(_9,{title:`Choose a ticket`,description:`Open a ticket to review its transcript and continue the workflow.`});if(i)return(0,X.jsx)(_9,{title:`Ticket unavailable`,description:i,action:(0,X.jsx)(Q,{variant:`warning`,onClick:v,children:`Retry ticket`})});if(!n||n.id!==t)return(0,X.jsx)(R9,{title:`Loading ticket`,backLabel:`Back to tickets`,onBack:_,children:(0,X.jsx)(v9,{text:`Loading ticket details...`})});let j=u3(n,{requireWorktree:!0}),M=I9(n.messages,n.id),N=M9(n.messages),P=!!N,F=pF(n.post_build_check),I=F?qb.t(`common:postBuildChecks.blockedReason`):P?qb.t(`common:questionSet.waitForResolution`):j.disabledReason,L=d.find(e=>e.id===c)??null,R=yF(n,`opencode`)===`opencode`&&d.length>0?(0,X.jsx)(_Y,{model:c,variant:l,skills:u,showModelSelector:!0,showSkillsSelector:!0,availableModels:d,availableSkills:f,selectedModel:L,onModelChange:x,onVariantChange:S,onSkillsChange:C,modelSelectId:`mobile-ticket-follow-up-model-selector`,variantSelectId:`mobile-ticket-follow-up-variant-selector`,skillsSelectId:`mobile-ticket-follow-up-skills-selector`,disabled:!!I||h}):yF(n,`opencode`)===`opencode`&&m?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading model controls...`}):null,z=!O&&R?(0,X.jsx)(B9,{controls:R}):R,ee=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(rC,{variant:C9(x9(n)),children:S9(n)}),n.tool?(0,X.jsx)(rC,{variant:`outline`,children:n.tool}):null,n.agent_status?(0,X.jsx)(rC,{variant:`outline`,children:n.agent_status}):null,n.branch?(0,X.jsx)(rC,{variant:`outline`,children:n.branch}):null,n.bundle?.name?(0,X.jsx)(rC,{variant:`outline`,children:n.bundle.name}):null]}),B=`mobile-ticket:${n.id}:${r}`,V=e=>{let t=e.metadata?.ask_question;if(!(e.role!==`assistant`||!t))return(0,X.jsx)(QJ,{messageContent:e.content,questionSet:t,storageKey:UJ({parentType:`ticket`,parentId:n.id,setId:t.id}),isActive:t.status===`pending`&&N?.id===e.id,isDisabled:n.agent_status===`running`||h,onResolve:t=>E(e.id,t)})},H=(0,X.jsx)(z9,{value:k,onTranscript:()=>A(`transcript`),onDetails:()=>A(`details`)});return(0,X.jsx)(R9,{title:n.title,backLabel:`Back to tickets`,onBack:_,subheader:O?void 0:H,children:O?(0,X.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col gap-3 overflow-hidden pt-3`,children:[(0,X.jsx)(V9,{ticket:n,badges:ee,actionState:a,actionError:o,onAction:y,className:`shrink-0`}),(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,X.jsx)(aY,{projectId:e,followUpTicketId:n.id,messages:M,internalLog:n.agent_log??null,currentThinkingMessageId:n.agent_message_id??null,previousThinkingLog:n.previous_agent_log??null,previousThinkingMessageId:n.previous_agent_message_id??null,pendingAgentTitle:n.title,liveResponseTiming:D,streamingResponse:n.streaming_response??null,isRunning:n.agent_status===`running`,canShowComposer:!0,followUpComposerControls:R,composerTheme:oy(n.state),forceScrollToBottomKey:B,layoutKey:B,scrollLayoutKey:B,followUpPrompt:s,followUpPlaceholder:j.placeholder,emptyStateText:`No follow-up messages yet.`,renderMessageBody:V,isSendingFollowUp:h,isComposerSubmitDisabled:P||F,postBuildCheck:n.post_build_check,followUpDisabledReason:I??void 0,onFollowUpPromptChange:b,onFollowUpKeyDown:w,onFollowUpSubmit:T},B)}),g?(0,X.jsx)(`p`,{className:`shrink-0 text-sm text-red-200`,children:g}):null]}):k===`details`?(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,X.jsx)(V9,{ticket:n,badges:ee,actionState:a,actionError:o,onAction:y,className:`h-full`})}):(0,X.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,X.jsx)(aY,{projectId:e,followUpTicketId:n.id,messages:M,internalLog:n.agent_log??null,currentThinkingMessageId:n.agent_message_id??null,previousThinkingLog:n.previous_agent_log??null,previousThinkingMessageId:n.previous_agent_message_id??null,pendingAgentTitle:n.title,liveResponseTiming:D,streamingResponse:n.streaming_response??null,isRunning:n.agent_status===`running`,canShowComposer:!0,followUpComposerControls:z,composerTheme:oy(n.state),surfaceVariant:`chat`,composerSize:`compact-on-laptop`,forceScrollToBottomKey:B,layoutKey:B,scrollLayoutKey:B,followUpPrompt:s,followUpPlaceholder:j.placeholder,emptyStateText:`No follow-up messages yet.`,renderMessageBody:V,isSendingFollowUp:h,isComposerSubmitDisabled:P||F,postBuildCheck:n.post_build_check,followUpDisabledReason:I??void 0,onFollowUpPromptChange:b,onFollowUpKeyDown:w,onFollowUpSubmit:T},B),g?(0,X.jsx)(`p`,{className:`shrink-0 px-1 pt-2 text-sm text-red-200`,children:g}):null]})})},Ove=[],kve=[],Ave=[],J9=e=>qb.t(`common:mobileApp.${e}`),Y9=`Project root has uncommitted changes. Confirm branch switch to continue.`,X9=(e,t)=>{if(!e)return e;let n=new Map(t.tickets.map(e=>[e.id,e]));return e.map(e=>n.get(e.id)??e)},jve=()=>{let e=new URLSearchParams(window.location.search),t=new URLSearchParams(window.location.hash.slice(1)),n=e.get(`mobileAccessId`)??``,r=e.get(`pairingId`)??``,i=t.get(`pairingSecret`)??``;return!n||!r||!i?null:{mobileAccessId:n,pairingId:r,pairingSecret:i}},Mve=()=>{window.history.replaceState({},``,`/mobile`)},Nve=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()},Z9=(e,t)=>e instanceof Ge&&e.message?e.message:t,Q9=e=>({status:`authenticated`,csrfToken:e,projects:null,selectedProjectId:null,projectError:null,projectSummary:null,projectSummaryError:null,chatSessions:null,chatSessionsError:null,selectedChatSessionId:null,chatSessionDetail:null,chatSessionDetailError:null,tickets:null,ticketsError:null,selectedBundleId:null,bundleDetail:null,bundleDetailError:null,selectedTicketId:null,ticketDetail:null,ticketDetailError:null,specSessions:null,specSessionsError:null,selectedSpecSessionId:null,specSessionDetail:null,specSessionDetailError:null}),$9=(e=`pairing_required`)=>({status:`unauthenticated`,reason:e}),Pve=e=>e instanceof Ge&&(e.status===401||e.status===403),Fve=()=>{let[e,t]=(0,p.useState)({status:`checking`}),[n,r]=(0,p.useState)(`connecting`),[i,a]=(0,p.useState)(`opencode`),[o,s]=(0,p.useState)(Br),[c,l]=(0,p.useState)(null),[u,d]=(0,p.useState)(`overview`),[f,m]=(0,p.useState)(!1),[h,g]=(0,p.useState)(!1),[_,v]=(0,p.useState)(!1),[y,b]=(0,p.useState)(!1),[x,S]=(0,p.useState)(!1),[C,w]=(0,p.useState)(!1),[T,E]=(0,p.useState)(``),[D,O]=(0,p.useState)(`build`),[k,A]=(0,p.useState)(``),[j,M]=(0,p.useState)(``),[N,P]=(0,p.useState)([]),[F,I]=(0,p.useState)([]),[L,R]=(0,p.useState)([]),[z,ee]=(0,p.useState)(null),[B,V]=(0,p.useState)(!1),[H,U]=(0,p.useState)(!1),[W,te]=(0,p.useState)(!1),[ne,re]=(0,p.useState)(null),[ie,ae]=(0,p.useState)(null),[G,oe]=(0,p.useState)(null),[se,ce]=(0,p.useState)(!1),[le,ue]=(0,p.useState)(``),[de,fe]=(0,p.useState)(`standard`),[pe,me]=(0,p.useState)(``),[he,ge]=(0,p.useState)(``),[_e,ve]=(0,p.useState)([]),[ye,be]=(0,p.useState)(!1),[xe,Se]=(0,p.useState)(!1),[Ce,we]=(0,p.useState)(null),[Te,Ee]=(0,p.useState)(null),[De,Oe]=(0,p.useState)(null),[ke,Ae]=(0,p.useState)(0),[je,Me]=(0,p.useState)(null),[Ne,Pe]=(0,p.useState)(null),[Fe,Ie]=(0,p.useState)(null),[Le,K]=(0,p.useState)(null),[Re,ze]=(0,p.useState)(``),[Be,Ve]=(0,p.useState)(``),[He,q]=(0,p.useState)(``),[Ue,We]=(0,p.useState)([]),[J,qe]=(0,p.useState)(!1),[Je,Xe]=(0,p.useState)(null),[Ze,Y]=(0,p.useState)(null),[Qe,$e]=(0,p.useState)(``),[et,tt]=(0,p.useState)(!1),[nt,rt]=(0,p.useState)(null),[it,at]=(0,p.useState)(0),[ot,st]=(0,p.useState)(0),[ct,lt]=(0,p.useState)(0),[ut,dt]=(0,p.useState)(`transcript`),[ft,pt]=(0,p.useState)(null),[mt,ht]=(0,p.useState)(null),[gt,_t]=(0,p.useState)(!1),[vt,yt]=(0,p.useState)(!1),[bt,xt]=(0,p.useState)(!1),[St,Ct]=(0,p.useState)(null),[wt,Tt]=(0,p.useState)(null),Et=(0,p.useRef)(null),Dt=(0,p.useRef)(null),Ot=(0,p.useRef)(null),kt=(0,p.useRef)(null),At=(0,p.useRef)(null),jt=(0,p.useRef)(0),Mt=(0,p.useRef)(!1),Nt=(0,p.useRef)(0),Pt=(0,p.useCallback)(e=>Pve(e)?(t($9(`session_revoked`)),r(`unavailable`),m(!1),g(!1),v(!1),b(!1),ce(!1),!0):!1,[]),Ft=(0,p.useCallback)(async(e,n,r,i)=>{try{let a=await x_e(n,r,i);t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedTicketId!==r?t:{...t,ticketDetail:a,ticketDetailError:null})}catch(i){if(!Ye(i)){if(Pt(i))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedTicketId!==r?t:{...t,ticketDetail:null,ticketDetailError:Z9(i,`Unable to load ticket details.`)})}}},[Pt]),It=(0,p.useCallback)(async(e,n,r,i)=>{try{let a=await T_e(n,r,i);t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedBundleId!==r?t:{...t,bundleDetail:a,bundleDetailError:null,tickets:X9(t.tickets,a)})}catch(i){if(!Ye(i)){if(Pt(i))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedBundleId!==r?t:{...t,bundleDetail:null,bundleDetailError:Z9(i,`Unable to load bundle details.`)})}}},[Pt]),Lt=(0,p.useCallback)(async(e,n,r)=>{try{let i=await b_e(n,r);t(t=>{if(t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n)return t;let r=t.selectedTicketId&&i.some(e=>e.id===t.selectedTicketId)?t.selectedTicketId:null,a=t.selectedBundleId&&i.some(e=>e.worktree_bundle_id===t.selectedBundleId)?t.selectedBundleId:null;return{...t,tickets:i,ticketsError:null,selectedBundleId:a,bundleDetail:a?t.bundleDetail:null,bundleDetailError:a?t.bundleDetailError:null,selectedTicketId:r,ticketDetail:r?t.ticketDetail:null,ticketDetailError:r?t.ticketDetailError:null}})}catch(r){if(!Ye(r)){if(Pt(r))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n?t:{...t,tickets:null,ticketsError:Z9(r,`Unable to load project tickets.`),selectedBundleId:null,bundleDetail:null,bundleDetailError:null,selectedTicketId:null,ticketDetail:null,ticketDetailError:null})}}},[Pt]),Rt=(0,p.useCallback)(async(e,n,r,i)=>{try{let a=await y_e(n,r,i);t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedChatSessionId!==r?t:{...t,chatSessionDetail:a,chatSessionDetailError:null})}catch(i){if(!Ye(i)){if(Pt(i))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedChatSessionId!==r?t:{...t,chatSessionDetail:null,chatSessionDetailError:Z9(i,`Unable to load chat transcript.`)})}}},[Pt]),zt=(0,p.useCallback)(async(e,n,r)=>{try{let i=await v_e(n,r);t(t=>{if(t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n)return t;let r=t.selectedChatSessionId&&i.some(e=>e.id===t.selectedChatSessionId)?t.selectedChatSessionId:null;return{...t,chatSessions:i,chatSessionsError:null,selectedChatSessionId:r,chatSessionDetail:r?t.chatSessionDetail:null,chatSessionDetailError:r?t.chatSessionDetailError:null}})}catch(r){if(!Ye(r)){if(Pt(r))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n?t:{...t,chatSessions:null,chatSessionsError:Z9(r,`Unable to load project chats.`),selectedChatSessionId:null,chatSessionDetail:null,chatSessionDetailError:null})}}},[Pt]),Bt=(0,p.useCallback)(async(e,n,r,i)=>{try{let a=await P_e(n,r,i);t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedSpecSessionId!==r?t:{...t,specSessionDetail:a,specSessionDetailError:null})}catch(i){if(!Ye(i)){if(Pt(i))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedSpecSessionId!==r?t:{...t,specSessionDetail:null,specSessionDetailError:Z9(i,J9(`specDetail.detailError`))})}}},[Pt]),Vt=(0,p.useCallback)(async(e,n,r)=>{try{let i=await N_e(n,r);t(t=>{if(t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n)return t;let r=t.selectedSpecSessionId&&i.some(e=>e.id===t.selectedSpecSessionId)?t.selectedSpecSessionId:null;return{...t,specSessions:i,specSessionsError:null,selectedSpecSessionId:r,specSessionDetail:r?t.specSessionDetail:null,specSessionDetailError:r?t.specSessionDetailError:null}})}catch(r){if(!Ye(r)){if(Pt(r))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n?t:{...t,specSessions:null,specSessionsError:Z9(r,J9(`specDetail.listError`)),selectedSpecSessionId:null,specSessionDetail:null,specSessionDetailError:null})}}},[Pt]),Ht=(0,p.useCallback)(async(e,n,r)=>{try{let i=await p_e(n,r);t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n?t:{...t,projectSummary:i,projectSummaryError:null})}catch(r){if(!Ye(r)){if(Pt(r))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n?t:{...t,projectSummary:null,projectSummaryError:Z9(r,`Unable to load the project summary.`)})}}},[Pt]),Ut=(0,p.useCallback)(async(e,n,r=!1)=>{yt(!0),ht(null);try{let[i,a]=await Promise.all([__e(e,n),r?a9(n):Promise.resolve(null)]),o=Et.current;if(o&&o!==e)return;if(pt(i),ht(null),Ct(null),a){let n=a.find(t=>t.id===e);n&&t(t=>t.status!==`authenticated`||t.selectedProjectId!==e?t:{...t,projects:t.projects?.map(t=>t.id===e?{...t,active_target_kind:n.active_target_kind,active_target_bundle_id:n.active_target_bundle_id}:t)??t.projects})}return!0}catch(t){if(!Ye(t)){if(Pt(t))return;let n=Et.current;if(n&&n!==e)return;pt(null),ht(Z9(t,`Unable to load project target options.`))}return!1}finally{n?.aborted||yt(!1)}},[Pt]),Wt=(0,p.useCallback)(e=>{t(t=>t.status===`authenticated`?{...t,projects:t.projects?.map(t=>t.id===e.id?e:t)??t.projects,projectSummary:t.projectSummary?.project.id===e.id?{...t.projectSummary,project:e}:t.projectSummary}:t)},[]),Gt=(0,p.useCallback)(async t=>{if(e.status!==`authenticated`)return;let n=Nt.current+1;Nt.current=n;try{let r=await d_e(t,e.csrfToken);Nt.current===n&&a(r.tool)}catch{}},[e]),Kt=(0,p.useCallback)(async(e,n,r)=>{try{let i=await a9(n),a=r&&i.some(e=>e.id===r)?r:i[0]?.id??null;t(t=>{if(t.status!==`authenticated`||t.csrfToken!==e)return t;let n=!!(t.selectedProjectId&&a&&t.selectedProjectId===a);return{...t,projects:i,selectedProjectId:a,projectError:null,projectSummary:n?t.projectSummary:null,projectSummaryError:n?t.projectSummaryError:null,chatSessions:n?t.chatSessions:null,chatSessionsError:n?t.chatSessionsError:null,selectedChatSessionId:n?t.selectedChatSessionId:null,chatSessionDetail:n?t.chatSessionDetail:null,chatSessionDetailError:n?t.chatSessionDetailError:null,tickets:n?t.tickets:null,ticketsError:n?t.ticketsError:null,selectedBundleId:n?t.selectedBundleId:null,bundleDetail:n?t.bundleDetail:null,bundleDetailError:n?t.bundleDetailError:null,selectedTicketId:n?t.selectedTicketId:null,ticketDetail:n?t.ticketDetail:null,ticketDetailError:n?t.ticketDetailError:null,specSessions:n?t.specSessions:null,specSessionsError:n?t.specSessionsError:null,selectedSpecSessionId:n?t.selectedSpecSessionId:null,specSessionDetail:n?t.specSessionDetail:null,specSessionDetailError:n?t.specSessionDetailError:null}});let o=a?i.find(e=>e.id===a)??null:null;a&&(Ht(e,a,n),o?.active_target_kind===`bundle`&&Ut(a,n),zt(e,a,n),Vt(e,a,n),Lt(e,a,n))}catch(n){if(!Ye(n)){if(Pt(n))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e?t:{...t,projects:t.projects??[],projectError:Z9(n,`Unable to load projects from desktop Archon.`)})}}},[Pt,zt,Ht,Ut,Vt,Lt]),qt=(0,p.useCallback)(async e=>{t({status:`checking`}),r(`connecting`);try{let n=await uve(e);if(n.authenticated&&n.csrf_token){r(`connecting`),t(Q9(n.csrf_token)),Kt(n.csrf_token,e,n.preferred_project_id);return}t($9())}catch(e){Ye(e)||t({status:`error`,message:Z9(e,`Mobile access is unavailable. Make sure it is still enabled on desktop Archon.`)})}},[Kt]),Jt=(0,p.useCallback)((e,n,i)=>{r(`connecting`),t(Q9(e)),Kt(e,i,n)},[Kt]);(0,p.useEffect)(()=>{let e=new AbortController;if(window.location.pathname===`/mobile/pair`){let n=jve();return Mve(),n?(t({status:`pairing`}),dve(n,e.signal).then(e=>{t({status:`pairing_confirmation`,payload:n,displayCode:e.display_code,expiresAt:e.expires_at,error:null})}).catch(e=>{t({status:`error`,message:Z9(e,`Pairing failed. Regenerate the pairing link from desktop Archon and try again.`)})}),()=>e.abort()):(t({status:`error`,message:`Pairing link is missing required pairing details.`}),()=>e.abort())}return qt(e.signal),()=>e.abort()},[Jt,qt]),(0,p.useEffect)(()=>{if(e.status!==`authenticated`)return;let t=new AbortController,n=Nt.current;return u_e(t.signal).then(e=>{Nt.current===n&&a(e.tool)}).catch(e=>{Ye(e)||Pt(e)}),f_e(t.signal).then(e=>s(e.length>0?e:Br())).catch(e=>{Ye(e)||Pt(e)||s(Br())}),()=>t.abort()},[e.status,Pt]);let Yt=e.status===`authenticated`?e.csrfToken:null,Xt=e.status===`authenticated`?e.selectedProjectId:null,Zt=e.status===`authenticated`?e.selectedChatSessionId:null,Qt=e.status===`authenticated`?e.selectedBundleId:null,$t=e.status===`authenticated`?e.selectedTicketId:null,en=e.status===`authenticated`?e.selectedSpecSessionId:null,tn=e.status===`authenticated`?e.projects?.find(t=>t.id===e.selectedProjectId)??null:null,nn=e.status===`authenticated`?e.chatSessionDetail:null,rn=e.status===`authenticated`?e.bundleDetail:null,an=e.status===`authenticated`?e.ticketDetail:null,on=e.status===`authenticated`?e.specSessionDetail:null,sn=!vt&&ft&&`current_branch`in ft?{status:`ready`,branch:ft.current_branch}:null,cn=on?.target_available===!1?on.target_unavailable_reason??J9(`specDetail.targetUnavailable`):null,ln=!!(on?.target_kind===`repo_root`&&on.target_branch_snapshot&&tn?.active_target_kind!==`bundle`),un=on?.target_kind===`bundle`&&mt?qb.t(`common:mobileApp.specDetail.targetRefreshError`,{error:mt}):ln&&mt?qb.t(`common:mobileApp.specDetail.targetLoadError`,{error:mt}):null,dn=on&&vt||ln&&!sn&&!un?J9(`specDetail.targetLoading`):un,fn=!!(on&&!cn&&!dn&&!s5({activeProject:tn,activeProjectBranchState:sn,session:on})),pn=fn&&on?qb.t(`common:mobileApp.specDetail.targetMismatch`,{sessionTarget:l5(on),currentTarget:u5({activeProject:tn,activeProjectBranchState:sn})}):null,mn=y9(tn,ft),hn=vt&&(!tn||tn.active_target_kind===`bundle`),gn=_ve(),_n=nn?.tool??i,vn=on?.tool??i,yn=u===`spec`?vn:u===`tickets`?an?.tool??i:_n,bn=z===yn,xn=bn?F:kve,Sn=bn?L:Ave,Cn=!!(Yt&&Xt)&&(!bn||B),wn=qb.t(`common:mobileApp.agentSettings.loading`),Tn=!!M9(nn?.messages),En=!!M9(on?.messages),Dn=!!M9(an?.messages),On=e.status!==`authenticated`||!e.selectedProjectId?`Choose a project before sending a prompt.`:Cn?wn:W?`Wait for the chat mode change before sending another prompt.`:nn?.agent_status===`running`?`Stop or wait for the current response before sending another prompt.`:Tn?qb.t(`common:questionSet.waitForResolution`):null,kn=!!(nn&&KY(nn,Tn)),An=e.status!==`authenticated`||!e.selectedProjectId?`Choose a project before sending a prompt.`:Cn?wn:cn||dn||pn||(xe?`Wait for the spec mode change before sending another prompt.`:on?.agent_status===`running`?`Stop or wait for the current response before sending another prompt.`:En?qb.t(`common:questionSet.waitForResolution`):null),jn=!gn&&(u===`tickets`&&(_&&!!$t||h&&!!Qt)||u===`chats`&&y||u===`spec`&&se);(0,p.useEffect)(()=>{Et.current=Xt},[Xt]),(0,p.useEffect)(()=>{Xt||(pt(null),ht(null),Ct(null),_t(!1),yt(!1),xt(!1))},[Xt]),(0,p.useEffect)(()=>{Dt.current=Zt},[Zt]),(0,p.useEffect)(()=>{Ot.current=Qt},[Qt]),(0,p.useEffect)(()=>{kt.current=$t},[$t]),(0,p.useEffect)(()=>{At.current=en},[en]),(0,p.useEffect)(()=>{if(!Yt||!Xt){I([]),R([]),ee(null),V(!1);return}let e=new AbortController;return V(!0),Promise.all([K_e(yn,e.signal),yn===`opencode`?q_e(yn,Xt,e.signal):Promise.resolve([])]).then(([t,n])=>{e.signal.aborted||(I(t),R(n),ee(yn))}).catch(e=>{Pt(e)||Ye(e)||(I([]),R([]),ee(yn))}).finally(()=>{e.signal.aborted||V(!1)}),()=>e.abort()},[yn,Yt,Pt,Xt]),(0,p.useEffect)(()=>{let e=ew(tn?.helper_models,_n);A(nn?nn.model??``:e.model??(_n===`opencode`?tn?.helper_model:null)??``),M(nn?nn.variant??``:e.variant??(_n===`opencode`?tn?.helper_variant:null)??``),P(nn?.skills??[])},[_n,nn,tn?.helper_model,tn?.helper_models,tn?.helper_variant]),(0,p.useEffect)(()=>{nn?.mode&&O(nn.mode)},[nn?.id,nn?.mode]),(0,p.useEffect)(()=>{if(nn)return;let e=xn.find(e=>e.id===k)??null;M(t=>e?e.variants.includes(t)?t:``:t)},[xn,nn,k]),(0,p.useEffect)(()=>{ze(``),Xe(null),Ve(an?.model??``),q(an?.variant??``),We(an?.skills??[])},[an?.id,an?.model,an?.skills,an?.variant]),(0,p.useEffect)(()=>{$e(``),rt(null)},[rn?.bundle.id]),(0,p.useEffect)(()=>{let e=ew(tn?.helper_models,vn);me(on?on.model??``:e.model??(vn===`opencode`?tn?.helper_model:null)??``),ge(on?on.variant??``:e.variant??(vn===`opencode`?tn?.helper_variant:null)??``),ve(on?.skills??[])},[vn,tn?.helper_model,tn?.helper_models,tn?.helper_variant,on]),(0,p.useEffect)(()=>{on?.mode&&fe(on.mode)},[on?.id,on?.mode]),(0,p.useEffect)(()=>{if(on)return;let e=xn.find(e=>e.id===pe)??null;ge(t=>e?e.variants.includes(t)?t:``:t)},[xn,on,pe]),(0,p.useEffect)(()=>{let e=xn.find(e=>e.id===Be)??null;q(t=>e?e.variants.includes(t)?t:``:t)},[xn,Be]),(0,p.useEffect)(()=>{if(!Yt)return;let e=mve();l(e),r(`connecting`);let t=()=>{let e=Et.current,t=Dt.current,n=Ot.current,r=kt.current,i=At.current;Kt(Yt,void 0,e),e&&(Ht(Yt,e),zt(Yt,e),Vt(Yt,e),Lt(Yt,e)),e&&t&&Rt(Yt,e,t),e&&n&&It(Yt,e,n),e&&r&&Ft(Yt,e,r),e&&i&&Bt(Yt,e,i)},n=()=>{r(`connected`),t()},i=()=>{r(`reconnecting`)},o=()=>{r(`unavailable`)},s=()=>{Kt(Yt,void 0,Et.current)},c=(e=null)=>{let t=Et.current;t&&(e?.project_id&&e.project_id!==t||Ht(Yt,t))},u=(e=null)=>{let t=Et.current;t&&(e?.project_id&&e.project_id!==t||zt(Yt,t))},d=(e=null)=>{let t=Et.current;t&&(e?.project_id&&e.project_id!==t||Lt(Yt,t))},f=(e=null)=>{let t=Et.current,n=Dt.current;!t||!n||e?.project_id&&e.project_id!==t||e?.id&&e.id!==n||Rt(Yt,t,n)},p=(e=null)=>{let t=Et.current,n=kt.current;!t||!n||e?.project_id&&e.project_id!==t||e?.id&&e.id!==n||Ft(Yt,t,n)},m=(e=null)=>{let t=Et.current,n=Ot.current;!t||!n||e?.project_id&&e.project_id!==t||It(Yt,t,n)},h=(e=null)=>{let t=Et.current;t&&(e?.project_id&&e.project_id!==t||Vt(Yt,t))},g=(e=null)=>{let t=Et.current,n=At.current;!t||!n||e?.project_id&&e.project_id!==t||e?.id&&e.id!==n||Bt(Yt,t,n)},_=e=>{e.tool!==`claude`&&e.tool!==`opencode`||(Nt.current+=1,a(e.tool))};return e.on(`connect`,n),e.on(`disconnect`,i),e.on(`connect_error`,o),e.on(`tool:updated`,_),e.on(`ticket:created`,c),e.on(`ticket:created`,d),e.on(`ticket:updated`,c),e.on(`ticket:updated`,d),e.on(`ticket:updated`,m),e.on(`ticket:updated`,p),e.on(`ticket:deleted`,s),e.on(`ticket:deleted`,d),e.on(`ticket:deleted`,m),e.on(`ticket-dependency:created`,c),e.on(`ticket-dependency:deleted`,c),e.on(`chat-session:created`,u),e.on(`chat-session:updated`,u),e.on(`chat-session:updated`,f),e.on(`chat-session:deleted`,u),e.on(`spec-session:created`,h),e.on(`spec-session:updated`,h),e.on(`spec-session:updated`,g),e.on(`spec-session:deleted`,h),()=>{e.off(`connect`,n),e.off(`disconnect`,i),e.off(`connect_error`,o),e.off(`tool:updated`,_),e.off(`ticket:created`,c),e.off(`ticket:created`,d),e.off(`ticket:updated`,c),e.off(`ticket:updated`,d),e.off(`ticket:updated`,m),e.off(`ticket:updated`,p),e.off(`ticket:deleted`,s),e.off(`ticket:deleted`,d),e.off(`ticket:deleted`,m),e.off(`ticket-dependency:created`,c),e.off(`ticket-dependency:deleted`,c),e.off(`chat-session:created`,u),e.off(`chat-session:updated`,u),e.off(`chat-session:updated`,f),e.off(`chat-session:deleted`,u),e.off(`spec-session:created`,h),e.off(`spec-session:updated`,h),e.off(`spec-session:updated`,g),e.off(`spec-session:deleted`,h),e.disconnect(),l(null)}},[Yt,It,Rt,zt,Ht,Kt,Bt,Vt,Ft,Lt]),(0,p.useEffect)(()=>{Qt||g(!1)},[Qt]),(0,p.useEffect)(()=>{$t||v(!1)},[$t]);let Mn=()=>{qt()},Nn=e=>{d(e),g(!1),v(!1),b(!1),ce(!1),Tt(null)},Pn=()=>{m(!0)},Fn=()=>{e.status!==`authenticated`||!e.selectedProjectId||(Ct(null),_t(!0),!ft&&!vt&&Ut(e.selectedProjectId))},In=()=>{e.status===`authenticated`&&(S(!0),pve(e.csrfToken).then(()=>t($9())).catch(e=>{Pt(e)||t({status:`error`,message:Z9(e,`Logout failed. Mobile access may have already been revoked from desktop Archon.`)})}).finally(()=>S(!1)))},Ln=()=>{if(e.status!==`pairing_confirmation`||C)return;let n=e.payload;w(!0),t({...e,error:null}),fve(n).then(e=>{if(e.authenticated&&e.csrf_token){window.history.replaceState({},``,`/mobile`),Jt(e.csrf_token,e.preferred_project_id);return}t($9())}).catch(e=>{t(t=>t.status===`pairing_confirmation`?{...t,error:Z9(e,`Pairing failed. Regenerate the pairing link from desktop Archon and try again.`)}:t)}).finally(()=>w(!1))},Rn=()=>{window.history.replaceState({},``,`/mobile`),t($9())},zn=()=>{e.status===`authenticated`&&(t({...e,projects:null,projectError:null}),Kt(e.csrfToken))},Bn=()=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,projectSummary:null,projectSummaryError:null}),Ht(e.csrfToken,e.selectedProjectId))},Vn=()=>{e.status!==`authenticated`||!e.selectedProjectId||(pt(null),ht(null),Ct(null),Ut(e.selectedProjectId))},Hn=()=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,chatSessions:null,chatSessionsError:null,selectedChatSessionId:null,chatSessionDetail:null,chatSessionDetailError:null}),zt(e.csrfToken,e.selectedProjectId))},Un=()=>{e.status!==`authenticated`||!e.selectedProjectId||!e.selectedChatSessionId||(t({...e,chatSessionDetail:null,chatSessionDetailError:null}),Rt(e.csrfToken,e.selectedProjectId,e.selectedChatSessionId))},Wn=()=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,tickets:null,ticketsError:null,selectedBundleId:null,bundleDetail:null,bundleDetailError:null,selectedTicketId:null,ticketDetail:null,ticketDetailError:null}),Lt(e.csrfToken,e.selectedProjectId))},Gn=()=>{e.status!==`authenticated`||!e.selectedProjectId||!e.selectedTicketId||(t({...e,ticketDetail:null,ticketDetailError:null}),Ft(e.csrfToken,e.selectedProjectId,e.selectedTicketId))},Kn=()=>{e.status!==`authenticated`||!e.selectedProjectId||!e.selectedBundleId||(t({...e,bundleDetail:null,bundleDetailError:null}),It(e.csrfToken,e.selectedProjectId,e.selectedBundleId))},qn=n=>{if(e.status!==`authenticated`)return;let r=e.projects?.find(e=>e.id===n)??null;Et.current=n,t({...e,selectedProjectId:n,projectSummary:null,projectSummaryError:null,chatSessions:null,chatSessionsError:null,selectedChatSessionId:null,chatSessionDetail:null,chatSessionDetailError:null,tickets:null,ticketsError:null,selectedBundleId:null,bundleDetail:null,bundleDetailError:null,selectedTicketId:null,ticketDetail:null,ticketDetailError:null,specSessions:null,specSessionsError:null,selectedSpecSessionId:null,specSessionDetail:null,specSessionDetailError:null}),Me(null),Pe(null),Ie(null),K(null),ae(null),K(null),Ee(null),rt(null),pt(null),ht(null),Ct(null),m(!1),_t(!1),g(!1),v(!1),b(!1),ce(!1),dt(`transcript`),Tt(null),d(`overview`),Ht(e.csrfToken,n),r?.active_target_kind===`bundle`&&Ut(n),zt(e.csrfToken,n),Vt(e.csrfToken,n),Lt(e.csrfToken,n)},Jn=async t=>{if(!(e.status!==`authenticated`||!e.selectedProjectId)){xt(!0),Ct(null);try{Wt(await d9(e.selectedProjectId,e.csrfToken,{kind:`bundle`,bundle_id:t})),_t(!1),Ht(e.csrfToken,e.selectedProjectId),await Ut(e.selectedProjectId)}catch(e){if(Pt(e))return;Ct(Z9(e,J9(`specDetail.updateTargetError`)))}finally{xt(!1)}}},Yn=async(t,n={})=>{if(e.status!==`authenticated`||!e.selectedProjectId)return;xt(!0),Ct(null);let r=r=>d9(e.selectedProjectId??``,e.csrfToken,{kind:`repo_root`,...t?{branch:t}:{},...n.createBranch===!1?{create_branch:!1}:{},...r?{confirm_dirty_switch:!0}:{}});try{let t;try{t=await r(n.confirmDirtySwitch===!0)}catch(e){if(!n.confirmDirtySwitch&&e instanceof Ge&&e.status===409&&e.message===Y9){if(!window.confirm(`${Y9}\n\nSwitch anyway?`))return;t=await r(!0)}else throw e}Wt(t),_t(!1),Ht(e.csrfToken,e.selectedProjectId),await Ut(e.selectedProjectId)}catch(e){if(Pt(e))return;Ct(Z9(e,J9(`specDetail.updateTargetError`)))}finally{xt(!1)}},Xn=un?Vn:()=>{if(!(!on||on.target_available===!1)){if(on.target_kind===`bundle`){on.target_bundle_id&&Jn(on.target_bundle_id);return}Yn(on.target_branch_snapshot??null,{createBranch:!1})}},Zn=n=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,selectedChatSessionId:n,chatSessionDetail:null,chatSessionDetailError:null}),ae(null),at(e=>e+1),b(!0),d(`chats`),Rt(e.csrfToken,e.selectedProjectId,n))},Qn=()=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,selectedChatSessionId:null,chatSessionDetail:null,chatSessionDetailError:null}),ae(null),E(``),at(e=>e+1),b(!0),d(`chats`))},$n=n=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,selectedBundleId:n,bundleDetail:null,bundleDetailError:null,selectedTicketId:null,ticketDetail:null,ticketDetailError:null}),Me(null),Pe(null),K(null),rt(null),Tt(null),dt(`transcript`),st(e=>e+1),g(!0),v(!1),d(`tickets`),It(e.csrfToken,e.selectedProjectId,n))},er=(n,r)=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,selectedTicketId:n,ticketDetail:null,ticketDetailError:null}),Tt(r),lt(e=>e+1),g(r!==null),v(!0),d(`tickets`),Ft(e.csrfToken,e.selectedProjectId,n))},tr=()=>{b(!1)},nr=async n=>{if(e.status!==`authenticated`||!e.selectedProjectId)return null;if(!e.chatSessionDetail||!e.selectedChatSessionId)return O(n),null;if(e.chatSessionDetail.mode===n||W||Tn)return null;let r=e.selectedProjectId,i=e.selectedChatSessionId,a=e.csrfToken;te(!0),ae(null);try{let e=await j_e(r,i,a,{mode:n});return O(e.mode),t(t=>{if(t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedChatSessionId!==i)return t;let n=t.chatSessions?.map(t=>t.id===e.id?e:t)??t.chatSessions;return{...t,chatSessions:n,chatSessionDetail:e,chatSessionDetailError:null}}),e}catch(e){return Pt(e)||ae(Z9(e,`Unable to update the chat mode right now.`)),null}finally{te(!1)}},rr=()=>{if(e.status===`authenticated`&&wt&&e.selectedBundleId===wt){t({...e,selectedTicketId:null,ticketDetail:null,ticketDetailError:null}),v(!1),g(!0),Tt(null);return}Tt(null),v(!1)},ir=()=>{g(!1)},ar=e=>{let t=xn.find(t=>t.id===e)??null;A(e),M(e=>t&&t.variants.includes(e)?e:``)},or=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),lr())},sr=(e,n,r)=>{t(t=>t.status!==`authenticated`||t.selectedProjectId!==e||t.selectedChatSessionId!==n?t:{...t,chatSessions:t.chatSessions?.map(e=>e.id===r.id?r:e)??t.chatSessions,chatSessionDetail:r,chatSessionDetailError:null})},cr=(n,r,i=e.status===`authenticated`?e.chatSessionDetail:null)=>{if(e.status!==`authenticated`||!e.selectedProjectId||H||On)return Promise.resolve(!1);let a=n.trim();if(!a)return Promise.resolve(!1);let o=e.selectedProjectId,s=i?.id??null,c=e.csrfToken,l=k||null,u=k&&j?j:null,d=_n===`opencode`?N:[],f=performance.now();jt.current+=1;let p=`mobile-chat:${jt.current}`;i&&oe({parentType:`chat`,parentId:i.id,turnKey:p,startedAt:f}),ae(null),U(!0);let m=e=>k_e(o,e.id,c,{instruction:a,tool:e.tool,model:l,variant:u,skills:d});return(i?m(i):O_e(o,c,{mode:D,tool:_n,model:l,variant:u,skills:d}).then(m)).then(e=>(oe({parentType:`chat`,parentId:e.id,turnKey:p,startedAt:f}),r&&E(``),b(!0),t(t=>{if(t.status!==`authenticated`||t.selectedProjectId!==o)return t;let n=t.chatSessions??[],r=n.some(t=>t.id===e.id)?n.map(t=>t.id===e.id?e:t):[e,...n];return{...t,chatSessions:r,selectedChatSessionId:e.id,chatSessionDetail:e,chatSessionDetailError:null}}),zt(c,o),!0)).catch(async e=>{oe(e=>e?.turnKey===p?null:e);let t=Ke(e,`chat_session`);return t&&s?sr(o,s,t):e instanceof Ge&&e.status===409&&s&&await Rt(c,o,s),Pt(e)||ae(Z9(e,`Unable to send the chat prompt.`)),!1}).finally(()=>{U(!1)})},lr=()=>{T.trim()&&cr(T,!0)},ur=async()=>{let t=e.status===`authenticated`?e.chatSessionDetail:null;if(!(!t||!KY(t,Tn)||Mt.current||H||On)){Mt.current=!0;try{let e=await nr(`build`);if(!e)return;await cr(GY,!1,e)}finally{Mt.current=!1}}},dr=async(n,r)=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedChatSessionId)throw Error(`Chat question set is unavailable.`);let i=e.selectedProjectId,a=e.selectedChatSessionId,o=e.csrfToken,s=UJ({parentType:`chat`,parentId:a,setId:r.set_id});ae(null);try{let e=await A_e(i,a,n,o,r);t(t=>t.status!==`authenticated`||t.selectedProjectId!==i||t.selectedChatSessionId!==a?t:{...t,chatSessions:t.chatSessions?.map(t=>t.id===e.id?e:t)??t.chatSessions,chatSessionDetail:e,chatSessionDetailError:null})}catch(e){if(e instanceof Ge&&e.status===409){GJ(s);let t=e.data&&typeof e.data==`object`&&`chat_session`in e.data?e.data.chat_session:null;t?sr(i,a,t):await Rt(o,i,a)}throw Pt(e)||ae(Z9(e,`Unable to resolve the chat questions.`)),e}},fr=()=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedChatSessionId||ne)return;let t=e.selectedProjectId,n=e.selectedChatSessionId;ae(null),re(n),oe(e=>e?.parentId===n?null:e),M_e(t,n,e.csrfToken).then(()=>Rt(e.csrfToken,t,n)).catch(e=>{Pt(e)||ae(Z9(e,`Unable to stop the chat response.`))}).finally(()=>re(null))},pr=()=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,specSessions:null,specSessionsError:null,selectedSpecSessionId:null,specSessionDetail:null,specSessionDetailError:null}),Vt(e.csrfToken,e.selectedProjectId))},mr=()=>{e.status!==`authenticated`||!e.selectedProjectId||!e.selectedSpecSessionId||(t({...e,specSessionDetail:null,specSessionDetailError:null}),Bt(e.csrfToken,e.selectedProjectId,e.selectedSpecSessionId))},hr=n=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,selectedSpecSessionId:n,specSessionDetail:null,specSessionDetailError:null}),Ee(null),Ct(null),Ae(e=>e+1),ce(!0),d(`spec`),Bt(e.csrfToken,e.selectedProjectId,n),Ut(e.selectedProjectId,void 0,!0))},gr=()=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,selectedSpecSessionId:null,specSessionDetail:null,specSessionDetailError:null}),Ee(null),ue(``),Ae(e=>e+1),ce(!0),d(`spec`))},_r=()=>{ce(!1)},vr=n=>{if(e.status!==`authenticated`||!e.selectedProjectId)return;if(!e.specSessionDetail||!e.selectedSpecSessionId){fe(n);return}if(e.specSessionDetail.mode===n||xe||En)return;let r=e.selectedProjectId,i=e.selectedSpecSessionId,a=e.csrfToken;Se(!0),Ee(null),L_e(r,i,a,{mode:n}).then(e=>{fe(e.mode),t(t=>{if(t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedSpecSessionId!==i)return t;let n=t.specSessions?.map(t=>t.id===e.id?e:t)??t.specSessions;return{...t,specSessions:n,specSessionDetail:e,specSessionDetailError:null}})}).catch(e=>{Pt(e)||Ee(Z9(e,J9(`specDetail.modeError`)))}).finally(()=>Se(!1))},yr=e=>{let t=xn.find(t=>t.id===e)??null;me(e),ge(e=>t&&t.variants.includes(e)?e:``)},br=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),Sr())},xr=(e,n,r)=>{t(t=>t.status!==`authenticated`||t.selectedProjectId!==e||t.selectedSpecSessionId!==n?t:{...t,specSessions:t.specSessions?.map(e=>e.id===r.id?r:e)??t.specSessions,specSessionDetail:r,specSessionDetailError:null})},Sr=()=>{if(e.status!==`authenticated`||!e.selectedProjectId||ye||An)return;let n=le.trim();if(!n)return;let r=e.selectedProjectId,i=e.specSessionDetail?.id??null,a=e.csrfToken,o=pe||null,s=pe&&he?he:null,c=vn===`opencode`?_e:[],l=performance.now();jt.current+=1;let u=`mobile-spec:${jt.current}`;e.specSessionDetail&&Oe({parentType:`spec`,parentId:e.specSessionDetail.id,turnKey:u,startedAt:l}),Ee(null),be(!0);let d=e=>s9(r,e.id,a,{instruction:n,tool:e.tool,model:o,variant:s,skills:c});(e.specSessionDetail?d(e.specSessionDetail):F_e(r,a,{mode:de,tool:vn,model:o,variant:s,skills:c}).then(d)).then(e=>{Oe({parentType:`spec`,parentId:e.id,turnKey:u,startedAt:l}),ue(``),ce(!0),t(t=>{if(t.status!==`authenticated`||t.selectedProjectId!==r)return t;let n=t.specSessions??[],i=n.some(t=>t.id===e.id)?n.map(t=>t.id===e.id?e:t):[e,...n];return{...t,specSessions:i,selectedSpecSessionId:e.id,specSessionDetail:e,specSessionDetailError:null}}),Vt(a,r)}).catch(e=>{Oe(e=>e?.turnKey===u?null:e);let t=e instanceof Ge&&e.status===409&&e.data&&typeof e.data==`object`&&`spec_session`in e.data?e.data.spec_session:null;t&&i&&xr(r,i,t),!Pt(e)&&Ee(Z9(e,J9(`specDetail.sendError`)))}).finally(()=>be(!1))},Cr=n=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedSpecSessionId||ye)return;let r=e.selectedProjectId,i=e.selectedSpecSessionId,a=e.csrfToken,o=e.specSessionDetail?.tool??vn,s=pe||null,c=pe&&he?he:null,l=vn===`opencode`?_e:[],u=performance.now();jt.current+=1;let d=`mobile-spec:${jt.current}`;Oe({parentType:`spec`,parentId:i,turnKey:d,startedAt:u}),Ee(null),be(!0),s9(r,i,a,{instruction:n,tool:o,model:s,variant:c,skills:l}).then(e=>{t(t=>t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedSpecSessionId!==i?t:{...t,specSessionDetail:e,specSessionDetailError:null})}).catch(e=>{Oe(e=>e?.turnKey===d?null:e);let t=e instanceof Ge&&e.status===409&&e.data&&typeof e.data==`object`&&`spec_session`in e.data?e.data.spec_session:null;t&&xr(r,i,t),!Pt(e)&&Ee(Z9(e,J9(`specDetail.sendError`)))}).finally(()=>be(!1))},wr=async(n,r)=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedSpecSessionId)throw Error(`Spec question set is unavailable.`);let i=e.selectedProjectId,a=e.selectedSpecSessionId,o=e.csrfToken,s=UJ({parentType:`spec`,parentId:a,setId:r.set_id});Ee(null);try{let e=await I_e(i,a,n,o,r);t(t=>t.status!==`authenticated`||t.selectedProjectId!==i||t.selectedSpecSessionId!==a?t:{...t,specSessions:t.specSessions?.map(t=>t.id===e.id?e:t)??t.specSessions,specSessionDetail:e,specSessionDetailError:null})}catch(e){if(e instanceof Ge&&e.status===409){GJ(s);let t=e.data&&typeof e.data==`object`&&`spec_session`in e.data?e.data.spec_session:null;t?xr(i,a,t):await Bt(o,i,a)}throw Pt(e)||Ee(Z9(e,`Unable to resolve the spec questions.`)),e}},Tr=()=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedSpecSessionId||Ce)return;let t=e.selectedProjectId,n=e.selectedSpecSessionId;Ee(null),we(n),Oe(e=>e?.parentId===n?null:e),R_e(t,n,e.csrfToken).then(()=>Bt(e.csrfToken,t,n)).catch(e=>{Pt(e)||Ee(Z9(e,J9(`specDetail.stopError`)))}).finally(()=>we(null))},Er=n=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedTicketId||Fe||(n===`stop-run`||n===`pause-build`)&&!window.confirm(`Stop this ticket action on the desktop machine?`))return;let r=e.selectedProjectId,i=e.selectedTicketId,a=e.csrfToken,o=n===`build`?c9(r,i,a,`build`):n===`review`?c9(r,i,a,`review`):n===`run`?z_e(r,i,a):n===`stop-run`?B_e(r,i,a):n===`pause-build`?l9(r,i,a):u9(r,i,a);Ie(n),K(null),o.then(e=>{t(t=>{if(t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedTicketId!==i)return t;let n=t.tickets?.map(t=>t.id===e.id?e:t)??t.tickets;return{...t,tickets:n,ticketDetail:e,ticketDetailError:null}}),Ht(a,r),Lt(a,r),Ft(a,r,i)}).catch(e=>{Pt(e)||K(Z9(e,`Unable to update this ticket from mobile.`))}).finally(()=>Ie(null))},Dr=n=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedBundleId||!e.bundleDetail||je)return;let r=e.selectedProjectId,i=e.selectedBundleId,a=e.csrfToken,o=e.bundleDetail,{runningBuildTicketId:s,resumableBuildTicketId:c}=j9(o);if(n===`pause-build`&&!window.confirm(`Pause this bundle build on the desktop machine?`))return;let l=e=>{t(t=>t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedBundleId!==i?t:{...t,tickets:X9(t.tickets,e),bundleDetail:e,bundleDetailError:null})},u=e=>{t(t=>t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedBundleId!==i?t:{...t,tickets:t.tickets?.map(t=>t.id===e.id?e:t)??t.tickets,bundleDetail:t.bundleDetail?{...t.bundleDetail,tickets:t.bundleDetail.tickets.map(t=>t.id===e.id?e:t)}:t.bundleDetail,bundleDetailError:null})},d=n===`build`?E_e(r,i,a):n===`review`?D_e(r,i,a):n===`pause-build`?s?l9(r,s,a):null:c?u9(r,c,a):null;d&&(Me(n),Pe(null),d.then(e=>{`tickets`in e?l(e):u(e),Ht(a,r),Lt(a,r),It(a,r,i)}).catch(e=>{Pt(e)||Pe(Z9(e,`Unable to update this bundle from mobile.`))}).finally(()=>Me(null)))},Or=e=>{let t=xn.find(t=>t.id===e)??null;Ve(e),q(e=>t&&t.variants.includes(e)?e:``)},kr=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),Ar())},Ar=()=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedTicketId||!e.ticketDetail||J||Dn)return;let n=Re.trim();if(!n)return;let r=e.selectedProjectId,i=e.ticketDetail,a=e.csrfToken,o=d3(i,{model:Be||null,variant:He||null,skills:Ue});jt.current+=1;let s={parentType:`ticket`,parentId:i.id,turnKey:`mobile-ticket:${jt.current}`,startedAt:performance.now()};Y(s);let c=()=>i.state===`plan`?H_e(r,i.id,a,n):W_e(r,i.id,a,n),l=e=>{t(t=>{if(t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedTicketId!==i.id)return t;let n=t.tickets?.map(t=>t.id===e.id?e:t)??t.tickets;return{...t,tickets:n,ticketDetail:e,ticketDetailError:null}})};qe(!0),Xe(null),(async()=>{o.shouldPersist&&l(await V_e(r,i.id,a,{model:o.model,variant:o.variant,skills:o.skills})),l(await c()),ze(``),Lt(a,r),Ft(a,r,i.id)})().catch(async e=>{Y(e=>e?.turnKey===s.turnKey?null:e);let t=Ke(e,`ticket`);t?l(t):e instanceof Ge&&e.status===409&&await Ft(a,r,i.id),!Pt(e)&&Xe(Z9(e,`Unable to send the ticket follow-up.`))}).finally(()=>qe(!1))},jr=async(n,r)=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedTicketId)throw Error(`Ticket question set is unavailable.`);let i=e.selectedProjectId,a=e.selectedTicketId,o=e.csrfToken,s=UJ({parentType:`ticket`,parentId:a,setId:r.set_id});Xe(null);try{let e=await U_e(i,a,n,o,r);t(t=>t.status!==`authenticated`||t.selectedProjectId!==i||t.selectedTicketId!==a?t:{...t,tickets:t.tickets?.map(t=>t.id===e.id?e:t)??t.tickets,ticketDetail:e,ticketDetailError:null})}catch(e){if(e instanceof Ge&&e.status===409){GJ(s);let n=e.data&&typeof e.data==`object`&&`ticket`in e.data?e.data.ticket:null;n?t(e=>e.status===`authenticated`&&e.selectedTicketId===a?{...e,ticketDetail:n}:e):await Ft(o,i,a)}throw Pt(e)||Xe(Z9(e,`Unable to resolve the ticket questions.`)),e}},Mr=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),Nr())},Nr=()=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedBundleId||!e.bundleDetail||et)return;let n=Qe.trim();if(!n)return;let r=e.selectedProjectId,i=e.selectedBundleId,a=e.csrfToken,o=e=>{t(t=>t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedBundleId!==i?t:{...t,tickets:X9(t.tickets,e),bundleDetail:e,bundleDetailError:null})};tt(!0),rt(null),G_e(r,i,a,n).then(e=>{o(e),$e(``),Lt(a,r),It(a,r,i)}).catch(e=>{Pt(e)||rt(Z9(e,`Unable to send the bundle follow-up.`))}).finally(()=>tt(!1))},Pr=(0,p.useCallback)(async(e,t,n)=>{try{return await S_e(t??``,e,n)}catch(e){throw Pt(e),e}},[Pt]),Fr=(0,p.useCallback)(async(e,t,n)=>{try{return await C_e(t??``,e,n)}catch(e){throw Pt(e),e}},[Pt]),Ir=(0,p.useCallback)(async(e,t,n)=>{try{return await w_e(t??``,e,n)}catch(e){throw Pt(e),e}},[Pt]);return e.status===`checking`?(0,X.jsx)(g9,{title:`Checking mobile session`,description:`Archon is validating this browser before showing project controls.`}):e.status===`pairing`?(0,X.jsx)(g9,{title:`Checking pairing link`,description:`Keep this page open while Archon verifies the one-time pairing link.`}):e.status===`pairing_confirmation`?(0,X.jsxs)(g9,{title:`Compare pairing code`,description:`Confirm this code matches the desktop dialog before pairing this phone.`,children:[(0,X.jsx)(iC,{className:`border-primary/25 bg-primary/10 shadow-none`,children:(0,X.jsxs)(lC,{className:`space-y-2 pt-5 text-center`,children:[(0,X.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-[0.18em] text-foreground`,children:`Verification code`}),(0,X.jsx)(`div`,{className:`font-mono text-3xl font-semibold tracking-[0.18em] text-foreground`,children:e.displayCode}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`Expires at `,Nve(e.expiresAt)]})]})}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`If this code does not match the desktop dialog, cancel and regenerate the pairing link from desktop Archon.`}),e.error?(0,X.jsx)(`p`,{className:`text-sm text-red-200`,children:e.error}):null,(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,X.jsx)(Q,{size:`lg`,disabled:C,onClick:Ln,children:C?`Pairing...`:`Pair this phone`}),(0,X.jsx)(Q,{variant:`outline`,size:`lg`,disabled:C,onClick:Rn,children:`Cancel`})]})]}):e.status===`unauthenticated`?(0,X.jsx)(g9,{title:e.reason===`session_revoked`?`Mobile session revoked`:`Pairing required`,description:e.reason===`session_revoked`?`This mobile session is no longer valid. Scan the QR code or open the pairing link from desktop Archon to continue.`:`This browser is not paired. Scan the QR code or open the pairing link from desktop Archon.`,children:(0,X.jsx)(Q,{onClick:Mn,children:`Retry`})}):e.status===`error`?(0,X.jsx)(g9,{title:`Mobile access unavailable`,description:e.message,children:(0,X.jsx)(Q,{onClick:Mn,children:`Retry`})}):(0,X.jsx)(gq,{socket:c??void 0,fetchTicketRuns:Pr,fetchChatRuns:Fr,fetchSpecRuns:Ir,children:(0,X.jsxs)(`main`,{className:Z(`bg-background text-foreground`,jn?`flex h-[100dvh] flex-col overflow-hidden`:`min-h-screen`),children:[(0,X.jsx)(ove,{open:f,projects:e.projects,selectedProjectId:e.selectedProjectId,error:e.projectError,onOpenChange:m,onSelectProject:qn,onRetry:zn}),(0,X.jsx)(sve,{open:gt,project:tn,targetOptions:ft,error:St??mt,isLoading:vt,isSubmitting:bt,onOpenChange:_t,onRetry:Vn,onSelectBundle:e=>{Jn(e)},onSelectRepoRoot:(e,t)=>{Yn(e,t)}}),(0,X.jsx)(tve,{activeTool:i,agents:o,selectedProject:tn,targetLabel:mn,isTargetLoading:hn,isTargetDisabled:!Xt,connectionState:n,onOpenProjects:Pn,onOpenTargetSelector:Fn,onToolChange:e=>{Gt(e)}}),jn?(0,X.jsxs)(`div`,{className:`mx-auto flex min-h-0 w-full max-w-6xl flex-1 flex-col overflow-hidden px-3 py-3 sm:px-4`,children:[u===`tickets`?(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:_&&e.selectedTicketId?(0,X.jsx)(q9,{selectedProjectId:e.selectedProjectId,ticketId:e.selectedTicketId,ticket:e.ticketDetail,openNonce:ct,error:e.ticketDetailError,actionState:Fe,actionError:Le,followUpPrompt:Re,followUpSelectedModel:Be,followUpSelectedVariant:He,followUpSelectedSkills:Ue,availableModels:xn,availableSkills:Sn,isLoadingAgentSettings:Cn,isSendingFollowUp:J,liveResponseTiming:an?.agent_status===`running`&&Ze?.parentId===an.id?Ze:null,followUpError:Je,onBack:rr,onRetry:Gn,onAction:Er,onFollowUpPromptChange:ze,onFollowUpModelChange:Or,onFollowUpVariantChange:q,onFollowUpSkillsChange:We,onFollowUpKeyDown:kr,onFollowUpSubmit:Ar,onResolveQuestionSet:jr,isLargeScreen:!1}):(0,X.jsx)(U9,{selectedProjectId:e.selectedProjectId,bundleId:e.selectedBundleId,bundleDetail:e.bundleDetail,openNonce:ot,mobileDetailView:ut,error:e.bundleDetailError,actionState:je,actionError:Ne,followUpPrompt:Qe,isSendingFollowUp:et,followUpError:nt,availableModels:xn,onBack:ir,onRetry:Kn,onAction:Dr,onDetailViewChange:dt,onSelectTicket:er,onFollowUpPromptChange:$e,onFollowUpKeyDown:Mr,onFollowUpSubmit:Nr,isLargeScreen:!1})}):null,u===`chats`?(0,X.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,X.jsx)(W9,{selectedProjectId:e.selectedProjectId,chatSession:e.chatSessionDetail,chatSessionId:e.selectedChatSessionId,openNonce:it,error:e.chatSessionDetailError,isStopping:ne===e.selectedChatSessionId,composerMode:e.chatSessionDetail?.mode??D,composerTool:_n,prompt:T,selectedModel:k,selectedVariant:j,selectedSkills:N,availableModels:xn,availableSkills:Sn,isLoadingAgentSettings:Cn,isSending:H,liveResponseTiming:nn?.agent_status===`running`&&G?.parentId===nn.id?G:null,isUpdatingMode:W,showStartBuilding:kn,composerDisabledReason:On,onBack:tr,onRetry:Un,onStop:fr,onModeChange:nr,onStartBuilding:ur,onPromptChange:E,onModelChange:ar,onVariantChange:M,onSkillsChange:P,onPromptKeyDown:or,onSubmit:lr,onResolveQuestionSet:dr,isLargeScreen:!1}),ie?(0,X.jsx)(`p`,{className:`mt-3 text-sm text-red-200`,children:ie}):null]}):null,u===`spec`?(0,X.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,X.jsx)(K9,{selectedProjectId:e.selectedProjectId,specSession:e.specSessionDetail,specSessionId:e.selectedSpecSessionId,openNonce:ke,error:e.specSessionDetailError,isStopping:Ce===e.selectedSpecSessionId,composerMode:e.specSessionDetail?.mode??de,composerTool:vn,prompt:le,selectedModel:pe,selectedVariant:he,selectedSkills:_e,availableModels:xn,availableSkills:Sn,isLoadingAgentSettings:Cn,isSending:ye,liveResponseTiming:on?.agent_status===`running`&&De?.parentId===on.id?De:null,isUpdatingMode:xe,composerDisabledReason:An,targetWarning:cn??dn??pn,targetActionLabel:un?J9(`specDetail.retryTarget`):fn&&on?qb.t(`common:mobileApp.specDetail.switchBack`,{target:l5(on)}):null,targetActionError:St,isRestoringTarget:bt,onBack:_r,onRetry:mr,onStop:Tr,onModeChange:vr,onPromptChange:ue,onModelChange:yr,onVariantChange:ge,onSkillsChange:ve,onPromptKeyDown:br,onSubmit:Sr,onSubmitAnswer:Cr,onResolveQuestionSet:wr,onRestoreTarget:Xn,isLargeScreen:!1}),Te?(0,X.jsx)(`p`,{className:`mt-3 text-sm text-red-200`,children:Te}):null]}):null]}):(0,X.jsx)(`div`,{className:`mx-auto w-full max-w-6xl px-3 py-3 pb-[calc(env(safe-area-inset-bottom)+5rem)] sm:px-4 lg:flex lg:min-h-[calc(100dvh-4.5rem)] lg:flex-col lg:overflow-hidden lg:pb-4`,children:(0,X.jsxs)(`div`,{className:`space-y-3 lg:flex lg:min-h-0 lg:flex-1 lg:flex-col`,children:[(0,X.jsx)(eve,{status:n,onRetry:Mn}),u===`overview`?(0,X.jsx)(`div`,{className:`space-y-3 lg:flex lg:min-h-0 lg:flex-1 lg:flex-col`,children:e.projectError?(0,X.jsx)(_9,{title:`Projects unavailable`,description:e.projectError,action:(0,X.jsx)(Q,{variant:`warning`,onClick:zn,children:`Retry projects`})}):e.selectedProjectId&&!e.projectSummary&&!e.projectSummaryError?(0,X.jsx)(P9,{}):(0,X.jsxs)(X.Fragment,{children:[e.selectedProjectId&&(0,X.jsx)(hve,{projectId:e.selectedProjectId,csrfToken:e.csrfToken,socket:c,initialRequests:e.projectSummary?.pending_approval_requests??Ove,onRequestError:Pt},e.selectedProjectId),(0,X.jsx)(xve,{selectedProjectId:e.selectedProjectId,summary:e.projectSummary,tickets:e.tickets,error:e.projectSummaryError,chatSessions:e.chatSessions,chatSessionDetail:e.chatSessionDetail,onRetry:Bn,onOpenTickets:()=>Nn(`tickets`),onOpenChats:()=>Nn(`chats`),onOpenSpec:()=>Nn(`spec`)}),(0,X.jsx)(vve,{isLoggingOut:x,onLogout:In})]})}):null,u===`tickets`?gn?(0,X.jsxs)(`div`,{className:`grid min-h-0 flex-1 gap-3 overflow-hidden lg:grid-cols-[minmax(15rem,18rem)_minmax(0,1fr)]`,children:[(0,X.jsx)(`div`,{className:`min-h-0`,children:(0,X.jsx)(E9,{selectedProjectId:e.selectedProjectId,tickets:e.tickets,selectedBundleId:e.selectedBundleId,selectedTicketId:e.selectedTicketId,error:e.ticketsError,onRetry:Wn,onSelectBundle:$n,onSelectTicket:er})}),(0,X.jsx)(`div`,{className:`hidden min-h-0 lg:flex lg:flex-col lg:overflow-hidden`,children:_&&e.selectedTicketId?(0,X.jsx)(q9,{selectedProjectId:e.selectedProjectId,ticketId:e.selectedTicketId,ticket:e.ticketDetail,openNonce:ct,error:e.ticketDetailError,actionState:Fe,actionError:Le,followUpPrompt:Re,followUpSelectedModel:Be,followUpSelectedVariant:He,followUpSelectedSkills:Ue,availableModels:xn,availableSkills:Sn,isLoadingAgentSettings:Cn,isSendingFollowUp:J,liveResponseTiming:an?.agent_status===`running`&&Ze?.parentId===an.id?Ze:null,followUpError:Je,onBack:rr,onRetry:Gn,onAction:Er,onFollowUpPromptChange:ze,onFollowUpModelChange:Or,onFollowUpVariantChange:q,onFollowUpSkillsChange:We,onFollowUpKeyDown:kr,onFollowUpSubmit:Ar,onResolveQuestionSet:jr,isLargeScreen:!0}):(0,X.jsx)(U9,{selectedProjectId:e.selectedProjectId,bundleId:e.selectedBundleId,bundleDetail:e.bundleDetail,openNonce:ot,mobileDetailView:ut,error:e.bundleDetailError,actionState:je,actionError:Ne,followUpPrompt:Qe,isSendingFollowUp:et,followUpError:nt,availableModels:xn,onBack:ir,onRetry:Kn,onAction:Dr,onDetailViewChange:dt,onSelectTicket:er,onFollowUpPromptChange:$e,onFollowUpKeyDown:Mr,onFollowUpSubmit:Nr,isLargeScreen:!0})})]}):(0,X.jsx)(E9,{selectedProjectId:e.selectedProjectId,tickets:e.tickets,selectedBundleId:e.selectedBundleId,selectedTicketId:e.selectedTicketId,error:e.ticketsError,onRetry:Wn,onSelectBundle:$n,onSelectTicket:er}):null,u===`chats`?gn?(0,X.jsxs)(`div`,{className:`grid min-h-0 flex-1 gap-3 overflow-hidden lg:grid-cols-[minmax(15rem,18rem)_minmax(0,1fr)]`,children:[(0,X.jsx)(`div`,{className:`min-h-0`,children:(0,X.jsx)(k9,{selectedProjectId:e.selectedProjectId,chatSessions:e.chatSessions,selectedChatSessionId:e.selectedChatSessionId,error:e.chatSessionsError,onRetry:Hn,onOpenNewChat:Qn,onSelectChat:Zn})}),(0,X.jsxs)(`div`,{className:`hidden min-h-0 lg:flex lg:flex-col lg:overflow-hidden`,children:[(0,X.jsx)(W9,{selectedProjectId:e.selectedProjectId,chatSession:e.chatSessionDetail,chatSessionId:e.selectedChatSessionId,openNonce:it,error:e.chatSessionDetailError,isStopping:ne===e.selectedChatSessionId,composerMode:e.chatSessionDetail?.mode??D,composerTool:_n,prompt:T,selectedModel:k,selectedVariant:j,selectedSkills:N,availableModels:xn,availableSkills:Sn,isLoadingAgentSettings:Cn,isSending:H,liveResponseTiming:nn?.agent_status===`running`&&G?.parentId===nn.id?G:null,isUpdatingMode:W,showStartBuilding:kn,composerDisabledReason:On,onBack:tr,onRetry:Un,onStop:fr,onModeChange:nr,onStartBuilding:ur,onPromptChange:E,onModelChange:ar,onVariantChange:M,onSkillsChange:P,onPromptKeyDown:or,onSubmit:lr,onResolveQuestionSet:dr,isLargeScreen:!0}),ie?(0,X.jsx)(`p`,{className:`mt-3 text-sm text-red-200`,children:ie}):null]})]}):(0,X.jsx)(k9,{selectedProjectId:e.selectedProjectId,chatSessions:e.chatSessions,selectedChatSessionId:e.selectedChatSessionId,error:e.chatSessionsError,onRetry:Hn,onOpenNewChat:Qn,onSelectChat:Zn}):null,u===`spec`?gn?(0,X.jsxs)(`div`,{className:`grid min-h-0 flex-1 gap-3 overflow-hidden lg:grid-cols-[minmax(15rem,18rem)_minmax(0,1fr)]`,children:[(0,X.jsx)(`div`,{className:`min-h-0`,children:(0,X.jsx)(A9,{selectedProjectId:e.selectedProjectId,specSessions:e.specSessions,selectedSpecSessionId:e.selectedSpecSessionId,error:e.specSessionsError,onRetry:pr,onOpenNewSpec:gr,onSelectSpec:hr})}),(0,X.jsxs)(`div`,{className:`hidden min-h-0 lg:flex lg:flex-col lg:overflow-hidden`,children:[(0,X.jsx)(K9,{selectedProjectId:e.selectedProjectId,specSession:e.specSessionDetail,specSessionId:e.selectedSpecSessionId,openNonce:ke,error:e.specSessionDetailError,isStopping:Ce===e.selectedSpecSessionId,composerMode:e.specSessionDetail?.mode??de,composerTool:vn,prompt:le,selectedModel:pe,selectedVariant:he,selectedSkills:_e,availableModels:xn,availableSkills:Sn,isLoadingAgentSettings:Cn,isSending:ye,liveResponseTiming:on?.agent_status===`running`&&De?.parentId===on.id?De:null,isUpdatingMode:xe,composerDisabledReason:An,targetWarning:cn??dn??pn,targetActionLabel:un?J9(`specDetail.retryTarget`):fn&&on?qb.t(`common:mobileApp.specDetail.switchBack`,{target:l5(on)}):null,targetActionError:St,isRestoringTarget:bt,onBack:_r,onRetry:mr,onStop:Tr,onModeChange:vr,onPromptChange:ue,onModelChange:yr,onVariantChange:ge,onSkillsChange:ve,onPromptKeyDown:br,onSubmit:Sr,onSubmitAnswer:Cr,onResolveQuestionSet:wr,onRestoreTarget:Xn,isLargeScreen:!0}),Te?(0,X.jsx)(`p`,{className:`mt-3 text-sm text-red-200`,children:Te}):null]})]}):(0,X.jsx)(A9,{selectedProjectId:e.selectedProjectId,specSessions:e.specSessions,selectedSpecSessionId:e.selectedSpecSessionId,error:e.specSessionsError,onRetry:pr,onOpenNewSpec:gr,onSelectSpec:hr}):null]})}),jn?null:(0,X.jsx)(nve,{activeSection:u,onChange:Nn})]})})},Ive=({socket:e=KS,children:t})=>(0,X.jsx)(lq.Provider,{value:e,children:t}),Lve=()=>typeof window<`u`&&window.location.pathname.startsWith(`/mobile`),Rve=()=>{let e=Lve();return Ab(e?null:KS),(0,X.jsx)(Ue,{i18n:qb,children:(0,X.jsx)(it,{children:(0,X.jsxs)(Ive,{children:[e&&(0,X.jsx)(Fve,{}),!e&&(0,X.jsx)(gq,{children:(0,X.jsx)(Cme,{children:(0,X.jsx)(c_e,{})})})]})})})};document.documentElement.classList.add(`dark`),document.documentElement.style.colorScheme=`dark`,t3(),(0,f.createRoot)(document.getElementById(`root`)).render((0,X.jsx)(Rve,{}));export{Z as $,pb as A,Tv as B,CC as C,hx as D,KS as E,tb as F,V_ as G,bv as H,$ as I,q_ as J,H_ as K,jv as L,eb as M,nb as N,ax as O,rb as P,Q,kv as R,wC as S,c as St,qS as T,iv as U,wv as V,J_ as W,W_ as X,G_ as Y,K_ as Z,LC as _,J as _t,C4 as a,Kt as at,zC as b,Y as bt,vue as c,Xt as ct,lE as d,Ht as dt,Vn as et,iE as f,Vt as ft,YC as g,Ge as gt,XC as h,rt as ht,T4 as i,Zt as it,ib as j,qb as k,uq as l,$t as lt,nw as m,Bt as mt,f8 as n,Yt as nt,w4 as o,en as ot,qT as p,Ut as pt,U_ as q,B4 as r,Jt as rt,u4 as s,Gt as st,G5 as t,qt as tt,HW as u,Qt as ut,BC as v,Ye as vt,rC as w,SC as x,q as xt,RC as y,Ze as yt,Ov as z};
275
+ `);te.current+=1,G([...ee.current,{kind:`source`,id:`${O.content.path}:${e}:${Date.now()}:${te.current}`,target:t,filePath:O.content.path,lineNumber:e,lineContent:r[e-1]??``,sourceContext:Mpe(O.content.content,e),contentSignature:O.content.content_signature,comment:n,stale:!1}])},[G,O,t]);(0,p.useEffect)(()=>{pe&&D(`source`)},[pe]);let be=(0,p.useCallback)(()=>{O.kind===`content`&&(D(`source`),j(!0))},[O.kind]),xe=(0,p.useCallback)(e=>{he.length!==0&&F(t=>((t<0?0:Math.min(t,he.length-1))+e+he.length)%he.length)},[he.length]);return(0,p.useEffect)(()=>{A&&re.current?.focus({preventScroll:!0})},[A]),(0,p.useEffect)(()=>{let e=e=>{if(!(!n||O.kind!==`content`||e.defaultPrevented)){if((e.ctrlKey||e.metaKey)&&!e.altKey&&e.key.toLocaleLowerCase()===`f`){e.preventDefault(),be(),requestAnimationFrame(()=>re.current?.focus({preventScroll:!0}));return}A&&e.key===`Escape`&&(e.preventDefault(),oe())}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[O.kind,n,A,be,oe]),(0,X.jsxs)(`section`,{className:`flex min-h-0 flex-1 overflow-hidden rounded-xl border border-border`,"aria-label":`Files mode`,children:[(0,X.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col border-r border-border bg-muted/10`,"aria-label":B6(`fileBrowser`),children:[(0,X.jsxs)(`div`,{className:`space-y-3 border-b border-border p-3`,children:[(0,X.jsxs)(`label`,{className:`block text-xs text-muted-foreground`,children:[B6(`searchFiles`),(0,X.jsx)(J_,{ref:ne,type:`search`,className:`mt-1 h-8`,value:_,onChange:e=>v(e.target.value),placeholder:B6(`searchPlaceholder`)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked)}),B6(`changedOnly`)]}),(0,X.jsx)(vv,{content:B6(`refreshFiles`),children:(0,X.jsx)(Q,{type:`button`,size:`icon-xs`,variant:`ghost`,"aria-label":B6(`refreshFiles`),disabled:h,onClick:()=>{ue(!0)},children:h?(0,X.jsx)(Ov,{className:`size-3.5 animate-spin`}):(0,X.jsx)(ix,{className:`size-3.5`})})})]})]}),h&&!u&&(0,X.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:B6(`loadingManifest`)}),f&&(0,X.jsxs)(`div`,{className:`space-y-3 p-4 text-sm text-destructive`,children:[(0,X.jsx)(`p`,{children:f}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>void ue(),children:B6(`retry`)})]}),u&&(0,X.jsxs)(X.Fragment,{children:[u.truncated&&(0,X.jsx)(`div`,{className:`border-b border-border px-3 py-2 text-xs text-amber-300`,children:B6(`truncated`)}),(0,X.jsx)(Dpe,{entries:u.entries,search:y,changedOnly:b,expandedPaths:S,selectedPath:w,commentCounts:ve,onExpandedPathsChange:C,onSelectPath:le})]})]}),(0,X.jsxs)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,X.jsxs)(`header`,{"data-testid":`workspace-file-header`,className:`flex min-h-12 shrink-0 flex-wrap items-center justify-between gap-2 border-b border-border px-4 py-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`truncate font-mono text-xs text-foreground`,children:w??B6(`selectFile`)}),de&&(0,X.jsx)(`div`,{className:`mt-0.5 text-[11px] capitalize text-muted-foreground`,children:Npe(de)})]}),(O.kind===`content`||fe||l||w&&de?.status&&c)&&(0,X.jsxs)(`div`,{"data-testid":`workspace-file-header-actions`,className:`flex shrink-0 flex-wrap items-center justify-end gap-2 pr-10`,children:[fe&&(0,X.jsxs)(`div`,{className:`flex items-center rounded-lg border border-border bg-muted/20 p-0.5`,role:`group`,"aria-label":B6(`viewMode.ariaLabel`),children:[(0,X.jsx)(Q,{type:`button`,size:`xs`,variant:me===`preview`?`secondary`:`ghost`,"aria-pressed":me===`preview`,disabled:pe,onClick:()=>{D(`preview`)},children:B6(`viewMode.preview`)}),(0,X.jsx)(Q,{type:`button`,size:`xs`,variant:me===`source`?`secondary`:`ghost`,"aria-pressed":me===`source`,onClick:()=>{D(`source`)},children:B6(`viewMode.source`)})]}),pe&&(0,X.jsx)(`p`,{className:`text-xs text-amber-200`,role:`status`,children:B6(`viewMode.sourceRequiredLargeFile`)}),O.kind===`content`&&!A&&(0,X.jsx)(vv,{content:B6(`source.search.open`),children:(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":B6(`source.search.open`),onClick:be,children:(0,X.jsx)(ape,{className:`size-4`})})}),O.kind===`content`&&A&&(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1 rounded-lg border border-border bg-muted/20 p-1`,role:`search`,children:[(0,X.jsx)(J_,{ref:re,type:`search`,className:`h-7 w-40 rounded-md px-2 text-xs sm:w-56`,"aria-label":B6(`source.search.inputLabel`),placeholder:B6(`source.search.placeholder`),value:M,onChange:e=>{N(e.target.value),F(0)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),xe(e.shiftKey?-1:1))}}),(0,X.jsx)(`output`,{className:`min-w-12 whitespace-nowrap px-1 text-center text-[11px] text-muted-foreground`,"aria-live":`polite`,children:he.length>0?B6(`source.search.matchCount`,{current:ge+1,total:he.length}):B6(`source.search.noMatches`)}),(0,X.jsx)(Q,{type:`button`,size:`icon-xs`,variant:`ghost`,"aria-label":B6(`source.search.previous`),disabled:he.length===0,onClick:()=>xe(-1),children:(0,X.jsx)(bv,{className:`size-3.5 rotate-180`})}),(0,X.jsx)(Q,{type:`button`,size:`icon-xs`,variant:`ghost`,"aria-label":B6(`source.search.next`),disabled:he.length===0,onClick:()=>xe(1),children:(0,X.jsx)(bv,{className:`size-3.5`})}),(0,X.jsx)(Q,{type:`button`,size:`icon-xs`,variant:`ghost`,"aria-label":B6(`source.search.close`),onClick:oe,children:(0,X.jsx)(ax,{className:`size-3.5`})})]}),w&&de?.status&&c&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>c(w),children:B6(`viewChanges`)}),l]})]}),O.kind===`empty`&&(0,X.jsx)(`div`,{className:`m-auto max-w-sm text-center text-sm text-muted-foreground`,children:B6(`empty`)}),O.kind===`loading`&&(0,X.jsx)(`div`,{className:`m-auto text-sm text-muted-foreground`,children:B6(`loadingFile`,{path:O.path})}),O.kind===`unsupported`&&(0,X.jsxs)(`div`,{className:`m-auto max-w-md space-y-2 text-center`,children:[(0,X.jsx)(rC,{variant:`outline`,className:`capitalize`,children:O.reason.replace(/_/g,` `)}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:O.message})]}),O.kind===`error`&&(0,X.jsxs)(`div`,{className:`m-auto max-w-md space-y-3 text-center`,children:[(0,X.jsx)(`p`,{className:`text-sm text-destructive`,children:O.message}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>void ce(O.path,!0),children:B6(`retry`)})]}),O.kind===`content`&&(0,X.jsx)(Ppe,{file:O.content,viewMode:me,comments:_e,canComment:r,searchMatches:he,activeSearchMatchIndex:ge,onAddComment:ye})]})]})},U6=r({WorkspaceReviewModal:()=>G6}),W6=e=>qb.t(`common:workspaceReviewModal.${e}`),Ipe=({activeMode:e,availableModes:t,onModeChange:n})=>(0,X.jsx)(`div`,{role:`tablist`,"aria-label":W6(`modeAriaLabel`),className:`flex items-center gap-1 rounded-lg border border-border/80 bg-muted/30 p-1`,children:t.map(t=>(0,X.jsxs)(Q,{type:`button`,role:`tab`,size:`sm`,variant:e===t?`secondary`:`ghost`,"aria-selected":e===t,"aria-controls":`workspace-review-${t}-panel`,onClick:()=>n(t),children:[t===`files`?(0,X.jsx)(Tv,{className:`h-4 w-4`}):(0,X.jsx)(Ev,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:W6(t)})]},t))}),G6=({target:e,initialMode:t=`changes`,reviewMode:n,onReviewModeChange:r,enabledModes:i=[`changes`],filesView:a,fileTarget:o,bundleTargetName:s=null,onClose:c,title:l,mode:u,onModeChange:d,canToggleMode:f=!1,...m})=>{let[h,g]=(0,p.useState)(t),_=n??h,v=i.includes(_)?i:[_,...i],[y]=(0,p.useState)(e),[b,x]=(0,p.useState)(null),[S,C]=(0,p.useState)(null),[w,T]=(0,p.useState)([]),[E,D]=(0,p.useState)([]),O=(0,p.useRef)(E),[k,A]=(0,p.useState)(null);O.current=E;let j=(0,p.useCallback)(e=>{O.current=e,D(e)},[]),M=(0,p.useCallback)(()=>{O.current=[],D([])},[]),N=v.length>1,P=N&&a===void 0,[F]=(0,p.useState)(s),[I]=(0,p.useState)(()=>o??(y.scope===`project_root`?m.targetKind===`bundle`&&m.reviewCommentsBundleId?{kind:`bundle`,bundle_id:m.reviewCommentsBundleId,ticket_id:null}:{kind:`repo_root`,bundle_id:null,ticket_id:null}:m.reviewCommentsBundleId?{kind:`bundle`,bundle_id:m.reviewCommentsBundleId,ticket_id:null}:{kind:`ticket`,bundle_id:null,ticket_id:y.ticketId})),L=I.kind===`repo_root`?qb.t(`common:workspaceFiles.repositoryRoot`):I.kind===`bundle`?qb.t(`common:workspaceFiles.bundleTarget`,{name:F||I.bundle_id}):qb.t(`common:workspaceFiles.ticketTarget`,{id:I.ticket_id}),R=I.kind===`ticket`?l:L,z=(0,p.useCallback)(async()=>{if(!m.projectId||E.length===0)return E;let e=await z6(m.projectId,E),t=new Map(e.map(e=>[e.id,e.stale])),n=O.current.map(e=>{let n=t.get(e.id);return n===void 0?e:{...e,stale:n}});return j(n),n},[m.projectId,E,j]),ee=(0,p.useCallback)(()=>{m.projectId&&localStorage.removeItem(R6(m.projectId,I)),M()},[m.projectId,M,I]),B=(0,p.useCallback)(e=>{r?.(e),n===void 0&&g(e)},[r,n]),V=(0,p.useCallback)(e=>{x(e),B(`changes`)},[B]),H=(0,p.useCallback)(e=>{C(e),B(`files`)},[B]),U=(0,p.useCallback)(e=>{x(t=>t===e?null:t)},[]),W=(0,p.useCallback)(e=>{C(t=>t===e?null:t)},[]),te=(0,p.useCallback)(e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[u!==void 0&&d&&(0,X.jsx)(HY,{value:u,disabled:!f||m.isUpdatingMode,onChange:d,planInactiveTooltip:(0,X.jsx)(QY,{label:qb.t(`common:ticketChangesModal.switchToPlan`)}),buildInactiveTooltip:(0,X.jsx)(QY,{label:qb.t(`common:ticketChangesModal.switchToBuild`)})}),(0,X.jsx)(A3,{reviewComments:w,reviewFindings:e.reviewFindings,githubComments:e.githubComments,pendingFixCount:e.pendingFixCount,canSendReview:e.canSendReview,isSubmittingReview:e.isSubmittingReview,reviewSubmitDisabledReason:e.reviewSubmitDisabledReason,onClearPendingFixes:e.onClearPendingFixes,onSubmitReview:e.onSubmitReview,onUpdateReviewComment:e.onUpdateReviewComment,onRemoveReviewComment:e.onRemoveReviewComment})]}),[f,m.isUpdatingMode,u,d,w]),ne=(0,p.useCallback)(()=>k?te(k):null,[te,k]);return(0,p.useEffect)(()=>{if(!d||u===void 0)return;let e=e=>{!YY(e)||!f||(e.preventDefault(),d(JY(u)))};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}},[f,u,d]),(0,X.jsx)(X.Fragment,{children:(0,X.jsx)(tC,{onClose:c,overlayClassName:`z-[70] bg-black/30 p-[5vh]`,panelClassName:`flex h-[92vh] w-full max-w-none flex-col overflow-hidden rounded-2xl border border-border bg-card p-6 shadow-2xl`,closeButtonLabel:W6(`closeAriaLabel`),renderContent:({closeButton:e})=>{let t=N?(0,X.jsx)(Ipe,{activeMode:_,availableModes:v,onModeChange:B}):null,n=N?(0,X.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:t}):null,r=y.scope===`ticket`?(0,X.jsx)(T6,{...m,...y,projectId:m.projectId,title:l,onClose:c,mode:u,onModeChange:d,canToggleMode:f,headerControls:n,isActive:_===`changes`,onPendingReviewCommentsChange:T,onReviewControlsStateChange:A,renderReviewControls:te,showReviewControls:!N||_===`changes`,sourceReviewComments:E,onSourceReviewCommentsChange:j,onClearSourceReviewComments:M,onSourceReviewCommentsSubmitted:ee,onValidateSourceReviewComments:z,requestedDiffPath:b,onRequestedDiffPathHandled:U,onViewCurrentFile:P?H:void 0}):(0,X.jsx)(T6,{...m,scope:`project_root`,projectId:m.projectId,title:l,onClose:c,mode:u,onModeChange:d,canToggleMode:f,headerControls:n,isActive:_===`changes`,onPendingReviewCommentsChange:T,onReviewControlsStateChange:A,renderReviewControls:te,showReviewControls:!N||_===`changes`,sourceReviewComments:E,onSourceReviewCommentsChange:j,onClearSourceReviewComments:M,onSourceReviewCommentsSubmitted:ee,onValidateSourceReviewComments:z,requestedDiffPath:b,onRequestedDiffPathHandled:U,onViewCurrentFile:P?H:void 0}),i=N?(0,X.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-hidden`,children:[_===`files`&&(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-4`,children:[(0,X.jsx)(`h2`,{className:`min-w-0 flex-1 truncate text-lg font-semibold text-foreground`,children:R}),(0,X.jsx)(`div`,{"data-testid":`workspace-review-files-header-actions`,className:`flex min-w-0 max-w-full items-center gap-2 pr-10`,children:(0,X.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center justify-end gap-2`,children:t})})]}),(0,X.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[(0,X.jsx)(`div`,{id:`workspace-review-changes-panel`,role:`tabpanel`,hidden:_!==`changes`,className:`min-h-0 flex-1 flex-col overflow-hidden data-[active=true]:flex`,"data-active":_===`changes`,children:r}),(0,X.jsx)(`div`,{id:`workspace-review-files-panel`,role:`tabpanel`,hidden:_!==`files`,className:`min-h-0 flex-1 flex-col overflow-hidden data-[active=true]:flex`,"data-active":_===`files`,children:a??(0,X.jsx)(Fpe,{projectId:m.projectId,target:I,isActive:_===`files`,canAddComments:m.canAddReviewComments??!1,comments:E,onCommentsChange:j,requestedPath:S,onRequestedPathHandled:W,onViewChanges:V,headerControls:_===`files`&&k?ne():void 0})})]})]}):r;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`absolute right-4 top-4 z-10 mt-2`,children:e}),i]})}})})},Lpe=e=>!(e instanceof Ge)||e.status!==409||typeof e.data!=`object`||e.data===null?!1:`code`in e.data&&e.data.code===`build_open_questions_changed`,Rpe=e=>{let t=new Map((e.execution_order_ticket_ids??[]).map((e,t)=>[e,t]));return e.tickets.map(e=>({ticket:e,questions:(e.build_open_questions??[]).filter(e=>e.status===`open`).sort((e,t)=>e.created_at.localeCompare(t.created_at))})).filter(e=>e.questions.length>0).sort((e,n)=>(t.get(e.ticket.id)??e.ticket.bundle_execution_position??2**53-1)-(t.get(n.ticket.id)??n.ticket.bundle_execution_position??2**53-1))},zpe=e=>e.flatMap(e=>e.questions.map(e=>`${e.id}:${e.updated_at}`)).join(`|`),Bpe=({details:e,onClose:t,onRefresh:n,onSubmit:r})=>{let{t:i}=q(`common`),a=(0,p.useMemo)(()=>Rpe(e),[e]),o=(0,p.useMemo)(()=>a.flatMap(e=>e.questions),[a]),s=(0,p.useMemo)(()=>zpe(a),[a]),c=(0,p.useRef)(s),[l,u]=(0,p.useState)(()=>Object.fromEntries(o.map(e=>[e.id,{mode:null,answer:``}]))),[d,f]=(0,p.useState)(!1),[m,h]=(0,p.useState)(!1),[g,_]=(0,p.useState)(null);(0,p.useEffect)(()=>{u(e=>Object.fromEntries(o.map(t=>[t.id,e[t.id]??{mode:null,answer:``}]))),c.current!==s&&(c.current=s,d||(h(!0),_(i(`buildOpenQuestionsDialog.refreshedError`))))},[d,o,s,i]);let v=o.length>0&&o.every(e=>{let t=l[e.id];return t?.mode===`dismiss`||t?.mode===`answer`&&t.answer.trim()!==``}),y=o.some(e=>l[e.id]?.mode===`answer`),b=o.length>0&&o.every(e=>l[e.id]?.mode===`dismiss`),x=(e,t)=>{u(n=>({...n,[e]:{...n[e]??{mode:null,answer:``},...t}})),_(null)};return(0,X.jsx)(V_,{open:!0,onOpenChange:e=>{e||t()},children:(0,X.jsx)(U_,{showCloseButton:!1,className:`flex max-h-[calc(100vh-2rem)] flex-col gap-0 overflow-hidden p-0 sm:max-w-3xl`,children:(0,X.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),!(!v||m||d)){f(!0),_(null);try{await r({resolutions:o.map(e=>{let t=l[e.id];return t.mode===`dismiss`?{question_id:e.id,dismiss:!0}:{question_id:e.id,answer:t.answer.trim()}})})}catch(e){if(Lpe(e)){try{await n()}catch{_(i(`buildOpenQuestionsDialog.refreshFailedError`))}h(!0),_(e=>e??i(`buildOpenQuestionsDialog.conflictError`))}else _(e instanceof Ge?e.message:i(`buildOpenQuestionsDialog.submitError`))}finally{f(!1)}}},className:`flex min-h-0 flex-col`,children:[(0,X.jsxs)(W_,{className:`border-b border-border/70 px-5 py-4 sm:px-6`,children:[(0,X.jsx)(K_,{children:i(`buildOpenQuestionsDialog.title`)}),(0,X.jsx)(q_,{children:i(`buildOpenQuestionsDialog.description`)})]}),(0,X.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4 sm:px-6`,children:[a.map(e=>(0,X.jsxs)(`section`,{"aria-labelledby":`build-question-ticket-${e.ticket.id}`,children:[(0,X.jsx)(`h3`,{id:`build-question-ticket-${e.ticket.id}`,className:`text-sm font-semibold text-foreground`,children:i(`buildOpenQuestionsDialog.ticketHeading`,{title:e.ticket.title})}),(0,X.jsx)(`div`,{className:`mt-2 space-y-3`,children:e.questions.map(e=>{let t=l[e.id]??{mode:null,answer:``};return(0,X.jsxs)(`article`,{className:`min-w-0 rounded-xl border border-border/70 bg-background/30 p-4`,children:[(0,X.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm leading-6 text-foreground`,children:e.question_text}),(0,X.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-x-5 gap-y-2`,children:[(0,X.jsxs)(iv,{className:`flex cursor-pointer items-center gap-2 text-sm`,children:[(0,X.jsx)(`input`,{type:`radio`,name:`decision-${e.id}`,checked:t.mode===`answer`,onChange:()=>x(e.id,{mode:`answer`})}),i(`buildOpenQuestionsDialog.answerOption`)]}),(0,X.jsxs)(iv,{className:`flex cursor-pointer items-center gap-2 text-sm`,children:[(0,X.jsx)(`input`,{type:`radio`,name:`decision-${e.id}`,checked:t.mode===`dismiss`,onChange:()=>x(e.id,{mode:`dismiss`})}),i(`buildOpenQuestionsDialog.dismissOption`)]})]}),t.mode===`answer`&&(0,X.jsxs)(`div`,{className:`mt-3`,children:[(0,X.jsx)(iv,{htmlFor:`answer-${e.id}`,className:`sr-only`,children:i(`buildOpenQuestionsDialog.answerLabel`,{question:e.question_text})}),(0,X.jsx)(Y_,{id:`answer-${e.id}`,value:t.answer,onChange:t=>x(e.id,{mode:`answer`,answer:t.target.value}),placeholder:i(`buildOpenQuestionsDialog.answerPlaceholder`),rows:3,className:`max-h-64 resize-y break-words`})]})]},e.id)})})]},e.ticket.id)),o.length===0&&!d&&(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`buildOpenQuestionsDialog.empty`)})]}),(0,X.jsxs)(G_,{className:`items-start border-t border-border/70 px-5 py-4 sm:items-center sm:px-6`,children:[(0,X.jsxs)(`div`,{className:`mr-auto min-w-0 text-xs leading-5 text-muted-foreground`,"aria-live":`polite`,children:[g&&(0,X.jsx)(`p`,{className:`text-destructive`,children:g}),!g&&b&&(0,X.jsx)(`p`,{children:i(`buildOpenQuestionsDialog.dismissSummary`)}),!g&&!y&&!b&&(0,X.jsx)(`p`,{children:i(`buildOpenQuestionsDialog.incompleteSummary`)})]}),m&&(0,X.jsx)(Q,{type:`button`,variant:`outline`,onClick:()=>{h(!1),_(null)},children:i(`buildOpenQuestionsDialog.reviewRefreshed`)}),(0,X.jsx)(Q,{type:`button`,variant:`ghost`,onClick:t,children:i(`buildOpenQuestionsDialog.cancel`)}),(0,X.jsx)(Q,{type:`submit`,disabled:!v||m||d,children:i(d?`buildOpenQuestionsDialog.submitting`:`buildOpenQuestionsDialog.submit`)})]})]})})})},K6={blocked:{className:`stroke-red-400/80`,markerId:`dependency-arrowhead-blocked`},ready:{className:`stroke-emerald-400/80`,markerId:`dependency-arrowhead-ready`},preview:{className:`stroke-amber-300/80`,markerId:`dependency-arrowhead-preview`}},Vpe=e=>qv(e)?`ready`:`blocked`,q6=180,Hpe=560,J6=88,Y6=12,X6=18,Z6=`dependency-overlay-clip`,Q6=(e,t,n)=>Math.min(Math.max(e,t),n),Upe=(e,t)=>{if(!e||e.width<=0||e.height<=0||t.length===0)return null;let n=`M 0 0 H ${e.width} V ${e.height} H 0 Z`,r=t.filter(e=>e.width>0&&e.height>0).map(e=>`M ${e.left} ${e.top} H ${e.left+e.width} V ${e.top+e.height} H ${e.left} Z`);return r.length===0?null:`${n} ${r.join(` `)}`},Wpe=(e,t,n)=>n&&n.width>0&&n.height>0?n:Object.values(e).reduce((e,t)=>({width:Math.max(e.width,t.left+t.width),height:Math.max(e.height,t.top+t.height)}),{width:t.x,height:t.y}),Gpe=(e,t)=>{let n=Q6(Math.round(e.length*7.2)+24,q6,Hpe),r=Math.max(q6,t-Y6*2);return Math.min(n,r)},Kpe=(e,t,n,r,i)=>{let a=n.get(e.blockerTicketId);if(!a)return null;let o=e.hoveredTicketId&&e.hoveredTicketId!==e.blockerTicketId?r[e.hoveredTicketId]:null,s=e.hoveredTicketId&&e.hoveredTicketId!==e.blockerTicketId?n.get(e.hoveredTicketId):null,c=s?`${a.title} is blocking ${s.title}`:`${a.title} is blocking...`,{start:l,end:u}=ty(t,o??{left:e.pointer.x,top:e.pointer.y,width:0,height:0}),d=Wpe(r,e.pointer,i),f=o&&s?{x:l.x+(u.x-l.x)*.6,y:l.y+(u.y-l.y)*.6-28}:{x:u.x,y:u.y-28},p=Gpe(c,d.width);return{text:c,x:o&&s?Q6(f.x-p/2,Y6,Math.max(Y6,d.width-p-Y6)):(()=>{let e=f.x+X6,t=f.x-X6-p;return e+p<=d.width-Y6?e:t>=Y6?t:Q6(e,Y6,Math.max(Y6,d.width-p-Y6))})(),y:Q6(f.y,Y6,Math.max(Y6,d.height-J6-Y6)),width:p}},$6=({blockerRect:e,dependentRect:t,className:n,testId:r,markerEnd:i})=>{let{start:a,end:o}=ty(e,t),{path:s}=ny(a,o);return(0,X.jsx)(`g`,{"data-testid":r,children:(0,X.jsx)(`path`,{d:s,className:n,fill:`none`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,markerEnd:i})})},qpe=({preview:e,cardRects:t,ticketsById:n,overlaySize:r})=>{if(!e)return null;let i=t[e.blockerTicketId];if(!i)return null;let a=(e.hoveredTicketId&&e.hoveredTicketId!==e.blockerTicketId&&t[e.hoveredTicketId]?t[e.hoveredTicketId]:null)??{left:e.pointer.x,top:e.pointer.y,width:0,height:0},o=Kpe(e,i,n,t,r);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)($6,{blockerRect:i,dependentRect:a,className:K6.preview.className,testId:`dependency-preview`,markerEnd:`url(#${K6.preview.markerId})`}),(e=>o?(0,X.jsx)(`foreignObject`,{x:o.x,y:o.y,width:o.width,height:J6,"data-testid":`dependency-preview-label`,children:e}):null)((0,X.jsx)(`div`,{className:`pointer-events-none flex h-full w-full items-start`,children:(0,X.jsx)(`div`,{className:`max-w-full rounded-md border border-amber-300/60 bg-stone-950/85 px-3 py-1.5 text-xs font-medium leading-5 text-amber-100 shadow-lg shadow-stone-950/20 whitespace-normal break-words`,children:o?.text})}))]})},Jpe=({dependencies:e,cardRects:t,clipRects:n=[],preview:r,ticketsById:i,overlaySize:a})=>{let o=Upe(a,n);return(0,X.jsxs)(`svg`,{className:`pointer-events-none absolute inset-0 z-10 h-full w-full overflow-visible`,children:[(0,X.jsxs)(`defs`,{children:[Object.values(K6).map(e=>(0,X.jsx)(`marker`,{id:e.markerId,markerWidth:`8`,markerHeight:`8`,refX:`7`,refY:`4`,orient:`auto`,markerUnits:`userSpaceOnUse`,children:(0,X.jsx)(`path`,{d:`M 0 0 L 8 4 L 0 8`,className:e.className,fill:`none`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`})},e.markerId)),o&&(0,X.jsx)(`clipPath`,{id:Z6,children:(0,X.jsx)(`path`,{d:o,clipRule:`evenodd`})})]}),(0,X.jsxs)(`g`,{"data-testid":`dependency-overlay-content`,clipPath:o?`url(#${Z6})`:void 0,children:[e.map(e=>{let n=i.get(e.blocker_ticket_id),r=i.get(e.dependent_ticket_id),a=t[e.blocker_ticket_id],o=t[e.dependent_ticket_id];if(n?.parked_at||r?.parked_at)return null;let s=K6[Vpe(n)];return!a||!o?null:(0,X.jsx)($6,{blockerRect:a,dependentRect:o,className:s.className,testId:`dependency-edge-${e.blocker_ticket_id}-${e.dependent_ticket_id}`,markerEnd:`url(#${s.markerId})`},`${e.blocker_ticket_id}:${e.dependent_ticket_id}`)}),(0,X.jsx)(qpe,{preview:r,cardRects:t,ticketsById:i,overlaySize:a})]})]})},Ype=({onOpenProjectExecutionSettings:e})=>{let{t}=q(`common`);return(0,X.jsxs)(`p`,{className:`mt-2 w-full max-w-none text-xs leading-relaxed text-amber-200/90`,role:`status`,children:[t(`modelSelector.dockerSandboxNotice`),e&&(0,X.jsx)(Q,{type:`button`,variant:`link`,size:`xs`,className:`ml-1 h-auto align-baseline px-0 text-xs font-medium text-amber-100`,onClick:e,children:t(`modelSelector.openExecutionSettings`)})]})},Xpe=({onSubmit:e,bundles:t,projectId:n=null,projectBranchState:r=null,tool:i,showModelSelector:a=!1,showSkillsSelector:o=!1,availableModels:s=[],availableSkills:c=[],initialModel:l=``,initialVariant:u=``,initialSkills:d=[],initialWorktreeBundleId:f=null,initialImportedDraft:p=null,onCreateBundle:m,onDeleteBundle:h,onRefreshBundles:g,showDockerSandboxModelNotice:_=!1,onOpenProjectExecutionSettings:v,onClose:y})=>{let{t:b}=q(`common`),{jiraImportState:x,importFromJira:S}=mw(n),{gitHubImportState:C,importFromGitHub:w}=IC(n),T=[{key:`jira`,label:b(`jiraImportField.label`),placeholder:b(`jiraImportField.placeholder`),state:x,onImport:S},{key:`github`,label:b(`githubImportField.label`),placeholder:b(`githubImportField.placeholder`),state:C,onImport:w}];return(0,X.jsx)(tC,{onClose:y,overlayClassName:`bg-black/70`,panelClassName:`h-[92vh] w-[96vw] max-w-6xl overflow-y-auto rounded-2xl border border-border bg-card p-4 shadow-2xl sm:p-5 lg:p-6`,renderContent:({closeButton:x})=>(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`absolute right-4 top-4 z-10 sm:right-5 sm:top-5 lg:right-6 lg:top-6`,children:x}),(0,X.jsx)(FY,{heading:b(`newTicketModal.heading`),bundles:t,showModelSelector:a,showSkillsSelector:o,availableModels:s,availableSkills:c,projectId:n,initialModel:l,initialVariant:u,initialSkills:d,initialWorktreeBundleId:f,initialImportedDraft:p,projectBranchState:r,externalImportProviders:T,onCancel:y,onCreateBundle:m,onDeleteBundle:h,onRefreshBundles:g,modelSelectorNotice:_?(0,X.jsx)(Ype,{onOpenProjectExecutionSettings:v}):void 0,titleInputId:`title`,descriptionInputId:`description`,bundleSelectId:`new-ticket-bundle`,modelSelectId:`new-model`,variantSelectId:`new-variant`,skillsSelectId:`new-skills`,showEmptyBundleOption:!0,planAction:i?{label:b(`newTicketModal.actions.plan`),onClick:async({title:t,description:n,model:r,variant:i,skills:a,worktree_bundle_id:o,external_source:s})=>{await e(t,n,`plan`,r,i,a,{worktree_bundle_id:o??void 0,...s?{external_source:s}:{}}),y()}}:void 0,primaryAction:{label:b(`newTicketModal.actions.createTicket`),variant:`subtle`,onClick:async({title:t,description:n,model:r,variant:i,skills:a,worktree_bundle_id:o,external_source:s})=>{await e(t,n,`create`,r,i,a,{worktree_bundle_id:o??void 0,...s?{external_source:s}:{}}),y()}},secondaryAction:{label:b(`newTicketModal.actions.createAndBuild`),variant:`brand`,showAdvanceIcon:!0,onClick:async({title:t,description:n,model:r,variant:i,skills:a,worktree_bundle_id:o,external_source:s})=>{await e(t,n,`build`,r,i,a,{worktree_bundle_id:o??void 0,...s?{external_source:s}:{}}),y()}}})]})})},Zpe=({className:e=``})=>{let{setNodeRef:t,isOver:n}=KP({id:`trash`});return(0,X.jsxs)(`div`,{ref:t,"data-testid":`delete-drop-zone`,className:`${e} flex min-w-[13rem] select-none items-center justify-between gap-4 rounded-2xl border px-4 py-3 backdrop-blur-sm transition-all duration-150 ${n?`scale-[1.02] border-red-400/70 bg-destructive/35 text-red-100 shadow-lg shadow-red-950/30`:`border-red-500/30 bg-background/82 text-red-200/85`}`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(rC,{variant:`destructive`,className:`text-[11px] uppercase tracking-[0.28em]`,children:`Delete`}),(0,X.jsx)(`div`,{className:`mt-1 text-sm font-medium`,children:n?`Release to delete`:`Drop here to delete`})]}),(0,X.jsx)(`div`,{className:`rounded-xl border p-2 transition-colors ${n?`border-red-400/60 bg-red-500/20`:`border-red-500/20 bg-background/60`}`,children:(0,X.jsx)(fC,{className:`h-5 w-5 transition-colors ${n?`text-red-100`:`text-red-300/70`}`})})]})},Qpe=(e,t)=>Y(Je(`/ticket-dependencies`,e),{signal:t}),$pe=(e,t)=>Y(Je(`/ticket-dependencies`,e),{method:`POST`,body:t,fallbackErrorMessage:`Unable to create the dependency right now.`}),eme=(e,t,n)=>Ze(Je(`/ticket-dependencies/${t}/${n}`,e),{method:`DELETE`,fallbackErrorMessage:`Unable to remove the dependency right now.`}),tme=(e,t)=>{let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n){let n=e[r],i=t[r];if(!n||!i||n.left!==i.left||n.top!==i.top||n.width!==i.width||n.height!==i.height)return!1}return!0},nme=(e,t)=>e.length===t.length?e.every((e,n)=>{let r=t[n];return r!==void 0&&e.left===r.left&&e.top===r.top&&e.width===r.width&&e.height===r.height}):!1,rme=(e,t)=>e===t?!0:!e||!t?!1:e.projectId===t.projectId&&e.blockerTicketId===t.blockerTicketId&&e.hoveredTicketId===t.hoveredTicketId&&e.pointer.x===t.pointer.x&&e.pointer.y===t.pointer.y,ime=({activeProjectId:e,tickets:t,dependencies:n,setDependencies:r,activeTicket:i,activeOverlayNode:a,dragOffset:o})=>{let[s,c]=(0,p.useState)({}),[l,u]=(0,p.useState)([]),[d,f]=(0,p.useState)({width:0,height:0}),[m,h]=(0,p.useState)(null),[g,_]=(0,p.useState)(null),v=(0,p.useRef)(null),y=(0,p.useRef)(null),b=(0,p.useRef)(null),x=(0,p.useRef)(new Map),S=(0,p.useRef)(new Map),C=(0,p.useRef)({}),w=(0,p.useRef)(null),T=(0,p.useRef)(null),E=(0,p.useRef)(null),D=(0,p.useRef)(null),O=(0,p.useRef)(null),k=(0,p.useRef)(null),A=(0,p.useRef)(null),j=(0,p.useMemo)(()=>new Map(t.map(e=>[e.id,e])),[t]);(0,p.useEffect)(()=>{O.current=g},[g]),(0,p.useLayoutEffect)(()=>{if(!i||!a||!y.current)return;let e=window.requestAnimationFrame(()=>{let e=y.current?.getBoundingClientRect(),t=a.getBoundingClientRect();e&&h({ticketId:i.id,rect:{left:t.left-e.left,top:t.top-e.top,width:t.width,height:t.height}})});return()=>{window.cancelAnimationFrame(e)}},[a,i,o.x,o.y]);let M=(0,p.useCallback)(()=>{w.current===null&&(w.current=window.requestAnimationFrame(()=>{w.current=null;let e=y.current;if(!e){b.current=null,C.current={},c({}),u([]),f({width:0,height:0});return}let t=e.getBoundingClientRect(),n={};b.current={left:t.left,top:t.top},f(e=>e.width===t.width&&e.height===t.height?e:{width:t.width,height:t.height});for(let[e,r]of x.current){let i=r.getBoundingClientRect();n[e]={left:i.left-t.left,top:i.top-t.top,width:i.width,height:i.height}}let r=Array.from(S.current.values()).flatMap(({columnNode:e,listNode:n})=>{let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),a=Math.max(0,i.top-r.top);return r.width<=0||a<=0?[]:[{left:r.left-t.left,top:r.top-t.top,width:r.width,height:a}]});u(e=>nme(e,r)?e:r),C.current=n,c(e=>tme(e,n)?e:n)}))},[]);(0,p.useEffect)(()=>{let e=v.current;if(!e)return;let t=()=>{M()};return e.addEventListener(`scroll`,t,!0),window.addEventListener(`resize`,t),()=>{e.removeEventListener(`scroll`,t,!0),window.removeEventListener(`resize`,t)}},[M]),(0,p.useEffect)(()=>{if(typeof ResizeObserver!=`function`)return;let e=new ResizeObserver(()=>{M()});T.current=e;for(let t of x.current.values())e.observe(t);return()=>{e.disconnect(),T.current===e&&(T.current=null)}},[M]),(0,p.useEffect)(()=>{if(typeof ResizeObserver!=`function`)return;let e=new ResizeObserver(()=>{M()});E.current=e;for(let t of S.current.values())e.observe(t.columnNode),e.observe(t.listNode);return()=>{e.disconnect(),E.current===e&&(E.current=null)}},[M]),(0,p.useEffect)(()=>{let e=v.current,t=y.current;if(!e&&!t)return;let n=new ResizeObserver(()=>{M()});return e&&n.observe(e),t&&t!==e&&n.observe(t),()=>{n.disconnect()}},[M]),(0,p.useEffect)(()=>(M(),()=>{w.current!==null&&(window.cancelAnimationFrame(w.current),w.current=null)}),[n,M,t]);let N=(0,p.useCallback)((e,t)=>{let n=x.current.get(e);if(t){if(n===t)return;x.current.set(e,t),T.current?.observe(t)}else{if(!n)return;x.current.delete(e),T.current?.unobserve(n)}M()},[M]),P=(0,p.useCallback)((e,t)=>{let n=S.current.get(e);if(t){if(n?.columnNode===t.columnNode&&n.listNode===t.listNode)return;n&&(E.current?.unobserve(n.columnNode),E.current?.unobserve(n.listNode)),S.current.set(e,t),E.current?.observe(t.columnNode),E.current?.observe(t.listNode)}else{if(!n)return;S.current.delete(e),E.current?.unobserve(n.columnNode),E.current?.unobserve(n.listNode)}M()},[M]),F=(0,p.useCallback)(e=>{rme(O.current,e)||(O.current=e,_(e))},[]),I=(0,p.useCallback)(()=>{k.current!==null&&(window.cancelAnimationFrame(k.current),k.current=null),A.current=null},[]),L=(0,p.useCallback)(e=>{A.current=e,k.current===null&&(k.current=window.requestAnimationFrame(()=>{k.current=null;let e=A.current;A.current=null,F(e)}))},[F]),R=(0,p.useCallback)((e,t)=>{let n=b.current;if(!n&&y.current){let e=y.current.getBoundingClientRect();n={left:e.left,top:e.top},b.current=n}return n?{x:e-n.left,y:t-n.top}:{x:e,y:t}},[]),z=(0,p.useCallback)((e,t,n)=>{for(let[r,i]of Object.entries(C.current))if(r!==n&&e>=i.left&&e<=i.left+i.width&&t>=i.top&&t<=i.top+i.height)return r;return null},[]),ee=(0,p.useCallback)(async t=>{if(e)try{await eme(e,t.blocker_ticket_id,t.dependent_ticket_id),r(e=>Gv(e,t.blocker_ticket_id,t.dependent_ticket_id))}catch(e){$.error(e instanceof Ge?e.message:`Unable to remove the dependency right now.`,{id:`board-dependency-error`})}},[e,r]),B=(0,p.useCallback)((t,i)=>{if(!e)return;i.preventDefault(),D.current?.();let a=(n,r,i=!1)=>{let a=R(n,r),o={projectId:e,blockerTicketId:t,hoveredTicketId:z(a.x,a.y,t),pointer:a};if(i){I(),F(o);return}L(o)};a(i.clientX,i.clientY,!0);let o=e=>{a(e.clientX,e.clientY)},s=async i=>{let a=R(i.clientX,i.clientY),o=z(a.x,a.y,t),s=o?Kv(n,t,o):null;if(D.current?.(),D.current=null,F(null),!(!o||!s)){if(!s.valid){$.error(dne(s.reason),{id:`board-dependency-error`});return}try{let n=await $pe(e,{blocker_ticket_id:t,dependent_ticket_id:o});r(e=>Wv(e,n))}catch(e){$.error(e instanceof Ge?e.message:`Unable to create the dependency right now.`,{id:`board-dependency-error`})}}};D.current=()=>{window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),I()},window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s,{once:!0})},[e,I,n,z,R,L,r,F]);(0,p.useEffect)(()=>{D.current?.(),D.current=null,I(),O.current=null},[e,I]),(0,p.useEffect)(()=>()=>{D.current?.(),k.current!==null&&(window.cancelAnimationFrame(k.current),k.current=null)},[]);let V=(0,p.useMemo)(()=>{let r=g?.blockerTicketId;if(!r||g.projectId!==e||!j.has(r))return null;let i=new Map;for(let e of t){if(e.id===r){i.set(e.id,`source`);continue}let t=Kv(n,r,e.id);i.set(e.id,t.valid?`valid`:`idle`)}return i},[e,n,g,j,t]),H=(0,p.useCallback)(e=>{if(!V||!g)return`idle`;let t=V.get(e)??`idle`;return e===g.hoveredTicketId&&t===`idle`?`invalid`:t},[V,g]),U=(0,p.useMemo)(()=>!g||g.projectId!==e||!j.has(g.blockerTicketId)?null:{blockerTicketId:g.blockerTicketId,hoveredTicketId:g.hoveredTicketId,pointer:g.pointer},[e,g,j]);return{boardViewportRef:v,boardContentRef:y,registerTicketNode:N,registerDependencyClipNodes:P,measuredCardRects:(0,p.useMemo)(()=>{if(!i)return s;let e=s[i.id];return e?m?.ticketId===i.id?{...s,[i.id]:m.rect}:{...s,[i.id]:{...e,left:e.left+o.x,top:e.top+o.y}}:s},[m,i,s,o.x,o.y]),dependencyClipRects:l,overlayPreview:U,overlaySize:d,getDependencyTargetState:H,handleDependencyStart:B,handleDeleteDependency:ee}},ame=`[data-terminal-pane="true"]`,ome=e=>{if(!(e instanceof HTMLElement))return!1;let t=e.tagName.toLowerCase();return t===`input`||t===`textarea`||e.isContentEditable},sme=e=>e instanceof HTMLElement?e.closest(ame)!==null:!1,cme=e=>ome(e)||sme(e),lme=(e,t={})=>{let{isBlocked:n}=t;(0,p.useEffect)(()=>{let t=t=>{if(t.defaultPrevented||t.repeat)return;let r=e.find(e=>!e.disabled&&e.key.toLowerCase()===t.key.toLowerCase()&&(e.ctrlKey??!1)===t.ctrlKey&&(e.altKey??!1)===t.altKey&&(e.metaKey??!1)===t.metaKey&&(e.shiftKey===void 0||e.shiftKey===t.shiftKey));r&&(n?.(document.activeElement)||(t.preventDefault(),r.onKeyDown()))};return window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`keydown`,t)}},[e,n])},e8=new Set([`queued`,`running`]),ume={check_batch:`checks`,check_repair:`auto_fix`,automation_review_fix:`auto_fix`,automation_commit:`commit`,automation_push:`push`,automation_pull_request:`pr`},t8=e=>{if(!e.id)return null;let t=Date.parse(e.updated_at);return Number.isFinite(t)?t:null},dme=e=>{let t=e.source_reference;if(e.kind!==`automation_progression`||e.status!==`waiting`&&!e8.has(e.status)||e.initiated_by!==`automation`&&e.initiated_by!==`recovery`||!t||typeof t!=`object`||t.kind!==`bundle`||typeof t.id!=`string`)return null;let n=t.id.trim(),r=t8(e);return!n||r===null?null:{bundleId:n,id:e.id,isActive:e8.has(e.status),updatedAt:r}},fme=e=>{let t=ume[e.kind],n=t8(e);return!t||!e8.has(e.status)||e.initiated_by!==`automation`||!e.parent_run_id||n===null?null:{id:e.id,parentRunId:e.parent_run_id,status:t,updatedAt:n}},n8=(e,t)=>e.updatedAt===t.updatedAt?e.id.localeCompare(t.id)>0:e.updatedAt>t.updatedAt,pme=e=>{let t=new Map,n=[];for(let r of e){if(!r||typeof r!=`object`)continue;let e=dme(r);if(e){let n=t.get(e.bundleId);(!n||n8(e,n))&&t.set(e.bundleId,e);continue}let i=fme(r);i&&n.push(i)}let r=new Map,i=new Map;for(let e of t.values())e.isActive&&(r.set(e.id,e.bundleId),i.set(e.bundleId,`automation`));let a=new Map;for(let e of n){let t=r.get(e.parentRunId);if(!t)continue;let n=a.get(t);(!n||n8(e,n))&&a.set(t,e)}for(let[e,t]of a)i.set(e,t.status);return i},r8=`archon.last-model-selection`,i8=`archon.last-variant-selection`,a8=`archon.last-skills-selection`,mme=()=>{try{let e=window.localStorage.getItem(a8),t=e?JSON.parse(e):[];return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}},o8=()=>({build:!1,stopBuild:!1,resumeBuild:!1,review:!1,undoReview:!1,run:!1,stop:!1,followUp:!1,bundleRefresh:!1}),hme=(e,t,n)=>{e?window.localStorage.setItem(r8,e):window.localStorage.removeItem(r8),t?window.localStorage.setItem(i8,t):window.localStorage.removeItem(i8),n.length>0?window.localStorage.setItem(a8,JSON.stringify(n)):window.localStorage.removeItem(a8)},s8=(e,t={})=>Vy(e,t),gme=()=>({model:window.localStorage.getItem(`archon.last-model-selection`)??``,variant:window.localStorage.getItem(`archon.last-variant-selection`)??``,skills:mme()}),c8={runs:[],events:[],isLoading:!1,isLoadingMore:!1,hasMoreRuns:!1,hasMoreEvents:!1,error:null},l8=(0,p.createContext)({state:new Map,loadMoreProject:()=>void 0,refreshProject:()=>void 0,subscribeProject:()=>()=>void 0}),_me=[`queued`,`waiting`,`running`],vme=(e,t,n,r)=>hue(e,{cursor:t,limit:200,signal:n,statuses:r}),yme=(e,t,n)=>gue(e,{cursor:t,limit:200,signal:n}),bme=(e,t)=>{let n=t.created_at.localeCompare(e.created_at);return n===0?t.id.localeCompare(e.id):n},xme=(e,t)=>{let n=t.created_at.localeCompare(e.created_at);if(n!==0)return n;let r=t.execution_run_id.localeCompare(e.execution_run_id);if(r!==0)return r;let i=t.sequence-e.sequence;return i===0?t.id.localeCompare(e.id):i},u8=(e,t)=>{let n=new Map(e.map(e=>[e.id,e]));for(let e of t){let t=n.get(e.id);(!t||e.updated_at>=t.updated_at)&&n.set(e.id,e)}return[...n.values()].sort(bme)},d8=(e,t)=>{let n=new Map(e.map(e=>[e.id,e]));for(let e of t)n.set(e.id,e);return[...n.values()].sort(xme)},Sme=async(e,t,n)=>{let r=null,i=[];do{let a=await e(t,r,n,_me);i=u8(i,a.runs),r=a.next_cursor}while(r);return i},Cme=({socket:e,fetchRunsPage:t,fetchEventsPage:n,children:r})=>{let i=uq(),a=e??i,o=t??vme,s=n??yme,[c,l]=(0,p.useState)(()=>new Map),u=(0,p.useRef)(new Map),d=(0,p.useRef)(new Map),f=(0,p.useRef)(new Map),m=(0,p.useRef)(new Map),h=(0,p.useCallback)(e=>{d.current.get(e)?.abort();let t=new AbortController;d.current.set(e,t),m.current.set(e,{runs:[],events:[]}),l(t=>{let n=new Map(t),r=n.get(e)??c8;return n.set(e,{...r,isLoading:!0,isLoadingMore:!1,error:null}),n}),Promise.all([o(e,null,t.signal),Sme(o,e,t.signal),s(e,null,t.signal)]).then(([n,r,i])=>{if(t.signal.aborted||d.current.get(e)!==t)return;f.current.set(e,{runs:n.next_cursor,events:i.next_cursor});let a=m.current.get(e)??{runs:[],events:[]};l(t=>{let o=new Map(t);return o.set(e,{runs:u8(u8(n.runs,r),a.runs),events:d8(i.events,a.events),isLoading:!1,isLoadingMore:!1,hasMoreRuns:!!n.next_cursor,hasMoreEvents:!!i.next_cursor,error:null}),o})}).catch(t=>{Ye(t)||l(n=>{let r=new Map(n),i=r.get(e)??c8;return r.set(e,{...i,isLoading:!1,isLoadingMore:!1,error:t instanceof Error?t.message:`Unable to load activity right now.`}),r})}).finally(()=>{d.current.get(e)===t&&(d.current.delete(e),m.current.delete(e))})},[s,o]),g=(0,p.useCallback)(e=>{if(d.current.has(e))return;let t=f.current.get(e);if(!t||!t.runs&&!t.events)return;let n=new AbortController;d.current.set(e,n),l(t=>{let n=new Map(t),r=n.get(e)??c8;return n.set(e,{...r,isLoadingMore:!0,error:null}),n}),Promise.all([t.runs?o(e,t.runs,n.signal):Promise.resolve({runs:[],next_cursor:null}),t.events?s(e,t.events,n.signal):Promise.resolve({events:[],next_cursor:null})]).then(([t,r])=>{n.signal.aborted||d.current.get(e)!==n||(f.current.set(e,{runs:t.next_cursor,events:r.next_cursor}),l(n=>{let i=new Map(n),a=i.get(e)??c8;return i.set(e,{...a,runs:u8(a.runs,t.runs),events:d8(a.events,r.events),isLoadingMore:!1,hasMoreRuns:!!t.next_cursor,hasMoreEvents:!!r.next_cursor,error:null}),i}))}).catch(t=>{Ye(t)||l(n=>{let r=new Map(n),i=r.get(e)??c8;return r.set(e,{...i,isLoadingMore:!1,error:t instanceof Error?t.message:`Unable to load more activity right now.`}),r})}).finally(()=>{d.current.get(e)===n&&d.current.delete(e)})},[s,o]),_=(0,p.useCallback)(e=>{let t=u.current.get(e)??0;return u.current.set(e,t+1),t===0&&h(e),()=>{let t=(u.current.get(e)??1)-1;if(t>0){u.current.set(e,t);return}u.current.delete(e),d.current.get(e)?.abort(),d.current.delete(e),f.current.delete(e),m.current.delete(e),l(t=>{let n=new Map(t);return n.delete(e),n})}},[h]),v=(0,p.useCallback)(e=>{if(!e||!u.current.has(e.project_id))return;let t=m.current.get(e.project_id);t&&(t.runs=u8(t.runs,[e])),l(t=>{let n=new Map(t),r=n.get(e.project_id)??c8;return n.set(e.project_id,{...r,runs:u8(r.runs,[e]),isLoading:!1}),n})},[]),y=(0,p.useCallback)(e=>{if(!e||!u.current.has(e.project_id))return;let t=m.current.get(e.project_id);t&&(t.events=d8(t.events,[e])),l(t=>{let n=new Map(t),r=n.get(e.project_id)??c8;return n.set(e.project_id,{...r,events:d8(r.events,[e]),isLoading:!1}),n})},[]),b=(0,p.useCallback)(()=>{for(let e of u.current.keys())h(e)},[h]);(0,p.useEffect)(()=>(a.on(`execution-run:updated`,v),a.on(`lifecycle-event:created`,y),a.on(`connect`,b),()=>{a.off(`execution-run:updated`,v),a.off(`lifecycle-event:created`,y),a.off(`connect`,b)}),[b,y,v,a]),(0,p.useEffect)(()=>()=>{for(let e of d.current.values())e.abort()},[]);let x=(0,p.useMemo)(()=>({state:c,loadMoreProject:g,refreshProject:h,subscribeProject:_}),[g,h,c,_]);return(0,X.jsx)(l8.Provider,{value:x,children:r})},f8=e=>{let{loadMoreProject:t,refreshProject:n,state:r,subscribeProject:i}=(0,p.useContext)(l8);(0,p.useEffect)(()=>{if(e)return i(e)},[e,i]);let a=(0,p.useCallback)(()=>{e&&n(e)},[e,n]),o=(0,p.useCallback)(()=>{e&&t(e)},[t,e]);return{...e?r.get(e)??c8:c8,loadMore:o,refresh:a}},p8=e=>({...e,messages:void 0,agent_log:void 0,streaming_response:void 0}),m8=(e,t)=>e?e.state!==t.state||e.parked_at!==t.parked_at||e.worktree_bundle_id!==t.worktree_bundle_id:!0,h8=(e,t)=>{if(!e)return t;let n=t.worktree_bundle_id!==null&&e.worktree_bundle_id===t.worktree_bundle_id,r=t.bundle??(n&&e.bundle?.id===t.worktree_bundle_id?e.bundle:null),i=t.bundle_execution_position??(n?e.bundle_execution_position??null:null);return{...e,...t,diff_stats:t.diff_stats===void 0?e.diff_stats:t.diff_stats,is_stale:t.is_stale===void 0?e.is_stale:t.is_stale,bundle:r,bundle_execution_position:i}},g8=(e,t)=>{let n=e=>gy(t)?gy(e):e.state===t.state&&!gy(e),r=e.findIndex(e=>n(e));if(r===-1)return[...e,t];let i=[...e];return i.splice(r,0,t),i},_8=(e,t)=>{let n=e.find(e=>e.id===t.id);return[n&&n.pull_request!==void 0&&t.pull_request===void 0?{...n,...t,pull_request:n.pull_request}:t,...e.filter(e=>e.id!==t.id)]},v8=(e,t)=>{let n=e.find(e=>e.id===t.id);if(!n)return[...e,t];let r=h8(n,t);return e.map(e=>e.id===t.id?r:e)},y8=(e,t)=>{let n=h8(e.find(e=>e.id===t.id),t);return g8(b8(e,t.id),n)},wme=(e,t)=>{if(e.length===0)return[...t];let n=[...e];for(let e of t)n=m8(n.find(t=>t.id===e.id),e)?y8(n,e):v8(n,e);let r=new Set(t.map(e=>e.id));return n.filter(e=>r.has(e.id))},b8=(e,t)=>e.filter(e=>e.id!==t),x8=(e,t,n,r={},i={})=>{let a=e.findIndex(e=>e.id===t);if(a===-1)return e;let o={...e[a],state:n,...r},s=b8(e,t);if(i.preferredIndex!==void 0){let e=Math.max(0,Math.min(i.preferredIndex,s.length));return s.splice(e,0,o),s}return g8(s,o)},S8=e=>e.state===`review`&&e.agent_status===`done`&&!!e.automation_progression_run_id,Tme=e=>S8(e)&&!e.automation_paused_at,Eme=15*1e3,Dme=1e3,Ome=async(e,t)=>{let n=bde({projectId:t,ticketId:e.id,agentMessageId:e.agent_message_id});if(!n)return;let r=e.worktree_bundle_id!==null&&e.state!==`plan`?{kind:`bundle`,projectId:t,bundleId:e.worktree_bundle_id}:{kind:`ticket`,projectId:t,ticketId:e.id};await i3({title:`Ticket done`,body:e.title,key:n,destination:r})},C8=e=>p8(e),kme=(e,t)=>t===`running`&&e.agent_status===`done`?`Finished ${e.state} for "${e.title}"`:t===`running`&&e.agent_status===`error`?`Failed ${e.state} for "${e.title}"`:t!==`running`&&e.agent_status===`running`?`Running ${e.state} for "${e.title}"`:null,Ame=({activeProjectId:e,refreshKey:t=0,onLoadedProjectIdChange:n,onProjectUsageChange:r,onBundlesChange:i,onBundlesLoadingChange:a,children:o})=>{let s=uq(),[c,l]=(0,p.useState)([]),[u,d]=(0,p.useState)([]),[f,m]=(0,p.useState)([]),[h,g]=(0,p.useState)([]),[_,v]=(0,p.useState)(null),[y,b]=(0,p.useState)(null),[x,S]=(0,p.useState)(null),[C,w]=(0,p.useState)(null),[T,E]=(0,p.useState)(null),[D,O]=(0,p.useState)(null),k=(0,p.useRef)(0),A=(0,p.useRef)(0),j=(0,p.useRef)(new Map),M=(0,p.useRef)(new Map),N=(0,p.useRef)([]),P=(0,p.useRef)(e),F=(0,p.useRef)(new Map),I=(0,p.useRef)(new Map),L=(0,p.useRef)(new Map),R=(0,p.useCallback)((e,t)=>{let n=I.current.get(t.id);return!n||!e||t.state===n?t:e},[]),z=(0,p.useCallback)((e,t)=>{if(e.length===0)return;let n=new Map(I.current);for(let r of e)n.set(r,t);I.current=n},[]),ee=(0,p.useCallback)(e=>{if(e.length===0||I.current.size===0)return;let t=new Map(I.current);for(let n of e)t.delete(n);I.current=t},[]),B=(0,p.useCallback)((e,t)=>{if(e.length===0)return;let n=new Map(L.current);for(let r of e)n.set(r,t);L.current=n},[]),V=(0,p.useCallback)(e=>{if(e.length===0||L.current.size===0)return;let t=new Map(L.current);for(let n of e)t.delete(n);L.current=t},[]),H=(0,p.useCallback)((e,t)=>{if(F.current.has(t.id))return null;let n=R(e,t);return L.current.has(t.id)?{...n,parked_at:L.current.get(t.id)??null}:n},[R]),U=(0,p.useCallback)((e,t)=>{if(F.current.size===0&&I.current.size===0&&L.current.size===0)return t;let n=new Map(e.map(e=>[e.id,e]));return t.flatMap(e=>{let t=H(n.get(e.id),e);return t?[t]:[]})},[H]),W=(0,p.useCallback)(async(e,t)=>{let n=await an(e,t,{detail:`board`});return Array.isArray(n)?(!t?.aborted&&P.current===e&&l(e=>wme(e,U(e,n).map(C8))),n):null},[U]),te=(0,p.useCallback)(async(e,t)=>{await W(e,t)},[W]),ne=(0,p.useCallback)(async(e,t)=>{let n=++A.current,r=await on(e,t);if(!Array.isArray(r)||t?.aborted||P.current!==e||A.current!==n)return;let i=new Map(r.map(e=>[e.id,e]));l(e=>e.map(e=>{let t=i.get(e.id);return t?{...e,diff_stats:t.diff_stats??null,is_stale:t.is_stale}:e}))},[]),re=(0,p.useCallback)(e=>e.some(e=>e.is_stale===void 0),[]),ie=(0,p.useCallback)(async e=>{let t=P.current;if(!t)return null;try{let n=await sn(e,t);if(P.current!==t)return null;let r=M.current.get(n.id),i=H(r,n);if(!i)return null;let a=C8(i),o=m8(r,a);return l(e=>o?y8(e,a):v8(e,a)),n}catch{return null}},[H]),ae=(0,p.useCallback)(async t=>{if(!e){m([]);return}m(await gt(e,t))},[e]),G=(0,p.useMemo)(()=>new Map(c.map(e=>[e.id,e])),[c]),oe=(0,p.useMemo)(()=>{let e=c.filter(e=>e.agent_status===`running`),t=new Set(e.map(e=>e.worktree_bundle_id).filter(e=>typeof e==`string`&&e.trim().length>0));return{total_running:e.length,running_plan_count:e.filter(e=>e.state===`plan`).length,running_build_count:e.filter(e=>e.state===`build`).length,running_review_count:e.filter(e=>e.state===`review`).length,active_bundle_count:t.size,latest_message:D}},[D,c]);(0,p.useEffect)(()=>{if(M.current=G,N.current.length===0)return;let e=[],t=[];for(let n of N.current){let r=G.get(n.blocker_ticket_id),i=G.get(n.dependent_ticket_id);r&&i&&r.project_id===P.current&&i.project_id===P.current?e.push(n):t.push(n)}N.current=t,e.length>0&&d(t=>e.reduce((e,t)=>Wv(e,t),t))},[G]),(0,p.useEffect)(()=>{P.current=e,F.current.clear(),N.current=[],I.current.clear(),L.current.clear(),O(null),v(null),j.current.clear()},[e]),(0,p.useEffect)(()=>{n?.(C?null:y)},[y,C,n]),(0,p.useEffect)(()=>{if(i){if(!e){i(null,[]);return}if(x!==e){i(e,[]);return}i(e,f)}},[e,f,x,i]),(0,p.useEffect)(()=>{if(a){if(!e){a(null,!1);return}a(e,T===e)}},[e,T,a]),(0,p.useEffect)(()=>{let t=new AbortController,n=++k.current,r=null,i=async()=>{try{if(!e){l([]),d([]),m([]),b(null),S(null),w(null);return}l([]),d([]),m([]),b(null),S(null),w(e),E(e);let i=W(e,t.signal).finally(()=>{!t.signal.aborted&&k.current===n&&(b(e),w(null))}),a=Qpe(e,t.signal).then(e=>(!t.signal.aborted&&k.current===n&&d(e),e)),o=gt(e,t.signal).then(e=>(!t.signal.aborted&&k.current===n&&m(e),e)).finally(()=>{!t.signal.aborted&&k.current===n&&(S(e),E(null))}),[s,c,u]=await Promise.allSettled([i,a,o]);if(t.signal.aborted)return;s.status!==`fulfilled`&&!Ye(s.reason)&&l([]),c.status===`fulfilled`?d(c.value):Ye(c.reason)||d([]),u.status===`fulfilled`?m(u.value):Ye(u.reason)||m([]),s.status===`fulfilled`&&s.value!==null&&re(s.value)&&(r=window.setTimeout(()=>{t.signal.aborted||ne(e,t.signal)},Dme))}finally{!t.signal.aborted&&k.current===n&&(w(null),E(null))}},a=t=>{t.project_id===e&&(v(t),!F.current.has(t.id)&&(t.bundle&&m(e=>_8(e,t.bundle)),l(e=>y8(e,C8(t)))))},o=t=>{if(t.project_id===e&&v(t),l(n=>{if(t.project_id!==e)return b8(n,t.id);let r=n.find(e=>e.id===t.id),i=H(r,t);if(!i)return n;let a=C8(i);return m8(r,a)?y8(n,a):v8(n,a)}),t.project_id!==e){d(e=>Uv(e,t.id));return}t.bundle&&m(e=>_8(e,t.bundle))},c=({id:e})=>{F.current.delete(e),L.current.delete(e),I.current.delete(e),l(t=>b8(t,e)),d(t=>Uv(t,e))},u=({project_id:e,bundle_id:t,pull_request:n})=>{e===P.current&&(m(e=>e.map(e=>e.id===t?{...e,pull_request:n}:e)),l(e=>e.map(e=>e.worktree_bundle_id!==t||!e.bundle?e:{...e,bundle:{...e.bundle,pull_request:n}})),v(e=>e?.worktree_bundle_id!==t||!e.bundle?e:{...e,bundle:{...e.bundle,pull_request:n}}))},f=e=>{if(!e)return;let t=M.current.get(e.blocker_ticket_id),n=M.current.get(e.dependent_ticket_id);if(!t||!n){N.current.push(e);return}t.project_id!==P.current||n.project_id!==P.current||d(t=>Wv(t,e))},p=e=>{d(t=>Gv(t,e.blocker_ticket_id,e.dependent_ticket_id))};return i(),s.on(`ticket:created`,a),s.on(`ticket:updated`,o),s.on(`ticket:deleted`,c),s.on(`bundle-pull-request:updated`,u),s.on(`ticket-dependency:created`,f),s.on(`ticket-dependency:deleted`,p),()=>{t.abort(),r!==null&&window.clearTimeout(r),s.off(`ticket:created`,a),s.off(`ticket:updated`,o),s.off(`ticket:deleted`,c),s.off(`bundle-pull-request:updated`,u),s.off(`ticket-dependency:created`,f),s.off(`ticket-dependency:deleted`,p)}},[e,ne,t,re,W,H,s]),(0,p.useEffect)(()=>{if(!e)return;let t=new AbortController,n=()=>{document.visibilityState===`visible`&&Promise.allSettled([W(e,t.signal),ae(t.signal)]).then(n=>{n[0]?.status===`fulfilled`&&n[0].value!==null&&re(n[0].value)&&ne(e,t.signal)}).catch(()=>{})},r=window.setInterval(n,Eme),i=hx(n);return()=>{t.abort(),window.clearInterval(r),i()}},[e,ae,ne,re,W]),(0,p.useEffect)(()=>{if(!e||!r||y!==e)return;let t=c.filter(e=>{let t=e.bundle?.branch??e.branch;return typeof t==`string`&&t.trim()!==``}).length;r({projectId:e,ticketCount:c.length,worktreeCount:t,repoPathLocked:c.length>0||t>0||f.length>0})},[e,f.length,y,r,c]),(0,p.useEffect)(()=>{if(e)for(let t of c){let n=j.current.get(t.id),r=S8(t),i=kme(t,n);i&&!r&&O(i),!r&&n!==void 0&&n===`running`&&t.agent_status===`done`&&(t.state===`plan`||t.state===`build`||t.state===`review`)&&Ome(t,e),r||j.current.set(t.id,t.agent_status)}},[e,c]);let se=(0,p.useCallback)(()=>{v(null)},[]),ce=(0,p.useMemo)(()=>({tickets:c,setTickets:l,dependencies:u,setDependencies:d,bundles:f,setBundles:m,pendingApprovalRequests:h,setPendingApprovalRequests:g,latestDetailedTicketUpdate:_,clearLatestDetailedTicketUpdate:se,loadedProjectId:y,bundlesLoadedProjectId:x,loadingProjectId:C,activeProjectIdRef:P,pendingDeletedTicketsRef:F,pendingOptimisticMovesRef:I,pendingParkedTicketsRef:L,refreshTickets:te,requestSingleTicketRefresh:ie,refreshBundles:ae,resolvePendingTicket:H,resolvePendingTickets:U,markPendingOptimisticMoves:z,clearPendingOptimisticMoves:ee,markPendingParkedTickets:B,clearPendingParkedTickets:V,liveActivity:oe}),[f,x,se,ee,V,u,oe,y,_,C,z,B,h,ae,te,ie,H,U,c]);return(0,X.jsx)(a3.Provider,{value:ce,children:o})},w8=(e,t)=>{let n=b8(e,t.ticket.id),r=Math.max(0,Math.min(t.index,n.length));return n.splice(r,0,t.ticket),n},T8=(0,p.lazy)(()=>HW(()=>import(`./VerificationDialog-CYCrlqmj.js`).then(e=>({default:e.VerificationDialog})),__vite__mapDeps([19,3]))),E8=[`plan`,`build`,`review`],D8=`done`,jme=({activeProjectId:e,activeProject:t=null,activeProjectBranchState:n=null,activeRun:r,activeTool:i,onPreviewReviewCapabilityChange:a,onRunStopped:o,onRunStatusChange:s,onViewSourceSpec:c,onNavigateToLifecycleSource:l,onStartChatFromBundle:u,refreshKey:d=0,boardFilterState:f,onBoardFilterStateChange:m,initialTicketId:h=null,onInitialTicketNavigationConsumed:g,onInitialTicketNavigationUnavailable:_,routedTicketId:v,routedModalStack:y=[],onTicketOpen:b,onTicketClose:x,routedBundleId:S,routedInspection:C=null,routedInspectionReviewCapability:w,inspectionOnly:T=!1,onBundleOpen:E,onBundleClose:D,onInspectionOpen:O,onInspectionModeChange:k,onInspectionClose:A,onInspectionUnavailable:j,initialImportedDraft:M=null,onInitialImportedDraftConsumed:N,onOpenProjectExecutionSettings:P})=>{let{t:F}=q(`common`),I=roe(noe(bP,{activationConstraint:{distance:5}})),{tickets:L,setTickets:R,dependencies:z,setDependencies:ee,bundles:B,setBundles:V,latestDetailedTicketUpdate:H,clearLatestDetailedTicketUpdate:U,loadedProjectId:W,bundlesLoadedProjectId:te,loadingProjectId:ne,activeProjectIdRef:re,pendingDeletedTicketsRef:ie,requestSingleTicketRefresh:ae,refreshBundles:G,resolvePendingTicket:oe,markPendingOptimisticMoves:se,clearPendingOptimisticMoves:ce,markPendingParkedTickets:le,clearPendingParkedTickets:ue}=o3(),{runs:de}=f8(e),fe=(0,p.useMemo)(()=>{let e=pme(de);for(let t of L)t.worktree_bundle_id&&t.automation_paused_reason&&e.delete(t.worktree_bundle_id);return e},[de,L]),[pe,me]=(0,p.useState)(null),[he,ge]=(0,p.useState)(null),[_e,ve]=(0,p.useState)(null),ye=(0,p.useCallback)(e=>ve(e),[]),[be,xe]=(0,p.useState)(null),[Se,Ce]=(0,p.useState)({x:0,y:0}),[we,Te]=(0,p.useState)(null),[Ee,De]=(0,p.useState)([]),[Oe,ke]=(0,p.useState)(null),Ae=QP(`opencode`),je=QP(`claude`),Me=(0,p.useMemo)(()=>({opencode:Ae.models,claude:je.models}),[Ae.models,je.models]),Ne={opencode:Ae.isLoading,claude:je.isLoading},Pe=(0,p.useCallback)(e=>{let n=Me[e]??[];return t?.build_execution_provider===`docker_sandbox`?LT(n,Oe?Oe.approved_providers?.[e]??[]:[]):n},[t?.build_execution_provider,Oe,Me]),Fe=(0,p.useMemo)(()=>({opencode:Pe(`opencode`),claude:Pe(`claude`)}),[Pe]);(0,p.useEffect)(()=>{if(!e||t?.build_execution_provider!==`docker_sandbox`){ke(null);return}let n=new AbortController;return ke(null),Yb(e,n.signal).then(e=>{n.signal.aborted||ke(e)}).catch(e=>{!Ye(e)&&!n.signal.aborted&&ke(null)}),()=>n.abort()},[t?.build_execution_provider,e]);let Ie=(0,p.useMemo)(()=>{if(t?.build_execution_provider!==`docker_sandbox`)return Ee;let e=Oe?.available_skills?.opencode;if(!e)return[];let n=new Map(Ee.map(e=>[e.name,e]));return e.map(e=>n.get(e)??{name:e,description:``})},[t?.build_execution_provider,Ee,Oe?.available_skills?.opencode]),[Le,K]=(0,p.useState)(!1),[Re,ze]=(0,p.useState)(!1),[Be,Ve]=(0,p.useState)(!1),[He,Ue]=(0,p.useState)(null),[We,Ke]=(0,p.useState)(null),[J,qe]=(0,p.useState)(null),Je=(0,p.useRef)(null),Xe=v===void 0?h:v,Ze=(0,p.useRef)(null),Y=(0,p.useRef)(null),[Qe,$e]=(0,p.useState)(null),et=(0,p.useRef)(null),[tt,nt]=(0,p.useState)(null),[rt,it]=(0,p.useState)(null),[at,ot]=(0,p.useState)(null),[st,ct]=(0,p.useState)(null),lt=(0,p.useRef)(0),[ut,dt]=(0,p.useState)(null),[ft,pt]=(0,p.useState)(null),[mt,ht]=(0,p.useState)(null),[gt,vt]=(0,p.useState)(!1),[yt,St]=(0,p.useState)(o8()),[Ct,wt]=(0,p.useState)(0),[At,jt]=(0,p.useState)(()=>({query:``,hideStaleTickets:!1,hideBundlesWithPullRequests:!1})),Mt=f??At,zt=e=>{let t={...Mt,...e};if(m){m(t);return}jt(t)},Bt=bF(i)||bF(J?.tool)||!!rt?.tickets.some(e=>bF(yF(e,i))),Vt=bF(i)&&(Pe(i).length>0||t?.build_execution_provider===`docker_sandbox`&&Me[i].length>0),Ht=bF(yF(J,i))&&Pe(yF(J,i)).length>0,Ut=!!rt?.tickets.some(e=>bF(yF(e,i)))&&(Fe.opencode.length>0||Fe.claude.length>0),Wt=(0,p.useRef)(null),[Gt,Kt]=(0,p.useState)(null),qt=L.find(e=>e.is_running)??null,Jt=qt?sy(qt):null,Yt=r?.context_key??null,Xt=r?.kind===`ticket`?cy(r,L)??Jt:Jt,Zt=r?.kind===`project`,Qt=Xt??Gt,$t=(0,p.useCallback)(e=>ly({bundleId:e,activeRunContextKey:Qt,isProjectRootRunActive:Zt}),[Qt,Zt]),en=pe!==null&&ky(pe,`trash`)||he!==null&&Cy(he),tn=ne===e,nn=(0,p.useMemo)(()=>t?KC(t):[],[t]),rn=(0,p.useMemo)(()=>YC(nn),[nn]),an=(0,p.useMemo)(()=>t?qC(t):[],[t]),on=(0,p.useMemo)(()=>t?JC(t):[],[t]),sn=rn.length>0,ln=(0,p.useMemo)(()=>new Map(L.map(e=>[e.id,e])),[L]);(0,p.useEffect)(()=>{Kt(null)},[e]),(0,p.useEffect)(()=>{Gt!==null&&(Zt||Xt!==null)&&Kt(null)},[Xt,Zt,Gt]),(0,p.useEffect)(()=>{if(!We){qe(null);return}let e=ln.get(We)??null;e&&qe(t=>!t||t.id!==We?e:dy(t,e))},[We,ln]),(0,p.useEffect)(()=>{H&&(qe(e=>!e||e.id!==H.id?e:dy(e,H)),it(e=>{if(!e)return e;let t=H.worktree_bundle_id;if(!t||e.bundle.id!==t)return e;let n=e.tickets.some(e=>e.id===H.id)?e.tickets.map(e=>e.id===H.id?dy(e,H):e):[...e.tickets,H];return{...e,tickets:n}}))},[H]),(0,p.useEffect)(()=>{H===null||We!==null||Qe!==null||U()},[U,H,Qe,We]);let dn=(0,p.useCallback)(async e=>{let t=await ae(e);if(!t)return null;let n=ln.get(e),r=n?dy(t,n):t;return qe(t=>t&&t.id!==e||We&&We!==e?t:r),r},[ae,We,ln]),fn=(0,p.useCallback)(e=>{qe(e),Ke(e.id),dn(e.id),b?.(e.id)},[b,dn]),pn=(0,p.useCallback)(()=>{et.current=null,$e(null),nt(null),it(null),vt(!1),St(o8())},[]),mn=(0,p.useMemo)(()=>new Map(B.map(e=>[e.id,e])),[B]),hn=(0,p.useMemo)(()=>{if(!rt)return null;let e=rt.bundle.id,t=H?.worktree_bundle_id===e?H:null,n=L.filter(t=>t.worktree_bundle_id===e),r=new Map(n.map(e=>[e.id,e])),i=rt.tickets.filter(e=>!ie.current.has(e.id)).map(e=>t&&e.id===t.id?dy(e,t):e);t&&!i.some(e=>e.id===t.id)&&!ie.current.has(t.id)&&i.push(t);let a=i.map(e=>dy(e,r.get(e.id)));for(let e of n)a.some(t=>t.id===e.id)||a.push(e);a=C3(a);let o=rt.execution_order_ticket_ids??[],s=a.map(e=>e.id),c=[...o,...s].filter((e,t,n)=>s.includes(e)&&n.indexOf(e)===t),l=n.some(e=>e.can_re_review!==void 0||e.has_completed_review!==void 0||e.has_follow_up_since_last_review!==void 0),u=n.some(e=>e.agent_status===`running`),d={has_completed_review:n.some(e=>e.has_completed_review===!0),has_follow_up_since_last_review:n.some(e=>e.has_follow_up_since_last_review===!0),can_re_review:!u&&n.some(e=>e.can_re_review===!0)},f=Iy(a),p=a.find(e=>e.id===rt.review_owner_ticket_id&&e.state===`review`)??null,m=Vy(a,{targetTicketId:rt.target_ticket_id,reviewOwnerTicketId:p?.id??rt.review_owner_ticket_id,latestSessionTicketId:f?.id??rt.latest_session_ticket_id});return{...rt,bundle:mn.get(e)??rt.bundle,tickets:a,execution_order_ticket_ids:c,latest_session_ticket_id:f?.id??null,latest_session_id:f?.session_id??null,review_owner_ticket_id:p?.id??null,target_ticket_id:m?.id??null,has_completed_review:l?d.has_completed_review:rt.has_completed_review,has_follow_up_since_last_review:l?d.has_follow_up_since_last_review:rt.has_follow_up_since_last_review,can_re_review:l?d.can_re_review:rt.can_re_review}},[mn,H,ie,rt,L]),gn=(0,p.useMemo)(()=>L.filter(e=>{if(Mt.hideStaleTickets&&vy(e))return!1;if(Mt.hideBundlesWithPullRequests&&e.worktree_bundle_id){let t=mn.get(e.worktree_bundle_id);if(t&&t.pull_request!==void 0?t.pull_request:e.bundle?.pull_request)return!1}return py(Mt.query,e)}),[Mt,mn,L]),_n=(0,p.useMemo)(()=>Wy(gn),[gn]),vn=(0,p.useMemo)(()=>gn.filter(e=>gy(e)),[gn]),yn=(0,p.useMemo)(()=>Hy(vn,B,D8),[B,vn]),{boardViewportRef:Fn,boardContentRef:Ln,registerTicketNode:Bn,registerDependencyClipNodes:Vn,measuredCardRects:Hn,dependencyClipRects:Un,overlayPreview:Wn,overlaySize:Gn,getDependencyTargetState:Kn,handleDependencyStart:qn,handleDeleteDependency:Jn}=ime({activeProjectId:e,tickets:L,dependencies:z,setDependencies:ee,activeTicket:pe,activeOverlayNode:be,dragOffset:Se}),Yn=gme(),Xn=!!t?.run_ide?.trim(),Zn=(0,p.useCallback)((e,t,n=L)=>{let r=Hy(n,B,t).find(t=>t.kind===`bundle`&&t.group.bundle.id===e);return r?.kind===`bundle`?r.group:null},[B,L]),Qn=(0,p.useCallback)(e=>{let n=yF(e,i);return(0,X.jsx)(h3,{ticket:e,allTickets:L,dependencies:z,bundles:B,projectMemoryEnabled:!!t?.memory_enabled,automationStatus:e.worktree_bundle_id?fe.get(e.worktree_bundle_id):null,overlay:!0,activeTool:i,showModelSelector:bF(n)&&Pe(n).length>0,availableModels:Pe(n),runDisabled:!0,hideBundleScopedControls:!0})},[t?.memory_enabled,i,fe,B,z,Pe,L]),$n=(0,p.useCallback)(t=>zy(t)?t.project_id===e?Xn:!!t.has_run_ide:!1,[Xn,e]),er=(0,p.useCallback)(e=>!!e.project_id&&!!(e.bundle?.branch??e.branch)&&zy(e),[]),tr=(0,p.useCallback)(e=>{let t=e?.tickets.find(t=>t.id===e.target_ticket_id)??e?.tickets.find(e=>e.has_worktree)??null;return t?$n(t):!1},[$n]),nr=(0,p.useCallback)(e=>{let t=C3(L.filter(t=>t.worktree_bundle_id===e));return rt?.bundle.id===e?s8(C3(rt.tickets.map(e=>t.find(t=>t.id===e.id)??e)),{targetTicketId:rt.target_ticket_id,reviewOwnerTicketId:rt.review_owner_ticket_id,latestSessionTicketId:rt.latest_session_ticket_id}):s8(t)},[rt,L]),rr=(0,p.useCallback)(e=>{let t=nr(e),n=B.some(t=>t.id===e&&t.has_prepared_worktree===!0)||L.some(t=>t.worktree_bundle_id===e&&zy(t))||!!(rt?.bundle.id===e&&rt.tickets.some(zy));return!!(t?.project_id&&(t.bundle?.branch??t.branch)&&n)},[B,nr,rt,L]),ir=(0,p.useCallback)(e=>{let t=mn.get(e),n=nr(e),r=rt?.bundle.id===e?[...L,...rt.tickets]:L;return!!(t&&n?.project_id&&By(t,r))},[mn,nr,rt,L]);(0,p.useEffect)(()=>{ze(!1),Ve(!1),dt(null),ht(null)},[e,d]),(0,p.useEffect)(()=>{if(!Bt){De([]);return}let t=new AbortController;return(async()=>{try{De(await $P(`opencode`,t.signal,e))}catch(e){Ye(e)||De([])}})(),()=>{t.abort()}},[e,Bt]);let ar=({active:e})=>{K(!1),xe(null),Ce({x:0,y:0}),ve(null);let t=Gy(String(e.id));if(t){ge(Zn(t.bundleId,t.column)),me(null);return}ge(null),me(L.find(t=>t.id===e.id)??null)},or=()=>{K(!1),xe(null),Ce({x:0,y:0}),me(null),ge(null),ve(null)},sr=(0,p.useCallback)(e=>{R(t=>e.reduce((e,t)=>y8(e,t),t))},[R]),cr=(0,p.useCallback)((e,t)=>{if(e.length===0)return;let n=e[0]?.state;n&&R(r=>e.reduce((e,r)=>x8(e,r.id,t,Oy(r,n,t)),r))},[R]),lr=(0,p.useCallback)((e,t=L)=>!e.worktree_bundle_id||!e.project_id||e.state!==`build`?[]:C3(t.filter(t=>t.project_id===e.project_id&&t.worktree_bundle_id===e.worktree_bundle_id&&t.state===`build`&&t.parked_at===null)),[L]),ur=async({active:e,over:t})=>{let n=Gy(String(e.id)),r=L.find(t=>t.id===e.id),i=n?Zn(n.bundleId,n.column):null,a=t?.id===`trash`&&(r!==void 0&&ky(r,`trash`)||i!==null&&Cy(i)),o=t?.id&&E8.includes(t.id)?t.id:null;if(K(a),xe(null),Ce({x:0,y:0}),me(null),ge(null),t){if(n){if(t.id===`trash`){if(!i||!Cy(i))return;await Sr(i);return}if(t.id===D8){if(!i||!wy(i))return;await yr(i);return}if(o){if(n.column===D8){if(!i||!Ty(i))return;await br(i);return}await ui(n.bundleId,n.column,o)}return}if(t.id===`trash`){if(!r||!ky(r,`trash`))return;wr(e.id);return}if(t.id===D8){if(!r||!ky(r,D8))return;await _r(e.id);return}if(o){if(r&&Sy(r,o)){await vr(e.id);return}if(!(!r||!ky(r,o)))try{await hr(r,o,{optimistic:!0})}catch(e){$.error(e instanceof Ge?e.message:F(`board.errors.moveTicket`),{id:`board-move-error`})}}}},dr=async(t,n,r,i,a,o,s)=>{let c=await cn({title:t,description:n,model:i,variant:a,skills:o,project_id:e,...s});if(hme(i,a,o),R(e=>y8(e,p8(c))),c.bundle&&V(e=>_8(e,c.bundle)),r===`build`)try{await hr(c,`build`)}catch(e){$.error(e instanceof Ge?e.message:F(`board.errors.moveTicket`),{id:`board-move-error`})}r===`plan`&&zn(c.id,c.project_id)},fr=async t=>{if(!e)throw Error(F(`board.errors.createBundleWithoutProject`));let n=await _t(e,{name:t,prepare:!0});return V(e=>_8(e,n)),n},pr=(0,p.useCallback)((e,t={})=>{let n=p8(e);R(e=>t.reorderInState?y8(e,n):v8(e,n)),qe(t=>!t||t.id!==e.id?t:dy(e,n)),e.bundle&&V(t=>_8(t,e.bundle))},[V,R]),mr=(0,p.useCallback)(e=>{V(t=>_8(t,e)),R(t=>t.map(t=>t.worktree_bundle_id===e.id?{...t,bundle:e}:t)),it(t=>!t||t.bundle.id!==e.id?t:{...t,bundle:e,tickets:t.tickets.map(t=>t.worktree_bundle_id===e.id?{...t,bundle:e}:t)})},[V,it,R]),hr=async(e,t,n={})=>{let r=L.findIndex(t=>t.id===e.id),i=t===`review`?lr(e):[],a=t===`review`&&i.length>1,o=n.optimistic?a?i.map(e=>e.id):[e.id]:[];n.optimistic&&(se(o,t),a?cr(i,t):R(n=>x8(n,e.id,t,Ey(e,t))));try{if(a&&e.project_id&&e.worktree_bundle_id){let t=await Et(e.project_id,e.worktree_bundle_id);Wr(t);let n=t.tickets.find(t=>t.id===e.id);if(!n)throw Error(F(`board.errors.missingBundleReviewTicket`));return ce(o),n}let n=await un(e.id,e.project_id,t);return R(r=>{let i=r.find(t=>t.id===e.id);return i?.state===t&&n.state===t&&i.agent_status!==n.agent_status&&n.agent_status===e.agent_status?r:m8(i,n)?y8(r,n):v8(r,n)}),n.bundle&&V(e=>_8(e,n.bundle)),ce(o),n}catch(t){throw n.optimistic&&(a?sr(i):R(t=>x8(t,e.id,e.state,{agent_status:e.agent_status,agent_log:e.agent_log,build_completed_at:e.build_completed_at},{preferredIndex:r})),ce(o)),t}},gr=(e,t)=>{R(n=>n.map(n=>n.id===e?{...n,...t}:n))},_r=async t=>{let n=L.find(e=>e.id===t);if(n)try{let r=new Date().toISOString();le([t],r),gr(t,{parked_at:r}),pr(await wn(t,n.project_id??e),{reorderInState:!0}),ue([t])}catch(e){ue([t]),gr(t,{parked_at:n.parked_at}),$.error(e instanceof Ge?e.message:F(`board.errors.parkTicket`),{id:`board-park-error`})}},vr=async t=>{let n=L.find(e=>e.id===t);if(n)try{le([t],null),gr(t,{parked_at:null}),pr(await Tn(t,n.project_id??e),{reorderInState:!0}),ue([t])}catch(e){ue([t]),gr(t,{parked_at:n.parked_at}),$.error(e instanceof Ge?e.message:F(`board.errors.returnTicket`),{id:`board-unpark-error`})}},yr=(0,p.useCallback)(async e=>{let t=new Set(e.tickets.map(e=>e.id)),n=e.tickets.map(e=>({id:e.id,parked_at:e.parked_at})),r=new Date().toISOString();le(e.tickets.map(e=>e.id),r),R(e=>e.map(e=>t.has(e.id)?{...e,parked_at:r}:e));let i=await Promise.allSettled(e.tickets.map(e=>wn(e.id,e.project_id??re.current))),a=new Set;if(i.forEach((t,n)=>{if(t.status===`fulfilled`){ue([t.value.id]),pr(t.value,{reorderInState:!0});return}let r=e.tickets[n];r&&a.add(r.id)}),a.size===0)return;ue([...a]),R(e=>e.map(e=>{if(!a.has(e.id))return e;let t=n.find(t=>t.id===e.id);return t?{...e,parked_at:t.parked_at}:e}));let o=i.find(e=>e.status===`rejected`),s=a.size===e.tickets.length?o?.reason instanceof Ge?o.reason.message:F(`board.errors.moveBundleToDone`):F(`board.toasts.movedBundleToDonePartial`,{movedCount:e.tickets.length-a.size,totalCount:e.tickets.length});$.error(s,{id:`board-bundle-park-error`})},[re,pr,ue,le,R,F]),br=(0,p.useCallback)(async e=>{let t=new Set(e.tickets.map(e=>e.id)),n=e.tickets.map(e=>({id:e.id,parked_at:e.parked_at}));le(e.tickets.map(e=>e.id),null),R(e=>e.map(e=>t.has(e.id)?{...e,parked_at:null}:e));let r=await Promise.allSettled(e.tickets.map(e=>Tn(e.id,e.project_id??re.current))),i=new Set;if(r.forEach((t,n)=>{if(t.status===`fulfilled`){ue([t.value.id]),pr(t.value,{reorderInState:!0});return}let r=e.tickets[n];r&&i.add(r.id)}),i.size===0)return;ue([...i]),R(e=>e.map(e=>{if(!i.has(e.id))return e;let t=n.find(t=>t.id===e.id);return t?{...e,parked_at:t.parked_at}:e}));let a=r.find(e=>e.status===`rejected`),o=i.size===e.tickets.length?a?.reason instanceof Ge?a.reason.message:F(`board.errors.restoreBundle`):F(`board.toasts.restoredBundlePartial`,{restoredCount:e.tickets.length-i.size,totalCount:e.tickets.length});$.error(o,{id:`board-bundle-unpark-error`})},[re,pr,ue,le,R,F]),xr=async t=>{if(!e)return;let n=await Ft(e,t);n.warning&&$.warning(n.warning,{id:`board-bundle-delete-warning`}),V(e=>e.filter(e=>e.id!==t))},Sr=(0,p.useCallback)(async t=>{let n=t.tickets.map(e=>({ticket:e,index:L.findIndex(t=>t.id===e.id)})).filter(e=>e.index!==-1);if(n.length===0)return;for(let e of n)ie.current.set(e.ticket.id,e);let r=new Set(n.map(e=>e.ticket.id));R(e=>e.filter(e=>!r.has(e.id))),ee(e=>e.filter(e=>!r.has(e.blocker_ticket_id)&&!r.has(e.dependent_ticket_id)));let i=await Promise.allSettled(n.map(async t=>(await Sn(t.ticket.id,t.ticket.project_id??e),ie.current.delete(t.ticket.id),t.ticket.id)));t.tickets.some(e=>e.project_id===re.current)&&G().catch(()=>{});let a=n.filter((e,t)=>i[t]?.status===`rejected`);if(a.length===0)return;for(let e of a)ie.current.delete(e.ticket.id);a.some(e=>e.ticket.project_id===re.current)&&R(e=>[...a].sort((e,t)=>e.index-t.index).reduce((e,t)=>w8(e,t),e));let o=i.find(e=>e.status===`rejected`),s=a.length===n.length?o?.reason instanceof Ge?o.reason.message:F(`board.errors.deleteBundleTickets`):F(`board.toasts.deletedBundleTicketsPartial`,{deletedCount:n.length-a.length,totalCount:n.length});$.error(s,{id:`board-delete-bundle-wrapper-error`})},[e,re,ie,G,ee,R,L,F]),Cr=e=>{let t=ln.get(e.id);pr(e,{reorderInState:t?t.state!==e.state||t.parked_at!==e.parked_at||t.worktree_bundle_id!==e.worktree_bundle_id:!1}),t?.worktree_bundle_id&&t.worktree_bundle_id!==e.worktree_bundle_id&&t.bundle?.ticket_count===1&&V(e=>e.filter(e=>e.id!==t.worktree_bundle_id)),(t?.worktree_bundle_id!==e.worktree_bundle_id||t?.bundle?.ticket_count!==e.bundle?.ticket_count)&&e.project_id===re.current&&G().catch(()=>{})},wr=async t=>{let n=L.find(e=>e.id===t),r=L.findIndex(e=>e.id===t);if(!(!n||r===-1)){ie.current.set(t,{ticket:n,index:r}),R(e=>b8(e,t)),ee(e=>Uv(e,t));try{await Sn(t,n.project_id??e),n.project_id===re.current&&G().catch(()=>{}),ie.current.delete(t)}catch(e){let n=ie.current.get(t);ie.current.delete(t),n&&n.ticket.project_id===re.current&&(R(e=>w8(e,n)),$.error(e instanceof Ge?e.message:F(`board.errors.deleteTicket`),{id:`board-delete-error`}))}}},Tr=async t=>{let n=L.find(e=>e.id===t);if(!n)return;let r=n.state===`review`?`review`:`build`;try{if(Ue(r),n.project_id&&n.worktree_bundle_id&&n.state===`review`){Wr(await Ot(n.project_id,n.worktree_bundle_id));return}pr(await Cn(t,n.project_id??e),{reorderInState:!0})}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.undoTicket`),{id:`board-undo-error`}),e}finally{Ue(e=>e===r?null:e)}},Er=async t=>{let n=L.find(e=>e.id===t);try{await Dn(t,n?.project_id??e)}catch(e){$.error(e instanceof Ge?e.message:F(`board.errors.retryTicket`),{id:`board-retry-error`})}},Dr=async t=>{let n=L.find(e=>e.id===t),r=n?sy(n):t;try{Kt(r),await On(t,n?.project_id??e),s?.()}catch(e){Kt(e=>e===r?null:e),$.error(e instanceof Ge?e.message:F(`board.errors.startRun`),{id:`board-run-error`})}},Or=(0,p.useCallback)(async t=>{let n=L.find(e=>e.id===t);try{await kn(t,n?.project_id??e)}catch(e){$.error(e instanceof Ge?e.message:F(`board.errors.openIde`),{id:`board-open-ide-error`})}},[e,F,L]),kr=async t=>{let n=L.find(e=>e.id===t),i=r?.kind===`ticket`&&n&&Xt===sy(n)?Yt:null;try{await An(t,n?.project_id??e),o?.(i),s?.()}catch{}},Ar=t=>{jn(t,L.find(e=>e.id===t)?.project_id??e).then(()=>{R(e=>e.map(e=>e.id===t?{...e,agent_status:`stopped`,is_running:!1}:e))})},jr=async t=>{let n=L.find(e=>e.id===t);try{await Mn(t,n?.project_id??e)}catch(e){$.error(e instanceof Error?e.message:F(`reviewInterrupt.error`))}},Mr=t=>{Nn(t,L.find(e=>e.id===t)?.project_id??e).then(()=>{R(e=>e.map(e=>e.id===t?{...e,agent_status:`running`}:e))})},Nr=(0,p.useCallback)(e=>{let t=nr(e);!t||!$n(t)||Or(t.id)},[$n,nr,Or]),Pr=(0,p.useCallback)((e,t)=>{let n=nr(e),r=t===`files`?ir(e):rr(e);if(!(!n||!r)){if(O){O({kind:`bundle`,bundleId:e},t);return}pt({target:{kind:`bundle`,bundleId:e,ticketId:n.id},projectId:n.project_id,title:n.bundle?Jy(n.bundle):n.title,bundleTargetName:n.bundle&&Jy(n.bundle)||null,initialMode:t,followUpMode:`build`})}},[ir,rr,nr,O]),Fr=(0,p.useCallback)((e,t)=>{let n=nr(e);if(!n?.project_id||!zy(n))return;let r=n.latest_check_gate_evaluation?.id??L.find(t=>t.worktree_bundle_id===e&&t.latest_check_gate_evaluation)?.latest_check_gate_evaluation?.id??null;if(nn.length===0&&!r)return;let i=B.find(t=>t.id===e)??n.bundle;i&&ht({bundleId:e,label:Jy(i),requestedInitialTab:t,gateEvaluationId:r,requiredCheckPolicy:i.required_check_policy??null})},[B,nr,nn.length,L]),Ir=(0,p.useCallback)((e,t)=>{let n=L.find(t=>t.id===e);if(!(!n||!er(n))){if(O){O({kind:`ticket`,ticketId:e},t);return}pt({target:{kind:`ticket`,ticketId:n.id},projectId:n.project_id,title:n.title,bundleTargetName:null,initialMode:t,followUpMode:`build`})}},[er,O,L]),Lr=(0,p.useCallback)(e=>Pr(e,`files`),[Pr]),Rr=(0,p.useCallback)(e=>Pr(e,`changes`),[Pr]),zr=(0,p.useCallback)(e=>Ir(e,`files`),[Ir]),Br=(0,p.useCallback)(e=>Ir(e,`changes`),[Ir]),Vr=(0,p.useCallback)(e=>{let t=L.find(t=>t.id===e);!t?.project_id||!zy(t)||dt({ticketId:t.id,label:t.title})},[L]),Hr=(0,p.useCallback)(async(t,n,r=`build`,i)=>{let a=L.find(e=>e.id===t);if(a)try{pr(a.state===`plan`?await Rn(t,a.project_id??e,n):await Pn(t,a.project_id??e,n,r,i))}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.sendFollowUp`),{id:`board-follow-up-error`}),e}},[e,pr,F,L]),Ur=(0,p.useCallback)(e=>{R(t=>e.reduce((e,t)=>{let n=e.find(e=>e.id===t.id),r=oe(n,t);if(!r)return e;let i=p8(n&&n.state===r.state&&n.agent_status===`running`&&r.agent_status===null?{...r,agent_status:n.agent_status,session_id:n.session_id,is_running:n.is_running}:r);return m8(n,i)?y8(e,i):v8(e,i)},t))},[oe,R]),Wr=(0,p.useCallback)(e=>{it(e),V(t=>_8(t,e.bundle)),Ur(e.tickets)},[Ur,V]),Gr=(0,p.useCallback)((e,t)=>{Array.isArray(t.tickets)&&it(n=>{if(!n||n.bundle.id!==e)return n;let r=fy(n.tickets,t.tickets),i=n.tickets.find(e=>e.id===n.review_owner_ticket_id&&e.state===`review`&&e.agent_status===`running`&&e.updated_at>=(t.tickets.find(t=>t.id===e.id)?.updated_at??``))??null;return{...n,tickets:r,execution_order_ticket_ids:t.execution_order_ticket_ids,latest_session_ticket_id:t.latest_session_ticket_id,latest_session_id:t.latest_session_id,review_owner_ticket_id:t.review_owner_ticket_id??i?.id??null,target_ticket_id:i?.id??t.target_ticket_id}})},[]),Kr=(0,p.useCallback)(async e=>{let t=re.current;if(!t)return null;let n=await bt(t,e);return re.current!==t||et.current!==e?null:(Wr(n),n)},[re,Wr]),qr=(0,p.useCallback)(async()=>{let e=st?.bundle.id,t=re.current;if(!e||!t)return null;let n=++lt.current,r=await bt(t,e);return n!==lt.current||re.current!==t?null:(Wr(r),ct(r),r)},[re,Wr,st?.bundle.id]),Jr=(0,p.useCallback)(async t=>{if(!e)return;ot(t),ct(null);let n=++lt.current;try{let r=await bt(e,t);if(re.current!==e||n!==lt.current)return;Wr(r),ct(r)}catch{if(n!==lt.current||re.current!==e)return;ot(null),$.error(F(`buildOpenQuestionsDialog.refreshFailedError`),{id:`board-build-open-questions-load-error`})}},[e,re,Wr,F]),Yr=(0,p.useCallback)(async t=>{let n=st?.bundle.id;if(!e||!n)return;let r=++lt.current;await Rt(e,n,t),r===lt.current&&(ot(null),ct(null))},[e,st?.bundle.id]),Xr=st?.bundle.id??null;(0,p.useEffect)(()=>{if(!Xr)return;let e=new Map(L.map(e=>[e.id,e])),t=B.find(e=>e.id===Xr);ct(n=>!n||n.bundle.id!==Xr?n:{...n,bundle:t?{...n.bundle,...t}:n.bundle,tickets:n.tickets.map(t=>{let n=e.get(t.id);return n?{...t,...n}:t})})},[B,Xr,L]);let Zr=(0,p.useCallback)(async e=>{let t=re.current;if(!t)return null;let n=await xt(t,e);return re.current!==t||et.current!==e?null:(Gr(e,n),n)},[re,Gr]),Qr=(0,p.useCallback)(async(e,t=null)=>{let n=re.current;if(!n)return;et.current=e,Ke(null),qe(null),$e(e),nt(t),St(o8());let r=mn.get(e)??null,i=L.filter(t=>t.worktree_bundle_id===e);if(r&&i.length>0){let e=Iy(i),t=Vy(i,{latestSessionTicketId:e?.id??null});it({bundle:r,tickets:i,latest_session_ticket_id:e?.id??null,latest_session_id:e?.session_id??null,review_owner_ticket_id:null,target_ticket_id:t?.id??null})}else it(null);vt(!0);try{await Zr(e)}catch(t){if(t instanceof Ge&&t.status===404&&S===e){pn(),j?.();return}}finally{re.current===n&&vt(!1)}},[re,mn,pn,j,Zr,S,L]),$r=(0,p.useCallback)((e,t=null)=>{Qr(e,t),E?.(e)},[E,Qr]),ei=(0,p.useCallback)(async(e,t)=>{St(t=>({...t,[e]:!0}));try{return await t()}finally{St(t=>({...t,[e]:!1}))}},[]),ti=(0,p.useCallback)(async t=>{await ei(`stopBuild`,async()=>{let n=L.find(e=>e.id===t);await jn(t,n?.project_id??e),R(e=>e.map(e=>e.id===t?{...e,agent_status:`stopped`,is_running:!1}:e)),n?.worktree_bundle_id&&await Kr(n.worktree_bundle_id)})},[e,Kr,ei,R,L]),ni=(0,p.useCallback)(async t=>{await ei(`stopBuild`,async()=>{let n=L.find(e=>e.id===t);try{await Mn(t,n?.project_id??e)}catch(e){$.error(e instanceof Error?e.message:F(`reviewInterrupt.error`))}})},[e,ei,F,L]),ri=(0,p.useCallback)(async t=>{await ei(`resumeBuild`,async()=>{let n=L.find(e=>e.id===t);await Nn(t,n?.project_id??e),R(e=>e.map(e=>e.id===t?{...e,agent_status:`running`}:e)),n?.worktree_bundle_id&&await Kr(n.worktree_bundle_id)})},[e,Kr,ei,R,L]),ii=(0,p.useCallback)(async t=>{if(e)try{Wr(await ei(`build`,()=>Tt(e,t))),Qe===t&&nt(`build`),s?.()}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.buildBundle`),{id:`board-bundle-build-error`}),e}},[e,Wr,s,ei,Qe,F]),ai=(0,p.useCallback)(async t=>{if(e)try{Wr(await ei(`review`,()=>Et(e,t))),Qe===t&&nt(`review`)}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.reviewBundle`),{id:`board-bundle-review-error`}),e}},[e,Wr,ei,Qe,F]),oi=(0,p.useCallback)(async t=>{if(e)try{Wr(await ei(`review`,()=>Dt(e,t))),Qe===t&&nt(`review`)}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.continueBundleReview`),{id:`board-bundle-continue-review-error`}),e}},[e,Wr,ei,Qe,F]),si=(0,p.useCallback)(async t=>{if(e)try{Ue(`review`),Wr(await ei(`undoReview`,()=>Ot(e,t))),Qe===t&&nt(`build`)}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.undoBundleReview`),{id:`board-bundle-undo-review-error`}),e}finally{Ue(e=>e===`review`?null:e)}},[e,Wr,ei,Qe,F]),ci=(0,p.useCallback)(async t=>{if(e)try{Wr(await It(e,t))}catch(e){$.error(e instanceof Ge?e.message:`Unable to resume the automation right now.`,{id:`board-bundle-resume-automation-error`})}},[e,Wr]),li=(0,p.useCallback)(async t=>{if(e)try{Wr(await Lt(e,t))}catch(e){$.error(e instanceof Ge?e.message:`Unable to dismiss the automation pause right now.`,{id:`board-bundle-dismiss-automation-error`})}},[e,Wr]),ui=(0,p.useCallback)(async(e,t,n)=>{if(t===D8||n===D8)return;let r=Dy(t,n);if(!r)return;let i=L.filter(n=>n.worktree_bundle_id===e&&n.state===t&&n.parked_at===null);if(i.length===0)return;let a=i.map(e=>e.id);se(a,n),cr(i,n);try{if(r===`build`){await ii(e),ce(a);return}if(r===`review`){await ai(e),ce(a);return}await si(e),ce(a)}catch(e){sr(i),ce(a),$.error(e instanceof Ge?e.message:F(`board.errors.moveBundle`),{id:`board-bundle-move-error`})}},[ce,ii,ai,si,se,cr,sr,L,F]),di=async t=>{e&&(Wr(await ei(`run`,()=>Nt(e,t))),s?.())},fi=async t=>{if(!e)return;let n=r?.kind===`ticket`&&Xt===t?Yt:null,i=await ei(`stop`,()=>Pt(e,t));o?.(n),Wr(i),s?.()},pi=(0,p.useCallback)(async(t,n,r=`build`,i)=>{e&&Wr(await ei(`followUp`,()=>kt(e,t,n,r,i)))},[e,Wr,ei]);(0,p.useEffect)(()=>()=>{a?.(null)},[a]),(0,p.useEffect)(()=>{if(!a)return;if(!r){a(null);return}if(r.kind===`project`){a({target:null,canSelect:!1,disabledReason:F(`board.preview.disabledProjectRoot`),submitPrompt:null});return}let e=L.find(e=>e.id===r.ticket_id);if(!e){a({target:null,canSelect:!1,disabledReason:F(`board.preview.disabledBuildCapable`),submitPrompt:null});return}if(e.state===`plan`){a({target:{kind:`ticket`,id:e.id},canSelect:!1,disabledReason:F(`board.preview.disabledPlanMode`),submitPrompt:null});return}if(e.worktree_bundle_id){a({target:{kind:`bundle`,id:e.worktree_bundle_id,ticket_id:e.id},canSelect:!0,disabledReason:null,promptPlaceholder:F(`board.preview.followUpBundlePlaceholder`),submitPrompt:t=>pi(e.worktree_bundle_id,t)});return}a({target:{kind:`ticket`,id:e.id},canSelect:!0,disabledReason:null,promptPlaceholder:F(`board.preview.followUpTicketPlaceholder`),submitPrompt:t=>Hr(e.id,t)})},[r,Hr,pi,a,F,L]);let mi=async t=>{let n=L.find(e=>e.id===t),r=n?ay(n.state):null;if(n)try{if(n.state===`review`&&n.can_re_review&&n.agent_status!==`running`){let t=await In(n.id,n.project_id??e);pr(t),t.worktree_bundle_id&&await Kr(t.worktree_bundle_id);return}if(!r)return;if(n.worktree_bundle_id&&r===`review`){await ai(n.worktree_bundle_id);return}await hr(n,r)}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.moveTicket`),{id:`board-move-error`}),e}},hi=async t=>{let n=L.find(e=>e.id===t);try{pr(await bn(t,n?.project_id??e))}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.startBuildChain`),{id:`board-build-chain-error`}),e}},gi=async t=>{let n=L.find(e=>e.id===t);try{await xn(t,n?.project_id??e)}catch(e){throw $.error(e instanceof Ge?e.message:F(`board.errors.stopBuildChain`),{id:`board-stop-build-chain-error`}),e}},_i=async()=>{if(!(!e||Be)){Ve(!0);try{let t=await En(e);R(e=>e.filter(e=>!t.deleted_ticket_ids.includes(e.id))),ee(e=>t.deleted_ticket_ids.reduce(Uv,e)),await G(),ze(!1),t.failed_count>0?$.error(F(`board.toasts.deleteDonePartial`,{count:t.deleted_count,deletedCount:t.deleted_count,failedCount:t.failed_count}),{id:`board-delete-parked-error`}):$.success(F(`board.toasts.deleteDoneSuccess`,{count:t.deleted_count}),{id:`board-delete-parked-success`})}catch(e){$.error(e instanceof Ge?e.message:F(`board.errors.emptyDone`),{id:`board-delete-parked-error`})}finally{Ve(!1)}}},vi=({delta:e})=>{Ce(e)},yi=(0,p.useCallback)((t=null)=>{e&&Te({initialWorktreeBundleId:t})},[e]);(0,p.useEffect)(()=>{!M||!e||(Te({initialWorktreeBundleId:null,initialImportedDraft:M}),N?.())},[M,e,N]),(0,p.useEffect)(()=>{if(!Xe||!e){Je.current=null;return}let t=`${e}:${Xe}`;if(W!==e||Je.current===t)return;Je.current=t;let n=ln.get(Xe);n?fn(n):_?.(),v===void 0&&g?.()},[e,W,g,_,fn,Xe,v,ln]),(0,p.useEffect)(()=>{v===void 0||v||!J||y.some(e=>e.kind===`ticket`&&e.ticketId===J.id)||(Ke(null),qe(null))},[y,v,J]),(0,p.useEffect)(()=>{!v||!e||W!==e||Je.current!==`${e}:${v}`||We!==v||ln.has(v)||(Ke(null),qe(null),_?.())},[e,W,_,v,We,ln]),(0,p.useEffect)(()=>{if(!S){let e=C?.target.kind===`bundle`?C.target.bundleId:null,t=e!==null&&et.current===e,n=et.current!==null&&y.some(e=>e.kind===`bundle`&&e.bundleId===et.current);Ze.current&&!t&&!n&&(Ze.current=null,e===null&&pn());return}let t=`${e}:${S}`;if(!(!e||W!==e||te!==e||Ze.current===t)){if(Ze.current=t,!mn.has(S)){j?.();return}Qr(S)}},[e,mn,te,pn,W,j,Qr,S,C,y,rt,Qe]),(0,p.useEffect)(()=>{!S||!e||W!==e||te!==e||Ze.current!==`${e}:${S}`||Qe!==S||mn.has(S)||(pn(),j?.())},[e,mn,te,pn,W,j,S,Qe]),(0,p.useEffect)(()=>{if(!C){Y.current=null,pt(e=>e?.isRouteOwned?null:e);return}let t=C?.target.kind===`bundle`?W===e&&te===e:W===e;if(!e||!t)return;let n=`${e}:${C.target.kind===`ticket`?`ticket:${C.target.ticketId}`:`bundle:${C.target.bundleId}`}`;if(Y.current===n)return;Y.current=n;let r=C.target,i=r.kind===`ticket`&&y.some(e=>e.kind===`ticket`&&e.ticketId===r.ticketId),a=y.some(e=>e.kind===`bundle`&&e.bundleId===(r.kind===`bundle`?r.bundleId:et.current));if(i||(Ke(null),qe(null)),!a&&r.kind===`ticket`&&pn(),pt(e=>e?.isRouteOwned?null:e),C.target.kind===`ticket`){let e=ln.get(C.target.ticketId);if(!e||!er(e)){j?.();return}pt({target:{kind:`ticket`,ticketId:e.id},projectId:e.project_id,title:e.title,bundleTargetName:null,initialMode:C.mode,followUpMode:`build`,isRouteOwned:!0});return}let{bundleId:o}=C.target,s=nr(o),c=C.mode===`files`?ir(o):rr(o);if(!s||!c){j?.();return}let l=mn.get(o)??s.bundle??null;pt({target:{kind:`bundle`,bundleId:o,ticketId:s.id},projectId:s.project_id,title:l?Jy(l):s.title,bundleTargetName:l&&Jy(l)||null,initialMode:C.mode,followUpMode:`build`,isRouteOwned:!0})},[e,mn,te,ir,rr,er,pn,nr,W,j,C,y,rt,Qe,ln]),(0,p.useEffect)(()=>{let t=C?.target.kind===`bundle`?W===e&&te===e:W===e;if(!C||!e||!t)return;let n=C.target.kind===`ticket`?`ticket:${C.target.ticketId}`:`bundle:${C.target.bundleId}`;if(Y.current!==`${e}:${n}`||!ft?.isRouteOwned)return;if(C.target.kind===`ticket`){if(ft.target.kind!==`ticket`||ft.target.ticketId!==C.target.ticketId)return;let e=ln.get(C.target.ticketId);(!e||!er(e))&&(pt(null),j?.());return}if(ft.target.kind!==`bundle`||ft.target.bundleId!==C.target.bundleId)return;let{bundleId:r}=C.target,i=nr(r),a=C.mode===`files`?ir(r):rr(r);if(!i||!a){pt(null),j?.();return}if(ft.target.ticketId!==i.id){let e=mn.get(r)??i.bundle??null;pt(t=>t?.isRouteOwned?{...t,target:{kind:`bundle`,bundleId:r,ticketId:i.id},projectId:i.project_id,title:e?Jy(e):i.title,bundleTargetName:e&&Jy(e)||null}:t)}},[e,mn,te,ir,rr,er,nr,W,j,C,ft,ln]);let bi=(0,p.useCallback)(()=>{Wt.current?.focus({preventScroll:!0})},[]);return lme([{key:`n`,onKeyDown:yi,disabled:!e},{key:`k`,ctrlKey:!0,onKeyDown:bi}],{isBlocked:cme}),(0,X.jsxs)(X.Fragment,{children:[!T&&(0,X.jsxs)(ase,{sensors:I,collisionDetection:poe,onDragStart:ar,onDragMove:vi,onDragCancel:or,onDragEnd:ur,children:[(0,X.jsx)(`div`,{className:`relative flex min-h-0 flex-1 overflow-hidden`,children:(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-4 overflow-hidden p-6`,children:[(0,X.jsx)(Mde,{query:Mt.query,inputRef:Wt,hideStaleTickets:Mt.hideStaleTickets,hideBundlesWithPullRequests:Mt.hideBundlesWithPullRequests,onQueryChange:e=>zt({query:e}),onClear:()=>{zt({query:``}),Wt.current?.focus()},onHideStaleTicketsChange:e=>zt({hideStaleTickets:e}),onHideBundlesWithPullRequestsChange:e=>zt({hideBundlesWithPullRequests:e})}),(0,X.jsx)(`div`,{ref:Fn,className:`flex min-h-0 flex-1 overflow-x-auto overflow-y-hidden`,children:(0,X.jsxs)(`div`,{ref:Ln,className:`relative flex min-h-0 w-max min-w-full gap-4`,children:[(0,X.jsx)(Jpe,{dependencies:z,cardRects:Hn,clipRects:Un,preview:Wn,ticketsById:ln,overlaySize:Gn}),E8.map(t=>{let n=L.filter(e=>e.state===t&&!gy(e)),r=gn.filter(e=>e.state===t&&!gy(e)),a=Hy(r,B,t),o=tn&&n.length===0?t===`plan`?1:t===`build`?2:0:0;return(0,X.jsx)(g3,{id:t,title:F(`card.columnLabels.${t}`),items:a,ticketCount:r.length,allTickets:L,dependencies:z,bundles:B,activeTool:i,modelsByTool:Fe,availableSkills:Ie,activeRunContextKey:Qt,automationStatuses:fe,isProjectRootRunActive:Zt,isBundleRunDisabled:$t,getDependencyTargetState:Kn,onDependencyStart:qn,onDeleteDependency:Jn,onRegisterTicketNode:Bn,onRegisterDependencyClipNodes:Vn,onAddTicket:t===`plan`&&e?yi:void 0,onCreateBundle:t===`plan`&&e?fr:void 0,onDeleteBundle:t===`plan`&&e?xr:void 0,onDeleteBundleWrapper:Sr,onRefreshBundles:t===`plan`&&e?G:void 0,onUpdateTicket:Cr,onDeleteTicket:wr,onUndoTicket:Tr,undoingColumn:He,onRetryTicket:Er,onAdvanceTicket:mi,onParkTicket:_r,onUnparkTicket:vr,onBuildChainTicket:hi,onRunTicket:Dr,onOpenVerificationTicket:nn.length>0?Vr:void 0,canOpenChangesForTicket:er,onOpenFilesTicket:zr,onOpenChangesTicket:Br,canOpenIdeForTicket:$n,onOpenIdeTicket:Or,onStopTicket:kr,onStopBuildTicket:Ar,onStopBuildChainTicket:gi,onResumeBuildTicket:Mr,onInterruptReviewTicket:jr,onOpenBundleFiles:Lr,onOpenBundleChanges:Rr,canOpenReviewForBundle:rr,canOpenFilesForBundle:ir,onOpenBundleVerification:nn.length>0?e=>Fr(e):void 0,onOpenBundleChecks:e=>Fr(e,`checks`),hasConfiguredChecks:nn.length>0,onOpenBundleIde:Nr,onAddTicketToBundle:yi,onStartChatFromBundle:u,onFollowUpTicket:Hr,bundleActionState:yt,onBuildBundle:ii,onReviewBundle:ai,onUndoBundleReview:si,onRunBundle:di,onStopBundle:fi,onParkBundleWrapper:yr,onUnparkBundleWrapper:br,onOpenTicketDetails:fn,onOpenBundleDetails:(e,t)=>{$r(e,t)},onRequestBundleRefresh:e=>{ei(`bundleRefresh`,()=>Kr(e))},onRequestTicketRefresh:ae,hoveredBundleId:_e,onHoverBundleChange:ye,multiColumnBundleIds:_n,onResumeBundleAutomation:ci,onDismissBundleAutomationPause:li,onOpenBuildQuestions:e=>{Jr(e)},loadingSkeletonCount:o},t)}),(0,X.jsx)(g3,{id:D8,title:F(`card.columnLabels.done`),items:yn,ticketCount:vn.length,allTickets:L,dependencies:z,activeTool:i,modelsByTool:Fe,availableSkills:Ie,bundles:B,activeRunContextKey:Qt,automationStatuses:fe,isProjectRootRunActive:Zt,isBundleRunDisabled:$t,getDependencyTargetState:Kn,onDependencyStart:qn,onDeleteDependency:Jn,onRegisterTicketNode:Bn,onRegisterDependencyClipNodes:Vn,onUpdateTicket:Cr,onDeleteTicket:wr,onUndoTicket:Tr,undoingColumn:He,onRetryTicket:Er,onAdvanceTicket:mi,onParkTicket:_r,onUnparkTicket:vr,onBuildChainTicket:hi,onRunTicket:Dr,onOpenVerificationTicket:nn.length>0?Vr:void 0,canOpenChangesForTicket:er,onOpenFilesTicket:zr,onOpenChangesTicket:Br,canOpenIdeForTicket:$n,onOpenIdeTicket:Or,onStopTicket:kr,onStopBuildTicket:Ar,onStopBuildChainTicket:gi,onResumeBuildTicket:Mr,onInterruptReviewTicket:jr,onOpenBundleFiles:Lr,onOpenBundleChanges:Rr,canOpenReviewForBundle:rr,canOpenFilesForBundle:ir,onOpenBundleVerification:nn.length>0?e=>Fr(e):void 0,onOpenBundleChecks:e=>Fr(e,`checks`),hasConfiguredChecks:nn.length>0,onOpenBundleIde:Nr,onAddTicketToBundle:yi,onStartChatFromBundle:u,onFollowUpTicket:Hr,bundleActionState:yt,onBuildBundle:ii,onReviewBundle:ai,onUndoBundleReview:si,onRunBundle:di,onStopBundle:fi,onParkBundleWrapper:yr,onUnparkBundleWrapper:br,onOpenTicketDetails:fn,onOpenBundleDetails:(e,t)=>{$r(e,t)},onRequestBundleRefresh:e=>{ei(`bundleRefresh`,()=>Kr(e))},onRequestTicketRefresh:ae,hoveredBundleId:_e,onHoverBundleChange:ye,multiColumnBundleIds:_n,onResumeBundleAutomation:ci,onDismissBundleAutomationPause:li,onOpenBuildQuestions:e=>{Jr(e)},className:`min-w-[272px] max-w-[272px] flex-[0.98] bg-card/65`,headerAccessory:(0,X.jsxs)(Q,{type:`button`,variant:`destructive`,size:`xs`,className:`gap-1.5`,disabled:vn.length===0||Be,onClick:()=>ze(!0),children:[(0,X.jsx)(fC,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{children:F(`board.doneColumn.emptyAction`)})]})})]})})]})}),(0,X.jsxs)(xse,{zIndex:5,dropAnimation:Le?null:void 0,children:[pe&&(0,X.jsx)(h3,{ticket:pe,allTickets:L,dependencies:z,bundles:B,projectMemoryEnabled:!!t?.memory_enabled,automationStatus:pe.worktree_bundle_id?fe.get(pe.worktree_bundle_id):null,overlay:!0,activeTool:i,showModelSelector:(()=>{let e=yF(pe,i);return bF(e)&&Pe(e).length>0})(),availableModels:Pe(yF(pe,i)),runDisabled:uy(pe,Qt,Zt,F(`board.errors.runBlockedByActive`))!==void 0,runDisabledReason:uy(pe,Qt,Zt,F(`board.errors.runBlockedByActive`)),onDependencyStart:qn,onDeleteDependency:Jn,onRegisterOverlayNode:xe,onCreateBundle:fr,onDeleteBundle:xr,onRefreshBundles:G,onUpdate:Cr,onDelete:()=>wr(pe.id),onUndo:()=>Tr(pe.id),undoInProgress:He===pe.state&&(pe.state===`build`||pe.state===`review`),onRetry:()=>Er(pe.id),onAdvance:()=>mi(pe.id),onPark:()=>_r(pe.id),onUnpark:()=>vr(pe.id),onBuildChain:()=>hi(pe.id),onRun:pe.worktree_bundle_id===null&&zy(pe)&&pe.has_run_config?()=>Dr(pe.id):void 0,onOpenIde:pe.worktree_bundle_id===null&&$n(pe)?()=>Or(pe.id):void 0,onStop:pe.worktree_bundle_id===null?()=>kr(pe.id):void 0,onStopBuild:()=>Ar(pe.id),onStopBuildChain:()=>gi(pe.id),onResumeBuild:()=>Mr(pe.id),onInterruptReview:()=>void jr(pe.id),onFollowUp:e=>Hr(pe.id,e),onRequestTicketRefresh:ae}),!pe&&he&&(0,X.jsx)(CF,{group:he,activeTool:i,modelsByTool:Fe,automationStatus:fe.get(he.bundle.id),overlay:!0,renderTicket:Qn})]}),en&&(0,X.jsx)(Zpe,{className:`pointer-events-auto fixed left-1/2 top-4 z-20 w-[min(14rem,calc(100vw-2rem))] -translate-x-1/2`})]}),we&&(()=>{let r=Pe(i),a=Vt&&Yn.model&&xF(Yn.model,r),o=a?Yn.model:``,s=a?Yn.variant:``;return(0,X.jsx)(Xpe,{onSubmit:dr,bundles:B,projectId:e,projectBranchState:n,tool:i,showModelSelector:Vt,showSkillsSelector:i===`opencode`,showDockerSandboxModelNotice:t?.build_execution_provider===`docker_sandbox`,onOpenProjectExecutionSettings:P,availableModels:r,availableSkills:Ie,initialModel:o,initialVariant:s,initialSkills:Vt&&i===`opencode`?Yn.skills:[],initialWorktreeBundleId:we.initialWorktreeBundleId,initialImportedDraft:we.initialImportedDraft,onCreateBundle:fr,onDeleteBundle:xr,onRefreshBundles:G,onClose:()=>Te(null)})})(),Re&&(0,X.jsx)(Nde,{ticketCount:vn.length,isDeleting:Be,onCancel:()=>ze(!1),onConfirm:()=>{_i()}}),J&&(0,X.jsx)(m3,{ticket:J,allTickets:L,dependencies:z,bundles:B,projectMemoryEnabled:!!t?.memory_enabled,automationStatus:J.automation_paused_reason?null:J.worktree_bundle_id?fe.get(J.worktree_bundle_id):null,projectBranchState:n,onClose:()=>{let e=J.id;Ke(null),qe(null),R(t=>t.map(t=>t.id===e?p8(t):t)),x?.()},showModelSelector:Ht,showSkillsSelector:yF(J,i)===`opencode`,activeTool:i,availableModels:Pe(yF(J,i)),availableReviewerModels:Me[i],isLoadingReviewerModels:Ne[i],availableSkills:Ie,runDisabled:uy(J,Qt,Zt,F(`board.errors.runBlockedByActive`))!==void 0,runDisabledReason:uy(J,Qt,Zt,F(`board.errors.runBlockedByActive`)),onDeleteDependency:Jn,onCreateBundle:fr,onDeleteBundle:xr,onRefreshBundles:G,onUpdate:Cr,onAdvance:()=>mi(J.id),onBuildChain:()=>hi(J.id),onRun:zy(J)&&J.has_run_config?()=>Dr(J.id):void 0,onOpenIde:$n(J)?()=>Or(J.id):void 0,onStop:()=>kr(J.id),onStopBuild:()=>Ar(J.id),onStopBuildChain:()=>gi(J.id),onResumeBuild:()=>Mr(J.id),onInterruptReview:()=>void jr(J.id),onFollowUp:(e,t)=>Hr(J.id,e,t),onReviewFollowUp:(e,t)=>J.worktree_bundle_id?pi(J.worktree_bundle_id,e,t,`changes`):Hr(J.id,e,t,`changes`),onProjectMemorySuggestionsChanged:()=>{wt(e=>e+1)},onRequestTicketRefresh:e=>{dn(e)},onWorkspaceReviewOpen:O?e=>{O({kind:`ticket`,ticketId:J.id},e)}:void 0,onViewSourceSpec:c,onNavigateToLifecycleSource:l,onOpenBuildQuestions:e=>{Jr(e)},onOpenChecks:J.worktree_bundle_id&&(nn.length>0||J.latest_check_gate_evaluation)?()=>{Fr(J.worktree_bundle_id,`checks`)}:void 0,onStopAutomation:J.worktree_bundle_id?()=>fi(J.worktree_bundle_id):void 0}),ut&&e&&t&&(()=>{let t=L.find(e=>e.id===ut.ticketId);if(!t)return null;let n=!!t.worktree_bundle_id,r=t.worktree_bundle_id?mn.get(t.worktree_bundle_id)?.required_check_policy??t.bundle?.required_check_policy:void 0,i=r?.required_check_definition_ids??an,a=r?.pre_review_check_definition_ids??on,o=n?{projectId:e,targetKind:`bundle`,targetBundleId:t.worktree_bundle_id}:null,s={scope:`ticket`,ticketId:t.id,projectId:t.project_id};return(0,X.jsx)(p.Suspense,{fallback:null,children:(0,X.jsx)(T8,{targetLabel:ut.label,definitions:nn,requiredDefinitionIds:i,preReviewDefinitionIds:a,checksTarget:o,testsTarget:s,onClose:()=>dt(null),requestedInitialTab:ut.requestedInitialTab})})})(),ft&&(()=>{let{target:e}=ft,t=L.find(t=>t.id===e.ticketId),n=e.kind===`bundle`,r=n?L.some(t=>t.worktree_bundle_id===e.bundleId):!!t,i=n?L.some(t=>t.worktree_bundle_id===e.bundleId&&t.agent_status===`running`):t?.agent_status===`running`,a=n?r&&!i:!!t&&!i,o=!!(ft.isRouteOwned&&w!==void 0),s=o?w:null,l=o?s?.canSubmitReviewPrompt??!1:a,u=i?F(`board.changes.reviewPromptDisabledReason`):r?!n&&t?u3(t).disabledReason??void 0:void 0:F(`board.changes.targetUnavailableReason`),d=!i&&(n||t?.state===`build`||t?.state===`review`),f=n?mn.get(e.bundleId):void 0;return(0,X.jsx)(G6,{target:{scope:`ticket`,ticketId:e.ticketId,onTicketUpdate:Cr,onRequestTicketRefresh:ae},initialMode:ft.initialMode,reviewMode:ft.isRouteOwned?C?.mode:void 0,onReviewModeChange:ft.isRouteOwned?k:void 0,enabledModes:[`changes`,`files`],projectId:ft.projectId,reviewCommentsBundleId:n?e.bundleId:null,title:ft.title,bundleTargetName:ft.bundleTargetName,fileTarget:f?.kind===`project_root`?{kind:`repo_root`,bundle_id:null,ticket_id:null}:void 0,onSubmitReviewPrompt:o?s?.submitPrompt:t=>n?pi(e.bundleId,t,ft.followUpMode,`changes`):Hr(e.ticketId,t,ft.followUpMode,`changes`),canSubmitReviewPrompt:l,reviewSubmitDisabledReason:o?s?.reviewSubmitDisabledReason??F(`workspaceReviewModal.chatRequired`):u,canAddReviewComments:l,canModifyChanges:a,changesDisabledReason:i?F(`board.changes.modifyChangesDisabledReason`):u,mode:o?s?.mode:ft.followUpMode,onModeChange:o?s?.onModeChange:e=>{pt(t=>t&&{...t,followUpMode:e})},canToggleMode:o?s?.canSubmitReviewPrompt??!1:d,isUpdatingMode:s?.isUpdatingMode??!1,onClose:()=>{if(pt(null),ft.isRouteOwned&&A?.(),n){Kr(e.bundleId);return}dn(e.ticketId)},onViewSourceSpec:c,originSpecSessionId:t?.origin_spec_session_id??null,originSpecSnapshotId:t?.origin_spec_snapshot_id??null})})(),mt&&e&&t&&(()=>{let t=mn.get(mt.bundleId)?.required_check_policy??mt.requiredCheckPolicy,n=t?.required_check_definition_ids??an,r=t?.pre_review_check_definition_ids??on;return(0,X.jsx)(p.Suspense,{fallback:null,children:(0,X.jsx)(T8,{targetLabel:mt.label,definitions:nn,requiredDefinitionIds:n,preReviewDefinitionIds:r,checksTarget:{projectId:e,targetKind:`bundle`,targetBundleId:mt.bundleId,gateEvaluationId:mt.gateEvaluationId},testsTarget:sn?{scope:`project`,projectId:e,targetKind:`bundle`,targetBundleId:mt.bundleId}:null,onClose:()=>ht(null),requestedInitialTab:mt.requestedInitialTab})})})(),Qe&&hn&&(0,X.jsx)(Wde,{details:hn,activeColumn:tt,isLoading:gt||yt.bundleRefresh,actionState:yt,canOpenIde:tr(hn),projectMemoryEnabled:!!t?.memory_enabled,memorySuggestionsRefreshKey:Ct,automationStatus:hn.tickets.some(e=>e.automation_paused_reason)?null:fe.get(hn.bundle.id),runDisabled:$t(hn.bundle.id),showModelSelector:Ut,activeTool:i,modelsByTool:Fe,modelsLoadingByTool:Ne,availableSkills:Ie,onClose:()=>{let e=hn.bundle.id;$e(null),nt(null),it(null),vt(!1),St(o8()),R(t=>t.map(t=>t.worktree_bundle_id===e&&t.id!==We?p8(t):t)),D?.()},onOpenTicketDetails:fn,onNavigateToLifecycleSource:l,onUpdateTicket:Cr,onOpenIde:()=>{let e=hn.tickets.find(e=>e.id===hn.target_ticket_id)??hn.tickets.find(e=>e.has_worktree);e&&Or(e.id)},onOpenVerification:nn.length>0?()=>{Fr(hn.bundle.id)}:void 0,onOpenChecks:nn.length>0||hn.tickets.some(e=>e.latest_check_gate_evaluation)?()=>{Fr(hn.bundle.id,`checks`)}:void 0,onRefresh:e=>ei(`bundleRefresh`,()=>Kr(e)).then(()=>void 0),onWorkspaceReviewOpen:O?e=>{O({kind:`bundle`,bundleId:hn.bundle.id},e)}:void 0,onUpdateBundle:mr,onBuildBundle:ii,onStopBuildTicket:ti,onResumeBuildTicket:ri,onInterruptReviewTicket:ni,onReviewBundle:ai,onContinueReviewBundle:oi,onUndoBundleReview:si,onRunBundle:di,onStopBundle:fi,onFollowUpBundle:pi,onOpenBuildQuestions:e=>{Jr(e)},onResumeBundleAutomation:ci,onDismissBundleAutomationPause:li}),at&&st&&(0,X.jsx)(Bpe,{details:st,onClose:()=>{lt.current+=1,ot(null),ct(null)},onRefresh:qr,onSubmit:Yr})]})},O8=({count:e,title:t,isDeleting:n,onConfirm:r,onCancel:i,labels:a})=>{let o=e>1;return(0,X.jsxs)(tC,{onClose:i,overlayClassName:`bg-black/70`,panelClassName:`max-w-sm rounded-2xl border border-border bg-card p-6 shadow-2xl`,children:[(0,X.jsx)(`h2`,{className:`mb-3 text-sm font-semibold uppercase tracking-widest text-muted-foreground`,children:o?a.bulkTitle:a.title}),t?(0,X.jsx)(`p`,{className:`mb-1 text-sm text-foreground`,children:t}):null,(0,X.jsx)(`p`,{className:`mb-6 text-xs text-muted-foreground`,children:o?a.bulkDescription(e):a.description}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,X.jsx)(Q,{type:`button`,variant:`ghost`,onClick:i,disabled:n,children:a.cancel}),(0,X.jsx)(Q,{type:`button`,variant:`destructive`,onClick:r,disabled:n,children:n?a.deleting:a.delete})]})]})},k8=({label:e})=>(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6 text-sm text-muted-foreground`,children:e}),A8=({label:e})=>(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6 text-sm text-muted-foreground`,children:e}),j8=({title:e,description:t,startNewSessionLabel:n,onStartNewSession:r,canStartNewSession:i})=>(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6`,children:(0,X.jsxs)(iC,{className:`w-full max-w-lg border-dashed border-border/70 bg-card/40`,children:[(0,X.jsxs)(aC,{children:[(0,X.jsx)(oC,{children:e}),(0,X.jsx)(sC,{children:t})]}),(0,X.jsx)(lC,{children:(0,X.jsx)(Q,{type:`button`,onClick:r,disabled:!i,children:n})})]})}),Mme=({className:e})=>(0,X.jsx)(Ug,{"aria-hidden":`true`,className:e}),Nme=({className:e})=>(0,X.jsx)(jg,{"aria-hidden":`true`,className:e}),Pme=({className:e})=>(0,X.jsx)(Mg,{"aria-hidden":`true`,className:e}),M8=({sessions:e,sessionGroups:t,activeSessionId:n,isDraftOpen:r,isLoadingSessions:i,isOpen:a,onToggleOpen:o,testId:s,railTestId:c,onDraftOpen:l,isCreatingSession:u,isSendingPrompt:d,newSessionShortcutHint:f,newSessionTooltip:m,isSelectionMode:h,selectedSessionIds:g,selectedSessionCount:_,hasDeletableSessions:v,deletingSessionIds:y,onEnterSelectionMode:b,onExitSelectionMode:x,onToggleSessionSelection:S,onSetSessionSelection:C,onConfirmDeleteSelectedSessions:w,selectionPresets:T,onSessionSelect:E,onConfirmDeleteSession:D,getSessionId:O,getSessionTitle:k,getDeleteDisabledReason:A,getActivityState:j,getRowAriaLabel:M,renderRowContent:N,labels:P})=>{let F=(0,p.useMemo)(()=>new Set(e.filter(e=>!A(e)&&!y.has(O(e))).map(e=>O(e))),[y,A,O,e]),I=(0,p.useMemo)(()=>T.map(t=>({...t,matchingSessionIds:new Set(e.filter(e=>F.has(O(e))&&t.matches(e)).map(O))})),[O,F,T,e]),L=(0,p.useRef)(null),R=(0,p.useRef)(!1),z=(0,p.useRef)(null),ee=(0,p.useCallback)(()=>{z.current!==null&&(window.clearTimeout(z.current),z.current=null)},[]),B=(0,p.useCallback)(()=>{ee(),z.current=window.setTimeout(()=>{R.current=!1,z.current=null},0)},[ee]),V=(0,p.useCallback)(()=>{L.current&&(L.current=null,B())},[B]),H=(0,p.useCallback)(e=>{let t=L.current;!t||t.visitedSessionIds.has(e)||!F.has(e)||(t.visitedSessionIds.add(e),C(e,t.mode===`select`))},[C,F]),U=(0,p.useCallback)(e=>{let t=L.current;!t||e.pointerId!==t.pointerId||V()},[V]);return(0,p.useEffect)(()=>{if(!h){V();return}return window.addEventListener(`pointerup`,U),window.addEventListener(`pointercancel`,U),()=>{window.removeEventListener(`pointerup`,U),window.removeEventListener(`pointercancel`,U),V(),ee()}},[ee,U,h,V]),(0,X.jsx)(`aside`,{"data-testid":s,"data-state":a?`expanded`:`collapsed`,"aria-label":P.ariaLabel,className:Z(`relative z-20 flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-background/40 transition-[width] duration-200 ease-out motion-reduce:transition-none`,a?`w-72`:`w-16`),children:a?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-start gap-2 border-b border-border/70 px-4 py-3.5`,children:[(0,X.jsxs)(Q,{type:`button`,size:`sm`,className:`gap-2`,onClick:l,disabled:u||d,children:[(0,X.jsx)(xv,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:P.newSession}),f]}),(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":P.collapseAriaLabel,"aria-expanded":a,className:`ml-auto`,onClick:o,children:(0,X.jsx)(Nme,{className:`h-4 w-4`})})]}),e.length>0?(0,X.jsx)(`div`,{className:`px-4 py-2.5`,children:h?(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 px-2 text-xs`,onClick:x,disabled:y.size>0,children:P.cancelSelection}),(0,X.jsxs)(eb,{children:[(0,X.jsx)(tb,{asChild:!0,children:(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 gap-1.5 px-2 text-xs`,children:P.addPreset})}),(0,X.jsx)(nb,{align:`start`,className:`w-44`,children:I.map(e=>(0,X.jsx)(rb,{disabled:e.matchingSessionIds.size===0,onSelect:()=>{for(let t of e.matchingSessionIds)C(t,!0)},children:e.label},e.key))})]}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`destructive`,className:`h-7 px-2 text-xs`,onClick:w,disabled:_===0||y.size>0,children:P.deleteSelected})]}),(0,X.jsx)(`div`,{className:`flex justify-end text-xs font-medium text-muted-foreground`,children:P.selectedCount(_)})]}):v?(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 gap-1.5 px-2 text-xs`,onClick:b,children:[(0,X.jsx)(Mme,{className:`h-3.5 w-3.5`}),P.select]}):null}):null,(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:i&&e.length===0?(0,X.jsx)(`div`,{className:`px-2 py-4 text-sm text-muted-foreground`,children:P.loadingSessions}):e.length===0?(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border/70 px-3 py-4 text-sm text-muted-foreground`,children:P.noSessions}):(0,X.jsx)(`div`,{className:`flex flex-col gap-3`,children:t.map(e=>(0,X.jsxs)(`section`,{"aria-label":e.label,className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(`div`,{className:`px-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground/80`,children:e.label}),e.sessions.map(e=>{let t=O(e),i=!r&&t===n,a=A(e),o=y.has(t),s=!!a||o,c=g.has(t),l=j(e,i);return(0,X.jsxs)(`div`,{"data-session-id":t,"data-session-selectable":s?`false`:`true`,className:Z(`group relative rounded-xl border transition-colors`,i?`border-sky-400/40 bg-sky-500/10 text-foreground ring-1 ring-sky-400/40`:`border-border/50 bg-card/35 text-muted-foreground hover:border-border/80 hover:bg-card/60 hover:text-foreground`),onPointerDownCapture:e=>{!h||s||e.pointerType&&e.pointerType!==`mouse`||typeof e.button==`number`&&e.button!==0||(e.preventDefault(),ee(),R.current=!0,L.current={pointerId:e.pointerId,mode:c?`deselect`:`select`,visitedSessionIds:new Set},H(t))},onPointerMove:e=>{let n=L.current;!n||n.pointerId!==e.pointerId||H(t)},children:[(0,X.jsx)(`button`,{type:`button`,"aria-label":M(e,l),className:`flex w-full min-w-0 cursor-pointer items-start gap-2 rounded-xl px-3 py-2 pr-11 text-left transition-colors focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:outline-none`,onClick:()=>{if(h){if(R.current){R.current=!1;return}if(s)return;S(t);return}E(e)},children:N({session:e,isActive:i,activityState:l,isSelectionMode:h})}),h?(0,X.jsx)(`div`,{className:`absolute top-2 right-2 flex h-7 w-7 items-center justify-center`,title:a??P.selectSessionTitle(k(e)),children:(0,X.jsx)(`input`,{type:`checkbox`,"aria-label":P.selectSessionAriaLabel(k(e)),checked:c,disabled:s,onClick:e=>{e.stopPropagation()},onChange:()=>{R.current||S(t)},className:`h-4 w-4 rounded border-border bg-background text-primary`})}):(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":P.deleteSessionAriaLabel,className:Z(`absolute top-2 right-2 h-7 w-7 shrink-0 rounded-md border border-transparent text-muted-foreground transition-all duration-150 hover:border-border/70 hover:bg-card/80 hover:text-foreground focus-visible:border-border/70 focus-visible:bg-card/80 focus-visible:text-foreground`,`opacity-100 sm:opacity-0 sm:pointer-events-none sm:group-hover:pointer-events-auto sm:group-focus-within:pointer-events-auto sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,s&&`sm:disabled:opacity-0 sm:group-hover:disabled:opacity-50 sm:group-focus-within:disabled:opacity-50`,(i||o)&&`sm:pointer-events-auto sm:opacity-100 sm:disabled:opacity-50`,a&&`cursor-not-allowed text-muted-foreground/50 hover:border-transparent hover:bg-transparent hover:text-muted-foreground/50 focus-visible:border-transparent focus-visible:bg-transparent focus-visible:text-muted-foreground/50`),title:a??P.deleteSessionTitle(k(e)),disabled:s,onClick:e=>{e.stopPropagation(),D(t)},children:(0,X.jsx)(fC,{className:`h-4 w-4`})})]},t)})]},e.key))})})]}):(0,X.jsxs)(`div`,{"data-testid":c,className:`flex h-full w-full flex-col items-center gap-2 bg-background/80 py-3`,children:[m?(0,X.jsx)(vv,{content:m,side:`right`,children:(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,"aria-label":P.newSession,className:`h-9 w-9`,onClick:l,disabled:u||d,children:(0,X.jsx)(xv,{className:`h-4 w-4`})})}):(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,"aria-label":P.newSession,className:`h-9 w-9`,onClick:l,disabled:u||d,children:(0,X.jsx)(xv,{className:`h-4 w-4`})}),(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":P.openAriaLabel,"aria-expanded":a,className:`h-9 w-9`,onClick:o,children:(0,X.jsx)(Pme,{className:`h-4 w-4`})})]})})},N8=({isInterrupting:e,onStop:t,interruptLabel:n,interruptingLabel:r})=>(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`gap-2`,disabled:e,onClick:t,children:[e?(0,X.jsx)(Ov,{className:`h-4 w-4 animate-spin`}):(0,X.jsx)(jv,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:e?r:n})]}),P8=4,Fme=5e3,F8=(e,t)=>qb.t(`common:chatChangesPanel.${e}`,t),I8=e=>e.replace(/^[ab]\//,``),L8=e=>{let t=`oldPath`in e&&typeof e.oldPath==`string`?I8(e.oldPath):``,n=`newPath`in e&&typeof e.newPath==`string`?I8(e.newPath):``;return[...new Set([n,t].filter(e=>e&&e!==`/dev/null`))]},R8=e=>{let[t,n]=L8(e);return!t&&!n?F8(`unknownFile`):t&&n&&t!==n?`${n} -> ${t}`:t??n??F8(`unknownFile`)},z8=e=>{let t=hG((()=>{let[t,n]=L8(e);return t??n??null})());if(!t)return null;try{return RM(e.hunks,{highlight:!0,refractor:uK.default,language:t,enhancers:[LM(e.hunks)]})}catch{return null}},B8=(e,t)=>e instanceof Error?e.message:t,Ime=(e,t)=>{if(!t)return e;let n=R8(t);return[t,...e.filter(e=>R8(e)!==n)]},Lme=e=>[...e].sort((e,t)=>{if(e.filePath!==t.filePath)return e.filePath.localeCompare(t.filePath);let n=e.newLineNumber??e.oldLineNumber??2**53-1,r=t.newLineNumber??t.oldLineNumber??2**53-1;return n===r?e.changeKey.localeCompare(t.changeKey):n-r}),Rme=({diffResponse:e,gitStatus:t})=>{let n=new Map;for(let t of e?.files??[])n.set(t.path,t);return t?t.files.map(e=>{let t=n.get(e.path)??(e.original_path?n.get(e.original_path):void 0);return{path:e.path,originalPath:e.original_path,status:e.status,staged:e.staged,unstaged:e.unstaged,conflicted:e.conflicted,additions:t?.additions??0,deletions:t?.deletions??0}}):(e?.files??[]).map(e=>({path:e.path,originalPath:null,status:null,staged:!1,unstaged:!1,conflicted:!1,additions:e.additions,deletions:e.deletions}))},V8=e=>{let t=e.split(/[\\/]/);return t[t.length-1]||e},zme={modified:`border-amber-500/40 bg-amber-500/10 text-amber-200`,added:`border-emerald-500/40 bg-emerald-500/10 text-emerald-200`,deleted:`border-rose-500/40 bg-rose-500/10 text-rose-200`,renamed:`border-sky-500/40 bg-sky-500/10 text-sky-200`,untracked:`border-violet-500/40 bg-violet-500/10 text-violet-200`,typechanged:`border-slate-500/40 bg-slate-500/10 text-slate-200`},Bme=e=>F8(`fileStatus.${e}`),Vme=({selectedDiffPath:e,sidebarFiles:t,diffStats:n,triggerMode:r=`full`,onSelectDiffPath:i})=>{let[a,o]=(0,p.useState)(!1),s=t.find(t=>t.path===e)??null,c=r===`compact`?e===`all`?F8(`picker.diff`):s?V8(s.path):F8(`picker.file`):e===`all`?F8(`picker.allChanges`):s?V8(s.path):e;return(0,X.jsxs)(av,{open:a,onOpenChange:o,children:[(0,X.jsx)(ov,{asChild:!0,children:(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,className:Z(`max-w-full gap-2`,r===`full`?`min-w-0 max-w-[18rem]`:`min-w-0 px-2.5`),"aria-label":F8(`picker.openChangedFilesAriaLabel`),title:e===`all`?void 0:s?.path??e,children:[(0,X.jsx)(`span`,{className:`truncate`,children:c}),r===`full`&&(0,X.jsx)(rC,{variant:`outline`,className:`shrink-0 text-[10px] uppercase tracking-wide`,children:F8(`picker.fileCount`,{count:t.length})}),(0,X.jsx)(bv,{className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,X.jsxs)(sv,{align:`start`,className:`z-[90] w-[28rem] max-w-[calc(100vw-2rem)] p-0`,children:[(0,X.jsx)(`div`,{className:`border-b border-border/80 px-4 py-3`,children:(0,X.jsx)(`div`,{className:`text-sm font-semibold text-foreground`,children:F8(`picker.title`)})}),(0,X.jsx)(`div`,{className:`max-h-[min(28rem,calc(100vh-10rem))] overflow-y-auto p-3`,children:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{i(`all`),o(!1)},className:Z(`flex w-full cursor-pointer items-start gap-3 rounded-xl border px-3 py-2.5 text-left transition-colors`,Z3(e===`all`),`justify-between`),children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:F8(`picker.allChanges`)}),(0,X.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground transition-colors group-hover:text-foreground/70`,children:F8(`picker.allChangesDescription`)})]}),n&&(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 text-[11px]`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground transition-colors group-hover:text-foreground/70`,children:F8(`picker.fileCount`,{count:n.files_changed})}),(0,X.jsxs)(`span`,{className:`font-mono tabular-nums text-emerald-400`,children:[`+`,n.additions]}),(0,X.jsxs)(`span`,{className:`font-mono tabular-nums text-rose-400`,children:[`-`,n.deletions]})]})]}),t.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>{i(t.path),o(!1)},className:Z(`flex w-full cursor-pointer items-start gap-3 rounded-xl border px-3 py-2.5 text-left transition-colors`,Z3(e===t.path)),children:(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:V8(t.path)}),(0,X.jsx)(`div`,{className:`mt-0.5 break-all font-mono text-[11px] text-muted-foreground transition-colors group-hover:text-foreground/70`,children:t.path})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 text-[11px]`,children:[(0,X.jsxs)(`span`,{className:`font-mono tabular-nums text-emerald-400`,children:[`+`,t.additions]}),(0,X.jsxs)(`span`,{className:`font-mono tabular-nums text-rose-400`,children:[`-`,t.deletions]})]})]}),(0,X.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5 text-[11px]`,children:[t.status&&(0,X.jsx)(rC,{variant:`outline`,className:zme[t.status],children:Bme(t.status)}),t.staged&&(0,X.jsx)(rC,{variant:`outline`,children:F8(`fileStatus.staged`)}),t.unstaged&&(0,X.jsx)(rC,{variant:`outline`,children:F8(`fileStatus.unstaged`)}),t.conflicted&&(0,X.jsx)(rC,{variant:`destructive`,children:F8(`fileStatus.conflicted`)}),t.originalPath&&(0,X.jsx)(`span`,{className:`break-all font-mono text-[11px] text-muted-foreground transition-colors group-hover:text-foreground/70`,children:t.status===`renamed`?F8(`fileStatus.renamedFrom`,{path:t.originalPath}):t.originalPath})]})]})},`${t.path}:${t.originalPath??``}`))]})})]})]})},H8=(0,p.memo)(({projectId:e,chatSessionId:t=null,canSubmitReviewPrompt:n,reviewSubmitDisabledReason:r,onSubmitReviewPrompt:i,state:a,onStateChange:o,isResizing:s=!1,onClose:c,desktopWidth:l,panelElementRef:u})=>{let[d,f]=(0,p.useState)(null),[m,h]=(0,p.useState)(null),[g,_]=(0,p.useState)(null),[v,y]=(0,p.useState)(!1),[,b]=(0,p.useState)(!1),[x,S]=(0,p.useState)(new Map),[C,w]=(0,p.useState)(!1),T=(0,p.useRef)(0),E=(0,p.useRef)(0),D=(0,p.useRef)(null),O=(0,p.useRef)(null),k=a.selectedDiffPath,A=a.activeReviewTarget,j=a.editingReviewCommentKey,M=A?.commentKey??j??`chat`,N=a.reviewDraftInput,P=(0,p.useMemo)(()=>new Map(a.reviewComments.map(e=>[qM(e.filePath,e.changeKey),e])),[a.reviewComments]),F=(0,p.useCallback)(async()=>{if(!e)throw Error(`Project id is required`);return t?await kae(e,t):await rr(e)},[t,e]),I=(0,p.useCallback)(async()=>{if(!e)throw Error(`Project id is required`);return t?await Aae(e,t):await ur(e)},[t,e]);(0,p.useEffect)(()=>{D.current=d},[d]),(0,p.useEffect)(()=>{O.current=m},[m]);let L=(0,p.useCallback)(async()=>{if(!e){E.current+=1,f(null),h(null),_(null),y(!1),b(!1);return}let t=T.current+1,n=E.current+1;T.current=t,E.current=n,y(!0),b(!0);let r=F().then(e=>{T.current===t&&(D.current=e,f(e),_(null))}).catch(e=>{T.current===t&&_(B8(e,F8(`errors.loadDiff`)))}).finally(()=>{T.current===t&&E.current===n&&y(!1)}),i=I().then(e=>{T.current===t&&(O.current=e,h(e))}).catch(()=>{}).finally(()=>{T.current===t&&b(!1)});await Promise.allSettled([r,i])},[F,I,e]),R=(0,p.useCallback)(async(t={})=>{if(!e)return;let{broadcastOnSignatureChange:n=!1}=t,r=T.current+1;T.current=r,b(!0);try{let t=await I();if(T.current!==r)return;let i=O.current?.workspace_signature??null,a=t.workspace_signature??null,o=!D.current||i!==a;if(O.current=t,h(t),!o){E.current+=1,y(!1);return}let s=!D.current,c=E.current+1;E.current=c,s&&y(!0);try{let t=await F();if(T.current!==r)return;D.current=t,f(t),_(null),n&&i!==a&&i6(e)}catch(e){if(T.current!==r)return;D.current||_(B8(e,F8(`errors.loadDiff`)))}finally{s&&E.current===c&&y(!1)}}catch{D.current||(E.current+=1,y(!1));return}finally{T.current===r&&b(!1)}},[F,I,e]);(0,p.useEffect)(()=>{L()},[L]),(0,p.useEffect)(()=>{if(e)return a6(t=>{t===e&&R()})},[e,R]),(0,p.useEffect)(()=>{if(!e)return;let t=hx(()=>{document.visibilityState===`visible`&&R({broadcastOnSignatureChange:!0})});return()=>{t()}},[e,R]),(0,p.useEffect)(()=>{if(!e)return;let t=window.setInterval(()=>{document.visibilityState===`visible`&&R({broadcastOnSignatureChange:!0})},Fme);return()=>{window.clearInterval(t)}},[e,R]);let z=(0,p.useMemo)(()=>{let e=typeof d?.diff==`string`?d.diff:``;return e.trim()?tO(e,{nearbySequences:`zip`}).map(e=>({...e,pathCandidates:L8(e)})):[]},[d]),ee=(0,p.useMemo)(()=>{let e=new Map;for(let t of z)for(let n of t.pathCandidates)e.has(n)||e.set(n,t);return e},[z]),B=(0,p.useMemo)(()=>Rme({diffResponse:d,gitStatus:m}),[d,m]);(0,p.useEffect)(()=>{if(k!==`all`&&!(!d&&!m)){if(B.length===0){o(e=>({...e,selectedDiffPath:`all`}));return}B.some(e=>e.path===k)||o(e=>({...e,selectedDiffPath:`all`}))}},[d,m,o,k,B]);let V=k===`all`?null:ee.get(k)??null,H=(0,p.useMemo)(()=>Ime(z,V),[z,V]),U=(0,p.useMemo)(()=>k===`all`?z:V?[V]:[],[z,k,V]);(0,p.useEffect)(()=>{S(new Map)},[z]),(0,p.useEffect)(()=>{if(H.length===0)return;let e=!1,t=null,n=0,r=()=>{if(e)return;let i=H.slice(n,n+P8);i.length!==0&&(S(e=>{let t=new Map(e);for(let e of i){let n=R8(e);t.has(n)||t.set(n,z8(e))}return t}),n+=P8,n<H.length&&(t=window.setTimeout(r,0)))};return t=window.setTimeout(r,0),()=>{e=!0,t!==null&&window.clearTimeout(t)}},[H]);let W=(0,p.useMemo)(()=>{let e=new Map;for(let t of H.slice(0,P8))e.set(R8(t),z8(t));return e},[H]),te=(0,p.useMemo)(()=>U.map(e=>({...e,tokens:x.get(R8(e))??W.get(R8(e))??null})),[W,x,U]),ne=(0,p.useMemo)(()=>z.map(e=>({...e,tokens:null})),[z]),re=(0,p.useMemo)(()=>Lme(a.reviewComments),[a.reviewComments]),ie=re.length,ae=n&&!C&&ie>0,G=(0,p.useCallback)(()=>{o(e=>({...e,activeReviewTarget:null,editingReviewCommentKey:null,reviewDraftInput:``,reviewComments:[]}))},[o]),oe=(0,p.useCallback)(({filePath:e,changeKey:t,commentKey:r})=>{let i=P.get(r);if(i){o(e=>({...e,selectedDiffPath:i.filePath,activeReviewTarget:null,editingReviewCommentKey:r,reviewDraftInput:i.comment}));return}n&&o(n=>({...n,activeReviewTarget:{filePath:e,changeKey:t,commentKey:r},editingReviewCommentKey:null,reviewDraftInput:``}))},[n,o,P]),se=(0,p.useCallback)(()=>{o(e=>({...e,activeReviewTarget:null,editingReviewCommentKey:null,reviewDraftInput:``}))},[o]),ce=(0,p.useCallback)(e=>{let t=P.has(e.commentKey);if(!n&&!t)return;let r=N.trim();if(!r)return;let i=e.change.type===`insert`?null:`oldLineNumber`in e.change?e.change.oldLineNumber:e.change.lineNumber,a=e.change.type===`delete`?null:`newLineNumber`in e.change?e.change.newLineNumber:e.change.lineNumber;o(t=>{let n=new Map(t.reviewComments.map(e=>[qM(e.filePath,e.changeKey),e]));return n.set(e.commentKey,{scope:`uncommitted`,filePath:e.filePath,changeKey:e.changeKey,changeType:e.change.type,oldLineNumber:i,newLineNumber:a,hunkHeader:e.hunk.content,lineContent:e.change.content,diffSnippet:JM(e.hunk,e.change),comment:r}),{...t,activeReviewTarget:null,editingReviewCommentKey:null,reviewDraftInput:``,reviewComments:[...n.values()]}})},[n,o,P,N]),le=(0,p.useCallback)(e=>{let t=P.get(e);t&&o(n=>({...n,selectedDiffPath:t.filePath,activeReviewTarget:null,editingReviewCommentKey:e,reviewDraftInput:t.comment}))},[o,P]),ue=(0,p.useCallback)(e=>{o(t=>({...t,activeReviewTarget:t.activeReviewTarget?.commentKey===e?null:t.activeReviewTarget,editingReviewCommentKey:t.editingReviewCommentKey===e?null:t.editingReviewCommentKey,reviewDraftInput:t.activeReviewTarget?.commentKey===e||t.editingReviewCommentKey===e?``:t.reviewDraftInput,reviewComments:t.reviewComments.filter(t=>qM(t.filePath,t.changeKey)!==e)}))},[o]),de=(0,p.useCallback)(async()=>{if(!ae)return;w(!0);let e=QM({drafts:re,findings:[],githubComments:[],uncommittedFiles:z});try{await i(e),G(),$.success(F8(`toasts.sendChangesSuccess`),{id:`chat-diff-review-submit-success`})}catch(e){$.error(B8(e,F8(`errors.sendChanges`)),{id:`chat-diff-review-submit-error`})}finally{w(!1)}},[ae,G,i,z,re]),fe=(0,p.useCallback)(e=>(0,X.jsx)(A3,{reviewComments:re,pendingFixCount:ie,triggerMode:e===`wide`?`full`:`compact`,canSendReview:ae,isSubmittingReview:C,reviewSubmitDisabledReason:r??void 0,onClearPendingFixes:G,onSubmitReview:()=>{de()}}),[ae,G,de,C,ie,re,r]),pe=c?(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":F8(`closeAriaLabel`),className:`text-muted-foreground hover:text-foreground`,onClick:c,children:(0,X.jsx)(ax,{className:`h-4 w-4`})}):null,me=l?{"--chat-changes-panel-width":`${l}px`}:void 0;return(0,X.jsx)(`aside`,{"data-testid":`chat-changes-panel`,"data-desktop-width":l?String(l):void 0,ref:u,style:me,className:Z(`flex h-[26rem] min-h-0 w-full shrink-0 flex-col overflow-hidden border-t border-border/70 bg-background/20 xl:h-full xl:border-l xl:border-t-0`,l?`xl:w-[var(--chat-changes-panel-width)]`:`xl:w-[32rem]`),children:(0,X.jsx)(X3,{selectedDiffPath:k,sidebarFiles:B,diffResponse:d,isDiffLoading:v,diffError:g,allDiffFiles:ne,renderedFiles:te,viewType:`unified`,onViewTypeChange:()=>{},onRetry:()=>{L()},activeReviewTarget:A,editingReviewCommentKey:j,reviewDraftInstanceKey:M,reviewDraftInput:N,reviewComments:re,reviewFindings:[],githubComments:[],selectedReviewFindingIds:[],selectedGitHubCommentIds:[],canSelectReviewTarget:n,canEditActiveReviewDraft:n,reviewFindingsError:null,gitHubCommentsError:null,hasStaleReviewFindings:!1,onSelectReviewTarget:oe,onToggleReviewFindingSelection:()=>{},onToggleGitHubCommentSelection:()=>{},onReviewDraftInputChange:e=>{o(t=>({...t,reviewDraftInput:e}))},onCancelReviewDraft:se,onEditReviewDraft:le,onRemoveReviewDraft:ue,onSaveReviewDraft:ce,diffThemeClassName:Q3,resolveFilePath:R8,normalizeDiffPath:I8,emptyStateTitle:F8(`emptyStateTitle`),emptyStateDescription:F8(`emptyStateDescription`),filePickerControl:e=>(0,X.jsx)(Vme,{selectedDiffPath:k,sidebarFiles:B,diffStats:d?.stats??null,triggerMode:e===`wide`?`full`:`compact`,onSelectDiffPath:e=>{o(t=>({...t,selectedDiffPath:e}))}}),reviewSummaryControl:fe,extraHeaderControl:pe,surfaceVariant:`flat`,showViewTypeToggle:!1,gutterVariant:`compact`,isResizing:s,resizePlaceholderLineThreshold:200})})});H8.displayName=`ChatChangesPanel`;var U8=({projectId:e,agentRunParentType:t=null,agentRunParentId:n=null,messages:r,internalLog:i,currentThinkingMessageId:a=null,previousThinkingLog:o=null,previousThinkingMessageId:s=null,pendingAgentTitle:c,streamingResponse:l,isRunning:u,isLoading:d=!1,canShowComposer:f,cardClassName:p,isExternallyResizing:m=!1,pendingAgentRevealKey:h=null,pendingAgentRevealDelayMs:g=0,liveResponseTiming:_=null,composerFocusNonce:v=0,blurComposerOnSendStart:y=!1,hidePendingAgentTitle:b=!1,forceScrollToBottomKey:x,header:S,composerControls:C,composerInlineControls:w,composerTheme:T=`default`,layoutKey:E,scrollLayoutKey:D,followUpPrompt:O,draftAttachments:k=[],followUpPlaceholder:A,emptyStateText:j=null,renderMessageFooter:M,renderMessageBody:N,isSendingFollowUp:P,isComposerSubmitDisabled:F=!1,isUploadingAttachments:I=!1,canAttachImages:L=!1,followUpDisabledReason:R,postBuildCheck:z=null,onFollowUpPromptChange:ee,onFollowUpKeyDown:B,onFollowUpPaste:V,onUploadAttachments:H,onRemoveAttachment:U,onFollowUpSubmit:W})=>(0,X.jsx)(BJ,{projectId:e,agentRunParentType:t,agentRunParentId:n,messages:r,internalLog:i,currentThinkingMessageId:a,previousThinkingLog:o,previousThinkingMessageId:s,pendingAgentTitle:c,streamingResponse:l,isRunning:u,isLoading:d,autoScrollBehavior:`sticky`,surfaceVariant:`chat`,canShowComposer:f,cardClassName:p,header:S,composerControls:C,composerInlineControls:w,composerTheme:T,composerSize:`compact-on-laptop`,showThinkingPlacement:`header`,pinComposerToBottom:!0,isExternallyResizing:m,pendingAgentRevealKey:h,pendingAgentRevealDelayMs:g,liveResponseTiming:_,composerFocusNonce:v,blurComposerOnSendStart:y,forceScrollToBottomKey:x,layoutKey:E,scrollLayoutKey:D,followUpPrompt:O,draftAttachments:k,followUpPlaceholder:A,emptyStateText:j,autoFocusComposer:!0,renderMessageFooter:M,renderMessageBody:N,isSendingFollowUp:P,isComposerSubmitDisabled:F,isUploadingAttachments:I,canAttachImages:L,followUpDisabledReason:R,postBuildCheck:z,hidePendingAgentTitle:b,onFollowUpPromptChange:ee,onFollowUpKeyDown:B,onFollowUpPaste:V,onUploadAttachments:H,onRemoveAttachment:U,onFollowUpSubmit:W}),W8=({disabled:e=!1,onClick:t})=>{let n=qb.t(`chatView.startBuilding.label`);return(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`gap-2 border-emerald-400/40 bg-emerald-400/10 text-emerald-100 hover:bg-emerald-400/20 hover:text-white`,"aria-label":qb.t(`chatView.startBuilding.ariaLabel`),disabled:e,onClick:t,children:[(0,X.jsx)(kv,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:n})]})},Hme=`mt-1 flex min-h-5 flex-wrap items-center gap-2 text-xs text-muted-foreground`,Ume=({label:e})=>(0,X.jsx)(`div`,{className:`inline-flex items-center rounded-full border border-amber-500/30 bg-amber-500/10 px-2 py-0.5 text-[11px] font-medium text-amber-100`,children:e}),G8=({title:e,tool:t=null,modelLabel:n=null,interrupted:r=!1,interruptedLabel:i,usage:a=null,metadataExtra:o=null,actions:s=null,warnings:c=null})=>(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`h3`,{className:`truncate text-sm font-semibold text-foreground`,children:e}),(0,X.jsxs)(`div`,{className:Hme,children:[(0,X.jsx)(jF,{tool:t,className:`text-[11px]`}),n?(0,X.jsx)(`p`,{children:n}):null,r?(0,X.jsx)(Ume,{label:i}):null,a?(0,X.jsx)(MF,{totalTokens:a.totalTokens,contextWindow:a.contextWindow,cost:a.cost,tool:a.tool,model:a.model,availableModels:a.availableModels}):null,o]})]}),s]}),c]}),K8=({projectId:e,suggestions:t,title:n,description:r,emptyState:i=null,onSuggestionsChanged:a})=>(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(n||r)&&(0,X.jsxs)(`div`,{children:[n&&(0,X.jsx)(`h4`,{className:`text-xs font-semibold uppercase tracking-[0.2em] text-muted-foreground`,children:n}),r&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r})]}),t.length>0?(0,X.jsx)(Pw,{projectId:e,suggestions:t,onChanged:(e,t)=>a?.(e,t)}):i&&(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed border-border/70 px-3 py-4 text-sm text-muted-foreground`,children:i})]}),q8=()=>({selectedDiffPath:`all`,activeReviewTarget:null,editingReviewCommentKey:null,reviewDraftInput:``,reviewComments:[]}),Wme=[{key:`today`,label:`Today`},{key:`yesterday`,label:`Yesterday`},{key:`last_7_days`,label:`Last 7 Days`},{key:`older`,label:`Older`}],Gme=e=>{if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t},J8=e=>e.activity_at??e.last_user_message_at??e.created_at,Kme=(e,t)=>{let n=J8(e),r=J8(t);return n===r?e.created_at===t.created_at?t.id.localeCompare(e.id):t.created_at.localeCompare(e.created_at):r.localeCompare(n)},Y8=e=>[...e].sort(Kme),qme=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),Jme=(e,t=new Date)=>{let n=Gme(J8(e));if(!n)return`older`;let r=qme(t),i=new Date(r);i.setDate(i.getDate()-1);let a=new Date(r);return a.setDate(a.getDate()-6),n>=r?`today`:n>=i?`yesterday`:n>=a?`last_7_days`:`older`},X8=(e,t=new Date)=>{let n=new Map;for(let r of Y8(e)){let e=Jme(r,t);n.set(e,[...n.get(e)??[],r])}return Wme.flatMap(e=>{let t=n.get(e.key)??[];return t.length===0?[]:[{key:e.key,label:e.label,sessions:t}]})},Z8=e=>{let t={...e};return delete t.messages,t.agent_log=null,t.agent_message_id=null,t.previous_agent_log=null,t.previous_agent_message_id=null,t.streaming_response=null,t},Q8=e=>e===`claude`?qb.t(`chatView.tool.claude`):qb.t(`chatView.tool.opencode`),$8=e=>new Map(e.map(e=>[e.id,e.label])),e5=({availableModelsById:e,model:t})=>t?e.get(t)??t:null,t5=({modelLabel:e,tool:t})=>e??Q8(t),n5=()=>qb.t(`chatView.user.you`),r5=`archon.chat-draft`,i5=({projectId:e,tool:t,chatSessionId:n})=>n?`${r5}:${e}:session:${n}`:`${r5}:${e}:draft:${t}`,a5=e=>{if(!e)return``;try{return window.localStorage.getItem(e)??``}catch{return``}},o5=({storageKey:e,value:t})=>{if(e)try{if(t){window.localStorage.setItem(e,t);return}window.localStorage.removeItem(e)}catch{}},s5=({activeProject:e,activeProjectBranchState:t,session:n})=>!e||n.target_available===!1?!1:n.target_kind===`bundle`?e.active_target_kind===`bundle`&&!!n.target_bundle_id&&e.active_target_bundle_id===n.target_bundle_id:e.active_target_kind===`bundle`?!1:!t||!n.target_branch_snapshot?!0:t.status!==`ready`||!t.branch?!1:t.branch===n.target_branch_snapshot,c5=({session:e,activeProject:t,activeProjectBranchState:n})=>e.target_kind===`bundle`?e.target_label_snapshot||qb.t(`common:chatView.targets.bundleFallback`):!t||t.active_target_kind===`bundle`||n?.status!==`ready`||!n.branch||!e.target_branch_snapshot||n.branch===e.target_branch_snapshot?null:qb.t(`common:chatView.targets.repoRootWithBranch`,{branch:e.target_branch_snapshot}),l5=e=>e.target_kind===`bundle`?e.target_label_snapshot||qb.t(`common:chatView.targets.bundleFallback`):e.target_branch_snapshot?qb.t(`common:chatView.targets.repoRootWithBranch`,{branch:e.target_branch_snapshot}):qb.t(`common:chatView.targets.repoRoot`),u5=({activeProject:e,activeProjectBranchState:t})=>e?e.active_target_kind===`bundle`?qb.t(`common:chatView.targets.selectedBundleTarget`):t?.branch?qb.t(`common:chatView.targets.repoRootWithBranch`,{branch:t.branch}):qb.t(`common:chatView.targets.repoRoot`):qb.t(`common:chatView.targets.currentTarget`),d5=(e,t)=>qb.t(`chatView.${e}`,t),Yme=1500,Xme=`archon.chat-run-config`,Zme=`archon.chat-changes-panel-layout`,Qme=`archon.chat-session-list-layout`,f5=512,p5=360,$me=.6,ehe=6,m5=`/`,the=`Slash`,nhe=`NumpadDivide`,rhe=600,h5=4,g5=(e,t)=>{let n=Number.isFinite(e)?Math.round(e):f5;if(!Number.isFinite(t))return Math.max(p5,n);let r=Math.max(p5,Math.round(t*$me));return Math.max(p5,Math.min(r,n))},ihe=e=>d5(e===`plan`?`mode.plan`:`mode.build`),_5=e=>d5(e===`plan`?`placeholders.plan`:`placeholders.build`),v5=e=>d5(`pendingMemorySuggestions`,{count:e}),ahe=e=>!e.defaultPrevented&&!e.altKey&&!e.repeat&&(e.ctrlKey||e.metaKey)&&(e.key===m5||e.code===the||e.code===nhe),y5=({modifierLabel:e,keys:t,ariaHidden:n=!1})=>(0,X.jsxs)(`span`,{"aria-hidden":n,className:`flex items-center gap-0.5 text-[10px] leading-none`,children:[(0,X.jsx)(UY,{"aria-hidden":n,children:e}),t.map(e=>(0,X.jsxs)(`span`,{className:`contents`,children:[(0,X.jsx)(`span`,{children:`+`}),(0,X.jsx)(UY,{"aria-hidden":n,children:e})]},e))]}),ohe=({label:e,modifierLabel:t,keys:n})=>(0,X.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{children:e}),(0,X.jsx)(y5,{modifierLabel:t,keys:n,ariaHidden:!0})]}),b5=({projectId:e,tool:t})=>`${Xme}:${e}:${t}`,x5=e=>`${Zme}:${e}`,S5=e=>`${Qme}:${e}`,she=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(Boolean).filter((e,t,n)=>n.indexOf(e)===t):[],C5=e=>{if(!e)return{isOpen:!0,width:f5};try{let t=window.localStorage.getItem(x5(e));if(!t)return{isOpen:!0,width:f5};let n=JSON.parse(t),r=typeof n.width==`number`&&Number.isFinite(n.width)?Math.max(p5,Math.round(n.width)):f5;return{isOpen:n.isOpen!==!1,width:r}}catch{return{isOpen:!0,width:f5}}},w5=e=>{if(!e)return{isOpen:!0};try{let t=window.localStorage.getItem(S5(e));return t?{isOpen:JSON.parse(t).isOpen!==!1}:{isOpen:!0}}catch{return{isOpen:!0}}},che=({projectId:e,isOpen:t,width:n})=>{if(e)try{window.localStorage.setItem(x5(e),JSON.stringify({isOpen:t,width:n}))}catch{}},lhe=({projectId:e,isOpen:t})=>{if(e)try{window.localStorage.setItem(S5(e),JSON.stringify({isOpen:t}))}catch{}},T5=({projectId:e,tool:t})=>{if(!e||t!==`opencode`&&t!==`claude`)return null;try{let n=window.localStorage.getItem(b5({projectId:e,tool:t}));if(!n)return null;let r=JSON.parse(n),i=(typeof r.model==`string`?r.model.trim():``)||null,a=r.mode===`plan`||r.mode===`build`?r.mode:null;return!i&&!a?null:{model:i,variant:i&&typeof r.variant==`string`&&r.variant.trim()||null,mode:a,skills:she(r.skills)}}catch{return null}},E5=({projectId:e,tool:t,model:n,variant:r,mode:i,skills:a})=>{if(!(!e||t!==`opencode`&&t!==`claude`||!n&&!i))try{window.localStorage.setItem(b5({projectId:e,tool:t}),JSON.stringify({model:n,variant:n?r:null,mode:i,skills:a}))}catch{}},uhe=({projectId:e,tool:t})=>{let n=T5({projectId:e,tool:t});!n||n.skills.length===0||E5({projectId:e,tool:t,...n,skills:[]})},D5=({projectId:e,tool:t})=>T5({projectId:e,tool:t})?.mode??`plan`,O5=({activeProjectId:e,helperModel:t,helperVariant:n,activeTool:r,availableModels:i,availableSkills:a})=>{let o=T5({projectId:e,tool:r}),s=t??``,c=o?.model??``,l=xF(c,i)?c:xF(s,i)?s:``,u=l===c?o?.variant??null:l&&l===s?n??null:null,d=i.find(e=>e.id===l)??null,f=d?d.variants.includes(u??``)?u??``:``:l?u??``:``,p=new Set(a.map(e=>e.name));return{model:l,variant:f,mode:o?.mode??`plan`,skills:r===`opencode`?(o?.skills??[]).filter(e=>p.has(e)):[]}},k5=e=>e&&e.replace(/\s+/g,` `).trim()||null,dhe=e=>{let t=k5(e.first_user_message_preview);if(t)return t;let n=e.messages?.find(e=>e.role===`user`)?.content;return k5(n)},fhe=({chatSessionId:e,instruction:t,attachments:n,createdAt:r})=>({id:`optimistic:${e}:${r}`,chat_session_id:e,role:`user`,kind:`prompt`,content:t,attachments:n,created_at:r}),phe=({session:e,instruction:t,attachments:n,createdAt:r})=>({...e,messages:[...e.messages??[],fhe({chatSessionId:e.id,instruction:t,attachments:n,createdAt:r})],activity_at:r,last_user_message_at:r,updated_at:r}),mhe=e=>!!(e.first_user_message_preview||e.last_user_message_at||e.messages?.some(e=>e.role===`user`)),A5=e=>e.agent_status===`running`?d5(`sidebar.deleteDisabledReason`):null,hhe=({proposals:e,isApplying:t,onApply:n})=>e.status===`applied`?(0,X.jsxs)(`div`,{className:`w-full rounded-md border border-emerald-500/30 bg-emerald-500/10 px-3 py-3 text-sm`,children:[(0,X.jsx)(`div`,{className:`font-medium text-foreground`,children:d5(`ticketProposal.createdTitle`)}),(0,X.jsx)(`div`,{className:`mt-1 text-muted-foreground`,children:d5(`ticketProposal.createdDescription`,{count:e.created_tickets.length})}),e.created_tickets.length>0?(0,X.jsx)(`ul`,{className:`mt-3 space-y-1 text-foreground`,children:e.created_tickets.map(e=>(0,X.jsx)(`li`,{children:e.title},e.ticket_id))}):null]}):(0,X.jsxs)(`div`,{className:`w-full rounded-md border border-sky-500/30 bg-sky-500/10 px-3 py-3 text-sm`,children:[(0,X.jsx)(`div`,{className:`font-medium text-foreground`,children:d5(`ticketProposal.proposedTitle`)}),(0,X.jsx)(`div`,{className:`mt-1 text-muted-foreground`,children:d5(`ticketProposal.proposedDescription`)}),(0,X.jsx)(`ul`,{className:`mt-3 space-y-3`,children:e.tickets.map(e=>(0,X.jsxs)(`li`,{className:`rounded border border-border/60 bg-background/80 px-3 py-2`,children:[(0,X.jsx)(`div`,{className:`font-medium text-foreground`,children:e.title}),(0,X.jsx)(`div`,{className:`mt-1 whitespace-pre-wrap text-muted-foreground`,children:e.description})]},e.key))}),e.dependencies.length>0?(0,X.jsx)(`div`,{className:`mt-3 text-muted-foreground`,children:d5(`ticketProposal.dependenciesLabel`,{value:e.dependencies.map(e=>`${e.blocker_key} -> ${e.dependent_key}`).join(`, `)})}):null,(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(Q,{type:`button`,size:`sm`,onClick:n,disabled:t,children:d5(t?`ticketProposal.creating`:`ticketProposal.create`)})})]}),ghe=({activeProjectId:e,activeProject:t,activeProjectBranchState:n=null,targetBundles:r=[],targetBranchSuggestions:i={current_branch:null,default_branch:null,previous_branch:null},isTargetBundleLoading:a=!1,isTargetSelectorLoading:o=!1,onTargetSelectorOpenChange:s,onSelectBundleTarget:c=async()=>!1,onSelectRepoRootTarget:l=async()=>!1,activeTool:u,routedChatSessionId:d,onRoutedChatNavigationUnavailable:f,onSessionNavigation:m,initialDraftOpen:h=!1,onInitialDraftOpenConsumed:g,initialSpecDraft:_=null,onInitialSpecDraftConsumed:v,onViewSourceSpec:y,onNavigateToLifecycleSource:b,onRestoreSessionTarget:x,onReviewCapabilityChange:S,isExternallyResizing:C=!1,showChangesPanel:w=!0})=>{let T=uq(),[E,D]=(0,p.useState)([]),[O,k]=(0,p.useState)(null),[A,j]=(0,p.useState)(null),M=pF(A?.post_build_check),[N,P]=(0,p.useState)(null),[F,I]=(0,p.useState)(!1),[L,R]=(0,p.useState)(null),[z,ee]=(0,p.useState)(()=>D5({projectId:e,tool:u})),[B,V]=(0,p.useState)({}),[H,U]=(0,p.useState)({}),[W,te]=(0,p.useState)({}),[ne,re]=(0,p.useState)([]),[ie,ae]=(0,p.useState)(``),[G,oe]=(0,p.useState)(``),[se,ce]=(0,p.useState)([]),[le,ue]=(0,p.useState)(!1),[de,fe]=(0,p.useState)(!1),[pe,me]=(0,p.useState)(!1),[he,ge]=(0,p.useState)(!1),[_e,ve]=(0,p.useState)(!1),[ye,be]=(0,p.useState)(null),[xe,Se]=(0,p.useState)([]),[Ce,we]=(0,p.useState)(()=>new Set),[Te,Ee]=(0,p.useState)(!1),[De,Oe]=(0,p.useState)(()=>new Set),[ke,Ae]=(0,p.useState)(!1),[je,Me]=(0,p.useState)(!1),[Ne,Pe]=(0,p.useState)(null),[Fe,Ie]=(0,p.useState)(null),[Le,K]=(0,p.useState)([]),[Re,ze]=(0,p.useState)(!1),[Be,Ve]=(0,p.useState)(!1),[He,q]=(0,p.useState)(0),[Ue,We]=(0,p.useState)(q8),[J,qe]=(0,p.useState)(()=>w5(e).isOpen),[Je,Xe]=(0,p.useState)(()=>C5(e).isOpen),[Ze,Y]=(0,p.useState)(!1),[Qe,$e]=(0,p.useState)(!1),[et,tt]=(0,p.useState)(()=>C5(e).width),[nt,rt]=(0,p.useState)(0),[it,at]=(0,p.useState)(null),[ot,st]=(0,p.useState)(()=>new Set),ct=(0,p.useRef)({model:``,variant:``,skills:[],showModelSelector:!1}),lt=(0,p.useRef)(!1),ut=(0,p.useRef)(L),dt=(0,p.useRef)(null),ft=(0,p.useRef)(null),pt=(0,p.useRef)(new Set),mt=(0,p.useRef)(0),ht=(0,p.useRef)(0),gt=(0,p.useRef)(d),_t=(0,p.useRef)(!1),vt=(0,p.useRef)(null),yt=(0,p.useRef)(null),bt=(0,p.useRef)(null),xt=(0,p.useRef)(null),St=(0,p.useRef)(null),Ct=(0,p.useRef)(null),wt=(0,p.useRef)(!1),Tt=(0,p.useRef)(!1),Et=(0,p.useRef)(0),Dt=(0,p.useRef)(f5),Ot=(0,p.useRef)(f5),kt=(0,p.useRef)(!1),At=(0,p.useRef)(0),jt=(0,p.useRef)({id:null,status:null}),Mt=(0,p.useRef)(new Map),Nt=(0,p.useRef)({}),Pt=(0,p.useRef)({}),Ft=(0,p.useRef)(new Set),It=(0,p.useRef)(!1),Lt=e?i5({projectId:e,tool:F?u:A?.tool??u,chatSessionId:F?null:O}):null,Rt=Lt?B[Lt]??``:``,zt=F?u:A?.tool??u,Bt=A?H[A.id]??[]:[],Vt=(A?W[A.id]??0:0)>0,{models:Ht,isLoading:Ut}=QP(zt),Wt=(0,p.useCallback)(()=>{ce([]),uhe({projectId:e,tool:u})},[e,u]);(0,p.useEffect)(()=>{lt.current=F},[F]),(0,p.useEffect)(()=>{Nt.current=B},[B]),(0,p.useEffect)(()=>{Pt.current=H},[H]),gt.current=d,(0,p.useEffect)(()=>{if(!(d===void 0||!de)){if(!d){lt.current||Wt(),P(null),be(null),k(null),j(null),I(!0);return}if(!(E.some(e=>e.id===d)||A?.id===d)){k(null),j(null),I(!1),f?.();return}O!==d&&(P(null),be(null),k(d),j(null),I(!1),kt.current=!0)}},[A?.id,O,de,f,Wt,d,E]),(0,p.useEffect)(()=>{if(!Lt||Ft.current.has(Lt))return;Ft.current.add(Lt);let e=a5(Lt);e&&V(t=>Object.prototype.hasOwnProperty.call(t,Lt)?t:{...t,[Lt]:e})},[Lt]),(0,p.useEffect)(()=>{!Lt||!Object.prototype.hasOwnProperty.call(B,Lt)||o5({storageKey:Lt,value:B[Lt]??``})},[Lt,B]),(0,p.useEffect)(()=>{if(!F){dt.current=null;return}let e=dt.current;!e||!Lt||Rt||V(t=>t[Lt]?t:{...t,[Lt]:e})},[F,Lt,Rt]),(0,p.useEffect)(()=>{ft.current=O},[O]),(0,p.useEffect)(()=>{ut.current=L},[L]);let Gt=(0,p.useCallback)(()=>{ht.current+=1},[]),Kt=(0,p.useCallback)(e=>{Gt(),j(e)},[Gt]);(0,p.useEffect)(()=>{if(!It.current){It.current=!0;return}let t=C5(e),n=w5(e);lt.current=!1,kt.current=!1,Ft.current=new Set,pt.current.clear(),k(null),Kt(null),I(!1),V({}),U({}),te({}),be(null),Se([]),we(new Set),Ee(!1),Oe(new Set),at(null),K([]),Ve(!1),fe(!1),We(q8()),st(new Set),Mt.current=new Map,Ot.current=t.width,qe(n.isOpen),tt(t.width),Xe(t.isOpen)},[e,Kt]),(0,p.useEffect)(()=>{Ze||(Ot.current=et,bt.current&&(bt.current.style.setProperty(`--chat-changes-panel-width`,`${et}px`),bt.current.setAttribute(`data-desktop-width`,String(et))))},[et,Ze]),(0,p.useEffect)(()=>{if(!w||!vt.current)return;let e=vt.current.getBoundingClientRect().width;if(e<=0)return;let t=g5(et,e);t!==et&&(Ot.current=t,tt(t))},[et,w]),(0,p.useEffect)(()=>{lhe({projectId:e,isOpen:J})},[e,J]),(0,p.useEffect)(()=>{w&&che({projectId:e,isOpen:Je,width:et})},[e,et,Je,w]),(0,p.useEffect)(()=>{Ve(!1)},[O,F]);let qt=(0,p.useCallback)(e=>{let t=Z8(e);D(e=>{let n=e.findIndex(e=>e.id===t.id);if(n===-1)return Y8([...e,t]);let r=[...e];return r[n]=t,Y8(r)})},[]),Jt=(0,p.useCallback)((t,n={})=>{let r=Array.from(new Set(t));if(r.length===0)return;let i=new Set(r),a=ft.current,o=n.preserveDraftRoute===!0,s=!!(o&&a&&i.has(a)&&gt.current===a),c=!!(!o&&a&&i.has(a)),l=c?E.find(e=>!i.has(e.id))??null:null;s&&(Wt(),m?.(null)),c&&(l||Wt(),m?.(l?.id??null));let d=e?r.map(t=>i5({projectId:e,tool:u,chatSessionId:t})):[];V(e=>{let t=d.filter(t=>Object.prototype.hasOwnProperty.call(e,t));if(t.length===0)return e;let n={...e};for(let e of t)delete n[e];return n}),U(e=>{let t={...e},n=!1;for(let e of r)Object.prototype.hasOwnProperty.call(t,e)&&(delete t[e],n=!0);return n?t:e}),te(e=>{let t={...e},n=!1;for(let e of r)Object.prototype.hasOwnProperty.call(t,e)&&(delete t[e],n=!0);return n?t:e});for(let e of d)o5({storageKey:e,value:``});D(e=>{let t=e.filter(e=>!i.has(e.id));if(a&&i.has(a)){if(gt.current===a)return o?(k(null),Kt(null),I(!0),t):(k(null),Kt(null),I(l===null),K([]),ze(!1),Ve(!1),t);let e=t[0]??null;k(e?.id??null),Kt(null),I(e===null),K([]),ze(!1),Ve(!1)}return t}),st(e=>{let t=new Set(e),n=!1;for(let e of r)t.delete(e)&&(n=!0);return n?t:e}),at(e=>e&&i.has(e.parentId)?null:e),be(e=>e&&i.has(e)?null:e),Se(e=>e.filter(e=>!i.has(e))),we(e=>{let t=new Set(e),n=!1;for(let e of r)t.delete(e)&&(n=!0);return n?t:e}),Oe(e=>{let t=new Set(e),n=!1;for(let e of r)t.delete(e)&&(n=!0);return n?t:e})},[e,u,m,Kt,Wt,E]),Yt=(0,p.useCallback)((e,t)=>{Jt([e],t)},[Jt]),Xt=(0,p.useCallback)((e,t)=>{e&&V(n=>n[e]===t?n:{...n,[e]:t})},[]),Zt=(0,p.useCallback)(e=>{e&&(V(t=>t[e]===``?t:{...t,[e]:``}),o5({storageKey:e,value:``}))},[]),Qt=(0,p.useCallback)((e,t)=>{U(n=>{if(t.length===0){if(!Object.prototype.hasOwnProperty.call(n,e))return n;let t={...n};return delete t[e],t}return{...n,[e]:t}})},[]),$t=(0,p.useCallback)(e=>{U(t=>{if(!Object.prototype.hasOwnProperty.call(t,e))return t;let n={...t};return delete n[e],n}),te(t=>{if(!Object.prototype.hasOwnProperty.call(t,e))return t;let n={...t};return delete n[e],n})},[]),en=(0,p.useCallback)((e,t)=>{te(n=>{let r=Math.max(0,(n[e]??0)+t);if(r===0){if(!Object.prototype.hasOwnProperty.call(n,e))return n;let t={...n};return delete t[e],t}return{...n,[e]:r}})},[]),tn=(0,p.useCallback)(({fromStorageKey:e,toStorageKey:t})=>{if(!e||!t||e===t)return;let n=Object.prototype.hasOwnProperty.call(Nt.current,e)?Nt.current[e]??``:a5(e);V(r=>{let i={...r,[t]:n};return delete i[e],i}),o5({storageKey:t,value:n}),o5({storageKey:e,value:``})},[]),nn=(0,p.useCallback)((e,t)=>{D(n=>{let r=n.findIndex(t=>t.id===e);if(r===-1)return n;let i=n[r];if(i.pending_memory_suggestion_count===t)return n;let a=[...n];return a[r]={...i,pending_memory_suggestion_count:t},a}),j(n=>!n||n.id!==e||n.pending_memory_suggestion_count===t?n:(ht.current+=1,{...n,pending_memory_suggestion_count:t}))},[]),rn=(0,p.useCallback)(async r=>{if(!e){D([]),k(null),Kt(null),I(!1),fe(!1);return}ue(!0);try{let i=await uN(e,r);if(r?.aborted)return;let a=Y8(i.map(Z8)),o=a[0]??null,s=t?.active_target_kind===`bundle`||n?.status!==`loading`;D(a),fe(!0),k(e=>d===void 0?lt.current?null:e&&a.some(t=>t.id===e)?e:e?a[0]?.id??null:kt.current?null:o?s?(kt.current=!0,s5({activeProject:t,activeProjectBranchState:n,session:o})?o.id:null):null:(kt.current=!0,null):e),a.length===0&&!d&&!lt.current&&(Wt(),I(!0))}catch(e){Ye(e)||$.error(e instanceof Error?e.message:d5(`errors.loadSessions`))}finally{r?.aborted||ue(!1)}},[t,n,e,Wt,Kt,d]),an=(0,p.useCallback)(async(t,n)=>{if(!e){Kt(null);return}me(!0);let r=mt.current+1;mt.current=r;let i=ht.current;try{let a=await dN(e,t,n);if(n?.aborted)return;let o=ht.current!==i,s=mt.current===r,c=ft.current===t&&!lt.current;if(!s||o||!c)return;Kt(a),qt(a)}catch(e){e instanceof Ge&&e.status===404&&gt.current===t&&ft.current===t?f?.():Ye(e)||$.error(e instanceof Error?e.message:d5(`errors.loadSession`))}finally{n?.aborted||me(!1)}},[e,f,Kt,qt]),on=(0,p.useCallback)(async(n,r)=>{if(!e||!t?.memory_enabled){K([]),ze(!1);return}ze(!0);try{let t=await Ar(e,null,r,n);if(r?.aborted)return;K(t.suggestions),nn(n,t.suggestions.length)}catch(e){Ye(e)||$.error(e instanceof Error?e.message:d5(`errors.loadMemorySuggestions`))}finally{r?.aborted||ze(!1)}},[t?.memory_enabled,e,nn]),sn=(0,p.useCallback)(e=>{K(t=>{let n=t.filter(t=>t.id!==e);return O&&nn(O,n.length),n}),q(e=>e+1),rn(),O&&an(O)},[O,an,rn,nn]);(0,p.useEffect)(()=>{let e=new AbortController;return rn(e.signal),()=>{e.abort()}},[rn]),(0,p.useEffect)(()=>{if(d!==void 0||lt.current||F||O||kt.current||E.length===0||t?.active_target_kind!==`bundle`&&n?.status===`loading`)return;kt.current=!0;let e=E[0]??null;e&&s5({activeProject:t,activeProjectBranchState:n,session:e})&&k(e.id)},[t,n,O,F,d,E]),(0,p.useEffect)(()=>{if(zt!==`opencode`&&zt!==`claude`){re([]),Me(!1);return}if(zt!==`opencode`){re([]);return}let t=new AbortController;return(async()=>{Me(!0);try{re(await $P(zt,t.signal,e))}catch(e){Ye(e)||re(e=>e)}finally{t.signal.aborted||Me(!1)}})(),()=>{t.abort()}},[e,zt]),(0,p.useEffect)(()=>{if(F||!O){Kt(null);return}if(A?.id===O)return;Kt(null);let e=new AbortController;return an(O,e.signal),()=>{e.abort()}},[A,O,F,an,Kt]),(0,p.useEffect)(()=>{if(!t?.memory_enabled||F||!O){K([]),ze(!1);return}let e=new AbortController;return on(O,e.signal),()=>{e.abort()}},[t?.memory_enabled,O,F,on,He]),(0,p.useEffect)(()=>{!Be||Re||Le.length>0||Ve(!1)},[Re,Be,Le.length]),(0,p.useEffect)(()=>{if(!O||A?.agent_status!==`running`)return;let e=new AbortController,t=window.setInterval(()=>{Promise.all([rn(e.signal),an(O,e.signal)])},Yme);return()=>{e.abort(),window.clearInterval(t)}},[A?.agent_status,O,an,rn]),(0,p.useEffect)(()=>{if(!e)return;let t=t=>{!t||t.project_id!==e||(t.id===O&&Kt(t),mhe(t)&&qt(t))},n=t=>{if(!t||t.project_id!==e)return;let n=pt.current.delete(t.id);Yt(t.id,n?{preserveDraftRoute:!0}:void 0)},r=()=>{rn();let e=ft.current;e&&!lt.current&&an(e)};return T.on(`connect`,r),T.on(`chat-session:created`,t),T.on(`chat-session:updated`,t),T.on(`chat-session:deleted`,n),()=>{T.off(`connect`,r),T.off(`chat-session:created`,t),T.off(`chat-session:updated`,t),T.off(`chat-session:deleted`,n)}},[e,O,an,rn,Yt,Kt,T,qt]),(0,p.useEffect)(()=>{F&&(ut.current||ee(D5({projectId:e,tool:u})))},[e,u,F]),(0,p.useEffect)(()=>{if(zt!==`opencode`&&zt!==`claude`){ae(``),oe(``),ce([]);return}if(F){let n=ew(t?.helper_models,zt),r=O5({activeProjectId:e,helperModel:n.model??(zt===`opencode`?t?.helper_model:null)??null,helperVariant:n.variant??(zt===`opencode`?t?.helper_variant:null)??null,activeTool:zt,availableModels:Ht,availableSkills:ne});ae(r.model),oe(r.variant),ce(r.skills);return}ae(A?.model??``),oe(A?.variant??``)},[e,t?.helper_model,t?.helper_models,t?.helper_variant,A?.id,A?.model,A?.variant,Ht,ne,zt,F]),(0,p.useEffect)(()=>{if(zt!==`opencode`){ce([]);return}F||ce(A?.skills??[])},[A?.skills,zt,F]),(0,p.useEffect)(()=>{let e=Ht.find(e=>e.id===ie)??null;oe(t=>e?e.variants.includes(t)?t:``:t)},[Ht,ie]),(0,p.useEffect)(()=>{if(zt!==`opencode`||!F||!ie||G)return;let n=ew(t?.helper_models,zt),r=O5({activeProjectId:e,helperModel:n.model??(zt===`opencode`?t?.helper_model:null)??null,helperVariant:n.variant??(zt===`opencode`?t?.helper_variant:null)??null,activeTool:zt,availableModels:Ht,availableSkills:ne});r.model===ie&&r.variant&&oe(r.variant)},[e,t?.helper_model,t?.helper_models,t?.helper_variant,zt,Ht,ne,F,ie,G]),(0,p.useEffect)(()=>{if(!ye)return;let e=A?.id===ye?A:E.find(e=>e.id===ye)??null;(!e||e.agent_status!==`running`)&&be(null)},[A,ye,E]),(0,p.useEffect)(()=>{let e=jt.current,n=A?.id??null,r=A?.agent_status??null;e.id===n&&e.status===`running`&&r===`done`&&t?.memory_enabled&&n&&q(e=>e+1),jt.current={id:n,status:r}},[t?.memory_enabled,e,A?.agent_status,A?.id,A?.title]),(0,p.useEffect)(()=>{O&&st(e=>{if(!e.has(O))return e;let t=new Set(e);return t.delete(O),t})},[O]),(0,p.useEffect)(()=>{it&&(it.parentId===O&&(_e||A?.agent_status===`running`)||at(null))},[A?.agent_status,O,_e,it]),(0,p.useEffect)(()=>{let e=Mt.current,t=new Map,n=[];for(let r of E){let i=e.get(r.id)??null,a=r.agent_status??null;i===`running`&&a===`done`&&r.id!==O&&n.push(r),t.set(r.id,a)}Mt.current=t,st(e=>{let t=new Set(e),r=!1,i=new Set(E.map(e=>e.id));for(let e of t)i.has(e)||(t.delete(e),r=!0);for(let e of E){let i=e.agent_status??null,a=n.some(t=>t.id===e.id);if((e.id===O||i!==`done`)&&t.delete(e.id)){r=!0;continue}a&&!t.has(e.id)&&(t.add(e.id),r=!0)}return r?t:e})},[e,O,E]);let cn=(0,p.useMemo)(()=>$8(Ht),[Ht]),ln=(0,p.useMemo)(()=>X8(E),[E]),un=(0,p.useMemo)(()=>{let e=new Set(ln.find(e=>e.key===`older`)?.sessions.map(e=>e.id)??[]);return[{key:`unavailable`,label:d5(`sidebar.presets.unavailable`),matches:e=>e.target_available===!1},{key:`older`,label:d5(`sidebar.presets.older`),matches:t=>e.has(t.id)}]},[ln]),dn=(0,p.useMemo)(()=>xe.length===0?[]:xe.flatMap(e=>{let t=E.find(t=>t.id===e)??(A?.id===e?A:null);return t?[t]:[]}),[A,xe,E]),fn=dn.length===1?dn[0]?.title??null:null;(0,p.useEffect)(()=>{xe.length>0&&dn.length!==xe.length&&Se(dn.map(e=>e.id))},[xe,dn]),(0,p.useEffect)(()=>{let e=new Set(E.filter(e=>!A5(e)&&!Ce.has(e.id)).map(e=>e.id));Oe(t=>{let n=new Set(Array.from(t).filter(t=>e.has(t)));return n.size===t.size?t:n})},[Ce,E]),(0,p.useEffect)(()=>{!Te||J||(Ee(!1),Oe(new Set))},[J,Te]);let pn=(0,p.useMemo)(()=>A?t5({modelLabel:e5({availableModelsById:cn,model:A.model}),tool:A.tool}):null,[A,cn]),mn=(0,p.useMemo)(()=>A?(A.messages??[]).map(e=>({id:e.id,role:e.role,kind:e.kind,content:e.content,attachments:e.attachments??[],ticket_proposals:e.ticket_proposals??null,transcript_runs:e.transcript_runs??null,metadata:e.metadata,responseTiming:e.response_timing?KK(e.response_timing):null,created_at:e.created_at,displayTitle:e.role===`assistant`?pn??Q8(A.tool):n5()})):[],[A,pn]),hn=(0,p.useMemo)(()=>[...A?.messages??[]].reverse().find(e=>e.metadata?.ask_question?.status===`pending`)??null,[A]),gn=!!hn,_n=(0,p.useCallback)(async(t,n)=>{if(!e||!A||Fe)return;let r=UJ({parentType:`chat`,parentId:A.id,setId:n.set_id});Ie(n.set_id);try{let r=await Tae(e,A.id,t,n);Kt(r),qt(r)}catch(e){if(e instanceof Ge&&e.status===409){GJ(r);let t=e.data&&typeof e.data==`object`&&`chat_session`in e.data?e.data.chat_session:null;t?(Kt(t),qt(t)):await an(A.id)}throw $.error(e instanceof Error?e.message:d5(`errors.resolveQuestions`)),e}finally{Ie(null)}},[e,A,an,Kt,Fe,qt]),vn=(0,p.useCallback)(e=>{let t=e.metadata?.ask_question;if(e.role!==`assistant`||!t||!A)return;let n=UJ({parentType:`chat`,parentId:A.id,setId:t.id});return(0,X.jsx)(QJ,{messageContent:e.content,questionSet:t,storageKey:n,isActive:t.status===`pending`&&hn?.id===e.id,isDisabled:A.agent_status===`running`||Fe===t.id,onResolve:t=>_n(e.id,t)})},[A,hn?.id,_n,Fe]),yn=A?.id&&A.agent_status===`running`&&it?.parentId===A.id?it.turnKey:null,bn=(zt===`opencode`||zt===`claude`)&&Ht.length>0,xn=(zt===`opencode`||zt===`claude`)&&!bn&&(je||Ut);(0,p.useEffect)(()=>{ct.current={model:ie,variant:G,skills:se,showModelSelector:bn}},[ie,se,G,bn]);let Sn=(0,p.useMemo)(()=>Ht.find(e=>e.id===ie)??null,[Ht,ie]),Cn=F?z:A?.mode??`build`,wn=F?d5(`composer.newChatTitle`):A?.title??d5(`composer.chatTitle`),Tn=F?u:A?.tool??u,En=(0,p.useMemo)(()=>qY(),[]),Dn=bn?ie||null:A?.model??null,On=Tn===`opencode`||Tn===`claude`,kn=e5({availableModelsById:cn,model:Dn}),An=F?`draft:${e??`none`}:${u}`:A?.id,jn=(0,p.useCallback)(({model:t=ie,variant:n=G,skills:r=se}={})=>{F&&E5({projectId:e,tool:u,model:bn&&t||null,variant:bn&&t&&n||null,mode:z,skills:bn&&u===`opencode`?r:[]})},[e,u,z,F,ie,se,G,bn]),Mn=(0,p.useCallback)(()=>{lt.current=!0,I(!0),Wt(),ee(D5({projectId:e,tool:u})),P(null),k(null),Kt(null),be(null),Ee(!1),Oe(new Set),at(null),R(null),dt.current=null,m?.(null)},[e,u,m,Kt,Wt]);(0,p.useEffect)(()=>{_&&(Mn(),ee(`build`),R({specSessionId:_.specSessionId,specSnapshotId:_.specSnapshotId}),dt.current=_.text,v?.())},[_,Mn,v]),(0,p.useEffect)(()=>{h&&(Mn(),g?.())},[h,Mn,g]);let Nn=(0,p.useCallback)((e,t=null)=>{lt.current=!1,I(!1),P(null),k(e),Kt(t),R(null),m?.(e)},[m,Kt]),Pn=(0,p.useCallback)(async()=>{if(!(!A||!x)){P(A.id);try{await x(A)}catch(e){$.error(e instanceof Error?e.message:d5(`errors.restoreTarget`))}finally{P(e=>e===A.id?null:e)}}},[A,x]),Fn=!!(A&&A.target_available!==!1&&!F&&!s5({activeProject:t,activeProjectBranchState:n,session:A})),In=Fn&&A?d5(`review.mismatchReason`,{sessionTarget:l5(A),currentTarget:u5({activeProject:t,activeProjectBranchState:n})}):null,Ln=Fn&&N===null,Rn=(0,p.useCallback)(async r=>{P(r.id);let i=r;if(e)try{let t=await dN(e,r.id);i=t,qt(t)}catch(e){$.error(e instanceof Error?e.message:d5(`errors.loadSession`)),P(e=>e===r.id?null:e);return}if(i.target_available===!1){Nn(i.id,i);return}if(!s5({activeProject:t,activeProjectBranchState:n,session:i})&&x)try{if(!await x(i)){P(e=>e===i.id?null:e);return}}catch(e){$.error(e instanceof Error?e.message:d5(`errors.restoreTarget`)),P(e=>e===i.id?null:e);return}Nn(i.id,i)},[t,n,e,x,Nn,qt]),zn=(0,p.useCallback)(()=>{rt(e=>e+1)},[]),Bn=(0,p.useCallback)(async t=>{if(F){let n=ct.current;return ee(t),E5({projectId:e,tool:u,model:n.showModelSelector&&n.model||null,variant:n.showModelSelector&&n.model&&n.variant||null,mode:t,skills:n.showModelSelector?n.skills:[]}),zn(),null}if(!e||!A||A.mode===t||ke||gn)return null;Ae(!0);try{let n=await Cae(e,A.id,{mode:t});return E5({projectId:e,tool:n.tool,model:n.model,variant:n.variant,mode:n.mode,skills:n.skills}),Kt(n),qt(n),zn(),n}catch(e){return $.error(e instanceof Error?e.message:d5(`errors.updateMode`)),null}finally{Ae(!1)}},[e,A,u,zn,gn,F,ke,Kt,qt]),Vn=(0,p.useCallback)(async({instruction:t,attachments:n,targetSession:r,startedAt:i})=>{if(!e)return null;let a=ct.current;At.current+=1;let o={parentType:`chat`,parentId:r.id,turnKey:`${r.id}:${At.current}`,startedAt:i};at(o);try{let i=await wae(e,r.id,{instruction:t,...n.length>0?{attachment_ids:n.map(e=>e.id)}:{},tool:r.tool,model:a.showModelSelector&&a.model||null,variant:a.showModelSelector&&a.model&&a.variant||null,skills:a.showModelSelector?a.skills:[]});return E5({projectId:e,tool:i.tool,model:i.model,variant:i.variant,mode:i.mode,skills:i.skills}),lt.current=!1,Kt(i),k(i.id),I(!1),qt(i),i}catch(e){throw at(e=>e?.turnKey===o.turnKey?null:e),e}},[e,Kt,qt]),Hn=(0,p.useCallback)(async({fromStorageKey:t})=>{if(!e)return null;let n=ct.current,r=ut.current,i=await xae(e,{mode:Cn,tool:u,model:n.showModelSelector&&n.model||null,variant:n.showModelSelector&&n.model&&n.variant||null,skills:n.showModelSelector?n.skills:[],originSpecSessionId:r?.specSessionId??null,originSpecSnapshotId:r?.specSnapshotId??null});lt.current=!1,I(!1),k(i.id),Kt(i),m?.(i.id),R(null);let a=i5({projectId:e,tool:i.tool,chatSessionId:i.id});return tn({fromStorageKey:t,toStorageKey:a}),{session:i,storageKey:a}},[e,u,Cn,tn,m,Kt]),Un=(0,p.useCallback)(async(t,n={})=>{let r=n.targetSession??A,i=!r||r.messages?.length===0;if(!e||_e||he||Vt||r?.agent_status===`running`||pF(r?.post_build_check)||r?.target_available===!1||Ln||gn)return!1;let a=t.trim(),o=n.preserveComposerDraft===!0,s=o?[]:r?Pt.current[r.id]??[]:[];if(!a&&s.length===0)return!1;ve(!0);let c=null,l=r,u=performance.now(),d=e&&r?i5({projectId:e,tool:r.tool,chatSessionId:r.id}):null,f=s;try{let t=r;if(!t){ge(!0);let e=await Hn({fromStorageKey:Lt});c=e?.session??null,t=c,d=e?.storageKey??null,f=c?Pt.current[c.id]??[]:[]}if(!t)return!1;o||Zt(d??Lt);let n=phe({session:t,instruction:a,attachments:f,createdAt:new Date().toISOString()});Kt(n),k(n.id),qt(n);let s=await Vn({instruction:a,attachments:f,targetSession:t,startedAt:u});return s&&i&&E5({projectId:e,tool:s.tool,model:s.model,variant:s.variant,mode:s.mode,skills:[]}),o||Zt(s&&e?i5({projectId:e,tool:s.tool,chatSessionId:s.id}):d),s&&!o&&$t(s.id),!0}catch(e){o||Xt(d??Lt,a);let t=Ke(e,`chat_session`);if(t?(lt.current=!1,Kt(t),k(t.id),I(!1),qt(t)):c?(Kt(c),k(c.id),I(!1),qt(c)):l&&(Kt(l),qt(l)),e instanceof Ge&&e.status===409&&!t){let e=c?.id??l?.id;e&&await an(e)}throw e}finally{ge(!1),ve(!1)}},[e,A,$t,Zt,Hn,Lt,gn,he,_e,Vt,an,Kt,Vn,Xt,Ln,qt]),Wn=(0,p.useCallback)(async()=>{if(!(!A||!KY(A,gn)||_t.current)){_t.current=!0;try{let e=await Bn(`build`);if(!e)return;await Un(GY,{preserveComposerDraft:!0,targetSession:e})}catch(e){$.error(e instanceof Error?e.message:d5(`errors.sendPrompt`))}finally{_t.current=!1}}},[A,Bn,gn,Un]),Gn=(0,p.useCallback)(e=>{lt.current=!0,I(!0),Wt(),ee(e),P(null),k(null),Kt(null),be(null),at(null)},[Kt,Wt]),Kn=(0,p.useCallback)(async t=>{if(e){pt.current.add(t.id);try{await fN(e,t.id),Yt(t.id,{preserveDraftRoute:!0}),Gn(t.mode)}catch(e){throw pt.current.delete(t.id),e}}},[e,Gn,Yt]),qn=(0,p.useCallback)(async t=>{if(!e||t.length===0||zt!==`opencode`&&zt!==`claude`)return;let n=t.slice(0,h5);if(n.length===0)return;let r=null,i=A;try{if(i||=(ge(!0),r=await Hn({fromStorageKey:Lt}),r?.session??null),!i)return;if((Pt.current[i.id]??[]).length+n.length>h5){$.error(`You can attach up to 4 images per turn.`);return}en(i.id,1);let t=await Eae(e,i.id,n),a=Pt.current[i.id]??[];Qt(i.id,[...a,...t.attachments])}catch(e){if(r&&!Rt.trim())try{await Kn(r.session)}catch{}$.error(e instanceof Error?e.message:d5(`errors.uploadAttachments`))}finally{i&&en(i.id,-1),ge(!1)}},[e,A,Hn,Kn,Rt,Lt,en,Qt,zt]),Jn=(0,p.useCallback)(async t=>{if(!e||!A)return;let n=(Pt.current[A.id]??[]).filter(e=>e.id!==t);try{await Dae(e,A.id,t),Qt(A.id,n),n.length===0&&!Rt.trim()&&(A.messages?.length??0)===0&&await Kn(A)}catch(e){$.error(e instanceof Error?e.message:d5(`errors.removeAttachment`))}},[e,A,Kn,Rt,Qt]),Yn=(0,p.useCallback)(e=>{if(zt!==`opencode`&&zt!==`claude`)return;let t=Array.from(e.clipboardData.items).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>e!==null);t.length!==0&&(e.preventDefault(),qn(t))},[zt,qn]),Xn=(0,p.useCallback)(async e=>{await Un(e)},[Un]),Zn=!!(e&&(F||A&&A.target_available!==!1&&!Ln)),Qn=A?.agent_status===`running`,$n=A?.agent_status===`stopped`,er=Qn&&ye===A?.id,tr=Zn&&!gn&&!Qn&&!M&&!_e&&!he&&!Vt,nr=Zn?A?.target_available===!1?A.target_unavailable_reason??d5(`review.unavailableTarget`):Ln?In??d5(`review.restoreTargetFallback`):gn?qb.t(`common:questionSet.waitForResolution`):Qn?d5(`review.waitTurn`):M?qb.t(`common:postBuildChecks.blockedReason`):Vt?d5(`review.waitUpload`):he||_e?d5(`review.waitPrompt`):null:d5(`review.missingTarget`),rr=(0,p.useCallback)(async()=>{if(!(!e||!A||A.agent_status!==`running`||er)){be(A.id);try{await Oae(e,A.id)}catch(e){be(e=>e===A.id?null:e),$.error(e instanceof Error?e.message:d5(`errors.interruptResponse`))}}},[e,A,er]),ir=(0,p.useCallback)(async()=>{if(!e||xe.length===0||Ce.size>0)return;let t=Array.from(new Set(xe)),n=Te||t.length>1;we(new Set(t));let r=await Promise.allSettled(t.map(async t=>(await fN(e,t),t))),i=[],a=[];for(let[e,n]of r.entries()){if(n.status===`fulfilled`){i.push(n.value);continue}a.push({sessionId:t[e]??``,message:n.reason instanceof Error?n.reason.message:null})}if(i.length>0&&Jt(i),we(new Set),a.length===0){Se([]),n&&(Ee(!1),Oe(new Set),$.success(d5(`toasts.deleteSelectedSuccess`,{count:i.length})));return}let o=a.map(e=>e.sessionId);if(Se(o),n&&Oe(new Set(o)),i.length>0){$.error(d5(`toasts.deleteSelectedPartial`,{count:i.length,deletedCount:i.length,failedCount:a.length}));return}$.error(a[0]?.message??d5(`errors.deleteSession`))},[e,xe,Ce,Te,Jt]),ar=(0,p.useMemo)(()=>E.some(e=>!A5(e)),[E]),or=(0,p.useCallback)((e,t)=>e.agent_status===`running`?`running`:e.agent_status===`stopped`?`interrupted`:!t&&ot.has(e.id)?`finished`:null,[ot]),sr=(0,p.useCallback)((e,n)=>[e.title,ihe(e.mode),Q8(e.tool),t?.memory_enabled&&e.pending_memory_suggestion_count>0?v5(e.pending_memory_suggestion_count):null,n===`running`?d5(`sidebar.running`):n===`interrupted`?d5(`sidebar.interrupted`):n===`finished`?d5(`sidebar.finished`):null].filter(Boolean).join(` `),[t]),cr=(0,p.useCallback)(({session:e,isActive:r,activityState:i})=>{let a=dhe(e),o=c5({session:e,activeProject:t,activeProjectBranchState:n}),s=i===`interrupted`?null:i;return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[o?(0,X.jsx)(`div`,{className:`mb-1 truncate text-[10px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75`,children:o}):null,(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`truncate text-[13px] font-medium leading-5`,children:e.title}),t?.memory_enabled&&e.pending_memory_suggestion_count>0?(0,X.jsx)(Ew,{tone:r?`default`:`muted`,className:`shrink-0`,"aria-label":v5(e.pending_memory_suggestion_count),title:v5(e.pending_memory_suggestion_count),children:e.pending_memory_suggestion_count}):null]}),a?(0,X.jsx)(`div`,{className:Z(`mt-0.5 line-clamp-1 text-xs leading-4`,r?`text-foreground/70`:`text-muted-foreground`),children:a}):null,e.target_available===!1?(0,X.jsx)(`div`,{className:`mt-1 line-clamp-1 text-[11px] leading-4 text-amber-200/90`,children:e.target_unavailable_reason??d5(`sidebar.targetUnavailable`)}):null]}),(0,X.jsx)(ib,{state:s,className:`mt-1`})]})},[t,n]),lr=(0,p.useMemo)(()=>({ariaLabel:d5(`sidebar.ariaLabel`),newSession:d5(`sidebar.newSession`),collapseAriaLabel:d5(`sidebar.collapseAriaLabel`),openAriaLabel:d5(`sidebar.openAriaLabel`),cancelSelection:d5(`sidebar.cancelSelection`),addPreset:d5(`sidebar.addPreset`),deleteSelected:d5(`sidebar.deleteSelected`),selectedCount:e=>d5(`sidebar.selectedCount`,{count:e}),select:d5(`sidebar.select`),loadingSessions:d5(`sidebar.loadingSessions`),noSessions:d5(`sidebar.noSessions`),deleteSessionAriaLabel:d5(`sidebar.deleteSessionAriaLabel`),selectSessionAriaLabel:e=>d5(`sidebar.selectSessionAriaLabel`,{title:e}),selectSessionTitle:e=>d5(`sidebar.selectSessionTitle`,{title:e}),deleteSessionTitle:e=>d5(`sidebar.deleteSessionTitle`,{title:e})}),[]),ur=(0,p.useMemo)(()=>({title:d5(`deleteSessionModal.title`),bulkTitle:d5(`deleteSessionModal.bulkTitle`),description:d5(`deleteSessionModal.description`),bulkDescription:e=>d5(`deleteSessionModal.bulkDescription`,{count:e}),cancel:d5(`deleteSessionModal.cancel`),delete:d5(`deleteSessionModal.delete`),deleting:d5(`deleteSessionModal.deleting`)}),[]),dr=(0,p.useMemo)(()=>(0,X.jsx)(y5,{modifierLabel:En,keys:[m5],ariaHidden:!0}),[En]),fr=(0,p.useMemo)(()=>(0,X.jsx)(ohe,{label:d5(`shortcuts.startNewSession`),modifierLabel:En,keys:[m5]}),[En]),pr=(0,p.useCallback)((e,t)=>{Oe(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]),mr=(0,p.useMemo)(()=>(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(HY,{value:Cn,planInactiveTooltip:(0,X.jsx)(QY,{label:d5(`shortcuts.switchToPlan`)}),buildInactiveTooltip:(0,X.jsx)(QY,{label:d5(`shortcuts.switchToBuild`)}),disabled:ke||gn,onChange:e=>{Bn(e)}}),Qn?(0,X.jsx)(N8,{isInterrupting:er,onStop:()=>{rr()},interruptLabel:d5(`review.interrupt`),interruptingLabel:d5(`review.interrupting`)}):null]}),[Cn,rr,Bn,gn,er,Qn,ke]),hr=(0,p.useMemo)(()=>(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(HY,{value:Cn,planInactiveTooltip:(0,X.jsx)(QY,{label:d5(`shortcuts.switchToPlan`)}),buildInactiveTooltip:(0,X.jsx)(QY,{label:d5(`shortcuts.switchToBuild`)}),disabled:ke||gn,onChange:e=>{Bn(e)}}),A&&KY(A,gn)&&(0,X.jsx)(W8,{disabled:_e||ke,onClick:()=>void Wn()}),F&&t&&(0,X.jsx)(Zy,{activeProject:t,branchState:n,bundles:r,branchSuggestions:i,isBundleLoading:a,isLoading:o,presentation:`composer`,closeAfterSelection:!0,triggerAriaLabel:qb.t(`common:projectTargetSelector.newChatAriaLabel`),onOpenChange:s,onSelectBundle:c,onSelectRepoRoot:l}),Qn&&(0,X.jsx)(N8,{isInterrupting:er,onStop:()=>{rr()},interruptLabel:d5(`review.interrupt`),interruptingLabel:d5(`review.interrupting`)})]}),[t,n,A,Cn,rr,Bn,Wn,gn,F,er,_e,Qn,a,o,ke,c,l,s,i,r]),gr=(0,p.useMemo)(()=>bn?(0,X.jsx)(_Y,{model:ie,variant:G,skills:se,showModelSelector:!0,showSkillsSelector:ne.length>0,availableModels:Ht,availableSkills:ne,selectedModel:Sn,onModelChange:e=>{let t=Ht.find(t=>t.id===e)??null,n=t&&t.variants.includes(G)?G:``;ae(e),oe(n),jn({model:e,variant:n})},onVariantChange:e=>{oe(e),jn({variant:e})},onSkillsChange:e=>{ce(e),jn({skills:e})},modelSelectId:`project-chat-model-selector`,variantSelectId:`project-chat-variant-selector`,skillsSelectId:`project-chat-skills-selector`,disabled:_e||he||A?.agent_status===`running`}):xn?(0,X.jsx)(gY,{dataTestId:`chat-model-selector-skeleton`}):null,[A?.agent_status,Ht,ne,he,_e,jn,Sn,ie,se,G,bn,xn]);(0,p.useEffect)(()=>{if(S)return()=>{S(null)}},[S]),(0,p.useEffect)(()=>{if(S){if(!e||!Zn){S(null);return}S({chatSessionId:A?.id??null,canSubmitReviewPrompt:tr,reviewSubmitDisabledReason:nr,mode:Cn,onModeChange:async e=>{await Bn(e)},isUpdatingMode:ke,promptPlaceholder:_5(Cn),promptComposerControls:mr,promptComposerInlineControls:gr,submitPrompt:Xn})}},[e,A,tr,Cn,Bn,Xn,Zn,ke,S,mr,gr,nr]);let _r=async()=>{if(!(!Rt.trim()&&Bt.length===0||Vt||gn||M))try{if(!await Un(Rt))return}catch(e){$.error(e instanceof Error?e.message:d5(`errors.sendPrompt`))}},vr=e=>{e.key!==`Enter`||e.shiftKey||A?.agent_status===`running`||M||he||_e||Vt||gn||(e.preventDefault(),_r())};(0,p.useEffect)(()=>{let t=t=>{if(ahe(t)){if(!e||he||_e)return;t.preventDefault(),Mn(),zn();return}YY(t)&&(!e||!F&&!A||(t.preventDefault(),Bn(JY(Cn))))};return window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`keydown`,t)}},[e,A,Cn,zn,Mn,Bn,he,F,_e]);let yr=(0,p.useCallback)(async t=>{if(!(!e||!A)){Pe(t);try{let n=await jae(e,A.id,t);Kt(n.chatSession),qt(n.chatSession),$.success(d5(`ticketProposal.createdFromChat`,{count:n.created_tickets.length}))}catch(e){$.error(e instanceof Error?e.message:d5(`errors.createTickets`))}finally{Pe(e=>e===t?null:e)}}},[e,A,Kt,qt]),br=(0,p.useCallback)(e=>e.ticket_proposals?(0,X.jsx)(hhe,{proposals:e.ticket_proposals,isApplying:Ne===e.id,onApply:()=>{yr(e.id)}}):null,[Ne,yr]),xr=(0,p.useCallback)(e=>{if(!vt.current)return;let t=vt.current.getBoundingClientRect().width,n=g5(e,t);Ot.current=n,bt.current&&(bt.current.style.setProperty(`--chat-changes-panel-width`,`${n}px`),bt.current.setAttribute(`data-desktop-width`,String(n)))},[]),Sr=(0,p.useCallback)(()=>{Ct.current?.(),Ct.current=null},[]),Cr=(0,p.useCallback)(e=>{let t=xt.current,n=St.current,r=wt.current;if(t!==null){if(xt.current=null,St.current=null,wt.current=!1,Y(!1),$e(!1),Sr(),e!==null&&typeof yt.current?.hasPointerCapture==`function`&&yt.current.hasPointerCapture(e)&&typeof yt.current.releasePointerCapture==`function`&&yt.current.releasePointerCapture(e),n===`collapsed`){if(!r)return;tt(Ot.current),Xe(!0);return}tt(Ot.current)}},[Sr]),wr=(0,p.useCallback)((e,t)=>{if(xt.current!==e)return;let n=t-Et.current,r=Dt.current-n;if(St.current===`collapsed`){if(!wt.current&&r<ehe)return;wt.current||(wt.current=!0,Tt.current=!0,$e(!0),Y(!0))}xr(r)},[xr]),Tr=(0,p.useCallback)((e,t)=>{if(xt.current===e){if(t!==null&&(St.current===`inline`||wt.current)){let e=t-Et.current;xr(Dt.current-e)}Cr(e)}},[Cr,xr]),Er=(0,p.useCallback)(e=>{if(!w)return;e.preventDefault(),xt.current=e.pointerId,St.current=Je?`inline`:`collapsed`,wt.current=!1,Tt.current=!1,Et.current=e.clientX,Dt.current=Je?Ot.current:0,Y(Je),Sr(),typeof e.currentTarget.setPointerCapture==`function`&&e.currentTarget.setPointerCapture(e.pointerId);let t=e=>{wr(e.pointerId,e.clientX)},n=e=>{Tr(e.pointerId,e.clientX)},r=e=>{Tr(e.pointerId,e.clientX)};window.addEventListener(`pointermove`,t),window.addEventListener(`pointerup`,n),window.addEventListener(`pointercancel`,r),Ct.current=()=>{window.removeEventListener(`pointermove`,t),window.removeEventListener(`pointerup`,n),window.removeEventListener(`pointercancel`,r)}},[Tr,wr,Je,w,Sr]),Dr=(0,p.useCallback)(e=>{wr(e.pointerId,e.clientX)},[wr]),Or=(0,p.useCallback)(e=>{Tr(e.pointerId,e.clientX)},[Tr]),kr=(0,p.useCallback)(e=>{Tr(e.pointerId,e.clientX)},[Tr]),jr=(0,p.useCallback)(e=>{xt.current===e.pointerId&&Cr(e.pointerId)},[Cr]),Mr=(0,p.useCallback)(()=>{if(Tt.current){Tt.current=!1;return}Xe(!0)},[]),Nr=(0,p.useCallback)(()=>{Xe(!1)},[]),Pr=(0,p.useCallback)(e=>{e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),Mr())},[Mr]);(0,p.useEffect)(()=>{w||(xt.current=null,St.current=null,wt.current=!1,Tt.current=!1,Y(!1),$e(!1),Sr())},[w,Sr]),(0,p.useEffect)(()=>()=>{Sr()},[Sr]);let Fr=!!O,Ir=A?.target_available===!1,Lr=Ir?A?.target_unavailable_reason??d5(`review.unavailableTarget`):null,Rr=F||!!(A&&A.target_available!==!1&&!Ln),zr=!!(t?.memory_enabled&&A&&(Le.length>0||Re)),Br=w&&(F||Fr)&&!Ir&&!Ln,Vr=Br&&!Je&&!Qe,Hr=Br&&(Je||Qe),Ur=`${An??`none`}:${Br?`changes-enabled`:`changes-disabled`}:${Hr?`panel-visible`:`panel-hidden`}`,Wr=(0,p.useCallback)(e=>{dt.current=null,Xt(Lt,e)},[Lt,Xt]),Gr=A||F?(0,X.jsx)(X.Fragment,{children:(0,X.jsx)(U8,{projectId:e,agentRunParentType:A?`chat`:null,agentRunParentId:A?.id??null,messages:A?mn:[],internalLog:A?.agent_log??null,currentThinkingMessageId:A?.agent_message_id??null,previousThinkingLog:A?.previous_agent_log??null,previousThinkingMessageId:A?.previous_agent_message_id??null,pendingAgentTitle:pn,streamingResponse:A?.streaming_response??null,isRunning:A?.agent_status===`running`,isLoading:!F&&pe,canShowComposer:Rr,cardClassName:`border-t-0`,isExternallyResizing:C||Ze,pendingAgentRevealKey:yn,pendingAgentRevealDelayMs:rhe,liveResponseTiming:it,composerFocusNonce:nt,header:(0,X.jsx)(G8,{title:wn,tool:F?null:A?.tool??null,modelLabel:kn,interrupted:$n,interruptedLabel:d5(`sidebar.interrupted`),usage:{totalTokens:A?.usage_snapshot_total_tokens??null,contextWindow:A?.usage_snapshot_context_window??null,cost:A?.usage_snapshot_cost??null,tool:Tn,model:Dn,availableModels:Ht},metadataExtra:(0,X.jsxs)(X.Fragment,{children:[A?.external_source?(0,X.jsx)(IF,{externalSource:A.external_source}):null,A?.origin_spec_session_id&&A.origin_spec_snapshot_id&&y?(0,X.jsx)(Q,{type:`button`,size:`xs`,variant:`ghost`,className:`h-6 px-2 text-[11px] text-violet-200 hover:text-violet-100`,onClick:()=>{y(A.origin_spec_session_id,A.origin_spec_snapshot_id)},children:qb.t(`common:specView.provenance.viewSourceSpec`)}):null]}),actions:A&&e?(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[zr&&(0,X.jsx)(Q,{type:`button`,size:`xs`,variant:`outline`,className:`gap-2`,onClick:()=>Ve(!0),children:Re?d5(`composer.loadingMemory`):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{children:d5(`composer.memorySuggestions`)}),(0,X.jsx)(Ew,{children:Le.length})]})}),(0,X.jsx)(V4,{projectId:e,scope:{type:`chat`,id:A.id},size:`xs`,onNavigateToLifecycleSource:b})]}):null,warnings:Ln&&In?(0,X.jsx)(`div`,{className:`w-fit max-w-md rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-50`,children:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{children:In}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`secondary`,onClick:()=>{Pn()},children:d5(`composer.switchBack`)}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`ghost`,onClick:Mn,children:d5(`composer.startNewSession`)})]})]})}):Ir&&Lr?(0,X.jsx)(`div`,{className:`w-fit max-w-md rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-50`,children:Lr}):null}),composerControls:hr,composerInlineControls:gr,composerTheme:Cn,layoutKey:An,scrollLayoutKey:Ur,followUpPrompt:Rt,draftAttachments:Bt,followUpPlaceholder:_5(Cn),emptyStateText:null,renderMessageFooter:br,renderMessageBody:vn,isSendingFollowUp:_e||he,isComposerSubmitDisabled:gn||M,postBuildCheck:A?.post_build_check,isUploadingAttachments:Vt,canAttachImages:On,followUpDisabledReason:Ir?Lr??void 0:A?.agent_status===`running`?d5(`review.waitTurnShort`):M?qb.t(`common:postBuildChecks.blockedReason`):Vt?d5(`review.waitUpload`):gn?qb.t(`common:questionSet.waitForResolution`):void 0,onFollowUpPromptChange:Wr,onFollowUpKeyDown:vr,onFollowUpPaste:Yn,onUploadAttachments:e=>{qn(e)},onRemoveAttachment:e=>{Jn(e)},onFollowUpSubmit:()=>{_r()}})}):Fr?(0,X.jsx)(k8,{label:d5(`composer.loadingSession`)}):!de||le?(0,X.jsx)(A8,{label:d5(`sidebar.loadingSessions`)}):(0,X.jsx)(j8,{title:d5(`composer.noSessionSelectedTitle`),description:d5(`composer.noSessionSelectedDescription`),startNewSessionLabel:d5(`composer.startNewSession`),onStartNewSession:Mn,canStartNewSession:!!e&&!he&&!_e}),Kr=Br?(0,X.jsx)(`div`,{ref:yt,"aria-label":d5(Vr?`composer.openDiff`:`composer.resizeDiffPanel`),"aria-orientation":Vr?void 0:`vertical`,className:Z(Vr?`group flex h-8 w-full shrink-0 touch-none select-none items-center justify-center border-t border-border/70 bg-background/90 text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground xl:h-auto xl:w-7 xl:cursor-col-resize xl:border-l xl:border-t-0`:`group hidden w-5 shrink-0 cursor-col-resize touch-none select-none items-center justify-center border-l border-border/70 bg-background/80 transition-colors xl:flex`,Ze&&!Vr&&`bg-background`),"data-testid":Vr?`collapsed-changes-rail`:void 0,onLostPointerCapture:jr,onPointerCancel:kr,onPointerDown:Er,onPointerMove:Dr,onPointerUp:Or,onClick:Vr?Mr:void 0,onKeyDown:Vr?Pr:void 0,role:Vr?`button`:`separator`,tabIndex:Vr?0:void 0,children:Vr?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`hidden h-full w-full items-center justify-center xl:flex`,children:(0,X.jsxs)(`span`,{className:`relative flex h-full w-full items-center justify-center`,children:[(0,X.jsx)(`span`,{className:`absolute top-1/2 left-1/2 flex -translate-x-1/2 -translate-y-[2.65rem] items-center justify-center text-sky-400/80 transition-colors group-hover:text-sky-300`,children:(0,X.jsx)(Ev,{className:`h-3 w-3 shrink-0`})}),(0,X.jsx)(`span`,{className:`absolute top-1/2 left-1/2 h-14 w-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-muted-foreground/70 transition-colors group-hover:bg-sky-300/90`})]})}),(0,X.jsxs)(`span`,{className:`flex items-center gap-2 text-xs font-medium xl:hidden`,children:[(0,X.jsx)(Ev,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{children:d5(`composer.diff`)})]})]}):(0,X.jsx)(`div`,{className:Z(`h-14 w-1.5 rounded-full transition-colors`,Ze?`bg-sky-300/90`:`bg-muted-foreground/70 group-hover:bg-sky-300/90`)})}):null,qr=Be&&e&&t?.memory_enabled?(0,X.jsx)(tC,{onClose:()=>Ve(!1),overlayClassName:`bg-background/75 p-4`,panelClassName:`w-full max-w-3xl`,renderContent:({closeButton:t})=>(0,X.jsxs)(iC,{size:`sm`,className:`max-h-[calc(100vh-2rem)] w-full gap-0 overflow-hidden border-border/80 bg-card/95 shadow-2xl`,children:[(0,X.jsxs)(aC,{className:`border-b border-border/80 pb-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(oC,{children:d5(`composer.memorySuggestionsTitle`)}),(0,X.jsx)(sC,{children:d5(`composer.memorySuggestionsDescription`)})]}),(0,X.jsx)(cC,{children:t})]}),(0,X.jsx)(lC,{className:`min-h-0 flex-1 overflow-y-auto pt-4`,children:(0,X.jsx)(K8,{projectId:e,suggestions:Le,emptyState:d5(`composer.memorySuggestionsEmpty`),onSuggestionsChanged:sn})})]}),closeButtonLabel:d5(`composer.closeMemorySuggestions`)}):null,Jr=dn.length>0?(0,X.jsx)(O8,{count:dn.length,title:fn,isDeleting:Ce.size>0,onConfirm:()=>{ir()},onCancel:()=>{Ce.size>0||Se([])},labels:ur}):null;return(0,X.jsxs)(`div`,{"data-testid":`chat-view-shell`,className:`relative flex min-h-0 flex-1 overflow-hidden border-t border-border/70`,children:[(0,X.jsx)(M8,{sessions:E,sessionGroups:ln,activeSessionId:O,isDraftOpen:F,isLoadingSessions:le,isOpen:J,onToggleOpen:()=>{qe(e=>!e)},testId:`chat-sessions-sidebar`,railTestId:`chat-sessions-rail`,onDraftOpen:Mn,isCreatingSession:he||!e,isSendingPrompt:_e,newSessionShortcutHint:dr,newSessionTooltip:fr,isSelectionMode:Te,selectedSessionIds:De,selectedSessionCount:De.size,hasDeletableSessions:ar,deletingSessionIds:Ce,onEnterSelectionMode:()=>{Ee(!0),Oe(new Set)},onExitSelectionMode:()=>{Ee(!1),Oe(new Set)},onToggleSessionSelection:e=>{Oe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},onSetSessionSelection:pr,onConfirmDeleteSelectedSessions:()=>{Se(Array.from(De))},selectionPresets:un,onSessionSelect:e=>{Rn(e)},onConfirmDeleteSession:e=>{Se([e])},getSessionId:e=>e.id,getSessionTitle:e=>e.title,getDeleteDisabledReason:A5,getActivityState:or,getRowAriaLabel:sr,renderRowContent:cr,labels:lr}),(0,X.jsxs)(`div`,{ref:vt,className:`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden xl:flex-row`,children:[(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:Gr}),Br?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(vv,{content:d5(`composer.openDiff`),disabled:!Vr,side:`left`,children:Kr}),Hr?(0,X.jsx)(H8,{projectId:e,chatSessionId:F?null:O,canSubmitReviewPrompt:tr,reviewSubmitDisabledReason:nr,onSubmitReviewPrompt:Xn,state:Ue,onStateChange:We,isResizing:Ze,onClose:Nr,desktopWidth:et,panelElementRef:bt}):null]}):null]}),qr,Jr]})},_he=({className:e})=>(0,X.jsx)(Ag,{"aria-hidden":`true`,className:e}),vhe=({activeProject:e,onNavigateToSource:t})=>{let{t:n}=q(`projects`);return e?(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-6 py-6`,children:(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-7xl flex-col gap-5`,children:[(0,X.jsx)(`div`,{className:`border-b border-border/60 pb-4`,children:(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`p`,{className:`text-[10px] font-semibold uppercase tracking-[0.24em] text-muted-foreground`,children:n(`memory.workspace.title`)}),(0,X.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:e.name})]})}),(0,X.jsx)(FT,{mode:`edit`,projectId:e.id,memoryEnabled:e.memory_enabled,persistedMemoryEnabled:e.memory_enabled,onMemoryEnabledChange:()=>{},showActivationControls:!1,archiveLayout:!0,onNavigateToSource:t})]})}):(0,X.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-sm text-muted-foreground`,children:n(`memory.workspace.selectProject`)})},yhe=(e,t,n,r)=>Y(J(`/projects/${e}/spec-sessions/${t}/snapshots/${n}/review`),{method:`POST`,body:r,fallbackErrorMessage:`Unable to start the spec review right now.`}),bhe=(e,t,n)=>Y(J(`/projects/${e}/spec-sessions/${t}/snapshots/${n}/review/stop`),{method:`POST`,fallbackErrorMessage:`Unable to stop the spec review right now.`}),j5=(e,t,n,r)=>Y(J(`/projects/${e}/spec-sessions/${t}/snapshots/${n}/review`),{signal:r,fallbackErrorMessage:`Unable to load the spec review right now.`}),xhe=(e,t,n,r)=>Y(J(`/projects/${e}/spec-sessions/${t}/snapshots/${n}/review-runs/${r}/revision-draft`),{method:`POST`,fallbackErrorMessage:`Unable to build the revision draft right now.`}),She=(e,t)=>!!t&&e===t,Che=({suggestion:e,isRecommended:t,recommendedLabel:n,onPick:r})=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{r(e.value)},className:Z(`inline-flex min-w-0 items-center gap-1.5 rounded-full border px-3 py-1.5 text-left text-xs font-medium transition-colors`,t?`border-amber-500/40 bg-amber-500/15 text-amber-200 hover:bg-amber-500/25 hover:text-amber-100`:`border-border/70 bg-background/70 text-foreground hover:border-border hover:bg-background`),children:[(0,X.jsx)(`span`,{className:`truncate`,children:e.label}),t?(0,X.jsx)(`span`,{className:`shrink-0 rounded-full bg-amber-500/30 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-amber-100`,children:n}):null]}),whe=({question:e,labels:t})=>(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm font-medium leading-relaxed text-foreground`,children:e.question}),e.rationale?(0,X.jsxs)(`p`,{className:`whitespace-pre-wrap break-words text-xs leading-relaxed text-muted-foreground`,children:[(0,X.jsxs)(`span`,{className:`font-semibold`,children:[t.rationaleLabel,`: `]}),e.rationale]}):null]}),M5=({question:e,isActive:t,isDisabled:n=!1,onSubmitAnswer:r,labels:i})=>{let[a,o]=(0,p.useState)(``),s=(0,p.useRef)(null);if((0,p.useEffect)(()=>{t&&o(``)},[e.question,t]),(0,p.useEffect)(()=>{s.current&&kD(s.current)},[a]),!t)return(0,X.jsx)(whe,{question:e,labels:i});let c=a.trim().length>0&&!n,l=e.suggestions.find(e=>e.recommended)?.id,u=e=>{o(e),requestAnimationFrame(()=>{s.current?.focus();let e=s.current;e&&e.setSelectionRange(e.value.length,e.value.length)})},d=()=>{let e=a.trim();!e||n||(r(e),o(``))};return(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(db,{className:`mt-0.5 h-4 w-4 flex-shrink-0 text-amber-300`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm font-medium leading-relaxed text-foreground`,children:e.question}),e.rationale?(0,X.jsxs)(`p`,{className:`mt-1 whitespace-pre-wrap break-words text-xs leading-relaxed text-muted-foreground`,children:[(0,X.jsxs)(`span`,{className:`font-semibold`,children:[i.rationaleLabel,`: `]}),e.rationale]}):null]})]}),e.suggestions.length>0?(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:i.suggestionsLabel}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.suggestions.map(e=>(0,X.jsx)(Che,{suggestion:e,isRecommended:She(e.id,l),recommendedLabel:i.recommendedSuggestionLabel,onPick:u},e.id))})]}):null,(0,X.jsx)(Y_,{ref:s,value:a,placeholder:i.answerPlaceholder,disabled:n,onChange:e=>{o(e.target.value)},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),d())}}),(0,X.jsx)(`div`,{className:`flex justify-end`,children:(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`secondary`,disabled:!c,onClick:d,children:n?i.submittingLabel:i.submitLabel})})]})},The=({className:e})=>(0,X.jsx)(fg,{"aria-hidden":`true`,className:e}),Ehe=[`h-10 w-10 px-0`,`border-amber-400/60 bg-amber-500/30 text-amber-100 shadow-[0_8px_24px_rgba(245,158,11,0.24)]`,`hover:bg-amber-500/45 hover:text-white hover:border-amber-300`,`focus-visible:border-ring/70 focus-visible:ring-2 focus-visible:ring-ring/20`].join(` `),Dhe=[`h-10 w-10 px-0 shadow-none`,`border-border/70 bg-transparent text-muted-foreground`,`hover:border-border hover:bg-background/60 hover:text-foreground`,`focus-visible:border-ring/70 focus-visible:ring-2 focus-visible:ring-ring/20`,`disabled:border-border/40 disabled:bg-transparent disabled:text-muted-foreground/50`].join(` `),N5=({on:e,disabled:t=!1,onToggle:n,tooltipContent:r,ariaLabelOn:i,ariaLabelOff:a,className:o})=>(0,X.jsx)(vv,{content:r,children:(0,X.jsx)(`span`,{className:`inline-flex`,children:(0,X.jsx)(Q,{type:`button`,size:`icon`,variant:e?`warning`:`ghost`,"aria-pressed":e,"aria-label":e?i:a,disabled:t,className:Z(e?Ehe:Dhe,o),onClick:()=>{t||n(!e)},children:(0,X.jsx)(The,{className:`h-5 w-5`})})})}),Ohe=({projectId:e,specSessionId:t,messages:n,internalLog:r,currentThinkingMessageId:i=null,previousThinkingLog:a=null,previousThinkingMessageId:o=null,pendingAgentTitle:s,streamingResponse:c,isRunning:l,isLoading:u=!1,canShowComposer:d,cardClassName:f,isExternallyResizing:p=!1,pendingAgentRevealKey:m=null,pendingAgentRevealDelayMs:h=0,liveResponseTiming:g=null,composerFocusNonce:_=0,blurComposerOnSendStart:v=!1,hidePendingAgentTitle:y=!1,forceScrollToBottomKey:b,header:x,composerControls:S,composerInlineControls:C,composerTheme:w=`default`,layoutKey:T,scrollLayoutKey:E,followUpPrompt:D,draftAttachments:O=[],followUpPlaceholder:k,emptyStateText:A=null,renderMessageFooter:j,renderMessageBody:M,isSendingFollowUp:N,isComposerSubmitDisabled:P=!1,isUploadingAttachments:F=!1,canAttachImages:I=!1,followUpDisabledReason:L,onFollowUpPromptChange:R,onFollowUpKeyDown:z,onFollowUpPaste:ee,onUploadAttachments:B,onRemoveAttachment:V,onFollowUpSubmit:H})=>(0,X.jsx)(BJ,{projectId:e,agentRunParentType:t?`spec`:null,agentRunParentId:t,messages:n,internalLog:r,currentThinkingMessageId:i,previousThinkingLog:a,previousThinkingMessageId:o,pendingAgentTitle:s,streamingResponse:c,isRunning:l||!!(N&&g),isLoading:u,autoScrollBehavior:`sticky`,surfaceVariant:`chat`,canShowComposer:d,cardClassName:f,header:x,composerControls:S,composerInlineControls:C,composerTheme:w,composerSize:`compact-on-laptop`,showThinkingPlacement:`header`,pinComposerToBottom:!0,isExternallyResizing:p,pendingAgentRevealKey:m,pendingAgentRevealDelayMs:h,liveResponseTiming:g,composerFocusNonce:_,blurComposerOnSendStart:v,forceScrollToBottomKey:b,layoutKey:T,scrollLayoutKey:E,followUpPrompt:D,draftAttachments:O,followUpPlaceholder:k,emptyStateText:A,autoFocusComposer:!0,renderMessageFooter:j,renderMessageBody:M,isSendingFollowUp:N,isComposerSubmitDisabled:P,isUploadingAttachments:F,canAttachImages:I,followUpDisabledReason:L,hidePendingAgentTitle:y,onFollowUpPromptChange:R,onFollowUpKeyDown:z,onFollowUpPaste:ee,onUploadAttachments:B,onRemoveAttachment:V,onFollowUpSubmit:H}),P5=e=>{let t={...e};return delete t.messages,t.agent_log=null,t.agent_message_id=null,t.previous_agent_log=null,t.previous_agent_message_id=null,t.streaming_response=null,t},F5=new Set([`deterministic`,`structural_heuristic`,`historical_heuristic`]),I5=e=>typeof e==`object`&&!!e&&!Array.isArray(e),khe=e=>I5(e)&&typeof e.seed_path==`string`&&typeof e.candidate_path==`string`&&F5.has(e.evidence_class)&&typeof e.depth==`number`&&Array.isArray(e.edge_ids),L5=e=>I5(e)&&typeof e.path==`string`&&typeof e.is_test==`boolean`&&F5.has(e.evidence_class)&&Array.isArray(e.chains)&&e.chains.length>0&&e.chains.every(khe),Ahe=e=>!I5(e)||e.version!==1||![`complete`,`stale`,`truncated`,`unavailable`].includes(e.capture_state)||!Array.isArray(e.affected_files)||!Array.isArray(e.affected_tests)||!e.affected_files.every(L5)||!e.affected_tests.every(L5)?null:e,jhe=e=>!!(e.likely_files.some(e=>e.origin!==`graph`)||e.file_relation_graph),R5=({evidenceClass:e})=>{let{t}=q(`common`);return(0,X.jsx)(rC,{variant:`outline`,className:`shrink-0 px-1.5 py-0 text-[10px] ${e===`deterministic`?`border-emerald-400/30 bg-emerald-500/10 text-emerald-200`:e===`structural_heuristic`?`border-amber-400/30 bg-amber-500/10 text-amber-200`:`border-sky-400/30 bg-sky-500/10 text-sky-200`}`,children:t(`specView.artifactPanel.repositoryEvidence.class.${e}`)})},Mhe=({candidate:e})=>{let{t}=q(`common`),n=e.chains.slice(0,2);return(0,X.jsxs)(`details`,{className:`group mt-2 border-t border-border/40 pt-2`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer list-none rounded-sm text-xs font-medium text-violet-300 outline-none hover:text-violet-200 focus-visible:ring-2 focus-visible:ring-ring/60 [&::-webkit-details-marker]:hidden`,children:t(`specView.artifactPanel.repositoryEvidence.showChains`,{count:n.length})}),(0,X.jsx)(`ol`,{className:`mt-2 space-y-2`,children:n.map((e,n)=>(0,X.jsxs)(`li`,{className:`min-w-0 rounded-md bg-background/35 px-2.5 py-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`text-[11px] font-medium text-foreground`,children:t(`specView.artifactPanel.repositoryEvidence.chainLabel`,{number:n+1})}),(0,X.jsx)(R5,{evidenceClass:e.evidence_class})]}),(0,X.jsx)(`p`,{className:`mt-1 break-words text-xs leading-relaxed text-muted-foreground`,children:t(`specView.artifactPanel.repositoryEvidence.chainSummary`,{seed:e.seed_path,candidate:e.candidate_path,count:e.depth})})]},`${e.seed_path}:${e.candidate_path}:${e.edge_ids.join(`:`)}`))})]})},Nhe=({row:e,affectedTest:t=!1})=>{let{t:n}=q(`common`);return(0,X.jsxs)(`li`,{className:`min-w-0 overflow-hidden rounded-md border border-border/50 bg-surface-hover px-3 py-2.5`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[(0,X.jsx)(`code`,{className:`min-w-0 break-all text-xs font-medium text-foreground`,children:e.path}),e.isNew&&(0,X.jsx)(rC,{variant:`success`,className:`shrink-0 px-1.5 py-0 text-[10px]`,children:n(`specView.artifactPanel.newFile`)})]}),(0,X.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,X.jsx)(`span`,{children:n(`specView.artifactPanel.repositoryEvidence.origin.${e.origin}`)}),t&&(0,X.jsx)(rC,{variant:`outline`,className:`px-1.5 py-0 text-[10px] text-violet-200`,children:n(`specView.artifactPanel.repositoryEvidence.affectedTest`)}),e.candidate&&(0,X.jsx)(R5,{evidenceClass:e.candidate.evidence_class})]}),e.reason&&(0,X.jsx)(`p`,{className:`mt-1 break-words text-xs leading-relaxed text-muted-foreground`,children:e.reason}),e.candidate&&(0,X.jsx)(Mhe,{candidate:e.candidate})]})},z5=e=>e.replace(/\\/g,`/`),Phe=({snapshot:e,onMermaidClick:t})=>{let{t:n}=q(`common`);Ahe(e.repository_evidence);let r=[],i=[],a=new Map(i.map(e=>[z5(e.path),e])),o=e.likely_files.filter(e=>e.origin!==`graph`),s=new Map(o.map(e=>[e.normalized_path??z5(e.path),e])),c=o.flatMap(e=>{let t=e.normalized_path??z5(e.path);return a.has(t)?[]:[{path:e.path,reason:e.reason||null,isNew:e.is_new,origin:e.origin??`planner`,candidate:null}]}),l=r.map(e=>{let t=s.get(z5(e.path));return{path:t?.path??e.path,reason:null,isNew:!1,origin:t?`both`:`graph`,candidate:e}}),u=new Set(r.map(e=>z5(e.path)));for(let t of e.likely_files.filter(e=>e.origin===`graph`)){let e=t.normalized_path??z5(t.path);u.has(e)||l.push({path:t.path,reason:t.reason||null,isNew:t.is_new,origin:`graph`,candidate:null})}return i.map(e=>{let t=s.get(z5(e.path));return{path:t?.path??e.path,reason:t?.reason??null,isNew:t?.is_new??!1,origin:t?`both`:`graph`,candidate:e}}),(0,X.jsxs)(`section`,{children:[c.length>0&&(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:c.map(e=>(0,X.jsx)(Nhe,{row:e},`${e.origin}:${e.path}`))}),!1,e.file_relation_graph&&(0,X.jsxs)(`section`,{className:`mt-4`,"aria-labelledby":`spec-file-relation-heading`,children:[(0,X.jsx)(`h3`,{id:`spec-file-relation-heading`,className:`text-xs font-semibold text-foreground`,children:n(`specView.artifactPanel.fileRelationGraph`)}),(0,X.jsx)(`p`,{className:`mb-2 mt-1 text-xs leading-relaxed text-muted-foreground`,children:n(`specView.artifactPanel.repositoryEvidence.diagramDescription`)}),(0,X.jsx)(`div`,{className:`overflow-auto rounded-md border border-border/50 bg-surface-hover p-3`,children:(0,X.jsx)(WW,{mermaid:e.file_relation_graph,onClick:()=>{t(e.file_relation_graph)}})})]})]})},B5=({className:e})=>(0,X.jsx)(Hg,{"aria-hidden":`true`,className:e}),Fhe=({className:e})=>(0,X.jsx)(Jh,{"aria-hidden":`true`,className:e}),V5=({className:e})=>(0,X.jsx)(ag,{"aria-hidden":`true`,className:e}),H5=({heading:e,open:t,onOpenChange:n,children:r})=>(0,X.jsxs)(SC,{open:t,onOpenChange:n,children:[(0,X.jsx)(CC,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-1.5 text-xs font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground transition-colors mb-2`,children:[(0,X.jsx)(bv,{className:`h-3 w-3 shrink-0 transition-transform ${t?``:`-rotate-90`}`}),e]})}),(0,X.jsx)(wC,{children:r})]}),Ihe=({actions:e})=>{let{t}=q(`common`);return e.hasExistingTicketsFromSnapshot?(0,X.jsxs)(`p`,{className:`flex w-full items-center justify-center gap-1.5 rounded-md px-3 py-1.5 text-sm font-medium text-muted-foreground`,children:[(0,X.jsx)(fb,{className:`h-3.5 w-3.5 text-emerald-400`}),t(`specView.actions.ticketsCreated`)]}):(0,X.jsxs)(Q,{type:`button`,size:`sm`,onClick:e.onCreateTickets,disabled:!!e.unavailableReason||e.isCreatingTickets||e.isImplementingInChat||e.isExporting,title:e.unavailableReason??void 0,className:`w-full justify-center gap-1.5 border-violet-300/70 bg-violet-500/15 text-violet-100 hover:bg-violet-500/25`,children:[(0,X.jsx)(B5,{className:`h-3.5 w-3.5`}),e.isCreatingTickets?t(`specView.actions.creatingTickets`):t(`specView.actions.createTickets`)]})},U5=({ticket:e})=>(0,X.jsxs)(`div`,{className:`min-w-0 rounded-md border border-border/50 bg-surface-hover px-3 py-2`,children:[(0,X.jsx)(`div`,{className:`break-words text-xs font-medium text-foreground`,children:e.title}),e.key&&(0,X.jsx)(`div`,{className:`mt-0.5 break-all text-xs text-violet-400`,children:e.key})]}),Lhe=({snapshot:e})=>{let{t}=q(`common`),n=new Map(e.tickets.map(e=>[e.key,e]));return(0,X.jsx)(`section`,{className:`space-y-2.5`,children:e.bundle_groups.map(e=>{let r=e.ticket_keys.map(e=>n.get(e)).filter(e=>e!==void 0);return(0,X.jsxs)(`article`,{className:`min-w-0 rounded-md border border-border/50 bg-surface px-3 py-2.5`,children:[(0,X.jsx)(`h4`,{className:`break-all text-sm font-semibold text-foreground`,children:e.name}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:t(`specView.artifactPanel.proposedTicketCount`,{count:r.length})}),r.length>0&&(0,X.jsx)(`ul`,{className:`mt-2 space-y-1.5`,children:r.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(U5,{ticket:e})},e.key))})]},e.key)})})},W5={high:0,medium:1,low:2},Rhe=e=>[...e].sort((e,t)=>{let n=W5[e.severity]??99,r=W5[t.severity]??99;return n===r?e.ordinal-t.ordinal:n-r}),zhe=e=>{let t={high:0,medium:0,low:0};for(let n of e)t[n.severity]+=1;return t},Bhe=({run:e})=>{let{t}=q(`common`),n=e.agent_status,r=t(`specView.review.status.${n}`,{defaultValue:n});return(0,X.jsx)(`span`,{className:`text-xs font-medium ${n===`running`?`text-violet-300`:n===`completed`?`text-emerald-300`:n===`error`||n===`parse_failed`?`text-rose-300`:`text-amber-300`}`,children:r})},Vhe=({review:e})=>{let{t}=q(`common`),[n,r]=(0,p.useState)(!0),i=e.review?.run??null,a=e.review?.findings??[],o=Rhe(a),s=zhe(a),c=e.isRunning||i?.agent_status===`running`,l=c,u=!!i&&!c&&i?.agent_status===`completed`&&a.length>0,d=i?.agent_status===`completed`?`specView.review.noFindings`:i?.agent_status===`stopped`?`specView.review.stoppedExplanation`:i?.agent_status===`error`?`specView.review.errorExplanation`:i?.agent_status===`parse_failed`?`specView.review.parseFailedExplanation`:null,f=(0,p.useMemo)(()=>new Map(e.availableModels.map(e=>[e.id,e.label])),[e.availableModels]),m=i?.model?e5({availableModelsById:f,model:i.model})??i.model:null,h=i?[m,t(`specView.review.findingsCount`,{count:a.length}),s.high>0?`${s.high} ${t(`specView.review.severity.high`)}`:null,s.medium>0?`${s.medium} ${t(`specView.review.severity.medium`)}`:null,s.low>0?`${s.low} ${t(`specView.review.severity.low`)}`:null].filter(Boolean).join(` · `):null;return(0,X.jsx)(H5,{heading:(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(V5,{className:`h-3.5 w-3.5`}),t(`specView.review.heading`)]}),open:n,onOpenChange:r,children:(0,X.jsxs)(`section`,{className:`rounded-md border border-border/50 bg-surface-hover px-3 py-3`,children:[i&&(0,X.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground`,children:[(0,X.jsx)(Bhe,{run:i}),c&&(0,X.jsx)(`span`,{className:`inline-flex items-center gap-1 text-violet-300`,"aria-hidden":`true`,children:(0,X.jsx)(`span`,{className:`h-3 w-3 animate-spin rounded-full border-2 border-violet-400 border-t-transparent`})}),h&&(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:h})]}),e.isLoading&&!i&&(0,X.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:t(`specView.review.loading`)}),o.length>0?(0,X.jsx)(`ul`,{className:`space-y-2`,children:o.map(e=>(0,X.jsxs)(`li`,{className:`rounded-md border border-border/40 bg-surface px-2.5 py-2`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`text-[0.65rem] font-bold uppercase tracking-wide ${e.severity===`high`?`text-rose-300`:e.severity===`medium`?`text-amber-300`:`text-sky-300`}`,children:e.severity}),(0,X.jsx)(`span`,{className:`min-w-0 break-words text-xs font-medium text-foreground`,children:e.title})]}),(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-foreground`,children:e.what_text}),e.why_text&&(0,X.jsxs)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:[(0,X.jsxs)(`span`,{className:`font-medium`,children:[t(`specView.review.why`),`:`]}),` `,e.why_text]}),e.suggestion_text&&(0,X.jsxs)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:[(0,X.jsxs)(`span`,{className:`font-medium`,children:[t(`specView.review.suggestion`),`:`]}),` `,e.suggestion_text]})]},e.id))}):d?(0,X.jsx)(`p`,{className:`text-xs ${i?.agent_status===`completed`?`text-emerald-300`:`text-muted-foreground`}`,children:t(d)}):null,l&&(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:e.onStopReview,className:`w-full justify-center gap-1.5`,children:[(0,X.jsx)(jv,{className:`h-3.5 w-3.5`}),t(`specView.review.stop`)]})}),u&&(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:e.onSendToPlanner,disabled:!!e.disabledReason||e.isSendingToPlanner,title:e.disabledReason??void 0,className:`w-full justify-center gap-1.5`,children:[(0,X.jsx)(vD,{className:`h-3.5 w-3.5`}),e.isSendingToPlanner?t(`specView.review.sendingToPlanner`):t(`specView.review.sendToPlanner`)]})})]})})},Hhe=({review:e})=>{let{t}=q(`common`),[n,r]=(0,p.useState)(!1),i=e.isRunning||e.review?.run?.agent_status===`running`,a=e.showModelSelector&&e.selectedDiscoveredModel!==null&&e.selectedDiscoveredModel.variants.length>0,o=t(i?`specView.review.running`:`specView.review.launch`);return(0,X.jsxs)(av,{open:n&&!i,onOpenChange:r,children:[(0,X.jsx)(ov,{asChild:!0,children:(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`ghost`,disabled:i||!!e.disabledReason,title:e.disabledReason??void 0,"aria-label":o,className:`gap-1.5 text-muted-foreground hover:text-foreground`,children:[(0,X.jsx)(V5,{className:`h-4 w-4`}),t(`specView.review.heading`)]})}),(0,X.jsx)(sv,{align:`end`,className:`w-72 max-w-[calc(100vw-2rem)] p-3`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-[0.22em] text-muted-foreground`,children:t(`specView.review.popoverTitle`)}),(0,X.jsx)(mv,{model:e.runConfigModel,showModelSelector:e.showModelSelector,availableModels:e.availableModels,onModelChange:e.onRunConfigModelChange,selectId:`spec-review-model`,label:t(`specView.review.model`)}),(0,X.jsx)(hv,{variant:e.runConfigVariant,selectedModel:e.selectedDiscoveredModel,showVariantSelector:a,onVariantChange:e.onRunConfigVariantChange,selectId:`spec-review-variant`,label:t(`specView.review.variant`)}),(0,X.jsxs)(Q,{type:`button`,size:`sm`,onClick:()=>{r(!1),e.onLaunchReview()},className:`w-full justify-center gap-1.5`,children:[(0,X.jsx)(V5,{className:`h-3.5 w-3.5`}),t(`specView.review.launchAction`)]})]})})]})},Uhe=(0,p.memo)((0,p.forwardRef)(({snapshot:e,isLoading:t,desktopWidth:n,onClose:r,actions:i,review:a,className:o},s)=>{let{t:c}=q(`common`),[l,u]=(0,p.useState)(null),[d,f]=(0,p.useState)(!1),[m,h]=(0,p.useState)(!0),[g,_]=(0,p.useState)(!0),[v,y]=(0,p.useState)(!0),[b,x]=(0,p.useState)(!0),[S,C]=(0,p.useState)(!0),[w,T]=(0,p.useState)(!0),[E,D]=(0,p.useState)(!0),[O,k]=(0,p.useState)(!0),[A,j]=(0,p.useState)(!0),M=(0,p.useCallback)(e=>{u(e)},[]),N=(0,p.useCallback)(()=>{f(!0)},[]),P=`flex h-[26rem] min-h-0 min-w-0 w-full shrink-0 flex-col overflow-hidden border-t border-border/70 bg-surface xl:h-full xl:border-l xl:border-t-0 ${o??``}`;if(t)return(0,X.jsxs)(`aside`,{ref:s,style:n?{"--spec-artifact-panel-width":`${n}px`}:void 0,className:n?`xl:w-[var(--spec-artifact-panel-width)] ${P}`:P,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/50 px-4 py-3`,children:[(0,X.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:c(`specView.artifactPanel.title`)}),(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,className:`text-muted-foreground hover:text-foreground`,"aria-label":c(`specView.artifactPanel.close`),onClick:r,children:(0,X.jsx)(ax,{className:`h-4 w-4`})})]}),(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,X.jsx)(`div`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-violet-400 border-t-transparent`})})]});if(!e)return(0,X.jsxs)(`aside`,{ref:s,style:n?{"--spec-artifact-panel-width":`${n}px`}:void 0,className:n?`xl:w-[var(--spec-artifact-panel-width)] ${P}`:P,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/50 px-4 py-3`,children:[(0,X.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:c(`specView.artifactPanel.title`)}),(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,className:`text-muted-foreground hover:text-foreground`,"aria-label":c(`specView.artifactPanel.close`),onClick:r,children:(0,X.jsx)(ax,{className:`h-4 w-4`})})]}),(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-4`,children:(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:c(`specView.artifactPanel.noSnapshot`)})})]});let F=jhe(e),I=e.tickets.length>0,L=e.bundle_groups.length>0,R=e.dependencies.length>0,z=e.open_questions.length>0,ee=e.assumptions.length>0;return(0,X.jsxs)(`aside`,{ref:s,style:n?{"--spec-artifact-panel-width":`${n}px`}:void 0,className:n?`xl:w-[var(--spec-artifact-panel-width)] ${P}`:P,children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b border-border/50 px-4 py-3`,children:[(0,X.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:c(`specView.artifactPanel.title`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[a&&(0,X.jsx)(Hhe,{review:a}),(0,X.jsx)(Q,{type:`button`,size:`icon-sm`,variant:`ghost`,className:`text-muted-foreground hover:text-foreground`,"aria-label":c(`specView.artifactPanel.close`),onClick:r,children:(0,X.jsx)(ax,{className:`h-4 w-4`})})]})]}),(0,X.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col gap-4 overflow-y-auto px-4 py-4`,children:[a&&(a.review?.run||a.isRunning)&&(0,X.jsx)(Vhe,{review:a}),(0,X.jsx)(H5,{heading:c(`specView.artifactPanel.summary`),open:m,onOpenChange:h,children:(0,X.jsx)(`section`,{className:`rounded-md border border-border/50 bg-surface-hover px-3 py-2`,children:(0,X.jsx)(`p`,{className:`text-sm leading-relaxed text-foreground whitespace-pre-wrap`,children:e.summary})})}),e.mermaid&&(0,X.jsx)(H5,{heading:c(`specView.artifactPanel.visualization`),open:g,onOpenChange:_,children:(0,X.jsx)(`section`,{className:`overflow-auto rounded-md border border-border/50 bg-surface-hover p-3`,children:(0,X.jsx)(WW,{mermaid:e.mermaid,onClick:()=>{M(e.mermaid)}})})}),e.mockup&&(0,X.jsx)(H5,{heading:(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(Fhe,{className:`h-3.5 w-3.5`}),c(`specView.artifactPanel.uiMockup`)]}),open:v,onOpenChange:y,children:(0,X.jsx)(`section`,{className:`rounded-md border border-border/50 bg-surface-hover p-3`,children:(0,X.jsx)(cG,{html:e.mockup,onClick:N})})}),F&&(0,X.jsx)(H5,{heading:(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(Tv,{className:`h-3.5 w-3.5`}),c(`specView.artifactPanel.likelyFiles`)]}),open:b,onOpenChange:x,children:(0,X.jsx)(Phe,{snapshot:e,onMermaidClick:M})}),I&&!L&&(0,X.jsx)(H5,{heading:(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(B5,{className:`h-3.5 w-3.5`}),c(`specView.artifactPanel.proposedTickets`)]}),open:S,onOpenChange:C,children:(0,X.jsx)(`section`,{children:(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:e.tickets.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(U5,{ticket:e})},e.key))})})}),L&&(0,X.jsx)(H5,{heading:(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(zv,{className:`h-3.5 w-3.5`}),c(`specView.artifactPanel.bundleGroups`)]}),open:w,onOpenChange:T,children:(0,X.jsx)(Lhe,{snapshot:e})}),R&&(0,X.jsx)(H5,{heading:(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(ow,{className:`h-3.5 w-3.5`}),c(`specView.artifactPanel.dependencies`)]}),open:E,onOpenChange:D,children:(0,X.jsx)(`section`,{children:(0,X.jsx)(`ul`,{className:`space-y-1`,children:e.dependencies.map((e,t)=>(0,X.jsxs)(`li`,{className:`flex min-w-0 flex-wrap items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`break-all font-mono text-violet-400`,children:e.blocker_key}),(0,X.jsx)(`span`,{children:`→`}),(0,X.jsx)(`span`,{className:`break-all font-mono text-violet-400`,children:e.dependent_key})]},t))})})}),z&&(0,X.jsx)(H5,{heading:c(`specView.artifactPanel.openQuestions`),open:O,onOpenChange:k,children:(0,X.jsx)(`section`,{children:(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:e.open_questions.map((e,t)=>(0,X.jsxs)(`li`,{className:`flex gap-2 text-sm text-amber-300`,children:[(0,X.jsx)(`span`,{className:`mt-0.5 shrink-0 text-amber-500`,children:`?`}),(0,X.jsx)(`span`,{className:`min-w-0 break-words`,children:e})]},t))})})}),ee&&(0,X.jsx)(H5,{heading:c(`specView.artifactPanel.assumptions`),open:A,onOpenChange:j,children:(0,X.jsx)(`section`,{children:(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:e.assumptions.map((e,t)=>(0,X.jsxs)(`li`,{className:`flex gap-2 text-sm text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`mt-0.5 shrink-0 text-violet-500`,children:`•`}),(0,X.jsx)(`span`,{className:`min-w-0 break-words`,children:e})]},t))})})})]}),i&&(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-t border-border/50 bg-surface/95 px-4 py-3 backdrop-blur`,children:[e.tickets.length>0&&(0,X.jsx)(Ihe,{actions:i}),(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:i.onImplementInChat,disabled:!!(i.unavailableReason||i.implementInChatUnavailableReason)||i.isCreatingTickets||i.isImplementingInChat||i.isExporting,title:i.unavailableReason??i.implementInChatUnavailableReason??void 0,className:`w-full justify-center gap-1.5`,children:[(0,X.jsx)(vD,{className:`h-3.5 w-3.5`}),i.isImplementingInChat?c(`specView.actions.startingImplementation`):c(`specView.actions.implementInChat`)]}),(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,onClick:i.onExport,disabled:!!i.unavailableReason||i.isCreatingTickets||i.isImplementingInChat||i.isExporting,title:i.unavailableReason??void 0,className:`w-full justify-center gap-1.5`,children:[(0,X.jsx)(mb,{className:`h-3.5 w-3.5`}),i.isExporting?c(`specView.actions.exportingSpec`):c(`specView.actions.exportSpec`)]})]}),l&&(0,X.jsx)(aG,{mermaid:l,open:!0,onClose:()=>{u(null)}}),e.mockup&&(0,X.jsx)(lG,{html:e.mockup,open:d,onClose:()=>{f(!1)}})]})})),G5=({className:e})=>(0,X.jsx)(pg,{"aria-hidden":`true`,className:e}),K5=(e,t)=>{if(!e||e.length===0)return!1;let n=e[e.length-1];return n?.kind===`grill-question`?t===null||n.created_at>t:!1},q5=(e,t)=>qb.t(`specView.${e}`,t),J5=e=>q5(`pendingMemorySuggestions`,{count:e}),Whe=1500,Y5=`archon.spec-draft`,X5=`archon.spec-run-config`,Z5=`archon.spec-review-run-config`,Q5=`archon.spec-session-list-layout`,$5=`archon.spec-artifact-panel-layout`,Ghe=`archon.spec-import-notice`,e7=420,t7=320,n7=.5,Khe=6,r7=`/`,qhe=`Slash`,Jhe=`NumpadDivide`,Yhe=e=>!e.defaultPrevented&&!e.altKey&&!e.repeat&&(e.ctrlKey||e.metaKey)&&(e.key===r7||e.code===qhe||e.code===Jhe),i7=({modifierLabel:e,keys:t,ariaHidden:n=!1})=>(0,X.jsxs)(`span`,{"aria-hidden":n,className:`flex items-center gap-0.5 text-[10px] leading-none`,children:[(0,X.jsx)(UY,{"aria-hidden":n,children:e}),t.map(e=>(0,X.jsxs)(`span`,{className:`contents`,children:[(0,X.jsx)(`span`,{children:`+`}),(0,X.jsx)(UY,{"aria-hidden":n,children:e})]},e))]}),Xhe=({label:e,modifierLabel:t,keys:n})=>(0,X.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{children:e}),(0,X.jsx)(i7,{modifierLabel:t,keys:n,ariaHidden:!0})]}),a7=({projectId:e,tool:t,sessionId:n=null})=>e?n?`${Y5}/${e}/sessions/${n}`:`${Y5}/${e}/draft/${t}`:null,o7=({projectId:e,sessionId:t})=>e&&t?`${Ghe}/${e}/${t}`:null,s7=({projectId:e,tool:t})=>{if(e)try{localStorage.setItem(`${Y5}/${e}/tool`,t)}catch{}},c7=e=>{if(!e)return{isOpen:!0};try{let t=localStorage.getItem(`${Q5}/${e}`);return{isOpen:(t?JSON.parse(t):null)?.isOpen??!0}}catch{return{isOpen:!0}}},Zhe=({projectId:e,isOpen:t})=>{if(e)try{localStorage.setItem(`${Q5}/${e}`,JSON.stringify({isOpen:t}))}catch{}},l7=(e,t)=>{let n=Number.isFinite(e)?Math.round(e):e7;if(!Number.isFinite(t))return Math.max(t7,n);let r=Math.max(t7,Math.round(t*n7));return Math.max(t7,Math.min(r,n))},u7=e=>{if(!e)return{isOpen:!1,width:e7};try{let t=localStorage.getItem(`${$5}/${e}`);if(!t)return{isOpen:!1,width:e7};let n=JSON.parse(t),r=typeof n.width==`number`&&Number.isFinite(n.width)?Math.max(t7,Math.round(n.width)):e7;return{isOpen:n.isOpen===!0,width:r}}catch{return{isOpen:!1,width:e7}}},Qhe=({projectId:e,isOpen:t,width:n})=>{if(e)try{localStorage.setItem(`${$5}/${e}`,JSON.stringify({isOpen:t,width:n}))}catch{}},$he=e=>{if(!e)return null;try{return localStorage.getItem(e)}catch{return null}},d7=({storageKey:e,value:t})=>{if(e)try{if(!t){localStorage.removeItem(e);return}localStorage.setItem(e,t)}catch{}},ege=e=>{if(!e)return null;try{let t=localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}},f7=({storageKey:e,notice:t})=>{if(e)try{if(!t){localStorage.removeItem(e);return}localStorage.setItem(e,JSON.stringify(t))}catch{}},tge=e=>{if(!e)return null;let t=e.skipped.reduce((e,t)=>e+t.count,0),n=e.skipped.map(e=>q5(`importNotice.skipReasons.${e.code}`,{count:e.count})).join(`, `);return e.imported_count>0&&t>0?q5(`importNotice.importedWithSkips`,{importedCount:e.imported_count,skippedCount:t,skippedSummary:n}):e.imported_count>0?q5(`importNotice.importedOnly`,{importedCount:e.imported_count}):t>0?q5(`importNotice.skippedOnly`,{skippedCount:t,skippedSummary:n}):null},p7=({keyPrefix:e,projectId:t,tool:n})=>`${e}:${t}:${n}`,nge=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(Boolean).filter((e,t,n)=>n.indexOf(e)===t):[],m7=({keyPrefix:e,projectId:t,tool:n})=>{if(!t||n!==`opencode`&&n!==`claude`)return null;try{let r=window.localStorage.getItem(p7({keyPrefix:e,projectId:t,tool:n}));if(!r)return null;let i=JSON.parse(r),a=(typeof i.model==`string`?i.model.trim():``)||null;return a?{model:a,variant:a&&typeof i.variant==`string`&&i.variant.trim()||null,skills:nge(i.skills)}:null}catch{return null}},h7=({keyPrefix:e,projectId:t,tool:n,model:r,variant:i,skills:a})=>{if(!(!t||n!==`opencode`&&n!==`claude`||!r))try{let o={model:r,variant:r?i:null,...a?{skills:a}:{}};window.localStorage.setItem(p7({keyPrefix:e,projectId:t,tool:n}),JSON.stringify(o))}catch{}},g7=({projectId:e,tool:t})=>m7({keyPrefix:X5,projectId:e,tool:t}),_7=({projectId:e,tool:t,model:n,variant:r,skills:i})=>h7({keyPrefix:X5,projectId:e,tool:t,model:n,variant:r,skills:i}),rge=({projectId:e,tool:t})=>{let n=g7({projectId:e,tool:t});!n||n.skills.length===0||_7({projectId:e,tool:t,...n,skills:[]})},ige=({projectId:e,tool:t})=>m7({keyPrefix:Z5,projectId:e,tool:t}),age=({projectId:e,tool:t,model:n,variant:r})=>h7({keyPrefix:Z5,projectId:e,tool:t,model:n,variant:r}),oge=({projectId:e,tool:t})=>{if(e)try{window.localStorage.removeItem(p7({keyPrefix:Z5,projectId:e,tool:t}))}catch{}},sge=`archon.spec-draft-grill`,v7=e=>e?`${sge}/${e}`:null,y7=e=>{let t=v7(e);if(!t)return!1;try{return window.localStorage.getItem(t)===`true`}catch{return!1}},b7=({projectId:e,grillOn:t})=>{let n=v7(e);if(n)try{t?window.localStorage.setItem(n,`true`):window.localStorage.removeItem(n)}catch{}},cge=({activeProjectId:e,activeProject:t=null,activeProjectBranchState:n=null,targetBundles:r=[],targetBranchSuggestions:i={current_branch:null,default_branch:null,previous_branch:null},isTargetBundleLoading:a=!1,isTargetSelectorLoading:o=!1,onTargetSelectorOpenChange:s,onSelectBundleTarget:c=async()=>!1,onSelectRepoRootTarget:l=async()=>!1,onRestoreSessionTarget:u,activeTool:d,routedSpecSessionId:f,routedSpecSnapshotId:m,initialIssueDraft:h=null,onRoutedSpecNavigationUnavailable:g,onSessionNavigation:_,onInitialIssueDraftConsumed:v,onImplementInChat:y,onNavigateToLifecycleSource:b})=>{let x=uq(),{t:S}=q(`common`),{jiraImportState:C,prepareSpecImportFromJira:w}=mw(e),{gitHubImportState:T,prepareSpecImportFromGitHub:E}=IC(e),[D,O]=(0,p.useState)([]),[k,A]=(0,p.useState)(null),[j,M]=(0,p.useState)(null),[N,P]=(0,p.useState)(null),[F,I]=(0,p.useState)(!1),[L,R]=(0,p.useState)(null),[z,ee]=(0,p.useState)({}),[B,V]=(0,p.useState)({}),[H,U]=(0,p.useState)(null),[W,te]=(0,p.useState)({}),[ne,re]=(0,p.useState)({}),[ie,ae]=(0,p.useState)([]),[G,oe]=(0,p.useState)(``),[se,ce]=(0,p.useState)(``),[le,ue]=(0,p.useState)([]),[de,fe]=(0,p.useState)(!1),[pe,me]=(0,p.useState)(!1),[he,ge]=(0,p.useState)(!1),[_e,ve]=(0,p.useState)(!1),[ye,be]=(0,p.useState)(!1),[xe,Se]=(0,p.useState)(null),[Ce,we]=(0,p.useState)([]),[Te,Ee]=(0,p.useState)(()=>new Set),[De,Oe]=(0,p.useState)(!1),[ke,Ae]=(0,p.useState)(()=>new Set),[je,Me]=(0,p.useState)(!1),[Ne,Pe]=(0,p.useState)(()=>c7(e).isOpen),[Fe,Ie]=(0,p.useState)(0),[Le,K]=(0,p.useState)(null),[Re,ze]=(0,p.useState)(()=>new Set),[Be,Ve]=(0,p.useState)(null),[He,Ue]=(0,p.useState)(null),[We,J]=(0,p.useState)(!1),[qe,Je]=(0,p.useState)(()=>u7(e).isOpen),[Xe,Ze]=(0,p.useState)(()=>u7(e).width),[Y,Qe]=(0,p.useState)(!1),[$e,et]=(0,p.useState)(!1),[tt,nt]=(0,p.useState)(!1),[rt,it]=(0,p.useState)(!1),[at,ot]=(0,p.useState)(!1),[st,ct]=(0,p.useState)(null),[lt,ut]=(0,p.useState)(!1),[dt,ft]=(0,p.useState)(null),[pt,mt]=(0,p.useState)(()=>y7(e)),[ht,gt]=(0,p.useState)(!1),[_t,vt]=(0,p.useState)([]),[yt,bt]=(0,p.useState)(!1),[xt,St]=(0,p.useState)(!1),[Ct,wt]=(0,p.useState)(0),[Tt,Et]=(0,p.useState)(null),[Dt,Ot]=(0,p.useState)(!1),[kt,At]=(0,p.useState)(!1),[jt,Mt]=(0,p.useState)(!1),[Nt,Pt]=(0,p.useState)(!1),[Ft,It]=(0,p.useState)(``),[Lt,Rt]=(0,p.useState)(``),[zt,Bt]=(0,p.useState)(!1),Vt=(0,p.useRef)(null),Ht=(0,p.useRef)(null),Ut=(0,p.useRef)(null),Wt=(0,p.useRef)(null),Gt=(0,p.useRef)(null),Kt=(0,p.useRef)(null),qt=(0,p.useRef)(!1),Jt=(0,p.useRef)(!1),Yt=(0,p.useRef)(0),Xt=(0,p.useRef)(e7),Zt=(0,p.useRef)(e7),Qt=(0,p.useRef)(null),$t=(0,p.useRef)(new Set),en=(0,p.useRef)(0),tn=(0,p.useRef)(0),nn=(0,p.useRef)(f),rn=(0,p.useRef)(!1),an=(0,p.useRef)(!1),on=(0,p.useRef)(!1),sn=(0,p.useRef)({}),cn=(0,p.useRef)({}),ln=(0,p.useRef)({}),un=(0,p.useRef)(new Set),dn=(0,p.useRef)(new Set),fn=(0,p.useRef)(0),pn=(0,p.useRef)({id:null,status:null}),mn=(0,p.useRef)(new Map),hn=(0,p.useRef)(!1),gn=(0,p.useRef)(!1),_n=(0,p.useRef)(()=>{}),vn=m===void 0?He:m;nn.current=f;let yn=e?a7({projectId:e,tool:F?d:j?.tool??d,sessionId:j?.id??null}):null,bn=o7({projectId:e,sessionId:j?.id??null}),xn=yn?z[yn]??``:``,Sn=j?B[bn??``]??null:H,Cn=F?d:j?.tool??d,wn=(0,p.useMemo)(()=>j?W[j.id]??[]:[],[j,W]),Tn=(0,p.useMemo)(()=>j?ne[j.id]??0:0,[j,ne])>0,{models:En,isLoading:Dn}=QP(Cn),On=(0,p.useCallback)(()=>{ue(e=>e.length===0?e:[]),rge({projectId:e,tool:d})},[e,d]);(0,p.useEffect)(()=>{rn.current=F},[F]),(0,p.useEffect)(()=>{sn.current=z},[z]),(0,p.useEffect)(()=>{cn.current=B},[B]),(0,p.useEffect)(()=>{ln.current=W},[W]),(0,p.useEffect)(()=>{if(!yn||un.current.has(yn))return;un.current.add(yn);let e=$he(yn);e&&ee(t=>Object.prototype.hasOwnProperty.call(t,yn)?t:{...t,[yn]:e})},[yn]),(0,p.useEffect)(()=>{if(!bn||dn.current.has(bn))return;dn.current.add(bn);let e=ege(bn);e&&V(t=>({...t,[bn]:e}))},[bn]),(0,p.useEffect)(()=>{!yn||!Object.prototype.hasOwnProperty.call(z,yn)||d7({storageKey:yn,value:z[yn]??``})},[yn,z]),(0,p.useEffect)(()=>{!bn||!Object.prototype.hasOwnProperty.call(B,bn)||f7({storageKey:bn,notice:B[bn]??null})},[bn,B]),(0,p.useEffect)(()=>{Qt.current=k},[k]),(0,p.useEffect)(()=>{let t=vn??j?.latest_snapshot_id;if(!j?.id||!t||!e){Ve(null),ut(!1),Je(!1);return}let n=!1;return J(!0),Rae(e,j.id,t).then(e=>{if(!n){if(vn&&e.spec_session_id!==j.id){Ve(null),ut(!1),g?.();return}Ve(e),ut((e.created_ticket_ids?.length??0)>0),Je(!0)}}).catch(e=>{n||(Ve(null),ut(!1),vn&&e instanceof Ge&&e.status===404?g?.():$.error(e instanceof Error?e.message:q5(`errors.loadSession`)))}).finally(()=>{n||J(!1)}),()=>{n=!0}},[j?.latest_snapshot_id,j?.id,e,vn,g]);let kn=Be?.id??null,An=j?.id??null;(0,p.useEffect)(()=>{if(!e||!An||!kn){Et(null);return}let t=!1;return Ot(!0),j5(e,An,kn).then(e=>{t||Et(e)}).catch(()=>{t||Et(null)}).finally(()=>{t||Ot(!1)}),()=>{t=!0}},[e,An,kn]);let jn=(0,p.useCallback)(()=>{!e||!An||!kn||j5(e,An,kn).then(Et).catch(()=>{})},[e,An,kn]);(0,p.useEffect)(()=>{Qhe({projectId:e,isOpen:qe,width:Xe})},[e,qe,Xe]),(0,p.useEffect)(()=>{if(!(f===void 0||!pe)){if(!f){rn.current||On(),Se(null),A(null),M(null),Ue(null),I(!0);return}if(!(D.some(e=>e.id===f)||j?.id===f)){$.error(q5(`errors.initialSessionMissing`)),an.current=!0,A(null),M(null),I(!1),g?.();return}k!==f&&(Se(null),A(f),M(null),I(!1),an.current=!0)}},[j?.id,k,pe,g,On,f,D]),(0,p.useEffect)(()=>{Y||(Zt.current=Xe,Ut.current&&(Ut.current.style.setProperty(`--spec-artifact-panel-width`,`${Xe}px`),Ut.current.setAttribute(`data-desktop-width`,String(Xe))))},[Xe,Y]);let Mn=(0,p.useCallback)(async t=>{if(!e){O([]),fe(!1);return}fe(!pe);try{let n=await pN(e,t);if(t?.aborted)return;O(Y8(n)),me(!0);let r=new Set(n.map(e=>e.id));ze(e=>{let t=new Set([...e].filter(e=>r.has(e)));return t.size===e.size?e:t})}catch(e){Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.loadSessions`))}finally{t?.aborted||fe(!1)}},[e,pe]);(0,p.useEffect)(()=>{let e=mn.current,t=new Map,n=[];for(let r of D){let i=e.get(r.id)??null,a=r.agent_status??null;i===`running`&&(a===`done`||a===`error`)&&r.id!==k&&n.push(r),t.set(r.id,a)}mn.current=t,ze(e=>{let t=new Set(e),r=!1,i=new Set(D.map(e=>e.id));for(let e of t)i.has(e)||(t.delete(e),r=!0);for(let e of D){let i=e.agent_status??null,a=n.some(t=>t.id===e.id);if((e.id===k||i!==`done`&&i!==`error`)&&t.delete(e.id)){r=!0;continue}a&&!t.has(e.id)&&(t.add(e.id),r=!0)}return r?t:e})},[e,k,D]);let Nn=(0,p.useCallback)(async(t,n)=>{if(!e)return;ge(!0);let r=en.current+1;en.current=r;let i=tn.current;try{let a=await hN(e,t,n);if(n?.aborted)return;let o=tn.current!==i,s=en.current===r,c=Qt.current===t&&!rn.current;if(!s||o||!c)return;M(a)}catch(e){e instanceof Ge&&e.status===404&&nn.current===t&&Qt.current===t?g?.():Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.loadSession`))}finally{n?.aborted||ge(!1)}},[e,g]),Pn=(0,p.useCallback)(e=>{O(t=>{let n=t.findIndex(t=>t.id===e.id);if(n===-1)return Y8([...t,P5(e)]);let r=t.slice();return r[n]=P5(e),Y8(r)})},[]),Fn=(0,p.useCallback)((e,t)=>{O(n=>{let r=n.findIndex(t=>t.id===e);if(r===-1)return n;let i=n[r];if(i.pending_memory_suggestion_count===t)return n;let a=[...n];return a[r]={...i,pending_memory_suggestion_count:t},a}),M(n=>!n||n.id!==e||n.pending_memory_suggestion_count===t?n:{...n,pending_memory_suggestion_count:t})},[]),In=(0,p.useCallback)(async(n,r)=>{if(!e||!t?.memory_enabled){vt([]),bt(!1);return}bt(!0);try{let t=await Ar(e,null,r,void 0,n);if(r?.aborted)return;vt(t.suggestions),Fn(n,t.suggestions.length)}catch(e){Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.loadMemorySuggestions`))}finally{r?.aborted||bt(!1)}},[t?.memory_enabled,e,Fn]),Ln=(0,p.useCallback)(e=>{vt(t=>{let n=t.filter(t=>t.id!==e);return k&&Fn(k,n.length),n}),wt(e=>e+1),Mn(),k&&Nn(k)},[k,Nn,Mn,Fn]),Rn=(0,p.useCallback)(e=>!!(e.first_user_message_preview||e.last_user_message_at||e.messages?.some(e=>e.role===`user`)),[]),zn=(0,p.useCallback)(()=>({tool:d,mode:pt?`grill`:`standard`,model:En.length>0&&G||null,variant:En.length>0&&se||null,skills:ie.length>0?le:[]}),[d,pt,En.length,G,se,ie.length,le]),Bn=(0,p.useCallback)(()=>{rn.current=!0,Qt.current=null,I(!0),On(),A(null),Ue(null),M(null),Ve(null),R(null),U(null),Se(null),K(null)},[On]),Vn=(0,p.useCallback)(()=>{_e||ye||(Bn(),_?.(null))},[_e,ye,_,Bn]),Hn=(0,p.useMemo)(()=>qY(),[]),Un=(0,p.useMemo)(()=>(0,X.jsx)(i7,{modifierLabel:Hn,keys:[r7],ariaHidden:!0}),[Hn]),Wn=(0,p.useMemo)(()=>(0,X.jsx)(Xhe,{label:q5(`sidebar.newSessionTooltip`),modifierLabel:Hn,keys:[r7]}),[Hn]);(0,p.useEffect)(()=>{let t=t=>{if(Yhe(t)){if(!e||_e||ye)return;t.preventDefault(),Vn(),Ie(e=>e+1);return}};return window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`keydown`,t)}},[e,_e,ye,Vn]);let Gn=(0,p.useCallback)(e=>{ye||(Se(null),A(e.id),Ue(null),I(!1),R(null),U(null),fn.current+=1,_?.(e.id))},[ye,_]),Kn=(0,p.useCallback)(async r=>{if(!e)return!1;ct(r.id);try{let i=await hN(e,r.id);return Pn(i),Qt.current===i.id&&M(i),i.target_available===!1?($.error(i.target_unavailable_reason??q5(`targets.unavailable`)),!1):!t||s5({activeProject:t,activeProjectBranchState:n,session:i})?!0:u?await u(i):!1}catch(e){return Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.restoreTarget`)),!1}finally{ct(e=>e===r.id?null:e)}},[t,n,e,u,Pn]),qn=(0,p.useCallback)(async t=>{if(e){Se(t);try{await Lae(e,t)}catch(e){Se(e=>e===t?null:e),Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.stopSession`))}}},[e]);(0,p.useEffect)(()=>{if(!xe)return;let e=j?.id===xe?j:D.find(e=>e.id===xe)??null;(!e||e.agent_status!==`running`)&&Se(null)},[j,xe,D]);let Jn=(0,p.useCallback)(async()=>{if(!(!e||!j||!Be)){nt(!0);try{if(!await Kn(j))return;let t=await Bae(e,j.id,Be.id);ut(!0),$.success(q5(`actions.createTicketsSuccess`,{count:t.tickets.length})),Mn()}catch(e){if(Ye(e))return;if(Ke(e,`existing_ticket_ids`)){ut(!0);return}$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{nt(!1)}}},[e,j,Be,Mn,Kn]),Yn=(0,p.useCallback)(()=>{Jn()},[Jn]),Xn=(0,p.useCallback)(async()=>{if(!(!e||!j||!Be)&&y){it(!0);try{if(!await Kn(j))return;let t=await Vae(e,j.id,Be.id);y(t.draft_text,t.spec_session_id,t.spec_snapshot_id)}catch(e){if(Ye(e))return;e instanceof Ge&&e.status===409&&await Nn(j.id),$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{it(!1)}}},[e,j,Be,Nn,y,Kn]),Zn=(0,p.useCallback)(async t=>{let n=t?.projectId??e,r=t?.sessionId??j?.id,i=t?.snapshotId??Be?.id;if(!(!n||!r||!i)){ot(!0);try{if(!j||j.id!==r||!await Kn(j))return;await zae(n,r,i,{overwrite:t?.overwrite}),ft(null),$.success(q5(`actions.exportSuccess`))}catch(e){if(Ye(e))return;if(e instanceof vN){ft({path:e.conflictingPath,projectId:n,sessionId:r,snapshotId:i});return}e instanceof Ge&&e.status===409&&j&&await Nn(j.id),$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{ot(!1)}}},[e,j,Be,Nn,Kn]),Qn=(0,p.useCallback)(()=>{Kt.current?.(),Kt.current=null},[]),$n=(0,p.useCallback)(e=>{if(!Vt.current)return;let t=Vt.current.getBoundingClientRect().width,n=l7(e,t);Zt.current=n,Ut.current&&(Ut.current.style.setProperty(`--spec-artifact-panel-width`,`${n}px`),Ut.current.setAttribute(`data-desktop-width`,String(n)))},[]),er=(0,p.useCallback)(e=>{let t=Wt.current,n=Gt.current,r=qt.current;if(t!==null){if(Wt.current=null,Gt.current=null,qt.current=!1,Qe(!1),et(!1),Qn(),e!==null&&typeof Ht.current?.hasPointerCapture==`function`&&Ht.current.hasPointerCapture(e)&&typeof Ht.current.releasePointerCapture==`function`&&Ht.current.releasePointerCapture(e),n===`collapsed`){if(!r)return;Ze(Zt.current),Je(!0);return}Ze(Zt.current)}},[Qn]),tr=(0,p.useCallback)((e,t)=>{if(Wt.current!==e)return;let n=t-Yt.current,r=Xt.current-n;if(Gt.current===`collapsed`){if(!qt.current&&r<Khe)return;qt.current||(qt.current=!0,Jt.current=!0,et(!0),Qe(!0))}$n(r)},[$n]),nr=(0,p.useCallback)((e,t)=>{if(Wt.current===e){if(t!==null&&(Gt.current===`inline`||qt.current)){let e=t-Yt.current;$n(Xt.current-e)}er(e)}},[er,$n]),rr=(0,p.useCallback)(e=>{e.preventDefault(),Wt.current=e.pointerId,Gt.current=qe?`inline`:`collapsed`,qt.current=!1,Jt.current=!1,Yt.current=e.clientX,Xt.current=qe?Zt.current:0,Qe(qe),Qn(),typeof e.currentTarget.setPointerCapture==`function`&&e.currentTarget.setPointerCapture(e.pointerId);let t=e=>{tr(e.pointerId,e.clientX)},n=e=>{nr(e.pointerId,e.clientX)},r=e=>{nr(e.pointerId,e.clientX)};window.addEventListener(`pointermove`,t),window.addEventListener(`pointerup`,n),window.addEventListener(`pointercancel`,r),Kt.current=()=>{window.removeEventListener(`pointermove`,t),window.removeEventListener(`pointerup`,n),window.removeEventListener(`pointercancel`,r)}},[nr,tr,qe,Qn]),ir=(0,p.useCallback)(e=>{tr(e.pointerId,e.clientX)},[tr]),ar=(0,p.useCallback)(e=>{nr(e.pointerId,e.clientX)},[nr]),or=(0,p.useCallback)(e=>{nr(e.pointerId,e.clientX)},[nr]),sr=(0,p.useCallback)(e=>{Wt.current===e.pointerId&&er(e.pointerId)},[er]),cr=(0,p.useCallback)(()=>{Je(!1)},[]),lr=(0,p.useCallback)(async()=>{if(!e||Ce.length===0)return;let t=Ce;Ee(e=>{let n=new Set(e);for(let e of t)n.add(e);return n});let n=[],r=[];for(let i of t)try{await _N(e,i),r.push(i)}catch(e){Ye(e)||n.push(e instanceof Error?e.message:q5(`errors.deleteSession`))}if(Ee(e=>{let n=new Set(e);for(let e of t)n.delete(e);return n}),we([]),_n.current(r),n.length>0){$.error(n.join(`
276
+ `));return}De&&(Oe(!1),Ae(new Set),$.success(q5(`toasts.deleteSelectedSuccess`,{count:t.length})))},[e,Ce,De]),ur=(0,p.useCallback)((t,n={})=>{let r=new Set(t);if(r.size===0)return;let i=Qt.current,a=n.preserveDraftRoute===!0,o=!!(a&&i&&r.has(i)&&nn.current===i),s=!!(!a&&i&&r.has(i)),c=s?D.find(e=>!r.has(e.id))??null:null;o&&(On(),_?.(null)),s&&(c||On(),_?.(c?.id??null));for(let t of r)d7({storageKey:a7({projectId:e,tool:d,sessionId:t}),value:``}),f7({storageKey:o7({projectId:e,sessionId:t}),notice:null});te(e=>{let t={...e},n=!1;for(let e of r)Object.prototype.hasOwnProperty.call(t,e)&&(delete t[e],n=!0);return n?t:e}),V(t=>{let n={...t},i=!1;for(let t of r){let r=o7({projectId:e,sessionId:t});r&&Object.prototype.hasOwnProperty.call(n,r)&&(delete n[r],i=!0)}return i?n:t}),O(e=>{let t=e.filter(e=>!r.has(e.id));if(i&&r.has(i)){if(nn.current===i)return a?(A(null),M(null),Ue(null),I(!0),t):(A(null),M(null),Ue(null),I(c===null),t);let e=t[0]??null;A(e?.id??null),M(null),Ue(null),I(e===null)}return t}),ze(e=>{let t=new Set(e),n=!1;for(let e of r)t.delete(e)&&(n=!0);return n?t:e}),K(e=>e&&r.has(e.parentId)?null:e),Se(e=>e&&r.has(e)?null:e),we(e=>e.filter(e=>!r.has(e))),Ee(e=>{let t=new Set(e),n=!1;for(let e of r)t.delete(e)&&(n=!0);return n?t:e}),Ae(e=>{let t=new Set(e),n=!1;for(let e of r)t.delete(e)&&(n=!0);return n?t:e})},[e,d,_,On,D]),dr=(0,p.useCallback)((e,t)=>{ur([e],t)},[ur]);_n.current=ur;let fr=(0,p.useCallback)((e,t)=>{e&&ee(n=>n[e]===t?n:{...n,[e]:t})},[]),pr=(0,p.useCallback)((e,t)=>{te(n=>{if(t.length===0){if(!Object.prototype.hasOwnProperty.call(n,e))return n;let t={...n};return delete t[e],t}return{...n,[e]:t}})},[]),mr=(0,p.useCallback)(e=>{te(t=>{if(!Object.prototype.hasOwnProperty.call(t,e))return t;let n={...t};return delete n[e],n}),re(t=>{if(!Object.prototype.hasOwnProperty.call(t,e))return t;let n={...t};return delete n[e],n})},[]),hr=(0,p.useCallback)((e,t)=>{e&&V(n=>(n[e]??null)===t?n:{...n,[e]:t})},[]),gr=(0,p.useCallback)(e=>{e&&(V(t=>!Object.prototype.hasOwnProperty.call(t,e)||t[e]===null?t:{...t,[e]:null}),f7({storageKey:e,notice:null}))},[]),_r=(0,p.useCallback)(t=>{if(e){if(t.spec_session){let n=a7({projectId:e,tool:t.spec_session.tool,sessionId:t.spec_session.id}),r=o7({projectId:e,sessionId:t.spec_session.id});fr(n,t.prompt_text),hr(r,t.import_notice),pr(t.spec_session.id,t.imported_attachments),Pn(t.spec_session),M(t.spec_session),A(t.spec_session.id),I(!1),R(null),U(null),Ie(e=>e+1);return}R(t.external_source),U(t.import_notice),On(),I(!0),A(null),M(null),Ue(null),Ve(null),fr(a7({projectId:e,tool:d}),t.prompt_text),Ie(e=>e+1)}},[e,d,On,fr,hr,pr,Pn]),vr=(0,p.useCallback)(async({provider:e,issueReference:t})=>{let n=$.loading(q5(`toasts.importPreparing`));try{let r=e===`jira`?await w?.({issueReference:t,...zn()}):await E?.({issueReference:t,...zn()});if(!r)throw Error(q5(`toasts.importError`));return(r.import_notice?.skipped.reduce((e,t)=>e+t.count,0)??0)>0?$.warning(q5(`toasts.importPartialSuccess`),{id:n}):$.success(q5(`toasts.importSuccess`),{id:n}),r}catch(e){if(Ye(e))$.dismiss(n);else{let t=e instanceof Error&&e.message?e.message:q5(`toasts.importError`);$.error(t,{id:n})}throw e}},[zn,E,w]),yr=(0,p.useMemo)(()=>[{key:`jira`,label:S(`jiraImportField.label`),placeholder:S(`jiraImportField.placeholder`),state:C,onImport:e=>vr({provider:`jira`,issueReference:e})},{key:`github`,label:S(`githubImportField.label`),placeholder:S(`githubImportField.placeholder`),state:T,onImport:e=>vr({provider:`github`,issueReference:e})}],[S,C,T,vr]),br=yr.some(e=>e.state===`enabled`);(0,p.useEffect)(()=>{h&&(vr({provider:h.external_source.provider,issueReference:h.external_source.external_key}).then(_r).catch(()=>void 0),v?.())},[h,vr,_r,v]);let xr=(0,p.useCallback)(async()=>{if(!(!e||!j||!Be)){At(!0);try{await yhe(e,j.id,Be.id,{tool:j.tool,...zt?{model:Ft||null,variant:Lt||null}:{},skills:j.skills}),zt&&age({projectId:e,tool:j.tool,model:Ft||null,variant:Lt||null}),jn()}catch(e){if(Ye(e))return;e instanceof Ge&&e.status===409&&await Nn(j.id),$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{At(!1)}}},[e,j,Be,zt,Ft,Lt,jn,Nn]),Sr=(0,p.useCallback)(async()=>{if(!(!e||!j||!Be)){Mt(!0);try{await bhe(e,j.id,Be.id),jn()}catch(e){if(Ye(e))return;$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{Mt(!1)}}},[e,j,Be,jn]),Cr=(0,p.useCallback)(async()=>{if(!e||!j||!Be)return;let t=Tt?.run;if(t){Pt(!0);try{fr(yn,(await xhe(e,j.id,Be.id,t.id)).draft_text),Ie(e=>e+1)}catch(e){if(Ye(e))return;$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{Pt(!1)}}},[e,j,Be,Tt,fr,yn]),wr=(0,p.useCallback)(e=>{e&&(ee(t=>t[e]===``?t:{...t,[e]:``}),d7({storageKey:e,value:``}))},[]),Tr=(0,p.useCallback)((e,t)=>{re(n=>{let r=Math.max(0,(n[e]??0)+t);if(r===0){if(!Object.prototype.hasOwnProperty.call(n,e))return n;let t={...n};return delete t[e],t}return{...n,[e]:r}})},[]),Er=(0,p.useCallback)(async t=>{if(!(!e||ht||gn.current)&&!(j&&j.agent_status===`running`)){if(!k||!j){mt(t),b7({projectId:e,grillOn:t});return}if(j.mode===(t?`grill`:`standard`)){mt(t);return}gt(!0);try{let n=await Nae(e,j.id,{mode:t?`grill`:`standard`});M(n),Pn(n),mt(t),t||K5(n.messages,n.latest_snapshot_created_at)&&await gN(e,n.id,{instruction:q5(`grill.finalizePrompt`),tool:n.tool,model:En.length>0&&G||null,variant:En.length>0&&se||null,skills:ie.length>0?le:[]})}catch(e){Ye(e)||$.error(e instanceof Error?e.message:q5(`grill.updateModeError`))}finally{gt(!1)}}},[e,j,k,ht,Pn,En,G,se,ie,le]),Dr=(0,p.useCallback)(async()=>{if(!e||_e||ye||hn.current||gn.current||t&&j&&!s5({activeProject:t,activeProjectBranchState:n,session:j}))return;let r=xn.trim();if(!r&&wn.length===0)return;be(!0);let i=yn,a=performance.now();fn.current+=1;let o=`spec:${fn.current}`;try{let t=k,n=!t,s=n;if(t&&!j){let r=await hN(e,t);r?s=r.messages?.length===0:(n=!0,s=!0,t=null)}else j&&(s=j.messages?.length===0);if(n){ve(!0);let n=await mN(e,{tool:d,mode:pt?`grill`:`standard`,model:En.length>0&&G||null,variant:En.length>0&&se||null,skills:ie.length>0?le:[],external_source:L??null});t=n.id,A(t),M(n),I(!1),_?.(t),R(null),mt(!1),b7({projectId:e,grillOn:!1}),s7({projectId:e,tool:d}),ve(!1)}if(!t)throw Error(`Unable to resolve the spec session.`);Se(e=>e===t?null:e),K({parentType:`spec`,parentId:t,turnKey:o,startedAt:a});let c=wn.map(e=>e.id),l=await gN(e,t,{instruction:r,tool:j?.tool??d,model:G||null,variant:se||null,skills:le,attachment_ids:c.length>0?c:void 0});M(l),_7({projectId:e,tool:l.tool,model:l.model,variant:l.variant,skills:s?[]:l.skills}),Ie(e=>e+1),mr(t),wr(i),gr(o7({projectId:e,sessionId:t})),U(null)}catch(e){K(e=>e?.turnKey===o?null:e);let t=Ke(e,`spec_session`);t?(M(t),Pn(t)):e instanceof Ge&&e.status===409&&Qt.current&&await Nn(Qt.current),Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{be(!1),ve(!1)}},[t,n,e,_e,ye,xn,wn,yn,k,j,d,pt,En,G,se,ie,le,L,Nn,Pn,mr,wr,gr,_]),Or=(0,p.useCallback)(async t=>{if(e){$t.current.add(t.id);try{await _N(e,t.id),dr(t.id,{preserveDraftRoute:!0}),Bn()}catch(e){throw $t.current.delete(t.id),e}}},[e,Bn,dr]),kr=(0,p.useCallback)(async t=>{if(!e||Cn!==`opencode`&&Cn!==`claude`)return;let n=k,r=null;if(!n&&t.length>0)try{ve(!0);let t=await mN(e,{tool:d,mode:pt?`grill`:`standard`,model:En.length>0&&G||null,variant:En.length>0&&se||null,skills:ie.length>0?le:[],external_source:L??null});r=t,n=t.id,A(n),M(t),I(!1),_?.(n),s7({projectId:e,tool:d})}catch(e){Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.upload`));return}finally{ve(!1)}if(n){Tr(n,t.length);try{let r=await Fae(e,n,t),i=[...ln.current[n]??[],...r.attachments];pr(n,i)}catch(e){if(r&&!xn.trim())try{await Or(r)}catch{}Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.upload`))}finally{Tr(n,-t.length)}}},[e,k,d,Cn,En,G,se,ie,le,pt,L,xn,Or,Tr,_,pr]),jr=(0,p.useCallback)(async t=>{if(!e||!j)return;let n=j,r=n.id,i=(ln.current[r]??[]).filter(e=>e.id!==t);try{await Iae(e,r,t),pr(r,i),i.length===0&&!xn.trim()&&(n.messages?.length??0)===0&&await Or(n)}catch(e){Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.removeAttachment`))}},[e,j,Or,xn,pr]);(0,p.useEffect)(()=>{Le&&(Le.parentId===k&&(ye||j?.agent_status===`running`)||K(null))},[j?.agent_status,k,ye,Le]),(0,p.useEffect)(()=>{if(!on.current){on.current=!0;return}let t=c7(e),n=u7(e);rn.current=!1,an.current=!1,un.current=new Set,dn.current=new Set,A(null),M(null),Ue(null),Ve(null),I(!1),R(null),ee({}),V({}),U(null),te({}),re({}),$t.current.clear(),Se(null),we([]),Ee(new Set),Oe(!1),Ae(new Set),K(null),vt([]),bt(!1),St(!1),me(!1),ze(new Set),mn.current=new Map,Zt.current=n.width,Pe(t.isOpen),Ze(n.width),Je(n.isOpen),mt(y7(e)),gt(!1)},[e]);let Mr=(0,p.useCallback)((e,t)=>{Ae(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]);(0,p.useEffect)(()=>{let e=new AbortController;return Mn(e.signal),()=>{e.abort()}},[Mn]),(0,p.useEffect)(()=>{if(f!==void 0||rn.current||F||k||an.current||D.length===0||t?.active_target_kind!==`bundle`&&n?.status===`loading`)return;let e=t?D.find(e=>s5({activeProject:t,activeProjectBranchState:n,session:e}))??null:D[0]??null;an.current=!0,e&&A(e.id)},[t,n,k,F,f,D]),(0,p.useEffect)(()=>{if(Cn!==`opencode`&&Cn!==`claude`){ae([]),Me(!1);return}if(Cn!==`opencode`){ae([]);return}let t=new AbortController;return(async()=>{Me(!0);try{ae(await $P(Cn,t.signal,e))}catch(e){Ye(e)||ae(e=>e)}finally{t.signal.aborted||Me(!1)}})(),()=>{t.abort()}},[e,Cn]),(0,p.useEffect)(()=>{if(Cn!==`opencode`&&Cn!==`claude`){oe(``),ce(``),ue([]);return}if(F){let t=g7({projectId:e,tool:Cn}),n=new Set(En.map(e=>e.id)),r=t?.model??``,i=r&&(n.size===0||n.has(r)),a=En.find(e=>e.id===r)??null,o=t?.variant??``,s=!a||a.variants.includes(o),c=new Set(ie.map(e=>e.name));oe(i?r:``),ce(e=>!i||!s?``:o||e),ue(Cn===`opencode`?(t?.skills??[]).filter(e=>c.has(e)):[]);return}oe(j?.model??``),ce(j?.variant??``),ue(j?.skills??[])},[e,j?.id,j?.model,j?.skills,j?.variant,En,ie,Cn,F]),(0,p.useEffect)(()=>{if(F||!k){M(null);return}if(j?.id===k)return;M(null);let e=new AbortController;return Nn(k,e.signal),()=>{e.abort()}},[j,k,F,Nn]),(0,p.useEffect)(()=>{St(!1)},[k,F]),(0,p.useEffect)(()=>{if(!t?.memory_enabled||F||!k){vt([]),bt(!1);return}let e=new AbortController;return In(k,e.signal),()=>{e.abort()}},[t?.memory_enabled,k,F,In,Ct]),(0,p.useEffect)(()=>{!xt||yt||_t.length>0||St(!1)},[yt,xt,_t.length]),(0,p.useEffect)(()=>{let e=pn.current,n=j?.id??null,r=j?.agent_status??null;e.id===n&&e.status===`running`&&r===`done`&&t?.memory_enabled&&n&&wt(e=>e+1),pn.current={id:n,status:r}},[t?.memory_enabled,j?.agent_status,j?.id]),(0,p.useEffect)(()=>{if(!k||j?.agent_status!==`running`)return;let e=new AbortController,t=window.setInterval(()=>{Promise.all([Mn(e.signal),Nn(k,e.signal)])},Whe);return()=>{e.abort(),window.clearInterval(t)}},[j?.agent_status,k,Nn,Mn]),(0,p.useEffect)(()=>{if(!e)return;let t=t=>{!t||t.project_id!==e||(!F&&t.id===Qt.current&&(tn.current+=1,M(t)),Rn(t)&&Pn(t))},n=t=>{if(!t||t.project_id!==e)return;let n=$t.current.delete(t.id);dr(t.id,n?{preserveDraftRoute:!0}:void 0)},r=()=>{Mn();let e=Qt.current;e&&!rn.current&&Nn(e)};return x.on(`connect`,r),x.on(`spec-session:created`,t),x.on(`spec-session:updated`,t),x.on(`spec-session:deleted`,n),()=>{x.off(`connect`,r),x.off(`spec-session:created`,t),x.off(`spec-session:updated`,t),x.off(`spec-session:deleted`,n)}},[e,F,Nn,Mn,Rn,Pn,dr,x]),(0,p.useEffect)(()=>{if(!e||!kn)return;let t=e=>{!e||e.spec_snapshot_id!==kn||jn()};return x.on(`spec-review:updated`,t),()=>{x.off(`spec-review:updated`,t)}},[e,kn,jn,x]);let Nr=(0,p.useMemo)(()=>X8(D),[D]),Pr=(0,p.useMemo)(()=>{let e=new Set(Nr.find(e=>e.key===`older`)?.sessions.map(e=>e.id)??[]);return[{key:`unavailable`,label:q5(`sidebar.presets.unavailable`),matches:e=>e.target_available===!1},{key:`older`,label:q5(`sidebar.presets.older`),matches:t=>e.has(t.id)}]},[Nr]),Fr=(0,p.useCallback)(e=>{e.key!==`Enter`||e.shiftKey||j?.agent_status===`running`||_e||ye||Tn||hn.current||gn.current||(e.preventDefault(),Dr())},[Dr,j?.agent_status,_e,ye,Tn]),Ir=(0,p.useCallback)(t=>{if(!e||Cn!==`opencode`&&Cn!==`claude`)return;let n=Array.from(t.clipboardData.files).filter(e=>e.type.startsWith(`image/`));n.length!==0&&(t.preventDefault(),kr(n))},[e,Cn,kr]),Lr=(0,p.useMemo)(()=>$8(En),[En]),Rr=(0,p.useMemo)(()=>j?t5({modelLabel:e5({availableModelsById:Lr,model:j.model}),tool:j.tool}):null,[j,Lr]),zr=(0,p.useMemo)(()=>j?.messages?j.messages.map(e=>({id:e.id,role:e.role,kind:e.kind,content:e.content,attachments:e.attachments??[],responseTiming:e.response_timing?KK(e.response_timing):null,transcript_runs:e.transcript_runs??null,metadata:e.metadata,created_at:e.created_at,displayTitle:e.role===`assistant`?Rr??Q8(j.tool):n5()})):[],[j,Rr]),Br=k!==null||F,Vr=F?null:j,Hr=Vr?.target_available===!1,Ur=!!(t&&Vr&&!Hr&&!s5({activeProject:t,activeProjectBranchState:n,session:Vr})),Wr=Ur&&Vr?q5(`targets.mismatchReason`,{sessionTarget:l5(Vr),currentTarget:u5({activeProject:t,activeProjectBranchState:n})}):null,Gr=Hr?Vr?.target_unavailable_reason??q5(`targets.unavailable`):null,Kr=Hr||Ur,qr=Vr?.streaming_response??null,Jr=Vr?.agent_status===`running`,Yr=!!(ye&&Le?.parentType===`spec`&&Le.parentId===k),Xr=Jr||Yr,Zr=Xr?Rr:null,Qr=Jr&&xe===k,$r=!!e&&!_e&&(F||k!==null&&!Kr),ei=!!(t?.memory_enabled&&j&&!F&&(j.pending_memory_suggestion_count>0||yt)),ti=(Cn===`opencode`||Cn===`claude`)&&(F||k!==null)&&Vr?.agent_status!==`running`,ni=(0,p.useMemo)(()=>{if(!j?.messages)return null;for(let e=j.messages.length-1;e>=0;--e){let t=j.messages[e];if(t.kind===`grill-question`)return t.id}return null},[j]),ri=(0,p.useMemo)(()=>!j||j.mode!==`grill`?!1:K5(j.messages,j.latest_snapshot_created_at),[j]),ii=(0,p.useMemo)(()=>[...j?.messages??[]].reverse().find(e=>e.metadata?.ask_question?.status===`pending`)??null,[j]),ai=!!ii,oi=(0,p.useCallback)(async t=>{if(!e||!k||!j)return;be(!0),fn.current+=1;let n={parentType:`spec`,parentId:k,turnKey:`spec:${fn.current}`,startedAt:performance.now()};K(n);try{M(await gN(e,k,{instruction:t,tool:j.tool,model:En.length>0&&G||null,variant:En.length>0&&se||null,skills:ie.length>0?le:[]})),Ie(e=>e+1)}catch(e){K(e=>e?.turnKey===n.turnKey?null:e),Ye(e)||$.error(e instanceof Error?e.message:q5(`errors.sendPrompt`))}finally{be(!1)}},[e,k,j,En,G,se,ie,le]),si=(0,p.useCallback)(async(t,n)=>{if(!e||!j||N)return;let r=UJ({parentType:`spec`,parentId:j.id,setId:n.set_id});P(n.set_id),be(!0),fn.current+=1;let i={parentType:`spec`,parentId:j.id,turnKey:`spec:${fn.current}`,startedAt:performance.now()};K(i);try{let r=await Pae(e,j.id,t,n);M(r),Pn(r)}catch(e){if(e instanceof Ge&&e.status===409){GJ(r);let t=e.data&&typeof e.data==`object`&&`spec_session`in e.data?e.data.spec_session:null;t?(M(t),Pn(t)):await Nn(j.id)}throw K(e=>e?.turnKey===i.turnKey?null:e),$.error(e instanceof Error?e.message:q5(`errors.resolveQuestions`)),e}finally{P(null),be(!1)}},[e,j,Nn,N,Pn]),ci=(0,p.useCallback)(e=>{if(e.role!==`assistant`)return;let t=e.metadata,n=t?.ask_question;if(n&&j)return(0,X.jsx)(QJ,{messageContent:e.content,questionSet:n,storageKey:UJ({parentType:`spec`,parentId:j.id,setId:n.id}),isActive:n.status===`pending`&&ii?.id===e.id,isDisabled:Kr||j.agent_status===`running`||N===n.id,onResolve:t=>si(e.id,t)});if(e.kind!==`grill-question`)return;let r=t?.grill_question;if(r)return(0,X.jsx)(M5,{question:r,isActive:Xr?!1:e.id===ni&&j?.agent_status!==`running`&&j?.mode===`grill`,isDisabled:Kr||ye||_e||ht,labels:{rationaleLabel:q5(`grill.rationaleLabel`),suggestionsLabel:q5(`grill.suggestionsLabel`),recommendedSuggestionLabel:q5(`grill.recommendedSuggestionLabel`),answerPlaceholder:q5(`grill.answerPlaceholder`),submitLabel:q5(`grill.submitLabel`),submittingLabel:q5(`grill.submittingLabel`)},onSubmitAnswer:e=>{oi(e)}})},[j,Xr,ye,_e,Kr,ht,ni,ii?.id,si,N,oi]),li=(Cn===`opencode`||Cn===`claude`)&&En.length>0,ui=Cn,di=F?q5(`composer.newSpecTitle`):j?.title??q5(`composer.specTitle`),fi=li?G||null:j?.model??null,pi=e5({availableModelsById:Lr,model:fi}),mi=j?.agent_status===`stopped`,hi=q5(`composer.placeholderSpec`),gi=D.some(e=>e.agent_status!==`running`),_i=(0,p.useMemo)(()=>({ariaLabel:q5(`sidebar.ariaLabel`),newSession:q5(`sidebar.newSession`),collapseAriaLabel:q5(`sidebar.collapseAriaLabel`),openAriaLabel:q5(`sidebar.openAriaLabel`),cancelSelection:q5(`sidebar.cancelSelection`),addPreset:q5(`sidebar.addPreset`),deleteSelected:q5(`sidebar.deleteSelected`),selectedCount:e=>`${e} selected`,select:q5(`sidebar.select`),loadingSessions:q5(`sidebar.loadingSessions`),noSessions:q5(`sidebar.noSessions`),deleteSessionAriaLabel:q5(`sidebar.deleteSessionAriaLabel`),selectSessionAriaLabel:e=>q5(`sidebar.selectSessionAriaLabel`,{title:e}),selectSessionTitle:e=>q5(`sidebar.selectSessionTitle`,{title:e}),deleteSessionTitle:e=>q5(`sidebar.deleteSessionTitle`,{title:e})}),[]),vi=(0,p.useMemo)(()=>({title:q5(`deleteModal.title`),bulkTitle:q5(`deleteModal.bulkTitle`),description:q5(`deleteModal.description`),bulkDescription:e=>q5(`deleteModal.bulkDescription`,{count:e}),cancel:q5(`deleteModal.cancel`),delete:q5(`deleteModal.delete`),deleting:q5(`deleteModal.deleting`)}),[]),yi=(0,p.useCallback)((e,t)=>e.agent_status===`running`?`running`:!t&&Re.has(e.id)?`finished`:null,[Re]),bi=(0,p.useCallback)(e=>e.agent_status===`running`?q5(`sidebar.cannotDeleteRunning`):null,[]),xi=!!(t?.memory_enabled&&k&&!F),Si=(0,p.useCallback)(e=>{let r=c5({session:e,activeProject:t,activeProjectBranchState:n}),i=xi&&e.pending_memory_suggestion_count>0?J5(e.pending_memory_suggestion_count):null,a=(e.linked_ticket_count??0)+(e.linked_chat_count??0);return a>0?[e.title,r,i,q5(`sidebar.linkedImplementationsAriaLabel`,{itemCount:a})].filter(Boolean).join(` `):e.has_completed_work===1?[e.title,r,i,q5(`sidebar.linkedImplementationsAriaLabelHistorical`)].filter(Boolean).join(` `):[e.title,r,i].filter(Boolean).join(` `)},[t,n,xi]),Ci=e=>{let t=e.first_user_message_preview??e.messages?.find(e=>e.role===`user`)?.content;return t&&t.replace(/\s+/g,` `).trim()||null},wi=(0,p.useCallback)(({session:e,activityState:r})=>{let i=Ci(e),a=c5({session:e,activeProject:t,activeProjectBranchState:n}),o=e.linked_ticket_count??0,s=e.linked_chat_count??0,c=o+s,l=e.has_completed_work===1||c>0,u=c>0,d=u?q5(`sidebar.linkedImplementationsTooltip`,{ticketCount:o,chatCount:s}):q5(`sidebar.linkedImplementationsTooltipHistorical`),f=xi&&e.pending_memory_suggestion_count>0;return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[a?(0,X.jsx)(`div`,{className:`mb-1 truncate text-[10px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75`,children:a}):null,(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 truncate text-[13px] font-medium leading-5`,children:[(0,X.jsx)(`span`,{className:`truncate`,children:e.title}),f?(0,X.jsx)(Ew,{tone:`muted`,className:`shrink-0`,"aria-label":J5(e.pending_memory_suggestion_count),title:J5(e.pending_memory_suggestion_count),children:e.pending_memory_suggestion_count}):null,l&&(0,X.jsx)(vv,{content:d,children:(0,X.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5 text-[11px] text-indigo-500 dark:text-indigo-400`,children:[(0,X.jsx)(wF,{className:`size-3`}),u&&(0,X.jsx)(`span`,{children:c})]})})]}),i?(0,X.jsx)(`div`,{className:`mt-0.5 line-clamp-1 text-xs leading-4 text-muted-foreground`,children:i}):null,e.target_available===!1?(0,X.jsx)(`div`,{className:`mt-1 line-clamp-1 text-[11px] leading-4 text-amber-200/90`,children:e.target_unavailable_reason??q5(`targets.unavailable`)}):null]}),(0,X.jsx)(ib,{state:r,className:`mt-1`})]})},[t,n,xi]),Ti=Jr?(0,X.jsx)(N8,{isInterrupting:Qr,onStop:()=>{k&&qn(k)},interruptLabel:q5(`composer.interrupt`),interruptingLabel:q5(`composer.interrupting`)}):null,Ei=(0,p.useMemo)(()=>En.find(e=>e.id===G)??null,[En,G]),Di=({model:t=G,variant:n=se,skills:r=le}={})=>{F&&_7({projectId:e,tool:d,model:t||null,variant:t&&n||null,skills:d===`opencode`?r:[]})},Oi=Cn===`opencode`||Cn===`claude`?je||Dn?(0,X.jsx)(gY,{}):En.length>0?(0,X.jsx)(_Y,{model:G,variant:se,skills:le,showModelSelector:!0,showSkillsSelector:ie.length>0,availableModels:En,availableSkills:ie,selectedModel:Ei,onModelChange:e=>{let t=En.find(t=>t.id===e)??null,n=t&&t.variants.includes(se)?se:``;oe(e),ce(n),Di({model:e,variant:n})},onVariantChange:e=>{ce(e),Di({variant:e})},onSkillsChange:e=>{ue(e),Di({skills:e})},modelSelectId:`spec-model-select`,variantSelectId:`spec-variant-select`,skillsSelectId:`spec-skills-select`}):null:null,ki=(0,p.useMemo)(()=>Ce.length===1?D.find(e=>e.id===Ce[0])?.title??``:``,[Ce,D]),Ai=(0,p.useMemo)(()=>D.filter(e=>Ce.includes(e.id)),[D,Ce]),ji=Br&&j!==null,Mi=ji&&!qe&&!$e,Ni=ji&&(qe||$e);(0,p.useEffect)(()=>{if(!Ni||Y||!Vt.current)return;let e=Vt.current,t=()=>{let t=e.getBoundingClientRect().width;if(t<=0)return;let n=l7(Xe,t);Zt.current=n,Ut.current&&(Ut.current.style.setProperty(`--spec-artifact-panel-width`,`${n}px`),Ut.current.setAttribute(`data-desktop-width`,String(n))),Ze(e=>e===n?e:n)};if(t(),typeof ResizeObserver!=`function`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[Xe,Ni,Y]);let Pi=j?.tool??d,Fi=Pi===`opencode`&&En.length>0,Ii=(0,p.useMemo)(()=>En.find(e=>e.id===Ft)??null,[En,Ft]),Li=Be&&ji?{review:Tt,isRunning:kt||jt,isLoading:Dt,availableModels:En,showModelSelector:Fi,runConfigTool:Pi,runConfigModel:Ft,runConfigVariant:Lt,selectedDiscoveredModel:Ii,onRunConfigModelChange:t=>{let n=En.find(e=>e.id===t)??null;It(t),Bt(!!t),t||oge({projectId:e,tool:Pi}),Rt(e=>n&&n.variants.includes(e)?e:``)},onRunConfigVariantChange:e=>{Rt(e),Bt(!!Ft)},onLaunchReview:()=>{xr()},onStopReview:()=>{Sr()},onSendToPlanner:()=>{Cr()},isSendingToPlanner:Nt,disabledReason:Gr??Wr}:void 0;(0,p.useEffect)(()=>{if(Pi!==`opencode`){It(``),Rt(``),Bt(!1);return}let t=ige({projectId:e,tool:Pi}),n=t?.model??``;It(n),Rt(n?t?.variant??``:``),Bt(!!n)},[e,Pi]),(0,p.useEffect)(()=>{ji||(Wt.current=null,Gt.current=null,qt.current=!1,Jt.current=!1,Qe(!1),et(!1),Qn())},[ji,Qn]),(0,p.useEffect)(()=>()=>{Qn()},[Qn]);let Ri=(0,X.jsx)(vv,{content:q5(`artifactPanel.open`),disabled:!Mi,side:`left`,children:(0,X.jsx)(`div`,{ref:Ht,className:Z(Mi?`group flex shrink-0 touch-none select-none items-center justify-center border-l border-border/70 bg-background/90 text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground xl:w-7 xl:cursor-col-resize`:`group hidden w-5 shrink-0 cursor-col-resize touch-none select-none items-center justify-center border-l border-border/70 bg-background/80 transition-colors xl:flex`,Y&&!Mi&&`bg-background`),role:Mi?`button`:`separator`,tabIndex:Mi?0:void 0,"aria-label":q5(Mi?`artifactPanel.open`:`artifactPanel.resize`),"aria-valuemin":Mi?void 0:t7,"aria-valuemax":Mi?void 0:Vt.current?Math.round(Vt.current.clientWidth*n7):800,"aria-valuenow":Mi?void 0:Xe,onClick:Mi?()=>{if(Jt.current){Jt.current=!1;return}Je(!0)}:void 0,onPointerDown:rr,onPointerMove:ir,onPointerUp:ar,onPointerCancel:or,onLostPointerCapture:sr,children:Mi?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`hidden h-full w-full items-center justify-center xl:flex`,children:(0,X.jsxs)(`span`,{className:`relative flex h-full w-full items-center justify-center`,children:[(0,X.jsx)(`span`,{className:`absolute top-1/2 left-1/2 flex -translate-x-1/2 -translate-y-[2.65rem] items-center justify-center text-sky-400/80 transition-colors group-hover:text-sky-300`,children:(0,X.jsx)(G5,{className:`h-3 w-3 shrink-0`})}),(0,X.jsx)(`span`,{className:`absolute top-1/2 left-1/2 h-14 w-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-muted-foreground/70 transition-colors group-hover:bg-sky-300/90`})]})}),(0,X.jsxs)(`span`,{className:`flex items-center gap-2 text-xs font-medium xl:hidden`,children:[(0,X.jsx)(G5,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{children:q5(`artifactPanel.title`)})]})]}):(0,X.jsx)(`div`,{className:Z(`h-14 w-1.5 rounded-full transition-colors`,Y?`bg-sky-300/90`:`bg-muted-foreground/70 group-hover:bg-sky-300/90`)})})}),zi=F&&br?(0,X.jsx)(kY,{providers:yr,onImported:_r,inputId:`spec-draft-external-import`,className:`max-w-md`,showImportSpinner:!0,showImportErrorToast:!1}):null,Bi=j?j.mode===`grill`:pt,Vi=ri;hn.current=Vi,gn.current=ai;let Hi=(0,X.jsx)(N5,{on:Bi,disabled:ht||Jr||_e||ye||ai||Kr,tooltipContent:q5(`grill.toggleTooltip`),ariaLabelOn:q5(`grill.toggleAriaLabelOn`),ariaLabelOff:q5(`grill.toggleAriaLabelOff`),onToggle:e=>{Er(e)}}),Ui=tge(Sn),Wi=(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[Ui?(0,X.jsxs)(`div`,{className:`rounded-md border border-sky-500/30 bg-sky-500/10 px-3 py-2 text-sm text-sky-950 dark:text-sky-100`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:q5(`importNotice.title`)}),(0,X.jsx)(`div`,{children:Ui})]}):null,(0,X.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[Hi,zi,Ti,F&&t&&(0,X.jsx)(Zy,{activeProject:t,branchState:n,bundles:r,branchSuggestions:i,isBundleLoading:a,isLoading:o,presentation:`composer`,closeAfterSelection:!0,triggerAriaLabel:qb.t(`common:projectTargetSelector.newSpecAriaLabel`),onOpenChange:s,onSelectBundle:c,onSelectRepoRoot:l})]})]}),Gi=Oi,Ki=(0,p.useCallback)(t=>{j?gr(o7({projectId:e,sessionId:j.id})):U(null),fr(yn,t)},[j,e,yn,fr,gr]),qi=(0,X.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:(0,X.jsx)(Ohe,{projectId:e,specSessionId:F?null:k,messages:zr,internalLog:Vr?.agent_log??null,currentThinkingMessageId:Vr?.agent_message_id??null,previousThinkingLog:Vr?.previous_agent_log??null,previousThinkingMessageId:Vr?.previous_agent_message_id??null,pendingAgentTitle:Zr,streamingResponse:qr,isRunning:Xr,isLoading:!F&&he,canShowComposer:$r,isExternallyResizing:Y,layoutKey:j?.id??`spec-draft`,scrollLayoutKey:ji?Ni?`artifact-visible`:`artifact-hidden`:`artifact-disabled`,header:(0,X.jsx)(G8,{title:di,tool:F?null:j?.tool??null,modelLabel:pi,interrupted:mi,interruptedLabel:q5(`sidebar.interrupted`),usage:{totalTokens:j?.usage_snapshot_total_tokens??null,contextWindow:j?.usage_snapshot_context_window??null,cost:j?.usage_snapshot_cost??null,tool:ui,model:fi,availableModels:En},metadataExtra:j?.external_source?(0,X.jsx)(IF,{externalSource:j.external_source}):null,actions:j&&e?(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[ei&&(0,X.jsx)(Q,{type:`button`,size:`xs`,variant:`outline`,className:`gap-2`,onClick:()=>St(!0),children:yt?q5(`composer.loadingMemory`):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{children:q5(`composer.memorySuggestions`)}),(0,X.jsx)(Ew,{children:_t.length})]})}),(0,X.jsx)(V4,{projectId:e,scope:{type:`spec`,id:j.id},size:`xs`,onNavigateToLifecycleSource:b})]}):null,warnings:Ur&&Wr?(0,X.jsx)(`div`,{className:`w-fit max-w-md rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-50`,children:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{children:Wr}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`secondary`,disabled:st===j?.id,onClick:()=>{j&&Kn(j)},children:st===j?.id?q5(`targets.switchingBack`):q5(`targets.switchBack`)}),(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`ghost`,onClick:Vn,children:q5(`composer.startNewSession`)})]})]})}):Hr&&Gr?(0,X.jsx)(`div`,{className:`w-fit max-w-md rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-50`,children:Gr}):null}),composerControls:Wi,composerInlineControls:Gi,composerTheme:`default`,composerFocusNonce:Fe,pendingAgentRevealKey:Xr&&Le?.parentId===k?Le?.turnKey??null:null,pendingAgentRevealDelayMs:Xr&&Le?.parentId===k?400:0,liveResponseTiming:Le,followUpPrompt:xn,draftAttachments:wn,followUpPlaceholder:hi,emptyStateText:null,isSendingFollowUp:ye||_e,isComposerSubmitDisabled:Vi||ai||Kr,isUploadingAttachments:Tn,canAttachImages:ti,followUpDisabledReason:Gr??Wr??(Vr?.agent_status===`running`?q5(`composer.waitTurn`):Tn?q5(`composer.waitUpload`):Vi?q5(`composer.waitGrill`):ai?qb.t(`common:questionSet.waitForResolution`):void 0),renderMessageBody:ci,onFollowUpPromptChange:Ki,onFollowUpKeyDown:Fr,onFollowUpPaste:Ir,onUploadAttachments:e=>{kr(e)},onRemoveAttachment:e=>{jr(e)},onFollowUpSubmit:()=>{Dr()}})}),Ji=!Br&&pe&&!de?(0,X.jsx)(j8,{title:q5(`composer.noSessionSelectedTitle`),description:q5(`composer.noSessionSelectedDescription`),startNewSessionLabel:q5(`composer.startNewSession`),onStartNewSession:Vn,canStartNewSession:!!e&&!_e&&!ye}):Br&&!F&&!he&&!j?(0,X.jsx)(k8,{label:q5(`composer.loadingSession`)}):!pe||de?(0,X.jsx)(A8,{label:q5(`sidebar.loadingSessions`)}):qi,Yi=xt&&e&&t?.memory_enabled?(0,X.jsx)(tC,{onClose:()=>St(!1),overlayClassName:`bg-background/75 p-4`,panelClassName:`w-full max-w-3xl`,renderContent:({closeButton:t})=>(0,X.jsxs)(iC,{size:`sm`,className:`max-h-[calc(100vh-2rem)] w-full gap-0 overflow-hidden border-border/80 bg-card/95 shadow-2xl`,children:[(0,X.jsxs)(aC,{className:`border-b border-border/80 pb-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(oC,{children:q5(`composer.memorySuggestionsTitle`)}),(0,X.jsx)(sC,{children:q5(`composer.memorySuggestionsDescription`)})]}),(0,X.jsx)(cC,{children:t})]}),(0,X.jsx)(lC,{className:`min-h-0 flex-1 overflow-y-auto pt-4`,children:(0,X.jsx)(K8,{projectId:e,suggestions:_t,emptyState:q5(`composer.memorySuggestionsEmpty`),onSuggestionsChanged:Ln})})]}),closeButtonLabel:q5(`composer.closeMemorySuggestions`)}):null,Xi=Ai.length>0?(0,X.jsx)(O8,{count:Ai.length,title:ki,isDeleting:Te.size>0,onConfirm:()=>{lr()},onCancel:()=>{Te.size>0||we([])},labels:vi}):null,Zi=dt===null?null:(0,X.jsx)(nC,{title:q5(`actions.exportConflictTitle`),description:q5(`actions.exportConflictDescription`,{path:dt.path}),confirmLabel:q5(`actions.exportConflictConfirm`),cancelLabel:q5(`actions.exportConflictCancel`),confirmVariant:`destructive`,onConfirm:()=>{ft(null),Zn({projectId:dt.projectId,sessionId:dt.sessionId,snapshotId:dt.snapshotId,overwrite:!0})},onCancel:()=>{ft(null)}});return(0,X.jsxs)(`div`,{"data-testid":`spec-view-shell`,className:`relative flex min-h-0 flex-1 overflow-hidden border-t border-border/70`,children:[(0,X.jsx)(M8,{sessions:D,sessionGroups:Nr,activeSessionId:k,isDraftOpen:F,isLoadingSessions:de,isOpen:Ne,onToggleOpen:()=>{Pe(t=>{let n=!t;return Zhe({projectId:e,isOpen:n}),n})},testId:`spec-sessions-sidebar`,railTestId:`spec-sessions-rail`,onDraftOpen:Vn,isCreatingSession:_e||!e,isSendingPrompt:ye,newSessionShortcutHint:Un,newSessionTooltip:Wn,isSelectionMode:De,selectedSessionIds:ke,selectedSessionCount:ke.size,hasDeletableSessions:gi,deletingSessionIds:Te,onEnterSelectionMode:()=>{Oe(!0),Ae(new Set)},onExitSelectionMode:()=>{Oe(!1),Ae(new Set)},onToggleSessionSelection:e=>{Ae(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},onSetSessionSelection:Mr,onConfirmDeleteSelectedSessions:()=>{we(Array.from(ke))},selectionPresets:Pr,onSessionSelect:e=>{Gn(e)},onConfirmDeleteSession:e=>{we([e])},getSessionId:e=>e.id,getSessionTitle:e=>e.title,getDeleteDisabledReason:bi,getActivityState:yi,getRowAriaLabel:Si,renderRowContent:wi,labels:_i}),(0,X.jsxs)(`div`,{"data-testid":`spec-artifact-split-pane`,ref:Vt,className:`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden xl:flex-row`,children:[(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:Ji}),ji?(0,X.jsxs)(X.Fragment,{children:[Ri,Ni?(0,X.jsx)(Uhe,{snapshot:Be,isLoading:We,desktopWidth:Xe,onClose:cr,ref:Ut,actions:Be?{onCreateTickets:Yn,onImplementInChat:()=>{Xn()},onExport:()=>{Zn()},isCreatingTickets:tt,isImplementingInChat:rt,isExporting:at,hasExistingTicketsFromSnapshot:lt,unavailableReason:Gr,implementInChatUnavailableReason:Be.bundle_groups.length>1?q5(`actions.implementInChatMultiBundleUnavailable`):null}:void 0,review:Li}):null]}):null]}),Yi,Xi,Zi]})},x7=()=>({hasRunning:!1,hasFinishedUnseen:!1,hasErrorUnseen:!1}),S7=()=>({board:x7(),chat:x7(),spec:x7(),memory:x7()}),C7=(e,t)=>{let n=e[t];return!n.hasFinishedUnseen&&!n.hasErrorUnseen?e:{...e,[t]:{...n,hasFinishedUnseen:!1,hasErrorUnseen:!1}}},lge=e=>({hasRunning:e.board.hasRunning||e.chat.hasRunning||e.spec.hasRunning,hasFinishedUnseen:e.board.hasFinishedUnseen||e.chat.hasFinishedUnseen||e.spec.hasFinishedUnseen,hasErrorUnseen:e.board.hasErrorUnseen||e.chat.hasErrorUnseen||e.spec.hasErrorUnseen}),w7=e=>e.hasErrorUnseen?`error`:e.hasRunning?`running`:e.hasFinishedUnseen?`finished`:null,uge=(e,t)=>t?null:w7(e),T7=320,dge=.7,fge=28,pge=6,mge=(e,t)=>{let n=Math.max(T7,Math.round(t*dge));return Math.max(T7,Math.min(n,Math.round(e)))},hge=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);if(n===-1)return[...e,t];let r=e.slice();return r[n]=t,r},gge=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);if(n===-1)return[...e,t];let r=e.slice();return r[n]=t,r},_ge=(e,t)=>{if(t.type===`reset`)return S7();if(t.type===`mark-workspace-visible`)return C7(e,t.workspace);let n=e[t.workspace],r={...n,hasRunning:t.activity.hasRunning,hasFinishedUnseen:t.visibleWorkspace===t.workspace?!1:n.hasFinishedUnseen||t.activity.didFinish,hasErrorUnseen:t.visibleWorkspace===t.workspace?!1:n.hasErrorUnseen||t.activity.didError};return n.hasRunning===r.hasRunning&&n.hasFinishedUnseen===r.hasFinishedUnseen&&n.hasErrorUnseen===r.hasErrorUnseen?e:{...e,[t.workspace]:r}},vge=({activeProjectId:e,onActivity:t})=>{let{tickets:n}=o3(),r=(0,p.useRef)(new Map);return(0,p.useEffect)(()=>{r.current=new Map},[e]),(0,p.useEffect)(()=>{let e=r.current,i=new Map,a=!1,o=!1;for(let t of n){let n=e.get(t.id)??null,r=t.agent_status??null,s=S8(t);!s&&n===`running`&&r===`done`&&(a=!0),n===`running`&&r===`error`&&(o=!0),i.set(t.id,s?n:r)}r.current=i,t({hasRunning:n.some(e=>e.agent_status===`running`||Tme(e)),didFinish:a,didError:o})},[t,n]),null},yge=({activeProjectId:e})=>{let{t}=q(`common`,{keyPrefix:`approvalRequest.notification`}),n=uq(),{setPendingApprovalRequests:r}=o3();return(0,p.useEffect)(()=>{if(!e){r([]);return}let i=new AbortController,a=0,o=async(n,r)=>{if(n.status!==`pending`||i.signal.aborted||r!==void 0&&r!==a)return;let o=(await bN(e,n.id,i.signal)).approval_request;o.status!==`pending`||i.signal.aborted||r!==void 0&&r!==a||await i3({title:t(`title`),body:t(o.action_kind===`git_push`?`forcePush`:`productionCheck`),key:Cde(o),destination:r3(o)})},s=()=>{let t=++a;(async()=>{let t=[],n;do{let r=await yN(e,{statuses:[`pending`],limit:200,cursor:n,signal:i.signal});t.push(...r.approval_requests),n=r.next_cursor??void 0}while(n);return t})().then(e=>{if(!(i.signal.aborted||t!==a))return r(e),Promise.allSettled(e.map(e=>o(e,t)))}).catch(e=>{Ye(e)})},c=t=>{if(!t||typeof t!=`object`)return;let n=t;n.project_id!==e||typeof n.id!=`string`||s()};return s(),n.on(`approval-request:created`,c),n.on(`approval-request:updated`,s),n.on(`connect`,s),()=>{i.abort(),n.off(`approval-request:created`,c),n.off(`approval-request:updated`,s),n.off(`connect`,s)}},[e,r,n,t]),null},bge=({activeProjectId:e,onActivity:t})=>{let n=uq(),[r,i]=(0,p.useState)([]),a=(0,p.useRef)(new Map);return(0,p.useEffect)(()=>{if(!e)return;let t=new AbortController;return(async()=>{try{let n=await uN(e,t.signal);if(t.signal.aborted)return;i(n)}catch(e){Ye(e)}})(),()=>{t.abort()}},[e,n]),(0,p.useEffect)(()=>{if(!e)return;let t=new AbortController,n=hx(()=>{document.visibilityState===`visible`&&uN(e,t.signal).then(e=>{t.signal.aborted||i(e)}).catch(e=>{Ye(e)})});return()=>{t.abort(),n()}},[e,n]),(0,p.useEffect)(()=>{if(!e)return;let t=t=>{!t||t.project_id!==e||i(e=>hge(e,t))},r=t=>{!t||t.project_id!==e||i(e=>e.filter(e=>e.id!==t.id))};return n.on(`chat-session:created`,t),n.on(`chat-session:updated`,t),n.on(`chat-session:deleted`,r),()=>{n.off(`chat-session:created`,t),n.off(`chat-session:updated`,t),n.off(`chat-session:deleted`,r)}},[e,n]),(0,p.useEffect)(()=>{let n=a.current,i=new Map,o=[],s=!1;for(let e of r){let t=n.get(e.id)??null,r=e.agent_status??null;t===`running`&&r===`done`&&o.push(e),t===`running`&&r===`error`&&(s=!0),i.set(e.id,r)}a.current=i;for(let e of o)if(e.title){let t=xde({projectId:e.project_id,chatSessionId:e.id,agentMessageId:e.agent_message_id});t&&i3({title:`Chat response ready`,body:e.title,key:t,destination:{kind:`chat-session`,projectId:e.project_id,chatSessionId:e.id}})}o.length>0&&e&&i6(e),t({hasRunning:r.some(e=>e.agent_status===`running`),didFinish:o.length>0,didError:s})},[e,t,r]),null},xge=({activeProjectId:e,onActivity:t})=>{let n=uq(),[r,i]=(0,p.useState)([]),a=(0,p.useRef)(new Map);return(0,p.useEffect)(()=>{if(!e)return;let t=new AbortController;return(async()=>{try{let n=await pN(e,t.signal);if(t.signal.aborted)return;i(n)}catch(e){Ye(e)}})(),()=>{t.abort()}},[e,n]),(0,p.useEffect)(()=>{if(!e)return;let t=new AbortController,n=hx(()=>{document.visibilityState===`visible`&&pN(e,t.signal).then(e=>{t.signal.aborted||i(e)}).catch(e=>{Ye(e)})});return()=>{t.abort(),n()}},[e,n]),(0,p.useEffect)(()=>{if(!e)return;let t=t=>{!t||t.project_id!==e||i(e=>gge(e,t))},r=t=>{!t||t.project_id!==e||i(e=>e.filter(e=>e.id!==t.id))};return n.on(`spec-session:created`,t),n.on(`spec-session:updated`,t),n.on(`spec-session:deleted`,r),()=>{n.off(`spec-session:created`,t),n.off(`spec-session:updated`,t),n.off(`spec-session:deleted`,r)}},[e,n]),(0,p.useEffect)(()=>{let e=a.current,n=new Map,i=[],o=!1;for(let t of r){let r=e.get(t.id)??null,a=t.agent_status??null;r===`running`&&a===`done`&&i.push(t),r===`running`&&a===`error`&&(o=!0),n.set(t.id,a)}a.current=n;for(let e of i)if(e.title){let t=Sde({projectId:e.project_id,specSessionId:e.id,agentMessageId:e.agent_message_id,latestSnapshotId:e.latest_snapshot_id});t&&i3({title:`Spec response ready`,body:e.title,key:t,destination:{kind:`spec-session`,projectId:e.project_id,specSessionId:e.id}})}t({hasRunning:r.some(e=>e.agent_status===`running`),didFinish:i.length>0,didError:o})},[e,t,r]),null},Sge=({activeProjectId:e,activeProject:t=null,activeProjectBranchState:n=null,targetBundles:r=[],targetBranchSuggestions:i={current_branch:null,default_branch:null,previous_branch:null},isTargetBundleLoading:a=!1,isTargetSelectorLoading:o=!1,onTargetSelectorOpenChange:s,onSelectBundleTarget:c,onSelectRepoRootTarget:l,activeRun:u,activeTool:d,onRestoreSessionTarget:f,onChatReviewCapabilityChange:m,routedInspectionReviewCapability:h,onPreviewReviewCapabilityChange:g,previewDisplayMode:_=`hidden`,previewPane:v=null,previewPaneWidth:y=480,isPreviewButtonDisabled:b=!1,previewButtonTitle:x,visibleWorkspace:S,onProjectUsageChange:C,onBundlesChange:w,onBundlesLoadingChange:T,onBoardLoadedProjectIdChange:E,onPreviewToggle:D,onPreviewPaneWidthChange:O,onRunStopped:k,onRunStatusChange:A,onWorkspaceActivityChange:j,onWorkspaceActivityEvent:M,pendingWorkspaceNavigation:N=null,onPendingWorkspaceNavigationConsumed:P,routedTicketId:F=null,routedModalStack:I=[],onRoutedTicketOpen:L,onRoutedTicketClose:R,onRoutedTicketUnavailable:z,routedBundleId:ee=null,routedChatSessionId:B,routedSpecSessionId:V,routedSpecSnapshotId:H,routedInspection:U=null,onRoutedBundleOpen:W,onRoutedBundleClose:te,onRoutedInspectionOpen:ne,onRoutedInspectionModeChange:re,onRoutedInspectionClose:ie,onChatSessionNavigation:ae,onSpecSessionNavigation:G,onRoutedEntityUnavailable:oe,onSpecImplementationChatReady:se,onViewSourceSpec:ce,onNavigateToLifecycleSource:le,onViewMemorySource:ue,onStartChatFromBundle:de,onOpenProjectExecutionSettings:fe,refreshKey:pe=0,boardFilterState:me,onBoardFilterStateChange:he})=>{let ge=(0,p.useRef)(null),_e=(0,p.useRef)(null),ve=(0,p.useRef)(null),ye=(0,p.useRef)(null),be=(0,p.useRef)(!1),xe=(0,p.useRef)(!1),Se=(0,p.useRef)(0),Ce=(0,p.useRef)(y),we=(0,p.useRef)(y),Te=S===`board`||S===`chat`,Ee=v!==null,[De,Oe]=(0,p.useState)(!1),[ke,Ae]=(0,p.useState)(!1),[je,Me]=(0,p.useState)(y),[Ne,Pe]=(0,p.useReducer)(_ge,void 0,S7),Fe=Te&&Ee&&_===`expanded`,Ie=Te&&Ee&&_===`inline`,Le=Te&&Ee&&_===`hidden`&&!ke,K=(Ie||ke)&&!Fe,Re=Fe||K,ze=Te&&Ee&&!Fe,Be=De?je:y,Ve=S!==`chat`||!K,He=e=>{let t=ve.current,n=ye.current,r=be.current;if(t!==null){if(ve.current=null,ye.current=null,be.current=!1,Oe(!1),Ae(!1),e!==null&&_e.current?.hasPointerCapture(e)&&_e.current.releasePointerCapture(e),n===`collapsed`){if(!r)return;O?.(we.current),D?.();return}O?.(we.current)}},q=e=>{if(!ge.current)return;let t=ge.current.getBoundingClientRect().width,n=mge(e,t);we.current=n,Me(n)},Ue=e=>{O&&(Le&&b||(e.preventDefault(),ve.current=e.pointerId,ye.current=Le?`collapsed`:`inline`,be.current=!1,xe.current=!1,Se.current=e.clientX,Ce.current=Le?0:we.current,Oe(!Le),e.currentTarget.setPointerCapture(e.pointerId)))},We=e=>{if(ve.current!==e.pointerId)return;let t=e.clientX-Se.current,n=Ce.current-t;if(ye.current===`collapsed`){if(!be.current&&n<pge)return;be.current||(be.current=!0,xe.current=!0,Ae(!0),Oe(!0))}q(n)},Ge=e=>{if(ve.current===e.pointerId){if(ye.current===`inline`||be.current){let t=e.clientX-Se.current;q(Ce.current-t)}He(e.pointerId)}},Ke=e=>{ve.current===e.pointerId&&He(e.pointerId)},J=(0,p.useCallback)((e,t)=>{M?.(e,t),Pe({type:`update-workspace`,workspace:e,activity:t,visibleWorkspace:S})},[M,S]);(0,p.useEffect)(()=>{Pe({type:`reset`})},[e]),(0,p.useEffect)(()=>{S!==`memory`&&Pe({type:`mark-workspace-visible`,workspace:S})},[S]),(0,p.useEffect)(()=>{j?.(Ne)},[j,Ne]),(0,p.useEffect)(()=>{De||(we.current=y),!Ee&&(ve.current=null,ye.current=null,be.current=!1,xe.current=!1,we.current=y)},[Ee,De,y]);let qe=()=>{if(xe.current){xe.current=!1;return}b||D?.()},Je=e=>{e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),qe())},Ye=(r=!1)=>(0,X.jsx)(jme,{activeProjectId:e,activeProject:t,activeProjectBranchState:n,activeRun:u,activeTool:d,inspectionOnly:r,onPreviewReviewCapabilityChange:r?void 0:g,onRunStopped:k,onRunStatusChange:A,onViewSourceSpec:ce,onNavigateToLifecycleSource:le,onStartChatFromBundle:de,onOpenProjectExecutionSettings:fe,refreshKey:pe,boardFilterState:me,onBoardFilterStateChange:he,onInitialTicketNavigationUnavailable:z,routedTicketId:F,routedModalStack:I,onTicketOpen:L,onTicketClose:R,routedBundleId:ee,routedInspection:U,routedInspectionReviewCapability:r&&S===`chat`?h:void 0,onBundleOpen:W,onBundleClose:te,onInspectionOpen:ne,onInspectionModeChange:re,onInspectionClose:ie,onInspectionUnavailable:oe,initialImportedDraft:N?.workspace===`board`&&`issueDraft`in N?N.draft:null,onInitialImportedDraftConsumed:P});return(0,X.jsx)(Ame,{activeProjectId:e,refreshKey:pe,onLoadedProjectIdChange:E,onProjectUsageChange:C,onBundlesChange:w,onBundlesLoadingChange:T,children:(0,X.jsxs)(`div`,{ref:ge,className:`flex min-h-0 flex-1 flex-col`,children:[(0,X.jsx)(vge,{activeProjectId:e,onActivity:e=>{J(`board`,e)}}),(0,X.jsx)(yge,{activeProjectId:e}),(0,X.jsx)(bge,{activeProjectId:e,onActivity:e=>{J(`chat`,e)}}),(0,X.jsx)(xge,{activeProjectId:e,onActivity:e=>{J(`spec`,e)}}),S===`spec`?(0,X.jsx)(`div`,{id:`project-workspace-panel-spec`,role:`tabpanel`,"aria-labelledby":`project-workspace-tab-spec`,className:`flex min-h-0 flex-1 flex-col`,children:(0,X.jsx)(cge,{activeProjectId:e,activeProject:t,activeProjectBranchState:n,targetBundles:r,targetBranchSuggestions:i,isTargetBundleLoading:a,isTargetSelectorLoading:o,onTargetSelectorOpenChange:s,onSelectBundleTarget:c,onSelectRepoRootTarget:l,onRestoreSessionTarget:f,activeTool:d,routedSpecSessionId:V,routedSpecSnapshotId:H,initialIssueDraft:N?.workspace===`spec`&&`issueDraft`in N?N.draft:null,onRoutedSpecNavigationUnavailable:oe,onSessionNavigation:G,onInitialIssueDraftConsumed:P,onImplementInChat:se,onNavigateToLifecycleSource:le})}):S===`memory`?(0,X.jsx)(`div`,{id:`project-workspace-panel-memory`,role:`tabpanel`,"aria-labelledby":`project-workspace-tab-memory`,className:`flex min-h-0 flex-1 flex-col`,children:(0,X.jsx)(vhe,{activeProject:t,onNavigateToSource:ue})}):(0,X.jsxs)(`div`,{id:S===`chat`?`project-workspace-panel-chat`:`project-workspace-panel-board`,role:`tabpanel`,"aria-labelledby":S===`chat`?`project-workspace-tab-chat`:`project-workspace-tab-board`,className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,X.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:S===`chat`?(0,X.jsx)(ghe,{activeProjectId:e,activeProject:t,activeProjectBranchState:n,targetBundles:r,targetBranchSuggestions:i,isTargetBundleLoading:a,isTargetSelectorLoading:o,onTargetSelectorOpenChange:s,onSelectBundleTarget:c,onSelectRepoRootTarget:l,activeTool:d,routedChatSessionId:B,initialDraftOpen:N?.workspace===`chat`&&`startNewDraft`in N,onInitialDraftOpenConsumed:P,initialSpecDraft:N?.workspace===`chat`&&`draft`in N?{text:N.draftText,specSessionId:N.specSessionId,specSnapshotId:N.specSnapshotId}:null,onInitialSpecDraftConsumed:P,onRoutedChatNavigationUnavailable:oe,onSessionNavigation:ae,onViewSourceSpec:ce,onNavigateToLifecycleSource:le,isExternallyResizing:De,onRestoreSessionTarget:f,onReviewCapabilityChange:m,showChangesPanel:Ve}):Ye()}),[ze?(0,X.jsx)(vv,{content:b?x??`Preview unavailable`:`Open preview`,disabled:!Le,side:`left`,children:(0,X.jsx)(`div`,{"aria-label":Le?x??`Show preview`:`Resize preview pane`,"aria-orientation":Le?void 0:`vertical`,className:Le?`group flex shrink-0 touch-none select-none items-center justify-center border-l border-border/70 bg-background/90 transition-colors ${b?`cursor-not-allowed text-muted-foreground/60`:`cursor-col-resize text-muted-foreground hover:bg-muted/50 hover:text-foreground`}`:`group flex w-5 shrink-0 cursor-col-resize touch-none select-none items-center justify-center border-l border-border/70 bg-background/80 ${De?`bg-background`:``}`,"data-preview-divider":`true`,"data-testid":Le?`collapsed-preview-rail`:void 0,onLostPointerCapture:Ke,onPointerCancel:Ge,onPointerDown:Ue,onPointerMove:We,onPointerUp:Ge,onClick:Le?qe:void 0,onKeyDown:Le?Je:void 0,ref:_e,role:Le?`button`:`separator`,style:Le?{width:`${fge}px`}:void 0,tabIndex:Le?b?-1:0:void 0,children:Le?(0,X.jsxs)(`span`,{className:`relative flex h-full w-full items-center justify-center`,children:[(0,X.jsx)(`span`,{className:`absolute top-1/2 left-1/2 flex -translate-x-1/2 -translate-y-[2.65rem] items-center justify-center text-sky-400/80 transition-colors group-hover:text-sky-300`,children:(0,X.jsx)(_he,{className:`h-3 w-3 shrink-0`})}),(0,X.jsx)(`span`,{className:`absolute top-1/2 left-1/2 h-14 w-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-muted-foreground/70 transition-colors group-hover:bg-sky-300/90`})]}):(0,X.jsx)(`div`,{className:`h-14 w-1.5 rounded-full transition-colors ${De?`bg-sky-300/90`:`bg-muted-foreground/70 group-hover:bg-sky-300/90`}`})})},`preview-divider`):null,Re?(0,X.jsx)(`div`,{className:Fe?`fixed inset-0 z-50 bg-black/70 p-4 sm:p-6`:`min-h-0 shrink-0 border-l border-border/70 bg-[#11131a]`,style:Fe?void 0:{width:`${Be}px`},children:(0,X.jsx)(`div`,{className:`h-full w-full`,children:v})},`preview-container`):null]]}),S!==`board`&&U&&Ye(!0)]})})},Cge=({isExpanded:e,isVisible:t,project:n,onClose:r,onToggleExpanded:i})=>(0,X.jsx)(`div`,{className:[`fixed inset-x-4 bottom-24 z-40`,e?`top-20`:`h-[min(28rem,calc(100vh-8rem))]`,t?`block`:`hidden`].join(` `),children:(0,X.jsx)(r4,{createSession:()=>Bse(n.id),isExpanded:e,isVisible:t,ariaLabel:`Project terminal for ${n.name}`,title:n.name,closeLabel:`Close terminal`,className:e?`h-full w-full rounded-2xl shadow-2xl`:`mx-auto h-full max-w-6xl shadow-2xl`,onClose:r,onToggleExpanded:i})}),wge=({activeWorkspace:e,activityByWorkspace:t,className:n,memoryEnabled:r=!1,onWorkspaceChange:i})=>{let{t:a}=q(`common`,{keyPrefix:`workspaceTabs`}),o=r?[`board`,`chat`,`spec`,`memory`]:[`board`,`chat`,`spec`],s={board:a(`board`),chat:a(`chat`),spec:a(`spec`),memory:a(`memory`)};return(0,X.jsx)(`div`,{className:Z(`min-w-0 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,n),children:(0,X.jsx)(`div`,{role:`tablist`,"aria-label":a(`ariaLabel`),className:`inline-flex min-w-max items-end gap-1 border-b border-border/70`,children:o.map(n=>{let r=e===n,a=uge(t[n],r),o=n===`board`?`border-sky-300/70 bg-sky-500/8 text-sky-200`:n===`spec`?`border-violet-300/70 bg-violet-500/8 text-violet-200`:n===`memory`?`border-amber-300/70 bg-amber-500/8 text-amber-200`:`border-emerald-300/70 bg-emerald-500/8 text-emerald-200`;return(0,X.jsx)(`button`,{id:`project-workspace-tab-${n}`,type:`button`,role:`tab`,"aria-selected":r,"aria-controls":`project-workspace-panel-${n}`,tabIndex:r?0:-1,className:Z(`cursor-pointer rounded-t-lg border-b-2 px-3 py-2 text-sm font-medium transition-colors duration-150 ease-out focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 sm:px-4 sm:py-2.5 sm:text-[15px]`,r?o:`border-transparent text-muted-foreground hover:border-border hover:bg-background/35 hover:text-foreground`),onClick:()=>i(n),children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[(0,X.jsx)(`span`,{children:s[n]}),(0,X.jsx)(ib,{state:a,className:`mt-0`})]})},n)})})})},E7=32,Tge=5.5,Ege=2,Dge=24,Oge=8,D7=new Map,kge={running:{fill:`#fcd34d`,stroke:`#f59e0b`},finished:{fill:`#34d399`,stroke:`#059669`},error:{fill:`#fb7185`,stroke:`#e11d48`}},O7=e=>e.replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`),k7=e=>{if(!e)return null;let t=e.trim().match(/^([0-9]+(?:\.[0-9]+)?)/);return t?Number(t[1]):null},A7=e=>{let t=new DOMParser().parseFromString(e,`image/svg+xml`);if(t.querySelector(`parsererror`))return null;let n=t.documentElement;if(n.nodeName.toLowerCase()!==`svg`)return null;let r=n.getAttribute(`viewBox`)?.trim(),i=k7(n.getAttribute(`width`)),a=k7(n.getAttribute(`height`)),o=r??(i&&a?`0 0 ${i} ${a}`:`0 0 ${E7} ${E7}`);return`<svg ${[Array.from(n.attributes).filter(e=>![`width`,`height`,`viewBox`,`x`,`y`,`preserveAspectRatio`].includes(e.name)).map(e=>`${e.name}="${O7(e.value)}"`).join(` `),`x="0"`,`y="0"`,`width="${E7}"`,`height="${E7}"`,`viewBox="${O7(o)}"`,`preserveAspectRatio="xMidYMid meet"`].filter(e=>e.length>0).join(` `)}>${n.innerHTML}</svg>`},Age=async e=>{if(!e)return null;let t=D7.get(e);if(t)return t;let n=(async()=>{try{if(e.startsWith(`data:image/svg+xml,`))return A7(decodeURIComponent(e.slice(19)));if(e.startsWith(`data:image/svg+xml;base64,`))return A7(atob(e.slice(26)));let t=await fetch(e);return t.ok?A7(await t.text()):null}catch{return null}})();return D7.set(e,n),n},jge=async(e,t)=>{let{fill:n,stroke:r}=kge[e],i=await Age(t);return i?[`<svg xmlns="http://www.w3.org/2000/svg" width="${E7}" height="${E7}" viewBox="0 0 ${E7} ${E7}">`,i,`<circle cx="${Dge}" cy="${Oge}" r="${Tge}" fill="${n}" stroke="${r}" stroke-width="${Ege}"/>`,`</svg>`].join(``):null},Mge=async(e,t)=>{if(!e)return t;let n=await jge(e,t);return n?`data:image/svg+xml,${encodeURIComponent(n)}`:t},Nge=()=>{let e=document.querySelector(`link[rel="icon"]`);if(e)return e;let t=document.createElement(`link`);return t.rel=`icon`,document.head.appendChild(t),t},j7=({defaultHref:e,state:t})=>{let n=Nge(),r=Number(n.dataset.browserTabActivityRequestId??`0`)+1;if(n.dataset.browserTabActivityState=t??`default`,n.dataset.browserTabActivityRequestId=String(r),!t){if(e){n.href=e;return}n.removeAttribute(`href`);return}Mge(t,e).then(e=>{if(n.dataset.browserTabActivityRequestId===String(r)){if(e){n.href=e;return}n.removeAttribute(`href`)}})},M7=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return t.archonDesktop===!0&&typeof t.modalHasParentEntry==`boolean`&&(t.modalParentDepth===void 0||Number.isInteger(t.modalParentDepth)&&t.modalParentDepth>0)&&(t.modalStack===void 0||Array.isArray(t.modalStack)&&t.modalStack.every(e=>!!e&&typeof e==`object`&&typeof e.kind==`string`&&typeof e.projectId==`string`))},N7=e=>!M7(e)||!e.modalHasParentEntry?0:e.modalParentDepth??1,P7=(e,t,n)=>!t||!n.isModal(t)?[]:M7(e)&&e.modalStack&&e.modalStack.length>0?e.modalStack:[t],F7=(e,t,n)=>({archonDesktop:!0,modalHasParentEntry:e,...t>1?{modalParentDepth:t}:{},...n.length>0?{modalStack:n}:{}}),Pge=(e=q4)=>{let[t,n]=(0,p.useState)(()=>e.parse(window.location.pathname)),[r,i]=(0,p.useState)(()=>{let t=e.parse(window.location.pathname);return t&&e.isModal(t)?[t]:[]}),[a,o]=(0,p.useState)(0),s=(0,p.useRef)(!1);(0,p.useEffect)(()=>{s.current||(s.current=!0,t&&e.isModal(t)&&window.history.replaceState(F7(!1,0,[t]),``,e.build(t)))},[e,t]),(0,p.useEffect)(()=>{let t=()=>{let t=e.parse(window.location.pathname);n(t),i(P7(window.history.state,t,e)),o(e=>e+1)};return window.addEventListener(`popstate`,t),()=>window.removeEventListener(`popstate`,t)},[e]);let c=(0,p.useCallback)(r=>{let a=e.isModal(r)?t&&e.isModal(t)?[...P7(window.history.state,t,e).slice(0,-1),r]:[r]:[],s=e.isModal(r)?N7(window.history.state):0,c=F7(s>0,s,a);window.history.replaceState(c,``,e.build(r)),n(r),i(a),o(e=>e+1)},[e,t]),l=(0,p.useCallback)(r=>{let a=e.isModal(r),s=a?t&&e.isModal(t)?[...P7(window.history.state,t,e),r]:[r]:[];window.history.pushState(F7(a,0,s),``,e.build(r)),n(r),i(s),o(e=>e+1)},[e,t]),u=(0,p.useCallback)(r=>{let a=N7(window.history.state);if(a===0){c(r);return}let s=a>0?a+1:0,l=P7(window.history.state,t,e),u=l.length>0?[...l.slice(0,-1),r]:[r],d=F7(s>0,s,u);window.history.pushState(d,``,e.build(r)),n(r),i(u),o(e=>e+1)},[e,c,t]);return{closeModal:(0,p.useCallback)((t,n)=>{let r=e.parse(window.location.pathname);if(!r||e.build(r)!==e.build(t))return;let i=N7(window.history.state);if(i===1){window.history.back();return}if(i>1){window.history.go(-i);return}let a=e.parent(t),o=n??a;o&&c(o)},[e,c]),modalStack:r,navigationVersion:a,push:l,pushModalSibling:u,replace:c,route:t}},I7=(e,t)=>qb.t(`common:projectFooter.${e}`,t),Fge=(e,t)=>{if(e?.kind===`activity-run`)return e;for(let e=t.length-1;e>=0;--e){let n=t[e];if(n.kind===`activity-run`)return n}return null},Ige=1e3,L7=`archon.active-project-id`,R7=`archon.workspace-by-project`,z7=`archon.preview-mode-by-project`,B7=`archon.dismissed-preview-run-context-by-project`,V7=5e3,H7=`archon.preview-pane-width`,U7=`archon.preview-viewport-preset`,W7=`archon.preview-zoom`,Lge=480,Rge=`responsive`,zge=1,G7={hasMounted:!1,isOpen:!1,isExpanded:!1},K7=`hidden`,Bge=(0,p.lazy)(()=>HW(()=>Promise.resolve().then(()=>U6).then(e=>({default:e.WorkspaceReviewModal})),void 0)),Vge=(0,p.lazy)(()=>HW(()=>import(`./VerificationDialog-CYCrlqmj.js`).then(e=>({default:e.VerificationDialog})),__vite__mapDeps([19,3]))),Hge=(0,p.lazy)(()=>HW(()=>import(`./GitHubActionsDialog-DL1RASVT.js`).then(e=>({default:e.GitHubActionsDialog})),__vite__mapDeps([20,3]))),Uge=(0,p.lazy)(()=>HW(()=>import(`./ActivityView-B00t5YvM.js`).then(e=>({default:e.ActivityView})),[])),q7=e=>{if(!e)return null;try{return JSON.parse(e)}catch{return null}},Wge=e=>{let t=e.startsWith(`/`)?e.slice(1).split(`/`):[];if(t[0]!==`app`||t[1]!==`projects`||!t[2])return null;try{return decodeURIComponent(t[2])||null}catch{return null}},Gge=e=>e?.kind===`workspace`?e.workspace:e?.kind===`chat-session`?`chat`:e?.kind===`spec-session`||e?.kind===`spec-snapshot`?`spec`:`board`,J7=e=>{let t=q7(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(e=>e.length>0):[]},Y7=e=>{let t=q7(e);return Array.isArray(t)?t.flatMap(e=>{if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e,n=typeof t.name==`string`?t.name:``,r=typeof t.cmd==`string`?t.cmd:``,i=typeof t.cwd==`string`?t.cwd:``;return n.trim()===``&&r.trim()===``&&i.trim()===``?[]:[{name:n,cmd:r,cwd:i}]}):[]},Kge=e=>{let t=q7(e);return Array.isArray(t)?t.flatMap(e=>{if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e,n=typeof t.source==`string`?t.source:``,r=typeof t.target==`string`?t.target:``,i=t.mode===`copy`||t.mode===`symlink`?t.mode:`copy`;return n.trim()===``&&r.trim()===``?[]:[{source:n,target:r,mode:i}]}):[]},qge=(e,t)=>{let n=new Set(qC(e)),r=new Set(JC(e)),i=new Set(Fre(e)),a=new Set(Ire(e));return{name:e.name,repoPath:e.repo_path,buildExecutionProvider:e.build_execution_provider??`host`,linkedProjectIds:e.linked_project_ids,runSetup:J7(e.run_setup),runServices:Y7(e.run_services),checkDefinitions:KC(e).map(e=>({id:e.id,name:e.name,category:e.category,command:e.command,cwd:e.cwd??``,timeoutMs:String(e.timeout_ms),runner:e.category===`test`?e.runner:`auto`,consequence:e.consequence??`ordinary`,required:n.has(e.id),preReview:n.has(e.id)&&r.has(e.id),postBuild:i.has(e.id),autoFix:a.has(e.id)})),runIde:e.run_ide??``,previewServiceName:e.preview_service_name??``,previewPath:e.preview_path??``,previewCapabilityMode:e.preview_capability_mode??`auto`,helperModel:e.helper_models?.[t]?.model??(t===`opencode`?e.helper_model:null)??``,helperVariant:e.helper_models?.[t]?.variant??(t===`opencode`?e.helper_variant:null)??``,helperModels:e.helper_models??{},reviewerModel:e.reviewer_models?.[t]?.model??(t===`opencode`?e.reviewer_model:null)??``,reviewerVariant:e.reviewer_models?.[t]?.variant??(t===`opencode`?e.reviewer_variant:null)??``,reviewerModels:e.reviewer_models??{},commitMessageRules:e.commit_message_rules??``,commitAfterEachTicket:e.commit_after_each_ticket,autoParkStaleTickets:e.auto_park_stale_tickets,memoryEnabled:e.memory_enabled,scanIncludeGlobs:e.scan_include_globs??[],scanExcludeGlobs:e.scan_exclude_globs??[],worktreeSync:Kge(e.worktree_sync),specAwareCodeReviewEnabled:e.spec_aware_code_review_enabled,automationDepth:e.automation_depth??`manual`,automationReviewFixEnabled:e.automation_review_fix_enabled??!1,automationPauseOnOpenQuestions:e.automation_pause_on_open_questions??!1,automationReviewSeverity:e.automation_review_severity??`medium`,automationReviewMaxIterations:e.automation_review_max_iterations??3}},X7=e=>{let t=e.previewServiceName?.trim()||null,n=e.previewPath?.trim()||``,r=n===``||n===`/`?null:n,i=t||r||e.previewCapabilityMode===`force_web`||e.previewCapabilityMode===`force_disabled`?e.previewCapabilityMode??`auto`:null;return{name:e.name,repo_path:e.repoPath,build_execution_provider:e.buildExecutionProvider??`host`,linked_project_ids:e.linkedProjectIds,run_setup:e.runSetup.length>0?e.runSetup:null,run_services:e.runServices.length>0?e.runServices.map(e=>({...e.name?{name:e.name}:{},cmd:e.cmd,...e.cwd?{cwd:e.cwd}:{}})):null,check_definitions:(e.checkDefinitions??[]).map(e=>e.category===`test`?{id:e.id,name:e.name,category:`test`,command:e.command,...e.cwd?{cwd:e.cwd}:{},timeout_ms:Number(e.timeoutMs),consequence:`ordinary`,runner:e.runner}:e.category===`custom`?{id:e.id,name:e.name,category:e.category,command:e.command,...e.cwd?{cwd:e.cwd}:{},timeout_ms:Number(e.timeoutMs),consequence:e.consequence??`ordinary`}:{id:e.id,name:e.name,category:e.category,command:e.command,...e.cwd?{cwd:e.cwd}:{},timeout_ms:Number(e.timeoutMs),consequence:`ordinary`}),required_check_definition_ids:(e.checkDefinitions??[]).filter(e=>e.required).map(e=>e.id).sort((e,t)=>e.localeCompare(t)),pre_review_check_definition_ids:(e.checkDefinitions??[]).filter(e=>e.required&&e.preReview).map(e=>e.id).sort((e,t)=>e.localeCompare(t)),post_build_check_definition_ids:(e.checkDefinitions??[]).filter(e=>e.postBuild).map(e=>e.id).sort((e,t)=>e.localeCompare(t)),auto_fix_check_definition_ids:(e.checkDefinitions??[]).filter(e=>e.autoFix).map(e=>e.id).sort((e,t)=>e.localeCompare(t)),run_ide:e.runIde||null,preview_service_name:t,preview_path:r,preview_capability_mode:i,helper_models:e.helperModels??{},reviewer_models:e.reviewerModels??{},commit_message_rules:e.commitMessageRules||null,commit_after_each_ticket:e.commitAfterEachTicket,auto_park_stale_tickets:e.autoParkStaleTickets,memory_enabled:e.memoryEnabled,scan_include_globs:e.scanIncludeGlobs??[],scan_exclude_globs:e.scanExcludeGlobs??[],worktree_sync:e.worktreeSync.length>0?e.worktreeSync.map(e=>({source:e.source,...e.target?{target:e.target}:{},mode:e.mode})):null,spec_aware_code_review_enabled:e.specAwareCodeReviewEnabled,automation_depth:e.automationDepth,automation_review_fix_enabled:e.automationReviewFixEnabled,automation_pause_on_open_questions:e.automationPauseOnOpenQuestions,automation_review_severity:e.automationReviewSeverity,automation_review_max_iterations:e.automationReviewMaxIterations}},Jge=e=>e?J7(e.run_setup).length>0||Y7(e.run_services).length>0||(e.run_ide?.trim().length??0)>0:!1,Z7=(e,t,n)=>`${e} ${e===1?t:n}`,Yge=e=>{if(!e.repo_path_locked)return null;let t=[];return e.ticket_count>0&&t.push(Z7(e.ticket_count,`ticket is attached`,`tickets are attached`)),e.worktree_count>0&&t.push(Z7(e.worktree_count,`worktree exists`,`worktrees exist`)),t.length===0?`Repository path is locked for this project.`:`Repository path is locked because ${t.join(` and `)}.`},Xge=(e,t)=>{if(t.length<=1)return`Keep at least one project in Archon.`;let n=[];e.ticket_count>0&&n.push(Z7(e.ticket_count,`ticket is attached`,`tickets are attached`)),e.worktree_count>0&&n.push(Z7(e.worktree_count,`worktree exists`,`worktrees exist`));let r=t.filter(t=>t.linked_project_ids.includes(e.id)).length;return r>0&&n.push(Z7(r,`project links to it`,`projects link to it`)),n.length===0?null:`This project can't be deleted while ${n.join(` and `)}.`},Zge=(e,t)=>e.id!==t.projectId||e.ticket_count===t.ticketCount&&e.worktree_count===t.worktreeCount&&e.repo_path_locked===t.repoPathLocked?e:{...e,ticket_count:t.ticketCount,worktree_count:t.worktreeCount,repo_path_locked:t.repoPathLocked},Qge=(e,t)=>({projectId:e,branch:t.branch,status:t.status,ahead:t.ahead??0,behind:t.behind??0,hasUpstream:t.has_upstream??!1,canPull:t.can_pull??!1,diffStats:t.diff_stats??null}),Q7=e=>({projectId:e,branch:null,status:`loading`,ahead:0,behind:0,hasUpstream:!1,canPull:!1,diffStats:null}),$7=(e,t)=>t?e[t]??G7:G7,e9=(e,t)=>t?e[t]??K7:K7,$ge=()=>{let e=window.localStorage.getItem(H7),t=Number(e);return Number.isFinite(t)&&t>=320?t:Lge},e_e=()=>{let e=window.localStorage.getItem(U7);return e===`phone`||e===`tablet`||e===`laptop`||e===`responsive`?e:Rge},t_e=()=>{let e=Number(window.localStorage.getItem(W7));return Number.isFinite(e)&&e>0?e:zge},n_e=()=>{let e=q7(window.localStorage.getItem(R7));return!e||typeof e!=`object`||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e).flatMap(([e,t])=>t===`activity`?[[e,`board`]]:t===`board`||t===`chat`||t===`spec`||t===`memory`?[[e,t]]:[]))},r_e=()=>{let e=q7(window.localStorage.getItem(z7));return!e||typeof e!=`object`||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e).filter(([,e])=>e===`hidden`||e===`inline`||e===`expanded`))},i_e=()=>{let e=q7(window.localStorage.getItem(B7));return!e||typeof e!=`object`||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e).filter(([,e])=>typeof e==`string`||e===null))},t9=e=>!!e?.preview_service_name?.trim()&&e?.preview_capability_mode!==`force_disabled`,a_e=({activeRun:e,project:t})=>{if(!e||e.kind!==`project`||!t)return!1;let n=t.active_target_kind??`repo_root`,r=t.active_target_bundle_id??null;return e.project_id===t.id&&(e.target_kind??`repo_root`)===n&&((e.target_kind??`repo_root`)!==`bundle`||e.target_bundle_id===r)},o_e=({activeRun:e,project:t,projectId:n})=>!e||!n?null:e.kind===`ticket`?e.project_id===n?e:null:a_e({activeRun:e,project:t})?e:null,n9=`Project root has uncommitted changes. Confirm branch switch to continue.`,s_e=({activeProject:e,activeProjectBranchState:t,nextTarget:n})=>e?n.kind===`bundle`?e.active_target_kind!==`bundle`||e.active_target_bundle_id!==n.bundleId:e.active_target_kind===`bundle`?!0:n.branch?t?.branch!==n.branch:!1:!1,c_e=()=>{let e=Pge(),t=uq(),{closeModal:n,modalStack:r,navigationVersion:i,push:a,pushModalSibling:o,replace:s,route:c}=e,l=Fge(c,r),[u,d]=(0,p.useState)(`opencode`),[f,m]=(0,p.useState)(Br),[h,g]=(0,p.useState)(!1),[_,v]=(0,p.useState)([]),[y,b]=(0,p.useState)(()=>window.localStorage.getItem(L7)),[x,S]=(0,p.useState)(null),[C,w]=(0,p.useState)(null),[T,E]=(0,p.useState)(null),[D,O]=(0,p.useState)({}),[k,A]=(0,p.useState)({}),[j,M]=(0,p.useState)({}),[N,P]=(0,p.useState)({}),[F,I]=(0,p.useState)({}),[L,R]=(0,p.useState)(r_e),[z,ee]=(0,p.useState)(i_e),[B,V]=(0,p.useState)($ge),[H,U]=(0,p.useState)(e_e),[W,te]=(0,p.useState)(t_e),[ne,re]=(0,p.useState)(null),[ie,ae]=(0,p.useState)({opencode:{models:[],loaded:!1},claude:{models:[],loaded:!1}}),[G,oe]=(0,p.useState)(0),[se,ce]=(0,p.useState)({opencode:{model:``,variant:``},claude:{model:``,variant:``}}),[le,ue]=(0,p.useState)(!1),[de,fe]=(0,p.useState)(null),[pe,me]=(0,p.useState)(`general`),[he,ge]=(0,p.useState)(null),[_e,ve]=(0,p.useState)(!1),[ye,be]=(0,p.useState)({}),[xe,Se]=(0,p.useState)(n_e),[Ce,we]=(0,p.useState)(null),[Te,Ee]=(0,p.useState)(()=>S7()),[De,Oe]=(0,p.useState)(()=>x7()),[ke,Ae]=(0,p.useState)(0),[je,Me]=(0,p.useState)(()=>({query:``,hideStaleTickets:!1,hideBundlesWithPullRequests:!1})),[Ne,Pe]=(0,p.useState)(null),[Fe,Ie]=(0,p.useState)(null),[Le,K]=(0,p.useState)({}),[Re,ze]=(0,p.useState)({}),[Be,Ve]=(0,p.useState)({}),[He,q]=(0,p.useState)({}),[Ue,We]=(0,p.useState)(!1),[Ke,J]=(0,p.useState)(!1),[qe,Je]=(0,p.useState)(!1),[Xe,Ze]=(0,p.useState)(!1),[Y,Qe]=(0,p.useState)(!1),[$e,et]=(0,p.useState)(!1),[tt,nt]=(0,p.useState)(`idle`),[rt,it]=(0,p.useState)(0),[ot,st]=(0,p.useState)(!1),{isGitHubConnected:ct,defaultBaseBranch:lt}=IC(y),[ut,dt]=(0,p.useState)(null),ft=(0,p.useRef)(null),pt=(0,p.useRef)(null),mt=(0,p.useRef)(null),ht=(0,p.useRef)(0),gt=(0,p.useRef)(-1),vt=(0,p.useRef)(!1),yt=(0,p.useRef)(0),bt=(0,p.useRef)(window.localStorage.getItem(L7)),xt=ie[u],St=xt.models,Ct=xt.loaded,wt=se[u].model,Tt=se[u].variant,Et=(0,p.useCallback)(()=>{ae(e=>({...e,[u]:{models:[],loaded:!1}})),oe(e=>e+1)},[u]),Dt=_.find(e=>e.id===y)??null,Ot=!!Dt?.memory_enabled,kt=y?xe[y]??`board`:`board`,At=kt===`memory`?Ot?`memory`:`board`:kt,jt=c?.projectId??Wge(window.location.pathname),Mt=jt?_.find(e=>e.id===jt)??null:null,Nt=c?.kind===`repository-inspection`?c:null,Pt=c?.kind===`workspace`&&c.workspace===`memory`&&Mt?.memory_enabled!==!0,It=tt===`error`,Lt=!!(c&&Mt&&y!==c.projectId),Rt=le&&window.location.pathname.startsWith(`/app`)&&(!c||!Mt||Pt||$e),Bt=_.find(e=>e.id===bt.current)??null,Vt=_[0]??null,Ht=(0,p.useCallback)(t=>{if(!y)return;Se(e=>({...e,[y]:t.workspace})),Ee(e=>C7(e,t.workspace));let n=t.workspace===`board`?{kind:`ticket`,projectId:y,ticketId:t.ticketId}:t.workspace===`chat`?{kind:`chat-session`,projectId:y,chatSessionId:t.chatSessionId}:t.specSnapshotId?{kind:`spec-snapshot`,projectId:y,specSessionId:t.specSessionId,specSnapshotId:t.specSnapshotId}:{kind:`spec-session`,projectId:y,specSessionId:t.specSessionId};if(c?.kind===`activity-run`){e.replace(n);return}e.push(n)},[y,e,c]),Ut=(0,p.useCallback)(t=>{y&&(Se(e=>({...e,[y]:t.workspace})),Ee(e=>C7(e,t.workspace)),we(t),e.push({kind:`workspace`,projectId:y,workspace:t.workspace}))},[y,e]),Gt=(0,p.useCallback)((e,t,n)=>{y&&Ut({workspace:`chat`,draft:!0,draftText:e,specSessionId:t,specSnapshotId:n})},[y,Ut]),Kt=(0,p.useCallback)((e,t)=>{Ht({workspace:`spec`,specSessionId:e,specSnapshotId:t})},[Ht]),Jt=(0,p.useCallback)(e=>{if(e.source_available){if(e.ticket_id){Ht({workspace:`board`,ticketId:e.ticket_id});return}if(e.chat_session_id){Ht({workspace:`chat`,chatSessionId:e.chat_session_id});return}e.spec_session_id&&Ht({workspace:`spec`,specSessionId:e.spec_session_id})}},[Ht]),Yt=(0,p.useCallback)(e=>{if(e.available){if(Je(!1),e.kind===`ticket`){Ht({workspace:`board`,ticketId:e.id});return}if(e.kind===`chat_session`){Ht({workspace:`chat`,chatSessionId:e.id});return}e.kind===`spec_session`&&Ht({workspace:`spec`,specSessionId:e.id})}},[Ht]),Xt=(0,p.useCallback)(e=>{Ut({workspace:`spec`,issueDraft:!0,draft:e})},[Ut]),Zt=(0,p.useCallback)(e=>{Ut({workspace:`board`,issueDraft:!0,draft:e})},[Ut]),Qt=(0,p.useCallback)(()=>{we(null)},[]),$t=Dt!==null,en=Jge(Dt),an=!!Dt?.run_ide?.trim(),on=y!==null&&C===y,sn=y!==null&&(!en||T===y),cn=y?D[y]??Q7(y):null,ln=y?k[y]??null:null,un=y?!!j[y]:!1,dn=y?N[y]??null:null,fn=(0,p.useMemo)(()=>y?Le[y]??[]:[],[y,Le]),pn=y?!!Re[y]:!1,mn=y?Be[y]??{current_branch:null,default_branch:null,previous_branch:null}:{current_branch:null,default_branch:null,previous_branch:null},hn=y?!!He[y]:!1,gn=y?F[y]??null:null,_n=e9(L,y),vn=_n!==`hidden`,yn=o_e({activeRun:x,project:Dt,projectId:y}),bn=yn?.context_key??null,xn=y?z[y]??null:null,Sn=t9(Dt),Cn=bn===ne,wn=(0,p.useMemo)(()=>lge(Te),[Te]),Tn=(0,p.useMemo)(()=>w7({hasRunning:wn.hasRunning,hasFinishedUnseen:De.hasFinishedUnseen,hasErrorUnseen:De.hasErrorUnseen}),[wn.hasRunning,De.hasErrorUnseen,De.hasFinishedUnseen]);(0,p.useEffect)(()=>{Pe(null),Ie(null),pt.current=null},[y]),(0,p.useEffect)(()=>{Ie(null)},[At]),(0,p.useEffect)(()=>{vn||(pt.current=null)},[vn]),(0,p.useEffect)(()=>{let e=Ne?.target?.kind??null;if(e===`ticket`||e===`bundle`){pt.current=Ne;return}(At===`board`||!vn)&&(pt.current=Ne)},[vn,Ne,At]),(0,p.useEffect)(()=>{Ee(S7())},[y]),(0,p.useEffect)(()=>{Oe(x7())},[y]),(0,p.useEffect)(()=>{if(!y||xx(y))return;let e=new AbortController;return at(y,e.signal).then(e=>{bx(y,e.connections)}).catch(e=>{Ye(e)}),()=>{e.abort()}},[y]);let En=(0,p.useCallback)((e,t)=>{document.visibilityState!==`visible`&&(!t.didFinish&&!t.didError||Oe(e=>{let n={...e,hasFinishedUnseen:e.hasFinishedUnseen||t.didFinish,hasErrorUnseen:e.hasErrorUnseen||t.didError};return e.hasFinishedUnseen===n.hasFinishedUnseen&&e.hasErrorUnseen===n.hasErrorUnseen?e:n}))},[]);(0,p.useEffect)(()=>{let e=()=>{document.visibilityState===`visible`&&Oe(e=>!e.hasFinishedUnseen&&!e.hasErrorUnseen?e:{...e,hasFinishedUnseen:!1,hasErrorUnseen:!1})};return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},[]),(0,p.useEffect)(()=>{let e=e=>{e.tool!==`claude`&&e.tool!==`opencode`||(ht.current+=1,d(e.tool),g(!0))};return t.on(`tool:updated`,e),()=>{t.off(`tool:updated`,e)}},[t]),(0,p.useEffect)(()=>(ft.current===null&&(ft.current=document.querySelector(`link[rel="icon"]`)?.getAttribute(`href`)??`/favicon.svg`),j7({defaultHref:ft.current,state:Tn}),()=>{j7({defaultHref:ft.current,state:null})}),[Tn]);let Dn=(0,p.useCallback)(async(e,t={})=>{let{refreshRemote:n=!1,signal:r}=t;try{let t=await $n(e,r,{refreshRemote:n});if(r?.aborted)return;O(n=>({...n,[e]:Qge(e,t)}))}catch(t){if(Ye(t))return;if(t instanceof Ge&&t.status===404){O(t=>({...t,[e]:{...Q7(e),status:`unknown`}}));return}O(t=>({...t,[e]:{projectId:e,branch:t[e]?.branch??null,status:`unknown`,ahead:t[e]?.ahead??0,behind:t[e]?.behind??0,hasUpstream:t[e]?.hasUpstream??!1,canPull:t[e]?.canPull??!1,diffStats:t[e]?.diffStats??null}}))}},[]),On=(0,p.useCallback)(async(e,t={})=>{let{refreshRemote:n=!1,signal:r,suppressLoading:i=!1}=t;i||M(t=>({...t,[e]:!0}));try{let t=await ur(e,{refreshRemote:n,signal:r});if(r?.aborted)return;A(n=>({...n,[e]:t}))}catch(t){if(Ye(t))return;t instanceof Ge&&t.status===404&&A(t=>({...t,[e]:null}))}finally{!r?.aborted&&!i&&M(t=>({...t,[e]:!1}))}},[]),kn=(0,p.useCallback)((e,t)=>{P(n=>({...n,[e]:t}))},[]),jn=(0,p.useCallback)(async(e,t)=>{A(n=>({...n,[e.id]:t})),e.active_target_kind!==`bundle`&&await Dn(e.id),i6(e.id)},[Dn]);(0,p.useEffect)(()=>{let e=new AbortController;return(async()=>{let t=ht.current;try{let{tool:n}=await Ur(e.signal);ht.current===t&&d(n)}catch(e){Ye(e)}finally{e.signal.aborted||g(!0)}})(),Hr(e.signal).then(t=>{e.signal.aborted||m(t.length>0?t:Br())}).catch(()=>{m(Br())}),()=>{e.abort()}},[]),(0,p.useEffect)(()=>{if(!le||_.length>0&&de===null||xt.loaded)return;let e=new AbortController;return(async()=>{try{let t=await Rr(u,e.signal);if(e.signal.aborted)return;ae(e=>({...e,[u]:{models:t,loaded:!0}}))}catch{}finally{e.signal.aborted||ae(e=>({...e,[u]:{...e[u],loaded:!0}}))}})(),()=>{e.abort()}},[xt.loaded,u,G,de,_.length,le]),(0,p.useEffect)(()=>{let e=new AbortController;return(async()=>{try{let t=await Vn(e.signal);if(e.signal.aborted)return;v(t)}catch(e){Ye(e)||v([])}finally{e.signal.aborted||ue(!0)}})(),()=>{e.abort()}},[]),(0,p.useEffect)(()=>{if(!le||gt.current===i)return;gt.current=i,et(!1),nt(`idle`),we(e=>e&&c?.kind===`workspace`&&c.workspace===e.workspace?e:null);let e=r.some(e=>e.kind===`activity-run`),t=r.some(e=>e.kind===`checks`);if(!e&&c?.kind!==`activity-run`&&!vt.current&&Je(!1),!t&&c?.kind!==`checks`&&ge(null),window.location.pathname===`/`){let e=_.find(e=>e.id===bt.current)??_[0]??null;if(!e){b(null);return}let t=xe[e.id]??`board`,n=t===`memory`&&!e.memory_enabled?`board`:t;b(e.id),Se(t=>({...t,[e.id]:n})),s({kind:`workspace`,projectId:e.id,workspace:n});return}if(!c)return;let n=_.find(e=>e.id===c.projectId);if(!n)return;b(n.id);let a=c.kind===`workspace`?c.workspace:c.kind===`ticket`||c.kind===`bundle`?`board`:c.kind===`repository-inspection`||c.kind===`bundle-inspection`||c.kind===`ticket-inspection`?xe[n.id]??`board`:c.kind===`chat-session`?`chat`:c.kind===`spec-session`||c.kind===`spec-snapshot`?`spec`:xe[n.id]??`board`;Se(e=>({...e,[n.id]:a})),vt.current&&c.kind!==`checks`&&(vt.current=!1,Je(!0)),(c.kind===`activity-run`||e)&&Je(!0),J4(c)!==window.location.pathname&&s(c)},[c,r,i,_,le,s,xe]),(0,p.useEffect)(()=>{if(c?.kind!==`checks`||!le)return;let e=_.find(e=>e.id===c.projectId);if(!e)return;let t=new AbortController,n=++yt.current;return nt(`loading`),qt(e.id,c.batchRunId,t.signal).then(({batch:r})=>{t.signal.aborted||yt.current!==n||(ge({projectId:e.id,targetKind:r.target_kind,targetBundleId:r.target_bundle_id,targetLabel:r.target_label??e.name,definitions:r.selected_definition_snapshots,requiredDefinitionIds:[],preReviewDefinitionIds:[]}),nt(`idle`))}).catch(e=>{if(!Ye(e)){if(e instanceof Ge&&e.status===404){et(!0);return}nt(`error`)}}),()=>t.abort()},[c,_,le,rt]),(0,p.useEffect)(()=>{if(st(!1),!y||!ct||Y)return;let e=new AbortController,t=async()=>{try{let t=await Wt(y,e.signal);e.signal.aborted||st(t.activeCount>0)}catch(e){Ye(e)}};t();let n=window.setInterval(()=>{t()},V7);return()=>{e.abort(),window.clearInterval(n)}},[y,Y,ct]),(0,p.useEffect)(()=>{if(le){if(y){bt.current=y,window.localStorage.setItem(L7,y);return}window.localStorage.removeItem(L7)}},[y,le]),(0,p.useEffect)(()=>{window.localStorage.setItem(R7,JSON.stringify(xe))},[xe]),(0,p.useEffect)(()=>{window.localStorage.setItem(z7,JSON.stringify(L))},[L]),(0,p.useEffect)(()=>{window.localStorage.setItem(B7,JSON.stringify(z))},[z]),(0,p.useEffect)(()=>{O(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)}),A(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)}),M(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)})},[_]),(0,p.useEffect)(()=>{be(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)})},[_]),(0,p.useEffect)(()=>{let e=new Set(_.map(e=>e.id));K(t=>Object.fromEntries(Object.entries(t).filter(([t])=>e.has(t)))),ze(t=>Object.fromEntries(Object.entries(t).filter(([t])=>e.has(t)))),Ve(t=>Object.fromEntries(Object.entries(t).filter(([t])=>e.has(t)))),q(t=>Object.fromEntries(Object.entries(t).filter(([t])=>e.has(t))))},[_]),(0,p.useEffect)(()=>{le&&(I(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)}),R(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)}),ee(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)}))},[_,le]),(0,p.useEffect)(()=>{le&&Se(e=>{let t=new Set(_.map(e=>e.id)),n=Object.entries(e).filter(([e])=>t.has(e));return n.length===Object.keys(e).length?e:Object.fromEntries(n)})},[_,le]),(0,p.useEffect)(()=>{if(!le||!y||!$t)return;let e=!1,t=null,n=null;O(e=>e[y]?e:{...e,[y]:Q7(y)});let r=async(r=!1)=>{let i=r?`remote`:`local`;if(t){if(n===`remote`||n===i)return;t.abort()}let a=new AbortController;t=a,n=i;try{await Promise.all([Dn(y,{refreshRemote:r,signal:a.signal}),On(y,{refreshRemote:r,signal:a.signal})])}catch{if(e||a.signal.aborted)return}finally{t===a&&(t=null,n=null)}};r(!1);let i=hx(()=>{document.visibilityState===`visible`&&r(!1)});return()=>{e=!0,t?.abort(),i()}},[y,$t,le,Dn,On]),(0,p.useEffect)(()=>{if(y)return a6(e=>{e===y&&(Dn(e),On(e))})},[y,Dn,On]),(0,p.useEffect)(()=>{if(!y||!$t)return;let e=ln?.operation_state??`idle`;if(!(dn===`rebase`||e!==`idle`))return;let t=!1,n=null,r=null,i=async()=>{r?.abort(),r=new AbortController;try{await On(y,{signal:r.signal,suppressLoading:!0})}catch{}finally{t||(n=window.setTimeout(()=>{i()},Ige))}};return i(),()=>{t=!0,r?.abort(),n!==null&&window.clearTimeout(n)}},[dn,y,ln?.operation_state,$t,On]);let Mn=(0,p.useCallback)(async e=>{let t=y;if(!t){S(null),E(null);return}try{let n=await tn(t,e);e?.aborted||(S(n.active_run),E(t))}catch(e){Ye(e)}},[y]),Nn=(0,p.useCallback)(async e=>{let t=y;if(t)try{let n=await zt(t,e);e?.aborted||I(e=>({...e,[t]:n}))}catch(e){Ye(e)}},[y]);(0,p.useEffect)(()=>{if(!le)return;if(!en){S(null),E(null);return}if(!on)return;let e=new AbortController;E(null),Mn(e.signal);let t=window.setInterval(()=>{Mn(e.signal)},V7),n=hx(()=>{document.visibilityState===`visible`&&Mn(e.signal)});return()=>{e.abort(),window.clearInterval(t),n()}},[on,en,le,Mn]),(0,p.useEffect)(()=>{if(!le||!y||!on||!Sn)return;let e=new AbortController;Nn(e.signal);let t=window.setInterval(()=>{Nn(e.signal)},V7),n=hx(()=>{document.visibilityState===`visible`&&Nn(e.signal)});return()=>{e.abort(),window.clearInterval(t),n()}},[y,on,Sn,le,Nn]),(0,p.useEffect)(()=>{window.localStorage.setItem(H7,String(B))},[B]),(0,p.useEffect)(()=>{window.localStorage.setItem(U7,H)},[H]),(0,p.useEffect)(()=>{window.localStorage.setItem(W7,String(W))},[W]),(0,p.useEffect)(()=>{y&&bn&&ee(e=>{let t=e[y]??null;return!t||t===bn?e:{...e,[y]:null}})},[y,bn]),(0,p.useEffect)(()=>{!y||!yn||!t9(Dt)||xn!==yn.context_key&&R(e=>e9(e,y)===`hidden`?{...e,[y]:`inline`}:e)},[Dt,y,xn,yn]);let Pn=async e=>{let t=ht.current+1;ht.current=t;try{let n=await Wr(e);if(ht.current!==t)return;d(n.tool)}catch{}},Fn=(0,p.useCallback)(e=>{v(t=>t.map(t=>t.id===e.id?e:t))},[]),In=(0,p.useCallback)((e,t)=>{K(n=>{let r=[t,...(n[e]??[]).filter(e=>e.id!==t.id)];return{...n,[e]:r}})},[]),Ln=(0,p.useCallback)(async e=>{q(t=>({...t,[e]:!0}));try{let t=await qn(e);Ve(n=>({...n,[e]:t}))}catch(e){$.error(e instanceof Ge?e.message:`Unable to load the project target options right now.`,{id:`project-target-selector-load-error`})}finally{q(t=>({...t,[e]:!1}))}},[]),Rn=async e=>{try{let t=await Hn(X7(e));return v(e=>[...e,t]),b(t.id),s({kind:`workspace`,projectId:t.id,workspace:`board`}),fe(null),null}catch(e){return e instanceof Ge?e.message:`Unable to create the project right now.`}},zn=async e=>{if(!Dt)return`Select a project before editing settings.`;try{let t=X7(e);delete t.build_execution_provider;let n=await Un(Dt.id,t);return v(e=>e.map(e=>e.id===n.id?n:e)),Ae(e=>e+1),fe(null),null}catch(e){return e instanceof Ge?e.message:`Unable to update the project right now.`}},Bn=async()=>{if(!Dt)return`Select a project before deleting it.`;try{await Gn(Dt.id);let e=_.filter(e=>e.id!==Dt.id);return v(e),b(e[0]?.id??null),e[0]&&s({kind:`workspace`,projectId:e[0].id,workspace:`board`}),fe(null),null}catch(e){return e instanceof Ge?e.message:`Unable to delete the project right now.`}},Qn=(0,p.useCallback)(e=>{v(t=>t.map(t=>Zge(t,e)))},[]),rr=(0,p.useCallback)((e,t)=>{e&&K(n=>({...n,[e]:t}))},[]),ir=(0,p.useCallback)((e,t)=>{e&&ze(n=>({...n,[e]:t}))},[]),ar=async(e,t,n)=>await Yn({repo_path:e,tool:u,helper_models:tw({},u,{model:t||null,variant:t&&n||null})}),or=async()=>(await Xn()).repo_path,sr=(0,p.useCallback)(async e=>{let t=await Zn({repo_path:e});return{valid:t.valid,repoRoot:t.repo_root,error:t.error,willInitialize:t.will_initialize,hasInitialCommit:t.has_initial_commit}},[]),cr=(0,p.useCallback)(async()=>{if(!(!Dt||_e)){ve(!0);try{let e=await Wn(Dt.id);v(t=>t.map(t=>t.id===e.id?e:t)),$.success(`Initial commit created.`,{id:`project-initial-commit-success`}),Dn(e.id),On(e.id)}catch(e){$.error(e instanceof Ge?e.message:`Unable to create the initial commit right now.`,{id:`project-initial-commit-error`})}finally{ve(!1)}}},[Dt,_e,Dn,On]),lr=(0,p.useCallback)((e,t)=>{R(t=>({...t,[e]:`hidden`})),t&&ee(n=>({...n,[e]:t}))},[]),dr=(0,p.useCallback)(()=>{y&&lr(y,bn)},[y,lr,bn]),fr=(0,p.useCallback)(e=>{y&&(R(e=>({...e,[y]:`hidden`})),e&&S(t=>t?.context_key===e?null:t))},[y]),pr=(0,p.useCallback)(async()=>{if(!yn||ne===yn.context_key)return;let{context_key:e}=yn;re(e);try{yn.kind===`ticket`?await An(yn.ticket_id,yn.project_id):S((await rn(yn.project_id)).active_run),fr(e),await Promise.all([Mn(),Nn()])}catch(e){$.error(e instanceof Ge?e.message:`Unable to stop the preview run right now.`,{id:`app-preview-run-stop-error`})}finally{re(t=>t===e?null:t)}},[fr,yn,Nn,Mn,ne]),mr=(0,p.useCallback)(e=>{!e||!y||Ln(y)},[y,Ln]),hr=(0,p.useCallback)(e=>new Promise(t=>{mt.current=t,dt(e)}),[]),gr=(0,p.useCallback)(e=>{let t=mt.current;mt.current=null,dt(null),t?.(e)},[]),_r=(0,p.useCallback)(async e=>{if(!Dt||!y)throw Error(`Select a project first.`);if(!s_e({activeProject:Dt,activeProjectBranchState:cn,nextTarget:e})||!x||x.kind!==`project`||x.project_id!==Dt.id)return!0;if(!await hr({title:`Stop current run and switch target?`,description:`Switching targets will stop the current run and close its preview.`,confirmLabel:`Stop and switch`,cancelLabel:`Keep current target`,confirmVariant:`destructive`}))return!1;try{let e=x.context_key,t=await rn(Dt.id);return fr(e),S(t.active_run),await Nn(),!0}catch(e){return $.error(e instanceof Ge?e.message:`Unable to stop the project run right now.`,{id:`project-target-switch-stop-run-error`}),!1}},[Dt,cn,y,x,fr,Nn,hr]),vr=(0,p.useCallback)(async e=>{if(!y)throw Error(`Select a project first.`);return await _r({kind:`bundle`,bundleId:e})?(Fn(await Jn(y,{kind:`bundle`,bundle_id:e})),A(e=>({...e,[y]:null})),await Promise.all([Dn(y),On(y)]),!0):!1},[y,_r,Dn,On,Fn]),yr=(0,p.useCallback)(async(e,t={})=>{if(!y)throw Error(`Select a project first.`);if(!await _r({kind:`repo_root`,branch:e}))return!1;let n=n=>Jn(y,{kind:`repo_root`,...e?{branch:e}:{},...t.createBranch===!1?{create_branch:!1}:{},...n?{confirm_dirty_switch:!0}:{}}),r;try{r=await n(t.confirmDirtySwitch===!0)}catch(e){if(!t.confirmDirtySwitch&&e instanceof Ge&&e.status===409&&e.message===n9){if(!await hr({title:`Switch repo root branch?`,description:`${n9}\n\nSwitch anyway?`,confirmLabel:`Switch anyway`,cancelLabel:`Keep current branch`}))return!1;r=await n(!0)}else throw e}return Fn(r),A(e=>({...e,[y]:null})),await Promise.all([Dn(y),On(y),Ln(y)]),!0},[y,_r,Ln,Dn,On,Fn,hr]),br=(0,p.useCallback)(async e=>!e.target_kind||e.target_available===!1?!0:e.target_kind===`bundle`?e.target_bundle_id?await vr(e.target_bundle_id):!1:await yr(e.target_branch_snapshot??null,{createBranch:!1}),[vr,yr]),xr=(0,p.useCallback)(async e=>{y&&await vr(e)&&Ut({workspace:`chat`,startNewDraft:!0})},[y,vr,Ut]),Sr=(0,p.useCallback)(()=>{We(!0)},[]),Cr=(0,p.useCallback)(()=>{We(!1)},[]),wr=(0,p.useCallback)(e=>{if(e){vr(e);return}yr(null)},[vr,yr]),Tr=(0,p.useCallback)(async e=>{if(!y)throw Error(`Select a project first.`);let t=await _t(y,{name:e,prepare:!0});return In(y,t),Ae(e=>e+1),t},[y,In]),Er=(0,p.useCallback)(async e=>{if(!y)throw Error(`Select a project first.`);let t=await Ft(y,e);t.warning&&$.warning(t.warning,{id:`bundle-delete-warning`}),K(t=>({...t,[y]:(t[y]??[]).filter(t=>t.id!==e)})),Ae(e=>e+1)},[y]),Dr=(0,p.useCallback)(async()=>{if(!Dt)return;let e=Dt.active_target_kind??`repo_root`,t=Dt.active_target_bundle_id??null,n=x?.kind===`project`&&x.project_id===Dt.id&&(x.target_kind??`repo_root`)===e&&((x.target_kind??`repo_root`)!==`bundle`||x.target_bundle_id===t),r=n?x?.context_key??null:null,i=!n&&t9(Dt)&&_n===`hidden`;i&&(R(e=>({...e,[Dt.id]:`inline`})),ee(e=>({...e,[Dt.id]:null})));try{let e=n?await rn(Dt.id):await nn(Dt.id);n&&fr(r),S(e.active_run),Nn()}catch(e){i&&R(e=>({...e,[Dt.id]:`hidden`})),$.error(e instanceof Ge?e.message:`Unable to update the project run right now.`,{id:`app-project-run-error`})}},[_n,Dt,x,fr,Nn]),Or=(0,p.useCallback)(async()=>{if(!(!Dt||!an))try{await Kn(Dt.id)}catch(e){$.error(e instanceof Error?e.message:`Unable to open the IDE right now.`,{id:`app-project-open-ide-error`})}},[Dt,an]),kr=(0,p.useCallback)(async()=>{if(Dt){kn(Dt.id,`pull`);try{let e=await er(Dt.id);await jn(Dt,e),$.success(e.behind===0?I7(`branchSynced`):I7(`branchUpdated`),{id:`app-project-pull-success`})}catch(e){$.error(e instanceof Ge?e.message:I7(`syncFallbackError`),{id:`app-project-pull-error`})}finally{kn(Dt.id,null)}}},[Dt,jn,kn]),Ar=(0,p.useCallback)(async()=>{if(!Dt)return;let e=ln?.base_branch??null;kn(Dt.id,`rebase`);try{let t=await tr(Dt.id);await jn(Dt,t);let n=t.base_branch??e;$.success(n?I7(`branchRebasedOnto`,{branch:n}):I7(`branchRebased`),{id:`app-project-rebase-success`})}catch(e){await Promise.allSettled([Dn(Dt.id),On(Dt.id,{suppressLoading:!0})]),$.error(e instanceof Ge?e.message:I7(`rebaseFallbackError`),{id:`app-project-rebase-error`})}finally{kn(Dt.id,null)}},[Dt,ln?.base_branch,jn,Dn,On,kn]),jr=(0,p.useCallback)(async()=>{if(Dt){kn(Dt.id,`abort`);try{await jn(Dt,await nr(Dt.id)),$.success(I7(`gitOperationAborted`),{id:`app-project-abort-success`})}catch(e){$.error(e instanceof Ge?e.message:I7(`abortFallbackError`),{id:`app-project-abort-error`})}finally{kn(Dt.id,null)}}},[Dt,jn,kn]),Mr=(0,p.useCallback)(e=>{Dt&&a(Dt.active_target_kind===`bundle`&&Dt.active_target_bundle_id?{kind:`bundle-inspection`,projectId:Dt.id,bundleId:Dt.active_target_bundle_id,mode:e}:{kind:`repository-inspection`,projectId:Dt.id,mode:e})},[Dt,a]),Nr=(0,p.useCallback)(()=>{if(c?.kind!==`repository-inspection`)return;let{projectId:e}=c;n(c,{kind:`workspace`,projectId:e,workspace:`board`}),Dn(e),On(e)},[n,c,Dn,On]),Pr=(0,p.useCallback)(()=>{if(!Dt)return;let e=Dt.active_target_kind??`repo_root`,t=Dt.active_target_bundle_id??null,n=e===`bundle`?fn.find(e=>e.id===t):null,r=n?.required_check_policy;ge({projectId:Dt.id,targetKind:e,targetBundleId:t,targetLabel:n?Jy(n):Dt.name,definitions:KC(Dt),requiredDefinitionIds:r?.required_check_definition_ids??qC(Dt),preReviewDefinitionIds:r?.pre_review_check_definition_ids??JC(Dt)})},[Dt,fn]),Fr=(0,p.useCallback)(()=>{ge(null),c?.kind===`checks`&&n(c)},[n,c]),Ir=(0,p.useCallback)(()=>{Je(!1),ge(null),c?.kind===`activity-run`&&n(c)},[n,c]),Lr=(0,p.useCallback)(()=>{c?.kind===`activity-run`&&(vt.current=!0,n(c))},[n,c]),zr=(0,p.useCallback)(()=>{et(!0)},[]),Vr=(0,p.useCallback)((e,t)=>{if(!y)return;if(e.kind===`check_batch`){a({kind:`checks`,projectId:y,batchRunId:e.id});return}if(e.kind===`check_attempt`&&t){a({kind:`checks`,projectId:y,batchRunId:t,attemptRunId:e.id});return}let n={kind:`activity-run`,projectId:y,runId:e.id};c?.kind===`activity-run`?s(n):a(n)},[y,c,a,s]),Gr=(0,p.useCallback)(e=>{if(!y)return;if(e.kind===`source_batch`||e.kind===`verification_batch`||e.kind===`required_check_gate`){qe&&c?.kind!==`activity-run`&&(vt.current=!0),a({kind:`checks`,projectId:y,batchRunId:e.executionRunId});return}let t={kind:`activity-run`,projectId:y,runId:e.executionRunId};c?.kind===`activity-run`?s(t):a(t)},[y,c,qe,a,s]),Kr=(0,p.useCallback)((e,t)=>{if(!y)return;let n={kind:`checks`,projectId:y,batchRunId:e,attemptRunId:t};if(c?.kind===`checks`){J4(c)!==J4(n)&&s(n);return}a(n)},[y,c,a,s]),qr=$7(ye,y),Jr=Dt?XC(Dt).length>0:!1,Yr=Dt?KC(Dt).length>0:!1,Xr=At===`chat`?Fe:null,Zr=pt.current,Qr=Zr?.target?.kind??null,$r=At===`chat`?Qr===`ticket`||Qr===`bundle`?{target:Zr?.target??null,canSelect:!1,disabledReason:`This preview belongs to a ticket run. Return to Board to send preview comments.`,promptMode:Zr?.promptMode??null,onPromptModeChange:Zr?.onPromptModeChange??null,isUpdatingPromptMode:Zr?.isUpdatingPromptMode??!1,promptPlaceholder:Zr?.promptPlaceholder??null,promptComposerControls:Zr?.promptComposerControls,promptComposerInlineControls:Zr?.promptComposerInlineControls,submitPrompt:null}:Xr?{target:{kind:`chat_session`,id:Xr.chatSessionId??`draft:${y}`},canSelect:Xr.canSubmitReviewPrompt,disabledReason:Xr.canSubmitReviewPrompt?null:Xr.reviewSubmitDisabledReason??`Wait for the current chat turn to finish before sending preview comments.`,promptMode:Xr.mode,onPromptModeChange:Xr.onModeChange,isUpdatingPromptMode:Xr.isUpdatingMode,promptPlaceholder:Xr.promptPlaceholder,promptComposerControls:Xr.promptComposerControls,promptComposerInlineControls:Xr.promptComposerInlineControls,submitPrompt:Xr.canSubmitReviewPrompt?Xr.submitPrompt:null}:{target:null,canSelect:!1,disabledReason:`Select a chat session to send preview comments.`,submitPrompt:null}:Ne,ei=Xr?.canSubmitReviewPrompt??!1,ti=At===`chat`?Xr?Xr.reviewSubmitDisabledReason:`Select a chat session to send review comments.`:qb.t(`common:workspaceReviewModal.chatRequired`),ni=(0,p.useCallback)(()=>{y&&be(e=>{let t=e[y]??G7;return{...e,[y]:{hasMounted:!0,isOpen:!t.isOpen,isExpanded:t.isExpanded}}})},[y]),ri=(0,p.useCallback)(e=>{be(t=>{let n=t[e]??G7;return!n.hasMounted||!n.isOpen?t:{...t,[e]:G7}})},[]),ii=(0,p.useCallback)(e=>{be(t=>{let n=t[e]??G7;return{...t,[e]:{hasMounted:!0,isOpen:n.isOpen,isExpanded:!n.isExpanded}}})},[]),ai=(0,p.useCallback)(()=>{me(`general`),fe(`create`)},[]),oi=(0,p.useCallback)((e=`general`)=>{me(e),fe(`edit`)},[]),si=(0,p.useCallback)(e=>{let t=xe[e.id]??`board`,n=t===`memory`&&!e.memory_enabled?`board`:t;b(e.id),a({kind:`workspace`,projectId:e.id,workspace:n})},[a,xe]),ci=(0,p.useCallback)(e=>{y&&(c?.kind===`ticket`&&c.ticketId===e||a({kind:`ticket`,projectId:y,ticketId:e}))},[y,c,a]),li=(0,p.useCallback)(()=>{c?.kind===`ticket`&&n(c)},[n,c]),ui=(0,p.useCallback)(e=>{y&&(c?.kind===`bundle`&&c.bundleId===e||a({kind:`bundle`,projectId:y,bundleId:e}))},[y,c,a]),di=(0,p.useCallback)(()=>{c?.kind===`bundle`&&n(c)},[n,c]),fi=(0,p.useCallback)((e,t)=>{y&&a(e.kind===`ticket`?{kind:`ticket-inspection`,projectId:y,ticketId:e.ticketId,mode:t}:{kind:`bundle-inspection`,projectId:y,bundleId:e.bundleId,mode:t})},[y,a]),pi=(0,p.useCallback)(e=>{if(c?.kind===`repository-inspection`){if(c.mode===e)return;o({...c,mode:e});return}if(c?.kind===`ticket-inspection`||c?.kind===`bundle-inspection`){if(c.mode===e)return;o({...c,mode:e})}},[c,o]),mi=(0,p.useCallback)(()=>{c?.kind!==`ticket-inspection`&&c?.kind!==`bundle-inspection`||n(c)},[n,c]),hi=(0,p.useCallback)(e=>{if(!y)return;let t=e?{kind:`chat-session`,projectId:y,chatSessionId:e}:{kind:`workspace`,projectId:y,workspace:`chat`};c&&J4(c)===J4(t)||a(t)},[y,c,a]),gi=(0,p.useCallback)(e=>{if(!y)return;let t=e?{kind:`spec-session`,projectId:y,specSessionId:e}:{kind:`workspace`,projectId:y,workspace:`spec`};c&&J4(c)===J4(t)||a(t)},[y,c,a]),_i=(0,p.useCallback)(()=>{if(y){if(vn){dr();return}R(e=>({...e,[y]:`inline`})),ee(e=>({...e,[y]:null}))}},[y,dr,vn]),vi=(0,p.useCallback)(()=>{y&&R(e=>{let t=e9(e,y);return{...e,[y]:t===`expanded`?`inline`:`expanded`}})},[y]),yi=Dt?Dt.preview_service_name?.trim()?Dt.preview_capability_mode===`force_disabled`?`Preview is disabled for this project.`:gn?.state===`unsupported`?gn.message??`Preview is unavailable for this project.`:vn?`Hide preview`:`Show preview`:`Choose a named preview service in project settings first.`:`Select a project first.`,bi=!Dt||!Dt.preview_service_name?.trim()||Dt.preview_capability_mode===`force_disabled`||gn?.state===`unsupported`,xi=Dt&&Dt.preview_service_name?.trim()?(0,X.jsx)(bae,{project:Dt,mode:_n===`expanded`?`expanded`:`inline`,status:gn,viewportPreset:H,zoom:W,activeRun:yn,reviewCapability:$r,isStoppingActiveRun:Cn,onHide:dr,onStopActiveRun:()=>{pr()},onToggleExpanded:vi,onViewportPresetChange:U,onZoomChange:te}):null;return(0,X.jsxs)(`div`,{className:`flex h-screen flex-col overflow-hidden bg-[linear-gradient(180deg,_rgba(15,16,21,1),_rgba(9,10,14,1))] text-foreground`,children:[(0,X.jsx)(px,{}),_.length>0&&(0,X.jsx)(`header`,{className:`border-b border-border bg-background/95 px-6 py-3 backdrop-blur`,children:(0,X.jsxs)(`div`,{className:`grid items-start gap-3 [grid-template-columns:minmax(0,1fr)_auto] min-[1440px]:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] min-[1440px]:items-center`,children:[(0,X.jsx)(`div`,{className:`min-w-0`,children:(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`min-w-0 w-full sm:w-[20rem] sm:min-w-[20rem] sm:max-w-[20rem]`,children:(0,X.jsx)(Rte,{activeProjectId:y,onCreateProject:ai,projects:_,onEditProject:()=>oi(),onProjectChange:e=>{let t=_.find(t=>t.id===e);t&&si(t)}})}),y&&(0,X.jsx)(Ine,{projectId:y,onStartSpecFromDraft:Xt,onCreateTicketFromDraft:Zt})]})}),(0,X.jsx)(`div`,{className:`min-w-0 justify-self-end min-[1440px]:col-start-3 min-[1440px]:row-start-1`,children:(0,X.jsx)(Ub,{activeTool:u,agents:f,onMobileAccessOpen:()=>J(!0),onOpenActivity:()=>Je(!0),onOpenExecutionRuntimes:()=>Ze(!0),onToolChange:Pn,...ct?{hasActiveGitHubRuns:ot,onOpenGitHubActions:()=>Qe(!0)}:{}})}),y&&(0,X.jsx)(`div`,{className:`col-span-2 flex min-w-0 justify-center min-[1440px]:col-span-1 min-[1440px]:col-start-2 min-[1440px]:row-start-1 min-[1440px]:justify-self-center`,children:(0,X.jsx)(wge,{activeWorkspace:At,activityByWorkspace:Te,className:`w-fit max-w-full`,memoryEnabled:Ot,onWorkspaceChange:e=>{y&&(Se(t=>({...t,[y]:e})),Ee(t=>C7(t,e)),a({kind:`workspace`,projectId:y,workspace:e}))}})})]})}),!le||Lt?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:`Loading projects...`}):Rt||It?(0,X.jsx)(Ite,{isTransientError:It,requestedProjectExists:Mt!==null,retainedProject:Bt?.id===Mt?.id?null:Bt,defaultProject:Vt,onCreateProject:ai,onRetry:()=>it(e=>e+1),onOpenProject:e=>{let t=xe[e.id]??`board`,n=t===`memory`&&!e.memory_enabled?`board`:t;b(e.id),s({kind:`workspace`,projectId:e.id,workspace:n})},onOpenWorkspace:()=>{if(!Mt)return;let e=Gge(c),t=e===`memory`&&!Mt.memory_enabled?`board`:e;b(Mt.id),s({kind:`workspace`,projectId:Mt.id,workspace:t})}}):_.length===0?(0,X.jsx)(Fte,{activeTool:u,agents:f,availableHelperModels:St,helperModel:wt,helperVariant:Tt,isHelperModelsLoaded:Ct,isToolLoaded:h,onCreateProject:ai,onHelperModelChange:e=>{ce(t=>({...t,[u]:{model:e,variant:``}}))},onHelperVariantChange:e=>{ce(t=>({...t,[u]:{...t[u],variant:e}}))},onToolChange:Pn}):(0,X.jsxs)(X.Fragment,{children:[Dt?.has_initial_commit===!1&&(0,X.jsx)(Lne,{isSubmitting:_e,onCreateInitialCommit:()=>{cr()}}),(0,X.jsx)(Sge,{activeProjectId:y,activeProject:Dt,activeProjectBranchState:cn,targetBundles:fn,targetBranchSuggestions:mn,isTargetBundleLoading:pn,isTargetSelectorLoading:hn,onTargetSelectorOpenChange:mr,onSelectBundleTarget:vr,onSelectRepoRootTarget:yr,activeRun:x,activeTool:u,onOpenProjectExecutionSettings:()=>oi(`execution`),onRestoreSessionTarget:br,onChatReviewCapabilityChange:Ie,routedInspectionReviewCapability:At===`chat`?Fe:null,isPreviewButtonDisabled:bi,onPreviewReviewCapabilityChange:Pe,onPreviewToggle:_i,onRunStopped:fr,onWorkspaceActivityChange:Ee,onWorkspaceActivityEvent:En,pendingWorkspaceNavigation:Ce,onPendingWorkspaceNavigationConsumed:Qt,routedTicketId:c?.kind===`ticket`?c.ticketId:null,routedModalStack:r,onRoutedTicketOpen:ci,onRoutedTicketClose:li,onRoutedTicketUnavailable:zr,routedBundleId:c?.kind===`bundle`?c.bundleId:null,routedChatSessionId:c?.kind===`chat-session`?c.chatSessionId:void 0,routedSpecSessionId:c?.kind===`spec-session`||c?.kind===`spec-snapshot`?c.specSessionId:void 0,routedSpecSnapshotId:c?.kind===`spec-snapshot`?c.specSnapshotId:void 0,routedInspection:c?.kind===`ticket-inspection`?{target:{kind:`ticket`,ticketId:c.ticketId},mode:c.mode}:c?.kind===`bundle-inspection`?{target:{kind:`bundle`,bundleId:c.bundleId},mode:c.mode}:null,onRoutedBundleOpen:ui,onRoutedBundleClose:di,onRoutedInspectionOpen:fi,onRoutedInspectionModeChange:pi,onRoutedInspectionClose:mi,onChatSessionNavigation:hi,onSpecSessionNavigation:gi,onRoutedEntityUnavailable:zr,onSpecImplementationChatReady:Gt,onViewSourceSpec:Kt,onNavigateToLifecycleSource:Yt,onViewMemorySource:Jt,onStartChatFromBundle:xr,previewDisplayMode:_n,previewPane:xi,previewPaneWidth:B,previewButtonTitle:yi,visibleWorkspace:At,refreshKey:ke,boardFilterState:je,onBoardFilterStateChange:Me,onBoardLoadedProjectIdChange:w,onBundlesChange:rr,onBundlesLoadingChange:ir,onPreviewPaneWidthChange:V,onProjectUsageChange:Qn,onRunStatusChange:()=>{Mn(),Nn()}},y??`no-project`)]}),_.length>0&&(0,X.jsx)($y,{activeProject:Dt,activeRun:x,branchState:cn,targetGitStatus:ln,isBoardLoadedForActiveProject:on,activeProjectBranchAction:dn,isProjectIdeAvailable:an,isProjectRunAvailable:en,isRunStatusLoadedForActiveProject:sn,isTerminalOpen:qr.isOpen,targetBundles:fn,targetBranchSuggestions:mn,isTargetBundleLoading:pn,isTargetSelectorLoading:hn,isTargetGitStatusLoading:un,hasConfiguredTests:Jr,hasConfiguredChecks:Yr,onProjectIdeOpen:()=>{Or()},onProjectPull:()=>{kr()},onProjectRebase:Ar,onProjectAbortGitOperation:jr,onProjectRunToggle:()=>{Dr()},onProjectFilesOpen:()=>Mr(`files`),onProjectChangesOpen:()=>Mr(`changes`),onProjectVerificationOpen:Pr,onTerminalToggle:ni,onTargetSelectorOpenChange:mr,onSelectBundleTarget:vr,onSelectRepoRootTarget:yr,onManageBundles:Sr}),(0,X.jsx)(Dre,{activeProjectId:y,open:Ke,onOpenChange:J}),(qe||l)&&y&&!Rt&&(0,X.jsx)(p.Suspense,{fallback:null,children:(0,X.jsx)(Uge,{projectId:y,initialRunId:l?.runId??null,initialEventId:l?.eventId??null,onClose:Ir,onDetailsClose:Lr,onRunSelectionChange:Vr,onRelatedReferenceSelection:Gr,onUnavailable:c?.kind===`activity-run`?zr:void 0,onNavigateToLifecycleSource:Yt})}),Y&&y&&(0,X.jsx)(p.Suspense,{fallback:null,children:(0,X.jsx)(Hge,{projectId:y,defaultBranch:lt,onClose:()=>Qe(!1)})}),Ue&&Dt&&(0,X.jsx)(mC,{bundles:fn,selectedBundleId:Dt.active_target_kind===`bundle`?Dt.active_target_bundle_id??null:null,activeTargetBundleId:Dt.active_target_kind===`bundle`?Dt.active_target_bundle_id??null:null,onSelectBundle:wr,onCreateBundle:Tr,onDeleteBundle:Er,onClose:Cr}),ut&&(0,X.jsx)(nC,{title:ut.title,description:ut.description,confirmLabel:ut.confirmLabel,cancelLabel:ut.cancelLabel,confirmVariant:ut.confirmVariant,onConfirm:()=>gr(!0),onCancel:()=>gr(!1)}),_.map(e=>{let t=$7(ye,e.id);return t.hasMounted?(0,X.jsx)(Cge,{project:e,isExpanded:t.isExpanded,isVisible:e.id===y&&t.isOpen,onClose:()=>ri(e.id),onToggleExpanded:()=>ii(e.id)},e.id):null}),de&&(0,X.jsx)(eD,{activeTool:u,activeAgentName:f.find(e=>e.id===u)?.displayName??u,mode:de,initialSection:pe,projectId:de===`edit`&&Dt?Dt.id:null,availableHelperModels:St,isLoadingHelperModels:!Ct,onRetryValidationModels:Et,isAutoConfigReady:h,initialValues:de===`edit`&&Dt?qge(Dt,u):_.length===0?{name:``,repoPath:``,linkedProjectIds:[],runSetup:[],runServices:[],checkDefinitions:[],runIde:``,previewServiceName:``,previewPath:``,previewCapabilityMode:`auto`,helperModel:wt,helperVariant:Tt,helperModels:tw({},u,{model:wt||null,variant:wt&&Tt||null}),reviewerModels:{},commitMessageRules:``,commitAfterEachTicket:!1,autoParkStaleTickets:!1,memoryEnabled:!1,worktreeSync:[],specAwareCodeReviewEnabled:!1,automationDepth:`manual`,automationReviewFixEnabled:!1,automationPauseOnOpenQuestions:!1,automationReviewSeverity:`medium`,automationReviewMaxIterations:3}:void 0,linkedProjectOptions:_.filter(e=>e.id!==Dt?.id).map(e=>({id:e.id,name:e.name})),repoPathLocked:de===`edit`&&Dt?Dt.repo_path_locked:!1,repoPathLockedMessage:de===`edit`&&Dt?Yge(Dt):null,deleteBlockedMessage:de===`edit`&&Dt?Xge(Dt,_):null,onDelete:de===`edit`?Bn:void 0,onAutoConfig:ar,onBrowseRepoPath:or,onValidateRepoPath:sr,onOpenExecutionRuntimes:()=>Ze(!0),onExecutionProfileSaved:(e,t)=>{v(n=>n.map(n=>n.id===e?{...n,build_execution_provider:t}:n))},onClose:()=>fe(null),onSubmit:de===`edit`?zn:Rn}),Xe&&(0,X.jsx)(ux,{onClose:()=>Ze(!1)}),Nt&&Nt.projectId===y&&Dt&&cn?.status!==`loading`&&!Rt&&(0,X.jsx)(p.Suspense,{fallback:null,children:(0,X.jsx)(Bge,{target:{scope:`project_root`},initialMode:Nt.mode,reviewMode:Nt.mode,onReviewModeChange:pi,enabledModes:[`changes`,`files`],projectId:Nt.projectId,targetKind:`repo_root`,reviewCommentsBundleId:null,title:Dt.name,bundleTargetName:null,hasHelperModel:!!(Dt.helper_models?.[u]?.model??(u===`opencode`?Dt.helper_model:null)),repoRootDefaultBranch:mn.default_branch,onSubmitReviewPrompt:Xr?.submitPrompt,canSubmitReviewPrompt:ei,reviewSubmitDisabledReason:ti??void 0,canAddReviewComments:ei,canModifyChanges:!0,mode:Xr?.mode,onModeChange:Xr?.onModeChange,canToggleMode:!!Xr?.canSubmitReviewPrompt,isUpdatingMode:Xr?.isUpdatingMode??!1,onClose:Nr})}),he&&(!qe||c?.kind===`checks`)&&!Rt&&he.projectId===y&&(0,X.jsx)(p.Suspense,{fallback:null,children:(0,X.jsx)(Vge,{targetLabel:he.targetLabel,definitions:he.definitions,requiredDefinitionIds:he.requiredDefinitionIds,preReviewDefinitionIds:he.preReviewDefinitionIds,checksTarget:{projectId:he.projectId,targetKind:he.targetKind,targetBundleId:he.targetBundleId},requestedInitialTab:c?.kind===`checks`?`checks`:void 0,directBatchRunId:c?.kind===`checks`?c.batchRunId:null,directAttemptRunId:c?.kind===`checks`?c.attemptRunId:null,onCheckSelectionChange:c?.kind===`checks`?Kr:void 0,onUnavailable:c?.kind===`checks`?zr:void 0,testsTarget:{scope:`project`,projectId:he.projectId,targetKind:he.targetKind,targetBundleId:he.targetBundleId},onClose:Fr,onOpenActivity:()=>{if(yt.current+=1,ge(null),c?.kind===`checks`){r.some(e=>e.kind===`activity-run`)?(Je(!0),n(c)):(vt.current=!0,s({kind:`workspace`,projectId:c.projectId,workspace:`board`}));return}Je(!0)}})})]})},r9=`X-Archon-Mobile-CSRF`,l_e=async(e,t={})=>{let n=await fetch(e,{credentials:`include`,...t});if(!n.ok){let e=null;try{e=await n.clone().json()}catch{}throw new Ge(await Xe(n,`Mobile request failed.`),n.status,e)}return n},i9=async(e,t={})=>await(await l_e(e,t)).json(),a9=e=>i9(`/mobile/projects`,{signal:e}),u_e=e=>i9(`/mobile/tool`,{signal:e}),d_e=(e,t)=>i9(`/mobile/tool`,o9(t,{tool:e})),f_e=async e=>Vr(await i9(`/mobile/agents`,{signal:e,cache:`no-store`})),p_e=(e,t)=>i9(`/mobile/projects/${encodeURIComponent(e)}/summary`,{signal:t}),m_e=async(e,t)=>{let n=[],r=null;do{let i=r?`?cursor=${encodeURIComponent(r)}`:``,a=await i9(`/mobile/projects/${encodeURIComponent(e)}/approval-requests${i}`,{signal:t});n.push(...a.approval_requests),r=a.next_cursor}while(r);return{approval_requests:n,next_cursor:null}},h_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/approval-requests/${encodeURIComponent(t)}`,{signal:n}),g_e=(e,t,n,r,i)=>i9(`/mobile/projects/${encodeURIComponent(e)}/approval-requests/${encodeURIComponent(t.id)}/${n}`,o9(r,{expected_action_fingerprint:t.action_fingerprint,...i?.trim()?{reason:i.trim()}:{}})),__e=(e,t)=>i9(`/mobile/projects/${encodeURIComponent(e)}/target-options`,{signal:t}),v_e=(e,t)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions`,{signal:t}),y_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions/${encodeURIComponent(t)}`,{signal:n}),b_e=(e,t)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets`,{signal:t}),x_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}`,{signal:n}),S_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/agent-runs`,{signal:n}),C_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions/${encodeURIComponent(t)}/agent-runs`,{signal:n}),w_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions/${encodeURIComponent(t)}/agent-runs`,{signal:n}),T_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/bundles/${encodeURIComponent(t)}`,{signal:n}),E_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/bundles/${encodeURIComponent(t)}/build`,o9(n)),D_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/bundles/${encodeURIComponent(t)}/review`,o9(n)),o9=(e,t,n=`POST`)=>({method:n,headers:{"Content-Type":`application/json`,[r9]:e},body:t===void 0?void 0:JSON.stringify(t)}),O_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions`,o9(t,n)),k_e=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions/${encodeURIComponent(t)}/messages`,o9(n,r)),A_e=(e,t,n,r,i)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions/${encodeURIComponent(t)}/plan-questions/${encodeURIComponent(n)}/resolve`,o9(r,i)),j_e=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions/${encodeURIComponent(t)}`,o9(n,r,`PATCH`)),M_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/chat-sessions/${encodeURIComponent(t)}/stop`,o9(n)),N_e=(e,t)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions`,{signal:t}),P_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions/${encodeURIComponent(t)}`,{signal:n}),F_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions`,o9(t,n)),s9=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions/${encodeURIComponent(t)}/messages`,o9(n,r)),I_e=(e,t,n,r,i)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions/${encodeURIComponent(t)}/plan-questions/${encodeURIComponent(n)}/resolve`,o9(r,i)),L_e=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions/${encodeURIComponent(t)}`,o9(n,r,`PATCH`)),R_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/spec-sessions/${encodeURIComponent(t)}/stop`,o9(n)),c9=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/state`,o9(n,{state:r},`PATCH`)),z_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/run`,o9(n)),B_e=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/stop`,o9(n)),l9=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/stop-build`,o9(n)),u9=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/resume-build`,o9(n)),V_e=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}`,o9(n,r,`PATCH`)),H_e=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/plan-follow-up`,o9(n,{instruction:r})),U_e=(e,t,n,r,i)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/plan-questions/${encodeURIComponent(n)}/resolve`,o9(r,i)),W_e=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/tickets/${encodeURIComponent(t)}/follow-up`,o9(n,{instruction:r})),G_e=(e,t,n,r)=>i9(`/mobile/projects/${encodeURIComponent(e)}/bundles/${encodeURIComponent(t)}/follow-up`,o9(n,{instruction:r})),d9=(e,t,n)=>i9(`/mobile/projects/${encodeURIComponent(e)}/target`,o9(t,n)),K_e=(e,t)=>i9(`/mobile/models?tool=${encodeURIComponent(e)}`,{signal:t}),q_e=(e,t,n)=>{let r=new URLSearchParams({tool:e});return t&&r.set(`project_id`,t),i9(`/mobile/skills?${r.toString()}`,{signal:n})},J_e=({className:e})=>(0,X.jsx)(bg,{"aria-hidden":`true`,className:e}),f9=e=>qb.t(`common:mobileApp.${e}`),Y_e={key:`overview`,label:f9(`navigation.overview`),Icon:J_e},p9={key:`tickets`,label:f9(`navigation.tickets`),Icon:B5,ctaAriaLabel:f9(`overviewActions.ticketsAriaLabel`)},m9={key:`chats`,label:f9(`navigation.chats`),Icon:vD,ctaAriaLabel:f9(`overviewActions.chatsAriaLabel`)},h9={key:`spec`,label:f9(`navigation.spec`),Icon:JS,ctaAriaLabel:f9(`overviewActions.specAriaLabel`)},X_e=[Y_e,p9,m9,h9],Z_e=({children:e})=>(0,X.jsx)(`main`,{className:`min-h-screen bg-background text-foreground`,children:(0,X.jsx)(`div`,{className:`mx-auto flex min-h-screen w-full max-w-lg items-center px-4 py-8`,children:(0,X.jsx)(`div`,{className:`w-full`,children:e})})}),g9=({title:e,description:t,children:n})=>(0,X.jsx)(Z_e,{children:(0,X.jsxs)(iC,{className:`w-full border-border/80 bg-card/90 shadow-2xl shadow-black/20`,children:[(0,X.jsxs)(aC,{children:[(0,X.jsx)(oC,{children:e}),(0,X.jsx)(sC,{children:t})]}),n&&(0,X.jsx)(lC,{className:`space-y-4`,children:n})]})}),Q_e=e=>e===`connected`?{label:`Connected`,variant:`success`,indicatorState:`finished`}:e===`reconnecting`?{label:`Reconnecting`,variant:`warning`,indicatorState:`running`}:e===`unavailable`?{label:`Offline`,variant:`destructive`,indicatorState:`error`}:{label:`Connecting`,variant:`outline`,indicatorState:`running`},$_e=({status:e})=>{let t=Q_e(e);return(0,X.jsxs)(rC,{variant:t.variant,className:`gap-1.5 px-2.5 py-1 text-[11px] uppercase tracking-[0.14em]`,children:[(0,X.jsx)(ib,{state:t.indicatorState,className:`mt-0`}),t.label]})},eve=({status:e,onRetry:t})=>e===`connected`?null:e===`unavailable`?(0,X.jsx)(iC,{className:`border-red-500/25 bg-destructive/10 shadow-none`,children:(0,X.jsxs)(lC,{className:`flex flex-col gap-3 pt-5`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-red-100`,children:`Desktop Archon is currently unreachable.`}),(0,X.jsx)(`p`,{className:`text-sm text-red-200/85`,children:`Mobile access may have been disabled, the backend may have restarted, or this phone lost network access.`})]}),(0,X.jsx)(`div`,{children:(0,X.jsx)(Q,{variant:`warning`,onClick:t,children:`Retry connection`})})]})}):(0,X.jsx)(iC,{className:`border-amber-500/25 bg-amber-500/10 shadow-none`,children:(0,X.jsx)(lC,{className:`pt-5 text-sm text-amber-100`,children:e===`connecting`?`Connecting to live updates from desktop Archon...`:`Reconnecting to desktop Archon. Existing content stays visible while this phone reconnects.`})}),tve=({activeTool:e,agents:t,selectedProject:n,targetLabel:r,isTargetLoading:i,isTargetDisabled:a,connectionState:o,onOpenProjects:s,onOpenTargetSelector:c,onToolChange:l})=>(0,X.jsx)(`header`,{className:`sticky top-0 z-20 border-b border-border/70 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/85`,children:(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-6xl items-center justify-between gap-3 px-3 pb-3 pt-4 sm:px-4`,children:[(0,X.jsxs)(`button`,{type:`button`,"aria-label":`Choose project`,className:`min-w-0 flex-1 text-left`,onClick:s,children:[(0,X.jsx)(`div`,{className:`truncate text-base font-medium text-foreground`,children:n?.name??`Choose a project`}),(0,X.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:n?.repo_path??`Select a desktop project to continue`})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,X.jsx)(`select`,{"aria-label":qb.t(`common:mobileApp.agentSelector.ariaLabel`),className:`h-8 max-w-28 rounded-lg border border-border bg-background px-2 text-xs text-foreground outline-none focus-visible:ring-2 focus-visible:ring-ring`,value:e,onChange:e=>l(e.target.value),children:t.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.displayName},e.id))}),(0,X.jsx)($_e,{status:o}),(0,X.jsxs)(Q,{variant:`outline`,size:`sm`,"aria-label":`Choose target`,"data-testid":`mobile-target-trigger`,className:`h-8 max-w-32 gap-2 px-2.5 sm:max-w-40`,disabled:a,onClick:c,children:[(0,X.jsx)(zv,{className:`h-3.5 w-3.5 shrink-0`}),i?(0,X.jsx)(Sv,{className:`h-3.5 w-16`}):(0,X.jsx)(`span`,{className:`truncate text-xs sm:text-sm`,children:r})]}),(0,X.jsx)(Q,{variant:`outline`,size:`icon-sm`,"aria-label":`Choose project`,onClick:s,children:(0,X.jsx)(Tv,{className:`h-4 w-4`})})]})]})}),nve=({activeSection:e,onChange:t})=>(0,X.jsx)(`nav`,{className:`fixed inset-x-0 bottom-0 z-20 border-t border-border/70 bg-background/95 px-3 pb-[calc(env(safe-area-inset-bottom)+0.75rem)] pt-2 backdrop-blur supports-[backdrop-filter]:bg-background/85 sm:px-4 lg:hidden`,children:(0,X.jsx)(`div`,{className:`mx-auto flex max-w-6xl gap-2 overflow-x-auto [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,children:X_e.map(n=>{let r=n.key===e,i=n.Icon;return(0,X.jsxs)(Q,{type:`button`,variant:r?`secondary`:`ghost`,className:`h-11 shrink-0 gap-2 whitespace-nowrap`,"aria-current":r?`page`:void 0,onClick:()=>t(n.key),children:[(0,X.jsx)(i,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:n.label})]},n.key)})})}),_9=({title:e,description:t,action:n})=>(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none`,children:[(0,X.jsxs)(aC,{children:[(0,X.jsx)(oC,{children:e}),(0,X.jsx)(sC,{children:t})]}),n&&(0,X.jsx)(lC,{children:n})]}),v9=({text:e})=>(0,X.jsxs)(`div`,{"aria-live":`polite`,className:`flex items-center gap-2 px-1 py-3 text-sm text-muted-foreground`,role:`status`,children:[(0,X.jsx)(Ov,{className:`h-4 w-4 animate-spin`}),(0,X.jsx)(`span`,{children:e})]}),rve=e=>e?`Repo root (${e})`:`Repo root`,ive=e=>{if(!e)return`Repo root`;if(e.length<=20)return e;let t=e.split(`/`).filter(Boolean),n=t[t.length-1]??e;return n.length<=17?`.../${n}`:`${n.slice(0,16)}...`},y9=(e,t)=>{if(!e)return`Target`;if(e.active_target_kind===`bundle`&&e.active_target_bundle_id){let n=t?.bundles.find(t=>t.id===e.active_target_bundle_id)??null;return n?Jy(n):`Selected bundle`}return ive(t?.current_branch??null)},b9=({title:e,description:t,children:n})=>(0,X.jsxs)(`div`,{className:`flex max-h-[80vh] flex-col overflow-hidden`,children:[(0,X.jsxs)(W_,{className:`border-b border-border/70 px-4 py-4`,children:[(0,X.jsx)(K_,{children:e}),t&&(0,X.jsx)(q_,{children:t})]}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-4`,children:n})]}),ave=({projects:e,selectedProjectId:t,error:n,onSelectProject:r,onRetry:i})=>n?(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(`p`,{className:`text-sm text-red-200`,children:n}),(0,X.jsx)(Q,{variant:`warning`,onClick:i,children:`Retry projects`})]}):e?e.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No projects are available on the desktop instance yet.`}):(0,X.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>{let n=e.id===t;return(0,X.jsxs)(`button`,{type:`button`,className:Z(`w-full rounded-2xl border px-4 py-3 text-left transition-colors`,n?`border-primary/50 bg-primary/10`:`border-border/80 bg-card/60 hover:border-primary/30 hover:bg-accent/60`),onClick:()=>r(e.id),children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),(0,X.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.repo_path})]}),n&&(0,X.jsx)(rC,{variant:`info`,children:`Current`})]}),(0,X.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2 text-[11px] uppercase tracking-[0.14em] text-muted-foreground`,children:(0,X.jsxs)(`span`,{children:[e.ticket_count,` tickets`]})})]},e.id)})}):(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading projects...`}),ove=({open:e,projects:t,selectedProjectId:n,error:r,onOpenChange:i,onSelectProject:a,onRetry:o})=>(0,X.jsx)(V_,{open:e,onOpenChange:i,children:(0,X.jsx)(U_,{showCloseButton:!1,"aria-describedby":void 0,className:`top-auto right-0 bottom-0 left-0 max-w-none translate-x-0 translate-y-0 overflow-hidden rounded-t-3xl rounded-b-none border-x-0 border-b-0 p-0 sm:top-1/2 sm:right-auto sm:bottom-auto sm:left-1/2 sm:max-w-md sm:-translate-x-1/2 sm:-translate-y-1/2 sm:rounded-2xl sm:border sm:p-0`,children:(0,X.jsx)(b9,{title:`Projects`,children:(0,X.jsx)(ave,{projects:t,selectedProjectId:n,error:r,onSelectProject:e=>{a(e),i(!1)},onRetry:o})})})}),sve=({open:e,project:t,targetOptions:n,error:r,isLoading:i,isSubmitting:a,onOpenChange:o,onRetry:s,onSelectBundle:c,onSelectRepoRoot:l})=>{let[u,d]=(0,p.useState)(``);(0,p.useEffect)(()=>{e&&d(n?.current_branch??``)},[e,n?.current_branch]);let f=t?.active_target_kind!==`bundle`,m=Fy(n?.bundles??[]),h=[{key:`default`,label:`Default branch`,branch:n?.default_branch??null},{key:`previous`,label:`Previous branch`,branch:n?.previous_branch??null}].filter(e=>e.branch&&e.branch!==n?.current_branch).filter((e,t,n)=>n.findIndex(t=>t.branch===e.branch)===t),g=t?r?(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(`p`,{className:`text-sm text-red-200`,children:r}),(0,X.jsx)(Q,{variant:`warning`,onClick:s,children:`Retry target options`})]}):n?(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-sm font-semibold text-foreground`,children:`Project target`}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Choose the repo root or a prepared bundle for new chats and desktop work launched from this phone.`})]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(iv,{className:`text-xs font-medium text-muted-foreground`,children:`Target`}),(0,X.jsxs)(`div`,{className:`space-y-2 rounded-xl border border-border/70 bg-background/40 p-2`,children:[(0,X.jsx)(Q,{type:`button`,variant:f?`secondary`:`ghost`,className:`w-full justify-start`,disabled:a,onClick:()=>l(null),children:rve(n.current_branch)}),(0,X.jsxs)(`div`,{className:`relative min-h-10`,"data-testid":`mobile-target-options`,children:[i&&(0,X.jsx)(`div`,{className:`pointer-events-none absolute right-2 top-2 z-10 text-muted-foreground`,"data-testid":`mobile-target-options-spinner`,children:(0,X.jsx)(Ov,{className:`h-3.5 w-3.5 animate-spin`})}),(0,X.jsx)(`div`,{className:`max-h-40 overflow-y-auto pr-7`,children:m.length===0&&!i?(0,X.jsx)(`p`,{className:`px-2 py-2 text-xs text-muted-foreground`,children:`No prepared bundles are available yet.`}):m.map(e=>(0,X.jsx)(Q,{type:`button`,variant:t.active_target_kind===`bundle`&&t.active_target_bundle_id===e.id?`secondary`:`ghost`,className:`w-full justify-start`,disabled:a,onClick:()=>c(e.id),children:(0,X.jsx)(`span`,{className:`truncate`,children:Jy(e)})},e.id))})]})]})]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(iv,{className:`text-xs font-medium text-muted-foreground`,children:`Repo root branch`}),(0,X.jsxs)(`div`,{className:`space-y-2 rounded-xl border border-border/70 bg-background/40 p-3`,children:[(0,X.jsx)(`div`,{className:`space-y-2`,children:h.length>0?h.map(({key:e,label:t,branch:n})=>(0,X.jsxs)(Q,{type:`button`,variant:`outline`,className:`w-full justify-between gap-3`,disabled:!f||a||!n,onClick:()=>l(n),children:[(0,X.jsx)(`span`,{children:t}),(0,X.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:n})]},e)):(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i?`Loading branch suggestions...`:`No suggested branches available.`})}),(0,X.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,X.jsx)(iv,{htmlFor:`mobile-project-target-branch-input`,className:`text-xs text-muted-foreground`,children:`Switch or create branch`}),(0,X.jsx)(J_,{id:`mobile-project-target-branch-input`,value:u,disabled:!f||a,onChange:e=>d(e.target.value),placeholder:`feature/quick-fix`})]}),(0,X.jsx)(Q,{type:`button`,disabled:!f||!u.trim()||a,onClick:()=>l(u.trim()),children:`Switch`})]}),!f&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Switch to repo root to choose a branch.`})]})]})]}):(0,X.jsx)(v9,{text:`Loading target options...`}):(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Select a project before choosing a target.`});return(0,X.jsx)(V_,{open:e,onOpenChange:o,children:(0,X.jsx)(U_,{showCloseButton:!1,"aria-describedby":void 0,className:`top-auto right-0 bottom-0 left-0 max-w-none translate-x-0 translate-y-0 overflow-hidden rounded-t-3xl rounded-b-none border-x-0 border-b-0 p-0 sm:top-1/2 sm:right-auto sm:bottom-auto sm:left-1/2 sm:max-w-md sm:-translate-x-1/2 sm:-translate-y-1/2 sm:rounded-2xl sm:border sm:p-0`,children:(0,X.jsx)(b9,{title:`Target`,description:t?y9(t,n):void 0,children:g})})})},x9=e=>e.parked_at?`parked`:e.state,S9=e=>{let t=x9(e);return t===`parked`?`Done`:`${t.slice(0,1).toUpperCase()}${t.slice(1)}`},C9=e=>e===`plan`?`info`:e===`build`?`success`:e===`review`?`warning`:`outline`,w9=({ticket:e,isSelected:t,onSelectTicket:n,className:r})=>(0,X.jsxs)(`button`,{type:`button`,className:Z(`w-full rounded-2xl border px-4 py-3 text-left transition-colors`,t?`border-primary/50 bg-primary/10`:`border-border/70 bg-card/40 hover:border-primary/30 hover:bg-accent/50`,r),onClick:()=>n(e.id),children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e.title})}),(0,X.jsx)(rC,{variant:C9(x9(e)),children:S9(e)})]}),(0,X.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2 text-[11px] uppercase tracking-[0.14em] text-muted-foreground`,children:[e.agent_status&&(0,X.jsx)(`span`,{children:e.agent_status}),e.branch&&(0,X.jsx)(`span`,{children:e.branch}),e.bundle?.name&&(0,X.jsx)(`span`,{children:e.bundle.name})]})]}),cve=({group:e,selectedBundleId:t,selectedTicketId:n,onSelectBundle:r,onSelectTicket:i})=>{let a=e.bundle.id===t,o=e.tickets.some(e=>e.id===n),[s,c]=(0,p.useState)(o),l=Jy(e.bundle)||e.bundle.branch||e.bundle.name||`Bundle`,u=e.tickets.filter(e=>e.agent_status===`running`).length,d=a||o;return(0,p.useEffect)(()=>{o&&c(!0)},[o]),(0,X.jsxs)(SC,{open:s,onOpenChange:c,children:[(0,X.jsxs)(`div`,{className:Z(`flex items-start gap-2 rounded-2xl border px-4 py-3 transition-colors`,d?`border-primary/50 bg-primary/10`:`border-border/70 bg-card/40 hover:border-primary/30 hover:bg-accent/50`),children:[(0,X.jsx)(`button`,{type:`button`,className:`min-w-0 flex-1 text-left`,"aria-label":`Open bundle ${l}`,onClick:()=>r(e.bundle.id),children:(0,X.jsx)(`div`,{className:`flex items-start justify-between gap-3`,children:(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(rC,{variant:`outline`,children:`Bundle`}),(0,X.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:l})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[11px] uppercase tracking-[0.14em] text-muted-foreground`,children:[(0,X.jsxs)(`span`,{children:[e.tickets.length,` ticket`,e.tickets.length===1?``:`s`]}),u>0&&(0,X.jsxs)(`span`,{children:[u,` running`]}),e.bundle.branch&&(0,X.jsx)(`span`,{children:e.bundle.branch})]})]})})}),(0,X.jsx)(CC,{asChild:!0,children:(0,X.jsx)(Q,{type:`button`,variant:`ghost`,size:`icon-sm`,className:`mt-0.5 shrink-0`,"aria-label":`Toggle bundle tickets for ${l}`,children:(0,X.jsx)(bv,{className:Z(`h-4 w-4 transition-transform`,s&&`rotate-180`)})})})]}),(0,X.jsx)(wC,{className:`pt-2`,children:(0,X.jsx)(`div`,{className:`space-y-2 pl-3`,children:e.tickets.map(t=>(0,X.jsx)(w9,{ticket:t,isSelected:t.id===n,onSelectTicket:t=>i(t,e.bundle.id),className:`rounded-xl`},t.id))})})]})},T9=(e,t)=>Hy(e,[],t),lve=e=>[{key:`plan`,label:`Plan`,tickets:e.filter(e=>!e.parked_at&&e.state===`plan`),items:T9(e.filter(e=>!e.parked_at&&e.state===`plan`),`plan`)},{key:`build`,label:`Build`,tickets:e.filter(e=>!e.parked_at&&e.state===`build`),items:T9(e.filter(e=>!e.parked_at&&e.state===`build`),`build`)},{key:`review`,label:`Review`,tickets:e.filter(e=>!e.parked_at&&e.state===`review`),items:T9(e.filter(e=>!e.parked_at&&e.state===`review`),`review`)},{key:`parked`,label:`Done`,tickets:e.filter(e=>e.parked_at),items:T9(e.filter(e=>e.parked_at),`done`)}].filter(e=>e.tickets.length>0),E9=({selectedProjectId:e,tickets:t,selectedBundleId:n,selectedTicketId:r,error:i,onRetry:a,onSelectBundle:o,onSelectTicket:s})=>{if(!e)return(0,X.jsx)(_9,{title:`Choose a project`,description:`Select a project before browsing tickets from this phone.`});if(i)return(0,X.jsx)(_9,{title:`Tickets unavailable`,description:i,action:(0,X.jsx)(Q,{variant:`warning`,onClick:a,children:`Retry tickets`})});if(!t)return(0,X.jsx)(iC,{className:`border-border/80 bg-card/70 shadow-none`,children:(0,X.jsx)(lC,{className:`pt-5 text-sm text-muted-foreground`,children:`Loading tickets...`})});if(t.length===0)return(0,X.jsx)(_9,{title:`No tickets`,description:`This project does not have any tickets yet.`});let c=lve(t);return(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none lg:flex lg:min-h-0 lg:flex-col`,children:[(0,X.jsxs)(aC,{className:`border-b border-border/70 pb-4`,children:[(0,X.jsx)(oC,{children:`Tickets`}),(0,X.jsxs)(sC,{children:[t.length,` total`]})]}),(0,X.jsx)(lC,{className:`space-y-4 pt-5 lg:min-h-0 lg:flex-1 lg:overflow-y-auto`,children:c.map(e=>(0,X.jsxs)(`section`,{className:`space-y-2`,"aria-label":`${e.label} tickets`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground`,children:[(0,X.jsx)(`span`,{children:e.label}),(0,X.jsx)(`span`,{children:e.tickets.length})]}),(0,X.jsx)(`div`,{className:`space-y-2`,children:e.items.map(e=>e.kind===`bundle`?(0,X.jsx)(cve,{group:e.group,selectedBundleId:n,selectedTicketId:r,onSelectBundle:o,onSelectTicket:s},e.group.id):(0,X.jsx)(w9,{ticket:e.ticket,isSelected:e.ticket.id===r,onSelectTicket:e=>s(e,null)},e.ticket.id))})]},e.key))})]})},uve=e=>i9(`/mobile-auth/status`,{signal:e}),dve=(e,t)=>i9(`/mobile-auth/pair/preview`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:t}),fve=e=>i9(`/mobile-auth/pair`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}),pve=e=>i9(`/mobile-auth/logout`,{method:`POST`,headers:{[r9]:e}}),mve=()=>GS(window.location.origin,{withCredentials:!0}),D9=({label:e,value:t,mono:n=!1})=>t?(0,X.jsxs)(`div`,{className:`grid min-w-0 gap-1 border-b border-border/50 py-2 last:border-0`,children:[(0,X.jsx)(`dt`,{className:`text-xs text-muted-foreground`,children:e}),(0,X.jsx)(`dd`,{className:n?`min-w-0 break-all font-mono text-xs text-foreground`:`min-w-0 break-words text-sm text-foreground`,children:t})]}):null,hve=({projectId:e,csrfToken:t,socket:n,initialRequests:r,onRequestError:i})=>{let{t:a,i18n:o}=q(`common`,{keyPrefix:`mobileApp.approvals`}),[s,c]=(0,p.useState)(r),[l,u]=(0,p.useState)(null),[d,f]=(0,p.useState)(null),[m,h]=(0,p.useState)(!1),[g,_]=(0,p.useState)(``),[v,y]=(0,p.useState)(null),[b,x]=(0,p.useState)(null),[S,C]=(0,p.useState)(!1),[w,T]=(0,p.useState)(0),E=(0,p.useRef)(r);E.current=r;let D=l?`${e}:${l}`:null,O=(0,p.useRef)(D);O.current=D;let k=(0,p.useRef)(!0);(0,p.useEffect)(()=>(k.current=!0,()=>{k.current=!1}),[]),(0,p.useEffect)(()=>{c(E.current),u(null)},[e]),(0,p.useEffect)(()=>{let t=new AbortController,n=e;return m_e(e,t.signal).then(r=>{if(t.signal.aborted||n!==e)return;let i=r?.approval_requests??[];c(i),u(e=>e&&i.some(t=>t.id===e)?e:null),y(null)}).catch(e=>{Ye(e)||i(e)||y(e instanceof Ge?e.message:a(`loadError`))}),()=>t.abort()},[i,e,w,a]),(0,p.useEffect)(()=>{if(f(null),_(``),C(!1),x(null),!l){h(!1);return}let t=new AbortController,n=`${e}:${l}`;return h(!0),h_e(e,l,t.signal).then(t=>{O.current===n&&t.approval_request.project_id===e&&t.approval_request.id===l&&f(t)}).catch(e=>{if(!Ye(e)&&O.current===n){if(i(e))return;x(e instanceof Ge?e.message:a(`detailError`))}}).finally(()=>{!t.signal.aborted&&O.current===n&&h(!1)}),()=>t.abort()},[i,e,w,l,a]),(0,p.useEffect)(()=>{if(!n)return;let t=t=>{t&&typeof t==`object`&&`project_id`in t&&t.project_id!==e||T(e=>e+1)};return n.on(`approval-request:created`,t),n.on(`approval-request:updated`,t),n.on(`connect`,t),()=>{n.off(`approval-request:created`,t),n.off(`approval-request:updated`,t),n.off(`connect`,t)}},[e,n]);let A=d?.approval_request.project_id===e&&d.approval_request.id===l?d.approval_request:null,j=A?.action.kind===`custom_check`?A.action.target.batch_environment:A?.authority.environment,M=A?.action.kind===`custom_check`?A.action.target.attempt_placement:A?.authority.execution_boundary?.attempt_placement,N=A?.action.kind===`git_push`?A.action.target.degradations??[]:[],P=async n=>{if(!A||S)return;let r=`${e}:${A.id}`;C(!0),x(null);try{if(await g_e(e,A,n,t,g),!k.current||O.current!==r)return;_(``),T(e=>e+1)}catch(e){if(!k.current||O.current!==r||i(e))return;let t=Ke(e,`approval_request`);t&&(c(e=>e.map(e=>e.id===t.id?t:e).filter(e=>e.status===`pending`)),f(e=>e&&e.approval_request.id===t.id?{...e,approval_request:t}:e)),x(e instanceof Ge?e.message:a(`decisionError`))}finally{k.current&&O.current===r&&C(!1)}};return s.length===0&&!v&&!A&&!b?null:(0,X.jsxs)(`section`,{"aria-labelledby":`mobile-approvals-title`,className:`rounded-2xl border border-amber-300/30 bg-amber-500/5 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{id:`mobile-approvals-title`,className:`font-semibold text-foreground`,children:a(`title`)}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:a(`count`,{count:s.length})})]}),(0,X.jsx)(`span`,{className:`rounded-full bg-amber-400/15 px-2.5 py-1 text-sm font-semibold text-amber-100`,children:s.length})]}),v&&(0,X.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-red-200`,children:v}),(0,X.jsx)(`div`,{className:`mt-3 space-y-2`,children:s.map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>u(e.id),className:`w-full rounded-xl border border-border bg-card/70 p-3 text-left outline-none focus:ring-2 focus:ring-ring/50`,children:[(0,X.jsx)(`span`,{className:`block text-sm font-medium text-foreground`,children:a(`action.${e.action_kind}`)}),(0,X.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:a(`expires`,{value:new Intl.DateTimeFormat(o.language,{dateStyle:`short`,timeStyle:`short`}).format(new Date(e.expires_at))})})]},e.id))}),l&&m&&(0,X.jsx)(`p`,{className:`mt-4 border-t border-border/60 pt-4 text-sm text-muted-foreground`,children:a(`loadingDetail`)}),l&&b&&(0,X.jsx)(`p`,{role:`alert`,className:`mt-4 border-t border-border/60 pt-4 text-sm text-red-200`,children:b}),A&&(0,X.jsxs)(`div`,{className:`mt-4 border-t border-border/60 pt-4`,children:[(0,X.jsx)(`p`,{className:`text-sm text-foreground`,children:a(`impact.${A.action_kind}`)}),(0,X.jsxs)(`dl`,{className:`mt-3 max-h-72 overflow-y-auto rounded-xl border border-border/60 bg-background/35 px-3`,children:[(0,X.jsx)(D9,{label:a(`fields.action`),value:a(`action.${A.action_kind}`)}),(0,X.jsx)(D9,{label:a(`fields.target`),value:A.action.kind===`git_push`?`${A.action.target.remote_name} ${A.action.target.ref}`:`${A.action.target.scope_kind} ${A.action.target.scope_id}`}),(0,X.jsx)(D9,{label:a(`fields.command`),value:A.action.kind===`custom_check`?A.action.target.effective_command??A.action.target.definition_snapshot?.command:null,mono:!0}),(0,X.jsx)(D9,{label:a(`fields.cwd`),value:A.action.kind===`custom_check`?A.action.target.effective_cwd??A.action.workspace_git.workspace_path:A.action.workspace_git.workspace_path,mono:!0}),(0,X.jsx)(D9,{label:a(`fields.branch`),value:A.action.workspace_git.branch}),(0,X.jsx)(D9,{label:a(`fields.head`),value:A.action.workspace_git.head_sha,mono:!0}),(0,X.jsx)(D9,{label:a(`fields.remoteHead`),value:A.action.workspace_git.remote_head_sha,mono:!0}),(0,X.jsx)(D9,{label:a(`fields.profile`),value:A.authority.selected_profile?`${A.authority.selected_profile.revision_id} (r${A.authority.selected_profile.revision})`:null}),(0,X.jsx)(D9,{label:a(`fields.launcher`),value:A.action.kind===`custom_check`&&A.action.target.launcher?a(`values.launcher.${A.action.target.launcher}`):null}),(0,X.jsx)(D9,{label:a(`fields.environment`),value:j?`${j.id} (r${j.revision})`:A.authority.execution_boundary?.placement===`host`?a(`values.noHostEnvironment`):a(`none`),mono:!!j}),(0,X.jsx)(D9,{label:a(`fields.placement`),value:A.authority.execution_boundary?.placement===`host`?a(`values.hostPlacement`):M?.scope.kind===`exact-sandbox`?a(`values.sandboxPlacement`,{id:M.scope.externalId}):a(`values.sandboxPlacementUnavailable`),mono:!!M}),(0,X.jsx)(D9,{label:a(`fields.authority`),value:A.authority.effective_capabilities.join(`, `)||a(`none`)}),(0,X.jsx)(D9,{label:a(`fields.degradations`),value:N.join(`, `)}),(0,X.jsx)(D9,{label:a(`fields.secrets`),value:A.action.logical_secret_references.join(`, `)||a(`none`)}),(0,X.jsx)(D9,{label:a(`fields.expires`),value:new Intl.DateTimeFormat(o.language,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(A.expires_at))})]}),(0,X.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:a(`history`,{count:d?.events.length??0})}),!!d?.events.length&&(0,X.jsx)(`ol`,{className:`mt-2 max-h-36 space-y-1 overflow-y-auto text-xs text-muted-foreground`,children:d.events.map(e=>(0,X.jsxs)(`li`,{children:[a(`status.${e.to_status}`),` · `,new Intl.DateTimeFormat(o.language,{dateStyle:`short`,timeStyle:`short`}).format(new Date(e.created_at)),e.reason?` · ${e.reason}`:``]},e.id))}),A.status!==`pending`&&(0,X.jsx)(`p`,{className:`mt-3 text-sm text-muted-foreground`,children:a(`remediation.${A.status}`)}),A.status===`pending`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`label`,{className:`mt-3 block text-xs text-muted-foreground`,htmlFor:`mobile-approval-reason-${A.id}`,children:a(`reason`)}),(0,X.jsx)(`textarea`,{id:`mobile-approval-reason-${A.id}`,rows:2,maxLength:2e3,value:g,onChange:e=>_(c4(e.target.value)),className:`mt-1 w-full rounded-xl border border-border bg-card px-3 py-2 text-sm text-foreground outline-none focus:ring-2 focus:ring-ring/50`}),(0,X.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,X.jsx)(Q,{disabled:S,onClick:()=>void P(`approve`),children:a(`approve`)}),(0,X.jsx)(Q,{variant:`outline`,disabled:S,onClick:()=>void P(`deny`),children:a(`deny`)}),(0,X.jsx)(Q,{variant:`ghost`,disabled:S,onClick:()=>void P(`cancel`),children:a(`cancel`)})]})]})]})]})},O9=e=>qb.t(`common:mobileApp.${e}`),k9=({selectedProjectId:e,chatSessions:t,selectedChatSessionId:n,error:r,onRetry:i,onOpenNewChat:a,onSelectChat:o})=>e?r?(0,X.jsx)(_9,{title:`Chats unavailable`,description:r,action:(0,X.jsx)(Q,{variant:`warning`,onClick:i,children:`Retry chats`})}):(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none lg:flex lg:min-h-0 lg:flex-col`,children:[(0,X.jsxs)(aC,{className:`border-b border-border/70 pb-4`,children:[(0,X.jsx)(oC,{children:`Chats`}),(0,X.jsx)(sC,{children:t?`${t.length} recent`:`Loading chats...`}),(0,X.jsx)(cC,{children:(0,X.jsx)(Q,{variant:`outline`,size:`sm`,onClick:a,children:`New chat`})})]}),(0,X.jsx)(lC,{className:`space-y-2 pt-5 lg:min-h-0 lg:flex-1 lg:overflow-y-auto`,children:t?t.length===0?(0,X.jsx)(_9,{title:`No chats`,description:`Start a new chat to plan or build from this project.`,action:(0,X.jsx)(Q,{onClick:a,children:`Start a chat`})}):t.map(e=>(0,X.jsx)(`button`,{type:`button`,className:Z(`w-full rounded-xl border px-3 py-2.5 text-left transition-colors`,e.id===n?`border-primary/50 bg-primary/10`:`border-border/70 bg-card/40 hover:border-primary/30 hover:bg-accent/50`),onClick:()=>o(e.id),children:(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1 pr-2 text-sm font-medium text-foreground line-clamp-2 break-words`,children:e.title}),(0,X.jsx)(rC,{variant:e.agent_status===`running`?`warning`:e.mode===`plan`?`info`:`success`,children:e.agent_status??e.mode})]})},e.id)):(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading chats...`})})]}):(0,X.jsx)(_9,{title:`Choose a project`,description:`Select a project before browsing chats from this phone.`}),A9=({selectedProjectId:e,specSessions:t,selectedSpecSessionId:n,error:r,onRetry:i,onOpenNewSpec:a,onSelectSpec:o})=>e?r?(0,X.jsx)(_9,{title:O9(`specList.listError`),description:r,action:(0,X.jsx)(Q,{variant:`warning`,onClick:i,children:O9(`specList.retry`)})}):(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none lg:flex lg:min-h-0 lg:flex-col`,children:[(0,X.jsxs)(aC,{className:`border-b border-border/70 pb-4`,children:[(0,X.jsx)(oC,{children:O9(`specList.title`)}),(0,X.jsx)(sC,{children:t?`${t.length} recent`:O9(`specList.loading`)}),(0,X.jsx)(cC,{children:(0,X.jsx)(Q,{variant:`outline`,size:`sm`,onClick:a,children:O9(`specList.newSpec`)})})]}),(0,X.jsx)(lC,{className:`space-y-2 pt-5 lg:min-h-0 lg:flex-1 lg:overflow-y-auto`,children:t?t.length===0?(0,X.jsx)(_9,{title:O9(`specList.emptyTitle`),description:O9(`specList.emptyDescription`),action:(0,X.jsx)(Q,{onClick:a,children:O9(`specList.startSpec`)})}):t.map(e=>(0,X.jsx)(`button`,{type:`button`,className:Z(`w-full rounded-xl border px-3 py-2.5 text-left transition-colors`,e.id===n?`border-primary/50 bg-primary/10`:`border-border/70 bg-card/40 hover:border-primary/30 hover:bg-accent/50`),onClick:()=>o(e.id),children:(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1 pr-2 text-sm font-medium text-foreground line-clamp-2 break-words`,children:e.title}),(0,X.jsx)(rC,{variant:e.agent_status===`running`?`warning`:e.mode===`grill`?`info`:`success`,children:e.agent_status??e.mode})]})},e.id)):(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:O9(`specList.loading`)})})]}):(0,X.jsx)(_9,{title:O9(`specList.emptyTitle`),description:`Select a project before browsing specs from this phone.`}),j9=e=>{let t=e.tickets.filter(e=>!e.parked_at),n=t.filter(e=>e.state===`plan`),r=t.filter(e=>e.state===`build`),i=t.filter(e=>e.state===`review`),a=t.some(e=>e.agent_status===`running`),o=t.find(e=>my(e)&&e.agent_status===`running`&&!!e.session_id)??null,s=t.find(e=>my(e)&&e.agent_status===`stopped`&&!!e.session_id)??null,c=[];n.length>0&&c.push({id:`build`,label:`Build Bundle`,pendingLabel:`Building Bundle...`,ariaLabel:`Build Bundle`,disabled:!1,disabledReason:null});let l=r.length>0&&r.every(e=>e.agent_status===`done`),u=r.length===0&&i.length>0&&e.can_re_review===!0&&!a;return(l||u)&&c.push({id:`review`,label:u?`Re-run review`:`Review Bundle`,pendingLabel:`Reviewing Bundle...`,ariaLabel:u?`Re-run review`:`Review Bundle`,disabled:!1,disabledReason:null}),o&&c.push({id:`pause-build`,label:`Pause Build`,pendingLabel:`Pausing Build...`,ariaLabel:`Pause Build`,title:`Pause the build session. You can resume it later.`,disabled:!1,disabledReason:null}),!o&&s&&c.push({id:`resume-build`,label:`Resume`,pendingLabel:`Resuming...`,ariaLabel:`Resume`,disabled:!1,disabledReason:null}),{actions:c,runningBuildTicketId:o?.id??null,resumableBuildTicketId:s?.id??null}},M9=e=>[...e??[]].reverse().find(e=>e.metadata?.ask_question?.status===`pending`)??null,gve=({className:e})=>(0,X.jsx)(Tg,{"aria-hidden":`true`,className:e}),_ve=()=>{let[e,t]=(0,p.useState)(()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(min-width: 1024px)`).matches);return(0,p.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(min-width: 1024px)`),n=n=>{t(n?.matches??e.matches)};return n(),typeof e.addEventListener==`function`?(e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)):(e.addListener(n),()=>e.removeListener(n))},[]),e},N9=({label:e,value:t,accentClassName:n})=>(0,X.jsxs)(`div`,{className:`rounded-2xl border border-border/70 bg-card/70 p-3`,children:[(0,X.jsx)(`div`,{className:Z(`text-xl font-semibold text-foreground`,n),children:t}),(0,X.jsx)(`div`,{className:`mt-1 text-xs uppercase tracking-[0.14em] text-muted-foreground`,children:e})]}),P9=()=>(0,X.jsxs)(`div`,{className:`space-y-3`,"data-testid":`mobile-overview-skeleton`,children:[(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none`,children:[(0,X.jsx)(aC,{className:`border-b border-border/70 pb-4`,children:(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,X.jsx)(Sv,{className:`h-6 w-28`}),(0,X.jsx)(Sv,{className:`h-6 w-28 rounded-full`})]})}),(0,X.jsxs)(lC,{className:`space-y-4 pt-5`,children:[(0,X.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3`,children:Array.from({length:6},(e,t)=>(0,X.jsxs)(`div`,{className:`rounded-2xl border border-border/70 bg-card/70 p-3`,children:[(0,X.jsx)(Sv,{className:`h-6 w-10`}),(0,X.jsx)(Sv,{className:`mt-2 h-3 w-16`})]},t))}),(0,X.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,X.jsx)(Sv,{className:`h-10 w-full rounded-xl`}),(0,X.jsx)(Sv,{className:`h-10 w-full rounded-xl`})]})]})]}),(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none`,children:[(0,X.jsx)(aC,{children:(0,X.jsx)(Sv,{className:`h-6 w-20`})}),(0,X.jsx)(lC,{children:(0,X.jsx)(Sv,{className:`h-10 w-40 rounded-xl`})})]})]}),vve=({isLoggingOut:e,onLogout:t})=>(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none`,children:[(0,X.jsx)(aC,{children:(0,X.jsx)(oC,{children:`Session`})}),(0,X.jsx)(lC,{children:(0,X.jsxs)(Q,{variant:`destructive`,className:`gap-2`,disabled:e,onClick:t,children:[(0,X.jsx)(gve,{className:`h-4 w-4`}),e?`Logging out...`:`Log out this phone`]})})]}),yve=({activeRun:e,tickets:t,chatSessions:n,chatSessionDetail:r})=>{let i=r?.agent_status===`running`||!!n?.some(e=>e.agent_status===`running`);if(e?.kind===`ticket`)return{label:`Ticket run active`,variant:`success`};if(i)return{label:`Chat active`,variant:`success`};if(e)return{label:`Project run active`,variant:`success`};let a=t?.filter(e=>e.agent_status===`running`&&e.parked_at===null)??[],o=gF(a.filter(e=>e.state===`review`));return o===`building`?{label:qb.t(`common:statusBadge.building`),variant:`success`}:o===`reviewing`?{label:qb.t(`common:statusBadge.reviewing`),variant:`warning`}:a.some(e=>e.state===`build`)?{label:qb.t(`common:statusBadge.building`),variant:`success`}:a.some(e=>e.state===`plan`)?{label:`Planning`,variant:`info`}:{label:`Idle`,variant:`outline`}},bve=({activeRun:e,tickets:t,chatSessions:n,chatSessionDetail:r})=>{let i=yve({activeRun:e,tickets:t,chatSessions:n,chatSessionDetail:r});return(0,X.jsx)(rC,{variant:i.variant,children:i.label})},xve=({selectedProjectId:e,summary:t,tickets:n,error:r,chatSessions:i,chatSessionDetail:a,onRetry:o,onOpenTickets:s,onOpenChats:c,onOpenSpec:l})=>{let u=p9.Icon,d=m9.Icon,f=h9.Icon;return r?(0,X.jsx)(_9,{title:`Project summary unavailable`,description:r,action:(0,X.jsx)(Q,{variant:`warning`,onClick:o,children:`Retry summary`})}):e?!t||t.project.id!==e?(0,X.jsx)(iC,{className:`border-border/80 bg-card/70 shadow-none`,children:(0,X.jsx)(lC,{className:`pt-5 text-sm text-muted-foreground`,children:`Loading project summary...`})}):(0,X.jsxs)(iC,{className:`border-border/80 bg-card/70 shadow-none`,children:[(0,X.jsxs)(aC,{className:`border-b border-border/70 pb-4`,children:[(0,X.jsx)(oC,{children:`Overview`}),(0,X.jsx)(cC,{children:(0,X.jsx)(bve,{activeRun:t.active_run,tickets:n,chatSessions:i,chatSessionDetail:a})})]}),(0,X.jsxs)(lC,{className:`space-y-4 pt-5`,children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3`,children:[(0,X.jsx)(N9,{label:`Tickets`,value:t.tickets.total}),(0,X.jsx)(N9,{label:`Plan`,value:t.tickets.plan,accentClassName:`text-sky-200`}),(0,X.jsx)(N9,{label:`Build`,value:t.tickets.build,accentClassName:`text-emerald-200`}),(0,X.jsx)(N9,{label:`Review`,value:t.tickets.review,accentClassName:`text-amber-200`}),(0,X.jsx)(N9,{label:`Done`,value:t.tickets.parked}),(0,X.jsx)(N9,{label:`Bundles`,value:t.project.bundle_count??0})]}),(0,X.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,X.jsxs)(Q,{variant:`outline`,className:`gap-2`,"aria-label":p9.ctaAriaLabel,onClick:s,children:[(0,X.jsx)(u,{className:`h-4 w-4`}),p9.label]}),(0,X.jsxs)(Q,{variant:`outline`,className:`gap-2`,"aria-label":m9.ctaAriaLabel,onClick:c,children:[(0,X.jsx)(d,{className:`h-4 w-4`}),m9.label]}),(0,X.jsxs)(Q,{variant:`outline`,className:`gap-2 sm:col-span-2`,"aria-label":h9.ctaAriaLabel,onClick:l,children:[(0,X.jsx)(f,{className:`h-4 w-4`}),h9.label]})]})]})]}):(0,X.jsx)(_9,{title:`Choose a project`,description:`Select a desktop project before opening tickets or chats from this phone.`})},Sve=({ticket:e})=>{let t=[{label:`State`,value:S9(e)},{label:`Tool`,value:yF(e,`opencode`)},{label:`Agent`,value:e.agent_status},{label:`Branch`,value:e.branch},{label:`Bundle`,value:e.bundle?.name??null},{label:`Model`,value:e.tool===`opencode`?e.model:null},{label:`Variant`,value:e.tool===`opencode`?e.variant:null}].filter(e=>!!e.value);return t.length===0?null:(0,X.jsxs)(`div`,{className:`min-w-0 space-y-2 rounded-xl border border-border/70 bg-background/40 px-3 py-3`,children:[(0,X.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,children:`Details`}),(0,X.jsx)(`dl`,{className:`grid gap-2 text-sm sm:grid-cols-2`,children:t.map(e=>(0,X.jsxs)(`div`,{className:`space-y-1 rounded-lg border border-border/60 bg-background/50 px-3 py-2`,children:[(0,X.jsx)(`dt`,{className:`text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,children:e.label}),(0,X.jsx)(`dd`,{className:`break-words text-foreground`,children:e.value})]},e.label))})]})},F9=({label:e,disabled:t,onClick:n})=>(0,X.jsx)(Q,{type:`button`,variant:`outline`,disabled:t,onClick:n,children:e}),Cve=({ticket:e,actionState:t,actionError:n,onAction:r})=>{let i=l3(e,{reviewLabel:e.worktree_bundle_id===null?`Review`:`Review Bundle`}),a=e.worktree_bundle_id===null&&e.state===`review`&&e.can_re_review===!0&&e.agent_status!==`running`&&!e.parked_at?[{id:`review`,label:`Re-run review`,pendingLabel:`Re-running review...`,ariaLabel:`Re-run review`,disabled:!1,disabledReason:null},...i]:i;return a.length===0?null:(0,X.jsx)(i4,{actions:a,activeAction:t,disableWhenActive:!0,className:`space-y-3`,heading:`Actions`,headingClassName:`text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,actionsClassName:`flex flex-wrap gap-2`,showDisabledReason:!0,disabledReasonClassName:`text-sm text-amber-200`,error:n,errorClassName:`text-sm text-red-200`,renderAction:({action:e,label:t,disabled:n})=>(0,X.jsx)(F9,{label:t,disabled:n,onClick:()=>r(e.id)},e.id)})},wve=({bundleDetail:e,actionState:t,actionError:n,onAction:r})=>{let{actions:i}=j9(e);return i.length===0?null:(0,X.jsx)(i4,{actions:i,activeAction:t,disableWhenActive:!0,className:`space-y-3`,heading:`Actions`,headingClassName:`text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,actionsClassName:`flex flex-wrap gap-2`,error:n,errorClassName:`text-sm text-red-200`,renderAction:({action:e,label:t,disabled:n})=>(0,X.jsx)(F9,{label:t,disabled:n,onClick:()=>r(e.id)},e.id)})},I9=(e,t)=>(e??[]).map(e=>({id:e.id,role:e.role,kind:e.kind,content:e.content,created_at:e.created_at,ticket_id:t??null,ticket_proposals:`ticket_proposals`in e?e.ticket_proposals??null:null,metadata:e.metadata,responseTiming:e.response_timing?KK(e.response_timing):null,transcript_runs:e.transcript_runs??null})),L9=({title:e,subtitle:t,badges:n,backLabel:r,onBack:i,action:a})=>(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[i?(0,X.jsxs)(Q,{variant:`ghost`,size:`sm`,className:`h-8 px-2.5 lg:hidden`,"aria-label":r,onClick:i,children:[(0,X.jsx)(cF,{className:`h-4 w-4`}),`Back`]}):null,(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e}),t?(0,X.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:t}):null]})]}),a?(0,X.jsx)(`div`,{className:`shrink-0`,children:a}):null]}),n?(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:n}):null]}),Tve=({title:e,backLabel:t,onBack:n,action:r})=>(0,X.jsxs)(`div`,{className:`-mx-3 flex shrink-0 items-center justify-between gap-3 border-b border-border/80 bg-background/95 px-3 py-2.5 backdrop-blur supports-[backdrop-filter]:bg-background/85 sm:-mx-4 sm:px-4 lg:hidden`,children:[(0,X.jsxs)(Q,{variant:`ghost`,size:`sm`,className:`h-8 px-2.5`,"aria-label":t,onClick:n,children:[(0,X.jsx)(cF,{className:`h-4 w-4`}),`Back`]}),(0,X.jsx)(`div`,{className:`min-w-0 flex-1 truncate text-sm font-medium text-foreground`,children:e}),(0,X.jsx)(`div`,{className:`shrink-0`,children:r})]}),R9=({title:e,backLabel:t,onBack:n,action:r,subheader:i,children:a})=>(0,X.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,X.jsx)(Tve,{title:e,backLabel:t,onBack:n,action:r}),i?(0,X.jsx)(`div`,{className:`shrink-0 border-b border-border/70 py-2 lg:hidden`,children:i}):null,(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:a})]}),z9=({value:e,onTranscript:t,onDetails:n})=>(0,X.jsxs)(`div`,{className:`flex gap-2 px-3 sm:px-0`,children:[(0,X.jsx)(Q,{type:`button`,variant:e===`transcript`?`secondary`:`ghost`,className:`h-9 flex-1`,"aria-pressed":e===`transcript`,onClick:t,children:`Transcript`}),(0,X.jsx)(Q,{type:`button`,variant:e===`details`?`secondary`:`ghost`,className:`h-9 flex-1`,"aria-pressed":e===`details`,onClick:n,children:`Details`})]}),B9=({controls:e})=>{let[t,n]=(0,p.useState)(!1);return(0,X.jsxs)(SC,{open:t,onOpenChange:n,children:[(0,X.jsx)(`div`,{className:`px-1 pb-1`,children:(0,X.jsx)(CC,{asChild:!0,children:(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 gap-1.5 px-2 text-xs text-muted-foreground`,children:[`Options`,(0,X.jsx)(bv,{className:Z(`h-3.5 w-3.5 transition-transform`,t&&`rotate-180`)})]})})}),(0,X.jsx)(wC,{className:`px-1 pb-1`,children:(0,X.jsx)(`div`,{className:`rounded-lg border border-border/70 bg-background/35 p-2`,children:e})})]})},V9=({ticket:e,badges:t,actionState:n,actionError:r,onAction:i,className:a})=>(0,X.jsxs)(iC,{className:Z(`flex min-h-0 min-w-0 flex-col border-border/80 bg-card/70 shadow-none`,a),children:[(0,X.jsx)(aC,{className:`min-w-0 pb-3`,children:(0,X.jsx)(L9,{title:e.title,badges:t})}),(0,X.jsxs)(lC,{className:`min-h-0 min-w-0 flex-1 space-y-3 overflow-y-auto pt-0`,children:[(0,X.jsx)(Cve,{ticket:e,actionState:n,actionError:r,onAction:i}),e.description?(0,X.jsxs)(`div`,{className:`min-w-0 space-y-2 rounded-xl border border-border/70 bg-background/40 px-3 py-3`,children:[(0,X.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,children:`Description`}),(0,X.jsx)(GK,{content:e.description,className:`min-w-0 text-foreground`})]}):null,(0,X.jsx)(Sve,{ticket:e})]})]}),H9=({bundleDetail:e,title:t,subtitle:n,badges:r,actionState:i,actionError:a,onAction:o,orderedTickets:s,highlightedTicketId:c,isTicketListOpen:l,onTicketListOpenChange:u,onSelectTicket:d,className:f,availableModels:p})=>(0,X.jsxs)(iC,{className:Z(`flex min-h-0 min-w-0 flex-col border-border/80 bg-card/70 shadow-none`,f),children:[(0,X.jsx)(aC,{className:`min-w-0 pb-3`,children:(0,X.jsx)(L9,{title:t,subtitle:n,badges:r})}),(0,X.jsxs)(lC,{className:`min-h-0 min-w-0 flex-1 space-y-3 overflow-y-auto pt-0`,children:[(0,X.jsx)(wve,{bundleDetail:e,actionState:i,actionError:a,onAction:o}),(0,X.jsxs)(SC,{open:l,onOpenChange:u,children:[(0,X.jsx)(CC,{asChild:!0,children:(0,X.jsxs)(Q,{type:`button`,variant:`ghost`,className:`h-8 gap-1.5 px-2 text-xs text-muted-foreground`,children:[`Tickets`,(0,X.jsx)(bv,{className:Z(`h-3.5 w-3.5 transition-transform`,l&&`rotate-180`)})]})}),(0,X.jsx)(wC,{className:`pt-2`,children:(0,X.jsx)(`div`,{className:`rounded-xl border border-border/70 bg-background/35 p-3`,children:(0,X.jsx)(v3,{tickets:s,highlightedTicketId:c,onOpenTicketDetails:e=>d(e.id,e.worktree_bundle_id),availableModels:p})})})]})]})]}),U9=({selectedProjectId:e,bundleId:t,bundleDetail:n,openNonce:r,mobileDetailView:i,error:a,actionState:o,actionError:s,followUpPrompt:c,isSendingFollowUp:l,followUpError:u,availableModels:d,onBack:f,onRetry:m,onAction:h,onDetailViewChange:g,onSelectTicket:_,onFollowUpPromptChange:v,onFollowUpKeyDown:y,onFollowUpSubmit:b,isLargeScreen:x})=>{let[S,C]=(0,p.useState)(!0);if((0,p.useEffect)(()=>{C(!0)},[t,r]),!e)return(0,X.jsx)(_9,{title:`Choose a project`,description:`Select a project before opening bundle details from this phone.`});if(!t)return(0,X.jsx)(_9,{title:`Choose a bundle`,description:`Open a bundle to review its transcript and grouped ticket progress.`});if(a)return(0,X.jsx)(R9,{title:`Bundle unavailable`,backLabel:`Back to tickets`,onBack:f,children:(0,X.jsx)(_9,{title:`Bundle unavailable`,description:a,action:(0,X.jsx)(Q,{variant:`warning`,onClick:m,children:`Retry bundle`})})});if(!n||n.bundle.id!==t)return(0,X.jsx)(R9,{title:`Loading bundle`,backLabel:`Back to tickets`,onBack:f,children:(0,X.jsx)(v9,{text:`Loading bundle details...`})});let w=Jy(n.bundle)||n.bundle.branch||n.bundle.name||`Bundle`,T=new Map(d.map(e=>[e.id,e.label])),E=S3(n.tickets,T),D=T3(n),O=C3(n.tickets,n.execution_order_ticket_ids),k=w3(n.tickets,T,E,n.execution_order_ticket_ids),A=vF(n.tickets,D?.state??null),j=n.tickets.find(e=>e.agent_status===`running`)??D,M=j??D??n.tickets[0]??null,N=j?.agent_status===`running`?E[j.id]??j.model??`Agent`:null,P=!!(D&&D.state!==`plan`&&zy(D)),F=n.tickets.some(e=>e.agent_status===`running`)?`Wait for all bundle tickets to finish building before sending a follow-up prompt.`:void 0,I=`mobile-bundle:${n.bundle.id}:${r}`,L=`${n.tickets.length} ticket${n.tickets.length===1?``:`s`}`,R=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(uF,{status:A}),(0,X.jsx)(rC,{variant:`outline`,children:L}),M?(0,X.jsxs)(rC,{variant:`outline`,children:[`Target: `,M.title]}):null]});return(0,X.jsx)(R9,{title:w,backLabel:`Back to tickets`,onBack:f,subheader:x?void 0:(0,X.jsx)(z9,{value:i,onTranscript:()=>g(`transcript`),onDetails:()=>g(`details`)}),children:x?(0,X.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col gap-3 overflow-hidden pt-3`,children:[(0,X.jsx)(H9,{bundleDetail:n,title:w,subtitle:n.bundle.branch,badges:R,actionState:o,actionError:s,onAction:h,orderedTickets:O,highlightedTicketId:n.target_ticket_id,isTicketListOpen:S,onTicketListOpenChange:C,onSelectTicket:_,className:`shrink-0`,availableModels:d}),(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,X.jsx)(_3,{projectId:e,followUpTicketId:n.target_ticket_id,messages:k,internalLog:j?.agent_log??null,currentThinkingMessageId:j?.agent_message_id??D?.agent_message_id??null,legacyThinkingTicketId:j?.id??D?.id??null,previousThinkingLog:j?.previous_agent_log??D?.previous_agent_log??null,previousThinkingMessageId:j?.previous_agent_message_id??D?.previous_agent_message_id??null,pendingAgentTitle:N,streamingResponse:j?.streaming_response??null,isRunning:n.tickets.some(e=>e.agent_status===`running`),canShowComposer:P,composerTheme:oy(D?.state??null),layoutKey:I,scrollLayoutKey:I,followUpPrompt:c,followUpPlaceholder:M?`Follow up on: ${M.title}`:`Follow up on this bundle`,isSendingFollowUp:l,followUpDisabledReason:F,onFollowUpPromptChange:v,onFollowUpKeyDown:y,onFollowUpSubmit:b},I)}),u?(0,X.jsx)(`p`,{className:`shrink-0 text-sm text-red-200`,children:u}):null]}):i===`details`?(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,X.jsx)(H9,{bundleDetail:n,title:w,subtitle:n.bundle.branch,badges:R,actionState:o,actionError:s,onAction:h,orderedTickets:O,highlightedTicketId:n.target_ticket_id,isTicketListOpen:S,onTicketListOpenChange:C,onSelectTicket:_,className:`h-full`,availableModels:d})}):(0,X.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,X.jsx)(_3,{projectId:e,followUpTicketId:n.target_ticket_id,messages:k,internalLog:j?.agent_log??null,currentThinkingMessageId:j?.agent_message_id??D?.agent_message_id??null,legacyThinkingTicketId:j?.id??D?.id??null,previousThinkingLog:j?.previous_agent_log??D?.previous_agent_log??null,previousThinkingMessageId:j?.previous_agent_message_id??D?.previous_agent_message_id??null,pendingAgentTitle:N,streamingResponse:j?.streaming_response??null,isRunning:n.tickets.some(e=>e.agent_status===`running`),canShowComposer:P,composerTheme:oy(D?.state??null),layoutKey:I,scrollLayoutKey:I,followUpPrompt:c,followUpPlaceholder:M?`Follow up on: ${M.title}`:`Follow up on this bundle`,isSendingFollowUp:l,followUpDisabledReason:F,onFollowUpPromptChange:v,onFollowUpKeyDown:y,onFollowUpSubmit:b},I),u?(0,X.jsx)(`p`,{className:`shrink-0 px-1 pt-2 text-sm text-red-200`,children:u}):null]})})},W9=({selectedProjectId:e,chatSession:t,chatSessionId:n,openNonce:r,error:i,isStopping:a,composerMode:o,composerTool:s,prompt:c,selectedModel:l,selectedVariant:u,selectedSkills:d,availableModels:f,availableSkills:p,isLoadingAgentSettings:m,isSending:h,isUpdatingMode:g,showStartBuilding:_,composerDisabledReason:v,onBack:y,onRetry:b,onStop:x,onModeChange:S,onStartBuilding:C,onPromptChange:w,onModelChange:T,onVariantChange:E,onSkillsChange:D,onPromptKeyDown:O,onSubmit:k,onResolveQuestionSet:A,liveResponseTiming:j,isLargeScreen:M})=>{if(!e)return(0,X.jsx)(_9,{title:`Choose a project`,description:`Select a project before opening the chat workspace.`});if(n&&i)return(0,X.jsx)(_9,{title:`Chat unavailable`,description:i,action:(0,X.jsx)(Q,{variant:`warning`,onClick:b,children:`Retry chat`})});if(n&&(!t||t.id!==n))return(0,X.jsx)(R9,{title:`Loading chat`,backLabel:`Back to chats`,onBack:y,children:(0,X.jsx)(v9,{text:`Loading chat transcript...`})});let N=t?.mode??o,P=f.length>0,F=f.find(e=>e.id===l)??null,I=I9(t?.messages),L=M9(t?.messages),R=!!L,z=pF(t?.post_build_check)?qb.t(`common:postBuildChecks.blockedReason`):R?qb.t(`common:questionSet.waitForResolution`):v,ee=t?.agent_status===`running`?(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`gap-2`,disabled:a,onClick:x,children:[a?(0,X.jsx)(Ov,{className:`h-4 w-4 animate-spin`}):(0,X.jsx)(jv,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:a?`Interrupting...`:`Interrupt`})]}):null,B=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(rC,{variant:N===`plan`?`info`:`success`,children:N}),(0,X.jsx)(rC,{variant:`outline`,children:t?.tool??s}),t?.agent_status?(0,X.jsx)(rC,{variant:`outline`,children:t.agent_status}):null]}),V=P?(0,X.jsx)(_Y,{model:l,variant:u,skills:d,showModelSelector:!0,showSkillsSelector:!0,availableModels:f,availableSkills:p,selectedModel:F,onModelChange:T,onVariantChange:E,onSkillsChange:D,modelSelectId:`mobile-chat-model-selector`,variantSelectId:`mobile-chat-variant-selector`,skillsSelectId:`mobile-chat-skills-selector`,disabled:!!z||h}):m?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading model controls...`}):null,H=!M&&V?(0,X.jsx)(B9,{controls:V}):V,U=(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(HY,{value:N,disabled:!!z||h||g,onChange:S}),_&&(0,X.jsx)(W8,{disabled:h||g,onClick:C})]}),W=t?(0,X.jsx)(`p`,{className:`text-xs leading-5 text-muted-foreground`,children:qb.t(`common:mobileApp.agentSelector.sessionLocked`,{agent:t.tool})}):null,te=M?void 0:({showThinkingControl:e})=>(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 py-1`,children:[U,(0,X.jsx)(`div`,{className:`ml-auto`,children:e})]}),ne=`mobile-chat:${n??`new`}:${r}`;return(0,X.jsx)(R9,{title:t?.title??`New chat`,backLabel:`Back to chats`,onBack:y,action:ee,children:(0,X.jsx)(U8,{projectId:e,agentRunParentType:t?`chat`:null,agentRunParentId:t?.id??null,messages:I,internalLog:t?.agent_log??null,currentThinkingMessageId:t?.agent_message_id??null,previousThinkingLog:t?.previous_agent_log??null,previousThinkingMessageId:t?.previous_agent_message_id??null,pendingAgentTitle:t?.title??`Archon`,streamingResponse:t?.streaming_response??null,isRunning:t?.agent_status===`running`,pendingAgentRevealKey:j?.turnKey??null,liveResponseTiming:j,canShowComposer:!0,header:M?(0,X.jsx)(L9,{title:t?.title??`New chat`,subtitle:t?.target_label_snapshot??`Project root`,badges:B}):te,composerControls:M?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[W,U]}):W,composerInlineControls:H,composerTheme:N,forceScrollToBottomKey:ne,layoutKey:ne,scrollLayoutKey:ne,composerFocusNonce:r,blurComposerOnSendStart:!M,followUpPrompt:c,followUpPlaceholder:n?`Continue this chat`:N===`plan`?`Ask Archon to scope or reason through project work`:`Ask Archon to build or verify something in this project`,emptyStateText:n?`No messages yet.`:`Start a new project chat from this phone.`,renderMessageBody:e=>{let n=e.metadata?.ask_question;if(!(e.role!==`assistant`||!n||!t))return(0,X.jsx)(QJ,{messageContent:e.content,questionSet:n,storageKey:UJ({parentType:`chat`,parentId:t.id,setId:n.id}),isActive:n.status===`pending`&&L?.id===e.id,isDisabled:t.agent_status===`running`||h||g,onResolve:t=>A(e.id,t)})},isSendingFollowUp:h,isComposerSubmitDisabled:!!z,postBuildCheck:t?.post_build_check,followUpDisabledReason:z??void 0,hidePendingAgentTitle:!M,onFollowUpPromptChange:w,onFollowUpKeyDown:O,onFollowUpSubmit:k},ne)})},Eve=e=>(e??[]).map(e=>({id:e.id,role:e.role,kind:e.kind,content:e.content,created_at:e.created_at,ticket_id:null,ticket_proposals:null,metadata:e.metadata,responseTiming:e.response_timing?KK(e.response_timing):null,transcript_runs:e.transcript_runs??null})),Dve=e=>{if(!e)return null;for(let t=e.length-1;t>=0;--t)if(e[t].kind===`grill-question`)return e[t].id;return null},G9=e=>qb.t(`common:mobileApp.${e}`),K9=({selectedProjectId:e,specSession:t,specSessionId:n,openNonce:r,error:i,isStopping:a,composerMode:o,composerTool:s,prompt:c,selectedModel:l,selectedVariant:u,selectedSkills:d,availableModels:f,availableSkills:p,isLoadingAgentSettings:m,isSending:h,isUpdatingMode:g,composerDisabledReason:_,targetWarning:v,targetActionLabel:y,targetActionError:b,isRestoringTarget:x,onBack:S,onRetry:C,onStop:w,onModeChange:T,onPromptChange:E,onModelChange:D,onVariantChange:O,onSkillsChange:k,onPromptKeyDown:A,onSubmit:j,onSubmitAnswer:M,onResolveQuestionSet:N,onRestoreTarget:P,liveResponseTiming:F,isLargeScreen:I})=>{if(!e)return(0,X.jsx)(_9,{title:G9(`specList.emptyTitle`),description:`Select a project before opening the spec workspace.`});if(n&&i)return(0,X.jsx)(_9,{title:G9(`specDetail.unavailableTitle`),description:i,action:(0,X.jsx)(Q,{variant:`warning`,onClick:C,children:G9(`specDetail.retry`)})});if(n&&(!t||t.id!==n))return(0,X.jsx)(R9,{title:G9(`specDetail.loadingTitle`),backLabel:G9(`specDetail.back`),onBack:S,children:(0,X.jsx)(v9,{text:G9(`specDetail.loading`)})});let L=t?.mode??o,R=f.length>0,z=f.find(e=>e.id===l)??null,ee=Eve(t?.messages),B=Dve(t?.messages),V=M9(t?.messages),H=V?qb.t(`common:questionSet.waitForResolution`):_,U=t?.agent_status===`running`,W=U?(0,X.jsxs)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`gap-2`,disabled:a,onClick:w,children:[a?(0,X.jsx)(Ov,{className:`h-4 w-4 animate-spin`}):(0,X.jsx)(jv,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:G9(a?`specDetail.interrupting`:`specDetail.interrupt`)})]}):null,te=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(rC,{variant:L===`grill`?`info`:`success`,children:L}),(0,X.jsx)(rC,{variant:`outline`,children:t?.tool??s}),t?.agent_status?(0,X.jsx)(rC,{variant:`outline`,children:t.agent_status}):null]}),ne=R?(0,X.jsx)(_Y,{model:l,variant:u,skills:d,showModelSelector:!0,showSkillsSelector:!0,availableModels:f,availableSkills:p,selectedModel:z,onModelChange:D,onVariantChange:O,onSkillsChange:k,modelSelectId:`mobile-spec-model-selector`,variantSelectId:`mobile-spec-variant-selector`,skillsSelectId:`mobile-spec-skills-selector`,disabled:!!H||h}):s===`opencode`&&m?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading model controls...`}):null,re=!I&&ne?(0,X.jsx)(B9,{controls:ne}):ne,ie={rationaleLabel:qb.t(`common:specView.grill.rationaleLabel`),suggestionsLabel:qb.t(`common:specView.grill.suggestionsLabel`),recommendedSuggestionLabel:qb.t(`common:specView.grill.recommendedSuggestionLabel`),answerPlaceholder:qb.t(`common:specView.grill.answerPlaceholder`),submitLabel:qb.t(`common:specView.grill.submitLabel`),submittingLabel:qb.t(`common:specView.grill.submittingLabel`)},ae=e=>{if(e.role!==`assistant`)return;let n=e.metadata,r=n?.ask_question;if(r&&t)return(0,X.jsx)(QJ,{messageContent:e.content,questionSet:r,storageKey:UJ({parentType:`spec`,parentId:t.id,setId:r.id}),isActive:r.status===`pending`&&V?.id===e.id,isDisabled:!!v||U||h||g,onResolve:t=>N(e.id,t)});if(e.kind!==`grill-question`)return;let i=n?.grill_question;if(i)return(0,X.jsx)(M5,{question:i,isActive:U?!1:e.id===B&&t?.agent_status!==`running`&&t?.mode===`grill`,isDisabled:!!v||h||g,labels:ie,onSubmitAnswer:M})},G=(0,X.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:(0,X.jsx)(N5,{on:L===`grill`,disabled:!!H||h||g,onToggle:e=>T(e?`grill`:`standard`),tooltipContent:qb.t(`common:specView.grill.toggleTooltip`),ariaLabelOn:qb.t(`common:specView.grill.toggleAriaLabelOn`),ariaLabelOff:qb.t(`common:specView.grill.toggleAriaLabelOff`)})}),oe=t?(0,X.jsx)(`p`,{className:`text-xs leading-5 text-muted-foreground`,children:qb.t(`common:mobileApp.agentSelector.sessionLocked`,{agent:t.tool})}):null,se=I?void 0:({showThinkingControl:e})=>(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 py-1`,children:[G,(0,X.jsx)(`div`,{className:`ml-auto`,children:e})]}),ce=`mobile-spec:${n??`new`}:${r}`;return(0,X.jsxs)(R9,{title:t?.title??G9(`specDetail.newSpecTitle`),backLabel:G9(`specDetail.back`),onBack:S,action:W,children:[v&&(0,X.jsxs)(`div`,{className:`mb-3 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-sm text-amber-100`,children:[(0,X.jsx)(`p`,{children:v}),y&&(0,X.jsx)(Q,{type:`button`,size:`sm`,variant:`outline`,className:`mt-2`,disabled:x,onClick:P,children:x?G9(`specDetail.switchingBack`):y}),b&&(0,X.jsx)(`p`,{className:`mt-2 text-red-200`,children:b})]}),(0,X.jsx)(U8,{projectId:e,agentRunParentType:n?`spec`:null,agentRunParentId:n,messages:ee,internalLog:t?.agent_log??null,currentThinkingMessageId:t?.agent_message_id??null,previousThinkingLog:t?.previous_agent_log??null,previousThinkingMessageId:t?.previous_agent_message_id??null,pendingAgentTitle:t?.title??G9(`specDetail.newSpecTitle`),streamingResponse:t?.streaming_response??null,isRunning:U,pendingAgentRevealKey:F?.turnKey??null,liveResponseTiming:F,canShowComposer:!0,header:I?(0,X.jsx)(L9,{title:t?.title??G9(`specDetail.newSpecTitle`),subtitle:t?.first_user_message_preview??null,badges:te}):se,composerControls:I?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[oe,G]}):oe,composerInlineControls:re,composerTheme:`default`,forceScrollToBottomKey:ce,layoutKey:ce,scrollLayoutKey:ce,composerFocusNonce:r,blurComposerOnSendStart:!I,followUpPrompt:c,followUpPlaceholder:G9(n?`specDetail.composerPlaceholder`:`specDetail.composerPlaceholderDraft`),emptyStateText:G9(n?`specDetail.emptyMessages`:`specDetail.emptyDraft`),renderMessageBody:ae,isSendingFollowUp:h,isComposerSubmitDisabled:!!H,followUpDisabledReason:H??void 0,hidePendingAgentTitle:!I,onFollowUpPromptChange:E,onFollowUpKeyDown:A,onFollowUpSubmit:j},ce)]})},q9=({selectedProjectId:e,ticketId:t,ticket:n,openNonce:r,error:i,actionState:a,actionError:o,followUpPrompt:s,followUpSelectedModel:c,followUpSelectedVariant:l,followUpSelectedSkills:u,availableModels:d,availableSkills:f,isLoadingAgentSettings:m,isSendingFollowUp:h,followUpError:g,onBack:_,onRetry:v,onAction:y,onFollowUpPromptChange:b,onFollowUpModelChange:x,onFollowUpVariantChange:S,onFollowUpSkillsChange:C,onFollowUpKeyDown:w,onFollowUpSubmit:T,onResolveQuestionSet:E,liveResponseTiming:D,isLargeScreen:O})=>{let[k,A]=(0,p.useState)(`transcript`);if((0,p.useEffect)(()=>{A(`transcript`)},[r,t]),!e)return(0,X.jsx)(_9,{title:`Choose a project`,description:`Select a project before opening ticket details from this phone.`});if(!t)return(0,X.jsx)(_9,{title:`Choose a ticket`,description:`Open a ticket to review its transcript and continue the workflow.`});if(i)return(0,X.jsx)(_9,{title:`Ticket unavailable`,description:i,action:(0,X.jsx)(Q,{variant:`warning`,onClick:v,children:`Retry ticket`})});if(!n||n.id!==t)return(0,X.jsx)(R9,{title:`Loading ticket`,backLabel:`Back to tickets`,onBack:_,children:(0,X.jsx)(v9,{text:`Loading ticket details...`})});let j=u3(n,{requireWorktree:!0}),M=I9(n.messages,n.id),N=M9(n.messages),P=!!N,F=pF(n.post_build_check),I=F?qb.t(`common:postBuildChecks.blockedReason`):P?qb.t(`common:questionSet.waitForResolution`):j.disabledReason,L=d.find(e=>e.id===c)??null,R=yF(n,`opencode`)===`opencode`&&d.length>0?(0,X.jsx)(_Y,{model:c,variant:l,skills:u,showModelSelector:!0,showSkillsSelector:!0,availableModels:d,availableSkills:f,selectedModel:L,onModelChange:x,onVariantChange:S,onSkillsChange:C,modelSelectId:`mobile-ticket-follow-up-model-selector`,variantSelectId:`mobile-ticket-follow-up-variant-selector`,skillsSelectId:`mobile-ticket-follow-up-skills-selector`,disabled:!!I||h}):yF(n,`opencode`)===`opencode`&&m?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading model controls...`}):null,z=!O&&R?(0,X.jsx)(B9,{controls:R}):R,ee=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(rC,{variant:C9(x9(n)),children:S9(n)}),n.tool?(0,X.jsx)(rC,{variant:`outline`,children:n.tool}):null,n.agent_status?(0,X.jsx)(rC,{variant:`outline`,children:n.agent_status}):null,n.branch?(0,X.jsx)(rC,{variant:`outline`,children:n.branch}):null,n.bundle?.name?(0,X.jsx)(rC,{variant:`outline`,children:n.bundle.name}):null]}),B=`mobile-ticket:${n.id}:${r}`,V=e=>{let t=e.metadata?.ask_question;if(!(e.role!==`assistant`||!t))return(0,X.jsx)(QJ,{messageContent:e.content,questionSet:t,storageKey:UJ({parentType:`ticket`,parentId:n.id,setId:t.id}),isActive:t.status===`pending`&&N?.id===e.id,isDisabled:n.agent_status===`running`||h,onResolve:t=>E(e.id,t)})},H=(0,X.jsx)(z9,{value:k,onTranscript:()=>A(`transcript`),onDetails:()=>A(`details`)});return(0,X.jsx)(R9,{title:n.title,backLabel:`Back to tickets`,onBack:_,subheader:O?void 0:H,children:O?(0,X.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col gap-3 overflow-hidden pt-3`,children:[(0,X.jsx)(V9,{ticket:n,badges:ee,actionState:a,actionError:o,onAction:y,className:`shrink-0`}),(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,X.jsx)(aY,{projectId:e,followUpTicketId:n.id,messages:M,internalLog:n.agent_log??null,currentThinkingMessageId:n.agent_message_id??null,previousThinkingLog:n.previous_agent_log??null,previousThinkingMessageId:n.previous_agent_message_id??null,pendingAgentTitle:n.title,liveResponseTiming:D,streamingResponse:n.streaming_response??null,isRunning:n.agent_status===`running`,canShowComposer:!0,followUpComposerControls:R,composerTheme:oy(n.state),forceScrollToBottomKey:B,layoutKey:B,scrollLayoutKey:B,followUpPrompt:s,followUpPlaceholder:j.placeholder,emptyStateText:`No follow-up messages yet.`,renderMessageBody:V,isSendingFollowUp:h,isComposerSubmitDisabled:P||F,postBuildCheck:n.post_build_check,followUpDisabledReason:I??void 0,onFollowUpPromptChange:b,onFollowUpKeyDown:w,onFollowUpSubmit:T},B)}),g?(0,X.jsx)(`p`,{className:`shrink-0 text-sm text-red-200`,children:g}):null]}):k===`details`?(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,X.jsx)(V9,{ticket:n,badges:ee,actionState:a,actionError:o,onAction:y,className:`h-full`})}):(0,X.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,X.jsx)(aY,{projectId:e,followUpTicketId:n.id,messages:M,internalLog:n.agent_log??null,currentThinkingMessageId:n.agent_message_id??null,previousThinkingLog:n.previous_agent_log??null,previousThinkingMessageId:n.previous_agent_message_id??null,pendingAgentTitle:n.title,liveResponseTiming:D,streamingResponse:n.streaming_response??null,isRunning:n.agent_status===`running`,canShowComposer:!0,followUpComposerControls:z,composerTheme:oy(n.state),surfaceVariant:`chat`,composerSize:`compact-on-laptop`,forceScrollToBottomKey:B,layoutKey:B,scrollLayoutKey:B,followUpPrompt:s,followUpPlaceholder:j.placeholder,emptyStateText:`No follow-up messages yet.`,renderMessageBody:V,isSendingFollowUp:h,isComposerSubmitDisabled:P||F,postBuildCheck:n.post_build_check,followUpDisabledReason:I??void 0,onFollowUpPromptChange:b,onFollowUpKeyDown:w,onFollowUpSubmit:T},B),g?(0,X.jsx)(`p`,{className:`shrink-0 px-1 pt-2 text-sm text-red-200`,children:g}):null]})})},Ove=[],kve=[],Ave=[],J9=e=>qb.t(`common:mobileApp.${e}`),Y9=`Project root has uncommitted changes. Confirm branch switch to continue.`,X9=(e,t)=>{if(!e)return e;let n=new Map(t.tickets.map(e=>[e.id,e]));return e.map(e=>n.get(e.id)??e)},jve=()=>{let e=new URLSearchParams(window.location.search),t=new URLSearchParams(window.location.hash.slice(1)),n=e.get(`mobileAccessId`)??``,r=e.get(`pairingId`)??``,i=t.get(`pairingSecret`)??``;return!n||!r||!i?null:{mobileAccessId:n,pairingId:r,pairingSecret:i}},Mve=()=>{window.history.replaceState({},``,`/mobile`)},Nve=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()},Z9=(e,t)=>e instanceof Ge&&e.message?e.message:t,Q9=e=>({status:`authenticated`,csrfToken:e,projects:null,selectedProjectId:null,projectError:null,projectSummary:null,projectSummaryError:null,chatSessions:null,chatSessionsError:null,selectedChatSessionId:null,chatSessionDetail:null,chatSessionDetailError:null,tickets:null,ticketsError:null,selectedBundleId:null,bundleDetail:null,bundleDetailError:null,selectedTicketId:null,ticketDetail:null,ticketDetailError:null,specSessions:null,specSessionsError:null,selectedSpecSessionId:null,specSessionDetail:null,specSessionDetailError:null}),$9=(e=`pairing_required`)=>({status:`unauthenticated`,reason:e}),Pve=e=>e instanceof Ge&&(e.status===401||e.status===403),Fve=()=>{let[e,t]=(0,p.useState)({status:`checking`}),[n,r]=(0,p.useState)(`connecting`),[i,a]=(0,p.useState)(`opencode`),[o,s]=(0,p.useState)(Br),[c,l]=(0,p.useState)(null),[u,d]=(0,p.useState)(`overview`),[f,m]=(0,p.useState)(!1),[h,g]=(0,p.useState)(!1),[_,v]=(0,p.useState)(!1),[y,b]=(0,p.useState)(!1),[x,S]=(0,p.useState)(!1),[C,w]=(0,p.useState)(!1),[T,E]=(0,p.useState)(``),[D,O]=(0,p.useState)(`build`),[k,A]=(0,p.useState)(``),[j,M]=(0,p.useState)(``),[N,P]=(0,p.useState)([]),[F,I]=(0,p.useState)([]),[L,R]=(0,p.useState)([]),[z,ee]=(0,p.useState)(null),[B,V]=(0,p.useState)(!1),[H,U]=(0,p.useState)(!1),[W,te]=(0,p.useState)(!1),[ne,re]=(0,p.useState)(null),[ie,ae]=(0,p.useState)(null),[G,oe]=(0,p.useState)(null),[se,ce]=(0,p.useState)(!1),[le,ue]=(0,p.useState)(``),[de,fe]=(0,p.useState)(`standard`),[pe,me]=(0,p.useState)(``),[he,ge]=(0,p.useState)(``),[_e,ve]=(0,p.useState)([]),[ye,be]=(0,p.useState)(!1),[xe,Se]=(0,p.useState)(!1),[Ce,we]=(0,p.useState)(null),[Te,Ee]=(0,p.useState)(null),[De,Oe]=(0,p.useState)(null),[ke,Ae]=(0,p.useState)(0),[je,Me]=(0,p.useState)(null),[Ne,Pe]=(0,p.useState)(null),[Fe,Ie]=(0,p.useState)(null),[Le,K]=(0,p.useState)(null),[Re,ze]=(0,p.useState)(``),[Be,Ve]=(0,p.useState)(``),[He,q]=(0,p.useState)(``),[Ue,We]=(0,p.useState)([]),[J,qe]=(0,p.useState)(!1),[Je,Xe]=(0,p.useState)(null),[Ze,Y]=(0,p.useState)(null),[Qe,$e]=(0,p.useState)(``),[et,tt]=(0,p.useState)(!1),[nt,rt]=(0,p.useState)(null),[it,at]=(0,p.useState)(0),[ot,st]=(0,p.useState)(0),[ct,lt]=(0,p.useState)(0),[ut,dt]=(0,p.useState)(`transcript`),[ft,pt]=(0,p.useState)(null),[mt,ht]=(0,p.useState)(null),[gt,_t]=(0,p.useState)(!1),[vt,yt]=(0,p.useState)(!1),[bt,xt]=(0,p.useState)(!1),[St,Ct]=(0,p.useState)(null),[wt,Tt]=(0,p.useState)(null),Et=(0,p.useRef)(null),Dt=(0,p.useRef)(null),Ot=(0,p.useRef)(null),kt=(0,p.useRef)(null),At=(0,p.useRef)(null),jt=(0,p.useRef)(0),Mt=(0,p.useRef)(!1),Nt=(0,p.useRef)(0),Pt=(0,p.useCallback)(e=>Pve(e)?(t($9(`session_revoked`)),r(`unavailable`),m(!1),g(!1),v(!1),b(!1),ce(!1),!0):!1,[]),Ft=(0,p.useCallback)(async(e,n,r,i)=>{try{let a=await x_e(n,r,i);t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedTicketId!==r?t:{...t,ticketDetail:a,ticketDetailError:null})}catch(i){if(!Ye(i)){if(Pt(i))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedTicketId!==r?t:{...t,ticketDetail:null,ticketDetailError:Z9(i,`Unable to load ticket details.`)})}}},[Pt]),It=(0,p.useCallback)(async(e,n,r,i)=>{try{let a=await T_e(n,r,i);t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedBundleId!==r?t:{...t,bundleDetail:a,bundleDetailError:null,tickets:X9(t.tickets,a)})}catch(i){if(!Ye(i)){if(Pt(i))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedBundleId!==r?t:{...t,bundleDetail:null,bundleDetailError:Z9(i,`Unable to load bundle details.`)})}}},[Pt]),Lt=(0,p.useCallback)(async(e,n,r)=>{try{let i=await b_e(n,r);t(t=>{if(t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n)return t;let r=t.selectedTicketId&&i.some(e=>e.id===t.selectedTicketId)?t.selectedTicketId:null,a=t.selectedBundleId&&i.some(e=>e.worktree_bundle_id===t.selectedBundleId)?t.selectedBundleId:null;return{...t,tickets:i,ticketsError:null,selectedBundleId:a,bundleDetail:a?t.bundleDetail:null,bundleDetailError:a?t.bundleDetailError:null,selectedTicketId:r,ticketDetail:r?t.ticketDetail:null,ticketDetailError:r?t.ticketDetailError:null}})}catch(r){if(!Ye(r)){if(Pt(r))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n?t:{...t,tickets:null,ticketsError:Z9(r,`Unable to load project tickets.`),selectedBundleId:null,bundleDetail:null,bundleDetailError:null,selectedTicketId:null,ticketDetail:null,ticketDetailError:null})}}},[Pt]),Rt=(0,p.useCallback)(async(e,n,r,i)=>{try{let a=await y_e(n,r,i);t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedChatSessionId!==r?t:{...t,chatSessionDetail:a,chatSessionDetailError:null})}catch(i){if(!Ye(i)){if(Pt(i))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedChatSessionId!==r?t:{...t,chatSessionDetail:null,chatSessionDetailError:Z9(i,`Unable to load chat transcript.`)})}}},[Pt]),zt=(0,p.useCallback)(async(e,n,r)=>{try{let i=await v_e(n,r);t(t=>{if(t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n)return t;let r=t.selectedChatSessionId&&i.some(e=>e.id===t.selectedChatSessionId)?t.selectedChatSessionId:null;return{...t,chatSessions:i,chatSessionsError:null,selectedChatSessionId:r,chatSessionDetail:r?t.chatSessionDetail:null,chatSessionDetailError:r?t.chatSessionDetailError:null}})}catch(r){if(!Ye(r)){if(Pt(r))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n?t:{...t,chatSessions:null,chatSessionsError:Z9(r,`Unable to load project chats.`),selectedChatSessionId:null,chatSessionDetail:null,chatSessionDetailError:null})}}},[Pt]),Bt=(0,p.useCallback)(async(e,n,r,i)=>{try{let a=await P_e(n,r,i);t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedSpecSessionId!==r?t:{...t,specSessionDetail:a,specSessionDetailError:null})}catch(i){if(!Ye(i)){if(Pt(i))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n||t.selectedSpecSessionId!==r?t:{...t,specSessionDetail:null,specSessionDetailError:Z9(i,J9(`specDetail.detailError`))})}}},[Pt]),Vt=(0,p.useCallback)(async(e,n,r)=>{try{let i=await N_e(n,r);t(t=>{if(t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n)return t;let r=t.selectedSpecSessionId&&i.some(e=>e.id===t.selectedSpecSessionId)?t.selectedSpecSessionId:null;return{...t,specSessions:i,specSessionsError:null,selectedSpecSessionId:r,specSessionDetail:r?t.specSessionDetail:null,specSessionDetailError:r?t.specSessionDetailError:null}})}catch(r){if(!Ye(r)){if(Pt(r))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n?t:{...t,specSessions:null,specSessionsError:Z9(r,J9(`specDetail.listError`)),selectedSpecSessionId:null,specSessionDetail:null,specSessionDetailError:null})}}},[Pt]),Ht=(0,p.useCallback)(async(e,n,r)=>{try{let i=await p_e(n,r);t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n?t:{...t,projectSummary:i,projectSummaryError:null})}catch(r){if(!Ye(r)){if(Pt(r))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e||t.selectedProjectId!==n?t:{...t,projectSummary:null,projectSummaryError:Z9(r,`Unable to load the project summary.`)})}}},[Pt]),Ut=(0,p.useCallback)(async(e,n,r=!1)=>{yt(!0),ht(null);try{let[i,a]=await Promise.all([__e(e,n),r?a9(n):Promise.resolve(null)]),o=Et.current;if(o&&o!==e)return;if(pt(i),ht(null),Ct(null),a){let n=a.find(t=>t.id===e);n&&t(t=>t.status!==`authenticated`||t.selectedProjectId!==e?t:{...t,projects:t.projects?.map(t=>t.id===e?{...t,active_target_kind:n.active_target_kind,active_target_bundle_id:n.active_target_bundle_id}:t)??t.projects})}return!0}catch(t){if(!Ye(t)){if(Pt(t))return;let n=Et.current;if(n&&n!==e)return;pt(null),ht(Z9(t,`Unable to load project target options.`))}return!1}finally{n?.aborted||yt(!1)}},[Pt]),Wt=(0,p.useCallback)(e=>{t(t=>t.status===`authenticated`?{...t,projects:t.projects?.map(t=>t.id===e.id?e:t)??t.projects,projectSummary:t.projectSummary?.project.id===e.id?{...t.projectSummary,project:e}:t.projectSummary}:t)},[]),Gt=(0,p.useCallback)(async t=>{if(e.status!==`authenticated`)return;let n=Nt.current+1;Nt.current=n;try{let r=await d_e(t,e.csrfToken);Nt.current===n&&a(r.tool)}catch{}},[e]),Kt=(0,p.useCallback)(async(e,n,r)=>{try{let i=await a9(n),a=r&&i.some(e=>e.id===r)?r:i[0]?.id??null;t(t=>{if(t.status!==`authenticated`||t.csrfToken!==e)return t;let n=!!(t.selectedProjectId&&a&&t.selectedProjectId===a);return{...t,projects:i,selectedProjectId:a,projectError:null,projectSummary:n?t.projectSummary:null,projectSummaryError:n?t.projectSummaryError:null,chatSessions:n?t.chatSessions:null,chatSessionsError:n?t.chatSessionsError:null,selectedChatSessionId:n?t.selectedChatSessionId:null,chatSessionDetail:n?t.chatSessionDetail:null,chatSessionDetailError:n?t.chatSessionDetailError:null,tickets:n?t.tickets:null,ticketsError:n?t.ticketsError:null,selectedBundleId:n?t.selectedBundleId:null,bundleDetail:n?t.bundleDetail:null,bundleDetailError:n?t.bundleDetailError:null,selectedTicketId:n?t.selectedTicketId:null,ticketDetail:n?t.ticketDetail:null,ticketDetailError:n?t.ticketDetailError:null,specSessions:n?t.specSessions:null,specSessionsError:n?t.specSessionsError:null,selectedSpecSessionId:n?t.selectedSpecSessionId:null,specSessionDetail:n?t.specSessionDetail:null,specSessionDetailError:n?t.specSessionDetailError:null}});let o=a?i.find(e=>e.id===a)??null:null;a&&(Ht(e,a,n),o?.active_target_kind===`bundle`&&Ut(a,n),zt(e,a,n),Vt(e,a,n),Lt(e,a,n))}catch(n){if(!Ye(n)){if(Pt(n))return;t(t=>t.status!==`authenticated`||t.csrfToken!==e?t:{...t,projects:t.projects??[],projectError:Z9(n,`Unable to load projects from desktop Archon.`)})}}},[Pt,zt,Ht,Ut,Vt,Lt]),qt=(0,p.useCallback)(async e=>{t({status:`checking`}),r(`connecting`);try{let n=await uve(e);if(n.authenticated&&n.csrf_token){r(`connecting`),t(Q9(n.csrf_token)),Kt(n.csrf_token,e,n.preferred_project_id);return}t($9())}catch(e){Ye(e)||t({status:`error`,message:Z9(e,`Mobile access is unavailable. Make sure it is still enabled on desktop Archon.`)})}},[Kt]),Jt=(0,p.useCallback)((e,n,i)=>{r(`connecting`),t(Q9(e)),Kt(e,i,n)},[Kt]);(0,p.useEffect)(()=>{let e=new AbortController;if(window.location.pathname===`/mobile/pair`){let n=jve();return Mve(),n?(t({status:`pairing`}),dve(n,e.signal).then(e=>{t({status:`pairing_confirmation`,payload:n,displayCode:e.display_code,expiresAt:e.expires_at,error:null})}).catch(e=>{t({status:`error`,message:Z9(e,`Pairing failed. Regenerate the pairing link from desktop Archon and try again.`)})}),()=>e.abort()):(t({status:`error`,message:`Pairing link is missing required pairing details.`}),()=>e.abort())}return qt(e.signal),()=>e.abort()},[Jt,qt]),(0,p.useEffect)(()=>{if(e.status!==`authenticated`)return;let t=new AbortController,n=Nt.current;return u_e(t.signal).then(e=>{Nt.current===n&&a(e.tool)}).catch(e=>{Ye(e)||Pt(e)}),f_e(t.signal).then(e=>s(e.length>0?e:Br())).catch(e=>{Ye(e)||Pt(e)||s(Br())}),()=>t.abort()},[e.status,Pt]);let Yt=e.status===`authenticated`?e.csrfToken:null,Xt=e.status===`authenticated`?e.selectedProjectId:null,Zt=e.status===`authenticated`?e.selectedChatSessionId:null,Qt=e.status===`authenticated`?e.selectedBundleId:null,$t=e.status===`authenticated`?e.selectedTicketId:null,en=e.status===`authenticated`?e.selectedSpecSessionId:null,tn=e.status===`authenticated`?e.projects?.find(t=>t.id===e.selectedProjectId)??null:null,nn=e.status===`authenticated`?e.chatSessionDetail:null,rn=e.status===`authenticated`?e.bundleDetail:null,an=e.status===`authenticated`?e.ticketDetail:null,on=e.status===`authenticated`?e.specSessionDetail:null,sn=!vt&&ft&&`current_branch`in ft?{status:`ready`,branch:ft.current_branch}:null,cn=on?.target_available===!1?on.target_unavailable_reason??J9(`specDetail.targetUnavailable`):null,ln=!!(on?.target_kind===`repo_root`&&on.target_branch_snapshot&&tn?.active_target_kind!==`bundle`),un=on?.target_kind===`bundle`&&mt?qb.t(`common:mobileApp.specDetail.targetRefreshError`,{error:mt}):ln&&mt?qb.t(`common:mobileApp.specDetail.targetLoadError`,{error:mt}):null,dn=on&&vt||ln&&!sn&&!un?J9(`specDetail.targetLoading`):un,fn=!!(on&&!cn&&!dn&&!s5({activeProject:tn,activeProjectBranchState:sn,session:on})),pn=fn&&on?qb.t(`common:mobileApp.specDetail.targetMismatch`,{sessionTarget:l5(on),currentTarget:u5({activeProject:tn,activeProjectBranchState:sn})}):null,mn=y9(tn,ft),hn=vt&&(!tn||tn.active_target_kind===`bundle`),gn=_ve(),_n=nn?.tool??i,vn=on?.tool??i,yn=u===`spec`?vn:u===`tickets`?an?.tool??i:_n,bn=z===yn,xn=bn?F:kve,Sn=bn?L:Ave,Cn=!!(Yt&&Xt)&&(!bn||B),wn=qb.t(`common:mobileApp.agentSettings.loading`),Tn=!!M9(nn?.messages),En=!!M9(on?.messages),Dn=!!M9(an?.messages),On=e.status!==`authenticated`||!e.selectedProjectId?`Choose a project before sending a prompt.`:Cn?wn:W?`Wait for the chat mode change before sending another prompt.`:nn?.agent_status===`running`?`Stop or wait for the current response before sending another prompt.`:Tn?qb.t(`common:questionSet.waitForResolution`):null,kn=!!(nn&&KY(nn,Tn)),An=e.status!==`authenticated`||!e.selectedProjectId?`Choose a project before sending a prompt.`:Cn?wn:cn||dn||pn||(xe?`Wait for the spec mode change before sending another prompt.`:on?.agent_status===`running`?`Stop or wait for the current response before sending another prompt.`:En?qb.t(`common:questionSet.waitForResolution`):null),jn=!gn&&(u===`tickets`&&(_&&!!$t||h&&!!Qt)||u===`chats`&&y||u===`spec`&&se);(0,p.useEffect)(()=>{Et.current=Xt},[Xt]),(0,p.useEffect)(()=>{Xt||(pt(null),ht(null),Ct(null),_t(!1),yt(!1),xt(!1))},[Xt]),(0,p.useEffect)(()=>{Dt.current=Zt},[Zt]),(0,p.useEffect)(()=>{Ot.current=Qt},[Qt]),(0,p.useEffect)(()=>{kt.current=$t},[$t]),(0,p.useEffect)(()=>{At.current=en},[en]),(0,p.useEffect)(()=>{if(!Yt||!Xt){I([]),R([]),ee(null),V(!1);return}let e=new AbortController;return V(!0),Promise.all([K_e(yn,e.signal),yn===`opencode`?q_e(yn,Xt,e.signal):Promise.resolve([])]).then(([t,n])=>{e.signal.aborted||(I(t),R(n),ee(yn))}).catch(e=>{Pt(e)||Ye(e)||(I([]),R([]),ee(yn))}).finally(()=>{e.signal.aborted||V(!1)}),()=>e.abort()},[yn,Yt,Pt,Xt]),(0,p.useEffect)(()=>{let e=ew(tn?.helper_models,_n);A(nn?nn.model??``:e.model??(_n===`opencode`?tn?.helper_model:null)??``),M(nn?nn.variant??``:e.variant??(_n===`opencode`?tn?.helper_variant:null)??``),P(nn?.skills??[])},[_n,nn,tn?.helper_model,tn?.helper_models,tn?.helper_variant]),(0,p.useEffect)(()=>{nn?.mode&&O(nn.mode)},[nn?.id,nn?.mode]),(0,p.useEffect)(()=>{if(nn)return;let e=xn.find(e=>e.id===k)??null;M(t=>e?e.variants.includes(t)?t:``:t)},[xn,nn,k]),(0,p.useEffect)(()=>{ze(``),Xe(null),Ve(an?.model??``),q(an?.variant??``),We(an?.skills??[])},[an?.id,an?.model,an?.skills,an?.variant]),(0,p.useEffect)(()=>{$e(``),rt(null)},[rn?.bundle.id]),(0,p.useEffect)(()=>{let e=ew(tn?.helper_models,vn);me(on?on.model??``:e.model??(vn===`opencode`?tn?.helper_model:null)??``),ge(on?on.variant??``:e.variant??(vn===`opencode`?tn?.helper_variant:null)??``),ve(on?.skills??[])},[vn,tn?.helper_model,tn?.helper_models,tn?.helper_variant,on]),(0,p.useEffect)(()=>{on?.mode&&fe(on.mode)},[on?.id,on?.mode]),(0,p.useEffect)(()=>{if(on)return;let e=xn.find(e=>e.id===pe)??null;ge(t=>e?e.variants.includes(t)?t:``:t)},[xn,on,pe]),(0,p.useEffect)(()=>{let e=xn.find(e=>e.id===Be)??null;q(t=>e?e.variants.includes(t)?t:``:t)},[xn,Be]),(0,p.useEffect)(()=>{if(!Yt)return;let e=mve();l(e),r(`connecting`);let t=()=>{let e=Et.current,t=Dt.current,n=Ot.current,r=kt.current,i=At.current;Kt(Yt,void 0,e),e&&(Ht(Yt,e),zt(Yt,e),Vt(Yt,e),Lt(Yt,e)),e&&t&&Rt(Yt,e,t),e&&n&&It(Yt,e,n),e&&r&&Ft(Yt,e,r),e&&i&&Bt(Yt,e,i)},n=()=>{r(`connected`),t()},i=()=>{r(`reconnecting`)},o=()=>{r(`unavailable`)},s=()=>{Kt(Yt,void 0,Et.current)},c=(e=null)=>{let t=Et.current;t&&(e?.project_id&&e.project_id!==t||Ht(Yt,t))},u=(e=null)=>{let t=Et.current;t&&(e?.project_id&&e.project_id!==t||zt(Yt,t))},d=(e=null)=>{let t=Et.current;t&&(e?.project_id&&e.project_id!==t||Lt(Yt,t))},f=(e=null)=>{let t=Et.current,n=Dt.current;!t||!n||e?.project_id&&e.project_id!==t||e?.id&&e.id!==n||Rt(Yt,t,n)},p=(e=null)=>{let t=Et.current,n=kt.current;!t||!n||e?.project_id&&e.project_id!==t||e?.id&&e.id!==n||Ft(Yt,t,n)},m=(e=null)=>{let t=Et.current,n=Ot.current;!t||!n||e?.project_id&&e.project_id!==t||It(Yt,t,n)},h=(e=null)=>{let t=Et.current;t&&(e?.project_id&&e.project_id!==t||Vt(Yt,t))},g=(e=null)=>{let t=Et.current,n=At.current;!t||!n||e?.project_id&&e.project_id!==t||e?.id&&e.id!==n||Bt(Yt,t,n)},_=e=>{e.tool!==`claude`&&e.tool!==`opencode`||(Nt.current+=1,a(e.tool))};return e.on(`connect`,n),e.on(`disconnect`,i),e.on(`connect_error`,o),e.on(`tool:updated`,_),e.on(`ticket:created`,c),e.on(`ticket:created`,d),e.on(`ticket:updated`,c),e.on(`ticket:updated`,d),e.on(`ticket:updated`,m),e.on(`ticket:updated`,p),e.on(`ticket:deleted`,s),e.on(`ticket:deleted`,d),e.on(`ticket:deleted`,m),e.on(`ticket-dependency:created`,c),e.on(`ticket-dependency:deleted`,c),e.on(`chat-session:created`,u),e.on(`chat-session:updated`,u),e.on(`chat-session:updated`,f),e.on(`chat-session:deleted`,u),e.on(`spec-session:created`,h),e.on(`spec-session:updated`,h),e.on(`spec-session:updated`,g),e.on(`spec-session:deleted`,h),()=>{e.off(`connect`,n),e.off(`disconnect`,i),e.off(`connect_error`,o),e.off(`tool:updated`,_),e.off(`ticket:created`,c),e.off(`ticket:created`,d),e.off(`ticket:updated`,c),e.off(`ticket:updated`,d),e.off(`ticket:updated`,m),e.off(`ticket:updated`,p),e.off(`ticket:deleted`,s),e.off(`ticket:deleted`,d),e.off(`ticket:deleted`,m),e.off(`ticket-dependency:created`,c),e.off(`ticket-dependency:deleted`,c),e.off(`chat-session:created`,u),e.off(`chat-session:updated`,u),e.off(`chat-session:updated`,f),e.off(`chat-session:deleted`,u),e.off(`spec-session:created`,h),e.off(`spec-session:updated`,h),e.off(`spec-session:updated`,g),e.off(`spec-session:deleted`,h),e.disconnect(),l(null)}},[Yt,It,Rt,zt,Ht,Kt,Bt,Vt,Ft,Lt]),(0,p.useEffect)(()=>{Qt||g(!1)},[Qt]),(0,p.useEffect)(()=>{$t||v(!1)},[$t]);let Mn=()=>{qt()},Nn=e=>{d(e),g(!1),v(!1),b(!1),ce(!1),Tt(null)},Pn=()=>{m(!0)},Fn=()=>{e.status!==`authenticated`||!e.selectedProjectId||(Ct(null),_t(!0),!ft&&!vt&&Ut(e.selectedProjectId))},In=()=>{e.status===`authenticated`&&(S(!0),pve(e.csrfToken).then(()=>t($9())).catch(e=>{Pt(e)||t({status:`error`,message:Z9(e,`Logout failed. Mobile access may have already been revoked from desktop Archon.`)})}).finally(()=>S(!1)))},Ln=()=>{if(e.status!==`pairing_confirmation`||C)return;let n=e.payload;w(!0),t({...e,error:null}),fve(n).then(e=>{if(e.authenticated&&e.csrf_token){window.history.replaceState({},``,`/mobile`),Jt(e.csrf_token,e.preferred_project_id);return}t($9())}).catch(e=>{t(t=>t.status===`pairing_confirmation`?{...t,error:Z9(e,`Pairing failed. Regenerate the pairing link from desktop Archon and try again.`)}:t)}).finally(()=>w(!1))},Rn=()=>{window.history.replaceState({},``,`/mobile`),t($9())},zn=()=>{e.status===`authenticated`&&(t({...e,projects:null,projectError:null}),Kt(e.csrfToken))},Bn=()=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,projectSummary:null,projectSummaryError:null}),Ht(e.csrfToken,e.selectedProjectId))},Vn=()=>{e.status!==`authenticated`||!e.selectedProjectId||(pt(null),ht(null),Ct(null),Ut(e.selectedProjectId))},Hn=()=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,chatSessions:null,chatSessionsError:null,selectedChatSessionId:null,chatSessionDetail:null,chatSessionDetailError:null}),zt(e.csrfToken,e.selectedProjectId))},Un=()=>{e.status!==`authenticated`||!e.selectedProjectId||!e.selectedChatSessionId||(t({...e,chatSessionDetail:null,chatSessionDetailError:null}),Rt(e.csrfToken,e.selectedProjectId,e.selectedChatSessionId))},Wn=()=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,tickets:null,ticketsError:null,selectedBundleId:null,bundleDetail:null,bundleDetailError:null,selectedTicketId:null,ticketDetail:null,ticketDetailError:null}),Lt(e.csrfToken,e.selectedProjectId))},Gn=()=>{e.status!==`authenticated`||!e.selectedProjectId||!e.selectedTicketId||(t({...e,ticketDetail:null,ticketDetailError:null}),Ft(e.csrfToken,e.selectedProjectId,e.selectedTicketId))},Kn=()=>{e.status!==`authenticated`||!e.selectedProjectId||!e.selectedBundleId||(t({...e,bundleDetail:null,bundleDetailError:null}),It(e.csrfToken,e.selectedProjectId,e.selectedBundleId))},qn=n=>{if(e.status!==`authenticated`)return;let r=e.projects?.find(e=>e.id===n)??null;Et.current=n,t({...e,selectedProjectId:n,projectSummary:null,projectSummaryError:null,chatSessions:null,chatSessionsError:null,selectedChatSessionId:null,chatSessionDetail:null,chatSessionDetailError:null,tickets:null,ticketsError:null,selectedBundleId:null,bundleDetail:null,bundleDetailError:null,selectedTicketId:null,ticketDetail:null,ticketDetailError:null,specSessions:null,specSessionsError:null,selectedSpecSessionId:null,specSessionDetail:null,specSessionDetailError:null}),Me(null),Pe(null),Ie(null),K(null),ae(null),K(null),Ee(null),rt(null),pt(null),ht(null),Ct(null),m(!1),_t(!1),g(!1),v(!1),b(!1),ce(!1),dt(`transcript`),Tt(null),d(`overview`),Ht(e.csrfToken,n),r?.active_target_kind===`bundle`&&Ut(n),zt(e.csrfToken,n),Vt(e.csrfToken,n),Lt(e.csrfToken,n)},Jn=async t=>{if(!(e.status!==`authenticated`||!e.selectedProjectId)){xt(!0),Ct(null);try{Wt(await d9(e.selectedProjectId,e.csrfToken,{kind:`bundle`,bundle_id:t})),_t(!1),Ht(e.csrfToken,e.selectedProjectId),await Ut(e.selectedProjectId)}catch(e){if(Pt(e))return;Ct(Z9(e,J9(`specDetail.updateTargetError`)))}finally{xt(!1)}}},Yn=async(t,n={})=>{if(e.status!==`authenticated`||!e.selectedProjectId)return;xt(!0),Ct(null);let r=r=>d9(e.selectedProjectId??``,e.csrfToken,{kind:`repo_root`,...t?{branch:t}:{},...n.createBranch===!1?{create_branch:!1}:{},...r?{confirm_dirty_switch:!0}:{}});try{let t;try{t=await r(n.confirmDirtySwitch===!0)}catch(e){if(!n.confirmDirtySwitch&&e instanceof Ge&&e.status===409&&e.message===Y9){if(!window.confirm(`${Y9}\n\nSwitch anyway?`))return;t=await r(!0)}else throw e}Wt(t),_t(!1),Ht(e.csrfToken,e.selectedProjectId),await Ut(e.selectedProjectId)}catch(e){if(Pt(e))return;Ct(Z9(e,J9(`specDetail.updateTargetError`)))}finally{xt(!1)}},Xn=un?Vn:()=>{if(!(!on||on.target_available===!1)){if(on.target_kind===`bundle`){on.target_bundle_id&&Jn(on.target_bundle_id);return}Yn(on.target_branch_snapshot??null,{createBranch:!1})}},Zn=n=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,selectedChatSessionId:n,chatSessionDetail:null,chatSessionDetailError:null}),ae(null),at(e=>e+1),b(!0),d(`chats`),Rt(e.csrfToken,e.selectedProjectId,n))},Qn=()=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,selectedChatSessionId:null,chatSessionDetail:null,chatSessionDetailError:null}),ae(null),E(``),at(e=>e+1),b(!0),d(`chats`))},$n=n=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,selectedBundleId:n,bundleDetail:null,bundleDetailError:null,selectedTicketId:null,ticketDetail:null,ticketDetailError:null}),Me(null),Pe(null),K(null),rt(null),Tt(null),dt(`transcript`),st(e=>e+1),g(!0),v(!1),d(`tickets`),It(e.csrfToken,e.selectedProjectId,n))},er=(n,r)=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,selectedTicketId:n,ticketDetail:null,ticketDetailError:null}),Tt(r),lt(e=>e+1),g(r!==null),v(!0),d(`tickets`),Ft(e.csrfToken,e.selectedProjectId,n))},tr=()=>{b(!1)},nr=async n=>{if(e.status!==`authenticated`||!e.selectedProjectId)return null;if(!e.chatSessionDetail||!e.selectedChatSessionId)return O(n),null;if(e.chatSessionDetail.mode===n||W||Tn)return null;let r=e.selectedProjectId,i=e.selectedChatSessionId,a=e.csrfToken;te(!0),ae(null);try{let e=await j_e(r,i,a,{mode:n});return O(e.mode),t(t=>{if(t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedChatSessionId!==i)return t;let n=t.chatSessions?.map(t=>t.id===e.id?e:t)??t.chatSessions;return{...t,chatSessions:n,chatSessionDetail:e,chatSessionDetailError:null}}),e}catch(e){return Pt(e)||ae(Z9(e,`Unable to update the chat mode right now.`)),null}finally{te(!1)}},rr=()=>{if(e.status===`authenticated`&&wt&&e.selectedBundleId===wt){t({...e,selectedTicketId:null,ticketDetail:null,ticketDetailError:null}),v(!1),g(!0),Tt(null);return}Tt(null),v(!1)},ir=()=>{g(!1)},ar=e=>{let t=xn.find(t=>t.id===e)??null;A(e),M(e=>t&&t.variants.includes(e)?e:``)},or=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),lr())},sr=(e,n,r)=>{t(t=>t.status!==`authenticated`||t.selectedProjectId!==e||t.selectedChatSessionId!==n?t:{...t,chatSessions:t.chatSessions?.map(e=>e.id===r.id?r:e)??t.chatSessions,chatSessionDetail:r,chatSessionDetailError:null})},cr=(n,r,i=e.status===`authenticated`?e.chatSessionDetail:null)=>{if(e.status!==`authenticated`||!e.selectedProjectId||H||On)return Promise.resolve(!1);let a=n.trim();if(!a)return Promise.resolve(!1);let o=e.selectedProjectId,s=i?.id??null,c=e.csrfToken,l=k||null,u=k&&j?j:null,d=_n===`opencode`?N:[],f=performance.now();jt.current+=1;let p=`mobile-chat:${jt.current}`;i&&oe({parentType:`chat`,parentId:i.id,turnKey:p,startedAt:f}),ae(null),U(!0);let m=e=>k_e(o,e.id,c,{instruction:a,tool:e.tool,model:l,variant:u,skills:d});return(i?m(i):O_e(o,c,{mode:D,tool:_n,model:l,variant:u,skills:d}).then(m)).then(e=>(oe({parentType:`chat`,parentId:e.id,turnKey:p,startedAt:f}),r&&E(``),b(!0),t(t=>{if(t.status!==`authenticated`||t.selectedProjectId!==o)return t;let n=t.chatSessions??[],r=n.some(t=>t.id===e.id)?n.map(t=>t.id===e.id?e:t):[e,...n];return{...t,chatSessions:r,selectedChatSessionId:e.id,chatSessionDetail:e,chatSessionDetailError:null}}),zt(c,o),!0)).catch(async e=>{oe(e=>e?.turnKey===p?null:e);let t=Ke(e,`chat_session`);return t&&s?sr(o,s,t):e instanceof Ge&&e.status===409&&s&&await Rt(c,o,s),Pt(e)||ae(Z9(e,`Unable to send the chat prompt.`)),!1}).finally(()=>{U(!1)})},lr=()=>{T.trim()&&cr(T,!0)},ur=async()=>{let t=e.status===`authenticated`?e.chatSessionDetail:null;if(!(!t||!KY(t,Tn)||Mt.current||H||On)){Mt.current=!0;try{let e=await nr(`build`);if(!e)return;await cr(GY,!1,e)}finally{Mt.current=!1}}},dr=async(n,r)=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedChatSessionId)throw Error(`Chat question set is unavailable.`);let i=e.selectedProjectId,a=e.selectedChatSessionId,o=e.csrfToken,s=UJ({parentType:`chat`,parentId:a,setId:r.set_id});ae(null);try{let e=await A_e(i,a,n,o,r);t(t=>t.status!==`authenticated`||t.selectedProjectId!==i||t.selectedChatSessionId!==a?t:{...t,chatSessions:t.chatSessions?.map(t=>t.id===e.id?e:t)??t.chatSessions,chatSessionDetail:e,chatSessionDetailError:null})}catch(e){if(e instanceof Ge&&e.status===409){GJ(s);let t=e.data&&typeof e.data==`object`&&`chat_session`in e.data?e.data.chat_session:null;t?sr(i,a,t):await Rt(o,i,a)}throw Pt(e)||ae(Z9(e,`Unable to resolve the chat questions.`)),e}},fr=()=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedChatSessionId||ne)return;let t=e.selectedProjectId,n=e.selectedChatSessionId;ae(null),re(n),oe(e=>e?.parentId===n?null:e),M_e(t,n,e.csrfToken).then(()=>Rt(e.csrfToken,t,n)).catch(e=>{Pt(e)||ae(Z9(e,`Unable to stop the chat response.`))}).finally(()=>re(null))},pr=()=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,specSessions:null,specSessionsError:null,selectedSpecSessionId:null,specSessionDetail:null,specSessionDetailError:null}),Vt(e.csrfToken,e.selectedProjectId))},mr=()=>{e.status!==`authenticated`||!e.selectedProjectId||!e.selectedSpecSessionId||(t({...e,specSessionDetail:null,specSessionDetailError:null}),Bt(e.csrfToken,e.selectedProjectId,e.selectedSpecSessionId))},hr=n=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,selectedSpecSessionId:n,specSessionDetail:null,specSessionDetailError:null}),Ee(null),Ct(null),Ae(e=>e+1),ce(!0),d(`spec`),Bt(e.csrfToken,e.selectedProjectId,n),Ut(e.selectedProjectId,void 0,!0))},gr=()=>{e.status!==`authenticated`||!e.selectedProjectId||(t({...e,selectedSpecSessionId:null,specSessionDetail:null,specSessionDetailError:null}),Ee(null),ue(``),Ae(e=>e+1),ce(!0),d(`spec`))},_r=()=>{ce(!1)},vr=n=>{if(e.status!==`authenticated`||!e.selectedProjectId)return;if(!e.specSessionDetail||!e.selectedSpecSessionId){fe(n);return}if(e.specSessionDetail.mode===n||xe||En)return;let r=e.selectedProjectId,i=e.selectedSpecSessionId,a=e.csrfToken;Se(!0),Ee(null),L_e(r,i,a,{mode:n}).then(e=>{fe(e.mode),t(t=>{if(t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedSpecSessionId!==i)return t;let n=t.specSessions?.map(t=>t.id===e.id?e:t)??t.specSessions;return{...t,specSessions:n,specSessionDetail:e,specSessionDetailError:null}})}).catch(e=>{Pt(e)||Ee(Z9(e,J9(`specDetail.modeError`)))}).finally(()=>Se(!1))},yr=e=>{let t=xn.find(t=>t.id===e)??null;me(e),ge(e=>t&&t.variants.includes(e)?e:``)},br=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),Sr())},xr=(e,n,r)=>{t(t=>t.status!==`authenticated`||t.selectedProjectId!==e||t.selectedSpecSessionId!==n?t:{...t,specSessions:t.specSessions?.map(e=>e.id===r.id?r:e)??t.specSessions,specSessionDetail:r,specSessionDetailError:null})},Sr=()=>{if(e.status!==`authenticated`||!e.selectedProjectId||ye||An)return;let n=le.trim();if(!n)return;let r=e.selectedProjectId,i=e.specSessionDetail?.id??null,a=e.csrfToken,o=pe||null,s=pe&&he?he:null,c=vn===`opencode`?_e:[],l=performance.now();jt.current+=1;let u=`mobile-spec:${jt.current}`;e.specSessionDetail&&Oe({parentType:`spec`,parentId:e.specSessionDetail.id,turnKey:u,startedAt:l}),Ee(null),be(!0);let d=e=>s9(r,e.id,a,{instruction:n,tool:e.tool,model:o,variant:s,skills:c});(e.specSessionDetail?d(e.specSessionDetail):F_e(r,a,{mode:de,tool:vn,model:o,variant:s,skills:c}).then(d)).then(e=>{Oe({parentType:`spec`,parentId:e.id,turnKey:u,startedAt:l}),ue(``),ce(!0),t(t=>{if(t.status!==`authenticated`||t.selectedProjectId!==r)return t;let n=t.specSessions??[],i=n.some(t=>t.id===e.id)?n.map(t=>t.id===e.id?e:t):[e,...n];return{...t,specSessions:i,selectedSpecSessionId:e.id,specSessionDetail:e,specSessionDetailError:null}}),Vt(a,r)}).catch(e=>{Oe(e=>e?.turnKey===u?null:e);let t=e instanceof Ge&&e.status===409&&e.data&&typeof e.data==`object`&&`spec_session`in e.data?e.data.spec_session:null;t&&i&&xr(r,i,t),!Pt(e)&&Ee(Z9(e,J9(`specDetail.sendError`)))}).finally(()=>be(!1))},Cr=n=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedSpecSessionId||ye)return;let r=e.selectedProjectId,i=e.selectedSpecSessionId,a=e.csrfToken,o=e.specSessionDetail?.tool??vn,s=pe||null,c=pe&&he?he:null,l=vn===`opencode`?_e:[],u=performance.now();jt.current+=1;let d=`mobile-spec:${jt.current}`;Oe({parentType:`spec`,parentId:i,turnKey:d,startedAt:u}),Ee(null),be(!0),s9(r,i,a,{instruction:n,tool:o,model:s,variant:c,skills:l}).then(e=>{t(t=>t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedSpecSessionId!==i?t:{...t,specSessionDetail:e,specSessionDetailError:null})}).catch(e=>{Oe(e=>e?.turnKey===d?null:e);let t=e instanceof Ge&&e.status===409&&e.data&&typeof e.data==`object`&&`spec_session`in e.data?e.data.spec_session:null;t&&xr(r,i,t),!Pt(e)&&Ee(Z9(e,J9(`specDetail.sendError`)))}).finally(()=>be(!1))},wr=async(n,r)=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedSpecSessionId)throw Error(`Spec question set is unavailable.`);let i=e.selectedProjectId,a=e.selectedSpecSessionId,o=e.csrfToken,s=UJ({parentType:`spec`,parentId:a,setId:r.set_id});Ee(null);try{let e=await I_e(i,a,n,o,r);t(t=>t.status!==`authenticated`||t.selectedProjectId!==i||t.selectedSpecSessionId!==a?t:{...t,specSessions:t.specSessions?.map(t=>t.id===e.id?e:t)??t.specSessions,specSessionDetail:e,specSessionDetailError:null})}catch(e){if(e instanceof Ge&&e.status===409){GJ(s);let t=e.data&&typeof e.data==`object`&&`spec_session`in e.data?e.data.spec_session:null;t?xr(i,a,t):await Bt(o,i,a)}throw Pt(e)||Ee(Z9(e,`Unable to resolve the spec questions.`)),e}},Tr=()=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedSpecSessionId||Ce)return;let t=e.selectedProjectId,n=e.selectedSpecSessionId;Ee(null),we(n),Oe(e=>e?.parentId===n?null:e),R_e(t,n,e.csrfToken).then(()=>Bt(e.csrfToken,t,n)).catch(e=>{Pt(e)||Ee(Z9(e,J9(`specDetail.stopError`)))}).finally(()=>we(null))},Er=n=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedTicketId||Fe||(n===`stop-run`||n===`pause-build`)&&!window.confirm(`Stop this ticket action on the desktop machine?`))return;let r=e.selectedProjectId,i=e.selectedTicketId,a=e.csrfToken,o=n===`build`?c9(r,i,a,`build`):n===`review`?c9(r,i,a,`review`):n===`run`?z_e(r,i,a):n===`stop-run`?B_e(r,i,a):n===`pause-build`?l9(r,i,a):u9(r,i,a);Ie(n),K(null),o.then(e=>{t(t=>{if(t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedTicketId!==i)return t;let n=t.tickets?.map(t=>t.id===e.id?e:t)??t.tickets;return{...t,tickets:n,ticketDetail:e,ticketDetailError:null}}),Ht(a,r),Lt(a,r),Ft(a,r,i)}).catch(e=>{Pt(e)||K(Z9(e,`Unable to update this ticket from mobile.`))}).finally(()=>Ie(null))},Dr=n=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedBundleId||!e.bundleDetail||je)return;let r=e.selectedProjectId,i=e.selectedBundleId,a=e.csrfToken,o=e.bundleDetail,{runningBuildTicketId:s,resumableBuildTicketId:c}=j9(o);if(n===`pause-build`&&!window.confirm(`Pause this bundle build on the desktop machine?`))return;let l=e=>{t(t=>t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedBundleId!==i?t:{...t,tickets:X9(t.tickets,e),bundleDetail:e,bundleDetailError:null})},u=e=>{t(t=>t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedBundleId!==i?t:{...t,tickets:t.tickets?.map(t=>t.id===e.id?e:t)??t.tickets,bundleDetail:t.bundleDetail?{...t.bundleDetail,tickets:t.bundleDetail.tickets.map(t=>t.id===e.id?e:t)}:t.bundleDetail,bundleDetailError:null})},d=n===`build`?E_e(r,i,a):n===`review`?D_e(r,i,a):n===`pause-build`?s?l9(r,s,a):null:c?u9(r,c,a):null;d&&(Me(n),Pe(null),d.then(e=>{`tickets`in e?l(e):u(e),Ht(a,r),Lt(a,r),It(a,r,i)}).catch(e=>{Pt(e)||Pe(Z9(e,`Unable to update this bundle from mobile.`))}).finally(()=>Me(null)))},Or=e=>{let t=xn.find(t=>t.id===e)??null;Ve(e),q(e=>t&&t.variants.includes(e)?e:``)},kr=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),Ar())},Ar=()=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedTicketId||!e.ticketDetail||J||Dn)return;let n=Re.trim();if(!n)return;let r=e.selectedProjectId,i=e.ticketDetail,a=e.csrfToken,o=d3(i,{model:Be||null,variant:He||null,skills:Ue});jt.current+=1;let s={parentType:`ticket`,parentId:i.id,turnKey:`mobile-ticket:${jt.current}`,startedAt:performance.now()};Y(s);let c=()=>i.state===`plan`?H_e(r,i.id,a,n):W_e(r,i.id,a,n),l=e=>{t(t=>{if(t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedTicketId!==i.id)return t;let n=t.tickets?.map(t=>t.id===e.id?e:t)??t.tickets;return{...t,tickets:n,ticketDetail:e,ticketDetailError:null}})};qe(!0),Xe(null),(async()=>{o.shouldPersist&&l(await V_e(r,i.id,a,{model:o.model,variant:o.variant,skills:o.skills})),l(await c()),ze(``),Lt(a,r),Ft(a,r,i.id)})().catch(async e=>{Y(e=>e?.turnKey===s.turnKey?null:e);let t=Ke(e,`ticket`);t?l(t):e instanceof Ge&&e.status===409&&await Ft(a,r,i.id),!Pt(e)&&Xe(Z9(e,`Unable to send the ticket follow-up.`))}).finally(()=>qe(!1))},jr=async(n,r)=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedTicketId)throw Error(`Ticket question set is unavailable.`);let i=e.selectedProjectId,a=e.selectedTicketId,o=e.csrfToken,s=UJ({parentType:`ticket`,parentId:a,setId:r.set_id});Xe(null);try{let e=await U_e(i,a,n,o,r);t(t=>t.status!==`authenticated`||t.selectedProjectId!==i||t.selectedTicketId!==a?t:{...t,tickets:t.tickets?.map(t=>t.id===e.id?e:t)??t.tickets,ticketDetail:e,ticketDetailError:null})}catch(e){if(e instanceof Ge&&e.status===409){GJ(s);let n=e.data&&typeof e.data==`object`&&`ticket`in e.data?e.data.ticket:null;n?t(e=>e.status===`authenticated`&&e.selectedTicketId===a?{...e,ticketDetail:n}:e):await Ft(o,i,a)}throw Pt(e)||Xe(Z9(e,`Unable to resolve the ticket questions.`)),e}},Mr=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),Nr())},Nr=()=>{if(e.status!==`authenticated`||!e.selectedProjectId||!e.selectedBundleId||!e.bundleDetail||et)return;let n=Qe.trim();if(!n)return;let r=e.selectedProjectId,i=e.selectedBundleId,a=e.csrfToken,o=e=>{t(t=>t.status!==`authenticated`||t.selectedProjectId!==r||t.selectedBundleId!==i?t:{...t,tickets:X9(t.tickets,e),bundleDetail:e,bundleDetailError:null})};tt(!0),rt(null),G_e(r,i,a,n).then(e=>{o(e),$e(``),Lt(a,r),It(a,r,i)}).catch(e=>{Pt(e)||rt(Z9(e,`Unable to send the bundle follow-up.`))}).finally(()=>tt(!1))},Pr=(0,p.useCallback)(async(e,t,n)=>{try{return await S_e(t??``,e,n)}catch(e){throw Pt(e),e}},[Pt]),Fr=(0,p.useCallback)(async(e,t,n)=>{try{return await C_e(t??``,e,n)}catch(e){throw Pt(e),e}},[Pt]),Ir=(0,p.useCallback)(async(e,t,n)=>{try{return await w_e(t??``,e,n)}catch(e){throw Pt(e),e}},[Pt]);return e.status===`checking`?(0,X.jsx)(g9,{title:`Checking mobile session`,description:`Archon is validating this browser before showing project controls.`}):e.status===`pairing`?(0,X.jsx)(g9,{title:`Checking pairing link`,description:`Keep this page open while Archon verifies the one-time pairing link.`}):e.status===`pairing_confirmation`?(0,X.jsxs)(g9,{title:`Compare pairing code`,description:`Confirm this code matches the desktop dialog before pairing this phone.`,children:[(0,X.jsx)(iC,{className:`border-primary/25 bg-primary/10 shadow-none`,children:(0,X.jsxs)(lC,{className:`space-y-2 pt-5 text-center`,children:[(0,X.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-[0.18em] text-foreground`,children:`Verification code`}),(0,X.jsx)(`div`,{className:`font-mono text-3xl font-semibold tracking-[0.18em] text-foreground`,children:e.displayCode}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`Expires at `,Nve(e.expiresAt)]})]})}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`If this code does not match the desktop dialog, cancel and regenerate the pairing link from desktop Archon.`}),e.error?(0,X.jsx)(`p`,{className:`text-sm text-red-200`,children:e.error}):null,(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,X.jsx)(Q,{size:`lg`,disabled:C,onClick:Ln,children:C?`Pairing...`:`Pair this phone`}),(0,X.jsx)(Q,{variant:`outline`,size:`lg`,disabled:C,onClick:Rn,children:`Cancel`})]})]}):e.status===`unauthenticated`?(0,X.jsx)(g9,{title:e.reason===`session_revoked`?`Mobile session revoked`:`Pairing required`,description:e.reason===`session_revoked`?`This mobile session is no longer valid. Scan the QR code or open the pairing link from desktop Archon to continue.`:`This browser is not paired. Scan the QR code or open the pairing link from desktop Archon.`,children:(0,X.jsx)(Q,{onClick:Mn,children:`Retry`})}):e.status===`error`?(0,X.jsx)(g9,{title:`Mobile access unavailable`,description:e.message,children:(0,X.jsx)(Q,{onClick:Mn,children:`Retry`})}):(0,X.jsx)(gq,{socket:c??void 0,fetchTicketRuns:Pr,fetchChatRuns:Fr,fetchSpecRuns:Ir,children:(0,X.jsxs)(`main`,{className:Z(`bg-background text-foreground`,jn?`flex h-[100dvh] flex-col overflow-hidden`:`min-h-screen`),children:[(0,X.jsx)(ove,{open:f,projects:e.projects,selectedProjectId:e.selectedProjectId,error:e.projectError,onOpenChange:m,onSelectProject:qn,onRetry:zn}),(0,X.jsx)(sve,{open:gt,project:tn,targetOptions:ft,error:St??mt,isLoading:vt,isSubmitting:bt,onOpenChange:_t,onRetry:Vn,onSelectBundle:e=>{Jn(e)},onSelectRepoRoot:(e,t)=>{Yn(e,t)}}),(0,X.jsx)(tve,{activeTool:i,agents:o,selectedProject:tn,targetLabel:mn,isTargetLoading:hn,isTargetDisabled:!Xt,connectionState:n,onOpenProjects:Pn,onOpenTargetSelector:Fn,onToolChange:e=>{Gt(e)}}),jn?(0,X.jsxs)(`div`,{className:`mx-auto flex min-h-0 w-full max-w-6xl flex-1 flex-col overflow-hidden px-3 py-3 sm:px-4`,children:[u===`tickets`?(0,X.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:_&&e.selectedTicketId?(0,X.jsx)(q9,{selectedProjectId:e.selectedProjectId,ticketId:e.selectedTicketId,ticket:e.ticketDetail,openNonce:ct,error:e.ticketDetailError,actionState:Fe,actionError:Le,followUpPrompt:Re,followUpSelectedModel:Be,followUpSelectedVariant:He,followUpSelectedSkills:Ue,availableModels:xn,availableSkills:Sn,isLoadingAgentSettings:Cn,isSendingFollowUp:J,liveResponseTiming:an?.agent_status===`running`&&Ze?.parentId===an.id?Ze:null,followUpError:Je,onBack:rr,onRetry:Gn,onAction:Er,onFollowUpPromptChange:ze,onFollowUpModelChange:Or,onFollowUpVariantChange:q,onFollowUpSkillsChange:We,onFollowUpKeyDown:kr,onFollowUpSubmit:Ar,onResolveQuestionSet:jr,isLargeScreen:!1}):(0,X.jsx)(U9,{selectedProjectId:e.selectedProjectId,bundleId:e.selectedBundleId,bundleDetail:e.bundleDetail,openNonce:ot,mobileDetailView:ut,error:e.bundleDetailError,actionState:je,actionError:Ne,followUpPrompt:Qe,isSendingFollowUp:et,followUpError:nt,availableModels:xn,onBack:ir,onRetry:Kn,onAction:Dr,onDetailViewChange:dt,onSelectTicket:er,onFollowUpPromptChange:$e,onFollowUpKeyDown:Mr,onFollowUpSubmit:Nr,isLargeScreen:!1})}):null,u===`chats`?(0,X.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,X.jsx)(W9,{selectedProjectId:e.selectedProjectId,chatSession:e.chatSessionDetail,chatSessionId:e.selectedChatSessionId,openNonce:it,error:e.chatSessionDetailError,isStopping:ne===e.selectedChatSessionId,composerMode:e.chatSessionDetail?.mode??D,composerTool:_n,prompt:T,selectedModel:k,selectedVariant:j,selectedSkills:N,availableModels:xn,availableSkills:Sn,isLoadingAgentSettings:Cn,isSending:H,liveResponseTiming:nn?.agent_status===`running`&&G?.parentId===nn.id?G:null,isUpdatingMode:W,showStartBuilding:kn,composerDisabledReason:On,onBack:tr,onRetry:Un,onStop:fr,onModeChange:nr,onStartBuilding:ur,onPromptChange:E,onModelChange:ar,onVariantChange:M,onSkillsChange:P,onPromptKeyDown:or,onSubmit:lr,onResolveQuestionSet:dr,isLargeScreen:!1}),ie?(0,X.jsx)(`p`,{className:`mt-3 text-sm text-red-200`,children:ie}):null]}):null,u===`spec`?(0,X.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,X.jsx)(K9,{selectedProjectId:e.selectedProjectId,specSession:e.specSessionDetail,specSessionId:e.selectedSpecSessionId,openNonce:ke,error:e.specSessionDetailError,isStopping:Ce===e.selectedSpecSessionId,composerMode:e.specSessionDetail?.mode??de,composerTool:vn,prompt:le,selectedModel:pe,selectedVariant:he,selectedSkills:_e,availableModels:xn,availableSkills:Sn,isLoadingAgentSettings:Cn,isSending:ye,liveResponseTiming:on?.agent_status===`running`&&De?.parentId===on.id?De:null,isUpdatingMode:xe,composerDisabledReason:An,targetWarning:cn??dn??pn,targetActionLabel:un?J9(`specDetail.retryTarget`):fn&&on?qb.t(`common:mobileApp.specDetail.switchBack`,{target:l5(on)}):null,targetActionError:St,isRestoringTarget:bt,onBack:_r,onRetry:mr,onStop:Tr,onModeChange:vr,onPromptChange:ue,onModelChange:yr,onVariantChange:ge,onSkillsChange:ve,onPromptKeyDown:br,onSubmit:Sr,onSubmitAnswer:Cr,onResolveQuestionSet:wr,onRestoreTarget:Xn,isLargeScreen:!1}),Te?(0,X.jsx)(`p`,{className:`mt-3 text-sm text-red-200`,children:Te}):null]}):null]}):(0,X.jsx)(`div`,{className:`mx-auto w-full max-w-6xl px-3 py-3 pb-[calc(env(safe-area-inset-bottom)+5rem)] sm:px-4 lg:flex lg:min-h-[calc(100dvh-4.5rem)] lg:flex-col lg:overflow-hidden lg:pb-4`,children:(0,X.jsxs)(`div`,{className:`space-y-3 lg:flex lg:min-h-0 lg:flex-1 lg:flex-col`,children:[(0,X.jsx)(eve,{status:n,onRetry:Mn}),u===`overview`?(0,X.jsx)(`div`,{className:`space-y-3 lg:flex lg:min-h-0 lg:flex-1 lg:flex-col`,children:e.projectError?(0,X.jsx)(_9,{title:`Projects unavailable`,description:e.projectError,action:(0,X.jsx)(Q,{variant:`warning`,onClick:zn,children:`Retry projects`})}):e.selectedProjectId&&!e.projectSummary&&!e.projectSummaryError?(0,X.jsx)(P9,{}):(0,X.jsxs)(X.Fragment,{children:[e.selectedProjectId&&(0,X.jsx)(hve,{projectId:e.selectedProjectId,csrfToken:e.csrfToken,socket:c,initialRequests:e.projectSummary?.pending_approval_requests??Ove,onRequestError:Pt},e.selectedProjectId),(0,X.jsx)(xve,{selectedProjectId:e.selectedProjectId,summary:e.projectSummary,tickets:e.tickets,error:e.projectSummaryError,chatSessions:e.chatSessions,chatSessionDetail:e.chatSessionDetail,onRetry:Bn,onOpenTickets:()=>Nn(`tickets`),onOpenChats:()=>Nn(`chats`),onOpenSpec:()=>Nn(`spec`)}),(0,X.jsx)(vve,{isLoggingOut:x,onLogout:In})]})}):null,u===`tickets`?gn?(0,X.jsxs)(`div`,{className:`grid min-h-0 flex-1 gap-3 overflow-hidden lg:grid-cols-[minmax(15rem,18rem)_minmax(0,1fr)]`,children:[(0,X.jsx)(`div`,{className:`min-h-0`,children:(0,X.jsx)(E9,{selectedProjectId:e.selectedProjectId,tickets:e.tickets,selectedBundleId:e.selectedBundleId,selectedTicketId:e.selectedTicketId,error:e.ticketsError,onRetry:Wn,onSelectBundle:$n,onSelectTicket:er})}),(0,X.jsx)(`div`,{className:`hidden min-h-0 lg:flex lg:flex-col lg:overflow-hidden`,children:_&&e.selectedTicketId?(0,X.jsx)(q9,{selectedProjectId:e.selectedProjectId,ticketId:e.selectedTicketId,ticket:e.ticketDetail,openNonce:ct,error:e.ticketDetailError,actionState:Fe,actionError:Le,followUpPrompt:Re,followUpSelectedModel:Be,followUpSelectedVariant:He,followUpSelectedSkills:Ue,availableModels:xn,availableSkills:Sn,isLoadingAgentSettings:Cn,isSendingFollowUp:J,liveResponseTiming:an?.agent_status===`running`&&Ze?.parentId===an.id?Ze:null,followUpError:Je,onBack:rr,onRetry:Gn,onAction:Er,onFollowUpPromptChange:ze,onFollowUpModelChange:Or,onFollowUpVariantChange:q,onFollowUpSkillsChange:We,onFollowUpKeyDown:kr,onFollowUpSubmit:Ar,onResolveQuestionSet:jr,isLargeScreen:!0}):(0,X.jsx)(U9,{selectedProjectId:e.selectedProjectId,bundleId:e.selectedBundleId,bundleDetail:e.bundleDetail,openNonce:ot,mobileDetailView:ut,error:e.bundleDetailError,actionState:je,actionError:Ne,followUpPrompt:Qe,isSendingFollowUp:et,followUpError:nt,availableModels:xn,onBack:ir,onRetry:Kn,onAction:Dr,onDetailViewChange:dt,onSelectTicket:er,onFollowUpPromptChange:$e,onFollowUpKeyDown:Mr,onFollowUpSubmit:Nr,isLargeScreen:!0})})]}):(0,X.jsx)(E9,{selectedProjectId:e.selectedProjectId,tickets:e.tickets,selectedBundleId:e.selectedBundleId,selectedTicketId:e.selectedTicketId,error:e.ticketsError,onRetry:Wn,onSelectBundle:$n,onSelectTicket:er}):null,u===`chats`?gn?(0,X.jsxs)(`div`,{className:`grid min-h-0 flex-1 gap-3 overflow-hidden lg:grid-cols-[minmax(15rem,18rem)_minmax(0,1fr)]`,children:[(0,X.jsx)(`div`,{className:`min-h-0`,children:(0,X.jsx)(k9,{selectedProjectId:e.selectedProjectId,chatSessions:e.chatSessions,selectedChatSessionId:e.selectedChatSessionId,error:e.chatSessionsError,onRetry:Hn,onOpenNewChat:Qn,onSelectChat:Zn})}),(0,X.jsxs)(`div`,{className:`hidden min-h-0 lg:flex lg:flex-col lg:overflow-hidden`,children:[(0,X.jsx)(W9,{selectedProjectId:e.selectedProjectId,chatSession:e.chatSessionDetail,chatSessionId:e.selectedChatSessionId,openNonce:it,error:e.chatSessionDetailError,isStopping:ne===e.selectedChatSessionId,composerMode:e.chatSessionDetail?.mode??D,composerTool:_n,prompt:T,selectedModel:k,selectedVariant:j,selectedSkills:N,availableModels:xn,availableSkills:Sn,isLoadingAgentSettings:Cn,isSending:H,liveResponseTiming:nn?.agent_status===`running`&&G?.parentId===nn.id?G:null,isUpdatingMode:W,showStartBuilding:kn,composerDisabledReason:On,onBack:tr,onRetry:Un,onStop:fr,onModeChange:nr,onStartBuilding:ur,onPromptChange:E,onModelChange:ar,onVariantChange:M,onSkillsChange:P,onPromptKeyDown:or,onSubmit:lr,onResolveQuestionSet:dr,isLargeScreen:!0}),ie?(0,X.jsx)(`p`,{className:`mt-3 text-sm text-red-200`,children:ie}):null]})]}):(0,X.jsx)(k9,{selectedProjectId:e.selectedProjectId,chatSessions:e.chatSessions,selectedChatSessionId:e.selectedChatSessionId,error:e.chatSessionsError,onRetry:Hn,onOpenNewChat:Qn,onSelectChat:Zn}):null,u===`spec`?gn?(0,X.jsxs)(`div`,{className:`grid min-h-0 flex-1 gap-3 overflow-hidden lg:grid-cols-[minmax(15rem,18rem)_minmax(0,1fr)]`,children:[(0,X.jsx)(`div`,{className:`min-h-0`,children:(0,X.jsx)(A9,{selectedProjectId:e.selectedProjectId,specSessions:e.specSessions,selectedSpecSessionId:e.selectedSpecSessionId,error:e.specSessionsError,onRetry:pr,onOpenNewSpec:gr,onSelectSpec:hr})}),(0,X.jsxs)(`div`,{className:`hidden min-h-0 lg:flex lg:flex-col lg:overflow-hidden`,children:[(0,X.jsx)(K9,{selectedProjectId:e.selectedProjectId,specSession:e.specSessionDetail,specSessionId:e.selectedSpecSessionId,openNonce:ke,error:e.specSessionDetailError,isStopping:Ce===e.selectedSpecSessionId,composerMode:e.specSessionDetail?.mode??de,composerTool:vn,prompt:le,selectedModel:pe,selectedVariant:he,selectedSkills:_e,availableModels:xn,availableSkills:Sn,isLoadingAgentSettings:Cn,isSending:ye,liveResponseTiming:on?.agent_status===`running`&&De?.parentId===on.id?De:null,isUpdatingMode:xe,composerDisabledReason:An,targetWarning:cn??dn??pn,targetActionLabel:un?J9(`specDetail.retryTarget`):fn&&on?qb.t(`common:mobileApp.specDetail.switchBack`,{target:l5(on)}):null,targetActionError:St,isRestoringTarget:bt,onBack:_r,onRetry:mr,onStop:Tr,onModeChange:vr,onPromptChange:ue,onModelChange:yr,onVariantChange:ge,onSkillsChange:ve,onPromptKeyDown:br,onSubmit:Sr,onSubmitAnswer:Cr,onResolveQuestionSet:wr,onRestoreTarget:Xn,isLargeScreen:!0}),Te?(0,X.jsx)(`p`,{className:`mt-3 text-sm text-red-200`,children:Te}):null]})]}):(0,X.jsx)(A9,{selectedProjectId:e.selectedProjectId,specSessions:e.specSessions,selectedSpecSessionId:e.selectedSpecSessionId,error:e.specSessionsError,onRetry:pr,onOpenNewSpec:gr,onSelectSpec:hr}):null]})}),jn?null:(0,X.jsx)(nve,{activeSection:u,onChange:Nn})]})})},Ive=({socket:e=KS,children:t})=>(0,X.jsx)(lq.Provider,{value:e,children:t}),Lve=()=>typeof window<`u`&&window.location.pathname.startsWith(`/mobile`),Rve=()=>{let e=Lve();return Ab(e?null:KS),(0,X.jsx)(Ue,{i18n:qb,children:(0,X.jsx)(it,{children:(0,X.jsxs)(Ive,{children:[e&&(0,X.jsx)(Fve,{}),!e&&(0,X.jsx)(gq,{children:(0,X.jsx)(Cme,{children:(0,X.jsx)(c_e,{})})})]})})})};document.documentElement.classList.add(`dark`),document.documentElement.style.colorScheme=`dark`,t3(),(0,f.createRoot)(document.getElementById(`root`)).render((0,X.jsx)(Rve,{}));export{Z as $,pb as A,Tv as B,CC as C,hx as D,KS as E,tb as F,V_ as G,bv as H,$ as I,q_ as J,H_ as K,jv as L,eb as M,nb as N,ax as O,rb as P,Q,kv as R,wC as S,c as St,qS as T,iv as U,wv as V,J_ as W,W_ as X,G_ as Y,K_ as Z,LC as _,J as _t,C4 as a,Kt as at,zC as b,Y as bt,vue as c,Xt as ct,lE as d,Ht as dt,Vn as et,iE as f,Vt as ft,YC as g,Ge as gt,XC as h,rt as ht,T4 as i,Zt as it,ib as j,qb as k,uq as l,$t as lt,nw as m,Bt as mt,f8 as n,Yt as nt,w4 as o,en as ot,qT as p,Ut as pt,U_ as q,B4 as r,Jt as rt,u4 as s,Gt as st,G5 as t,qt as tt,HW as u,Qt as ut,BC as v,Ye as vt,rC as w,SC as x,q as xt,RC as y,Ze as yt,Ov as z};