runcastle 1.4.0 → 1.4.1
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.
|
@@ -180,8 +180,8 @@ ${s.join(`
|
|
|
180
180
|
`)}clearSelection(){this._model.clearSelection(),this._removeMouseDownListeners(),this.refresh(),this._onSelectionChange.fire()}refresh(e){this._refreshAnimationFrame||=this._coreBrowserService.window.requestAnimationFrame(()=>this._refresh()),gZ&&e&&this.selectionText.length&&this._onLinuxMouseSelection.fire(this.selectionText)}_refresh(){this._refreshAnimationFrame=void 0,this._onRedrawRequest.fire({start:this._model.finalSelectionStart,end:this._model.finalSelectionEnd,columnSelectMode:this._activeSelectionMode===3})}_isClickInSelection(e){let t=this._getMouseBufferCoords(e),n=this._model.finalSelectionStart,r=this._model.finalSelectionEnd;return!n||!r||!t?!1:this._areCoordsInSelection(t,n,r)}isCellInSelection(e,t){let n=this._model.finalSelectionStart,r=this._model.finalSelectionEnd;return!n||!r?!1:this._areCoordsInSelection([e,t],n,r)}_areCoordsInSelection(e,t,n){return e[1]>t[1]&&e[1]<n[1]||t[1]===n[1]&&e[1]===t[1]&&e[0]>=t[0]&&e[0]<n[0]||t[1]<n[1]&&e[1]===n[1]&&e[0]<n[0]||t[1]<n[1]&&e[1]===t[1]&&e[0]>=t[0]}_selectWordAtCursor(e,t){let n=this._linkifier.currentLink?.link?.range;if(n)return this._model.selectionStart=[n.start.x-1,n.start.y-1],this._model.selectionStartLength=zZ(n,this._bufferService.cols),this._model.selectionEnd=void 0,!0;let r=this._getMouseBufferCoords(e);return r?(this._selectWordAt(r,t),this._model.selectionEnd=void 0,!0):!1}selectAll(){this._model.isSelectAllActive=!0,this.refresh(),this._onSelectionChange.fire()}selectLines(e,t){this._model.clearSelection(),e=Math.max(e,0),t=Math.min(t,this._bufferService.buffer.lines.length-1),this._model.selectionStart=[0,e],this._model.selectionEnd=[this._bufferService.cols,t],this.refresh(),this._onSelectionChange.fire()}_handleTrim(e){this._model.handleTrim(e)&&this.refresh()}_getMouseBufferCoords(e){let t=this._mouseService.getCoords(e,this._screenElement,this._bufferService.cols,this._bufferService.rows,!0);if(t)return t[0]--,t[1]--,t[1]+=this._bufferService.buffer.ydisp,t}_getMouseEventScrollAmount(e){let t=eZ(this._coreBrowserService.window,e,this._screenElement)[1],n=this._renderService.dimensions.css.canvas.height;return t>=0&&t<=n?0:(t>n&&(t-=n),t=Math.min(Math.max(t,-BZ),BZ),t/=BZ,t/Math.abs(t)+Math.round(t*(VZ-1)))}shouldForceSelection(e){return fZ?e.altKey&&this._optionsService.rawOptions.macOptionClickForcesSelection:e.shiftKey}handleMouseDown(e){if(this._mouseDownTimeStamp=e.timeStamp,!(e.button===2&&this.hasSelection)&&e.button===0){if(!this._enabled){if(!this.shouldForceSelection(e))return;e.stopPropagation()}e.preventDefault(),this._dragScrollAmount=0,this._enabled&&e.shiftKey?this._handleIncrementalClick(e):e.detail===1?this._handleSingleClick(e):e.detail===2?this._handleDoubleClick(e):e.detail===3&&this._handleTripleClick(e),this._addMouseDownListeners(),this.refresh(!0)}}_addMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.addEventListener(`mousemove`,this._mouseMoveListener),this._screenElement.ownerDocument.addEventListener(`mouseup`,this._mouseUpListener)),this._dragScrollIntervalTimer=this._coreBrowserService.window.setInterval(()=>this._dragScroll(),HZ)}_removeMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.removeEventListener(`mousemove`,this._mouseMoveListener),this._screenElement.ownerDocument.removeEventListener(`mouseup`,this._mouseUpListener)),this._coreBrowserService.window.clearInterval(this._dragScrollIntervalTimer),this._dragScrollIntervalTimer=void 0}_handleIncrementalClick(e){this._model.selectionStart&&(this._model.selectionEnd=this._getMouseBufferCoords(e))}_handleSingleClick(e){if(this._model.selectionStartLength=0,this._model.isSelectAllActive=!1,this._activeSelectionMode=this.shouldColumnSelect(e)?3:0,this._model.selectionStart=this._getMouseBufferCoords(e),!this._model.selectionStart)return;this._model.selectionEnd=void 0;let t=this._bufferService.buffer.lines.get(this._model.selectionStart[1]);t&&t.length!==this._model.selectionStart[0]&&t.hasWidth(this._model.selectionStart[0])===0&&this._model.selectionStart[0]++}_handleDoubleClick(e){this._selectWordAtCursor(e,!0)&&(this._activeSelectionMode=1)}_handleTripleClick(e){let t=this._getMouseBufferCoords(e);t&&(this._activeSelectionMode=2,this._selectLineAt(t[1]))}shouldColumnSelect(e){return e.altKey&&!(fZ&&this._optionsService.rawOptions.macOptionClickForcesSelection)}_handleMouseMove(e){if(e.stopImmediatePropagation(),!this._model.selectionStart)return;let t=this._model.selectionEnd?[this._model.selectionEnd[0],this._model.selectionEnd[1]]:null;if(this._model.selectionEnd=this._getMouseBufferCoords(e),!this._model.selectionEnd){this.refresh(!0);return}this._activeSelectionMode===2?this._model.selectionEnd[1]<this._model.selectionStart[1]?this._model.selectionEnd[0]=0:this._model.selectionEnd[0]=this._bufferService.cols:this._activeSelectionMode===1&&this._selectToWordAt(this._model.selectionEnd),this._dragScrollAmount=this._getMouseEventScrollAmount(e),this._activeSelectionMode!==3&&(this._dragScrollAmount>0?this._model.selectionEnd[0]=this._bufferService.cols:this._dragScrollAmount<0&&(this._model.selectionEnd[0]=0));let n=this._bufferService.buffer;if(this._model.selectionEnd[1]<n.lines.length){let e=n.lines.get(this._model.selectionEnd[1]);e&&e.hasWidth(this._model.selectionEnd[0])===0&&this._model.selectionEnd[0]<this._bufferService.cols&&this._model.selectionEnd[0]++}(!t||t[0]!==this._model.selectionEnd[0]||t[1]!==this._model.selectionEnd[1])&&this.refresh(!0)}_dragScroll(){if(!(!this._model.selectionEnd||!this._model.selectionStart)&&this._dragScrollAmount){this._onRequestScrollLines.fire({amount:this._dragScrollAmount,suppressScrollEvent:!1});let e=this._bufferService.buffer;this._dragScrollAmount>0?(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=this._bufferService.cols),this._model.selectionEnd[1]=Math.min(e.ydisp+this._bufferService.rows,e.lines.length-1)):(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=0),this._model.selectionEnd[1]=e.ydisp),this.refresh()}}_handleMouseUp(e){let t=e.timeStamp-this._mouseDownTimeStamp;if(this._removeMouseDownListeners(),this.selectionText.length<=1&&t<UZ&&e.altKey&&this._optionsService.rawOptions.altClickMovesCursor){if(this._bufferService.buffer.ybase===this._bufferService.buffer.ydisp){let t=this._mouseService.getCoords(e,this._element,this._bufferService.cols,this._bufferService.rows,!1);if(t&&t[0]!==void 0&&t[1]!==void 0){let e=TZ(t[0]-1,t[1]-1,this._bufferService,this._coreService.decPrivateModes.applicationCursorKeys);this._coreService.triggerDataEvent(e,!0)}}}else this._fireEventIfSelectionChanged()}_fireEventIfSelectionChanged(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd,n=!!e&&!!t&&(e[0]!==t[0]||e[1]!==t[1]);if(!n){this._oldHasSelection&&this._fireOnSelectionChange(e,t,n);return}!e||!t||(!this._oldSelectionStart||!this._oldSelectionEnd||e[0]!==this._oldSelectionStart[0]||e[1]!==this._oldSelectionStart[1]||t[0]!==this._oldSelectionEnd[0]||t[1]!==this._oldSelectionEnd[1])&&this._fireOnSelectionChange(e,t,n)}_fireOnSelectionChange(e,t,n){this._oldSelectionStart=e,this._oldSelectionEnd=t,this._oldHasSelection=n,this._onSelectionChange.fire()}_handleBufferActivate(e){this.clearSelection(),this._trimListener.dispose(),this._trimListener=e.activeBuffer.lines.onTrim(e=>this._handleTrim(e))}_convertViewportColToCharacterIndex(e,t){let n=t;for(let r=0;t>=r;r++){let i=e.loadCell(r,this._workCell).getChars().length;this._workCell.getWidth()===0?n--:i>1&&t!==r&&(n+=i-1)}return n}setSelection(e,t,n){this._model.clearSelection(),this._removeMouseDownListeners(),this._model.selectionStart=[e,t],this._model.selectionStartLength=n,this.refresh(),this._fireEventIfSelectionChanged()}rightClickSelect(e){this._isClickInSelection(e)||(this._selectWordAtCursor(e,!1)&&this.refresh(!0),this._fireEventIfSelectionChanged())}_getWordAt(e,t,n=!0,r=!0){if(e[0]>=this._bufferService.cols)return;let i=this._bufferService.buffer,a=i.lines.get(e[1]);if(!a)return;let o=i.translateBufferLineToString(e[1],!1),s=this._convertViewportColToCharacterIndex(a,e[0]),c=s,l=e[0]-s,u=0,d=0,f=0,p=0;if(o.charAt(s)===` `){for(;s>0&&o.charAt(s-1)===` `;)s--;for(;c<o.length&&o.charAt(c+1)===` `;)c++}else{let t=e[0],n=e[0];a.getWidth(t)===0&&(u++,t--),a.getWidth(n)===2&&(d++,n++);let r=a.getString(n).length;for(r>1&&(p+=r-1,c+=r-1);t>0&&s>0&&!this._isCharWordSeparator(a.loadCell(t-1,this._workCell));){a.loadCell(t-1,this._workCell);let e=this._workCell.getChars().length;this._workCell.getWidth()===0?(u++,t--):e>1&&(f+=e-1,s-=e-1),s--,t--}for(;n<a.length&&c+1<o.length&&!this._isCharWordSeparator(a.loadCell(n+1,this._workCell));){a.loadCell(n+1,this._workCell);let e=this._workCell.getChars().length;this._workCell.getWidth()===2?(d++,n++):e>1&&(p+=e-1,c+=e-1),c++,n++}}c++;let m=s+l-u+f,h=Math.min(this._bufferService.cols,c-s+u+d-f-p);if(!(!t&&o.slice(s,c).trim()===``)){if(n&&m===0&&a.getCodePoint(0)!==32){let t=i.lines.get(e[1]-1);if(t&&a.isWrapped&&t.getCodePoint(this._bufferService.cols-1)!==32){let t=this._getWordAt([this._bufferService.cols-1,e[1]-1],!1,!0,!1);if(t){let e=this._bufferService.cols-t.start;m-=e,h+=e}}}if(r&&m+h===this._bufferService.cols&&a.getCodePoint(this._bufferService.cols-1)!==32){let t=i.lines.get(e[1]+1);if(t?.isWrapped&&t.getCodePoint(0)!==32){let t=this._getWordAt([0,e[1]+1],!1,!1,!0);t&&(h+=t.length)}}return{start:m,length:h}}}_selectWordAt(e,t){let n=this._getWordAt(e,t);if(n){for(;n.start<0;)n.start+=this._bufferService.cols,e[1]--;this._model.selectionStart=[n.start,e[1]],this._model.selectionStartLength=n.length}}_selectToWordAt(e){let t=this._getWordAt(e,!0);if(t){let n=e[1];for(;t.start<0;)t.start+=this._bufferService.cols,n--;if(!this._model.areSelectionValuesReversed())for(;t.start+t.length>this._bufferService.cols;)t.length-=this._bufferService.cols,n++;this._model.selectionEnd=[this._model.areSelectionValuesReversed()?t.start:t.start+t.length,n]}}_isCharWordSeparator(e){return e.getWidth()!==0&&this._optionsService.rawOptions.wordSeparator.indexOf(e.getChars())>=0}_selectLineAt(e){let t=this._bufferService.buffer.getWrappedRangeForLine(e),n={start:{x:0,y:t.first},end:{x:this._bufferService.cols-1,y:t.last}};this._model.selectionStart=[0,t.first],this._model.selectionEnd=void 0,this._model.selectionStartLength=zZ(n,this._bufferService.cols)}};GZ=WG([Z(3,_K),Z(4,yK),Z(5,jK),Z(6,CK),Z(7,MK),Z(8,AK)],GZ);var KZ=class{constructor(){this._data={}}set(e,t,n){this._data[e]||(this._data[e]={}),this._data[e][t]=n}get(e,t){return this._data[e]?this._data[e][t]:void 0}clear(){this._data={}}},qZ=class{constructor(){this._color=new KZ,this._css=new KZ}setCss(e,t,n){this._css.set(e,t,n)}getCss(e,t){return this._css.get(e,t)}setColor(e,t,n){this._color.set(e,t,n)}getColor(e,t){return this._color.get(e,t)}clear(){this._color.clear(),this._css.clear()}},JZ=Object.freeze((()=>{let e=[SX.toColor(`#2e3436`),SX.toColor(`#cc0000`),SX.toColor(`#4e9a06`),SX.toColor(`#c4a000`),SX.toColor(`#3465a4`),SX.toColor(`#75507b`),SX.toColor(`#06989a`),SX.toColor(`#d3d7cf`),SX.toColor(`#555753`),SX.toColor(`#ef2929`),SX.toColor(`#8ae234`),SX.toColor(`#fce94f`),SX.toColor(`#729fcf`),SX.toColor(`#ad7fa8`),SX.toColor(`#34e2e2`),SX.toColor(`#eeeeec`)],t=[0,95,135,175,215,255];for(let n=0;n<216;n++){let r=t[n/36%6|0],i=t[n/6%6|0],a=t[n%6];e.push({css:bX.toCss(r,i,a),rgba:bX.toRgba(r,i,a)})}for(let t=0;t<24;t++){let n=8+t*10;e.push({css:bX.toCss(n,n,n),rgba:bX.toRgba(n,n,n)})}return e})()),YZ=SX.toColor(`#ffffff`),XZ=SX.toColor(`#000000`),ZZ=SX.toColor(`#ffffff`),QZ=XZ,$Z={css:`rgba(255, 255, 255, 0.3)`,rgba:4294967117},eQ=YZ,tQ=class extends pq{constructor(e){super(),this._optionsService=e,this._contrastCache=new qZ,this._halfContrastCache=new qZ,this._onChangeColors=this._register(new Q),this.onChangeColors=this._onChangeColors.event,this._colors={foreground:YZ,background:XZ,cursor:ZZ,cursorAccent:QZ,selectionForeground:void 0,selectionBackgroundTransparent:$Z,selectionBackgroundOpaque:xX.blend(XZ,$Z),selectionInactiveBackgroundTransparent:$Z,selectionInactiveBackgroundOpaque:xX.blend(XZ,$Z),scrollbarSliderBackground:xX.opacity(YZ,.2),scrollbarSliderHoverBackground:xX.opacity(YZ,.4),scrollbarSliderActiveBackground:xX.opacity(YZ,.5),overviewRulerBorder:YZ,ansi:JZ.slice(),contrastCache:this._contrastCache,halfContrastCache:this._halfContrastCache},this._updateRestoreColors(),this._setTheme(this._optionsService.rawOptions.theme),this._register(this._optionsService.onSpecificOptionChange(`minimumContrastRatio`,()=>this._contrastCache.clear())),this._register(this._optionsService.onSpecificOptionChange(`theme`,()=>this._setTheme(this._optionsService.rawOptions.theme)))}get colors(){return this._colors}_setTheme(e={}){let t=this._colors;if(t.foreground=nQ(e.foreground,YZ),t.background=nQ(e.background,XZ),t.cursor=xX.blend(t.background,nQ(e.cursor,ZZ)),t.cursorAccent=xX.blend(t.background,nQ(e.cursorAccent,QZ)),t.selectionBackgroundTransparent=nQ(e.selectionBackground,$Z),t.selectionBackgroundOpaque=xX.blend(t.background,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundTransparent=nQ(e.selectionInactiveBackground,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundOpaque=xX.blend(t.background,t.selectionInactiveBackgroundTransparent),t.selectionForeground=e.selectionForeground?nQ(e.selectionForeground,yX):void 0,t.selectionForeground===yX&&(t.selectionForeground=void 0),xX.isOpaque(t.selectionBackgroundTransparent)&&(t.selectionBackgroundTransparent=xX.opacity(t.selectionBackgroundTransparent,.3)),xX.isOpaque(t.selectionInactiveBackgroundTransparent)&&(t.selectionInactiveBackgroundTransparent=xX.opacity(t.selectionInactiveBackgroundTransparent,.3)),t.scrollbarSliderBackground=nQ(e.scrollbarSliderBackground,xX.opacity(t.foreground,.2)),t.scrollbarSliderHoverBackground=nQ(e.scrollbarSliderHoverBackground,xX.opacity(t.foreground,.4)),t.scrollbarSliderActiveBackground=nQ(e.scrollbarSliderActiveBackground,xX.opacity(t.foreground,.5)),t.overviewRulerBorder=nQ(e.overviewRulerBorder,eQ),t.ansi=JZ.slice(),t.ansi[0]=nQ(e.black,JZ[0]),t.ansi[1]=nQ(e.red,JZ[1]),t.ansi[2]=nQ(e.green,JZ[2]),t.ansi[3]=nQ(e.yellow,JZ[3]),t.ansi[4]=nQ(e.blue,JZ[4]),t.ansi[5]=nQ(e.magenta,JZ[5]),t.ansi[6]=nQ(e.cyan,JZ[6]),t.ansi[7]=nQ(e.white,JZ[7]),t.ansi[8]=nQ(e.brightBlack,JZ[8]),t.ansi[9]=nQ(e.brightRed,JZ[9]),t.ansi[10]=nQ(e.brightGreen,JZ[10]),t.ansi[11]=nQ(e.brightYellow,JZ[11]),t.ansi[12]=nQ(e.brightBlue,JZ[12]),t.ansi[13]=nQ(e.brightMagenta,JZ[13]),t.ansi[14]=nQ(e.brightCyan,JZ[14]),t.ansi[15]=nQ(e.brightWhite,JZ[15]),e.extendedAnsi){let n=Math.min(t.ansi.length-16,e.extendedAnsi.length);for(let r=0;r<n;r++)t.ansi[r+16]=nQ(e.extendedAnsi[r],JZ[r+16])}this._contrastCache.clear(),this._halfContrastCache.clear(),this._updateRestoreColors(),this._onChangeColors.fire(this.colors)}restoreColor(e){this._restoreColor(e),this._onChangeColors.fire(this.colors)}_restoreColor(e){if(e===void 0){for(let e=0;e<this._restoreColors.ansi.length;++e)this._colors.ansi[e]=this._restoreColors.ansi[e];return}switch(e){case 256:this._colors.foreground=this._restoreColors.foreground;break;case 257:this._colors.background=this._restoreColors.background;break;case 258:this._colors.cursor=this._restoreColors.cursor;break;default:this._colors.ansi[e]=this._restoreColors.ansi[e]}}modifyColors(e){e(this._colors),this._onChangeColors.fire(this.colors)}_updateRestoreColors(){this._restoreColors={foreground:this._colors.foreground,background:this._colors.background,cursor:this._colors.cursor,ansi:this._colors.ansi.slice()}}};tQ=WG([Z(0,CK)],tQ);function nQ(e,t){if(e!==void 0)try{return SX.toColor(e)}catch{}return t}var rQ=class{constructor(...e){this._entries=new Map;for(let[t,n]of e)this.set(t,n)}set(e,t){let n=this._entries.get(e);return this._entries.set(e,t),n}forEach(e){for(let[t,n]of this._entries.entries())e(t,n)}has(e){return this._entries.has(e)}get(e){return this._entries.get(e)}},iQ=class{constructor(){this._services=new rQ,this._services.set(xK,this)}setService(e,t){this._services.set(e,t)}getService(e){return this._services.get(e)}createInstance(e,...t){let n=mK(e).sort((e,t)=>e.index-t.index),r=[];for(let t of n){let n=this._services.get(t.id);if(!n)throw Error(`[createInstance] ${e.name} depends on UNKNOWN service ${t.id._id}.`);r.push(n)}let i=n.length>0?n[0].index:t.length;if(t.length!==i)throw Error(`[createInstance] First service dependency of ${e.name} at position ${i+1} conflicts with ${t.length} static arguments`);return new e(...t,...r)}},aQ={trace:0,debug:1,info:2,warn:3,error:4,off:5},oQ=`xterm.js: `,sQ=class extends pq{constructor(e){super(),this._optionsService=e,this._logLevel=5,this._updateLogLevel(),this._register(this._optionsService.onSpecificOptionChange(`logLevel`,()=>this._updateLogLevel())),cQ=this}get logLevel(){return this._logLevel}_updateLogLevel(){this._logLevel=aQ[this._optionsService.rawOptions.logLevel]}_evalLazyOptionalParams(e){for(let t=0;t<e.length;t++)typeof e[t]==`function`&&(e[t]=e[t]())}_log(e,t,n){this._evalLazyOptionalParams(n),e.call(console,(this._optionsService.options.logger?``:oQ)+t,...n)}trace(e,...t){this._logLevel<=0&&this._log(this._optionsService.options.logger?.trace.bind(this._optionsService.options.logger)??console.log,e,t)}debug(e,...t){this._logLevel<=1&&this._log(this._optionsService.options.logger?.debug.bind(this._optionsService.options.logger)??console.log,e,t)}info(e,...t){this._logLevel<=2&&this._log(this._optionsService.options.logger?.info.bind(this._optionsService.options.logger)??console.info,e,t)}warn(e,...t){this._logLevel<=3&&this._log(this._optionsService.options.logger?.warn.bind(this._optionsService.options.logger)??console.warn,e,t)}error(e,...t){this._logLevel<=4&&this._log(this._optionsService.options.logger?.error.bind(this._optionsService.options.logger)??console.error,e,t)}};sQ=WG([Z(0,CK)],sQ);var cQ,lQ=class extends pq{constructor(e){super(),this._maxLength=e,this.onDeleteEmitter=this._register(new Q),this.onDelete=this.onDeleteEmitter.event,this.onInsertEmitter=this._register(new Q),this.onInsert=this.onInsertEmitter.event,this.onTrimEmitter=this._register(new Q),this.onTrim=this.onTrimEmitter.event,this._array=Array(this._maxLength),this._startIndex=0,this._length=0}get maxLength(){return this._maxLength}set maxLength(e){if(this._maxLength===e)return;let t=Array(e);for(let n=0;n<Math.min(e,this.length);n++)t[n]=this._array[this._getCyclicIndex(n)];this._array=t,this._maxLength=e,this._startIndex=0}get length(){return this._length}set length(e){if(e>this._length)for(let t=this._length;t<e;t++)this._array[t]=void 0;this._length=e}get(e){return this._array[this._getCyclicIndex(e)]}set(e,t){this._array[this._getCyclicIndex(e)]=t}push(e){this._array[this._getCyclicIndex(this._length)]=e,this._length===this._maxLength?(this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1)):this._length++}recycle(){if(this._length!==this._maxLength)throw Error(`Can only recycle when the buffer is full`);return this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1),this._array[this._getCyclicIndex(this._length-1)]}get isFull(){return this._length===this._maxLength}pop(){return this._array[this._getCyclicIndex(this._length---1)]}splice(e,t,...n){if(t){for(let n=e;n<this._length-t;n++)this._array[this._getCyclicIndex(n)]=this._array[this._getCyclicIndex(n+t)];this._length-=t,this.onDeleteEmitter.fire({index:e,amount:t})}for(let t=this._length-1;t>=e;t--)this._array[this._getCyclicIndex(t+n.length)]=this._array[this._getCyclicIndex(t)];for(let t=0;t<n.length;t++)this._array[this._getCyclicIndex(e+t)]=n[t];if(n.length&&this.onInsertEmitter.fire({index:e,amount:n.length}),this._length+n.length>this._maxLength){let e=this._length+n.length-this._maxLength;this._startIndex+=e,this._length=this._maxLength,this.onTrimEmitter.fire(e)}else this._length+=n.length}trimStart(e){e>this._length&&(e=this._length),this._startIndex+=e,this._length-=e,this.onTrimEmitter.fire(e)}shiftElements(e,t,n){if(!(t<=0)){if(e<0||e>=this._length)throw Error(`start argument out of range`);if(e+n<0)throw Error(`Cannot shift elements in list beyond index 0`);if(n>0){for(let r=t-1;r>=0;r--)this.set(e+r+n,this.get(e+r));let r=e+t+n-this._length;if(r>0)for(this._length+=r;this._length>this._maxLength;)this._length--,this._startIndex++,this.onTrimEmitter.fire(1)}else for(let r=0;r<t;r++)this.set(e+r+n,this.get(e+r))}}_getCyclicIndex(e){return(this._startIndex+e)%this._maxLength}},uQ=3,dQ=Object.freeze(new cK),fQ=0,pQ=2,mQ=class e{constructor(e,t,n=!1){this.isWrapped=n,this._combined={},this._extendedAttrs={},this._data=new Uint32Array(e*uQ);let r=t||uK.fromCharData([0,oK,1,0]);for(let t=0;t<e;++t)this.setCell(t,r);this.length=e}get(e){let t=this._data[e*uQ+0],n=t&2097151;return[this._data[e*uQ+1],t&2097152?this._combined[e]:n?nK(n):``,t>>22,t&2097152?this._combined[e].charCodeAt(this._combined[e].length-1):n]}set(e,t){this._data[e*uQ+1]=t[0],t[1].length>1?(this._combined[e]=t[1],this._data[e*uQ+0]=e|2097152|t[2]<<22):this._data[e*uQ+0]=t[1].charCodeAt(0)|t[2]<<22}getWidth(e){return this._data[e*uQ+0]>>22}hasWidth(e){return this._data[e*uQ+0]&12582912}getFg(e){return this._data[e*uQ+1]}getBg(e){return this._data[e*uQ+2]}hasContent(e){return this._data[e*uQ+0]&4194303}getCodePoint(e){let t=this._data[e*uQ+0];return t&2097152?this._combined[e].charCodeAt(this._combined[e].length-1):t&2097151}isCombined(e){return this._data[e*uQ+0]&2097152}getString(e){let t=this._data[e*uQ+0];return t&2097152?this._combined[e]:t&2097151?nK(t&2097151):``}isProtected(e){return this._data[e*uQ+2]&536870912}loadCell(e,t){return fQ=e*uQ,t.content=this._data[fQ+0],t.fg=this._data[fQ+1],t.bg=this._data[fQ+2],t.content&2097152&&(t.combinedData=this._combined[e]),t.bg&268435456&&(t.extended=this._extendedAttrs[e]),t}setCell(e,t){t.content&2097152&&(this._combined[e]=t.combinedData),t.bg&268435456&&(this._extendedAttrs[e]=t.extended),this._data[e*uQ+0]=t.content,this._data[e*uQ+1]=t.fg,this._data[e*uQ+2]=t.bg}setCellFromCodepoint(e,t,n,r){r.bg&268435456&&(this._extendedAttrs[e]=r.extended),this._data[e*uQ+0]=t|n<<22,this._data[e*uQ+1]=r.fg,this._data[e*uQ+2]=r.bg}addCodepointToCell(e,t,n){let r=this._data[e*uQ+0];r&2097152?this._combined[e]+=nK(t):r&2097151?(this._combined[e]=nK(r&2097151)+nK(t),r&=-2097152,r|=2097152):r=t|1<<22,n&&(r&=-12582913,r|=n<<22),this._data[e*uQ+0]=r}insertCells(e,t,n){if(e%=this.length,e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,n),t<this.length-e){let r=new uK;for(let n=this.length-e-t-1;n>=0;--n)this.setCell(e+t+n,this.loadCell(e+n,r));for(let r=0;r<t;++r)this.setCell(e+r,n)}else for(let t=e;t<this.length;++t)this.setCell(t,n);this.getWidth(this.length-1)===2&&this.setCellFromCodepoint(this.length-1,0,1,n)}deleteCells(e,t,n){if(e%=this.length,t<this.length-e){let r=new uK;for(let n=0;n<this.length-e-t;++n)this.setCell(e+n,this.loadCell(e+t+n,r));for(let e=this.length-t;e<this.length;++e)this.setCell(e,n)}else for(let t=e;t<this.length;++t)this.setCell(t,n);e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,n),this.getWidth(e)===0&&!this.hasContent(e)&&this.setCellFromCodepoint(e,0,1,n)}replaceCells(e,t,n,r=!1){if(r){for(e&&this.getWidth(e-1)===2&&!this.isProtected(e-1)&&this.setCellFromCodepoint(e-1,0,1,n),t<this.length&&this.getWidth(t-1)===2&&!this.isProtected(t)&&this.setCellFromCodepoint(t,0,1,n);e<t&&e<this.length;)this.isProtected(e)||this.setCell(e,n),e++;return}for(e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,n),t<this.length&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t,0,1,n);e<t&&e<this.length;)this.setCell(e++,n)}resize(e,t){if(e===this.length)return this._data.length*4*pQ<this._data.buffer.byteLength;let n=e*uQ;if(e>this.length){if(this._data.buffer.byteLength>=n*4)this._data=new Uint32Array(this._data.buffer,0,n);else{let e=new Uint32Array(n);e.set(this._data),this._data=e}for(let n=this.length;n<e;++n)this.setCell(n,t)}else{this._data=this._data.subarray(0,n);let t=Object.keys(this._combined);for(let n=0;n<t.length;n++){let r=parseInt(t[n],10);r>=e&&delete this._combined[r]}let r=Object.keys(this._extendedAttrs);for(let t=0;t<r.length;t++){let n=parseInt(r[t],10);n>=e&&delete this._extendedAttrs[n]}}return this.length=e,n*4*pQ<this._data.buffer.byteLength}cleanupMemory(){if(this._data.length*4*pQ<this._data.buffer.byteLength){let e=new Uint32Array(this._data.length);return e.set(this._data),this._data=e,1}return 0}fill(e,t=!1){if(t){for(let t=0;t<this.length;++t)this.isProtected(t)||this.setCell(t,e);return}this._combined={},this._extendedAttrs={};for(let t=0;t<this.length;++t)this.setCell(t,e)}copyFrom(e){this.length===e.length?this._data.set(e._data):this._data=new Uint32Array(e._data),this.length=e.length,this._combined={};for(let t in e._combined)this._combined[t]=e._combined[t];this._extendedAttrs={};for(let t in e._extendedAttrs)this._extendedAttrs[t]=e._extendedAttrs[t];this.isWrapped=e.isWrapped}clone(){let t=new e(0);t._data=new Uint32Array(this._data),t.length=this.length;for(let e in this._combined)t._combined[e]=this._combined[e];for(let e in this._extendedAttrs)t._extendedAttrs[e]=this._extendedAttrs[e];return t.isWrapped=this.isWrapped,t}getTrimmedLength(){for(let e=this.length-1;e>=0;--e)if(this._data[e*uQ+0]&4194303)return e+(this._data[e*uQ+0]>>22);return 0}getNoBgTrimmedLength(){for(let e=this.length-1;e>=0;--e)if(this._data[e*uQ+0]&4194303||this._data[e*uQ+2]&50331648)return e+(this._data[e*uQ+0]>>22);return 0}copyCellsFrom(e,t,n,r,i){let a=e._data;if(i)for(let i=r-1;i>=0;i--){for(let e=0;e<uQ;e++)this._data[(n+i)*uQ+e]=a[(t+i)*uQ+e];a[(t+i)*uQ+2]&268435456&&(this._extendedAttrs[n+i]=e._extendedAttrs[t+i])}else for(let i=0;i<r;i++){for(let e=0;e<uQ;e++)this._data[(n+i)*uQ+e]=a[(t+i)*uQ+e];a[(t+i)*uQ+2]&268435456&&(this._extendedAttrs[n+i]=e._extendedAttrs[t+i])}let o=Object.keys(e._combined);for(let r=0;r<o.length;r++){let i=parseInt(o[r],10);i>=t&&(this._combined[i-t+n]=e._combined[i])}}translateToString(e,t,n,r){t??=0,n??=this.length,e&&(n=Math.min(n,this.getTrimmedLength())),r&&(r.length=0);let i=``;for(;t<n;){let e=this._data[t*uQ+0],n=e&2097151,a=e&2097152?this._combined[t]:n?nK(n):sK;if(i+=a,r)for(let e=0;e<a.length;++e)r.push(t);t+=e>>22||1}return r&&r.push(t),i}};function hQ(e,t,n,r,i,a){let o=[];for(let s=0;s<e.length-1;s++){let c=s,l=e.get(++c);if(!l.isWrapped)continue;let u=[e.get(s)];for(;c<e.length&&l.isWrapped;)u.push(l),l=e.get(++c);if(!a&&r>=s&&r<c){s+=u.length-1;continue}let d=0,f=yQ(u,d,t),p=1,m=0;for(;p<u.length;){let e=yQ(u,p,t),r=e-m,a=n-f,o=Math.min(r,a);u[d].copyCellsFrom(u[p],m,f,o,!1),f+=o,f===n&&(d++,f=0),m+=o,m===e&&(p++,m=0),f===0&&d!==0&&u[d-1].getWidth(n-1)===2&&(u[d].copyCellsFrom(u[d-1],n-1,f++,1,!1),u[d-1].setCell(n-1,i))}u[d].replaceCells(f,n,i);let h=0;for(let e=u.length-1;e>0&&(e>d||u[e].getTrimmedLength()===0);e--)h++;h>0&&(o.push(s+u.length-h),o.push(h)),s+=u.length-1}return o}function gQ(e,t){let n=[],r=0,i=t[r],a=0;for(let o=0;o<e.length;o++)if(i===o){let n=t[++r];e.onDeleteEmitter.fire({index:o-a,amount:n}),o+=n-1,a+=n,i=t[++r]}else n.push(o);return{layout:n,countRemoved:a}}function _Q(e,t){let n=[];for(let r=0;r<t.length;r++)n.push(e.get(t[r]));for(let t=0;t<n.length;t++)e.set(t,n[t]);e.length=t.length}function vQ(e,t,n){let r=[],i=e.map((n,r)=>yQ(e,r,t)).reduce((e,t)=>e+t),a=0,o=0,s=0;for(;s<i;){if(i-s<n){r.push(i-s);break}a+=n;let c=yQ(e,o,t);a>c&&(a-=c,o++);let l=e[o].getWidth(a-1)===2;l&&a--;let u=l?n-1:n;r.push(u),s+=u}return r}function yQ(e,t,n){if(t===e.length-1)return e[t].getTrimmedLength();let r=!e[t].hasContent(n-1)&&e[t].getWidth(n-1)===1,i=e[t+1].getWidth(0)===2;return r&&i?n-1:n}var bQ=class e{constructor(t){this.line=t,this.isDisposed=!1,this._disposables=[],this._id=e._nextId++,this._onDispose=this.register(new Q),this.onDispose=this._onDispose.event}get id(){return this._id}dispose(){this.isDisposed||(this.isDisposed=!0,this.line=-1,this._onDispose.fire(),cq(this._disposables),this._disposables.length=0)}register(e){return this._disposables.push(e),e}};bQ._nextId=1;var xQ=bQ,SQ={},CQ=SQ.B;SQ[0]={"`":`◆`,a:`▒`,b:`␉`,c:`␌`,d:`␍`,e:`␊`,f:`°`,g:`±`,h:``,i:`␋`,j:`┘`,k:`┐`,l:`┌`,m:`└`,n:`┼`,o:`⎺`,p:`⎻`,q:`─`,r:`⎼`,s:`⎽`,t:`├`,u:`┤`,v:`┴`,w:`┬`,x:`│`,y:`≤`,z:`≥`,"{":`π`,"|":`≠`,"}":`£`,"~":`·`},SQ.A={"#":`£`},SQ.B=void 0,SQ[4]={"#":`£`,"@":`¾`,"[":`ij`,"\\":`½`,"]":`|`,"{":`¨`,"|":`f`,"}":`¼`,"~":`´`},SQ.C=SQ[5]={"[":`Ä`,"\\":`Ö`,"]":`Å`,"^":`Ü`,"`":`é`,"{":`ä`,"|":`ö`,"}":`å`,"~":`ü`},SQ.R={"#":`£`,"@":`à`,"[":`°`,"\\":`ç`,"]":`§`,"{":`é`,"|":`ù`,"}":`è`,"~":`¨`},SQ.Q={"@":`à`,"[":`â`,"\\":`ç`,"]":`ê`,"^":`î`,"`":`ô`,"{":`é`,"|":`ù`,"}":`è`,"~":`û`},SQ.K={"@":`§`,"[":`Ä`,"\\":`Ö`,"]":`Ü`,"{":`ä`,"|":`ö`,"}":`ü`,"~":`ß`},SQ.Y={"#":`£`,"@":`§`,"[":`°`,"\\":`ç`,"]":`é`,"`":`ù`,"{":`à`,"|":`ò`,"}":`è`,"~":`ì`},SQ.E=SQ[6]={"@":`Ä`,"[":`Æ`,"\\":`Ø`,"]":`Å`,"^":`Ü`,"`":`ä`,"{":`æ`,"|":`ø`,"}":`å`,"~":`ü`},SQ.Z={"#":`£`,"@":`§`,"[":`¡`,"\\":`Ñ`,"]":`¿`,"{":`°`,"|":`ñ`,"}":`ç`},SQ.H=SQ[7]={"@":`É`,"[":`Ä`,"\\":`Ö`,"]":`Å`,"^":`Ü`,"`":`é`,"{":`ä`,"|":`ö`,"}":`å`,"~":`ü`},SQ[`=`]={"#":`ù`,"@":`à`,"[":`é`,"\\":`ç`,"]":`ê`,"^":`î`,_:`è`,"`":`ô`,"{":`ä`,"|":`ö`,"}":`ü`,"~":`û`};var wQ=4294967295,TQ=class{constructor(e,t,n){this._hasScrollback=e,this._optionsService=t,this._bufferService=n,this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.tabs={},this.savedY=0,this.savedX=0,this.savedCurAttrData=dQ.clone(),this.savedCharset=CQ,this.markers=[],this._nullCell=uK.fromCharData([0,oK,1,0]),this._whitespaceCell=uK.fromCharData([0,sK,1,32]),this._isClearing=!1,this._memoryCleanupQueue=new xZ,this._memoryCleanupPosition=0,this._cols=this._bufferService.cols,this._rows=this._bufferService.rows,this.lines=new lQ(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}getNullCell(e){return e?(this._nullCell.fg=e.fg,this._nullCell.bg=e.bg,this._nullCell.extended=e.extended):(this._nullCell.fg=0,this._nullCell.bg=0,this._nullCell.extended=new lK),this._nullCell}getWhitespaceCell(e){return e?(this._whitespaceCell.fg=e.fg,this._whitespaceCell.bg=e.bg,this._whitespaceCell.extended=e.extended):(this._whitespaceCell.fg=0,this._whitespaceCell.bg=0,this._whitespaceCell.extended=new lK),this._whitespaceCell}getBlankLine(e,t){return new mQ(this._bufferService.cols,this.getNullCell(e),t)}get hasScrollback(){return this._hasScrollback&&this.lines.maxLength>this._rows}get isCursorInViewport(){let e=this.ybase+this.y-this.ydisp;return e>=0&&e<this._rows}_getCorrectBufferLength(e){if(!this._hasScrollback)return e;let t=e+this._optionsService.rawOptions.scrollback;return t>wQ?wQ:t}fillViewportRows(e){if(this.lines.length===0){e===void 0&&(e=dQ);let t=this._rows;for(;t--;)this.lines.push(this.getBlankLine(e))}}clear(){this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.lines=new lQ(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}resize(e,t){let n=this.getNullCell(dQ),r=0,i=this._getCorrectBufferLength(t);if(i>this.lines.maxLength&&(this.lines.maxLength=i),this.lines.length>0){if(this._cols<e)for(let t=0;t<this.lines.length;t++)r+=+this.lines.get(t).resize(e,n);let a=0;if(this._rows<t)for(let r=this._rows;r<t;r++)this.lines.length<t+this.ybase&&(this._optionsService.rawOptions.windowsMode||this._optionsService.rawOptions.windowsPty.backend!==void 0||this._optionsService.rawOptions.windowsPty.buildNumber!==void 0?this.lines.push(new mQ(e,n)):this.ybase>0&&this.lines.length<=this.ybase+this.y+a+1?(this.ybase--,a++,this.ydisp>0&&this.ydisp--):this.lines.push(new mQ(e,n)));else for(let e=this._rows;e>t;e--)this.lines.length>t+this.ybase&&(this.lines.length>this.ybase+this.y+1?this.lines.pop():(this.ybase++,this.ydisp++));if(i<this.lines.maxLength){let e=this.lines.length-i;e>0&&(this.lines.trimStart(e),this.ybase=Math.max(this.ybase-e,0),this.ydisp=Math.max(this.ydisp-e,0),this.savedY=Math.max(this.savedY-e,0)),this.lines.maxLength=i}this.x=Math.min(this.x,e-1),this.y=Math.min(this.y,t-1),a&&(this.y+=a),this.savedX=Math.min(this.savedX,e-1),this.scrollTop=0}if(this.scrollBottom=t-1,this._isReflowEnabled&&(this._reflow(e,t),this._cols>e))for(let t=0;t<this.lines.length;t++)r+=+this.lines.get(t).resize(e,n);this._cols=e,this._rows=t,this._memoryCleanupQueue.clear(),r>.1*this.lines.length&&(this._memoryCleanupPosition=0,this._memoryCleanupQueue.enqueue(()=>this._batchedMemoryCleanup()))}_batchedMemoryCleanup(){let e=!0;this._memoryCleanupPosition>=this.lines.length&&(this._memoryCleanupPosition=0,e=!1);let t=0;for(;this._memoryCleanupPosition<this.lines.length;)if(t+=this.lines.get(this._memoryCleanupPosition++).cleanupMemory(),t>100)return!0;return e}get _isReflowEnabled(){let e=this._optionsService.rawOptions.windowsPty;return e&&e.buildNumber?this._hasScrollback&&e.backend===`conpty`&&e.buildNumber>=21376:this._hasScrollback&&!this._optionsService.rawOptions.windowsMode}_reflow(e,t){this._cols!==e&&(e>this._cols?this._reflowLarger(e,t):this._reflowSmaller(e,t))}_reflowLarger(e,t){let n=this._optionsService.rawOptions.reflowCursorLine,r=hQ(this.lines,this._cols,e,this.ybase+this.y,this.getNullCell(dQ),n);if(r.length>0){let n=gQ(this.lines,r);_Q(this.lines,n.layout),this._reflowLargerAdjustViewport(e,t,n.countRemoved)}}_reflowLargerAdjustViewport(e,t,n){let r=this.getNullCell(dQ),i=n;for(;i-->0;)this.ybase===0?(this.y>0&&this.y--,this.lines.length<t&&this.lines.push(new mQ(e,r))):(this.ydisp===this.ybase&&this.ydisp--,this.ybase--);this.savedY=Math.max(this.savedY-n,0)}_reflowSmaller(e,t){let n=this._optionsService.rawOptions.reflowCursorLine,r=this.getNullCell(dQ),i=[],a=0;for(let o=this.lines.length-1;o>=0;o--){let s=this.lines.get(o);if(!s||!s.isWrapped&&s.getTrimmedLength()<=e)continue;let c=[s];for(;s.isWrapped&&o>0;)s=this.lines.get(--o),c.unshift(s);if(!n){let e=this.ybase+this.y;if(e>=o&&e<o+c.length)continue}let l=c[c.length-1].getTrimmedLength(),u=vQ(c,this._cols,e),d=u.length-c.length,f;f=this.ybase===0&&this.y!==this.lines.length-1?Math.max(0,this.y-this.lines.maxLength+d):Math.max(0,this.lines.length-this.lines.maxLength+d);let p=[];for(let e=0;e<d;e++){let e=this.getBlankLine(dQ,!0);p.push(e)}p.length>0&&(i.push({start:o+c.length+a,newLines:p}),a+=p.length),c.push(...p);let m=u.length-1,h=u[m];h===0&&(m--,h=u[m]);let g=c.length-d-1,_=l;for(;g>=0;){let e=Math.min(_,h);if(c[m]===void 0)break;c[m].copyCellsFrom(c[g],_-e,h-e,e,!0),h-=e,h===0&&(m--,h=u[m]),_-=e,_===0&&(g--,_=yQ(c,Math.max(g,0),this._cols))}for(let t=0;t<c.length;t++)u[t]<e&&c[t].setCell(u[t],r);let v=d-f;for(;v-->0;)this.ybase===0?this.y<t-1?(this.y++,this.lines.pop()):(this.ybase++,this.ydisp++):this.ybase<Math.min(this.lines.maxLength,this.lines.length+a)-t&&(this.ybase===this.ydisp&&this.ydisp++,this.ybase++);this.savedY=Math.min(this.savedY+d,this.ybase+t-1)}if(i.length>0){let e=[],t=[];for(let e=0;e<this.lines.length;e++)t.push(this.lines.get(e));let n=this.lines.length,r=n-1,o=0,s=i[o];this.lines.length=Math.min(this.lines.maxLength,this.lines.length+a);let c=0;for(let l=Math.min(this.lines.maxLength-1,n+a-1);l>=0;l--)if(s&&s.start>r+c){for(let e=s.newLines.length-1;e>=0;e--)this.lines.set(l--,s.newLines[e]);l++,e.push({index:r+1,amount:s.newLines.length}),c+=s.newLines.length,s=i[++o]}else this.lines.set(l,t[r--]);let l=0;for(let t=e.length-1;t>=0;t--)e[t].index+=l,this.lines.onInsertEmitter.fire(e[t]),l+=e[t].amount;let u=Math.max(0,n+a-this.lines.maxLength);u>0&&this.lines.onTrimEmitter.fire(u)}}translateBufferLineToString(e,t,n=0,r){let i=this.lines.get(e);return i?i.translateToString(t,n,r):``}getWrappedRangeForLine(e){let t=e,n=e;for(;t>0&&this.lines.get(t).isWrapped;)t--;for(;n+1<this.lines.length&&this.lines.get(n+1).isWrapped;)n++;return{first:t,last:n}}setupTabStops(e){for(e==null?(this.tabs={},e=0):this.tabs[e]||(e=this.prevStop(e));e<this._cols;e+=this._optionsService.rawOptions.tabStopWidth)this.tabs[e]=!0}prevStop(e){for(e??=this.x;!this.tabs[--e]&&e>0;);return e>=this._cols?this._cols-1:e<0?0:e}nextStop(e){for(e??=this.x;!this.tabs[++e]&&e<this._cols;);return e>=this._cols?this._cols-1:e<0?0:e}clearMarkers(e){this._isClearing=!0;for(let t=0;t<this.markers.length;t++)this.markers[t].line===e&&(this.markers[t].dispose(),this.markers.splice(t--,1));this._isClearing=!1}clearAllMarkers(){this._isClearing=!0;for(let e=0;e<this.markers.length;e++)this.markers[e].dispose();this.markers.length=0,this._isClearing=!1}addMarker(e){let t=new xQ(e);return this.markers.push(t),t.register(this.lines.onTrim(e=>{t.line-=e,t.line<0&&t.dispose()})),t.register(this.lines.onInsert(e=>{t.line>=e.index&&(t.line+=e.amount)})),t.register(this.lines.onDelete(e=>{t.line>=e.index&&t.line<e.index+e.amount&&t.dispose(),t.line>e.index&&(t.line-=e.amount)})),t.register(t.onDispose(()=>this._removeMarker(t))),t}_removeMarker(e){this._isClearing||this.markers.splice(this.markers.indexOf(e),1)}},EQ=class extends pq{constructor(e,t){super(),this._optionsService=e,this._bufferService=t,this._onBufferActivate=this._register(new Q),this.onBufferActivate=this._onBufferActivate.event,this.reset(),this._register(this._optionsService.onSpecificOptionChange(`scrollback`,()=>this.resize(this._bufferService.cols,this._bufferService.rows))),this._register(this._optionsService.onSpecificOptionChange(`tabStopWidth`,()=>this.setupTabStops()))}reset(){this._normal=new TQ(!0,this._optionsService,this._bufferService),this._normal.fillViewportRows(),this._alt=new TQ(!1,this._optionsService,this._bufferService),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}),this.setupTabStops()}get alt(){return this._alt}get active(){return this._activeBuffer}get normal(){return this._normal}activateNormalBuffer(){this._activeBuffer!==this._normal&&(this._normal.x=this._alt.x,this._normal.y=this._alt.y,this._alt.clearAllMarkers(),this._alt.clear(),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}))}activateAltBuffer(e){this._activeBuffer!==this._alt&&(this._alt.fillViewportRows(e),this._alt.x=this._normal.x,this._alt.y=this._normal.y,this._activeBuffer=this._alt,this._onBufferActivate.fire({activeBuffer:this._alt,inactiveBuffer:this._normal}))}resize(e,t){this._normal.resize(e,t),this._alt.resize(e,t),this.setupTabStops(e)}setupTabStops(e){this._normal.setupTabStops(e),this._alt.setupTabStops(e)}},DQ=2,OQ=1,kQ=class extends pq{constructor(e){super(),this.isUserScrolling=!1,this._onResize=this._register(new Q),this.onResize=this._onResize.event,this._onScroll=this._register(new Q),this.onScroll=this._onScroll.event,this.cols=Math.max(e.rawOptions.cols||0,DQ),this.rows=Math.max(e.rawOptions.rows||0,OQ),this.buffers=this._register(new EQ(e,this)),this._register(this.buffers.onBufferActivate(e=>{this._onScroll.fire(e.activeBuffer.ydisp)}))}get buffer(){return this.buffers.active}resize(e,t){let n=this.cols!==e,r=this.rows!==t;this.cols=e,this.rows=t,this.buffers.resize(e,t),this._onResize.fire({cols:e,rows:t,colsChanged:n,rowsChanged:r})}reset(){this.buffers.reset(),this.isUserScrolling=!1}scroll(e,t=!1){let n=this.buffer,r;r=this._cachedBlankLine,(!r||r.length!==this.cols||r.getFg(0)!==e.fg||r.getBg(0)!==e.bg)&&(r=n.getBlankLine(e,t),this._cachedBlankLine=r),r.isWrapped=t;let i=n.ybase+n.scrollTop,a=n.ybase+n.scrollBottom;if(n.scrollTop===0){let e=n.lines.isFull;a===n.lines.length-1?e?n.lines.recycle().copyFrom(r):n.lines.push(r.clone()):n.lines.splice(a+1,0,r.clone()),e?this.isUserScrolling&&(n.ydisp=Math.max(n.ydisp-1,0)):(n.ybase++,this.isUserScrolling||n.ydisp++)}else{let e=a-i+1;n.lines.shiftElements(i+1,e-1,-1),n.lines.set(a,r.clone())}this.isUserScrolling||(n.ydisp=n.ybase),this._onScroll.fire(n.ydisp)}scrollLines(e,t){let n=this.buffer;if(e<0){if(n.ydisp===0)return;this.isUserScrolling=!0}else e+n.ydisp>=n.ybase&&(this.isUserScrolling=!1);let r=n.ydisp;n.ydisp=Math.max(Math.min(n.ydisp+e,n.ybase),0),r!==n.ydisp&&(t||this._onScroll.fire(n.ydisp))}};kQ=WG([Z(0,CK)],kQ);var AQ={cols:80,rows:24,cursorBlink:!1,cursorStyle:`block`,cursorWidth:1,cursorInactiveStyle:`outline`,customGlyphs:!0,drawBoldTextInBrightColors:!0,documentOverride:null,fastScrollModifier:`alt`,fastScrollSensitivity:5,fontFamily:`monospace`,fontSize:15,fontWeight:`normal`,fontWeightBold:`bold`,ignoreBracketedPasteMode:!1,lineHeight:1,letterSpacing:0,linkHandler:null,logLevel:`info`,logger:null,scrollback:1e3,scrollOnEraseInDisplay:!1,scrollOnUserInput:!0,scrollSensitivity:1,screenReaderMode:!1,smoothScrollDuration:0,macOptionIsMeta:!1,macOptionClickForcesSelection:!1,minimumContrastRatio:1,disableStdin:!1,allowProposedApi:!1,allowTransparency:!1,tabStopWidth:8,theme:{},reflowCursorLine:!1,rescaleOverlappingGlyphs:!1,rightClickSelectsWord:fZ,windowOptions:{},windowsMode:!1,windowsPty:{},wordSeparator:` ()[]{}',"\``,altClickMovesCursor:!0,convertEol:!1,termName:`xterm`,cancelEvents:!1,overviewRuler:{}},jQ=[`normal`,`bold`,`100`,`200`,`300`,`400`,`500`,`600`,`700`,`800`,`900`],MQ=class extends pq{constructor(e){super(),this._onOptionChange=this._register(new Q),this.onOptionChange=this._onOptionChange.event;let t={...AQ};for(let n in e)if(n in t)try{let r=e[n];t[n]=this._sanitizeAndValidateOption(n,r)}catch(e){console.error(e)}this.rawOptions=t,this.options={...t},this._setupOptions(),this._register(uq(()=>{this.rawOptions.linkHandler=null,this.rawOptions.documentOverride=null}))}onSpecificOptionChange(e,t){return this.onOptionChange(n=>{n===e&&t(this.rawOptions[e])})}onMultipleOptionChange(e,t){return this.onOptionChange(n=>{e.indexOf(n)!==-1&&t()})}_setupOptions(){let e=e=>{if(!(e in AQ))throw Error(`No option with key "${e}"`);return this.rawOptions[e]},t=(e,t)=>{if(!(e in AQ))throw Error(`No option with key "${e}"`);t=this._sanitizeAndValidateOption(e,t),this.rawOptions[e]!==t&&(this.rawOptions[e]=t,this._onOptionChange.fire(e))};for(let n in this.rawOptions){let r={get:e.bind(this,n),set:t.bind(this,n)};Object.defineProperty(this.options,n,r)}}_sanitizeAndValidateOption(e,t){switch(e){case`cursorStyle`:if(t||=AQ[e],!NQ(t))throw Error(`"${t}" is not a valid value for ${e}`);break;case`wordSeparator`:t||=AQ[e];break;case`fontWeight`:case`fontWeightBold`:if(typeof t==`number`&&1<=t&&t<=1e3)break;t=jQ.includes(t)?t:AQ[e];break;case`cursorWidth`:t=Math.floor(t);case`lineHeight`:case`tabStopWidth`:if(t<1)throw Error(`${e} cannot be less than 1, value: ${t}`);break;case`minimumContrastRatio`:t=Math.max(1,Math.min(21,Math.round(t*10)/10));break;case`scrollback`:if(t=Math.min(t,4294967295),t<0)throw Error(`${e} cannot be less than 0, value: ${t}`);break;case`fastScrollSensitivity`:case`scrollSensitivity`:if(t<=0)throw Error(`${e} cannot be less than or equal to 0, value: ${t}`);break;case`rows`:case`cols`:if(!t&&t!==0)throw Error(`${e} must be numeric, value: ${t}`);break;case`windowsPty`:t??={};break}return t}};function NQ(e){return e===`block`||e===`underline`||e===`bar`}function PQ(e,t=5){if(typeof e!=`object`)return e;let n=Array.isArray(e)?[]:{};for(let r in e)n[r]=t<=1?e[r]:e[r]&&PQ(e[r],t-1);return n}var FQ=Object.freeze({insertMode:!1}),IQ=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,cursorBlink:void 0,cursorStyle:void 0,origin:!1,reverseWraparound:!1,sendFocus:!1,synchronizedOutput:!1,wraparound:!0}),LQ=class extends pq{constructor(e,t,n){super(),this._bufferService=e,this._logService=t,this._optionsService=n,this.isCursorInitialized=!1,this.isCursorHidden=!1,this._onData=this._register(new Q),this.onData=this._onData.event,this._onUserInput=this._register(new Q),this.onUserInput=this._onUserInput.event,this._onBinary=this._register(new Q),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this._register(new Q),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.modes=PQ(FQ),this.decPrivateModes=PQ(IQ)}reset(){this.modes=PQ(FQ),this.decPrivateModes=PQ(IQ)}triggerDataEvent(e,t=!1){if(this._optionsService.rawOptions.disableStdin)return;let n=this._bufferService.buffer;t&&this._optionsService.rawOptions.scrollOnUserInput&&n.ybase!==n.ydisp&&this._onRequestScrollToBottom.fire(),t&&this._onUserInput.fire(),this._logService.debug(`sending data "${e}"`),this._logService.trace(`sending data (codes)`,()=>e.split(``).map(e=>e.charCodeAt(0))),this._onData.fire(e)}triggerBinaryEvent(e){this._optionsService.rawOptions.disableStdin||(this._logService.debug(`sending binary "${e}"`),this._logService.trace(`sending binary (codes)`,()=>e.split(``).map(e=>e.charCodeAt(0))),this._onBinary.fire(e))}};LQ=WG([Z(0,_K),Z(1,SK),Z(2,CK)],LQ);var RQ={NONE:{events:0,restrict:()=>!1},X10:{events:1,restrict:e=>e.button===4||e.action!==1?!1:(e.ctrl=!1,e.alt=!1,e.shift=!1,!0)},VT200:{events:19,restrict:e=>e.action!==32},DRAG:{events:23,restrict:e=>!(e.action===32&&e.button===3)},ANY:{events:31,restrict:e=>!0}};function zQ(e,t){let n=(e.ctrl?16:0)|(e.shift?4:0)|(e.alt?8:0);return e.button===4?(n|=64,n|=e.action):(n|=e.button&3,e.button&4&&(n|=64),e.button&8&&(n|=128),e.action===32?n|=32:e.action===0&&!t&&(n|=3)),n}var BQ=String.fromCharCode,VQ={DEFAULT:e=>{let t=[zQ(e,!1)+32,e.col+32,e.row+32];return t[0]>255||t[1]>255||t[2]>255?``:`\x1B[M${BQ(t[0])}${BQ(t[1])}${BQ(t[2])}`},SGR:e=>{let t=e.action===0&&e.button!==4?`m`:`M`;return`\x1B[<${zQ(e,!0)};${e.col};${e.row}${t}`},SGR_PIXELS:e=>{let t=e.action===0&&e.button!==4?`m`:`M`;return`\x1B[<${zQ(e,!0)};${e.x};${e.y}${t}`}},HQ=class extends pq{constructor(e,t,n){super(),this._bufferService=e,this._coreService=t,this._optionsService=n,this._protocols={},this._encodings={},this._activeProtocol=``,this._activeEncoding=``,this._lastEvent=null,this._wheelPartialScroll=0,this._onProtocolChange=this._register(new Q),this.onProtocolChange=this._onProtocolChange.event;for(let e of Object.keys(RQ))this.addProtocol(e,RQ[e]);for(let e of Object.keys(VQ))this.addEncoding(e,VQ[e]);this.reset()}addProtocol(e,t){this._protocols[e]=t}addEncoding(e,t){this._encodings[e]=t}get activeProtocol(){return this._activeProtocol}get areMouseEventsActive(){return this._protocols[this._activeProtocol].events!==0}set activeProtocol(e){if(!this._protocols[e])throw Error(`unknown protocol "${e}"`);this._activeProtocol=e,this._onProtocolChange.fire(this._protocols[e].events)}get activeEncoding(){return this._activeEncoding}set activeEncoding(e){if(!this._encodings[e])throw Error(`unknown encoding "${e}"`);this._activeEncoding=e}reset(){this.activeProtocol=`NONE`,this.activeEncoding=`DEFAULT`,this._lastEvent=null,this._wheelPartialScroll=0}consumeWheelEvent(e,t,n){if(e.deltaY===0||e.shiftKey||t===void 0||n===void 0)return 0;let r=t/n,i=this._applyScrollModifier(e.deltaY,e);return e.deltaMode===WheelEvent.DOM_DELTA_PIXEL?(i/=r+0,Math.abs(e.deltaY)<50&&(i*=.3),this._wheelPartialScroll+=i,i=Math.floor(Math.abs(this._wheelPartialScroll))*(this._wheelPartialScroll>0?1:-1),this._wheelPartialScroll%=1):e.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(i*=this._bufferService.rows),i}_applyScrollModifier(e,t){return t.altKey||t.ctrlKey||t.shiftKey?e*this._optionsService.rawOptions.fastScrollSensitivity*this._optionsService.rawOptions.scrollSensitivity:e*this._optionsService.rawOptions.scrollSensitivity}triggerMouseEvent(e){if(e.col<0||e.col>=this._bufferService.cols||e.row<0||e.row>=this._bufferService.rows||e.button===4&&e.action===32||e.button===3&&e.action!==32||e.button!==4&&(e.action===2||e.action===3)||(e.col++,e.row++,e.action===32&&this._lastEvent&&this._equalEvents(this._lastEvent,e,this._activeEncoding===`SGR_PIXELS`))||!this._protocols[this._activeProtocol].restrict(e))return!1;let t=this._encodings[this._activeEncoding](e);return t&&(this._activeEncoding===`DEFAULT`?this._coreService.triggerBinaryEvent(t):this._coreService.triggerDataEvent(t,!0)),this._lastEvent=e,!0}explainEvents(e){return{down:!!(e&1),up:!!(e&2),drag:!!(e&4),move:!!(e&8),wheel:!!(e&16)}}_equalEvents(e,t,n){if(n){if(e.x!==t.x||e.y!==t.y)return!1}else if(e.col!==t.col||e.row!==t.row)return!1;return!(e.button!==t.button||e.action!==t.action||e.ctrl!==t.ctrl||e.alt!==t.alt||e.shift!==t.shift)}};HQ=WG([Z(0,_K),Z(1,yK),Z(2,CK)],HQ);var UQ=[[768,879],[1155,1158],[1160,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1539],[1552,1557],[1611,1630],[1648,1648],[1750,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2305,2306],[2364,2364],[2369,2376],[2381,2381],[2385,2388],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2672,2673],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2883],[2893,2893],[2902,2902],[2946,2946],[3008,3008],[3021,3021],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3393,3395],[3405,3405],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3984,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4146],[4150,4151],[4153,4153],[4184,4185],[4448,4607],[4959,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7616,7626],[7678,7679],[8203,8207],[8234,8238],[8288,8291],[8298,8303],[8400,8431],[12330,12335],[12441,12442],[43014,43014],[43019,43019],[43045,43046],[64286,64286],[65024,65039],[65056,65059],[65279,65279],[65529,65531]],WQ=[[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[917505,917505],[917536,917631],[917760,917999]],GQ;function KQ(e,t){let n=0,r=t.length-1,i;if(e<t[0][0]||e>t[r][1])return!1;for(;r>=n;)if(i=n+r>>1,e>t[i][1])n=i+1;else if(e<t[i][0])r=i-1;else return!0;return!1}var qQ=class{constructor(){if(this.version=`6`,!GQ){GQ=new Uint8Array(65536),GQ.fill(1),GQ[0]=0,GQ.fill(0,1,32),GQ.fill(0,127,160),GQ.fill(2,4352,4448),GQ[9001]=2,GQ[9002]=2,GQ.fill(2,11904,42192),GQ[12351]=1,GQ.fill(2,44032,55204),GQ.fill(2,63744,64256),GQ.fill(2,65040,65050),GQ.fill(2,65072,65136),GQ.fill(2,65280,65377),GQ.fill(2,65504,65511);for(let e=0;e<UQ.length;++e)GQ.fill(0,UQ[e][0],UQ[e][1]+1)}}wcwidth(e){return e<32?0:e<127?1:e<65536?GQ[e]:KQ(e,WQ)?0:e>=131072&&e<=196605||e>=196608&&e<=262141?2:1}charProperties(e,t){let n=this.wcwidth(e),r=n===0&&t!==0;if(r){let e=JQ.extractWidth(t);e===0?r=!1:e>n&&(n=e)}return JQ.createPropertyValue(0,n,r)}},JQ=class e{constructor(){this._providers=Object.create(null),this._active=``,this._onChange=new Q,this.onChange=this._onChange.event;let e=new qQ;this.register(e),this._active=e.version,this._activeProvider=e}static extractShouldJoin(e){return(e&1)!=0}static extractWidth(e){return e>>1&3}static extractCharKind(e){return e>>3}static createPropertyValue(e,t,n=!1){return(e&16777215)<<3|(t&3)<<1|!!n}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(e){if(!this._providers[e])throw Error(`unknown Unicode version "${e}"`);this._active=e,this._activeProvider=this._providers[e],this._onChange.fire(e)}register(e){this._providers[e.version]=e}wcwidth(e){return this._activeProvider.wcwidth(e)}getStringCellWidth(t){let n=0,r=0,i=t.length;for(let a=0;a<i;++a){let o=t.charCodeAt(a);if(55296<=o&&o<=56319){if(++a>=i)return n+this.wcwidth(o);let e=t.charCodeAt(a);56320<=e&&e<=57343?o=(o-55296)*1024+e-56320+65536:n+=this.wcwidth(e)}let s=this.charProperties(o,r),c=e.extractWidth(s);e.extractShouldJoin(s)&&(c-=e.extractWidth(r)),n+=c,r=s}return n}charProperties(e,t){return this._activeProvider.charProperties(e,t)}},YQ=class{constructor(){this.glevel=0,this._charsets=[]}reset(){this.charset=void 0,this._charsets=[],this.glevel=0}setgLevel(e){this.glevel=e,this.charset=this._charsets[e]}setgCharset(e,t){this._charsets[e]=t,this.glevel===e&&(this.charset=t)}};function XQ(e){let t=e.buffer.lines.get(e.buffer.ybase+e.buffer.y-1)?.get(e.cols-1),n=e.buffer.lines.get(e.buffer.ybase+e.buffer.y);n&&t&&(n.isWrapped=t[3]!==0&&t[3]!==32)}var ZQ=2147483647,QQ=256,$Q=class e{constructor(e=32,t=32){if(this.maxLength=e,this.maxSubParamsLength=t,t>QQ)throw Error(`maxSubParamsLength must not be greater than 256`);this.params=new Int32Array(e),this.length=0,this._subParams=new Int32Array(t),this._subParamsLength=0,this._subParamsIdx=new Uint16Array(e),this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}static fromArray(t){let n=new e;if(!t.length)return n;for(let e=+!!Array.isArray(t[0]);e<t.length;++e){let r=t[e];if(Array.isArray(r))for(let e=0;e<r.length;++e)n.addSubParam(r[e]);else n.addParam(r)}return n}clone(){let t=new e(this.maxLength,this.maxSubParamsLength);return t.params.set(this.params),t.length=this.length,t._subParams.set(this._subParams),t._subParamsLength=this._subParamsLength,t._subParamsIdx.set(this._subParamsIdx),t._rejectDigits=this._rejectDigits,t._rejectSubDigits=this._rejectSubDigits,t._digitIsSub=this._digitIsSub,t}toArray(){let e=[];for(let t=0;t<this.length;++t){e.push(this.params[t]);let n=this._subParamsIdx[t]>>8,r=this._subParamsIdx[t]&255;r-n>0&&e.push(Array.prototype.slice.call(this._subParams,n,r))}return e}reset(){this.length=0,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}addParam(e){if(this._digitIsSub=!1,this.length>=this.maxLength){this._rejectDigits=!0;return}if(e<-1)throw Error(`values lesser than -1 are not allowed`);this._subParamsIdx[this.length]=this._subParamsLength<<8|this._subParamsLength,this.params[this.length++]=e>ZQ?ZQ:e}addSubParam(e){if(this._digitIsSub=!0,this.length){if(this._rejectDigits||this._subParamsLength>=this.maxSubParamsLength){this._rejectSubDigits=!0;return}if(e<-1)throw Error(`values lesser than -1 are not allowed`);this._subParams[this._subParamsLength++]=e>ZQ?ZQ:e,this._subParamsIdx[this.length-1]++}}hasSubParams(e){return(this._subParamsIdx[e]&255)-(this._subParamsIdx[e]>>8)>0}getSubParams(e){let t=this._subParamsIdx[e]>>8,n=this._subParamsIdx[e]&255;return n-t>0?this._subParams.subarray(t,n):null}getSubParamsAll(){let e={};for(let t=0;t<this.length;++t){let n=this._subParamsIdx[t]>>8,r=this._subParamsIdx[t]&255;r-n>0&&(e[t]=this._subParams.slice(n,r))}return e}addDigit(e){let t;if(this._rejectDigits||!(t=this._digitIsSub?this._subParamsLength:this.length)||this._digitIsSub&&this._rejectSubDigits)return;let n=this._digitIsSub?this._subParams:this.params,r=n[t-1];n[t-1]=~r?Math.min(r*10+e,ZQ):e}},e$=[],t$=class{constructor(){this._state=0,this._active=e$,this._id=-1,this._handlers=Object.create(null),this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let n=this._handlers[e];return n.push(t),{dispose:()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=e$}reset(){if(this._state===2)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].end(!1);this._stack.paused=!1,this._active=e$,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||e$,!this._active.length)this._handlerFb(this._id,`START`);else for(let e=this._active.length-1;e>=0;e--)this._active[e].start()}_put(e,t,n){if(!this._active.length)this._handlerFb(this._id,`PUT`,rK(e,t,n));else for(let r=this._active.length-1;r>=0;r--)this._active[r].put(e,t,n)}start(){this.reset(),this._state=1}put(e,t,n){if(this._state!==3){if(this._state===1)for(;t<n;){let n=e[t++];if(n===59){this._state=2,this._start();break}if(n<48||57<n){this._state=3;return}this._id===-1&&(this._id=0),this._id=this._id*10+n-48}this._state===2&&n-t>0&&this._put(e,t,n)}}end(e,t=!0){if(this._state!==0){if(this._state!==3)if(this._state===1&&this._start(),!this._active.length)this._handlerFb(this._id,`END`,e);else{let n=!1,r=this._active.length-1,i=!1;if(this._stack.paused&&(r=this._stack.loopPosition-1,n=t,i=this._stack.fallThrough,this._stack.paused=!1),!i&&n===!1){for(;r>=0&&(n=this._active[r].end(e),n!==!0);r--)if(n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!1,n;r--}for(;r>=0;r--)if(n=this._active[r].end(!1),n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!0,n}this._active=e$,this._id=-1,this._state=0}}},n$=class{constructor(e){this._handler=e,this._data=``,this._hitLimit=!1}start(){this._data=``,this._hitLimit=!1}put(e,t,n){this._hitLimit||(this._data+=rK(e,t,n),this._data.length>1e7&&(this._data=``,this._hitLimit=!0))}end(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data),t instanceof Promise))return t.then(e=>(this._data=``,this._hitLimit=!1,e));return this._data=``,this._hitLimit=!1,t}},r$=[],i$=class{constructor(){this._handlers=Object.create(null),this._active=r$,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=r$}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let n=this._handlers[e];return n.push(t),{dispose:()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}reset(){if(this._active.length)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].unhook(!1);this._stack.paused=!1,this._active=r$,this._ident=0}hook(e,t){if(this.reset(),this._ident=e,this._active=this._handlers[e]||r$,!this._active.length)this._handlerFb(this._ident,`HOOK`,t);else for(let e=this._active.length-1;e>=0;e--)this._active[e].hook(t)}put(e,t,n){if(!this._active.length)this._handlerFb(this._ident,`PUT`,rK(e,t,n));else for(let r=this._active.length-1;r>=0;r--)this._active[r].put(e,t,n)}unhook(e,t=!0){if(!this._active.length)this._handlerFb(this._ident,`UNHOOK`,e);else{let n=!1,r=this._active.length-1,i=!1;if(this._stack.paused&&(r=this._stack.loopPosition-1,n=t,i=this._stack.fallThrough,this._stack.paused=!1),!i&&n===!1){for(;r>=0&&(n=this._active[r].unhook(e),n!==!0);r--)if(n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!1,n;r--}for(;r>=0;r--)if(n=this._active[r].unhook(!1),n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!0,n}this._active=r$,this._ident=0}},a$=new $Q;a$.addParam(0);var o$=class{constructor(e){this._handler=e,this._data=``,this._params=a$,this._hitLimit=!1}hook(e){this._params=e.length>1||e.params[0]?e.clone():a$,this._data=``,this._hitLimit=!1}put(e,t,n){this._hitLimit||(this._data+=rK(e,t,n),this._data.length>1e7&&(this._data=``,this._hitLimit=!0))}unhook(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data,this._params),t instanceof Promise))return t.then(e=>(this._params=a$,this._data=``,this._hitLimit=!1,e));return this._params=a$,this._data=``,this._hitLimit=!1,t}},s$=class{constructor(e){this.table=new Uint8Array(e)}setDefault(e,t){this.table.fill(e<<4|t)}add(e,t,n,r){this.table[t<<8|e]=n<<4|r}addMany(e,t,n,r){for(let i=0;i<e.length;i++)this.table[t<<8|e[i]]=n<<4|r}},c$=160,l$=function(){let e=new s$(4095),t=Array.apply(null,Array(256)).map((e,t)=>t),n=(e,n)=>t.slice(e,n),r=n(32,127),i=n(0,24);i.push(25),i.push.apply(i,n(28,32));let a=n(0,14),o;for(o in e.setDefault(1,0),e.addMany(r,0,2,0),a)e.addMany([24,26,153,154],o,3,0),e.addMany(n(128,144),o,3,0),e.addMany(n(144,152),o,3,0),e.add(156,o,0,0),e.add(27,o,11,1),e.add(157,o,4,8),e.addMany([152,158,159],o,0,7),e.add(155,o,11,3),e.add(144,o,11,9);return e.addMany(i,0,3,0),e.addMany(i,1,3,1),e.add(127,1,0,1),e.addMany(i,8,0,8),e.addMany(i,3,3,3),e.add(127,3,0,3),e.addMany(i,4,3,4),e.add(127,4,0,4),e.addMany(i,6,3,6),e.addMany(i,5,3,5),e.add(127,5,0,5),e.addMany(i,2,3,2),e.add(127,2,0,2),e.add(93,1,4,8),e.addMany(r,8,5,8),e.add(127,8,5,8),e.addMany([156,27,24,26,7],8,6,0),e.addMany(n(28,32),8,0,8),e.addMany([88,94,95],1,0,7),e.addMany(r,7,0,7),e.addMany(i,7,0,7),e.add(156,7,0,0),e.add(127,7,0,7),e.add(91,1,11,3),e.addMany(n(64,127),3,7,0),e.addMany(n(48,60),3,8,4),e.addMany([60,61,62,63],3,9,4),e.addMany(n(48,60),4,8,4),e.addMany(n(64,127),4,7,0),e.addMany([60,61,62,63],4,0,6),e.addMany(n(32,64),6,0,6),e.add(127,6,0,6),e.addMany(n(64,127),6,0,0),e.addMany(n(32,48),3,9,5),e.addMany(n(32,48),5,9,5),e.addMany(n(48,64),5,0,6),e.addMany(n(64,127),5,7,0),e.addMany(n(32,48),4,9,5),e.addMany(n(32,48),1,9,2),e.addMany(n(32,48),2,9,2),e.addMany(n(48,127),2,10,0),e.addMany(n(48,80),1,10,0),e.addMany(n(81,88),1,10,0),e.addMany([89,90,92],1,10,0),e.addMany(n(96,127),1,10,0),e.add(80,1,11,9),e.addMany(i,9,0,9),e.add(127,9,0,9),e.addMany(n(28,32),9,0,9),e.addMany(n(32,48),9,9,12),e.addMany(n(48,60),9,8,10),e.addMany([60,61,62,63],9,9,10),e.addMany(i,11,0,11),e.addMany(n(32,128),11,0,11),e.addMany(n(28,32),11,0,11),e.addMany(i,10,0,10),e.add(127,10,0,10),e.addMany(n(28,32),10,0,10),e.addMany(n(48,60),10,8,10),e.addMany([60,61,62,63],10,0,11),e.addMany(n(32,48),10,9,12),e.addMany(i,12,0,12),e.add(127,12,0,12),e.addMany(n(28,32),12,0,12),e.addMany(n(32,48),12,9,12),e.addMany(n(48,64),12,0,11),e.addMany(n(64,127),12,12,13),e.addMany(n(64,127),10,12,13),e.addMany(n(64,127),9,12,13),e.addMany(i,13,13,13),e.addMany(r,13,13,13),e.add(127,13,0,13),e.addMany([27,156,24,26],13,14,0),e.add(c$,0,2,0),e.add(c$,8,5,8),e.add(c$,6,0,6),e.add(c$,11,0,11),e.add(c$,13,13,13),e}(),u$=class extends pq{constructor(e=l$){super(),this._transitions=e,this._parseStack={state:0,handlers:[],handlerPos:0,transition:0,chunkPos:0},this.initialState=0,this.currentState=this.initialState,this._params=new $Q,this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._printHandlerFb=(e,t,n)=>{},this._executeHandlerFb=e=>{},this._csiHandlerFb=(e,t)=>{},this._escHandlerFb=e=>{},this._errorHandlerFb=e=>e,this._printHandler=this._printHandlerFb,this._executeHandlers=Object.create(null),this._csiHandlers=Object.create(null),this._escHandlers=Object.create(null),this._register(uq(()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._escHandlers=Object.create(null)})),this._oscParser=this._register(new t$),this._dcsParser=this._register(new i$),this._errorHandler=this._errorHandlerFb,this.registerEscHandler({final:`\\`},()=>!0)}_identifier(e,t=[64,126]){let n=0;if(e.prefix){if(e.prefix.length>1)throw Error(`only one byte as prefix supported`);if(n=e.prefix.charCodeAt(0),n&&60>n||n>63)throw Error(`prefix must be in range 0x3c .. 0x3f`)}if(e.intermediates){if(e.intermediates.length>2)throw Error(`only two bytes as intermediates are supported`);for(let t=0;t<e.intermediates.length;++t){let r=e.intermediates.charCodeAt(t);if(32>r||r>47)throw Error(`intermediate must be in range 0x20 .. 0x2f`);n<<=8,n|=r}}if(e.final.length!==1)throw Error(`final must be a single byte`);let r=e.final.charCodeAt(0);if(t[0]>r||r>t[1])throw Error(`final must be in range ${t[0]} .. ${t[1]}`);return n<<=8,n|=r,n}identToString(e){let t=[];for(;e;)t.push(String.fromCharCode(e&255)),e>>=8;return t.reverse().join(``)}setPrintHandler(e){this._printHandler=e}clearPrintHandler(){this._printHandler=this._printHandlerFb}registerEscHandler(e,t){let n=this._identifier(e,[48,126]);this._escHandlers[n]===void 0&&(this._escHandlers[n]=[]);let r=this._escHandlers[n];return r.push(t),{dispose:()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)}}}clearEscHandler(e){this._escHandlers[this._identifier(e,[48,126])]&&delete this._escHandlers[this._identifier(e,[48,126])]}setEscHandlerFallback(e){this._escHandlerFb=e}setExecuteHandler(e,t){this._executeHandlers[e.charCodeAt(0)]=t}clearExecuteHandler(e){this._executeHandlers[e.charCodeAt(0)]&&delete this._executeHandlers[e.charCodeAt(0)]}setExecuteHandlerFallback(e){this._executeHandlerFb=e}registerCsiHandler(e,t){let n=this._identifier(e);this._csiHandlers[n]===void 0&&(this._csiHandlers[n]=[]);let r=this._csiHandlers[n];return r.push(t),{dispose:()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)}}}clearCsiHandler(e){this._csiHandlers[this._identifier(e)]&&delete this._csiHandlers[this._identifier(e)]}setCsiHandlerFallback(e){this._csiHandlerFb=e}registerDcsHandler(e,t){return this._dcsParser.registerHandler(this._identifier(e),t)}clearDcsHandler(e){this._dcsParser.clearHandler(this._identifier(e))}setDcsHandlerFallback(e){this._dcsParser.setHandlerFallback(e)}registerOscHandler(e,t){return this._oscParser.registerHandler(e,t)}clearOscHandler(e){this._oscParser.clearHandler(e)}setOscHandlerFallback(e){this._oscParser.setHandlerFallback(e)}setErrorHandler(e){this._errorHandler=e}clearErrorHandler(){this._errorHandler=this._errorHandlerFb}reset(){this.currentState=this.initialState,this._oscParser.reset(),this._dcsParser.reset(),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._parseStack.state!==0&&(this._parseStack.state=2,this._parseStack.handlers=[])}_preserveStack(e,t,n,r,i){this._parseStack.state=e,this._parseStack.handlers=t,this._parseStack.handlerPos=n,this._parseStack.transition=r,this._parseStack.chunkPos=i}parse(e,t,n){let r=0,i=0,a=0,o;if(this._parseStack.state)if(this._parseStack.state===2)this._parseStack.state=0,a=this._parseStack.chunkPos+1;else{if(n===void 0||this._parseStack.state===1)throw this._parseStack.state=1,Error(`improper continuation due to previous async handler, giving up parsing`);let t=this._parseStack.handlers,i=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(n===!1&&i>-1){for(;i>=0&&(o=t[i](this._params),o!==!0);i--)if(o instanceof Promise)return this._parseStack.handlerPos=i,o}this._parseStack.handlers=[];break;case 4:if(n===!1&&i>-1){for(;i>=0&&(o=t[i](),o!==!0);i--)if(o instanceof Promise)return this._parseStack.handlerPos=i,o}this._parseStack.handlers=[];break;case 6:if(r=e[this._parseStack.chunkPos],o=this._dcsParser.unhook(r!==24&&r!==26,n),o)return o;r===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break;case 5:if(r=e[this._parseStack.chunkPos],o=this._oscParser.end(r!==24&&r!==26,n),o)return o;r===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break}this._parseStack.state=0,a=this._parseStack.chunkPos+1,this.precedingJoinState=0,this.currentState=this._parseStack.transition&15}for(let n=a;n<t;++n){switch(r=e[n],i=this._transitions.table[this.currentState<<8|(r<160?r:c$)],i>>4){case 2:for(let i=n+1;;++i){if(i>=t||(r=e[i])<32||r>126&&r<c$){this._printHandler(e,n,i),n=i-1;break}if(++i>=t||(r=e[i])<32||r>126&&r<c$){this._printHandler(e,n,i),n=i-1;break}if(++i>=t||(r=e[i])<32||r>126&&r<c$){this._printHandler(e,n,i),n=i-1;break}if(++i>=t||(r=e[i])<32||r>126&&r<c$){this._printHandler(e,n,i),n=i-1;break}}break;case 3:this._executeHandlers[r]?this._executeHandlers[r]():this._executeHandlerFb(r),this.precedingJoinState=0;break;case 0:break;case 1:if(this._errorHandler({position:n,code:r,currentState:this.currentState,collect:this._collect,params:this._params,abort:!1}).abort)return;break;case 7:let a=this._csiHandlers[this._collect<<8|r],s=a?a.length-1:-1;for(;s>=0&&(o=a[s](this._params),o!==!0);s--)if(o instanceof Promise)return this._preserveStack(3,a,s,i,n),o;s<0&&this._csiHandlerFb(this._collect<<8|r,this._params),this.precedingJoinState=0;break;case 8:do switch(r){case 59:this._params.addParam(0);break;case 58:this._params.addSubParam(-1);break;default:this._params.addDigit(r-48)}while(++n<t&&(r=e[n])>47&&r<60);n--;break;case 9:this._collect<<=8,this._collect|=r;break;case 10:let c=this._escHandlers[this._collect<<8|r],l=c?c.length-1:-1;for(;l>=0&&(o=c[l](),o!==!0);l--)if(o instanceof Promise)return this._preserveStack(4,c,l,i,n),o;l<0&&this._escHandlerFb(this._collect<<8|r),this.precedingJoinState=0;break;case 11:this._params.reset(),this._params.addParam(0),this._collect=0;break;case 12:this._dcsParser.hook(this._collect<<8|r,this._params);break;case 13:for(let i=n+1;;++i)if(i>=t||(r=e[i])===24||r===26||r===27||r>127&&r<c$){this._dcsParser.put(e,n,i),n=i-1;break}break;case 14:if(o=this._dcsParser.unhook(r!==24&&r!==26),o)return this._preserveStack(6,[],0,i,n),o;r===27&&(i|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0;break;case 4:this._oscParser.start();break;case 5:for(let i=n+1;;i++)if(i>=t||(r=e[i])<32||r>127&&r<c$){this._oscParser.put(e,n,i),n=i-1;break}break;case 6:if(o=this._oscParser.end(r!==24&&r!==26),o)return this._preserveStack(5,[],0,i,n),o;r===27&&(i|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0;break}this.currentState=i&15}}},d$=/^([\da-f])\/([\da-f])\/([\da-f])$|^([\da-f]{2})\/([\da-f]{2})\/([\da-f]{2})$|^([\da-f]{3})\/([\da-f]{3})\/([\da-f]{3})$|^([\da-f]{4})\/([\da-f]{4})\/([\da-f]{4})$/,f$=/^[\da-f]+$/;function p$(e){if(!e)return;let t=e.toLowerCase();if(t.indexOf(`rgb:`)===0){t=t.slice(4);let e=d$.exec(t);if(e){let t=e[1]?15:e[4]?255:e[7]?4095:65535;return[Math.round(parseInt(e[1]||e[4]||e[7]||e[10],16)/t*255),Math.round(parseInt(e[2]||e[5]||e[8]||e[11],16)/t*255),Math.round(parseInt(e[3]||e[6]||e[9]||e[12],16)/t*255)]}}else if(t.indexOf(`#`)===0&&(t=t.slice(1),f$.exec(t)&&[3,6,9,12].includes(t.length))){let e=t.length/3,n=[0,0,0];for(let r=0;r<3;++r){let i=parseInt(t.slice(e*r,e*r+e),16);n[r]=e===1?i<<4:e===2?i:e===3?i>>4:i>>8}return n}}function m$(e,t){let n=e.toString(16),r=n.length<2?`0`+n:n;switch(t){case 4:return n[0];case 8:return r;case 12:return(r+r).slice(0,3);default:return r+r}}function h$(e,t=16){let[n,r,i]=e;return`rgb:${m$(n,t)}/${m$(r,t)}/${m$(i,t)}`}var g$={"(":0,")":1,"*":2,"+":3,"-":1,".":2},_$=131072,v$=10;function y$(e,t){if(e>24)return t.setWinLines||!1;switch(e){case 1:return!!t.restoreWin;case 2:return!!t.minimizeWin;case 3:return!!t.setWinPosition;case 4:return!!t.setWinSizePixels;case 5:return!!t.raiseWin;case 6:return!!t.lowerWin;case 7:return!!t.refreshWin;case 8:return!!t.setWinSizeChars;case 9:return!!t.maximizeWin;case 10:return!!t.fullscreenWin;case 11:return!!t.getWinState;case 13:return!!t.getWinPosition;case 14:return!!t.getWinSizePixels;case 15:return!!t.getScreenSizePixels;case 16:return!!t.getCellSizePixels;case 18:return!!t.getWinSizeChars;case 19:return!!t.getScreenSizeChars;case 20:return!!t.getIconTitle;case 21:return!!t.getWinTitle;case 22:return!!t.pushTitle;case 23:return!!t.popTitle;case 24:return!!t.setWinLines}return!1}var b$=5e3,x$=0,S$=class extends pq{constructor(e,t,n,r,i,a,o,s,c=new u$){super(),this._bufferService=e,this._charsetService=t,this._coreService=n,this._logService=r,this._optionsService=i,this._oscLinkService=a,this._coreMouseService=o,this._unicodeService=s,this._parser=c,this._parseBuffer=new Uint32Array(4096),this._stringDecoder=new iK,this._utf8Decoder=new aK,this._windowTitle=``,this._iconName=``,this._windowTitleStack=[],this._iconNameStack=[],this._curAttrData=dQ.clone(),this._eraseAttrDataInternal=dQ.clone(),this._onRequestBell=this._register(new Q),this.onRequestBell=this._onRequestBell.event,this._onRequestRefreshRows=this._register(new Q),this.onRequestRefreshRows=this._onRequestRefreshRows.event,this._onRequestReset=this._register(new Q),this.onRequestReset=this._onRequestReset.event,this._onRequestSendFocus=this._register(new Q),this.onRequestSendFocus=this._onRequestSendFocus.event,this._onRequestSyncScrollBar=this._register(new Q),this.onRequestSyncScrollBar=this._onRequestSyncScrollBar.event,this._onRequestWindowsOptionsReport=this._register(new Q),this.onRequestWindowsOptionsReport=this._onRequestWindowsOptionsReport.event,this._onA11yChar=this._register(new Q),this.onA11yChar=this._onA11yChar.event,this._onA11yTab=this._register(new Q),this.onA11yTab=this._onA11yTab.event,this._onCursorMove=this._register(new Q),this.onCursorMove=this._onCursorMove.event,this._onLineFeed=this._register(new Q),this.onLineFeed=this._onLineFeed.event,this._onScroll=this._register(new Q),this.onScroll=this._onScroll.event,this._onTitleChange=this._register(new Q),this.onTitleChange=this._onTitleChange.event,this._onColor=this._register(new Q),this.onColor=this._onColor.event,this._parseStack={paused:!1,cursorStartX:0,cursorStartY:0,decodedLength:0,position:0},this._specialColors=[256,257,258],this._register(this._parser),this._dirtyRowTracker=new C$(this._bufferService),this._activeBuffer=this._bufferService.buffer,this._register(this._bufferService.buffers.onBufferActivate(e=>this._activeBuffer=e.activeBuffer)),this._parser.setCsiHandlerFallback((e,t)=>{this._logService.debug(`Unknown CSI code: `,{identifier:this._parser.identToString(e),params:t.toArray()})}),this._parser.setEscHandlerFallback(e=>{this._logService.debug(`Unknown ESC code: `,{identifier:this._parser.identToString(e)})}),this._parser.setExecuteHandlerFallback(e=>{this._logService.debug(`Unknown EXECUTE code: `,{code:e})}),this._parser.setOscHandlerFallback((e,t,n)=>{this._logService.debug(`Unknown OSC code: `,{identifier:e,action:t,data:n})}),this._parser.setDcsHandlerFallback((e,t,n)=>{t===`HOOK`&&(n=n.toArray()),this._logService.debug(`Unknown DCS code: `,{identifier:this._parser.identToString(e),action:t,payload:n})}),this._parser.setPrintHandler((e,t,n)=>this.print(e,t,n)),this._parser.registerCsiHandler({final:`@`},e=>this.insertChars(e)),this._parser.registerCsiHandler({intermediates:` `,final:`@`},e=>this.scrollLeft(e)),this._parser.registerCsiHandler({final:`A`},e=>this.cursorUp(e)),this._parser.registerCsiHandler({intermediates:` `,final:`A`},e=>this.scrollRight(e)),this._parser.registerCsiHandler({final:`B`},e=>this.cursorDown(e)),this._parser.registerCsiHandler({final:`C`},e=>this.cursorForward(e)),this._parser.registerCsiHandler({final:`D`},e=>this.cursorBackward(e)),this._parser.registerCsiHandler({final:`E`},e=>this.cursorNextLine(e)),this._parser.registerCsiHandler({final:`F`},e=>this.cursorPrecedingLine(e)),this._parser.registerCsiHandler({final:`G`},e=>this.cursorCharAbsolute(e)),this._parser.registerCsiHandler({final:`H`},e=>this.cursorPosition(e)),this._parser.registerCsiHandler({final:`I`},e=>this.cursorForwardTab(e)),this._parser.registerCsiHandler({final:`J`},e=>this.eraseInDisplay(e,!1)),this._parser.registerCsiHandler({prefix:`?`,final:`J`},e=>this.eraseInDisplay(e,!0)),this._parser.registerCsiHandler({final:`K`},e=>this.eraseInLine(e,!1)),this._parser.registerCsiHandler({prefix:`?`,final:`K`},e=>this.eraseInLine(e,!0)),this._parser.registerCsiHandler({final:`L`},e=>this.insertLines(e)),this._parser.registerCsiHandler({final:`M`},e=>this.deleteLines(e)),this._parser.registerCsiHandler({final:`P`},e=>this.deleteChars(e)),this._parser.registerCsiHandler({final:`S`},e=>this.scrollUp(e)),this._parser.registerCsiHandler({final:`T`},e=>this.scrollDown(e)),this._parser.registerCsiHandler({final:`X`},e=>this.eraseChars(e)),this._parser.registerCsiHandler({final:`Z`},e=>this.cursorBackwardTab(e)),this._parser.registerCsiHandler({final:"`"},e=>this.charPosAbsolute(e)),this._parser.registerCsiHandler({final:`a`},e=>this.hPositionRelative(e)),this._parser.registerCsiHandler({final:`b`},e=>this.repeatPrecedingCharacter(e)),this._parser.registerCsiHandler({final:`c`},e=>this.sendDeviceAttributesPrimary(e)),this._parser.registerCsiHandler({prefix:`>`,final:`c`},e=>this.sendDeviceAttributesSecondary(e)),this._parser.registerCsiHandler({final:`d`},e=>this.linePosAbsolute(e)),this._parser.registerCsiHandler({final:`e`},e=>this.vPositionRelative(e)),this._parser.registerCsiHandler({final:`f`},e=>this.hVPosition(e)),this._parser.registerCsiHandler({final:`g`},e=>this.tabClear(e)),this._parser.registerCsiHandler({final:`h`},e=>this.setMode(e)),this._parser.registerCsiHandler({prefix:`?`,final:`h`},e=>this.setModePrivate(e)),this._parser.registerCsiHandler({final:`l`},e=>this.resetMode(e)),this._parser.registerCsiHandler({prefix:`?`,final:`l`},e=>this.resetModePrivate(e)),this._parser.registerCsiHandler({final:`m`},e=>this.charAttributes(e)),this._parser.registerCsiHandler({final:`n`},e=>this.deviceStatus(e)),this._parser.registerCsiHandler({prefix:`?`,final:`n`},e=>this.deviceStatusPrivate(e)),this._parser.registerCsiHandler({intermediates:`!`,final:`p`},e=>this.softReset(e)),this._parser.registerCsiHandler({intermediates:` `,final:`q`},e=>this.setCursorStyle(e)),this._parser.registerCsiHandler({final:`r`},e=>this.setScrollRegion(e)),this._parser.registerCsiHandler({final:`s`},e=>this.saveCursor(e)),this._parser.registerCsiHandler({final:`t`},e=>this.windowOptions(e)),this._parser.registerCsiHandler({final:`u`},e=>this.restoreCursor(e)),this._parser.registerCsiHandler({intermediates:`'`,final:`}`},e=>this.insertColumns(e)),this._parser.registerCsiHandler({intermediates:`'`,final:`~`},e=>this.deleteColumns(e)),this._parser.registerCsiHandler({intermediates:`"`,final:`q`},e=>this.selectProtected(e)),this._parser.registerCsiHandler({intermediates:`$`,final:`p`},e=>this.requestMode(e,!0)),this._parser.registerCsiHandler({prefix:`?`,intermediates:`$`,final:`p`},e=>this.requestMode(e,!1)),this._parser.setExecuteHandler($.BEL,()=>this.bell()),this._parser.setExecuteHandler($.LF,()=>this.lineFeed()),this._parser.setExecuteHandler($.VT,()=>this.lineFeed()),this._parser.setExecuteHandler($.FF,()=>this.lineFeed()),this._parser.setExecuteHandler($.CR,()=>this.carriageReturn()),this._parser.setExecuteHandler($.BS,()=>this.backspace()),this._parser.setExecuteHandler($.HT,()=>this.tab()),this._parser.setExecuteHandler($.SO,()=>this.shiftOut()),this._parser.setExecuteHandler($.SI,()=>this.shiftIn()),this._parser.setExecuteHandler(fX.IND,()=>this.index()),this._parser.setExecuteHandler(fX.NEL,()=>this.nextLine()),this._parser.setExecuteHandler(fX.HTS,()=>this.tabSet()),this._parser.registerOscHandler(0,new n$(e=>(this.setTitle(e),this.setIconName(e),!0))),this._parser.registerOscHandler(1,new n$(e=>this.setIconName(e))),this._parser.registerOscHandler(2,new n$(e=>this.setTitle(e))),this._parser.registerOscHandler(4,new n$(e=>this.setOrReportIndexedColor(e))),this._parser.registerOscHandler(8,new n$(e=>this.setHyperlink(e))),this._parser.registerOscHandler(10,new n$(e=>this.setOrReportFgColor(e))),this._parser.registerOscHandler(11,new n$(e=>this.setOrReportBgColor(e))),this._parser.registerOscHandler(12,new n$(e=>this.setOrReportCursorColor(e))),this._parser.registerOscHandler(104,new n$(e=>this.restoreIndexedColor(e))),this._parser.registerOscHandler(110,new n$(e=>this.restoreFgColor(e))),this._parser.registerOscHandler(111,new n$(e=>this.restoreBgColor(e))),this._parser.registerOscHandler(112,new n$(e=>this.restoreCursorColor(e))),this._parser.registerEscHandler({final:`7`},()=>this.saveCursor()),this._parser.registerEscHandler({final:`8`},()=>this.restoreCursor()),this._parser.registerEscHandler({final:`D`},()=>this.index()),this._parser.registerEscHandler({final:`E`},()=>this.nextLine()),this._parser.registerEscHandler({final:`H`},()=>this.tabSet()),this._parser.registerEscHandler({final:`M`},()=>this.reverseIndex()),this._parser.registerEscHandler({final:`=`},()=>this.keypadApplicationMode()),this._parser.registerEscHandler({final:`>`},()=>this.keypadNumericMode()),this._parser.registerEscHandler({final:`c`},()=>this.fullReset()),this._parser.registerEscHandler({final:`n`},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:`o`},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:`|`},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:`}`},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:`~`},()=>this.setgLevel(1)),this._parser.registerEscHandler({intermediates:`%`,final:`@`},()=>this.selectDefaultCharset()),this._parser.registerEscHandler({intermediates:`%`,final:`G`},()=>this.selectDefaultCharset());for(let e in SQ)this._parser.registerEscHandler({intermediates:`(`,final:e},()=>this.selectCharset(`(`+e)),this._parser.registerEscHandler({intermediates:`)`,final:e},()=>this.selectCharset(`)`+e)),this._parser.registerEscHandler({intermediates:`*`,final:e},()=>this.selectCharset(`*`+e)),this._parser.registerEscHandler({intermediates:`+`,final:e},()=>this.selectCharset(`+`+e)),this._parser.registerEscHandler({intermediates:`-`,final:e},()=>this.selectCharset(`-`+e)),this._parser.registerEscHandler({intermediates:`.`,final:e},()=>this.selectCharset(`.`+e)),this._parser.registerEscHandler({intermediates:`/`,final:e},()=>this.selectCharset(`/`+e));this._parser.registerEscHandler({intermediates:`#`,final:`8`},()=>this.screenAlignmentPattern()),this._parser.setErrorHandler(e=>(this._logService.error(`Parsing error: `,e),e)),this._parser.registerDcsHandler({intermediates:`$`,final:`q`},new o$((e,t)=>this.requestStatusString(e,t)))}getAttrData(){return this._curAttrData}_preserveStack(e,t,n,r){this._parseStack.paused=!0,this._parseStack.cursorStartX=e,this._parseStack.cursorStartY=t,this._parseStack.decodedLength=n,this._parseStack.position=r}_logSlowResolvingAsync(e){this._logService.logLevel<=3&&Promise.race([e,new Promise((e,t)=>setTimeout(()=>t(`#SLOW_TIMEOUT`),b$))]).catch(e=>{if(e!==`#SLOW_TIMEOUT`)throw e;console.warn(`async parser handler taking longer than ${b$} ms`)})}_getCurrentLinkId(){return this._curAttrData.extended.urlId}parse(e,t){let n,r=this._activeBuffer.x,i=this._activeBuffer.y,a=0,o=this._parseStack.paused;if(o){if(n=this._parser.parse(this._parseBuffer,this._parseStack.decodedLength,t))return this._logSlowResolvingAsync(n),n;r=this._parseStack.cursorStartX,i=this._parseStack.cursorStartY,this._parseStack.paused=!1,e.length>_$&&(a=this._parseStack.position+_$)}if(this._logService.logLevel<=1&&this._logService.debug(`parsing data ${typeof e==`string`?` "${e}"`:` "${Array.prototype.map.call(e,e=>String.fromCharCode(e)).join(``)}"`}`),this._logService.logLevel===0&&this._logService.trace(`parsing data (codes)`,typeof e==`string`?e.split(``).map(e=>e.charCodeAt(0)):e),this._parseBuffer.length<e.length&&this._parseBuffer.length<_$&&(this._parseBuffer=new Uint32Array(Math.min(e.length,_$))),o||this._dirtyRowTracker.clearRange(),e.length>_$)for(let t=a;t<e.length;t+=_$){let a=t+_$<e.length?t+_$:e.length,o=typeof e==`string`?this._stringDecoder.decode(e.substring(t,a),this._parseBuffer):this._utf8Decoder.decode(e.subarray(t,a),this._parseBuffer);if(n=this._parser.parse(this._parseBuffer,o))return this._preserveStack(r,i,o,t),this._logSlowResolvingAsync(n),n}else if(!o){let t=typeof e==`string`?this._stringDecoder.decode(e,this._parseBuffer):this._utf8Decoder.decode(e,this._parseBuffer);if(n=this._parser.parse(this._parseBuffer,t))return this._preserveStack(r,i,t,0),this._logSlowResolvingAsync(n),n}(this._activeBuffer.x!==r||this._activeBuffer.y!==i)&&this._onCursorMove.fire();let s=this._dirtyRowTracker.end+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp),c=this._dirtyRowTracker.start+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp);c<this._bufferService.rows&&this._onRequestRefreshRows.fire({start:Math.min(c,this._bufferService.rows-1),end:Math.min(s,this._bufferService.rows-1)})}print(e,t,n){let r,i,a=this._charsetService.charset,o=this._optionsService.rawOptions.screenReaderMode,s=this._bufferService.cols,c=this._coreService.decPrivateModes.wraparound,l=this._coreService.modes.insertMode,u=this._curAttrData,d=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._activeBuffer.x&&n-t>0&&d.getWidth(this._activeBuffer.x-1)===2&&d.setCellFromCodepoint(this._activeBuffer.x-1,0,1,u);let f=this._parser.precedingJoinState;for(let p=t;p<n;++p){if(r=e[p],r<127&&a){let e=a[String.fromCharCode(r)];e&&(r=e.charCodeAt(0))}let t=this._unicodeService.charProperties(r,f);i=JQ.extractWidth(t);let n=JQ.extractShouldJoin(t),m=n?JQ.extractWidth(f):0;if(f=t,o&&this._onA11yChar.fire(nK(r)),this._getCurrentLinkId()&&this._oscLinkService.addLineToLink(this._getCurrentLinkId(),this._activeBuffer.ybase+this._activeBuffer.y),this._activeBuffer.x+i-m>s){if(c){let e=d,t=this._activeBuffer.x-m;for(this._activeBuffer.x=m,this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData(),!0)):(this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!0),d=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y),m>0&&d instanceof mQ&&d.copyCellsFrom(e,t,0,m,!1);t<s;)e.setCellFromCodepoint(t++,0,1,u)}else if(this._activeBuffer.x=s-1,i===2)continue}if(n&&this._activeBuffer.x){let e=d.getWidth(this._activeBuffer.x-1)?1:2;d.addCodepointToCell(this._activeBuffer.x-e,r,i);for(let e=i-m;--e>=0;)d.setCellFromCodepoint(this._activeBuffer.x++,0,0,u);continue}if(l&&(d.insertCells(this._activeBuffer.x,i-m,this._activeBuffer.getNullCell(u)),d.getWidth(s-1)===2&&d.setCellFromCodepoint(s-1,0,1,u)),d.setCellFromCodepoint(this._activeBuffer.x++,r,i,u),i>0)for(;--i;)d.setCellFromCodepoint(this._activeBuffer.x++,0,0,u)}this._parser.precedingJoinState=f,this._activeBuffer.x<s&&n-t>0&&d.getWidth(this._activeBuffer.x)===0&&!d.hasContent(this._activeBuffer.x)&&d.setCellFromCodepoint(this._activeBuffer.x,0,1,u),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}registerCsiHandler(e,t){return e.final===`t`&&!e.prefix&&!e.intermediates?this._parser.registerCsiHandler(e,e=>!y$(e.params[0],this._optionsService.rawOptions.windowOptions)||t(e)):this._parser.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._parser.registerDcsHandler(e,new o$(t))}registerEscHandler(e,t){return this._parser.registerEscHandler(e,t)}registerOscHandler(e,t){return this._parser.registerOscHandler(e,new n$(t))}bell(){return this._onRequestBell.fire(),!0}lineFeed(){return this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._optionsService.rawOptions.convertEol&&(this._activeBuffer.x=0),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows?this._activeBuffer.y=this._bufferService.rows-1:this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.x>=this._bufferService.cols&&this._activeBuffer.x--,this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._onLineFeed.fire(),!0}carriageReturn(){return this._activeBuffer.x=0,!0}backspace(){if(!this._coreService.decPrivateModes.reverseWraparound)return this._restrictCursor(),this._activeBuffer.x>0&&this._activeBuffer.x--,!0;if(this._restrictCursor(this._bufferService.cols),this._activeBuffer.x>0)this._activeBuffer.x--;else if(this._activeBuffer.x===0&&this._activeBuffer.y>this._activeBuffer.scrollTop&&this._activeBuffer.y<=this._activeBuffer.scrollBottom&&this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y)?.isWrapped){this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.y--,this._activeBuffer.x=this._bufferService.cols-1;let e=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);e.hasWidth(this._activeBuffer.x)&&!e.hasContent(this._activeBuffer.x)&&this._activeBuffer.x--}return this._restrictCursor(),!0}tab(){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let e=this._activeBuffer.x;return this._activeBuffer.x=this._activeBuffer.nextStop(),this._optionsService.rawOptions.screenReaderMode&&this._onA11yTab.fire(this._activeBuffer.x-e),!0}shiftOut(){return this._charsetService.setgLevel(1),!0}shiftIn(){return this._charsetService.setgLevel(0),!0}_restrictCursor(e=this._bufferService.cols-1){this._activeBuffer.x=Math.min(e,Math.max(0,this._activeBuffer.x)),this._activeBuffer.y=this._coreService.decPrivateModes.origin?Math.min(this._activeBuffer.scrollBottom,Math.max(this._activeBuffer.scrollTop,this._activeBuffer.y)):Math.min(this._bufferService.rows-1,Math.max(0,this._activeBuffer.y)),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_setCursor(e,t){this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._coreService.decPrivateModes.origin?(this._activeBuffer.x=e,this._activeBuffer.y=this._activeBuffer.scrollTop+t):(this._activeBuffer.x=e,this._activeBuffer.y=t),this._restrictCursor(),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_moveCursor(e,t){this._restrictCursor(),this._setCursor(this._activeBuffer.x+e,this._activeBuffer.y+t)}cursorUp(e){let t=this._activeBuffer.y-this._activeBuffer.scrollTop;return t>=0?this._moveCursor(0,-Math.min(t,e.params[0]||1)):this._moveCursor(0,-(e.params[0]||1)),!0}cursorDown(e){let t=this._activeBuffer.scrollBottom-this._activeBuffer.y;return t>=0?this._moveCursor(0,Math.min(t,e.params[0]||1)):this._moveCursor(0,e.params[0]||1),!0}cursorForward(e){return this._moveCursor(e.params[0]||1,0),!0}cursorBackward(e){return this._moveCursor(-(e.params[0]||1),0),!0}cursorNextLine(e){return this.cursorDown(e),this._activeBuffer.x=0,!0}cursorPrecedingLine(e){return this.cursorUp(e),this._activeBuffer.x=0,!0}cursorCharAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}cursorPosition(e){return this._setCursor(e.length>=2?(e.params[1]||1)-1:0,(e.params[0]||1)-1),!0}charPosAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}hPositionRelative(e){return this._moveCursor(e.params[0]||1,0),!0}linePosAbsolute(e){return this._setCursor(this._activeBuffer.x,(e.params[0]||1)-1),!0}vPositionRelative(e){return this._moveCursor(0,e.params[0]||1),!0}hVPosition(e){return this.cursorPosition(e),!0}tabClear(e){let t=e.params[0];return t===0?delete this._activeBuffer.tabs[this._activeBuffer.x]:t===3&&(this._activeBuffer.tabs={}),!0}cursorForwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.nextStop();return!0}cursorBackwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.prevStop();return!0}selectProtected(e){let t=e.params[0];return t===1&&(this._curAttrData.bg|=536870912),(t===2||t===0)&&(this._curAttrData.bg&=-536870913),!0}_eraseInBufferLine(e,t,n,r=!1,i=!1){let a=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);a.replaceCells(t,n,this._activeBuffer.getNullCell(this._eraseAttrData()),i),r&&(a.isWrapped=!1)}_resetBufferLine(e,t=!1){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n&&(n.fill(this._activeBuffer.getNullCell(this._eraseAttrData()),t),this._bufferService.buffer.clearMarkers(this._activeBuffer.ybase+e),n.isWrapped=!1)}eraseInDisplay(e,t=!1){this._restrictCursor(this._bufferService.cols);let n;switch(e.params[0]){case 0:for(n=this._activeBuffer.y,this._dirtyRowTracker.markDirty(n),this._eraseInBufferLine(n++,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);n<this._bufferService.rows;n++)this._resetBufferLine(n,t);this._dirtyRowTracker.markDirty(n);break;case 1:for(n=this._activeBuffer.y,this._dirtyRowTracker.markDirty(n),this._eraseInBufferLine(n,0,this._activeBuffer.x+1,!0,t),this._activeBuffer.x+1>=this._bufferService.cols&&(this._activeBuffer.lines.get(n+1).isWrapped=!1);n--;)this._resetBufferLine(n,t);this._dirtyRowTracker.markDirty(0);break;case 2:if(this._optionsService.rawOptions.scrollOnEraseInDisplay){for(n=this._bufferService.rows,this._dirtyRowTracker.markRangeDirty(0,n-1);n--&&!this._activeBuffer.lines.get(this._activeBuffer.ybase+n)?.getTrimmedLength(););for(;n>=0;n--)this._bufferService.scroll(this._eraseAttrData())}else{for(n=this._bufferService.rows,this._dirtyRowTracker.markDirty(n-1);n--;)this._resetBufferLine(n,t);this._dirtyRowTracker.markDirty(0)}break;case 3:let e=this._activeBuffer.lines.length-this._bufferService.rows;e>0&&(this._activeBuffer.lines.trimStart(e),this._activeBuffer.ybase=Math.max(this._activeBuffer.ybase-e,0),this._activeBuffer.ydisp=Math.max(this._activeBuffer.ydisp-e,0),this._onScroll.fire(0));break}return!0}eraseInLine(e,t=!1){switch(this._restrictCursor(this._bufferService.cols),e.params[0]){case 0:this._eraseInBufferLine(this._activeBuffer.y,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);break;case 1:this._eraseInBufferLine(this._activeBuffer.y,0,this._activeBuffer.x+1,!1,t);break;case 2:this._eraseInBufferLine(this._activeBuffer.y,0,this._bufferService.cols,!0,t);break}return this._dirtyRowTracker.markDirty(this._activeBuffer.y),!0}insertLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let n=this._activeBuffer.ybase+this._activeBuffer.y,r=this._bufferService.rows-1-this._activeBuffer.scrollBottom,i=this._bufferService.rows-1+this._activeBuffer.ybase-r+1;for(;t--;)this._activeBuffer.lines.splice(i-1,1),this._activeBuffer.lines.splice(n,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}deleteLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let n=this._activeBuffer.ybase+this._activeBuffer.y,r;for(r=this._bufferService.rows-1-this._activeBuffer.scrollBottom,r=this._bufferService.rows-1+this._activeBuffer.ybase-r;t--;)this._activeBuffer.lines.splice(n,1),this._activeBuffer.lines.splice(r,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}insertChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.insertCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}deleteChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.deleteCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}scrollUp(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollDown(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,0,this._activeBuffer.getBlankLine(dQ));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollLeft(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.deleteCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollRight(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.insertCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}insertColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.insertCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}deleteColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.deleteCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}eraseChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.replaceCells(this._activeBuffer.x,this._activeBuffer.x+(e.params[0]||1),this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}repeatPrecedingCharacter(e){let t=this._parser.precedingJoinState;if(!t)return!0;let n=e.params[0]||1,r=JQ.extractWidth(t),i=this._activeBuffer.x-r,a=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).getString(i),o=new Uint32Array(a.length*n),s=0;for(let e=0;e<a.length;){let t=a.codePointAt(e)||0;o[s++]=t,e+=t>65535?2:1}let c=s;for(let e=1;e<n;++e)o.copyWithin(c,0,s),c+=s;return this.print(o,0,c),!0}sendDeviceAttributesPrimary(e){return e.params[0]>0||(this._is(`xterm`)||this._is(`rxvt-unicode`)||this._is(`screen`)?this._coreService.triggerDataEvent($.ESC+`[?1;2c`):this._is(`linux`)&&this._coreService.triggerDataEvent($.ESC+`[?6c`)),!0}sendDeviceAttributesSecondary(e){return e.params[0]>0||(this._is(`xterm`)?this._coreService.triggerDataEvent($.ESC+`[>0;276;0c`):this._is(`rxvt-unicode`)?this._coreService.triggerDataEvent($.ESC+`[>85;95;0c`):this._is(`linux`)?this._coreService.triggerDataEvent(e.params[0]+`c`):this._is(`screen`)&&this._coreService.triggerDataEvent($.ESC+`[>83;40003;0c`)),!0}_is(e){return(this._optionsService.rawOptions.termName+``).indexOf(e)===0}setMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!0;break;case 20:this._optionsService.options.convertEol=!0;break}return!0}setModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!0;break;case 2:this._charsetService.setgCharset(0,CQ),this._charsetService.setgCharset(1,CQ),this._charsetService.setgCharset(2,CQ),this._charsetService.setgCharset(3,CQ);break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(132,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!0,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!0;break;case 12:this._optionsService.options.cursorBlink=!0;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!0;break;case 66:this._logService.debug(`Serial port requested application keypad.`),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire();break;case 9:this._coreMouseService.activeProtocol=`X10`;break;case 1e3:this._coreMouseService.activeProtocol=`VT200`;break;case 1002:this._coreMouseService.activeProtocol=`DRAG`;break;case 1003:this._coreMouseService.activeProtocol=`ANY`;break;case 1004:this._coreService.decPrivateModes.sendFocus=!0,this._onRequestSendFocus.fire();break;case 1005:this._logService.debug(`DECSET 1005 not supported (see #2507)`);break;case 1006:this._coreMouseService.activeEncoding=`SGR`;break;case 1015:this._logService.debug(`DECSET 1015 not supported (see #2507)`);break;case 1016:this._coreMouseService.activeEncoding=`SGR_PIXELS`;break;case 25:this._coreService.isCursorHidden=!1;break;case 1048:this.saveCursor();break;case 1049:this.saveCursor();case 47:case 1047:this._bufferService.buffers.activateAltBuffer(this._eraseAttrData()),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!0;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!0;break}return!0}resetMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!1;break;case 20:this._optionsService.options.convertEol=!1;break}return!0}resetModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!1;break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(80,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!1,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!1;break;case 12:this._optionsService.options.cursorBlink=!1;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!1;break;case 66:this._logService.debug(`Switching back to normal keypad.`),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire();break;case 9:case 1e3:case 1002:case 1003:this._coreMouseService.activeProtocol=`NONE`;break;case 1004:this._coreService.decPrivateModes.sendFocus=!1;break;case 1005:this._logService.debug(`DECRST 1005 not supported (see #2507)`);break;case 1006:this._coreMouseService.activeEncoding=`DEFAULT`;break;case 1015:this._logService.debug(`DECRST 1015 not supported (see #2507)`);break;case 1016:this._coreMouseService.activeEncoding=`DEFAULT`;break;case 25:this._coreService.isCursorHidden=!0;break;case 1048:this.restoreCursor();break;case 1049:case 47:case 1047:this._bufferService.buffers.activateNormalBuffer(),e.params[t]===1049&&this.restoreCursor(),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!1;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!1,this._onRequestRefreshRows.fire(void 0);break}return!0}requestMode(e,t){let n;(e=>(e[e.NOT_RECOGNIZED=0]=`NOT_RECOGNIZED`,e[e.SET=1]=`SET`,e[e.RESET=2]=`RESET`,e[e.PERMANENTLY_SET=3]=`PERMANENTLY_SET`,e[e.PERMANENTLY_RESET=4]=`PERMANENTLY_RESET`))(n||={});let r=this._coreService.decPrivateModes,{activeProtocol:i,activeEncoding:a}=this._coreMouseService,o=this._coreService,{buffers:s,cols:c}=this._bufferService,{active:l,alt:u}=s,d=this._optionsService.rawOptions,f=(e,n)=>(o.triggerDataEvent(`${$.ESC}[${t?``:`?`}${e};${n}$y`),!0),p=e=>e?1:2,m=e.params[0];return t?m===2?f(m,4):m===4?f(m,p(o.modes.insertMode)):m===12?f(m,3):m===20?f(m,p(d.convertEol)):f(m,0):m===1?f(m,p(r.applicationCursorKeys)):m===3?f(m,d.windowOptions.setWinLines?c===80?2:+(c===132):0):m===6?f(m,p(r.origin)):m===7?f(m,p(r.wraparound)):m===8?f(m,3):m===9?f(m,p(i===`X10`)):m===12?f(m,p(d.cursorBlink)):m===25?f(m,p(!o.isCursorHidden)):m===45?f(m,p(r.reverseWraparound)):m===66?f(m,p(r.applicationKeypad)):m===67?f(m,4):m===1e3?f(m,p(i===`VT200`)):m===1002?f(m,p(i===`DRAG`)):m===1003?f(m,p(i===`ANY`)):m===1004?f(m,p(r.sendFocus)):m===1005?f(m,4):m===1006?f(m,p(a===`SGR`)):m===1015?f(m,4):m===1016?f(m,p(a===`SGR_PIXELS`)):m===1048?f(m,1):m===47||m===1047||m===1049?f(m,p(l===u)):m===2004?f(m,p(r.bracketedPasteMode)):m===2026?f(m,p(r.synchronizedOutput)):f(m,0)}_updateAttrColor(e,t,n,r,i){return t===2?(e|=50331648,e&=-16777216,e|=cK.fromColorRGB([n,r,i])):t===5&&(e&=-50331904,e|=33554432|n&255),e}_extractColor(e,t,n){let r=[0,0,-1,0,0,0],i=0,a=0;do{if(r[a+i]=e.params[t+a],e.hasSubParams(t+a)){let n=e.getSubParams(t+a),o=0;do r[1]===5&&(i=1),r[a+o+1+i]=n[o];while(++o<n.length&&o+a+1+i<r.length);break}if(r[1]===5&&a+i>=2||r[1]===2&&a+i>=5)break;r[1]&&(i=1)}while(++a+t<e.length&&a+i<r.length);for(let e=2;e<r.length;++e)r[e]===-1&&(r[e]=0);switch(r[0]){case 38:n.fg=this._updateAttrColor(n.fg,r[1],r[3],r[4],r[5]);break;case 48:n.bg=this._updateAttrColor(n.bg,r[1],r[3],r[4],r[5]);break;case 58:n.extended=n.extended.clone(),n.extended.underlineColor=this._updateAttrColor(n.extended.underlineColor,r[1],r[3],r[4],r[5])}return a}_processUnderline(e,t){t.extended=t.extended.clone(),(!~e||e>5)&&(e=1),t.extended.underlineStyle=e,t.fg|=268435456,e===0&&(t.fg&=-268435457),t.updateExtended()}_processSGR0(e){e.fg=dQ.fg,e.bg=dQ.bg,e.extended=e.extended.clone(),e.extended.underlineStyle=0,e.extended.underlineColor&=-67108864,e.updateExtended()}charAttributes(e){if(e.length===1&&e.params[0]===0)return this._processSGR0(this._curAttrData),!0;let t=e.length,n,r=this._curAttrData;for(let i=0;i<t;i++)n=e.params[i],n>=30&&n<=37?(r.fg&=-50331904,r.fg|=16777216|n-30):n>=40&&n<=47?(r.bg&=-50331904,r.bg|=16777216|n-40):n>=90&&n<=97?(r.fg&=-50331904,r.fg|=n-90|16777224):n>=100&&n<=107?(r.bg&=-50331904,r.bg|=n-100|16777224):n===0?this._processSGR0(r):n===1?r.fg|=134217728:n===3?r.bg|=67108864:n===4?(r.fg|=268435456,this._processUnderline(e.hasSubParams(i)?e.getSubParams(i)[0]:1,r)):n===5?r.fg|=536870912:n===7?r.fg|=67108864:n===8?r.fg|=1073741824:n===9?r.fg|=2147483648:n===2?r.bg|=134217728:n===21?this._processUnderline(2,r):n===22?(r.fg&=-134217729,r.bg&=-134217729):n===23?r.bg&=-67108865:n===24?(r.fg&=-268435457,this._processUnderline(0,r)):n===25?r.fg&=-536870913:n===27?r.fg&=-67108865:n===28?r.fg&=-1073741825:n===29?r.fg&=2147483647:n===39?(r.fg&=-67108864,r.fg|=dQ.fg&16777215):n===49?(r.bg&=-67108864,r.bg|=dQ.bg&16777215):n===38||n===48||n===58?i+=this._extractColor(e,i,r):n===53?r.bg|=1073741824:n===55?r.bg&=-1073741825:n===59?(r.extended=r.extended.clone(),r.extended.underlineColor=-1,r.updateExtended()):n===100?(r.fg&=-67108864,r.fg|=dQ.fg&16777215,r.bg&=-67108864,r.bg|=dQ.bg&16777215):this._logService.debug(`Unknown SGR attribute: %d.`,n);return!0}deviceStatus(e){switch(e.params[0]){case 5:this._coreService.triggerDataEvent(`${$.ESC}[0n`);break;case 6:let e=this._activeBuffer.y+1,t=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${$.ESC}[${e};${t}R`);break}return!0}deviceStatusPrivate(e){switch(e.params[0]){case 6:let e=this._activeBuffer.y+1,t=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${$.ESC}[?${e};${t}R`);break;case 15:break;case 25:break;case 26:break;case 53:break}return!0}softReset(e){return this._coreService.isCursorHidden=!1,this._onRequestSyncScrollBar.fire(),this._activeBuffer.scrollTop=0,this._activeBuffer.scrollBottom=this._bufferService.rows-1,this._curAttrData=dQ.clone(),this._coreService.reset(),this._charsetService.reset(),this._activeBuffer.savedX=0,this._activeBuffer.savedY=this._activeBuffer.ybase,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,this._coreService.decPrivateModes.origin=!1,!0}setCursorStyle(e){let t=e.length===0?1:e.params[0];if(t===0)this._coreService.decPrivateModes.cursorStyle=void 0,this._coreService.decPrivateModes.cursorBlink=void 0;else{switch(t){case 1:case 2:this._coreService.decPrivateModes.cursorStyle=`block`;break;case 3:case 4:this._coreService.decPrivateModes.cursorStyle=`underline`;break;case 5:case 6:this._coreService.decPrivateModes.cursorStyle=`bar`;break}let e=t%2==1;this._coreService.decPrivateModes.cursorBlink=e}return!0}setScrollRegion(e){let t=e.params[0]||1,n;return(e.length<2||(n=e.params[1])>this._bufferService.rows||n===0)&&(n=this._bufferService.rows),n>t&&(this._activeBuffer.scrollTop=t-1,this._activeBuffer.scrollBottom=n-1,this._setCursor(0,0)),!0}windowOptions(e){if(!y$(e.params[0],this._optionsService.rawOptions.windowOptions))return!0;let t=e.length>1?e.params[1]:0;switch(e.params[0]){case 14:t!==2&&this._onRequestWindowsOptionsReport.fire(0);break;case 16:this._onRequestWindowsOptionsReport.fire(1);break;case 18:this._bufferService&&this._coreService.triggerDataEvent(`${$.ESC}[8;${this._bufferService.rows};${this._bufferService.cols}t`);break;case 22:(t===0||t===2)&&(this._windowTitleStack.push(this._windowTitle),this._windowTitleStack.length>v$&&this._windowTitleStack.shift()),(t===0||t===1)&&(this._iconNameStack.push(this._iconName),this._iconNameStack.length>v$&&this._iconNameStack.shift());break;case 23:(t===0||t===2)&&this._windowTitleStack.length&&this.setTitle(this._windowTitleStack.pop()),(t===0||t===1)&&this._iconNameStack.length&&this.setIconName(this._iconNameStack.pop());break}return!0}saveCursor(e){return this._activeBuffer.savedX=this._activeBuffer.x,this._activeBuffer.savedY=this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,!0}restoreCursor(e){return this._activeBuffer.x=this._activeBuffer.savedX||0,this._activeBuffer.y=Math.max(this._activeBuffer.savedY-this._activeBuffer.ybase,0),this._curAttrData.fg=this._activeBuffer.savedCurAttrData.fg,this._curAttrData.bg=this._activeBuffer.savedCurAttrData.bg,this._charsetService.charset=this._savedCharset,this._activeBuffer.savedCharset&&(this._charsetService.charset=this._activeBuffer.savedCharset),this._restrictCursor(),!0}setTitle(e){return this._windowTitle=e,this._onTitleChange.fire(e),!0}setIconName(e){return this._iconName=e,!0}setOrReportIndexedColor(e){let t=[],n=e.split(`;`);for(;n.length>1;){let e=n.shift(),r=n.shift();if(/^\d+$/.exec(e)){let n=parseInt(e);if(w$(n))if(r===`?`)t.push({type:0,index:n});else{let e=p$(r);e&&t.push({type:1,index:n,color:e})}}}return t.length&&this._onColor.fire(t),!0}setHyperlink(e){let t=e.indexOf(`;`);if(t===-1)return!0;let n=e.slice(0,t).trim(),r=e.slice(t+1);return r?this._createHyperlink(n,r):!n.trim()&&this._finishHyperlink()}_createHyperlink(e,t){this._getCurrentLinkId()&&this._finishHyperlink();let n=e.split(`:`),r,i=n.findIndex(e=>e.startsWith(`id=`));return i!==-1&&(r=n[i].slice(3)||void 0),this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=this._oscLinkService.registerLink({id:r,uri:t}),this._curAttrData.updateExtended(),!0}_finishHyperlink(){return this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=0,this._curAttrData.updateExtended(),!0}_setOrReportSpecialColor(e,t){let n=e.split(`;`);for(let e=0;e<n.length&&!(t>=this._specialColors.length);++e,++t)if(n[e]===`?`)this._onColor.fire([{type:0,index:this._specialColors[t]}]);else{let r=p$(n[e]);r&&this._onColor.fire([{type:1,index:this._specialColors[t],color:r}])}return!0}setOrReportFgColor(e){return this._setOrReportSpecialColor(e,0)}setOrReportBgColor(e){return this._setOrReportSpecialColor(e,1)}setOrReportCursorColor(e){return this._setOrReportSpecialColor(e,2)}restoreIndexedColor(e){if(!e)return this._onColor.fire([{type:2}]),!0;let t=[],n=e.split(`;`);for(let e=0;e<n.length;++e)if(/^\d+$/.exec(n[e])){let r=parseInt(n[e]);w$(r)&&t.push({type:2,index:r})}return t.length&&this._onColor.fire(t),!0}restoreFgColor(e){return this._onColor.fire([{type:2,index:256}]),!0}restoreBgColor(e){return this._onColor.fire([{type:2,index:257}]),!0}restoreCursorColor(e){return this._onColor.fire([{type:2,index:258}]),!0}nextLine(){return this._activeBuffer.x=0,this.index(),!0}keypadApplicationMode(){return this._logService.debug(`Serial port requested application keypad.`),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire(),!0}keypadNumericMode(){return this._logService.debug(`Switching back to normal keypad.`),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire(),!0}selectDefaultCharset(){return this._charsetService.setgLevel(0),this._charsetService.setgCharset(0,CQ),!0}selectCharset(e){return e.length===2?(e[0]===`/`||this._charsetService.setgCharset(g$[e[0]],SQ[e[1]]||CQ),!0):(this.selectDefaultCharset(),!0)}index(){return this._restrictCursor(),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._restrictCursor(),!0}tabSet(){return this._activeBuffer.tabs[this._activeBuffer.x]=!0,!0}reverseIndex(){if(this._restrictCursor(),this._activeBuffer.y===this._activeBuffer.scrollTop){let e=this._activeBuffer.scrollBottom-this._activeBuffer.scrollTop;this._activeBuffer.lines.shiftElements(this._activeBuffer.ybase+this._activeBuffer.y,e,1),this._activeBuffer.lines.set(this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.getBlankLine(this._eraseAttrData())),this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom)}else this._activeBuffer.y--,this._restrictCursor();return!0}fullReset(){return this._parser.reset(),this._onRequestReset.fire(),!0}reset(){this._curAttrData=dQ.clone(),this._eraseAttrDataInternal=dQ.clone()}_eraseAttrData(){return this._eraseAttrDataInternal.bg&=-67108864,this._eraseAttrDataInternal.bg|=this._curAttrData.bg&67108863,this._eraseAttrDataInternal}setgLevel(e){return this._charsetService.setgLevel(e),!0}screenAlignmentPattern(){let e=new uK;e.content=4194373,e.fg=this._curAttrData.fg,e.bg=this._curAttrData.bg,this._setCursor(0,0);for(let t=0;t<this._bufferService.rows;++t){let n=this._activeBuffer.ybase+this._activeBuffer.y+t,r=this._activeBuffer.lines.get(n);r&&(r.fill(e),r.isWrapped=!1)}return this._dirtyRowTracker.markAllDirty(),this._setCursor(0,0),!0}requestStatusString(e,t){let n=e=>(this._coreService.triggerDataEvent(`${$.ESC}${e}${$.ESC}\\`),!0),r=this._bufferService.buffer,i=this._optionsService.rawOptions;return n(e===`"q`?`P1$r${+!!this._curAttrData.isProtected()}"q`:e===`"p`?`P1$r61;1"p`:e===`r`?`P1$r${r.scrollTop+1};${r.scrollBottom+1}r`:e===`m`?`P1$r0m`:e===` q`?`P1$r${{block:2,underline:4,bar:6}[i.cursorStyle]-+!!i.cursorBlink} q`:`P0$r`)}markRangeDirty(e,t){this._dirtyRowTracker.markRangeDirty(e,t)}},C$=class{constructor(e){this._bufferService=e,this.clearRange()}clearRange(){this.start=this._bufferService.buffer.y,this.end=this._bufferService.buffer.y}markDirty(e){e<this.start?this.start=e:e>this.end&&(this.end=e)}markRangeDirty(e,t){e>t&&(x$=e,e=t,t=x$),e<this.start&&(this.start=e),t>this.end&&(this.end=t)}markAllDirty(){this.markRangeDirty(0,this._bufferService.rows-1)}};C$=WG([Z(0,_K)],C$);function w$(e){return 0<=e&&e<256}var T$=5e7,E$=12,D$=50,O$=class extends pq{constructor(e){super(),this._action=e,this._writeBuffer=[],this._callbacks=[],this._pendingData=0,this._bufferOffset=0,this._isSyncWriting=!1,this._syncCalls=0,this._didUserInput=!1,this._onWriteParsed=this._register(new Q),this.onWriteParsed=this._onWriteParsed.event}handleUserInput(){this._didUserInput=!0}writeSync(e,t){if(t!==void 0&&this._syncCalls>t){this._syncCalls=0;return}if(this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(void 0),this._syncCalls++,this._isSyncWriting)return;this._isSyncWriting=!0;let n;for(;n=this._writeBuffer.shift();){this._action(n);let e=this._callbacks.shift();e&&e()}this._pendingData=0,this._bufferOffset=2147483647,this._isSyncWriting=!1,this._syncCalls=0}write(e,t){if(this._pendingData>T$)throw Error(`write data discarded, use flow control to avoid losing data`);if(!this._writeBuffer.length){if(this._bufferOffset=0,this._didUserInput){this._didUserInput=!1,this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t),this._innerWrite();return}setTimeout(()=>this._innerWrite())}this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t)}_innerWrite(e=0,t=!0){let n=e||performance.now();for(;this._writeBuffer.length>this._bufferOffset;){let e=this._writeBuffer[this._bufferOffset],r=this._action(e,t);if(r){r.catch(e=>(queueMicrotask(()=>{throw e}),Promise.resolve(!1))).then(e=>performance.now()-n>=E$?setTimeout(()=>this._innerWrite(0,e)):this._innerWrite(n,e));return}let i=this._callbacks[this._bufferOffset];if(i&&i(),this._bufferOffset++,this._pendingData-=e.length,performance.now()-n>=E$)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>D$&&(this._writeBuffer=this._writeBuffer.slice(this._bufferOffset),this._callbacks=this._callbacks.slice(this._bufferOffset),this._bufferOffset=0),setTimeout(()=>this._innerWrite())):(this._writeBuffer.length=0,this._callbacks.length=0,this._pendingData=0,this._bufferOffset=0),this._onWriteParsed.fire()}},k$=class{constructor(e){this._bufferService=e,this._nextId=1,this._entriesWithId=new Map,this._dataByLinkId=new Map}registerLink(e){let t=this._bufferService.buffer;if(e.id===void 0){let n=t.addMarker(t.ybase+t.y),r={data:e,id:this._nextId++,lines:[n]};return n.onDispose(()=>this._removeMarkerFromLink(r,n)),this._dataByLinkId.set(r.id,r),r.id}let n=e,r=this._getEntryIdKey(n),i=this._entriesWithId.get(r);if(i)return this.addLineToLink(i.id,t.ybase+t.y),i.id;let a=t.addMarker(t.ybase+t.y),o={id:this._nextId++,key:this._getEntryIdKey(n),data:n,lines:[a]};return a.onDispose(()=>this._removeMarkerFromLink(o,a)),this._entriesWithId.set(o.key,o),this._dataByLinkId.set(o.id,o),o.id}addLineToLink(e,t){let n=this._dataByLinkId.get(e);if(n&&n.lines.every(e=>e.line!==t)){let e=this._bufferService.buffer.addMarker(t);n.lines.push(e),e.onDispose(()=>this._removeMarkerFromLink(n,e))}}getLinkData(e){return this._dataByLinkId.get(e)?.data}_getEntryIdKey(e){return`${e.id};;${e.uri}`}_removeMarkerFromLink(e,t){let n=e.lines.indexOf(t);n!==-1&&(e.lines.splice(n,1),e.lines.length===0&&(e.data.id!==void 0&&this._entriesWithId.delete(e.key),this._dataByLinkId.delete(e.id)))}};k$=WG([Z(0,_K)],k$);var A$=!1,j$=class extends pq{constructor(e){super(),this._windowsWrappingHeuristics=this._register(new mq),this._onBinary=this._register(new Q),this.onBinary=this._onBinary.event,this._onData=this._register(new Q),this.onData=this._onData.event,this._onLineFeed=this._register(new Q),this.onLineFeed=this._onLineFeed.event,this._onResize=this._register(new Q),this.onResize=this._onResize.event,this._onWriteParsed=this._register(new Q),this.onWriteParsed=this._onWriteParsed.event,this._onScroll=this._register(new Q),this._instantiationService=new iQ,this.optionsService=this._register(new MQ(e)),this._instantiationService.setService(CK,this.optionsService),this._bufferService=this._register(this._instantiationService.createInstance(kQ)),this._instantiationService.setService(_K,this._bufferService),this._logService=this._register(this._instantiationService.createInstance(sQ)),this._instantiationService.setService(SK,this._logService),this.coreService=this._register(this._instantiationService.createInstance(LQ)),this._instantiationService.setService(yK,this.coreService),this.coreMouseService=this._register(this._instantiationService.createInstance(HQ)),this._instantiationService.setService(vK,this.coreMouseService),this.unicodeService=this._register(this._instantiationService.createInstance(JQ)),this._instantiationService.setService(TK,this.unicodeService),this._charsetService=this._instantiationService.createInstance(YQ),this._instantiationService.setService(bK,this._charsetService),this._oscLinkService=this._instantiationService.createInstance(k$),this._instantiationService.setService(wK,this._oscLinkService),this._inputHandler=this._register(new S$(this._bufferService,this._charsetService,this.coreService,this._logService,this.optionsService,this._oscLinkService,this.coreMouseService,this.unicodeService)),this._register(xq.forward(this._inputHandler.onLineFeed,this._onLineFeed)),this._register(this._inputHandler),this._register(xq.forward(this._bufferService.onResize,this._onResize)),this._register(xq.forward(this.coreService.onData,this._onData)),this._register(xq.forward(this.coreService.onBinary,this._onBinary)),this._register(this.coreService.onRequestScrollToBottom(()=>this.scrollToBottom(!0))),this._register(this.coreService.onUserInput(()=>this._writeBuffer.handleUserInput())),this._register(this.optionsService.onMultipleOptionChange([`windowsMode`,`windowsPty`],()=>this._handleWindowsPtyOptionChange())),this._register(this._bufferService.onScroll(()=>{this._onScroll.fire({position:this._bufferService.buffer.ydisp}),this._inputHandler.markRangeDirty(this._bufferService.buffer.scrollTop,this._bufferService.buffer.scrollBottom)})),this._writeBuffer=this._register(new O$((e,t)=>this._inputHandler.parse(e,t))),this._register(xq.forward(this._writeBuffer.onWriteParsed,this._onWriteParsed))}get onScroll(){return this._onScrollApi||(this._onScrollApi=this._register(new Q),this._onScroll.event(e=>{this._onScrollApi?.fire(e.position)})),this._onScrollApi.event}get cols(){return this._bufferService.cols}get rows(){return this._bufferService.rows}get buffers(){return this._bufferService.buffers}get options(){return this.optionsService.options}set options(e){for(let t in e)this.optionsService.options[t]=e[t]}write(e,t){this._writeBuffer.write(e,t)}writeSync(e,t){this._logService.logLevel<=3&&!A$&&(this._logService.warn(`writeSync is unreliable and will be removed soon.`),A$=!0),this._writeBuffer.writeSync(e,t)}input(e,t=!0){this.coreService.triggerDataEvent(e,t)}resize(e,t){isNaN(e)||isNaN(t)||(e=Math.max(e,DQ),t=Math.max(t,OQ),this._bufferService.resize(e,t))}scroll(e,t=!1){this._bufferService.scroll(e,t)}scrollLines(e,t){this._bufferService.scrollLines(e,t)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}registerEscHandler(e,t){return this._inputHandler.registerEscHandler(e,t)}registerDcsHandler(e,t){return this._inputHandler.registerDcsHandler(e,t)}registerCsiHandler(e,t){return this._inputHandler.registerCsiHandler(e,t)}registerOscHandler(e,t){return this._inputHandler.registerOscHandler(e,t)}_setup(){this._handleWindowsPtyOptionChange()}reset(){this._inputHandler.reset(),this._bufferService.reset(),this._charsetService.reset(),this.coreService.reset(),this.coreMouseService.reset()}_handleWindowsPtyOptionChange(){let e=!1,t=this.optionsService.rawOptions.windowsPty;t&&t.buildNumber!==void 0&&t.buildNumber!==void 0?e=t.backend===`conpty`&&t.buildNumber<21376:this.optionsService.rawOptions.windowsMode&&(e=!0),e?this._enableWindowsWrappingHeuristics():this._windowsWrappingHeuristics.clear()}_enableWindowsWrappingHeuristics(){if(!this._windowsWrappingHeuristics.value){let e=[];e.push(this.onLineFeed(XQ.bind(null,this._bufferService))),e.push(this.registerCsiHandler({final:`H`},()=>(XQ(this._bufferService),!1))),this._windowsWrappingHeuristics.value=uq(()=>{for(let t of e)t.dispose()})}}},M$={48:[`0`,`)`],49:[`1`,`!`],50:[`2`,`@`],51:[`3`,`#`],52:[`4`,`$`],53:[`5`,`%`],54:[`6`,`^`],55:[`7`,`&`],56:[`8`,`*`],57:[`9`,`(`],186:[`;`,`:`],187:[`=`,`+`],188:[`,`,`<`],189:[`-`,`_`],190:[`.`,`>`],191:[`/`,`?`],192:["`",`~`],219:[`[`,`{`],220:[`\\`,`|`],221:[`]`,`}`],222:[`'`,`"`]};function N$(e,t,n,r){let i={type:0,cancel:!1,key:void 0},a=!!e.shiftKey|(e.altKey?2:0)|(e.ctrlKey?4:0)|(e.metaKey?8:0);switch(e.keyCode){case 0:e.key===`UIKeyInputUpArrow`?t?i.key=$.ESC+`OA`:i.key=$.ESC+`[A`:e.key===`UIKeyInputLeftArrow`?t?i.key=$.ESC+`OD`:i.key=$.ESC+`[D`:e.key===`UIKeyInputRightArrow`?t?i.key=$.ESC+`OC`:i.key=$.ESC+`[C`:e.key===`UIKeyInputDownArrow`&&(t?i.key=$.ESC+`OB`:i.key=$.ESC+`[B`);break;case 8:i.key=e.ctrlKey?`\b`:$.DEL,e.altKey&&(i.key=$.ESC+i.key);break;case 9:if(e.shiftKey){i.key=$.ESC+`[Z`;break}i.key=$.HT,i.cancel=!0;break;case 13:i.key=e.altKey?$.ESC+$.CR:$.CR,i.cancel=!0;break;case 27:i.key=$.ESC,e.altKey&&(i.key=$.ESC+$.ESC),i.cancel=!0;break;case 37:if(e.metaKey)break;a?i.key=$.ESC+`[1;`+(a+1)+`D`:t?i.key=$.ESC+`OD`:i.key=$.ESC+`[D`;break;case 39:if(e.metaKey)break;a?i.key=$.ESC+`[1;`+(a+1)+`C`:t?i.key=$.ESC+`OC`:i.key=$.ESC+`[C`;break;case 38:if(e.metaKey)break;a?i.key=$.ESC+`[1;`+(a+1)+`A`:t?i.key=$.ESC+`OA`:i.key=$.ESC+`[A`;break;case 40:if(e.metaKey)break;a?i.key=$.ESC+`[1;`+(a+1)+`B`:t?i.key=$.ESC+`OB`:i.key=$.ESC+`[B`;break;case 45:!e.shiftKey&&!e.ctrlKey&&(i.key=$.ESC+`[2~`);break;case 46:a?i.key=$.ESC+`[3;`+(a+1)+`~`:i.key=$.ESC+`[3~`;break;case 36:a?i.key=$.ESC+`[1;`+(a+1)+`H`:t?i.key=$.ESC+`OH`:i.key=$.ESC+`[H`;break;case 35:a?i.key=$.ESC+`[1;`+(a+1)+`F`:t?i.key=$.ESC+`OF`:i.key=$.ESC+`[F`;break;case 33:e.shiftKey?i.type=2:e.ctrlKey?i.key=$.ESC+`[5;`+(a+1)+`~`:i.key=$.ESC+`[5~`;break;case 34:e.shiftKey?i.type=3:e.ctrlKey?i.key=$.ESC+`[6;`+(a+1)+`~`:i.key=$.ESC+`[6~`;break;case 112:a?i.key=$.ESC+`[1;`+(a+1)+`P`:i.key=$.ESC+`OP`;break;case 113:a?i.key=$.ESC+`[1;`+(a+1)+`Q`:i.key=$.ESC+`OQ`;break;case 114:a?i.key=$.ESC+`[1;`+(a+1)+`R`:i.key=$.ESC+`OR`;break;case 115:a?i.key=$.ESC+`[1;`+(a+1)+`S`:i.key=$.ESC+`OS`;break;case 116:a?i.key=$.ESC+`[15;`+(a+1)+`~`:i.key=$.ESC+`[15~`;break;case 117:a?i.key=$.ESC+`[17;`+(a+1)+`~`:i.key=$.ESC+`[17~`;break;case 118:a?i.key=$.ESC+`[18;`+(a+1)+`~`:i.key=$.ESC+`[18~`;break;case 119:a?i.key=$.ESC+`[19;`+(a+1)+`~`:i.key=$.ESC+`[19~`;break;case 120:a?i.key=$.ESC+`[20;`+(a+1)+`~`:i.key=$.ESC+`[20~`;break;case 121:a?i.key=$.ESC+`[21;`+(a+1)+`~`:i.key=$.ESC+`[21~`;break;case 122:a?i.key=$.ESC+`[23;`+(a+1)+`~`:i.key=$.ESC+`[23~`;break;case 123:a?i.key=$.ESC+`[24;`+(a+1)+`~`:i.key=$.ESC+`[24~`;break;default:if(e.ctrlKey&&!e.shiftKey&&!e.altKey&&!e.metaKey)e.keyCode>=65&&e.keyCode<=90?i.key=String.fromCharCode(e.keyCode-64):e.keyCode===32?i.key=$.NUL:e.keyCode>=51&&e.keyCode<=55?i.key=String.fromCharCode(e.keyCode-51+27):e.keyCode===56?i.key=$.DEL:e.keyCode===219?i.key=$.ESC:e.keyCode===220?i.key=$.FS:e.keyCode===221&&(i.key=$.GS);else if((!n||r)&&e.altKey&&!e.metaKey){let t=M$[e.keyCode]?.[+!!e.shiftKey];if(t)i.key=$.ESC+t;else if(e.keyCode>=65&&e.keyCode<=90){let t=e.ctrlKey?e.keyCode-64:e.keyCode+32,n=String.fromCharCode(t);e.shiftKey&&(n=n.toUpperCase()),i.key=$.ESC+n}else if(e.keyCode===32)i.key=$.ESC+(e.ctrlKey?$.NUL:` `);else if(e.key===`Dead`&&e.code.startsWith(`Key`)){let t=e.code.slice(3,4);e.shiftKey||(t=t.toLowerCase()),i.key=$.ESC+t,i.cancel=!0}}else n&&!e.altKey&&!e.ctrlKey&&!e.shiftKey&&e.metaKey?e.keyCode===65&&(i.type=1):e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.keyCode>=48&&e.key.length===1?i.key=e.key:e.key&&e.ctrlKey&&(e.key===`_`&&(i.key=$.US),e.key===`@`&&(i.key=$.NUL));break}return i}var P$=0,F$=class{constructor(e){this._getKey=e,this._array=[],this._insertedValues=[],this._flushInsertedTask=new xZ,this._isFlushingInserted=!1,this._deletedIndices=[],this._flushDeletedTask=new xZ,this._isFlushingDeleted=!1}clear(){this._array.length=0,this._insertedValues.length=0,this._flushInsertedTask.clear(),this._isFlushingInserted=!1,this._deletedIndices.length=0,this._flushDeletedTask.clear(),this._isFlushingDeleted=!1}insert(e){this._flushCleanupDeleted(),this._insertedValues.length===0&&this._flushInsertedTask.enqueue(()=>this._flushInserted()),this._insertedValues.push(e)}_flushInserted(){let e=this._insertedValues.sort((e,t)=>this._getKey(e)-this._getKey(t)),t=0,n=0,r=Array(this._array.length+this._insertedValues.length);for(let i=0;i<r.length;i++)n>=this._array.length||this._getKey(e[t])<=this._getKey(this._array[n])?(r[i]=e[t],t++):r[i]=this._array[n++];this._array=r,this._insertedValues.length=0}_flushCleanupInserted(){!this._isFlushingInserted&&this._insertedValues.length>0&&this._flushInsertedTask.flush()}delete(e){if(this._flushCleanupInserted(),this._array.length===0)return!1;let t=this._getKey(e);if(t===void 0||(P$=this._search(t),P$===-1)||this._getKey(this._array[P$])!==t)return!1;do if(this._array[P$]===e)return this._deletedIndices.length===0&&this._flushDeletedTask.enqueue(()=>this._flushDeleted()),this._deletedIndices.push(P$),!0;while(++P$<this._array.length&&this._getKey(this._array[P$])===t);return!1}_flushDeleted(){this._isFlushingDeleted=!0;let e=this._deletedIndices.sort((e,t)=>e-t),t=0,n=Array(this._array.length-e.length),r=0;for(let i=0;i<this._array.length;i++)e[t]===i?t++:n[r++]=this._array[i];this._array=n,this._deletedIndices.length=0,this._isFlushingDeleted=!1}_flushCleanupDeleted(){!this._isFlushingDeleted&&this._deletedIndices.length>0&&this._flushDeletedTask.flush()}*getKeyIterator(e){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(P$=this._search(e),!(P$<0||P$>=this._array.length)&&this._getKey(this._array[P$])===e))do yield this._array[P$];while(++P$<this._array.length&&this._getKey(this._array[P$])===e)}forEachByKey(e,t){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(P$=this._search(e),!(P$<0||P$>=this._array.length)&&this._getKey(this._array[P$])===e))do t(this._array[P$]);while(++P$<this._array.length&&this._getKey(this._array[P$])===e)}values(){return this._flushCleanupInserted(),this._flushCleanupDeleted(),[...this._array].values()}_search(e){let t=0,n=this._array.length-1;for(;n>=t;){let r=t+n>>1,i=this._getKey(this._array[r]);if(i>e)n=r-1;else if(i<e)t=r+1;else{for(;r>0&&this._getKey(this._array[r-1])===e;)r--;return r}}return t}},I$=0,L$=0,R$=class extends pq{constructor(){super(),this._decorations=new F$(e=>e?.marker.line),this._onDecorationRegistered=this._register(new Q),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this._register(new Q),this.onDecorationRemoved=this._onDecorationRemoved.event,this._register(uq(()=>this.reset()))}get decorations(){return this._decorations.values()}registerDecoration(e){if(e.marker.isDisposed)return;let t=new z$(e);if(t){let e=t.marker.onDispose(()=>t.dispose()),n=t.onDispose(()=>{n.dispose(),t&&(this._decorations.delete(t)&&this._onDecorationRemoved.fire(t),e.dispose())});this._decorations.insert(t),this._onDecorationRegistered.fire(t)}return t}reset(){for(let e of this._decorations.values())e.dispose();this._decorations.clear()}*getDecorationsAtCell(e,t,n){let r=0,i=0;for(let a of this._decorations.getKeyIterator(t))r=a.options.x??0,i=r+(a.options.width??1),e>=r&&e<i&&(!n||(a.options.layer??`bottom`)===n)&&(yield a)}forEachDecorationAtCell(e,t,n,r){this._decorations.forEachByKey(t,t=>{I$=t.options.x??0,L$=I$+(t.options.width??1),e>=I$&&e<L$&&(!n||(t.options.layer??`bottom`)===n)&&r(t)})}},z$=class extends fq{constructor(e){super(),this.options=e,this.onRenderEmitter=this.add(new Q),this.onRender=this.onRenderEmitter.event,this._onDispose=this.add(new Q),this.onDispose=this._onDispose.event,this._cachedBg=null,this._cachedFg=null,this.marker=e.marker,this.options.overviewRulerOptions&&!this.options.overviewRulerOptions.position&&(this.options.overviewRulerOptions.position=`full`)}get backgroundColorRGB(){return this._cachedBg===null&&(this.options.backgroundColor?this._cachedBg=SX.toColor(this.options.backgroundColor):this._cachedBg=void 0),this._cachedBg}get foregroundColorRGB(){return this._cachedFg===null&&(this.options.foregroundColor?this._cachedFg=SX.toColor(this.options.foregroundColor):this._cachedFg=void 0),this._cachedFg}dispose(){this._onDispose.fire(),super.dispose()}},B$=1e3,V$=class{constructor(e,t=B$){this._renderCallback=e,this._debounceThresholdMS=t,this._lastRefreshMs=0,this._additionalRefreshRequested=!1}dispose(){this._refreshTimeoutID&&clearTimeout(this._refreshTimeoutID)}refresh(e,t,n){this._rowCount=n,e=e===void 0?0:e,t=t===void 0?this._rowCount-1:t,this._rowStart=this._rowStart===void 0?e:Math.min(this._rowStart,e),this._rowEnd=this._rowEnd===void 0?t:Math.max(this._rowEnd,t);let r=performance.now();if(r-this._lastRefreshMs>=this._debounceThresholdMS)this._lastRefreshMs=r,this._innerRefresh();else if(!this._additionalRefreshRequested){let e=r-this._lastRefreshMs,t=this._debounceThresholdMS-e;this._additionalRefreshRequested=!0,this._refreshTimeoutID=window.setTimeout(()=>{this._lastRefreshMs=performance.now(),this._innerRefresh(),this._additionalRefreshRequested=!1,this._refreshTimeoutID=void 0},t)}}_innerRefresh(){if(this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0)return;let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t)}},H$=20,U$=class extends pq{constructor(e,t,n,r){super(),this._terminal=e,this._coreBrowserService=n,this._renderService=r,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce=``;let i=this._coreBrowserService.mainDocument;this._accessibilityContainer=i.createElement(`div`),this._accessibilityContainer.classList.add(`xterm-accessibility`),this._rowContainer=i.createElement(`div`),this._rowContainer.setAttribute(`role`,`list`),this._rowContainer.classList.add(`xterm-accessibility-tree`),this._rowElements=[];for(let e=0;e<this._terminal.rows;e++)this._rowElements[e]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[e]);if(this._topBoundaryFocusListener=e=>this._handleBoundaryFocus(e,0),this._bottomBoundaryFocusListener=e=>this._handleBoundaryFocus(e,1),this._rowElements[0].addEventListener(`focus`,this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=i.createElement(`div`),this._liveRegion.classList.add(`live-region`),this._liveRegion.setAttribute(`aria-live`,`assertive`),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this._register(new V$(this._renderRows.bind(this))),!this._terminal.element)throw Error(`Cannot enable accessibility before Terminal.open`);this._terminal.element.insertAdjacentElement(`afterbegin`,this._accessibilityContainer),this._register(this._terminal.onResize(e=>this._handleResize(e.rows))),this._register(this._terminal.onRender(e=>this._refreshRows(e.start,e.end))),this._register(this._terminal.onScroll(()=>this._refreshRows())),this._register(this._terminal.onA11yChar(e=>this._handleChar(e))),this._register(this._terminal.onLineFeed(()=>this._handleChar(`
|
|
181
181
|
`))),this._register(this._terminal.onA11yTab(e=>this._handleTab(e))),this._register(this._terminal.onKey(e=>this._handleKey(e.key))),this._register(this._terminal.onBlur(()=>this._clearLiveRegion())),this._register(this._renderService.onDimensionsChange(()=>this._refreshRowsDimensions())),this._register(fY(i,`selectionchange`,()=>this._handleSelectionChange())),this._register(this._coreBrowserService.onDprChange(()=>this._refreshRowsDimensions())),this._refreshRowsDimensions(),this._refreshRows(),this._register(uq(()=>{this._accessibilityContainer.remove(),this._rowElements.length=0}))}_handleTab(e){for(let t=0;t<e;t++)this._handleChar(` `)}_handleChar(e){this._liveRegionLineCount<H$+1&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==e&&(this._charsToAnnounce+=e):this._charsToAnnounce+=e,e===`
|
|
182
182
|
`&&(this._liveRegionLineCount++,this._liveRegionLineCount===H$+1&&(this._liveRegion.textContent+=JG.get())))}_clearLiveRegion(){this._liveRegion.textContent=``,this._liveRegionLineCount=0}_handleKey(e){this._clearLiveRegion(),/\p{Control}/u.test(e)||this._charsToConsume.push(e)}_refreshRows(e,t){this._liveRegionDebouncer.refresh(e,t,this._terminal.rows)}_renderRows(e,t){let n=this._terminal.buffer,r=n.lines.length.toString();for(let i=e;i<=t;i++){let e=n.lines.get(n.ydisp+i),t=[],a=e?.translateToString(!0,void 0,void 0,t)||``,o=(n.ydisp+i+1).toString(),s=this._rowElements[i];s&&(a.length===0?(s.textContent=`\xA0`,this._rowColumns.set(s,[0,1])):(s.textContent=a,this._rowColumns.set(s,t)),s.setAttribute(`aria-posinset`,o),s.setAttribute(`aria-setsize`,r),this._alignRowWidth(s))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce=``)}_handleBoundaryFocus(e,t){let n=e.target,r=this._rowElements[t===0?1:this._rowElements.length-2];if(n.getAttribute(`aria-posinset`)===(t===0?`1`:`${this._terminal.buffer.lines.length}`)||e.relatedTarget!==r)return;let i,a;if(t===0?(i=n,a=this._rowElements.pop(),this._rowContainer.removeChild(a)):(i=this._rowElements.shift(),a=n,this._rowContainer.removeChild(i)),i.removeEventListener(`focus`,this._topBoundaryFocusListener),a.removeEventListener(`focus`,this._bottomBoundaryFocusListener),t===0){let e=this._createAccessibilityTreeNode();this._rowElements.unshift(e),this._rowContainer.insertAdjacentElement(`afterbegin`,e)}else{let e=this._createAccessibilityTreeNode();this._rowElements.push(e),this._rowContainer.appendChild(e)}this._rowElements[0].addEventListener(`focus`,this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._terminal.scrollLines(t===0?-1:1),this._rowElements[t===0?1:this._rowElements.length-2].focus(),e.preventDefault(),e.stopImmediatePropagation()}_handleSelectionChange(){if(this._rowElements.length===0)return;let e=this._coreBrowserService.mainDocument.getSelection();if(!e)return;if(e.isCollapsed){this._rowContainer.contains(e.anchorNode)&&this._terminal.clearSelection();return}if(!e.anchorNode||!e.focusNode){console.error(`anchorNode and/or focusNode are null`);return}let t={node:e.anchorNode,offset:e.anchorOffset},n={node:e.focusNode,offset:e.focusOffset};if((t.node.compareDocumentPosition(n.node)&Node.DOCUMENT_POSITION_PRECEDING||t.node===n.node&&t.offset>n.offset)&&([t,n]=[n,t]),t.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(t={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(t.node))return;let r=this._rowElements.slice(-1)[0];if(n.node.compareDocumentPosition(r)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(n={node:r,offset:r.textContent?.length??0}),!this._rowContainer.contains(n.node))return;let i=({node:e,offset:t})=>{let n=e instanceof Text?e.parentNode:e,r=parseInt(n?.getAttribute(`aria-posinset`),10)-1;if(isNaN(r))return console.warn(`row is invalid. Race condition?`),null;let i=this._rowColumns.get(n);if(!i)return console.warn(`columns is null. Race condition?`),null;let a=t<i.length?i[t]:i.slice(-1)[0]+1;return a>=this._terminal.cols&&(++r,a=0),{row:r,column:a}},a=i(t),o=i(n);if(!(!a||!o)){if(a.row>o.row||a.row===o.row&&a.column>=o.column)throw Error(`invalid range`);this._terminal.select(a.column,a.row,(o.row-a.row)*this._terminal.cols-a.column+o.column)}}_handleResize(e){this._rowElements[this._rowElements.length-1].removeEventListener(`focus`,this._bottomBoundaryFocusListener);for(let e=this._rowContainer.children.length;e<this._terminal.rows;e++)this._rowElements[e]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[e]);for(;this._rowElements.length>e;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){let e=this._coreBrowserService.mainDocument.createElement(`div`);return e.setAttribute(`role`,`listitem`),e.tabIndex=-1,this._refreshRowDimensions(e),e}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){Object.assign(this._accessibilityContainer.style,{width:`${this._renderService.dimensions.css.canvas.width}px`,fontSize:`${this._terminal.options.fontSize}px`}),this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let e=0;e<this._terminal.rows;e++)this._refreshRowDimensions(this._rowElements[e]),this._alignRowWidth(this._rowElements[e])}}_refreshRowDimensions(e){e.style.height=`${this._renderService.dimensions.css.cell.height}px`}_alignRowWidth(e){e.style.transform=``;let t=e.getBoundingClientRect().width,n=this._rowColumns.get(e)?.slice(-1)?.[0];if(!n)return;let r=n*this._renderService.dimensions.css.cell.width;e.style.transform=`scaleX(${r/t})`}};U$=WG([Z(1,xK),Z(2,AK),Z(3,MK)],U$);var W$=class extends pq{constructor(e,t,n,r,i){super(),this._element=e,this._mouseService=t,this._renderService=n,this._bufferService=r,this._linkProviderService=i,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this._register(new Q),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new Q),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(uq(()=>{cq(this._linkCacheDisposables),this._linkCacheDisposables.length=0,this._lastMouseEvent=void 0,this._activeProviderReplies?.clear()})),this._register(this._bufferService.onResize(()=>{this._clearCurrentLink(),this._wasResized=!0})),this._register(fY(this._element,`mouseleave`,()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(fY(this._element,`mousemove`,this._handleMouseMove.bind(this))),this._register(fY(this._element,`mousedown`,this._handleMouseDown.bind(this))),this._register(fY(this._element,`mouseup`,this._handleMouseUp.bind(this)))}get currentLink(){return this._currentLink}_handleMouseMove(e){this._lastMouseEvent=e;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);if(!t)return;this._isMouseOut=!1;let n=e.composedPath();for(let e=0;e<n.length;e++){let t=n[e];if(t.classList.contains(`xterm`))break;if(t.classList.contains(`xterm-hover`))return}(!this._lastBufferCell||t.x!==this._lastBufferCell.x||t.y!==this._lastBufferCell.y)&&(this._handleHover(t),this._lastBufferCell=t)}_handleHover(e){if(this._activeLine!==e.y||this._wasResized){this._clearCurrentLink(),this._askForLink(e,!1),this._wasResized=!1;return}this._currentLink&&this._linkAtPosition(this._currentLink.link,e)||(this._clearCurrentLink(),this._askForLink(e,!0))}_askForLink(e,t){(!this._activeProviderReplies||!t)&&(this._activeProviderReplies?.forEach(e=>{e?.forEach(e=>{e.link.dispose&&e.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=e.y);let n=!1;for(let[r,i]of this._linkProviderService.linkProviders.entries())t?this._activeProviderReplies?.get(r)&&(n=this._checkLinkProviderResult(r,e,n)):i.provideLinks(e.y,t=>{if(this._isMouseOut)return;let i=t?.map(e=>({link:e}));this._activeProviderReplies?.set(r,i),n=this._checkLinkProviderResult(r,e,n),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)})}_removeIntersectingLinks(e,t){let n=new Set;for(let r=0;r<t.size;r++){let i=t.get(r);if(i)for(let t=0;t<i.length;t++){let r=i[t],a=r.link.range.start.y<e?0:r.link.range.start.x,o=r.link.range.end.y>e?this._bufferService.cols:r.link.range.end.x;for(let e=a;e<=o;e++){if(n.has(e)){i.splice(t--,1);break}n.add(e)}}}}_checkLinkProviderResult(e,t,n){if(!this._activeProviderReplies)return n;let r=this._activeProviderReplies.get(e),i=!1;for(let t=0;t<e;t++)(!this._activeProviderReplies.has(t)||this._activeProviderReplies.get(t))&&(i=!0);if(!i&&r){let e=r.find(e=>this._linkAtPosition(e.link,t));e&&(n=!0,this._handleNewLink(e))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!n)for(let e=0;e<this._activeProviderReplies.size;e++){let r=this._activeProviderReplies.get(e)?.find(e=>this._linkAtPosition(e.link,t));if(r){n=!0,this._handleNewLink(r);break}}return n}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);t&&this._mouseDownLink&&G$(this._mouseDownLink.link,this._currentLink.link)&&this._linkAtPosition(this._currentLink.link,t)&&this._currentLink.link.activate(e,this._currentLink.link.text)}_clearCurrentLink(e,t){!this._currentLink||!this._lastMouseEvent||(!e||!t||this._currentLink.link.range.start.y>=e&&this._currentLink.link.range.end.y<=t)&&(this._linkLeave(this._element,this._currentLink.link,this._lastMouseEvent),this._currentLink=void 0,cq(this._linkCacheDisposables),this._linkCacheDisposables.length=0)}_handleNewLink(e){if(!this._lastMouseEvent)return;let t=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);t&&this._linkAtPosition(e.link,t)&&(this._currentLink=e,this._currentLink.state={decorations:{underline:e.link.decorations===void 0||e.link.decorations.underline,pointerCursor:e.link.decorations===void 0||e.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,e.link,this._lastMouseEvent),e.link.decorations={},Object.defineProperties(e.link.decorations,{pointerCursor:{get:()=>this._currentLink?.state?.decorations.pointerCursor,set:e=>{this._currentLink?.state&&this._currentLink.state.decorations.pointerCursor!==e&&(this._currentLink.state.decorations.pointerCursor=e,this._currentLink.state.isHovered&&this._element.classList.toggle(`xterm-cursor-pointer`,e))}},underline:{get:()=>this._currentLink?.state?.decorations.underline,set:t=>{this._currentLink?.state&&this._currentLink?.state?.decorations.underline!==t&&(this._currentLink.state.decorations.underline=t,this._currentLink.state.isHovered&&this._fireUnderlineEvent(e.link,t))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(e=>{if(!this._currentLink)return;let t=e.start===0?0:e.start+1+this._bufferService.buffer.ydisp,n=this._bufferService.buffer.ydisp+1+e.end;if(this._currentLink.link.range.start.y>=t&&this._currentLink.link.range.end.y<=n&&(this._clearCurrentLink(t,n),this._lastMouseEvent)){let e=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);e&&this._askForLink(e,!1)}})))}_linkHover(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!0),this._currentLink.state.decorations.pointerCursor&&e.classList.add(`xterm-cursor-pointer`)),t.hover&&t.hover(n,t.text)}_fireUnderlineEvent(e,t){let n=e.range,r=this._bufferService.buffer.ydisp,i=this._createLinkUnderlineEvent(n.start.x-1,n.start.y-r-1,n.end.x,n.end.y-r-1,void 0);(t?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(i)}_linkLeave(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!1),this._currentLink.state.decorations.pointerCursor&&e.classList.remove(`xterm-cursor-pointer`)),t.leave&&t.leave(n,t.text)}_linkAtPosition(e,t){let n=e.range.start.y*this._bufferService.cols+e.range.start.x,r=e.range.end.y*this._bufferService.cols+e.range.end.x,i=t.y*this._bufferService.cols+t.x;return n<=i&&i<=r}_positionFromMouseEvent(e,t,n){let r=n.getCoords(e,t,this._bufferService.cols,this._bufferService.rows);if(r)return{x:r[0],y:r[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(e,t,n,r,i){return{x1:e,y1:t,x2:n,y2:r,cols:this._bufferService.cols,fg:i}}};W$=WG([Z(1,jK),Z(2,MK),Z(3,_K),Z(4,IK)],W$);function G$(e,t){return e.text===t.text&&e.range.start.x===t.range.start.x&&e.range.start.y===t.range.start.y&&e.range.end.x===t.range.end.x&&e.range.end.y===t.range.end.y}var K$=class extends j${constructor(e={}){super(e),this._linkifier=this._register(new mq),this.browser=iZ,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new mq),this._onCursorMove=this._register(new Q),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new Q),this.onKey=this._onKey.event,this._onRender=this._register(new Q),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new Q),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new Q),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new Q),this.onBell=this._onBell.event,this._onFocus=this._register(new Q),this._onBlur=this._register(new Q),this._onA11yCharEmitter=this._register(new Q),this._onA11yTabEmitter=this._register(new Q),this._onWillOpen=this._register(new Q),this._setup(),this._decorationService=this._instantiationService.createInstance(R$),this._instantiationService.setService(EK,this._decorationService),this._linkProviderService=this._instantiationService.createInstance($X),this._instantiationService.setService(IK,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(DK)),this._register(this._inputHandler.onRequestBell(()=>this._onBell.fire())),this._register(this._inputHandler.onRequestRefreshRows(e=>this.refresh(e?.start??0,e?.end??this.rows-1))),this._register(this._inputHandler.onRequestSendFocus(()=>this._reportFocus())),this._register(this._inputHandler.onRequestReset(()=>this.reset())),this._register(this._inputHandler.onRequestWindowsOptionsReport(e=>this._reportWindowsOptions(e))),this._register(this._inputHandler.onColor(e=>this._handleColorEvent(e))),this._register(xq.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(xq.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(xq.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(xq.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(e=>this._afterResize(e.cols,e.rows))),this._register(uq(()=>{this._customKeyEventHandler=void 0,this.element?.parentNode?.removeChild(this.element)}))}get linkifier(){return this._linkifier.value}get onFocus(){return this._onFocus.event}get onBlur(){return this._onBlur.event}get onA11yChar(){return this._onA11yCharEmitter.event}get onA11yTab(){return this._onA11yTabEmitter.event}get onWillOpen(){return this._onWillOpen.event}_handleColorEvent(e){if(this._themeService)for(let t of e){let e,n=``;switch(t.index){case 256:e=`foreground`,n=`10`;break;case 257:e=`background`,n=`11`;break;case 258:e=`cursor`,n=`12`;break;default:e=`ansi`,n=`4;`+t.index}switch(t.type){case 0:let r=xX.toColorRGB(e===`ansi`?this._themeService.colors.ansi[t.index]:this._themeService.colors[e]);this.coreService.triggerDataEvent(`${$.ESC}]${n};${h$(r)}${pX.ST}`);break;case 1:if(e===`ansi`)this._themeService.modifyColors(e=>e.ansi[t.index]=bX.toColor(...t.color));else{let n=e;this._themeService.modifyColors(e=>e[n]=bX.toColor(...t.color))}break;case 2:this._themeService.restoreColor(t.index);break}}}_setup(){super._setup(),this._customKeyEventHandler=void 0}get buffer(){return this.buffers.active}focus(){this.textarea&&this.textarea.focus({preventScroll:!0})}_handleScreenReaderModeOptionChange(e){e?!this._accessibilityManager.value&&this._renderService&&(this._accessibilityManager.value=this._instantiationService.createInstance(U$,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent($.ESC+`[I`),this.element.classList.add(`focus`),this._showCursor(),this._onFocus.fire()}blur(){return this.textarea?.blur()}_handleTextAreaBlur(){this.textarea.value=``,this.refresh(this.buffer.y,this.buffer.y),this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent($.ESC+`[O`),this.element.classList.remove(`focus`),this._onBlur.fire()}_syncTextArea(){if(!this.textarea||!this.buffer.isCursorInViewport||this._compositionHelper.isComposing||!this._renderService)return;let e=this.buffer.ybase+this.buffer.y,t=this.buffer.lines.get(e);if(!t)return;let n=Math.min(this.buffer.x,this.cols-1),r=this._renderService.dimensions.css.cell.height,i=t.getWidth(n),a=this._renderService.dimensions.css.cell.width*i,o=this.buffer.y*this._renderService.dimensions.css.cell.height,s=n*this._renderService.dimensions.css.cell.width;this.textarea.style.left=s+`px`,this.textarea.style.top=o+`px`,this.textarea.style.width=a+`px`,this.textarea.style.height=r+`px`,this.textarea.style.lineHeight=r+`px`,this.textarea.style.zIndex=`-5`}_initGlobal(){this._bindKeys(),this._register(fY(this.element,`copy`,e=>{this.hasSelection()&&ZG(e,this._selectionService)}));let e=e=>QG(e,this.textarea,this.coreService,this.optionsService);this._register(fY(this.textarea,`paste`,e)),this._register(fY(this.element,`paste`,e)),cZ?this._register(fY(this.element,`mousedown`,e=>{e.button===2&&tK(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(fY(this.element,`contextmenu`,e=>{tK(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),gZ&&this._register(fY(this.element,`auxclick`,e=>{e.button===1&&eK(e,this.textarea,this.screenElement)}))}_bindKeys(){this._register(fY(this.textarea,`keyup`,e=>this._keyUp(e),!0)),this._register(fY(this.textarea,`keydown`,e=>this._keyDown(e),!0)),this._register(fY(this.textarea,`keypress`,e=>this._keyPress(e),!0)),this._register(fY(this.textarea,`compositionstart`,()=>this._compositionHelper.compositionstart())),this._register(fY(this.textarea,`compositionupdate`,e=>this._compositionHelper.compositionupdate(e))),this._register(fY(this.textarea,`compositionend`,()=>this._compositionHelper.compositionend())),this._register(fY(this.textarea,`input`,e=>this._inputEvent(e),!0)),this._register(this.onRender(()=>this._compositionHelper.updateCompositionElements()))}open(e){if(!e)throw Error(`Terminal requires a parent element.`);if(e.isConnected||this._logService.debug(`Terminal.open was called on an element that was not attached to the DOM`),this.element?.ownerDocument.defaultView&&this._coreBrowserService){this.element.ownerDocument.defaultView!==this._coreBrowserService.window&&(this._coreBrowserService.window=this.element.ownerDocument.defaultView);return}this._document=e.ownerDocument,this.options.documentOverride&&this.options.documentOverride instanceof Document&&(this._document=this.optionsService.rawOptions.documentOverride),this.element=this._document.createElement(`div`),this.element.dir=`ltr`,this.element.classList.add(`terminal`),this.element.classList.add(`xterm`),e.appendChild(this.element);let t=this._document.createDocumentFragment();this._viewportElement=this._document.createElement(`div`),this._viewportElement.classList.add(`xterm-viewport`),t.appendChild(this._viewportElement),this.screenElement=this._document.createElement(`div`),this.screenElement.classList.add(`xterm-screen`),this._register(fY(this.screenElement,`mousemove`,e=>this.updateCursorStyle(e))),this._helperContainer=this._document.createElement(`div`),this._helperContainer.classList.add(`xterm-helpers`),this.screenElement.appendChild(this._helperContainer),t.appendChild(this.screenElement);let n=this.textarea=this._document.createElement(`textarea`);this.textarea.classList.add(`xterm-helper-textarea`),this.textarea.setAttribute(`aria-label`,KG.get()),_Z||this.textarea.setAttribute(`aria-multiline`,`false`),this.textarea.setAttribute(`autocorrect`,`off`),this.textarea.setAttribute(`autocapitalize`,`off`),this.textarea.setAttribute(`spellcheck`,`false`),this.textarea.tabIndex=0,this._register(this.optionsService.onSpecificOptionChange(`disableStdin`,()=>n.readOnly=this.optionsService.rawOptions.disableStdin)),this.textarea.readOnly=this.optionsService.rawOptions.disableStdin,this._coreBrowserService=this._register(this._instantiationService.createInstance(ZX,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<`u`?window.document:null)),this._instantiationService.setService(AK,this._coreBrowserService),this._register(fY(this.textarea,`focus`,e=>this._handleTextAreaFocus(e))),this._register(fY(this.textarea,`blur`,()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(qX,this._document,this._helperContainer),this._instantiationService.setService(kK,this._charSizeService),this._themeService=this._instantiationService.createInstance(tQ),this._instantiationService.setService(FK,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(OX),this._instantiationService.setService(PK,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(CZ,this.rows,this.screenElement)),this._instantiationService.setService(MK,this._renderService),this._register(this._renderService.onRenderedViewportChange(e=>this._onRender.fire(e))),this.onResize(e=>this._renderService.resize(e.cols,e.rows)),this._compositionView=this._document.createElement(`div`),this._compositionView.classList.add(`composition-view`),this._compositionHelper=this._instantiationService.createInstance(mX,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(nZ),this._instantiationService.setService(jK,this._mouseService);let r=this._linkifier.value=this._register(this._instantiationService.createInstance(W$,this.screenElement));this.element.appendChild(t);try{this._onWillOpen.fire(this.element)}catch{}this._renderService.hasRenderer()||this._renderService.setRenderer(this._createRenderer()),this._register(this.onCursorMove(()=>{this._renderService.handleCursorMove(),this._syncTextArea()})),this._register(this.onResize(()=>this._renderService.handleResize(this.cols,this.rows))),this._register(this.onBlur(()=>this._renderService.handleBlur())),this._register(this.onFocus(()=>this._renderService.handleFocus())),this._viewport=this._register(this._instantiationService.createInstance(aX,this.element,this.screenElement)),this._register(this._viewport.onRequestScrollLines(e=>{super.scrollLines(e,!1),this.refresh(0,this.rows-1)})),this._selectionService=this._register(this._instantiationService.createInstance(GZ,this.element,this.screenElement,r)),this._instantiationService.setService(NK,this._selectionService),this._register(this._selectionService.onRequestScrollLines(e=>this.scrollLines(e.amount,e.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(e=>this._renderService.handleSelectionChanged(e.start,e.end,e.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(e=>{this.textarea.value=e,this.textarea.focus(),this.textarea.select()})),this._register(xq.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(oX,this.screenElement)),this._register(fY(this.element,`mousedown`,e=>this._selectionService.handleMouseDown(e))),this.coreMouseService.areMouseEventsActive?(this._selectionService.disable(),this.element.classList.add(`enable-mouse-events`)):this._selectionService.enable(),this.options.screenReaderMode&&(this._accessibilityManager.value=this._instantiationService.createInstance(U$,this)),this._register(this.optionsService.onSpecificOptionChange(`screenReaderMode`,e=>this._handleScreenReaderModeOptionChange(e))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(dX,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange(`overviewRuler`,e=>{!this._overviewRulerRenderer&&e&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(dX,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(KX,this,this._document,this.element,this.screenElement,this._viewportElement,this._helperContainer,this.linkifier)}bindMouse(){let e=this,t=this.element;function n(t){let n=e._mouseService.getMouseReportCoords(t,e.screenElement);if(!n)return!1;let r,i;switch(t.overrideType||t.type){case`mousemove`:i=32,t.buttons===void 0?(r=3,t.button!==void 0&&(r=t.button<3?t.button:3)):r=t.buttons&1?0:t.buttons&4?1:t.buttons&2?2:3;break;case`mouseup`:i=0,r=t.button<3?t.button:3;break;case`mousedown`:i=1,r=t.button<3?t.button:3;break;case`wheel`:if(e._customWheelEventHandler&&e._customWheelEventHandler(t)===!1)return!1;let n=t.deltaY;if(n===0||e.coreMouseService.consumeWheelEvent(t,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return!1;i=n<0?0:1,r=4;break;default:return!1}return i===void 0||r===void 0||r>4?!1:e.coreMouseService.triggerMouseEvent({col:n.col,row:n.row,x:n.x,y:n.y,button:r,action:i,ctrl:t.ctrlKey,alt:t.altKey,shift:t.shiftKey})}let r={mouseup:null,wheel:null,mousedrag:null,mousemove:null},i={mouseup:e=>(n(e),e.buttons||(this._document.removeEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.removeEventListener(`mousemove`,r.mousedrag)),this.cancel(e)),wheel:e=>(n(e),this.cancel(e,!0)),mousedrag:e=>{e.buttons&&n(e)},mousemove:e=>{e.buttons||n(e)}};this._register(this.coreMouseService.onProtocolChange(e=>{e?(this.optionsService.rawOptions.logLevel===`debug`&&this._logService.debug(`Binding to mouse events:`,this.coreMouseService.explainEvents(e)),this.element.classList.add(`enable-mouse-events`),this._selectionService.disable()):(this._logService.debug(`Unbinding from mouse events.`),this.element.classList.remove(`enable-mouse-events`),this._selectionService.enable()),e&8?r.mousemove||=(t.addEventListener(`mousemove`,i.mousemove),i.mousemove):(t.removeEventListener(`mousemove`,r.mousemove),r.mousemove=null),e&16?r.wheel||=(t.addEventListener(`wheel`,i.wheel,{passive:!1}),i.wheel):(t.removeEventListener(`wheel`,r.wheel),r.wheel=null),e&2?r.mouseup||=i.mouseup:(this._document.removeEventListener(`mouseup`,r.mouseup),r.mouseup=null),e&4?r.mousedrag||=i.mousedrag:(this._document.removeEventListener(`mousemove`,r.mousedrag),r.mousedrag=null)})),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this._register(fY(t,`mousedown`,e=>{if(e.preventDefault(),this.focus(),!(!this.coreMouseService.areMouseEventsActive||this._selectionService.shouldForceSelection(e)))return n(e),r.mouseup&&this._document.addEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.addEventListener(`mousemove`,r.mousedrag),this.cancel(e)})),this._register(fY(t,`wheel`,t=>{if(!r.wheel){if(this._customWheelEventHandler&&this._customWheelEventHandler(t)===!1)return!1;if(!this.buffer.hasScrollback){if(t.deltaY===0)return!1;if(e.coreMouseService.consumeWheelEvent(t,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return this.cancel(t,!0);let n=$.ESC+(this.coreService.decPrivateModes.applicationCursorKeys?`O`:`[`)+(t.deltaY<0?`A`:`B`);return this.coreService.triggerDataEvent(n,!0),this.cancel(t,!0)}}},{passive:!1}))}refresh(e,t){this._renderService?.refreshRows(e,t)}updateCursorStyle(e){this._selectionService?.shouldColumnSelect(e)?this.element.classList.add(`column-select`):this.element.classList.remove(`column-select`)}_showCursor(){this.coreService.isCursorInitialized||(this.coreService.isCursorInitialized=!0,this.refresh(this.buffer.y,this.buffer.y))}scrollLines(e,t){this._viewport?this._viewport.scrollLines(e):super.scrollLines(e,t),this.refresh(0,this.rows-1)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){e&&this._viewport?this._viewport.scrollToLine(this.buffer.ybase,!0):this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}paste(e){$G(e,this.textarea,this.coreService,this.optionsService)}attachCustomKeyEventHandler(e){this._customKeyEventHandler=e}attachCustomWheelEventHandler(e){this._customWheelEventHandler=e}registerLinkProvider(e){return this._linkProviderService.registerLinkProvider(e)}registerCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);let t=this._characterJoinerService.register(e);return this.refresh(0,this.rows-1),t}deregisterCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);this._characterJoinerService.deregister(e)&&this.refresh(0,this.rows-1)}get markers(){return this.buffer.markers}registerMarker(e){return this.buffer.addMarker(this.buffer.ybase+this.buffer.y+e)}registerDecoration(e){return this._decorationService.registerDecoration(e)}hasSelection(){return this._selectionService?this._selectionService.hasSelection:!1}select(e,t,n){this._selectionService.setSelection(e,t,n)}getSelection(){return this._selectionService?this._selectionService.selectionText:``}getSelectionPosition(){if(!(!this._selectionService||!this._selectionService.hasSelection))return{start:{x:this._selectionService.selectionStart[0],y:this._selectionService.selectionStart[1]},end:{x:this._selectionService.selectionEnd[0],y:this._selectionService.selectionEnd[1]}}}clearSelection(){this._selectionService?.clearSelection()}selectAll(){this._selectionService?.selectAll()}selectLines(e,t){this._selectionService?.selectLines(e,t)}_keyDown(e){if(this._keyDownHandled=!1,this._keyDownSeen=!0,this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;let t=this.browser.isMac&&this.options.macOptionIsMeta&&e.altKey;if(!t&&!this._compositionHelper.keydown(e))return this.options.scrollOnUserInput&&this.buffer.ybase!==this.buffer.ydisp&&this.scrollToBottom(!0),!1;!t&&(e.key===`Dead`||e.key===`AltGraph`)&&(this._unprocessedDeadKey=!0);let n=N$(e,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(e),n.type===3||n.type===2){let t=this.rows-1;return this.scrollLines(n.type===2?-t:t),this.cancel(e,!0)}if(n.type===1&&this.selectAll(),this._isThirdLevelShift(this.browser,e)||(n.cancel&&this.cancel(e,!0),!n.key)||e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.key.length===1&&e.key.charCodeAt(0)>=65&&e.key.charCodeAt(0)<=90)return!0;if(this._unprocessedDeadKey)return this._unprocessedDeadKey=!1,!0;if((n.key===$.ETX||n.key===$.CR)&&(this.textarea.value=``),this._onKey.fire({key:n.key,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(n.key,!0),!this.optionsService.rawOptions.screenReaderMode||e.altKey||e.ctrlKey)return this.cancel(e,!0);this._keyDownHandled=!0}_isThirdLevelShift(e,t){let n=e.isMac&&!this.options.macOptionIsMeta&&t.altKey&&!t.ctrlKey&&!t.metaKey||e.isWindows&&t.altKey&&t.ctrlKey&&!t.metaKey||e.isWindows&&t.getModifierState(`AltGraph`);return t.type===`keypress`?n:n&&(!t.keyCode||t.keyCode>47)}_keyUp(e){this._keyDownSeen=!1,!(this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)&&(q$(e)||this.focus(),this.updateCursorStyle(e),this._keyPressHandled=!1)}_keyPress(e){let t;if(this._keyPressHandled=!1,this._keyDownHandled||this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;if(this.cancel(e),e.charCode)t=e.charCode;else if(e.which===null||e.which===void 0)t=e.keyCode;else if(e.which!==0&&e.charCode!==0)t=e.which;else return!1;return!t||(e.altKey||e.ctrlKey||e.metaKey)&&!this._isThirdLevelShift(this.browser,e)?!1:(t=String.fromCharCode(t),this._onKey.fire({key:t,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(t,!0),this._keyPressHandled=!0,this._unprocessedDeadKey=!1,!0)}_inputEvent(e){if(e.data&&e.inputType===`insertText`&&(!e.composed||!this._keyDownSeen)&&!this.optionsService.rawOptions.screenReaderMode){if(this._keyPressHandled)return!1;this._unprocessedDeadKey=!1;let t=e.data;return this.coreService.triggerDataEvent(t,!0),this.cancel(e),!0}return!1}resize(e,t){if(e===this.cols&&t===this.rows){this._charSizeService&&!this._charSizeService.hasValidSize&&this._charSizeService.measure();return}super.resize(e,t)}_afterResize(e,t){this._charSizeService?.measure()}clear(){if(!(this.buffer.ybase===0&&this.buffer.y===0)){this.buffer.clearAllMarkers(),this.buffer.lines.set(0,this.buffer.lines.get(this.buffer.ybase+this.buffer.y)),this.buffer.lines.length=1,this.buffer.ydisp=0,this.buffer.ybase=0,this.buffer.y=0;for(let e=1;e<this.rows;e++)this.buffer.lines.push(this.buffer.getBlankLine(dQ));this._onScroll.fire({position:this.buffer.ydisp}),this.refresh(0,this.rows-1)}}reset(){this.options.rows=this.rows,this.options.cols=this.cols;let e=this._customKeyEventHandler;this._setup(),super.reset(),this._selectionService?.reset(),this._decorationService.reset(),this._customKeyEventHandler=e,this.refresh(0,this.rows-1)}clearTextureAtlas(){this._renderService?.clearTextureAtlas()}_reportFocus(){this.element?.classList.contains(`focus`)?this.coreService.triggerDataEvent($.ESC+`[I`):this.coreService.triggerDataEvent($.ESC+`[O`)}_reportWindowsOptions(e){if(this._renderService)switch(e){case 0:let e=this._renderService.dimensions.css.canvas.width.toFixed(0),t=this._renderService.dimensions.css.canvas.height.toFixed(0);this.coreService.triggerDataEvent(`${$.ESC}[4;${t};${e}t`);break;case 1:let n=this._renderService.dimensions.css.cell.width.toFixed(0),r=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${$.ESC}[6;${r};${n}t`);break}}cancel(e,t){if(!(!this.options.cancelEvents&&!t))return e.preventDefault(),e.stopPropagation(),!1}};function q$(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}var J$=class{constructor(){this._addons=[]}dispose(){for(let e=this._addons.length-1;e>=0;e--)this._addons[e].instance.dispose()}loadAddon(e,t){let n={instance:t,dispose:t.dispose,isDisposed:!1};this._addons.push(n),t.dispose=()=>this._wrappedAddonDispose(n),t.activate(e)}_wrappedAddonDispose(e){if(e.isDisposed)return;let t=-1;for(let n=0;n<this._addons.length;n++)if(this._addons[n]===e){t=n;break}if(t===-1)throw Error(`Could not dispose an addon that has not been loaded`);e.isDisposed=!0,e.dispose.apply(e.instance),this._addons.splice(t,1)}},Y$=class{constructor(e){this._line=e}get isWrapped(){return this._line.isWrapped}get length(){return this._line.length}getCell(e,t){if(!(e<0||e>=this._line.length))return t?(this._line.loadCell(e,t),t):this._line.loadCell(e,new uK)}translateToString(e,t,n){return this._line.translateToString(e,t,n)}},X$=class{constructor(e,t){this._buffer=e,this.type=t}init(e){return this._buffer=e,this}get cursorY(){return this._buffer.y}get cursorX(){return this._buffer.x}get viewportY(){return this._buffer.ydisp}get baseY(){return this._buffer.ybase}get length(){return this._buffer.lines.length}getLine(e){let t=this._buffer.lines.get(e);if(t)return new Y$(t)}getNullCell(){return new uK}},Z$=class extends pq{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new Q),this.onBufferChange=this._onBufferChange.event,this._normal=new X$(this._core.buffers.normal,`normal`),this._alternate=new X$(this._core.buffers.alt,`alternate`),this._core.buffers.onBufferActivate(()=>this._onBufferChange.fire(this.active))}get active(){if(this._core.buffers.active===this._core.buffers.normal)return this.normal;if(this._core.buffers.active===this._core.buffers.alt)return this.alternate;throw Error(`Active buffer is neither normal nor alternate`)}get normal(){return this._normal.init(this._core.buffers.normal)}get alternate(){return this._alternate.init(this._core.buffers.alt)}},Q$=class{constructor(e){this._core=e}registerCsiHandler(e,t){return this._core.registerCsiHandler(e,e=>t(e.toArray()))}addCsiHandler(e,t){return this.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._core.registerDcsHandler(e,(e,n)=>t(e,n.toArray()))}addDcsHandler(e,t){return this.registerDcsHandler(e,t)}registerEscHandler(e,t){return this._core.registerEscHandler(e,t)}addEscHandler(e,t){return this.registerEscHandler(e,t)}registerOscHandler(e,t){return this._core.registerOscHandler(e,t)}addOscHandler(e,t){return this.registerOscHandler(e,t)}},$$=class{constructor(e){this._core=e}register(e){this._core.unicodeService.register(e)}get versions(){return this._core.unicodeService.versions}get activeVersion(){return this._core.unicodeService.activeVersion}set activeVersion(e){this._core.unicodeService.activeVersion=e}},e1=[`cols`,`rows`],t1=0,n1=class extends pq{constructor(e){super(),this._core=this._register(new K$(e)),this._addonManager=this._register(new J$),this._publicOptions={...this._core.options};let t=e=>this._core.options[e],n=(e,t)=>{this._checkReadonlyOptions(e),this._core.options[e]=t};for(let e in this._core.options){let r={get:t.bind(this,e),set:n.bind(this,e)};Object.defineProperty(this._publicOptions,e,r)}}_checkReadonlyOptions(e){if(e1.includes(e))throw Error(`Option "${e}" can only be set in the constructor`)}_checkProposedApi(){if(!this._core.optionsService.rawOptions.allowProposedApi)throw Error(`You must set the allowProposedApi option to true to use proposed API`)}get onBell(){return this._core.onBell}get onBinary(){return this._core.onBinary}get onCursorMove(){return this._core.onCursorMove}get onData(){return this._core.onData}get onKey(){return this._core.onKey}get onLineFeed(){return this._core.onLineFeed}get onRender(){return this._core.onRender}get onResize(){return this._core.onResize}get onScroll(){return this._core.onScroll}get onSelectionChange(){return this._core.onSelectionChange}get onTitleChange(){return this._core.onTitleChange}get onWriteParsed(){return this._core.onWriteParsed}get element(){return this._core.element}get parser(){return this._parser||=new Q$(this._core),this._parser}get unicode(){return this._checkProposedApi(),new $$(this._core)}get textarea(){return this._core.textarea}get rows(){return this._core.rows}get cols(){return this._core.cols}get buffer(){return this._buffer||=this._register(new Z$(this._core)),this._buffer}get markers(){return this._checkProposedApi(),this._core.markers}get modes(){let e=this._core.coreService.decPrivateModes,t=`none`;switch(this._core.coreMouseService.activeProtocol){case`X10`:t=`x10`;break;case`VT200`:t=`vt200`;break;case`DRAG`:t=`drag`;break;case`ANY`:t=`any`;break}return{applicationCursorKeysMode:e.applicationCursorKeys,applicationKeypadMode:e.applicationKeypad,bracketedPasteMode:e.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:t,originMode:e.origin,reverseWraparoundMode:e.reverseWraparound,sendFocusMode:e.sendFocus,synchronizedOutputMode:e.synchronizedOutput,wraparoundMode:e.wraparound}}get options(){return this._publicOptions}set options(e){for(let t in e)this._publicOptions[t]=e[t]}blur(){this._core.blur()}focus(){this._core.focus()}input(e,t=!0){this._core.input(e,t)}resize(e,t){this._verifyIntegers(e,t),this._core.resize(e,t)}open(e){this._core.open(e)}attachCustomKeyEventHandler(e){this._core.attachCustomKeyEventHandler(e)}attachCustomWheelEventHandler(e){this._core.attachCustomWheelEventHandler(e)}registerLinkProvider(e){return this._core.registerLinkProvider(e)}registerCharacterJoiner(e){return this._checkProposedApi(),this._core.registerCharacterJoiner(e)}deregisterCharacterJoiner(e){this._checkProposedApi(),this._core.deregisterCharacterJoiner(e)}registerMarker(e=0){return this._verifyIntegers(e),this._core.registerMarker(e)}registerDecoration(e){return this._checkProposedApi(),this._verifyPositiveIntegers(e.x??0,e.width??0,e.height??0),this._core.registerDecoration(e)}hasSelection(){return this._core.hasSelection()}select(e,t,n){this._verifyIntegers(e,t,n),this._core.select(e,t,n)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(e,t){this._verifyIntegers(e,t),this._core.selectLines(e,t)}dispose(){super.dispose()}scrollLines(e){this._verifyIntegers(e),this._core.scrollLines(e)}scrollPages(e){this._verifyIntegers(e),this._core.scrollPages(e)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(e){this._verifyIntegers(e),this._core.scrollToLine(e)}clear(){this._core.clear()}write(e,t){this._core.write(e,t)}writeln(e,t){this._core.write(e),this._core.write(`\r
|
|
183
|
-
`,t)}paste(e){this._core.paste(e)}refresh(e,t){this._verifyIntegers(e,t),this._core.refresh(e,t)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(e){this._addonManager.loadAddon(this,e)}static get strings(){return{get promptLabel(){return KG.get()},set promptLabel(e){KG.set(e)},get tooMuchOutput(){return JG.get()},set tooMuchOutput(e){JG.set(e)}}}_verifyIntegers(...e){for(t1 of e)if(t1===1/0||isNaN(t1)||t1%1!=0)throw Error(`This API only accepts integers`)}_verifyPositiveIntegers(...e){for(t1 of e)if(t1&&(t1===1/0||isNaN(t1)||t1%1!=0||t1<0))throw Error(`This API only accepts positive integers`)}},r1=250,i1=5e3,a1=8e3,o1=3e3;function s1(e){return`${e.protocol===`https:`?`wss:`:`ws:`}//${e.host}`}function c1(){return s1(window.location)}var l1=class{opts;ws=null;backoff=r1;reconnectTimer=null;connectTimer=null;stallTimer=null;disposed=!1;ended=!1;receivedData=!1;url;constructor(e){this.opts=e;let t=e.wsBase??c1();this.url=`${t.replace(/\/$/,``)}/ws/terminal/${encodeURIComponent(e.sessionId)}`}connect(){if(this.disposed||this.ended)return;this.clearTimer(),this.opts.onStatus(this.backoff===r1?`connecting`:`reconnecting`);let e=new WebSocket(this.url);e.binaryType=`arraybuffer`,this.ws=e,this.connectTimer=setTimeout(()=>{e.readyState===WebSocket.CONNECTING&&this.forceClose(e)},a1),e.onopen=()=>{this.clearConnectTimer(),this.receivedData&&(this.receivedData=!1,this.opts.onReset?.())},e.onmessage=e=>{typeof e.data==`string`?this.handleControl(e.data):(this.receivedData=!0,this.opts.onData(new Uint8Array(e.data)))},e.onclose=()=>{this.ws=null,this.clearConnectTimer(),this.clearStallTimer(),!(this.disposed||this.ended)&&(this.opts.onStatus(`reconnecting`),this.scheduleReconnect())},e.onerror=()=>{this.forceClose(e)}}send(e){this.ws&&this.ws.readyState===WebSocket.OPEN&&(this.ws.send(new TextEncoder().encode(e)),this.watchForStall())}resize(e,t){this.ws&&this.ws.readyState===WebSocket.OPEN&&(this.ws.send(JSON.stringify({t:`resize`,cols:e,rows:t})),this.watchForStall())}dispose(){if(this.disposed=!0,this.clearTimer(),this.clearConnectTimer(),this.clearStallTimer(),this.ws){this.ws.onopen=null,this.ws.onclose=null,this.ws.onerror=null,this.ws.onmessage=null;try{this.ws.close()}catch{}this.ws=null}}handleControl(e){let t;try{t=JSON.parse(e)}catch{return}t.t===`status`&&(t.status===`live`?(this.backoff=r1,this.opts.onStatus(`live`)):t.status===`ended`&&(this.ended=!0,this.opts.onStatus(`ended`)))}watchForStall(){this.stallTimer===null&&(this.stallTimer=setTimeout(()=>{this.stallTimer=null;let e=this.ws;!e||e.readyState!==WebSocket.OPEN||e.bufferedAmount>0&&this.forceClose(e)},o1))}forceClose(e){try{e.close()}catch{}if(this.ws===e&&e.readyState===WebSocket.CLOSED){if(e.onclose=null,this.ws=null,this.disposed||this.ended)return;this.opts.onStatus(`reconnecting`),this.scheduleReconnect()}}scheduleReconnect(){this.clearTimer();let e=this.backoff;this.backoff=Math.min(this.backoff*2,i1),this.reconnectTimer=setTimeout(()=>this.connect(),e)}clearTimer(){this.reconnectTimer!==null&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}clearConnectTimer(){this.connectTimer!==null&&(clearTimeout(this.connectTimer),this.connectTimer=null)}clearStallTimer(){this.stallTimer!==null&&(clearTimeout(this.stallTimer),this.stallTimer=null)}},u1={dark:{"--color-surface-inset":`#0d0d0f`,"--color-text":`#ededef`,"--color-accent":`#4f8ef7`,"--color-accent-subtle":`#16213a`,"--color-surface-selected":`#222226`,"--color-danger":`#f06363`,"--color-success":`#46b67a`,"--color-warning":`#e2a53b`,"--color-accent-text":`#7aaafa`},light:{"--color-surface-inset":`#f7f7f8`,"--color-text":`#18181b`,"--color-accent":`#2f6fe4`,"--color-accent-subtle":`#ecf2fe`,"--color-surface-selected":`#eaeaed`,"--color-danger":`#c42828`,"--color-success":`#1e8e53`,"--color-warning":`#a86a06`,"--color-accent-text":`#2463d6`}},d1={dark:{black:`#2a2a2f`,magenta:`#c68af0`,cyan:`#56c2d6`,white:`#d4d4d8`,brightBlack:`#6b6b74`,brightRed:`#ff8a8a`,brightGreen:`#72d49c`,brightYellow:`#f2c46e`,brightMagenta:`#d9a9f7`,brightCyan:`#86dbe8`,brightWhite:`#fafafa`},light:{black:`#18181b`,magenta:`#9337be`,cyan:`#0e7488`,white:`#52525b`,brightBlack:`#71717a`,brightRed:`#d63a3a`,brightGreen:`#1f9a5a`,brightYellow:`#b57308`,brightMagenta:`#a64ccf`,brightCyan:`#128399`,brightWhite:`#27272a`}};function f1(e){let t=typeof document>`u`?null:getComputedStyle(document.documentElement);return n=>t?.getPropertyValue(n).trim()||u1[e][n]||``}function p1(e,t=f1(e)){let n=t(`--color-surface-inset`);return{background:n,foreground:t(`--color-text`),cursor:t(`--color-accent`),cursorAccent:n,selectionBackground:t(`--color-accent-subtle`),selectionInactiveBackground:t(`--color-surface-selected`),red:t(`--color-danger`),green:t(`--color-success`),yellow:t(`--color-warning`),blue:t(`--color-accent`),brightBlue:t(`--color-accent-text`),...d1[e]}}function m1(e){return e.key===`v`||e.key===`V`||e.code===`KeyV`}function h1(e){let t=e.type===`keydown`;if(!t&&e.type!==`keypress`)return{intercept:!1};if(e.key===`Enter`&&(e.shiftKey||e.ctrlKey))return{intercept:!0,bytes:t?`\x1B\r`:``};if(Nb(e))return{intercept:!0,bytes:``};if(m1(e)&&!e.shiftKey&&!e.metaKey){if(e.ctrlKey&&!e.altKey)return{intercept:!0,bytes:``};if(e.altKey&&!e.ctrlKey)return{intercept:!0,bytes:t?`\x1Bv`:``}}return{intercept:!1}}var g1=`"Geist Mono Variable", "Cascadia Code", Consolas, monospace`;function _1({sessionId:e,wsBase:t,onEnded:n}){let r=(0,L.useRef)(null),[i,a]=(0,L.useState)(`connecting`),o=(0,L.useRef)(n);o.current=n;let{resolved:s}=nM(),c=(0,L.useRef)(s);c.current=s;let l=(0,L.useRef)(null);(0,L.useEffect)(()=>{let e=l.current;e&&(e.options.theme=p1(s))},[s]),(0,L.useEffect)(()=>{let n=r.current;if(!n)return;let i=new n1({theme:p1(c.current),fontFamily:g1,fontSize:12.5,lineHeight:1.2,cursorBlink:!0,allowProposedApi:!0,scrollback:5e3});l.current=i;let s=new BG;i.loadAddon(s),i.open(n);let u=()=>{try{s.fit()}catch{}};u();let d=requestAnimationFrame(u),f=!1;typeof document<`u`&&document.fonts?.check?.(`12px ${g1}`)||document.fonts?.load(`12px ${g1}`).then(()=>{f||(i.options.fontFamily=`monospace`,i.options.fontFamily=g1,u())});let p;p=new l1({sessionId:e,wsBase:t,onData:e=>i.write(e),onReset:()=>i.reset(),onStatus:e=>{a(e),e===`live`&&p.resize(i.cols,i.rows),e===`ended`&&o.current?.()}});let m=i.onData(e=>p.send(e)),h=i.onResize(({cols:e,rows:t})=>p.resize(e,t));i.attachCustomKeyEventHandler(e=>{let t=h1(e);return t.intercept?(t.bytes&&p.send(t.bytes),!1):!0}),p.connect();let g=new ResizeObserver(()=>u());return g.observe(n),()=>{f=!0,l.current=null,cancelAnimationFrame(d),g.disconnect(),m.dispose(),h.dispose(),p.dispose(),i.dispose()}},[e,t]);let u=i===`connecting`?{text:`Connecting…`,tone:`dim`}:i===`reconnecting`?{text:`Disconnected — reconnecting… keystrokes are dropped until the stream is back`,tone:`down`}:i===`ended`?{text:`Session stream ended — relaunch or end the session above`,tone:`dim`}:null;return(0,R.jsxs)(`div`,{className:q(`relative box-border h-full w-full overflow-hidden bg-surface-inset pt-2 pr-0.5 pb-1.5 pl-2.5`,`[&_.xterm-viewport]:bg-transparent!`),children:[(0,R.jsx)(`div`,{ref:r,className:`h-full w-full`,"data-session-id":e}),u&&(0,R.jsx)(`div`,{role:`status`,className:q(`pointer-events-none absolute inset-x-0 top-0 px-2.5 py-1 text-xs animate-fade-in`,u.tone===`down`?`bg-danger-subtle text-danger`:`border-b border-border-subtle bg-surface-inset text-text-tertiary`),children:u.text})]})}function v1(e,t){if(!e)return null;let n=Wv(e,t);if(n.kind===`notDone`)return null;if(n.kind===`mapComplete`)return`Map complete — every waypoint is done. Converge from the bar above.`;let r=n.waypoint.status===`dropped`?`Dropped`:`Resolved`;return n.kind===`awaitingResearch`?`${r} — waiting on ${n.claimed} research run${n.claimed===1?``:`s`}`:`${r}${n.waypoint.summary?` — ${n.waypoint.summary}`:``}`}function y1({session:e,full:t,right:n,className:r}){let i=e.ccSessionId??e.id,a=v1(t,e),o=e.status!==`ended`;return(0,R.jsxs)(`div`,{className:q(`flex min-h-10 min-w-0 items-center gap-3 text-sm`,r),title:i,children:[(0,R.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-2 font-medium text-text`,children:[(0,R.jsx)(Dy,{size:16,className:`text-icon`}),Qv(e),` session`]}),a?(0,R.jsx)(rA,{tone:`success`,icon:(0,R.jsx)(by,{}),className:`min-w-0 flex-1`,title:a,children:a}):o?(0,R.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:[(0,R.jsx)(rA,{tone:e.status===`launching`?`warning`:`live`,children:e.status===`launching`?`Starting…`:`Live`}),e.createdAt&&(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary tabular-nums`,children:mh(e.createdAt,Date.now())})]}):(0,R.jsxs)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-text-tertiary`,children:[`Ended`,e.endedAt===void 0?``:` ${ph(e.endedAt)}`]}),n&&(0,R.jsx)(`span`,{className:`flex shrink-0 items-center gap-1`,children:n})]})}function b1({featureId:e,sessions:t,full:n,className:r,right:i,fill:a=!1}){let o=E1(t);return o?Ag(o)?(0,R.jsxs)(`section`,{"aria-label":`Session`,className:q(`flex min-h-0 flex-1 flex-col animate-fade-in`,r),children:[(0,R.jsx)(y1,{session:o,full:n,right:(0,R.jsxs)(R.Fragment,{children:[i,(0,R.jsx)(IG,{featureId:e,sessionId:o.id})]})}),(0,R.jsx)(x1,{featureId:e,session:o}),(0,R.jsx)(`div`,{className:`mt-1 min-h-0 flex-1 overflow-hidden rounded-md border border-border bg-surface-inset`,id:`session-terminal`,children:(0,R.jsx)(LG,{label:`terminal`,children:(0,R.jsx)(_1,{sessionId:o.id})})})]}):a?(0,R.jsxs)(`section`,{"aria-label":`Session`,className:q(`flex min-h-0 flex-1 flex-col`,r),children:[(0,R.jsx)(y1,{session:o,full:n}),(0,R.jsx)(`div`,{className:`mt-1 flex min-h-0 flex-1 items-center justify-center rounded-md bg-surface-inset`,children:(0,R.jsx)(GA,{icon:(0,R.jsx)(Dy,{}),title:`The session has ended`,hint:`Pick it back up from the next step above — the conversation is still on disk.`})})]}):(0,R.jsx)(y1,{session:o,full:n,className:`mb-6`}):null}function x1({featureId:e,session:t}){let n=pF(e);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(C1,{session:t,events:n}),(0,R.jsx)(T1,{session:t,notReady:kg(n,t.id)})]})}var S1=5e3;function C1({session:e,events:t}){return Og(e,t,w1(S1))?(0,R.jsx)(`p`,{className:`m-0 pb-1.5 text-xs text-text-tertiary animate-fade-in`,children:`The agent hasn’t checked in yet.`}):null}function w1(e){let[t,n]=(0,L.useState)(()=>Date.now());return(0,L.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function T1({session:e,notReady:t}){return t?(0,R.jsxs)(`div`,{className:`flex items-start gap-1.5 pb-2 text-sm text-text-secondary animate-fade-in`,role:`status`,children:[(0,R.jsx)(rA,{tone:`warning`,icon:(0,R.jsx)(tb,{}),size:`sm`,strong:!0,className:`shrink-0`,children:`Not ready`}),(0,R.jsxs)(`span`,{className:`min-w-0`,children:[`— `,k_(e),` has not started on its briefing. Answer anything waiting in the terminal (a trust or login prompt).`]})]}):null}function E1(e){let t=[...e].reverse();return t.find(Ag)??t[0]}function D1({docs:e,value:t,onPick:n,className:r}){let i=t?.split(/[\\/]/).pop()??`Docs`;return(0,R.jsxs)(DP,{children:[(0,R.jsx)(OP,{asChild:!0,children:(0,R.jsxs)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(ky,{}),className:q(`max-w-56`,r),"aria-label":t?`Docs — showing ${i}`:`Docs`,children:[(0,R.jsx)(`span`,{className:q(`truncate`,t&&`font-mono`),children:i}),(0,R.jsx)(wy,{size:12,className:`shrink-0 text-icon`})]})}),(0,R.jsx)(kP,{align:`end`,className:`min-w-52`,children:e.map(e=>(0,R.jsx)(AP,{icon:e.relPath===t?(0,R.jsx)(by,{}):(0,R.jsx)(ky,{}),"aria-current":e.relPath===t?`true`:void 0,onSelect:()=>n(e.relPath),children:e.title||e.relPath.split(/[\\/]/).pop()},e.relPath))})]})}function O1({featureId:e,kind:t,docs:n,collapsed:r=!1,onToggle:i,mapped:a=!1,mode:o=`live`,children:s}){let c=n.find(e=>e.relPath.endsWith(`${t}.md`))?.relPath,[l,u]=(0,L.useState)(c),[d,f]=(0,L.useState)(!1),p=(0,L.useRef)(void 0),m=o===`static`;(0,L.useEffect)(()=>u(c),[t,c]);let h=gF(e,l,{live:!m}),g=h.content??``;(0,L.useEffect)(()=>{if(h.content!==void 0){if(p.current!==void 0&&p.current!==g&&t===`spec`){f(!0);let e=window.setTimeout(()=>f(!1),3e3);return p.current=g,()=>window.clearTimeout(e)}p.current=g}},[g,h.content,t]);let _=_g(g);if(r&&i)return(0,R.jsxs)(`div`,{className:`flex w-9 flex-none flex-col items-center gap-2 pt-0.5`,children:[(0,R.jsx)(nE,{label:`Expand the ${t} pane`,icon:(0,R.jsx)(Gy,{}),onClick:i,tooltipSide:`right`}),(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary tabular-nums [writing-mode:vertical-rl]`,children:t===`decisions`?`${_} decisions`:`Spec`})]});let v=m||l===c,y=t===`spec`?`Spec`:m?`Decisions`:`Decisions so far`,b=(0,R.jsxs)(R.Fragment,{children:[h.loading&&(0,R.jsx)(UA,{children:`Loading…`}),h.failed&&(0,R.jsxs)(WA,{children:[`Could not read `,l]}),g?(0,R.jsx)(PG,{source:g,size:m?`base`:`sm`}):v?(0,R.jsx)(k1,{kind:t,mapped:a,frozen:m}):null,s]});return m?(0,R.jsx)(IA,{title:y,action:(0,R.jsxs)(`span`,{className:`font-mono text-xs text-text-tertiary`,children:[t,`.md`,t===`decisions`&&_>0?` · ${_}`:``]}),children:b}):(0,R.jsxs)(`section`,{"aria-label":v?y:l,className:`flex min-h-0 w-(--artifact-w) flex-none flex-col`,children:[(0,R.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center gap-2`,children:[(0,R.jsx)(`h2`,{className:`m-0 min-w-0 truncate text-sm font-medium text-text`,children:v?y:l?.split(/[\\/]/).pop()}),v&&t===`decisions`&&(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary tabular-nums`,children:_}),v&&t===`spec`&&d&&(0,R.jsx)(rA,{tone:`live`,className:`animate-fade-in`,children:`Updating`}),(0,R.jsxs)(`span`,{className:`ml-auto flex items-center gap-0.5`,children:[(0,R.jsx)(D1,{docs:n,value:l,onPick:u}),i&&(0,R.jsx)(nE,{label:`Collapse the ${t} pane`,size:`sm`,icon:(0,R.jsx)(Gy,{}),onClick:i})]})]}),(0,R.jsx)(`div`,{className:`mt-2 min-h-0 flex-1 overflow-y-auto border-t border-border-subtle pt-4 pr-3`,children:b})]})}function k1({kind:e,mapped:t,frozen:n}){return n?(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(ky,{}),title:e===`decisions`?`No decisions were recorded`:`No spec`,hint:`This feature was created as a quick change and skipped ideation.`}):(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(ky,{}),title:e===`decisions`?`No decisions yet`:`No spec yet`,hint:e===`decisions`?`They land here one by one as the session settles them.`:t?`The converge session writes it here from the map and the decisions.`:`The session is drafting the spec — it appears here as it's written.`})}function A1({featureId:e,relPath:t,title:n,onClose:r,returnFocusRef:i}){let a=B.docs.read.useQuery({featureId:e,relPath:t});return(0,R.jsxs)(QA,{open:!0,onClose:r,labelledBy:`doc-peek-title`,size:`lg`,returnFocusRef:i,className:`flex max-h-[84vh] flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`flex h-(--topbar-h) shrink-0 items-center gap-2 border-b border-border-subtle pr-2 pl-5`,children:[(0,R.jsx)(ky,{size:16,className:`shrink-0 text-icon`}),(0,R.jsx)(`h2`,{id:`doc-peek-title`,className:`m-0 min-w-0 truncate text-sm font-medium text-text`,children:n||t.split(/[\\/]/).pop()}),(0,R.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-text-tertiary`,title:t,children:t}),(0,R.jsx)(nE,{label:`Close`,size:`sm`,icon:(0,R.jsx)(xy,{}),onClick:r})]}),(0,R.jsx)(`div`,{className:`min-h-0 overflow-y-auto px-10 pt-8 pb-12`,children:(0,R.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[a.isLoading&&(0,R.jsxs)(WA,{children:[`Loading `,n,`…`]}),a.error&&(0,R.jsxs)(WA,{children:[`Could not read `,t,`: `,a.error.message]}),a.data&&(0,R.jsx)(PG,{source:ch(a.data.content),size:`base`})]})})]})}var j1={ready:`accent`,working:`live`,waiting:`neutral`,done:`success`};function M1({featureId:e,group:t,item:n,blocker:r,readonly:i=!1}){let a=n.waypoint,[o,s]=(0,L.useState)(n.openByDefault),[c,l]=(0,L.useState)(!1),u=B.useUtils(),d=Ab(),f=a.type===`research`,p=!f&&!!a.lastSessionId,m=a.claimedBy?.startsWith(`run_`)??!1,h=i||o,g=B.feature.workWaypoint.useMutation({onSuccess:()=>{l(!1),u.feature.get.invalidate({id:e}),u.feature.list.invalidate()},onError:(e,t)=>{!f&&!t.endLive&&r&&e.data?.code===`PRECONDITION_FAILED`?l(!0):(l(!1),d.push(e.message))}}),_=(0,R.jsxs)(R.Fragment,{children:[!i&&(0,R.jsx)(Ty,{size:12,className:q(`shrink-0 text-icon transition-transform duration-(--dur-2) ease-app`,h&&`rotate-90`)}),(0,R.jsx)(`span`,{className:`inline-flex size-4 shrink-0 items-center justify-center`,children:(0,R.jsx)(tA,{tone:j1[t]})}),(0,R.jsx)(`span`,{className:q(`min-w-0 flex-1 truncate text-sm`,t===`done`?`text-text-secondary`:`font-medium text-text`),children:a.title}),(0,R.jsx)(`span`,{className:`shrink-0 text-xs text-text-tertiary`,children:n.stateWord})]});return(0,R.jsxs)(`div`,{className:`rounded-md`,children:[i?(0,R.jsx)(`div`,{className:`flex min-h-8 items-center gap-2 px-2`,children:_}):(0,R.jsx)(`button`,{type:`button`,className:`flex min-h-8 w-full cursor-pointer items-center gap-2 rounded-md bg-transparent px-2 text-left transition-colors duration-(--dur-1) ease-app hover:bg-surface-hover`,"aria-expanded":h,title:h?`Collapse this waypoint`:`Expand this waypoint`,onClick:()=>s(e=>!e),children:_}),h&&(0,R.jsxs)(`div`,{className:q(`pr-2 pb-3 text-sm animate-fade-in`,i?`pl-8`:`pl-[3.25rem]`),children:[(0,R.jsx)(PG,{source:a.question}),t===`working`&&m&&(0,R.jsx)(`div`,{className:`mt-2 text-xs text-text-tertiary`,children:`Researching…`}),t===`done`&&a.summary&&(0,R.jsx)(PG,{source:a.summary,tone:`tertiary`,className:`mt-2`}),(0,R.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-text-tertiary`,children:[(0,R.jsx)(`span`,{className:`font-mono`,children:a.type}),n.originTitle&&(0,R.jsxs)(`span`,{children:[`Surfaced by `,n.originTitle]})]}),!i&&t===`ready`&&(0,R.jsxs)(`div`,{className:`mt-3 flex items-center gap-2`,children:[(0,R.jsx)(Y,{size:`sm`,icon:p?(0,R.jsx)(ab,{}):(0,R.jsx)(Ly,{}),disabled:g.isPending,title:f?`Start an unattended research run on this waypoint`:p?`Resume the previous session on this waypoint`:`Claim this waypoint and open a session`,onClick:()=>g.mutate({featureId:e,waypointId:a.id}),children:p?`Resume`:`Work`}),f&&(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary`,children:`Runs unattended`})]}),!i&&c&&r&&(0,R.jsxs)(`div`,{className:`mt-3 rounded-md bg-danger-subtle px-3 py-2`,role:`alert`,children:[(0,R.jsx)(`div`,{className:`text-xs text-text-secondary`,children:r.waypointTitle?(0,R.jsxs)(R.Fragment,{children:[`A session is live on `,(0,R.jsx)(`b`,{className:`font-medium text-text`,children:r.waypointTitle}),` and its waypoint is still open. End it and work this instead?`]}):(0,R.jsxs)(R.Fragment,{children:[`A `,r.kind,` session is live on this feature. End it and work this instead?`]})}),(0,R.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,R.jsx)(Y,{size:`sm`,variant:`danger`,disabled:g.isPending,onClick:()=>g.mutate({featureId:e,waypointId:a.id,endLive:!0}),children:`End & work this`}),(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>l(!1),children:`Cancel`})]})]})]})]})}var N1=[`Destination`,`Notes`,`Not yet specified`,`Out of scope`];function P1({full:e,relPath:t,collapsed:n,onToggle:r,readonly:i=!1,layout:a=`rail`}){let o=e.feature.id,[s,c]=(0,L.useState)(),l=B.docs.read.useQuery({featureId:o,relPath:t??`map.md`},{enabled:!!t}),u=l.data?x_(l.data.content):{},d=E_(e.waypoints,e.frontierIds,i),f=T_(e.waypoints,e.frontierIds),p=!!t||e.waypoints.length>0,m=a===`rail`,h=`${f.done}/${f.total} done`;if(m&&n)return(0,R.jsxs)(`div`,{className:`flex w-9 flex-none flex-col items-center gap-2 pt-0.5`,children:[(0,R.jsx)(nE,{label:`Expand the map`,icon:(0,R.jsx)(Gy,{}),onClick:r,tooltipSide:`right`}),(0,R.jsxs)(`span`,{className:`text-xs text-text-tertiary tabular-nums`,children:[f.done,`/`,f.total]}),(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary [writing-mode:vertical-rl]`,children:`Map`})]});let g=(0,R.jsxs)(R.Fragment,{children:[l.isLoading&&(0,R.jsx)(WA,{children:`Loading the map…`}),p?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(I1,{featureId:o,groups:d,blocker:Gv(e.sessions,e.waypoints),readonly:i}),t&&(0,R.jsx)(F1,{sections:u})]}):(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(ky,{}),title:`Not charted yet`,hint:`The session writes the map as you explore the idea.`})]});return(0,R.jsxs)(`section`,{"aria-label":`Map`,className:q(`flex min-h-0 flex-col`,m?`w-(--maprail-w) flex-none`:`min-w-0`),children:[m?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center gap-2`,children:[(0,R.jsx)(`h2`,{className:`m-0 text-sm font-medium text-text`,children:`Map`}),(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary tabular-nums`,"aria-label":`${f.done} of ${f.total} waypoints done`,children:h}),(0,R.jsx)(nE,{label:A_,size:`sm`,icon:(0,R.jsx)(nb,{}),className:`-ml-1`}),(0,R.jsxs)(`span`,{className:`ml-auto flex items-center gap-0.5`,children:[(0,R.jsx)(D1,{docs:e.docs,value:t,onPick:c}),(0,R.jsx)(nE,{label:`Collapse the map`,size:`sm`,icon:(0,R.jsx)(Gy,{}),onClick:r})]})]}),(0,R.jsx)(`div`,{className:`mt-2 min-h-0 flex-1 overflow-y-auto pr-2`,children:g})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{className:`mt-0 mb-3 text-xs text-text-tertiary`,children:h}),g]}),s&&s!==t&&(0,R.jsx)(A1,{featureId:o,relPath:s,title:e.docs.find(e=>e.relPath===s)?.title||s.split(/[\\/]/).pop()||`Document`,onClose:()=>c(void 0)})]})}function F1({sections:e}){let t=N1.filter(t=>(e[t]?.trim()??``)!==``);return(0,R.jsx)(JA,{title:`Map document`,icon:(0,R.jsx)(ky,{}),className:`mt-4`,bodyClassName:`pl-6 pr-1`,children:t.length===0?(0,R.jsx)(WA,{children:`Nothing written yet — the session fills this in as it explores the idea.`}):t.map(t=>(0,R.jsxs)(`section`,{className:`mt-3 first:mt-0`,children:[(0,R.jsx)(`div`,{className:`mb-1 text-xs font-medium text-text-tertiary`,children:t}),(0,R.jsx)(PG,{source:e[t].trim()})]},t))})}function I1({featureId:e,groups:t,blocker:n,readonly:r}){return t.length===0?(0,R.jsx)(WA,{children:`No waypoints yet — they appear here as the map takes shape.`}):(0,R.jsx)(`div`,{className:`flex flex-col gap-3`,children:t.map(t=>{let i=(0,R.jsx)(`div`,{className:`flex flex-col`,children:t.waypoints.map(i=>(0,R.jsx)(M1,{featureId:e,group:t.key,item:i,blocker:n,readonly:r},i.waypoint.id))});return t.key===`done`&&!r?(0,R.jsx)(JA,{title:t.label,aside:t.waypoints.length,children:i},t.key):(0,R.jsxs)(`section`,{children:[(0,R.jsx)(mA,{count:t.waypoints.length,className:`px-2`,children:t.label}),i]},t.key)})})}function L1({full:e,effective:t,chatDocked:n=!1,mapRailCollapsed:r,onToggleMapRail:i,artifactPaneCollapsed:a,onToggleArtifactPane:o}){let s=e.docs.some(e=>e.relPath.endsWith(`spec.md`))?`spec`:`decisions`,c=qv(e.sessions,n);return(0,R.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-1 gap-6`,children:[e.feature.mapped&&t===`planning`?(0,R.jsx)(P1,{full:e,relPath:b_(e),collapsed:r,onToggle:i}):(0,R.jsx)(O1,{featureId:e.feature.id,kind:s,docs:e.docs,collapsed:a,onToggle:o,mapped:e.feature.mapped}),(0,R.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:c.length>0?(0,R.jsx)(b1,{featureId:e.feature.id,sessions:c,full:e,fill:!0}):(0,R.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center rounded-lg bg-surface-inset`,children:c.length<e.sessions.length?(0,R.jsx)(GA,{icon:(0,R.jsx)(Dy,{}),title:`The chat is in the aside`,hint:`The conversation is open on the right — close it to bring the terminal back here.`}):(0,R.jsx)(GA,{icon:(0,R.jsx)(Dy,{}),title:`No session yet`,hint:`Start a session from the next step above — you and the agent shape the idea here before any code is written.`})})})]})}var R1=Object.defineProperty,z1=(e,t)=>R1(e,`name`,{value:t,configurable:!0});function B1(e,[t,n]){return Math.min(n,Math.max(t,e))}z1(B1,`clamp`);var V1=Object.defineProperty,H1=(e,t)=>V1(e,`name`,{value:t,configurable:!0});function U1(e){let t=L.useRef({value:e,previous:e});return L.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}H1(U1,`usePrevious`);var W1=Object.defineProperty,G1=(e,t)=>W1(e,`name`,{value:t,configurable:!0}),K1=[` `,`Enter`,`ArrowUp`,`ArrowDown`],q1=[` `,`Enter`],J1=`Select`,[Y1,X1,Z1]=aM(J1),[Q1,$1]=sx(J1,[Z1,hw]),e0=hw(),[t0,n0]=Q1(J1),[r0,i0]=Q1(J1);function a0(e){let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:a,value:o,defaultValue:s,onValueChange:c,dir:l,name:u,autoComplete:d,disabled:f,required:p,form:m,internal_do_not_use_render:h}=e,g=e0(t),[_,v]=L.useState(null),[y,b]=L.useState(null),[x,S]=L.useState(!1),C=yM(l),[w,T]=Xw({prop:r,defaultProp:i??!1,onChange:a,caller:J1}),[E,D]=Xw({prop:o,defaultProp:s,onChange:c,caller:J1}),O=L.useRef(null),k=L.useRef(E);L.useEffect(()=>{let e=m?_?.ownerDocument.getElementById(m):_?.form;if(e instanceof HTMLFormElement){let t=G1(()=>D(k.current),`reset`);return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)}},[m,_,D]);let A=!_||!!m||!!_.closest(`form`),[j,M]=L.useState(new Set),N=Xx(),P=Array.from(j).map(e=>e.props.value).join(`;`),F=L.useCallback(e=>{M(t=>new Set(t).add(e))},[]),ee=L.useCallback(e=>{M(t=>{let n=new Set(t);return n.delete(e),n})},[]),te={required:p,trigger:_,onTriggerChange:v,valueNode:y,onValueNodeChange:b,valueNodeHasChildren:x,onValueNodeHasChildrenChange:S,contentId:N,value:E,onValueChange:D,open:w,onOpenChange:T,dir:C,triggerPointerDownPosRef:O,disabled:f,name:u,autoComplete:d,form:m,nativeOptions:j,nativeSelectKey:P,isFormControl:A};return(0,R.jsx)(Ow,{...g,children:(0,R.jsx)(t0,{scope:t,...te,children:(0,R.jsx)(Y1.Provider,{scope:t,children:(0,R.jsx)(r0,{scope:t,onNativeOptionAdd:F,onNativeOptionRemove:ee,children:W0(h)?h(te):n})})})})}G1(a0,`SelectProvider`);var o0=G1(e=>{let{__scopeSelect:t,children:n,...r}=e;return(0,R.jsx)(a0,{__scopeSelect:t,...r,internal_do_not_use_render:({isFormControl:e})=>(0,R.jsxs)(R.Fragment,{children:[n,e?(0,R.jsx)(U0,{__scopeSelect:t}):null]})})},`Select`),s0=`SelectTrigger`,c0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,disabled:r=!1,...i}=e,a=e0(n),o=n0(s0,n),s=o.disabled||r,c=rx(t,o.onTriggerChange),l=X1(n),u=L.useRef(`touch`),[d,f,p]=K0(e=>{let t=l().filter(e=>!e.disabled),n=q0(t,e,t.find(e=>e.value===o.value));n!==void 0&&o.onValueChange(n.value)}),m=G1(e=>{s||(o.onOpenChange(!0),p()),e&&(o.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})},`handleOpen`);return(0,R.jsx)(kw,{asChild:!0,...a,children:(0,R.jsx)(Ex.button,{type:`button`,role:`combobox`,"aria-controls":o.open?o.contentId:void 0,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":`none`,dir:o.dir,"data-state":o.open?`open`:`closed`,disabled:s,"data-disabled":s?``:void 0,"data-placeholder":G0(o.value)?``:void 0,...i,ref:c,onClick:J(i.onClick,e=>{e.currentTarget.focus(),u.current!==`mouse`&&m(e)}),onPointerDown:J(i.onPointerDown,e=>{u.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),e.button===0&&e.ctrlKey===!1&&e.pointerType===`mouse`&&(m(e),e.preventDefault())}),onKeyDown:J(i.onKeyDown,e=>{let t=d.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&f(e.key),!(t&&e.key===` `)&&K1.includes(e.key)&&(m(),e.preventDefault())})})})},`SelectTrigger`)),l0=`SelectValue`,u0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,className:r,style:i,children:a,placeholder:o=``,...s}=e,c=n0(l0,n),{onValueNodeHasChildrenChange:l}=c,u=a!==void 0,d=rx(t,c.onValueNodeChange);Gx(()=>{l(u)},[l,u]);let f=G0(c.value);return(0,R.jsx)(Ex.span,{...s,asChild:!f&&s.asChild,ref:d,style:{pointerEvents:`none`},children:(0,R.jsx)(L.Fragment,{children:f?o:a},f?`placeholder`:`value`)})},`SelectValue`)),d0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,children:r,...i}=e;return(0,R.jsx)(Ex.span,{"aria-hidden":!0,...i,ref:t,children:r||`▼`})},`SelectIcon`)),[f0,p0]=Q1(`SelectPortal`,{forceMount:void 0}),m0=G1(e=>{let{__scopeSelect:t,forceMount:n,...r}=e;return(0,R.jsx)(f0,{scope:e.__scopeSelect,forceMount:n,children:(0,R.jsx)(Mw,{asChild:!0,...r})})},`SelectPortal`),h0=`SelectContent`,g0=L.forwardRef(G1(function(e,t){let n=p0(h0,e.__scopeSelect),{forceMount:r=n.forceMount,...i}=e,a=n0(h0,e.__scopeSelect),[o,s]=L.useState();return Gx(()=>{s(new DocumentFragment)},[]),(0,R.jsx)(Iw,{present:r||a.open,children:({present:e})=>e?(0,R.jsx)(S0,{...i,ref:t}):(0,R.jsx)(_0,{...i,fragment:o})})},`SelectContent`)),_0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,children:r,fragment:i}=e;return i?Rb.createPortal((0,R.jsx)(y0,{scope:n,children:(0,R.jsx)(Y1.Slot,{scope:n,children:(0,R.jsx)(`div`,{ref:t,children:r})})}),i):null},`SelectContentFragment`)),v0=10,[y0,b0]=Q1(h0),x0=dx(`SelectContent.RemoveScroll`),S0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n}=e,{position:r=`item-aligned`,onCloseAutoFocus:i,onEscapeKeyDown:a,onPointerDownOutside:o,side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g,..._}=e,v=n0(h0,n),[y,b]=L.useState(null),[x,S]=L.useState(null),C=rx(t,b),[w,T]=L.useState(null),[E,D]=L.useState(null),O=X1(n),[k,A]=L.useState(!1),j=L.useRef(!1);L.useEffect(()=>{if(y)return uO(y)},[y]),GE();let M=L.useCallback(e=>{let[t,...n]=O().map(e=>e.ref.current),[r]=n.slice(-1),i=document.activeElement;for(let n of e)if(n===i||(n?.scrollIntoView({block:`nearest`}),n===t&&x&&(x.scrollTop=0),n===r&&x&&(x.scrollTop=x.scrollHeight),n?.focus(),document.activeElement!==i))return},[O,x]),N=L.useCallback(()=>M([w,y]),[M,w,y]);L.useEffect(()=>{k&&N()},[k,N]);let{onOpenChange:P,triggerPointerDownPosRef:F}=v;L.useEffect(()=>{if(y){let e={x:0,y:0},t=G1(t=>{e={x:Math.abs(Math.round(t.pageX)-(F.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(F.current?.y??0))}},`handlePointerMove`),n=G1(n=>{e.x<=10&&e.y<=10?n.preventDefault():n.composedPath().includes(y)||P(!1),document.removeEventListener(`pointermove`,t),F.current=null},`handlePointerUp`);return F.current!==null&&(document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,n,{capture:!0,once:!0})),()=>{document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,n,{capture:!0})}}},[y,P,F]),L.useEffect(()=>{let e=G1(()=>P(!1),`close`);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[P]);let[ee,te]=K0(e=>{let t=O().filter(e=>!e.disabled),n=q0(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current?.focus())}),ne=L.useCallback((e,t,n)=>{let r=!j.current&&!n;(v.value!==void 0&&v.value===t||r)&&(T(e),r&&(j.current=!0))},[v.value]),I=L.useCallback(()=>y?.focus(),[y]),re=L.useCallback((e,t,n)=>{let r=!j.current&&!n;(v.value!==void 0&&v.value===t||r)&&D(e)},[v.value]),ie=r===`popper`?w0:C0,ae=ie===w0?{side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g}:{};return(0,R.jsx)(y0,{scope:n,content:y,viewport:x,onViewportChange:S,itemRefCallback:ne,selectedItem:w,onItemLeave:I,itemTextRefCallback:re,focusSelectedItem:N,selectedItemText:E,position:r,isPositioned:k,searchRef:ee,children:(0,R.jsx)(tO,{as:x0,allowPinchZoom:!0,children:(0,R.jsx)(OE,{asChild:!0,trapped:v.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:J(i,e=>{v.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,R.jsx)(Rx,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>v.onOpenChange(!1),children:(0,R.jsx)(ie,{role:`listbox`,id:v.contentId,"data-state":v.open?`open`:`closed`,dir:v.dir,onContextMenu:e=>e.preventDefault(),..._,...ae,onPlaced:()=>A(!0),ref:C,style:{display:`flex`,flexDirection:`column`,outline:`none`,..._.style},onKeyDown:J(_.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&te(e.key),[`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(e.key)){let t=O().filter(e=>!e.disabled).map(e=>e.ref.current);if([`ArrowUp`,`End`].includes(e.key)&&(t=t.slice().reverse()),[`ArrowUp`,`ArrowDown`].includes(e.key)){let n=e.target,r=t.indexOf(n);t=t.slice(r+1)}setTimeout(()=>M(t)),e.preventDefault()}})})})})})})},`SelectContentImpl`)),C0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,onPlaced:r,...i}=e,a=n0(h0,n),o=b0(h0,n),[s,c]=L.useState(null),[l,u]=L.useState(null),d=rx(t,u),f=X1(n),p=L.useRef(!1),m=L.useRef(!0),{viewport:h,selectedItem:g,selectedItemText:_,focusSelectedItem:v}=o,y=L.useCallback(()=>{if(a.trigger&&a.valueNode&&s&&l&&h&&g&&_){let e=a.trigger.getBoundingClientRect(),t=l.getBoundingClientRect(),n=a.valueNode.getBoundingClientRect(),i=_.getBoundingClientRect();if(a.dir!==`rtl`){let r=i.left-t.left,a=n.left-r,o=e.left-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-v0,d=B1(a,[v0,Math.max(v0,u-l)]);s.style.minWidth=c+`px`,s.style.left=d+`px`}else{let r=t.right-i.right,a=window.innerWidth-n.right-r,o=window.innerWidth-e.right-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-v0,d=B1(a,[v0,Math.max(v0,u-l)]);s.style.minWidth=c+`px`,s.style.right=d+`px`}let o=f(),c=window.innerHeight-v0*2,u=h.scrollHeight,d=window.getComputedStyle(l),m=parseInt(d.borderTopWidth,10),v=parseInt(d.paddingTop,10),y=parseInt(d.borderBottomWidth,10),b=parseInt(d.paddingBottom,10),x=m+v+u+b+y,S=Math.min(g.offsetHeight*5,x),C=window.getComputedStyle(h),w=parseInt(C.paddingTop,10),T=parseInt(C.paddingBottom,10),E=e.top+e.height/2-v0,D=c-E,O=g.offsetHeight/2,k=g.offsetTop+O,A=m+v+k,j=x-A;if(A<=E){let e=o.length>0&&g===o[o.length-1].ref.current;s.style.bottom=`0px`;let t=l.clientHeight-h.offsetTop-h.offsetHeight,n=A+Math.max(D,O+(e?T:0)+t+y);s.style.height=n+`px`}else{let e=o.length>0&&g===o[0].ref.current;s.style.top=`0px`;let t=Math.max(E,m+h.offsetTop+(e?w:0)+O)+j;s.style.height=t+`px`,h.scrollTop=A-E+h.offsetTop}s.style.margin=`${v0}px 0`,s.style.minHeight=S+`px`,s.style.maxHeight=c+`px`,r?.(),requestAnimationFrame(()=>p.current=!0)}},[f,a.trigger,a.valueNode,s,l,h,g,_,a.dir,r]);Gx(()=>y(),[y]);let[b,x]=L.useState();return Gx(()=>{l&&x(window.getComputedStyle(l).zIndex)},[l]),(0,R.jsx)(T0,{scope:n,contentWrapper:s,shouldExpandOnScrollRef:p,onScrollButtonChange:L.useCallback(e=>{e&&m.current===!0&&(y(),v?.(),m.current=!1)},[y,v]),children:(0,R.jsx)(`div`,{ref:c,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:b},children:(0,R.jsx)(Ex.div,{...i,ref:d,style:{boxSizing:`border-box`,maxHeight:`100%`,...i.style}})})})},`SelectItemAlignedPosition`)),w0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,align:r=`start`,collisionPadding:i=v0,...a}=e,o=e0(n);return(0,R.jsx)(Aw,{...o,...a,ref:t,align:r,collisionPadding:i,style:{boxSizing:`border-box`,...a.style,"--radix-select-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-select-content-available-width":`var(--radix-popper-available-width)`,"--radix-select-content-available-height":`var(--radix-popper-available-height)`,"--radix-select-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-select-trigger-height":`var(--radix-popper-anchor-height)`}})},`SelectPopperPosition`)),[T0,E0]=Q1(h0,{}),D0=`SelectViewport`,O0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,nonce:r,...i}=e,a=b0(D0,n),o=E0(D0,n),s=rx(t,a.onViewportChange),c=L.useRef(0);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`},nonce:r}),(0,R.jsx)(Y1.Slot,{scope:n,children:(0,R.jsx)(Ex.div,{"data-radix-select-viewport":``,role:`presentation`,...i,ref:s,style:{position:`relative`,flex:1,overflow:`hidden auto`,...i.style},onScroll:J(i.onScroll,e=>{let t=e.currentTarget,{contentWrapper:n,shouldExpandOnScrollRef:r}=o;if(r?.current&&n){let e=Math.abs(c.current-t.scrollTop);if(e>0){let r=window.innerHeight-v0*2,i=parseFloat(n.style.minHeight),a=parseFloat(n.style.height),o=Math.max(i,a);if(o<r){let i=o+e,a=Math.min(r,i),s=i-a;n.style.height=a+`px`,n.style.bottom===`0px`&&(t.scrollTop=s>0?s:0,n.style.justifyContent=`flex-end`)}}}c.current=t.scrollTop})})})]})},`SelectViewport`)),[k0,A0]=Q1(`SelectGroup`),j0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,...r}=e,i=Xx();return(0,R.jsx)(k0,{scope:n,id:i,children:(0,R.jsx)(Ex.div,{role:`group`,"aria-labelledby":i,...r,ref:t})})},`SelectGroup`)),M0=`SelectLabel`,N0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,...r}=e,i=A0(M0,n);return(0,R.jsx)(Ex.div,{id:i.id,...r,ref:t})},`SelectLabel`)),P0=`SelectItem`,[F0,I0]=Q1(P0),L0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,value:r,disabled:i=!1,textValue:a,...o}=e,s=n0(P0,n),c=b0(P0,n),l=s.value===r,[u,d]=L.useState(a??``),[f,p]=L.useState(!1),m=rx(t,Ax(e=>c.itemRefCallback?.(e,r,i))),h=Xx(),g=L.useRef(`touch`),_=G1(()=>{i||(s.onValueChange(r),s.onOpenChange(!1))},`handleSelect`);return(0,R.jsx)(F0,{scope:n,value:r,disabled:i,textId:h,isSelected:l,onItemTextChange:L.useCallback(e=>{d(t=>t||(e?.textContent??``).trim())},[]),children:(0,R.jsx)(Y1.ItemSlot,{scope:n,value:r,disabled:i,textValue:u,children:(0,R.jsx)(Ex.div,{role:`option`,"aria-labelledby":h,"data-highlighted":f?``:void 0,"aria-selected":l&&f,"data-state":l?`checked`:`unchecked`,"aria-disabled":i||void 0,"data-disabled":i?``:void 0,tabIndex:i?void 0:-1,...o,ref:m,onFocus:J(o.onFocus,()=>p(!0)),onBlur:J(o.onBlur,()=>p(!1)),onClick:J(o.onClick,()=>{g.current!==`mouse`&&_()}),onPointerUp:J(o.onPointerUp,()=>{g.current===`mouse`&&_()}),onPointerDown:J(o.onPointerDown,e=>{g.current=e.pointerType}),onPointerMove:J(o.onPointerMove,e=>{g.current=e.pointerType,i?c.onItemLeave?.():g.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:J(o.onPointerLeave,e=>{e.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:J(o.onKeyDown,e=>{i||e.target!==e.currentTarget||c.searchRef?.current!==``&&e.key===` `||(q1.includes(e.key)&&_(),e.key===` `&&e.preventDefault())})})})})},`SelectItem`)),R0=`SelectItemText`,z0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,className:r,style:i,...a}=e,o=n0(R0,n),s=b0(R0,n),c=I0(R0,n),l=i0(R0,n),[u,d]=L.useState(null),f=Ax(e=>s.itemTextRefCallback?.(e,c.value,c.disabled)),p=rx(t,d,c.onItemTextChange,f),m=u?.textContent,h=L.useMemo(()=>(0,R.jsx)(`option`,{value:c.value,disabled:c.disabled,children:m},c.value),[c.disabled,c.value,m]),{onNativeOptionAdd:g,onNativeOptionRemove:_}=l;return Gx(()=>(g(h),()=>_(h)),[g,_,h]),(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(Ex.span,{id:c.textId,...a,ref:p}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren&&!G0(o.value)?Rb.createPortal(a.children,o.valueNode):null]})},`SelectItemText`)),B0=`SelectItemIndicator`,V0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,...r}=e;return I0(B0,n).isSelected?(0,R.jsx)(Ex.span,{"aria-hidden":!0,...r,ref:t}):null},`SelectItemIndicator`)),H0=`SelectBubbleInput`,U0=L.forwardRef(G1(function({__scopeSelect:e,...t},n){let r=n0(H0,e),{value:i,onValueChange:a,required:o,disabled:s,name:c,autoComplete:l,form:u}=r,{nativeOptions:d,nativeSelectKey:f}=r,p=L.useRef(null),m=rx(n,p),h=i??``,g=U1(h),_=Array.from(d).some(e=>(e.props.value??``)===``);return L.useEffect(()=>{let e=p.current;if(!e)return;let t=window.HTMLSelectElement.prototype,n=Object.getOwnPropertyDescriptor(t,`value`).set;if(g!==h&&n){let t=new Event(`change`,{bubbles:!0});n.call(e,h),e.dispatchEvent(t)}},[g,h]),(0,R.jsxs)(Ex.select,{"aria-hidden":!0,required:o,tabIndex:-1,name:c,autoComplete:l,disabled:s,form:u,onChange:e=>a(e.target.value),...t,style:{...rT,...t.style},ref:m,defaultValue:h,children:[G0(i)&&!_?(0,R.jsx)(`option`,{value:``}):null,Array.from(d)]},f)},`SelectBubbleInput`));function W0(e){return typeof e==`function`}G1(W0,`isFunction`);function G0(e){return e===``||e===void 0}G1(G0,`shouldShowPlaceholder`);function K0(e){let t=Ax(e),n=L.useRef(``),r=L.useRef(0),i=L.useCallback(e=>{let i=n.current+e;t(i),G1((function e(t){n.current=t,window.clearTimeout(r.current),t!==``&&(r.current=window.setTimeout(()=>e(``),1e3))}),`updateSearch`)(i)},[t]),a=L.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return L.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}G1(K0,`useTypeaheadSearch`);function q0(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=J0(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}G1(q0,`findNextItem`);function J0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}G1(J0,`wrapArray`);var Y0=`\0empty`,X0=e=>e===``?Y0:e,Z0=e=>e===Y0?``:e;function Q0({value:e,defaultValue:t,onValueChange:n,...r}){return(0,R.jsx)(o0,{value:e===void 0?void 0:X0(e),defaultValue:t===void 0?void 0:X0(t),onValueChange:n&&(e=>n(Z0(e))),...r})}var $0=`inline-flex min-w-0 cursor-pointer items-center justify-between gap-1.5 text-left`,e2=`h-(--control-h) rounded-md border border-border bg-surface-inset px-2.5 text-sm text-text transition-colors duration-(--dur-1) ease-app hover:border-border-strong data-[state=open]:border-accent data-placeholder:text-text-tertiary disabled:cursor-not-allowed disabled:text-text-disabled`,t2=`h-(--control-sm) rounded-md px-1.5 text-xs text-text-tertiary transition-colors duration-(--dur-1) ease-app enabled:hover:bg-surface-hover enabled:hover:text-text data-[state=open]:bg-surface-selected data-[state=open]:text-text disabled:cursor-not-allowed disabled:text-text-disabled`;function n2({className:e,children:t,...n}){return(0,R.jsxs)(c0,{className:q($0,e),...n,children:[t,(0,R.jsx)(d0,{className:`shrink-0 text-icon`,children:(0,R.jsx)(wy,{size:14})})]})}function r2({className:e,...t}){return(0,R.jsx)(`span`,{className:q(`min-w-0 flex-1 truncate text-left`,e),children:(0,R.jsx)(u0,{...t})})}function i2({className:e,position:t=`popper`,sideOffset:n=4,collisionPadding:r=8,onEscapeKeyDown:i,children:a,...o}){return(0,R.jsx)(m0,{children:(0,R.jsx)(g0,{position:t,sideOffset:n,collisionPadding:r,onEscapeKeyDown:e=>{i?.(e),e.stopPropagation()},className:q(zb,`max-h-(--radix-select-content-available-height) min-w-32`,e),...o,children:(0,R.jsx)(O0,{className:`w-full min-w-(--radix-select-trigger-width) p-1`,children:a})})})}var a2=j0;function o2({className:e,...t}){return(0,R.jsx)(N0,{className:q(Ub,e),...t})}var s2=q(Bb,Vb,`justify-between gap-3 data-[state=checked]:font-medium`);function c2({className:e,children:t,value:n,...r}){return(0,R.jsxs)(L0,{value:X0(n),className:q(s2,e),...r,children:[(0,R.jsx)(z0,{children:t}),(0,R.jsx)(V0,{className:`inline-flex shrink-0 items-center`,children:(0,R.jsx)(by,{size:14,className:`text-text!`})})]})}function l2(e){return/\bimplementer[- ]only\b/i.test(e?.note??``)}function u2({value:e,roster:t,onChange:n,disabled:r=!1,label:i,ticketKind:a}){let o=t.find(t=>t.id===e),s=a===`review`&&l2(o),c=i??(o?`${o.id} · ${Rp[o.runtime]}`:e||`default model`),l=i??`Ticket model`;return(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-col items-end gap-1`,children:[(0,R.jsxs)(Q0,{value:e,onValueChange:n,children:[(0,R.jsx)(n2,{"aria-label":l,disabled:r,className:q(t2,`max-w-64 font-mono`),children:(0,R.jsx)(r2,{children:c})}),(0,R.jsxs)(i2,{"aria-label":l,className:`min-w-64 font-mono text-xs`,children:[(0,R.jsx)(c2,{value:``,children:`default (project model)`}),Hp(t).map(e=>(0,R.jsxs)(a2,{children:[(0,R.jsx)(o2,{children:e.label}),e.entries.map(e=>(0,R.jsxs)(c2,{value:e.id,children:[e.note?`${e.id} — ${e.note}`:e.id,a===`review`&&l2(e)?` — not recommended for review`:``]},e.id))]},e.runtime))]})]}),s&&(0,R.jsx)(`span`,{className:`text-xs text-warning`,children:`Implementer-only model — not recommended for review tickets`})]})}var d2=(0,L.createContext)(null);function f2({open:e,children:t}){return(0,R.jsx)(d2.Provider,{value:e,children:t})}function p2({location:e,children:t}){let n=(0,L.useContext)(d2);return n?(0,R.jsx)(`button`,{type:`button`,className:sE,onClick:t=>{t.stopPropagation(),n(e)},children:t}):(0,R.jsx)(R.Fragment,{children:t})}function m2({text:e}){let t=(0,L.useContext)(d2),n=jm(e);return!t||!n?(0,R.jsx)(R.Fragment,{children:e}):(0,R.jsxs)(R.Fragment,{children:[n.before,(0,R.jsx)(p2,{location:n.location,children:n.phrase}),n.after]})}function h2({ticket:e,busy:t,onCancel:n,onSave:r}){let[i,a]=(0,L.useState)(e.title),[o,s]=(0,L.useState)(e.goal),[c,l]=(0,L.useState)(e.context),[u,d]=(0,L.useState)(e.acceptanceCriteria.join(`
|
|
183
|
+
`,t)}paste(e){this._core.paste(e)}refresh(e,t){this._verifyIntegers(e,t),this._core.refresh(e,t)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(e){this._addonManager.loadAddon(this,e)}static get strings(){return{get promptLabel(){return KG.get()},set promptLabel(e){KG.set(e)},get tooMuchOutput(){return JG.get()},set tooMuchOutput(e){JG.set(e)}}}_verifyIntegers(...e){for(t1 of e)if(t1===1/0||isNaN(t1)||t1%1!=0)throw Error(`This API only accepts integers`)}_verifyPositiveIntegers(...e){for(t1 of e)if(t1&&(t1===1/0||isNaN(t1)||t1%1!=0||t1<0))throw Error(`This API only accepts positive integers`)}},r1=250,i1=5e3,a1=8e3,o1=3e3;function s1(e){return`${e.protocol===`https:`?`wss:`:`ws:`}//${e.host}`}function c1(){return s1(window.location)}var l1=class{opts;ws=null;backoff=r1;reconnectTimer=null;connectTimer=null;stallTimer=null;disposed=!1;ended=!1;receivedData=!1;url;constructor(e){this.opts=e;let t=e.wsBase??c1();this.url=`${t.replace(/\/$/,``)}/ws/terminal/${encodeURIComponent(e.sessionId)}`}connect(){if(this.disposed||this.ended)return;this.clearTimer(),this.opts.onStatus(this.backoff===r1?`connecting`:`reconnecting`);let e=new WebSocket(this.url);e.binaryType=`arraybuffer`,this.ws=e,this.connectTimer=setTimeout(()=>{e.readyState===WebSocket.CONNECTING&&this.forceClose(e)},a1),e.onopen=()=>{this.clearConnectTimer(),this.receivedData&&(this.receivedData=!1,this.opts.onReset?.())},e.onmessage=e=>{typeof e.data==`string`?this.handleControl(e.data):(this.receivedData=!0,this.opts.onData(new Uint8Array(e.data)))},e.onclose=()=>{this.ws=null,this.clearConnectTimer(),this.clearStallTimer(),!(this.disposed||this.ended)&&(this.opts.onStatus(`reconnecting`),this.scheduleReconnect())},e.onerror=()=>{this.forceClose(e)}}send(e){this.ws&&this.ws.readyState===WebSocket.OPEN&&(this.ws.send(new TextEncoder().encode(e)),this.watchForStall())}resize(e,t){this.ws&&this.ws.readyState===WebSocket.OPEN&&(this.ws.send(JSON.stringify({t:`resize`,cols:e,rows:t})),this.watchForStall())}dispose(){if(this.disposed=!0,this.clearTimer(),this.clearConnectTimer(),this.clearStallTimer(),this.ws){this.ws.onopen=null,this.ws.onclose=null,this.ws.onerror=null,this.ws.onmessage=null;try{this.ws.close()}catch{}this.ws=null}}handleControl(e){let t;try{t=JSON.parse(e)}catch{return}t.t===`status`&&(t.status===`live`?(this.backoff=r1,this.opts.onStatus(`live`)):t.status===`ended`&&(this.ended=!0,this.opts.onStatus(`ended`)))}watchForStall(){this.stallTimer===null&&(this.stallTimer=setTimeout(()=>{this.stallTimer=null;let e=this.ws;!e||e.readyState!==WebSocket.OPEN||e.bufferedAmount>0&&this.forceClose(e)},o1))}forceClose(e){try{e.close()}catch{}if(this.ws===e&&e.readyState===WebSocket.CLOSED){if(e.onclose=null,this.ws=null,this.disposed||this.ended)return;this.opts.onStatus(`reconnecting`),this.scheduleReconnect()}}scheduleReconnect(){this.clearTimer();let e=this.backoff;this.backoff=Math.min(this.backoff*2,i1),this.reconnectTimer=setTimeout(()=>this.connect(),e)}clearTimer(){this.reconnectTimer!==null&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}clearConnectTimer(){this.connectTimer!==null&&(clearTimeout(this.connectTimer),this.connectTimer=null)}clearStallTimer(){this.stallTimer!==null&&(clearTimeout(this.stallTimer),this.stallTimer=null)}},u1={dark:{"--color-surface-inset":`#0c0e14`,"--color-text":`#eceef4`,"--color-accent":`#4f8ef7`,"--color-accent-subtle":`#16213a`,"--color-surface-selected":`#212636`,"--color-danger":`#f06363`,"--color-success":`#46b67a`,"--color-warning":`#e2a53b`,"--color-accent-text":`#7aaafa`},light:{"--color-surface-inset":`#f4f6f9`,"--color-text":`#161a24`,"--color-accent":`#2f6fe4`,"--color-accent-subtle":`#ecf2fe`,"--color-surface-selected":`#e4e8f1`,"--color-danger":`#c42828`,"--color-success":`#1e8e53`,"--color-warning":`#a86a06`,"--color-accent-text":`#2463d6`}},d1={dark:{black:`#2a2a2f`,magenta:`#c68af0`,cyan:`#56c2d6`,white:`#d4d4d8`,brightBlack:`#6b6b74`,brightRed:`#ff8a8a`,brightGreen:`#72d49c`,brightYellow:`#f2c46e`,brightMagenta:`#d9a9f7`,brightCyan:`#86dbe8`,brightWhite:`#fafafa`},light:{black:`#18181b`,magenta:`#9337be`,cyan:`#0e7488`,white:`#52525b`,brightBlack:`#71717a`,brightRed:`#d63a3a`,brightGreen:`#1f9a5a`,brightYellow:`#b57308`,brightMagenta:`#a64ccf`,brightCyan:`#128399`,brightWhite:`#27272a`}};function f1(e){let t=typeof document>`u`?null:getComputedStyle(document.documentElement);return n=>t?.getPropertyValue(n).trim()||u1[e][n]||``}function p1(e,t=f1(e)){let n=t(`--color-surface-inset`);return{background:n,foreground:t(`--color-text`),cursor:t(`--color-accent`),cursorAccent:n,selectionBackground:t(`--color-accent-subtle`),selectionInactiveBackground:t(`--color-surface-selected`),red:t(`--color-danger`),green:t(`--color-success`),yellow:t(`--color-warning`),blue:t(`--color-accent`),brightBlue:t(`--color-accent-text`),...d1[e]}}function m1(e){return e.key===`v`||e.key===`V`||e.code===`KeyV`}function h1(e){let t=e.type===`keydown`;if(!t&&e.type!==`keypress`)return{intercept:!1};if(e.key===`Enter`&&(e.shiftKey||e.ctrlKey))return{intercept:!0,bytes:t?`\x1B\r`:``};if(Nb(e))return{intercept:!0,bytes:``};if(m1(e)&&!e.shiftKey&&!e.metaKey){if(e.ctrlKey&&!e.altKey)return{intercept:!0,bytes:``};if(e.altKey&&!e.ctrlKey)return{intercept:!0,bytes:t?`\x1Bv`:``}}return{intercept:!1}}var g1=`"Geist Mono Variable", "Cascadia Code", Consolas, monospace`;function _1({sessionId:e,wsBase:t,onEnded:n}){let r=(0,L.useRef)(null),[i,a]=(0,L.useState)(`connecting`),o=(0,L.useRef)(n);o.current=n;let{resolved:s}=nM(),c=(0,L.useRef)(s);c.current=s;let l=(0,L.useRef)(null);(0,L.useEffect)(()=>{let e=l.current;e&&(e.options.theme=p1(s))},[s]),(0,L.useEffect)(()=>{let n=r.current;if(!n)return;let i=new n1({theme:p1(c.current),fontFamily:g1,fontSize:12.5,lineHeight:1.2,cursorBlink:!0,allowProposedApi:!0,scrollback:5e3});l.current=i;let s=new BG;i.loadAddon(s),i.open(n);let u=()=>{try{s.fit()}catch{}};u();let d=requestAnimationFrame(u),f=!1;typeof document<`u`&&document.fonts?.check?.(`12px ${g1}`)||document.fonts?.load(`12px ${g1}`).then(()=>{f||(i.options.fontFamily=`monospace`,i.options.fontFamily=g1,u())});let p;p=new l1({sessionId:e,wsBase:t,onData:e=>i.write(e),onReset:()=>i.reset(),onStatus:e=>{a(e),e===`live`&&p.resize(i.cols,i.rows),e===`ended`&&o.current?.()}});let m=i.onData(e=>p.send(e)),h=i.onResize(({cols:e,rows:t})=>p.resize(e,t));i.attachCustomKeyEventHandler(e=>{let t=h1(e);return t.intercept?(t.bytes&&p.send(t.bytes),!1):!0}),p.connect();let g=new ResizeObserver(()=>u());return g.observe(n),()=>{f=!0,l.current=null,cancelAnimationFrame(d),g.disconnect(),m.dispose(),h.dispose(),p.dispose(),i.dispose()}},[e,t]);let u=i===`connecting`?{text:`Connecting…`,tone:`dim`}:i===`reconnecting`?{text:`Disconnected — reconnecting… keystrokes are dropped until the stream is back`,tone:`down`}:i===`ended`?{text:`Session stream ended — relaunch or end the session above`,tone:`dim`}:null;return(0,R.jsxs)(`div`,{className:q(`relative box-border h-full w-full overflow-hidden bg-surface-inset pt-2 pr-0.5 pb-1.5 pl-2.5`,`[&_.xterm-viewport]:bg-transparent!`),children:[(0,R.jsx)(`div`,{ref:r,className:`h-full w-full`,"data-session-id":e}),u&&(0,R.jsx)(`div`,{role:`status`,className:q(`pointer-events-none absolute inset-x-0 top-0 px-2.5 py-1 text-xs animate-fade-in`,u.tone===`down`?`bg-danger-subtle text-danger`:`border-b border-border-subtle bg-surface-inset text-text-tertiary`),children:u.text})]})}function v1(e,t){if(!e)return null;let n=Wv(e,t);if(n.kind===`notDone`)return null;if(n.kind===`mapComplete`)return`Map complete — every waypoint is done. Converge from the bar above.`;let r=n.waypoint.status===`dropped`?`Dropped`:`Resolved`;return n.kind===`awaitingResearch`?`${r} — waiting on ${n.claimed} research run${n.claimed===1?``:`s`}`:`${r}${n.waypoint.summary?` — ${n.waypoint.summary}`:``}`}function y1({session:e,full:t,right:n,className:r}){let i=e.ccSessionId??e.id,a=v1(t,e),o=e.status!==`ended`;return(0,R.jsxs)(`div`,{className:q(`flex min-h-10 min-w-0 items-center gap-3 text-sm`,r),title:i,children:[(0,R.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-2 font-medium text-text`,children:[(0,R.jsx)(Dy,{size:16,className:`text-icon`}),Qv(e),` session`]}),a?(0,R.jsx)(rA,{tone:`success`,icon:(0,R.jsx)(by,{}),className:`min-w-0 flex-1`,title:a,children:a}):o?(0,R.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:[(0,R.jsx)(rA,{tone:e.status===`launching`?`warning`:`live`,children:e.status===`launching`?`Starting…`:`Live`}),e.createdAt&&(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary tabular-nums`,children:mh(e.createdAt,Date.now())})]}):(0,R.jsxs)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-text-tertiary`,children:[`Ended`,e.endedAt===void 0?``:` ${ph(e.endedAt)}`]}),n&&(0,R.jsx)(`span`,{className:`flex shrink-0 items-center gap-1`,children:n})]})}function b1({featureId:e,sessions:t,full:n,className:r,right:i,fill:a=!1}){let o=E1(t);return o?Ag(o)?(0,R.jsxs)(`section`,{"aria-label":`Session`,className:q(`flex min-h-0 flex-1 flex-col animate-fade-in`,r),children:[(0,R.jsx)(y1,{session:o,full:n,right:(0,R.jsxs)(R.Fragment,{children:[i,(0,R.jsx)(IG,{featureId:e,sessionId:o.id})]})}),(0,R.jsx)(x1,{featureId:e,session:o}),(0,R.jsx)(`div`,{className:`mt-1 min-h-0 flex-1 overflow-hidden rounded-md border border-border bg-surface-inset`,id:`session-terminal`,children:(0,R.jsx)(LG,{label:`terminal`,children:(0,R.jsx)(_1,{sessionId:o.id})})})]}):a?(0,R.jsxs)(`section`,{"aria-label":`Session`,className:q(`flex min-h-0 flex-1 flex-col`,r),children:[(0,R.jsx)(y1,{session:o,full:n}),(0,R.jsx)(`div`,{className:`mt-1 flex min-h-0 flex-1 items-center justify-center rounded-md bg-surface-inset`,children:(0,R.jsx)(GA,{icon:(0,R.jsx)(Dy,{}),title:`The session has ended`,hint:`Pick it back up from the next step above — the conversation is still on disk.`})})]}):(0,R.jsx)(y1,{session:o,full:n,className:`mb-6`}):null}function x1({featureId:e,session:t}){let n=pF(e);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(C1,{session:t,events:n}),(0,R.jsx)(T1,{session:t,notReady:kg(n,t.id)})]})}var S1=5e3;function C1({session:e,events:t}){return Og(e,t,w1(S1))?(0,R.jsx)(`p`,{className:`m-0 pb-1.5 text-xs text-text-tertiary animate-fade-in`,children:`The agent hasn’t checked in yet.`}):null}function w1(e){let[t,n]=(0,L.useState)(()=>Date.now());return(0,L.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function T1({session:e,notReady:t}){return t?(0,R.jsxs)(`div`,{className:`flex items-start gap-1.5 pb-2 text-sm text-text-secondary animate-fade-in`,role:`status`,children:[(0,R.jsx)(rA,{tone:`warning`,icon:(0,R.jsx)(tb,{}),size:`sm`,strong:!0,className:`shrink-0`,children:`Not ready`}),(0,R.jsxs)(`span`,{className:`min-w-0`,children:[`— `,k_(e),` has not started on its briefing. Answer anything waiting in the terminal (a trust or login prompt).`]})]}):null}function E1(e){let t=[...e].reverse();return t.find(Ag)??t[0]}function D1({docs:e,value:t,onPick:n,className:r}){let i=t?.split(/[\\/]/).pop()??`Docs`;return(0,R.jsxs)(DP,{children:[(0,R.jsx)(OP,{asChild:!0,children:(0,R.jsxs)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(ky,{}),className:q(`max-w-56`,r),"aria-label":t?`Docs — showing ${i}`:`Docs`,children:[(0,R.jsx)(`span`,{className:q(`truncate`,t&&`font-mono`),children:i}),(0,R.jsx)(wy,{size:12,className:`shrink-0 text-icon`})]})}),(0,R.jsx)(kP,{align:`end`,className:`min-w-52`,children:e.map(e=>(0,R.jsx)(AP,{icon:e.relPath===t?(0,R.jsx)(by,{}):(0,R.jsx)(ky,{}),"aria-current":e.relPath===t?`true`:void 0,onSelect:()=>n(e.relPath),children:e.title||e.relPath.split(/[\\/]/).pop()},e.relPath))})]})}function O1({featureId:e,kind:t,docs:n,collapsed:r=!1,onToggle:i,mapped:a=!1,mode:o=`live`,children:s}){let c=n.find(e=>e.relPath.endsWith(`${t}.md`))?.relPath,[l,u]=(0,L.useState)(c),[d,f]=(0,L.useState)(!1),p=(0,L.useRef)(void 0),m=o===`static`;(0,L.useEffect)(()=>u(c),[t,c]);let h=gF(e,l,{live:!m}),g=h.content??``;(0,L.useEffect)(()=>{if(h.content!==void 0){if(p.current!==void 0&&p.current!==g&&t===`spec`){f(!0);let e=window.setTimeout(()=>f(!1),3e3);return p.current=g,()=>window.clearTimeout(e)}p.current=g}},[g,h.content,t]);let _=_g(g);if(r&&i)return(0,R.jsxs)(`div`,{className:`flex w-9 flex-none flex-col items-center gap-2 pt-0.5`,children:[(0,R.jsx)(nE,{label:`Expand the ${t} pane`,icon:(0,R.jsx)(Gy,{}),onClick:i,tooltipSide:`right`}),(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary tabular-nums [writing-mode:vertical-rl]`,children:t===`decisions`?`${_} decisions`:`Spec`})]});let v=m||l===c,y=t===`spec`?`Spec`:m?`Decisions`:`Decisions so far`,b=(0,R.jsxs)(R.Fragment,{children:[h.loading&&(0,R.jsx)(UA,{children:`Loading…`}),h.failed&&(0,R.jsxs)(WA,{children:[`Could not read `,l]}),g?(0,R.jsx)(PG,{source:g,size:m?`base`:`sm`}):v?(0,R.jsx)(k1,{kind:t,mapped:a,frozen:m}):null,s]});return m?(0,R.jsx)(IA,{title:y,action:(0,R.jsxs)(`span`,{className:`font-mono text-xs text-text-tertiary`,children:[t,`.md`,t===`decisions`&&_>0?` · ${_}`:``]}),children:b}):(0,R.jsxs)(`section`,{"aria-label":v?y:l,className:`flex min-h-0 w-(--artifact-w) flex-none flex-col`,children:[(0,R.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center gap-2`,children:[(0,R.jsx)(`h2`,{className:`m-0 min-w-0 truncate text-sm font-medium text-text`,children:v?y:l?.split(/[\\/]/).pop()}),v&&t===`decisions`&&(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary tabular-nums`,children:_}),v&&t===`spec`&&d&&(0,R.jsx)(rA,{tone:`live`,className:`animate-fade-in`,children:`Updating`}),(0,R.jsxs)(`span`,{className:`ml-auto flex items-center gap-0.5`,children:[(0,R.jsx)(D1,{docs:n,value:l,onPick:u}),i&&(0,R.jsx)(nE,{label:`Collapse the ${t} pane`,size:`sm`,icon:(0,R.jsx)(Gy,{}),onClick:i})]})]}),(0,R.jsx)(`div`,{className:`mt-2 min-h-0 flex-1 overflow-y-auto border-t border-border-subtle pt-4 pr-3`,children:b})]})}function k1({kind:e,mapped:t,frozen:n}){return n?(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(ky,{}),title:e===`decisions`?`No decisions were recorded`:`No spec`,hint:`This feature was created as a quick change and skipped ideation.`}):(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(ky,{}),title:e===`decisions`?`No decisions yet`:`No spec yet`,hint:e===`decisions`?`They land here one by one as the session settles them.`:t?`The converge session writes it here from the map and the decisions.`:`The session is drafting the spec — it appears here as it's written.`})}function A1({featureId:e,relPath:t,title:n,onClose:r,returnFocusRef:i}){let a=B.docs.read.useQuery({featureId:e,relPath:t});return(0,R.jsxs)(QA,{open:!0,onClose:r,labelledBy:`doc-peek-title`,size:`lg`,returnFocusRef:i,className:`flex max-h-[84vh] flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`flex h-(--topbar-h) shrink-0 items-center gap-2 border-b border-border-subtle pr-2 pl-5`,children:[(0,R.jsx)(ky,{size:16,className:`shrink-0 text-icon`}),(0,R.jsx)(`h2`,{id:`doc-peek-title`,className:`m-0 min-w-0 truncate text-sm font-medium text-text`,children:n||t.split(/[\\/]/).pop()}),(0,R.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-text-tertiary`,title:t,children:t}),(0,R.jsx)(nE,{label:`Close`,size:`sm`,icon:(0,R.jsx)(xy,{}),onClick:r})]}),(0,R.jsx)(`div`,{className:`min-h-0 overflow-y-auto px-10 pt-8 pb-12`,children:(0,R.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[a.isLoading&&(0,R.jsxs)(WA,{children:[`Loading `,n,`…`]}),a.error&&(0,R.jsxs)(WA,{children:[`Could not read `,t,`: `,a.error.message]}),a.data&&(0,R.jsx)(PG,{source:ch(a.data.content),size:`base`})]})})]})}var j1={ready:`accent`,working:`live`,waiting:`neutral`,done:`success`};function M1({featureId:e,group:t,item:n,blocker:r,readonly:i=!1}){let a=n.waypoint,[o,s]=(0,L.useState)(n.openByDefault),[c,l]=(0,L.useState)(!1),u=B.useUtils(),d=Ab(),f=a.type===`research`,p=!f&&!!a.lastSessionId,m=a.claimedBy?.startsWith(`run_`)??!1,h=i||o,g=B.feature.workWaypoint.useMutation({onSuccess:()=>{l(!1),u.feature.get.invalidate({id:e}),u.feature.list.invalidate()},onError:(e,t)=>{!f&&!t.endLive&&r&&e.data?.code===`PRECONDITION_FAILED`?l(!0):(l(!1),d.push(e.message))}}),_=(0,R.jsxs)(R.Fragment,{children:[!i&&(0,R.jsx)(Ty,{size:12,className:q(`shrink-0 text-icon transition-transform duration-(--dur-2) ease-app`,h&&`rotate-90`)}),(0,R.jsx)(`span`,{className:`inline-flex size-4 shrink-0 items-center justify-center`,children:(0,R.jsx)(tA,{tone:j1[t]})}),(0,R.jsx)(`span`,{className:q(`min-w-0 flex-1 truncate text-sm`,t===`done`?`text-text-secondary`:`font-medium text-text`),children:a.title}),(0,R.jsx)(`span`,{className:`shrink-0 text-xs text-text-tertiary`,children:n.stateWord})]});return(0,R.jsxs)(`div`,{className:`rounded-md`,children:[i?(0,R.jsx)(`div`,{className:`flex min-h-8 items-center gap-2 px-2`,children:_}):(0,R.jsx)(`button`,{type:`button`,className:`flex min-h-8 w-full cursor-pointer items-center gap-2 rounded-md bg-transparent px-2 text-left transition-colors duration-(--dur-1) ease-app hover:bg-surface-hover`,"aria-expanded":h,title:h?`Collapse this waypoint`:`Expand this waypoint`,onClick:()=>s(e=>!e),children:_}),h&&(0,R.jsxs)(`div`,{className:q(`pr-2 pb-3 text-sm animate-fade-in`,i?`pl-8`:`pl-[3.25rem]`),children:[(0,R.jsx)(PG,{source:a.question}),t===`working`&&m&&(0,R.jsx)(`div`,{className:`mt-2 text-xs text-text-tertiary`,children:`Researching…`}),t===`done`&&a.summary&&(0,R.jsx)(PG,{source:a.summary,tone:`tertiary`,className:`mt-2`}),(0,R.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-text-tertiary`,children:[(0,R.jsx)(`span`,{className:`font-mono`,children:a.type}),n.originTitle&&(0,R.jsxs)(`span`,{children:[`Surfaced by `,n.originTitle]})]}),!i&&t===`ready`&&(0,R.jsxs)(`div`,{className:`mt-3 flex items-center gap-2`,children:[(0,R.jsx)(Y,{size:`sm`,icon:p?(0,R.jsx)(ab,{}):(0,R.jsx)(Ly,{}),disabled:g.isPending,title:f?`Start an unattended research run on this waypoint`:p?`Resume the previous session on this waypoint`:`Claim this waypoint and open a session`,onClick:()=>g.mutate({featureId:e,waypointId:a.id}),children:p?`Resume`:`Work`}),f&&(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary`,children:`Runs unattended`})]}),!i&&c&&r&&(0,R.jsxs)(`div`,{className:`mt-3 rounded-md bg-danger-subtle px-3 py-2`,role:`alert`,children:[(0,R.jsx)(`div`,{className:`text-xs text-text-secondary`,children:r.waypointTitle?(0,R.jsxs)(R.Fragment,{children:[`A session is live on `,(0,R.jsx)(`b`,{className:`font-medium text-text`,children:r.waypointTitle}),` and its waypoint is still open. End it and work this instead?`]}):(0,R.jsxs)(R.Fragment,{children:[`A `,r.kind,` session is live on this feature. End it and work this instead?`]})}),(0,R.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,R.jsx)(Y,{size:`sm`,variant:`danger`,disabled:g.isPending,onClick:()=>g.mutate({featureId:e,waypointId:a.id,endLive:!0}),children:`End & work this`}),(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>l(!1),children:`Cancel`})]})]})]})]})}var N1=[`Destination`,`Notes`,`Not yet specified`,`Out of scope`];function P1({full:e,relPath:t,collapsed:n,onToggle:r,readonly:i=!1,layout:a=`rail`}){let o=e.feature.id,[s,c]=(0,L.useState)(),l=B.docs.read.useQuery({featureId:o,relPath:t??`map.md`},{enabled:!!t}),u=l.data?x_(l.data.content):{},d=E_(e.waypoints,e.frontierIds,i),f=T_(e.waypoints,e.frontierIds),p=!!t||e.waypoints.length>0,m=a===`rail`,h=`${f.done}/${f.total} done`;if(m&&n)return(0,R.jsxs)(`div`,{className:`flex w-9 flex-none flex-col items-center gap-2 pt-0.5`,children:[(0,R.jsx)(nE,{label:`Expand the map`,icon:(0,R.jsx)(Gy,{}),onClick:r,tooltipSide:`right`}),(0,R.jsxs)(`span`,{className:`text-xs text-text-tertiary tabular-nums`,children:[f.done,`/`,f.total]}),(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary [writing-mode:vertical-rl]`,children:`Map`})]});let g=(0,R.jsxs)(R.Fragment,{children:[l.isLoading&&(0,R.jsx)(WA,{children:`Loading the map…`}),p?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(I1,{featureId:o,groups:d,blocker:Gv(e.sessions,e.waypoints),readonly:i}),t&&(0,R.jsx)(F1,{sections:u})]}):(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(ky,{}),title:`Not charted yet`,hint:`The session writes the map as you explore the idea.`})]});return(0,R.jsxs)(`section`,{"aria-label":`Map`,className:q(`flex min-h-0 flex-col`,m?`w-(--maprail-w) flex-none`:`min-w-0`),children:[m?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center gap-2`,children:[(0,R.jsx)(`h2`,{className:`m-0 text-sm font-medium text-text`,children:`Map`}),(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary tabular-nums`,"aria-label":`${f.done} of ${f.total} waypoints done`,children:h}),(0,R.jsx)(nE,{label:A_,size:`sm`,icon:(0,R.jsx)(nb,{}),className:`-ml-1`}),(0,R.jsxs)(`span`,{className:`ml-auto flex items-center gap-0.5`,children:[(0,R.jsx)(D1,{docs:e.docs,value:t,onPick:c}),(0,R.jsx)(nE,{label:`Collapse the map`,size:`sm`,icon:(0,R.jsx)(Gy,{}),onClick:r})]})]}),(0,R.jsx)(`div`,{className:`mt-2 min-h-0 flex-1 overflow-y-auto pr-2`,children:g})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{className:`mt-0 mb-3 text-xs text-text-tertiary`,children:h}),g]}),s&&s!==t&&(0,R.jsx)(A1,{featureId:o,relPath:s,title:e.docs.find(e=>e.relPath===s)?.title||s.split(/[\\/]/).pop()||`Document`,onClose:()=>c(void 0)})]})}function F1({sections:e}){let t=N1.filter(t=>(e[t]?.trim()??``)!==``);return(0,R.jsx)(JA,{title:`Map document`,icon:(0,R.jsx)(ky,{}),className:`mt-4`,bodyClassName:`pl-6 pr-1`,children:t.length===0?(0,R.jsx)(WA,{children:`Nothing written yet — the session fills this in as it explores the idea.`}):t.map(t=>(0,R.jsxs)(`section`,{className:`mt-3 first:mt-0`,children:[(0,R.jsx)(`div`,{className:`mb-1 text-xs font-medium text-text-tertiary`,children:t}),(0,R.jsx)(PG,{source:e[t].trim()})]},t))})}function I1({featureId:e,groups:t,blocker:n,readonly:r}){return t.length===0?(0,R.jsx)(WA,{children:`No waypoints yet — they appear here as the map takes shape.`}):(0,R.jsx)(`div`,{className:`flex flex-col gap-3`,children:t.map(t=>{let i=(0,R.jsx)(`div`,{className:`flex flex-col`,children:t.waypoints.map(i=>(0,R.jsx)(M1,{featureId:e,group:t.key,item:i,blocker:n,readonly:r},i.waypoint.id))});return t.key===`done`&&!r?(0,R.jsx)(JA,{title:t.label,aside:t.waypoints.length,children:i},t.key):(0,R.jsxs)(`section`,{children:[(0,R.jsx)(mA,{count:t.waypoints.length,className:`px-2`,children:t.label}),i]},t.key)})})}function L1({full:e,effective:t,chatDocked:n=!1,mapRailCollapsed:r,onToggleMapRail:i,artifactPaneCollapsed:a,onToggleArtifactPane:o}){let s=e.docs.some(e=>e.relPath.endsWith(`spec.md`))?`spec`:`decisions`,c=qv(e.sessions,n);return(0,R.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-1 gap-6`,children:[e.feature.mapped&&t===`planning`?(0,R.jsx)(P1,{full:e,relPath:b_(e),collapsed:r,onToggle:i}):(0,R.jsx)(O1,{featureId:e.feature.id,kind:s,docs:e.docs,collapsed:a,onToggle:o,mapped:e.feature.mapped}),(0,R.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:c.length>0?(0,R.jsx)(b1,{featureId:e.feature.id,sessions:c,full:e,fill:!0}):(0,R.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center rounded-lg bg-surface-inset`,children:c.length<e.sessions.length?(0,R.jsx)(GA,{icon:(0,R.jsx)(Dy,{}),title:`The chat is in the aside`,hint:`The conversation is open on the right — close it to bring the terminal back here.`}):(0,R.jsx)(GA,{icon:(0,R.jsx)(Dy,{}),title:`No session yet`,hint:`Start a session from the next step above — you and the agent shape the idea here before any code is written.`})})})]})}var R1=Object.defineProperty,z1=(e,t)=>R1(e,`name`,{value:t,configurable:!0});function B1(e,[t,n]){return Math.min(n,Math.max(t,e))}z1(B1,`clamp`);var V1=Object.defineProperty,H1=(e,t)=>V1(e,`name`,{value:t,configurable:!0});function U1(e){let t=L.useRef({value:e,previous:e});return L.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}H1(U1,`usePrevious`);var W1=Object.defineProperty,G1=(e,t)=>W1(e,`name`,{value:t,configurable:!0}),K1=[` `,`Enter`,`ArrowUp`,`ArrowDown`],q1=[` `,`Enter`],J1=`Select`,[Y1,X1,Z1]=aM(J1),[Q1,$1]=sx(J1,[Z1,hw]),e0=hw(),[t0,n0]=Q1(J1),[r0,i0]=Q1(J1);function a0(e){let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:a,value:o,defaultValue:s,onValueChange:c,dir:l,name:u,autoComplete:d,disabled:f,required:p,form:m,internal_do_not_use_render:h}=e,g=e0(t),[_,v]=L.useState(null),[y,b]=L.useState(null),[x,S]=L.useState(!1),C=yM(l),[w,T]=Xw({prop:r,defaultProp:i??!1,onChange:a,caller:J1}),[E,D]=Xw({prop:o,defaultProp:s,onChange:c,caller:J1}),O=L.useRef(null),k=L.useRef(E);L.useEffect(()=>{let e=m?_?.ownerDocument.getElementById(m):_?.form;if(e instanceof HTMLFormElement){let t=G1(()=>D(k.current),`reset`);return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)}},[m,_,D]);let A=!_||!!m||!!_.closest(`form`),[j,M]=L.useState(new Set),N=Xx(),P=Array.from(j).map(e=>e.props.value).join(`;`),F=L.useCallback(e=>{M(t=>new Set(t).add(e))},[]),ee=L.useCallback(e=>{M(t=>{let n=new Set(t);return n.delete(e),n})},[]),te={required:p,trigger:_,onTriggerChange:v,valueNode:y,onValueNodeChange:b,valueNodeHasChildren:x,onValueNodeHasChildrenChange:S,contentId:N,value:E,onValueChange:D,open:w,onOpenChange:T,dir:C,triggerPointerDownPosRef:O,disabled:f,name:u,autoComplete:d,form:m,nativeOptions:j,nativeSelectKey:P,isFormControl:A};return(0,R.jsx)(Ow,{...g,children:(0,R.jsx)(t0,{scope:t,...te,children:(0,R.jsx)(Y1.Provider,{scope:t,children:(0,R.jsx)(r0,{scope:t,onNativeOptionAdd:F,onNativeOptionRemove:ee,children:W0(h)?h(te):n})})})})}G1(a0,`SelectProvider`);var o0=G1(e=>{let{__scopeSelect:t,children:n,...r}=e;return(0,R.jsx)(a0,{__scopeSelect:t,...r,internal_do_not_use_render:({isFormControl:e})=>(0,R.jsxs)(R.Fragment,{children:[n,e?(0,R.jsx)(U0,{__scopeSelect:t}):null]})})},`Select`),s0=`SelectTrigger`,c0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,disabled:r=!1,...i}=e,a=e0(n),o=n0(s0,n),s=o.disabled||r,c=rx(t,o.onTriggerChange),l=X1(n),u=L.useRef(`touch`),[d,f,p]=K0(e=>{let t=l().filter(e=>!e.disabled),n=q0(t,e,t.find(e=>e.value===o.value));n!==void 0&&o.onValueChange(n.value)}),m=G1(e=>{s||(o.onOpenChange(!0),p()),e&&(o.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})},`handleOpen`);return(0,R.jsx)(kw,{asChild:!0,...a,children:(0,R.jsx)(Ex.button,{type:`button`,role:`combobox`,"aria-controls":o.open?o.contentId:void 0,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":`none`,dir:o.dir,"data-state":o.open?`open`:`closed`,disabled:s,"data-disabled":s?``:void 0,"data-placeholder":G0(o.value)?``:void 0,...i,ref:c,onClick:J(i.onClick,e=>{e.currentTarget.focus(),u.current!==`mouse`&&m(e)}),onPointerDown:J(i.onPointerDown,e=>{u.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),e.button===0&&e.ctrlKey===!1&&e.pointerType===`mouse`&&(m(e),e.preventDefault())}),onKeyDown:J(i.onKeyDown,e=>{let t=d.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&f(e.key),!(t&&e.key===` `)&&K1.includes(e.key)&&(m(),e.preventDefault())})})})},`SelectTrigger`)),l0=`SelectValue`,u0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,className:r,style:i,children:a,placeholder:o=``,...s}=e,c=n0(l0,n),{onValueNodeHasChildrenChange:l}=c,u=a!==void 0,d=rx(t,c.onValueNodeChange);Gx(()=>{l(u)},[l,u]);let f=G0(c.value);return(0,R.jsx)(Ex.span,{...s,asChild:!f&&s.asChild,ref:d,style:{pointerEvents:`none`},children:(0,R.jsx)(L.Fragment,{children:f?o:a},f?`placeholder`:`value`)})},`SelectValue`)),d0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,children:r,...i}=e;return(0,R.jsx)(Ex.span,{"aria-hidden":!0,...i,ref:t,children:r||`▼`})},`SelectIcon`)),[f0,p0]=Q1(`SelectPortal`,{forceMount:void 0}),m0=G1(e=>{let{__scopeSelect:t,forceMount:n,...r}=e;return(0,R.jsx)(f0,{scope:e.__scopeSelect,forceMount:n,children:(0,R.jsx)(Mw,{asChild:!0,...r})})},`SelectPortal`),h0=`SelectContent`,g0=L.forwardRef(G1(function(e,t){let n=p0(h0,e.__scopeSelect),{forceMount:r=n.forceMount,...i}=e,a=n0(h0,e.__scopeSelect),[o,s]=L.useState();return Gx(()=>{s(new DocumentFragment)},[]),(0,R.jsx)(Iw,{present:r||a.open,children:({present:e})=>e?(0,R.jsx)(S0,{...i,ref:t}):(0,R.jsx)(_0,{...i,fragment:o})})},`SelectContent`)),_0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,children:r,fragment:i}=e;return i?Rb.createPortal((0,R.jsx)(y0,{scope:n,children:(0,R.jsx)(Y1.Slot,{scope:n,children:(0,R.jsx)(`div`,{ref:t,children:r})})}),i):null},`SelectContentFragment`)),v0=10,[y0,b0]=Q1(h0),x0=dx(`SelectContent.RemoveScroll`),S0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n}=e,{position:r=`item-aligned`,onCloseAutoFocus:i,onEscapeKeyDown:a,onPointerDownOutside:o,side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g,..._}=e,v=n0(h0,n),[y,b]=L.useState(null),[x,S]=L.useState(null),C=rx(t,b),[w,T]=L.useState(null),[E,D]=L.useState(null),O=X1(n),[k,A]=L.useState(!1),j=L.useRef(!1);L.useEffect(()=>{if(y)return uO(y)},[y]),GE();let M=L.useCallback(e=>{let[t,...n]=O().map(e=>e.ref.current),[r]=n.slice(-1),i=document.activeElement;for(let n of e)if(n===i||(n?.scrollIntoView({block:`nearest`}),n===t&&x&&(x.scrollTop=0),n===r&&x&&(x.scrollTop=x.scrollHeight),n?.focus(),document.activeElement!==i))return},[O,x]),N=L.useCallback(()=>M([w,y]),[M,w,y]);L.useEffect(()=>{k&&N()},[k,N]);let{onOpenChange:P,triggerPointerDownPosRef:F}=v;L.useEffect(()=>{if(y){let e={x:0,y:0},t=G1(t=>{e={x:Math.abs(Math.round(t.pageX)-(F.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(F.current?.y??0))}},`handlePointerMove`),n=G1(n=>{e.x<=10&&e.y<=10?n.preventDefault():n.composedPath().includes(y)||P(!1),document.removeEventListener(`pointermove`,t),F.current=null},`handlePointerUp`);return F.current!==null&&(document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,n,{capture:!0,once:!0})),()=>{document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,n,{capture:!0})}}},[y,P,F]),L.useEffect(()=>{let e=G1(()=>P(!1),`close`);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[P]);let[ee,te]=K0(e=>{let t=O().filter(e=>!e.disabled),n=q0(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current?.focus())}),ne=L.useCallback((e,t,n)=>{let r=!j.current&&!n;(v.value!==void 0&&v.value===t||r)&&(T(e),r&&(j.current=!0))},[v.value]),I=L.useCallback(()=>y?.focus(),[y]),re=L.useCallback((e,t,n)=>{let r=!j.current&&!n;(v.value!==void 0&&v.value===t||r)&&D(e)},[v.value]),ie=r===`popper`?w0:C0,ae=ie===w0?{side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g}:{};return(0,R.jsx)(y0,{scope:n,content:y,viewport:x,onViewportChange:S,itemRefCallback:ne,selectedItem:w,onItemLeave:I,itemTextRefCallback:re,focusSelectedItem:N,selectedItemText:E,position:r,isPositioned:k,searchRef:ee,children:(0,R.jsx)(tO,{as:x0,allowPinchZoom:!0,children:(0,R.jsx)(OE,{asChild:!0,trapped:v.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:J(i,e=>{v.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,R.jsx)(Rx,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>v.onOpenChange(!1),children:(0,R.jsx)(ie,{role:`listbox`,id:v.contentId,"data-state":v.open?`open`:`closed`,dir:v.dir,onContextMenu:e=>e.preventDefault(),..._,...ae,onPlaced:()=>A(!0),ref:C,style:{display:`flex`,flexDirection:`column`,outline:`none`,..._.style},onKeyDown:J(_.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&te(e.key),[`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(e.key)){let t=O().filter(e=>!e.disabled).map(e=>e.ref.current);if([`ArrowUp`,`End`].includes(e.key)&&(t=t.slice().reverse()),[`ArrowUp`,`ArrowDown`].includes(e.key)){let n=e.target,r=t.indexOf(n);t=t.slice(r+1)}setTimeout(()=>M(t)),e.preventDefault()}})})})})})})},`SelectContentImpl`)),C0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,onPlaced:r,...i}=e,a=n0(h0,n),o=b0(h0,n),[s,c]=L.useState(null),[l,u]=L.useState(null),d=rx(t,u),f=X1(n),p=L.useRef(!1),m=L.useRef(!0),{viewport:h,selectedItem:g,selectedItemText:_,focusSelectedItem:v}=o,y=L.useCallback(()=>{if(a.trigger&&a.valueNode&&s&&l&&h&&g&&_){let e=a.trigger.getBoundingClientRect(),t=l.getBoundingClientRect(),n=a.valueNode.getBoundingClientRect(),i=_.getBoundingClientRect();if(a.dir!==`rtl`){let r=i.left-t.left,a=n.left-r,o=e.left-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-v0,d=B1(a,[v0,Math.max(v0,u-l)]);s.style.minWidth=c+`px`,s.style.left=d+`px`}else{let r=t.right-i.right,a=window.innerWidth-n.right-r,o=window.innerWidth-e.right-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-v0,d=B1(a,[v0,Math.max(v0,u-l)]);s.style.minWidth=c+`px`,s.style.right=d+`px`}let o=f(),c=window.innerHeight-v0*2,u=h.scrollHeight,d=window.getComputedStyle(l),m=parseInt(d.borderTopWidth,10),v=parseInt(d.paddingTop,10),y=parseInt(d.borderBottomWidth,10),b=parseInt(d.paddingBottom,10),x=m+v+u+b+y,S=Math.min(g.offsetHeight*5,x),C=window.getComputedStyle(h),w=parseInt(C.paddingTop,10),T=parseInt(C.paddingBottom,10),E=e.top+e.height/2-v0,D=c-E,O=g.offsetHeight/2,k=g.offsetTop+O,A=m+v+k,j=x-A;if(A<=E){let e=o.length>0&&g===o[o.length-1].ref.current;s.style.bottom=`0px`;let t=l.clientHeight-h.offsetTop-h.offsetHeight,n=A+Math.max(D,O+(e?T:0)+t+y);s.style.height=n+`px`}else{let e=o.length>0&&g===o[0].ref.current;s.style.top=`0px`;let t=Math.max(E,m+h.offsetTop+(e?w:0)+O)+j;s.style.height=t+`px`,h.scrollTop=A-E+h.offsetTop}s.style.margin=`${v0}px 0`,s.style.minHeight=S+`px`,s.style.maxHeight=c+`px`,r?.(),requestAnimationFrame(()=>p.current=!0)}},[f,a.trigger,a.valueNode,s,l,h,g,_,a.dir,r]);Gx(()=>y(),[y]);let[b,x]=L.useState();return Gx(()=>{l&&x(window.getComputedStyle(l).zIndex)},[l]),(0,R.jsx)(T0,{scope:n,contentWrapper:s,shouldExpandOnScrollRef:p,onScrollButtonChange:L.useCallback(e=>{e&&m.current===!0&&(y(),v?.(),m.current=!1)},[y,v]),children:(0,R.jsx)(`div`,{ref:c,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:b},children:(0,R.jsx)(Ex.div,{...i,ref:d,style:{boxSizing:`border-box`,maxHeight:`100%`,...i.style}})})})},`SelectItemAlignedPosition`)),w0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,align:r=`start`,collisionPadding:i=v0,...a}=e,o=e0(n);return(0,R.jsx)(Aw,{...o,...a,ref:t,align:r,collisionPadding:i,style:{boxSizing:`border-box`,...a.style,"--radix-select-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-select-content-available-width":`var(--radix-popper-available-width)`,"--radix-select-content-available-height":`var(--radix-popper-available-height)`,"--radix-select-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-select-trigger-height":`var(--radix-popper-anchor-height)`}})},`SelectPopperPosition`)),[T0,E0]=Q1(h0,{}),D0=`SelectViewport`,O0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,nonce:r,...i}=e,a=b0(D0,n),o=E0(D0,n),s=rx(t,a.onViewportChange),c=L.useRef(0);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`},nonce:r}),(0,R.jsx)(Y1.Slot,{scope:n,children:(0,R.jsx)(Ex.div,{"data-radix-select-viewport":``,role:`presentation`,...i,ref:s,style:{position:`relative`,flex:1,overflow:`hidden auto`,...i.style},onScroll:J(i.onScroll,e=>{let t=e.currentTarget,{contentWrapper:n,shouldExpandOnScrollRef:r}=o;if(r?.current&&n){let e=Math.abs(c.current-t.scrollTop);if(e>0){let r=window.innerHeight-v0*2,i=parseFloat(n.style.minHeight),a=parseFloat(n.style.height),o=Math.max(i,a);if(o<r){let i=o+e,a=Math.min(r,i),s=i-a;n.style.height=a+`px`,n.style.bottom===`0px`&&(t.scrollTop=s>0?s:0,n.style.justifyContent=`flex-end`)}}}c.current=t.scrollTop})})})]})},`SelectViewport`)),[k0,A0]=Q1(`SelectGroup`),j0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,...r}=e,i=Xx();return(0,R.jsx)(k0,{scope:n,id:i,children:(0,R.jsx)(Ex.div,{role:`group`,"aria-labelledby":i,...r,ref:t})})},`SelectGroup`)),M0=`SelectLabel`,N0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,...r}=e,i=A0(M0,n);return(0,R.jsx)(Ex.div,{id:i.id,...r,ref:t})},`SelectLabel`)),P0=`SelectItem`,[F0,I0]=Q1(P0),L0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,value:r,disabled:i=!1,textValue:a,...o}=e,s=n0(P0,n),c=b0(P0,n),l=s.value===r,[u,d]=L.useState(a??``),[f,p]=L.useState(!1),m=rx(t,Ax(e=>c.itemRefCallback?.(e,r,i))),h=Xx(),g=L.useRef(`touch`),_=G1(()=>{i||(s.onValueChange(r),s.onOpenChange(!1))},`handleSelect`);return(0,R.jsx)(F0,{scope:n,value:r,disabled:i,textId:h,isSelected:l,onItemTextChange:L.useCallback(e=>{d(t=>t||(e?.textContent??``).trim())},[]),children:(0,R.jsx)(Y1.ItemSlot,{scope:n,value:r,disabled:i,textValue:u,children:(0,R.jsx)(Ex.div,{role:`option`,"aria-labelledby":h,"data-highlighted":f?``:void 0,"aria-selected":l&&f,"data-state":l?`checked`:`unchecked`,"aria-disabled":i||void 0,"data-disabled":i?``:void 0,tabIndex:i?void 0:-1,...o,ref:m,onFocus:J(o.onFocus,()=>p(!0)),onBlur:J(o.onBlur,()=>p(!1)),onClick:J(o.onClick,()=>{g.current!==`mouse`&&_()}),onPointerUp:J(o.onPointerUp,()=>{g.current===`mouse`&&_()}),onPointerDown:J(o.onPointerDown,e=>{g.current=e.pointerType}),onPointerMove:J(o.onPointerMove,e=>{g.current=e.pointerType,i?c.onItemLeave?.():g.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:J(o.onPointerLeave,e=>{e.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:J(o.onKeyDown,e=>{i||e.target!==e.currentTarget||c.searchRef?.current!==``&&e.key===` `||(q1.includes(e.key)&&_(),e.key===` `&&e.preventDefault())})})})})},`SelectItem`)),R0=`SelectItemText`,z0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,className:r,style:i,...a}=e,o=n0(R0,n),s=b0(R0,n),c=I0(R0,n),l=i0(R0,n),[u,d]=L.useState(null),f=Ax(e=>s.itemTextRefCallback?.(e,c.value,c.disabled)),p=rx(t,d,c.onItemTextChange,f),m=u?.textContent,h=L.useMemo(()=>(0,R.jsx)(`option`,{value:c.value,disabled:c.disabled,children:m},c.value),[c.disabled,c.value,m]),{onNativeOptionAdd:g,onNativeOptionRemove:_}=l;return Gx(()=>(g(h),()=>_(h)),[g,_,h]),(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(Ex.span,{id:c.textId,...a,ref:p}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren&&!G0(o.value)?Rb.createPortal(a.children,o.valueNode):null]})},`SelectItemText`)),B0=`SelectItemIndicator`,V0=L.forwardRef(G1(function(e,t){let{__scopeSelect:n,...r}=e;return I0(B0,n).isSelected?(0,R.jsx)(Ex.span,{"aria-hidden":!0,...r,ref:t}):null},`SelectItemIndicator`)),H0=`SelectBubbleInput`,U0=L.forwardRef(G1(function({__scopeSelect:e,...t},n){let r=n0(H0,e),{value:i,onValueChange:a,required:o,disabled:s,name:c,autoComplete:l,form:u}=r,{nativeOptions:d,nativeSelectKey:f}=r,p=L.useRef(null),m=rx(n,p),h=i??``,g=U1(h),_=Array.from(d).some(e=>(e.props.value??``)===``);return L.useEffect(()=>{let e=p.current;if(!e)return;let t=window.HTMLSelectElement.prototype,n=Object.getOwnPropertyDescriptor(t,`value`).set;if(g!==h&&n){let t=new Event(`change`,{bubbles:!0});n.call(e,h),e.dispatchEvent(t)}},[g,h]),(0,R.jsxs)(Ex.select,{"aria-hidden":!0,required:o,tabIndex:-1,name:c,autoComplete:l,disabled:s,form:u,onChange:e=>a(e.target.value),...t,style:{...rT,...t.style},ref:m,defaultValue:h,children:[G0(i)&&!_?(0,R.jsx)(`option`,{value:``}):null,Array.from(d)]},f)},`SelectBubbleInput`));function W0(e){return typeof e==`function`}G1(W0,`isFunction`);function G0(e){return e===``||e===void 0}G1(G0,`shouldShowPlaceholder`);function K0(e){let t=Ax(e),n=L.useRef(``),r=L.useRef(0),i=L.useCallback(e=>{let i=n.current+e;t(i),G1((function e(t){n.current=t,window.clearTimeout(r.current),t!==``&&(r.current=window.setTimeout(()=>e(``),1e3))}),`updateSearch`)(i)},[t]),a=L.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return L.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}G1(K0,`useTypeaheadSearch`);function q0(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=J0(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}G1(q0,`findNextItem`);function J0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}G1(J0,`wrapArray`);var Y0=`\0empty`,X0=e=>e===``?Y0:e,Z0=e=>e===Y0?``:e;function Q0({value:e,defaultValue:t,onValueChange:n,...r}){return(0,R.jsx)(o0,{value:e===void 0?void 0:X0(e),defaultValue:t===void 0?void 0:X0(t),onValueChange:n&&(e=>n(Z0(e))),...r})}var $0=`inline-flex min-w-0 cursor-pointer items-center justify-between gap-1.5 text-left`,e2=`h-(--control-h) rounded-md border border-border bg-surface-inset px-2.5 text-sm text-text transition-colors duration-(--dur-1) ease-app hover:border-border-strong data-[state=open]:border-accent data-placeholder:text-text-tertiary disabled:cursor-not-allowed disabled:text-text-disabled`,t2=`h-(--control-sm) rounded-md px-1.5 text-xs text-text-tertiary transition-colors duration-(--dur-1) ease-app enabled:hover:bg-surface-hover enabled:hover:text-text data-[state=open]:bg-surface-selected data-[state=open]:text-text disabled:cursor-not-allowed disabled:text-text-disabled`;function n2({className:e,children:t,...n}){return(0,R.jsxs)(c0,{className:q($0,e),...n,children:[t,(0,R.jsx)(d0,{className:`shrink-0 text-icon`,children:(0,R.jsx)(wy,{size:14})})]})}function r2({className:e,...t}){return(0,R.jsx)(`span`,{className:q(`min-w-0 flex-1 truncate text-left`,e),children:(0,R.jsx)(u0,{...t})})}function i2({className:e,position:t=`popper`,sideOffset:n=4,collisionPadding:r=8,onEscapeKeyDown:i,children:a,...o}){return(0,R.jsx)(m0,{children:(0,R.jsx)(g0,{position:t,sideOffset:n,collisionPadding:r,onEscapeKeyDown:e=>{i?.(e),e.stopPropagation()},className:q(zb,`max-h-(--radix-select-content-available-height) min-w-32`,e),...o,children:(0,R.jsx)(O0,{className:`w-full min-w-(--radix-select-trigger-width) p-1`,children:a})})})}var a2=j0;function o2({className:e,...t}){return(0,R.jsx)(N0,{className:q(Ub,e),...t})}var s2=q(Bb,Vb,`justify-between gap-3 data-[state=checked]:font-medium`);function c2({className:e,children:t,value:n,...r}){return(0,R.jsxs)(L0,{value:X0(n),className:q(s2,e),...r,children:[(0,R.jsx)(z0,{children:t}),(0,R.jsx)(V0,{className:`inline-flex shrink-0 items-center`,children:(0,R.jsx)(by,{size:14,className:`text-text!`})})]})}function l2(e){return/\bimplementer[- ]only\b/i.test(e?.note??``)}function u2({value:e,roster:t,onChange:n,disabled:r=!1,label:i,ticketKind:a}){let o=t.find(t=>t.id===e),s=a===`review`&&l2(o),c=i??(o?`${o.id} · ${Rp[o.runtime]}`:e||`default model`),l=i??`Ticket model`;return(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-col items-end gap-1`,children:[(0,R.jsxs)(Q0,{value:e,onValueChange:n,children:[(0,R.jsx)(n2,{"aria-label":l,disabled:r,className:q(t2,`max-w-64 font-mono`),children:(0,R.jsx)(r2,{children:c})}),(0,R.jsxs)(i2,{"aria-label":l,className:`min-w-64 font-mono text-xs`,children:[(0,R.jsx)(c2,{value:``,children:`default (project model)`}),Hp(t).map(e=>(0,R.jsxs)(a2,{children:[(0,R.jsx)(o2,{children:e.label}),e.entries.map(e=>(0,R.jsxs)(c2,{value:e.id,children:[e.note?`${e.id} — ${e.note}`:e.id,a===`review`&&l2(e)?` — not recommended for review`:``]},e.id))]},e.runtime))]})]}),s&&(0,R.jsx)(`span`,{className:`text-xs text-warning`,children:`Implementer-only model — not recommended for review tickets`})]})}var d2=(0,L.createContext)(null);function f2({open:e,children:t}){return(0,R.jsx)(d2.Provider,{value:e,children:t})}function p2({location:e,children:t}){let n=(0,L.useContext)(d2);return n?(0,R.jsx)(`button`,{type:`button`,className:sE,onClick:t=>{t.stopPropagation(),n(e)},children:t}):(0,R.jsx)(R.Fragment,{children:t})}function m2({text:e}){let t=(0,L.useContext)(d2),n=jm(e);return!t||!n?(0,R.jsx)(R.Fragment,{children:e}):(0,R.jsxs)(R.Fragment,{children:[n.before,(0,R.jsx)(p2,{location:n.location,children:n.phrase}),n.after]})}function h2({ticket:e,busy:t,onCancel:n,onSave:r}){let[i,a]=(0,L.useState)(e.title),[o,s]=(0,L.useState)(e.goal),[c,l]=(0,L.useState)(e.context),[u,d]=(0,L.useState)(e.acceptanceCriteria.join(`
|
|
184
184
|
`)),f=u.split(`
|
|
185
185
|
`).map(e=>e.trim()).filter(Boolean),p=!!i.trim()&&!!o.trim()&&f.length>0;return(0,R.jsxs)(`div`,{className:`flex flex-col gap-4 pt-1 pr-3 pb-5 pl-10 animate-fade-in`,children:[(0,R.jsx)(AA,{label:`Title`,children:(0,R.jsx)(DA,{value:i,onChange:e=>a(e.target.value)})}),(0,R.jsx)(AA,{label:`Goal`,children:(0,R.jsx)(kA,{rows:3,value:o,onChange:e=>s(e.target.value)})}),(0,R.jsx)(AA,{label:`Context`,children:(0,R.jsx)(kA,{rows:3,value:c,onChange:e=>l(e.target.value)})}),(0,R.jsx)(AA,{label:`Acceptance`,help:`One criterion per line.`,children:(0,R.jsx)(kA,{rows:3,value:u,onChange:e=>d(e.target.value)})}),(0,R.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,R.jsx)(Y,{variant:`ghost`,onClick:n,disabled:t,children:`Cancel`}),(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(by,{}),disabled:!p||t,onClick:()=>r({title:i.trim(),goal:o.trim(),context:c.trim(),acceptanceCriteria:f}),children:t?`Saving…`:`Save ticket`})]})]})}var g2=new Set([`pending`,`failed`]);function _2({title:e,children:t}){return(0,R.jsxs)(`section`,{className:`flex flex-col gap-1`,children:[(0,R.jsx)(`h4`,{className:`m-0 text-xs font-medium text-text-tertiary`,children:e}),t]})}function v2({ticket:e,roster:t,readonly:n,onEdit:r,onModel:i,onCancel:a,onCopySha:o}){let[s,c]=(0,L.useState)(!1),[l,u]=(0,L.useState)(!1),[d,f]=(0,L.useState)(!1),[p,m]=(0,L.useState)(!1),h=g2.has(e.status),g=Rg(e,t),_=e.status===`cancelled`;return(0,R.jsxs)(`article`,{"data-list-row":``,children:[(0,R.jsx)(vA,{label:`${s?`Collapse`:`Expand`} ticket #${e.seq}`,expanded:s,onClick:()=>c(e=>!e),className:q(s&&`bg-surface-hover/50`),leading:(0,R.jsx)(`span`,{className:`inline-flex`,children:(0,R.jsx)(Ty,{size:12,className:q(`transition-transform duration-(--dur-2) ease-app`,s&&`rotate-90`)})}),title:(0,R.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,R.jsxs)(`span`,{className:`w-7 shrink-0 text-xs text-text-tertiary tabular-nums`,children:[`#`,e.seq]}),(0,R.jsx)(`span`,{className:q(`min-w-0 truncate`,_?`text-text-tertiary line-through`:`text-text`),children:e.title}),(0,R.jsx)(aA,{kind:e.kind}),e.blockedBy.length>0&&(0,R.jsxs)(`span`,{className:`shrink-0 text-xs text-text-tertiary`,title:`Runs after these tickets land`,children:[`after #`,e.blockedBy.join(`, #`)]})]}),control:h&&!n&&i?(0,R.jsx)(u2,{value:e.model??``,roster:t,onChange:t=>i(e.id,t)}):g&&(0,R.jsxs)(`span`,{className:`max-w-56 shrink truncate font-mono text-xs text-text-tertiary`,children:[g.id,` · `,g.runtimeLabel]}),meta:(0,R.jsx)(`span`,{className:`flex w-20 justify-end`,children:(0,R.jsx)(iA,{status:e.status})})}),s&&l&&r&&(0,R.jsx)(h2,{ticket:e,busy:p,onCancel:()=>u(!1),onSave:t=>{m(!0),r(e.id,t).then(()=>u(!1),()=>void 0).finally(()=>m(!1))}}),s&&!l&&(0,R.jsxs)(`div`,{className:`flex flex-col gap-4 pt-2 pr-3 pb-5 pl-[3.75rem] animate-fade-in`,children:[!n&&h&&r&&a&&(d?(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md bg-danger-subtle px-3 py-2 text-sm text-text-secondary`,children:[(0,R.jsxs)(`span`,{className:`mr-auto`,children:[`Cancel #`,e.seq,`? Tickets that depend on it treat it as done. Its text stays in the ledger.`]}),(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>f(!1),children:`Keep it`}),(0,R.jsx)(Y,{size:`sm`,variant:`danger`,onClick:()=>a(e.id),children:`Cancel ticket`})]}):(0,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,icon:(0,R.jsx)(Ay,{}),onClick:()=>u(!0),children:`Edit ticket`}),(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,icon:(0,R.jsx)(xy,{}),onClick:()=>f(!0),children:`Cancel ticket`})]})),(0,R.jsx)(_2,{title:`Goal`,children:(0,R.jsx)(PG,{source:e.goal})}),e.context&&(0,R.jsx)(_2,{title:`Context`,children:(0,R.jsx)(PG,{source:e.context})}),(0,R.jsx)(_2,{title:`Acceptance`,children:(0,R.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-5 text-sm text-text-secondary marker:text-text-tertiary`,children:e.acceptanceCriteria.map((e,t)=>(0,R.jsx)(`li`,{children:e},t))})}),e.seams.length>0&&(0,R.jsx)(_2,{title:`Seams`,children:(0,R.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 font-mono text-xs text-text-secondary`,children:e.seams.map((e,t)=>(0,R.jsx)(`span`,{children:e},t))})}),(0,R.jsx)(_2,{title:`Commits`,children:e.commits.length===0?(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary`,children:`No commits yet — the burn writes them`}):(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.commits.map(e=>o?(0,R.jsx)(`button`,{type:`button`,title:`Copy the full SHA`,className:`cursor-pointer rounded-sm bg-surface-inset px-1.5 py-0.5 font-mono text-xs text-text-secondary transition-colors duration-(--dur-1) hover:text-text`,onClick:()=>o(e),children:lh(e)},e):(0,R.jsx)(`span`,{className:`rounded-sm bg-surface-inset px-1.5 py-0.5 font-mono text-xs text-text-secondary`,children:lh(e)},e))})}),e.digest&&(0,R.jsx)(_2,{title:`Digest`,children:(0,R.jsx)(PG,{source:e.digest})}),e.status===`failed`&&e.error&&(0,R.jsxs)(`div`,{className:`rounded-md bg-danger-subtle px-3 py-2 text-sm`,children:[(0,R.jsx)(`div`,{className:`mb-1 text-xs font-medium text-danger`,children:`Error`}),(0,R.jsx)(m2,{text:e.error})]}),_&&e.error&&(0,R.jsx)(_2,{title:`Cancelled`,children:(0,R.jsx)(m2,{text:e.error})})]})]})}function y2(e,t){let n=e.filter(e=>e.lap===t&&e.status!==`cancelled`),r=[Kg(Gg(e,t)),`Lap ${t}`],i=n.filter(e=>e.status===`failed`).length,a=n.filter(e=>e.status===`burning`).length;return i&&r.push(`${i} failed`),a&&r.push(`${a} burning`),r.join(` · `)}function b2({tickets:e,currentLap:t,roster:n,readonly:r=!1,docs:i,sandbox:a,defaultModel:o,onDoc:s,onEdit:c,onModel:l,onBulkModel:u,onCancel:d,onCopySha:f}){let p=e.filter(e=>e.lap===t),m=p.filter(e=>e.status===`pending`);return(0,R.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[(0,R.jsxs)(`div`,{className:`mb-2 flex min-h-7 flex-wrap items-center gap-x-4 gap-y-1`,children:[(0,R.jsx)(xA,{items:[{text:y2(e,t)},!r&&!!a&&{text:`Sandbox ${a}`},!r&&!!o&&{text:o,mono:!0,title:`The project’s model for tickets with none of their own`}]}),(0,R.jsxs)(`span`,{className:`ml-auto flex items-center gap-1`,children:[s&&(0,R.jsx)(D1,{docs:i,onPick:s}),!r&&u&&(0,R.jsx)(u2,{value:``,roster:n,disabled:m.length===0,label:`Model for all pending`,onChange:u})]})]}),p.length===0&&(r?(0,R.jsx)(GA,{icon:(0,R.jsx)(Ny,{}),title:`No tickets in this lap`,compact:!0}):(0,R.jsx)(GA,{icon:(0,R.jsx)(Ny,{}),title:`No tickets yet`,hint:`The session breaks the spec into tickets — they appear here as they land.`,compact:!0})),e.length>0&&(0,R.jsx)(`div`,{className:`min-h-0 overflow-y-auto`,children:(0,R.jsx)(oj,{groups:Lg(e,t),currentLap:t,headClassName:`px-3`,meta:e=>{let{done:t,total:n}=Gg(e.rows.map(e=>({...e,landedLap:e.lap})),e.lap);return`${t} of ${n} done`},children:e=>(0,R.jsx)(yA,{divided:!0,children:e.map(e=>(0,R.jsx)(v2,{ticket:e,roster:n,readonly:r,onEdit:c,onModel:l,onCancel:d,onCopySha:f},e.id))})})}),!r&&(0,R.jsx)(`p`,{className:`mt-3 mb-0 text-xs text-text-tertiary`,children:`Edit and Cancel are available on pending and failed tickets until you burn.`})]})}function x2({full:e,effective:t,events:n,mapRailCollapsed:r,onToggleMapRail:i}){return e.tickets.length===0?(0,R.jsx)(O1,{featureId:e.feature.id,kind:`decisions`,docs:e.docs,mode:`static`}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(IA,{title:`Tickets`,children:(0,R.jsx)(S2,{full:e})}),e.feature.mapped&&(0,R.jsx)(IA,{title:`Map`,children:(0,R.jsx)(P1,{full:e,relPath:b_(e),collapsed:r,onToggle:i,readonly:!0,layout:`section`})})]})}function S2({full:e}){let t=B.settings.get.useQuery({projectId:e.feature.projectId});return(0,R.jsx)(b2,{tickets:e.tickets,currentLap:e.feature.lap,roster:Vp(t.data),readonly:!0,docs:e.docs})}function C2(){let e=Ab(),[t,n]=(0,L.useState)(null),r=(0,L.useRef)(null);return(0,L.useEffect)(()=>{r.current=t?.preview??null},[t]),(0,L.useEffect)(()=>()=>{r.current&&URL.revokeObjectURL(r.current)},[]),{staged:t,stage:async t=>{try{let e=await Gm(t),r={png:e,preview:URL.createObjectURL(e)};n(e=>(e&&URL.revokeObjectURL(e.preview),r))}catch(t){e.push(t instanceof Error?t.message:`that image could not be read`)}},drop:()=>{n(e=>(e&&URL.revokeObjectURL(e.preview),null))}}}function w2({preview:e,onDrop:t}){return(0,R.jsxs)(`div`,{className:`relative w-fit animate-rise-in`,children:[(0,R.jsx)(`img`,{src:e,alt:`the picture this note will carry`,className:`block h-[54px] w-24 rounded-md bg-surface-inset object-cover`}),(0,R.jsx)(`span`,{className:`absolute -top-2 -right-2 rounded-md bg-surface-raised shadow-popover`,children:(0,R.jsx)(nE,{size:`sm`,label:`Remove picture`,icon:(0,R.jsx)(xy,{}),onClick:t})})]})}function T2({onPick:e}){let t=(0,L.useRef)(null);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`input`,{ref:t,type:`file`,accept:`image/*`,className:`hidden`,"aria-label":`attach an image`,onChange:t=>{let n=t.target.files?.[0];n&&e(n),t.target.value=``}}),(0,R.jsx)(nE,{size:`sm`,label:`Attach image`,icon:(0,R.jsx)(db,{}),onClick:()=>t.current?.click()})]})}function E2({featureId:e,primary:t=!1}){let n=B.useUtils(),r=Ab(),[i,a]=(0,L.useState)(``),[o,s]=(0,L.useState)(!1),{staged:c,stage:l,drop:u}=C2(),[d,f]=(0,L.useState)(null),p=B.notes.add.useMutation(),m=e=>{c?f(e):l(e)},h=e=>{let t=Wm(e.clipboardData);t&&(e.preventDefault(),m(t))},g=async()=>{if(!(!i.trim()||o)){s(!0);try{let t=c?.png,o=await MF({createNote:()=>p.mutateAsync({featureId:e,text:i}),uploadScreenshot:async e=>{t&&await Km(e,t)}});o.uploadError&&r.push(`the note was saved, but its picture was not: ${o.uploadError}`),a(``),u(),n.notes.list.invalidate({featureId:e})}catch(e){r.push(e instanceof Error?e.message:`the note could not be saved`)}finally{s(!1)}}};return(0,R.jsxs)(`div`,{className:`flex flex-col gap-2`,onPaste:h,children:[(0,R.jsx)(kA,{rows:2,"aria-label":`what did you just see?`,className:`min-h-16`,placeholder:`What did you just see? Paste a screenshot straight in.`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||(e.preventDefault(),g())}}),c&&(0,R.jsx)(w2,{preview:c.preview,onDrop:u}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(T2,{onPick:m}),(0,R.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center gap-1 truncate text-xs text-text-tertiary`,children:[(0,R.jsx)(Gb,{children:`Shift`}),(0,R.jsx)(Gb,{children:`Enter`}),(0,R.jsx)(`span`,{className:`truncate`,children:`for a new line`})]}),(0,R.jsx)(Y,{size:`sm`,variant:t?`primary`:`secondary`,icon:(0,R.jsx)(yy,{}),disabled:!i.trim()||o,onClick:()=>void g(),children:o?`Adding…`:`Add note`})]}),(0,R.jsx)(O2,{open:!!d,onKeep:()=>f(null),onReplace:()=>{let e=d;f(null),e&&l(e)}})]})}function D2({note:e,onDone:t}){let n=B.useUtils(),r=Ab(),[i,a]=(0,L.useState)(e.text),[o,s]=(0,L.useState)(!1),[c,l]=(0,L.useState)(null),u=()=>void n.notes.list.invalidate({featureId:e.featureId}),d=B.notes.edit.useMutation({onSuccess:()=>{u(),t()},onError:e=>r.push(e.message)}),f=()=>{i.trim()&&!d.isPending&&d.mutate({noteId:e.id,text:i})},p=async t=>{s(!0);try{await Km(e.id,await Gm(t)),u()}catch(e){r.push(e instanceof Error?e.message:`that picture could not be attached`)}finally{s(!1)}},m=t=>{e.screenshotUrl?l(t):p(t)};return(0,R.jsxs)(`div`,{className:`flex flex-col gap-2`,onPaste:e=>{let t=Wm(e.clipboardData);t&&(e.preventDefault(),m(t))},children:[(0,R.jsx)(kA,{rows:2,"aria-label":`edit this note`,className:`min-h-16`,value:i,autoFocus:!0,onChange:e=>a(e.target.value),onKeyDown:e=>{if(e.key===`Escape`){e.preventDefault(),t();return}e.key!==`Enter`||e.shiftKey||(e.preventDefault(),f())}}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(T2,{onPick:m}),o&&(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary`,children:`Attaching…`}),(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:t,children:`Cancel`}),(0,R.jsx)(Y,{size:`sm`,disabled:!i.trim()||d.isPending,onClick:f,children:`Save`})]}),(0,R.jsx)(O2,{open:!!c,onKeep:()=>l(null),onReplace:()=>{let e=c;l(null),e&&p(e)}})]})}function O2({open:e,onKeep:t,onReplace:n}){return(0,R.jsxs)(QA,{open:e,onClose:t,size:`sm`,label:`Replace this note’s picture?`,children:[(0,R.jsx)($A,{title:`Replace this note’s picture?`,description:`A note carries one picture. Keep both by writing a second note.`}),(0,R.jsxs)(tj,{children:[(0,R.jsx)(Y,{variant:`ghost`,onClick:t,children:`Keep the old one`}),(0,R.jsx)(Y,{variant:`danger`,onClick:n,children:`Replace`})]})]})}function k2({note:e,onClose:t}){let n=B.useUtils(),r=Ab(),i=B.notes.remove.useMutation({onSuccess:()=>{e&&n.notes.list.invalidate({featureId:e.featureId}),t()},onError:e=>{r.push(e.message),t()}});return(0,R.jsxs)(QA,{open:!!e,onClose:t,size:`sm`,label:`Delete this note and its picture?`,children:[(0,R.jsx)($A,{title:`Delete this note and its picture?`,description:`There is no undo.`}),(0,R.jsxs)(tj,{children:[(0,R.jsx)(Y,{variant:`ghost`,onClick:t,children:`Keep it`}),(0,R.jsx)(Y,{variant:`danger`,disabled:i.isPending,onClick:()=>e&&i.mutate({noteId:e.id}),children:`Delete`})]})]})}function A2(e,t,n){return t.has(e.id)?`open`:e.status===`dismissed`?`dismissed`:e.status===`carried`?`carried`:e.status===`fixed`||n?.status===`done`?`fixed`:n&&n.status!==`failed`&&n.status!==`cancelled`?`fixing`:e.status===`open`||e.status===`failed`?`open`:`fixing`}function j2(e,t){if(e.item.kind!==t.item.kind)return e.item.kind===`defect`?-1:1;let n=e.item.kind===`note`?e.item.note.createdAt:e.item.finding.createdAt;return(t.item.kind===`note`?t.item.note.createdAt:t.item.finding.createdAt)-n}function M2(e){let t=new Set(e.openDefects.map(e=>e.id)),n=t=>t?e.tickets.find(e=>e.id===t):void 0,r=[],i=[],a=(e,t,n)=>{(n?r:i).push({lap:PF(e),item:e,open:t})};for(let r of e.findings){if(r.kind!==`defect`)continue;let e=n(r.fixTicketId),i=A2(r,t,e);i!==`carried`&&a({kind:`defect`,finding:r,...i===`fixing`&&e?{fixTicket:{id:e.id,seq:e.seq}}:{}},i===`open`,i===`open`||i===`fixing`)}for(let t of e.notes){let e=n(t.ticketId??null);a({kind:`note`,note:t,...e?{ticket:{seq:e.seq,title:e.title}}:{}},t.status===`open`,t.status===`open`)}return r.sort(j2),i.sort(j2),{attention:r,settled:i}}function N2({featureId:e,rows:t,readonly:n,currentLap:r,onStage:i,onSeek:a,onViewLane:o,highlight:s,scrollTo:c,scroller:l}){let u=B.useUtils(),d=Ab(),[f,p]=(0,L.useState)(null),[m,h]=(0,L.useState)(null),[g,_]=(0,L.useState)(null),v=e=>d.push(e.message),y=()=>void u.notes.list.invalidate({featureId:e}),b=()=>void u.findings.listByFeature.invalidate({featureId:e}),x=B.findings.dismiss.useMutation({onSuccess:b,onError:v}),S=B.findings.reopen.useMutation({onSuccess:b,onError:v}),C=B.notes.toggle.useMutation({onSuccess:y,onError:v}),w=B.notes.reopen.useMutation({onSuccess:y,onError:v}),T=C.isPending||w.isPending;(0,L.useEffect)(()=>{if(!c)return;let e=document.getElementById(FF(c));if(!e)return;let t=l?.current;if(!t){e.scrollIntoView({behavior:`smooth`,block:`nearest`});return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();t.scrollBy({top:n.top-r.top-(r.height-n.height)/2,behavior:`smooth`})},[c,t,l]);let E=new Set(s??[]),D=e=>(0,R.jsx)(RF,{item:e.item,onStage:i,readonly:n,showLap:r===void 0,highlighted:E.has(NF(e.item)),editor:e.item.kind===`note`&&f===e.item.note.id?(0,R.jsx)(D2,{note:e.item.note,onDone:()=>p(null)}):void 0,controls:O(e),onSeek:a,onOpenImage:_,onViewLane:o},NF(e.item));function O(e){let{item:t}=e;if(t.kind===`defect`){let n=t.finding.id,r=(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,icon:(0,R.jsx)(xy,{}),disabled:x.isPending,onClick:()=>x.mutate({findingId:n}),children:`Dismiss`});return t.finding.status===`carried`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,icon:(0,R.jsx)(Cy,{}),disabled:S.isPending,onClick:()=>S.mutate({findingId:n}),children:`Reopen`}),r]}):e.open?r:void 0}let n=t.note;if(n.status===`promoted`)return;if(n.status===`carried`)return(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,icon:(0,R.jsx)(Cy,{}),disabled:T,onClick:()=>w.mutate({noteId:n.id}),children:`Reopen`});if(f===n.id)return;let r=n.status===`done`;return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(nE,{size:`sm`,label:r?`Mark not done`:`Mark done`,icon:(0,R.jsx)(by,{}),active:r,disabled:T,onClick:()=>C.mutate({noteId:n.id})}),n.status===`open`&&(0,R.jsxs)(DP,{children:[(0,R.jsx)(OP,{asChild:!0,children:(0,R.jsx)(nE,{size:`sm`,label:`Note actions`,icon:(0,R.jsx)(Ey,{})})}),(0,R.jsxs)(kP,{align:`end`,children:[(0,R.jsx)(AP,{icon:(0,R.jsx)(Ay,{}),onSelect:()=>p(n.id),children:`Edit`}),(0,R.jsx)(AP,{tone:`danger`,icon:(0,R.jsx)(Sy,{}),onSelect:()=>h(n),children:`Delete`})]})]})]})}return(0,R.jsxs)(`div`,{className:`flex flex-col`,children:[r===void 0?t.map(e=>D(e)):(0,R.jsx)(oj,{groups:Lg(t,r),currentLap:r,meta:e=>`${e.rows.length} open`,children:e=>e.map(e=>D(e))}),(0,R.jsx)(CF,{url:g,onClose:()=>_(null)}),(0,R.jsx)(k2,{note:m,onClose:()=>h(null)})]})}function P2({featureId:e,findings:t,readonly:n}){if(t.length===0)return null;let r=t.map(e=>({lap:e.lap,item:{kind:`defect`,finding:e},open:!1}));return(0,R.jsxs)(`section`,{id:`carried-findings`,className:`flex flex-col gap-2`,children:[(0,R.jsxs)(`div`,{className:`flex min-h-7 items-baseline gap-3`,children:[(0,R.jsx)(`h2`,{className:`m-0 text-lg font-semibold text-text`,children:`Carried, still open`}),(0,R.jsxs)(`span`,{className:`text-xs text-text-tertiary`,children:[t.length,` carried, not counted as open`]})]}),(0,R.jsx)(N2,{featureId:e,rows:r,readonly:n,onStage:null})]})}var F2={danger:`bg-danger-subtle px-3 py-2.5`,accent:`bg-accent-subtle px-3 py-2.5`,warning:`py-1`,quiet:`py-1`},I2={danger:`text-danger`,accent:`text-warning`,warning:`text-warning`,quiet:`text-icon`};function L2({tone:e,icon:t,title:n,meta:r,children:i,actions:a,role:o=`alert`,className:s}){let c=t??(e===`quiet`?(0,R.jsx)(nb,{}):(0,R.jsx)(tb,{}));return(0,R.jsxs)(`div`,{role:o,className:q(`flex items-start gap-3 rounded-md text-sm animate-rise-in`,F2[e],s),children:[(0,R.jsx)(`span`,{"aria-hidden":!0,className:q(`mt-0.5 inline-flex size-4 shrink-0 items-center justify-center [&>svg]:size-4`,I2[e]),children:c}),(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1`,children:[(0,R.jsxs)(`div`,{className:`flex min-h-5 flex-wrap items-baseline gap-x-2`,children:[(0,R.jsx)(`span`,{className:`font-medium text-text`,children:n}),r&&(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary`,children:r})]}),i&&(0,R.jsx)(`div`,{className:`text-sm text-pretty text-text-secondary`,children:i})]}),a&&(0,R.jsx)(`div`,{className:`-my-0.5 flex shrink-0 items-center gap-1.5`,children:a})]})}function R2({branch:e,conflict:t,readonly:n,liveSessionId:r,resolveEnded:i,busy:a,onResolve:o}){return n?null:(0,R.jsxs)(L2,{tone:`danger`,title:`Merge conflict`,meta:(0,R.jsxs)(`span`,{title:oh(t.at),children:[`recorded `,ph(t.at)]}),actions:(0,R.jsx)(Y,{size:`sm`,icon:(0,R.jsx)(Ky,{}),disabled:a,onClick:o,children:r?`End session & resolve`:`Resolve with agent`}),children:[(0,R.jsxs)(`p`,{className:`m-0`,children:[`Merging `,(0,R.jsx)(`code`,{className:`font-mono text-xs`,children:t.base}),` into`,` `,(0,R.jsx)(`code`,{className:`font-mono text-xs`,children:e}),` hit conflicts. An agent can merge the base into this branch in the talk worktree, resolve with full spec context, and commit — then retry Merge & ship.`]}),t.files.length>0&&(0,R.jsx)(`ul`,{className:`m-0 mt-2 flex list-none flex-col gap-0.5 p-0`,children:t.files.map(e=>(0,R.jsx)(`li`,{className:`truncate font-mono text-xs text-danger`,title:e,children:e},e))}),i&&(0,R.jsx)(`p`,{className:`m-0 mt-2 text-warning`,children:`The resolve session ended but the merge hasn’t landed — resolve by hand or retry.`}),r&&(0,R.jsx)(`p`,{className:`m-0 mt-2 text-xs text-text-tertiary`,children:`One terminal per feature — your live session will be closed to open the resolve session.`})]})}function z2({featureId:e,branch:t,conflict:n,readonly:r,liveSessionId:i,resolveEnded:a}){let o=mF(e,t);return(0,R.jsx)(R2,{branch:t,conflict:n,readonly:r,liveSessionId:i,resolveEnded:a,busy:o.pending,onResolve:()=>void o.resolve(n,i??void 0)})}function B2({text:e}){let t=e?.trim();return t?(0,R.jsxs)(JA,{title:`How to drive this app`,icon:(0,R.jsx)(Dy,{}),aside:(0,R.jsx)(p2,{location:{page:`project`,field:`driveInstructions`},children:`Edit in settings`}),children:[(0,R.jsx)(PG,{source:t}),(0,R.jsx)(`p`,{className:`m-0 mt-2 text-xs text-text-tertiary`,children:Xp})]}):null}function V2({featureId:e,label:t}){let n=B.useUtils(),r=Ab(),i=B.feature.testDrive.useMutation({onSuccess:()=>{n.feature.driveInfo.invalidate(),n.feature.get.invalidate({id:e})},onError:e=>r.push(e.message)});return(0,R.jsx)(Y,{className:`self-start`,icon:(0,R.jsx)(Ry,{}),loading:i.isPending,onClick:()=>i.mutate({featureId:e,action:`stop`}),children:t})}function H2({featureId:e,failure:t,readonly:n}){let r=B.useUtils(),i=Ab(),a=B.feature.fixDrive.useMutation({onSuccess:()=>{r.feature.get.invalidate({id:e}),r.events.invalidate()},onError:e=>i.push(e.message)});return(0,R.jsx)(U2,{failure:t,explanation:(0,R.jsxs)(R.Fragment,{children:[`The branch is checked out, but `,(0,R.jsx)(`code`,{className:`font-mono`,children:t.command}),` `,t.outcome,` — so whatever it was meant to bring up is probably not running. An agent can read this failure on your machine, repair the environment and retry the drive.`]}),children:!n&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.canFix&&(0,R.jsx)(Y,{icon:(0,R.jsx)(ab,{}),loading:a.isPending,onClick:()=>a.mutate({featureId:e}),children:`Fix drive`}),(0,R.jsx)(V2,{featureId:e,label:`Stop test drive`})]})})}function U2({failure:e,explanation:t,children:n}){return(0,R.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,R.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,R.jsx)(rA,{tone:`danger`,size:`sm`,strong:!0,children:`Drive setup failed`}),(0,R.jsx)(`div`,{className:`text-sm text-pretty text-text-secondary`,children:t})]}),e.output&&(0,R.jsx)(JA,{title:`What the command printed`,icon:(0,R.jsx)(Dy,{}),children:(0,R.jsx)(`pre`,{className:`m-0 max-h-55 overflow-auto rounded-md bg-surface-inset px-3 py-2.5 font-mono text-xs whitespace-pre-wrap text-text-secondary`,children:e.output})}),n]})}function W2({branch:e,drive:t}){let[n,r]=(0,L.useState)(!1),i=B_(t);return(0,R.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,R.jsxs)(`div`,{className:`flex min-h-7 flex-wrap items-center gap-x-4 gap-y-1 text-xs text-text-tertiary`,children:[t?.devPaneId&&(0,R.jsx)(rA,{tone:`live`,children:`Dev server`}),(0,R.jsx)(`span`,{className:`truncate font-mono`,children:e}),i&&(0,R.jsx)(`span`,{className:`truncate font-mono`,children:i.state===`ready`?i.url:V_(i)}),(0,R.jsx)(`span`,{className:`flex-1`}),t?.devPaneId&&(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,icon:(0,R.jsx)(Dy,{}),"aria-expanded":n,onClick:()=>r(e=>!e),children:n?`Hide output`:`Show output`})]}),n&&t?.devPaneId&&(0,R.jsx)(`div`,{className:`relative h-105 min-h-65 overflow-hidden rounded-md bg-surface-inset animate-rise-in`,children:(0,R.jsx)(LG,{label:`dev terminal`,children:(0,R.jsx)(_1,{sessionId:t.devPaneId})})})]})}function G2(e){let t=e;return t?.tagName===`INPUT`||t?.tagName===`TEXTAREA`||t?.isContentEditable===!0}function K2(e,t){let n=e?.expanded??!1,r=e?.set;(0,L.useEffect)(()=>{if(!t||!r)return;let e=e=>{G2(e.target)||e.metaKey||e.ctrlKey||e.altKey||(e.key===`f`||e.key===`F`?(e.preventDefault(),r(!n)):e.key===`Escape`&&n&&(e.preventDefault(),r(!1)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,n,r])}var q2=(e=`pen`)=>({tool:e,shapes:[],redo:[],text:``});function J2(e,t){return{...e,shapes:[...e.shapes,{tool:e.tool,points:[t]}],redo:[]}}function Y2(e,t){if(e.shapes.length===0)return e;let n=e.shapes.slice(),r=n[n.length-1];return n[n.length-1]={...r,points:[...r.points,t]},{...e,shapes:n}}function X2(e){return e}function Z2(e){let t=e.shapes.at(-1);return t?{...e,shapes:e.shapes.slice(0,-1),redo:[...e.redo,t]}:e}function Q2(e){let t=e.redo.at(-1);return t?{...e,shapes:[...e.shapes,t],redo:e.redo.slice(0,-1)}:e}var $2=e=>({...e,shapes:[],redo:[]}),e4=(e,t)=>({...e,tool:t}),t4=(e,t)=>({...e,text:t}),n4=e=>e.shapes.length>0||e.text.trim().length>0,r4=n4;function i4(e,t){switch(t.kind){case`begin`:return J2(e,t.point);case`extend`:return Y2(e,t.point);case`commit`:return X2(e);case`undo`:return Z2(e);case`redo`:return Q2(e);case`clear`:return $2(e);case`tool`:return e4(e,t.tool);case`text`:return t4(e,t.text)}}var a4=[{tool:`pen`,label:`Pen`,key:`P`,icon:(0,R.jsx)(fb,{})},{tool:`arrow`,label:`Arrow`,key:`A`,icon:(0,R.jsx)(pb,{})},{tool:`rect`,label:`Rect`,key:`R`,icon:(0,R.jsx)(mb,{})}],o4=`pointer-events-auto flex items-center gap-0.5 rounded-lg bg-surface-raised p-1 shadow-popover`,s4={p:`pen`,a:`arrow`,r:`rect`};function c4({video:e,timestamp:t,onSave:n,onCancel:r}){let[i,a]=(0,L.useReducer)(i4,void 0,()=>q2()),[o,s]=(0,L.useState)(!1),[c,l]=(0,L.useState)(!1),[u,d]=(0,L.useState)(null),f=(0,L.useRef)(null),p=(0,L.useRef)(!1),m=e=>{let t=e.getBoundingClientRect();return t.width>0?e.width/t.width:1};(0,L.useEffect)(()=>{let t=f.current;if(!t)return;t.width!==e.videoWidth&&(t.width=e.videoWidth),t.height!==e.videoHeight&&(t.height=e.videoHeight);let n=t.getContext(`2d`);n&&(n.clearRect(0,0,t.width,t.height),TF(n,i.shapes,m(t)))},[i.shapes,e]);let h=e=>{let t=f.current;return t?AF(t.getBoundingClientRect(),{width:t.width,height:t.height},{x:e.clientX,y:e.clientY}):null},g=e=>{let t=h(e);t&&(f.current?.setPointerCapture?.(e.pointerId),p.current=!0,a({kind:`begin`,point:t}))},_=e=>{if(!p.current)return;let t=h(e);t&&a({kind:`extend`,point:t})},v=e=>{if(!p.current)return;p.current=!1;let t=f.current;t?.hasPointerCapture?.(e.pointerId)&&t.releasePointerCapture(e.pointerId),a({kind:`commit`})},y=()=>{r4(i)?l(!0):r()},b=async()=>{let t=f.current;if(!(!n4(i)||o||!t)){s(!0),d(null);try{await n(await jF(document.createElement(`canvas`),e,i.shapes,m(t)),i.text.trim())}catch(e){d(e instanceof Error?e.message:`the annotated frame could not be saved`)}finally{s(!1)}}};return(0,L.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){e.preventDefault(),c?l(!1):y();return}let t=e.target;if(t?.tagName===`INPUT`||t?.tagName===`TEXTAREA`||t?.isContentEditable===!0||e.metaKey||e.ctrlKey||e.altKey)return;let n=s4[e.key.toLowerCase()];n&&(e.preventDefault(),a({kind:`tool`,tool:n}))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[c,i,r]),(0,R.jsxs)(`div`,{className:`absolute inset-0 z-20`,"data-testid":`annotation-overlay`,children:[(0,R.jsx)(`canvas`,{ref:f,"aria-label":`draw on this frame`,className:`absolute inset-0 h-full w-full cursor-crosshair touch-none`,onPointerDown:g,onPointerMove:_,onPointerUp:v,onPointerCancel:v}),(0,R.jsxs)(`div`,{className:`pointer-events-none absolute inset-x-0 top-0 flex flex-wrap items-center gap-2 p-3 animate-fade-in`,children:[(0,R.jsxs)(`div`,{className:o4,children:[a4.map(({tool:e,label:t,key:n,icon:r})=>(0,R.jsx)(nE,{label:t,kbd:n,icon:r,active:i.tool===e,tooltipSide:`bottom`,onClick:()=>a({kind:`tool`,tool:e})},e)),(0,R.jsx)(`span`,{"aria-hidden":!0,className:`mx-1 h-4 w-px bg-border`}),(0,R.jsx)(nE,{label:`Undo`,icon:(0,R.jsx)(Cy,{}),tooltipSide:`bottom`,disabled:i.shapes.length===0,onClick:()=>a({kind:`undo`})}),(0,R.jsx)(nE,{label:`Redo`,icon:(0,R.jsx)(hb,{}),tooltipSide:`bottom`,disabled:i.redo.length===0,onClick:()=>a({kind:`redo`})}),(0,R.jsx)(nE,{label:`Clear`,icon:(0,R.jsx)(Sy,{}),tooltipSide:`bottom`,disabled:i.shapes.length===0,onClick:()=>a({kind:`clear`})})]}),(0,R.jsx)(`span`,{className:`pointer-events-none rounded-md bg-surface-raised px-2 py-1 font-mono text-xs text-text-secondary tabular-nums shadow-popover`,children:Hd(t)})]}),(0,R.jsxs)(`div`,{className:`absolute inset-x-3 bottom-3 flex flex-col gap-2 rounded-lg bg-surface-raised p-2 shadow-popover animate-rise-in`,children:[u&&(0,R.jsx)(`p`,{className:`m-0 px-1 text-sm text-danger`,role:`alert`,children:u}),(0,R.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,R.jsx)(kA,{rows:2,"aria-label":`what’s wrong in this frame?`,className:`min-w-0 flex-1 resize-none`,placeholder:`What’s wrong in this frame? A drawing alone saves too.`,value:i.text,autoFocus:!0,onChange:e=>a({kind:`text`,text:e.target.value}),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||(e.preventDefault(),b())}}),(0,R.jsx)(Y,{variant:`ghost`,onClick:y,children:`Cancel`}),(0,R.jsx)(Y,{variant:`primary`,loading:o,disabled:!n4(i),onClick:()=>void b(),children:o?`Saving…`:`Save note`})]})]}),(0,R.jsxs)(QA,{open:c,onClose:()=>l(!1),size:`sm`,label:`Discard this annotation?`,children:[(0,R.jsx)($A,{title:`Discard this annotation?`,description:`The drawing and the words go with it.`}),(0,R.jsxs)(tj,{children:[(0,R.jsx)(Y,{variant:`ghost`,onClick:()=>l(!1),children:`Keep editing`}),(0,R.jsx)(Y,{variant:`danger`,onClick:r,children:`Discard`})]})]})]})}var l4=[.5,.75,1,1.25,1.5,1.75,2],u4=1.5,d4=5,f4=1/30;function p4(e,t){let n=l4.indexOf(e);return l4[((n===-1?l4.indexOf(u4):n)+t+l4.length)%l4.length]}function m4({url:e,featureId:t,ticketId:n,passKind:r,readonly:i,frameClassName:a,expand:o,markers:s=[],onMarkerClick:c,onAnnotationSaved:l,onDuration:u,handleRef:d}){let f=B.useUtils(),p=Ab(),m=(0,L.useRef)(null),[h,g]=(0,L.useState)(!1),[_,v]=(0,L.useState)(0),[y,b]=(0,L.useState)(0),[x,S]=(0,L.useState)(u4),[C,w]=(0,L.useState)(`loading`),[T,E]=(0,L.useState)(null),[D,O]=(0,L.useState)(!1),[k,A]=(0,L.useState)(null),j=B.notes.add.useMutation({onError:e=>p.push(e.message)});(0,L.useEffect)(()=>{let t=!0;return fetch(e,{method:`HEAD`}).then(e=>{let n=Number(e.headers.get(`content-length`));t&&Number.isFinite(n)&&n>0&&E(n)}).catch(()=>void 0),()=>{t=!1}},[e]);let M=(0,L.useCallback)(e=>{let t=m.current;if(!t)return;let n=kF(e,{playable:OF(t),annotating:D});n!==null&&(t.currentTime=n,v(n))},[D]),N=(0,L.useCallback)(e=>{m.current?.pause(),M(e)},[M]);(0,L.useEffect)(()=>{if(d)return d.current={seek:N,pause:()=>m.current?.pause(),getTicketId:()=>n},()=>{d.current=null}},[d,N,n]);let P=(0,L.useCallback)(()=>{let e=m.current;!e||D||C!==`ready`||(e.paused?e.play().catch(()=>p.push(`the browser refused to play this recording`)):e.pause())},[D,C,p]),F=(0,L.useCallback)(e=>{let t=m.current;t&&M(t.currentTime+e)},[M]),ee=(0,L.useCallback)(e=>{let t=m.current;t?.paused&&M(t.currentTime+e)},[M]),te=(0,L.useCallback)(e=>{S(e);let t=m.current;t&&(t.playbackRate=e)},[]),ne=()=>{C===`ready`&&(m.current?.pause(),O(!0))};K2(o,!D),(0,L.useEffect)(()=>{if(D)return;let e=e=>{if(G2(e.target)||e.metaKey||e.ctrlKey||e.altKey)return;let t=()=>e.preventDefault();switch(e.key){case` `:case`k`:case`K`:return t(),P();case`j`:case`J`:case`ArrowLeft`:return t(),F(-5);case`l`:case`L`:case`ArrowRight`:return t(),F(d4);case`,`:return t(),ee(-.03333333333333333);case`.`:return t(),ee(f4);case`<`:return t(),te(p4(x,-1));case`>`:return t(),te(p4(x,1))}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[D,P,F,ee,te,x]);let I=()=>{w(`loading`),m.current?.load()},re=async(e,r)=>{let i=m.current;if(!i)return;let a=i.currentTime,o=await MF({createNote:()=>j.mutateAsync({featureId:t,text:r||`Annotated ${Hd(a)}`,videoTimestamp:a,reviewTicketId:n}),uploadScreenshot:t=>Km(t,e)});f.notes.list.invalidate({featureId:t}),o.uploadError&&p.push(`the note was saved, but its annotated frame was not: ${o.uploadError}`),O(!1),l?.(o.note.id)},ie=e=>{let t=OF(e);b(t),u?.(t)},ae=y>0&&!D&&C===`ready`,oe=T===null?`Loading the recording`:`Loading the recording — ${dh(T)}`;return(0,R.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-2 animate-fade-in`,children:[(0,R.jsxs)(`div`,{className:a,children:[(0,R.jsx)(`video`,{ref:m,className:`min-h-0 w-full flex-1 cursor-pointer object-contain`,src:e,preload:`metadata`,"aria-label":r===`verification`?`verification walkthrough`:`review walkthrough`,onClick:P,onLoadedMetadata:e=>{let t=e.currentTarget;ie(t),t.playbackRate=x,t.currentTime===0&&(t.currentTime=.01)},onDurationChange:e=>ie(e.currentTarget),onProgress:e=>ie(e.currentTarget),onCanPlay:()=>w(e=>e===`error`?e:`ready`),onError:()=>w(`error`),onTimeUpdate:e=>v(e.currentTarget.currentTime),onPlay:()=>g(!0),onPause:()=>g(!1),onEnded:()=>g(!1)}),C===`loading`&&(0,R.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-2 bg-surface-inset/70 animate-fade-in`,children:[(0,R.jsx)(aE,{}),(0,R.jsx)(`span`,{className:`text-sm text-text-secondary`,children:oe})]}),C===`error`&&(0,R.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-1.5 bg-surface-inset px-6 text-center animate-fade-in`,role:`alert`,children:[(0,R.jsx)(`span`,{className:`text-base font-medium text-text`,children:`This recording can’t be played`}),(0,R.jsx)(`span`,{className:`text-sm text-text-tertiary`,children:`The file may be corrupt.`}),(0,R.jsx)(`code`,{className:`max-w-full truncate font-mono text-xs text-text-tertiary`,children:e}),(0,R.jsx)(Y,{className:`mt-2`,icon:(0,R.jsx)(ab,{}),onClick:I,children:`Retry`})]}),D&&m.current&&(0,R.jsx)(c4,{video:m.current,timestamp:_,onSave:re,onCancel:()=>O(!1)})]}),(0,R.jsxs)(`div`,{className:`flex h-(--control-lg) items-center gap-3`,children:[(0,R.jsx)(nE,{label:h?`pause`:`play`,kbd:`K`,icon:h?(0,R.jsx)(cb,{}):(0,R.jsx)(Ly,{}),disabled:D||C!==`ready`,onClick:P}),(0,R.jsx)(`span`,{className:`shrink-0 font-mono text-xs text-text-secondary tabular-nums`,children:Hd(_)}),(0,R.jsxs)(`div`,{className:`relative flex h-full flex-1 items-center`,onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();t.width<=0||y<=0||A((e.clientX-t.left)/t.width*y)},onMouseLeave:()=>A(null),children:[(0,R.jsx)(`input`,{type:`range`,className:`h-1 w-full cursor-pointer accent-accent disabled:cursor-default disabled:opacity-50`,min:0,step:1,max:y||1,value:Math.min(_,y||1),disabled:!ae,"aria-label":`scrub the walkthrough`,onChange:e=>M(Number(e.target.value))}),k!==null&&(0,R.jsx)(`span`,{className:`pointer-events-none absolute -top-5 -translate-x-1/2 rounded-sm bg-surface-raised px-1.5 font-mono text-xs text-text-secondary tabular-nums shadow-popover`,style:{left:`${Math.min(100,Math.max(0,k/(y||1)*100))}%`},children:Hd(k)}),y>0&&s.map(e=>(0,R.jsx)(`button`,{type:`button`,className:e.noteIds.length>1?`absolute top-1/2 flex size-4 -translate-x-1/2 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full bg-accent text-xs leading-none text-on-primary transition-transform duration-(--dur-1) ease-app hover:scale-110`:`absolute top-1/2 size-2.5 -translate-x-1/2 -translate-y-1/2 cursor-pointer rounded-full bg-accent ring-2 ring-surface transition-transform duration-(--dur-1) ease-app hover:scale-125`,style:{left:`${Math.min(100,e.at/y*100)}%`},"aria-label":`${e.noteIds.length} note${e.noteIds.length>1?`s`:``} at ${Hd(e.at)}`,title:`${e.noteIds.length} note${e.noteIds.length>1?`s`:``} at ${Hd(e.at)}`,onClick:()=>{N(e.at),c?.(e.noteIds)},children:e.noteIds.length>1?e.noteIds.length:``},e.at))]}),(0,R.jsx)(`span`,{className:`shrink-0 font-mono text-xs text-text-tertiary tabular-nums`,children:Hd(y)}),(0,R.jsxs)(Y,{size:`sm`,variant:`ghost`,className:`font-mono tabular-nums`,"aria-label":`playback speed ${x}×`,title:`Playback speed (< and >)`,onClick:()=>te(p4(x,1)),children:[x,`×`]}),!i&&!D&&(0,R.jsx)(Y,{size:`sm`,icon:(0,R.jsx)(Ay,{}),onClick:ne,children:`Annotate`})]})]})}function h4(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),width:Math.abs(t.x-e.x),height:Math.abs(t.y-e.y)}}function g4(e,t,n,r){let i=r>0&&n>0?n/r:1;return{x:Math.round((e.x+t.left)*i),y:Math.round((e.y+t.top)*i),width:Math.round(e.width*i),height:Math.round(e.height*i)}}function _4(e){return e.width>=8&&e.height>=8}function v4(e){return e?typeof e.mediaDevices?.getDisplayMedia==`function`&&`userAgentData`in e:!1}var y4=6e3,b4=120;function x4(e){return new Promise(t=>{if(typeof e.requestVideoFrameCallback==`function`){e.requestVideoFrameCallback(()=>t());return}setTimeout(t,b4)})}function S4({url:e,agentDriving:t=!1,readonly:n=!1,...r}){let i=Ab(),a=B.useUtils(),o=B.notes.add.useMutation(),s=(0,L.useRef)(null),c=(0,L.useRef)(null),l=(0,L.useRef)(null),[u]=(0,L.useState)(()=>!n&&v4(typeof navigator>`u`?void 0:navigator)),[d,f]=(0,L.useState)(!1),[p,m]=(0,L.useState)(!1),[h,g]=(0,L.useState)(null),_=(0,L.useRef)(null),[v,y]=(0,L.useState)(null),[b,x]=(0,L.useState)(``),[S,C]=(0,L.useState)(!1),[w,T]=(0,L.useState)(!1),[E,D]=(0,L.useState)(!1),[O,k]=(0,L.useState)(0);(0,L.useEffect)(()=>{T(!1),D(!1);let e=setTimeout(()=>D(!0),y4);return()=>clearTimeout(e)},[e,O]),(0,L.useEffect)(()=>()=>{l.current?.getTracks().forEach(e=>e.stop()),l.current=null},[]),(0,L.useEffect)(()=>()=>URL.revokeObjectURL(v?.preview??``),[v]);let A=async()=>{if(!l.current){f(!0);try{let e=await navigator.mediaDevices.getDisplayMedia({video:{displaySurface:`browser`},audio:!1,preferCurrentTab:!0,selfBrowserSurface:`include`});l.current=e,e.getVideoTracks().forEach(t=>{t.addEventListener(`ended`,()=>{l.current===e&&(l.current=null)})});let t=c.current;t&&(t.srcObject=e,await t.play())}catch(e){i.push(e instanceof Error&&e.name===`NotAllowedError`?`tab sharing was declined — nothing to capture from`:`tab capture failed: ${e instanceof Error?e.message:String(e)}`);return}finally{f(!1)}}m(!0)},j=async e=>{let t=s.current,n=c.current;if(!t||!n)return;if(await new Promise(requestAnimationFrame),await new Promise(requestAnimationFrame),await x4(n),!n.videoWidth){i.push(`the tab is no longer being shared — click Select area again`),l.current=null;return}let r=g4(e,t.getBoundingClientRect(),n.videoWidth,window.innerWidth),a=document.createElement(`canvas`);a.width=r.width,a.height=r.height;let o=a.getContext(`2d`);if(!o)return;o.drawImage(n,r.x,r.y,r.width,r.height,0,0,r.width,r.height);let u=await new Promise(e=>a.toBlob(e,`image/png`));if(!u){i.push(`the selected region could not be turned into a picture`);return}x(``),y({png:u,preview:URL.createObjectURL(u)})},M=e=>{let t=s.current?.getBoundingClientRect();t&&(_.current={x:e.clientX-t.left,y:e.clientY-t.top},e.currentTarget.setPointerCapture?.(e.pointerId))},N=e=>{let t=s.current?.getBoundingClientRect();!_.current||!t||g(h4(_.current,{x:e.clientX-t.left,y:e.clientY-t.top}))},P=e=>{let t=s.current?.getBoundingClientRect(),n=_.current;if(_.current=null,!n||!t)return;let r=h4(n,{x:e.clientX-t.left,y:e.clientY-t.top});m(!1),g(null),_4(r)&&j(r)},F=()=>{y(null),x(``)},ee=async()=>{if(!v||S)return;C(!0);let e=b.trim()||`Screenshot from the test drive`;try{let t;if(r.projectId!==void 0){let n=r.projectId;t=await MF({createNote:()=>a.client.projectNotes.add.mutate({projectId:n,text:e}),uploadScreenshot:e=>Mb(e,v.png)}),a.projectNotes.invalidate()}else{let n=r.featureId;t=await MF({createNote:()=>o.mutateAsync({featureId:n,text:e}),uploadScreenshot:e=>Km(e,v.png)}),a.notes.list.invalidate({featureId:n})}t.uploadError&&i.push(`the note was saved, but its screenshot was not: ${t.uploadError}`),F()}catch(e){i.push(e instanceof Error?e.message:`the note could not be saved`)}finally{C(!1)}};return(0,R.jsxs)(`div`,{ref:s,className:`relative flex min-h-0 flex-1 flex-col overflow-hidden rounded-md bg-surface-inset`,children:[(0,R.jsx)(`iframe`,{className:`min-h-0 flex-1 border-0`,src:e,title:`the app on this branch`,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups`,onLoad:()=>T(!0)},O),(0,R.jsxs)(`div`,{className:`pointer-events-none absolute inset-x-0 top-0 flex flex-wrap items-center gap-2 p-3`,children:[(0,R.jsxs)(`div`,{className:`pointer-events-auto flex items-center gap-0.5 rounded-lg bg-surface-raised p-1 shadow-popover`,children:[u?(0,R.jsx)(nE,{label:d?`Sharing…`:p?`Drag a region`:`Select area`,icon:(0,R.jsx)(gb,{}),active:p,disabled:d,tooltipSide:`bottom`,onClick:()=>void A()}):null,(0,R.jsx)(nE,{label:`Reload`,icon:(0,R.jsx)(ab,{}),tooltipSide:`bottom`,onClick:()=>k(e=>e+1)}),(0,R.jsx)(nE,{label:`Open app`,href:e,target:`_blank`,icon:(0,R.jsx)(qy,{}),tooltipSide:`bottom`})]}),!u&&!n&&(0,R.jsx)(`span`,{className:`pointer-events-none rounded-md bg-surface-raised px-2 py-1 text-xs text-text-tertiary shadow-popover`,children:`This browser can’t capture its own tab — paste a screenshot into a note instead`}),t&&(0,R.jsx)(`span`,{className:`pointer-events-none rounded-md bg-surface-raised px-2 py-1 shadow-popover`,children:(0,R.jsx)(rA,{tone:`live`,children:`Review agent driving — notes land as it finds things`})}),!w&&E&&(0,R.jsx)(`span`,{className:`pointer-events-none rounded-md bg-surface-raised px-2 py-1 text-xs text-text-tertiary shadow-popover`,children:`Can’t embed? Open the app and paste a screenshot into a note.`})]}),p&&(0,R.jsx)(`div`,{className:`absolute inset-0 z-10 cursor-crosshair touch-none bg-scrim/20 animate-fade-in`,"aria-label":`drag over the part of the app that needs fixing`,onPointerDown:M,onPointerMove:N,onPointerUp:P,onPointerCancel:P,children:h&&(0,R.jsx)(`div`,{className:`absolute rounded-sm border-2 border-accent bg-accent-subtle/40`,style:{left:h.x,top:h.y,width:h.width,height:h.height}})}),v&&(0,R.jsxs)(`div`,{className:`absolute inset-x-3 bottom-3 z-20 flex items-end gap-3 rounded-lg bg-surface-raised p-2 shadow-popover animate-rise-in`,children:[(0,R.jsx)(`img`,{className:`h-14 w-24 rounded-md bg-surface-inset object-contain`,src:v.preview,alt:`the region you selected`}),(0,R.jsx)(kA,{rows:2,"aria-label":`what’s wrong here?`,className:`min-w-0 flex-1 resize-none`,placeholder:`What’s wrong here? Optional — the picture is the note.`,value:b,autoFocus:!0,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||(e.preventDefault(),ee())}}),(0,R.jsx)(Y,{variant:`ghost`,onClick:F,children:`Discard`}),(0,R.jsx)(Y,{variant:`primary`,loading:S,onClick:()=>void ee(),children:S?`Saving…`:`Save note`})]}),u&&(0,R.jsx)(`video`,{ref:c,muted:!0,playsInline:!0,className:`hidden`})]})}function C4(e,t){return Y_(e).stageKind===`player`&&t?`player`:`drive`}function w4(e,t){return`relative flex w-full flex-col rounded-md bg-surface-inset ${e?`min-h-0 flex-1`:`aspect-video max-h-[calc(100vh-320px)]`} ${t===`screen`?`overflow-hidden`:`overflow-auto p-6`}`}function T4(e,t,n){let r=[`Lap ${e.lap}`,e.passKind===`verification`?`Verification walkthrough`:`Walkthrough`];return t!==null&&t>0&&r.push(Hd(t)),e.passKind===`verification`&&n!==null&&n>0&&r.push(`confirms ${n} fix${n===1?``:`es`}`),r.push(e.landedSince===0?`this build`:`reviewed ${e.reviewedCommit?e.reviewedCommit.slice(0,7):`an earlier build`}`),r.join(` · `)}function E4({featureId:e,branch:t,recordings:n,picked:r=null,notes:i,readonly:a,driveState:o,drive:s,dryRun:c,failure:l,expand:u,handleRef:d,onStageRecording:f,onMarkerClick:p,onAnnotationSaved:m}){let[h,g]=(0,L.useState)(null),_=pv(n),v=n.find(e=>e.ticketId===r)??_,y=C4(o,!!v?.videoUrl);(0,L.useEffect)(()=>g(null),[v?.ticketId]);let b=v?n.indexOf(v):-1,x=b>0?n[b-1]:void 0,S=v&&x?x.landedSince-v.landedSince:null,C=Y_(o),w=C.stageKind===`panel`||C.stageKind===`agent`,T=y===`player`&&v?.videoUrl?v.ticketId:null;(0,L.useEffect)(()=>{f?.(T?{ticketId:T}:null)},[f,T]),K2(u,y!==`player`);let E=u?.expanded??!1;return(0,R.jsxs)(`section`,{id:`evidence-stage`,className:`flex min-h-0 flex-1 flex-col gap-3`,children:[(0,R.jsxs)(`header`,{className:`flex min-h-7 flex-wrap items-center gap-x-4 gap-y-2`,children:[v&&(0,R.jsx)(`span`,{className:`min-w-0 truncate text-sm text-text-secondary`,title:v.passKind===`verification`?`the fix count is derived from what landed between the two passes`:void 0,children:T4(v,h,S)}),u&&(0,R.jsx)(nE,{className:`ml-auto`,label:E?`Collapse`:`Expand`,kbd:`F`,icon:E?(0,R.jsx)(ub,{}):(0,R.jsx)(lb,{}),active:E,onClick:()=>u.set(!E)})]}),y===`player`&&v?.videoUrl?(0,R.jsx)(m4,{url:v.videoUrl,featureId:e,ticketId:v.ticketId,passKind:v.passKind,readonly:a,frameClassName:w4(E,`screen`),expand:u,markers:DF(i,v.ticketId),onMarkerClick:p,onAnnotationSaved:m,onDuration:g,handleRef:d},v.ticketId):(0,R.jsx)(`div`,{className:w4(E,w?`screen`:`prose`),children:(0,R.jsx)(D4,{featureId:e,branch:t,driveState:o,drive:s,dryRun:c,failure:l,hasRecording:!!v?.videoUrl,readonly:a})}),C.footer.showDevChip&&(0,R.jsx)(W2,{branch:s?.branch??t,drive:s})]})}function D4({featureId:e,branch:t,driveState:n,drive:r,dryRun:i,failure:a,hasRecording:o,readonly:s}){if(n===`idle`)return i?(0,R.jsx)(`div`,{className:`text-sm text-text-secondary`,children:`A preparation dry-run is holding the drive — it is proving this project’s drive commands on your machine. Stop it from Preparation, and this branch can take the wheel.`}):o?(0,R.jsx)(`div`,{className:`font-mono text-xs text-text-tertiary`,children:t}):(0,R.jsx)(rA,{spinning:!0,size:`sm`,children:`Starting the test drive — the branch is being checked out`});let c=s?null:(0,R.jsx)(V2,{featureId:e,label:`Stop test drive`});switch(Y_(n).stageKind){case`starting`:return(0,R.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,R.jsx)(rA,{spinning:!0,size:`sm`,strong:!0,children:`Starting the dev server`}),(0,R.jsx)(`span`,{className:`truncate font-mono text-xs text-text-tertiary`,children:r?.branch??t})]}),(0,R.jsx)(`div`,{className:`text-sm text-text-secondary`,children:`The branch is checked out and the project’s dev command is running. The app appears here as soon as it answers — its output is under the stage.`})]});case`failed`:return a?(0,R.jsx)(H2,{featureId:e,failure:a,readonly:s}):(0,R.jsx)(`div`,{className:`text-sm text-text-secondary`,children:`The drive’s setup command failed — its output is in the timeline.`});case`bare`:return(0,R.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,R.jsx)(rA,{tone:`neutral`,size:`sm`,strong:!0,children:`Branch checked out — nothing started`}),(0,R.jsx)(`div`,{className:`text-sm text-text-secondary`,children:s?`This project had no dev command, so the drive checked the branch out and started nothing.`:(0,R.jsxs)(R.Fragment,{children:[`This project has no dev command ·`,` `,(0,R.jsx)(p2,{location:{page:`project`,field:`devCommand`},children:`Set one in Settings`}),` `,`and the next drive boots the app right here.`]})}),c]});case`agent`:return(0,R.jsxs)(R.Fragment,{children:[r?.devUrl?(0,R.jsx)(S4,{featureId:e,url:r.devUrl,agentDriving:!0,readonly:s}):(0,R.jsxs)(`div`,{className:`flex flex-col gap-3 p-6`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,R.jsx)(rA,{tone:`live`,size:`sm`,strong:!0,children:`Review agent driving`}),(0,R.jsx)(`span`,{className:`truncate font-mono text-xs text-text-tertiary`,children:r?.branch??t})]}),(0,R.jsx)(`div`,{className:`text-sm text-text-secondary`,children:`Notes land below as it finds things. No dev server answered, so there is nothing to show here.`})]}),!s&&(0,R.jsx)(`div`,{className:`p-2`,children:(0,R.jsx)(V2,{featureId:e,label:`Stop the review drive`})})]});default:return r?.devUrl?(0,R.jsx)(S4,{featureId:e,url:r.devUrl,readonly:s}):(0,R.jsx)(`div`,{className:`p-6 text-sm text-text-secondary`,children:`The dev server is up but has not printed an address yet — its output is under the stage.`})}}function O4({account:e,tickets:t,observations:n=[],carried:r}){let i=t.filter(e=>(e.digest??``).trim().length>0).sort((e,t)=>e.seq-t.seq),a=!!e||i.length>0;if(!a&&!r&&n.length===0)return null;let o=[a?`digest`:null,r?`carried`:null,n.length>0?`${n.length} observation${n.length===1?``:`s`}`:null].filter(e=>e!==null);return(0,R.jsx)(`div`,{id:`full-accounts`,children:(0,R.jsx)(JA,{title:`Full account`,icon:(0,R.jsx)(ky,{}),aside:o.join(` · `),children:(0,R.jsxs)(`div`,{className:`flex flex-col gap-6 pt-1`,children:[e&&(0,R.jsx)(A4,{account:e}),i.length>0&&(0,R.jsxs)(`section`,{children:[(0,R.jsx)(mA,{children:`Ticket digests`}),(0,R.jsx)(`div`,{className:`mt-2 flex flex-col gap-5`,children:i.map(e=>(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`div`,{className:`text-sm font-medium text-text`,children:[`#`,e.seq,` `,e.title,(0,R.jsxs)(`span`,{className:`ml-2 font-normal text-text-tertiary`,children:[`lap `,e.lap,e.kind===`review`?e.passKind===`verification`?` · verification pass`:` · review pass`:``]})]}),(0,R.jsx)(PG,{source:e.digest.trim(),className:`mt-2`})]},e.seq))})]}),r&&(0,R.jsxs)(`section`,{children:[(0,R.jsx)(mA,{children:`Carried, quick-fixed and handled`}),(0,R.jsx)(`div`,{className:`mt-2`,children:r})]}),n.length>0&&(0,R.jsxs)(`section`,{children:[(0,R.jsx)(mA,{count:n.length,children:`Observations`}),(0,R.jsx)(`ul`,{className:`m-0 mt-2 flex list-none flex-col gap-2 p-0`,children:n.map(e=>(0,R.jsxs)(`li`,{className:`flex flex-col gap-0.5`,children:[(0,R.jsx)(`span`,{className:`text-sm text-text`,children:e.title}),(0,R.jsx)(k4,{detail:e.detail})]},e.id))})]})]})})})}function k4({detail:e}){let{head:t,rest:n}=Av(e);return n?(0,R.jsx)(JA,{bare:!0,title:(0,R.jsx)(`span`,{className:`font-normal text-text-tertiary`,children:t}),children:(0,R.jsx)(`p`,{className:`m-0 text-sm text-pretty text-text-secondary`,children:n})}):(0,R.jsx)(`span`,{className:`text-sm text-text-tertiary`,children:t})}function A4({account:e}){return(0,R.jsxs)(`section`,{children:[(0,R.jsx)(mA,{children:`What landed this lap`}),e.source===`review`?(0,R.jsx)(PG,{source:e.prose,className:`mt-2`}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`div`,{className:`mt-2 text-sm text-text-tertiary`,children:`No review summary this lap — below is each burner’s own account of the ticket it ran.`}),(0,R.jsx)(`div`,{className:`mt-3 flex flex-col gap-4`,children:e.entries.map(e=>(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`div`,{className:`text-sm font-medium text-text`,children:[`#`,e.seq,` `,e.title]}),(0,R.jsx)(PG,{source:e.digest,className:`mt-2`})]},e.seq))})]})]})}function j4({featureId:e,line:t,readonly:n,onOpen:r}){if(n)return null;let{phase:i}=t;return(0,R.jsx)(L2,{tone:`quiet`,role:`status`,icon:(0,R.jsx)(dA,{status:`live`}),title:t.text,actions:(0,R.jsxs)(R.Fragment,{children:[i&&r&&(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,icon:(0,R.jsx)(Iy,{}),onClick:()=>r(i),children:`Open`}),(0,R.jsx)(IG,{featureId:e,sessionId:t.sessionId})]})})}function M4({lap:e,outcome:t,agenticReview:n}){return(0,R.jsxs)(L2,{tone:`accent`,title:`Nothing verified this lap`,meta:`lap ${e}`,actions:n&&(0,R.jsx)(Y,{size:`sm`,icon:(0,R.jsx)(zy,{}),disabled:!!n.blocked,...n.blocked?{title:n.blocked}:{},onClick:n.onStart,children:`Agentic review`}),children:[(0,R.jsx)(`p`,{className:`m-0`,children:`The review pass ran and produced no evidence, so nothing on this branch has been checked this lap. Nothing is blocked — run another review, or drive it yourself, before you ship.`}),t.line&&(0,R.jsx)(`p`,{className:`m-0 mt-1.5 break-words text-text`,children:t.line}),t.reason&&(0,R.jsx)(`p`,{className:`m-0 mt-1 font-mono text-xs break-words text-text-tertiary`,children:t.reason})]})}function N4(e){let t=e.filter(e=>e.item.kind===`defect`&&e.item.fixTicket).length,n=[`${e.length-t} open`];return t>0&&n.push(`${t} being fixed`),n.join(` · `)}function P4({featureId:e,lap:t,rows:n,readonly:r,...i}){if(n.length===0&&r)return null;let a=n.length===0;return(0,R.jsxs)(`section`,{id:`open-work`,className:`flex flex-col gap-2`,children:[(0,R.jsxs)(`div`,{className:`flex min-h-7 items-baseline gap-3`,children:[(0,R.jsx)(`h2`,{className:`m-0 text-lg font-semibold text-text`,children:a?`Notes`:`Needs attention`}),!a&&(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary tabular-nums`,children:N4(n)})]}),a?(0,R.jsx)(`p`,{className:`m-0 text-sm text-text-tertiary`,children:`Nothing needs attention. Write down what you see while you drive — a pasted screenshot rides along.`}):(0,R.jsx)(N2,{featureId:e,rows:n,readonly:r,currentLap:t,...i}),!r&&(0,R.jsx)(`div`,{className:`mt-2`,children:(0,R.jsx)(E2,{featureId:e})})]})}function F4({featureId:e,lap:t,rows:n,readonly:r,scroller:i,...a}){return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`div`,{ref:i,className:`min-h-0 flex-1 overflow-y-auto px-1 py-2`,children:n.length===0?(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(Uy,{}),title:`Nothing needs attention`,hint:r?`Nothing was left open when this feature shipped.`:`The review found nothing open and you have written no notes. Write what you see.`}):(0,R.jsx)(N2,{featureId:e,rows:n,readonly:r,currentLap:t,scroller:i,...a})}),!r&&(0,R.jsx)(`div`,{className:`shrink-0 border-t border-border-subtle p-3`,children:(0,R.jsx)(E2,{featureId:e})})]})}function I4(){return(0,L.useRef)(null)}function L4({onClose:e,className:t,...n}){let r=I4(),i=n.rows.length>0?N4(n.rows):null;return(0,R.jsx)(LA,{label:`Needs attention`,title:(0,R.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[`Needs attention`,i&&(0,R.jsx)(`span`,{className:`text-xs font-normal text-text-tertiary tabular-nums`,children:i})]}),onClose:e,className:t,bodyClassName:`flex flex-col`,children:(0,R.jsx)(F4,{...n,scroller:r})})}function R4({projectId:e,holderLabel:t}){let n=B.useUtils(),r=Ab(),i=B.project.testDrive.useMutation({onSuccess:()=>void n.feature.driveInfo.invalidate(),onError:e=>r.push(e.message)});return(0,R.jsx)(L2,{tone:`quiet`,role:`status`,title:`${H_(t)} is running`,actions:(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,icon:(0,R.jsx)(Ry,{}),disabled:i.isPending,onClick:()=>i.mutate({projectId:e,action:`stop`}),children:i.isPending?`Stopping…`:`Stop it`})})}function z4({denial:e,readonly:t,primary:n,busy:r,refusal:i,onReview:a,onDismiss:o}){return t?null:(0,R.jsxs)(L2,{tone:`accent`,title:`Review couldn’t drive — uncommitted changes`,meta:(0,R.jsxs)(`span`,{title:oh(e.at),children:[`denied `,ph(e.at)]}),actions:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(Y,{size:`sm`,variant:n?`secondary`:`ghost`,icon:(0,R.jsx)(zy,{}),loading:r,onClick:a,children:r?`Starting…`:`Agentic review`}),(0,R.jsx)(nE,{size:`sm`,label:`Dismiss`,icon:(0,R.jsx)(xy,{}),onClick:o})]}),children:[(0,R.jsx)(`p`,{className:`m-0`,children:`The drive was refused because the working tree had uncommitted changes, so the review ran repo-only — the gates and the diff, with no app to walk. Commit or discard the files below, then run another review: a fresh pass is minted for this lap and burns with the drive available to it.`}),e.dirtyFiles.length>0?(0,R.jsx)(`ul`,{className:`m-0 mt-2 flex list-none flex-col gap-0.5 p-0`,children:e.dirtyFiles.map(e=>(0,R.jsx)(`li`,{className:`truncate font-mono text-xs text-text`,title:e,children:e},e))}):(0,R.jsx)(`p`,{className:`m-0 mt-2 font-mono text-xs break-words text-text-tertiary`,children:e.message}),i&&(0,R.jsx)(`div`,{className:`mt-2`,children:(0,R.jsx)(YA,{message:i})})]})}function B4({featureId:e,denial:t,readonly:n,primary:r,onDismiss:i}){let a=B.useUtils(),[o,s]=(0,L.useState)(null),c=B.feature.agenticReview.useMutation({onSuccess:()=>{a.feature.get.invalidate({id:e}),a.events.invalidate()},onError:e=>s(e.message)});return(0,R.jsx)(z4,{denial:t,readonly:n,primary:r,busy:c.isPending,refusal:o,onReview:()=>{s(null),c.mutate({featureId:e})},onDismiss:i})}function V4(e){switch(e.kind){case`verified`:return{tone:`success`,strong:`Verified`,...e.mode?{text:`${e.mode} mode`}:{}};case`unverified`:return{tone:`warning`,strong:`Unverified`};case`could-not-run`:return{tone:`warning`,strong:`Could not run`};case`none`:return null}}var H4=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function U4(e){let{found:t,fixed:n,carried:r}=e.defects;return[e.completedAt===null?{text:`Not reviewed yet`}:{text:`Reviewed ${ph(e.completedAt)}`,title:oh(e.completedAt)},V4(e.outcome),e.burned>0?{text:`${H4(e.burned,`ticket`)} burned`}:null,t>0?{text:[H4(t,`defect`)+` found`,n>0?`${n} fixed`:``,r>0?`${r} carried`:``].filter(Boolean).join(`, `)}:null,e.notes>0?{text:H4(e.notes,`test note`)}:null].filter(e=>e!==null)}function W4(e){let t=e.passKind===`verification`?`Verification`:`Review`,n=[e.mode?`${e.mode} mode`:null,e.couldNotRun?`could not run`:e.verdict].filter(Boolean).join(`, `);return n?`${t} — ${n}`:t}function G4({entry:e,tickets:t,account:n,staged:r,onStage:i,onViewRun:a}){let o=new Map(e.passes.map(e=>[e.ticketId,e])),s=[...t.filter(t=>t.lap===e.lap)].sort((e,t)=>(t.seq??0)-(e.seq??0)),c=e.passes.filter(e=>!s.some(t=>t.id===e.ticketId)),l=(e,t,n=0)=>(0,R.jsx)(vA,{index:n,leading:e.verdict===`verified`?(0,R.jsx)(by,{}):(0,R.jsx)(zy,{}),title:`#${e.seq} · ${W4(e)}`,meta:t?.completedAt?ph(t.completedAt):void 0,active:r===e.ticketId,actions:e.videoUrl?(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,icon:(0,R.jsx)(Ly,{}),"aria-pressed":r===e.ticketId,onClick:()=>i(e.ticketId),children:`Recording`}):void 0},e.ticketId);return(0,R.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,R.jsx)(xA,{items:U4(e)}),n&&(0,R.jsx)(`p`,{className:`m-0 text-base text-pretty text-text-secondary`,children:n}),e.outcome.kind===`unverified`&&(e.outcome.line||e.outcome.reason)&&(0,R.jsxs)(`div`,{className:`flex flex-col gap-0.5 text-sm`,children:[e.outcome.line&&(0,R.jsx)(`span`,{className:`text-warning`,children:e.outcome.line}),e.outcome.reason&&(0,R.jsx)(`span`,{className:`text-text-tertiary`,children:e.outcome.reason})]}),(s.length>0||c.length>0)&&(0,R.jsxs)(yA,{divided:!0,label:`Lap ${e.lap} tickets`,children:[s.map((e,t)=>{let n=o.get(e.id);if(n)return l(n,e,t);let r=e.kind===`review`;return(0,R.jsx)(vA,{index:t,leading:r?(0,R.jsx)(zy,{}):(0,R.jsx)(Ny,{}),title:`#${e.seq??`?`} · ${e.title??(r?`Review`:`Ticket`)}`,meta:e.status===`done`?e.completedAt?ph(e.completedAt):void 0:(0,R.jsx)(iA,{status:e.status}),...a&&!r?{onClick:a}:{}},e.id)}),c.map((e,t)=>l(e,void 0,s.length+t))]})]})}function K4({passes:e,tickets:t,findings:n,notes:r,currentLap:i,account:a=null,staged:o,onStage:s,onViewRun:c}){let l=Dv({passes:e,tickets:t,findings:n,notes:r,currentLap:i});if(e.length===0&&t.length===0)return null;let[u,...d]=l.filter(e=>e.lap===i||e.passes.length>0||t.some(t=>t.lap===e.lap)||e.defects.found>0||e.notes>0),f=e=>(0,R.jsx)(G4,{entry:e,tickets:t,account:e.lap===i?a:null,staged:o,onStage:s,...c?{onViewRun:c}:{}});return(0,R.jsxs)(`section`,{id:`lap-trail`,className:`flex flex-col gap-3`,children:[(0,R.jsxs)(`h2`,{className:`m-0 text-lg font-semibold text-text`,children:[`Lap `,u.lap]}),f(u),d.length>0&&(0,R.jsx)(`div`,{className:`mt-3`,children:d.map(e=>{let t=V4(e.outcome);return(0,R.jsx)(JA,{title:`Lap ${e.lap}`,aside:t?.strong??(e.completedAt===null?void 0:`Reviewed ${ph(e.completedAt)}`),children:f(e)},e.lap)})})]})}var q4={ok:`success`,warn:`warning`,danger:`danger`,idle:`neutral`};function J4(e){let t=q4[e.tone],n=(0,R.jsx)(`span`,{className:`whitespace-nowrap`,...e.detail?{title:e.detail}:{},children:e.value}),r=e.sub&&e.detail?(0,R.jsx)(`span`,{className:`text-warning`,title:e.detail,children:e.sub}):e.sub,i=e.key===`tickets`?(0,R.jsx)(Ny,{}):e.key===`laps`?(0,R.jsx)(Cy,{}):void 0;return{label:e.label,value:n,...r?{sub:r}:{},...i&&e.tone===`idle`?{leading:i}:{tone:t}}}function Y4({artifact:e,currentLap:t,landedSince:n,tickets:r,checks:i,runState:a,verification:o,driveLap:s,unverifiedKeys:c,testDrive:l,agenticReview:u,shipped:d=!1,driving:f,noWalkthrough:p=!1}){return(0,R.jsxs)(`div`,{className:`flex flex-wrap items-start gap-x-8 gap-y-4`,children:[(0,R.jsx)(bA,{className:`min-w-0 flex-1`,items:vv({artifact:e,currentLap:t,landedSince:n,tickets:r,checks:{passed:i.filter(e=>e.tone===`ok`).length,total:i.length},...d?{}:{runState:a},...o?{verification:o}:{},...s===void 0?{}:{driveLap:s},...f===void 0?{}:{driving:f},...p?{noWalkthrough:p}:{},...c?{unverifiedKeys:c}:{},shipped:d}).map(J4)}),(l||u)&&(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[l&&(0,R.jsx)(Y,{icon:(0,R.jsx)(Ly,{}),disabled:!!l.blocked,...l.blocked?{title:l.blocked}:{},onClick:l.onStart,children:`Test drive`}),u&&(0,R.jsx)(Y,{variant:`ghost`,icon:(0,R.jsx)(zy,{}),disabled:!!u.blocked,...u.blocked?{title:u.blocked}:{},onClick:u.onStart,children:`Agentic review`})]})]})}function X4({checks:e}){return e.length===0?null:(0,R.jsx)(JA,{title:`Check details`,icon:(0,R.jsx)($y,{}),children:e.map(e=>(0,R.jsx)(pA,{row:e},e.key))})}function Z4({lap:e,laterLaps:t,currentLap:n,readonly:r}){return t?(0,R.jsxs)(JA,{title:`Deferred to a later lap`,icon:(0,R.jsx)(Cy,{}),children:[(0,R.jsxs)(`p`,{className:`m-0`,children:[e.story,`.`]}),e.promotedFromEarlier>0&&(0,R.jsxs)(`p`,{className:`m-0 mt-2 text-text-tertiary`,children:[`Includes `,e.promotedFromEarlier,` ticket`,e.promotedFromEarlier===1?``:`s`,` promoted in an earlier lap.`]}),(0,R.jsx)(`p`,{className:`m-0 mt-3 text-text-tertiary`,children:r?`The spec kept this out of lap ${n} on purpose, and it was still deferred when this feature shipped.`:`The spec kept this out of lap ${n} on purpose. Start lap ${n+1} from the next step to take it on — or ship what landed, if lap ${n} is enough.`}),(0,R.jsx)(PG,{source:t,className:`mt-2`})]}):null}function Q4({full:e,driving:t,conflict:n,readonly:r=!1,onViewPhase:i}){let{feature:a,tickets:o,runs:s}=e,c=Ab(),l=B.useUtils(),u=Zv(e.sessions),d=vh(s),f=pF(a.id),p=B.feature.commitCount.useQuery({featureId:a.id},{refetchInterval:eh(5e3)}),m=B.feature.driveInfo.useQuery(void 0,{refetchInterval:eh()}),h=m.data?.featureId===a.id?m.data:void 0,g=eh(),_=a.phase===`review`&&g,v=B.notes.list.useQuery({featureId:a.id},{refetchInterval:_}),y=B.findings.listByFeature.useQuery({featureId:a.id},{refetchInterval:_}),b=jv(e),x=B.docs.read.useQuery({featureId:a.id,relPath:b??`spec.md`},{enabled:!!b}),S=Um(a.id).data??[],C=S.filter(e=>e.hasVideo&&e.videoUrl),w=pv(S.filter(e=>e.completedAt!==null))??null,T=jp(B.project.prep.useQuery({projectId:a.projectId}).data?.findings??[]),E=B.project.list.useQuery().data?.find(e=>e.id===a.projectId);B.feature.testDrive.useMutation({onSuccess:()=>{l.feature.driveInfo.invalidate(),l.feature.get.invalidate({id:a.id})},onError:e=>c.push(e.message)});let D=B.feature.agenticReview.useMutation({onSuccess:()=>{l.feature.get.invalidate({id:a.id}),l.events.invalidate()},onError:e=>c.push(e.message)}),O=(0,L.useRef)(null),[k,A]=(0,L.useState)(null),[j,M]=(0,L.useState)(null),[N,P]=(0,L.useState)(!1),[F,ee]=(0,L.useState)(!0);(0,L.useEffect)(()=>{N&&ee(!0)},[N]);let[te,ne]=(0,L.useState)(null),[I,re]=(0,L.useState)({ids:[],scrollTo:null});(0,L.useEffect)(()=>{if(I.ids.length===0)return;let e=setTimeout(()=>re({ids:[],scrollTo:null}),2e3);return()=>clearTimeout(e)},[I]);let ie=(0,L.useCallback)(e=>{A(e),document.getElementById(`evidence-stage`)?.scrollIntoView({behavior:`smooth`,block:`start`})},[]),ae=(0,L.useCallback)(e=>{O.current?.seek(e),document.getElementById(`evidence-stage`)?.scrollIntoView({behavior:`smooth`,block:`start`})},[]),oe=i?e=>{i(`building`),requestAnimationFrame(()=>document.getElementById(`lane-${e}`)?.scrollIntoView({behavior:`smooth`,block:`center`}))}:void 0,se=h?.state??`idle`,ce=se!==`idle`||!!t,le=C.length>0||ce,ue={expanded:N&&le,set:P},de=m.data&&m.data.featureId!==a.id?m.data:void 0,fe=de?.projectDrive&&de.projectId?de.projectId:void 0,pe=a.phase===`review`?K_(f,s,te):null,me=r?null:Ov({passes:S,tickets:o,currentLap:a.lap}),he=r?null:{onStart:()=>D.mutate({featureId:a.id}),...D.isPending?{blocked:`starting…`}:d?.status===`running`?{blocked:`a burn is running`}:{}},{attention:ge,settled:_e}=M2({findings:y.data?.findings??[],notes:v.data??[],tickets:o,openDefects:y.data?.openDefects??[]}),ve=(y.data?.findings??[]).filter(e=>e.kind===`observation`),ye=Fg(o,a.lap),be=y.data?.summary,xe=be?be.found+be.observations:void 0,Se=Ig(ye)??Sv(be),Ce=xv({tickets:o,run:d,commitCount:p.data?.count,findings:xe}),we=zg(o,{lap:a.lap,lapSessionRan:o.some(e=>e.lap===a.lap)}),Te=Nv(x.data?.content),Ee=le?(0,R.jsx)(E4,{featureId:a.id,branch:a.branch,recordings:C,picked:k,notes:v.data??[],readonly:r,driveState:se,drive:h,dryRun:m.data?.dryRun??!1,failure:W_(h,{sessionLive:!!u}),expand:ue,handleRef:O,onStageRecording:M,onMarkerClick:e=>re({ids:e,scrollTo:null}),onAnnotationSaved:e=>re({ids:[e],scrollTo:e})}):null,De=(0,R.jsxs)(R.Fragment,{children:[n&&(0,R.jsx)(z2,{featureId:a.id,branch:a.branch,conflict:n,readonly:r,liveSessionId:u?.sessionId??null,resolveEnded:Cg(f,e.sessions)}),pe&&(0,R.jsx)(B4,{featureId:a.id,denial:pe,readonly:r,primary:!me,onDismiss:()=>ne(pe.eventId)},pe.eventId),me&&(0,R.jsx)(M4,{lap:a.lap,outcome:me,agenticReview:he}),u&&(0,R.jsx)(j4,{featureId:a.id,line:u,readonly:r,onOpen:i}),!r&&!ce&&de&&fe&&(0,R.jsx)(R4,{projectId:fe,holderLabel:de.holderLabel})]}),Oe={featureId:a.id,lap:a.lap,rows:ge,readonly:r,onStage:le?j:null,onSeek:ae,highlight:I.ids,scrollTo:I.scrollTo,onViewLane:oe},ke=ue.expanded,Ae=!!n||!!pe||!!me||!!u&&!r||!r&&!ce&&!!fe,je=ke?(0,R.jsx)(`div`,{"data-stage-overlay":``,className:`fixed inset-0 z-[100] flex bg-surface animate-fade-in`,children:(0,R.jsx)(RA,{aside:F&&(0,R.jsx)(L4,{...Oe,onClose:()=>ee(!1)}),children:(0,R.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col p-6`,children:Ee})})}):null;return(0,R.jsxs)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto`,children:[(0,R.jsxs)(`div`,{className:`flex flex-col gap-10`,children:[Ae&&(0,R.jsx)(`div`,{className:`flex flex-col gap-4`,children:De}),(0,R.jsx)(Y4,{artifact:w,currentLap:a.lap,landedSince:w?.landedSince??0,tickets:o,checks:Ce,runState:d?.status??`no run recorded`,verification:_v(o),...r?{}:{unverifiedKeys:T},...r?{}:{driving:ce},...he?{agenticReview:he}:{}}),!ke&&Ee,(0,R.jsx)(P4,{...Oe}),(0,R.jsx)(P2,{featureId:a.id,findings:y.data?.carriedFindings??[],readonly:r}),(0,R.jsx)(K4,{passes:S,tickets:o,findings:y.data?.findings??[],notes:v.data??[],currentLap:a.lap,account:Se,staged:j?.ticketId??null,onStage:ie,...i?{onViewRun:()=>i(`building`)}:{}}),(0,R.jsxs)(`div`,{className:`flex flex-col [&>*:last-child]:border-b [&>*:last-child]:border-border-subtle`,children:[(0,R.jsx)(B2,{text:E?.driveInstructions}),(0,R.jsx)(O4,{account:ye,tickets:o,observations:ve,carried:_e.length>0?(0,R.jsx)(N2,{featureId:a.id,rows:_e,readonly:r,onStage:le?j:null,onSeek:ae,onViewLane:oe}):null}),(0,R.jsx)(X4,{checks:Ce}),(0,R.jsx)(Z4,{lap:we,laterLaps:Te,currentLap:a.lap,readonly:r})]})]}),je&&(typeof document>`u`?je:(0,Rb.createPortal)(je,document.body))]})}var $4=`Untitled chat`,e3=RegExp(`\x1B\\[[0-9;]*[A-Za-z]`,`g`),t3=/<\/?[a-z][a-z0-9_-]*(?:\s[^<>]*)?>/g,n3=/^(?:[#>▎❯•*\-.]+\s*)+/,r3=/[`▎]|\*\*/g;function i3(e){if(!e)return $4;let t=e.replace(e3,``).replace(t3,` `).replace(r3,``).replace(/\s+/g,` `).trim().replace(n3,``).trim();return!t||t===`…`||/^untitled$/i.test(t)?$4:t}function a3(e){return e.charAt(0).toUpperCase()+e.slice(1)}var o3=/<command-name>([\s\S]*?)<\/command-name>/,s3=/<command-args>([\s\S]*?)<\/command-args>/,c3=/^\s*<local-command-(?:stdout|stderr)>([\s\S]*?)<\/local-command-(?:stdout|stderr)>\s*$/,l3=/^\s*<local-command-caveat>[\s\S]*?<\/local-command-caveat>\s*$/;function u3(e){if(l3.test(e))return{kind:`skip`};let t=o3.exec(e);if(t){let n=t[1].trim(),r=s3.exec(e)?.[1]?.trim()??``,i=n.startsWith(`/`)?n:`/${n}`;return{kind:`command`,command:r?`${i} ${r}`:i}}let n=c3.exec(e);if(n){let e=n[1].replace(e3,``).trim();return e?{kind:`output`,text:e}:{kind:`skip`}}return{kind:`text`,text:e}}function d3({sessionId:e,className:t}){let n=B.project.conversationTranscript.useQuery({sessionId:e});if(n.isPending)return(0,R.jsx)(WA,{children:`Reading the transcript…`});if(n.data?.status===`unavailable`)return(0,R.jsx)(WA,{children:`Transcript not available for this session.`});let r=n.data?.turns??[];return r.length===0?(0,R.jsx)(WA,{children:`No transcript kept for this conversation.`}):(0,R.jsx)(p3,{turns:r,assistant:O_(n.data?.runtime),runtime:n.data?.runtime,...t?{className:t}:{}})}var f3=`flex max-h-[clamp(300px,calc(100dvh-340px),1200px)] flex-col gap-6 overflow-y-auto pr-1`;function p3({turns:e,assistant:t,runtime:n,className:r=f3}){let i=n===`codex`?Hy:Vy,a=(0,L.useRef)(null);a.current===null&&e.length>0&&(a.current=e.length);let o=a.current??0;return(0,R.jsx)(`div`,{className:r,children:e.map((e,n)=>{let r=u3(e.text);if(r.kind===`skip`)return null;let a=n<8?{"--i":n}:void 0,s=n<8?q(`animate-rise-in`,`[animation-delay:calc(var(--i)*20ms)]`):n>=o?`animate-rise-in`:void 0;if(r.kind===`command`||r.kind===`output`)return(0,R.jsxs)(`div`,{style:a,"data-turn-kind":r.kind,className:q(`flex min-w-0 items-start gap-1.5 font-mono text-xs text-text-tertiary`,s),children:[(0,R.jsx)(Dy,{size:12,className:`mt-0.5 shrink-0 text-icon`}),(0,R.jsx)(`span`,{className:`min-w-0 break-words whitespace-pre-wrap`,children:r.kind===`command`?r.command:r.text})]},n);let c=e.role===`user`;return(0,R.jsxs)(`article`,{style:a,className:q(`flex flex-col gap-1.5`,s),children:[(0,R.jsxs)(`span`,{className:`flex items-center gap-1.5 text-xs font-medium text-text-secondary`,children:[c?(0,R.jsx)(ob,{size:14,className:`shrink-0 text-icon`}):(0,R.jsx)(i,{size:14,className:`shrink-0 text-icon`}),c?`You`:t]}),c?(0,R.jsx)(`div`,{className:`rounded-md bg-surface-inset px-3 py-2 text-base break-words whitespace-pre-wrap text-text`,children:r.text}):(0,R.jsx)(PG,{source:r.text,size:`base`,tone:`primary`})]},n)})})}function m3({full:e,chatDocked:t=!1}){let{feature:n,tickets:r,runs:i}=e,a=pF(n.id),[o,s]=(0,L.useState)(!1),c=Mv(e),l=Um(n.id).data??[],u=l.filter(e=>e.hasVideo&&e.videoUrl),d=mv(l),f=B.findings.listByFeature.useQuery({featureId:n.id}),p=B.notes.list.useQuery({featureId:n.id}),m=jv(e),h=B.docs.read.useQuery({featureId:n.id,relPath:m??`spec.md`},{enabled:!!m}),g=B.project.list.useQuery().data?.find(e=>e.id===n.projectId),_=Jv(e.sessions),v=qv(_.filter(Ag),t),y=vh(i),b=xv({tickets:r,run:y,findings:f.data?.findings.length}).filter(e=>e.key!==`changes`),x=Fg(r,n.lap),S=Ig(x)??Sv(f.data?.summary),C=(f.data?.findings??[]).filter(e=>e.kind===`observation`),[w,T]=(0,L.useState)(null);return(0,R.jsxs)(`div`,{className:`flex flex-col gap-10`,children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-start gap-x-8 gap-y-4`,children:[(0,R.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,R.jsx)(Y4,{artifact:d,currentLap:n.lap,landedSince:d?.landedSince??0,tickets:r,checks:b,runState:y?.status??`no run recorded`,shipped:!0,driveLap:Tg(a),noWalkthrough:u.length===0})}),c&&(0,R.jsx)(Y,{variant:`ghost`,icon:(0,R.jsx)(ky,{}),onClick:()=>s(!0),children:`Outcome doc`})]}),u.length>0&&(0,R.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,R.jsx)(`h2`,{className:`m-0 text-lg font-semibold text-text`,children:`Walkthrough`}),(0,R.jsx)(E4,{featureId:n.id,branch:n.branch,recordings:u,picked:w,notes:[],readonly:!0,driveState:`idle`,dryRun:!1,failure:null})]}),(0,R.jsx)(K4,{passes:l,tickets:r,findings:f.data?.findings??[],notes:p.data??[],currentLap:n.lap,account:S,staged:u.length>0?w:null,onStage:T}),v.length>0&&(0,R.jsx)(`div`,{className:`flex h-[clamp(300px,calc(100dvh-420px),1200px)] flex-col`,children:(0,R.jsx)(b1,{featureId:n.id,sessions:v})}),(0,R.jsx)(h3,{sessions:_}),(0,R.jsxs)(`div`,{className:`flex flex-col [&>*:last-child]:border-b [&>*:last-child]:border-border-subtle`,children:[(0,R.jsx)(B2,{text:g?.driveInstructions}),(0,R.jsx)(O4,{account:x,tickets:r,observations:C}),(0,R.jsx)(X4,{checks:b}),(0,R.jsx)(Z4,{lap:zg(r,{lap:n.lap,lapSessionRan:!0}),laterLaps:Nv(h.data?.content),currentLap:n.lap,readonly:!0})]}),o&&c&&(0,R.jsx)(A1,{featureId:n.id,relPath:c,title:`outcome`,onClose:()=>s(!1)})]})}function h3({sessions:e}){return e.length===0?null:(0,R.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,R.jsx)(`h2`,{className:`m-0 text-lg font-semibold text-text`,children:`Questions asked`}),(0,R.jsx)(yA,{divided:!0,label:`Questions asked`,children:e.map((e,t)=>{let n=e.createdAt===void 0?void 0:ph(e.createdAt);return e.transcriptMissing?(0,R.jsx)(vA,{index:t,leading:(0,R.jsx)(Oy,{}),title:(0,R.jsx)(`span`,{className:`text-text-tertiary`,children:`Session opened, nothing recorded`}),meta:n},e.id):(0,R.jsx)(g3,{title:e.title??`Conversation`,when:n,sessionId:e.id},e.id)})})]})}function g3({title:e,when:t,sessionId:n}){let[r,i]=(0,L.useState)(!1);return(0,R.jsx)(`div`,{"data-list-row":``,className:`px-3`,children:(0,R.jsx)(JA,{bare:!0,icon:(0,R.jsx)(Oy,{}),title:(0,R.jsx)(`span`,{className:`font-normal text-text`,children:e}),aside:t,onToggle:e=>e&&i(!0),children:r&&(0,R.jsx)(d3,{sessionId:n})})})}function _3({featureId:e,chatDocked:t=!1}){let n=Ab(),r=B.useUtils(),i=B.feature.get.useQuery({id:e},{refetchInterval:eh()}),[a,o]=(0,L.useState)(null),s=B.ticket.edit.useMutation({onSuccess:()=>{r.feature.get.invalidate({id:e})},onError:e=>n.push(e.message)}),c=B.ticket.cancel.useMutation({onSuccess:()=>{r.feature.get.invalidate({id:e}),n.push(`ticket cancelled`,`success`)},onError:e=>n.push(e.message)}),l=i.data?.feature.projectId,u=B.settings.get.useQuery({projectId:l??``},{enabled:!!l}),d=Vp(u.data),f=mm(u.data,`implement`)??`…`,p=i.data,m=qv(p?.sessions??[],t),h=[...m].reverse().find(Ag),g=p?p.tickets.filter(e=>e.lap===p.feature.lap):[],_=y3(h?.id,g.length);if(i.isLoading)return(0,R.jsx)(WA,{children:`Loading tickets…`});if(!p)return(0,R.jsxs)(WA,{children:[`Could not load tickets: `,i.error?.message??`unknown`]});let{feature:v,tickets:y,docs:b}=p,x=[...m].reverse().find(e=>e.status===`ended`),S=async(e,t)=>{await s.mutateAsync({ticketId:e,...t}),n.push(`ticket updated`,`success`)},C=(e,t)=>s.mutate({ticketId:e,model:t}),w=async t=>{let i=v3(y,v.lap);try{for(let e of i)await r.client.ticket.edit.mutate({ticketId:e.id,model:t});await r.feature.get.invalidate({id:e}),n.push(`${i.length} tickets set to ${t||`the default model`}`,`success`)}catch(e){n.push(e instanceof Error?e.message:`could not update ticket models`)}},T=(0,R.jsx)(b2,{tickets:y,currentLap:v.lap,roster:d,docs:b,sandbox:Dj,defaultModel:f,onDoc:o,onEdit:S,onModel:C,onBulkModel:e=>{w(e)},onCancel:e=>c.mutate({ticketId:e}),onCopySha:e=>{navigator.clipboard.writeText(e),n.push(`copied ${lh(e)}`,`info`)}});return(0,R.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col gap-3 overflow-y-auto`,children:[h&&(0,R.jsx)(b3,{featureId:e,live:h,ticketCount:g.length,open:_.open,onToggle:_.toggle}),!h&&x&&(0,R.jsx)(y1,{session:x}),(0,R.jsxs)(`section`,{"aria-label":`Tickets`,className:`flex min-h-0 flex-col${_.open?` shrink-0`:``}`,children:[(0,R.jsx)(`h2`,{className:`m-0 mb-2 text-lg font-semibold text-text`,children:`Tickets`}),T]}),a&&(0,R.jsx)(A1,{featureId:e,relPath:a,title:b.find(e=>e.relPath===a)?.title??a,onClose:()=>o(null)})]})}function v3(e,t){return e.filter(e=>e.lap===t&&e.status===`pending`)}function y3(e,t){let n=`runcastle.tickets.term:${e??``}`,[r,i]=(0,L.useState)(t===0);return(0,L.useEffect)(()=>{let e=null;try{e=sessionStorage.getItem(n)}catch{}i(e===null?t===0:e===`open`)},[n,t]),{open:r,toggle:e=>{i(e);try{sessionStorage.setItem(n,e?`open`:`closed`)}catch{}}}}function b3({featureId:e,live:t,ticketCount:n,open:r,onToggle:i}){return r?(0,R.jsx)(`div`,{className:`flex h-full shrink-0 flex-col`,children:(0,R.jsx)(b1,{featureId:e,sessions:[t],right:(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,icon:(0,R.jsx)(Dy,{}),onClick:()=>i(!1),children:`Hide terminal`})})}):(0,R.jsx)(`div`,{className:`flex-none`,children:(0,R.jsx)(y1,{session:t,right:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`span`,{className:`text-xs text-text-tertiary tabular-nums`,children:[n,` tickets emitted`]}),(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,icon:(0,R.jsx)(Dy,{}),onClick:()=>i(!0),children:`Show terminal`}),(0,R.jsx)(IG,{featureId:e,sessionId:t.id})]})})})}function x3({open:e,title:t,body:n,confirmLabel:r,confirmIcon:i,busy:a,onConfirm:o,onClose:s}){let c=(0,L.useId)();return(0,R.jsxs)(QA,{open:e,onClose:s,size:`sm`,labelledBy:c,children:[(0,R.jsx)($A,{id:c,title:t,onClose:s}),(0,R.jsx)(ej,{children:(0,R.jsx)(`p`,{className:`m-0 text-sm text-pretty text-text-secondary`,children:n})}),(0,R.jsxs)(tj,{children:[(0,R.jsx)(Y,{variant:`ghost`,onClick:s,disabled:a,children:`Keep going`}),(0,R.jsx)(Y,{variant:`danger`,icon:i,autoFocus:!0,disabled:a,onClick:()=>{o(),s()},children:r})]})]})}var S3=[`pending`,`failed`],C3={pending:{tone:`neutral`,word:`Pending`},burning:{tone:`live`,word:`Burning`},done:{tone:`success`,word:`Done`,icon:(0,R.jsx)(by,{})},failed:{tone:`danger`,word:`Failed`},"launch-failed":{tone:`danger`,word:`Launch failed`},stopped:{tone:`warning`,word:`Stopped`},waived:{tone:`neutral`,word:`Set aside`,muted:!0}},w3={"claude-code":Vy,codex:Hy},T3=`shrink-0 text-xs text-text-tertiary tabular-nums`;function E3({ticket:e,featureBranch:t,readonly:n,expanded:r,onToggle:i,index:a,hadOutput:o,elapsed:s,duration:c,model:l,roster:u,defectTitle:d,busy:f,stopping:p,waiving:m,terminalBlocked:h,onModel:g,onRetry:_,onRetryWithModel:v,onRetryFresh:y,onWaive:b,onStop:x,onResolveInTerminal:S,onCopySha:C,children:w}){let[T,E]=(0,L.useState)(!1),D=Zg({...e,hadOutput:o}),O=Qg({...e,hadOutput:o}),k=e.status===`failed`?e.conflictFiles:void 0,A=e.error?.split(`
|
|
186
186
|
`)[0],j=D===`failed`||D===`launch-failed`,M=j||D===`stopped`,N=!n&&u&&g&&S3.includes(e.status)?{roster:u,onChange:g}:null,P=l?w3[l.runtime]:null,F=D===`done`?e.commits[0]:void 0,ee=C3[D],te=D===`burning`?s:c,ne=a!==void 0&&a<8,I=!n&&(M||D===`burning`||N),re=`lane-${e.id}-detail`,ie=A&&!k&&!(r&&O);return(0,R.jsxs)(`div`,{id:`lane-${e.id}`,"data-lane-state":D,style:ne?{"--i":a}:void 0,className:q(`border-b border-border-subtle animate-rise-in`,ne&&`[animation-delay:calc(var(--i)*20ms)]`),children:[(0,R.jsxs)(`div`,{className:q(`group/lane flex min-h-10 items-center gap-3 rounded-md pr-2`,`transition-colors duration-(--dur-1) ease-app hover:bg-surface-hover`,ee.muted&&`opacity-60`),children:[(0,R.jsxs)(`button`,{type:`button`,"aria-expanded":r,"aria-controls":r?re:void 0,onClick:i,className:`flex min-h-10 min-w-0 flex-1 cursor-pointer items-center gap-2.5 rounded-md py-2 pl-2 text-left`,children:[(0,R.jsx)(Ty,{size:14,className:q(`shrink-0 text-icon transition-transform duration-(--dur-2) ease-app`,r&&`rotate-90`)}),(0,R.jsxs)(`span`,{className:`w-7 shrink-0 text-xs text-text-tertiary tabular-nums`,children:[`#`,e.seq]}),(0,R.jsx)(`span`,{className:q(`min-w-0 flex-1 truncate text-sm text-text`,ee.muted&&`line-through`),title:d?`${e.title} — fixes: ${d}`:e.title,children:e.title}),d&&(0,R.jsxs)(`span`,{className:`hidden max-w-60 min-w-0 shrink truncate text-xs text-text-tertiary @3xl:block`,title:`Fixes: ${d}`,children:[`fixes “`,d,`”`]}),(0,R.jsx)(`span`,{className:`hidden shrink-0 @lg:inline-flex`,children:(0,R.jsx)(aA,{kind:e.kind,passKind:e.passKind})})]}),(0,R.jsx)(`span`,{className:`hidden w-16 shrink-0 @xl:inline-flex`,children:F&&(C?(0,R.jsx)(WT,{label:`Copy commit SHA`,children:(0,R.jsx)(`button`,{type:`button`,className:q(T3,`cursor-pointer rounded-sm px-1 font-mono transition-colors duration-(--dur-1) hover:bg-surface-selected hover:text-text`),onClick:()=>C(F),children:lh(F)})}):(0,R.jsx)(`span`,{className:q(T3,`px-1 font-mono`),title:F,children:lh(F)}))}),(0,R.jsx)(`span`,{className:`hidden w-44 shrink-0 @2xl:inline-flex`,children:l&&P&&(0,R.jsxs)(`span`,{className:q(T3,`inline-flex max-w-full items-center gap-1.5 font-mono`),title:`Burns on ${l.id} (${l.runtimeLabel})`,children:[(0,R.jsx)(P,{size:12,className:`shrink-0 text-icon`}),(0,R.jsx)(`span`,{className:`truncate`,children:l.id})]})}),(0,R.jsx)(`span`,{className:q(T3,`hidden w-14 text-right @md:block`),children:te}),(0,R.jsx)(`span`,{className:`flex shrink-0 animate-fade-in @md:w-28`,children:(0,R.jsx)(rA,{tone:ee.tone,icon:ee.icon,className:ee.muted?`text-text-tertiary`:void 0,children:ee.word})},D)]}),(ie||k||I)&&(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 pr-2 pb-3 pl-17.5`,children:[ie&&(0,R.jsx)(`div`,{className:q(`min-w-0 truncate text-xs`,j?`text-danger`:`text-text-tertiary`),title:e.error,children:(0,R.jsx)(m2,{text:A})}),k&&(0,R.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,R.jsxs)(`p`,{className:`m-0 flex items-start gap-1.5 text-sm text-text-secondary`,children:[(0,R.jsx)(tb,{size:14,className:`mt-[3px] shrink-0 text-danger`}),(0,R.jsxs)(`span`,{className:`min-w-0`,children:[`Merge conflict — the work is committed but could not land on`,` `,(0,R.jsx)(`code`,{className:`font-mono text-xs text-text`,children:t})]})]}),k.length>0&&(0,R.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-0.5 p-0 pl-5`,children:k.map(e=>(0,R.jsx)(`li`,{className:`truncate font-mono text-xs text-text-secondary`,title:e,children:e},e))}),A&&(0,R.jsx)(`div`,{className:`truncate pl-5 text-xs text-text-tertiary`,title:e.error,children:(0,R.jsx)(m2,{text:A})})]}),I&&(0,R.jsxs)(`div`,{className:`-ml-2 flex flex-wrap items-center gap-1`,children:[M&&_&&(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(ab,{}),disabled:f,title:k?`run an agent that merges the feature branch into this ticket’s branch and resolves the conflict — it gets the ticket, the feature docs, and the commits it is reconciling against`:`retry this ticket — continues from any commits preserved by previous attempts`,onClick:_,children:k?`Resolve with agent`:`Retry`}),M&&u&&v&&(0,R.jsx)(u2,{value:``,roster:u,label:`Retry on…`,ticketKind:e.kind,onChange:v}),k&&S&&(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(Dy,{}),disabled:f||h,title:h?`available once this run finishes and no terminal is open`:`open a terminal on the feature branch, briefed with this ticket and its conflicting files, and resolve it yourself`,onClick:S,children:`Resolve in terminal`}),M&&y&&(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(Cy,{}),disabled:f,title:k?`throw away the conflicting branch and re-implement the ticket from the current feature branch tip`:`discard any preserved commits from previous attempts and redo the ticket from the feature branch tip`,onClick:()=>E(!0),children:`Retry fresh`}),M&&b&&(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(xy,{}),loading:m,disabled:f,title:`set this ticket aside — it stops asking to be retried and is carried into review as explicitly unfinished work`,onClick:b,children:m?`Waiving…`:`Waive`}),D===`burning`&&x&&(0,R.jsx)(Y,{variant:`danger-ghost`,size:`sm`,icon:(0,R.jsx)(Ry,{}),loading:p,disabled:f,title:`stop this ticket's agent — other lanes keep burning; committed work is preserved for retry`,onClick:x,children:p?`Stopping…`:`Stop ticket`}),N&&(0,R.jsx)(u2,{value:e.model??``,roster:N.roster,ticketKind:e.kind,onChange:N.onChange})]})]}),r&&(0,R.jsxs)(`div`,{id:re,className:q(`flex flex-col gap-3 overflow-hidden pr-2 pb-4 pl-17.5`,`h-auto transition-[height,opacity] duration-(--dur-2) ease-out-app starting:h-0 starting:opacity-0`),children:[O&&(0,R.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,R.jsxs)(`p`,{className:`m-0 flex items-start gap-1.5 text-sm text-text`,children:[(0,R.jsx)(tb,{size:14,className:`mt-[3px] shrink-0 text-danger`}),(0,R.jsx)(`span`,{className:`min-w-0 break-words`,children:O.text})]}),O.hint&&(0,R.jsx)(`p`,{className:`m-0 pl-5 text-sm text-text-secondary`,children:O.hint}),e.error&&(0,R.jsx)(JA,{size:`sm`,title:`What the engine reported`,className:`pl-5`,children:(0,R.jsx)(`pre`,{className:`m-0 overflow-x-auto rounded-md bg-surface-inset px-3 py-2 font-mono text-xs whitespace-pre-wrap text-text-secondary`,children:e.error})})]}),w]}),y&&(0,R.jsx)(x3,{open:T,title:`Start ticket #${e.seq} over?`,body:`Any commits preserved from previous attempts are discarded and the ticket is redone from the feature branch tip.`,confirmLabel:`Retry fresh`,confirmIcon:(0,R.jsx)(Cy,{}),busy:f,onConfirm:y,onClose:()=>E(!1)})]})}function D3({digest:e}){return e?.trim()?(0,R.jsx)(JA,{bare:!0,title:`What this ticket produced`,icon:(0,R.jsx)(ky,{}),children:(0,R.jsx)(PG,{source:e})}):null}var O3={"claude-code":Vy,codex:Hy};function k3({ticketId:e,bootEvents:t,runtime:n,poll:r=!0}){let{chunks:i,live:a,trimmed:o}=M3(e,r),s=(0,L.useRef)(null),[c,l]=(0,L.useState)(!0),{blocks:u,completed:d}=(0,L.useMemo)(()=>u_(i),[i]);(0,L.useEffect)(()=>{if(!c)return;let e=s.current;e&&(e.scrollTop=e.scrollHeight)},[u,a,c]);let f=()=>{let e=s.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight<24;l(t)},p=n?O3[n]:null,m=u.length>0||a;return(0,R.jsxs)(`div`,{className:`relative max-h-120 overflow-y-auto rounded-md bg-surface-inset px-4 py-3`,ref:s,onScroll:f,children:[o&&(0,R.jsx)(`div`,{className:`pb-2 text-center text-xs text-text-tertiary`,children:`Earlier output trimmed`}),!m&&(0,R.jsx)(WA,{children:`No agent output captured — transcripts are held in server memory for the current burn; older runs keep only the event timeline.`}),m&&(0,R.jsxs)(`div`,{className:`mb-1.5 flex items-center gap-1.5 text-xs font-medium text-text-secondary`,children:[p&&(0,R.jsx)(p,{size:14,className:`shrink-0 text-icon`}),n?O_(n):`Agent`]}),u.length===0&&a&&(0,R.jsx)(j3,{events:t}),u.length>0&&(0,R.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:u.map((e,t)=>(0,R.jsx)(A3,{block:e},t))}),d&&(0,R.jsx)(`div`,{className:`mt-2`,children:(0,R.jsx)(rA,{tone:`success`,icon:(0,R.jsx)(by,{}),children:`Agent reported complete`})}),a&&(0,R.jsx)(`div`,{className:`mt-2`,children:(0,R.jsx)(rA,{tone:`live`,children:`Burning…`})}),!c&&(0,R.jsx)(`div`,{className:`pointer-events-none sticky bottom-0 flex justify-end`,children:(0,R.jsx)(`span`,{className:`pointer-events-auto rounded-md bg-surface-raised shadow-popover animate-fade-in`,children:(0,R.jsx)(Y,{size:`sm`,icon:(0,R.jsx)(wy,{}),onClick:()=>l(!0),children:`Follow`})})})]})}function A3({block:e}){return e.kind===`text`?(0,R.jsx)(`div`,{className:`py-1 animate-rise-in`,children:(0,R.jsx)(PG,{source:e.text,size:`base`,tone:`primary`})}):(0,R.jsx)(JA,{size:`sm`,animate:!0,title:(0,R.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,title:e.args||void 0,children:[(0,R.jsx)(`span`,{className:`shrink-0 font-medium text-text-secondary`,children:e.name}),e.args&&(0,R.jsx)(`span`,{className:`min-w-0 truncate font-mono text-text-tertiary`,children:e.args})]}),bodyClassName:`pb-1`,children:e.args&&(0,R.jsx)(`pre`,{className:`m-0 font-mono text-xs break-words whitespace-pre-wrap text-text-tertiary`,children:e.args})})}function j3({events:e}){return e.length===0?(0,R.jsx)(WA,{children:`Starting the container…`}):(0,R.jsx)(`div`,{className:`flex flex-col gap-1`,children:e.map(e=>(0,R.jsxs)(`div`,{className:`flex gap-3 text-xs animate-rise-in`,children:[(0,R.jsx)(`span`,{className:`shrink-0 text-text-tertiary tabular-nums`,children:ah(e.ts)}),(0,R.jsx)(`span`,{className:`min-w-0 flex-1 break-words text-text-secondary`,children:e.message})]},e.id))})}function M3(e,t){let[n,r]=(0,L.useState)([]),[i,a]=(0,L.useState)(!1),[o,s]=(0,L.useState)(!1),c=n.length>0?n[n.length-1].i:void 0,l=eh(1e3),u=B.run.agentTranscript.useQuery({ticketId:e,after:c},{refetchInterval:t?l:!1});return(0,L.useEffect)(()=>{let e=u.data;e&&(a(e.live),s(e.firstIndex>0),r(t=>{let n=t.length>0?t[t.length-1].i:-1;if(e.nextIndex<=n)return[];if(e.chunks.length===0)return t;let r=e.chunks.filter(e=>e.i>n);return r.length===0?t:[...t,...r]}))},[u.data]),{chunks:n,live:i,trimmed:o}}function N3({runs:e,selectedId:t,latestId:n,onPick:r}){if(e.length<2)return null;let i=e.findIndex(e=>e.id===t),a=i>=0?e[i]:void 0,o=a?`${a.id===n?`Latest`:ph(a.startedAt)} · ${e.length} runs`:`${e.length} runs`;return(0,R.jsxs)(Q0,{value:t??void 0,onValueChange:r,children:[(0,R.jsxs)(n2,{"aria-label":`Run history`,title:a?oh(a.startedAt):void 0,className:t2,children:[(0,R.jsx)(eb,{size:14,className:`shrink-0 text-icon`}),(0,R.jsx)(r2,{children:o})]}),(0,R.jsx)(i2,{align:`end`,"aria-label":`Run history`,className:`min-w-72`,children:e.map(e=>(0,R.jsx)(c2,{value:e.id,title:oh(e.startedAt),children:(0,R.jsxs)(`span`,{className:`flex min-w-0 items-center gap-3`,children:[(0,R.jsx)(`span`,{className:`w-16 shrink-0 text-xs text-text-tertiary tabular-nums`,children:ph(e.startedAt)}),(0,R.jsx)(`span`,{className:`w-24 shrink-0`,children:(0,R.jsx)(cA,{status:e.status})}),(0,R.jsxs)(`span`,{className:`min-w-0 truncate`,children:[`Lap `,e.lap,` · `,e.ticketIds.length,` lane`,e.ticketIds.length===1?``:`s`]}),e.id===n&&(0,R.jsx)(`span`,{className:`shrink-0 text-xs text-text-tertiary`,children:`latest`})]})},e.id))})]})}function P3({headline:e,elapsed:t,status:n,landed:r,burning:i,busy:a,cancelling:o,onCancelRun:s,runs:c=[],selectedRunId:l=null,latestRunId:u=null,onPickRun:d,onBackToLatest:f}){let[p,m]=(0,L.useState)(!1),h=r&&r.total>0?e.split(` · `).filter(e=>!/^All \d+ tickets? landed$/.test(e)&&!/^(Burned|Burning) \d+ tickets?$/.test(e)&&!/^\d+ done$/.test(e)).join(`, `):e;return(0,R.jsxs)(`header`,{className:`mb-4 flex flex-col gap-1.5`,children:[(0,R.jsxs)(`div`,{className:`flex min-h-7 items-center gap-2`,children:[(0,R.jsx)(`h2`,{className:`m-0 min-w-0 flex-1 text-lg font-semibold text-text`,children:f?`Past run`:`Run`}),d&&(0,R.jsx)(N3,{runs:c,selectedId:l,latestId:u,onPick:d}),f&&(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(rb,{}),onClick:f,children:`Back to latest`}),s&&(0,R.jsx)(Y,{variant:`danger-ghost`,size:`sm`,icon:(0,R.jsx)(Ry,{}),loading:o,disabled:a,onClick:()=>m(!0),children:o?`Stopping…`:`Cancel run`})]}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5`,children:[n&&(0,R.jsx)(cA,{status:n}),(0,R.jsx)(xA,{items:[t?{icon:(0,R.jsx)(eb,{}),text:(0,R.jsx)(`span`,{className:`tabular-nums`,children:t})}:null,r&&r.total>0?{icon:(0,R.jsx)(Ny,{}),strong:`${r.done} of ${r.total}`,text:`landed`}:null,h?{text:h}:null]})]}),s&&(0,R.jsx)(x3,{open:p,title:`Cancel this run?`,body:i>0?`Stops ${i} burning agent${i===1?``:`s`}. Finished work is kept; the burn can resume later.`:`Stops the run before its remaining tickets start. Finished work is kept; the burn can resume later.`,confirmLabel:`Cancel run`,confirmIcon:(0,R.jsx)(Ry,{}),busy:a,onConfirm:s,onClose:()=>m(!1)})]})}function F3({tickets:e,currentLap:t,lane:n}){let r=0;return(0,R.jsx)(`div`,{className:`@container flex flex-col border-t border-border-subtle`,children:(0,R.jsx)(oj,{groups:Lg(e,t),currentLap:t,meta:e=>`${e.rows.length} lane${e.rows.length===1?``:`s`}`,headClassName:`mt-2 px-2`,children:e=>(0,R.jsx)(`div`,{className:`flex flex-col`,children:f_(e).map(e=>(0,R.jsxs)(`div`,{className:`flex flex-col`,children:[e.title&&(0,R.jsx)(mA,{className:`mt-4 px-2`,children:e.title}),e.rows.map(e=>n(e,r++))]},e.kind))})})})}var I3=140,L3=64;function R3(e){return e.replace(/```[^\n]*\n?/g,``).replace(/^\s{0,3}#{1,6}\s+/gm,``).replace(/^\s{0,3}>\s?/gm,``).replace(/^\s*[-*+]\s+/gm,``).replace(/^\s*\d+\.\s+/gm,``).replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/(\*\*|__)(.+?)\1/g,`$2`).replace(/~~(.+?)~~/g,`$1`).replace(/(^|[\s(])[*_](\S(?:.*?\S)?)[*_]($|[\s.,;:)!?])/g,`$1$2$3`).replace(/`([^`]+)`/g,`$1`).trim()}function z3(e){for(let t of e.split(`
|
|
187
|
-
`)){let e=t.trim();if(e!==``)return e}return``}function B3(e,t){return e.length>t?`${e.slice(0,t-1).trimEnd()}…`:e}function V3(e){if(typeof e!=`object`||!e)return null;let t=e;return typeof t.name!=`string`||t.name===``?null:{name:t.name,args:typeof t.args==`string`?t.args:``}}function H3(e){return e.endsWith(`.tool`)}function U3(e){let t=e.replace(/[._]+/g,` `).trim();return t===``?``:`${t[0].toUpperCase()}${t.slice(1)}`}function W3(e,t){if(!t.startsWith(e))return null;let n=t.slice(e.length).replace(/^[\s:;,—–-]+/,``).trim().replace(/^\((.*)\)$/s,`$1`).trim(),r=U3(e);return n===``?r:`${r} — ${n}`}function G3(e){return typeof e==`object`&&e?e:null}function K3(e){return typeof e==`string`&&e!==``?e:null}function q3(e){if(e.type!==`feature.created`)return null;let t=G3(e.data),n=K3(t?.branch);if(!t||!n)return null;if(t.draft===!0)return`Feature created as a draft — ${n} is not cut yet`;if(t.branchReady!==!0)return`Feature created — branch ${n} is still being cut`;let r=K3(t.baseBranch);return r?`Feature created on branch ${n}, from ${r}`:`Feature created on branch ${n}`}function J3(e){if(H3(e.type)){let t=V3(e.data);if(!t){let t=z3(e.message);return{summary:B3(t,I3)||U3(e.type),detail:e.message.trim()===t?null:e.message.trim()}}let n=B3(z3(t.args),L3);return{summary:n?`${t.name} — ${n}`:`${t.name}`,detail:t.args.trim()===``?null:t.args.trim()}}let t=R3(e.message),n=q3(e)??W3(e.type,t)??t,r=B3(z3(n),I3),i=n===r?null:n;return{summary:r||U3(e.type),detail:i}}function Y3(e){return e===`lap.started`}function X3(e){if(e.type!==`run.finished`||typeof e.data!=`object`||e.data===null)return null;let t=e.data.status;return t===`succeeded`||t===`failed`||t===`cancelled`?t:null}function Z3(e){let t=X3(e);if(t)return t===`succeeded`?`ok`:`error`;let n=e.type;return n===`merge.conflict.resolved`?`ok`:n===`merge.conflict.resolving`?`active`:/(error|fail|conflict|cancel|stopped|timeout)/i.test(n)?`error`:/(done|succeed|finished|shipped|merged)/i.test(n)?`ok`:/(start|burn|launch|advance|running|retry|resum)/i.test(n)?`active`:`info`}function Q3(e){return typeof e.data!=`object`||e.data===null?!1:e.data.oversized===!0}var $3={error:`danger`,ok:`success`,active:`neutral`,info:`neutral`};function e6({events:e}){let t=e.some(Q3);return(0,R.jsxs)(JA,{defaultOpen:t,title:`Run timeline`,icon:(0,R.jsx)(jy,{}),aside:(0,R.jsx)(`span`,{className:`tabular-nums`,children:e.length}),children:[e.length===0&&(0,R.jsx)(WA,{children:`Waiting for events…`}),(0,R.jsx)(`ol`,{className:`@container m-0 flex max-h-96 list-none flex-col overflow-y-auto p-0`,children:e.map(e=>{let t=Q3(e);return(0,R.jsxs)(`li`,{className:`flex min-h-7 items-start gap-3 py-1 text-sm`,children:[(0,R.jsx)(`span`,{className:`w-20 shrink-0 pt-px text-xs whitespace-nowrap text-text-tertiary tabular-nums`,children:ah(e.ts)}),(0,R.jsx)(`span`,{className:`inline-flex h-5 w-2 shrink-0 items-center justify-center`,children:(0,R.jsx)(tA,{tone:t?`warning`:$3[Z3(e)]??`neutral`})}),(0,R.jsx)(`span`,{className:q(`min-w-0 flex-1`,t?`break-words text-warning`:`truncate text-text-secondary`),children:e.message}),(0,R.jsx)(`span`,{className:`hidden w-40 shrink-0 truncate pt-px text-right font-mono text-xs text-text-tertiary @xl:block`,children:e.type})]},e.id)})})]},t?`warned`:`quiet`)}function t6({gates:e}){return e.length===0?null:(0,R.jsxs)(`section`,{className:`mb-6 flex flex-col gap-2`,role:`alert`,children:[(0,R.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,R.jsx)(rA,{tone:`warning`,icon:(0,R.jsx)(tb,{}),size:`sm`,strong:!0,children:`Verification unavailable`}),(0,R.jsx)(`p`,{className:`m-0 pl-5.5 text-sm text-text-secondary`,children:`The sandbox lacked a command or runtime. Ticket results were kept; these gates still need checking.`})]}),(0,R.jsx)(`ul`,{className:`m-0 flex list-none flex-col p-0 pl-5.5`,children:e.map(e=>(0,R.jsxs)(`li`,{className:`flex flex-col gap-0.5 border-t border-border-subtle py-2 first:border-t-0`,children:[(0,R.jsx)(`code`,{className:`font-mono text-xs text-text`,children:e.command}),(0,R.jsx)(`span`,{className:`font-mono text-xs break-words text-text-tertiary`,children:e.error})]},e.command))})]})}function n6({featureId:e,runId:t,readonly:n=!1,chatDocked:r=!1}){let i=eh(),a=Ab(),o=B.useUtils(),[s,c]=(0,L.useState)(null),l=!!s&&s!==t,u=s??t,d=n||l,f=B.feature.get.useQuery({id:e},{refetchInterval:i}),p=B.run.get.useQuery({runId:u},{refetchInterval:!l&&i,enabled:!!u}),m=B.run.listByFeature.useQuery({featureId:e},{refetchInterval:i}),h=pF(e),g=f.data?.feature.projectId,_=B.settings.get.useQuery({projectId:g},{enabled:!!g}),v=B.findings.listByFeature.useQuery({featureId:e}),y={onSuccess:()=>o.feature.get.invalidate({id:e}),onError:e=>a.push(e.message)},b=B.ticket.retry.useMutation(y),x=B.ticket.edit.useMutation(y),S=B.ticket.stop.useMutation(y),C=B.ticket.cancel.useMutation(y),w=B.feature.launchSession.useMutation(y),T=B.run.cancel.useMutation(y),E=b.isPending||x.isPending||S.isPending||C.isPending||w.isPending||T.isPending,D=l?p.data?.tickets??[]:f.data?.tickets??[],O=f.data?.feature.branch??``,k=f.data?.feature.lap??1,A=(0,L.useMemo)(()=>h.filter(e=>e.runId===u),[h,u]),j=(0,L.useMemo)(()=>Dg(A),[A]),M=(0,L.useMemo)(()=>p_(A),[A]),N=(0,L.useMemo)(()=>Jg(A),[A]),[P,F]=(0,L.useState)(null),ee=D.find(e=>e.status===`burning`)?.id,te=P??new Set(ee?[ee]:[]),ne=e=>F(()=>{let t=new Set(te);return t.has(e)?t.delete(e):t.add(e),t}),I=Vp(_.data),re=(0,L.useMemo)(()=>new Map((v.data?.findings??[]).map(e=>[e.id,e.title])),[v.data]),ie=e=>Rg(e,I)??Rg({model:mm(_.data,e.kind===`review`?`review`:`implement`)},I),ae=f.data?.sessions??[],oe=ae.some(Ag),se=oe||p.data?.status===`running`,ce=p.data?p.data.status===`running`:!!u;if(!t&&!oe)return(0,R.jsx)(GA,{icon:(0,R.jsx)(Py,{}),title:`No run yet`,hint:`${j_} Every ticket gets its own lane here.`});let le=D.filter(e=>e.status===`burning`).length,ue=e=>{navigator.clipboard?.writeText(e).then(()=>a.push(`copied ${lh(e)}`,`info`),()=>a.push(`copy failed`))},de=e=>b.mutate({ticketId:e.id},{onSuccess:t=>{t.resolvingConflict?a.push(`resolving ticket #${e.seq}'s conflict with an agent`,`info`):t.resumedFrom&&a.push(`resuming ticket #${e.seq} from ${t.preservedCommits} preserved commit(s)`,`info`)}}),fe=(t,n)=>{let r=M.get(t.id),i=j.get(t.id),o=t.status===`failed`?t.conflictFiles:void 0;return(0,R.jsxs)(E3,{ticket:t,featureBranch:O,readonly:d,expanded:te.has(t.id),index:n,onToggle:()=>ne(t.id),hadOutput:r?.hadOutput,elapsed:r?mh(r.startedAt,Date.now()):void 0,duration:i===void 0?void 0:mh(0,i),model:ie(t),roster:I,defectTitle:t.originFindingId?re.get(t.originFindingId):void 0,busy:E,stopping:S.isPending&&S.variables?.ticketId===t.id,waiving:C.isPending&&C.variables?.ticketId===t.id,terminalBlocked:se,onCopySha:ue,onModel:e=>x.mutate({ticketId:t.id,model:e}),onRetry:()=>de(t),onRetryWithModel:ce?void 0:e=>x.mutate({ticketId:t.id,model:e},{onSuccess:()=>de(t)}),onRetryFresh:()=>b.mutate({ticketId:t.id,fresh:!0}),onWaive:()=>C.mutate({ticketId:t.id,reason:`waived from the run view`},{onSuccess:e=>{a.push(`ticket #${t.seq} set aside — it stays visible as unfinished work at review`,`info`),e.confirmed||a.push(N_)}}),onStop:()=>S.mutate({ticketId:t.id},{onSuccess:e=>{e.swept?a.push(`no live agent — the lane was orphaned; marked failed, retry to resume it`,`info`):e.stopped?e.confirmed||a.push(N_):a.push(`no live agent for this ticket (already finishing?)`,`info`)}}),onResolveInTerminal:o?()=>w.mutate({featureId:e,kind:`chat`,kickoffLine:yg({seq:t.seq,title:t.title,branch:t.attemptBranch??``,featureBranch:O,files:o}),purpose:`resolve-conflict`,purposeData:{mergeFrom:t.attemptBranch??``,mergeInto:O}}):void 0,children:[(0,R.jsx)(D3,{digest:t.digest}),(0,R.jsx)(LG,{label:`agent transcript`,children:(0,R.jsx)(k3,{ticketId:t.id,bootEvents:A.filter(e=>e.ticketId===t.id),runtime:ie(t)?.runtime,poll:!l})})]},t.id)};return(0,R.jsxs)(`div`,{className:`flex flex-col`,children:[(0,R.jsx)(b1,{featureId:e,sessions:qv(ae,r),className:`mb-10 h-[clamp(320px,calc(100dvh-360px),960px)]`}),(0,R.jsx)(P3,{headline:e_(D.map(e=>({...e,hadOutput:M.get(e.id)?.hadOutput,reviewFix:!!e.originFindingId})),{status:p.data?.status},m_(D,A)),elapsed:p.data?mh(p.data.startedAt,p.data.endedAt??Date.now()):``,status:p.data?.status,landed:{done:D.filter(e=>e.status===`done`).length,total:D.length},burning:le,busy:E,cancelling:T.isPending,onCancelRun:d||!t||p.data?.status!==`running`?void 0:()=>T.mutate({runId:t},{onSuccess:e=>{e.confirmed||a.push(N_)}}),runs:m.data??[],selectedRunId:u,latestRunId:t,onPickRun:c,...l?{onBackToLatest:()=>c(null)}:{}}),(0,R.jsx)(t6,{gates:N}),D.length===0?(0,R.jsx)(GA,{icon:(0,R.jsx)(Py,{}),title:`No ticket lanes`,hint:`This run has nothing to burn — a session breaks the work into tickets, and they appear here as lanes.`}):(0,R.jsx)(F3,{tickets:D,currentLap:k,lane:fe}),(0,R.jsxs)(`div`,{className:`mt-8 flex flex-col`,children:[(0,R.jsx)(e6,{events:A}),p.data?.digest&&(0,R.jsx)(r6,{digest:p.data.digest})]})]})}function r6({digest:e}){return(0,R.jsx)(JA,{title:`What this run produced`,icon:(0,R.jsx)(ky,{}),children:(0,R.jsx)(PG,{source:e})})}var i6={error:`danger`,ok:`success`,active:`accent`,info:`neutral`};function a6(e){return e.replace(/_/g,` `).replace(`.`,` · `)}function o6({events:e}){let t=e.slice(-50).reverse();return t.length===0?(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(jy,{}),title:`Nothing yet`,hint:`Everything that happens to this feature shows up here.`}):(0,R.jsx)(`div`,{className:`flex flex-col`,children:t.map(e=>Y3(e.type)?(0,R.jsx)(s6,{event:e},e.id):(0,R.jsx)(c6,{event:e},e.id))})}function s6({event:e}){return(0,R.jsxs)(`div`,{className:`my-2 flex items-center gap-2 text-xs font-medium text-accent-text`,role:`separator`,children:[(0,R.jsx)(`span`,{className:`first-letter:uppercase`,children:J3(e).summary}),(0,R.jsx)(`span`,{className:`h-px flex-1 bg-border-subtle`}),(0,R.jsx)(`span`,{className:`font-normal text-text-tertiary tabular-nums`,children:fh(e.ts)})]})}function c6({event:e}){let[t,n]=(0,L.useState)(!1),r=J3(e);return(0,R.jsxs)(`div`,{className:`flex gap-3 py-2`,children:[(0,R.jsx)(`span`,{className:`flex h-5 w-1.5 shrink-0 items-center`,children:(0,R.jsx)(tA,{tone:i6[Z3(e)]})}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[r.detail?(0,R.jsxs)(`button`,{type:`button`,className:`group/ev m-0 flex w-full cursor-pointer items-start gap-1 bg-transparent p-0 text-left text-sm text-text-secondary transition-colors duration-(--dur-1) ease-app hover:text-text`,"aria-expanded":t,title:t?`Show less`:`Show the whole event`,onClick:()=>n(e=>!e),children:[(0,R.jsx)(`span`,{className:`min-w-0 flex-1`,children:r.summary}),(0,R.jsx)(Ty,{size:14,"aria-hidden":`true`,className:q(`mt-0.5 shrink-0 text-icon transition-transform duration-(--dur-2) ease-app`,t&&`rotate-90`)})]}):(0,R.jsx)(`div`,{className:`text-sm text-text-secondary`,children:r.summary}),t&&r.detail&&(0,R.jsx)(`pre`,{className:`m-0 mt-2 max-h-[260px] overflow-auto rounded-md bg-surface-inset px-2.5 py-2 font-mono text-xs break-words whitespace-pre-wrap text-text-secondary animate-fade-in`,children:r.detail}),(0,R.jsxs)(`div`,{className:`mt-0.5 flex items-baseline gap-2 text-xs text-text-tertiary`,children:[(0,R.jsx)(`span`,{className:`truncate`,children:a6(e.type)}),(0,R.jsx)(`span`,{className:`ml-auto shrink-0 tabular-nums`,children:fh(e.ts)})]})]})]})}function l6(e){return e.split(/[\\/]/).pop()??e}function u6({featureId:e,docs:t}){let[n,r]=(0,L.useState)(null),i=(0,L.useRef)(null);return(0,R.jsxs)(`section`,{"aria-label":`Knowledge`,children:[t.length===0?(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(ky,{}),title:`No docs yet`,hint:`Docs the sessions write — decisions, the spec, the map — collect here.`}):(0,R.jsx)(yA,{label:`Feature docs`,className:`-mx-2`,children:t.map((e,t)=>(0,R.jsx)(vA,{index:t,leading:(0,R.jsx)(ky,{}),title:e.title||l6(e.relPath),meta:(0,R.jsx)(`span`,{className:`font-mono`,children:l6(e.relPath)}),onClick:t=>{i.current=t.currentTarget,r({relPath:e.relPath,title:e.title})}},e.relPath))}),n&&(0,R.jsx)(A1,{featureId:e,relPath:n.relPath,title:n.title,returnFocusRef:i,onClose:()=>r(null)})]})}var d6=[{id:`knowledge`,label:`Knowledge`,icon:(0,R.jsx)(ky,{})},{id:`activity`,label:`Activity`,icon:(0,R.jsx)(jy,{})}];function f6({featureId:e,onClose:t}){return t?(0,R.jsx)(p6,{featureId:e,onClose:t}):null}function p6({featureId:e,onClose:t}){let[n,r]=(0,L.useState)(`knowledge`),i=B.feature.get.useQuery({id:e},{refetchInterval:eh()}),a=pF(e);return(0,R.jsx)(LA,{label:`Details`,title:(0,R.jsx)(CA,{items:d6,value:n,onChange:r,size:`sm`,label:`Details`}),onClose:t,bodyClassName:`px-4 py-4`,children:i.isLoading?(0,R.jsx)(UA,{children:`Loading…`}):i.data?(0,R.jsx)(`div`,{role:`tabpanel`,"aria-label":n===`knowledge`?`Knowledge`:`Activity`,className:`animate-fade-in`,children:n===`knowledge`?(0,R.jsx)(u6,{featureId:e,docs:i.data.docs}):(0,R.jsx)(o6,{events:a})},n):(0,R.jsx)(WA,{children:i.error?.message??`Could not load the details`})})}function m6({featureId:e,sessions:t,busy:n,onOpenChat:r,onCollapse:i}){let a=Kv(t),o=!!a&&Ag(a);return(0,R.jsx)(LA,{label:`Chat`,title:(0,R.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[o&&a&&(0,R.jsx)(dA,{status:a.status}),(0,R.jsx)(`span`,{children:`Chat`}),(0,R.jsx)(`span`,{className:`truncate font-normal text-text-tertiary`,children:`One transcript, resumed`})]}),actions:o&&a?(0,R.jsx)(IG,{featureId:e,sessionId:a.id}):void 0,onClose:i,bodyClassName:`flex flex-col overflow-hidden`,children:(0,R.jsx)(`section`,{"aria-label":`Feature chat`,className:`flex min-h-0 flex-1 flex-col`,children:o&&a?(0,R.jsx)(`div`,{className:`min-h-0 flex-1 bg-surface-inset`,id:`chat-panel-terminal`,children:(0,R.jsx)(LG,{label:`terminal`,children:(0,R.jsx)(_1,{sessionId:a.id})})}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-4`,children:a?(0,R.jsx)(d3,{sessionId:a.id,className:`flex flex-col gap-4`}):(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(Oy,{}),title:`No conversation yet`,hint:`One chat per feature — it knows the state, answers questions, and edits the next burn's tickets.`})}),(0,R.jsxs)(`div`,{className:`flex flex-none items-center gap-3 border-t border-border-subtle px-4 py-3`,children:[(0,R.jsx)(Y,{variant:`secondary`,icon:a?(0,R.jsx)(ab,{}):(0,R.jsx)(Ly,{}),disabled:n,onClick:r,children:a?`Resume the conversation`:`Start the conversation`}),(0,R.jsx)(`span`,{className:`truncate text-xs text-text-tertiary`,children:`Every door resumes it`})]})]})})})}function h6({tag:e,details:t,children:n}){let r=Ab();return(0,R.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-md bg-danger-subtle px-4 py-3`,role:`alert`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-danger`,children:[(0,R.jsx)(tb,{size:16,className:`shrink-0`}),e]}),(0,R.jsx)(`p`,{className:`m-0 text-sm text-text-secondary`,children:n}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,R.jsx)(`code`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-text-tertiary`,title:t,children:t}),(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(Jy,{}),onClick:()=>NP(t,r),children:`Copy details`})]})]})}function g6({crumb:e,children:t}){return(0,R.jsxs)(`section`,{className:`flex min-h-0 min-w-0 flex-1 flex-col bg-surface`,children:[(0,R.jsx)(MA,{crumbs:[{label:e,icon:(0,R.jsx)(tb,{})}]}),(0,R.jsx)(PA,{children:t})]})}function _6({featureId:e,error:t}){return(0,R.jsx)(g6,{crumb:`Feature`,children:(0,R.jsx)(h6,{tag:`Broken`,details:`feature ${e} — ${t.name}: ${t.message}`,children:`This feature couldn't be rendered. Everything else still works.`})})}function v6({feature:e}){return(0,R.jsxs)(g6,{crumb:e.title,children:[(0,R.jsx)(FA,{title:e.title,meta:[{text:`Unknown phase`}]}),(0,R.jsx)(`div`,{className:`mt-8`,children:(0,R.jsxs)(h6,{tag:`Unrecognized phase`,details:`feature ${e.id} (${e.slug}) has phase "${e.phase}"`,children:[`This feature's phase is `,(0,R.jsx)(`strong`,{className:`font-mono font-medium text-text`,children:e.phase}),`, which this version of runcastle doesn't know. Nothing here can be acted on until the row is fixed.`]})})]})}function y6({step:e}){return e.state===`done`?(0,R.jsx)(xb,{phase:`shipped`,size:14,label:``}):e.state===`current`?(0,R.jsx)(xb,{phase:e.phase,size:14,label:``,className:e.phase===`shipped`?void 0:`text-text`}):(0,R.jsx)(xb,{phase:`draft`,size:14,label:``,className:`text-text-tertiary`})}var b6={done:`text-text-secondary`,current:`font-medium text-text`,upcoming:`text-text-tertiary`};function x6({steps:e,onView:t,readonly:n=!1}){return(0,R.jsx)(`nav`,{"aria-label":`Pipeline`,className:`-ml-2 flex flex-wrap items-center gap-x-0.5 gap-y-1`,children:e.map((r,i)=>{let a=n&&r.isViewed;return(0,R.jsxs)(L.Fragment,{children:[(0,R.jsxs)(`button`,{type:`button`,className:q(`inline-flex h-(--control-sm) shrink-0 items-center gap-1.5 rounded-md px-2 text-xs`,`transition-colors duration-(--dur-1) ease-app`,b6[r.state],a&&`bg-surface-selected text-text`,r.clickable&&!a?`cursor-pointer hover:bg-surface-hover hover:text-text`:r.clickable?`cursor-pointer`:`cursor-default`),title:r.tip,"aria-current":r.state===`current`?`step`:void 0,"aria-pressed":r.clickable?a:void 0,disabled:!r.clickable,onClick:()=>r.clickable&&t(r.phase),children:[(0,R.jsx)(y6,{step:r}),(0,R.jsx)(`span`,{children:vb[r.phase]})]}),i<e.length-1&&(0,R.jsx)(`span`,{"aria-hidden":`true`,className:`mx-0.5 h-px w-3 shrink-0 bg-border-strong`})]},r.phase)})})}function S6({feature:e,isDraft:t,steps:n,onViewPhase:r,readonly:i=!1,facts:a=[],className:o,children:s}){let c=Ab(),l=(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-4 gap-y-1.5`,children:[!t&&e.branch&&(0,R.jsxs)(`button`,{type:`button`,className:q(`inline-flex min-w-0 max-w-full cursor-pointer items-center gap-1.5 rounded-sm bg-transparent p-0`,`font-mono text-xs text-text-tertiary transition-colors duration-(--dur-1) ease-app hover:text-text`),title:`Copy branch name`,onClick:()=>NP(e.branch,c),children:[(0,R.jsx)(gy,{size:14,className:`shrink-0 text-icon`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.branch})]}),(0,R.jsx)(xA,{items:a})]});return(0,R.jsx)(FA,{title:e.title,meta:l,className:o,children:(!t||s)&&(0,R.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[!t&&(0,R.jsx)(x6,{steps:n,readonly:i,onView:t=>r(t===e.phase?null:t)}),s]})})}var C6={startDraft:(0,R.jsx)(Ly,{}),chat:(0,R.jsx)(Oy,{}),converge:(0,R.jsx)(By,{}),workNext:(0,R.jsx)(Iy,{}),resumeConverge:(0,R.jsx)(ab,{}),burn:(0,R.jsx)(Py,{}),cancelRun:(0,R.jsx)(Ry,{}),testDriveStart:(0,R.jsx)(Ly,{}),testDriveStop:(0,R.jsx)(Ry,{}),stopDriveAndIterate:(0,R.jsx)(Ry,{}),fixDrive:(0,R.jsx)(Dy,{}),merge:(0,R.jsx)(Ky,{}),resolveConflict:(0,R.jsx)(tb,{}),iterate:(0,R.jsx)(ab,{}),endSessionAndIterate:(0,R.jsx)(ab,{}),unarchive:(0,R.jsx)(Wy,{})},w6={danger:`danger`,note:`neutral`,clear:`success`};function T6(e){return/[.!?…:]$/.test(e)?e:`${e}.`}function E6({ns:e,guidance:t,busy:n,onAction:r,draftBranch:i,hideChat:a=!1,demote:o}){let s=a?e.secondary.filter(e=>e.kind!==`chat`):e.secondary,c=[...s,e.primary].filter(e=>!!e?.disabled),l=!!e.primary||s.length>0,u=s.filter(e=>!o?.includes(e.kind)),d=s.filter(e=>o?.includes(e.kind)),f=u.length>2?u.slice(0,2):u,p=[...u.length>2?u.slice(2):[],...d],m=c.filter(t=>!o?.includes(t.kind)||t===e.primary);if(!l&&!e.busy&&!e.alert&&!e.counts&&!e.note)return null;let h=e.title??(t?void 0:e.desc),g=t&&e.desc&&e.desc!==h?e.desc:void 0;return(0,R.jsxs)(`div`,{className:`flex flex-wrap items-start gap-x-6 gap-y-3 animate-fade-in`,role:e.alert?`alert`:void 0,children:[(0,R.jsxs)(`div`,{className:`min-w-0 flex-1 basis-80 text-sm text-text-secondary`,children:[(h||g)&&(0,R.jsxs)(`p`,{className:`m-0 text-pretty`,children:[e.busy?(0,R.jsx)(aE,{size:`sm`,className:`mr-2 inline-block align-[-2px]`}):e.alert?(0,R.jsx)(tA,{tone:`warning`,className:`mr-2 align-middle`}):null,h&&(0,R.jsx)(`span`,{className:`font-medium text-text`,children:g?T6(h):h}),h&&g&&` `,g]}),e.counts&&(0,R.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1`,children:[e.counts.pills.map(e=>(0,R.jsx)(rA,{tone:w6[e.tone],size:`sm`,children:e.label},e.label)),e.counts.trailing&&(0,R.jsx)(`span`,{className:`text-sm text-text-tertiary`,children:e.counts.trailing})]}),e.note&&(0,R.jsx)(`p`,{className:`mt-1.5 mb-0 text-xs text-text-tertiary first-letter:uppercase`,role:`note`,children:e.note})]}),l&&(0,R.jsxs)(`div`,{className:`ml-auto flex min-w-0 flex-col items-end gap-1.5`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-end gap-2`,children:[f.map((e,t)=>(0,R.jsx)(Y,{variant:`ghost`,icon:C6[e.kind],disabled:n||!!e.disabled,title:e.disabled??e.hint,onClick:()=>r(e.kind,e.waypointId),children:e.label},t)),p.length>0&&(0,R.jsxs)(DP,{children:[(0,R.jsx)(OP,{asChild:!0,children:(0,R.jsx)(nE,{label:`More actions`,icon:(0,R.jsx)(Ey,{}),disabled:n})}),(0,R.jsx)(kP,{align:`end`,children:p.map(e=>(0,R.jsx)(AP,{icon:C6[e.kind],disabled:!!e.disabled,title:e.disabled??e.hint,onSelect:()=>r(e.kind,e.waypointId),children:e.label},e.kind))})]}),e.primary&&(0,R.jsxs)(R.Fragment,{children:[i&&(0,R.jsx)(ij,{prefix:`from`,value:i.value,branches:i.branches,detected:i.detected,missing:i.missing,onPick:i.onPick}),(0,R.jsx)(Y,{variant:e.primary.danger?`danger`:`primary`,icon:C6[e.primary.kind],disabled:n||!!e.primary.disabled,title:e.primary.disabled??e.primary.hint,onClick:()=>r(e.primary.kind,e.primary.waypointId),children:n?`Working…`:e.primary.label})]})]}),m.map(e=>(0,R.jsxs)(`div`,{className:q(`flex flex-wrap items-center justify-end gap-2 text-right text-xs`,i&&e.kind===`startDraft`&&i.missing?`text-warning`:`text-text-tertiary`),children:[(0,R.jsx)(`span`,{children:e.disabled}),e.escape&&(0,R.jsx)(Y,{size:`sm`,variant:`secondary`,icon:C6[e.escape.kind],onClick:()=>r(e.escape.kind),disabled:n,children:e.escape.label})]},e.kind))]})]},`${e.title??``}|${e.primary?.kind??``}`)}function D6({phase:e,livePhase:t,facts:n,onBack:r}){return(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2 animate-fade-in`,role:`status`,children:[(0,R.jsxs)(`p`,{className:`m-0 min-w-0 flex-1 basis-60 text-sm text-text-secondary`,children:[(0,R.jsxs)(`span`,{className:`font-medium text-text`,children:[`Viewing `,vb[e].toLowerCase()]}),n?(0,R.jsxs)(`span`,{className:`text-text-tertiary`,children:[` — `,n]}):null]}),(0,R.jsxs)(Y,{variant:`ghost`,icon:(0,R.jsx)(rb,{}),onClick:r,children:[`Back to `,vb[t].toLowerCase()]})]})}function O6(e){let t=pF(e),[n,r]=(0,L.useState)(null),i=(0,L.useRef)(null);return(0,L.useEffect)(()=>{if(t.length===0)return;let e=t[t.length-1].id;if(i.current===null){i.current=e;return}let n=i.current;i.current=e;let a=t.filter(e=>e.id>n&&e.type===`session.resume_failed`),o=a[a.length-1];o&&r(o.message||`session resume failed — relaunch to continue`)},[t]),(0,L.useEffect)(()=>{if(!n)return;let e=setTimeout(()=>r(null),8e3);return()=>clearTimeout(e)},[n]),{message:n,dismiss:()=>r(null)}}var k6=`flex h-full min-h-0 min-w-0 flex-1 flex-col bg-surface`,A6=`runcastle.feature.details`;function j6(e){try{return sessionStorage.getItem(e)}catch{return null}}function M6(e,t){try{sessionStorage.setItem(e,t)}catch{}}function N6({featureId:e,viewedPhase:t,onViewPhase:n,guidance:r,mapRailCollapsed:i,onToggleMapRail:a,artifactPaneCollapsed:o,onToggleArtifactPane:s,chatPanelOpen:c,onToggleChatPanel:l,driving:u,onDriveChange:d,onDeleted:f,detailsOpen:p,onToggleDetails:m}){let h=B.useUtils(),g=Ab(),_=B.feature.get.useQuery({id:e},{refetchInterval:eh()}),v=O6(e),y=pF(e),b=Nd(y),x=wg(y),S=_.data?.feature.phase===`review`,C=B.feature.mergeDelta.useQuery({featureId:e},{refetchInterval:eh(5e3),enabled:S}),w=eh(),T=S?w:!1,E=B.notes.list.useQuery({featureId:e},{refetchInterval:T}),D=E.data?.filter(e=>e.status===`open`)??[],O=E.data?D.length:void 0,k=B.findings.listByFeature.useQuery({featureId:e},{refetchInterval:T}),A=k.data?.openDefects??[],j=k.data?.summary.open,M=Um(e,S),N=mv(M.data??[]),P=gv(N,{landedSince:N?.landedSince??0,lap:_.data?.feature.lap??1},_v(_.data?.tickets??[])),F=Ov({passes:M.data??[],tickets:_.data?.tickets??[],currentLap:_.data?.feature.lap??1}),[ee,te]=(0,L.useState)(!1),[ne,I]=(0,L.useState)(!1),re=!!_.data&&_.data.feature.phase!==`shipped`,ie=B.feature.burnWarnings.useQuery({featureId:e},{refetchInterval:eh(),enabled:re}),[ae,oe]=(0,L.useState)(null),se=B.notes.triagePreview.useQuery({featureId:e},{enabled:ae!==null}),ce=_.data?b_(_.data):void 0,le=B.docs.read.useQuery({featureId:e,relPath:ce??`map.md`},{enabled:!!ce}),ue=_.data?.feature.phase===`review`?jv(_.data):void 0,de=Nv(B.docs.read.useQuery({featureId:e,relPath:ue??`spec.md`},{enabled:!!ue}).data?.content),fe=_.data?.feature.projectId,pe=B.project.prep.useQuery({projectId:fe??``},{enabled:!!fe,refetchInterval:eh()}),me=B.feature.driveInfo.useQuery(void 0,{refetchInterval:eh()}),he=B.ticket.durationStats.useQuery({projectId:fe??``},{enabled:!!fe}),ge=mm(B.settings.get.useQuery({projectId:fe??``},{enabled:!!fe&&re}).data,`implement`),_e=_.data?.feature.phase===`planning`||_.data?.feature.phase===`building`,ve=B.docs.digestSize.useQuery({featureId:e},{enabled:_e}),ye=_.data?.feature.status===`draft`,be=B.project.branches.useQuery({projectId:fe??``},{enabled:!!fe&&ye}),[xe,Se]=(0,L.useState)(null),Ce=(xe?.featureId===e?xe.base:``)||(be.data?mg(be.data):``),we=!ye||Ce?void 0:be.data?`unpicked`:`loading`,Te=hF(vh(_.data?.runs??[])),Ee=gF(e,_F(_.data?.docs??[],`decisions.md`)).content,De=()=>{h.feature.get.invalidate({id:e}),h.feature.list.invalidate(),h.events.invalidate()},Oe=B.feature.launchSession.useMutation({onSuccess:De,onError:e=>g.push(e.message)}),ke=B.feature.burn.useMutation({onSuccess:()=>{De(),n(null)},onError:e=>g.push(e.message)}),Ae=B.feature.converge.useMutation({onSuccess:()=>{De(),n(null)},onError:e=>g.push(e.message)}),je=B.feature.workWaypoint.useMutation({onSuccess:De,onError:e=>g.push(e.message)}),Me=B.feature.endSession.useMutation({onError:e=>g.push(e.message)}),Ne=B.notes.triage.useMutation(),Pe=B.findings.dismiss.useMutation(),Fe=B.run.cancel.useMutation({onSuccess:e=>{De(),e.confirmed?g.push(`run cancelled — its agents are stopped`,`info`):g.push(N_)},onError:e=>g.push(e.message)}),Ie=B.feature.fixDrive.useMutation({onSuccess:De,onError:e=>g.push(e.message)}),Le=B.feature.testDrive.useMutation({onSuccess:e=>{if(De(),e.hookFailure){let t=e.hookFailure;g.push(`${t.phase===`setup`?`Test drive setup`:`Test drive teardown`} failed: ${t.command}${t.timedOut?` (timed out)`:``} — see the timeline for its output`)}e.dbDrift&&g.push(e.dbDrift.resetCommand?`Migrations differ between the branches — your dev database may be ahead. Rebuild it with: ${e.dbDrift.resetCommand}`:`Migrations differ between the branches — your dev database may be ahead. Set a database reset command in settings for a one-line fix here.`,`info`),e.carriedChanges?.length&&g.push(`${e.carriedChanges.length} uncommitted file(s) came back with you onto ${e.branch}`,`info`)},onError:e=>g.push(e.message)}),Re=B.feature.merge.useMutation({onSettled:De,onError:e=>g.push(e.message)}),ze=B.feature.unarchive.useMutation({onSuccess:()=>{De(),g.push(`feature unarchived`,`success`)},onError:e=>g.push(e.message)}),Be=B.feature.start.useMutation({onSuccess:(e,t)=>{De(),Oe.mutate({featureId:t.featureId,kind:`chat`})},onError:e=>g.push(e.message)}),Ve=mF(e,_.data?.feature.branch??``),[He,Ue]=(0,L.useState)(null),[We,Ge]=(0,L.useState)(()=>j6(A6)===`1`),Ke=p!==void 0,qe=Ke?p:We,Je=e=>{if(Ke){e!==p&&m?.();return}Ge(e),M6(A6,e?`1`:`0`)},[Ye,Xe]=(0,L.useState)(null),Ze=B.feature.archive.useMutation({onSuccess:()=>{De(),g.push(`feature archived`,`success`)},onError:e=>g.push(e.message)}),Qe=B.feature.delete.useMutation({onSuccess:()=>{h.feature.list.invalidate(),Xe(null),f?.()},onError:e=>g.push(e.message)});if(_.isLoading)return(0,R.jsxs)(`section`,{className:k6,children:[(0,R.jsx)(MA,{}),(0,R.jsx)(PA,{children:(0,R.jsx)(UA,{children:`Loading feature…`})})]});if(!_.data)return(0,R.jsxs)(`section`,{className:k6,children:[(0,R.jsx)(MA,{}),(0,R.jsx)(PA,{children:(0,R.jsxs)(WA,{children:[`Could not load the feature`,_.error?`: ${_.error.message}`:``]})})]});let $e=!!_.error,et=_.data,tt=et.feature;if(nd(tt.phase)===null)return(0,R.jsx)(v6,{feature:tt});let nt=sv(tt,t),rt=cv(tt,nt),it=lv(tt,nt,{planning:(e=>ey({phase:e,full:et,events:y,decisions:Ee}))(`planning`)}),at=vh(et.runs),ot=qg(y,at?.id),st=Te&&at?.id===Te&&nt===`review`?`building`:nt,ct=$_(et,{driving:u?.featureId===tt.id,driveState:me.data?.featureId===tt.id?me.data.state:`idle`,mapContent:le.data?.content,conflict:b,unverifiedDriveKeys:jp(pe.data?.findings??[]),...me.data&&me.data.featureId!==tt.id?{slotHolder:me.data.holderLabel}:{},...he.data?{burnStats:he.data}:{},...ve.data?{docsDigestBytes:ve.data.bytes}:{},...we?{draftBaseMissing:we}:{},openNotes:O,openDefects:j,...F?{unverifiedReview:{reason:F.reason}}:{},laterLaps:de,interruptedBurn:ot}),lt=Mg(et.sessions),ut=lt?.kind===`chat`?lt:void 0,dt=Be.isPending||Oe.isPending||ke.isPending||Ae.isPending||je.isPending||Fe.isPending||Le.isPending||Re.isPending||Ne.isPending||Pe.isPending||Ie.isPending||ze.isPending||Me.isPending||Ve.pending,ft=()=>{(O??0)+(j??0)>0?oe(Date.now()):Oe.mutate({featureId:e,kind:`chat`})},pt=async()=>{if(!lt)return!0;try{await Me.mutateAsync({sessionId:lt.id})}catch{return!1}return De(),!0},mt=async t=>{let{dismissFindingIds:n,...r}=t;try{for(let e of n)await Pe.mutateAsync({findingId:e});await Ne.mutateAsync({featureId:e,...r}),oe(null),De(),h.notes.list.invalidate({featureId:e}),h.findings.listByFeature.invalidate({featureId:e}),t.carry?await pt()&&Oe.mutate({featureId:e,kind:`chat`}):ke.mutate({featureId:e})}catch(e){g.push(e instanceof Error?e.message:String(e))}},ht=()=>{Oe.mutate({featureId:e,kind:`chat`})},gt=()=>{!c&&!ut&&ht(),c||Je(!1),l()},_t=(t,n)=>{switch(t){case`startDraft`:Be.mutate({featureId:e,baseBranch:Ce});break;case`chat`:gt();break;case`iterate`:ft();break;case`endSessionAndIterate`:pt().then(e=>{e&&ft()});break;case`converge`:case`resumeConverge`:Ae.mutate({featureId:e});break;case`workNext`:n&&je.mutate({featureId:e,waypointId:n});break;case`burn`:I(!0);break;case`cancelRun`:at&&Fe.mutate({runId:at.id});break;case`unarchive`:ze.mutate({featureId:e});break;case`testDriveStart`:Le.mutate({featureId:e,action:`start`},{onSuccess:t=>{De(),t.ok&&t.branch?d({featureId:e,branch:t.branch}):t.ok||g.push(t.deniedReason??`test drive denied`)}});break;case`testDriveStop`:Le.mutate({featureId:e,action:`stop`},{onSuccess:()=>{De(),d(null)}});break;case`stopDriveAndIterate`:Le.mutate({featureId:e,action:`stop`},{onSuccess:()=>{De(),d(null),ft()}});break;case`fixDrive`:Ie.mutate({featureId:e});break;case`merge`:te(!0);break;case`resolveConflict`:b&&Ve.resolve(b,lt?.id);break;default:}},vt=()=>{ke.mutate({featureId:e},{onSuccess:()=>I(!1)})},yt=()=>{Re.mutate({featureId:e},{onSuccess:e=>{if(De(),te(!1),e.ok)d(null),g.push(`merged — feature shipped`,`success`);else if(e.conflict){let t=e.files.length;g.push(t>0?`merge conflict in ${t} file${t===1?``:`s`} — resolve below and retry`:`merge conflict — resolve below and retry`)}}})},bt=st===`building`&&!at,xt=!ye&&et.tickets.length>0&&!bt,St=xt&&He?.featureId===e?He.view:`overview`,Ct=t=>Ue({featureId:e,view:t}),wt=e=>{Ct(`overview`),n(e)},Tt=Gg(et.tickets,tt.lap),Et=St===`overview`&&!ye&&st===`planning`&&!rt,Dt=!ye&&st!==`shipped`,Ot=`${e}:${ye?`draft`:st}:${St}`,kt=c?`chat`:qe?`details`:null,At=()=>{if(kt===`details`)return Je(!1);c&&l(),Je(!0)},jt=tt.status===`shipped`?Yv([...y]):null,Mt=[ye?{phase:`draft`,text:`Parked ${ph(tt.createdAt)}`}:jt?{tone:`success`,text:`Merged ${ph(jt)}`}:{text:`Started ${ph(tt.createdAt)}`},Tt.total>0&&st===`planning`&&{text:Kg(Tt)},tt.status===`archived`&&{tone:`neutral`,text:`Archived`},tt.lap>1&&{text:`Lap ${tt.lap}`,title:F_(tt.lap)}].filter(e=>!!e),Nt=[{key:`copy-link`,label:`Copy link`,onSelect:()=>NP(window.location.origin+Vh({kind:`feature`,projectId:tt.projectId,featureSlug:tt.slug}),g)},...!ye&&tt.branch?[{key:`copy-branch`,label:`Copy branch name`,onSelect:()=>NP(tt.branch,g)}]:[],...tt.status===`archived`?[{key:`unarchive`,label:`Unarchive`,onSelect:()=>ze.mutate({featureId:e})}]:tt.status===`draft`?[]:[{key:`archive`,label:`Archive`,onSelect:()=>Ze.mutate({featureId:e})}],...f&&tt.status!==`shipped`?[{key:`delete`,label:`Delete…`,danger:!0,onSelect:e=>Xe(e)}]:[]],Pt=rt?(0,R.jsx)(D6,{phase:nt,livePhase:tt.phase,facts:ty({phase:nt,full:et,events:y,decisions:Ee}),onBack:()=>wt(null)}):(0,R.jsx)(E6,{ns:ct,guidance:r,busy:dt,onAction:_t,hideChat:!0,...st===`planning`||st===`building`?{demote:[`merge`]}:{},draftBranch:ye?{branches:be.data?.branches,value:Ce||null,detected:be.data?.detected,missing:we===`unpicked`,onPick:t=>Se({featureId:e,base:t})}:void 0}),Ft=(0,R.jsxs)(S6,{feature:tt,isDraft:ye,steps:it,readonly:rt,facts:Mt,onViewPhase:wt,children:[v.message&&(0,R.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md bg-danger-subtle px-3 py-2 text-sm text-danger`,role:`alert`,children:[(0,R.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:`Resume failed.`}),` `,v.message]}),(0,R.jsx)(nE,{label:`Dismiss`,size:`sm`,icon:(0,R.jsx)(xy,{}),onClick:v.dismiss})]}),Pt]}),It=St===`tickets`?(0,R.jsx)(IA,{title:`Tickets`,children:(0,R.jsx)(S2,{full:et})}):ye?(0,R.jsx)(FG,{full:et}):(0,R.jsx)(P6,{effective:st,full:et,events:y,driving:u,conflict:b,runId:at?.id??null,readonly:rt,chatDocked:c,mapRailCollapsed:i,onToggleMapRail:a,onViewPhase:wt,artifactPaneCollapsed:o,onToggleArtifactPane:s});return(0,R.jsxs)(`section`,{className:q(k6,`overflow-clip`),"aria-label":tt.title,children:[(0,R.jsxs)(RA,{asideClassName:`@max-4xl:top-(--topbar-h)`,aside:kt===null?null:kt===`chat`?(0,R.jsx)(m6,{featureId:e,sessions:et.sessions,busy:Oe.isPending,onOpenChat:ht,onCollapse:l}):(0,R.jsx)(f6,{featureId:e,onClose:()=>Je(!1)}),children:[(0,R.jsx)(MA,{crumbs:[{label:tt.title,icon:(0,R.jsx)(xb,{phase:ye?`draft`:tt.phase,size:14,label:``})}],tabs:xt?(0,R.jsx)(CA,{label:`Feature views`,size:`sm`,value:St,onChange:Ct,items:[{id:`overview`,label:`Overview`,icon:(0,R.jsx)(Qy,{})},{id:`tickets`,label:`Tickets`,icon:(0,R.jsx)(Ny,{}),...Tt.total>0?{count:Tt.total}:{}}]}):void 0,actions:(0,R.jsxs)(R.Fragment,{children:[$e&&(0,R.jsx)(rA,{tone:`warning`,className:`mr-2`,title:`The server is unreachable — retrying`,children:`Offline, retrying`}),!ye&&(0,R.jsxs)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(Oy,{}),"aria-pressed":kt===`chat`,onClick:gt,disabled:Oe.isPending,children:[`Chat`,ut&&(0,R.jsx)(tA,{tone:`live`,label:`Chat session live`})]}),(0,R.jsx)(IP,{actions:Nt,size:`md`}),(0,R.jsx)(nE,{label:kt===`details`?`Hide details`:`Show details`,icon:(0,R.jsx)(hy,{}),active:kt===`details`,onClick:At})]})}),Et?(0,R.jsxs)(`div`,{className:`mx-auto flex min-h-0 w-full max-w-(--content-wide) min-w-0 flex-1 flex-col px-8 pt-12 animate-rise-in`,children:[(0,R.jsx)(`div`,{className:`shrink-0 pb-5`,children:Ft}),(0,R.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 pb-6`,children:It})]},Ot):(0,R.jsxs)(PA,{width:Dt?`wide`:`default`,routeKey:Ot,children:[Ft,(0,R.jsx)(`div`,{className:`mt-10`,children:It})]})]}),ne&&(0,R.jsx)(xF,{title:tt.title,branch:tt.branch,summary:Uv({branch:tt.branch,pendingTickets:Ug(et.tickets),lap:Vv(et.runs),...ge?{defaultModel:ge}:{},warnings:ie.data}),busy:ke.isPending,warningsPending:!ie.data,onConfirm:vt,onCancel:()=>I(!1)}),ee&&(0,R.jsx)(vF,{title:tt.title,branch:tt.branch,base:C.data?.base,summary:Bv({branch:tt.branch,...C.data?.base?{base:C.data.base}:{},...C.data?{delta:C.data}:{},tickets:et.tickets,lap:tt.lap,driveTaken:x,openNotes:O,...me.data?.projectDrive&&me.data.projectId===tt.projectId?{projectDrive:{holderLabel:me.data.holderLabel}}:{},freshness:P,conflict:b,laterLaps:de,burning:at?.status===`running`}),busy:Re.isPending,resolving:Ve.pending,onConfirm:yt,onResolve:b?()=>void Ve.resolve(b,lt?.id??void 0):void 0,onCancel:()=>te(!1)}),Ye&&(0,R.jsx)(LP,{title:tt.title,slug:tt.slug,busy:Qe.isPending,onConfirm:()=>Qe.mutate({featureId:e}),onCancel:()=>Xe(null),returnFocusRef:Ye}),ae!==null&&(0,R.jsx)(BF,{lap:tt.lap,notes:D,defects:A,standing:se.data?.standingFixTickets??[],openedAt:ae,busy:dt,readonly:rt,sessionLive:!!lt,onCommit:e=>void mt(e),onClose:()=>oe(null)})]})}function P6({effective:e,full:t,events:n,driving:r,conflict:i,runId:a,readonly:o,chatDocked:s,mapRailCollapsed:c,onToggleMapRail:l,onViewPhase:u,artifactPaneCollapsed:d,onToggleArtifactPane:f}){if(o&&e===`planning`)return(0,R.jsx)(x2,{full:t,effective:e,events:n,mapRailCollapsed:c,onToggleMapRail:l});switch(e){case`planning`:return(0,R.jsx)(L1,{full:t,effective:e,chatDocked:s,mapRailCollapsed:c,onToggleMapRail:l,artifactPaneCollapsed:d,onToggleArtifactPane:f});case`building`:return a?(0,R.jsx)(n6,{featureId:t.feature.id,runId:a,readonly:o,chatDocked:s}):(0,R.jsx)(_3,{featureId:t.feature.id,chatDocked:s});case`review`:return(0,R.jsx)(Q4,{full:t,driving:r,conflict:i,readonly:o,onViewPhase:u});case`shipped`:return(0,R.jsx)(m3,{full:t,chatDocked:s})}}function F6(e){let t=B.useUtils(),n=Ab(),r=B.project.sessionBranch.useQuery({projectId:e}),i=B.project.branches.useQuery({projectId:e,includeFeatureBranches:!0}),a=iy(r.data,i.data?.branches),o=B.settings.update.useMutation({onSuccess:()=>{t.project.sessionBranch.invalidate(),t.settings.get.invalidate()},onError:e=>n.push(e.message)});return{value:a?.value??null,branches:i.data?.branches,detected:r.data?.detected,missing:a?.origin===`vanished`,pick:t=>o.mutate({projectId:e,key:`sessionBranch`,value:t}),picking:o.isPending}}var I6=10,L6=8;function R6({conversations:e,pending:t,busy:n,onResume:r,onOpen:i,onView:a}){let[o,s]=(0,L.useState)(``),[c,l]=(0,L.useState)(!1),u=(0,L.useMemo)(()=>[...e].sort((e,t)=>Number(t.status!==`ended`)-Number(e.status!==`ended`)).map(e=>({c:e,title:i3(e.title)})),[e]);if(t)return null;let d=o.trim().toLowerCase(),f=d?u.filter(e=>e.title.toLowerCase().includes(d)):u,p=c||d?f:f.slice(0,I6),m=f.length-p.length;return(0,R.jsxs)(IA,{title:`Chats`,action:e.length>L6?(0,R.jsx)(DA,{icon:(0,R.jsx)(py,{}),placeholder:`Filter`,"aria-label":`Filter chats`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Escape`&&s(``)},className:`w-50`}):void 0,children:[e.length===0?(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(Oy,{}),title:`No chats yet`,hint:`A new chat starts from the row above.`}):p.length===0?(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(py,{}),title:`No chat matches`,hint:`Nothing titled “${o.trim()}”.`}):(0,R.jsx)(yA,{label:`Chats`,children:p.map(({c:e,title:t},o)=>{let s=e.status!==`ended`;return(0,R.jsx)(vA,{index:o,leading:s?(0,R.jsx)(tA,{tone:`live`,label:e.status}):(0,R.jsx)(Oy,{}),title:t,meta:e.createdAt===null?void 0:fh(e.createdAt),onClick:()=>a(e),actionsOverlay:!0,actions:(0,R.jsx)(nE,{size:`sm`,label:e.resumable?s?`Open`:`Reopen`:`Reopen — this one never got started`,"aria-label":s?`Open`:`Reopen`,icon:s?(0,R.jsx)(Iy,{}):(0,R.jsx)(ab,{}),disabled:n||!e.resumable,onClick:()=>s?i?.(e.id):r(e.id)})},e.id)})}),m>0&&(0,R.jsxs)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(wy,{}),className:`mt-2`,onClick:()=>l(!0),children:[`Show `,m,` more`]})]})}function z6({icon:e,title:t,status:n,hint:r,actions:i,caption:a,children:o,rule:s=!0,className:c}){return(0,R.jsxs)(`div`,{className:q(`py-4`,s&&`border-b border-border-subtle`,c),children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-3`,children:[(0,R.jsx)(`span`,{"aria-hidden":!0,className:`grid size-8 shrink-0 place-items-center rounded-md bg-surface-hover text-icon [&>svg]:size-4`,children:e}),(0,R.jsxs)(`div`,{className:`flex min-w-60 flex-1 flex-col`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,R.jsx)(`h2`,{className:`m-0 text-sm font-medium text-text`,children:t}),n]}),(0,R.jsx)(`p`,{className:`m-0 text-sm text-pretty text-text-tertiary`,children:r})]}),(0,R.jsxs)(`div`,{className:`ml-auto flex shrink-0 flex-col items-end gap-1`,children:[(0,R.jsx)(`div`,{className:`flex items-center gap-2`,children:i}),a&&(0,R.jsx)(`span`,{className:`max-w-[32ch] text-right text-xs text-text-tertiary`,children:a})]})]}),o]})}function B6({landing:e,onStart:t,starting:n,openSession:r}){return(0,R.jsx)(z6,{icon:(0,R.jsx)(By,{}),title:`Talk it through`,hint:`Bring a raw idea; the chat checks it against what’s built and cuts it into features.`,actions:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(ij,{prefix:`landing on`,value:e.value,branches:e.branches,detected:e.detected,missing:e.missing,disabled:e.picking,onPick:e.pick}),(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(yy,{}),loading:n,disabled:n||e.missing,title:e.missing?`the branch this chat would land on is gone — pick another`:void 0,onClick:t,children:`New chat`})]}),caption:e.missing?`The landing branch is gone — pick another.`:void 0,children:r&&(0,R.jsxs)(`div`,{role:`status`,className:`mt-3 ml-12 flex flex-wrap items-center gap-2 animate-rise-in`,children:[(0,R.jsx)(`span`,{className:`mr-auto text-sm text-text-secondary`,children:`A chat is already open.`}),(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(Oy,{}),onClick:r.onOpen,children:`Open it`}),(0,R.jsx)(Y,{size:`sm`,icon:(0,R.jsx)(ab,{}),loading:n,disabled:n,onClick:r.onReplace,children:`End it and start new`})]})})}function V6({lead:e,when:t,actions:n,className:r,children:i}){return(0,R.jsx)(vA,{as:`li`,animate:!0,wrap:!0,leading:e,title:(0,R.jsx)(`span`,{className:`flex flex-col`,children:i}),meta:t,actions:n,actionsOverlay:!0,className:q(`focus-within:bg-surface-hover hover:bg-surface-hover`,r)})}function H6(){return(0,R.jsx)(`span`,{className:`grid w-10 place-items-center`,"aria-hidden":!0,children:(0,R.jsx)(`i`,{className:`size-1.5 rounded-full bg-text-disabled`})})}function U6({note:e}){let t=Lb(e);return t?(0,R.jsx)(`span`,{className:`mt-0.5 font-mono text-xs text-text-tertiary`,title:t.title,children:t.label}):null}function W6({projectId:e,onTriage:t,triaging:n,reveal:r=!1,onRevealed:i}){let a=B.useUtils(),o=Ab(),s=B.projectNotes.list.useQuery({projectId:e},{refetchInterval:eh()}),c=B.feature.list.useQuery({projectId:e},{refetchInterval:eh()}),[l,u]=(0,L.useState)(null),[d,f]=(0,L.useState)(``),[p,m]=(0,L.useState)(null),h=e=>o.push(e.message),g=()=>void a.projectNotes.invalidate(),_=B.projectNotes.edit.useMutation({onSuccess:()=>{g(),u(null)},onError:h}),v=B.projectNotes.delete.useMutation({onSuccess:g,onError:h}),y=B.projectNotes.dismiss.useMutation({onSuccess:g,onError:h}),b=B.projectNotes.reopen.useMutation({onSuccess:g,onError:h}),x=s.data??[],S=_.isPending||v.isPending||y.isPending||b.isPending,C=K6(x.filter(e=>e.status===`open`)),w=K6(x.filter(e=>e.status===`triaged`)),T=(0,L.useRef)(null),E=x.length>0;if((0,L.useEffect)(()=>{!r||!T.current||(T.current.scrollIntoView?.({block:`center`}),i?.())},[r,E,i]),!E)return null;let D=e=>{d.trim()&&!_.isPending&&_.mutate({noteId:e,text:d})},O=e=>e.screenshotUrl?(0,R.jsx)(cj,{size:`sm`,url:e.screenshotUrl,onOpen:m}):(0,R.jsx)(H6,{});return(0,R.jsxs)(`section`,{ref:T,"aria-label":`Notes`,className:`flex flex-col`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3 px-4 pt-3 pb-2`,children:[(0,R.jsx)(`span`,{className:`min-w-0 flex-1 text-xs text-pretty text-text-tertiary`,children:`Grouped, questioned and routed in a triage chat.`}),(0,R.jsx)(Y,{size:`sm`,icon:(0,R.jsx)(By,{}),className:`shrink-0`,loading:n,disabled:C.length===0||n,title:C.length===0?`nothing is open to triage`:void 0,onClick:t,children:`Triage ${C.length}`})]}),C.length===0?(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(Uy,{}),title:`Inbox clear`,hint:`Every note has been triaged.`}):(0,R.jsx)(`ul`,{className:G6,children:C.map(e=>(0,R.jsx)(V6,{lead:O(e),when:fh(e.createdAt),actions:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(nE,{size:`sm`,label:`Edit`,icon:(0,R.jsx)(Ay,{}),onClick:()=>{u(e.id),f(e.text)}}),(0,R.jsx)(nE,{size:`sm`,label:`Dismiss`,icon:(0,R.jsx)(by,{}),disabled:S,onClick:()=>y.mutate({noteId:e.id})}),(0,R.jsx)(nE,{size:`sm`,label:`Delete`,icon:(0,R.jsx)(Sy,{}),variant:`danger-ghost`,disabled:S,onClick:()=>v.mutate({noteId:e.id})})]}),children:l===e.id?(0,R.jsx)(`input`,{"aria-label":`edit this note`,className:wA,value:d,autoFocus:!0,onChange:e=>f(e.target.value),onKeyDown:t=>{t.key===`Escape`?(t.preventDefault(),u(null)):t.key===`Enter`&&(t.preventDefault(),D(e.id))}}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-text`,children:e.text}),(0,R.jsx)(U6,{note:e})]})},e.id))}),w.length>0&&(0,R.jsx)(JA,{title:`${w.length} triaged`,className:`mx-4 mt-2`,children:(0,R.jsx)(`ul`,{className:`m-0 flex list-none flex-col p-0`,children:w.map(t=>(0,R.jsxs)(V6,{lead:t.screenshotUrl?O(t):null,actions:(0,R.jsx)(nE,{size:`sm`,label:`Reopen`,icon:(0,R.jsx)(Cy,{}),disabled:S,onClick:()=>b.mutate({noteId:t.id})}),children:[(0,R.jsx)(`span`,{className:`text-text-secondary`,children:t.text}),(0,R.jsx)(U6,{note:t}),(0,R.jsxs)(`span`,{className:`mt-0.5 flex flex-wrap items-baseline gap-x-2 text-xs text-text-tertiary`,children:[(0,R.jsx)(`span`,{children:t.outcome}),(0,R.jsx)(q6,{projectId:e,feature:c.data?.find(e=>e.id===t.featureId)})]})]},t.id))})}),(0,R.jsx)(CF,{url:p,onClose:()=>m(null)})]})}var G6=`m-0 flex list-none flex-col px-1 py-1`;function K6(e){return[...e].sort((e,t)=>t.createdAt-e.createdAt)}function q6({projectId:e,feature:t}){return t?(0,R.jsx)(`a`,{className:sE,href:Vh({kind:`feature`,projectId:e,featureSlug:t.slug}),children:t.title}):null}function J6({conversation:e,projectName:t=`Project`,onBack:n,onReopen:r,reopening:i,children:a}){let o=i3(e.title),s=e.status!==`ended`;return(0,R.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,R.jsx)(MA,{crumbs:[{label:t,icon:(0,R.jsx)(My,{}),onClick:n},{label:o,icon:(0,R.jsx)(Oy,{})}],actions:(0,R.jsx)(Y,{icon:s?(0,R.jsx)(Iy,{}):(0,R.jsx)(ab,{}),loading:i,disabled:i||!e.resumable,title:e.resumable?void 0:`this one never got started`,onClick:r,children:s?`Open`:`Reopen`})}),(0,R.jsxs)(PA,{routeKey:`transcript-${e.id}`,children:[(0,R.jsx)(FA,{title:o,meta:[e.createdAt!==null&&{icon:(0,R.jsx)(eb,{}),text:`Started ${ph(e.createdAt)}`},s&&{tone:`live`,text:`Open now`}]}),(0,R.jsx)(`div`,{className:`mt-8`,children:a})]})]})}function Y6({session:e,title:t,projectName:n=`Project`,branch:r,hidden:i,onBack:a,endControl:o,switcher:s,children:c}){let l=a3(jg(e)),u=e.status===`live`?`live`:e.status===`launching`?`accent`:`neutral`,d=e.ccSessionId??e.id;return(0,R.jsxs)(`div`,{className:i?`hidden`:`flex min-h-0 flex-1 flex-col`,"data-live-chat":!0,"aria-hidden":i,children:[(0,R.jsx)(MA,{crumbs:[{label:n,icon:(0,R.jsx)(My,{}),onClick:a},{label:i3(t),icon:(0,R.jsx)(Oy,{})}],tabs:s,actions:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`mr-2 hidden min-w-0 items-center gap-4 text-xs whitespace-nowrap text-text-tertiary md:flex`,children:[(0,R.jsx)(rA,{tone:u,children:l}),r&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,R.jsx)(Iy,{size:14,className:`text-icon`}),`lands on `,(0,R.jsx)(`span`,{className:`font-mono`,children:r})]}),(0,R.jsx)(`span`,{className:`hidden font-mono xl:inline`,title:d,children:d.slice(0,8)})]}),o]})}),(0,R.jsx)(`div`,{className:`min-h-0 flex-1 bg-surface-inset animate-fade-in`,children:c})]})}function X6({projectId:e,startedAt:t,onClose:n}){let r=B.projectNotes.list.useQuery({projectId:e},{refetchInterval:eh()}),[i,a]=(0,L.useState)(null),{thisDrive:o,alreadyOpen:s}=Ib(r.data??[],t),c=o.length+s.length;return(0,R.jsxs)(LA,{title:`Notes`,actions:c>0?(0,R.jsxs)(`span`,{className:`pr-1 text-xs text-text-tertiary tabular-nums`,title:`${c} open`,children:[c,` open`]}):void 0,onClose:n,bodyClassName:`flex flex-col`,children:[(0,R.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,R.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto pb-2`,children:[(0,R.jsx)(Z6,{title:`This drive`,children:o.length===0?(0,R.jsx)(Q6,{children:`Nothing yet. Select an area of the app, or type below.`}):o.map(e=>(0,R.jsx)($6,{note:e,onOpen:a},e.id))}),(0,R.jsx)(Z6,{title:`Already open`,children:s.length===0?(0,R.jsx)(Q6,{children:`No other open notes.`}):s.map(e=>(0,R.jsx)($6,{note:e,onOpen:a},e.id))})]}),(0,R.jsx)(e8,{projectId:e})]}),(0,R.jsx)(CF,{url:i,onClose:()=>a(null)})]})}function Z6({title:e,children:t}){return(0,R.jsxs)(`section`,{"aria-label":e,className:`pt-2`,children:[(0,R.jsx)(mA,{className:`px-4`,children:e}),(0,R.jsx)(`ul`,{className:`m-0 flex list-none flex-col px-1 py-0`,children:t})]})}function Q6({children:e}){return(0,R.jsx)(`li`,{className:`px-3 py-1.5 text-sm text-text-tertiary`,children:e})}function $6({note:e,onOpen:t}){return(0,R.jsxs)(V6,{lead:e.screenshotUrl?(0,R.jsx)(cj,{size:`sm`,url:e.screenshotUrl,onOpen:t}):(0,R.jsx)(H6,{}),when:fh(e.createdAt),children:[(0,R.jsx)(`span`,{className:`text-text`,children:e.text}),(0,R.jsx)(U6,{note:e})]})}function e8({projectId:e}){let t=B.useUtils(),n=Ab(),r=B.projectNotes.add.useMutation(),[i,a]=(0,L.useState)(``),[o,s]=(0,L.useState)(null),[c,l]=(0,L.useState)(!1),u=(0,L.useRef)(null);(0,L.useEffect)(()=>()=>URL.revokeObjectURL(o?.preview??``),[o]);let d=e=>{let t=Wm(e.clipboardData);t&&(e.preventDefault(),Gm(t).then(e=>s({png:e,preview:URL.createObjectURL(e)})).catch(e=>n.push(e instanceof Error?e.message:`that image could not be read`)))},f=async()=>{if(!(!i.trim()||c)){l(!0);try{let c=await r.mutateAsync({projectId:e,text:i});if(o)try{await Mb(c.id,o.png)}catch(e){n.push(`the note was saved, but its picture was not: ${e instanceof Error?e.message:String(e)}`)}t.projectNotes.invalidate(),a(``),s(null),u.current?.focus()}catch(e){n.push(e instanceof Error?e.message:`the note could not be saved`)}finally{l(!1)}}};return(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-border-subtle p-3`,onPaste:d,children:[(0,R.jsx)(DA,{ref:u,autoComplete:`off`,"aria-label":`New note`,placeholder:`What did you just notice?`,value:i,disabled:c,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f())}}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-text-tertiary`,children:[o?(0,R.jsxs)(`span`,{className:`inline-flex h-6 items-center gap-1.5 rounded-md bg-surface-hover pr-0.5 pl-1 text-text-secondary animate-pop-in`,children:[(0,R.jsx)(`img`,{src:o.preview,alt:`the picture this note will carry`,className:`h-4 w-6 rounded-sm bg-surface-inset object-cover`}),`Screenshot`,(0,R.jsx)(nE,{size:`sm`,label:`Remove the picture`,icon:(0,R.jsx)(xy,{}),onClick:()=>s(null)})]}):(0,R.jsx)(`span`,{children:`Paste a screenshot`}),(0,R.jsxs)(`span`,{className:`ml-auto flex items-center gap-1`,children:[(0,R.jsx)(Gb,{children:`↵`}),` save`]}),(0,R.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(Gb,{children:wj(`J`)}),` anywhere`]})]})]})}function t8({projectId:e,projectName:t=`Project`,repoPath:n,drive:r,hidden:i,onProjectPage:a,onStop:o,stopping:s,onOpenPreparation:c,switcher:l}){let[u,d]=(0,L.useState)(!0),f=Y_(r.state).stageKind,p=f===`failed`?(0,R.jsx)(rA,{tone:`danger`,children:`Setup failed`}):f===`starting`?(0,R.jsx)(rA,{spinning:!0,children:`Starting`}):(0,R.jsx)(rA,{tone:`live`,children:`Running`}),m=(0,R.jsx)(Y,{icon:(0,R.jsx)(Ry,{}),loading:s,disabled:s,onClick:o,children:`Stop drive`}),h=`${n??``}${r.commit?` @ ${r.commit}`:``}`;return(0,R.jsxs)(`div`,{className:i?`hidden`:`flex min-h-0 flex-1 flex-col`,"aria-hidden":i,"data-project-drive":!0,children:[(0,R.jsx)(MA,{crumbs:[{label:t,icon:(0,R.jsx)(My,{}),onClick:a},{label:`Test drive`,icon:(0,R.jsx)(Ly,{})}],tabs:l,actions:(0,R.jsxs)(R.Fragment,{children:[m,(0,R.jsx)(nE,{label:u?`Hide notes`:`Show notes`,icon:(0,R.jsx)(hy,{}),active:u,onClick:()=>d(e=>!e)})]})}),(0,R.jsx)(RA,{aside:u&&(0,R.jsx)(X6,{projectId:e,startedAt:r.startedAt,onClose:()=>d(!1)}),children:(0,R.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col gap-4 overflow-y-auto px-6 pt-5 pb-4 animate-fade-in`,children:[(0,R.jsxs)(`header`,{className:`flex flex-col gap-1.5`,children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,R.jsxs)(`h2`,{className:`m-0 text-lg font-semibold text-text`,children:[`Driving `,(0,R.jsx)(`span`,{className:`font-mono text-base font-medium`,children:r.branch})]}),p]}),(0,R.jsx)(xA,{items:[{icon:(0,R.jsx)(My,{}),mono:!0,text:h,title:h},{icon:(0,R.jsx)(ob,{}),mono:!0,text:`project-drive`,title:`the identity this drive runs as`}]})]}),(0,R.jsx)(n8,{projectId:e,drive:r,stop:m,onOpenPreparation:c}),(0,R.jsx)(W2,{branch:r.branch,drive:r})]})})]})}function n8({projectId:e,drive:t,stop:n,onOpenPreparation:r}){let i=W_(t);switch(Y_(t.state).stageKind){case`failed`:return i?(0,R.jsx)(i8,{children:(0,R.jsx)(U2,{failure:i,explanation:(0,R.jsxs)(R.Fragment,{children:[`Your checkout is as it was, but`,` `,(0,R.jsx)(`code`,{className:`font-mono text-xs`,children:i.command}),` `,i.outcome,` — so whatever it was meant to bring up is probably not running. Preparation is where this project’s drive commands are repaired and proven.`]}),children:(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(zy,{}),onClick:r,children:`Open preparation`}),n]})})}):(0,R.jsx)(i8,{children:(0,R.jsx)(GA,{icon:(0,R.jsx)(tb,{}),title:`The drive’s setup command failed`,hint:`Its output is in the timeline.`})});case`bare`:return(0,R.jsx)(i8,{children:(0,R.jsx)(GA,{icon:(0,R.jsx)(Dy,{}),title:`Setup ran — nothing started.`,hint:(0,R.jsxs)(R.Fragment,{children:[`This project has no dev command ·`,` `,(0,R.jsx)(p2,{location:{page:`project`,field:`devCommand`},children:`Set one in Settings`}),` `,`and the next drive boots the app right here.`]})})});case`panel`:case`agent`:return t.devUrl?(0,R.jsx)(`div`,{className:`flex min-h-100 flex-1 flex-col`,children:(0,R.jsx)(S4,{projectId:e,url:t.devUrl})}):(0,R.jsx)(i8,{children:(0,R.jsx)(GA,{icon:(0,R.jsx)(eb,{}),title:`Waiting for an address`,hint:`The dev server is up but has not printed an address yet — its output is under the stage.`})});default:return(0,R.jsx)(i8,{children:(0,R.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-center`,children:[(0,R.jsx)(rA,{tone:`live`,size:`sm`,strong:!0,children:`Starting the dev server…`}),(0,R.jsx)(`p`,{className:`m-0 max-w-[52ch] text-sm text-pretty text-text-tertiary`,children:`Your checkout is driven as it is and the project’s dev command is running. The app appears here as soon as it answers — its output is under the stage.`})]})})}}function r8({value:e,chat:t,drive:n,onPick:r}){return(0,R.jsx)(CA,{label:`Project views`,size:`sm`,value:e,onChange:r,items:[{id:`overview`,label:`Overview`,icon:(0,R.jsx)(My,{})},...t?[{id:`chat`,label:`Live chat`,icon:(0,R.jsx)(Oy,{})}]:[],...n?[{id:`drive`,label:`Drive`,icon:(0,R.jsx)(Ly,{})}]:[]]})}function i8({children:e}){return(0,R.jsx)(`div`,{className:`flex min-h-65 flex-1 flex-col justify-center rounded-md bg-surface-inset p-6`,children:e})}var a8=`project-drive`;function o8({card:e,branch:t,setupCommand:n,devCommand:r,stopCommand:i,starting:a,onStart:o,onPrepare:s,onReturn:c}){if(e.state===`hidden`)return null;let l=e.state===`running`,u=[{label:`Branch`,value:t??`…`,mono:!0,sub:`your checkout, as it is — no branch switch`},{label:`As`,value:a8,mono:!0},s8(`Setup`,n,`driveSetupCommand`),s8(`Dev`,r,`devCommand`),s8(`Stop`,i,`driveStopCommand`)];return(0,R.jsxs)(`section`,{"aria-label":`Test drive`,children:[(0,R.jsx)(z6,{icon:(0,R.jsx)(Ly,{}),title:`Test drive`,status:l?(0,R.jsx)(rA,{tone:`live`,children:`Running`}):void 0,hint:`Run everything that has shipped and jot what you notice. Notes land in the inbox.`,actions:e.state===`prepare`?(0,R.jsx)(Y,{icon:(0,R.jsx)(zy,{}),onClick:s,children:`Prepare drive`}):l?(0,R.jsx)(Y,{icon:(0,R.jsx)(Iy,{}),onClick:c,children:`Return to drive`}):(0,R.jsx)(Y,{icon:(0,R.jsx)(Ly,{}),loading:a,disabled:e.state===`blocked`||a,title:e.state===`blocked`?e.reason:void 0,onClick:o,children:`Test drive`}),caption:e.state===`blocked`?e.reason:e.state===`prepare`?`No setup or dev command yet.`:void 0,rule:!1}),(0,R.jsx)(JA,{title:`Drive setup`,icon:(0,R.jsx)(Dy,{}),aside:(0,R.jsxs)(`span`,{className:`font-mono`,children:[a8,` · `,t??`…`]}),children:(0,R.jsx)(`div`,{className:`rounded-md border border-border-subtle bg-surface-inset px-4 py-3`,children:(0,R.jsx)(bA,{items:u,className:`gap-x-8`})})})]})}function s8(e,t,n){return t?.trim()?{label:e,value:t,mono:!0}:{label:e,value:(0,R.jsxs)(`span`,{className:`font-normal text-text-tertiary`,children:[`Nothing set ·`,` `,(0,R.jsx)(p2,{location:{page:`project`,field:n},children:`Settings`})]})}}function c8(e){let t=B.useUtils(),n=Ab(),r=B.feature.driveInfo.useQuery(void 0,{refetchInterval:eh()}),i=B.project.testDrive.useMutation({onSuccess:()=>void t.feature.driveInfo.invalidate(),onError:e=>n.push(e.message)}),a=r.data??null,o=(t,r)=>i.mutate({projectId:e,action:t},{onSuccess:e=>{e.ok?r?.():n.push(e.deniedReason??`the drive could not ${t}`)}});return{slot:a,drive:Pb(a,e)?a:null,start:e=>o(`start`,e),stop:e=>o(`stop`,e),starting:i.isPending&&i.variables?.action===`start`,stopping:i.isPending&&i.variables?.action===`stop`}}function l8({projectId:e,talk:t,newChatRequest:n=0,onConsumeNewChatRequest:r,inboxRequest:i=0,onConsumeInboxRequest:a,empty:o=!1,onOpenPreparation:s,driveRequest:c=0,onConsumeDriveRequest:l}){let u=B.useUtils(),d=B.project.list.useQuery().data?.find(t=>t.id===e),f=F6(e),p=B.project.branches.useQuery({projectId:e,includeFeatureBranches:!0}),m=c8(e),h=m.drive,g=t.session,[_,v]=(0,L.useState)(null),y=B.projectNotes.list.useQuery({projectId:e},{refetchInterval:eh()}),[b,x]=(0,L.useState)(null),[S,C]=(0,L.useState)(!!(g&&n>0)),[w,T]=(0,L.useState)(`chat`),[E,D]=(0,L.useState)(!!(g&&n>0)),[O,k]=(0,L.useState)(void 0);(0,L.useEffect)(()=>{n>0&&g&&(C(!0),D(!0),k(void 0),r?.())},[n,r,g]),(0,L.useEffect)(()=>{i>0&&(v(null),C(!0),x(!0))},[i]),(0,L.useEffect)(()=>{g||(D(!1),k(void 0))},[g]);let A=g?.id;(0,L.useEffect)(()=>{A&&T(`chat`)},[A]);let j=()=>{v(null),C(!1),T(`drive`)},M=()=>{C(!1),T(`chat`)},N=()=>{T(`chat`),g&&C(!0)};(0,L.useEffect)(()=>{c>0&&(j(),l?.())},[c,l]);let P=_,F=P!==null||S||!g&&!(h&&w===`drive`),ee=!!h&&!F&&(w===`drive`||!g),te=!!g&&!F&&!ee,ne=g||h?(0,R.jsx)(r8,{value:ee?`drive`:te?`chat`:`overview`,chat:!!g,drive:!!h,onPick:e=>{e===`overview`?(v(null),N()):e===`chat`?(v(null),M()):j()}}):void 0,I=e=>{t.resume(e),v(null),M()},re=d?.name??`This project`,ie=(y.data??[]).filter(e=>e.status===`open`).length,ae=(y.data??[]).length>0,oe=ae&&(b??ie>0);return(0,R.jsxs)(`section`,{className:`flex h-full min-h-0 min-w-0 flex-1 flex-col`,children:[(0,R.jsx)(`div`,{className:F?`flex min-h-0 flex-1 flex-col`:`hidden`,hidden:!F,children:P?(0,R.jsx)(J6,{conversation:P,projectName:re,onBack:()=>v(null),onReopen:()=>{P.status===`ended`?I(P.id):(v(null),M())},reopening:t.starting,children:(0,R.jsx)(d3,{sessionId:P.id})}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(MA,{crumbs:[{label:re,icon:(0,R.jsx)(My,{})}],tabs:ne,actions:(0,R.jsx)(R.Fragment,{children:ae&&(0,R.jsx)(nE,{label:`Notes`,badge:ie,icon:(0,R.jsx)(hy,{}),active:oe,onClick:()=>x(!oe)})})}),(0,R.jsx)(RA,{aside:oe&&(0,R.jsx)(LA,{title:`Notes`,onClose:()=>x(!1),children:(0,R.jsx)(W6,{projectId:e,triaging:t.starting,reveal:i>0,onRevealed:a,onTriage:()=>{if(!g){t.triage();return}k(`triage`),D(!0)}})}),children:(0,R.jsxs)(PA,{routeKey:`project-${e}`,children:[(0,R.jsx)(FA,{title:re,meta:[{icon:(0,R.jsx)(gy,{}),text:ny,mono:!0,title:`the branch project chats run on`},f.value?{icon:(0,R.jsx)(Iy,{}),text:`lands on ${f.value}`}:null]}),(0,R.jsxs)(`div`,{className:`mt-8`,children:[(0,R.jsx)(B6,{landing:f,onStart:t.start,starting:t.starting,openSession:g&&E?{onOpen:()=>{D(!1),k(void 0),M()},onReplace:()=>{D(!1),t.replace(O),M()}}:void 0}),(0,R.jsx)(o8,{card:Fb({empty:o||!d,setupCommand:d?.driveSetupCommand,devCommand:d?.devCommand,drive:m.slot,projectId:e}),branch:h?.branch??(p.data?.current||null),setupCommand:d?.driveSetupCommand,devCommand:d?.devCommand,stopCommand:d?.driveStopCommand,starting:m.starting,onStart:()=>m.start(j),onPrepare:()=>s?.(),onReturn:j})]}),(0,R.jsx)(R6,{conversations:t.conversations,pending:t.conversationsPending,busy:t.starting,onResume:I,onOpen:M,onView:v})]})})]})}),h&&(0,R.jsx)(t8,{projectId:e,projectName:re,repoPath:d?.repoPath,drive:h,hidden:!ee,onProjectPage:N,onStop:()=>m.stop(N),stopping:m.stopping,onOpenPreparation:()=>s?.(),switcher:ne}),g&&(0,R.jsx)(Y6,{session:g,projectName:re,title:u8(t.conversations,g.id)??`project`,branch:f.value,hidden:!te,switcher:ne,onBack:()=>{D(!1),C(!0)},endControl:(0,R.jsx)(IG,{sessionId:g.id,onEnded:()=>{u.project.projectSession.invalidate(),u.project.conversations.invalidate()}}),children:(0,R.jsx)(LG,{label:`terminal`,children:(0,R.jsx)(_1,{sessionId:g.id})})})]})}function u8(e,t){return e.find(e=>e.id===t)?.title??null}function d8({dirty:e,onDismiss:t,children:n}){return(0,R.jsx)(QA,{open:!0,onClose:t,dirty:e,inline:!0,labelledBy:`park-draft-title`,backdropClassName:`min-h-0 overflow-y-auto bg-surface`,className:`max-w-[560px]`,children:n})}function f8({title:e,slug:t,oneLiner:n,notes:r,duplicate:i,busy:a,ready:o,onTitleChange:s,onOneLinerChange:c,onNotesChange:l,onSubmit:u,onCancel:d}){let f=()=>u(r.trim()||void 0);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)($A,{id:`park-draft-title`,title:`Park it for later`,description:`Write it down now, work it out later. Nothing is cut until you Start it.`,onClose:d}),(0,R.jsxs)(ej,{className:`flex flex-col gap-4 pt-1`,children:[(0,R.jsx)(AA,{label:`Title`,error:i,children:(0,R.jsx)(DA,{value:e,onChange:e=>s(e.target.value),placeholder:`e.g. Slack alerts on failed runs`,autoFocus:!0,invalid:!!i,onKeyDown:e=>{e.key===`Enter`&&f()}})}),(0,R.jsx)(AA,{label:`One-liner (optional)`,children:(0,R.jsx)(DA,{value:n,onChange:e=>c(e.target.value),placeholder:`What and why, in a sentence`,onKeyDown:e=>{e.key===`Enter`&&f()}})}),(0,R.jsx)(AA,{label:`Notes (optional — becomes the brief)`,children:(0,R.jsx)(kA,{rows:5,value:r,onChange:e=>l(e.target.value),placeholder:`Anything Start should know`})})]}),(0,R.jsxs)(tj,{className:`mt-2 border-t border-border-subtle pt-4`,start:(0,R.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,children:[(0,R.jsx)(gy,{size:14,className:`shrink-0 text-icon`}),(0,R.jsxs)(`span`,{className:`truncate font-mono`,children:[`feature/`,t||`…`,` · draft`]})]}),children:[(0,R.jsx)(Y,{variant:`ghost`,onClick:d,disabled:a,children:`Cancel`}),(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(ky,{}),onClick:f,disabled:!o||a,children:a?`Parking…`:`Park draft`})]})]})}function p8({projectId:e,onCancel:t,onCreated:n}){let[r,i]=(0,L.useState)(``),[a,o]=(0,L.useState)(``),[s,c]=(0,L.useState)(``),l=B.useUtils(),u=Ab(),d=gg(r,B.feature.list.useQuery({projectId:e},{refetchInterval:eh()}).data??[]),f=async e=>{await l.feature.list.invalidate(),n(e)},p=B.feature.create.useMutation({onSuccess:e=>void f(e.id),onError:e=>u.push(e.message)}),m=p.isPending,h=!!r.trim(),g=!!r.trim()||!!a.trim()||!!s.trim(),_=t=>{!h||m||p.mutate({projectId:e,title:r.trim(),oneLiner:a.trim(),draft:!0,...t?{brief:t}:{}})};return(0,R.jsx)(d8,{dirty:g,onDismiss:t,children:e=>(0,R.jsx)(f8,{title:r,slug:hg(r),oneLiner:a,notes:s,duplicate:d,busy:m,ready:h,onTitleChange:i,onOneLinerChange:o,onNotesChange:c,onSubmit:_,onCancel:e})})}var m8=`Repo facts an agent establishes once — how to install, how to verify, what is already red — so no burn agent re-derives them per ticket.`;function h8({projectId:e,onClose:t}){let n=B.useUtils(),r=Ab(),i=B.project.list.useQuery().data?.find(t=>t.id===e),a=B.project.prep.useQuery({projectId:e},{refetchInterval:eh(3e3)}),o=B.project.prepSession.useQuery({projectId:e},{refetchInterval:eh()}),s=B.project.talkToPrep.useMutation({onSuccess:()=>void n.project.prepSession.invalidate(),onError:e=>r.push(e.message)}),c=B.project.dryRunStop.useMutation({onSuccess:()=>{n.project.prep.invalidate(),n.feature.driveInfo.invalidate()},onError:e=>r.push(e.message)}),[l,u]=(0,L.useState)(!1),d=a.data,f=o.data??null,p=d?.findings??[],m=d?.pendingKeys??[],h=p.filter(Fp).length,g=f?f.ccSessionId??f.id:``;return(0,R.jsxs)(`section`,{className:`flex h-full min-h-0 min-w-0 flex-1 flex-col`,children:[(0,R.jsx)(MA,{crumbs:[{label:i?.name??`This project`,icon:(0,R.jsx)(My,{}),...t?{onClick:t}:{}},{label:`Preparation`,icon:(0,R.jsx)(zy,{})}],actions:f?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`mr-2 hidden items-center gap-4 text-xs text-text-tertiary md:flex`,children:[(0,R.jsx)(rA,{tone:f.status===`live`?`live`:`accent`,children:a3(jg(f))}),(0,R.jsx)(`span`,{className:`font-mono`,title:g,children:g.slice(0,8)})]}),(0,R.jsx)(IG,{sessionId:f.id,onEnded:()=>{n.project.prepSession.invalidate(),n.project.prep.invalidate()}}),p.length>0&&(0,R.jsx)(nE,{label:l?`Hide what is established`:`Show what is established`,icon:(0,R.jsx)(hy,{}),active:l,onClick:()=>u(e=>!e)})]}):void 0}),d?.dryRun&&(0,R.jsx)(v8,{open:B_(d.dryRun),stopping:c.isPending,onStop:()=>c.mutate({projectId:e})}),f?(0,R.jsx)(RA,{aside:l&&p.length>0&&(0,R.jsx)(LA,{title:`Established`,onClose:()=>u(!1),bodyClassName:`px-4 py-3`,children:(0,R.jsx)(_8,{findings:p,staleCount:h,compact:!0})}),children:(0,R.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 bg-surface-inset animate-fade-in`,children:(0,R.jsx)(LG,{label:`terminal`,children:(0,R.jsx)(_1,{sessionId:f.id})})})}):(0,R.jsxs)(PA,{routeKey:`prepare-${e}`,children:[a.isLoading&&(0,R.jsx)(UA,{children:`Loading preparation…`}),a.error&&(0,R.jsx)(GA,{icon:(0,R.jsx)(tb,{}),title:`Could not load preparation`,hint:a.error.message}),d&&(0,R.jsx)(g8,{prepared:d.prepared,preparedAt:d.preparedAt,pending:m,findings:p,staleCount:h,starting:s.isPending,onStart:()=>s.mutate({projectId:e}),onStartFresh:()=>s.mutate({projectId:e,fresh:!0})})]})]})}function g8({prepared:e,preparedAt:t,pending:n,findings:r,staleCount:i,starting:a,onStart:o,onStartFresh:s}){let c=r.length>0,l=[e&&{icon:(0,R.jsx)(eb,{}),text:t===null?`No preparation conversation on record`:`Prepared ${kp(t)}`},!e&&n.length>0&&{strong:n.length,text:`to establish`},c&&{strong:r.length,text:`established`},i>0&&{tone:`warning`,strong:i,text:`stale`}];return e?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(FA,{title:`Re-prepare this project`,meta:l,children:[(0,R.jsxs)(`p`,{className:`m-0 max-w-[60ch] text-base text-pretty text-text-secondary`,children:[t===null&&`Every field already had a value. `,m8,` Repo facts drift; re-preparing measures them again with you there.`]}),(0,R.jsxs)(`div`,{className:`mt-6 flex flex-wrap items-center gap-2`,children:[(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(ab,{}),loading:a,disabled:a,onClick:o,children:`Resume`}),(0,R.jsx)(Y,{icon:(0,R.jsx)(yy,{}),disabled:a,onClick:s,children:`Start fresh`})]}),(0,R.jsx)(`p`,{className:`mt-2 mb-0 max-w-[60ch] text-xs text-pretty text-text-tertiary`,children:`Resume continues your last preparation conversation; Start fresh opens one that has never seen it — values you typed by hand are never overwritten.`})]}),(0,R.jsx)(_8,{findings:r,staleCount:i})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(FA,{title:c?`Finish preparing this project`:`Prepare this project first`,meta:l,children:[(0,R.jsx)(`p`,{className:`m-0 max-w-[60ch] text-base text-pretty text-text-secondary`,children:m8}),(0,R.jsx)(`div`,{className:`mt-6 flex flex-wrap items-center gap-2`,children:(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(Ly,{}),loading:a,disabled:a,onClick:o,children:`Start preparation`})}),(0,R.jsx)(`p`,{className:`mt-2 mb-0 max-w-[60ch] text-xs text-pretty text-text-tertiary`,children:`Opens a terminal session here with an agent in your own checkout — it runs this repo's commands, records the answers, and asks you the ones only you know.`})]}),n.length>0&&(0,R.jsx)(IA,{title:`To establish`,children:(0,R.jsx)(yA,{divided:!0,label:`To establish`,children:n.map((e,t)=>(0,R.jsx)(vA,{index:t,leading:(0,R.jsx)(sb,{}),title:Dp[e]??e,meta:`Not yet`},e))})}),(0,R.jsx)(_8,{findings:r,staleCount:i})]})}function _8({findings:e,staleCount:t,compact:n=!1}){if(e.length===0)return null;let r=(0,R.jsxs)(R.Fragment,{children:[t>0&&(0,R.jsx)(y8,{count:t}),(0,R.jsx)(b8,{findings:e})]});return n?r:(0,R.jsx)(IA,{title:`Established`,children:r})}function v8({open:e,stopping:t,onStop:n}){return(0,R.jsxs)(`div`,{className:`flex h-10 shrink-0 items-center gap-3 border-b border-border-subtle px-4 animate-fade-in`,children:[(0,R.jsx)(rA,{tone:`live`,size:`sm`,strong:!0,children:`Preparation dry run in progress`}),e&&(e.state===`ready`?(0,R.jsxs)(`a`,{className:q(`cursor-pointer text-accent-text no-underline decoration-accent-text/50 underline-offset-2 transition-colors duration-(--dur-1) ease-app hover:underline hover:decoration-accent-text`,`inline-flex min-w-0 items-center gap-1 truncate font-mono text-xs`),href:e.url,target:`_blank`,rel:`noreferrer`,children:[e.url,(0,R.jsx)(qy,{size:12,className:`shrink-0`})]}):(0,R.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs text-text-tertiary`,children:V_(e)})),(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(Ry,{}),loading:t,disabled:t,onClick:n,children:`Stop`})]})}function y8({count:e}){return(0,R.jsxs)(`div`,{className:`mb-4 flex max-w-[64ch] items-start gap-2 text-sm text-pretty text-text-secondary`,children:[(0,R.jsx)(tb,{size:16,className:`mt-0.5 shrink-0 text-warning`}),(0,R.jsxs)(`span`,{children:[e,` finding`,e===1?` has`:`s have`,` not been re-measured in a long time. A stale test baseline is worse than none — agents trust it and file their own breakage under “already red on main”.`]})]})}function b8({findings:e}){return(0,R.jsx)(`div`,{className:`flex flex-col [&>details:last-child]:border-b [&>details:last-child]:border-border-subtle`,children:e.map((e,t)=>(0,R.jsx)(x8,{finding:e,label:Dp[e.key]??e.key,index:t},e.key))})}function x8({finding:e,label:t,index:n}){let[r,i]=(0,L.useState)(!1),a=Ip(e),o=Fp(e);return(0,R.jsx)(JA,{title:t,index:n,aside:(0,R.jsxs)(`span`,{className:`flex items-center gap-4`,children:[o&&(0,R.jsx)(rA,{tone:`warning`,children:`Stale`}),(0,R.jsx)(S8,{finding:e}),(0,R.jsx)(rA,{title:a.title,children:a.label})]}),children:(0,R.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,R.jsx)(`div`,{className:q(`text-xs`,o?`text-warning`:`text-text-tertiary`),children:Mp(e)}),e.evidence&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`div`,{className:`rounded-md border border-border-subtle bg-surface-inset px-3 py-2`,children:(0,R.jsx)(`div`,{className:q(`font-mono text-xs leading-[1.5] break-words whitespace-pre-wrap text-text-secondary`,!r&&`line-clamp-3`),children:e.evidence})}),(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,className:`-ml-2 self-start`,onClick:()=>i(e=>!e),"aria-expanded":r,"aria-label":`${r?`Collapse`:`Show full`} evidence for ${t}`,children:r?`Show less`:`Show full evidence`})]})]})})}function S8({finding:e}){return Ap(e.key)?e.verifiedAt===void 0?(0,R.jsx)(rA,{tone:`warning`,title:`No dry run has ever proven this value — a drive that depends on it may fall over`,children:`Unproven`}):(0,R.jsxs)(rA,{tone:`success`,icon:(0,R.jsx)(by,{size:14}),title:`A preparation dry run ran this value on the real drive machinery and it worked`,children:[`Proven `,kp(e.verifiedAt)]}):null}var C8=(e,t)=>e===``||t.includes(e);function w8(e){let{open:t,onClose:n,features:r,selectedFeatureId:i,onSelect:a,onOpenSettings:o,onOpenPreparation:s,onOpenProjectChat:c,onOpenNote:l,onToggleSidebar:u,onToggleDetails:d,nav:f}=e,p=nM(),[m,h]=(0,L.useState)(``),[g,_]=(0,L.useState)(0),v=(0,L.useRef)(null),y=(0,L.useRef)([]);(0,L.useEffect)(()=>{if(!t)return;h(``),_(0),v.current?.focus();let e=requestAnimationFrame(()=>v.current?.focus());return()=>cancelAnimationFrame(e)},[t]),(0,L.useEffect)(()=>{if(!t)return;let e=e=>{e.key!==`Escape`||e.defaultPrevented||(e.preventDefault(),n())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,n]),(0,L.useEffect)(()=>{_(0)},[m]);let b=m.trim().toLowerCase(),x=(0,L.useMemo)(()=>b===``?r:r.filter(e=>e.slug.toLowerCase().includes(b)||e.title.toLowerCase().includes(b)),[r,b]),S=(0,L.useMemo)(()=>(f.projects??[]).filter(e=>e.id!==f.currentProjectId),[f.projects,f.currentProjectId]),C=(0,L.useMemo)(()=>b===``?S:S.filter(e=>e.name.toLowerCase().includes(b)),[S,b]),w=(0,L.useMemo)(()=>{let e=p.resolved===`dark`?`light`:`dark`;return[{kind:`projectChat`,shows:dy(b),glyph:(0,R.jsx)(Qy,{}),label:`Project chat`,run:c},{kind:`newNote`,shows:C8(b,`new note jot capture`),glyph:(0,R.jsx)(Ay,{}),label:`New note`,kbd:wj(`J`),run:l},{kind:`preparation`,shows:uy(b),glyph:(0,R.jsx)(zy,{}),label:`Preparation`,run:s},{kind:`settings`,shows:C8(b,`settings preferences`),glyph:(0,R.jsx)(my,{}),label:`Settings`,run:o},{kind:`theme`,shows:C8(b,`toggle theme dark light appearance ${e}`),glyph:p.resolved===`dark`?(0,R.jsx)(Yy,{}):(0,R.jsx)(Xy,{}),label:`Toggle theme — switch to ${e}`,run:p.toggle},...u?[{kind:`sidebar`,shows:C8(b,`toggle sidebar hide show collapse expand`),glyph:(0,R.jsx)(Gy,{}),label:`Toggle sidebar`,kbd:wj(`B`),run:u}]:[],...d?[{kind:`details`,shows:C8(b,`toggle details panel inspector hide show`),glyph:(0,R.jsx)(hy,{}),label:`Toggle details panel`,run:d}]:[],{kind:`home`,shows:C8(b,`all projects home`),glyph:(0,R.jsx)(My,{}),label:`All projects`,run:f.goHome},{kind:`openProject`,shows:C8(b,`open a project`),glyph:(0,R.jsx)(yy,{}),label:`Open a project…`,run:f.showOpen}].filter(e=>e.shows)},[b,p.resolved,p.toggle,c,l,o,s,u,d,f]),T=(0,L.useMemo)(()=>{let e=x.map(e=>({kind:`feature`,feature:e}));for(let t of C)e.push({kind:`project`,id:t.id,name:t.name});for(let t of w)e.push({kind:`action`,action:t});return e},[x,C,w]);if(!t)return null;let E=e=>{if(T.length===0)return;let t=(g+e+T.length)%T.length;_(t),y.current[t]?.scrollIntoView({block:`nearest`})},D=e=>{let t=T[e];if(t){switch(t.kind){case`feature`:a(t.feature.id);break;case`project`:f.enterProject(t.id);break;case`action`:t.action.run();break}n()}},O=e=>{e.key===`ArrowDown`?(e.preventDefault(),E(1)):e.key===`ArrowUp`?(e.preventDefault(),E(-1)):e.key===`Enter`?(e.preventDefault(),D(g)):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),n())},k=x.length,A=k+C.length,j=(e,t,n,r,i,a)=>(0,R.jsxs)(`div`,{ref:t=>{y.current[e]=t},role:`option`,"aria-selected":e===g,"data-selected":e===g,className:q(Bb,Vb,`min-h-8 hover:bg-transparent`),onMouseMove:()=>e!==g&&_(e),onClick:()=>D(e),children:[(0,R.jsx)(`span`,{className:`inline-flex size-4 shrink-0 items-center justify-center [&>svg]:size-4`,children:n}),(0,R.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:a,children:r}),i]},t),M=e=>(0,R.jsx)(`div`,{className:q(Ub,`pt-2.5`),children:e});return(0,R.jsx)(`div`,{className:`fixed inset-0 z-[300] flex animate-backdrop-in items-start justify-center bg-scrim px-4 pt-[12vh] pb-4`,onMouseDown:e=>{e.target===e.currentTarget&&n()},children:(0,R.jsxs)(`div`,{role:`dialog`,"aria-label":`Command palette`,className:`flex max-h-[min(520px,76vh)] w-full max-w-[560px] animate-dialog-in flex-col overflow-hidden rounded-lg bg-surface-raised text-text shadow-dialog`,children:[(0,R.jsxs)(`div`,{className:`flex h-13 shrink-0 items-center gap-3 border-b border-border-subtle px-4`,children:[(0,R.jsx)(py,{size:16,className:`shrink-0 text-icon`}),(0,R.jsx)(`input`,{ref:v,className:`h-full min-w-0 flex-1 border-0 bg-transparent p-0 font-sans text-base text-text outline-none placeholder:text-text-tertiary`,placeholder:`Search features, projects, or jump to…`,value:m,onChange:e=>h(e.target.value),onKeyDown:O,"aria-label":`Search features, projects, or jump to`})]}),(0,R.jsxs)(`div`,{role:`listbox`,"aria-label":`Results`,className:`min-h-0 flex-1 overflow-y-auto p-1.5`,children:[x.length>0&&M(`Features`),x.map((e,t)=>j(t,e.id,(0,R.jsx)(xb,{phase:e.status===`draft`?`draft`:e.phase,label:``}),e.title,(0,R.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2 text-xs text-text-tertiary`,children:[e.id===i&&(0,R.jsx)(`span`,{className:`text-text-secondary`,children:`Current`}),(0,R.jsx)(`span`,{children:e.status===`draft`?vb.draft:vb[e.phase]})]}),e.title)),C.length>0&&M(`Projects`),C.map((e,t)=>j(k+t,e.id,(0,R.jsx)(My,{className:`text-icon`}),e.name,(0,R.jsx)(`span`,{className:`shrink-0 text-xs text-text-tertiary`,children:`Switch`}),e.name)),w.length>0&&M(`Actions`),w.map((e,t)=>j(A+t,e.kind,e.glyph,e.label,e.kbd?(0,R.jsx)(Gb,{children:e.kbd}):null,e.label)),T.length===0&&(0,R.jsx)(`div`,{className:`p-6 text-center text-sm text-text-tertiary`,children:`No matches`})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-4 border-t border-border-subtle px-4 py-2 text-xs text-text-tertiary`,children:[(0,R.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(Gb,{children:`↑`}),(0,R.jsx)(Gb,{children:`↓`}),` to move`]}),(0,R.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(Gb,{children:`Enter`}),` to open`]}),(0,R.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(Gb,{children:`Esc`}),` to close`]})]})]})})}var T8=1500,E8=`flex h-13 items-center gap-3 px-4`;function D8({projectId:e,projectName:t,open:n,openRequest:r=0,onClose:i,onOpenInbox:a}){let o=B.useUtils(),s=Ab(),[c,l]=(0,L.useState)(``),[u,d]=(0,L.useState)(null),[f,p]=(0,L.useState)(!1),[m,h]=(0,L.useState)(!1),g=(0,L.useRef)(null),_=(0,L.useRef)(0),v=()=>{l(``),d(null),p(!1),h(!1)},[y,b]=(0,L.useState)(n);n!==y&&(b(n),_.current+=1,n&&v());let[x,S]=(0,L.useState)(r);r!==x&&(S(r),n&&m&&v()),(0,L.useEffect)(()=>{n&&g.current?.focus()},[r]);let C=B.projectNotes.add.useMutation(),w=B.projectNotes.openCount.useQuery({projectId:e},{enabled:n}),T=(0,L.useRef)(null);(0,L.useEffect)(()=>{T.current=u?.preview??null},[u]),(0,L.useEffect)(()=>{if(n)return()=>{T.current&&URL.revokeObjectURL(T.current)}},[n]);let E=(0,L.useRef)(i);E.current=i,(0,L.useEffect)(()=>{if(!m)return;let e=setTimeout(()=>E.current(),T8);return()=>clearTimeout(e)},[m]);let D=async e=>{try{let t=await Gm(e),n={png:t,preview:URL.createObjectURL(t)};d(e=>(e&&URL.revokeObjectURL(e.preview),n))}catch(e){s.push(e instanceof Error?e.message:`that image could not be read`)}},O=()=>{d(e=>(e&&URL.revokeObjectURL(e.preview),null)),g.current?.focus()},k=e=>{let t=Wm(e.clipboardData);t&&(e.preventDefault(),D(t))},A=async()=>{if(!c.trim()||f)return;let t=_.current,n=()=>_.current===t;p(!0);try{let t=await C.mutateAsync({projectId:e,text:c});if(u)try{await Mb(t.id,u.png)}catch(e){s.push(`the note was saved, but its picture was not: ${e instanceof Error?e.message:String(e)}`)}o.projectNotes.openCount.setData({projectId:e},e=>e===void 0?e:e+1),o.projectNotes.invalidate(),n()&&h(!0)}catch(e){s.push(e instanceof Error?e.message:`the note could not be saved`)}finally{n()&&p(!1)}};return(0,R.jsx)(QA,{open:n,onClose:i,size:`palette`,scrim:m?`none`:`light`,className:`overflow-hidden`,label:`Jot a note`,initialFocusRef:g,children:m?(0,R.jsxs)(`div`,{className:q(E8,`text-sm animate-fade-in`),role:`status`,children:[(0,R.jsx)(`span`,{className:`flex shrink-0 items-center text-success`,children:(0,R.jsx)(by,{size:16})}),(0,R.jsxs)(`span`,{className:`min-w-0 flex-1 truncate text-text-secondary`,children:[`Noted in `,(0,R.jsx)(`span`,{className:`font-medium text-text`,children:t}),w.data!==void 0&&(0,R.jsxs)(R.Fragment,{children:[` · `,w.data,` open`]})]}),(0,R.jsx)(`button`,{className:q(sE,`text-sm`),onClick:()=>{a(),i()},title:`Read the pile on the project workspace`,children:`View`})]}):(0,R.jsxs)(`div`,{onPaste:k,children:[(0,R.jsxs)(`div`,{className:q(E8,`border-b border-border-subtle`),children:[(0,R.jsx)(`span`,{className:`flex shrink-0 items-center text-icon`,children:(0,R.jsx)(Ay,{size:16})}),(0,R.jsx)(`input`,{ref:g,className:`h-full min-w-0 flex-1 border-0 bg-transparent p-0 font-sans text-base text-text outline-none placeholder:text-text-tertiary`,autoComplete:`off`,"aria-label":`what did you just notice?`,placeholder:`What did you just notice?`,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),A())}})]}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-4 py-2 text-xs text-text-tertiary`,children:[u?(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-text-secondary animate-fade-in`,children:[(0,R.jsx)(`img`,{src:u.preview,alt:`the picture this note will carry`,className:`h-5 w-8 rounded-sm bg-surface-inset object-cover`}),`Screenshot`,(0,R.jsx)(nE,{size:`sm`,label:`Remove the picture`,icon:(0,R.jsx)(xy,{}),onClick:O})]}):(0,R.jsx)(`span`,{children:`Paste a screenshot`}),(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsxs)(`span`,{children:[`to `,(0,R.jsx)(`span`,{className:`font-medium text-text-secondary`,children:t})]}),(0,R.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(Gb,{children:`↵`}),` save`]}),(0,R.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(Gb,{children:`esc`}),` close`]})]})]})})}var O8={"claude-code":{check:`afk-key`,kind:`token`},codex:{check:`auth`,kind:`sign-in`}};function k8(e){return Wu.flatMap(t=>{let{check:n,kind:r}=O8[t],i=e.find(e=>e.runtime===t&&e.check===n);return i?[{runtime:t,kind:r,probe:i}]:[]})}function A8(e){return`${O8[e].check}-${e}`}function j8(e){let t=Rp[e],n=O8[e].kind===`token`;return{field:A8(e),label:n?`${t} token`:t,reason:n?`burns with ${t} need a token`:`sign in to ${t}`,terms:n?[t,`token`,`AFK credential`]:[t,`sign in`,`login`]}}var M8=[{field:`container-runtime`,label:`Container runtime`,reason:`no container runtime on this machine`,terms:[`Container runtime`,`Docker`,`Podman`]},{field:`sandcastle-image`,label:`Sandcastle image`,reason:`the sandcastle image needs building`,terms:[`Sandcastle image`,`build`,`rebuild`]},...Wu.map(j8),{field:`burn-cache`,label:`Burn cache`,terms:[`Burn cache`,`volume`,`clear`]}];function N8(e){let t=e.find(e=>!e.ok);return t?{count:`${e.filter(e=>e.ok).length} of ${e.length}`,text:`ready — ${t.reason}`}:{count:null,text:`Ready for unattended burns`}}var P8=[{page:`general`,label:`General`,Icon:my},{page:`models`,label:`Models`,Icon:Ny},{page:`burns`,label:`Burns`,Icon:Py},{page:`project`,label:`This project`,Icon:My}];function F8({page:e,filter:t,filterRef:n,projectName:r,onFilter:i,onSelect:a}){let o=t.query.trim()!==``;return(0,R.jsxs)(`nav`,{"aria-label":`Settings pages`,className:`flex min-h-0 flex-col gap-0.5 border-r border-border-subtle bg-canvas px-2 pt-4 pb-3`,children:[(0,R.jsx)(`div`,{className:`mb-2 px-2.5 text-sm font-medium text-text`,children:`Settings`}),(0,R.jsx)(OA,{ref:n,size:`md`,"aria-label":`Filter settings`,placeholder:`Filter`,kbd:`Ctrl F`,autoComplete:`off`,value:t.query,onChange:e=>i(e.target.value),className:`mb-3`}),P8.map(({page:n,label:r,Icon:i})=>(0,R.jsx)(_A,{label:r,icon:(0,R.jsx)(i,{}),active:n===e,onClick:()=>a(n),meta:o?t.counts[n]||``:void 0},n)),(0,R.jsx)(`div`,{className:`flex-1`}),(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5 px-2.5 pt-3`,children:[(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary`,children:`This project is`}),(0,R.jsx)(`span`,{className:`truncate font-mono text-xs text-text-secondary`,title:r,children:r})]})]})}var I8=1500;function L8(e){let t=(0,L.useRef)(null),[n,r]=(0,L.useState)(!1);return(0,L.useEffect)(()=>{if(!e)return;t.current?.scrollIntoView?.({block:`center`}),r(!0);let n=setTimeout(()=>r(!1),I8);return()=>clearTimeout(n)},[e]),{ref:t,flash:n}}function R8(e,t){return e.query.trim()===``||e.matches.has(t)}var z8=1400;function B8({title:e,rows:t,projectId:n,filter:r,highlightField:i,onOpenEvidence:a,evidence:o}){let s=t.filter(e=>R8(r,e.key));return s.length===0?null:(0,R.jsx)(V8,{title:e,children:s.map(e=>(0,R.jsx)(U8,{row:e,projectId:n,highlight:i===e.key,...a&&e.provenanceChip?.evidence?{onOpenEvidence:()=>a(e.key)}:{},...o?{evidence:o(e)}:{}},e.key))})}function V8({title:e,action:t,description:n,children:r}){return(0,R.jsxs)(`section`,{className:`mt-9 first:mt-0`,children:[(0,R.jsxs)(`div`,{className:`flex min-h-7 items-center gap-3 border-b border-border-subtle pb-2`,children:[(0,R.jsx)(`h3`,{className:`m-0 min-w-0 flex-1 text-sm font-medium text-text`,children:e}),t&&(0,R.jsx)(`div`,{className:`flex shrink-0 items-center gap-1`,children:t})]}),n&&(0,R.jsx)(`div`,{className:`mt-2.5 text-xs text-pretty text-text-tertiary`,children:n}),(0,R.jsx)(`div`,{children:r})]})}function H8({label:e,htmlFor:t,description:n,descriptionId:r,aside:i,control:a,below:o,stacked:s=!1,flash:c=!1,rowRef:l}){return(0,R.jsxs)(`div`,{ref:l,className:q(`border-b border-border-subtle py-4 last:border-b-0`,`transition-[outline-color] duration-(--dur-3) ease-app`,s?`flex flex-col gap-2.5`:`grid grid-cols-[minmax(0,1fr)_minmax(0,300px)] items-start gap-x-8 gap-y-1.5`,c&&`rounded-md outline-2 outline-offset-4 outline-accent`),children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5 pt-1`,children:[(0,R.jsxs)(`div`,{className:`flex min-h-5 items-center gap-2`,children:[(0,R.jsx)(`label`,{htmlFor:t,className:`text-sm font-medium text-text`,children:e}),i]}),n&&(0,R.jsx)(`p`,{id:r,className:`m-0 text-xs text-pretty text-text-tertiary`,children:n})]}),(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1.5`,children:[a,o]})]})}function U8({row:e,projectId:t,highlight:n,onOpenEvidence:r,evidence:i}){let a=B.useUtils(),o=e.ghostValue?``:e.value,[s,c]=(0,L.useState)(o),[l,u]=(0,L.useState)(null),[d,f]=(0,L.useState)(!1),[p,m]=(0,L.useState)(!1),{ref:h,flash:g}=L8(n),_=(0,L.useRef)(void 0);(0,L.useEffect)(()=>c(o),[o]),(0,L.useEffect)(()=>()=>clearTimeout(_.current),[]);let v=B.settings.update.useMutation({onSuccess:()=>{u(null),f(!0),clearTimeout(_.current),_.current=setTimeout(()=>f(!1),z8),e.restartRequired&&m(!0),a.settings.get.invalidate(),a.project.prep.invalidate()},onError:e=>{c(o),u(e.message)}}),y=e=>{c(e),l&&u(null)},b=n=>{u(null),v.mutate({...t?{projectId:t}:{},key:e.key,value:n})},x=t=>{if(t.trim()===o.trim())return;let n=rm(e.control,t);if(`error`in n){u(n.error);return}b(n.value)},S=()=>b(null),C=`set-${t?`project`:`global`}-${e.key}`,w=`${C}-help`,T=`${C}-error`,E=`${C}-about`,D=q(E,e.shortHelp?w:null,l?T:null)||void 0,O=e.sourceChip||e.clearable||e.provenanceChip;return(0,R.jsx)(H8,{rowRef:h,flash:g,stacked:e.control===`textarea`,label:e.label,htmlFor:C,description:e.tooltip||void 0,descriptionId:E,aside:d&&(0,R.jsx)(W8,{}),control:(0,R.jsx)(G8,{id:C,describedBy:D,row:e,draft:s,disabled:v.isPending,onDraft:y,onCommit:x,onRevert:()=>c(o)}),below:(0,R.jsxs)(R.Fragment,{children:[e.shortHelp&&(0,R.jsx)(`div`,{id:w,className:`text-xs text-text-tertiary`,children:e.shortHelp}),O&&(0,R.jsxs)(`div`,{className:`flex min-h-5 flex-wrap items-center gap-x-3 gap-y-1`,children:[e.sourceChip&&(0,R.jsx)(q8,{kind:e.sourceChip,envVar:Lp[e.key]}),e.sourceChip===`project`&&(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:S,className:`-ml-1.5`,children:`Use global`}),e.clearable&&(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:S,className:`-ml-1.5`,children:`Clear`}),e.provenanceChip&&(0,R.jsxs)(`div`,{className:`relative flex min-w-0`,children:[(0,R.jsx)(Y8,{chip:e.provenanceChip,onOpenEvidence:r}),i]}),e.stale&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-warning`,title:`Measured a long time ago — “Re-prepare the project”, at the foot of the features rail, refreshes it`,children:[(0,R.jsx)(tA,{tone:`warning`}),`Stale`]})]}),p&&(0,R.jsx)(`div`,{className:`text-xs text-warning`,children:`Restart the server to apply`}),l&&(0,R.jsx)(`div`,{id:T,role:`alert`,className:`text-xs text-danger`,children:l})]})})}function W8(){return(0,R.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1 text-xs text-text-tertiary animate-fade-in`,children:[(0,R.jsx)(by,{size:12,className:`text-success`}),`Saved`]})}function G8({id:e,describedBy:t,row:n,draft:r,disabled:i,onDraft:a,onCommit:o,onRevert:s}){let c={id:e,"aria-describedby":t,disabled:i},l=e=>{e.key===`Escape`&&(s(),e.currentTarget.blur())},u=e=>{e.key===`Enter`&&e.currentTarget.blur(),l(e)},d=n.unit?(0,R.jsx)(`span`,{className:`min-w-0 text-xs text-pretty text-text-tertiary`,children:n.unit}):void 0;if(n.readOnly)return(0,R.jsx)(DA,{...c,disabled:!0,readOnly:!0,mono:n.control!==`select`,icon:(0,R.jsx)(Fy,{}),className:`w-full`,inputClassName:n.control===`number`?`tabular-nums`:void 0,value:n.optionLabels[n.value]??n.value});if(n.control===`select`)return(0,R.jsxs)(Q0,{value:r,onValueChange:e=>{a(e),o(e)},children:[(0,R.jsx)(n2,{...c,className:q(e2,`w-full`),children:(0,R.jsx)(r2,{})}),(0,R.jsxs)(i2,{children:[n.ghostValue&&(0,R.jsxs)(c2,{value:``,children:[`Use global (`,n.optionLabels[n.ghostValue]??n.ghostValue,`)`]}),n.modelGroups.length>0?n.modelGroups.map(e=>(0,R.jsxs)(a2,{children:[(0,R.jsx)(o2,{children:e.label}),e.entries.map(e=>(0,R.jsx)(c2,{value:e.id,title:e.note,children:e.note?`${e.id} — ${e.note}`:e.id},e.id))]},e.runtime)):n.options.map(e=>(0,R.jsx)(c2,{value:e,children:n.optionLabels[e]??e},e))]})]});if(n.control===`textarea`)return(0,R.jsx)(kA,{...c,mono:!0,rows:3,placeholder:n.ghostValue??n.placeholder,value:r,onChange:e=>a(e.target.value),onBlur:e=>o(e.target.value),onKeyDown:l});let f=(0,R.jsx)(DA,{...c,type:n.control===`number`?`number`:`text`,mono:!0,className:n.control===`number`?`w-24 shrink-0`:`w-full`,inputClassName:n.control===`number`?`tabular-nums`:void 0,placeholder:n.ghostValue??n.placeholder,value:r,onChange:e=>a(e.target.value),onBlur:e=>o(e.target.value),onKeyDown:u});return d?(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2.5`,children:[f,d]}):f}var K8={global:{text:`Global`,tone:`neutral`,word:`text-text-tertiary`},project:{text:`This project`,tone:`accent`,word:`text-text-secondary`},env:{text:`Env`,tone:`neutral`,word:`text-text-tertiary`}};function q8({kind:e,envVar:t}){let n=K8[e];return(0,R.jsxs)(`span`,{className:q(`inline-flex shrink-0 items-center gap-1.5 text-xs`,n.word),...e===`env`&&t?{title:`Set by ${t}`}:{},children:[e===`env`?(0,R.jsx)(Fy,{size:12,className:`text-icon`}):(0,R.jsx)(tA,{tone:n.tone}),(0,R.jsx)(`span`,{children:n.text})]})}var J8={ok:`success`,muted:`neutral`,warn:`warning`};function Y8({chip:e,onOpenEvidence:t}){let n=(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(tA,{tone:J8[e.tone]}),(0,R.jsx)(`span`,{className:`truncate`,children:e.text})]}),r=e.tone===`warn`?`text-warning`:`text-text-secondary`;return t?(0,R.jsx)(`button`,{type:`button`,onClick:t,className:q(`-mx-1.5 inline-flex h-6 min-w-0 cursor-pointer items-center gap-1.5 rounded-md border-0 bg-transparent px-1.5 text-xs`,`underline decoration-border-strong decoration-dotted underline-offset-4`,`transition-colors duration-(--dur-1) ease-app hover:bg-surface-hover hover:text-text`,r),children:n}):(0,R.jsx)(`span`,{className:q(`inline-flex min-w-0 items-center gap-1.5 text-xs`,r),children:n})}var X8=`theme`,Z8=[{value:`dark`,label:`Dark`,icon:(0,R.jsx)(Xy,{size:14})},{value:`light`,label:`Light`,icon:(0,R.jsx)(Yy,{size:14})},{value:`system`,label:`System`,icon:(0,R.jsx)(Zy,{size:14})}];function Q8({globals:e,filter:t,highlightField:n}){let r=R8(t,`theme`)&&(0,R.jsx)(V8,{title:`Appearance`,children:(0,R.jsx)($8,{})});if(e.isLoading)return(0,R.jsxs)(R.Fragment,{children:[r,(0,R.jsx)(UA,{className:`mt-9`,children:`Loading settings…`})]});if(e.error)return(0,R.jsxs)(R.Fragment,{children:[r,(0,R.jsxs)(WA,{children:[`Could not load settings: `,e.error.message]})]});if(!e.data)return(0,R.jsx)(R.Fragment,{children:r});let i=pm(e.data,`general`),a=e=>i.filter(t=>t.group===e);return(0,R.jsxs)(R.Fragment,{children:[r,(0,R.jsx)(B8,{title:`Server`,rows:a(`server`),filter:t,highlightField:n}),(0,R.jsx)(B8,{title:`Sessions`,rows:a(`sessions`),filter:t,highlightField:n})]})}function $8(){let{preference:e,setPreference:t}=nM();return(0,R.jsx)(H8,{label:`Theme`,description:`Dark is the default; System follows your operating system as it changes.`,control:(0,R.jsx)(BA,{id:`settings-theme`,label:`Theme`,items:Z8.map(e=>({value:e.value,label:e.label,icon:e.icon})),value:e,onChange:t,className:`w-full`})})}var e5=`grid grid-cols-[minmax(0,1.5fr)_minmax(0,1.3fr)_minmax(0,0.8fr)_88px_24px] items-center gap-3`,t5=`min-h-8 border-b border-border-subtle px-2 text-xs font-medium text-text-tertiary`,n5=e=>`models:${e}`,r5=`models:new`,i5=`opacity-0 transition-opacity duration-(--dur-1) group-hover:opacity-100 group-focus-within:opacity-100 focus-visible:opacity-100`;function a5({rows:e,stepLabels:t,customModels:n,filter:r,writes:i}){let[a,o]=(0,L.useState)(!1),s=r.query.trim()!==``,c=(a||s?e:xm(e)).filter(e=>R8(r,e.id)),l=a||s?0:Sm(e);return(0,R.jsxs)(`div`,{className:`mt-3`,children:[(0,R.jsxs)(`div`,{className:q(e5,t5),children:[(0,R.jsx)(`span`,{children:`Model`}),(0,R.jsx)(`span`,{children:`Use-case note`}),(0,R.jsx)(`span`,{children:`Used for`}),(0,R.jsx)(`span`,{children:`Default`}),(0,R.jsx)(`span`,{})]}),c.map((e,r)=>(0,R.jsx)(o5,{index:r,row:e,stepLabels:t,customModels:n,writes:i},e.id)),l>0&&(0,R.jsxs)(`div`,{className:`flex min-h-10 items-center gap-2 border-b border-border-subtle px-2 text-xs text-text-tertiary`,children:[l,` more `,l===1?`model`:`models`,` nobody uses`,(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>o(!0),children:`Show all`})]}),!s&&(0,R.jsx)(l5,{customModels:n,writes:i})]})}function o5({row:e,index:t,stepLabels:n,customModels:r,writes:i}){let a=n5(e.id),o=e.usedFor.map(e=>n.get(e)??e).join(`, `),s=t=>{let n=t.trim(),o=n===``&&!e.custom?r.filter(t=>t.id!==e.id):Zu(r,[{id:e.id,runtime:e.runtime,...n?{note:n}:{}}]);i.save(a,`models`,o)},c=()=>{if(e.isDefault){i.refuse(a,`${e.id} is the default model — make another model the default first.`);return}if(e.usedFor.length>0){i.refuse(a,`${e.id} runs ${o} — reset those steps first.`);return}i.save(a,`models`,r.filter(t=>t.id!==e.id))},l=t<8;return(0,R.jsxs)(`div`,{className:q(`group border-b border-border-subtle transition-colors duration-(--dur-1) ease-app hover:bg-surface-hover`,l&&`animate-rise-in`),style:l?{animationDelay:`${t*20}ms`}:void 0,children:[(0,R.jsxs)(`div`,{className:q(e5,`min-h-10 px-2 text-sm`),children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,R.jsx)(d5,{runtime:e.runtime}),(0,R.jsx)(`span`,{className:`truncate text-text`,title:e.displayName?`${e.displayName} — ${e.id}`:e.id,children:e.id}),e.isNew&&(0,R.jsx)(rA,{tone:`accent`,className:`shrink-0`,children:`New`})]}),(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,R.jsx)(c5,{row:e,onCommit:s}),i.saved===a&&(0,R.jsx)(W8,{})]}),(0,R.jsxs)(`span`,{className:`truncate text-xs text-text-tertiary`,title:o||void 0,children:[e.isDefault&&(0,R.jsx)(`span`,{className:`text-text-secondary`,children:`Default`}),e.isDefault&&o!==``&&`, `,o===``?e.isDefault?``:`—`:o]}),e.isDefault?(0,R.jsx)(`span`,{"data-default-mark":``,className:`inline-flex`,children:(0,R.jsx)(rA,{strong:!0,icon:(0,R.jsx)(by,{}),children:`Default`})}):(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,"aria-label":`Make ${e.id} the default`,onClick:()=>i.save(a,`model`,e.id),className:q(`-ml-2 justify-self-start`,i5),children:`Make default`}),e.custom?(0,R.jsx)(nE,{label:`Remove ${e.id}`,size:`sm`,icon:(0,R.jsx)(Sy,{}),onClick:c,variant:`danger-ghost`,className:i5}):(0,R.jsx)(`span`,{})]}),(0,R.jsx)(s5,{row:e}),(0,R.jsx)(u5,{writes:i,cell:a})]})}function s5({row:e}){return!e.noLongerOffered&&!e.retirement?null:(0,R.jsxs)(`p`,{className:`m-0 flex flex-wrap gap-x-4 pr-2 pb-2.5 pl-8 text-xs text-warning`,children:[e.noLongerOffered&&(0,R.jsxs)(`span`,{children:[`no longer offered by `,_m[e.noLongerOffered]]}),e.retirement&&(0,R.jsxs)(`span`,{children:[`retires `,e.retirement.at,` → `,e.retirement.replacement]})]})}function c5({row:e,onCommit:t}){let[n,r]=(0,L.useState)(e.note);return(0,L.useEffect)(()=>r(e.note),[e.note]),(0,R.jsx)(`input`,{type:`text`,"aria-label":`Note for ${e.id}`,placeholder:e.isDefault?`e.g. UI/UX work, design-heavy tickets`:`Add a note`,className:q(`-ml-2 h-7 min-w-0 flex-1 rounded-md border border-transparent bg-transparent px-2 text-sm text-text`,`transition-colors duration-(--dur-1) ease-app placeholder:text-text-disabled`,`hover:border-border focus:border-accent focus:bg-surface-inset`),value:n,onChange:e=>r(e.target.value),onBlur:()=>n.trim()!==e.note.trim()&&t(n),onKeyDown:e=>e.key===`Enter`&&e.currentTarget.blur()})}function l5({customModels:e,writes:t}){let[n,r]=(0,L.useState)(``),[i,a]=(0,L.useState)(``),[o,s]=(0,L.useState)(``),c=()=>{let c=Up(n,i,o);if(`error`in c){t.refuse(r5,c.error);return}t.save(r5,`models`,Zu(e,[c.entry])),r(``),a(``),s(``)},l=e=>{e.key===`Enter`&&c()};return(0,R.jsxs)(`div`,{className:`pt-3`,children:[(0,R.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_132px_minmax(0,1.2fr)_auto] items-center gap-2`,children:[(0,R.jsx)(DA,{mono:!0,"aria-label":`New model id`,placeholder:`Model id, e.g. claude-opus-5[1m]`,value:n,onChange:e=>r(e.target.value),onKeyDown:l}),(0,R.jsxs)(Q0,{value:i,onValueChange:a,children:[(0,R.jsx)(n2,{"aria-label":`Runtime (required)`,className:q(e2,`w-full`,i===``&&`text-text-tertiary`),children:(0,R.jsx)(r2,{})}),(0,R.jsxs)(i2,{children:[(0,R.jsx)(c2,{value:``,children:`Runs on…`}),Wu.map(e=>(0,R.jsx)(c2,{value:e,children:Rp[e]},e))]})]}),(0,R.jsx)(DA,{"aria-label":`New model note`,placeholder:`Use-case note (optional)`,value:o,onChange:e=>s(e.target.value),onKeyDown:l}),(0,R.jsx)(Y,{icon:(0,R.jsx)(yy,{}),onClick:c,children:`Add model`})]}),(0,R.jsx)(u5,{writes:t,cell:r5,className:`pt-1.5`})]})}function u5({writes:e,cell:t,className:n=`pr-2 pb-2.5 pl-8`}){return e.error?.cell===t?(0,R.jsx)(`p`,{role:`alert`,className:q(`m-0 text-xs text-danger`,n),children:e.error.message}):null}function d5({runtime:e}){let t=e===`codex`?Hy:Vy;return(0,R.jsx)(`span`,{role:`img`,"aria-label":Rp[e],title:Rp[e],className:`inline-flex size-4 shrink-0 items-center justify-center text-icon`,children:(0,R.jsx)(t,{size:14})})}function f5({groups:e}){return(0,R.jsx)(R.Fragment,{children:e.map(e=>(0,R.jsxs)(a2,{children:[(0,R.jsx)(o2,{children:e.label}),e.entries.map(e=>(0,R.jsx)(c2,{value:e.id,title:e.note,children:e.note?`${e.id} — ${e.note}`:e.id},e.id))]},e.runtime))})}var p5=[{group:`sessions`,title:`Sessions`,caption:`Interactive — you are in the terminal`},{group:`unattended`,title:`Unattended`,caption:`Burns and scripted runs`}],m5=`grid grid-cols-[minmax(0,1fr)_260px_24px] items-center gap-3`;function h5({rows:e,groups:t,defaultModel:n,projectModel:r,filter:i,writes:a}){return(0,R.jsxs)(R.Fragment,{children:[r&&(0,R.jsxs)(`p`,{className:`m-0 mt-3 flex items-center gap-2 text-xs text-text-secondary`,children:[(0,R.jsx)(tA,{tone:`warning`}),(0,R.jsxs)(`span`,{children:[`This project runs everything on `,(0,R.jsx)(`span`,{className:`font-mono`,children:r}),` — these apply to other projects.`]})]}),p5.map(({group:r,title:o,caption:s})=>{let c=e.filter(e=>e.group===r&&R8(i,Yp(e.step)));return c.length===0?null:(0,R.jsxs)(L.Fragment,{children:[(0,R.jsxs)(`div`,{className:q(m5,t5,`mt-4`),children:[(0,R.jsxs)(`span`,{children:[o,(0,R.jsx)(`span`,{className:`ml-2 font-normal text-text-disabled`,children:s})]}),(0,R.jsx)(`span`,{children:`Model`}),(0,R.jsx)(`span`,{})]}),c.map(e=>(0,R.jsx)(g5,{row:e,groups:t,defaultModel:n,writes:a},e.step))]},r)})]})}function g5({row:e,groups:t,defaultModel:n,writes:r}){let i=Yp(e.step),a=e.value!==null;return(0,R.jsxs)(`div`,{className:`group border-b border-border-subtle transition-colors duration-(--dur-1) ease-app hover:bg-surface-hover`,children:[(0,R.jsxs)(`div`,{className:q(m5,`min-h-12 px-2 py-1.5`),children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,R.jsxs)(`span`,{className:`flex items-center gap-2 text-sm text-text`,children:[e.label,r.saved===i&&(0,R.jsx)(W8,{})]}),(0,R.jsx)(`span`,{className:`truncate text-xs text-text-tertiary`,title:e.description,children:e.description})]}),(0,R.jsxs)(Q0,{value:e.value??``,onValueChange:e=>r.save(i,i,e===``?null:e),children:[(0,R.jsx)(n2,{"aria-label":`Model for ${e.label}`,className:q(e2,`w-full`,!a&&`text-text-tertiary`),children:(0,R.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 [&>span:last-child]:truncate`,children:[(0,R.jsx)(d5,{runtime:e.effectiveRuntime}),(0,R.jsx)(r2,{})]})}),(0,R.jsxs)(i2,{children:[(0,R.jsxs)(c2,{value:``,children:[`Default (`,n,`)`]}),(0,R.jsx)(f5,{groups:t})]})]}),a?(0,R.jsx)(nE,{label:`Reset ${e.label} to default`,size:`sm`,icon:(0,R.jsx)(Cy,{}),onClick:()=>r.save(i,i,null),className:i5}):(0,R.jsx)(`span`,{})]}),(0,R.jsx)(u5,{writes:r,cell:i,className:`px-2 pb-2.5`})]})}var _5=1400,v5=`model`;function y5(){let e=B.useUtils(),[t,n]=(0,L.useState)(null),[r,i]=(0,L.useState)(null),a=(0,L.useRef)([]),o=(0,L.useRef)(null),s=(0,L.useRef)(void 0);(0,L.useEffect)(()=>()=>clearTimeout(s.current),[]);let c=()=>{let e=a.current.shift();if(!e){o.current=null;return}o.current=e.cell,l.mutate({key:e.key,value:e.value})},l=B.settings.update.useMutation({onSuccess:()=>{n(o.current),clearTimeout(s.current),s.current=setTimeout(()=>n(null),_5),e.settings.get.invalidate(),c()},onError:e=>{let t=o.current;t&&i({cell:t,message:e.message}),a.current=[],o.current=null}}),u=e=>i(t=>t&&t.cell===e?null:t);return{saved:t,error:r,save:(e,t,n)=>{u(e),a.current.push({cell:e,key:t,value:n}),o.current===null&&c()},refuse:(e,t)=>i({cell:e,message:t})}}function b5({globals:e,scoped:t,filter:n,highlightField:r}){let i=y5();if(e.isLoading)return(0,R.jsx)(WA,{children:`Loading settings…`});if(e.error)return(0,R.jsxs)(WA,{children:[`Could not load settings: `,e.error.message]});if(!e.data)return null;let a=e.data,o=bm(a),s=wm(a),c=Hp(Vp(a)),l=hm(a),u=new Map(s.map(e=>[e.step,e.label]));return(0,R.jsxs)(R.Fragment,{children:[R8(n,`model`)&&(0,R.jsx)(`div`,{className:`-mt-3.5`,children:(0,R.jsx)(C5,{value:l,groups:c,writes:i,highlight:r===`model`})}),o.some(e=>R8(n,e.id))&&(0,R.jsxs)(V8,{title:`Roster`,action:(0,R.jsx)(S5,{}),description:(0,R.jsxs)(R.Fragment,{children:[`A model with a `,(0,R.jsx)(`span`,{className:`text-text-secondary`,children:`use-case note`}),` is offered to the tickets agent, which may pick it per ticket; models without a note are never picked automatically.`]}),children:[(0,R.jsx)(x5,{view:a}),(0,R.jsx)(a5,{rows:o,stepLabels:u,customModels:Bp(a),filter:n,writes:i})]}),s.some(e=>R8(n,Yp(e.step)))&&(0,R.jsx)(V8,{title:`Per step`,description:`Every step runs the default unless it names a model of its own.`,children:(0,R.jsx)(h5,{rows:s,groups:c,defaultModel:l,projectModel:Tm(t.data),filter:n,writes:i})})]})}function x5({view:e}){return(0,R.jsx)(`ul`,{"aria-label":`Model discovery`,className:`m-0 mt-1.5 flex list-none flex-wrap gap-x-5 gap-y-1 p-0 text-xs`,children:Cm(e).map(e=>(0,R.jsxs)(`li`,{className:q(`inline-flex items-center gap-1.5`,e.failed?`text-warning`:`text-text-tertiary`),children:[(0,R.jsx)(d5,{runtime:e.runtime}),e.text]},e.runtime))})}function S5(){let e=B.useUtils(),t=B.settings.refreshModels.useMutation({onSuccess:()=>void e.settings.get.invalidate()});return(0,R.jsxs)(R.Fragment,{children:[t.error&&(0,R.jsxs)(`span`,{role:`alert`,className:`text-xs text-danger`,children:[`Refresh failed: `,t.error.message]}),(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(ab,{}),loading:t.isPending,onClick:()=>t.mutate(),children:t.isPending?`Refreshing…`:`Refresh`})]})}function C5({value:e,groups:t,writes:n,highlight:r}){let{ref:i,flash:a}=L8(r);return(0,R.jsx)(H8,{rowRef:i,flash:a,label:`Default model`,htmlFor:`settings-default-model`,description:`Runs every step that has no model of its own below — and every project that has not set one.`,aside:n.saved===v5&&(0,R.jsx)(W8,{}),control:(0,R.jsxs)(Q0,{value:e,onValueChange:e=>n.save(v5,`model`,e),children:[(0,R.jsx)(n2,{id:`settings-default-model`,className:q(e2,`w-full`),children:(0,R.jsx)(r2,{})}),(0,R.jsx)(i2,{children:(0,R.jsx)(f5,{groups:t})})]}),below:(0,R.jsx)(u5,{writes:n,cell:v5,className:``})})}function w5({projectId:e,filter:t,highlightField:n,onDismiss:r}){let i=B.useUtils(),a=B.setup.doctor.useQuery(e?{projectId:e}:void 0,{refetchOnWindowFocus:!1}),o=a.data,s=e=>o?.results.find(t=>t.id===e),c=s(`container-runtime`),l=s(`sandcastle-image`),u=k8(o?.results??[]),[d,f]=(0,L.useState)(0),p=()=>{f(e=>e+1),i.setup.doctor.cancel().then(()=>a.refetch())},m=k5(a.isLoading,d),h=e=>!t||R8(t,e),g=m?D5:`checking prerequisites…`,_=a.error?.message??(m?O5:null),v=N8([...c?[{field:`container-runtime`,ok:c.status===`ok`}]:[],...l?[{field:`sandcastle-image`,ok:T5(l)}]:[],...u.map(e=>({field:A8(e.runtime),ok:e.probe.status===`ok`}))].map(({field:e,ok:t})=>({ok:t,reason:A5[e].reason??A5[e].label}))),y=e=>({field:e,label:A5[e].label,visible:h(e),highlight:n===e}),b=o!==void 0&&v.count===null;return(0,R.jsxs)(`section`,{"aria-label":`Unattended burn prerequisites`,className:`flex flex-col`,children:[(0,R.jsxs)(`div`,{className:`flex items-start gap-3 pb-3`,children:[(0,R.jsx)(`span`,{"aria-hidden":!0,className:q(`mt-0.5 inline-flex size-7 shrink-0 items-center justify-center rounded-md bg-surface-hover [&>svg]:size-4`,b?`text-success`:`text-icon`),children:b?(0,R.jsx)(by,{}):(0,R.jsx)(Py,{})}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`div`,{className:`flex min-h-7 items-center gap-2 text-sm font-medium text-text`,children:a.isLoading?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(aE,{}),(0,R.jsx)(`span`,{className:`font-normal text-text-secondary`,children:g})]}):a.error?`Could not run the checks`:(0,R.jsxs)(`span`,{className:`min-w-0`,children:[v.count&&(0,R.jsxs)(`span`,{className:`tabular-nums`,children:[v.count,` `]}),v.text]})}),!r&&(0,R.jsx)(`p`,{className:`m-0 text-xs text-pretty text-text-tertiary`,children:`A burn you walk away from runs its tickets in containers, so it needs what an interactive session never does. Fix any of these now, or leave them for later.`})]}),r&&(0,R.jsx)(Y,{variant:`ghost`,className:`shrink-0`,onClick:r,children:`Set up later`})]}),_&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2.5 py-2 pl-10`,children:[(0,R.jsx)(tA,{tone:`warning`}),(0,R.jsx)(`span`,{className:`min-w-0 grow text-xs text-text-secondary`,children:_}),(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(ab,{}),onClick:p,children:`Retry`})]}),o&&(0,R.jsxs)(M5,{children:[(0,R.jsx)(P5,{...y(`container-runtime`),probe:c,onRecheck:p}),(0,R.jsx)(F5,{...y(`sandcastle-image`),probe:l,runtimeOk:c?.status===`ok`,projectId:e,onDone:p}),u.map(e=>e.kind===`token`?(0,R.jsx)(V5,{...y(A8(e.runtime)),probe:e.probe,onDone:p},e.runtime):(0,R.jsx)(H5,{...y(A8(e.runtime)),row:e,onDone:p},e.runtime)),e&&(0,R.jsx)(z5,{...y(`burn-cache`),projectId:e})]})]})}function T5(e){return e.status===`ok`||e.severity===`info`}var E5=1e4,D5=`still checking — this is taking longer than usual`,O5=`The container runtime has not answered yet. A runtime that is starting up — or wedged — can leave the checks outstanding for minutes.`;function k5(e,t){let[n,r]=(0,L.useState)(!1);return(0,L.useEffect)(()=>{if(r(!1),!e)return;let t=setTimeout(()=>r(!0),E5);return()=>clearTimeout(t)},[e,t]),n}var A5=Object.fromEntries(M8.map(e=>[e.field,e]));function j5({field:e,label:t,visible:n=!0,highlight:r=!1,detail:i,ok:a,status:o,children:s,below:c}){let{ref:l,flash:u}=L8(r);return n?(0,R.jsxs)(`li`,{ref:l,...e?{"data-field":e}:{},className:q(`grid grid-cols-[28px_minmax(0,1fr)_auto] items-start gap-x-3 gap-y-2.5 py-3 [counter-increment:checklist]`,`border-t border-border-subtle first:border-t-0`,u&&`rounded-md outline-2 outline-offset-4 outline-accent`),children:[(0,R.jsx)(`span`,{"aria-hidden":!0,className:`flex h-5 items-center justify-center text-xs text-text-tertiary tabular-nums before:content-[counter(checklist)]`}),(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsxs)(`div`,{className:`flex min-h-5 flex-wrap items-center gap-x-3 gap-y-0.5`,children:[(0,R.jsx)(`span`,{className:`text-sm font-medium text-text`,children:t}),a?(0,R.jsx)(rA,{tone:`success`,icon:(0,R.jsx)(by,{}),children:o??`Ready`}):(0,R.jsx)(rA,{tone:`warning`,children:o??`Needed`})]}),(0,R.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-xs text-text-tertiary`,title:i,children:i})]}),(0,R.jsx)(`div`,{className:`flex max-w-96 flex-wrap items-center justify-end gap-2`,children:s}),c]}):null}function M5({children:e}){return(0,R.jsx)(`ol`,{className:`m-0 list-none border-t border-border-subtle p-0 [counter-reset:checklist]`,children:e})}function N5({sessionId:e,label:t,onDone:n,onEnded:r}){return(0,R.jsxs)(`div`,{className:`col-span-full flex flex-col gap-2`,children:[(0,R.jsx)(`div`,{className:`h-70 overflow-hidden rounded-md border border-border bg-surface-inset animate-rise-in`,children:(0,R.jsx)(LG,{label:t,children:(0,R.jsx)(_1,{sessionId:e,onEnded:r})})}),n&&(0,R.jsx)(`div`,{className:`flex justify-end`,children:(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(ab,{}),onClick:n,children:`Done — re-check`})})]})}function P5({probe:e,onRecheck:t,...n}){let r=B.setup.runtimeGuide.useQuery(void 0,{enabled:e?.status===`missing`,refetchOnWindowFocus:!1}),i=Ab();if(!e)return null;let a=e.status===`missing`?r.data:void 0,o=a?.command??e.fix??``,s=e.status===`ok`;return(0,R.jsxs)(j5,{...n,detail:e.detail,ok:s,children:[!s&&o&&(0,R.jsx)(R.Fragment,{children:(0,R.jsx)(U5,{command:o,onCopy:()=>{navigator.clipboard?.writeText(o),i.push(`copied`,`info`)}})}),!s&&a?.note&&(0,R.jsx)(`span`,{className:`basis-full text-right text-xs text-text-tertiary`,children:a.note}),!s&&(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(ab,{}),onClick:t,children:`Re-check`})]})}function F5({probe:e,runtimeOk:t,projectId:n,onDone:r,...i}){let[a,o]=(0,L.useState)(null),s=Ab(),c=B.setup.imageBuildTarget.useQuery(n?{projectId:n}:void 0),l=B.setup.startTerminal.useMutation({onSuccess:({sessionId:e,notices:t})=>{o(e);for(let e of t)s.push(e)},onError:e=>s.push(e.message)});return e?(0,R.jsx)(j5,{...i,detail:e.detail,ok:T5(e),below:a&&(0,R.jsx)(N5,{sessionId:a,label:`build-image`,onEnded:r,onDone:()=>{o(null),r()}}),children:!a&&(0,R.jsx)(L5,{probe:e,target:I5(c),runtimeOk:t,pending:l.isPending,onStart:()=>l.mutate({kind:`build-image`,...n?{projectId:n}:{}})})}):null}function I5(e){let{data:t}=e;return t?t.kind===`refused`?{kind:`refused`,reason:t.reason}:{kind:`ready`,dockerfile:t.dockerfile,tag:t.tag}:e.error?{kind:`error`,message:e.error.message}:{kind:`loading`}}function L5({probe:e,target:t,runtimeOk:n,pending:r,onStart:i}){if(e.status===`custom`)return(0,R.jsx)(`span`,{className:`basis-full text-right text-xs text-text-tertiary`,children:e.fix});if(t.kind===`refused`)return(0,R.jsx)(`span`,{className:`basis-full text-right text-xs text-text-tertiary`,children:t.reason});let a=e.status===`missing`||e.status===`not-built-yet`?`Build`:`Rebuild`,o=r?`Starting…`:t.kind===`ready`?`${a} image · ${t.tag}`:t.kind===`loading`?`${a} image · resolving…`:`${a} image`;return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(Y,{variant:`secondary`,size:`sm`,icon:(0,R.jsx)(Ny,{}),"aria-label":`${a} image`,disabled:!n||r||t.kind!==`ready`,title:n?t.kind===`ready`?`Dockerfile: ${t.dockerfile}\nImage: ${t.tag}`:void 0:`Install a container runtime first`,onClick:i,children:o}),t.kind===`error`&&(0,R.jsx)(`span`,{className:`basis-full text-right text-xs text-warning`,children:t.message})]})}function R5({status:e,pending:t,refusal:n,onClear:r,...i}){return e?.mode===`volume`?(0,R.jsxs)(j5,{field:A5[`burn-cache`].field,label:A5[`burn-cache`].label,...i,ok:!0,detail:`${e.volumeName} — ${e.sizeBytes===null?`empty`:dh(e.sizeBytes)}`,children:[(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(Sy,{}),disabled:t,onClick:r,children:t?`Clearing…`:`Clear`}),n&&(0,R.jsx)(`span`,{className:`basis-full text-right text-xs text-warning`,children:n})]}):null}function z5({projectId:e,...t}){let n=B.useUtils(),[r,i]=(0,L.useState)(null),a=B.system.burnCache.status.useQuery({projectId:e},{refetchOnWindowFocus:!1}),o=B.system.burnCache.clear.useMutation({onSuccess:()=>{i(null),n.system.burnCache.status.invalidate()},onError:e=>i(e.message)});return(0,R.jsx)(R5,{...t,status:a.data,pending:o.isPending,refusal:r,onClear:()=>o.mutate({projectId:e})})}var B5={"claude-code":{mint:{kind:`setup-token`,label:`Run claude setup-token`},placeholder:`paste sk-ant-oat01-…`}};function V5({probe:e,onDone:t,...n}){let[r,i]=(0,L.useState)(null),[a,o]=(0,L.useState)(``),[s,c]=(0,L.useState)(null),l=Ab(),u=B.setup.startTerminal.useMutation({onSuccess:({sessionId:e})=>i(e),onError:e=>l.push(e.message)}),d=B.setup.afkToken.useMutation({onSuccess:e=>{c(e),e.valid&&t()},onError:e=>l.push(e.message)});if(!e?.runtime)return null;let f=e.runtime,p=B5[f];return p?(0,R.jsxs)(j5,{...n,detail:e.detail,ok:e.status===`ok`,below:r&&(0,R.jsx)(N5,{sessionId:r,label:`setup-token`}),children:[p.mint&&!r&&(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(Dy,{}),onClick:()=>p.mint&&u.mutate({kind:p.mint.kind}),disabled:u.isPending,children:u.isPending?`Starting…`:p.mint.label}),(0,R.jsx)(DA,{"aria-label":n.label,mono:!0,className:`w-52`,value:a,onChange:e=>o(e.target.value),placeholder:p.placeholder,spellCheck:!1,autoComplete:`off`}),(0,R.jsx)(Y,{variant:`primary`,disabled:a.trim()===``||d.isPending,onClick:()=>d.mutate({token:a,runtime:f}),children:d.isPending?`Verifying…`:`Save & verify`}),s&&(0,R.jsxs)(`span`,{className:`basis-full text-right text-xs`,children:[(0,R.jsx)(rA,{tone:s.valid?`success`:`warning`,icon:s.valid?(0,R.jsx)(by,{}):(0,R.jsx)(tb,{}),children:s.detail}),s.fix&&(0,R.jsx)(`span`,{className:`mt-0.5 block text-text-tertiary`,children:s.fix})]})]}):null}function H5({row:e,onDone:t,...n}){let[r,i]=(0,L.useState)(null),a=Ab(),o=B.setup.startTerminal.useMutation({onSuccess:({sessionId:e})=>i(e),onError:e=>a.push(e.message)}),s=Im[e.runtime],c=e.probe.status===`ok`;return(0,R.jsx)(j5,{...n,ok:c,status:c?`Signed in`:`Not signed in`,detail:e.probe.detail,below:r&&(0,R.jsx)(N5,{sessionId:r,label:s.kind,onDone:()=>{i(null),t()}}),children:!c&&!r&&(0,R.jsx)(Y,{variant:`secondary`,size:`sm`,icon:(0,R.jsx)(ob,{}),disabled:o.isPending,onClick:()=>o.mutate({kind:s.kind}),children:o.isPending?`Starting…`:`Sign in`})})}function U5({command:e,onCopy:t}){return(0,R.jsxs)(`span`,{className:`inline-flex max-w-full min-w-0 items-center gap-1 rounded-md bg-surface-inset py-0.5 pr-0.5 pl-2`,children:[(0,R.jsx)(`code`,{className:`min-w-0 truncate font-mono text-xs text-text-secondary`,title:e,children:e}),(0,R.jsx)(nE,{label:`Copy`,size:`sm`,icon:(0,R.jsx)(Jy,{}),onClick:t})]})}function W5({globals:e,projectId:t,filter:n,highlightField:r}){return e.isLoading?(0,R.jsx)(WA,{children:`Loading settings…`}):e.error?(0,R.jsxs)(WA,{children:[`Could not load settings: `,e.error.message]}):e.data?(0,R.jsxs)(R.Fragment,{children:[M8.some(e=>R8(n,e.field))&&(0,R.jsx)(V8,{title:`Prerequisites for unattended burns`,children:(0,R.jsx)(w5,{projectId:t,filter:n,highlightField:r})}),(0,R.jsx)(B8,{title:`Width & retries`,rows:pm(e.data,`burns`),filter:n,highlightField:r})]}):null}var G5={prep:`established by preparation`,session:`established in a conversation on this machine`,human:`set by you`,build:`built by runcastle from this repo's own Dockerfile`};function K5({source:e,evidence:t,onClose:n}){let r=(0,L.useRef)(null);return(0,L.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.stopPropagation(),n())},t=e=>{let t=r.current?.parentElement;e.target instanceof Node&&t?.contains(e.target)||n()};return window.addEventListener(`keydown`,e,!0),window.addEventListener(`mousedown`,t),()=>{window.removeEventListener(`keydown`,e,!0),window.removeEventListener(`mousedown`,t)}},[n]),(0,R.jsxs)(`div`,{ref:r,className:`absolute top-7 left-0 z-10 max-h-72 w-105 overflow-auto rounded-lg bg-surface-raised px-3.5 py-3 shadow-popover animate-pop-in`,children:[(0,R.jsxs)(`h4`,{className:`m-0 mb-2 text-xs font-medium text-text-tertiary`,children:[`Evidence · `,G5[e]]}),(0,R.jsx)(`pre`,{className:`m-0 font-mono text-xs leading-[18px] whitespace-pre-wrap text-text-secondary`,children:t})]})}var q5=[{group:`model`,title:`Model & sandbox`},{group:`commands`,title:`Commands`},{group:`chat`,title:`Project chat`}];function J5({scoped:e,projectId:t,filter:n,highlightField:r}){let i=B.project.prep.useQuery({projectId:t}),[a,o]=(0,L.useState)(null);if(e.isLoading)return(0,R.jsx)(WA,{children:`Loading settings…`});if(e.error)return(0,R.jsxs)(WA,{children:[`Could not load settings: `,e.error.message]});if(!e.data)return null;let s=i.data?.findings??[],c=new Map(s.map(e=>[e.key,e])),l=pm(e.data,`project`,s),u=e=>{let t=c.get(e.key);return a!==e.key||!t?.evidence?null:(0,R.jsx)(K5,{source:t.source,evidence:t.evidence,onClose:()=>o(null)})};return(0,R.jsx)(R.Fragment,{children:q5.map(({group:e,title:i})=>(0,R.jsx)(B8,{title:i,rows:l.filter(t=>t.group===e),projectId:t,filter:n,highlightField:r,onOpenEvidence:e=>o(t=>t===e?null:e),evidence:u},e))})}var Y5={general:`How runcastle looks, where its server listens, and how sessions are sandboxed.`,models:`The default model, the roster this machine offers, and which model runs each step.`,burns:`What an unattended run needs before it starts, and how hard it tries once it does.`,project:`Values this project sets for itself. Unset fields inherit the global value, shown as ghost text.`},X5={general:Q8,models:b5,burns:W5,project:J5};function Z5({projectId:e,projectName:t,location:n,onClose:r}){let i=B.settings.get.useQuery(),a=B.settings.get.useQuery({projectId:e}),[o,s]=(0,L.useState)(n.page),[c,l]=(0,L.useState)(``),u=(0,L.useRef)(null),d=(0,L.useMemo)(()=>Om(c,$5(i.data,a.data)),[c,i.data,a.data]),f={query:c,...d},p=c.trim()!==``;(0,L.useEffect)(()=>{if(!p||d.counts[o]>0)return;let e=P8.find(e=>d.counts[e.page]>0);e&&s(e.page)},[p,d,o]);let m=e=>{!(e.metaKey||e.ctrlKey)||e.key.toLowerCase()!==`f`||(e.preventDefault(),u.current?.focus(),u.current?.select())},h=X5[o],g=P8.find(e=>e.page===o)?.label??``,_=p&&d.matches.size===0;return(0,R.jsx)(QA,{open:!0,onClose:r,size:`xl`,label:`Settings`,className:`overflow-hidden`,children:(0,R.jsxs)(`div`,{className:`relative grid h-[min(720px,84vh)] grid-cols-[208px_minmax(0,1fr)]`,onKeyDown:m,children:[(0,R.jsx)(F8,{page:o,filter:f,filterRef:u,projectName:t,onFilter:l,onSelect:s}),(0,R.jsx)(`section`,{className:`grid min-h-0 min-w-0 grid-rows-[minmax(0,1fr)] bg-surface`,children:(0,R.jsx)(`div`,{className:`min-h-0 overflow-x-hidden overflow-y-auto px-8 pt-9 pb-12`,children:(0,R.jsxs)(`div`,{className:`animate-rise-in`,children:[(0,R.jsxs)(`header`,{className:`mb-8`,children:[(0,R.jsx)(`h2`,{className:`m-0 text-lg font-semibold text-text`,children:g}),(0,R.jsx)(`p`,{className:`mt-1 mb-0 text-sm text-text-tertiary`,children:Y5[o]})]}),(0,R.jsx)(`div`,{children:(0,R.jsx)(h,{globals:i,scoped:a,projectId:e,filter:f,...o===n.page&&n.field?{highlightField:n.field}:{}})}),_&&(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(py,{}),title:`Nothing matches`,hint:`Try “model”, “verify” or “image”.`})]},o)})}),(0,R.jsx)(nE,{label:`Close`,kbd:`Esc`,size:`sm`,icon:(0,R.jsx)(xy,{}),onClick:r,className:`absolute top-3 right-3`})]})})}var Q5={id:X8,page:`general`,terms:[`Theme`,`Appearance`,`Dark`,`Light`,`System`]};function $5(e,t){let n=P8.flatMap(({page:n})=>{let r=n===`project`?t:e;return r?Dm(r,n):[]}),r=M8.map(e=>({id:e.field,page:`burns`,terms:[e.label,...e.terms]}));return[Q5,...n,...r]}function e7({projectId:e,nav:t}){let n=pg(e),{selectedFeatureId:r,projectSelected:i,preparing:a,select:o,selectProject:s,startPreparation:c,setCmdk:l}=n,[u,d]=(0,L.useState)(null),[f,p]=(0,L.useState)(0),[m,h]=(0,L.useState)(!1),[g,_]=(0,L.useState)(0),v=()=>{h(!0),_(e=>e+1)},[y,b]=(0,L.useState)(0),x=()=>{s(),b(e=>e+1)},S=()=>b(0),[C,w]=(0,L.useState)(0),T=()=>{s(),w(e=>e+1)},E=()=>w(0),D=qP(),O=B.feature.list.useQuery({projectId:e},{refetchInterval:eh()}),k=jb(e),A=B.project.prep.useQuery({projectId:e}),j=A.data?.prepared??!0,M=A.data?.empty??!0,N=B.feature.driveInfo.useQuery(void 0,{refetchInterval:eh()}).data,P=Pb(N,e)?N:null,F=O.data,[ee,te]=(0,L.useState)(!1),[ne]=(0,L.useState)(()=>Uh(Kh()));(0,L.useEffect)(()=>{if(ee||!F)return;let t=Wh(ne,e);if(t?.kind===`chat`)s();else if(t?.kind===`prepare`)c();else if(t){let e=F.find(e=>e.slug===t.featureSlug);o(e?.id??Sh(F)?.id??null)}else if(!r&&!i&&!a){let e=Sh(F);e&&o(e.id)}te(!0)},[ee,F,e,ne,r,i,a,o,s,c]);let I=F?.find(e=>e.id===r)?.slug??null;Yh(ee&&!n.creating?Gh({projectId:e,preparing:a,projectSelected:i,featureSlug:I}):null,t=>{if(!t||Bh(t)!==e)return;let n=Wh(t,e);if(!n)o(null);else if(n.kind===`chat`)s();else if(n.kind===`prepare`)c();else{let e=F?.find(e=>e.slug===n.featureSlug);o(e?.id??Sh(F??[])?.id??null)}});let re=()=>{s(),k.session?p(e=>e+1):k.start()};(0,L.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`k`?(e.preventDefault(),l(!0)):Nb(e)&&(e.preventDefault(),v())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l]);let ie=ay({...n,featureCount:F?.length??0,prepared:j,empty:M}),ae=F?.find(e=>e.id===r)?.phase,oe=sg(n.inspectorPreference,n.viewedPhase??ae),se=oy(ie,oe),ce=ie===`feature`?()=>n.toggleInspector(oe):void 0,le=ie===`create`?(0,R.jsx)(`section`,{className:`relative flex min-h-0 min-w-0 flex-col`,children:(0,R.jsx)(p8,{projectId:e,onCancel:n.cancelCreate,onCreated:n.select})}):ie===`prepare`?(0,R.jsx)(h8,{projectId:e,...n.preparing?{onClose:n.closePreparation}:{}}):ie===`project`?(0,R.jsx)(l8,{projectId:e,talk:k,newChatRequest:f,onConsumeNewChatRequest:()=>p(0),inboxRequest:y,onConsumeInboxRequest:S,empty:M,onOpenPreparation:n.startPreparation,driveRequest:C,onConsumeDriveRequest:E}):ie===`feature`&&r?(0,R.jsx)(LG,{label:`feature view`,fallback:e=>(0,R.jsx)(_6,{featureId:r,error:e}),children:(0,R.jsx)(N6,{featureId:r,viewedPhase:n.viewedPhase,onViewPhase:n.viewPhase,guidance:n.guidance,mapRailCollapsed:n.mapRailCollapsed,onToggleMapRail:n.toggleMapRail,artifactPaneCollapsed:n.artifactPaneCollapsed,onToggleArtifactPane:n.toggleArtifactPane,chatPanelOpen:n.chatPanelOpen,onToggleChatPanel:n.toggleChatPanel,driving:u,onDriveChange:d,detailsOpen:se,onToggleDetails:()=>n.toggleInspector(oe),onDeleted:()=>{n.select(null),n.selectProject()}})},`ws-${r}`):null,ue=(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(YP,{sidebar:(0,R.jsx)(QP,{projectId:e,nav:t,view:ie,selectedFeatureId:n.selectedFeatureId,talk:k,onSelect:n.select,onSelectProject:n.selectProject,onNewChat:re,onDraft:n.startDraft,onOpenPreparation:n.startPreparation,onOpenNote:v,onOpenCmdk:()=>l(!0),onOpenSettings:()=>n.openSettings(),projectDriveBranch:P?.branch??null,onOpenProjectDrive:T,driving:u,onDriveChange:d}),rail:(0,R.jsx)(fF,{onOpenCmdk:()=>l(!0),onNewChat:re}),children:(0,R.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col [&>*]:min-h-0 [&>*]:flex-1`,children:le})}),(0,R.jsx)(w8,{open:n.cmdkOpen,onClose:()=>n.setCmdk(!1),features:F??[],selectedFeatureId:n.selectedFeatureId,onSelect:n.select,onOpenSettings:()=>n.openSettings(),onOpenPreparation:n.startPreparation,onOpenProjectChat:n.selectProject,onOpenNote:v,onToggleSidebar:D.toggleSidebar,onToggleDetails:ce,nav:t}),(0,R.jsx)(D8,{projectId:e,projectName:t.currentProject?.name??``,open:m,openRequest:g,onClose:()=>h(!1),onOpenInbox:x}),n.settings&&(0,R.jsx)(Z5,{projectId:e,projectName:t.currentProject?.name??``,location:n.settings,onClose:n.closeSettings})]});return(0,R.jsx)(f2,{open:n.openSettings,children:ue})}var t7=`${wA} h-7 w-full font-medium`,n7=`A run is in flight — it has to finish before this project can go.`;function r7({project:e,stats:t,loading:n,onOpen:r,index:i}){let a=Ab(),o=B.useUtils(),[s,c]=(0,L.useState)(!1),[l,u]=(0,L.useState)(!1),[d,f]=(0,L.useState)(e.name),p=B.project.rename.useMutation({onSuccess:async()=>{await o.project.list.invalidate(),c(!1)},onError:e=>a.push(e.message)}),m=B.project.close.useMutation({onSuccess:async()=>{await o.project.list.invalidate(),a.push(`removed ${e.name}`,`info`)},onError:e=>a.push(e.message)});(0,L.useEffect)(()=>{if(!l)return;let e=e=>{e.key===`Escape`&&u(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l]);let h=t.activeRuns>0,g=()=>{let t=d.trim();t&&t!==e.name?p.mutate({projectId:e.id,name:t}):c(!1)},_=s?(0,R.jsx)(`input`,{className:t7,value:d,"aria-label":`Project name`,maxLength:80,autoFocus:!0,onChange:e=>f(e.target.value),onKeyDown:t=>{t.stopPropagation(),t.key===`Enter`&&g(),t.key===`Escape`&&(f(e.name),c(!1))},onBlur:g}):(0,R.jsx)(`span`,{className:`block truncate font-medium`,children:e.name});return l?(0,R.jsx)(vA,{className:`animate-fade-in`,wrap:!0,title:(0,R.jsxs)(`span`,{className:`text-text-secondary`,children:[`Remove `,(0,R.jsx)(`span`,{className:`font-medium text-text`,children:e.name}),`? The repo on disk is untouched.`,h&&(0,R.jsx)(`span`,{className:`block text-xs text-text-tertiary`,children:n7})]}),control:(0,R.jsxs)(`span`,{className:`flex shrink-0 gap-2 pr-3`,children:[(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>u(!1),children:`Cancel`}),(0,R.jsx)(Y,{size:`sm`,variant:`danger`,icon:(0,R.jsx)(Sy,{}),disabled:h||m.isPending,onClick:()=>m.mutate({projectId:e.id}),children:m.isPending?`Removing…`:`Remove`})]})}):(0,R.jsx)(vA,{index:i,leading:(0,R.jsx)(My,{}),title:_,description:(0,R.jsx)(`span`,{className:`block truncate text-left font-mono`,dir:`rtl`,title:e.repoPath,children:(0,R.jsx)(`bdi`,{children:e.repoPath})}),meta:n?`Loading…`:(0,R.jsx)(xA,{className:`flex-nowrap`,items:[{strong:t.total,text:t.total===1?`feature`:`features`},t.activeRuns>0&&{tone:`live`,strong:t.activeRuns,text:`running`},t.needsYou>0&&{tone:`warning`,strong:t.needsYou,text:`needs you`}]}),onClick:s?void 0:r,tooltip:`Open ${e.name}`,actionsOverlay:!0,actions:!s&&(0,R.jsx)(IP,{label:`${e.name} actions`,actions:[{key:`rename`,label:`Rename`,onSelect:()=>{f(e.name),c(!0)}},{key:`remove`,label:`Remove from list`,danger:!0,onSelect:()=>u(!0)}]})})}function i7({nav:e}){let t=e.projects??[],n=eh(),r=B.useQueries(e=>t.map(t=>e.feature.list({projectId:t.id},{refetchInterval:n}))),i=t.map((e,t)=>Ah(r[t]?.data??[])),a=i.reduce((e,t)=>e+t.activeRuns,0),o=i.reduce((e,t)=>e+t.needsYou,0);return(0,R.jsx)(YP,{sidebar:(0,R.jsx)(a7,{nav:e}),children:(0,R.jsxs)(`section`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,R.jsx)(MA,{crumbs:[{label:`Projects`,icon:(0,R.jsx)(Qy,{})}]}),(0,R.jsxs)(PA,{routeKey:`portfolio`,children:[(0,R.jsx)(FA,{title:`Projects`,meta:[{strong:t.length,text:t.length===1?`project open`:`projects open`},a>0&&{tone:`live`,strong:a,text:`running`},o>0&&{tone:`warning`,strong:o,text:o===1?`needs you`:`need you`}],actions:(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(yy,{}),onClick:e.showOpen,children:`Open a project`})}),(0,R.jsx)(yA,{divided:!0,label:`Open projects`,className:`mt-8`,children:t.map((t,n)=>(0,R.jsx)(r7,{index:n,project:t,stats:i[n],loading:r[n]?.data===void 0,onOpen:()=>e.enterProject(t.id)},t.id))})]})]})})}function a7({nav:e}){let t=Zm(),n=nM();return(0,R.jsxs)(`nav`,{"aria-label":`Projects`,className:`flex h-full min-h-0 flex-col p-2`,children:[(0,R.jsxs)(`div`,{className:`flex h-9 shrink-0 items-center gap-0.5`,children:[(0,R.jsx)(`div`,{className:`flex min-w-0 flex-1`,children:(0,R.jsx)(BP,{nav:e})}),(0,R.jsx)(JP,{})]}),(0,R.jsx)(`div`,{className:`mt-2 flex flex-col gap-px`,children:(0,R.jsx)(_A,{icon:(0,R.jsx)(Qy,{}),label:`All projects`,meta:e.projects?.length,active:!0})}),(0,R.jsx)(`div`,{className:`flex-1`}),(0,R.jsx)(uF,{health:t===`live`?`ok`:t===`connecting`?`connecting`:`reconnecting`,origin:typeof window>`u`?`this machine`:window.location.origin,sandbox:Dj,notify:null,theme:n.resolved,onToggleTheme:n.toggle})]})}var o7=4;function s7({crumbs:e,value:t,onNavigate:n,onEnterPath:r,placeholder:i}){let[a,o]=(0,L.useState)(null),s=a!==null,c=e.length>o7,l=c?e.slice(-3):e;return s?(0,R.jsx)(`input`,{className:`${wA} flex-1 font-mono text-xs`,"aria-label":`Path`,spellCheck:!1,autoComplete:`off`,autoFocus:!0,value:a,placeholder:i,onChange:e=>o(e.target.value),onBlur:()=>o(null),onKeyDown:e=>{e.key===`Enter`&&(r(a.trim()),o(null)),e.key===`Escape`&&(e.stopPropagation(),o(null))}}):(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-1 cursor-text items-center gap-0.5 truncate`,onClick:()=>o(t),role:`group`,"aria-label":`Current path`,children:[c&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(c7,{crumb:e[0],onNavigate:n}),(0,R.jsx)(Ty,{size:12,className:`shrink-0 text-text-disabled`}),(0,R.jsx)(`span`,{className:`shrink-0 px-1 text-sm text-text-tertiary`,title:e[e.length-1].path,children:`…`})]}),l.map((e,t)=>(0,R.jsxs)(`span`,{className:`flex shrink-0 items-center gap-0.5`,children:[(t>0||c)&&(0,R.jsx)(Ty,{size:12,className:`shrink-0 text-text-disabled`}),(0,R.jsx)(c7,{crumb:e,onNavigate:n})]},e.path)),(0,R.jsx)(`button`,{type:`button`,className:`${oE} ml-1 inline-flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-md text-icon transition-colors duration-(--dur-1) ease-app hover:bg-surface-hover hover:text-text`,"aria-label":`Edit path`,title:`Edit path`,onClick:()=>o(t),children:(0,R.jsx)(Ay,{size:14})})]})}function c7({crumb:e,onNavigate:t}){return(0,R.jsx)(`button`,{type:`button`,className:`${oE} shrink-0 rounded-sm px-1 py-0.5 cursor-pointer font-mono text-xs text-text-secondary transition-colors duration-(--dur-1) ease-app hover:bg-surface-hover hover:text-text`,onClick:n=>{n.stopPropagation(),t(e.path)},children:e.name})}function l7({initialPath:e,onPick:t,onCancel:n}){let r=e?.trim()||void 0,[i,a]=(0,L.useState)(r),[o,s]=(0,L.useState)(!1),[c,l]=(0,L.useState)(r??null),[u,d]=(0,L.useState)(null),f=B.project.roots.useQuery(),p=B.project.browse.useQuery({dir:i,showHidden:o},{placeholderData:e=>e,retry:!1}),m=p.data,h=m?.dir??i,g=e=>{l(null),d(null),a(e)},_=e=>{l(e||null),d(null),a(e||void 0)},v=c!==null&&p.isError?Fh(i,p.error.message):null,y=v!==null&&v.dir!==i,b=v?.dir,x=p.error?.message;(0,L.useEffect)(()=>{y&&(i===c&&x&&d(Rh(x)),a(b))},[y,b,i,c,x]);let S=e=>{if(![`ArrowDown`,`ArrowUp`,`Home`,`End`].includes(e.key))return;let t=[...e.currentTarget.querySelectorAll(`[data-dir-row] button`)];if(t.length===0)return;e.preventDefault();let n=t.indexOf(document.activeElement);t[e.key===`Home`?0:e.key===`End`?t.length-1:e.key===`ArrowDown`?Math.min(t.length-1,n+1):Math.max(0,n===-1?0:n-1)]?.focus()};return(0,R.jsxs)(QA,{open:!0,onClose:n,size:`lg`,labelledBy:`dir-picker-title`,className:`flex h-[min(620px,76vh)] flex-col overflow-hidden`,children:[(0,R.jsx)($A,{id:`dir-picker-title`,title:`Choose a repository`,description:`Browse this machine for a git repository to open.`,onClose:n}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-y border-border-subtle px-3 py-2`,children:[(0,R.jsx)(nE,{label:`Up one level`,icon:(0,R.jsx)(ib,{}),onClick:()=>m?.parent&&g(m.parent),disabled:!m?.parent}),(0,R.jsx)(s7,{crumbs:m?.crumbs??[],value:c??h??``,onNavigate:g,onEnterPath:_,placeholder:Tj()}),(0,R.jsx)(HA,{label:`Hidden`,checked:o,onChange:s,className:`shrink-0 px-2`})]}),u&&(0,R.jsx)(`div`,{className:`shrink-0 border-b border-border-subtle px-4 py-3`,children:(0,R.jsx)(YA,{message:u.message,path:u.path,hint:`Showing the closest folder that could be listed. Edit the path to try again.`})}),(0,R.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,R.jsxs)(`div`,{className:`flex w-44 shrink-0 flex-col gap-0.5 overflow-y-auto border-r border-border-subtle p-2`,onKeyDown:S,children:[(0,R.jsx)(mA,{className:`px-2.5`,children:`Locations`}),(f.data??[]).map(e=>(0,R.jsx)(`div`,{"data-dir-row":``,children:(0,R.jsx)(_A,{label:(0,R.jsx)(`span`,{className:`font-mono text-xs`,children:e.label}),title:e.path,icon:e.label===`~`?(0,R.jsx)(Qy,{}):(0,R.jsx)(My,{}),active:h===e.path,onClick:()=>g(e.path)})},e.path))]}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-y-auto p-2`,onKeyDown:S,children:[y||p.isLoading?(0,R.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 py-2 text-sm text-text-tertiary`,children:[(0,R.jsx)(aE,{}),` Loading…`]}):p.isError?(0,R.jsx)(`div`,{className:`p-2`,children:(0,R.jsx)(YA,{...Rh(p.error.message)})}):(m?.entries.length??0)===0?(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(My,{}),title:`No subfolders here`,hint:o?void 0:`Hidden folders, junctions and node_modules are filtered.`}):(0,R.jsx)(`div`,{className:`flex flex-col gap-0.5 animate-rise-in`,role:`list`,children:(m?.entries??[]).map(e=>(0,R.jsx)(`div`,{role:`listitem`,"data-dir-row":``,children:(0,R.jsx)(_A,{onDoubleClick:()=>e.isRepo&&t(e.path),label:e.name,title:e.path,icon:e.isRepo?(0,R.jsx)(gy,{}):(0,R.jsx)(My,{}),onClick:()=>g(e.path),className:e.isRepo?`text-text`:void 0,meta:e.isRepo?(0,R.jsx)(`span`,{className:`text-text-secondary`,children:`git`}):e.isSymlink?`link`:void 0})},e.path))},h),m?.truncated&&(0,R.jsx)(`p`,{className:`m-0 px-2.5 py-2 text-xs text-text-tertiary`,children:`Listing truncated — this folder is very large.`})]})]}),(0,R.jsxs)(tj,{className:`border-t border-border-subtle pt-3 pb-3`,start:(0,R.jsx)(`div`,{className:`min-w-0 truncate text-left font-mono text-xs`,dir:`rtl`,title:h,children:(0,R.jsx)(`bdi`,{children:h??`—`})}),children:[(0,R.jsx)(Y,{variant:`ghost`,onClick:n,children:`Cancel`}),(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(My,{}),onClick:()=>h&&t(h),disabled:!h||p.isError,children:`Open this folder`})]})]})}function u7({rail:e,stepKey:t,direction:n=`forward`,onKeyDown:r,children:i}){return(0,R.jsx)(`div`,{className:`flex min-h-full`,onKeyDown:r,children:(0,R.jsxs)(`div`,{className:q(`m-auto grid w-full gap-12 px-8 py-12`,e?`max-w-[860px] grid-cols-[176px_minmax(0,1fr)]`:`max-w-[560px]`),children:[e&&(0,R.jsx)(`div`,{className:`pt-1`,children:e}),(0,R.jsx)(`div`,{className:q(`min-w-0`,n===`forward`?`animate-slide-in-right`:`animate-rise-in`),children:i},t)]})})}function d7({title:e,children:t}){return(0,R.jsxs)(`header`,{children:[(0,R.jsx)(`h1`,{className:`m-0 text-xl font-semibold tracking-tight text-pretty text-text`,children:e}),(0,R.jsx)(`p`,{className:`mt-2 mb-0 text-base text-pretty text-text-secondary`,children:t})]})}function f7({onBack:e,note:t,children:n}){return(0,R.jsxs)(`footer`,{className:`mt-10 border-t border-border-subtle pt-5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e&&(0,R.jsx)(Y,{variant:`ghost`,icon:(0,R.jsx)(rb,{}),onClick:e,children:`Back`}),(0,R.jsx)(`div`,{className:`ml-auto flex items-center gap-2`,children:n})]}),t&&(0,R.jsx)(`p`,{className:`mt-2 mb-0 text-right text-xs text-text-tertiary`,children:t})]})}function p7({firstRun:e,rail:t,variant:n=`screen`,onOpened:r,onCancel:i}){let[a,o]=(0,L.useState)(``),[s,c]=(0,L.useState)(!1),[l,u]=(0,L.useState)(``),[d,f]=(0,L.useState)(!1),p=Ab(),m=B.useUtils(),h=B.project.open.useMutation({onSuccess:async e=>{await m.project.list.invalidate(),p.push(`opened ${e.name}`,`info`),r(e.id)},onError:()=>void 0}),g=B.project.initRepo.useMutation({onSuccess:({repoPath:e})=>{u(e),h.mutate({repoPath:e})},onError:()=>void 0}),_=()=>{h.reset(),g.reset(),f(!1)},v=e=>{let t=(e??a).trim();if(t){if(_(),!Ej(t)){f(!0);return}u(t),h.mutate({repoPath:t})}},y=()=>{_(),c(!0)},b=h.isPending||g.isPending,x=g.error??h.error,S=d?{message:`Enter an absolute path`,hint:`A path from the root of this machine, like ${Tj()}.`,path:null}:x?zh(x.message,l):null,C=e=>{o(e),c(!1),v(e)},w=(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:q(`flex items-center gap-2`,n===`screen`&&`mt-8`),children:[(0,R.jsx)(DA,{id:`open-repo-path`,size:`lg`,mono:!0,icon:(0,R.jsx)(My,{}),className:`flex-1`,value:a,onChange:e=>o(e.target.value),placeholder:Tj(),"aria-label":`Repository path`,autoFocus:!0,spellCheck:!1,invalid:!!S,"aria-describedby":S?`open-repo-error`:`open-repo-hint`,onKeyDown:e=>{e.key===`Enter`&&v()}}),(0,R.jsx)(Y,{size:`lg`,icon:(0,R.jsx)(py,{}),onClick:y,disabled:b,children:`Browse…`}),(0,R.jsx)(Y,{variant:`primary`,size:`lg`,icon:(0,R.jsx)(Iy,{}),loading:h.isPending,onClick:()=>v(),disabled:b||a.trim()===``,children:`Open`})]}),S?(0,R.jsx)(`div`,{className:`mt-3 animate-rise-in`,children:(0,R.jsx)(YA,{...S,id:`open-repo-error`,action:S.offer===`init-repo`?(0,R.jsx)(Y,{size:`sm`,icon:(0,R.jsx)(gy,{}),loading:g.isPending,onClick:()=>g.mutate({repoPath:l}),disabled:b,children:`Initialize repository`}):void 0})}):(0,R.jsx)(`p`,{id:`open-repo-hint`,className:`mt-2.5 mb-0 text-xs text-text-tertiary`,children:`Paste an absolute path, or browse for one. The default branch is detected when the project opens.`})]}),T=(0,R.jsx)(R.Fragment,{children:s&&(0,R.jsx)(l7,{initialPath:a,onPick:C,onCancel:()=>c(!1)})});return n===`dialog`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)($A,{title:`Open a project`,description:`Point runcastle at a local git repository — every feature runs its pipeline against it.`,onClose:b?void 0:i}),(0,R.jsx)(ej,{className:`pt-1`,children:w}),T]}):(0,R.jsxs)(u7,{rail:t,stepKey:`project`,onKeyDown:t=>{t.key===`Escape`&&!e&&!s&&i()},children:[!t&&(0,R.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs text-text-tertiary`,children:[(0,R.jsx)(Cb,{size:14}),e?`Welcome to runcastle`:`Your projects`]}),(0,R.jsx)(d7,{title:e?`Open your first project`:`Open a project`,children:`Point runcastle at a local git repository — every feature runs its pipeline against it.`}),w,!e&&(0,R.jsx)(`footer`,{className:`mt-10 flex items-center border-t border-border-subtle pt-5`,children:(0,R.jsx)(Y,{variant:`ghost`,icon:(0,R.jsx)(rb,{}),onClick:i,disabled:b,children:`Cancel`})}),T]})}function m7({onBack:e,onNext:t}){let[n,r]=(0,L.useState)(!1);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(d7,{title:`Run burns unattended?`,children:P_}),n&&(0,R.jsx)(`div`,{className:`mt-8 animate-rise-in`,children:(0,R.jsx)(w5,{onDismiss:t})}),(0,R.jsx)(f7,{onBack:e,children:!n&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(Y,{variant:`ghost`,icon:(0,R.jsx)(Py,{}),onClick:()=>r(!0),children:`Set up now`}),(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(Iy,{}),onClick:t,children:`Skip for now`})]})})]})}function h7({onBack:e,onNext:t}){let[n,r]=(0,L.useState)(``),[i,a]=(0,L.useState)(``),o=Ab(),s=B.useUtils(),c=B.setup.gitIdentity.useMutation({onSuccess:async()=>{await s.setup.doctor.invalidate(),t()},onError:e=>o.push(e.message)}),l=n.trim()!==``&&i.includes(`@`),u=()=>l&&c.mutate({name:n.trim(),email:i.trim()}),d=e=>e.key===`Enter`&&u();return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(d7,{title:`Set your git identity`,children:[`runcastle commits documentation and merges on your behalf, so it needs a name and email. This writes to `,(0,R.jsx)(`code`,{className:`font-mono text-sm text-text`,children:`git config --global`}),`.`]}),(0,R.jsxs)(`div`,{className:`mt-8 flex max-w-sm flex-col gap-4`,children:[(0,R.jsx)(AA,{label:`Name`,children:(0,R.jsx)(DA,{id:`wiz-name`,size:`lg`,value:n,onChange:e=>r(e.target.value),placeholder:`Ada Lovelace`,autoFocus:!0,spellCheck:!1,onKeyDown:d})}),(0,R.jsx)(AA,{label:`Email`,children:(0,R.jsx)(DA,{id:`wiz-email`,size:`lg`,type:`email`,value:i,onChange:e=>a(e.target.value),placeholder:`ada@example.com`,spellCheck:!1,onKeyDown:d})})]}),(0,R.jsx)(f7,{onBack:e,children:(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(Iy,{}),loading:c.isPending,onClick:u,disabled:!l,children:`Continue`})})]})}function g7({onNext:e}){return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(Cb,{size:32,variant:`solid`,className:`mb-6`}),(0,R.jsx)(d7,{title:`Your coding agent, driven through a pipeline`,children:`Describe a feature and runcastle runs the agent sessions that carry it from idea to merged, stopping at each gate until you say go.`}),(0,R.jsx)(`ol`,{className:`m-0 mt-8 flex list-none flex-col p-0`,children:ev.map((e,t)=>(0,R.jsxs)(`li`,{className:`grid grid-cols-[16px_96px_minmax(0,1fr)] items-center gap-3 border-b border-border-subtle py-2.5 text-sm last:border-b-0 animate-rise-in`,style:{animationDelay:`${120+t*40}ms`},children:[(0,R.jsx)(xb,{phase:e,size:16,label:``}),(0,R.jsx)(`span`,{className:`font-medium text-text`,children:vb[e]}),(0,R.jsx)(`span`,{className:`text-text-tertiary`,children:nv[e]})]},e))}),(0,R.jsx)(f7,{children:(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(Iy,{}),onClick:e,autoFocus:!0,children:`Set up runcastle`})})]})}function _7({runtimes:e,onBack:t,onNext:n}){let r=Rm(e);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(d7,{title:`Connect a coding agent`,children:`runcastle drives whichever agent you have — sign in to one or both. The ones you connect here are the ones whose models you can pick later.`}),(0,R.jsx)(`div`,{className:`mt-8`,children:(0,R.jsx)(M5,{children:e.map(e=>(0,R.jsx)(v7,{runtime:e},e.runtime))})}),(0,R.jsx)(f7,{onBack:t,note:r.length===0&&`Connect at least one agent to continue — runcastle has nothing to run without one.`,children:(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(Iy,{}),onClick:n,disabled:r.length===0,children:`Continue`})})]})}function v7({runtime:e}){let[t,n]=(0,L.useState)(null),r=Ab(),i=B.useUtils(),a=B.setup.startTerminal.useMutation({onSuccess:({sessionId:e})=>n(e),onError:e=>r.push(e.message)}),o=Im[e.runtime],s=e.talkReady?`Ready`:e.installed?`Not signed in`:`Not installed`;return(0,R.jsxs)(j5,{label:e.label,status:s,detail:e.detail,ok:e.talkReady,below:t&&(0,R.jsx)(N5,{sessionId:t,label:o.kind,onDone:()=>{n(null),i.setup.doctor.invalidate()}}),children:[e.installFix&&(0,R.jsx)(U5,{command:e.installFix,onCopy:()=>{navigator.clipboard?.writeText(e.installFix??``),r.push(`copied`,`info`)}}),e.installed&&!e.talkReady&&!t&&(0,R.jsxs)(Y,{size:`sm`,icon:(0,R.jsx)(Dy,{}),loading:a.isPending,onClick:()=>a.mutate({kind:o.kind}),children:[`Run `,o.command]}),e.talkReady&&!e.afkReady&&(0,R.jsxs)(`span`,{className:`basis-full text-right text-xs text-text-tertiary`,children:[`Signed in for sessions you watch. Unattended burns on `,e.label,` also need its key — the next step sets that up.`]})]})}var y7={passed:`shipped`,done:`shipped`,current:`review`,todo:`draft`},b7={passed:`text-text-secondary`,done:`text-text-secondary`,current:`bg-surface-selected font-medium text-text`,todo:`text-text-tertiary`};function x7({steps:e}){return(0,R.jsxs)(`nav`,{"aria-label":`Setup`,className:`flex flex-col gap-4`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 text-sm font-medium text-text`,children:[(0,R.jsx)(Cb,{size:16}),`Set up runcastle`]}),(0,R.jsx)(`ol`,{className:`m-0 flex list-none flex-col gap-0.5 p-0`,"aria-label":`Setup progress`,children:e.map(e=>(0,R.jsxs)(`li`,{"data-state":e.state,"aria-current":e.state===`current`?`step`:void 0,className:q(`flex flex-col rounded-md px-2.5 py-1.5 text-sm transition-colors duration-(--dur-2) ease-app`,b7[e.state]),children:[(0,R.jsxs)(`span`,{className:`flex min-h-5 items-center gap-2`,children:[(0,R.jsx)(xb,{phase:y7[e.state],size:14,label:``}),e.label]}),e.detected&&(0,R.jsx)(`span`,{className:`mt-0.5 pl-5.5 text-xs font-normal text-pretty text-text-tertiary`,children:e.detected})]},e.key))})]})}function S7({onOpened:e,onCancel:t}){let n=B.setup.doctor.useQuery(void 0,{refetchOnWindowFocus:!1}),r=n.data?.results.find(e=>e.id===`git-identity`),i=Lm(n.data?.results??[]),[a,o]=(0,L.useState)(`intro`),[s,c]=(0,L.useState)(`forward`),l=(e,t)=>{c(t),o(e)},u=B.setup.seedModelDefaults.useMutation(),d=()=>{u.mutate({runtimes:Rm(i)}),l(`project`,`forward`)};if(n.isLoading)return(0,R.jsx)(u7,{children:(0,R.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-sm text-text-tertiary`,children:[(0,R.jsx)(aE,{}),` Preparing setup…`]})});if(a===`project`)return(0,R.jsx)(p7,{firstRun:!0,rail:(0,R.jsx)(x7,{steps:Vm(`project`,r)}),onOpened:e,onCancel:t});if(a===`intro`)return(0,R.jsx)(u7,{stepKey:`intro`,direction:s,children:(0,R.jsx)(g7,{onNext:()=>l(Nm(r),`forward`)})});let f=()=>{let e=Pm(a);e===`project`||e===void 0?d():l(e,`forward`)},p=()=>l(Fm(a,r)??`intro`,`back`);return(0,R.jsxs)(u7,{rail:(0,R.jsx)(x7,{steps:Vm(a,r)}),stepKey:a,direction:s,children:[a===`identity`&&(0,R.jsx)(h7,{onBack:p,onNext:f}),a===`runtimes`&&(0,R.jsx)(_7,{runtimes:i,onBack:p,onNext:f}),a===`afk`&&(0,R.jsx)(m7,{onBack:p,onNext:f})]})}var C7=`runcastle.update.dismissed`;function w7(e,t){return e.updateAvailable&&e.latest!==null&&e.latest!==t}function T7({tone:e=`neutral`,icon:t,children:n,action:r,onDismiss:i,dismissLabel:a=`Dismiss`}){return(0,R.jsxs)(`div`,{role:`status`,className:q(`flex h-10 shrink-0 animate-fade-in items-center gap-2.5 overflow-hidden border-b border-border-subtle pr-2 pl-4 text-sm`,e===`danger`?`bg-danger-subtle`:`bg-surface`),children:[(0,R.jsx)(`span`,{className:q(`inline-flex shrink-0 [&>svg]:size-4`,e===`danger`?`text-danger`:`text-accent`),children:t}),(0,R.jsx)(`span`,{className:`flex min-w-0 flex-1 items-center gap-2 truncate text-text-secondary`,children:n}),r,i&&(0,R.jsx)(nE,{size:`sm`,label:a,icon:(0,R.jsx)(xy,{}),onClick:i})]})}function E7(){let e=Ab(),t=B.system.checkUpdate.useQuery(void 0,{staleTime:1/0,refetchOnWindowFocus:!1,retry:!1}),[n,r]=(0,L.useState)(()=>{try{return localStorage.getItem(C7)}catch{return null}}),i=t.data;return!i||!i.latest||!w7(i,n)?null:(0,R.jsxs)(T7,{icon:(0,R.jsx)(Iy,{}),onDismiss:()=>{try{localStorage.setItem(C7,i.latest)}catch{}r(i.latest)},dismissLabel:`Dismiss update notice`,action:(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,icon:(0,R.jsx)(Jy,{}),onClick:()=>navigator.clipboard.writeText(i.command).then(()=>e.push(`Update command copied`,`info`),()=>e.push(`Copy failed`)),children:`Copy command`}),children:[(0,R.jsxs)(`span`,{className:`shrink-0 text-text`,children:[`runcastle `,i.latest,` is available`]}),(0,R.jsxs)(`span`,{className:`shrink-0 text-text-tertiary`,children:[`you're on `,i.current]}),(0,R.jsx)(`code`,{className:`min-w-0 truncate font-mono text-xs text-text-tertiary select-all`,children:i.command})]})}function D7({error:e,onRecheck:t}){return e?(0,R.jsxs)(T7,{tone:`danger`,icon:(0,R.jsx)(tb,{}),action:(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,icon:(0,R.jsx)(ab,{}),onClick:t,children:`Re-run checks`}),children:[(0,R.jsx)(`span`,{className:`shrink-0 font-medium text-text`,children:`Setup checks could not run`}),(0,R.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs text-text-secondary`,title:e,children:e})]}):null}function O7(){let e=$h(),t,n=null;return e.loading||e.projects===void 0?t=(0,R.jsx)(YP,{children:(0,R.jsx)(PA,{children:(0,R.jsx)(UA,{children:`Loading projects…`})})}):e.view===`setup`?t=(0,R.jsx)(YP,{children:(0,R.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto`,children:(0,R.jsx)(S7,{onOpened:e.enterProject,onCancel:e.cancelOpen})})}):e.view===`open`&&e.projects.length>0?(t=e.currentProjectId?(0,R.jsx)(e7,{projectId:e.currentProjectId,nav:e},e.currentProjectId):(0,R.jsx)(i7,{nav:e}),n=(0,R.jsx)(QA,{open:!0,onClose:e.cancelOpen,size:`md`,label:`Open a project`,children:(0,R.jsx)(p7,{variant:`dialog`,firstRun:!1,onOpened:e.enterProject,onCancel:e.cancelOpen})})):t=e.view===`open`?(0,R.jsx)(YP,{children:(0,R.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto`,children:(0,R.jsx)(p7,{firstRun:e.projects.length===0,onOpened:e.enterProject,onCancel:e.cancelOpen})})}):e.view===`project`&&e.currentProjectId?(0,R.jsx)(e7,{projectId:e.currentProjectId,nav:e},e.currentProjectId):(0,R.jsx)(i7,{nav:e}),(0,R.jsx)(KP,{notices:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(E7,{}),(0,R.jsx)(D7,{error:e.doctorError,onRecheck:e.recheckDoctor})]}),children:(0,R.jsxs)(`div`,{className:`h-full bg-canvas`,children:[t,n]})})}function k7(){return ih(),(0,R.jsx)(O7,{})}function A7(e){return e instanceof Error&&e.message?e.message:typeof e==`string`&&e!==``?e:`something went wrong`}function j7(e,t){return typeof t.options.onError==`function`?null:A7(e)}Zj();function M7(){let[e]=(0,L.useState)(()=>new Ve({mutationCache:new Pe({onError:(e,t,n,r)=>{let i=j7(e,r);i&&Ob(i)}}),defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!0,refetchOnReconnect:!0}}})),[t]=(0,L.useState)(()=>B.createClient({links:[Bn({url:`/api/trpc`})]}));return(0,R.jsx)(B.Provider,{client:t,queryClient:e,children:(0,R.jsx)(Je,{client:e,children:(0,R.jsx)(UT,{children:(0,R.jsx)(kb,{children:(0,R.jsx)(k7,{})})})})})}var N7=document.getElementById(`root`);if(!N7)throw Error(`#root not found`);(0,pr.createRoot)(N7).render((0,R.jsx)(L.StrictMode,{children:(0,R.jsx)(M7,{})}));
|
|
187
|
+
`)){let e=t.trim();if(e!==``)return e}return``}function B3(e,t){return e.length>t?`${e.slice(0,t-1).trimEnd()}…`:e}function V3(e){if(typeof e!=`object`||!e)return null;let t=e;return typeof t.name!=`string`||t.name===``?null:{name:t.name,args:typeof t.args==`string`?t.args:``}}function H3(e){return e.endsWith(`.tool`)}function U3(e){let t=e.replace(/[._]+/g,` `).trim();return t===``?``:`${t[0].toUpperCase()}${t.slice(1)}`}function W3(e,t){if(!t.startsWith(e))return null;let n=t.slice(e.length).replace(/^[\s:;,—–-]+/,``).trim().replace(/^\((.*)\)$/s,`$1`).trim(),r=U3(e);return n===``?r:`${r} — ${n}`}function G3(e){return typeof e==`object`&&e?e:null}function K3(e){return typeof e==`string`&&e!==``?e:null}function q3(e){if(e.type!==`feature.created`)return null;let t=G3(e.data),n=K3(t?.branch);if(!t||!n)return null;if(t.draft===!0)return`Feature created as a draft — ${n} is not cut yet`;if(t.branchReady!==!0)return`Feature created — branch ${n} is still being cut`;let r=K3(t.baseBranch);return r?`Feature created on branch ${n}, from ${r}`:`Feature created on branch ${n}`}function J3(e){if(H3(e.type)){let t=V3(e.data);if(!t){let t=z3(e.message);return{summary:B3(t,I3)||U3(e.type),detail:e.message.trim()===t?null:e.message.trim()}}let n=B3(z3(t.args),L3);return{summary:n?`${t.name} — ${n}`:`${t.name}`,detail:t.args.trim()===``?null:t.args.trim()}}let t=R3(e.message),n=q3(e)??W3(e.type,t)??t,r=B3(z3(n),I3),i=n===r?null:n;return{summary:r||U3(e.type),detail:i}}function Y3(e){return e===`lap.started`}function X3(e){if(e.type!==`run.finished`||typeof e.data!=`object`||e.data===null)return null;let t=e.data.status;return t===`succeeded`||t===`failed`||t===`cancelled`?t:null}function Z3(e){let t=X3(e);if(t)return t===`succeeded`?`ok`:`error`;let n=e.type;return n===`merge.conflict.resolved`?`ok`:n===`merge.conflict.resolving`?`active`:/(error|fail|conflict|cancel|stopped|timeout)/i.test(n)?`error`:/(done|succeed|finished|shipped|merged)/i.test(n)?`ok`:/(start|burn|launch|advance|running|retry|resum)/i.test(n)?`active`:`info`}function Q3(e){return typeof e.data!=`object`||e.data===null?!1:e.data.oversized===!0}var $3={error:`danger`,ok:`success`,active:`neutral`,info:`neutral`};function e6({events:e}){let t=e.some(Q3);return(0,R.jsxs)(JA,{defaultOpen:t,title:`Run timeline`,icon:(0,R.jsx)(jy,{}),aside:(0,R.jsx)(`span`,{className:`tabular-nums`,children:e.length}),children:[e.length===0&&(0,R.jsx)(WA,{children:`Waiting for events…`}),(0,R.jsx)(`ol`,{className:`@container m-0 flex max-h-96 list-none flex-col overflow-y-auto p-0`,children:e.map(e=>{let t=Q3(e);return(0,R.jsxs)(`li`,{className:`flex min-h-7 items-start gap-3 py-1 text-sm`,children:[(0,R.jsx)(`span`,{className:`w-20 shrink-0 pt-px text-xs whitespace-nowrap text-text-tertiary tabular-nums`,children:ah(e.ts)}),(0,R.jsx)(`span`,{className:`inline-flex h-5 w-2 shrink-0 items-center justify-center`,children:(0,R.jsx)(tA,{tone:t?`warning`:$3[Z3(e)]??`neutral`})}),(0,R.jsx)(`span`,{className:q(`min-w-0 flex-1`,t?`break-words text-warning`:`truncate text-text-secondary`),children:e.message}),(0,R.jsx)(`span`,{className:`hidden w-40 shrink-0 truncate pt-px text-right font-mono text-xs text-text-tertiary @xl:block`,children:e.type})]},e.id)})})]},t?`warned`:`quiet`)}function t6({gates:e}){return e.length===0?null:(0,R.jsxs)(`section`,{className:`mb-6 flex flex-col gap-2`,role:`alert`,children:[(0,R.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,R.jsx)(rA,{tone:`warning`,icon:(0,R.jsx)(tb,{}),size:`sm`,strong:!0,children:`Verification unavailable`}),(0,R.jsx)(`p`,{className:`m-0 pl-5.5 text-sm text-text-secondary`,children:`The sandbox lacked a command or runtime. Ticket results were kept; these gates still need checking.`})]}),(0,R.jsx)(`ul`,{className:`m-0 flex list-none flex-col p-0 pl-5.5`,children:e.map(e=>(0,R.jsxs)(`li`,{className:`flex flex-col gap-0.5 border-t border-border-subtle py-2 first:border-t-0`,children:[(0,R.jsx)(`code`,{className:`font-mono text-xs text-text`,children:e.command}),(0,R.jsx)(`span`,{className:`font-mono text-xs break-words text-text-tertiary`,children:e.error})]},e.command))})]})}function n6({featureId:e,runId:t,readonly:n=!1,chatDocked:r=!1}){let i=eh(),a=Ab(),o=B.useUtils(),[s,c]=(0,L.useState)(null),l=!!s&&s!==t,u=s??t,d=n||l,f=B.feature.get.useQuery({id:e},{refetchInterval:i}),p=B.run.get.useQuery({runId:u},{refetchInterval:!l&&i,enabled:!!u}),m=B.run.listByFeature.useQuery({featureId:e},{refetchInterval:i}),h=pF(e),g=f.data?.feature.projectId,_=B.settings.get.useQuery({projectId:g},{enabled:!!g}),v=B.findings.listByFeature.useQuery({featureId:e}),y={onSuccess:()=>o.feature.get.invalidate({id:e}),onError:e=>a.push(e.message)},b=B.ticket.retry.useMutation(y),x=B.ticket.edit.useMutation(y),S=B.ticket.stop.useMutation(y),C=B.ticket.cancel.useMutation(y),w=B.feature.launchSession.useMutation(y),T=B.run.cancel.useMutation(y),E=b.isPending||x.isPending||S.isPending||C.isPending||w.isPending||T.isPending,D=l?p.data?.tickets??[]:f.data?.tickets??[],O=f.data?.feature.branch??``,k=f.data?.feature.lap??1,A=(0,L.useMemo)(()=>h.filter(e=>e.runId===u),[h,u]),j=(0,L.useMemo)(()=>Dg(A),[A]),M=(0,L.useMemo)(()=>p_(A),[A]),N=(0,L.useMemo)(()=>Jg(A),[A]),[P,F]=(0,L.useState)(null),ee=D.find(e=>e.status===`burning`)?.id,te=P??new Set(ee?[ee]:[]),ne=e=>F(()=>{let t=new Set(te);return t.has(e)?t.delete(e):t.add(e),t}),I=Vp(_.data),re=(0,L.useMemo)(()=>new Map((v.data?.findings??[]).map(e=>[e.id,e.title])),[v.data]),ie=e=>Rg(e,I)??Rg({model:mm(_.data,e.kind===`review`?`review`:`implement`)},I),ae=f.data?.sessions??[],oe=ae.some(Ag),se=oe||p.data?.status===`running`,ce=p.data?p.data.status===`running`:!!u;if(!t&&!oe)return(0,R.jsx)(GA,{icon:(0,R.jsx)(Py,{}),title:`No run yet`,hint:`${j_} Every ticket gets its own lane here.`});let le=D.filter(e=>e.status===`burning`).length,ue=e=>{navigator.clipboard?.writeText(e).then(()=>a.push(`copied ${lh(e)}`,`info`),()=>a.push(`copy failed`))},de=e=>b.mutate({ticketId:e.id},{onSuccess:t=>{t.resolvingConflict?a.push(`resolving ticket #${e.seq}'s conflict with an agent`,`info`):t.resumedFrom&&a.push(`resuming ticket #${e.seq} from ${t.preservedCommits} preserved commit(s)`,`info`)}}),fe=(t,n)=>{let r=M.get(t.id),i=j.get(t.id),o=t.status===`failed`?t.conflictFiles:void 0;return(0,R.jsxs)(E3,{ticket:t,featureBranch:O,readonly:d,expanded:te.has(t.id),index:n,onToggle:()=>ne(t.id),hadOutput:r?.hadOutput,elapsed:r?mh(r.startedAt,Date.now()):void 0,duration:i===void 0?void 0:mh(0,i),model:ie(t),roster:I,defectTitle:t.originFindingId?re.get(t.originFindingId):void 0,busy:E,stopping:S.isPending&&S.variables?.ticketId===t.id,waiving:C.isPending&&C.variables?.ticketId===t.id,terminalBlocked:se,onCopySha:ue,onModel:e=>x.mutate({ticketId:t.id,model:e}),onRetry:()=>de(t),onRetryWithModel:ce?void 0:e=>x.mutate({ticketId:t.id,model:e},{onSuccess:()=>de(t)}),onRetryFresh:()=>b.mutate({ticketId:t.id,fresh:!0}),onWaive:()=>C.mutate({ticketId:t.id,reason:`waived from the run view`},{onSuccess:e=>{a.push(`ticket #${t.seq} set aside — it stays visible as unfinished work at review`,`info`),e.confirmed||a.push(N_)}}),onStop:()=>S.mutate({ticketId:t.id},{onSuccess:e=>{e.swept?a.push(`no live agent — the lane was orphaned; marked failed, retry to resume it`,`info`):e.stopped?e.confirmed||a.push(N_):a.push(`no live agent for this ticket (already finishing?)`,`info`)}}),onResolveInTerminal:o?()=>w.mutate({featureId:e,kind:`chat`,kickoffLine:yg({seq:t.seq,title:t.title,branch:t.attemptBranch??``,featureBranch:O,files:o}),purpose:`resolve-conflict`,purposeData:{mergeFrom:t.attemptBranch??``,mergeInto:O}}):void 0,children:[(0,R.jsx)(D3,{digest:t.digest}),(0,R.jsx)(LG,{label:`agent transcript`,children:(0,R.jsx)(k3,{ticketId:t.id,bootEvents:A.filter(e=>e.ticketId===t.id),runtime:ie(t)?.runtime,poll:!l})})]},t.id)};return(0,R.jsxs)(`div`,{className:`flex flex-col`,children:[(0,R.jsx)(b1,{featureId:e,sessions:qv(ae,r),className:`mb-10 h-[clamp(320px,calc(100dvh-360px),960px)]`}),(0,R.jsx)(P3,{headline:e_(D.map(e=>({...e,hadOutput:M.get(e.id)?.hadOutput,reviewFix:!!e.originFindingId})),{status:p.data?.status},m_(D,A)),elapsed:p.data?mh(p.data.startedAt,p.data.endedAt??Date.now()):``,status:p.data?.status,landed:{done:D.filter(e=>e.status===`done`).length,total:D.length},burning:le,busy:E,cancelling:T.isPending,onCancelRun:d||!t||p.data?.status!==`running`?void 0:()=>T.mutate({runId:t},{onSuccess:e=>{e.confirmed||a.push(N_)}}),runs:m.data??[],selectedRunId:u,latestRunId:t,onPickRun:c,...l?{onBackToLatest:()=>c(null)}:{}}),(0,R.jsx)(t6,{gates:N}),D.length===0?(0,R.jsx)(GA,{icon:(0,R.jsx)(Py,{}),title:`No ticket lanes`,hint:`This run has nothing to burn — a session breaks the work into tickets, and they appear here as lanes.`}):(0,R.jsx)(F3,{tickets:D,currentLap:k,lane:fe}),(0,R.jsxs)(`div`,{className:`mt-8 flex flex-col`,children:[(0,R.jsx)(e6,{events:A}),p.data?.digest&&(0,R.jsx)(r6,{digest:p.data.digest})]})]})}function r6({digest:e}){return(0,R.jsx)(JA,{title:`What this run produced`,icon:(0,R.jsx)(ky,{}),children:(0,R.jsx)(PG,{source:e})})}var i6={error:`danger`,ok:`success`,active:`accent`,info:`neutral`};function a6(e){return e.replace(/_/g,` `).replace(`.`,` · `)}function o6({events:e}){let t=e.slice(-50).reverse();return t.length===0?(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(jy,{}),title:`Nothing yet`,hint:`Everything that happens to this feature shows up here.`}):(0,R.jsx)(`div`,{className:`flex flex-col`,children:t.map(e=>Y3(e.type)?(0,R.jsx)(s6,{event:e},e.id):(0,R.jsx)(c6,{event:e},e.id))})}function s6({event:e}){return(0,R.jsxs)(`div`,{className:`my-2 flex items-center gap-2 text-xs font-medium text-accent-text`,role:`separator`,children:[(0,R.jsx)(`span`,{className:`first-letter:uppercase`,children:J3(e).summary}),(0,R.jsx)(`span`,{className:`h-px flex-1 bg-border-subtle`}),(0,R.jsx)(`span`,{className:`font-normal text-text-tertiary tabular-nums`,children:fh(e.ts)})]})}function c6({event:e}){let[t,n]=(0,L.useState)(!1),r=J3(e);return(0,R.jsxs)(`div`,{className:`flex gap-3 py-2`,children:[(0,R.jsx)(`span`,{className:`flex h-5 w-1.5 shrink-0 items-center`,children:(0,R.jsx)(tA,{tone:i6[Z3(e)]})}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[r.detail?(0,R.jsxs)(`button`,{type:`button`,className:`group/ev m-0 flex w-full cursor-pointer items-start gap-1 bg-transparent p-0 text-left text-sm text-text-secondary transition-colors duration-(--dur-1) ease-app hover:text-text`,"aria-expanded":t,title:t?`Show less`:`Show the whole event`,onClick:()=>n(e=>!e),children:[(0,R.jsx)(`span`,{className:`min-w-0 flex-1`,children:r.summary}),(0,R.jsx)(Ty,{size:14,"aria-hidden":`true`,className:q(`mt-0.5 shrink-0 text-icon transition-transform duration-(--dur-2) ease-app`,t&&`rotate-90`)})]}):(0,R.jsx)(`div`,{className:`text-sm text-text-secondary`,children:r.summary}),t&&r.detail&&(0,R.jsx)(`pre`,{className:`m-0 mt-2 max-h-[260px] overflow-auto rounded-md bg-surface-inset px-2.5 py-2 font-mono text-xs break-words whitespace-pre-wrap text-text-secondary animate-fade-in`,children:r.detail}),(0,R.jsxs)(`div`,{className:`mt-0.5 flex items-baseline gap-2 text-xs text-text-tertiary`,children:[(0,R.jsx)(`span`,{className:`truncate`,children:a6(e.type)}),(0,R.jsx)(`span`,{className:`ml-auto shrink-0 tabular-nums`,children:fh(e.ts)})]})]})]})}function l6(e){return e.split(/[\\/]/).pop()??e}function u6({featureId:e,docs:t}){let[n,r]=(0,L.useState)(null),i=(0,L.useRef)(null);return(0,R.jsxs)(`section`,{"aria-label":`Knowledge`,children:[t.length===0?(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(ky,{}),title:`No docs yet`,hint:`Docs the sessions write — decisions, the spec, the map — collect here.`}):(0,R.jsx)(yA,{label:`Feature docs`,className:`-mx-2`,children:t.map((e,t)=>(0,R.jsx)(vA,{index:t,leading:(0,R.jsx)(ky,{}),title:e.title||l6(e.relPath),meta:(0,R.jsx)(`span`,{className:`font-mono`,children:l6(e.relPath)}),onClick:t=>{i.current=t.currentTarget,r({relPath:e.relPath,title:e.title})}},e.relPath))}),n&&(0,R.jsx)(A1,{featureId:e,relPath:n.relPath,title:n.title,returnFocusRef:i,onClose:()=>r(null)})]})}var d6=[{id:`knowledge`,label:`Knowledge`,icon:(0,R.jsx)(ky,{})},{id:`activity`,label:`Activity`,icon:(0,R.jsx)(jy,{})}];function f6({featureId:e,onClose:t}){return t?(0,R.jsx)(p6,{featureId:e,onClose:t}):null}function p6({featureId:e,onClose:t}){let[n,r]=(0,L.useState)(`knowledge`),i=B.feature.get.useQuery({id:e},{refetchInterval:eh()}),a=pF(e);return(0,R.jsx)(LA,{label:`Details`,title:(0,R.jsx)(CA,{items:d6,value:n,onChange:r,size:`sm`,label:`Details`}),onClose:t,bodyClassName:`px-4 py-4`,children:i.isLoading?(0,R.jsx)(UA,{children:`Loading…`}):i.data?(0,R.jsx)(`div`,{role:`tabpanel`,"aria-label":n===`knowledge`?`Knowledge`:`Activity`,className:`animate-fade-in`,children:n===`knowledge`?(0,R.jsx)(u6,{featureId:e,docs:i.data.docs}):(0,R.jsx)(o6,{events:a})},n):(0,R.jsx)(WA,{children:i.error?.message??`Could not load the details`})})}function m6({featureId:e,sessions:t,busy:n,onOpenChat:r,onCollapse:i}){let a=Kv(t),o=!!a&&Ag(a);return(0,R.jsx)(LA,{label:`Chat`,title:(0,R.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[o&&a&&(0,R.jsx)(dA,{status:a.status}),(0,R.jsx)(`span`,{children:`Chat`}),(0,R.jsx)(`span`,{className:`truncate font-normal text-text-tertiary`,children:`One transcript, resumed`})]}),actions:o&&a?(0,R.jsx)(IG,{featureId:e,sessionId:a.id}):void 0,onClose:i,bodyClassName:`flex flex-col overflow-hidden`,children:(0,R.jsx)(`section`,{"aria-label":`Feature chat`,className:`flex min-h-0 flex-1 flex-col`,children:o&&a?(0,R.jsx)(`div`,{className:`min-h-0 flex-1 bg-surface-inset`,id:`chat-panel-terminal`,children:(0,R.jsx)(LG,{label:`terminal`,children:(0,R.jsx)(_1,{sessionId:a.id})})}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-4`,children:a?(0,R.jsx)(d3,{sessionId:a.id,className:`flex flex-col gap-4`}):(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(Oy,{}),title:`No conversation yet`,hint:`One chat per feature — it knows the state, answers questions, and edits the next burn's tickets.`})}),(0,R.jsxs)(`div`,{className:`flex flex-none items-center gap-3 border-t border-border-subtle px-4 py-3`,children:[(0,R.jsx)(Y,{variant:`secondary`,icon:a?(0,R.jsx)(ab,{}):(0,R.jsx)(Ly,{}),disabled:n,onClick:r,children:a?`Resume the conversation`:`Start the conversation`}),(0,R.jsx)(`span`,{className:`truncate text-xs text-text-tertiary`,children:`Every door resumes it`})]})]})})})}function h6({tag:e,details:t,children:n}){let r=Ab();return(0,R.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-md bg-danger-subtle px-4 py-3`,role:`alert`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-danger`,children:[(0,R.jsx)(tb,{size:16,className:`shrink-0`}),e]}),(0,R.jsx)(`p`,{className:`m-0 text-sm text-text-secondary`,children:n}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,R.jsx)(`code`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-text-tertiary`,title:t,children:t}),(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(Jy,{}),onClick:()=>NP(t,r),children:`Copy details`})]})]})}function g6({crumb:e,children:t}){return(0,R.jsxs)(`section`,{className:`flex min-h-0 min-w-0 flex-1 flex-col bg-surface`,children:[(0,R.jsx)(MA,{crumbs:[{label:e,icon:(0,R.jsx)(tb,{})}]}),(0,R.jsx)(PA,{children:t})]})}function _6({featureId:e,error:t}){return(0,R.jsx)(g6,{crumb:`Feature`,children:(0,R.jsx)(h6,{tag:`Broken`,details:`feature ${e} — ${t.name}: ${t.message}`,children:`This feature couldn't be rendered. Everything else still works.`})})}function v6({feature:e}){return(0,R.jsxs)(g6,{crumb:e.title,children:[(0,R.jsx)(FA,{title:e.title,meta:[{text:`Unknown phase`}]}),(0,R.jsx)(`div`,{className:`mt-8`,children:(0,R.jsxs)(h6,{tag:`Unrecognized phase`,details:`feature ${e.id} (${e.slug}) has phase "${e.phase}"`,children:[`This feature's phase is `,(0,R.jsx)(`strong`,{className:`font-mono font-medium text-text`,children:e.phase}),`, which this version of runcastle doesn't know. Nothing here can be acted on until the row is fixed.`]})})]})}function y6({step:e}){return e.state===`done`?(0,R.jsx)(xb,{phase:`shipped`,size:14,label:``}):e.state===`current`?(0,R.jsx)(xb,{phase:e.phase,size:14,label:``}):(0,R.jsx)(xb,{phase:`draft`,size:14,label:``,className:`text-text-tertiary`})}var b6={done:`text-text-secondary`,current:`font-medium text-text bg-[color-mix(in_srgb,var(--step-hue)_14%,transparent)]`,upcoming:`text-text-tertiary`};function x6({steps:e,onView:t,readonly:n=!1}){return(0,R.jsx)(`nav`,{"aria-label":`Pipeline`,className:`-ml-2 flex flex-wrap items-center gap-x-0.5 gap-y-1`,children:e.map((r,i)=>{let a=n&&r.isViewed;return(0,R.jsxs)(L.Fragment,{children:[(0,R.jsxs)(`button`,{type:`button`,className:q(`inline-flex h-(--control-sm) shrink-0 items-center gap-1.5 rounded-md px-2 text-xs`,`transition-colors duration-(--dur-1) ease-app`,b6[r.state],a&&`bg-surface-selected text-text`,r.clickable&&!a?`cursor-pointer hover:bg-surface-hover hover:text-text`:r.clickable?`cursor-pointer`:`cursor-default`),style:{"--step-hue":`var(--color-phase-${r.phase})`},title:r.tip,"aria-current":r.state===`current`?`step`:void 0,"aria-pressed":r.clickable?a:void 0,disabled:!r.clickable,onClick:()=>r.clickable&&t(r.phase),children:[(0,R.jsx)(y6,{step:r}),(0,R.jsx)(`span`,{children:vb[r.phase]})]}),i<e.length-1&&(0,R.jsx)(`span`,{"aria-hidden":`true`,className:`mx-0.5 h-px w-3 shrink-0 bg-border-strong`})]},r.phase)})})}function S6({feature:e,isDraft:t,steps:n,onViewPhase:r,readonly:i=!1,facts:a=[],className:o,children:s}){let c=Ab(),l=(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-4 gap-y-1.5`,children:[!t&&e.branch&&(0,R.jsxs)(`button`,{type:`button`,className:q(`inline-flex min-w-0 max-w-full cursor-pointer items-center gap-1.5 rounded-sm bg-transparent p-0`,`font-mono text-xs text-text-tertiary transition-colors duration-(--dur-1) ease-app hover:text-text`),title:`Copy branch name`,onClick:()=>NP(e.branch,c),children:[(0,R.jsx)(gy,{size:14,className:`shrink-0 text-icon`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.branch})]}),(0,R.jsx)(xA,{items:a})]});return(0,R.jsx)(FA,{title:e.title,meta:l,className:o,children:(!t||s)&&(0,R.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[!t&&(0,R.jsx)(x6,{steps:n,readonly:i,onView:t=>r(t===e.phase?null:t)}),s]})})}var C6={startDraft:(0,R.jsx)(Ly,{}),chat:(0,R.jsx)(Oy,{}),converge:(0,R.jsx)(By,{}),workNext:(0,R.jsx)(Iy,{}),resumeConverge:(0,R.jsx)(ab,{}),burn:(0,R.jsx)(Py,{}),cancelRun:(0,R.jsx)(Ry,{}),testDriveStart:(0,R.jsx)(Ly,{}),testDriveStop:(0,R.jsx)(Ry,{}),stopDriveAndIterate:(0,R.jsx)(Ry,{}),fixDrive:(0,R.jsx)(Dy,{}),merge:(0,R.jsx)(Ky,{}),resolveConflict:(0,R.jsx)(tb,{}),iterate:(0,R.jsx)(ab,{}),endSessionAndIterate:(0,R.jsx)(ab,{}),unarchive:(0,R.jsx)(Wy,{})},w6={danger:`danger`,note:`neutral`,clear:`success`};function T6(e){return/[.!?…:]$/.test(e)?e:`${e}.`}function E6({ns:e,guidance:t,busy:n,onAction:r,draftBranch:i,hideChat:a=!1,demote:o}){let s=a?e.secondary.filter(e=>e.kind!==`chat`):e.secondary,c=[...s,e.primary].filter(e=>!!e?.disabled),l=!!e.primary||s.length>0,u=s.filter(e=>!o?.includes(e.kind)),d=s.filter(e=>o?.includes(e.kind)),f=u.length>2?u.slice(0,2):u,p=[...u.length>2?u.slice(2):[],...d],m=c.filter(t=>!o?.includes(t.kind)||t===e.primary);if(!l&&!e.busy&&!e.alert&&!e.counts&&!e.note)return null;let h=e.title??(t?void 0:e.desc),g=t&&e.desc&&e.desc!==h?e.desc:void 0;return(0,R.jsxs)(`div`,{className:`flex flex-wrap items-start gap-x-6 gap-y-3 animate-fade-in`,role:e.alert?`alert`:void 0,children:[(0,R.jsxs)(`div`,{className:`min-w-0 flex-1 basis-80 text-sm text-text-secondary`,children:[(h||g)&&(0,R.jsxs)(`p`,{className:`m-0 text-pretty`,children:[e.busy?(0,R.jsx)(aE,{size:`sm`,className:`mr-2 inline-block align-[-2px]`}):e.alert?(0,R.jsx)(tA,{tone:`warning`,className:`mr-2 align-middle`}):null,h&&(0,R.jsx)(`span`,{className:`font-medium text-text`,children:g?T6(h):h}),h&&g&&` `,g]}),e.counts&&(0,R.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1`,children:[e.counts.pills.map(e=>(0,R.jsx)(rA,{tone:w6[e.tone],size:`sm`,children:e.label},e.label)),e.counts.trailing&&(0,R.jsx)(`span`,{className:`text-sm text-text-tertiary`,children:e.counts.trailing})]}),e.note&&(0,R.jsx)(`p`,{className:`mt-1.5 mb-0 text-xs text-text-tertiary first-letter:uppercase`,role:`note`,children:e.note})]}),l&&(0,R.jsxs)(`div`,{className:`ml-auto flex min-w-0 flex-col items-end gap-1.5`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-end gap-2`,children:[f.map((e,t)=>(0,R.jsx)(Y,{variant:`ghost`,icon:C6[e.kind],disabled:n||!!e.disabled,title:e.disabled??e.hint,onClick:()=>r(e.kind,e.waypointId),children:e.label},t)),p.length>0&&(0,R.jsxs)(DP,{children:[(0,R.jsx)(OP,{asChild:!0,children:(0,R.jsx)(nE,{label:`More actions`,icon:(0,R.jsx)(Ey,{}),disabled:n})}),(0,R.jsx)(kP,{align:`end`,children:p.map(e=>(0,R.jsx)(AP,{icon:C6[e.kind],disabled:!!e.disabled,title:e.disabled??e.hint,onSelect:()=>r(e.kind,e.waypointId),children:e.label},e.kind))})]}),e.primary&&(0,R.jsxs)(R.Fragment,{children:[i&&(0,R.jsx)(ij,{prefix:`from`,value:i.value,branches:i.branches,detected:i.detected,missing:i.missing,onPick:i.onPick}),(0,R.jsx)(Y,{variant:e.primary.danger?`danger`:`primary`,icon:C6[e.primary.kind],disabled:n||!!e.primary.disabled,title:e.primary.disabled??e.primary.hint,onClick:()=>r(e.primary.kind,e.primary.waypointId),children:n?`Working…`:e.primary.label})]})]}),m.map(e=>(0,R.jsxs)(`div`,{className:q(`flex flex-wrap items-center justify-end gap-2 text-right text-xs`,i&&e.kind===`startDraft`&&i.missing?`text-warning`:`text-text-tertiary`),children:[(0,R.jsx)(`span`,{children:e.disabled}),e.escape&&(0,R.jsx)(Y,{size:`sm`,variant:`secondary`,icon:C6[e.escape.kind],onClick:()=>r(e.escape.kind),disabled:n,children:e.escape.label})]},e.kind))]})]},`${e.title??``}|${e.primary?.kind??``}`)}function D6({phase:e,livePhase:t,facts:n,onBack:r}){return(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2 animate-fade-in`,role:`status`,children:[(0,R.jsxs)(`p`,{className:`m-0 min-w-0 flex-1 basis-60 text-sm text-text-secondary`,children:[(0,R.jsxs)(`span`,{className:`font-medium text-text`,children:[`Viewing `,vb[e].toLowerCase()]}),n?(0,R.jsxs)(`span`,{className:`text-text-tertiary`,children:[` — `,n]}):null]}),(0,R.jsxs)(Y,{variant:`ghost`,icon:(0,R.jsx)(rb,{}),onClick:r,children:[`Back to `,vb[t].toLowerCase()]})]})}function O6(e){let t=pF(e),[n,r]=(0,L.useState)(null),i=(0,L.useRef)(null);return(0,L.useEffect)(()=>{if(t.length===0)return;let e=t[t.length-1].id;if(i.current===null){i.current=e;return}let n=i.current;i.current=e;let a=t.filter(e=>e.id>n&&e.type===`session.resume_failed`),o=a[a.length-1];o&&r(o.message||`session resume failed — relaunch to continue`)},[t]),(0,L.useEffect)(()=>{if(!n)return;let e=setTimeout(()=>r(null),8e3);return()=>clearTimeout(e)},[n]),{message:n,dismiss:()=>r(null)}}var k6=`flex h-full min-h-0 min-w-0 flex-1 flex-col bg-surface`,A6=`runcastle.feature.details`;function j6(e){try{return sessionStorage.getItem(e)}catch{return null}}function M6(e,t){try{sessionStorage.setItem(e,t)}catch{}}function N6({featureId:e,viewedPhase:t,onViewPhase:n,guidance:r,mapRailCollapsed:i,onToggleMapRail:a,artifactPaneCollapsed:o,onToggleArtifactPane:s,chatPanelOpen:c,onToggleChatPanel:l,driving:u,onDriveChange:d,onDeleted:f,detailsOpen:p,onToggleDetails:m}){let h=B.useUtils(),g=Ab(),_=B.feature.get.useQuery({id:e},{refetchInterval:eh()}),v=O6(e),y=pF(e),b=Nd(y),x=wg(y),S=_.data?.feature.phase===`review`,C=B.feature.mergeDelta.useQuery({featureId:e},{refetchInterval:eh(5e3),enabled:S}),w=eh(),T=S?w:!1,E=B.notes.list.useQuery({featureId:e},{refetchInterval:T}),D=E.data?.filter(e=>e.status===`open`)??[],O=E.data?D.length:void 0,k=B.findings.listByFeature.useQuery({featureId:e},{refetchInterval:T}),A=k.data?.openDefects??[],j=k.data?.summary.open,M=Um(e,S),N=mv(M.data??[]),P=gv(N,{landedSince:N?.landedSince??0,lap:_.data?.feature.lap??1},_v(_.data?.tickets??[])),F=Ov({passes:M.data??[],tickets:_.data?.tickets??[],currentLap:_.data?.feature.lap??1}),[ee,te]=(0,L.useState)(!1),[ne,I]=(0,L.useState)(!1),re=!!_.data&&_.data.feature.phase!==`shipped`,ie=B.feature.burnWarnings.useQuery({featureId:e},{refetchInterval:eh(),enabled:re}),[ae,oe]=(0,L.useState)(null),se=B.notes.triagePreview.useQuery({featureId:e},{enabled:ae!==null}),ce=_.data?b_(_.data):void 0,le=B.docs.read.useQuery({featureId:e,relPath:ce??`map.md`},{enabled:!!ce}),ue=_.data?.feature.phase===`review`?jv(_.data):void 0,de=Nv(B.docs.read.useQuery({featureId:e,relPath:ue??`spec.md`},{enabled:!!ue}).data?.content),fe=_.data?.feature.projectId,pe=B.project.prep.useQuery({projectId:fe??``},{enabled:!!fe,refetchInterval:eh()}),me=B.feature.driveInfo.useQuery(void 0,{refetchInterval:eh()}),he=B.ticket.durationStats.useQuery({projectId:fe??``},{enabled:!!fe}),ge=mm(B.settings.get.useQuery({projectId:fe??``},{enabled:!!fe&&re}).data,`implement`),_e=_.data?.feature.phase===`planning`||_.data?.feature.phase===`building`,ve=B.docs.digestSize.useQuery({featureId:e},{enabled:_e}),ye=_.data?.feature.status===`draft`,be=B.project.branches.useQuery({projectId:fe??``},{enabled:!!fe&&ye}),[xe,Se]=(0,L.useState)(null),Ce=(xe?.featureId===e?xe.base:``)||(be.data?mg(be.data):``),we=!ye||Ce?void 0:be.data?`unpicked`:`loading`,Te=hF(vh(_.data?.runs??[])),Ee=gF(e,_F(_.data?.docs??[],`decisions.md`)).content,De=()=>{h.feature.get.invalidate({id:e}),h.feature.list.invalidate(),h.events.invalidate()},Oe=B.feature.launchSession.useMutation({onSuccess:De,onError:e=>g.push(e.message)}),ke=B.feature.burn.useMutation({onSuccess:()=>{De(),n(null)},onError:e=>g.push(e.message)}),Ae=B.feature.converge.useMutation({onSuccess:()=>{De(),n(null)},onError:e=>g.push(e.message)}),je=B.feature.workWaypoint.useMutation({onSuccess:De,onError:e=>g.push(e.message)}),Me=B.feature.endSession.useMutation({onError:e=>g.push(e.message)}),Ne=B.notes.triage.useMutation(),Pe=B.findings.dismiss.useMutation(),Fe=B.run.cancel.useMutation({onSuccess:e=>{De(),e.confirmed?g.push(`run cancelled — its agents are stopped`,`info`):g.push(N_)},onError:e=>g.push(e.message)}),Ie=B.feature.fixDrive.useMutation({onSuccess:De,onError:e=>g.push(e.message)}),Le=B.feature.testDrive.useMutation({onSuccess:e=>{if(De(),e.hookFailure){let t=e.hookFailure;g.push(`${t.phase===`setup`?`Test drive setup`:`Test drive teardown`} failed: ${t.command}${t.timedOut?` (timed out)`:``} — see the timeline for its output`)}e.dbDrift&&g.push(e.dbDrift.resetCommand?`Migrations differ between the branches — your dev database may be ahead. Rebuild it with: ${e.dbDrift.resetCommand}`:`Migrations differ between the branches — your dev database may be ahead. Set a database reset command in settings for a one-line fix here.`,`info`),e.carriedChanges?.length&&g.push(`${e.carriedChanges.length} uncommitted file(s) came back with you onto ${e.branch}`,`info`)},onError:e=>g.push(e.message)}),Re=B.feature.merge.useMutation({onSettled:De,onError:e=>g.push(e.message)}),ze=B.feature.unarchive.useMutation({onSuccess:()=>{De(),g.push(`feature unarchived`,`success`)},onError:e=>g.push(e.message)}),Be=B.feature.start.useMutation({onSuccess:(e,t)=>{De(),Oe.mutate({featureId:t.featureId,kind:`chat`})},onError:e=>g.push(e.message)}),Ve=mF(e,_.data?.feature.branch??``),[He,Ue]=(0,L.useState)(null),[We,Ge]=(0,L.useState)(()=>j6(A6)===`1`),Ke=p!==void 0,qe=Ke?p:We,Je=e=>{if(Ke){e!==p&&m?.();return}Ge(e),M6(A6,e?`1`:`0`)},[Ye,Xe]=(0,L.useState)(null),Ze=B.feature.archive.useMutation({onSuccess:()=>{De(),g.push(`feature archived`,`success`)},onError:e=>g.push(e.message)}),Qe=B.feature.delete.useMutation({onSuccess:()=>{h.feature.list.invalidate(),Xe(null),f?.()},onError:e=>g.push(e.message)});if(_.isLoading)return(0,R.jsxs)(`section`,{className:k6,children:[(0,R.jsx)(MA,{}),(0,R.jsx)(PA,{children:(0,R.jsx)(UA,{children:`Loading feature…`})})]});if(!_.data)return(0,R.jsxs)(`section`,{className:k6,children:[(0,R.jsx)(MA,{}),(0,R.jsx)(PA,{children:(0,R.jsxs)(WA,{children:[`Could not load the feature`,_.error?`: ${_.error.message}`:``]})})]});let $e=!!_.error,et=_.data,tt=et.feature;if(nd(tt.phase)===null)return(0,R.jsx)(v6,{feature:tt});let nt=sv(tt,t),rt=cv(tt,nt),it=lv(tt,nt,{planning:(e=>ey({phase:e,full:et,events:y,decisions:Ee}))(`planning`)}),at=vh(et.runs),ot=qg(y,at?.id),st=Te&&at?.id===Te&&nt===`review`?`building`:nt,ct=$_(et,{driving:u?.featureId===tt.id,driveState:me.data?.featureId===tt.id?me.data.state:`idle`,mapContent:le.data?.content,conflict:b,unverifiedDriveKeys:jp(pe.data?.findings??[]),...me.data&&me.data.featureId!==tt.id?{slotHolder:me.data.holderLabel}:{},...he.data?{burnStats:he.data}:{},...ve.data?{docsDigestBytes:ve.data.bytes}:{},...we?{draftBaseMissing:we}:{},openNotes:O,openDefects:j,...F?{unverifiedReview:{reason:F.reason}}:{},laterLaps:de,interruptedBurn:ot}),lt=Mg(et.sessions),ut=lt?.kind===`chat`?lt:void 0,dt=Be.isPending||Oe.isPending||ke.isPending||Ae.isPending||je.isPending||Fe.isPending||Le.isPending||Re.isPending||Ne.isPending||Pe.isPending||Ie.isPending||ze.isPending||Me.isPending||Ve.pending,ft=()=>{(O??0)+(j??0)>0?oe(Date.now()):Oe.mutate({featureId:e,kind:`chat`})},pt=async()=>{if(!lt)return!0;try{await Me.mutateAsync({sessionId:lt.id})}catch{return!1}return De(),!0},mt=async t=>{let{dismissFindingIds:n,...r}=t;try{for(let e of n)await Pe.mutateAsync({findingId:e});await Ne.mutateAsync({featureId:e,...r}),oe(null),De(),h.notes.list.invalidate({featureId:e}),h.findings.listByFeature.invalidate({featureId:e}),t.carry?await pt()&&Oe.mutate({featureId:e,kind:`chat`}):ke.mutate({featureId:e})}catch(e){g.push(e instanceof Error?e.message:String(e))}},ht=()=>{Oe.mutate({featureId:e,kind:`chat`})},gt=()=>{!c&&!ut&&ht(),c||Je(!1),l()},_t=(t,n)=>{switch(t){case`startDraft`:Be.mutate({featureId:e,baseBranch:Ce});break;case`chat`:gt();break;case`iterate`:ft();break;case`endSessionAndIterate`:pt().then(e=>{e&&ft()});break;case`converge`:case`resumeConverge`:Ae.mutate({featureId:e});break;case`workNext`:n&&je.mutate({featureId:e,waypointId:n});break;case`burn`:I(!0);break;case`cancelRun`:at&&Fe.mutate({runId:at.id});break;case`unarchive`:ze.mutate({featureId:e});break;case`testDriveStart`:Le.mutate({featureId:e,action:`start`},{onSuccess:t=>{De(),t.ok&&t.branch?d({featureId:e,branch:t.branch}):t.ok||g.push(t.deniedReason??`test drive denied`)}});break;case`testDriveStop`:Le.mutate({featureId:e,action:`stop`},{onSuccess:()=>{De(),d(null)}});break;case`stopDriveAndIterate`:Le.mutate({featureId:e,action:`stop`},{onSuccess:()=>{De(),d(null),ft()}});break;case`fixDrive`:Ie.mutate({featureId:e});break;case`merge`:te(!0);break;case`resolveConflict`:b&&Ve.resolve(b,lt?.id);break;default:}},vt=()=>{ke.mutate({featureId:e},{onSuccess:()=>I(!1)})},yt=()=>{Re.mutate({featureId:e},{onSuccess:e=>{if(De(),te(!1),e.ok)d(null),g.push(`merged — feature shipped`,`success`);else if(e.conflict){let t=e.files.length;g.push(t>0?`merge conflict in ${t} file${t===1?``:`s`} — resolve below and retry`:`merge conflict — resolve below and retry`)}}})},bt=st===`building`&&!at,xt=!ye&&et.tickets.length>0&&!bt,St=xt&&He?.featureId===e?He.view:`overview`,Ct=t=>Ue({featureId:e,view:t}),wt=e=>{Ct(`overview`),n(e)},Tt=Gg(et.tickets,tt.lap),Et=St===`overview`&&!ye&&st===`planning`&&!rt,Dt=!ye&&st!==`shipped`,Ot=`${e}:${ye?`draft`:st}:${St}`,kt=c?`chat`:qe?`details`:null,At=()=>{if(kt===`details`)return Je(!1);c&&l(),Je(!0)},jt=tt.status===`shipped`?Yv([...y]):null,Mt=[ye?{phase:`draft`,text:`Parked ${ph(tt.createdAt)}`}:jt?{tone:`success`,text:`Merged ${ph(jt)}`}:{text:`Started ${ph(tt.createdAt)}`},Tt.total>0&&st===`planning`&&{text:Kg(Tt)},tt.status===`archived`&&{tone:`neutral`,text:`Archived`},tt.lap>1&&{text:`Lap ${tt.lap}`,title:F_(tt.lap)}].filter(e=>!!e),Nt=[{key:`copy-link`,label:`Copy link`,onSelect:()=>NP(window.location.origin+Vh({kind:`feature`,projectId:tt.projectId,featureSlug:tt.slug}),g)},...!ye&&tt.branch?[{key:`copy-branch`,label:`Copy branch name`,onSelect:()=>NP(tt.branch,g)}]:[],...tt.status===`archived`?[{key:`unarchive`,label:`Unarchive`,onSelect:()=>ze.mutate({featureId:e})}]:tt.status===`draft`?[]:[{key:`archive`,label:`Archive`,onSelect:()=>Ze.mutate({featureId:e})}],...f&&tt.status!==`shipped`?[{key:`delete`,label:`Delete…`,danger:!0,onSelect:e=>Xe(e)}]:[]],Pt=rt?(0,R.jsx)(D6,{phase:nt,livePhase:tt.phase,facts:ty({phase:nt,full:et,events:y,decisions:Ee}),onBack:()=>wt(null)}):(0,R.jsx)(E6,{ns:ct,guidance:r,busy:dt,onAction:_t,hideChat:!0,...st===`planning`||st===`building`?{demote:[`merge`]}:{},draftBranch:ye?{branches:be.data?.branches,value:Ce||null,detected:be.data?.detected,missing:we===`unpicked`,onPick:t=>Se({featureId:e,base:t})}:void 0}),Ft=(0,R.jsxs)(S6,{feature:tt,isDraft:ye,steps:it,readonly:rt,facts:Mt,onViewPhase:wt,children:[v.message&&(0,R.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md bg-danger-subtle px-3 py-2 text-sm text-danger`,role:`alert`,children:[(0,R.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:`Resume failed.`}),` `,v.message]}),(0,R.jsx)(nE,{label:`Dismiss`,size:`sm`,icon:(0,R.jsx)(xy,{}),onClick:v.dismiss})]}),Pt]}),It=St===`tickets`?(0,R.jsx)(IA,{title:`Tickets`,children:(0,R.jsx)(S2,{full:et})}):ye?(0,R.jsx)(FG,{full:et}):(0,R.jsx)(P6,{effective:st,full:et,events:y,driving:u,conflict:b,runId:at?.id??null,readonly:rt,chatDocked:c,mapRailCollapsed:i,onToggleMapRail:a,onViewPhase:wt,artifactPaneCollapsed:o,onToggleArtifactPane:s});return(0,R.jsxs)(`section`,{className:q(k6,`overflow-clip`),"aria-label":tt.title,children:[(0,R.jsxs)(RA,{asideClassName:`@max-4xl:top-(--topbar-h)`,aside:kt===null?null:kt===`chat`?(0,R.jsx)(m6,{featureId:e,sessions:et.sessions,busy:Oe.isPending,onOpenChat:ht,onCollapse:l}):(0,R.jsx)(f6,{featureId:e,onClose:()=>Je(!1)}),children:[(0,R.jsx)(MA,{crumbs:[{label:tt.title,icon:(0,R.jsx)(xb,{phase:ye?`draft`:tt.phase,size:14,label:``})}],tabs:xt?(0,R.jsx)(CA,{label:`Feature views`,size:`sm`,value:St,onChange:Ct,items:[{id:`overview`,label:`Overview`,icon:(0,R.jsx)(Qy,{})},{id:`tickets`,label:`Tickets`,icon:(0,R.jsx)(Ny,{}),...Tt.total>0?{count:Tt.total}:{}}]}):void 0,actions:(0,R.jsxs)(R.Fragment,{children:[$e&&(0,R.jsx)(rA,{tone:`warning`,className:`mr-2`,title:`The server is unreachable — retrying`,children:`Offline, retrying`}),!ye&&(0,R.jsxs)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(Oy,{}),"aria-pressed":kt===`chat`,onClick:gt,disabled:Oe.isPending,children:[`Chat`,ut&&(0,R.jsx)(tA,{tone:`live`,label:`Chat session live`})]}),(0,R.jsx)(IP,{actions:Nt,size:`md`}),(0,R.jsx)(nE,{label:kt===`details`?`Hide details`:`Show details`,icon:(0,R.jsx)(hy,{}),active:kt===`details`,onClick:At})]})}),Et?(0,R.jsxs)(`div`,{className:`mx-auto flex min-h-0 w-full max-w-(--content-wide) min-w-0 flex-1 flex-col px-8 pt-12 animate-rise-in`,children:[(0,R.jsx)(`div`,{className:`shrink-0 pb-5`,children:Ft}),(0,R.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 pb-6`,children:It})]},Ot):(0,R.jsxs)(PA,{width:Dt?`wide`:`default`,routeKey:Ot,children:[Ft,(0,R.jsx)(`div`,{className:`mt-10`,children:It})]})]}),ne&&(0,R.jsx)(xF,{title:tt.title,branch:tt.branch,summary:Uv({branch:tt.branch,pendingTickets:Ug(et.tickets),lap:Vv(et.runs),...ge?{defaultModel:ge}:{},warnings:ie.data}),busy:ke.isPending,warningsPending:!ie.data,onConfirm:vt,onCancel:()=>I(!1)}),ee&&(0,R.jsx)(vF,{title:tt.title,branch:tt.branch,base:C.data?.base,summary:Bv({branch:tt.branch,...C.data?.base?{base:C.data.base}:{},...C.data?{delta:C.data}:{},tickets:et.tickets,lap:tt.lap,driveTaken:x,openNotes:O,...me.data?.projectDrive&&me.data.projectId===tt.projectId?{projectDrive:{holderLabel:me.data.holderLabel}}:{},freshness:P,conflict:b,laterLaps:de,burning:at?.status===`running`}),busy:Re.isPending,resolving:Ve.pending,onConfirm:yt,onResolve:b?()=>void Ve.resolve(b,lt?.id??void 0):void 0,onCancel:()=>te(!1)}),Ye&&(0,R.jsx)(LP,{title:tt.title,slug:tt.slug,busy:Qe.isPending,onConfirm:()=>Qe.mutate({featureId:e}),onCancel:()=>Xe(null),returnFocusRef:Ye}),ae!==null&&(0,R.jsx)(BF,{lap:tt.lap,notes:D,defects:A,standing:se.data?.standingFixTickets??[],openedAt:ae,busy:dt,readonly:rt,sessionLive:!!lt,onCommit:e=>void mt(e),onClose:()=>oe(null)})]})}function P6({effective:e,full:t,events:n,driving:r,conflict:i,runId:a,readonly:o,chatDocked:s,mapRailCollapsed:c,onToggleMapRail:l,onViewPhase:u,artifactPaneCollapsed:d,onToggleArtifactPane:f}){if(o&&e===`planning`)return(0,R.jsx)(x2,{full:t,effective:e,events:n,mapRailCollapsed:c,onToggleMapRail:l});switch(e){case`planning`:return(0,R.jsx)(L1,{full:t,effective:e,chatDocked:s,mapRailCollapsed:c,onToggleMapRail:l,artifactPaneCollapsed:d,onToggleArtifactPane:f});case`building`:return a?(0,R.jsx)(n6,{featureId:t.feature.id,runId:a,readonly:o,chatDocked:s}):(0,R.jsx)(_3,{featureId:t.feature.id,chatDocked:s});case`review`:return(0,R.jsx)(Q4,{full:t,driving:r,conflict:i,readonly:o,onViewPhase:u});case`shipped`:return(0,R.jsx)(m3,{full:t,chatDocked:s})}}function F6(e){let t=B.useUtils(),n=Ab(),r=B.project.sessionBranch.useQuery({projectId:e}),i=B.project.branches.useQuery({projectId:e,includeFeatureBranches:!0}),a=iy(r.data,i.data?.branches),o=B.settings.update.useMutation({onSuccess:()=>{t.project.sessionBranch.invalidate(),t.settings.get.invalidate()},onError:e=>n.push(e.message)});return{value:a?.value??null,branches:i.data?.branches,detected:r.data?.detected,missing:a?.origin===`vanished`,pick:t=>o.mutate({projectId:e,key:`sessionBranch`,value:t}),picking:o.isPending}}var I6=10,L6=8;function R6({conversations:e,pending:t,busy:n,onResume:r,onOpen:i,onView:a}){let[o,s]=(0,L.useState)(``),[c,l]=(0,L.useState)(!1),u=(0,L.useMemo)(()=>[...e].sort((e,t)=>Number(t.status!==`ended`)-Number(e.status!==`ended`)).map(e=>({c:e,title:i3(e.title)})),[e]);if(t)return null;let d=o.trim().toLowerCase(),f=d?u.filter(e=>e.title.toLowerCase().includes(d)):u,p=c||d?f:f.slice(0,I6),m=f.length-p.length;return(0,R.jsxs)(IA,{title:`Chats`,action:e.length>L6?(0,R.jsx)(DA,{icon:(0,R.jsx)(py,{}),placeholder:`Filter`,"aria-label":`Filter chats`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Escape`&&s(``)},className:`w-50`}):void 0,children:[e.length===0?(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(Oy,{}),title:`No chats yet`,hint:`A new chat starts from the row above.`}):p.length===0?(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(py,{}),title:`No chat matches`,hint:`Nothing titled “${o.trim()}”.`}):(0,R.jsx)(yA,{label:`Chats`,children:p.map(({c:e,title:t},o)=>{let s=e.status!==`ended`;return(0,R.jsx)(vA,{index:o,leading:s?(0,R.jsx)(tA,{tone:`live`,label:e.status}):(0,R.jsx)(Oy,{}),title:t,meta:e.createdAt===null?void 0:fh(e.createdAt),onClick:()=>a(e),actionsOverlay:!0,actions:(0,R.jsx)(nE,{size:`sm`,label:e.resumable?s?`Open`:`Reopen`:`Reopen — this one never got started`,"aria-label":s?`Open`:`Reopen`,icon:s?(0,R.jsx)(Iy,{}):(0,R.jsx)(ab,{}),disabled:n||!e.resumable,onClick:()=>s?i?.(e.id):r(e.id)})},e.id)})}),m>0&&(0,R.jsxs)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(wy,{}),className:`mt-2`,onClick:()=>l(!0),children:[`Show `,m,` more`]})]})}function z6({icon:e,title:t,status:n,hint:r,actions:i,caption:a,children:o,rule:s=!0,className:c}){return(0,R.jsxs)(`div`,{className:q(`py-4`,s&&`border-b border-border-subtle`,c),children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-3`,children:[(0,R.jsx)(`span`,{"aria-hidden":!0,className:`grid size-8 shrink-0 place-items-center rounded-md bg-surface-hover text-icon [&>svg]:size-4`,children:e}),(0,R.jsxs)(`div`,{className:`flex min-w-60 flex-1 flex-col`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,R.jsx)(`h2`,{className:`m-0 text-sm font-medium text-text`,children:t}),n]}),(0,R.jsx)(`p`,{className:`m-0 text-sm text-pretty text-text-tertiary`,children:r})]}),(0,R.jsxs)(`div`,{className:`ml-auto flex shrink-0 flex-col items-end gap-1`,children:[(0,R.jsx)(`div`,{className:`flex items-center gap-2`,children:i}),a&&(0,R.jsx)(`span`,{className:`max-w-[32ch] text-right text-xs text-text-tertiary`,children:a})]})]}),o]})}function B6({landing:e,onStart:t,starting:n,openSession:r}){return(0,R.jsx)(z6,{icon:(0,R.jsx)(By,{}),title:`Talk it through`,hint:`Bring a raw idea; the chat checks it against what’s built and cuts it into features.`,actions:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(ij,{prefix:`landing on`,value:e.value,branches:e.branches,detected:e.detected,missing:e.missing,disabled:e.picking,onPick:e.pick}),(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(yy,{}),loading:n,disabled:n||e.missing,title:e.missing?`the branch this chat would land on is gone — pick another`:void 0,onClick:t,children:`New chat`})]}),caption:e.missing?`The landing branch is gone — pick another.`:void 0,children:r&&(0,R.jsxs)(`div`,{role:`status`,className:`mt-3 ml-12 flex flex-wrap items-center gap-2 animate-rise-in`,children:[(0,R.jsx)(`span`,{className:`mr-auto text-sm text-text-secondary`,children:`A chat is already open.`}),(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(Oy,{}),onClick:r.onOpen,children:`Open it`}),(0,R.jsx)(Y,{size:`sm`,icon:(0,R.jsx)(ab,{}),loading:n,disabled:n,onClick:r.onReplace,children:`End it and start new`})]})})}function V6({lead:e,when:t,actions:n,className:r,children:i}){return(0,R.jsx)(vA,{as:`li`,animate:!0,wrap:!0,leading:e,title:(0,R.jsx)(`span`,{className:`flex flex-col`,children:i}),meta:t,actions:n,actionsOverlay:!0,className:q(`focus-within:bg-surface-hover hover:bg-surface-hover`,r)})}function H6(){return(0,R.jsx)(`span`,{className:`grid w-10 place-items-center`,"aria-hidden":!0,children:(0,R.jsx)(`i`,{className:`size-1.5 rounded-full bg-text-disabled`})})}function U6({note:e}){let t=Lb(e);return t?(0,R.jsx)(`span`,{className:`mt-0.5 font-mono text-xs text-text-tertiary`,title:t.title,children:t.label}):null}function W6({projectId:e,onTriage:t,triaging:n,reveal:r=!1,onRevealed:i}){let a=B.useUtils(),o=Ab(),s=B.projectNotes.list.useQuery({projectId:e},{refetchInterval:eh()}),c=B.feature.list.useQuery({projectId:e},{refetchInterval:eh()}),[l,u]=(0,L.useState)(null),[d,f]=(0,L.useState)(``),[p,m]=(0,L.useState)(null),h=e=>o.push(e.message),g=()=>void a.projectNotes.invalidate(),_=B.projectNotes.edit.useMutation({onSuccess:()=>{g(),u(null)},onError:h}),v=B.projectNotes.delete.useMutation({onSuccess:g,onError:h}),y=B.projectNotes.dismiss.useMutation({onSuccess:g,onError:h}),b=B.projectNotes.reopen.useMutation({onSuccess:g,onError:h}),x=s.data??[],S=_.isPending||v.isPending||y.isPending||b.isPending,C=K6(x.filter(e=>e.status===`open`)),w=K6(x.filter(e=>e.status===`triaged`)),T=(0,L.useRef)(null),E=x.length>0;if((0,L.useEffect)(()=>{!r||!T.current||(T.current.scrollIntoView?.({block:`center`}),i?.())},[r,E,i]),!E)return null;let D=e=>{d.trim()&&!_.isPending&&_.mutate({noteId:e,text:d})},O=e=>e.screenshotUrl?(0,R.jsx)(cj,{size:`sm`,url:e.screenshotUrl,onOpen:m}):(0,R.jsx)(H6,{});return(0,R.jsxs)(`section`,{ref:T,"aria-label":`Notes`,className:`flex flex-col`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3 px-4 pt-3 pb-2`,children:[(0,R.jsx)(`span`,{className:`min-w-0 flex-1 text-xs text-pretty text-text-tertiary`,children:`Grouped, questioned and routed in a triage chat.`}),(0,R.jsx)(Y,{size:`sm`,icon:(0,R.jsx)(By,{}),className:`shrink-0`,loading:n,disabled:C.length===0||n,title:C.length===0?`nothing is open to triage`:void 0,onClick:t,children:`Triage ${C.length}`})]}),C.length===0?(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(Uy,{}),title:`Inbox clear`,hint:`Every note has been triaged.`}):(0,R.jsx)(`ul`,{className:G6,children:C.map(e=>(0,R.jsx)(V6,{lead:O(e),when:fh(e.createdAt),actions:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(nE,{size:`sm`,label:`Edit`,icon:(0,R.jsx)(Ay,{}),onClick:()=>{u(e.id),f(e.text)}}),(0,R.jsx)(nE,{size:`sm`,label:`Dismiss`,icon:(0,R.jsx)(by,{}),disabled:S,onClick:()=>y.mutate({noteId:e.id})}),(0,R.jsx)(nE,{size:`sm`,label:`Delete`,icon:(0,R.jsx)(Sy,{}),variant:`danger-ghost`,disabled:S,onClick:()=>v.mutate({noteId:e.id})})]}),children:l===e.id?(0,R.jsx)(`input`,{"aria-label":`edit this note`,className:wA,value:d,autoFocus:!0,onChange:e=>f(e.target.value),onKeyDown:t=>{t.key===`Escape`?(t.preventDefault(),u(null)):t.key===`Enter`&&(t.preventDefault(),D(e.id))}}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-text`,children:e.text}),(0,R.jsx)(U6,{note:e})]})},e.id))}),w.length>0&&(0,R.jsx)(JA,{title:`${w.length} triaged`,className:`mx-4 mt-2`,children:(0,R.jsx)(`ul`,{className:`m-0 flex list-none flex-col p-0`,children:w.map(t=>(0,R.jsxs)(V6,{lead:t.screenshotUrl?O(t):null,actions:(0,R.jsx)(nE,{size:`sm`,label:`Reopen`,icon:(0,R.jsx)(Cy,{}),disabled:S,onClick:()=>b.mutate({noteId:t.id})}),children:[(0,R.jsx)(`span`,{className:`text-text-secondary`,children:t.text}),(0,R.jsx)(U6,{note:t}),(0,R.jsxs)(`span`,{className:`mt-0.5 flex flex-wrap items-baseline gap-x-2 text-xs text-text-tertiary`,children:[(0,R.jsx)(`span`,{children:t.outcome}),(0,R.jsx)(q6,{projectId:e,feature:c.data?.find(e=>e.id===t.featureId)})]})]},t.id))})}),(0,R.jsx)(CF,{url:p,onClose:()=>m(null)})]})}var G6=`m-0 flex list-none flex-col px-1 py-1`;function K6(e){return[...e].sort((e,t)=>t.createdAt-e.createdAt)}function q6({projectId:e,feature:t}){return t?(0,R.jsx)(`a`,{className:sE,href:Vh({kind:`feature`,projectId:e,featureSlug:t.slug}),children:t.title}):null}function J6({conversation:e,projectName:t=`Project`,onBack:n,onReopen:r,reopening:i,children:a}){let o=i3(e.title),s=e.status!==`ended`;return(0,R.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,R.jsx)(MA,{crumbs:[{label:t,icon:(0,R.jsx)(My,{}),onClick:n},{label:o,icon:(0,R.jsx)(Oy,{})}],actions:(0,R.jsx)(Y,{icon:s?(0,R.jsx)(Iy,{}):(0,R.jsx)(ab,{}),loading:i,disabled:i||!e.resumable,title:e.resumable?void 0:`this one never got started`,onClick:r,children:s?`Open`:`Reopen`})}),(0,R.jsxs)(PA,{routeKey:`transcript-${e.id}`,children:[(0,R.jsx)(FA,{title:o,meta:[e.createdAt!==null&&{icon:(0,R.jsx)(eb,{}),text:`Started ${ph(e.createdAt)}`},s&&{tone:`live`,text:`Open now`}]}),(0,R.jsx)(`div`,{className:`mt-8`,children:a})]})]})}function Y6({session:e,title:t,projectName:n=`Project`,branch:r,hidden:i,onBack:a,endControl:o,switcher:s,children:c}){let l=a3(jg(e)),u=e.status===`live`?`live`:e.status===`launching`?`accent`:`neutral`,d=e.ccSessionId??e.id;return(0,R.jsxs)(`div`,{className:i?`hidden`:`flex min-h-0 flex-1 flex-col`,"data-live-chat":!0,"aria-hidden":i,children:[(0,R.jsx)(MA,{crumbs:[{label:n,icon:(0,R.jsx)(My,{}),onClick:a},{label:i3(t),icon:(0,R.jsx)(Oy,{})}],tabs:s,actions:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`mr-2 hidden min-w-0 items-center gap-4 text-xs whitespace-nowrap text-text-tertiary md:flex`,children:[(0,R.jsx)(rA,{tone:u,children:l}),r&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,R.jsx)(Iy,{size:14,className:`text-icon`}),`lands on `,(0,R.jsx)(`span`,{className:`font-mono`,children:r})]}),(0,R.jsx)(`span`,{className:`hidden font-mono xl:inline`,title:d,children:d.slice(0,8)})]}),o]})}),(0,R.jsx)(`div`,{className:`min-h-0 flex-1 bg-surface-inset animate-fade-in`,children:c})]})}function X6({projectId:e,startedAt:t,onClose:n}){let r=B.projectNotes.list.useQuery({projectId:e},{refetchInterval:eh()}),[i,a]=(0,L.useState)(null),{thisDrive:o,alreadyOpen:s}=Ib(r.data??[],t),c=o.length+s.length;return(0,R.jsxs)(LA,{title:`Notes`,actions:c>0?(0,R.jsxs)(`span`,{className:`pr-1 text-xs text-text-tertiary tabular-nums`,title:`${c} open`,children:[c,` open`]}):void 0,onClose:n,bodyClassName:`flex flex-col`,children:[(0,R.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,R.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto pb-2`,children:[(0,R.jsx)(Z6,{title:`This drive`,children:o.length===0?(0,R.jsx)(Q6,{children:`Nothing yet. Select an area of the app, or type below.`}):o.map(e=>(0,R.jsx)($6,{note:e,onOpen:a},e.id))}),(0,R.jsx)(Z6,{title:`Already open`,children:s.length===0?(0,R.jsx)(Q6,{children:`No other open notes.`}):s.map(e=>(0,R.jsx)($6,{note:e,onOpen:a},e.id))})]}),(0,R.jsx)(e8,{projectId:e})]}),(0,R.jsx)(CF,{url:i,onClose:()=>a(null)})]})}function Z6({title:e,children:t}){return(0,R.jsxs)(`section`,{"aria-label":e,className:`pt-2`,children:[(0,R.jsx)(mA,{className:`px-4`,children:e}),(0,R.jsx)(`ul`,{className:`m-0 flex list-none flex-col px-1 py-0`,children:t})]})}function Q6({children:e}){return(0,R.jsx)(`li`,{className:`px-3 py-1.5 text-sm text-text-tertiary`,children:e})}function $6({note:e,onOpen:t}){return(0,R.jsxs)(V6,{lead:e.screenshotUrl?(0,R.jsx)(cj,{size:`sm`,url:e.screenshotUrl,onOpen:t}):(0,R.jsx)(H6,{}),when:fh(e.createdAt),children:[(0,R.jsx)(`span`,{className:`text-text`,children:e.text}),(0,R.jsx)(U6,{note:e})]})}function e8({projectId:e}){let t=B.useUtils(),n=Ab(),r=B.projectNotes.add.useMutation(),[i,a]=(0,L.useState)(``),[o,s]=(0,L.useState)(null),[c,l]=(0,L.useState)(!1),u=(0,L.useRef)(null);(0,L.useEffect)(()=>()=>URL.revokeObjectURL(o?.preview??``),[o]);let d=e=>{let t=Wm(e.clipboardData);t&&(e.preventDefault(),Gm(t).then(e=>s({png:e,preview:URL.createObjectURL(e)})).catch(e=>n.push(e instanceof Error?e.message:`that image could not be read`)))},f=async()=>{if(!(!i.trim()||c)){l(!0);try{let c=await r.mutateAsync({projectId:e,text:i});if(o)try{await Mb(c.id,o.png)}catch(e){n.push(`the note was saved, but its picture was not: ${e instanceof Error?e.message:String(e)}`)}t.projectNotes.invalidate(),a(``),s(null),u.current?.focus()}catch(e){n.push(e instanceof Error?e.message:`the note could not be saved`)}finally{l(!1)}}};return(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-border-subtle p-3`,onPaste:d,children:[(0,R.jsx)(DA,{ref:u,autoComplete:`off`,"aria-label":`New note`,placeholder:`What did you just notice?`,value:i,disabled:c,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f())}}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-text-tertiary`,children:[o?(0,R.jsxs)(`span`,{className:`inline-flex h-6 items-center gap-1.5 rounded-md bg-surface-hover pr-0.5 pl-1 text-text-secondary animate-pop-in`,children:[(0,R.jsx)(`img`,{src:o.preview,alt:`the picture this note will carry`,className:`h-4 w-6 rounded-sm bg-surface-inset object-cover`}),`Screenshot`,(0,R.jsx)(nE,{size:`sm`,label:`Remove the picture`,icon:(0,R.jsx)(xy,{}),onClick:()=>s(null)})]}):(0,R.jsx)(`span`,{children:`Paste a screenshot`}),(0,R.jsxs)(`span`,{className:`ml-auto flex items-center gap-1`,children:[(0,R.jsx)(Gb,{children:`↵`}),` save`]}),(0,R.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(Gb,{children:wj(`J`)}),` anywhere`]})]})]})}function t8({projectId:e,projectName:t=`Project`,repoPath:n,drive:r,hidden:i,onProjectPage:a,onStop:o,stopping:s,onOpenPreparation:c,switcher:l}){let[u,d]=(0,L.useState)(!0),f=Y_(r.state).stageKind,p=f===`failed`?(0,R.jsx)(rA,{tone:`danger`,children:`Setup failed`}):f===`starting`?(0,R.jsx)(rA,{spinning:!0,children:`Starting`}):(0,R.jsx)(rA,{tone:`live`,children:`Running`}),m=(0,R.jsx)(Y,{icon:(0,R.jsx)(Ry,{}),loading:s,disabled:s,onClick:o,children:`Stop drive`}),h=`${n??``}${r.commit?` @ ${r.commit}`:``}`;return(0,R.jsxs)(`div`,{className:i?`hidden`:`flex min-h-0 flex-1 flex-col`,"aria-hidden":i,"data-project-drive":!0,children:[(0,R.jsx)(MA,{crumbs:[{label:t,icon:(0,R.jsx)(My,{}),onClick:a},{label:`Test drive`,icon:(0,R.jsx)(Ly,{})}],tabs:l,actions:(0,R.jsxs)(R.Fragment,{children:[m,(0,R.jsx)(nE,{label:u?`Hide notes`:`Show notes`,icon:(0,R.jsx)(hy,{}),active:u,onClick:()=>d(e=>!e)})]})}),(0,R.jsx)(RA,{aside:u&&(0,R.jsx)(X6,{projectId:e,startedAt:r.startedAt,onClose:()=>d(!1)}),children:(0,R.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col gap-4 overflow-y-auto px-6 pt-5 pb-4 animate-fade-in`,children:[(0,R.jsxs)(`header`,{className:`flex flex-col gap-1.5`,children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,R.jsxs)(`h2`,{className:`m-0 text-lg font-semibold text-text`,children:[`Driving `,(0,R.jsx)(`span`,{className:`font-mono text-base font-medium`,children:r.branch})]}),p]}),(0,R.jsx)(xA,{items:[{icon:(0,R.jsx)(My,{}),mono:!0,text:h,title:h},{icon:(0,R.jsx)(ob,{}),mono:!0,text:`project-drive`,title:`the identity this drive runs as`}]})]}),(0,R.jsx)(n8,{projectId:e,drive:r,stop:m,onOpenPreparation:c}),(0,R.jsx)(W2,{branch:r.branch,drive:r})]})})]})}function n8({projectId:e,drive:t,stop:n,onOpenPreparation:r}){let i=W_(t);switch(Y_(t.state).stageKind){case`failed`:return i?(0,R.jsx)(i8,{children:(0,R.jsx)(U2,{failure:i,explanation:(0,R.jsxs)(R.Fragment,{children:[`Your checkout is as it was, but`,` `,(0,R.jsx)(`code`,{className:`font-mono text-xs`,children:i.command}),` `,i.outcome,` — so whatever it was meant to bring up is probably not running. Preparation is where this project’s drive commands are repaired and proven.`]}),children:(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(zy,{}),onClick:r,children:`Open preparation`}),n]})})}):(0,R.jsx)(i8,{children:(0,R.jsx)(GA,{icon:(0,R.jsx)(tb,{}),title:`The drive’s setup command failed`,hint:`Its output is in the timeline.`})});case`bare`:return(0,R.jsx)(i8,{children:(0,R.jsx)(GA,{icon:(0,R.jsx)(Dy,{}),title:`Setup ran — nothing started.`,hint:(0,R.jsxs)(R.Fragment,{children:[`This project has no dev command ·`,` `,(0,R.jsx)(p2,{location:{page:`project`,field:`devCommand`},children:`Set one in Settings`}),` `,`and the next drive boots the app right here.`]})})});case`panel`:case`agent`:return t.devUrl?(0,R.jsx)(`div`,{className:`flex min-h-100 flex-1 flex-col`,children:(0,R.jsx)(S4,{projectId:e,url:t.devUrl})}):(0,R.jsx)(i8,{children:(0,R.jsx)(GA,{icon:(0,R.jsx)(eb,{}),title:`Waiting for an address`,hint:`The dev server is up but has not printed an address yet — its output is under the stage.`})});default:return(0,R.jsx)(i8,{children:(0,R.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-center`,children:[(0,R.jsx)(rA,{tone:`live`,size:`sm`,strong:!0,children:`Starting the dev server…`}),(0,R.jsx)(`p`,{className:`m-0 max-w-[52ch] text-sm text-pretty text-text-tertiary`,children:`Your checkout is driven as it is and the project’s dev command is running. The app appears here as soon as it answers — its output is under the stage.`})]})})}}function r8({value:e,chat:t,drive:n,onPick:r}){return(0,R.jsx)(CA,{label:`Project views`,size:`sm`,value:e,onChange:r,items:[{id:`overview`,label:`Overview`,icon:(0,R.jsx)(My,{})},...t?[{id:`chat`,label:`Live chat`,icon:(0,R.jsx)(Oy,{})}]:[],...n?[{id:`drive`,label:`Drive`,icon:(0,R.jsx)(Ly,{})}]:[]]})}function i8({children:e}){return(0,R.jsx)(`div`,{className:`flex min-h-65 flex-1 flex-col justify-center rounded-md bg-surface-inset p-6`,children:e})}var a8=`project-drive`;function o8({card:e,branch:t,setupCommand:n,devCommand:r,stopCommand:i,starting:a,onStart:o,onPrepare:s,onReturn:c}){if(e.state===`hidden`)return null;let l=e.state===`running`,u=[{label:`Branch`,value:t??`…`,mono:!0,sub:`your checkout, as it is — no branch switch`},{label:`As`,value:a8,mono:!0},s8(`Setup`,n,`driveSetupCommand`),s8(`Dev`,r,`devCommand`),s8(`Stop`,i,`driveStopCommand`)];return(0,R.jsxs)(`section`,{"aria-label":`Test drive`,children:[(0,R.jsx)(z6,{icon:(0,R.jsx)(Ly,{}),title:`Test drive`,status:l?(0,R.jsx)(rA,{tone:`live`,children:`Running`}):void 0,hint:`Run everything that has shipped and jot what you notice. Notes land in the inbox.`,actions:e.state===`prepare`?(0,R.jsx)(Y,{icon:(0,R.jsx)(zy,{}),onClick:s,children:`Prepare drive`}):l?(0,R.jsx)(Y,{icon:(0,R.jsx)(Iy,{}),onClick:c,children:`Return to drive`}):(0,R.jsx)(Y,{icon:(0,R.jsx)(Ly,{}),loading:a,disabled:e.state===`blocked`||a,title:e.state===`blocked`?e.reason:void 0,onClick:o,children:`Test drive`}),caption:e.state===`blocked`?e.reason:e.state===`prepare`?`No setup or dev command yet.`:void 0,rule:!1}),(0,R.jsx)(JA,{title:`Drive setup`,icon:(0,R.jsx)(Dy,{}),aside:(0,R.jsxs)(`span`,{className:`font-mono`,children:[a8,` · `,t??`…`]}),children:(0,R.jsx)(`div`,{className:`rounded-md border border-border-subtle bg-surface-inset px-4 py-3`,children:(0,R.jsx)(bA,{items:u,className:`gap-x-8`})})})]})}function s8(e,t,n){return t?.trim()?{label:e,value:t,mono:!0}:{label:e,value:(0,R.jsxs)(`span`,{className:`font-normal text-text-tertiary`,children:[`Nothing set ·`,` `,(0,R.jsx)(p2,{location:{page:`project`,field:n},children:`Settings`})]})}}function c8(e){let t=B.useUtils(),n=Ab(),r=B.feature.driveInfo.useQuery(void 0,{refetchInterval:eh()}),i=B.project.testDrive.useMutation({onSuccess:()=>void t.feature.driveInfo.invalidate(),onError:e=>n.push(e.message)}),a=r.data??null,o=(t,r)=>i.mutate({projectId:e,action:t},{onSuccess:e=>{e.ok?r?.():n.push(e.deniedReason??`the drive could not ${t}`)}});return{slot:a,drive:Pb(a,e)?a:null,start:e=>o(`start`,e),stop:e=>o(`stop`,e),starting:i.isPending&&i.variables?.action===`start`,stopping:i.isPending&&i.variables?.action===`stop`}}function l8({projectId:e,talk:t,newChatRequest:n=0,onConsumeNewChatRequest:r,inboxRequest:i=0,onConsumeInboxRequest:a,empty:o=!1,onOpenPreparation:s,driveRequest:c=0,onConsumeDriveRequest:l}){let u=B.useUtils(),d=B.project.list.useQuery().data?.find(t=>t.id===e),f=F6(e),p=B.project.branches.useQuery({projectId:e,includeFeatureBranches:!0}),m=c8(e),h=m.drive,g=t.session,[_,v]=(0,L.useState)(null),y=B.projectNotes.list.useQuery({projectId:e},{refetchInterval:eh()}),[b,x]=(0,L.useState)(null),[S,C]=(0,L.useState)(!!(g&&n>0)),[w,T]=(0,L.useState)(`chat`),[E,D]=(0,L.useState)(!!(g&&n>0)),[O,k]=(0,L.useState)(void 0);(0,L.useEffect)(()=>{n>0&&g&&(C(!0),D(!0),k(void 0),r?.())},[n,r,g]),(0,L.useEffect)(()=>{i>0&&(v(null),C(!0),x(!0))},[i]),(0,L.useEffect)(()=>{g||(D(!1),k(void 0))},[g]);let A=g?.id;(0,L.useEffect)(()=>{A&&T(`chat`)},[A]);let j=()=>{v(null),C(!1),T(`drive`)},M=()=>{C(!1),T(`chat`)},N=()=>{T(`chat`),g&&C(!0)};(0,L.useEffect)(()=>{c>0&&(j(),l?.())},[c,l]);let P=_,F=P!==null||S||!g&&!(h&&w===`drive`),ee=!!h&&!F&&(w===`drive`||!g),te=!!g&&!F&&!ee,ne=g||h?(0,R.jsx)(r8,{value:ee?`drive`:te?`chat`:`overview`,chat:!!g,drive:!!h,onPick:e=>{e===`overview`?(v(null),N()):e===`chat`?(v(null),M()):j()}}):void 0,I=e=>{t.resume(e),v(null),M()},re=d?.name??`This project`,ie=(y.data??[]).filter(e=>e.status===`open`).length,ae=(y.data??[]).length>0,oe=ae&&(b??ie>0);return(0,R.jsxs)(`section`,{className:`flex h-full min-h-0 min-w-0 flex-1 flex-col`,children:[(0,R.jsx)(`div`,{className:F?`flex min-h-0 flex-1 flex-col`:`hidden`,hidden:!F,children:P?(0,R.jsx)(J6,{conversation:P,projectName:re,onBack:()=>v(null),onReopen:()=>{P.status===`ended`?I(P.id):(v(null),M())},reopening:t.starting,children:(0,R.jsx)(d3,{sessionId:P.id})}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(MA,{crumbs:[{label:re,icon:(0,R.jsx)(My,{})}],tabs:ne,actions:(0,R.jsx)(R.Fragment,{children:ae&&(0,R.jsx)(nE,{label:`Notes`,badge:ie,icon:(0,R.jsx)(hy,{}),active:oe,onClick:()=>x(!oe)})})}),(0,R.jsx)(RA,{aside:oe&&(0,R.jsx)(LA,{title:`Notes`,onClose:()=>x(!1),children:(0,R.jsx)(W6,{projectId:e,triaging:t.starting,reveal:i>0,onRevealed:a,onTriage:()=>{if(!g){t.triage();return}k(`triage`),D(!0)}})}),children:(0,R.jsxs)(PA,{routeKey:`project-${e}`,children:[(0,R.jsx)(FA,{title:re,meta:[{icon:(0,R.jsx)(gy,{}),text:ny,mono:!0,title:`the branch project chats run on`},f.value?{icon:(0,R.jsx)(Iy,{}),text:`lands on ${f.value}`}:null]}),(0,R.jsxs)(`div`,{className:`mt-8`,children:[(0,R.jsx)(B6,{landing:f,onStart:t.start,starting:t.starting,openSession:g&&E?{onOpen:()=>{D(!1),k(void 0),M()},onReplace:()=>{D(!1),t.replace(O),M()}}:void 0}),(0,R.jsx)(o8,{card:Fb({empty:o||!d,setupCommand:d?.driveSetupCommand,devCommand:d?.devCommand,drive:m.slot,projectId:e}),branch:h?.branch??(p.data?.current||null),setupCommand:d?.driveSetupCommand,devCommand:d?.devCommand,stopCommand:d?.driveStopCommand,starting:m.starting,onStart:()=>m.start(j),onPrepare:()=>s?.(),onReturn:j})]}),(0,R.jsx)(R6,{conversations:t.conversations,pending:t.conversationsPending,busy:t.starting,onResume:I,onOpen:M,onView:v})]})})]})}),h&&(0,R.jsx)(t8,{projectId:e,projectName:re,repoPath:d?.repoPath,drive:h,hidden:!ee,onProjectPage:N,onStop:()=>m.stop(N),stopping:m.stopping,onOpenPreparation:()=>s?.(),switcher:ne}),g&&(0,R.jsx)(Y6,{session:g,projectName:re,title:u8(t.conversations,g.id)??`project`,branch:f.value,hidden:!te,switcher:ne,onBack:()=>{D(!1),C(!0)},endControl:(0,R.jsx)(IG,{sessionId:g.id,onEnded:()=>{u.project.projectSession.invalidate(),u.project.conversations.invalidate()}}),children:(0,R.jsx)(LG,{label:`terminal`,children:(0,R.jsx)(_1,{sessionId:g.id})})})]})}function u8(e,t){return e.find(e=>e.id===t)?.title??null}function d8({dirty:e,onDismiss:t,children:n}){return(0,R.jsx)(QA,{open:!0,onClose:t,dirty:e,inline:!0,labelledBy:`park-draft-title`,backdropClassName:`min-h-0 overflow-y-auto bg-surface`,className:`max-w-[560px]`,children:n})}function f8({title:e,slug:t,oneLiner:n,notes:r,duplicate:i,busy:a,ready:o,onTitleChange:s,onOneLinerChange:c,onNotesChange:l,onSubmit:u,onCancel:d}){let f=()=>u(r.trim()||void 0);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)($A,{id:`park-draft-title`,title:`Park it for later`,description:`Write it down now, work it out later. Nothing is cut until you Start it.`,onClose:d}),(0,R.jsxs)(ej,{className:`flex flex-col gap-4 pt-1`,children:[(0,R.jsx)(AA,{label:`Title`,error:i,children:(0,R.jsx)(DA,{value:e,onChange:e=>s(e.target.value),placeholder:`e.g. Slack alerts on failed runs`,autoFocus:!0,invalid:!!i,onKeyDown:e=>{e.key===`Enter`&&f()}})}),(0,R.jsx)(AA,{label:`One-liner (optional)`,children:(0,R.jsx)(DA,{value:n,onChange:e=>c(e.target.value),placeholder:`What and why, in a sentence`,onKeyDown:e=>{e.key===`Enter`&&f()}})}),(0,R.jsx)(AA,{label:`Notes (optional — becomes the brief)`,children:(0,R.jsx)(kA,{rows:5,value:r,onChange:e=>l(e.target.value),placeholder:`Anything Start should know`})})]}),(0,R.jsxs)(tj,{className:`mt-2 border-t border-border-subtle pt-4`,start:(0,R.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,children:[(0,R.jsx)(gy,{size:14,className:`shrink-0 text-icon`}),(0,R.jsxs)(`span`,{className:`truncate font-mono`,children:[`feature/`,t||`…`,` · draft`]})]}),children:[(0,R.jsx)(Y,{variant:`ghost`,onClick:d,disabled:a,children:`Cancel`}),(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(ky,{}),onClick:f,disabled:!o||a,children:a?`Parking…`:`Park draft`})]})]})}function p8({projectId:e,onCancel:t,onCreated:n}){let[r,i]=(0,L.useState)(``),[a,o]=(0,L.useState)(``),[s,c]=(0,L.useState)(``),l=B.useUtils(),u=Ab(),d=gg(r,B.feature.list.useQuery({projectId:e},{refetchInterval:eh()}).data??[]),f=async e=>{await l.feature.list.invalidate(),n(e)},p=B.feature.create.useMutation({onSuccess:e=>void f(e.id),onError:e=>u.push(e.message)}),m=p.isPending,h=!!r.trim(),g=!!r.trim()||!!a.trim()||!!s.trim(),_=t=>{!h||m||p.mutate({projectId:e,title:r.trim(),oneLiner:a.trim(),draft:!0,...t?{brief:t}:{}})};return(0,R.jsx)(d8,{dirty:g,onDismiss:t,children:e=>(0,R.jsx)(f8,{title:r,slug:hg(r),oneLiner:a,notes:s,duplicate:d,busy:m,ready:h,onTitleChange:i,onOneLinerChange:o,onNotesChange:c,onSubmit:_,onCancel:e})})}var m8=`Repo facts an agent establishes once — how to install, how to verify, what is already red — so no burn agent re-derives them per ticket.`;function h8({projectId:e,onClose:t}){let n=B.useUtils(),r=Ab(),i=B.project.list.useQuery().data?.find(t=>t.id===e),a=B.project.prep.useQuery({projectId:e},{refetchInterval:eh(3e3)}),o=B.project.prepSession.useQuery({projectId:e},{refetchInterval:eh()}),s=B.project.talkToPrep.useMutation({onSuccess:()=>void n.project.prepSession.invalidate(),onError:e=>r.push(e.message)}),c=B.project.dryRunStop.useMutation({onSuccess:()=>{n.project.prep.invalidate(),n.feature.driveInfo.invalidate()},onError:e=>r.push(e.message)}),[l,u]=(0,L.useState)(!1),d=a.data,f=o.data??null,p=d?.findings??[],m=d?.pendingKeys??[],h=p.filter(Fp).length,g=f?f.ccSessionId??f.id:``;return(0,R.jsxs)(`section`,{className:`flex h-full min-h-0 min-w-0 flex-1 flex-col`,children:[(0,R.jsx)(MA,{crumbs:[{label:i?.name??`This project`,icon:(0,R.jsx)(My,{}),...t?{onClick:t}:{}},{label:`Preparation`,icon:(0,R.jsx)(zy,{})}],actions:f?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`mr-2 hidden items-center gap-4 text-xs text-text-tertiary md:flex`,children:[(0,R.jsx)(rA,{tone:f.status===`live`?`live`:`accent`,children:a3(jg(f))}),(0,R.jsx)(`span`,{className:`font-mono`,title:g,children:g.slice(0,8)})]}),(0,R.jsx)(IG,{sessionId:f.id,onEnded:()=>{n.project.prepSession.invalidate(),n.project.prep.invalidate()}}),p.length>0&&(0,R.jsx)(nE,{label:l?`Hide what is established`:`Show what is established`,icon:(0,R.jsx)(hy,{}),active:l,onClick:()=>u(e=>!e)})]}):void 0}),d?.dryRun&&(0,R.jsx)(v8,{open:B_(d.dryRun),stopping:c.isPending,onStop:()=>c.mutate({projectId:e})}),f?(0,R.jsx)(RA,{aside:l&&p.length>0&&(0,R.jsx)(LA,{title:`Established`,onClose:()=>u(!1),bodyClassName:`px-4 py-3`,children:(0,R.jsx)(_8,{findings:p,staleCount:h,compact:!0})}),children:(0,R.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 bg-surface-inset animate-fade-in`,children:(0,R.jsx)(LG,{label:`terminal`,children:(0,R.jsx)(_1,{sessionId:f.id})})})}):(0,R.jsxs)(PA,{routeKey:`prepare-${e}`,children:[a.isLoading&&(0,R.jsx)(UA,{children:`Loading preparation…`}),a.error&&(0,R.jsx)(GA,{icon:(0,R.jsx)(tb,{}),title:`Could not load preparation`,hint:a.error.message}),d&&(0,R.jsx)(g8,{prepared:d.prepared,preparedAt:d.preparedAt,pending:m,findings:p,staleCount:h,starting:s.isPending,onStart:()=>s.mutate({projectId:e}),onStartFresh:()=>s.mutate({projectId:e,fresh:!0})})]})]})}function g8({prepared:e,preparedAt:t,pending:n,findings:r,staleCount:i,starting:a,onStart:o,onStartFresh:s}){let c=r.length>0,l=[e&&{icon:(0,R.jsx)(eb,{}),text:t===null?`No preparation conversation on record`:`Prepared ${kp(t)}`},!e&&n.length>0&&{strong:n.length,text:`to establish`},c&&{strong:r.length,text:`established`},i>0&&{tone:`warning`,strong:i,text:`stale`}];return e?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(FA,{title:`Re-prepare this project`,meta:l,children:[(0,R.jsxs)(`p`,{className:`m-0 max-w-[60ch] text-base text-pretty text-text-secondary`,children:[t===null&&`Every field already had a value. `,m8,` Repo facts drift; re-preparing measures them again with you there.`]}),(0,R.jsxs)(`div`,{className:`mt-6 flex flex-wrap items-center gap-2`,children:[(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(ab,{}),loading:a,disabled:a,onClick:o,children:`Resume`}),(0,R.jsx)(Y,{icon:(0,R.jsx)(yy,{}),disabled:a,onClick:s,children:`Start fresh`})]}),(0,R.jsx)(`p`,{className:`mt-2 mb-0 max-w-[60ch] text-xs text-pretty text-text-tertiary`,children:`Resume continues your last preparation conversation; Start fresh opens one that has never seen it — values you typed by hand are never overwritten.`})]}),(0,R.jsx)(_8,{findings:r,staleCount:i})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(FA,{title:c?`Finish preparing this project`:`Prepare this project first`,meta:l,children:[(0,R.jsx)(`p`,{className:`m-0 max-w-[60ch] text-base text-pretty text-text-secondary`,children:m8}),(0,R.jsx)(`div`,{className:`mt-6 flex flex-wrap items-center gap-2`,children:(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(Ly,{}),loading:a,disabled:a,onClick:o,children:`Start preparation`})}),(0,R.jsx)(`p`,{className:`mt-2 mb-0 max-w-[60ch] text-xs text-pretty text-text-tertiary`,children:`Opens a terminal session here with an agent in your own checkout — it runs this repo's commands, records the answers, and asks you the ones only you know.`})]}),n.length>0&&(0,R.jsx)(IA,{title:`To establish`,children:(0,R.jsx)(yA,{divided:!0,label:`To establish`,children:n.map((e,t)=>(0,R.jsx)(vA,{index:t,leading:(0,R.jsx)(sb,{}),title:Dp[e]??e,meta:`Not yet`},e))})}),(0,R.jsx)(_8,{findings:r,staleCount:i})]})}function _8({findings:e,staleCount:t,compact:n=!1}){if(e.length===0)return null;let r=(0,R.jsxs)(R.Fragment,{children:[t>0&&(0,R.jsx)(y8,{count:t}),(0,R.jsx)(b8,{findings:e})]});return n?r:(0,R.jsx)(IA,{title:`Established`,children:r})}function v8({open:e,stopping:t,onStop:n}){return(0,R.jsxs)(`div`,{className:`flex h-10 shrink-0 items-center gap-3 border-b border-border-subtle px-4 animate-fade-in`,children:[(0,R.jsx)(rA,{tone:`live`,size:`sm`,strong:!0,children:`Preparation dry run in progress`}),e&&(e.state===`ready`?(0,R.jsxs)(`a`,{className:q(`cursor-pointer text-accent-text no-underline decoration-accent-text/50 underline-offset-2 transition-colors duration-(--dur-1) ease-app hover:underline hover:decoration-accent-text`,`inline-flex min-w-0 items-center gap-1 truncate font-mono text-xs`),href:e.url,target:`_blank`,rel:`noreferrer`,children:[e.url,(0,R.jsx)(qy,{size:12,className:`shrink-0`})]}):(0,R.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs text-text-tertiary`,children:V_(e)})),(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(Ry,{}),loading:t,disabled:t,onClick:n,children:`Stop`})]})}function y8({count:e}){return(0,R.jsxs)(`div`,{className:`mb-4 flex max-w-[64ch] items-start gap-2 text-sm text-pretty text-text-secondary`,children:[(0,R.jsx)(tb,{size:16,className:`mt-0.5 shrink-0 text-warning`}),(0,R.jsxs)(`span`,{children:[e,` finding`,e===1?` has`:`s have`,` not been re-measured in a long time. A stale test baseline is worse than none — agents trust it and file their own breakage under “already red on main”.`]})]})}function b8({findings:e}){return(0,R.jsx)(`div`,{className:`flex flex-col [&>details:last-child]:border-b [&>details:last-child]:border-border-subtle`,children:e.map((e,t)=>(0,R.jsx)(x8,{finding:e,label:Dp[e.key]??e.key,index:t},e.key))})}function x8({finding:e,label:t,index:n}){let[r,i]=(0,L.useState)(!1),a=Ip(e),o=Fp(e);return(0,R.jsx)(JA,{title:t,index:n,aside:(0,R.jsxs)(`span`,{className:`flex items-center gap-4`,children:[o&&(0,R.jsx)(rA,{tone:`warning`,children:`Stale`}),(0,R.jsx)(S8,{finding:e}),(0,R.jsx)(rA,{title:a.title,children:a.label})]}),children:(0,R.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,R.jsx)(`div`,{className:q(`text-xs`,o?`text-warning`:`text-text-tertiary`),children:Mp(e)}),e.evidence&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`div`,{className:`rounded-md border border-border-subtle bg-surface-inset px-3 py-2`,children:(0,R.jsx)(`div`,{className:q(`font-mono text-xs leading-[1.5] break-words whitespace-pre-wrap text-text-secondary`,!r&&`line-clamp-3`),children:e.evidence})}),(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,className:`-ml-2 self-start`,onClick:()=>i(e=>!e),"aria-expanded":r,"aria-label":`${r?`Collapse`:`Show full`} evidence for ${t}`,children:r?`Show less`:`Show full evidence`})]})]})})}function S8({finding:e}){return Ap(e.key)?e.verifiedAt===void 0?(0,R.jsx)(rA,{tone:`warning`,title:`No dry run has ever proven this value — a drive that depends on it may fall over`,children:`Unproven`}):(0,R.jsxs)(rA,{tone:`success`,icon:(0,R.jsx)(by,{size:14}),title:`A preparation dry run ran this value on the real drive machinery and it worked`,children:[`Proven `,kp(e.verifiedAt)]}):null}var C8=(e,t)=>e===``||t.includes(e);function w8(e){let{open:t,onClose:n,features:r,selectedFeatureId:i,onSelect:a,onOpenSettings:o,onOpenPreparation:s,onOpenProjectChat:c,onOpenNote:l,onToggleSidebar:u,onToggleDetails:d,nav:f}=e,p=nM(),[m,h]=(0,L.useState)(``),[g,_]=(0,L.useState)(0),v=(0,L.useRef)(null),y=(0,L.useRef)([]);(0,L.useEffect)(()=>{if(!t)return;h(``),_(0),v.current?.focus();let e=requestAnimationFrame(()=>v.current?.focus());return()=>cancelAnimationFrame(e)},[t]),(0,L.useEffect)(()=>{if(!t)return;let e=e=>{e.key!==`Escape`||e.defaultPrevented||(e.preventDefault(),n())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,n]),(0,L.useEffect)(()=>{_(0)},[m]);let b=m.trim().toLowerCase(),x=(0,L.useMemo)(()=>b===``?r:r.filter(e=>e.slug.toLowerCase().includes(b)||e.title.toLowerCase().includes(b)),[r,b]),S=(0,L.useMemo)(()=>(f.projects??[]).filter(e=>e.id!==f.currentProjectId),[f.projects,f.currentProjectId]),C=(0,L.useMemo)(()=>b===``?S:S.filter(e=>e.name.toLowerCase().includes(b)),[S,b]),w=(0,L.useMemo)(()=>{let e=p.resolved===`dark`?`light`:`dark`;return[{kind:`projectChat`,shows:dy(b),glyph:(0,R.jsx)(Qy,{}),label:`Project chat`,run:c},{kind:`newNote`,shows:C8(b,`new note jot capture`),glyph:(0,R.jsx)(Ay,{}),label:`New note`,kbd:wj(`J`),run:l},{kind:`preparation`,shows:uy(b),glyph:(0,R.jsx)(zy,{}),label:`Preparation`,run:s},{kind:`settings`,shows:C8(b,`settings preferences`),glyph:(0,R.jsx)(my,{}),label:`Settings`,run:o},{kind:`theme`,shows:C8(b,`toggle theme dark light appearance ${e}`),glyph:p.resolved===`dark`?(0,R.jsx)(Yy,{}):(0,R.jsx)(Xy,{}),label:`Toggle theme — switch to ${e}`,run:p.toggle},...u?[{kind:`sidebar`,shows:C8(b,`toggle sidebar hide show collapse expand`),glyph:(0,R.jsx)(Gy,{}),label:`Toggle sidebar`,kbd:wj(`B`),run:u}]:[],...d?[{kind:`details`,shows:C8(b,`toggle details panel inspector hide show`),glyph:(0,R.jsx)(hy,{}),label:`Toggle details panel`,run:d}]:[],{kind:`home`,shows:C8(b,`all projects home`),glyph:(0,R.jsx)(My,{}),label:`All projects`,run:f.goHome},{kind:`openProject`,shows:C8(b,`open a project`),glyph:(0,R.jsx)(yy,{}),label:`Open a project…`,run:f.showOpen}].filter(e=>e.shows)},[b,p.resolved,p.toggle,c,l,o,s,u,d,f]),T=(0,L.useMemo)(()=>{let e=x.map(e=>({kind:`feature`,feature:e}));for(let t of C)e.push({kind:`project`,id:t.id,name:t.name});for(let t of w)e.push({kind:`action`,action:t});return e},[x,C,w]);if(!t)return null;let E=e=>{if(T.length===0)return;let t=(g+e+T.length)%T.length;_(t),y.current[t]?.scrollIntoView({block:`nearest`})},D=e=>{let t=T[e];if(t){switch(t.kind){case`feature`:a(t.feature.id);break;case`project`:f.enterProject(t.id);break;case`action`:t.action.run();break}n()}},O=e=>{e.key===`ArrowDown`?(e.preventDefault(),E(1)):e.key===`ArrowUp`?(e.preventDefault(),E(-1)):e.key===`Enter`?(e.preventDefault(),D(g)):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),n())},k=x.length,A=k+C.length,j=(e,t,n,r,i,a)=>(0,R.jsxs)(`div`,{ref:t=>{y.current[e]=t},role:`option`,"aria-selected":e===g,"data-selected":e===g,className:q(Bb,Vb,`min-h-8 hover:bg-transparent`),onMouseMove:()=>e!==g&&_(e),onClick:()=>D(e),children:[(0,R.jsx)(`span`,{className:`inline-flex size-4 shrink-0 items-center justify-center [&>svg]:size-4`,children:n}),(0,R.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:a,children:r}),i]},t),M=e=>(0,R.jsx)(`div`,{className:q(Ub,`pt-2.5`),children:e});return(0,R.jsx)(`div`,{className:`fixed inset-0 z-[300] flex animate-backdrop-in items-start justify-center bg-scrim px-4 pt-[12vh] pb-4`,onMouseDown:e=>{e.target===e.currentTarget&&n()},children:(0,R.jsxs)(`div`,{role:`dialog`,"aria-label":`Command palette`,className:`flex max-h-[min(520px,76vh)] w-full max-w-[560px] animate-dialog-in flex-col overflow-hidden rounded-lg bg-surface-raised text-text shadow-dialog`,children:[(0,R.jsxs)(`div`,{className:`flex h-13 shrink-0 items-center gap-3 border-b border-border-subtle px-4`,children:[(0,R.jsx)(py,{size:16,className:`shrink-0 text-icon`}),(0,R.jsx)(`input`,{ref:v,className:`h-full min-w-0 flex-1 border-0 bg-transparent p-0 font-sans text-base text-text outline-none placeholder:text-text-tertiary`,placeholder:`Search features, projects, or jump to…`,value:m,onChange:e=>h(e.target.value),onKeyDown:O,"aria-label":`Search features, projects, or jump to`})]}),(0,R.jsxs)(`div`,{role:`listbox`,"aria-label":`Results`,className:`min-h-0 flex-1 overflow-y-auto p-1.5`,children:[x.length>0&&M(`Features`),x.map((e,t)=>j(t,e.id,(0,R.jsx)(xb,{phase:e.status===`draft`?`draft`:e.phase,label:``}),e.title,(0,R.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2 text-xs text-text-tertiary`,children:[e.id===i&&(0,R.jsx)(`span`,{className:`text-text-secondary`,children:`Current`}),(0,R.jsx)(`span`,{children:e.status===`draft`?vb.draft:vb[e.phase]})]}),e.title)),C.length>0&&M(`Projects`),C.map((e,t)=>j(k+t,e.id,(0,R.jsx)(My,{className:`text-icon`}),e.name,(0,R.jsx)(`span`,{className:`shrink-0 text-xs text-text-tertiary`,children:`Switch`}),e.name)),w.length>0&&M(`Actions`),w.map((e,t)=>j(A+t,e.kind,e.glyph,e.label,e.kbd?(0,R.jsx)(Gb,{children:e.kbd}):null,e.label)),T.length===0&&(0,R.jsx)(`div`,{className:`p-6 text-center text-sm text-text-tertiary`,children:`No matches`})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-4 border-t border-border-subtle px-4 py-2 text-xs text-text-tertiary`,children:[(0,R.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(Gb,{children:`↑`}),(0,R.jsx)(Gb,{children:`↓`}),` to move`]}),(0,R.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(Gb,{children:`Enter`}),` to open`]}),(0,R.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(Gb,{children:`Esc`}),` to close`]})]})]})})}var T8=1500,E8=`flex h-13 items-center gap-3 px-4`;function D8({projectId:e,projectName:t,open:n,openRequest:r=0,onClose:i,onOpenInbox:a}){let o=B.useUtils(),s=Ab(),[c,l]=(0,L.useState)(``),[u,d]=(0,L.useState)(null),[f,p]=(0,L.useState)(!1),[m,h]=(0,L.useState)(!1),g=(0,L.useRef)(null),_=(0,L.useRef)(0),v=()=>{l(``),d(null),p(!1),h(!1)},[y,b]=(0,L.useState)(n);n!==y&&(b(n),_.current+=1,n&&v());let[x,S]=(0,L.useState)(r);r!==x&&(S(r),n&&m&&v()),(0,L.useEffect)(()=>{n&&g.current?.focus()},[r]);let C=B.projectNotes.add.useMutation(),w=B.projectNotes.openCount.useQuery({projectId:e},{enabled:n}),T=(0,L.useRef)(null);(0,L.useEffect)(()=>{T.current=u?.preview??null},[u]),(0,L.useEffect)(()=>{if(n)return()=>{T.current&&URL.revokeObjectURL(T.current)}},[n]);let E=(0,L.useRef)(i);E.current=i,(0,L.useEffect)(()=>{if(!m)return;let e=setTimeout(()=>E.current(),T8);return()=>clearTimeout(e)},[m]);let D=async e=>{try{let t=await Gm(e),n={png:t,preview:URL.createObjectURL(t)};d(e=>(e&&URL.revokeObjectURL(e.preview),n))}catch(e){s.push(e instanceof Error?e.message:`that image could not be read`)}},O=()=>{d(e=>(e&&URL.revokeObjectURL(e.preview),null)),g.current?.focus()},k=e=>{let t=Wm(e.clipboardData);t&&(e.preventDefault(),D(t))},A=async()=>{if(!c.trim()||f)return;let t=_.current,n=()=>_.current===t;p(!0);try{let t=await C.mutateAsync({projectId:e,text:c});if(u)try{await Mb(t.id,u.png)}catch(e){s.push(`the note was saved, but its picture was not: ${e instanceof Error?e.message:String(e)}`)}o.projectNotes.openCount.setData({projectId:e},e=>e===void 0?e:e+1),o.projectNotes.invalidate(),n()&&h(!0)}catch(e){s.push(e instanceof Error?e.message:`the note could not be saved`)}finally{n()&&p(!1)}};return(0,R.jsx)(QA,{open:n,onClose:i,size:`palette`,scrim:m?`none`:`light`,className:`overflow-hidden`,label:`Jot a note`,initialFocusRef:g,children:m?(0,R.jsxs)(`div`,{className:q(E8,`text-sm animate-fade-in`),role:`status`,children:[(0,R.jsx)(`span`,{className:`flex shrink-0 items-center text-success`,children:(0,R.jsx)(by,{size:16})}),(0,R.jsxs)(`span`,{className:`min-w-0 flex-1 truncate text-text-secondary`,children:[`Noted in `,(0,R.jsx)(`span`,{className:`font-medium text-text`,children:t}),w.data!==void 0&&(0,R.jsxs)(R.Fragment,{children:[` · `,w.data,` open`]})]}),(0,R.jsx)(`button`,{className:q(sE,`text-sm`),onClick:()=>{a(),i()},title:`Read the pile on the project workspace`,children:`View`})]}):(0,R.jsxs)(`div`,{onPaste:k,children:[(0,R.jsxs)(`div`,{className:q(E8,`border-b border-border-subtle`),children:[(0,R.jsx)(`span`,{className:`flex shrink-0 items-center text-icon`,children:(0,R.jsx)(Ay,{size:16})}),(0,R.jsx)(`input`,{ref:g,className:`h-full min-w-0 flex-1 border-0 bg-transparent p-0 font-sans text-base text-text outline-none placeholder:text-text-tertiary`,autoComplete:`off`,"aria-label":`what did you just notice?`,placeholder:`What did you just notice?`,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),A())}})]}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-4 py-2 text-xs text-text-tertiary`,children:[u?(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-text-secondary animate-fade-in`,children:[(0,R.jsx)(`img`,{src:u.preview,alt:`the picture this note will carry`,className:`h-5 w-8 rounded-sm bg-surface-inset object-cover`}),`Screenshot`,(0,R.jsx)(nE,{size:`sm`,label:`Remove the picture`,icon:(0,R.jsx)(xy,{}),onClick:O})]}):(0,R.jsx)(`span`,{children:`Paste a screenshot`}),(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsxs)(`span`,{children:[`to `,(0,R.jsx)(`span`,{className:`font-medium text-text-secondary`,children:t})]}),(0,R.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(Gb,{children:`↵`}),` save`]}),(0,R.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(Gb,{children:`esc`}),` close`]})]})]})})}var O8={"claude-code":{check:`afk-key`,kind:`token`},codex:{check:`auth`,kind:`sign-in`}};function k8(e){return Wu.flatMap(t=>{let{check:n,kind:r}=O8[t],i=e.find(e=>e.runtime===t&&e.check===n);return i?[{runtime:t,kind:r,probe:i}]:[]})}function A8(e){return`${O8[e].check}-${e}`}function j8(e){let t=Rp[e],n=O8[e].kind===`token`;return{field:A8(e),label:n?`${t} token`:t,reason:n?`burns with ${t} need a token`:`sign in to ${t}`,terms:n?[t,`token`,`AFK credential`]:[t,`sign in`,`login`]}}var M8=[{field:`container-runtime`,label:`Container runtime`,reason:`no container runtime on this machine`,terms:[`Container runtime`,`Docker`,`Podman`]},{field:`sandcastle-image`,label:`Sandcastle image`,reason:`the sandcastle image needs building`,terms:[`Sandcastle image`,`build`,`rebuild`]},...Wu.map(j8),{field:`burn-cache`,label:`Burn cache`,terms:[`Burn cache`,`volume`,`clear`]}];function N8(e){let t=e.find(e=>!e.ok);return t?{count:`${e.filter(e=>e.ok).length} of ${e.length}`,text:`ready — ${t.reason}`}:{count:null,text:`Ready for unattended burns`}}var P8=[{page:`general`,label:`General`,Icon:my},{page:`models`,label:`Models`,Icon:Ny},{page:`burns`,label:`Burns`,Icon:Py},{page:`project`,label:`This project`,Icon:My}];function F8({page:e,filter:t,filterRef:n,projectName:r,onFilter:i,onSelect:a}){let o=t.query.trim()!==``;return(0,R.jsxs)(`nav`,{"aria-label":`Settings pages`,className:`flex min-h-0 flex-col gap-0.5 border-r border-border-subtle bg-canvas px-2 pt-4 pb-3`,children:[(0,R.jsx)(`div`,{className:`mb-2 px-2.5 text-sm font-medium text-text`,children:`Settings`}),(0,R.jsx)(OA,{ref:n,size:`md`,"aria-label":`Filter settings`,placeholder:`Filter`,kbd:`Ctrl F`,autoComplete:`off`,value:t.query,onChange:e=>i(e.target.value),className:`mb-3`}),P8.map(({page:n,label:r,Icon:i})=>(0,R.jsx)(_A,{label:r,icon:(0,R.jsx)(i,{}),active:n===e,onClick:()=>a(n),meta:o?t.counts[n]||``:void 0},n)),(0,R.jsx)(`div`,{className:`flex-1`}),(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5 px-2.5 pt-3`,children:[(0,R.jsx)(`span`,{className:`text-xs text-text-tertiary`,children:`This project is`}),(0,R.jsx)(`span`,{className:`truncate font-mono text-xs text-text-secondary`,title:r,children:r})]})]})}var I8=1500;function L8(e){let t=(0,L.useRef)(null),[n,r]=(0,L.useState)(!1);return(0,L.useEffect)(()=>{if(!e)return;t.current?.scrollIntoView?.({block:`center`}),r(!0);let n=setTimeout(()=>r(!1),I8);return()=>clearTimeout(n)},[e]),{ref:t,flash:n}}function R8(e,t){return e.query.trim()===``||e.matches.has(t)}var z8=1400;function B8({title:e,rows:t,projectId:n,filter:r,highlightField:i,onOpenEvidence:a,evidence:o}){let s=t.filter(e=>R8(r,e.key));return s.length===0?null:(0,R.jsx)(V8,{title:e,children:s.map(e=>(0,R.jsx)(U8,{row:e,projectId:n,highlight:i===e.key,...a&&e.provenanceChip?.evidence?{onOpenEvidence:()=>a(e.key)}:{},...o?{evidence:o(e)}:{}},e.key))})}function V8({title:e,action:t,description:n,children:r}){return(0,R.jsxs)(`section`,{className:`mt-9 first:mt-0`,children:[(0,R.jsxs)(`div`,{className:`flex min-h-7 items-center gap-3 border-b border-border-subtle pb-2`,children:[(0,R.jsx)(`h3`,{className:`m-0 min-w-0 flex-1 text-sm font-medium text-text`,children:e}),t&&(0,R.jsx)(`div`,{className:`flex shrink-0 items-center gap-1`,children:t})]}),n&&(0,R.jsx)(`div`,{className:`mt-2.5 text-xs text-pretty text-text-tertiary`,children:n}),(0,R.jsx)(`div`,{children:r})]})}function H8({label:e,htmlFor:t,description:n,descriptionId:r,aside:i,control:a,below:o,stacked:s=!1,flash:c=!1,rowRef:l}){return(0,R.jsxs)(`div`,{ref:l,className:q(`border-b border-border-subtle py-4 last:border-b-0`,`transition-[outline-color] duration-(--dur-3) ease-app`,s?`flex flex-col gap-2.5`:`grid grid-cols-[minmax(0,1fr)_minmax(0,300px)] items-start gap-x-8 gap-y-1.5`,c&&`rounded-md outline-2 outline-offset-4 outline-accent`),children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5 pt-1`,children:[(0,R.jsxs)(`div`,{className:`flex min-h-5 items-center gap-2`,children:[(0,R.jsx)(`label`,{htmlFor:t,className:`text-sm font-medium text-text`,children:e}),i]}),n&&(0,R.jsx)(`p`,{id:r,className:`m-0 text-xs text-pretty text-text-tertiary`,children:n})]}),(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1.5`,children:[a,o]})]})}function U8({row:e,projectId:t,highlight:n,onOpenEvidence:r,evidence:i}){let a=B.useUtils(),o=e.ghostValue?``:e.value,[s,c]=(0,L.useState)(o),[l,u]=(0,L.useState)(null),[d,f]=(0,L.useState)(!1),[p,m]=(0,L.useState)(!1),{ref:h,flash:g}=L8(n),_=(0,L.useRef)(void 0);(0,L.useEffect)(()=>c(o),[o]),(0,L.useEffect)(()=>()=>clearTimeout(_.current),[]);let v=B.settings.update.useMutation({onSuccess:()=>{u(null),f(!0),clearTimeout(_.current),_.current=setTimeout(()=>f(!1),z8),e.restartRequired&&m(!0),a.settings.get.invalidate(),a.project.prep.invalidate()},onError:e=>{c(o),u(e.message)}}),y=e=>{c(e),l&&u(null)},b=n=>{u(null),v.mutate({...t?{projectId:t}:{},key:e.key,value:n})},x=t=>{if(t.trim()===o.trim())return;let n=rm(e.control,t);if(`error`in n){u(n.error);return}b(n.value)},S=()=>b(null),C=`set-${t?`project`:`global`}-${e.key}`,w=`${C}-help`,T=`${C}-error`,E=`${C}-about`,D=q(E,e.shortHelp?w:null,l?T:null)||void 0,O=e.sourceChip||e.clearable||e.provenanceChip;return(0,R.jsx)(H8,{rowRef:h,flash:g,stacked:e.control===`textarea`,label:e.label,htmlFor:C,description:e.tooltip||void 0,descriptionId:E,aside:d&&(0,R.jsx)(W8,{}),control:(0,R.jsx)(G8,{id:C,describedBy:D,row:e,draft:s,disabled:v.isPending,onDraft:y,onCommit:x,onRevert:()=>c(o)}),below:(0,R.jsxs)(R.Fragment,{children:[e.shortHelp&&(0,R.jsx)(`div`,{id:w,className:`text-xs text-text-tertiary`,children:e.shortHelp}),O&&(0,R.jsxs)(`div`,{className:`flex min-h-5 flex-wrap items-center gap-x-3 gap-y-1`,children:[e.sourceChip&&(0,R.jsx)(q8,{kind:e.sourceChip,envVar:Lp[e.key]}),e.sourceChip===`project`&&(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:S,className:`-ml-1.5`,children:`Use global`}),e.clearable&&(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:S,className:`-ml-1.5`,children:`Clear`}),e.provenanceChip&&(0,R.jsxs)(`div`,{className:`relative flex min-w-0`,children:[(0,R.jsx)(Y8,{chip:e.provenanceChip,onOpenEvidence:r}),i]}),e.stale&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-warning`,title:`Measured a long time ago — “Re-prepare the project”, at the foot of the features rail, refreshes it`,children:[(0,R.jsx)(tA,{tone:`warning`}),`Stale`]})]}),p&&(0,R.jsx)(`div`,{className:`text-xs text-warning`,children:`Restart the server to apply`}),l&&(0,R.jsx)(`div`,{id:T,role:`alert`,className:`text-xs text-danger`,children:l})]})})}function W8(){return(0,R.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1 text-xs text-text-tertiary animate-fade-in`,children:[(0,R.jsx)(by,{size:12,className:`text-success`}),`Saved`]})}function G8({id:e,describedBy:t,row:n,draft:r,disabled:i,onDraft:a,onCommit:o,onRevert:s}){let c={id:e,"aria-describedby":t,disabled:i},l=e=>{e.key===`Escape`&&(s(),e.currentTarget.blur())},u=e=>{e.key===`Enter`&&e.currentTarget.blur(),l(e)},d=n.unit?(0,R.jsx)(`span`,{className:`min-w-0 text-xs text-pretty text-text-tertiary`,children:n.unit}):void 0;if(n.readOnly)return(0,R.jsx)(DA,{...c,disabled:!0,readOnly:!0,mono:n.control!==`select`,icon:(0,R.jsx)(Fy,{}),className:`w-full`,inputClassName:n.control===`number`?`tabular-nums`:void 0,value:n.optionLabels[n.value]??n.value});if(n.control===`select`)return(0,R.jsxs)(Q0,{value:r,onValueChange:e=>{a(e),o(e)},children:[(0,R.jsx)(n2,{...c,className:q(e2,`w-full`),children:(0,R.jsx)(r2,{})}),(0,R.jsxs)(i2,{children:[n.ghostValue&&(0,R.jsxs)(c2,{value:``,children:[`Use global (`,n.optionLabels[n.ghostValue]??n.ghostValue,`)`]}),n.modelGroups.length>0?n.modelGroups.map(e=>(0,R.jsxs)(a2,{children:[(0,R.jsx)(o2,{children:e.label}),e.entries.map(e=>(0,R.jsx)(c2,{value:e.id,title:e.note,children:e.note?`${e.id} — ${e.note}`:e.id},e.id))]},e.runtime)):n.options.map(e=>(0,R.jsx)(c2,{value:e,children:n.optionLabels[e]??e},e))]})]});if(n.control===`textarea`)return(0,R.jsx)(kA,{...c,mono:!0,rows:3,placeholder:n.ghostValue??n.placeholder,value:r,onChange:e=>a(e.target.value),onBlur:e=>o(e.target.value),onKeyDown:l});let f=(0,R.jsx)(DA,{...c,type:n.control===`number`?`number`:`text`,mono:!0,className:n.control===`number`?`w-24 shrink-0`:`w-full`,inputClassName:n.control===`number`?`tabular-nums`:void 0,placeholder:n.ghostValue??n.placeholder,value:r,onChange:e=>a(e.target.value),onBlur:e=>o(e.target.value),onKeyDown:u});return d?(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2.5`,children:[f,d]}):f}var K8={global:{text:`Global`,tone:`neutral`,word:`text-text-tertiary`},project:{text:`This project`,tone:`accent`,word:`text-text-secondary`},env:{text:`Env`,tone:`neutral`,word:`text-text-tertiary`}};function q8({kind:e,envVar:t}){let n=K8[e];return(0,R.jsxs)(`span`,{className:q(`inline-flex shrink-0 items-center gap-1.5 text-xs`,n.word),...e===`env`&&t?{title:`Set by ${t}`}:{},children:[e===`env`?(0,R.jsx)(Fy,{size:12,className:`text-icon`}):(0,R.jsx)(tA,{tone:n.tone}),(0,R.jsx)(`span`,{children:n.text})]})}var J8={ok:`success`,muted:`neutral`,warn:`warning`};function Y8({chip:e,onOpenEvidence:t}){let n=(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(tA,{tone:J8[e.tone]}),(0,R.jsx)(`span`,{className:`truncate`,children:e.text})]}),r=e.tone===`warn`?`text-warning`:`text-text-secondary`;return t?(0,R.jsx)(`button`,{type:`button`,onClick:t,className:q(`-mx-1.5 inline-flex h-6 min-w-0 cursor-pointer items-center gap-1.5 rounded-md border-0 bg-transparent px-1.5 text-xs`,`underline decoration-border-strong decoration-dotted underline-offset-4`,`transition-colors duration-(--dur-1) ease-app hover:bg-surface-hover hover:text-text`,r),children:n}):(0,R.jsx)(`span`,{className:q(`inline-flex min-w-0 items-center gap-1.5 text-xs`,r),children:n})}var X8=`theme`,Z8=[{value:`dark`,label:`Dark`,icon:(0,R.jsx)(Xy,{size:14})},{value:`light`,label:`Light`,icon:(0,R.jsx)(Yy,{size:14})},{value:`system`,label:`System`,icon:(0,R.jsx)(Zy,{size:14})}];function Q8({globals:e,filter:t,highlightField:n}){let r=R8(t,`theme`)&&(0,R.jsx)(V8,{title:`Appearance`,children:(0,R.jsx)($8,{})});if(e.isLoading)return(0,R.jsxs)(R.Fragment,{children:[r,(0,R.jsx)(UA,{className:`mt-9`,children:`Loading settings…`})]});if(e.error)return(0,R.jsxs)(R.Fragment,{children:[r,(0,R.jsxs)(WA,{children:[`Could not load settings: `,e.error.message]})]});if(!e.data)return(0,R.jsx)(R.Fragment,{children:r});let i=pm(e.data,`general`),a=e=>i.filter(t=>t.group===e);return(0,R.jsxs)(R.Fragment,{children:[r,(0,R.jsx)(B8,{title:`Server`,rows:a(`server`),filter:t,highlightField:n}),(0,R.jsx)(B8,{title:`Sessions`,rows:a(`sessions`),filter:t,highlightField:n})]})}function $8(){let{preference:e,setPreference:t}=nM();return(0,R.jsx)(H8,{label:`Theme`,description:`Dark is the default; System follows your operating system as it changes.`,control:(0,R.jsx)(BA,{id:`settings-theme`,label:`Theme`,items:Z8.map(e=>({value:e.value,label:e.label,icon:e.icon})),value:e,onChange:t,className:`w-full`})})}var e5=`grid grid-cols-[minmax(0,1.5fr)_minmax(0,1.3fr)_minmax(0,0.8fr)_88px_24px] items-center gap-3`,t5=`min-h-8 border-b border-border-subtle px-2 text-xs font-medium text-text-tertiary`,n5=e=>`models:${e}`,r5=`models:new`,i5=`opacity-0 transition-opacity duration-(--dur-1) group-hover:opacity-100 group-focus-within:opacity-100 focus-visible:opacity-100`;function a5({rows:e,stepLabels:t,customModels:n,filter:r,writes:i}){let[a,o]=(0,L.useState)(!1),s=r.query.trim()!==``,c=(a||s?e:xm(e)).filter(e=>R8(r,e.id)),l=a||s?0:Sm(e);return(0,R.jsxs)(`div`,{className:`mt-3`,children:[(0,R.jsxs)(`div`,{className:q(e5,t5),children:[(0,R.jsx)(`span`,{children:`Model`}),(0,R.jsx)(`span`,{children:`Use-case note`}),(0,R.jsx)(`span`,{children:`Used for`}),(0,R.jsx)(`span`,{children:`Default`}),(0,R.jsx)(`span`,{})]}),c.map((e,r)=>(0,R.jsx)(o5,{index:r,row:e,stepLabels:t,customModels:n,writes:i},e.id)),l>0&&(0,R.jsxs)(`div`,{className:`flex min-h-10 items-center gap-2 border-b border-border-subtle px-2 text-xs text-text-tertiary`,children:[l,` more `,l===1?`model`:`models`,` nobody uses`,(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>o(!0),children:`Show all`})]}),!s&&(0,R.jsx)(l5,{customModels:n,writes:i})]})}function o5({row:e,index:t,stepLabels:n,customModels:r,writes:i}){let a=n5(e.id),o=e.usedFor.map(e=>n.get(e)??e).join(`, `),s=t=>{let n=t.trim(),o=n===``&&!e.custom?r.filter(t=>t.id!==e.id):Zu(r,[{id:e.id,runtime:e.runtime,...n?{note:n}:{}}]);i.save(a,`models`,o)},c=()=>{if(e.isDefault){i.refuse(a,`${e.id} is the default model — make another model the default first.`);return}if(e.usedFor.length>0){i.refuse(a,`${e.id} runs ${o} — reset those steps first.`);return}i.save(a,`models`,r.filter(t=>t.id!==e.id))},l=t<8;return(0,R.jsxs)(`div`,{className:q(`group border-b border-border-subtle transition-colors duration-(--dur-1) ease-app hover:bg-surface-hover`,l&&`animate-rise-in`),style:l?{animationDelay:`${t*20}ms`}:void 0,children:[(0,R.jsxs)(`div`,{className:q(e5,`min-h-10 px-2 text-sm`),children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,R.jsx)(d5,{runtime:e.runtime}),(0,R.jsx)(`span`,{className:`truncate text-text`,title:e.displayName?`${e.displayName} — ${e.id}`:e.id,children:e.id}),e.isNew&&(0,R.jsx)(rA,{tone:`accent`,className:`shrink-0`,children:`New`})]}),(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,R.jsx)(c5,{row:e,onCommit:s}),i.saved===a&&(0,R.jsx)(W8,{})]}),(0,R.jsxs)(`span`,{className:`truncate text-xs text-text-tertiary`,title:o||void 0,children:[e.isDefault&&(0,R.jsx)(`span`,{className:`text-text-secondary`,children:`Default`}),e.isDefault&&o!==``&&`, `,o===``?e.isDefault?``:`—`:o]}),e.isDefault?(0,R.jsx)(`span`,{"data-default-mark":``,className:`inline-flex`,children:(0,R.jsx)(rA,{strong:!0,icon:(0,R.jsx)(by,{}),children:`Default`})}):(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,"aria-label":`Make ${e.id} the default`,onClick:()=>i.save(a,`model`,e.id),className:q(`-ml-2 justify-self-start`,i5),children:`Make default`}),e.custom?(0,R.jsx)(nE,{label:`Remove ${e.id}`,size:`sm`,icon:(0,R.jsx)(Sy,{}),onClick:c,variant:`danger-ghost`,className:i5}):(0,R.jsx)(`span`,{})]}),(0,R.jsx)(s5,{row:e}),(0,R.jsx)(u5,{writes:i,cell:a})]})}function s5({row:e}){return!e.noLongerOffered&&!e.retirement?null:(0,R.jsxs)(`p`,{className:`m-0 flex flex-wrap gap-x-4 pr-2 pb-2.5 pl-8 text-xs text-warning`,children:[e.noLongerOffered&&(0,R.jsxs)(`span`,{children:[`no longer offered by `,_m[e.noLongerOffered]]}),e.retirement&&(0,R.jsxs)(`span`,{children:[`retires `,e.retirement.at,` → `,e.retirement.replacement]})]})}function c5({row:e,onCommit:t}){let[n,r]=(0,L.useState)(e.note);return(0,L.useEffect)(()=>r(e.note),[e.note]),(0,R.jsx)(`input`,{type:`text`,"aria-label":`Note for ${e.id}`,placeholder:e.isDefault?`e.g. UI/UX work, design-heavy tickets`:`Add a note`,className:q(`-ml-2 h-7 min-w-0 flex-1 rounded-md border border-transparent bg-transparent px-2 text-sm text-text`,`transition-colors duration-(--dur-1) ease-app placeholder:text-text-disabled`,`hover:border-border focus:border-accent focus:bg-surface-inset`),value:n,onChange:e=>r(e.target.value),onBlur:()=>n.trim()!==e.note.trim()&&t(n),onKeyDown:e=>e.key===`Enter`&&e.currentTarget.blur()})}function l5({customModels:e,writes:t}){let[n,r]=(0,L.useState)(``),[i,a]=(0,L.useState)(``),[o,s]=(0,L.useState)(``),c=()=>{let c=Up(n,i,o);if(`error`in c){t.refuse(r5,c.error);return}t.save(r5,`models`,Zu(e,[c.entry])),r(``),a(``),s(``)},l=e=>{e.key===`Enter`&&c()};return(0,R.jsxs)(`div`,{className:`pt-3`,children:[(0,R.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_132px_minmax(0,1.2fr)_auto] items-center gap-2`,children:[(0,R.jsx)(DA,{mono:!0,"aria-label":`New model id`,placeholder:`Model id, e.g. claude-opus-5[1m]`,value:n,onChange:e=>r(e.target.value),onKeyDown:l}),(0,R.jsxs)(Q0,{value:i,onValueChange:a,children:[(0,R.jsx)(n2,{"aria-label":`Runtime (required)`,className:q(e2,`w-full`,i===``&&`text-text-tertiary`),children:(0,R.jsx)(r2,{})}),(0,R.jsxs)(i2,{children:[(0,R.jsx)(c2,{value:``,children:`Runs on…`}),Wu.map(e=>(0,R.jsx)(c2,{value:e,children:Rp[e]},e))]})]}),(0,R.jsx)(DA,{"aria-label":`New model note`,placeholder:`Use-case note (optional)`,value:o,onChange:e=>s(e.target.value),onKeyDown:l}),(0,R.jsx)(Y,{icon:(0,R.jsx)(yy,{}),onClick:c,children:`Add model`})]}),(0,R.jsx)(u5,{writes:t,cell:r5,className:`pt-1.5`})]})}function u5({writes:e,cell:t,className:n=`pr-2 pb-2.5 pl-8`}){return e.error?.cell===t?(0,R.jsx)(`p`,{role:`alert`,className:q(`m-0 text-xs text-danger`,n),children:e.error.message}):null}function d5({runtime:e}){let t=e===`codex`?Hy:Vy;return(0,R.jsx)(`span`,{role:`img`,"aria-label":Rp[e],title:Rp[e],className:`inline-flex size-4 shrink-0 items-center justify-center text-icon`,children:(0,R.jsx)(t,{size:14})})}function f5({groups:e}){return(0,R.jsx)(R.Fragment,{children:e.map(e=>(0,R.jsxs)(a2,{children:[(0,R.jsx)(o2,{children:e.label}),e.entries.map(e=>(0,R.jsx)(c2,{value:e.id,title:e.note,children:e.note?`${e.id} — ${e.note}`:e.id},e.id))]},e.runtime))})}var p5=[{group:`sessions`,title:`Sessions`,caption:`Interactive — you are in the terminal`},{group:`unattended`,title:`Unattended`,caption:`Burns and scripted runs`}],m5=`grid grid-cols-[minmax(0,1fr)_260px_24px] items-center gap-3`;function h5({rows:e,groups:t,defaultModel:n,projectModel:r,filter:i,writes:a}){return(0,R.jsxs)(R.Fragment,{children:[r&&(0,R.jsxs)(`p`,{className:`m-0 mt-3 flex items-center gap-2 text-xs text-text-secondary`,children:[(0,R.jsx)(tA,{tone:`warning`}),(0,R.jsxs)(`span`,{children:[`This project runs everything on `,(0,R.jsx)(`span`,{className:`font-mono`,children:r}),` — these apply to other projects.`]})]}),p5.map(({group:r,title:o,caption:s})=>{let c=e.filter(e=>e.group===r&&R8(i,Yp(e.step)));return c.length===0?null:(0,R.jsxs)(L.Fragment,{children:[(0,R.jsxs)(`div`,{className:q(m5,t5,`mt-4`),children:[(0,R.jsxs)(`span`,{children:[o,(0,R.jsx)(`span`,{className:`ml-2 font-normal text-text-disabled`,children:s})]}),(0,R.jsx)(`span`,{children:`Model`}),(0,R.jsx)(`span`,{})]}),c.map(e=>(0,R.jsx)(g5,{row:e,groups:t,defaultModel:n,writes:a},e.step))]},r)})]})}function g5({row:e,groups:t,defaultModel:n,writes:r}){let i=Yp(e.step),a=e.value!==null;return(0,R.jsxs)(`div`,{className:`group border-b border-border-subtle transition-colors duration-(--dur-1) ease-app hover:bg-surface-hover`,children:[(0,R.jsxs)(`div`,{className:q(m5,`min-h-12 px-2 py-1.5`),children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,R.jsxs)(`span`,{className:`flex items-center gap-2 text-sm text-text`,children:[e.label,r.saved===i&&(0,R.jsx)(W8,{})]}),(0,R.jsx)(`span`,{className:`truncate text-xs text-text-tertiary`,title:e.description,children:e.description})]}),(0,R.jsxs)(Q0,{value:e.value??``,onValueChange:e=>r.save(i,i,e===``?null:e),children:[(0,R.jsx)(n2,{"aria-label":`Model for ${e.label}`,className:q(e2,`w-full`,!a&&`text-text-tertiary`),children:(0,R.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 [&>span:last-child]:truncate`,children:[(0,R.jsx)(d5,{runtime:e.effectiveRuntime}),(0,R.jsx)(r2,{})]})}),(0,R.jsxs)(i2,{children:[(0,R.jsxs)(c2,{value:``,children:[`Default (`,n,`)`]}),(0,R.jsx)(f5,{groups:t})]})]}),a?(0,R.jsx)(nE,{label:`Reset ${e.label} to default`,size:`sm`,icon:(0,R.jsx)(Cy,{}),onClick:()=>r.save(i,i,null),className:i5}):(0,R.jsx)(`span`,{})]}),(0,R.jsx)(u5,{writes:r,cell:i,className:`px-2 pb-2.5`})]})}var _5=1400,v5=`model`;function y5(){let e=B.useUtils(),[t,n]=(0,L.useState)(null),[r,i]=(0,L.useState)(null),a=(0,L.useRef)([]),o=(0,L.useRef)(null),s=(0,L.useRef)(void 0);(0,L.useEffect)(()=>()=>clearTimeout(s.current),[]);let c=()=>{let e=a.current.shift();if(!e){o.current=null;return}o.current=e.cell,l.mutate({key:e.key,value:e.value})},l=B.settings.update.useMutation({onSuccess:()=>{n(o.current),clearTimeout(s.current),s.current=setTimeout(()=>n(null),_5),e.settings.get.invalidate(),c()},onError:e=>{let t=o.current;t&&i({cell:t,message:e.message}),a.current=[],o.current=null}}),u=e=>i(t=>t&&t.cell===e?null:t);return{saved:t,error:r,save:(e,t,n)=>{u(e),a.current.push({cell:e,key:t,value:n}),o.current===null&&c()},refuse:(e,t)=>i({cell:e,message:t})}}function b5({globals:e,scoped:t,filter:n,highlightField:r}){let i=y5();if(e.isLoading)return(0,R.jsx)(WA,{children:`Loading settings…`});if(e.error)return(0,R.jsxs)(WA,{children:[`Could not load settings: `,e.error.message]});if(!e.data)return null;let a=e.data,o=bm(a),s=wm(a),c=Hp(Vp(a)),l=hm(a),u=new Map(s.map(e=>[e.step,e.label]));return(0,R.jsxs)(R.Fragment,{children:[R8(n,`model`)&&(0,R.jsx)(`div`,{className:`-mt-3.5`,children:(0,R.jsx)(C5,{value:l,groups:c,writes:i,highlight:r===`model`})}),o.some(e=>R8(n,e.id))&&(0,R.jsxs)(V8,{title:`Roster`,action:(0,R.jsx)(S5,{}),description:(0,R.jsxs)(R.Fragment,{children:[`A model with a `,(0,R.jsx)(`span`,{className:`text-text-secondary`,children:`use-case note`}),` is offered to the tickets agent, which may pick it per ticket; models without a note are never picked automatically.`]}),children:[(0,R.jsx)(x5,{view:a}),(0,R.jsx)(a5,{rows:o,stepLabels:u,customModels:Bp(a),filter:n,writes:i})]}),s.some(e=>R8(n,Yp(e.step)))&&(0,R.jsx)(V8,{title:`Per step`,description:`Every step runs the default unless it names a model of its own.`,children:(0,R.jsx)(h5,{rows:s,groups:c,defaultModel:l,projectModel:Tm(t.data),filter:n,writes:i})})]})}function x5({view:e}){return(0,R.jsx)(`ul`,{"aria-label":`Model discovery`,className:`m-0 mt-1.5 flex list-none flex-wrap gap-x-5 gap-y-1 p-0 text-xs`,children:Cm(e).map(e=>(0,R.jsxs)(`li`,{className:q(`inline-flex items-center gap-1.5`,e.failed?`text-warning`:`text-text-tertiary`),children:[(0,R.jsx)(d5,{runtime:e.runtime}),e.text]},e.runtime))})}function S5(){let e=B.useUtils(),t=B.settings.refreshModels.useMutation({onSuccess:()=>void e.settings.get.invalidate()});return(0,R.jsxs)(R.Fragment,{children:[t.error&&(0,R.jsxs)(`span`,{role:`alert`,className:`text-xs text-danger`,children:[`Refresh failed: `,t.error.message]}),(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(ab,{}),loading:t.isPending,onClick:()=>t.mutate(),children:t.isPending?`Refreshing…`:`Refresh`})]})}function C5({value:e,groups:t,writes:n,highlight:r}){let{ref:i,flash:a}=L8(r);return(0,R.jsx)(H8,{rowRef:i,flash:a,label:`Default model`,htmlFor:`settings-default-model`,description:`Runs every step that has no model of its own below — and every project that has not set one.`,aside:n.saved===v5&&(0,R.jsx)(W8,{}),control:(0,R.jsxs)(Q0,{value:e,onValueChange:e=>n.save(v5,`model`,e),children:[(0,R.jsx)(n2,{id:`settings-default-model`,className:q(e2,`w-full`),children:(0,R.jsx)(r2,{})}),(0,R.jsx)(i2,{children:(0,R.jsx)(f5,{groups:t})})]}),below:(0,R.jsx)(u5,{writes:n,cell:v5,className:``})})}function w5({projectId:e,filter:t,highlightField:n,onDismiss:r}){let i=B.useUtils(),a=B.setup.doctor.useQuery(e?{projectId:e}:void 0,{refetchOnWindowFocus:!1}),o=a.data,s=e=>o?.results.find(t=>t.id===e),c=s(`container-runtime`),l=s(`sandcastle-image`),u=k8(o?.results??[]),[d,f]=(0,L.useState)(0),p=()=>{f(e=>e+1),i.setup.doctor.cancel().then(()=>a.refetch())},m=k5(a.isLoading,d),h=e=>!t||R8(t,e),g=m?D5:`checking prerequisites…`,_=a.error?.message??(m?O5:null),v=N8([...c?[{field:`container-runtime`,ok:c.status===`ok`}]:[],...l?[{field:`sandcastle-image`,ok:T5(l)}]:[],...u.map(e=>({field:A8(e.runtime),ok:e.probe.status===`ok`}))].map(({field:e,ok:t})=>({ok:t,reason:A5[e].reason??A5[e].label}))),y=e=>({field:e,label:A5[e].label,visible:h(e),highlight:n===e}),b=o!==void 0&&v.count===null;return(0,R.jsxs)(`section`,{"aria-label":`Unattended burn prerequisites`,className:`flex flex-col`,children:[(0,R.jsxs)(`div`,{className:`flex items-start gap-3 pb-3`,children:[(0,R.jsx)(`span`,{"aria-hidden":!0,className:q(`mt-0.5 inline-flex size-7 shrink-0 items-center justify-center rounded-md bg-surface-hover [&>svg]:size-4`,b?`text-success`:`text-icon`),children:b?(0,R.jsx)(by,{}):(0,R.jsx)(Py,{})}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`div`,{className:`flex min-h-7 items-center gap-2 text-sm font-medium text-text`,children:a.isLoading?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(aE,{}),(0,R.jsx)(`span`,{className:`font-normal text-text-secondary`,children:g})]}):a.error?`Could not run the checks`:(0,R.jsxs)(`span`,{className:`min-w-0`,children:[v.count&&(0,R.jsxs)(`span`,{className:`tabular-nums`,children:[v.count,` `]}),v.text]})}),!r&&(0,R.jsx)(`p`,{className:`m-0 text-xs text-pretty text-text-tertiary`,children:`A burn you walk away from runs its tickets in containers, so it needs what an interactive session never does. Fix any of these now, or leave them for later.`})]}),r&&(0,R.jsx)(Y,{variant:`ghost`,className:`shrink-0`,onClick:r,children:`Set up later`})]}),_&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2.5 py-2 pl-10`,children:[(0,R.jsx)(tA,{tone:`warning`}),(0,R.jsx)(`span`,{className:`min-w-0 grow text-xs text-text-secondary`,children:_}),(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(ab,{}),onClick:p,children:`Retry`})]}),o&&(0,R.jsxs)(M5,{children:[(0,R.jsx)(P5,{...y(`container-runtime`),probe:c,onRecheck:p}),(0,R.jsx)(F5,{...y(`sandcastle-image`),probe:l,runtimeOk:c?.status===`ok`,projectId:e,onDone:p}),u.map(e=>e.kind===`token`?(0,R.jsx)(V5,{...y(A8(e.runtime)),probe:e.probe,onDone:p},e.runtime):(0,R.jsx)(H5,{...y(A8(e.runtime)),row:e,onDone:p},e.runtime)),e&&(0,R.jsx)(z5,{...y(`burn-cache`),projectId:e})]})]})}function T5(e){return e.status===`ok`||e.severity===`info`}var E5=1e4,D5=`still checking — this is taking longer than usual`,O5=`The container runtime has not answered yet. A runtime that is starting up — or wedged — can leave the checks outstanding for minutes.`;function k5(e,t){let[n,r]=(0,L.useState)(!1);return(0,L.useEffect)(()=>{if(r(!1),!e)return;let t=setTimeout(()=>r(!0),E5);return()=>clearTimeout(t)},[e,t]),n}var A5=Object.fromEntries(M8.map(e=>[e.field,e]));function j5({field:e,label:t,visible:n=!0,highlight:r=!1,detail:i,ok:a,status:o,children:s,below:c}){let{ref:l,flash:u}=L8(r);return n?(0,R.jsxs)(`li`,{ref:l,...e?{"data-field":e}:{},className:q(`grid grid-cols-[28px_minmax(0,1fr)_auto] items-start gap-x-3 gap-y-2.5 py-3 [counter-increment:checklist]`,`border-t border-border-subtle first:border-t-0`,u&&`rounded-md outline-2 outline-offset-4 outline-accent`),children:[(0,R.jsx)(`span`,{"aria-hidden":!0,className:`flex h-5 items-center justify-center text-xs text-text-tertiary tabular-nums before:content-[counter(checklist)]`}),(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsxs)(`div`,{className:`flex min-h-5 flex-wrap items-center gap-x-3 gap-y-0.5`,children:[(0,R.jsx)(`span`,{className:`text-sm font-medium text-text`,children:t}),a?(0,R.jsx)(rA,{tone:`success`,icon:(0,R.jsx)(by,{}),children:o??`Ready`}):(0,R.jsx)(rA,{tone:`warning`,children:o??`Needed`})]}),(0,R.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-xs text-text-tertiary`,title:i,children:i})]}),(0,R.jsx)(`div`,{className:`flex max-w-96 flex-wrap items-center justify-end gap-2`,children:s}),c]}):null}function M5({children:e}){return(0,R.jsx)(`ol`,{className:`m-0 list-none border-t border-border-subtle p-0 [counter-reset:checklist]`,children:e})}function N5({sessionId:e,label:t,onDone:n,onEnded:r}){return(0,R.jsxs)(`div`,{className:`col-span-full flex flex-col gap-2`,children:[(0,R.jsx)(`div`,{className:`h-70 overflow-hidden rounded-md border border-border bg-surface-inset animate-rise-in`,children:(0,R.jsx)(LG,{label:t,children:(0,R.jsx)(_1,{sessionId:e,onEnded:r})})}),n&&(0,R.jsx)(`div`,{className:`flex justify-end`,children:(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(ab,{}),onClick:n,children:`Done — re-check`})})]})}function P5({probe:e,onRecheck:t,...n}){let r=B.setup.runtimeGuide.useQuery(void 0,{enabled:e?.status===`missing`,refetchOnWindowFocus:!1}),i=Ab();if(!e)return null;let a=e.status===`missing`?r.data:void 0,o=a?.command??e.fix??``,s=e.status===`ok`;return(0,R.jsxs)(j5,{...n,detail:e.detail,ok:s,children:[!s&&o&&(0,R.jsx)(R.Fragment,{children:(0,R.jsx)(U5,{command:o,onCopy:()=>{navigator.clipboard?.writeText(o),i.push(`copied`,`info`)}})}),!s&&a?.note&&(0,R.jsx)(`span`,{className:`basis-full text-right text-xs text-text-tertiary`,children:a.note}),!s&&(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(ab,{}),onClick:t,children:`Re-check`})]})}function F5({probe:e,runtimeOk:t,projectId:n,onDone:r,...i}){let[a,o]=(0,L.useState)(null),s=Ab(),c=B.setup.imageBuildTarget.useQuery(n?{projectId:n}:void 0),l=B.setup.startTerminal.useMutation({onSuccess:({sessionId:e,notices:t})=>{o(e);for(let e of t)s.push(e)},onError:e=>s.push(e.message)});return e?(0,R.jsx)(j5,{...i,detail:e.detail,ok:T5(e),below:a&&(0,R.jsx)(N5,{sessionId:a,label:`build-image`,onEnded:r,onDone:()=>{o(null),r()}}),children:!a&&(0,R.jsx)(L5,{probe:e,target:I5(c),runtimeOk:t,pending:l.isPending,onStart:()=>l.mutate({kind:`build-image`,...n?{projectId:n}:{}})})}):null}function I5(e){let{data:t}=e;return t?t.kind===`refused`?{kind:`refused`,reason:t.reason}:{kind:`ready`,dockerfile:t.dockerfile,tag:t.tag}:e.error?{kind:`error`,message:e.error.message}:{kind:`loading`}}function L5({probe:e,target:t,runtimeOk:n,pending:r,onStart:i}){if(e.status===`custom`)return(0,R.jsx)(`span`,{className:`basis-full text-right text-xs text-text-tertiary`,children:e.fix});if(t.kind===`refused`)return(0,R.jsx)(`span`,{className:`basis-full text-right text-xs text-text-tertiary`,children:t.reason});let a=e.status===`missing`||e.status===`not-built-yet`?`Build`:`Rebuild`,o=r?`Starting…`:t.kind===`ready`?`${a} image · ${t.tag}`:t.kind===`loading`?`${a} image · resolving…`:`${a} image`;return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(Y,{variant:`secondary`,size:`sm`,icon:(0,R.jsx)(Ny,{}),"aria-label":`${a} image`,disabled:!n||r||t.kind!==`ready`,title:n?t.kind===`ready`?`Dockerfile: ${t.dockerfile}\nImage: ${t.tag}`:void 0:`Install a container runtime first`,onClick:i,children:o}),t.kind===`error`&&(0,R.jsx)(`span`,{className:`basis-full text-right text-xs text-warning`,children:t.message})]})}function R5({status:e,pending:t,refusal:n,onClear:r,...i}){return e?.mode===`volume`?(0,R.jsxs)(j5,{field:A5[`burn-cache`].field,label:A5[`burn-cache`].label,...i,ok:!0,detail:`${e.volumeName} — ${e.sizeBytes===null?`empty`:dh(e.sizeBytes)}`,children:[(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(Sy,{}),disabled:t,onClick:r,children:t?`Clearing…`:`Clear`}),n&&(0,R.jsx)(`span`,{className:`basis-full text-right text-xs text-warning`,children:n})]}):null}function z5({projectId:e,...t}){let n=B.useUtils(),[r,i]=(0,L.useState)(null),a=B.system.burnCache.status.useQuery({projectId:e},{refetchOnWindowFocus:!1}),o=B.system.burnCache.clear.useMutation({onSuccess:()=>{i(null),n.system.burnCache.status.invalidate()},onError:e=>i(e.message)});return(0,R.jsx)(R5,{...t,status:a.data,pending:o.isPending,refusal:r,onClear:()=>o.mutate({projectId:e})})}var B5={"claude-code":{mint:{kind:`setup-token`,label:`Run claude setup-token`},placeholder:`paste sk-ant-oat01-…`}};function V5({probe:e,onDone:t,...n}){let[r,i]=(0,L.useState)(null),[a,o]=(0,L.useState)(``),[s,c]=(0,L.useState)(null),l=Ab(),u=B.setup.startTerminal.useMutation({onSuccess:({sessionId:e})=>i(e),onError:e=>l.push(e.message)}),d=B.setup.afkToken.useMutation({onSuccess:e=>{c(e),e.valid&&t()},onError:e=>l.push(e.message)});if(!e?.runtime)return null;let f=e.runtime,p=B5[f];return p?(0,R.jsxs)(j5,{...n,detail:e.detail,ok:e.status===`ok`,below:r&&(0,R.jsx)(N5,{sessionId:r,label:`setup-token`}),children:[p.mint&&!r&&(0,R.jsx)(Y,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(Dy,{}),onClick:()=>p.mint&&u.mutate({kind:p.mint.kind}),disabled:u.isPending,children:u.isPending?`Starting…`:p.mint.label}),(0,R.jsx)(DA,{"aria-label":n.label,mono:!0,className:`w-52`,value:a,onChange:e=>o(e.target.value),placeholder:p.placeholder,spellCheck:!1,autoComplete:`off`}),(0,R.jsx)(Y,{variant:`primary`,disabled:a.trim()===``||d.isPending,onClick:()=>d.mutate({token:a,runtime:f}),children:d.isPending?`Verifying…`:`Save & verify`}),s&&(0,R.jsxs)(`span`,{className:`basis-full text-right text-xs`,children:[(0,R.jsx)(rA,{tone:s.valid?`success`:`warning`,icon:s.valid?(0,R.jsx)(by,{}):(0,R.jsx)(tb,{}),children:s.detail}),s.fix&&(0,R.jsx)(`span`,{className:`mt-0.5 block text-text-tertiary`,children:s.fix})]})]}):null}function H5({row:e,onDone:t,...n}){let[r,i]=(0,L.useState)(null),a=Ab(),o=B.setup.startTerminal.useMutation({onSuccess:({sessionId:e})=>i(e),onError:e=>a.push(e.message)}),s=Im[e.runtime],c=e.probe.status===`ok`;return(0,R.jsx)(j5,{...n,ok:c,status:c?`Signed in`:`Not signed in`,detail:e.probe.detail,below:r&&(0,R.jsx)(N5,{sessionId:r,label:s.kind,onDone:()=>{i(null),t()}}),children:!c&&!r&&(0,R.jsx)(Y,{variant:`secondary`,size:`sm`,icon:(0,R.jsx)(ob,{}),disabled:o.isPending,onClick:()=>o.mutate({kind:s.kind}),children:o.isPending?`Starting…`:`Sign in`})})}function U5({command:e,onCopy:t}){return(0,R.jsxs)(`span`,{className:`inline-flex max-w-full min-w-0 items-center gap-1 rounded-md bg-surface-inset py-0.5 pr-0.5 pl-2`,children:[(0,R.jsx)(`code`,{className:`min-w-0 truncate font-mono text-xs text-text-secondary`,title:e,children:e}),(0,R.jsx)(nE,{label:`Copy`,size:`sm`,icon:(0,R.jsx)(Jy,{}),onClick:t})]})}function W5({globals:e,projectId:t,filter:n,highlightField:r}){return e.isLoading?(0,R.jsx)(WA,{children:`Loading settings…`}):e.error?(0,R.jsxs)(WA,{children:[`Could not load settings: `,e.error.message]}):e.data?(0,R.jsxs)(R.Fragment,{children:[M8.some(e=>R8(n,e.field))&&(0,R.jsx)(V8,{title:`Prerequisites for unattended burns`,children:(0,R.jsx)(w5,{projectId:t,filter:n,highlightField:r})}),(0,R.jsx)(B8,{title:`Width & retries`,rows:pm(e.data,`burns`),filter:n,highlightField:r})]}):null}var G5={prep:`established by preparation`,session:`established in a conversation on this machine`,human:`set by you`,build:`built by runcastle from this repo's own Dockerfile`};function K5({source:e,evidence:t,onClose:n}){let r=(0,L.useRef)(null);return(0,L.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.stopPropagation(),n())},t=e=>{let t=r.current?.parentElement;e.target instanceof Node&&t?.contains(e.target)||n()};return window.addEventListener(`keydown`,e,!0),window.addEventListener(`mousedown`,t),()=>{window.removeEventListener(`keydown`,e,!0),window.removeEventListener(`mousedown`,t)}},[n]),(0,R.jsxs)(`div`,{ref:r,className:`absolute top-7 left-0 z-10 max-h-72 w-105 overflow-auto rounded-lg bg-surface-raised px-3.5 py-3 shadow-popover animate-pop-in`,children:[(0,R.jsxs)(`h4`,{className:`m-0 mb-2 text-xs font-medium text-text-tertiary`,children:[`Evidence · `,G5[e]]}),(0,R.jsx)(`pre`,{className:`m-0 font-mono text-xs leading-[18px] whitespace-pre-wrap text-text-secondary`,children:t})]})}var q5=[{group:`model`,title:`Model & sandbox`},{group:`commands`,title:`Commands`},{group:`chat`,title:`Project chat`}];function J5({scoped:e,projectId:t,filter:n,highlightField:r}){let i=B.project.prep.useQuery({projectId:t}),[a,o]=(0,L.useState)(null);if(e.isLoading)return(0,R.jsx)(WA,{children:`Loading settings…`});if(e.error)return(0,R.jsxs)(WA,{children:[`Could not load settings: `,e.error.message]});if(!e.data)return null;let s=i.data?.findings??[],c=new Map(s.map(e=>[e.key,e])),l=pm(e.data,`project`,s),u=e=>{let t=c.get(e.key);return a!==e.key||!t?.evidence?null:(0,R.jsx)(K5,{source:t.source,evidence:t.evidence,onClose:()=>o(null)})};return(0,R.jsx)(R.Fragment,{children:q5.map(({group:e,title:i})=>(0,R.jsx)(B8,{title:i,rows:l.filter(t=>t.group===e),projectId:t,filter:n,highlightField:r,onOpenEvidence:e=>o(t=>t===e?null:e),evidence:u},e))})}var Y5={general:`How runcastle looks, where its server listens, and how sessions are sandboxed.`,models:`The default model, the roster this machine offers, and which model runs each step.`,burns:`What an unattended run needs before it starts, and how hard it tries once it does.`,project:`Values this project sets for itself. Unset fields inherit the global value, shown as ghost text.`},X5={general:Q8,models:b5,burns:W5,project:J5};function Z5({projectId:e,projectName:t,location:n,onClose:r}){let i=B.settings.get.useQuery(),a=B.settings.get.useQuery({projectId:e}),[o,s]=(0,L.useState)(n.page),[c,l]=(0,L.useState)(``),u=(0,L.useRef)(null),d=(0,L.useMemo)(()=>Om(c,$5(i.data,a.data)),[c,i.data,a.data]),f={query:c,...d},p=c.trim()!==``;(0,L.useEffect)(()=>{if(!p||d.counts[o]>0)return;let e=P8.find(e=>d.counts[e.page]>0);e&&s(e.page)},[p,d,o]);let m=e=>{!(e.metaKey||e.ctrlKey)||e.key.toLowerCase()!==`f`||(e.preventDefault(),u.current?.focus(),u.current?.select())},h=X5[o],g=P8.find(e=>e.page===o)?.label??``,_=p&&d.matches.size===0;return(0,R.jsx)(QA,{open:!0,onClose:r,size:`xl`,label:`Settings`,className:`overflow-hidden`,children:(0,R.jsxs)(`div`,{className:`relative grid h-[min(720px,84vh)] grid-cols-[208px_minmax(0,1fr)]`,onKeyDown:m,children:[(0,R.jsx)(F8,{page:o,filter:f,filterRef:u,projectName:t,onFilter:l,onSelect:s}),(0,R.jsx)(`section`,{className:`grid min-h-0 min-w-0 grid-rows-[minmax(0,1fr)] bg-surface`,children:(0,R.jsx)(`div`,{className:`min-h-0 overflow-x-hidden overflow-y-auto px-8 pt-9 pb-12`,children:(0,R.jsxs)(`div`,{className:`animate-rise-in`,children:[(0,R.jsxs)(`header`,{className:`mb-8`,children:[(0,R.jsx)(`h2`,{className:`m-0 text-lg font-semibold text-text`,children:g}),(0,R.jsx)(`p`,{className:`mt-1 mb-0 text-sm text-text-tertiary`,children:Y5[o]})]}),(0,R.jsx)(`div`,{children:(0,R.jsx)(h,{globals:i,scoped:a,projectId:e,filter:f,...o===n.page&&n.field?{highlightField:n.field}:{}})}),_&&(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(py,{}),title:`Nothing matches`,hint:`Try “model”, “verify” or “image”.`})]},o)})}),(0,R.jsx)(nE,{label:`Close`,kbd:`Esc`,size:`sm`,icon:(0,R.jsx)(xy,{}),onClick:r,className:`absolute top-3 right-3`})]})})}var Q5={id:X8,page:`general`,terms:[`Theme`,`Appearance`,`Dark`,`Light`,`System`]};function $5(e,t){let n=P8.flatMap(({page:n})=>{let r=n===`project`?t:e;return r?Dm(r,n):[]}),r=M8.map(e=>({id:e.field,page:`burns`,terms:[e.label,...e.terms]}));return[Q5,...n,...r]}function e7({projectId:e,nav:t}){let n=pg(e),{selectedFeatureId:r,projectSelected:i,preparing:a,select:o,selectProject:s,startPreparation:c,setCmdk:l}=n,[u,d]=(0,L.useState)(null),[f,p]=(0,L.useState)(0),[m,h]=(0,L.useState)(!1),[g,_]=(0,L.useState)(0),v=()=>{h(!0),_(e=>e+1)},[y,b]=(0,L.useState)(0),x=()=>{s(),b(e=>e+1)},S=()=>b(0),[C,w]=(0,L.useState)(0),T=()=>{s(),w(e=>e+1)},E=()=>w(0),D=qP(),O=B.feature.list.useQuery({projectId:e},{refetchInterval:eh()}),k=jb(e),A=B.project.prep.useQuery({projectId:e}),j=A.data?.prepared??!0,M=A.data?.empty??!0,N=B.feature.driveInfo.useQuery(void 0,{refetchInterval:eh()}).data,P=Pb(N,e)?N:null,F=O.data,[ee,te]=(0,L.useState)(!1),[ne]=(0,L.useState)(()=>Uh(Kh()));(0,L.useEffect)(()=>{if(ee||!F)return;let t=Wh(ne,e);if(t?.kind===`chat`)s();else if(t?.kind===`prepare`)c();else if(t){let e=F.find(e=>e.slug===t.featureSlug);o(e?.id??Sh(F)?.id??null)}else if(!r&&!i&&!a){let e=Sh(F);e&&o(e.id)}te(!0)},[ee,F,e,ne,r,i,a,o,s,c]);let I=F?.find(e=>e.id===r)?.slug??null;Yh(ee&&!n.creating?Gh({projectId:e,preparing:a,projectSelected:i,featureSlug:I}):null,t=>{if(!t||Bh(t)!==e)return;let n=Wh(t,e);if(!n)o(null);else if(n.kind===`chat`)s();else if(n.kind===`prepare`)c();else{let e=F?.find(e=>e.slug===n.featureSlug);o(e?.id??Sh(F??[])?.id??null)}});let re=()=>{s(),k.session?p(e=>e+1):k.start()};(0,L.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`k`?(e.preventDefault(),l(!0)):Nb(e)&&(e.preventDefault(),v())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l]);let ie=ay({...n,featureCount:F?.length??0,prepared:j,empty:M}),ae=F?.find(e=>e.id===r)?.phase,oe=sg(n.inspectorPreference,n.viewedPhase??ae),se=oy(ie,oe),ce=ie===`feature`?()=>n.toggleInspector(oe):void 0,le=ie===`create`?(0,R.jsx)(`section`,{className:`relative flex min-h-0 min-w-0 flex-col`,children:(0,R.jsx)(p8,{projectId:e,onCancel:n.cancelCreate,onCreated:n.select})}):ie===`prepare`?(0,R.jsx)(h8,{projectId:e,...n.preparing?{onClose:n.closePreparation}:{}}):ie===`project`?(0,R.jsx)(l8,{projectId:e,talk:k,newChatRequest:f,onConsumeNewChatRequest:()=>p(0),inboxRequest:y,onConsumeInboxRequest:S,empty:M,onOpenPreparation:n.startPreparation,driveRequest:C,onConsumeDriveRequest:E}):ie===`feature`&&r?(0,R.jsx)(LG,{label:`feature view`,fallback:e=>(0,R.jsx)(_6,{featureId:r,error:e}),children:(0,R.jsx)(N6,{featureId:r,viewedPhase:n.viewedPhase,onViewPhase:n.viewPhase,guidance:n.guidance,mapRailCollapsed:n.mapRailCollapsed,onToggleMapRail:n.toggleMapRail,artifactPaneCollapsed:n.artifactPaneCollapsed,onToggleArtifactPane:n.toggleArtifactPane,chatPanelOpen:n.chatPanelOpen,onToggleChatPanel:n.toggleChatPanel,driving:u,onDriveChange:d,detailsOpen:se,onToggleDetails:()=>n.toggleInspector(oe),onDeleted:()=>{n.select(null),n.selectProject()}})},`ws-${r}`):null,ue=(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(YP,{sidebar:(0,R.jsx)(QP,{projectId:e,nav:t,view:ie,selectedFeatureId:n.selectedFeatureId,talk:k,onSelect:n.select,onSelectProject:n.selectProject,onNewChat:re,onDraft:n.startDraft,onOpenPreparation:n.startPreparation,onOpenNote:v,onOpenCmdk:()=>l(!0),onOpenSettings:()=>n.openSettings(),projectDriveBranch:P?.branch??null,onOpenProjectDrive:T,driving:u,onDriveChange:d}),rail:(0,R.jsx)(fF,{onOpenCmdk:()=>l(!0),onNewChat:re}),children:(0,R.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col [&>*]:min-h-0 [&>*]:flex-1`,children:le})}),(0,R.jsx)(w8,{open:n.cmdkOpen,onClose:()=>n.setCmdk(!1),features:F??[],selectedFeatureId:n.selectedFeatureId,onSelect:n.select,onOpenSettings:()=>n.openSettings(),onOpenPreparation:n.startPreparation,onOpenProjectChat:n.selectProject,onOpenNote:v,onToggleSidebar:D.toggleSidebar,onToggleDetails:ce,nav:t}),(0,R.jsx)(D8,{projectId:e,projectName:t.currentProject?.name??``,open:m,openRequest:g,onClose:()=>h(!1),onOpenInbox:x}),n.settings&&(0,R.jsx)(Z5,{projectId:e,projectName:t.currentProject?.name??``,location:n.settings,onClose:n.closeSettings})]});return(0,R.jsx)(f2,{open:n.openSettings,children:ue})}var t7=`${wA} h-7 w-full font-medium`,n7=`A run is in flight — it has to finish before this project can go.`;function r7({project:e,stats:t,loading:n,onOpen:r,index:i}){let a=Ab(),o=B.useUtils(),[s,c]=(0,L.useState)(!1),[l,u]=(0,L.useState)(!1),[d,f]=(0,L.useState)(e.name),p=B.project.rename.useMutation({onSuccess:async()=>{await o.project.list.invalidate(),c(!1)},onError:e=>a.push(e.message)}),m=B.project.close.useMutation({onSuccess:async()=>{await o.project.list.invalidate(),a.push(`removed ${e.name}`,`info`)},onError:e=>a.push(e.message)});(0,L.useEffect)(()=>{if(!l)return;let e=e=>{e.key===`Escape`&&u(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l]);let h=t.activeRuns>0,g=()=>{let t=d.trim();t&&t!==e.name?p.mutate({projectId:e.id,name:t}):c(!1)},_=s?(0,R.jsx)(`input`,{className:t7,value:d,"aria-label":`Project name`,maxLength:80,autoFocus:!0,onChange:e=>f(e.target.value),onKeyDown:t=>{t.stopPropagation(),t.key===`Enter`&&g(),t.key===`Escape`&&(f(e.name),c(!1))},onBlur:g}):(0,R.jsx)(`span`,{className:`block truncate font-medium`,children:e.name});return l?(0,R.jsx)(vA,{className:`animate-fade-in`,wrap:!0,title:(0,R.jsxs)(`span`,{className:`text-text-secondary`,children:[`Remove `,(0,R.jsx)(`span`,{className:`font-medium text-text`,children:e.name}),`? The repo on disk is untouched.`,h&&(0,R.jsx)(`span`,{className:`block text-xs text-text-tertiary`,children:n7})]}),control:(0,R.jsxs)(`span`,{className:`flex shrink-0 gap-2 pr-3`,children:[(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>u(!1),children:`Cancel`}),(0,R.jsx)(Y,{size:`sm`,variant:`danger`,icon:(0,R.jsx)(Sy,{}),disabled:h||m.isPending,onClick:()=>m.mutate({projectId:e.id}),children:m.isPending?`Removing…`:`Remove`})]})}):(0,R.jsx)(vA,{index:i,leading:(0,R.jsx)(My,{}),title:_,description:(0,R.jsx)(`span`,{className:`block truncate text-left font-mono`,dir:`rtl`,title:e.repoPath,children:(0,R.jsx)(`bdi`,{children:e.repoPath})}),meta:n?`Loading…`:(0,R.jsx)(xA,{className:`flex-nowrap`,items:[{strong:t.total,text:t.total===1?`feature`:`features`},t.activeRuns>0&&{tone:`live`,strong:t.activeRuns,text:`running`},t.needsYou>0&&{tone:`warning`,strong:t.needsYou,text:`needs you`}]}),onClick:s?void 0:r,tooltip:`Open ${e.name}`,actionsOverlay:!0,actions:!s&&(0,R.jsx)(IP,{label:`${e.name} actions`,actions:[{key:`rename`,label:`Rename`,onSelect:()=>{f(e.name),c(!0)}},{key:`remove`,label:`Remove from list`,danger:!0,onSelect:()=>u(!0)}]})})}function i7({nav:e}){let t=e.projects??[],n=eh(),r=B.useQueries(e=>t.map(t=>e.feature.list({projectId:t.id},{refetchInterval:n}))),i=t.map((e,t)=>Ah(r[t]?.data??[])),a=i.reduce((e,t)=>e+t.activeRuns,0),o=i.reduce((e,t)=>e+t.needsYou,0);return(0,R.jsx)(YP,{sidebar:(0,R.jsx)(a7,{nav:e}),children:(0,R.jsxs)(`section`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,R.jsx)(MA,{crumbs:[{label:`Projects`,icon:(0,R.jsx)(Qy,{})}]}),(0,R.jsxs)(PA,{routeKey:`portfolio`,children:[(0,R.jsx)(FA,{title:`Projects`,meta:[{strong:t.length,text:t.length===1?`project open`:`projects open`},a>0&&{tone:`live`,strong:a,text:`running`},o>0&&{tone:`warning`,strong:o,text:o===1?`needs you`:`need you`}],actions:(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(yy,{}),onClick:e.showOpen,children:`Open a project`})}),(0,R.jsx)(yA,{divided:!0,label:`Open projects`,className:`mt-8`,children:t.map((t,n)=>(0,R.jsx)(r7,{index:n,project:t,stats:i[n],loading:r[n]?.data===void 0,onOpen:()=>e.enterProject(t.id)},t.id))})]})]})})}function a7({nav:e}){let t=Zm(),n=nM();return(0,R.jsxs)(`nav`,{"aria-label":`Projects`,className:`flex h-full min-h-0 flex-col p-2`,children:[(0,R.jsxs)(`div`,{className:`flex h-9 shrink-0 items-center gap-0.5`,children:[(0,R.jsx)(`div`,{className:`flex min-w-0 flex-1`,children:(0,R.jsx)(BP,{nav:e})}),(0,R.jsx)(JP,{})]}),(0,R.jsx)(`div`,{className:`mt-2 flex flex-col gap-px`,children:(0,R.jsx)(_A,{icon:(0,R.jsx)(Qy,{}),label:`All projects`,meta:e.projects?.length,active:!0})}),(0,R.jsx)(`div`,{className:`flex-1`}),(0,R.jsx)(uF,{health:t===`live`?`ok`:t===`connecting`?`connecting`:`reconnecting`,origin:typeof window>`u`?`this machine`:window.location.origin,sandbox:Dj,notify:null,theme:n.resolved,onToggleTheme:n.toggle})]})}var o7=4;function s7({crumbs:e,value:t,onNavigate:n,onEnterPath:r,placeholder:i}){let[a,o]=(0,L.useState)(null),s=a!==null,c=e.length>o7,l=c?e.slice(-3):e;return s?(0,R.jsx)(`input`,{className:`${wA} flex-1 font-mono text-xs`,"aria-label":`Path`,spellCheck:!1,autoComplete:`off`,autoFocus:!0,value:a,placeholder:i,onChange:e=>o(e.target.value),onBlur:()=>o(null),onKeyDown:e=>{e.key===`Enter`&&(r(a.trim()),o(null)),e.key===`Escape`&&(e.stopPropagation(),o(null))}}):(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-1 cursor-text items-center gap-0.5 truncate`,onClick:()=>o(t),role:`group`,"aria-label":`Current path`,children:[c&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(c7,{crumb:e[0],onNavigate:n}),(0,R.jsx)(Ty,{size:12,className:`shrink-0 text-text-disabled`}),(0,R.jsx)(`span`,{className:`shrink-0 px-1 text-sm text-text-tertiary`,title:e[e.length-1].path,children:`…`})]}),l.map((e,t)=>(0,R.jsxs)(`span`,{className:`flex shrink-0 items-center gap-0.5`,children:[(t>0||c)&&(0,R.jsx)(Ty,{size:12,className:`shrink-0 text-text-disabled`}),(0,R.jsx)(c7,{crumb:e,onNavigate:n})]},e.path)),(0,R.jsx)(`button`,{type:`button`,className:`${oE} ml-1 inline-flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-md text-icon transition-colors duration-(--dur-1) ease-app hover:bg-surface-hover hover:text-text`,"aria-label":`Edit path`,title:`Edit path`,onClick:()=>o(t),children:(0,R.jsx)(Ay,{size:14})})]})}function c7({crumb:e,onNavigate:t}){return(0,R.jsx)(`button`,{type:`button`,className:`${oE} shrink-0 rounded-sm px-1 py-0.5 cursor-pointer font-mono text-xs text-text-secondary transition-colors duration-(--dur-1) ease-app hover:bg-surface-hover hover:text-text`,onClick:n=>{n.stopPropagation(),t(e.path)},children:e.name})}function l7({initialPath:e,onPick:t,onCancel:n}){let r=e?.trim()||void 0,[i,a]=(0,L.useState)(r),[o,s]=(0,L.useState)(!1),[c,l]=(0,L.useState)(r??null),[u,d]=(0,L.useState)(null),f=B.project.roots.useQuery(),p=B.project.browse.useQuery({dir:i,showHidden:o},{placeholderData:e=>e,retry:!1}),m=p.data,h=m?.dir??i,g=e=>{l(null),d(null),a(e)},_=e=>{l(e||null),d(null),a(e||void 0)},v=c!==null&&p.isError?Fh(i,p.error.message):null,y=v!==null&&v.dir!==i,b=v?.dir,x=p.error?.message;(0,L.useEffect)(()=>{y&&(i===c&&x&&d(Rh(x)),a(b))},[y,b,i,c,x]);let S=e=>{if(![`ArrowDown`,`ArrowUp`,`Home`,`End`].includes(e.key))return;let t=[...e.currentTarget.querySelectorAll(`[data-dir-row] button`)];if(t.length===0)return;e.preventDefault();let n=t.indexOf(document.activeElement);t[e.key===`Home`?0:e.key===`End`?t.length-1:e.key===`ArrowDown`?Math.min(t.length-1,n+1):Math.max(0,n===-1?0:n-1)]?.focus()};return(0,R.jsxs)(QA,{open:!0,onClose:n,size:`lg`,labelledBy:`dir-picker-title`,className:`flex h-[min(620px,76vh)] flex-col overflow-hidden`,children:[(0,R.jsx)($A,{id:`dir-picker-title`,title:`Choose a repository`,description:`Browse this machine for a git repository to open.`,onClose:n}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-y border-border-subtle px-3 py-2`,children:[(0,R.jsx)(nE,{label:`Up one level`,icon:(0,R.jsx)(ib,{}),onClick:()=>m?.parent&&g(m.parent),disabled:!m?.parent}),(0,R.jsx)(s7,{crumbs:m?.crumbs??[],value:c??h??``,onNavigate:g,onEnterPath:_,placeholder:Tj()}),(0,R.jsx)(HA,{label:`Hidden`,checked:o,onChange:s,className:`shrink-0 px-2`})]}),u&&(0,R.jsx)(`div`,{className:`shrink-0 border-b border-border-subtle px-4 py-3`,children:(0,R.jsx)(YA,{message:u.message,path:u.path,hint:`Showing the closest folder that could be listed. Edit the path to try again.`})}),(0,R.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,R.jsxs)(`div`,{className:`flex w-44 shrink-0 flex-col gap-0.5 overflow-y-auto border-r border-border-subtle p-2`,onKeyDown:S,children:[(0,R.jsx)(mA,{className:`px-2.5`,children:`Locations`}),(f.data??[]).map(e=>(0,R.jsx)(`div`,{"data-dir-row":``,children:(0,R.jsx)(_A,{label:(0,R.jsx)(`span`,{className:`font-mono text-xs`,children:e.label}),title:e.path,icon:e.label===`~`?(0,R.jsx)(Qy,{}):(0,R.jsx)(My,{}),active:h===e.path,onClick:()=>g(e.path)})},e.path))]}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-y-auto p-2`,onKeyDown:S,children:[y||p.isLoading?(0,R.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 py-2 text-sm text-text-tertiary`,children:[(0,R.jsx)(aE,{}),` Loading…`]}):p.isError?(0,R.jsx)(`div`,{className:`p-2`,children:(0,R.jsx)(YA,{...Rh(p.error.message)})}):(m?.entries.length??0)===0?(0,R.jsx)(GA,{compact:!0,icon:(0,R.jsx)(My,{}),title:`No subfolders here`,hint:o?void 0:`Hidden folders, junctions and node_modules are filtered.`}):(0,R.jsx)(`div`,{className:`flex flex-col gap-0.5 animate-rise-in`,role:`list`,children:(m?.entries??[]).map(e=>(0,R.jsx)(`div`,{role:`listitem`,"data-dir-row":``,children:(0,R.jsx)(_A,{onDoubleClick:()=>e.isRepo&&t(e.path),label:e.name,title:e.path,icon:e.isRepo?(0,R.jsx)(gy,{}):(0,R.jsx)(My,{}),onClick:()=>g(e.path),className:e.isRepo?`text-text`:void 0,meta:e.isRepo?(0,R.jsx)(`span`,{className:`text-text-secondary`,children:`git`}):e.isSymlink?`link`:void 0})},e.path))},h),m?.truncated&&(0,R.jsx)(`p`,{className:`m-0 px-2.5 py-2 text-xs text-text-tertiary`,children:`Listing truncated — this folder is very large.`})]})]}),(0,R.jsxs)(tj,{className:`border-t border-border-subtle pt-3 pb-3`,start:(0,R.jsx)(`div`,{className:`min-w-0 truncate text-left font-mono text-xs`,dir:`rtl`,title:h,children:(0,R.jsx)(`bdi`,{children:h??`—`})}),children:[(0,R.jsx)(Y,{variant:`ghost`,onClick:n,children:`Cancel`}),(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(My,{}),onClick:()=>h&&t(h),disabled:!h||p.isError,children:`Open this folder`})]})]})}function u7({rail:e,stepKey:t,direction:n=`forward`,onKeyDown:r,children:i}){return(0,R.jsx)(`div`,{className:`flex min-h-full`,onKeyDown:r,children:(0,R.jsxs)(`div`,{className:q(`m-auto grid w-full gap-12 px-8 py-12`,e?`max-w-[860px] grid-cols-[176px_minmax(0,1fr)]`:`max-w-[560px]`),children:[e&&(0,R.jsx)(`div`,{className:`pt-1`,children:e}),(0,R.jsx)(`div`,{className:q(`min-w-0`,n===`forward`?`animate-slide-in-right`:`animate-rise-in`),children:i},t)]})})}function d7({title:e,children:t}){return(0,R.jsxs)(`header`,{children:[(0,R.jsx)(`h1`,{className:`m-0 text-xl font-semibold tracking-tight text-pretty text-text`,children:e}),(0,R.jsx)(`p`,{className:`mt-2 mb-0 text-base text-pretty text-text-secondary`,children:t})]})}function f7({onBack:e,note:t,children:n}){return(0,R.jsxs)(`footer`,{className:`mt-10 border-t border-border-subtle pt-5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e&&(0,R.jsx)(Y,{variant:`ghost`,icon:(0,R.jsx)(rb,{}),onClick:e,children:`Back`}),(0,R.jsx)(`div`,{className:`ml-auto flex items-center gap-2`,children:n})]}),t&&(0,R.jsx)(`p`,{className:`mt-2 mb-0 text-right text-xs text-text-tertiary`,children:t})]})}function p7({firstRun:e,rail:t,variant:n=`screen`,onOpened:r,onCancel:i}){let[a,o]=(0,L.useState)(``),[s,c]=(0,L.useState)(!1),[l,u]=(0,L.useState)(``),[d,f]=(0,L.useState)(!1),p=Ab(),m=B.useUtils(),h=B.project.open.useMutation({onSuccess:async e=>{await m.project.list.invalidate(),p.push(`opened ${e.name}`,`info`),r(e.id)},onError:()=>void 0}),g=B.project.initRepo.useMutation({onSuccess:({repoPath:e})=>{u(e),h.mutate({repoPath:e})},onError:()=>void 0}),_=()=>{h.reset(),g.reset(),f(!1)},v=e=>{let t=(e??a).trim();if(t){if(_(),!Ej(t)){f(!0);return}u(t),h.mutate({repoPath:t})}},y=()=>{_(),c(!0)},b=h.isPending||g.isPending,x=g.error??h.error,S=d?{message:`Enter an absolute path`,hint:`A path from the root of this machine, like ${Tj()}.`,path:null}:x?zh(x.message,l):null,C=e=>{o(e),c(!1),v(e)},w=(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:q(`flex items-center gap-2`,n===`screen`&&`mt-8`),children:[(0,R.jsx)(DA,{id:`open-repo-path`,size:`lg`,mono:!0,icon:(0,R.jsx)(My,{}),className:`flex-1`,value:a,onChange:e=>o(e.target.value),placeholder:Tj(),"aria-label":`Repository path`,autoFocus:!0,spellCheck:!1,invalid:!!S,"aria-describedby":S?`open-repo-error`:`open-repo-hint`,onKeyDown:e=>{e.key===`Enter`&&v()}}),(0,R.jsx)(Y,{size:`lg`,icon:(0,R.jsx)(py,{}),onClick:y,disabled:b,children:`Browse…`}),(0,R.jsx)(Y,{variant:`primary`,size:`lg`,icon:(0,R.jsx)(Iy,{}),loading:h.isPending,onClick:()=>v(),disabled:b||a.trim()===``,children:`Open`})]}),S?(0,R.jsx)(`div`,{className:`mt-3 animate-rise-in`,children:(0,R.jsx)(YA,{...S,id:`open-repo-error`,action:S.offer===`init-repo`?(0,R.jsx)(Y,{size:`sm`,icon:(0,R.jsx)(gy,{}),loading:g.isPending,onClick:()=>g.mutate({repoPath:l}),disabled:b,children:`Initialize repository`}):void 0})}):(0,R.jsx)(`p`,{id:`open-repo-hint`,className:`mt-2.5 mb-0 text-xs text-text-tertiary`,children:`Paste an absolute path, or browse for one. The default branch is detected when the project opens.`})]}),T=(0,R.jsx)(R.Fragment,{children:s&&(0,R.jsx)(l7,{initialPath:a,onPick:C,onCancel:()=>c(!1)})});return n===`dialog`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)($A,{title:`Open a project`,description:`Point runcastle at a local git repository — every feature runs its pipeline against it.`,onClose:b?void 0:i}),(0,R.jsx)(ej,{className:`pt-1`,children:w}),T]}):(0,R.jsxs)(u7,{rail:t,stepKey:`project`,onKeyDown:t=>{t.key===`Escape`&&!e&&!s&&i()},children:[!t&&(0,R.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs text-text-tertiary`,children:[(0,R.jsx)(Cb,{size:14}),e?`Welcome to runcastle`:`Your projects`]}),(0,R.jsx)(d7,{title:e?`Open your first project`:`Open a project`,children:`Point runcastle at a local git repository — every feature runs its pipeline against it.`}),w,!e&&(0,R.jsx)(`footer`,{className:`mt-10 flex items-center border-t border-border-subtle pt-5`,children:(0,R.jsx)(Y,{variant:`ghost`,icon:(0,R.jsx)(rb,{}),onClick:i,disabled:b,children:`Cancel`})}),T]})}function m7({onBack:e,onNext:t}){let[n,r]=(0,L.useState)(!1);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(d7,{title:`Run burns unattended?`,children:P_}),n&&(0,R.jsx)(`div`,{className:`mt-8 animate-rise-in`,children:(0,R.jsx)(w5,{onDismiss:t})}),(0,R.jsx)(f7,{onBack:e,children:!n&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(Y,{variant:`ghost`,icon:(0,R.jsx)(Py,{}),onClick:()=>r(!0),children:`Set up now`}),(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(Iy,{}),onClick:t,children:`Skip for now`})]})})]})}function h7({onBack:e,onNext:t}){let[n,r]=(0,L.useState)(``),[i,a]=(0,L.useState)(``),o=Ab(),s=B.useUtils(),c=B.setup.gitIdentity.useMutation({onSuccess:async()=>{await s.setup.doctor.invalidate(),t()},onError:e=>o.push(e.message)}),l=n.trim()!==``&&i.includes(`@`),u=()=>l&&c.mutate({name:n.trim(),email:i.trim()}),d=e=>e.key===`Enter`&&u();return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(d7,{title:`Set your git identity`,children:[`runcastle commits documentation and merges on your behalf, so it needs a name and email. This writes to `,(0,R.jsx)(`code`,{className:`font-mono text-sm text-text`,children:`git config --global`}),`.`]}),(0,R.jsxs)(`div`,{className:`mt-8 flex max-w-sm flex-col gap-4`,children:[(0,R.jsx)(AA,{label:`Name`,children:(0,R.jsx)(DA,{id:`wiz-name`,size:`lg`,value:n,onChange:e=>r(e.target.value),placeholder:`Ada Lovelace`,autoFocus:!0,spellCheck:!1,onKeyDown:d})}),(0,R.jsx)(AA,{label:`Email`,children:(0,R.jsx)(DA,{id:`wiz-email`,size:`lg`,type:`email`,value:i,onChange:e=>a(e.target.value),placeholder:`ada@example.com`,spellCheck:!1,onKeyDown:d})})]}),(0,R.jsx)(f7,{onBack:e,children:(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(Iy,{}),loading:c.isPending,onClick:u,disabled:!l,children:`Continue`})})]})}function g7({onNext:e}){return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(Cb,{size:32,variant:`solid`,className:`mb-6`}),(0,R.jsx)(d7,{title:`Your coding agent, driven through a pipeline`,children:`Describe a feature and runcastle runs the agent sessions that carry it from idea to merged, stopping at each gate until you say go.`}),(0,R.jsx)(`ol`,{className:`m-0 mt-8 flex list-none flex-col p-0`,children:ev.map((e,t)=>(0,R.jsxs)(`li`,{className:`grid grid-cols-[16px_96px_minmax(0,1fr)] items-center gap-3 border-b border-border-subtle py-2.5 text-sm last:border-b-0 animate-rise-in`,style:{animationDelay:`${120+t*40}ms`},children:[(0,R.jsx)(xb,{phase:e,size:16,label:``}),(0,R.jsx)(`span`,{className:`font-medium text-text`,children:vb[e]}),(0,R.jsx)(`span`,{className:`text-text-tertiary`,children:nv[e]})]},e))}),(0,R.jsx)(f7,{children:(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(Iy,{}),onClick:e,autoFocus:!0,children:`Set up runcastle`})})]})}function _7({runtimes:e,onBack:t,onNext:n}){let r=Rm(e);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(d7,{title:`Connect a coding agent`,children:`runcastle drives whichever agent you have — sign in to one or both. The ones you connect here are the ones whose models you can pick later.`}),(0,R.jsx)(`div`,{className:`mt-8`,children:(0,R.jsx)(M5,{children:e.map(e=>(0,R.jsx)(v7,{runtime:e},e.runtime))})}),(0,R.jsx)(f7,{onBack:t,note:r.length===0&&`Connect at least one agent to continue — runcastle has nothing to run without one.`,children:(0,R.jsx)(Y,{variant:`primary`,icon:(0,R.jsx)(Iy,{}),onClick:n,disabled:r.length===0,children:`Continue`})})]})}function v7({runtime:e}){let[t,n]=(0,L.useState)(null),r=Ab(),i=B.useUtils(),a=B.setup.startTerminal.useMutation({onSuccess:({sessionId:e})=>n(e),onError:e=>r.push(e.message)}),o=Im[e.runtime],s=e.talkReady?`Ready`:e.installed?`Not signed in`:`Not installed`;return(0,R.jsxs)(j5,{label:e.label,status:s,detail:e.detail,ok:e.talkReady,below:t&&(0,R.jsx)(N5,{sessionId:t,label:o.kind,onDone:()=>{n(null),i.setup.doctor.invalidate()}}),children:[e.installFix&&(0,R.jsx)(U5,{command:e.installFix,onCopy:()=>{navigator.clipboard?.writeText(e.installFix??``),r.push(`copied`,`info`)}}),e.installed&&!e.talkReady&&!t&&(0,R.jsxs)(Y,{size:`sm`,icon:(0,R.jsx)(Dy,{}),loading:a.isPending,onClick:()=>a.mutate({kind:o.kind}),children:[`Run `,o.command]}),e.talkReady&&!e.afkReady&&(0,R.jsxs)(`span`,{className:`basis-full text-right text-xs text-text-tertiary`,children:[`Signed in for sessions you watch. Unattended burns on `,e.label,` also need its key — the next step sets that up.`]})]})}var y7={passed:`shipped`,done:`shipped`,current:`review`,todo:`draft`},b7={passed:`text-text-secondary`,done:`text-text-secondary`,current:`bg-surface-selected font-medium text-text`,todo:`text-text-tertiary`};function x7({steps:e}){return(0,R.jsxs)(`nav`,{"aria-label":`Setup`,className:`flex flex-col gap-4`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 text-sm font-medium text-text`,children:[(0,R.jsx)(Cb,{size:16}),`Set up runcastle`]}),(0,R.jsx)(`ol`,{className:`m-0 flex list-none flex-col gap-0.5 p-0`,"aria-label":`Setup progress`,children:e.map(e=>(0,R.jsxs)(`li`,{"data-state":e.state,"aria-current":e.state===`current`?`step`:void 0,className:q(`flex flex-col rounded-md px-2.5 py-1.5 text-sm transition-colors duration-(--dur-2) ease-app`,b7[e.state]),children:[(0,R.jsxs)(`span`,{className:`flex min-h-5 items-center gap-2`,children:[(0,R.jsx)(xb,{phase:y7[e.state],size:14,label:``}),e.label]}),e.detected&&(0,R.jsx)(`span`,{className:`mt-0.5 pl-5.5 text-xs font-normal text-pretty text-text-tertiary`,children:e.detected})]},e.key))})]})}function S7({onOpened:e,onCancel:t}){let n=B.setup.doctor.useQuery(void 0,{refetchOnWindowFocus:!1}),r=n.data?.results.find(e=>e.id===`git-identity`),i=Lm(n.data?.results??[]),[a,o]=(0,L.useState)(`intro`),[s,c]=(0,L.useState)(`forward`),l=(e,t)=>{c(t),o(e)},u=B.setup.seedModelDefaults.useMutation(),d=()=>{u.mutate({runtimes:Rm(i)}),l(`project`,`forward`)};if(n.isLoading)return(0,R.jsx)(u7,{children:(0,R.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-sm text-text-tertiary`,children:[(0,R.jsx)(aE,{}),` Preparing setup…`]})});if(a===`project`)return(0,R.jsx)(p7,{firstRun:!0,rail:(0,R.jsx)(x7,{steps:Vm(`project`,r)}),onOpened:e,onCancel:t});if(a===`intro`)return(0,R.jsx)(u7,{stepKey:`intro`,direction:s,children:(0,R.jsx)(g7,{onNext:()=>l(Nm(r),`forward`)})});let f=()=>{let e=Pm(a);e===`project`||e===void 0?d():l(e,`forward`)},p=()=>l(Fm(a,r)??`intro`,`back`);return(0,R.jsxs)(u7,{rail:(0,R.jsx)(x7,{steps:Vm(a,r)}),stepKey:a,direction:s,children:[a===`identity`&&(0,R.jsx)(h7,{onBack:p,onNext:f}),a===`runtimes`&&(0,R.jsx)(_7,{runtimes:i,onBack:p,onNext:f}),a===`afk`&&(0,R.jsx)(m7,{onBack:p,onNext:f})]})}var C7=`runcastle.update.dismissed`;function w7(e,t){return e.updateAvailable&&e.latest!==null&&e.latest!==t}function T7({tone:e=`neutral`,icon:t,children:n,action:r,onDismiss:i,dismissLabel:a=`Dismiss`}){return(0,R.jsxs)(`div`,{role:`status`,className:q(`flex h-10 shrink-0 animate-fade-in items-center gap-2.5 overflow-hidden border-b border-border-subtle pr-2 pl-4 text-sm`,e===`danger`?`bg-danger-subtle`:`bg-surface`),children:[(0,R.jsx)(`span`,{className:q(`inline-flex shrink-0 [&>svg]:size-4`,e===`danger`?`text-danger`:`text-accent`),children:t}),(0,R.jsx)(`span`,{className:`flex min-w-0 flex-1 items-center gap-2 truncate text-text-secondary`,children:n}),r,i&&(0,R.jsx)(nE,{size:`sm`,label:a,icon:(0,R.jsx)(xy,{}),onClick:i})]})}function E7(){let e=Ab(),t=B.system.checkUpdate.useQuery(void 0,{staleTime:1/0,refetchOnWindowFocus:!1,retry:!1}),[n,r]=(0,L.useState)(()=>{try{return localStorage.getItem(C7)}catch{return null}}),i=t.data;return!i||!i.latest||!w7(i,n)?null:(0,R.jsxs)(T7,{icon:(0,R.jsx)(Iy,{}),onDismiss:()=>{try{localStorage.setItem(C7,i.latest)}catch{}r(i.latest)},dismissLabel:`Dismiss update notice`,action:(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,icon:(0,R.jsx)(Jy,{}),onClick:()=>navigator.clipboard.writeText(i.command).then(()=>e.push(`Update command copied`,`info`),()=>e.push(`Copy failed`)),children:`Copy command`}),children:[(0,R.jsxs)(`span`,{className:`shrink-0 text-text`,children:[`runcastle `,i.latest,` is available`]}),(0,R.jsxs)(`span`,{className:`shrink-0 text-text-tertiary`,children:[`you're on `,i.current]}),(0,R.jsx)(`code`,{className:`min-w-0 truncate font-mono text-xs text-text-tertiary select-all`,children:i.command})]})}function D7({error:e,onRecheck:t}){return e?(0,R.jsxs)(T7,{tone:`danger`,icon:(0,R.jsx)(tb,{}),action:(0,R.jsx)(Y,{size:`sm`,variant:`ghost`,icon:(0,R.jsx)(ab,{}),onClick:t,children:`Re-run checks`}),children:[(0,R.jsx)(`span`,{className:`shrink-0 font-medium text-text`,children:`Setup checks could not run`}),(0,R.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs text-text-secondary`,title:e,children:e})]}):null}function O7(){let e=$h(),t,n=null;return e.loading||e.projects===void 0?t=(0,R.jsx)(YP,{children:(0,R.jsx)(PA,{children:(0,R.jsx)(UA,{children:`Loading projects…`})})}):e.view===`setup`?t=(0,R.jsx)(YP,{children:(0,R.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto`,children:(0,R.jsx)(S7,{onOpened:e.enterProject,onCancel:e.cancelOpen})})}):e.view===`open`&&e.projects.length>0?(t=e.currentProjectId?(0,R.jsx)(e7,{projectId:e.currentProjectId,nav:e},e.currentProjectId):(0,R.jsx)(i7,{nav:e}),n=(0,R.jsx)(QA,{open:!0,onClose:e.cancelOpen,size:`md`,label:`Open a project`,children:(0,R.jsx)(p7,{variant:`dialog`,firstRun:!1,onOpened:e.enterProject,onCancel:e.cancelOpen})})):t=e.view===`open`?(0,R.jsx)(YP,{children:(0,R.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto`,children:(0,R.jsx)(p7,{firstRun:e.projects.length===0,onOpened:e.enterProject,onCancel:e.cancelOpen})})}):e.view===`project`&&e.currentProjectId?(0,R.jsx)(e7,{projectId:e.currentProjectId,nav:e},e.currentProjectId):(0,R.jsx)(i7,{nav:e}),(0,R.jsx)(KP,{notices:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(E7,{}),(0,R.jsx)(D7,{error:e.doctorError,onRecheck:e.recheckDoctor})]}),children:(0,R.jsxs)(`div`,{className:`h-full bg-canvas`,children:[t,n]})})}function k7(){return ih(),(0,R.jsx)(O7,{})}function A7(e){return e instanceof Error&&e.message?e.message:typeof e==`string`&&e!==``?e:`something went wrong`}function j7(e,t){return typeof t.options.onError==`function`?null:A7(e)}Zj();function M7(){let[e]=(0,L.useState)(()=>new Ve({mutationCache:new Pe({onError:(e,t,n,r)=>{let i=j7(e,r);i&&Ob(i)}}),defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!0,refetchOnReconnect:!0}}})),[t]=(0,L.useState)(()=>B.createClient({links:[Bn({url:`/api/trpc`})]}));return(0,R.jsx)(B.Provider,{client:t,queryClient:e,children:(0,R.jsx)(Je,{client:e,children:(0,R.jsx)(UT,{children:(0,R.jsx)(kb,{children:(0,R.jsx)(k7,{})})})})})}var N7=document.getElementById(`root`);if(!N7)throw Error(`#root not found`);(0,pr.createRoot)(N7).render((0,R.jsx)(L.StrictMode,{children:(0,R.jsx)(M7,{})}));
|