nomoreide 0.1.92 → 0.1.93
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.
- package/README.md +22 -1
- package/dist/cli/commands.d.ts +2 -0
- package/dist/cli/commands.js +32 -3
- package/dist/cli/commands.js.map +1 -1
- package/dist/core/agent-env-writers.d.ts +19 -0
- package/dist/core/agent-env-writers.js +220 -8
- package/dist/core/agent-env-writers.js.map +1 -1
- package/dist/core/agent-profiles/apply.d.ts +16 -0
- package/dist/core/agent-profiles/apply.js +24 -11
- package/dist/core/agent-profiles/apply.js.map +1 -1
- package/dist/core/agent-profiles/builtin.d.ts +8 -0
- package/dist/core/agent-profiles/builtin.js +33 -0
- package/dist/core/agent-profiles/builtin.js.map +1 -0
- package/dist/core/agent-profiles/debug-setup.d.ts +18 -0
- package/dist/core/agent-profiles/debug-setup.js +237 -0
- package/dist/core/agent-profiles/debug-setup.js.map +1 -0
- package/dist/core/agent-profiles/index.d.ts +3 -1
- package/dist/core/agent-profiles/index.js +3 -1
- package/dist/core/agent-profiles/index.js.map +1 -1
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.js +8 -0
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools/services.d.ts +2 -0
- package/dist/mcp/tools/services.js +18 -9
- package/dist/mcp/tools/services.js.map +1 -1
- package/dist/web/client/assets/{code-editor-KPRIkcWr.js → code-editor-C9RcL5cM.js} +1 -1
- package/dist/web/client/assets/{index-Czn4YU1U.js → index-94L5mFZd.js} +3 -3
- package/dist/web/client/index.html +1 -1
- package/package.json +2 -1
- package/profiles/nomoreide-debug/profile.json +19 -0
- package/profiles/nomoreide-debug/skills/nomoreide-debug/SKILL.md +38 -0
- package/profiles/nomoreide-debug/skills/nomoreide-debug/agents/openai.yaml +13 -0
- package/profiles/nomoreide-debug/skills/nomoreide-debug/evals/evals.json +23 -0
|
@@ -116,7 +116,7 @@ WARNING: This link could potentially be dangerous`)){let s=window.open();if(s){t
|
|
|
116
116
|
`&&(this._liveRegionLineCount++,this._liveRegionLineCount===iN+1&&(this._liveRegion.textContent+=jx.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,i=s.lines.length.toString();for(let a=e;a<=t;a++){let l=s.lines.get(s.ydisp+a),c=[],u=l?.translateToString(!0,void 0,void 0,c)||"",f=(s.ydisp+a+1).toString(),h=this._rowElements[a];h&&(u.length===0?(h.textContent=" ",this._rowColumns.set(h,[0,1])):(h.textContent=u,this._rowColumns.set(h,c)),h.setAttribute("aria-posinset",f),h.setAttribute("aria-setsize",i),this._alignRowWidth(h))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce="")}_handleBoundaryFocus(e,t){let s=e.target,i=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!==i)return;let c,u;if(t===0?(c=s,u=this._rowElements.pop(),this._rowContainer.removeChild(u)):(c=this._rowElements.shift(),u=s,this._rowContainer.removeChild(c)),c.removeEventListener("focus",this._topBoundaryFocusListener),u.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 i=this._rowElements.slice(-1)[0];if(s.node.compareDocumentPosition(i)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(s={node:i,offset:i.textContent?.length??0}),!this._rowContainer.contains(s.node))return;let a=({node:u,offset:f})=>{let h=u instanceof Text?u.parentNode:u,p=parseInt(h?.getAttribute("aria-posinset"),10)-1;if(isNaN(p))return console.warn("row is invalid. Race condition?"),null;let g=this._rowColumns.get(h);if(!g)return console.warn("columns is null. Race condition?"),null;let b=f<g.length?g[f]:g.slice(-1)[0]+1;return b>=this._terminal.cols&&(++p,b=0),{row:p,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 i=s*this._renderService.dimensions.css.cell.width;e.style.transform=`scaleX(${i/t})`}};Uf=As([Xe(1,S1),Xe(2,Jr),Xe(3,ea)],Uf);var c0=class extends At{constructor(e,t,s,i,a){super(),this._element=e,this._mouseService=t,this._renderService=s,this._bufferService=i,this._linkProviderService=a,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this._register(new Ue),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new Ue),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(xs(()=>{Oo(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(vt(this._element,"mouseleave",()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(vt(this._element,"mousemove",this._handleMouseMove.bind(this))),this._register(vt(this._element,"mousedown",this._handleMouseDown.bind(this))),this._register(vt(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 i=0;i<s.length;i++){let a=s[i];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(i=>{i?.forEach(a=>{a.link.dispose&&a.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=e.y);let s=!1;for(let[i,a]of this._linkProviderService.linkProviders.entries())t?this._activeProviderReplies?.get(i)&&(s=this._checkLinkProviderResult(i,e,s)):a.provideLinks(e.y,l=>{if(this._isMouseOut)return;let c=l?.map(u=>({link:u}));this._activeProviderReplies?.set(i,c),s=this._checkLinkProviderResult(i,e,s),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)})}_removeIntersectingLinks(e,t){let s=new Set;for(let i=0;i<t.size;i++){let a=t.get(i);if(a)for(let l=0;l<a.length;l++){let c=a[l],u=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=u;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 i=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&&i){let l=i.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(u=>this._linkAtPosition(u.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&&sX(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,Oo(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 i=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>=i&&this._currentLink.link.range.end.y<=a&&(this._clearCurrentLink(i,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,i=this._bufferService.buffer.ydisp,a=this._createLinkUnderlineEvent(s.start.x-1,s.start.y-i-1,s.end.x,s.end.y-i-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,i=e.range.end.y*this._bufferService.cols+e.range.end.x,a=t.y*this._bufferService.cols+t.x;return s<=a&&a<=i}_positionFromMouseEvent(e,t,s){let i=s.getCoords(e,t,this._bufferService.cols,this._bufferService.rows);if(i)return{x:i[0],y:i[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(e,t,s,i,a){return{x1:e,y1:t,x2:s,y2:i,cols:this._bufferService.cols,fg:a}}};c0=As([Xe(1,k1),Xe(2,ea),Xe(3,Dn),Xe(4,cT)],c0);function sX(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 nX=class extends KY{constructor(e={}){super(e),this._linkifier=this._register(new Fl),this.browser=jT,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new Fl),this._onCursorMove=this._register(new Ue),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new Ue),this.onKey=this._onKey.event,this._onRender=this._register(new Ue),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new Ue),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new Ue),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new Ue),this.onBell=this._onBell.event,this._onFocus=this._register(new Ue),this._onBlur=this._register(new Ue),this._onA11yCharEmitter=this._register(new Ue),this._onA11yTabEmitter=this._register(new Ue),this._onWillOpen=this._register(new Ue),this._setup(),this._decorationService=this._instantiationService.createInstance(QY),this._instantiationService.setService(Qu,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(VK),this._instantiationService.setService(cT,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(Tx)),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(mn.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(mn.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(mn.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(mn.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(t=>this._afterResize(t.cols,t.rows))),this._register(xs(()=>{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,i="";switch(t.index){case 256:s="foreground",i="10";break;case 257:s="background",i="11";break;case 258:s="cursor",i="12";break;default:s="ansi",i="4;"+t.index}switch(t.type){case 0:let a=ms.toColorRGB(s==="ansi"?this._themeService.colors.ansi[t.index]:this._themeService.colors[s]);this.coreService.triggerDataEvent(`${Me.ESC}]${i};${FY(a)}${NT.ST}`);break;case 1:if(s==="ansi")this._themeService.modifyColors(l=>l.ansi[t.index]=Us.toColor(...t.color));else{let l=s;this._themeService.modifyColors(c=>c[l]=Us.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(Uf,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(Me.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(Me.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),i=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,u=s*this._renderService.dimensions.css.cell.width;this.textarea.style.left=u+"px",this.textarea.style.top=c+"px",this.textarea.style.width=l+"px",this.textarea.style.height=i+"px",this.textarea.style.lineHeight=i+"px",this.textarea.style.zIndex="-5"}_initGlobal(){this._bindKeys(),this._register(vt(this.element,"copy",t=>{this.hasSelection()&&oW(t,this._selectionService)}));let e=t=>lW(t,this.textarea,this.coreService,this.optionsService);this._register(vt(this.textarea,"paste",e)),this._register(vt(this.element,"paste",e)),AT?this._register(vt(this.element,"mousedown",t=>{t.button===2&&mC(t,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(vt(this.element,"contextmenu",t=>{mC(t,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),M1&&this._register(vt(this.element,"auxclick",t=>{t.button===1&&eT(t,this.textarea,this.screenElement)}))}_bindKeys(){this._register(vt(this.textarea,"keyup",e=>this._keyUp(e),!0)),this._register(vt(this.textarea,"keydown",e=>this._keyDown(e),!0)),this._register(vt(this.textarea,"keypress",e=>this._keyPress(e),!0)),this._register(vt(this.textarea,"compositionstart",()=>this._compositionHelper.compositionstart())),this._register(vt(this.textarea,"compositionupdate",e=>this._compositionHelper.compositionupdate(e))),this._register(vt(this.textarea,"compositionend",()=>this._compositionHelper.compositionend())),this._register(vt(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(vt(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",Ex.get()),MT||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(qK,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<"u"?window.document:null)),this._instantiationService.setService(Jr,this._coreBrowserService),this._register(vt(this.textarea,"focus",a=>this._handleTextAreaFocus(a))),this._register(vt(this.textarea,"blur",()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(Zx,this._document,this._helperContainer),this._instantiationService.setService(jm,this._charSizeService),this._themeService=this._instantiationService.createInstance(t0),this._instantiationService.setService(Zl,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(Hf),this._instantiationService.setService(lT,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(Jx,this.rows,this.screenElement)),this._instantiationService.setService(ea,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(Kx,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(Qx),this._instantiationService.setService(k1,this._mouseService);let i=this._linkifier.value=this._register(this._instantiationService.createInstance(c0,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(Vx,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(e0,this.element,this.screenElement,i)),this._instantiationService.setService(gW,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(mn.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(Wx,this.screenElement)),this._register(vt(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(Uf,this)),this._register(this.optionsService.onSpecificOptionChange("screenReaderMode",a=>this._handleScreenReaderModeOptionChange(a))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(If,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange("overviewRuler",a=>{!this._overviewRulerRenderer&&a&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(If,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(Xx,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 u,f;switch(l.overrideType||l.type){case"mousemove":f=32,l.buttons===void 0?(u=3,l.button!==void 0&&(u=l.button<3?l.button:3)):u=l.buttons&1?0:l.buttons&4?1:l.buttons&2?2:3;break;case"mouseup":f=0,u=l.button<3?l.button:3;break;case"mousedown":f=1,u=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,u=4;break;default:return!1}return f===void 0||u===void 0||u>4?!1:e.coreMouseService.triggerMouseEvent({col:c.col,row:c.row,x:c.x,y:c.y,button:u,action:f,ctrl:l.ctrlKey,alt:l.altKey,shift:l.shiftKey})}let i={mouseup:null,wheel:null,mousedrag:null,mousemove:null},a={mouseup:l=>(s(l),l.buttons||(this._document.removeEventListener("mouseup",i.mouseup),i.mousedrag&&this._document.removeEventListener("mousemove",i.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?i.mousemove||(t.addEventListener("mousemove",a.mousemove),i.mousemove=a.mousemove):(t.removeEventListener("mousemove",i.mousemove),i.mousemove=null),l&16?i.wheel||(t.addEventListener("wheel",a.wheel,{passive:!1}),i.wheel=a.wheel):(t.removeEventListener("wheel",i.wheel),i.wheel=null),l&2?i.mouseup||(i.mouseup=a.mouseup):(this._document.removeEventListener("mouseup",i.mouseup),i.mouseup=null),l&4?i.mousedrag||(i.mousedrag=a.mousedrag):(this._document.removeEventListener("mousemove",i.mousedrag),i.mousedrag=null)})),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this._register(vt(t,"mousedown",l=>{if(l.preventDefault(),this.focus(),!(!this.coreMouseService.areMouseEventsActive||this._selectionService.shouldForceSelection(l)))return s(l),i.mouseup&&this._document.addEventListener("mouseup",i.mouseup),i.mousedrag&&this._document.addEventListener("mousemove",i.mousedrag),this.cancel(l)})),this._register(vt(t,"wheel",l=>{if(!i.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=Me.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){JA(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=XY(e,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(e),s.type===3||s.type===2){let i=this.rows-1;return this.scrollLines(s.type===2?-i:i),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===Me.ETX||s.key===Me.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)&&(iX(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(Hs));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(Me.ESC+"[I"):this.coreService.triggerDataEvent(Me.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(`${Me.ESC}[4;${s};${t}t`);break;case 1:let i=this._renderService.dimensions.css.cell.width.toFixed(0),a=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${Me.ESC}[6;${a};${i}t`);break}}cancel(e,t){if(!(!this.options.cancelEvents&&!t))return e.preventDefault(),e.stopPropagation(),!1}};function iX(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}var rX=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)}},aX=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 Ri)}translateToString(e,t,s){return this._line.translateToString(e,t,s)}},rN=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 aX(t)}getNullCell(){return new Ri}},oX=class extends At{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new Ue),this.onBufferChange=this._onBufferChange.event,this._normal=new rN(this._core.buffers.normal,"normal"),this._alternate=new rN(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)}},lX=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,i)=>t(s,i.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)}},cX=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}},uX=["cols","rows"],or=0,dX=class extends At{constructor(e){super(),this._core=this._register(new nX(e)),this._addonManager=this._register(new rX),this._publicOptions={...this._core.options};let t=i=>this._core.options[i],s=(i,a)=>{this._checkReadonlyOptions(i),this._core.options[i]=a};for(let i in this._core.options){let a={get:t.bind(this,i),set:s.bind(this,i)};Object.defineProperty(this._publicOptions,i,a)}}_checkReadonlyOptions(e){if(uX.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 lX(this._core)),this._parser}get unicode(){return this._checkProposedApi(),new cX(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 oX(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 Ex.get()},set promptLabel(e){Ex.set(e)},get tooMuchOutput(){return jx.get()},set tooMuchOutput(e){jx.set(e)}}}_verifyIntegers(...e){for(or of e)if(or===1/0||isNaN(or)||or%1!==0)throw new Error("This API only accepts integers")}_verifyPositiveIntegers(...e){for(or of e)if(or&&(or===1/0||isNaN(or)||or%1!==0||or<0))throw new Error("This API only accepts positive integers")}};const FT="nomoreide-theme-choice",hX="nomoreide:ui-preferences";function fX(){if(typeof window>"u")return"system";try{const e=window.localStorage.getItem(hX),t=e?JSON.parse(e):null;if((t?.version===1||t?.version===2)&&(t.theme==="light"||t.theme==="dark"||t.theme==="system"))return t.theme}catch{}try{const e=window.localStorage.getItem(FT);if(e==="light"||e==="dark"||e==="system")return e}catch{}return"system"}function D1(e){return e!=="system"?e:typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function u0(e){if(typeof document>"u")return;const t=document.documentElement;t.classList.toggle("dark",e==="dark"),t.style.colorScheme=e}let zo=fX(),Eo=D1(zo);const pf=new Set;let Do=null;function UT(){for(const e of pf)e()}function qf(){if(Do?.(),Do=null,Eo=D1(zo),u0(Eo),zo!=="system"||typeof window>"u"||typeof window.matchMedia!="function")return;const e=window.matchMedia("(prefers-color-scheme: dark)"),t=s=>{Eo=s.matches?"dark":"light",u0(Eo),UT()};e.addEventListener("change",t),Do=()=>e.removeEventListener("change",t)}qf();function mX(){return zo}function pX(){return Eo}function d0(e){if(!(e!==zo)){e==="system"&&!Do?qf():(Eo=D1(e),u0(Eo));return}zo=e,qf();try{window.localStorage.setItem(FT,e)}catch{}UT()}function qT(e){return pf.add(e),zo==="system"&&!Do&&qf(),()=>{pf.delete(e),pf.size===0&&(Do?.(),Do=null)}}function GT(){return[v.useSyncExternalStore(qT,mX,()=>"system"),d0]}function VT(){return v.useSyncExternalStore(qT,pX,()=>"dark")}const gX={fontSize:13,cursorStyle:"block",scrollback:5e3,copyOnSelect:!1},Pb={state:"connecting",cwd:Co("terminal.localWorkspace"),detail:Co("terminal.openingShell")},Gf=1;function aN(e){return e==="light"?{background:"#fcfcfc",black:"#24211f",blue:"#2869b8",brightBlack:"#6e6964",brightBlue:"#3478c9",brightCyan:"#188e88",brightGreen:"#2c8d49",brightMagenta:"#925db6",brightRed:"#d94747",brightWhite:"#ffffff",brightYellow:"#9a7200",cursor:"#24211f",cyan:"#147d78",foreground:"#24211f",green:"#247a3c",magenta:"#8050a6",red:"#c43d3d",selectionBackground:"#147d7830",white:"#d9d5d0",yellow:"#8a6500"}:{background:"#090909",black:"#090909",blue:"#69a7ff",brightBlack:"#5f6368",brightBlue:"#8ab4f8",brightCyan:"#7ddfd7",brightGreen:"#8fdc8a",brightMagenta:"#d7a2ff",brightRed:"#ff8a80",brightWhite:"#ffffff",brightYellow:"#ffd166",cursor:"#f2f2f2",cyan:"#62d0c8",foreground:"#f2f2f2",green:"#7ac77f",magenta:"#c792ea",red:"#ff6b6b",selectionBackground:"#ffffff33",white:"#e8eaed",yellow:"#f7c948"}}function bX(e){return{focus:e.focus,input:e.sendInput,refit:e.refit,restart:()=>e.sendControl("restart"),stop:()=>e.sendControl("stop")}}function vX(e,t,s){if(!e||e.readyState!==Gf)return;const i=t?.proposeDimensions();e.send(JSON.stringify({cols:i?.cols,rows:i?.rows,type:s}))}function xX(e,t){if(!e)return;const s=t.schedule(()=>{t.refit(),t.focus()});return()=>t.cancel(s)}function yX(e){const t=e.location??window.location,s=e.createSocket??(p=>new WebSocket(p));e.reportStatus(e.initialStatus);const i=s(_X(e.sessionId,t));let a=!1,l;const c=[],u=e.scheduleInitialInput??(p=>{const g=window.setTimeout(p,200);return()=>window.clearTimeout(g)}),f=()=>{l?.(),l=u(()=>{l=void 0,(e.claimInitialInput?.()??[]).forEach((g,b)=>{const x=()=>i.send(JSON.stringify({data:g,type:"input"}));if(b===0)x();else{const _=e.scheduleInput??((k,C)=>{const E=window.setTimeout(k,C);return()=>window.clearTimeout(E)});c.push(_(x,b*(e.initialInputIntervalMs??75)))}})})},h=e.terminal.onData(p=>{a||i.readyState===Gf&&i.send(JSON.stringify({data:p,type:"input"}))});return i.addEventListener("open",()=>{a||(e.reportStatus(p=>({...p,state:"running",detail:Co("terminal.shellConnected")})),e.sendResize())}),i.addEventListener("message",p=>{if(a)return;const g=wX(p.data);if(g){if(g.type==="output"){e.terminal.write(g.data),f();return}if(g.type==="error"){e.reportStatus(b=>({...b,state:"error",detail:g.error}));return}e.reportStatus(b=>({state:g.state==="idle"?"connecting":g.state,cwd:g.cwd??b.cwd,detail:g.error??g.shell??Co("terminal.shellConnected")}))}}),i.addEventListener("close",()=>{a||e.reportStatus(p=>({...p,state:p.state==="exited"?p.state:"exited",detail:Co("terminal.socketClosed")}))}),i.addEventListener("error",()=>{a||e.reportStatus(p=>({...p,state:"error",detail:Co("terminal.socketError")}))}),{socket:i,dispose:()=>{a||(a=!0,l?.(),c.forEach(p=>{p()}),h.dispose(),i.close())}}}const WT=v.forwardRef(function({sessionId:t,active:s,focused:i=s,claimInitialInput:a,initialInputIntervalMs:l,onStatusChange:c,displaySettings:u=gX},f){const h=VT(),p=v.useRef(null),g=v.useRef(null),b=v.useRef(null),x=v.useRef(null),_=v.useRef(c),k=v.useRef(u),C=v.useRef(Pb),E=js();v.useEffect(()=>{_.current=c},[c]);const j=v.useCallback(D=>{const z=typeof D=="function"?D(C.current):D;C.current=z,_.current?.(z)},[]),N=v.useCallback(()=>{const D=b.current;if(!D)return;D.fit();const z=D.proposeDimensions();if(!z)return;if(E){U7(t,z.cols,z.rows);return}const O=x.current;O?.readyState===Gf&&O.send(JSON.stringify({cols:z.cols,rows:z.rows,type:"resize"}))},[E,t]);v.useEffect(()=>{k.current=u;const D=g.current;D&&(D.options.fontSize=u.fontSize,D.options.cursorStyle=u.cursorStyle,D.options.scrollback=u.scrollback,N())},[u.copyOnSelect,u.cursorStyle,u.fontSize,u.scrollback,N]);const A=v.useCallback(D=>{E||vX(x.current,b.current,D)},[E]),T=v.useCallback(D=>{if(E){Yg(t,D);return}const z=x.current;z?.readyState===Gf&&z.send(JSON.stringify({data:D,type:"input"}))},[E,t]);return v.useImperativeHandle(f,()=>bX({focus:()=>g.current?.focus(),refit:N,sendControl:A,sendInput:T}),[A,T,N]),v.useEffect(()=>{const D=p.current;if(!D)return;const z=new dX({allowProposedApi:!0,cursorBlink:!0,cursorStyle:k.current.cursorStyle,fontFamily:'"SF Mono", "Symbols Nerd Font Mono", "JetBrains Mono", ui-monospace, Menlo, monospace',fontSize:k.current.fontSize,lineHeight:1.25,scrollback:k.current.scrollback,theme:aN(h)}),O=new sW;z.loadAddon(O),z.open(D),g.current=z,b.current=O;const $=z.onSelectionChange(()=>{if(!k.current.copyOnSelect)return;const B=z.getSelection();if(B)try{navigator.clipboard?.writeText(B).catch(()=>{})}catch{}});let M;if(E){j(Pb);let B=null,U=!1,Y;const P=z.onData(V=>{Yg(t,V)});G7(t,V=>{z.write(V),Y!==void 0&&window.clearTimeout(Y),Y=window.setTimeout(()=>{Y=void 0,(async()=>{const W=a?.()??[];for(let re=0;re<W.length;re+=1)re>0&&await new Promise(ce=>window.setTimeout(ce,l??75)),await Yg(t,W[re])})()},200)}).then(V=>{if(U){V();return}B=V,j(W=>({...W,state:"running",detail:Co("terminal.shellConnected")})),F7(t),N()},V=>{U||j(W=>({...W,state:"error",detail:V instanceof Error?V.message:String(V)}))}),M=()=>{U=!0,Y!==void 0&&window.clearTimeout(Y),P.dispose(),B?.()}}else{const B=yX({claimInitialInput:a,initialInputIntervalMs:l,initialStatus:Pb,reportStatus:j,sendResize:N,sessionId:t,terminal:z});x.current=B.socket,M=()=>{B.dispose(),x.current=null}}window.addEventListener("resize",N);const I=window.setTimeout(N,0),G=new ResizeObserver(()=>N());return G.observe(D),()=>{window.removeEventListener("resize",N),window.clearTimeout(I),G.disconnect(),M(),$.dispose(),z.dispose(),g.current=null,b.current=null}},[j,t,N,E]),v.useEffect(()=>{const D=g.current;D&&(D.options.theme=aN(h))},[h]),v.useEffect(()=>xX(s,{cancel:D=>window.clearTimeout(D),focus:()=>{i&&g.current?.focus()},refit:N,schedule:D=>window.setTimeout(D,0)}),[s,i,N]),n.jsx("section",{"aria-label":"terminal viewport",className:se("h-full min-h-0 overflow-hidden bg-[#fcfcfc] px-3 py-0.5 dark:bg-[#090909]",!s&&"hidden"),children:n.jsx("div",{className:"h-full w-full",ref:p})})});function _X(e,t){const s=t.protocol==="https:"?"wss:":"ws:",i=encodeURIComponent(e);return`${s}//${t.host}/api/terminal/socket?id=${i}`}function wX(e){if(typeof e!="string")return null;try{const t=JSON.parse(e);return typeof t?.type=="string"?t:null}catch{return null}}const SX={skills:"agent-env",mcps:"agent-env",plugins:"agent-env",hooks:"agent"};function KT(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 YT({auth:e,mcps:t}){return t===0?null:e?e.failed?n.jsx("span",{className:"size-1.5 rounded-full bg-red-500"}):e.needsAuth?n.jsx("span",{className:"size-1.5 rounded-full bg-amber-500"}):e.checked?n.jsx("span",{className:"size-1.5 rounded-full bg-emerald-500"}):null:n.jsx("span",{className:"size-1.5 animate-pulse rounded-full bg-muted-foreground/50"})}function kX(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 n.jsx("span",{className:se("size-1.5 shrink-0 rounded-full",t)})}function CX(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 NX({anchor:e,items:t,mcpAuth:s,onClose:i,onInsert:a,onManage:l}){const c=X(),u=v.useRef(null);return v.useEffect(()=>{function f(g){const b=g.target;u.current?.contains(b)||b.closest?.("[data-capability-trigger]")||i()}function h(g){g.key==="Escape"&&i()}function p(g){u.current?.contains(g.target)||i()}return document.addEventListener("mousedown",f),document.addEventListener("keydown",h),window.addEventListener("scroll",p,!0),()=>{document.removeEventListener("mousedown",f),document.removeEventListener("keydown",h),window.removeEventListener("scroll",p,!0)}},[i]),Xn.createPortal(n.jsxs("div",{className:"fixed z-50 w-72 overflow-hidden rounded-md border border-border bg-card shadow-md","data-capability-menu":!0,ref:u,style:e.up?{left:e.left,bottom:window.innerHeight-e.top+4}:{left:e.left,top:e.bottom+4},children:[n.jsx("div",{className:"max-h-64 overflow-y-auto p-1",children:t.length===0?n.jsx("div",{className:"px-2 py-1.5 text-[11px] text-muted-foreground",children:c("dock.capabilityEmpty")}):t.map((f,h)=>{const p=f.insert,g=n.jsxs(n.Fragment,{children:[s?kX(s[f.name]):null,n.jsx("span",{className:se("truncate font-mono text-xs",f.sub&&"pl-4"),children:f.name}),f.detail?n.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 p&&a?n.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(p),i()},type:"button",children:g},b):n.jsx("div",{className:"flex w-full items-center gap-2 px-2 py-1.5",children:g},b)})}),l?n.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(),i()},type:"button",children:c("dock.capabilityManage")}):null]}),document.body)}function XT(e,t,s){const[i,a]=v.useState(null),l=u=>f=>{const h=CX(f.currentTarget);a(p=>p?.key===u?null:{key:u,anchor:h})},c=i&&e.items?n.jsx(NX,{anchor:i.anchor,items:e.items[i.key],mcpAuth:i.key==="mcps"?e.mcpAuth:void 0,onClose:()=>a(null),onInsert:t,onManage:s?()=>s(SX[i.key]):void 0}):null;return{openKey:i?.key??null,toggle:l,dropdown:c}}function EX({capabilities:e,providerLabel:t,onInsert:s,onNavigate:i}){const a=X(),{counts:l,auth:c}=e,{openKey:u,toggle:f,dropdown:h}=XT(e,s,i);return l?n.jsxs("nav",{"aria-label":a("dock.capabilitiesAria",{name:t??"Agent"}),className:"mt-2 flex flex-wrap items-center gap-1.5",children:[n.jsx(Bh,{count:l.skills,expanded:u==="skills",icon:n.jsx(Sn,{}),label:a("agentEnv.skills"),onClick:f("skills")}),n.jsx(Bh,{count:l.mcps,expanded:u==="mcps",icon:n.jsx(um,{}),label:a("agentEnv.mcpServers"),onClick:f("mcps"),title:KT(a,c),trailing:n.jsx(YT,{auth:c,mcps:l.mcps})}),n.jsx(Bh,{count:l.plugins,expanded:u==="plugins",icon:n.jsx(Fu,{}),label:a("agentEnv.plugins"),onClick:f("plugins")}),n.jsx(Bh,{count:l.hooks,expanded:u==="hooks",icon:n.jsx(P0,{}),label:a("dock.hooks"),onClick:f("hooks")}),h]}):null}function oN({capabilities:e,providerLabel:t,onInsert:s,onNavigate:i}){const a=X(),{counts:l,auth:c}=e,{openKey:u,toggle:f,dropdown:h}=XT(e,s,i);if(!l)return null;const p=(b,x,_,k,C)=>n.jsxs("button",{"aria-expanded":u===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:k,type:"button",children:[x,n.jsx("span",{children:_}),C]}),g=[`${a("agentEnv.mcpServers")}: ${l.mcps}`,KT(a,c)].filter(Boolean).join(" · ");return n.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:[p("skills",n.jsx(Sn,{}),l.skills,`${a("agentEnv.skills")}: ${l.skills}`),p("mcps",n.jsx(um,{}),l.mcps,g,n.jsx(YT,{auth:c,mcps:l.mcps})),p("plugins",n.jsx(Fu,{}),l.plugins,`${a("agentEnv.plugins")}: ${l.plugins}`),p("hooks",n.jsx(P0,{}),l.hooks,`${a("dock.hooks")}: ${l.hooks}`),h]})}function Bh({count:e,expanded:t,icon:s,label:i,onClick:a,title:l,trailing:c}){return n.jsxs("button",{"aria-expanded":t,className:se("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,n.jsx("span",{children:i}),n.jsx("span",{className:"font-mono text-foreground",children:e}),c]})}function jX(e){return Object.keys(e.mcpServers).length+Object.keys(e.remoteMcpServers).length+Object.keys(e.projectMcpServers).length+Object.keys(e.projectRemoteMcpServers).length}function AX(e,t){const s=e?.skills??[];return{skills:s.filter(i=>i.kind!=="plugin").length,plugins:s.filter(i=>i.kind==="plugin").length,mcps:e?jX(e):0,hooks:t}}function TX(e){let t=0,s=0;for(const i of e)i.state==="needs-auth"?t+=1:i.state==="failed"&&(s+=1);return{checked:e.length,needsAuth:t,failed:s}}function RX(e,t){return t==="claude"?`/${e} `:`@${e} `}function MX(e){return`Use the "${e}" MCP server: `}function DX(e,t,s){const i=[],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 i.push({name:f.name,detail:f.scope,insert:RX(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 p of Object.keys(f))l.push({name:p,detail:h,insert:MX(p)});const u=t.map(f=>({name:f.matcher?`${f.event} · ${f.matcher}`:f.event,detail:f.command}));return{skills:i,plugins:a,mcps:l,hooks:u}}function LX(e,t=!0){const s=e==="codex"?"codex":"claude",i=e==="codex"?"codex":"claude-code",[a,l]=v.useState(null),[c,u]=v.useState(null),[f,h]=v.useState(null),[p,g]=v.useState({});return v.useEffect(()=>{if(!t)return;let b=!1;return l(null),u(null),h(null),g({}),Promise.all([i3().catch(()=>[]),B0().catch(()=>null)]).then(([x,_])=>{if(b)return;const k=x.find(E=>E.agent===s),C=_?.agents[i]?.hooks??[];l(AX(k,C.length)),u(DX(k,C,e))}),n3(i).then(x=>{b||(h(TX(x)),g(Object.fromEntries(x.map(_=>[_.name,_.state]))))}).catch(()=>{b||h({checked:0,needsAuth:0,failed:0})}),()=>{b=!0}},[t,s,i,e]),{counts:a,items:c,auth:f,mcpAuth:p}}const OX=new Set(["c","cpp","cs","go","java","js","jsx","kt","mjs","py","rs","swift","ts","tsx"]),PX=new Set([".env",".gitignore","components.json","dockerfile","package.json","tsconfig.json","vite.config.ts"]),zX=new Set(["conf","config","ini","toml","yaml","yml"]),BX=new Set(["csv","json","sql","xml"]),IX=new Set(["md","mdx","rst","txt"]),HX=new Set(["gif","jpeg","jpg","png","svg","webp"]),$X=new Set(["package-lock.json","pnpm-lock.yaml","yarn.lock"]),FX=new Set(["css","less","sass","scss"]);function UX(e){const t=e.split("/").pop()?.toLowerCase()??e.toLowerCase(),s=t.includes(".")?t.split(".").pop()??"":"";return $X.has(t)||t.endsWith(".lock")?"lock":qX(t)?"test":PX.has(t)||zX.has(s)?"config":FX.has(s)?"style":HX.has(s)?"image":IX.has(s)?"document":BX.has(s)?"data":OX.has(s)?"code":"generic"}function qX(e){return e.includes(".test.")||e.includes(".spec.")||e.endsWith("_test.go")}function L1({path:e,className:t}){const s=UX(e),i=GX[s];return n.jsx(i,{"aria-label":`${s} file`,className:se("size-3.5 shrink-0",VX[s],t)})}const GX={code:Oj,config:O0,data:hi,document:T0,generic:Bj,image:m8,lock:M8,style:qj,test:$D},VX={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 WX(e){const t=e.lastIndexOf(".");return t>0?e.slice(t):""}function KX({onPick:e,onClose:t}){const[s,i]=v.useState(""),[a,l]=v.useState(null),[c,u]=v.useState(null),[f,h]=v.useState(!1),p=v.useRef(null),g=X(),b=a?a.parent!==a.path:!1;return v.useEffect(()=>{function x(_){p.current&&!p.current.contains(_.target)&&t()}return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[t]),v.useEffect(()=>{let x=!0;return h(!0),u(null),v3(s,{files:!0}).then(_=>x&&l(_)).catch(_=>x&&u(_ instanceof Error?_.message:String(_))).finally(()=>x&&h(!1)),()=>{x=!1}},[s]),n.jsxs("div",{ref:p,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:[n.jsxs("div",{className:"flex items-center gap-1 border-b border-border px-2 py-1.5",children:[n.jsx(Q,{"aria-label":g("agent.picker.parentFolder"),className:"size-7",disabled:!b,onClick:()=>a&&i(a.parent),size:"icon",type:"button",variant:"ghost",children:n.jsx(nm,{})}),n.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",title:a?.path,children:a?.path??"…"}),f?n.jsx(Bt,{className:"size-3.5 animate-spin text-muted-foreground"}):null,a?n.jsxs(Q,{className:"h-7 px-2 text-[11px]",onClick:()=>e(a.path),size:"sm",title:g("agent.picker.attachFolder"),type:"button",variant:"outline",children:[n.jsx(_D,{})," ",g("agent.picker.thisFolder")]}):null,n.jsx(Q,{"aria-label":g("common.close"),className:"size-7",onClick:t,size:"icon",type:"button",variant:"ghost",children:n.jsx(Gt,{})})]}),n.jsx("div",{className:"max-h-64 overflow-auto p-1",children:c?n.jsx(nt,{variant:"destructive",className:"m-1",children:c}):a&&a.entries.length===0?n.jsx(nt,{variant:"muted",className:"m-1 text-center",children:g("agent.picker.emptyFolder")}):a?.entries.map(x=>{const _=x.isDir?"":WX(x.name);return n.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:()=>x.isDir?i(x.path):e(x.path),title:x.path,type:"button",children:[x.isDir?n.jsx(Io,{className:"size-3.5 shrink-0 text-amber-600"}):n.jsx(L1,{path:x.path}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:x.name}),_?n.jsx("span",{className:"shrink-0 rounded bg-muted px-1 font-mono text-[10px] text-muted-foreground",children:_}):null]},x.path)})})]})}const lN="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 YX(e,t){const s=t?.trim()||e.split(/\r?\n/).find(i=>i.trim())?.trim()||"Agent task";return s.length>60?`${s.slice(0,57).trimEnd()}…`:s}function XX({capabilities:e,onNavigate:t,onShellMode:s,shellMode:i=!1}){const a=X(),{activeSource:l,clearSource:c,configured:u,createShellTask:f,createTask:h,creating:p,draft:g,focusNonce:b,insertPath:x,insertPrompt:_,onboarding:k,provider:C,providers:E,selectProvider:j,setDraft:N,setOnboarding:A}=Vt(),[T,D]=v.useState(!1),[z,O]=v.useState(""),$=v.useRef(null);v.useEffect(()=>{const B=requestAnimationFrame(()=>{const U=$.current;if(!U)return;U.focus();const Y=U.value.length;U.setSelectionRange(Y,Y)});return()=>cancelAnimationFrame(B)},[b]),v.useLayoutEffect(()=>{$.current&&($.current.style.height="auto",$.current.style.height=`${$.current.scrollHeight}px`)},[g]);const M=!!p||(i?!1:!g.trim()||u!==!0);async function I(B=g,U){if(p)return;if(i){if(!await f(B))return;N(""),c(),O("");return}!B.trim()||u!==!0||!await h({prompt:B,label:YX(B,U??l?.label),source:l??void 0})||(N(""),c(),A(!1),O(""))}function G(B){B.key==="Enter"&&!B.shiftKey&&(B.preventDefault(),I())}return n.jsx("div",{className:"flex h-full items-center justify-center overflow-auto p-6",children:n.jsxs("div",{className:"w-full max-w-3xl",children:[!i&&u===null?n.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,!i&&u===!1?n.jsxs("div",{className:"mb-3 border-l-2 border-amber-500/70 pl-3 text-xs text-muted-foreground",children:[n.jsx("span",{className:"font-medium text-foreground",children:a("dock.notInstalled",{name:C?.label??"Agent"})})," ",C?.installHint]}):null,l?n.jsxs("div",{className:"mb-2 flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[n.jsx("span",{className:"font-mono uppercase tracking-wide",children:a("dock.sourceLabel")}),n.jsx("span",{className:"rounded-sm bg-muted px-1.5 py-0.5 text-foreground",children:l.label}),n.jsx("button",{"aria-label":a("dock.clearSourceAria"),onClick:c,type:"button",children:n.jsx(Gt,{className:"size-3"})})]}):null,n.jsxs("div",{className:"border border-border bg-card shadow-sm",children:[k&&!i?n.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2",children:[n.jsx(k8,{className:"size-4 text-muted-foreground"}),n.jsx("input",{"aria-label":a("dock.repoUrlAria"),className:"min-w-0 flex-1 bg-transparent text-sm outline-none",disabled:u!==!0,onChange:B=>O(B.target.value),placeholder:"https://github.com/owner/repository",value:z}),n.jsx(Q,{disabled:u!==!0||!z.trim()||!!p,onClick:()=>{I(Nq(z),`Onboard ${z}`)},size:"sm",children:a("dock.onboard")})]}):null,n.jsx("textarea",{"aria-label":a(i?"dock.shellCommandAria":"dock.promptAria"),className:se("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",i&&"font-mono"),disabled:!i&&u!==!0,onChange:B=>N(B.target.value),onKeyDown:G,placeholder:a(i?"dock.shellPlaceholder":"dock.promptPlaceholder"),ref:$,rows:2,value:g}),n.jsxs("div",{className:"flex h-10 items-center gap-1 border-t border-border px-2",children:[n.jsxs("fieldset",{"aria-label":a("dock.providerAria"),className:"flex shrink-0 items-center gap-0.5",children:[E.map(B=>{const U=B.id==="codex"?kr:Qi,Y=!i&&(C?.id??"claude")===B.id;return n.jsxs("button",{"aria-label":B.label,"aria-pressed":Y,className:se(lN,Y&&"bg-muted text-foreground"),disabled:!B.configured,onClick:()=>{s?.(!1),j(B.id)},title:B.configured?B.label:`${B.label}${a("dock.notInstalledSuffix")} — ${B.installHint}`,type:"button",children:[n.jsx(U,{className:"size-3.5"}),Y?n.jsx("span",{children:B.label}):null]},B.id)}),n.jsxs("button",{"aria-label":a("dock.shell"),"aria-pressed":i,className:se(lN,i&&"bg-muted text-foreground"),onClick:()=>s?.(!0),title:a("dock.shellTitle"),type:"button",children:[n.jsx(wr,{className:"size-3.5"}),i?n.jsx("span",{children:a("dock.shell")}):null]})]}),n.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:()=>D(B=>!B),type:"button",children:n.jsx(fL,{className:"size-3.5"})}),i?null:n.jsx("button",{className:"px-2 text-[11px] text-muted-foreground hover:text-foreground",onClick:()=>A(!k),type:"button",children:a("dock.repoUrlToggle")}),n.jsx("span",{className:"flex-1"}),n.jsx("span",{className:"hidden text-[10px] text-muted-foreground sm:inline",children:a(i?"dock.shellEnterHint":"dock.shiftEnterHint")}),n.jsx(Q,{"aria-label":a(i?"dock.openShellAria":"dock.runAria"),className:"size-7",disabled:M,onClick:()=>{I()},size:"icon",children:n.jsx(tm,{})})]})]}),e?n.jsx(EX,{capabilities:e,onInsert:_,onNavigate:t,providerLabel:C?.label}):null,T?n.jsx("div",{className:"relative mt-2",children:n.jsx(KX,{onClose:()=>D(!1),onPick:B=>{x(B),D(!1)}})}):null]})})}function ZX(e){const t=new Date(e);return Number.isNaN(t.valueOf())?e:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(t)}function QX({error:e,loading:t,onLoad:s,onResume:i,transcripts:a}){const l=X(),[c,u]=v.useState(!1),[f,h]=v.useState(""),[p,g]=v.useState({above:!1,maxHeight:560,offset:36,right:8}),b=v.useRef(null),x=v.useRef(null),_=v.useRef(null),k=v.useMemo(()=>{const N=f.trim().toLocaleLowerCase();return N?a.filter(A=>{const T=A.provider==="codex"?"codex":"claude code";return`${A.title} ${T}`.toLocaleLowerCase().includes(N)}):a},[f,a]),C=v.useCallback(()=>{const N=b.current?.getBoundingClientRect();if(!N)return;const A=4,T=8,D=Math.max(0,N.top-A-T),z=Math.max(0,window.innerHeight-N.bottom-A-T),O=D>z;g({above:O,maxHeight:Math.min(560,O?D:z),offset:O?window.innerHeight-N.top+A:N.bottom+A,right:Math.max(8,window.innerWidth-N.right)})},[]);v.useEffect(()=>{c?(s(),window.requestAnimationFrame(()=>_.current?.focus())):h("")},[c,s]),v.useEffect(()=>{if(c)return C(),window.addEventListener("resize",C),()=>window.removeEventListener("resize",C)},[c,C]),v.useEffect(()=>{if(!c)return;const N=T=>{const D=T.target;!b.current?.contains(D)&&!x.current?.contains(D)&&u(!1)},A=T=>{T.key==="Escape"&&u(!1)};return document.addEventListener("pointerdown",N),window.addEventListener("keydown",A),()=>{document.removeEventListener("pointerdown",N),window.removeEventListener("keydown",A)}},[c]);const E=async N=>{u(!1),await i(N)},j=c?Xn.createPortal(n.jsxs("section",{"aria-label":l("dock.conversations"),className:"fixed z-[100] flex w-[min(28rem,calc(100vw-1rem))] flex-col overflow-hidden rounded-md border border-border bg-popover text-popover-foreground shadow-2xl",ref:x,role:"dialog",style:{maxHeight:p.maxHeight,right:p.right,...p.above?{bottom:p.offset}:{top:p.offset}},children:[n.jsxs("header",{className:"flex h-11 shrink-0 items-center gap-3 border-b border-border bg-muted/35 px-3",children:[n.jsx("div",{className:"grid size-6 place-items-center rounded border border-border bg-background",children:n.jsx(Zh,{className:"size-3 text-primary"})}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("h2",{className:"font-mono text-xs font-semibold uppercase tracking-[0.12em]",children:l("dock.conversations")}),n.jsx("p",{className:"truncate text-[10px] text-muted-foreground",children:l("dock.conversationsScope")})]}),n.jsx("button",{"aria-label":l("dock.refreshConversations"),className:"grid size-7 place-items-center rounded-sm text-muted-foreground hover:bg-background hover:text-foreground disabled:opacity-50",disabled:t,onClick:()=>{s()},type:"button",children:n.jsx(Mi,{className:se("size-3.5",t&&"animate-spin")})})]}),n.jsx("div",{className:"shrink-0 border-b border-border bg-background/70 p-2",children:n.jsxs("div",{className:"flex h-8 items-center gap-2 rounded border border-border bg-background px-2 text-muted-foreground shadow-sm focus-within:border-primary/50 focus-within:text-foreground",children:[n.jsx(Au,{className:"size-3.5 shrink-0"}),n.jsx("input",{"aria-label":l("dock.searchConversations"),className:"min-w-0 flex-1 bg-transparent text-xs text-foreground outline-none placeholder:text-muted-foreground",onInput:N=>h(N.currentTarget.value),placeholder:l("dock.searchConversationsPlaceholder"),ref:_,type:"search",value:f}),f?n.jsx("button",{"aria-label":l("dock.clearConversationSearch"),className:"grid size-5 shrink-0 place-items-center rounded-sm hover:bg-muted",onClick:()=>{h(""),_.current?.focus()},type:"button",children:n.jsx(Gt,{className:"size-3"})}):null]})}),n.jsx("section",{"aria-label":l("dock.conversationResults"),className:"min-h-0 flex-1 overflow-y-auto overscroll-contain p-1.5 [scrollbar-gutter:stable]","data-conversation-scroll":!0,children:t&&a.length===0?n.jsxs("div",{className:"flex h-28 items-center justify-center gap-2 text-xs text-muted-foreground",children:[n.jsx(Bt,{className:"size-4 animate-spin"}),l("dock.loadingConversations")]}):e?n.jsx("div",{className:"m-1 rounded border border-destructive/30 bg-destructive/5 px-3 py-4 text-xs text-destructive",children:e}):a.length===0?n.jsxs("div",{className:"px-4 py-8 text-center",children:[n.jsx(Zh,{className:"mx-auto mb-2 size-5 text-muted-foreground/50"}),n.jsx("p",{className:"text-xs font-medium",children:l("dock.noConversations")}),n.jsx("p",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:l("dock.noConversationsHint")})]}):k.length===0?n.jsxs("div",{className:"px-4 py-8 text-center",children:[n.jsx(Au,{className:"mx-auto mb-2 size-5 text-muted-foreground/50"}),n.jsx("p",{className:"text-xs font-medium",children:l("dock.noMatchingConversations")}),n.jsx("p",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:l("dock.noMatchingConversationsHint")})]}):k.map(N=>{const A=N.provider==="codex"?kr:Qi;return n.jsxs("button",{className:"group flex w-full items-start gap-3 rounded px-2.5 py-2.5 text-left hover:bg-muted/70 focus-visible:bg-muted focus-visible:outline-none",onClick:()=>{E(N)},type:"button",children:[n.jsx("span",{className:"mt-0.5 grid size-7 shrink-0 place-items-center rounded border border-border bg-background group-hover:border-primary/40",children:n.jsx(A,{className:"size-3.5 text-muted-foreground group-hover:text-foreground"})}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"line-clamp-2 text-xs font-medium leading-4",children:N.title}),n.jsxs("span",{className:"mt-1 flex items-center gap-2 font-mono text-[10px] text-muted-foreground",children:[n.jsx("span",{className:"uppercase tracking-wide",children:N.provider==="codex"?"Codex":"Claude"}),n.jsx("span",{"aria-hidden":!0,children:"·"}),n.jsx("time",{dateTime:N.updatedAt,children:ZX(N.updatedAt)})]})]}),n.jsx("span",{className:"mt-1 translate-x-1 font-mono text-[10px] text-primary opacity-0 transition-all group-hover:translate-x-0 group-hover:opacity-100",children:l("dock.resume")})]},`${N.provider}:${N.id}`)})})]}),document.body):null;return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"relative",ref:b,children:n.jsx("button",{"aria-expanded":c,"aria-haspopup":"dialog","aria-label":l("dock.conversationsAria"),className:se("grid size-7 place-items-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground",c&&"bg-muted text-foreground"),onClick:()=>{c||C(),u(N=>!N)},title:l("dock.conversations"),type:"button",children:n.jsx(Zh,{className:"size-3.5"})})}),j]})}function JX({creating:e,direction:t="up",onCreateAgent:s,onCreateShell:i,providers:a}){const l=X(),[c,u]=v.useState(!1),[f,h]=v.useState({bottom:36,right:8}),p=v.useRef(null),g=v.useRef(null);function b(){const x=p.current?.getBoundingClientRect();x&&h(t==="down"?{top:x.bottom+4,right:Math.max(8,window.innerWidth-x.right)}:{bottom:window.innerHeight-x.top+4,right:Math.max(8,window.innerWidth-x.right)}),u(_=>!_)}return v.useEffect(()=>{if(!c)return;const x=k=>{const C=k.target;!p.current?.contains(C)&&!g.current?.contains(C)&&u(!1)},_=k=>{k.key==="Escape"&&u(!1)};return document.addEventListener("pointerdown",x),window.addEventListener("keydown",_),()=>{document.removeEventListener("pointerdown",x),window.removeEventListener("keydown",_)}},[c]),n.jsxs("div",{className:"relative",ref:p,children:[n.jsx("button",{"aria-expanded":c,"aria-haspopup":"menu","aria-label":l("dock.newSessionMenu"),className:se("grid size-7 place-items-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground",c&&"bg-muted text-foreground"),onClick:b,type:"button",children:n.jsx(Es,{className:"size-3.5"})}),c?Xn.createPortal(n.jsxs("div",{"aria-label":l("dock.newSessionMenu"),className:"fixed z-[100] w-52 overflow-hidden rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-xl",ref:g,role:"menu",style:f,children:[a.map(x=>{const _=x.id==="codex"?kr:Qi;return n.jsxs("button",{"aria-label":x.label,className:"flex w-full items-center gap-2 rounded-sm px-2 py-2 text-left text-xs transition-colors hover:bg-muted disabled:cursor-not-allowed disabled:opacity-45",disabled:e||!x.configured,onClick:()=>{u(!1),s(x)},role:"menuitem",title:x.configured?x.label:`${x.label}${l("dock.notInstalledSuffix")}`,type:"button",children:[n.jsx(_,{className:"size-3.5 shrink-0"}),n.jsx("span",{className:"min-w-0 flex-1 truncate font-medium",children:x.label}),x.configured?null:n.jsx("span",{className:"text-[10px] text-muted-foreground",children:l("dock.notInstalledShort")})]},x.id)}),n.jsx("div",{className:"my-1 h-px bg-border"}),n.jsxs("button",{"aria-label":l("dock.shell"),className:"flex w-full items-center gap-2 rounded-sm px-2 py-2 text-left text-xs transition-colors hover:bg-muted disabled:cursor-not-allowed disabled:opacity-45",disabled:e,onClick:()=>{u(!1),i()},role:"menuitem",type:"button",children:[n.jsx(wr,{className:"size-3.5 shrink-0"}),n.jsx("span",{className:"font-medium",children:l("dock.shell")})]})]}),document.body):null]})}const Wn="new";function cN(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 zb({tasks:e,activeTaskId:t,ariaLabel:s,composing:i,onActivate:a,onClose:l,onDragEnd:c,onDragStart:u,onRename:f,pendingTaskIds:h}){const p=X(),[g,b]=v.useState(null),[x,_]=v.useState(""),k=v.useRef(null),C=v.useRef(null);v.useEffect(()=>{if(g){k.current?.focus(),k.current?.select();return}const D=C.current;C.current=null,D&&document.getElementById(`agent-tab-${D}`)?.focus()},[g]);const E=(D,z)=>{!f||h?.has(D.id)||(b(D.id),_(z))},j=D=>{C.current=D,b(null)},N=(D,z)=>{const O=x.trim();C.current=D.id,b(null),O&&O!==z&&f?.(D.id,O)},A=[...e.map(D=>D.id),...i?[Wn]:[]],T=(D,z)=>{const O=A.indexOf(z);let $=O;if(D.key==="ArrowLeft")$=Math.max(0,O-1);else if(D.key==="ArrowRight")$=Math.min(A.length-1,O+1);else if(D.key==="Home")$=0;else if(D.key==="End")$=A.length-1;else return;D.preventDefault();const M=A[$];M&&(a(M),window.setTimeout(()=>document.getElementById(`agent-tab-${M}`)?.focus(),0))};return n.jsxs("div",{"aria-label":s??p("dock.tasksAria"),className:"flex min-w-0 flex-1 items-stretch gap-px overflow-x-auto",role:"tablist",children:[e.map(D=>{const z=D.kind==="shell",O=D.label||(z?p("dock.shellFallback"):p("dock.taskFallback",{provider:D.provider==="codex"?"Codex":"Claude"})),$=D.id===t,M=g===D.id,I=!!u&&!M,G=z?wr:D.provider==="codex"?kr:Qi;return n.jsxs("div",{className:se("group/tab flex h-9 shrink-0 items-center border-x border-transparent",$&&"border-border bg-background"),children:[M?n.jsxs("div",{className:"flex h-full max-w-56 items-center gap-2 px-3 text-xs",children:[n.jsx("button",{"aria-controls":`agent-panel-${D.id}`,"aria-label":p("dock.openTaskAria",{label:O}),"aria-selected":$,className:"sr-only",id:`agent-tab-${D.id}`,role:"tab",tabIndex:-1,type:"button",children:O}),n.jsx(G,{className:"size-3 shrink-0 text-foreground"}),n.jsx(Lo,{"aria-hidden":!0,className:se("size-2",cN(D.state))}),n.jsx("input",{"aria-label":p("dock.renameTaskAria",{label:O}),className:"h-6 min-w-24 max-w-40 rounded-sm border border-primary/50 bg-background px-1.5 font-mono text-[11px] text-foreground outline-none ring-1 ring-primary/20",maxLength:60,onBlur:()=>N(D,O),onInput:B=>_(B.currentTarget.value),onKeyDown:B=>{B.key==="Escape"?(B.preventDefault(),j(D.id)):B.key==="Enter"&&!B.nativeEvent.isComposing&&(B.preventDefault(),B.currentTarget.blur())},onPointerDown:B=>B.stopPropagation(),ref:k,value:x})]}):n.jsxs("button",{"aria-controls":`agent-panel-${D.id}`,"aria-keyshortcuts":f?"F2":void 0,"aria-label":p("dock.openTaskAria",{label:O}),"aria-selected":$,className:se("flex h-full max-w-56 items-center gap-2 px-3 text-xs",I&&"cursor-grab active:cursor-grabbing"),draggable:I,id:`agent-tab-${D.id}`,onClick:()=>a(D.id),onDoubleClick:()=>E(D,O),onDragEnd:c,onDragStart:B=>{B.dataTransfer&&(B.dataTransfer.effectAllowed="move",B.dataTransfer.setData("text/plain",D.id)),u?.(D.id)},onKeyDown:B=>{B.key==="F2"?(B.preventDefault(),E(D,O)):T(B,D.id)},role:"tab",tabIndex:$?0:-1,title:f?p("dock.renameTaskHint"):I?p("dock.dragTaskToSplit"):void 0,type:"button",children:[n.jsx(G,{className:se("size-3 shrink-0",$?"text-foreground":"text-muted-foreground")}),n.jsx(Lo,{"aria-hidden":!0,className:se("size-2",cN(D.state))}),n.jsx("span",{className:se("truncate font-mono text-[11px]",$?"text-foreground":"text-muted-foreground"),children:O})]}),n.jsx("button",{"aria-label":p("dock.closeTaskAria",{label:O}),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:M||h?.has(D.id),onClick:()=>l(D.id),type:"button",children:n.jsx(Gt,{className:"size-3"})})]},D.id)}),i?n.jsx("div",{className:"flex h-9 shrink-0 items-center border-x border-border bg-background",children:n.jsxs("button",{"aria-controls":`agent-panel-${Wn}`,"aria-selected":!0,className:"flex h-full items-center gap-2 px-3 text-xs",id:`agent-tab-${Wn}`,onClick:()=>a(Wn),onKeyDown:D=>T(D,Wn),role:"tab",type:"button",children:[n.jsx(Es,{"aria-hidden":!0,className:"size-3 shrink-0 text-foreground"}),n.jsx("span",{className:"truncate font-mono text-[11px] text-foreground",children:p("dock.newTaskTab")})]})}):null]})}const eZ=5,h0=new Map,Bb=new Map,f0=[];let m0=0;function uN(){for(;m0<eZ&&f0.length>0;){const e=f0.shift();e&&(m0++,e())}}function tZ(e){return h0.get(e)}function ZT(e){const t=h0.get(e);if(t)return Promise.resolve(t);const s=Bb.get(e);if(s)return s;const i=new Promise((a,l)=>{f0.push(()=>{M9(e).then(c=>{c.state!=="pending"&&h0.set(e,c),a(c)}).catch(l).finally(()=>{m0--,Bb.delete(e),uN()})})});return Bb.set(e,i),uN(),i}function sZ(e,t){const{claude:s,codex:i}=e??{},a=i?{fiveHour:i.primary,weekly:i.secondary,contextPercent:i.contextWindow&&i.contextWindow>0?Math.min(100,i.lastTotalTokens/i.contextWindow*100):null,costUSD:null}:null,l=s?{fiveHour:s.fiveHour,weekly:s.weekly,contextPercent:null,costUSD:s.costUSD}:null;return t==="codex"&&a?a:l??a??null}function nZ(e){const t=e?.selectedRepository?.name??null,s=e?.status?.branch??null,i=e?.status?.ahead??0,[a,l]=v.useState(null),[c,u]=v.useState(null);return v.useEffect(()=>{if(!t){l(null);return}let f=!0;return c3(1).then(h=>{f&&l(h[0]?.hash??null)}).catch(()=>{f&&l(null)}),()=>{f=!1}},[t,s,i]),v.useEffect(()=>{if(!a){u(null);return}let f=!0;const h=()=>ZT(a).then(g=>{f&&u(g)}).catch(()=>{f&&u(null)});h();const p=window.setInterval(h,3e4);return()=>{f=!1,window.clearInterval(p)}},[a]),c}function iZ(e){return e>=90?"bg-red-500":e>=70?"bg-amber-500":"bg-emerald-500"}function rZ(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"}}function aZ(e,t,s){const i=e("dock.status.limitTitle",{label:t,pct:s.usedPercent.toFixed(0)});if(!s.resetsAtUnix)return i;const a=new Date(s.resetsAtUnix*1e3).toLocaleString();return`${i}${e("dock.status.resetsSuffix",{time:a})}`}function dN({label:e,window:t,className:s}){const i=X(),a=Math.min(100,Math.max(0,t.usedPercent));return n.jsxs("span",{className:se("flex items-center gap-1 font-mono text-[10px] text-muted-foreground",s),title:aZ(i,e,t),children:[n.jsx("span",{children:e}),n.jsx("span",{className:"h-1.5 w-7 overflow-hidden rounded-full bg-muted",children:n.jsx("span",{className:se("block h-full",iZ(a)),style:{width:`${a.toFixed(0)}%`}})}),n.jsxs("span",{className:"tabular-nums text-foreground",children:[a.toFixed(0),"%"]})]})}function Ih({title:e,className:t,children:s}){return n.jsx("span",{className:se("flex items-center gap-1 font-mono text-[10px] text-muted-foreground",t),title:e,children:s})}function hN(){return n.jsx("span",{"aria-hidden":!0,className:"h-3 w-px shrink-0 bg-border"})}function Ib({git:e,provider:t,variant:s="strip"}){const i=X(),{usage:a}=OA(15e3),l=nZ(e),c=sZ(a,t),u=e?.status??null,f=u?.upstream??i("dock.status.noUpstream"),h=l&&l.state!=="unknown"&&l.totalCount>0,p=s==="strip"&&!!u?.branch,g=s==="strip"&&(c?.contextPercent!=null||c?.costUSD!=null),b=[];return p&&u&&b.push(n.jsxs(Ih,{className:"hidden max-w-[9rem] md:flex",title:i("dock.status.branchTitle",{branch:u.branch,upstream:f}),children:[n.jsx(Mn,{className:"size-3 shrink-0"}),n.jsx("span",{className:"truncate text-foreground",children:u.branch}),u.ahead>0?n.jsxs("span",{className:"text-emerald-600",children:["↑",u.ahead]}):null,u.behind>0?n.jsxs("span",{className:"text-amber-600",children:["↓",u.behind]}):null]},"branch")),h&&l&&b.push(n.jsxs(Ih,{className:"hidden sm:flex",title:i("dock.status.ciTitle",{state:l.state,count:l.totalCount}),children:[n.jsx("span",{className:se("size-2 shrink-0 rounded-full",rZ(l.state))}),n.jsx("span",{children:i("dock.status.ci")})]},"ci")),c?.fiveHour&&b.push(n.jsx(dN,{label:i("dock.status.fiveHour"),window:c.fiveHour},"5h")),c?.weekly&&b.push(n.jsx(dN,{className:"hidden sm:flex",label:i("dock.status.weekly"),window:c.weekly},"wk")),g&&c&&(c.contextPercent!=null?b.push(n.jsxs(Ih,{className:"hidden lg:flex",title:i("dock.status.contextTitle",{pct:c.contextPercent.toFixed(0)}),children:[n.jsx("span",{children:i("dock.status.context")}),n.jsxs("span",{className:"tabular-nums text-foreground",children:[c.contextPercent.toFixed(0),"%"]})]},"ctx")):c.costUSD!=null&&b.push(n.jsx(Ih,{className:"hidden lg:flex",title:i("dock.status.costTitle",{cost:c.costUSD.toFixed(4)}),children:n.jsxs("span",{className:"tabular-nums text-emerald-700 dark:text-emerald-500",children:["$",c.costUSD.toFixed(2)]})},"cost"))),b.length===0?null:n.jsxs("span",{className:se("flex shrink-0 items-center gap-2",s==="dock"&&"hidden border-l border-border px-2 lg:flex",s==="side"&&"min-w-max px-2"),children:[s==="strip"?n.jsx(hN,{}):null,b.map((x,_)=>n.jsxs("span",{className:"flex items-center gap-2",children:[_>0?n.jsx(hN,{}):null,x]},_))]})}function Rm({className:e}){return n.jsx("svg",{className:se("size-3.5",e),viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:n.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"})})}function oZ(e,t,s){const i=t/100,a=s/100,l=(1-Math.abs(2*a-1))*i,c=e/60,u=l*(1-Math.abs(c%2-1));let f=0,h=0,p=0;c>=0&&c<1?[f,h,p]=[l,u,0]:c<2?[f,h,p]=[u,l,0]:c<3?[f,h,p]=[0,l,u]:c<4?[f,h,p]=[0,u,l]:c<5?[f,h,p]=[u,0,l]:[f,h,p]=[l,0,u];const g=a-l/2;return[f+g,h+g,p+g]}function lZ(e,t,s){const[i,a,l]=oZ(e,t,s).map(c=>c<=.03928?c/12.92:((c+.055)/1.055)**2.4);return .2126*i+.7152*a+.0722*l}function Hh(e,t,s){const i=lZ(e,t,s),a=1.05/(i+.05),l=(i+.05)/.05;return a>=l?"0 0% 100%":"0 0% 12%"}function _o(e,t=62){const s=(e%360+360)%360,i=t;return{light:{primary:`${s} ${i}% 43%`,primaryForeground:Hh(s,i,43),accent:`${s} ${i}% 41%`,accentForeground:Hh(s,i,41),ring:`${s} ${i}% 45%`},dark:{primary:`${s} ${i}% 60%`,primaryForeground:Hh(s,i,60),accent:`${s} ${i}% 58%`,accentForeground:Hh(s,i,58),ring:`${s} ${i}% 58%`}}}const cZ={light:{primary:"24 9% 10%",primaryForeground:"0 0% 98%",accent:"170 34% 39%",accentForeground:"0 0% 100%",ring:"170 34% 39%"},dark:{primary:"0 0% 95%",primaryForeground:"24 10% 10%",accent:"170 34% 45%",accentForeground:"24 10% 10%",ring:"170 34% 45%"}},QT=[{id:"classic",labelKey:"settingsHub.accent.classic",swatch:"hsl(24 9% 20%)",theme:cZ},{id:"emerald",labelKey:"settingsHub.accent.emerald",swatch:"hsl(160 62% 43%)",theme:_o(160)},{id:"ocean",labelKey:"settingsHub.accent.ocean",swatch:"hsl(205 62% 43%)",theme:_o(205)},{id:"indigo",labelKey:"settingsHub.accent.indigo",swatch:"hsl(245 62% 47%)",theme:_o(245,58)},{id:"violet",labelKey:"settingsHub.accent.violet",swatch:"hsl(272 62% 47%)",theme:_o(272)},{id:"rose",labelKey:"settingsHub.accent.rose",swatch:"hsl(340 62% 47%)",theme:_o(340)},{id:"amber",labelKey:"settingsHub.accent.amber",swatch:"hsl(35 80% 50%)",theme:_o(35,80)}],Vf=new Map(QT.map(e=>[e.id,e])),Mm="classic",JT=/^custom:(\d{1,3})$/;function Bu(e){if(typeof e!="string")return!1;if(Vf.has(e))return!0;const t=JT.exec(e);return t?Number(t[1])>=0&&Number(t[1])<=359:!1}function O1(e){const t=JT.exec(e);return t?Number(t[1]):null}function uZ(e){const t=O1(e);return t!==null?`hsl(${t} 62% 47%)`:Vf.get(e)?.swatch??"hsl(24 9% 20%)"}function dZ(e){const t=O1(e);return t!==null?_o(t):(Vf.get(e)??Vf.get("classic")).theme}const fN="nomoreide-accent";function mN(e){return`--primary:${e.primary};--primary-foreground:${e.primaryForeground};--accent:${e.accent};--accent-foreground:${e.accentForeground};--ring:${e.ring};`}function eR(e){if(typeof document>"u")return;const t=dZ(Bu(e)?e:Mm);let s=document.getElementById(fN);s||(s=document.createElement("style"),s.id=fN,document.head.appendChild(s)),s.textContent=`:root{${mN(t.light)}}
|
|
118
118
|
.dark{${mN(t.dark)}}`}function hZ(e,t,s){return s&&Bu(t[s])?t[s]:Bu(e)?e:Mm}const tR="nomoreide:ui-preferences";function fZ(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}function sR(){return{version:2,theme:"system",language:"en",density:"comfortable",codeFontSize:12,reducedMotion:fZ(),sidebarDocked:!1,agentDockPlacement:"bottom",projectScope:"all",accent:Mm,projectAccents:{}}}function mZ(e){if(!e||typeof e!="object"||Array.isArray(e))return{};const t={};for(const[s,i]of Object.entries(e))s&&Bu(i)&&(t[s]=i);return t}function pZ(){if(typeof window>"u")return{};const e=Rl("nomoreide-theme-choice"),t=Rl("nomoreide-language")??Rl("nomoreide-language-choice"),s=Rl("nomoreide:sidebar-docked"),i=Rl("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"}:{},...i==="all"||i==="project"?{projectScope:i}:{}}}function Rl(e){try{return window.localStorage.getItem(e)}catch{return null}}function Dm(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e;return t.version!==1&&t.version!==2||!["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,version:2,agentDockPlacement:t.agentDockPlacement==="right"?"right":"bottom",accent:Bu(t.accent)?t.accent:Mm,projectAccents:mZ(t.projectAccents)}}function gZ(e,t){return Dm({...e,...t})}function ku(e){const t=Dm(e);if(!t)return!1;try{return window.localStorage.setItem(tR,JSON.stringify(t)),!0}catch{return!1}}function bZ(){let e=null;try{const s=Rl(tR);e=s?Dm(JSON.parse(s)):null}catch{e=null}const t=e??{...sR(),...pZ()};return ku(t),t}function vZ(){const e=sR();return ku(e),e}function pN(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`),eR(e.accent)}const gN={version:1,terminal:{fontSize:13,cursorStyle:"block",scrollback:5e3,copyOnSelect:!1,confirmTerminate:!0}},$h={logs:{showTimestamps:!0,wrapLines:!0},database:{confirmWrites:!0,resultLimit:100}},nR=v.createContext(null);function Ma(e){return e instanceof Error?e.message:String(e)}function xZ(e,t){return{...e,terminal:{...e.terminal,...t.terminal}}}function yZ(e,t){return{...e,logs:{...e.logs,...t.logs},database:{...e.database,...t.database}}}function _Z({children:e}){const[t,s]=v.useState(gN),[i,a]=v.useState(gN),[l,c]=v.useState($h),[u,f]=v.useState($h),[h,p]=v.useState(()=>bZ()),[g,b]=v.useState(!0),[x,_]=v.useState(null),[k,C]=v.useState(!1),[E,j]=v.useState(null),[N,A]=v.useState(null),[T,D]=v.useState("idle"),[z,O]=v.useState(null),[$]=GT(),[M]=jA(),I=v.useRef(!0),G=v.useRef(!1),B=v.useRef(0),U=v.useRef(0),Y=v.useRef(0),P=v.useRef(0),V=v.useRef(Promise.resolve()),W=v.useRef(Promise.resolve()),re=v.useRef(t),ce=v.useRef(l),F=v.useRef(null),K=v.useRef(null),ue=v.useRef(h),ge=v.useRef(i),J=v.useRef(u),ne=v.useRef(null),Le=v.useRef(0),ve=v.useRef(null),Se=v.useRef(null),Ve=v.useRef(!1),rt=v.useRef(null),Re=v.useRef(h.language),ie=v.useCallback(()=>{ne.current!==null&&(window.clearTimeout(ne.current),ne.current=null)},[]),Be=v.useCallback(()=>{ie(),D("saved"),ne.current=window.setTimeout(()=>{I.current&&D("idle")},1500)},[ie]),We=v.useCallback(()=>{ie(),Le.current===0&&(ve.current=null,O(null)),Le.current+=1,D("saving")},[ie]),He=v.useCallback(ot=>{if(ot&&!ve.current&&(ve.current=ot),Le.current=Math.max(0,Le.current-1),Le.current>0){D("saving"),ve.current&&O(ve.current);return}if(ve.current){O(ve.current),D("error");return}Be()},[Be]),at=v.useCallback(ot=>{if(F.current===ot)return K.current??Promise.resolve();const S=++U.current;if(++P.current,F.current=ot,_(ot),A(null),ce.current=structuredClone($h),J.current=structuredClone($h),c(ce.current),f(J.current),ot===null)return C(!1),K.current=null,Promise.resolve();C(!0);const me=W.current.then(()=>tb(ot)).then(de=>{!I.current||S!==U.current||F.current!==ot||(ce.current=de.project,J.current=de.project,c(de.project),f(de.project))}).catch(de=>{I.current&&S===U.current&&F.current===ot&&A(`Could not load project settings: ${Ma(de)}`)}).finally(()=>{I.current&&S===U.current&&F.current===ot&&(C(!1),K.current=null)});return K.current=me,me},[]),mt=v.useCallback(async()=>{const ot=F.current;if(!ot)return;const S=++U.current;++P.current;const te=W.current;C(!0),A(null);const me=te.then(()=>tb(ot)).then(de=>{!I.current||S!==U.current||F.current!==ot||(ce.current=de.project,J.current=de.project,c(de.project),f(de.project))}).catch(de=>{I.current&&S===U.current&&F.current===ot&&A(`Could not load project settings: ${Ma(de)}`)}).finally(()=>{I.current&&S===U.current&&F.current===ot&&(C(!1),K.current=null)});return K.current=me,me},[]),ht=v.useCallback(async()=>{const ot=++B.current,S=F.current,te=S?++U.current:U.current,me=Y.current,de=P.current,be=V.current,De=W.current;b(!0),S&&C(!0),j(null),S&&A(null);try{await Promise.all([be,De]);const L=await tb(S??void 0);if(!I.current||ot!==B.current)return;me===Y.current&&(re.current=L.global,ge.current=L.global,s(L.global),a(L.global)),de===P.current&&S===F.current&&te===U.current&&(ce.current=L.project,J.current=L.project,c(L.project),f(L.project))}catch(L){const oe=S===null||S===F.current&&te===U.current;I.current&&ot===B.current&&oe&&(S?A(`Could not load project settings: ${Ma(L)}`):j(Ma(L)))}finally{I.current&&ot===B.current&&(b(!1),S===F.current&&C(!1))}},[]);v.useEffect(()=>(I.current=!0,G.current||(G.current=!0,ht()),Se.current=window.setTimeout(()=>{Ve.current=!0},0),()=>{I.current=!1,ie(),Se.current!==null&&(window.clearTimeout(Se.current),Se.current=null)}),[ie,ht]);const xt=v.useCallback(ot=>{const S=Dm(ot);return S?(ku(S),ue.current=S,pN(S),p(S),rt.current=S.theme,d0(S.theme),Re.current=S.language,Cx(S.language),!0):!1},[]);v.useEffect(()=>{pN(h),rt.current=h.theme,d0(h.theme),Re.current=h.language,Cx(h.language)},[]),v.useEffect(()=>{eR(hZ(h.accent,h.projectAccents,x))},[h.accent,h.projectAccents,x]),v.useEffect(()=>{if(Ve.current&&rt.current!==null&&$!==rt.current){const ot={...h,theme:$};ue.current=ot,ku(ot),p(ot),rt.current=$}},[$,h]),v.useEffect(()=>{if(Ve.current&&M!==Re.current){const ot={...h,language:M};ue.current=ot,ku(ot),p(ot),Re.current=M}},[M,h]);const is=v.useCallback(ot=>{const S=gZ(ue.current,ot);return S?xt(S):!1},[xt]),Qs=v.useCallback(()=>{xt(vZ())},[xt]),us=v.useCallback(async ot=>{const S=++Y.current,te=xZ(re.current,ot);re.current=te,s(te),We();const me=V.current.then(()=>uz(ot));V.current=me.then(()=>{},()=>{});try{const de=await me;if(!I.current)return;ge.current=de,a(de),S===Y.current&&(re.current=de,s(de)),He()}catch(de){if(!I.current)return;S===Y.current&&(re.current=ge.current,s(ge.current)),He(`Could not save global settings: ${Ma(de)}`)}},[We,He]),It=v.useCallback(async ot=>{const S=F.current;if(!S){O("Select a project before changing project settings."),D("error");return}const te=++P.current,me=yZ(ce.current,ot);ce.current=me,c(me),We();const de=W.current.then(()=>dz(S,ot));W.current=de.then(()=>{},()=>{});try{const be=await de;if(!I.current)return;S===F.current&&(J.current=be,f(be),te===P.current&&(ce.current=be,c(be))),He()}catch(be){if(!I.current)return;S===F.current&&te===P.current&&(ce.current=J.current,c(J.current)),He(`Could not save project settings: ${Ma(be)}`)}},[We,He]),Ts=v.useCallback(async()=>{const ot=++Y.current;We();const S=V.current.then(hz);V.current=S.then(()=>{},()=>{});try{const te=await S;if(!I.current)return;ge.current=te,a(te),ot===Y.current&&(re.current=te,s(te)),He()}catch(te){if(!I.current)return;He(`Could not reset global settings: ${Ma(te)}`)}},[We,He]),Wt=v.useCallback(async()=>{const ot=F.current;if(!ot){O("Select a project before resetting project settings."),D("error");return}const S=++P.current;We();const te=W.current.then(()=>fz(ot));W.current=te.then(()=>{},()=>{});try{const me=await te;if(!I.current)return;ot===F.current&&(J.current=me,f(me),S===P.current&&(ce.current=me,c(me))),He()}catch(me){if(!I.current)return;He(`Could not reset project settings: ${Ma(me)}`)}},[We,He]);return n.jsx(nR.Provider,{value:{loading:g,loadError:E,retry:ht,activeProjectPath:x,projectLoading:k,projectLoadError:N,selectProject:at,retryProject:mt,saveState:T,saveError:z,global:t,confirmedGlobal:i,project:l,confirmedProject:u,ui:h,updateGlobal:us,updateProject:It,updateUi:is,resetGlobal:Ts,resetProject:Wt,resetUi:Qs},children:e})}function Lm(){const e=Om();if(!e)throw new Error("useSettings must be used within SettingsProvider");return e}function Om(){return v.useContext(nR)}const wZ=[{page:"services",labelKey:"nav.services",icon:n.jsx(hm,{})},{page:"docker",labelKey:"nav.docker",icon:n.jsx(am,{})},{page:"git",labelKey:"nav.git",icon:n.jsx(Mn,{})},{page:"github",labelKey:"nav.github",icon:n.jsx(Rm,{})},{page:"workflows",labelKey:"nav.workflows",icon:n.jsx(yf,{})},{page:"errors",labelKey:"nav.errors",icon:n.jsx($u,{})},{page:"database",labelKey:"nav.database",icon:n.jsx(hi,{})},{page:"terminal",labelKey:"nav.terminal",icon:n.jsx(wr,{})},{page:"agent",labelKey:"nav.agent",icon:n.jsx(sm,{})},{page:"agent-env",labelKey:"nav.agentEnv",icon:n.jsx(Fu,{})}];function SZ(e,t){const s=Math.max(0,t-48),i=Math.min(180,s);return Math.max(i,Math.min(s,e))}function kZ(e,t){const s=Math.max(0,t-320),i=Math.min(340,s);return Math.max(i,Math.min(s,e))}function bN(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}function CZ({currentPage:e="services",git:t,onGitRefresh:s,onInsetChange:i,onNavigate:a}){const l=X(),c=Om(),{activeTaskId:u,claimInitialInput:f,closeTask:h,createShellTask:p,createTask:g,creating:b,draft:x,focusNonce:_,insertPrompt:k,loadTranscripts:C,onboarding:E,open:j,pendingTaskIds:N,provider:A,providers:T,renameTask:D,resumeTask:z,setActiveTaskId:O,setOpen:$,stopTask:M,tasks:I,terminalError:G,transcripts:B,transcriptsError:U,transcriptsLoading:Y,updateTaskStatus:P}=Vt(),[V,W]=v.useState(null),[re,ce]=v.useState(480),[F,K]=v.useState(!1),[ue,ge]=v.useState(()=>typeof window.matchMedia!="function"||window.matchMedia("(min-width: 700px)").matches),[J,ne]=v.useState(!1),[Le,ve]=v.useState(null),[Se,Ve]=v.useState(!1),[rt,Re]=v.useState(()=>new Set),[ie,Be]=v.useState(null),[We,He]=v.useState("left"),[at,mt]=v.useState(50),[ht,xt]=v.useState(null),[is,Qs]=v.useState(!1),us=v.useRef(null),It=v.useRef(null),Ts=v.useRef(!1),Wt=v.useRef(null),ot=v.useRef(null),S=v.useRef(new Map),te=v.useRef(_),me=v.useRef(E),de=v.useRef(0),De=(c?.ui.agentDockPlacement??"bottom")==="right"&&ue?"right":"bottom",L=De==="right"&&!Se;v.useEffect(()=>{(x||E)&&(Qs(!1),de.current+=1,He("left"),O(Wn))},[]),v.useEffect(()=>{_!==te.current&&(Qs(!1),de.current+=1,He("left"),O(Wn)),te.current=_},[_,O]),v.useEffect(()=>{E&&!me.current&&(Qs(!1),de.current+=1,He("left"),O(Wn)),me.current=E},[E,O]),v.useEffect(()=>()=>{us.current?.(),It.current?.(),Wt.current?.()},[]),v.useEffect(()=>{if(typeof window.matchMedia!="function")return;const _e=window.matchMedia("(min-width: 700px)"),tt=()=>ge(_e.matches);return tt(),_e.addEventListener?.("change",tt),()=>_e.removeEventListener?.("change",tt)},[]),v.useEffect(()=>{i?.(De,Se?0:De==="right"&&j?re:36)},[Se,i,j,De,re]),v.useEffect(()=>{if(!Se)return;const _e=tt=>{tt.key==="Escape"&&Ve(!1)};return window.addEventListener("keydown",_e),()=>window.removeEventListener("keydown",_e)},[Se]),v.useEffect(()=>{j||Ve(!1)},[j]),v.useEffect(()=>{const _e=new Set(I.map(tt=>tt.id));Re(tt=>{const _t=new Set([...tt].filter(ft=>_e.has(ft)));return _t.size===tt.size&&[..._t].every(ft=>tt.has(ft))?tt:_t})},[I]);const oe=()=>{Ve(!1),$(!1)},Ee=_e=>{a?.(_e),oe()};function Ce(_e){_e.preventDefault(),_e.currentTarget.setPointerCapture?.(_e.pointerId),K(!0);const tt=Ht=>{L?ce(kZ(window.innerWidth-Ht.clientX,window.innerWidth)):W(SZ(window.innerHeight-Ht.clientY,window.innerHeight))},_t=()=>{window.removeEventListener("pointermove",tt),window.removeEventListener("pointerup",ft),us.current=null},ft=()=>{K(!1),_t()};us.current?.(),us.current=_t,window.addEventListener("pointermove",tt),window.addEventListener("pointerup",ft)}function Ne(_e){c?.updateUi({agentDockPlacement:_e})}function Oe(_e){_e.preventDefault(),_e.currentTarget.setPointerCapture?.(_e.pointerId);const tt={x:_e.clientX,y:_e.clientY};let _t=!1;ne(!0),ve(De);const ft=ze=>ue&&ze.clientX>=window.innerWidth*.72?"right":"bottom",Ht=ze=>{Math.hypot(ze.clientX-tt.x,ze.clientY-tt.y)>5&&(_t=!0),ve(ft(ze))},os=()=>{window.removeEventListener("pointermove",Ht),window.removeEventListener("pointerup",Pn),It.current=null},Pn=ze=>{_t&&(Ts.current=!0,window.setTimeout(()=>{Ts.current=!1},0)),Ne(ft(ze)),ne(!1),ve(null),os()};It.current?.(),It.current=os,window.addEventListener("pointermove",Ht),window.addEventListener("pointerup",Pn)}function ye(_e){_e.preventDefault(),_e.currentTarget.setPointerCapture?.(_e.pointerId);const tt=Ht=>{const os=ot.current?.getBoundingClientRect();if(!os?.width)return;const Pn=(Ht.clientX-os.left)/os.width*100;mt(Math.max(25,Math.min(75,Pn)))},_t=()=>{window.removeEventListener("pointermove",tt),window.removeEventListener("pointerup",ft),Wt.current=null},ft=()=>_t();Wt.current?.(),Wt.current=_t,window.addEventListener("pointermove",tt),window.addEventListener("pointerup",ft)}const $e=u===Wn||I.length===0,Ie=I.filter(_e=>rt.has(_e.id)),qe=I.filter(_e=>!rt.has(_e.id)),q=qe.find(_e=>_e.id===u)??null,le=Ie.find(_e=>_e.id===ie)??Ie[0]??null,Pe=Ie.length>0,Ye=We==="right"&&le?le:q,Nt=Pe&&!L,Dt=$e?Wn:Ye?.id??u;v.useEffect(()=>{le?.id!==ie&&Be(le?.id??null),!le&&We==="right"&&He("left")},[ie,We,le]);const Qe=Ye?.provider??A?.id,Ke=Ye?.kind==="shell",pt=Ke?wr:Qe==="codex"?kr:Qi,ds=Ke?l("dock.shell"):Ye?Ye.provider==="codex"?"Codex":"Claude Code":A?.label??"Agent",Kt=Ye?.label||l(Ke?"dock.shellFallback":"dock.newTask"),fi=Ye?!Ke:$e&&!is,Ji=LX((Ye?.provider??A?.id??"claude")==="codex"?"codex":"claude",j),Cr=_e=>{if(Ye?.state==="running"){const tt=S.current.get(Ye.id);if(tt){tt.input(_e),tt.focus();return}}k(_e)},Zn=_e=>{de.current+=1,He("left"),O(_e)},bs=_e=>{de.current+=1,He("right"),Be(_e)},qs=async _e=>{const tt=qe.findIndex(Ht=>Ht.id===_e),_t=qe.filter(Ht=>Ht.id!==_e),ft=_t[Math.min(Math.max(tt,0),_t.length-1)]?.id??($e?Wn:null);await h(_e,ft)&&qe.length===1&&Ie.length>0&&(Re(new Set),Be(null),O(le?.id??Ie[0]?.id??null),He("left"))},Hi=async _e=>{const tt=Ie.findIndex(Ht=>Ht.id===_e),_t=Ie.filter(Ht=>Ht.id!==_e),ft=_t[Math.min(Math.max(tt,0),_t.length-1)]?.id??null;await h(_e)&&(Re(Ht=>{const os=new Set(Ht);return os.delete(_e),os}),Be(Ht=>Ht===_e?ft:Ht),ft||He(Ht=>Ht==="right"?"left":Ht))},Va=async _e=>{const tt=We,_t=++de.current,ft=await g({prompt:"",provider:_e.id,label:l("dock.taskFallback",{provider:_e.label}),...tt==="right"?{background:!0}:{}});if(!ft||tt!=="right"){ft&&He("left");return}Re(Ht=>new Set(Ht).add(ft.id)),de.current===_t&&(Be(ft.id),He("right"))},qo=async()=>{const _e=We,tt=++de.current,_t=await p(void 0,_e==="right"?{background:!0}:void 0);if(!_t||_e!=="right"){_t&&He("left");return}Re(ft=>new Set(ft).add(_t.id)),de.current===tt&&(Be(_t.id),He("right"))},ta=async _e=>{const tt=We,_t=++de.current,ft=tt==="right"?await z(_e,{background:!0}):await z(_e);return!ft||tt!=="right"?(ft&&He("left"),ft):(Re(Ht=>new Set(Ht).add(ft.id)),de.current===_t&&(Be(ft.id),He("right")),ft)},sa=!!(ht&&rt.has(ht)),er=!!(ht&&!sa&&($e||qe.some(_e=>_e.id!==ht))),Wa=()=>{if(!(!ht||!er)){if(de.current+=1,ht===u){const _e=qe.find(tt=>tt.id!==ht)?.id??($e?Wn:null);if(!_e)return;O(_e)}Re(_e=>new Set(_e).add(ht)),Be(ht),He("right"),xt(null)}},on=()=>{if(!ht||!sa)return;de.current+=1;const _e=Ie.filter(tt=>tt.id!==ht);Re(tt=>{const _t=new Set(tt);return _t.delete(ht),_t}),ie===ht&&Be(_e[0]?.id??null),He("left"),O(ht),xt(null)};return n.jsxs(n.Fragment,{children:[j?null:L?n.jsxs("button",{"aria-label":l("dock.openAria"),className:"fixed bottom-0 right-0 z-50 flex w-9 flex-col items-center gap-2 border-l border-border bg-card/95 py-3 shadow-[-4px_0_18px_-14px_rgba(0,0,0,.45)] backdrop-blur",onClick:()=>$(!0),style:{top:js()?32:0},title:Kt,type:"button",children:[n.jsx(pt,{className:"size-4 text-primary"}),Ye?n.jsx("span",{className:se("size-1.5 rounded-full bg-muted-foreground",Ye.state==="running"&&"bg-emerald-500",Ye.state==="error"&&"bg-destructive"),children:n.jsxs("span",{className:"sr-only",children:[l("dock.activeStatusSr"),bN(Ye.state)]})}):null,n.jsx("span",{className:"h-px w-4 bg-border"}),n.jsx("span",{className:"min-h-0 flex-1 [writing-mode:vertical-rl] truncate font-mono text-[10px] text-muted-foreground",children:Kt}),I.length>1?n.jsx("span",{className:"grid size-5 place-items-center rounded-full bg-muted font-mono text-[10px] text-muted-foreground",children:I.length}):null,n.jsx(Rj,{className:"size-3.5 text-muted-foreground"})]}):n.jsxs("button",{"aria-label":l("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:()=>$(!0),type:"button",children:[n.jsx(pt,{className:"size-3.5 text-primary"}),n.jsx("span",{className:"text-xs font-medium",children:ds}),n.jsx("span",{className:"h-3 w-px bg-border"}),n.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",children:Kt}),n.jsx(Ib,{git:t,provider:Qe,variant:"strip"}),Ye?n.jsxs("span",{className:se("font-mono text-[10px] text-muted-foreground",Ye.state==="running"&&"text-emerald-600",Ye.state==="error"&&"text-destructive"),children:[n.jsx("span",{className:"sr-only",children:l("dock.activeStatusSr")}),bN(Ye.state)]}):null,I.length>1?n.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:I.length}):null,n.jsx(nm,{className:"size-3.5 text-muted-foreground"})]}),n.jsxs("div",{"aria-hidden":!j||void 0,className:se("fixed z-50 flex flex-col overflow-hidden bg-card",Se?"inset-x-0 bottom-0 border-t border-border shadow-[0_-12px_30px_-20px_rgba(0,0,0,.5)]":L?"bottom-0 right-0 border-l border-border shadow-[-12px_0_30px_-20px_rgba(0,0,0,.5)]":"inset-x-0 bottom-0 border-t border-border shadow-[0_-12px_30px_-20px_rgba(0,0,0,.5)]",!Se&&!F&&(L?"transition-[width] duration-150":"transition-[height] duration-150"),!j&&"invisible pointer-events-none border-transparent shadow-none"),inert:!j||void 0,style:Se?{height:"auto",top:js()?32:0}:L?{top:js()?32:0,width:j?re:0}:{height:j?V??"50vh":0},children:[Se?n.jsx("nav",{"aria-label":l("dock.fullscreenNavAria"),className:"flex h-11 shrink-0 items-center gap-1 overflow-x-auto border-b border-border bg-background px-2",children:wZ.map(_e=>n.jsxs("button",{"aria-current":e===_e.page?"page":void 0,"aria-label":l(_e.labelKey),className:se("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===_e.page&&"bg-primary text-primary-foreground hover:bg-primary/90 hover:text-primary-foreground"),onClick:()=>Ee(_e.page),type:"button",children:[_e.icon,n.jsx("span",{children:l(_e.labelKey)})]},_e.page))}):null,n.jsx("div",{"aria-hidden":!0,className:se("absolute z-20 touch-none",L?"inset-y-0 -left-1 w-2 cursor-ew-resize":"inset-x-0 -top-1 h-2 cursor-ns-resize",Se&&"hidden"),"data-agent-resize-grip":!0,onDoubleClick:()=>L?ce(480):W(null),onPointerDown:Ce,title:L?l("dock.resizeWidthAria"):void 0}),n.jsxs("div",{className:"flex h-9 shrink-0 items-stretch border-b border-border bg-muted/25","data-agent-dock-toolbar":!0,children:[Se?null:n.jsx("button",{"aria-label":l("dock.positionGrip"),className:"grid w-8 shrink-0 cursor-grab place-items-center border-r border-border text-muted-foreground hover:bg-muted hover:text-foreground active:cursor-grabbing",onClick:()=>{if(Ts.current){Ts.current=!1;return}Ne(De==="right"?"bottom":"right")},onPointerDown:Oe,title:l(De==="right"?"dock.moveToBottom":"dock.moveToRight"),type:"button",children:n.jsx(c8,{className:"size-3.5"})}),Nt?n.jsx("span",{className:"min-w-0 flex-1"}):n.jsx(zb,{activeTaskId:L?Dt:u,composing:$e,onActivate:_e=>L&&rt.has(_e)?bs(_e):Zn(_e),onClose:_e=>{rt.has(_e)?Hi(_e):qs(_e)},onDragEnd:L?void 0:()=>xt(null),onDragStart:L?void 0:xt,onRename:(_e,tt)=>{D(_e,tt)},pendingTaskIds:N,tasks:L?I:qe}),!L&&fi?n.jsx(oN,{capabilities:Ji,onInsert:Cr,onNavigate:a?Ee:void 0,providerLabel:ds}):n.jsx("span",{className:"flex-1"}),L?null:n.jsx(Ib,{git:t,provider:Qe,variant:"dock"}),n.jsxs("div",{className:"flex shrink-0 items-center border-l border-border px-1",children:[n.jsx(QX,{error:U,loading:Y,onLoad:C,onResume:ta,transcripts:B}),n.jsx(JX,{creating:!!b,direction:L?"down":"up",onCreateAgent:_e=>{Va(_e)},onCreateShell:()=>{qo()},providers:T}),Ye?.state==="running"?n.jsx("button",{"aria-label":l("dock.stopTaskAria",{label:Kt}),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:N.has(Ye.id),onClick:()=>{M(Ye.id)},type:"button",children:n.jsx($a,{className:"size-3"})}):null,n.jsx("button",{"aria-label":l(Se?"dock.restoreDock":"dock.enterFullScreen"),className:"grid size-7 place-items-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground",onClick:()=>Ve(_e=>!_e),type:"button",children:Se?n.jsx(L0,{className:"size-3.5"}):n.jsx(D0,{className:"size-3.5"})}),n.jsx("button",{"aria-label":l("dock.collapseAria"),className:"grid size-7 place-items-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground",onClick:oe,type:"button",children:L?n.jsx(gn,{className:"size-3.5"}):n.jsx(kn,{className:"size-3.5"})})]})]}),L?n.jsxs("div",{className:"flex min-h-9 shrink-0 items-center overflow-x-auto border-b border-border bg-muted/10","data-agent-side-utilities":!0,children:[fi?n.jsx(oN,{capabilities:Ji,onInsert:Cr,onNavigate:a?Ee:void 0,providerLabel:ds}):null,n.jsx("span",{className:"min-w-2 flex-1"}),n.jsx(Ib,{git:t,provider:Qe,variant:"side"})]}):null,G?n.jsx("div",{role:"alert",className:"border-b border-destructive/30 bg-destructive/5 px-3 py-1 font-mono text-[11px] text-destructive",children:G}):null,t&&$e?n.jsx("div",{className:"shrink-0 px-3 pt-2",children:n.jsx(QV,{git:t,onRefresh:s})}):null,n.jsxs("div",{className:"relative min-h-0 flex-1 bg-background","data-agent-split-container":!0,ref:ot,children:[Nt?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"absolute left-0 top-0 z-10 flex h-9 items-stretch overflow-hidden border-b border-border bg-muted/25","data-agent-pane-tabs":"left",style:{right:`${100-at}%`},children:n.jsx(zb,{activeTaskId:u,ariaLabel:l("dock.leftTasksAria"),composing:$e,onActivate:Zn,onClose:_e=>{qs(_e)},onDragEnd:()=>xt(null),onDragStart:xt,onRename:(_e,tt)=>{D(_e,tt)},pendingTaskIds:N,tasks:qe})}),n.jsx("div",{className:"absolute right-0 top-0 z-10 flex h-9 items-stretch overflow-hidden border-b border-border bg-muted/25","data-agent-pane-tabs":"right",style:{left:`${at}%`},children:n.jsx(zb,{activeTaskId:le?.id??null,ariaLabel:l("dock.rightTasksAria"),composing:!1,onActivate:bs,onClose:_e=>{Hi(_e)},onDragEnd:()=>xt(null),onDragStart:xt,onRename:(_e,tt)=>{D(_e,tt)},pendingTaskIds:N,tasks:Ie})})]}):null,I.map(_e=>{const tt=rt.has(_e.id),_t=j&&(L?_e.id===Dt:tt?_e.id===le?.id:_e.id===u),ft=_t&&We===(tt?"right":"left"),Ht=Nt?tt?{left:`${at}%`,right:0}:{left:0,right:`${100-at}%`}:void 0;return n.jsx("div",{"aria-labelledby":`agent-tab-${_e.id}`,className:se("absolute bottom-0",Nt?"top-9":"top-0 inset-x-0",!_t&&"invisible pointer-events-none"),id:`agent-panel-${_e.id}`,onPointerDown:()=>{de.current+=1,He(tt?"right":"left")},role:"tabpanel",style:Ht,children:n.jsx(WT,{active:_t,claimInitialInput:()=>f(_e.id),displaySettings:c?.confirmedGlobal.terminal,focused:ft,onStatusChange:os=>P(_e.id,{state:os.state==="connecting"?"idle":os.state,cwd:os.cwd,error:os.state==="error"?os.detail:void 0}),ref:os=>{os?S.current.set(_e.id,os):S.current.delete(_e.id)},sessionId:_e.id})},_e.id)}),j&&$e?n.jsx("div",{"aria-labelledby":`agent-tab-${Wn}`,className:se("absolute bottom-0 bg-background",Nt?"top-9":"top-0 inset-x-0"),id:`agent-panel-${Wn}`,onPointerDown:()=>{de.current+=1,He("left")},role:"tabpanel",style:Nt?{left:0,right:`${100-at}%`}:void 0,children:n.jsx(XX,{capabilities:is?void 0:Ji,onNavigate:a?Ee:void 0,onShellMode:Qs,shellMode:is})}):null,Nt?n.jsx("hr",{"aria-label":l("dock.splitResizeAria"),"aria-orientation":"vertical","aria-valuemax":75,"aria-valuemin":25,"aria-valuenow":Math.round(at),className:"absolute inset-y-0 z-20 h-auto w-3 -translate-x-1/2 cursor-col-resize touch-none border-0 bg-transparent after:absolute after:inset-y-0 after:left-1/2 after:w-px after:-translate-x-1/2 after:bg-border after:transition-colors hover:after:bg-primary focus-visible:after:bg-primary",onDoubleClick:()=>mt(50),onKeyDown:_e=>{(_e.key==="ArrowLeft"||_e.key==="ArrowRight")&&(_e.preventDefault(),mt(tt=>Math.max(25,Math.min(75,tt+(_e.key==="ArrowLeft"?-5:5)))))},onPointerDown:ye,style:{left:`${at}%`},tabIndex:0}):null,!L&&er?n.jsx("section",{"aria-label":l("dock.splitDropTarget"),className:se("absolute bottom-2 right-2 z-30 grid place-items-center rounded-md border border-dashed border-primary/60 bg-primary/10 text-xs font-medium text-primary backdrop-blur-sm",Pe?"top-11":"top-2"),onDragOver:_e=>{_e.preventDefault(),_e.dataTransfer&&(_e.dataTransfer.dropEffect="move")},onDrop:_e=>{_e.preventDefault(),Wa()},style:{width:Pe?`calc(${100-at}% - 0.75rem)`:"calc(50% - 0.75rem)"},children:l("dock.splitDropTarget")}):null,!L&&sa?n.jsx("section",{"aria-label":l("dock.leftDropTarget"),className:"absolute bottom-2 left-2 top-11 z-30 grid place-items-center rounded-md border border-dashed border-primary/60 bg-primary/10 text-xs font-medium text-primary backdrop-blur-sm",onDragOver:_e=>{_e.preventDefault(),_e.dataTransfer&&(_e.dataTransfer.dropEffect="move")},onDrop:_e=>{_e.preventDefault(),on()},style:{width:`calc(${at}% - 0.75rem)`},children:l("dock.leftDropTarget")}):null]})]}),J?n.jsxs(n.Fragment,{children:[n.jsx("section",{className:se("pointer-events-none fixed inset-x-6 bottom-6 z-[60] grid h-24 place-items-center rounded-lg border-2 border-dashed bg-card/90 text-sm font-medium shadow-xl backdrop-blur",Le==="bottom"?"border-primary text-primary":"border-border text-muted-foreground"),children:n.jsxs("span",{className:"flex items-center gap-2",children:[n.jsx(nL,{className:"size-4"}),l("dock.snapBottom")]})}),ue?n.jsx("section",{className:se("pointer-events-none fixed bottom-6 right-6 top-6 z-[60] grid w-44 place-items-center rounded-lg border-2 border-dashed bg-card/90 text-sm font-medium shadow-xl backdrop-blur",Le==="right"?"border-primary text-primary":"border-border text-muted-foreground"),children:n.jsxs("span",{className:"flex items-center gap-2",children:[n.jsx(dL,{className:"size-4"}),l("dock.snapRight")]})}):null]}):null]})}function Pl(e,t){const s=`nomoreide:${e}`,[i,a]=v.useState(()=>{try{const c=window.localStorage.getItem(s);return c===null?t:JSON.parse(c)}catch{return t}}),l=v.useCallback(c=>{a(c);try{window.localStorage.setItem(s,JSON.stringify(c))}catch{}},[s]);return[i,l]}const Hb={host:"",port:"",user:"",password:"",database:"",ssl:!1},NZ="localhost";function p0(e,t,{includePassword:s=!0}={}){const i=e==="mysql"?"mysql":"postgres",a=t.host.trim()||NZ,l=t.port.trim(),c=t.database.trim().replace(/^\//,""),u=t.user.trim(),f=s&&t.password,h=u?`${encodeURIComponent(u)}${f?`:${encodeURIComponent(t.password)}`:""}@`:"",p=l?`:${l}`:"",g=e==="postgres"&&t.ssl?"?sslmode=require":"";return`${i}://${h}${a}${p}/${c}${g}`}function g0(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:vN(t.username),password:vN(t.password),database:t.pathname.replace(/^\//,""),ssl:t.searchParams.get("sslmode")==="require"||t.searchParams.has("ssl")}}function EZ(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 vN(e){try{return decodeURIComponent(e)}catch{return e}}const jZ=[{value:"postgres",label:"Postgres"},{value:"mysql",label:"MySQL"},{value:"sqlite",label:"SQLite"}];function AZ({onClose:e,onSaved:t,initial:s,projects:i=[]}){const a=X(),{isPending:l,runOperation:c}=Yn(),{error:u,success:f}=gs(),h=!!s,p=v.useMemo(()=>TZ(s),[s]),[g,b]=v.useState(p.engine),[x,_]=v.useState(p.name),[k,C]=v.useState(p.url),[E,j]=v.useState(p.fields),[N,A]=v.useState([]),[T,D]=v.useState(s?.projectPath??""),[z,O]=v.useState({status:"idle"}),[$,M]=v.useState(!1),I=`database:${s?.name??"new"}:save`,G=l(I);v.useEffect(()=>{h||MP().then(A).catch(()=>A([]))},[h]);const B=g==="sqlite",U=B?k.trim():p0(g,E),Y=B?!!k.trim():!!(E.host.trim()&&E.database.trim());function P(){O({status:"idle"})}function V(J,ne){return p0(J,ne,{includePassword:!1})}function W(J){b(J),P(),J!=="sqlite"&&C(V(J,E))}function re(J){const ne={...E,...J};j(ne),C(V(g,ne)),P()}function ce(J){P();const ne=EZ(J),Le=ne??g;ne&&ne!==g&&b(ne);const ve=ne==="sqlite"?null:g0(J);if(!ve){C(J);return}ve.password?(j(ve),C(V(Le,ve))):(j({...ve,password:E.password}),C(J))}function F(J){b(J.engine);const ne=J.engine==="sqlite"?null:g0(J.url);ne?(j(ne),C(V(J.engine,ne))):C(J.url),P(),x.trim()||_(RZ(J));const Le=J.cwd?i.find(ve=>Zr(J.cwd,ve.path)):void 0;Le&&D(Le.path)}function K(){return x.trim()?B?k.trim()?null:a("database.dialog.errFilePathRequired"):E.host.trim()?E.database.trim()?null:a("database.dialog.errDatabaseRequired"):a("database.dialog.errHostRequired"):a("database.dialog.errNameRequired")}async function ue(){if(Y){M(!0),P();try{const J=await LP({engine:g,url:U});O(J.ok?{status:"ok",message:a("database.dialog.connected")}:{status:"fail",message:J.error??a("database.dialog.connectionFailed")})}catch(J){O({status:"fail",message:J instanceof Error?J.message:String(J)})}finally{M(!1)}}}async function ge(){const J=K();if(J){u(J);return}try{await c({key:I,label:a("database.dialog.savingConnection",{name:x.trim()})},()=>DP({name:x.trim(),engine:g,url:U,projectPath:T})),f(a("database.dialog.savedToast",{name:x.trim()})),t(),e()}catch(ne){u(ne instanceof Error?ne.message:String(ne))}}return n.jsx(Kn,{icon:n.jsx(hi,{}),onClose:e,title:a(h?"database.dialog.editTitle":"database.dialog.addTitle"),children:n.jsxs("div",{className:"flex flex-col gap-4",children:[N.length>0?n.jsxs("section",{children:[n.jsxs("p",{className:"mb-1.5 flex items-center gap-1.5 text-xs font-medium text-muted-foreground",children:[n.jsx(rO,{className:"size-3.5"}),a("database.dialog.foundInServices")]}),n.jsx("div",{className:"flex flex-wrap gap-1.5",children:N.map(J=>n.jsxs("button",{type:"button",onClick:()=>F(J),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:J.maskedUrl,children:[n.jsx(Ze,{variant:"outline",size:"small",children:J.engine}),n.jsx("span",{className:"font-mono",children:J.service}),n.jsxs("span",{className:"font-mono text-muted-foreground",children:["·",J.key]})]},`${J.service}:${J.key}`))})]}):null,n.jsxs("section",{children:[n.jsx("p",{className:"mb-1.5 text-xs font-medium text-muted-foreground",children:a("database.dialog.engine")}),n.jsx("div",{className:"flex gap-1.5",children:jZ.map(J=>n.jsx(Q,{size:"sm",variant:g===J.value?"default":"outline",onClick:()=>W(J.value),disabled:h,type:"button",children:J.label},J.value))})]}),n.jsxs("label",{className:"flex flex-col gap-1.5",children:[n.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a("database.dialog.name")}),n.jsx(St,{value:x,onChange:J=>_(J.target.value),placeholder:a("database.dialog.namePlaceholder"),disabled:h}),h?n.jsx("span",{className:"text-[11px] text-muted-foreground",children:a("database.dialog.nameLocked")}):null]}),i.length>0?n.jsxs("label",{className:"flex flex-col gap-1.5",children:[n.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Project"}),n.jsxs("select",{className:"h-9 rounded-md border border-border bg-background px-2 text-sm",onChange:J=>D(J.target.value),value:T,children:[n.jsx("option",{value:"",children:"No project (shared)"}),T&&!i.some(J=>J.path===T)?n.jsx("option",{value:T,children:T}):null,i.map(J=>n.jsx("option",{value:J.path,children:J.name},J.path))]}),n.jsx("span",{className:"text-[11px] text-muted-foreground",children:"Classifies the connection under a project; shared connections show in every project scope."})]}):null,B?null:n.jsxs("section",{className:"flex flex-col gap-3",children:[n.jsxs("div",{className:"flex gap-3",children:[n.jsxs("label",{className:"flex flex-1 flex-col gap-1.5",children:[n.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a("database.dialog.host")}),n.jsx(St,{value:E.host,onChange:J=>re({host:J.target.value}),placeholder:"localhost",className:"font-mono text-xs"})]}),n.jsxs("label",{className:"flex w-24 flex-col gap-1.5",children:[n.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a("database.dialog.port")}),n.jsx(St,{value:E.port,onChange:J=>re({port:J.target.value}),placeholder:g==="mysql"?"3306":"5432",className:"font-mono text-xs"})]})]}),n.jsxs("div",{className:"flex gap-3",children:[n.jsxs("label",{className:"flex flex-1 flex-col gap-1.5",children:[n.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a("database.dialog.user")}),n.jsx(St,{value:E.user,onChange:J=>re({user:J.target.value}),placeholder:"postgres",className:"font-mono text-xs"})]}),n.jsxs("label",{className:"flex flex-1 flex-col gap-1.5",children:[n.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a("database.dialog.password")}),n.jsx(St,{type:"password",value:E.password,onChange:J=>re({password:J.target.value}),placeholder:h?a("database.dialog.passwordKeep"):"••••••••",className:"font-mono text-xs"})]})]}),n.jsxs("label",{className:"flex flex-col gap-1.5",children:[n.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a("database.dialog.database")}),n.jsx(St,{value:E.database,onChange:J=>re({database:J.target.value}),placeholder:"app",className:"font-mono text-xs"})]}),g==="postgres"?n.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[n.jsx("input",{type:"checkbox",checked:E.ssl,onChange:J=>re({ssl:J.target.checked}),className:"size-3.5 accent-primary"}),a("database.dialog.requireSslPre")," ",n.jsx("span",{className:"font-mono",children:"?sslmode=require"}),a("database.dialog.requireSslPost")]}):null]}),n.jsxs("label",{className:"flex flex-col gap-1.5",children:[n.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a(B?"database.dialog.filePath":"database.dialog.connectionUrl")}),n.jsx(St,{value:k,onChange:J=>ce(J.target.value),placeholder:B?"/abs/path/to/app.db":g==="mysql"?"mysql://user:pass@host:3306/db":"postgres://user:pass@host:5432/db",className:"font-mono text-xs"}),n.jsx("span",{className:"text-[11px] text-muted-foreground",children:a(B?"database.dialog.sqliteHint":"database.dialog.urlHint")})]}),z.status!=="idle"?n.jsxs("div",{className:`flex items-center gap-1.5 rounded-md border px-2.5 py-1.5 text-xs ${z.status==="ok"?"border-emerald-500/40 text-emerald-600 dark:text-emerald-400":"border-destructive/40 text-destructive"}`,children:[z.status==="ok"?n.jsx(rn,{className:"size-3.5"}):n.jsx(Gt,{className:"size-3.5"}),n.jsx("span",{className:"break-all font-mono",children:z.message})]}):null,n.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border pt-3",children:[n.jsxs(Q,{variant:"outline",size:"sm",onClick:()=>{ue()},disabled:$||!Y,type:"button",children:[$?n.jsx(Bt,{className:"animate-spin"}):null,a("database.dialog.testConnection")]}),n.jsx(Q,{size:"sm",onClick:()=>{ge()},loading:G,loadingLabel:a("common.saving"),type:"button",children:a(h?"database.dialog.saveChanges":"common.save")})]})]})})}function TZ(e){if(!e)return{engine:"postgres",name:"",fields:Hb,url:""};if(e.engine==="sqlite")return{engine:"sqlite",name:e.name,fields:Hb,url:e.url};const t=g0(e.url),s=t?{...t,password:""}:Hb;return{engine:e.engine,name:e.name,fields:s,url:p0(e.engine,s,{includePassword:!1})}}function RZ(e){try{const s=new URL(e.url).pathname.replace(/^\//,"");if(s)return`${e.service}-${s}`}catch{}return`${e.service}-${e.engine}`}function MZ({connections:e,projectLabel:t,selected:s,onSelect:i,onAdd:a,onEdit:l,onRemove:c}){const u=X(),[f,h]=v.useState(!1),p=v.useRef(null),g=e.find(b=>b.name===s);return v.useEffect(()=>{if(!f)return;function b(x){p.current&&x.target instanceof Node&&!p.current.contains(x.target)&&h(!1)}return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[f]),n.jsxs("div",{className:"relative z-50 flex items-center gap-2",ref:p,children:[n.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:[n.jsx(hi,{className:"text-muted-foreground"}),n.jsx("span",{className:"truncate",children:g?.name??u("database.selectConnection")}),g?n.jsx(Ze,{variant:"outline",size:"small",children:g.engine}):null,n.jsx(kn,{className:se("ml-auto transition-transform",f&&"rotate-180")})]}),f?n.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:[n.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2",children:[n.jsx(hi,{className:"size-3.5 text-muted-foreground"}),n.jsx("div",{className:"text-xs font-semibold",children:u("database.connections")}),n.jsx(Ze,{className:"ml-auto",variant:"outline",size:"small",children:e.length})]}),n.jsx("div",{className:"max-h-72 overflow-auto",children:e.length?n.jsx("div",{className:"divide-y divide-border",children:e.map(b=>{const x=b.name===s;return n.jsxs("div",{className:se("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",x&&"bg-muted/70"),children:[n.jsxs("button",{className:"min-w-0 text-left",onClick:()=>{i(b.name),h(!1)},type:"button",children:[n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"truncate text-sm font-medium leading-tight",children:b.name}),t?n.jsx(Ze,{className:"shrink-0",size:"small",variant:"outline",children:t(b)??"unassigned"}):null]}),n.jsx("span",{className:"block truncate font-mono text-[10px] leading-tight text-muted-foreground",children:b.url})]}),x?n.jsx(rn,{className:"size-3.5"}):n.jsx("span",{className:"size-3.5"}),n.jsx(Q,{"aria-label":u("database.editConn",{name:b.name}),className:"size-6 opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>{l(b),h(!1)},size:"icon",title:u("database.editConn",{name:b.name}),type:"button",variant:"ghost",children:n.jsx(Il,{className:"size-3.5"})}),n.jsx(Q,{"aria-label":u("database.removeConn",{name:b.name}),className:"size-6 opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>c(b.name),size:"icon",title:u("database.removeConn",{name:b.name}),type:"button",variant:"ghost",children:n.jsx(Xi,{className:"size-3.5 text-destructive"})})]},b.name)})}):n.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:u("database.noSavedConnections")})}),n.jsx("div",{className:"border-t border-border bg-muted/20 p-2",children:n.jsxs(Q,{className:"w-full",onClick:()=>{a(),h(!1)},size:"sm",type:"button",children:[n.jsx(Es,{className:"size-3"}),u("database.addConnection")]})})]}):null]})}function DZ({onAddManual:e,onAddWithAi:t}){const s=X(),[i,a]=v.useState(!1),l=v.useRef(null);v.useEffect(()=>{if(!i)return;function u(f){l.current&&f.target instanceof Node&&!l.current.contains(f.target)&&a(!1)}return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[i]);function c(u){a(!1),u()}return n.jsxs("div",{className:"relative",ref:l,children:[n.jsxs(Q,{"aria-label":s("database.addMenuAria"),onClick:()=>a(u=>!u),size:"sm",type:"button",children:[n.jsx(Es,{className:"size-3.5"}),s("common.add")]}),i?n.jsxs("div",{className:"absolute right-0 top-9 z-50 w-56 overflow-hidden rounded-lg border border-border bg-card shadow-lg",children:[n.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:[n.jsx(hi,{className:"size-3.5 text-muted-foreground"}),s("database.addConnection")]}),n.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:[n.jsx(Sn,{className:"size-3.5 text-muted-foreground"}),s("database.addWithAi")]})]}):null]})}function LZ(){const[e,t]=v.useState([]),[s,i]=v.useState(!0),[a,l]=v.useState(null),c=v.useCallback(async()=>{i(!0),l(null);try{t(await r3())}catch(u){l(u instanceof Error?u.message:String(u))}finally{i(!1)}},[]);return v.useEffect(()=>{c()},[c]),{connections:e,loading:s,error:a,refresh:c}}const OZ=[50,100,500,1e3];function iR(e){return[...new Set([...OZ,e])].sort((t,s)=>t-s)}function PZ(e){const[t,s]=v.useState(null),[i,a]=v.useState(null),[l,c]=v.useState(!1);v.useEffect(()=>{s(null),a(null)},[e]);const u=v.useCallback(async(h,p)=>{if(!(!e||!h.trim())){c(!0),a(null);try{s(await PP(e,h,p))}catch(g){s(null),a(g instanceof Error?g.message:String(g))}finally{c(!1)}}},[e]),f=v.useCallback(()=>{s(null),a(null)},[]);return{result:t,error:i,running:l,run:u,reset:f}}const zZ=["select","show","explain","pragma","describe","desc"];function BZ(e){const t=/^\s*([a-z]+)/i.exec(e)?.[1]?.toLowerCase()??"";return zZ.includes(t)}function IZ(e){const[t,s]=v.useState(null),[i,a]=v.useState(null),[l,c]=v.useState(null),[u,f]=v.useState(!1),[h,p]=v.useState(!1);v.useEffect(()=>{s(null),a(null),c(null)},[e]);const g=v.useCallback(async k=>{if(!(!e||!k.trim())){f(!0),c(null),a(null);try{const C=await QS(e,k,"preview");s({sql:k,preview:C})}catch(C){c(C instanceof Error?C.message:String(C))}finally{f(!1)}}},[e]),b=v.useCallback(async k=>{const C=k??t?.sql;if(!e||!C)return null;p(!0),c(null);try{const E=await QS(e,C,"commit");return a(E),s(null),E}catch(E){return s(null),c(E instanceof Error?E.message:String(E)),null}finally{p(!1)}},[e,t]),x=v.useCallback(()=>s(null),[]),_=v.useCallback(()=>{s(null),a(null),c(null)},[]);return{pending:t,committed:i,error:l,previewing:u,committing:h,preview:g,commit:b,cancel:x,reset:_}}function HZ(e,t){const[s,i]=v.useState(!1),a=v.useCallback(async l=>{if(e){i(!0);try{await zP(e,l),t()}finally{i(!1)}}},[e,t]);return{updating:s,setUnlocked:a}}function $Z(e,t=100){const[s,i]=v.useState([]),[a,l]=v.useState(null),[c,u]=v.useState(null),[f,h]=v.useState(null),[p,g]=v.useState(null),[b,x]=v.useState(!1),[_,k]=v.useState(!1),[C,E]=v.useState(()=>t),j=v.useRef(!1),[N,A]=v.useState(0);v.useEffect(()=>{j.current||E(t)},[t]),v.useEffect(()=>{A(0)},[e,a]),v.useEffect(()=>{if(i([]),l(null),u(null),h(null),g(null),!e)return;let M=!1;return x(!0),a3(e).then(I=>{M||(i(I),l(I[0]?.qualifiedName??null))}).catch(I=>{M||h(I instanceof Error?I.message:String(I))}).finally(()=>{M||x(!1)}),()=>{M=!0}},[e]),v.useEffect(()=>{if(u(null),g(null),!e||!a)return;let M=!1;return k(!0),BP(e,a,C,N).then(I=>{M||u(I)}).catch(I=>{M||g(I instanceof Error?I.message:String(I))}).finally(()=>{M||k(!1)}),()=>{M=!0}},[e,a,C,N]);const T=N>0,D=c?c.rowCount===C:!1;function z(M){j.current=!0,E(M),A(0)}function O(){D&&A(M=>M+C)}function $(){A(M=>Math.max(0,M-C))}return{tables:s,selectedTable:a,setSelectedTable:l,sample:c,tablesError:f,rowsError:p,loadingTables:b,loadingRows:_,limit:C,offset:N,canPrev:T,canNext:D,changePageSize:z,nextPage:O,prevPage:$}}function FZ(e,t,s,i){const a=X(),{provider:l}=Vt(),[c,u]=v.useState(!1),[f,h]=v.useState(null),p=v.useRef(null),g=v.useRef(!0);return v.useEffect(()=>(g.current=!0,()=>{g.current=!1,p.current?.abort()}),[]),{generate:v.useCallback(async x=>{if(!e||!x.trim()||c)return;u(!0),h(null);const _=new AbortController;p.current=_;try{let k=[];try{k=await a3(e)}catch{k=[]}if(!g.current||_.signal.aborted)return;const C=await w1({prompt:Aq(e,x,{engine:t,tables:k,unlocked:s}),provider:l?.id,signal:_.signal});if(!g.current)return;const E=UZ(C);E?i(E):h(a("database.sql.noSqlBlock"))}catch(k){g.current&&!_.signal.aborted&&h(k instanceof Error?k.message:String(k))}finally{p.current===_&&(p.current=null),g.current&&u(!1)}},[e,t,s,c,i,l?.id,a]),generating:c,error:f}}function UZ(e){if(!e)return null;const s=/```(?:sql)?\s*\n?([\s\S]*?)```/i.exec(e)?.[1]?.trim();return s||null}function qZ({connection:e,sample:t}){const s=X(),{sendToAgent:i}=Vt(),{success:a,error:l}=gs(),c=t.columns.map(g=>g.name);function u(g){i({prompt:jq(e,t.engine,t.table,t.columns,g),source:{type:"database-row",label:s("database.grid.rowSource",{table:t.table.name})},mode:"draft"})}async function f(g,b){try{await navigator.clipboard.writeText(g),a(s("database.grid.copiedWhat",{what:b}))}catch(x){l(x instanceof Error?x.message:String(x))}}function h(g){const b=x=>{const _=Cu(x);return/[",\n]/.test(_)?`"${_.replace(/"/g,'""')}"`:_};return`${c.join(",")}
|
|
119
|
-
${c.map(x=>b(g[x])).join(",")}`}function p(g){const b=_=>_==null?"NULL":typeof _=="number"||typeof _=="boolean"?String(_):`'${(typeof _=="object"?JSON.stringify(_):String(_)).replace(/'/g,"''")}'`,x=c.map(_=>b(g[_])).join(", ");return`INSERT INTO ${t.table} (${c.join(", ")}) VALUES (${x});`}return t.columns.length===0?n.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:s("database.grid.noColumnsTable")}):n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:n.jsxs("table",{className:"code-font-size w-max min-w-full border-collapse text-left font-mono",children:[n.jsx("thead",{className:"sticky top-0 z-10 bg-card",children:n.jsxs("tr",{className:"border-b border-border",children:[t.columns.map(g=>n.jsxs("th",{className:"whitespace-nowrap px-3 py-2 font-semibold text-foreground",children:[n.jsxs("span",{className:"flex items-center gap-1",children:[g.primaryKey?n.jsx($j,{className:"size-3 text-amber-500"}):null,g.name]}),n.jsx("span",{className:"block font-normal text-muted-foreground",children:g.dataType})]},g.name)),n.jsx("th",{className:"sticky right-0 z-20 w-16 border-l border-border bg-card px-2 py-2"})]})}),n.jsxs("tbody",{children:[t.rows.map((g,b)=>n.jsxs("tr",{className:"group border-b border-border/60 hover:bg-muted/40",children:[t.columns.map(x=>n.jsx("td",{className:"max-w-[320px] truncate px-3 py-1 align-top text-muted-foreground",title:Cu(g[x.name]),children:Cu(g[x.name])},x.name)),n.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:n.jsxs("div",{className:"relative z-[1] flex items-center justify-end gap-0.5",children:[n.jsx(xr,{label:s("database.grid.askAiRow"),onAsk:()=>u(g)}),n.jsx(Yl,{label:s("database.grid.rowActions"),items:[{label:s("database.grid.copyJson"),icon:n.jsx(V6,{className:"size-3.5"}),onSelect:()=>{f(JSON.stringify(g,null,2),s("database.grid.rowAsJson"))}},{label:s("database.grid.copyCsv"),icon:n.jsx(zD,{className:"size-3.5"}),onSelect:()=>{f(h(g),s("database.grid.rowAsCsv"))}},{label:s("database.grid.copySqlInsert"),icon:n.jsx(hi,{className:"size-3.5"}),onSelect:()=>{f(p(g),s("database.grid.insertStatement"))}}]})]})})]},b)),t.rows.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:t.columns.length+1,className:"px-3 py-6 text-center text-muted-foreground",children:s("database.grid.noRows")})}):null]})]})})}function Cu(e){return e==null?"NULL":typeof e=="object"?JSON.stringify(e):String(e)}function GZ({connection:e,busy:t,onConfirm:s,onClose:i}){const a=X();return n.jsx(Kn,{icon:n.jsx(PL,{className:"text-amber-500"}),onClose:i,title:a("database.write.unlockTitle",{connection:e}),children:n.jsxs("div",{className:"flex flex-col gap-4 text-sm",children:[n.jsx("p",{className:"text-muted-foreground",children:a("database.write.unlockBody1")}),n.jsx("p",{className:"text-muted-foreground",children:a("database.write.unlockBody2")}),n.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border pt-3",children:[n.jsx(Q,{variant:"outline",size:"sm",onClick:i,type:"button",children:a("common.cancel")}),n.jsxs(Q,{size:"sm",onClick:s,disabled:t,type:"button",children:[t?n.jsx(Bt,{className:"animate-spin"}):n.jsx(Fj,{}),a("database.write.unlockWrites")]})]})]})})}function VZ({sql:e,preview:t,busy:s,onConfirm:i,onClose:a}){const l=X();return n.jsx(Kn,{icon:n.jsx(Zi,{className:"text-amber-500"}),onClose:a,title:l("database.write.confirmTitle"),children:n.jsxs("div",{className:"flex flex-col gap-4 text-sm",children:[n.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?n.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")}):n.jsxs("p",{className:"text-muted-foreground",children:[l("database.write.willAffectPre")," ",n.jsx("strong",{className:"text-foreground tabular-nums",children:t.affectedRows??0})," ",l("database.write.willAffectPost")]}),n.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border pt-3",children:[n.jsx(Q,{variant:"outline",size:"sm",onClick:a,type:"button",children:l("common.cancel")}),n.jsxs(Q,{size:"sm",className:"bg-amber-600 text-white hover:bg-amber-600/90",onClick:i,disabled:s,type:"button",children:[s?n.jsx(Bt,{className:"animate-spin"}):null,l("database.write.runCommit")]})]})]})})}function WZ({connection:e,engine:t,unlocked:s,seed:i,onWriteAccessChange:a,preferences:l={confirmWrites:!0,resultLimit:100}}){const c=X(),{isPending:u,runOperation:f}=Yn(),{success:h}=gs(),{sendToAgent:p}=Vt(),g=PZ(e),b=IZ(e),x=HZ(e,a),[_,k]=v.useState(i?.sql??""),[C,E]=v.useState(()=>l.resultLimit),j=v.useRef(!1);v.useEffect(()=>{j.current||E(l.resultLimit)},[l.resultLimit]);const N=i?.nonce;v.useEffect(()=>{i&&k(i.sql)},[N]);const[A,T]=v.useState(!1),D=FZ(e,t,s,k),z=_.trim().length>0&&!BZ(_),O=s&&z,$=z&&!s,M=g.running||b.previewing||b.committing,I=`database:${e}:write`,G=u(I);function B(){if(_.trim()){if($){T(!0);return}O?(g.reset(),l.confirmWrites?b.preview(_):P(_)):(b.reset(),g.run(_,C))}}function U(V){(V.metaKey||V.ctrlKey)&&V.key==="Enter"&&(V.preventDefault(),B())}function Y(V){p({prompt:Tq(e,t,_,V),source:{type:"database-sql-debug",label:"Debug SQL"},label:c("database.sql.debugLabel")})}async function P(V){const W=await f({key:I,label:c("database.sql.committingWrite",{connection:e})},()=>b.commit(V));if(W?.committed){const re=W.affectedRows??0;h(c("database.sql.committed",{count:re}))}}return n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[n.jsxs("div",{className:"shrink-0 border-b border-border p-2",children:[n.jsx(KZ,{generate:D}),n.jsx("textarea",{value:_,onChange:V=>k(V.target.value),onKeyDown:U,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"}),n.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[n.jsx(YZ,{unlocked:s,updating:x.updating,onUnlock:()=>T(!0),onLock:()=>{x.setUnlocked(!1)}}),n.jsxs("div",{className:"flex items-center gap-2",children:[O?null:n.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:V=>{j.current=!0,E(Number(V.target.value))},children:iR(l.resultLimit).map(V=>n.jsx("option",{value:V,children:c("database.sql.rowsOption",{size:V})},V))}),n.jsxs(Q,{size:"sm",className:se("h-7 px-3",O&&"bg-amber-600 text-white hover:bg-amber-600/90"),onClick:B,disabled:M||!_.trim(),loading:O&&G,loadingLabel:c("database.sql.runWrite"),type:"button",children:[M?n.jsx(Bt,{className:"size-3.5 animate-spin"}):n.jsx(_r,{className:"size-3.5"}),O?l.confirmWrites?c("database.sql.previewWrite"):c("database.sql.runWrite"):c("database.sql.run")]})]})]})]}),n.jsx(XZ,{read:g,write:b,onDebug:Y}),A?n.jsx(GZ,{connection:e,busy:x.updating,onConfirm:async()=>{await x.setUnlocked(!0),T(!1)},onClose:()=>T(!1)}):null,b.pending?n.jsx(VZ,{sql:b.pending.sql,preview:b.pending.preview,busy:b.committing,onConfirm:()=>{P()},onClose:b.cancel}):null]})}function KZ({generate:e}){const t=X(),[s,i]=v.useState("");function a(){const c=s.trim();!c||e.generating||e.generate(c)}function l(c){c.key==="Enter"&&(c.preventDefault(),a())}return n.jsxs("div",{className:"mb-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"relative flex-1",children:[n.jsx(cs,{className:"pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2"}),n.jsx("input",{value:s,onChange:c=>i(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"})]}),n.jsxs(Q,{size:"sm",variant:"outline",className:"h-8 px-3",onClick:a,disabled:e.generating||!s.trim(),type:"button",children:[e.generating?n.jsx(Bt,{className:"size-3.5 animate-spin"}):n.jsx(cs,{className:"size-3.5"}),e.generating?t("database.sql.generating"):t("database.sql.askAi")]})]}),e.error?n.jsx("p",{className:"mt-1 text-[11px] text-amber-600 dark:text-amber-400",children:e.error}):null]})}function YZ({unlocked:e,updating:t,onUnlock:s,onLock:i}){const a=X();return n.jsxs("button",{type:"button",onClick:e?i:s,disabled:t,className:se("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?n.jsx(Bt,{className:"size-3.5 animate-spin"}):e?n.jsx(Fj,{className:"size-3.5"}):n.jsx(O8,{className:"size-3.5"}),a(e?"database.sql.writesUnlocked":"database.sql.readOnly")]})}function XZ({read:e,write:t,onDebug:s}){const i=X(),a=t.error??e.error;return n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:a?n.jsxs("div",{className:"space-y-3 p-4",children:[n.jsx("p",{className:"code-font-size whitespace-pre-wrap font-mono text-destructive",children:a}),n.jsxs(Q,{size:"sm",variant:"outline",className:"h-7 px-3",onClick:()=>s(a),type:"button",children:[n.jsx(cs,{className:"size-3.5"}),i("database.sql.debugWithAi")]})]}):t.committed?n.jsx(ZZ,{outcome:t.committed}):e.result?n.jsx(rR,{columns:e.result.columns,rows:e.result.rows,truncated:e.result.truncated}):n.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center text-sm text-muted-foreground",children:i("database.sql.emptyResult")})})}function ZZ({outcome:e}){const t=X();if(!e)return null;const s=e.affectedRows??0;return n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[n.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:[n.jsx(rn,{className:"size-3.5"}),t("database.sql.committed",{count:s})]}),e.rows&&e.rows.length>0&&e.columns?n.jsx(rR,{columns:e.columns,rows:e.rows}):null]})}function rR({columns:e,rows:t,truncated:s=!1}){const i=X();return e.length===0?n.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:i("database.sql.noColumns")}):n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[s?n.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:[n.jsx(Zi,{className:"size-3.5"}),i("database.sql.truncated",{count:t.length})]}):null,n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:n.jsxs("table",{className:"code-font-size w-max min-w-full border-collapse text-left font-mono",children:[n.jsx("thead",{className:"sticky top-0 z-10 bg-card",children:n.jsx("tr",{className:"border-b border-border",children:e.map(a=>n.jsx("th",{className:"whitespace-nowrap px-3 py-2 font-semibold text-foreground",children:a.name},a.name))})}),n.jsxs("tbody",{children:[t.map((a,l)=>n.jsx("tr",{className:"border-b border-border/60 hover:bg-muted/40",children:e.map(c=>n.jsx("td",{className:"max-w-[320px] truncate px-3 py-1 align-top text-muted-foreground",title:Cu(a[c.name]),children:Cu(a[c.name])},c.name))},l)),t.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:e.length,className:"px-3 py-6 text-center text-muted-foreground",children:i("database.grid.noRows")})}):null]})]})})]})}function QZ({staged:e,onStageConsumed:t,projects:s=[],scopePath:i=null}={}){const a=X(),c=Om()?.confirmedProject.database??{confirmWrites:!0,resultLimit:100},{connections:u,loading:f,error:h,refresh:p}=LZ(),g=v.useMemo(()=>u.filter(I=>vV(I.projectPath,i)),[u,i]),b=I=>I.projectPath?s.find(B=>Zr(I.projectPath,B.path))?.name??I.projectPath.split("/").pop()??null:null;$o(p);const{error:x,success:_}=gs(),{sendToAgent:k}=Vt(),[C,E]=Pl("database:selected",null),[j,N]=Pl("database:mode","browse"),[A,T]=v.useState(null),[D,z]=v.useState(null);v.useEffect(()=>{e&&(e.connection&&E(e.connection),N("query"),z({sql:e.sql,nonce:e.nonce}),t?.())},[e?.nonce]);function O(){k({prompt:Cq,source:{type:"database-setup",label:"Add a database"},label:"Help me connect a database, one step at a time."})}v.useEffect(()=>{if(g.length===0){C!==null&&E(null);return}(!C||!g.some(I=>I.name===C))&&E(g[0].name)},[g,C,E]);async function $(I){try{await OP(I),_(a("database.toast.removed",{name:I})),await p()}catch(G){x(G instanceof Error?G.message:String(G))}}function M(I){T({mode:"edit",target:I})}return n.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[n.jsxs("header",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(hi,{className:"size-4 text-muted-foreground"}),n.jsx("span",{className:"text-sm font-semibold",children:a("database.title")}),f&&g.length===0?n.jsx(Bt,{className:"size-3.5 animate-spin text-muted-foreground"}):null]}),n.jsxs("div",{className:"flex items-center gap-2",children:[C?n.jsx(JZ,{mode:j,onChange:N}):null,n.jsx(MZ,{connections:g,projectLabel:b,selected:C,onSelect:E,onAdd:()=>T({mode:"add"}),onEdit:M,onRemove:I=>{$(I)}}),n.jsx(DZ,{onAddManual:()=>T({mode:"add"}),onAddWithAi:O})]})]}),n.jsx("div",{className:"min-h-0 flex-1",children:h?n.jsx("div",{className:"p-4",children:n.jsx(nt,{variant:"muted",className:"border-destructive/40 text-destructive",children:h})}):C?j==="query"?n.jsx(WZ,{connection:C,engine:g.find(I=>I.name===C)?.engine,unlocked:g.find(I=>I.name===C)?.writeUnlocked??!1,seed:D,onWriteAccessChange:p,preferences:c},C):n.jsx(eQ,{connection:C,resultLimit:c.resultLimit}):n.jsx(tQ,{onAdd:()=>T({mode:"add"}),onAddWithAi:O})}),A?n.jsx(AZ,{initial:A.mode==="edit"?A.target:void 0,projects:s,onClose:()=>T(null),onSaved:p}):null]})}function JZ({mode:e,onChange:t}){const s=X(),i=[{value:"browse",label:s("database.browse"),icon:Xj},{value:"query",label:s("database.sql"),icon:ql}];return n.jsx("div",{className:"flex items-center rounded-md border border-border p-0.5",children:i.map(a=>{const l=a.icon;return n.jsxs("button",{type:"button",onClick:()=>t(a.value),className:se("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:[n.jsx(l,{className:"size-3.5"}),a.label]},a.value)})})}function eQ({connection:e,resultLimit:t}){const s=X(),{sendToAgent:i}=Vt(),{tables:a,selectedTable:l,setSelectedTable:c,sample:u,tablesError:f,rowsError:h,loadingTables:p,loadingRows:g,limit:b,offset:x,canPrev:_,canNext:k,changePageSize:C,nextPage:E,prevPage:j}=$Z(e,t);function N(T){i({prompt:F2(e,T.table,{engine:T.engine,columns:T.columns}),source:{type:"database-table",label:`${T.table.name} table`},mode:"draft"})}function A(T){i({prompt:F2(e,T),source:{type:"database-table",label:`${T.name} table`},mode:"draft"})}return n.jsxs("div",{className:"flex h-full min-h-0",children:[n.jsxs("div",{className:"flex w-56 shrink-0 flex-col border-r border-border",children:[n.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[n.jsx(Xj,{className:"size-4 text-muted-foreground"}),n.jsx("span",{className:"text-sm font-semibold",children:s("database.tables")}),n.jsx(Ze,{variant:"outline",size:"small",children:a.length}),p?n.jsx(Bt,{className:"size-3.5 animate-spin"}):null]}),f?n.jsx("div",{className:"p-3",children:n.jsx(nt,{variant:"muted",className:"border-destructive/40 text-destructive",children:f})}):n.jsxs("ul",{className:"min-h-0 flex-1 overflow-auto",children:[a.map(T=>n.jsxs("li",{className:se("group flex items-center gap-1 pr-1 transition-colors hover:bg-muted/50",T.qualifiedName===l&&"bg-muted/70"),children:[n.jsx("button",{type:"button",onClick:()=>c(T.qualifiedName),className:se("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}),n.jsx(xr,{label:s("database.askAiAbout",{name:T.qualifiedName}),onAsk:()=>A(T)})]},T.qualifiedName)),!p&&a.length===0?n.jsx("li",{className:"px-3 py-2 text-xs text-muted-foreground",children:s("database.noTables")}):null]})]}),n.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[n.jsxs("div",{className:"group flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-2",children:[n.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[n.jsx("span",{className:"truncate font-mono text-xs font-semibold",children:l??s("database.selectTable")}),u?n.jsx(xr,{label:s("database.askAiAbout",{name:u.table.qualifiedName}),onAsk:()=>N(u)}):null]}),u?n.jsxs("div",{className:"flex shrink-0 items-center gap-2 text-[11px] text-muted-foreground",children:[n.jsx("span",{className:"tabular-nums",children:u.rowCount===0?s("database.noRows"):s("database.rowsRange",{from:x+1,to:x+u.rowCount})}),n.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:iR(t).map(T=>n.jsx("option",{value:T,children:s("database.perPage",{size:T})},T))}),n.jsx(Q,{size:"sm",variant:"outline",className:"h-6 px-2",onClick:j,disabled:!_,type:"button",children:s("database.prev")}),n.jsx(Q,{size:"sm",variant:"outline",className:"h-6 px-2",onClick:E,disabled:!k,type:"button",children:s("database.next")})]}):null]}),h?n.jsx("div",{className:"p-4",children:n.jsx(nt,{variant:"muted",className:"border-destructive/40 text-destructive",children:h})}):g?n.jsxs("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:[n.jsx(Bt,{className:"mr-2 size-4 animate-spin"}),s("database.loadingRows")]}):u?n.jsx(qZ,{connection:e,sample:u}):n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:s("database.pickTable")})]})]})}function tQ({onAdd:e,onAddWithAi:t}){const s=X();return n.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center",children:n.jsxs("div",{className:"max-w-sm",children:[n.jsx(hi,{className:"mx-auto size-8 text-muted-foreground/50"}),n.jsx("p",{className:"mt-3 text-sm font-medium",children:s("database.emptyTitle")}),n.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:[s("database.emptyBody1")," ",n.jsx("code",{children:".env"})," ",s("database.emptyBody2")]}),n.jsxs("div",{className:"mt-4 flex items-center justify-center gap-2",children:[n.jsxs(Q,{size:"sm",onClick:e,type:"button",children:[n.jsx(Es,{}),s("database.addConnection")]}),n.jsxs(Q,{size:"sm",variant:"outline",onClick:t,type:"button",children:[n.jsx(Sn,{}),s("database.addWithAi")]})]})]})})}const dr=[{id:"general",label:"General",description:"Language, navigation, and startup context.",icon:y8,scope:"global",keywords:["language","sidebar","dock","agent","project scope"]},{id:"appearance",label:"Appearance",description:"Theme, density, type size, and motion.",icon:qj,scope:"global",keywords:["theme","dark","light","font","motion","accent","color","colour"]},{id:"terminal",label:"Terminal",description:"Terminal rendering and process safeguards.",icon:wr,scope:"global",keywords:["shell","cursor","scrollback","copy","terminate"]},{id:"services-logs",label:"Services & Logs",description:"How this project presents runtime output.",icon:hm,scope:"project",keywords:["timestamps","wrap","runtime","services"]},{id:"git-github",label:"Git & GitHub",description:"Source-control preferences and connection status.",icon:Mn,scope:"mixed",keywords:["git","github","co-author","repository"]},{id:"agents-mcp",label:"Agents & MCP",description:"Agent environments and MCP management.",icon:sm,scope:"mixed",keywords:["agent","model","mcp","claude","codex"]},{id:"database-safety",label:"Database & Safety",description:"Project query limits and write safeguards.",icon:hi,scope:"project",keywords:["database","sql","danger confirmation","writes","limit"]},{id:"notifications",label:"Notifications",description:"Browser notification capability and permission.",icon:I6,scope:"global",keywords:["alerts","desktop","permission"]},{id:"data-privacy",label:"Data & Privacy",description:"Local storage, export, reset, and privacy.",icon:Wj,scope:"mixed",keywords:["data","privacy","export","reset","storage"]},{id:"about",label:"About",description:"Version, runtime, documentation, and support.",icon:b8,scope:"global",keywords:["version","docs","runtime","issues"]}],aR={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."},"agent-dock-placement":{category:"general",label:"Agent dock position",description:"Place the agent workspace along the bottom or right edge."},"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."},accent:{category:"appearance",label:"Accent color",description:"Recolor the workbench, globally or per project."},"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 sQ(e){const t=aR[e];if(!t)throw new Error(`Missing settings copy for "${e}".`);return t}function oR(e){return`settingsHub.item.${e}.label`}function lR(e){return`settingsHub.item.${e}.desc`}function Nu(e){return`settingsHub.cat.${e}.label`}function nQ(e){return`settingsHub.cat.${e}.desc`}const iQ=Object.keys(aR);function rQ(e,t,s){const i=cR(e),a=t.trim().toLowerCase().split(/\s+/).filter(Boolean);return iQ.filter(l=>{const c=sQ(l);if(c.category!==e)return!1;const u=s?` ${s(Nu(e))} ${s(oR(l))} ${s(lR(l))}`:"",f=`${i.label} ${i.description} ${i.keywords.join(" ")} ${c.label} ${c.description}${u}`.toLowerCase();return a.every(h=>f.includes(h))})}function cR(e){return dr.find(t=>t.id===e)??dr[0]}function aQ({scope:e}){const t=X();return n.jsx("span",{className:se("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 oQ({state:e,error:t}){const s=X();return e==="idle"?null:n.jsxs("div",{"aria-live":"polite",className:se("flex items-center gap-1.5 text-xs",e==="error"?"text-destructive":"text-muted-foreground"),children:[e==="saving"?n.jsx(Bt,{className:"size-3.5 animate-spin"}):null,e==="saved"?n.jsx(rn,{className:"size-3.5 text-emerald-600"}):null,e==="error"?n.jsx(im,{className:"size-3.5"}):null,n.jsx("span",{children:e==="saving"?s("settingsHub.saving"):e==="saved"?s("settingsHub.saved"):t})]})}function Iu({id:e,label:t,description:s,children:i,disabled:a=!1}){return n.jsxs("div",{className:se("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:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("label",{className:"text-sm font-medium",htmlFor:e,children:t}),n.jsx("p",{className:"mt-0.5 max-w-xl text-xs leading-5 text-muted-foreground",id:`${e}-description`,children:s})]}),n.jsx("div",{className:"min-w-0 sm:justify-self-end",children:i})]})}function go({id:e,label:t,description:s,checked:i,onChange:a,disabled:l=!1}){return n.jsx(Iu,{description:s,disabled:l,id:e,label:t,children:n.jsx("input",{"aria-describedby":`${e}-description`,checked:i,className:"size-4 accent-foreground",disabled:l,id:e,onChange:c=>a(c.target.checked),type:"checkbox"})})}function Nl({id:e,label:t,description:s,value:i,options:a,onChange:l,disabled:c=!1}){return n.jsx(Iu,{description:s,disabled:c,id:e,label:t,children:n.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:u=>l(u.target.value),value:i,children:a.map(u=>n.jsx("option",{disabled:u.disabled,value:u.value,children:u.label},u.value))})})}function Fh({id:e,label:t,description:s,value:i,min:a,max:l,onSave:c,disabled:u=!1,scopeKey:f}){const h=X(),{isPending:p,runOperation:g}=Yn(),[b,x]=v.useState(String(i)),[_,k]=v.useState(null),C=`settings:${f??"global"}:${e}:save`,E=p(C);v.useEffect(()=>{x(String(i)),k(null)},[f,i]);async function j(){const N=Number(b);if(!Number.isInteger(N)||N<a||N>l){k(h("settingsHub.numberRange",{min:a,max:l}));return}k(null);try{await g({key:C,label:h("settingsHub.savingSetting",{label:t})},async()=>c(N))}catch(A){k(A instanceof Error?A.message:String(A))}}return n.jsx(Iu,{description:s,disabled:u,id:e,label:t,children:n.jsxs("div",{className:"flex flex-col items-start gap-1 sm:items-end",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(St,{"aria-describedby":`${e}-description${_?` ${e}-error`:""}`,"aria-invalid":!!_,className:"h-8 w-24 font-mono text-xs",disabled:u,id:e,max:l,min:a,onChange:N=>x(N.target.value),type:"number",value:b}),n.jsx(Q,{"aria-label":h("settingsHub.saveAria",{label:t}),disabled:u,loading:E,loadingLabel:h("settingsHub.saving"),onClick:()=>{j()},size:"sm",type:"button",variant:"outline",children:h("settingsHub.save")})]}),_?n.jsx("span",{className:"text-[11px] text-destructive",id:`${e}-error`,role:"alert",children:_}):null]})})}function Da({title:e,description:t,action:s}){return n.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:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"text-sm font-medium",children:e}),n.jsx("p",{className:"mt-0.5 break-words text-xs leading-5 text-muted-foreground",children:t})]}),s?n.jsx("div",{className:"w-full shrink-0 [&_button]:w-full sm:w-auto sm:[&_button]:w-auto",children:s}):null]})}function lQ({children:e}){return n.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 cQ({selected:e,onSelect:t,search:s,onSearch:i,saveState:a,saveError:l,children:c}){const u=X(),f=v.useRef([]),h=cR(e),p=h.icon;function g(b,x){let _=null;if(b.key==="ArrowDown"&&(_=(x+1)%dr.length),b.key==="ArrowUp"&&(_=(x-1+dr.length)%dr.length),b.key==="Home"&&(_=0),b.key==="End"&&(_=dr.length-1),_===null)return;b.preventDefault();const k=dr[_];t(k.id),f.current[_]?.focus()}return n.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[n.jsxs("header",{className:"flex shrink-0 flex-wrap items-center gap-3 border-b border-border px-3 py-2.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Vj,{className:"size-4 text-muted-foreground"}),n.jsx("span",{className:"text-sm font-semibold",children:u("settingsHub.title")})]}),n.jsxs("div",{className:"relative ml-auto w-full sm:w-64",children:[n.jsx(Au,{className:"pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"}),n.jsx("input",{"aria-label":u("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=>i(b.target.value),placeholder:u("settingsHub.searchPlaceholder"),type:"search",value:s}),s?n.jsx("button",{"aria-label":u("settingsHub.clearSearch"),className:"absolute right-1.5 top-1/2 -translate-y-1/2 rounded p-1 text-muted-foreground hover:bg-muted",onClick:()=>i(""),type:"button",children:n.jsx(Gt,{className:"size-3"})}):null]}),n.jsx(oQ,{error:l,state:a})]}),n.jsxs("div",{className:"border-b border-border px-3 py-2 md:hidden",children:[n.jsx("label",{className:"mb-1 block text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",htmlFor:"settings-category-select",children:u("settingsHub.category")}),n.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:dr.map(b=>n.jsx("option",{value:b.id,children:u(Nu(b.id))},b.id))})]}),n.jsxs("div",{className:"flex min-h-0 flex-1",children:[n.jsx("aside",{className:"hidden w-56 shrink-0 border-r border-border bg-muted/20 p-2 md:block",children:n.jsx("nav",{"aria-label":u("settingsHub.categoriesAria"),className:"space-y-0.5",children:dr.map((b,x)=>{const _=b.icon,k=e===b.id;return n.jsxs("button",{"aria-current":k?"page":void 0,className:se("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",k?"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=>g(C,x),ref:C=>{f.current[x]=C},tabIndex:k?0:-1,type:"button",children:[n.jsx(_,{className:"size-3.5"}),n.jsx("span",{children:u(Nu(b.id))})]},b.id)})})}),n.jsx("main",{className:"min-w-0 flex-1 overflow-y-auto",children:n.jsxs("div",{className:"mx-auto max-w-3xl px-3 py-4 sm:px-6 sm:py-6",children:[s?null:n.jsxs("div",{className:"mb-4",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(p,{className:"size-4 text-muted-foreground"}),n.jsx("h2",{className:"text-base font-semibold",children:u(Nu(h.id))})]}),n.jsx("p",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:u(nQ(h.id))})]}),c]})})]})]})}const uR="linear-gradient(to right, hsl(0 70% 50%), hsl(60 70% 50%), hsl(120 70% 45%), hsl(180 60% 45%), hsl(240 62% 55%), hsl(300 62% 52%), hsl(360 70% 50%))";function xN({color:e,selected:t,title:s,rainbow:i,onClick:a}){return n.jsx("button",{"aria-label":s,"aria-pressed":t,className:se("grid size-6 place-items-center rounded-full ring-offset-2 ring-offset-background transition",t?"ring-2 ring-ring":"ring-1 ring-border hover:ring-foreground/40"),onClick:a,style:{background:i?uR:e},title:s,type:"button",children:t?n.jsx(rn,{className:"size-3.5 text-white drop-shadow-[0_1px_1px_rgba(0,0,0,0.5)]"}):null})}function yN({value:e,onChange:t}){const s=X(),i=O1(e),a=i!==null;return n.jsxs("div",{className:"flex flex-col items-start gap-2 sm:items-end",children:[n.jsxs("div",{className:"flex flex-wrap items-center justify-start gap-1.5 sm:justify-end",children:[QT.map(l=>n.jsx(xN,{color:l.swatch,onClick:()=>t(l.id),selected:e===l.id,title:s(l.labelKey)},l.id)),n.jsx(xN,{color:uZ(a?e:"custom:265"),onClick:()=>t(a?e:"custom:265"),rainbow:!a,selected:a,title:s("settingsHub.accent.custom")})]}),a?n.jsx("input",{"aria-label":s("settingsHub.accent.hue"),className:"h-2 w-44 cursor-pointer appearance-none rounded-full outline-none",max:359,min:0,onChange:l=>t(`custom:${l.target.value}`),style:{background:uR},type:"range",value:i??0}):null]})}function uQ({ui:e,updateUi:t,activeProject:s}){const i=X(),a=s?.path??null,l=a?e.projectAccents[a]:void 0,c=l!==void 0,u=f=>{if(!a)return;const h={...e.projectAccents};f===null?delete h[a]:h[a]=f,t({projectAccents:h})};return n.jsxs(n.Fragment,{children:[n.jsx(Iu,{description:i("settingsHub.accent.description"),id:"setting-accent",label:i("settingsHub.accent.label"),children:n.jsx(yN,{onChange:f=>t({accent:f}),value:e.accent})}),s?n.jsx(Iu,{description:i("settingsHub.accent.projectDescription"),id:"setting-project-accent",label:i("settingsHub.accent.projectLabel",{name:s.name}),children:n.jsxs("div",{className:"flex flex-col items-start gap-2 sm:items-end",children:[n.jsxs("div",{className:"inline-flex rounded-md border border-input p-0.5 text-xs",children:[n.jsx("button",{className:se("rounded px-2 py-1 transition-colors",c?"text-muted-foreground hover:text-foreground":"bg-muted font-medium text-foreground"),onClick:()=>u(null),type:"button",children:i("settingsHub.accent.useGlobal")}),n.jsx("button",{className:se("rounded px-2 py-1 transition-colors",c?"bg-muted font-medium text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>u(l??e.accent),type:"button",children:i("settingsHub.accent.override")})]}),c?n.jsx(yN,{onChange:u,value:l??e.accent}):null]})}):null]})}function ci({scope:e,title:t,children:s}){const i=X();return n.jsxs("section",{className:"mb-4 overflow-hidden rounded-lg border border-border bg-background/70",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border bg-muted/25 px-4 py-2.5",children:[n.jsx("h3",{className:"text-xs font-semibold",children:t??i(e==="global"?"settingsHub.global":"settingsHub.currentProject")}),n.jsx(aQ,{scope:e})]}),s]})}function tu({project:e,ready:t,loadError:s,onRetry:i}){const a=X();return e&&s?n.jsxs("div",{className:"border-b border-destructive/30 bg-destructive/5 px-4 py-3",role:"alert",children:[n.jsx("p",{className:"text-xs text-destructive",children:s}),n.jsx(Q,{"aria-label":a("settingsHub.retryProject"),className:"mt-2",onClick:i,size:"sm",type:"button",variant:"outline",children:a("settingsHub.retryProject")})]}):e&&!t?n.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?n.jsxs("div",{className:"border-b border-border/50 bg-amber-500/5 px-4 py-2 text-[11px] text-muted-foreground",children:[n.jsx("span",{className:"font-medium text-foreground",children:e.name})," · ",a("settingsHub.projectWritesPre"),n.jsx("code",{children:"nomoreide.config.json"}),a("settingsHub.projectWritesPost")]}):n.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 dQ({activeProject:e=null,onNavigate:t}={}){const s=X(),i=Lm(),a=!!(e?.path&&e.path===i.activeProjectPath&&!i.projectLoading&&!i.projectLoadError),[l,c]=v.useState("general"),[u,f]=v.useState(""),h=u.trim().toLowerCase(),p=v.useMemo(()=>h?dr.map(b=>({id:b.id,settingIds:rQ(b.id,h,s)})).filter(b=>b.settingIds.length>0):[],[h,s]);let g;return i.loading?g=n.jsx("div",{"aria-label":s("settingsHub.loadingAria"),className:"space-y-3",role:"status",children:[0,1,2].map(b=>n.jsx("div",{className:"h-20 animate-pulse rounded-lg border border-border bg-muted/40"},b))}):i.loadError?g=n.jsxs("div",{className:"rounded-lg border border-destructive/30 bg-destructive/5 p-4",role:"alert",children:[n.jsx("p",{className:"text-sm font-medium",children:s("settingsHub.loadFailed")}),n.jsx("p",{className:"mt-1 text-xs text-destructive",children:i.loadError}),n.jsx(Q,{className:"mt-3",onClick:()=>{i.retry()},size:"sm",type:"button",variant:"outline",children:s("settingsHub.retry")})]}):h?g=n.jsxs("div",{children:[n.jsx("h2",{className:"mb-4 text-base font-semibold",children:s("settingsHub.searchResults")}),p.length?p.map(({id:b,settingIds:x})=>n.jsxs("div",{className:"mb-5",children:[n.jsx("div",{className:"mb-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:s(Nu(b))}),n.jsx(_N,{activeProject:e,category:b,onNavigate:t,projectReady:a,settings:i,visibleSettingIds:new Set(x)})]},b)):n.jsx(lQ,{children:s("settingsHub.noMatches",{query:u.trim()})})]}):g=n.jsx(_N,{activeProject:e,category:l,onNavigate:t,projectReady:a,settings:i}),n.jsx(cQ,{onSearch:f,onSelect:c,saveError:i.saveError,saveState:i.saveState,search:u,selected:l,children:g})}function _N({category:e,activeProject:t,projectReady:s,onNavigate:i,settings:a,visibleSettingIds:l}){const c=X(),u=!s,f=g=>!l||l.has(g),h=g=>g.some(f),p=g=>({label:c(oR(g)),description:c(lR(g))});switch(e){case"general":return n.jsxs(ci,{scope:"global",children:[f("language")?n.jsx(Nl,{...p("language"),id:"setting-language",onChange:g=>a.updateUi({language:g}),options:BU.map(g=>({value:g.value,label:g.nativeLabel,disabled:!g.available})),value:a.ui.language}):null,f("sidebar-docked")?n.jsx(go,{...p("sidebar-docked"),checked:a.ui.sidebarDocked,id:"setting-sidebar-docked",onChange:g=>a.updateUi({sidebarDocked:g})}):null,f("agent-dock-placement")?n.jsx(Nl,{...p("agent-dock-placement"),id:"setting-agent-dock-placement",onChange:g=>a.updateUi({agentDockPlacement:g}),options:[{value:"bottom",label:c("settingsHub.opt.bottom")},{value:"right",label:c("settingsHub.opt.right")}],value:a.ui.agentDockPlacement}):null,f("project-scope")?n.jsx(Nl,{...p("project-scope"),id:"setting-project-scope",onChange:g=>a.updateUi({projectScope:g}),options:[{value:"all",label:c("settingsHub.opt.allProjects")},{value:"project",label:c("settingsHub.currentProject")}],value:a.ui.projectScope}):null]});case"appearance":return n.jsxs(ci,{scope:"global",children:[f("theme")?n.jsx(Nl,{...p("theme"),id:"setting-theme",onChange:g=>a.updateUi({theme:g}),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")?n.jsx(Nl,{...p("density"),id:"setting-density",onChange:g=>a.updateUi({density:g}),options:[{value:"comfortable",label:c("settingsHub.opt.comfortable")},{value:"compact",label:c("settingsHub.opt.compact")}],value:a.ui.density}):null,f("code-font")?n.jsx(Fh,{...p("code-font"),id:"setting-code-font",max:18,min:10,onSave:g=>{a.updateUi({codeFontSize:g})},value:a.ui.codeFontSize}):null,f("reduced-motion")?n.jsx(go,{...p("reduced-motion"),checked:a.ui.reducedMotion,id:"setting-reduced-motion",onChange:g=>a.updateUi({reducedMotion:g})}):null,f("accent")?n.jsx(uQ,{activeProject:t?.path?{name:t.name,path:t.path}:null,ui:a.ui,updateUi:a.updateUi}):null]});case"terminal":return n.jsxs(ci,{scope:"global",children:[f("terminal-font")?n.jsx(Fh,{...p("terminal-font"),id:"setting-terminal-font",max:24,min:10,onSave:g=>a.updateGlobal({terminal:{fontSize:g}}),value:a.global.terminal.fontSize}):null,f("cursor")?n.jsx(Nl,{...p("cursor"),id:"setting-cursor",onChange:g=>{a.updateGlobal({terminal:{cursorStyle:g}})},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")?n.jsx(Fh,{...p("scrollback"),id:"setting-scrollback",max:1e5,min:500,onSave:g=>a.updateGlobal({terminal:{scrollback:g}}),value:a.global.terminal.scrollback}):null,f("copy-on-select")?n.jsx(go,{...p("copy-on-select"),checked:a.global.terminal.copyOnSelect,id:"setting-copy-on-select",onChange:g=>{a.updateGlobal({terminal:{copyOnSelect:g}})}}):null,f("confirm-terminate")?n.jsx(go,{...p("confirm-terminate"),checked:a.global.terminal.confirmTerminate,id:"setting-confirm-terminate",onChange:g=>{a.updateGlobal({terminal:{confirmTerminate:g}})}}):null]});case"services-logs":return n.jsxs(ci,{scope:"project",children:[n.jsx(tu,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),f("log-timestamps")?n.jsx(go,{...p("log-timestamps"),checked:a.project.logs.showTimestamps,disabled:u,id:"setting-log-timestamps",onChange:g=>{a.updateProject({logs:{showTimestamps:g}})}}):null,f("wrap-lines")?n.jsx(go,{...p("wrap-lines"),checked:a.project.logs.wrapLines,disabled:u,id:"setting-wrap-lines",onChange:g=>{a.updateProject({logs:{wrapLines:g}})}}):null]});case"git-github":return n.jsxs(n.Fragment,{children:[h(["github-connection"])?n.jsx(ci,{scope:"global",children:n.jsx(Da,{action:n.jsx(Q,{onClick:()=>i?.("github"),size:"sm",type:"button",variant:"outline",children:c("settingsHub.manageGitHub")}),description:p("github-connection").description,title:p("github-connection").label})}):null,h(["repository-defaults"])?n.jsxs(ci,{scope:"project",children:[n.jsx(tu,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),n.jsx(Da,{description:p("repository-defaults").description,title:p("repository-defaults").label})]}):null]});case"agents-mcp":return n.jsxs(n.Fragment,{children:[h(["agent-environments"])?n.jsx(ci,{scope:"global",children:n.jsx(Da,{action:n.jsx(Q,{onClick:()=>i?.("agent-env"),size:"sm",type:"button",variant:"outline",children:c("settingsHub.openAgentEnv")}),description:p("agent-environments").description,title:p("agent-environments").label})}):null,h(["project-agent-context"])?n.jsxs(ci,{scope:"project",children:[n.jsx(tu,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),n.jsx(Da,{description:p("project-agent-context").description,title:p("project-agent-context").label})]}):null]});case"database-safety":return n.jsxs(ci,{scope:"project",children:[n.jsx(tu,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),f("confirm-writes")?n.jsx(go,{...p("confirm-writes"),checked:a.project.database.confirmWrites,disabled:u,id:"setting-confirm-writes",onChange:g=>{a.updateProject({database:{confirmWrites:g}})}}):null,f("result-limit")?n.jsx(Fh,{...p("result-limit"),disabled:u,id:"setting-result-limit",max:5e3,min:10,onSave:g=>a.updateProject({database:{resultLimit:g}}),scopeKey:a.activeProjectPath,value:a.project.database.resultLimit}):null,f("connections")?n.jsx(Da,{action:n.jsx(Q,{disabled:u,onClick:()=>i?.("database"),size:"sm",type:"button",variant:"outline",children:c("settingsHub.openDatabase")}),description:p("connections").description,title:p("connections").label}):null]});case"notifications":{const g=typeof Notification>"u"?c("settingsHub.notifUnavailable"):c("settingsHub.notifPermission",{value:Notification.permission});return n.jsx(ci,{scope:"global",children:f("desktop-notifications")?n.jsx(Da,{action:n.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:g}),description:p("desktop-notifications").description,title:p("desktop-notifications").label}):null})}case"data-privacy":return n.jsxs(n.Fragment,{children:[h(["local-storage"])?n.jsx(ci,{scope:"global",children:n.jsx(Da,{description:p("local-storage").description,title:p("local-storage").label})}):null,h(["export-reset"])?n.jsxs(ci,{scope:"project",children:[n.jsx(tu,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),n.jsx(Da,{description:p("export-reset").description,title:p("export-reset").label})]}):null]});case"about":return n.jsx(ci,{scope:"global",children:n.jsxs("div",{className:"grid grid-cols-[auto_1fr] gap-x-5 gap-y-2 px-4 py-4 text-xs",children:[f("version")?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-muted-foreground",children:p("version").label}),n.jsxs("code",{children:["v","0.1.92"]})]}):null,f("console")?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-muted-foreground",children:p("console").label}),n.jsx("code",{children:"127.0.0.1:4317"})]}):null,f("documentation")?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-muted-foreground",children:p("documentation").label}),n.jsxs("a",{className:"inline-flex items-center gap-1 text-primary hover:underline",href:"https://www.nomoreide.com/docs",rel:"noreferrer",target:"_blank",children:[n.jsx(jj,{className:"size-3"}),"nomoreide.com/docs",n.jsx(Xr,{className:"size-3"})]})]}):null]})})}}function hQ(e,t){const s=t.trim().toLocaleLowerCase();return s?[e.service,e.title,e.file??"",...e.logExcerpt].some(i=>i.toLocaleLowerCase().includes(s)):!0}function fQ(e,t,s){const i=new Set(s.levels),a=new Set(s.services);return e.filter(l=>hQ(l,t)&&(i.size===0||i.has(l.level))&&(a.size===0||a.has(l.service)))}function mQ(e){return{levels:[...new Set(e.map(({level:t})=>t))].sort(),services:[...new Set(e.map(({service:t})=>t))].sort()}}function pQ(e){return e.levels.length+e.services.length}function gQ({detailId:e,incident:t,onReviewChanges:s}){const i=X(),{sendToAgent:a}=Vt(),{isPending:l,runOperation:c}=Yn(),u=`error:${t.id}:fix`,f=l(u),[h,p]=v.useState(null);async function g(){await c({errorMessage:b=>b instanceof Error?b.message:String(b),key:u,label:i("errors.incident.fixingOperation",{service:t.service})},async()=>{const{prompt:b,sessionId:x}=await ZP(t.id);a({prompt:b,source:{type:"error",label:`${t.service} — ${t.level}`},label:i("errors.incident.fixLabel",{level:t.level,service:t.service,title:t.title})}),p(x)})}return n.jsxs("div",{className:"min-w-0 rounded-lg border border-border bg-background","data-incident-detail":"true",id:e,children:[n.jsxs("div",{className:"px-4 py-3",children:[n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(Ze,{variant:t.level==="error"?"danger":"secondary",appearance:"subtle",size:"small",children:i(t.level==="error"?"errors.level.error":"errors.level.warning")}),n.jsx("span",{className:"truncate font-mono text-xs font-semibold",children:t.service}),t.count>1?n.jsxs(Ze,{variant:"outline",size:"small",children:["×",t.count]}):null]}),n.jsxs(Q,{loading:f,loadingLabel:i("errors.incident.starting"),onClick:()=>{g().catch(()=>{})},size:"sm",variant:"outline",children:[n.jsx(cs,{className:"size-3.5"}),i("errors.incident.fixWithAi")]})]}),n.jsx("p",{className:"mt-1.5 break-words font-mono text-xs text-foreground",children:t.title}),t.file?n.jsxs("p",{className:"mt-1 flex items-center gap-1.5 font-mono text-[11px] text-muted-foreground",children:[n.jsx(zj,{className:"size-3.5"}),t.file,t.line?`:${t.line}`:""]}):null,n.jsx("p",{className:"mt-1 font-mono text-[10px] text-muted-foreground/80",children:i("errors.incident.firstLast",{first:new Date(t.firstSeen).toLocaleString(),last:new Date(t.lastSeen).toLocaleTimeString()})})]}),n.jsxs("div",{className:"border-t border-border p-4",children:[h?n.jsx(nt,{variant:"muted",className:"mb-3",children:n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[n.jsx("span",{className:"text-xs",children:i("errors.incident.working")}),s?n.jsxs(Q,{onClick:()=>s(h),size:"sm",variant:"outline",children:[n.jsx(Pj,{className:"size-3.5"}),i("errors.incident.reviewChanges")]}):null]})}):null,n.jsx("p",{className:"mb-1.5 text-xs font-medium text-muted-foreground",children:i("errors.incident.logExcerpt")}),n.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
|
+
${c.map(x=>b(g[x])).join(",")}`}function p(g){const b=_=>_==null?"NULL":typeof _=="number"||typeof _=="boolean"?String(_):`'${(typeof _=="object"?JSON.stringify(_):String(_)).replace(/'/g,"''")}'`,x=c.map(_=>b(g[_])).join(", ");return`INSERT INTO ${t.table} (${c.join(", ")}) VALUES (${x});`}return t.columns.length===0?n.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:s("database.grid.noColumnsTable")}):n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:n.jsxs("table",{className:"code-font-size w-max min-w-full border-collapse text-left font-mono",children:[n.jsx("thead",{className:"sticky top-0 z-10 bg-card",children:n.jsxs("tr",{className:"border-b border-border",children:[t.columns.map(g=>n.jsxs("th",{className:"whitespace-nowrap px-3 py-2 font-semibold text-foreground",children:[n.jsxs("span",{className:"flex items-center gap-1",children:[g.primaryKey?n.jsx($j,{className:"size-3 text-amber-500"}):null,g.name]}),n.jsx("span",{className:"block font-normal text-muted-foreground",children:g.dataType})]},g.name)),n.jsx("th",{className:"sticky right-0 z-20 w-16 border-l border-border bg-card px-2 py-2"})]})}),n.jsxs("tbody",{children:[t.rows.map((g,b)=>n.jsxs("tr",{className:"group border-b border-border/60 hover:bg-muted/40",children:[t.columns.map(x=>n.jsx("td",{className:"max-w-[320px] truncate px-3 py-1 align-top text-muted-foreground",title:Cu(g[x.name]),children:Cu(g[x.name])},x.name)),n.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:n.jsxs("div",{className:"relative z-[1] flex items-center justify-end gap-0.5",children:[n.jsx(xr,{label:s("database.grid.askAiRow"),onAsk:()=>u(g)}),n.jsx(Yl,{label:s("database.grid.rowActions"),items:[{label:s("database.grid.copyJson"),icon:n.jsx(V6,{className:"size-3.5"}),onSelect:()=>{f(JSON.stringify(g,null,2),s("database.grid.rowAsJson"))}},{label:s("database.grid.copyCsv"),icon:n.jsx(zD,{className:"size-3.5"}),onSelect:()=>{f(h(g),s("database.grid.rowAsCsv"))}},{label:s("database.grid.copySqlInsert"),icon:n.jsx(hi,{className:"size-3.5"}),onSelect:()=>{f(p(g),s("database.grid.insertStatement"))}}]})]})})]},b)),t.rows.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:t.columns.length+1,className:"px-3 py-6 text-center text-muted-foreground",children:s("database.grid.noRows")})}):null]})]})})}function Cu(e){return e==null?"NULL":typeof e=="object"?JSON.stringify(e):String(e)}function GZ({connection:e,busy:t,onConfirm:s,onClose:i}){const a=X();return n.jsx(Kn,{icon:n.jsx(PL,{className:"text-amber-500"}),onClose:i,title:a("database.write.unlockTitle",{connection:e}),children:n.jsxs("div",{className:"flex flex-col gap-4 text-sm",children:[n.jsx("p",{className:"text-muted-foreground",children:a("database.write.unlockBody1")}),n.jsx("p",{className:"text-muted-foreground",children:a("database.write.unlockBody2")}),n.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border pt-3",children:[n.jsx(Q,{variant:"outline",size:"sm",onClick:i,type:"button",children:a("common.cancel")}),n.jsxs(Q,{size:"sm",onClick:s,disabled:t,type:"button",children:[t?n.jsx(Bt,{className:"animate-spin"}):n.jsx(Fj,{}),a("database.write.unlockWrites")]})]})]})})}function VZ({sql:e,preview:t,busy:s,onConfirm:i,onClose:a}){const l=X();return n.jsx(Kn,{icon:n.jsx(Zi,{className:"text-amber-500"}),onClose:a,title:l("database.write.confirmTitle"),children:n.jsxs("div",{className:"flex flex-col gap-4 text-sm",children:[n.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?n.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")}):n.jsxs("p",{className:"text-muted-foreground",children:[l("database.write.willAffectPre")," ",n.jsx("strong",{className:"text-foreground tabular-nums",children:t.affectedRows??0})," ",l("database.write.willAffectPost")]}),n.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border pt-3",children:[n.jsx(Q,{variant:"outline",size:"sm",onClick:a,type:"button",children:l("common.cancel")}),n.jsxs(Q,{size:"sm",className:"bg-amber-600 text-white hover:bg-amber-600/90",onClick:i,disabled:s,type:"button",children:[s?n.jsx(Bt,{className:"animate-spin"}):null,l("database.write.runCommit")]})]})]})})}function WZ({connection:e,engine:t,unlocked:s,seed:i,onWriteAccessChange:a,preferences:l={confirmWrites:!0,resultLimit:100}}){const c=X(),{isPending:u,runOperation:f}=Yn(),{success:h}=gs(),{sendToAgent:p}=Vt(),g=PZ(e),b=IZ(e),x=HZ(e,a),[_,k]=v.useState(i?.sql??""),[C,E]=v.useState(()=>l.resultLimit),j=v.useRef(!1);v.useEffect(()=>{j.current||E(l.resultLimit)},[l.resultLimit]);const N=i?.nonce;v.useEffect(()=>{i&&k(i.sql)},[N]);const[A,T]=v.useState(!1),D=FZ(e,t,s,k),z=_.trim().length>0&&!BZ(_),O=s&&z,$=z&&!s,M=g.running||b.previewing||b.committing,I=`database:${e}:write`,G=u(I);function B(){if(_.trim()){if($){T(!0);return}O?(g.reset(),l.confirmWrites?b.preview(_):P(_)):(b.reset(),g.run(_,C))}}function U(V){(V.metaKey||V.ctrlKey)&&V.key==="Enter"&&(V.preventDefault(),B())}function Y(V){p({prompt:Tq(e,t,_,V),source:{type:"database-sql-debug",label:"Debug SQL"},label:c("database.sql.debugLabel")})}async function P(V){const W=await f({key:I,label:c("database.sql.committingWrite",{connection:e})},()=>b.commit(V));if(W?.committed){const re=W.affectedRows??0;h(c("database.sql.committed",{count:re}))}}return n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[n.jsxs("div",{className:"shrink-0 border-b border-border p-2",children:[n.jsx(KZ,{generate:D}),n.jsx("textarea",{value:_,onChange:V=>k(V.target.value),onKeyDown:U,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"}),n.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[n.jsx(YZ,{unlocked:s,updating:x.updating,onUnlock:()=>T(!0),onLock:()=>{x.setUnlocked(!1)}}),n.jsxs("div",{className:"flex items-center gap-2",children:[O?null:n.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:V=>{j.current=!0,E(Number(V.target.value))},children:iR(l.resultLimit).map(V=>n.jsx("option",{value:V,children:c("database.sql.rowsOption",{size:V})},V))}),n.jsxs(Q,{size:"sm",className:se("h-7 px-3",O&&"bg-amber-600 text-white hover:bg-amber-600/90"),onClick:B,disabled:M||!_.trim(),loading:O&&G,loadingLabel:c("database.sql.runWrite"),type:"button",children:[M?n.jsx(Bt,{className:"size-3.5 animate-spin"}):n.jsx(_r,{className:"size-3.5"}),O?l.confirmWrites?c("database.sql.previewWrite"):c("database.sql.runWrite"):c("database.sql.run")]})]})]})]}),n.jsx(XZ,{read:g,write:b,onDebug:Y}),A?n.jsx(GZ,{connection:e,busy:x.updating,onConfirm:async()=>{await x.setUnlocked(!0),T(!1)},onClose:()=>T(!1)}):null,b.pending?n.jsx(VZ,{sql:b.pending.sql,preview:b.pending.preview,busy:b.committing,onConfirm:()=>{P()},onClose:b.cancel}):null]})}function KZ({generate:e}){const t=X(),[s,i]=v.useState("");function a(){const c=s.trim();!c||e.generating||e.generate(c)}function l(c){c.key==="Enter"&&(c.preventDefault(),a())}return n.jsxs("div",{className:"mb-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"relative flex-1",children:[n.jsx(cs,{className:"pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2"}),n.jsx("input",{value:s,onChange:c=>i(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"})]}),n.jsxs(Q,{size:"sm",variant:"outline",className:"h-8 px-3",onClick:a,disabled:e.generating||!s.trim(),type:"button",children:[e.generating?n.jsx(Bt,{className:"size-3.5 animate-spin"}):n.jsx(cs,{className:"size-3.5"}),e.generating?t("database.sql.generating"):t("database.sql.askAi")]})]}),e.error?n.jsx("p",{className:"mt-1 text-[11px] text-amber-600 dark:text-amber-400",children:e.error}):null]})}function YZ({unlocked:e,updating:t,onUnlock:s,onLock:i}){const a=X();return n.jsxs("button",{type:"button",onClick:e?i:s,disabled:t,className:se("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?n.jsx(Bt,{className:"size-3.5 animate-spin"}):e?n.jsx(Fj,{className:"size-3.5"}):n.jsx(O8,{className:"size-3.5"}),a(e?"database.sql.writesUnlocked":"database.sql.readOnly")]})}function XZ({read:e,write:t,onDebug:s}){const i=X(),a=t.error??e.error;return n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:a?n.jsxs("div",{className:"space-y-3 p-4",children:[n.jsx("p",{className:"code-font-size whitespace-pre-wrap font-mono text-destructive",children:a}),n.jsxs(Q,{size:"sm",variant:"outline",className:"h-7 px-3",onClick:()=>s(a),type:"button",children:[n.jsx(cs,{className:"size-3.5"}),i("database.sql.debugWithAi")]})]}):t.committed?n.jsx(ZZ,{outcome:t.committed}):e.result?n.jsx(rR,{columns:e.result.columns,rows:e.result.rows,truncated:e.result.truncated}):n.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center text-sm text-muted-foreground",children:i("database.sql.emptyResult")})})}function ZZ({outcome:e}){const t=X();if(!e)return null;const s=e.affectedRows??0;return n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[n.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:[n.jsx(rn,{className:"size-3.5"}),t("database.sql.committed",{count:s})]}),e.rows&&e.rows.length>0&&e.columns?n.jsx(rR,{columns:e.columns,rows:e.rows}):null]})}function rR({columns:e,rows:t,truncated:s=!1}){const i=X();return e.length===0?n.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:i("database.sql.noColumns")}):n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[s?n.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:[n.jsx(Zi,{className:"size-3.5"}),i("database.sql.truncated",{count:t.length})]}):null,n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:n.jsxs("table",{className:"code-font-size w-max min-w-full border-collapse text-left font-mono",children:[n.jsx("thead",{className:"sticky top-0 z-10 bg-card",children:n.jsx("tr",{className:"border-b border-border",children:e.map(a=>n.jsx("th",{className:"whitespace-nowrap px-3 py-2 font-semibold text-foreground",children:a.name},a.name))})}),n.jsxs("tbody",{children:[t.map((a,l)=>n.jsx("tr",{className:"border-b border-border/60 hover:bg-muted/40",children:e.map(c=>n.jsx("td",{className:"max-w-[320px] truncate px-3 py-1 align-top text-muted-foreground",title:Cu(a[c.name]),children:Cu(a[c.name])},c.name))},l)),t.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:e.length,className:"px-3 py-6 text-center text-muted-foreground",children:i("database.grid.noRows")})}):null]})]})})]})}function QZ({staged:e,onStageConsumed:t,projects:s=[],scopePath:i=null}={}){const a=X(),c=Om()?.confirmedProject.database??{confirmWrites:!0,resultLimit:100},{connections:u,loading:f,error:h,refresh:p}=LZ(),g=v.useMemo(()=>u.filter(I=>vV(I.projectPath,i)),[u,i]),b=I=>I.projectPath?s.find(B=>Zr(I.projectPath,B.path))?.name??I.projectPath.split("/").pop()??null:null;$o(p);const{error:x,success:_}=gs(),{sendToAgent:k}=Vt(),[C,E]=Pl("database:selected",null),[j,N]=Pl("database:mode","browse"),[A,T]=v.useState(null),[D,z]=v.useState(null);v.useEffect(()=>{e&&(e.connection&&E(e.connection),N("query"),z({sql:e.sql,nonce:e.nonce}),t?.())},[e?.nonce]);function O(){k({prompt:Cq,source:{type:"database-setup",label:"Add a database"},label:"Help me connect a database, one step at a time."})}v.useEffect(()=>{if(g.length===0){C!==null&&E(null);return}(!C||!g.some(I=>I.name===C))&&E(g[0].name)},[g,C,E]);async function $(I){try{await OP(I),_(a("database.toast.removed",{name:I})),await p()}catch(G){x(G instanceof Error?G.message:String(G))}}function M(I){T({mode:"edit",target:I})}return n.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[n.jsxs("header",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(hi,{className:"size-4 text-muted-foreground"}),n.jsx("span",{className:"text-sm font-semibold",children:a("database.title")}),f&&g.length===0?n.jsx(Bt,{className:"size-3.5 animate-spin text-muted-foreground"}):null]}),n.jsxs("div",{className:"flex items-center gap-2",children:[C?n.jsx(JZ,{mode:j,onChange:N}):null,n.jsx(MZ,{connections:g,projectLabel:b,selected:C,onSelect:E,onAdd:()=>T({mode:"add"}),onEdit:M,onRemove:I=>{$(I)}}),n.jsx(DZ,{onAddManual:()=>T({mode:"add"}),onAddWithAi:O})]})]}),n.jsx("div",{className:"min-h-0 flex-1",children:h?n.jsx("div",{className:"p-4",children:n.jsx(nt,{variant:"muted",className:"border-destructive/40 text-destructive",children:h})}):C?j==="query"?n.jsx(WZ,{connection:C,engine:g.find(I=>I.name===C)?.engine,unlocked:g.find(I=>I.name===C)?.writeUnlocked??!1,seed:D,onWriteAccessChange:p,preferences:c},C):n.jsx(eQ,{connection:C,resultLimit:c.resultLimit}):n.jsx(tQ,{onAdd:()=>T({mode:"add"}),onAddWithAi:O})}),A?n.jsx(AZ,{initial:A.mode==="edit"?A.target:void 0,projects:s,onClose:()=>T(null),onSaved:p}):null]})}function JZ({mode:e,onChange:t}){const s=X(),i=[{value:"browse",label:s("database.browse"),icon:Xj},{value:"query",label:s("database.sql"),icon:ql}];return n.jsx("div",{className:"flex items-center rounded-md border border-border p-0.5",children:i.map(a=>{const l=a.icon;return n.jsxs("button",{type:"button",onClick:()=>t(a.value),className:se("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:[n.jsx(l,{className:"size-3.5"}),a.label]},a.value)})})}function eQ({connection:e,resultLimit:t}){const s=X(),{sendToAgent:i}=Vt(),{tables:a,selectedTable:l,setSelectedTable:c,sample:u,tablesError:f,rowsError:h,loadingTables:p,loadingRows:g,limit:b,offset:x,canPrev:_,canNext:k,changePageSize:C,nextPage:E,prevPage:j}=$Z(e,t);function N(T){i({prompt:F2(e,T.table,{engine:T.engine,columns:T.columns}),source:{type:"database-table",label:`${T.table.name} table`},mode:"draft"})}function A(T){i({prompt:F2(e,T),source:{type:"database-table",label:`${T.name} table`},mode:"draft"})}return n.jsxs("div",{className:"flex h-full min-h-0",children:[n.jsxs("div",{className:"flex w-56 shrink-0 flex-col border-r border-border",children:[n.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[n.jsx(Xj,{className:"size-4 text-muted-foreground"}),n.jsx("span",{className:"text-sm font-semibold",children:s("database.tables")}),n.jsx(Ze,{variant:"outline",size:"small",children:a.length}),p?n.jsx(Bt,{className:"size-3.5 animate-spin"}):null]}),f?n.jsx("div",{className:"p-3",children:n.jsx(nt,{variant:"muted",className:"border-destructive/40 text-destructive",children:f})}):n.jsxs("ul",{className:"min-h-0 flex-1 overflow-auto",children:[a.map(T=>n.jsxs("li",{className:se("group flex items-center gap-1 pr-1 transition-colors hover:bg-muted/50",T.qualifiedName===l&&"bg-muted/70"),children:[n.jsx("button",{type:"button",onClick:()=>c(T.qualifiedName),className:se("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}),n.jsx(xr,{label:s("database.askAiAbout",{name:T.qualifiedName}),onAsk:()=>A(T)})]},T.qualifiedName)),!p&&a.length===0?n.jsx("li",{className:"px-3 py-2 text-xs text-muted-foreground",children:s("database.noTables")}):null]})]}),n.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[n.jsxs("div",{className:"group flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-2",children:[n.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[n.jsx("span",{className:"truncate font-mono text-xs font-semibold",children:l??s("database.selectTable")}),u?n.jsx(xr,{label:s("database.askAiAbout",{name:u.table.qualifiedName}),onAsk:()=>N(u)}):null]}),u?n.jsxs("div",{className:"flex shrink-0 items-center gap-2 text-[11px] text-muted-foreground",children:[n.jsx("span",{className:"tabular-nums",children:u.rowCount===0?s("database.noRows"):s("database.rowsRange",{from:x+1,to:x+u.rowCount})}),n.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:iR(t).map(T=>n.jsx("option",{value:T,children:s("database.perPage",{size:T})},T))}),n.jsx(Q,{size:"sm",variant:"outline",className:"h-6 px-2",onClick:j,disabled:!_,type:"button",children:s("database.prev")}),n.jsx(Q,{size:"sm",variant:"outline",className:"h-6 px-2",onClick:E,disabled:!k,type:"button",children:s("database.next")})]}):null]}),h?n.jsx("div",{className:"p-4",children:n.jsx(nt,{variant:"muted",className:"border-destructive/40 text-destructive",children:h})}):g?n.jsxs("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:[n.jsx(Bt,{className:"mr-2 size-4 animate-spin"}),s("database.loadingRows")]}):u?n.jsx(qZ,{connection:e,sample:u}):n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:s("database.pickTable")})]})]})}function tQ({onAdd:e,onAddWithAi:t}){const s=X();return n.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center",children:n.jsxs("div",{className:"max-w-sm",children:[n.jsx(hi,{className:"mx-auto size-8 text-muted-foreground/50"}),n.jsx("p",{className:"mt-3 text-sm font-medium",children:s("database.emptyTitle")}),n.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:[s("database.emptyBody1")," ",n.jsx("code",{children:".env"})," ",s("database.emptyBody2")]}),n.jsxs("div",{className:"mt-4 flex items-center justify-center gap-2",children:[n.jsxs(Q,{size:"sm",onClick:e,type:"button",children:[n.jsx(Es,{}),s("database.addConnection")]}),n.jsxs(Q,{size:"sm",variant:"outline",onClick:t,type:"button",children:[n.jsx(Sn,{}),s("database.addWithAi")]})]})]})})}const dr=[{id:"general",label:"General",description:"Language, navigation, and startup context.",icon:y8,scope:"global",keywords:["language","sidebar","dock","agent","project scope"]},{id:"appearance",label:"Appearance",description:"Theme, density, type size, and motion.",icon:qj,scope:"global",keywords:["theme","dark","light","font","motion","accent","color","colour"]},{id:"terminal",label:"Terminal",description:"Terminal rendering and process safeguards.",icon:wr,scope:"global",keywords:["shell","cursor","scrollback","copy","terminate"]},{id:"services-logs",label:"Services & Logs",description:"How this project presents runtime output.",icon:hm,scope:"project",keywords:["timestamps","wrap","runtime","services"]},{id:"git-github",label:"Git & GitHub",description:"Source-control preferences and connection status.",icon:Mn,scope:"mixed",keywords:["git","github","co-author","repository"]},{id:"agents-mcp",label:"Agents & MCP",description:"Agent environments and MCP management.",icon:sm,scope:"mixed",keywords:["agent","model","mcp","claude","codex"]},{id:"database-safety",label:"Database & Safety",description:"Project query limits and write safeguards.",icon:hi,scope:"project",keywords:["database","sql","danger confirmation","writes","limit"]},{id:"notifications",label:"Notifications",description:"Browser notification capability and permission.",icon:I6,scope:"global",keywords:["alerts","desktop","permission"]},{id:"data-privacy",label:"Data & Privacy",description:"Local storage, export, reset, and privacy.",icon:Wj,scope:"mixed",keywords:["data","privacy","export","reset","storage"]},{id:"about",label:"About",description:"Version, runtime, documentation, and support.",icon:b8,scope:"global",keywords:["version","docs","runtime","issues"]}],aR={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."},"agent-dock-placement":{category:"general",label:"Agent dock position",description:"Place the agent workspace along the bottom or right edge."},"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."},accent:{category:"appearance",label:"Accent color",description:"Recolor the workbench, globally or per project."},"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 sQ(e){const t=aR[e];if(!t)throw new Error(`Missing settings copy for "${e}".`);return t}function oR(e){return`settingsHub.item.${e}.label`}function lR(e){return`settingsHub.item.${e}.desc`}function Nu(e){return`settingsHub.cat.${e}.label`}function nQ(e){return`settingsHub.cat.${e}.desc`}const iQ=Object.keys(aR);function rQ(e,t,s){const i=cR(e),a=t.trim().toLowerCase().split(/\s+/).filter(Boolean);return iQ.filter(l=>{const c=sQ(l);if(c.category!==e)return!1;const u=s?` ${s(Nu(e))} ${s(oR(l))} ${s(lR(l))}`:"",f=`${i.label} ${i.description} ${i.keywords.join(" ")} ${c.label} ${c.description}${u}`.toLowerCase();return a.every(h=>f.includes(h))})}function cR(e){return dr.find(t=>t.id===e)??dr[0]}function aQ({scope:e}){const t=X();return n.jsx("span",{className:se("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 oQ({state:e,error:t}){const s=X();return e==="idle"?null:n.jsxs("div",{"aria-live":"polite",className:se("flex items-center gap-1.5 text-xs",e==="error"?"text-destructive":"text-muted-foreground"),children:[e==="saving"?n.jsx(Bt,{className:"size-3.5 animate-spin"}):null,e==="saved"?n.jsx(rn,{className:"size-3.5 text-emerald-600"}):null,e==="error"?n.jsx(im,{className:"size-3.5"}):null,n.jsx("span",{children:e==="saving"?s("settingsHub.saving"):e==="saved"?s("settingsHub.saved"):t})]})}function Iu({id:e,label:t,description:s,children:i,disabled:a=!1}){return n.jsxs("div",{className:se("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:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("label",{className:"text-sm font-medium",htmlFor:e,children:t}),n.jsx("p",{className:"mt-0.5 max-w-xl text-xs leading-5 text-muted-foreground",id:`${e}-description`,children:s})]}),n.jsx("div",{className:"min-w-0 sm:justify-self-end",children:i})]})}function go({id:e,label:t,description:s,checked:i,onChange:a,disabled:l=!1}){return n.jsx(Iu,{description:s,disabled:l,id:e,label:t,children:n.jsx("input",{"aria-describedby":`${e}-description`,checked:i,className:"size-4 accent-foreground",disabled:l,id:e,onChange:c=>a(c.target.checked),type:"checkbox"})})}function Nl({id:e,label:t,description:s,value:i,options:a,onChange:l,disabled:c=!1}){return n.jsx(Iu,{description:s,disabled:c,id:e,label:t,children:n.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:u=>l(u.target.value),value:i,children:a.map(u=>n.jsx("option",{disabled:u.disabled,value:u.value,children:u.label},u.value))})})}function Fh({id:e,label:t,description:s,value:i,min:a,max:l,onSave:c,disabled:u=!1,scopeKey:f}){const h=X(),{isPending:p,runOperation:g}=Yn(),[b,x]=v.useState(String(i)),[_,k]=v.useState(null),C=`settings:${f??"global"}:${e}:save`,E=p(C);v.useEffect(()=>{x(String(i)),k(null)},[f,i]);async function j(){const N=Number(b);if(!Number.isInteger(N)||N<a||N>l){k(h("settingsHub.numberRange",{min:a,max:l}));return}k(null);try{await g({key:C,label:h("settingsHub.savingSetting",{label:t})},async()=>c(N))}catch(A){k(A instanceof Error?A.message:String(A))}}return n.jsx(Iu,{description:s,disabled:u,id:e,label:t,children:n.jsxs("div",{className:"flex flex-col items-start gap-1 sm:items-end",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(St,{"aria-describedby":`${e}-description${_?` ${e}-error`:""}`,"aria-invalid":!!_,className:"h-8 w-24 font-mono text-xs",disabled:u,id:e,max:l,min:a,onChange:N=>x(N.target.value),type:"number",value:b}),n.jsx(Q,{"aria-label":h("settingsHub.saveAria",{label:t}),disabled:u,loading:E,loadingLabel:h("settingsHub.saving"),onClick:()=>{j()},size:"sm",type:"button",variant:"outline",children:h("settingsHub.save")})]}),_?n.jsx("span",{className:"text-[11px] text-destructive",id:`${e}-error`,role:"alert",children:_}):null]})})}function Da({title:e,description:t,action:s}){return n.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:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"text-sm font-medium",children:e}),n.jsx("p",{className:"mt-0.5 break-words text-xs leading-5 text-muted-foreground",children:t})]}),s?n.jsx("div",{className:"w-full shrink-0 [&_button]:w-full sm:w-auto sm:[&_button]:w-auto",children:s}):null]})}function lQ({children:e}){return n.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 cQ({selected:e,onSelect:t,search:s,onSearch:i,saveState:a,saveError:l,children:c}){const u=X(),f=v.useRef([]),h=cR(e),p=h.icon;function g(b,x){let _=null;if(b.key==="ArrowDown"&&(_=(x+1)%dr.length),b.key==="ArrowUp"&&(_=(x-1+dr.length)%dr.length),b.key==="Home"&&(_=0),b.key==="End"&&(_=dr.length-1),_===null)return;b.preventDefault();const k=dr[_];t(k.id),f.current[_]?.focus()}return n.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[n.jsxs("header",{className:"flex shrink-0 flex-wrap items-center gap-3 border-b border-border px-3 py-2.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Vj,{className:"size-4 text-muted-foreground"}),n.jsx("span",{className:"text-sm font-semibold",children:u("settingsHub.title")})]}),n.jsxs("div",{className:"relative ml-auto w-full sm:w-64",children:[n.jsx(Au,{className:"pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"}),n.jsx("input",{"aria-label":u("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=>i(b.target.value),placeholder:u("settingsHub.searchPlaceholder"),type:"search",value:s}),s?n.jsx("button",{"aria-label":u("settingsHub.clearSearch"),className:"absolute right-1.5 top-1/2 -translate-y-1/2 rounded p-1 text-muted-foreground hover:bg-muted",onClick:()=>i(""),type:"button",children:n.jsx(Gt,{className:"size-3"})}):null]}),n.jsx(oQ,{error:l,state:a})]}),n.jsxs("div",{className:"border-b border-border px-3 py-2 md:hidden",children:[n.jsx("label",{className:"mb-1 block text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",htmlFor:"settings-category-select",children:u("settingsHub.category")}),n.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:dr.map(b=>n.jsx("option",{value:b.id,children:u(Nu(b.id))},b.id))})]}),n.jsxs("div",{className:"flex min-h-0 flex-1",children:[n.jsx("aside",{className:"hidden w-56 shrink-0 border-r border-border bg-muted/20 p-2 md:block",children:n.jsx("nav",{"aria-label":u("settingsHub.categoriesAria"),className:"space-y-0.5",children:dr.map((b,x)=>{const _=b.icon,k=e===b.id;return n.jsxs("button",{"aria-current":k?"page":void 0,className:se("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",k?"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=>g(C,x),ref:C=>{f.current[x]=C},tabIndex:k?0:-1,type:"button",children:[n.jsx(_,{className:"size-3.5"}),n.jsx("span",{children:u(Nu(b.id))})]},b.id)})})}),n.jsx("main",{className:"min-w-0 flex-1 overflow-y-auto",children:n.jsxs("div",{className:"mx-auto max-w-3xl px-3 py-4 sm:px-6 sm:py-6",children:[s?null:n.jsxs("div",{className:"mb-4",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(p,{className:"size-4 text-muted-foreground"}),n.jsx("h2",{className:"text-base font-semibold",children:u(Nu(h.id))})]}),n.jsx("p",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:u(nQ(h.id))})]}),c]})})]})]})}const uR="linear-gradient(to right, hsl(0 70% 50%), hsl(60 70% 50%), hsl(120 70% 45%), hsl(180 60% 45%), hsl(240 62% 55%), hsl(300 62% 52%), hsl(360 70% 50%))";function xN({color:e,selected:t,title:s,rainbow:i,onClick:a}){return n.jsx("button",{"aria-label":s,"aria-pressed":t,className:se("grid size-6 place-items-center rounded-full ring-offset-2 ring-offset-background transition",t?"ring-2 ring-ring":"ring-1 ring-border hover:ring-foreground/40"),onClick:a,style:{background:i?uR:e},title:s,type:"button",children:t?n.jsx(rn,{className:"size-3.5 text-white drop-shadow-[0_1px_1px_rgba(0,0,0,0.5)]"}):null})}function yN({value:e,onChange:t}){const s=X(),i=O1(e),a=i!==null;return n.jsxs("div",{className:"flex flex-col items-start gap-2 sm:items-end",children:[n.jsxs("div",{className:"flex flex-wrap items-center justify-start gap-1.5 sm:justify-end",children:[QT.map(l=>n.jsx(xN,{color:l.swatch,onClick:()=>t(l.id),selected:e===l.id,title:s(l.labelKey)},l.id)),n.jsx(xN,{color:uZ(a?e:"custom:265"),onClick:()=>t(a?e:"custom:265"),rainbow:!a,selected:a,title:s("settingsHub.accent.custom")})]}),a?n.jsx("input",{"aria-label":s("settingsHub.accent.hue"),className:"h-2 w-44 cursor-pointer appearance-none rounded-full outline-none",max:359,min:0,onChange:l=>t(`custom:${l.target.value}`),style:{background:uR},type:"range",value:i??0}):null]})}function uQ({ui:e,updateUi:t,activeProject:s}){const i=X(),a=s?.path??null,l=a?e.projectAccents[a]:void 0,c=l!==void 0,u=f=>{if(!a)return;const h={...e.projectAccents};f===null?delete h[a]:h[a]=f,t({projectAccents:h})};return n.jsxs(n.Fragment,{children:[n.jsx(Iu,{description:i("settingsHub.accent.description"),id:"setting-accent",label:i("settingsHub.accent.label"),children:n.jsx(yN,{onChange:f=>t({accent:f}),value:e.accent})}),s?n.jsx(Iu,{description:i("settingsHub.accent.projectDescription"),id:"setting-project-accent",label:i("settingsHub.accent.projectLabel",{name:s.name}),children:n.jsxs("div",{className:"flex flex-col items-start gap-2 sm:items-end",children:[n.jsxs("div",{className:"inline-flex rounded-md border border-input p-0.5 text-xs",children:[n.jsx("button",{className:se("rounded px-2 py-1 transition-colors",c?"text-muted-foreground hover:text-foreground":"bg-muted font-medium text-foreground"),onClick:()=>u(null),type:"button",children:i("settingsHub.accent.useGlobal")}),n.jsx("button",{className:se("rounded px-2 py-1 transition-colors",c?"bg-muted font-medium text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>u(l??e.accent),type:"button",children:i("settingsHub.accent.override")})]}),c?n.jsx(yN,{onChange:u,value:l??e.accent}):null]})}):null]})}function ci({scope:e,title:t,children:s}){const i=X();return n.jsxs("section",{className:"mb-4 overflow-hidden rounded-lg border border-border bg-background/70",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border bg-muted/25 px-4 py-2.5",children:[n.jsx("h3",{className:"text-xs font-semibold",children:t??i(e==="global"?"settingsHub.global":"settingsHub.currentProject")}),n.jsx(aQ,{scope:e})]}),s]})}function tu({project:e,ready:t,loadError:s,onRetry:i}){const a=X();return e&&s?n.jsxs("div",{className:"border-b border-destructive/30 bg-destructive/5 px-4 py-3",role:"alert",children:[n.jsx("p",{className:"text-xs text-destructive",children:s}),n.jsx(Q,{"aria-label":a("settingsHub.retryProject"),className:"mt-2",onClick:i,size:"sm",type:"button",variant:"outline",children:a("settingsHub.retryProject")})]}):e&&!t?n.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?n.jsxs("div",{className:"border-b border-border/50 bg-amber-500/5 px-4 py-2 text-[11px] text-muted-foreground",children:[n.jsx("span",{className:"font-medium text-foreground",children:e.name})," · ",a("settingsHub.projectWritesPre"),n.jsx("code",{children:"nomoreide.config.json"}),a("settingsHub.projectWritesPost")]}):n.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 dQ({activeProject:e=null,onNavigate:t}={}){const s=X(),i=Lm(),a=!!(e?.path&&e.path===i.activeProjectPath&&!i.projectLoading&&!i.projectLoadError),[l,c]=v.useState("general"),[u,f]=v.useState(""),h=u.trim().toLowerCase(),p=v.useMemo(()=>h?dr.map(b=>({id:b.id,settingIds:rQ(b.id,h,s)})).filter(b=>b.settingIds.length>0):[],[h,s]);let g;return i.loading?g=n.jsx("div",{"aria-label":s("settingsHub.loadingAria"),className:"space-y-3",role:"status",children:[0,1,2].map(b=>n.jsx("div",{className:"h-20 animate-pulse rounded-lg border border-border bg-muted/40"},b))}):i.loadError?g=n.jsxs("div",{className:"rounded-lg border border-destructive/30 bg-destructive/5 p-4",role:"alert",children:[n.jsx("p",{className:"text-sm font-medium",children:s("settingsHub.loadFailed")}),n.jsx("p",{className:"mt-1 text-xs text-destructive",children:i.loadError}),n.jsx(Q,{className:"mt-3",onClick:()=>{i.retry()},size:"sm",type:"button",variant:"outline",children:s("settingsHub.retry")})]}):h?g=n.jsxs("div",{children:[n.jsx("h2",{className:"mb-4 text-base font-semibold",children:s("settingsHub.searchResults")}),p.length?p.map(({id:b,settingIds:x})=>n.jsxs("div",{className:"mb-5",children:[n.jsx("div",{className:"mb-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:s(Nu(b))}),n.jsx(_N,{activeProject:e,category:b,onNavigate:t,projectReady:a,settings:i,visibleSettingIds:new Set(x)})]},b)):n.jsx(lQ,{children:s("settingsHub.noMatches",{query:u.trim()})})]}):g=n.jsx(_N,{activeProject:e,category:l,onNavigate:t,projectReady:a,settings:i}),n.jsx(cQ,{onSearch:f,onSelect:c,saveError:i.saveError,saveState:i.saveState,search:u,selected:l,children:g})}function _N({category:e,activeProject:t,projectReady:s,onNavigate:i,settings:a,visibleSettingIds:l}){const c=X(),u=!s,f=g=>!l||l.has(g),h=g=>g.some(f),p=g=>({label:c(oR(g)),description:c(lR(g))});switch(e){case"general":return n.jsxs(ci,{scope:"global",children:[f("language")?n.jsx(Nl,{...p("language"),id:"setting-language",onChange:g=>a.updateUi({language:g}),options:BU.map(g=>({value:g.value,label:g.nativeLabel,disabled:!g.available})),value:a.ui.language}):null,f("sidebar-docked")?n.jsx(go,{...p("sidebar-docked"),checked:a.ui.sidebarDocked,id:"setting-sidebar-docked",onChange:g=>a.updateUi({sidebarDocked:g})}):null,f("agent-dock-placement")?n.jsx(Nl,{...p("agent-dock-placement"),id:"setting-agent-dock-placement",onChange:g=>a.updateUi({agentDockPlacement:g}),options:[{value:"bottom",label:c("settingsHub.opt.bottom")},{value:"right",label:c("settingsHub.opt.right")}],value:a.ui.agentDockPlacement}):null,f("project-scope")?n.jsx(Nl,{...p("project-scope"),id:"setting-project-scope",onChange:g=>a.updateUi({projectScope:g}),options:[{value:"all",label:c("settingsHub.opt.allProjects")},{value:"project",label:c("settingsHub.currentProject")}],value:a.ui.projectScope}):null]});case"appearance":return n.jsxs(ci,{scope:"global",children:[f("theme")?n.jsx(Nl,{...p("theme"),id:"setting-theme",onChange:g=>a.updateUi({theme:g}),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")?n.jsx(Nl,{...p("density"),id:"setting-density",onChange:g=>a.updateUi({density:g}),options:[{value:"comfortable",label:c("settingsHub.opt.comfortable")},{value:"compact",label:c("settingsHub.opt.compact")}],value:a.ui.density}):null,f("code-font")?n.jsx(Fh,{...p("code-font"),id:"setting-code-font",max:18,min:10,onSave:g=>{a.updateUi({codeFontSize:g})},value:a.ui.codeFontSize}):null,f("reduced-motion")?n.jsx(go,{...p("reduced-motion"),checked:a.ui.reducedMotion,id:"setting-reduced-motion",onChange:g=>a.updateUi({reducedMotion:g})}):null,f("accent")?n.jsx(uQ,{activeProject:t?.path?{name:t.name,path:t.path}:null,ui:a.ui,updateUi:a.updateUi}):null]});case"terminal":return n.jsxs(ci,{scope:"global",children:[f("terminal-font")?n.jsx(Fh,{...p("terminal-font"),id:"setting-terminal-font",max:24,min:10,onSave:g=>a.updateGlobal({terminal:{fontSize:g}}),value:a.global.terminal.fontSize}):null,f("cursor")?n.jsx(Nl,{...p("cursor"),id:"setting-cursor",onChange:g=>{a.updateGlobal({terminal:{cursorStyle:g}})},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")?n.jsx(Fh,{...p("scrollback"),id:"setting-scrollback",max:1e5,min:500,onSave:g=>a.updateGlobal({terminal:{scrollback:g}}),value:a.global.terminal.scrollback}):null,f("copy-on-select")?n.jsx(go,{...p("copy-on-select"),checked:a.global.terminal.copyOnSelect,id:"setting-copy-on-select",onChange:g=>{a.updateGlobal({terminal:{copyOnSelect:g}})}}):null,f("confirm-terminate")?n.jsx(go,{...p("confirm-terminate"),checked:a.global.terminal.confirmTerminate,id:"setting-confirm-terminate",onChange:g=>{a.updateGlobal({terminal:{confirmTerminate:g}})}}):null]});case"services-logs":return n.jsxs(ci,{scope:"project",children:[n.jsx(tu,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),f("log-timestamps")?n.jsx(go,{...p("log-timestamps"),checked:a.project.logs.showTimestamps,disabled:u,id:"setting-log-timestamps",onChange:g=>{a.updateProject({logs:{showTimestamps:g}})}}):null,f("wrap-lines")?n.jsx(go,{...p("wrap-lines"),checked:a.project.logs.wrapLines,disabled:u,id:"setting-wrap-lines",onChange:g=>{a.updateProject({logs:{wrapLines:g}})}}):null]});case"git-github":return n.jsxs(n.Fragment,{children:[h(["github-connection"])?n.jsx(ci,{scope:"global",children:n.jsx(Da,{action:n.jsx(Q,{onClick:()=>i?.("github"),size:"sm",type:"button",variant:"outline",children:c("settingsHub.manageGitHub")}),description:p("github-connection").description,title:p("github-connection").label})}):null,h(["repository-defaults"])?n.jsxs(ci,{scope:"project",children:[n.jsx(tu,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),n.jsx(Da,{description:p("repository-defaults").description,title:p("repository-defaults").label})]}):null]});case"agents-mcp":return n.jsxs(n.Fragment,{children:[h(["agent-environments"])?n.jsx(ci,{scope:"global",children:n.jsx(Da,{action:n.jsx(Q,{onClick:()=>i?.("agent-env"),size:"sm",type:"button",variant:"outline",children:c("settingsHub.openAgentEnv")}),description:p("agent-environments").description,title:p("agent-environments").label})}):null,h(["project-agent-context"])?n.jsxs(ci,{scope:"project",children:[n.jsx(tu,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),n.jsx(Da,{description:p("project-agent-context").description,title:p("project-agent-context").label})]}):null]});case"database-safety":return n.jsxs(ci,{scope:"project",children:[n.jsx(tu,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),f("confirm-writes")?n.jsx(go,{...p("confirm-writes"),checked:a.project.database.confirmWrites,disabled:u,id:"setting-confirm-writes",onChange:g=>{a.updateProject({database:{confirmWrites:g}})}}):null,f("result-limit")?n.jsx(Fh,{...p("result-limit"),disabled:u,id:"setting-result-limit",max:5e3,min:10,onSave:g=>a.updateProject({database:{resultLimit:g}}),scopeKey:a.activeProjectPath,value:a.project.database.resultLimit}):null,f("connections")?n.jsx(Da,{action:n.jsx(Q,{disabled:u,onClick:()=>i?.("database"),size:"sm",type:"button",variant:"outline",children:c("settingsHub.openDatabase")}),description:p("connections").description,title:p("connections").label}):null]});case"notifications":{const g=typeof Notification>"u"?c("settingsHub.notifUnavailable"):c("settingsHub.notifPermission",{value:Notification.permission});return n.jsx(ci,{scope:"global",children:f("desktop-notifications")?n.jsx(Da,{action:n.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:g}),description:p("desktop-notifications").description,title:p("desktop-notifications").label}):null})}case"data-privacy":return n.jsxs(n.Fragment,{children:[h(["local-storage"])?n.jsx(ci,{scope:"global",children:n.jsx(Da,{description:p("local-storage").description,title:p("local-storage").label})}):null,h(["export-reset"])?n.jsxs(ci,{scope:"project",children:[n.jsx(tu,{loadError:a.projectLoadError,onRetry:()=>{a.retryProject()},project:t,ready:s}),n.jsx(Da,{description:p("export-reset").description,title:p("export-reset").label})]}):null]});case"about":return n.jsx(ci,{scope:"global",children:n.jsxs("div",{className:"grid grid-cols-[auto_1fr] gap-x-5 gap-y-2 px-4 py-4 text-xs",children:[f("version")?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-muted-foreground",children:p("version").label}),n.jsxs("code",{children:["v","0.1.93"]})]}):null,f("console")?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-muted-foreground",children:p("console").label}),n.jsx("code",{children:"127.0.0.1:4317"})]}):null,f("documentation")?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-muted-foreground",children:p("documentation").label}),n.jsxs("a",{className:"inline-flex items-center gap-1 text-primary hover:underline",href:"https://www.nomoreide.com/docs",rel:"noreferrer",target:"_blank",children:[n.jsx(jj,{className:"size-3"}),"nomoreide.com/docs",n.jsx(Xr,{className:"size-3"})]})]}):null]})})}}function hQ(e,t){const s=t.trim().toLocaleLowerCase();return s?[e.service,e.title,e.file??"",...e.logExcerpt].some(i=>i.toLocaleLowerCase().includes(s)):!0}function fQ(e,t,s){const i=new Set(s.levels),a=new Set(s.services);return e.filter(l=>hQ(l,t)&&(i.size===0||i.has(l.level))&&(a.size===0||a.has(l.service)))}function mQ(e){return{levels:[...new Set(e.map(({level:t})=>t))].sort(),services:[...new Set(e.map(({service:t})=>t))].sort()}}function pQ(e){return e.levels.length+e.services.length}function gQ({detailId:e,incident:t,onReviewChanges:s}){const i=X(),{sendToAgent:a}=Vt(),{isPending:l,runOperation:c}=Yn(),u=`error:${t.id}:fix`,f=l(u),[h,p]=v.useState(null);async function g(){await c({errorMessage:b=>b instanceof Error?b.message:String(b),key:u,label:i("errors.incident.fixingOperation",{service:t.service})},async()=>{const{prompt:b,sessionId:x}=await ZP(t.id);a({prompt:b,source:{type:"error",label:`${t.service} — ${t.level}`},label:i("errors.incident.fixLabel",{level:t.level,service:t.service,title:t.title})}),p(x)})}return n.jsxs("div",{className:"min-w-0 rounded-lg border border-border bg-background","data-incident-detail":"true",id:e,children:[n.jsxs("div",{className:"px-4 py-3",children:[n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(Ze,{variant:t.level==="error"?"danger":"secondary",appearance:"subtle",size:"small",children:i(t.level==="error"?"errors.level.error":"errors.level.warning")}),n.jsx("span",{className:"truncate font-mono text-xs font-semibold",children:t.service}),t.count>1?n.jsxs(Ze,{variant:"outline",size:"small",children:["×",t.count]}):null]}),n.jsxs(Q,{loading:f,loadingLabel:i("errors.incident.starting"),onClick:()=>{g().catch(()=>{})},size:"sm",variant:"outline",children:[n.jsx(cs,{className:"size-3.5"}),i("errors.incident.fixWithAi")]})]}),n.jsx("p",{className:"mt-1.5 break-words font-mono text-xs text-foreground",children:t.title}),t.file?n.jsxs("p",{className:"mt-1 flex items-center gap-1.5 font-mono text-[11px] text-muted-foreground",children:[n.jsx(zj,{className:"size-3.5"}),t.file,t.line?`:${t.line}`:""]}):null,n.jsx("p",{className:"mt-1 font-mono text-[10px] text-muted-foreground/80",children:i("errors.incident.firstLast",{first:new Date(t.firstSeen).toLocaleString(),last:new Date(t.lastSeen).toLocaleTimeString()})})]}),n.jsxs("div",{className:"border-t border-border p-4",children:[h?n.jsx(nt,{variant:"muted",className:"mb-3",children:n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[n.jsx("span",{className:"text-xs",children:i("errors.incident.working")}),s?n.jsxs(Q,{onClick:()=>s(h),size:"sm",variant:"outline",children:[n.jsx(Pj,{className:"size-3.5"}),i("errors.incident.reviewChanges")]}):null]})}):null,n.jsx("p",{className:"mb-1.5 text-xs font-medium text-muted-foreground",children:i("errors.incident.logExcerpt")}),n.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(`
|
|
120
120
|
`)}),n.jsx("p",{className:"mt-3 text-[11px] text-muted-foreground",children:i("errors.incident.explain")})]})]})}function bQ({activeCount:e,levels:t,onClear:s,onToggleLevel:i,onToggleService:a,open:l,query:c,reduceMotion:u,selectedLevels:f,selectedServices:h,services:p}){const g=X(),b=u?{duration:0}:{duration:.16};return n.jsx(EF,{initial:!1,children:l?n.jsxs(Ro.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:[n.jsx(wN,{format:x=>g(x==="error"?"errors.level.error":"errors.level.warning"),label:g("errors.filterSeverity"),onToggle:i,options:t,selected:f}),n.jsx(wN,{format:x=>x,label:g("errors.filterService"),onToggle:a,options:p,selected:h}),n.jsx(Q,{disabled:e===0&&!c,onClick:s,size:"sm",type:"button",variant:"ghost",children:g("errors.clearFilters")})]}):null})}function wN({format:e,label:t,onToggle:s,options:i,selected:a}){return n.jsxs("fieldset",{children:[n.jsx("legend",{className:"mb-2 text-xs font-semibold",children:t}),n.jsx("div",{className:"flex flex-wrap gap-1.5",children:i.map(l=>{const c=a.includes(l);return n.jsx(Q,{"aria-pressed":c,onClick:()=>s(l),size:"sm",type:"button",variant:c?"secondary":"outline",children:e(l)},l)})})]})}function SN(e,t){return e.includes(t)?e.filter(s=>s!==t):[...e,t]}function vQ({connected:e,error:t,incidents:s,onReviewChanges:i}){const[a,l]=v.useState(""),[c,u]=v.useState(()=>({levels:[],services:[]})),[f,h]=v.useState(!1),[p,g]=v.useState(null),b=OU(),x=X(),_=v.useMemo(()=>mQ(s),[s]),k=v.useMemo(()=>fQ(s,a,c),[c,s,a]),C=pQ(c),E=()=>{l(""),u({levels:[],services:[]})},j=b?{duration:0}:{duration:.16};return n.jsxs("section",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[n.jsxs("header",{className:"flex shrink-0 flex-wrap items-center justify-between gap-2 border-b border-border px-4 py-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx($u,{className:"size-4 text-muted-foreground"}),n.jsx("h2",{className:"text-sm font-semibold",children:x("errors.incidents")}),n.jsx(Ze,{appearance:"outline",size:"small",variant:"outline",children:x("errors.summary",{count:s.length})})]}),n.jsx(Ze,{appearance:"outline",icon:n.jsx("span",{className:se("inline-block size-1.5 rounded-full",e?"animate-pulse bg-emerald-500":"bg-muted-foreground/60")}),size:"small",variant:"outline",children:x(e?"errors.live":"errors.reconnecting")})]}),n.jsxs("div",{className:"shrink-0 border-b border-border px-4 py-3",children:[n.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",children:[n.jsxs("div",{className:"relative min-w-0 flex-1",children:[n.jsx(Au,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),n.jsx(St,{"aria-label":x("errors.searchAria"),className:"pl-9",onChange:N=>l(N.target.value),placeholder:x("errors.searchPlaceholder"),type:"search",value:a})]}),n.jsxs(Q,{"aria-expanded":f,"aria-label":x(f?"errors.hideFilters":"errors.showFilters"),onClick:()=>h(N=>!N),size:"sm",type:"button",variant:"outline",children:[n.jsx($L,{}),x("errors.filters"),C>0?n.jsx(Ze,{appearance:"solid",size:"small",variant:"primary",children:C}):null]})]}),n.jsx(bQ,{activeCount:C,levels:_.levels,onClear:E,onToggleLevel:N=>u(A=>({...A,levels:SN(A.levels,N)})),onToggleService:N=>u(A=>({...A,services:SN(A.services,N)})),open:f,query:a,reduceMotion:b,selectedLevels:c.levels,selectedServices:c.services,services:_.services}),n.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:x("errors.resultCount",{shown:k.length,total:s.length})})]}),t?n.jsx("div",{className:"shrink-0 px-4 pt-3",children:n.jsx(nt,{className:"border-destructive/40 text-destructive",variant:"muted",children:x("errors.loadFailed",{error:t})})}):null,n.jsx("div",{className:"min-h-0 flex-1 overflow-auto p-2 sm:p-4",children:s.length===0?n.jsx(kN,{body:x("errors.emptyBody"),title:x("errors.emptyTitle")}):k.length===0?n.jsx(kN,{body:x("errors.noMatchesBody"),title:x("errors.noMatchesTitle"),children:n.jsx(Q,{onClick:E,size:"sm",type:"button",variant:"outline",children:x("errors.clearFilters")})}):n.jsxs("table",{"aria-label":x("errors.tableAria"),className:"w-full table-fixed border-collapse",children:[n.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:n.jsxs("tr",{children:[n.jsx("th",{className:"w-24 px-3 py-2",scope:"col",children:x("errors.columnSeverity")}),n.jsx("th",{className:"w-36 px-3 py-2",scope:"col",children:x("errors.columnLatest")}),n.jsx("th",{className:"w-28 px-3 py-2",scope:"col",children:x("errors.columnService")}),n.jsx("th",{className:"px-3 py-2",scope:"col",children:x("errors.columnIncident")}),n.jsx("th",{className:"w-20 px-3 py-2",scope:"col",children:x("errors.columnCount")}),n.jsx("th",{className:"w-48 px-3 py-2",scope:"col",children:x("errors.columnSource")}),n.jsx("th",{className:"w-10 px-2 py-2",scope:"col",children:n.jsx("span",{className:"sr-only",children:x("errors.columnActions")})})]})}),n.jsx("tbody",{className:"divide-y divide-border",children:k.map(N=>{const A=N.id===p,T=`incident-detail-${N.id}`;return n.jsxs(v.Fragment,{children:[n.jsxs("tr",{className:"transition-colors hover:bg-muted/40 motion-reduce:transition-none","data-incident-id":N.id,children:[n.jsx("td",{className:"w-24 px-2 py-3 align-middle md:px-3",children:n.jsx(Ze,{appearance:"subtle",size:"small",variant:N.level==="error"?"danger":"warning",children:x(N.level==="error"?"errors.level.error":"errors.level.warning")})}),n.jsx("td",{className:"hidden px-3 py-3 align-middle font-mono text-[11px] text-muted-foreground md:table-cell",children:new Date(N.lastSeen).toLocaleString()}),n.jsx("td",{className:"hidden truncate px-3 py-3 align-middle font-mono text-xs font-semibold md:table-cell",children:N.service}),n.jsxs("td",{className:"min-w-0 px-2 py-3 align-middle md:px-3",children:[n.jsx("p",{className:"truncate text-xs font-medium",children:N.title}),n.jsxs("p",{className:"mt-0.5 truncate font-mono text-[10px] text-muted-foreground md:hidden",children:[N.service," · ",new Date(N.lastSeen).toLocaleString()]})]}),n.jsxs("td",{className:"hidden px-3 py-3 align-middle font-mono text-xs text-muted-foreground md:table-cell",children:["×",N.count]}),n.jsx("td",{className:"hidden truncate px-3 py-3 align-middle font-mono text-[11px] text-muted-foreground md:table-cell",children:N.file?`${N.file}${N.line?`:${N.line}`:""}`:x("common.none")}),n.jsx("td",{className:"w-10 px-2 py-3 align-middle",children:n.jsx(Q,{"aria-controls":T,"aria-expanded":A,"aria-label":x(A?"errors.collapseIncident":"errors.expandIncident",{title:N.title}),onClick:()=>g(A?null:N.id),size:"icon-sm",type:"button",variant:"ghost",children:n.jsx(kn,{className:se("transition-transform motion-reduce:transition-none",A&&"rotate-180")})})})]}),A?n.jsx("tr",{children:n.jsx("td",{className:"px-2 pb-3 md:px-3",colSpan:7,children:n.jsx(Ro.div,{animate:{opacity:1,y:0},initial:{opacity:0,y:b?0:-4},transition:j,children:n.jsx(gQ,{detailId:T,incident:N,onReviewChanges:i})})})}):null]},N.id)})})]})})]})}function kN({body:e,children:t,title:s}){return n.jsx("div",{className:"flex min-h-64 items-center justify-center p-8 text-center",children:n.jsxs("div",{className:"max-w-sm",children:[n.jsx($u,{className:"mx-auto size-8 text-muted-foreground/50"}),n.jsx("p",{className:"mt-3 text-sm font-medium",children:s}),n.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:e}),t?n.jsx("div",{className:"mt-4",children:t}):null]})})}function CN(e){return[...e].sort((t,s)=>t.lastSeen<s.lastSeen?1:t.lastSeen>s.lastSeen?-1:s.id-t.id)}function xQ(){const[e,t]=v.useState([]),[s,i]=v.useState(!1),[a,l]=v.useState(null),c=v.useCallback(u=>{t(f=>CN([...f.filter(h=>h.id!==u.id),u]))},[]);return v.useEffect(()=>{let u=!0;l3().then(h=>{u&&t(CN(h))}).catch(h=>{u&&l(h instanceof Error?h.message:String(h))});const f=new EventSource("/api/errors/stream");return f.addEventListener("open",()=>i(!0)),f.addEventListener("error",()=>i(!1)),f.addEventListener("incident",h=>{try{const p=JSON.parse(h.data);c(p)}catch{}}),()=>{u=!1,f.close()}},[c]),{incidents:e,connected:s,error:a}}function yQ({inScope:e,onReviewChanges:t}={}){const{incidents:s,connected:i,error:a}=xQ(),l=v.useMemo(()=>e?s.filter(c=>e(c.service)):s,[s,e]);return n.jsx(vQ,{connected:i,error:a,incidents:l,onReviewChanges:t})}function Ul({label:e}){return n.jsx(nt,{variant:"muted",className:"m-4 text-center",children:e})}const _Q=900*1e3,fu=12,$b=200;function wQ({events:e}){const t=X(),[s,i]=v.useState(null),[a,l]=v.useState(null),{rows:c,windowStart:u,windowEnd:f}=v.useMemo(()=>SQ(e),[e]),h=s?c.find(p=>p.service===s)??null:null;return n.jsxs(n.Fragment,{children:[n.jsxs(Di,{className:"rounded-none border-0 border-b border-border bg-transparent",children:[n.jsxs(Li,{className:"border-b border-border px-3 py-2",children:[n.jsxs(Oi,{className:"flex items-center gap-2",children:[n.jsx(jo,{className:"size-3.5"}),t("services.timeline.title")]}),n.jsx(Sr,{className:"text-xs",children:e.length===0?t("services.timeline.noEvents"):t("services.timeline.events",{count:e.length})})]}),n.jsx(Pi,{className:"p-0",children:c.length===0?n.jsx(Ul,{label:t("services.timeline.empty")}):n.jsxs("div",{className:"divide-y divide-border",children:[c.map(p=>n.jsx(CQ,{onClick:()=>i(p.service),row:p,windowEnd:f,windowStart:u},p.service)),n.jsxs("div",{className:"flex justify-between px-3 py-1.5 font-mono text-[10px] text-muted-foreground",children:[n.jsx("span",{children:Wf(u)}),n.jsx("span",{children:t("services.timeline.now")})]})]})})]}),h?n.jsx(Kn,{icon:n.jsx(jo,{}),onClose:()=>i(null),title:h.service,children:n.jsx(EQ,{onSelect:l,row:h})}):null,a?n.jsx(Kn,{icon:n.jsx(jo,{}),onClose:()=>l(null),title:a.title,children:n.jsx(jQ,{event:a})}):null]})}function SQ(e){const t=Date.now(),s=t,i=t-_Q;let a=e.filter(f=>{if(f.kind==="service.http")return!1;const h=new Date(f.timestamp).getTime();return!Number.isNaN(h)&&h>=i});a.length===0&&e.length>0?a=e.slice(-$b):a.length>$b&&(a=a.slice(-$b));const l=new Map;for(const f of a){const h=f.service||"·system",p=l.get(h)??[];p.push(f),l.set(h,p)}const c=Math.max(s-i,1);return{rows:Array.from(l.entries()).map(([f,h])=>{const p=[...h].sort((j,N)=>j.timestamp.localeCompare(N.timestamp)),g=new Array(fu).fill(0),b=new Array(fu).fill(null);for(const j of p){const N=new Date(j.timestamp).getTime(),A=Math.max(i,Math.min(s,N)),T=Math.min(fu-1,Math.floor((A-i)/c*fu));g[T]+=1;const D=b[T];b[T]=kQ(D,j.severity)}const x=p.filter(j=>j.severity==="error").length,_=p.filter(j=>j.severity==="warning").length,k=p.length-x-_,C=[...p].reverse().find(j=>j.severity!=="info")??null,E=x>0?"error":_>0?"warning":"info";return{service:f,events:p,errors:x,warnings:_,infos:k,buckets:g,bucketSeverity:b,lastNotable:C,worstSeverity:E}}).sort((f,h)=>{const p=b=>b.errors*1e3+b.warnings,g=p(h)-p(f);return g!==0?g:f.service.localeCompare(h.service)}),windowStart:i,windowEnd:s}}function kQ(e,t){return e==="error"||t==="error"?"error":e==="warning"||t==="warning"?"warning":"info"}function CQ({onClick:e,row:t,windowEnd:s,windowStart:i}){const a=X(),l=Math.max(1,...t.buckets);return n.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:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx("span",{className:se("size-2 shrink-0 rounded-full",dR(t.worstSeverity))}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-foreground",dir:"rtl",children:n.jsx("bdi",{children:t.service})}),t.errors>0?n.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?n.jsxs("span",{className:"rounded bg-amber-500/15 px-1 font-mono text-[10px] text-amber-500",children:[t.warnings,"W"]}):null,n.jsx(gn,{className:"size-3 text-muted-foreground"})]}),n.jsx("div",{className:"timeline-density mt-1.5 grid h-3 gap-px","data-testid":"timeline-density",style:{gridTemplateColumns:`repeat(${fu}, minmax(0, 1fr))`},children:t.buckets.map((c,u)=>n.jsx(NQ,{count:c,max:l,severity:t.bucketSeverity[u]},u))}),t.lastNotable?n.jsx("div",{className:"mt-1 truncate font-mono text-[10px] text-muted-foreground",children:t.lastNotable.detail??t.lastNotable.title}):n.jsx("div",{className:"mt-1 truncate text-[10px] text-muted-foreground",children:a("services.timeline.infoEvents",{count:t.infos})}),n.jsxs("div",{className:"mt-0.5 flex justify-between font-mono text-[9px] text-muted-foreground/60",children:[n.jsx("span",{children:Wf(i)}),n.jsx("span",{children:Wf(s)})]})]})}function NQ({count:e,max:t,severity:s}){const i=X();if(e===0)return n.jsx("span",{className:"rounded-sm bg-border/60"});const a=Math.min(1,.35+e/t*.65);return n.jsx("span",{className:se("rounded-sm",AQ(s)),style:{opacity:a},title:i("services.timeline.eventsCount",{count:e})})}function EQ({onSelect:e,row:t}){const s=X(),i=[...t.events].sort((a,l)=>l.timestamp.localeCompare(a.timestamp));return n.jsxs("div",{className:"flex max-h-[480px] flex-col overflow-hidden",children:[n.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-4 py-2 text-xs text-muted-foreground",children:[n.jsx("span",{children:s("services.timeline.eventsCount",{count:t.events.length})}),n.jsx("span",{children:"·"}),n.jsx("span",{children:s("services.timeline.errorsCount",{count:t.errors})}),n.jsx("span",{children:"·"}),n.jsx("span",{children:s("services.timeline.warningsCount",{count:t.warnings})})]}),n.jsx("ul",{className:"min-h-0 divide-y divide-border overflow-auto",children:i.map(a=>n.jsx("li",{children:n.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:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:se("size-2 shrink-0 rounded-full",dR(a.severity))}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-foreground",children:a.title}),n.jsx("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground",children:Wf(a.timestamp)})]}),a.detail?n.jsx("div",{className:"mt-1 truncate font-mono text-[10px] text-muted-foreground",children:a.detail}):null]})},a.id))})]})}function jQ({event:e}){const t=X(),s=new Date(e.timestamp);return n.jsxs("div",{className:"space-y-3 p-4 text-sm",children:[n.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n.jsx("span",{className:se("rounded px-1.5 py-0.5 font-mono text-[10px] uppercase text-white",TQ(e.severity)),children:e.severity}),n.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?n.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]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-xs text-muted-foreground",children:t("services.timeline.when")}),n.jsx("div",{className:"font-mono text-xs",children:Number.isNaN(s.getTime())?e.timestamp:s.toLocaleString()})]}),e.detail?n.jsxs("div",{children:[n.jsx("div",{className:"text-xs text-muted-foreground",children:t("services.timeline.detail")}),n.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 dR(e){return e==="error"?"bg-red-500":e==="warning"?"bg-amber-500":"bg-zinc-400"}function AQ(e){return e==="error"?"bg-red-500":e==="warning"?"bg-amber-500":"bg-zinc-500"}function TQ(e){return e==="error"?"bg-red-600":e==="warning"?"bg-amber-600":"bg-zinc-700"}function Wf(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 b0=150,zl=40,NN=200,EN=64,Uh=20;function RQ({statuses:e,health:t,hasDependencies:s,onSelectService:i}){const a=X(),[l,c]=v.useState(null),[u,f]=v.useState(null);v.useEffect(()=>{let g=!0;return W9().then(b=>{g&&c(b)}).catch(b=>{g&&f(b instanceof Error?b.message:String(b))}),()=>{g=!1}},[]);const h=v.useMemo(()=>l?MQ(l.nodes):null,[l]);if(u)return n.jsx(nt,{variant:"destructive",children:a("services.graph.loadError",{error:u})});if(!l||!h)return n.jsxs("div",{className:"flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground",children:[n.jsx(Bt,{className:"size-4 animate-spin"}),a("services.graph.loading")]});if(!s)return n.jsx("div",{className:"grid gap-3",children:n.jsxs(nt,{variant:"muted",children:[n.jsx("div",{className:"font-medium",children:a("services.graph.noDeps")}),n.jsxs("div",{className:"mt-1 text-xs",children:[a("services.graph.noDepsHint1")," ",n.jsx("span",{className:"font-medium",children:a("services.graph.dependencies")}),a("services.graph.noDepsHint2")]})]})});const p=l.nodes.filter(g=>g.missing.length>0);return n.jsxs("div",{className:"grid gap-3",children:[l.cycles.length>0?n.jsxs(nt,{variant:"destructive",children:[n.jsxs("div",{className:"flex items-center gap-1.5 font-medium",children:[n.jsx(Zi,{className:"size-4"}),a("services.graph.cycleDetected")]}),n.jsxs("div",{className:"mt-1 text-xs",children:[l.cycles.map(g=>g.join(" → ")).join("; "),". ",a("services.graph.cycleHint")]})]}):null,p.length>0?n.jsx(nt,{variant:"muted",children:n.jsx("div",{className:"text-xs",children:p.map(g=>n.jsxs("div",{children:[n.jsx("span",{className:"font-medium",children:g.name})," ",a(g.missing.length>1?"services.graph.dependsUnknownMany":"services.graph.dependsUnknownOne",{list:g.missing.join(", ")})]},g.name))})}):null,n.jsx("div",{className:"overflow-auto rounded-md border border-border bg-muted/20 p-2",children:n.jsxs("svg",{"aria-label":a("services.graph.aria"),height:h.height,role:"img",width:h.width,children:[h.edges.map(g=>n.jsx("path",{className:"fill-none stroke-border",d:g.path,strokeWidth:1.5},`${g.from}->${g.to}`)),h.nodes.map(g=>{const b=e[g.name],x=DQ(b?.state,t[g.name]?.status);return n.jsxs("g",{"aria-label":a("services.graph.selectAria",{name:g.name}),className:"cursor-pointer",onClick:()=>i(g.name),transform:`translate(${g.x}, ${g.y})`,children:[n.jsx("rect",{className:se("stroke-2",x.fill,x.stroke),height:zl,rx:6,width:b0}),n.jsx("circle",{className:x.dot,cx:14,cy:zl/2,r:4}),n.jsx("text",{className:"fill-foreground text-[11px] font-medium",dominantBaseline:"middle",x:26,y:zl/2,children:LQ(g.name)})]},g.name)})]})}),l.order.length>0?n.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[n.jsx("span",{className:"font-medium uppercase tracking-wide",children:a("services.graph.startOrder")})," ",l.order.join(" → ")]}):null]})}function MQ(e){const t=new Map(e.map(g=>[g.name,g.dependsOn])),s=new Map,i=new Set,a=g=>{const b=s.get(g);if(b!==void 0)return b;if(i.has(g))return 0;i.add(g);const x=t.get(g)??[],_=x.length===0?0:Math.max(...x.map(k=>a(k)+1));return i.delete(g),s.set(g,_),_};for(const g of e)a(g.name);const l=new Map,c=e.map(g=>{const b=s.get(g.name)??0,x=l.get(b)??0;return l.set(b,x+1),{...g,x:Uh+b*NN,y:Uh+x*EN}}),u=new Map(c.map(g=>[g.name,g])),f=c.flatMap(g=>g.dependsOn.flatMap(b=>{const x=u.get(b);if(!x)return[];const _=x.x+b0,k=x.y+zl/2,C=g.x,E=g.y+zl/2,j=(_+C)/2;return[{from:b,to:g.name,path:`M ${_} ${k} C ${j} ${k}, ${j} ${E}, ${C} ${E}`}]})),h=Math.max(0,...c.map(g=>s.get(g.name)??0)),p=Math.max(1,...l.values());return{nodes:c,edges:f,width:Uh*2+h*NN+b0,height:Uh*2+(p-1)*EN+zl}}function DQ(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 LQ(e,t=18){return e.length>t?`${e.slice(0,t-1)}…`:e}function OQ({onOnboardRepo:e,onOnboardWithAi:t,onCreateService:s,onCreateWithAi:i}){const a=X();return n.jsx("div",{className:"flex h-full min-h-0 items-center justify-center overflow-auto bg-card/85 p-6",children:n.jsxs("div",{className:"w-full max-w-xl space-y-6",children:[n.jsxs("div",{className:"space-y-2 text-center",children:[n.jsx("h2",{className:"text-xl font-semibold",children:a("services.firstRun.title")}),n.jsx("p",{className:"text-sm text-muted-foreground",children:a("services.firstRun.desc")})]}),n.jsxs("div",{className:"space-y-3",children:[n.jsx(jN,{icon:n.jsx(Mn,{className:"size-5"}),title:a("services.addFromGithub"),description:a("services.firstRun.githubDesc"),onClick:e,onAi:t,aiTitle:a("services.onboardWithAiHint")}),n.jsx(jN,{icon:n.jsx(Es,{className:"size-5"}),title:a("services.firstRun.createTitle"),description:a("services.firstRun.createDesc"),onClick:s,onAi:i,aiTitle:a("services.firstRun.createAiHint")})]})]})})}function jN({icon:e,title:t,description:s,onClick:i,onAi:a,aiTitle:l}){return n.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:[n.jsxs("button",{className:"flex flex-1 items-start gap-3 px-4 py-4 text-left hover:bg-muted/60",onClick:i,type:"button",children:[n.jsx("span",{className:"mt-0.5 shrink-0 text-muted-foreground",children:e}),n.jsxs("span",{className:"min-w-0 space-y-1",children:[n.jsx("span",{className:"block text-sm font-semibold",children:t}),n.jsx("span",{className:"block text-xs text-muted-foreground",children:s})]})]}),n.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:[n.jsx(cs,{className:"size-4 shrink-0"}),"AI"]})]})}function PQ({health:e}){const t=X();if(!e)return null;const s=e.processTree,i=e.status==="healthy"||e.status==="unknown"?void 0:HQ(e.summary);return n.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:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsxs("span",{className:se("inline-flex h-7 shrink-0 items-center gap-1.5 rounded-md px-2.5 font-medium",zQ(e.status)),children:[n.jsx("span",{className:"inline-flex shrink-0",children:n.jsx(jo,{className:"size-3"})}),n.jsx("span",{className:"whitespace-nowrap",children:e.status})]}),i?n.jsx("span",{className:"min-w-0 truncate",children:i}):null]}),s?n.jsxs("div",{className:"health-metrics flex min-w-max items-center gap-2 font-mono sm:justify-end",children:[n.jsxs("span",{className:"inline-flex items-center gap-1 font-mono",children:[n.jsx(SD,{className:"size-3"}),s.processCount," ",s.processCount===1?t("services.process"):t("services.processes")]}),n.jsxs("span",{children:[IQ(s.cpuPercent)," CPU"]}),n.jsxs("span",{className:"inline-flex items-center gap-1 font-mono",children:[n.jsx(F8,{className:"size-3"}),BQ(s.rssMb)," RAM"]})]}):null]})}function zQ(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 BQ(e){return Number.isInteger(e)?`${e} MB`:`${e.toFixed(1)} MB`}function IQ(e){return`${e.toFixed(1)}%`}function HQ(e){return e.replace(/^Recent error log:\s*/i,"Recent stderr: ").replace(/:\s*\d+(?:\.\d+)? MB RSS\.?$/i,"").replace(/\s+RSS\.?$/i,"")}function $Q({ports:e}){const t=X(),s=e.filter(a=>a.state==="occupied").length,i=e.filter(a=>a.state==="managed").length;return n.jsxs(Di,{className:"rounded-none border-0 border-b border-border bg-transparent",children:[n.jsxs(Li,{className:"border-b border-border px-3 py-2",children:[n.jsxs(Oi,{className:"flex items-center gap-2",children:[n.jsx(Q8,{className:"size-3.5"}),t("services.ports")]}),n.jsx(Sr,{className:"text-xs",children:t("services.portsSummary",{managed:i,occupied:s})})]}),n.jsx(Pi,{className:"p-0",children:e.length?n.jsx("div",{className:"divide-y divide-border",children:e.map(a=>n.jsxs("div",{className:"grid grid-cols-[1fr_auto] items-center gap-2 px-3 py-2",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsxs("div",{className:"font-mono text-xs",children:[":",a.port]}),n.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:a.services.join(", ")||t("services.unassigned")}),a.urls[0]?n.jsx("div",{className:"truncate font-mono text-[10px] text-muted-foreground",children:a.urls[0]}):null]}),n.jsx(FQ,{port:a})]},a.port))}):n.jsx(Ul,{label:t("services.noPorts")})})]})}function FQ({compact:e,port:t}){const s=X(),i=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 n.jsx(Ze,{className:se(e&&"max-w-36 truncate"),variant:a,children:i})}function UQ({onChange:e,value:t}){const s=X();return n.jsxs("div",{className:"relative block",children:[n.jsx(Au,{className:"pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"}),n.jsx(St,{"aria-label":s("services.log.search"),className:"h-8 w-44 pl-7 text-xs",onChange:i=>e(i.target.value),placeholder:s("services.log.search"),value:t})]})}function qQ({className:e,containerRef:t,emptyText:s,logs:i,query:a,showTimestamps:l=!0,wrapLines:c=!0}){return n.jsx("div",{className:se("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:i.length?i.map((u,f)=>n.jsxs("div",{className:se("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)]",u.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?n.jsx("span",{className:"text-muted-foreground dark:text-zinc-500",title:u.timestamp,children:GQ(u.timestamp)}):null,n.jsxs("span",{className:c?"whitespace-pre-wrap break-words":"whitespace-pre",children:[u.stream==="stderr"?n.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,KQ(u.text,a)]})]},WQ(u,f))):n.jsx("div",{className:"p-3 text-muted-foreground",children:s})})}function GQ(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 VQ(e){return`${e.timestamp} ${e.stream} ${e.text}`}function WQ(e,t){return e.cursor??`${e.service}-${e.timestamp}-${e.stream}-${t}`}function KQ(e,t){const s=t.trim();if(!s)return e;const i=e.toLowerCase(),a=s.toLowerCase(),l=[];let c=0,u=i.indexOf(a);for(;u!==-1;){u>c&&l.push(e.slice(c,u));const f=u+s.length;l.push(n.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(u,f)},`${u}-${f}`)),c=f,u=i.indexOf(a,c)}return c<e.length&&l.push(e.slice(c)),l}function AN(e){return`${e.kind}:${e.name}`}function YQ(e,t=!1,s={}){const[i,a]=v.useState(),[l,c]=v.useState(),[u,f]=v.useState(e.kind==="source"),h=JSON.stringify(s);return v.useEffect(()=>{a(void 0),c(void 0);let p=!1;const g=async()=>{try{if(e.kind==="service"){const x=await b3(e.name,s);p||(a(x.logs),f(x.queryable),c(void 0))}else{const x=await m3(e.name,s);p||(a(x),f(!0),c(void 0))}}catch(x){p||c(x instanceof Error?x.message:String(x))}};g();const b=window.setInterval(g,t?1e3:2e3);return()=>{p=!0,window.clearInterval(b)}},[e.kind,e.name,t,h]),{logs:i,error:l,queryable:u}}const XQ=[{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 hR({target:e,query:t,setQuery:s,streaming:i,setStreaming:a,hideStdout:l,setHideStdout:c,fill:u=!1,leading:f,trailing:h}){const p=X(),b=Om()?.confirmedProject.logs??{showTimestamps:!0,wrapLines:!0},x=e.kind==="source",[_,k]=v.useState(""),[C,E]=v.useState(""),[j,N]=v.useState(t);v.useEffect(()=>{const K=window.setTimeout(()=>N(t),300);return()=>window.clearTimeout(K)},[t]);const A=v.useMemo(()=>{const K={};_&&(K.since=_),C&&(K.level=C);const ue=j.trim();return ue&&(K.grep=ue),K},[_,C,j]),{logs:T,error:D,queryable:z}=YQ(e,i,A),O=x||z,$=v.useRef(null),M=v.useRef(!0),[I,G]=v.useState([]),[B,U]=v.useState(!1),Y=JSON.stringify(A);v.useEffect(()=>{G([])},[Y,e.kind,e.name]);const P=v.useMemo(()=>{const K=T??[];if(I.length===0)return K;const ue=new Set(I.map(ge=>ge.cursor).filter(Boolean));return[...I,...K.filter(ge=>!ge.cursor||!ue.has(ge.cursor))]},[T,I]),V=(I[0]??(T??[])[0])?.cursor;async function W(){if(!(!O||!V||B)){U(!0),M.current=!1;try{const K={...A,before:V,lines:200},ue=e.kind==="source"?await m3(e.name,K):(await b3(e.name,K)).logs;ue.length&&G(ge=>{const J=new Set(ge.map(Le=>Le.cursor).filter(Boolean));return[...ue.filter(Le=>!Le.cursor||!J.has(Le.cursor)),...ge]})}finally{U(!1)}}}const re=t.trim().toLowerCase(),ce=v.useMemo(()=>{let K=P;return l&&(K=K.filter(ue=>ue.stream==="stderr")),re&&(K=K.filter(ue=>VQ(ue).toLowerCase().includes(re))),K},[P,l,re]);v.useEffect(()=>{const K=$.current;if(!K)return;const ue=()=>{const ge=K.scrollHeight-K.scrollTop-K.clientHeight;M.current=ge<40};return ue(),K.addEventListener("scroll",ue,{passive:!0}),()=>K.removeEventListener("scroll",ue)},[]),v.useEffect(()=>{if(!i||!M.current||ce.length===0)return;const K=$.current;K&&(K.scrollTop=K.scrollHeight)},[i,ce]);const F=T?re?p("services.log.noMatch",{query:t.trim()}):p(l?"services.log.noStderr":"services.log.noEntries"):p("common.loading");return n.jsxs("div",{className:u?"flex h-full min-h-0 flex-col gap-2":"flex flex-col gap-2",children:[n.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[f,n.jsx(UQ,{onChange:s,value:t}),O?n.jsxs(n.Fragment,{children:[n.jsx("select",{"aria-label":p("services.log.timeRange"),className:"h-8 rounded-md border border-border bg-background px-2 text-xs",onChange:K=>k(K.target.value),value:_,children:XQ.map(K=>n.jsx("option",{value:K.value,children:p(K.labelKey)},K.labelKey))}),n.jsxs("select",{"aria-label":p("services.log.level"),className:"h-8 rounded-md border border-border bg-background px-2 text-xs",onChange:K=>E(K.target.value),value:C,children:[n.jsx("option",{value:"",children:p("services.log.allLevels")}),n.jsx("option",{value:"warn",children:p("services.log.warningsPlus")}),n.jsx("option",{value:"error",children:p("services.log.errors")})]})]}):n.jsxs(TN,{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:[n.jsx(WD,{}),p("services.log.errorsOnly")]}),n.jsxs(TN,{active:i,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(!i),children:[n.jsx(wL,{}),p(i?"services.log.streaming":"services.log.stream")]}),O&&V?n.jsxs(Q,{disabled:B,onClick:()=>{W()},size:"sm",type:"button",variant:"outline",children:[n.jsx(nm,{}),p(B?"common.loading":"services.log.loadOlder")]}):null,h?n.jsx("div",{className:"ml-auto flex items-center gap-2",children:h}):null]}),D?n.jsx("div",{className:"text-red-600",children:D}):null,n.jsx(qQ,{className:se("rounded border border-border/60",u?"min-h-0 flex-1":"max-h-80"),containerRef:$,emptyText:F,logs:ce,query:t,showTimestamps:b.showTimestamps,wrapLines:b.wrapLines})]})}function TN({active:e,activeClassName:t,children:s,onClick:i}){return n.jsx(Q,{"aria-pressed":e,className:e?t:void 0,onClick:i,size:"sm",type:"button",variant:"outline",children:s})}function ZQ(e,t){return e.kind===t.kind&&e.name===t.name}function QQ({options:e,target:t,onChange:s,className:i}){const a=X(),l=e.findIndex(u=>ZQ(u.target,t)),c=[...new Set(e.map(u=>u.group))];return n.jsx("select",{"aria-label":a("services.logSource"),className:i??"h-8 max-w-44 rounded-md border border-border bg-background px-2 text-xs",onChange:u=>s(e[Number(u.target.value)].target),value:String(l),children:c.map(u=>n.jsx("optgroup",{label:u,children:e.map((f,h)=>f.group===u?n.jsx("option",{value:String(h),children:f.label},`${f.group}:${f.label}`):null)},u))})}function JQ({serviceName:e}){const t=X(),[s,i]=v.useState(""),[a,l]=v.useState(!1),[c,u]=v.useState(!1),[f,h]=v.useState(!1),p=n.jsx(hR,{fill:!0,hideStdout:c,query:s,setHideStdout:u,setQuery:i,setStreaming:l,streaming:a,target:{kind:"service",name:e},trailing:n.jsx(Q,{"aria-label":t(f?"services.logsView.exitFs":"services.logsView.expand"),className:"text-muted-foreground hover:text-foreground",onClick:()=>h(g=>!g),size:"icon-sm",title:t(f?"services.fsExit":"services.fsExpand"),type:"button",variant:"ghost",children:f?n.jsx(L0,{}):n.jsx(D0,{})})});return f?n.jsx(P1,{onClose:()=>h(!1),title:t("services.logsTitle",{name:e}),children:p}):n.jsx("div",{className:"h-[60vh] min-h-[24rem]",children:p})}function P1({title:e,onClose:t,children:s,maxWidthClass:i="max-w-6xl"}){const a=X();return v.useEffect(()=>{function l(c){c.key==="Escape"&&t()}return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[t]),Xn.createPortal(n.jsx("div",{className:"fixed inset-0 z-[1000] bg-black/40 p-4 sm:p-8",onMouseDown:t,children:n.jsxs("div",{"aria-modal":"true",className:`mx-auto flex h-full ${i} flex-col overflow-hidden rounded-lg border border-border bg-card text-xs shadow-xl`,onMouseDown:l=>l.stopPropagation(),role:"dialog",children:[n.jsxs("div",{className:"flex shrink-0 items-center gap-3 border-b border-border px-4 py-2",children:[n.jsx("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold",children:e}),n.jsx(Q,{"aria-label":a("services.closeLogs"),onClick:t,size:"icon",type:"button",variant:"ghost",children:n.jsx(Gt,{})})]}),n.jsx("div",{className:"min-h-0 flex-1 p-3",children:s})]})}),document.body)}const eJ={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 tJ({onClose:e,onAdded:t}){const s=X(),[i,a]=v.useState(""),[l,c]=v.useState("journald"),[u,f]=v.useState(""),[h,p]=v.useState(""),[g,b]=v.useState(""),[x,_]=v.useState(""),[k,C]=v.useState(""),[E,j]=v.useState(""),[N,A]=v.useState(),[T,D]=v.useState(!1);async function z(){D(!0),A(void 0);try{const O={name:i.trim(),kind:"command"};l==="file"?(O.kind="file",O.path=h.trim()):l==="ssh"?(O.kind="ssh",O.host=u.trim(),O.path=h.trim()):l==="command"?(O.kind="command",O.command=g.trim(),x.trim()&&(O.cwd=x.trim())):l==="journald"?(O.driver="journald",O.unit=k.trim(),u.trim()&&(O.host=u.trim())):l==="docker"&&(O.driver="docker",O.container=E.trim(),u.trim()&&(O.host=u.trim()));const $=await z9(O);t($,O.name),e()}catch(O){A(O instanceof Error?O.message:String(O))}finally{D(!1)}}return n.jsx(Kn,{icon:n.jsx(dm,{}),onClose:e,size:"md",title:s("services.log.addSourceTitle"),children:n.jsxs("form",{className:"flex flex-col gap-3 p-4 text-xs",onSubmit:O=>{O.preventDefault(),z()},children:[n.jsx(Gr,{label:s("services.log.name"),children:n.jsx(St,{autoFocus:!0,onChange:O=>a(O.target.value),placeholder:"PROD",value:i})}),n.jsxs(Gr,{label:s("services.log.type"),children:[n.jsxs("select",{className:"h-9 w-full rounded-md border border-border bg-background px-2 text-xs",onChange:O=>c(O.target.value),value:l,children:[n.jsx("option",{value:"journald",children:s("services.log.typeJournald")}),n.jsx("option",{value:"docker",children:s("services.log.typeDocker")}),n.jsx("option",{value:"ssh",children:s("services.log.typeSsh")}),n.jsx("option",{value:"file",children:s("services.log.typeFile")}),n.jsx("option",{value:"command",children:s("services.log.typeCommand")})]}),n.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:s(eJ[l])})]}),l==="journald"||l==="docker"?n.jsx(Gr,{label:s("services.log.hostOptional"),children:n.jsx(St,{onChange:O=>f(O.target.value),placeholder:"jobjourney-prod (an alias from ~/.ssh/config)",value:u})}):null,l==="journald"?n.jsx(Gr,{label:s("services.log.unit"),children:n.jsx(St,{onChange:O=>C(O.target.value),placeholder:"jobjourney",value:k})}):null,l==="docker"?n.jsx(Gr,{label:s("services.log.container"),children:n.jsx(St,{onChange:O=>j(O.target.value),placeholder:"brainctl-api",value:E})}):null,l==="ssh"?n.jsx(Gr,{label:s("services.log.host"),children:n.jsx(St,{onChange:O=>f(O.target.value),placeholder:"prod (an alias from ~/.ssh/config)",value:u})}):null,l==="file"||l==="ssh"?n.jsx(Gr,{label:s(l==="ssh"?"services.log.remotePath":"services.log.filePath"),children:n.jsx(St,{onChange:O=>p(O.target.value),placeholder:"/var/log/app/out.log",value:h})}):null,l==="command"?n.jsxs(n.Fragment,{children:[n.jsx(Gr,{label:s("services.log.command"),children:n.jsx(St,{onChange:O=>b(O.target.value),placeholder:"kubectl logs -l app=myapp --tail 500",value:g})}),n.jsx(Gr,{label:s("services.log.cwdOptional"),children:n.jsx(St,{onChange:O=>_(O.target.value),placeholder:"/srv/app",value:x})})]}):null,N?n.jsx("div",{className:"text-red-600",children:N}):null,n.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[n.jsx(Q,{onClick:e,size:"sm",type:"button",variant:"outline",children:s("common.cancel")}),n.jsx(Q,{disabled:T||!i.trim(),size:"sm",type:"submit",children:s(T?"common.saving":"services.log.addSource")})]})]})})}function Gr({label:e,children:t}){return n.jsxs("label",{className:"flex flex-col gap-1",children:[n.jsx("span",{className:"font-medium text-muted-foreground",children:e}),t]})}const RN=4;function sJ({services:e,initialService:t,onClose:s}){const i=X(),[a,l]=v.useState([]),[c,u]=v.useState(!1),[f,h]=v.useState(()=>[0]),[p,g]=v.useState(()=>{const A=t?{kind:"service",name:t}:e[0]?{kind:"service",name:e[0]}:void 0;return A?{0:A}:{}}),b=v.useRef(1);v.useEffect(()=>{let A=!1;return P9().then(T=>{A||l(T)}),()=>{A=!0}},[]);const x=[...e.map(A=>({target:{kind:"service",name:A},label:A,group:i("services.title")})),...a.map(A=>({target:{kind:"source",name:A.name},label:A.name,group:i("services.log.sourcesGroup")}))],_=x.map(A=>A.target);function k(){if(f.length>=RN||_.length===0)return;const A=b.current++,T=new Set(Object.values(p).map(AN)),D=_.find(z=>!T.has(AN(z)))??_[0];h(z=>[...z,A]),g(z=>({...z,[A]:D}))}function C(A){h(T=>T.filter(D=>D!==A)),g(T=>{const D={...T};return delete D[A],D})}function E(A,T){g(D=>({...D,[A]:T}))}function j(A,T){l(A);const D=f[0];D!==void 0&&E(D,{kind:"source",name:T})}const N=n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("span",{children:i("services.logs")}),n.jsxs(Q,{onClick:()=>u(!0),size:"sm",type:"button",variant:"outline",children:[n.jsx(Es,{}),i("services.log.addSource")]}),n.jsxs(Q,{disabled:f.length>=RN||_.length===0,onClick:k,size:"sm",type:"button",variant:"outline",children:[n.jsx(Es,{}),i("services.log.addPane")]})]});return n.jsxs(n.Fragment,{children:[n.jsx(P1,{maxWidthClass:"max-w-[1500px]",onClose:s,title:N,children:_.length===0?n.jsx("div",{className:"grid h-full place-items-center text-center text-muted-foreground",children:n.jsxs("div",{children:[n.jsx("p",{children:i("services.log.noneYet")}),n.jsxs(Q,{className:"mt-2",onClick:()=>u(!0),size:"sm",type:"button",children:[n.jsx(Es,{}),i("services.log.addLogSource")]})]})}):n.jsx("div",{className:se("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(A=>n.jsx(nJ,{onChangeTarget:T=>E(A,T),onRemove:f.length>1?()=>C(A):void 0,options:x,target:p[A]??_[0]},A))})}),c?n.jsx(tJ,{onAdded:j,onClose:()=>u(!1)}):null]})}function nJ({options:e,target:t,onChangeTarget:s,onRemove:i}){const a=X(),[l,c]=v.useState(""),[u,f]=v.useState(!0),[h,p]=v.useState(!1);return n.jsx("div",{className:"flex min-h-0 min-w-0 flex-col rounded-lg border border-border bg-background/60 p-2",children:n.jsx(hR,{fill:!0,hideStdout:h,leading:n.jsx(QQ,{onChange:s,options:e,target:t}),query:l,setHideStdout:p,setQuery:c,setStreaming:f,streaming:u,target:t,trailing:i?n.jsx(Q,{"aria-label":a("services.log.removePane"),onClick:i,size:"icon",type:"button",variant:"ghost",children:n.jsx(Gt,{})}):void 0})})}function iJ({runtime:e,reloading:t,onReload:s}){const i=X();if(!e?.stale)return null;const a=e.staleFiles,l=a.length===1?i("services.env.staleOne",{file:a[0].relativePath}):i("services.env.staleMany",{count:a.length});return n.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:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Zi,{className:"size-4 shrink-0"}),n.jsx("span",{children:i("services.env.staleBanner",{summary:l})})]}),n.jsxs(Q,{disabled:t,onClick:s,size:"sm",type:"button",variant:"outline",children:[n.jsx(NL,{})," ",i(t?"services.env.reloading":"services.env.reloadService")]})]})}function rJ({rows:e,revealAll:t,onAdd:s,onRemove:i,onUpdate:a}){const l=X();return e.length===0?n.jsxs("div",{className:"text-muted-foreground",children:[l("services.env.noVars")," ",n.jsx("button",{className:"underline",onClick:s,type:"button",children:l("services.env.addOne")}),"."]}):n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full font-mono text-[11px]",children:[n.jsx("thead",{className:"text-left text-muted-foreground",children:n.jsxs("tr",{children:[n.jsx("th",{className:"py-1 pr-3",children:l("services.env.key")}),n.jsx("th",{className:"py-1 pr-3",children:l("services.env.value")}),n.jsx("th",{className:"py-1 w-8"})]})}),n.jsx("tbody",{children:e.map((c,u)=>{const f=!c.reveal&&!t;return n.jsxs("tr",{className:"border-t border-border/40",children:[n.jsx("td",{className:"py-1 pr-3 align-top",children:n.jsx("input",{className:"w-full rounded border border-border/60 bg-background px-1.5 py-0.5 font-mono",onChange:h=>a(u,{key:h.target.value}),placeholder:"KEY",spellCheck:!1,value:c.key})}),n.jsx("td",{className:"py-1 pr-3 align-top",children:n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("input",{className:"w-full rounded border border-border/60 bg-background px-1.5 py-0.5 font-mono",onChange:h=>a(u,{value:h.target.value}),spellCheck:!1,type:f?"password":"text",value:c.value}),n.jsx("button",{className:"text-muted-foreground hover:text-foreground",onClick:()=>a(u,{reveal:!c.reveal}),title:c.reveal||t?l("services.env.hide"):l("services.env.reveal"),type:"button",children:c.reveal||t?n.jsx(om,{size:14}):n.jsx(lm,{size:14})})]})}),n.jsx("td",{className:"py-1 align-top",children:n.jsx("button",{className:"text-muted-foreground hover:text-red-600",onClick:()=>i(u),type:"button",children:n.jsx(Xi,{size:14})})})]},u)})})]})})}function aJ({serviceName:e,onClose:t,onPick:s}){const i=X(),[a,l]=v.useState(),[c,u]=v.useState(),[f,h]=v.useState(!0),[p,g]=v.useState();v.useEffect(()=>{let _=!1;return h(!0),u(void 0),(async()=>{try{const k=await Q9(e,p);_||l(k)}catch(k){_||u(k instanceof Error?k.message:String(k))}finally{_||h(!1)}})(),()=>{_=!0}},[e,p]);function b(_){if(_.kind==="directory"){g(_.relativePath);return}_.supported&&s(_.relativePath)}function x(){if(!a||a.isRoot)return;const _=a.relativePath,k=_.includes("/")?_.slice(0,_.lastIndexOf("/")):"";g(k||void 0)}return n.jsx(Kn,{icon:n.jsx(cm,{}),onClose:t,size:"lg",title:i("services.fileBrowser.title"),children:n.jsxs("div",{className:"flex flex-col gap-2 p-4",children:[n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsxs(Q,{disabled:!a||a.isRoot,onClick:x,size:"sm",type:"button",variant:"outline",children:[n.jsx(nm,{})," ",i("services.fileBrowser.up")]}),n.jsx("code",{className:"truncate rounded bg-muted px-2 py-1 font-mono",children:a?.relativePath||"./"})]}),c?n.jsx("div",{className:"text-red-600",children:c}):f?n.jsx("div",{className:"text-muted-foreground",children:i("common.loading")}):!a||a.entries.length===0?n.jsx("div",{className:"text-muted-foreground",children:i("services.fileBrowser.empty")}):n.jsx("div",{className:"max-h-[50vh] overflow-auto rounded border border-border/60",children:n.jsx("ul",{className:"divide-y divide-border/40",children:a.entries.map(_=>{const k=_.kind==="directory",C=k||_.supported;return n.jsx("li",{children:n.jsxs("button",{className:se("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:[k?n.jsx(Io,{size:14}):n.jsx(Bj,{size:14}),n.jsx("span",{className:"flex-1 truncate font-mono",children:_.name}),!k&&_.format?n.jsx(Ze,{size:"small",variant:"secondary",children:_.format}):null]})},_.relativePath)})})}),n.jsxs("p",{className:"text-xs text-muted-foreground",children:[i("services.fileBrowser.hintPre")," ",n.jsx("code",{children:".env*"}),", ",n.jsx("code",{children:"appsettings*.json"})," ",i("services.fileBrowser.hintAnd")," ",n.jsx("code",{children:"application*.yml"}),i("services.fileBrowser.hintTail")]})]})})}function oJ(e){const{error:t,success:s}=gs(),[i,a]=v.useState(),[l,c]=v.useState(!1),u=v.useCallback(async()=>{try{a(await sz(e))}catch{a(void 0)}},[e]);v.useEffect(()=>{u()},[u]);const f=v.useCallback(async()=>{c(!0);try{await g3(e),s(`Reloaded ${e} with the latest configuration.`),await u()}catch(h){t(h instanceof Error?h.message:String(h))}finally{c(!1)}},[e,u,t,s]);return{runtime:i,reloading:l,refresh:u,reload:f}}function fR(e){if(!e.trim())return e;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function lJ(e){const{error:t,success:s}=gs(),[i,a]=v.useState([]),[l,c]=v.useState(),[u,f]=v.useState(),[h,p]=v.useState(!0),[g,b]=v.useState(!1),[x,_]=v.useState(!1),[k,C]=v.useState(!1),[E,j]=v.useState();v.useEffect(()=>{let M=!1;return p(!0),j(void 0),(async()=>{try{const I=await J9(e);if(M)return;a(I.files),I.files.length>0?c(G=>G??I.files[0].path):(c(void 0),f(void 0))}catch(I){M||j(I instanceof Error?I.message:String(I))}finally{M||p(!1)}})(),()=>{M=!0}},[e]);const N=v.useCallback(async M=>{b(!0),j(void 0);try{const I=await ak(e,M),G={path:I.path,relativePath:I.relativePath,format:I.format};I.format==="env"?f({info:G,exists:I.exists,rows:I.entries.map(B=>({...B,reveal:!1}))}):f({info:G,exists:I.exists,text:I.format==="json"?fR(I.content):I.content}),C(!1)}catch(I){j(I instanceof Error?I.message:String(I))}finally{b(!1)}},[e]);v.useEffect(()=>{l&&N(l)},[l,N]);function A(M,I){f(G=>{if(!G?.rows)return G;const B=G.rows.map((U,Y)=>Y===M?{...U,...I}:U);return{...G,rows:B}}),C(!0)}function T(){f(M=>M?.rows?{...M,rows:[...M.rows,{key:"",value:"",secret:!1,reveal:!0}]}:M),C(!0)}function D(M){f(I=>I?.rows?{...I,rows:I.rows.filter((G,B)=>B!==M)}:I),C(!0)}function z(M){f(I=>I&&{...I,text:M}),C(!0)}async function O(){if(u){_(!0);try{if(u.info.format==="env"&&u.rows){const M=await ez(e,u.info.path,u.rows.map(I=>({key:I.key.trim(),value:I.value})));f({info:{path:M.path,relativePath:M.relativePath,format:M.format},exists:M.exists,rows:M.entries.map(I=>({...I,reveal:!1}))}),s(`Saved ${M.entries.length} entries to ${M.relativePath}.`)}else if(u.text!==void 0){const M=await tz(e,u.info.path,u.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 $(M){try{const I=await ak(e,M),G={path:I.path,relativePath:I.relativePath,format:I.format};return a(B=>B.some(U=>U.path===G.path)?B:[...B,G]),c(G.path),s(`Loaded ${G.relativePath}.`),!0}catch(I){return t(I instanceof Error?I.message:String(I)),!1}}return{files:i,selectedPath:l,setSelectedPath:c,loaded:u,loadingList:h,loadingFile:g,saving:x,dirty:k,error:E,addRow:T,removeRow:D,updateRow:A,updateText:z,save:O,pickFile:$}}function cJ({serviceName:e}){const t=X(),{files:s,selectedPath:i,setSelectedPath:a,loaded:l,loadingList:c,loadingFile:u,saving:f,dirty:h,error:p,addRow:g,removeRow:b,updateRow:x,updateText:_,save:k,pickFile:C}=lJ(e),E=oJ(e),[j,N]=v.useState(!1),[A,T]=v.useState(!1);async function D(){await k(),await E.refresh()}return c?n.jsx("div",{className:"text-muted-foreground",children:t("common.loading")}):p&&!l?n.jsx("div",{className:"text-red-600",children:p}):n.jsxs("div",{className:"space-y-2",children:[n.jsx(iJ,{onReload:()=>{E.reload()},reloading:E.reloading,runtime:E.runtime}),n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[n.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n.jsx("span",{className:"text-muted-foreground",children:t("services.env.file")}),s.length>0?n.jsx("select",{className:"rounded border border-border/60 bg-background px-1.5 py-0.5 font-mono text-xs",onChange:z=>a(z.target.value),value:i??"",children:s.map(z=>n.jsxs("option",{value:z.path,children:[z.relativePath," [",z.format,"]"]},z.path))}):n.jsx("span",{className:"text-muted-foreground",children:t("services.env.noneDetected")}),n.jsxs(Q,{onClick:()=>T(!0),size:"sm",type:"button",variant:"outline",children:[n.jsx(cm,{})," ",t("services.env.browseFiles")]}),l?n.jsx("code",{className:"rounded bg-background px-1.5 py-0.5 font-mono text-muted-foreground",children:l.info.path}):null]}),n.jsxs("div",{className:"flex items-center gap-1",children:[l?.info.format==="env"?n.jsxs(n.Fragment,{children:[n.jsxs(Q,{onClick:()=>N(z=>!z),size:"sm",type:"button",variant:"outline",children:[j?n.jsx(om,{}):n.jsx(lm,{}),t(j?"services.env.hideSecrets":"services.env.revealSecrets")]}),n.jsxs(Q,{onClick:g,size:"sm",type:"button",variant:"outline",children:[n.jsx(Es,{})," ",t("common.add")]})]}):null,n.jsxs(Q,{disabled:!h||f||!l,onClick:()=>{D()},size:"sm",type:"button",children:[n.jsx(Gj,{})," ",t(f?"common.saving":"common.save")]})]})]}),p&&!l?n.jsx("div",{className:"text-red-600",children:p}):l?.info.format==="env"&&l.rows?n.jsx("div",{className:se(u&&"opacity-60 transition-opacity"),children:n.jsx(rJ,{revealAll:j,rows:l.rows,onAdd:g,onRemove:b,onUpdate:x})}):l?.text!==void 0?n.jsxs("div",{className:se("space-y-1",u&&"opacity-60 transition-opacity"),children:[l.info.format==="json"?n.jsx("div",{className:"flex justify-end",children:n.jsx(Q,{onClick:()=>_(fR(l.text??"")),size:"sm",type:"button",variant:"outline",children:t("services.env.formatJson")})}):null,n.jsx("textarea",{className:"min-h-[300px] w-full rounded border border-border/60 bg-background p-2 font-mono text-[11px] leading-relaxed",onChange:z=>_(z.target.value),spellCheck:!1,value:l.text})]}):u?n.jsx("div",{className:"text-muted-foreground",children:t("services.env.loadingFile")}):null,l?n.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,A?n.jsx(aJ,{onClose:()=>T(!1),onPick:z=>{C(z).then(O=>{O&&T(!1)})},serviceName:e}):null]})}function uJ({serviceName:e,status:t,timeline:s,onRefresh:i}){const a=X(),{error:l,success:c}=gs(),[u,f]=v.useState(!1),h=t?.inspector,p=t?.state==="running",g=v.useMemo(()=>s.filter(_=>_.kind==="service.http"&&_.service===e).map(_=>{const k=_.data??{};return{id:k.id??_.id,startedAt:_.timestamp,method:k.method??"?",path:k.path??"?",status:k.status??0,durationMs:k.durationMs??0,reqBytes:k.reqBytes??0,resBytes:k.resBytes??0}}).slice(-500).reverse(),[s,e]);async function b(_){f(!0);try{await ji(`/api/services/${encodeURIComponent(e)}/inspector`,{enabled:_?"true":"false"}),await i(),c(_?a("services.http.started",{name:e}):a("services.http.stopped",{name:e}))}catch(k){l(k instanceof Error?k.message:String(k))}finally{f(!1)}}if(!p)return n.jsx("div",{className:"text-muted-foreground",children:a("services.http.notRunning")});if(!h?.enabled)return n.jsxs("div",{className:"space-y-2",children:[n.jsx("p",{className:"text-muted-foreground",children:a("services.http.intro")}),n.jsxs(Q,{disabled:u,onClick:()=>b(!0),size:"sm",type:"button",children:[n.jsx(_r,{})," ",a("services.http.start")]})]});const x=h.port?`http://127.0.0.1:${h.port}`:void 0;return n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n.jsx("span",{className:"text-muted-foreground",children:a("services.http.inspectUrl")}),x?n.jsxs(n.Fragment,{children:[n.jsx("code",{className:"rounded bg-background px-1.5 py-0.5 font-mono",children:x}),n.jsxs(Q,{onClick:()=>{navigator.clipboard.writeText(x),c(a("services.http.copiedUrl"))},size:"sm",type:"button",variant:"outline",children:[n.jsx(gf,{})," ",a("common.copy")]}),n.jsx(Q,{onClick:()=>{pm(x)},size:"sm",type:"button",variant:"outline",children:a("common.open")})]}):n.jsx("span",{className:"text-muted-foreground",children:a("services.startingEllipsis")}),n.jsx("span",{className:"text-muted-foreground",children:a("services.http.upstream",{port:h.upstreamPort??"?"})}),n.jsxs(Q,{disabled:u,onClick:()=>b(!1),size:"sm",type:"button",variant:"outline",children:[n.jsx($a,{})," ",a("common.stop")]})]}),g.length===0?n.jsx("div",{className:"text-muted-foreground",children:a("services.http.noRequests")}):n.jsx("div",{className:"max-h-80 overflow-auto",children:n.jsxs("table",{className:"w-full font-mono text-[11px]",children:[n.jsx("thead",{className:"sticky top-0 bg-muted/60 text-left text-muted-foreground",children:n.jsxs("tr",{children:[n.jsx("th",{className:"py-1 pr-3",children:a("services.http.time")}),n.jsx("th",{className:"py-1 pr-3",children:a("services.http.method")}),n.jsx("th",{className:"py-1 pr-3",children:a("services.http.path")}),n.jsx("th",{className:"py-1 pr-3 text-right",children:a("services.http.status")}),n.jsx("th",{className:"py-1 pr-3 text-right",children:a("services.http.size")}),n.jsx("th",{className:"py-1 pr-3 text-right",children:"ms"})]})}),n.jsx("tbody",{children:g.map(_=>n.jsxs("tr",{className:"border-t border-border/40",children:[n.jsx("td",{className:"py-1 pr-3 text-muted-foreground",children:new Date(_.startedAt).toLocaleTimeString()}),n.jsx("td",{className:"py-1 pr-3",children:_.method}),n.jsx("td",{className:"py-1 pr-3 truncate max-w-[40ch]",children:_.path}),n.jsx("td",{className:se("py-1 pr-3 text-right",dJ(_.status)),children:_.status}),n.jsx("td",{className:"py-1 pr-3 text-right text-muted-foreground",children:hJ(_.resBytes)}),n.jsx("td",{className:"py-1 pr-3 text-right",children:_.durationMs.toFixed(1)})]},_.id))})]})})]})}function dJ(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 hJ(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function fJ({serviceName:e}){const t=X(),[s,i]=v.useState(null),[a,l]=v.useState(null),[c,u]=v.useState(()=>Date.now());return v.useEffect(()=>{let f=!1;async function h(){try{const g=await nz(e);f||(i(g),u(Date.now()),l(null))}catch(g){f||l(g instanceof Error?g.message:String(g))}}h();const p=setInterval(()=>{h()},3e3);return()=>{f=!0,clearInterval(p)}},[e]),a?n.jsx("p",{className:"text-destructive",children:t("services.metrics.loadError",{error:a})}):s?s.samples.length===0?n.jsx("p",{className:"text-muted-foreground",children:t("services.metrics.noSamples")}):n.jsx(mJ,{series:s,now:c}):n.jsx("p",{className:"text-muted-foreground",children:t("services.metrics.loading")})}function mJ({series:e,now:t}){const s=X(),{samples:i}=e,a=v.useMemo(()=>MN(i,h=>h.cpu),[i]),l=v.useMemo(()=>MN(i,h=>h.rss),[i]),c=e.startedAt?new Date(e.startedAt):null,u=c?t-c.getTime():null,f=i.length>1?i[i.length-1].t-i[0].t:0;return n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[n.jsx(qh,{accent:"#22c55e",label:"CPU",value:`${a.last.toFixed(1)}%`,sub:s("services.metrics.peakAvg",{peak:`${a.max.toFixed(1)}%`,avg:`${a.avg.toFixed(1)}%`})}),n.jsx(qh,{accent:"#3b82f6",label:s("services.metrics.memory"),value:Fb(l.last),sub:s("services.metrics.peakAvg",{peak:Fb(l.max),avg:Fb(l.avg)})}),n.jsx(qh,{accent:"#a855f7",label:s("services.metrics.uptime"),value:u!=null?ON(u):"—",sub:c?s("services.metrics.since",{time:c.toLocaleTimeString()}):s("services.metrics.notRunning")}),n.jsx(qh,{accent:"#f59e0b",label:s("services.metrics.samples"),value:String(i.length),sub:f?s("services.metrics.over",{dur:ON(f)}):s("services.metrics.collecting")})]}),n.jsx(LN,{label:"CPU",samples:i,pick:h=>h.cpu,summary:a,color:"#22c55e",suffix:"%",unit:"percent"}),n.jsx(LN,{label:s("services.metrics.memoryRss"),samples:i,pick:h=>h.rss,summary:l,color:"#3b82f6",suffix:" MB",unit:"mb"})]})}function MN(e,t){const s=e.map(t),i=s.reduce((a,l)=>a+l,0);return{last:s[s.length-1],max:Math.max(...s),min:Math.min(...s),avg:i/s.length}}function qh({accent:e,label:t,value:s,sub:i}){return n.jsxs("div",{className:"rounded-lg border border-border bg-card px-3 py-2",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full",style:{backgroundColor:e}}),n.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:t})]}),n.jsx("div",{className:"mt-1 font-mono text-lg leading-none tabular-nums",children:s}),n.jsx("div",{className:"mt-1 truncate font-mono text-[10px] text-muted-foreground",children:i})]})}const El=160,DN=44,pJ=20;function LN({label:e,samples:t,pick:s,summary:i,color:a,suffix:l,unit:c}){const u=X(),f=v.useMemo(()=>`metric-grad-${c}-${Math.random().toString(36).slice(2,8)}`,[c]),h=t.map(s),p=Math.max(...h,c==="percent"?10:1),g=gJ(p),b=0,x=g-b||1,_=t[0].t,k=t[t.length-1].t,C=Math.max(1,k-_),E=I=>(I-_)/C*1e3,j=I=>(1-(I-b)/x)*1e3,N=t.map(I=>`${E(I.t).toFixed(1)},${j(s(I)).toFixed(1)}`),A=`M0,1000 L${N.join(" L")} L1000,1000 Z`,T=`M${N.join(" L")}`,D=E(k),z=j(i.last),O=j(i.avg),$=[1,.75,.5,.25,0],M=5;return n.jsxs("figure",{className:"space-y-1",children:[n.jsxs("figcaption",{className:"flex items-baseline justify-between",children:[n.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:e}),n.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:[u("services.metrics.wNow")," ",n.jsxs("span",{className:"text-foreground",children:[i.last.toFixed(1),l]}),n.jsx("span",{className:"mx-1.5",children:"·"}),u("services.metrics.wPeak")," ",i.max.toFixed(1),l,n.jsx("span",{className:"mx-1.5",children:"·"}),u("services.metrics.wAvg")," ",i.avg.toFixed(1),l]})]}),n.jsxs("div",{className:"rounded-lg border border-border bg-card p-2",children:[n.jsxs("div",{className:"flex",children:[n.jsx("div",{className:"relative flex shrink-0 flex-col justify-between text-right font-mono text-[10px] text-muted-foreground",style:{width:DN,height:El},children:$.map(I=>n.jsx("span",{className:"pr-1 leading-none",children:bJ(b+I*x,c)},I))}),n.jsxs("div",{className:"relative min-w-0 flex-1",style:{height:El},children:[$.map((I,G)=>n.jsx("div",{className:"pointer-events-none absolute inset-x-0 border-t border-border/40",style:{top:`${I===1?0:I===0?El-1:(1-I)*El}px`,borderStyle:G===$.length-1?"solid":"dashed"}},I)),n.jsx("div",{className:"pointer-events-none absolute inset-x-0 border-t border-dashed",style:{top:`${O/1e3*El}px`,borderColor:a,opacity:.4}}),n.jsxs("svg",{"aria-label":e,className:"absolute inset-0 h-full w-full",preserveAspectRatio:"none",role:"img",viewBox:"0 0 1000 1000",children:[n.jsx("defs",{children:n.jsxs("linearGradient",{id:f,x1:"0",x2:"0",y1:"0",y2:"1",children:[n.jsx("stop",{offset:"0%",stopColor:a,stopOpacity:.35}),n.jsx("stop",{offset:"100%",stopColor:a,stopOpacity:.02})]})}),n.jsx("path",{d:A,fill:`url(#${f})`}),n.jsx("path",{d:T,fill:"none",stroke:a,strokeWidth:2,vectorEffect:"non-scaling-stroke",strokeLinejoin:"round",strokeLinecap:"round"})]}),n.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:`${D/1e3*100}%`,top:`${z/1e3*El}px`,backgroundColor:a,boxShadow:`0 0 0 4px ${a}33`}})]})]}),n.jsx("div",{className:"flex font-mono text-[10px] text-muted-foreground",style:{height:pJ,paddingLeft:DN},children:n.jsx("div",{className:"relative flex-1",children:Array.from({length:M+1},(I,G)=>{const B=G/M,U=_+B*C;return n.jsx("span",{className:"absolute top-1 whitespace-nowrap",style:{left:`${B*100}%`,transform:G===0?"translateX(0)":G===M?"translateX(-100%)":"translateX(-50%)"},children:vJ(U-k)},G)})})})]})]})}function gJ(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 bJ(e,t){return t==="percent"?`${e.toFixed(0)}%`:e>=1024?`${(e/1024).toFixed(1)}G`:`${e.toFixed(0)}M`}function Fb(e){return e>=1024?`${(e/1024).toFixed(2)} GB`:`${e.toFixed(0)} MB`}function ON(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 i=Math.floor(s/60);return i<24?`${i}h ${s%60}m`:`${Math.floor(i/24)}d ${i%24}h`}function vJ(e){const t=Math.round(e/1e3);if(t===0)return"now";if(Math.abs(t)<60)return`${t}s`;const i=Math.round(t/60);return Math.abs(i)<60?`${i}m`:`${Math.round(i/60)}h`}function xJ({rows:e,running:t}){const s=X();if(e.length===0)return n.jsx("div",{className:"text-muted-foreground",children:s(t?"services.proc.emptyRunning":"services.proc.emptyStopped")});const i=[...e].sort((l,c)=>c.cpuPercent-l.cpuPercent),a=new Set(e.map(l=>l.pid));return n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full font-mono text-[11px]",children:[n.jsx("thead",{className:"text-left text-muted-foreground",children:n.jsxs("tr",{children:[n.jsx("th",{className:"py-1 pr-3",children:"PID"}),n.jsx("th",{className:"py-1 pr-3",children:"PPID"}),n.jsx("th",{className:"py-1 pr-3 text-right",children:"CPU%"}),n.jsx("th",{className:"py-1 pr-3 text-right",children:"RSS MB"}),n.jsx("th",{className:"py-1",children:s("services.proc.command")})]})}),n.jsx("tbody",{children:i.map(l=>{const c=a.has(l.ppid);return n.jsxs("tr",{className:"border-t border-border/40",children:[n.jsx("td",{className:"py-1 pr-3",children:l.pid}),n.jsx("td",{className:"py-1 pr-3 text-muted-foreground",children:l.ppid}),n.jsx("td",{className:"py-1 pr-3 text-right",children:l.cpuPercent.toFixed(1)}),n.jsx("td",{className:"py-1 pr-3 text-right",children:l.rssMb.toFixed(1)}),n.jsx("td",{className:se("py-1 truncate max-w-[60ch]",c&&"pl-4"),children:l.command})]},l.pid)})})]})})}const PN={connecting:"bg-amber-500",running:"bg-emerald-500",exited:"bg-muted-foreground/40",error:"bg-red-500"},yJ={state:"connecting",cwd:"Local workspace",detail:"Opening shell"};function mR({sessionId:e,active:t,toolbarExtra:s}){const i=X(),{confirmedGlobal:a}=Lm(),l=v.useRef(null),[c,u]=v.useState(yJ),[f,h]=v.useState(null),p=v.useCallback(x=>u(x),[]),g=v.useCallback(x=>{l.current?.[x]()},[]),b=v.useCallback(x=>{if(a.terminal.confirmTerminate){h(x);return}g(x)},[a.terminal.confirmTerminate,g]);return n.jsxs("section",{className:se("flex h-full min-h-0 flex-col bg-background text-foreground",!t&&"hidden"),children:[n.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-between gap-3 border-b border-border bg-card px-4 py-2",children:[n.jsx("div",{className:"min-w-0",children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("span",{className:"relative flex size-2.5 shrink-0 items-center justify-center",title:c.state,children:[c.state==="connecting"&&n.jsx("span",{className:se("absolute inline-flex size-full animate-ping rounded-full opacity-60",PN[c.state])}),n.jsx("span",{className:se("relative inline-flex size-2 rounded-full",PN[c.state])})]}),n.jsxs("span",{className:"truncate font-mono text-[11px] text-muted-foreground",children:[c.cwd," · ",c.detail]})]})}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(Q,{"aria-label":i("terminal.restart"),className:"text-muted-foreground hover:bg-muted hover:text-foreground",size:"icon-sm",variant:"ghost",onClick:()=>b("restart"),title:i("terminal.restart"),type:"button",children:n.jsx(Uu,{})}),n.jsx(Q,{"aria-label":i("terminal.stop"),className:"text-muted-foreground hover:bg-muted hover:text-foreground",size:"icon-sm",variant:"ghost",onClick:()=>b("stop"),title:i("terminal.stop"),type:"button",children:n.jsx($a,{})}),s]})]}),n.jsx("div",{className:"min-h-0 flex-1",children:n.jsx(WT,{active:t,displaySettings:a.terminal,onStatusChange:p,ref:l,sessionId:e})}),f?n.jsx(Xl,{confirmLabel:i(f==="restart"?"terminal.restart":"terminal.stop"),message:i(f==="restart"?"terminal.confirmRestartBody":"terminal.confirmStopBody"),onCancel:()=>h(null),onConfirm:()=>{g(f),h(null)},title:i(f==="restart"?"terminal.confirmRestartTitle":"terminal.confirmStopTitle"),tone:"danger"}):null]})}function _J({serviceName:e,active:t}){const s=X(),[i,a]=v.useState(null),[l,c]=v.useState(null),[u,f]=v.useState(!1),h=v.useRef(!1),p=v.useRef(!0);v.useEffect(()=>(p.current=!0,()=>{p.current=!1}),[]),v.useEffect(()=>{!t||h.current||(h.current=!0,(async()=>{try{const x=await bu({serviceName:e});p.current&&a(x.id)}catch(x){p.current&&(c(x instanceof Error?x.message:String(x)),h.current=!1)}})())},[t,e]);const g=n.jsx(Q,{"aria-label":s(u?"services.term.exitFs":"services.term.expand"),className:"text-white/60 hover:bg-white/10 hover:text-white",onClick:()=>f(x=>!x),size:"icon-sm",title:s(u?"services.fsExit":"services.fsExpand"),type:"button",variant:"ghost",children:u?n.jsx(L0,{}):n.jsx(D0,{})}),b=l?n.jsx("div",{className:"p-3 font-mono text-[11px] text-destructive",children:s("services.term.openError",{error:l})}):i?n.jsx(mR,{active:t,sessionId:i,toolbarExtra:g}):n.jsx("div",{className:"p-3 font-mono text-[11px] text-muted-foreground",children:s("services.term.opening")});return u&&t?n.jsx(P1,{onClose:()=>f(!1),title:s("services.termTitle",{name:e}),children:b}):n.jsx("div",{className:se("h-[60vh] min-h-[24rem] overflow-hidden rounded-md border border-border",!t&&"hidden"),children:b})}const wJ=500;function SJ(e){const[t,s]=v.useState(),[i,a]=v.useState([]),[l,c]=v.useState(),[u,f]=v.useState(!1),h=v.useRef(void 0);v.useEffect(()=>{h.current=void 0,s(void 0),a([]);const g=new EventSource(`/api/services/${encodeURIComponent(e)}/test/stream`),b=x=>{try{const _=JSON.parse(x.data);_.run.id!==h.current&&(h.current=_.run.id,a([])),s(_.run),_.line&&a(k=>[...k,_.line].slice(-wJ))}catch{}};return g.addEventListener("status",b),g.addEventListener("output",b),()=>g.close()},[e]);const p=v.useCallback(async g=>{f(!0),c(void 0);try{await rz(e,g)}catch(b){c(b instanceof Error?b.message:String(b))}finally{f(!1)}},[e]);return{run:t,lines:i,error:l,starting:u,start:p}}const kJ={running:"secondary",passed:"success",failed:"error",error:"error"},CJ={running:"services.tests.statusRunning",passed:"services.tests.statusPassed",failed:"services.tests.statusFailed",error:"services.tests.statusError"};function NJ({serviceName:e}){const t=X(),{run:s,lines:i,error:a,starting:l,start:c}=SJ(e),[u,f]=v.useState(""),h=s?.status==="running"||l,p=s?.status==="failed"||s?.status==="error";return n.jsxs("div",{className:"space-y-2",children:[n.jsxs("form",{className:"flex items-center gap-2",onSubmit:g=>{g.preventDefault(),h||c(u.trim()||void 0)},children:[n.jsx(St,{className:"h-7 flex-1 text-[11px]",disabled:h,onChange:g=>f(g.target.value),placeholder:t("services.tests.patternPlaceholder"),value:u}),n.jsx(Q,{disabled:h,size:"sm",type:"submit",children:t(h?"services.tests.running":"services.tests.runTests")})]}),a?n.jsx("div",{className:"text-red-600",children:a}):null,s?n.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-muted-foreground",children:[n.jsx(Ze,{size:"small",variant:kJ[s.status],children:t(CJ[s.status])}),n.jsx("code",{className:"font-mono text-[11px]",children:s.command}),s.failingCount>0?n.jsxs("span",{children:["· ",t("services.tests.failing",{count:s.failingCount})]}):null,s.exitCode!=null?n.jsxs("span",{children:["· ",t("services.tests.exit",{code:s.exitCode})]}):null]}):n.jsx("div",{className:"text-muted-foreground",children:t("services.tests.noRuns")}),i.length>0?n.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap break-all rounded bg-background p-2 font-mono text-[11px]",children:i.map((g,b)=>n.jsx("div",{className:se(g.stream==="stderr"&&"text-red-500"),children:g.text},b))}):null,p?n.jsxs("div",{className:"rounded border border-border bg-muted/40 p-2",children:[t("services.tests.failuresPre")," ",n.jsx("a",{className:"font-medium underline",href:"/errors",children:t("services.tests.errorInbox")})," ",t("services.tests.failuresPost")]}):null]})}function EJ({serviceName:e,status:t,health:s,timeline:i,onRefresh:a}){const l=X(),[c,u]=Pl("service-detail:tab","metrics"),f=s?.processTree?.processes??[];return n.jsxs("div",{className:"border-t border-border bg-muted/30 px-3 py-2 text-xs",children:[n.jsxs("div",{className:"mb-2 flex gap-1",children:[n.jsx(bo,{active:c==="logs",onClick:()=>u("logs"),children:l("services.logs")}),n.jsxs(bo,{active:c==="processes",onClick:()=>u("processes"),children:[l("services.tab.processes")," ",f.length?n.jsx(Ze,{variant:"secondary",size:"small",children:f.length}):null]}),n.jsx(bo,{active:c==="metrics",onClick:()=>u("metrics"),children:l("services.tab.metrics")}),n.jsxs(bo,{active:c==="http",onClick:()=>u("http"),children:["HTTP",t?.inspector?.enabled?n.jsx(Ze,{variant:"success",size:"small",children:l("services.tab.on")}):null]}),n.jsx(bo,{active:c==="env",onClick:()=>u("env"),children:l("services.tab.env")}),n.jsx(bo,{active:c==="tests",onClick:()=>u("tests"),children:l("services.tab.tests")}),n.jsx(bo,{active:c==="terminal",onClick:()=>u("terminal"),children:l("nav.terminal")})]}),c==="processes"?n.jsx(xJ,{rows:f,running:t?.state==="running"}):null,c==="metrics"?n.jsx(fJ,{serviceName:e}):null,c==="http"?n.jsx(uJ,{serviceName:e,status:t,timeline:i,onRefresh:a}):null,c==="env"?n.jsx(cJ,{serviceName:e}):null,c==="tests"?n.jsx(NJ,{serviceName:e}):null,c==="logs"?n.jsx(JQ,{serviceName:e}):null,n.jsx(_J,{active:c==="terminal",serviceName:e},e)]})}function bo({active:e,onClick:t,children:s}){return n.jsx("button",{className:se("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 jJ={high:"success",medium:"warning",low:"secondary"};function AJ({onClose:e,onRefresh:t}){const s=X(),i=gs(),{sendToAgent:a}=Vt(),[l,c]=v.useState("url"),[u,f]=v.useState(""),[h,p]=v.useState(!1),[g,b]=v.useState(null),[x,_]=v.useState(null),[k,C]=v.useState([]),[E,j]=v.useState([]),[N,A]=v.useState(null),T=N?.kind==="docker-compose"?E.find($=>$.composeService===N.composeService):void 0;async function D(){if(u.trim()){p(!0),b(null);try{const $=await F9(u.trim());_($.profile),C($.proposals),j($.databases),A($.proposals[0]??null),$.proposals.length===0&&b(s("onboard.scanNoDetect")),c("review")}catch($){b($ instanceof Error?$.message:String($))}finally{p(!1)}}}function z(){a({prompt:`Onboard this repository and register it as a NoMoreIDE service: ${u.trim()}
|
|
121
121
|
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:u.trim()})}),e()}async function O($){if(N){p(!0),b(null);try{await U9(N,$,T),await t();const M=(T?s("onboard.extraDb"):"")+($?s("onboard.extraStart"):"");i.success(s("onboard.registeredToast",{name:N.name,extras:M})),e()}catch(M){b(M instanceof Error?M.message:String(M))}finally{p(!1)}}}return n.jsxs(Kn,{icon:n.jsx(Mn,{}),onClose:e,size:"lg",title:s("onboard.title"),children:[l==="url"?n.jsx(TJ,{url:u,busy:h,error:g,onChange:f,onScan:D,onRefine:z}):null,l==="review"&&x?n.jsx(RJ,{profile:x,proposals:k,selected:N,database:T,error:g,onSelect:A,onEdit:A,onBack:()=>c("url"),onRefine:z,onContinue:()=>c("install")}):null,l==="install"&&N?n.jsx(DJ,{proposal:N,busy:h,error:g,onBack:()=>c("review"),onRegister:O}):null]})}function TJ({url:e,busy:t,error:s,onChange:i,onScan:a,onRefine:l}){const c=X();return n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("p",{className:"text-sm text-muted-foreground",children:c("onboard.urlIntro")}),n.jsx(St,{autoFocus:!0,placeholder:"https://github.com/owner/repo",value:e,onChange:u=>i(u.target.value),onKeyDown:u=>{u.key==="Enter"&&!t&&a()}}),s?n.jsx("p",{className:"text-sm text-destructive",children:s}):null,n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsxs(Q,{variant:"ghost",size:"sm",onClick:l,disabled:!e.trim(),children:[n.jsx(Sn,{className:"size-3.5"}),c("onboard.refineWithAi")]}),n.jsxs(Q,{onClick:a,disabled:t||!e.trim(),children:[t?n.jsx(Bt,{className:"size-4 animate-spin"}):n.jsx(Mn,{className:"size-4"}),c(t?"onboard.cloning":"onboard.cloneDetect")]})]})]})}function RJ({profile:e,proposals:t,selected:s,database:i,error:a,onSelect:l,onEdit:c,onBack:u,onRefine:f,onContinue:h}){const p=X();return n.jsxs("div",{className:"flex flex-col gap-4",children:[n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[n.jsx("span",{className:"text-sm font-medium",children:e.name}),e.languages.map(g=>n.jsx(Ze,{variant:"outline",size:"small",label:g},g))]}),a?n.jsx("p",{className:"text-sm text-destructive",children:a}):null,t.length>0?n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:p("onboard.detectedServices")}),t.map(g=>{const b=s?.name===g.name;return n.jsxs("button",{type:"button",onClick:()=>l(g),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:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsx("span",{className:"font-medium",children:g.name}),n.jsx(Ze,{variant:jJ[g.confidence],size:"small",label:g.confidence})]}),n.jsx("div",{className:"mt-0.5 font-mono text-xs text-muted-foreground",children:g.kind==="docker-compose"?`compose · ${g.composeService}`:g.command}),n.jsx("div",{className:"text-[11px] text-muted-foreground",children:g.reason})]},g.name)})]}):null,s?n.jsx(MJ,{proposal:s,onChange:c}):null,i?n.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:[n.jsx(hi,{className:"size-3.5"}),n.jsxs("span",{children:[p("onboard.alsoRegistersPre")," ",n.jsx("span",{className:"font-medium",children:i.name})," (",i.engine,")"," ",p("onboard.alsoRegistersPost")]})]}):null,e.envKeys.length>0?n.jsxs("div",{className:"text-xs text-muted-foreground",children:[n.jsx("span",{className:"font-medium",children:p("onboard.envFrom")})," ",e.envKeys.join(", ")]}):null,e.readmeExcerpt?n.jsxs("details",{className:"rounded-md border border-border bg-muted/30 p-2 text-xs",children:[n.jsx("summary",{className:"cursor-pointer font-medium",children:p("onboard.readmeExcerpt")}),n.jsx("pre",{className:"mt-2 max-h-40 overflow-auto whitespace-pre-wrap font-mono",children:e.readmeExcerpt})]}):null,n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsxs(Q,{variant:"ghost",size:"sm",onClick:u,children:[n.jsx(Hu,{className:"size-3.5"}),p("common.back")]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs(Q,{variant:"outline",size:"sm",onClick:f,children:[n.jsx(Sn,{className:"size-3.5"}),p("onboard.refineWithAi")]}),n.jsx(Q,{onClick:h,disabled:!s,children:p("onboard.continue")})]})]})]})}function MJ({proposal:e,onChange:t}){const s=X();return n.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[n.jsx(mu,{label:s("onboard.serviceName"),children:n.jsx(St,{value:e.name,onChange:i=>t({...e,name:i.target.value})})}),n.jsx(mu,{label:s("onboard.portOptional"),children:n.jsx(St,{value:e.port?.toString()??"",placeholder:"auto",onChange:i=>t({...e,port:i.target.value?Number(i.target.value):void 0})})}),e.kind==="docker-compose"?n.jsx(mu,{label:s("onboard.composeService"),className:"col-span-2",children:n.jsx(St,{value:e.composeService??"",onChange:i=>t({...e,composeService:i.target.value})})}):n.jsx(mu,{label:s("onboard.runCommand"),className:"col-span-2",children:n.jsx(St,{value:e.command??"",onChange:i=>t({...e,command:i.target.value})})})]})}function DJ({proposal:e,busy:t,error:s,onBack:i,onRegister:a}){const l=X(),[c,u]=v.useState(e.installCommand??""),[f,h]=v.useState([]),[p,g]=v.useState(!1),[b,x]=v.useState(!1),_=v.useRef(null);function k(E){h(j=>[...j,E]),queueMicrotask(()=>{const j=_.current;j&&(j.scrollTop=j.scrollHeight)})}async function C(){c.trim()&&(g(!0),x(!1),h([]),await q9({clonePath:e.cwd,command:c.trim()},{onLine:E=>k(E.text),onDone:E=>{k(E===0?l("onboard.installComplete"):l("onboard.installExited",{code:E??"?"})),g(!1),x(E===0)},onError:E=>{k(`✗ ${E}`),g(!1)}}))}return n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsxs("div",{className:"flex items-end gap-2",children:[n.jsx(mu,{label:l("onboard.installCommand"),className:"flex-1",children:n.jsx(St,{value:c,placeholder:"e.g. npm install",onChange:E=>u(E.target.value)})}),n.jsxs(Q,{variant:"outline",onClick:C,disabled:p||!c.trim(),children:[p?n.jsx(Bt,{className:"size-4 animate-spin"}):n.jsx(ju,{className:"size-4"}),l("onboard.install")]})]}),f.length>0?n.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(`
|
|
122
122
|
`)}):null,s?n.jsx("p",{className:"text-sm text-destructive",children:s}):null,n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsxs(Q,{variant:"ghost",size:"sm",onClick:i,children:[n.jsx(Hu,{className:"size-3.5"}),l("common.back")]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Q,{variant:"outline",onClick:()=>a(!1),disabled:t,children:l("onboard.registerOnly")}),n.jsxs(Q,{onClick:()=>a(!0),disabled:t,children:[t?n.jsx(Bt,{className:"size-4 animate-spin"}):n.jsx(_r,{className:"size-4"}),b||!c.trim()?l("onboard.registerStart"):l("onboard.skipInstallStart")]})]})]})]})}function mu({label:e,className:t,children:s}){return n.jsxs("label",{className:`flex flex-col gap-1 text-xs ${t??""}`,children:[n.jsx("span",{className:"font-medium text-muted-foreground",children:e}),s]})}function LJ({data:e,onRefresh:t,focusService:s,onServiceFocused:i,scopeName:a}){const l=X(),c=e.config.services[0]?.name??"",[u,f]=v.useState(c),[h,p]=v.useState(null),[g,b]=v.useState(!1),{sendToAgent:x,startOnboard:_}=Vt(),[k,C]=v.useState(!1),[E,j]=v.useState(!1),[N,A]=v.useState(!1),[T,D]=v.useState(!1),[z,O]=v.useState(!1),$=v.useRef({}),{error:M,message:I,success:G}=gs(),B=v.useMemo(()=>new Set(e.config.bundles.flatMap(ve=>ve.services)),[e.config.bundles]),U=v.useMemo(()=>{const ve=new Map;for(const Se of e.config.bundles)for(const Ve of Se.services)ve.has(Ve)||ve.set(Ve,Se.name);return ve},[e.config.bundles]),Y=v.useMemo(()=>e.config.services.filter(ve=>!B.has(ve.name)),[e.config.services,B]),P=v.useMemo(()=>e.config.services.map(ve=>ve.name),[e.config.services]),V=v.useMemo(()=>GA(e.config.services,e.config.gitRepositories),[e.config.services,e.config.gitRepositories]),W=v.useMemo(()=>e.config.services.some(ve=>(ve.dependsOn?.length??0)>0),[e.config.services]),re=e.health??{},ce=e.config.bundles.length>0||Y.length>0;v.useEffect(()=>{!e.config.services.some(Se=>Se.name===u)&&c&&f(c)},[e.config.services,c,u]),v.useEffect(()=>{s&&e.config.services.some(ve=>ve.name===s)&&(f(s),i?.())},[s,e.config.services,i]);const F=v.useMemo(()=>e.config.services.find(ve=>ve.name===u),[e.config.services,u]),K=u?e.runtime.services[u]:void 0,ue=u?re[u]:void 0;async function ge(ve,Se){if(!ve.services.includes(Se))try{await az(ve.name,ve.services,Se),G(l("services.toast.addedToGroup",{service:Se,group:ve.name})),await t()}catch(Ve){M(Ve instanceof Error?Ve.message:String(Ve))}}async function J(){if(F){if(wu(K?.state)){M(l("services.toast.stopBeforeDelete",{name:F.name}));return}if(window.confirm(l("services.confirmDelete",{name:F.name})))try{await X9(F.name),G(l("services.toast.deleted",{name:F.name})),await t()}catch(ve){M(ve instanceof Error?ve.message:String(ve))}}}async function ne(ve){const Se=e.config.bundles.filter(Ve=>Ve.services.includes(ve));if(Se.length!==0)try{for(const Ve of Se)await lz(Ve.name,Ve.services,ve);I({text:l("services.toast.removedFromGroups",{service:ve,groups:Se.map(Ve=>Ve.name).join(", ")})}),await t()}catch(Ve){M(Ve instanceof Error?Ve.message:String(Ve))}}v.useEffect(()=>{const ve=Object.fromEntries(e.config.services.map(Ve=>[Ve.name,e.runtime.services[Ve.name]?.state??"stopped"])),Se=$.current;if(Object.keys(Se).length){const Ve=new Map,rt=new Map;for(const Re of e.config.services){const ie=ve[Re.name],Be=Se[Re.name];if(!Be||Be===ie)continue;const We=e.runtime.services[Re.name],He=U.get(Re.name);if(He){const at=Ve.get(He)??new Map;if(at.set(ie,(at.get(ie)??0)+1),Ve.set(He,at),ie==="exited"){const mt=rt.get(He)??[];mt.push(We?.exitCode),rt.set(He,mt)}continue}ie==="running"?G(l("services.toast.running",{name:Re.name})):ie==="stopped"?I({text:l("services.toast.stopped",{name:Re.name})}):ie==="starting"?I({text:l("services.toast.starting",{name:Re.name})}):ie==="exited"&&M(We?.exitCode===void 0||We.exitCode===null?l("services.toast.exited",{name:Re.name}):l("services.toast.exitedWithCode",{name:Re.name,code:We.exitCode}))}for(const[Re,ie]of Ve)PJ({exitCodes:rt.get(Re)??[],groupName:Re,showErrorToast:M,showMessageToast:I,showSuccessToast:G,transitions:ie,t:l})}$.current=ve},[e.config.services,e.runtime.services,U,M,I,G]);const Le=e.config.services.length>0;return n.jsxs(n.Fragment,{children:[!Le&&a?n.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center",children:n.jsxs("div",{className:"max-w-sm text-sm text-muted-foreground",children:[n.jsxs("p",{className:"font-medium text-foreground",children:["No services in ",a]}),n.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."})]})}):Le?n.jsxs("div",{className:se("grid h-full min-h-0 overflow-hidden bg-card/85",N?"lg:grid-cols-[320px_minmax(0,1fr)]":"lg:grid-cols-[320px_minmax(0,1fr)_340px]"),children:[n.jsx("div",{className:"min-h-0 min-w-0 overflow-auto border-r border-border",children:n.jsxs(Di,{className:"min-w-0 rounded-none border-0 border-b border-border bg-transparent",children:[n.jsx(Li,{className:"border-b border-border px-3 py-2",children:n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsx(Oi,{className:"text-sm",children:l("services.title")}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsxs(Q,{"aria-haspopup":"dialog",className:"h-7 gap-1.5 px-2 text-xs",onClick:()=>j(!0),size:"sm",type:"button",variant:"outline",children:[n.jsx(yf,{className:"size-3.5"}),l("services.graph")]}),n.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:[n.jsx(dm,{className:"size-3.5"}),l("services.logs")]}),n.jsx(OJ,{onCreateGroup:()=>p("group"),onCreateService:()=>p("service"),onOnboardRepo:()=>b(!0),onOnboardWithAi:_,canGroupWithAi:Y.length>1,onCreateWithAi:()=>x({prompt:$2,source:{type:"service-setup",label:"Add a service"},label:"Help me add a new service, one step at a time."}),onGroupWithAi:()=>x({prompt:zq(Y),source:{type:"group-services",label:"Group services"},label:"Propose how to group my ungrouped services."})})]})]})}),n.jsxs(Pi,{className:"p-0",children:[!a&&V.length>0?n.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border bg-muted/40 px-3 py-2 text-xs",children:[n.jsx("span",{className:"text-muted-foreground",children:l("services.unassignedNotice",{count:V.length})}),V.map(ve=>n.jsx(Q,{className:"h-6 px-2 text-[11px]",onClick:()=>{f(ve.name),D(!0)},size:"sm",variant:"outline",children:ve.name},ve.name))]}):null,ce?n.jsxs("div",{className:"divide-y divide-border",children:[e.config.bundles.map(ve=>n.jsx(NV,{group:ve,onRefresh:t,ports:e.ports,allServices:e.config.services,health:re,services:e.config.services.filter(Se=>ve.services.includes(Se.name)),statuses:e.runtime.services,timeline:e.timeline,selectedService:u,onSelectService:f,onDropService:Se=>{ge(ve,Se)}},ve.name)),Y.length?n.jsxs("div",{className:se("transition-colors",z&&"bg-primary/5 outline-dashed outline-2 -outline-offset-2 outline-primary/60"),onDragOver:ve=>{ve.dataTransfer.types.includes(Lu)&&(ve.preventDefault(),ve.dataTransfer.dropEffect="move",O(!0))},onDragLeave:()=>O(!1),onDrop:ve=>{ve.preventDefault(),O(!1);const Se=ve.dataTransfer.getData(Lu);Se&&ne(Se)},children:[n.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:[n.jsx("span",{children:l("services.ungrouped")}),n.jsx("span",{className:"text-muted-foreground/80",children:Y.length})]}),n.jsx("div",{className:"divide-y divide-border",children:Y.map(ve=>n.jsx(WA,{service:ve,status:e.runtime.services[ve.name],health:re[ve.name],ports:e.ports,onRefresh:t,timeline:e.timeline,selected:u===ve.name,onSelect:()=>f(ve.name)},ve.name))})]}):null]}):n.jsx(Ul,{label:l("services.empty")})]})]})}),n.jsx("div",{className:"min-h-0 min-w-0 overflow-auto",children:F?n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[n.jsxs("div",{className:"shrink-0 space-y-2 border-b border-border bg-background/60 px-4 py-3",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx("h2",{className:"min-w-0 truncate text-base font-semibold",children:F.name}),n.jsx(KA,{state:K?.state??"stopped"}),n.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[(()=>{const ve=K?.url??(F.port?jV(F.port):void 0);return ve?n.jsx(gr,{label:l("services.openUrl",{url:ve}),children:n.jsx(Q,{"aria-label":l("services.openInBrowser"),className:"size-7",onClick:()=>{pm(ve)},size:"icon",type:"button",variant:"outline",children:n.jsx(Xr,{})})}):null})(),ue?.agentContext&&F?n.jsx(gr,{label:l("services.debugWithAi"),children:n.jsx(Q,{"aria-label":l("services.debugWithAi"),className:"size-7",onClick:()=>x({prompt:Fq({service:F.name,context:ue.agentContext}),source:{type:"service-debug",label:F.name},label:`Debug \`${F.name}\` with its current context.`}),size:"icon",type:"button",variant:"outline",children:n.jsx(cs,{className:"size-3.5"})})}):null,n.jsx(_1,{active:wu(K?.state),baseUrl:`/api/services/${encodeURIComponent(F.name)}`,compact:!0,resourceKind:"service",resourceName:F.name,targetLabel:F.name,onRefresh:t}),n.jsx(Yl,{className:"size-7 border border-border bg-background opacity-100 hover:border-foreground/30",items:[{icon:n.jsx(Il,{className:"size-3.5"}),label:l("services.editService"),onSelect:()=>D(!0)},...wu(K?.state)?[]:[{icon:n.jsx(Xi,{className:"size-3.5 text-destructive"}),label:l("services.deleteService"),onSelect:()=>{J()}}]],label:l("services.moreActions",{name:F.name})}),n.jsx(gr,{label:l(N?"services.showRail":"services.hideRail"),side:"left",children:n.jsx(Q,{"aria-label":l(N?"services.showRail":"services.hideRail"),className:"size-7",onClick:()=>A(ve=>!ve),size:"icon",type:"button",variant:"ghost",children:N?n.jsx(Rj,{}):n.jsx(gn,{})})})]})]}),F.command?n.jsxs("div",{className:"truncate font-mono text-[11px] text-muted-foreground",title:F.command,children:["$ ",F.command]}):null,F.cwd?n.jsx("div",{className:"truncate font-mono text-[11px] text-muted-foreground",title:F.cwd,children:F.cwd}):null,n.jsx(PQ,{health:ue})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:n.jsx(EJ,{serviceName:F.name,status:K,health:ue,timeline:e.timeline??[],onRefresh:t},F.name)})]}):n.jsx(Ul,{label:l("services.selectPrompt")})}),N?null:n.jsxs("div",{className:"min-h-0 overflow-auto border-l border-border",children:[n.jsx($Q,{ports:e.ports}),n.jsx(wQ,{events:e.timeline??[]})]})]}):n.jsx(OQ,{onOnboardRepo:()=>b(!0),onOnboardWithAi:_,onCreateService:()=>p("service"),onCreateWithAi:()=>x({prompt:$2,source:{type:"service-setup",label:"Add a service"},label:"Help me add a new service, one step at a time."})}),T&&F?n.jsx(Kn,{icon:n.jsx(Il,{}),onClose:()=>D(!1),size:"lg",title:l("services.editServiceTitle",{name:F.name}),children:n.jsx(aC,{cwd:e.cwd,initialService:F,availableServices:P,onRefresh:t,repositories:e.config.gitRepositories,onSaved:()=>D(!1)})}):null,h?n.jsx(Kn,{icon:h==="service"?n.jsx(Es,{}):n.jsx(j0,{}),onClose:()=>p(null),size:h==="service"?"lg":"md",title:l(h==="service"?"services.addService":"services.createGroup"),children:h==="service"?n.jsx(aC,{cwd:e.cwd,availableServices:P,onRefresh:t,onSaved:()=>p(null),repositories:e.config.gitRepositories}):n.jsx(VA,{services:Y,onRefresh:t,onSaved:()=>p(null)})}):null,g?n.jsx(AJ,{onClose:()=>b(!1),onRefresh:t}):null,k?n.jsx(sJ,{initialService:u||void 0,onClose:()=>C(!1),services:e.config.services.map(ve=>ve.name)}):null,E?n.jsx(Kn,{icon:n.jsx(yf,{}),onClose:()=>j(!1),size:"lg",title:l("services.depGraphTitle"),children:n.jsx(RQ,{statuses:e.runtime.services,health:re,hasDependencies:W,onSelectService:ve=>{f(ve),j(!1)}})}):null]})}function OJ({onCreateService:e,onCreateGroup:t,onCreateWithAi:s,onGroupWithAi:i,canGroupWithAi:a,onOnboardRepo:l,onOnboardWithAi:c}){const u=X(),[f,h]=v.useState(!1);function p(g){h(!1),g()}return n.jsxs("div",{className:"relative",children:[n.jsx(gr,{label:u("services.add"),side:"bottom",children:n.jsx(Q,{"aria-expanded":f,"aria-haspopup":"menu","aria-label":u("services.addServiceOrGroup"),className:"size-7",onClick:()=>h(g=>!g),size:"icon",type:"button",variant:"ghost",children:n.jsx(Es,{})})}),f?n.jsxs(n.Fragment,{children:[n.jsx("button",{"aria-hidden":!0,className:"fixed inset-0 z-[40] cursor-default",onClick:()=>h(!1),tabIndex:-1,type:"button"}),n.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:[n.jsxs("div",{className:"group flex items-stretch",children:[n.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:()=>p(e),role:"menuitem",type:"button",children:[n.jsx(Es,{}),u("services.createService")]}),n.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:()=>p(s),role:"menuitem",title:u("services.setupWithAiHint"),type:"button",children:[n.jsx(cs,{className:"size-3.5 shrink-0"}),"AI"]})]}),n.jsxs("div",{className:"group flex items-stretch",children:[n.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:()=>p(t),role:"menuitem",type:"button",children:[n.jsx(j0,{}),u("services.createGroup")]}),a?n.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:()=>p(i),role:"menuitem",title:u("services.groupWithAiHint"),type:"button",children:[n.jsx(cs,{className:"size-3.5 shrink-0"}),"AI"]}):null]}),n.jsxs("div",{className:"group flex items-stretch",children:[n.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:()=>p(l),role:"menuitem",type:"button",children:[n.jsx(Mn,{}),u("services.addFromGithub")]}),n.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:()=>p(c),role:"menuitem",title:u("services.onboardWithAiHint"),type:"button",children:[n.jsx(cs,{className:"size-3.5 shrink-0"}),"AI"]})]})]})]}):null]})}function PJ({exitCodes:e,groupName:t,showErrorToast:s,showMessageToast:i,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")i({text:c("services.toast.groupStopped",{name:t})});else if(h==="starting")i({text:c("services.toast.groupStarting",{name:t})});else if(h==="exited"){const p=e.filter(g=>g!=null);s(p.length?c("services.toast.groupExitedWithCode",{name:t,code:p.join(", ")}):c("services.toast.groupExited",{name:t}))}return}const u=[...l.entries()].map(([h,p])=>`${p} ${h}`).join(", "),f=c("services.toast.groupUpdated",{name:t,summary:u});l.has("exited")?s(f):i({text:f})}function zJ({container:e,onClose:t}){const s=X(),[i,a]=v.useState(null),[l,c]=v.useState(null),[u,f]=v.useState(!0);async function h(){f(!0),c(null);try{a(await KP(e.id,500))}catch(p){c(p instanceof Error?p.message:String(p))}finally{f(!1)}}return v.useEffect(()=>{h()},[e.id]),n.jsxs(Kn,{icon:n.jsx(dm,{}),onClose:t,size:"lg",title:s("docker.logs.title",{name:e.name}),children:[n.jsx("div",{className:"mb-2 flex justify-end",children:n.jsxs(Q,{disabled:u,loading:u,onClick:()=>{h()},size:"sm",type:"button",variant:"outline",children:[n.jsx(Mi,{}),s("common.refresh")]})}),l?n.jsx(nt,{variant:"destructive",children:l}):u&&i===null?n.jsxs("div",{className:"flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground",children:[n.jsx(Bt,{className:"size-4 animate-spin"}),s("docker.logs.loading")]}):i?n.jsx("pre",{className:"max-h-[60vh] overflow-auto whitespace-pre-wrap rounded border border-border bg-background p-3 font-mono text-[11px]",children:i}):n.jsx(nt,{variant:"muted",children:s("docker.logs.empty")})]})}const BJ={running:"success",restarting:"warning",exited:"danger",dead:"danger",paused:"outline",created:"outline"};function IJ({container:e,onRefresh:t,onSelect:s,selected:i,stats:a}){const l=X(),[c,u]=v.useState(!1),f=e.state==="running"||e.state==="restarting";return n.jsxs("div",{className:se("grid grid-cols-[minmax(0,1fr)_auto] items-center gap-2 px-3 py-2",i?"bg-muted/70":"hover:bg-muted/40"),children:[n.jsxs("button",{"aria-pressed":i,className:"min-w-0 cursor-pointer rounded-sm text-left",onClick:()=>s(e),type:"button",children:[n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"truncate text-sm font-medium",title:e.name,children:e.name}),n.jsx(Ze,{size:"small",variant:BJ[e.state]??"outline",children:e.state}),e.status?n.jsx("span",{className:"truncate text-[11px] font-normal text-muted-foreground",children:e.status}):null]}),n.jsxs("span",{className:"block truncate text-[11px] text-muted-foreground",children:[n.jsx("span",{title:e.image,children:e.image}),e.service?` · ${e.service}`:"",n.jsxs("span",{className:"font-mono",children:[" · ",e.id.slice(0,12)]})]}),e.ports?n.jsx("span",{className:"block truncate font-mono text-[11px] text-muted-foreground",title:e.ports,children:e.ports}):null,a&&f?n.jsxs("span",{className:"flex flex-wrap items-center gap-x-3 text-[11px] tabular-nums text-muted-foreground",children:[n.jsx("span",{children:l("docker.stats.cpu",{value:zN(a.cpuPercent)})}),n.jsx("span",{children:l("docker.stats.mem",{usage:a.memoryUsage||"—",percent:zN(a.memoryPercent)})}),a.netIo?n.jsx("span",{children:l("docker.stats.net",{value:a.netIo})}):null]}):null]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[n.jsx(gr,{label:l("docker.actions.logs"),children:n.jsx(Q,{"aria-label":l("docker.actions.logs"),className:"size-7",onClick:()=>u(!0),size:"icon",type:"button",variant:"ghost",children:n.jsx(dm,{})})}),n.jsx(BN,{action:f?"restart":"start",container:e,icon:f?n.jsx(Uu,{}):n.jsx(_r,{}),label:l(f?"common.restart":"common.start"),onRefresh:t}),f?n.jsx(BN,{action:"stop",container:e,icon:n.jsx($a,{}),label:l("common.stop"),onRefresh:t}):null]}),c?n.jsx(zJ,{container:e,onClose:()=>u(!1)}):null]})}function zN(e){return e===null?"—":`${e.toFixed(1)}%`}function BN({action:e,container:t,icon:s,label:i,onRefresh:a}){const l=X(),{error:c,success:u}=gs(),{isPending:f,runOperation:h}=Yn(),p=`docker:${t.id}:${e}`,g=f(p);return n.jsx(gr,{label:i,children:n.jsx(Q,{"aria-label":i,className:"size-7",loading:g,loadingLabel:i,onClick:()=>{h({key:p,label:i},async()=>{try{await WP(t.id,e),u(l("docker.actions.done",{label:i,name:t.name})),await a()}catch(b){const x=b instanceof Error?b.message:String(b);c(l("docker.actions.failed",{label:i,name:t.name,message:x}))}})},size:"icon",type:"button",variant:"outline",children:s})})}function HJ({container:e,onClose:t}){const s=X(),[i,a]=v.useState(null),[l,c]=v.useState(null);return v.useEffect(()=>{let u=!1;return a(null),c(null),VP(e.id).then(f=>{u||a(f)}).catch(f=>{u||c(f instanceof Error?f.message:String(f))}),()=>{u=!0}},[e.id]),n.jsxs("aside",{className:"flex h-full min-h-0 flex-col border-l border-border",children:[n.jsxs("header",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-semibold",title:e.name,children:e.name}),n.jsx(gr,{label:s("common.close"),children:n.jsx(Q,{"aria-label":s("common.close"),className:"size-7",onClick:t,size:"icon",type:"button",variant:"ghost",children:n.jsx(Gt,{})})})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:l?n.jsx("p",{className:"p-3 text-xs text-destructive",children:l}):i?n.jsx($J,{detail:i,t:s}):n.jsxs("div",{className:"flex items-center justify-center gap-2 py-12 text-xs text-muted-foreground",children:[n.jsx(Bt,{className:"size-3.5 animate-spin"}),s("docker.detail.loading")]})})]})}function $J({detail:e,t}){return n.jsxs(n.Fragment,{children:[n.jsx(jl,{title:t("docker.detail.overview"),children:n.jsx(Ub,{rows:[[t("docker.detail.image"),e.image],[t("docker.detail.command"),e.command],[t("docker.detail.created"),IN(e.created)],[t("docker.detail.started"),IN(e.startedAt)],[t("docker.detail.restarts"),String(e.restartCount)],[t("docker.detail.id"),e.id.slice(0,12)]]})}),e.ports.length?n.jsx(jl,{title:t("docker.detail.ports"),children:n.jsx(Ub,{rows:e.ports.map(s=>[s.containerPort,s.hostPort||t("docker.detail.notPublished")])})}):null,e.mounts.length?n.jsx(jl,{title:t("docker.detail.mounts"),children:n.jsx("ul",{className:"space-y-1.5",children:e.mounts.map(s=>n.jsxs("li",{className:"min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"truncate font-mono text-[11px]",children:s.destination}),n.jsx(Ze,{size:"small",variant:"outline",children:s.readOnly?"ro":"rw"})]}),n.jsxs("div",{className:"truncate font-mono text-[11px] text-muted-foreground",children:[s.type," · ",s.source]})]},`${s.source}:${s.destination}`))})}):null,e.networks.length?n.jsx(jl,{title:t("docker.detail.networks"),children:n.jsx("div",{className:"flex flex-wrap gap-1",children:e.networks.map(s=>n.jsx(Ze,{size:"small",variant:"outline",children:s},s))})}):null,e.env.length?n.jsx(jl,{title:t("docker.detail.env"),children:n.jsx("ul",{className:"space-y-1",children:e.env.map(s=>n.jsxs("li",{className:"min-w-0 font-mono text-[11px]",children:[n.jsxs("span",{className:"text-muted-foreground",children:[s.key,"="]}),n.jsx("span",{className:"break-all",children:s.value}),s.secret?n.jsx(gr,{label:t("docker.detail.masked"),children:n.jsx(om,{className:"ml-1 inline size-3 text-muted-foreground"})}):null]},s.key))})}):null,Object.keys(e.labels).length?n.jsx(jl,{title:t("docker.detail.labels"),children:n.jsx(Ub,{rows:Object.entries(e.labels),mono:!0})}):null]})}function jl({title:e,children:t}){return n.jsxs("section",{className:"border-b border-border px-3 py-2.5",children:[n.jsx("h3",{className:"mb-1.5 text-[10px] font-semibold uppercase tracking-widest text-muted-foreground",children:e}),t]})}function Ub({rows:e,mono:t=!1}){return n.jsx("dl",{className:"grid grid-cols-[minmax(0,auto)_minmax(0,1fr)] gap-x-3 gap-y-1 text-[11px]",children:e.map(([s,i])=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{className:"truncate text-muted-foreground",title:s,children:s}),n.jsx("dd",{className:`min-w-0 break-all ${t?"font-mono":""}`,children:i||"—"})]},s))})}function IN(e){if(!e)return"";const t=new Date(e);return Number.isNaN(t.getTime())?e:t.getUTCFullYear()<=1?"":t.toLocaleString()}function FJ(){const[e,t]=v.useState(null),[s,i]=v.useState([]),[a,l]=v.useState(!0),[c,u]=v.useState(null),f=v.useCallback(async()=>{l(!0),u(null);try{const h=await HP();t(h),i(h.available?await $P():[])}catch(h){u(h instanceof Error?h.message:String(h))}finally{l(!1)}},[]);return v.useEffect(()=>{f()},[f]),{status:e,containers:s,loading:a,error:c,refresh:f}}function UJ(e,t=5e3){const[s,i]=v.useState(new Map),a=v.useRef(e);return a.current=e,v.useEffect(()=>{if(!e)return;let l=!1;const c=async()=>{try{const f=await FP();if(l||!a.current)return;i(new Map(f.map(h=>[h.id,h])))}catch{}};c();const u=setInterval(()=>{c()},t);return()=>{l=!0,clearInterval(u)}},[e,t]),v.useCallback(l=>{const c=s.get(l);if(c)return c;for(const[u,f]of s)if(u.startsWith(l)||l.startsWith(u))return f},[s])}function qJ(e){const t=new Map,s=[];for(const a of e){if(!a.project){s.push(a);continue}const l=t.get(a.project)??[];l.push(a),t.set(a.project,l)}const i=[...t.entries()].sort(([a],[l])=>a.localeCompare(l)).map(([a,l])=>({project:a,containers:l}));return s.length&&i.push({project:null,containers:s}),i}function z1(e,t){const[s,i]=v.useState([]),[a,l]=v.useState(!1),[c,u]=v.useState(null),f=v.useRef(e);f.current=e;const h=v.useCallback(async()=>{l(!0),u(null);try{i(await f.current())}catch(p){u(p instanceof Error?p.message:String(p))}finally{l(!1)}},[]);return v.useEffect(()=>{t&&h()},[t,h]),v.useMemo(()=>({rows:s,loading:a,error:c,reload:h}),[s,a,c,h])}function GJ({active:e}){const t=X(),{rows:s,loading:i,error:a}=z1(UP,e);return n.jsx(B1,{columns:[t("docker.images.repository"),t("docker.images.tag"),t("docker.images.size"),t("docker.images.created")],empty:t("docker.images.empty"),error:a,loading:i,rowCount:s.length,children:s.map(l=>n.jsxs("tr",{className:"hover:bg-muted/40",children:[n.jsx(mr,{children:n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"truncate",children:l.repository}),l.dangling?n.jsx(Ze,{size:"small",variant:"outline",children:t("docker.images.dangling")}):null]})}),n.jsx(mr,{mono:!0,children:l.tag}),n.jsx(mr,{children:l.size}),n.jsx(mr,{muted:!0,children:l.createdSince})]},l.id+l.tag))})}function VJ({active:e}){const t=X(),{rows:s,loading:i,error:a}=z1(qP,e);return n.jsx(B1,{columns:[t("docker.volumes.name"),t("docker.volumes.driver"),t("docker.volumes.mountpoint")],empty:t("docker.volumes.empty"),error:a,loading:i,rowCount:s.length,children:s.map(l=>n.jsxs("tr",{className:"hover:bg-muted/40",children:[n.jsx(mr,{mono:!0,children:l.name}),n.jsx(mr,{children:l.driver}),n.jsx(mr,{mono:!0,muted:!0,children:l.mountpoint})]},l.name))})}function WJ({active:e}){const t=X(),{rows:s,loading:i,error:a}=z1(GP,e);return n.jsx(B1,{columns:[t("docker.networks.name"),t("docker.networks.driver"),t("docker.networks.scope")],empty:t("docker.networks.empty"),error:a,loading:i,rowCount:s.length,children:s.map(l=>n.jsxs("tr",{className:"hover:bg-muted/40",children:[n.jsx(mr,{children:l.name}),n.jsx(mr,{children:l.driver}),n.jsx(mr,{muted:!0,children:l.scope})]},l.id))})}function B1({children:e,columns:t,empty:s,error:i,loading:a,rowCount:l}){const c=X();return i?n.jsx("p",{className:"p-3 text-xs text-destructive",children:i}):a&&l===0?n.jsxs("div",{className:"flex items-center justify-center gap-2 py-16 text-sm text-muted-foreground",children:[n.jsx(Bt,{className:"size-4 animate-spin"}),c("docker.loading")]}):l===0?n.jsx(Ul,{label:s}):n.jsxs("table",{className:"w-full text-left text-xs",children:[n.jsx("thead",{className:"sticky top-0 z-10 bg-muted/60 text-muted-foreground backdrop-blur",children:n.jsx("tr",{children:t.map(u=>n.jsx("th",{className:"px-3 py-2 font-medium",scope:"col",children:u},u))})}),n.jsx("tbody",{className:"divide-y divide-border",children:e})]})}function mr({children:e,mono:t=!1,muted:s=!1}){return n.jsx("td",{className:`max-w-0 truncate px-3 py-1.5 ${t?"font-mono":""} ${s?"text-muted-foreground":""}`,children:e})}const KJ=[{id:"containers",labelKey:"docker.tabContainers"},{id:"images",labelKey:"docker.tabImages"},{id:"volumes",labelKey:"docker.tabVolumes"},{id:"networks",labelKey:"docker.tabNetworks"}];function YJ(){const e=X(),{status:t,containers:s,loading:i,error:a,refresh:l}=FJ(),[c,u]=v.useState("containers"),[f,h]=v.useState(null);$o(l);const p=t?.available===!0,g=UJ(p&&c==="containers"),b=s.filter(x=>x.state==="running"||x.state==="restarting").length;return n.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[n.jsxs("header",{className:"flex shrink-0 flex-wrap items-center gap-2 border-b border-border px-3 py-2",children:[n.jsx(am,{className:"size-4 text-muted-foreground"}),n.jsx("span",{className:"text-sm font-semibold",children:e("nav.docker")}),n.jsx("div",{className:"ml-2 flex items-center gap-0.5 rounded-md border border-border bg-muted/40 p-0.5",children:KJ.map(x=>n.jsx("button",{className:se("flex h-6 items-center rounded px-2.5 text-xs font-medium transition-colors",c===x.id?"bg-background shadow-sm":"text-muted-foreground hover:bg-muted/60 hover:text-foreground"),onClick:()=>u(x.id),type:"button",children:e(x.labelKey)},x.id))}),c==="containers"&&s.length?n.jsx("span",{className:"text-xs tabular-nums text-muted-foreground",children:e("docker.runningCount",{running:String(b),total:String(s.length)})}):null,t?.version?n.jsxs("span",{className:"text-[11px] tabular-nums text-muted-foreground",children:["v",t.version]}):null,n.jsxs(Q,{className:"ml-auto h-7 gap-1.5 px-2 text-xs",onClick:()=>{l()},size:"sm",type:"button",variant:"outline",children:[n.jsx(Mi,{className:"size-3.5"}),e("common.refresh")]})]}),a?n.jsx(nt,{className:"m-3 shrink-0",variant:"destructive",children:a}):null,i&&t===null?n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(Bt,{className:"size-4 animate-spin"}),e("docker.loading")]}):t&&!p?n.jsx(XJ,{error:t.error}):c==="containers"?n.jsxs("div",{className:se("grid min-h-0 flex-1 overflow-hidden",f?"lg:grid-cols-[minmax(0,1fr)_340px]":"grid-cols-1"),children:[n.jsx("div",{className:"min-h-0 overflow-auto",children:n.jsx(ZJ,{containers:s,onRefresh:l,onSelect:x=>h(_=>_?.id===x.id?null:x),selectedId:f?.id??null,statsFor:g})}),f?n.jsx("div",{className:"hidden min-h-0 lg:block",children:n.jsx(HJ,{container:f,onClose:()=>h(null)})}):null]}):n.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[c==="images"?n.jsx(GJ,{active:!0}):null,c==="volumes"?n.jsx(VJ,{active:!0}):null,c==="networks"?n.jsx(WJ,{active:!0}):null]})]})}function XJ({error:e}){const t=X();return n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:n.jsxs(nt,{className:"m-3",variant:"muted",children:[n.jsx(am,{}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium text-foreground",children:t("docker.unavailable.title")}),n.jsx("p",{className:"mt-1 text-muted-foreground",children:t("docker.unavailable.body")}),e?n.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre-wrap rounded border border-border bg-background p-2 font-mono text-[11px] text-muted-foreground",children:e}):null]})]})})}function ZJ({containers:e,onRefresh:t,onSelect:s,selectedId:i,statsFor:a}){const l=X(),c=qJ(e);return c.length?n.jsx("div",{className:"divide-y divide-border",children:c.map(u=>n.jsxs("section",{children:[n.jsxs("div",{className:"sticky top-0 z-10 flex items-center gap-2 border-b border-border bg-muted/60 px-3 py-1.5 text-xs font-medium backdrop-blur",children:[u.project??l("docker.otherContainers"),n.jsx("span",{className:"tabular-nums text-muted-foreground",children:u.containers.length})]}),n.jsx("div",{className:"divide-y divide-border",children:u.containers.map(f=>n.jsx(IJ,{container:f,onRefresh:t,onSelect:s,selected:i===f.id,stats:a(f.id)},f.id))})]},u.project??"__ungrouped__"))}):n.jsx(Ul,{label:l("docker.empty")})}function QJ({data:e,onOpenService:t}){const s=X(),i=v.useMemo(()=>JJ(e,s("services.startingEllipsis")),[e,s]);return i.length?n.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:[n.jsxs("span",{className:"flex shrink-0 items-center gap-1.5 font-mono text-[10px] uppercase tracking-wider text-muted-foreground",children:[n.jsx(jo,{className:"size-3"}),s("services.stripeRunning")]}),n.jsx("div",{className:"flex min-w-0 items-center gap-2",children:i.map(a=>n.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:[n.jsx("span",{className:se("size-2 shrink-0 rounded-full",tee(a.tone))}),n.jsx("span",{className:"max-w-40 truncate font-medium text-foreground",children:a.name}),a.port?n.jsxs("span",{className:"text-muted-foreground",children:[":",a.port]}):null,a.uptime?n.jsxs("span",{className:"text-muted-foreground/70",children:["↑",a.uptime]}):null]},a.name))})]}):null}function JJ(e,t){const s=new Map(e.config.services.map(i=>[i.name,i.port]));return Object.values(e.runtime.services).filter(i=>i.state==="running"||i.state==="starting").map(i=>({name:i.name,tone:eee(i,e.health[i.name]),port:s.get(i.name)??see(i.url),uptime:i.state==="running"?nee(i.startedAt):t,url:i.url})).sort((i,a)=>i.name.localeCompare(a.name))}function eee(e,t){return e.state==="starting"?"starting":t?.status==="healthy"?"healthy":t?.status==="warning"?"warning":t?.status==="unhealthy"?"unhealthy":"healthy"}function tee(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 see(e){if(e)try{const t=new URL(e).port;return t?Number(t):void 0}catch{return}}function nee(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 i=Math.floor(s/60);if(i<60)return`${i}m`;const a=Math.floor(i/60),l=i%60;return a<24?`${a}h${l?`${l}m`:""}`:`${Math.floor(a/24)}d${a%24?`${a%24}h`:""}`}function iee(){const e=X(),{confirmedGlobal:t}=Lm(),[s,i]=v.useState([]),[a,l]=v.useState(null),[c,u]=v.useState(!1),[f,h]=v.useState(null);v.useEffect(()=>{let x=!1;return(async()=>{let _=await x3().catch(()=>[]);if(_.length===0){const k=await bu().catch(()=>null);_=k?[k]:[]}x||(i(_),l(_[0]?.id??null))})(),()=>{x=!0}},[]);const p=v.useCallback(async()=>{u(!0);try{const x=await bu();i(_=>[..._,x]),l(x.id)}finally{u(!1)}},[]),g=v.useCallback(async x=>{u(!0);try{await Jv(x);const _=s.findIndex(C=>C.id===x),k=s.filter(C=>C.id!==x);if(k.length===0){const C=await bu();i([C]),l(C.id);return}if(i(k),a===x){const C=k[Math.min(_,k.length-1)];l(C.id)}}finally{u(!1)}},[s,a]),b=v.useCallback((x,_)=>{if(t.terminal.confirmTerminate){h({id:x,name:_});return}g(x)},[g,t.terminal.confirmTerminate]);return n.jsxs("section",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[n.jsxs("div",{"aria-label":e("terminal.tabs"),className:"flex shrink-0 items-center gap-1 overflow-x-auto border-b border-border bg-card px-2 py-1.5",role:"tablist",children:[s.map((x,_)=>{const k=x.label??e("terminal.tabName",{n:_+1});return n.jsxs("div",{className:se("group flex items-center gap-1 rounded-md border border-transparent px-2 py-1 text-xs",x.id===a?"border-border bg-muted text-foreground":"text-muted-foreground hover:bg-muted/60 hover:text-foreground"),children:[n.jsx("button",{"aria-selected":x.id===a,className:"max-w-[160px] truncate font-medium",onClick:()=>l(x.id),role:"tab",type:"button",children:k}),n.jsx("button",{"aria-label":e("terminal.closeTab",{name:k}),className:"rounded p-0.5 text-muted-foreground opacity-0 transition hover:bg-muted hover:text-foreground group-hover:opacity-100",disabled:c,onClick:()=>b(x.id,k),type:"button",children:n.jsx(Gt,{className:"size-3"})})]},x.id)}),n.jsx("button",{"aria-label":e("terminal.newTerminal"),className:"ml-1 rounded-md p-1 text-muted-foreground transition hover:bg-muted hover:text-foreground disabled:opacity-40",disabled:c,onClick:()=>{p()},type:"button",children:n.jsx(Es,{className:"size-4"})})]}),n.jsx("div",{className:"relative min-h-0 flex-1",children:s.length===0?n.jsx("div",{className:"flex h-full items-center justify-center font-mono text-[11px] text-muted-foreground",children:e("terminal.starting")}):s.map(x=>n.jsx("div",{className:"absolute inset-0",children:n.jsx(mR,{active:x.id===a,sessionId:x.id})},x.id))}),f?n.jsx(Xl,{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 x=f.id;h(null),g(x)},title:`Close ${f.name}?`,tone:"danger"}):null]})}function pR({branch:e}){return n.jsx("span",{className:"min-w-0 max-w-40",title:e,children:n.jsx(Ze,{className:"w-full max-w-full shadow-none",variant:"outline",children:e})})}function gR({branch:e,error:t,files:s,selectedFile:i,onSelectFile:a,root:l,staging:c}){const u=X(),f=v.useMemo(()=>lee(s).filter(g=>g.files.length),[s]),[h,p]=v.useState({staged:!1,unstaged:!1,untracked:!1});return n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[n.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:[n.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-[12px] font-semibold tracking-tight",children:[n.jsx(Mn,{className:"size-3.5"}),n.jsx("span",{className:"truncate",children:u("git.tab.changes")})]}),n.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[e?n.jsx(pR,{branch:e}):null,n.jsx(Ze,{variant:"secondary",children:s.length})]})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-auto py-1",children:f.length?f.map(g=>n.jsx(ree,{collapsed:h[g.id],group:g,onSelectFile:a,onToggle:()=>p(b=>({...b,[g.id]:!b[g.id]})),root:l,selectedFile:i,staging:c},g.id)):n.jsx(nt,{variant:"muted",className:"m-3 text-center",children:t??u("git.noChangedFiles")})})]})}function ree({collapsed:e,group:t,onSelectFile:s,onToggle:i,root:a,selectedFile:l,staging:c}){const u=X(),f=e?gn:kn,h=t.files.map(g=>g.path),p=c?t.id==="staged"?{label:u("git.stageArea.unstageAll"),run:()=>c.onUnstage(h)}:{label:u("git.stageArea.stageAll"),run:()=>c.onStage(h)}:null;return n.jsxs("section",{className:"border-b border-border last:border-b-0",children:[n.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:[n.jsxs("button",{className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",onClick:i,type:"button",children:[n.jsx(f,{className:"size-3.5"}),n.jsx("span",{className:"truncate",children:u(t.labelKey)})]}),p?n.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:p.run,type:"button",children:p.label}):null,n.jsx(Ze,{className:"min-w-6 justify-center font-mono shadow-none",size:"small",variant:"outline",children:t.files.length})]}),e?null:n.jsx("div",{children:t.files.map(g=>n.jsx(aee,{active:l===g.path,file:g,group:t.id,onClick:()=>s(g.path),root:a,staging:c},g.path))})]})}function aee({active:e,file:t,group:s,onClick:i,root:a,staging:l}){const c=X(),u=t.path.split("/").pop()||t.path,f=t.path.split("/").slice(0,-1).join("/"),h=a?UA(Xu(a,t.path)):{},p=s==="staged";return n.jsxs("div",{className:se("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:[n.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:i,type:"button",...h,children:[n.jsx(L1,{path:t.path}),n.jsxs("span",{className:"flex min-w-0 flex-1 items-baseline gap-1.5 truncate",children:[n.jsx("span",{"data-testid":"changed-file-name",className:"shrink-0 truncate",children:u}),f?n.jsx("span",{"data-testid":"changed-file-dir",className:"min-w-0 truncate text-muted-foreground",children:f}):null]})]}),l?n.jsx("button",{"aria-label":p?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:()=>p?l.onUnstage([t.path]):l.onStage([t.path]),title:c(p?"git.stageArea.unstage":"git.stageArea.stage"),type:"button",children:p?n.jsx(Uj,{className:"size-3.5"}):n.jsx(Es,{className:"size-3.5"})}):null,n.jsx("span",{className:se("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:oee(t,s)})]})}function oee(e,t){return t==="untracked"?"?":t==="staged"?e.index.trim():e.workingTree.trim()}function lee(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 bR({branch:e,files:t,onDone:s,repo:i}){const a=X(),{sendToAgent:l}=Vt(),[c,u]=v.useState(""),[f,h]=v.useState(null),[p,g]=v.useState(null),[b,x]=v.useState(null),_=v.useMemo(()=>t.filter(j=>j.index.trim()&&j.index!=="?").map(j=>j.path),[t]),k=_.length>0&&c.trim().length>0&&f===null;async function C(j,N){h(j),g(null),x(null);try{if(await h3(c.trim(),i),N){const A=await gm(i);x(a("git.commit.committedPushed",{branch:A.branch}))}else x(a("git.commit.committed"));u(""),s()}catch(A){g(A instanceof Error?A.message:String(A))}finally{h(null)}}function E(){l({prompt:Dq({branch:e,stagedFiles:_}),source:{type:"git-commit",label:a("git.commit.sourceLabel")},mode:"send",label:a("git.commit.suggestLabel")})}return n.jsxs("div",{className:"shrink-0 space-y-2 border-t border-border bg-card/95 p-2.5",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-tight text-muted-foreground",children:a("git.commit.title")}),n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-[11px] text-muted-foreground",children:a("git.commit.stagedCount",{count:_.length})}),n.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:E,title:a("git.commit.suggestTitle"),type:"button",children:[n.jsx(cs,{className:"size-3.5"}),a("git.commit.aiMessage")]})]})]}),n.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:j=>{u(j.target.value),g(null),x(null)},placeholder:_.length?a("git.commit.messagePlaceholder"):a("git.commit.stagePrompt"),value:c}),n.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[n.jsxs(Q,{disabled:!k,onClick:()=>{C("commit",!1)},size:"sm",type:"button",variant:"outline",children:[f==="commit"?n.jsx(Bt,{className:"size-3.5 animate-spin"}):n.jsx(rn,{className:"size-3.5"}),a("git.commit.commit")]}),n.jsxs(Q,{disabled:!k,onClick:()=>{C("push",!0)},size:"sm",type:"button",children:[f==="push"?n.jsx(Bt,{className:"size-3.5 animate-spin"}):n.jsx(fm,{className:"size-3.5"}),a("git.commit.commitPush")]})]}),p?n.jsx(nt,{className:"px-2.5 py-1.5 text-[11px]",variant:"destructive",children:p}):b?n.jsx(nt,{className:"px-2.5 py-1.5 text-[11px]",variant:"muted",children:b}):null]})}function cee(e){const t={name:"",path:"",children:[],isFile:!1},s=new Map;s.set("",t);const i=[...e].sort();for(const l of i){const c=l.split("/");let u="";for(let f=0;f<c.length;f+=1){const h=c[f],p=f===c.length-1,g=u?`${u}/${h}`:h;let b=s.get(g);b||(b={name:h,path:g,children:[],isFile:p},s.set(g,b),s.get(u)?.children.push(b)),u=g}}const a=l=>{l.children.sort((c,u)=>c.isFile!==u.isFile?c.isFile?1:-1:c.name.localeCompare(u.name)),l.children.forEach(a)};return a(t),t}function HN(e,t){const s={"":!0},i=a=>{for(const l of a.children)l.isFile||(s[l.path]=!0,t&&i(l))};return i(e),s}function $N({defaultExpandAll:e=!1,paths:t,status:s,selectedFile:i,onSelectFile:a,branch:l,emptyMessage:c,root:u,title:f}){const h=X(),p=f??h("git.tree.filesDefault"),g=c??h("git.tree.emptyDefault"),b=v.useMemo(()=>cee(t),[t]),x=v.useMemo(()=>HN(b,e),[e,b]),_=v.useMemo(()=>HN(b,!0),[b]),k=Math.max(0,Object.keys(_).length-1),C=v.useMemo(()=>{const O=new Map;for(const $ of s)O.set($.path,$);return O},[s]),[E,j]=v.useState(x),[N,A]=v.useState(!1);v.useEffect(()=>{N||b.children.length===0||(j(x),A(!0))},[x,N,b.children.length]);function T(O){j($=>({...$,[O]:!$[O]}))}function D(){j(_)}function z(){j({"":!0})}return n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[n.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:[n.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-[12px] font-semibold tracking-tight",children:[n.jsx(Io,{className:"size-3.5"}),n.jsx("span",{className:"truncate",children:p})]}),n.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[k>0?n.jsxs("span",{className:"flex items-center gap-0.5",children:[n.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:D,title:h("git.tree.expandAll"),type:"button",children:n.jsx(j8,{className:"size-3.5"})}),n.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:z,title:h("git.tree.collapseAll"),type:"button",children:n.jsx(N8,{className:"size-3.5"})})]}):null,l?n.jsx(pR,{branch:l}):null,n.jsx(Ze,{variant:"secondary",children:t.length})]})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-auto py-1",children:b.children.length===0?n.jsx(nt,{variant:"muted",className:"m-3 text-center",children:g}):b.children.map(O=>n.jsx(vR,{depth:0,expanded:E,node:O,onSelectFile:a,onToggle:T,root:u,selectedFile:i,statusByPath:C},O.path))})]})}function vR({depth:e,expanded:t,node:s,onSelectFile:i,onToggle:a,root:l,selectedFile:c,statusByPath:u}){const f=t[s.path]??!1,h=6+e*12,p=l?UA(Xu(l,s.path)):{};if(s.isFile){const x=u.get(s.path),_=c===s.path;return n.jsxs("button",{className:se("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:()=>i(s.path),style:{paddingLeft:h},type:"button",...p,children:[n.jsx(L1,{path:s.path}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:s.name}),x?n.jsx(uee,{file:x}):null]})}const g=f?kn:gn,b=f?cm:Io;return n.jsxs("div",{children:[n.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",...p,children:[n.jsx(g,{className:"size-3.5 shrink-0 text-muted-foreground"}),n.jsx(b,{className:"size-3.5 shrink-0 text-amber-600"}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:s.name})]}),f?s.children.map(x=>n.jsx(vR,{depth:e+1,expanded:t,node:x,onSelectFile:i,onToggle:a,root:l,selectedFile:c,statusByPath:u},x.path)):null]})}function uee({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 n.jsx("span",{className:se("ml-1 shrink-0 font-mono text-[10px] font-semibold",s),children:t})}var qb,FN;function dee(){if(FN)return qb;FN=1;function e(q){return q instanceof Map?q.clear=q.delete=q.set=function(){throw new Error("map is read-only")}:q instanceof Set&&(q.add=q.clear=q.delete=function(){throw new Error("set is read-only")}),Object.freeze(q),Object.getOwnPropertyNames(q).forEach(le=>{const Pe=q[le],Ye=typeof Pe;(Ye==="object"||Ye==="function")&&!Object.isFrozen(Pe)&&e(Pe)}),q}class t{constructor(le){le.data===void 0&&(le.data={}),this.data=le.data,this.isMatchIgnored=!1}ignoreMatch(){this.isMatchIgnored=!0}}function s(q){return q.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function i(q,...le){const Pe=Object.create(null);for(const Ye in q)Pe[Ye]=q[Ye];return le.forEach(function(Ye){for(const Nt in Ye)Pe[Nt]=Ye[Nt]}),Pe}const a="</span>",l=q=>!!q.scope,c=(q,{prefix:le})=>{if(q.startsWith("language:"))return q.replace("language:","language-");if(q.includes(".")){const Pe=q.split(".");return[`${le}${Pe.shift()}`,...Pe.map((Ye,Nt)=>`${Ye}${"_".repeat(Nt+1)}`)].join(" ")}return`${le}${q}`};class u{constructor(le,Pe){this.buffer="",this.classPrefix=Pe.classPrefix,le.walk(this)}addText(le){this.buffer+=s(le)}openNode(le){if(!l(le))return;const Pe=c(le.scope,{prefix:this.classPrefix});this.span(Pe)}closeNode(le){l(le)&&(this.buffer+=a)}value(){return this.buffer}span(le){this.buffer+=`<span class="${le}">`}}const f=(q={})=>{const le={children:[]};return Object.assign(le,q),le};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(le){this.top.children.push(le)}openNode(le){const Pe=f({scope:le});this.add(Pe),this.stack.push(Pe)}closeNode(){if(this.stack.length>1)return this.stack.pop()}closeAllNodes(){for(;this.closeNode(););}toJSON(){return JSON.stringify(this.rootNode,null,4)}walk(le){return this.constructor._walk(le,this.rootNode)}static _walk(le,Pe){return typeof Pe=="string"?le.addText(Pe):Pe.children&&(le.openNode(Pe),Pe.children.forEach(Ye=>this._walk(le,Ye)),le.closeNode(Pe)),le}static _collapse(le){typeof le!="string"&&le.children&&(le.children.every(Pe=>typeof Pe=="string")?le.children=[le.children.join("")]:le.children.forEach(Pe=>{h._collapse(Pe)}))}}class p extends h{constructor(le){super(),this.options=le}addText(le){le!==""&&this.add(le)}startScope(le){this.openNode(le)}endScope(){this.closeNode()}__addSublanguage(le,Pe){const Ye=le.root;Pe&&(Ye.scope=`language:${Pe}`),this.add(Ye)}toHTML(){return new u(this,this.options).value()}finalize(){return this.closeAllNodes(),!0}}function g(q){return q?typeof q=="string"?q:q.source:null}function b(q){return k("(?=",q,")")}function x(q){return k("(?:",q,")*")}function _(q){return k("(?:",q,")?")}function k(...q){return q.map(Pe=>g(Pe)).join("")}function C(q){const le=q[q.length-1];return typeof le=="object"&&le.constructor===Object?(q.splice(q.length-1,1),le):{}}function E(...q){return"("+(C(q).capture?"":"?:")+q.map(Ye=>g(Ye)).join("|")+")"}function j(q){return new RegExp(q.toString()+"|").exec("").length-1}function N(q,le){const Pe=q&&q.exec(le);return Pe&&Pe.index===0}const A=/\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;function T(q,{joinWith:le}){let Pe=0;return q.map(Ye=>{Pe+=1;const Nt=Pe;let Dt=g(Ye),Qe="";for(;Dt.length>0;){const Ke=A.exec(Dt);if(!Ke){Qe+=Dt;break}Qe+=Dt.substring(0,Ke.index),Dt=Dt.substring(Ke.index+Ke[0].length),Ke[0][0]==="\\"&&Ke[1]?Qe+="\\"+String(Number(Ke[1])+Nt):(Qe+=Ke[0],Ke[0]==="("&&Pe++)}return Qe}).map(Ye=>`(${Ye})`).join(le)}const D=/\b\B/,z="[a-zA-Z]\\w*",O="[a-zA-Z_]\\w*",$="\\b\\d+(\\.\\d+)?",M="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",I="\\b(0b[01]+)",G="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",B=(q={})=>{const le=/^#![ ]*\//;return q.binary&&(q.begin=k(le,/.*\b/,q.binary,/\b.*/)),i({scope:"meta",begin:le,end:/$/,relevance:0,"on:begin":(Pe,Ye)=>{Pe.index!==0&&Ye.ignoreMatch()}},q)},U={begin:"\\\\[\\s\\S]",relevance:0},Y={scope:"string",begin:"'",end:"'",illegal:"\\n",contains:[U]},P={scope:"string",begin:'"',end:'"',illegal:"\\n",contains:[U]},V={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/},W=function(q,le,Pe={}){const Ye=i({scope:"comment",begin:q,end:le,contains:[]},Pe);Ye.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 Nt=E("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 Ye.contains.push({begin:k(/[ ]+/,"(",Nt,/[.]?[:]?([.][ ]|[ ])/,"){3}")}),Ye},re=W("//","$"),ce=W("/\\*","\\*/"),F=W("#","$"),K={scope:"number",begin:$,relevance:0},ue={scope:"number",begin:M,relevance:0},ge={scope:"number",begin:I,relevance:0},J={scope:"regexp",begin:/\/(?=[^/\n]*\/)/,end:/\/[gimuy]*/,contains:[U,{begin:/\[/,end:/\]/,relevance:0,contains:[U]}]},ne={scope:"title",begin:z,relevance:0},Le={scope:"title",begin:O,relevance:0},ve={begin:"\\.\\s*"+O,relevance:0};var Ve=Object.freeze({__proto__:null,APOS_STRING_MODE:Y,BACKSLASH_ESCAPE:U,BINARY_NUMBER_MODE:ge,BINARY_NUMBER_RE:I,COMMENT:W,C_BLOCK_COMMENT_MODE:ce,C_LINE_COMMENT_MODE:re,C_NUMBER_MODE:ue,C_NUMBER_RE:M,END_SAME_AS_BEGIN:function(q){return Object.assign(q,{"on:begin":(le,Pe)=>{Pe.data._beginMatch=le[1]},"on:end":(le,Pe)=>{Pe.data._beginMatch!==le[1]&&Pe.ignoreMatch()}})},HASH_COMMENT_MODE:F,IDENT_RE:z,MATCH_NOTHING_RE:D,METHOD_GUARD:ve,NUMBER_MODE:K,NUMBER_RE:$,PHRASAL_WORDS_MODE:V,QUOTE_STRING_MODE:P,REGEXP_MODE:J,RE_STARTERS_RE:G,SHEBANG:B,TITLE_MODE:ne,UNDERSCORE_IDENT_RE:O,UNDERSCORE_TITLE_MODE:Le});function rt(q,le){q.input[q.index-1]==="."&&le.ignoreMatch()}function Re(q,le){q.className!==void 0&&(q.scope=q.className,delete q.className)}function ie(q,le){le&&q.beginKeywords&&(q.begin="\\b("+q.beginKeywords.split(" ").join("|")+")(?!\\.)(?=\\b|\\s)",q.__beforeBegin=rt,q.keywords=q.keywords||q.beginKeywords,delete q.beginKeywords,q.relevance===void 0&&(q.relevance=0))}function Be(q,le){Array.isArray(q.illegal)&&(q.illegal=E(...q.illegal))}function We(q,le){if(q.match){if(q.begin||q.end)throw new Error("begin & end are not supported with match");q.begin=q.match,delete q.match}}function He(q,le){q.relevance===void 0&&(q.relevance=1)}const at=(q,le)=>{if(!q.beforeMatch)return;if(q.starts)throw new Error("beforeMatch cannot be used with starts");const Pe=Object.assign({},q);Object.keys(q).forEach(Ye=>{delete q[Ye]}),q.keywords=Pe.keywords,q.begin=k(Pe.beforeMatch,b(Pe.begin)),q.starts={relevance:0,contains:[Object.assign(Pe,{endsParent:!0})]},q.relevance=0,delete Pe.beforeMatch},mt=["of","and","for","in","not","or","if","then","parent","list","value"],ht="keyword";function xt(q,le,Pe=ht){const Ye=Object.create(null);return typeof q=="string"?Nt(Pe,q.split(" ")):Array.isArray(q)?Nt(Pe,q):Object.keys(q).forEach(function(Dt){Object.assign(Ye,xt(q[Dt],le,Dt))}),Ye;function Nt(Dt,Qe){le&&(Qe=Qe.map(Ke=>Ke.toLowerCase())),Qe.forEach(function(Ke){const pt=Ke.split("|");Ye[pt[0]]=[Dt,is(pt[0],pt[1])]})}}function is(q,le){return le?Number(le):Qs(q)?0:1}function Qs(q){return mt.includes(q.toLowerCase())}const us={},It=q=>{console.error(q)},Ts=(q,...le)=>{console.log(`WARN: ${q}`,...le)},Wt=(q,le)=>{us[`${q}/${le}`]||(console.log(`Deprecated as of ${q}. ${le}`),us[`${q}/${le}`]=!0)},ot=new Error;function S(q,le,{key:Pe}){let Ye=0;const Nt=q[Pe],Dt={},Qe={};for(let Ke=1;Ke<=le.length;Ke++)Qe[Ke+Ye]=Nt[Ke],Dt[Ke+Ye]=!0,Ye+=j(le[Ke-1]);q[Pe]=Qe,q[Pe]._emit=Dt,q[Pe]._multi=!0}function te(q){if(Array.isArray(q.begin)){if(q.skip||q.excludeBegin||q.returnBegin)throw It("skip, excludeBegin, returnBegin not compatible with beginScope: {}"),ot;if(typeof q.beginScope!="object"||q.beginScope===null)throw It("beginScope must be object"),ot;S(q,q.begin,{key:"beginScope"}),q.begin=T(q.begin,{joinWith:""})}}function me(q){if(Array.isArray(q.end)){if(q.skip||q.excludeEnd||q.returnEnd)throw It("skip, excludeEnd, returnEnd not compatible with endScope: {}"),ot;if(typeof q.endScope!="object"||q.endScope===null)throw It("endScope must be object"),ot;S(q,q.end,{key:"endScope"}),q.end=T(q.end,{joinWith:""})}}function de(q){q.scope&&typeof q.scope=="object"&&q.scope!==null&&(q.beginScope=q.scope,delete q.scope)}function be(q){de(q),typeof q.beginScope=="string"&&(q.beginScope={_wrap:q.beginScope}),typeof q.endScope=="string"&&(q.endScope={_wrap:q.endScope}),te(q),me(q)}function De(q){function le(Qe,Ke){return new RegExp(g(Qe),"m"+(q.case_insensitive?"i":"")+(q.unicodeRegex?"u":"")+(Ke?"g":""))}class Pe{constructor(){this.matchIndexes={},this.regexes=[],this.matchAt=1,this.position=0}addRule(Ke,pt){pt.position=this.position++,this.matchIndexes[this.matchAt]=pt,this.regexes.push([pt,Ke]),this.matchAt+=j(Ke)+1}compile(){this.regexes.length===0&&(this.exec=()=>null);const Ke=this.regexes.map(pt=>pt[1]);this.matcherRe=le(T(Ke,{joinWith:"|"}),!0),this.lastIndex=0}exec(Ke){this.matcherRe.lastIndex=this.lastIndex;const pt=this.matcherRe.exec(Ke);if(!pt)return null;const ds=pt.findIndex((fi,Ji)=>Ji>0&&fi!==void 0),Kt=this.matchIndexes[ds];return pt.splice(0,ds),Object.assign(pt,Kt)}}class Ye{constructor(){this.rules=[],this.multiRegexes=[],this.count=0,this.lastIndex=0,this.regexIndex=0}getMatcher(Ke){if(this.multiRegexes[Ke])return this.multiRegexes[Ke];const pt=new Pe;return this.rules.slice(Ke).forEach(([ds,Kt])=>pt.addRule(ds,Kt)),pt.compile(),this.multiRegexes[Ke]=pt,pt}resumingScanAtSamePosition(){return this.regexIndex!==0}considerAll(){this.regexIndex=0}addRule(Ke,pt){this.rules.push([Ke,pt]),pt.type==="begin"&&this.count++}exec(Ke){const pt=this.getMatcher(this.regexIndex);pt.lastIndex=this.lastIndex;let ds=pt.exec(Ke);if(this.resumingScanAtSamePosition()&&!(ds&&ds.index===this.lastIndex)){const Kt=this.getMatcher(0);Kt.lastIndex=this.lastIndex+1,ds=Kt.exec(Ke)}return ds&&(this.regexIndex+=ds.position+1,this.regexIndex===this.count&&this.considerAll()),ds}}function Nt(Qe){const Ke=new Ye;return Qe.contains.forEach(pt=>Ke.addRule(pt.begin,{rule:pt,type:"begin"})),Qe.terminatorEnd&&Ke.addRule(Qe.terminatorEnd,{type:"end"}),Qe.illegal&&Ke.addRule(Qe.illegal,{type:"illegal"}),Ke}function Dt(Qe,Ke){const pt=Qe;if(Qe.isCompiled)return pt;[Re,We,be,at].forEach(Kt=>Kt(Qe,Ke)),q.compilerExtensions.forEach(Kt=>Kt(Qe,Ke)),Qe.__beforeBegin=null,[ie,Be,He].forEach(Kt=>Kt(Qe,Ke)),Qe.isCompiled=!0;let ds=null;return typeof Qe.keywords=="object"&&Qe.keywords.$pattern&&(Qe.keywords=Object.assign({},Qe.keywords),ds=Qe.keywords.$pattern,delete Qe.keywords.$pattern),ds=ds||/\w+/,Qe.keywords&&(Qe.keywords=xt(Qe.keywords,q.case_insensitive)),pt.keywordPatternRe=le(ds,!0),Ke&&(Qe.begin||(Qe.begin=/\B|\b/),pt.beginRe=le(pt.begin),!Qe.end&&!Qe.endsWithParent&&(Qe.end=/\B|\b/),Qe.end&&(pt.endRe=le(pt.end)),pt.terminatorEnd=g(pt.end)||"",Qe.endsWithParent&&Ke.terminatorEnd&&(pt.terminatorEnd+=(Qe.end?"|":"")+Ke.terminatorEnd)),Qe.illegal&&(pt.illegalRe=le(Qe.illegal)),Qe.contains||(Qe.contains=[]),Qe.contains=[].concat(...Qe.contains.map(function(Kt){return oe(Kt==="self"?Qe:Kt)})),Qe.contains.forEach(function(Kt){Dt(Kt,pt)}),Qe.starts&&Dt(Qe.starts,Ke),pt.matcher=Nt(pt),pt}if(q.compilerExtensions||(q.compilerExtensions=[]),q.contains&&q.contains.includes("self"))throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");return q.classNameAliases=i(q.classNameAliases||{}),Dt(q)}function L(q){return q?q.endsWithParent||L(q.starts):!1}function oe(q){return q.variants&&!q.cachedVariants&&(q.cachedVariants=q.variants.map(function(le){return i(q,{variants:null},le)})),q.cachedVariants?q.cachedVariants:L(q)?i(q,{starts:q.starts?i(q.starts):null}):Object.isFrozen(q)?i(q):q}var Ee="11.11.1";class Ce extends Error{constructor(le,Pe){super(le),this.name="HTMLInjectionError",this.html=Pe}}const Ne=s,Oe=i,ye=Symbol("nomatch"),$e=7,Ie=function(q){const le=Object.create(null),Pe=Object.create(null),Ye=[];let Nt=!0;const Dt="Could not find the language '{}', did you forget to load/include a language module?",Qe={disableAutodetect:!0,name:"Plain text",contains:[]};let Ke={ignoreUnescapedHTML:!1,throwUnescapedHTML:!1,noHighlightRe:/^(no-?highlight)$/i,languageDetectRe:/\blang(?:uage)?-([\w-]+)\b/i,classPrefix:"hljs-",cssSelector:"pre code",languages:null,__emitter:p};function pt(ze){return Ke.noHighlightRe.test(ze)}function ds(ze){let ut=ze.className+" ";ut+=ze.parentNode?ze.parentNode.className:"";const Tt=Ke.languageDetectRe.exec(ut);if(Tt){const Yt=on(Tt[1]);return Yt||(Ts(Dt.replace("{}",Tt[1])),Ts("Falling back to no-highlight mode for this block.",ze)),Yt?Tt[1]:"no-highlight"}return ut.split(/\s+/).find(Yt=>pt(Yt)||on(Yt))}function Kt(ze,ut,Tt){let Yt="",Rs="";typeof ut=="object"?(Yt=ze,Tt=ut.ignoreIllegals,Rs=ut.language):(Wt("10.7.0","highlight(lang, code, ...args) has been deprecated."),Wt("10.7.0",`Please use highlight(code, options) instead.
|
|
@@ -217,7 +217,7 @@ Please report this to https://github.com/markedjs/marked.`,e){let i="<p>An error
|
|
|
217
217
|
`+L.slice(Ne,Oe),Ne=Oe+1),ye=$e;return Ie+=`
|
|
218
218
|
`,L.length-Ne>oe&&ye>Ne?Ie+=L.slice(Ne,ye)+`
|
|
219
219
|
`+L.slice(ye+1):Ie+=L.slice(Ne),Ie.slice(1)}function It(L){let oe="",Ee=0;for(let Ce=0;Ce<L.length;Ee>=65536?Ce+=2:Ce++){Ee=rt(L,Ce);const Ne=U[Ee];!Ne&&ne(Ee)?(oe+=L[Ce],Ee>=65536&&(oe+=L[Ce+1])):oe+=Ne||W(Ee)}return oe}function Ts(L,oe,Ee){let Ce="";const Ne=L.tag;for(let Oe=0,ye=Ee.length;Oe<ye;Oe+=1){let $e=Ee[Oe];L.replacer&&($e=L.replacer.call(Ee,String(Oe),$e)),(me(L,oe,$e,!1,!1)||typeof $e>"u"&&me(L,oe,null,!1,!1))&&(Ce!==""&&(Ce+=","+(L.condenseFlow?"":" ")),Ce+=L.dump)}L.tag=Ne,L.dump="["+Ce+"]"}function Wt(L,oe,Ee,Ce){let Ne="";const Oe=L.tag;for(let ye=0,$e=Ee.length;ye<$e;ye+=1){let Ie=Ee[ye];L.replacer&&(Ie=L.replacer.call(Ee,String(ye),Ie)),(me(L,oe+1,Ie,!0,!0,!1,!0)||typeof Ie>"u"&&me(L,oe+1,null,!0,!0,!1,!0))&&((!Ce||Ne!=="")&&(Ne+=ue(L,oe)),L.dump&&u===L.dump.charCodeAt(0)?Ne+="-":Ne+="- ",Ne+=L.dump)}L.tag=Oe,L.dump=Ne||"[]"}function ot(L,oe,Ee){let Ce="";const Ne=L.tag,Oe=Object.keys(Ee);for(let ye=0,$e=Oe.length;ye<$e;ye+=1){let Ie="";Ce!==""&&(Ie+=", "),L.condenseFlow&&(Ie+='"');const qe=Oe[ye];let q=Ee[qe];L.replacer&&(q=L.replacer.call(Ee,qe,q)),me(L,oe,qe,!1,!1)&&(L.dump.length>1024&&(Ie+="? "),Ie+=L.dump+(L.condenseFlow?'"':"")+":"+(L.condenseFlow?"":" "),me(L,oe,q,!1,!1)&&(Ie+=L.dump,Ce+=Ie))}L.tag=Ne,L.dump="{"+Ce+"}"}function S(L,oe,Ee,Ce){let Ne="";const Oe=L.tag,ye=Object.keys(Ee);if(L.sortKeys===!0)ye.sort();else if(typeof L.sortKeys=="function")ye.sort(L.sortKeys);else if(L.sortKeys)throw new t("sortKeys must be a boolean or a function");for(let $e=0,Ie=ye.length;$e<Ie;$e+=1){let qe="";(!Ce||Ne!=="")&&(qe+=ue(L,oe));const q=ye[$e];let le=Ee[q];if(L.replacer&&(le=L.replacer.call(Ee,q,le)),!me(L,oe+1,q,!0,!0,!0))continue;const Pe=L.tag!==null&&L.tag!=="?"||L.dump&&L.dump.length>1024;Pe&&(L.dump&&u===L.dump.charCodeAt(0)?qe+="?":qe+="? "),qe+=L.dump,Pe&&(qe+=ue(L,oe)),me(L,oe+1,le,!0,Pe)&&(L.dump&&u===L.dump.charCodeAt(0)?qe+=":":qe+=": ",qe+=L.dump,Ne+=qe)}L.tag=Oe,L.dump=Ne||"{}"}function te(L,oe,Ee){const Ce=Ee?L.explicitTypes:L.implicitTypes;for(let Ne=0,Oe=Ce.length;Ne<Oe;Ne+=1){const ye=Ce[Ne];if((ye.instanceOf||ye.predicate)&&(!ye.instanceOf||typeof oe=="object"&&oe instanceof ye.instanceOf)&&(!ye.predicate||ye.predicate(oe))){if(Ee?ye.multi&&ye.representName?L.tag=ye.representName(oe):L.tag=ye.tag:L.tag="?",ye.represent){const $e=L.styleMap[ye.tag]||ye.defaultStyle;let Ie;if(i.call(ye.represent)==="[object Function]")Ie=ye.represent(oe,$e);else if(a.call(ye.represent,$e))Ie=ye.represent[$e](oe,$e);else throw new t("!<"+ye.tag+'> tag resolver accepts not "'+$e+'" style');L.dump=Ie}return!0}}return!1}function me(L,oe,Ee,Ce,Ne,Oe,ye){L.tag=null,L.dump=Ee,te(L,Ee,!1)||te(L,Ee,!0);const $e=i.call(L.dump),Ie=Ce;Ce&&(Ce=L.flowLevel<0||L.flowLevel>oe);const qe=$e==="[object Object]"||$e==="[object Array]";let q,le;if(qe&&(q=L.duplicates.indexOf(Ee),le=q!==-1),(L.tag!==null&&L.tag!=="?"||le||L.indent!==2&&oe>0)&&(Ne=!1),le&&L.usedDuplicates[q])L.dump="*ref_"+q;else{if(qe&&le&&!L.usedDuplicates[q]&&(L.usedDuplicates[q]=!0),$e==="[object Object]")Ce&&Object.keys(L.dump).length!==0?(S(L,oe,L.dump,Ne),le&&(L.dump="&ref_"+q+L.dump)):(ot(L,oe,L.dump),le&&(L.dump="&ref_"+q+" "+L.dump));else if($e==="[object Array]")Ce&&L.dump.length!==0?(L.noArrayIndent&&!ye&&oe>0?Wt(L,oe-1,L.dump,Ne):Wt(L,oe,L.dump,Ne),le&&(L.dump="&ref_"+q+L.dump)):(Ts(L,oe,L.dump),le&&(L.dump="&ref_"+q+" "+L.dump));else if($e==="[object String]")L.tag!=="?"&&ht(L,L.dump,oe,Oe,Ie);else{if($e==="[object Undefined]")return!1;if(L.skipInvalid)return!1;throw new t("unacceptable kind of an object to dump "+$e)}if(L.tag!==null&&L.tag!=="?"){let Pe=encodeURI(L.tag[0]==="!"?L.tag.slice(1):L.tag).replace(/!/g,"%21");L.tag[0]==="!"?Pe="!"+Pe:Pe.slice(0,18)==="tag:yaml.org,2002:"?Pe="!!"+Pe.slice(18):Pe="!<"+Pe+">",L.dump=Pe+" "+L.dump}}return!0}function de(L,oe){const Ee=[],Ce=[];be(L,Ee,Ce);const Ne=Ce.length;for(let Oe=0;Oe<Ne;Oe+=1)oe.duplicates.push(Ee[Ce[Oe]]);oe.usedDuplicates=new Array(Ne)}function be(L,oe,Ee){if(L!==null&&typeof L=="object"){const Ce=oe.indexOf(L);if(Ce!==-1)Ee.indexOf(Ce)===-1&&Ee.push(Ce);else if(oe.push(L),Array.isArray(L))for(let Ne=0,Oe=L.length;Ne<Oe;Ne+=1)be(L[Ne],oe,Ee);else{const Ne=Object.keys(L);for(let Oe=0,ye=Ne.length;Oe<ye;Oe+=1)be(L[Ne[Oe]],oe,Ee)}}}function De(L,oe){oe=oe||{};const Ee=new F(oe);Ee.noRefs||de(L,Ee);let Ce=L;return Ee.replacer&&(Ce=Ee.replacer.call({"":Ce},"",Ce)),me(Ee,0,Ce,!0,!0)?Ee.dump+`
|
|
220
|
-
`:""}return Yv.dump=De,Yv}var nj;function Fte(){if(nj)return xn;nj=1;const e=Hte(),t=$te();function s(i,a){return function(){throw new Error("Function yaml."+i+" is removed in js-yaml 4. Use yaml."+a+" instead, which is now safe by default.")}}return xn.Type=On(),xn.Schema=AR(),xn.FAILSAFE_SCHEMA=DR(),xn.JSON_SCHEMA=BR(),xn.CORE_SCHEMA=IR(),xn.DEFAULT_SCHEMA=Y1(),xn.load=e.load,xn.loadAll=e.loadAll,xn.dump=t.dump,xn.YAMLException=nd(),xn.types={binary:FR(),float:zR(),map:MR(),null:LR(),pairs:qR(),set:GR(),timestamp:HR(),bool:OR(),int:PR(),merge:$R(),omap:UR(),seq:RR(),str:TR()},xn.safeLoad=s("safeLoad","load"),xn.safeLoadAll=s("safeLoadAll","loadAll"),xn.safeDump=s("safeDump","dump"),xn}var Ute=Fte();const VR=Bte(Ute),{Type:gie,Schema:bie,FAILSAFE_SCHEMA:vie,JSON_SCHEMA:xie,CORE_SCHEMA:yie,DEFAULT_SCHEMA:_ie,load:wie,loadAll:Sie,dump:kie,YAMLException:Cie,types:Nie,safeLoad:Eie,safeLoadAll:jie,safeDump:Aie}=VR;function WR(e){return e!==null&&typeof e=="object"}function KR(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 YR(e){return e==null?"null":typeof e=="string"?e===""?'""':e:String(e)}function XR({label:e,value:t,depth:s,defaultOpen:i}){const[a,l]=v.useState(i),c={paddingLeft:`${s*1.1}rem`};if(!WR(t))return n.jsxs("div",{className:"flex items-baseline gap-2 py-[1px]",style:c,children:[n.jsxs("span",{className:"text-muted-foreground",children:[e,":"]}),n.jsx("span",{className:se("whitespace-pre-wrap break-words",KR(t)),children:YR(t)})]});const u=Array.isArray(t)?t.map((h,p)=>[String(p),h]):Object.entries(t),f=Array.isArray(t)?`[${u.length}]`:`{${u.length}}`;return n.jsxs("div",{children:[n.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?n.jsx(kn,{className:"size-3.5 shrink-0 text-muted-foreground"}):n.jsx(gn,{className:"size-3.5 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"font-medium text-foreground",children:e}),n.jsx("span",{className:"text-muted-foreground",children:f})]}),a?u.map(([h,p])=>n.jsx(XR,{label:h,value:p,depth:s+1,defaultOpen:s<1},h)):null]})}function qte({content:e}){const t=X(),s=v.useMemo(()=>{try{const a=VR.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 n.jsx("div",{className:"p-4",children:n.jsx(nt,{variant:"destructive",children:t("git.yaml.parseError",{error:s.error})})});if(!WR(s.value))return n.jsx("div",{className:"p-4 font-mono text-[12px]",children:n.jsx("span",{className:KR(s.value),children:YR(s.value)})});const i=Array.isArray(s.value)?s.value.map((a,l)=>[String(l),a]):Object.entries(s.value);return n.jsx("div",{className:"min-w-max px-4 py-3 font-mono text-[12px] leading-[1.6]",children:i.map(([a,l])=>n.jsx(XR,{label:a,value:l,depth:0,defaultOpen:!0},a))})}const Gte=v.lazy(()=>qu(()=>import("./code-editor-
|
|
220
|
+
`:""}return Yv.dump=De,Yv}var nj;function Fte(){if(nj)return xn;nj=1;const e=Hte(),t=$te();function s(i,a){return function(){throw new Error("Function yaml."+i+" is removed in js-yaml 4. Use yaml."+a+" instead, which is now safe by default.")}}return xn.Type=On(),xn.Schema=AR(),xn.FAILSAFE_SCHEMA=DR(),xn.JSON_SCHEMA=BR(),xn.CORE_SCHEMA=IR(),xn.DEFAULT_SCHEMA=Y1(),xn.load=e.load,xn.loadAll=e.loadAll,xn.dump=t.dump,xn.YAMLException=nd(),xn.types={binary:FR(),float:zR(),map:MR(),null:LR(),pairs:qR(),set:GR(),timestamp:HR(),bool:OR(),int:PR(),merge:$R(),omap:UR(),seq:RR(),str:TR()},xn.safeLoad=s("safeLoad","load"),xn.safeLoadAll=s("safeLoadAll","loadAll"),xn.safeDump=s("safeDump","dump"),xn}var Ute=Fte();const VR=Bte(Ute),{Type:gie,Schema:bie,FAILSAFE_SCHEMA:vie,JSON_SCHEMA:xie,CORE_SCHEMA:yie,DEFAULT_SCHEMA:_ie,load:wie,loadAll:Sie,dump:kie,YAMLException:Cie,types:Nie,safeLoad:Eie,safeLoadAll:jie,safeDump:Aie}=VR;function WR(e){return e!==null&&typeof e=="object"}function KR(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 YR(e){return e==null?"null":typeof e=="string"?e===""?'""':e:String(e)}function XR({label:e,value:t,depth:s,defaultOpen:i}){const[a,l]=v.useState(i),c={paddingLeft:`${s*1.1}rem`};if(!WR(t))return n.jsxs("div",{className:"flex items-baseline gap-2 py-[1px]",style:c,children:[n.jsxs("span",{className:"text-muted-foreground",children:[e,":"]}),n.jsx("span",{className:se("whitespace-pre-wrap break-words",KR(t)),children:YR(t)})]});const u=Array.isArray(t)?t.map((h,p)=>[String(p),h]):Object.entries(t),f=Array.isArray(t)?`[${u.length}]`:`{${u.length}}`;return n.jsxs("div",{children:[n.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?n.jsx(kn,{className:"size-3.5 shrink-0 text-muted-foreground"}):n.jsx(gn,{className:"size-3.5 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"font-medium text-foreground",children:e}),n.jsx("span",{className:"text-muted-foreground",children:f})]}),a?u.map(([h,p])=>n.jsx(XR,{label:h,value:p,depth:s+1,defaultOpen:s<1},h)):null]})}function qte({content:e}){const t=X(),s=v.useMemo(()=>{try{const a=VR.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 n.jsx("div",{className:"p-4",children:n.jsx(nt,{variant:"destructive",children:t("git.yaml.parseError",{error:s.error})})});if(!WR(s.value))return n.jsx("div",{className:"p-4 font-mono text-[12px]",children:n.jsx("span",{className:KR(s.value),children:YR(s.value)})});const i=Array.isArray(s.value)?s.value.map((a,l)=>[String(l),a]):Object.entries(s.value);return n.jsx("div",{className:"min-w-max px-4 py-3 font-mono text-[12px] leading-[1.6]",children:i.map(([a,l])=>n.jsx(XR,{label:a,value:l,depth:0,defaultOpen:!0},a))})}const Gte=v.lazy(()=>qu(()=>import("./code-editor-C9RcL5cM.js"),[]).then(e=>({default:e.CodeEditor})));function Vte(e){const t=e.split("/").pop()?.toLowerCase().split(".").pop()??"";return t==="md"||t==="mdx"||t==="markdown"?"markdown":t==="yml"||t==="yaml"?"yaml":null}function Wte(e){const t=e.split("/").pop()?.toLowerCase()??"",s=t.includes(".")?t.split(".").pop()??"":"",i={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 i[s]?i[s]:t==="dockerfile"?"dockerfile":null}function Kte(e,t){const s=e.endsWith(`
|
|
221
221
|
`)?e.slice(0,-1):e;return!t||!v0.getLanguage(t)?s.split(`
|
|
222
222
|
`).map(ij):s.split(`
|
|
223
223
|
`).map(i=>{if(!i)return"";try{return v0.highlight(i,{language:t,ignoreIllegals:!0}).value}catch{return ij(i)}})}function ij(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Yte({content:e,path:t}){const s=v.useMemo(()=>Wte(t),[t]),i=v.useMemo(()=>Kte(e,s),[e,s]),a=`${Math.max(2,String(i.length).length)}ch`;return n.jsx("div",{className:"min-w-max font-mono text-[12px] leading-[1.5]",children:i.map((l,c)=>n.jsxs("div",{className:"flex",children:[n.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}),n.jsx("span",{className:"hljs whitespace-pre px-3 text-zinc-800 dark:text-zinc-100",dangerouslySetInnerHTML:{__html:l||" "}})]},c))})}function Xte({path:e,isModified:t,onViewDiff:s,onFileSaved:i,onSendToAi:a}){const[l,c]=v.useState(null),[u,f]=v.useState(""),[h,p]=v.useState(!1),[g,b]=v.useState(null),[x,_]=v.useState(!1),[k,C]=v.useState(!1),{success:E,error:j}=gs(),N=X(),A=v.useMemo(()=>Vte(e),[e]),[T,D]=v.useState("preview"),z=!!(l&&!l.binary&&!l.truncated),O=l?u!==l.content:!1;v.useEffect(()=>{D(A?"preview":"source"),p(!1)},[A]),v.useEffect(()=>{if(!e){c(null);return}let I=!0;return _(!0),b(null),p(!1),r9(e).then(G=>{I&&(c(G),f(G.content),_(!1))}).catch(G=>{I&&(b(G instanceof Error?G.message:String(G)),_(!1))}),()=>{I=!1}},[e]);async function $(){if(!(!e||!l||!O||k)){C(!0);try{await a9(e,u);const I={...l,content:u,size:new TextEncoder().encode(u).length};c(I),p(!1),E(N("git.fileViewer.savedToast",{path:e})),i?.(e)}catch(I){j(I instanceof Error?I.message:String(I))}finally{C(!1)}}}function M(){f(l?.content??""),p(!1)}return e?n.jsxs("section",{className:"flex min-h-0 min-w-0 flex-col border-l border-border bg-card",children:[n.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border px-3 py-1.5",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:e}),n.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[10px] text-muted-foreground",children:[n.jsx("span",{children:N("git.fileViewer.readOnly")}),l?.truncated?n.jsx("span",{className:"text-amber-700",children:N("git.fileViewer.truncated")}):null,l?.binary?n.jsx("span",{className:"text-amber-700",children:N("git.fileViewer.binary")}):null]})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[A&&!l?.binary?n.jsxs("div",{className:"flex items-center rounded-md border border-border p-0.5",children:[n.jsxs("button",{type:"button",onClick:()=>D("preview"),"aria-pressed":T==="preview",className:se("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:[n.jsx(lm,{className:"size-3.5"}),N("git.fileViewer.preview")]}),n.jsxs("button",{type:"button",onClick:()=>D("source"),"aria-pressed":T==="source",className:se("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:[n.jsx(Dj,{className:"size-3.5"}),N("git.fileViewer.source")]})]}):null,t?n.jsx(Q,{onClick:s,size:"sm",type:"button",variant:"outline",children:N("git.fileViewer.viewDiff")}):null,a?n.jsx(Q,{"aria-label":N("git.fileViewer.sendToAi"),className:"size-8",disabled:!e,onClick:a,size:"icon",title:N("git.fileViewer.sendPathToAi"),type:"button",variant:"outline",children:n.jsx(cs,{className:"size-4"})}):null,h?n.jsxs(n.Fragment,{children:[n.jsxs(Q,{disabled:!O||k,onClick:()=>{$()},size:"sm",type:"button",children:[n.jsx(Gj,{}),N("git.fileViewer.apply")]}),n.jsxs(Q,{disabled:k,onClick:M,size:"sm",type:"button",variant:"outline",children:[n.jsx(Gt,{}),N("common.cancel")]})]}):z?n.jsxs(Q,{onClick:()=>{D("source"),p(!0)},size:"sm",type:"button",variant:"outline",children:[n.jsx(Il,{}),N("common.edit")]}):null]})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-card",children:g?n.jsx("div",{className:"p-4",children:n.jsx(nt,{variant:"destructive",children:g})}):x?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:N("common.loading")}):l?.binary?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:N("git.fileViewer.cannotBinary")}):l?h?n.jsx(v.Suspense,{fallback:n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:N("git.fileViewer.loadingEditor")}),children:n.jsx(Gte,{path:e,value:u,onChange:f})}):A&&T==="preview"?A==="markdown"?n.jsx(K1,{content:l.content}):n.jsx(qte,{content:l.content}):n.jsx(Yte,{content:l.content,path:e}):null})]}):n.jsx("div",{className:"p-4",children:n.jsx(nt,{variant:"muted",className:"border-dashed p-12 text-center",children:N("git.fileViewer.selectFile")})})}function Zte({activeHunkIndex:e,filePaths:t,hunkCount:s,pendingNextFilePath:i,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?i===c?{kind:"file",filePath:c}:{kind:"confirm-next-file",filePath:c}:{kind:"none"}}function rj(e){const t={name:"",fullPath:"",children:new Map};for(const s of e){const i=s.name.split("/");let a=t;i.forEach((l,c)=>{let u=a.children.get(l);u||(u={name:l,fullPath:i.slice(0,c+1).join("/"),children:new Map},a.children.set(l,u)),a=u}),a.branch=s}return t}function aj({label:e,tree:t,onSelect:s,defaultOpen:i,forceOpen:a}){const[l,c]=v.useState(i??!1),u=a||l,f=t.children.size===0;return n.jsxs("div",{className:"mb-1",children:[n.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:[u?n.jsx(kn,{size:12}):n.jsx(gn,{size:12}),e,f?null:n.jsxs("span",{className:"ml-1 text-[10px] font-normal",children:["(",t.children.size,")"]})]}),u&&!f?n.jsx("ul",{children:Array.from(t.children.values()).map(h=>n.jsx(ZR,{node:h,depth:1,onSelect:s,forceOpen:a},h.fullPath))}):null]})}function ZR({node:e,depth:t,onSelect:s,forceOpen:i}){const[a,l]=v.useState(!0),c=i||a,u=e.children.size>0,f=e.branch,h={paddingLeft:`${t*10}px`};return!u&&f?n.jsx("li",{children:n.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:[n.jsx(Mn,{size:11,className:"shrink-0 opacity-70"}),n.jsx("span",{className:"truncate",children:e.name}),f.current?n.jsx("span",{className:"text-[10px]",children:"●"}):null]})}):n.jsxs("li",{children:[n.jsxs("button",{type:"button",onClick:()=>{f?s(f):l(p=>!p)},style:h,className:"flex w-full items-center gap-1 py-0.5 pr-2 text-left text-[12px] hover:bg-muted/60",children:[u?c?n.jsx(kn,{size:11}):n.jsx(gn,{size:11}):n.jsx("span",{className:"inline-block w-[11px]"}),n.jsx("span",{className:"truncate",children:e.name})]}),c&&u?n.jsx("ul",{children:Array.from(e.children.values()).map(p=>n.jsx(ZR,{node:p,depth:t+1,onSelect:s,forceOpen:i},p.fullPath))}):null]})}function Qte({selectedCommit:e,selectedFile:t,diff:s,diffLoading:i,diffError:a}){const l=X();return n.jsxs("section",{className:"flex min-h-0 min-w-0 flex-col bg-card border-b border-border",children:[n.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border px-3 py-1.5",children:n.jsxs("div",{className:"min-w-0",children:[n.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:t??(e?e.subject:l("git.graph.commitFallback"))}),e?n.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[10px] text-muted-foreground",children:[n.jsx("span",{className:"font-mono",children:e.hash.slice(0,12)}),n.jsxs("span",{children:[e.author," <",e.email,">"]}),n.jsx("span",{children:new Date(e.timestamp*1e3).toLocaleString()})]}):null]})}),n.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:a?n.jsx("div",{className:"p-4",children:n.jsx(nt,{variant:"destructive",children:a})}):e?i?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:l("git.diff.loading")}):s?n.jsx(Yu,{activeHunkIndex:0,diff:s}):n.jsx("div",{className:"p-4",children:n.jsx(nt,{variant:"muted",className:"border-dashed p-6 text-center",children:e.parents.length>1?l("git.graph.mergeNoDiff"):l("git.graph.noTextualChanges")})}):n.jsx("div",{className:"p-4",children:n.jsx(nt,{variant:"muted",className:"border-dashed p-12 text-center",children:l("git.graph.selectCommitDiff")})})})]})}function Jte({files:e,filesError:t,selectedHash:s,selectedFile:i,onSelect:a}){const l=X();return n.jsxs("aside",{className:"flex min-h-0 flex-col overflow-hidden border-r border-border",children:[n.jsx("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:n.jsxs("h2",{className:"text-[13px] font-semibold tracking-tight",children:[l("git.tree.filesDefault"),e.length?n.jsx("span",{className:"ml-2 text-[11px] font-normal text-muted-foreground",children:e.length}):null]})}),n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:t?n.jsx("div",{className:"p-3",children:n.jsx(nt,{variant:"destructive",children:t})}):s?e.length===0?n.jsx("div",{className:"p-3 text-[12px] text-muted-foreground",children:l("git.graph.noFileChanges")}):n.jsx("ul",{className:"divide-y divide-border",children:e.map(c=>n.jsx("li",{children:n.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 ${i===c.path?"bg-muted":""}`,children:[n.jsx("span",{className:ese(c.index),children:c.index.trim()||"·"}),n.jsx("span",{className:"truncate font-mono",children:c.path})]})},c.path))}):n.jsx("div",{className:"p-3 text-[12px] text-muted-foreground",children:l("git.graph.selectCommitFiles")})})]})}function ese(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 oj=["#3b82f6","#10b981","#f59e0b","#ec4899","#8b5cf6","#14b8a6","#ef4444","#84cc16"];function nu(e){return oj[e%oj.length]}function tse({lane:e,laneCount:t,edges:s,throughLanes:i,isMerge:a,height:l=28,laneWidth:c=14}){const f=Math.max(e+1,t,1)*c,h=l/2,p=iu(e,c),g=a?4:3.5;return n.jsxs("svg",{width:f,height:l,viewBox:`0 0 ${f} ${l}`,style:{flex:"0 0 auto",display:"block"},children:[i.map(b=>n.jsx("line",{x1:iu(b,c),y1:0,x2:iu(b,c),y2:l,stroke:nu(b),strokeWidth:1.5},`t-${b}`)),n.jsx("line",{x1:p,y1:0,x2:p,y2:h,stroke:nu(e),strokeWidth:1.5}),s.map((b,x)=>{const _=iu(b.fromLane,c),k=iu(b.toLane,c);if(_===k)return n.jsx("line",{x1:_,y1:h,x2:k,y2:l,stroke:nu(b.toLane),strokeWidth:1.5},`e-${x}`);const C=h+(l-h)/2;return n.jsx("path",{d:`M ${_} ${h} C ${_} ${C}, ${k} ${C}, ${k} ${l}`,fill:"none",stroke:nu(b.toLane),strokeWidth:1.5},`e-${x}`)}),n.jsx("circle",{cx:p,cy:h,r:g,fill:nu(e),stroke:"var(--background, #fff)",strokeWidth:1.5})]})}function iu(e,t){return e*t+t/2}function sse({sha:e}){const t=X(),[s,i]=v.useState(()=>tZ(e)??null),a=v.useRef(null);if(v.useEffect(()=>{if(s)return;const u=a.current;if(!u||typeof IntersectionObserver>"u")return;let f=!0;const h=new IntersectionObserver(p=>{p.some(g=>g.isIntersecting)&&(h.disconnect(),ZT(e).then(g=>{f&&i(g)}).catch(()=>{}))},{rootMargin:"200px"});return h.observe(u),()=>{f=!1,h.disconnect()}},[e,s]),!s||s.state==="unknown"||s.totalCount===0)return n.jsx("span",{ref:a,"aria-hidden":!0,className:"inline-block size-2 shrink-0"});const l=nse(s.state),c=t("github.ci.badgeLabel",{state:s.state,count:s.totalCount});return n.jsx("span",{"aria-label":c,className:`shrink-0 size-2 rounded-full ${l}`,title:c})}function nse(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 lj=28;function ise({commits:e,loading:t,error:s,selectedHash:i,maxLanes:a,rowRefs:l,onSelect:c,onLoadMore:u}){const f=X(),{sendToAgent:h}=Vt(),[p,g]=v.useState(null);function b(x,_){g(null),h({prompt:Mq(x,_),source:{type:"git-commit",label:x.hash.slice(0,7)},label:`${x.hash.slice(0,7)}: ${_}`})}return n.jsxs("aside",{className:"flex min-h-0 flex-col overflow-hidden border-r border-border",children:[n.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[n.jsxs("h2",{className:"text-[13px] font-semibold tracking-tight",children:[f("git.graph.commitTree"),e.length?n.jsx("span",{className:"ml-2 text-[11px] font-normal text-muted-foreground",children:f("git.graph.commitsCount",{count:e.length})}):null]}),n.jsx(Q,{disabled:t,onClick:u,size:"sm",type:"button",variant:"outline",children:f("git.graph.loadMore")})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:s?n.jsx("div",{className:"p-3",children:n.jsx(nt,{variant:"destructive",children:s})}):t&&e.length===0?n.jsx("div",{className:"p-3 text-[12px] text-muted-foreground",children:f("git.graph.loadingCommits")}):e.length===0?n.jsx("div",{className:"p-3 text-[12px] text-muted-foreground",children:f("git.graph.noCommits")}):n.jsx("ul",{className:"divide-y divide-border",children:e.map(x=>n.jsxs("li",{ref:_=>{_?l.current.set(x.hash,_):l.current.delete(x.hash)},className:"group flex flex-col",children:[n.jsxs("div",{className:`flex items-center transition-colors hover:bg-muted/60 ${i===x.hash?"bg-muted":""}`,children:[n.jsxs("button",{onClick:()=>c(x.hash),type:"button",className:"flex min-w-0 flex-1 items-center gap-2 px-2 py-0.5 text-left",style:{minHeight:lj},title:`${x.hash}
|
|
@@ -225,4 +225,4 @@ ${x.author} <${x.email}>
|
|
|
225
225
|
${x.subject}`,children:[n.jsx(tse,{lane:x.lane,laneCount:Math.max(x.laneCount,a),edges:x.edges,throughLanes:x.throughLanes,isMerge:x.parents.length>1,height:lj}),n.jsxs("span",{className:"flex items-center gap-1 font-mono text-[10px] text-muted-foreground",children:[x.hash.slice(0,7),n.jsx(sse,{sha:x.hash})]}),n.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[x.refs.map(_=>n.jsx("span",{className:ase(_.kind),children:_.name},`${_.kind}-${_.name}`)),n.jsx("span",{className:"truncate text-[12px]",children:x.subject})]}),n.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:x.author}),n.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/70",title:new Date(x.timestamp*1e3).toLocaleString(),children:rse(x.timestamp)})]}),n.jsx(xr,{className:`mr-1 shrink-0 ${p===x.hash?"opacity-100":""}`,label:f("git.graph.askCommitLabel",{sha:x.hash.slice(0,7)}),onAsk:()=>g(_=>_===x.hash?null:x.hash)})]}),p===x.hash?n.jsx("div",{className:"px-2 pb-1.5 pt-0.5",children:n.jsx(Qr,{placeholder:f("git.graph.askPlaceholder"),onSubmit:_=>b(x,_),onCancel:()=>g(null)})}):null]},x.hash))})})]})}function rse(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 i=Math.floor(s/60);if(i<24)return`${i}h`;const a=Math.floor(i/24);if(a<30)return`${a}d`;const l=Math.floor(a/30);return l<12?`${l}mo`:`${Math.floor(l/12)}y`}function ase(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 cj=200;function ose(){const[e,t]=v.useState([]),[s,i]=v.useState(cj),[a,l]=v.useState(0),[c,u]=v.useState(!0),[f,h]=v.useState(null),[p,g]=v.useState(null),[b,x]=v.useState([]),[_,k]=v.useState(!1),[C,E]=v.useState(null),[j,N]=v.useState(null),[A,T]=v.useState(""),[D,z]=v.useState(!1),[O,$]=v.useState(null),M=v.useCallback(B=>{g(B),x([]),N(null),T("")},[]);v.useEffect(()=>{let B=!0;return u(!0),h(null),c3(s).then(U=>{B&&(t(U),U.length>0&&!U.some(Y=>Y.hash===p)&&M(U[0].hash))}).catch(U=>{B&&h(U instanceof Error?U.message:String(U))}).finally(()=>{B&&u(!1)}),()=>{B=!1}},[s,a]),v.useEffect(()=>{if(!p){x([]),N(null),k(!1);return}let B=!0;return E(null),k(!0),s9(p).then(U=>{B&&(x(U),N(U[0]?.path??null))}).catch(U=>{B&&E(U instanceof Error?U.message:String(U))}).finally(()=>{B&&k(!1)}),()=>{B=!1}},[p]),v.useEffect(()=>{if(!p||!j){T(""),z(!1);return}let B=!0;return $(null),z(!0),t9(p,j).then(U=>{B&&T(U)}).catch(U=>{B&&$(U instanceof Error?U.message:String(U))}).finally(()=>{B&&z(!1)}),()=>{B=!1}},[p,j]);const I=v.useMemo(()=>e.reduce((B,U)=>Math.max(B,U.laneCount),1),[e]),G=e.find(B=>B.hash===p)??null;return{commits:e,loading:c,error:f,selectedHash:p,setSelectedHash:M,files:b,filesError:C,selectedFile:j,setSelectedFile:N,diff:A,diffLoading:D||_,diffError:O,maxLanes:I,selectedCommit:G,loadMore:()=>i(B=>B+cj),refresh:()=>l(B=>B+1)}}function lse({branches:e=[]}){const{commits:t,loading:s,error:i,selectedHash:a,setSelectedHash:l,files:c,filesError:u,selectedFile:f,setSelectedFile:h,diff:p,diffLoading:g,diffError:b,maxLanes:x,selectedCommit:_,loadMore:k,refresh:C}=ose(),E=X();$o(C);const[j,N]=v.useState(""),A=v.useMemo(()=>{const M=j.trim().toLowerCase();return M?e.filter(I=>I.name.toLowerCase().includes(M)):e},[e,j]),T=v.useMemo(()=>rj(A.filter(M=>!M.remote)),[A]),D=v.useMemo(()=>rj(A.filter(M=>M.remote)),[A]),z=j.trim().length>0,O=v.useRef(new Map);function $(M){const I=M.remote?"remote":"branch",G=t.find(Y=>Y.refs.some(P=>P.kind===I&&P.name===M.name));if(!G)return;l(G.hash);const B=O.current.get(G.hash),U=B?.parentElement?.parentElement;!B||!U||U.scrollTo({top:Math.max(B.offsetTop-U.clientHeight/2+B.clientHeight/2,0),behavior:"smooth"})}return n.jsxs("div",{className:"grid h-full min-h-0 overflow-hidden border-0 bg-card/85 grid-cols-[220px_minmax(0,1fr)]",children:[n.jsxs("aside",{className:"flex min-h-0 flex-col overflow-hidden border-r border-border",children:[n.jsxs("div",{className:"flex shrink-0 flex-col gap-1 border-b border-border px-3 py-1.5",children:[n.jsx("h2",{className:"text-[13px] font-semibold tracking-tight",children:E("git.graph.branches")}),n.jsx("input",{type:"search",value:j,onChange:M=>N(M.target.value),placeholder:E("git.graph.searchBranches"),className:"w-full rounded border border-border bg-background px-2 py-1 text-[11px] outline-none focus:border-foreground"})]}),n.jsxs("div",{className:"min-h-0 flex-1 overflow-auto py-1",children:[n.jsx(aj,{label:E("git.branch.sectionLocal"),tree:T,onSelect:$,defaultOpen:!0,forceOpen:z}),n.jsx(aj,{label:E("git.branch.sectionRemote"),tree:D,onSelect:$,forceOpen:z})]})]}),n.jsxs("div",{className:"grid min-h-0 min-w-0 grid-rows-[minmax(0,3fr)_minmax(0,2fr)]",children:[n.jsx(Qte,{selectedCommit:_,selectedFile:f,diff:p,diffLoading:g,diffError:b}),n.jsxs("div",{className:"grid min-h-0 min-w-0 grid-cols-[minmax(0,1fr)_280px]",children:[n.jsx(ise,{commits:t,loading:s,error:i,selectedHash:a,maxLanes:x,rowRefs:O,onSelect:l,onLoadMore:k}),n.jsx(Jte,{files:c,filesError:u,selectedHash:a,selectedFile:f,onSelect:h})]})]})]})}function cse({repo:e,file:t,onClose:s}){const i=X(),[a,l]=v.useState(""),[c,u]=v.useState(null),[f,h]=v.useState(!0);v.useEffect(()=>{let g=!0;return h(!0),u(null),u3(t,e).then(b=>{g&&l(b)}).catch(b=>{g&&u(b instanceof Error?b.message:String(b))}).finally(()=>{g&&h(!1)}),()=>{g=!1}},[e,t]),v.useEffect(()=>{function g(b){b.key==="Escape"&&s()}return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[s]);const p=x1(a);return Xn.createPortal(n.jsxs("div",{className:"fixed inset-0 z-[1000] flex justify-end",children:[n.jsx("button",{"aria-label":i("git.diff.closeAria"),className:"absolute inset-0 bg-black/35",onClick:s,type:"button"}),n.jsxs("div",{className:"relative z-10 flex h-full w-[min(900px,calc(100vw-3rem))] flex-col bg-card shadow-xl",children:[n.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border px-3 py-2",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:t}),n.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-muted-foreground",children:[n.jsx("span",{className:"font-mono",children:e}),p.additions||p.deletions?n.jsxs("span",{className:"flex items-center gap-1 font-mono",children:[n.jsxs("span",{className:"text-emerald-700",children:["+",p.additions]}),n.jsxs("span",{className:"text-red-700",children:["-",p.deletions]})]}):null]})]}),n.jsx(Q,{"aria-label":i("git.diff.closeAria"),onClick:s,size:"icon",variant:"ghost",children:n.jsx(Gt,{})})]}),n.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:c?n.jsx("div",{className:"p-4",children:n.jsx(nt,{variant:"destructive",children:c})}):f?n.jsx("div",{className:"p-4 text-xs text-muted-foreground",children:i("git.diff.loading")}):n.jsx(Yu,{diff:a||i("git.noUnstagedDiff")})})]})]}),document.body)}function QR(e){return e.split(/[\\/]/).filter(Boolean).pop()??"project"}function use({initialPath:e,onSelect:t,selectedPath:s}){const i=X(),[a,l]=v.useState(e),[c,u]=v.useState(e),[f,h]=v.useState(null),[p,g]=v.useState(null),[b,x]=v.useState(!1),_=dse(f);return v.useEffect(()=>{l(e)},[e]),v.useEffect(()=>{f&&u(f.path)},[f]),v.useEffect(()=>{let k=!0;return x(!0),g(null),v3(a).then(C=>{k&&(h(C),t(C.path))}).catch(C=>{k&&g(C instanceof Error?C.message:String(C))}).finally(()=>{k&&x(!1)}),()=>{k=!1}},[a,t]),n.jsxs("div",{className:"rounded-md border border-border bg-background",children:[n.jsxs("div",{className:"flex items-center gap-2 border-b border-border p-2",children:[_?n.jsx(Q,{"aria-label":i("git.folder.parentAria"),onClick:()=>f&&l(f.parent),size:"icon",type:"button",variant:"ghost",children:n.jsx(kn,{className:"rotate-90"})}):null,n.jsx(St,{"aria-label":i("git.folder.pathAria"),className:"h-7 min-w-0 flex-1 font-mono text-xs",onChange:k=>u(k.target.value),onKeyDown:k=>{if(k.key==="Enter"){k.preventDefault();const C=c.trim();C&&l(C)}},spellCheck:!1,value:c}),b?n.jsx(Bt,{className:"size-4 shrink-0 animate-spin text-muted-foreground"}):null]}),n.jsxs("div",{className:"max-h-56 overflow-auto p-1",children:[p?n.jsx(nt,{variant:"destructive",className:"m-1",children:p}):null,!p&&f?.entries.length===0?n.jsx(nt,{variant:"muted",className:"m-1 text-center",children:i("git.folder.empty")}):null,f?.entries.map(k=>n.jsxs(Q,{className:se("h-8 w-full justify-start rounded-sm px-2 text-left",s===k.path&&"bg-muted"),onClick:()=>l(k.path),title:k.path,type:"button",variant:"ghost",children:[n.jsx(Io,{className:"text-accent"}),n.jsx("span",{className:"truncate",children:k.name})]},k.path))]})]})}function dse(e){return!!(e&&e.parent!==e.path)}function w0({confirmLabel:e,errorMessage:t,initialPath:s,onCancel:i,onSelect:a,onUse:l,selectedPath:c,title:u}){const f=X();return Xn.createPortal(n.jsx("div",{className:"fixed inset-0 z-[1000] grid place-items-center bg-black/35 px-4",children:n.jsxs("div",{className:"w-full max-w-2xl rounded-xl border border-border bg-card p-4 shadow-xl",children:[n.jsxs("div",{className:"mb-3 flex items-center gap-3",children:[n.jsx("div",{className:"flex size-8 items-center justify-center rounded-lg border border-border bg-background",children:n.jsx(Io,{className:"size-4"})}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("div",{className:"text-sm font-semibold",children:u??f("git.repo.chooseFolder")}),n.jsx("div",{className:"truncate font-mono text-xs text-muted-foreground",children:c})]}),n.jsx(Q,{"aria-label":f("git.repo.closeFolderPicker"),onClick:i,size:"icon",variant:"ghost",children:n.jsx(Gt,{})})]}),n.jsx(use,{initialPath:s,onSelect:a,selectedPath:c}),t?n.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,n.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[n.jsx(Q,{onClick:i,type:"button",variant:"outline",children:f("common.cancel")}),n.jsx(Q,{onClick:()=>{l()},type:"button",children:e??f("git.repo.useThisFolder")})]})]})}),document.body)}const ru=5,hse=240,S0=8,fse=176+S0;function mse({currentRepoPath:e}){const t=X(),[s,i]=v.useState(null),[a,l]=v.useState([]),[c,u]=v.useState(null),[f,h]=v.useState(!0),[p,g]=v.useState(null),b=v.useRef(null),x=v.useRef(null),[_,k]=v.useState(0);v.useEffect(()=>{const U=x.current;if(!U)return;const Y=new ResizeObserver(P=>{k(P[0].contentRect.width)});return Y.observe(U),()=>Y.disconnect()},[s]);const C=v.useCallback(()=>{let U=!0;return h(!0),u(null),Zg().then(Y=>{U&&(i(Y.repos),l(Y.board))}).catch(Y=>{U&&u(Y instanceof Error?Y.message:String(Y))}).finally(()=>{U&&h(!1)}),()=>{U=!1}},[]);v.useEffect(C,[C]);const E=v.useCallback(()=>{Zg().then(U=>{i(U.repos),l(U.board)}).catch(U=>{u(U instanceof Error?U.message:String(U))})},[]),j=v.useCallback(U=>{l(U),ek(U).catch(Y=>{u(Y instanceof Error?Y.message:String(Y))})},[]),N=v.useCallback(async U=>{const Y=U.trim();if(!Y.startsWith("/"))return t("git.board.absolutePathError");try{const P=QR(Y);await ji("/api/git/repositories",{name:P,path:Y});const V=await Zg();i(V.repos);const W=(V.board.includes(P)?V.board:[...V.board,P]).slice(0,ru);return l(W),await ek(W),null}catch(P){return P instanceof Error?P.message:String(P)}},[t]),A=new Map((s??[]).map(U=>[U.name,U])),T=a.map(U=>A.get(U)).filter(U=>!!U).slice(0,ru),D=(s??[]).filter(U=>!a.includes(U.name)),z=T.length<ru,O=Math.max(0,_-(z?fse:0)),$=_===0?ru:Math.max(1,Math.floor((O+S0)/(hse+S0))),M=Math.min(T.length,$),I=T.slice(0,M),G=T.length-M;function B(U){const Y=b.current;if(b.current=null,Y===null||Y===U)return;const P=[...a],[V]=P.splice(Y,1);P.splice(U,0,V),j(P)}return n.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[n.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:[n.jsxs("span",{className:"flex items-center gap-1.5 text-[12px] font-semibold tracking-tight",children:[n.jsx(R0,{className:"size-3.5"}),t("git.board.repositories"),s?n.jsxs(Ze,{variant:"secondary",className:"ml-1",children:[T.length,s.length>T.length?` / ${s.length}`:""]}):null,G>0?n.jsx("span",{className:"ml-1 text-[10px] font-normal text-muted-foreground",children:t("git.board.hidden",{count:G})}):null]}),n.jsxs(Q,{"aria-label":t("git.board.refreshAria"),disabled:f,onClick:C,size:"sm",type:"button",variant:"outline",children:[n.jsx(Mi,{className:f?"animate-spin":void 0}),t("common.refresh")]})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:c?n.jsx(nt,{variant:"destructive",className:"m-3",children:c}):s&&s.length===0?n.jsx(nt,{variant:"muted",className:"m-3 text-center",children:t("git.board.emptyRegistered")}):n.jsxs("div",{className:"flex h-full min-h-0 gap-2 p-2",ref:x,children:[I.map((U,Y)=>n.jsx(pse,{repo:U,isCurrent:!!e&&U.path===e,selectedFile:p?.repo===U.name?p.file:"",onSelectFile:P=>g({repo:U.name,file:P}),onRemove:()=>j(a.filter(P=>P!==U.name)),onMutated:E,onDragStart:()=>{b.current=Y},onDropColumn:()=>B(Y)},U.name)),z?n.jsx(gse,{unpinned:D,onAdd:U=>j([...a,U].slice(0,ru)),onRegister:N}):null]})}),p?n.jsx(cse,{repo:p.repo,file:p.file,onClose:()=>g(null)}):null]})}function pse({repo:e,isCurrent:t,selectedFile:s,onSelectFile:i,onRemove:a,onMutated:l,onDragStart:c,onDropColumn:u}){const f=X(),[h,p]=v.useState(!1),[g,b]=v.useState(!1),[x,_]=v.useState(!1),k=v.useCallback(async(N,A)=>{if(A.length){b(!0);try{await N(A,e.name),l()}finally{b(!1)}}},[e.name,l]),C={busy:g,onStage:N=>{k(I0,N)},onUnstage:N=>{k(d3,N)}},E=e.files.filter(N=>N.index.trim()&&N.index!=="?").length,j=x?kn:gn;return n.jsxs("div",{className:se("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:N=>{N.preventDefault(),p(!0)},onDragLeave:()=>p(!1),onDrop:()=>{p(!1),u()},children:[n.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:[n.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[n.jsx(o8,{className:"size-3.5 shrink-0 text-muted-foreground/60"}),n.jsx("span",{className:"truncate text-[12px] font-semibold",title:e.path,children:e.name}),t?n.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:[n.jsx(rn,{className:"size-2.5"}),f("git.board.current")]}):null]}),n.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[n.jsxs("span",{className:"flex items-center gap-1 font-mono text-[10px] text-muted-foreground",children:[e.ahead?n.jsxs("span",{className:"flex items-center",title:f("git.board.aheadTitle",{count:e.ahead}),children:[n.jsx(tm,{className:"size-3"}),e.ahead]}):null,e.behind?n.jsxs("span",{className:"flex items-center",title:f("git.board.behindTitle",{count:e.behind}),children:[n.jsx(em,{className:"size-3"}),e.behind]}):null]}),n.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:n.jsx(Gt,{className:"size-3.5"})})]})]}),n.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:n.jsx(gR,{branch:e.branch||void 0,error:e.error,files:e.files,onSelectFile:i,root:e.path,selectedFile:s,staging:C})}),n.jsxs("div",{className:"shrink-0 border-t border-border",children:[n.jsxs("button",{"aria-expanded":x,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:()=>_(N=>!N),type:"button",children:[n.jsx(j,{className:"size-3.5 shrink-0"}),n.jsx("span",{className:"flex-1",children:f("git.commit.title")}),E?n.jsx(Ze,{size:"small",variant:"secondary",children:f("git.commit.stagedCount",{count:E})}):null]}),x?n.jsx(bR,{branch:e.branch||void 0,files:e.files,onDone:l,repo:e.name}):null]})]})}function gse({unpinned:e,onAdd:t,onRegister:s}){const i=X(),[a,l]=v.useState(!1),[c,u]=v.useState(null),[f,h]=v.useState(""),[p,g]=v.useState(null),[b,x]=v.useState(!1),[_,k]=v.useState(!1),[C,E]=v.useState(""),j=v.useRef(null),N=v.useRef(null);function A(){if(a){l(!1);return}u(j.current?.getBoundingClientRect()??null),g(null),l(!0)}v.useEffect(()=>{if(!a)return;function z(O){const $=O.target;$ instanceof Node&&(N.current?.contains($)||j.current?.contains($)||l(!1))}return document.addEventListener("mousedown",z),()=>document.removeEventListener("mousedown",z)},[a]);async function T(z){x(!0),g(null);const O=await s(z);return x(!1),O?(g(O),!1):(h(""),l(!1),!0)}async function D(z){z.preventDefault(),await T(f)}return n.jsxs("div",{className:"w-44 shrink-0",children:[n.jsxs("button",{ref:j,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:A,type:"button",children:[n.jsx(Es,{className:"size-5"}),n.jsx("span",{className:"text-[12px] font-medium",children:i("git.board.addRepo")})]}),a&&c?Xn.createPortal(n.jsxs("div",{ref:N,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?n.jsxs("div",{className:"border-b border-border",children:[n.jsx("div",{className:"px-3 pb-1 pt-2 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:i("git.board.pinRegistered")}),n.jsx("div",{className:"max-h-52 overflow-auto pb-1",children:e.map(z=>n.jsxs("button",{className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm hover:bg-muted",onClick:()=>{t(z.name),l(!1)},type:"button",children:[n.jsx(R0,{className:"size-3.5 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"min-w-0 flex-1 truncate",title:z.path,children:z.name}),z.files.length?n.jsx(Ze,{variant:"outline",className:"h-5 px-1.5 text-[10px]",children:z.files.length}):null]},z.name))})]}):null,n.jsxs("div",{className:"p-2.5",children:[n.jsx("div",{className:"pb-1.5 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:i("git.board.addNew")}),n.jsxs("form",{className:"flex gap-1.5",onSubmit:D,children:[n.jsx(St,{"aria-label":i("git.board.absPathAria"),className:"h-7 flex-1 px-2 font-mono text-[11px]",onChange:z=>{h(z.target.value),g(null)},placeholder:"/absolute/path/to/repo",value:f}),n.jsx(Q,{className:"h-7 px-2 text-[11px]",disabled:b||!f.trim(),size:"sm",type:"submit",children:i("common.add")})]}),n.jsxs(Q,{className:"mt-1.5 h-7 w-full gap-1.5 text-[11px]",disabled:b,onClick:()=>{E(f.trim()||""),k(!0)},size:"sm",type:"button",variant:"outline",children:[n.jsx(vf,{className:"size-3"}),i("git.board.browseFolders")]}),p?n.jsx("div",{className:"mt-1.5 text-[10px] text-destructive",children:p}):null]})]}),document.body):null,_?n.jsx(w0,{confirmLabel:i("git.board.addRepo"),errorMessage:p,initialPath:C||"/",selectedPath:C,title:i("git.board.addRepoTitle"),onCancel:()=>k(!1),onSelect:E,onUse:async()=>{await T(C)&&k(!1)}}):null]})}const k0=300,bse=600,vse=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 xse(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:!vse.has(t.slice(s+1))}function yse(e){return e>=bse?"danger":e>=k0?"warn":"ok"}const _se={ok:"bg-emerald-500/60",warn:"bg-amber-500/70",danger:"bg-destructive/70"},wse={ok:"text-muted-foreground",warn:"text-amber-600 dark:text-amber-400",danger:"text-destructive"};function Sse({onOpenFile:e,root:t}){const s=X(),[i,a]=v.useState([]),[l,c]=v.useState(!0),[u,f]=v.useState(null),[h,p]=v.useState(!0);function g(){c(!0),f(null),i9().then(a).catch(C=>f(C instanceof Error?C.message:String(C))).finally(()=>c(!1))}v.useEffect(()=>{g()},[]);const b=v.useMemo(()=>h?i.filter(C=>xse(C.path)):i,[i,h]),x=i.length-b.length,_=b[0]?.lines??1,k=b.filter(C=>C.lines>=k0).length;return n.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[n.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-2",children:[n.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[n.jsx(zj,{className:"size-4"}),n.jsx("span",{className:"font-semibold text-foreground",children:s("git.largest.title")}),!l&&!u?n.jsxs("span",{children:[s("git.largest.summary",{visible:b.length,over:k,warn:k0}),h&&x>0?s("git.largest.hiddenSuffix",{hidden:x}):""]}):null]}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsxs(Q,{size:"sm",variant:h?"default":"outline",className:"h-7",onClick:()=>p(C=>!C),title:s("git.largest.codeOnlyTitle"),type:"button",children:[n.jsx(Dj,{}),s("git.largest.codeOnly")]}),n.jsxs(Q,{size:"sm",variant:"outline",className:"h-7",onClick:g,disabled:l,type:"button",children:[l?n.jsx(Bt,{className:"animate-spin"}):n.jsx(Mi,{}),s("common.refresh")]})]})]}),u?n.jsx(nt,{variant:"destructive",className:"m-3",children:u}):l&&i.length===0?n.jsxs("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:[n.jsx(Bt,{className:"mr-2 size-4 animate-spin"}),s("git.largest.scanning")]}):b.length===0?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i.length===0?s("git.largest.noTextFiles"):s("git.largest.noCodeFiles")}):n.jsx("ul",{className:"min-h-0 flex-1 divide-y divide-border/60 overflow-auto",children:b.map((C,E)=>{const j=yse(C.lines);return n.jsxs("li",{className:"group flex items-center gap-3 px-3 transition-colors hover:bg-muted/50",children:[n.jsx("span",{className:"w-6 shrink-0 text-right font-mono text-[10px] text-muted-foreground",children:E+1}),n.jsx("button",{type:"button",onClick:()=>e(C.path),className:"min-w-0 flex-1 py-1.5 text-left",children:n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("span",{className:"truncate font-mono text-[11px]",children:C.path}),n.jsxs("span",{className:se("shrink-0 font-mono text-[11px] tabular-nums",wse[j]),children:[C.truncated?"≥":"",s("git.largest.linesCount",{count:C.lines.toLocaleString()})]})]}),n.jsx("div",{className:"mt-1 h-1 w-full overflow-hidden rounded-full bg-muted",children:n.jsx("div",{className:se("h-full rounded-full",_se[j]),style:{width:`${Math.max(2,C.lines/_*100)}%`}})})]})}),n.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-0.5",children:[n.jsx(kse,{file:C,root:t}),n.jsx(Cse,{file:C,root:t})]})]},C.path)})})]})}function kse({file:e,root:t}){const s=X(),{sendToAgent:i}=Vt(),a=Xu(t,e.path),l=e.path.split("/").pop()??e.path;function c(){i({prompt:Rq({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 u(){i({prompt:a,source:{label:l,type:"large-file"},mode:"draft"})}return n.jsx(JR,{label:s("git.largest.aiActions",{path:e.path}),trigger:n.jsx(cs,{className:"size-3.5"}),children:f=>n.jsxs(n.Fragment,{children:[n.jsx(Eu,{icon:n.jsx(cs,{className:"size-3.5"}),onSelect:()=>{f(),c()},children:s("git.largest.askSplit")}),n.jsx(Eu,{icon:n.jsx(Oj,{className:"size-3.5"}),onSelect:()=>{f(),u()},children:s("git.largest.sendPath")})]})})}function Cse({file:e,root:t}){const s=X(),{error:i,success:a}=gs(),l=Xu(t,e.path),c=e.path.split("/").pop()??e.path;async function u(f,h){try{await navigator.clipboard.writeText(f),a(s("git.largest.copiedWhat",{what:h}))}catch(p){i(p instanceof Error?p.message:s("git.largest.couldNotCopy",{what:h}))}}return n.jsx(JR,{label:s("git.largest.copyPathFor",{path:e.path}),trigger:n.jsxs(n.Fragment,{children:[n.jsx(Lj,{className:"size-3.5"}),n.jsx("span",{className:"sr-only",children:s("common.moreActions")})]}),children:f=>n.jsxs(n.Fragment,{children:[n.jsx(Eu,{icon:n.jsx(T0,{className:"size-3.5"}),onSelect:()=>{f(),u(c,s("git.largest.whatFileName"))},children:s("git.largest.copyFileName")}),n.jsx(Eu,{icon:n.jsx(gf,{className:"size-3.5"}),onSelect:()=>{f(),u(e.path,s("git.largest.whatRelPath"))},children:s("git.largest.copyRelPath")}),n.jsx(Eu,{icon:n.jsx(gf,{className:"size-3.5"}),onSelect:()=>{f(),u(l,s("git.largest.whatAbsPath"))},children:s("git.largest.copyAbsPath")})]})})}function JR({children:e,label:t,trigger:s}){const[i,a]=v.useState(!1),[l,c]=v.useState({right:0,top:0}),u=v.useRef(null),f=v.useRef(null);function h(){a(!1)}function p(){const g=u.current?.getBoundingClientRect();g&&c({top:g.bottom+6,right:window.innerWidth-g.right}),a(b=>!b)}return v.useEffect(()=>{if(!i)return;function g(x){const _=x.target;u.current?.contains(_)||f.current?.contains(_)||h()}function b(x){x.key==="Escape"&&h()}return document.addEventListener("mousedown",g),document.addEventListener("keydown",b),window.addEventListener("scroll",h,!0),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",b),window.removeEventListener("scroll",h,!0)}},[i]),n.jsxs(n.Fragment,{children:[n.jsx("button",{"aria-label":t,className:se("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",i&&"bg-muted text-foreground opacity-100"),onClick:p,ref:u,title:t,type:"button",children:s}),i?Xn.createPortal(n.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 Eu({children:e,icon:t,onSelect:s}){return n.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:[n.jsx("span",{className:"text-muted-foreground",children:t}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:e})]})}function Nse({data:e,onRefresh:t}){const s=X(),{insertPath:i}=Vt(),[a,l]=v.useState(!1),[c,u]=v.useState("changes"),[f,h]=v.useState("changes"),[p,g]=v.useState(e.git.status?.files[0]?.path??""),[b,x]=v.useState(""),[_,k]=v.useState([]),[C,E]=v.useState(null),[j,N]=v.useState(""),[A,T]=v.useState(null),[D,z]=v.useState(0),[O,$]=v.useState(null),[M,I]=v.useState(()=>new Set),G=e.git.status?.files??[],B=v.useMemo(()=>{const Re=new Set(G.map(Be=>Be.path)),ie=[...M].filter(Be=>!Re.has(Be)).sort().map(Be=>({path:Be,index:" ",workingTree:"M"}));return[...G,...ie]},[G,M]),U=v.useMemo(()=>B.map(Re=>Re.path),[B]),Y=v.useMemo(()=>x1(j),[j]),P=v.useCallback(async(Re,ie)=>{if(ie.length){l(!0);try{await Re(ie),t?.()}finally{l(!1)}}},[t]),V=t?{busy:a,onStage:Re=>{P(I0,Re)},onUnstage:Re=>{P(d3,Re)}}:void 0;v.useEffect(()=>{const Re=B[0]?.path??"";g(ie=>ie&&B.some(Be=>Be.path===ie)?ie:Re)},[B]),v.useEffect(()=>{if(c!=="all"||_.length>0)return;let Re=!0;return E(null),n9().then(ie=>{Re&&k(ie)}).catch(ie=>{Re&&E(ie instanceof Error?ie.message:String(ie))}),()=>{Re=!1}},[c,_.length]),v.useEffect(()=>{if(!p){N("");return}let Re=!0;return T(null),u3(p).then(ie=>{Re&&(N(ie),z(0),$(null))}).catch(ie=>{Re&&T(ie instanceof Error?ie.message:String(ie))}),()=>{Re=!1}},[p]);function W(Re){z(0),$(null),g(Re)}function re(){const Re=Zte({activeHunkIndex:D,filePaths:U,hunkCount:Y.hunks,pendingNextFilePath:O,selectedFile:p});Re.kind==="hunk"?($(null),z(Re.activeHunkIndex)):Re.kind==="confirm-next-file"?$(Re.filePath):Re.kind==="file"?W(Re.filePath):$(null)}function ce(){if($(null),D>0){z(Be=>Be-1);return}const Re=B.findIndex(Be=>Be.path===p),ie=B[Re-1];ie&&W(ie.path)}const F=B.findIndex(Re=>Re.path===p),K=!!(Y.hunks&&D<Y.hunks-1||B[F+1]),ue=!!(D>0||B[F-1]),ge=O?s("git.navHintEndOfFile",{path:O}):null,J=Re=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${Re?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`,ne=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"}`,Le=v.useMemo(()=>{const Re=new Set(B.map(ie=>ie.path));for(const ie of M)Re.add(ie);return Re},[B,M]);if(!e.git.selectedRepository)return n.jsx(Ese,{});function ve(){b&&(u("changes"),h("changes"),W(b))}function Se(Re){I(ie=>new Set(ie).add(Re)),x(Re),u("changes"),h("changes"),W(Re)}function Ve(Re){x(Re),u("all")}function rt(Re){Re&&i(Xu(e.git.cwd,Re))}return n.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:[n.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border bg-card/95 px-3 py-1",children:[n.jsx("button",{type:"button",className:J(c==="changes"),onClick:()=>u("changes"),children:s("git.tab.changes")}),n.jsx("button",{type:"button","aria-label":s("git.boardAria"),className:J(c==="board"),onClick:()=>u("board"),children:s("git.tab.board")}),n.jsx("button",{type:"button","aria-label":s("git.allFilesAria"),className:J(c==="all"),onClick:()=>u("all"),children:s("git.tab.all")}),n.jsx("button",{type:"button",className:J(c==="graph"),onClick:()=>u("graph"),children:s("git.tab.tree")}),n.jsx("button",{type:"button",className:J(c==="largest"),onClick:()=>u("largest"),children:s("git.tab.largest")}),n.jsx("button",{type:"button",className:J(c==="snapshots"),onClick:()=>u("snapshots"),children:s("git.tab.snapshots")})]}),n.jsx("div",{className:"min-h-0 flex-1",children:c==="board"?n.jsx(mse,{currentRepoPath:e.git.cwd}):c==="graph"?n.jsx(lse,{branches:e.git.branches??[]}):c==="largest"?n.jsx(Sse,{onOpenFile:Ve,root:e.git.cwd}):c==="snapshots"?n.jsx(lq,{}):c==="all"?n.jsxs("div",{className:"grid h-full min-h-0 overflow-hidden border-0 bg-card/85 xl:grid-cols-[320px_minmax(0,1fr)]",children:[n.jsx("aside",{className:"flex min-h-0 flex-col overflow-hidden",children:C?n.jsx(nt,{variant:"destructive",className:"m-3",children:C}):n.jsx($N,{branch:e.git.status?.branch||void 0,onSelectFile:x,paths:_,root:e.git.cwd,selectedFile:b,status:B})}),n.jsx(Xte,{isModified:Le.has(b),onFileSaved:Se,onSendToAi:()=>rt(b),onViewDiff:ve,path:b})]}):n.jsxs("div",{className:"grid h-full min-h-0 overflow-hidden border-0 bg-card/85 xl:grid-cols-[320px_minmax(0,1fr)]",children:[n.jsxs("aside",{className:"flex min-h-0 flex-col overflow-hidden",children:[n.jsxs("div",{className:"flex shrink-0 gap-0.5 border-b border-border bg-card/95 p-1",children:[n.jsx("button",{"aria-label":s("git.modeListAria"),className:ne(f==="changes"),onClick:()=>h("changes"),type:"button",children:s("git.tab.changes")}),n.jsx("button",{"aria-label":s("git.modeTreeAria"),className:ne(f==="tree"),onClick:()=>h("tree"),type:"button",children:s("git.tab.tree")})]}),f==="changes"?n.jsx(gR,{branch:e.git.status?.branch||void 0,error:e.git.error,files:B,selectedFile:p,onSelectFile:W,root:e.git.cwd,staging:V}):n.jsx($N,{branch:e.git.status?.branch||void 0,defaultExpandAll:!0,emptyMessage:e.git.error??s("git.noChangedFiles"),onSelectFile:W,paths:U,root:e.git.cwd,selectedFile:p,status:B,title:s("git.tab.changes")}),t&&e.git.status?n.jsx(bR,{branch:e.git.status.branch||void 0,files:B,onDone:t}):null]}),n.jsxs("section",{className:"flex min-h-0 min-w-0 flex-col border-l border-border bg-card",children:[n.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border px-3 py-1.5",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:p||s("git.diff")}),n.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[10px] text-muted-foreground",children:[n.jsx("span",{children:s("git.longRowsWrap")}),Y.additions||Y.deletions?n.jsxs("span",{className:"flex items-center gap-1 font-mono",children:[n.jsxs("span",{className:"text-emerald-700",children:["+",Y.additions]}),n.jsxs("span",{className:"text-red-700",children:["-",Y.deletions]})]}):null]})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[ge?n.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:ge}):null,n.jsxs(Q,{disabled:!p||!ue,onClick:ce,size:"sm",type:"button",variant:"outline",children:[n.jsx(tm,{}),s("git.previous")]}),n.jsxs(Q,{disabled:!p||!K,onClick:re,size:"sm",type:"button",variant:"outline",children:[n.jsx(em,{}),s("git.next")]}),n.jsx(Q,{"aria-label":s("git.sendToAiAria"),className:"size-8",disabled:!p,onClick:()=>rt(p),size:"icon",title:s("git.sendToAiTitle"),type:"button",variant:"outline",children:n.jsx(cs,{className:"size-4"})})]})]}),n.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:A?n.jsx("div",{className:"p-4",children:n.jsx(nt,{variant:"destructive",children:A})}):p?n.jsx(Yu,{activeHunkIndex:D,diff:j||s("git.noUnstagedDiff")}):n.jsx("div",{className:"p-4",children:n.jsx(nt,{variant:"muted",className:"border-dashed p-12 text-center",children:s("git.selectFilePrompt")})})})]})]})})]})}function Ese(){const e=X();return n.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center",children:n.jsxs("div",{className:"max-w-sm",children:[n.jsx(R0,{className:"mx-auto size-8 text-muted-foreground/50"}),n.jsx("p",{className:"mt-3 text-sm font-medium",children:e("git.noRepoTitle")}),n.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:e("git.noRepoBody")})]})})}function uj(e,t,s){const i=e.trim(),a=i.toLowerCase(),l=[],c=/\breview|check|inspect|audit\b/.test(a),u=/\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),p=/\bpr\b|pull request/.test(a),g=Ase(a,s);return p&&l.push({kind:"action",id:"assert-pr-branch",title:"Check PR branch",op:"assert-pr-branch"}),c&&(l.push(Wh("gate-review","Approve review","Review the current changes?")),l.push(au("review","Review changes","Review the current git changes. Summarize risks, likely bugs, and anything that should change before committing.",Kh(g,["skills","mcpServers"])))),u&&l.push(au("verify","Run verification","Run the relevant tests or checks for this repository. If something fails, stop and explain the failure.",Kh(g,["skills","mcpServers","plugins"]))),f&&(l.push(au("commit-message","Generate commit message","Stage the appropriate changed files, inspect the staged diff briefly, and draft one conventional commit message. Do not commit.",Kh(g,["skills"]))),l.push(Wh("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(Wh("gate-push","Approve push",p?"Push and continue toward a PR?":"Push this branch?")),l.push({kind:"action",id:"push",title:"Push branch",op:"push"})),p&&(l.push(au("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.",Kh(g,["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(Wh("gate-start","Approve start","Run this workflow?")),l.push(au("ai-step","AI step",i||"Complete this workflow step.",g))),{id:Rse(e4(dj(a))||"custom-workflow",t),name:dj(a),description:i||"Custom AI-authored workflow.",builtin:!1,steps:Tse(l)}}function jse(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(`
|
|
226
226
|
`)}function dj(e){const t=/\breview|check|inspect|audit\b/.test(e),s=/\bcommit\b|\bship|push|pr|pull request\b/.test(e),i=/\bpr\b|pull request/.test(e),a=/\btest|verify|ci\b/.test(e);return t&&s&&i?"Review, Commit & PR":a&&s&&i?"Verify, Commit & PR":t&&s?"Review & Commit":s&&i?"Commit & PR":s?"Commit workflow":t?"Review workflow":"Custom workflow"}function Wh(e,t,s){return{kind:"gate",id:e,title:t,message:s}}function au(e,t,s,i,a){return{kind:"agent",id:e,title:t,prompt:s,capabilities:X1(i),verify:a}}function Ase(e,t){return X1({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 Kh(e,t){const s={};for(const i of t){const a=e[i];a?.length&&(s[i]=a)}return X1(s)}function X1(e){if(!e)return;const t={};for(const s of["skills","mcpServers","plugins","hooks"]){const i=Array.from(new Set((e[s]??[]).filter(Boolean)));i.length&&(t[s]=i)}return Object.keys(t).length?t:void 0}function Tse(e){const t=new Map;return e.map(s=>{const i=e4(s.id)||s.kind,a=t.get(i)??0;return t.set(i,a+1),a===0?{...s,id:i}:{...s,id:`${i}-${a+1}`}})}function Rse(e,t){const s=new Set(t.map(l=>l.id));let i=e||"workflow",a=2;for(;s.has(i);)i=`${e}-${a}`,a++;return i}function e4(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}const Zf={"error-incident":"workflows.triggers.eventErrorIncident","service-crash":"workflows.triggers.eventServiceCrash","ci-failure":"workflows.triggers.eventCiFailure"};function Mse({workflows:e}){const t=X(),{triggers:s,pending:i,error:a,saveTrigger:l,removeTrigger:c,runPending:u,dismissPending:f}=ZV(),[h,p]=v.useState(!1),g=b=>e.find(x=>x.id===b)?.name??b;return n.jsxs("section",{className:"border-t border-border px-4 py-3",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsxs("div",{children:[n.jsxs("h3",{className:"flex items-center gap-1.5 text-[12px] font-semibold",children:[n.jsx(Zj,{className:"size-3.5 text-amber-500"})," ",t("workflows.triggers.title")]}),n.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:t("workflows.triggers.subtitle")})]}),n.jsxs(Q,{onClick:()=>p(b=>!b),size:"sm",type:"button",variant:"outline",children:[n.jsx(Es,{className:"size-3.5"})," ",t("workflows.triggers.add")]})]}),a?n.jsx("p",{className:"mt-2 text-[11px] text-destructive",children:a}):null,i.length>0?n.jsx("div",{className:"mt-3 space-y-1.5",children:i.map(b=>n.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:[n.jsxs("div",{className:"min-w-0",children:[n.jsxs("div",{className:"truncate text-[11px] font-medium",children:[g(b.workflowId),n.jsxs("span",{className:"ml-1.5 text-muted-foreground",children:["· ",t(Zf[b.event])]})]}),n.jsx("div",{className:"truncate text-[10px] text-muted-foreground",children:b.summary})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[n.jsxs(Q,{onClick:()=>u(b),size:"sm",type:"button",variant:"outline",children:[n.jsx(_r,{className:"size-3"})," ",t("workflows.run")]}),n.jsx(Q,{onClick:()=>{f(b.id)},size:"icon",type:"button",variant:"ghost","aria-label":t("workflows.triggers.dismiss"),children:n.jsx(Gt,{className:"size-3.5"})})]})]},b.id))}):null,h?n.jsx(Dse,{workflows:e,onCancel:()=>p(!1),onSave:async b=>{await l(b),p(!1)}}):null,n.jsxs("div",{className:"mt-3 space-y-1.5",children:[s.length===0&&!h?n.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:t("workflows.triggers.empty")}):null,s.map(b=>n.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-border px-2.5 py-1.5",children:[n.jsxs("label",{className:"flex min-w-0 items-center gap-2",children:[n.jsx("input",{checked:b.enabled,className:"size-3.5 accent-primary",onChange:x=>{l({...b,enabled:x.target.checked})},type:"checkbox"}),n.jsxs("span",{className:"min-w-0 truncate text-[11px]",children:[n.jsx("span",{className:"font-medium",children:t(Zf[b.event])}),b.filter?n.jsxs("span",{className:"text-muted-foreground",children:[" · “",b.filter,"”"]}):null,n.jsxs("span",{className:"text-muted-foreground",children:[" → ",g(b.workflowId)]}),b.autoRun?n.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]})]}),n.jsx(Q,{onClick:()=>{c(b.id)},size:"icon",type:"button",variant:"ghost","aria-label":t("workflows.triggers.deleteAria"),children:n.jsx(Xi,{className:"size-3.5"})})]},b.id))]})]})}function Dse({workflows:e,onCancel:t,onSave:s}){const i=X(),[a,l]=v.useState("error-incident"),[c,u]=v.useState(e[0]?.id??""),[f,h]=v.useState(""),[p,g]=v.useState(!1),b="rounded border border-border bg-background px-2 py-1 text-[11px] outline-none focus:border-primary";return n.jsxs("div",{className:"mt-3 space-y-2 rounded-md border border-border bg-background p-3",children:[n.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[n.jsxs("label",{className:"flex flex-col gap-1 text-[10px] font-medium text-muted-foreground",children:[i("workflows.triggers.when"),n.jsx("select",{className:b,value:a,onChange:x=>l(x.target.value),children:Object.keys(Zf).map(x=>n.jsx("option",{value:x,children:i(Zf[x])},x))})]}),n.jsxs("label",{className:"flex flex-col gap-1 text-[10px] font-medium text-muted-foreground",children:[i("workflows.triggers.runWorkflow"),n.jsx("select",{className:b,value:c,onChange:x=>u(x.target.value),children:e.map(x=>n.jsx("option",{value:x.id,children:x.name},x.id))})]})]}),n.jsxs("label",{className:"flex flex-col gap-1 text-[10px] font-medium text-muted-foreground",children:[i("workflows.triggers.filterLabel"),n.jsx("input",{className:b,value:f,onChange:x=>h(x.target.value),placeholder:"e.g. api",type:"text"})]}),n.jsxs("label",{className:"flex w-fit items-center gap-1.5 text-[11px] text-muted-foreground",children:[n.jsx("input",{checked:p,className:"size-3.5 accent-primary",onChange:x=>g(x.target.checked),type:"checkbox"}),i("workflows.triggers.autoRunLabel")]}),n.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[n.jsx(Q,{onClick:t,size:"sm",type:"button",variant:"ghost",children:i("common.cancel")}),n.jsx(Q,{disabled:!c,onClick:()=>{s({id:`trigger-${Date.now().toString(36)}`,event:a,workflowId:c,filter:f.trim()||void 0,enabled:!0,autoRun:p})},size:"sm",type:"button",children:i("common.add")})]})]})}function Lse(){const e=X(),{run:t,start:s,resume:i,approve:a,skip:l,stop:c,dismiss:u}=XA(),[f,h]=v.useState([]),[p,g]=v.useState(null),[b,x]=v.useState(null),[_,k]=v.useState(null),[C,E]=v.useState(!0),[j,N]=v.useState(!1),[A,T]=v.useState(!0);v.useEffect(()=>{let M=!0;return E(!0),Promise.all([y3(),B0().catch(()=>null)]).then(([I,G])=>{M&&(h(I),g(G))}).catch(I=>{M&&k(I instanceof Error?I.message:String(I))}).finally(()=>{M&&E(!1)}),()=>{M=!1}},[]);function D(M){N(!0),s(M,A)}async function z(M){k(null);try{const I=await Oz(M);h(I),x(null)}catch(I){k(I instanceof Error?I.message:String(I))}}async function O(M){if(!M.builtin&&window.confirm(e("workflows.deleteConfirm",{name:M.name}))){k(null);try{h(await Pz(M.id))}catch(I){k(I instanceof Error?I.message:String(I))}}}function $(M){x({...M,id:Z1(`${M.id}-copy`,f),name:`${M.name} copy`,builtin:!1,steps:M.steps.map((I,G)=>({...I,id:`${I.id}-${G+1}`}))})}return t&&j?n.jsx(qse,{run:t,onApprove:a,onSkip:l,onStop:c,onBack:()=>N(!1),onResume:()=>{N(!0),i(A)},onRestart:()=>{N(!0),s(t.workflow,A)}}):b?n.jsx(zse,{agent:p?Wse(p):null,existing:f,initial:b,onCancel:()=>x(null),onSave:M=>{z(M)}}):n.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-auto bg-card/85",children:[n.jsxs("div",{className:"border-b border-border px-4 py-3",children:[n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsxs("div",{children:[n.jsxs("h2",{className:"flex items-center gap-1.5 text-[13px] font-semibold",children:[n.jsx(cs,{className:"size-4"})," ",e("workflows.title")]}),n.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:e("workflows.subtitle")})]}),n.jsxs(Q,{onClick:()=>x(Yse(f)),size:"sm",type:"button",variant:"outline",children:[n.jsx(Es,{className:"size-3.5"})," ",e("workflows.new")]})]}),n.jsxs("label",{className:"mt-2 flex w-fit items-center gap-1.5 text-[11px] text-muted-foreground",children:[n.jsx("input",{checked:A,className:"size-3.5 accent-primary",onChange:M=>T(M.target.checked),type:"checkbox"}),e("workflows.autoApprove"),n.jsx("span",{className:"text-muted-foreground/60",children:e("workflows.autoApproveHint")})]})]}),_?n.jsx(nt,{variant:"destructive",className:"m-4",children:_}):C?n.jsxs("div",{className:"flex flex-1 items-center justify-center text-[12px] text-muted-foreground",children:[n.jsx(Bt,{className:"mr-2 size-4 animate-spin"})," ",e("workflows.loading")]}):n.jsxs(n.Fragment,{children:[t?n.jsx(Ose,{onClear:u,onView:()=>N(!0),run:t}):null,n.jsx("div",{className:"grid gap-3 p-4 sm:grid-cols-2 xl:grid-cols-3",children:f.map(M=>n.jsx(Pse,{lastRun:t?.workflow.id===M.id?t:null,workflow:M,onDelete:()=>{O(M)},onDuplicate:()=>$(M),onEdit:()=>x(M),onRun:()=>D(M)},M.id))}),n.jsx(Mse,{workflows:f})]})]})}function Ose({onClear:e,onView:t,run:s}){const i=X(),a=s.outcome==="running";return n.jsx("section",{className:"mx-4 mt-4 rounded-md border border-border bg-background p-3 shadow-sm",children:n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/70",children:i(a?"workflows.banner.running":"workflows.banner.last")}),n.jsx(i4,{outcome:s.outcome})]}),n.jsx("p",{className:"mt-1 truncate text-[13px] font-medium",children:s.workflow.name}),n.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:a?i("workflows.banner.startedAt",{time:C0(s.startedAt)}):i("workflows.banner.ranAt",{time:C0(s.startedAt)})})]}),n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[n.jsxs(Q,{onClick:t,size:"sm",type:"button",children:[n.jsx(ql,{className:"size-3.5"})," ",i("workflows.viewRun")]}),a?null:n.jsxs(Q,{onClick:e,size:"sm",type:"button",variant:"outline",children:[n.jsx(Gt,{className:"size-3.5"})," ",i("workflows.clear")]})]})]})})}function Pse({lastRun:e,workflow:t,onDelete:s,onDuplicate:i,onEdit:a,onRun:l}){const c=X(),[u,f]=v.useState(!1),h=t.steps.length;return n.jsxs("div",{className:"flex flex-col rounded-lg border border-border bg-background p-3.5 shadow-sm",children:[n.jsxs("div",{className:"flex items-start justify-between gap-2",children:[n.jsx("h3",{className:"text-[13px] font-semibold",children:t.name}),t.builtin?n.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?n.jsx("p",{className:"mt-1 text-[11px] leading-snug text-muted-foreground",children:t.description}):null,e?n.jsxs("p",{className:"mt-2 flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[n.jsx(ql,{className:"size-3"}),e.outcome==="running"?c("workflows.runningNow"):c("workflows.lastRun",{time:C0(e.startedAt)})]}):null,n.jsxs("button",{"aria-expanded":u,className:"mt-2.5 flex w-full items-center gap-1.5 text-[11px] text-muted-foreground transition-colors hover:text-foreground",onClick:()=>f(p=>!p),type:"button",children:[n.jsx(gn,{className:se("size-3 shrink-0 transition-transform",u?"rotate-90":""),"aria-hidden":!0}),n.jsx("span",{children:c(h===1?"workflows.stepOne":"workflows.stepMany",{count:h})})]}),u?n.jsx("ol",{className:"mt-1.5 space-y-1",children:t.steps.map(p=>n.jsxs("li",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[n.jsx(Qse,{kind:p.kind}),n.jsx("span",{className:"truncate",children:Qf(p)})]},p.id))}):null,n.jsxs(Q,{className:"mt-3 w-full",onClick:l,size:"sm",type:"button",children:[n.jsx(_r,{className:"size-3.5"})," ",c("workflows.run")]}),n.jsxs("div",{className:"mt-2 grid grid-cols-3 gap-1.5",children:[n.jsxs(Q,{onClick:a,size:"sm",type:"button",variant:"outline",children:[n.jsx(pL,{className:"size-3.5"})," ",c("common.edit")]}),n.jsxs(Q,{onClick:i,size:"sm",type:"button",variant:"outline",children:[n.jsx(gf,{className:"size-3.5"})," ",c("common.copy")]}),n.jsxs(Q,{disabled:t.builtin,onClick:s,size:"sm",title:t.builtin?c("workflows.deleteBuiltinHint"):c("workflows.deleteTitle"),type:"button",variant:"outline",children:[n.jsx(Xi,{className:"size-3.5"})," ",c("common.delete")]})]})]})}function zse({agent:e,existing:t,initial:s,onCancel:i,onSave:a}){const l=X(),[c,u]=v.useState(()=>structuredClone(s)),[f,h]=v.useState(s.description??""),[p,g]=v.useState(!1),b=Kse(e),{sendToAgent:x}=Vt(),_=!c.id.trim()||!c.name.trim()||c.steps.length===0;function k(z,O){u($=>({...$,steps:$.steps.map((M,I)=>I===z?O(M):M)}))}function C(z,O){u($=>{const M=z+O;if(M<0||M>=$.steps.length)return $;const I=[...$.steps],[G]=I.splice(z,1);return I.splice(M,0,G),{...$,steps:I}})}function E(z){u(O=>({...O,steps:O.steps.filter(($,M)=>M!==z)}))}function j(z,O){u($=>{const M=[...$.steps];return M.splice(z,0,Ise(O,$.steps)),{...$,steps:M}})}function N(z=f){const O=uj(z,t,b);u(O)}function A(z){const O=uj(z,[],b);u($=>({...$,steps:[...$.steps,...O.steps]}))}function T(){x({prompt:jse(f||c.description||c.name),source:{type:"workflow",label:l("workflows.builder.composerSource")},mode:"draft"})}function D(){const z=Bl(c.id)||Z1(Bl(c.name)||"workflow",t);a({...c,id:z,name:c.name.trim(),description:(f||c.description)?.trim()||void 0,builtin:!1,steps:c.steps.map(Xse)})}return n.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border px-4 py-3",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(cs,{className:"size-4 shrink-0"}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("input",{"aria-label":l("workflows.builder.nameAria"),className:"w-full bg-transparent text-[14px] font-semibold outline-none",onChange:z=>u(O=>({...O,name:z.target.value,id:Bl(z.target.value)||O.id})),placeholder:l("workflows.builder.namePlaceholder"),value:c.name}),n.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:c.id})]})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[n.jsxs(Q,{onClick:()=>g(z=>!z),size:"sm",type:"button",variant:p?"default":"outline",children:[n.jsx(Sn,{className:"size-3.5"})," ",l("workflows.builder.aiCompose")]}),n.jsxs(Q,{onClick:i,size:"sm",type:"button",variant:"outline",children:[n.jsx(Hu,{className:"size-3.5"})," ",l("common.back")]}),n.jsxs(Q,{disabled:_,onClick:D,size:"sm",type:"button",children:[n.jsx(rn,{className:"size-3.5"})," ",l("common.save")]})]})]}),p?n.jsx("section",{className:"shrink-0 border-b border-border bg-muted/20 p-4",children:n.jsxs("div",{className:"grid gap-3 xl:grid-cols-[minmax(0,1.1fr)_minmax(0,0.9fr)]",children:[n.jsxs("div",{className:"rounded-lg border border-border bg-background p-3 shadow-sm",children:[n.jsx(Yr,{children:l("workflows.builder.describe")}),n.jsx("textarea",{className:"min-h-16 w-full resize-none bg-transparent text-[13px] leading-relaxed outline-none placeholder:text-muted-foreground",onChange:z=>h(z.target.value),placeholder:l("workflows.builder.describePlaceholder"),value:f}),n.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:[n.jsxs(Q,{onClick:()=>N(),size:"sm",type:"button",children:[n.jsx(Sn,{className:"size-3.5"})," ",l("workflows.builder.draftTimeline")]}),n.jsxs(Q,{onClick:T,size:"sm",type:"button",variant:"outline",children:[n.jsx(q8,{className:"size-3.5"})," ",l("workflows.builder.askAi")]}),["Commit safely","Review then push","Fix CI then PR","File issue from changes"].map(z=>n.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(z),N(z)},type:"button",children:z},z))]})]}),n.jsxs("div",{className:"grid gap-3",children:[n.jsx(Hse,{onAdd:A}),n.jsx($se,{capabilities:b})]})]})}):null,n.jsx("main",{className:"min-h-0 flex-1 overflow-auto p-4",children:n.jsxs("div",{className:"mx-auto max-w-3xl",children:[n.jsx(hj,{onInsert:z=>j(0,z)}),c.steps.length?c.steps.map((z,O)=>n.jsxs(v.Fragment,{children:[n.jsxs("div",{className:"flex gap-4",children:[n.jsxs("div",{className:"relative flex w-9 shrink-0 justify-center pt-2",children:[n.jsx("span",{"aria-hidden":!0,className:"absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border"}),n.jsx(Bse,{index:O,kind:z.kind})]}),n.jsx("div",{className:"min-w-0 flex-1 pb-1",children:n.jsx(Fse,{capabilities:b,index:O,isFirst:O===0,isLast:O===c.steps.length-1,onMove:C,onRemove:E,onUpdate:k,step:z})})]}),n.jsx(hj,{onInsert:$=>j(O+1,$)})]},`${z.kind}:${z.id}`)):n.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 hj({defaultOpen:e=!1,onInsert:t}){const s=X(),[i,a]=v.useState(e),l=["gate","agent","action"];return n.jsxs("div",{className:"flex gap-4",children:[n.jsxs("div",{className:"relative flex w-9 shrink-0 justify-center",children:[n.jsx("span",{"aria-hidden":!0,className:"absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border"}),n.jsx("button",{"aria-label":s(i?"workflows.builder.cancelAddStep":"workflows.builder.addStepHere"),className:se("relative z-10 my-1.5 flex size-5 items-center justify-center rounded-full border bg-card text-muted-foreground transition-colors",i?"border-primary/50 text-primary":"border-border hover:border-primary/50 hover:text-primary"),onClick:()=>a(c=>!c),type:"button",children:i?n.jsx(Gt,{className:"size-3"}):n.jsx(Es,{className:"size-3"})})]}),n.jsx("div",{className:"flex-1 py-1",children:i?n.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:l.map(c=>n.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:[n.jsx(r4,{kind:c})," ",s(t4[c])]},c))}):null})]})}function Bse({index:e,kind:t}){return n.jsxs("div",{className:"relative z-10 flex size-9 items-center justify-center rounded-full border border-border bg-card shadow-sm",children:[n.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}),n.jsx(r4,{kind:t})]})}function Ise(e,t){const s=new Set(t.map(a=>a.id)),i=a=>{let l=a,c=2;for(;s.has(l);)l=`${a}-${c++}`;return l};return e==="gate"?{kind:"gate",id:i("gate"),title:"Approve step",message:"Continue?"}:e==="action"?{kind:"action",id:i("action"),title:"Commit with approved message",op:"commit"}:{kind:"agent",id:i("step"),title:"AI step",prompt:""}}function Hse({onAdd:e}){const t=X(),[s,i]=v.useState("");return n.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),i(""))},children:[n.jsx(Yr,{children:t("workflows.builder.addStepLabel")}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{className:"min-w-0 flex-1 bg-transparent text-[12px] outline-none placeholder:text-muted-foreground",onChange:a=>i(a.target.value),placeholder:t("workflows.builder.addStepPlaceholder"),value:s}),n.jsxs(Q,{size:"sm",type:"submit",variant:"outline",children:[n.jsx(Es,{className:"size-3.5"})," ",t("common.add")]})]})]})}function $se({capabilities:e}){const t=X(),s=[...e.skills.map(i=>`@skill:${i}`),...e.mcpServers.map(i=>`@mcp:${i}`),...e.plugins.map(i=>`@plugin:${i}`)].slice(0,18);return s.length?n.jsxs("div",{className:"rounded-lg border border-border bg-background p-3",children:[n.jsx(Yr,{children:t("workflows.builder.detectedCapabilities")}),n.jsx("div",{className:"flex max-h-20 flex-wrap gap-1.5 overflow-hidden",children:s.map(i=>n.jsx("span",{className:"rounded-md border border-border bg-muted/30 px-2 py-1 font-mono text-[11px] text-muted-foreground",children:i},i))})]}):null}function Fse({capabilities:e,index:t,isFirst:s,isLast:i,onMove:a,onRemove:l,onUpdate:c,step:u}){const f=X();return n.jsx("section",{className:"group rounded-lg border border-border bg-background p-3 shadow-sm",children:n.jsxs("div",{className:"flex items-start gap-3",children:[n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(N0,{kind:u.kind}),n.jsx("input",{className:"min-w-0 flex-1 bg-transparent text-[13px] font-semibold outline-none",onChange:h=>c(t,p=>({...p,title:h.target.value})),value:u.title})]}),u.kind==="gate"?n.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,p=>p.kind==="gate"?{...p,message:h.target.value}:p),placeholder:f("workflows.builder.gatePlaceholder"),value:u.message}):u.kind==="action"?n.jsxs("div",{className:"mt-2 space-y-1.5",children:[n.jsxs("select",{className:"w-full rounded-md border border-border bg-background px-2 py-1 text-[12px] outline-none",onChange:h=>{const p=h.target.value;c(t,g=>g.kind==="action"?{...g,op:p}:g)},value:u.op,children:[n.jsx("option",{value:"commit",children:f("workflows.op.commit")}),n.jsx("option",{value:"push",children:f("workflows.op.push")}),n.jsx("option",{value:"assert-pr-branch",children:f("workflows.op.assertPrBranch")}),n.jsx("option",{value:"checkout-default-and-pull",children:f("workflows.op.checkoutDefault")})]}),n.jsx("p",{className:"text-[11px] leading-relaxed text-muted-foreground",children:f(s4[u.op])})]}):n.jsxs(n.Fragment,{children:[n.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,p=>p.kind==="agent"?{...p,prompt:h.target.value}:p),placeholder:f("workflows.builder.agentPromptPlaceholder"),value:u.prompt}),n.jsx(Use,{capabilities:e,selected:u.capabilities,onToggle:(h,p)=>c(t,g=>g.kind==="agent"?{...g,capabilities:Zse(g.capabilities,h,p)}:g)})]})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-70 transition-opacity group-hover:opacity-100",children:[n.jsx(Q,{disabled:s,onClick:()=>a(t,-1),size:"sm",type:"button",variant:"ghost",children:"↑"}),n.jsx(Q,{disabled:i,onClick:()=>a(t,1),size:"sm",type:"button",variant:"ghost",children:"↓"}),n.jsx(Q,{onClick:()=>l(t),size:"sm",type:"button",variant:"ghost",children:n.jsx(Xi,{className:"size-3.5"})})]})]})})}function Use({capabilities:e,onToggle:t,selected:s}){const i=X(),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 n.jsxs("div",{className:"space-y-2",children:[n.jsx(Yr,{children:i("workflows.builder.capabilities")}),a.map(l=>n.jsxs("div",{children:[n.jsx("div",{className:"mb-1 text-[10px] text-muted-foreground",children:l.label}),l.values.length?n.jsx("div",{className:"flex flex-wrap gap-1.5",children:l.values.map(c=>{const u=s?.[l.key]?.includes(c)??!1;return n.jsx("button",{className:se("rounded-md border px-2 py-1 text-[11px] transition-colors",u?"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)})}):n.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:i("workflows.builder.noneDetected")})]},l.key))]})}function qse({run:e,onApprove:t,onSkip:s,onStop:i,onBack:a,onResume:l,onRestart:c}){const u=X(),{sendToAgent:f}=Vt(),h=e.outcome!=="running",[p,g]=v.useState(e.index);v.useEffect(()=>{g(e.index)},[e.index]);const b=e.workflow.steps[p]??e.workflow.steps[e.index],x=e.statuses[p]??"pending",_=e.outputs[p],k=e.outputs[p-1],C=b?.kind==="gate"&&x==="waiting",E=x==="failed"||x==="blocked",j=x==="blocked"&&b?.kind==="action"&&b.op==="assert-pr-branch";return n.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsxs("h2",{className:"flex items-center gap-1.5 text-[13px] font-semibold",children:[n.jsx(cs,{className:"size-4"})," ",e.workflow.name]}),n.jsxs("p",{className:"mt-0.5 flex items-center gap-1 text-[11px] text-muted-foreground",children:[n.jsx(ql,{className:"size-3"})," ",u("workflows.run.watchDock")]})]}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx(i4,{outcome:e.outcome}),n.jsxs(Q,{onClick:a,size:"sm",type:"button",variant:"outline",children:[n.jsx(Hu,{className:"size-3.5"})," ",u("workflows.run.workflows")]}),h?null:n.jsxs(Q,{onClick:i,size:"sm",type:"button",variant:"outline",children:[n.jsx($a,{className:"size-3.5"})," ",u("common.stop")]})]})]}),n.jsxs("div",{className:"grid min-h-0 flex-1 overflow-hidden lg:grid-cols-[minmax(240px,320px)_minmax(0,1fr)]",children:[n.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:n.jsx("ol",{className:"space-y-1",children:e.workflow.steps.map((N,A)=>{const T=e.statuses[A],D=T==="running"||T==="waiting",z=A===p;return n.jsx("li",{children:n.jsxs("button",{className:se("flex w-full items-center gap-2 rounded-md border px-2.5 py-2 text-left transition-colors",z?"border-primary/45 bg-primary/[0.06]":D?"border-primary/30 bg-primary/[0.03]":"border-transparent hover:border-border hover:bg-muted/40"),onClick:()=>g(A),type:"button",children:[n.jsx("span",{className:se("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":D?"border-primary/50":T==="done"?"border-emerald-500/50":"border-border"),children:n.jsx(mj,{status:T,kind:N.kind})}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate text-[12px] font-medium",children:Qf(N)}),n.jsxs("span",{className:"mt-0.5 flex items-center gap-1.5",children:[n.jsx(N0,{kind:N.kind}),n.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:u(fj[T])})]})]}),n.jsx(gn,{className:se("size-3.5 shrink-0 text-muted-foreground/50 transition-transform",z?"translate-x-0.5 text-primary":"")})]})},N.id)})})}),n.jsx("main",{className:"min-h-0 overflow-auto p-4",children:b?n.jsxs("section",{className:se("min-h-full rounded-lg border bg-background p-4 shadow-sm",x==="failed"?"border-destructive/40 bg-destructive/[0.03]":x==="blocked"?"border-amber-500/40 bg-amber-500/[0.04]":x==="running"||x==="waiting"?"border-primary/40 bg-primary/[0.03]":"border-border"),children:[n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-border pb-3",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(mj,{status:x,kind:b.kind}),n.jsx("h3",{className:"truncate text-[13px] font-semibold",children:Qf(b)})]}),n.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[n.jsx(N0,{kind:b.kind}),n.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:u(fj[x])})]})]}),n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[h&&E&&p===e.index&&!j?n.jsxs(Q,{"aria-label":u("workflows.run.resumeAria"),onClick:l,size:"sm",type:"button",children:[n.jsx(_r,{className:"size-3.5"})," ",u("workflows.run.resume")]}):null,E?n.jsxs(Q,{"aria-label":u("workflows.run.debugAria"),onClick:()=>f({prompt:DV({workflowName:e.workflow.name,step:b,status:x,error:e.error,previousOutput:k,output:_}),source:{type:"workflow-debug",label:b.title},mode:"send",label:u("workflows.run.debugLabel",{title:b.title}),background:!0}),size:"sm",type:"button",variant:"outline",children:[n.jsx(cs,{className:"size-3.5"})," ",u("workflows.run.debugWithAi")]}):null,h?null:n.jsxs(Q,{"aria-label":u("workflows.run.stopAria"),onClick:i,size:"sm",type:"button",variant:"outline",children:[n.jsx($a,{className:"size-3.5"})," ",u("workflows.run.stopAfter")]})]})]}),n.jsxs("div",{className:"py-3 text-[11px] leading-relaxed",children:[n.jsx(Vse,{output:_,previousOutput:k,status:x,step:b}),C?n.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-1.5",children:[n.jsxs(Q,{onClick:t,size:"sm",type:"button",children:[n.jsx(rn,{className:"size-3.5"})," ",u("workflows.run.approve")]}),n.jsxs(Q,{onClick:s,size:"sm",type:"button",variant:"outline",children:[n.jsx(Yj,{className:"size-3.5"})," ",u("workflows.run.skip")]}),n.jsxs(Q,{onClick:i,size:"sm",type:"button",variant:"outline",children:[n.jsx(Gt,{className:"size-3.5"})," ",u("common.stop")]})]}):null,x==="failed"&&e.error?n.jsx("p",{className:"mt-3 text-destructive",children:e.error}):null,j?n.jsx(Gse,{error:e.error,onRestart:c,workflowName:e.workflow.name}):null,x==="blocked"&&e.error?n.jsx("p",{className:"mt-3 text-amber-700 dark:text-amber-400",children:e.error}):null]})]}):null})]})]})}function Gse({error:e,onRestart:t,workflowName:s}){const i=X(),{provider:a}=Vt(),[l,c]=v.useState(""),[u,f]=v.useState(!1),[h,p]=v.useState(!1),[g,b]=v.useState(null),[x,_]=v.useState(null),k=v.useRef(null),C=$V(l);v.useEffect(()=>()=>k.current?.abort(),[]);async function E(N){k.current?.abort();const A=new AbortController;k.current=A,_(null),b(null),c(""),f(!0);try{const T=await w1({prompt:[LV({workflowName:s,error:e}),N?.trim()?N.trim():""].filter(Boolean).join(`
|
|
227
227
|
|
|
228
|
-
`),provider:a?.id,signal:A.signal});A.signal.aborted||c(T)}catch(T){A.signal.aborted||_(T instanceof Error?T.message:String(T))}finally{k.current===A&&(k.current=null,f(!1))}}async function j(){if(C){p(!0),_(null);try{await l9(C),b(C)}catch(N){_(N instanceof Error?N.message:String(N))}finally{p(!1)}}}return n.jsxs("div",{className:"mt-3 rounded-md border border-border bg-muted/35 p-3",children:[n.jsx(Yr,{children:i("workflows.recover.title")}),n.jsx("p",{className:"mb-2 text-[11px] text-muted-foreground",children:i("workflows.recover.desc")}),n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[n.jsxs(Q,{onClick:()=>{E()},size:"sm",type:"button",children:[n.jsx(cs,{className:"size-3.5"})," ",i("workflows.recover.recommend")]}),g?n.jsxs(Q,{onClick:t,size:"sm",type:"button",variant:"outline",children:[n.jsx(_r,{className:"size-3.5"})," ",i("workflows.recover.runAgain")]}):null]}),u?n.jsxs("p",{className:"mt-2 flex items-center gap-1 text-[11px] text-muted-foreground",children:[n.jsx(Bt,{className:"size-3 animate-spin"})," ",i("workflows.recover.choosing")]}):null,C?n.jsxs("div",{className:"mt-3 rounded-md border border-border bg-background p-2.5",children:[n.jsx(Yr,{children:i("workflows.recover.recommendedBranch")}),n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[n.jsx("code",{className:"min-w-0 rounded bg-muted px-2 py-1 font-mono text-[12px] text-foreground",children:C}),n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[n.jsxs(Q,{disabled:h||g===C,onClick:()=>{j()},size:"sm",type:"button",children:[h?n.jsx(Bt,{className:"size-3.5 animate-spin"}):n.jsx(rn,{className:"size-3.5"}),i("workflows.recover.createBranch")]}),n.jsxs(Q,{disabled:h,onClick:()=>{E("Recommend a different concise branch name. Keep the same output contract with `BRANCH_NAME: <branch-name>`.")},size:"sm",type:"button",variant:"outline",children:[n.jsx(cs,{className:"size-3.5"})," ",i("workflows.recover.askAnother")]})]})]})]}):l&&!u?n.jsxs("div",{className:"mt-3 rounded-md border border-border bg-background p-2.5",children:[n.jsx("p",{className:"text-[11px] text-muted-foreground",children:i("workflows.recover.noBranch")}),n.jsxs(Q,{className:"mt-2",onClick:()=>{E("Return only a concise branch suggestion using this exact line: `BRANCH_NAME: <branch-name>`.")},size:"sm",type:"button",variant:"outline",children:[n.jsx(cs,{className:"size-3.5"})," ",i("workflows.recover.askAnother")]})]}):null,g?n.jsxs("p",{className:"mt-2 text-[11px] text-emerald-700 dark:text-emerald-400",children:[i("workflows.recover.createdPre"),n.jsx("code",{className:"font-mono",children:g}),i("workflows.recover.createdPost")]}):null,x?n.jsx("p",{className:"mt-2 text-[11px] text-destructive",children:x}):null]})}const fj={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"},t4={gate:"workflows.kind.gate",agent:"workflows.kind.agent",action:"workflows.kind.action"};function Vse({output:e,previousOutput:t,status:s,step:i}){const a=X();if(i.kind==="gate"){const c=i.id==="gate-commit"?t?.trim():"";return n.jsxs("div",{children:[n.jsx("p",{className:"text-muted-foreground",children:i.message}),c?n.jsxs("div",{className:"mt-3",children:[n.jsx(Yr,{children:a("workflows.step.generatedCommitMessage")}),n.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(i.kind==="action")return n.jsx("p",{className:"text-muted-foreground",children:a(s4[i.op])});const l=s==="done"||s==="failed"||s==="skipped";return e?n.jsxs("div",{children:[n.jsx(Yr,{children:a("workflows.step.result")}),n.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})]}):n.jsxs("div",{children:[n.jsx(Yr,{children:a(l?"workflows.step.result":"workflows.step.task")}),l?n.jsx("p",{className:"italic text-muted-foreground",children:a("workflows.step.noReply")}):n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-muted-foreground",children:i.prompt}),s==="running"?n.jsxs("p",{className:"mt-1.5 flex items-center gap-1 text-muted-foreground/80",children:[n.jsx(Bt,{className:"size-3 animate-spin"})," ",a("workflows.step.working")]}):null]})]})}function Wse(e){return e.detected.name==="codex"?e.agents.codex:e.agents["claude-code"]??e}function Kse(e){return e?{skills:gu(e.skills.map(t=>t.name)),mcpServers:gu(e.mcpServers.map(t=>t.name)),plugins:gu(e.plugins.map(t=>t.name)),hooks:gu(e.hooks.map(t=>t.matcher?`${t.event}: ${t.matcher}`:t.event))}:{skills:[],mcpServers:[],plugins:[],hooks:[]}}function Yse(e){return{id:Z1("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 Xse(e){const t=Bl(e.id)||e.kind,s=e.title.trim()||Qf(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 i=n4(e.capabilities);return{...e,id:t,title:s,prompt:e.prompt.trim()||"Complete this workflow step.",capabilities:i}}const s4={"assert-pr-branch":"workflows.opDesc.assertPrBranch","checkout-default-and-pull":"workflows.opDesc.checkoutDefault",push:"workflows.opDesc.push",commit:"workflows.opDesc.commit"};function n4(e){if(!e)return;const t={};for(const s of["skills","mcpServers","plugins","hooks"]){const i=gu((e[s]??[]).map(a=>a.trim()).filter(Boolean));i.length&&(t[s]=i)}return Object.keys(t).length?t:void 0}function Zse(e,t,s){const i=e?.[t]??[],a=i.includes(s)?i.filter(l=>l!==s):[...i,s];return n4({...e??{},[t]:a})}function Z1(e,t){const s=new Set(t.map(l=>l.id));let i=Bl(e)||"workflow",a=2;for(;s.has(i);)i=`${Bl(e)||"workflow"}-${a}`,a++;return i}function Bl(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function gu(e){return Array.from(new Set(e.filter(Boolean)))}function Yr({children:e}){return n.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/70",children:e})}function C0(e){return new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"2-digit"}).format(new Date(e))}function i4({outcome:e}){const t=X(),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:i,className:a}=s[e];return n.jsx("span",{className:se("rounded-full border px-2 py-0.5 text-[10px] font-medium",a),children:t(i)})}function r4({kind:e}){return e==="gate"?n.jsx(Kj,{className:"size-4 text-amber-600 dark:text-amber-400"}):e==="agent"?n.jsx(Sn,{className:"size-4 text-primary"}):n.jsx(_r,{className:"size-4 text-muted-foreground"})}function mj({status:e,kind:t}){return e==="running"?n.jsx(Bt,{className:"size-4 shrink-0 animate-spin text-primary"}):e==="waiting"?n.jsx(Kj,{className:"size-4 shrink-0 text-primary"}):e==="done"?n.jsx(rn,{className:"size-4 shrink-0 text-emerald-600 dark:text-emerald-400"}):e==="blocked"?n.jsx(im,{className:"size-4 shrink-0 text-amber-600 dark:text-amber-400"}):e==="failed"?n.jsx(Zi,{className:"size-4 shrink-0 text-destructive"}):e==="skipped"?n.jsx(Yj,{className:"size-4 shrink-0 text-muted-foreground/60"}):t==="agent"?n.jsx(Sn,{className:"size-4 shrink-0 text-muted-foreground/50"}):n.jsx(rD,{className:"size-4 shrink-0 text-muted-foreground/50"})}function Qse(e){return n.jsx(gn,{className:"size-3 shrink-0 text-muted-foreground/40","aria-hidden":!0})}function N0({kind:e}){const t=X(),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 n.jsx("span",{className:se("shrink-0 rounded-full border px-1.5 py-px text-[9px] uppercase tracking-wide",s),children:t(t4[e])})}function Qf(e){return e.title}function Jse(){const[e,t]=v.useState(!1),[s,i]=v.useState(!1),[a,l]=v.useState(!0),[c,u]=v.useState("checking"),[f,h]=v.useState(null),[p,g]=v.useState(null);function b(){l(!0),u("checking"),h(null),b9().then(x=>{t(x.configured),i(x.deviceFlowAvailable),u(x.status),h(x.error??null),g(x)}).catch(x=>{t(!1),i(!1),u("connection_error"),h(x instanceof Error?x.message:String(x)),g(null)}).finally(()=>l(!1))}return v.useEffect(()=>{b()},[]),{configured:e,deviceFlowAvailable:s,loading:a,status:c,error:f,info:p,isConnected:c==="connected",needsLogin:c==="not_configured"||c==="auth_error",refresh:b}}const Xv=30;function ene(e="open"){const[t,s]=v.useState([]),[i,a]=v.useState(!0),[l,c]=v.useState(!1),[u,f]=v.useState(!1),[h,p]=v.useState(1),[g,b]=v.useState(null),[x,_]=v.useState(null),[k,C]=v.useState(null),[E,j]=v.useState(""),[N,A]=v.useState(!1),[T,D]=v.useState(null);v.useEffect(()=>{let $=!0;return a(!0),b(null),p(1),Qg(e,1).then(M=>{$&&(s(M),f(M.length===Xv),M.length>0&&!M.some(I=>I.number===x)&&_(M[0]?.number??null))}).catch(M=>{$&&b(M instanceof Error?M.message:String(M))}).finally(()=>{$&&a(!1)}),()=>{$=!1}},[e]),v.useEffect(()=>{if(!x){C(null);return}let $=!0;return S9(x).then(M=>{$&&C(M)}).catch(()=>{}),()=>{$=!1}},[x]),v.useEffect(()=>{if(!x){j("");return}let $=!0;return A(!0),D(null),k9(x).then(M=>{$&&j(M)}).catch(M=>{$&&D(M instanceof Error?M.message:String(M))}).finally(()=>{$&&A(!1)}),()=>{$=!1}},[x]);function z(){if(l||!u)return;const $=h+1;c(!0),Qg(e,$).then(M=>{s(I=>{const G=new Set(I.map(B=>B.number));return[...I,...M.filter(B=>!G.has(B.number))]}),f(M.length===Xv),p($)}).catch(M=>b(M instanceof Error?M.message:String(M))).finally(()=>c(!1))}function O(){let $=!0;return a(!0),b(null),p(1),Qg(e,1).then(M=>{$&&(s(M),f(M.length===Xv))}).catch(M=>{$&&b(M instanceof Error?M.message:String(M))}).finally(()=>{$&&a(!1)}),()=>{$=!1}}return{prs:t,loading:i,loadingMore:l,hasMore:u,error:g,selectedNumber:x,setSelectedNumber:_,selectedPR:k,diff:E,diffLoading:N,diffError:T,loadMore:z,refresh:O}}const Zv=30;function tne(e="open"){const[t,s]=v.useState([]),[i,a]=v.useState(!0),[l,c]=v.useState(!1),[u,f]=v.useState(!1),[h,p]=v.useState(1),[g,b]=v.useState(null),[x,_]=v.useState(null),[k,C]=v.useState(null),[E,j]=v.useState([]),[N,A]=v.useState(!1),[T,D]=v.useState(null),[z,O]=v.useState(!1);v.useEffect(()=>{let G=!0;return a(!0),b(null),p(1),Jg(e,1).then(B=>{G&&(s(B),f(B.length===Zv),B.length>0&&!B.some(U=>U.number===x)&&_(B[0]?.number??null))}).catch(B=>{G&&b(B instanceof Error?B.message:String(B))}).finally(()=>{G&&a(!1)}),()=>{G=!1}},[e]),v.useEffect(()=>{if(!x){C(null),j([]);return}let G=!0;return A(!0),Promise.all([A9(x),T9(x)]).then(([B,U])=>{G&&(C(B),j(U))}).catch(()=>{}).finally(()=>{G&&A(!1)}),()=>{G=!1}},[x]);async function $(G){if(x){O(!0),D(null);try{const B=await R9(x,G);j(U=>[...U,B])}catch(B){D(B instanceof Error?B.message:String(B))}finally{O(!1)}}}function M(){if(l||!u)return;const G=h+1;c(!0),Jg(e,G).then(B=>{s(U=>{const Y=new Set(U.map(P=>P.number));return[...U,...B.filter(P=>!Y.has(P.number))]}),f(B.length===Zv),p(G)}).catch(B=>b(B instanceof Error?B.message:String(B))).finally(()=>c(!1))}function I(){let G=!0;return a(!0),p(1),Jg(e,1).then(B=>{G&&(s(B),f(B.length===Zv))}).catch(()=>{}).finally(()=>{G&&a(!1)}),()=>{G=!1}}return{issues:t,loading:i,loadingMore:l,hasMore:u,error:g,selectedNumber:x,setSelectedNumber:_,selectedIssue:k,comments:E,commentsLoading:N,commentError:T,submitting:z,addComment:$,loadMore:M,refresh:I}}function a4({deviceFlowAvailable:e,initialMode:t,onSaved:s}){const i=X(),[a,l]=v.useState(()=>t==="device-pending"&&!e?"pat":t??(e?"choose":"pat"));return a==="device-pending"?n.jsx(sne,{onSuccess:s,onCancel:()=>l("choose")}):a==="pat"?n.jsx(nne,{onSaved:s,onBack:e?()=>l("choose"):void 0}):n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[n.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[n.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-muted",children:n.jsx($S,{className:"size-6 text-muted-foreground"})}),n.jsxs("div",{children:[n.jsx("h2",{className:"text-base font-semibold",children:i("github.setup.connectTitle")}),n.jsx("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:i("github.setup.connectDesc")})]})]}),n.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-2",children:[n.jsxs(Q,{className:"w-full",onClick:()=>l("device-pending"),type:"button",children:[n.jsx($S,{className:"mr-2 size-4"}),i("github.setup.authorizeWith")]}),n.jsx("button",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",onClick:()=>l("pat"),type:"button",children:i("github.setup.usePat")})]})]})}function sne({onSuccess:e,onCancel:t}){const s=X(),[i,a]=v.useState(null),[l,c]=v.useState(null),[u,f]=v.useState(!0),[h,p]=v.useState(!1),g=v.useRef(null),b=v.useRef(5),x=v.useRef(!1);v.useEffect(()=>{let E=!0;return v9().then(j=>{if(!E)return;a(j),b.current=j.interval,f(!1);const N=j.verification_uri_complete||j.verification_uri;N&&pm(N),_(j.device_code,j.interval),setTimeout(()=>{x.current=!0},j.expires_in*1e3)}).catch(j=>{E&&(c(j instanceof Error?j.message:String(j)),f(!1))}),()=>{E=!1,g.current&&clearTimeout(g.current)}},[]);function _(E,j){g.current=setTimeout(()=>{k(E,j)},j*1e3)}async function k(E,j){if(x.current){c(s("github.setup.expired"));return}try{const N=await x9(E);if(N.done){e();return}const A=N.slowDown?j+5:j;b.current=A,_(E,A)}catch{_(E,b.current)}}function C(){i&&navigator.clipboard.writeText(i.user_code).then(()=>{p(!0),setTimeout(()=>p(!1),2e3)})}return u?n.jsx("div",{className:"flex h-full items-center justify-center",children:n.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[n.jsx(FS,{className:"size-6 animate-spin text-muted-foreground"}),n.jsx("p",{className:"text-[13px] text-muted-foreground",children:s("github.setup.requesting")})]})}):l?n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-4 p-8",children:[n.jsx(nt,{variant:"destructive",children:l}),n.jsx(Q,{onClick:t,variant:"outline",children:s("github.setup.goBack")})]}):n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[n.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[n.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-emerald-100 dark:bg-emerald-500/15",children:n.jsx(rm,{className:"size-6 text-emerald-600 dark:text-emerald-400"})}),n.jsxs("div",{children:[n.jsx("h2",{className:"text-base font-semibold",children:s("github.setup.authorizeOnTitle")}),n.jsxs("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:[s("github.setup.enterCodePre"),n.jsx("strong",{children:s("github.setup.authorizeWord")}),s("github.setup.enterCodePost")]})]})]}),n.jsxs("div",{className:"flex flex-col items-center gap-2",children:[n.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:i?.user_code}),n.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")})]}),n.jsxs("div",{className:"flex flex-col items-center gap-2",children:[n.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-muted-foreground",children:[n.jsx(FS,{className:"size-3.5 animate-spin"}),s("github.setup.waiting")]}),n.jsx("a",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",href:i?.verification_uri_complete||i?.verification_uri,rel:"noopener noreferrer",target:"_blank",children:s("github.setup.openAgain")}),n.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 nne({onSaved:e,onBack:t}){const s=X(),[i,a]=v.useState(""),[l,c]=v.useState(!1),[u,f]=v.useState(null);async function h(p){p.preventDefault();const g=i.trim();if(g){c(!0),f(null);try{await y9("github.com",g),e()}catch(b){f(b instanceof Error?b.message:String(b))}finally{c(!1)}}}return n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[n.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[n.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-muted",children:n.jsx($j,{className:"size-6 text-muted-foreground"})}),n.jsxs("div",{children:[n.jsx("h2",{className:"text-base font-semibold",children:s("github.setup.patTitle")}),n.jsxs("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:[s("github.setup.patDescPre"),n.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"),n.jsx("code",{className:"rounded bg-muted px-1 py-px text-[11px]",children:"repo"}),s("github.setup.patDescAnd"),n.jsx("code",{className:"rounded bg-muted px-1 py-px text-[11px]",children:"workflow"}),s("github.setup.patDescPost")]})]})]}),n.jsxs("form",{className:"flex w-full max-w-sm flex-col gap-3",onSubmit:p=>{h(p)},children:[n.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:p=>a(p.target.value),placeholder:"ghp_...",spellCheck:!1,type:"password",value:i}),u?n.jsx(nt,{variant:"destructive",children:u}):null,n.jsx(Q,{disabled:!i.trim()||l,type:"submit",children:s(l?"common.saving":"github.setup.saveToken")}),t?n.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 Q1({hasMore:e,loading:t,onLoadMore:s}){const i=X();return e?n.jsx("div",{className:"p-2",children:n.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?n.jsx(Bt,{className:"size-3 animate-spin"}):null,i(t?"common.loading":"github.loadMore")]})}):null}function ine({prs:e,loading:t,loadingMore:s,hasMore:i,error:a,selectedNumber:l,onSelect:c,onLoadMore:u}){const f=X();return t&&e.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.prs.loading")}):a?n.jsx("div",{className:"p-4 text-[12px] text-red-500",children:a}):e.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.prs.empty")}):n.jsxs(n.Fragment,{children:[n.jsx("ul",{className:"divide-y divide-border",children:e.map(h=>n.jsx("li",{children:n.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:[n.jsx("span",{className:"mt-0.5 shrink-0",children:n.jsx(rne,{pr:h})}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate text-[13px] font-medium",children:h.title}),n.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",h.number," · ",h.base.ref," ← ",h.head.ref," · ",h.user.login]})]}),h.draft?n.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))}),n.jsx(Q1,{hasMore:i,loading:s,onLoadMore:u})]})}function rne({pr:e}){return e.state==="merged"?n.jsx(xf,{className:"size-4 text-purple-500"}):e.state==="closed"?n.jsx(t8,{className:"size-4 text-red-500"}):n.jsx(Hj,{className:"size-4 text-emerald-500"})}function o4({body:e,title:t}){const s=X(),i=t??s("github.md.description"),[a,l]=v.useState("rendered"),c=u=>se("rounded px-1.5 py-0.5 text-[10px] font-medium transition-colors",u?"bg-foreground text-background":"text-muted-foreground hover:text-foreground");return n.jsxs("section",{className:"overflow-hidden rounded-md border border-border bg-muted/25",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[n.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:i}),n.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-background/60 p-0.5",children:[n.jsx("button",{className:c(a==="rendered"),onClick:()=>l("rendered"),type:"button",children:s("github.md.rendered")}),n.jsx("button",{className:c(a==="raw"),onClick:()=>l("raw"),type:"button",children:s("github.md.raw")})]})]}),a==="rendered"?n.jsx(K1,{content:e}):n.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap px-3 py-3 font-mono text-[12px]",children:e})]})}function ane({pr:e,diff:t,diffLoading:s,diffError:i,onMerged:a}){const l=X(),[c,u]=v.useState("cockpit"),[f,h]=v.useState(null),[p,g]=v.useState(!1),[b,x]=v.useState(null),[_,k]=v.useState(null),[C,E]=v.useState(!1),[j,N]=v.useState(null),[A,T]=v.useState(!1),{sendToAgent:D}=Vt(),{isPending:z,runOperation:O}=Yn(),$=e?`github:pr:${e.number}:merge`:"",M=$?z($):!1,I=v.useMemo(()=>nq(t),[t]);v.useEffect(()=>{N(W=>W&&I.some(re=>re.path===W)?W:I[0]?.path??null)},[I]);const G=I.find(W=>W.path===j)??I[0]??null;function B(W){N(W),u("diff")}function U(W,re){e&&(T(!1),D({prompt:re?Iq(e,re,W):Bq(e,W),source:{type:"github-pr",label:`PR #${e.number}${re?` · ${Jf(re)}`:""}`},label:`PR #${e.number}${re?` (${Jf(re)})`:""}: ${W}`}))}if(v.useEffect(()=>{if(T(!1),!e){h(null);return}let W=!0;return g(!0),x(null),C9(e.number).then(re=>{W&&h(re)}).catch(re=>{W&&x(re instanceof Error?re.message:String(re))}).finally(()=>{W&&g(!1)}),()=>{W=!1}},[e]),!e)return n.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:l("github.pr.selectPrompt")});const Y=e.state==="open"&&!e.draft;async function P(){if(!(!e||M)){k(null);try{await O({errorMessage:W=>W instanceof Error?W.message:String(W),key:$,label:l("github.pr.mergingOperation",{number:e.number})},()=>j9(e.number,{method:"squash"})),E(!1),a?.()}catch(W){k(W instanceof Error?W.message:String(W)),E(!1)}}}const V=W=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${W?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`;return n.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[n.jsxs("div",{className:"group flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-semibold",children:e.title}),n.jsx(xr,{className:se("shrink-0",A&&"opacity-100"),label:l("github.pr.askLabel",{number:e.number}),onAsk:()=>T(W=>!W)}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[n.jsx("button",{className:V(c==="cockpit"),onClick:()=>u("cockpit"),type:"button",children:l("github.pr.tabReview")}),n.jsx("button",{className:V(c==="diff"),onClick:()=>u("diff"),type:"button",children:l("github.pr.tabDiff")})]}),Y?n.jsxs(Q,{className:"shrink-0",loading:M,loadingLabel:l("github.pr.merging"),onClick:()=>E(!0),size:"sm",title:l("github.pr.squashTitle"),type:"button",variant:"success",children:[n.jsx(xf,{}),l("github.pr.squashMerge")]}):null,n.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:n.jsx(Xr,{className:"size-3.5"})})]}),_?n.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,A?n.jsx("div",{className:"shrink-0 border-b border-border px-3 py-1.5",children:n.jsx(Qr,{placeholder:l("github.pr.askPlaceholder"),onSubmit:W=>U(W),onCancel:()=>T(!1)})}):null,c==="cockpit"?n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:n.jsx(one,{cockpit:f,error:b,loading:p,onOpenFile:B,pr:e})}):s?n.jsx(vm,{className:"flex-1",label:l("git.diff.loading")}):i?n.jsx("div",{className:"p-4 text-[12px] text-red-500",children:i}):I.length?n.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1",children:[n.jsx(lne,{files:I,onAsk:(W,re)=>U(re,W),onSelect:N,selected:G?.path??null}),n.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:G?n.jsx(Yu,{diff:G.diff}):null})]}):n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:l("github.pr.noDiff")}),C?n.jsx(Xl,{confirmLabel:M?n.jsxs(n.Fragment,{children:[n.jsx(bm,{size:"sm"})," ",l("github.pr.merging")]}):l("github.pr.squashMerge"),icon:n.jsx(xf,{}),loading:M,message:n.jsxs(n.Fragment,{children:[l("github.pr.confirmPre"),n.jsxs("span",{className:"font-mono",children:["#",e.number]})," ",n.jsx("span",{className:"font-medium text-foreground",children:e.title}),l("github.pr.confirmInto"),n.jsx("span",{className:"font-mono",children:e.base.ref}),l("github.pr.confirmQ")]}),onCancel:()=>E(!1),onConfirm:()=>{P()},title:l("github.pr.squashMerge"),tone:"success"}):null]})}function one({pr:e,cockpit:t,loading:s,error:i,onOpenFile:a}){const l=X(),[c,u]=v.useState(!1),f=t?.pr??e,h=t?.files??[],p=t?.reviews??[],g=t?.comments??[],b=t?.checks??null,x=b?.runs.filter(_=>_.conclusion==="failure"||_.conclusion==="timed_out"||_.conclusion==="cancelled")??[];return n.jsxs("div",{className:"space-y-3 p-4",children:[n.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 text-[12px]",children:[n.jsx(dne,{pr:f}),n.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:[n.jsx(Mn,{className:"size-3 shrink-0 text-muted-foreground"}),f.base.ref,n.jsx(Hu,{className:"size-3 shrink-0 text-muted-foreground"}),f.head.ref]}),n.jsxs("span",{className:"inline-flex items-center gap-1 text-muted-foreground",children:[n.jsx(nO,{className:"size-3 shrink-0"}),f.user.login]}),n.jsxs("span",{className:"inline-flex items-center gap-1 text-muted-foreground",children:[n.jsx(Y6,{className:"size-3 shrink-0"}),new Date(f.created_at).toLocaleDateString()]})]}),i?n.jsx("div",{className:"rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-[12px] text-red-500",children:i}):null,s?n.jsx(vm,{className:"justify-start",label:l("github.pr.loadingCockpit")}):null,n.jsxs("div",{className:"grid gap-2 md:grid-cols-4",children:[n.jsx(Yh,{title:l("github.pr.mergeReadiness"),value:l(l4(f,b)),tone:cne(f,b)}),n.jsx(Yh,{title:l("github.pr.reviewStateTitle"),value:l(c4(p)),tone:une(p)}),n.jsx(Yh,{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"}),n.jsx(Yh,{title:l("github.pr.changedFiles"),value:String(h.length),tone:"muted"})]}),x.length>0?n.jsxs("section",{className:"rounded-md border border-red-500/25 bg-red-500/10 px-3 py-2",children:[n.jsx("div",{className:"mb-1 text-[11px] font-medium text-red-500",children:l("github.pr.failingChecks")}),n.jsx("div",{className:"flex flex-wrap gap-2",children:x.slice(0,4).map(_=>n.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:[n.jsx(A0,{className:"size-3"}),l("github.pr.openFailingCheck",{name:_.name})]},_.id))})]}):null,n.jsxs("section",{className:"rounded-md border border-border bg-muted/25 p-3",children:[n.jsxs("button",{className:"flex w-full items-center gap-2 text-[12px] font-medium",onClick:()=>u(_=>!_),type:"button",children:[c?n.jsx(kn,{className:"size-3.5 text-muted-foreground"}):n.jsx(gn,{className:"size-3.5 text-muted-foreground"}),n.jsx(T0,{className:"size-3.5 text-muted-foreground"}),l("github.pr.changedFiles"),h.length?n.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:["(",h.length,")"]}):null]}),c?h.length?n.jsx("ul",{className:"mt-2 divide-y divide-border",children:h.slice(0,12).map(_=>n.jsx("li",{children:n.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:[n.jsx("span",{className:"w-16 shrink-0 font-mono text-[10px] uppercase text-muted-foreground",children:_.status}),n.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:_.path}),n.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-emerald-600",children:["+",_.additions]}),n.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-red-500",children:["-",_.deletions]})]})},_.path))}):n.jsx("p",{className:"mt-2 text-[12px] text-muted-foreground",children:l("github.pr.noFileMeta")}):null]}),n.jsxs("section",{className:"rounded-md border border-border bg-muted/25 p-3",children:[n.jsxs("div",{className:"mb-2 flex items-center gap-2 text-[12px] font-medium",children:[n.jsx(V8,{className:"size-3.5 text-muted-foreground"}),l("github.pr.reviewStateTitle")]}),p.length||g.length?n.jsxs("div",{className:"space-y-2",children:[p.slice(-4).map(_=>n.jsx(pj,{href:_.html_url,meta:`${_.user.login} - ${_.state.toLowerCase()}`,text:_.body||l("github.pr.noReviewSummary")},`review:${_.id}`)),g.slice(-4).map(_=>n.jsx(pj,{href:_.html_url,meta:l("github.pr.reviewMetaComment",{login:_.user.login}),text:_.body},`comment:${_.id}`))]}):n.jsx("p",{className:"text-[12px] text-muted-foreground",children:l("github.pr.noReviews")})]}),f.body?n.jsx(o4,{body:f.body}):n.jsx("p",{className:"text-[12px] italic text-muted-foreground",children:l("github.noDescription")})]})}function lne({files:e,selected:t,onSelect:s,onAsk:i}){const a=X(),[l,c]=v.useState(null);return n.jsx("div",{className:"w-44 shrink-0 overflow-y-auto border-r border-border bg-card/60",children:n.jsx("ul",{className:"py-1",children:e.map(u=>n.jsxs("li",{className:"group flex flex-col",children:[n.jsxs("div",{className:se("flex items-center transition-colors",u.path===t?"bg-muted":"hover:bg-muted/60"),children:[n.jsxs("button",{className:se("flex min-w-0 flex-1 items-center gap-1.5 px-2.5 py-1.5 text-left text-[11px]",u.path===t?"text-foreground":"text-muted-foreground group-hover:text-foreground"),onClick:()=>s(u.path),title:u.path,type:"button",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:Jf(u.path)}),n.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-emerald-600",children:["+",u.additions]}),n.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-red-500",children:["-",u.deletions]})]}),n.jsx(xr,{className:se("mr-1 shrink-0",l===u.path&&"opacity-100"),label:a("github.pr.askFileLabel",{name:Jf(u.path)}),onAsk:()=>c(f=>f===u.path?null:u.path)})]}),l===u.path?n.jsx("div",{className:"px-2 pb-1.5 pt-0.5",children:n.jsx(Qr,{placeholder:a("github.pr.askFilePlaceholder"),onSubmit:f=>{c(null),i(u.path,f)},onCancel:()=>c(null)})}):null]},u.path))})})}function Jf(e){const t=e.split("/");return t[t.length-1]||e}function Yh({title:e,value:t,tone:s}){const i=s==="success"?"bg-emerald-500":s==="warning"?"bg-amber-500":s==="danger"?"bg-red-500":"bg-muted-foreground";return n.jsxs("div",{className:"rounded-md border border-border bg-card px-3 py-2",children:[n.jsx("div",{className:"text-[10px] uppercase text-muted-foreground",children:e}),n.jsxs("div",{className:"mt-1 flex items-center gap-1.5 text-[12px] font-medium",children:[n.jsx("span",{className:`size-1.5 rounded-full ${i}`}),t]})]})}function pj({meta:e,text:t,href:s}){return n.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:[n.jsxs("span",{className:"mb-1 flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[n.jsx(Xr,{className:"size-3"}),e]}),n.jsx("span",{className:"line-clamp-2 whitespace-pre-wrap",children:t})]})}function l4(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 cne(e,t){const s=l4(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 c4(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 une(e){const t=c4(e);return t==="github.pr.review.approved"?"success":t==="github.pr.review.changesRequested"?"danger":t==="github.pr.review.commented"?"warning":"muted"}function dne({pr:e}){const t=X(),{labelKey:s,dot:i,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 n.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground",children:[n.jsx("span",{className:`size-1.5 rounded-full ${i}`}),a==="merged"?n.jsx(xf,{className:"size-3"}):a==="open"?n.jsx(rm,{className:"size-3"}):n.jsx(Lo,{className:"size-3"}),t(s)]})}function u4({label:e}){return n.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 text-[10px] font-medium text-muted-foreground",title:e.name,children:[n.jsx("span",{className:"size-2 shrink-0 rounded-sm",style:{backgroundColor:`#${e.color}`}}),n.jsx("span",{className:"truncate",children:e.name})]})}function hne({issues:e,loading:t,loadingMore:s,hasMore:i,error:a,selectedNumber:l,onSelect:c,onLoadMore:u}){const f=X();return t&&e.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.issues.loading")}):a?n.jsx("div",{className:"p-4 text-[12px] text-red-500",children:a}):e.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.issues.empty")}):n.jsxs(n.Fragment,{children:[n.jsx("ul",{className:"divide-y divide-border",children:e.map(h=>n.jsx("li",{children:n.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:[n.jsx(oD,{className:`mt-0.5 size-4 shrink-0 ${h.state==="open"?"text-emerald-500":"text-red-500"}`}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate text-[13px] font-medium",children:h.title}),n.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?n.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(p=>n.jsx(u4,{label:p},p.name))}):null]})},h.number))}),n.jsx(Q1,{hasMore:i,loading:s,onLoadMore:u})]})}const Xh=6,fne=6,mne=8;function pne(e,t,s,i){const a=Math.max(0,Math.min(fne,e/2,t/2)),l=Math.max(0,Math.min(mne,s-a,i-a));return[`M ${a} 0`,`H ${e-a}`,`A ${a} ${a} 0 0 1 ${e} ${a}`,`V ${t-i-a}`,`A ${a} ${a} 0 0 1 ${e-a} ${t-i}`,`H ${e-s+l}`,`A ${l} ${l} 0 0 0 ${e-s} ${t-i+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 gne({value:e,onChange:t,placeholder:s,rows:i=3,action:a}){const l=X(),c=v.useRef(null),u=v.useRef(null),[f,h]=v.useState(null),[p,g]=v.useState({w:0,h:0});v.useLayoutEffect(()=>{const x=c.current,_=u.current;if(!x||!_)return;const k=()=>{h({w:x.clientWidth,h:x.clientHeight}),g({w:_.offsetWidth+Xh*2,h:_.offsetHeight+Xh*2})};k();const C=new ResizeObserver(k);return C.observe(x),C.observe(_),()=>C.disconnect()},[]);const b=f&&p.w&&p.h?pne(f.w,f.h,p.w,p.h):null;return n.jsxs("div",{className:"relative",ref:c,children:[n.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:x=>t(x.target.value),placeholder:s,rows:i,style:{clipPath:b?`path('${b}')`:void 0,paddingBottom:p.h||44},value:e}),f&&b?n.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:[n.jsx("title",{children:l("github.commentBorderTitle")}),n.jsx("path",{d:b,stroke:"currentColor",strokeWidth:1})]}):null,n.jsx("div",{className:"absolute",ref:u,style:{bottom:Xh,right:Xh},children:a})]})}function bne({issue:e,comments:t,commentsLoading:s,commentError:i,submitting:a,onAddComment:l}){const c=X(),[u,f]=v.useState(""),[h,p]=v.useState(!1),{sendToAgent:g}=Vt(),{isPending:b,runOperation:x}=Yn(),_=e?`github:issue:${e.number}:comment`:"",k=a||(_?b(_):!1);v.useEffect(()=>{p(!1)},[e?.number]);function C(j){e&&(p(!1),g({prompt:Hq(e,j),source:{type:"github-issue",label:`Issue #${e.number}`},label:`Issue #${e.number}: ${j}`}))}if(!e)return n.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:c("github.issue.selectPrompt")});async function E(j){if(j.preventDefault(),!e)return;const N=u.trim();N&&(await x({key:_,label:c("github.issue.postingOperation",{number:e.number})},()=>l(N)),f(""))}return n.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[n.jsxs("div",{className:"group flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-semibold",children:e.title}),n.jsx(xr,{className:se("shrink-0",h&&"opacity-100"),label:c("github.issue.askLabel",{number:e.number}),onAsk:()=>p(j=>!j)}),n.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:n.jsx(Xr,{className:"size-3.5"})})]}),h?n.jsx("div",{className:"shrink-0 border-b border-border px-3 py-1.5",children:n.jsx(Qr,{placeholder:c("github.issue.askPlaceholder"),onSubmit:C,onCancel:()=>p(!1)})}):null,n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:n.jsxs("div",{className:"space-y-3 p-4",children:[n.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[12px]",children:[n.jsxs("span",{className:"text-[11px]",children:[n.jsx("span",{className:"text-muted-foreground",children:c("github.issue.author")}),n.jsx("span",{className:"font-medium",children:e.user.login})]}),n.jsxs("span",{className:"text-[11px]",children:[n.jsx("span",{className:"text-muted-foreground",children:c("github.issue.opened")}),n.jsx("span",{className:"font-medium",children:new Date(e.created_at).toLocaleDateString()})]}),e.labels.map(j=>n.jsx(u4,{label:j},j.name))]}),e.body?n.jsx(o4,{body:e.body}):n.jsx("p",{className:"text-[12px] text-muted-foreground italic",children:c("github.noDescription")}),s?n.jsx(vm,{className:"justify-start",label:c("github.issue.loadingComments")}):n.jsx("div",{className:"space-y-2",children:t.map(j=>n.jsxs("div",{className:"rounded-md border border-border bg-muted/20 p-3",children:[n.jsxs("div",{className:"mb-1 flex items-baseline gap-2",children:[n.jsx("span",{className:"text-[11px] font-semibold",children:j.user.login}),n.jsx("span",{className:"text-[10px] text-muted-foreground",children:new Date(j.created_at).toLocaleDateString()})]}),n.jsx(K1,{content:j.body})]},j.id))})]})}),n.jsx("div",{className:"shrink-0 border-t border-border p-3",children:n.jsxs("form",{className:"flex flex-col gap-2",onSubmit:j=>{E(j)},children:[n.jsx(gne,{action:n.jsx(Q,{disabled:!u.trim(),loading:k,loadingLabel:c("github.issue.posting"),size:"sm",type:"submit",children:c("github.issue.comment")}),onChange:f,placeholder:c("github.issue.addComment"),value:u}),i?n.jsx(nt,{variant:"destructive",children:i}):null]})})]})}const gj=30,vne=4e3;function xne(e){return e.status==="in_progress"||e.status==="queued"}function bj(e){return e.map(t=>`${t.id}:${t.status}:${t.conclusion}`).join("|")}function vj(e){return e.map(t=>`${t.id}:${t.status}:${t.conclusion}:`+t.steps.map(s=>`${s.number}:${s.status}:${s.conclusion}`).join(",")).join("|")}function yne(e,t){if(e.length===0)return t;const s=new Map(t.map(c=>[c.id,c])),i=new Set(e.map(c=>c.id)),a=t.filter(c=>!i.has(c.id)),l=e.map(c=>s.get(c.id)??c);return[...a,...l]}function _ne(e){const[t,s]=v.useState([]),[i,a]=v.useState(null),[l,c]=v.useState([]),[u,f]=v.useState(!0),[h,p]=v.useState(!1),[g,b]=v.useState(!1),[x,_]=v.useState(1),[k,C]=v.useState(!1),[E,j]=v.useState(null),[N,A]=v.useState(null);function T(){let $=!0;return f(!0),j(null),_(1),Qh(e,1).then(M=>{$&&(s(M),b(M.length===gj))}).catch(M=>{$&&j(M instanceof Error?M.message:String(M))}).finally(()=>{$&&f(!1)}),()=>{$=!1}}function D(){if(h||!g)return;const $=x+1;p(!0),Qh(e,$).then(M=>{s(I=>{const G=new Set(I.map(B=>B.id));return[...I,...M.filter(B=>!G.has(B.id))]}),b(M.length===gj),_($)}).catch(M=>j(M instanceof Error?M.message:String(M))).finally(()=>p(!1))}const z=v.useCallback(()=>{Qh(e,1).then($=>s(M=>{const I=yne(M,$);return bj(M)===bj(I)?M:I})).catch(()=>{}),i&&nk(i).then($=>c(M=>vj(M)===vj($)?M:$)).catch(()=>{})},[e,i]);v.useEffect(T,[e]),v.useEffect(()=>{a($=>$&&t.some(M=>M.id===$)?$:t[0]?.id??null)},[t]),v.useEffect(()=>{if(!i){c([]);return}let $=!0;return C(!0),A(null),nk(i).then(M=>{$&&c(M)}).catch(M=>{$&&A(M instanceof Error?M.message:String(M))}).finally(()=>{$&&C(!1)}),()=>{$=!1}},[i]);const O=t.some(xne);return v.useEffect(()=>{if(!O)return;const $=window.setInterval(()=>{document.visibilityState==="visible"&&z()},vne);return()=>window.clearInterval($)},[O,z]),{runs:t,selectedRunId:i,jobs:l,loading:u,loadingMore:h,hasMore:g,jobsLoading:k,error:E,jobsError:N,loadMore:D,refresh:T,syncLatest:z,setSelectedRunId:a}}function d4(e){return e.conclusion==="failure"||e.conclusion==="timed_out"||e.conclusion==="cancelled"}function wne({branch:e,onClearBranch:t}){const{runs:s,selectedRunId:i,jobs:a,loading:l,loadingMore:c,hasMore:u,jobsLoading:f,error:h,jobsError:p,loadMore:g,refresh:b,syncLatest:x,setSelectedRunId:_}=_ne(e),k=X();$o(x);const C=s.find(T=>T.id===i)??null,{sendToAgent:E}=Vt(),[j,N]=v.useState(null);function A(T,D){N(null),E({prompt:$q(T,D),source:{type:"github-run",label:k("github.actions.runLabel",{number:T.run_number})},label:k("github.actions.runInputLabel",{number:T.run_number,input:D??k("github.actions.fixDefault")})})}return n.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[n.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("h2",{className:"text-[13px] font-semibold",children:k("github.actions.title")}),e?n.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:[n.jsx("span",{className:"shrink-0",children:k("github.actions.filteredTo")}),n.jsx("span",{className:"min-w-0 truncate font-mono",children:e}),t?n.jsx("button",{"aria-label":k("github.actions.clearFilter"),className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:t,title:k("github.actions.clearFilter"),type:"button",children:n.jsx(Gt,{className:"size-3"})}):null]}):null]}),n.jsxs(Q,{disabled:l,onClick:()=>{b()},size:"sm",type:"button",variant:"outline",children:[n.jsx(Mi,{className:`mr-1 size-3.5 ${l?"animate-spin":""}`}),k("common.refresh")]})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:h?n.jsx("div",{className:"p-4 text-[12px] text-red-500",children:h}):l&&s.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:k("github.actions.loadingRuns")}):s.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:k("github.actions.noRuns")}):n.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(280px,380px)_minmax(0,1fr)] divide-x divide-border",children:[n.jsxs("div",{className:"min-h-0 overflow-auto",children:[n.jsx("ul",{className:"divide-y divide-border",children:s.map(T=>n.jsxs("li",{className:"group flex flex-col",children:[n.jsxs("div",{className:`flex items-center transition-colors hover:bg-muted/60 ${T.id===i?"bg-muted/70":""}`,children:[n.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:[n.jsx(Sne,{run:T}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate text-[13px] font-medium",children:T.name}),n.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",T.run_number," · ",T.head_branch," · ",T.event," ·"," ",n.jsx("span",{title:new Date(T.created_at).toLocaleString(),children:z3(T.created_at)})]})]}),n.jsx(kne,{run:T})]}),d4(T)?n.jsx(xr,{className:`mr-2 shrink-0 ${j===T.id?"opacity-100":""}`,label:k("github.actions.fixRunAi",{number:T.run_number}),onAsk:()=>N(D=>D===T.id?null:T.id)}):null]}),j===T.id?n.jsx("div",{className:"px-3 pb-2 pt-0.5",children:n.jsx(Qr,{onCancel:()=>N(null),onSubmit:D=>A(T,D),placeholder:k("github.actions.askPlaceholder")})}):null]},T.id))}),n.jsx(Q1,{hasMore:u,loading:c,onLoadMore:g})]}),n.jsx(Cne,{error:p,jobs:a,loading:f,onFix:T=>A(T),run:C})]})})]})}function Sne({run:e}){return e.status==="in_progress"||e.status==="queued"?n.jsx(Lo,{className:"size-4 shrink-0 animate-pulse text-amber-400"}):e.conclusion==="success"?n.jsx(rm,{className:"size-4 shrink-0 text-emerald-500"}):e.conclusion==="failure"||e.conclusion==="timed_out"?n.jsx(A0,{className:"size-4 shrink-0 text-red-500"}):n.jsx(Lo,{className:"size-4 shrink-0 text-zinc-400"})}function kne({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 n.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[n.jsx("span",{className:`size-1.5 rounded-full ${s}`}),t]})}function Cne({run:e,jobs:t,loading:s,error:i,onFix:a}){const l=X();return e?n.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[n.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate text-[13px] font-semibold",children:e.name}),n.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["Run #",e.run_number," · ",e.head_branch," · ",e.head_sha.slice(0,7)]})]}),d4(e)?n.jsxs(Q,{className:"shrink-0 gap-1",onClick:()=>a(e),size:"sm",title:l("github.actions.fixTitle"),type:"button",variant:"outline",children:[n.jsx(cs,{className:"size-3.5"}),l("github.actions.fixWithAi")]}):null,n.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:n.jsx(Xr,{className:"size-3.5"})})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:i?n.jsx("div",{className:"p-4 text-[12px] text-red-500",children:i}):s?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:l("github.actions.loadingJobs")}):t.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:l("github.actions.noJobs")}):n.jsx("ul",{className:"divide-y divide-border",children:t.map(c=>n.jsxs("li",{className:"px-3 py-3",children:[n.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[n.jsx(xj,{item:c}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-medium",children:c.name}),n.jsx("span",{className:"shrink-0 font-mono text-[11px] text-muted-foreground",children:yj(c.started_at,c.completed_at)}),n.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:n.jsx(Xr,{className:"size-3.5"})})]}),c.steps.length?n.jsx("ol",{className:"space-y-1.5 pl-6",children:c.steps.map(u=>n.jsxs("li",{className:"flex items-center gap-2 text-[12px]",children:[n.jsx(xj,{item:u}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:u.name}),n.jsx("span",{className:"shrink-0 font-mono text-[11px] text-muted-foreground",children:yj(u.started_at,u.completed_at)})]},`${c.id}:${u.number}`))}):n.jsx("p",{className:"pl-6 text-[12px] text-muted-foreground",children:l("github.actions.noSteps")})]},c.id))})})]}):n.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:l("github.actions.selectRun")})}function xj({item:e}){return e.status==="in_progress"||e.status==="queued"?n.jsx(Lo,{className:"size-3.5 shrink-0 animate-pulse text-amber-400"}):e.conclusion==="success"||e.conclusion==="skipped"?n.jsx(rm,{className:"size-3.5 shrink-0 text-emerald-500"}):e.conclusion==="failure"||e.conclusion==="timed_out"||e.conclusion==="cancelled"?n.jsx(A0,{className:"size-3.5 shrink-0 text-red-500"}):n.jsx(Lo,{className:"size-3.5 shrink-0 text-zinc-400"})}function yj(e,t){if(!e)return"-";const s=Date.parse(e),i=t?Date.parse(t):Date.now();if(!Number.isFinite(s)||!Number.isFinite(i)||i<s)return"-";const a=Math.max(0,Math.round((i-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 Nne({onCreatePR:e,onViewRuns:t}){const s=X(),[i,a]=v.useState(null),[l,c]=v.useState(!0),[u,f]=v.useState(null);function h(){let g=!0;return c(!0),f(null),w9().then(b=>{g&&a(b)}).catch(b=>{g&&f(b instanceof Error?b.message:String(b))}).finally(()=>{g&&c(!1)}),()=>{g=!1}}v.useEffect(h,[]),$o(()=>{h()});const p=v.useMemo(()=>[...i?.branches??[]].sort((b,x)=>{const _=wj(b,i),k=wj(x,i);return _-k||b.name.localeCompare(x.name)}),[i]);return n.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[n.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("h2",{className:"text-[13px] font-semibold",children:s("github.tab.branches")}),n.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:i?.repository.full_name??s("github.selectedRepo")})]}),n.jsxs(Q,{disabled:l,onClick:()=>{h()},size:"sm",type:"button",variant:"outline",children:[n.jsx(Mi,{className:`mr-1 size-3.5 ${l?"animate-spin":""}`}),s("common.refresh")]})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:u?n.jsx("div",{className:"p-4 text-[12px] text-red-500",children:u}):l&&!i?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:s("github.branches.loading")}):p.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:s("github.branches.empty")}):n.jsx("ul",{className:"divide-y divide-border",children:p.map(g=>n.jsx(Ene,{branch:g,currentBranch:i?.currentBranch??null,defaultBranch:i?.defaultBranch??null,onCreatePR:e,onViewRuns:t},g.name))})})]})}function Ene({branch:e,defaultBranch:t,currentBranch:s,onCreatePR:i,onViewRuns:a}){const l=X(),c=e.name===t,u=e.name===s,f=!c;return n.jsxs("li",{className:"flex flex-wrap items-center gap-3 px-3 py-2.5",children:[n.jsx(Mn,{className:"size-4 shrink-0 text-muted-foreground"}),n.jsxs("div",{className:"min-w-48 flex-1",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx("span",{className:"truncate font-mono text-[13px] font-medium",children:e.name}),c?n.jsx(_j,{label:l("github.branches.default"),tone:"success"}):null,u?n.jsx(_j,{label:l("github.branches.current"),tone:"warning"}):null,e.protected?n.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground",children:[n.jsx(Wj,{className:"size-3"}),l("github.branches.protected")]}):null]}),n.jsx("div",{className:"mt-0.5 font-mono text-[11px] text-muted-foreground",children:e.commit.sha.slice(0,7)})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[n.jsxs(Q,{onClick:()=>a(e.name),size:"sm",title:l("github.branches.viewRunsTitle",{name:e.name}),type:"button",variant:"outline",children:[n.jsx(cD,{className:"size-3.5"}),l("github.branches.viewRuns")]}),n.jsxs(Q,{disabled:!f,onClick:()=>i(e.name),size:"sm",title:f?l("github.branches.openPrTitle",{name:e.name}):l("github.branches.defaultNoPr"),type:"button",variant:"outline",children:[n.jsx(Hj,{className:"size-3.5"}),l("github.branches.openPr")]})]})]})}function _j({label:e,tone:t}){const s=t==="success"?"bg-emerald-500":"bg-amber-500";return n.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground",children:[n.jsx("span",{className:`size-1.5 rounded-full ${s}`}),e]})}function wj(e,t){return e.name===t?.currentBranch?0:e.name===t?.defaultBranch?1:e.protected?2:3}function jne(){const e=X(),t=Jse();let s;return t.loading||t.status==="checking"?s=n.jsx(vm,{fill:!0,label:e("common.loading")}):t.status==="not_configured"?s=n.jsx(a4,{deviceFlowAvailable:t.deviceFlowAvailable,onSaved:t.refresh}):t.status==="auth_error"||t.status==="connection_error"?s=n.jsx(Ane,{token:t}):s=n.jsx(Tne,{token:t}),n.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:s})}function Ane({token:e}){const t=X(),[s,i]=v.useState(null);if(s)return n.jsx(a4,{deviceFlowAvailable:e.deviceFlowAvailable,initialMode:s,onSaved:e.refresh});const a=e.status==="auth_error";return n.jsx("div",{className:"flex h-full items-center justify-center p-8",children:n.jsxs("div",{className:"w-full max-w-lg space-y-4 rounded-md border border-border bg-card p-5",children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(Rm,{className:"size-5"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("h2",{className:"text-sm font-semibold",children:t("github.connFailed")}),n.jsx("p",{className:"text-[12px] text-muted-foreground",children:t(a?"github.tokenRejected":"github.cantValidate")})]}),n.jsx(h4,{label:t(a?"github.needsRelogin":"github.connProblem"),tone:a?"danger":"warning"})]}),e.error?n.jsx(nt,{variant:"destructive",children:e.error}):null,n.jsxs("div",{className:"flex flex-wrap gap-2",children:[n.jsxs(Q,{onClick:e.refresh,type:"button",variant:a?"outline":"default",children:[n.jsx(Mi,{}),t("common.refresh")]}),n.jsx(Q,{onClick:()=>i(e.deviceFlowAvailable?"device-pending":"pat"),type:"button",variant:a?"default":"outline",children:t("github.reconnectGithub")}),n.jsx(Q,{onClick:()=>i("pat"),type:"button",variant:"outline",children:t("github.useToken")})]})]})})}function Tne({token:e}){const t=X(),[s,i]=Pl("github:tab","prs"),[a,l]=Pl("github:pr-state","open"),[c,u]=Pl("github:issue-state","open"),[f,h]=v.useState(null),[p,g]=v.useState(null),[b,x]=v.useState(null),{isPending:_,runOperation:k}=Yn(),C=_("github:disconnect"),E=ene(a),j=tne(c);$o(()=>{s==="prs"?E.refresh():s==="issues"&&j.refresh()});const N=D=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${D?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`,A=D=>`rounded px-2 py-0.5 text-[10px] font-medium transition-colors ${D?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`;async function T(){x(null);try{await k({errorMessage:D=>D instanceof Error?D.message:String(D),key:"github:disconnect",label:t("github.disconnecting")},async()=>{await _9("github.com"),e.refresh()})}catch(D){x(D instanceof Error?D.message:String(D))}}return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border bg-card/95 px-3 py-1",children:[n.jsx("button",{className:N(s==="prs"),onClick:()=>i("prs"),type:"button",children:t("github.tab.prs")}),n.jsx("button",{className:N(s==="issues"),onClick:()=>i("issues"),type:"button",children:t("github.tab.issues")}),n.jsx("button",{className:N(s==="branches"),onClick:()=>i("branches"),type:"button",children:t("github.tab.branches")}),n.jsx("button",{className:N(s==="actions"),onClick:()=>i("actions"),type:"button",children:t("github.tab.actions")}),n.jsxs("div",{className:"ml-auto flex min-w-0 items-center gap-2",children:[n.jsx(Rne,{token:e}),n.jsxs(Q,{onClick:e.refresh,size:"sm",title:t("github.recheckTitle"),type:"button",variant:"outline",children:[n.jsx(Mi,{}),t("github.reconnect")]}),n.jsx(Q,{loading:C,loadingLabel:t("github.disconnecting"),onClick:()=>{T()},size:"sm",type:"button",variant:"outline",children:t("github.disconnect")})]}),s==="prs"?n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-muted/60 p-0.5",children:[n.jsx("button",{className:A(a==="open"),onClick:()=>l("open"),type:"button",children:t("github.open")}),n.jsx("button",{className:A(a==="closed"),onClick:()=>l("closed"),type:"button",children:t("github.closed")})]}),n.jsx(Q,{onClick:()=>h(""),size:"sm",type:"button",variant:"outline",children:t("github.newPr")})]}):s==="issues"?n.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-muted/60 p-0.5",children:[n.jsx("button",{className:A(c==="open"),onClick:()=>u("open"),type:"button",children:t("github.open")}),n.jsx("button",{className:A(c==="closed"),onClick:()=>u("closed"),type:"button",children:t("github.closed")})]}):null]}),b?n.jsx(nt,{variant:"destructive",className:"m-3",children:b}):null,f!==null?n.jsx(Mne,{initialHead:f,onCreated:D=>{h(null),i("prs"),E.setSelectedNumber(D.number),E.refresh()},onCancel:()=>h(null)}):n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s==="prs"?n.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(0,1fr)_minmax(0,2fr)] divide-x divide-border",children:[n.jsx("div",{className:"min-h-0 overflow-auto",children:n.jsx(ine,{error:E.error,hasMore:E.hasMore,loading:E.loading,loadingMore:E.loadingMore,onLoadMore:E.loadMore,onSelect:E.setSelectedNumber,prs:E.prs,selectedNumber:E.selectedNumber})}),n.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden",children:n.jsx(ane,{diff:E.diff,diffError:E.diffError,diffLoading:E.diffLoading,onMerged:()=>E.refresh(),pr:E.selectedPR})})]}):s==="issues"?n.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(0,1fr)_minmax(0,2fr)] divide-x divide-border",children:[n.jsx("div",{className:"min-h-0 overflow-auto",children:n.jsx(hne,{error:j.error,hasMore:j.hasMore,issues:j.issues,loading:j.loading,loadingMore:j.loadingMore,onLoadMore:j.loadMore,onSelect:j.setSelectedNumber,selectedNumber:j.selectedNumber})}),n.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden",children:n.jsx(bne,{commentError:j.commentError,comments:j.comments,commentsLoading:j.commentsLoading,issue:j.selectedIssue,onAddComment:j.addComment,submitting:j.submitting})})]}):s==="branches"?n.jsx(Nne,{onCreatePR:D=>h(D),onViewRuns:D=>{g(D),i("actions")}}):n.jsx(wne,{branch:p??void 0,onClearBranch:()=>g(null)})})]})}function Rne({token:e}){const t=X(),s=e.info?.repository?.full_name??(e.info?.user?`@${e.info.user.login}`:"GitHub");return n.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 border-r border-border pr-2",children:[n.jsx(Rm,{className:"size-4 shrink-0 text-foreground"}),n.jsx(h4,{label:t("github.connected"),tone:"success"}),n.jsx("span",{className:"max-w-48 truncate font-mono text-[10px] text-muted-foreground",children:s})]})}function h4({label:e,tone:t}){const s=t==="success"?"bg-emerald-500":t==="danger"?"bg-red-500":"bg-amber-500";return n.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-[11px] font-medium text-muted-foreground",children:[n.jsx("span",{className:`size-1.5 rounded-full ${s}`}),e]})}function Mne({initialHead:e,onCreated:t,onCancel:s}){const i=X(),[a,l]=v.useState(""),[c,u]=v.useState(""),[f,h]=v.useState(""),[p,g]=v.useState("main"),[b,x]=v.useState(!1),[_,k]=v.useState(null),[C,E]=v.useState(!0),[j,N]=v.useState(!1),[A,T]=v.useState(null);v.useEffect(()=>{let $=!0;return E(!0),T(null),N9().then(M=>{$&&(k(M),l(M.title),u(M.body),h(e||M.head),g(M.base||M.suggestedBase||"main"),x(M.draft))}).catch(M=>{$&&T(M instanceof Error?M.message:String(M))}).finally(()=>{$&&E(!1)}),()=>{$=!1}},[e]);async function D($){if($.preventDefault(),!(!a.trim()||!f.trim()||!p.trim())){N(!0),T(null);try{const M=await E9({title:a.trim(),body:c.trim()||void 0,head:f.trim(),base:p.trim(),draft:b});t(M)}catch(M){T(M instanceof Error?M.message:String(M))}finally{N(!1)}}}const z="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",O=_?.warnings??[];return n.jsxs("form",{className:"flex min-h-0 flex-col gap-3 overflow-auto bg-muted/20 p-4",onSubmit:$=>{D($)},children:[n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("h3",{className:"text-[13px] font-semibold",children:i("github.branchToPr")}),n.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:[_?.repository?.full_name??i("github.selectedRepo"),_?.currentBranch?` - ${_.currentBranch}`:""]})]}),n.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:i(C?"github.detectingBranch":"github.editableDraft")})]}),n.jsx(Dne,{template:_,loading:C}),O.length>0?n.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:O[0]}):null,n.jsx("input",{className:z,disabled:C,onChange:$=>l($.target.value),placeholder:i("github.fieldTitle"),required:!0,value:a}),n.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[n.jsxs("label",{className:"space-y-1",children:[n.jsx("span",{className:"text-[10px] uppercase text-muted-foreground",children:i("github.head")}),n.jsx("input",{className:z,disabled:C,onChange:$=>h($.target.value),placeholder:i("github.headBranch"),required:!0,value:f})]}),n.jsxs("label",{className:"space-y-1",children:[n.jsx("span",{className:"text-[10px] uppercase text-muted-foreground",children:i("github.base")}),n.jsx("input",{className:z,disabled:C,onChange:$=>g($.target.value),placeholder:i("github.baseBranch"),required:!0,value:p})]})]}),n.jsx("textarea",{className:`${z} resize-none`,disabled:C,onChange:$=>u($.target.value),placeholder:i("github.descriptionOptional"),rows:7,value:c}),n.jsxs("label",{className:"flex items-center gap-2 text-[12px]",children:[n.jsx("input",{checked:b,className:"size-3.5",disabled:C,onChange:$=>x($.target.checked),type:"checkbox"}),i("github.createAsDraft")]}),A?n.jsx(nt,{variant:"destructive",children:A}):null,n.jsxs("div",{className:"flex gap-2",children:[n.jsx(Q,{disabled:C||j||!a.trim()||!f.trim()||!p.trim(),type:"submit",children:i(j?"github.creating":"github.createPr")}),n.jsx(Q,{onClick:s,type:"button",variant:"outline",children:i("common.cancel")})]})]})}function Dne({template:e,loading:t}){const s=X(),i=e?.compare,a=i?.ciStatus,l=[{label:s("github.compare.base"),value:i?.base||e?.base||"main"},{label:s("github.compare.head"),value:i?.head||e?.head||"manual"},{label:s("github.compare.ahead"),value:t?"...":String(i?.aheadBy??0)},{label:s("github.compare.changed"),value:t?"...":String(i?.files.length??0)},{label:s("github.compare.ci"),value:a?`${a.state} (${a.totalCount})`:s("github.compare.unavailable")}];return n.jsxs("div",{className:"rounded-md border border-border bg-card px-3 py-2",children:[n.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[n.jsx("span",{className:"text-[11px] font-medium text-foreground",children:s("github.compareSummary")}),i?.headSha?n.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:i.headSha.slice(0,7)}):null]}),n.jsx("div",{className:"grid grid-cols-5 gap-2",children:l.map(c=>n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"truncate text-[10px] uppercase text-muted-foreground",children:c.label}),n.jsx("div",{className:"truncate font-mono text-[11px] text-foreground",children:c.value})]},c.label))}),i?.files.length?n.jsx("div",{className:"mt-2 flex flex-wrap gap-x-3 gap-y-1 text-[11px] text-muted-foreground",children:i.files.slice(0,4).map(c=>n.jsxs("span",{className:"max-w-52 truncate",children:[c.status," ",c.path]},`${c.status}:${c.path}`))}):null]})}function Lne({data:e,onRefresh:t}){const s=X(),{error:i,success:a}=gs(),[l,c]=v.useState(null),u=e.config.services,f=e.config.gitRepositories,h=GA(u,f).length;async function p(b,x){c(b);try{const{name:_}=await f9(x);await t(),a(s("git.repo.addedToast",{name:_}))}catch(_){i(_ instanceof Error?_.message:String(_))}finally{c(null)}}async function g(b,x){c(b);try{await Z9(b,x||void 0),await t(),a(s("services.project.savedToast",{name:b}))}catch(_){i(_ instanceof Error?_.message:String(_))}finally{c(null)}}return u.length===0?n.jsx("div",{className:"px-4 py-6 text-center text-xs text-muted-foreground",children:s("services.project.noServices")}):n.jsxs("div",{children:[n.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between border-b border-border bg-card px-4 py-2",children:[n.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:s("services.project.tableTitle")}),n.jsx("span",{className:"text-[11px] text-muted-foreground",children:h>0?s("services.project.countWithUnassigned",{total:u.length,unassigned:h}):s("services.project.count",{total:u.length})})]}),n.jsx("div",{className:"divide-y divide-border",children:u.map(b=>{const x=!!b.projectPath,_=f.find(C=>Zr(b.projectPath??b.cwd,C.path)),k=f.find(C=>Zr(b.cwd,C.path));return n.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_minmax(0,1.2fr)_auto] items-center gap-2 px-4 py-1.5",children:[n.jsxs("span",{className:"min-w-0",children:[n.jsx("span",{className:"block truncate text-xs font-medium leading-tight",children:b.name}),n.jsx("span",{className:"block truncate font-mono text-[10px] leading-tight text-muted-foreground",title:b.cwd,children:b.cwd})]}),n.jsxs("select",{"aria-label":s("services.project.selectAria",{name:b.name}),className:se("h-7 w-full truncate rounded-md border border-border bg-background py-0 pl-1.5 pr-6 text-[11px]",!_&&"border-amber-500/70"),disabled:l===b.name,onChange:C=>{g(b.name,C.target.value)},title:s("services.project.selectTitle"),value:b.projectPath??"",children:[n.jsx("option",{value:"",children:k?s("services.project.inferredAs",{name:k.name}):s("services.project.inferredNone")}),f.map(C=>n.jsx("option",{value:C.path,children:C.name},C.path)),x&&!_?n.jsx("option",{value:b.projectPath,children:s("services.project.missingProject",{path:b.projectPath??""})}):null]}),_?n.jsx("span",{className:"text-[10px] text-muted-foreground",children:s(x?"services.project.pinned":"services.project.inferred")}):b.cwd?n.jsxs("button",{"aria-label":s("services.project.adoptAria",{name:b.name}),className:"flex items-center gap-1 whitespace-nowrap rounded px-1 py-0.5 text-[10px] text-amber-600 transition-colors hover:bg-amber-500/10 disabled:opacity-50 dark:text-amber-500",disabled:l===b.name,onClick:()=>{p(b.name,b.cwd??"")},title:s("services.project.adoptTitle"),type:"button",children:[n.jsx(Zi,{className:"size-3.5"}),s("services.project.adopt")]}):n.jsx(Zi,{"aria-label":s("services.project.unassignedAria"),className:"size-3.5 text-amber-500"})]},b.name)})})]})}function One({data:e,onAdded:t,onCreated:s,onRefresh:i}){const a=X(),[l,c]=v.useState("path"),[u,f]=v.useState(e.git.cwd),[h,p]=v.useState(""),[g,b]=v.useState(!1),[x,_]=v.useState(""),[k,C]=v.useState(null),[E,j]=v.useState(!1),[N,A]=v.useState(null),[T,D]=v.useState(null),[z,O]=v.useState(e.git.cwd),{error:$,success:M}=gs();function I(V){const W=V instanceof Error?V.message:String(V);A(W),$(W)}async function G(V){const W=V.trim();if(!W.startsWith("/")){const re=a("git.repo.absPathError");return A(re),$(re),!1}try{const re=QR(W);return await u9(re,W),A(null),await i(),M(a("git.repo.addedToast",{name:re})),!0}catch(re){return I(re),!1}}async function B(V){V.preventDefault(),await G(u)&&t()}async function U(V){V.preventDefault();const W=h.trim();if(W){b(!0),A(null);try{const{name:re}=await d9(W);p(""),await i(),M(a("git.repo.clonedToast",{name:re})),t()}catch(re){I(re)}finally{b(!1)}}}async function Y(V){V.preventDefault();const W=x.trim();if(W){j(!0),A(null);try{const re=await h9(W,k??void 0);_(""),await i(),M(a("git.repo.createdToast",{name:re.name})),await s(re.name)}catch(re){I(re)}finally{j(!1)}}}const P=[["path",Io,a("git.repo.modeExisting")],["url",ju,a("git.repo.modeClone")],["new",Sn,a("git.repo.modeCreate")]];return n.jsxs("div",{className:"shrink-0 border-t border-border bg-muted/20 p-3",children:[n.jsxs("div",{className:"mb-1.5 flex flex-wrap items-center gap-x-2 gap-y-1",children:[n.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:a("git.repo.addSection")}),n.jsx("span",{className:"text-[11px] text-muted-foreground",children:a("git.repo.addQuestion")}),n.jsx("div",{className:"flex gap-1 text-[11px]",children:P.map(([V,W,re])=>n.jsxs("button",{className:se("flex items-center gap-1 rounded px-2 py-0.5 transition-colors",l===V?"bg-muted font-medium text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>{c(V),A(null)},type:"button",children:[n.jsx(W,{className:"size-3"}),re]},V))})]}),l==="path"?n.jsxs("form",{className:"flex gap-1.5",onSubmit:B,children:[n.jsx(St,{"aria-label":a("git.repo.pasteAbsPath"),className:"h-7 flex-1 px-2 font-mono text-[11px]",onChange:V=>{f(V.target.value),A(null)},placeholder:"/absolute/path",value:u}),n.jsxs(Q,{className:"h-7 px-2 text-[11px]",size:"sm",type:"submit",children:[n.jsx(Es,{className:"size-3"}),a("common.add")]}),n.jsx(Q,{"aria-label":a("git.repo.browseAdd"),className:"h-7 px-2",onClick:()=>{A(null),O(e.git.cwd),D("adopt")},size:"sm",type:"button",variant:"outline",children:n.jsx(vf,{className:"size-3"})})]}):l==="new"?n.jsxs("form",{className:"flex gap-1.5",onSubmit:Y,children:[n.jsx(St,{"aria-label":a("git.repo.createName"),className:"h-7 flex-1 px-2 font-mono text-[11px]",onChange:V=>{_(V.target.value),A(null)},placeholder:a("git.repo.createNamePlaceholder"),value:x}),n.jsxs(Q,{className:"h-7 px-2 text-[11px]",disabled:E||!x.trim(),size:"sm",type:"submit",children:[n.jsx(Sn,{className:"size-3"}),a(E?"git.repo.creating":"git.repo.create")]}),n.jsx(Q,{"aria-label":a("git.repo.createBrowse"),className:"h-7 px-2",onClick:()=>{A(null),O(k??e.git.cwd),D("parent")},size:"sm",title:a("git.repo.createBrowse"),type:"button",variant:"outline",children:n.jsx(vf,{className:"size-3"})})]}):n.jsxs("form",{className:"flex gap-1.5",onSubmit:U,children:[n.jsx(St,{"aria-label":a("git.repo.remoteUrl"),className:"h-7 flex-1 px-2 font-mono text-[11px]",onChange:V=>{p(V.target.value),A(null)},placeholder:"https://… or git@host:owner/repo.git",value:h}),n.jsxs(Q,{className:"h-7 px-2 text-[11px]",disabled:g||!h.trim(),size:"sm",type:"submit",children:[n.jsx(ju,{className:"size-3"}),a(g?"git.repo.cloning":"git.repo.clone")]})]}),N?n.jsx("div",{className:"mt-1.5 truncate text-[10px] text-destructive",children:N}):null,n.jsxs("div",{className:"mt-1 text-[10px] text-muted-foreground",children:[l==="path"?a("git.repo.existingHint"):null,l==="url"?a("git.repo.cloneHint"):null,l==="new"?k?a("git.repo.createIn",{path:k}):a("git.repo.createHint"):null]}),T==="adopt"?n.jsx(w0,{confirmLabel:a("git.repo.addProject"),errorMessage:N,initialPath:e.git.cwd,selectedPath:z,title:a("git.repo.addProjectTitle"),onCancel:()=>D(null),onSelect:O,onUse:async()=>{await G(z)&&(D(null),t())}}):null,T==="parent"?n.jsx(w0,{confirmLabel:a("git.repo.useThisFolder"),initialPath:k??e.git.cwd,selectedPath:z,title:a("git.repo.createParentTitle"),onCancel:()=>D(null),onSelect:O,onUse:()=>{C(z),D(null)}}):null]})}function Pne({data:e,onRemove:t,onSelect:s,onSelectAll:i,scopeAll:a}){const l=X(),c=e.git.selectedRepository;return n.jsxs("div",{className:"min-h-0 overflow-y-auto border-border sm:border-r",children:[n.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between border-b border-border bg-card px-4 py-2",children:[n.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:l("git.repo.projectsShort")}),n.jsx("span",{className:"text-[11px] text-muted-foreground",children:l("git.repo.projectsColumnHint")})]}),n.jsxs("button",{className:se("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:i,type:"button",children:[n.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(bf,{className:"size-3.5 shrink-0 text-muted-foreground"}),n.jsxs("span",{className:"min-w-0",children:[n.jsx("span",{className:"block truncate text-sm font-medium leading-tight",children:l("app.allProjects")}),n.jsx("span",{className:"block truncate text-[10px] leading-tight text-muted-foreground",children:l("app.allProjectsHint")})]})]}),a?n.jsx(rn,{className:"size-3.5"}):n.jsx("span",{className:"size-3.5"})]}),e.config.gitRepositories.length?n.jsx("div",{className:"divide-y divide-border",children:e.config.gitRepositories.map(u=>{const f=!a&&u.name===c?.name,h=e.config.services.filter(p=>Zr(p.projectPath??p.cwd,u.path)).length;return n.jsxs("div",{className:se("group grid w-full grid-cols-[1fr_auto_auto_auto] items-center gap-2 px-4 py-2 text-left transition-colors hover:bg-muted",f&&"bg-muted/70"),children:[n.jsxs("button",{className:"min-w-0 text-left",onClick:()=>s(u.name),type:"button",children:[n.jsx("span",{className:"block truncate text-sm font-medium leading-tight",children:u.name}),n.jsx("span",{className:"block truncate font-mono text-[10px] leading-tight text-muted-foreground",title:u.path,children:u.path})]}),n.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",children:h===1?l("git.repo.serviceCountOne",{count:h}):l("git.repo.serviceCount",{count:h})}),f?n.jsx(rn,{className:"size-3.5"}):n.jsx("span",{className:"size-3.5"}),n.jsx(Q,{"aria-label":l("git.repo.removeName",{name:u.name}),className:"size-6 opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>t(u.name),size:"icon",title:l("git.repo.removeName",{name:u.name}),type:"button",variant:"ghost",children:n.jsx(Xi,{className:"size-3.5 text-destructive"})})]},u.name)})}):n.jsx("div",{className:"px-4 py-6 text-center text-xs text-muted-foreground",children:l("git.repo.noProjects")})]})}function zne({data:e,onClose:t,onRefresh:s,onScopeChange:i,scopeAll:a}){const l=X(),{error:c,success:u}=gs();async function f(g){try{await f3(g),i(!1),t(),await s(),u(l("git.repo.switchedToast",{name:g}))}catch(b){c(b instanceof Error?b.message:String(b))}}function h(){i(!0),t(),u(l("app.showingAllProjects"))}async function p(g){try{await c9(g),await s(),u(l("git.repo.removedToast",{name:g}))}catch(b){c(b instanceof Error?b.message:String(b))}}return Xn.createPortal(n.jsx("div",{className:"fixed inset-0 z-[1000] grid place-items-center bg-black/35 px-4",onMouseDown:g=>{g.target===g.currentTarget&&t()},children:n.jsxs("div",{className:"flex max-h-[85vh] w-full max-w-3xl flex-col overflow-hidden rounded-xl border border-border bg-card shadow-xl",children:[n.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-4 py-3",children:[n.jsx(bf,{className:"size-4 text-muted-foreground"}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"text-sm font-semibold leading-tight",children:l("git.repo.projectsShort")}),n.jsx("div",{className:"truncate text-[10px] leading-tight text-muted-foreground",children:l("git.repo.projectsSubtitle")})]}),n.jsx(Ze,{className:"h-5 px-1.5 text-[10px]",variant:"outline",children:e.config.gitRepositories.length}),n.jsx(Q,{"aria-label":l("git.repo.closeSwitcher"),className:"ml-auto size-7",onClick:t,size:"icon",variant:"ghost",children:n.jsx(Gt,{className:"size-4"})})]}),n.jsxs("div",{className:"grid min-h-0 flex-1 grid-cols-1 overflow-hidden sm:grid-cols-2",children:[n.jsx(Pne,{data:e,onRemove:g=>{p(g)},onSelect:g=>{f(g)},onSelectAll:h,scopeAll:a}),n.jsx("div",{className:"min-h-0 overflow-y-auto border-t border-border sm:border-t-0",children:n.jsx(Lne,{data:e,onRefresh:s})})]}),n.jsx(One,{data:e,onAdded:t,onCreated:g=>f(g),onRefresh:s})]})}),document.body)}function Bne({data:e,scopeAll:t,onScopeChange:s,onRefresh:i}){const a=X(),[l,c]=v.useState(!1),[u,f]=v.useState(!1),[h,p]=v.useState({top:0,left:0}),g=v.useRef(null),b=v.useRef(null),{error:x,success:_}=gs(),k=e.git.selectedRepository,C=t?a("app.allProjects"):k?.name??a("app.pickProject"),E=t?null:e.git.status?.branch??null;function j(){const A=g.current?.getBoundingClientRect();A&&p({top:A.bottom+4,left:A.left}),c(T=>!T)}v.useEffect(()=>{if(!l)return;function A(z){const O=z.target;g.current?.contains(O)||b.current?.contains(O)||c(!1)}function T(z){z.key==="Escape"&&c(!1)}function D(z){b.current?.contains(z.target)||c(!1)}return document.addEventListener("mousedown",A),document.addEventListener("keydown",T),window.addEventListener("scroll",D,!0),()=>{document.removeEventListener("mousedown",A),document.removeEventListener("keydown",T),window.removeEventListener("scroll",D,!0)}},[l]);async function N(A){c(!1);try{await f3(A),s(!1),await i(),_(a("git.repo.switchedToast",{name:A}))}catch(T){x(T instanceof Error?T.message:String(T))}}return n.jsxs(n.Fragment,{children:[n.jsxs("button",{"aria-expanded":l,"aria-haspopup":"menu","aria-label":a("app.projectScope",{label:C}),className:se("flex h-7 min-w-0 items-center gap-1.5 rounded-md border border-transparent px-1.5 text-left transition-colors hover:border-border hover:bg-muted",l&&"border-border bg-muted"),onClick:j,ref:g,title:a("app.projectScope",{label:C}),type:"button",children:[n.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center rounded border border-border bg-background text-[10px] font-semibold",children:t?n.jsx(bf,{className:"size-3 text-muted-foreground"}):k?C.charAt(0).toUpperCase():n.jsx(j0,{className:"size-3 text-muted-foreground"})}),n.jsx("span",{className:"truncate text-sm font-medium",children:C}),E?n.jsx("span",{className:"hidden truncate font-mono text-[11px] text-muted-foreground sm:inline",children:E}):null,n.jsx(kn,{className:se("size-3.5 shrink-0 text-muted-foreground transition-transform",l&&"rotate-180")})]}),l?Xn.createPortal(n.jsxs("div",{className:"fixed z-50 flex max-h-80 min-w-56 flex-col rounded-md border border-border bg-card p-1 shadow-md",ref:b,role:"menu",style:{top:h.top,left:h.left},children:[n.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[n.jsx(Qv,{active:t,icon:n.jsx(bf,{className:"size-3.5 text-muted-foreground"}),label:a("app.allProjects"),onSelect:()=>{c(!1),s(!0),_(a("app.showingAllProjects"))}}),e.config.gitRepositories.map(A=>n.jsx(Qv,{active:!t&&k?.name===A.name,icon:n.jsx("span",{className:"flex size-3.5 items-center justify-center text-[9px] font-semibold text-muted-foreground",children:A.name.charAt(0).toUpperCase()}),label:A.name,onSelect:()=>{N(A.name)}},A.name))]}),n.jsx("div",{className:"my-1 h-px shrink-0 bg-border"}),n.jsx(Qv,{active:!1,icon:n.jsx(vf,{className:"size-3.5 text-muted-foreground"}),label:`${a("app.addManageProjects")}…`,onSelect:()=>{c(!1),f(!0)}})]}),document.body):null,u?n.jsx(zne,{data:e,onClose:()=>f(!1),onRefresh:i,onScopeChange:s,scopeAll:t}):null]})}function Qv({active:e,icon:t,label:s,onSelect:i}){return n.jsxs("button",{className:se("flex w-full shrink-0 items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs transition-colors hover:bg-muted",e&&"bg-muted/60"),onClick:i,role:"menuitem",type:"button",children:[n.jsx("span",{className:"shrink-0",children:t}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:s}),e?n.jsx(rn,{className:"size-3.5 shrink-0 text-muted-foreground"}):null]})}function Ine({ahead:e=0,behind:t=0,branches:s,currentBranch:i,disabled:a,onRefresh:l,upstream:c}){const u=X(),[f,h]=v.useState(!1),[p,g]=v.useState(""),[b,x]=v.useState(null),[_,k]=v.useState(null),[C,E]=v.useState(null),j=s.filter(M=>!M.remote),N=s.filter(M=>M.remote);async function A(M,I){x(M),E(null),k(null);try{await I(),await l()}catch(G){E(G instanceof Error?G.message:String(G))}finally{x(null)}}async function T(M){await A(`switch:${M}`,async()=>{await ji("/api/git/branches/switch",{name:M}),h(!1)})}async function D(){await A("fetch",async()=>{await ji("/api/git/fetch",{}),k(u("git.branch.fetched"))})}async function z(){await A("push",async()=>{const M=await gm();k(M.setUpstream?u("git.branch.pushedSetUpstream",{branch:M.branch}):u("git.branch.pushed",{branch:M.branch}))})}const O=!!i&&(e>0||!c&&t===0);async function $(M){M.preventDefault();const I=p.trim();if(!I){E(u("git.branch.nameRequired"));return}await A("create",async()=>{await ji("/api/git/branches",{name:I}),g(""),h(!1)})}return n.jsxs("div",{className:"fixed bottom-12 right-4 z-50 flex items-end",children:[f?n.jsxs("div",{"aria-label":u("git.branch.switchAria"),className:"mb-11 w-[min(460px,calc(100vw-2rem))] rounded-lg border border-border bg-card shadow-xl",role:"dialog",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border p-3",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(Mn,{className:"size-4 text-muted-foreground"}),n.jsx("span",{className:"truncate text-sm font-semibold",children:i||u("git.branch.branches")})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[O?n.jsxs(Q,{"aria-label":u("git.branch.pushAria"),className:"gap-1.5 px-2 text-xs",disabled:a||b!==null,onClick:()=>{z()},size:"sm",title:c?u("git.branch.pushCountTo",{ahead:e,upstream:c}):u("git.branch.pushSetUpstream"),type:"button",variant:"default",children:[n.jsx(fm,{className:se("size-3.5",b==="push"&&"animate-pulse")}),u("git.branch.push"),e>0?` ${e}`:""]}):null,n.jsx(Q,{"aria-label":u("git.branch.fetchAria"),disabled:a||b!==null,onClick:()=>{D()},size:"icon",title:u("git.branch.fetchAria"),type:"button",variant:"ghost",children:n.jsx(Mi,{className:se(b==="fetch"&&"animate-spin")})}),n.jsx(Q,{"aria-label":u("git.branch.closeAria"),onClick:()=>h(!1),size:"icon",type:"button",variant:"ghost",children:n.jsx(Gt,{})})]})]}),n.jsx("div",{className:"max-h-72 overflow-auto",children:s.length?n.jsxs(n.Fragment,{children:[n.jsx(Sj,{branches:j,busy:b!==null,disabled:a,empty:u("git.branch.noLocal"),label:u("git.branch.sectionLocal"),onSwitch:T}),n.jsx(Sj,{branches:N,busy:b!==null,disabled:a,empty:u("git.branch.noRemote"),label:u("git.branch.sectionRemote"),onSwitch:T})]}):n.jsx("div",{className:"px-3 py-6 text-center text-sm text-muted-foreground",children:u("git.branch.noneFound")})}),n.jsxs("div",{className:"border-t border-border p-3",children:[n.jsxs("form",{className:"grid gap-2 sm:grid-cols-[1fr_auto]",onSubmit:$,children:[n.jsx(St,{"aria-label":u("git.branch.newNameAria"),disabled:a||b!==null,onChange:M=>{g(M.target.value),E(null),k(null)},placeholder:"feature/new-work",value:p}),n.jsxs(Q,{disabled:a||b!==null,type:"submit",children:[n.jsx(n8,{}),u("git.branch.create")]})]}),C||_?n.jsx(nt,{className:"mt-3 px-3 py-2 text-xs",variant:C?"destructive":"muted",children:C??_}):null]})]}):null,n.jsxs(Q,{className:"h-8 max-w-[260px] gap-2 rounded-md shadow-lg",disabled:a,onClick:()=>h(M=>!M),size:"sm",title:u("git.branch.switchAria"),type:"button",variant:"default",children:[n.jsx(Mn,{className:"size-4"}),n.jsx("span",{className:"truncate font-mono text-xs",children:i||u("git.branch.noBranch")}),i&&(e>0||t>0)?n.jsxs("span",{className:"flex items-center gap-1 font-mono text-[11px] tabular-nums",title:c?u("git.branch.aheadBehindUpstream",{ahead:e,behind:t,upstream:c}):u("git.branch.aheadBehind",{ahead:e,behind:t}),children:[t>0?n.jsxs("span",{className:"flex items-center",children:[n.jsx(em,{className:"size-3"}),t]}):null,e>0?n.jsxs("span",{className:"flex items-center",children:[n.jsx(tm,{className:"size-3"}),e]}):null]}):null,n.jsx(kn,{className:se("size-4 transition-transform",f&&"rotate-180")})]})]})}function Sj({branches:e,busy:t,disabled:s,empty:i,label:a,onSwitch:l}){const c=X();return n.jsxs("section",{children:[n.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(u=>n.jsxs("button",{className:se("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",u.current&&"bg-muted/70"),disabled:s||t||u.current,onClick:()=>{l(u.name)},type:"button",children:[n.jsxs("span",{className:"min-w-0",children:[n.jsx("span",{className:"block truncate font-medium",children:u.name}),u.upstream?n.jsx("span",{className:"block truncate font-mono text-[11px] text-muted-foreground",children:c("git.branch.tracks",{upstream:u.upstream})}):null]}),n.jsx(Ze,{variant:u.current?"success":u.remote?"outline":"secondary",children:u.current?c("git.branch.tagCurrent"):u.remote?c("git.branch.tagRemote"):c("git.branch.tagLocal")})]},`${u.remote?"remote":"local"}:${u.name}`)):n.jsx("div",{className:"border-b border-border px-3 py-3 text-sm text-muted-foreground",children:i})]})}function Hne(){const e=X(),[,t]=GT(),s=VT(),i=v.useRef(null),a=v.useCallback(()=>{const l=s==="dark"?"light":"dark",c=i.current,u=document;if(!c||!u.startViewTransition||window.matchMedia("(prefers-reduced-motion: reduce)").matches){t(l);return}const f=c.getBoundingClientRect(),h=f.left+f.width/2,p=f.top+f.height/2,g=Math.hypot(Math.max(h,window.innerWidth-h),Math.max(p,window.innerHeight-p));u.startViewTransition(()=>{t(l)}).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${h}px ${p}px)`,`circle(${g}px at ${h}px ${p}px)`]},{duration:500,easing:"ease-in-out",pseudoElement:"::view-transition-new(root)"})})},[s,t]);return n.jsxs("button",{ref:i,type:"button",onClick:a,title:e(s==="dark"?"action.toLight":"action.toDark"),"aria-label":e("action.theme"),className:Mf(),children:[n.jsx("span",{className:Df(),children:s==="dark"?n.jsx(XL,{}):n.jsx(X8,{})}),n.jsx("span",{className:Lf(),children:e("action.theme")})]})}function $ne(){const e=X();return js()?n.jsxs("div",{className:"flex items-center justify-between h-8 bg-background border-b border-border select-none",style:{WebkitAppRegion:"drag"},onMouseDown:()=>pO(),children:[n.jsx("span",{className:"px-3 text-xs font-medium text-muted-foreground",children:"NoMoreIDE"}),n.jsxs("div",{className:"flex items-center",style:{WebkitAppRegion:"no-drag"},children:[n.jsx("button",{type:"button",onClick:hO,className:"h-8 w-10 flex items-center justify-center hover:bg-muted transition-colors","aria-label":e("common.minimize"),children:n.jsx(Uj,{className:"h-3 w-3"})}),n.jsx("button",{type:"button",onClick:fO,className:"h-8 w-10 flex items-center justify-center hover:bg-muted transition-colors","aria-label":e("common.maximize"),children:n.jsx($a,{className:"h-3 w-3"})}),n.jsx("button",{type:"button",onClick:mO,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:n.jsx(Gt,{className:"h-3 w-3"})})]})]}):null}const Fne=300;function Une(){const{operations:e}=Yn(),[t,s]=v.useState(!1),[i,a]=v.useState(!1),l=v.useId(),c=X();if(v.useEffect(()=>{if(e.length===0){s(!1),a(!1);return}const h=Math.min(...e.map(({startedAt:b})=>b)),p=Math.max(0,Fne-(Date.now()-h));if(p===0){s(!0);return}s(!1);const g=window.setTimeout(()=>s(!0),p);return()=>window.clearTimeout(g)},[e]),!t||e.length===0)return null;const u=e.length>1,f=u?c("operation.multiple",{count:e.length}):e[0].label;return n.jsxs("aside",{"aria-live":"polite",className:"relative z-30 mx-4 mt-2 shrink-0 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:[n.jsxs("div",{className:"flex min-h-7 items-center gap-2",children:[n.jsx(bm,{size:"sm"}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium",children:f}),u?n.jsx(Q,{"aria-controls":l,"aria-expanded":i,"aria-label":c(i?"operation.hideDetails":"operation.showDetails"),onClick:()=>a(h=>!h),size:"icon-sm",type:"button",variant:"ghost",children:n.jsx(kn,{className:se("transition-transform motion-reduce:transition-none",i&&"rotate-180")})}):null]}),u&&i?n.jsx("ul",{className:"mt-2 space-y-1 border-t border-border pt-2",id:l,children:e.map(h=>n.jsxs("li",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[n.jsx("span",{"aria-hidden":!0,className:"size-1.5 shrink-0 rounded-full bg-primary"}),n.jsx("span",{className:"truncate",children:h.label})]},h.id))}):null]})}function qne(e){const t=e===document?document.scrollingElement:e instanceof Element?e:null;if(!t)return null;const s=t.scrollHeight-t.clientHeight;return s<=0?null:Math.round(t.scrollTop/s*100)}function Gne({type:e="circle",position:t="bottom-right",color:s="hsl(var(--primary))",strokeSize:i=2,showPercentage:a=!1}){const[l,c]=v.useState(0);return v.useEffect(()=>{const u=f=>{const h=qne(f.target);h!==null&&c(h)};return document.addEventListener("scroll",u,{capture:!0,passive:!0}),()=>document.removeEventListener("scroll",u,!0)},[]),e==="bar"?n.jsx("div",{"aria-hidden":"true",className:"pointer-events-none fixed inset-x-0 top-0 z-[100]",style:{height:`${i}px`},children:n.jsx(Ro.span,{animate:{width:`${l}%`},className:"block h-full",initial:!1,style:{backgroundColor:s,boxShadow:`0 0 8px ${s}`},transition:{duration:.12,ease:"easeOut"}})}):n.jsx("div",{className:se("pointer-events-none fixed z-[100] flex items-center justify-center",{"end-0 top-0":t==="top-right","bottom-0 end-0":t==="bottom-right","start-0 top-0":t==="top-left","bottom-0 start-0":t==="bottom-left"}),children:l>0?n.jsxs(n.Fragment,{children:[n.jsxs("svg",{"aria-hidden":"true",height:"100",viewBox:"0 0 100 100",width:"100",children:[n.jsx("circle",{cx:"50",cy:"50",fill:"none",r:"30",stroke:"hsl(var(--border))",strokeWidth:i}),n.jsx(Ro.circle,{animate:{pathLength:l/100},cx:"50",cy:"50",fill:"none",initial:!1,pathLength:"1",r:"30",stroke:s,strokeWidth:i,style:{rotate:-90,transformOrigin:"center"},transition:{duration:.12,ease:"easeOut"}})]}),a?n.jsxs("span",{className:"absolute text-sm",children:[l,"%"]}):null]}):null})}const f4={services:"/",docker:"/docker",git:"/git",github:"/github",workflows:"/workflows",errors:"/errors",database:"/database",terminal:"/terminal",agent:"/agent","agent-env":"/agent-env",settings:"/settings"},Vne={services:"nav.services",docker:"nav.docker",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"},Wne=Object.entries(f4).filter(([,e])=>e!=="/").sort(([,e],[,t])=>t.length-e.length);function Kne(e){for(const[t,s]of Wne)if(e.startsWith(s))return t;return"services"}const Yne=[{labelKey:"nav.section.run",items:[{page:"services",labelKey:"nav.services",icon:n.jsx(hm,{})},{page:"docker",labelKey:"nav.docker",icon:n.jsx(am,{})},{page:"errors",labelKey:"nav.errors",icon:n.jsx($u,{})},{page:"terminal",labelKey:"nav.terminal",icon:n.jsx(wr,{})}]},{labelKey:"nav.section.code",items:[{page:"git",labelKey:"nav.git",icon:n.jsx(Mn,{})},{page:"github",labelKey:"nav.github",icon:n.jsx(Rm,{})},{page:"workflows",labelKey:"nav.workflows",icon:n.jsx(yf,{})}]},{labelKey:"nav.section.data",items:[{page:"database",labelKey:"nav.database",icon:n.jsx(hi,{})}]},{labelKey:"nav.section.agent",items:[{page:"agent",labelKey:"nav.agentConsole",icon:n.jsx(sm,{})},{page:"agent-env",labelKey:"nav.agentEnv",icon:n.jsx(Fu,{})}]}];function Xne(e=!1){return se("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 Zne(e,t=!1){return se("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 Qne(e=!1,t=!1){return se("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 Jne(e=!1){return se("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 eie({docked:e,onToggleDock:t}){return n.jsxs("div",{className:se("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:[n.jsxs("span",{className:se("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:[n.jsx("span",{children:"Made with"}),n.jsx(d8,{"aria-label":"love",className:"size-3 shrink-0 fill-red-500 text-red-500"}),n.jsx("span",{children:"by Robert Wang"}),n.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:n.jsxs("svg",{className:"size-3 fill-current",role:"img",viewBox:"0 0 24 24",children:[n.jsx("title",{children:"LinkedIn"}),n.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"})]})})]}),n.jsx("button",{"aria-label":e?"Undock sidebar":"Dock sidebar","aria-pressed":e,className:se("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?n.jsx(rL,{}):n.jsx(oL,{})})]})}function tie({className:e}){return n.jsxs("div",{className:se("min-w-0",e),children:[n.jsxs("div",{className:"flex items-baseline gap-1.5",children:[n.jsx("div",{className:"text-sm font-semibold",children:"NoMoreIDE"}),n.jsxs("div",{className:"font-mono text-[10px] text-muted-foreground",children:["v","0.1.92"]})]}),n.jsx("div",{className:"font-mono text-[11px] text-muted-foreground",children:"127.0.0.1 console"})]})}function sie({syncLocation:e=!0}={}){return n.jsx(_Z,{children:n.jsx(tq,{children:n.jsx(iie,{syncLocation:e})})})}function nie({projectPath:e,selectProject:t}){return v.useEffect(()=>{t(e)},[e,t]),null}function iie({syncLocation:e}){const t=X(),[,s]=v.useTransition(),[i,a]=v.useState(()=>e?Kne(window.location.pathname):"services"),[l,c]=v.useState(null),[u,f]=v.useState(null),[h,p]=v.useState(null),[g,b]=v.useState(0),[x,_]=v.useState({placement:"bottom",size:36}),[k,C]=v.useState(null),[E,j]=v.useState(!0),{error:N,message:A,success:T}=gs(),{ui:D,updateUi:z,selectProject:O}=Lm(),$=D.sidebarDocked,M=D.projectScope==="all",I=v.useCallback(K=>z({projectScope:K?"all":"project"}),[z]),G=v.useCallback((K,ue)=>{_(ge=>ge.placement===K&&ge.size===ue?ge:{placement:K,size:ue})},[]),B=RG(),U=v.useCallback(async(K={})=>{K.silent||j(!0),C(null);try{const ue=await V9();K.silent?s(()=>c(ue)):c(ue),K.notify&&T(t("app.dashboardRefreshed"))}catch(ue){const ge=ue instanceof Error?ue.message:String(ue);C(ge),N(ge)}finally{j(!1)}},[N,T,s,t]),Y=v.useCallback(()=>{U({notify:!0}),B.runActive()},[U,B]);v.useEffect(()=>{U()},[U]),v.useEffect(()=>{function K(){document.visibilityState==="visible"&&(U({silent:!0}),B.runActive())}const ue=window.setInterval(K,5e3);return window.addEventListener("focus",K),document.addEventListener("visibilitychange",K),()=>{window.clearInterval(ue),window.removeEventListener("focus",K),document.removeEventListener("visibilitychange",K)}},[i,U,B.runActive]),v.useEffect(()=>{if(!e)return;const K=f4[i];window.location.pathname!==K&&window.history.pushState(null,"",K)},[i,e]);const P=!M&&l?.git.selectedRepository||null,V=v.useMemo(()=>l&&P?xV(l,P):l,[l,P]),W=v.useMemo(()=>P&&V?new Set(V.config.services.map(K=>K.name)):null,[P,V]),re=v.useMemo(()=>V?Object.values(V.runtime.services).filter(K=>K.state==="running").length:0,[V]),ce=l?.git.selectedRepository?.name??l?.git.cwd??"no-git-repository",F=l?.git.selectedRepository?.path??null;return n.jsxs(bq,{children:[n.jsx(nie,{projectPath:F,selectProject:O}),n.jsx(MG,{value:B,children:n.jsx(YV,{onRefresh:()=>{U({silent:!0})},children:n.jsx(XV,{children:n.jsxs("div",{className:"flex flex-col h-screen overflow-hidden",children:[n.jsx(Gne,{type:"bar",strokeSize:2},i),n.jsx($ne,{}),n.jsxs("div",{className:"flex-1 overflow-hidden transition-[padding] duration-150",style:x.placement==="right"?{paddingRight:x.size}:{paddingBottom:x.size},children:[n.jsxs("div",{className:"mx-auto flex h-full max-w-[1500px]",children:[n.jsxs("aside",{className:Xne($),children:[n.jsxs("div",{className:se("grid h-12 grid-cols-[48px_minmax(0,1fr)] items-center overflow-hidden transition-[width] duration-150",$?"w-full":"w-12 group-hover/sidebar:w-full"),children:[n.jsx("div",{className:"flex size-12 items-center justify-center",children:n.jsx("div",{className:"flex size-9 items-center justify-center overflow-hidden rounded-md bg-primary text-primary-foreground",children:n.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:[n.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"}),n.jsx("path",{d:"M22 31L30 39L22 47",stroke:"hsl(var(--primary))",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"4.5"}),n.jsx("path",{d:"M36 47H48",stroke:"hsl(var(--primary))",strokeLinecap:"round",strokeWidth:"4.5"})]})})}),n.jsx(tie,{className:se("min-w-0 translate-x-1 overflow-hidden transition-opacity duration-200",$?"opacity-100":"opacity-0 group-hover/sidebar:opacity-100")})]}),n.jsx("nav",{className:"mt-3 flex-1 content-start overflow-y-auto overflow-x-hidden",children:Yne.map((K,ue)=>n.jsxs("div",{className:se(ue>0&&"mt-2 border-t border-border/60 pt-2"),children:[n.jsx(rie,{docked:$,label:t(K.labelKey)}),n.jsx("div",{className:"grid gap-0.5",children:K.items.map(ge=>n.jsx(kj,{active:i===ge.page,badge:ge.page==="services"?re:void 0,docked:$,icon:ge.icon,label:t(ge.labelKey),onClick:()=>a(ge.page)},ge.page))})]},K.labelKey))}),n.jsx("div",{className:"mb-1 border-t border-border/60 pt-1",children:n.jsx(kj,{active:i==="settings",docked:$,icon:n.jsx(Vj,{}),label:t("nav.settings"),onClick:()=>a("settings")})}),n.jsx(eie,{docked:$,onToggleDock:()=>z({sidebarDocked:!$})})]}),n.jsxs("main",{className:"flex h-full min-w-0 flex-1 flex-col px-0 py-0",children:[n.jsxs("header",{className:se("relative z-40 flex shrink-0 flex-wrap items-center justify-between gap-3 border border-border bg-card/90 px-3 py-1.5 backdrop-blur","border-x-0 border-t-0 border-b"),children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[n.jsx(cL,{className:"mr-1 size-4 shrink-0 text-muted-foreground md:hidden"}),l?n.jsx(Bne,{data:l,onRefresh:()=>U({silent:!0}),onScopeChange:I,scopeAll:M}):null,n.jsx(gn,{className:"size-3.5 shrink-0 text-muted-foreground/60"}),n.jsx("h1",{className:"truncate px-1 text-sm font-semibold tracking-tight",children:t(Vne[i])})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[k?n.jsx(Ze,{variant:"danger",children:k}):null,n.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:[n.jsxs("button",{"aria-label":t("action.refresh"),className:Mf(),onClick:Y,title:t("action.refreshTitle"),type:"button",children:[n.jsx("span",{className:Df(),children:n.jsx(Mi,{className:se(E&&"animate-spin")})}),n.jsx("span",{className:Lf(),children:t("action.refresh")})]}),n.jsx(Hne,{}),n.jsxs("a",{"aria-label":t("action.docsTitle"),className:Mf(),href:"https://www.nomoreide.com/docs",rel:"noreferrer",target:"_blank",title:t("action.docsTitle"),children:[n.jsx("span",{className:Df(),children:n.jsx(jj,{})}),n.jsx("span",{className:Lf(),children:t("action.docs")})]}),l?n.jsx(TV,{data:l}):null]})]})]}),n.jsx(Une,{}),l?n.jsx(QJ,{data:l,onOpenService:K=>{W&&!W.has(K)&&(I(!0),A({text:t("app.serviceOutsideScope")})),f(K),a("services"),U({silent:!0})}}):null,E&&!l?n.jsx(nt,{variant:"muted",children:t("app.loading")}):null,n.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[V&&i==="services"?n.jsx(LJ,{data:V,onRefresh:U,focusService:u,onServiceFocused:()=>f(null),scopeName:P?.name??null}):null,i==="docker"?n.jsx(YJ,{}):null,l&&i==="git"?n.jsx(Nse,{data:l,onRefresh:()=>{U({silent:!0})}}):null,i==="github"?n.jsx(jne,{},ce):null,i==="workflows"?n.jsx(Lse,{}):null,i==="agent"?n.jsx(TG,{focusChanges:g,onOpenAgentEnv:()=>a("agent-env")}):null,i==="agent-env"?n.jsx(sV,{}):null,i==="errors"?n.jsx(yQ,{inScope:W?K=>W.has(K):void 0,onReviewChanges:()=>{b(K=>K+1),a("agent")}}):null,i==="database"?n.jsx(QZ,{projects:l?.config.gitRepositories??[],scopePath:P?.path??null,staged:h,onStageConsumed:()=>p(null)}):null,i==="terminal"?n.jsx(iee,{}):null,i==="settings"?n.jsx(dQ,{activeProject:l?.git.selectedRepository??null,onNavigate:K=>a(K)}):null]})]})]}),l&&i==="git"?n.jsx(Ine,{ahead:l.git.status?.ahead??0,behind:l.git.status?.behind??0,branches:l.git.branches,currentBranch:l.git.status?.branch||void 0,disabled:!l.git.status,onRefresh:U,upstream:l.git.status?.upstream}):null,n.jsx(CZ,{currentPage:i,git:l?.git,onInsetChange:G,onNavigate:K=>a(K),onGitRefresh:()=>{U({silent:!0})}})]})]})})})})]})}function rie({docked:e,label:t}){return n.jsx("div",{className:"flex h-5 items-center overflow-hidden px-3",children:n.jsx("span",{className:se("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 kj({active:e,badge:t,docked:s,icon:i,label:a,onClick:l}){const c=t!==void 0&&t>0;return n.jsxs(Q,{"aria-label":a,title:a,className:Zne(e,s),variant:"ghost",onClick:l,type:"button",children:[n.jsx("span",{className:Jne(s),children:i}),n.jsx("span",{className:Qne(s,c),children:a}),t!==void 0&&t>0?n.jsx(Ze,{appearance:t>0?"solid":"outline",className:se("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]})}Nj.createRoot(document.getElementById("root")).render(n.jsx(v.StrictMode,{children:n.jsx(sie,{})}));export{n as j,v as r};
|
|
228
|
+
`),provider:a?.id,signal:A.signal});A.signal.aborted||c(T)}catch(T){A.signal.aborted||_(T instanceof Error?T.message:String(T))}finally{k.current===A&&(k.current=null,f(!1))}}async function j(){if(C){p(!0),_(null);try{await l9(C),b(C)}catch(N){_(N instanceof Error?N.message:String(N))}finally{p(!1)}}}return n.jsxs("div",{className:"mt-3 rounded-md border border-border bg-muted/35 p-3",children:[n.jsx(Yr,{children:i("workflows.recover.title")}),n.jsx("p",{className:"mb-2 text-[11px] text-muted-foreground",children:i("workflows.recover.desc")}),n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[n.jsxs(Q,{onClick:()=>{E()},size:"sm",type:"button",children:[n.jsx(cs,{className:"size-3.5"})," ",i("workflows.recover.recommend")]}),g?n.jsxs(Q,{onClick:t,size:"sm",type:"button",variant:"outline",children:[n.jsx(_r,{className:"size-3.5"})," ",i("workflows.recover.runAgain")]}):null]}),u?n.jsxs("p",{className:"mt-2 flex items-center gap-1 text-[11px] text-muted-foreground",children:[n.jsx(Bt,{className:"size-3 animate-spin"})," ",i("workflows.recover.choosing")]}):null,C?n.jsxs("div",{className:"mt-3 rounded-md border border-border bg-background p-2.5",children:[n.jsx(Yr,{children:i("workflows.recover.recommendedBranch")}),n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[n.jsx("code",{className:"min-w-0 rounded bg-muted px-2 py-1 font-mono text-[12px] text-foreground",children:C}),n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[n.jsxs(Q,{disabled:h||g===C,onClick:()=>{j()},size:"sm",type:"button",children:[h?n.jsx(Bt,{className:"size-3.5 animate-spin"}):n.jsx(rn,{className:"size-3.5"}),i("workflows.recover.createBranch")]}),n.jsxs(Q,{disabled:h,onClick:()=>{E("Recommend a different concise branch name. Keep the same output contract with `BRANCH_NAME: <branch-name>`.")},size:"sm",type:"button",variant:"outline",children:[n.jsx(cs,{className:"size-3.5"})," ",i("workflows.recover.askAnother")]})]})]})]}):l&&!u?n.jsxs("div",{className:"mt-3 rounded-md border border-border bg-background p-2.5",children:[n.jsx("p",{className:"text-[11px] text-muted-foreground",children:i("workflows.recover.noBranch")}),n.jsxs(Q,{className:"mt-2",onClick:()=>{E("Return only a concise branch suggestion using this exact line: `BRANCH_NAME: <branch-name>`.")},size:"sm",type:"button",variant:"outline",children:[n.jsx(cs,{className:"size-3.5"})," ",i("workflows.recover.askAnother")]})]}):null,g?n.jsxs("p",{className:"mt-2 text-[11px] text-emerald-700 dark:text-emerald-400",children:[i("workflows.recover.createdPre"),n.jsx("code",{className:"font-mono",children:g}),i("workflows.recover.createdPost")]}):null,x?n.jsx("p",{className:"mt-2 text-[11px] text-destructive",children:x}):null]})}const fj={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"},t4={gate:"workflows.kind.gate",agent:"workflows.kind.agent",action:"workflows.kind.action"};function Vse({output:e,previousOutput:t,status:s,step:i}){const a=X();if(i.kind==="gate"){const c=i.id==="gate-commit"?t?.trim():"";return n.jsxs("div",{children:[n.jsx("p",{className:"text-muted-foreground",children:i.message}),c?n.jsxs("div",{className:"mt-3",children:[n.jsx(Yr,{children:a("workflows.step.generatedCommitMessage")}),n.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(i.kind==="action")return n.jsx("p",{className:"text-muted-foreground",children:a(s4[i.op])});const l=s==="done"||s==="failed"||s==="skipped";return e?n.jsxs("div",{children:[n.jsx(Yr,{children:a("workflows.step.result")}),n.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})]}):n.jsxs("div",{children:[n.jsx(Yr,{children:a(l?"workflows.step.result":"workflows.step.task")}),l?n.jsx("p",{className:"italic text-muted-foreground",children:a("workflows.step.noReply")}):n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-muted-foreground",children:i.prompt}),s==="running"?n.jsxs("p",{className:"mt-1.5 flex items-center gap-1 text-muted-foreground/80",children:[n.jsx(Bt,{className:"size-3 animate-spin"})," ",a("workflows.step.working")]}):null]})]})}function Wse(e){return e.detected.name==="codex"?e.agents.codex:e.agents["claude-code"]??e}function Kse(e){return e?{skills:gu(e.skills.map(t=>t.name)),mcpServers:gu(e.mcpServers.map(t=>t.name)),plugins:gu(e.plugins.map(t=>t.name)),hooks:gu(e.hooks.map(t=>t.matcher?`${t.event}: ${t.matcher}`:t.event))}:{skills:[],mcpServers:[],plugins:[],hooks:[]}}function Yse(e){return{id:Z1("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 Xse(e){const t=Bl(e.id)||e.kind,s=e.title.trim()||Qf(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 i=n4(e.capabilities);return{...e,id:t,title:s,prompt:e.prompt.trim()||"Complete this workflow step.",capabilities:i}}const s4={"assert-pr-branch":"workflows.opDesc.assertPrBranch","checkout-default-and-pull":"workflows.opDesc.checkoutDefault",push:"workflows.opDesc.push",commit:"workflows.opDesc.commit"};function n4(e){if(!e)return;const t={};for(const s of["skills","mcpServers","plugins","hooks"]){const i=gu((e[s]??[]).map(a=>a.trim()).filter(Boolean));i.length&&(t[s]=i)}return Object.keys(t).length?t:void 0}function Zse(e,t,s){const i=e?.[t]??[],a=i.includes(s)?i.filter(l=>l!==s):[...i,s];return n4({...e??{},[t]:a})}function Z1(e,t){const s=new Set(t.map(l=>l.id));let i=Bl(e)||"workflow",a=2;for(;s.has(i);)i=`${Bl(e)||"workflow"}-${a}`,a++;return i}function Bl(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function gu(e){return Array.from(new Set(e.filter(Boolean)))}function Yr({children:e}){return n.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/70",children:e})}function C0(e){return new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"2-digit"}).format(new Date(e))}function i4({outcome:e}){const t=X(),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:i,className:a}=s[e];return n.jsx("span",{className:se("rounded-full border px-2 py-0.5 text-[10px] font-medium",a),children:t(i)})}function r4({kind:e}){return e==="gate"?n.jsx(Kj,{className:"size-4 text-amber-600 dark:text-amber-400"}):e==="agent"?n.jsx(Sn,{className:"size-4 text-primary"}):n.jsx(_r,{className:"size-4 text-muted-foreground"})}function mj({status:e,kind:t}){return e==="running"?n.jsx(Bt,{className:"size-4 shrink-0 animate-spin text-primary"}):e==="waiting"?n.jsx(Kj,{className:"size-4 shrink-0 text-primary"}):e==="done"?n.jsx(rn,{className:"size-4 shrink-0 text-emerald-600 dark:text-emerald-400"}):e==="blocked"?n.jsx(im,{className:"size-4 shrink-0 text-amber-600 dark:text-amber-400"}):e==="failed"?n.jsx(Zi,{className:"size-4 shrink-0 text-destructive"}):e==="skipped"?n.jsx(Yj,{className:"size-4 shrink-0 text-muted-foreground/60"}):t==="agent"?n.jsx(Sn,{className:"size-4 shrink-0 text-muted-foreground/50"}):n.jsx(rD,{className:"size-4 shrink-0 text-muted-foreground/50"})}function Qse(e){return n.jsx(gn,{className:"size-3 shrink-0 text-muted-foreground/40","aria-hidden":!0})}function N0({kind:e}){const t=X(),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 n.jsx("span",{className:se("shrink-0 rounded-full border px-1.5 py-px text-[9px] uppercase tracking-wide",s),children:t(t4[e])})}function Qf(e){return e.title}function Jse(){const[e,t]=v.useState(!1),[s,i]=v.useState(!1),[a,l]=v.useState(!0),[c,u]=v.useState("checking"),[f,h]=v.useState(null),[p,g]=v.useState(null);function b(){l(!0),u("checking"),h(null),b9().then(x=>{t(x.configured),i(x.deviceFlowAvailable),u(x.status),h(x.error??null),g(x)}).catch(x=>{t(!1),i(!1),u("connection_error"),h(x instanceof Error?x.message:String(x)),g(null)}).finally(()=>l(!1))}return v.useEffect(()=>{b()},[]),{configured:e,deviceFlowAvailable:s,loading:a,status:c,error:f,info:p,isConnected:c==="connected",needsLogin:c==="not_configured"||c==="auth_error",refresh:b}}const Xv=30;function ene(e="open"){const[t,s]=v.useState([]),[i,a]=v.useState(!0),[l,c]=v.useState(!1),[u,f]=v.useState(!1),[h,p]=v.useState(1),[g,b]=v.useState(null),[x,_]=v.useState(null),[k,C]=v.useState(null),[E,j]=v.useState(""),[N,A]=v.useState(!1),[T,D]=v.useState(null);v.useEffect(()=>{let $=!0;return a(!0),b(null),p(1),Qg(e,1).then(M=>{$&&(s(M),f(M.length===Xv),M.length>0&&!M.some(I=>I.number===x)&&_(M[0]?.number??null))}).catch(M=>{$&&b(M instanceof Error?M.message:String(M))}).finally(()=>{$&&a(!1)}),()=>{$=!1}},[e]),v.useEffect(()=>{if(!x){C(null);return}let $=!0;return S9(x).then(M=>{$&&C(M)}).catch(()=>{}),()=>{$=!1}},[x]),v.useEffect(()=>{if(!x){j("");return}let $=!0;return A(!0),D(null),k9(x).then(M=>{$&&j(M)}).catch(M=>{$&&D(M instanceof Error?M.message:String(M))}).finally(()=>{$&&A(!1)}),()=>{$=!1}},[x]);function z(){if(l||!u)return;const $=h+1;c(!0),Qg(e,$).then(M=>{s(I=>{const G=new Set(I.map(B=>B.number));return[...I,...M.filter(B=>!G.has(B.number))]}),f(M.length===Xv),p($)}).catch(M=>b(M instanceof Error?M.message:String(M))).finally(()=>c(!1))}function O(){let $=!0;return a(!0),b(null),p(1),Qg(e,1).then(M=>{$&&(s(M),f(M.length===Xv))}).catch(M=>{$&&b(M instanceof Error?M.message:String(M))}).finally(()=>{$&&a(!1)}),()=>{$=!1}}return{prs:t,loading:i,loadingMore:l,hasMore:u,error:g,selectedNumber:x,setSelectedNumber:_,selectedPR:k,diff:E,diffLoading:N,diffError:T,loadMore:z,refresh:O}}const Zv=30;function tne(e="open"){const[t,s]=v.useState([]),[i,a]=v.useState(!0),[l,c]=v.useState(!1),[u,f]=v.useState(!1),[h,p]=v.useState(1),[g,b]=v.useState(null),[x,_]=v.useState(null),[k,C]=v.useState(null),[E,j]=v.useState([]),[N,A]=v.useState(!1),[T,D]=v.useState(null),[z,O]=v.useState(!1);v.useEffect(()=>{let G=!0;return a(!0),b(null),p(1),Jg(e,1).then(B=>{G&&(s(B),f(B.length===Zv),B.length>0&&!B.some(U=>U.number===x)&&_(B[0]?.number??null))}).catch(B=>{G&&b(B instanceof Error?B.message:String(B))}).finally(()=>{G&&a(!1)}),()=>{G=!1}},[e]),v.useEffect(()=>{if(!x){C(null),j([]);return}let G=!0;return A(!0),Promise.all([A9(x),T9(x)]).then(([B,U])=>{G&&(C(B),j(U))}).catch(()=>{}).finally(()=>{G&&A(!1)}),()=>{G=!1}},[x]);async function $(G){if(x){O(!0),D(null);try{const B=await R9(x,G);j(U=>[...U,B])}catch(B){D(B instanceof Error?B.message:String(B))}finally{O(!1)}}}function M(){if(l||!u)return;const G=h+1;c(!0),Jg(e,G).then(B=>{s(U=>{const Y=new Set(U.map(P=>P.number));return[...U,...B.filter(P=>!Y.has(P.number))]}),f(B.length===Zv),p(G)}).catch(B=>b(B instanceof Error?B.message:String(B))).finally(()=>c(!1))}function I(){let G=!0;return a(!0),p(1),Jg(e,1).then(B=>{G&&(s(B),f(B.length===Zv))}).catch(()=>{}).finally(()=>{G&&a(!1)}),()=>{G=!1}}return{issues:t,loading:i,loadingMore:l,hasMore:u,error:g,selectedNumber:x,setSelectedNumber:_,selectedIssue:k,comments:E,commentsLoading:N,commentError:T,submitting:z,addComment:$,loadMore:M,refresh:I}}function a4({deviceFlowAvailable:e,initialMode:t,onSaved:s}){const i=X(),[a,l]=v.useState(()=>t==="device-pending"&&!e?"pat":t??(e?"choose":"pat"));return a==="device-pending"?n.jsx(sne,{onSuccess:s,onCancel:()=>l("choose")}):a==="pat"?n.jsx(nne,{onSaved:s,onBack:e?()=>l("choose"):void 0}):n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[n.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[n.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-muted",children:n.jsx($S,{className:"size-6 text-muted-foreground"})}),n.jsxs("div",{children:[n.jsx("h2",{className:"text-base font-semibold",children:i("github.setup.connectTitle")}),n.jsx("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:i("github.setup.connectDesc")})]})]}),n.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-2",children:[n.jsxs(Q,{className:"w-full",onClick:()=>l("device-pending"),type:"button",children:[n.jsx($S,{className:"mr-2 size-4"}),i("github.setup.authorizeWith")]}),n.jsx("button",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",onClick:()=>l("pat"),type:"button",children:i("github.setup.usePat")})]})]})}function sne({onSuccess:e,onCancel:t}){const s=X(),[i,a]=v.useState(null),[l,c]=v.useState(null),[u,f]=v.useState(!0),[h,p]=v.useState(!1),g=v.useRef(null),b=v.useRef(5),x=v.useRef(!1);v.useEffect(()=>{let E=!0;return v9().then(j=>{if(!E)return;a(j),b.current=j.interval,f(!1);const N=j.verification_uri_complete||j.verification_uri;N&&pm(N),_(j.device_code,j.interval),setTimeout(()=>{x.current=!0},j.expires_in*1e3)}).catch(j=>{E&&(c(j instanceof Error?j.message:String(j)),f(!1))}),()=>{E=!1,g.current&&clearTimeout(g.current)}},[]);function _(E,j){g.current=setTimeout(()=>{k(E,j)},j*1e3)}async function k(E,j){if(x.current){c(s("github.setup.expired"));return}try{const N=await x9(E);if(N.done){e();return}const A=N.slowDown?j+5:j;b.current=A,_(E,A)}catch{_(E,b.current)}}function C(){i&&navigator.clipboard.writeText(i.user_code).then(()=>{p(!0),setTimeout(()=>p(!1),2e3)})}return u?n.jsx("div",{className:"flex h-full items-center justify-center",children:n.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[n.jsx(FS,{className:"size-6 animate-spin text-muted-foreground"}),n.jsx("p",{className:"text-[13px] text-muted-foreground",children:s("github.setup.requesting")})]})}):l?n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-4 p-8",children:[n.jsx(nt,{variant:"destructive",children:l}),n.jsx(Q,{onClick:t,variant:"outline",children:s("github.setup.goBack")})]}):n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[n.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[n.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-emerald-100 dark:bg-emerald-500/15",children:n.jsx(rm,{className:"size-6 text-emerald-600 dark:text-emerald-400"})}),n.jsxs("div",{children:[n.jsx("h2",{className:"text-base font-semibold",children:s("github.setup.authorizeOnTitle")}),n.jsxs("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:[s("github.setup.enterCodePre"),n.jsx("strong",{children:s("github.setup.authorizeWord")}),s("github.setup.enterCodePost")]})]})]}),n.jsxs("div",{className:"flex flex-col items-center gap-2",children:[n.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:i?.user_code}),n.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")})]}),n.jsxs("div",{className:"flex flex-col items-center gap-2",children:[n.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-muted-foreground",children:[n.jsx(FS,{className:"size-3.5 animate-spin"}),s("github.setup.waiting")]}),n.jsx("a",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",href:i?.verification_uri_complete||i?.verification_uri,rel:"noopener noreferrer",target:"_blank",children:s("github.setup.openAgain")}),n.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 nne({onSaved:e,onBack:t}){const s=X(),[i,a]=v.useState(""),[l,c]=v.useState(!1),[u,f]=v.useState(null);async function h(p){p.preventDefault();const g=i.trim();if(g){c(!0),f(null);try{await y9("github.com",g),e()}catch(b){f(b instanceof Error?b.message:String(b))}finally{c(!1)}}}return n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[n.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[n.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-muted",children:n.jsx($j,{className:"size-6 text-muted-foreground"})}),n.jsxs("div",{children:[n.jsx("h2",{className:"text-base font-semibold",children:s("github.setup.patTitle")}),n.jsxs("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:[s("github.setup.patDescPre"),n.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"),n.jsx("code",{className:"rounded bg-muted px-1 py-px text-[11px]",children:"repo"}),s("github.setup.patDescAnd"),n.jsx("code",{className:"rounded bg-muted px-1 py-px text-[11px]",children:"workflow"}),s("github.setup.patDescPost")]})]})]}),n.jsxs("form",{className:"flex w-full max-w-sm flex-col gap-3",onSubmit:p=>{h(p)},children:[n.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:p=>a(p.target.value),placeholder:"ghp_...",spellCheck:!1,type:"password",value:i}),u?n.jsx(nt,{variant:"destructive",children:u}):null,n.jsx(Q,{disabled:!i.trim()||l,type:"submit",children:s(l?"common.saving":"github.setup.saveToken")}),t?n.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 Q1({hasMore:e,loading:t,onLoadMore:s}){const i=X();return e?n.jsx("div",{className:"p-2",children:n.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?n.jsx(Bt,{className:"size-3 animate-spin"}):null,i(t?"common.loading":"github.loadMore")]})}):null}function ine({prs:e,loading:t,loadingMore:s,hasMore:i,error:a,selectedNumber:l,onSelect:c,onLoadMore:u}){const f=X();return t&&e.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.prs.loading")}):a?n.jsx("div",{className:"p-4 text-[12px] text-red-500",children:a}):e.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.prs.empty")}):n.jsxs(n.Fragment,{children:[n.jsx("ul",{className:"divide-y divide-border",children:e.map(h=>n.jsx("li",{children:n.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:[n.jsx("span",{className:"mt-0.5 shrink-0",children:n.jsx(rne,{pr:h})}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate text-[13px] font-medium",children:h.title}),n.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",h.number," · ",h.base.ref," ← ",h.head.ref," · ",h.user.login]})]}),h.draft?n.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))}),n.jsx(Q1,{hasMore:i,loading:s,onLoadMore:u})]})}function rne({pr:e}){return e.state==="merged"?n.jsx(xf,{className:"size-4 text-purple-500"}):e.state==="closed"?n.jsx(t8,{className:"size-4 text-red-500"}):n.jsx(Hj,{className:"size-4 text-emerald-500"})}function o4({body:e,title:t}){const s=X(),i=t??s("github.md.description"),[a,l]=v.useState("rendered"),c=u=>se("rounded px-1.5 py-0.5 text-[10px] font-medium transition-colors",u?"bg-foreground text-background":"text-muted-foreground hover:text-foreground");return n.jsxs("section",{className:"overflow-hidden rounded-md border border-border bg-muted/25",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[n.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:i}),n.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-background/60 p-0.5",children:[n.jsx("button",{className:c(a==="rendered"),onClick:()=>l("rendered"),type:"button",children:s("github.md.rendered")}),n.jsx("button",{className:c(a==="raw"),onClick:()=>l("raw"),type:"button",children:s("github.md.raw")})]})]}),a==="rendered"?n.jsx(K1,{content:e}):n.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap px-3 py-3 font-mono text-[12px]",children:e})]})}function ane({pr:e,diff:t,diffLoading:s,diffError:i,onMerged:a}){const l=X(),[c,u]=v.useState("cockpit"),[f,h]=v.useState(null),[p,g]=v.useState(!1),[b,x]=v.useState(null),[_,k]=v.useState(null),[C,E]=v.useState(!1),[j,N]=v.useState(null),[A,T]=v.useState(!1),{sendToAgent:D}=Vt(),{isPending:z,runOperation:O}=Yn(),$=e?`github:pr:${e.number}:merge`:"",M=$?z($):!1,I=v.useMemo(()=>nq(t),[t]);v.useEffect(()=>{N(W=>W&&I.some(re=>re.path===W)?W:I[0]?.path??null)},[I]);const G=I.find(W=>W.path===j)??I[0]??null;function B(W){N(W),u("diff")}function U(W,re){e&&(T(!1),D({prompt:re?Iq(e,re,W):Bq(e,W),source:{type:"github-pr",label:`PR #${e.number}${re?` · ${Jf(re)}`:""}`},label:`PR #${e.number}${re?` (${Jf(re)})`:""}: ${W}`}))}if(v.useEffect(()=>{if(T(!1),!e){h(null);return}let W=!0;return g(!0),x(null),C9(e.number).then(re=>{W&&h(re)}).catch(re=>{W&&x(re instanceof Error?re.message:String(re))}).finally(()=>{W&&g(!1)}),()=>{W=!1}},[e]),!e)return n.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:l("github.pr.selectPrompt")});const Y=e.state==="open"&&!e.draft;async function P(){if(!(!e||M)){k(null);try{await O({errorMessage:W=>W instanceof Error?W.message:String(W),key:$,label:l("github.pr.mergingOperation",{number:e.number})},()=>j9(e.number,{method:"squash"})),E(!1),a?.()}catch(W){k(W instanceof Error?W.message:String(W)),E(!1)}}}const V=W=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${W?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`;return n.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[n.jsxs("div",{className:"group flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-semibold",children:e.title}),n.jsx(xr,{className:se("shrink-0",A&&"opacity-100"),label:l("github.pr.askLabel",{number:e.number}),onAsk:()=>T(W=>!W)}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[n.jsx("button",{className:V(c==="cockpit"),onClick:()=>u("cockpit"),type:"button",children:l("github.pr.tabReview")}),n.jsx("button",{className:V(c==="diff"),onClick:()=>u("diff"),type:"button",children:l("github.pr.tabDiff")})]}),Y?n.jsxs(Q,{className:"shrink-0",loading:M,loadingLabel:l("github.pr.merging"),onClick:()=>E(!0),size:"sm",title:l("github.pr.squashTitle"),type:"button",variant:"success",children:[n.jsx(xf,{}),l("github.pr.squashMerge")]}):null,n.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:n.jsx(Xr,{className:"size-3.5"})})]}),_?n.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,A?n.jsx("div",{className:"shrink-0 border-b border-border px-3 py-1.5",children:n.jsx(Qr,{placeholder:l("github.pr.askPlaceholder"),onSubmit:W=>U(W),onCancel:()=>T(!1)})}):null,c==="cockpit"?n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:n.jsx(one,{cockpit:f,error:b,loading:p,onOpenFile:B,pr:e})}):s?n.jsx(vm,{className:"flex-1",label:l("git.diff.loading")}):i?n.jsx("div",{className:"p-4 text-[12px] text-red-500",children:i}):I.length?n.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1",children:[n.jsx(lne,{files:I,onAsk:(W,re)=>U(re,W),onSelect:N,selected:G?.path??null}),n.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:G?n.jsx(Yu,{diff:G.diff}):null})]}):n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:l("github.pr.noDiff")}),C?n.jsx(Xl,{confirmLabel:M?n.jsxs(n.Fragment,{children:[n.jsx(bm,{size:"sm"})," ",l("github.pr.merging")]}):l("github.pr.squashMerge"),icon:n.jsx(xf,{}),loading:M,message:n.jsxs(n.Fragment,{children:[l("github.pr.confirmPre"),n.jsxs("span",{className:"font-mono",children:["#",e.number]})," ",n.jsx("span",{className:"font-medium text-foreground",children:e.title}),l("github.pr.confirmInto"),n.jsx("span",{className:"font-mono",children:e.base.ref}),l("github.pr.confirmQ")]}),onCancel:()=>E(!1),onConfirm:()=>{P()},title:l("github.pr.squashMerge"),tone:"success"}):null]})}function one({pr:e,cockpit:t,loading:s,error:i,onOpenFile:a}){const l=X(),[c,u]=v.useState(!1),f=t?.pr??e,h=t?.files??[],p=t?.reviews??[],g=t?.comments??[],b=t?.checks??null,x=b?.runs.filter(_=>_.conclusion==="failure"||_.conclusion==="timed_out"||_.conclusion==="cancelled")??[];return n.jsxs("div",{className:"space-y-3 p-4",children:[n.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 text-[12px]",children:[n.jsx(dne,{pr:f}),n.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:[n.jsx(Mn,{className:"size-3 shrink-0 text-muted-foreground"}),f.base.ref,n.jsx(Hu,{className:"size-3 shrink-0 text-muted-foreground"}),f.head.ref]}),n.jsxs("span",{className:"inline-flex items-center gap-1 text-muted-foreground",children:[n.jsx(nO,{className:"size-3 shrink-0"}),f.user.login]}),n.jsxs("span",{className:"inline-flex items-center gap-1 text-muted-foreground",children:[n.jsx(Y6,{className:"size-3 shrink-0"}),new Date(f.created_at).toLocaleDateString()]})]}),i?n.jsx("div",{className:"rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-[12px] text-red-500",children:i}):null,s?n.jsx(vm,{className:"justify-start",label:l("github.pr.loadingCockpit")}):null,n.jsxs("div",{className:"grid gap-2 md:grid-cols-4",children:[n.jsx(Yh,{title:l("github.pr.mergeReadiness"),value:l(l4(f,b)),tone:cne(f,b)}),n.jsx(Yh,{title:l("github.pr.reviewStateTitle"),value:l(c4(p)),tone:une(p)}),n.jsx(Yh,{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"}),n.jsx(Yh,{title:l("github.pr.changedFiles"),value:String(h.length),tone:"muted"})]}),x.length>0?n.jsxs("section",{className:"rounded-md border border-red-500/25 bg-red-500/10 px-3 py-2",children:[n.jsx("div",{className:"mb-1 text-[11px] font-medium text-red-500",children:l("github.pr.failingChecks")}),n.jsx("div",{className:"flex flex-wrap gap-2",children:x.slice(0,4).map(_=>n.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:[n.jsx(A0,{className:"size-3"}),l("github.pr.openFailingCheck",{name:_.name})]},_.id))})]}):null,n.jsxs("section",{className:"rounded-md border border-border bg-muted/25 p-3",children:[n.jsxs("button",{className:"flex w-full items-center gap-2 text-[12px] font-medium",onClick:()=>u(_=>!_),type:"button",children:[c?n.jsx(kn,{className:"size-3.5 text-muted-foreground"}):n.jsx(gn,{className:"size-3.5 text-muted-foreground"}),n.jsx(T0,{className:"size-3.5 text-muted-foreground"}),l("github.pr.changedFiles"),h.length?n.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:["(",h.length,")"]}):null]}),c?h.length?n.jsx("ul",{className:"mt-2 divide-y divide-border",children:h.slice(0,12).map(_=>n.jsx("li",{children:n.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:[n.jsx("span",{className:"w-16 shrink-0 font-mono text-[10px] uppercase text-muted-foreground",children:_.status}),n.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:_.path}),n.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-emerald-600",children:["+",_.additions]}),n.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-red-500",children:["-",_.deletions]})]})},_.path))}):n.jsx("p",{className:"mt-2 text-[12px] text-muted-foreground",children:l("github.pr.noFileMeta")}):null]}),n.jsxs("section",{className:"rounded-md border border-border bg-muted/25 p-3",children:[n.jsxs("div",{className:"mb-2 flex items-center gap-2 text-[12px] font-medium",children:[n.jsx(V8,{className:"size-3.5 text-muted-foreground"}),l("github.pr.reviewStateTitle")]}),p.length||g.length?n.jsxs("div",{className:"space-y-2",children:[p.slice(-4).map(_=>n.jsx(pj,{href:_.html_url,meta:`${_.user.login} - ${_.state.toLowerCase()}`,text:_.body||l("github.pr.noReviewSummary")},`review:${_.id}`)),g.slice(-4).map(_=>n.jsx(pj,{href:_.html_url,meta:l("github.pr.reviewMetaComment",{login:_.user.login}),text:_.body},`comment:${_.id}`))]}):n.jsx("p",{className:"text-[12px] text-muted-foreground",children:l("github.pr.noReviews")})]}),f.body?n.jsx(o4,{body:f.body}):n.jsx("p",{className:"text-[12px] italic text-muted-foreground",children:l("github.noDescription")})]})}function lne({files:e,selected:t,onSelect:s,onAsk:i}){const a=X(),[l,c]=v.useState(null);return n.jsx("div",{className:"w-44 shrink-0 overflow-y-auto border-r border-border bg-card/60",children:n.jsx("ul",{className:"py-1",children:e.map(u=>n.jsxs("li",{className:"group flex flex-col",children:[n.jsxs("div",{className:se("flex items-center transition-colors",u.path===t?"bg-muted":"hover:bg-muted/60"),children:[n.jsxs("button",{className:se("flex min-w-0 flex-1 items-center gap-1.5 px-2.5 py-1.5 text-left text-[11px]",u.path===t?"text-foreground":"text-muted-foreground group-hover:text-foreground"),onClick:()=>s(u.path),title:u.path,type:"button",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:Jf(u.path)}),n.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-emerald-600",children:["+",u.additions]}),n.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-red-500",children:["-",u.deletions]})]}),n.jsx(xr,{className:se("mr-1 shrink-0",l===u.path&&"opacity-100"),label:a("github.pr.askFileLabel",{name:Jf(u.path)}),onAsk:()=>c(f=>f===u.path?null:u.path)})]}),l===u.path?n.jsx("div",{className:"px-2 pb-1.5 pt-0.5",children:n.jsx(Qr,{placeholder:a("github.pr.askFilePlaceholder"),onSubmit:f=>{c(null),i(u.path,f)},onCancel:()=>c(null)})}):null]},u.path))})})}function Jf(e){const t=e.split("/");return t[t.length-1]||e}function Yh({title:e,value:t,tone:s}){const i=s==="success"?"bg-emerald-500":s==="warning"?"bg-amber-500":s==="danger"?"bg-red-500":"bg-muted-foreground";return n.jsxs("div",{className:"rounded-md border border-border bg-card px-3 py-2",children:[n.jsx("div",{className:"text-[10px] uppercase text-muted-foreground",children:e}),n.jsxs("div",{className:"mt-1 flex items-center gap-1.5 text-[12px] font-medium",children:[n.jsx("span",{className:`size-1.5 rounded-full ${i}`}),t]})]})}function pj({meta:e,text:t,href:s}){return n.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:[n.jsxs("span",{className:"mb-1 flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[n.jsx(Xr,{className:"size-3"}),e]}),n.jsx("span",{className:"line-clamp-2 whitespace-pre-wrap",children:t})]})}function l4(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 cne(e,t){const s=l4(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 c4(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 une(e){const t=c4(e);return t==="github.pr.review.approved"?"success":t==="github.pr.review.changesRequested"?"danger":t==="github.pr.review.commented"?"warning":"muted"}function dne({pr:e}){const t=X(),{labelKey:s,dot:i,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 n.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground",children:[n.jsx("span",{className:`size-1.5 rounded-full ${i}`}),a==="merged"?n.jsx(xf,{className:"size-3"}):a==="open"?n.jsx(rm,{className:"size-3"}):n.jsx(Lo,{className:"size-3"}),t(s)]})}function u4({label:e}){return n.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 text-[10px] font-medium text-muted-foreground",title:e.name,children:[n.jsx("span",{className:"size-2 shrink-0 rounded-sm",style:{backgroundColor:`#${e.color}`}}),n.jsx("span",{className:"truncate",children:e.name})]})}function hne({issues:e,loading:t,loadingMore:s,hasMore:i,error:a,selectedNumber:l,onSelect:c,onLoadMore:u}){const f=X();return t&&e.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.issues.loading")}):a?n.jsx("div",{className:"p-4 text-[12px] text-red-500",children:a}):e.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:f("github.issues.empty")}):n.jsxs(n.Fragment,{children:[n.jsx("ul",{className:"divide-y divide-border",children:e.map(h=>n.jsx("li",{children:n.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:[n.jsx(oD,{className:`mt-0.5 size-4 shrink-0 ${h.state==="open"?"text-emerald-500":"text-red-500"}`}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate text-[13px] font-medium",children:h.title}),n.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?n.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(p=>n.jsx(u4,{label:p},p.name))}):null]})},h.number))}),n.jsx(Q1,{hasMore:i,loading:s,onLoadMore:u})]})}const Xh=6,fne=6,mne=8;function pne(e,t,s,i){const a=Math.max(0,Math.min(fne,e/2,t/2)),l=Math.max(0,Math.min(mne,s-a,i-a));return[`M ${a} 0`,`H ${e-a}`,`A ${a} ${a} 0 0 1 ${e} ${a}`,`V ${t-i-a}`,`A ${a} ${a} 0 0 1 ${e-a} ${t-i}`,`H ${e-s+l}`,`A ${l} ${l} 0 0 0 ${e-s} ${t-i+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 gne({value:e,onChange:t,placeholder:s,rows:i=3,action:a}){const l=X(),c=v.useRef(null),u=v.useRef(null),[f,h]=v.useState(null),[p,g]=v.useState({w:0,h:0});v.useLayoutEffect(()=>{const x=c.current,_=u.current;if(!x||!_)return;const k=()=>{h({w:x.clientWidth,h:x.clientHeight}),g({w:_.offsetWidth+Xh*2,h:_.offsetHeight+Xh*2})};k();const C=new ResizeObserver(k);return C.observe(x),C.observe(_),()=>C.disconnect()},[]);const b=f&&p.w&&p.h?pne(f.w,f.h,p.w,p.h):null;return n.jsxs("div",{className:"relative",ref:c,children:[n.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:x=>t(x.target.value),placeholder:s,rows:i,style:{clipPath:b?`path('${b}')`:void 0,paddingBottom:p.h||44},value:e}),f&&b?n.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:[n.jsx("title",{children:l("github.commentBorderTitle")}),n.jsx("path",{d:b,stroke:"currentColor",strokeWidth:1})]}):null,n.jsx("div",{className:"absolute",ref:u,style:{bottom:Xh,right:Xh},children:a})]})}function bne({issue:e,comments:t,commentsLoading:s,commentError:i,submitting:a,onAddComment:l}){const c=X(),[u,f]=v.useState(""),[h,p]=v.useState(!1),{sendToAgent:g}=Vt(),{isPending:b,runOperation:x}=Yn(),_=e?`github:issue:${e.number}:comment`:"",k=a||(_?b(_):!1);v.useEffect(()=>{p(!1)},[e?.number]);function C(j){e&&(p(!1),g({prompt:Hq(e,j),source:{type:"github-issue",label:`Issue #${e.number}`},label:`Issue #${e.number}: ${j}`}))}if(!e)return n.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:c("github.issue.selectPrompt")});async function E(j){if(j.preventDefault(),!e)return;const N=u.trim();N&&(await x({key:_,label:c("github.issue.postingOperation",{number:e.number})},()=>l(N)),f(""))}return n.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[n.jsxs("div",{className:"group flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-semibold",children:e.title}),n.jsx(xr,{className:se("shrink-0",h&&"opacity-100"),label:c("github.issue.askLabel",{number:e.number}),onAsk:()=>p(j=>!j)}),n.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:n.jsx(Xr,{className:"size-3.5"})})]}),h?n.jsx("div",{className:"shrink-0 border-b border-border px-3 py-1.5",children:n.jsx(Qr,{placeholder:c("github.issue.askPlaceholder"),onSubmit:C,onCancel:()=>p(!1)})}):null,n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:n.jsxs("div",{className:"space-y-3 p-4",children:[n.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[12px]",children:[n.jsxs("span",{className:"text-[11px]",children:[n.jsx("span",{className:"text-muted-foreground",children:c("github.issue.author")}),n.jsx("span",{className:"font-medium",children:e.user.login})]}),n.jsxs("span",{className:"text-[11px]",children:[n.jsx("span",{className:"text-muted-foreground",children:c("github.issue.opened")}),n.jsx("span",{className:"font-medium",children:new Date(e.created_at).toLocaleDateString()})]}),e.labels.map(j=>n.jsx(u4,{label:j},j.name))]}),e.body?n.jsx(o4,{body:e.body}):n.jsx("p",{className:"text-[12px] text-muted-foreground italic",children:c("github.noDescription")}),s?n.jsx(vm,{className:"justify-start",label:c("github.issue.loadingComments")}):n.jsx("div",{className:"space-y-2",children:t.map(j=>n.jsxs("div",{className:"rounded-md border border-border bg-muted/20 p-3",children:[n.jsxs("div",{className:"mb-1 flex items-baseline gap-2",children:[n.jsx("span",{className:"text-[11px] font-semibold",children:j.user.login}),n.jsx("span",{className:"text-[10px] text-muted-foreground",children:new Date(j.created_at).toLocaleDateString()})]}),n.jsx(K1,{content:j.body})]},j.id))})]})}),n.jsx("div",{className:"shrink-0 border-t border-border p-3",children:n.jsxs("form",{className:"flex flex-col gap-2",onSubmit:j=>{E(j)},children:[n.jsx(gne,{action:n.jsx(Q,{disabled:!u.trim(),loading:k,loadingLabel:c("github.issue.posting"),size:"sm",type:"submit",children:c("github.issue.comment")}),onChange:f,placeholder:c("github.issue.addComment"),value:u}),i?n.jsx(nt,{variant:"destructive",children:i}):null]})})]})}const gj=30,vne=4e3;function xne(e){return e.status==="in_progress"||e.status==="queued"}function bj(e){return e.map(t=>`${t.id}:${t.status}:${t.conclusion}`).join("|")}function vj(e){return e.map(t=>`${t.id}:${t.status}:${t.conclusion}:`+t.steps.map(s=>`${s.number}:${s.status}:${s.conclusion}`).join(",")).join("|")}function yne(e,t){if(e.length===0)return t;const s=new Map(t.map(c=>[c.id,c])),i=new Set(e.map(c=>c.id)),a=t.filter(c=>!i.has(c.id)),l=e.map(c=>s.get(c.id)??c);return[...a,...l]}function _ne(e){const[t,s]=v.useState([]),[i,a]=v.useState(null),[l,c]=v.useState([]),[u,f]=v.useState(!0),[h,p]=v.useState(!1),[g,b]=v.useState(!1),[x,_]=v.useState(1),[k,C]=v.useState(!1),[E,j]=v.useState(null),[N,A]=v.useState(null);function T(){let $=!0;return f(!0),j(null),_(1),Qh(e,1).then(M=>{$&&(s(M),b(M.length===gj))}).catch(M=>{$&&j(M instanceof Error?M.message:String(M))}).finally(()=>{$&&f(!1)}),()=>{$=!1}}function D(){if(h||!g)return;const $=x+1;p(!0),Qh(e,$).then(M=>{s(I=>{const G=new Set(I.map(B=>B.id));return[...I,...M.filter(B=>!G.has(B.id))]}),b(M.length===gj),_($)}).catch(M=>j(M instanceof Error?M.message:String(M))).finally(()=>p(!1))}const z=v.useCallback(()=>{Qh(e,1).then($=>s(M=>{const I=yne(M,$);return bj(M)===bj(I)?M:I})).catch(()=>{}),i&&nk(i).then($=>c(M=>vj(M)===vj($)?M:$)).catch(()=>{})},[e,i]);v.useEffect(T,[e]),v.useEffect(()=>{a($=>$&&t.some(M=>M.id===$)?$:t[0]?.id??null)},[t]),v.useEffect(()=>{if(!i){c([]);return}let $=!0;return C(!0),A(null),nk(i).then(M=>{$&&c(M)}).catch(M=>{$&&A(M instanceof Error?M.message:String(M))}).finally(()=>{$&&C(!1)}),()=>{$=!1}},[i]);const O=t.some(xne);return v.useEffect(()=>{if(!O)return;const $=window.setInterval(()=>{document.visibilityState==="visible"&&z()},vne);return()=>window.clearInterval($)},[O,z]),{runs:t,selectedRunId:i,jobs:l,loading:u,loadingMore:h,hasMore:g,jobsLoading:k,error:E,jobsError:N,loadMore:D,refresh:T,syncLatest:z,setSelectedRunId:a}}function d4(e){return e.conclusion==="failure"||e.conclusion==="timed_out"||e.conclusion==="cancelled"}function wne({branch:e,onClearBranch:t}){const{runs:s,selectedRunId:i,jobs:a,loading:l,loadingMore:c,hasMore:u,jobsLoading:f,error:h,jobsError:p,loadMore:g,refresh:b,syncLatest:x,setSelectedRunId:_}=_ne(e),k=X();$o(x);const C=s.find(T=>T.id===i)??null,{sendToAgent:E}=Vt(),[j,N]=v.useState(null);function A(T,D){N(null),E({prompt:$q(T,D),source:{type:"github-run",label:k("github.actions.runLabel",{number:T.run_number})},label:k("github.actions.runInputLabel",{number:T.run_number,input:D??k("github.actions.fixDefault")})})}return n.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[n.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("h2",{className:"text-[13px] font-semibold",children:k("github.actions.title")}),e?n.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:[n.jsx("span",{className:"shrink-0",children:k("github.actions.filteredTo")}),n.jsx("span",{className:"min-w-0 truncate font-mono",children:e}),t?n.jsx("button",{"aria-label":k("github.actions.clearFilter"),className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:t,title:k("github.actions.clearFilter"),type:"button",children:n.jsx(Gt,{className:"size-3"})}):null]}):null]}),n.jsxs(Q,{disabled:l,onClick:()=>{b()},size:"sm",type:"button",variant:"outline",children:[n.jsx(Mi,{className:`mr-1 size-3.5 ${l?"animate-spin":""}`}),k("common.refresh")]})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:h?n.jsx("div",{className:"p-4 text-[12px] text-red-500",children:h}):l&&s.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:k("github.actions.loadingRuns")}):s.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:k("github.actions.noRuns")}):n.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(280px,380px)_minmax(0,1fr)] divide-x divide-border",children:[n.jsxs("div",{className:"min-h-0 overflow-auto",children:[n.jsx("ul",{className:"divide-y divide-border",children:s.map(T=>n.jsxs("li",{className:"group flex flex-col",children:[n.jsxs("div",{className:`flex items-center transition-colors hover:bg-muted/60 ${T.id===i?"bg-muted/70":""}`,children:[n.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:[n.jsx(Sne,{run:T}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate text-[13px] font-medium",children:T.name}),n.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",T.run_number," · ",T.head_branch," · ",T.event," ·"," ",n.jsx("span",{title:new Date(T.created_at).toLocaleString(),children:z3(T.created_at)})]})]}),n.jsx(kne,{run:T})]}),d4(T)?n.jsx(xr,{className:`mr-2 shrink-0 ${j===T.id?"opacity-100":""}`,label:k("github.actions.fixRunAi",{number:T.run_number}),onAsk:()=>N(D=>D===T.id?null:T.id)}):null]}),j===T.id?n.jsx("div",{className:"px-3 pb-2 pt-0.5",children:n.jsx(Qr,{onCancel:()=>N(null),onSubmit:D=>A(T,D),placeholder:k("github.actions.askPlaceholder")})}):null]},T.id))}),n.jsx(Q1,{hasMore:u,loading:c,onLoadMore:g})]}),n.jsx(Cne,{error:p,jobs:a,loading:f,onFix:T=>A(T),run:C})]})})]})}function Sne({run:e}){return e.status==="in_progress"||e.status==="queued"?n.jsx(Lo,{className:"size-4 shrink-0 animate-pulse text-amber-400"}):e.conclusion==="success"?n.jsx(rm,{className:"size-4 shrink-0 text-emerald-500"}):e.conclusion==="failure"||e.conclusion==="timed_out"?n.jsx(A0,{className:"size-4 shrink-0 text-red-500"}):n.jsx(Lo,{className:"size-4 shrink-0 text-zinc-400"})}function kne({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 n.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[n.jsx("span",{className:`size-1.5 rounded-full ${s}`}),t]})}function Cne({run:e,jobs:t,loading:s,error:i,onFix:a}){const l=X();return e?n.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[n.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate text-[13px] font-semibold",children:e.name}),n.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["Run #",e.run_number," · ",e.head_branch," · ",e.head_sha.slice(0,7)]})]}),d4(e)?n.jsxs(Q,{className:"shrink-0 gap-1",onClick:()=>a(e),size:"sm",title:l("github.actions.fixTitle"),type:"button",variant:"outline",children:[n.jsx(cs,{className:"size-3.5"}),l("github.actions.fixWithAi")]}):null,n.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:n.jsx(Xr,{className:"size-3.5"})})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:i?n.jsx("div",{className:"p-4 text-[12px] text-red-500",children:i}):s?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:l("github.actions.loadingJobs")}):t.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:l("github.actions.noJobs")}):n.jsx("ul",{className:"divide-y divide-border",children:t.map(c=>n.jsxs("li",{className:"px-3 py-3",children:[n.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[n.jsx(xj,{item:c}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-medium",children:c.name}),n.jsx("span",{className:"shrink-0 font-mono text-[11px] text-muted-foreground",children:yj(c.started_at,c.completed_at)}),n.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:n.jsx(Xr,{className:"size-3.5"})})]}),c.steps.length?n.jsx("ol",{className:"space-y-1.5 pl-6",children:c.steps.map(u=>n.jsxs("li",{className:"flex items-center gap-2 text-[12px]",children:[n.jsx(xj,{item:u}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:u.name}),n.jsx("span",{className:"shrink-0 font-mono text-[11px] text-muted-foreground",children:yj(u.started_at,u.completed_at)})]},`${c.id}:${u.number}`))}):n.jsx("p",{className:"pl-6 text-[12px] text-muted-foreground",children:l("github.actions.noSteps")})]},c.id))})})]}):n.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:l("github.actions.selectRun")})}function xj({item:e}){return e.status==="in_progress"||e.status==="queued"?n.jsx(Lo,{className:"size-3.5 shrink-0 animate-pulse text-amber-400"}):e.conclusion==="success"||e.conclusion==="skipped"?n.jsx(rm,{className:"size-3.5 shrink-0 text-emerald-500"}):e.conclusion==="failure"||e.conclusion==="timed_out"||e.conclusion==="cancelled"?n.jsx(A0,{className:"size-3.5 shrink-0 text-red-500"}):n.jsx(Lo,{className:"size-3.5 shrink-0 text-zinc-400"})}function yj(e,t){if(!e)return"-";const s=Date.parse(e),i=t?Date.parse(t):Date.now();if(!Number.isFinite(s)||!Number.isFinite(i)||i<s)return"-";const a=Math.max(0,Math.round((i-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 Nne({onCreatePR:e,onViewRuns:t}){const s=X(),[i,a]=v.useState(null),[l,c]=v.useState(!0),[u,f]=v.useState(null);function h(){let g=!0;return c(!0),f(null),w9().then(b=>{g&&a(b)}).catch(b=>{g&&f(b instanceof Error?b.message:String(b))}).finally(()=>{g&&c(!1)}),()=>{g=!1}}v.useEffect(h,[]),$o(()=>{h()});const p=v.useMemo(()=>[...i?.branches??[]].sort((b,x)=>{const _=wj(b,i),k=wj(x,i);return _-k||b.name.localeCompare(x.name)}),[i]);return n.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[n.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("h2",{className:"text-[13px] font-semibold",children:s("github.tab.branches")}),n.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:i?.repository.full_name??s("github.selectedRepo")})]}),n.jsxs(Q,{disabled:l,onClick:()=>{h()},size:"sm",type:"button",variant:"outline",children:[n.jsx(Mi,{className:`mr-1 size-3.5 ${l?"animate-spin":""}`}),s("common.refresh")]})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:u?n.jsx("div",{className:"p-4 text-[12px] text-red-500",children:u}):l&&!i?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:s("github.branches.loading")}):p.length===0?n.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:s("github.branches.empty")}):n.jsx("ul",{className:"divide-y divide-border",children:p.map(g=>n.jsx(Ene,{branch:g,currentBranch:i?.currentBranch??null,defaultBranch:i?.defaultBranch??null,onCreatePR:e,onViewRuns:t},g.name))})})]})}function Ene({branch:e,defaultBranch:t,currentBranch:s,onCreatePR:i,onViewRuns:a}){const l=X(),c=e.name===t,u=e.name===s,f=!c;return n.jsxs("li",{className:"flex flex-wrap items-center gap-3 px-3 py-2.5",children:[n.jsx(Mn,{className:"size-4 shrink-0 text-muted-foreground"}),n.jsxs("div",{className:"min-w-48 flex-1",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx("span",{className:"truncate font-mono text-[13px] font-medium",children:e.name}),c?n.jsx(_j,{label:l("github.branches.default"),tone:"success"}):null,u?n.jsx(_j,{label:l("github.branches.current"),tone:"warning"}):null,e.protected?n.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground",children:[n.jsx(Wj,{className:"size-3"}),l("github.branches.protected")]}):null]}),n.jsx("div",{className:"mt-0.5 font-mono text-[11px] text-muted-foreground",children:e.commit.sha.slice(0,7)})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[n.jsxs(Q,{onClick:()=>a(e.name),size:"sm",title:l("github.branches.viewRunsTitle",{name:e.name}),type:"button",variant:"outline",children:[n.jsx(cD,{className:"size-3.5"}),l("github.branches.viewRuns")]}),n.jsxs(Q,{disabled:!f,onClick:()=>i(e.name),size:"sm",title:f?l("github.branches.openPrTitle",{name:e.name}):l("github.branches.defaultNoPr"),type:"button",variant:"outline",children:[n.jsx(Hj,{className:"size-3.5"}),l("github.branches.openPr")]})]})]})}function _j({label:e,tone:t}){const s=t==="success"?"bg-emerald-500":"bg-amber-500";return n.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground",children:[n.jsx("span",{className:`size-1.5 rounded-full ${s}`}),e]})}function wj(e,t){return e.name===t?.currentBranch?0:e.name===t?.defaultBranch?1:e.protected?2:3}function jne(){const e=X(),t=Jse();let s;return t.loading||t.status==="checking"?s=n.jsx(vm,{fill:!0,label:e("common.loading")}):t.status==="not_configured"?s=n.jsx(a4,{deviceFlowAvailable:t.deviceFlowAvailable,onSaved:t.refresh}):t.status==="auth_error"||t.status==="connection_error"?s=n.jsx(Ane,{token:t}):s=n.jsx(Tne,{token:t}),n.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:s})}function Ane({token:e}){const t=X(),[s,i]=v.useState(null);if(s)return n.jsx(a4,{deviceFlowAvailable:e.deviceFlowAvailable,initialMode:s,onSaved:e.refresh});const a=e.status==="auth_error";return n.jsx("div",{className:"flex h-full items-center justify-center p-8",children:n.jsxs("div",{className:"w-full max-w-lg space-y-4 rounded-md border border-border bg-card p-5",children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(Rm,{className:"size-5"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("h2",{className:"text-sm font-semibold",children:t("github.connFailed")}),n.jsx("p",{className:"text-[12px] text-muted-foreground",children:t(a?"github.tokenRejected":"github.cantValidate")})]}),n.jsx(h4,{label:t(a?"github.needsRelogin":"github.connProblem"),tone:a?"danger":"warning"})]}),e.error?n.jsx(nt,{variant:"destructive",children:e.error}):null,n.jsxs("div",{className:"flex flex-wrap gap-2",children:[n.jsxs(Q,{onClick:e.refresh,type:"button",variant:a?"outline":"default",children:[n.jsx(Mi,{}),t("common.refresh")]}),n.jsx(Q,{onClick:()=>i(e.deviceFlowAvailable?"device-pending":"pat"),type:"button",variant:a?"default":"outline",children:t("github.reconnectGithub")}),n.jsx(Q,{onClick:()=>i("pat"),type:"button",variant:"outline",children:t("github.useToken")})]})]})})}function Tne({token:e}){const t=X(),[s,i]=Pl("github:tab","prs"),[a,l]=Pl("github:pr-state","open"),[c,u]=Pl("github:issue-state","open"),[f,h]=v.useState(null),[p,g]=v.useState(null),[b,x]=v.useState(null),{isPending:_,runOperation:k}=Yn(),C=_("github:disconnect"),E=ene(a),j=tne(c);$o(()=>{s==="prs"?E.refresh():s==="issues"&&j.refresh()});const N=D=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${D?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`,A=D=>`rounded px-2 py-0.5 text-[10px] font-medium transition-colors ${D?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`;async function T(){x(null);try{await k({errorMessage:D=>D instanceof Error?D.message:String(D),key:"github:disconnect",label:t("github.disconnecting")},async()=>{await _9("github.com"),e.refresh()})}catch(D){x(D instanceof Error?D.message:String(D))}}return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border bg-card/95 px-3 py-1",children:[n.jsx("button",{className:N(s==="prs"),onClick:()=>i("prs"),type:"button",children:t("github.tab.prs")}),n.jsx("button",{className:N(s==="issues"),onClick:()=>i("issues"),type:"button",children:t("github.tab.issues")}),n.jsx("button",{className:N(s==="branches"),onClick:()=>i("branches"),type:"button",children:t("github.tab.branches")}),n.jsx("button",{className:N(s==="actions"),onClick:()=>i("actions"),type:"button",children:t("github.tab.actions")}),n.jsxs("div",{className:"ml-auto flex min-w-0 items-center gap-2",children:[n.jsx(Rne,{token:e}),n.jsxs(Q,{onClick:e.refresh,size:"sm",title:t("github.recheckTitle"),type:"button",variant:"outline",children:[n.jsx(Mi,{}),t("github.reconnect")]}),n.jsx(Q,{loading:C,loadingLabel:t("github.disconnecting"),onClick:()=>{T()},size:"sm",type:"button",variant:"outline",children:t("github.disconnect")})]}),s==="prs"?n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-muted/60 p-0.5",children:[n.jsx("button",{className:A(a==="open"),onClick:()=>l("open"),type:"button",children:t("github.open")}),n.jsx("button",{className:A(a==="closed"),onClick:()=>l("closed"),type:"button",children:t("github.closed")})]}),n.jsx(Q,{onClick:()=>h(""),size:"sm",type:"button",variant:"outline",children:t("github.newPr")})]}):s==="issues"?n.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-muted/60 p-0.5",children:[n.jsx("button",{className:A(c==="open"),onClick:()=>u("open"),type:"button",children:t("github.open")}),n.jsx("button",{className:A(c==="closed"),onClick:()=>u("closed"),type:"button",children:t("github.closed")})]}):null]}),b?n.jsx(nt,{variant:"destructive",className:"m-3",children:b}):null,f!==null?n.jsx(Mne,{initialHead:f,onCreated:D=>{h(null),i("prs"),E.setSelectedNumber(D.number),E.refresh()},onCancel:()=>h(null)}):n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s==="prs"?n.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(0,1fr)_minmax(0,2fr)] divide-x divide-border",children:[n.jsx("div",{className:"min-h-0 overflow-auto",children:n.jsx(ine,{error:E.error,hasMore:E.hasMore,loading:E.loading,loadingMore:E.loadingMore,onLoadMore:E.loadMore,onSelect:E.setSelectedNumber,prs:E.prs,selectedNumber:E.selectedNumber})}),n.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden",children:n.jsx(ane,{diff:E.diff,diffError:E.diffError,diffLoading:E.diffLoading,onMerged:()=>E.refresh(),pr:E.selectedPR})})]}):s==="issues"?n.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(0,1fr)_minmax(0,2fr)] divide-x divide-border",children:[n.jsx("div",{className:"min-h-0 overflow-auto",children:n.jsx(hne,{error:j.error,hasMore:j.hasMore,issues:j.issues,loading:j.loading,loadingMore:j.loadingMore,onLoadMore:j.loadMore,onSelect:j.setSelectedNumber,selectedNumber:j.selectedNumber})}),n.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden",children:n.jsx(bne,{commentError:j.commentError,comments:j.comments,commentsLoading:j.commentsLoading,issue:j.selectedIssue,onAddComment:j.addComment,submitting:j.submitting})})]}):s==="branches"?n.jsx(Nne,{onCreatePR:D=>h(D),onViewRuns:D=>{g(D),i("actions")}}):n.jsx(wne,{branch:p??void 0,onClearBranch:()=>g(null)})})]})}function Rne({token:e}){const t=X(),s=e.info?.repository?.full_name??(e.info?.user?`@${e.info.user.login}`:"GitHub");return n.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 border-r border-border pr-2",children:[n.jsx(Rm,{className:"size-4 shrink-0 text-foreground"}),n.jsx(h4,{label:t("github.connected"),tone:"success"}),n.jsx("span",{className:"max-w-48 truncate font-mono text-[10px] text-muted-foreground",children:s})]})}function h4({label:e,tone:t}){const s=t==="success"?"bg-emerald-500":t==="danger"?"bg-red-500":"bg-amber-500";return n.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-[11px] font-medium text-muted-foreground",children:[n.jsx("span",{className:`size-1.5 rounded-full ${s}`}),e]})}function Mne({initialHead:e,onCreated:t,onCancel:s}){const i=X(),[a,l]=v.useState(""),[c,u]=v.useState(""),[f,h]=v.useState(""),[p,g]=v.useState("main"),[b,x]=v.useState(!1),[_,k]=v.useState(null),[C,E]=v.useState(!0),[j,N]=v.useState(!1),[A,T]=v.useState(null);v.useEffect(()=>{let $=!0;return E(!0),T(null),N9().then(M=>{$&&(k(M),l(M.title),u(M.body),h(e||M.head),g(M.base||M.suggestedBase||"main"),x(M.draft))}).catch(M=>{$&&T(M instanceof Error?M.message:String(M))}).finally(()=>{$&&E(!1)}),()=>{$=!1}},[e]);async function D($){if($.preventDefault(),!(!a.trim()||!f.trim()||!p.trim())){N(!0),T(null);try{const M=await E9({title:a.trim(),body:c.trim()||void 0,head:f.trim(),base:p.trim(),draft:b});t(M)}catch(M){T(M instanceof Error?M.message:String(M))}finally{N(!1)}}}const z="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",O=_?.warnings??[];return n.jsxs("form",{className:"flex min-h-0 flex-col gap-3 overflow-auto bg-muted/20 p-4",onSubmit:$=>{D($)},children:[n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("h3",{className:"text-[13px] font-semibold",children:i("github.branchToPr")}),n.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:[_?.repository?.full_name??i("github.selectedRepo"),_?.currentBranch?` - ${_.currentBranch}`:""]})]}),n.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:i(C?"github.detectingBranch":"github.editableDraft")})]}),n.jsx(Dne,{template:_,loading:C}),O.length>0?n.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:O[0]}):null,n.jsx("input",{className:z,disabled:C,onChange:$=>l($.target.value),placeholder:i("github.fieldTitle"),required:!0,value:a}),n.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[n.jsxs("label",{className:"space-y-1",children:[n.jsx("span",{className:"text-[10px] uppercase text-muted-foreground",children:i("github.head")}),n.jsx("input",{className:z,disabled:C,onChange:$=>h($.target.value),placeholder:i("github.headBranch"),required:!0,value:f})]}),n.jsxs("label",{className:"space-y-1",children:[n.jsx("span",{className:"text-[10px] uppercase text-muted-foreground",children:i("github.base")}),n.jsx("input",{className:z,disabled:C,onChange:$=>g($.target.value),placeholder:i("github.baseBranch"),required:!0,value:p})]})]}),n.jsx("textarea",{className:`${z} resize-none`,disabled:C,onChange:$=>u($.target.value),placeholder:i("github.descriptionOptional"),rows:7,value:c}),n.jsxs("label",{className:"flex items-center gap-2 text-[12px]",children:[n.jsx("input",{checked:b,className:"size-3.5",disabled:C,onChange:$=>x($.target.checked),type:"checkbox"}),i("github.createAsDraft")]}),A?n.jsx(nt,{variant:"destructive",children:A}):null,n.jsxs("div",{className:"flex gap-2",children:[n.jsx(Q,{disabled:C||j||!a.trim()||!f.trim()||!p.trim(),type:"submit",children:i(j?"github.creating":"github.createPr")}),n.jsx(Q,{onClick:s,type:"button",variant:"outline",children:i("common.cancel")})]})]})}function Dne({template:e,loading:t}){const s=X(),i=e?.compare,a=i?.ciStatus,l=[{label:s("github.compare.base"),value:i?.base||e?.base||"main"},{label:s("github.compare.head"),value:i?.head||e?.head||"manual"},{label:s("github.compare.ahead"),value:t?"...":String(i?.aheadBy??0)},{label:s("github.compare.changed"),value:t?"...":String(i?.files.length??0)},{label:s("github.compare.ci"),value:a?`${a.state} (${a.totalCount})`:s("github.compare.unavailable")}];return n.jsxs("div",{className:"rounded-md border border-border bg-card px-3 py-2",children:[n.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[n.jsx("span",{className:"text-[11px] font-medium text-foreground",children:s("github.compareSummary")}),i?.headSha?n.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:i.headSha.slice(0,7)}):null]}),n.jsx("div",{className:"grid grid-cols-5 gap-2",children:l.map(c=>n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"truncate text-[10px] uppercase text-muted-foreground",children:c.label}),n.jsx("div",{className:"truncate font-mono text-[11px] text-foreground",children:c.value})]},c.label))}),i?.files.length?n.jsx("div",{className:"mt-2 flex flex-wrap gap-x-3 gap-y-1 text-[11px] text-muted-foreground",children:i.files.slice(0,4).map(c=>n.jsxs("span",{className:"max-w-52 truncate",children:[c.status," ",c.path]},`${c.status}:${c.path}`))}):null]})}function Lne({data:e,onRefresh:t}){const s=X(),{error:i,success:a}=gs(),[l,c]=v.useState(null),u=e.config.services,f=e.config.gitRepositories,h=GA(u,f).length;async function p(b,x){c(b);try{const{name:_}=await f9(x);await t(),a(s("git.repo.addedToast",{name:_}))}catch(_){i(_ instanceof Error?_.message:String(_))}finally{c(null)}}async function g(b,x){c(b);try{await Z9(b,x||void 0),await t(),a(s("services.project.savedToast",{name:b}))}catch(_){i(_ instanceof Error?_.message:String(_))}finally{c(null)}}return u.length===0?n.jsx("div",{className:"px-4 py-6 text-center text-xs text-muted-foreground",children:s("services.project.noServices")}):n.jsxs("div",{children:[n.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between border-b border-border bg-card px-4 py-2",children:[n.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:s("services.project.tableTitle")}),n.jsx("span",{className:"text-[11px] text-muted-foreground",children:h>0?s("services.project.countWithUnassigned",{total:u.length,unassigned:h}):s("services.project.count",{total:u.length})})]}),n.jsx("div",{className:"divide-y divide-border",children:u.map(b=>{const x=!!b.projectPath,_=f.find(C=>Zr(b.projectPath??b.cwd,C.path)),k=f.find(C=>Zr(b.cwd,C.path));return n.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_minmax(0,1.2fr)_auto] items-center gap-2 px-4 py-1.5",children:[n.jsxs("span",{className:"min-w-0",children:[n.jsx("span",{className:"block truncate text-xs font-medium leading-tight",children:b.name}),n.jsx("span",{className:"block truncate font-mono text-[10px] leading-tight text-muted-foreground",title:b.cwd,children:b.cwd})]}),n.jsxs("select",{"aria-label":s("services.project.selectAria",{name:b.name}),className:se("h-7 w-full truncate rounded-md border border-border bg-background py-0 pl-1.5 pr-6 text-[11px]",!_&&"border-amber-500/70"),disabled:l===b.name,onChange:C=>{g(b.name,C.target.value)},title:s("services.project.selectTitle"),value:b.projectPath??"",children:[n.jsx("option",{value:"",children:k?s("services.project.inferredAs",{name:k.name}):s("services.project.inferredNone")}),f.map(C=>n.jsx("option",{value:C.path,children:C.name},C.path)),x&&!_?n.jsx("option",{value:b.projectPath,children:s("services.project.missingProject",{path:b.projectPath??""})}):null]}),_?n.jsx("span",{className:"text-[10px] text-muted-foreground",children:s(x?"services.project.pinned":"services.project.inferred")}):b.cwd?n.jsxs("button",{"aria-label":s("services.project.adoptAria",{name:b.name}),className:"flex items-center gap-1 whitespace-nowrap rounded px-1 py-0.5 text-[10px] text-amber-600 transition-colors hover:bg-amber-500/10 disabled:opacity-50 dark:text-amber-500",disabled:l===b.name,onClick:()=>{p(b.name,b.cwd??"")},title:s("services.project.adoptTitle"),type:"button",children:[n.jsx(Zi,{className:"size-3.5"}),s("services.project.adopt")]}):n.jsx(Zi,{"aria-label":s("services.project.unassignedAria"),className:"size-3.5 text-amber-500"})]},b.name)})})]})}function One({data:e,onAdded:t,onCreated:s,onRefresh:i}){const a=X(),[l,c]=v.useState("path"),[u,f]=v.useState(e.git.cwd),[h,p]=v.useState(""),[g,b]=v.useState(!1),[x,_]=v.useState(""),[k,C]=v.useState(null),[E,j]=v.useState(!1),[N,A]=v.useState(null),[T,D]=v.useState(null),[z,O]=v.useState(e.git.cwd),{error:$,success:M}=gs();function I(V){const W=V instanceof Error?V.message:String(V);A(W),$(W)}async function G(V){const W=V.trim();if(!W.startsWith("/")){const re=a("git.repo.absPathError");return A(re),$(re),!1}try{const re=QR(W);return await u9(re,W),A(null),await i(),M(a("git.repo.addedToast",{name:re})),!0}catch(re){return I(re),!1}}async function B(V){V.preventDefault(),await G(u)&&t()}async function U(V){V.preventDefault();const W=h.trim();if(W){b(!0),A(null);try{const{name:re}=await d9(W);p(""),await i(),M(a("git.repo.clonedToast",{name:re})),t()}catch(re){I(re)}finally{b(!1)}}}async function Y(V){V.preventDefault();const W=x.trim();if(W){j(!0),A(null);try{const re=await h9(W,k??void 0);_(""),await i(),M(a("git.repo.createdToast",{name:re.name})),await s(re.name)}catch(re){I(re)}finally{j(!1)}}}const P=[["path",Io,a("git.repo.modeExisting")],["url",ju,a("git.repo.modeClone")],["new",Sn,a("git.repo.modeCreate")]];return n.jsxs("div",{className:"shrink-0 border-t border-border bg-muted/20 p-3",children:[n.jsxs("div",{className:"mb-1.5 flex flex-wrap items-center gap-x-2 gap-y-1",children:[n.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:a("git.repo.addSection")}),n.jsx("span",{className:"text-[11px] text-muted-foreground",children:a("git.repo.addQuestion")}),n.jsx("div",{className:"flex gap-1 text-[11px]",children:P.map(([V,W,re])=>n.jsxs("button",{className:se("flex items-center gap-1 rounded px-2 py-0.5 transition-colors",l===V?"bg-muted font-medium text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>{c(V),A(null)},type:"button",children:[n.jsx(W,{className:"size-3"}),re]},V))})]}),l==="path"?n.jsxs("form",{className:"flex gap-1.5",onSubmit:B,children:[n.jsx(St,{"aria-label":a("git.repo.pasteAbsPath"),className:"h-7 flex-1 px-2 font-mono text-[11px]",onChange:V=>{f(V.target.value),A(null)},placeholder:"/absolute/path",value:u}),n.jsxs(Q,{className:"h-7 px-2 text-[11px]",size:"sm",type:"submit",children:[n.jsx(Es,{className:"size-3"}),a("common.add")]}),n.jsx(Q,{"aria-label":a("git.repo.browseAdd"),className:"h-7 px-2",onClick:()=>{A(null),O(e.git.cwd),D("adopt")},size:"sm",type:"button",variant:"outline",children:n.jsx(vf,{className:"size-3"})})]}):l==="new"?n.jsxs("form",{className:"flex gap-1.5",onSubmit:Y,children:[n.jsx(St,{"aria-label":a("git.repo.createName"),className:"h-7 flex-1 px-2 font-mono text-[11px]",onChange:V=>{_(V.target.value),A(null)},placeholder:a("git.repo.createNamePlaceholder"),value:x}),n.jsxs(Q,{className:"h-7 px-2 text-[11px]",disabled:E||!x.trim(),size:"sm",type:"submit",children:[n.jsx(Sn,{className:"size-3"}),a(E?"git.repo.creating":"git.repo.create")]}),n.jsx(Q,{"aria-label":a("git.repo.createBrowse"),className:"h-7 px-2",onClick:()=>{A(null),O(k??e.git.cwd),D("parent")},size:"sm",title:a("git.repo.createBrowse"),type:"button",variant:"outline",children:n.jsx(vf,{className:"size-3"})})]}):n.jsxs("form",{className:"flex gap-1.5",onSubmit:U,children:[n.jsx(St,{"aria-label":a("git.repo.remoteUrl"),className:"h-7 flex-1 px-2 font-mono text-[11px]",onChange:V=>{p(V.target.value),A(null)},placeholder:"https://… or git@host:owner/repo.git",value:h}),n.jsxs(Q,{className:"h-7 px-2 text-[11px]",disabled:g||!h.trim(),size:"sm",type:"submit",children:[n.jsx(ju,{className:"size-3"}),a(g?"git.repo.cloning":"git.repo.clone")]})]}),N?n.jsx("div",{className:"mt-1.5 truncate text-[10px] text-destructive",children:N}):null,n.jsxs("div",{className:"mt-1 text-[10px] text-muted-foreground",children:[l==="path"?a("git.repo.existingHint"):null,l==="url"?a("git.repo.cloneHint"):null,l==="new"?k?a("git.repo.createIn",{path:k}):a("git.repo.createHint"):null]}),T==="adopt"?n.jsx(w0,{confirmLabel:a("git.repo.addProject"),errorMessage:N,initialPath:e.git.cwd,selectedPath:z,title:a("git.repo.addProjectTitle"),onCancel:()=>D(null),onSelect:O,onUse:async()=>{await G(z)&&(D(null),t())}}):null,T==="parent"?n.jsx(w0,{confirmLabel:a("git.repo.useThisFolder"),initialPath:k??e.git.cwd,selectedPath:z,title:a("git.repo.createParentTitle"),onCancel:()=>D(null),onSelect:O,onUse:()=>{C(z),D(null)}}):null]})}function Pne({data:e,onRemove:t,onSelect:s,onSelectAll:i,scopeAll:a}){const l=X(),c=e.git.selectedRepository;return n.jsxs("div",{className:"min-h-0 overflow-y-auto border-border sm:border-r",children:[n.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between border-b border-border bg-card px-4 py-2",children:[n.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:l("git.repo.projectsShort")}),n.jsx("span",{className:"text-[11px] text-muted-foreground",children:l("git.repo.projectsColumnHint")})]}),n.jsxs("button",{className:se("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:i,type:"button",children:[n.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(bf,{className:"size-3.5 shrink-0 text-muted-foreground"}),n.jsxs("span",{className:"min-w-0",children:[n.jsx("span",{className:"block truncate text-sm font-medium leading-tight",children:l("app.allProjects")}),n.jsx("span",{className:"block truncate text-[10px] leading-tight text-muted-foreground",children:l("app.allProjectsHint")})]})]}),a?n.jsx(rn,{className:"size-3.5"}):n.jsx("span",{className:"size-3.5"})]}),e.config.gitRepositories.length?n.jsx("div",{className:"divide-y divide-border",children:e.config.gitRepositories.map(u=>{const f=!a&&u.name===c?.name,h=e.config.services.filter(p=>Zr(p.projectPath??p.cwd,u.path)).length;return n.jsxs("div",{className:se("group grid w-full grid-cols-[1fr_auto_auto_auto] items-center gap-2 px-4 py-2 text-left transition-colors hover:bg-muted",f&&"bg-muted/70"),children:[n.jsxs("button",{className:"min-w-0 text-left",onClick:()=>s(u.name),type:"button",children:[n.jsx("span",{className:"block truncate text-sm font-medium leading-tight",children:u.name}),n.jsx("span",{className:"block truncate font-mono text-[10px] leading-tight text-muted-foreground",title:u.path,children:u.path})]}),n.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",children:h===1?l("git.repo.serviceCountOne",{count:h}):l("git.repo.serviceCount",{count:h})}),f?n.jsx(rn,{className:"size-3.5"}):n.jsx("span",{className:"size-3.5"}),n.jsx(Q,{"aria-label":l("git.repo.removeName",{name:u.name}),className:"size-6 opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>t(u.name),size:"icon",title:l("git.repo.removeName",{name:u.name}),type:"button",variant:"ghost",children:n.jsx(Xi,{className:"size-3.5 text-destructive"})})]},u.name)})}):n.jsx("div",{className:"px-4 py-6 text-center text-xs text-muted-foreground",children:l("git.repo.noProjects")})]})}function zne({data:e,onClose:t,onRefresh:s,onScopeChange:i,scopeAll:a}){const l=X(),{error:c,success:u}=gs();async function f(g){try{await f3(g),i(!1),t(),await s(),u(l("git.repo.switchedToast",{name:g}))}catch(b){c(b instanceof Error?b.message:String(b))}}function h(){i(!0),t(),u(l("app.showingAllProjects"))}async function p(g){try{await c9(g),await s(),u(l("git.repo.removedToast",{name:g}))}catch(b){c(b instanceof Error?b.message:String(b))}}return Xn.createPortal(n.jsx("div",{className:"fixed inset-0 z-[1000] grid place-items-center bg-black/35 px-4",onMouseDown:g=>{g.target===g.currentTarget&&t()},children:n.jsxs("div",{className:"flex max-h-[85vh] w-full max-w-3xl flex-col overflow-hidden rounded-xl border border-border bg-card shadow-xl",children:[n.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-4 py-3",children:[n.jsx(bf,{className:"size-4 text-muted-foreground"}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"text-sm font-semibold leading-tight",children:l("git.repo.projectsShort")}),n.jsx("div",{className:"truncate text-[10px] leading-tight text-muted-foreground",children:l("git.repo.projectsSubtitle")})]}),n.jsx(Ze,{className:"h-5 px-1.5 text-[10px]",variant:"outline",children:e.config.gitRepositories.length}),n.jsx(Q,{"aria-label":l("git.repo.closeSwitcher"),className:"ml-auto size-7",onClick:t,size:"icon",variant:"ghost",children:n.jsx(Gt,{className:"size-4"})})]}),n.jsxs("div",{className:"grid min-h-0 flex-1 grid-cols-1 overflow-hidden sm:grid-cols-2",children:[n.jsx(Pne,{data:e,onRemove:g=>{p(g)},onSelect:g=>{f(g)},onSelectAll:h,scopeAll:a}),n.jsx("div",{className:"min-h-0 overflow-y-auto border-t border-border sm:border-t-0",children:n.jsx(Lne,{data:e,onRefresh:s})})]}),n.jsx(One,{data:e,onAdded:t,onCreated:g=>f(g),onRefresh:s})]})}),document.body)}function Bne({data:e,scopeAll:t,onScopeChange:s,onRefresh:i}){const a=X(),[l,c]=v.useState(!1),[u,f]=v.useState(!1),[h,p]=v.useState({top:0,left:0}),g=v.useRef(null),b=v.useRef(null),{error:x,success:_}=gs(),k=e.git.selectedRepository,C=t?a("app.allProjects"):k?.name??a("app.pickProject"),E=t?null:e.git.status?.branch??null;function j(){const A=g.current?.getBoundingClientRect();A&&p({top:A.bottom+4,left:A.left}),c(T=>!T)}v.useEffect(()=>{if(!l)return;function A(z){const O=z.target;g.current?.contains(O)||b.current?.contains(O)||c(!1)}function T(z){z.key==="Escape"&&c(!1)}function D(z){b.current?.contains(z.target)||c(!1)}return document.addEventListener("mousedown",A),document.addEventListener("keydown",T),window.addEventListener("scroll",D,!0),()=>{document.removeEventListener("mousedown",A),document.removeEventListener("keydown",T),window.removeEventListener("scroll",D,!0)}},[l]);async function N(A){c(!1);try{await f3(A),s(!1),await i(),_(a("git.repo.switchedToast",{name:A}))}catch(T){x(T instanceof Error?T.message:String(T))}}return n.jsxs(n.Fragment,{children:[n.jsxs("button",{"aria-expanded":l,"aria-haspopup":"menu","aria-label":a("app.projectScope",{label:C}),className:se("flex h-7 min-w-0 items-center gap-1.5 rounded-md border border-transparent px-1.5 text-left transition-colors hover:border-border hover:bg-muted",l&&"border-border bg-muted"),onClick:j,ref:g,title:a("app.projectScope",{label:C}),type:"button",children:[n.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center rounded border border-border bg-background text-[10px] font-semibold",children:t?n.jsx(bf,{className:"size-3 text-muted-foreground"}):k?C.charAt(0).toUpperCase():n.jsx(j0,{className:"size-3 text-muted-foreground"})}),n.jsx("span",{className:"truncate text-sm font-medium",children:C}),E?n.jsx("span",{className:"hidden truncate font-mono text-[11px] text-muted-foreground sm:inline",children:E}):null,n.jsx(kn,{className:se("size-3.5 shrink-0 text-muted-foreground transition-transform",l&&"rotate-180")})]}),l?Xn.createPortal(n.jsxs("div",{className:"fixed z-50 flex max-h-80 min-w-56 flex-col rounded-md border border-border bg-card p-1 shadow-md",ref:b,role:"menu",style:{top:h.top,left:h.left},children:[n.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[n.jsx(Qv,{active:t,icon:n.jsx(bf,{className:"size-3.5 text-muted-foreground"}),label:a("app.allProjects"),onSelect:()=>{c(!1),s(!0),_(a("app.showingAllProjects"))}}),e.config.gitRepositories.map(A=>n.jsx(Qv,{active:!t&&k?.name===A.name,icon:n.jsx("span",{className:"flex size-3.5 items-center justify-center text-[9px] font-semibold text-muted-foreground",children:A.name.charAt(0).toUpperCase()}),label:A.name,onSelect:()=>{N(A.name)}},A.name))]}),n.jsx("div",{className:"my-1 h-px shrink-0 bg-border"}),n.jsx(Qv,{active:!1,icon:n.jsx(vf,{className:"size-3.5 text-muted-foreground"}),label:`${a("app.addManageProjects")}…`,onSelect:()=>{c(!1),f(!0)}})]}),document.body):null,u?n.jsx(zne,{data:e,onClose:()=>f(!1),onRefresh:i,onScopeChange:s,scopeAll:t}):null]})}function Qv({active:e,icon:t,label:s,onSelect:i}){return n.jsxs("button",{className:se("flex w-full shrink-0 items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs transition-colors hover:bg-muted",e&&"bg-muted/60"),onClick:i,role:"menuitem",type:"button",children:[n.jsx("span",{className:"shrink-0",children:t}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:s}),e?n.jsx(rn,{className:"size-3.5 shrink-0 text-muted-foreground"}):null]})}function Ine({ahead:e=0,behind:t=0,branches:s,currentBranch:i,disabled:a,onRefresh:l,upstream:c}){const u=X(),[f,h]=v.useState(!1),[p,g]=v.useState(""),[b,x]=v.useState(null),[_,k]=v.useState(null),[C,E]=v.useState(null),j=s.filter(M=>!M.remote),N=s.filter(M=>M.remote);async function A(M,I){x(M),E(null),k(null);try{await I(),await l()}catch(G){E(G instanceof Error?G.message:String(G))}finally{x(null)}}async function T(M){await A(`switch:${M}`,async()=>{await ji("/api/git/branches/switch",{name:M}),h(!1)})}async function D(){await A("fetch",async()=>{await ji("/api/git/fetch",{}),k(u("git.branch.fetched"))})}async function z(){await A("push",async()=>{const M=await gm();k(M.setUpstream?u("git.branch.pushedSetUpstream",{branch:M.branch}):u("git.branch.pushed",{branch:M.branch}))})}const O=!!i&&(e>0||!c&&t===0);async function $(M){M.preventDefault();const I=p.trim();if(!I){E(u("git.branch.nameRequired"));return}await A("create",async()=>{await ji("/api/git/branches",{name:I}),g(""),h(!1)})}return n.jsxs("div",{className:"fixed bottom-12 right-4 z-50 flex items-end",children:[f?n.jsxs("div",{"aria-label":u("git.branch.switchAria"),className:"mb-11 w-[min(460px,calc(100vw-2rem))] rounded-lg border border-border bg-card shadow-xl",role:"dialog",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border p-3",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(Mn,{className:"size-4 text-muted-foreground"}),n.jsx("span",{className:"truncate text-sm font-semibold",children:i||u("git.branch.branches")})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[O?n.jsxs(Q,{"aria-label":u("git.branch.pushAria"),className:"gap-1.5 px-2 text-xs",disabled:a||b!==null,onClick:()=>{z()},size:"sm",title:c?u("git.branch.pushCountTo",{ahead:e,upstream:c}):u("git.branch.pushSetUpstream"),type:"button",variant:"default",children:[n.jsx(fm,{className:se("size-3.5",b==="push"&&"animate-pulse")}),u("git.branch.push"),e>0?` ${e}`:""]}):null,n.jsx(Q,{"aria-label":u("git.branch.fetchAria"),disabled:a||b!==null,onClick:()=>{D()},size:"icon",title:u("git.branch.fetchAria"),type:"button",variant:"ghost",children:n.jsx(Mi,{className:se(b==="fetch"&&"animate-spin")})}),n.jsx(Q,{"aria-label":u("git.branch.closeAria"),onClick:()=>h(!1),size:"icon",type:"button",variant:"ghost",children:n.jsx(Gt,{})})]})]}),n.jsx("div",{className:"max-h-72 overflow-auto",children:s.length?n.jsxs(n.Fragment,{children:[n.jsx(Sj,{branches:j,busy:b!==null,disabled:a,empty:u("git.branch.noLocal"),label:u("git.branch.sectionLocal"),onSwitch:T}),n.jsx(Sj,{branches:N,busy:b!==null,disabled:a,empty:u("git.branch.noRemote"),label:u("git.branch.sectionRemote"),onSwitch:T})]}):n.jsx("div",{className:"px-3 py-6 text-center text-sm text-muted-foreground",children:u("git.branch.noneFound")})}),n.jsxs("div",{className:"border-t border-border p-3",children:[n.jsxs("form",{className:"grid gap-2 sm:grid-cols-[1fr_auto]",onSubmit:$,children:[n.jsx(St,{"aria-label":u("git.branch.newNameAria"),disabled:a||b!==null,onChange:M=>{g(M.target.value),E(null),k(null)},placeholder:"feature/new-work",value:p}),n.jsxs(Q,{disabled:a||b!==null,type:"submit",children:[n.jsx(n8,{}),u("git.branch.create")]})]}),C||_?n.jsx(nt,{className:"mt-3 px-3 py-2 text-xs",variant:C?"destructive":"muted",children:C??_}):null]})]}):null,n.jsxs(Q,{className:"h-8 max-w-[260px] gap-2 rounded-md shadow-lg",disabled:a,onClick:()=>h(M=>!M),size:"sm",title:u("git.branch.switchAria"),type:"button",variant:"default",children:[n.jsx(Mn,{className:"size-4"}),n.jsx("span",{className:"truncate font-mono text-xs",children:i||u("git.branch.noBranch")}),i&&(e>0||t>0)?n.jsxs("span",{className:"flex items-center gap-1 font-mono text-[11px] tabular-nums",title:c?u("git.branch.aheadBehindUpstream",{ahead:e,behind:t,upstream:c}):u("git.branch.aheadBehind",{ahead:e,behind:t}),children:[t>0?n.jsxs("span",{className:"flex items-center",children:[n.jsx(em,{className:"size-3"}),t]}):null,e>0?n.jsxs("span",{className:"flex items-center",children:[n.jsx(tm,{className:"size-3"}),e]}):null]}):null,n.jsx(kn,{className:se("size-4 transition-transform",f&&"rotate-180")})]})]})}function Sj({branches:e,busy:t,disabled:s,empty:i,label:a,onSwitch:l}){const c=X();return n.jsxs("section",{children:[n.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(u=>n.jsxs("button",{className:se("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",u.current&&"bg-muted/70"),disabled:s||t||u.current,onClick:()=>{l(u.name)},type:"button",children:[n.jsxs("span",{className:"min-w-0",children:[n.jsx("span",{className:"block truncate font-medium",children:u.name}),u.upstream?n.jsx("span",{className:"block truncate font-mono text-[11px] text-muted-foreground",children:c("git.branch.tracks",{upstream:u.upstream})}):null]}),n.jsx(Ze,{variant:u.current?"success":u.remote?"outline":"secondary",children:u.current?c("git.branch.tagCurrent"):u.remote?c("git.branch.tagRemote"):c("git.branch.tagLocal")})]},`${u.remote?"remote":"local"}:${u.name}`)):n.jsx("div",{className:"border-b border-border px-3 py-3 text-sm text-muted-foreground",children:i})]})}function Hne(){const e=X(),[,t]=GT(),s=VT(),i=v.useRef(null),a=v.useCallback(()=>{const l=s==="dark"?"light":"dark",c=i.current,u=document;if(!c||!u.startViewTransition||window.matchMedia("(prefers-reduced-motion: reduce)").matches){t(l);return}const f=c.getBoundingClientRect(),h=f.left+f.width/2,p=f.top+f.height/2,g=Math.hypot(Math.max(h,window.innerWidth-h),Math.max(p,window.innerHeight-p));u.startViewTransition(()=>{t(l)}).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${h}px ${p}px)`,`circle(${g}px at ${h}px ${p}px)`]},{duration:500,easing:"ease-in-out",pseudoElement:"::view-transition-new(root)"})})},[s,t]);return n.jsxs("button",{ref:i,type:"button",onClick:a,title:e(s==="dark"?"action.toLight":"action.toDark"),"aria-label":e("action.theme"),className:Mf(),children:[n.jsx("span",{className:Df(),children:s==="dark"?n.jsx(XL,{}):n.jsx(X8,{})}),n.jsx("span",{className:Lf(),children:e("action.theme")})]})}function $ne(){const e=X();return js()?n.jsxs("div",{className:"flex items-center justify-between h-8 bg-background border-b border-border select-none",style:{WebkitAppRegion:"drag"},onMouseDown:()=>pO(),children:[n.jsx("span",{className:"px-3 text-xs font-medium text-muted-foreground",children:"NoMoreIDE"}),n.jsxs("div",{className:"flex items-center",style:{WebkitAppRegion:"no-drag"},children:[n.jsx("button",{type:"button",onClick:hO,className:"h-8 w-10 flex items-center justify-center hover:bg-muted transition-colors","aria-label":e("common.minimize"),children:n.jsx(Uj,{className:"h-3 w-3"})}),n.jsx("button",{type:"button",onClick:fO,className:"h-8 w-10 flex items-center justify-center hover:bg-muted transition-colors","aria-label":e("common.maximize"),children:n.jsx($a,{className:"h-3 w-3"})}),n.jsx("button",{type:"button",onClick:mO,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:n.jsx(Gt,{className:"h-3 w-3"})})]})]}):null}const Fne=300;function Une(){const{operations:e}=Yn(),[t,s]=v.useState(!1),[i,a]=v.useState(!1),l=v.useId(),c=X();if(v.useEffect(()=>{if(e.length===0){s(!1),a(!1);return}const h=Math.min(...e.map(({startedAt:b})=>b)),p=Math.max(0,Fne-(Date.now()-h));if(p===0){s(!0);return}s(!1);const g=window.setTimeout(()=>s(!0),p);return()=>window.clearTimeout(g)},[e]),!t||e.length===0)return null;const u=e.length>1,f=u?c("operation.multiple",{count:e.length}):e[0].label;return n.jsxs("aside",{"aria-live":"polite",className:"relative z-30 mx-4 mt-2 shrink-0 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:[n.jsxs("div",{className:"flex min-h-7 items-center gap-2",children:[n.jsx(bm,{size:"sm"}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium",children:f}),u?n.jsx(Q,{"aria-controls":l,"aria-expanded":i,"aria-label":c(i?"operation.hideDetails":"operation.showDetails"),onClick:()=>a(h=>!h),size:"icon-sm",type:"button",variant:"ghost",children:n.jsx(kn,{className:se("transition-transform motion-reduce:transition-none",i&&"rotate-180")})}):null]}),u&&i?n.jsx("ul",{className:"mt-2 space-y-1 border-t border-border pt-2",id:l,children:e.map(h=>n.jsxs("li",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[n.jsx("span",{"aria-hidden":!0,className:"size-1.5 shrink-0 rounded-full bg-primary"}),n.jsx("span",{className:"truncate",children:h.label})]},h.id))}):null]})}function qne(e){const t=e===document?document.scrollingElement:e instanceof Element?e:null;if(!t)return null;const s=t.scrollHeight-t.clientHeight;return s<=0?null:Math.round(t.scrollTop/s*100)}function Gne({type:e="circle",position:t="bottom-right",color:s="hsl(var(--primary))",strokeSize:i=2,showPercentage:a=!1}){const[l,c]=v.useState(0);return v.useEffect(()=>{const u=f=>{const h=qne(f.target);h!==null&&c(h)};return document.addEventListener("scroll",u,{capture:!0,passive:!0}),()=>document.removeEventListener("scroll",u,!0)},[]),e==="bar"?n.jsx("div",{"aria-hidden":"true",className:"pointer-events-none fixed inset-x-0 top-0 z-[100]",style:{height:`${i}px`},children:n.jsx(Ro.span,{animate:{width:`${l}%`},className:"block h-full",initial:!1,style:{backgroundColor:s,boxShadow:`0 0 8px ${s}`},transition:{duration:.12,ease:"easeOut"}})}):n.jsx("div",{className:se("pointer-events-none fixed z-[100] flex items-center justify-center",{"end-0 top-0":t==="top-right","bottom-0 end-0":t==="bottom-right","start-0 top-0":t==="top-left","bottom-0 start-0":t==="bottom-left"}),children:l>0?n.jsxs(n.Fragment,{children:[n.jsxs("svg",{"aria-hidden":"true",height:"100",viewBox:"0 0 100 100",width:"100",children:[n.jsx("circle",{cx:"50",cy:"50",fill:"none",r:"30",stroke:"hsl(var(--border))",strokeWidth:i}),n.jsx(Ro.circle,{animate:{pathLength:l/100},cx:"50",cy:"50",fill:"none",initial:!1,pathLength:"1",r:"30",stroke:s,strokeWidth:i,style:{rotate:-90,transformOrigin:"center"},transition:{duration:.12,ease:"easeOut"}})]}),a?n.jsxs("span",{className:"absolute text-sm",children:[l,"%"]}):null]}):null})}const f4={services:"/",docker:"/docker",git:"/git",github:"/github",workflows:"/workflows",errors:"/errors",database:"/database",terminal:"/terminal",agent:"/agent","agent-env":"/agent-env",settings:"/settings"},Vne={services:"nav.services",docker:"nav.docker",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"},Wne=Object.entries(f4).filter(([,e])=>e!=="/").sort(([,e],[,t])=>t.length-e.length);function Kne(e){for(const[t,s]of Wne)if(e.startsWith(s))return t;return"services"}const Yne=[{labelKey:"nav.section.run",items:[{page:"services",labelKey:"nav.services",icon:n.jsx(hm,{})},{page:"docker",labelKey:"nav.docker",icon:n.jsx(am,{})},{page:"errors",labelKey:"nav.errors",icon:n.jsx($u,{})},{page:"terminal",labelKey:"nav.terminal",icon:n.jsx(wr,{})}]},{labelKey:"nav.section.code",items:[{page:"git",labelKey:"nav.git",icon:n.jsx(Mn,{})},{page:"github",labelKey:"nav.github",icon:n.jsx(Rm,{})},{page:"workflows",labelKey:"nav.workflows",icon:n.jsx(yf,{})}]},{labelKey:"nav.section.data",items:[{page:"database",labelKey:"nav.database",icon:n.jsx(hi,{})}]},{labelKey:"nav.section.agent",items:[{page:"agent",labelKey:"nav.agentConsole",icon:n.jsx(sm,{})},{page:"agent-env",labelKey:"nav.agentEnv",icon:n.jsx(Fu,{})}]}];function Xne(e=!1){return se("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 Zne(e,t=!1){return se("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 Qne(e=!1,t=!1){return se("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 Jne(e=!1){return se("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 eie({docked:e,onToggleDock:t}){return n.jsxs("div",{className:se("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:[n.jsxs("span",{className:se("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:[n.jsx("span",{children:"Made with"}),n.jsx(d8,{"aria-label":"love",className:"size-3 shrink-0 fill-red-500 text-red-500"}),n.jsx("span",{children:"by Robert Wang"}),n.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:n.jsxs("svg",{className:"size-3 fill-current",role:"img",viewBox:"0 0 24 24",children:[n.jsx("title",{children:"LinkedIn"}),n.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"})]})})]}),n.jsx("button",{"aria-label":e?"Undock sidebar":"Dock sidebar","aria-pressed":e,className:se("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?n.jsx(rL,{}):n.jsx(oL,{})})]})}function tie({className:e}){return n.jsxs("div",{className:se("min-w-0",e),children:[n.jsxs("div",{className:"flex items-baseline gap-1.5",children:[n.jsx("div",{className:"text-sm font-semibold",children:"NoMoreIDE"}),n.jsxs("div",{className:"font-mono text-[10px] text-muted-foreground",children:["v","0.1.93"]})]}),n.jsx("div",{className:"font-mono text-[11px] text-muted-foreground",children:"127.0.0.1 console"})]})}function sie({syncLocation:e=!0}={}){return n.jsx(_Z,{children:n.jsx(tq,{children:n.jsx(iie,{syncLocation:e})})})}function nie({projectPath:e,selectProject:t}){return v.useEffect(()=>{t(e)},[e,t]),null}function iie({syncLocation:e}){const t=X(),[,s]=v.useTransition(),[i,a]=v.useState(()=>e?Kne(window.location.pathname):"services"),[l,c]=v.useState(null),[u,f]=v.useState(null),[h,p]=v.useState(null),[g,b]=v.useState(0),[x,_]=v.useState({placement:"bottom",size:36}),[k,C]=v.useState(null),[E,j]=v.useState(!0),{error:N,message:A,success:T}=gs(),{ui:D,updateUi:z,selectProject:O}=Lm(),$=D.sidebarDocked,M=D.projectScope==="all",I=v.useCallback(K=>z({projectScope:K?"all":"project"}),[z]),G=v.useCallback((K,ue)=>{_(ge=>ge.placement===K&&ge.size===ue?ge:{placement:K,size:ue})},[]),B=RG(),U=v.useCallback(async(K={})=>{K.silent||j(!0),C(null);try{const ue=await V9();K.silent?s(()=>c(ue)):c(ue),K.notify&&T(t("app.dashboardRefreshed"))}catch(ue){const ge=ue instanceof Error?ue.message:String(ue);C(ge),N(ge)}finally{j(!1)}},[N,T,s,t]),Y=v.useCallback(()=>{U({notify:!0}),B.runActive()},[U,B]);v.useEffect(()=>{U()},[U]),v.useEffect(()=>{function K(){document.visibilityState==="visible"&&(U({silent:!0}),B.runActive())}const ue=window.setInterval(K,5e3);return window.addEventListener("focus",K),document.addEventListener("visibilitychange",K),()=>{window.clearInterval(ue),window.removeEventListener("focus",K),document.removeEventListener("visibilitychange",K)}},[i,U,B.runActive]),v.useEffect(()=>{if(!e)return;const K=f4[i];window.location.pathname!==K&&window.history.pushState(null,"",K)},[i,e]);const P=!M&&l?.git.selectedRepository||null,V=v.useMemo(()=>l&&P?xV(l,P):l,[l,P]),W=v.useMemo(()=>P&&V?new Set(V.config.services.map(K=>K.name)):null,[P,V]),re=v.useMemo(()=>V?Object.values(V.runtime.services).filter(K=>K.state==="running").length:0,[V]),ce=l?.git.selectedRepository?.name??l?.git.cwd??"no-git-repository",F=l?.git.selectedRepository?.path??null;return n.jsxs(bq,{children:[n.jsx(nie,{projectPath:F,selectProject:O}),n.jsx(MG,{value:B,children:n.jsx(YV,{onRefresh:()=>{U({silent:!0})},children:n.jsx(XV,{children:n.jsxs("div",{className:"flex flex-col h-screen overflow-hidden",children:[n.jsx(Gne,{type:"bar",strokeSize:2},i),n.jsx($ne,{}),n.jsxs("div",{className:"flex-1 overflow-hidden transition-[padding] duration-150",style:x.placement==="right"?{paddingRight:x.size}:{paddingBottom:x.size},children:[n.jsxs("div",{className:"mx-auto flex h-full max-w-[1500px]",children:[n.jsxs("aside",{className:Xne($),children:[n.jsxs("div",{className:se("grid h-12 grid-cols-[48px_minmax(0,1fr)] items-center overflow-hidden transition-[width] duration-150",$?"w-full":"w-12 group-hover/sidebar:w-full"),children:[n.jsx("div",{className:"flex size-12 items-center justify-center",children:n.jsx("div",{className:"flex size-9 items-center justify-center overflow-hidden rounded-md bg-primary text-primary-foreground",children:n.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:[n.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"}),n.jsx("path",{d:"M22 31L30 39L22 47",stroke:"hsl(var(--primary))",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"4.5"}),n.jsx("path",{d:"M36 47H48",stroke:"hsl(var(--primary))",strokeLinecap:"round",strokeWidth:"4.5"})]})})}),n.jsx(tie,{className:se("min-w-0 translate-x-1 overflow-hidden transition-opacity duration-200",$?"opacity-100":"opacity-0 group-hover/sidebar:opacity-100")})]}),n.jsx("nav",{className:"mt-3 flex-1 content-start overflow-y-auto overflow-x-hidden",children:Yne.map((K,ue)=>n.jsxs("div",{className:se(ue>0&&"mt-2 border-t border-border/60 pt-2"),children:[n.jsx(rie,{docked:$,label:t(K.labelKey)}),n.jsx("div",{className:"grid gap-0.5",children:K.items.map(ge=>n.jsx(kj,{active:i===ge.page,badge:ge.page==="services"?re:void 0,docked:$,icon:ge.icon,label:t(ge.labelKey),onClick:()=>a(ge.page)},ge.page))})]},K.labelKey))}),n.jsx("div",{className:"mb-1 border-t border-border/60 pt-1",children:n.jsx(kj,{active:i==="settings",docked:$,icon:n.jsx(Vj,{}),label:t("nav.settings"),onClick:()=>a("settings")})}),n.jsx(eie,{docked:$,onToggleDock:()=>z({sidebarDocked:!$})})]}),n.jsxs("main",{className:"flex h-full min-w-0 flex-1 flex-col px-0 py-0",children:[n.jsxs("header",{className:se("relative z-40 flex shrink-0 flex-wrap items-center justify-between gap-3 border border-border bg-card/90 px-3 py-1.5 backdrop-blur","border-x-0 border-t-0 border-b"),children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[n.jsx(cL,{className:"mr-1 size-4 shrink-0 text-muted-foreground md:hidden"}),l?n.jsx(Bne,{data:l,onRefresh:()=>U({silent:!0}),onScopeChange:I,scopeAll:M}):null,n.jsx(gn,{className:"size-3.5 shrink-0 text-muted-foreground/60"}),n.jsx("h1",{className:"truncate px-1 text-sm font-semibold tracking-tight",children:t(Vne[i])})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[k?n.jsx(Ze,{variant:"danger",children:k}):null,n.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:[n.jsxs("button",{"aria-label":t("action.refresh"),className:Mf(),onClick:Y,title:t("action.refreshTitle"),type:"button",children:[n.jsx("span",{className:Df(),children:n.jsx(Mi,{className:se(E&&"animate-spin")})}),n.jsx("span",{className:Lf(),children:t("action.refresh")})]}),n.jsx(Hne,{}),n.jsxs("a",{"aria-label":t("action.docsTitle"),className:Mf(),href:"https://www.nomoreide.com/docs",rel:"noreferrer",target:"_blank",title:t("action.docsTitle"),children:[n.jsx("span",{className:Df(),children:n.jsx(jj,{})}),n.jsx("span",{className:Lf(),children:t("action.docs")})]}),l?n.jsx(TV,{data:l}):null]})]})]}),n.jsx(Une,{}),l?n.jsx(QJ,{data:l,onOpenService:K=>{W&&!W.has(K)&&(I(!0),A({text:t("app.serviceOutsideScope")})),f(K),a("services"),U({silent:!0})}}):null,E&&!l?n.jsx(nt,{variant:"muted",children:t("app.loading")}):null,n.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[V&&i==="services"?n.jsx(LJ,{data:V,onRefresh:U,focusService:u,onServiceFocused:()=>f(null),scopeName:P?.name??null}):null,i==="docker"?n.jsx(YJ,{}):null,l&&i==="git"?n.jsx(Nse,{data:l,onRefresh:()=>{U({silent:!0})}}):null,i==="github"?n.jsx(jne,{},ce):null,i==="workflows"?n.jsx(Lse,{}):null,i==="agent"?n.jsx(TG,{focusChanges:g,onOpenAgentEnv:()=>a("agent-env")}):null,i==="agent-env"?n.jsx(sV,{}):null,i==="errors"?n.jsx(yQ,{inScope:W?K=>W.has(K):void 0,onReviewChanges:()=>{b(K=>K+1),a("agent")}}):null,i==="database"?n.jsx(QZ,{projects:l?.config.gitRepositories??[],scopePath:P?.path??null,staged:h,onStageConsumed:()=>p(null)}):null,i==="terminal"?n.jsx(iee,{}):null,i==="settings"?n.jsx(dQ,{activeProject:l?.git.selectedRepository??null,onNavigate:K=>a(K)}):null]})]})]}),l&&i==="git"?n.jsx(Ine,{ahead:l.git.status?.ahead??0,behind:l.git.status?.behind??0,branches:l.git.branches,currentBranch:l.git.status?.branch||void 0,disabled:!l.git.status,onRefresh:U,upstream:l.git.status?.upstream}):null,n.jsx(CZ,{currentPage:i,git:l?.git,onInsetChange:G,onNavigate:K=>a(K),onGitRefresh:()=>{U({silent:!0})}})]})]})})})})]})}function rie({docked:e,label:t}){return n.jsx("div",{className:"flex h-5 items-center overflow-hidden px-3",children:n.jsx("span",{className:se("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 kj({active:e,badge:t,docked:s,icon:i,label:a,onClick:l}){const c=t!==void 0&&t>0;return n.jsxs(Q,{"aria-label":a,title:a,className:Zne(e,s),variant:"ghost",onClick:l,type:"button",children:[n.jsx("span",{className:Jne(s),children:i}),n.jsx("span",{className:Qne(s,c),children:a}),t!==void 0&&t>0?n.jsx(Ze,{appearance:t>0?"solid":"outline",className:se("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]})}Nj.createRoot(document.getElementById("root")).render(n.jsx(v.StrictMode,{children:n.jsx(sie,{})}));export{n as j,v as r};
|