nomoreide 0.1.84 → 0.1.85
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.
|
@@ -115,7 +115,7 @@ WARNING: This link could potentially be dangerous`)){let s=window.open();if(s){t
|
|
|
115
115
|
`))),this._register(this._terminal.onA11yTab(l=>this._handleTab(l))),this._register(this._terminal.onKey(l=>this._handleKey(l.key))),this._register(this._terminal.onBlur(()=>this._clearLiveRegion())),this._register(this._renderService.onDimensionsChange(()=>this._refreshRowsDimensions())),this._register(ut(a,"selectionchange",()=>this._handleSelectionChange())),this._register(this._coreBrowserService.onDprChange(()=>this._refreshRowsDimensions())),this._refreshRowsDimensions(),this._refreshRows(),this._register(is(()=>{this._accessibilityContainer.remove(),this._rowElements.length=0}))}_handleTab(e){for(let t=0;t<e;t++)this._handleChar(" ")}_handleChar(e){this._liveRegionLineCount<hC+1&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==e&&(this._charsToAnnounce+=e):this._charsToAnnounce+=e,e===`
|
|
116
116
|
`&&(this._liveRegionLineCount++,this._liveRegionLineCount===hC+1&&(this._liveRegion.textContent+=Hv.get())))}_clearLiveRegion(){this._liveRegion.textContent="",this._liveRegionLineCount=0}_handleKey(e){this._clearLiveRegion(),new RegExp("\\p{Control}","u").test(e)||this._charsToConsume.push(e)}_refreshRows(e,t){this._liveRegionDebouncer.refresh(e,t,this._terminal.rows)}_renderRows(e,t){let s=this._terminal.buffer,n=s.lines.length.toString();for(let a=e;a<=t;a++){let l=s.lines.get(s.ydisp+a),c=[],d=l?.translateToString(!0,void 0,void 0,c)||"",f=(s.ydisp+a+1).toString(),h=this._rowElements[a];h&&(d.length===0?(h.textContent=" ",this._rowColumns.set(h,[0,1])):(h.textContent=d,this._rowColumns.set(h,c)),h.setAttribute("aria-posinset",f),h.setAttribute("aria-setsize",n),this._alignRowWidth(h))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce="")}_handleBoundaryFocus(e,t){let s=e.target,n=this._rowElements[t===0?1:this._rowElements.length-2],a=s.getAttribute("aria-posinset"),l=t===0?"1":`${this._terminal.buffer.lines.length}`;if(a===l||e.relatedTarget!==n)return;let c,d;if(t===0?(c=s,d=this._rowElements.pop(),this._rowContainer.removeChild(d)):(c=this._rowElements.shift(),d=s,this._rowContainer.removeChild(c)),c.removeEventListener("focus",this._topBoundaryFocusListener),d.removeEventListener("focus",this._bottomBoundaryFocusListener),t===0){let f=this._createAccessibilityTreeNode();this._rowElements.unshift(f),this._rowContainer.insertAdjacentElement("afterbegin",f)}else{let f=this._createAccessibilityTreeNode();this._rowElements.push(f),this._rowContainer.appendChild(f)}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},s={node:e.focusNode,offset:e.focusOffset};if((t.node.compareDocumentPosition(s.node)&Node.DOCUMENT_POSITION_PRECEDING||t.node===s.node&&t.offset>s.offset)&&([t,s]=[s,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 n=this._rowElements.slice(-1)[0];if(s.node.compareDocumentPosition(n)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(s={node:n,offset:n.textContent?.length??0}),!this._rowContainer.contains(s.node))return;let a=({node:d,offset:f})=>{let h=d instanceof Text?d.parentNode:d,g=parseInt(h?.getAttribute("aria-posinset"),10)-1;if(isNaN(g))return console.warn("row is invalid. Race condition?"),null;let p=this._rowColumns.get(h);if(!p)return console.warn("columns is null. Race condition?"),null;let b=f<p.length?p[f]:p.slice(-1)[0]+1;return b>=this._terminal.cols&&(++g,b=0),{row:g,column:b}},l=a(t),c=a(s);if(!(!l||!c)){if(l.row>c.row||l.row===c.row&&l.column>=c.column)throw new Error("invalid range");this._terminal.select(l.column,l.row,(c.row-l.row)*this._terminal.cols-l.column+c.column)}}_handleResize(e){this._rowElements[this._rowElements.length-1].removeEventListener("focus",this._bottomBoundaryFocusListener);for(let t=this._rowContainer.children.length;t<this._terminal.rows;t++)this._rowElements[t]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[t]);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,s=this._rowColumns.get(e)?.slice(-1)?.[0];if(!s)return;let n=s*this._renderService.dimensions.css.cell.width;e.style.transform=`scaleX(${n/t})`}};Ef=ps([Ge(1,P0),Ge(2,Hr),Ge(3,$r)],Ef);var _x=class extends xt{constructor(e,t,s,n,a){super(),this._element=e,this._mouseService=t,this._renderService=s,this._bufferService=n,this._linkProviderService=a,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this._register(new Ie),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new Ie),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(is(()=>{yo(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(ut(this._element,"mouseleave",()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(ut(this._element,"mousemove",this._handleMouseMove.bind(this))),this._register(ut(this._element,"mousedown",this._handleMouseDown.bind(this))),this._register(ut(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 s=e.composedPath();for(let n=0;n<s.length;n++){let a=s[n];if(a.classList.contains("xterm"))break;if(a.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(n=>{n?.forEach(a=>{a.link.dispose&&a.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=e.y);let s=!1;for(let[n,a]of this._linkProviderService.linkProviders.entries())t?this._activeProviderReplies?.get(n)&&(s=this._checkLinkProviderResult(n,e,s)):a.provideLinks(e.y,l=>{if(this._isMouseOut)return;let c=l?.map(d=>({link:d}));this._activeProviderReplies?.set(n,c),s=this._checkLinkProviderResult(n,e,s),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)})}_removeIntersectingLinks(e,t){let s=new Set;for(let n=0;n<t.size;n++){let a=t.get(n);if(a)for(let l=0;l<a.length;l++){let c=a[l],d=c.link.range.start.y<e?0:c.link.range.start.x,f=c.link.range.end.y>e?this._bufferService.cols:c.link.range.end.x;for(let h=d;h<=f;h++){if(s.has(h)){a.splice(l--,1);break}s.add(h)}}}}_checkLinkProviderResult(e,t,s){if(!this._activeProviderReplies)return s;let n=this._activeProviderReplies.get(e),a=!1;for(let l=0;l<e;l++)(!this._activeProviderReplies.has(l)||this._activeProviderReplies.get(l))&&(a=!0);if(!a&&n){let l=n.find(c=>this._linkAtPosition(c.link,t));l&&(s=!0,this._handleNewLink(l))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!s)for(let l=0;l<this._activeProviderReplies.size;l++){let c=this._activeProviderReplies.get(l)?.find(d=>this._linkAtPosition(d.link,t));if(c){s=!0,this._handleNewLink(c);break}}return s}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);t&&this._mouseDownLink&&YW(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,yo(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?!0:e.link.decorations.underline,pointerCursor:e.link.decorations===void 0?!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:s=>{this._currentLink?.state&&this._currentLink.state.decorations.pointerCursor!==s&&(this._currentLink.state.decorations.pointerCursor=s,this._currentLink.state.isHovered&&this._element.classList.toggle("xterm-cursor-pointer",s))}},underline:{get:()=>this._currentLink?.state?.decorations.underline,set:s=>{this._currentLink?.state&&this._currentLink?.state?.decorations.underline!==s&&(this._currentLink.state.decorations.underline=s,this._currentLink.state.isHovered&&this._fireUnderlineEvent(e.link,s))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(s=>{if(!this._currentLink)return;let n=s.start===0?0:s.start+1+this._bufferService.buffer.ydisp,a=this._bufferService.buffer.ydisp+1+s.end;if(this._currentLink.link.range.start.y>=n&&this._currentLink.link.range.end.y<=a&&(this._clearCurrentLink(n,a),this._lastMouseEvent)){let l=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);l&&this._askForLink(l,!1)}})))}_linkHover(e,t,s){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(s,t.text)}_fireUnderlineEvent(e,t){let s=e.range,n=this._bufferService.buffer.ydisp,a=this._createLinkUnderlineEvent(s.start.x-1,s.start.y-n-1,s.end.x,s.end.y-n-1,void 0);(t?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(a)}_linkLeave(e,t,s){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(s,t.text)}_linkAtPosition(e,t){let s=e.range.start.y*this._bufferService.cols+e.range.start.x,n=e.range.end.y*this._bufferService.cols+e.range.end.x,a=t.y*this._bufferService.cols+t.x;return s<=a&&a<=n}_positionFromMouseEvent(e,t,s){let n=s.getCoords(e,t,this._bufferService.cols,this._bufferService.rows);if(n)return{x:n[0],y:n[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(e,t,s,n,a){return{x1:e,y1:t,x2:s,y2:n,cols:this._bufferService.cols,fg:a}}};_x=ps([Ge(1,z0),Ge(2,$r),Ge(3,wn),Ge(4,A5)],_x);function YW(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 XW=class extends $W{constructor(e={}){super(e),this._linkifier=this._register(new jl),this.browser=K5,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new jl),this._onCursorMove=this._register(new Ie),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new Ie),this.onKey=this._onKey.event,this._onRender=this._register(new Ie),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new Ie),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new Ie),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new Ie),this.onBell=this._onBell.event,this._onFocus=this._register(new Ie),this._onBlur=this._register(new Ie),this._onA11yCharEmitter=this._register(new Ie),this._onA11yTabEmitter=this._register(new Ie),this._onWillOpen=this._register(new Ie),this._setup(),this._decorationService=this._instantiationService.createInstance(GW),this._instantiationService.setService(Bu,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(IV),this._instantiationService.setService(A5,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(Fv)),this._register(this._inputHandler.onRequestBell(()=>this._onBell.fire())),this._register(this._inputHandler.onRequestRefreshRows(t=>this.refresh(t?.start??0,t?.end??this.rows-1))),this._register(this._inputHandler.onRequestSendFocus(()=>this._reportFocus())),this._register(this._inputHandler.onRequestReset(()=>this.reset())),this._register(this._inputHandler.onRequestWindowsOptionsReport(t=>this._reportWindowsOptions(t))),this._register(this._inputHandler.onColor(t=>this._handleColorEvent(t))),this._register(nn.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(nn.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(nn.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(nn.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(t=>this._afterResize(t.cols,t.rows))),this._register(is(()=>{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 s,n="";switch(t.index){case 256:s="foreground",n="10";break;case 257:s="background",n="11";break;case 258:s="cursor",n="12";break;default:s="ansi",n="4;"+t.index}switch(t.type){case 0:let a=Jt.toColorRGB(s==="ansi"?this._themeService.colors.ansi[t.index]:this._themeService.colors[s]);this.coreService.triggerDataEvent(`${Te.ESC}]${n};${OW(a)}${V5.ST}`);break;case 1:if(s==="ansi")this._themeService.modifyColors(l=>l.ansi[t.index]=Ds.toColor(...t.color));else{let l=s;this._themeService.modifyColors(c=>c[l]=Ds.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(Ef,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(Te.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(Te.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 s=Math.min(this.buffer.x,this.cols-1),n=this._renderService.dimensions.css.cell.height,a=t.getWidth(s),l=this._renderService.dimensions.css.cell.width*a,c=this.buffer.y*this._renderService.dimensions.css.cell.height,d=s*this._renderService.dimensions.css.cell.width;this.textarea.style.left=d+"px",this.textarea.style.top=c+"px",this.textarea.style.width=l+"px",this.textarea.style.height=n+"px",this.textarea.style.lineHeight=n+"px",this.textarea.style.zIndex="-5"}_initGlobal(){this._bindKeys(),this._register(ut(this.element,"copy",t=>{this.hasSelection()&&eG(t,this._selectionService)}));let e=t=>tG(t,this.textarea,this.coreService,this.optionsService);this._register(ut(this.textarea,"paste",e)),this._register(ut(this.element,"paste",e)),Y5?this._register(ut(this.element,"mousedown",t=>{t.button===2&&w2(t,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(ut(this.element,"contextmenu",t=>{w2(t,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),G0&&this._register(ut(this.element,"auxclick",t=>{t.button===1&&y5(t,this.textarea,this.screenElement)}))}_bindKeys(){this._register(ut(this.textarea,"keyup",e=>this._keyUp(e),!0)),this._register(ut(this.textarea,"keydown",e=>this._keyDown(e),!0)),this._register(ut(this.textarea,"keypress",e=>this._keyPress(e),!0)),this._register(ut(this.textarea,"compositionstart",()=>this._compositionHelper.compositionstart())),this._register(ut(this.textarea,"compositionupdate",e=>this._compositionHelper.compositionupdate(e))),this._register(ut(this.textarea,"compositionend",()=>this._compositionHelper.compositionend())),this._register(ut(this.textarea,"input",e=>this._inputEvent(e),!0)),this._register(this.onRender(()=>this._compositionHelper.updateCompositionElements()))}open(e){if(!e)throw new 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(ut(this.screenElement,"mousemove",a=>this.updateCursorStyle(a))),this._helperContainer=this._document.createElement("div"),this._helperContainer.classList.add("xterm-helpers"),this.screenElement.appendChild(this._helperContainer),t.appendChild(this.screenElement);let s=this.textarea=this._document.createElement("textarea");this.textarea.classList.add("xterm-helper-textarea"),this.textarea.setAttribute("aria-label",Iv.get()),Q5||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",()=>s.readOnly=this.optionsService.rawOptions.disableStdin)),this.textarea.readOnly=this.optionsService.rawOptions.disableStdin,this._coreBrowserService=this._register(this._instantiationService.createInstance(zV,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<"u"?window.document:null)),this._instantiationService.setService(Hr,this._coreBrowserService),this._register(ut(this.textarea,"focus",a=>this._handleTextAreaFocus(a))),this._register(ut(this.textarea,"blur",()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(cx,this._document,this._helperContainer),this._instantiationService.setService(hm,this._charSizeService),this._themeService=this._instantiationService.createInstance(fx),this._instantiationService.setService(Pl,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(kf),this._instantiationService.setService(j5,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(dx,this.rows,this.screenElement)),this._instantiationService.setService($r,this._renderService),this._register(this._renderService.onRenderedViewportChange(a=>this._onRender.fire(a))),this.onResize(a=>this._renderService.resize(a.cols,a.rows)),this._compositionView=this._document.createElement("div"),this._compositionView.classList.add("composition-view"),this._compositionHelper=this._instantiationService.createInstance(ax,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(ux),this._instantiationService.setService(z0,this._mouseService);let n=this._linkifier.value=this._register(this._instantiationService.createInstance(_x,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(ix,this.element,this.screenElement)),this._register(this._viewport.onRequestScrollLines(a=>{super.scrollLines(a,!1),this.refresh(0,this.rows-1)})),this._selectionService=this._register(this._instantiationService.createInstance(hx,this.element,this.screenElement,n)),this._instantiationService.setService(cG,this._selectionService),this._register(this._selectionService.onRequestScrollLines(a=>this.scrollLines(a.amount,a.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(a=>this._renderService.handleSelectionChanged(a.start,a.end,a.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(a=>{this.textarea.value=a,this.textarea.focus(),this.textarea.select()})),this._register(nn.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(rx,this.screenElement)),this._register(ut(this.element,"mousedown",a=>this._selectionService.handleMouseDown(a))),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(Ef,this)),this._register(this.optionsService.onSpecificOptionChange("screenReaderMode",a=>this._handleScreenReaderModeOptionChange(a))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Sf,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange("overviewRuler",a=>{!this._overviewRulerRenderer&&a&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Sf,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(lx,this,this._document,this.element,this.screenElement,this._viewportElement,this._helperContainer,this.linkifier)}bindMouse(){let e=this,t=this.element;function s(l){let c=e._mouseService.getMouseReportCoords(l,e.screenElement);if(!c)return!1;let d,f;switch(l.overrideType||l.type){case"mousemove":f=32,l.buttons===void 0?(d=3,l.button!==void 0&&(d=l.button<3?l.button:3)):d=l.buttons&1?0:l.buttons&4?1:l.buttons&2?2:3;break;case"mouseup":f=0,d=l.button<3?l.button:3;break;case"mousedown":f=1,d=l.button<3?l.button:3;break;case"wheel":if(e._customWheelEventHandler&&e._customWheelEventHandler(l)===!1)return!1;let h=l.deltaY;if(h===0||e.coreMouseService.consumeWheelEvent(l,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return!1;f=h<0?0:1,d=4;break;default:return!1}return f===void 0||d===void 0||d>4?!1:e.coreMouseService.triggerMouseEvent({col:c.col,row:c.row,x:c.x,y:c.y,button:d,action:f,ctrl:l.ctrlKey,alt:l.altKey,shift:l.shiftKey})}let n={mouseup:null,wheel:null,mousedrag:null,mousemove:null},a={mouseup:l=>(s(l),l.buttons||(this._document.removeEventListener("mouseup",n.mouseup),n.mousedrag&&this._document.removeEventListener("mousemove",n.mousedrag)),this.cancel(l)),wheel:l=>(s(l),this.cancel(l,!0)),mousedrag:l=>{l.buttons&&s(l)},mousemove:l=>{l.buttons||s(l)}};this._register(this.coreMouseService.onProtocolChange(l=>{l?(this.optionsService.rawOptions.logLevel==="debug"&&this._logService.debug("Binding to mouse events:",this.coreMouseService.explainEvents(l)),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()),l&8?n.mousemove||(t.addEventListener("mousemove",a.mousemove),n.mousemove=a.mousemove):(t.removeEventListener("mousemove",n.mousemove),n.mousemove=null),l&16?n.wheel||(t.addEventListener("wheel",a.wheel,{passive:!1}),n.wheel=a.wheel):(t.removeEventListener("wheel",n.wheel),n.wheel=null),l&2?n.mouseup||(n.mouseup=a.mouseup):(this._document.removeEventListener("mouseup",n.mouseup),n.mouseup=null),l&4?n.mousedrag||(n.mousedrag=a.mousedrag):(this._document.removeEventListener("mousemove",n.mousedrag),n.mousedrag=null)})),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this._register(ut(t,"mousedown",l=>{if(l.preventDefault(),this.focus(),!(!this.coreMouseService.areMouseEventsActive||this._selectionService.shouldForceSelection(l)))return s(l),n.mouseup&&this._document.addEventListener("mouseup",n.mouseup),n.mousedrag&&this._document.addEventListener("mousemove",n.mousedrag),this.cancel(l)})),this._register(ut(t,"wheel",l=>{if(!n.wheel){if(this._customWheelEventHandler&&this._customWheelEventHandler(l)===!1)return!1;if(!this.buffer.hasScrollback){if(l.deltaY===0)return!1;if(e.coreMouseService.consumeWheelEvent(l,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return this.cancel(l,!0);let c=Te.ESC+(this.coreService.decPrivateModes.applicationCursorKeys?"O":"[")+(l.deltaY<0?"A":"B");return this.coreService.triggerDataEvent(c,!0),this.cancel(l,!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){x5(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 new 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 new 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,s){this._selectionService.setSelection(e,t,s)}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 s=UW(e,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(e),s.type===3||s.type===2){let n=this.rows-1;return this.scrollLines(s.type===2?-n:n),this.cancel(e,!0)}if(s.type===1&&this.selectAll(),this._isThirdLevelShift(this.browser,e)||(s.cancel&&this.cancel(e,!0),!s.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((s.key===Te.ETX||s.key===Te.CR)&&(this.textarea.value=""),this._onKey.fire({key:s.key,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(s.key,!0),!this.optionsService.rawOptions.screenReaderMode||e.altKey||e.ctrlKey)return this.cancel(e,!0);this._keyDownHandled=!0}_isThirdLevelShift(e,t){let s=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"?s:s&&(!t.keyCode||t.keyCode>47)}_keyUp(e){this._keyDownSeen=!1,!(this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)&&(ZW(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(Ts));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(Te.ESC+"[I"):this.coreService.triggerDataEvent(Te.ESC+"[O")}_reportWindowsOptions(e){if(this._renderService)switch(e){case 0:let t=this._renderService.dimensions.css.canvas.width.toFixed(0),s=this._renderService.dimensions.css.canvas.height.toFixed(0);this.coreService.triggerDataEvent(`${Te.ESC}[4;${s};${t}t`);break;case 1:let n=this._renderService.dimensions.css.cell.width.toFixed(0),a=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${Te.ESC}[6;${a};${n}t`);break}}cancel(e,t){if(!(!this.options.cancelEvents&&!t))return e.preventDefault(),e.stopPropagation(),!1}};function ZW(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}var QW=class{constructor(){this._addons=[]}dispose(){for(let e=this._addons.length-1;e>=0;e--)this._addons[e].instance.dispose()}loadAddon(e,t){let s={instance:t,dispose:t.dispose,isDisposed:!1};this._addons.push(s),t.dispose=()=>this._wrappedAddonDispose(s),t.activate(e)}_wrappedAddonDispose(e){if(e.isDisposed)return;let t=-1;for(let s=0;s<this._addons.length;s++)if(this._addons[s]===e){t=s;break}if(t===-1)throw new Error("Could not dispose an addon that has not been loaded");e.isDisposed=!0,e.dispose.apply(e.instance),this._addons.splice(t,1)}},JW=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 yi)}translateToString(e,t,s){return this._line.translateToString(e,t,s)}},fC=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 JW(t)}getNullCell(){return new yi}},eK=class extends xt{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new Ie),this.onBufferChange=this._onBufferChange.event,this._normal=new fC(this._core.buffers.normal,"normal"),this._alternate=new fC(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 new 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)}},tK=class{constructor(e){this._core=e}registerCsiHandler(e,t){return this._core.registerCsiHandler(e,s=>t(s.toArray()))}addCsiHandler(e,t){return this.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._core.registerDcsHandler(e,(s,n)=>t(s,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)}},sK=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}},nK=["cols","rows"],Wi=0,iK=class extends xt{constructor(e){super(),this._core=this._register(new XW(e)),this._addonManager=this._register(new QW),this._publicOptions={...this._core.options};let t=n=>this._core.options[n],s=(n,a)=>{this._checkReadonlyOptions(n),this._core.options[n]=a};for(let n in this._core.options){let a={get:t.bind(this,n),set:s.bind(this,n)};Object.defineProperty(this._publicOptions,n,a)}}_checkReadonlyOptions(e){if(nK.includes(e))throw new Error(`Option "${e}" can only be set in the constructor`)}_checkProposedApi(){if(!this._core.optionsService.rawOptions.allowProposedApi)throw new 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||(this._parser=new tK(this._core)),this._parser}get unicode(){return this._checkProposedApi(),new sK(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._buffer=this._register(new eK(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,s){this._verifyIntegers(e,t,s),this._core.select(e,t,s)}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
|
|
117
117
|
`,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 Iv.get()},set promptLabel(e){Iv.set(e)},get tooMuchOutput(){return Hv.get()},set tooMuchOutput(e){Hv.set(e)}}}_verifyIntegers(...e){for(Wi of e)if(Wi===1/0||isNaN(Wi)||Wi%1!==0)throw new Error("This API only accepts integers")}_verifyPositiveIntegers(...e){for(Wi of e)if(Wi&&(Wi===1/0||isNaN(Wi)||Wi%1!==0||Wi<0))throw new Error("This API only accepts positive integers")}};const rK={fontSize:13,cursorStyle:"block",scrollback:5e3,copyOnSelect:!1},yb={state:"connecting",cwd:uo("terminal.localWorkspace"),detail:uo("terminal.openingShell")},jf=1;function aK(e){return{focus:e.focus,input:e.sendInput,refit:e.refit,restart:()=>e.sendControl("restart"),stop:()=>e.sendControl("stop")}}function oK(e,t,s){if(!e||e.readyState!==jf)return;const n=t?.proposeDimensions();e.send(JSON.stringify({cols:n?.cols,rows:n?.rows,type:s}))}function lK(e,t){if(!e)return;const s=t.schedule(()=>{t.refit(),t.focus()});return()=>t.cancel(s)}function cK(e){const t=e.location??window.location,s=e.createSocket??(g=>new WebSocket(g));e.reportStatus(e.initialStatus);const n=s(uK(e.sessionId,t));let a=!1,l;const c=[],d=e.scheduleInitialInput??(g=>{const p=window.setTimeout(g,200);return()=>window.clearTimeout(p)}),f=()=>{l?.(),l=d(()=>{l=void 0,(e.claimInitialInput?.()??[]).forEach((p,b)=>{const v=()=>n.send(JSON.stringify({data:p,type:"input"}));if(b===0)v();else{const _=e.scheduleInput??((S,C)=>{const N=window.setTimeout(S,C);return()=>window.clearTimeout(N)});c.push(_(v,b*(e.initialInputIntervalMs??75)))}})})},h=e.terminal.onData(g=>{a||n.readyState===jf&&n.send(JSON.stringify({data:g,type:"input"}))});return n.addEventListener("open",()=>{a||(e.reportStatus(g=>({...g,state:"running",detail:uo("terminal.shellConnected")})),e.sendResize())}),n.addEventListener("message",g=>{if(a)return;const p=dK(g.data);if(p){if(p.type==="output"){e.terminal.write(p.data),f();return}if(p.type==="error"){e.reportStatus(b=>({...b,state:"error",detail:p.error}));return}e.reportStatus(b=>({state:p.state==="idle"?"connecting":p.state,cwd:p.cwd??b.cwd,detail:p.error??p.shell??uo("terminal.shellConnected")}))}}),n.addEventListener("close",()=>{a||e.reportStatus(g=>({...g,state:g.state==="exited"?g.state:"exited",detail:uo("terminal.socketClosed")}))}),n.addEventListener("error",()=>{a||e.reportStatus(g=>({...g,state:"error",detail:uo("terminal.socketError")}))}),{socket:n,dispose:()=>{a||(a=!0,l?.(),c.forEach(g=>{g()}),h.dispose(),n.close())}}}const lA=x.forwardRef(function({sessionId:t,active:s,claimInitialInput:n,initialInputIntervalMs:a,onStatusChange:l,displaySettings:c=rK},d){const f=x.useRef(null),h=x.useRef(null),g=x.useRef(null),p=x.useRef(null),b=x.useRef(l),v=x.useRef(c),_=x.useRef(yb),S=$s();x.useEffect(()=>{b.current=l},[l]);const C=x.useCallback(E=>{const T=typeof E=="function"?E(_.current):E;_.current=T,b.current?.(T)},[]),N=x.useCallback(()=>{const E=g.current;if(!E)return;E.fit();const T=E.proposeDimensions();if(!T)return;if(S){QL(t,T.cols,T.rows);return}const L=p.current;L?.readyState===jf&&L.send(JSON.stringify({cols:T.cols,rows:T.rows,type:"resize"}))},[S,t]);x.useEffect(()=>{v.current=c;const E=h.current;E&&(E.options.fontSize=c.fontSize,E.options.cursorStyle=c.cursorStyle,E.options.scrollback=c.scrollback,N())},[c.copyOnSelect,c.cursorStyle,c.fontSize,c.scrollback,N]);const A=x.useCallback(E=>{S||oK(p.current,g.current,E)},[S]),j=x.useCallback(E=>{if(S){Dg(t,E);return}const T=p.current;T?.readyState===jf&&T.send(JSON.stringify({data:E,type:"input"}))},[S,t]);return x.useImperativeHandle(d,()=>aK({focus:()=>h.current?.focus(),refit:N,sendControl:A,sendInput:j}),[A,j,N]),x.useEffect(()=>{const E=f.current;if(!E)return;const T=new iK({allowProposedApi:!0,cursorBlink:!0,cursorStyle:v.current.cursorStyle,fontFamily:'"SF Mono", "JetBrains Mono", ui-monospace, Menlo, monospace',fontSize:v.current.fontSize,lineHeight:1.25,scrollback:v.current.scrollback,theme:{background:"#090909",black:"#090909",blue:"#69a7ff",brightBlack:"#5f6368",brightBlue:"#8ab4f8",brightCyan:"#7ddfd7",brightGreen:"#8fdc8a",brightMagenta:"#d7a2ff",brightRed:"#ff8a80",brightWhite:"#ffffff",brightYellow:"#ffd166",cyan:"#62d0c8",foreground:"#f2f2f2",green:"#7ac77f",magenta:"#c792ea",red:"#ff6b6b",selectionBackground:"#ffffff33",white:"#e8eaed",yellow:"#f7c948"}}),L=new Yq;T.loadAddon(L),T.open(E),h.current=T,g.current=L;const H=T.onSelectionChange(()=>{if(!v.current.copyOnSelect)return;const z=T.getSelection();if(z)try{navigator.clipboard?.writeText(z).catch(()=>{})}catch{}});let P;if(S){C(yb);let z=null,G=!1,D;const q=T.onData(W=>{Dg(t,W)});eO(t,W=>{T.write(W),D!==void 0&&window.clearTimeout(D),D=window.setTimeout(()=>{D=void 0,(async()=>{const I=n?.()??[];for(let Y=0;Y<I.length;Y+=1)Y>0&&await new Promise($=>window.setTimeout($,a??75)),await Dg(t,I[Y])})()},200)}).then(W=>{if(G){W();return}z=W,C(I=>({...I,state:"running",detail:uo("terminal.shellConnected")})),ZL(t),N()},W=>{G||C(I=>({...I,state:"error",detail:W instanceof Error?W.message:String(W)}))}),P=()=>{G=!0,D!==void 0&&window.clearTimeout(D),q.dispose(),z?.()}}else{const z=cK({claimInitialInput:n,initialInputIntervalMs:a,initialStatus:yb,reportStatus:C,sendResize:N,sessionId:t,terminal:T});p.current=z.socket,P=()=>{z.dispose(),p.current=null}}window.addEventListener("resize",N);const F=window.setTimeout(N,0),M=new ResizeObserver(()=>N());return M.observe(E),()=>{window.removeEventListener("resize",N),window.clearTimeout(F),M.disconnect(),P(),H.dispose(),T.dispose(),h.current=null,g.current=null}},[C,t,N,S]),x.useEffect(()=>lK(s,{cancel:E=>window.clearTimeout(E),focus:()=>h.current?.focus(),refit:N,schedule:E=>window.setTimeout(E,0)}),[s,N]),i.jsx("section",{"aria-label":"terminal viewport",className:oe("h-full min-h-0 overflow-hidden bg-[#090909] px-3 py-0.5",!s&&"hidden"),children:i.jsx("div",{className:"h-full w-full",ref:f})})});function uK(e,t){const s=t.protocol==="https:"?"wss:":"ws:",n=encodeURIComponent(e);return`${s}//${t.host}/api/terminal/socket?id=${n}`}function dK(e){if(typeof e!="string")return null;try{const t=JSON.parse(e);return typeof t?.type=="string"?t:null}catch{return null}}const hK={skills:"agent-env",mcps:"agent-env",plugins:"agent-env",hooks:"agent"};function cA(e,t){return t?t.needsAuth||t.failed?[t.needsAuth?e("dock.mcpNeedsAuth",{count:t.needsAuth}):"",t.failed?e("dock.mcpFailed",{count:t.failed}):""].filter(Boolean).join(" · "):t.checked?e("dock.mcpConnected"):void 0:e("dock.mcpAuthChecking")}function uA({auth:e,mcps:t}){return t===0?null:e?e.failed?i.jsx("span",{className:"size-1.5 rounded-full bg-red-500"}):e.needsAuth?i.jsx("span",{className:"size-1.5 rounded-full bg-amber-500"}):e.checked?i.jsx("span",{className:"size-1.5 rounded-full bg-emerald-500"}):null:i.jsx("span",{className:"size-1.5 animate-pulse rounded-full bg-muted-foreground/50"})}function fK(e){if(!e)return null;const t=e==="failed"?"bg-red-500":e==="needs-auth"?"bg-amber-500":e==="unknown"?"bg-muted-foreground/50":"bg-emerald-500";return i.jsx("span",{className:oe("size-1.5 shrink-0 rounded-full",t)})}function mK(e){const t=e.getBoundingClientRect();return{left:Math.max(8,Math.min(t.left,window.innerWidth-296)),top:t.top,bottom:t.bottom,up:window.innerHeight-t.bottom<300}}function pK({anchor:e,items:t,mcpAuth:s,onClose:n,onInsert:a,onManage:l}){const c=ee(),d=x.useRef(null);return x.useEffect(()=>{function f(p){const b=p.target;d.current?.contains(b)||b.closest?.("[data-capability-trigger]")||n()}function h(p){p.key==="Escape"&&n()}function g(p){d.current?.contains(p.target)||n()}return document.addEventListener("mousedown",f),document.addEventListener("keydown",h),window.addEventListener("scroll",g,!0),()=>{document.removeEventListener("mousedown",f),document.removeEventListener("keydown",h),window.removeEventListener("scroll",g,!0)}},[n]),Ii.createPortal(i.jsxs("div",{className:"fixed z-50 w-72 overflow-hidden rounded-md border border-border bg-card shadow-md","data-capability-menu":!0,ref:d,style:e.up?{left:e.left,bottom:window.innerHeight-e.top+4}:{left:e.left,top:e.bottom+4},children:[i.jsx("div",{className:"max-h-64 overflow-y-auto p-1",children:t.length===0?i.jsx("div",{className:"px-2 py-1.5 text-[11px] text-muted-foreground",children:c("dock.capabilityEmpty")}):t.map((f,h)=>{const g=f.insert,p=i.jsxs(i.Fragment,{children:[s?fK(s[f.name]):null,i.jsx("span",{className:oe("truncate font-mono text-xs",f.sub&&"pl-4"),children:f.name}),f.detail?i.jsx("span",{className:"ml-auto max-w-[45%] shrink-0 truncate pl-2 text-[10px] text-muted-foreground",children:f.detail}):null]}),b=`${f.name}-${h}`;return g&&a?i.jsx("button",{className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left transition-colors hover:bg-muted",onClick:()=>{a(g),n()},type:"button",children:p},b):i.jsx("div",{className:"flex w-full items-center gap-2 px-2 py-1.5",children:p},b)})}),l?i.jsx("button",{className:"flex w-full items-center border-t border-border px-2 py-1.5 text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:()=>{l(),n()},type:"button",children:c("dock.capabilityManage")}):null]}),document.body)}function dA(e,t,s){const[n,a]=x.useState(null),l=d=>f=>{const h=mK(f.currentTarget);a(g=>g?.key===d?null:{key:d,anchor:h})},c=n&&e.items?i.jsx(pK,{anchor:n.anchor,items:e.items[n.key],mcpAuth:n.key==="mcps"?e.mcpAuth:void 0,onClose:()=>a(null),onInsert:t,onManage:s?()=>s(hK[n.key]):void 0}):null;return{openKey:n?.key??null,toggle:l,dropdown:c}}function gK({capabilities:e,providerLabel:t,onInsert:s,onNavigate:n}){const a=ee(),{counts:l,auth:c}=e,{openKey:d,toggle:f,dropdown:h}=dA(e,s,n);return l?i.jsxs("nav",{"aria-label":a("dock.capabilitiesAria",{name:t??"Agent"}),className:"mt-2 flex flex-wrap items-center gap-1.5",children:[i.jsx(Eh,{count:l.skills,expanded:d==="skills",icon:i.jsx(zn,{}),label:a("agentEnv.skills"),onClick:f("skills")}),i.jsx(Eh,{count:l.mcps,expanded:d==="mcps",icon:i.jsx(Wf,{}),label:a("agentEnv.mcpServers"),onClick:f("mcps"),title:cA(a,c),trailing:i.jsx(uA,{auth:c,mcps:l.mcps})}),i.jsx(Eh,{count:l.plugins,expanded:d==="plugins",icon:i.jsx(Au,{}),label:a("agentEnv.plugins"),onClick:f("plugins")}),i.jsx(Eh,{count:l.hooks,expanded:d==="hooks",icon:i.jsx(Yx,{}),label:a("dock.hooks"),onClick:f("hooks")}),h]}):null}function bK({capabilities:e,providerLabel:t,onInsert:s,onNavigate:n}){const a=ee(),{counts:l,auth:c}=e,{openKey:d,toggle:f,dropdown:h}=dA(e,s,n);if(!l)return null;const g=(b,v,_,S,C)=>i.jsxs("button",{"aria-expanded":d===b,className:"flex h-7 items-center gap-1 rounded-sm px-1.5 font-mono text-[10px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground [&_svg]:size-3","data-capability-trigger":!0,onClick:f(b),title:S,type:"button",children:[v,i.jsx("span",{children:_}),C]}),p=[`${a("agentEnv.mcpServers")}: ${l.mcps}`,cA(a,c)].filter(Boolean).join(" · ");return i.jsxs("nav",{"aria-label":a("dock.capabilitiesAria",{name:t??"Agent"}),className:"hidden shrink-0 items-center gap-0.5 border-l border-border px-1 sm:flex",children:[g("skills",i.jsx(zn,{}),l.skills,`${a("agentEnv.skills")}: ${l.skills}`),g("mcps",i.jsx(Wf,{}),l.mcps,p,i.jsx(uA,{auth:c,mcps:l.mcps})),g("plugins",i.jsx(Au,{}),l.plugins,`${a("agentEnv.plugins")}: ${l.plugins}`),g("hooks",i.jsx(Yx,{}),l.hooks,`${a("dock.hooks")}: ${l.hooks}`),h]})}function Eh({count:e,expanded:t,icon:s,label:n,onClick:a,title:l,trailing:c}){return i.jsxs("button",{"aria-expanded":t,className:oe("flex items-center gap-1.5 rounded-sm border border-border bg-muted/30 px-2 py-1 text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground [&_svg]:size-3",t&&"bg-muted text-foreground"),"data-capability-trigger":!0,onClick:a,title:l,type:"button",children:[s,i.jsx("span",{children:n}),i.jsx("span",{className:"font-mono text-foreground",children:e}),c]})}function vK(e){return Object.keys(e.mcpServers).length+Object.keys(e.remoteMcpServers).length+Object.keys(e.projectMcpServers).length+Object.keys(e.projectRemoteMcpServers).length}function xK(e,t){const s=e?.skills??[];return{skills:s.filter(n=>n.kind!=="plugin").length,plugins:s.filter(n=>n.kind==="plugin").length,mcps:e?vK(e):0,hooks:t}}function yK(e){let t=0,s=0;for(const n of e)n.state==="needs-auth"?t+=1:n.state==="failed"&&(s+=1);return{checked:e.length,needsAuth:t,failed:s}}function _K(e,t){return t==="claude"?`/${e} `:`@${e} `}function wK(e){return`Use the "${e}" MCP server: `}function SK(e,t,s){const n=[],a=[];for(const f of e?.skills??[])if(f.kind==="plugin"){if(a.push({name:f.name,detail:f.scope,insert:`Use the "${f.name}" plugin: `}),s==="claude")for(const h of[...f.pluginSkills??[],...f.pluginCommands??[]])a.push({name:`${f.name}:${h}`,insert:`/${f.name}:${h} `,sub:!0})}else n.push({name:f.name,detail:f.scope,insert:_K(f.name,s)});const l=[],c=[[e?.mcpServers??{},"user"],[e?.remoteMcpServers??{},"user · remote"],[e?.projectMcpServers??{},"project"],[e?.projectRemoteMcpServers??{},"project · remote"]];for(const[f,h]of c)for(const g of Object.keys(f))l.push({name:g,detail:h,insert:wK(g)});const d=t.map(f=>({name:f.matcher?`${f.event} · ${f.matcher}`:f.event,detail:f.command}));return{skills:n,plugins:a,mcps:l,hooks:d}}function kK(e,t=!0){const s=e==="codex"?"codex":"claude",n=e==="codex"?"codex":"claude-code",[a,l]=x.useState(null),[c,d]=x.useState(null),[f,h]=x.useState(null),[g,p]=x.useState({});return x.useEffect(()=>{if(!t)return;let b=!1;return l(null),d(null),h(null),p({}),Promise.all([jE().catch(()=>[]),Zx().catch(()=>null)]).then(([v,_])=>{if(b)return;const S=v.find(N=>N.agent===s),C=_?.agents[n]?.hooks??[];l(xK(S,C.length)),d(SK(S,C,e))}),EE(n).then(v=>{b||(h(yK(v)),p(Object.fromEntries(v.map(_=>[_.name,_.state]))))}).catch(()=>{b||h({checked:0,needsAuth:0,failed:0})}),()=>{b=!0}},[t,s,n,e]),{counts:a,items:c,auth:f,mcpAuth:g}}const CK=new Set(["c","cpp","cs","go","java","js","jsx","kt","mjs","py","rs","swift","ts","tsx"]),NK=new Set([".env",".gitignore","components.json","dockerfile","package.json","tsconfig.json","vite.config.ts"]),EK=new Set(["conf","config","ini","toml","yaml","yml"]),jK=new Set(["csv","json","sql","xml"]),AK=new Set(["md","mdx","rst","txt"]),TK=new Set(["gif","jpeg","jpg","png","svg","webp"]),RK=new Set(["package-lock.json","pnpm-lock.yaml","yarn.lock"]),MK=new Set(["css","less","sass","scss"]);function DK(e){const t=e.split("/").pop()?.toLowerCase()??e.toLowerCase(),s=t.includes(".")?t.split(".").pop()??"":"";return RK.has(t)||t.endsWith(".lock")?"lock":LK(t)?"test":NK.has(t)||EK.has(s)?"config":MK.has(s)?"style":TK.has(s)?"image":AK.has(s)?"document":jK.has(s)?"data":CK.has(s)?"code":"generic"}function LK(e){return e.includes(".test.")||e.includes(".spec.")||e.endsWith("_test.go")}function V0({path:e,className:t}){const s=DK(e),n=OK[s];return i.jsx(n,{"aria-label":`${s} file`,className:oe("size-3.5 shrink-0",PK[s],t)})}const OK={code:iE,config:Kx,data:ti,document:$x,generic:oE,image:A6,lock:W6,style:fE,test:n6},PK={code:"text-sky-600",config:"text-zinc-600",data:"text-emerald-700",document:"text-blue-700",generic:"text-muted-foreground",image:"text-fuchsia-700",lock:"text-amber-700",style:"text-rose-700",test:"text-violet-700"};function zK(e){const t=e.lastIndexOf(".");return t>0?e.slice(t):""}function BK({onPick:e,onClose:t}){const[s,n]=x.useState(""),[a,l]=x.useState(null),[c,d]=x.useState(null),[f,h]=x.useState(!1),g=x.useRef(null),p=ee(),b=a?a.parent!==a.path:!1;return x.useEffect(()=>{function v(_){g.current&&!g.current.contains(_.target)&&t()}return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[t]),x.useEffect(()=>{let v=!0;return h(!0),d(null),$E(s,{files:!0}).then(_=>v&&l(_)).catch(_=>v&&d(_ instanceof Error?_.message:String(_))).finally(()=>v&&h(!1)),()=>{v=!1}},[s]),i.jsxs("div",{ref:g,className:"absolute bottom-full left-2 z-10 mb-2 w-[22rem] max-w-[calc(100vw-1rem)] overflow-hidden rounded-md border border-border bg-card shadow-lg",children:[i.jsxs("div",{className:"flex items-center gap-1 border-b border-border px-2 py-1.5",children:[i.jsx(Q,{"aria-label":p("agent.picker.parentFolder"),className:"size-7",disabled:!b,onClick:()=>a&&n(a.parent),size:"icon",type:"button",variant:"ghost",children:i.jsx(Ff,{})}),i.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",title:a?.path,children:a?.path??"…"}),f?i.jsx(Lt,{className:"size-3.5 animate-spin text-muted-foreground"}):null,a?i.jsxs(Q,{className:"h-7 px-2 text-[11px]",onClick:()=>e(a.path),size:"sm",title:p("agent.picker.attachFolder"),type:"button",variant:"outline",children:[i.jsx(zM,{})," ",p("agent.picker.thisFolder")]}):null,i.jsx(Q,{"aria-label":p("common.close"),className:"size-7",onClick:t,size:"icon",type:"button",variant:"ghost",children:i.jsx(Vt,{})})]}),i.jsx("div",{className:"max-h-64 overflow-auto p-1",children:c?i.jsx(tt,{variant:"destructive",className:"m-1",children:c}):a&&a.entries.length===0?i.jsx(tt,{variant:"muted",className:"m-1 text-center",children:p("agent.picker.emptyFolder")}):a?.entries.map(v=>{const _=v.isDir?"":zK(v.name);return i.jsxs("button",{className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1 text-left text-[12px] hover:bg-muted",onClick:()=>v.isDir?n(v.path):e(v.path),title:v.path,type:"button",children:[v.isDir?i.jsx(ko,{className:"size-3.5 shrink-0 text-amber-600"}):i.jsx(V0,{path:v.path}),i.jsx("span",{className:"min-w-0 flex-1 truncate",children:v.name}),_?i.jsx("span",{className:"shrink-0 rounded bg-muted px-1 font-mono text-[10px] text-muted-foreground",children:_}):null]},v.path)})})]})}const mC="flex h-7 items-center gap-1.5 rounded-sm px-2 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:pointer-events-none disabled:opacity-40";function IK(e,t){const s=t?.trim()||e.split(/\r?\n/).find(n=>n.trim())?.trim()||"Agent task";return s.length>60?`${s.slice(0,57).trimEnd()}…`:s}function HK({capabilities:e,onNavigate:t,onShellMode:s,shellMode:n=!1}){const a=ee(),{activeSource:l,clearSource:c,configured:d,createShellTask:f,createTask:h,creating:g,draft:p,focusNonce:b,insertPath:v,insertPrompt:_,onboarding:S,provider:C,providers:N,selectProvider:A,setDraft:j,setOnboarding:E}=Ot(),[T,L]=x.useState(!1),[H,P]=x.useState(""),F=x.useRef(null);x.useEffect(()=>{const D=requestAnimationFrame(()=>{const q=F.current;if(!q)return;q.focus();const W=q.value.length;q.setSelectionRange(W,W)});return()=>cancelAnimationFrame(D)},[b]),x.useLayoutEffect(()=>{F.current&&(F.current.style.height="auto",F.current.style.height=`${F.current.scrollHeight}px`)},[p]);const M=!!g||(n?!1:!p.trim()||d!==!0);async function z(D=p,q){if(g)return;if(n){if(!await f(D))return;j(""),c(),P("");return}!D.trim()||d!==!0||!await h({prompt:D,label:IK(D,q??l?.label),source:l??void 0})||(j(""),c(),E(!1),P(""))}function G(D){D.key==="Enter"&&!D.shiftKey&&(D.preventDefault(),z())}return i.jsx("div",{className:"flex h-full items-center justify-center overflow-auto p-6",children:i.jsxs("div",{className:"w-full max-w-3xl",children:[!n&&d===null?i.jsx("div",{className:"mb-3 border-l-2 border-border pl-3 text-xs text-muted-foreground",children:a("dock.checkingAvailability",{name:C?.label??"agent"})}):null,!n&&d===!1?i.jsxs("div",{className:"mb-3 border-l-2 border-amber-500/70 pl-3 text-xs text-muted-foreground",children:[i.jsx("span",{className:"font-medium text-foreground",children:a("dock.notInstalled",{name:C?.label??"Agent"})})," ",C?.installHint]}):null,l?i.jsxs("div",{className:"mb-2 flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[i.jsx("span",{className:"font-mono uppercase tracking-wide",children:a("dock.sourceLabel")}),i.jsx("span",{className:"rounded-sm bg-muted px-1.5 py-0.5 text-foreground",children:l.label}),i.jsx("button",{"aria-label":a("dock.clearSourceAria"),onClick:c,type:"button",children:i.jsx(Vt,{className:"size-3"})})]}):null,i.jsxs("div",{className:"border border-border bg-card shadow-sm",children:[S&&!n?i.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2",children:[i.jsx(I6,{className:"size-4 text-muted-foreground"}),i.jsx("input",{"aria-label":a("dock.repoUrlAria"),className:"min-w-0 flex-1 bg-transparent text-sm outline-none",disabled:d!==!0,onChange:D=>P(D.target.value),placeholder:"https://github.com/owner/repository",value:H}),i.jsx(Q,{disabled:d!==!0||!H.trim()||!!g,onClick:()=>{z(SF(H),`Onboard ${H}`)},size:"sm",children:a("dock.onboard")})]}):null,i.jsx("textarea",{"aria-label":a(n?"dock.shellCommandAria":"dock.promptAria"),className:oe("block max-h-40 min-h-20 w-full resize-none bg-transparent px-3 py-3 text-sm leading-relaxed outline-none placeholder:text-muted-foreground",n&&"font-mono"),disabled:!n&&d!==!0,onChange:D=>j(D.target.value),onKeyDown:G,placeholder:a(n?"dock.shellPlaceholder":"dock.promptPlaceholder"),ref:F,rows:2,value:p}),i.jsxs("div",{className:"flex h-10 items-center gap-1 border-t border-border px-2",children:[i.jsxs("fieldset",{"aria-label":a("dock.providerAria"),className:"flex shrink-0 items-center gap-0.5",children:[N.map(D=>{const q=D.id==="codex"?Da:Br,W=!n&&(C?.id??"claude")===D.id;return i.jsxs("button",{"aria-label":D.label,"aria-pressed":W,className:oe(mC,W&&"bg-muted text-foreground"),disabled:!D.configured,onClick:()=>{s?.(!1),A(D.id)},title:D.configured?D.label:`${D.label}${a("dock.notInstalledSuffix")} — ${D.installHint}`,type:"button",children:[i.jsx(q,{className:"size-3.5"}),W?i.jsx("span",{children:D.label}):null]},D.id)}),i.jsxs("button",{"aria-label":a("dock.shell"),"aria-pressed":n,className:oe(mC,n&&"bg-muted text-foreground"),onClick:()=>s?.(!0),title:a("dock.shellTitle"),type:"button",children:[i.jsx(zr,{className:"size-3.5"}),n?i.jsx("span",{children:a("dock.shell")}):null]})]}),i.jsx("button",{"aria-label":a("dock.attachAria"),className:"grid size-7 place-items-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground",onClick:()=>L(D=>!D),type:"button",children:i.jsx(kD,{className:"size-3.5"})}),n?null:i.jsx("button",{className:"px-2 text-[11px] text-muted-foreground hover:text-foreground",onClick:()=>E(!S),type:"button",children:a("dock.repoUrlToggle")}),i.jsx("span",{className:"flex-1"}),i.jsx("span",{className:"hidden text-[10px] text-muted-foreground sm:inline",children:a(n?"dock.shellEnterHint":"dock.shiftEnterHint")}),i.jsx(Q,{"aria-label":a(n?"dock.openShellAria":"dock.runAria"),className:"size-7",disabled:M,onClick:()=>{z()},size:"icon",children:i.jsx(If,{})})]})]}),e?i.jsx(gK,{capabilities:e,onInsert:_,onNavigate:t,providerLabel:C?.label}):null,T?i.jsx("div",{className:"relative mt-2",children:i.jsx(BK,{onClose:()=>L(!1),onPick:D=>{v(D),L(!1)}})}):null]})})}const Zi="new";function $K(e){return e==="running"?"fill-emerald-500 text-emerald-500":e==="error"?"fill-destructive text-destructive":"fill-muted-foreground/50 text-muted-foreground/50"}function FK({tasks:e,activeTaskId:t,composing:s,onActivate:n,onClose:a,onSplit:l,pendingTaskIds:c,splitTaskId:d}){const f=ee();return i.jsxs("div",{"aria-label":f("dock.tasksAria"),className:"flex min-w-0 flex-1 items-stretch gap-px overflow-x-auto",role:"tablist",children:[e.map(h=>{const g=h.kind==="shell",p=h.label||(g?f("dock.shellFallback"):f("dock.taskFallback",{provider:h.provider==="codex"?"Codex":"Claude"})),b=h.id===t,v=h.id===d,_=g?zr:h.provider==="codex"?Da:Br;return i.jsxs("div",{className:oe("group/tab flex h-9 shrink-0 items-center border-x border-transparent",(b||v)&&"border-border bg-background"),"data-split":v||void 0,children:[i.jsxs("button",{"aria-controls":`agent-panel-${h.id}`,"aria-label":f("dock.openTaskAria",{label:p}),"aria-selected":b,className:"flex h-full max-w-56 items-center gap-2 px-3 text-xs",id:`agent-tab-${h.id}`,onClick:()=>n(h.id),role:"tab",type:"button",children:[i.jsx(_,{className:oe("size-3 shrink-0",b||v?"text-foreground":"text-muted-foreground")}),i.jsx(kl,{"aria-hidden":!0,className:oe("size-2",$K(h.state))}),i.jsx("span",{className:oe("truncate font-mono text-[11px]",b||v?"text-foreground":"text-muted-foreground"),children:p})]}),l&&!b?i.jsx("button",{"aria-label":f(v?"dock.unsplitTaskAria":"dock.splitTaskAria",{label:p}),"aria-pressed":v,className:oe("grid size-6 place-items-center rounded-sm text-muted-foreground opacity-50 hover:bg-muted hover:text-foreground group-hover/tab:opacity-100",v&&"text-foreground opacity-100"),onClick:()=>l(h.id),type:"button",children:i.jsx(LM,{className:"size-3"})}):null,i.jsx("button",{"aria-label":f("dock.closeTaskAria",{label:p}),className:"mr-1 grid size-6 place-items-center rounded-sm text-muted-foreground opacity-50 hover:bg-muted hover:text-foreground group-hover/tab:opacity-100 disabled:pointer-events-none disabled:opacity-25",disabled:c?.has(h.id),onClick:()=>a(h.id),type:"button",children:i.jsx(Vt,{className:"size-3"})})]},h.id)}),s?i.jsx("div",{className:"flex h-9 shrink-0 items-center border-x border-border bg-background",children:i.jsxs("button",{"aria-controls":`agent-panel-${Zi}`,"aria-selected":!0,className:"flex h-full items-center gap-2 px-3 text-xs",id:`agent-tab-${Zi}`,onClick:()=>n(Zi),role:"tab",type:"button",children:[i.jsx(fs,{"aria-hidden":!0,className:"size-3 shrink-0 text-foreground"}),i.jsx("span",{className:"truncate font-mono text-[11px] text-foreground",children:f("dock.newTaskTab")})]})}):null]})}function pm({className:e}){return i.jsx("svg",{className:oe("size-3.5",e),viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:i.jsx("path",{d:"M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"})})}const hA="nomoreide-theme-choice",UK="nomoreide:ui-preferences";function qK(){if(typeof window>"u")return"system";try{const e=window.localStorage.getItem(UK),t=e?JSON.parse(e):null;if(t?.version===1&&(t.theme==="light"||t.theme==="dark"||t.theme==="system"))return t.theme}catch{}try{const e=window.localStorage.getItem(hA);if(e==="light"||e==="dark"||e==="system")return e}catch{}return"system"}function W0(e){return e!=="system"?e:typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function wx(e){if(typeof document>"u")return;const t=document.documentElement;t.classList.toggle("dark",e==="dark"),t.style.colorScheme=e}let wo=qK(),fo=W0(wo);const Jh=new Set;let vo=null;function fA(){for(const e of Jh)e()}function Af(){if(vo?.(),vo=null,fo=W0(wo),wx(fo),wo!=="system"||typeof window>"u"||typeof window.matchMedia!="function")return;const e=window.matchMedia("(prefers-color-scheme: dark)"),t=s=>{fo=s.matches?"dark":"light",wx(fo),fA()};e.addEventListener("change",t),vo=()=>e.removeEventListener("change",t)}Af();function GK(){return wo}function VK(){return fo}function Sx(e){if(!(e!==wo)){e==="system"&&!vo?Af():(fo=W0(e),wx(fo));return}wo=e,Af();try{window.localStorage.setItem(hA,e)}catch{}fA()}function mA(e){return Jh.add(e),wo==="system"&&!vo&&Af(),()=>{Jh.delete(e),Jh.size===0&&(vo?.(),vo=null)}}function pA(){return[x.useSyncExternalStore(mA,GK,()=>"system"),Sx]}function WK(){return x.useSyncExternalStore(mA,VK,()=>"dark")}const gA="nomoreide:ui-preferences";function KK(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}function bA(){return{version:1,theme:"system",language:"en",density:"comfortable",codeFontSize:12,reducedMotion:KK(),sidebarDocked:!1,projectScope:"all"}}function YK(){if(typeof window>"u")return{};const e=pl("nomoreide-theme-choice"),t=pl("nomoreide-language")??pl("nomoreide-language-choice"),s=pl("nomoreide:sidebar-docked"),n=pl("nomoreide:project-scope");return{...e==="light"||e==="dark"||e==="system"?{theme:e}:{},...t==="en"||t==="zh"?{language:t}:{},...s==="true"||s==="false"?{sidebarDocked:s==="true"}:{},...n==="all"||n==="project"?{projectScope:n}:{}}}function pl(e){try{return window.localStorage.getItem(e)}catch{return null}}function gm(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e;return t.version!==1||!["light","dark","system"].includes(String(t.theme))||!["en","zh"].includes(String(t.language))||!["comfortable","compact"].includes(String(t.density))||typeof t.codeFontSize!="number"||!Number.isInteger(t.codeFontSize)||t.codeFontSize<10||t.codeFontSize>18||typeof t.reducedMotion!="boolean"||typeof t.sidebarDocked!="boolean"||!["all","project"].includes(String(t.projectScope))?null:t}function XK(e,t){return gm({...e,...t})}function mu(e){const t=gm(e);if(!t)return!1;try{return window.localStorage.setItem(gA,JSON.stringify(t)),!0}catch{return!1}}function ZK(){let e=null;try{const s=pl(gA);e=s?gm(JSON.parse(s)):null}catch{e=null}const t=e??{...bA(),...YK()};return mu(t),t}function QK(){const e=bA();return mu(e),e}function pC(e){if(typeof document>"u")return;const t=document.documentElement;t.dataset.density=e.density,t.dataset.reducedMotion=String(e.reducedMotion),t.style.setProperty("--code-font-size",`${e.codeFontSize}px`)}const gC={version:1,terminal:{fontSize:13,cursorStyle:"block",scrollback:5e3,copyOnSelect:!1,confirmTerminate:!0}},jh={logs:{showTimestamps:!0,wrapLines:!0},database:{confirmWrites:!0,resultLimit:100}},vA=x.createContext(null);function ya(e){return e instanceof Error?e.message:String(e)}function JK(e,t){return{...e,terminal:{...e.terminal,...t.terminal}}}function eY(e,t){return{...e,logs:{...e.logs,...t.logs},database:{...e.database,...t.database}}}function tY({children:e}){const[t,s]=x.useState(gC),[n,a]=x.useState(gC),[l,c]=x.useState(jh),[d,f]=x.useState(jh),[h,g]=x.useState(()=>ZK()),[p,b]=x.useState(!0),[v,_]=x.useState(null),[S,C]=x.useState(!1),[N,A]=x.useState(null),[j,E]=x.useState(null),[T,L]=x.useState("idle"),[H,P]=x.useState(null),[F]=pA(),[M]=Z3(),z=x.useRef(!0),G=x.useRef(!1),D=x.useRef(0),q=x.useRef(0),W=x.useRef(0),I=x.useRef(0),Y=x.useRef(Promise.resolve()),$=x.useRef(Promise.resolve()),me=x.useRef(t),J=x.useRef(l),V=x.useRef(null),K=x.useRef(null),xe=x.useRef(h),ie=x.useRef(n),Z=x.useRef(d),ge=x.useRef(null),ne=x.useRef(0),we=x.useRef(null),Ne=x.useRef(null),Ue=x.useRef(!1),Pe=x.useRef(null),Re=x.useRef(h.language),pe=x.useCallback(()=>{ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null)},[]),Qe=x.useCallback(()=>{pe(),L("saved"),ge.current=window.setTimeout(()=>{z.current&&L("idle")},1500)},[pe]),jt=x.useCallback(()=>{pe(),ne.current===0&&(we.current=null,P(null)),ne.current+=1,L("saving")},[pe]),dt=x.useCallback(st=>{if(st&&!we.current&&(we.current=st),ne.current=Math.max(0,ne.current-1),ne.current>0){L("saving"),we.current&&P(we.current);return}if(we.current){P(we.current),L("error");return}Qe()},[Qe]),Fs=x.useCallback(st=>{if(V.current===st)return K.current??Promise.resolve();const nt=++q.current;if(++I.current,V.current=st,_(st),E(null),J.current=structuredClone(jh),Z.current=structuredClone(jh),c(J.current),f(Z.current),st===null)return C(!1),K.current=null,Promise.resolve();C(!0);const k=$.current.then(()=>Ig(st)).then(se=>{!z.current||nt!==q.current||V.current!==st||(J.current=se.project,Z.current=se.project,c(se.project),f(se.project))}).catch(se=>{z.current&&nt===q.current&&V.current===st&&E(`Could not load project settings: ${ya(se)}`)}).finally(()=>{z.current&&nt===q.current&&V.current===st&&(C(!1),K.current=null)});return K.current=k,k},[]),Cn=x.useCallback(async()=>{const st=V.current;if(!st)return;const nt=++q.current;++I.current;const At=$.current;C(!0),E(null);const k=At.then(()=>Ig(st)).then(se=>{!z.current||nt!==q.current||V.current!==st||(J.current=se.project,Z.current=se.project,c(se.project),f(se.project))}).catch(se=>{z.current&&nt===q.current&&V.current===st&&E(`Could not load project settings: ${ya(se)}`)}).finally(()=>{z.current&&nt===q.current&&V.current===st&&(C(!1),K.current=null)});return K.current=k,k},[]),gs=x.useCallback(async()=>{const st=++D.current,nt=V.current,At=nt?++q.current:q.current,k=W.current,se=I.current,ve=Y.current,ke=$.current;b(!0),nt&&C(!0),A(null),nt&&E(null);try{await Promise.all([ve,ke]);const le=await Ig(nt??void 0);if(!z.current||st!==D.current)return;k===W.current&&(me.current=le.global,ie.current=le.global,s(le.global),a(le.global)),se===I.current&&nt===V.current&&At===q.current&&(J.current=le.project,Z.current=le.project,c(le.project),f(le.project))}catch(le){const Le=nt===null||nt===V.current&&At===q.current;z.current&&st===D.current&&Le&&(nt?E(`Could not load project settings: ${ya(le)}`):A(ya(le)))}finally{z.current&&st===D.current&&(b(!1),nt===V.current&&C(!1))}},[]);x.useEffect(()=>(z.current=!0,G.current||(G.current=!0,gs()),Ne.current=window.setTimeout(()=>{Ue.current=!0},0),()=>{z.current=!1,pe(),Ne.current!==null&&(window.clearTimeout(Ne.current),Ne.current=null)}),[pe,gs]);const Us=x.useCallback(st=>{const nt=gm(st);return nt?(mu(nt),xe.current=nt,pC(nt),g(nt),Pe.current=nt.theme,Sx(nt.theme),Re.current=nt.language,zv(nt.language),!0):!1},[]);x.useEffect(()=>{pC(h),Pe.current=h.theme,Sx(h.theme),Re.current=h.language,zv(h.language)},[]),x.useEffect(()=>{if(Ue.current&&Pe.current!==null&&F!==Pe.current){const st={...h,theme:F};xe.current=st,mu(st),g(st),Pe.current=F}},[F,h]),x.useEffect(()=>{if(Ue.current&&M!==Re.current){const st={...h,language:M};xe.current=st,mu(st),g(st),Re.current=M}},[M,h]);const fn=x.useCallback(st=>{const nt=XK(xe.current,st);return nt?Us(nt):!1},[Us]),ni=x.useCallback(()=>{Us(QK())},[Us]),Bn=x.useCallback(async st=>{const nt=++W.current,At=JK(me.current,st);me.current=At,s(At),jt();const k=Y.current.then(()=>o9(st));Y.current=k.then(()=>{},()=>{});try{const se=await k;if(!z.current)return;ie.current=se,a(se),nt===W.current&&(me.current=se,s(se)),dt()}catch(se){if(!z.current)return;nt===W.current&&(me.current=ie.current,s(ie.current)),dt(`Could not save global settings: ${ya(se)}`)}},[jt,dt]),Pt=x.useCallback(async st=>{const nt=V.current;if(!nt){P("Select a project before changing project settings."),L("error");return}const At=++I.current,k=eY(J.current,st);J.current=k,c(k),jt();const se=$.current.then(()=>l9(nt,st));$.current=se.then(()=>{},()=>{});try{const ve=await se;if(!z.current)return;nt===V.current&&(Z.current=ve,f(ve),At===I.current&&(J.current=ve,c(ve))),dt()}catch(ve){if(!z.current)return;nt===V.current&&At===I.current&&(J.current=Z.current,c(Z.current)),dt(`Could not save project settings: ${ya(ve)}`)}},[jt,dt]),bs=x.useCallback(async()=>{const st=++W.current;jt();const nt=Y.current.then(c9);Y.current=nt.then(()=>{},()=>{});try{const At=await nt;if(!z.current)return;ie.current=At,a(At),st===W.current&&(me.current=At,s(At)),dt()}catch(At){if(!z.current)return;dt(`Could not reset global settings: ${ya(At)}`)}},[jt,dt]),rs=x.useCallback(async()=>{const st=V.current;if(!st){P("Select a project before resetting project settings."),L("error");return}const nt=++I.current;jt();const At=$.current.then(()=>u9(st));$.current=At.then(()=>{},()=>{});try{const k=await At;if(!z.current)return;st===V.current&&(Z.current=k,f(k),nt===I.current&&(J.current=k,c(k))),dt()}catch(k){if(!z.current)return;dt(`Could not reset project settings: ${ya(k)}`)}},[jt,dt]);return i.jsx(vA.Provider,{value:{loading:p,loadError:N,retry:gs,activeProjectPath:v,projectLoading:S,projectLoadError:j,selectProject:Fs,retryProject:Cn,saveState:T,saveError:H,global:t,confirmedGlobal:n,project:l,confirmedProject:d,ui:h,updateGlobal:Bn,updateProject:Pt,updateUi:fn,resetGlobal:bs,resetProject:rs,resetUi:ni},children:e})}function bm(){const e=vm();if(!e)throw new Error("useSettings must be used within SettingsProvider");return e}function vm(){return x.useContext(vA)}const sY=[{page:"services",labelKey:"nav.services",icon:i.jsx(Yf,{})},{page:"git",labelKey:"nav.git",icon:i.jsx(Pn,{})},{page:"github",labelKey:"nav.github",icon:i.jsx(pm,{})},{page:"workflows",labelKey:"nav.workflows",icon:i.jsx(nf,{})},{page:"errors",labelKey:"nav.errors",icon:i.jsx(ju,{})},{page:"database",labelKey:"nav.database",icon:i.jsx(ti,{})},{page:"terminal",labelKey:"nav.terminal",icon:i.jsx(zr,{})},{page:"agent",labelKey:"nav.agent",icon:i.jsx(Hf,{})},{page:"agent-env",labelKey:"nav.agentEnv",icon:i.jsx(Au,{})}];function nY(e,t){const s=Math.max(0,t-48),n=Math.min(180,s);return Math.max(n,Math.min(s,e))}function iY(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}function rY({currentPage:e="services",git:t,onGitRefresh:s,onNavigate:n}){const a=ee(),l=vm(),{activeTaskId:c,claimInitialInput:d,closeTask:f,draft:h,focusNonce:g,insertPrompt:p,onboarding:b,open:v,pendingTaskIds:_,provider:S,setActiveTaskId:C,setOpen:N,stopTask:A,tasks:j,terminalError:E,updateTaskStatus:T}=Ot(),[L,H]=x.useState(null),[P,F]=x.useState(!1),[M,z]=x.useState(!1),[G,D]=x.useState(null),[q,W]=x.useState(!1),I=x.useRef(null),Y=x.useRef(new Map),$=x.useRef(g),me=x.useRef(b),J=j.find(pe=>pe.id===c)??null;x.useEffect(()=>{(h||b)&&C(Zi)},[]),x.useEffect(()=>{g!==$.current&&C(Zi),$.current=g},[g,C]),x.useEffect(()=>{b&&!me.current&&C(Zi),me.current=b},[b,C]),x.useEffect(()=>()=>I.current?.(),[]),x.useEffect(()=>{if(!M)return;const pe=Qe=>{Qe.key==="Escape"&&z(!1)};return window.addEventListener("keydown",pe),()=>window.removeEventListener("keydown",pe)},[M]),x.useEffect(()=>{v||z(!1)},[v]);const V=()=>{z(!1),N(!1)},K=pe=>{n?.(pe),V()};function xe(pe){pe.preventDefault(),pe.currentTarget.setPointerCapture?.(pe.pointerId),F(!0);const Qe=Fs=>H(nY(window.innerHeight-Fs.clientY,window.innerHeight)),jt=()=>{window.removeEventListener("pointermove",Qe),window.removeEventListener("pointerup",dt),I.current=null},dt=()=>{F(!1),jt()};I.current?.(),I.current=jt,window.addEventListener("pointermove",Qe),window.addEventListener("pointerup",dt)}const ie=J?.provider??S?.id,Z=J?.kind==="shell",ge=Z?zr:ie==="codex"?Da:Br,ne=Z?a("dock.shell"):J?J.provider==="codex"?"Codex":"Claude Code":S?.label??"Agent",we=c===Zi||j.length===0,Ne=we?!q:!Z,Ue=G&&G!==c&&j.some(pe=>pe.id===G)?G:null,Pe=kK(((we?S?.id:J?.provider??S?.id)??"claude")==="codex"?"codex":"claude",v),Re=pe=>{if(!we&&J?.state==="running"){const Qe=Y.current.get(J.id);if(Qe){Qe.input(pe),Qe.focus();return}}p(pe)};return i.jsxs(i.Fragment,{children:[v?null:i.jsxs("button",{"aria-label":a("dock.openAria"),className:"fixed inset-x-0 bottom-0 z-50 flex h-9 w-full items-center gap-2 border-t border-border bg-card/95 px-3 text-left shadow-[0_-4px_18px_-14px_rgba(0,0,0,.45)] backdrop-blur",onClick:()=>N(!0),type:"button",children:[i.jsx(ge,{className:"size-3.5 text-primary"}),i.jsx("span",{className:"text-xs font-medium",children:ne}),i.jsx("span",{className:"h-3 w-px bg-border"}),i.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",children:J?.label??a("dock.newTask")}),J?i.jsxs("span",{className:oe("font-mono text-[10px] text-muted-foreground",J.state==="running"&&"text-emerald-600",J.state==="error"&&"text-destructive"),children:[i.jsx("span",{className:"sr-only",children:a("dock.activeStatusSr")}),iY(J.state)]}):null,j.length>1?i.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:j.length}):null,i.jsx(Ff,{className:"size-3.5 text-muted-foreground"})]}),i.jsxs("div",{"aria-hidden":!v||void 0,className:oe("fixed inset-x-0 bottom-0 z-50 flex flex-col overflow-hidden border-t border-border bg-card shadow-[0_-12px_30px_-20px_rgba(0,0,0,.5)]",!M&&(P||"transition-[height] duration-150"),!v&&"invisible pointer-events-none border-transparent shadow-none"),inert:!v||void 0,style:M?{height:"auto",top:$s()?32:0}:{height:v?L??"50vh":0},children:[M?i.jsx("nav",{"aria-label":a("dock.fullscreenNavAria"),className:"flex h-11 shrink-0 items-center gap-1 overflow-x-auto border-b border-border bg-background px-2",children:sY.map(pe=>i.jsxs("button",{"aria-current":e===pe.page?"page":void 0,"aria-label":a(pe.labelKey),className:oe("flex h-8 shrink-0 items-center gap-2 rounded-md px-3 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground [&_svg]:size-4",e===pe.page&&"bg-primary text-primary-foreground hover:bg-primary/90 hover:text-primary-foreground"),onClick:()=>K(pe.page),type:"button",children:[pe.icon,i.jsx("span",{children:a(pe.labelKey)})]},pe.page))}):null,i.jsx("div",{"aria-hidden":!0,className:oe("absolute inset-x-0 -top-1 z-20 h-2 cursor-ns-resize",M&&"hidden"),"data-agent-resize-grip":!0,onDoubleClick:()=>H(null),onPointerDown:xe}),i.jsxs("div",{className:"flex h-9 shrink-0 items-stretch border-b border-border bg-muted/25",children:[i.jsx(FK,{activeTaskId:c,composing:we,onActivate:C,onClose:pe=>{f(pe)},onSplit:pe=>D(Qe=>Qe===pe?null:pe),pendingTaskIds:_,splitTaskId:Ue,tasks:j}),Ne?i.jsx(bK,{capabilities:Pe,onInsert:Re,onNavigate:n?K:void 0,providerLabel:ne}):i.jsx("span",{className:"flex-1"}),i.jsxs("div",{className:"flex shrink-0 items-center border-l border-border px-1",children:[i.jsx("button",{"aria-label":a("dock.newTask"),className:"grid size-7 place-items-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground",onClick:()=>C(Zi),type:"button",children:i.jsx(fs,{className:"size-3.5"})}),J?.state==="running"?i.jsx("button",{"aria-label":a("dock.stopTaskAria",{label:J.label??a("dock.newTask")}),className:"grid size-7 place-items-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground disabled:pointer-events-none disabled:opacity-35",disabled:_.has(J.id),onClick:()=>{A(J.id)},type:"button",children:i.jsx(xo,{className:"size-3"})}):null,i.jsx("button",{"aria-label":a(M?"dock.restoreDock":"dock.enterFullScreen"),className:"grid size-7 place-items-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground",onClick:()=>z(pe=>!pe),type:"button",children:M?i.jsx(Vx,{className:"size-3.5"}):i.jsx(Gx,{className:"size-3.5"})}),i.jsx("button",{"aria-label":a("dock.collapseAria"),className:"grid size-7 place-items-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground",onClick:V,type:"button",children:i.jsx(hn,{className:"size-3.5"})})]})]}),E?i.jsx("div",{role:"alert",className:"border-b border-destructive/30 bg-destructive/5 px-3 py-1 font-mono text-[11px] text-destructive",children:E}):null,t&&we?i.jsx("div",{className:"shrink-0 px-3 pt-2",children:i.jsx(Gq,{git:t,onRefresh:s})}):null,i.jsxs("div",{className:"relative min-h-0 flex-1 bg-[#101214]",children:[j.map(pe=>{const Qe=v&&(pe.id===c||pe.id===Ue),jt=Ue?pe.id===Ue?"left-1/2 right-0 border-l border-border":"left-0 right-1/2":"inset-x-0";return i.jsx("div",{"aria-labelledby":`agent-tab-${pe.id}`,className:oe("absolute inset-y-0",jt,!Qe&&"invisible pointer-events-none"),id:`agent-panel-${pe.id}`,role:"tabpanel",children:i.jsx(lA,{active:Qe,claimInitialInput:()=>d(pe.id),displaySettings:l?.confirmedGlobal.terminal,onStatusChange:dt=>T(pe.id,{state:dt.state==="connecting"?"idle":dt.state,cwd:dt.cwd,error:dt.state==="error"?dt.detail:void 0}),ref:dt=>{dt?Y.current.set(pe.id,dt):Y.current.delete(pe.id)},sessionId:pe.id})},pe.id)}),v&&we?i.jsx("div",{"aria-labelledby":`agent-tab-${Zi}`,className:oe("absolute inset-y-0 bg-background",Ue?"left-0 right-1/2":"inset-x-0"),id:`agent-panel-${Zi}`,role:"tabpanel",children:i.jsx(HK,{capabilities:q?void 0:Pe,onNavigate:n?K:void 0,onShellMode:W,shellMode:q})}):null]})]})]})}function _l(e,t){const s=`nomoreide:${e}`,[n,a]=x.useState(()=>{try{const c=window.localStorage.getItem(s);return c===null?t:JSON.parse(c)}catch{return t}}),l=x.useCallback(c=>{a(c);try{window.localStorage.setItem(s,JSON.stringify(c))}catch{}},[s]);return[n,l]}function xm(e,t){if(!e)return!1;const s=t.endsWith("/")?t.slice(0,-1):t;return e===s||e.startsWith(`${s}/`)}function aY(e,t){return!t||!e?!0:xm(e,t)}function oY(e,t){const s=e.config.services.filter(d=>xm(d.cwd,t.path)),n=new Set(s.map(d=>d.name)),a=e.config.bundles.map(d=>({...d,services:d.services.filter(f=>n.has(f))})).filter(d=>d.services.length>0),l=Object.fromEntries(Object.entries(e.runtime.services).filter(([d])=>n.has(d))),c=Object.fromEntries(Object.entries(e.health).filter(([d])=>n.has(d)));return{...e,config:{...e.config,services:s,bundles:a},runtime:{services:l},health:c,ports:e.ports.filter(d=>d.services.some(f=>n.has(f))),logs:e.logs.filter(d=>n.has(d.service)),timeline:e.timeline.filter(d=>!d.service||n.has(d.service))}}const _b={host:"",port:"",user:"",password:"",database:"",ssl:!1},lY="localhost";function kx(e,t,{includePassword:s=!0}={}){const n=e==="mysql"?"mysql":"postgres",a=t.host.trim()||lY,l=t.port.trim(),c=t.database.trim().replace(/^\//,""),d=t.user.trim(),f=s&&t.password,h=d?`${encodeURIComponent(d)}${f?`:${encodeURIComponent(t.password)}`:""}@`:"",g=l?`:${l}`:"",p=e==="postgres"&&t.ssl?"?sslmode=require":"";return`${n}://${h}${a}${g}/${c}${p}`}function Cx(e){if(!e.trim())return null;let t;try{t=new URL(e.trim())}catch{return null}return{host:t.hostname,port:t.port,user:bC(t.username),password:bC(t.password),database:t.pathname.replace(/^\//,""),ssl:t.searchParams.get("sslmode")==="require"||t.searchParams.has("ssl")}}function cY(e){const t=/^([a-z0-9+]+):\/\//i.exec(e.trim());if(!t)return null;const s=t[1].toLowerCase();return s.startsWith("postgres")?"postgres":s.startsWith("mysql")?"mysql":s.startsWith("sqlite")||s==="file"?"sqlite":null}function bC(e){try{return decodeURIComponent(e)}catch{return e}}const uY=[{value:"postgres",label:"Postgres"},{value:"mysql",label:"MySQL"},{value:"sqlite",label:"SQLite"}];function dY({onClose:e,onSaved:t,initial:s,projects:n=[]}){const a=ee(),{isPending:l,runOperation:c}=si(),{error:d,success:f}=ms(),h=!!s,g=x.useMemo(()=>hY(s),[s]),[p,b]=x.useState(g.engine),[v,_]=x.useState(g.name),[S,C]=x.useState(g.url),[N,A]=x.useState(g.fields),[j,E]=x.useState([]),[T,L]=x.useState(s?.projectPath??""),[H,P]=x.useState({status:"idle"}),[F,M]=x.useState(!1),z=`database:${s?.name??"new"}:save`,G=l(z);x.useEffect(()=>{h||$O().then(E).catch(()=>E([]))},[h]);const D=p==="sqlite",q=D?S.trim():kx(p,N),W=D?!!S.trim():!!(N.host.trim()&&N.database.trim());function I(){P({status:"idle"})}function Y(Z,ge){return kx(Z,ge,{includePassword:!1})}function $(Z){b(Z),I(),Z!=="sqlite"&&C(Y(Z,N))}function me(Z){const ge={...N,...Z};A(ge),C(Y(p,ge)),I()}function J(Z){I();const ge=cY(Z),ne=ge??p;ge&&ge!==p&&b(ge);const we=ge==="sqlite"?null:Cx(Z);if(!we){C(Z);return}we.password?(A(we),C(Y(ne,we))):(A({...we,password:N.password}),C(Z))}function V(Z){b(Z.engine);const ge=Z.engine==="sqlite"?null:Cx(Z.url);ge?(A(ge),C(Y(Z.engine,ge))):C(Z.url),I(),v.trim()||_(fY(Z));const ne=Z.cwd?n.find(we=>xm(Z.cwd,we.path)):void 0;ne&&L(ne.path)}function K(){return v.trim()?D?S.trim()?null:a("database.dialog.errFilePathRequired"):N.host.trim()?N.database.trim()?null:a("database.dialog.errDatabaseRequired"):a("database.dialog.errHostRequired"):a("database.dialog.errNameRequired")}async function xe(){if(W){M(!0),I();try{const Z=await UO({engine:p,url:q});P(Z.ok?{status:"ok",message:a("database.dialog.connected")}:{status:"fail",message:Z.error??a("database.dialog.connectionFailed")})}catch(Z){P({status:"fail",message:Z instanceof Error?Z.message:String(Z)})}finally{M(!1)}}}async function ie(){const Z=K();if(Z){d(Z);return}try{await c({key:z,label:a("database.dialog.savingConnection",{name:v.trim()})},()=>FO({name:v.trim(),engine:p,url:q,projectPath:T})),f(a("database.dialog.savedToast",{name:v.trim()})),t(),e()}catch(ge){d(ge instanceof Error?ge.message:String(ge))}}return i.jsx(ei,{icon:i.jsx(ti,{}),onClose:e,title:a(h?"database.dialog.editTitle":"database.dialog.addTitle"),children:i.jsxs("div",{className:"flex flex-col gap-4",children:[j.length>0?i.jsxs("section",{children:[i.jsxs("p",{className:"mb-1.5 flex items-center gap-1.5 text-xs font-medium text-muted-foreground",children:[i.jsx(g8,{className:"size-3.5"}),a("database.dialog.foundInServices")]}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:j.map(Z=>i.jsxs("button",{type:"button",onClick:()=>V(Z),className:"group flex items-center gap-1.5 rounded-md border border-border bg-background px-2 py-1 text-left text-xs transition-colors hover:border-primary hover:bg-muted",title:Z.maskedUrl,children:[i.jsx(Ke,{variant:"outline",size:"small",children:Z.engine}),i.jsx("span",{className:"font-mono",children:Z.service}),i.jsxs("span",{className:"font-mono text-muted-foreground",children:["·",Z.key]})]},`${Z.service}:${Z.key}`))})]}):null,i.jsxs("section",{children:[i.jsx("p",{className:"mb-1.5 text-xs font-medium text-muted-foreground",children:a("database.dialog.engine")}),i.jsx("div",{className:"flex gap-1.5",children:uY.map(Z=>i.jsx(Q,{size:"sm",variant:p===Z.value?"default":"outline",onClick:()=>$(Z.value),disabled:h,type:"button",children:Z.label},Z.value))})]}),i.jsxs("label",{className:"flex flex-col gap-1.5",children:[i.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a("database.dialog.name")}),i.jsx(pt,{value:v,onChange:Z=>_(Z.target.value),placeholder:a("database.dialog.namePlaceholder"),disabled:h}),h?i.jsx("span",{className:"text-[11px] text-muted-foreground",children:a("database.dialog.nameLocked")}):null]}),n.length>0?i.jsxs("label",{className:"flex flex-col gap-1.5",children:[i.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Project"}),i.jsxs("select",{className:"h-9 rounded-md border border-border bg-background px-2 text-sm",onChange:Z=>L(Z.target.value),value:T,children:[i.jsx("option",{value:"",children:"No project (shared)"}),T&&!n.some(Z=>Z.path===T)?i.jsx("option",{value:T,children:T}):null,n.map(Z=>i.jsx("option",{value:Z.path,children:Z.name},Z.path))]}),i.jsx("span",{className:"text-[11px] text-muted-foreground",children:"Classifies the connection under a project; shared connections show in every project scope."})]}):null,D?null:i.jsxs("section",{className:"flex flex-col gap-3",children:[i.jsxs("div",{className:"flex gap-3",children:[i.jsxs("label",{className:"flex flex-1 flex-col gap-1.5",children:[i.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a("database.dialog.host")}),i.jsx(pt,{value:N.host,onChange:Z=>me({host:Z.target.value}),placeholder:"localhost",className:"font-mono text-xs"})]}),i.jsxs("label",{className:"flex w-24 flex-col gap-1.5",children:[i.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a("database.dialog.port")}),i.jsx(pt,{value:N.port,onChange:Z=>me({port:Z.target.value}),placeholder:p==="mysql"?"3306":"5432",className:"font-mono text-xs"})]})]}),i.jsxs("div",{className:"flex gap-3",children:[i.jsxs("label",{className:"flex flex-1 flex-col gap-1.5",children:[i.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a("database.dialog.user")}),i.jsx(pt,{value:N.user,onChange:Z=>me({user:Z.target.value}),placeholder:"postgres",className:"font-mono text-xs"})]}),i.jsxs("label",{className:"flex flex-1 flex-col gap-1.5",children:[i.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a("database.dialog.password")}),i.jsx(pt,{type:"password",value:N.password,onChange:Z=>me({password:Z.target.value}),placeholder:h?a("database.dialog.passwordKeep"):"••••••••",className:"font-mono text-xs"})]})]}),i.jsxs("label",{className:"flex flex-col gap-1.5",children:[i.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a("database.dialog.database")}),i.jsx(pt,{value:N.database,onChange:Z=>me({database:Z.target.value}),placeholder:"app",className:"font-mono text-xs"})]}),p==="postgres"?i.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[i.jsx("input",{type:"checkbox",checked:N.ssl,onChange:Z=>me({ssl:Z.target.checked}),className:"size-3.5 accent-primary"}),a("database.dialog.requireSslPre")," ",i.jsx("span",{className:"font-mono",children:"?sslmode=require"}),a("database.dialog.requireSslPost")]}):null]}),i.jsxs("label",{className:"flex flex-col gap-1.5",children:[i.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a(D?"database.dialog.filePath":"database.dialog.connectionUrl")}),i.jsx(pt,{value:S,onChange:Z=>J(Z.target.value),placeholder:D?"/abs/path/to/app.db":p==="mysql"?"mysql://user:pass@host:3306/db":"postgres://user:pass@host:5432/db",className:"font-mono text-xs"}),i.jsx("span",{className:"text-[11px] text-muted-foreground",children:a(D?"database.dialog.sqliteHint":"database.dialog.urlHint")})]}),H.status!=="idle"?i.jsxs("div",{className:`flex items-center gap-1.5 rounded-md border px-2.5 py-1.5 text-xs ${H.status==="ok"?"border-emerald-500/40 text-emerald-600 dark:text-emerald-400":"border-destructive/40 text-destructive"}`,children:[H.status==="ok"?i.jsx(Ys,{className:"size-3.5"}):i.jsx(Vt,{className:"size-3.5"}),i.jsx("span",{className:"break-all font-mono",children:H.message})]}):null,i.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border pt-3",children:[i.jsxs(Q,{variant:"outline",size:"sm",onClick:()=>{xe()},disabled:F||!W,type:"button",children:[F?i.jsx(Lt,{className:"animate-spin"}):null,a("database.dialog.testConnection")]}),i.jsx(Q,{size:"sm",onClick:()=>{ie()},loading:G,loadingLabel:a("common.saving"),type:"button",children:a(h?"database.dialog.saveChanges":"common.save")})]})]})})}function hY(e){if(!e)return{engine:"postgres",name:"",fields:_b,url:""};if(e.engine==="sqlite")return{engine:"sqlite",name:e.name,fields:_b,url:e.url};const t=Cx(e.url),s=t?{...t,password:""}:_b;return{engine:e.engine,name:e.name,fields:s,url:kx(e.engine,s,{includePassword:!1})}}function fY(e){try{const s=new URL(e.url).pathname.replace(/^\//,"");if(s)return`${e.service}-${s}`}catch{}return`${e.service}-${e.engine}`}function mY({connections:e,projectLabel:t,selected:s,onSelect:n,onAdd:a,onEdit:l,onRemove:c}){const d=ee(),[f,h]=x.useState(!1),g=x.useRef(null),p=e.find(b=>b.name===s);return x.useEffect(()=>{if(!f)return;function b(v){g.current&&v.target instanceof Node&&!g.current.contains(v.target)&&h(!1)}return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[f]),i.jsxs("div",{className:"relative z-50 flex items-center gap-2",ref:g,children:[i.jsxs(Q,{className:"max-w-[240px] justify-start gap-2 rounded-md border-border bg-card",onClick:()=>h(b=>!b),size:"sm",type:"button",variant:"outline",children:[i.jsx(ti,{className:"text-muted-foreground"}),i.jsx("span",{className:"truncate",children:p?.name??d("database.selectConnection")}),p?i.jsx(Ke,{variant:"outline",size:"small",children:p.engine}):null,i.jsx(hn,{className:oe("ml-auto transition-transform",f&&"rotate-180")})]}),f?i.jsxs("div",{className:"absolute right-0 top-10 z-50 w-[min(420px,calc(100vw-2rem))] overflow-hidden rounded-lg border border-border bg-card shadow-lg",children:[i.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2",children:[i.jsx(ti,{className:"size-3.5 text-muted-foreground"}),i.jsx("div",{className:"text-xs font-semibold",children:d("database.connections")}),i.jsx(Ke,{className:"ml-auto",variant:"outline",size:"small",children:e.length})]}),i.jsx("div",{className:"max-h-72 overflow-auto",children:e.length?i.jsx("div",{className:"divide-y divide-border",children:e.map(b=>{const v=b.name===s;return i.jsxs("div",{className:oe("group grid w-full grid-cols-[1fr_auto_auto_auto] items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-muted",v&&"bg-muted/70"),children:[i.jsxs("button",{className:"min-w-0 text-left",onClick:()=>{n(b.name),h(!1)},type:"button",children:[i.jsxs("span",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:"truncate text-sm font-medium leading-tight",children:b.name}),t?i.jsx(Ke,{className:"shrink-0",size:"small",variant:"outline",children:t(b)??"unassigned"}):null]}),i.jsx("span",{className:"block truncate font-mono text-[10px] leading-tight text-muted-foreground",children:b.url})]}),v?i.jsx(Ys,{className:"size-3.5"}):i.jsx("span",{className:"size-3.5"}),i.jsx(Q,{"aria-label":d("database.editConn",{name:b.name}),className:"size-6 opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>{l(b),h(!1)},size:"icon",title:d("database.editConn",{name:b.name}),type:"button",variant:"ghost",children:i.jsx(Cl,{className:"size-3.5"})}),i.jsx(Q,{"aria-label":d("database.removeConn",{name:b.name}),className:"size-6 opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>c(b.name),size:"icon",title:d("database.removeConn",{name:b.name}),type:"button",variant:"ghost",children:i.jsx(Bi,{className:"size-3.5 text-destructive"})})]},b.name)})}):i.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:d("database.noSavedConnections")})}),i.jsx("div",{className:"border-t border-border bg-muted/20 p-2",children:i.jsxs(Q,{className:"w-full",onClick:()=>{a(),h(!1)},size:"sm",type:"button",children:[i.jsx(fs,{className:"size-3"}),d("database.addConnection")]})})]}):null]})}function pY({onAddManual:e,onAddWithAi:t}){const s=ee(),[n,a]=x.useState(!1),l=x.useRef(null);x.useEffect(()=>{if(!n)return;function d(f){l.current&&f.target instanceof Node&&!l.current.contains(f.target)&&a(!1)}return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[n]);function c(d){a(!1),d()}return i.jsxs("div",{className:"relative",ref:l,children:[i.jsxs(Q,{"aria-label":s("database.addMenuAria"),onClick:()=>a(d=>!d),size:"sm",type:"button",children:[i.jsx(fs,{className:"size-3.5"}),s("common.add")]}),n?i.jsxs("div",{className:"absolute right-0 top-9 z-50 w-56 overflow-hidden rounded-lg border border-border bg-card shadow-lg",children:[i.jsxs("button",{className:"flex w-full items-center gap-2 px-3 py-2 text-left text-sm transition-colors hover:bg-muted",onClick:()=>c(e),type:"button",children:[i.jsx(ti,{className:"size-3.5 text-muted-foreground"}),s("database.addConnection")]}),i.jsxs("button",{className:"flex w-full items-center gap-2 border-t border-border px-3 py-2 text-left text-sm transition-colors hover:bg-muted",onClick:()=>c(t),type:"button",children:[i.jsx(zn,{className:"size-3.5 text-muted-foreground"}),s("database.addWithAi")]})]}):null]})}function gY(){const[e,t]=x.useState([]),[s,n]=x.useState(!0),[a,l]=x.useState(null),c=x.useCallback(async()=>{n(!0),l(null);try{t(await AE())}catch(d){l(d instanceof Error?d.message:String(d))}finally{n(!1)}},[]);return x.useEffect(()=>{c()},[c]),{connections:e,loading:s,error:a,refresh:c}}const bY=[50,100,500,1e3];function xA(e){return[...new Set([...bY,e])].sort((t,s)=>t-s)}function vY(e){const[t,s]=x.useState(null),[n,a]=x.useState(null),[l,c]=x.useState(!1);x.useEffect(()=>{s(null),a(null)},[e]);const d=x.useCallback(async(h,g)=>{if(!(!e||!h.trim())){c(!0),a(null);try{s(await GO(e,h,g))}catch(p){s(null),a(p instanceof Error?p.message:String(p))}finally{c(!1)}}},[e]),f=x.useCallback(()=>{s(null),a(null)},[]);return{result:t,error:n,running:l,run:d,reset:f}}const xY=["select","show","explain","pragma","describe","desc"];function yY(e){const t=/^\s*([a-z]+)/i.exec(e)?.[1]?.toLowerCase()??"";return xY.includes(t)}function _Y(e){const[t,s]=x.useState(null),[n,a]=x.useState(null),[l,c]=x.useState(null),[d,f]=x.useState(!1),[h,g]=x.useState(!1);x.useEffect(()=>{s(null),a(null),c(null)},[e]);const p=x.useCallback(async S=>{if(!(!e||!S.trim())){f(!0),c(null),a(null);try{const C=await cS(e,S,"preview");s({sql:S,preview:C})}catch(C){c(C instanceof Error?C.message:String(C))}finally{f(!1)}}},[e]),b=x.useCallback(async S=>{const C=S??t?.sql;if(!e||!C)return null;g(!0),c(null);try{const N=await cS(e,C,"commit");return a(N),s(null),N}catch(N){return s(null),c(N instanceof Error?N.message:String(N)),null}finally{g(!1)}},[e,t]),v=x.useCallback(()=>s(null),[]),_=x.useCallback(()=>{s(null),a(null),c(null)},[]);return{pending:t,committed:n,error:l,previewing:d,committing:h,preview:p,commit:b,cancel:v,reset:_}}function wY(e,t){const[s,n]=x.useState(!1),a=x.useCallback(async l=>{if(e){n(!0);try{await VO(e,l),t()}finally{n(!1)}}},[e,t]);return{updating:s,setUnlocked:a}}function SY(e,t=100){const[s,n]=x.useState([]),[a,l]=x.useState(null),[c,d]=x.useState(null),[f,h]=x.useState(null),[g,p]=x.useState(null),[b,v]=x.useState(!1),[_,S]=x.useState(!1),[C,N]=x.useState(()=>t),A=x.useRef(!1),[j,E]=x.useState(0);x.useEffect(()=>{A.current||N(t)},[t]),x.useEffect(()=>{E(0)},[e,a]),x.useEffect(()=>{if(n([]),l(null),d(null),h(null),p(null),!e)return;let M=!1;return v(!0),TE(e).then(z=>{M||(n(z),l(z[0]?.qualifiedName??null))}).catch(z=>{M||h(z instanceof Error?z.message:String(z))}).finally(()=>{M||v(!1)}),()=>{M=!0}},[e]),x.useEffect(()=>{if(d(null),p(null),!e||!a)return;let M=!1;return S(!0),WO(e,a,C,j).then(z=>{M||d(z)}).catch(z=>{M||p(z instanceof Error?z.message:String(z))}).finally(()=>{M||S(!1)}),()=>{M=!0}},[e,a,C,j]);const T=j>0,L=c?c.rowCount===C:!1;function H(M){A.current=!0,N(M),E(0)}function P(){L&&E(M=>M+C)}function F(){E(M=>Math.max(0,M-C))}return{tables:s,selectedTable:a,setSelectedTable:l,sample:c,tablesError:f,rowsError:g,loadingTables:b,loadingRows:_,limit:C,offset:j,canPrev:T,canNext:L,changePageSize:H,nextPage:P,prevPage:F}}function kY(e,t,s,n){const a=ee(),{provider:l}=Ot(),[c,d]=x.useState(!1),[f,h]=x.useState(null),g=x.useRef(null),p=x.useRef(!0);return x.useEffect(()=>(p.current=!0,()=>{p.current=!1,g.current?.abort()}),[]),{generate:x.useCallback(async v=>{if(!e||!v.trim()||c)return;d(!0),h(null);const _=new AbortController;g.current=_;try{let S=[];try{S=await TE(e)}catch{S=[]}if(!p.current||_.signal.aborted)return;const C=await O0({prompt:NF(e,v,{engine:t,tables:S,unlocked:s}),provider:l?.id,signal:_.signal});if(!p.current)return;const N=CY(C);N?n(N):h(a("database.sql.noSqlBlock"))}catch(S){p.current&&!_.signal.aborted&&h(S instanceof Error?S.message:String(S))}finally{g.current===_&&(g.current=null),p.current&&d(!1)}},[e,t,s,c,n,l?.id,a]),generating:c,error:f}}function CY(e){if(!e)return null;const s=/```(?:sql)?\s*\n?([\s\S]*?)```/i.exec(e)?.[1]?.trim();return s||null}function NY({connection:e,sample:t}){const s=ee(),{sendToAgent:n}=Ot(),{success:a,error:l}=ms(),c=t.columns.map(p=>p.name);function d(p){n({prompt:CF(e,t.engine,t.table,t.columns,p),source:{type:"database-row",label:s("database.grid.rowSource",{table:t.table.name})},mode:"draft"})}async function f(p,b){try{await navigator.clipboard.writeText(p),a(s("database.grid.copiedWhat",{what:b}))}catch(v){l(v instanceof Error?v.message:String(v))}}function h(p){const b=v=>{const _=pu(v);return/[",\n]/.test(_)?`"${_.replace(/"/g,'""')}"`:_};return`${c.join(",")}
|
|
118
|
-
${c.map(v=>b(p[v])).join(",")}`}function g(p){const b=_=>_==null?"NULL":typeof _=="number"||typeof _=="boolean"?String(_):`'${(typeof _=="object"?JSON.stringify(_):String(_)).replace(/'/g,"''")}'`,v=c.map(_=>b(p[_])).join(", ");return`INSERT INTO ${t.table} (${c.join(", ")}) VALUES (${v});`}return t.columns.length===0?i.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:s("database.grid.noColumnsTable")}):i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:i.jsxs("table",{className:"code-font-size w-max min-w-full border-collapse text-left font-mono",children:[i.jsx("thead",{className:"sticky top-0 z-10 bg-card",children:i.jsxs("tr",{className:"border-b border-border",children:[t.columns.map(p=>i.jsxs("th",{className:"whitespace-nowrap px-3 py-2 font-semibold text-foreground",children:[i.jsxs("span",{className:"flex items-center gap-1",children:[p.primaryKey?i.jsx(uE,{className:"size-3 text-amber-500"}):null,p.name]}),i.jsx("span",{className:"block font-normal text-muted-foreground",children:p.dataType})]},p.name)),i.jsx("th",{className:"sticky right-0 z-20 w-16 border-l border-border bg-card px-2 py-2"})]})}),i.jsxs("tbody",{children:[t.rows.map((p,b)=>i.jsxs("tr",{className:"group border-b border-border/60 hover:bg-muted/40",children:[t.columns.map(v=>i.jsx("td",{className:"max-w-[320px] truncate px-3 py-1 align-top text-muted-foreground",title:pu(p[v.name]),children:pu(p[v.name])},v.name)),i.jsx("td",{className:"sticky right-0 z-[1] border-l border-border/60 bg-card px-2 py-1 align-top before:pointer-events-none before:absolute before:inset-0 before:bg-muted/40 before:opacity-0 group-hover:before:opacity-100",children:i.jsxs("div",{className:"relative z-[1] flex items-center justify-end gap-0.5",children:[i.jsx(ir,{label:s("database.grid.askAiRow"),onAsk:()=>d(p)}),i.jsx(Ll,{label:s("database.grid.rowActions"),items:[{label:s("database.grid.copyJson"),icon:i.jsx(lM,{className:"size-3.5"}),onSelect:()=>{f(JSON.stringify(p,null,2),s("database.grid.rowAsJson"))}},{label:s("database.grid.copyCsv"),icon:i.jsx(JM,{className:"size-3.5"}),onSelect:()=>{f(h(p),s("database.grid.rowAsCsv"))}},{label:s("database.grid.copySqlInsert"),icon:i.jsx(ti,{className:"size-3.5"}),onSelect:()=>{f(g(p),s("database.grid.insertStatement"))}}]})]})})]},b)),t.rows.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:t.columns.length+1,className:"px-3 py-6 text-center text-muted-foreground",children:s("database.grid.noRows")})}):null]})]})})}function pu(e){return e==null?"NULL":typeof e=="object"?JSON.stringify(e):String(e)}function EY({connection:e,busy:t,onConfirm:s,onClose:n}){const a=ee();return i.jsx(ei,{icon:i.jsx(WD,{className:"text-amber-500"}),onClose:n,title:a("database.write.unlockTitle",{connection:e}),children:i.jsxs("div",{className:"flex flex-col gap-4 text-sm",children:[i.jsx("p",{className:"text-muted-foreground",children:a("database.write.unlockBody1")}),i.jsx("p",{className:"text-muted-foreground",children:a("database.write.unlockBody2")}),i.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border pt-3",children:[i.jsx(Q,{variant:"outline",size:"sm",onClick:n,type:"button",children:a("common.cancel")}),i.jsxs(Q,{size:"sm",onClick:s,disabled:t,type:"button",children:[t?i.jsx(Lt,{className:"animate-spin"}):i.jsx(dE,{}),a("database.write.unlockWrites")]})]})]})})}function jY({sql:e,preview:t,busy:s,onConfirm:n,onClose:a}){const l=ee();return i.jsx(ei,{icon:i.jsx(Lr,{className:"text-amber-500"}),onClose:a,title:l("database.write.confirmTitle"),children:i.jsxs("div",{className:"flex flex-col gap-4 text-sm",children:[i.jsx("pre",{className:"max-h-40 overflow-auto rounded-md border border-border bg-muted/40 px-3 py-2 font-mono text-[11px] whitespace-pre-wrap",children:e}),t.previewUnavailable?i.jsx("p",{className:"rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[13px] text-amber-700 dark:text-amber-300",children:l("database.write.previewUnavailable")}):i.jsxs("p",{className:"text-muted-foreground",children:[l("database.write.willAffectPre")," ",i.jsx("strong",{className:"text-foreground tabular-nums",children:t.affectedRows??0})," ",l("database.write.willAffectPost")]}),i.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border pt-3",children:[i.jsx(Q,{variant:"outline",size:"sm",onClick:a,type:"button",children:l("common.cancel")}),i.jsxs(Q,{size:"sm",className:"bg-amber-600 text-white hover:bg-amber-600/90",onClick:n,disabled:s,type:"button",children:[s?i.jsx(Lt,{className:"animate-spin"}):null,l("database.write.runCommit")]})]})]})})}function AY({connection:e,engine:t,unlocked:s,seed:n,onWriteAccessChange:a,preferences:l={confirmWrites:!0,resultLimit:100}}){const c=ee(),{isPending:d,runOperation:f}=si(),{success:h}=ms(),{sendToAgent:g}=Ot(),p=vY(e),b=_Y(e),v=wY(e,a),[_,S]=x.useState(n?.sql??""),[C,N]=x.useState(()=>l.resultLimit),A=x.useRef(!1);x.useEffect(()=>{A.current||N(l.resultLimit)},[l.resultLimit]);const j=n?.nonce;x.useEffect(()=>{n&&S(n.sql)},[j]);const[E,T]=x.useState(!1),L=kY(e,t,s,S),H=_.trim().length>0&&!yY(_),P=s&&H,F=H&&!s,M=p.running||b.previewing||b.committing,z=`database:${e}:write`,G=d(z);function D(){if(_.trim()){if(F){T(!0);return}P?(p.reset(),l.confirmWrites?b.preview(_):I(_)):(b.reset(),p.run(_,C))}}function q(Y){(Y.metaKey||Y.ctrlKey)&&Y.key==="Enter"&&(Y.preventDefault(),D())}function W(Y){g({prompt:EF(e,t,_,Y),source:{type:"database-sql-debug",label:"Debug SQL"},label:c("database.sql.debugLabel")})}async function I(Y){const $=await f({key:z,label:c("database.sql.committingWrite",{connection:e})},()=>b.commit(Y));if($?.committed){const me=$.affectedRows??0;h(c("database.sql.committed",{count:me}))}}return i.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[i.jsxs("div",{className:"shrink-0 border-b border-border p-2",children:[i.jsx(TY,{generate:L}),i.jsx("textarea",{value:_,onChange:Y=>S(Y.target.value),onKeyDown:q,spellCheck:!1,placeholder:c(s?"database.sql.placeholderUnlocked":"database.sql.placeholderLocked"),className:"code-font-size h-24 w-full resize-y rounded-md border border-border bg-background px-2 py-1.5 font-mono outline-none focus:border-ring"}),i.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[i.jsx(RY,{unlocked:s,updating:v.updating,onUnlock:()=>T(!0),onLock:()=>{v.setUnlocked(!1)}}),i.jsxs("div",{className:"flex items-center gap-2",children:[P?null:i.jsx("select",{"aria-label":c("database.sql.maxRows"),className:"rounded-md border border-border bg-background px-1.5 py-1 text-[11px]",value:C,onChange:Y=>{A.current=!0,N(Number(Y.target.value))},children:xA(l.resultLimit).map(Y=>i.jsx("option",{value:Y,children:c("database.sql.rowsOption",{size:Y})},Y))}),i.jsxs(Q,{size:"sm",className:oe("h-7 px-3",P&&"bg-amber-600 text-white hover:bg-amber-600/90"),onClick:D,disabled:M||!_.trim(),loading:P&&G,loadingLabel:c("database.sql.runWrite"),type:"button",children:[M?i.jsx(Lt,{className:"size-3.5 animate-spin"}):i.jsx(Or,{className:"size-3.5"}),P?l.confirmWrites?c("database.sql.previewWrite"):c("database.sql.runWrite"):c("database.sql.run")]})]})]})]}),i.jsx(MY,{read:p,write:b,onDebug:W}),E?i.jsx(EY,{connection:e,busy:v.updating,onConfirm:async()=>{await v.setUnlocked(!0),T(!1)},onClose:()=>T(!1)}):null,b.pending?i.jsx(jY,{sql:b.pending.sql,preview:b.pending.preview,busy:b.committing,onConfirm:()=>{I()},onClose:b.cancel}):null]})}function TY({generate:e}){const t=ee(),[s,n]=x.useState("");function a(){const c=s.trim();!c||e.generating||e.generate(c)}function l(c){c.key==="Enter"&&(c.preventDefault(),a())}return i.jsxs("div",{className:"mb-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx(Xt,{className:"pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2"}),i.jsx("input",{value:s,onChange:c=>n(c.target.value),onKeyDown:l,disabled:e.generating,placeholder:t("database.sql.generatePlaceholder"),className:"h-8 w-full rounded-md border border-border bg-background pl-7 pr-2 text-[12px] outline-none focus:border-ring disabled:opacity-60"})]}),i.jsxs(Q,{size:"sm",variant:"outline",className:"h-8 px-3",onClick:a,disabled:e.generating||!s.trim(),type:"button",children:[e.generating?i.jsx(Lt,{className:"size-3.5 animate-spin"}):i.jsx(Xt,{className:"size-3.5"}),e.generating?t("database.sql.generating"):t("database.sql.askAi")]})]}),e.error?i.jsx("p",{className:"mt-1 text-[11px] text-amber-600 dark:text-amber-400",children:e.error}):null]})}function RY({unlocked:e,updating:t,onUnlock:s,onLock:n}){const a=ee();return i.jsxs("button",{type:"button",onClick:e?n:s,disabled:t,className:oe("flex items-center gap-1.5 rounded-md border px-2 py-1 text-[11px] font-medium transition-colors",e?"border-amber-500/50 text-amber-600 hover:bg-amber-500/10 dark:text-amber-400":"border-border text-muted-foreground hover:text-foreground"),title:a(e?"database.sql.writesUnlockedTitle":"database.sql.readOnlyTitle"),children:[t?i.jsx(Lt,{className:"size-3.5 animate-spin"}):e?i.jsx(dE,{className:"size-3.5"}):i.jsx(X6,{className:"size-3.5"}),a(e?"database.sql.writesUnlocked":"database.sql.readOnly")]})}function MY({read:e,write:t,onDebug:s}){const n=ee(),a=t.error??e.error;return i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:a?i.jsxs("div",{className:"space-y-3 p-4",children:[i.jsx("p",{className:"code-font-size whitespace-pre-wrap font-mono text-destructive",children:a}),i.jsxs(Q,{size:"sm",variant:"outline",className:"h-7 px-3",onClick:()=>s(a),type:"button",children:[i.jsx(Xt,{className:"size-3.5"}),n("database.sql.debugWithAi")]})]}):t.committed?i.jsx(DY,{outcome:t.committed}):e.result?i.jsx(yA,{columns:e.result.columns,rows:e.result.rows,truncated:e.result.truncated}):i.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center text-sm text-muted-foreground",children:n("database.sql.emptyResult")})})}function DY({outcome:e}){const t=ee();if(!e)return null;const s=e.affectedRows??0;return i.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[i.jsxs("div",{className:"flex shrink-0 items-center gap-1.5 border-b border-border bg-emerald-500/10 px-3 py-1.5 text-[12px] text-emerald-700 dark:text-emerald-400",children:[i.jsx(Ys,{className:"size-3.5"}),t("database.sql.committed",{count:s})]}),e.rows&&e.rows.length>0&&e.columns?i.jsx(yA,{columns:e.columns,rows:e.rows}):null]})}function yA({columns:e,rows:t,truncated:s=!1}){const n=ee();return e.length===0?i.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:n("database.sql.noColumns")}):i.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[s?i.jsxs("div",{className:"flex shrink-0 items-center gap-1.5 border-b border-border bg-amber-500/10 px-3 py-1.5 text-[11px] text-amber-600 dark:text-amber-400",children:[i.jsx(Lr,{className:"size-3.5"}),n("database.sql.truncated",{count:t.length})]}):null,i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:i.jsxs("table",{className:"code-font-size w-max min-w-full border-collapse text-left font-mono",children:[i.jsx("thead",{className:"sticky top-0 z-10 bg-card",children:i.jsx("tr",{className:"border-b border-border",children:e.map(a=>i.jsx("th",{className:"whitespace-nowrap px-3 py-2 font-semibold text-foreground",children:a.name},a.name))})}),i.jsxs("tbody",{children:[t.map((a,l)=>i.jsx("tr",{className:"border-b border-border/60 hover:bg-muted/40",children:e.map(c=>i.jsx("td",{className:"max-w-[320px] truncate px-3 py-1 align-top text-muted-foreground",title:pu(a[c.name]),children:pu(a[c.name])},c.name))},l)),t.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:e.length,className:"px-3 py-6 text-center text-muted-foreground",children:n("database.grid.noRows")})}):null]})]})})]})}function LY({staged:e,onStageConsumed:t,projects:s=[],scopePath:n=null}={}){const a=ee(),c=vm()?.confirmedProject.database??{confirmWrites:!0,resultLimit:100},{connections:d,loading:f,error:h,refresh:g}=gY(),p=x.useMemo(()=>d.filter(z=>aY(z.projectPath,n)),[d,n]),b=z=>z.projectPath?s.find(D=>xm(z.projectPath,D.path))?.name??z.projectPath.split("/").pop()??null:null;Dl(g);const{error:v,success:_}=ms(),{sendToAgent:S}=Ot(),[C,N]=_l("database:selected",null),[A,j]=_l("database:mode","browse"),[E,T]=x.useState(null),[L,H]=x.useState(null);x.useEffect(()=>{e&&(e.connection&&N(e.connection),j("query"),H({sql:e.sql,nonce:e.nonce}),t?.())},[e?.nonce]);function P(){S({prompt:wF,source:{type:"database-setup",label:"Add a database"},label:"Help me connect a database, one step at a time."})}x.useEffect(()=>{if(p.length===0){C!==null&&N(null);return}(!C||!p.some(z=>z.name===C))&&N(p[0].name)},[p,C,N]);async function F(z){try{await qO(z),_(a("database.toast.removed",{name:z})),await g()}catch(G){v(G instanceof Error?G.message:String(G))}}function M(z){T({mode:"edit",target:z})}return i.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[i.jsxs("header",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(ti,{className:"size-4 text-muted-foreground"}),i.jsx("span",{className:"text-sm font-semibold",children:a("database.title")}),f&&p.length===0?i.jsx(Lt,{className:"size-3.5 animate-spin text-muted-foreground"}):null]}),i.jsxs("div",{className:"flex items-center gap-2",children:[C?i.jsx(OY,{mode:A,onChange:j}):null,i.jsx(mY,{connections:p,projectLabel:b,selected:C,onSelect:N,onAdd:()=>T({mode:"add"}),onEdit:M,onRemove:z=>{F(z)}}),i.jsx(pY,{onAddManual:()=>T({mode:"add"}),onAddWithAi:P})]})]}),i.jsx("div",{className:"min-h-0 flex-1",children:h?i.jsx("div",{className:"p-4",children:i.jsx(tt,{variant:"muted",className:"border-destructive/40 text-destructive",children:h})}):C?A==="query"?i.jsx(AY,{connection:C,engine:p.find(z=>z.name===C)?.engine,unlocked:p.find(z=>z.name===C)?.writeUnlocked??!1,seed:L,onWriteAccessChange:g,preferences:c},C):i.jsx(PY,{connection:C,resultLimit:c.resultLimit}):i.jsx(zY,{onAdd:()=>T({mode:"add"}),onAddWithAi:P})}),E?i.jsx(dY,{initial:E.mode==="edit"?E.target:void 0,projects:s,onClose:()=>T(null),onSaved:g}):null]})}function OY({mode:e,onChange:t}){const s=ee(),n=[{value:"browse",label:s("database.browse"),icon:yE},{value:"query",label:s("database.sql"),icon:Al}];return i.jsx("div",{className:"flex items-center rounded-md border border-border p-0.5",children:n.map(a=>{const l=a.icon;return i.jsxs("button",{type:"button",onClick:()=>t(a.value),className:oe("flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium transition-colors",e===a.value?"bg-muted text-foreground":"text-muted-foreground hover:text-foreground"),children:[i.jsx(l,{className:"size-3.5"}),a.label]},a.value)})})}function PY({connection:e,resultLimit:t}){const s=ee(),{sendToAgent:n}=Ot(),{tables:a,selectedTable:l,setSelectedTable:c,sample:d,tablesError:f,rowsError:h,loadingTables:g,loadingRows:p,limit:b,offset:v,canPrev:_,canNext:S,changePageSize:C,nextPage:N,prevPage:A}=SY(e,t);function j(T){n({prompt:Zk(e,T.table,{engine:T.engine,columns:T.columns}),source:{type:"database-table",label:`${T.table.name} table`},mode:"draft"})}function E(T){n({prompt:Zk(e,T),source:{type:"database-table",label:`${T.name} table`},mode:"draft"})}return i.jsxs("div",{className:"flex h-full min-h-0",children:[i.jsxs("div",{className:"flex w-56 shrink-0 flex-col border-r border-border",children:[i.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[i.jsx(yE,{className:"size-4 text-muted-foreground"}),i.jsx("span",{className:"text-sm font-semibold",children:s("database.tables")}),i.jsx(Ke,{variant:"outline",size:"small",children:a.length}),g?i.jsx(Lt,{className:"size-3.5 animate-spin"}):null]}),f?i.jsx("div",{className:"p-3",children:i.jsx(tt,{variant:"muted",className:"border-destructive/40 text-destructive",children:f})}):i.jsxs("ul",{className:"min-h-0 flex-1 overflow-auto",children:[a.map(T=>i.jsxs("li",{className:oe("group flex items-center gap-1 pr-1 transition-colors hover:bg-muted/50",T.qualifiedName===l&&"bg-muted/70"),children:[i.jsx("button",{type:"button",onClick:()=>c(T.qualifiedName),className:oe("min-w-0 flex-1 truncate px-3 py-1.5 text-left font-mono text-[11px]",T.qualifiedName===l&&"font-semibold"),children:T.qualifiedName}),i.jsx(ir,{label:s("database.askAiAbout",{name:T.qualifiedName}),onAsk:()=>E(T)})]},T.qualifiedName)),!g&&a.length===0?i.jsx("li",{className:"px-3 py-2 text-xs text-muted-foreground",children:s("database.noTables")}):null]})]}),i.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[i.jsxs("div",{className:"group flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-2",children:[i.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[i.jsx("span",{className:"truncate font-mono text-xs font-semibold",children:l??s("database.selectTable")}),d?i.jsx(ir,{label:s("database.askAiAbout",{name:d.table.qualifiedName}),onAsk:()=>j(d)}):null]}),d?i.jsxs("div",{className:"flex shrink-0 items-center gap-2 text-[11px] text-muted-foreground",children:[i.jsx("span",{className:"tabular-nums",children:d.rowCount===0?s("database.noRows"):s("database.rowsRange",{from:v+1,to:v+d.rowCount})}),i.jsx("select",{"aria-label":s("database.rowsPerPage"),className:"rounded-md border border-border bg-background px-1.5 py-0.5 text-[11px]",value:b,onChange:T=>C(Number(T.target.value)),children:xA(t).map(T=>i.jsx("option",{value:T,children:s("database.perPage",{size:T})},T))}),i.jsx(Q,{size:"sm",variant:"outline",className:"h-6 px-2",onClick:A,disabled:!_,type:"button",children:s("database.prev")}),i.jsx(Q,{size:"sm",variant:"outline",className:"h-6 px-2",onClick:N,disabled:!S,type:"button",children:s("database.next")})]}):null]}),h?i.jsx("div",{className:"p-4",children:i.jsx(tt,{variant:"muted",className:"border-destructive/40 text-destructive",children:h})}):p?i.jsxs("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:[i.jsx(Lt,{className:"mr-2 size-4 animate-spin"}),s("database.loadingRows")]}):d?i.jsx(NY,{connection:e,sample:d}):i.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:s("database.pickTable")})]})]})}function zY({onAdd:e,onAddWithAi:t}){const s=ee();return i.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center",children:i.jsxs("div",{className:"max-w-sm",children:[i.jsx(ti,{className:"mx-auto size-8 text-muted-foreground/50"}),i.jsx("p",{className:"mt-3 text-sm font-medium",children:s("database.emptyTitle")}),i.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:[s("database.emptyBody1")," ",i.jsx("code",{children:".env"})," ",s("database.emptyBody2")]}),i.jsxs("div",{className:"mt-4 flex items-center justify-center gap-2",children:[i.jsxs(Q,{size:"sm",onClick:e,type:"button",children:[i.jsx(fs,{}),s("database.addConnection")]}),i.jsxs(Q,{size:"sm",variant:"outline",onClick:t,type:"button",children:[i.jsx(zn,{}),s("database.addWithAi")]})]})]})})}const Qi=[{id:"general",label:"General",description:"Language, navigation, and startup context.",icon:O6,scope:"global",keywords:["language","sidebar","project scope"]},{id:"appearance",label:"Appearance",description:"Theme, density, type size, and motion.",icon:fE,scope:"global",keywords:["theme","dark","light","font","motion"]},{id:"terminal",label:"Terminal",description:"Terminal rendering and process safeguards.",icon:zr,scope:"global",keywords:["shell","cursor","scrollback","copy","terminate"]},{id:"services-logs",label:"Services & Logs",description:"How this project presents runtime output.",icon:Yf,scope:"project",keywords:["timestamps","wrap","runtime","services"]},{id:"git-github",label:"Git & GitHub",description:"Source-control preferences and connection status.",icon:Pn,scope:"mixed",keywords:["git","github","co-author","repository"]},{id:"agents-mcp",label:"Agents & MCP",description:"Agent environments and MCP management.",icon:Hf,scope:"mixed",keywords:["agent","model","mcp","claude","codex"]},{id:"database-safety",label:"Database & Safety",description:"Project query limits and write safeguards.",icon:ti,scope:"project",keywords:["database","sql","danger confirmation","writes","limit"]},{id:"notifications",label:"Notifications",description:"Browser notification capability and permission.",icon:tM,scope:"global",keywords:["alerts","desktop","permission"]},{id:"data-privacy",label:"Data & Privacy",description:"Local storage, export, reset, and privacy.",icon:bE,scope:"mixed",keywords:["data","privacy","export","reset","storage"]},{id:"about",label:"About",description:"Version, runtime, documentation, and support.",icon:M6,scope:"global",keywords:["version","docs","runtime","issues"]}],_A={language:{category:"general",label:"Language",description:"Choose the language preference for this console."},"sidebar-docked":{category:"general",label:"Dock sidebar",description:"Keep the navigation expanded while you work."},"project-scope":{category:"general",label:"Default project scope",description:"Choose whether Run pages open across every project or the selected project."},theme:{category:"appearance",label:"Theme",description:"Follow your system or choose an explicit dashboard theme."},density:{category:"appearance",label:"Interface density",description:"Adjust spacing throughout the control surface."},"code-font":{category:"appearance",label:"Code font size",description:"Size used by code and log surfaces."},"reduced-motion":{category:"appearance",label:"Reduced motion",description:"Reduce non-essential movement and animated transitions."},"terminal-font":{category:"terminal",label:"Terminal font size",description:"Text size for terminal sessions."},cursor:{category:"terminal",label:"Cursor style",description:"Shape of the active terminal cursor."},scrollback:{category:"terminal",label:"Scrollback limit",description:"Number of previous terminal lines kept in memory."},"copy-on-select":{category:"terminal",label:"Copy on select",description:"Copy selected terminal text to the clipboard."},"confirm-terminate":{category:"terminal",label:"Confirm before terminating",description:"Ask before closing, stopping, or restarting a running process. Danger confirmation."},"log-timestamps":{category:"services-logs",label:"Show timestamps",description:"Show the time gutter beside each log entry."},"wrap-lines":{category:"services-logs",label:"Wrap log lines",description:"Wrap long output instead of scrolling horizontally."},"github-connection":{category:"git-github",label:"GitHub connection",description:"Review the current GitHub connection without exposing credentials here."},"repository-defaults":{category:"git-github",label:"Repository defaults",description:"Repository-specific Git preferences will appear when their behavior is available."},"agent-environments":{category:"agents-mcp",label:"Agent environments",description:"Manage installed agents, MCP servers, skills, and profiles."},"project-agent-context":{category:"agents-mcp",label:"Project agent context",description:"Project-specific agent configuration remains in Agent Environments."},"confirm-writes":{category:"database-safety",label:"Confirm before writes",description:"Show a danger confirmation before write statements are submitted."},"result-limit":{category:"database-safety",label:"Default result limit",description:"Maximum rows requested for a default browse or query."},connections:{category:"database-safety",label:"Connections",description:"Manage connections and write access in the Database workbench."},"desktop-notifications":{category:"notifications",label:"Desktop notifications",description:"Shows whether desktop notifications are supported in this environment. Permission controls arrive with notification events."},"local-storage":{category:"data-privacy",label:"Local settings storage",description:"UI preferences stay in local browser storage; operational settings live in your NoMoreIDE config directory."},"export-reset":{category:"data-privacy",label:"Export and reset",description:"Export and reset controls are coming in a later delivery."},version:{category:"about",label:"Version",description:"Application version."},console:{category:"about",label:"Console",description:"Local runtime address."},documentation:{category:"about",label:"Documentation",description:"NoMoreIDE documentation and support."}};function BY(e){const t=_A[e];if(!t)throw new Error(`Missing settings copy for "${e}".`);return t}function wA(e){return`settingsHub.item.${e}.label`}function SA(e){return`settingsHub.item.${e}.desc`}function gu(e){return`settingsHub.cat.${e}.label`}function IY(e){return`settingsHub.cat.${e}.desc`}const HY=Object.keys(_A);function $Y(e,t,s){const n=kA(e),a=t.trim().toLowerCase().split(/\s+/).filter(Boolean);return HY.filter(l=>{const c=BY(l);if(c.category!==e)return!1;const d=s?` ${s(gu(e))} ${s(wA(l))} ${s(SA(l))}`:"",f=`${n.label} ${n.description} ${n.keywords.join(" ")} ${c.label} ${c.description}${d}`.toLowerCase();return a.every(h=>f.includes(h))})}function kA(e){return Qi.find(t=>t.id===e)??Qi[0]}function FY({scope:e}){const t=ee();return i.jsx("span",{className:oe("rounded-full border px-2 py-0.5 font-mono text-[10px] uppercase tracking-wide",e==="project"?"border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300":"border-border bg-muted/60 text-muted-foreground"),children:t(e==="project"?"settingsHub.currentProject":"settingsHub.global")})}function UY({state:e,error:t}){const s=ee();return e==="idle"?null:i.jsxs("div",{"aria-live":"polite",className:oe("flex items-center gap-1.5 text-xs",e==="error"?"text-destructive":"text-muted-foreground"),children:[e==="saving"?i.jsx(Lt,{className:"size-3.5 animate-spin"}):null,e==="saved"?i.jsx(Ys,{className:"size-3.5 text-emerald-600"}):null,e==="error"?i.jsx(Uf,{className:"size-3.5"}):null,i.jsx("span",{children:e==="saving"?s("settingsHub.saving"):e==="saved"?s("settingsHub.saved"):t})]})}function K0({id:e,label:t,description:s,children:n,disabled:a=!1}){return i.jsxs("div",{className:oe("settings-row grid gap-3 border-b border-border/50 px-4 last:border-b-0 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center",a&&"opacity-55"),children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("label",{className:"text-sm font-medium",htmlFor:e,children:t}),i.jsx("p",{className:"mt-0.5 max-w-xl text-xs leading-5 text-muted-foreground",id:`${e}-description`,children:s})]}),i.jsx("div",{className:"min-w-0 sm:justify-self-end",children:n})]})}function so({id:e,label:t,description:s,checked:n,onChange:a,disabled:l=!1}){return i.jsx(K0,{description:s,disabled:l,id:e,label:t,children:i.jsx("input",{"aria-describedby":`${e}-description`,checked:n,className:"size-4 accent-foreground",disabled:l,id:e,onChange:c=>a(c.target.checked),type:"checkbox"})})}function Uc({id:e,label:t,description:s,value:n,options:a,onChange:l,disabled:c=!1}){return i.jsx(K0,{description:s,disabled:c,id:e,label:t,children:i.jsx("select",{"aria-describedby":`${e}-description`,className:"h-8 min-w-36 rounded-md border border-input bg-background px-2 text-xs focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",disabled:c,id:e,onChange:d=>l(d.target.value),value:n,children:a.map(d=>i.jsx("option",{disabled:d.disabled,value:d.value,children:d.label},d.value))})})}function Ah({id:e,label:t,description:s,value:n,min:a,max:l,onSave:c,disabled:d=!1,scopeKey:f}){const h=ee(),{isPending:g,runOperation:p}=si(),[b,v]=x.useState(String(n)),[_,S]=x.useState(null),C=`settings:${f??"global"}:${e}:save`,N=g(C);x.useEffect(()=>{v(String(n)),S(null)},[f,n]);async function A(){const j=Number(b);if(!Number.isInteger(j)||j<a||j>l){S(h("settingsHub.numberRange",{min:a,max:l}));return}S(null);try{await p({key:C,label:h("settingsHub.savingSetting",{label:t})},async()=>c(j))}catch(E){S(E instanceof Error?E.message:String(E))}}return i.jsx(K0,{description:s,disabled:d,id:e,label:t,children:i.jsxs("div",{className:"flex flex-col items-start gap-1 sm:items-end",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(pt,{"aria-describedby":`${e}-description${_?` ${e}-error`:""}`,"aria-invalid":!!_,className:"h-8 w-24 font-mono text-xs",disabled:d,id:e,max:l,min:a,onChange:j=>v(j.target.value),type:"number",value:b}),i.jsx(Q,{"aria-label":h("settingsHub.saveAria",{label:t}),disabled:d,loading:N,loadingLabel:h("settingsHub.saving"),onClick:()=>{A()},size:"sm",type:"button",variant:"outline",children:h("settingsHub.save")})]}),_?i.jsx("span",{className:"text-[11px] text-destructive",id:`${e}-error`,role:"alert",children:_}):null]})})}function _a({title:e,description:t,action:s}){return i.jsxs("div",{className:"settings-row flex flex-col items-stretch justify-between gap-3 border-b border-border/50 px-4 last:border-b-0 sm:flex-row sm:items-center sm:gap-4",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:"text-sm font-medium",children:e}),i.jsx("p",{className:"mt-0.5 break-words text-xs leading-5 text-muted-foreground",children:t})]}),s?i.jsx("div",{className:"w-full shrink-0 [&_button]:w-full sm:w-auto sm:[&_button]:w-auto",children:s}):null]})}function qY({children:e}){return i.jsx("div",{className:"border border-dashed border-border bg-muted/30 px-4 py-3 text-xs leading-5 text-muted-foreground",children:e})}function GY({selected:e,onSelect:t,search:s,onSearch:n,saveState:a,saveError:l,children:c}){const d=ee(),f=x.useRef([]),h=kA(e),g=h.icon;function p(b,v){let _=null;if(b.key==="ArrowDown"&&(_=(v+1)%Qi.length),b.key==="ArrowUp"&&(_=(v-1+Qi.length)%Qi.length),b.key==="Home"&&(_=0),b.key==="End"&&(_=Qi.length-1),_===null)return;b.preventDefault();const S=Qi[_];t(S.id),f.current[_]?.focus()}return i.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[i.jsxs("header",{className:"flex shrink-0 flex-wrap items-center gap-3 border-b border-border px-3 py-2.5",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(gE,{className:"size-4 text-muted-foreground"}),i.jsx("span",{className:"text-sm font-semibold",children:d("settingsHub.title")})]}),i.jsxs("div",{className:"relative ml-auto w-full sm:w-64",children:[i.jsx(Wx,{className:"pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"}),i.jsx("input",{"aria-label":d("settingsHub.searchAria"),className:"h-8 w-full rounded-md border border-input bg-background pl-8 pr-8 text-xs outline-none focus:ring-2 focus:ring-ring",onChange:b=>n(b.target.value),placeholder:d("settingsHub.searchPlaceholder"),type:"search",value:s}),s?i.jsx("button",{"aria-label":d("settingsHub.clearSearch"),className:"absolute right-1.5 top-1/2 -translate-y-1/2 rounded p-1 text-muted-foreground hover:bg-muted",onClick:()=>n(""),type:"button",children:i.jsx(Vt,{className:"size-3"})}):null]}),i.jsx(UY,{error:l,state:a})]}),i.jsxs("div",{className:"border-b border-border px-3 py-2 md:hidden",children:[i.jsx("label",{className:"mb-1 block text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",htmlFor:"settings-category-select",children:d("settingsHub.category")}),i.jsx("select",{className:"h-9 w-full rounded-md border border-input bg-background px-2 text-sm",id:"settings-category-select",onChange:b=>t(b.target.value),value:e,children:Qi.map(b=>i.jsx("option",{value:b.id,children:d(gu(b.id))},b.id))})]}),i.jsxs("div",{className:"flex min-h-0 flex-1",children:[i.jsx("aside",{className:"hidden w-56 shrink-0 border-r border-border bg-muted/20 p-2 md:block",children:i.jsx("nav",{"aria-label":d("settingsHub.categoriesAria"),className:"space-y-0.5",children:Qi.map((b,v)=>{const _=b.icon,S=e===b.id;return i.jsxs("button",{"aria-current":S?"page":void 0,className:oe("flex w-full items-center gap-2 rounded-md px-2.5 py-2 text-left text-xs font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring",S?"bg-background text-foreground shadow-sm ring-1 ring-border":"text-muted-foreground hover:bg-muted hover:text-foreground"),onClick:()=>t(b.id),onKeyDown:C=>p(C,v),ref:C=>{f.current[v]=C},tabIndex:S?0:-1,type:"button",children:[i.jsx(_,{className:"size-3.5"}),i.jsx("span",{children:d(gu(b.id))})]},b.id)})})}),i.jsx("main",{className:"min-w-0 flex-1 overflow-y-auto",children:i.jsxs("div",{className:"mx-auto max-w-3xl px-3 py-4 sm:px-6 sm:py-6",children:[s?null:i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(g,{className:"size-4 text-muted-foreground"}),i.jsx("h2",{className:"text-base font-semibold",children:d(gu(h.id))})]}),i.jsx("p",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:d(IY(h.id))})]}),c]})})]})]})}function Xn({scope:e,title:t,children:s}){const n=ee();return i.jsxs("section",{className:"mb-4 overflow-hidden rounded-lg border border-border bg-background/70",children:[i.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border bg-muted/25 px-4 py-2.5",children:[i.jsx("h3",{className:"text-xs font-semibold",children:t??n(e==="global"?"settingsHub.global":"settingsHub.currentProject")}),i.jsx(FY,{scope:e})]}),s]})}function qc({project:e,ready:t,loadError:s,onRetry:n}){const a=ee();return e&&s?i.jsxs("div",{className:"border-b border-destructive/30 bg-destructive/5 px-4 py-3",role:"alert",children:[i.jsx("p",{className:"text-xs text-destructive",children:s}),i.jsx(Q,{"aria-label":a("settingsHub.retryProject"),className:"mt-2",onClick:n,size:"sm",type:"button",variant:"outline",children:a("settingsHub.retryProject")})]}):e&&!t?i.jsx("div",{className:"border-b border-border/50 bg-muted/30 px-4 py-2 text-xs text-muted-foreground",children:a("settingsHub.loadingProject",{name:e.name})}):e?i.jsxs("div",{className:"border-b border-border/50 bg-amber-500/5 px-4 py-2 text-[11px] text-muted-foreground",children:[i.jsx("span",{className:"font-medium text-foreground",children:e.name})," · ",a("settingsHub.projectWritesPre"),i.jsx("code",{children:"nomoreide.config.json"}),a("settingsHub.projectWritesPost")]}):i.jsx("div",{className:"border-b border-border/50 bg-muted/30 px-4 py-2 text-xs text-muted-foreground",children:a("settingsHub.selectProject")})}function VY({activeProject:e=null,onNavigate:t}={}){const s=ee(),n=bm(),a=!!(e?.path&&e.path===n.activeProjectPath&&!n.projectLoading&&!n.projectLoadError),[l,c]=x.useState("general"),[d,f]=x.useState(""),h=d.trim().toLowerCase(),g=x.useMemo(()=>h?Qi.map(b=>({id:b.id,settingIds:$Y(b.id,h,s)})).filter(b=>b.settingIds.length>0):[],[h,s]);let p;return n.loading?p=i.jsx("div",{"aria-label":s("settingsHub.loadingAria"),className:"space-y-3",role:"status",children:[0,1,2].map(b=>i.jsx("div",{className:"h-20 animate-pulse rounded-lg border border-border bg-muted/40"},b))}):n.loadError?p=i.jsxs("div",{className:"rounded-lg border border-destructive/30 bg-destructive/5 p-4",role:"alert",children:[i.jsx("p",{className:"text-sm font-medium",children:s("settingsHub.loadFailed")}),i.jsx("p",{className:"mt-1 text-xs text-destructive",children:n.loadError}),i.jsx(Q,{className:"mt-3",onClick:()=>{n.retry()},size:"sm",type:"button",variant:"outline",children:s("settingsHub.retry")})]}):h?p=i.jsxs("div",{children:[i.jsx("h2",{className:"mb-4 text-base font-semibold",children:s("settingsHub.searchResults")}),g.length?g.map(({id:b,settingIds:v})=>i.jsxs("div",{className:"mb-5",children:[i.jsx("div",{className:"mb-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:s(gu(b))}),i.jsx(vC,{activeProject:e,category:b,onNavigate:t,projectReady:a,settings:n,visibleSettingIds:new Set(v)})]},b)):i.jsx(qY,{children:s("settingsHub.noMatches",{query:d.trim()})})]}):p=i.jsx(vC,{activeProject:e,category:l,onNavigate:t,projectReady:a,settings:n}),i.jsx(GY,{onSearch:f,onSelect:c,saveError:n.saveError,saveState:n.saveState,search:d,selected:l,children:p})}function vC({category:e,activeProject:t,projectReady:s,onNavigate:n,settings:a,visibleSettingIds:l}){const c=ee(),d=!s,f=p=>!l||l.has(p),h=p=>p.some(f),g=p=>({label:c(wA(p)),description:c(SA(p))});switch(e){case"general":return i.jsxs(Xn,{scope:"global",children:[f("language")?i.jsx(Uc,{...g("language"),id:"setting-language",onChange:p=>a.updateUi({language:p}),options:L$.map(p=>({value:p.value,label:p.nativeLabel,disabled:!p.available})),value:a.ui.language}):null,f("sidebar-docked")?i.jsx(so,{...g("sidebar-docked"),checked:a.ui.sidebarDocked,id:"setting-sidebar-docked",onChange:p=>a.updateUi({sidebarDocked:p})}):null,f("project-scope")?i.jsx(Uc,{...g("project-scope"),id:"setting-project-scope",onChange:p=>a.updateUi({projectScope:p}),options:[{value:"all",label:c("settingsHub.opt.allProjects")},{value:"project",label:c("settingsHub.currentProject")}],value:a.ui.projectScope}):null]});case"appearance":return i.jsxs(Xn,{scope:"global",children:[f("theme")?i.jsx(Uc,{...g("theme"),id:"setting-theme",onChange:p=>a.updateUi({theme:p}),options:[{value:"system",label:c("settingsHub.opt.system")},{value:"light",label:c("settingsHub.opt.light")},{value:"dark",label:c("settingsHub.opt.dark")}],value:a.ui.theme}):null,f("density")?i.jsx(Uc,{...g("density"),id:"setting-density",onChange:p=>a.updateUi({density:p}),options:[{value:"comfortable",label:c("settingsHub.opt.comfortable")},{value:"compact",label:c("settingsHub.opt.compact")}],value:a.ui.density}):null,f("code-font")?i.jsx(Ah,{...g("code-font"),id:"setting-code-font",max:18,min:10,onSave:p=>{a.updateUi({codeFontSize:p})},value:a.ui.codeFontSize}):null,f("reduced-motion")?i.jsx(so,{...g("reduced-motion"),checked:a.ui.reducedMotion,id:"setting-reduced-motion",onChange:p=>a.updateUi({reducedMotion:p})}):null]});case"terminal":return i.jsxs(Xn,{scope:"global",children:[f("terminal-font")?i.jsx(Ah,{...g("terminal-font"),id:"setting-terminal-font",max:24,min:10,onSave:p=>a.updateGlobal({terminal:{fontSize:p}}),value:a.global.terminal.fontSize}):null,f("cursor")?i.jsx(Uc,{...g("cursor"),id:"setting-cursor",onChange:p=>{a.updateGlobal({terminal:{cursorStyle:p}})},options:[{value:"block",label:c("settingsHub.opt.block")},{value:"underline",label:c("settingsHub.opt.underline")},{value:"bar",label:c("settingsHub.opt.bar")}],value:a.global.terminal.cursorStyle}):null,f("scrollback")?i.jsx(Ah,{...g("scrollback"),id:"setting-scrollback",max:1e5,min:500,onSave:p=>a.updateGlobal({terminal:{scrollback:p}}),value:a.global.terminal.scrollback}):null,f("copy-on-select")?i.jsx(so,{...g("copy-on-select"),checked:a.global.terminal.copyOnSelect,id:"setting-copy-on-select",onChange:p=>{a.updateGlobal({terminal:{copyOnSelect:p}})}}):null,f("confirm-terminate")?i.jsx(so,{...g("confirm-terminate"),checked:a.global.terminal.confirmTerminate,id:"setting-confirm-terminate",onChange:p=>{a.updateGlobal({terminal:{confirmTerminate:p}})}}):null]});case"services-logs":return i.jsxs(Xn,{scope:"project",children:[i.jsx(qc,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),f("log-timestamps")?i.jsx(so,{...g("log-timestamps"),checked:a.project.logs.showTimestamps,disabled:d,id:"setting-log-timestamps",onChange:p=>{a.updateProject({logs:{showTimestamps:p}})}}):null,f("wrap-lines")?i.jsx(so,{...g("wrap-lines"),checked:a.project.logs.wrapLines,disabled:d,id:"setting-wrap-lines",onChange:p=>{a.updateProject({logs:{wrapLines:p}})}}):null]});case"git-github":return i.jsxs(i.Fragment,{children:[h(["github-connection"])?i.jsx(Xn,{scope:"global",children:i.jsx(_a,{action:i.jsx(Q,{onClick:()=>n?.("github"),size:"sm",type:"button",variant:"outline",children:c("settingsHub.manageGitHub")}),description:g("github-connection").description,title:g("github-connection").label})}):null,h(["repository-defaults"])?i.jsxs(Xn,{scope:"project",children:[i.jsx(qc,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),i.jsx(_a,{description:g("repository-defaults").description,title:g("repository-defaults").label})]}):null]});case"agents-mcp":return i.jsxs(i.Fragment,{children:[h(["agent-environments"])?i.jsx(Xn,{scope:"global",children:i.jsx(_a,{action:i.jsx(Q,{onClick:()=>n?.("agent-env"),size:"sm",type:"button",variant:"outline",children:c("settingsHub.openAgentEnv")}),description:g("agent-environments").description,title:g("agent-environments").label})}):null,h(["project-agent-context"])?i.jsxs(Xn,{scope:"project",children:[i.jsx(qc,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),i.jsx(_a,{description:g("project-agent-context").description,title:g("project-agent-context").label})]}):null]});case"database-safety":return i.jsxs(Xn,{scope:"project",children:[i.jsx(qc,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),f("confirm-writes")?i.jsx(so,{...g("confirm-writes"),checked:a.project.database.confirmWrites,disabled:d,id:"setting-confirm-writes",onChange:p=>{a.updateProject({database:{confirmWrites:p}})}}):null,f("result-limit")?i.jsx(Ah,{...g("result-limit"),disabled:d,id:"setting-result-limit",max:5e3,min:10,onSave:p=>a.updateProject({database:{resultLimit:p}}),scopeKey:a.activeProjectPath,value:a.project.database.resultLimit}):null,f("connections")?i.jsx(_a,{action:i.jsx(Q,{disabled:d,onClick:()=>n?.("database"),size:"sm",type:"button",variant:"outline",children:c("settingsHub.openDatabase")}),description:g("connections").description,title:g("connections").label}):null]});case"notifications":{const p=typeof Notification>"u"?c("settingsHub.notifUnavailable"):c("settingsHub.notifPermission",{value:Notification.permission});return i.jsx(Xn,{scope:"global",children:f("desktop-notifications")?i.jsx(_a,{action:i.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:p}),description:g("desktop-notifications").description,title:g("desktop-notifications").label}):null})}case"data-privacy":return i.jsxs(i.Fragment,{children:[h(["local-storage"])?i.jsx(Xn,{scope:"global",children:i.jsx(_a,{description:g("local-storage").description,title:g("local-storage").label})}):null,h(["export-reset"])?i.jsxs(Xn,{scope:"project",children:[i.jsx(qc,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),i.jsx(_a,{description:g("export-reset").description,title:g("export-reset").label})]}):null]});case"about":return i.jsx(Xn,{scope:"global",children:i.jsxs("div",{className:"grid grid-cols-[auto_1fr] gap-x-5 gap-y-2 px-4 py-4 text-xs",children:[f("version")?i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-muted-foreground",children:g("version").label}),i.jsxs("code",{children:["v","0.1.84"]})]}):null,f("console")?i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-muted-foreground",children:g("console").label}),i.jsx("code",{children:"127.0.0.1:4317"})]}):null,f("documentation")?i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-muted-foreground",children:g("documentation").label}),i.jsxs("a",{className:"inline-flex items-center gap-1 text-primary hover:underline",href:"https://www.nomoreide.com/docs",rel:"noreferrer",target:"_blank",children:[i.jsx(QN,{className:"size-3"}),"nomoreide.com/docs",i.jsx(ja,{className:"size-3"})]})]}):null]})})}}function WY(e,t){const s=t.trim().toLocaleLowerCase();return s?[e.service,e.title,e.file??"",...e.logExcerpt].some(n=>n.toLocaleLowerCase().includes(s)):!0}function KY(e,t,s){const n=new Set(s.levels),a=new Set(s.services);return e.filter(l=>WY(l,t)&&(n.size===0||n.has(l.level))&&(a.size===0||a.has(l.service)))}function YY(e){return{levels:[...new Set(e.map(({level:t})=>t))].sort(),services:[...new Set(e.map(({service:t})=>t))].sort()}}function XY(e){return e.levels.length+e.services.length}function ZY({detailId:e,incident:t,onReviewChanges:s}){const n=ee(),{sendToAgent:a}=Ot(),{isPending:l,runOperation:c}=si(),d=`error:${t.id}:fix`,f=l(d),[h,g]=x.useState(null);async function p(){await c({errorMessage:b=>b instanceof Error?b.message:String(b),key:d,label:n("errors.incident.fixingOperation",{service:t.service})},async()=>{const{prompt:b,sessionId:v}=await XO(t.id);a({prompt:b,source:{type:"error",label:`${t.service} — ${t.level}`},label:n("errors.incident.fixLabel",{level:t.level,service:t.service,title:t.title})}),g(v)})}return i.jsxs("div",{className:"min-w-0 rounded-lg border border-border bg-background","data-incident-detail":"true",id:e,children:[i.jsxs("div",{className:"px-4 py-3",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(Ke,{variant:t.level==="error"?"danger":"secondary",appearance:"subtle",size:"small",children:n(t.level==="error"?"errors.level.error":"errors.level.warning")}),i.jsx("span",{className:"truncate font-mono text-xs font-semibold",children:t.service}),t.count>1?i.jsxs(Ke,{variant:"outline",size:"small",children:["×",t.count]}):null]}),i.jsxs(Q,{loading:f,loadingLabel:n("errors.incident.starting"),onClick:()=>{p().catch(()=>{})},size:"sm",variant:"outline",children:[i.jsx(Xt,{className:"size-3.5"}),n("errors.incident.fixWithAi")]})]}),i.jsx("p",{className:"mt-1.5 break-words font-mono text-xs text-foreground",children:t.title}),t.file?i.jsxs("p",{className:"mt-1 flex items-center gap-1.5 font-mono text-[11px] text-muted-foreground",children:[i.jsx(aE,{className:"size-3.5"}),t.file,t.line?`:${t.line}`:""]}):null,i.jsx("p",{className:"mt-1 font-mono text-[10px] text-muted-foreground/80",children:n("errors.incident.firstLast",{first:new Date(t.firstSeen).toLocaleString(),last:new Date(t.lastSeen).toLocaleTimeString()})})]}),i.jsxs("div",{className:"border-t border-border p-4",children:[h?i.jsx(tt,{variant:"muted",className:"mb-3",children:i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[i.jsx("span",{className:"text-xs",children:n("errors.incident.working")}),s?i.jsxs(Q,{onClick:()=>s(h),size:"sm",variant:"outline",children:[i.jsx(rE,{className:"size-3.5"}),n("errors.incident.reviewChanges")]}):null]})}):null,i.jsx("p",{className:"mb-1.5 text-xs font-medium text-muted-foreground",children:n("errors.incident.logExcerpt")}),i.jsx("pre",{className:"overflow-x-auto rounded-md border border-border bg-muted/40 p-3 font-mono text-[11px] leading-relaxed",children:t.logExcerpt.join(`
|
|
118
|
+
${c.map(v=>b(p[v])).join(",")}`}function g(p){const b=_=>_==null?"NULL":typeof _=="number"||typeof _=="boolean"?String(_):`'${(typeof _=="object"?JSON.stringify(_):String(_)).replace(/'/g,"''")}'`,v=c.map(_=>b(p[_])).join(", ");return`INSERT INTO ${t.table} (${c.join(", ")}) VALUES (${v});`}return t.columns.length===0?i.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:s("database.grid.noColumnsTable")}):i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:i.jsxs("table",{className:"code-font-size w-max min-w-full border-collapse text-left font-mono",children:[i.jsx("thead",{className:"sticky top-0 z-10 bg-card",children:i.jsxs("tr",{className:"border-b border-border",children:[t.columns.map(p=>i.jsxs("th",{className:"whitespace-nowrap px-3 py-2 font-semibold text-foreground",children:[i.jsxs("span",{className:"flex items-center gap-1",children:[p.primaryKey?i.jsx(uE,{className:"size-3 text-amber-500"}):null,p.name]}),i.jsx("span",{className:"block font-normal text-muted-foreground",children:p.dataType})]},p.name)),i.jsx("th",{className:"sticky right-0 z-20 w-16 border-l border-border bg-card px-2 py-2"})]})}),i.jsxs("tbody",{children:[t.rows.map((p,b)=>i.jsxs("tr",{className:"group border-b border-border/60 hover:bg-muted/40",children:[t.columns.map(v=>i.jsx("td",{className:"max-w-[320px] truncate px-3 py-1 align-top text-muted-foreground",title:pu(p[v.name]),children:pu(p[v.name])},v.name)),i.jsx("td",{className:"sticky right-0 z-[1] border-l border-border/60 bg-card px-2 py-1 align-top before:pointer-events-none before:absolute before:inset-0 before:bg-muted/40 before:opacity-0 group-hover:before:opacity-100",children:i.jsxs("div",{className:"relative z-[1] flex items-center justify-end gap-0.5",children:[i.jsx(ir,{label:s("database.grid.askAiRow"),onAsk:()=>d(p)}),i.jsx(Ll,{label:s("database.grid.rowActions"),items:[{label:s("database.grid.copyJson"),icon:i.jsx(lM,{className:"size-3.5"}),onSelect:()=>{f(JSON.stringify(p,null,2),s("database.grid.rowAsJson"))}},{label:s("database.grid.copyCsv"),icon:i.jsx(JM,{className:"size-3.5"}),onSelect:()=>{f(h(p),s("database.grid.rowAsCsv"))}},{label:s("database.grid.copySqlInsert"),icon:i.jsx(ti,{className:"size-3.5"}),onSelect:()=>{f(g(p),s("database.grid.insertStatement"))}}]})]})})]},b)),t.rows.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:t.columns.length+1,className:"px-3 py-6 text-center text-muted-foreground",children:s("database.grid.noRows")})}):null]})]})})}function pu(e){return e==null?"NULL":typeof e=="object"?JSON.stringify(e):String(e)}function EY({connection:e,busy:t,onConfirm:s,onClose:n}){const a=ee();return i.jsx(ei,{icon:i.jsx(WD,{className:"text-amber-500"}),onClose:n,title:a("database.write.unlockTitle",{connection:e}),children:i.jsxs("div",{className:"flex flex-col gap-4 text-sm",children:[i.jsx("p",{className:"text-muted-foreground",children:a("database.write.unlockBody1")}),i.jsx("p",{className:"text-muted-foreground",children:a("database.write.unlockBody2")}),i.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border pt-3",children:[i.jsx(Q,{variant:"outline",size:"sm",onClick:n,type:"button",children:a("common.cancel")}),i.jsxs(Q,{size:"sm",onClick:s,disabled:t,type:"button",children:[t?i.jsx(Lt,{className:"animate-spin"}):i.jsx(dE,{}),a("database.write.unlockWrites")]})]})]})})}function jY({sql:e,preview:t,busy:s,onConfirm:n,onClose:a}){const l=ee();return i.jsx(ei,{icon:i.jsx(Lr,{className:"text-amber-500"}),onClose:a,title:l("database.write.confirmTitle"),children:i.jsxs("div",{className:"flex flex-col gap-4 text-sm",children:[i.jsx("pre",{className:"max-h-40 overflow-auto rounded-md border border-border bg-muted/40 px-3 py-2 font-mono text-[11px] whitespace-pre-wrap",children:e}),t.previewUnavailable?i.jsx("p",{className:"rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[13px] text-amber-700 dark:text-amber-300",children:l("database.write.previewUnavailable")}):i.jsxs("p",{className:"text-muted-foreground",children:[l("database.write.willAffectPre")," ",i.jsx("strong",{className:"text-foreground tabular-nums",children:t.affectedRows??0})," ",l("database.write.willAffectPost")]}),i.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border pt-3",children:[i.jsx(Q,{variant:"outline",size:"sm",onClick:a,type:"button",children:l("common.cancel")}),i.jsxs(Q,{size:"sm",className:"bg-amber-600 text-white hover:bg-amber-600/90",onClick:n,disabled:s,type:"button",children:[s?i.jsx(Lt,{className:"animate-spin"}):null,l("database.write.runCommit")]})]})]})})}function AY({connection:e,engine:t,unlocked:s,seed:n,onWriteAccessChange:a,preferences:l={confirmWrites:!0,resultLimit:100}}){const c=ee(),{isPending:d,runOperation:f}=si(),{success:h}=ms(),{sendToAgent:g}=Ot(),p=vY(e),b=_Y(e),v=wY(e,a),[_,S]=x.useState(n?.sql??""),[C,N]=x.useState(()=>l.resultLimit),A=x.useRef(!1);x.useEffect(()=>{A.current||N(l.resultLimit)},[l.resultLimit]);const j=n?.nonce;x.useEffect(()=>{n&&S(n.sql)},[j]);const[E,T]=x.useState(!1),L=kY(e,t,s,S),H=_.trim().length>0&&!yY(_),P=s&&H,F=H&&!s,M=p.running||b.previewing||b.committing,z=`database:${e}:write`,G=d(z);function D(){if(_.trim()){if(F){T(!0);return}P?(p.reset(),l.confirmWrites?b.preview(_):I(_)):(b.reset(),p.run(_,C))}}function q(Y){(Y.metaKey||Y.ctrlKey)&&Y.key==="Enter"&&(Y.preventDefault(),D())}function W(Y){g({prompt:EF(e,t,_,Y),source:{type:"database-sql-debug",label:"Debug SQL"},label:c("database.sql.debugLabel")})}async function I(Y){const $=await f({key:z,label:c("database.sql.committingWrite",{connection:e})},()=>b.commit(Y));if($?.committed){const me=$.affectedRows??0;h(c("database.sql.committed",{count:me}))}}return i.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[i.jsxs("div",{className:"shrink-0 border-b border-border p-2",children:[i.jsx(TY,{generate:L}),i.jsx("textarea",{value:_,onChange:Y=>S(Y.target.value),onKeyDown:q,spellCheck:!1,placeholder:c(s?"database.sql.placeholderUnlocked":"database.sql.placeholderLocked"),className:"code-font-size h-24 w-full resize-y rounded-md border border-border bg-background px-2 py-1.5 font-mono outline-none focus:border-ring"}),i.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[i.jsx(RY,{unlocked:s,updating:v.updating,onUnlock:()=>T(!0),onLock:()=>{v.setUnlocked(!1)}}),i.jsxs("div",{className:"flex items-center gap-2",children:[P?null:i.jsx("select",{"aria-label":c("database.sql.maxRows"),className:"rounded-md border border-border bg-background px-1.5 py-1 text-[11px]",value:C,onChange:Y=>{A.current=!0,N(Number(Y.target.value))},children:xA(l.resultLimit).map(Y=>i.jsx("option",{value:Y,children:c("database.sql.rowsOption",{size:Y})},Y))}),i.jsxs(Q,{size:"sm",className:oe("h-7 px-3",P&&"bg-amber-600 text-white hover:bg-amber-600/90"),onClick:D,disabled:M||!_.trim(),loading:P&&G,loadingLabel:c("database.sql.runWrite"),type:"button",children:[M?i.jsx(Lt,{className:"size-3.5 animate-spin"}):i.jsx(Or,{className:"size-3.5"}),P?l.confirmWrites?c("database.sql.previewWrite"):c("database.sql.runWrite"):c("database.sql.run")]})]})]})]}),i.jsx(MY,{read:p,write:b,onDebug:W}),E?i.jsx(EY,{connection:e,busy:v.updating,onConfirm:async()=>{await v.setUnlocked(!0),T(!1)},onClose:()=>T(!1)}):null,b.pending?i.jsx(jY,{sql:b.pending.sql,preview:b.pending.preview,busy:b.committing,onConfirm:()=>{I()},onClose:b.cancel}):null]})}function TY({generate:e}){const t=ee(),[s,n]=x.useState("");function a(){const c=s.trim();!c||e.generating||e.generate(c)}function l(c){c.key==="Enter"&&(c.preventDefault(),a())}return i.jsxs("div",{className:"mb-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx(Xt,{className:"pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2"}),i.jsx("input",{value:s,onChange:c=>n(c.target.value),onKeyDown:l,disabled:e.generating,placeholder:t("database.sql.generatePlaceholder"),className:"h-8 w-full rounded-md border border-border bg-background pl-7 pr-2 text-[12px] outline-none focus:border-ring disabled:opacity-60"})]}),i.jsxs(Q,{size:"sm",variant:"outline",className:"h-8 px-3",onClick:a,disabled:e.generating||!s.trim(),type:"button",children:[e.generating?i.jsx(Lt,{className:"size-3.5 animate-spin"}):i.jsx(Xt,{className:"size-3.5"}),e.generating?t("database.sql.generating"):t("database.sql.askAi")]})]}),e.error?i.jsx("p",{className:"mt-1 text-[11px] text-amber-600 dark:text-amber-400",children:e.error}):null]})}function RY({unlocked:e,updating:t,onUnlock:s,onLock:n}){const a=ee();return i.jsxs("button",{type:"button",onClick:e?n:s,disabled:t,className:oe("flex items-center gap-1.5 rounded-md border px-2 py-1 text-[11px] font-medium transition-colors",e?"border-amber-500/50 text-amber-600 hover:bg-amber-500/10 dark:text-amber-400":"border-border text-muted-foreground hover:text-foreground"),title:a(e?"database.sql.writesUnlockedTitle":"database.sql.readOnlyTitle"),children:[t?i.jsx(Lt,{className:"size-3.5 animate-spin"}):e?i.jsx(dE,{className:"size-3.5"}):i.jsx(X6,{className:"size-3.5"}),a(e?"database.sql.writesUnlocked":"database.sql.readOnly")]})}function MY({read:e,write:t,onDebug:s}){const n=ee(),a=t.error??e.error;return i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:a?i.jsxs("div",{className:"space-y-3 p-4",children:[i.jsx("p",{className:"code-font-size whitespace-pre-wrap font-mono text-destructive",children:a}),i.jsxs(Q,{size:"sm",variant:"outline",className:"h-7 px-3",onClick:()=>s(a),type:"button",children:[i.jsx(Xt,{className:"size-3.5"}),n("database.sql.debugWithAi")]})]}):t.committed?i.jsx(DY,{outcome:t.committed}):e.result?i.jsx(yA,{columns:e.result.columns,rows:e.result.rows,truncated:e.result.truncated}):i.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center text-sm text-muted-foreground",children:n("database.sql.emptyResult")})})}function DY({outcome:e}){const t=ee();if(!e)return null;const s=e.affectedRows??0;return i.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[i.jsxs("div",{className:"flex shrink-0 items-center gap-1.5 border-b border-border bg-emerald-500/10 px-3 py-1.5 text-[12px] text-emerald-700 dark:text-emerald-400",children:[i.jsx(Ys,{className:"size-3.5"}),t("database.sql.committed",{count:s})]}),e.rows&&e.rows.length>0&&e.columns?i.jsx(yA,{columns:e.columns,rows:e.rows}):null]})}function yA({columns:e,rows:t,truncated:s=!1}){const n=ee();return e.length===0?i.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:n("database.sql.noColumns")}):i.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[s?i.jsxs("div",{className:"flex shrink-0 items-center gap-1.5 border-b border-border bg-amber-500/10 px-3 py-1.5 text-[11px] text-amber-600 dark:text-amber-400",children:[i.jsx(Lr,{className:"size-3.5"}),n("database.sql.truncated",{count:t.length})]}):null,i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:i.jsxs("table",{className:"code-font-size w-max min-w-full border-collapse text-left font-mono",children:[i.jsx("thead",{className:"sticky top-0 z-10 bg-card",children:i.jsx("tr",{className:"border-b border-border",children:e.map(a=>i.jsx("th",{className:"whitespace-nowrap px-3 py-2 font-semibold text-foreground",children:a.name},a.name))})}),i.jsxs("tbody",{children:[t.map((a,l)=>i.jsx("tr",{className:"border-b border-border/60 hover:bg-muted/40",children:e.map(c=>i.jsx("td",{className:"max-w-[320px] truncate px-3 py-1 align-top text-muted-foreground",title:pu(a[c.name]),children:pu(a[c.name])},c.name))},l)),t.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:e.length,className:"px-3 py-6 text-center text-muted-foreground",children:n("database.grid.noRows")})}):null]})]})})]})}function LY({staged:e,onStageConsumed:t,projects:s=[],scopePath:n=null}={}){const a=ee(),c=vm()?.confirmedProject.database??{confirmWrites:!0,resultLimit:100},{connections:d,loading:f,error:h,refresh:g}=gY(),p=x.useMemo(()=>d.filter(z=>aY(z.projectPath,n)),[d,n]),b=z=>z.projectPath?s.find(D=>xm(z.projectPath,D.path))?.name??z.projectPath.split("/").pop()??null:null;Dl(g);const{error:v,success:_}=ms(),{sendToAgent:S}=Ot(),[C,N]=_l("database:selected",null),[A,j]=_l("database:mode","browse"),[E,T]=x.useState(null),[L,H]=x.useState(null);x.useEffect(()=>{e&&(e.connection&&N(e.connection),j("query"),H({sql:e.sql,nonce:e.nonce}),t?.())},[e?.nonce]);function P(){S({prompt:wF,source:{type:"database-setup",label:"Add a database"},label:"Help me connect a database, one step at a time."})}x.useEffect(()=>{if(p.length===0){C!==null&&N(null);return}(!C||!p.some(z=>z.name===C))&&N(p[0].name)},[p,C,N]);async function F(z){try{await qO(z),_(a("database.toast.removed",{name:z})),await g()}catch(G){v(G instanceof Error?G.message:String(G))}}function M(z){T({mode:"edit",target:z})}return i.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[i.jsxs("header",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(ti,{className:"size-4 text-muted-foreground"}),i.jsx("span",{className:"text-sm font-semibold",children:a("database.title")}),f&&p.length===0?i.jsx(Lt,{className:"size-3.5 animate-spin text-muted-foreground"}):null]}),i.jsxs("div",{className:"flex items-center gap-2",children:[C?i.jsx(OY,{mode:A,onChange:j}):null,i.jsx(mY,{connections:p,projectLabel:b,selected:C,onSelect:N,onAdd:()=>T({mode:"add"}),onEdit:M,onRemove:z=>{F(z)}}),i.jsx(pY,{onAddManual:()=>T({mode:"add"}),onAddWithAi:P})]})]}),i.jsx("div",{className:"min-h-0 flex-1",children:h?i.jsx("div",{className:"p-4",children:i.jsx(tt,{variant:"muted",className:"border-destructive/40 text-destructive",children:h})}):C?A==="query"?i.jsx(AY,{connection:C,engine:p.find(z=>z.name===C)?.engine,unlocked:p.find(z=>z.name===C)?.writeUnlocked??!1,seed:L,onWriteAccessChange:g,preferences:c},C):i.jsx(PY,{connection:C,resultLimit:c.resultLimit}):i.jsx(zY,{onAdd:()=>T({mode:"add"}),onAddWithAi:P})}),E?i.jsx(dY,{initial:E.mode==="edit"?E.target:void 0,projects:s,onClose:()=>T(null),onSaved:g}):null]})}function OY({mode:e,onChange:t}){const s=ee(),n=[{value:"browse",label:s("database.browse"),icon:yE},{value:"query",label:s("database.sql"),icon:Al}];return i.jsx("div",{className:"flex items-center rounded-md border border-border p-0.5",children:n.map(a=>{const l=a.icon;return i.jsxs("button",{type:"button",onClick:()=>t(a.value),className:oe("flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium transition-colors",e===a.value?"bg-muted text-foreground":"text-muted-foreground hover:text-foreground"),children:[i.jsx(l,{className:"size-3.5"}),a.label]},a.value)})})}function PY({connection:e,resultLimit:t}){const s=ee(),{sendToAgent:n}=Ot(),{tables:a,selectedTable:l,setSelectedTable:c,sample:d,tablesError:f,rowsError:h,loadingTables:g,loadingRows:p,limit:b,offset:v,canPrev:_,canNext:S,changePageSize:C,nextPage:N,prevPage:A}=SY(e,t);function j(T){n({prompt:Zk(e,T.table,{engine:T.engine,columns:T.columns}),source:{type:"database-table",label:`${T.table.name} table`},mode:"draft"})}function E(T){n({prompt:Zk(e,T),source:{type:"database-table",label:`${T.name} table`},mode:"draft"})}return i.jsxs("div",{className:"flex h-full min-h-0",children:[i.jsxs("div",{className:"flex w-56 shrink-0 flex-col border-r border-border",children:[i.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[i.jsx(yE,{className:"size-4 text-muted-foreground"}),i.jsx("span",{className:"text-sm font-semibold",children:s("database.tables")}),i.jsx(Ke,{variant:"outline",size:"small",children:a.length}),g?i.jsx(Lt,{className:"size-3.5 animate-spin"}):null]}),f?i.jsx("div",{className:"p-3",children:i.jsx(tt,{variant:"muted",className:"border-destructive/40 text-destructive",children:f})}):i.jsxs("ul",{className:"min-h-0 flex-1 overflow-auto",children:[a.map(T=>i.jsxs("li",{className:oe("group flex items-center gap-1 pr-1 transition-colors hover:bg-muted/50",T.qualifiedName===l&&"bg-muted/70"),children:[i.jsx("button",{type:"button",onClick:()=>c(T.qualifiedName),className:oe("min-w-0 flex-1 truncate px-3 py-1.5 text-left font-mono text-[11px]",T.qualifiedName===l&&"font-semibold"),children:T.qualifiedName}),i.jsx(ir,{label:s("database.askAiAbout",{name:T.qualifiedName}),onAsk:()=>E(T)})]},T.qualifiedName)),!g&&a.length===0?i.jsx("li",{className:"px-3 py-2 text-xs text-muted-foreground",children:s("database.noTables")}):null]})]}),i.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[i.jsxs("div",{className:"group flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-2",children:[i.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[i.jsx("span",{className:"truncate font-mono text-xs font-semibold",children:l??s("database.selectTable")}),d?i.jsx(ir,{label:s("database.askAiAbout",{name:d.table.qualifiedName}),onAsk:()=>j(d)}):null]}),d?i.jsxs("div",{className:"flex shrink-0 items-center gap-2 text-[11px] text-muted-foreground",children:[i.jsx("span",{className:"tabular-nums",children:d.rowCount===0?s("database.noRows"):s("database.rowsRange",{from:v+1,to:v+d.rowCount})}),i.jsx("select",{"aria-label":s("database.rowsPerPage"),className:"rounded-md border border-border bg-background px-1.5 py-0.5 text-[11px]",value:b,onChange:T=>C(Number(T.target.value)),children:xA(t).map(T=>i.jsx("option",{value:T,children:s("database.perPage",{size:T})},T))}),i.jsx(Q,{size:"sm",variant:"outline",className:"h-6 px-2",onClick:A,disabled:!_,type:"button",children:s("database.prev")}),i.jsx(Q,{size:"sm",variant:"outline",className:"h-6 px-2",onClick:N,disabled:!S,type:"button",children:s("database.next")})]}):null]}),h?i.jsx("div",{className:"p-4",children:i.jsx(tt,{variant:"muted",className:"border-destructive/40 text-destructive",children:h})}):p?i.jsxs("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:[i.jsx(Lt,{className:"mr-2 size-4 animate-spin"}),s("database.loadingRows")]}):d?i.jsx(NY,{connection:e,sample:d}):i.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:s("database.pickTable")})]})]})}function zY({onAdd:e,onAddWithAi:t}){const s=ee();return i.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center",children:i.jsxs("div",{className:"max-w-sm",children:[i.jsx(ti,{className:"mx-auto size-8 text-muted-foreground/50"}),i.jsx("p",{className:"mt-3 text-sm font-medium",children:s("database.emptyTitle")}),i.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:[s("database.emptyBody1")," ",i.jsx("code",{children:".env"})," ",s("database.emptyBody2")]}),i.jsxs("div",{className:"mt-4 flex items-center justify-center gap-2",children:[i.jsxs(Q,{size:"sm",onClick:e,type:"button",children:[i.jsx(fs,{}),s("database.addConnection")]}),i.jsxs(Q,{size:"sm",variant:"outline",onClick:t,type:"button",children:[i.jsx(zn,{}),s("database.addWithAi")]})]})]})})}const Qi=[{id:"general",label:"General",description:"Language, navigation, and startup context.",icon:O6,scope:"global",keywords:["language","sidebar","project scope"]},{id:"appearance",label:"Appearance",description:"Theme, density, type size, and motion.",icon:fE,scope:"global",keywords:["theme","dark","light","font","motion"]},{id:"terminal",label:"Terminal",description:"Terminal rendering and process safeguards.",icon:zr,scope:"global",keywords:["shell","cursor","scrollback","copy","terminate"]},{id:"services-logs",label:"Services & Logs",description:"How this project presents runtime output.",icon:Yf,scope:"project",keywords:["timestamps","wrap","runtime","services"]},{id:"git-github",label:"Git & GitHub",description:"Source-control preferences and connection status.",icon:Pn,scope:"mixed",keywords:["git","github","co-author","repository"]},{id:"agents-mcp",label:"Agents & MCP",description:"Agent environments and MCP management.",icon:Hf,scope:"mixed",keywords:["agent","model","mcp","claude","codex"]},{id:"database-safety",label:"Database & Safety",description:"Project query limits and write safeguards.",icon:ti,scope:"project",keywords:["database","sql","danger confirmation","writes","limit"]},{id:"notifications",label:"Notifications",description:"Browser notification capability and permission.",icon:tM,scope:"global",keywords:["alerts","desktop","permission"]},{id:"data-privacy",label:"Data & Privacy",description:"Local storage, export, reset, and privacy.",icon:bE,scope:"mixed",keywords:["data","privacy","export","reset","storage"]},{id:"about",label:"About",description:"Version, runtime, documentation, and support.",icon:M6,scope:"global",keywords:["version","docs","runtime","issues"]}],_A={language:{category:"general",label:"Language",description:"Choose the language preference for this console."},"sidebar-docked":{category:"general",label:"Dock sidebar",description:"Keep the navigation expanded while you work."},"project-scope":{category:"general",label:"Default project scope",description:"Choose whether Run pages open across every project or the selected project."},theme:{category:"appearance",label:"Theme",description:"Follow your system or choose an explicit dashboard theme."},density:{category:"appearance",label:"Interface density",description:"Adjust spacing throughout the control surface."},"code-font":{category:"appearance",label:"Code font size",description:"Size used by code and log surfaces."},"reduced-motion":{category:"appearance",label:"Reduced motion",description:"Reduce non-essential movement and animated transitions."},"terminal-font":{category:"terminal",label:"Terminal font size",description:"Text size for terminal sessions."},cursor:{category:"terminal",label:"Cursor style",description:"Shape of the active terminal cursor."},scrollback:{category:"terminal",label:"Scrollback limit",description:"Number of previous terminal lines kept in memory."},"copy-on-select":{category:"terminal",label:"Copy on select",description:"Copy selected terminal text to the clipboard."},"confirm-terminate":{category:"terminal",label:"Confirm before terminating",description:"Ask before closing, stopping, or restarting a running process. Danger confirmation."},"log-timestamps":{category:"services-logs",label:"Show timestamps",description:"Show the time gutter beside each log entry."},"wrap-lines":{category:"services-logs",label:"Wrap log lines",description:"Wrap long output instead of scrolling horizontally."},"github-connection":{category:"git-github",label:"GitHub connection",description:"Review the current GitHub connection without exposing credentials here."},"repository-defaults":{category:"git-github",label:"Repository defaults",description:"Repository-specific Git preferences will appear when their behavior is available."},"agent-environments":{category:"agents-mcp",label:"Agent environments",description:"Manage installed agents, MCP servers, skills, and profiles."},"project-agent-context":{category:"agents-mcp",label:"Project agent context",description:"Project-specific agent configuration remains in Agent Environments."},"confirm-writes":{category:"database-safety",label:"Confirm before writes",description:"Show a danger confirmation before write statements are submitted."},"result-limit":{category:"database-safety",label:"Default result limit",description:"Maximum rows requested for a default browse or query."},connections:{category:"database-safety",label:"Connections",description:"Manage connections and write access in the Database workbench."},"desktop-notifications":{category:"notifications",label:"Desktop notifications",description:"Shows whether desktop notifications are supported in this environment. Permission controls arrive with notification events."},"local-storage":{category:"data-privacy",label:"Local settings storage",description:"UI preferences stay in local browser storage; operational settings live in your NoMoreIDE config directory."},"export-reset":{category:"data-privacy",label:"Export and reset",description:"Export and reset controls are coming in a later delivery."},version:{category:"about",label:"Version",description:"Application version."},console:{category:"about",label:"Console",description:"Local runtime address."},documentation:{category:"about",label:"Documentation",description:"NoMoreIDE documentation and support."}};function BY(e){const t=_A[e];if(!t)throw new Error(`Missing settings copy for "${e}".`);return t}function wA(e){return`settingsHub.item.${e}.label`}function SA(e){return`settingsHub.item.${e}.desc`}function gu(e){return`settingsHub.cat.${e}.label`}function IY(e){return`settingsHub.cat.${e}.desc`}const HY=Object.keys(_A);function $Y(e,t,s){const n=kA(e),a=t.trim().toLowerCase().split(/\s+/).filter(Boolean);return HY.filter(l=>{const c=BY(l);if(c.category!==e)return!1;const d=s?` ${s(gu(e))} ${s(wA(l))} ${s(SA(l))}`:"",f=`${n.label} ${n.description} ${n.keywords.join(" ")} ${c.label} ${c.description}${d}`.toLowerCase();return a.every(h=>f.includes(h))})}function kA(e){return Qi.find(t=>t.id===e)??Qi[0]}function FY({scope:e}){const t=ee();return i.jsx("span",{className:oe("rounded-full border px-2 py-0.5 font-mono text-[10px] uppercase tracking-wide",e==="project"?"border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300":"border-border bg-muted/60 text-muted-foreground"),children:t(e==="project"?"settingsHub.currentProject":"settingsHub.global")})}function UY({state:e,error:t}){const s=ee();return e==="idle"?null:i.jsxs("div",{"aria-live":"polite",className:oe("flex items-center gap-1.5 text-xs",e==="error"?"text-destructive":"text-muted-foreground"),children:[e==="saving"?i.jsx(Lt,{className:"size-3.5 animate-spin"}):null,e==="saved"?i.jsx(Ys,{className:"size-3.5 text-emerald-600"}):null,e==="error"?i.jsx(Uf,{className:"size-3.5"}):null,i.jsx("span",{children:e==="saving"?s("settingsHub.saving"):e==="saved"?s("settingsHub.saved"):t})]})}function K0({id:e,label:t,description:s,children:n,disabled:a=!1}){return i.jsxs("div",{className:oe("settings-row grid gap-3 border-b border-border/50 px-4 last:border-b-0 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center",a&&"opacity-55"),children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("label",{className:"text-sm font-medium",htmlFor:e,children:t}),i.jsx("p",{className:"mt-0.5 max-w-xl text-xs leading-5 text-muted-foreground",id:`${e}-description`,children:s})]}),i.jsx("div",{className:"min-w-0 sm:justify-self-end",children:n})]})}function so({id:e,label:t,description:s,checked:n,onChange:a,disabled:l=!1}){return i.jsx(K0,{description:s,disabled:l,id:e,label:t,children:i.jsx("input",{"aria-describedby":`${e}-description`,checked:n,className:"size-4 accent-foreground",disabled:l,id:e,onChange:c=>a(c.target.checked),type:"checkbox"})})}function Uc({id:e,label:t,description:s,value:n,options:a,onChange:l,disabled:c=!1}){return i.jsx(K0,{description:s,disabled:c,id:e,label:t,children:i.jsx("select",{"aria-describedby":`${e}-description`,className:"h-8 min-w-36 rounded-md border border-input bg-background px-2 text-xs focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",disabled:c,id:e,onChange:d=>l(d.target.value),value:n,children:a.map(d=>i.jsx("option",{disabled:d.disabled,value:d.value,children:d.label},d.value))})})}function Ah({id:e,label:t,description:s,value:n,min:a,max:l,onSave:c,disabled:d=!1,scopeKey:f}){const h=ee(),{isPending:g,runOperation:p}=si(),[b,v]=x.useState(String(n)),[_,S]=x.useState(null),C=`settings:${f??"global"}:${e}:save`,N=g(C);x.useEffect(()=>{v(String(n)),S(null)},[f,n]);async function A(){const j=Number(b);if(!Number.isInteger(j)||j<a||j>l){S(h("settingsHub.numberRange",{min:a,max:l}));return}S(null);try{await p({key:C,label:h("settingsHub.savingSetting",{label:t})},async()=>c(j))}catch(E){S(E instanceof Error?E.message:String(E))}}return i.jsx(K0,{description:s,disabled:d,id:e,label:t,children:i.jsxs("div",{className:"flex flex-col items-start gap-1 sm:items-end",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(pt,{"aria-describedby":`${e}-description${_?` ${e}-error`:""}`,"aria-invalid":!!_,className:"h-8 w-24 font-mono text-xs",disabled:d,id:e,max:l,min:a,onChange:j=>v(j.target.value),type:"number",value:b}),i.jsx(Q,{"aria-label":h("settingsHub.saveAria",{label:t}),disabled:d,loading:N,loadingLabel:h("settingsHub.saving"),onClick:()=>{A()},size:"sm",type:"button",variant:"outline",children:h("settingsHub.save")})]}),_?i.jsx("span",{className:"text-[11px] text-destructive",id:`${e}-error`,role:"alert",children:_}):null]})})}function _a({title:e,description:t,action:s}){return i.jsxs("div",{className:"settings-row flex flex-col items-stretch justify-between gap-3 border-b border-border/50 px-4 last:border-b-0 sm:flex-row sm:items-center sm:gap-4",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:"text-sm font-medium",children:e}),i.jsx("p",{className:"mt-0.5 break-words text-xs leading-5 text-muted-foreground",children:t})]}),s?i.jsx("div",{className:"w-full shrink-0 [&_button]:w-full sm:w-auto sm:[&_button]:w-auto",children:s}):null]})}function qY({children:e}){return i.jsx("div",{className:"border border-dashed border-border bg-muted/30 px-4 py-3 text-xs leading-5 text-muted-foreground",children:e})}function GY({selected:e,onSelect:t,search:s,onSearch:n,saveState:a,saveError:l,children:c}){const d=ee(),f=x.useRef([]),h=kA(e),g=h.icon;function p(b,v){let _=null;if(b.key==="ArrowDown"&&(_=(v+1)%Qi.length),b.key==="ArrowUp"&&(_=(v-1+Qi.length)%Qi.length),b.key==="Home"&&(_=0),b.key==="End"&&(_=Qi.length-1),_===null)return;b.preventDefault();const S=Qi[_];t(S.id),f.current[_]?.focus()}return i.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[i.jsxs("header",{className:"flex shrink-0 flex-wrap items-center gap-3 border-b border-border px-3 py-2.5",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(gE,{className:"size-4 text-muted-foreground"}),i.jsx("span",{className:"text-sm font-semibold",children:d("settingsHub.title")})]}),i.jsxs("div",{className:"relative ml-auto w-full sm:w-64",children:[i.jsx(Wx,{className:"pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"}),i.jsx("input",{"aria-label":d("settingsHub.searchAria"),className:"h-8 w-full rounded-md border border-input bg-background pl-8 pr-8 text-xs outline-none focus:ring-2 focus:ring-ring",onChange:b=>n(b.target.value),placeholder:d("settingsHub.searchPlaceholder"),type:"search",value:s}),s?i.jsx("button",{"aria-label":d("settingsHub.clearSearch"),className:"absolute right-1.5 top-1/2 -translate-y-1/2 rounded p-1 text-muted-foreground hover:bg-muted",onClick:()=>n(""),type:"button",children:i.jsx(Vt,{className:"size-3"})}):null]}),i.jsx(UY,{error:l,state:a})]}),i.jsxs("div",{className:"border-b border-border px-3 py-2 md:hidden",children:[i.jsx("label",{className:"mb-1 block text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",htmlFor:"settings-category-select",children:d("settingsHub.category")}),i.jsx("select",{className:"h-9 w-full rounded-md border border-input bg-background px-2 text-sm",id:"settings-category-select",onChange:b=>t(b.target.value),value:e,children:Qi.map(b=>i.jsx("option",{value:b.id,children:d(gu(b.id))},b.id))})]}),i.jsxs("div",{className:"flex min-h-0 flex-1",children:[i.jsx("aside",{className:"hidden w-56 shrink-0 border-r border-border bg-muted/20 p-2 md:block",children:i.jsx("nav",{"aria-label":d("settingsHub.categoriesAria"),className:"space-y-0.5",children:Qi.map((b,v)=>{const _=b.icon,S=e===b.id;return i.jsxs("button",{"aria-current":S?"page":void 0,className:oe("flex w-full items-center gap-2 rounded-md px-2.5 py-2 text-left text-xs font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring",S?"bg-background text-foreground shadow-sm ring-1 ring-border":"text-muted-foreground hover:bg-muted hover:text-foreground"),onClick:()=>t(b.id),onKeyDown:C=>p(C,v),ref:C=>{f.current[v]=C},tabIndex:S?0:-1,type:"button",children:[i.jsx(_,{className:"size-3.5"}),i.jsx("span",{children:d(gu(b.id))})]},b.id)})})}),i.jsx("main",{className:"min-w-0 flex-1 overflow-y-auto",children:i.jsxs("div",{className:"mx-auto max-w-3xl px-3 py-4 sm:px-6 sm:py-6",children:[s?null:i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(g,{className:"size-4 text-muted-foreground"}),i.jsx("h2",{className:"text-base font-semibold",children:d(gu(h.id))})]}),i.jsx("p",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:d(IY(h.id))})]}),c]})})]})]})}function Xn({scope:e,title:t,children:s}){const n=ee();return i.jsxs("section",{className:"mb-4 overflow-hidden rounded-lg border border-border bg-background/70",children:[i.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border bg-muted/25 px-4 py-2.5",children:[i.jsx("h3",{className:"text-xs font-semibold",children:t??n(e==="global"?"settingsHub.global":"settingsHub.currentProject")}),i.jsx(FY,{scope:e})]}),s]})}function qc({project:e,ready:t,loadError:s,onRetry:n}){const a=ee();return e&&s?i.jsxs("div",{className:"border-b border-destructive/30 bg-destructive/5 px-4 py-3",role:"alert",children:[i.jsx("p",{className:"text-xs text-destructive",children:s}),i.jsx(Q,{"aria-label":a("settingsHub.retryProject"),className:"mt-2",onClick:n,size:"sm",type:"button",variant:"outline",children:a("settingsHub.retryProject")})]}):e&&!t?i.jsx("div",{className:"border-b border-border/50 bg-muted/30 px-4 py-2 text-xs text-muted-foreground",children:a("settingsHub.loadingProject",{name:e.name})}):e?i.jsxs("div",{className:"border-b border-border/50 bg-amber-500/5 px-4 py-2 text-[11px] text-muted-foreground",children:[i.jsx("span",{className:"font-medium text-foreground",children:e.name})," · ",a("settingsHub.projectWritesPre"),i.jsx("code",{children:"nomoreide.config.json"}),a("settingsHub.projectWritesPost")]}):i.jsx("div",{className:"border-b border-border/50 bg-muted/30 px-4 py-2 text-xs text-muted-foreground",children:a("settingsHub.selectProject")})}function VY({activeProject:e=null,onNavigate:t}={}){const s=ee(),n=bm(),a=!!(e?.path&&e.path===n.activeProjectPath&&!n.projectLoading&&!n.projectLoadError),[l,c]=x.useState("general"),[d,f]=x.useState(""),h=d.trim().toLowerCase(),g=x.useMemo(()=>h?Qi.map(b=>({id:b.id,settingIds:$Y(b.id,h,s)})).filter(b=>b.settingIds.length>0):[],[h,s]);let p;return n.loading?p=i.jsx("div",{"aria-label":s("settingsHub.loadingAria"),className:"space-y-3",role:"status",children:[0,1,2].map(b=>i.jsx("div",{className:"h-20 animate-pulse rounded-lg border border-border bg-muted/40"},b))}):n.loadError?p=i.jsxs("div",{className:"rounded-lg border border-destructive/30 bg-destructive/5 p-4",role:"alert",children:[i.jsx("p",{className:"text-sm font-medium",children:s("settingsHub.loadFailed")}),i.jsx("p",{className:"mt-1 text-xs text-destructive",children:n.loadError}),i.jsx(Q,{className:"mt-3",onClick:()=>{n.retry()},size:"sm",type:"button",variant:"outline",children:s("settingsHub.retry")})]}):h?p=i.jsxs("div",{children:[i.jsx("h2",{className:"mb-4 text-base font-semibold",children:s("settingsHub.searchResults")}),g.length?g.map(({id:b,settingIds:v})=>i.jsxs("div",{className:"mb-5",children:[i.jsx("div",{className:"mb-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:s(gu(b))}),i.jsx(vC,{activeProject:e,category:b,onNavigate:t,projectReady:a,settings:n,visibleSettingIds:new Set(v)})]},b)):i.jsx(qY,{children:s("settingsHub.noMatches",{query:d.trim()})})]}):p=i.jsx(vC,{activeProject:e,category:l,onNavigate:t,projectReady:a,settings:n}),i.jsx(GY,{onSearch:f,onSelect:c,saveError:n.saveError,saveState:n.saveState,search:d,selected:l,children:p})}function vC({category:e,activeProject:t,projectReady:s,onNavigate:n,settings:a,visibleSettingIds:l}){const c=ee(),d=!s,f=p=>!l||l.has(p),h=p=>p.some(f),g=p=>({label:c(wA(p)),description:c(SA(p))});switch(e){case"general":return i.jsxs(Xn,{scope:"global",children:[f("language")?i.jsx(Uc,{...g("language"),id:"setting-language",onChange:p=>a.updateUi({language:p}),options:L$.map(p=>({value:p.value,label:p.nativeLabel,disabled:!p.available})),value:a.ui.language}):null,f("sidebar-docked")?i.jsx(so,{...g("sidebar-docked"),checked:a.ui.sidebarDocked,id:"setting-sidebar-docked",onChange:p=>a.updateUi({sidebarDocked:p})}):null,f("project-scope")?i.jsx(Uc,{...g("project-scope"),id:"setting-project-scope",onChange:p=>a.updateUi({projectScope:p}),options:[{value:"all",label:c("settingsHub.opt.allProjects")},{value:"project",label:c("settingsHub.currentProject")}],value:a.ui.projectScope}):null]});case"appearance":return i.jsxs(Xn,{scope:"global",children:[f("theme")?i.jsx(Uc,{...g("theme"),id:"setting-theme",onChange:p=>a.updateUi({theme:p}),options:[{value:"system",label:c("settingsHub.opt.system")},{value:"light",label:c("settingsHub.opt.light")},{value:"dark",label:c("settingsHub.opt.dark")}],value:a.ui.theme}):null,f("density")?i.jsx(Uc,{...g("density"),id:"setting-density",onChange:p=>a.updateUi({density:p}),options:[{value:"comfortable",label:c("settingsHub.opt.comfortable")},{value:"compact",label:c("settingsHub.opt.compact")}],value:a.ui.density}):null,f("code-font")?i.jsx(Ah,{...g("code-font"),id:"setting-code-font",max:18,min:10,onSave:p=>{a.updateUi({codeFontSize:p})},value:a.ui.codeFontSize}):null,f("reduced-motion")?i.jsx(so,{...g("reduced-motion"),checked:a.ui.reducedMotion,id:"setting-reduced-motion",onChange:p=>a.updateUi({reducedMotion:p})}):null]});case"terminal":return i.jsxs(Xn,{scope:"global",children:[f("terminal-font")?i.jsx(Ah,{...g("terminal-font"),id:"setting-terminal-font",max:24,min:10,onSave:p=>a.updateGlobal({terminal:{fontSize:p}}),value:a.global.terminal.fontSize}):null,f("cursor")?i.jsx(Uc,{...g("cursor"),id:"setting-cursor",onChange:p=>{a.updateGlobal({terminal:{cursorStyle:p}})},options:[{value:"block",label:c("settingsHub.opt.block")},{value:"underline",label:c("settingsHub.opt.underline")},{value:"bar",label:c("settingsHub.opt.bar")}],value:a.global.terminal.cursorStyle}):null,f("scrollback")?i.jsx(Ah,{...g("scrollback"),id:"setting-scrollback",max:1e5,min:500,onSave:p=>a.updateGlobal({terminal:{scrollback:p}}),value:a.global.terminal.scrollback}):null,f("copy-on-select")?i.jsx(so,{...g("copy-on-select"),checked:a.global.terminal.copyOnSelect,id:"setting-copy-on-select",onChange:p=>{a.updateGlobal({terminal:{copyOnSelect:p}})}}):null,f("confirm-terminate")?i.jsx(so,{...g("confirm-terminate"),checked:a.global.terminal.confirmTerminate,id:"setting-confirm-terminate",onChange:p=>{a.updateGlobal({terminal:{confirmTerminate:p}})}}):null]});case"services-logs":return i.jsxs(Xn,{scope:"project",children:[i.jsx(qc,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),f("log-timestamps")?i.jsx(so,{...g("log-timestamps"),checked:a.project.logs.showTimestamps,disabled:d,id:"setting-log-timestamps",onChange:p=>{a.updateProject({logs:{showTimestamps:p}})}}):null,f("wrap-lines")?i.jsx(so,{...g("wrap-lines"),checked:a.project.logs.wrapLines,disabled:d,id:"setting-wrap-lines",onChange:p=>{a.updateProject({logs:{wrapLines:p}})}}):null]});case"git-github":return i.jsxs(i.Fragment,{children:[h(["github-connection"])?i.jsx(Xn,{scope:"global",children:i.jsx(_a,{action:i.jsx(Q,{onClick:()=>n?.("github"),size:"sm",type:"button",variant:"outline",children:c("settingsHub.manageGitHub")}),description:g("github-connection").description,title:g("github-connection").label})}):null,h(["repository-defaults"])?i.jsxs(Xn,{scope:"project",children:[i.jsx(qc,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),i.jsx(_a,{description:g("repository-defaults").description,title:g("repository-defaults").label})]}):null]});case"agents-mcp":return i.jsxs(i.Fragment,{children:[h(["agent-environments"])?i.jsx(Xn,{scope:"global",children:i.jsx(_a,{action:i.jsx(Q,{onClick:()=>n?.("agent-env"),size:"sm",type:"button",variant:"outline",children:c("settingsHub.openAgentEnv")}),description:g("agent-environments").description,title:g("agent-environments").label})}):null,h(["project-agent-context"])?i.jsxs(Xn,{scope:"project",children:[i.jsx(qc,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),i.jsx(_a,{description:g("project-agent-context").description,title:g("project-agent-context").label})]}):null]});case"database-safety":return i.jsxs(Xn,{scope:"project",children:[i.jsx(qc,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),f("confirm-writes")?i.jsx(so,{...g("confirm-writes"),checked:a.project.database.confirmWrites,disabled:d,id:"setting-confirm-writes",onChange:p=>{a.updateProject({database:{confirmWrites:p}})}}):null,f("result-limit")?i.jsx(Ah,{...g("result-limit"),disabled:d,id:"setting-result-limit",max:5e3,min:10,onSave:p=>a.updateProject({database:{resultLimit:p}}),scopeKey:a.activeProjectPath,value:a.project.database.resultLimit}):null,f("connections")?i.jsx(_a,{action:i.jsx(Q,{disabled:d,onClick:()=>n?.("database"),size:"sm",type:"button",variant:"outline",children:c("settingsHub.openDatabase")}),description:g("connections").description,title:g("connections").label}):null]});case"notifications":{const p=typeof Notification>"u"?c("settingsHub.notifUnavailable"):c("settingsHub.notifPermission",{value:Notification.permission});return i.jsx(Xn,{scope:"global",children:f("desktop-notifications")?i.jsx(_a,{action:i.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:p}),description:g("desktop-notifications").description,title:g("desktop-notifications").label}):null})}case"data-privacy":return i.jsxs(i.Fragment,{children:[h(["local-storage"])?i.jsx(Xn,{scope:"global",children:i.jsx(_a,{description:g("local-storage").description,title:g("local-storage").label})}):null,h(["export-reset"])?i.jsxs(Xn,{scope:"project",children:[i.jsx(qc,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),i.jsx(_a,{description:g("export-reset").description,title:g("export-reset").label})]}):null]});case"about":return i.jsx(Xn,{scope:"global",children:i.jsxs("div",{className:"grid grid-cols-[auto_1fr] gap-x-5 gap-y-2 px-4 py-4 text-xs",children:[f("version")?i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-muted-foreground",children:g("version").label}),i.jsxs("code",{children:["v","0.1.85"]})]}):null,f("console")?i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-muted-foreground",children:g("console").label}),i.jsx("code",{children:"127.0.0.1:4317"})]}):null,f("documentation")?i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-muted-foreground",children:g("documentation").label}),i.jsxs("a",{className:"inline-flex items-center gap-1 text-primary hover:underline",href:"https://www.nomoreide.com/docs",rel:"noreferrer",target:"_blank",children:[i.jsx(QN,{className:"size-3"}),"nomoreide.com/docs",i.jsx(ja,{className:"size-3"})]})]}):null]})})}}function WY(e,t){const s=t.trim().toLocaleLowerCase();return s?[e.service,e.title,e.file??"",...e.logExcerpt].some(n=>n.toLocaleLowerCase().includes(s)):!0}function KY(e,t,s){const n=new Set(s.levels),a=new Set(s.services);return e.filter(l=>WY(l,t)&&(n.size===0||n.has(l.level))&&(a.size===0||a.has(l.service)))}function YY(e){return{levels:[...new Set(e.map(({level:t})=>t))].sort(),services:[...new Set(e.map(({service:t})=>t))].sort()}}function XY(e){return e.levels.length+e.services.length}function ZY({detailId:e,incident:t,onReviewChanges:s}){const n=ee(),{sendToAgent:a}=Ot(),{isPending:l,runOperation:c}=si(),d=`error:${t.id}:fix`,f=l(d),[h,g]=x.useState(null);async function p(){await c({errorMessage:b=>b instanceof Error?b.message:String(b),key:d,label:n("errors.incident.fixingOperation",{service:t.service})},async()=>{const{prompt:b,sessionId:v}=await XO(t.id);a({prompt:b,source:{type:"error",label:`${t.service} — ${t.level}`},label:n("errors.incident.fixLabel",{level:t.level,service:t.service,title:t.title})}),g(v)})}return i.jsxs("div",{className:"min-w-0 rounded-lg border border-border bg-background","data-incident-detail":"true",id:e,children:[i.jsxs("div",{className:"px-4 py-3",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(Ke,{variant:t.level==="error"?"danger":"secondary",appearance:"subtle",size:"small",children:n(t.level==="error"?"errors.level.error":"errors.level.warning")}),i.jsx("span",{className:"truncate font-mono text-xs font-semibold",children:t.service}),t.count>1?i.jsxs(Ke,{variant:"outline",size:"small",children:["×",t.count]}):null]}),i.jsxs(Q,{loading:f,loadingLabel:n("errors.incident.starting"),onClick:()=>{p().catch(()=>{})},size:"sm",variant:"outline",children:[i.jsx(Xt,{className:"size-3.5"}),n("errors.incident.fixWithAi")]})]}),i.jsx("p",{className:"mt-1.5 break-words font-mono text-xs text-foreground",children:t.title}),t.file?i.jsxs("p",{className:"mt-1 flex items-center gap-1.5 font-mono text-[11px] text-muted-foreground",children:[i.jsx(aE,{className:"size-3.5"}),t.file,t.line?`:${t.line}`:""]}):null,i.jsx("p",{className:"mt-1 font-mono text-[10px] text-muted-foreground/80",children:n("errors.incident.firstLast",{first:new Date(t.firstSeen).toLocaleString(),last:new Date(t.lastSeen).toLocaleTimeString()})})]}),i.jsxs("div",{className:"border-t border-border p-4",children:[h?i.jsx(tt,{variant:"muted",className:"mb-3",children:i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[i.jsx("span",{className:"text-xs",children:n("errors.incident.working")}),s?i.jsxs(Q,{onClick:()=>s(h),size:"sm",variant:"outline",children:[i.jsx(rE,{className:"size-3.5"}),n("errors.incident.reviewChanges")]}):null]})}):null,i.jsx("p",{className:"mb-1.5 text-xs font-medium text-muted-foreground",children:n("errors.incident.logExcerpt")}),i.jsx("pre",{className:"overflow-x-auto rounded-md border border-border bg-muted/40 p-3 font-mono text-[11px] leading-relaxed",children:t.logExcerpt.join(`
|
|
119
119
|
`)}),i.jsx("p",{className:"mt-3 text-[11px] text-muted-foreground",children:n("errors.incident.explain")})]})]})}function QY({activeCount:e,levels:t,onClear:s,onToggleLevel:n,onToggleService:a,open:l,query:c,reduceMotion:d,selectedLevels:f,selectedServices:h,services:g}){const p=ee(),b=d?{duration:0}:{duration:.16};return i.jsx(SH,{initial:!1,children:l?i.jsxs(du.div,{animate:{height:"auto",opacity:1},className:"mt-3 grid gap-4 overflow-hidden rounded-lg border border-border bg-background p-3 md:grid-cols-2 lg:w-[280px] lg:grid-cols-1",exit:{height:0,opacity:0},initial:{height:0,opacity:0},transition:b,children:[i.jsx(xC,{format:v=>p(v==="error"?"errors.level.error":"errors.level.warning"),label:p("errors.filterSeverity"),onToggle:n,options:t,selected:f}),i.jsx(xC,{format:v=>v,label:p("errors.filterService"),onToggle:a,options:g,selected:h}),i.jsx(Q,{disabled:e===0&&!c,onClick:s,size:"sm",type:"button",variant:"ghost",children:p("errors.clearFilters")})]}):null})}function xC({format:e,label:t,onToggle:s,options:n,selected:a}){return i.jsxs("fieldset",{children:[i.jsx("legend",{className:"mb-2 text-xs font-semibold",children:t}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:n.map(l=>{const c=a.includes(l);return i.jsx(Q,{"aria-pressed":c,onClick:()=>s(l),size:"sm",type:"button",variant:c?"secondary":"outline",children:e(l)},l)})})]})}function yC(e,t){return e.includes(t)?e.filter(s=>s!==t):[...e,t]}function JY({connected:e,error:t,incidents:s,onReviewChanges:n}){const[a,l]=x.useState(""),[c,d]=x.useState(()=>({levels:[],services:[]})),[f,h]=x.useState(!1),[g,p]=x.useState(null),b=R$(),v=ee(),_=x.useMemo(()=>YY(s),[s]),S=x.useMemo(()=>KY(s,a,c),[c,s,a]),C=XY(c),N=()=>{l(""),d({levels:[],services:[]})},A=b?{duration:0}:{duration:.16};return i.jsxs("section",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[i.jsxs("header",{className:"flex shrink-0 flex-wrap items-center justify-between gap-2 border-b border-border px-4 py-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(ju,{className:"size-4 text-muted-foreground"}),i.jsx("h2",{className:"text-sm font-semibold",children:v("errors.incidents")}),i.jsx(Ke,{appearance:"outline",size:"small",variant:"outline",children:v("errors.summary",{count:s.length})})]}),i.jsx(Ke,{appearance:"outline",icon:i.jsx("span",{className:oe("inline-block size-1.5 rounded-full",e?"animate-pulse bg-emerald-500":"bg-muted-foreground/60")}),size:"small",variant:"outline",children:v(e?"errors.live":"errors.reconnecting")})]}),i.jsxs("div",{className:"shrink-0 border-b border-border px-4 py-3",children:[i.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",children:[i.jsxs("div",{className:"relative min-w-0 flex-1",children:[i.jsx(Wx,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),i.jsx(pt,{"aria-label":v("errors.searchAria"),className:"pl-9",onChange:j=>l(j.target.value),placeholder:v("errors.searchPlaceholder"),type:"search",value:a})]}),i.jsxs(Q,{"aria-expanded":f,"aria-label":v(f?"errors.hideFilters":"errors.showFilters"),onClick:()=>h(j=>!j),size:"sm",type:"button",variant:"outline",children:[i.jsx(QD,{}),v("errors.filters"),C>0?i.jsx(Ke,{appearance:"solid",size:"small",variant:"primary",children:C}):null]})]}),i.jsx(QY,{activeCount:C,levels:_.levels,onClear:N,onToggleLevel:j=>d(E=>({...E,levels:yC(E.levels,j)})),onToggleService:j=>d(E=>({...E,services:yC(E.services,j)})),open:f,query:a,reduceMotion:b,selectedLevels:c.levels,selectedServices:c.services,services:_.services}),i.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:v("errors.resultCount",{shown:S.length,total:s.length})})]}),t?i.jsx("div",{className:"shrink-0 px-4 pt-3",children:i.jsx(tt,{className:"border-destructive/40 text-destructive",variant:"muted",children:v("errors.loadFailed",{error:t})})}):null,i.jsx("div",{className:"min-h-0 flex-1 overflow-auto p-2 sm:p-4",children:s.length===0?i.jsx(_C,{body:v("errors.emptyBody"),title:v("errors.emptyTitle")}):S.length===0?i.jsx(_C,{body:v("errors.noMatchesBody"),title:v("errors.noMatchesTitle"),children:i.jsx(Q,{onClick:N,size:"sm",type:"button",variant:"outline",children:v("errors.clearFilters")})}):i.jsxs("table",{"aria-label":v("errors.tableAria"),className:"w-full table-fixed border-collapse",children:[i.jsx("thead",{className:"hidden border-b border-border text-left text-[10px] font-semibold uppercase tracking-wide text-muted-foreground md:table-header-group",children:i.jsxs("tr",{children:[i.jsx("th",{className:"w-24 px-3 py-2",scope:"col",children:v("errors.columnSeverity")}),i.jsx("th",{className:"w-36 px-3 py-2",scope:"col",children:v("errors.columnLatest")}),i.jsx("th",{className:"w-28 px-3 py-2",scope:"col",children:v("errors.columnService")}),i.jsx("th",{className:"px-3 py-2",scope:"col",children:v("errors.columnIncident")}),i.jsx("th",{className:"w-20 px-3 py-2",scope:"col",children:v("errors.columnCount")}),i.jsx("th",{className:"w-48 px-3 py-2",scope:"col",children:v("errors.columnSource")}),i.jsx("th",{className:"w-10 px-2 py-2",scope:"col",children:i.jsx("span",{className:"sr-only",children:v("errors.columnActions")})})]})}),i.jsx("tbody",{className:"divide-y divide-border",children:S.map(j=>{const E=j.id===g,T=`incident-detail-${j.id}`;return i.jsxs(x.Fragment,{children:[i.jsxs("tr",{className:"transition-colors hover:bg-muted/40 motion-reduce:transition-none","data-incident-id":j.id,children:[i.jsx("td",{className:"w-24 px-2 py-3 align-middle md:px-3",children:i.jsx(Ke,{appearance:"subtle",size:"small",variant:j.level==="error"?"danger":"warning",children:v(j.level==="error"?"errors.level.error":"errors.level.warning")})}),i.jsx("td",{className:"hidden px-3 py-3 align-middle font-mono text-[11px] text-muted-foreground md:table-cell",children:new Date(j.lastSeen).toLocaleString()}),i.jsx("td",{className:"hidden truncate px-3 py-3 align-middle font-mono text-xs font-semibold md:table-cell",children:j.service}),i.jsxs("td",{className:"min-w-0 px-2 py-3 align-middle md:px-3",children:[i.jsx("p",{className:"truncate text-xs font-medium",children:j.title}),i.jsxs("p",{className:"mt-0.5 truncate font-mono text-[10px] text-muted-foreground md:hidden",children:[j.service," · ",new Date(j.lastSeen).toLocaleString()]})]}),i.jsxs("td",{className:"hidden px-3 py-3 align-middle font-mono text-xs text-muted-foreground md:table-cell",children:["×",j.count]}),i.jsx("td",{className:"hidden truncate px-3 py-3 align-middle font-mono text-[11px] text-muted-foreground md:table-cell",children:j.file?`${j.file}${j.line?`:${j.line}`:""}`:v("common.none")}),i.jsx("td",{className:"w-10 px-2 py-3 align-middle",children:i.jsx(Q,{"aria-controls":T,"aria-expanded":E,"aria-label":v(E?"errors.collapseIncident":"errors.expandIncident",{title:j.title}),onClick:()=>p(E?null:j.id),size:"icon-sm",type:"button",variant:"ghost",children:i.jsx(hn,{className:oe("transition-transform motion-reduce:transition-none",E&&"rotate-180")})})})]}),E?i.jsx("tr",{children:i.jsx("td",{className:"px-2 pb-3 md:px-3",colSpan:7,children:i.jsx(du.div,{animate:{opacity:1,y:0},initial:{opacity:0,y:b?0:-4},transition:A,children:i.jsx(ZY,{detailId:T,incident:j,onReviewChanges:n})})})}):null]},j.id)})})]})})]})}function _C({body:e,children:t,title:s}){return i.jsx("div",{className:"flex min-h-64 items-center justify-center p-8 text-center",children:i.jsxs("div",{className:"max-w-sm",children:[i.jsx(ju,{className:"mx-auto size-8 text-muted-foreground/50"}),i.jsx("p",{className:"mt-3 text-sm font-medium",children:s}),i.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:e}),t?i.jsx("div",{className:"mt-4",children:t}):null]})})}function wC(e){return[...e].sort((t,s)=>t.lastSeen<s.lastSeen?1:t.lastSeen>s.lastSeen?-1:s.id-t.id)}function eX(){const[e,t]=x.useState([]),[s,n]=x.useState(!1),[a,l]=x.useState(null),c=x.useCallback(d=>{t(f=>wC([...f.filter(h=>h.id!==d.id),d]))},[]);return x.useEffect(()=>{let d=!0;ME().then(h=>{d&&t(wC(h))}).catch(h=>{d&&l(h instanceof Error?h.message:String(h))});const f=new EventSource("/api/errors/stream");return f.addEventListener("open",()=>n(!0)),f.addEventListener("error",()=>n(!1)),f.addEventListener("incident",h=>{try{const g=JSON.parse(h.data);c(g)}catch{}}),()=>{d=!1,f.close()}},[c]),{incidents:e,connected:s,error:a}}function tX({inScope:e,onReviewChanges:t}={}){const{incidents:s,connected:n,error:a}=eX(),l=x.useMemo(()=>e?s.filter(c=>e(c.service)):s,[s,e]);return i.jsx(JY,{connected:n,error:a,incidents:l,onReviewChanges:t})}function Tf({label:e}){return i.jsx(tt,{variant:"muted",className:"m-4 text-center",children:e})}const sX=900*1e3,su=12,wb=200;function nX({events:e}){const t=ee(),[s,n]=x.useState(null),[a,l]=x.useState(null),{rows:c,windowStart:d,windowEnd:f}=x.useMemo(()=>iX(e),[e]),h=s?c.find(g=>g.service===s)??null:null;return i.jsxs(i.Fragment,{children:[i.jsxs(_i,{className:"rounded-none border-0 border-b border-border bg-transparent",children:[i.jsxs(wi,{className:"border-b border-border px-3 py-2",children:[i.jsxs(Si,{className:"flex items-center gap-2",children:[i.jsx(mo,{className:"size-3.5"}),t("services.timeline.title")]}),i.jsx(ar,{className:"text-xs",children:e.length===0?t("services.timeline.noEvents"):t("services.timeline.events",{count:e.length})})]}),i.jsx(ki,{className:"p-0",children:c.length===0?i.jsx(Tf,{label:t("services.timeline.empty")}):i.jsxs("div",{className:"divide-y divide-border",children:[c.map(g=>i.jsx(aX,{onClick:()=>n(g.service),row:g,windowEnd:f,windowStart:d},g.service)),i.jsxs("div",{className:"flex justify-between px-3 py-1.5 font-mono text-[10px] text-muted-foreground",children:[i.jsx("span",{children:Rf(d)}),i.jsx("span",{children:t("services.timeline.now")})]})]})})]}),h?i.jsx(ei,{icon:i.jsx(mo,{}),onClose:()=>n(null),title:h.service,children:i.jsx(lX,{onSelect:l,row:h})}):null,a?i.jsx(ei,{icon:i.jsx(mo,{}),onClose:()=>l(null),title:a.title,children:i.jsx(cX,{event:a})}):null]})}function iX(e){const t=Date.now(),s=t,n=t-sX;let a=e.filter(f=>{if(f.kind==="service.http")return!1;const h=new Date(f.timestamp).getTime();return!Number.isNaN(h)&&h>=n});a.length===0&&e.length>0?a=e.slice(-wb):a.length>wb&&(a=a.slice(-wb));const l=new Map;for(const f of a){const h=f.service||"·system",g=l.get(h)??[];g.push(f),l.set(h,g)}const c=Math.max(s-n,1);return{rows:Array.from(l.entries()).map(([f,h])=>{const g=[...h].sort((A,j)=>A.timestamp.localeCompare(j.timestamp)),p=new Array(su).fill(0),b=new Array(su).fill(null);for(const A of g){const j=new Date(A.timestamp).getTime(),E=Math.max(n,Math.min(s,j)),T=Math.min(su-1,Math.floor((E-n)/c*su));p[T]+=1;const L=b[T];b[T]=rX(L,A.severity)}const v=g.filter(A=>A.severity==="error").length,_=g.filter(A=>A.severity==="warning").length,S=g.length-v-_,C=[...g].reverse().find(A=>A.severity!=="info")??null,N=v>0?"error":_>0?"warning":"info";return{service:f,events:g,errors:v,warnings:_,infos:S,buckets:p,bucketSeverity:b,lastNotable:C,worstSeverity:N}}).sort((f,h)=>{const g=b=>b.errors*1e3+b.warnings,p=g(h)-g(f);return p!==0?p:f.service.localeCompare(h.service)}),windowStart:n,windowEnd:s}}function rX(e,t){return e==="error"||t==="error"?"error":e==="warning"||t==="warning"?"warning":"info"}function aX({onClick:e,row:t,windowEnd:s,windowStart:n}){const a=ee(),l=Math.max(1,...t.buckets);return i.jsxs("button",{className:"timeline-service-row block w-full px-3 py-2 text-left transition-colors hover:bg-muted/40 focus:outline-none focus-visible:bg-muted/40","data-testid":"timeline-service-row",onClick:e,type:"button",children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i.jsx("span",{className:oe("size-2 shrink-0 rounded-full",CA(t.worstSeverity))}),i.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-foreground",dir:"rtl",children:i.jsx("bdi",{children:t.service})}),t.errors>0?i.jsxs("span",{className:"rounded bg-red-500/15 px-1 font-mono text-[10px] text-red-500",children:[t.errors,"E"]}):null,t.warnings>0?i.jsxs("span",{className:"rounded bg-amber-500/15 px-1 font-mono text-[10px] text-amber-500",children:[t.warnings,"W"]}):null,i.jsx(_n,{className:"size-3 text-muted-foreground"})]}),i.jsx("div",{className:"timeline-density mt-1.5 grid h-3 gap-px","data-testid":"timeline-density",style:{gridTemplateColumns:`repeat(${su}, minmax(0, 1fr))`},children:t.buckets.map((c,d)=>i.jsx(oX,{count:c,max:l,severity:t.bucketSeverity[d]},d))}),t.lastNotable?i.jsx("div",{className:"mt-1 truncate font-mono text-[10px] text-muted-foreground",children:t.lastNotable.detail??t.lastNotable.title}):i.jsx("div",{className:"mt-1 truncate text-[10px] text-muted-foreground",children:a("services.timeline.infoEvents",{count:t.infos})}),i.jsxs("div",{className:"mt-0.5 flex justify-between font-mono text-[9px] text-muted-foreground/60",children:[i.jsx("span",{children:Rf(n)}),i.jsx("span",{children:Rf(s)})]})]})}function oX({count:e,max:t,severity:s}){const n=ee();if(e===0)return i.jsx("span",{className:"rounded-sm bg-border/60"});const a=Math.min(1,.35+e/t*.65);return i.jsx("span",{className:oe("rounded-sm",uX(s)),style:{opacity:a},title:n("services.timeline.eventsCount",{count:e})})}function lX({onSelect:e,row:t}){const s=ee(),n=[...t.events].sort((a,l)=>l.timestamp.localeCompare(a.timestamp));return i.jsxs("div",{className:"flex max-h-[480px] flex-col overflow-hidden",children:[i.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-4 py-2 text-xs text-muted-foreground",children:[i.jsx("span",{children:s("services.timeline.eventsCount",{count:t.events.length})}),i.jsx("span",{children:"·"}),i.jsx("span",{children:s("services.timeline.errorsCount",{count:t.errors})}),i.jsx("span",{children:"·"}),i.jsx("span",{children:s("services.timeline.warningsCount",{count:t.warnings})})]}),i.jsx("ul",{className:"min-h-0 divide-y divide-border overflow-auto",children:n.map(a=>i.jsx("li",{children:i.jsxs("button",{className:"block w-full px-4 py-2 text-left hover:bg-muted/40 focus:outline-none focus-visible:bg-muted/40",onClick:()=>e(a),type:"button",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:oe("size-2 shrink-0 rounded-full",CA(a.severity))}),i.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-foreground",children:a.title}),i.jsx("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground",children:Rf(a.timestamp)})]}),a.detail?i.jsx("div",{className:"mt-1 truncate font-mono text-[10px] text-muted-foreground",children:a.detail}):null]})},a.id))})]})}function cX({event:e}){const t=ee(),s=new Date(e.timestamp);return i.jsxs("div",{className:"space-y-3 p-4 text-sm",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:oe("rounded px-1.5 py-0.5 font-mono text-[10px] uppercase text-white",dX(e.severity)),children:e.severity}),i.jsx("span",{className:"rounded border border-border bg-muted px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground",children:e.kind}),e.service?i.jsx("span",{className:"rounded border border-border bg-background px-1.5 py-0.5 font-mono text-[10px] text-foreground",children:e.service}):null]}),i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-muted-foreground",children:t("services.timeline.when")}),i.jsx("div",{className:"font-mono text-xs",children:Number.isNaN(s.getTime())?e.timestamp:s.toLocaleString()})]}),e.detail?i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-muted-foreground",children:t("services.timeline.detail")}),i.jsx("pre",{className:"mt-1 max-h-72 overflow-auto whitespace-pre-wrap rounded border border-border bg-background p-3 font-mono text-xs",children:e.detail})]}):null]})}function CA(e){return e==="error"?"bg-red-500":e==="warning"?"bg-amber-500":"bg-zinc-400"}function uX(e){return e==="error"?"bg-red-500":e==="warning"?"bg-amber-500":"bg-zinc-500"}function dX(e){return e==="error"?"bg-red-600":e==="warning"?"bg-amber-600":"bg-zinc-700"}function Rf(e){const t=typeof e=="number"?new Date(e):new Date(e);return Number.isNaN(t.getTime())?"--:--:--":t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}const Nx=150,wl=40,SC=200,kC=64,Th=20;function hX({statuses:e,health:t,hasDependencies:s,onSelectService:n}){const a=ee(),[l,c]=x.useState(null),[d,f]=x.useState(null);x.useEffect(()=>{let p=!0;return G7().then(b=>{p&&c(b)}).catch(b=>{p&&f(b instanceof Error?b.message:String(b))}),()=>{p=!1}},[]);const h=x.useMemo(()=>l?fX(l.nodes):null,[l]);if(d)return i.jsx(tt,{variant:"destructive",children:a("services.graph.loadError",{error:d})});if(!l||!h)return i.jsxs("div",{className:"flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground",children:[i.jsx(Lt,{className:"size-4 animate-spin"}),a("services.graph.loading")]});if(!s)return i.jsx("div",{className:"grid gap-3",children:i.jsxs(tt,{variant:"muted",children:[i.jsx("div",{className:"font-medium",children:a("services.graph.noDeps")}),i.jsxs("div",{className:"mt-1 text-xs",children:[a("services.graph.noDepsHint1")," ",i.jsx("span",{className:"font-medium",children:a("services.graph.dependencies")}),a("services.graph.noDepsHint2")]})]})});const g=l.nodes.filter(p=>p.missing.length>0);return i.jsxs("div",{className:"grid gap-3",children:[l.cycles.length>0?i.jsxs(tt,{variant:"destructive",children:[i.jsxs("div",{className:"flex items-center gap-1.5 font-medium",children:[i.jsx(Lr,{className:"size-4"}),a("services.graph.cycleDetected")]}),i.jsxs("div",{className:"mt-1 text-xs",children:[l.cycles.map(p=>p.join(" → ")).join("; "),". ",a("services.graph.cycleHint")]})]}):null,g.length>0?i.jsx(tt,{variant:"muted",children:i.jsx("div",{className:"text-xs",children:g.map(p=>i.jsxs("div",{children:[i.jsx("span",{className:"font-medium",children:p.name})," ",a(p.missing.length>1?"services.graph.dependsUnknownMany":"services.graph.dependsUnknownOne",{list:p.missing.join(", ")})]},p.name))})}):null,i.jsx("div",{className:"overflow-auto rounded-md border border-border bg-muted/20 p-2",children:i.jsxs("svg",{"aria-label":a("services.graph.aria"),height:h.height,role:"img",width:h.width,children:[h.edges.map(p=>i.jsx("path",{className:"fill-none stroke-border",d:p.path,strokeWidth:1.5},`${p.from}->${p.to}`)),h.nodes.map(p=>{const b=e[p.name],v=mX(b?.state,t[p.name]?.status);return i.jsxs("g",{"aria-label":a("services.graph.selectAria",{name:p.name}),className:"cursor-pointer",onClick:()=>n(p.name),transform:`translate(${p.x}, ${p.y})`,children:[i.jsx("rect",{className:oe("stroke-2",v.fill,v.stroke),height:wl,rx:6,width:Nx}),i.jsx("circle",{className:v.dot,cx:14,cy:wl/2,r:4}),i.jsx("text",{className:"fill-foreground text-[11px] font-medium",dominantBaseline:"middle",x:26,y:wl/2,children:pX(p.name)})]},p.name)})]})}),l.order.length>0?i.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[i.jsx("span",{className:"font-medium uppercase tracking-wide",children:a("services.graph.startOrder")})," ",l.order.join(" → ")]}):null]})}function fX(e){const t=new Map(e.map(p=>[p.name,p.dependsOn])),s=new Map,n=new Set,a=p=>{const b=s.get(p);if(b!==void 0)return b;if(n.has(p))return 0;n.add(p);const v=t.get(p)??[],_=v.length===0?0:Math.max(...v.map(S=>a(S)+1));return n.delete(p),s.set(p,_),_};for(const p of e)a(p.name);const l=new Map,c=e.map(p=>{const b=s.get(p.name)??0,v=l.get(b)??0;return l.set(b,v+1),{...p,x:Th+b*SC,y:Th+v*kC}}),d=new Map(c.map(p=>[p.name,p])),f=c.flatMap(p=>p.dependsOn.flatMap(b=>{const v=d.get(b);if(!v)return[];const _=v.x+Nx,S=v.y+wl/2,C=p.x,N=p.y+wl/2,A=(_+C)/2;return[{from:b,to:p.name,path:`M ${_} ${S} C ${A} ${S}, ${A} ${N}, ${C} ${N}`}]})),h=Math.max(0,...c.map(p=>s.get(p.name)??0)),g=Math.max(1,...l.values());return{nodes:c,edges:f,width:Th*2+h*SC+Nx,height:Th*2+(g-1)*kC+wl}}function mX(e,t){return e==="running"?t==="warning"?{fill:"fill-amber-500/10",stroke:"stroke-amber-500/60",dot:"fill-amber-500"}:t==="unhealthy"?{fill:"fill-red-500/10",stroke:"stroke-red-500/60",dot:"fill-red-500"}:{fill:"fill-emerald-500/10",stroke:"stroke-emerald-500/60",dot:"fill-emerald-500"}:e==="starting"?{fill:"fill-amber-500/10",stroke:"stroke-amber-500/60",dot:"fill-amber-500"}:e==="exited"?{fill:"fill-red-500/10",stroke:"stroke-red-500/60",dot:"fill-red-500"}:{fill:"fill-card",stroke:"stroke-border",dot:"fill-muted-foreground"}}function pX(e,t=18){return e.length>t?`${e.slice(0,t-1)}…`:e}function gX({onOnboardRepo:e,onOnboardWithAi:t,onCreateService:s,onCreateWithAi:n}){const a=ee();return i.jsx("div",{className:"flex h-full min-h-0 items-center justify-center overflow-auto bg-card/85 p-6",children:i.jsxs("div",{className:"w-full max-w-xl space-y-6",children:[i.jsxs("div",{className:"space-y-2 text-center",children:[i.jsx("h2",{className:"text-xl font-semibold",children:a("services.firstRun.title")}),i.jsx("p",{className:"text-sm text-muted-foreground",children:a("services.firstRun.desc")})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsx(CC,{icon:i.jsx(Pn,{className:"size-5"}),title:a("services.addFromGithub"),description:a("services.firstRun.githubDesc"),onClick:e,onAi:t,aiTitle:a("services.onboardWithAiHint")}),i.jsx(CC,{icon:i.jsx(fs,{className:"size-5"}),title:a("services.firstRun.createTitle"),description:a("services.firstRun.createDesc"),onClick:s,onAi:n,aiTitle:a("services.firstRun.createAiHint")})]})]})})}function CC({icon:e,title:t,description:s,onClick:n,onAi:a,aiTitle:l}){return i.jsxs("div",{className:"group flex items-stretch overflow-hidden rounded-lg border border-border bg-card shadow-sm transition-colors hover:border-foreground/20",children:[i.jsxs("button",{className:"flex flex-1 items-start gap-3 px-4 py-4 text-left hover:bg-muted/60",onClick:n,type:"button",children:[i.jsx("span",{className:"mt-0.5 shrink-0 text-muted-foreground",children:e}),i.jsxs("span",{className:"min-w-0 space-y-1",children:[i.jsx("span",{className:"block text-sm font-semibold",children:t}),i.jsx("span",{className:"block text-xs text-muted-foreground",children:s})]})]}),i.jsxs("button",{className:"flex shrink-0 items-center gap-1.5 border-l border-border px-4 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground",onClick:a,title:l,type:"button",children:[i.jsx(Xt,{className:"size-4 shrink-0"}),"AI"]})]})}function bX({health:e}){const t=ee();if(!e)return null;const s=e.processTree,n=e.status==="healthy"||e.status==="unknown"?void 0:_X(e.summary);return i.jsxs("div",{className:"mt-1.5 grid min-w-0 gap-2 text-[11px] text-muted-foreground sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center",children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i.jsxs("span",{className:oe("inline-flex h-7 shrink-0 items-center gap-1.5 rounded-md px-2.5 font-medium",vX(e.status)),children:[i.jsx("span",{className:"inline-flex shrink-0",children:i.jsx(mo,{className:"size-3"})}),i.jsx("span",{className:"whitespace-nowrap",children:e.status})]}),n?i.jsx("span",{className:"min-w-0 truncate",children:n}):null]}),s?i.jsxs("div",{className:"health-metrics flex min-w-max items-center gap-2 font-mono sm:justify-end",children:[i.jsxs("span",{className:"inline-flex items-center gap-1 font-mono",children:[i.jsx(IM,{className:"size-3"}),s.processCount," ",s.processCount===1?t("services.process"):t("services.processes")]}),i.jsxs("span",{children:[yX(s.cpuPercent)," CPU"]}),i.jsxs("span",{className:"inline-flex items-center gap-1 font-mono",children:[i.jsx(nD,{className:"size-3"}),xX(s.rssMb)," RAM"]})]}):null]})}function vX(e){return e==="healthy"?"bg-emerald-600 text-white":e==="warning"?"bg-amber-600 text-white":e==="unhealthy"?"bg-red-600 text-white":"bg-zinc-700 text-white"}function xX(e){return Number.isInteger(e)?`${e} MB`:`${e.toFixed(1)} MB`}function yX(e){return`${e.toFixed(1)}%`}function _X(e){return e.replace(/^Recent error log:\s*/i,"Recent stderr: ").replace(/:\s*\d+(?:\.\d+)? MB RSS\.?$/i,"").replace(/\s+RSS\.?$/i,"")}function wX({ports:e}){const t=ee(),s=e.filter(a=>a.state==="occupied").length,n=e.filter(a=>a.state==="managed").length;return i.jsxs(_i,{className:"rounded-none border-0 border-b border-border bg-transparent",children:[i.jsxs(wi,{className:"border-b border-border px-3 py-2",children:[i.jsxs(Si,{className:"flex items-center gap-2",children:[i.jsx(fD,{className:"size-3.5"}),t("services.ports")]}),i.jsx(ar,{className:"text-xs",children:t("services.portsSummary",{managed:n,occupied:s})})]}),i.jsx(ki,{className:"p-0",children:e.length?i.jsx("div",{className:"divide-y divide-border",children:e.map(a=>i.jsxs("div",{className:"grid grid-cols-[1fr_auto] items-center gap-2 px-3 py-2",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"font-mono text-xs",children:[":",a.port]}),i.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:a.services.join(", ")||t("services.unassigned")}),a.urls[0]?i.jsx("div",{className:"truncate font-mono text-[10px] text-muted-foreground",children:a.urls[0]}):null]}),i.jsx(SX,{port:a})]},a.port))}):i.jsx(Tf,{label:t("services.noPorts")})})]})}function SX({compact:e,port:t}){const s=ee(),n=t.state==="managed"?s("services.portManaged"):t.state==="occupied"?s("services.portOccupied"):s("services.portAvailable"),a=t.state==="managed"?"success":t.state==="occupied"?"warning":"outline";return i.jsx(Ke,{className:oe(e&&"max-w-36 truncate"),variant:a,children:n})}function kX({onChange:e,value:t}){const s=ee();return i.jsxs("div",{className:"relative block",children:[i.jsx(Wx,{className:"pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"}),i.jsx(pt,{"aria-label":s("services.log.search"),className:"h-8 w-44 pl-7 text-xs",onChange:n=>e(n.target.value),placeholder:s("services.log.search"),value:t})]})}function CX({className:e,containerRef:t,emptyText:s,logs:n,query:a,showTimestamps:l=!0,wrapLines:c=!0}){return i.jsx("div",{className:oe("code-font-size h-full max-w-full overflow-auto bg-background font-mono leading-5 dark:bg-zinc-950",e),ref:t,role:"log",children:n.length?n.map((d,f)=>i.jsxs("div",{className:oe("grid min-w-max gap-2 border-b border-border/45 px-3 py-0.5 dark:border-zinc-800/80",l?"grid-cols-[88px_minmax(420px,1fr)]":"grid-cols-[minmax(420px,1fr)]",d.stream==="stderr"?"bg-red-50/70 text-red-800 dark:bg-red-950/35 dark:text-red-100":"bg-emerald-50/35 text-zinc-800 dark:bg-zinc-950 dark:text-zinc-200 dark:odd:bg-zinc-900/45"),children:[l?i.jsx("span",{className:"text-muted-foreground dark:text-zinc-500",title:d.timestamp,children:NX(d.timestamp)}):null,i.jsxs("span",{className:c?"whitespace-pre-wrap break-words":"whitespace-pre",children:[d.stream==="stderr"?i.jsx("span",{className:"mr-2 rounded bg-red-100 px-1 font-semibold uppercase text-red-700 dark:bg-red-500/15 dark:text-red-300 dark:ring-1 dark:ring-red-400/20",children:"stderr"}):null,AX(d.text,a)]})]},jX(d,f))):i.jsx("div",{className:"p-3 text-muted-foreground",children:s})})}function NX(e){const t=/T(\d{2}:\d{2}:\d{2})(?:\.(\d{1,3}))?/.exec(e);return t?t[2]?`${t[1]}.${t[2]}`:t[1]:e}function EX(e){return`${e.timestamp} ${e.stream} ${e.text}`}function jX(e,t){return e.cursor??`${e.service}-${e.timestamp}-${e.stream}-${t}`}function AX(e,t){const s=t.trim();if(!s)return e;const n=e.toLowerCase(),a=s.toLowerCase(),l=[];let c=0,d=n.indexOf(a);for(;d!==-1;){d>c&&l.push(e.slice(c,d));const f=d+s.length;l.push(i.jsx("mark",{className:"rounded bg-amber-200 px-0.5 text-amber-950 dark:bg-amber-400/20 dark:text-amber-200",children:e.slice(d,f)},`${d}-${f}`)),c=f,d=n.indexOf(a,c)}return c<e.length&&l.push(e.slice(c)),l}function NC(e){return`${e.kind}:${e.name}`}function TX(e,t=!1,s={}){const[n,a]=x.useState(),[l,c]=x.useState(),[d,f]=x.useState(e.kind==="source"),h=JSON.stringify(s);return x.useEffect(()=>{a(void 0),c(void 0);let g=!1;const p=async()=>{try{if(e.kind==="service"){const v=await HE(e.name,s);g||(a(v.logs),f(v.queryable),c(void 0))}else{const v=await zE(e.name,s);g||(a(v),f(!0),c(void 0))}}catch(v){g||c(v instanceof Error?v.message:String(v))}};p();const b=window.setInterval(p,t?1e3:2e3);return()=>{g=!0,window.clearInterval(b)}},[e.kind,e.name,t,h]),{logs:n,error:l,queryable:d}}const RX=[{labelKey:"services.log.range.live",value:""},{labelKey:"services.log.range.15min",value:"15 min ago"},{labelKey:"services.log.range.hour",value:"1 hour ago"},{labelKey:"services.log.range.today",value:"today"},{labelKey:"services.log.range.24h",value:"1 day ago"},{labelKey:"services.log.range.7days",value:"7 days ago"}];function NA({target:e,query:t,setQuery:s,streaming:n,setStreaming:a,hideStdout:l,setHideStdout:c,fill:d=!1,leading:f,trailing:h}){const g=ee(),b=vm()?.confirmedProject.logs??{showTimestamps:!0,wrapLines:!0},v=e.kind==="source",[_,S]=x.useState(""),[C,N]=x.useState(""),[A,j]=x.useState(t);x.useEffect(()=>{const K=window.setTimeout(()=>j(t),300);return()=>window.clearTimeout(K)},[t]);const E=x.useMemo(()=>{const K={};_&&(K.since=_),C&&(K.level=C);const xe=A.trim();return xe&&(K.grep=xe),K},[_,C,A]),{logs:T,error:L,queryable:H}=TX(e,n,E),P=v||H,F=x.useRef(null),M=x.useRef(!0),[z,G]=x.useState([]),[D,q]=x.useState(!1),W=JSON.stringify(E);x.useEffect(()=>{G([])},[W,e.kind,e.name]);const I=x.useMemo(()=>{const K=T??[];if(z.length===0)return K;const xe=new Set(z.map(ie=>ie.cursor).filter(Boolean));return[...z,...K.filter(ie=>!ie.cursor||!xe.has(ie.cursor))]},[T,z]),Y=(z[0]??(T??[])[0])?.cursor;async function $(){if(!(!P||!Y||D)){q(!0),M.current=!1;try{const K={...E,before:Y,lines:200},xe=e.kind==="source"?await zE(e.name,K):(await HE(e.name,K)).logs;xe.length&&G(ie=>{const Z=new Set(ie.map(ne=>ne.cursor).filter(Boolean));return[...xe.filter(ne=>!ne.cursor||!Z.has(ne.cursor)),...ie]})}finally{q(!1)}}}const me=t.trim().toLowerCase(),J=x.useMemo(()=>{let K=I;return l&&(K=K.filter(xe=>xe.stream==="stderr")),me&&(K=K.filter(xe=>EX(xe).toLowerCase().includes(me))),K},[I,l,me]);x.useEffect(()=>{const K=F.current;if(!K)return;const xe=()=>{const ie=K.scrollHeight-K.scrollTop-K.clientHeight;M.current=ie<40};return xe(),K.addEventListener("scroll",xe,{passive:!0}),()=>K.removeEventListener("scroll",xe)},[]),x.useEffect(()=>{if(!n||!M.current||J.length===0)return;const K=F.current;K&&(K.scrollTop=K.scrollHeight)},[n,J]);const V=T?me?g("services.log.noMatch",{query:t.trim()}):g(l?"services.log.noStderr":"services.log.noEntries"):g("common.loading");return i.jsxs("div",{className:d?"flex h-full min-h-0 flex-col gap-2":"flex flex-col gap-2",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[f,i.jsx(kX,{onChange:s,value:t}),P?i.jsxs(i.Fragment,{children:[i.jsx("select",{"aria-label":g("services.log.timeRange"),className:"h-8 rounded-md border border-border bg-background px-2 text-xs",onChange:K=>S(K.target.value),value:_,children:RX.map(K=>i.jsx("option",{value:K.value,children:g(K.labelKey)},K.labelKey))}),i.jsxs("select",{"aria-label":g("services.log.level"),className:"h-8 rounded-md border border-border bg-background px-2 text-xs",onChange:K=>N(K.target.value),value:C,children:[i.jsx("option",{value:"",children:g("services.log.allLevels")}),i.jsx("option",{value:"warn",children:g("services.log.warningsPlus")}),i.jsx("option",{value:"error",children:g("services.log.errors")})]})]}):i.jsxs(EC,{active:l,activeClassName:"border-amber-600 bg-amber-50 text-amber-700 dark:border-amber-400/40 dark:bg-amber-500/15 dark:text-amber-300",onClick:()=>c(!l),children:[i.jsx(c6,{}),g("services.log.errorsOnly")]}),i.jsxs(EC,{active:n,activeClassName:"border-emerald-600 bg-emerald-50 text-emerald-700 dark:border-emerald-400/40 dark:bg-emerald-500/15 dark:text-emerald-300",onClick:()=>a(!n),children:[i.jsx(DD,{}),g(n?"services.log.streaming":"services.log.stream")]}),P&&Y?i.jsxs(Q,{disabled:D,onClick:()=>{$()},size:"sm",type:"button",variant:"outline",children:[i.jsx(Ff,{}),g(D?"common.loading":"services.log.loadOlder")]}):null,h?i.jsx("div",{className:"ml-auto flex items-center gap-2",children:h}):null]}),L?i.jsx("div",{className:"text-red-600",children:L}):null,i.jsx(CX,{className:oe("rounded border border-border/60",d?"min-h-0 flex-1":"max-h-80"),containerRef:F,emptyText:V,logs:J,query:t,showTimestamps:b.showTimestamps,wrapLines:b.wrapLines})]})}function EC({active:e,activeClassName:t,children:s,onClick:n}){return i.jsx(Q,{"aria-pressed":e,className:e?t:void 0,onClick:n,size:"sm",type:"button",variant:"outline",children:s})}function MX(e,t){return e.kind===t.kind&&e.name===t.name}function DX({options:e,target:t,onChange:s,className:n}){const a=ee(),l=e.findIndex(d=>MX(d.target,t)),c=[...new Set(e.map(d=>d.group))];return i.jsx("select",{"aria-label":a("services.logSource"),className:n??"h-8 max-w-44 rounded-md border border-border bg-background px-2 text-xs",onChange:d=>s(e[Number(d.target.value)].target),value:String(l),children:c.map(d=>i.jsx("optgroup",{label:d,children:e.map((f,h)=>f.group===d?i.jsx("option",{value:String(h),children:f.label},`${f.group}:${f.label}`):null)},d))})}function LX({serviceName:e}){const t=ee(),[s,n]=x.useState(""),[a,l]=x.useState(!1),[c,d]=x.useState(!1),[f,h]=x.useState(!1),g=i.jsx(NA,{fill:!0,hideStdout:c,query:s,setHideStdout:d,setQuery:n,setStreaming:l,streaming:a,target:{kind:"service",name:e},trailing:i.jsx(Q,{"aria-label":t(f?"services.logsView.exitFs":"services.logsView.expand"),className:"text-muted-foreground hover:text-foreground",onClick:()=>h(p=>!p),size:"icon-sm",title:t(f?"services.fsExit":"services.fsExpand"),type:"button",variant:"ghost",children:f?i.jsx(Vx,{}):i.jsx(Gx,{})})});return f?i.jsx(Y0,{onClose:()=>h(!1),title:t("services.logsTitle",{name:e}),children:g}):i.jsx("div",{className:"h-[60vh] min-h-[24rem]",children:g})}function Y0({title:e,onClose:t,children:s,maxWidthClass:n="max-w-6xl"}){const a=ee();return x.useEffect(()=>{function l(c){c.key==="Escape"&&t()}return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[t]),Ii.createPortal(i.jsx("div",{className:"fixed inset-0 z-[1000] bg-black/40 p-4 sm:p-8",onMouseDown:t,children:i.jsxs("div",{"aria-modal":"true",className:`mx-auto flex h-full ${n} flex-col overflow-hidden rounded-lg border border-border bg-card text-xs shadow-xl`,onMouseDown:l=>l.stopPropagation(),role:"dialog",children:[i.jsxs("div",{className:"flex shrink-0 items-center gap-3 border-b border-border px-4 py-2",children:[i.jsx("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold",children:e}),i.jsx(Q,{"aria-label":a("services.closeLogs"),onClick:t,size:"icon",type:"button",variant:"ghost",children:i.jsx(Vt,{})})]}),i.jsx("div",{className:"min-h-0 flex-1 p-3",children:s})]})}),document.body)}const OX={journald:"services.log.hint.journald",docker:"services.log.hint.docker",ssh:"services.log.hint.ssh",file:"services.log.hint.file",command:"services.log.hint.command"};function PX({onClose:e,onAdded:t}){const s=ee(),[n,a]=x.useState(""),[l,c]=x.useState("journald"),[d,f]=x.useState(""),[h,g]=x.useState(""),[p,b]=x.useState(""),[v,_]=x.useState(""),[S,C]=x.useState(""),[N,A]=x.useState(""),[j,E]=x.useState(),[T,L]=x.useState(!1);async function H(){L(!0),E(void 0);try{const P={name:n.trim(),kind:"command"};l==="file"?(P.kind="file",P.path=h.trim()):l==="ssh"?(P.kind="ssh",P.host=d.trim(),P.path=h.trim()):l==="command"?(P.kind="command",P.command=p.trim(),v.trim()&&(P.cwd=v.trim())):l==="journald"?(P.driver="journald",P.unit=S.trim(),d.trim()&&(P.host=d.trim())):l==="docker"&&(P.driver="docker",P.container=N.trim(),d.trim()&&(P.host=d.trim()));const F=await O7(P);t(F,P.name),e()}catch(P){E(P instanceof Error?P.message:String(P))}finally{L(!1)}}return i.jsx(ei,{icon:i.jsx(pE,{}),onClose:e,size:"md",title:s("services.log.addSourceTitle"),children:i.jsxs("form",{className:"flex flex-col gap-3 p-4 text-xs",onSubmit:P=>{P.preventDefault(),H()},children:[i.jsx(Ar,{label:s("services.log.name"),children:i.jsx(pt,{autoFocus:!0,onChange:P=>a(P.target.value),placeholder:"PROD",value:n})}),i.jsxs(Ar,{label:s("services.log.type"),children:[i.jsxs("select",{className:"h-9 w-full rounded-md border border-border bg-background px-2 text-xs",onChange:P=>c(P.target.value),value:l,children:[i.jsx("option",{value:"journald",children:s("services.log.typeJournald")}),i.jsx("option",{value:"docker",children:s("services.log.typeDocker")}),i.jsx("option",{value:"ssh",children:s("services.log.typeSsh")}),i.jsx("option",{value:"file",children:s("services.log.typeFile")}),i.jsx("option",{value:"command",children:s("services.log.typeCommand")})]}),i.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:s(OX[l])})]}),l==="journald"||l==="docker"?i.jsx(Ar,{label:s("services.log.hostOptional"),children:i.jsx(pt,{onChange:P=>f(P.target.value),placeholder:"jobjourney-prod (an alias from ~/.ssh/config)",value:d})}):null,l==="journald"?i.jsx(Ar,{label:s("services.log.unit"),children:i.jsx(pt,{onChange:P=>C(P.target.value),placeholder:"jobjourney",value:S})}):null,l==="docker"?i.jsx(Ar,{label:s("services.log.container"),children:i.jsx(pt,{onChange:P=>A(P.target.value),placeholder:"brainctl-api",value:N})}):null,l==="ssh"?i.jsx(Ar,{label:s("services.log.host"),children:i.jsx(pt,{onChange:P=>f(P.target.value),placeholder:"prod (an alias from ~/.ssh/config)",value:d})}):null,l==="file"||l==="ssh"?i.jsx(Ar,{label:s(l==="ssh"?"services.log.remotePath":"services.log.filePath"),children:i.jsx(pt,{onChange:P=>g(P.target.value),placeholder:"/var/log/app/out.log",value:h})}):null,l==="command"?i.jsxs(i.Fragment,{children:[i.jsx(Ar,{label:s("services.log.command"),children:i.jsx(pt,{onChange:P=>b(P.target.value),placeholder:"kubectl logs -l app=myapp --tail 500",value:p})}),i.jsx(Ar,{label:s("services.log.cwdOptional"),children:i.jsx(pt,{onChange:P=>_(P.target.value),placeholder:"/srv/app",value:v})})]}):null,j?i.jsx("div",{className:"text-red-600",children:j}):null,i.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[i.jsx(Q,{onClick:e,size:"sm",type:"button",variant:"outline",children:s("common.cancel")}),i.jsx(Q,{disabled:T||!n.trim(),size:"sm",type:"submit",children:s(T?"common.saving":"services.log.addSource")})]})]})})}function Ar({label:e,children:t}){return i.jsxs("label",{className:"flex flex-col gap-1",children:[i.jsx("span",{className:"font-medium text-muted-foreground",children:e}),t]})}const jC=4;function zX({services:e,initialService:t,onClose:s}){const n=ee(),[a,l]=x.useState([]),[c,d]=x.useState(!1),[f,h]=x.useState(()=>[0]),[g,p]=x.useState(()=>{const E=t?{kind:"service",name:t}:e[0]?{kind:"service",name:e[0]}:void 0;return E?{0:E}:{}}),b=x.useRef(1);x.useEffect(()=>{let E=!1;return L7().then(T=>{E||l(T)}),()=>{E=!0}},[]);const v=[...e.map(E=>({target:{kind:"service",name:E},label:E,group:n("services.title")})),...a.map(E=>({target:{kind:"source",name:E.name},label:E.name,group:n("services.log.sourcesGroup")}))],_=v.map(E=>E.target);function S(){if(f.length>=jC||_.length===0)return;const E=b.current++,T=new Set(Object.values(g).map(NC)),L=_.find(H=>!T.has(NC(H)))??_[0];h(H=>[...H,E]),p(H=>({...H,[E]:L}))}function C(E){h(T=>T.filter(L=>L!==E)),p(T=>{const L={...T};return delete L[E],L})}function N(E,T){p(L=>({...L,[E]:T}))}function A(E,T){l(E);const L=f[0];L!==void 0&&N(L,{kind:"source",name:T})}const j=i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{children:n("services.logs")}),i.jsxs(Q,{onClick:()=>d(!0),size:"sm",type:"button",variant:"outline",children:[i.jsx(fs,{}),n("services.log.addSource")]}),i.jsxs(Q,{disabled:f.length>=jC||_.length===0,onClick:S,size:"sm",type:"button",variant:"outline",children:[i.jsx(fs,{}),n("services.log.addPane")]})]});return i.jsxs(i.Fragment,{children:[i.jsx(Y0,{maxWidthClass:"max-w-[1500px]",onClose:s,title:j,children:_.length===0?i.jsx("div",{className:"grid h-full place-items-center text-center text-muted-foreground",children:i.jsxs("div",{children:[i.jsx("p",{children:n("services.log.noneYet")}),i.jsxs(Q,{className:"mt-2",onClick:()=>d(!0),size:"sm",type:"button",children:[i.jsx(fs,{}),n("services.log.addLogSource")]})]})}):i.jsx("div",{className:oe("grid h-full min-h-0 gap-3",f.length>1?"lg:grid-cols-2":"grid-cols-1",f.length>2?"lg:grid-rows-2":"grid-rows-1"),children:f.map(E=>i.jsx(BX,{onChangeTarget:T=>N(E,T),onRemove:f.length>1?()=>C(E):void 0,options:v,target:g[E]??_[0]},E))})}),c?i.jsx(PX,{onAdded:A,onClose:()=>d(!1)}):null]})}function BX({options:e,target:t,onChangeTarget:s,onRemove:n}){const a=ee(),[l,c]=x.useState(""),[d,f]=x.useState(!0),[h,g]=x.useState(!1);return i.jsx("div",{className:"flex min-h-0 min-w-0 flex-col rounded-lg border border-border bg-background/60 p-2",children:i.jsx(NA,{fill:!0,hideStdout:h,leading:i.jsx(DX,{onChange:s,options:e,target:t}),query:l,setHideStdout:g,setQuery:c,setStreaming:f,streaming:d,target:t,trailing:n?i.jsx(Q,{"aria-label":a("services.log.removePane"),onClick:n,size:"icon",type:"button",variant:"ghost",children:i.jsx(Vt,{})}):void 0})})}function IX({runtime:e,reloading:t,onReload:s}){const n=ee();if(!e?.stale)return null;const a=e.staleFiles,l=a.length===1?n("services.env.staleOne",{file:a[0].relativePath}):n("services.env.staleMany",{count:a.length});return i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded border border-amber-500/40 bg-amber-500/10 px-2.5 py-1.5 text-amber-700 dark:text-amber-400",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Lr,{className:"size-4 shrink-0"}),i.jsx("span",{children:n("services.env.staleBanner",{summary:l})})]}),i.jsxs(Q,{disabled:t,onClick:s,size:"sm",type:"button",variant:"outline",children:[i.jsx(zD,{})," ",n(t?"services.env.reloading":"services.env.reloadService")]})]})}function HX({rows:e,revealAll:t,onAdd:s,onRemove:n,onUpdate:a}){const l=ee();return e.length===0?i.jsxs("div",{className:"text-muted-foreground",children:[l("services.env.noVars")," ",i.jsx("button",{className:"underline",onClick:s,type:"button",children:l("services.env.addOne")}),"."]}):i.jsx("div",{className:"overflow-x-auto",children:i.jsxs("table",{className:"w-full font-mono text-[11px]",children:[i.jsx("thead",{className:"text-left text-muted-foreground",children:i.jsxs("tr",{children:[i.jsx("th",{className:"py-1 pr-3",children:l("services.env.key")}),i.jsx("th",{className:"py-1 pr-3",children:l("services.env.value")}),i.jsx("th",{className:"py-1 w-8"})]})}),i.jsx("tbody",{children:e.map((c,d)=>{const f=!c.reveal&&!t;return i.jsxs("tr",{className:"border-t border-border/40",children:[i.jsx("td",{className:"py-1 pr-3 align-top",children:i.jsx("input",{className:"w-full rounded border border-border/60 bg-background px-1.5 py-0.5 font-mono",onChange:h=>a(d,{key:h.target.value}),placeholder:"KEY",spellCheck:!1,value:c.key})}),i.jsx("td",{className:"py-1 pr-3 align-top",children:i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("input",{className:"w-full rounded border border-border/60 bg-background px-1.5 py-0.5 font-mono",onChange:h=>a(d,{value:h.target.value}),spellCheck:!1,type:f?"password":"text",value:c.value}),i.jsx("button",{className:"text-muted-foreground hover:text-foreground",onClick:()=>a(d,{reveal:!c.reveal}),title:c.reveal||t?l("services.env.hide"):l("services.env.reveal"),type:"button",children:c.reveal||t?i.jsx(Hx,{size:14}):i.jsx(Gf,{size:14})})]})}),i.jsx("td",{className:"py-1 align-top",children:i.jsx("button",{className:"text-muted-foreground hover:text-red-600",onClick:()=>n(d),type:"button",children:i.jsx(Bi,{size:14})})})]},d)})})]})})}function $X({serviceName:e,onClose:t,onPick:s}){const n=ee(),[a,l]=x.useState(),[c,d]=x.useState(),[f,h]=x.useState(!0),[g,p]=x.useState();x.useEffect(()=>{let _=!1;return h(!0),d(void 0),(async()=>{try{const S=await Y7(e,g);_||l(S)}catch(S){_||d(S instanceof Error?S.message:String(S))}finally{_||h(!1)}})(),()=>{_=!0}},[e,g]);function b(_){if(_.kind==="directory"){p(_.relativePath);return}_.supported&&s(_.relativePath)}function v(){if(!a||a.isRoot)return;const _=a.relativePath,S=_.includes("/")?_.slice(0,_.lastIndexOf("/")):"";p(S||void 0)}return i.jsx(ei,{icon:i.jsx(Vf,{}),onClose:t,size:"lg",title:n("services.fileBrowser.title"),children:i.jsxs("div",{className:"flex flex-col gap-2 p-4",children:[i.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[i.jsxs(Q,{disabled:!a||a.isRoot,onClick:v,size:"sm",type:"button",variant:"outline",children:[i.jsx(Ff,{})," ",n("services.fileBrowser.up")]}),i.jsx("code",{className:"truncate rounded bg-muted px-2 py-1 font-mono",children:a?.relativePath||"./"})]}),c?i.jsx("div",{className:"text-red-600",children:c}):f?i.jsx("div",{className:"text-muted-foreground",children:n("common.loading")}):!a||a.entries.length===0?i.jsx("div",{className:"text-muted-foreground",children:n("services.fileBrowser.empty")}):i.jsx("div",{className:"max-h-[50vh] overflow-auto rounded border border-border/60",children:i.jsx("ul",{className:"divide-y divide-border/40",children:a.entries.map(_=>{const S=_.kind==="directory",C=S||_.supported;return i.jsx("li",{children:i.jsxs("button",{className:oe("flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs",C?"hover:bg-muted":"cursor-not-allowed text-muted-foreground"),disabled:!C,onClick:()=>b(_),type:"button",children:[S?i.jsx(ko,{size:14}):i.jsx(oE,{size:14}),i.jsx("span",{className:"flex-1 truncate font-mono",children:_.name}),!S&&_.format?i.jsx(Ke,{size:"small",variant:"secondary",children:_.format}):null]})},_.relativePath)})})}),i.jsxs("p",{className:"text-xs text-muted-foreground",children:[n("services.fileBrowser.hintPre")," ",i.jsx("code",{children:".env*"}),", ",i.jsx("code",{children:"appsettings*.json"})," ",n("services.fileBrowser.hintAnd")," ",i.jsx("code",{children:"application*.yml"}),n("services.fileBrowser.hintTail")]})]})})}function FX(e){const{error:t,success:s}=ms(),[n,a]=x.useState(),[l,c]=x.useState(!1),d=x.useCallback(async()=>{try{a(await J7(e))}catch{a(void 0)}},[e]);x.useEffect(()=>{d()},[d]);const f=x.useCallback(async()=>{c(!0);try{await IE(e),s(`Reloaded ${e} with the latest configuration.`),await d()}catch(h){t(h instanceof Error?h.message:String(h))}finally{c(!1)}},[e,d,t,s]);return{runtime:n,reloading:l,refresh:d,reload:f}}function EA(e){if(!e.trim())return e;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function UX(e){const{error:t,success:s}=ms(),[n,a]=x.useState([]),[l,c]=x.useState(),[d,f]=x.useState(),[h,g]=x.useState(!0),[p,b]=x.useState(!1),[v,_]=x.useState(!1),[S,C]=x.useState(!1),[N,A]=x.useState();x.useEffect(()=>{let M=!1;return g(!0),A(void 0),(async()=>{try{const z=await X7(e);if(M)return;a(z.files),z.files.length>0?c(G=>G??z.files[0].path):(c(void 0),f(void 0))}catch(z){M||A(z instanceof Error?z.message:String(z))}finally{M||g(!1)}})(),()=>{M=!0}},[e]);const j=x.useCallback(async M=>{b(!0),A(void 0);try{const z=await gS(e,M),G={path:z.path,relativePath:z.relativePath,format:z.format};z.format==="env"?f({info:G,exists:z.exists,rows:z.entries.map(D=>({...D,reveal:!1}))}):f({info:G,exists:z.exists,text:z.format==="json"?EA(z.content):z.content}),C(!1)}catch(z){A(z instanceof Error?z.message:String(z))}finally{b(!1)}},[e]);x.useEffect(()=>{l&&j(l)},[l,j]);function E(M,z){f(G=>{if(!G?.rows)return G;const D=G.rows.map((q,W)=>W===M?{...q,...z}:q);return{...G,rows:D}}),C(!0)}function T(){f(M=>M?.rows?{...M,rows:[...M.rows,{key:"",value:"",secret:!1,reveal:!0}]}:M),C(!0)}function L(M){f(z=>z?.rows?{...z,rows:z.rows.filter((G,D)=>D!==M)}:z),C(!0)}function H(M){f(z=>z&&{...z,text:M}),C(!0)}async function P(){if(d){_(!0);try{if(d.info.format==="env"&&d.rows){const M=await Z7(e,d.info.path,d.rows.map(z=>({key:z.key.trim(),value:z.value})));f({info:{path:M.path,relativePath:M.relativePath,format:M.format},exists:M.exists,rows:M.entries.map(z=>({...z,reveal:!1}))}),s(`Saved ${M.entries.length} entries to ${M.relativePath}.`)}else if(d.text!==void 0){const M=await Q7(e,d.info.path,d.text);f({info:{path:M.path,relativePath:M.relativePath,format:M.format},exists:M.exists,text:M.content}),s(`Saved ${M.relativePath}.`)}C(!1)}catch(M){t(M instanceof Error?M.message:String(M))}finally{_(!1)}}}async function F(M){try{const z=await gS(e,M),G={path:z.path,relativePath:z.relativePath,format:z.format};return a(D=>D.some(q=>q.path===G.path)?D:[...D,G]),c(G.path),s(`Loaded ${G.relativePath}.`),!0}catch(z){return t(z instanceof Error?z.message:String(z)),!1}}return{files:n,selectedPath:l,setSelectedPath:c,loaded:d,loadingList:h,loadingFile:p,saving:v,dirty:S,error:N,addRow:T,removeRow:L,updateRow:E,updateText:H,save:P,pickFile:F}}function qX({serviceName:e}){const t=ee(),{files:s,selectedPath:n,setSelectedPath:a,loaded:l,loadingList:c,loadingFile:d,saving:f,dirty:h,error:g,addRow:p,removeRow:b,updateRow:v,updateText:_,save:S,pickFile:C}=UX(e),N=FX(e),[A,j]=x.useState(!1),[E,T]=x.useState(!1);async function L(){await S(),await N.refresh()}return c?i.jsx("div",{className:"text-muted-foreground",children:t("common.loading")}):g&&!l?i.jsx("div",{className:"text-red-600",children:g}):i.jsxs("div",{className:"space-y-2",children:[i.jsx(IX,{onReload:()=>{N.reload()},reloading:N.reloading,runtime:N.runtime}),i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"text-muted-foreground",children:t("services.env.file")}),s.length>0?i.jsx("select",{className:"rounded border border-border/60 bg-background px-1.5 py-0.5 font-mono text-xs",onChange:H=>a(H.target.value),value:n??"",children:s.map(H=>i.jsxs("option",{value:H.path,children:[H.relativePath," [",H.format,"]"]},H.path))}):i.jsx("span",{className:"text-muted-foreground",children:t("services.env.noneDetected")}),i.jsxs(Q,{onClick:()=>T(!0),size:"sm",type:"button",variant:"outline",children:[i.jsx(Vf,{})," ",t("services.env.browseFiles")]}),l?i.jsx("code",{className:"rounded bg-background px-1.5 py-0.5 font-mono text-muted-foreground",children:l.info.path}):null]}),i.jsxs("div",{className:"flex items-center gap-1",children:[l?.info.format==="env"?i.jsxs(i.Fragment,{children:[i.jsxs(Q,{onClick:()=>j(H=>!H),size:"sm",type:"button",variant:"outline",children:[A?i.jsx(Hx,{}):i.jsx(Gf,{}),t(A?"services.env.hideSecrets":"services.env.revealSecrets")]}),i.jsxs(Q,{onClick:p,size:"sm",type:"button",variant:"outline",children:[i.jsx(fs,{})," ",t("common.add")]})]}):null,i.jsxs(Q,{disabled:!h||f||!l,onClick:()=>{L()},size:"sm",type:"button",children:[i.jsx(mE,{})," ",t(f?"common.saving":"common.save")]})]})]}),g&&!l?i.jsx("div",{className:"text-red-600",children:g}):l?.info.format==="env"&&l.rows?i.jsx("div",{className:oe(d&&"opacity-60 transition-opacity"),children:i.jsx(HX,{revealAll:A,rows:l.rows,onAdd:p,onRemove:b,onUpdate:v})}):l?.text!==void 0?i.jsxs("div",{className:oe("space-y-1",d&&"opacity-60 transition-opacity"),children:[l.info.format==="json"?i.jsx("div",{className:"flex justify-end",children:i.jsx(Q,{onClick:()=>_(EA(l.text??"")),size:"sm",type:"button",variant:"outline",children:t("services.env.formatJson")})}):null,i.jsx("textarea",{className:"min-h-[300px] w-full rounded border border-border/60 bg-background p-2 font-mono text-[11px] leading-relaxed",onChange:H=>_(H.target.value),spellCheck:!1,value:l.text})]}):d?i.jsx("div",{className:"text-muted-foreground",children:t("services.env.loadingFile")}):null,l?i.jsxs("p",{className:"text-muted-foreground",children:[l.info.format==="env"?t("services.env.preservedEnv"):l.info.format==="json"?t("services.env.validatedJson"):t("services.env.rawYaml")," ",t("services.env.restartHint")]}):null,E?i.jsx($X,{onClose:()=>T(!1),onPick:H=>{C(H).then(P=>{P&&T(!1)})},serviceName:e}):null]})}function GX({serviceName:e,status:t,timeline:s,onRefresh:n}){const a=ee(),{error:l,success:c}=ms(),[d,f]=x.useState(!1),h=t?.inspector,g=t?.state==="running",p=x.useMemo(()=>s.filter(_=>_.kind==="service.http"&&_.service===e).map(_=>{const S=_.data??{};return{id:S.id??_.id,startedAt:_.timestamp,method:S.method??"?",path:S.path??"?",status:S.status??0,durationMs:S.durationMs??0,reqBytes:S.reqBytes??0,resBytes:S.resBytes??0}}).slice(-500).reverse(),[s,e]);async function b(_){f(!0);try{await Pi(`/api/services/${encodeURIComponent(e)}/inspector`,{enabled:_?"true":"false"}),await n(),c(_?a("services.http.started",{name:e}):a("services.http.stopped",{name:e}))}catch(S){l(S instanceof Error?S.message:String(S))}finally{f(!1)}}if(!g)return i.jsx("div",{className:"text-muted-foreground",children:a("services.http.notRunning")});if(!h?.enabled)return i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-muted-foreground",children:a("services.http.intro")}),i.jsxs(Q,{disabled:d,onClick:()=>b(!0),size:"sm",type:"button",children:[i.jsx(Or,{})," ",a("services.http.start")]})]});const v=h.port?`http://127.0.0.1:${h.port}`:void 0;return i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"text-muted-foreground",children:a("services.http.inspectUrl")}),v?i.jsxs(i.Fragment,{children:[i.jsx("code",{className:"rounded bg-background px-1.5 py-0.5 font-mono",children:v}),i.jsxs(Q,{onClick:()=>{navigator.clipboard.writeText(v),c(a("services.http.copiedUrl"))},size:"sm",type:"button",variant:"outline",children:[i.jsx(ef,{})," ",a("common.copy")]}),i.jsx(Q,{onClick:()=>{Qf(v)},size:"sm",type:"button",variant:"outline",children:a("common.open")})]}):i.jsx("span",{className:"text-muted-foreground",children:a("services.startingEllipsis")}),i.jsx("span",{className:"text-muted-foreground",children:a("services.http.upstream",{port:h.upstreamPort??"?"})}),i.jsxs(Q,{disabled:d,onClick:()=>b(!1),size:"sm",type:"button",variant:"outline",children:[i.jsx(xo,{})," ",a("common.stop")]})]}),p.length===0?i.jsx("div",{className:"text-muted-foreground",children:a("services.http.noRequests")}):i.jsx("div",{className:"max-h-80 overflow-auto",children:i.jsxs("table",{className:"w-full font-mono text-[11px]",children:[i.jsx("thead",{className:"sticky top-0 bg-muted/60 text-left text-muted-foreground",children:i.jsxs("tr",{children:[i.jsx("th",{className:"py-1 pr-3",children:a("services.http.time")}),i.jsx("th",{className:"py-1 pr-3",children:a("services.http.method")}),i.jsx("th",{className:"py-1 pr-3",children:a("services.http.path")}),i.jsx("th",{className:"py-1 pr-3 text-right",children:a("services.http.status")}),i.jsx("th",{className:"py-1 pr-3 text-right",children:a("services.http.size")}),i.jsx("th",{className:"py-1 pr-3 text-right",children:"ms"})]})}),i.jsx("tbody",{children:p.map(_=>i.jsxs("tr",{className:"border-t border-border/40",children:[i.jsx("td",{className:"py-1 pr-3 text-muted-foreground",children:new Date(_.startedAt).toLocaleTimeString()}),i.jsx("td",{className:"py-1 pr-3",children:_.method}),i.jsx("td",{className:"py-1 pr-3 truncate max-w-[40ch]",children:_.path}),i.jsx("td",{className:oe("py-1 pr-3 text-right",VX(_.status)),children:_.status}),i.jsx("td",{className:"py-1 pr-3 text-right text-muted-foreground",children:WX(_.resBytes)}),i.jsx("td",{className:"py-1 pr-3 text-right",children:_.durationMs.toFixed(1)})]},_.id))})]})})]})}function VX(e){return e>=500?"text-red-600 dark:text-red-400":e>=400?"text-amber-600 dark:text-amber-400":e>=300?"text-zinc-500":e>=200?"text-emerald-600 dark:text-emerald-400":"text-muted-foreground"}function WX(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function KX({serviceName:e}){const t=ee(),[s,n]=x.useState(null),[a,l]=x.useState(null),[c,d]=x.useState(()=>Date.now());return x.useEffect(()=>{let f=!1;async function h(){try{const p=await e9(e);f||(n(p),d(Date.now()),l(null))}catch(p){f||l(p instanceof Error?p.message:String(p))}}h();const g=setInterval(()=>{h()},3e3);return()=>{f=!0,clearInterval(g)}},[e]),a?i.jsx("p",{className:"text-destructive",children:t("services.metrics.loadError",{error:a})}):s?s.samples.length===0?i.jsx("p",{className:"text-muted-foreground",children:t("services.metrics.noSamples")}):i.jsx(YX,{series:s,now:c}):i.jsx("p",{className:"text-muted-foreground",children:t("services.metrics.loading")})}function YX({series:e,now:t}){const s=ee(),{samples:n}=e,a=x.useMemo(()=>AC(n,h=>h.cpu),[n]),l=x.useMemo(()=>AC(n,h=>h.rss),[n]),c=e.startedAt?new Date(e.startedAt):null,d=c?t-c.getTime():null,f=n.length>1?n[n.length-1].t-n[0].t:0;return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[i.jsx(Rh,{accent:"#22c55e",label:"CPU",value:`${a.last.toFixed(1)}%`,sub:s("services.metrics.peakAvg",{peak:`${a.max.toFixed(1)}%`,avg:`${a.avg.toFixed(1)}%`})}),i.jsx(Rh,{accent:"#3b82f6",label:s("services.metrics.memory"),value:Sb(l.last),sub:s("services.metrics.peakAvg",{peak:Sb(l.max),avg:Sb(l.avg)})}),i.jsx(Rh,{accent:"#a855f7",label:s("services.metrics.uptime"),value:d!=null?MC(d):"—",sub:c?s("services.metrics.since",{time:c.toLocaleTimeString()}):s("services.metrics.notRunning")}),i.jsx(Rh,{accent:"#f59e0b",label:s("services.metrics.samples"),value:String(n.length),sub:f?s("services.metrics.over",{dur:MC(f)}):s("services.metrics.collecting")})]}),i.jsx(RC,{label:"CPU",samples:n,pick:h=>h.cpu,summary:a,color:"#22c55e",suffix:"%",unit:"percent"}),i.jsx(RC,{label:s("services.metrics.memoryRss"),samples:n,pick:h=>h.rss,summary:l,color:"#3b82f6",suffix:" MB",unit:"mb"})]})}function AC(e,t){const s=e.map(t),n=s.reduce((a,l)=>a+l,0);return{last:s[s.length-1],max:Math.max(...s),min:Math.min(...s),avg:n/s.length}}function Rh({accent:e,label:t,value:s,sub:n}){return i.jsxs("div",{className:"rounded-lg border border-border bg-card px-3 py-2",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full",style:{backgroundColor:e}}),i.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:t})]}),i.jsx("div",{className:"mt-1 font-mono text-lg leading-none tabular-nums",children:s}),i.jsx("div",{className:"mt-1 truncate font-mono text-[10px] text-muted-foreground",children:n})]})}const hl=160,TC=44,XX=20;function RC({label:e,samples:t,pick:s,summary:n,color:a,suffix:l,unit:c}){const d=ee(),f=x.useMemo(()=>`metric-grad-${c}-${Math.random().toString(36).slice(2,8)}`,[c]),h=t.map(s),g=Math.max(...h,c==="percent"?10:1),p=ZX(g),b=0,v=p-b||1,_=t[0].t,S=t[t.length-1].t,C=Math.max(1,S-_),N=z=>(z-_)/C*1e3,A=z=>(1-(z-b)/v)*1e3,j=t.map(z=>`${N(z.t).toFixed(1)},${A(s(z)).toFixed(1)}`),E=`M0,1000 L${j.join(" L")} L1000,1000 Z`,T=`M${j.join(" L")}`,L=N(S),H=A(n.last),P=A(n.avg),F=[1,.75,.5,.25,0],M=5;return i.jsxs("figure",{className:"space-y-1",children:[i.jsxs("figcaption",{className:"flex items-baseline justify-between",children:[i.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:e}),i.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:[d("services.metrics.wNow")," ",i.jsxs("span",{className:"text-foreground",children:[n.last.toFixed(1),l]}),i.jsx("span",{className:"mx-1.5",children:"·"}),d("services.metrics.wPeak")," ",n.max.toFixed(1),l,i.jsx("span",{className:"mx-1.5",children:"·"}),d("services.metrics.wAvg")," ",n.avg.toFixed(1),l]})]}),i.jsxs("div",{className:"rounded-lg border border-border bg-card p-2",children:[i.jsxs("div",{className:"flex",children:[i.jsx("div",{className:"relative flex shrink-0 flex-col justify-between text-right font-mono text-[10px] text-muted-foreground",style:{width:TC,height:hl},children:F.map(z=>i.jsx("span",{className:"pr-1 leading-none",children:QX(b+z*v,c)},z))}),i.jsxs("div",{className:"relative min-w-0 flex-1",style:{height:hl},children:[F.map((z,G)=>i.jsx("div",{className:"pointer-events-none absolute inset-x-0 border-t border-border/40",style:{top:`${z===1?0:z===0?hl-1:(1-z)*hl}px`,borderStyle:G===F.length-1?"solid":"dashed"}},z)),i.jsx("div",{className:"pointer-events-none absolute inset-x-0 border-t border-dashed",style:{top:`${P/1e3*hl}px`,borderColor:a,opacity:.4}}),i.jsxs("svg",{"aria-label":e,className:"absolute inset-0 h-full w-full",preserveAspectRatio:"none",role:"img",viewBox:"0 0 1000 1000",children:[i.jsx("defs",{children:i.jsxs("linearGradient",{id:f,x1:"0",x2:"0",y1:"0",y2:"1",children:[i.jsx("stop",{offset:"0%",stopColor:a,stopOpacity:.35}),i.jsx("stop",{offset:"100%",stopColor:a,stopOpacity:.02})]})}),i.jsx("path",{d:E,fill:`url(#${f})`}),i.jsx("path",{d:T,fill:"none",stroke:a,strokeWidth:2,vectorEffect:"non-scaling-stroke",strokeLinejoin:"round",strokeLinecap:"round"})]}),i.jsx("span",{className:"pointer-events-none absolute z-10 block h-2.5 w-2.5 -translate-x-1/2 -translate-y-1/2 rounded-full ring-2 ring-card",style:{left:`${L/1e3*100}%`,top:`${H/1e3*hl}px`,backgroundColor:a,boxShadow:`0 0 0 4px ${a}33`}})]})]}),i.jsx("div",{className:"flex font-mono text-[10px] text-muted-foreground",style:{height:XX,paddingLeft:TC},children:i.jsx("div",{className:"relative flex-1",children:Array.from({length:M+1},(z,G)=>{const D=G/M,q=_+D*C;return i.jsx("span",{className:"absolute top-1 whitespace-nowrap",style:{left:`${D*100}%`,transform:G===0?"translateX(0)":G===M?"translateX(-100%)":"translateX(-50%)"},children:JX(q-S)},G)})})})]})]})}function ZX(e){if(e<=1)return 1;const t=Math.pow(10,Math.floor(Math.log10(e))),s=e/t;return(s<=1?1:s<=2?2:s<=5?5:10)*t}function QX(e,t){return t==="percent"?`${e.toFixed(0)}%`:e>=1024?`${(e/1024).toFixed(1)}G`:`${e.toFixed(0)}M`}function Sb(e){return e>=1024?`${(e/1024).toFixed(2)} GB`:`${e.toFixed(0)} MB`}function MC(e){const t=Math.max(0,Math.round(e/1e3));if(t<60)return`${t}s`;const s=Math.floor(t/60);if(s<60)return`${s}m ${t%60}s`;const n=Math.floor(s/60);return n<24?`${n}h ${s%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function JX(e){const t=Math.round(e/1e3);if(t===0)return"now";if(Math.abs(t)<60)return`${t}s`;const n=Math.round(t/60);return Math.abs(n)<60?`${n}m`:`${Math.round(n/60)}h`}function eZ({rows:e,running:t}){const s=ee();if(e.length===0)return i.jsx("div",{className:"text-muted-foreground",children:s(t?"services.proc.emptyRunning":"services.proc.emptyStopped")});const n=[...e].sort((l,c)=>c.cpuPercent-l.cpuPercent),a=new Set(e.map(l=>l.pid));return i.jsx("div",{className:"overflow-x-auto",children:i.jsxs("table",{className:"w-full font-mono text-[11px]",children:[i.jsx("thead",{className:"text-left text-muted-foreground",children:i.jsxs("tr",{children:[i.jsx("th",{className:"py-1 pr-3",children:"PID"}),i.jsx("th",{className:"py-1 pr-3",children:"PPID"}),i.jsx("th",{className:"py-1 pr-3 text-right",children:"CPU%"}),i.jsx("th",{className:"py-1 pr-3 text-right",children:"RSS MB"}),i.jsx("th",{className:"py-1",children:s("services.proc.command")})]})}),i.jsx("tbody",{children:n.map(l=>{const c=a.has(l.ppid);return i.jsxs("tr",{className:"border-t border-border/40",children:[i.jsx("td",{className:"py-1 pr-3",children:l.pid}),i.jsx("td",{className:"py-1 pr-3 text-muted-foreground",children:l.ppid}),i.jsx("td",{className:"py-1 pr-3 text-right",children:l.cpuPercent.toFixed(1)}),i.jsx("td",{className:"py-1 pr-3 text-right",children:l.rssMb.toFixed(1)}),i.jsx("td",{className:oe("py-1 truncate max-w-[60ch]",c&&"pl-4"),children:l.command})]},l.pid)})})]})})}const DC={connecting:"bg-amber-500",running:"bg-emerald-500",exited:"bg-muted-foreground/40",error:"bg-red-500"},tZ={state:"connecting",cwd:"Local workspace",detail:"Opening shell"};function jA({sessionId:e,active:t,toolbarExtra:s}){const n=ee(),{confirmedGlobal:a}=bm(),l=x.useRef(null),[c,d]=x.useState(tZ),[f,h]=x.useState(null),g=x.useCallback(v=>d(v),[]),p=x.useCallback(v=>{l.current?.[v]()},[]),b=x.useCallback(v=>{if(a.terminal.confirmTerminate){h(v);return}p(v)},[a.terminal.confirmTerminate,p]);return i.jsxs("section",{className:oe("flex h-full min-h-0 flex-col bg-[#090909] text-white",!t&&"hidden"),children:[i.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-between gap-3 border-b border-white/10 bg-[#111111] px-4 py-2",children:[i.jsx("div",{className:"min-w-0",children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{className:"relative flex size-2.5 shrink-0 items-center justify-center",title:c.state,children:[c.state==="connecting"&&i.jsx("span",{className:oe("absolute inline-flex size-full animate-ping rounded-full opacity-60",DC[c.state])}),i.jsx("span",{className:oe("relative inline-flex size-2 rounded-full",DC[c.state])})]}),i.jsxs("span",{className:"truncate font-mono text-[11px] text-white/55",children:[c.cwd," · ",c.detail]})]})}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx(Q,{"aria-label":n("terminal.restart"),className:"text-white/60 hover:bg-white/10 hover:text-white",size:"icon-sm",variant:"ghost",onClick:()=>b("restart"),title:n("terminal.restart"),type:"button",children:i.jsx(Kf,{})}),i.jsx(Q,{"aria-label":n("terminal.stop"),className:"text-white/60 hover:bg-white/10 hover:text-white",size:"icon-sm",variant:"ghost",onClick:()=>b("stop"),title:n("terminal.stop"),type:"button",children:i.jsx(xo,{})}),s]})]}),i.jsx("div",{className:"min-h-0 flex-1",children:i.jsx(lA,{active:t,displaySettings:a.terminal,onStatusChange:g,ref:l,sessionId:e})}),f?i.jsx(Ol,{confirmLabel:n(f==="restart"?"terminal.restart":"terminal.stop"),message:n(f==="restart"?"terminal.confirmRestartBody":"terminal.confirmStopBody"),onCancel:()=>h(null),onConfirm:()=>{p(f),h(null)},title:n(f==="restart"?"terminal.confirmRestartTitle":"terminal.confirmStopTitle"),tone:"danger"}):null]})}function sZ({serviceName:e,active:t}){const s=ee(),[n,a]=x.useState(null),[l,c]=x.useState(null),[d,f]=x.useState(!1),h=x.useRef(!1),g=x.useRef(!0);x.useEffect(()=>(g.current=!0,()=>{g.current=!1}),[]),x.useEffect(()=>{!t||h.current||(h.current=!0,(async()=>{try{const v=await au({serviceName:e});g.current&&a(v.id)}catch(v){g.current&&(c(v instanceof Error?v.message:String(v)),h.current=!1)}})())},[t,e]);const p=i.jsx(Q,{"aria-label":s(d?"services.term.exitFs":"services.term.expand"),className:"text-white/60 hover:bg-white/10 hover:text-white",onClick:()=>f(v=>!v),size:"icon-sm",title:s(d?"services.fsExit":"services.fsExpand"),type:"button",variant:"ghost",children:d?i.jsx(Vx,{}):i.jsx(Gx,{})}),b=l?i.jsx("div",{className:"p-3 font-mono text-[11px] text-destructive",children:s("services.term.openError",{error:l})}):n?i.jsx(jA,{active:t,sessionId:n,toolbarExtra:p}):i.jsx("div",{className:"p-3 font-mono text-[11px] text-muted-foreground",children:s("services.term.opening")});return d&&t?i.jsx(Y0,{onClose:()=>f(!1),title:s("services.termTitle",{name:e}),children:b}):i.jsx("div",{className:oe("h-[60vh] min-h-[24rem] overflow-hidden rounded-md border border-border",!t&&"hidden"),children:b})}const nZ=500;function iZ(e){const[t,s]=x.useState(),[n,a]=x.useState([]),[l,c]=x.useState(),[d,f]=x.useState(!1),h=x.useRef(void 0);x.useEffect(()=>{h.current=void 0,s(void 0),a([]);const p=new EventSource(`/api/services/${encodeURIComponent(e)}/test/stream`),b=v=>{try{const _=JSON.parse(v.data);_.run.id!==h.current&&(h.current=_.run.id,a([])),s(_.run),_.line&&a(S=>[...S,_.line].slice(-nZ))}catch{}};return p.addEventListener("status",b),p.addEventListener("output",b),()=>p.close()},[e]);const g=x.useCallback(async p=>{f(!0),c(void 0);try{await s9(e,p)}catch(b){c(b instanceof Error?b.message:String(b))}finally{f(!1)}},[e]);return{run:t,lines:n,error:l,starting:d,start:g}}const rZ={running:"secondary",passed:"success",failed:"error",error:"error"},aZ={running:"services.tests.statusRunning",passed:"services.tests.statusPassed",failed:"services.tests.statusFailed",error:"services.tests.statusError"};function oZ({serviceName:e}){const t=ee(),{run:s,lines:n,error:a,starting:l,start:c}=iZ(e),[d,f]=x.useState(""),h=s?.status==="running"||l,g=s?.status==="failed"||s?.status==="error";return i.jsxs("div",{className:"space-y-2",children:[i.jsxs("form",{className:"flex items-center gap-2",onSubmit:p=>{p.preventDefault(),h||c(d.trim()||void 0)},children:[i.jsx(pt,{className:"h-7 flex-1 text-[11px]",disabled:h,onChange:p=>f(p.target.value),placeholder:t("services.tests.patternPlaceholder"),value:d}),i.jsx(Q,{disabled:h,size:"sm",type:"submit",children:t(h?"services.tests.running":"services.tests.runTests")})]}),a?i.jsx("div",{className:"text-red-600",children:a}):null,s?i.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-muted-foreground",children:[i.jsx(Ke,{size:"small",variant:rZ[s.status],children:t(aZ[s.status])}),i.jsx("code",{className:"font-mono text-[11px]",children:s.command}),s.failingCount>0?i.jsxs("span",{children:["· ",t("services.tests.failing",{count:s.failingCount})]}):null,s.exitCode!=null?i.jsxs("span",{children:["· ",t("services.tests.exit",{code:s.exitCode})]}):null]}):i.jsx("div",{className:"text-muted-foreground",children:t("services.tests.noRuns")}),n.length>0?i.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap break-all rounded bg-background p-2 font-mono text-[11px]",children:n.map((p,b)=>i.jsx("div",{className:oe(p.stream==="stderr"&&"text-red-500"),children:p.text},b))}):null,g?i.jsxs("div",{className:"rounded border border-border bg-muted/40 p-2",children:[t("services.tests.failuresPre")," ",i.jsx("a",{className:"font-medium underline",href:"/errors",children:t("services.tests.errorInbox")})," ",t("services.tests.failuresPost")]}):null]})}function lZ({serviceName:e,status:t,health:s,timeline:n,onRefresh:a}){const l=ee(),[c,d]=_l("service-detail:tab","metrics"),f=s?.processTree?.processes??[];return i.jsxs("div",{className:"border-t border-border bg-muted/30 px-3 py-2 text-xs",children:[i.jsxs("div",{className:"mb-2 flex gap-1",children:[i.jsx(no,{active:c==="logs",onClick:()=>d("logs"),children:l("services.logs")}),i.jsxs(no,{active:c==="processes",onClick:()=>d("processes"),children:[l("services.tab.processes")," ",f.length?i.jsx(Ke,{variant:"secondary",size:"small",children:f.length}):null]}),i.jsx(no,{active:c==="metrics",onClick:()=>d("metrics"),children:l("services.tab.metrics")}),i.jsxs(no,{active:c==="http",onClick:()=>d("http"),children:["HTTP",t?.inspector?.enabled?i.jsx(Ke,{variant:"success",size:"small",children:l("services.tab.on")}):null]}),i.jsx(no,{active:c==="env",onClick:()=>d("env"),children:l("services.tab.env")}),i.jsx(no,{active:c==="tests",onClick:()=>d("tests"),children:l("services.tab.tests")}),i.jsx(no,{active:c==="terminal",onClick:()=>d("terminal"),children:l("nav.terminal")})]}),c==="processes"?i.jsx(eZ,{rows:f,running:t?.state==="running"}):null,c==="metrics"?i.jsx(KX,{serviceName:e}):null,c==="http"?i.jsx(GX,{serviceName:e,status:t,timeline:n,onRefresh:a}):null,c==="env"?i.jsx(qX,{serviceName:e}):null,c==="tests"?i.jsx(oZ,{serviceName:e}):null,c==="logs"?i.jsx(LX,{serviceName:e}):null,i.jsx(sZ,{active:c==="terminal",serviceName:e},e)]})}function no({active:e,onClick:t,children:s}){return i.jsx("button",{className:oe("inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition-colors",e?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),onClick:t,type:"button",children:s})}const cZ={high:"success",medium:"warning",low:"secondary"};function uZ({onClose:e,onRefresh:t}){const s=ee(),n=ms(),{sendToAgent:a}=Ot(),[l,c]=x.useState("url"),[d,f]=x.useState(""),[h,g]=x.useState(!1),[p,b]=x.useState(null),[v,_]=x.useState(null),[S,C]=x.useState([]),[N,A]=x.useState([]),[j,E]=x.useState(null),T=j?.kind==="docker-compose"?N.find(F=>F.composeService===j.composeService):void 0;async function L(){if(d.trim()){g(!0),b(null);try{const F=await H7(d.trim());_(F.profile),C(F.proposals),A(F.databases),E(F.proposals[0]??null),F.proposals.length===0&&b(s("onboard.scanNoDetect")),c("review")}catch(F){b(F instanceof Error?F.message:String(F))}finally{g(!1)}}}function H(){a({prompt:`Onboard this repository and register it as a NoMoreIDE service: ${d.trim()}
|
|
120
120
|
Use nomoreide_onboard_repo to inspect it, pick the best run command, then register and start it.`,source:{type:"repo-onboard",label:"Onboard repo"},label:s("onboard.refineLabel",{url:d.trim()})}),e()}async function P(F){if(j){g(!0),b(null);try{await $7(j,F,T),await t();const M=(T?s("onboard.extraDb"):"")+(F?s("onboard.extraStart"):"");n.success(s("onboard.registeredToast",{name:j.name,extras:M})),e()}catch(M){b(M instanceof Error?M.message:String(M))}finally{g(!1)}}}return i.jsxs(ei,{icon:i.jsx(Pn,{}),onClose:e,size:"lg",title:s("onboard.title"),children:[l==="url"?i.jsx(dZ,{url:d,busy:h,error:p,onChange:f,onScan:L,onRefine:H}):null,l==="review"&&v?i.jsx(hZ,{profile:v,proposals:S,selected:j,database:T,error:p,onSelect:E,onEdit:E,onBack:()=>c("url"),onRefine:H,onContinue:()=>c("install")}):null,l==="install"&&j?i.jsx(mZ,{proposal:j,busy:h,error:p,onBack:()=>c("review"),onRegister:P}):null]})}function dZ({url:e,busy:t,error:s,onChange:n,onScan:a,onRefine:l}){const c=ee();return i.jsxs("div",{className:"flex flex-col gap-3",children:[i.jsx("p",{className:"text-sm text-muted-foreground",children:c("onboard.urlIntro")}),i.jsx(pt,{autoFocus:!0,placeholder:"https://github.com/owner/repo",value:e,onChange:d=>n(d.target.value),onKeyDown:d=>{d.key==="Enter"&&!t&&a()}}),s?i.jsx("p",{className:"text-sm text-destructive",children:s}):null,i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsxs(Q,{variant:"ghost",size:"sm",onClick:l,disabled:!e.trim(),children:[i.jsx(zn,{className:"size-3.5"}),c("onboard.refineWithAi")]}),i.jsxs(Q,{onClick:a,disabled:t||!e.trim(),children:[t?i.jsx(Lt,{className:"size-4 animate-spin"}):i.jsx(Pn,{className:"size-4"}),c(t?"onboard.cloning":"onboard.cloneDetect")]})]})]})}function hZ({profile:e,proposals:t,selected:s,database:n,error:a,onSelect:l,onEdit:c,onBack:d,onRefine:f,onContinue:h}){const g=ee();return i.jsxs("div",{className:"flex flex-col gap-4",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[i.jsx("span",{className:"text-sm font-medium",children:e.name}),e.languages.map(p=>i.jsx(Ke,{variant:"outline",size:"small",label:p},p))]}),a?i.jsx("p",{className:"text-sm text-destructive",children:a}):null,t.length>0?i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:g("onboard.detectedServices")}),t.map(p=>{const b=s?.name===p.name;return i.jsxs("button",{type:"button",onClick:()=>l(p),className:`rounded-md border px-3 py-2 text-left text-sm transition-colors ${b?"border-primary bg-primary/5":"border-border hover:bg-muted/50"}`,children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("span",{className:"font-medium",children:p.name}),i.jsx(Ke,{variant:cZ[p.confidence],size:"small",label:p.confidence})]}),i.jsx("div",{className:"mt-0.5 font-mono text-xs text-muted-foreground",children:p.kind==="docker-compose"?`compose · ${p.composeService}`:p.command}),i.jsx("div",{className:"text-[11px] text-muted-foreground",children:p.reason})]},p.name)})]}):null,s?i.jsx(fZ,{proposal:s,onChange:c}):null,n?i.jsxs("div",{className:"flex items-center gap-1.5 rounded-md border border-border bg-muted/30 px-2.5 py-1.5 text-xs text-muted-foreground",children:[i.jsx(ti,{className:"size-3.5"}),i.jsxs("span",{children:[g("onboard.alsoRegistersPre")," ",i.jsx("span",{className:"font-medium",children:n.name})," (",n.engine,")"," ",g("onboard.alsoRegistersPost")]})]}):null,e.envKeys.length>0?i.jsxs("div",{className:"text-xs text-muted-foreground",children:[i.jsx("span",{className:"font-medium",children:g("onboard.envFrom")})," ",e.envKeys.join(", ")]}):null,e.readmeExcerpt?i.jsxs("details",{className:"rounded-md border border-border bg-muted/30 p-2 text-xs",children:[i.jsx("summary",{className:"cursor-pointer font-medium",children:g("onboard.readmeExcerpt")}),i.jsx("pre",{className:"mt-2 max-h-40 overflow-auto whitespace-pre-wrap font-mono",children:e.readmeExcerpt})]}):null,i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsxs(Q,{variant:"ghost",size:"sm",onClick:d,children:[i.jsx(Eu,{className:"size-3.5"}),g("common.back")]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs(Q,{variant:"outline",size:"sm",onClick:f,children:[i.jsx(zn,{className:"size-3.5"}),g("onboard.refineWithAi")]}),i.jsx(Q,{onClick:h,disabled:!s,children:g("onboard.continue")})]})]})]})}function fZ({proposal:e,onChange:t}){const s=ee();return i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsx(nu,{label:s("onboard.serviceName"),children:i.jsx(pt,{value:e.name,onChange:n=>t({...e,name:n.target.value})})}),i.jsx(nu,{label:s("onboard.portOptional"),children:i.jsx(pt,{value:e.port?.toString()??"",placeholder:"auto",onChange:n=>t({...e,port:n.target.value?Number(n.target.value):void 0})})}),e.kind==="docker-compose"?i.jsx(nu,{label:s("onboard.composeService"),className:"col-span-2",children:i.jsx(pt,{value:e.composeService??"",onChange:n=>t({...e,composeService:n.target.value})})}):i.jsx(nu,{label:s("onboard.runCommand"),className:"col-span-2",children:i.jsx(pt,{value:e.command??"",onChange:n=>t({...e,command:n.target.value})})})]})}function mZ({proposal:e,busy:t,error:s,onBack:n,onRegister:a}){const l=ee(),[c,d]=x.useState(e.installCommand??""),[f,h]=x.useState([]),[g,p]=x.useState(!1),[b,v]=x.useState(!1),_=x.useRef(null);function S(N){h(A=>[...A,N]),queueMicrotask(()=>{const A=_.current;A&&(A.scrollTop=A.scrollHeight)})}async function C(){c.trim()&&(p(!0),v(!1),h([]),await F7({clonePath:e.cwd,command:c.trim()},{onLine:N=>S(N.text),onDone:N=>{S(N===0?l("onboard.installComplete"):l("onboard.installExited",{code:N??"?"})),p(!1),v(N===0)},onError:N=>{S(`✗ ${N}`),p(!1)}}))}return i.jsxs("div",{className:"flex flex-col gap-3",children:[i.jsxs("div",{className:"flex items-end gap-2",children:[i.jsx(nu,{label:l("onboard.installCommand"),className:"flex-1",children:i.jsx(pt,{value:c,placeholder:"e.g. npm install",onChange:N=>d(N.target.value)})}),i.jsxs(Q,{variant:"outline",onClick:C,disabled:g||!c.trim(),children:[g?i.jsx(Lt,{className:"size-4 animate-spin"}):i.jsx(vu,{className:"size-4"}),l("onboard.install")]})]}),f.length>0?i.jsx("pre",{ref:_,className:"max-h-48 overflow-auto rounded-md border border-border bg-black/80 p-2 font-mono text-[11px] text-green-200",children:f.join(`
|
|
121
121
|
`)}):null,s?i.jsx("p",{className:"text-sm text-destructive",children:s}):null,i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsxs(Q,{variant:"ghost",size:"sm",onClick:n,children:[i.jsx(Eu,{className:"size-3.5"}),l("common.back")]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Q,{variant:"outline",onClick:()=>a(!1),disabled:t,children:l("onboard.registerOnly")}),i.jsxs(Q,{onClick:()=>a(!0),disabled:t,children:[t?i.jsx(Lt,{className:"size-4 animate-spin"}):i.jsx(Or,{className:"size-4"}),b||!c.trim()?l("onboard.registerStart"):l("onboard.skipInstallStart")]})]})]})]})}function nu({label:e,className:t,children:s}){return i.jsxs("label",{className:`flex flex-col gap-1 text-xs ${t??""}`,children:[i.jsx("span",{className:"font-medium text-muted-foreground",children:e}),s]})}function pZ({data:e,onRefresh:t,focusService:s,onServiceFocused:n,scopeName:a}){const l=ee(),c=e.config.services[0]?.name??"",[d,f]=x.useState(c),[h,g]=x.useState(null),[p,b]=x.useState(!1),{sendToAgent:v,startOnboard:_}=Ot(),[S,C]=x.useState(!1),[N,A]=x.useState(!1),[j,E]=x.useState(!1),[T,L]=x.useState(!1),[H,P]=x.useState(!1),F=x.useRef({}),{error:M,message:z,success:G}=ms(),D=x.useMemo(()=>new Set(e.config.bundles.flatMap(ne=>ne.services)),[e.config.bundles]),q=x.useMemo(()=>{const ne=new Map;for(const we of e.config.bundles)for(const Ne of we.services)ne.has(Ne)||ne.set(Ne,we.name);return ne},[e.config.bundles]),W=x.useMemo(()=>e.config.services.filter(ne=>!D.has(ne.name)),[e.config.services,D]),I=x.useMemo(()=>e.config.services.map(ne=>ne.name),[e.config.services]),Y=x.useMemo(()=>e.config.services.some(ne=>(ne.dependsOn?.length??0)>0),[e.config.services]),$=e.health??{},me=e.config.bundles.length>0||W.length>0;x.useEffect(()=>{!e.config.services.some(we=>we.name===d)&&c&&f(c)},[e.config.services,c,d]),x.useEffect(()=>{s&&e.config.services.some(ne=>ne.name===s)&&(f(s),n?.())},[s,e.config.services,n]);const J=x.useMemo(()=>e.config.services.find(ne=>ne.name===d),[e.config.services,d]),V=d?e.runtime.services[d]:void 0,K=d?$[d]:void 0;async function xe(ne,we){if(!ne.services.includes(we))try{await n9(ne.name,ne.services,we),G(l("services.toast.addedToGroup",{service:we,group:ne.name})),await t()}catch(Ne){M(Ne instanceof Error?Ne.message:String(Ne))}}async function ie(){if(J){if(hu(V?.state)){M(l("services.toast.stopBeforeDelete",{name:J.name}));return}if(window.confirm(l("services.confirmDelete",{name:J.name})))try{await K7(J.name),G(l("services.toast.deleted",{name:J.name})),await t()}catch(ne){M(ne instanceof Error?ne.message:String(ne))}}}async function Z(ne){const we=e.config.bundles.filter(Ne=>Ne.services.includes(ne));if(we.length!==0)try{for(const Ne of we)await r9(Ne.name,Ne.services,ne);z({text:l("services.toast.removedFromGroups",{service:ne,groups:we.map(Ne=>Ne.name).join(", ")})}),await t()}catch(Ne){M(Ne instanceof Error?Ne.message:String(Ne))}}x.useEffect(()=>{const ne=Object.fromEntries(e.config.services.map(Ne=>[Ne.name,e.runtime.services[Ne.name]?.state??"stopped"])),we=F.current;if(Object.keys(we).length){const Ne=new Map,Ue=new Map;for(const Pe of e.config.services){const Re=ne[Pe.name],pe=we[Pe.name];if(!pe||pe===Re)continue;const Qe=e.runtime.services[Pe.name],jt=q.get(Pe.name);if(jt){const dt=Ne.get(jt)??new Map;if(dt.set(Re,(dt.get(Re)??0)+1),Ne.set(jt,dt),Re==="exited"){const Fs=Ue.get(jt)??[];Fs.push(Qe?.exitCode),Ue.set(jt,Fs)}continue}Re==="running"?G(l("services.toast.running",{name:Pe.name})):Re==="stopped"?z({text:l("services.toast.stopped",{name:Pe.name})}):Re==="starting"?z({text:l("services.toast.starting",{name:Pe.name})}):Re==="exited"&&M(Qe?.exitCode===void 0||Qe.exitCode===null?l("services.toast.exited",{name:Pe.name}):l("services.toast.exitedWithCode",{name:Pe.name,code:Qe.exitCode}))}for(const[Pe,Re]of Ne)bZ({exitCodes:Ue.get(Pe)??[],groupName:Pe,showErrorToast:M,showMessageToast:z,showSuccessToast:G,transitions:Re,t:l})}F.current=ne},[e.config.services,e.runtime.services,q,M,z,G]);const ge=e.config.services.length>0;return i.jsxs(i.Fragment,{children:[!ge&&a?i.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center",children:i.jsxs("div",{className:"max-w-sm text-sm text-muted-foreground",children:[i.jsxs("p",{className:"font-medium text-foreground",children:["No services in ",a]}),i.jsx("p",{className:"mt-1 text-xs",children:"Services whose working directory lives under this project appear here. Switch to All projects in the sidebar to see everything."})]})}):ge?i.jsxs("div",{className:oe("grid h-full min-h-0 overflow-hidden bg-card/85",j?"lg:grid-cols-[320px_minmax(0,1fr)]":"lg:grid-cols-[320px_minmax(0,1fr)_340px]"),children:[i.jsx("div",{className:"min-h-0 min-w-0 overflow-auto border-r border-border",children:i.jsxs(_i,{className:"min-w-0 rounded-none border-0 border-b border-border bg-transparent",children:[i.jsx(wi,{className:"border-b border-border px-3 py-2",children:i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx(Si,{className:"text-sm",children:l("services.title")}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsxs(Q,{"aria-haspopup":"dialog",className:"h-7 gap-1.5 px-2 text-xs",onClick:()=>A(!0),size:"sm",type:"button",variant:"outline",children:[i.jsx(nf,{className:"size-3.5"}),l("services.graph")]}),i.jsxs(Q,{"aria-haspopup":"dialog",className:"h-7 gap-1.5 px-2 text-xs",onClick:()=>C(!0),size:"sm",type:"button",variant:"outline",children:[i.jsx(pE,{className:"size-3.5"}),l("services.logs")]}),i.jsx(gZ,{onCreateGroup:()=>g("group"),onCreateService:()=>g("service"),onOnboardRepo:()=>b(!0),onOnboardWithAi:_,canGroupWithAi:W.length>1,onCreateWithAi:()=>v({prompt:Xk,source:{type:"service-setup",label:"Add a service"},label:"Help me add a new service, one step at a time."}),onGroupWithAi:()=>v({prompt:LF(W),source:{type:"group-services",label:"Group services"},label:"Propose how to group my ungrouped services."})})]})]})}),i.jsx(ki,{className:"p-0",children:me?i.jsxs("div",{className:"divide-y divide-border",children:[e.config.bundles.map(ne=>i.jsx(xq,{group:ne,onRefresh:t,ports:e.ports,allServices:e.config.services,health:$,services:e.config.services.filter(we=>ne.services.includes(we.name)),statuses:e.runtime.services,timeline:e.timeline,selectedService:d,onSelectService:f,onDropService:we=>{xe(ne,we)}},ne.name)),W.length?i.jsxs("div",{className:oe("transition-colors",H&&"bg-primary/5 outline-dashed outline-2 -outline-offset-2 outline-primary/60"),onDragOver:ne=>{ne.dataTransfer.types.includes(Su)&&(ne.preventDefault(),ne.dataTransfer.dropEffect="move",P(!0))},onDragLeave:()=>P(!1),onDrop:ne=>{ne.preventDefault(),P(!1);const we=ne.dataTransfer.getData(Su);we&&Z(we)},children:[i.jsxs("div",{className:"flex items-center justify-between gap-2 bg-muted/55 px-3 py-1 text-[10px] font-semibold uppercase text-muted-foreground",children:[i.jsx("span",{children:l("services.ungrouped")}),i.jsx("span",{className:"text-muted-foreground/80",children:W.length})]}),i.jsx("div",{className:"divide-y divide-border",children:W.map(ne=>i.jsx(f5,{service:ne,status:e.runtime.services[ne.name],health:$[ne.name],ports:e.ports,onRefresh:t,timeline:e.timeline,selected:d===ne.name,onSelect:()=>f(ne.name)},ne.name))})]}):null]}):i.jsx(Tf,{label:l("services.empty")})})]})}),i.jsx("div",{className:"min-h-0 min-w-0 overflow-auto",children:J?i.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[i.jsxs("div",{className:"shrink-0 space-y-2 border-b border-border bg-background/60 px-4 py-3",children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i.jsx("h2",{className:"min-w-0 truncate text-base font-semibold",children:J.name}),i.jsx(m5,{state:V?.state??"stopped"}),i.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[(()=>{const ne=V?.url??(J.port?_q(J.port):void 0);return ne?i.jsx(yl,{label:l("services.openUrl",{url:ne}),children:i.jsx(Q,{"aria-label":l("services.openInBrowser"),className:"size-7",onClick:()=>{Qf(ne)},size:"icon",type:"button",variant:"outline",children:i.jsx(ja,{})})}):null})(),K?.agentContext&&J?i.jsx(yl,{label:l("services.debugWithAi"),children:i.jsx(Q,{"aria-label":l("services.debugWithAi"),className:"size-7",onClick:()=>v({prompt:IF({service:J.name,context:K.agentContext}),source:{type:"service-debug",label:J.name},label:`Debug \`${J.name}\` with its current context.`}),size:"icon",type:"button",variant:"outline",children:i.jsx(Xt,{className:"size-3.5"})})}):null,i.jsx(L0,{active:hu(V?.state),baseUrl:`/api/services/${encodeURIComponent(J.name)}`,compact:!0,resourceKind:"service",resourceName:J.name,targetLabel:J.name,onRefresh:t}),i.jsx(Ll,{className:"size-7 border border-border bg-background opacity-100 hover:border-foreground/30",items:[{icon:i.jsx(Cl,{className:"size-3.5"}),label:l("services.editService"),onSelect:()=>L(!0)},...hu(V?.state)?[]:[{icon:i.jsx(Bi,{className:"size-3.5 text-destructive"}),label:l("services.deleteService"),onSelect:()=>{ie()}}]],label:l("services.moreActions",{name:J.name})}),i.jsx(yl,{label:l(j?"services.showRail":"services.hideRail"),side:"left",children:i.jsx(Q,{"aria-label":l(j?"services.showRail":"services.hideRail"),className:"size-7",onClick:()=>E(ne=>!ne),size:"icon",type:"button",variant:"ghost",children:j?i.jsx(gM,{}):i.jsx(_n,{})})})]})]}),J.command?i.jsxs("div",{className:"truncate font-mono text-[11px] text-muted-foreground",title:J.command,children:["$ ",J.command]}):null,J.cwd?i.jsx("div",{className:"truncate font-mono text-[11px] text-muted-foreground",title:J.cwd,children:J.cwd}):null,i.jsx(bX,{health:K})]}),i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:i.jsx(lZ,{serviceName:J.name,status:V,health:K,timeline:e.timeline??[],onRefresh:t},J.name)})]}):i.jsx(Tf,{label:l("services.selectPrompt")})}),j?null:i.jsxs("div",{className:"min-h-0 overflow-auto border-l border-border",children:[i.jsx(wX,{ports:e.ports}),i.jsx(nX,{events:e.timeline??[]})]})]}):i.jsx(gX,{onOnboardRepo:()=>b(!0),onOnboardWithAi:_,onCreateService:()=>g("service"),onCreateWithAi:()=>v({prompt:Xk,source:{type:"service-setup",label:"Add a service"},label:"Help me add a new service, one step at a time."})}),T&&J?i.jsx(ei,{icon:i.jsx(Cl,{}),onClose:()=>L(!1),size:"lg",title:l("services.editServiceTitle",{name:J.name}),children:i.jsx(m2,{cwd:e.cwd,initialService:J,availableServices:I,onRefresh:t,onSaved:()=>L(!1)})}):null,h?i.jsx(ei,{icon:h==="service"?i.jsx(fs,{}):i.jsx($f,{}),onClose:()=>g(null),size:h==="service"?"lg":"md",title:l(h==="service"?"services.addService":"services.createGroup"),children:h==="service"?i.jsx(m2,{cwd:e.cwd,availableServices:I,onRefresh:t,onSaved:()=>g(null)}):i.jsx(h5,{services:W,onRefresh:t,onSaved:()=>g(null)})}):null,p?i.jsx(uZ,{onClose:()=>b(!1),onRefresh:t}):null,S?i.jsx(zX,{initialService:d||void 0,onClose:()=>C(!1),services:e.config.services.map(ne=>ne.name)}):null,N?i.jsx(ei,{icon:i.jsx(nf,{}),onClose:()=>A(!1),size:"lg",title:l("services.depGraphTitle"),children:i.jsx(hX,{statuses:e.runtime.services,health:$,hasDependencies:Y,onSelectService:ne=>{f(ne),A(!1)}})}):null]})}function gZ({onCreateService:e,onCreateGroup:t,onCreateWithAi:s,onGroupWithAi:n,canGroupWithAi:a,onOnboardRepo:l,onOnboardWithAi:c}){const d=ee(),[f,h]=x.useState(!1);function g(p){h(!1),p()}return i.jsxs("div",{className:"relative",children:[i.jsx(yl,{label:d("services.add"),side:"bottom",children:i.jsx(Q,{"aria-expanded":f,"aria-haspopup":"menu","aria-label":d("services.addServiceOrGroup"),className:"size-7",onClick:()=>h(p=>!p),size:"icon",type:"button",variant:"ghost",children:i.jsx(fs,{})})}),f?i.jsxs(i.Fragment,{children:[i.jsx("button",{"aria-hidden":!0,className:"fixed inset-0 z-[40] cursor-default",onClick:()=>h(!1),tabIndex:-1,type:"button"}),i.jsxs("div",{className:"absolute right-0 z-[50] mt-1 w-56 overflow-hidden rounded-md border border-border bg-card py-1 shadow-lg",role:"menu",children:[i.jsxs("div",{className:"group flex items-stretch",children:[i.jsxs("button",{className:"flex flex-1 items-center gap-2 whitespace-nowrap px-3 py-2 text-left text-sm hover:bg-muted/60 [&_svg]:size-4",onClick:()=>g(e),role:"menuitem",type:"button",children:[i.jsx(fs,{}),d("services.createService")]}),i.jsxs("button",{className:"flex max-w-0 items-center gap-1.5 overflow-hidden whitespace-nowrap border-l border-transparent px-0 text-[11px] font-medium text-muted-foreground opacity-0 transition-all duration-200 ease-out hover:bg-muted/60 hover:text-foreground group-hover:max-w-24 group-hover:border-border group-hover:px-3 group-hover:opacity-100",onClick:()=>g(s),role:"menuitem",title:d("services.setupWithAiHint"),type:"button",children:[i.jsx(Xt,{className:"size-3.5 shrink-0"}),"AI"]})]}),i.jsxs("div",{className:"group flex items-stretch",children:[i.jsxs("button",{className:"flex flex-1 items-center gap-2 whitespace-nowrap px-3 py-2 text-left text-sm hover:bg-muted/60 [&_svg]:size-4",onClick:()=>g(t),role:"menuitem",type:"button",children:[i.jsx($f,{}),d("services.createGroup")]}),a?i.jsxs("button",{className:"flex max-w-0 items-center gap-1.5 overflow-hidden whitespace-nowrap border-l border-transparent px-0 text-[11px] font-medium text-muted-foreground opacity-0 transition-all duration-200 ease-out hover:bg-muted/60 hover:text-foreground group-hover:max-w-24 group-hover:border-border group-hover:px-3 group-hover:opacity-100",onClick:()=>g(n),role:"menuitem",title:d("services.groupWithAiHint"),type:"button",children:[i.jsx(Xt,{className:"size-3.5 shrink-0"}),"AI"]}):null]}),i.jsxs("div",{className:"group flex items-stretch",children:[i.jsxs("button",{className:"flex flex-1 items-center gap-2 whitespace-nowrap px-3 py-2 text-left text-sm hover:bg-muted/60 [&_svg]:size-4",onClick:()=>g(l),role:"menuitem",type:"button",children:[i.jsx(Pn,{}),d("services.addFromGithub")]}),i.jsxs("button",{className:"flex max-w-0 items-center gap-1.5 overflow-hidden whitespace-nowrap border-l border-transparent px-0 text-[11px] font-medium text-muted-foreground opacity-0 transition-all duration-200 ease-out hover:bg-muted/60 hover:text-foreground group-hover:max-w-24 group-hover:border-border group-hover:px-3 group-hover:opacity-100",onClick:()=>g(c),role:"menuitem",title:d("services.onboardWithAiHint"),type:"button",children:[i.jsx(Xt,{className:"size-3.5 shrink-0"}),"AI"]})]})]})]}):null]})}function bZ({exitCodes:e,groupName:t,showErrorToast:s,showMessageToast:n,showSuccessToast:a,transitions:l,t:c}){if(l.size===1){const[h]=l.keys();if(h==="running")a(c("services.toast.groupRunning",{name:t}));else if(h==="stopped")n({text:c("services.toast.groupStopped",{name:t})});else if(h==="starting")n({text:c("services.toast.groupStarting",{name:t})});else if(h==="exited"){const g=e.filter(p=>p!=null);s(g.length?c("services.toast.groupExitedWithCode",{name:t,code:g.join(", ")}):c("services.toast.groupExited",{name:t}))}return}const d=[...l.entries()].map(([h,g])=>`${g} ${h}`).join(", "),f=c("services.toast.groupUpdated",{name:t,summary:d});l.has("exited")?s(f):n({text:f})}function vZ({data:e,onOpenService:t}){const s=ee(),n=x.useMemo(()=>xZ(e,s("services.startingEllipsis")),[e,s]);return n.length?i.jsxs("div",{className:"flex shrink-0 items-center gap-3 overflow-x-auto border-b border-border bg-card/60 px-4 py-1.5 backdrop-blur",children:[i.jsxs("span",{className:"flex shrink-0 items-center gap-1.5 font-mono text-[10px] uppercase tracking-wider text-muted-foreground",children:[i.jsx(mo,{className:"size-3"}),s("services.stripeRunning")]}),i.jsx("div",{className:"flex min-w-0 items-center gap-2",children:n.map(a=>i.jsxs("button",{className:"group flex shrink-0 items-center gap-2 rounded-md border border-border/60 bg-background/60 px-2.5 py-1 font-mono text-[11px] transition-colors hover:border-border hover:bg-muted",onClick:()=>t(a.name),title:a.url?`${a.name} — ${a.url}`:a.name,type:"button",children:[i.jsx("span",{className:oe("size-2 shrink-0 rounded-full",_Z(a.tone))}),i.jsx("span",{className:"max-w-40 truncate font-medium text-foreground",children:a.name}),a.port?i.jsxs("span",{className:"text-muted-foreground",children:[":",a.port]}):null,a.uptime?i.jsxs("span",{className:"text-muted-foreground/70",children:["↑",a.uptime]}):null]},a.name))})]}):null}function xZ(e,t){const s=new Map(e.config.services.map(n=>[n.name,n.port]));return Object.values(e.runtime.services).filter(n=>n.state==="running"||n.state==="starting").map(n=>({name:n.name,tone:yZ(n,e.health[n.name]),port:s.get(n.name)??wZ(n.url),uptime:n.state==="running"?SZ(n.startedAt):t,url:n.url})).sort((n,a)=>n.name.localeCompare(a.name))}function yZ(e,t){return e.state==="starting"?"starting":t?.status==="healthy"?"healthy":t?.status==="warning"?"warning":t?.status==="unhealthy"?"unhealthy":"healthy"}function _Z(e){return e==="starting"?"animate-pulse bg-amber-500":e==="warning"?"bg-amber-500":e==="unhealthy"?"bg-red-500":e==="unknown"?"bg-zinc-500":"bg-emerald-500"}function wZ(e){if(e)try{const t=new URL(e).port;return t?Number(t):void 0}catch{return}}function SZ(e){if(!e)return;const t=new Date(e).getTime();if(Number.isNaN(t))return;const s=Math.max(0,Math.floor((Date.now()-t)/1e3));if(s<60)return`${s}s`;const n=Math.floor(s/60);if(n<60)return`${n}m`;const a=Math.floor(n/60),l=n%60;return a<24?`${a}h${l?`${l}m`:""}`:`${Math.floor(a/24)}d${a%24?`${a%24}h`:""}`}function kZ(){const e=ee(),{confirmedGlobal:t}=bm(),[s,n]=x.useState([]),[a,l]=x.useState(null),[c,d]=x.useState(!1),[f,h]=x.useState(null);x.useEffect(()=>{let v=!1;return(async()=>{let _=await FE().catch(()=>[]);if(_.length===0){const S=await au().catch(()=>null);_=S?[S]:[]}v||(n(_),l(_[0]?.id??null))})(),()=>{v=!0}},[]);const g=x.useCallback(async()=>{d(!0);try{const v=await au();n(_=>[..._,v]),l(v.id)}finally{d(!1)}},[]),p=x.useCallback(async v=>{d(!0);try{await dv(v);const _=s.findIndex(C=>C.id===v),S=s.filter(C=>C.id!==v);if(S.length===0){const C=await au();n([C]),l(C.id);return}if(n(S),a===v){const C=S[Math.min(_,S.length-1)];l(C.id)}}finally{d(!1)}},[s,a]),b=x.useCallback((v,_)=>{if(t.terminal.confirmTerminate){h({id:v,name:_});return}p(v)},[p,t.terminal.confirmTerminate]);return i.jsxs("section",{className:"flex h-full min-h-0 flex-col bg-[#090909] text-white",children:[i.jsxs("div",{"aria-label":e("terminal.tabs"),className:"flex shrink-0 items-center gap-1 overflow-x-auto border-b border-white/10 bg-[#111111] px-2 py-1.5",role:"tablist",children:[s.map((v,_)=>{const S=v.label??e("terminal.tabName",{n:_+1});return i.jsxs("div",{className:oe("group flex items-center gap-1 rounded-md border border-transparent px-2 py-1 text-xs",v.id===a?"border-white/15 bg-white/10 text-white":"text-white/60 hover:bg-white/5"),children:[i.jsx("button",{"aria-selected":v.id===a,className:"max-w-[160px] truncate font-medium",onClick:()=>l(v.id),role:"tab",type:"button",children:S}),i.jsx("button",{"aria-label":e("terminal.closeTab",{name:S}),className:"rounded p-0.5 text-white/40 opacity-0 transition hover:bg-white/10 hover:text-white group-hover:opacity-100",disabled:c,onClick:()=>b(v.id,S),type:"button",children:i.jsx(Vt,{className:"size-3"})})]},v.id)}),i.jsx("button",{"aria-label":e("terminal.newTerminal"),className:"ml-1 rounded-md p-1 text-white/60 transition hover:bg-white/10 hover:text-white disabled:opacity-40",disabled:c,onClick:()=>{g()},type:"button",children:i.jsx(fs,{className:"size-4"})})]}),i.jsx("div",{className:"relative min-h-0 flex-1",children:s.length===0?i.jsx("div",{className:"flex h-full items-center justify-center font-mono text-[11px] text-white/40",children:e("terminal.starting")}):s.map(v=>i.jsx("div",{className:"absolute inset-0",children:i.jsx(jA,{active:v.id===a,sessionId:v.id})},v.id))}),f?i.jsx(Ol,{confirmLabel:`Close ${f.name}`,loading:c,message:"The running shell process will be terminated and this terminal tab will be closed.",onCancel:()=>h(null),onConfirm:()=>{const v=f.id;h(null),p(v)},title:`Close ${f.name}?`,tone:"danger"}):null]})}function AA({branch:e}){return i.jsx("span",{className:"min-w-0 max-w-40",title:e,children:i.jsx(Ke,{className:"w-full max-w-full shadow-none",variant:"outline",children:e})})}function TA({branch:e,error:t,files:s,selectedFile:n,onSelectFile:a,root:l,staging:c}){const d=ee(),f=x.useMemo(()=>jZ(s).filter(p=>p.files.length),[s]),[h,g]=x.useState({staged:!1,unstaged:!1,untracked:!1});return i.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[i.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border bg-card/95 px-2.5 py-1.5",children:[i.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-[12px] font-semibold tracking-tight",children:[i.jsx(Pn,{className:"size-3.5"}),i.jsx("span",{className:"truncate",children:d("git.tab.changes")})]}),i.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[e?i.jsx(AA,{branch:e}):null,i.jsx(Ke,{variant:"secondary",children:s.length})]})]}),i.jsx("div",{className:"min-h-0 flex-1 overflow-auto py-1",children:f.length?f.map(p=>i.jsx(CZ,{collapsed:h[p.id],group:p,onSelectFile:a,onToggle:()=>g(b=>({...b,[p.id]:!b[p.id]})),root:l,selectedFile:n,staging:c},p.id)):i.jsx(tt,{variant:"muted",className:"m-3 text-center",children:t??d("git.noChangedFiles")})})]})}function CZ({collapsed:e,group:t,onSelectFile:s,onToggle:n,root:a,selectedFile:l,staging:c}){const d=ee(),f=e?_n:hn,h=t.files.map(p=>p.path),g=c?t.id==="staged"?{label:d("git.stageArea.unstageAll"),run:()=>c.onUnstage(h)}:{label:d("git.stageArea.stageAll"),run:()=>c.onStage(h)}:null;return i.jsxs("section",{className:"border-b border-border last:border-b-0",children:[i.jsxs("div",{className:"flex w-full items-center justify-between gap-2 bg-muted/45 px-2 py-0.5 text-[10px] font-semibold uppercase text-muted-foreground hover:bg-muted",children:[i.jsxs("button",{className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",onClick:n,type:"button",children:[i.jsx(f,{className:"size-3.5"}),i.jsx("span",{className:"truncate",children:d(t.labelKey)})]}),g?i.jsx("button",{className:"shrink-0 rounded px-1 text-[10px] font-medium normal-case text-muted-foreground transition-colors hover:bg-background hover:text-foreground disabled:opacity-50",disabled:c?.busy,onClick:g.run,type:"button",children:g.label}):null,i.jsx(Ke,{className:"min-w-6 justify-center font-mono shadow-none",size:"small",variant:"outline",children:t.files.length})]}),e?null:i.jsx("div",{children:t.files.map(p=>i.jsx(NZ,{active:l===p.path,file:p,group:t.id,onClick:()=>s(p.path),root:a,staging:c},p.path))})]})}function NZ({active:e,file:t,group:s,onClick:n,root:a,staging:l}){const c=ee(),d=t.path.split("/").pop()||t.path,f=t.path.split("/").slice(0,-1).join("/"),h=a?d5(Pu(a,t.path)):{},g=s==="staged";return i.jsxs("div",{className:oe("group flex w-full items-center gap-1.5 px-1 py-0.5 text-[12px] hover:bg-muted",e&&"bg-muted font-medium"),children:[i.jsxs("button",{"aria-label":c("git.file.openAria",{path:t.path}),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",onClick:n,type:"button",...h,children:[i.jsx(V0,{path:t.path}),i.jsxs("span",{className:"flex min-w-0 flex-1 items-baseline gap-1.5 truncate",children:[i.jsx("span",{"data-testid":"changed-file-name",className:"shrink-0 truncate",children:d}),f?i.jsx("span",{"data-testid":"changed-file-dir",className:"min-w-0 truncate text-muted-foreground",children:f}):null]})]}),l?i.jsx("button",{"aria-label":g?c("git.stageArea.unstageFile",{path:t.path}):c("git.stageArea.stageFile",{path:t.path}),className:"shrink-0 rounded p-0.5 text-muted-foreground opacity-0 transition-colors hover:bg-background hover:text-foreground focus:opacity-100 group-hover:opacity-100 disabled:opacity-50",disabled:l.busy,onClick:()=>g?l.onUnstage([t.path]):l.onStage([t.path]),title:c(g?"git.stageArea.unstage":"git.stageArea.stage"),type:"button",children:g?i.jsx(hE,{className:"size-3.5"}):i.jsx(fs,{className:"size-3.5"})}):null,i.jsx("span",{className:oe("ml-1 shrink-0 font-mono text-[10px] font-semibold",s==="untracked"&&"text-amber-700 dark:text-amber-400",s==="staged"&&"text-emerald-700 dark:text-emerald-400",s==="unstaged"&&"text-zinc-800 dark:text-zinc-300"),children:EZ(t,s)})]})}function EZ(e,t){return t==="untracked"?"?":t==="staged"?e.index.trim():e.workingTree.trim()}function jZ(e){return[{id:"unstaged",labelKey:"git.group.changes",files:e.filter(t=>!(t.index==="?"&&t.workingTree==="?")&&t.workingTree.trim())},{id:"staged",labelKey:"git.group.staged",files:e.filter(t=>!(t.index==="?"&&t.workingTree==="?")&&t.index.trim()&&!t.workingTree.trim())},{id:"untracked",labelKey:"git.group.untracked",files:e.filter(t=>t.index==="?"&&t.workingTree==="?")}]}function RA({branch:e,files:t,onDone:s,repo:n}){const a=ee(),{sendToAgent:l}=Ot(),[c,d]=x.useState(""),[f,h]=x.useState(null),[g,p]=x.useState(null),[b,v]=x.useState(null),_=x.useMemo(()=>t.filter(A=>A.index.trim()&&A.index!=="?").map(A=>A.path),[t]),S=_.length>0&&c.trim().length>0&&f===null;async function C(A,j){h(A),p(null),v(null);try{if(await OE(c.trim(),n),j){const E=await Jf(n);v(a("git.commit.committedPushed",{branch:E.branch}))}else v(a("git.commit.committed"));d(""),s()}catch(E){p(E instanceof Error?E.message:String(E))}finally{h(null)}}function N(){l({prompt:TF({branch:e,stagedFiles:_}),source:{type:"git-commit",label:a("git.commit.sourceLabel")},mode:"send",label:a("git.commit.suggestLabel")})}return i.jsxs("div",{className:"shrink-0 space-y-2 border-t border-border bg-card/95 p-2.5",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-tight text-muted-foreground",children:a("git.commit.title")}),i.jsxs("span",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:"text-[11px] text-muted-foreground",children:a("git.commit.stagedCount",{count:_.length})}),i.jsxs("button",{"aria-label":a("git.commit.suggestAria"),className:"flex items-center gap-1 rounded px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50",disabled:_.length===0,onClick:N,title:a("git.commit.suggestTitle"),type:"button",children:[i.jsx(Xt,{className:"size-3.5"}),a("git.commit.aiMessage")]})]})]}),i.jsx("textarea",{"aria-label":a("git.commit.messageAria"),className:"min-h-16 w-full resize-y rounded-md border border-border bg-background px-2.5 py-1.5 text-[12px] outline-none transition-colors placeholder:text-muted-foreground focus:border-foreground/40 focus:ring-2 focus:ring-ring",onChange:A=>{d(A.target.value),p(null),v(null)},placeholder:_.length?a("git.commit.messagePlaceholder"):a("git.commit.stagePrompt"),value:c}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsxs(Q,{disabled:!S,onClick:()=>{C("commit",!1)},size:"sm",type:"button",variant:"outline",children:[f==="commit"?i.jsx(Lt,{className:"size-3.5 animate-spin"}):i.jsx(Ys,{className:"size-3.5"}),a("git.commit.commit")]}),i.jsxs(Q,{disabled:!S,onClick:()=>{C("push",!0)},size:"sm",type:"button",children:[f==="push"?i.jsx(Lt,{className:"size-3.5 animate-spin"}):i.jsx(Xf,{className:"size-3.5"}),a("git.commit.commitPush")]})]}),g?i.jsx(tt,{className:"px-2.5 py-1.5 text-[11px]",variant:"destructive",children:g}):b?i.jsx(tt,{className:"px-2.5 py-1.5 text-[11px]",variant:"muted",children:b}):null]})}function AZ(e){const t={name:"",path:"",children:[],isFile:!1},s=new Map;s.set("",t);const n=[...e].sort();for(const l of n){const c=l.split("/");let d="";for(let f=0;f<c.length;f+=1){const h=c[f],g=f===c.length-1,p=d?`${d}/${h}`:h;let b=s.get(p);b||(b={name:h,path:p,children:[],isFile:g},s.set(p,b),s.get(d)?.children.push(b)),d=p}}const a=l=>{l.children.sort((c,d)=>c.isFile!==d.isFile?c.isFile?1:-1:c.name.localeCompare(d.name)),l.children.forEach(a)};return a(t),t}function LC(e,t){const s={"":!0},n=a=>{for(const l of a.children)l.isFile||(s[l.path]=!0,t&&n(l))};return n(e),s}function OC({defaultExpandAll:e=!1,paths:t,status:s,selectedFile:n,onSelectFile:a,branch:l,emptyMessage:c,root:d,title:f}){const h=ee(),g=f??h("git.tree.filesDefault"),p=c??h("git.tree.emptyDefault"),b=x.useMemo(()=>AZ(t),[t]),v=x.useMemo(()=>LC(b,e),[e,b]),_=x.useMemo(()=>LC(b,!0),[b]),S=Math.max(0,Object.keys(_).length-1),C=x.useMemo(()=>{const P=new Map;for(const F of s)P.set(F.path,F);return P},[s]),[N,A]=x.useState(v),[j,E]=x.useState(!1);x.useEffect(()=>{j||b.children.length===0||(A(v),E(!0))},[v,j,b.children.length]);function T(P){A(F=>({...F,[P]:!F[P]}))}function L(){A(_)}function H(){A({"":!0})}return i.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[i.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border bg-card/95 px-2.5 py-1.5",children:[i.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-[12px] font-semibold tracking-tight",children:[i.jsx(ko,{className:"size-3.5"}),i.jsx("span",{className:"truncate",children:g})]}),i.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[S>0?i.jsxs("span",{className:"flex items-center gap-0.5",children:[i.jsx("button",{"aria-label":h("git.tree.expandAll"),className:"flex size-6 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:L,title:h("git.tree.expandAll"),type:"button",children:i.jsx(U6,{className:"size-3.5"})}),i.jsx("button",{"aria-label":h("git.tree.collapseAll"),className:"flex size-6 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:H,title:h("git.tree.collapseAll"),type:"button",children:i.jsx($6,{className:"size-3.5"})})]}):null,l?i.jsx(AA,{branch:l}):null,i.jsx(Ke,{variant:"secondary",children:t.length})]})]}),i.jsx("div",{className:"min-h-0 flex-1 overflow-auto py-1",children:b.children.length===0?i.jsx(tt,{variant:"muted",className:"m-3 text-center",children:p}):b.children.map(P=>i.jsx(MA,{depth:0,expanded:N,node:P,onSelectFile:a,onToggle:T,root:d,selectedFile:n,statusByPath:C},P.path))})]})}function MA({depth:e,expanded:t,node:s,onSelectFile:n,onToggle:a,root:l,selectedFile:c,statusByPath:d}){const f=t[s.path]??!1,h=6+e*12,g=l?d5(Pu(l,s.path)):{};if(s.isFile){const v=d.get(s.path),_=c===s.path;return i.jsxs("button",{className:oe("flex w-full items-center gap-1.5 px-1 py-0.5 text-left text-[12px] hover:bg-muted",_&&"bg-muted font-medium"),onClick:()=>n(s.path),style:{paddingLeft:h},type:"button",...g,children:[i.jsx(V0,{path:s.path}),i.jsx("span",{className:"min-w-0 flex-1 truncate",children:s.name}),v?i.jsx(TZ,{file:v}):null]})}const p=f?hn:_n,b=f?Vf:ko;return i.jsxs("div",{children:[i.jsxs("button",{className:"flex w-full items-center gap-1 py-0.5 text-left text-[12px] font-medium hover:bg-muted",onClick:()=>a(s.path),style:{paddingLeft:h},type:"button",...g,children:[i.jsx(p,{className:"size-3.5 shrink-0 text-muted-foreground"}),i.jsx(b,{className:"size-3.5 shrink-0 text-amber-600"}),i.jsx("span",{className:"min-w-0 flex-1 truncate",children:s.name})]}),f?s.children.map(v=>i.jsx(MA,{depth:e+1,expanded:t,node:v,onSelectFile:n,onToggle:a,root:l,selectedFile:c,statusByPath:d},v.path)):null]})}function TZ({file:e}){const t=e.workingTree.trim()||e.index.trim();if(!t)return null;const s=e.index.trim()&&!e.workingTree.trim()?"text-emerald-700 dark:text-emerald-400":t==="?"?"text-amber-700 dark:text-amber-400":"text-zinc-700 dark:text-zinc-300";return i.jsx("span",{className:oe("ml-1 shrink-0 font-mono text-[10px] font-semibold",s),children:t})}var kb,PC;function RZ(){if(PC)return kb;PC=1;function e(U){return U instanceof Map?U.clear=U.delete=U.set=function(){throw new Error("map is read-only")}:U instanceof Set&&(U.add=U.clear=U.delete=function(){throw new Error("set is read-only")}),Object.freeze(U),Object.getOwnPropertyNames(U).forEach(re=>{const _e=U[re],$e=typeof _e;($e==="object"||$e==="function")&&!Object.isFrozen(_e)&&e(_e)}),U}class t{constructor(re){re.data===void 0&&(re.data={}),this.data=re.data,this.isMatchIgnored=!1}ignoreMatch(){this.isMatchIgnored=!0}}function s(U){return U.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function n(U,...re){const _e=Object.create(null);for(const $e in U)_e[$e]=U[$e];return re.forEach(function($e){for(const lt in $e)_e[lt]=$e[lt]}),_e}const a="</span>",l=U=>!!U.scope,c=(U,{prefix:re})=>{if(U.startsWith("language:"))return U.replace("language:","language-");if(U.includes(".")){const _e=U.split(".");return[`${re}${_e.shift()}`,..._e.map(($e,lt)=>`${$e}${"_".repeat(lt+1)}`)].join(" ")}return`${re}${U}`};class d{constructor(re,_e){this.buffer="",this.classPrefix=_e.classPrefix,re.walk(this)}addText(re){this.buffer+=s(re)}openNode(re){if(!l(re))return;const _e=c(re.scope,{prefix:this.classPrefix});this.span(_e)}closeNode(re){l(re)&&(this.buffer+=a)}value(){return this.buffer}span(re){this.buffer+=`<span class="${re}">`}}const f=(U={})=>{const re={children:[]};return Object.assign(re,U),re};class h{constructor(){this.rootNode=f(),this.stack=[this.rootNode]}get top(){return this.stack[this.stack.length-1]}get root(){return this.rootNode}add(re){this.top.children.push(re)}openNode(re){const _e=f({scope:re});this.add(_e),this.stack.push(_e)}closeNode(){if(this.stack.length>1)return this.stack.pop()}closeAllNodes(){for(;this.closeNode(););}toJSON(){return JSON.stringify(this.rootNode,null,4)}walk(re){return this.constructor._walk(re,this.rootNode)}static _walk(re,_e){return typeof _e=="string"?re.addText(_e):_e.children&&(re.openNode(_e),_e.children.forEach($e=>this._walk(re,$e)),re.closeNode(_e)),re}static _collapse(re){typeof re!="string"&&re.children&&(re.children.every(_e=>typeof _e=="string")?re.children=[re.children.join("")]:re.children.forEach(_e=>{h._collapse(_e)}))}}class g extends h{constructor(re){super(),this.options=re}addText(re){re!==""&&this.add(re)}startScope(re){this.openNode(re)}endScope(){this.closeNode()}__addSublanguage(re,_e){const $e=re.root;_e&&($e.scope=`language:${_e}`),this.add($e)}toHTML(){return new d(this,this.options).value()}finalize(){return this.closeAllNodes(),!0}}function p(U){return U?typeof U=="string"?U:U.source:null}function b(U){return S("(?=",U,")")}function v(U){return S("(?:",U,")*")}function _(U){return S("(?:",U,")?")}function S(...U){return U.map(_e=>p(_e)).join("")}function C(U){const re=U[U.length-1];return typeof re=="object"&&re.constructor===Object?(U.splice(U.length-1,1),re):{}}function N(...U){return"("+(C(U).capture?"":"?:")+U.map($e=>p($e)).join("|")+")"}function A(U){return new RegExp(U.toString()+"|").exec("").length-1}function j(U,re){const _e=U&&U.exec(re);return _e&&_e.index===0}const E=/\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;function T(U,{joinWith:re}){let _e=0;return U.map($e=>{_e+=1;const lt=_e;let Dt=p($e),Ve="";for(;Dt.length>0;){const qe=E.exec(Dt);if(!qe){Ve+=Dt;break}Ve+=Dt.substring(0,qe.index),Dt=Dt.substring(qe.index+qe[0].length),qe[0][0]==="\\"&&qe[1]?Ve+="\\"+String(Number(qe[1])+lt):(Ve+=qe[0],qe[0]==="("&&_e++)}return Ve}).map($e=>`(${$e})`).join(re)}const L=/\b\B/,H="[a-zA-Z]\\w*",P="[a-zA-Z_]\\w*",F="\\b\\d+(\\.\\d+)?",M="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",z="\\b(0b[01]+)",G="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",D=(U={})=>{const re=/^#![ ]*\//;return U.binary&&(U.begin=S(re,/.*\b/,U.binary,/\b.*/)),n({scope:"meta",begin:re,end:/$/,relevance:0,"on:begin":(_e,$e)=>{_e.index!==0&&$e.ignoreMatch()}},U)},q={begin:"\\\\[\\s\\S]",relevance:0},W={scope:"string",begin:"'",end:"'",illegal:"\\n",contains:[q]},I={scope:"string",begin:'"',end:'"',illegal:"\\n",contains:[q]},Y={begin:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},$=function(U,re,_e={}){const $e=n({scope:"comment",begin:U,end:re,contains:[]},_e);$e.contains.push({scope:"doctag",begin:"[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)",end:/(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/,excludeBegin:!0,relevance:0});const lt=N("I","a","is","so","us","to","at","if","in","it","on",/[A-Za-z]+['](d|ve|re|ll|t|s|n)/,/[A-Za-z]+[-][a-z]+/,/[A-Za-z][a-z]{2,}/);return $e.contains.push({begin:S(/[ ]+/,"(",lt,/[.]?[:]?([.][ ]|[ ])/,"){3}")}),$e},me=$("//","$"),J=$("/\\*","\\*/"),V=$("#","$"),K={scope:"number",begin:F,relevance:0},xe={scope:"number",begin:M,relevance:0},ie={scope:"number",begin:z,relevance:0},Z={scope:"regexp",begin:/\/(?=[^/\n]*\/)/,end:/\/[gimuy]*/,contains:[q,{begin:/\[/,end:/\]/,relevance:0,contains:[q]}]},ge={scope:"title",begin:H,relevance:0},ne={scope:"title",begin:P,relevance:0},we={begin:"\\.\\s*"+P,relevance:0};var Ue=Object.freeze({__proto__:null,APOS_STRING_MODE:W,BACKSLASH_ESCAPE:q,BINARY_NUMBER_MODE:ie,BINARY_NUMBER_RE:z,COMMENT:$,C_BLOCK_COMMENT_MODE:J,C_LINE_COMMENT_MODE:me,C_NUMBER_MODE:xe,C_NUMBER_RE:M,END_SAME_AS_BEGIN:function(U){return Object.assign(U,{"on:begin":(re,_e)=>{_e.data._beginMatch=re[1]},"on:end":(re,_e)=>{_e.data._beginMatch!==re[1]&&_e.ignoreMatch()}})},HASH_COMMENT_MODE:V,IDENT_RE:H,MATCH_NOTHING_RE:L,METHOD_GUARD:we,NUMBER_MODE:K,NUMBER_RE:F,PHRASAL_WORDS_MODE:Y,QUOTE_STRING_MODE:I,REGEXP_MODE:Z,RE_STARTERS_RE:G,SHEBANG:D,TITLE_MODE:ge,UNDERSCORE_IDENT_RE:P,UNDERSCORE_TITLE_MODE:ne});function Pe(U,re){U.input[U.index-1]==="."&&re.ignoreMatch()}function Re(U,re){U.className!==void 0&&(U.scope=U.className,delete U.className)}function pe(U,re){re&&U.beginKeywords&&(U.begin="\\b("+U.beginKeywords.split(" ").join("|")+")(?!\\.)(?=\\b|\\s)",U.__beforeBegin=Pe,U.keywords=U.keywords||U.beginKeywords,delete U.beginKeywords,U.relevance===void 0&&(U.relevance=0))}function Qe(U,re){Array.isArray(U.illegal)&&(U.illegal=N(...U.illegal))}function jt(U,re){if(U.match){if(U.begin||U.end)throw new Error("begin & end are not supported with match");U.begin=U.match,delete U.match}}function dt(U,re){U.relevance===void 0&&(U.relevance=1)}const Fs=(U,re)=>{if(!U.beforeMatch)return;if(U.starts)throw new Error("beforeMatch cannot be used with starts");const _e=Object.assign({},U);Object.keys(U).forEach($e=>{delete U[$e]}),U.keywords=_e.keywords,U.begin=S(_e.beforeMatch,b(_e.begin)),U.starts={relevance:0,contains:[Object.assign(_e,{endsParent:!0})]},U.relevance=0,delete _e.beforeMatch},Cn=["of","and","for","in","not","or","if","then","parent","list","value"],gs="keyword";function Us(U,re,_e=gs){const $e=Object.create(null);return typeof U=="string"?lt(_e,U.split(" ")):Array.isArray(U)?lt(_e,U):Object.keys(U).forEach(function(Dt){Object.assign($e,Us(U[Dt],re,Dt))}),$e;function lt(Dt,Ve){re&&(Ve=Ve.map(qe=>qe.toLowerCase())),Ve.forEach(function(qe){const ct=qe.split("|");$e[ct[0]]=[Dt,fn(ct[0],ct[1])]})}}function fn(U,re){return re?Number(re):ni(U)?0:1}function ni(U){return Cn.includes(U.toLowerCase())}const Bn={},Pt=U=>{console.error(U)},bs=(U,...re)=>{console.log(`WARN: ${U}`,...re)},rs=(U,re)=>{Bn[`${U}/${re}`]||(console.log(`Deprecated as of ${U}. ${re}`),Bn[`${U}/${re}`]=!0)},st=new Error;function nt(U,re,{key:_e}){let $e=0;const lt=U[_e],Dt={},Ve={};for(let qe=1;qe<=re.length;qe++)Ve[qe+$e]=lt[qe],Dt[qe+$e]=!0,$e+=A(re[qe-1]);U[_e]=Ve,U[_e]._emit=Dt,U[_e]._multi=!0}function At(U){if(Array.isArray(U.begin)){if(U.skip||U.excludeBegin||U.returnBegin)throw Pt("skip, excludeBegin, returnBegin not compatible with beginScope: {}"),st;if(typeof U.beginScope!="object"||U.beginScope===null)throw Pt("beginScope must be object"),st;nt(U,U.begin,{key:"beginScope"}),U.begin=T(U.begin,{joinWith:""})}}function k(U){if(Array.isArray(U.end)){if(U.skip||U.excludeEnd||U.returnEnd)throw Pt("skip, excludeEnd, returnEnd not compatible with endScope: {}"),st;if(typeof U.endScope!="object"||U.endScope===null)throw Pt("endScope must be object"),st;nt(U,U.end,{key:"endScope"}),U.end=T(U.end,{joinWith:""})}}function se(U){U.scope&&typeof U.scope=="object"&&U.scope!==null&&(U.beginScope=U.scope,delete U.scope)}function ve(U){se(U),typeof U.beginScope=="string"&&(U.beginScope={_wrap:U.beginScope}),typeof U.endScope=="string"&&(U.endScope={_wrap:U.endScope}),At(U),k(U)}function ke(U){function re(Ve,qe){return new RegExp(p(Ve),"m"+(U.case_insensitive?"i":"")+(U.unicodeRegex?"u":"")+(qe?"g":""))}class _e{constructor(){this.matchIndexes={},this.regexes=[],this.matchAt=1,this.position=0}addRule(qe,ct){ct.position=this.position++,this.matchIndexes[this.matchAt]=ct,this.regexes.push([ct,qe]),this.matchAt+=A(qe)+1}compile(){this.regexes.length===0&&(this.exec=()=>null);const qe=this.regexes.map(ct=>ct[1]);this.matcherRe=re(T(qe,{joinWith:"|"}),!0),this.lastIndex=0}exec(qe){this.matcherRe.lastIndex=this.lastIndex;const ct=this.matcherRe.exec(qe);if(!ct)return null;const vs=ct.findIndex((or,jo)=>jo>0&&or!==void 0),ss=this.matchIndexes[vs];return ct.splice(0,vs),Object.assign(ct,ss)}}class $e{constructor(){this.rules=[],this.multiRegexes=[],this.count=0,this.lastIndex=0,this.regexIndex=0}getMatcher(qe){if(this.multiRegexes[qe])return this.multiRegexes[qe];const ct=new _e;return this.rules.slice(qe).forEach(([vs,ss])=>ct.addRule(vs,ss)),ct.compile(),this.multiRegexes[qe]=ct,ct}resumingScanAtSamePosition(){return this.regexIndex!==0}considerAll(){this.regexIndex=0}addRule(qe,ct){this.rules.push([qe,ct]),ct.type==="begin"&&this.count++}exec(qe){const ct=this.getMatcher(this.regexIndex);ct.lastIndex=this.lastIndex;let vs=ct.exec(qe);if(this.resumingScanAtSamePosition()&&!(vs&&vs.index===this.lastIndex)){const ss=this.getMatcher(0);ss.lastIndex=this.lastIndex+1,vs=ss.exec(qe)}return vs&&(this.regexIndex+=vs.position+1,this.regexIndex===this.count&&this.considerAll()),vs}}function lt(Ve){const qe=new $e;return Ve.contains.forEach(ct=>qe.addRule(ct.begin,{rule:ct,type:"begin"})),Ve.terminatorEnd&&qe.addRule(Ve.terminatorEnd,{type:"end"}),Ve.illegal&&qe.addRule(Ve.illegal,{type:"illegal"}),qe}function Dt(Ve,qe){const ct=Ve;if(Ve.isCompiled)return ct;[Re,jt,ve,Fs].forEach(ss=>ss(Ve,qe)),U.compilerExtensions.forEach(ss=>ss(Ve,qe)),Ve.__beforeBegin=null,[pe,Qe,dt].forEach(ss=>ss(Ve,qe)),Ve.isCompiled=!0;let vs=null;return typeof Ve.keywords=="object"&&Ve.keywords.$pattern&&(Ve.keywords=Object.assign({},Ve.keywords),vs=Ve.keywords.$pattern,delete Ve.keywords.$pattern),vs=vs||/\w+/,Ve.keywords&&(Ve.keywords=Us(Ve.keywords,U.case_insensitive)),ct.keywordPatternRe=re(vs,!0),qe&&(Ve.begin||(Ve.begin=/\B|\b/),ct.beginRe=re(ct.begin),!Ve.end&&!Ve.endsWithParent&&(Ve.end=/\B|\b/),Ve.end&&(ct.endRe=re(ct.end)),ct.terminatorEnd=p(ct.end)||"",Ve.endsWithParent&&qe.terminatorEnd&&(ct.terminatorEnd+=(Ve.end?"|":"")+qe.terminatorEnd)),Ve.illegal&&(ct.illegalRe=re(Ve.illegal)),Ve.contains||(Ve.contains=[]),Ve.contains=[].concat(...Ve.contains.map(function(ss){return Le(ss==="self"?Ve:ss)})),Ve.contains.forEach(function(ss){Dt(ss,ct)}),Ve.starts&&Dt(Ve.starts,qe),ct.matcher=lt(ct),ct}if(U.compilerExtensions||(U.compilerExtensions=[]),U.contains&&U.contains.includes("self"))throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");return U.classNameAliases=n(U.classNameAliases||{}),Dt(U)}function le(U){return U?U.endsWithParent||le(U.starts):!1}function Le(U){return U.variants&&!U.cachedVariants&&(U.cachedVariants=U.variants.map(function(re){return n(U,{variants:null},re)})),U.cachedVariants?U.cachedVariants:le(U)?n(U,{starts:U.starts?n(U.starts):null}):Object.isFrozen(U)?n(U):U}var O="11.11.1";class ce extends Error{constructor(re,_e){super(re),this.name="HTMLInjectionError",this.html=_e}}const Oe=s,Ce=n,fe=Symbol("nomatch"),Me=7,je=function(U){const re=Object.create(null),_e=Object.create(null),$e=[];let lt=!0;const Dt="Could not find the language '{}', did you forget to load/include a language module?",Ve={disableAutodetect:!0,name:"Plain text",contains:[]};let qe={ignoreUnescapedHTML:!1,throwUnescapedHTML:!1,noHighlightRe:/^(no-?highlight)$/i,languageDetectRe:/\blang(?:uage)?-([\w-]+)\b/i,classPrefix:"hljs-",cssSelector:"pre code",languages:null,__emitter:g};function ct(ze){return qe.noHighlightRe.test(ze)}function vs(ze){let it=ze.className+" ";it+=ze.parentNode?ze.parentNode.className:"";const yt=qe.languageDetectRe.exec(it);if(yt){const zt=mn(yt[1]);return zt||(bs(Dt.replace("{}",yt[1])),bs("Falling back to no-highlight mode for this block.",ze)),zt?yt[1]:"no-highlight"}return it.split(/\s+/).find(zt=>ct(zt)||mn(zt))}function ss(ze,it,yt){let zt="",ys="";typeof it=="object"?(zt=ze,yt=it.ignoreIllegals,ys=it.language):(rs("10.7.0","highlight(lang, code, ...args) has been deprecated."),rs("10.7.0",`Please use highlight(code, options) instead.
|
|
@@ -216,7 +216,7 @@ Please report this to https://github.com/markedjs/marked.`,e){let n="<p>An error
|
|
|
216
216
|
`+O.slice(fe,Me),fe=Me+1),je=He;return U+=`
|
|
217
217
|
`,O.length-fe>ce&&je>fe?U+=O.slice(fe,je)+`
|
|
218
218
|
`+O.slice(je+1):U+=O.slice(fe),U.slice(1)}function rs(O){let ce="",Oe=0;for(let Ce=0;Ce<O.length;Oe>=65536?Ce+=2:Ce++){Oe=pe(O,Ce);const fe=I[Oe];!fe&&we(Oe)?(ce+=O[Ce],Oe>=65536&&(ce+=O[Ce+1])):ce+=fe||J(Oe)}return ce}function st(O,ce,Oe){let Ce="";const fe=O.tag;for(let Me=0,je=Oe.length;Me<je;Me+=1){let He=Oe[Me];O.replacer&&(He=O.replacer.call(Oe,String(Me),He)),(ve(O,ce,He,!1,!1)||typeof He>"u"&&ve(O,ce,null,!1,!1))&&(Ce!==""&&(Ce+=","+(O.condenseFlow?"":" ")),Ce+=O.dump)}O.tag=fe,O.dump="["+Ce+"]"}function nt(O,ce,Oe,Ce){let fe="";const Me=O.tag;for(let je=0,He=Oe.length;je<He;je+=1){let U=Oe[je];O.replacer&&(U=O.replacer.call(Oe,String(je),U)),(ve(O,ce+1,U,!0,!0,!1,!0)||typeof U>"u"&&ve(O,ce+1,null,!0,!0,!1,!0))&&((!Ce||fe!=="")&&(fe+=Z(O,ce)),O.dump&&h===O.dump.charCodeAt(0)?fe+="-":fe+="- ",fe+=O.dump)}O.tag=Me,O.dump=fe||"[]"}function At(O,ce,Oe){let Ce="";const fe=O.tag,Me=Object.keys(Oe);for(let je=0,He=Me.length;je<He;je+=1){let U="";Ce!==""&&(U+=", "),O.condenseFlow&&(U+='"');const re=Me[je];let _e=Oe[re];O.replacer&&(_e=O.replacer.call(Oe,re,_e)),ve(O,ce,re,!1,!1)&&(O.dump.length>1024&&(U+="? "),U+=O.dump+(O.condenseFlow?'"':"")+":"+(O.condenseFlow?"":" "),ve(O,ce,_e,!1,!1)&&(U+=O.dump,Ce+=U))}O.tag=fe,O.dump="{"+Ce+"}"}function k(O,ce,Oe,Ce){let fe="";const Me=O.tag,je=Object.keys(Oe);if(O.sortKeys===!0)je.sort();else if(typeof O.sortKeys=="function")je.sort(O.sortKeys);else if(O.sortKeys)throw new n("sortKeys must be a boolean or a function");for(let He=0,U=je.length;He<U;He+=1){let re="";(!Ce||fe!=="")&&(re+=Z(O,ce));const _e=je[He];let $e=Oe[_e];if(O.replacer&&($e=O.replacer.call(Oe,_e,$e)),!ve(O,ce+1,_e,!0,!0,!0))continue;const lt=O.tag!==null&&O.tag!=="?"||O.dump&&O.dump.length>1024;lt&&(O.dump&&h===O.dump.charCodeAt(0)?re+="?":re+="? "),re+=O.dump,lt&&(re+=Z(O,ce)),ve(O,ce+1,$e,!0,lt)&&(O.dump&&h===O.dump.charCodeAt(0)?re+=":":re+=": ",re+=O.dump,fe+=re)}O.tag=Me,O.dump=fe||"{}"}function se(O,ce,Oe){const Ce=Oe?O.explicitTypes:O.implicitTypes;for(let fe=0,Me=Ce.length;fe<Me;fe+=1){const je=Ce[fe];if((je.instanceOf||je.predicate)&&(!je.instanceOf||typeof ce=="object"&&ce instanceof je.instanceOf)&&(!je.predicate||je.predicate(ce))){if(Oe?je.multi&&je.representName?O.tag=je.representName(ce):O.tag=je.tag:O.tag="?",je.represent){const He=O.styleMap[je.tag]||je.defaultStyle;let U;if(l.call(je.represent)==="[object Function]")U=je.represent(ce,He);else if(c.call(je.represent,He))U=je.represent[He](ce,He);else throw new n("!<"+je.tag+'> tag resolver accepts not "'+He+'" style');O.dump=U}return!0}}return!1}function ve(O,ce,Oe,Ce,fe,Me,je){O.tag=null,O.dump=Oe,se(O,Oe,!1)||se(O,Oe,!0);const He=l.call(O.dump),U=Ce;Ce&&(Ce=O.flowLevel<0||O.flowLevel>ce);const re=He==="[object Object]"||He==="[object Array]";let _e,$e;if(re&&(_e=O.duplicates.indexOf(Oe),$e=_e!==-1),(O.tag!==null&&O.tag!=="?"||$e||O.indent!==2&&ce>0)&&(fe=!1),$e&&O.usedDuplicates[_e])O.dump="*ref_"+_e;else{if(re&&$e&&!O.usedDuplicates[_e]&&(O.usedDuplicates[_e]=!0),He==="[object Object]")Ce&&Object.keys(O.dump).length!==0?(k(O,ce,O.dump,fe),$e&&(O.dump="&ref_"+_e+O.dump)):(At(O,ce,O.dump),$e&&(O.dump="&ref_"+_e+" "+O.dump));else if(He==="[object Array]")Ce&&O.dump.length!==0?(O.noArrayIndent&&!je&&ce>0?nt(O,ce-1,O.dump,fe):nt(O,ce,O.dump,fe),$e&&(O.dump="&ref_"+_e+O.dump)):(st(O,ce,O.dump),$e&&(O.dump="&ref_"+_e+" "+O.dump));else if(He==="[object String]")O.tag!=="?"&&fn(O,O.dump,ce,Me,U);else{if(He==="[object Undefined]")return!1;if(O.skipInvalid)return!1;throw new n("unacceptable kind of an object to dump "+He)}if(O.tag!==null&&O.tag!=="?"){let lt=encodeURI(O.tag[0]==="!"?O.tag.slice(1):O.tag).replace(/!/g,"%21");O.tag[0]==="!"?lt="!"+lt:lt.slice(0,18)==="tag:yaml.org,2002:"?lt="!!"+lt.slice(18):lt="!<"+lt+">",O.dump=lt+" "+O.dump}}return!0}function ke(O,ce){const Oe=[],Ce=[];le(O,Oe,Ce);const fe=Ce.length;for(let Me=0;Me<fe;Me+=1)ce.duplicates.push(Oe[Ce[Me]]);ce.usedDuplicates=new Array(fe)}function le(O,ce,Oe){if(O!==null&&typeof O=="object"){const Ce=ce.indexOf(O);if(Ce!==-1)Oe.indexOf(Ce)===-1&&Oe.push(Ce);else if(ce.push(O),Array.isArray(O))for(let fe=0,Me=O.length;fe<Me;fe+=1)le(O[fe],ce,Oe);else{const fe=Object.keys(O);for(let Me=0,je=fe.length;Me<je;Me+=1)le(O[fe[Me]],ce,Oe)}}}function Le(O,ce){ce=ce||{};const Oe=new xe(ce);Oe.noRefs||ke(O,Oe);let Ce=O;return Oe.replacer&&(Ce=Oe.replacer.call({"":Ce},"",Ce)),ve(Oe,0,Ce,!0,!0)?Oe.dump+`
|
|
219
|
-
`:""}t.exports.dump=Le})),oT=uJ(ts(((e,t)=>{var s=hJ(),n=fJ();function a(l,c){return function(){throw new Error("Function yaml."+l+" is removed in js-yaml 4. Use yaml."+c+" instead, which is now safe by default.")}}t.exports.Type=kn(),t.exports.Schema=qA(),t.exports.FAILSAFE_SCHEMA=KA(),t.exports.JSON_SCHEMA=JA(),t.exports.CORE_SCHEMA=eT(),t.exports.DEFAULT_SCHEMA=a1(),t.exports.load=s.load,t.exports.loadAll=s.loadAll,t.exports.dump=n.dump,t.exports.YAMLException=Uu(),t.exports.types={binary:nT(),float:QA(),map:WA(),null:YA(),pairs:rT(),set:aT(),timestamp:tT(),bool:XA(),int:ZA(),merge:sT(),omap:iT(),seq:VA(),str:GA()},t.exports.safeLoad=a("safeLoad","load"),t.exports.safeLoadAll=a("safeLoadAll","loadAll"),t.exports.safeDump=a("safeDump","dump")}))()),{Type:Hte,Schema:$te,FAILSAFE_SCHEMA:Fte,JSON_SCHEMA:Ute,CORE_SCHEMA:qte,DEFAULT_SCHEMA:Gte,load:Vte,loadAll:Wte,dump:Kte,YAMLException:Yte,types:Xte,safeLoad:Zte,safeLoadAll:Qte,safeDump:Jte}=oT.default,mJ=oT.default;function lT(e){return e!==null&&typeof e=="object"}function cT(e){return typeof e=="string"?"text-rose-700 dark:text-rose-300":typeof e=="number"?"text-emerald-700 dark:text-emerald-300":typeof e=="boolean"?"text-blue-700 dark:text-blue-400":e==null?"text-muted-foreground italic":"text-foreground"}function uT(e){return e==null?"null":typeof e=="string"?e===""?'""':e:String(e)}function dT({label:e,value:t,depth:s,defaultOpen:n}){const[a,l]=x.useState(n),c={paddingLeft:`${s*1.1}rem`};if(!lT(t))return i.jsxs("div",{className:"flex items-baseline gap-2 py-[1px]",style:c,children:[i.jsxs("span",{className:"text-muted-foreground",children:[e,":"]}),i.jsx("span",{className:oe("whitespace-pre-wrap break-words",cT(t)),children:uT(t)})]});const d=Array.isArray(t)?t.map((h,g)=>[String(g),h]):Object.entries(t),f=Array.isArray(t)?`[${d.length}]`:`{${d.length}}`;return i.jsxs("div",{children:[i.jsxs("button",{type:"button",onClick:()=>l(h=>!h),className:"flex w-full items-center gap-1 py-[1px] text-left hover:bg-muted",style:c,children:[a?i.jsx(hn,{className:"size-3.5 shrink-0 text-muted-foreground"}):i.jsx(_n,{className:"size-3.5 shrink-0 text-muted-foreground"}),i.jsx("span",{className:"font-medium text-foreground",children:e}),i.jsx("span",{className:"text-muted-foreground",children:f})]}),a?d.map(([h,g])=>i.jsx(dT,{label:h,value:g,depth:s+1,defaultOpen:s<1},h)):null]})}function pJ({content:e}){const t=ee(),s=x.useMemo(()=>{try{const a=mJ.loadAll(e);return{value:a.length<=1?a[0]:a,error:null}}catch(a){return{value:null,error:a instanceof Error?a.message:String(a)}}},[e]);if(s.error)return i.jsx("div",{className:"p-4",children:i.jsx(tt,{variant:"destructive",children:t("git.yaml.parseError",{error:s.error})})});if(!lT(s.value))return i.jsx("div",{className:"p-4 font-mono text-[12px]",children:i.jsx("span",{className:cT(s.value),children:uT(s.value)})});const n=Array.isArray(s.value)?s.value.map((a,l)=>[String(l),a]):Object.entries(s.value);return i.jsx("div",{className:"min-w-max px-4 py-3 font-mono text-[12px] leading-[1.6]",children:n.map(([a,l])=>i.jsx(dT,{label:a,value:l,depth:0,defaultOpen:!0},a))})}const gJ=x.lazy(()=>Tu(()=>import("./code-editor-
|
|
219
|
+
`:""}t.exports.dump=Le})),oT=uJ(ts(((e,t)=>{var s=hJ(),n=fJ();function a(l,c){return function(){throw new Error("Function yaml."+l+" is removed in js-yaml 4. Use yaml."+c+" instead, which is now safe by default.")}}t.exports.Type=kn(),t.exports.Schema=qA(),t.exports.FAILSAFE_SCHEMA=KA(),t.exports.JSON_SCHEMA=JA(),t.exports.CORE_SCHEMA=eT(),t.exports.DEFAULT_SCHEMA=a1(),t.exports.load=s.load,t.exports.loadAll=s.loadAll,t.exports.dump=n.dump,t.exports.YAMLException=Uu(),t.exports.types={binary:nT(),float:QA(),map:WA(),null:YA(),pairs:rT(),set:aT(),timestamp:tT(),bool:XA(),int:ZA(),merge:sT(),omap:iT(),seq:VA(),str:GA()},t.exports.safeLoad=a("safeLoad","load"),t.exports.safeLoadAll=a("safeLoadAll","loadAll"),t.exports.safeDump=a("safeDump","dump")}))()),{Type:Hte,Schema:$te,FAILSAFE_SCHEMA:Fte,JSON_SCHEMA:Ute,CORE_SCHEMA:qte,DEFAULT_SCHEMA:Gte,load:Vte,loadAll:Wte,dump:Kte,YAMLException:Yte,types:Xte,safeLoad:Zte,safeLoadAll:Qte,safeDump:Jte}=oT.default,mJ=oT.default;function lT(e){return e!==null&&typeof e=="object"}function cT(e){return typeof e=="string"?"text-rose-700 dark:text-rose-300":typeof e=="number"?"text-emerald-700 dark:text-emerald-300":typeof e=="boolean"?"text-blue-700 dark:text-blue-400":e==null?"text-muted-foreground italic":"text-foreground"}function uT(e){return e==null?"null":typeof e=="string"?e===""?'""':e:String(e)}function dT({label:e,value:t,depth:s,defaultOpen:n}){const[a,l]=x.useState(n),c={paddingLeft:`${s*1.1}rem`};if(!lT(t))return i.jsxs("div",{className:"flex items-baseline gap-2 py-[1px]",style:c,children:[i.jsxs("span",{className:"text-muted-foreground",children:[e,":"]}),i.jsx("span",{className:oe("whitespace-pre-wrap break-words",cT(t)),children:uT(t)})]});const d=Array.isArray(t)?t.map((h,g)=>[String(g),h]):Object.entries(t),f=Array.isArray(t)?`[${d.length}]`:`{${d.length}}`;return i.jsxs("div",{children:[i.jsxs("button",{type:"button",onClick:()=>l(h=>!h),className:"flex w-full items-center gap-1 py-[1px] text-left hover:bg-muted",style:c,children:[a?i.jsx(hn,{className:"size-3.5 shrink-0 text-muted-foreground"}):i.jsx(_n,{className:"size-3.5 shrink-0 text-muted-foreground"}),i.jsx("span",{className:"font-medium text-foreground",children:e}),i.jsx("span",{className:"text-muted-foreground",children:f})]}),a?d.map(([h,g])=>i.jsx(dT,{label:h,value:g,depth:s+1,defaultOpen:s<1},h)):null]})}function pJ({content:e}){const t=ee(),s=x.useMemo(()=>{try{const a=mJ.loadAll(e);return{value:a.length<=1?a[0]:a,error:null}}catch(a){return{value:null,error:a instanceof Error?a.message:String(a)}}},[e]);if(s.error)return i.jsx("div",{className:"p-4",children:i.jsx(tt,{variant:"destructive",children:t("git.yaml.parseError",{error:s.error})})});if(!lT(s.value))return i.jsx("div",{className:"p-4 font-mono text-[12px]",children:i.jsx("span",{className:cT(s.value),children:uT(s.value)})});const n=Array.isArray(s.value)?s.value.map((a,l)=>[String(l),a]):Object.entries(s.value);return i.jsx("div",{className:"min-w-max px-4 py-3 font-mono text-[12px] leading-[1.6]",children:n.map(([a,l])=>i.jsx(dT,{label:a,value:l,depth:0,defaultOpen:!0},a))})}const gJ=x.lazy(()=>Tu(()=>import("./code-editor-CkE0Uvxv.js"),[]).then(e=>({default:e.CodeEditor})));function bJ(e){const t=e.split("/").pop()?.toLowerCase().split(".").pop()??"";return t==="md"||t==="mdx"||t==="markdown"?"markdown":t==="yml"||t==="yaml"?"yaml":null}function vJ(e){const t=e.split("/").pop()?.toLowerCase()??"",s=t.includes(".")?t.split(".").pop()??"":"",n={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",mjs:"javascript",cjs:"javascript",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",kt:"kotlin",swift:"swift",c:"c",h:"c",cpp:"cpp",cc:"cpp",hpp:"cpp",cs:"csharp",sh:"bash",bash:"bash",zsh:"bash",json:"json",yaml:"yaml",yml:"yaml",toml:"ini",ini:"ini",md:"markdown",mdx:"markdown",css:"css",scss:"scss",less:"less",html:"xml",xml:"xml",sql:"sql",dockerfile:"dockerfile"};return n[s]?n[s]:t==="dockerfile"?"dockerfile":null}function xJ(e,t){const s=e.endsWith(`
|
|
220
220
|
`)?e.slice(0,-1):e;return!t||!Ex.getLanguage(t)?s.split(`
|
|
221
221
|
`).map(EN):s.split(`
|
|
222
222
|
`).map(n=>{if(!n)return"";try{return Ex.highlight(n,{language:t,ignoreIllegals:!0}).value}catch{return EN(n)}})}function EN(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function yJ({content:e,path:t}){const s=x.useMemo(()=>vJ(t),[t]),n=x.useMemo(()=>xJ(e,s),[e,s]),a=`${Math.max(2,String(n.length).length)}ch`;return i.jsx("div",{className:"min-w-max font-mono text-[12px] leading-[1.5]",children:n.map((l,c)=>i.jsxs("div",{className:"flex",children:[i.jsx("span",{className:"shrink-0 select-none border-r border-zinc-200 bg-zinc-100 px-2 text-right text-zinc-400 dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-500",style:{minWidth:`calc(${a} + 1rem)`},children:c+1}),i.jsx("span",{className:"hljs whitespace-pre px-3 text-zinc-800 dark:text-zinc-100",dangerouslySetInnerHTML:{__html:l||" "}})]},c))})}function _J({path:e,isModified:t,onViewDiff:s,onFileSaved:n,onSendToAi:a}){const[l,c]=x.useState(null),[d,f]=x.useState(""),[h,g]=x.useState(!1),[p,b]=x.useState(null),[v,_]=x.useState(!1),[S,C]=x.useState(!1),{success:N,error:A}=ms(),j=ee(),E=x.useMemo(()=>bJ(e),[e]),[T,L]=x.useState("preview"),H=!!(l&&!l.binary&&!l.truncated),P=l?d!==l.content:!1;x.useEffect(()=>{L(E?"preview":"source"),g(!1)},[E]),x.useEffect(()=>{if(!e){c(null);return}let z=!0;return _(!0),b(null),g(!1),r7(e).then(G=>{z&&(c(G),f(G.content),_(!1))}).catch(G=>{z&&(b(G instanceof Error?G.message:String(G)),_(!1))}),()=>{z=!1}},[e]);async function F(){if(!(!e||!l||!P||S)){C(!0);try{await a7(e,d);const z={...l,content:d,size:new TextEncoder().encode(d).length};c(z),g(!1),N(j("git.fileViewer.savedToast",{path:e})),n?.(e)}catch(z){A(z instanceof Error?z.message:String(z))}finally{C(!1)}}}function M(){f(l?.content??""),g(!1)}return e?i.jsxs("section",{className:"flex min-h-0 min-w-0 flex-col border-l border-border bg-card",children:[i.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border px-3 py-1.5",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:e}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[10px] text-muted-foreground",children:[i.jsx("span",{children:j("git.fileViewer.readOnly")}),l?.truncated?i.jsx("span",{className:"text-amber-700",children:j("git.fileViewer.truncated")}):null,l?.binary?i.jsx("span",{className:"text-amber-700",children:j("git.fileViewer.binary")}):null]})]}),i.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[E&&!l?.binary?i.jsxs("div",{className:"flex items-center rounded-md border border-border p-0.5",children:[i.jsxs("button",{type:"button",onClick:()=>L("preview"),"aria-pressed":T==="preview",className:oe("flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium transition-colors",T==="preview"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-muted"),children:[i.jsx(Gf,{className:"size-3.5"}),j("git.fileViewer.preview")]}),i.jsxs("button",{type:"button",onClick:()=>L("source"),"aria-pressed":T==="source",className:oe("flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium transition-colors",T==="source"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-muted"),children:[i.jsx(sE,{className:"size-3.5"}),j("git.fileViewer.source")]})]}):null,t?i.jsx(Q,{onClick:s,size:"sm",type:"button",variant:"outline",children:j("git.fileViewer.viewDiff")}):null,a?i.jsx(Q,{"aria-label":j("git.fileViewer.sendToAi"),className:"size-8",disabled:!e,onClick:a,size:"icon",title:j("git.fileViewer.sendPathToAi"),type:"button",variant:"outline",children:i.jsx(Xt,{className:"size-4"})}):null,h?i.jsxs(i.Fragment,{children:[i.jsxs(Q,{disabled:!P||S,onClick:()=>{F()},size:"sm",type:"button",children:[i.jsx(mE,{}),j("git.fileViewer.apply")]}),i.jsxs(Q,{disabled:S,onClick:M,size:"sm",type:"button",variant:"outline",children:[i.jsx(Vt,{}),j("common.cancel")]})]}):H?i.jsxs(Q,{onClick:()=>{L("source"),g(!0)},size:"sm",type:"button",variant:"outline",children:[i.jsx(Cl,{}),j("common.edit")]}):null]})]}),i.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-card",children:p?i.jsx("div",{className:"p-4",children:i.jsx(tt,{variant:"destructive",children:p})}):v?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:j("common.loading")}):l?.binary?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:j("git.fileViewer.cannotBinary")}):l?h?i.jsx(x.Suspense,{fallback:i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:j("git.fileViewer.loadingEditor")}),children:i.jsx(gJ,{path:e,value:d,onChange:f})}):E&&T==="preview"?E==="markdown"?i.jsx(r1,{content:l.content}):i.jsx(pJ,{content:l.content}):i.jsx(yJ,{content:l.content,path:e}):null})]}):i.jsx("div",{className:"p-4",children:i.jsx(tt,{variant:"muted",className:"border-dashed p-12 text-center",children:j("git.fileViewer.selectFile")})})}function wJ({activeHunkIndex:e,filePaths:t,hunkCount:s,pendingNextFilePath:n,selectedFile:a}){if(s>0&&e<s-1)return{kind:"hunk",activeHunkIndex:e+1};const l=t.indexOf(a),c=t[l+1];return c?n===c?{kind:"file",filePath:c}:{kind:"confirm-next-file",filePath:c}:{kind:"none"}}function jN(e){const t={name:"",fullPath:"",children:new Map};for(const s of e){const n=s.name.split("/");let a=t;n.forEach((l,c)=>{let d=a.children.get(l);d||(d={name:l,fullPath:n.slice(0,c+1).join("/"),children:new Map},a.children.set(l,d)),a=d}),a.branch=s}return t}function AN({label:e,tree:t,onSelect:s,defaultOpen:n,forceOpen:a}){const[l,c]=x.useState(n??!1),d=a||l,f=t.children.size===0;return i.jsxs("div",{className:"mb-1",children:[i.jsxs("button",{type:"button",onClick:()=>c(h=>!h),className:"flex w-full items-center gap-1 px-2 py-0.5 text-left text-[11px] font-semibold uppercase tracking-wide text-muted-foreground hover:text-foreground",children:[d?i.jsx(hn,{size:12}):i.jsx(_n,{size:12}),e,f?null:i.jsxs("span",{className:"ml-1 text-[10px] font-normal",children:["(",t.children.size,")"]})]}),d&&!f?i.jsx("ul",{children:Array.from(t.children.values()).map(h=>i.jsx(hT,{node:h,depth:1,onSelect:s,forceOpen:a},h.fullPath))}):null]})}function hT({node:e,depth:t,onSelect:s,forceOpen:n}){const[a,l]=x.useState(!0),c=n||a,d=e.children.size>0,f=e.branch,h={paddingLeft:`${t*10}px`};return!d&&f?i.jsx("li",{children:i.jsxs("button",{type:"button",onClick:()=>s(f),style:h,title:f.name,className:`flex w-full items-center gap-1.5 py-0.5 pr-2 text-left text-[12px] hover:bg-muted/60 ${f.current?"font-semibold text-emerald-700":""}`,children:[i.jsx(Pn,{size:11,className:"shrink-0 opacity-70"}),i.jsx("span",{className:"truncate",children:e.name}),f.current?i.jsx("span",{className:"text-[10px]",children:"●"}):null]})}):i.jsxs("li",{children:[i.jsxs("button",{type:"button",onClick:()=>{f?s(f):l(g=>!g)},style:h,className:"flex w-full items-center gap-1 py-0.5 pr-2 text-left text-[12px] hover:bg-muted/60",children:[d?c?i.jsx(hn,{size:11}):i.jsx(_n,{size:11}):i.jsx("span",{className:"inline-block w-[11px]"}),i.jsx("span",{className:"truncate",children:e.name})]}),c&&d?i.jsx("ul",{children:Array.from(e.children.values()).map(g=>i.jsx(hT,{node:g,depth:t+1,onSelect:s,forceOpen:n},g.fullPath))}):null]})}function SJ({selectedCommit:e,selectedFile:t,diff:s,diffLoading:n,diffError:a}){const l=ee();return i.jsxs("section",{className:"flex min-h-0 min-w-0 flex-col bg-card border-b border-border",children:[i.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border px-3 py-1.5",children:i.jsxs("div",{className:"min-w-0",children:[i.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:t??(e?e.subject:l("git.graph.commitFallback"))}),e?i.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[10px] text-muted-foreground",children:[i.jsx("span",{className:"font-mono",children:e.hash.slice(0,12)}),i.jsxs("span",{children:[e.author," <",e.email,">"]}),i.jsx("span",{children:new Date(e.timestamp*1e3).toLocaleString()})]}):null]})}),i.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:a?i.jsx("div",{className:"p-4",children:i.jsx(tt,{variant:"destructive",children:a})}):e?n?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:l("git.diff.loading")}):s?i.jsx(Ou,{activeHunkIndex:0,diff:s}):i.jsx("div",{className:"p-4",children:i.jsx(tt,{variant:"muted",className:"border-dashed p-6 text-center",children:e.parents.length>1?l("git.graph.mergeNoDiff"):l("git.graph.noTextualChanges")})}):i.jsx("div",{className:"p-4",children:i.jsx(tt,{variant:"muted",className:"border-dashed p-12 text-center",children:l("git.graph.selectCommitDiff")})})})]})}function kJ({files:e,filesError:t,selectedHash:s,selectedFile:n,onSelect:a}){const l=ee();return i.jsxs("aside",{className:"flex min-h-0 flex-col overflow-hidden border-r border-border",children:[i.jsx("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:i.jsxs("h2",{className:"text-[13px] font-semibold tracking-tight",children:[l("git.tree.filesDefault"),e.length?i.jsx("span",{className:"ml-2 text-[11px] font-normal text-muted-foreground",children:e.length}):null]})}),i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:t?i.jsx("div",{className:"p-3",children:i.jsx(tt,{variant:"destructive",children:t})}):s?e.length===0?i.jsx("div",{className:"p-3 text-[12px] text-muted-foreground",children:l("git.graph.noFileChanges")}):i.jsx("ul",{className:"divide-y divide-border",children:e.map(c=>i.jsx("li",{children:i.jsxs("button",{onClick:()=>a(c.path),type:"button",title:c.path,className:`flex w-full items-center gap-2 px-2 py-1 text-left text-[12px] transition-colors hover:bg-muted/60 ${n===c.path?"bg-muted":""}`,children:[i.jsx("span",{className:CJ(c.index),children:c.index.trim()||"·"}),i.jsx("span",{className:"truncate font-mono",children:c.path})]})},c.path))}):i.jsx("div",{className:"p-3 text-[12px] text-muted-foreground",children:l("git.graph.selectCommitFiles")})})]})}function CJ(e){const t="inline-flex h-4 w-4 shrink-0 items-center justify-center rounded text-[10px] font-bold";switch(e.trim().toUpperCase()){case"A":return`${t} bg-emerald-100 text-emerald-800 dark:bg-emerald-500/15 dark:text-emerald-300`;case"D":return`${t} bg-red-100 text-red-800 dark:bg-red-500/15 dark:text-red-300`;case"M":return`${t} bg-amber-100 text-amber-800 dark:bg-amber-500/15 dark:text-amber-300`;case"R":return`${t} bg-blue-100 text-blue-800 dark:bg-blue-500/15 dark:text-blue-300`;case"C":return`${t} bg-indigo-100 text-indigo-800 dark:bg-indigo-500/15 dark:text-indigo-300`;default:return`${t} bg-slate-100 text-slate-700 dark:bg-slate-500/15 dark:text-slate-300`}}const TN=["#3b82f6","#10b981","#f59e0b","#ec4899","#8b5cf6","#14b8a6","#ef4444","#84cc16"];function Vc(e){return TN[e%TN.length]}function NJ({lane:e,laneCount:t,edges:s,throughLanes:n,isMerge:a,height:l=28,laneWidth:c=14}){const f=Math.max(e+1,t,1)*c,h=l/2,g=Wc(e,c),p=a?4:3.5;return i.jsxs("svg",{width:f,height:l,viewBox:`0 0 ${f} ${l}`,style:{flex:"0 0 auto",display:"block"},children:[n.map(b=>i.jsx("line",{x1:Wc(b,c),y1:0,x2:Wc(b,c),y2:l,stroke:Vc(b),strokeWidth:1.5},`t-${b}`)),i.jsx("line",{x1:g,y1:0,x2:g,y2:h,stroke:Vc(e),strokeWidth:1.5}),s.map((b,v)=>{const _=Wc(b.fromLane,c),S=Wc(b.toLane,c);if(_===S)return i.jsx("line",{x1:_,y1:h,x2:S,y2:l,stroke:Vc(b.toLane),strokeWidth:1.5},`e-${v}`);const C=h+(l-h)/2;return i.jsx("path",{d:`M ${_} ${h} C ${_} ${C}, ${S} ${C}, ${S} ${l}`,fill:"none",stroke:Vc(b.toLane),strokeWidth:1.5},`e-${v}`)}),i.jsx("circle",{cx:g,cy:h,r:p,fill:Vc(e),stroke:"var(--background, #fff)",strokeWidth:1.5})]})}function Wc(e,t){return e*t+t/2}const EJ=5,Rx=new Map,lv=new Map,Mx=[];let Dx=0;function RN(){for(;Dx<EJ&&Mx.length>0;){const e=Mx.shift();e&&(Dx++,e())}}function jJ(e){return Rx.get(e)}function AJ(e){const t=Rx.get(e);if(t)return Promise.resolve(t);const s=lv.get(e);if(s)return s;const n=new Promise((a,l)=>{Mx.push(()=>{T7(e).then(c=>{c.state!=="pending"&&Rx.set(e,c),a(c)}).catch(l).finally(()=>{Dx--,lv.delete(e),RN()})})});return lv.set(e,n),RN(),n}function TJ({sha:e}){const t=ee(),[s,n]=x.useState(()=>jJ(e)??null),a=x.useRef(null);if(x.useEffect(()=>{if(s)return;const d=a.current;if(!d||typeof IntersectionObserver>"u")return;let f=!0;const h=new IntersectionObserver(g=>{g.some(p=>p.isIntersecting)&&(h.disconnect(),AJ(e).then(p=>{f&&n(p)}).catch(()=>{}))},{rootMargin:"200px"});return h.observe(d),()=>{f=!1,h.disconnect()}},[e,s]),!s||s.state==="unknown"||s.totalCount===0)return i.jsx("span",{ref:a,"aria-hidden":!0,className:"inline-block size-2 shrink-0"});const l=RJ(s.state),c=t("github.ci.badgeLabel",{state:s.state,count:s.totalCount});return i.jsx("span",{"aria-label":c,className:`shrink-0 size-2 rounded-full ${l}`,title:c})}function RJ(e){switch(e){case"success":return"bg-emerald-500";case"pending":return"bg-amber-400 animate-pulse";case"failure":return"bg-red-500";case"error":return"bg-orange-500";default:return"bg-zinc-400"}}const MN=28;function MJ({commits:e,loading:t,error:s,selectedHash:n,maxLanes:a,rowRefs:l,onSelect:c,onLoadMore:d}){const f=ee(),{sendToAgent:h}=Ot(),[g,p]=x.useState(null);function b(v,_){p(null),h({prompt:AF(v,_),source:{type:"git-commit",label:v.hash.slice(0,7)},label:`${v.hash.slice(0,7)}: ${_}`})}return i.jsxs("aside",{className:"flex min-h-0 flex-col overflow-hidden border-r border-border",children:[i.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[i.jsxs("h2",{className:"text-[13px] font-semibold tracking-tight",children:[f("git.graph.commitTree"),e.length?i.jsx("span",{className:"ml-2 text-[11px] font-normal text-muted-foreground",children:f("git.graph.commitsCount",{count:e.length})}):null]}),i.jsx(Q,{disabled:t,onClick:d,size:"sm",type:"button",variant:"outline",children:f("git.graph.loadMore")})]}),i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:s?i.jsx("div",{className:"p-3",children:i.jsx(tt,{variant:"destructive",children:s})}):t&&e.length===0?i.jsx("div",{className:"p-3 text-[12px] text-muted-foreground",children:f("git.graph.loadingCommits")}):e.length===0?i.jsx("div",{className:"p-3 text-[12px] text-muted-foreground",children:f("git.graph.noCommits")}):i.jsx("ul",{className:"divide-y divide-border",children:e.map(v=>i.jsxs("li",{ref:_=>{_?l.current.set(v.hash,_):l.current.delete(v.hash)},className:"group flex flex-col",children:[i.jsxs("div",{className:`flex items-center transition-colors hover:bg-muted/60 ${n===v.hash?"bg-muted":""}`,children:[i.jsxs("button",{onClick:()=>c(v.hash),type:"button",className:"flex min-w-0 flex-1 items-center gap-2 px-2 py-0.5 text-left",style:{minHeight:MN},title:`${v.hash}
|
|
@@ -224,4 +224,4 @@ ${v.author} <${v.email}>
|
|
|
224
224
|
${v.subject}`,children:[i.jsx(NJ,{lane:v.lane,laneCount:Math.max(v.laneCount,a),edges:v.edges,throughLanes:v.throughLanes,isMerge:v.parents.length>1,height:MN}),i.jsxs("span",{className:"flex items-center gap-1 font-mono text-[10px] text-muted-foreground",children:[v.hash.slice(0,7),i.jsx(TJ,{sha:v.hash})]}),i.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[v.refs.map(_=>i.jsx("span",{className:LJ(_.kind),children:_.name},`${_.kind}-${_.name}`)),i.jsx("span",{className:"truncate text-[12px]",children:v.subject})]}),i.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:v.author}),i.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/70",title:new Date(v.timestamp*1e3).toLocaleString(),children:DJ(v.timestamp)})]}),i.jsx(ir,{className:`mr-1 shrink-0 ${g===v.hash?"opacity-100":""}`,label:f("git.graph.askCommitLabel",{sha:v.hash.slice(0,7)}),onAsk:()=>p(_=>_===v.hash?null:v.hash)})]}),g===v.hash?i.jsx("div",{className:"px-2 pb-1.5 pt-0.5",children:i.jsx(Ir,{placeholder:f("git.graph.askPlaceholder"),onSubmit:_=>b(v,_),onCancel:()=>p(null)})}):null]},v.hash))})})]})}function DJ(e){if(!e)return"";const t=Math.max(0,Math.floor(Date.now()/1e3-e));if(t<60)return`${t}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const n=Math.floor(s/60);if(n<24)return`${n}h`;const a=Math.floor(n/24);if(a<30)return`${a}d`;const l=Math.floor(a/30);return l<12?`${l}mo`:`${Math.floor(l/12)}y`}function LJ(e){const t="rounded border px-1.5 py-px text-[10px] font-medium";switch(e){case"head":return`${t} border-emerald-200 bg-emerald-100 text-emerald-800 dark:border-emerald-400/30 dark:bg-emerald-500/15 dark:text-emerald-300`;case"branch":return`${t} border-blue-200 bg-blue-100 text-blue-800 dark:border-blue-400/30 dark:bg-blue-500/15 dark:text-blue-300`;case"remote":return`${t} border-slate-200 bg-slate-100 text-slate-700 dark:border-zinc-700/80 dark:bg-zinc-800/80 dark:text-zinc-300`;case"tag":return`${t} border-amber-200 bg-amber-100 text-amber-800 dark:border-amber-400/30 dark:bg-amber-500/15 dark:text-amber-300`}}const DN=200;function OJ(){const[e,t]=x.useState([]),[s,n]=x.useState(DN),[a,l]=x.useState(0),[c,d]=x.useState(!0),[f,h]=x.useState(null),[g,p]=x.useState(null),[b,v]=x.useState([]),[_,S]=x.useState(!1),[C,N]=x.useState(null),[A,j]=x.useState(null),[E,T]=x.useState(""),[L,H]=x.useState(!1),[P,F]=x.useState(null),M=x.useCallback(D=>{p(D),v([]),j(null),T("")},[]);x.useEffect(()=>{let D=!0;return d(!0),h(null),e7(s).then(q=>{D&&(t(q),q.length>0&&!q.some(W=>W.hash===g)&&M(q[0].hash))}).catch(q=>{D&&h(q instanceof Error?q.message:String(q))}).finally(()=>{D&&d(!1)}),()=>{D=!1}},[s,a]),x.useEffect(()=>{if(!g){v([]),j(null),S(!1);return}let D=!0;return N(null),S(!0),s7(g).then(q=>{D&&(v(q),j(q[0]?.path??null))}).catch(q=>{D&&N(q instanceof Error?q.message:String(q))}).finally(()=>{D&&S(!1)}),()=>{D=!1}},[g]),x.useEffect(()=>{if(!g||!A){T(""),H(!1);return}let D=!0;return F(null),H(!0),t7(g,A).then(q=>{D&&T(q)}).catch(q=>{D&&F(q instanceof Error?q.message:String(q))}).finally(()=>{D&&H(!1)}),()=>{D=!1}},[g,A]);const z=x.useMemo(()=>e.reduce((D,q)=>Math.max(D,q.laneCount),1),[e]),G=e.find(D=>D.hash===g)??null;return{commits:e,loading:c,error:f,selectedHash:g,setSelectedHash:M,files:b,filesError:C,selectedFile:A,setSelectedFile:j,diff:E,diffLoading:L||_,diffError:P,maxLanes:z,selectedCommit:G,loadMore:()=>n(D=>D+DN),refresh:()=>l(D=>D+1)}}function PJ({branches:e=[]}){const{commits:t,loading:s,error:n,selectedHash:a,setSelectedHash:l,files:c,filesError:d,selectedFile:f,setSelectedFile:h,diff:g,diffLoading:p,diffError:b,maxLanes:v,selectedCommit:_,loadMore:S,refresh:C}=OJ(),N=ee();Dl(C);const[A,j]=x.useState(""),E=x.useMemo(()=>{const M=A.trim().toLowerCase();return M?e.filter(z=>z.name.toLowerCase().includes(M)):e},[e,A]),T=x.useMemo(()=>jN(E.filter(M=>!M.remote)),[E]),L=x.useMemo(()=>jN(E.filter(M=>M.remote)),[E]),H=A.trim().length>0,P=x.useRef(new Map);function F(M){const z=M.remote?"remote":"branch",G=t.find(W=>W.refs.some(I=>I.kind===z&&I.name===M.name));if(!G)return;l(G.hash);const D=P.current.get(G.hash),q=D?.parentElement?.parentElement;!D||!q||q.scrollTo({top:Math.max(D.offsetTop-q.clientHeight/2+D.clientHeight/2,0),behavior:"smooth"})}return i.jsxs("div",{className:"grid h-full min-h-0 overflow-hidden border-0 bg-card/85 grid-cols-[220px_minmax(0,1fr)]",children:[i.jsxs("aside",{className:"flex min-h-0 flex-col overflow-hidden border-r border-border",children:[i.jsxs("div",{className:"flex shrink-0 flex-col gap-1 border-b border-border px-3 py-1.5",children:[i.jsx("h2",{className:"text-[13px] font-semibold tracking-tight",children:N("git.graph.branches")}),i.jsx("input",{type:"search",value:A,onChange:M=>j(M.target.value),placeholder:N("git.graph.searchBranches"),className:"w-full rounded border border-border bg-background px-2 py-1 text-[11px] outline-none focus:border-foreground"})]}),i.jsxs("div",{className:"min-h-0 flex-1 overflow-auto py-1",children:[i.jsx(AN,{label:N("git.branch.sectionLocal"),tree:T,onSelect:F,defaultOpen:!0,forceOpen:H}),i.jsx(AN,{label:N("git.branch.sectionRemote"),tree:L,onSelect:F,forceOpen:H})]})]}),i.jsxs("div",{className:"grid min-h-0 min-w-0 grid-rows-[minmax(0,3fr)_minmax(0,2fr)]",children:[i.jsx(SJ,{selectedCommit:_,selectedFile:f,diff:g,diffLoading:p,diffError:b}),i.jsxs("div",{className:"grid min-h-0 min-w-0 grid-cols-[minmax(0,1fr)_280px]",children:[i.jsx(MJ,{commits:t,loading:s,error:n,selectedHash:a,maxLanes:v,rowRefs:P,onSelect:l,onLoadMore:S}),i.jsx(kJ,{files:c,filesError:d,selectedHash:a,selectedFile:f,onSelect:h})]})]})]})}function zJ({repo:e,file:t,onClose:s}){const n=ee(),[a,l]=x.useState(""),[c,d]=x.useState(null),[f,h]=x.useState(!0);x.useEffect(()=>{let p=!0;return h(!0),d(null),DE(t,e).then(b=>{p&&l(b)}).catch(b=>{p&&d(b instanceof Error?b.message:String(b))}).finally(()=>{p&&h(!1)}),()=>{p=!1}},[e,t]),x.useEffect(()=>{function p(b){b.key==="Escape"&&s()}return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[s]);const g=M0(a);return Ii.createPortal(i.jsxs("div",{className:"fixed inset-0 z-[1000] flex justify-end",children:[i.jsx("button",{"aria-label":n("git.diff.closeAria"),className:"absolute inset-0 bg-black/35",onClick:s,type:"button"}),i.jsxs("div",{className:"relative z-10 flex h-full w-[min(900px,calc(100vw-3rem))] flex-col bg-card shadow-xl",children:[i.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border px-3 py-2",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:t}),i.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-muted-foreground",children:[i.jsx("span",{className:"font-mono",children:e}),g.additions||g.deletions?i.jsxs("span",{className:"flex items-center gap-1 font-mono",children:[i.jsxs("span",{className:"text-emerald-700",children:["+",g.additions]}),i.jsxs("span",{className:"text-red-700",children:["-",g.deletions]})]}):null]})]}),i.jsx(Q,{"aria-label":n("git.diff.closeAria"),onClick:s,size:"icon",variant:"ghost",children:i.jsx(Vt,{})})]}),i.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:c?i.jsx("div",{className:"p-4",children:i.jsx(tt,{variant:"destructive",children:c})}):f?i.jsx("div",{className:"p-4 text-xs text-muted-foreground",children:n("git.diff.loading")}):i.jsx(Ou,{diff:a||n("git.noUnstagedDiff")})})]})]}),document.body)}function fT(e){return e.split(/[\\/]/).filter(Boolean).pop()??"project"}function BJ({initialPath:e,onSelect:t,selectedPath:s}){const n=ee(),[a,l]=x.useState(e),[c,d]=x.useState(e),[f,h]=x.useState(null),[g,p]=x.useState(null),[b,v]=x.useState(!1),_=IJ(f);return x.useEffect(()=>{l(e)},[e]),x.useEffect(()=>{f&&d(f.path)},[f]),x.useEffect(()=>{let S=!0;return v(!0),p(null),$E(a).then(C=>{S&&(h(C),t(C.path))}).catch(C=>{S&&p(C instanceof Error?C.message:String(C))}).finally(()=>{S&&v(!1)}),()=>{S=!1}},[a,t]),i.jsxs("div",{className:"rounded-md border border-border bg-background",children:[i.jsxs("div",{className:"flex items-center gap-2 border-b border-border p-2",children:[_?i.jsx(Q,{"aria-label":n("git.folder.parentAria"),onClick:()=>f&&l(f.parent),size:"icon",type:"button",variant:"ghost",children:i.jsx(hn,{className:"rotate-90"})}):null,i.jsx(pt,{"aria-label":n("git.folder.pathAria"),className:"h-7 min-w-0 flex-1 font-mono text-xs",onChange:S=>d(S.target.value),onKeyDown:S=>{if(S.key==="Enter"){S.preventDefault();const C=c.trim();C&&l(C)}},spellCheck:!1,value:c}),b?i.jsx(Lt,{className:"size-4 shrink-0 animate-spin text-muted-foreground"}):null]}),i.jsxs("div",{className:"max-h-56 overflow-auto p-1",children:[g?i.jsx(tt,{variant:"destructive",className:"m-1",children:g}):null,!g&&f?.entries.length===0?i.jsx(tt,{variant:"muted",className:"m-1 text-center",children:n("git.folder.empty")}):null,f?.entries.map(S=>i.jsxs(Q,{className:oe("h-8 w-full justify-start rounded-sm px-2 text-left",s===S.path&&"bg-muted"),onClick:()=>l(S.path),title:S.path,type:"button",variant:"ghost",children:[i.jsx(ko,{className:"text-accent"}),i.jsx("span",{className:"truncate",children:S.name})]},S.path))]})]})}function IJ(e){return!!(e&&e.parent!==e.path)}function mT({confirmLabel:e,errorMessage:t,initialPath:s,onCancel:n,onSelect:a,onUse:l,selectedPath:c,title:d}){const f=ee();return Ii.createPortal(i.jsx("div",{className:"fixed inset-0 z-[1000] grid place-items-center bg-black/35 px-4",children:i.jsxs("div",{className:"w-full max-w-2xl rounded-xl border border-border bg-card p-4 shadow-xl",children:[i.jsxs("div",{className:"mb-3 flex items-center gap-3",children:[i.jsx("div",{className:"flex size-8 items-center justify-center rounded-lg border border-border bg-background",children:i.jsx(ko,{className:"size-4"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("div",{className:"text-sm font-semibold",children:d??f("git.repo.chooseFolder")}),i.jsx("div",{className:"truncate font-mono text-xs text-muted-foreground",children:c})]}),i.jsx(Q,{"aria-label":f("git.repo.closeFolderPicker"),onClick:n,size:"icon",variant:"ghost",children:i.jsx(Vt,{})})]}),i.jsx(BJ,{initialPath:s,onSelect:a,selectedPath:c}),t?i.jsx("div",{className:"mt-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:t}):null,i.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[i.jsx(Q,{onClick:n,type:"button",variant:"outline",children:f("common.cancel")}),i.jsx(Q,{onClick:()=>{l()},type:"button",children:e??f("git.repo.useThisFolder")})]})]})}),document.body)}const Kc=5,HJ=240,Lx=8,$J=176+Lx;function FJ({currentRepoPath:e}){const t=ee(),[s,n]=x.useState(null),[a,l]=x.useState([]),[c,d]=x.useState(null),[f,h]=x.useState(!0),[g,p]=x.useState(null),b=x.useRef(null),v=x.useRef(null),[_,S]=x.useState(0);x.useEffect(()=>{const q=v.current;if(!q)return;const W=new ResizeObserver(I=>{S(I[0].contentRect.width)});return W.observe(q),()=>W.disconnect()},[s]);const C=x.useCallback(()=>{let q=!0;return h(!0),d(null),Og().then(W=>{q&&(n(W.repos),l(W.board))}).catch(W=>{q&&d(W instanceof Error?W.message:String(W))}).finally(()=>{q&&h(!1)}),()=>{q=!1}},[]);x.useEffect(C,[C]);const N=x.useCallback(()=>{Og().then(q=>{n(q.repos),l(q.board)}).catch(q=>{d(q instanceof Error?q.message:String(q))})},[]),A=x.useCallback(q=>{l(q),uS(q).catch(W=>{d(W instanceof Error?W.message:String(W))})},[]),j=x.useCallback(async q=>{const W=q.trim();if(!W.startsWith("/"))return t("git.board.absolutePathError");try{const I=fT(W);await Pi("/api/git/repositories",{name:I,path:W});const Y=await Og();n(Y.repos);const $=(Y.board.includes(I)?Y.board:[...Y.board,I]).slice(0,Kc);return l($),await uS($),null}catch(I){return I instanceof Error?I.message:String(I)}},[t]),E=new Map((s??[]).map(q=>[q.name,q])),T=a.map(q=>E.get(q)).filter(q=>!!q).slice(0,Kc),L=(s??[]).filter(q=>!a.includes(q.name)),H=T.length<Kc,P=Math.max(0,_-(H?$J:0)),F=_===0?Kc:Math.max(1,Math.floor((P+Lx)/(HJ+Lx))),M=Math.min(T.length,F),z=T.slice(0,M),G=T.length-M;function D(q){const W=b.current;if(b.current=null,W===null||W===q)return;const I=[...a],[Y]=I.splice(W,1);I.splice(q,0,Y),A(I)}return i.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[i.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border bg-card/95 px-3 py-1.5",children:[i.jsxs("span",{className:"flex items-center gap-1.5 text-[12px] font-semibold tracking-tight",children:[i.jsx(Fx,{className:"size-3.5"}),t("git.board.repositories"),s?i.jsxs(Ke,{variant:"secondary",className:"ml-1",children:[T.length,s.length>T.length?` / ${s.length}`:""]}):null,G>0?i.jsx("span",{className:"ml-1 text-[10px] font-normal text-muted-foreground",children:t("git.board.hidden",{count:G})}):null]}),i.jsxs(Q,{"aria-label":t("git.board.refreshAria"),disabled:f,onClick:C,size:"sm",type:"button",variant:"outline",children:[i.jsx(Pr,{className:f?"animate-spin":void 0}),t("common.refresh")]})]}),i.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:c?i.jsx(tt,{variant:"destructive",className:"m-3",children:c}):s&&s.length===0?i.jsx(tt,{variant:"muted",className:"m-3 text-center",children:t("git.board.emptyRegistered")}):i.jsxs("div",{className:"flex h-full min-h-0 gap-2 p-2",ref:v,children:[z.map((q,W)=>i.jsx(UJ,{repo:q,isCurrent:!!e&&q.path===e,selectedFile:g?.repo===q.name?g.file:"",onSelectFile:I=>p({repo:q.name,file:I}),onRemove:()=>A(a.filter(I=>I!==q.name)),onMutated:N,onDragStart:()=>{b.current=W},onDropColumn:()=>D(W)},q.name)),H?i.jsx(qJ,{unpinned:L,onAdd:q=>A([...a,q].slice(0,Kc)),onRegister:j}):null]})}),g?i.jsx(zJ,{repo:g.repo,file:g.file,onClose:()=>p(null)}):null]})}function UJ({repo:e,isCurrent:t,selectedFile:s,onSelectFile:n,onRemove:a,onMutated:l,onDragStart:c,onDropColumn:d}){const f=ee(),[h,g]=x.useState(!1),[p,b]=x.useState(!1),[v,_]=x.useState(!1),S=x.useCallback(async(j,E)=>{if(E.length){b(!0);try{await j(E,e.name),l()}finally{b(!1)}}},[e.name,l]),C={busy:p,onStage:j=>{S(Qx,j)},onUnstage:j=>{S(LE,j)}},N=e.files.filter(j=>j.index.trim()&&j.index!=="?").length,A=v?hn:_n;return i.jsxs("div",{className:oe("flex min-w-0 flex-1 flex-col overflow-hidden rounded-md border border-border bg-card",t&&"border-primary/60 ring-1 ring-primary/30",h&&"ring-2 ring-foreground/40"),onDragOver:j=>{j.preventDefault(),g(!0)},onDragLeave:()=>g(!1),onDrop:()=>{g(!1),d()},children:[i.jsxs("div",{className:"flex shrink-0 cursor-grab items-center justify-between gap-1 border-b border-border bg-muted/40 px-1.5 py-1.5 active:cursor-grabbing",draggable:!0,onDragStart:c,children:[i.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[i.jsx(S6,{className:"size-3.5 shrink-0 text-muted-foreground/60"}),i.jsx("span",{className:"truncate text-[12px] font-semibold",title:e.path,children:e.name}),t?i.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 rounded bg-primary px-1 py-px text-[9px] font-semibold uppercase tracking-wide text-primary-foreground",title:f("git.board.currentTitle"),children:[i.jsx(Ys,{className:"size-2.5"}),f("git.board.current")]}):null]}),i.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[i.jsxs("span",{className:"flex items-center gap-1 font-mono text-[10px] text-muted-foreground",children:[e.ahead?i.jsxs("span",{className:"flex items-center",title:f("git.board.aheadTitle",{count:e.ahead}),children:[i.jsx(If,{className:"size-3"}),e.ahead]}):null,e.behind?i.jsxs("span",{className:"flex items-center",title:f("git.board.behindTitle",{count:e.behind}),children:[i.jsx(Bf,{className:"size-3"}),e.behind]}):null]}),i.jsx("button",{"aria-label":f("git.board.removeAria",{name:e.name}),className:"rounded p-0.5 text-muted-foreground transition-colors hover:bg-background hover:text-foreground",onClick:a,title:f("git.board.removeTitle"),type:"button",children:i.jsx(Vt,{className:"size-3.5"})})]})]}),i.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:i.jsx(TA,{branch:e.branch||void 0,error:e.error,files:e.files,onSelectFile:n,root:e.path,selectedFile:s,staging:C})}),i.jsxs("div",{className:"shrink-0 border-t border-border",children:[i.jsxs("button",{"aria-expanded":v,className:"flex w-full items-center gap-1.5 bg-muted/40 px-2 py-1 text-left text-[11px] font-semibold uppercase tracking-tight text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:()=>_(j=>!j),type:"button",children:[i.jsx(A,{className:"size-3.5 shrink-0"}),i.jsx("span",{className:"flex-1",children:f("git.commit.title")}),N?i.jsx(Ke,{size:"small",variant:"secondary",children:f("git.commit.stagedCount",{count:N})}):null]}),v?i.jsx(RA,{branch:e.branch||void 0,files:e.files,onDone:l,repo:e.name}):null]})]})}function qJ({unpinned:e,onAdd:t,onRegister:s}){const n=ee(),[a,l]=x.useState(!1),[c,d]=x.useState(null),[f,h]=x.useState(""),[g,p]=x.useState(null),[b,v]=x.useState(!1),[_,S]=x.useState(!1),[C,N]=x.useState(""),A=x.useRef(null),j=x.useRef(null);function E(){if(a){l(!1);return}d(A.current?.getBoundingClientRect()??null),p(null),l(!0)}x.useEffect(()=>{if(!a)return;function H(P){const F=P.target;F instanceof Node&&(j.current?.contains(F)||A.current?.contains(F)||l(!1))}return document.addEventListener("mousedown",H),()=>document.removeEventListener("mousedown",H)},[a]);async function T(H){v(!0),p(null);const P=await s(H);return v(!1),P?(p(P),!1):(h(""),l(!1),!0)}async function L(H){H.preventDefault(),await T(f)}return i.jsxs("div",{className:"w-44 shrink-0",children:[i.jsxs("button",{ref:A,className:"flex h-full w-full flex-col items-center justify-center gap-1.5 rounded-md border border-dashed border-border text-muted-foreground transition-colors hover:border-foreground/40 hover:text-foreground",onClick:E,type:"button",children:[i.jsx(fs,{className:"size-5"}),i.jsx("span",{className:"text-[12px] font-medium",children:n("git.board.addRepo")})]}),a&&c?Ii.createPortal(i.jsxs("div",{ref:j,className:"fixed z-[1000] w-72 overflow-hidden rounded-lg border border-border bg-card shadow-xl",style:{left:Math.max(8,Math.min(c.left,window.innerWidth-296)),top:Math.min(c.top,window.innerHeight-320)},children:[e.length?i.jsxs("div",{className:"border-b border-border",children:[i.jsx("div",{className:"px-3 pb-1 pt-2 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:n("git.board.pinRegistered")}),i.jsx("div",{className:"max-h-52 overflow-auto pb-1",children:e.map(H=>i.jsxs("button",{className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm hover:bg-muted",onClick:()=>{t(H.name),l(!1)},type:"button",children:[i.jsx(Fx,{className:"size-3.5 shrink-0 text-muted-foreground"}),i.jsx("span",{className:"min-w-0 flex-1 truncate",title:H.path,children:H.name}),H.files.length?i.jsx(Ke,{variant:"outline",className:"h-5 px-1.5 text-[10px]",children:H.files.length}):null]},H.name))})]}):null,i.jsxs("div",{className:"p-2.5",children:[i.jsx("div",{className:"pb-1.5 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:n("git.board.addNew")}),i.jsxs("form",{className:"flex gap-1.5",onSubmit:L,children:[i.jsx(pt,{"aria-label":n("git.board.absPathAria"),className:"h-7 flex-1 px-2 font-mono text-[11px]",onChange:H=>{h(H.target.value),p(null)},placeholder:"/absolute/path/to/repo",value:f}),i.jsx(Q,{className:"h-7 px-2 text-[11px]",disabled:b||!f.trim(),size:"sm",type:"submit",children:n("common.add")})]}),i.jsxs(Q,{className:"mt-1.5 h-7 w-full gap-1.5 text-[11px]",disabled:b,onClick:()=>{N(f.trim()||""),S(!0)},size:"sm",type:"button",variant:"outline",children:[i.jsx(Ux,{className:"size-3"}),n("git.board.browseFolders")]}),g?i.jsx("div",{className:"mt-1.5 text-[10px] text-destructive",children:g}):null]})]}),document.body):null,_?i.jsx(mT,{confirmLabel:n("git.board.addRepo"),errorMessage:g,initialPath:C||"/",selectedPath:C,title:n("git.board.addRepoTitle"),onCancel:()=>S(!1),onSelect:N,onUse:async()=>{await T(C)&&S(!1)}}):null]})}const Ox=300,GJ=600,VJ=new Set(["md","mdx","markdown","txt","rst","adoc","json","jsonc","json5","yaml","yml","toml","xml","ini","cfg","conf","env","properties","csv","tsv","lock","svg","map","snap","png","jpg","jpeg","gif","ico","webp"]);function WJ(e){const t=e.toLowerCase();if(t.endsWith(".d.ts")||t.endsWith(".min.js")||t.endsWith(".min.css"))return!1;const s=t.lastIndexOf(".");return s<0?!0:!VJ.has(t.slice(s+1))}function KJ(e){return e>=GJ?"danger":e>=Ox?"warn":"ok"}const YJ={ok:"bg-emerald-500/60",warn:"bg-amber-500/70",danger:"bg-destructive/70"},XJ={ok:"text-muted-foreground",warn:"text-amber-600 dark:text-amber-400",danger:"text-destructive"};function ZJ({onOpenFile:e,root:t}){const s=ee(),[n,a]=x.useState([]),[l,c]=x.useState(!0),[d,f]=x.useState(null),[h,g]=x.useState(!0);function p(){c(!0),f(null),i7().then(a).catch(C=>f(C instanceof Error?C.message:String(C))).finally(()=>c(!1))}x.useEffect(()=>{p()},[]);const b=x.useMemo(()=>h?n.filter(C=>WJ(C.path)):n,[n,h]),v=n.length-b.length,_=b[0]?.lines??1,S=b.filter(C=>C.lines>=Ox).length;return i.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[i.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-2",children:[i.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[i.jsx(aE,{className:"size-4"}),i.jsx("span",{className:"font-semibold text-foreground",children:s("git.largest.title")}),!l&&!d?i.jsxs("span",{children:[s("git.largest.summary",{visible:b.length,over:S,warn:Ox}),h&&v>0?s("git.largest.hiddenSuffix",{hidden:v}):""]}):null]}),i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsxs(Q,{size:"sm",variant:h?"default":"outline",className:"h-7",onClick:()=>g(C=>!C),title:s("git.largest.codeOnlyTitle"),type:"button",children:[i.jsx(sE,{}),s("git.largest.codeOnly")]}),i.jsxs(Q,{size:"sm",variant:"outline",className:"h-7",onClick:p,disabled:l,type:"button",children:[l?i.jsx(Lt,{className:"animate-spin"}):i.jsx(Pr,{}),s("common.refresh")]})]})]}),d?i.jsx(tt,{variant:"destructive",className:"m-3",children:d}):l&&n.length===0?i.jsxs("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:[i.jsx(Lt,{className:"mr-2 size-4 animate-spin"}),s("git.largest.scanning")]}):b.length===0?i.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:n.length===0?s("git.largest.noTextFiles"):s("git.largest.noCodeFiles")}):i.jsx("ul",{className:"min-h-0 flex-1 divide-y divide-border/60 overflow-auto",children:b.map((C,N)=>{const A=KJ(C.lines);return i.jsxs("li",{className:"group flex items-center gap-3 px-3 transition-colors hover:bg-muted/50",children:[i.jsx("span",{className:"w-6 shrink-0 text-right font-mono text-[10px] text-muted-foreground",children:N+1}),i.jsx("button",{type:"button",onClick:()=>e(C.path),className:"min-w-0 flex-1 py-1.5 text-left",children:i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsxs("div",{className:"flex items-center justify-between gap-3",children:[i.jsx("span",{className:"truncate font-mono text-[11px]",children:C.path}),i.jsxs("span",{className:oe("shrink-0 font-mono text-[11px] tabular-nums",XJ[A]),children:[C.truncated?"≥":"",s("git.largest.linesCount",{count:C.lines.toLocaleString()})]})]}),i.jsx("div",{className:"mt-1 h-1 w-full overflow-hidden rounded-full bg-muted",children:i.jsx("div",{className:oe("h-full rounded-full",YJ[A]),style:{width:`${Math.max(2,C.lines/_*100)}%`}})})]})}),i.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-0.5",children:[i.jsx(QJ,{file:C,root:t}),i.jsx(JJ,{file:C,root:t})]})]},C.path)})})]})}function QJ({file:e,root:t}){const s=ee(),{sendToAgent:n}=Ot(),a=Pu(t,e.path),l=e.path.split("/").pop()??e.path;function c(){n({prompt:jF({absolutePath:a,lines:e.lines,relativePath:e.path}),source:{label:l,type:"large-file"},label:s("git.largest.splitLabel",{path:e.path,count:e.lines.toLocaleString()}),mode:"send"})}function d(){n({prompt:a,source:{label:l,type:"large-file"},mode:"draft"})}return i.jsx(pT,{label:s("git.largest.aiActions",{path:e.path}),trigger:i.jsx(Xt,{className:"size-3.5"}),children:f=>i.jsxs(i.Fragment,{children:[i.jsx(bu,{icon:i.jsx(Xt,{className:"size-3.5"}),onSelect:()=>{f(),c()},children:s("git.largest.askSplit")}),i.jsx(bu,{icon:i.jsx(iE,{className:"size-3.5"}),onSelect:()=>{f(),d()},children:s("git.largest.sendPath")})]})})}function JJ({file:e,root:t}){const s=ee(),{error:n,success:a}=ms(),l=Pu(t,e.path),c=e.path.split("/").pop()??e.path;async function d(f,h){try{await navigator.clipboard.writeText(f),a(s("git.largest.copiedWhat",{what:h}))}catch(g){n(g instanceof Error?g.message:s("git.largest.couldNotCopy",{what:h}))}}return i.jsx(pT,{label:s("git.largest.copyPathFor",{path:e.path}),trigger:i.jsxs(i.Fragment,{children:[i.jsx(nE,{className:"size-3.5"}),i.jsx("span",{className:"sr-only",children:s("common.moreActions")})]}),children:f=>i.jsxs(i.Fragment,{children:[i.jsx(bu,{icon:i.jsx($x,{className:"size-3.5"}),onSelect:()=>{f(),d(c,s("git.largest.whatFileName"))},children:s("git.largest.copyFileName")}),i.jsx(bu,{icon:i.jsx(ef,{className:"size-3.5"}),onSelect:()=>{f(),d(e.path,s("git.largest.whatRelPath"))},children:s("git.largest.copyRelPath")}),i.jsx(bu,{icon:i.jsx(ef,{className:"size-3.5"}),onSelect:()=>{f(),d(l,s("git.largest.whatAbsPath"))},children:s("git.largest.copyAbsPath")})]})})}function pT({children:e,label:t,trigger:s}){const[n,a]=x.useState(!1),[l,c]=x.useState({right:0,top:0}),d=x.useRef(null),f=x.useRef(null);function h(){a(!1)}function g(){const p=d.current?.getBoundingClientRect();p&&c({top:p.bottom+6,right:window.innerWidth-p.right}),a(b=>!b)}return x.useEffect(()=>{if(!n)return;function p(v){const _=v.target;d.current?.contains(_)||f.current?.contains(_)||h()}function b(v){v.key==="Escape"&&h()}return document.addEventListener("mousedown",p),document.addEventListener("keydown",b),window.addEventListener("scroll",h,!0),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",b),window.removeEventListener("scroll",h,!0)}},[n]),i.jsxs(i.Fragment,{children:[i.jsx("button",{"aria-label":t,className:oe("flex h-7 min-w-7 shrink-0 items-center justify-center gap-1 rounded-md px-1.5 text-muted-foreground opacity-0 transition-all duration-150 hover:bg-muted hover:text-foreground group-hover:opacity-100",n&&"bg-muted text-foreground opacity-100"),onClick:g,ref:d,title:t,type:"button",children:s}),n?Ii.createPortal(i.jsx("div",{className:"fixed z-50 w-56 overflow-hidden rounded-md border border-border bg-card p-1 shadow-md",ref:f,style:{top:l.top,right:l.right},children:e(h)}),document.body):null]})}function bu({children:e,icon:t,onSelect:s}){return i.jsxs("button",{className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs text-foreground transition-colors hover:bg-muted",onClick:s,type:"button",children:[i.jsx("span",{className:"text-muted-foreground",children:t}),i.jsx("span",{className:"min-w-0 flex-1 truncate",children:e})]})}function eee({data:e,onRefresh:t}){const s=ee(),{insertPath:n}=Ot(),[a,l]=x.useState(!1),[c,d]=x.useState("changes"),[f,h]=x.useState("changes"),[g,p]=x.useState(e.git.status?.files[0]?.path??""),[b,v]=x.useState(""),[_,S]=x.useState([]),[C,N]=x.useState(null),[A,j]=x.useState(""),[E,T]=x.useState(null),[L,H]=x.useState(0),[P,F]=x.useState(null),[M,z]=x.useState(()=>new Set),G=e.git.status?.files??[],D=x.useMemo(()=>{const Re=new Set(G.map(Qe=>Qe.path)),pe=[...M].filter(Qe=>!Re.has(Qe)).sort().map(Qe=>({path:Qe,index:" ",workingTree:"M"}));return[...G,...pe]},[G,M]),q=x.useMemo(()=>D.map(Re=>Re.path),[D]),W=x.useMemo(()=>M0(A),[A]),I=x.useCallback(async(Re,pe)=>{if(pe.length){l(!0);try{await Re(pe),t?.()}finally{l(!1)}}},[t]),Y=t?{busy:a,onStage:Re=>{I(Qx,Re)},onUnstage:Re=>{I(LE,Re)}}:void 0;x.useEffect(()=>{const Re=D[0]?.path??"";p(pe=>pe&&D.some(Qe=>Qe.path===pe)?pe:Re)},[D]),x.useEffect(()=>{if(c!=="all"||_.length>0)return;let Re=!0;return N(null),n7().then(pe=>{Re&&S(pe)}).catch(pe=>{Re&&N(pe instanceof Error?pe.message:String(pe))}),()=>{Re=!1}},[c,_.length]),x.useEffect(()=>{if(!g){j("");return}let Re=!0;return T(null),DE(g).then(pe=>{Re&&(j(pe),H(0),F(null))}).catch(pe=>{Re&&T(pe instanceof Error?pe.message:String(pe))}),()=>{Re=!1}},[g]);function $(Re){H(0),F(null),p(Re)}function me(){const Re=wJ({activeHunkIndex:L,filePaths:q,hunkCount:W.hunks,pendingNextFilePath:P,selectedFile:g});Re.kind==="hunk"?(F(null),H(Re.activeHunkIndex)):Re.kind==="confirm-next-file"?F(Re.filePath):Re.kind==="file"?$(Re.filePath):F(null)}function J(){if(F(null),L>0){H(Qe=>Qe-1);return}const Re=D.findIndex(Qe=>Qe.path===g),pe=D[Re-1];pe&&$(pe.path)}const V=D.findIndex(Re=>Re.path===g),K=!!(W.hunks&&L<W.hunks-1||D[V+1]),xe=!!(L>0||D[V-1]),ie=P?s("git.navHintEndOfFile",{path:P}):null,Z=Re=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${Re?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`,ge=Re=>`flex-1 px-2 py-0.5 text-[11px] font-medium transition-colors ${Re?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`,ne=x.useMemo(()=>{const Re=new Set(D.map(pe=>pe.path));for(const pe of M)Re.add(pe);return Re},[D,M]);if(!e.git.selectedRepository)return i.jsx(tee,{});function we(){b&&(d("changes"),h("changes"),$(b))}function Ne(Re){z(pe=>new Set(pe).add(Re)),v(Re),d("changes"),h("changes"),$(Re)}function Ue(Re){v(Re),d("all")}function Pe(Re){Re&&n(Pu(e.git.cwd,Re))}return i.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:[i.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border bg-card/95 px-3 py-1",children:[i.jsx("button",{type:"button",className:Z(c==="changes"),onClick:()=>d("changes"),children:s("git.tab.changes")}),i.jsx("button",{type:"button","aria-label":s("git.boardAria"),className:Z(c==="board"),onClick:()=>d("board"),children:s("git.tab.board")}),i.jsx("button",{type:"button","aria-label":s("git.allFilesAria"),className:Z(c==="all"),onClick:()=>d("all"),children:s("git.tab.all")}),i.jsx("button",{type:"button",className:Z(c==="graph"),onClick:()=>d("graph"),children:s("git.tab.tree")}),i.jsx("button",{type:"button",className:Z(c==="largest"),onClick:()=>d("largest"),children:s("git.tab.largest")}),i.jsx("button",{type:"button",className:Z(c==="snapshots"),onClick:()=>d("snapshots"),children:s("git.tab.snapshots")})]}),i.jsx("div",{className:"min-h-0 flex-1",children:c==="board"?i.jsx(FJ,{currentRepoPath:e.git.cwd}):c==="graph"?i.jsx(PJ,{branches:e.git.branches??[]}):c==="largest"?i.jsx(ZJ,{onOpenFile:Ue,root:e.git.cwd}):c==="snapshots"?i.jsx(iF,{}):c==="all"?i.jsxs("div",{className:"grid h-full min-h-0 overflow-hidden border-0 bg-card/85 xl:grid-cols-[320px_minmax(0,1fr)]",children:[i.jsx("aside",{className:"flex min-h-0 flex-col overflow-hidden",children:C?i.jsx(tt,{variant:"destructive",className:"m-3",children:C}):i.jsx(OC,{branch:e.git.status?.branch||void 0,onSelectFile:v,paths:_,root:e.git.cwd,selectedFile:b,status:D})}),i.jsx(_J,{isModified:ne.has(b),onFileSaved:Ne,onSendToAi:()=>Pe(b),onViewDiff:we,path:b})]}):i.jsxs("div",{className:"grid h-full min-h-0 overflow-hidden border-0 bg-card/85 xl:grid-cols-[320px_minmax(0,1fr)]",children:[i.jsxs("aside",{className:"flex min-h-0 flex-col overflow-hidden",children:[i.jsxs("div",{className:"flex shrink-0 gap-0.5 border-b border-border bg-card/95 p-1",children:[i.jsx("button",{"aria-label":s("git.modeListAria"),className:ge(f==="changes"),onClick:()=>h("changes"),type:"button",children:s("git.tab.changes")}),i.jsx("button",{"aria-label":s("git.modeTreeAria"),className:ge(f==="tree"),onClick:()=>h("tree"),type:"button",children:s("git.tab.tree")})]}),f==="changes"?i.jsx(TA,{branch:e.git.status?.branch||void 0,error:e.git.error,files:D,selectedFile:g,onSelectFile:$,root:e.git.cwd,staging:Y}):i.jsx(OC,{branch:e.git.status?.branch||void 0,defaultExpandAll:!0,emptyMessage:e.git.error??s("git.noChangedFiles"),onSelectFile:$,paths:q,root:e.git.cwd,selectedFile:g,status:D,title:s("git.tab.changes")}),t&&e.git.status?i.jsx(RA,{branch:e.git.status.branch||void 0,files:D,onDone:t}):null]}),i.jsxs("section",{className:"flex min-h-0 min-w-0 flex-col border-l border-border bg-card",children:[i.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border px-3 py-1.5",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:g||s("git.diff")}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[10px] text-muted-foreground",children:[i.jsx("span",{children:s("git.longRowsWrap")}),W.additions||W.deletions?i.jsxs("span",{className:"flex items-center gap-1 font-mono",children:[i.jsxs("span",{className:"text-emerald-700",children:["+",W.additions]}),i.jsxs("span",{className:"text-red-700",children:["-",W.deletions]})]}):null]})]}),i.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[ie?i.jsx("span",{className:"max-w-72 truncate rounded border border-amber-200 bg-amber-50 px-2 py-1 text-[11px] text-amber-900",children:ie}):null,i.jsxs(Q,{disabled:!g||!xe,onClick:J,size:"sm",type:"button",variant:"outline",children:[i.jsx(If,{}),s("git.previous")]}),i.jsxs(Q,{disabled:!g||!K,onClick:me,size:"sm",type:"button",variant:"outline",children:[i.jsx(Bf,{}),s("git.next")]}),i.jsx(Q,{"aria-label":s("git.sendToAiAria"),className:"size-8",disabled:!g,onClick:()=>Pe(g),size:"icon",title:s("git.sendToAiTitle"),type:"button",variant:"outline",children:i.jsx(Xt,{className:"size-4"})})]})]}),i.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:E?i.jsx("div",{className:"p-4",children:i.jsx(tt,{variant:"destructive",children:E})}):g?i.jsx(Ou,{activeHunkIndex:L,diff:A||s("git.noUnstagedDiff")}):i.jsx("div",{className:"p-4",children:i.jsx(tt,{variant:"muted",className:"border-dashed p-12 text-center",children:s("git.selectFilePrompt")})})})]})]})})]})}function tee(){const e=ee();return i.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center",children:i.jsxs("div",{className:"max-w-sm",children:[i.jsx(Fx,{className:"mx-auto size-8 text-muted-foreground/50"}),i.jsx("p",{className:"mt-3 text-sm font-medium",children:e("git.noRepoTitle")}),i.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:e("git.noRepoBody")})]})})}function LN(e,t,s){const n=e.trim(),a=n.toLowerCase(),l=[],c=/\breview|check|inspect|audit\b/.test(a),d=/\btest|verify|ci\b/.test(a),f=/\bcommit\b/.test(a)||/\bship|push|pr|pull request\b/.test(a),h=/\bpush|ship|pr|pull request\b/.test(a),g=/\bpr\b|pull request/.test(a),p=nee(a,s);return g&&l.push({kind:"action",id:"assert-pr-branch",title:"Check PR branch",op:"assert-pr-branch"}),c&&(l.push(Dh("gate-review","Approve review","Review the current changes?")),l.push(Yc("review","Review changes","Review the current git changes. Summarize risks, likely bugs, and anything that should change before committing.",Lh(p,["skills","mcpServers"])))),d&&l.push(Yc("verify","Run verification","Run the relevant tests or checks for this repository. If something fails, stop and explain the failure.",Lh(p,["skills","mcpServers","plugins"]))),f&&(l.push(Yc("commit-message","Generate commit message","Stage the appropriate changed files, inspect the staged diff briefly, and draft one conventional commit message. Do not commit.",Lh(p,["skills"]))),l.push(Dh("gate-commit","Approve commit","Commit with this generated message?")),l.push({kind:"action",id:"commit",title:"Commit with approved message",op:"commit"})),h&&(l.push(Dh("gate-push","Approve push",g?"Push and continue toward a PR?":"Push this branch?")),l.push({kind:"action",id:"push",title:"Push branch",op:"push"})),g&&(l.push(Yc("open-pr","Open PR","Open a pull request for the current branch. Use the latest commit subject as the title and summarize the commit list in the body.",Lh(p,["mcpServers","plugins"]))),l.push({kind:"action",id:"checkout-default-and-pull",title:"Return to default branch",op:"checkout-default-and-pull"})),l.length||(l.push(Dh("gate-start","Approve start","Run this workflow?")),l.push(Yc("ai-step","AI step",n||"Complete this workflow step.",p))),{id:ree(gT(ON(a))||"custom-workflow",t),name:ON(a),description:n||"Custom AI-authored workflow.",builtin:!1,steps:iee(l)}}function see(e){return["Create a NoMoreIDE workflow from this user intent:","",e.trim()||"(no intent provided)","","Return a workflow JSON object only. Use this shape:","{",' "id": "short-kebab-id",',' "name": "Human name",',' "description": "One sentence",',' "steps": [',' { kind: "gate", id: "gate-id", title: "Approve thing", message: "Question for the user?" },',' { kind: "agent", id: "ai-id", title: "AI task", prompt: "Clear instruction", capabilities: { skills: [], mcpServers: [], plugins: [], hooks: [] }, verify: "committed" },',' { kind: "action", id: "push", title: "Push", op: "push" },',' { kind: "action", id: "checkout-default-and-pull", title: "Return to default branch", op: "checkout-default-and-pull" }'," ]","}","","Use gates before mutating git or GitHub state. Prefer intent-level AI steps over direct MCP tool calls."].join(`
|
|
225
225
|
`)}function ON(e){const t=/\breview|check|inspect|audit\b/.test(e),s=/\bcommit\b|\bship|push|pr|pull request\b/.test(e),n=/\bpr\b|pull request/.test(e),a=/\btest|verify|ci\b/.test(e);return t&&s&&n?"Review, Commit & PR":a&&s&&n?"Verify, Commit & PR":t&&s?"Review & Commit":s&&n?"Commit & PR":s?"Commit workflow":t?"Review workflow":"Custom workflow"}function Dh(e,t,s){return{kind:"gate",id:e,title:t,message:s}}function Yc(e,t,s,n,a){return{kind:"agent",id:e,title:t,prompt:s,capabilities:o1(n),verify:a}}function nee(e,t){return o1({skills:t.skills.filter(s=>e.includes(s.toLowerCase())),mcpServers:t.mcpServers.filter(s=>e.includes(s.toLowerCase())),plugins:t.plugins.filter(s=>e.includes(s.toLowerCase())),hooks:t.hooks.filter(s=>e.includes(s.toLowerCase()))})??{}}function Lh(e,t){const s={};for(const n of t){const a=e[n];a?.length&&(s[n]=a)}return o1(s)}function o1(e){if(!e)return;const t={};for(const s of["skills","mcpServers","plugins","hooks"]){const n=Array.from(new Set((e[s]??[]).filter(Boolean)));n.length&&(t[s]=n)}return Object.keys(t).length?t:void 0}function iee(e){const t=new Map;return e.map(s=>{const n=gT(s.id)||s.kind,a=t.get(n)??0;return t.set(n,a+1),a===0?{...s,id:n}:{...s,id:`${n}-${a+1}`}})}function ree(e,t){const s=new Set(t.map(l=>l.id));let n=e||"workflow",a=2;for(;s.has(n);)n=`${e}-${a}`,a++;return n}function gT(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}const Of={"error-incident":"workflows.triggers.eventErrorIncident","service-crash":"workflows.triggers.eventServiceCrash","ci-failure":"workflows.triggers.eventCiFailure"};function aee({workflows:e}){const t=ee(),{triggers:s,pending:n,error:a,saveTrigger:l,removeTrigger:c,runPending:d,dismissPending:f}=qq(),[h,g]=x.useState(!1),p=b=>e.find(v=>v.id===b)?.name??b;return i.jsxs("section",{className:"border-t border-border px-4 py-3",children:[i.jsxs("div",{className:"flex items-center justify-between gap-3",children:[i.jsxs("div",{children:[i.jsxs("h3",{className:"flex items-center gap-1.5 text-[12px] font-semibold",children:[i.jsx(_E,{className:"size-3.5 text-amber-500"})," ",t("workflows.triggers.title")]}),i.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:t("workflows.triggers.subtitle")})]}),i.jsxs(Q,{onClick:()=>g(b=>!b),size:"sm",type:"button",variant:"outline",children:[i.jsx(fs,{className:"size-3.5"})," ",t("workflows.triggers.add")]})]}),a?i.jsx("p",{className:"mt-2 text-[11px] text-destructive",children:a}):null,n.length>0?i.jsx("div",{className:"mt-3 space-y-1.5",children:n.map(b=>i.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-amber-500/40 bg-amber-500/5 px-2.5 py-1.5",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"truncate text-[11px] font-medium",children:[p(b.workflowId),i.jsxs("span",{className:"ml-1.5 text-muted-foreground",children:["· ",t(Of[b.event])]})]}),i.jsx("div",{className:"truncate text-[10px] text-muted-foreground",children:b.summary})]}),i.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[i.jsxs(Q,{onClick:()=>d(b),size:"sm",type:"button",variant:"outline",children:[i.jsx(Or,{className:"size-3"})," ",t("workflows.run")]}),i.jsx(Q,{onClick:()=>{f(b.id)},size:"icon",type:"button",variant:"ghost","aria-label":t("workflows.triggers.dismiss"),children:i.jsx(Vt,{className:"size-3.5"})})]})]},b.id))}):null,h?i.jsx(oee,{workflows:e,onCancel:()=>g(!1),onSave:async b=>{await l(b),g(!1)}}):null,i.jsxs("div",{className:"mt-3 space-y-1.5",children:[s.length===0&&!h?i.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:t("workflows.triggers.empty")}):null,s.map(b=>i.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-border px-2.5 py-1.5",children:[i.jsxs("label",{className:"flex min-w-0 items-center gap-2",children:[i.jsx("input",{checked:b.enabled,className:"size-3.5 accent-primary",onChange:v=>{l({...b,enabled:v.target.checked})},type:"checkbox"}),i.jsxs("span",{className:"min-w-0 truncate text-[11px]",children:[i.jsx("span",{className:"font-medium",children:t(Of[b.event])}),b.filter?i.jsxs("span",{className:"text-muted-foreground",children:[" · “",b.filter,"”"]}):null,i.jsxs("span",{className:"text-muted-foreground",children:[" → ",p(b.workflowId)]}),b.autoRun?i.jsx("span",{className:"ml-1.5 rounded bg-amber-500/15 px-1 py-px text-[9px] font-semibold uppercase text-amber-600",children:t("workflows.triggers.autoBadge")}):null]})]}),i.jsx(Q,{onClick:()=>{c(b.id)},size:"icon",type:"button",variant:"ghost","aria-label":t("workflows.triggers.deleteAria"),children:i.jsx(Bi,{className:"size-3.5"})})]},b.id))]})]})}function oee({workflows:e,onCancel:t,onSave:s}){const n=ee(),[a,l]=x.useState("error-incident"),[c,d]=x.useState(e[0]?.id??""),[f,h]=x.useState(""),[g,p]=x.useState(!1),b="rounded border border-border bg-background px-2 py-1 text-[11px] outline-none focus:border-primary";return i.jsxs("div",{className:"mt-3 space-y-2 rounded-md border border-border bg-background p-3",children:[i.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[i.jsxs("label",{className:"flex flex-col gap-1 text-[10px] font-medium text-muted-foreground",children:[n("workflows.triggers.when"),i.jsx("select",{className:b,value:a,onChange:v=>l(v.target.value),children:Object.keys(Of).map(v=>i.jsx("option",{value:v,children:n(Of[v])},v))})]}),i.jsxs("label",{className:"flex flex-col gap-1 text-[10px] font-medium text-muted-foreground",children:[n("workflows.triggers.runWorkflow"),i.jsx("select",{className:b,value:c,onChange:v=>d(v.target.value),children:e.map(v=>i.jsx("option",{value:v.id,children:v.name},v.id))})]})]}),i.jsxs("label",{className:"flex flex-col gap-1 text-[10px] font-medium text-muted-foreground",children:[n("workflows.triggers.filterLabel"),i.jsx("input",{className:b,value:f,onChange:v=>h(v.target.value),placeholder:"e.g. api",type:"text"})]}),i.jsxs("label",{className:"flex w-fit items-center gap-1.5 text-[11px] text-muted-foreground",children:[i.jsx("input",{checked:g,className:"size-3.5 accent-primary",onChange:v=>p(v.target.checked),type:"checkbox"}),n("workflows.triggers.autoRunLabel")]}),i.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[i.jsx(Q,{onClick:t,size:"sm",type:"button",variant:"ghost",children:n("common.cancel")}),i.jsx(Q,{disabled:!c,onClick:()=>{s({id:`trigger-${Date.now().toString(36)}`,event:a,workflowId:c,filter:f.trim()||void 0,enabled:!0,autoRun:g})},size:"sm",type:"button",children:n("common.add")})]})]})}function lee(){const e=ee(),{run:t,start:s,resume:n,approve:a,skip:l,stop:c,dismiss:d}=g5(),[f,h]=x.useState([]),[g,p]=x.useState(null),[b,v]=x.useState(null),[_,S]=x.useState(null),[C,N]=x.useState(!0),[A,j]=x.useState(!1),[E,T]=x.useState(!0);x.useEffect(()=>{let M=!0;return N(!0),Promise.all([UE(),Zx().catch(()=>null)]).then(([z,G])=>{M&&(h(z),p(G))}).catch(z=>{M&&S(z instanceof Error?z.message:String(z))}).finally(()=>{M&&N(!1)}),()=>{M=!1}},[]);function L(M){j(!0),s(M,E)}async function H(M){S(null);try{const z=await R9(M);h(z),v(null)}catch(z){S(z instanceof Error?z.message:String(z))}}async function P(M){if(!M.builtin&&window.confirm(e("workflows.deleteConfirm",{name:M.name}))){S(null);try{h(await M9(M.id))}catch(z){S(z instanceof Error?z.message:String(z))}}}function F(M){v({...M,id:l1(`${M.id}-copy`,f),name:`${M.name} copy`,builtin:!1,steps:M.steps.map((z,G)=>({...z,id:`${z.id}-${G+1}`}))})}return t&&A?i.jsx(vee,{run:t,onApprove:a,onSkip:l,onStop:c,onBack:()=>j(!1),onResume:()=>{j(!0),n(E)},onRestart:()=>{j(!0),s(t.workflow,E)}}):b?i.jsx(dee,{agent:g?_ee(g):null,existing:f,initial:b,onCancel:()=>v(null),onSave:M=>{H(M)}}):i.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-auto bg-card/85",children:[i.jsxs("div",{className:"border-b border-border px-4 py-3",children:[i.jsxs("div",{className:"flex items-start justify-between gap-3",children:[i.jsxs("div",{children:[i.jsxs("h2",{className:"flex items-center gap-1.5 text-[13px] font-semibold",children:[i.jsx(Xt,{className:"size-4"})," ",e("workflows.title")]}),i.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:e("workflows.subtitle")})]}),i.jsxs(Q,{onClick:()=>v(See(f)),size:"sm",type:"button",variant:"outline",children:[i.jsx(fs,{className:"size-3.5"})," ",e("workflows.new")]})]}),i.jsxs("label",{className:"mt-2 flex w-fit items-center gap-1.5 text-[11px] text-muted-foreground",children:[i.jsx("input",{checked:E,className:"size-3.5 accent-primary",onChange:M=>T(M.target.checked),type:"checkbox"}),e("workflows.autoApprove"),i.jsx("span",{className:"text-muted-foreground/60",children:e("workflows.autoApproveHint")})]})]}),_?i.jsx(tt,{variant:"destructive",className:"m-4",children:_}):C?i.jsxs("div",{className:"flex flex-1 items-center justify-center text-[12px] text-muted-foreground",children:[i.jsx(Lt,{className:"mr-2 size-4 animate-spin"})," ",e("workflows.loading")]}):i.jsxs(i.Fragment,{children:[t?i.jsx(cee,{onClear:d,onView:()=>j(!0),run:t}):null,i.jsx("div",{className:"grid gap-3 p-4 sm:grid-cols-2 xl:grid-cols-3",children:f.map(M=>i.jsx(uee,{lastRun:t?.workflow.id===M.id?t:null,workflow:M,onDelete:()=>{P(M)},onDuplicate:()=>F(M),onEdit:()=>v(M),onRun:()=>L(M)},M.id))}),i.jsx(aee,{workflows:f})]})]})}function cee({onClear:e,onView:t,run:s}){const n=ee(),a=s.outcome==="running";return i.jsx("section",{className:"mx-4 mt-4 rounded-md border border-border bg-background p-3 shadow-sm",children:i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/70",children:n(a?"workflows.banner.running":"workflows.banner.last")}),i.jsx(yT,{outcome:s.outcome})]}),i.jsx("p",{className:"mt-1 truncate text-[13px] font-medium",children:s.workflow.name}),i.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:a?n("workflows.banner.startedAt",{time:Px(s.startedAt)}):n("workflows.banner.ranAt",{time:Px(s.startedAt)})})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[i.jsxs(Q,{onClick:t,size:"sm",type:"button",children:[i.jsx(Al,{className:"size-3.5"})," ",n("workflows.viewRun")]}),a?null:i.jsxs(Q,{onClick:e,size:"sm",type:"button",variant:"outline",children:[i.jsx(Vt,{className:"size-3.5"})," ",n("workflows.clear")]})]})]})})}function uee({lastRun:e,workflow:t,onDelete:s,onDuplicate:n,onEdit:a,onRun:l}){const c=ee(),[d,f]=x.useState(!1),h=t.steps.length;return i.jsxs("div",{className:"flex flex-col rounded-lg border border-border bg-background p-3.5 shadow-sm",children:[i.jsxs("div",{className:"flex items-start justify-between gap-2",children:[i.jsx("h3",{className:"text-[13px] font-semibold",children:t.name}),t.builtin?i.jsx("span",{className:"rounded-full border border-border px-1.5 py-px text-[9px] uppercase tracking-wide text-muted-foreground",children:c("workflows.template")}):null]}),t.description?i.jsx("p",{className:"mt-1 text-[11px] leading-snug text-muted-foreground",children:t.description}):null,e?i.jsxs("p",{className:"mt-2 flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[i.jsx(Al,{className:"size-3"}),e.outcome==="running"?c("workflows.runningNow"):c("workflows.lastRun",{time:Px(e.startedAt)})]}):null,i.jsxs("button",{"aria-expanded":d,className:"mt-2.5 flex w-full items-center gap-1.5 text-[11px] text-muted-foreground transition-colors hover:text-foreground",onClick:()=>f(g=>!g),type:"button",children:[i.jsx(_n,{className:oe("size-3 shrink-0 transition-transform",d?"rotate-90":""),"aria-hidden":!0}),i.jsx("span",{children:c(h===1?"workflows.stepOne":"workflows.stepMany",{count:h})})]}),d?i.jsx("ol",{className:"mt-1.5 space-y-1",children:t.steps.map(g=>i.jsxs("li",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[i.jsx(Nee,{kind:g.kind}),i.jsx("span",{className:"truncate",children:Pf(g)})]},g.id))}):null,i.jsxs(Q,{className:"mt-3 w-full",onClick:l,size:"sm",type:"button",children:[i.jsx(Or,{className:"size-3.5"})," ",c("workflows.run")]}),i.jsxs("div",{className:"mt-2 grid grid-cols-3 gap-1.5",children:[i.jsxs(Q,{onClick:a,size:"sm",type:"button",variant:"outline",children:[i.jsx(ND,{className:"size-3.5"})," ",c("common.edit")]}),i.jsxs(Q,{onClick:n,size:"sm",type:"button",variant:"outline",children:[i.jsx(ef,{className:"size-3.5"})," ",c("common.copy")]}),i.jsxs(Q,{disabled:t.builtin,onClick:s,size:"sm",title:t.builtin?c("workflows.deleteBuiltinHint"):c("workflows.deleteTitle"),type:"button",variant:"outline",children:[i.jsx(Bi,{className:"size-3.5"})," ",c("common.delete")]})]})]})}function dee({agent:e,existing:t,initial:s,onCancel:n,onSave:a}){const l=ee(),[c,d]=x.useState(()=>structuredClone(s)),[f,h]=x.useState(s.description??""),[g,p]=x.useState(!1),b=wee(e),{sendToAgent:v}=Ot(),_=!c.id.trim()||!c.name.trim()||c.steps.length===0;function S(H,P){d(F=>({...F,steps:F.steps.map((M,z)=>z===H?P(M):M)}))}function C(H,P){d(F=>{const M=H+P;if(M<0||M>=F.steps.length)return F;const z=[...F.steps],[G]=z.splice(H,1);return z.splice(M,0,G),{...F,steps:z}})}function N(H){d(P=>({...P,steps:P.steps.filter((F,M)=>M!==H)}))}function A(H,P){d(F=>{const M=[...F.steps];return M.splice(H,0,fee(P,F.steps)),{...F,steps:M}})}function j(H=f){const P=LN(H,t,b);d(P)}function E(H){const P=LN(H,[],b);d(F=>({...F,steps:[...F.steps,...P.steps]}))}function T(){v({prompt:see(f||c.description||c.name),source:{type:"workflow",label:l("workflows.builder.composerSource")},mode:"draft"})}function L(){const H=Sl(c.id)||l1(Sl(c.name)||"workflow",t);a({...c,id:H,name:c.name.trim(),description:(f||c.description)?.trim()||void 0,builtin:!1,steps:c.steps.map(kee)})}return i.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:[i.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border px-4 py-3",children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(Xt,{className:"size-4 shrink-0"}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("input",{"aria-label":l("workflows.builder.nameAria"),className:"w-full bg-transparent text-[14px] font-semibold outline-none",onChange:H=>d(P=>({...P,name:H.target.value,id:Sl(H.target.value)||P.id})),placeholder:l("workflows.builder.namePlaceholder"),value:c.name}),i.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:c.id})]})]}),i.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[i.jsxs(Q,{onClick:()=>p(H=>!H),size:"sm",type:"button",variant:g?"default":"outline",children:[i.jsx(zn,{className:"size-3.5"})," ",l("workflows.builder.aiCompose")]}),i.jsxs(Q,{onClick:n,size:"sm",type:"button",variant:"outline",children:[i.jsx(Eu,{className:"size-3.5"})," ",l("common.back")]}),i.jsxs(Q,{disabled:_,onClick:L,size:"sm",type:"button",children:[i.jsx(Ys,{className:"size-3.5"})," ",l("common.save")]})]})]}),g?i.jsx("section",{className:"shrink-0 border-b border-border bg-muted/20 p-4",children:i.jsxs("div",{className:"grid gap-3 xl:grid-cols-[minmax(0,1.1fr)_minmax(0,0.9fr)]",children:[i.jsxs("div",{className:"rounded-lg border border-border bg-background p-3 shadow-sm",children:[i.jsx(Dr,{children:l("workflows.builder.describe")}),i.jsx("textarea",{className:"min-h-16 w-full resize-none bg-transparent text-[13px] leading-relaxed outline-none placeholder:text-muted-foreground",onChange:H=>h(H.target.value),placeholder:l("workflows.builder.describePlaceholder"),value:f}),i.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:[i.jsxs(Q,{onClick:()=>j(),size:"sm",type:"button",children:[i.jsx(zn,{className:"size-3.5"})," ",l("workflows.builder.draftTimeline")]}),i.jsxs(Q,{onClick:T,size:"sm",type:"button",variant:"outline",children:[i.jsx(rD,{className:"size-3.5"})," ",l("workflows.builder.askAi")]}),["Commit safely","Review then push","Fix CI then PR","File issue from changes"].map(H=>i.jsx("button",{className:"rounded-md border border-border bg-muted/30 px-2 py-1 text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:()=>{h(H),j(H)},type:"button",children:H},H))]})]}),i.jsxs("div",{className:"grid gap-3",children:[i.jsx(mee,{onAdd:E}),i.jsx(pee,{capabilities:b})]})]})}):null,i.jsx("main",{className:"min-h-0 flex-1 overflow-auto p-4",children:i.jsxs("div",{className:"mx-auto max-w-3xl",children:[i.jsx(PN,{onInsert:H=>A(0,H)}),c.steps.length?c.steps.map((H,P)=>i.jsxs(x.Fragment,{children:[i.jsxs("div",{className:"flex gap-4",children:[i.jsxs("div",{className:"relative flex w-9 shrink-0 justify-center pt-2",children:[i.jsx("span",{"aria-hidden":!0,className:"absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border"}),i.jsx(hee,{index:P,kind:H.kind})]}),i.jsx("div",{className:"min-w-0 flex-1 pb-1",children:i.jsx(gee,{capabilities:b,index:P,isFirst:P===0,isLast:P===c.steps.length-1,onMove:C,onRemove:N,onUpdate:S,step:H})})]}),i.jsx(PN,{onInsert:F=>A(P+1,F)})]},`${H.kind}:${H.id}`)):i.jsx("div",{className:"ml-[3.25rem] flex h-24 items-center justify-center rounded-lg border border-dashed border-border text-[12px] text-muted-foreground",children:l("workflows.builder.emptyCanvas")})]})})]})}function PN({defaultOpen:e=!1,onInsert:t}){const s=ee(),[n,a]=x.useState(e),l=["gate","agent","action"];return i.jsxs("div",{className:"flex gap-4",children:[i.jsxs("div",{className:"relative flex w-9 shrink-0 justify-center",children:[i.jsx("span",{"aria-hidden":!0,className:"absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border"}),i.jsx("button",{"aria-label":s(n?"workflows.builder.cancelAddStep":"workflows.builder.addStepHere"),className:oe("relative z-10 my-1.5 flex size-5 items-center justify-center rounded-full border bg-card text-muted-foreground transition-colors",n?"border-primary/50 text-primary":"border-border hover:border-primary/50 hover:text-primary"),onClick:()=>a(c=>!c),type:"button",children:n?i.jsx(Vt,{className:"size-3"}):i.jsx(fs,{className:"size-3"})})]}),i.jsx("div",{className:"flex-1 py-1",children:n?i.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:l.map(c=>i.jsxs("button",{className:"flex items-center gap-1.5 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-muted-foreground transition-colors hover:border-primary/40 hover:text-foreground",onClick:()=>{t(c),a(!1)},type:"button",children:[i.jsx(_T,{kind:c})," ",s(bT[c])]},c))}):null})]})}function hee({index:e,kind:t}){return i.jsxs("div",{className:"relative z-10 flex size-9 items-center justify-center rounded-full border border-border bg-card shadow-sm",children:[i.jsx("span",{className:"absolute -right-1 -top-1 flex size-4 items-center justify-center rounded-full border border-border bg-background font-mono text-[9px] text-muted-foreground",children:e+1}),i.jsx(_T,{kind:t})]})}function fee(e,t){const s=new Set(t.map(a=>a.id)),n=a=>{let l=a,c=2;for(;s.has(l);)l=`${a}-${c++}`;return l};return e==="gate"?{kind:"gate",id:n("gate"),title:"Approve step",message:"Continue?"}:e==="action"?{kind:"action",id:n("action"),title:"Commit with approved message",op:"commit"}:{kind:"agent",id:n("step"),title:"AI step",prompt:""}}function mee({onAdd:e}){const t=ee(),[s,n]=x.useState("");return i.jsxs("form",{className:"rounded-lg border border-dashed border-border bg-background/70 p-3",onSubmit:a=>{a.preventDefault();const l=s.trim();l&&(e(l),n(""))},children:[i.jsx(Dr,{children:t("workflows.builder.addStepLabel")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{className:"min-w-0 flex-1 bg-transparent text-[12px] outline-none placeholder:text-muted-foreground",onChange:a=>n(a.target.value),placeholder:t("workflows.builder.addStepPlaceholder"),value:s}),i.jsxs(Q,{size:"sm",type:"submit",variant:"outline",children:[i.jsx(fs,{className:"size-3.5"})," ",t("common.add")]})]})]})}function pee({capabilities:e}){const t=ee(),s=[...e.skills.map(n=>`@skill:${n}`),...e.mcpServers.map(n=>`@mcp:${n}`),...e.plugins.map(n=>`@plugin:${n}`)].slice(0,18);return s.length?i.jsxs("div",{className:"rounded-lg border border-border bg-background p-3",children:[i.jsx(Dr,{children:t("workflows.builder.detectedCapabilities")}),i.jsx("div",{className:"flex max-h-20 flex-wrap gap-1.5 overflow-hidden",children:s.map(n=>i.jsx("span",{className:"rounded-md border border-border bg-muted/30 px-2 py-1 font-mono text-[11px] text-muted-foreground",children:n},n))})]}):null}function gee({capabilities:e,index:t,isFirst:s,isLast:n,onMove:a,onRemove:l,onUpdate:c,step:d}){const f=ee();return i.jsx("section",{className:"group rounded-lg border border-border bg-background p-3 shadow-sm",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(zx,{kind:d.kind}),i.jsx("input",{className:"min-w-0 flex-1 bg-transparent text-[13px] font-semibold outline-none",onChange:h=>c(t,g=>({...g,title:h.target.value})),value:d.title})]}),d.kind==="gate"?i.jsx("textarea",{className:"mt-2 min-h-12 w-full resize-none bg-transparent text-[12px] leading-relaxed text-muted-foreground outline-none focus:text-foreground",onChange:h=>c(t,g=>g.kind==="gate"?{...g,message:h.target.value}:g),placeholder:f("workflows.builder.gatePlaceholder"),value:d.message}):d.kind==="action"?i.jsxs("div",{className:"mt-2 space-y-1.5",children:[i.jsxs("select",{className:"w-full rounded-md border border-border bg-background px-2 py-1 text-[12px] outline-none",onChange:h=>{const g=h.target.value;c(t,p=>p.kind==="action"?{...p,op:g}:p)},value:d.op,children:[i.jsx("option",{value:"commit",children:f("workflows.op.commit")}),i.jsx("option",{value:"push",children:f("workflows.op.push")}),i.jsx("option",{value:"assert-pr-branch",children:f("workflows.op.assertPrBranch")}),i.jsx("option",{value:"checkout-default-and-pull",children:f("workflows.op.checkoutDefault")})]}),i.jsx("p",{className:"text-[11px] leading-relaxed text-muted-foreground",children:f(vT[d.op])})]}):i.jsxs(i.Fragment,{children:[i.jsx("textarea",{className:"mt-2 min-h-16 w-full resize-none bg-transparent text-[12px] leading-relaxed text-muted-foreground outline-none focus:text-foreground",onChange:h=>c(t,g=>g.kind==="agent"?{...g,prompt:h.target.value}:g),placeholder:f("workflows.builder.agentPromptPlaceholder"),value:d.prompt}),i.jsx(bee,{capabilities:e,selected:d.capabilities,onToggle:(h,g)=>c(t,p=>p.kind==="agent"?{...p,capabilities:Cee(p.capabilities,h,g)}:p)})]})]}),i.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-70 transition-opacity group-hover:opacity-100",children:[i.jsx(Q,{disabled:s,onClick:()=>a(t,-1),size:"sm",type:"button",variant:"ghost",children:"↑"}),i.jsx(Q,{disabled:n,onClick:()=>a(t,1),size:"sm",type:"button",variant:"ghost",children:"↓"}),i.jsx(Q,{onClick:()=>l(t),size:"sm",type:"button",variant:"ghost",children:i.jsx(Bi,{className:"size-3.5"})})]})]})})}function bee({capabilities:e,onToggle:t,selected:s}){const n=ee(),a=[{key:"skills",label:"Skills",values:e.skills},{key:"mcpServers",label:"MCP",values:e.mcpServers},{key:"plugins",label:"Plugins",values:e.plugins},{key:"hooks",label:"Hooks",values:e.hooks}];return i.jsxs("div",{className:"space-y-2",children:[i.jsx(Dr,{children:n("workflows.builder.capabilities")}),a.map(l=>i.jsxs("div",{children:[i.jsx("div",{className:"mb-1 text-[10px] text-muted-foreground",children:l.label}),l.values.length?i.jsx("div",{className:"flex flex-wrap gap-1.5",children:l.values.map(c=>{const d=s?.[l.key]?.includes(c)??!1;return i.jsx("button",{className:oe("rounded-md border px-2 py-1 text-[11px] transition-colors",d?"border-primary/50 bg-primary/10 text-primary":"border-border bg-muted/30 text-muted-foreground hover:bg-muted"),onClick:()=>t(l.key,c),type:"button",children:c},c)})}):i.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:n("workflows.builder.noneDetected")})]},l.key))]})}function vee({run:e,onApprove:t,onSkip:s,onStop:n,onBack:a,onResume:l,onRestart:c}){const d=ee(),{sendToAgent:f}=Ot(),h=e.outcome!=="running",[g,p]=x.useState(e.index);x.useEffect(()=>{p(e.index)},[e.index]);const b=e.workflow.steps[g]??e.workflow.steps[e.index],v=e.statuses[g]??"pending",_=e.outputs[g],S=e.outputs[g-1],C=b?.kind==="gate"&&v==="waiting",N=v==="failed"||v==="blocked",A=v==="blocked"&&b?.kind==="action"&&b.op==="assert-pr-branch";return i.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsxs("h2",{className:"flex items-center gap-1.5 text-[13px] font-semibold",children:[i.jsx(Xt,{className:"size-4"})," ",e.workflow.name]}),i.jsxs("p",{className:"mt-0.5 flex items-center gap-1 text-[11px] text-muted-foreground",children:[i.jsx(Al,{className:"size-3"})," ",d("workflows.run.watchDock")]})]}),i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx(yT,{outcome:e.outcome}),i.jsxs(Q,{onClick:a,size:"sm",type:"button",variant:"outline",children:[i.jsx(Eu,{className:"size-3.5"})," ",d("workflows.run.workflows")]}),h?null:i.jsxs(Q,{onClick:n,size:"sm",type:"button",variant:"outline",children:[i.jsx(xo,{className:"size-3.5"})," ",d("common.stop")]})]})]}),i.jsxs("div",{className:"grid min-h-0 flex-1 overflow-hidden lg:grid-cols-[minmax(240px,320px)_minmax(0,1fr)]",children:[i.jsx("aside",{className:"min-h-0 overflow-auto border-b border-border bg-background/55 p-3 lg:border-b-0 lg:border-r",children:i.jsx("ol",{className:"space-y-1",children:e.workflow.steps.map((j,E)=>{const T=e.statuses[E],L=T==="running"||T==="waiting",H=E===g;return i.jsx("li",{children:i.jsxs("button",{className:oe("flex w-full items-center gap-2 rounded-md border px-2.5 py-2 text-left transition-colors",H?"border-primary/45 bg-primary/[0.06]":L?"border-primary/30 bg-primary/[0.03]":"border-transparent hover:border-border hover:bg-muted/40"),onClick:()=>p(E),type:"button",children:[i.jsx("span",{className:oe("flex size-7 shrink-0 items-center justify-center rounded-full border bg-card",T==="failed"?"border-destructive/50":T==="blocked"?"border-amber-500/50":L?"border-primary/50":T==="done"?"border-emerald-500/50":"border-border"),children:i.jsx(BN,{status:T,kind:j.kind})}),i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"block truncate text-[12px] font-medium",children:Pf(j)}),i.jsxs("span",{className:"mt-0.5 flex items-center gap-1.5",children:[i.jsx(zx,{kind:j.kind}),i.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:d(zN[T])})]})]}),i.jsx(_n,{className:oe("size-3.5 shrink-0 text-muted-foreground/50 transition-transform",H?"translate-x-0.5 text-primary":"")})]})},j.id)})})}),i.jsx("main",{className:"min-h-0 overflow-auto p-4",children:b?i.jsxs("section",{className:oe("min-h-full rounded-lg border bg-background p-4 shadow-sm",v==="failed"?"border-destructive/40 bg-destructive/[0.03]":v==="blocked"?"border-amber-500/40 bg-amber-500/[0.04]":v==="running"||v==="waiting"?"border-primary/40 bg-primary/[0.03]":"border-border"),children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-border pb-3",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(BN,{status:v,kind:b.kind}),i.jsx("h3",{className:"truncate text-[13px] font-semibold",children:Pf(b)})]}),i.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[i.jsx(zx,{kind:b.kind}),i.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:d(zN[v])})]})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[h&&N&&g===e.index&&!A?i.jsxs(Q,{"aria-label":d("workflows.run.resumeAria"),onClick:l,size:"sm",type:"button",children:[i.jsx(Or,{className:"size-3.5"})," ",d("workflows.run.resume")]}):null,N?i.jsxs(Q,{"aria-label":d("workflows.run.debugAria"),onClick:()=>f({prompt:Nq({workflowName:e.workflow.name,step:b,status:v,error:e.error,previousOutput:S,output:_}),source:{type:"workflow-debug",label:b.title},mode:"send",label:d("workflows.run.debugLabel",{title:b.title}),background:!0}),size:"sm",type:"button",variant:"outline",children:[i.jsx(Xt,{className:"size-3.5"})," ",d("workflows.run.debugWithAi")]}):null,h?null:i.jsxs(Q,{"aria-label":d("workflows.run.stopAria"),onClick:n,size:"sm",type:"button",variant:"outline",children:[i.jsx(xo,{className:"size-3.5"})," ",d("workflows.run.stopAfter")]})]})]}),i.jsxs("div",{className:"py-3 text-[11px] leading-relaxed",children:[i.jsx(yee,{output:_,previousOutput:S,status:v,step:b}),C?i.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-1.5",children:[i.jsxs(Q,{onClick:t,size:"sm",type:"button",children:[i.jsx(Ys,{className:"size-3.5"})," ",d("workflows.run.approve")]}),i.jsxs(Q,{onClick:s,size:"sm",type:"button",variant:"outline",children:[i.jsx(xE,{className:"size-3.5"})," ",d("workflows.run.skip")]}),i.jsxs(Q,{onClick:n,size:"sm",type:"button",variant:"outline",children:[i.jsx(Vt,{className:"size-3.5"})," ",d("common.stop")]})]}):null,v==="failed"&&e.error?i.jsx("p",{className:"mt-3 text-destructive",children:e.error}):null,A?i.jsx(xee,{error:e.error,onRestart:c,workflowName:e.workflow.name}):null,v==="blocked"&&e.error?i.jsx("p",{className:"mt-3 text-amber-700 dark:text-amber-400",children:e.error}):null]})]}):null})]})]})}function xee({error:e,onRestart:t,workflowName:s}){const n=ee(),{provider:a}=Ot(),[l,c]=x.useState(""),[d,f]=x.useState(!1),[h,g]=x.useState(!1),[p,b]=x.useState(null),[v,_]=x.useState(null),S=x.useRef(null),C=Lq(l);x.useEffect(()=>()=>S.current?.abort(),[]);async function N(j){S.current?.abort();const E=new AbortController;S.current=E,_(null),b(null),c(""),f(!0);try{const T=await O0({prompt:[Eq({workflowName:s,error:e}),j?.trim()?j.trim():""].filter(Boolean).join(`
|
|
226
226
|
|
|
227
|
-
`),provider:a?.id,signal:E.signal});E.signal.aborted||c(T)}catch(T){E.signal.aborted||_(T instanceof Error?T.message:String(T))}finally{S.current===E&&(S.current=null,f(!1))}}async function A(){if(C){g(!0),_(null);try{await l7(C),b(C)}catch(j){_(j instanceof Error?j.message:String(j))}finally{g(!1)}}}return i.jsxs("div",{className:"mt-3 rounded-md border border-border bg-muted/35 p-3",children:[i.jsx(Dr,{children:n("workflows.recover.title")}),i.jsx("p",{className:"mb-2 text-[11px] text-muted-foreground",children:n("workflows.recover.desc")}),i.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[i.jsxs(Q,{onClick:()=>{N()},size:"sm",type:"button",children:[i.jsx(Xt,{className:"size-3.5"})," ",n("workflows.recover.recommend")]}),p?i.jsxs(Q,{onClick:t,size:"sm",type:"button",variant:"outline",children:[i.jsx(Or,{className:"size-3.5"})," ",n("workflows.recover.runAgain")]}):null]}),d?i.jsxs("p",{className:"mt-2 flex items-center gap-1 text-[11px] text-muted-foreground",children:[i.jsx(Lt,{className:"size-3 animate-spin"})," ",n("workflows.recover.choosing")]}):null,C?i.jsxs("div",{className:"mt-3 rounded-md border border-border bg-background p-2.5",children:[i.jsx(Dr,{children:n("workflows.recover.recommendedBranch")}),i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[i.jsx("code",{className:"min-w-0 rounded bg-muted px-2 py-1 font-mono text-[12px] text-foreground",children:C}),i.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[i.jsxs(Q,{disabled:h||p===C,onClick:()=>{A()},size:"sm",type:"button",children:[h?i.jsx(Lt,{className:"size-3.5 animate-spin"}):i.jsx(Ys,{className:"size-3.5"}),n("workflows.recover.createBranch")]}),i.jsxs(Q,{disabled:h,onClick:()=>{N("Recommend a different concise branch name. Keep the same output contract with `BRANCH_NAME: <branch-name>`.")},size:"sm",type:"button",variant:"outline",children:[i.jsx(Xt,{className:"size-3.5"})," ",n("workflows.recover.askAnother")]})]})]})]}):l&&!d?i.jsxs("div",{className:"mt-3 rounded-md border border-border bg-background p-2.5",children:[i.jsx("p",{className:"text-[11px] text-muted-foreground",children:n("workflows.recover.noBranch")}),i.jsxs(Q,{className:"mt-2",onClick:()=>{N("Return only a concise branch suggestion using this exact line: `BRANCH_NAME: <branch-name>`.")},size:"sm",type:"button",variant:"outline",children:[i.jsx(Xt,{className:"size-3.5"})," ",n("workflows.recover.askAnother")]})]}):null,p?i.jsxs("p",{className:"mt-2 text-[11px] text-emerald-700 dark:text-emerald-400",children:[n("workflows.recover.createdPre"),i.jsx("code",{className:"font-mono",children:p}),n("workflows.recover.createdPost")]}):null,v?i.jsx("p",{className:"mt-2 text-[11px] text-destructive",children:v}):null]})}const zN={running:"workflows.status.running",waiting:"workflows.status.waiting",done:"workflows.status.done",blocked:"workflows.status.needsYou",failed:"workflows.status.failed",skipped:"workflows.status.skipped",pending:"workflows.status.queued"},bT={gate:"workflows.kind.gate",agent:"workflows.kind.agent",action:"workflows.kind.action"};function yee({output:e,previousOutput:t,status:s,step:n}){const a=ee();if(n.kind==="gate"){const c=n.id==="gate-commit"?t?.trim():"";return i.jsxs("div",{children:[i.jsx("p",{className:"text-muted-foreground",children:n.message}),c?i.jsxs("div",{className:"mt-3",children:[i.jsx(Dr,{children:a("workflows.step.generatedCommitMessage")}),i.jsx("div",{className:"whitespace-pre-wrap break-words rounded-md border border-border bg-muted/50 px-2.5 py-2 font-mono text-[11px] text-foreground",children:c})]}):null]})}if(n.kind==="action")return i.jsx("p",{className:"text-muted-foreground",children:a(vT[n.op])});const l=s==="done"||s==="failed"||s==="skipped";return e?i.jsxs("div",{children:[i.jsx(Dr,{children:a("workflows.step.result")}),i.jsx("div",{className:"whitespace-pre-wrap break-words rounded-md bg-muted/50 px-2.5 py-2 font-mono text-[11px] text-foreground",children:e})]}):i.jsxs("div",{children:[i.jsx(Dr,{children:a(l?"workflows.step.result":"workflows.step.task")}),l?i.jsx("p",{className:"italic text-muted-foreground",children:a("workflows.step.noReply")}):i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"text-muted-foreground",children:n.prompt}),s==="running"?i.jsxs("p",{className:"mt-1.5 flex items-center gap-1 text-muted-foreground/80",children:[i.jsx(Lt,{className:"size-3 animate-spin"})," ",a("workflows.step.working")]}):null]})]})}function _ee(e){return e.detected.name==="codex"?e.agents.codex:e.agents["claude-code"]??e}function wee(e){return e?{skills:ru(e.skills.map(t=>t.name)),mcpServers:ru(e.mcpServers.map(t=>t.name)),plugins:ru(e.plugins.map(t=>t.name)),hooks:ru(e.hooks.map(t=>t.matcher?`${t.event}: ${t.matcher}`:t.event))}:{skills:[],mcpServers:[],plugins:[],hooks:[]}}function See(e){return{id:l1("custom-workflow",e),name:"Custom workflow",description:"A user-built workflow.",builtin:!1,steps:[{kind:"gate",id:"gate-start",title:"Approve start",message:"Run this workflow?"}]}}function kee(e){const t=Sl(e.id)||e.kind,s=e.title.trim()||Pf(e);if(e.kind==="gate")return{...e,id:t,title:s,message:e.message.trim()||"Continue?"};if(e.kind==="action")return{...e,id:t,title:s};const n=xT(e.capabilities);return{...e,id:t,title:s,prompt:e.prompt.trim()||"Complete this workflow step.",capabilities:n}}const vT={"assert-pr-branch":"workflows.opDesc.assertPrBranch","checkout-default-and-pull":"workflows.opDesc.checkoutDefault",push:"workflows.opDesc.push",commit:"workflows.opDesc.commit"};function xT(e){if(!e)return;const t={};for(const s of["skills","mcpServers","plugins","hooks"]){const n=ru((e[s]??[]).map(a=>a.trim()).filter(Boolean));n.length&&(t[s]=n)}return Object.keys(t).length?t:void 0}function Cee(e,t,s){const n=e?.[t]??[],a=n.includes(s)?n.filter(l=>l!==s):[...n,s];return xT({...e??{},[t]:a})}function l1(e,t){const s=new Set(t.map(l=>l.id));let n=Sl(e)||"workflow",a=2;for(;s.has(n);)n=`${Sl(e)||"workflow"}-${a}`,a++;return n}function Sl(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function ru(e){return Array.from(new Set(e.filter(Boolean)))}function Dr({children:e}){return i.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/70",children:e})}function Px(e){return new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"2-digit"}).format(new Date(e))}function yT({outcome:e}){const t=ee(),s={running:{labelKey:"workflows.status.running",className:"border-primary/40 text-primary"},done:{labelKey:"workflows.status.done",className:"border-emerald-500/40 text-emerald-600 dark:text-emerald-400"},stopped:{labelKey:"workflows.status.stopped",className:"border-border text-muted-foreground"},failed:{labelKey:"workflows.status.failed",className:"border-destructive/40 text-destructive"},blocked:{labelKey:"workflows.status.needsYou",className:"border-amber-500/40 text-amber-700 dark:text-amber-400"}},{labelKey:n,className:a}=s[e];return i.jsx("span",{className:oe("rounded-full border px-2 py-0.5 text-[10px] font-medium",a),children:t(n)})}function _T({kind:e}){return e==="gate"?i.jsx(vE,{className:"size-4 text-amber-600 dark:text-amber-400"}):e==="agent"?i.jsx(zn,{className:"size-4 text-primary"}):i.jsx(Or,{className:"size-4 text-muted-foreground"})}function BN({status:e,kind:t}){return e==="running"?i.jsx(Lt,{className:"size-4 shrink-0 animate-spin text-primary"}):e==="waiting"?i.jsx(vE,{className:"size-4 shrink-0 text-primary"}):e==="done"?i.jsx(Ys,{className:"size-4 shrink-0 text-emerald-600 dark:text-emerald-400"}):e==="blocked"?i.jsx(Uf,{className:"size-4 shrink-0 text-amber-600 dark:text-amber-400"}):e==="failed"?i.jsx(Lr,{className:"size-4 shrink-0 text-destructive"}):e==="skipped"?i.jsx(xE,{className:"size-4 shrink-0 text-muted-foreground/60"}):t==="agent"?i.jsx(zn,{className:"size-4 shrink-0 text-muted-foreground/50"}):i.jsx(wM,{className:"size-4 shrink-0 text-muted-foreground/50"})}function Nee(e){return i.jsx(_n,{className:"size-3 shrink-0 text-muted-foreground/40","aria-hidden":!0})}function zx({kind:e}){const t=ee(),s=e==="agent"?"border-primary/30 text-primary":e==="gate"?"border-amber-500/40 text-amber-600 dark:text-amber-400":"border-border text-muted-foreground";return i.jsx("span",{className:oe("shrink-0 rounded-full border px-1.5 py-px text-[9px] uppercase tracking-wide",s),children:t(bT[e])})}function Pf(e){return e.title}function Eee(){const[e,t]=x.useState(!1),[s,n]=x.useState(!1),[a,l]=x.useState(!0),[c,d]=x.useState("checking"),[f,h]=x.useState(null),[g,p]=x.useState(null);function b(){l(!0),d("checking"),h(null),p7().then(v=>{t(v.configured),n(v.deviceFlowAvailable),d(v.status),h(v.error??null),p(v)}).catch(v=>{t(!1),n(!1),d("connection_error"),h(v instanceof Error?v.message:String(v)),p(null)}).finally(()=>l(!1))}return x.useEffect(()=>{b()},[]),{configured:e,deviceFlowAvailable:s,loading:a,status:c,error:f,info:g,isConnected:c==="connected",needsLogin:c==="not_configured"||c==="auth_error",refresh:b}}const cv=30;function jee(e="open"){const[t,s]=x.useState([]),[n,a]=x.useState(!0),[l,c]=x.useState(!1),[d,f]=x.useState(!1),[h,g]=x.useState(1),[p,b]=x.useState(null),[v,_]=x.useState(null),[S,C]=x.useState(null),[N,A]=x.useState(""),[j,E]=x.useState(!1),[T,L]=x.useState(null);x.useEffect(()=>{let F=!0;return a(!0),b(null),g(1),Pg(e,1).then(M=>{F&&(s(M),f(M.length===cv),M.length>0&&!M.some(z=>z.number===v)&&_(M[0]?.number??null))}).catch(M=>{F&&b(M instanceof Error?M.message:String(M))}).finally(()=>{F&&a(!1)}),()=>{F=!1}},[e]),x.useEffect(()=>{if(!v){C(null);return}let F=!0;return _7(v).then(M=>{F&&C(M)}).catch(()=>{}),()=>{F=!1}},[v]),x.useEffect(()=>{if(!v){A("");return}let F=!0;return E(!0),L(null),w7(v).then(M=>{F&&A(M)}).catch(M=>{F&&L(M instanceof Error?M.message:String(M))}).finally(()=>{F&&E(!1)}),()=>{F=!1}},[v]);function H(){if(l||!d)return;const F=h+1;c(!0),Pg(e,F).then(M=>{s(z=>{const G=new Set(z.map(D=>D.number));return[...z,...M.filter(D=>!G.has(D.number))]}),f(M.length===cv),g(F)}).catch(M=>b(M instanceof Error?M.message:String(M))).finally(()=>c(!1))}function P(){let F=!0;return a(!0),b(null),g(1),Pg(e,1).then(M=>{F&&(s(M),f(M.length===cv))}).catch(M=>{F&&b(M instanceof Error?M.message:String(M))}).finally(()=>{F&&a(!1)}),()=>{F=!1}}return{prs:t,loading:n,loadingMore:l,hasMore:d,error:p,selectedNumber:v,setSelectedNumber:_,selectedPR:S,diff:N,diffLoading:j,diffError:T,loadMore:H,refresh:P}}const uv=30;function Aee(e="open"){const[t,s]=x.useState([]),[n,a]=x.useState(!0),[l,c]=x.useState(!1),[d,f]=x.useState(!1),[h,g]=x.useState(1),[p,b]=x.useState(null),[v,_]=x.useState(null),[S,C]=x.useState(null),[N,A]=x.useState([]),[j,E]=x.useState(!1),[T,L]=x.useState(null),[H,P]=x.useState(!1);x.useEffect(()=>{let G=!0;return a(!0),b(null),g(1),zg(e,1).then(D=>{G&&(s(D),f(D.length===uv),D.length>0&&!D.some(q=>q.number===v)&&_(D[0]?.number??null))}).catch(D=>{G&&b(D instanceof Error?D.message:String(D))}).finally(()=>{G&&a(!1)}),()=>{G=!1}},[e]),x.useEffect(()=>{if(!v){C(null),A([]);return}let G=!0;return E(!0),Promise.all([E7(v),j7(v)]).then(([D,q])=>{G&&(C(D),A(q))}).catch(()=>{}).finally(()=>{G&&E(!1)}),()=>{G=!1}},[v]);async function F(G){if(v){P(!0),L(null);try{const D=await A7(v,G);A(q=>[...q,D])}catch(D){L(D instanceof Error?D.message:String(D))}finally{P(!1)}}}function M(){if(l||!d)return;const G=h+1;c(!0),zg(e,G).then(D=>{s(q=>{const W=new Set(q.map(I=>I.number));return[...q,...D.filter(I=>!W.has(I.number))]}),f(D.length===uv),g(G)}).catch(D=>b(D instanceof Error?D.message:String(D))).finally(()=>c(!1))}function z(){let G=!0;return a(!0),g(1),zg(e,1).then(D=>{G&&(s(D),f(D.length===uv))}).catch(()=>{}).finally(()=>{G&&a(!1)}),()=>{G=!1}}return{issues:t,loading:n,loadingMore:l,hasMore:d,error:p,selectedNumber:v,setSelectedNumber:_,selectedIssue:S,comments:N,commentsLoading:j,commentError:T,submitting:H,addComment:F,loadMore:M,refresh:z}}function wT({deviceFlowAvailable:e,initialMode:t,onSaved:s}){const n=ee(),[a,l]=x.useState(()=>t==="device-pending"&&!e?"pat":t??(e?"choose":"pat"));return a==="device-pending"?i.jsx(Tee,{onSuccess:s,onCancel:()=>l("choose")}):a==="pat"?i.jsx(Ree,{onSaved:s,onBack:e?()=>l("choose"):void 0}):i.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[i.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[i.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-muted",children:i.jsx(Qw,{className:"size-6 text-muted-foreground"})}),i.jsxs("div",{children:[i.jsx("h2",{className:"text-base font-semibold",children:n("github.setup.connectTitle")}),i.jsx("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:n("github.setup.connectDesc")})]})]}),i.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-2",children:[i.jsxs(Q,{className:"w-full",onClick:()=>l("device-pending"),type:"button",children:[i.jsx(Qw,{className:"mr-2 size-4"}),n("github.setup.authorizeWith")]}),i.jsx("button",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",onClick:()=>l("pat"),type:"button",children:n("github.setup.usePat")})]})]})}function Tee({onSuccess:e,onCancel:t}){const s=ee(),[n,a]=x.useState(null),[l,c]=x.useState(null),[d,f]=x.useState(!0),[h,g]=x.useState(!1),p=x.useRef(null),b=x.useRef(5),v=x.useRef(!1);x.useEffect(()=>{let N=!0;return g7().then(A=>{if(!N)return;a(A),b.current=A.interval,f(!1);const j=A.verification_uri_complete||A.verification_uri;j&&Qf(j),_(A.device_code,A.interval),setTimeout(()=>{v.current=!0},A.expires_in*1e3)}).catch(A=>{N&&(c(A instanceof Error?A.message:String(A)),f(!1))}),()=>{N=!1,p.current&&clearTimeout(p.current)}},[]);function _(N,A){p.current=setTimeout(()=>{S(N,A)},A*1e3)}async function S(N,A){if(v.current){c(s("github.setup.expired"));return}try{const j=await b7(N);if(j.done){e();return}const E=j.slowDown?A+5:A;b.current=E,_(N,E)}catch{_(N,b.current)}}function C(){n&&navigator.clipboard.writeText(n.user_code).then(()=>{g(!0),setTimeout(()=>g(!1),2e3)})}return d?i.jsx("div",{className:"flex h-full items-center justify-center",children:i.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[i.jsx(Jw,{className:"size-6 animate-spin text-muted-foreground"}),i.jsx("p",{className:"text-[13px] text-muted-foreground",children:s("github.setup.requesting")})]})}):l?i.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-4 p-8",children:[i.jsx(tt,{variant:"destructive",children:l}),i.jsx(Q,{onClick:t,variant:"outline",children:s("github.setup.goBack")})]}):i.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[i.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[i.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-emerald-100 dark:bg-emerald-500/15",children:i.jsx(qf,{className:"size-6 text-emerald-600 dark:text-emerald-400"})}),i.jsxs("div",{children:[i.jsx("h2",{className:"text-base font-semibold",children:s("github.setup.authorizeOnTitle")}),i.jsxs("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:[s("github.setup.enterCodePre"),i.jsx("strong",{children:s("github.setup.authorizeWord")}),s("github.setup.enterCodePost")]})]})]}),i.jsxs("div",{className:"flex flex-col items-center gap-2",children:[i.jsx("div",{className:"flex cursor-pointer select-all items-center gap-3 rounded-xl border-2 border-border bg-muted px-6 py-4 font-mono text-2xl font-bold tracking-[0.3em] transition-colors hover:border-ring",onClick:C,title:s("github.setup.clickToCopy"),children:n?.user_code}),i.jsx("button",{className:"text-[11px] text-muted-foreground transition-colors hover:text-foreground",onClick:C,type:"button",children:s(h?"common.copied":"github.setup.clickCodeCopy")})]}),i.jsxs("div",{className:"flex flex-col items-center gap-2",children:[i.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-muted-foreground",children:[i.jsx(Jw,{className:"size-3.5 animate-spin"}),s("github.setup.waiting")]}),i.jsx("a",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",href:n?.verification_uri_complete||n?.verification_uri,rel:"noopener noreferrer",target:"_blank",children:s("github.setup.openAgain")}),i.jsx("button",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",onClick:t,type:"button",children:s("common.cancel")})]})]})}function Ree({onSaved:e,onBack:t}){const s=ee(),[n,a]=x.useState(""),[l,c]=x.useState(!1),[d,f]=x.useState(null);async function h(g){g.preventDefault();const p=n.trim();if(p){c(!0),f(null);try{await v7("github.com",p),e()}catch(b){f(b instanceof Error?b.message:String(b))}finally{c(!1)}}}return i.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[i.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[i.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-muted",children:i.jsx(uE,{className:"size-6 text-muted-foreground"})}),i.jsxs("div",{children:[i.jsx("h2",{className:"text-base font-semibold",children:s("github.setup.patTitle")}),i.jsxs("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:[s("github.setup.patDescPre"),i.jsx("a",{className:"underline underline-offset-2 hover:text-foreground",href:"https://github.com/settings/tokens/new?scopes=repo,workflow",rel:"noopener noreferrer",target:"_blank",children:"github.com/settings/tokens"}),s("github.setup.patDescMid"),i.jsx("code",{className:"rounded bg-muted px-1 py-px text-[11px]",children:"repo"}),s("github.setup.patDescAnd"),i.jsx("code",{className:"rounded bg-muted px-1 py-px text-[11px]",children:"workflow"}),s("github.setup.patDescPost")]})]})]}),i.jsxs("form",{className:"flex w-full max-w-sm flex-col gap-3",onSubmit:g=>{h(g)},children:[i.jsx("input",{autoComplete:"off",className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-[13px] placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring",onChange:g=>a(g.target.value),placeholder:"ghp_...",spellCheck:!1,type:"password",value:n}),d?i.jsx(tt,{variant:"destructive",children:d}):null,i.jsx(Q,{disabled:!n.trim()||l,type:"submit",children:s(l?"common.saving":"github.setup.saveToken")}),t?i.jsx("button",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",onClick:t,type:"button",children:s("github.setup.back")}):null]})]})}function c1({hasMore:e,loading:t,onLoadMore:s}){const n=ee();return e?i.jsx("div",{className:"p-2",children:i.jsxs("button",{className:"flex w-full items-center justify-center gap-1.5 rounded-md border border-border py-1.5 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground disabled:opacity-60",disabled:t,onClick:s,type:"button",children:[t?i.jsx(Lt,{className:"size-3 animate-spin"}):null,n(t?"common.loading":"github.loadMore")]})}):null}function Mee({prs:e,loading:t,loadingMore:s,hasMore:n,error:a,selectedNumber:l,onSelect:c,onLoadMore:d}){const f=ee();return t&&e.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.prs.loading")}):a?i.jsx("div",{className:"p-4 text-[12px] text-red-500",children:a}):e.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.prs.empty")}):i.jsxs(i.Fragment,{children:[i.jsx("ul",{className:"divide-y divide-border",children:e.map(h=>i.jsx("li",{children:i.jsxs("button",{className:`flex w-full items-start gap-3 px-3 py-2.5 text-left transition-colors hover:bg-muted/60 ${l===h.number?"bg-muted":""}`,onClick:()=>c(h.number),type:"button",children:[i.jsx("span",{className:"mt-0.5 shrink-0",children:i.jsx(Dee,{pr:h})}),i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"block truncate text-[13px] font-medium",children:h.title}),i.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",h.number," · ",h.base.ref," ← ",h.head.ref," · ",h.user.login]})]}),h.draft?i.jsx("span",{className:"shrink-0 rounded border border-border px-1.5 py-px text-[10px] text-muted-foreground",children:f("github.prs.draft")}):null]})},h.number))}),i.jsx(c1,{hasMore:n,loading:s,onLoadMore:d})]})}function Dee({pr:e}){return e.state==="merged"?i.jsx(sf,{className:"size-4 text-purple-500"}):e.state==="closed"?i.jsx(b6,{className:"size-4 text-red-500"}):i.jsx(cE,{className:"size-4 text-emerald-500"})}function ST({body:e,title:t}){const s=ee(),n=t??s("github.md.description"),[a,l]=x.useState("rendered"),c=d=>oe("rounded px-1.5 py-0.5 text-[10px] font-medium transition-colors",d?"bg-foreground text-background":"text-muted-foreground hover:text-foreground");return i.jsxs("section",{className:"overflow-hidden rounded-md border border-border bg-muted/25",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[i.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:n}),i.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-background/60 p-0.5",children:[i.jsx("button",{className:c(a==="rendered"),onClick:()=>l("rendered"),type:"button",children:s("github.md.rendered")}),i.jsx("button",{className:c(a==="raw"),onClick:()=>l("raw"),type:"button",children:s("github.md.raw")})]})]}),a==="rendered"?i.jsx(r1,{content:e}):i.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap px-3 py-3 font-mono text-[12px]",children:e})]})}function Lee({pr:e,diff:t,diffLoading:s,diffError:n,onMerged:a}){const l=ee(),[c,d]=x.useState("cockpit"),[f,h]=x.useState(null),[g,p]=x.useState(!1),[b,v]=x.useState(null),[_,S]=x.useState(null),[C,N]=x.useState(!1),[A,j]=x.useState(null),[E,T]=x.useState(!1),{sendToAgent:L}=Ot(),{isPending:H,runOperation:P}=si(),F=e?`github:pr:${e.number}:merge`:"",M=F?H(F):!1,z=x.useMemo(()=>J$(t),[t]);x.useEffect(()=>{j($=>$&&z.some(me=>me.path===$)?$:z[0]?.path??null)},[z]);const G=z.find($=>$.path===A)??z[0]??null;function D($){j($),d("diff")}function q($,me){e&&(T(!1),L({prompt:me?PF(e,me,$):OF(e,$),source:{type:"github-pr",label:`PR #${e.number}${me?` · ${zf(me)}`:""}`},label:`PR #${e.number}${me?` (${zf(me)})`:""}: ${$}`}))}if(x.useEffect(()=>{if(T(!1),!e){h(null);return}let $=!0;return p(!0),v(null),S7(e.number).then(me=>{$&&h(me)}).catch(me=>{$&&v(me instanceof Error?me.message:String(me))}).finally(()=>{$&&p(!1)}),()=>{$=!1}},[e]),!e)return i.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:l("github.pr.selectPrompt")});const W=e.state==="open"&&!e.draft;async function I(){if(!(!e||M)){S(null);try{await P({errorMessage:$=>$ instanceof Error?$.message:String($),key:F,label:l("github.pr.mergingOperation",{number:e.number})},()=>N7(e.number,{method:"squash"})),N(!1),a?.()}catch($){S($ instanceof Error?$.message:String($)),N(!1)}}}const Y=$=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${$?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`;return i.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[i.jsxs("div",{className:"group flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[i.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-semibold",children:e.title}),i.jsx(ir,{className:oe("shrink-0",E&&"opacity-100"),label:l("github.pr.askLabel",{number:e.number}),onAsk:()=>T($=>!$)}),i.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[i.jsx("button",{className:Y(c==="cockpit"),onClick:()=>d("cockpit"),type:"button",children:l("github.pr.tabReview")}),i.jsx("button",{className:Y(c==="diff"),onClick:()=>d("diff"),type:"button",children:l("github.pr.tabDiff")})]}),W?i.jsxs(Q,{className:"shrink-0",loading:M,loadingLabel:l("github.pr.merging"),onClick:()=>N(!0),size:"sm",title:l("github.pr.squashTitle"),type:"button",variant:"success",children:[i.jsx(sf,{}),l("github.pr.squashMerge")]}):null,i.jsx("a",{"aria-label":l("github.openOnGithub"),className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:e.html_url,rel:"noopener noreferrer",target:"_blank",title:l("github.openOnGithub"),children:i.jsx(ja,{className:"size-3.5"})})]}),_?i.jsx("div",{className:"shrink-0 border-b border-border bg-red-500/10 px-3 py-1.5 text-[11px] text-red-500",children:_}):null,E?i.jsx("div",{className:"shrink-0 border-b border-border px-3 py-1.5",children:i.jsx(Ir,{placeholder:l("github.pr.askPlaceholder"),onSubmit:$=>q($),onCancel:()=>T(!1)})}):null,c==="cockpit"?i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:i.jsx(Oee,{cockpit:f,error:b,loading:g,onOpenFile:D,pr:e})}):s?i.jsx(sm,{className:"flex-1",label:l("git.diff.loading")}):n?i.jsx("div",{className:"p-4 text-[12px] text-red-500",children:n}):z.length?i.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1",children:[i.jsx(Pee,{files:z,onAsk:($,me)=>q(me,$),onSelect:j,selected:G?.path??null}),i.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:G?i.jsx(Ou,{diff:G.diff}):null})]}):i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:l("github.pr.noDiff")}),C?i.jsx(Ol,{confirmLabel:M?i.jsxs(i.Fragment,{children:[i.jsx(tm,{size:"sm"})," ",l("github.pr.merging")]}):l("github.pr.squashMerge"),icon:i.jsx(sf,{}),loading:M,message:i.jsxs(i.Fragment,{children:[l("github.pr.confirmPre"),i.jsxs("span",{className:"font-mono",children:["#",e.number]})," ",i.jsx("span",{className:"font-medium text-foreground",children:e.title}),l("github.pr.confirmInto"),i.jsx("span",{className:"font-mono",children:e.base.ref}),l("github.pr.confirmQ")]}),onCancel:()=>N(!1),onConfirm:()=>{I()},title:l("github.pr.squashMerge"),tone:"success"}):null]})}function Oee({pr:e,cockpit:t,loading:s,error:n,onOpenFile:a}){const l=ee(),[c,d]=x.useState(!1),f=t?.pr??e,h=t?.files??[],g=t?.reviews??[],p=t?.comments??[],b=t?.checks??null,v=b?.runs.filter(_=>_.conclusion==="failure"||_.conclusion==="timed_out"||_.conclusion==="cancelled")??[];return i.jsxs("div",{className:"space-y-3 p-4",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 text-[12px]",children:[i.jsx(Iee,{pr:f}),i.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md border border-border bg-muted/40 px-2 py-1 font-mono text-[11px]",children:[i.jsx(Pn,{className:"size-3 shrink-0 text-muted-foreground"}),f.base.ref,i.jsx(Eu,{className:"size-3 shrink-0 text-muted-foreground"}),f.head.ref]}),i.jsxs("span",{className:"inline-flex items-center gap-1 text-muted-foreground",children:[i.jsx(m8,{className:"size-3 shrink-0"}),f.user.login]}),i.jsxs("span",{className:"inline-flex items-center gap-1 text-muted-foreground",children:[i.jsx(dM,{className:"size-3 shrink-0"}),new Date(f.created_at).toLocaleDateString()]})]}),n?i.jsx("div",{className:"rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-[12px] text-red-500",children:n}):null,s?i.jsx(sm,{className:"justify-start",label:l("github.pr.loadingCockpit")}):null,i.jsxs("div",{className:"grid gap-2 md:grid-cols-4",children:[i.jsx(Oh,{title:l("github.pr.mergeReadiness"),value:l(kT(f,b)),tone:zee(f,b)}),i.jsx(Oh,{title:l("github.pr.reviewStateTitle"),value:l(CT(g)),tone:Bee(g)}),i.jsx(Oh,{title:l("github.pr.checks"),value:b?l("github.pr.checksValue",{state:b.state,count:b.totalCount}):l("github.pr.unknown"),tone:b?.state==="success"?"success":b?.state==="failure"||b?.state==="error"?"danger":"muted"}),i.jsx(Oh,{title:l("github.pr.changedFiles"),value:String(h.length),tone:"muted"})]}),v.length>0?i.jsxs("section",{className:"rounded-md border border-red-500/25 bg-red-500/10 px-3 py-2",children:[i.jsx("div",{className:"mb-1 text-[11px] font-medium text-red-500",children:l("github.pr.failingChecks")}),i.jsx("div",{className:"flex flex-wrap gap-2",children:v.slice(0,4).map(_=>i.jsxs("a",{className:"inline-flex items-center gap-1 text-[11px] text-red-500 underline-offset-2 hover:underline",href:_.html_url,rel:"noopener noreferrer",target:"_blank",children:[i.jsx(Ix,{className:"size-3"}),l("github.pr.openFailingCheck",{name:_.name})]},_.id))})]}):null,i.jsxs("section",{className:"rounded-md border border-border bg-muted/25 p-3",children:[i.jsxs("button",{className:"flex w-full items-center gap-2 text-[12px] font-medium",onClick:()=>d(_=>!_),type:"button",children:[c?i.jsx(hn,{className:"size-3.5 text-muted-foreground"}):i.jsx(_n,{className:"size-3.5 text-muted-foreground"}),i.jsx($x,{className:"size-3.5 text-muted-foreground"}),l("github.pr.changedFiles"),h.length?i.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:["(",h.length,")"]}):null]}),c?h.length?i.jsx("ul",{className:"mt-2 divide-y divide-border",children:h.slice(0,12).map(_=>i.jsx("li",{children:i.jsxs("button",{className:"flex w-full items-center gap-2 py-1.5 text-left text-[12px] transition-colors hover:text-foreground",onClick:()=>a(_.path),title:l("github.pr.viewDiffTitle",{path:_.path}),type:"button",children:[i.jsx("span",{className:"w-16 shrink-0 font-mono text-[10px] uppercase text-muted-foreground",children:_.status}),i.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:_.path}),i.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-emerald-600",children:["+",_.additions]}),i.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-red-500",children:["-",_.deletions]})]})},_.path))}):i.jsx("p",{className:"mt-2 text-[12px] text-muted-foreground",children:l("github.pr.noFileMeta")}):null]}),i.jsxs("section",{className:"rounded-md border border-border bg-muted/25 p-3",children:[i.jsxs("div",{className:"mb-2 flex items-center gap-2 text-[12px] font-medium",children:[i.jsx(oD,{className:"size-3.5 text-muted-foreground"}),l("github.pr.reviewStateTitle")]}),g.length||p.length?i.jsxs("div",{className:"space-y-2",children:[g.slice(-4).map(_=>i.jsx(IN,{href:_.html_url,meta:`${_.user.login} - ${_.state.toLowerCase()}`,text:_.body||l("github.pr.noReviewSummary")},`review:${_.id}`)),p.slice(-4).map(_=>i.jsx(IN,{href:_.html_url,meta:l("github.pr.reviewMetaComment",{login:_.user.login}),text:_.body},`comment:${_.id}`))]}):i.jsx("p",{className:"text-[12px] text-muted-foreground",children:l("github.pr.noReviews")})]}),f.body?i.jsx(ST,{body:f.body}):i.jsx("p",{className:"text-[12px] italic text-muted-foreground",children:l("github.noDescription")})]})}function Pee({files:e,selected:t,onSelect:s,onAsk:n}){const a=ee(),[l,c]=x.useState(null);return i.jsx("div",{className:"w-44 shrink-0 overflow-y-auto border-r border-border bg-card/60",children:i.jsx("ul",{className:"py-1",children:e.map(d=>i.jsxs("li",{className:"group flex flex-col",children:[i.jsxs("div",{className:oe("flex items-center transition-colors",d.path===t?"bg-muted":"hover:bg-muted/60"),children:[i.jsxs("button",{className:oe("flex min-w-0 flex-1 items-center gap-1.5 px-2.5 py-1.5 text-left text-[11px]",d.path===t?"text-foreground":"text-muted-foreground group-hover:text-foreground"),onClick:()=>s(d.path),title:d.path,type:"button",children:[i.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:zf(d.path)}),i.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-emerald-600",children:["+",d.additions]}),i.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-red-500",children:["-",d.deletions]})]}),i.jsx(ir,{className:oe("mr-1 shrink-0",l===d.path&&"opacity-100"),label:a("github.pr.askFileLabel",{name:zf(d.path)}),onAsk:()=>c(f=>f===d.path?null:d.path)})]}),l===d.path?i.jsx("div",{className:"px-2 pb-1.5 pt-0.5",children:i.jsx(Ir,{placeholder:a("github.pr.askFilePlaceholder"),onSubmit:f=>{c(null),n(d.path,f)},onCancel:()=>c(null)})}):null]},d.path))})})}function zf(e){const t=e.split("/");return t[t.length-1]||e}function Oh({title:e,value:t,tone:s}){const n=s==="success"?"bg-emerald-500":s==="warning"?"bg-amber-500":s==="danger"?"bg-red-500":"bg-muted-foreground";return i.jsxs("div",{className:"rounded-md border border-border bg-card px-3 py-2",children:[i.jsx("div",{className:"text-[10px] uppercase text-muted-foreground",children:e}),i.jsxs("div",{className:"mt-1 flex items-center gap-1.5 text-[12px] font-medium",children:[i.jsx("span",{className:`size-1.5 rounded-full ${n}`}),t]})]})}function IN({meta:e,text:t,href:s}){return i.jsxs("a",{className:"block rounded border border-border bg-card px-2.5 py-2 text-[12px] transition-colors hover:bg-muted/60",href:s,rel:"noopener noreferrer",target:"_blank",children:[i.jsxs("span",{className:"mb-1 flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[i.jsx(ja,{className:"size-3"}),e]}),i.jsx("span",{className:"line-clamp-2 whitespace-pre-wrap",children:t})]})}function kT(e,t){return e.state==="merged"?"github.pr.readiness.merged":e.state==="closed"?"github.pr.readiness.closed":e.draft?"github.pr.readiness.draft":e.mergeable===!1?"github.pr.readiness.blocked":t?.state==="failure"||t?.state==="error"?"github.pr.readiness.checksFailing":t?.state==="pending"?"github.pr.readiness.checksPending":e.mergeable===!0?"github.pr.readiness.ready":"github.pr.unknown"}function zee(e,t){const s=kT(e,t);return s==="github.pr.readiness.ready"?"success":s==="github.pr.readiness.blocked"||s==="github.pr.readiness.checksFailing"?"danger":s==="github.pr.readiness.draft"||s==="github.pr.readiness.checksPending"?"warning":"muted"}function CT(e){return e.some(t=>t.state==="CHANGES_REQUESTED")?"github.pr.review.changesRequested":e.some(t=>t.state==="APPROVED")?"github.pr.review.approved":e.some(t=>t.state==="COMMENTED")?"github.pr.review.commented":"github.pr.review.none"}function Bee(e){const t=CT(e);return t==="github.pr.review.approved"?"success":t==="github.pr.review.changesRequested"?"danger":t==="github.pr.review.commented"?"warning":"muted"}function Iee({pr:e}){const t=ee(),{labelKey:s,dot:n,kind:a}=e.state==="merged"?{labelKey:"github.prState.merged",dot:"bg-violet-500",kind:"merged"}:e.state==="closed"?{labelKey:"github.prState.closed",dot:"bg-red-500",kind:"other"}:e.draft?{labelKey:"github.prState.draft",dot:"bg-muted-foreground",kind:"other"}:{labelKey:"github.prState.open",dot:"bg-emerald-500",kind:"open"};return i.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground",children:[i.jsx("span",{className:`size-1.5 rounded-full ${n}`}),a==="merged"?i.jsx(sf,{className:"size-3"}):a==="open"?i.jsx(qf,{className:"size-3"}):i.jsx(kl,{className:"size-3"}),t(s)]})}function NT({label:e}){return i.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 text-[10px] font-medium text-muted-foreground",title:e.name,children:[i.jsx("span",{className:"size-2 shrink-0 rounded-sm",style:{backgroundColor:`#${e.color}`}}),i.jsx("span",{className:"truncate",children:e.name})]})}function Hee({issues:e,loading:t,loadingMore:s,hasMore:n,error:a,selectedNumber:l,onSelect:c,onLoadMore:d}){const f=ee();return t&&e.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.issues.loading")}):a?i.jsx("div",{className:"p-4 text-[12px] text-red-500",children:a}):e.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.issues.empty")}):i.jsxs(i.Fragment,{children:[i.jsx("ul",{className:"divide-y divide-border",children:e.map(h=>i.jsx("li",{children:i.jsxs("button",{className:`flex w-full items-start gap-3 px-3 py-2.5 text-left transition-colors hover:bg-muted/60 ${l===h.number?"bg-muted":""}`,onClick:()=>c(h.number),type:"button",children:[i.jsx(kM,{className:`mt-0.5 size-4 shrink-0 ${h.state==="open"?"text-emerald-500":"text-red-500"}`}),i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"block truncate text-[13px] font-medium",children:h.title}),i.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",h.number," · ",h.user.login," · ",f("github.issues.commentsCount",{count:h.comments})]})]}),h.labels.length>0?i.jsx("span",{className:"flex max-w-40 shrink-0 flex-wrap justify-end gap-x-2 gap-y-0.5",children:h.labels.slice(0,3).map(g=>i.jsx(NT,{label:g},g.name))}):null]})},h.number))}),i.jsx(c1,{hasMore:n,loading:s,onLoadMore:d})]})}const Ph=6,$ee=6,Fee=8;function Uee(e,t,s,n){const a=Math.max(0,Math.min($ee,e/2,t/2)),l=Math.max(0,Math.min(Fee,s-a,n-a));return[`M ${a} 0`,`H ${e-a}`,`A ${a} ${a} 0 0 1 ${e} ${a}`,`V ${t-n-a}`,`A ${a} ${a} 0 0 1 ${e-a} ${t-n}`,`H ${e-s+l}`,`A ${l} ${l} 0 0 0 ${e-s} ${t-n+l}`,`V ${t-a}`,`A ${a} ${a} 0 0 1 ${e-s-a} ${t}`,`H ${a}`,`A ${a} ${a} 0 0 1 0 ${t-a}`,`V ${a}`,`A ${a} ${a} 0 0 1 ${a} 0`,"Z"].join(" ")}function qee({value:e,onChange:t,placeholder:s,rows:n=3,action:a}){const l=ee(),c=x.useRef(null),d=x.useRef(null),[f,h]=x.useState(null),[g,p]=x.useState({w:0,h:0});x.useLayoutEffect(()=>{const v=c.current,_=d.current;if(!v||!_)return;const S=()=>{h({w:v.clientWidth,h:v.clientHeight}),p({w:_.offsetWidth+Ph*2,h:_.offsetHeight+Ph*2})};S();const C=new ResizeObserver(S);return C.observe(v),C.observe(_),()=>C.disconnect()},[]);const b=f&&g.w&&g.h?Uee(f.w,f.h,g.w,g.h):null;return i.jsxs("div",{className:"relative",ref:c,children:[i.jsx("textarea",{className:"peer block w-full resize-none bg-background px-3 pt-2 font-mono text-[12px] placeholder:text-muted-foreground focus:outline-none",onChange:v=>t(v.target.value),placeholder:s,rows:n,style:{clipPath:b?`path('${b}')`:void 0,paddingBottom:g.h||44},value:e}),f&&b?i.jsxs("svg",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 overflow-visible text-border transition-colors peer-focus:text-foreground/40",fill:"none",height:f.h,viewBox:`0 0 ${f.w} ${f.h}`,width:f.w,children:[i.jsx("title",{children:l("github.commentBorderTitle")}),i.jsx("path",{d:b,stroke:"currentColor",strokeWidth:1})]}):null,i.jsx("div",{className:"absolute",ref:d,style:{bottom:Ph,right:Ph},children:a})]})}function Gee({issue:e,comments:t,commentsLoading:s,commentError:n,submitting:a,onAddComment:l}){const c=ee(),[d,f]=x.useState(""),[h,g]=x.useState(!1),{sendToAgent:p}=Ot(),{isPending:b,runOperation:v}=si(),_=e?`github:issue:${e.number}:comment`:"",S=a||(_?b(_):!1);x.useEffect(()=>{g(!1)},[e?.number]);function C(A){e&&(g(!1),p({prompt:zF(e,A),source:{type:"github-issue",label:`Issue #${e.number}`},label:`Issue #${e.number}: ${A}`}))}if(!e)return i.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:c("github.issue.selectPrompt")});async function N(A){A.preventDefault();const j=d.trim();j&&(await v({key:_,label:c("github.issue.postingOperation",{number:e.number})},()=>l(j)),f(""))}return i.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[i.jsxs("div",{className:"group flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[i.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-semibold",children:e.title}),i.jsx(ir,{className:oe("shrink-0",h&&"opacity-100"),label:c("github.issue.askLabel",{number:e.number}),onAsk:()=>g(A=>!A)}),i.jsx("a",{"aria-label":c("github.openOnGithub"),className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:e.html_url,rel:"noopener noreferrer",target:"_blank",children:i.jsx(ja,{className:"size-3.5"})})]}),h?i.jsx("div",{className:"shrink-0 border-b border-border px-3 py-1.5",children:i.jsx(Ir,{placeholder:c("github.issue.askPlaceholder"),onSubmit:C,onCancel:()=>g(!1)})}):null,i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:i.jsxs("div",{className:"space-y-3 p-4",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[12px]",children:[i.jsxs("span",{className:"text-[11px]",children:[i.jsx("span",{className:"text-muted-foreground",children:c("github.issue.author")}),i.jsx("span",{className:"font-medium",children:e.user.login})]}),i.jsxs("span",{className:"text-[11px]",children:[i.jsx("span",{className:"text-muted-foreground",children:c("github.issue.opened")}),i.jsx("span",{className:"font-medium",children:new Date(e.created_at).toLocaleDateString()})]}),e.labels.map(A=>i.jsx(NT,{label:A},A.name))]}),e.body?i.jsx(ST,{body:e.body}):i.jsx("p",{className:"text-[12px] text-muted-foreground italic",children:c("github.noDescription")}),s?i.jsx(sm,{className:"justify-start",label:c("github.issue.loadingComments")}):i.jsx("div",{className:"space-y-2",children:t.map(A=>i.jsxs("div",{className:"rounded-md border border-border bg-muted/20 p-3",children:[i.jsxs("div",{className:"mb-1 flex items-baseline gap-2",children:[i.jsx("span",{className:"text-[11px] font-semibold",children:A.user.login}),i.jsx("span",{className:"text-[10px] text-muted-foreground",children:new Date(A.created_at).toLocaleDateString()})]}),i.jsx(r1,{content:A.body})]},A.id))})]})}),i.jsx("div",{className:"shrink-0 border-t border-border p-3",children:i.jsxs("form",{className:"flex flex-col gap-2",onSubmit:A=>{N(A)},children:[i.jsx(qee,{action:i.jsx(Q,{disabled:!d.trim(),loading:S,loadingLabel:c("github.issue.posting"),size:"sm",type:"submit",children:c("github.issue.comment")}),onChange:f,placeholder:c("github.issue.addComment"),value:d}),n?i.jsx(tt,{variant:"destructive",children:n}):null]})})]})}const HN=30,Vee=4e3;function Wee(e){return e.status==="in_progress"||e.status==="queued"}function $N(e){return e.map(t=>`${t.id}:${t.status}:${t.conclusion}`).join("|")}function FN(e){return e.map(t=>`${t.id}:${t.status}:${t.conclusion}:`+t.steps.map(s=>`${s.number}:${s.status}:${s.conclusion}`).join(",")).join("|")}function Kee(e,t){if(e.length===0)return t;const s=new Map(t.map(c=>[c.id,c])),n=new Set(e.map(c=>c.id)),a=t.filter(c=>!n.has(c.id)),l=e.map(c=>s.get(c.id)??c);return[...a,...l]}function Yee(e){const[t,s]=x.useState([]),[n,a]=x.useState(null),[l,c]=x.useState([]),[d,f]=x.useState(!0),[h,g]=x.useState(!1),[p,b]=x.useState(!1),[v,_]=x.useState(1),[S,C]=x.useState(!1),[N,A]=x.useState(null),[j,E]=x.useState(null);function T(){let F=!0;return f(!0),A(null),_(1),zh(e,1).then(M=>{F&&(s(M),b(M.length===HN))}).catch(M=>{F&&A(M instanceof Error?M.message:String(M))}).finally(()=>{F&&f(!1)}),()=>{F=!1}}function L(){if(h||!p)return;const F=v+1;g(!0),zh(e,F).then(M=>{s(z=>{const G=new Set(z.map(D=>D.id));return[...z,...M.filter(D=>!G.has(D.id))]}),b(M.length===HN),_(F)}).catch(M=>A(M instanceof Error?M.message:String(M))).finally(()=>g(!1))}const H=x.useCallback(()=>{zh(e,1).then(F=>s(M=>{const z=Kee(M,F);return $N(M)===$N(z)?M:z})).catch(()=>{}),n&&fS(n).then(F=>c(M=>FN(M)===FN(F)?M:F)).catch(()=>{})},[e,n]);x.useEffect(T,[e]),x.useEffect(()=>{a(F=>F&&t.some(M=>M.id===F)?F:t[0]?.id??null)},[t]),x.useEffect(()=>{if(!n){c([]);return}let F=!0;return C(!0),E(null),fS(n).then(M=>{F&&c(M)}).catch(M=>{F&&E(M instanceof Error?M.message:String(M))}).finally(()=>{F&&C(!1)}),()=>{F=!1}},[n]);const P=t.some(Wee);return x.useEffect(()=>{if(!P)return;const F=window.setInterval(()=>{document.visibilityState==="visible"&&H()},Vee);return()=>window.clearInterval(F)},[P,H]),{runs:t,selectedRunId:n,jobs:l,loading:d,loadingMore:h,hasMore:p,jobsLoading:S,error:N,jobsError:j,loadMore:L,refresh:T,syncLatest:H,setSelectedRunId:a}}function ET(e){return e.conclusion==="failure"||e.conclusion==="timed_out"||e.conclusion==="cancelled"}function Xee({branch:e,onClearBranch:t}){const{runs:s,selectedRunId:n,jobs:a,loading:l,loadingMore:c,hasMore:d,jobsLoading:f,error:h,jobsError:g,loadMore:p,refresh:b,syncLatest:v,setSelectedRunId:_}=Yee(e),S=ee();Dl(v);const C=s.find(T=>T.id===n)??null,{sendToAgent:N}=Ot(),[A,j]=x.useState(null);function E(T,L){j(null),N({prompt:BF(T,L),source:{type:"github-run",label:S("github.actions.runLabel",{number:T.run_number})},label:S("github.actions.runInputLabel",{number:T.run_number,input:L??S("github.actions.fixDefault")})})}return i.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[i.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("h2",{className:"text-[13px] font-semibold",children:S("github.actions.title")}),e?i.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:[i.jsx("span",{className:"shrink-0",children:S("github.actions.filteredTo")}),i.jsx("span",{className:"min-w-0 truncate font-mono",children:e}),t?i.jsx("button",{"aria-label":S("github.actions.clearFilter"),className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:t,title:S("github.actions.clearFilter"),type:"button",children:i.jsx(Vt,{className:"size-3"})}):null]}):null]}),i.jsxs(Q,{disabled:l,onClick:()=>{b()},size:"sm",type:"button",variant:"outline",children:[i.jsx(Pr,{className:`mr-1 size-3.5 ${l?"animate-spin":""}`}),S("common.refresh")]})]}),i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:h?i.jsx("div",{className:"p-4 text-[12px] text-red-500",children:h}):l&&s.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:S("github.actions.loadingRuns")}):s.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:S("github.actions.noRuns")}):i.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(280px,380px)_minmax(0,1fr)] divide-x divide-border",children:[i.jsxs("div",{className:"min-h-0 overflow-auto",children:[i.jsx("ul",{className:"divide-y divide-border",children:s.map(T=>i.jsxs("li",{className:"group flex flex-col",children:[i.jsxs("div",{className:`flex items-center transition-colors hover:bg-muted/60 ${T.id===n?"bg-muted/70":""}`,children:[i.jsxs("button",{className:"flex min-w-0 flex-1 items-center gap-3 px-3 py-2.5 text-left",onClick:()=>_(T.id),type:"button",children:[i.jsx(Zee,{run:T}),i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"block truncate text-[13px] font-medium",children:T.name}),i.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",T.run_number," · ",T.head_branch," · ",T.event," ·"," ",i.jsx("span",{title:new Date(T.created_at).toLocaleString(),children:aj(T.created_at)})]})]}),i.jsx(Qee,{run:T})]}),ET(T)?i.jsx(ir,{className:`mr-2 shrink-0 ${A===T.id?"opacity-100":""}`,label:S("github.actions.fixRunAi",{number:T.run_number}),onAsk:()=>j(L=>L===T.id?null:T.id)}):null]}),A===T.id?i.jsx("div",{className:"px-3 pb-2 pt-0.5",children:i.jsx(Ir,{onCancel:()=>j(null),onSubmit:L=>E(T,L),placeholder:S("github.actions.askPlaceholder")})}):null]},T.id))}),i.jsx(c1,{hasMore:d,loading:c,onLoadMore:p})]}),i.jsx(Jee,{error:g,jobs:a,loading:f,onFix:T=>E(T),run:C})]})})]})}function Zee({run:e}){return e.status==="in_progress"||e.status==="queued"?i.jsx(kl,{className:"size-4 shrink-0 animate-pulse text-amber-400"}):e.conclusion==="success"?i.jsx(qf,{className:"size-4 shrink-0 text-emerald-500"}):e.conclusion==="failure"||e.conclusion==="timed_out"?i.jsx(Ix,{className:"size-4 shrink-0 text-red-500"}):i.jsx(kl,{className:"size-4 shrink-0 text-zinc-400"})}function Qee({run:e}){const t=e.status==="completed"?e.conclusion??"completed":e.status,s=t==="success"?"bg-emerald-500":t==="failure"||t==="timed_out"?"bg-red-500":t==="in_progress"||t==="queued"?"bg-amber-500":"bg-muted-foreground";return i.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[i.jsx("span",{className:`size-1.5 rounded-full ${s}`}),t]})}function Jee({run:e,jobs:t,loading:s,error:n,onFix:a}){const l=ee();return e?i.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[i.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"block truncate text-[13px] font-semibold",children:e.name}),i.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["Run #",e.run_number," · ",e.head_branch," · ",e.head_sha.slice(0,7)]})]}),ET(e)?i.jsxs(Q,{className:"shrink-0 gap-1",onClick:()=>a(e),size:"sm",title:l("github.actions.fixTitle"),type:"button",variant:"outline",children:[i.jsx(Xt,{className:"size-3.5"}),l("github.actions.fixWithAi")]}):null,i.jsx("a",{"aria-label":l("github.actions.openRun"),className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:e.html_url,rel:"noopener noreferrer",target:"_blank",title:l("github.actions.openRun"),children:i.jsx(ja,{className:"size-3.5"})})]}),i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:n?i.jsx("div",{className:"p-4 text-[12px] text-red-500",children:n}):s?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:l("github.actions.loadingJobs")}):t.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:l("github.actions.noJobs")}):i.jsx("ul",{className:"divide-y divide-border",children:t.map(c=>i.jsxs("li",{className:"px-3 py-3",children:[i.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[i.jsx(UN,{item:c}),i.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-medium",children:c.name}),i.jsx("span",{className:"shrink-0 font-mono text-[11px] text-muted-foreground",children:qN(c.started_at,c.completed_at)}),i.jsx("a",{"aria-label":l("github.actions.openJobAria",{name:c.name}),className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:c.html_url,rel:"noopener noreferrer",target:"_blank",title:l("github.actions.openJob"),children:i.jsx(ja,{className:"size-3.5"})})]}),c.steps.length?i.jsx("ol",{className:"space-y-1.5 pl-6",children:c.steps.map(d=>i.jsxs("li",{className:"flex items-center gap-2 text-[12px]",children:[i.jsx(UN,{item:d}),i.jsx("span",{className:"min-w-0 flex-1 truncate",children:d.name}),i.jsx("span",{className:"shrink-0 font-mono text-[11px] text-muted-foreground",children:qN(d.started_at,d.completed_at)})]},`${c.id}:${d.number}`))}):i.jsx("p",{className:"pl-6 text-[12px] text-muted-foreground",children:l("github.actions.noSteps")})]},c.id))})})]}):i.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:l("github.actions.selectRun")})}function UN({item:e}){return e.status==="in_progress"||e.status==="queued"?i.jsx(kl,{className:"size-3.5 shrink-0 animate-pulse text-amber-400"}):e.conclusion==="success"||e.conclusion==="skipped"?i.jsx(qf,{className:"size-3.5 shrink-0 text-emerald-500"}):e.conclusion==="failure"||e.conclusion==="timed_out"||e.conclusion==="cancelled"?i.jsx(Ix,{className:"size-3.5 shrink-0 text-red-500"}):i.jsx(kl,{className:"size-3.5 shrink-0 text-zinc-400"})}function qN(e,t){if(!e)return"-";const s=Date.parse(e),n=t?Date.parse(t):Date.now();if(!Number.isFinite(s)||!Number.isFinite(n)||n<s)return"-";const a=Math.max(0,Math.round((n-s)/1e3));if(a<60)return`${a}s`;const l=Math.floor(a/60),c=a%60;return c?`${l}m ${c}s`:`${l}m`}function ete({onCreatePR:e,onViewRuns:t}){const s=ee(),[n,a]=x.useState(null),[l,c]=x.useState(!0),[d,f]=x.useState(null);function h(){let p=!0;return c(!0),f(null),y7().then(b=>{p&&a(b)}).catch(b=>{p&&f(b instanceof Error?b.message:String(b))}).finally(()=>{p&&c(!1)}),()=>{p=!1}}x.useEffect(h,[]),Dl(()=>{h()});const g=x.useMemo(()=>[...n?.branches??[]].sort((b,v)=>{const _=VN(b,n),S=VN(v,n);return _-S||b.name.localeCompare(v.name)}),[n]);return i.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[i.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("h2",{className:"text-[13px] font-semibold",children:s("github.tab.branches")}),i.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:n?.repository.full_name??s("github.selectedRepo")})]}),i.jsxs(Q,{disabled:l,onClick:()=>{h()},size:"sm",type:"button",variant:"outline",children:[i.jsx(Pr,{className:`mr-1 size-3.5 ${l?"animate-spin":""}`}),s("common.refresh")]})]}),i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:d?i.jsx("div",{className:"p-4 text-[12px] text-red-500",children:d}):l&&!n?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:s("github.branches.loading")}):g.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:s("github.branches.empty")}):i.jsx("ul",{className:"divide-y divide-border",children:g.map(p=>i.jsx(tte,{branch:p,currentBranch:n?.currentBranch??null,defaultBranch:n?.defaultBranch??null,onCreatePR:e,onViewRuns:t},p.name))})})]})}function tte({branch:e,defaultBranch:t,currentBranch:s,onCreatePR:n,onViewRuns:a}){const l=ee(),c=e.name===t,d=e.name===s,f=!c;return i.jsxs("li",{className:"flex flex-wrap items-center gap-3 px-3 py-2.5",children:[i.jsx(Pn,{className:"size-4 shrink-0 text-muted-foreground"}),i.jsxs("div",{className:"min-w-48 flex-1",children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i.jsx("span",{className:"truncate font-mono text-[13px] font-medium",children:e.name}),c?i.jsx(GN,{label:l("github.branches.default"),tone:"success"}):null,d?i.jsx(GN,{label:l("github.branches.current"),tone:"warning"}):null,e.protected?i.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground",children:[i.jsx(bE,{className:"size-3"}),l("github.branches.protected")]}):null]}),i.jsx("div",{className:"mt-0.5 font-mono text-[11px] text-muted-foreground",children:e.commit.sha.slice(0,7)})]}),i.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[i.jsxs(Q,{onClick:()=>a(e.name),size:"sm",title:l("github.branches.viewRunsTitle",{name:e.name}),type:"button",variant:"outline",children:[i.jsx(NM,{className:"size-3.5"}),l("github.branches.viewRuns")]}),i.jsxs(Q,{disabled:!f,onClick:()=>n(e.name),size:"sm",title:f?l("github.branches.openPrTitle",{name:e.name}):l("github.branches.defaultNoPr"),type:"button",variant:"outline",children:[i.jsx(cE,{className:"size-3.5"}),l("github.branches.openPr")]})]})]})}function GN({label:e,tone:t}){const s=t==="success"?"bg-emerald-500":"bg-amber-500";return i.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground",children:[i.jsx("span",{className:`size-1.5 rounded-full ${s}`}),e]})}function VN(e,t){return e.name===t?.currentBranch?0:e.name===t?.defaultBranch?1:e.protected?2:3}function ste(){const e=ee(),t=Eee();let s;return t.loading||t.status==="checking"?s=i.jsx(sm,{fill:!0,label:e("common.loading")}):t.status==="not_configured"?s=i.jsx(wT,{deviceFlowAvailable:t.deviceFlowAvailable,onSaved:t.refresh}):t.status==="auth_error"||t.status==="connection_error"?s=i.jsx(nte,{token:t}):s=i.jsx(ite,{token:t}),i.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:s})}function nte({token:e}){const t=ee(),[s,n]=x.useState(null);if(s)return i.jsx(wT,{deviceFlowAvailable:e.deviceFlowAvailable,initialMode:s,onSaved:e.refresh});const a=e.status==="auth_error";return i.jsx("div",{className:"flex h-full items-center justify-center p-8",children:i.jsxs("div",{className:"w-full max-w-lg space-y-4 rounded-md border border-border bg-card p-5",children:[i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx(pm,{className:"size-5"}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("h2",{className:"text-sm font-semibold",children:t("github.connFailed")}),i.jsx("p",{className:"text-[12px] text-muted-foreground",children:t(a?"github.tokenRejected":"github.cantValidate")})]}),i.jsx(jT,{label:t(a?"github.needsRelogin":"github.connProblem"),tone:a?"danger":"warning"})]}),e.error?i.jsx(tt,{variant:"destructive",children:e.error}):null,i.jsxs("div",{className:"flex flex-wrap gap-2",children:[i.jsxs(Q,{onClick:e.refresh,type:"button",variant:a?"outline":"default",children:[i.jsx(Pr,{}),t("common.refresh")]}),i.jsx(Q,{onClick:()=>n(e.deviceFlowAvailable?"device-pending":"pat"),type:"button",variant:a?"default":"outline",children:t("github.reconnectGithub")}),i.jsx(Q,{onClick:()=>n("pat"),type:"button",variant:"outline",children:t("github.useToken")})]})]})})}function ite({token:e}){const t=ee(),[s,n]=_l("github:tab","prs"),[a,l]=_l("github:pr-state","open"),[c,d]=_l("github:issue-state","open"),[f,h]=x.useState(null),[g,p]=x.useState(null),[b,v]=x.useState(null),{isPending:_,runOperation:S}=si(),C=_("github:disconnect"),N=jee(a),A=Aee(c);Dl(()=>{s==="prs"?N.refresh():s==="issues"&&A.refresh()});const j=L=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${L?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`,E=L=>`rounded px-2 py-0.5 text-[10px] font-medium transition-colors ${L?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`;async function T(){v(null);try{await S({errorMessage:L=>L instanceof Error?L.message:String(L),key:"github:disconnect",label:t("github.disconnecting")},async()=>{await x7("github.com"),e.refresh()})}catch(L){v(L instanceof Error?L.message:String(L))}}return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border bg-card/95 px-3 py-1",children:[i.jsx("button",{className:j(s==="prs"),onClick:()=>n("prs"),type:"button",children:t("github.tab.prs")}),i.jsx("button",{className:j(s==="issues"),onClick:()=>n("issues"),type:"button",children:t("github.tab.issues")}),i.jsx("button",{className:j(s==="branches"),onClick:()=>n("branches"),type:"button",children:t("github.tab.branches")}),i.jsx("button",{className:j(s==="actions"),onClick:()=>n("actions"),type:"button",children:t("github.tab.actions")}),i.jsxs("div",{className:"ml-auto flex min-w-0 items-center gap-2",children:[i.jsx(rte,{token:e}),i.jsxs(Q,{onClick:e.refresh,size:"sm",title:t("github.recheckTitle"),type:"button",variant:"outline",children:[i.jsx(Pr,{}),t("github.reconnect")]}),i.jsx(Q,{loading:C,loadingLabel:t("github.disconnecting"),onClick:()=>{T()},size:"sm",type:"button",variant:"outline",children:t("github.disconnect")})]}),s==="prs"?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-muted/60 p-0.5",children:[i.jsx("button",{className:E(a==="open"),onClick:()=>l("open"),type:"button",children:t("github.open")}),i.jsx("button",{className:E(a==="closed"),onClick:()=>l("closed"),type:"button",children:t("github.closed")})]}),i.jsx(Q,{onClick:()=>h(""),size:"sm",type:"button",variant:"outline",children:t("github.newPr")})]}):s==="issues"?i.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-muted/60 p-0.5",children:[i.jsx("button",{className:E(c==="open"),onClick:()=>d("open"),type:"button",children:t("github.open")}),i.jsx("button",{className:E(c==="closed"),onClick:()=>d("closed"),type:"button",children:t("github.closed")})]}):null]}),b?i.jsx(tt,{variant:"destructive",className:"m-3",children:b}):null,f!==null?i.jsx(ate,{initialHead:f,onCreated:L=>{h(null),n("prs"),N.setSelectedNumber(L.number),N.refresh()},onCancel:()=>h(null)}):i.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s==="prs"?i.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(0,1fr)_minmax(0,2fr)] divide-x divide-border",children:[i.jsx("div",{className:"min-h-0 overflow-auto",children:i.jsx(Mee,{error:N.error,hasMore:N.hasMore,loading:N.loading,loadingMore:N.loadingMore,onLoadMore:N.loadMore,onSelect:N.setSelectedNumber,prs:N.prs,selectedNumber:N.selectedNumber})}),i.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden",children:i.jsx(Lee,{diff:N.diff,diffError:N.diffError,diffLoading:N.diffLoading,onMerged:()=>N.refresh(),pr:N.selectedPR})})]}):s==="issues"?i.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(0,1fr)_minmax(0,2fr)] divide-x divide-border",children:[i.jsx("div",{className:"min-h-0 overflow-auto",children:i.jsx(Hee,{error:A.error,hasMore:A.hasMore,issues:A.issues,loading:A.loading,loadingMore:A.loadingMore,onLoadMore:A.loadMore,onSelect:A.setSelectedNumber,selectedNumber:A.selectedNumber})}),i.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden",children:i.jsx(Gee,{commentError:A.commentError,comments:A.comments,commentsLoading:A.commentsLoading,issue:A.selectedIssue,onAddComment:A.addComment,submitting:A.submitting})})]}):s==="branches"?i.jsx(ete,{onCreatePR:L=>h(L),onViewRuns:L=>{p(L),n("actions")}}):i.jsx(Xee,{branch:g??void 0,onClearBranch:()=>p(null)})})]})}function rte({token:e}){const t=ee(),s=e.info?.repository?.full_name??(e.info?.user?`@${e.info.user.login}`:"GitHub");return i.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 border-r border-border pr-2",children:[i.jsx(pm,{className:"size-4 shrink-0 text-foreground"}),i.jsx(jT,{label:t("github.connected"),tone:"success"}),i.jsx("span",{className:"max-w-48 truncate font-mono text-[10px] text-muted-foreground",children:s})]})}function jT({label:e,tone:t}){const s=t==="success"?"bg-emerald-500":t==="danger"?"bg-red-500":"bg-amber-500";return i.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-[11px] font-medium text-muted-foreground",children:[i.jsx("span",{className:`size-1.5 rounded-full ${s}`}),e]})}function ate({initialHead:e,onCreated:t,onCancel:s}){const n=ee(),[a,l]=x.useState(""),[c,d]=x.useState(""),[f,h]=x.useState(""),[g,p]=x.useState("main"),[b,v]=x.useState(!1),[_,S]=x.useState(null),[C,N]=x.useState(!0),[A,j]=x.useState(!1),[E,T]=x.useState(null);x.useEffect(()=>{let F=!0;return N(!0),T(null),k7().then(M=>{F&&(S(M),l(M.title),d(M.body),h(e||M.head),p(M.base||M.suggestedBase||"main"),v(M.draft))}).catch(M=>{F&&T(M instanceof Error?M.message:String(M))}).finally(()=>{F&&N(!1)}),()=>{F=!1}},[e]);async function L(F){if(F.preventDefault(),!(!a.trim()||!f.trim()||!g.trim())){j(!0),T(null);try{const M=await C7({title:a.trim(),body:c.trim()||void 0,head:f.trim(),base:g.trim(),draft:b});t(M)}catch(M){T(M instanceof Error?M.message:String(M))}finally{j(!1)}}}const H="w-full rounded-md border border-border bg-background px-3 py-2 text-[13px] placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring",P=_?.warnings??[];return i.jsxs("form",{className:"flex min-h-0 flex-col gap-3 overflow-auto bg-muted/20 p-4",onSubmit:F=>{L(F)},children:[i.jsxs("div",{className:"flex items-start justify-between gap-3",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("h3",{className:"text-[13px] font-semibold",children:n("github.branchToPr")}),i.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:[_?.repository?.full_name??n("github.selectedRepo"),_?.currentBranch?` - ${_.currentBranch}`:""]})]}),i.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:n(C?"github.detectingBranch":"github.editableDraft")})]}),i.jsx(ote,{template:_,loading:C}),P.length>0?i.jsx("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[12px] text-amber-700 dark:text-amber-300",children:P[0]}):null,i.jsx("input",{className:H,disabled:C,onChange:F=>l(F.target.value),placeholder:n("github.fieldTitle"),required:!0,value:a}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsxs("label",{className:"space-y-1",children:[i.jsx("span",{className:"text-[10px] uppercase text-muted-foreground",children:n("github.head")}),i.jsx("input",{className:H,disabled:C,onChange:F=>h(F.target.value),placeholder:n("github.headBranch"),required:!0,value:f})]}),i.jsxs("label",{className:"space-y-1",children:[i.jsx("span",{className:"text-[10px] uppercase text-muted-foreground",children:n("github.base")}),i.jsx("input",{className:H,disabled:C,onChange:F=>p(F.target.value),placeholder:n("github.baseBranch"),required:!0,value:g})]})]}),i.jsx("textarea",{className:`${H} resize-none`,disabled:C,onChange:F=>d(F.target.value),placeholder:n("github.descriptionOptional"),rows:7,value:c}),i.jsxs("label",{className:"flex items-center gap-2 text-[12px]",children:[i.jsx("input",{checked:b,className:"size-3.5",disabled:C,onChange:F=>v(F.target.checked),type:"checkbox"}),n("github.createAsDraft")]}),E?i.jsx(tt,{variant:"destructive",children:E}):null,i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Q,{disabled:C||A||!a.trim()||!f.trim()||!g.trim(),type:"submit",children:n(A?"github.creating":"github.createPr")}),i.jsx(Q,{onClick:s,type:"button",variant:"outline",children:n("common.cancel")})]})]})}function ote({template:e,loading:t}){const s=ee(),n=e?.compare,a=n?.ciStatus,l=[{label:s("github.compare.base"),value:n?.base||e?.base||"main"},{label:s("github.compare.head"),value:n?.head||e?.head||"manual"},{label:s("github.compare.ahead"),value:t?"...":String(n?.aheadBy??0)},{label:s("github.compare.changed"),value:t?"...":String(n?.files.length??0)},{label:s("github.compare.ci"),value:a?`${a.state} (${a.totalCount})`:s("github.compare.unavailable")}];return i.jsxs("div",{className:"rounded-md border border-border bg-card px-3 py-2",children:[i.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[i.jsx("span",{className:"text-[11px] font-medium text-foreground",children:s("github.compareSummary")}),n?.headSha?i.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:n.headSha.slice(0,7)}):null]}),i.jsx("div",{className:"grid grid-cols-5 gap-2",children:l.map(c=>i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:"truncate text-[10px] uppercase text-muted-foreground",children:c.label}),i.jsx("div",{className:"truncate font-mono text-[11px] text-foreground",children:c.value})]},c.label))}),n?.files.length?i.jsx("div",{className:"mt-2 flex flex-wrap gap-x-3 gap-y-1 text-[11px] text-muted-foreground",children:n.files.slice(0,4).map(c=>i.jsxs("span",{className:"max-w-52 truncate",children:[c.status," ",c.path]},`${c.status}:${c.path}`))}):null]})}function lte({data:e,docked:t,scopeAll:s,onScopeChange:n,onRefresh:a,onClose:l,onManage:c}){const d=ee(),{error:f,success:h}=ms(),g=e.git.selectedRepository;async function p(S){l();try{await PE(S),n(!1),await a(),h(d("git.repo.switchedToast",{name:S}))}catch(C){f(C instanceof Error?C.message:String(C))}}function b(){l(),n(!0),h(d("app.showingAllProjects"))}const v=S=>oe("grid h-8 grid-cols-[48px_minmax(0,1fr)] items-center overflow-hidden rounded-md text-left transition-[background-color,width] duration-150 hover:bg-muted",t?"w-full":"w-12 group-hover/sidebar:w-full",S&&"bg-muted/60"),_=oe("flex min-w-0 items-center gap-2 overflow-hidden whitespace-pre pr-2 text-xs transition duration-150",t?"translate-x-1 opacity-100":"opacity-0 group-hover/sidebar:translate-x-1 group-hover/sidebar:opacity-100");return i.jsxs("div",{className:"mt-1 grid gap-0.5",children:[i.jsxs("button",{className:v(s),onClick:b,title:d("app.allProjects"),type:"button",children:[i.jsx("span",{className:"flex h-8 w-12 items-center justify-center",children:i.jsx(tf,{className:"size-4 text-muted-foreground"})}),i.jsxs("span",{className:_,children:[i.jsx("span",{className:"min-w-0 flex-1 truncate font-medium",children:d("app.allProjects")}),s?i.jsx(Ys,{className:"size-3.5 shrink-0"}):null]})]}),e.config.gitRepositories.map(S=>{const C=!s&&S.name===g?.name;return i.jsxs("button",{className:v(C),onClick:()=>{p(S.name)},title:S.path,type:"button",children:[i.jsx("span",{className:"flex h-8 w-12 items-center justify-center",children:i.jsx($f,{className:"size-4 text-muted-foreground"})}),i.jsxs("span",{className:_,children:[i.jsx("span",{className:"min-w-0 flex-1 truncate font-medium",children:S.name}),C?i.jsx(Ys,{className:"size-3.5 shrink-0"}):null]})]},S.name)}),i.jsxs("button",{className:oe("grid h-8 grid-cols-[48px_minmax(0,1fr)] items-center overflow-hidden rounded-md text-left text-muted-foreground transition-[background-color,color,width] duration-150 hover:bg-muted hover:text-foreground",t?"w-full":"w-12 group-hover/sidebar:w-full"),onClick:()=>{l(),c()},title:d("app.addManageProjects"),type:"button",children:[i.jsx("span",{className:"flex h-8 w-12 items-center justify-center",children:i.jsx(Ux,{className:"size-4"})}),i.jsx("span",{className:_,children:i.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[d("app.addManageProjects"),"…"]})})]})]})}function cte({data:e,docked:t,scopeAll:s,onScopeChange:n,onRefresh:a}){const l=ee(),[c,d]=x.useState(!1),[f,h]=x.useState(!1),g=e.git.selectedRepository,p=s?l("app.allProjects"):g?.name??l("app.pickProject"),b=e.config.gitRepositories.length,v=s?l(b===1?"app.projectCountOne":"app.projectCountMany",{count:b}):g?e.git.status?.branch??g.path:l("app.setContext");return i.jsxs(i.Fragment,{children:[i.jsxs("button",{"aria-label":l("app.projectScope",{label:p}),className:oe("relative grid h-11 grid-cols-[48px_minmax(0,1fr)] items-center overflow-hidden rounded-md text-left transition-[background-color,width] duration-150 hover:bg-muted",t?"w-full":"w-12 group-hover/sidebar:w-full"),"aria-expanded":c,onClick:()=>d(_=>!_),title:l("app.projectScope",{label:p}),type:"button",children:[i.jsx("span",{className:"flex h-11 w-12 items-center justify-center",children:i.jsx("span",{className:"flex size-8 items-center justify-center rounded-lg border border-border bg-background text-[13px] font-semibold text-foreground",children:s?i.jsx(tf,{className:"size-4 text-muted-foreground"}):g?p.charAt(0).toUpperCase():i.jsx($f,{className:"size-4 text-muted-foreground"})})}),i.jsxs("span",{className:oe("min-w-0 overflow-hidden whitespace-pre pr-8 transition duration-150",t?"translate-x-1 opacity-100":"opacity-0 group-hover/sidebar:translate-x-1 group-hover/sidebar:opacity-100"),children:[i.jsx("span",{className:"block truncate text-[13px] font-semibold leading-tight",children:p}),i.jsx("span",{className:"block truncate text-[10px] leading-tight text-muted-foreground",children:v})]}),i.jsx(hn,{className:oe("absolute right-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground transition-[opacity,transform] duration-150",t?"opacity-100":"opacity-0 group-hover/sidebar:opacity-100",c&&"rotate-180")})]}),c?i.jsx(lte,{data:e,docked:t,onClose:()=>d(!1),onManage:()=>h(!0),onRefresh:a,onScopeChange:n,scopeAll:s}):null,f?i.jsx(ute,{data:e,onClose:()=>h(!1),onRefresh:a,onScopeChange:n,scopeAll:s}):null]})}function ute({data:e,onClose:t,onRefresh:s,onScopeChange:n,scopeAll:a}){const l=ee(),[c,d]=x.useState("path"),[f,h]=x.useState(e.git.cwd),[g,p]=x.useState(""),[b,v]=x.useState(!1),[_,S]=x.useState(null),[C,N]=x.useState(!1),[A,j]=x.useState(e.git.cwd),E=e.git.selectedRepository,{error:T,success:L}=ms();async function H(D){try{await PE(D),n(!1),t(),await s(),L(l("git.repo.switchedToast",{name:D}))}catch(q){T(q instanceof Error?q.message:String(q))}}function P(){n(!0),t(),L(l("app.showingAllProjects"))}async function F(D){const q=D.trim();if(!q.startsWith("/")){const W=l("git.repo.absPathError");return S(W),T(W),!1}try{const W=fT(q);return await u7(W,q),S(null),await s(),L(l("git.repo.addedToast",{name:W})),!0}catch(W){const I=W instanceof Error?W.message:String(W);return S(I),T(I),!1}}async function M(D){try{await c7(D),await s(),L(l("git.repo.removedToast",{name:D}))}catch(q){T(q instanceof Error?q.message:String(q))}}async function z(D){D.preventDefault(),await F(f)&&t()}async function G(D){D.preventDefault();const q=g.trim();if(q){v(!0),S(null);try{const{name:W}=await d7(q);p(""),await s(),L(l("git.repo.clonedToast",{name:W})),t()}catch(W){const I=W instanceof Error?W.message:String(W);S(I),T(I)}finally{v(!1)}}}return Ii.createPortal(i.jsxs("div",{className:"fixed inset-0 z-[1000] grid place-items-center bg-black/35 px-4",onMouseDown:D=>{D.target===D.currentTarget&&t()},children:[i.jsxs("div",{className:"w-full max-w-md overflow-hidden rounded-xl border border-border bg-card shadow-xl",children:[i.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-4 py-3",children:[i.jsx(tf,{className:"size-4 text-muted-foreground"}),i.jsx("div",{className:"text-sm font-semibold",children:l("git.repo.projectsShort")}),i.jsx(Ke,{className:"h-5 px-1.5 text-[10px]",variant:"outline",children:e.config.gitRepositories.length}),i.jsx(Q,{"aria-label":l("git.repo.closeSwitcher"),className:"ml-auto size-7",onClick:t,size:"icon",variant:"ghost",children:i.jsx(Vt,{className:"size-4"})})]}),i.jsxs("div",{className:"max-h-80 overflow-auto",children:[i.jsxs("button",{className:oe("grid w-full grid-cols-[1fr_auto] items-center gap-2 border-b border-border px-4 py-2.5 text-left transition-colors hover:bg-muted",a&&"bg-muted/70"),onClick:P,type:"button",children:[i.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(tf,{className:"size-3.5 shrink-0 text-muted-foreground"}),i.jsxs("span",{className:"min-w-0",children:[i.jsx("span",{className:"block truncate text-sm font-medium leading-tight",children:l("app.allProjects")}),i.jsx("span",{className:"block truncate text-[10px] leading-tight text-muted-foreground",children:l("app.allProjectsHint")})]})]}),a?i.jsx(Ys,{className:"size-3.5"}):i.jsx("span",{className:"size-3.5"})]}),e.config.gitRepositories.length?i.jsx("div",{className:"divide-y divide-border",children:e.config.gitRepositories.map(D=>{const q=!a&&D.name===E?.name;return i.jsxs("div",{className:oe("group grid w-full grid-cols-[1fr_auto_auto] items-center gap-2 px-4 py-2 text-left transition-colors hover:bg-muted",q&&"bg-muted/70"),children:[i.jsxs("button",{className:"min-w-0 text-left",onClick:()=>{H(D.name)},type:"button",children:[i.jsx("span",{className:"block truncate text-sm font-medium leading-tight",children:D.name}),i.jsx("span",{className:"block truncate font-mono text-[10px] leading-tight text-muted-foreground",children:D.path})]}),q?i.jsx(Ys,{className:"size-3.5"}):i.jsx("span",{className:"size-3.5"}),i.jsx(Q,{"aria-label":l("git.repo.removeName",{name:D.name}),className:"size-6 opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>{M(D.name)},size:"icon",title:l("git.repo.removeName",{name:D.name}),type:"button",variant:"ghost",children:i.jsx(Bi,{className:"size-3.5 text-destructive"})})]},D.name)})}):i.jsx("div",{className:"px-4 py-6 text-center text-xs text-muted-foreground",children:l("git.repo.noProjects")})]}),i.jsxs("div",{className:"border-t border-border bg-muted/20 p-3",children:[i.jsxs("div",{className:"mb-1.5 flex gap-1 text-[11px]",children:[i.jsxs("button",{className:oe("flex items-center gap-1 rounded px-2 py-0.5 transition-colors",c==="path"?"bg-muted font-medium text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>{d("path"),S(null)},type:"button",children:[i.jsx(ko,{className:"size-3"}),l("git.repo.localPath")]}),i.jsxs("button",{className:oe("flex items-center gap-1 rounded px-2 py-0.5 transition-colors",c==="url"?"bg-muted font-medium text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>{d("url"),S(null)},type:"button",children:[i.jsx(vu,{className:"size-3"}),l("git.repo.cloneUrl")]})]}),c==="path"?i.jsxs("form",{className:"flex gap-1.5",onSubmit:z,children:[i.jsx(pt,{"aria-label":l("git.repo.pasteAbsPath"),className:"h-7 flex-1 px-2 font-mono text-[11px]",onChange:D=>{h(D.target.value),S(null)},placeholder:"/absolute/path",value:f}),i.jsxs(Q,{className:"h-7 px-2 text-[11px]",size:"sm",type:"submit",children:[i.jsx(fs,{className:"size-3"}),l("common.add")]}),i.jsx(Q,{"aria-label":l("git.repo.browseAdd"),className:"h-7 px-2",onClick:()=>{S(null),j(e.git.cwd),N(!0)},size:"sm",type:"button",variant:"outline",children:i.jsx(Ux,{className:"size-3"})})]}):i.jsxs("form",{className:"flex gap-1.5",onSubmit:G,children:[i.jsx(pt,{"aria-label":l("git.repo.remoteUrl"),className:"h-7 flex-1 px-2 font-mono text-[11px]",onChange:D=>{p(D.target.value),S(null)},placeholder:"https://… or git@host:owner/repo.git",value:g}),i.jsxs(Q,{className:"h-7 px-2 text-[11px]",disabled:b||!g.trim(),size:"sm",type:"submit",children:[i.jsx(vu,{className:"size-3"}),l(b?"git.repo.cloning":"git.repo.clone")]})]}),_?i.jsx("div",{className:"mt-1.5 truncate text-[10px] text-destructive",children:_}):null,c==="url"?i.jsx("div",{className:"mt-1 text-[10px] text-muted-foreground",children:l("git.repo.cloneHint")}):null]})]}),C?i.jsx(mT,{confirmLabel:l("git.repo.addProject"),errorMessage:_,initialPath:e.git.cwd,selectedPath:A,title:l("git.repo.addProjectTitle"),onCancel:()=>N(!1),onSelect:j,onUse:async()=>{await F(A)&&(N(!1),t())}}):null]}),document.body)}function dte({ahead:e=0,behind:t=0,branches:s,currentBranch:n,disabled:a,onRefresh:l,upstream:c}){const d=ee(),[f,h]=x.useState(!1),[g,p]=x.useState(""),[b,v]=x.useState(null),[_,S]=x.useState(null),[C,N]=x.useState(null),A=s.filter(M=>!M.remote),j=s.filter(M=>M.remote);async function E(M,z){v(M),N(null),S(null);try{await z(),await l()}catch(G){N(G instanceof Error?G.message:String(G))}finally{v(null)}}async function T(M){await E(`switch:${M}`,async()=>{await Pi("/api/git/branches/switch",{name:M}),h(!1)})}async function L(){await E("fetch",async()=>{await Pi("/api/git/fetch",{}),S(d("git.branch.fetched"))})}async function H(){await E("push",async()=>{const M=await Jf();S(M.setUpstream?d("git.branch.pushedSetUpstream",{branch:M.branch}):d("git.branch.pushed",{branch:M.branch}))})}const P=!!n&&(e>0||!c&&t===0);async function F(M){M.preventDefault();const z=g.trim();if(!z){N(d("git.branch.nameRequired"));return}await E("create",async()=>{await Pi("/api/git/branches",{name:z}),p(""),h(!1)})}return i.jsxs("div",{className:"fixed bottom-12 right-4 z-50 flex items-end",children:[f?i.jsxs("div",{"aria-label":d("git.branch.switchAria"),className:"mb-11 w-[min(460px,calc(100vw-2rem))] rounded-lg border border-border bg-card shadow-xl",role:"dialog",children:[i.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border p-3",children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(Pn,{className:"size-4 text-muted-foreground"}),i.jsx("span",{className:"truncate text-sm font-semibold",children:n||d("git.branch.branches")})]}),i.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[P?i.jsxs(Q,{"aria-label":d("git.branch.pushAria"),className:"gap-1.5 px-2 text-xs",disabled:a||b!==null,onClick:()=>{H()},size:"sm",title:c?d("git.branch.pushCountTo",{ahead:e,upstream:c}):d("git.branch.pushSetUpstream"),type:"button",variant:"default",children:[i.jsx(Xf,{className:oe("size-3.5",b==="push"&&"animate-pulse")}),d("git.branch.push"),e>0?` ${e}`:""]}):null,i.jsx(Q,{"aria-label":d("git.branch.fetchAria"),disabled:a||b!==null,onClick:()=>{L()},size:"icon",title:d("git.branch.fetchAria"),type:"button",variant:"ghost",children:i.jsx(Pr,{className:oe(b==="fetch"&&"animate-spin")})}),i.jsx(Q,{"aria-label":d("git.branch.closeAria"),onClick:()=>h(!1),size:"icon",type:"button",variant:"ghost",children:i.jsx(Vt,{})})]})]}),i.jsx("div",{className:"max-h-72 overflow-auto",children:s.length?i.jsxs(i.Fragment,{children:[i.jsx(WN,{branches:A,busy:b!==null,disabled:a,empty:d("git.branch.noLocal"),label:d("git.branch.sectionLocal"),onSwitch:T}),i.jsx(WN,{branches:j,busy:b!==null,disabled:a,empty:d("git.branch.noRemote"),label:d("git.branch.sectionRemote"),onSwitch:T})]}):i.jsx("div",{className:"px-3 py-6 text-center text-sm text-muted-foreground",children:d("git.branch.noneFound")})}),i.jsxs("div",{className:"border-t border-border p-3",children:[i.jsxs("form",{className:"grid gap-2 sm:grid-cols-[1fr_auto]",onSubmit:F,children:[i.jsx(pt,{"aria-label":d("git.branch.newNameAria"),disabled:a||b!==null,onChange:M=>{p(M.target.value),N(null),S(null)},placeholder:"feature/new-work",value:g}),i.jsxs(Q,{disabled:a||b!==null,type:"submit",children:[i.jsx(x6,{}),d("git.branch.create")]})]}),C||_?i.jsx(tt,{className:"mt-3 px-3 py-2 text-xs",variant:C?"destructive":"muted",children:C??_}):null]})]}):null,i.jsxs(Q,{className:"h-8 max-w-[260px] gap-2 rounded-md shadow-lg",disabled:a,onClick:()=>h(M=>!M),size:"sm",title:d("git.branch.switchAria"),type:"button",variant:"default",children:[i.jsx(Pn,{className:"size-4"}),i.jsx("span",{className:"truncate font-mono text-xs",children:n||d("git.branch.noBranch")}),n&&(e>0||t>0)?i.jsxs("span",{className:"flex items-center gap-1 font-mono text-[11px] tabular-nums",title:c?d("git.branch.aheadBehindUpstream",{ahead:e,behind:t,upstream:c}):d("git.branch.aheadBehind",{ahead:e,behind:t}),children:[t>0?i.jsxs("span",{className:"flex items-center",children:[i.jsx(Bf,{className:"size-3"}),t]}):null,e>0?i.jsxs("span",{className:"flex items-center",children:[i.jsx(If,{className:"size-3"}),e]}):null]}):null,i.jsx(hn,{className:oe("size-4 transition-transform",f&&"rotate-180")})]})]})}function WN({branches:e,busy:t,disabled:s,empty:n,label:a,onSwitch:l}){const c=ee();return i.jsxs("section",{children:[i.jsx("div",{className:"border-b border-border bg-muted/60 px-3 py-1.5 text-[11px] font-semibold uppercase text-muted-foreground",children:a}),e.length?e.map(d=>i.jsxs("button",{className:oe("grid w-full grid-cols-[1fr_auto] items-center gap-2 border-b border-border px-3 py-2 text-left text-sm last:border-b-0 hover:bg-muted",d.current&&"bg-muted/70"),disabled:s||t||d.current,onClick:()=>{l(d.name)},type:"button",children:[i.jsxs("span",{className:"min-w-0",children:[i.jsx("span",{className:"block truncate font-medium",children:d.name}),d.upstream?i.jsx("span",{className:"block truncate font-mono text-[11px] text-muted-foreground",children:c("git.branch.tracks",{upstream:d.upstream})}):null]}),i.jsx(Ke,{variant:d.current?"success":d.remote?"outline":"secondary",children:d.current?c("git.branch.tagCurrent"):d.remote?c("git.branch.tagRemote"):c("git.branch.tagLocal")})]},`${d.remote?"remote":"local"}:${d.name}`)):i.jsx("div",{className:"border-b border-border px-3 py-3 text-sm text-muted-foreground",children:n})]})}function hte(){const e=ee(),[,t]=pA(),s=WK(),n=x.useRef(null),a=x.useCallback(()=>{const l=s==="dark"?"light":"dark",c=n.current,d=document;if(!c||!d.startViewTransition||window.matchMedia("(prefers-reduced-motion: reduce)").matches){t(l);return}const f=c.getBoundingClientRect(),h=f.left+f.width/2,g=f.top+f.height/2,p=Math.hypot(Math.max(h,window.innerWidth-h),Math.max(g,window.innerHeight-g));d.startViewTransition(()=>{t(l)}).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${h}px ${g}px)`,`circle(${p}px at ${h}px ${g}px)`]},{duration:500,easing:"ease-in-out",pseudoElement:"::view-transition-new(root)"})})},[s,t]);return i.jsxs("button",{ref:n,type:"button",onClick:a,title:e(s==="dark"?"action.toLight":"action.toDark"),"aria-label":e("action.theme"),className:gf(),children:[i.jsx("span",{className:bf(),children:s==="dark"?i.jsx(o8,{}):i.jsx(dD,{})}),i.jsx("span",{className:vf(),children:e("action.theme")})]})}function fte(){const e=ee();return $s()?i.jsxs("div",{className:"flex items-center justify-between h-8 bg-background border-b border-border select-none",style:{WebkitAppRegion:"drag"},onMouseDown:()=>N8(),children:[i.jsx("span",{className:"px-3 text-xs font-medium text-muted-foreground",children:"NoMoreIDE"}),i.jsxs("div",{className:"flex items-center",style:{WebkitAppRegion:"no-drag"},children:[i.jsx("button",{type:"button",onClick:S8,className:"h-8 w-10 flex items-center justify-center hover:bg-muted transition-colors","aria-label":e("common.minimize"),children:i.jsx(hE,{className:"h-3 w-3"})}),i.jsx("button",{type:"button",onClick:k8,className:"h-8 w-10 flex items-center justify-center hover:bg-muted transition-colors","aria-label":e("common.maximize"),children:i.jsx(xo,{className:"h-3 w-3"})}),i.jsx("button",{type:"button",onClick:C8,className:"h-8 w-10 flex items-center justify-center hover:bg-destructive hover:text-destructive-foreground transition-colors","aria-label":e("common.close"),children:i.jsx(Vt,{className:"h-3 w-3"})})]})]}):null}const mte=300;function pte(){const{operations:e}=si(),[t,s]=x.useState(!1),[n,a]=x.useState(!1),l=x.useId(),c=ee();if(x.useEffect(()=>{if(e.length===0){s(!1),a(!1);return}const h=Math.min(...e.map(({startedAt:b})=>b)),g=Math.max(0,mte-(Date.now()-h));if(g===0){s(!0);return}s(!1);const p=window.setTimeout(()=>s(!0),g);return()=>window.clearTimeout(p)},[e]),!t||e.length===0)return null;const d=e.length>1,f=d?c("operation.multiple",{count:e.length}):e[0].label;return i.jsxs("aside",{"aria-live":"polite",className:"rounded-lg border border-border bg-card px-3 py-2 text-card-foreground shadow-sm transition-all motion-reduce:transition-none",role:"status",children:[i.jsxs("div",{className:"flex min-h-7 items-center gap-2",children:[i.jsx(tm,{size:"sm"}),i.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium",children:f}),d?i.jsx(Q,{"aria-controls":l,"aria-expanded":n,"aria-label":c(n?"operation.hideDetails":"operation.showDetails"),onClick:()=>a(h=>!h),size:"icon-sm",type:"button",variant:"ghost",children:i.jsx(hn,{className:oe("transition-transform motion-reduce:transition-none",n&&"rotate-180")})}):null]}),d&&n?i.jsx("ul",{className:"mt-2 space-y-1 border-t border-border pt-2",id:l,children:e.map(h=>i.jsxs("li",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[i.jsx("span",{"aria-hidden":!0,className:"size-1.5 shrink-0 rounded-full bg-primary"}),i.jsx("span",{className:"truncate",children:h.label})]},h.id))}):null]})}const AT={services:"/",git:"/git",github:"/github",workflows:"/workflows",errors:"/errors",database:"/database",terminal:"/terminal",agent:"/agent","agent-env":"/agent-env",settings:"/settings"},gte={services:"nav.services",git:"nav.git",github:"nav.github",workflows:"nav.workflows",errors:"nav.errors",database:"nav.database",terminal:"nav.terminal",agent:"pageTitle.agent","agent-env":"pageTitle.agentEnv",settings:"nav.settings"},bte=Object.entries(AT).filter(([,e])=>e!=="/").sort(([,e],[,t])=>t.length-e.length);function vte(e){for(const[t,s]of bte)if(e.startsWith(s))return t;return"services"}const xte=[{labelKey:"nav.section.run",items:[{page:"services",labelKey:"nav.services",icon:i.jsx(Yf,{})},{page:"errors",labelKey:"nav.errors",icon:i.jsx(ju,{})},{page:"terminal",labelKey:"nav.terminal",icon:i.jsx(zr,{})}]},{labelKey:"nav.section.code",items:[{page:"git",labelKey:"nav.git",icon:i.jsx(Pn,{})},{page:"github",labelKey:"nav.github",icon:i.jsx(pm,{})},{page:"workflows",labelKey:"nav.workflows",icon:i.jsx(nf,{})}]},{labelKey:"nav.section.data",items:[{page:"database",labelKey:"nav.database",icon:i.jsx(ti,{})}]},{labelKey:"nav.section.agent",items:[{page:"agent",labelKey:"nav.agentConsole",icon:i.jsx(Hf,{})},{page:"agent-env",labelKey:"nav.agentEnv",icon:i.jsx(Au,{})}]}];function yte(e=!1){return oe("group/sidebar hidden h-full shrink-0 overflow-x-hidden overflow-y-auto border-r border-border bg-card/85 py-4 backdrop-blur transition-[width,padding] duration-200 md:flex md:flex-col",e?"w-64 px-4":"w-16 px-2 hover:w-64 hover:px-4")}function _te(e,t=!1){return oe("relative grid h-10 grid-cols-[48px_minmax(0,1fr)] items-center justify-start gap-0 overflow-hidden rounded-md px-0 text-sm font-medium transition-[background-color,color,width] duration-150",t?"w-full":"w-12 group-hover/sidebar:w-full",e?"bg-primary text-primary-foreground hover:bg-primary/90":"hover:bg-muted")}function wte(e=!1,t=!1){return oe("min-w-0 overflow-hidden text-left text-current transition duration-150 whitespace-pre",e?"translate-x-1 opacity-100":"opacity-0 group-hover/sidebar:translate-x-1 group-hover/sidebar:opacity-100",t?"pr-10":"pr-3")}function Ste(e=!1){return oe("flex h-10 w-12 items-center justify-center text-current transition-transform duration-150 [&_svg]:size-5",e?"translate-x-0":"-translate-x-px group-hover/sidebar:translate-x-0")}function kte({docked:e,onToggleDock:t}){return i.jsxs("div",{className:oe("mt-auto flex h-10 min-w-0 items-center overflow-hidden border-t border-border/60 text-[11px] text-muted-foreground transition-[height,opacity,width] duration-150",e?"w-full justify-start opacity-100":"w-12 justify-center group-hover/sidebar:w-full group-hover/sidebar:justify-start group-hover/sidebar:opacity-100"),children:[i.jsxs("span",{className:oe("flex min-w-0 items-center gap-1.5 overflow-hidden whitespace-pre transition-[opacity,width] duration-150",e?"flex-1 opacity-100":"w-0 flex-none opacity-0 group-hover/sidebar:w-auto group-hover/sidebar:flex-1 group-hover/sidebar:opacity-100"),children:[i.jsx("span",{children:"Made with"}),i.jsx(C6,{"aria-label":"love",className:"size-3 shrink-0 fill-red-500 text-red-500"}),i.jsx("span",{children:"by Robert Wang"}),i.jsx("a",{"aria-label":"Robert Wang on LinkedIn",className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-[#0A66C2]",href:"https://www.linkedin.com/in/robert-wang-cs/",rel:"noopener noreferrer",target:"_blank",title:"LinkedIn",children:i.jsxs("svg",{className:"size-3 fill-current",role:"img",viewBox:"0 0 24 24",children:[i.jsx("title",{children:"LinkedIn"}),i.jsx("path",{d:"M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.063 2.063 0 1 1 0-4.126 2.063 2.063 0 0 1 0 4.126zM7.119 20.452H3.554V9h3.565v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.225 0z"})]})})]}),i.jsx("button",{"aria-label":e?"Undock sidebar":"Dock sidebar","aria-pressed":e,className:oe("flex size-8 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground [&_svg]:size-4",e?"ml-auto bg-muted text-foreground":"group-hover/sidebar:ml-auto"),onClick:t,title:e?"Undock sidebar":"Dock sidebar",type:"button",children:e?i.jsx(vD,{}):i.jsx(yD,{})})]})}function Cte({className:e}){return i.jsxs("div",{className:oe("min-w-0",e),children:[i.jsxs("div",{className:"flex items-baseline gap-1.5",children:[i.jsx("div",{className:"text-sm font-semibold",children:"NoMoreIDE"}),i.jsxs("div",{className:"font-mono text-[10px] text-muted-foreground",children:["v","0.1.84"]})]}),i.jsx("div",{className:"font-mono text-[11px] text-muted-foreground",children:"127.0.0.1 console"})]})}function Nte({syncLocation:e=!0}={}){return i.jsx(tY,{children:i.jsx(Z$,{children:i.jsx(jte,{syncLocation:e})})})}function Ete({projectPath:e,selectProject:t}){return x.useEffect(()=>{t(e)},[e,t]),null}function jte({syncLocation:e}){const t=ee(),[s,n]=x.useState(()=>e?vte(window.location.pathname):"services"),[a,l]=x.useState(null),[c,d]=x.useState(null),[f,h]=x.useState(null),[g,p]=x.useState(0),[b,v]=x.useState(null),[_,S]=x.useState(!0),{error:C,message:N,success:A}=ms(),{ui:j,updateUi:E,selectProject:T}=bm(),L=j.sidebarDocked,H=j.projectScope==="all",P=x.useCallback($=>E({projectScope:$?"all":"project"}),[E]),F=NU(),M=x.useCallback(async($={})=>{$.silent||S(!0),v(null);try{l(await q7()),$.notify&&A(t("app.dashboardRefreshed"))}catch(me){const J=me instanceof Error?me.message:String(me);v(J),C(J)}finally{S(!1)}},[C,A,t]),z=x.useCallback(()=>{M({notify:!0}),F.runActive()},[M,F]);x.useEffect(()=>{M()},[M]),x.useEffect(()=>{function $(){document.visibilityState==="visible"&&(M({silent:!0}),F.runActive())}const me=window.setInterval($,5e3);return window.addEventListener("focus",$),document.addEventListener("visibilitychange",$),()=>{window.clearInterval(me),window.removeEventListener("focus",$),document.removeEventListener("visibilitychange",$)}},[s,M,F.runActive]),x.useEffect(()=>{if(!e)return;const $=AT[s];window.location.pathname!==$&&window.history.pushState(null,"",$)},[s,e]);const G=!H&&a?.git.selectedRepository||null,D=x.useMemo(()=>a&&G?oY(a,G):a,[a,G]),q=x.useMemo(()=>G&&D?new Set(D.config.services.map($=>$.name)):null,[G,D]),W=x.useMemo(()=>D?Object.values(D.runtime.services).filter($=>$.state==="running").length:0,[D]),I=a?.git.selectedRepository?.name??a?.git.cwd??"no-git-repository",Y=a?.git.selectedRepository?.path??null;return i.jsxs(fF,{children:[i.jsx(Ete,{projectPath:Y,selectProject:T}),i.jsx(EU,{value:F,children:i.jsx(Fq,{onRefresh:()=>{M({silent:!0})},children:i.jsx(Uq,{children:i.jsxs("div",{className:"flex flex-col h-screen overflow-hidden",children:[i.jsx(fte,{}),i.jsxs("div",{className:"flex-1 overflow-hidden pb-9",children:[i.jsxs("div",{className:"mx-auto flex h-full max-w-[1500px]",children:[i.jsxs("aside",{className:yte(L),children:[i.jsxs("div",{className:oe("grid h-12 grid-cols-[48px_minmax(0,1fr)] items-center overflow-hidden transition-[width] duration-150",L?"w-full":"w-12 group-hover/sidebar:w-full"),children:[i.jsx("div",{className:"flex size-12 items-center justify-center",children:i.jsx("div",{className:"flex size-9 items-center justify-center overflow-hidden rounded-md bg-primary text-primary-foreground",children:i.jsxs("svg",{"aria-label":"NoMoreIDE",className:"size-6",fill:"none",role:"img",viewBox:"0 0 64 64",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("path",{d:"M5 17C5 13.69 7.69 11 11 11H25L31 17H53C56.31 17 59 19.69 59 23V53C59 56.31 56.31 59 53 59H11C7.69 59 5 56.31 5 53V17Z",fill:"currentColor"}),i.jsx("path",{d:"M22 31L30 39L22 47",stroke:"hsl(var(--primary))",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"4.5"}),i.jsx("path",{d:"M36 47H48",stroke:"hsl(var(--primary))",strokeLinecap:"round",strokeWidth:"4.5"})]})})}),i.jsx(Cte,{className:oe("min-w-0 translate-x-1 overflow-hidden transition-opacity duration-200",L?"opacity-100":"opacity-0 group-hover/sidebar:opacity-100")})]}),a?i.jsx("div",{className:"mt-3 border-b border-border/60 pb-2",children:i.jsx(cte,{data:a,docked:L,onRefresh:()=>M({silent:!0}),onScopeChange:P,scopeAll:H})}):null,i.jsx("nav",{className:"mt-2 flex-1 content-start overflow-y-auto overflow-x-hidden",children:xte.map(($,me)=>i.jsxs("div",{className:oe(me>0&&"mt-2 border-t border-border/60 pt-2"),children:[i.jsx(Ate,{docked:L,label:t($.labelKey)}),i.jsx("div",{className:"grid gap-0.5",children:$.items.map(J=>i.jsx(KN,{active:s===J.page,badge:J.page==="services"?W:void 0,docked:L,icon:J.icon,label:t(J.labelKey),onClick:()=>n(J.page)},J.page))})]},$.labelKey))}),i.jsx("div",{className:"mb-1 border-t border-border/60 pt-1",children:i.jsx(KN,{active:s==="settings",docked:L,icon:i.jsx(gE,{}),label:t("nav.settings"),onClick:()=>n("settings")})}),i.jsx(kte,{docked:L,onToggleDock:()=>E({sidebarDocked:!L})})]}),i.jsxs("main",{className:"flex h-full min-w-0 flex-1 flex-col px-0 py-0",children:[i.jsxs("header",{className:oe("relative z-40 flex shrink-0 flex-wrap items-center justify-between gap-3 border border-border bg-card/90 px-4 py-3 backdrop-blur","border-x-0 border-t-0 border-b"),children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx(wD,{className:"size-4 text-muted-foreground md:hidden"}),i.jsxs("div",{children:[i.jsx("h1",{className:"text-lg font-semibold tracking-tight",children:t(gte[s])}),i.jsx("p",{className:"font-mono text-xs text-muted-foreground",children:s==="git"||s==="github"?a?.git.selectedRepository?.name??a?.git.cwd??t("app.localWorkspace"):G?.name??t("app.allProjects")})]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[b?i.jsx(Ke,{variant:"danger",children:b}):null,i.jsxs("div",{"aria-label":"Dashboard quick actions",className:"flex items-center gap-1 rounded-lg border border-border bg-background p-px",role:"toolbar",children:[i.jsxs("button",{"aria-label":t("action.refresh"),className:gf(),onClick:z,title:t("action.refreshTitle"),type:"button",children:[i.jsx("span",{className:bf(),children:i.jsx(Pr,{className:oe(_&&"animate-spin")})}),i.jsx("span",{className:vf(),children:t("action.refresh")})]}),i.jsx(hte,{}),i.jsxs("a",{"aria-label":t("action.docsTitle"),className:gf(),href:"https://www.nomoreide.com/docs",rel:"noreferrer",target:"_blank",title:t("action.docsTitle"),children:[i.jsx("span",{className:bf(),children:i.jsx(QN,{})}),i.jsx("span",{className:vf(),children:t("action.docs")})]}),a?i.jsx(Sq,{data:a}):null]})]})]}),i.jsx("div",{className:"relative z-30 shrink-0 px-4 pt-2",children:i.jsx(pte,{})}),a?i.jsx(vZ,{data:a,onOpenService:$=>{q&&!q.has($)&&(P(!0),N({text:t("app.serviceOutsideScope")})),d($),n("services"),M({silent:!0})}}):null,_&&!a?i.jsx(tt,{variant:"muted",children:t("app.loading")}):null,i.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[D&&s==="services"?i.jsx(pZ,{data:D,onRefresh:M,focusService:c,onServiceFocused:()=>d(null),scopeName:G?.name??null}):null,a&&s==="git"?i.jsx(eee,{data:a,onRefresh:()=>{M({silent:!0})}}):null,s==="github"?i.jsx(ste,{},I):null,s==="workflows"?i.jsx(lee,{}):null,s==="agent"?i.jsx(CU,{focusChanges:g,onOpenAgentEnv:()=>n("agent-env")}):null,s==="agent-env"?i.jsx(ZU,{}):null,s==="errors"?i.jsx(tX,{inScope:q?$=>q.has($):void 0,onReviewChanges:()=>{p($=>$+1),n("agent")}}):null,s==="database"?i.jsx(LY,{projects:a?.config.gitRepositories??[],scopePath:G?.path??null,staged:f,onStageConsumed:()=>h(null)}):null,s==="terminal"?i.jsx(kZ,{}):null,s==="settings"?i.jsx(VY,{activeProject:a?.git.selectedRepository??null,onNavigate:$=>n($)}):null]})]})]}),a&&s==="git"?i.jsx(dte,{ahead:a.git.status?.ahead??0,behind:a.git.status?.behind??0,branches:a.git.branches,currentBranch:a.git.status?.branch||void 0,disabled:!a.git.status,onRefresh:M,upstream:a.git.status?.upstream}):null,i.jsx(rY,{currentPage:s,git:a?.git,onNavigate:$=>n($),onGitRefresh:()=>{M({silent:!0})}})]})]})})})})]})}function Ate({docked:e,label:t}){return i.jsx("div",{className:"flex h-5 items-center overflow-hidden px-3",children:i.jsx("span",{className:oe("whitespace-pre text-[10px] font-semibold uppercase tracking-widest text-muted-foreground transition-opacity duration-150",e?"opacity-100":"opacity-0 group-hover/sidebar:opacity-100"),children:t})})}function KN({active:e,badge:t,docked:s,icon:n,label:a,onClick:l}){const c=t!==void 0&&t>0;return i.jsxs(Q,{"aria-label":a,title:a,className:_te(e,s),variant:"ghost",onClick:l,type:"button",children:[i.jsx("span",{className:Ste(s),children:n}),i.jsx("span",{className:wte(s,c),children:a}),t!==void 0&&t>0?i.jsx(Ke,{appearance:t>0?"solid":"outline",className:oe("min-w-6 justify-center px-1.5 font-mono shadow-none",e?"border-primary-foreground/40 bg-primary-foreground/15 text-primary-foreground dark:border-primary-foreground/40 dark:bg-primary-foreground/15 dark:text-primary-foreground":t>0?"":"border-border bg-background text-muted-foreground","absolute right-1.5 top-1.5 h-4 min-w-4 rounded-full px-1 text-[10px] leading-none shadow-none group-hover/sidebar:right-2 group-hover/sidebar:top-1/2 group-hover/sidebar:-translate-y-1/2 group-hover/sidebar:text-xs",s&&"right-2 top-1/2 -translate-y-1/2 text-xs"),size:"small",variant:t>0?"success":"outline",children:t}):null]})}XN.createRoot(document.getElementById("root")).render(i.jsx(x.StrictMode,{children:i.jsx(Nte,{})}));export{i as j,x as r};
|
|
227
|
+
`),provider:a?.id,signal:E.signal});E.signal.aborted||c(T)}catch(T){E.signal.aborted||_(T instanceof Error?T.message:String(T))}finally{S.current===E&&(S.current=null,f(!1))}}async function A(){if(C){g(!0),_(null);try{await l7(C),b(C)}catch(j){_(j instanceof Error?j.message:String(j))}finally{g(!1)}}}return i.jsxs("div",{className:"mt-3 rounded-md border border-border bg-muted/35 p-3",children:[i.jsx(Dr,{children:n("workflows.recover.title")}),i.jsx("p",{className:"mb-2 text-[11px] text-muted-foreground",children:n("workflows.recover.desc")}),i.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[i.jsxs(Q,{onClick:()=>{N()},size:"sm",type:"button",children:[i.jsx(Xt,{className:"size-3.5"})," ",n("workflows.recover.recommend")]}),p?i.jsxs(Q,{onClick:t,size:"sm",type:"button",variant:"outline",children:[i.jsx(Or,{className:"size-3.5"})," ",n("workflows.recover.runAgain")]}):null]}),d?i.jsxs("p",{className:"mt-2 flex items-center gap-1 text-[11px] text-muted-foreground",children:[i.jsx(Lt,{className:"size-3 animate-spin"})," ",n("workflows.recover.choosing")]}):null,C?i.jsxs("div",{className:"mt-3 rounded-md border border-border bg-background p-2.5",children:[i.jsx(Dr,{children:n("workflows.recover.recommendedBranch")}),i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[i.jsx("code",{className:"min-w-0 rounded bg-muted px-2 py-1 font-mono text-[12px] text-foreground",children:C}),i.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[i.jsxs(Q,{disabled:h||p===C,onClick:()=>{A()},size:"sm",type:"button",children:[h?i.jsx(Lt,{className:"size-3.5 animate-spin"}):i.jsx(Ys,{className:"size-3.5"}),n("workflows.recover.createBranch")]}),i.jsxs(Q,{disabled:h,onClick:()=>{N("Recommend a different concise branch name. Keep the same output contract with `BRANCH_NAME: <branch-name>`.")},size:"sm",type:"button",variant:"outline",children:[i.jsx(Xt,{className:"size-3.5"})," ",n("workflows.recover.askAnother")]})]})]})]}):l&&!d?i.jsxs("div",{className:"mt-3 rounded-md border border-border bg-background p-2.5",children:[i.jsx("p",{className:"text-[11px] text-muted-foreground",children:n("workflows.recover.noBranch")}),i.jsxs(Q,{className:"mt-2",onClick:()=>{N("Return only a concise branch suggestion using this exact line: `BRANCH_NAME: <branch-name>`.")},size:"sm",type:"button",variant:"outline",children:[i.jsx(Xt,{className:"size-3.5"})," ",n("workflows.recover.askAnother")]})]}):null,p?i.jsxs("p",{className:"mt-2 text-[11px] text-emerald-700 dark:text-emerald-400",children:[n("workflows.recover.createdPre"),i.jsx("code",{className:"font-mono",children:p}),n("workflows.recover.createdPost")]}):null,v?i.jsx("p",{className:"mt-2 text-[11px] text-destructive",children:v}):null]})}const zN={running:"workflows.status.running",waiting:"workflows.status.waiting",done:"workflows.status.done",blocked:"workflows.status.needsYou",failed:"workflows.status.failed",skipped:"workflows.status.skipped",pending:"workflows.status.queued"},bT={gate:"workflows.kind.gate",agent:"workflows.kind.agent",action:"workflows.kind.action"};function yee({output:e,previousOutput:t,status:s,step:n}){const a=ee();if(n.kind==="gate"){const c=n.id==="gate-commit"?t?.trim():"";return i.jsxs("div",{children:[i.jsx("p",{className:"text-muted-foreground",children:n.message}),c?i.jsxs("div",{className:"mt-3",children:[i.jsx(Dr,{children:a("workflows.step.generatedCommitMessage")}),i.jsx("div",{className:"whitespace-pre-wrap break-words rounded-md border border-border bg-muted/50 px-2.5 py-2 font-mono text-[11px] text-foreground",children:c})]}):null]})}if(n.kind==="action")return i.jsx("p",{className:"text-muted-foreground",children:a(vT[n.op])});const l=s==="done"||s==="failed"||s==="skipped";return e?i.jsxs("div",{children:[i.jsx(Dr,{children:a("workflows.step.result")}),i.jsx("div",{className:"whitespace-pre-wrap break-words rounded-md bg-muted/50 px-2.5 py-2 font-mono text-[11px] text-foreground",children:e})]}):i.jsxs("div",{children:[i.jsx(Dr,{children:a(l?"workflows.step.result":"workflows.step.task")}),l?i.jsx("p",{className:"italic text-muted-foreground",children:a("workflows.step.noReply")}):i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"text-muted-foreground",children:n.prompt}),s==="running"?i.jsxs("p",{className:"mt-1.5 flex items-center gap-1 text-muted-foreground/80",children:[i.jsx(Lt,{className:"size-3 animate-spin"})," ",a("workflows.step.working")]}):null]})]})}function _ee(e){return e.detected.name==="codex"?e.agents.codex:e.agents["claude-code"]??e}function wee(e){return e?{skills:ru(e.skills.map(t=>t.name)),mcpServers:ru(e.mcpServers.map(t=>t.name)),plugins:ru(e.plugins.map(t=>t.name)),hooks:ru(e.hooks.map(t=>t.matcher?`${t.event}: ${t.matcher}`:t.event))}:{skills:[],mcpServers:[],plugins:[],hooks:[]}}function See(e){return{id:l1("custom-workflow",e),name:"Custom workflow",description:"A user-built workflow.",builtin:!1,steps:[{kind:"gate",id:"gate-start",title:"Approve start",message:"Run this workflow?"}]}}function kee(e){const t=Sl(e.id)||e.kind,s=e.title.trim()||Pf(e);if(e.kind==="gate")return{...e,id:t,title:s,message:e.message.trim()||"Continue?"};if(e.kind==="action")return{...e,id:t,title:s};const n=xT(e.capabilities);return{...e,id:t,title:s,prompt:e.prompt.trim()||"Complete this workflow step.",capabilities:n}}const vT={"assert-pr-branch":"workflows.opDesc.assertPrBranch","checkout-default-and-pull":"workflows.opDesc.checkoutDefault",push:"workflows.opDesc.push",commit:"workflows.opDesc.commit"};function xT(e){if(!e)return;const t={};for(const s of["skills","mcpServers","plugins","hooks"]){const n=ru((e[s]??[]).map(a=>a.trim()).filter(Boolean));n.length&&(t[s]=n)}return Object.keys(t).length?t:void 0}function Cee(e,t,s){const n=e?.[t]??[],a=n.includes(s)?n.filter(l=>l!==s):[...n,s];return xT({...e??{},[t]:a})}function l1(e,t){const s=new Set(t.map(l=>l.id));let n=Sl(e)||"workflow",a=2;for(;s.has(n);)n=`${Sl(e)||"workflow"}-${a}`,a++;return n}function Sl(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function ru(e){return Array.from(new Set(e.filter(Boolean)))}function Dr({children:e}){return i.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/70",children:e})}function Px(e){return new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"2-digit"}).format(new Date(e))}function yT({outcome:e}){const t=ee(),s={running:{labelKey:"workflows.status.running",className:"border-primary/40 text-primary"},done:{labelKey:"workflows.status.done",className:"border-emerald-500/40 text-emerald-600 dark:text-emerald-400"},stopped:{labelKey:"workflows.status.stopped",className:"border-border text-muted-foreground"},failed:{labelKey:"workflows.status.failed",className:"border-destructive/40 text-destructive"},blocked:{labelKey:"workflows.status.needsYou",className:"border-amber-500/40 text-amber-700 dark:text-amber-400"}},{labelKey:n,className:a}=s[e];return i.jsx("span",{className:oe("rounded-full border px-2 py-0.5 text-[10px] font-medium",a),children:t(n)})}function _T({kind:e}){return e==="gate"?i.jsx(vE,{className:"size-4 text-amber-600 dark:text-amber-400"}):e==="agent"?i.jsx(zn,{className:"size-4 text-primary"}):i.jsx(Or,{className:"size-4 text-muted-foreground"})}function BN({status:e,kind:t}){return e==="running"?i.jsx(Lt,{className:"size-4 shrink-0 animate-spin text-primary"}):e==="waiting"?i.jsx(vE,{className:"size-4 shrink-0 text-primary"}):e==="done"?i.jsx(Ys,{className:"size-4 shrink-0 text-emerald-600 dark:text-emerald-400"}):e==="blocked"?i.jsx(Uf,{className:"size-4 shrink-0 text-amber-600 dark:text-amber-400"}):e==="failed"?i.jsx(Lr,{className:"size-4 shrink-0 text-destructive"}):e==="skipped"?i.jsx(xE,{className:"size-4 shrink-0 text-muted-foreground/60"}):t==="agent"?i.jsx(zn,{className:"size-4 shrink-0 text-muted-foreground/50"}):i.jsx(wM,{className:"size-4 shrink-0 text-muted-foreground/50"})}function Nee(e){return i.jsx(_n,{className:"size-3 shrink-0 text-muted-foreground/40","aria-hidden":!0})}function zx({kind:e}){const t=ee(),s=e==="agent"?"border-primary/30 text-primary":e==="gate"?"border-amber-500/40 text-amber-600 dark:text-amber-400":"border-border text-muted-foreground";return i.jsx("span",{className:oe("shrink-0 rounded-full border px-1.5 py-px text-[9px] uppercase tracking-wide",s),children:t(bT[e])})}function Pf(e){return e.title}function Eee(){const[e,t]=x.useState(!1),[s,n]=x.useState(!1),[a,l]=x.useState(!0),[c,d]=x.useState("checking"),[f,h]=x.useState(null),[g,p]=x.useState(null);function b(){l(!0),d("checking"),h(null),p7().then(v=>{t(v.configured),n(v.deviceFlowAvailable),d(v.status),h(v.error??null),p(v)}).catch(v=>{t(!1),n(!1),d("connection_error"),h(v instanceof Error?v.message:String(v)),p(null)}).finally(()=>l(!1))}return x.useEffect(()=>{b()},[]),{configured:e,deviceFlowAvailable:s,loading:a,status:c,error:f,info:g,isConnected:c==="connected",needsLogin:c==="not_configured"||c==="auth_error",refresh:b}}const cv=30;function jee(e="open"){const[t,s]=x.useState([]),[n,a]=x.useState(!0),[l,c]=x.useState(!1),[d,f]=x.useState(!1),[h,g]=x.useState(1),[p,b]=x.useState(null),[v,_]=x.useState(null),[S,C]=x.useState(null),[N,A]=x.useState(""),[j,E]=x.useState(!1),[T,L]=x.useState(null);x.useEffect(()=>{let F=!0;return a(!0),b(null),g(1),Pg(e,1).then(M=>{F&&(s(M),f(M.length===cv),M.length>0&&!M.some(z=>z.number===v)&&_(M[0]?.number??null))}).catch(M=>{F&&b(M instanceof Error?M.message:String(M))}).finally(()=>{F&&a(!1)}),()=>{F=!1}},[e]),x.useEffect(()=>{if(!v){C(null);return}let F=!0;return _7(v).then(M=>{F&&C(M)}).catch(()=>{}),()=>{F=!1}},[v]),x.useEffect(()=>{if(!v){A("");return}let F=!0;return E(!0),L(null),w7(v).then(M=>{F&&A(M)}).catch(M=>{F&&L(M instanceof Error?M.message:String(M))}).finally(()=>{F&&E(!1)}),()=>{F=!1}},[v]);function H(){if(l||!d)return;const F=h+1;c(!0),Pg(e,F).then(M=>{s(z=>{const G=new Set(z.map(D=>D.number));return[...z,...M.filter(D=>!G.has(D.number))]}),f(M.length===cv),g(F)}).catch(M=>b(M instanceof Error?M.message:String(M))).finally(()=>c(!1))}function P(){let F=!0;return a(!0),b(null),g(1),Pg(e,1).then(M=>{F&&(s(M),f(M.length===cv))}).catch(M=>{F&&b(M instanceof Error?M.message:String(M))}).finally(()=>{F&&a(!1)}),()=>{F=!1}}return{prs:t,loading:n,loadingMore:l,hasMore:d,error:p,selectedNumber:v,setSelectedNumber:_,selectedPR:S,diff:N,diffLoading:j,diffError:T,loadMore:H,refresh:P}}const uv=30;function Aee(e="open"){const[t,s]=x.useState([]),[n,a]=x.useState(!0),[l,c]=x.useState(!1),[d,f]=x.useState(!1),[h,g]=x.useState(1),[p,b]=x.useState(null),[v,_]=x.useState(null),[S,C]=x.useState(null),[N,A]=x.useState([]),[j,E]=x.useState(!1),[T,L]=x.useState(null),[H,P]=x.useState(!1);x.useEffect(()=>{let G=!0;return a(!0),b(null),g(1),zg(e,1).then(D=>{G&&(s(D),f(D.length===uv),D.length>0&&!D.some(q=>q.number===v)&&_(D[0]?.number??null))}).catch(D=>{G&&b(D instanceof Error?D.message:String(D))}).finally(()=>{G&&a(!1)}),()=>{G=!1}},[e]),x.useEffect(()=>{if(!v){C(null),A([]);return}let G=!0;return E(!0),Promise.all([E7(v),j7(v)]).then(([D,q])=>{G&&(C(D),A(q))}).catch(()=>{}).finally(()=>{G&&E(!1)}),()=>{G=!1}},[v]);async function F(G){if(v){P(!0),L(null);try{const D=await A7(v,G);A(q=>[...q,D])}catch(D){L(D instanceof Error?D.message:String(D))}finally{P(!1)}}}function M(){if(l||!d)return;const G=h+1;c(!0),zg(e,G).then(D=>{s(q=>{const W=new Set(q.map(I=>I.number));return[...q,...D.filter(I=>!W.has(I.number))]}),f(D.length===uv),g(G)}).catch(D=>b(D instanceof Error?D.message:String(D))).finally(()=>c(!1))}function z(){let G=!0;return a(!0),g(1),zg(e,1).then(D=>{G&&(s(D),f(D.length===uv))}).catch(()=>{}).finally(()=>{G&&a(!1)}),()=>{G=!1}}return{issues:t,loading:n,loadingMore:l,hasMore:d,error:p,selectedNumber:v,setSelectedNumber:_,selectedIssue:S,comments:N,commentsLoading:j,commentError:T,submitting:H,addComment:F,loadMore:M,refresh:z}}function wT({deviceFlowAvailable:e,initialMode:t,onSaved:s}){const n=ee(),[a,l]=x.useState(()=>t==="device-pending"&&!e?"pat":t??(e?"choose":"pat"));return a==="device-pending"?i.jsx(Tee,{onSuccess:s,onCancel:()=>l("choose")}):a==="pat"?i.jsx(Ree,{onSaved:s,onBack:e?()=>l("choose"):void 0}):i.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[i.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[i.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-muted",children:i.jsx(Qw,{className:"size-6 text-muted-foreground"})}),i.jsxs("div",{children:[i.jsx("h2",{className:"text-base font-semibold",children:n("github.setup.connectTitle")}),i.jsx("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:n("github.setup.connectDesc")})]})]}),i.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-2",children:[i.jsxs(Q,{className:"w-full",onClick:()=>l("device-pending"),type:"button",children:[i.jsx(Qw,{className:"mr-2 size-4"}),n("github.setup.authorizeWith")]}),i.jsx("button",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",onClick:()=>l("pat"),type:"button",children:n("github.setup.usePat")})]})]})}function Tee({onSuccess:e,onCancel:t}){const s=ee(),[n,a]=x.useState(null),[l,c]=x.useState(null),[d,f]=x.useState(!0),[h,g]=x.useState(!1),p=x.useRef(null),b=x.useRef(5),v=x.useRef(!1);x.useEffect(()=>{let N=!0;return g7().then(A=>{if(!N)return;a(A),b.current=A.interval,f(!1);const j=A.verification_uri_complete||A.verification_uri;j&&Qf(j),_(A.device_code,A.interval),setTimeout(()=>{v.current=!0},A.expires_in*1e3)}).catch(A=>{N&&(c(A instanceof Error?A.message:String(A)),f(!1))}),()=>{N=!1,p.current&&clearTimeout(p.current)}},[]);function _(N,A){p.current=setTimeout(()=>{S(N,A)},A*1e3)}async function S(N,A){if(v.current){c(s("github.setup.expired"));return}try{const j=await b7(N);if(j.done){e();return}const E=j.slowDown?A+5:A;b.current=E,_(N,E)}catch{_(N,b.current)}}function C(){n&&navigator.clipboard.writeText(n.user_code).then(()=>{g(!0),setTimeout(()=>g(!1),2e3)})}return d?i.jsx("div",{className:"flex h-full items-center justify-center",children:i.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[i.jsx(Jw,{className:"size-6 animate-spin text-muted-foreground"}),i.jsx("p",{className:"text-[13px] text-muted-foreground",children:s("github.setup.requesting")})]})}):l?i.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-4 p-8",children:[i.jsx(tt,{variant:"destructive",children:l}),i.jsx(Q,{onClick:t,variant:"outline",children:s("github.setup.goBack")})]}):i.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[i.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[i.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-emerald-100 dark:bg-emerald-500/15",children:i.jsx(qf,{className:"size-6 text-emerald-600 dark:text-emerald-400"})}),i.jsxs("div",{children:[i.jsx("h2",{className:"text-base font-semibold",children:s("github.setup.authorizeOnTitle")}),i.jsxs("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:[s("github.setup.enterCodePre"),i.jsx("strong",{children:s("github.setup.authorizeWord")}),s("github.setup.enterCodePost")]})]})]}),i.jsxs("div",{className:"flex flex-col items-center gap-2",children:[i.jsx("div",{className:"flex cursor-pointer select-all items-center gap-3 rounded-xl border-2 border-border bg-muted px-6 py-4 font-mono text-2xl font-bold tracking-[0.3em] transition-colors hover:border-ring",onClick:C,title:s("github.setup.clickToCopy"),children:n?.user_code}),i.jsx("button",{className:"text-[11px] text-muted-foreground transition-colors hover:text-foreground",onClick:C,type:"button",children:s(h?"common.copied":"github.setup.clickCodeCopy")})]}),i.jsxs("div",{className:"flex flex-col items-center gap-2",children:[i.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-muted-foreground",children:[i.jsx(Jw,{className:"size-3.5 animate-spin"}),s("github.setup.waiting")]}),i.jsx("a",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",href:n?.verification_uri_complete||n?.verification_uri,rel:"noopener noreferrer",target:"_blank",children:s("github.setup.openAgain")}),i.jsx("button",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",onClick:t,type:"button",children:s("common.cancel")})]})]})}function Ree({onSaved:e,onBack:t}){const s=ee(),[n,a]=x.useState(""),[l,c]=x.useState(!1),[d,f]=x.useState(null);async function h(g){g.preventDefault();const p=n.trim();if(p){c(!0),f(null);try{await v7("github.com",p),e()}catch(b){f(b instanceof Error?b.message:String(b))}finally{c(!1)}}}return i.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[i.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[i.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-muted",children:i.jsx(uE,{className:"size-6 text-muted-foreground"})}),i.jsxs("div",{children:[i.jsx("h2",{className:"text-base font-semibold",children:s("github.setup.patTitle")}),i.jsxs("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:[s("github.setup.patDescPre"),i.jsx("a",{className:"underline underline-offset-2 hover:text-foreground",href:"https://github.com/settings/tokens/new?scopes=repo,workflow",rel:"noopener noreferrer",target:"_blank",children:"github.com/settings/tokens"}),s("github.setup.patDescMid"),i.jsx("code",{className:"rounded bg-muted px-1 py-px text-[11px]",children:"repo"}),s("github.setup.patDescAnd"),i.jsx("code",{className:"rounded bg-muted px-1 py-px text-[11px]",children:"workflow"}),s("github.setup.patDescPost")]})]})]}),i.jsxs("form",{className:"flex w-full max-w-sm flex-col gap-3",onSubmit:g=>{h(g)},children:[i.jsx("input",{autoComplete:"off",className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-[13px] placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring",onChange:g=>a(g.target.value),placeholder:"ghp_...",spellCheck:!1,type:"password",value:n}),d?i.jsx(tt,{variant:"destructive",children:d}):null,i.jsx(Q,{disabled:!n.trim()||l,type:"submit",children:s(l?"common.saving":"github.setup.saveToken")}),t?i.jsx("button",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",onClick:t,type:"button",children:s("github.setup.back")}):null]})]})}function c1({hasMore:e,loading:t,onLoadMore:s}){const n=ee();return e?i.jsx("div",{className:"p-2",children:i.jsxs("button",{className:"flex w-full items-center justify-center gap-1.5 rounded-md border border-border py-1.5 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground disabled:opacity-60",disabled:t,onClick:s,type:"button",children:[t?i.jsx(Lt,{className:"size-3 animate-spin"}):null,n(t?"common.loading":"github.loadMore")]})}):null}function Mee({prs:e,loading:t,loadingMore:s,hasMore:n,error:a,selectedNumber:l,onSelect:c,onLoadMore:d}){const f=ee();return t&&e.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.prs.loading")}):a?i.jsx("div",{className:"p-4 text-[12px] text-red-500",children:a}):e.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.prs.empty")}):i.jsxs(i.Fragment,{children:[i.jsx("ul",{className:"divide-y divide-border",children:e.map(h=>i.jsx("li",{children:i.jsxs("button",{className:`flex w-full items-start gap-3 px-3 py-2.5 text-left transition-colors hover:bg-muted/60 ${l===h.number?"bg-muted":""}`,onClick:()=>c(h.number),type:"button",children:[i.jsx("span",{className:"mt-0.5 shrink-0",children:i.jsx(Dee,{pr:h})}),i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"block truncate text-[13px] font-medium",children:h.title}),i.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",h.number," · ",h.base.ref," ← ",h.head.ref," · ",h.user.login]})]}),h.draft?i.jsx("span",{className:"shrink-0 rounded border border-border px-1.5 py-px text-[10px] text-muted-foreground",children:f("github.prs.draft")}):null]})},h.number))}),i.jsx(c1,{hasMore:n,loading:s,onLoadMore:d})]})}function Dee({pr:e}){return e.state==="merged"?i.jsx(sf,{className:"size-4 text-purple-500"}):e.state==="closed"?i.jsx(b6,{className:"size-4 text-red-500"}):i.jsx(cE,{className:"size-4 text-emerald-500"})}function ST({body:e,title:t}){const s=ee(),n=t??s("github.md.description"),[a,l]=x.useState("rendered"),c=d=>oe("rounded px-1.5 py-0.5 text-[10px] font-medium transition-colors",d?"bg-foreground text-background":"text-muted-foreground hover:text-foreground");return i.jsxs("section",{className:"overflow-hidden rounded-md border border-border bg-muted/25",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[i.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:n}),i.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-background/60 p-0.5",children:[i.jsx("button",{className:c(a==="rendered"),onClick:()=>l("rendered"),type:"button",children:s("github.md.rendered")}),i.jsx("button",{className:c(a==="raw"),onClick:()=>l("raw"),type:"button",children:s("github.md.raw")})]})]}),a==="rendered"?i.jsx(r1,{content:e}):i.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap px-3 py-3 font-mono text-[12px]",children:e})]})}function Lee({pr:e,diff:t,diffLoading:s,diffError:n,onMerged:a}){const l=ee(),[c,d]=x.useState("cockpit"),[f,h]=x.useState(null),[g,p]=x.useState(!1),[b,v]=x.useState(null),[_,S]=x.useState(null),[C,N]=x.useState(!1),[A,j]=x.useState(null),[E,T]=x.useState(!1),{sendToAgent:L}=Ot(),{isPending:H,runOperation:P}=si(),F=e?`github:pr:${e.number}:merge`:"",M=F?H(F):!1,z=x.useMemo(()=>J$(t),[t]);x.useEffect(()=>{j($=>$&&z.some(me=>me.path===$)?$:z[0]?.path??null)},[z]);const G=z.find($=>$.path===A)??z[0]??null;function D($){j($),d("diff")}function q($,me){e&&(T(!1),L({prompt:me?PF(e,me,$):OF(e,$),source:{type:"github-pr",label:`PR #${e.number}${me?` · ${zf(me)}`:""}`},label:`PR #${e.number}${me?` (${zf(me)})`:""}: ${$}`}))}if(x.useEffect(()=>{if(T(!1),!e){h(null);return}let $=!0;return p(!0),v(null),S7(e.number).then(me=>{$&&h(me)}).catch(me=>{$&&v(me instanceof Error?me.message:String(me))}).finally(()=>{$&&p(!1)}),()=>{$=!1}},[e]),!e)return i.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:l("github.pr.selectPrompt")});const W=e.state==="open"&&!e.draft;async function I(){if(!(!e||M)){S(null);try{await P({errorMessage:$=>$ instanceof Error?$.message:String($),key:F,label:l("github.pr.mergingOperation",{number:e.number})},()=>N7(e.number,{method:"squash"})),N(!1),a?.()}catch($){S($ instanceof Error?$.message:String($)),N(!1)}}}const Y=$=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${$?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`;return i.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[i.jsxs("div",{className:"group flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[i.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-semibold",children:e.title}),i.jsx(ir,{className:oe("shrink-0",E&&"opacity-100"),label:l("github.pr.askLabel",{number:e.number}),onAsk:()=>T($=>!$)}),i.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[i.jsx("button",{className:Y(c==="cockpit"),onClick:()=>d("cockpit"),type:"button",children:l("github.pr.tabReview")}),i.jsx("button",{className:Y(c==="diff"),onClick:()=>d("diff"),type:"button",children:l("github.pr.tabDiff")})]}),W?i.jsxs(Q,{className:"shrink-0",loading:M,loadingLabel:l("github.pr.merging"),onClick:()=>N(!0),size:"sm",title:l("github.pr.squashTitle"),type:"button",variant:"success",children:[i.jsx(sf,{}),l("github.pr.squashMerge")]}):null,i.jsx("a",{"aria-label":l("github.openOnGithub"),className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:e.html_url,rel:"noopener noreferrer",target:"_blank",title:l("github.openOnGithub"),children:i.jsx(ja,{className:"size-3.5"})})]}),_?i.jsx("div",{className:"shrink-0 border-b border-border bg-red-500/10 px-3 py-1.5 text-[11px] text-red-500",children:_}):null,E?i.jsx("div",{className:"shrink-0 border-b border-border px-3 py-1.5",children:i.jsx(Ir,{placeholder:l("github.pr.askPlaceholder"),onSubmit:$=>q($),onCancel:()=>T(!1)})}):null,c==="cockpit"?i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:i.jsx(Oee,{cockpit:f,error:b,loading:g,onOpenFile:D,pr:e})}):s?i.jsx(sm,{className:"flex-1",label:l("git.diff.loading")}):n?i.jsx("div",{className:"p-4 text-[12px] text-red-500",children:n}):z.length?i.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1",children:[i.jsx(Pee,{files:z,onAsk:($,me)=>q(me,$),onSelect:j,selected:G?.path??null}),i.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:G?i.jsx(Ou,{diff:G.diff}):null})]}):i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:l("github.pr.noDiff")}),C?i.jsx(Ol,{confirmLabel:M?i.jsxs(i.Fragment,{children:[i.jsx(tm,{size:"sm"})," ",l("github.pr.merging")]}):l("github.pr.squashMerge"),icon:i.jsx(sf,{}),loading:M,message:i.jsxs(i.Fragment,{children:[l("github.pr.confirmPre"),i.jsxs("span",{className:"font-mono",children:["#",e.number]})," ",i.jsx("span",{className:"font-medium text-foreground",children:e.title}),l("github.pr.confirmInto"),i.jsx("span",{className:"font-mono",children:e.base.ref}),l("github.pr.confirmQ")]}),onCancel:()=>N(!1),onConfirm:()=>{I()},title:l("github.pr.squashMerge"),tone:"success"}):null]})}function Oee({pr:e,cockpit:t,loading:s,error:n,onOpenFile:a}){const l=ee(),[c,d]=x.useState(!1),f=t?.pr??e,h=t?.files??[],g=t?.reviews??[],p=t?.comments??[],b=t?.checks??null,v=b?.runs.filter(_=>_.conclusion==="failure"||_.conclusion==="timed_out"||_.conclusion==="cancelled")??[];return i.jsxs("div",{className:"space-y-3 p-4",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 text-[12px]",children:[i.jsx(Iee,{pr:f}),i.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md border border-border bg-muted/40 px-2 py-1 font-mono text-[11px]",children:[i.jsx(Pn,{className:"size-3 shrink-0 text-muted-foreground"}),f.base.ref,i.jsx(Eu,{className:"size-3 shrink-0 text-muted-foreground"}),f.head.ref]}),i.jsxs("span",{className:"inline-flex items-center gap-1 text-muted-foreground",children:[i.jsx(m8,{className:"size-3 shrink-0"}),f.user.login]}),i.jsxs("span",{className:"inline-flex items-center gap-1 text-muted-foreground",children:[i.jsx(dM,{className:"size-3 shrink-0"}),new Date(f.created_at).toLocaleDateString()]})]}),n?i.jsx("div",{className:"rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-[12px] text-red-500",children:n}):null,s?i.jsx(sm,{className:"justify-start",label:l("github.pr.loadingCockpit")}):null,i.jsxs("div",{className:"grid gap-2 md:grid-cols-4",children:[i.jsx(Oh,{title:l("github.pr.mergeReadiness"),value:l(kT(f,b)),tone:zee(f,b)}),i.jsx(Oh,{title:l("github.pr.reviewStateTitle"),value:l(CT(g)),tone:Bee(g)}),i.jsx(Oh,{title:l("github.pr.checks"),value:b?l("github.pr.checksValue",{state:b.state,count:b.totalCount}):l("github.pr.unknown"),tone:b?.state==="success"?"success":b?.state==="failure"||b?.state==="error"?"danger":"muted"}),i.jsx(Oh,{title:l("github.pr.changedFiles"),value:String(h.length),tone:"muted"})]}),v.length>0?i.jsxs("section",{className:"rounded-md border border-red-500/25 bg-red-500/10 px-3 py-2",children:[i.jsx("div",{className:"mb-1 text-[11px] font-medium text-red-500",children:l("github.pr.failingChecks")}),i.jsx("div",{className:"flex flex-wrap gap-2",children:v.slice(0,4).map(_=>i.jsxs("a",{className:"inline-flex items-center gap-1 text-[11px] text-red-500 underline-offset-2 hover:underline",href:_.html_url,rel:"noopener noreferrer",target:"_blank",children:[i.jsx(Ix,{className:"size-3"}),l("github.pr.openFailingCheck",{name:_.name})]},_.id))})]}):null,i.jsxs("section",{className:"rounded-md border border-border bg-muted/25 p-3",children:[i.jsxs("button",{className:"flex w-full items-center gap-2 text-[12px] font-medium",onClick:()=>d(_=>!_),type:"button",children:[c?i.jsx(hn,{className:"size-3.5 text-muted-foreground"}):i.jsx(_n,{className:"size-3.5 text-muted-foreground"}),i.jsx($x,{className:"size-3.5 text-muted-foreground"}),l("github.pr.changedFiles"),h.length?i.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:["(",h.length,")"]}):null]}),c?h.length?i.jsx("ul",{className:"mt-2 divide-y divide-border",children:h.slice(0,12).map(_=>i.jsx("li",{children:i.jsxs("button",{className:"flex w-full items-center gap-2 py-1.5 text-left text-[12px] transition-colors hover:text-foreground",onClick:()=>a(_.path),title:l("github.pr.viewDiffTitle",{path:_.path}),type:"button",children:[i.jsx("span",{className:"w-16 shrink-0 font-mono text-[10px] uppercase text-muted-foreground",children:_.status}),i.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:_.path}),i.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-emerald-600",children:["+",_.additions]}),i.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-red-500",children:["-",_.deletions]})]})},_.path))}):i.jsx("p",{className:"mt-2 text-[12px] text-muted-foreground",children:l("github.pr.noFileMeta")}):null]}),i.jsxs("section",{className:"rounded-md border border-border bg-muted/25 p-3",children:[i.jsxs("div",{className:"mb-2 flex items-center gap-2 text-[12px] font-medium",children:[i.jsx(oD,{className:"size-3.5 text-muted-foreground"}),l("github.pr.reviewStateTitle")]}),g.length||p.length?i.jsxs("div",{className:"space-y-2",children:[g.slice(-4).map(_=>i.jsx(IN,{href:_.html_url,meta:`${_.user.login} - ${_.state.toLowerCase()}`,text:_.body||l("github.pr.noReviewSummary")},`review:${_.id}`)),p.slice(-4).map(_=>i.jsx(IN,{href:_.html_url,meta:l("github.pr.reviewMetaComment",{login:_.user.login}),text:_.body},`comment:${_.id}`))]}):i.jsx("p",{className:"text-[12px] text-muted-foreground",children:l("github.pr.noReviews")})]}),f.body?i.jsx(ST,{body:f.body}):i.jsx("p",{className:"text-[12px] italic text-muted-foreground",children:l("github.noDescription")})]})}function Pee({files:e,selected:t,onSelect:s,onAsk:n}){const a=ee(),[l,c]=x.useState(null);return i.jsx("div",{className:"w-44 shrink-0 overflow-y-auto border-r border-border bg-card/60",children:i.jsx("ul",{className:"py-1",children:e.map(d=>i.jsxs("li",{className:"group flex flex-col",children:[i.jsxs("div",{className:oe("flex items-center transition-colors",d.path===t?"bg-muted":"hover:bg-muted/60"),children:[i.jsxs("button",{className:oe("flex min-w-0 flex-1 items-center gap-1.5 px-2.5 py-1.5 text-left text-[11px]",d.path===t?"text-foreground":"text-muted-foreground group-hover:text-foreground"),onClick:()=>s(d.path),title:d.path,type:"button",children:[i.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:zf(d.path)}),i.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-emerald-600",children:["+",d.additions]}),i.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-red-500",children:["-",d.deletions]})]}),i.jsx(ir,{className:oe("mr-1 shrink-0",l===d.path&&"opacity-100"),label:a("github.pr.askFileLabel",{name:zf(d.path)}),onAsk:()=>c(f=>f===d.path?null:d.path)})]}),l===d.path?i.jsx("div",{className:"px-2 pb-1.5 pt-0.5",children:i.jsx(Ir,{placeholder:a("github.pr.askFilePlaceholder"),onSubmit:f=>{c(null),n(d.path,f)},onCancel:()=>c(null)})}):null]},d.path))})})}function zf(e){const t=e.split("/");return t[t.length-1]||e}function Oh({title:e,value:t,tone:s}){const n=s==="success"?"bg-emerald-500":s==="warning"?"bg-amber-500":s==="danger"?"bg-red-500":"bg-muted-foreground";return i.jsxs("div",{className:"rounded-md border border-border bg-card px-3 py-2",children:[i.jsx("div",{className:"text-[10px] uppercase text-muted-foreground",children:e}),i.jsxs("div",{className:"mt-1 flex items-center gap-1.5 text-[12px] font-medium",children:[i.jsx("span",{className:`size-1.5 rounded-full ${n}`}),t]})]})}function IN({meta:e,text:t,href:s}){return i.jsxs("a",{className:"block rounded border border-border bg-card px-2.5 py-2 text-[12px] transition-colors hover:bg-muted/60",href:s,rel:"noopener noreferrer",target:"_blank",children:[i.jsxs("span",{className:"mb-1 flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[i.jsx(ja,{className:"size-3"}),e]}),i.jsx("span",{className:"line-clamp-2 whitespace-pre-wrap",children:t})]})}function kT(e,t){return e.state==="merged"?"github.pr.readiness.merged":e.state==="closed"?"github.pr.readiness.closed":e.draft?"github.pr.readiness.draft":e.mergeable===!1?"github.pr.readiness.blocked":t?.state==="failure"||t?.state==="error"?"github.pr.readiness.checksFailing":t?.state==="pending"?"github.pr.readiness.checksPending":e.mergeable===!0?"github.pr.readiness.ready":"github.pr.unknown"}function zee(e,t){const s=kT(e,t);return s==="github.pr.readiness.ready"?"success":s==="github.pr.readiness.blocked"||s==="github.pr.readiness.checksFailing"?"danger":s==="github.pr.readiness.draft"||s==="github.pr.readiness.checksPending"?"warning":"muted"}function CT(e){return e.some(t=>t.state==="CHANGES_REQUESTED")?"github.pr.review.changesRequested":e.some(t=>t.state==="APPROVED")?"github.pr.review.approved":e.some(t=>t.state==="COMMENTED")?"github.pr.review.commented":"github.pr.review.none"}function Bee(e){const t=CT(e);return t==="github.pr.review.approved"?"success":t==="github.pr.review.changesRequested"?"danger":t==="github.pr.review.commented"?"warning":"muted"}function Iee({pr:e}){const t=ee(),{labelKey:s,dot:n,kind:a}=e.state==="merged"?{labelKey:"github.prState.merged",dot:"bg-violet-500",kind:"merged"}:e.state==="closed"?{labelKey:"github.prState.closed",dot:"bg-red-500",kind:"other"}:e.draft?{labelKey:"github.prState.draft",dot:"bg-muted-foreground",kind:"other"}:{labelKey:"github.prState.open",dot:"bg-emerald-500",kind:"open"};return i.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground",children:[i.jsx("span",{className:`size-1.5 rounded-full ${n}`}),a==="merged"?i.jsx(sf,{className:"size-3"}):a==="open"?i.jsx(qf,{className:"size-3"}):i.jsx(kl,{className:"size-3"}),t(s)]})}function NT({label:e}){return i.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 text-[10px] font-medium text-muted-foreground",title:e.name,children:[i.jsx("span",{className:"size-2 shrink-0 rounded-sm",style:{backgroundColor:`#${e.color}`}}),i.jsx("span",{className:"truncate",children:e.name})]})}function Hee({issues:e,loading:t,loadingMore:s,hasMore:n,error:a,selectedNumber:l,onSelect:c,onLoadMore:d}){const f=ee();return t&&e.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.issues.loading")}):a?i.jsx("div",{className:"p-4 text-[12px] text-red-500",children:a}):e.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.issues.empty")}):i.jsxs(i.Fragment,{children:[i.jsx("ul",{className:"divide-y divide-border",children:e.map(h=>i.jsx("li",{children:i.jsxs("button",{className:`flex w-full items-start gap-3 px-3 py-2.5 text-left transition-colors hover:bg-muted/60 ${l===h.number?"bg-muted":""}`,onClick:()=>c(h.number),type:"button",children:[i.jsx(kM,{className:`mt-0.5 size-4 shrink-0 ${h.state==="open"?"text-emerald-500":"text-red-500"}`}),i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"block truncate text-[13px] font-medium",children:h.title}),i.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",h.number," · ",h.user.login," · ",f("github.issues.commentsCount",{count:h.comments})]})]}),h.labels.length>0?i.jsx("span",{className:"flex max-w-40 shrink-0 flex-wrap justify-end gap-x-2 gap-y-0.5",children:h.labels.slice(0,3).map(g=>i.jsx(NT,{label:g},g.name))}):null]})},h.number))}),i.jsx(c1,{hasMore:n,loading:s,onLoadMore:d})]})}const Ph=6,$ee=6,Fee=8;function Uee(e,t,s,n){const a=Math.max(0,Math.min($ee,e/2,t/2)),l=Math.max(0,Math.min(Fee,s-a,n-a));return[`M ${a} 0`,`H ${e-a}`,`A ${a} ${a} 0 0 1 ${e} ${a}`,`V ${t-n-a}`,`A ${a} ${a} 0 0 1 ${e-a} ${t-n}`,`H ${e-s+l}`,`A ${l} ${l} 0 0 0 ${e-s} ${t-n+l}`,`V ${t-a}`,`A ${a} ${a} 0 0 1 ${e-s-a} ${t}`,`H ${a}`,`A ${a} ${a} 0 0 1 0 ${t-a}`,`V ${a}`,`A ${a} ${a} 0 0 1 ${a} 0`,"Z"].join(" ")}function qee({value:e,onChange:t,placeholder:s,rows:n=3,action:a}){const l=ee(),c=x.useRef(null),d=x.useRef(null),[f,h]=x.useState(null),[g,p]=x.useState({w:0,h:0});x.useLayoutEffect(()=>{const v=c.current,_=d.current;if(!v||!_)return;const S=()=>{h({w:v.clientWidth,h:v.clientHeight}),p({w:_.offsetWidth+Ph*2,h:_.offsetHeight+Ph*2})};S();const C=new ResizeObserver(S);return C.observe(v),C.observe(_),()=>C.disconnect()},[]);const b=f&&g.w&&g.h?Uee(f.w,f.h,g.w,g.h):null;return i.jsxs("div",{className:"relative",ref:c,children:[i.jsx("textarea",{className:"peer block w-full resize-none bg-background px-3 pt-2 font-mono text-[12px] placeholder:text-muted-foreground focus:outline-none",onChange:v=>t(v.target.value),placeholder:s,rows:n,style:{clipPath:b?`path('${b}')`:void 0,paddingBottom:g.h||44},value:e}),f&&b?i.jsxs("svg",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 overflow-visible text-border transition-colors peer-focus:text-foreground/40",fill:"none",height:f.h,viewBox:`0 0 ${f.w} ${f.h}`,width:f.w,children:[i.jsx("title",{children:l("github.commentBorderTitle")}),i.jsx("path",{d:b,stroke:"currentColor",strokeWidth:1})]}):null,i.jsx("div",{className:"absolute",ref:d,style:{bottom:Ph,right:Ph},children:a})]})}function Gee({issue:e,comments:t,commentsLoading:s,commentError:n,submitting:a,onAddComment:l}){const c=ee(),[d,f]=x.useState(""),[h,g]=x.useState(!1),{sendToAgent:p}=Ot(),{isPending:b,runOperation:v}=si(),_=e?`github:issue:${e.number}:comment`:"",S=a||(_?b(_):!1);x.useEffect(()=>{g(!1)},[e?.number]);function C(A){e&&(g(!1),p({prompt:zF(e,A),source:{type:"github-issue",label:`Issue #${e.number}`},label:`Issue #${e.number}: ${A}`}))}if(!e)return i.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:c("github.issue.selectPrompt")});async function N(A){A.preventDefault();const j=d.trim();j&&(await v({key:_,label:c("github.issue.postingOperation",{number:e.number})},()=>l(j)),f(""))}return i.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[i.jsxs("div",{className:"group flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[i.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-semibold",children:e.title}),i.jsx(ir,{className:oe("shrink-0",h&&"opacity-100"),label:c("github.issue.askLabel",{number:e.number}),onAsk:()=>g(A=>!A)}),i.jsx("a",{"aria-label":c("github.openOnGithub"),className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:e.html_url,rel:"noopener noreferrer",target:"_blank",children:i.jsx(ja,{className:"size-3.5"})})]}),h?i.jsx("div",{className:"shrink-0 border-b border-border px-3 py-1.5",children:i.jsx(Ir,{placeholder:c("github.issue.askPlaceholder"),onSubmit:C,onCancel:()=>g(!1)})}):null,i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:i.jsxs("div",{className:"space-y-3 p-4",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[12px]",children:[i.jsxs("span",{className:"text-[11px]",children:[i.jsx("span",{className:"text-muted-foreground",children:c("github.issue.author")}),i.jsx("span",{className:"font-medium",children:e.user.login})]}),i.jsxs("span",{className:"text-[11px]",children:[i.jsx("span",{className:"text-muted-foreground",children:c("github.issue.opened")}),i.jsx("span",{className:"font-medium",children:new Date(e.created_at).toLocaleDateString()})]}),e.labels.map(A=>i.jsx(NT,{label:A},A.name))]}),e.body?i.jsx(ST,{body:e.body}):i.jsx("p",{className:"text-[12px] text-muted-foreground italic",children:c("github.noDescription")}),s?i.jsx(sm,{className:"justify-start",label:c("github.issue.loadingComments")}):i.jsx("div",{className:"space-y-2",children:t.map(A=>i.jsxs("div",{className:"rounded-md border border-border bg-muted/20 p-3",children:[i.jsxs("div",{className:"mb-1 flex items-baseline gap-2",children:[i.jsx("span",{className:"text-[11px] font-semibold",children:A.user.login}),i.jsx("span",{className:"text-[10px] text-muted-foreground",children:new Date(A.created_at).toLocaleDateString()})]}),i.jsx(r1,{content:A.body})]},A.id))})]})}),i.jsx("div",{className:"shrink-0 border-t border-border p-3",children:i.jsxs("form",{className:"flex flex-col gap-2",onSubmit:A=>{N(A)},children:[i.jsx(qee,{action:i.jsx(Q,{disabled:!d.trim(),loading:S,loadingLabel:c("github.issue.posting"),size:"sm",type:"submit",children:c("github.issue.comment")}),onChange:f,placeholder:c("github.issue.addComment"),value:d}),n?i.jsx(tt,{variant:"destructive",children:n}):null]})})]})}const HN=30,Vee=4e3;function Wee(e){return e.status==="in_progress"||e.status==="queued"}function $N(e){return e.map(t=>`${t.id}:${t.status}:${t.conclusion}`).join("|")}function FN(e){return e.map(t=>`${t.id}:${t.status}:${t.conclusion}:`+t.steps.map(s=>`${s.number}:${s.status}:${s.conclusion}`).join(",")).join("|")}function Kee(e,t){if(e.length===0)return t;const s=new Map(t.map(c=>[c.id,c])),n=new Set(e.map(c=>c.id)),a=t.filter(c=>!n.has(c.id)),l=e.map(c=>s.get(c.id)??c);return[...a,...l]}function Yee(e){const[t,s]=x.useState([]),[n,a]=x.useState(null),[l,c]=x.useState([]),[d,f]=x.useState(!0),[h,g]=x.useState(!1),[p,b]=x.useState(!1),[v,_]=x.useState(1),[S,C]=x.useState(!1),[N,A]=x.useState(null),[j,E]=x.useState(null);function T(){let F=!0;return f(!0),A(null),_(1),zh(e,1).then(M=>{F&&(s(M),b(M.length===HN))}).catch(M=>{F&&A(M instanceof Error?M.message:String(M))}).finally(()=>{F&&f(!1)}),()=>{F=!1}}function L(){if(h||!p)return;const F=v+1;g(!0),zh(e,F).then(M=>{s(z=>{const G=new Set(z.map(D=>D.id));return[...z,...M.filter(D=>!G.has(D.id))]}),b(M.length===HN),_(F)}).catch(M=>A(M instanceof Error?M.message:String(M))).finally(()=>g(!1))}const H=x.useCallback(()=>{zh(e,1).then(F=>s(M=>{const z=Kee(M,F);return $N(M)===$N(z)?M:z})).catch(()=>{}),n&&fS(n).then(F=>c(M=>FN(M)===FN(F)?M:F)).catch(()=>{})},[e,n]);x.useEffect(T,[e]),x.useEffect(()=>{a(F=>F&&t.some(M=>M.id===F)?F:t[0]?.id??null)},[t]),x.useEffect(()=>{if(!n){c([]);return}let F=!0;return C(!0),E(null),fS(n).then(M=>{F&&c(M)}).catch(M=>{F&&E(M instanceof Error?M.message:String(M))}).finally(()=>{F&&C(!1)}),()=>{F=!1}},[n]);const P=t.some(Wee);return x.useEffect(()=>{if(!P)return;const F=window.setInterval(()=>{document.visibilityState==="visible"&&H()},Vee);return()=>window.clearInterval(F)},[P,H]),{runs:t,selectedRunId:n,jobs:l,loading:d,loadingMore:h,hasMore:p,jobsLoading:S,error:N,jobsError:j,loadMore:L,refresh:T,syncLatest:H,setSelectedRunId:a}}function ET(e){return e.conclusion==="failure"||e.conclusion==="timed_out"||e.conclusion==="cancelled"}function Xee({branch:e,onClearBranch:t}){const{runs:s,selectedRunId:n,jobs:a,loading:l,loadingMore:c,hasMore:d,jobsLoading:f,error:h,jobsError:g,loadMore:p,refresh:b,syncLatest:v,setSelectedRunId:_}=Yee(e),S=ee();Dl(v);const C=s.find(T=>T.id===n)??null,{sendToAgent:N}=Ot(),[A,j]=x.useState(null);function E(T,L){j(null),N({prompt:BF(T,L),source:{type:"github-run",label:S("github.actions.runLabel",{number:T.run_number})},label:S("github.actions.runInputLabel",{number:T.run_number,input:L??S("github.actions.fixDefault")})})}return i.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[i.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("h2",{className:"text-[13px] font-semibold",children:S("github.actions.title")}),e?i.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:[i.jsx("span",{className:"shrink-0",children:S("github.actions.filteredTo")}),i.jsx("span",{className:"min-w-0 truncate font-mono",children:e}),t?i.jsx("button",{"aria-label":S("github.actions.clearFilter"),className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:t,title:S("github.actions.clearFilter"),type:"button",children:i.jsx(Vt,{className:"size-3"})}):null]}):null]}),i.jsxs(Q,{disabled:l,onClick:()=>{b()},size:"sm",type:"button",variant:"outline",children:[i.jsx(Pr,{className:`mr-1 size-3.5 ${l?"animate-spin":""}`}),S("common.refresh")]})]}),i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:h?i.jsx("div",{className:"p-4 text-[12px] text-red-500",children:h}):l&&s.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:S("github.actions.loadingRuns")}):s.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:S("github.actions.noRuns")}):i.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(280px,380px)_minmax(0,1fr)] divide-x divide-border",children:[i.jsxs("div",{className:"min-h-0 overflow-auto",children:[i.jsx("ul",{className:"divide-y divide-border",children:s.map(T=>i.jsxs("li",{className:"group flex flex-col",children:[i.jsxs("div",{className:`flex items-center transition-colors hover:bg-muted/60 ${T.id===n?"bg-muted/70":""}`,children:[i.jsxs("button",{className:"flex min-w-0 flex-1 items-center gap-3 px-3 py-2.5 text-left",onClick:()=>_(T.id),type:"button",children:[i.jsx(Zee,{run:T}),i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"block truncate text-[13px] font-medium",children:T.name}),i.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",T.run_number," · ",T.head_branch," · ",T.event," ·"," ",i.jsx("span",{title:new Date(T.created_at).toLocaleString(),children:aj(T.created_at)})]})]}),i.jsx(Qee,{run:T})]}),ET(T)?i.jsx(ir,{className:`mr-2 shrink-0 ${A===T.id?"opacity-100":""}`,label:S("github.actions.fixRunAi",{number:T.run_number}),onAsk:()=>j(L=>L===T.id?null:T.id)}):null]}),A===T.id?i.jsx("div",{className:"px-3 pb-2 pt-0.5",children:i.jsx(Ir,{onCancel:()=>j(null),onSubmit:L=>E(T,L),placeholder:S("github.actions.askPlaceholder")})}):null]},T.id))}),i.jsx(c1,{hasMore:d,loading:c,onLoadMore:p})]}),i.jsx(Jee,{error:g,jobs:a,loading:f,onFix:T=>E(T),run:C})]})})]})}function Zee({run:e}){return e.status==="in_progress"||e.status==="queued"?i.jsx(kl,{className:"size-4 shrink-0 animate-pulse text-amber-400"}):e.conclusion==="success"?i.jsx(qf,{className:"size-4 shrink-0 text-emerald-500"}):e.conclusion==="failure"||e.conclusion==="timed_out"?i.jsx(Ix,{className:"size-4 shrink-0 text-red-500"}):i.jsx(kl,{className:"size-4 shrink-0 text-zinc-400"})}function Qee({run:e}){const t=e.status==="completed"?e.conclusion??"completed":e.status,s=t==="success"?"bg-emerald-500":t==="failure"||t==="timed_out"?"bg-red-500":t==="in_progress"||t==="queued"?"bg-amber-500":"bg-muted-foreground";return i.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[i.jsx("span",{className:`size-1.5 rounded-full ${s}`}),t]})}function Jee({run:e,jobs:t,loading:s,error:n,onFix:a}){const l=ee();return e?i.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[i.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"block truncate text-[13px] font-semibold",children:e.name}),i.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["Run #",e.run_number," · ",e.head_branch," · ",e.head_sha.slice(0,7)]})]}),ET(e)?i.jsxs(Q,{className:"shrink-0 gap-1",onClick:()=>a(e),size:"sm",title:l("github.actions.fixTitle"),type:"button",variant:"outline",children:[i.jsx(Xt,{className:"size-3.5"}),l("github.actions.fixWithAi")]}):null,i.jsx("a",{"aria-label":l("github.actions.openRun"),className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:e.html_url,rel:"noopener noreferrer",target:"_blank",title:l("github.actions.openRun"),children:i.jsx(ja,{className:"size-3.5"})})]}),i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:n?i.jsx("div",{className:"p-4 text-[12px] text-red-500",children:n}):s?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:l("github.actions.loadingJobs")}):t.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:l("github.actions.noJobs")}):i.jsx("ul",{className:"divide-y divide-border",children:t.map(c=>i.jsxs("li",{className:"px-3 py-3",children:[i.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[i.jsx(UN,{item:c}),i.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-medium",children:c.name}),i.jsx("span",{className:"shrink-0 font-mono text-[11px] text-muted-foreground",children:qN(c.started_at,c.completed_at)}),i.jsx("a",{"aria-label":l("github.actions.openJobAria",{name:c.name}),className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:c.html_url,rel:"noopener noreferrer",target:"_blank",title:l("github.actions.openJob"),children:i.jsx(ja,{className:"size-3.5"})})]}),c.steps.length?i.jsx("ol",{className:"space-y-1.5 pl-6",children:c.steps.map(d=>i.jsxs("li",{className:"flex items-center gap-2 text-[12px]",children:[i.jsx(UN,{item:d}),i.jsx("span",{className:"min-w-0 flex-1 truncate",children:d.name}),i.jsx("span",{className:"shrink-0 font-mono text-[11px] text-muted-foreground",children:qN(d.started_at,d.completed_at)})]},`${c.id}:${d.number}`))}):i.jsx("p",{className:"pl-6 text-[12px] text-muted-foreground",children:l("github.actions.noSteps")})]},c.id))})})]}):i.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:l("github.actions.selectRun")})}function UN({item:e}){return e.status==="in_progress"||e.status==="queued"?i.jsx(kl,{className:"size-3.5 shrink-0 animate-pulse text-amber-400"}):e.conclusion==="success"||e.conclusion==="skipped"?i.jsx(qf,{className:"size-3.5 shrink-0 text-emerald-500"}):e.conclusion==="failure"||e.conclusion==="timed_out"||e.conclusion==="cancelled"?i.jsx(Ix,{className:"size-3.5 shrink-0 text-red-500"}):i.jsx(kl,{className:"size-3.5 shrink-0 text-zinc-400"})}function qN(e,t){if(!e)return"-";const s=Date.parse(e),n=t?Date.parse(t):Date.now();if(!Number.isFinite(s)||!Number.isFinite(n)||n<s)return"-";const a=Math.max(0,Math.round((n-s)/1e3));if(a<60)return`${a}s`;const l=Math.floor(a/60),c=a%60;return c?`${l}m ${c}s`:`${l}m`}function ete({onCreatePR:e,onViewRuns:t}){const s=ee(),[n,a]=x.useState(null),[l,c]=x.useState(!0),[d,f]=x.useState(null);function h(){let p=!0;return c(!0),f(null),y7().then(b=>{p&&a(b)}).catch(b=>{p&&f(b instanceof Error?b.message:String(b))}).finally(()=>{p&&c(!1)}),()=>{p=!1}}x.useEffect(h,[]),Dl(()=>{h()});const g=x.useMemo(()=>[...n?.branches??[]].sort((b,v)=>{const _=VN(b,n),S=VN(v,n);return _-S||b.name.localeCompare(v.name)}),[n]);return i.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[i.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("h2",{className:"text-[13px] font-semibold",children:s("github.tab.branches")}),i.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:n?.repository.full_name??s("github.selectedRepo")})]}),i.jsxs(Q,{disabled:l,onClick:()=>{h()},size:"sm",type:"button",variant:"outline",children:[i.jsx(Pr,{className:`mr-1 size-3.5 ${l?"animate-spin":""}`}),s("common.refresh")]})]}),i.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:d?i.jsx("div",{className:"p-4 text-[12px] text-red-500",children:d}):l&&!n?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:s("github.branches.loading")}):g.length===0?i.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:s("github.branches.empty")}):i.jsx("ul",{className:"divide-y divide-border",children:g.map(p=>i.jsx(tte,{branch:p,currentBranch:n?.currentBranch??null,defaultBranch:n?.defaultBranch??null,onCreatePR:e,onViewRuns:t},p.name))})})]})}function tte({branch:e,defaultBranch:t,currentBranch:s,onCreatePR:n,onViewRuns:a}){const l=ee(),c=e.name===t,d=e.name===s,f=!c;return i.jsxs("li",{className:"flex flex-wrap items-center gap-3 px-3 py-2.5",children:[i.jsx(Pn,{className:"size-4 shrink-0 text-muted-foreground"}),i.jsxs("div",{className:"min-w-48 flex-1",children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i.jsx("span",{className:"truncate font-mono text-[13px] font-medium",children:e.name}),c?i.jsx(GN,{label:l("github.branches.default"),tone:"success"}):null,d?i.jsx(GN,{label:l("github.branches.current"),tone:"warning"}):null,e.protected?i.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground",children:[i.jsx(bE,{className:"size-3"}),l("github.branches.protected")]}):null]}),i.jsx("div",{className:"mt-0.5 font-mono text-[11px] text-muted-foreground",children:e.commit.sha.slice(0,7)})]}),i.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[i.jsxs(Q,{onClick:()=>a(e.name),size:"sm",title:l("github.branches.viewRunsTitle",{name:e.name}),type:"button",variant:"outline",children:[i.jsx(NM,{className:"size-3.5"}),l("github.branches.viewRuns")]}),i.jsxs(Q,{disabled:!f,onClick:()=>n(e.name),size:"sm",title:f?l("github.branches.openPrTitle",{name:e.name}):l("github.branches.defaultNoPr"),type:"button",variant:"outline",children:[i.jsx(cE,{className:"size-3.5"}),l("github.branches.openPr")]})]})]})}function GN({label:e,tone:t}){const s=t==="success"?"bg-emerald-500":"bg-amber-500";return i.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground",children:[i.jsx("span",{className:`size-1.5 rounded-full ${s}`}),e]})}function VN(e,t){return e.name===t?.currentBranch?0:e.name===t?.defaultBranch?1:e.protected?2:3}function ste(){const e=ee(),t=Eee();let s;return t.loading||t.status==="checking"?s=i.jsx(sm,{fill:!0,label:e("common.loading")}):t.status==="not_configured"?s=i.jsx(wT,{deviceFlowAvailable:t.deviceFlowAvailable,onSaved:t.refresh}):t.status==="auth_error"||t.status==="connection_error"?s=i.jsx(nte,{token:t}):s=i.jsx(ite,{token:t}),i.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:s})}function nte({token:e}){const t=ee(),[s,n]=x.useState(null);if(s)return i.jsx(wT,{deviceFlowAvailable:e.deviceFlowAvailable,initialMode:s,onSaved:e.refresh});const a=e.status==="auth_error";return i.jsx("div",{className:"flex h-full items-center justify-center p-8",children:i.jsxs("div",{className:"w-full max-w-lg space-y-4 rounded-md border border-border bg-card p-5",children:[i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx(pm,{className:"size-5"}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("h2",{className:"text-sm font-semibold",children:t("github.connFailed")}),i.jsx("p",{className:"text-[12px] text-muted-foreground",children:t(a?"github.tokenRejected":"github.cantValidate")})]}),i.jsx(jT,{label:t(a?"github.needsRelogin":"github.connProblem"),tone:a?"danger":"warning"})]}),e.error?i.jsx(tt,{variant:"destructive",children:e.error}):null,i.jsxs("div",{className:"flex flex-wrap gap-2",children:[i.jsxs(Q,{onClick:e.refresh,type:"button",variant:a?"outline":"default",children:[i.jsx(Pr,{}),t("common.refresh")]}),i.jsx(Q,{onClick:()=>n(e.deviceFlowAvailable?"device-pending":"pat"),type:"button",variant:a?"default":"outline",children:t("github.reconnectGithub")}),i.jsx(Q,{onClick:()=>n("pat"),type:"button",variant:"outline",children:t("github.useToken")})]})]})})}function ite({token:e}){const t=ee(),[s,n]=_l("github:tab","prs"),[a,l]=_l("github:pr-state","open"),[c,d]=_l("github:issue-state","open"),[f,h]=x.useState(null),[g,p]=x.useState(null),[b,v]=x.useState(null),{isPending:_,runOperation:S}=si(),C=_("github:disconnect"),N=jee(a),A=Aee(c);Dl(()=>{s==="prs"?N.refresh():s==="issues"&&A.refresh()});const j=L=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${L?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`,E=L=>`rounded px-2 py-0.5 text-[10px] font-medium transition-colors ${L?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`;async function T(){v(null);try{await S({errorMessage:L=>L instanceof Error?L.message:String(L),key:"github:disconnect",label:t("github.disconnecting")},async()=>{await x7("github.com"),e.refresh()})}catch(L){v(L instanceof Error?L.message:String(L))}}return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border bg-card/95 px-3 py-1",children:[i.jsx("button",{className:j(s==="prs"),onClick:()=>n("prs"),type:"button",children:t("github.tab.prs")}),i.jsx("button",{className:j(s==="issues"),onClick:()=>n("issues"),type:"button",children:t("github.tab.issues")}),i.jsx("button",{className:j(s==="branches"),onClick:()=>n("branches"),type:"button",children:t("github.tab.branches")}),i.jsx("button",{className:j(s==="actions"),onClick:()=>n("actions"),type:"button",children:t("github.tab.actions")}),i.jsxs("div",{className:"ml-auto flex min-w-0 items-center gap-2",children:[i.jsx(rte,{token:e}),i.jsxs(Q,{onClick:e.refresh,size:"sm",title:t("github.recheckTitle"),type:"button",variant:"outline",children:[i.jsx(Pr,{}),t("github.reconnect")]}),i.jsx(Q,{loading:C,loadingLabel:t("github.disconnecting"),onClick:()=>{T()},size:"sm",type:"button",variant:"outline",children:t("github.disconnect")})]}),s==="prs"?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-muted/60 p-0.5",children:[i.jsx("button",{className:E(a==="open"),onClick:()=>l("open"),type:"button",children:t("github.open")}),i.jsx("button",{className:E(a==="closed"),onClick:()=>l("closed"),type:"button",children:t("github.closed")})]}),i.jsx(Q,{onClick:()=>h(""),size:"sm",type:"button",variant:"outline",children:t("github.newPr")})]}):s==="issues"?i.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-muted/60 p-0.5",children:[i.jsx("button",{className:E(c==="open"),onClick:()=>d("open"),type:"button",children:t("github.open")}),i.jsx("button",{className:E(c==="closed"),onClick:()=>d("closed"),type:"button",children:t("github.closed")})]}):null]}),b?i.jsx(tt,{variant:"destructive",className:"m-3",children:b}):null,f!==null?i.jsx(ate,{initialHead:f,onCreated:L=>{h(null),n("prs"),N.setSelectedNumber(L.number),N.refresh()},onCancel:()=>h(null)}):i.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s==="prs"?i.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(0,1fr)_minmax(0,2fr)] divide-x divide-border",children:[i.jsx("div",{className:"min-h-0 overflow-auto",children:i.jsx(Mee,{error:N.error,hasMore:N.hasMore,loading:N.loading,loadingMore:N.loadingMore,onLoadMore:N.loadMore,onSelect:N.setSelectedNumber,prs:N.prs,selectedNumber:N.selectedNumber})}),i.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden",children:i.jsx(Lee,{diff:N.diff,diffError:N.diffError,diffLoading:N.diffLoading,onMerged:()=>N.refresh(),pr:N.selectedPR})})]}):s==="issues"?i.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(0,1fr)_minmax(0,2fr)] divide-x divide-border",children:[i.jsx("div",{className:"min-h-0 overflow-auto",children:i.jsx(Hee,{error:A.error,hasMore:A.hasMore,issues:A.issues,loading:A.loading,loadingMore:A.loadingMore,onLoadMore:A.loadMore,onSelect:A.setSelectedNumber,selectedNumber:A.selectedNumber})}),i.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden",children:i.jsx(Gee,{commentError:A.commentError,comments:A.comments,commentsLoading:A.commentsLoading,issue:A.selectedIssue,onAddComment:A.addComment,submitting:A.submitting})})]}):s==="branches"?i.jsx(ete,{onCreatePR:L=>h(L),onViewRuns:L=>{p(L),n("actions")}}):i.jsx(Xee,{branch:g??void 0,onClearBranch:()=>p(null)})})]})}function rte({token:e}){const t=ee(),s=e.info?.repository?.full_name??(e.info?.user?`@${e.info.user.login}`:"GitHub");return i.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 border-r border-border pr-2",children:[i.jsx(pm,{className:"size-4 shrink-0 text-foreground"}),i.jsx(jT,{label:t("github.connected"),tone:"success"}),i.jsx("span",{className:"max-w-48 truncate font-mono text-[10px] text-muted-foreground",children:s})]})}function jT({label:e,tone:t}){const s=t==="success"?"bg-emerald-500":t==="danger"?"bg-red-500":"bg-amber-500";return i.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-[11px] font-medium text-muted-foreground",children:[i.jsx("span",{className:`size-1.5 rounded-full ${s}`}),e]})}function ate({initialHead:e,onCreated:t,onCancel:s}){const n=ee(),[a,l]=x.useState(""),[c,d]=x.useState(""),[f,h]=x.useState(""),[g,p]=x.useState("main"),[b,v]=x.useState(!1),[_,S]=x.useState(null),[C,N]=x.useState(!0),[A,j]=x.useState(!1),[E,T]=x.useState(null);x.useEffect(()=>{let F=!0;return N(!0),T(null),k7().then(M=>{F&&(S(M),l(M.title),d(M.body),h(e||M.head),p(M.base||M.suggestedBase||"main"),v(M.draft))}).catch(M=>{F&&T(M instanceof Error?M.message:String(M))}).finally(()=>{F&&N(!1)}),()=>{F=!1}},[e]);async function L(F){if(F.preventDefault(),!(!a.trim()||!f.trim()||!g.trim())){j(!0),T(null);try{const M=await C7({title:a.trim(),body:c.trim()||void 0,head:f.trim(),base:g.trim(),draft:b});t(M)}catch(M){T(M instanceof Error?M.message:String(M))}finally{j(!1)}}}const H="w-full rounded-md border border-border bg-background px-3 py-2 text-[13px] placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring",P=_?.warnings??[];return i.jsxs("form",{className:"flex min-h-0 flex-col gap-3 overflow-auto bg-muted/20 p-4",onSubmit:F=>{L(F)},children:[i.jsxs("div",{className:"flex items-start justify-between gap-3",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("h3",{className:"text-[13px] font-semibold",children:n("github.branchToPr")}),i.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:[_?.repository?.full_name??n("github.selectedRepo"),_?.currentBranch?` - ${_.currentBranch}`:""]})]}),i.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:n(C?"github.detectingBranch":"github.editableDraft")})]}),i.jsx(ote,{template:_,loading:C}),P.length>0?i.jsx("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[12px] text-amber-700 dark:text-amber-300",children:P[0]}):null,i.jsx("input",{className:H,disabled:C,onChange:F=>l(F.target.value),placeholder:n("github.fieldTitle"),required:!0,value:a}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsxs("label",{className:"space-y-1",children:[i.jsx("span",{className:"text-[10px] uppercase text-muted-foreground",children:n("github.head")}),i.jsx("input",{className:H,disabled:C,onChange:F=>h(F.target.value),placeholder:n("github.headBranch"),required:!0,value:f})]}),i.jsxs("label",{className:"space-y-1",children:[i.jsx("span",{className:"text-[10px] uppercase text-muted-foreground",children:n("github.base")}),i.jsx("input",{className:H,disabled:C,onChange:F=>p(F.target.value),placeholder:n("github.baseBranch"),required:!0,value:g})]})]}),i.jsx("textarea",{className:`${H} resize-none`,disabled:C,onChange:F=>d(F.target.value),placeholder:n("github.descriptionOptional"),rows:7,value:c}),i.jsxs("label",{className:"flex items-center gap-2 text-[12px]",children:[i.jsx("input",{checked:b,className:"size-3.5",disabled:C,onChange:F=>v(F.target.checked),type:"checkbox"}),n("github.createAsDraft")]}),E?i.jsx(tt,{variant:"destructive",children:E}):null,i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Q,{disabled:C||A||!a.trim()||!f.trim()||!g.trim(),type:"submit",children:n(A?"github.creating":"github.createPr")}),i.jsx(Q,{onClick:s,type:"button",variant:"outline",children:n("common.cancel")})]})]})}function ote({template:e,loading:t}){const s=ee(),n=e?.compare,a=n?.ciStatus,l=[{label:s("github.compare.base"),value:n?.base||e?.base||"main"},{label:s("github.compare.head"),value:n?.head||e?.head||"manual"},{label:s("github.compare.ahead"),value:t?"...":String(n?.aheadBy??0)},{label:s("github.compare.changed"),value:t?"...":String(n?.files.length??0)},{label:s("github.compare.ci"),value:a?`${a.state} (${a.totalCount})`:s("github.compare.unavailable")}];return i.jsxs("div",{className:"rounded-md border border-border bg-card px-3 py-2",children:[i.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[i.jsx("span",{className:"text-[11px] font-medium text-foreground",children:s("github.compareSummary")}),n?.headSha?i.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:n.headSha.slice(0,7)}):null]}),i.jsx("div",{className:"grid grid-cols-5 gap-2",children:l.map(c=>i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:"truncate text-[10px] uppercase text-muted-foreground",children:c.label}),i.jsx("div",{className:"truncate font-mono text-[11px] text-foreground",children:c.value})]},c.label))}),n?.files.length?i.jsx("div",{className:"mt-2 flex flex-wrap gap-x-3 gap-y-1 text-[11px] text-muted-foreground",children:n.files.slice(0,4).map(c=>i.jsxs("span",{className:"max-w-52 truncate",children:[c.status," ",c.path]},`${c.status}:${c.path}`))}):null]})}function lte({data:e,docked:t,scopeAll:s,onScopeChange:n,onRefresh:a,onClose:l,onManage:c}){const d=ee(),{error:f,success:h}=ms(),g=e.git.selectedRepository;async function p(S){l();try{await PE(S),n(!1),await a(),h(d("git.repo.switchedToast",{name:S}))}catch(C){f(C instanceof Error?C.message:String(C))}}function b(){l(),n(!0),h(d("app.showingAllProjects"))}const v=S=>oe("grid h-8 grid-cols-[48px_minmax(0,1fr)] items-center overflow-hidden rounded-md text-left transition-[background-color,width] duration-150 hover:bg-muted",t?"w-full":"w-12 group-hover/sidebar:w-full",S&&"bg-muted/60"),_=oe("flex min-w-0 items-center gap-2 overflow-hidden whitespace-pre pr-2 text-xs transition duration-150",t?"translate-x-1 opacity-100":"opacity-0 group-hover/sidebar:translate-x-1 group-hover/sidebar:opacity-100");return i.jsxs("div",{className:"mt-1 grid gap-0.5",children:[i.jsxs("button",{className:v(s),onClick:b,title:d("app.allProjects"),type:"button",children:[i.jsx("span",{className:"flex h-8 w-12 items-center justify-center",children:i.jsx(tf,{className:"size-4 text-muted-foreground"})}),i.jsxs("span",{className:_,children:[i.jsx("span",{className:"min-w-0 flex-1 truncate font-medium",children:d("app.allProjects")}),s?i.jsx(Ys,{className:"size-3.5 shrink-0"}):null]})]}),e.config.gitRepositories.map(S=>{const C=!s&&S.name===g?.name;return i.jsxs("button",{className:v(C),onClick:()=>{p(S.name)},title:S.path,type:"button",children:[i.jsx("span",{className:"flex h-8 w-12 items-center justify-center",children:i.jsx($f,{className:"size-4 text-muted-foreground"})}),i.jsxs("span",{className:_,children:[i.jsx("span",{className:"min-w-0 flex-1 truncate font-medium",children:S.name}),C?i.jsx(Ys,{className:"size-3.5 shrink-0"}):null]})]},S.name)}),i.jsxs("button",{className:oe("grid h-8 grid-cols-[48px_minmax(0,1fr)] items-center overflow-hidden rounded-md text-left text-muted-foreground transition-[background-color,color,width] duration-150 hover:bg-muted hover:text-foreground",t?"w-full":"w-12 group-hover/sidebar:w-full"),onClick:()=>{l(),c()},title:d("app.addManageProjects"),type:"button",children:[i.jsx("span",{className:"flex h-8 w-12 items-center justify-center",children:i.jsx(Ux,{className:"size-4"})}),i.jsx("span",{className:_,children:i.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[d("app.addManageProjects"),"…"]})})]})]})}function cte({data:e,docked:t,scopeAll:s,onScopeChange:n,onRefresh:a}){const l=ee(),[c,d]=x.useState(!1),[f,h]=x.useState(!1),g=e.git.selectedRepository,p=s?l("app.allProjects"):g?.name??l("app.pickProject"),b=e.config.gitRepositories.length,v=s?l(b===1?"app.projectCountOne":"app.projectCountMany",{count:b}):g?e.git.status?.branch??g.path:l("app.setContext");return i.jsxs(i.Fragment,{children:[i.jsxs("button",{"aria-label":l("app.projectScope",{label:p}),className:oe("relative grid h-11 grid-cols-[48px_minmax(0,1fr)] items-center overflow-hidden rounded-md text-left transition-[background-color,width] duration-150 hover:bg-muted",t?"w-full":"w-12 group-hover/sidebar:w-full"),"aria-expanded":c,onClick:()=>d(_=>!_),title:l("app.projectScope",{label:p}),type:"button",children:[i.jsx("span",{className:"flex h-11 w-12 items-center justify-center",children:i.jsx("span",{className:"flex size-8 items-center justify-center rounded-lg border border-border bg-background text-[13px] font-semibold text-foreground",children:s?i.jsx(tf,{className:"size-4 text-muted-foreground"}):g?p.charAt(0).toUpperCase():i.jsx($f,{className:"size-4 text-muted-foreground"})})}),i.jsxs("span",{className:oe("min-w-0 overflow-hidden whitespace-pre pr-8 transition duration-150",t?"translate-x-1 opacity-100":"opacity-0 group-hover/sidebar:translate-x-1 group-hover/sidebar:opacity-100"),children:[i.jsx("span",{className:"block truncate text-[13px] font-semibold leading-tight",children:p}),i.jsx("span",{className:"block truncate text-[10px] leading-tight text-muted-foreground",children:v})]}),i.jsx(hn,{className:oe("absolute right-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground transition-[opacity,transform] duration-150",t?"opacity-100":"opacity-0 group-hover/sidebar:opacity-100",c&&"rotate-180")})]}),c?i.jsx(lte,{data:e,docked:t,onClose:()=>d(!1),onManage:()=>h(!0),onRefresh:a,onScopeChange:n,scopeAll:s}):null,f?i.jsx(ute,{data:e,onClose:()=>h(!1),onRefresh:a,onScopeChange:n,scopeAll:s}):null]})}function ute({data:e,onClose:t,onRefresh:s,onScopeChange:n,scopeAll:a}){const l=ee(),[c,d]=x.useState("path"),[f,h]=x.useState(e.git.cwd),[g,p]=x.useState(""),[b,v]=x.useState(!1),[_,S]=x.useState(null),[C,N]=x.useState(!1),[A,j]=x.useState(e.git.cwd),E=e.git.selectedRepository,{error:T,success:L}=ms();async function H(D){try{await PE(D),n(!1),t(),await s(),L(l("git.repo.switchedToast",{name:D}))}catch(q){T(q instanceof Error?q.message:String(q))}}function P(){n(!0),t(),L(l("app.showingAllProjects"))}async function F(D){const q=D.trim();if(!q.startsWith("/")){const W=l("git.repo.absPathError");return S(W),T(W),!1}try{const W=fT(q);return await u7(W,q),S(null),await s(),L(l("git.repo.addedToast",{name:W})),!0}catch(W){const I=W instanceof Error?W.message:String(W);return S(I),T(I),!1}}async function M(D){try{await c7(D),await s(),L(l("git.repo.removedToast",{name:D}))}catch(q){T(q instanceof Error?q.message:String(q))}}async function z(D){D.preventDefault(),await F(f)&&t()}async function G(D){D.preventDefault();const q=g.trim();if(q){v(!0),S(null);try{const{name:W}=await d7(q);p(""),await s(),L(l("git.repo.clonedToast",{name:W})),t()}catch(W){const I=W instanceof Error?W.message:String(W);S(I),T(I)}finally{v(!1)}}}return Ii.createPortal(i.jsxs("div",{className:"fixed inset-0 z-[1000] grid place-items-center bg-black/35 px-4",onMouseDown:D=>{D.target===D.currentTarget&&t()},children:[i.jsxs("div",{className:"w-full max-w-md overflow-hidden rounded-xl border border-border bg-card shadow-xl",children:[i.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-4 py-3",children:[i.jsx(tf,{className:"size-4 text-muted-foreground"}),i.jsx("div",{className:"text-sm font-semibold",children:l("git.repo.projectsShort")}),i.jsx(Ke,{className:"h-5 px-1.5 text-[10px]",variant:"outline",children:e.config.gitRepositories.length}),i.jsx(Q,{"aria-label":l("git.repo.closeSwitcher"),className:"ml-auto size-7",onClick:t,size:"icon",variant:"ghost",children:i.jsx(Vt,{className:"size-4"})})]}),i.jsxs("div",{className:"max-h-80 overflow-auto",children:[i.jsxs("button",{className:oe("grid w-full grid-cols-[1fr_auto] items-center gap-2 border-b border-border px-4 py-2.5 text-left transition-colors hover:bg-muted",a&&"bg-muted/70"),onClick:P,type:"button",children:[i.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(tf,{className:"size-3.5 shrink-0 text-muted-foreground"}),i.jsxs("span",{className:"min-w-0",children:[i.jsx("span",{className:"block truncate text-sm font-medium leading-tight",children:l("app.allProjects")}),i.jsx("span",{className:"block truncate text-[10px] leading-tight text-muted-foreground",children:l("app.allProjectsHint")})]})]}),a?i.jsx(Ys,{className:"size-3.5"}):i.jsx("span",{className:"size-3.5"})]}),e.config.gitRepositories.length?i.jsx("div",{className:"divide-y divide-border",children:e.config.gitRepositories.map(D=>{const q=!a&&D.name===E?.name;return i.jsxs("div",{className:oe("group grid w-full grid-cols-[1fr_auto_auto] items-center gap-2 px-4 py-2 text-left transition-colors hover:bg-muted",q&&"bg-muted/70"),children:[i.jsxs("button",{className:"min-w-0 text-left",onClick:()=>{H(D.name)},type:"button",children:[i.jsx("span",{className:"block truncate text-sm font-medium leading-tight",children:D.name}),i.jsx("span",{className:"block truncate font-mono text-[10px] leading-tight text-muted-foreground",children:D.path})]}),q?i.jsx(Ys,{className:"size-3.5"}):i.jsx("span",{className:"size-3.5"}),i.jsx(Q,{"aria-label":l("git.repo.removeName",{name:D.name}),className:"size-6 opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>{M(D.name)},size:"icon",title:l("git.repo.removeName",{name:D.name}),type:"button",variant:"ghost",children:i.jsx(Bi,{className:"size-3.5 text-destructive"})})]},D.name)})}):i.jsx("div",{className:"px-4 py-6 text-center text-xs text-muted-foreground",children:l("git.repo.noProjects")})]}),i.jsxs("div",{className:"border-t border-border bg-muted/20 p-3",children:[i.jsxs("div",{className:"mb-1.5 flex gap-1 text-[11px]",children:[i.jsxs("button",{className:oe("flex items-center gap-1 rounded px-2 py-0.5 transition-colors",c==="path"?"bg-muted font-medium text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>{d("path"),S(null)},type:"button",children:[i.jsx(ko,{className:"size-3"}),l("git.repo.localPath")]}),i.jsxs("button",{className:oe("flex items-center gap-1 rounded px-2 py-0.5 transition-colors",c==="url"?"bg-muted font-medium text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>{d("url"),S(null)},type:"button",children:[i.jsx(vu,{className:"size-3"}),l("git.repo.cloneUrl")]})]}),c==="path"?i.jsxs("form",{className:"flex gap-1.5",onSubmit:z,children:[i.jsx(pt,{"aria-label":l("git.repo.pasteAbsPath"),className:"h-7 flex-1 px-2 font-mono text-[11px]",onChange:D=>{h(D.target.value),S(null)},placeholder:"/absolute/path",value:f}),i.jsxs(Q,{className:"h-7 px-2 text-[11px]",size:"sm",type:"submit",children:[i.jsx(fs,{className:"size-3"}),l("common.add")]}),i.jsx(Q,{"aria-label":l("git.repo.browseAdd"),className:"h-7 px-2",onClick:()=>{S(null),j(e.git.cwd),N(!0)},size:"sm",type:"button",variant:"outline",children:i.jsx(Ux,{className:"size-3"})})]}):i.jsxs("form",{className:"flex gap-1.5",onSubmit:G,children:[i.jsx(pt,{"aria-label":l("git.repo.remoteUrl"),className:"h-7 flex-1 px-2 font-mono text-[11px]",onChange:D=>{p(D.target.value),S(null)},placeholder:"https://… or git@host:owner/repo.git",value:g}),i.jsxs(Q,{className:"h-7 px-2 text-[11px]",disabled:b||!g.trim(),size:"sm",type:"submit",children:[i.jsx(vu,{className:"size-3"}),l(b?"git.repo.cloning":"git.repo.clone")]})]}),_?i.jsx("div",{className:"mt-1.5 truncate text-[10px] text-destructive",children:_}):null,c==="url"?i.jsx("div",{className:"mt-1 text-[10px] text-muted-foreground",children:l("git.repo.cloneHint")}):null]})]}),C?i.jsx(mT,{confirmLabel:l("git.repo.addProject"),errorMessage:_,initialPath:e.git.cwd,selectedPath:A,title:l("git.repo.addProjectTitle"),onCancel:()=>N(!1),onSelect:j,onUse:async()=>{await F(A)&&(N(!1),t())}}):null]}),document.body)}function dte({ahead:e=0,behind:t=0,branches:s,currentBranch:n,disabled:a,onRefresh:l,upstream:c}){const d=ee(),[f,h]=x.useState(!1),[g,p]=x.useState(""),[b,v]=x.useState(null),[_,S]=x.useState(null),[C,N]=x.useState(null),A=s.filter(M=>!M.remote),j=s.filter(M=>M.remote);async function E(M,z){v(M),N(null),S(null);try{await z(),await l()}catch(G){N(G instanceof Error?G.message:String(G))}finally{v(null)}}async function T(M){await E(`switch:${M}`,async()=>{await Pi("/api/git/branches/switch",{name:M}),h(!1)})}async function L(){await E("fetch",async()=>{await Pi("/api/git/fetch",{}),S(d("git.branch.fetched"))})}async function H(){await E("push",async()=>{const M=await Jf();S(M.setUpstream?d("git.branch.pushedSetUpstream",{branch:M.branch}):d("git.branch.pushed",{branch:M.branch}))})}const P=!!n&&(e>0||!c&&t===0);async function F(M){M.preventDefault();const z=g.trim();if(!z){N(d("git.branch.nameRequired"));return}await E("create",async()=>{await Pi("/api/git/branches",{name:z}),p(""),h(!1)})}return i.jsxs("div",{className:"fixed bottom-12 right-4 z-50 flex items-end",children:[f?i.jsxs("div",{"aria-label":d("git.branch.switchAria"),className:"mb-11 w-[min(460px,calc(100vw-2rem))] rounded-lg border border-border bg-card shadow-xl",role:"dialog",children:[i.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border p-3",children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(Pn,{className:"size-4 text-muted-foreground"}),i.jsx("span",{className:"truncate text-sm font-semibold",children:n||d("git.branch.branches")})]}),i.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[P?i.jsxs(Q,{"aria-label":d("git.branch.pushAria"),className:"gap-1.5 px-2 text-xs",disabled:a||b!==null,onClick:()=>{H()},size:"sm",title:c?d("git.branch.pushCountTo",{ahead:e,upstream:c}):d("git.branch.pushSetUpstream"),type:"button",variant:"default",children:[i.jsx(Xf,{className:oe("size-3.5",b==="push"&&"animate-pulse")}),d("git.branch.push"),e>0?` ${e}`:""]}):null,i.jsx(Q,{"aria-label":d("git.branch.fetchAria"),disabled:a||b!==null,onClick:()=>{L()},size:"icon",title:d("git.branch.fetchAria"),type:"button",variant:"ghost",children:i.jsx(Pr,{className:oe(b==="fetch"&&"animate-spin")})}),i.jsx(Q,{"aria-label":d("git.branch.closeAria"),onClick:()=>h(!1),size:"icon",type:"button",variant:"ghost",children:i.jsx(Vt,{})})]})]}),i.jsx("div",{className:"max-h-72 overflow-auto",children:s.length?i.jsxs(i.Fragment,{children:[i.jsx(WN,{branches:A,busy:b!==null,disabled:a,empty:d("git.branch.noLocal"),label:d("git.branch.sectionLocal"),onSwitch:T}),i.jsx(WN,{branches:j,busy:b!==null,disabled:a,empty:d("git.branch.noRemote"),label:d("git.branch.sectionRemote"),onSwitch:T})]}):i.jsx("div",{className:"px-3 py-6 text-center text-sm text-muted-foreground",children:d("git.branch.noneFound")})}),i.jsxs("div",{className:"border-t border-border p-3",children:[i.jsxs("form",{className:"grid gap-2 sm:grid-cols-[1fr_auto]",onSubmit:F,children:[i.jsx(pt,{"aria-label":d("git.branch.newNameAria"),disabled:a||b!==null,onChange:M=>{p(M.target.value),N(null),S(null)},placeholder:"feature/new-work",value:g}),i.jsxs(Q,{disabled:a||b!==null,type:"submit",children:[i.jsx(x6,{}),d("git.branch.create")]})]}),C||_?i.jsx(tt,{className:"mt-3 px-3 py-2 text-xs",variant:C?"destructive":"muted",children:C??_}):null]})]}):null,i.jsxs(Q,{className:"h-8 max-w-[260px] gap-2 rounded-md shadow-lg",disabled:a,onClick:()=>h(M=>!M),size:"sm",title:d("git.branch.switchAria"),type:"button",variant:"default",children:[i.jsx(Pn,{className:"size-4"}),i.jsx("span",{className:"truncate font-mono text-xs",children:n||d("git.branch.noBranch")}),n&&(e>0||t>0)?i.jsxs("span",{className:"flex items-center gap-1 font-mono text-[11px] tabular-nums",title:c?d("git.branch.aheadBehindUpstream",{ahead:e,behind:t,upstream:c}):d("git.branch.aheadBehind",{ahead:e,behind:t}),children:[t>0?i.jsxs("span",{className:"flex items-center",children:[i.jsx(Bf,{className:"size-3"}),t]}):null,e>0?i.jsxs("span",{className:"flex items-center",children:[i.jsx(If,{className:"size-3"}),e]}):null]}):null,i.jsx(hn,{className:oe("size-4 transition-transform",f&&"rotate-180")})]})]})}function WN({branches:e,busy:t,disabled:s,empty:n,label:a,onSwitch:l}){const c=ee();return i.jsxs("section",{children:[i.jsx("div",{className:"border-b border-border bg-muted/60 px-3 py-1.5 text-[11px] font-semibold uppercase text-muted-foreground",children:a}),e.length?e.map(d=>i.jsxs("button",{className:oe("grid w-full grid-cols-[1fr_auto] items-center gap-2 border-b border-border px-3 py-2 text-left text-sm last:border-b-0 hover:bg-muted",d.current&&"bg-muted/70"),disabled:s||t||d.current,onClick:()=>{l(d.name)},type:"button",children:[i.jsxs("span",{className:"min-w-0",children:[i.jsx("span",{className:"block truncate font-medium",children:d.name}),d.upstream?i.jsx("span",{className:"block truncate font-mono text-[11px] text-muted-foreground",children:c("git.branch.tracks",{upstream:d.upstream})}):null]}),i.jsx(Ke,{variant:d.current?"success":d.remote?"outline":"secondary",children:d.current?c("git.branch.tagCurrent"):d.remote?c("git.branch.tagRemote"):c("git.branch.tagLocal")})]},`${d.remote?"remote":"local"}:${d.name}`)):i.jsx("div",{className:"border-b border-border px-3 py-3 text-sm text-muted-foreground",children:n})]})}function hte(){const e=ee(),[,t]=pA(),s=WK(),n=x.useRef(null),a=x.useCallback(()=>{const l=s==="dark"?"light":"dark",c=n.current,d=document;if(!c||!d.startViewTransition||window.matchMedia("(prefers-reduced-motion: reduce)").matches){t(l);return}const f=c.getBoundingClientRect(),h=f.left+f.width/2,g=f.top+f.height/2,p=Math.hypot(Math.max(h,window.innerWidth-h),Math.max(g,window.innerHeight-g));d.startViewTransition(()=>{t(l)}).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${h}px ${g}px)`,`circle(${p}px at ${h}px ${g}px)`]},{duration:500,easing:"ease-in-out",pseudoElement:"::view-transition-new(root)"})})},[s,t]);return i.jsxs("button",{ref:n,type:"button",onClick:a,title:e(s==="dark"?"action.toLight":"action.toDark"),"aria-label":e("action.theme"),className:gf(),children:[i.jsx("span",{className:bf(),children:s==="dark"?i.jsx(o8,{}):i.jsx(dD,{})}),i.jsx("span",{className:vf(),children:e("action.theme")})]})}function fte(){const e=ee();return $s()?i.jsxs("div",{className:"flex items-center justify-between h-8 bg-background border-b border-border select-none",style:{WebkitAppRegion:"drag"},onMouseDown:()=>N8(),children:[i.jsx("span",{className:"px-3 text-xs font-medium text-muted-foreground",children:"NoMoreIDE"}),i.jsxs("div",{className:"flex items-center",style:{WebkitAppRegion:"no-drag"},children:[i.jsx("button",{type:"button",onClick:S8,className:"h-8 w-10 flex items-center justify-center hover:bg-muted transition-colors","aria-label":e("common.minimize"),children:i.jsx(hE,{className:"h-3 w-3"})}),i.jsx("button",{type:"button",onClick:k8,className:"h-8 w-10 flex items-center justify-center hover:bg-muted transition-colors","aria-label":e("common.maximize"),children:i.jsx(xo,{className:"h-3 w-3"})}),i.jsx("button",{type:"button",onClick:C8,className:"h-8 w-10 flex items-center justify-center hover:bg-destructive hover:text-destructive-foreground transition-colors","aria-label":e("common.close"),children:i.jsx(Vt,{className:"h-3 w-3"})})]})]}):null}const mte=300;function pte(){const{operations:e}=si(),[t,s]=x.useState(!1),[n,a]=x.useState(!1),l=x.useId(),c=ee();if(x.useEffect(()=>{if(e.length===0){s(!1),a(!1);return}const h=Math.min(...e.map(({startedAt:b})=>b)),g=Math.max(0,mte-(Date.now()-h));if(g===0){s(!0);return}s(!1);const p=window.setTimeout(()=>s(!0),g);return()=>window.clearTimeout(p)},[e]),!t||e.length===0)return null;const d=e.length>1,f=d?c("operation.multiple",{count:e.length}):e[0].label;return i.jsxs("aside",{"aria-live":"polite",className:"rounded-lg border border-border bg-card px-3 py-2 text-card-foreground shadow-sm transition-all motion-reduce:transition-none",role:"status",children:[i.jsxs("div",{className:"flex min-h-7 items-center gap-2",children:[i.jsx(tm,{size:"sm"}),i.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium",children:f}),d?i.jsx(Q,{"aria-controls":l,"aria-expanded":n,"aria-label":c(n?"operation.hideDetails":"operation.showDetails"),onClick:()=>a(h=>!h),size:"icon-sm",type:"button",variant:"ghost",children:i.jsx(hn,{className:oe("transition-transform motion-reduce:transition-none",n&&"rotate-180")})}):null]}),d&&n?i.jsx("ul",{className:"mt-2 space-y-1 border-t border-border pt-2",id:l,children:e.map(h=>i.jsxs("li",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[i.jsx("span",{"aria-hidden":!0,className:"size-1.5 shrink-0 rounded-full bg-primary"}),i.jsx("span",{className:"truncate",children:h.label})]},h.id))}):null]})}const AT={services:"/",git:"/git",github:"/github",workflows:"/workflows",errors:"/errors",database:"/database",terminal:"/terminal",agent:"/agent","agent-env":"/agent-env",settings:"/settings"},gte={services:"nav.services",git:"nav.git",github:"nav.github",workflows:"nav.workflows",errors:"nav.errors",database:"nav.database",terminal:"nav.terminal",agent:"pageTitle.agent","agent-env":"pageTitle.agentEnv",settings:"nav.settings"},bte=Object.entries(AT).filter(([,e])=>e!=="/").sort(([,e],[,t])=>t.length-e.length);function vte(e){for(const[t,s]of bte)if(e.startsWith(s))return t;return"services"}const xte=[{labelKey:"nav.section.run",items:[{page:"services",labelKey:"nav.services",icon:i.jsx(Yf,{})},{page:"errors",labelKey:"nav.errors",icon:i.jsx(ju,{})},{page:"terminal",labelKey:"nav.terminal",icon:i.jsx(zr,{})}]},{labelKey:"nav.section.code",items:[{page:"git",labelKey:"nav.git",icon:i.jsx(Pn,{})},{page:"github",labelKey:"nav.github",icon:i.jsx(pm,{})},{page:"workflows",labelKey:"nav.workflows",icon:i.jsx(nf,{})}]},{labelKey:"nav.section.data",items:[{page:"database",labelKey:"nav.database",icon:i.jsx(ti,{})}]},{labelKey:"nav.section.agent",items:[{page:"agent",labelKey:"nav.agentConsole",icon:i.jsx(Hf,{})},{page:"agent-env",labelKey:"nav.agentEnv",icon:i.jsx(Au,{})}]}];function yte(e=!1){return oe("group/sidebar hidden h-full shrink-0 overflow-x-hidden overflow-y-auto border-r border-border bg-card/85 py-4 backdrop-blur transition-[width,padding] duration-200 md:flex md:flex-col",e?"w-64 px-4":"w-16 px-2 hover:w-64 hover:px-4")}function _te(e,t=!1){return oe("relative grid h-10 grid-cols-[48px_minmax(0,1fr)] items-center justify-start gap-0 overflow-hidden rounded-md px-0 text-sm font-medium transition-[background-color,color,width] duration-150",t?"w-full":"w-12 group-hover/sidebar:w-full",e?"bg-primary text-primary-foreground hover:bg-primary/90":"hover:bg-muted")}function wte(e=!1,t=!1){return oe("min-w-0 overflow-hidden text-left text-current transition duration-150 whitespace-pre",e?"translate-x-1 opacity-100":"opacity-0 group-hover/sidebar:translate-x-1 group-hover/sidebar:opacity-100",t?"pr-10":"pr-3")}function Ste(e=!1){return oe("flex h-10 w-12 items-center justify-center text-current transition-transform duration-150 [&_svg]:size-5",e?"translate-x-0":"-translate-x-px group-hover/sidebar:translate-x-0")}function kte({docked:e,onToggleDock:t}){return i.jsxs("div",{className:oe("mt-auto flex h-10 min-w-0 items-center overflow-hidden border-t border-border/60 text-[11px] text-muted-foreground transition-[height,opacity,width] duration-150",e?"w-full justify-start opacity-100":"w-12 justify-center group-hover/sidebar:w-full group-hover/sidebar:justify-start group-hover/sidebar:opacity-100"),children:[i.jsxs("span",{className:oe("flex min-w-0 items-center gap-1.5 overflow-hidden whitespace-pre transition-[opacity,width] duration-150",e?"flex-1 opacity-100":"w-0 flex-none opacity-0 group-hover/sidebar:w-auto group-hover/sidebar:flex-1 group-hover/sidebar:opacity-100"),children:[i.jsx("span",{children:"Made with"}),i.jsx(C6,{"aria-label":"love",className:"size-3 shrink-0 fill-red-500 text-red-500"}),i.jsx("span",{children:"by Robert Wang"}),i.jsx("a",{"aria-label":"Robert Wang on LinkedIn",className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-[#0A66C2]",href:"https://www.linkedin.com/in/robert-wang-cs/",rel:"noopener noreferrer",target:"_blank",title:"LinkedIn",children:i.jsxs("svg",{className:"size-3 fill-current",role:"img",viewBox:"0 0 24 24",children:[i.jsx("title",{children:"LinkedIn"}),i.jsx("path",{d:"M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.063 2.063 0 1 1 0-4.126 2.063 2.063 0 0 1 0 4.126zM7.119 20.452H3.554V9h3.565v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.225 0z"})]})})]}),i.jsx("button",{"aria-label":e?"Undock sidebar":"Dock sidebar","aria-pressed":e,className:oe("flex size-8 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground [&_svg]:size-4",e?"ml-auto bg-muted text-foreground":"group-hover/sidebar:ml-auto"),onClick:t,title:e?"Undock sidebar":"Dock sidebar",type:"button",children:e?i.jsx(vD,{}):i.jsx(yD,{})})]})}function Cte({className:e}){return i.jsxs("div",{className:oe("min-w-0",e),children:[i.jsxs("div",{className:"flex items-baseline gap-1.5",children:[i.jsx("div",{className:"text-sm font-semibold",children:"NoMoreIDE"}),i.jsxs("div",{className:"font-mono text-[10px] text-muted-foreground",children:["v","0.1.85"]})]}),i.jsx("div",{className:"font-mono text-[11px] text-muted-foreground",children:"127.0.0.1 console"})]})}function Nte({syncLocation:e=!0}={}){return i.jsx(tY,{children:i.jsx(Z$,{children:i.jsx(jte,{syncLocation:e})})})}function Ete({projectPath:e,selectProject:t}){return x.useEffect(()=>{t(e)},[e,t]),null}function jte({syncLocation:e}){const t=ee(),[s,n]=x.useState(()=>e?vte(window.location.pathname):"services"),[a,l]=x.useState(null),[c,d]=x.useState(null),[f,h]=x.useState(null),[g,p]=x.useState(0),[b,v]=x.useState(null),[_,S]=x.useState(!0),{error:C,message:N,success:A}=ms(),{ui:j,updateUi:E,selectProject:T}=bm(),L=j.sidebarDocked,H=j.projectScope==="all",P=x.useCallback($=>E({projectScope:$?"all":"project"}),[E]),F=NU(),M=x.useCallback(async($={})=>{$.silent||S(!0),v(null);try{l(await q7()),$.notify&&A(t("app.dashboardRefreshed"))}catch(me){const J=me instanceof Error?me.message:String(me);v(J),C(J)}finally{S(!1)}},[C,A,t]),z=x.useCallback(()=>{M({notify:!0}),F.runActive()},[M,F]);x.useEffect(()=>{M()},[M]),x.useEffect(()=>{function $(){document.visibilityState==="visible"&&(M({silent:!0}),F.runActive())}const me=window.setInterval($,5e3);return window.addEventListener("focus",$),document.addEventListener("visibilitychange",$),()=>{window.clearInterval(me),window.removeEventListener("focus",$),document.removeEventListener("visibilitychange",$)}},[s,M,F.runActive]),x.useEffect(()=>{if(!e)return;const $=AT[s];window.location.pathname!==$&&window.history.pushState(null,"",$)},[s,e]);const G=!H&&a?.git.selectedRepository||null,D=x.useMemo(()=>a&&G?oY(a,G):a,[a,G]),q=x.useMemo(()=>G&&D?new Set(D.config.services.map($=>$.name)):null,[G,D]),W=x.useMemo(()=>D?Object.values(D.runtime.services).filter($=>$.state==="running").length:0,[D]),I=a?.git.selectedRepository?.name??a?.git.cwd??"no-git-repository",Y=a?.git.selectedRepository?.path??null;return i.jsxs(fF,{children:[i.jsx(Ete,{projectPath:Y,selectProject:T}),i.jsx(EU,{value:F,children:i.jsx(Fq,{onRefresh:()=>{M({silent:!0})},children:i.jsx(Uq,{children:i.jsxs("div",{className:"flex flex-col h-screen overflow-hidden",children:[i.jsx(fte,{}),i.jsxs("div",{className:"flex-1 overflow-hidden pb-9",children:[i.jsxs("div",{className:"mx-auto flex h-full max-w-[1500px]",children:[i.jsxs("aside",{className:yte(L),children:[i.jsxs("div",{className:oe("grid h-12 grid-cols-[48px_minmax(0,1fr)] items-center overflow-hidden transition-[width] duration-150",L?"w-full":"w-12 group-hover/sidebar:w-full"),children:[i.jsx("div",{className:"flex size-12 items-center justify-center",children:i.jsx("div",{className:"flex size-9 items-center justify-center overflow-hidden rounded-md bg-primary text-primary-foreground",children:i.jsxs("svg",{"aria-label":"NoMoreIDE",className:"size-6",fill:"none",role:"img",viewBox:"0 0 64 64",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("path",{d:"M5 17C5 13.69 7.69 11 11 11H25L31 17H53C56.31 17 59 19.69 59 23V53C59 56.31 56.31 59 53 59H11C7.69 59 5 56.31 5 53V17Z",fill:"currentColor"}),i.jsx("path",{d:"M22 31L30 39L22 47",stroke:"hsl(var(--primary))",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"4.5"}),i.jsx("path",{d:"M36 47H48",stroke:"hsl(var(--primary))",strokeLinecap:"round",strokeWidth:"4.5"})]})})}),i.jsx(Cte,{className:oe("min-w-0 translate-x-1 overflow-hidden transition-opacity duration-200",L?"opacity-100":"opacity-0 group-hover/sidebar:opacity-100")})]}),a?i.jsx("div",{className:"mt-3 border-b border-border/60 pb-2",children:i.jsx(cte,{data:a,docked:L,onRefresh:()=>M({silent:!0}),onScopeChange:P,scopeAll:H})}):null,i.jsx("nav",{className:"mt-2 flex-1 content-start overflow-y-auto overflow-x-hidden",children:xte.map(($,me)=>i.jsxs("div",{className:oe(me>0&&"mt-2 border-t border-border/60 pt-2"),children:[i.jsx(Ate,{docked:L,label:t($.labelKey)}),i.jsx("div",{className:"grid gap-0.5",children:$.items.map(J=>i.jsx(KN,{active:s===J.page,badge:J.page==="services"?W:void 0,docked:L,icon:J.icon,label:t(J.labelKey),onClick:()=>n(J.page)},J.page))})]},$.labelKey))}),i.jsx("div",{className:"mb-1 border-t border-border/60 pt-1",children:i.jsx(KN,{active:s==="settings",docked:L,icon:i.jsx(gE,{}),label:t("nav.settings"),onClick:()=>n("settings")})}),i.jsx(kte,{docked:L,onToggleDock:()=>E({sidebarDocked:!L})})]}),i.jsxs("main",{className:"flex h-full min-w-0 flex-1 flex-col px-0 py-0",children:[i.jsxs("header",{className:oe("relative z-40 flex shrink-0 flex-wrap items-center justify-between gap-3 border border-border bg-card/90 px-4 py-3 backdrop-blur","border-x-0 border-t-0 border-b"),children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx(wD,{className:"size-4 text-muted-foreground md:hidden"}),i.jsxs("div",{children:[i.jsx("h1",{className:"text-lg font-semibold tracking-tight",children:t(gte[s])}),i.jsx("p",{className:"font-mono text-xs text-muted-foreground",children:s==="git"||s==="github"?a?.git.selectedRepository?.name??a?.git.cwd??t("app.localWorkspace"):G?.name??t("app.allProjects")})]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[b?i.jsx(Ke,{variant:"danger",children:b}):null,i.jsxs("div",{"aria-label":"Dashboard quick actions",className:"flex items-center gap-1 rounded-lg border border-border bg-background p-px",role:"toolbar",children:[i.jsxs("button",{"aria-label":t("action.refresh"),className:gf(),onClick:z,title:t("action.refreshTitle"),type:"button",children:[i.jsx("span",{className:bf(),children:i.jsx(Pr,{className:oe(_&&"animate-spin")})}),i.jsx("span",{className:vf(),children:t("action.refresh")})]}),i.jsx(hte,{}),i.jsxs("a",{"aria-label":t("action.docsTitle"),className:gf(),href:"https://www.nomoreide.com/docs",rel:"noreferrer",target:"_blank",title:t("action.docsTitle"),children:[i.jsx("span",{className:bf(),children:i.jsx(QN,{})}),i.jsx("span",{className:vf(),children:t("action.docs")})]}),a?i.jsx(Sq,{data:a}):null]})]})]}),i.jsx("div",{className:"relative z-30 shrink-0 px-4 pt-2",children:i.jsx(pte,{})}),a?i.jsx(vZ,{data:a,onOpenService:$=>{q&&!q.has($)&&(P(!0),N({text:t("app.serviceOutsideScope")})),d($),n("services"),M({silent:!0})}}):null,_&&!a?i.jsx(tt,{variant:"muted",children:t("app.loading")}):null,i.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[D&&s==="services"?i.jsx(pZ,{data:D,onRefresh:M,focusService:c,onServiceFocused:()=>d(null),scopeName:G?.name??null}):null,a&&s==="git"?i.jsx(eee,{data:a,onRefresh:()=>{M({silent:!0})}}):null,s==="github"?i.jsx(ste,{},I):null,s==="workflows"?i.jsx(lee,{}):null,s==="agent"?i.jsx(CU,{focusChanges:g,onOpenAgentEnv:()=>n("agent-env")}):null,s==="agent-env"?i.jsx(ZU,{}):null,s==="errors"?i.jsx(tX,{inScope:q?$=>q.has($):void 0,onReviewChanges:()=>{p($=>$+1),n("agent")}}):null,s==="database"?i.jsx(LY,{projects:a?.config.gitRepositories??[],scopePath:G?.path??null,staged:f,onStageConsumed:()=>h(null)}):null,s==="terminal"?i.jsx(kZ,{}):null,s==="settings"?i.jsx(VY,{activeProject:a?.git.selectedRepository??null,onNavigate:$=>n($)}):null]})]})]}),a&&s==="git"?i.jsx(dte,{ahead:a.git.status?.ahead??0,behind:a.git.status?.behind??0,branches:a.git.branches,currentBranch:a.git.status?.branch||void 0,disabled:!a.git.status,onRefresh:M,upstream:a.git.status?.upstream}):null,i.jsx(rY,{currentPage:s,git:a?.git,onNavigate:$=>n($),onGitRefresh:()=>{M({silent:!0})}})]})]})})})})]})}function Ate({docked:e,label:t}){return i.jsx("div",{className:"flex h-5 items-center overflow-hidden px-3",children:i.jsx("span",{className:oe("whitespace-pre text-[10px] font-semibold uppercase tracking-widest text-muted-foreground transition-opacity duration-150",e?"opacity-100":"opacity-0 group-hover/sidebar:opacity-100"),children:t})})}function KN({active:e,badge:t,docked:s,icon:n,label:a,onClick:l}){const c=t!==void 0&&t>0;return i.jsxs(Q,{"aria-label":a,title:a,className:_te(e,s),variant:"ghost",onClick:l,type:"button",children:[i.jsx("span",{className:Ste(s),children:n}),i.jsx("span",{className:wte(s,c),children:a}),t!==void 0&&t>0?i.jsx(Ke,{appearance:t>0?"solid":"outline",className:oe("min-w-6 justify-center px-1.5 font-mono shadow-none",e?"border-primary-foreground/40 bg-primary-foreground/15 text-primary-foreground dark:border-primary-foreground/40 dark:bg-primary-foreground/15 dark:text-primary-foreground":t>0?"":"border-border bg-background text-muted-foreground","absolute right-1.5 top-1.5 h-4 min-w-4 rounded-full px-1 text-[10px] leading-none shadow-none group-hover/sidebar:right-2 group-hover/sidebar:top-1/2 group-hover/sidebar:-translate-y-1/2 group-hover/sidebar:text-xs",s&&"right-2 top-1/2 -translate-y-1/2 text-xs"),size:"small",variant:t>0?"success":"outline",children:t}):null]})}XN.createRoot(document.getElementById("root")).render(i.jsx(x.StrictMode,{children:i.jsx(Nte,{})}));export{i as j,x as r};
|