teapot-coding-agent 0.22.5 → 0.22.7

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/dist/master.js CHANGED
@@ -677,7 +677,12 @@ When this task is done (or truly blocked), call finish() with a summary for @${p
677
677
  "\n\n[Last conversation turns before finishing]\n" +
678
678
  d.recentContext.map((r) => r).join("\n\n");
679
679
  }
680
- parent.enqueuePrompt(`[harness] Sub-agent ${ac.id} finished. Final report:\n${report.slice(0, 6000) || "(no summary)"}`, "harness");
680
+ parent.enqueuePrompt(
681
+ // NO truncation: the sub's report is the parent's primary input for
682
+ // deciding what to do next. Clipping it (the old 2000/6000 caps)
683
+ // silently dropped exactly the details the operator spawned the sub
684
+ // to gather. Context management is compaction's job, not the pipe's.
685
+ `[harness] Sub-agent ${ac.id} finished. Final report:\n${report || "(no summary)"}`, "harness");
681
686
  }
682
687
  else if (e.type === "error") {
683
688
  parent.enqueuePrompt(`[harness] Sub-agent ${ac.id} hit an error: ${String(e.data.message ?? "").slice(0, 500)}`, "harness");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.22.5",
3
+ "version": "0.22.7",
4
4
  "description": "A lightweight, always-on multi-agent harness for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",
@@ -19,12 +19,12 @@ WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){t
19
19
  `&&(this._liveRegionLineCount++,this._liveRegionLineCount===pc+1&&(this._liveRegion.textContent+=Ke.get())))}_clearLiveRegion(){this._liveRegion.textContent=``,this._liveRegionLineCount=0}_handleKey(e){this._clearLiveRegion(),/\p{Control}/u.test(e)||this._charsToConsume.push(e)}_refreshRows(e,t){this._liveRegionDebouncer.refresh(e,t,this._terminal.rows)}_renderRows(e,t){let n=this._terminal.buffer,r=n.lines.length.toString();for(let i=e;i<=t;i++){let e=n.lines.get(n.ydisp+i),t=[],a=e?.translateToString(!0,void 0,void 0,t)||``,o=(n.ydisp+i+1).toString(),s=this._rowElements[i];s&&(a.length===0?(s.textContent=`\xA0`,this._rowColumns.set(s,[0,1])):(s.textContent=a,this._rowColumns.set(s,t)),s.setAttribute(`aria-posinset`,o),s.setAttribute(`aria-setsize`,r),this._alignRowWidth(s))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce=``)}_handleBoundaryFocus(e,t){let n=e.target,r=this._rowElements[t===0?1:this._rowElements.length-2];if(n.getAttribute(`aria-posinset`)===(t===0?`1`:`${this._terminal.buffer.lines.length}`)||e.relatedTarget!==r)return;let i,a;if(t===0?(i=n,a=this._rowElements.pop(),this._rowContainer.removeChild(a)):(i=this._rowElements.shift(),a=n,this._rowContainer.removeChild(i)),i.removeEventListener(`focus`,this._topBoundaryFocusListener),a.removeEventListener(`focus`,this._bottomBoundaryFocusListener),t===0){let e=this._createAccessibilityTreeNode();this._rowElements.unshift(e),this._rowContainer.insertAdjacentElement(`afterbegin`,e)}else{let e=this._createAccessibilityTreeNode();this._rowElements.push(e),this._rowContainer.appendChild(e)}this._rowElements[0].addEventListener(`focus`,this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._terminal.scrollLines(t===0?-1:1),this._rowElements[t===0?1:this._rowElements.length-2].focus(),e.preventDefault(),e.stopImmediatePropagation()}_handleSelectionChange(){if(this._rowElements.length===0)return;let e=this._coreBrowserService.mainDocument.getSelection();if(!e)return;if(e.isCollapsed){this._rowContainer.contains(e.anchorNode)&&this._terminal.clearSelection();return}if(!e.anchorNode||!e.focusNode){console.error(`anchorNode and/or focusNode are null`);return}let t={node:e.anchorNode,offset:e.anchorOffset},n={node:e.focusNode,offset:e.focusOffset};if((t.node.compareDocumentPosition(n.node)&Node.DOCUMENT_POSITION_PRECEDING||t.node===n.node&&t.offset>n.offset)&&([t,n]=[n,t]),t.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(t={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(t.node))return;let r=this._rowElements.slice(-1)[0];if(n.node.compareDocumentPosition(r)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(n={node:r,offset:r.textContent?.length??0}),!this._rowContainer.contains(n.node))return;let i=({node:e,offset:t})=>{let n=e instanceof Text?e.parentNode:e,r=parseInt(n?.getAttribute(`aria-posinset`),10)-1;if(isNaN(r))return console.warn(`row is invalid. Race condition?`),null;let i=this._rowColumns.get(n);if(!i)return console.warn(`columns is null. Race condition?`),null;let a=t<i.length?i[t]:i.slice(-1)[0]+1;return a>=this._terminal.cols&&(++r,a=0),{row:r,column:a}},a=i(t),o=i(n);if(!(!a||!o)){if(a.row>o.row||a.row===o.row&&a.column>=o.column)throw Error(`invalid range`);this._terminal.select(a.column,a.row,(o.row-a.row)*this._terminal.cols-a.column+o.column)}}_handleResize(e){this._rowElements[this._rowElements.length-1].removeEventListener(`focus`,this._bottomBoundaryFocusListener);for(let e=this._rowContainer.children.length;e<this._terminal.rows;e++)this._rowElements[e]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[e]);for(;this._rowElements.length>e;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){let e=this._coreBrowserService.mainDocument.createElement(`div`);return e.setAttribute(`role`,`listitem`),e.tabIndex=-1,this._refreshRowDimensions(e),e}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){Object.assign(this._accessibilityContainer.style,{width:`${this._renderService.dimensions.css.canvas.width}px`,fontSize:`${this._terminal.options.fontSize}px`}),this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let e=0;e<this._terminal.rows;e++)this._refreshRowDimensions(this._rowElements[e]),this._alignRowWidth(this._rowElements[e])}}_refreshRowDimensions(e){e.style.height=`${this._renderService.dimensions.css.cell.height}px`}_alignRowWidth(e){e.style.transform=``;let t=e.getBoundingClientRect().width,n=this._rowColumns.get(e)?.slice(-1)?.[0];if(!n)return;let r=n*this._renderService.dimensions.css.cell.width;e.style.transform=`scaleX(${r/t})`}};mc=R([z(1,vt),z(2,Dt),z(3,kt)],mc);var hc=class extends H{constructor(e,t,n,r,i){super(),this._element=e,this._mouseService=t,this._renderService=n,this._bufferService=r,this._linkProviderService=i,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this._register(new W),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new W),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(V(()=>{Qt(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(G(this._element,`mouseleave`,()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(G(this._element,`mousemove`,this._handleMouseMove.bind(this))),this._register(G(this._element,`mousedown`,this._handleMouseDown.bind(this))),this._register(G(this._element,`mouseup`,this._handleMouseUp.bind(this)))}get currentLink(){return this._currentLink}_handleMouseMove(e){this._lastMouseEvent=e;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);if(!t)return;this._isMouseOut=!1;let n=e.composedPath();for(let e=0;e<n.length;e++){let t=n[e];if(t.classList.contains(`xterm`))break;if(t.classList.contains(`xterm-hover`))return}(!this._lastBufferCell||t.x!==this._lastBufferCell.x||t.y!==this._lastBufferCell.y)&&(this._handleHover(t),this._lastBufferCell=t)}_handleHover(e){if(this._activeLine!==e.y||this._wasResized){this._clearCurrentLink(),this._askForLink(e,!1),this._wasResized=!1;return}this._currentLink&&this._linkAtPosition(this._currentLink.link,e)||(this._clearCurrentLink(),this._askForLink(e,!0))}_askForLink(e,t){(!this._activeProviderReplies||!t)&&(this._activeProviderReplies?.forEach(e=>{e?.forEach(e=>{e.link.dispose&&e.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=e.y);let n=!1;for(let[r,i]of this._linkProviderService.linkProviders.entries())t?this._activeProviderReplies?.get(r)&&(n=this._checkLinkProviderResult(r,e,n)):i.provideLinks(e.y,t=>{if(this._isMouseOut)return;let i=t?.map(e=>({link:e}));this._activeProviderReplies?.set(r,i),n=this._checkLinkProviderResult(r,e,n),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)})}_removeIntersectingLinks(e,t){let n=new Set;for(let r=0;r<t.size;r++){let i=t.get(r);if(i)for(let t=0;t<i.length;t++){let r=i[t],a=r.link.range.start.y<e?0:r.link.range.start.x,o=r.link.range.end.y>e?this._bufferService.cols:r.link.range.end.x;for(let e=a;e<=o;e++){if(n.has(e)){i.splice(t--,1);break}n.add(e)}}}}_checkLinkProviderResult(e,t,n){if(!this._activeProviderReplies)return n;let r=this._activeProviderReplies.get(e),i=!1;for(let t=0;t<e;t++)(!this._activeProviderReplies.has(t)||this._activeProviderReplies.get(t))&&(i=!0);if(!i&&r){let e=r.find(e=>this._linkAtPosition(e.link,t));e&&(n=!0,this._handleNewLink(e))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!n)for(let e=0;e<this._activeProviderReplies.size;e++){let r=this._activeProviderReplies.get(e)?.find(e=>this._linkAtPosition(e.link,t));if(r){n=!0,this._handleNewLink(r);break}}return n}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);t&&this._mouseDownLink&&gc(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,Qt(this._linkCacheDisposables),this._linkCacheDisposables.length=0)}_handleNewLink(e){if(!this._lastMouseEvent)return;let t=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);t&&this._linkAtPosition(e.link,t)&&(this._currentLink=e,this._currentLink.state={decorations:{underline:e.link.decorations===void 0||e.link.decorations.underline,pointerCursor:e.link.decorations===void 0||e.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,e.link,this._lastMouseEvent),e.link.decorations={},Object.defineProperties(e.link.decorations,{pointerCursor:{get:()=>this._currentLink?.state?.decorations.pointerCursor,set:e=>{this._currentLink?.state&&this._currentLink.state.decorations.pointerCursor!==e&&(this._currentLink.state.decorations.pointerCursor=e,this._currentLink.state.isHovered&&this._element.classList.toggle(`xterm-cursor-pointer`,e))}},underline:{get:()=>this._currentLink?.state?.decorations.underline,set:t=>{this._currentLink?.state&&this._currentLink?.state?.decorations.underline!==t&&(this._currentLink.state.decorations.underline=t,this._currentLink.state.isHovered&&this._fireUnderlineEvent(e.link,t))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(e=>{if(!this._currentLink)return;let t=e.start===0?0:e.start+1+this._bufferService.buffer.ydisp,n=this._bufferService.buffer.ydisp+1+e.end;if(this._currentLink.link.range.start.y>=t&&this._currentLink.link.range.end.y<=n&&(this._clearCurrentLink(t,n),this._lastMouseEvent)){let e=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);e&&this._askForLink(e,!1)}})))}_linkHover(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!0),this._currentLink.state.decorations.pointerCursor&&e.classList.add(`xterm-cursor-pointer`)),t.hover&&t.hover(n,t.text)}_fireUnderlineEvent(e,t){let n=e.range,r=this._bufferService.buffer.ydisp,i=this._createLinkUnderlineEvent(n.start.x-1,n.start.y-r-1,n.end.x,n.end.y-r-1,void 0);(t?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(i)}_linkLeave(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!1),this._currentLink.state.decorations.pointerCursor&&e.classList.remove(`xterm-cursor-pointer`)),t.leave&&t.leave(n,t.text)}_linkAtPosition(e,t){let n=e.range.start.y*this._bufferService.cols+e.range.start.x,r=e.range.end.y*this._bufferService.cols+e.range.end.x,i=t.y*this._bufferService.cols+t.x;return n<=i&&i<=r}_positionFromMouseEvent(e,t,n){let r=n.getCoords(e,t,this._bufferService.cols,this._bufferService.rows);if(r)return{x:r[0],y:r[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(e,t,n,r,i){return{x1:e,y1:t,x2:n,y2:r,cols:this._bufferService.cols,fg:i}}};hc=R([z(1,Ot),z(2,kt),z(3,mt),z(4,Nt)],hc);function gc(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 _c=class extends nc{constructor(e={}){super(e),this._linkifier=this._register(new nn),this.browser=Aa,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new nn),this._onCursorMove=this._register(new W),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new W),this.onKey=this._onKey.event,this._onRender=this._register(new W),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new W),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new W),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new W),this.onBell=this._onBell.event,this._onFocus=this._register(new W),this._onBlur=this._register(new W),this._onA11yCharEmitter=this._register(new W),this._onA11yTabEmitter=this._register(new W),this._onWillOpen=this._register(new W),this._setup(),this._decorationService=this._instantiationService.createInstance(lc),this._instantiationService.setService(Ct,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(Ta),this._instantiationService.setService(Nt,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(wt)),this._register(this._inputHandler.onRequestBell(()=>this._onBell.fire())),this._register(this._inputHandler.onRequestRefreshRows(e=>this.refresh(e?.start??0,e?.end??this.rows-1))),this._register(this._inputHandler.onRequestSendFocus(()=>this._reportFocus())),this._register(this._inputHandler.onRequestReset(()=>this.reset())),this._register(this._inputHandler.onRequestWindowsOptionsReport(e=>this._reportWindowsOptions(e))),this._register(this._inputHandler.onColor(e=>this._handleColorEvent(e))),this._register(ln.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(ln.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(ln.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(ln.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(e=>this._afterResize(e.cols,e.rows))),this._register(V(()=>{this._customKeyEventHandler=void 0,this.element?.parentNode?.removeChild(this.element)}))}get linkifier(){return this._linkifier.value}get onFocus(){return this._onFocus.event}get onBlur(){return this._onBlur.event}get onA11yChar(){return this._onA11yCharEmitter.event}get onA11yTab(){return this._onA11yTabEmitter.event}get onWillOpen(){return this._onWillOpen.event}_handleColorEvent(e){if(this._themeService)for(let t of e){let e,n=``;switch(t.index){case 256:e=`foreground`,n=`10`;break;case 257:e=`background`,n=`11`;break;case 258:e=`cursor`,n=`12`;break;default:e=`ansi`,n=`4;`+t.index}switch(t.type){case 0:let r=J.toColorRGB(e===`ansi`?this._themeService.colors.ansi[t.index]:this._themeService.colors[e]);this.coreService.triggerDataEvent(`${K.ESC}]${n};${Bs(r)}${Hi.ST}`);break;case 1:if(e===`ansi`)this._themeService.modifyColors(e=>e.ansi[t.index]=Ji.toColor(...t.color));else{let n=e;this._themeService.modifyColors(e=>e[n]=Ji.toColor(...t.color))}break;case 2:this._themeService.restoreColor(t.index)}}}_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(mc,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(K.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(K.ESC+`[O`),this.element.classList.remove(`focus`),this._onBlur.fire()}_syncTextArea(){if(!this.textarea||!this.buffer.isCursorInViewport||this._compositionHelper.isComposing||!this._renderService)return;let e=this.buffer.ybase+this.buffer.y,t=this.buffer.lines.get(e);if(!t)return;let n=Math.min(this.buffer.x,this.cols-1),r=this._renderService.dimensions.css.cell.height,i=t.getWidth(n),a=this._renderService.dimensions.css.cell.width*i,o=this.buffer.y*this._renderService.dimensions.css.cell.height,s=n*this._renderService.dimensions.css.cell.width;this.textarea.style.left=s+`px`,this.textarea.style.top=o+`px`,this.textarea.style.width=a+`px`,this.textarea.style.height=r+`px`,this.textarea.style.lineHeight=r+`px`,this.textarea.style.zIndex=`-5`}_initGlobal(){this._bindKeys(),this._register(G(this.element,`copy`,e=>{this.hasSelection()&&Je(e,this._selectionService)}));let e=e=>Ye(e,this.textarea,this.coreService,this.optionsService);this._register(G(this.textarea,`paste`,e)),this._register(G(this.element,`paste`,e)),Pa?this._register(G(this.element,`mousedown`,e=>{e.button===2&&Qe(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(G(this.element,`contextmenu`,e=>{Qe(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),Ha&&this._register(G(this.element,`auxclick`,e=>{e.button===1&&Ze(e,this.textarea,this.screenElement)}))}_bindKeys(){this._register(G(this.textarea,`keyup`,e=>this._keyUp(e),!0)),this._register(G(this.textarea,`keydown`,e=>this._keyDown(e),!0)),this._register(G(this.textarea,`keypress`,e=>this._keyPress(e),!0)),this._register(G(this.textarea,`compositionstart`,()=>this._compositionHelper.compositionstart())),this._register(G(this.textarea,`compositionupdate`,e=>this._compositionHelper.compositionupdate(e))),this._register(G(this.textarea,`compositionend`,()=>this._compositionHelper.compositionend())),this._register(G(this.textarea,`input`,e=>this._inputEvent(e),!0)),this._register(this.onRender(()=>this._compositionHelper.updateCompositionElements()))}open(e){if(!e)throw Error(`Terminal requires a parent element.`);if(e.isConnected||this._logService.debug(`Terminal.open was called on an element that was not attached to the DOM`),this.element?.ownerDocument.defaultView&&this._coreBrowserService){this.element.ownerDocument.defaultView!==this._coreBrowserService.window&&(this._coreBrowserService.window=this.element.ownerDocument.defaultView);return}this._document=e.ownerDocument,this.options.documentOverride&&this.options.documentOverride instanceof Document&&(this._document=this.optionsService.rawOptions.documentOverride),this.element=this._document.createElement(`div`),this.element.dir=`ltr`,this.element.classList.add(`terminal`),this.element.classList.add(`xterm`),e.appendChild(this.element);let t=this._document.createDocumentFragment();this._viewportElement=this._document.createElement(`div`),this._viewportElement.classList.add(`xterm-viewport`),t.appendChild(this._viewportElement),this.screenElement=this._document.createElement(`div`),this.screenElement.classList.add(`xterm-screen`),this._register(G(this.screenElement,`mousemove`,e=>this.updateCursorStyle(e))),this._helperContainer=this._document.createElement(`div`),this._helperContainer.classList.add(`xterm-helpers`),this.screenElement.appendChild(this._helperContainer),t.appendChild(this.screenElement);let n=this.textarea=this._document.createElement(`textarea`);this.textarea.classList.add(`xterm-helper-textarea`),this.textarea.setAttribute(`aria-label`,We.get()),Ua||this.textarea.setAttribute(`aria-multiline`,`false`),this.textarea.setAttribute(`autocorrect`,`off`),this.textarea.setAttribute(`autocapitalize`,`off`),this.textarea.setAttribute(`spellcheck`,`false`),this.textarea.tabIndex=0,this._register(this.optionsService.onSpecificOptionChange(`disableStdin`,()=>n.readOnly=this.optionsService.rawOptions.disableStdin)),this.textarea.readOnly=this.optionsService.rawOptions.disableStdin,this._coreBrowserService=this._register(this._instantiationService.createInstance(Ca,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<`u`?window.document:null)),this._instantiationService.setService(Dt,this._coreBrowserService),this._register(G(this.textarea,`focus`,e=>this._handleTextAreaFocus(e))),this._register(G(this.textarea,`blur`,()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(ya,this._document,this._helperContainer),this._instantiationService.setService(Et,this._charSizeService),this._themeService=this._instantiationService.createInstance(Oo),this._instantiationService.setService(Mt,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(ea),this._instantiationService.setService(jt,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(Ya,this.rows,this.screenElement)),this._instantiationService.setService(kt,this._renderService),this._register(this._renderService.onRenderedViewportChange(e=>this._onRender.fire(e))),this.onResize(e=>this._renderService.resize(e.cols,e.rows)),this._compositionView=this._document.createElement(`div`),this._compositionView.classList.add(`composition-view`),this._compositionHelper=this._instantiationService.createInstance(Ui,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(Oa),this._instantiationService.setService(Ot,this._mouseService);let r=this._linkifier.value=this._register(this._instantiationService.createInstance(hc,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(Pi,this.element,this.screenElement)),this._register(this._viewport.onRequestScrollLines(e=>{super.scrollLines(e,!1),this.refresh(0,this.rows-1)})),this._selectionService=this._register(this._instantiationService.createInstance(vo,this.element,this.screenElement,r)),this._instantiationService.setService(At,this._selectionService),this._register(this._selectionService.onRequestScrollLines(e=>this.scrollLines(e.amount,e.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(e=>this._renderService.handleSelectionChanged(e.start,e.end,e.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(e=>{this.textarea.value=e,this.textarea.focus(),this.textarea.select()})),this._register(ln.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(Fi,this.screenElement)),this._register(G(this.element,`mousedown`,e=>this._selectionService.handleMouseDown(e))),this.coreMouseService.areMouseEventsActive?(this._selectionService.disable(),this.element.classList.add(`enable-mouse-events`)):this._selectionService.enable(),this.options.screenReaderMode&&(this._accessibilityManager.value=this._instantiationService.createInstance(mc,this)),this._register(this.optionsService.onSpecificOptionChange(`screenReaderMode`,e=>this._handleScreenReaderModeOptionChange(e))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Bi,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange(`overviewRuler`,e=>{!this._overviewRulerRenderer&&e&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Bi,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(va,this,this._document,this.element,this.screenElement,this._viewportElement,this._helperContainer,this.linkifier)}bindMouse(){let e=this,t=this.element;function n(t){let n=e._mouseService.getMouseReportCoords(t,e.screenElement);if(!n)return!1;let r,i;switch(t.overrideType||t.type){case`mousemove`:i=32,t.buttons===void 0?(r=3,t.button!==void 0&&(r=t.button<3?t.button:3)):r=t.buttons&1?0:t.buttons&4?1:t.buttons&2?2:3;break;case`mouseup`:i=0,r=t.button<3?t.button:3;break;case`mousedown`:i=1,r=t.button<3?t.button:3;break;case`wheel`:if(e._customWheelEventHandler&&e._customWheelEventHandler(t)===!1)return!1;let n=t.deltaY;if(n===0||e.coreMouseService.consumeWheelEvent(t,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return!1;i=n<0?0:1,r=4;break;default:return!1}return i===void 0||r===void 0||r>4?!1:e.coreMouseService.triggerMouseEvent({col:n.col,row:n.row,x:n.x,y:n.y,button:r,action:i,ctrl:t.ctrlKey,alt:t.altKey,shift:t.shiftKey})}let r={mouseup:null,wheel:null,mousedrag:null,mousemove:null},i={mouseup:e=>(n(e),e.buttons||(this._document.removeEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.removeEventListener(`mousemove`,r.mousedrag)),this.cancel(e)),wheel:e=>(n(e),this.cancel(e,!0)),mousedrag:e=>{e.buttons&&n(e)},mousemove:e=>{e.buttons||n(e)}};this._register(this.coreMouseService.onProtocolChange(e=>{e?(this.optionsService.rawOptions.logLevel===`debug`&&this._logService.debug(`Binding to mouse events:`,this.coreMouseService.explainEvents(e)),this.element.classList.add(`enable-mouse-events`),this._selectionService.disable()):(this._logService.debug(`Unbinding from mouse events.`),this.element.classList.remove(`enable-mouse-events`),this._selectionService.enable()),e&8?r.mousemove||=(t.addEventListener(`mousemove`,i.mousemove),i.mousemove):(t.removeEventListener(`mousemove`,r.mousemove),r.mousemove=null),e&16?r.wheel||=(t.addEventListener(`wheel`,i.wheel,{passive:!1}),i.wheel):(t.removeEventListener(`wheel`,r.wheel),r.wheel=null),e&2?r.mouseup||=i.mouseup:(this._document.removeEventListener(`mouseup`,r.mouseup),r.mouseup=null),e&4?r.mousedrag||=i.mousedrag:(this._document.removeEventListener(`mousemove`,r.mousedrag),r.mousedrag=null)})),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this._register(G(t,`mousedown`,e=>{if(e.preventDefault(),this.focus(),!(!this.coreMouseService.areMouseEventsActive||this._selectionService.shouldForceSelection(e)))return n(e),r.mouseup&&this._document.addEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.addEventListener(`mousemove`,r.mousedrag),this.cancel(e)})),this._register(G(t,`wheel`,t=>{if(!r.wheel){if(this._customWheelEventHandler&&this._customWheelEventHandler(t)===!1)return!1;if(!this.buffer.hasScrollback){if(t.deltaY===0)return!1;if(e.coreMouseService.consumeWheelEvent(t,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return this.cancel(t,!0);let n=K.ESC+(this.coreService.decPrivateModes.applicationCursorKeys?`O`:`[`)+(t.deltaY<0?`A`:`B`);return this.coreService.triggerDataEvent(n,!0),this.cancel(t,!0)}}},{passive:!1}))}refresh(e,t){this._renderService?.refreshRows(e,t)}updateCursorStyle(e){this._selectionService?.shouldColumnSelect(e)?this.element.classList.add(`column-select`):this.element.classList.remove(`column-select`)}_showCursor(){this.coreService.isCursorInitialized||(this.coreService.isCursorInitialized=!0,this.refresh(this.buffer.y,this.buffer.y))}scrollLines(e,t){this._viewport?this._viewport.scrollLines(e):super.scrollLines(e,t),this.refresh(0,this.rows-1)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){e&&this._viewport?this._viewport.scrollToLine(this.buffer.ybase,!0):this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}paste(e){Xe(e,this.textarea,this.coreService,this.optionsService)}attachCustomKeyEventHandler(e){this._customKeyEventHandler=e}attachCustomWheelEventHandler(e){this._customWheelEventHandler=e}registerLinkProvider(e){return this._linkProviderService.registerLinkProvider(e)}registerCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);let t=this._characterJoinerService.register(e);return this.refresh(0,this.rows-1),t}deregisterCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);this._characterJoinerService.deregister(e)&&this.refresh(0,this.rows-1)}get markers(){return this.buffer.markers}registerMarker(e){return this.buffer.addMarker(this.buffer.ybase+this.buffer.y+e)}registerDecoration(e){return this._decorationService.registerDecoration(e)}hasSelection(){return this._selectionService?this._selectionService.hasSelection:!1}select(e,t,n){this._selectionService.setSelection(e,t,n)}getSelection(){return this._selectionService?this._selectionService.selectionText:``}getSelectionPosition(){if(!(!this._selectionService||!this._selectionService.hasSelection))return{start:{x:this._selectionService.selectionStart[0],y:this._selectionService.selectionStart[1]},end:{x:this._selectionService.selectionEnd[0],y:this._selectionService.selectionEnd[1]}}}clearSelection(){this._selectionService?.clearSelection()}selectAll(){this._selectionService?.selectAll()}selectLines(e,t){this._selectionService?.selectLines(e,t)}_keyDown(e){if(this._keyDownHandled=!1,this._keyDownSeen=!0,this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;let t=this.browser.isMac&&this.options.macOptionIsMeta&&e.altKey;if(!t&&!this._compositionHelper.keydown(e))return this.options.scrollOnUserInput&&this.buffer.ybase!==this.buffer.ydisp&&this.scrollToBottom(!0),!1;!t&&(e.key===`Dead`||e.key===`AltGraph`)&&(this._unprocessedDeadKey=!0);let n=ic(e,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(e),n.type===3||n.type===2){let t=this.rows-1;return this.scrollLines(n.type===2?-t:t),this.cancel(e,!0)}if(n.type===1&&this.selectAll(),this._isThirdLevelShift(this.browser,e)||(n.cancel&&this.cancel(e,!0),!n.key)||e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.key.length===1&&e.key.charCodeAt(0)>=65&&e.key.charCodeAt(0)<=90)return!0;if(this._unprocessedDeadKey)return this._unprocessedDeadKey=!1,!0;if((n.key===K.ETX||n.key===K.CR)&&(this.textarea.value=``),this._onKey.fire({key:n.key,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(n.key,!0),!this.optionsService.rawOptions.screenReaderMode||e.altKey||e.ctrlKey)return this.cancel(e,!0);this._keyDownHandled=!0}_isThirdLevelShift(e,t){let n=e.isMac&&!this.options.macOptionIsMeta&&t.altKey&&!t.ctrlKey&&!t.metaKey||e.isWindows&&t.altKey&&t.ctrlKey&&!t.metaKey||e.isWindows&&t.getModifierState(`AltGraph`);return t.type===`keypress`?n:n&&(!t.keyCode||t.keyCode>47)}_keyUp(e){this._keyDownSeen=!1,!(this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)&&(vc(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(Io));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(K.ESC+`[I`):this.coreService.triggerDataEvent(K.ESC+`[O`)}_reportWindowsOptions(e){if(this._renderService)switch(e){case 0:let e=this._renderService.dimensions.css.canvas.width.toFixed(0),t=this._renderService.dimensions.css.canvas.height.toFixed(0);this.coreService.triggerDataEvent(`${K.ESC}[4;${t};${e}t`);break;case 1:let n=this._renderService.dimensions.css.cell.width.toFixed(0),r=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${K.ESC}[6;${r};${n}t`);break}}cancel(e,t){if(!(!this.options.cancelEvents&&!t))return e.preventDefault(),e.stopPropagation(),!1}};function vc(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}var yc=class{constructor(){this._addons=[]}dispose(){for(let e=this._addons.length-1;e>=0;e--)this._addons[e].instance.dispose()}loadAddon(e,t){let n={instance:t,dispose:t.dispose,isDisposed:!1};this._addons.push(n),t.dispose=()=>this._wrappedAddonDispose(n),t.activate(e)}_wrappedAddonDispose(e){if(e.isDisposed)return;let t=-1;for(let n=0;n<this._addons.length;n++)if(this._addons[n]===e){t=n;break}if(t===-1)throw Error(`Could not dispose an addon that has not been loaded`);e.isDisposed=!0,e.dispose.apply(e.instance),this._addons.splice(t,1)}},bc=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 st)}translateToString(e,t,n){return this._line.translateToString(e,t,n)}},xc=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 bc(t)}getNullCell(){return new st}},Sc=class extends H{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new W),this.onBufferChange=this._onBufferChange.event,this._normal=new xc(this._core.buffers.normal,`normal`),this._alternate=new xc(this._core.buffers.alt,`alternate`),this._core.buffers.onBufferActivate(()=>this._onBufferChange.fire(this.active))}get active(){if(this._core.buffers.active===this._core.buffers.normal)return this.normal;if(this._core.buffers.active===this._core.buffers.alt)return this.alternate;throw Error(`Active buffer is neither normal nor alternate`)}get normal(){return this._normal.init(this._core.buffers.normal)}get alternate(){return this._alternate.init(this._core.buffers.alt)}},Cc=class{constructor(e){this._core=e}registerCsiHandler(e,t){return this._core.registerCsiHandler(e,e=>t(e.toArray()))}addCsiHandler(e,t){return this.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._core.registerDcsHandler(e,(e,n)=>t(e,n.toArray()))}addDcsHandler(e,t){return this.registerDcsHandler(e,t)}registerEscHandler(e,t){return this._core.registerEscHandler(e,t)}addEscHandler(e,t){return this.registerEscHandler(e,t)}registerOscHandler(e,t){return this._core.registerOscHandler(e,t)}addOscHandler(e,t){return this.registerOscHandler(e,t)}},wc=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}},Tc=[`cols`,`rows`],Ec=0,Dc=class extends H{constructor(e){super(),this._core=this._register(new _c(e)),this._addonManager=this._register(new yc),this._publicOptions={...this._core.options};let t=e=>this._core.options[e],n=(e,t)=>{this._checkReadonlyOptions(e),this._core.options[e]=t};for(let e in this._core.options){let r={get:t.bind(this,e),set:n.bind(this,e)};Object.defineProperty(this._publicOptions,e,r)}}_checkReadonlyOptions(e){if(Tc.includes(e))throw Error(`Option "${e}" can only be set in the constructor`)}_checkProposedApi(){if(!this._core.optionsService.rawOptions.allowProposedApi)throw Error(`You must set the allowProposedApi option to true to use proposed API`)}get onBell(){return this._core.onBell}get onBinary(){return this._core.onBinary}get onCursorMove(){return this._core.onCursorMove}get onData(){return this._core.onData}get onKey(){return this._core.onKey}get onLineFeed(){return this._core.onLineFeed}get onRender(){return this._core.onRender}get onResize(){return this._core.onResize}get onScroll(){return this._core.onScroll}get onSelectionChange(){return this._core.onSelectionChange}get onTitleChange(){return this._core.onTitleChange}get onWriteParsed(){return this._core.onWriteParsed}get element(){return this._core.element}get parser(){return this._parser||=new Cc(this._core),this._parser}get unicode(){return this._checkProposedApi(),new wc(this._core)}get textarea(){return this._core.textarea}get rows(){return this._core.rows}get cols(){return this._core.cols}get buffer(){return this._buffer||=this._register(new Sc(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`}return{applicationCursorKeysMode:e.applicationCursorKeys,applicationKeypadMode:e.applicationKeypad,bracketedPasteMode:e.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:t,originMode:e.origin,reverseWraparoundMode:e.reverseWraparound,sendFocusMode:e.sendFocus,synchronizedOutputMode:e.synchronizedOutput,wraparoundMode:e.wraparound}}get options(){return this._publicOptions}set options(e){for(let t in e)this._publicOptions[t]=e[t]}blur(){this._core.blur()}focus(){this._core.focus()}input(e,t=!0){this._core.input(e,t)}resize(e,t){this._verifyIntegers(e,t),this._core.resize(e,t)}open(e){this._core.open(e)}attachCustomKeyEventHandler(e){this._core.attachCustomKeyEventHandler(e)}attachCustomWheelEventHandler(e){this._core.attachCustomWheelEventHandler(e)}registerLinkProvider(e){return this._core.registerLinkProvider(e)}registerCharacterJoiner(e){return this._checkProposedApi(),this._core.registerCharacterJoiner(e)}deregisterCharacterJoiner(e){this._checkProposedApi(),this._core.deregisterCharacterJoiner(e)}registerMarker(e=0){return this._verifyIntegers(e),this._core.registerMarker(e)}registerDecoration(e){return this._checkProposedApi(),this._verifyPositiveIntegers(e.x??0,e.width??0,e.height??0),this._core.registerDecoration(e)}hasSelection(){return this._core.hasSelection()}select(e,t,n){this._verifyIntegers(e,t,n),this._core.select(e,t,n)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(e,t){this._verifyIntegers(e,t),this._core.selectLines(e,t)}dispose(){super.dispose()}scrollLines(e){this._verifyIntegers(e),this._core.scrollLines(e)}scrollPages(e){this._verifyIntegers(e),this._core.scrollPages(e)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(e){this._verifyIntegers(e),this._core.scrollToLine(e)}clear(){this._core.clear()}write(e,t){this._core.write(e,t)}writeln(e,t){this._core.write(e),this._core.write(`\r
20
20
  `,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 We.get()},set promptLabel(e){We.set(e)},get tooMuchOutput(){return Ke.get()},set tooMuchOutput(e){Ke.set(e)}}}_verifyIntegers(...e){for(Ec of e)if(Ec===1/0||isNaN(Ec)||Ec%1!=0)throw Error(`This API only accepts integers`)}_verifyPositiveIntegers(...e){for(Ec of e)if(Ec&&(Ec===1/0||isNaN(Ec)||Ec%1!=0||Ec<0))throw Error(`This API only accepts positive integers`)}},Oc=2,kc=1,Ac=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(Oc,Math.floor(u/e.css.cell.width)),rows:Math.max(kc,Math.floor(l/e.css.cell.height))}}},jc=`modulepreload`,Mc=function(e){return`/`+e},Nc={},Pc=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Mc(t,n),t=s(t),t in Nc)return;Nc[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:jc,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Fc=P(`<div class=overlay><div class=modal style=max-width:360px><div class=modal-head><b>🔒 sign in</b><span></span></div><form style=display:flex;flex-direction:column;gap:10px><input id=pw-input type=password placeholder=password autofocus><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:7px 12px;cursor:pointer">unlock</button><span class=muted style=font-size:11px>the token is stored locally and sent as Bearer to this server only`),Ic=P(`<div class=themegrid>`),Lc=P(`<div class=themepop><label class=trow title="switch automatically when the OS switches appearance — pick which theme to use for each"><input type=checkbox>follow system`),Rc=P(`<i class=notifdot>`),zc=P(`<br>`),Bc=P(`<span class="badge queued">⏳ <!> of yours queued`),Vc=P(`<span class="badge cron">⏰ `),Hc=P(`<span class=sub>ℹ`),Uc=P(`<header class=chan-head><span class=hash>#</span><span class=title></span><span></span><span class=sub> · <!>/<!> · turns <!> · tools </span><span style=margin-left:auto;display:flex;gap:4px>`),Wc=P(`<div class=divider-msg>── beginning of log ──`),Gc=P(`<div class=divider-msg>loading older events…`),Kc=P(`<details class=reasoning open><summary>💭 thinking </summary><div class="mono thinkscroll">`),qc=P(`<div class=muted style=font-size:11.5px;margin-bottom:4px>🗜 summarizing older context…`),Jc=P(`<div class=content>`),Yc=P(`<div class="msg live"><div class=avatar style="background:#5865f233;border:1px solid #5865f266">🫖</div><div class=msg-body><div class=msg-head><span class=author style=color:var(--acc)>agent</span><span class=ts>streaming…`),Xc=P(`<div class=feed>`),Zc=P(`<div class="termempty muted">no shell here — + opens one, tabs fill the focused pane`),Qc=P(`<div class=termsplit>`),$c=P(`<div class="termempty muted">no shell here — click a tab or + to add`),el=P(`<div class=termpane>`),tl=P(`<div class=termdrawer><div class=termgrip title="drag to resize · double-click to reset"></div><div class=termbar><div class=termtabs></div><div style=display:flex;gap:4px;align-items:center><span class="muted mono"style=flex:1;text-align:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap></span></div></div><div class=termbody><div class=termpane>`),nl=P(`<button class=jump>↓ `),rl=P(`<div class=cmds>`),il=P(`<div class=imgstage><span class=muted style=font-size:11px;align-self:center> image<!> attached`),al=P(`<label class=forkchip title="inherit the conversation prefix byte-exactly — the sub-agent's provider prefix cache starts warm"><input type=checkbox>fork ctx`),ol=P(`<span class=muted style=font-size:11.5px;white-space:nowrap>🖼 `),sl=P(`<div><form><textarea rows=1></textarea><button type=button class="iconbtn maxbtn"></button><button type=submit>send</button><input id=composer-file type=file accept=image/* multiple style=display:none></form><div class=hint>`),cl=P(`<h3 title="identity + storage locations for this agent">🎛 session`),ll=P(`<div class="card sesscard"><div class=sessrow><span class=k>agent</span><b></b><span></span></div><div class=sessrow><span class=k>workspace</span><span class="mono ellip"></span></div><div class=sessrow><span class=k>session</span><span class=mono>/`),ul=P(`<h3 title="switch provider/model live — applies from the agent's next turn; the list shows context window &amp; pricing from the provider">🧦 model`),dl=P(`<div class=meta style=color:var(--fg)>`),fl=P(`<div class=modelbox><select title="provider (OpenAI-compatible endpoint)"></select><div style=display:flex;gap:4px><input type=text list=model-list style=flex:1;min-width:0><datalist id=model-list></datalist><button title="apply to this session — takes effect from the agent's next turn">apply</button></div><div class=meta>current: `),pl=P(`<h3>⏯ controls`),ml=P(`<button title="stop every sub-agent this agent spawned (descendants included)">⏹ subs`),hl=P(`<div class=btnrow><button></button><button title="branch off the conversation here — try things without disturbing the main line">⑂ fork</button><button title="remove agent from teapot (session log stays on disk)">🗑 remove`),gl=P(`<div class=ctrlrow><label title="auto-continue fires after a round ONLY when all hold: ① this toggle is on ② a goal is set and its status is 'active' ③ the round ended cleanly (no error / not stopped). It stops when the goal is marked done, or if you press ■ stop. Sending any prompt also starts an idle agent regardless."><input type=checkbox>auto-continue</label><span class=muted>loops while goal is active · stops on done / stop`),_l=P(`<span>`),vl=P(`<h3 title="what the agent is working toward — auto-continue keeps looping while the status is 'active'">🎯 goal`),yl=P(`<div class=statrow style=margin-bottom:6px><span class=k>status`),bl=P(`<div class=card><div class=content>`),xl=P(`<div class="card verifycard"title="verification contract — finish(goalComplete=true) is audited against these requirements by an independent reviewer before the goal counts as done"><div class=vtitle>🔍 verification contract</div><div class=content>`),Sl=P(`<div class=muted style=font-size:11px;margin-top:4px>stored with the session · the agent reads it via get_goal() · auto-continue loops while status is "working" and stops when marked done`),Cl=P(`<form style=display:flex;flex-direction:column;gap:6px;margin-top:8px;margin-bottom:6px><textarea id=goal-input rows=3 placeholder="set new goal…"style="background:var(--bg-darkest);border:none;border-radius:6px;padding:6px 8px;color:var(--fg);font:inherit;width:100%;resize:vertical"></textarea><textarea id=goal-verify-input rows=2 placeholder="verification contract (optional) — e.g. 'npm test passes; endpoint documented'. finish(goalComplete=true) is then audited against this."title="pi-goal-x-style verification contract — an independent reviewer checks the agent's finish against these requirements"style="background:var(--bg-darkest);border:1px solid var(--bg-light);border-radius:6px;padding:6px 8px;color:var(--fg);font:inherit;font-size:12.5px;width:100%;resize:vertical"></textarea><div style=display:flex;justify-content:flex-end;align-items:center;gap:10px><label class=muted title="queue a harness prompt telling the agent about the new goal at its next turn boundary"style=display:flex;align-items:center;gap:4px;font-size:11.5px;white-space:nowrap;cursor:pointer><input id=goal-notify type=checkbox> notify agent</label><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:4px 12px;cursor:pointer">✓ save goal`),wl=P(`<span class=badge>/<!> done`),Tl=P(`<h3 title="todo.md — a shared checklist in the session dir. Write tasks like '- [ ] fix login'; the agent ticks them off via set_todo, you edit here. With notify on, it's told at its next turn boundary.">✅ tasks<span class=muted style=text-transform:none;letter-spacing:0>· shared checklist (you + agent)`),El=P(`<div class=bartrack style=margin-bottom:6px><div>`),Dl=P(`<textarea id=todo-input class=mono rows=5 placeholder="- task one
21
21
  - task two"title="shared with the agent — it may check items off via set_todo; your unsaved edits win until you save"style="width:100%;background:var(--bg-darkest);border:none;border-radius:6px;padding:6px 8px;color:var(--fg);font-family:ui-monospace,Menlo,monospace;font-size:12.5px;resize:vertical">`),Ol=P(`<div style=display:flex;justify-content:flex-end;align-items:center;gap:10px;margin-top:4px><label class=muted title="queue a harness prompt telling the agent the task list changed"style=display:flex;align-items:center;gap:4px;font-size:11.5px;white-space:nowrap;cursor:pointer><input id=todo-notify type=checkbox checked> notify agent</label><button style="background:var(--ok);border:none;border-radius:6px;color:#fff;padding:4px 12px;cursor:pointer">✓ save tasks`),kl=P(`<h3 title="latest report_progress snapshot. The harness asks for one after real activity (time AND output gates); errors show under ⚠ problems">📈 progress`),Al=P(`<h3 title="cumulative billed totals · the cached pill counts tokens served from the provider's prompt cache (far cheaper) · context bar turns orange ≥70% and red ≥85% of the model window">📊 runtime`),jl=P(`<span class="pill ok">⚡ <!>% cached`),Ml=P(`<div class=statrow><span class=k>cost</span><b>$`),Nl=P(`<div class="card runcard"><div class=statgrid><div class=stat title="LLM turns taken this session"><span>turns</span><b></b></div><div class=stat title="tool calls executed"><span>tools</span><b></b></div><div class=stat title="times old turns were summarized to free context"><span>compacted</span><b></b></div></div><div class=statrow><span class=k>tokens</span><b> in / <!> out`),Pl=P(`<h3>🌿 branches <span class=muted style=text-transform:none;letter-spacing:0>· click to filter the feed`),Fl=P(`<h3>⏰ schedule <span class=muted style=text-transform:none;letter-spacing:0>· cron tasks, all agents · edit in settings`),Il=P(`<div><nav class=sidebar><div class=agent-list></div><div class=sidebar-footer><div class=footer-row style=justify-content:flex-end><button>🔔</button></div><div class=brand-row><div class=brand>🫖 teapot <span class=version>v</span><span></span></div></div><div class=metrics></div></div></nav><section class=channel></section><aside>`),Ll=P(`<div class=notifbackdrop>`),Rl=P(`<button class=editbtn>clear all`),zl=P(`<div class=notiflist>`),Bl=P(`<div class=notifpanel><div class=notifhead>notifications<span style=display:flex;gap:8px;align-items:center><button class=iconbtn title="close notifications">✕`),Vl=P(`<span class=caret>`),Hl=P(`<span class=notifbadge>🔔`),Ul=P(`<span class=subtag>🧩`),Wl=P(`<span class=mini-cron>⏰`),Gl=P(`<span title="goal done">✓`),Kl=P(`<div><span></span><span>`),ql=P(`<span class=caret-spacer>`),Jl=P(`<span class=ghosttag title="workspace missing">👻`),Yl=P(`<span>🧩 `),Xl=P(`<label class=trow>system light →<select class=w100>`),Zl=P(`<label class=trow>system dark →<select class=w100>`),Ql=P(`<option>`),$l=P(`<button><span class=swdots>`),eu=P(`<i>`),tu=P(`<div class=muted style=display:grid;place-items:center;height:100%>select an agent`),nu=P(`<div class="divider-msg compacting"title="the harness is compressing old turns into notes so work can continue within the context window">🗜 `),ru=P(`<div class=muted style=display:grid;place-items:center;height:100%>no events yet — say something or press ▶ start`),iu=P(`<div class="content muted">thinking…`),au=P(`<span>⌨ <button class=tabx title="close this shell">✕`),ou=P(`<div><b class=mono></b><span class=muted>`),su=P(`<div class=cmdrow><b>@</b><span class=muted>`),cu=P(`<span class=imgchip><img><button type=button class=imgx title=remove>✕`),lu=P(`<span class=badge title="no goal set yet">no goal`),uu=P(`<button>`),du=P(`<div class="card muted">no goal yet — write one below and press ✓ save. Then ▶ start (or any message) sets it in motion.`),fu=P(`<div><div class=vtitle><span class="meta muted"style=margin-left:auto></span></div><div class=content>`),pu=P(`<div class="content mdpreview"style="max-height:40vh;padding:8px 10px">`),mu=P(`<div class=muted>none yet — the harness asks for a report after real activity, and the agent can report_progress anytime`),hu=P(`<div class=progrow><b>recent</b><span class="content inline-md">`),gu=P(`<div class="progrow warn"><b>⚠ problems</b><span class="content inline-md">`),_u=P(`<div class=progrow><b>next</b><span class="content inline-md">`),vu=P(`<div class=progrow><b>goal</b><span>`),yu=P(`<div class="card prog"><div class=progrow><b>doing</b><span class="content inline-md"></span></div><div class="meta muted">`),bu=P(`<div class=statrow><span class=k>context</span><span class=muted>no window known for this model yet`),xu=P(`<span>% of `),Su=P(`<div class=bartrack><div>`),Cu=P(`<div class=bartrack style=margin-top:4px><div>`),wu=P(`<div class=statrow title="a compaction pass is running right now — the summarizer's output streams in the timeline"><span class=k>🗜</span><b>compacting…</b><span class=muted style=font-size:11px;color:var(--acc)>`),Tu=P(`<div class=ctxblock title="estimated live context vs the model's real window. Past the window, old turns are summarized into notes (compaction); the compact line below shows where that starts."><div class=statrow><span class=k>context</span><b>~<!> tok</b></div><div class=statrow style=margin-top:4px><span class=k>compact</span><b> tok</b><span class=muted style=font-size:11px;color:var(--dim)></span></div><div class=ctrlrow style=margin-top:6px><label title="when on, older turns are automatically summarized when context exceeds the budget"><input type=checkbox>auto-compact</label><span class=muted style=font-size:11.5px>summarizes old turns when budget exceeded</span></div><div class=muted style=font-size:11px;margin-top:4px>compaction starts around ~<!> tok — older turns get summarized, recent ones stay intact`),Eu=P(`<div><span></span><span> events`),Du=P(`<div class=muted>no scheduled tasks — add them in ⚙ settings ("scheduled tasks")`),Ou=P(`<span title="runs on a forked branch so chatter stays off the main line">⑂`),ku=P(`<div><div class=sched-top><b></b><span class=muted>@</span></div><div class="sched-meta mono"> → next </div><div class="sched-prompt muted">`),Au=P(`<div class=muted style=padding:10px>nothing yet — progress, finishes, questions and errors will land here`),ju=P(`<div class=nbody>`),Mu=P(`<div><div class=nhead><span class=nicon></span><span class=ntitle></span><span class="meta muted"></span><button class="iconbtn nreadbtn">`),Nu=P(`<div><div style=font-size:12.5px;margin-bottom:4px> event(s) came after this prompt — what should happen to them on the new branch?</div><label style=display:flex;gap:6px;align-items:center;font-size:13px;color:var(--fg)><input type=radio name=tail>summarize them into a note the agent can still read</label><label style=display:flex;gap:6px;align-items:center;font-size:13px;color:var(--fg)><input type=radio name=tail>discard them entirely (clean timeline)`),Pu=P(`<form style=display:flex;flex-direction:column;gap:10px><textarea id=edit-text class="mono w100"rows=6></textarea><div style=display:flex;justify-content:flex-end;gap:8px><button type=button>cancel</button><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 12px;cursor:pointer">⑂ fork & resend`),Fu=P(`<span class=bashelapsed>running… `),Iu=P(`<span class=bashelapsed> elapsed`),Lu=P(`<span class=thinktimer>`),Ru=P(`<div class=mono>`),zu=P(`<pre class="mono toolbody">`),Bu=P(`<div class=meta>ms`),Vu=P(`<div class=meta>waiting for output…`),Hu=P(`<div class="meta bgjob-note">runs in background — poll with <b>bash_output(job_id=&quot;<!>&quot;)`),Uu=P(`<b>action="kill"`),Wu=P(`<div class="meta muted"> bytes — open it from 🗂 files for the full view`),Gu=P(`<div class=meta>`),Ku=P(`<div class=meta>writing…`),qu=P(`<pre class="mono toolbody del">`),Ju=P(`<pre class="mono toolbody add">`),Yu=P(`<div class=meta> · <!>ms`),Xu=P(`<div class=meta>applying…`),Zu=P(`<pre class="mono toolbody patch">`),Qu=P(`<div>`),$u=P(`<div class="pline meta">… <!> more lines`),ed=P(`<div class=meta>validating…`),td=P(`<a target=_blank rel="noopener noreferrer"referrerpolicy=no-referrer>open ↗`),nd=P(`<span class=muted>`),rd=P(`<div class=meta>loading…`),id=P(`<div class=meta>bundled: `),ad=P(`<div class=meta>saving…`),od=P(`<span class=actor>@`),sd=P(`<details><summary><b>⚙ </b><span class=meta></span><span class=toolcopy>`),cd=P(`<div class=divider-msg>⑂ forked from <!> → `),ld=P(`<div class=divider-msg>🎯 goal <!>: `),ud=P(`<div class=divider-msg>✅ tasks updated (<!>)`),dd=P(`<div> → `),fd=P(`<div class="embed fail"><div class=mono>🛑 runaway: <!> tool failures in a row (limit <!>)</div><div class=meta>last: <!> — `),pd=P(`<div class="embed warn-embed"title="a round-fatal API error occurred; auto-retry is waiting, then a fresh round starts (onError: retry)"><div class=mono>↻ API error — retrying (attempt <!>) in <!>s…`),md=P(`<div class=divider-msg>🗜 compacted: <!> → <!> tok (<!>)`),hd=P(`<button class=editbtn title="withdraw this message — it has not reached the model yet; the text goes back to the input box">✕ cancel`),gd=P(`<button class=editbtn title="edit this prompt — forks the conversation here (later events are dropped or summarized)">✎ edit`),_d=P(`<div class=msg-head><span class=author></span><span class=ts></span><span class=ts>`),vd=P(`<div><div></div><div class=msg-body>`),yd=P(`<span class=grouptime>`),bd=P(`<div class=qfree><input type=text><button>reply`),xd=P(`<div class=promptimgs>`),Sd=P(`<img class=promptimg alt=attachment>`),Cd=P(`<details class=reasoning><summary>💭 reasoning</summary><div class=mono>`),wd=P(`<div class=interrupted>⚠ interrupted — partial output kept`),Td=P(`<div class=msgfoot><span>copy summary`),Ed=P(`<details><summary><span class=meta></span></summary><div class=mono></div><div class=meta>ms`),Dd=P(`<div class="content muted">Rejected: `),Od=P(`<details class="embed decision"><summary><b>📌 <span class="content inline-md"></span></b><span class=meta>decision logged</span></summary><div class=content>`),kd=P(`<div class=meta style=color:var(--ok)>✓ answered — continuing below`),Ad=P(`<div class=qopts>`),jd=P(`<div><div>❓ `),Md=P(`<button class=qopt>`),Nd=P(`<div class=embed style=border-color:var(--ok)><div>📈 <div class="content inline-md">`),Pd=P(`<div class="embed fail"><div class=mono>⚠ `),Fd=P(`<div class=vtitle style=margin-top:6px>what the agent kept`),Id=P(`<details class="embed compaction"><summary><b>🗜 context compacted</b><span class=meta> · <!> → <!> tok · `),Ld=P(`<div class="content muted">`),Rd=P(`<button type=button><span class=iconbtn-glyph>`),zd=P(`<button class=copybtn>`),Bd=P(`<div class=overlay><div class=modal><div class=modal-head><b></b><button class=iconbtn>✕`),Vd=P(`<span style=color:var(--err);font-size:13px>`),Hd=P(`<form style=display:flex;flex-direction:column;gap:10px><label>workspace directory<div style=display:flex;gap:6px><input type=text class="w100 mono"><button type=button>go</button><button type=button title="parent directory">↑</button></div></label><div class=dirlist></div><div style=display:flex;gap:10px><label style=flex:1>agent name <input type=text placeholder="(directory name)"></label><label>provider<select></select></label><label style=flex:1>model <input type=text placeholder="(provider default)"></label></div><button type=submit style=align-self:flex-end>create`),Ud=P(`<div class=direntry>📁 `),Wd=P(`<span class=fsize>`),Gd=P(`<div><span class=ficon></span><span class=fname>`),Kd=P(`<h3 title="the agent's workspace — lazy-loaded, dotfiles hidden; click a folder to expand, a file to preview"style=display:flex;align-items:center;gap:6px>🗂 files <span class=muted style=text-transform:none;letter-spacing:0>· `),qd=P(`<div class=filebox>`),Jd=P(`<div class=muted style=padding:6px>`),Yd=P(`<img>`),Xd=P(`<div class=mediapreview><div class="meta muted"> preview`),Zd=P(`<button title="rendered markdown">👁 preview`),Qd=P(`<button title="edit and save back to the workspace">✎ edit`),$d=P(`<div class=filetoolbar><button title="syntax-highlighted source">&lt;/> code`),ef=P(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),tf=P(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),nf=P(`<div class="content mdpreview">`),rf=P(`<video controls>`),af=P(`<audio controls>`),of=P(`<div class=filepreview>`),sf=P(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),cf=P(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),lf=P(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),uf=P(`<div class=muted style=font-size:11.5px;margin-top:-6px>`),df=P(`<span style=color:var(--fg)>`),ff=P(`<div class=muted style=font-size:11.5px;margin-top:-8px> models found at this endpoint`),pf=P(`<div class=overlay style=background:var(--bg-darkest)><div class=modal style=max-width:560px><div class=modal-head><b>🫖 welcome to teapot</b></div><p class=muted style="margin:0 0 10px;font-size:13px">first run — pick an OpenAI-compatible provider and you're done. everything below can be changed later in ⚙ settings.</p><form style=display:flex;flex-direction:column;gap:12px><div style=display:flex;gap:6px;flex-wrap:wrap></div><label>base url<input type=text class="w100 mono"list=wiz-preset-urls><datalist id=wiz-preset-urls></datalist></label><label>api key <input type=password class=w100 placeholder="(local providers may not need one)"></label><label>default model<input type=text class="w100 mono"list=wiz-model-list><datalist id=wiz-model-list></datalist></label><fieldset><legend>first agent</legend><label>workspace directory<input type=text class="w100 mono"></label><label title="asks for this password when opening the UI or API from another machine — plain-HTTP LAN traffic is NOT encrypted"style=margin-top:4px>protect the API with a password? <input type=password class=w100 placeholder="(optional — LAN traffic is still plain HTTP)"></label></fieldset><button type=submit style="background:var(--acc);border:none;border-radius:8px;color:#fff;padding:9px 14px;font-weight:600;cursor:pointer">`),mf=P(`<button type=button>`),hf=P(`<div class=muted style=font-size:11.5px;margin-top:-8px>models appear here automatically once the endpoint answers GET /models`),gf=P(`<label><input type=number min=0>`),_f=P(`<form style=display:flex;flex-direction:column;gap:14px><fieldset><legend>providers</legend><button type=button>+ add custom</button><div style=display:flex;gap:6px;flex-wrap:wrap;margin-top:6px><span class=muted style=font-size:11.5px>quick-add:</span></div><div><label title="agents without an explicit provider use this one"style=display:flex;align-items:center;gap:6px;margin-top:6px>default provider<select><option value>(none — first provider wins)</option></select></label></div></fieldset><fieldset><legend>agent runtime</legend><div class=cfggrid><label title="auto-compact threshold in k tokens. Leave EMPTY to derive per model (75% of its context window) — recommended, since models differ wildly in window size. Set only to force an absolute cap across all models.">compact budget (k tok)<input type=number min=0 placeholder="(derive: 75% of window)"></label></div></fieldset><fieldset><legend>scheduled tasks</legend><button type=button>+ add task</button></fieldset><fieldset><legend>agents (read-only — edit config file or use +)</legend></fieldset><button type=submit style="align-self:flex-end;background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 14px;cursor:pointer">save settings`),vf=P(`<div class=cfgrow><input class=cfgname placeholder=name><input placeholder=https://…/v1><input placeholder="api key"type=password><input placeholder="default model"><button type=button class=danger title="remove provider">✕`),yf=P(`<button type=button>+ `),bf=P(`<div class=cfgcol><div class=cfgrow><input placeholder=id><input placeholder="agent id"><input placeholder="every 30m / cron"><label style=display:flex;gap:3px;align-items:center;white-space:nowrap;color:var(--dim);font-size:11px><input type=checkbox>fork</label><button type=button class=danger>✕</button></div><textarea rows=2 placeholder="prompt to send">`),xf=P(`<span class=muted>🧩 sub of @`),Sf=P(`<div class=cfgrow><b></b><span class=muted>`),Cf=new Map;function wf(e){let t=Cf.get(e);if(t!==void 0)return t;let n=Fe(e);return Cf.set(e,n),Cf.size>500&&Cf.delete(Cf.keys().next().value),n}var Tf={prompt:{name:`you`,icon:`🟧`,color:`#faa81a`},user:{name:`you`,icon:`🟧`,color:`#faa81a`},message:{name:`agent`,icon:`🫖`,color:`#5865f2`},progress:{name:`progress`,icon:`📈`,color:`#3ba55d`},question:{name:`agent`,icon:`❓`,color:`#5865f2`}},Ef={name:`harness`,icon:`📣`,color:`#3ba55d`},[Df,Of]=v(``),kf,Q=e=>{Of(e),clearTimeout(kf),kf=setTimeout(()=>Of(``),3200)},Af=[{key:`dark`,label:`Dark`,mode:`dark`,sw:[`#1a1c22`,`#2b2e39`,`#5865f2`]},{key:`midnight`,label:`Midnight`,mode:`dark`,sw:[`#0d0f18`,`#252a42`,`#8b7cf7`]},{key:`tea`,label:`Milk Tea`,mode:`dark`,sw:[`#241c16`,`#493b2d`,`#d98e32`]},{key:`coffee`,label:`Coffee`,mode:`dark`,sw:[`#191410`,`#403527`,`#c68a4b`]},{key:`matcha`,label:`Matcha`,mode:`dark`,sw:[`#1b2217`,`#3c4a33`,`#8db64e`]},{key:`matrix`,label:`Matrix`,mode:`dark`,sw:[`#060a06`,`#18301d`,`#2fd558`]},{key:`sunset`,label:`Sunset`,mode:`dark`,sw:[`#1c1422`,`#452f52`,`#f2784b`]},{key:`light`,label:`Light`,mode:`light`,sw:[`#eceef4`,`#ffffff`,`#4757d8`]},{key:`strawberry`,label:`Strawberry`,mode:`light`,sw:[`#fbe4ea`,`#fffafb`,`#e05575`]},{key:`ramune`,label:`Ramune`,mode:`light`,sw:[`#ddeff7`,`#fbfeff`,`#1d86ae`]}];function jf(){let e=``,t=``;try{let n=getComputedStyle(document.documentElement);e=n.getPropertyValue(`--term-bg`).trim(),t=n.getPropertyValue(`--term-fg`).trim()}catch{}return{background:e||`#0d0e12`,foreground:t||`#dcdee4`}}var Mf=e=>{if(e.data?.actor)return{name:`@${String(e.data.actor)}`,icon:`🧩`,color:`#3ba0c9`};if(e.type===`tool_call`||e.type===`tool_result`)return{name:String(e.data?.name??`tool`),icon:`⚙`,color:`#3ba0c9`};if(e.type===`prompt`){let t=String(e.data?.source??`user`);return t===`user`?Tf.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:Ef}return Tf[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},Nf=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`system_note`]),Pf=new Set([`system_note`]),Ff=e=>{let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`};async function $(e,t){let n=localStorage.getItem(`teapot.token`),r=new Headers(t?.headers);n&&!r.has(`authorization`)&&r.set(`authorization`,`Bearer ${n}`);let i=await fetch(e,{...t,headers:r});if(!i.ok){i.status===401&&window.dispatchEvent(new CustomEvent(`teapot:unauthorized`));let t=null;try{t=await i.json()}catch{}let n=(t&&typeof t==`object`&&`error`in t?String(t.error):``)||`${e}: HTTP ${i.status}`;throw Object.assign(Error(n),{payload:t})}return i.json()}var If=location.hash.match(/[#&]token=([^&]+)/);If&&(localStorage.setItem(`teapot.token`,decodeURIComponent(If[1])),history.replaceState(null,``,location.pathname+location.search));var Lf=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function Rf(){let[e,t]=v([]),[n,r]=v(null),[i,a]=v([]),[o,s]=v(0),[c,l]=v([]),[u,d]=v(null),f=new Map,[p,m]=v(f.get(n()??``)??``),h=e=>{m(e);let t=n();t&&(e?f.set(t,e):f.delete(t))},[g,_]=v({providers:{}}),[S,te]=v(!1),[w,T]=v(!1),[ne,E]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>1100:localStorage.getItem(`teapot.panel`)===`1`),re=()=>{let e=!ne();E(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},[D,ie]=v(!1),[O,ae]=v(localStorage.getItem(`teapot.theme`)??`dark`),[oe,se]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[ce,le]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[ue,de]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),k=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[fe,pe]=v(k?.matches??!1);ee(()=>{let e=e=>pe(e.matches);k?.addEventListener(`change`,e),C(()=>k?.removeEventListener(`change`,e))}),b(()=>{let e=oe()?fe()?ce():ue():O();document.documentElement.dataset.theme=e,document.documentElement.dataset.appearance=Af.find(t=>t.key===e)?.mode??`dark`});let[me,he]=v(``),[ge,_e]=v(``),[ve,ye]=v([]),be=()=>Object.keys(g().providers??{});async function xe(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);ye(t.models??[])}catch{ye([])}}let Se=e=>{let t={text:`📄`,image:`🖼️`,audio:`🔊`,video:`🎬`,file:`📎`},n=e=>(e??[`text`]).map(e=>t[e]??e).join(``);return e?.modalities?`${n(e.modalities.input)} → ${n(e.modalities.output)}`:``},P=()=>{let e=ge().trim()||B()?.model||``;if(!e)return``;let t=ve().find(t=>t.id===e);if(!t)return``;let n=[],r=Se(t);r&&r!==`📄 → 📄`&&n.push(r),t.contextLength&&n.push(`ctx ${Jf(t.contextLength)} tok`);let i=e=>e===void 0?``:`${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=i(t.pricing.prompt),r=i(t.pricing.completion);e&&r?n.push(`${e} in · ${r} out`):(e||r)&&n.push(i(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)};b(()=>{let t=n(),r=e().find(e=>e.id===t),i=r?.provider||g().defaultProvider||be()[0]||``;r&&(me()!==i&&(he(i),xe(i)),ge()&&_e(``))});let[Ce,Oe]=v(!1),[ke,Ae]=v(!0),[je,Me]=v(0),[Ne,Pe]=v(null),Ie=()=>He().startsWith(`[compact] `),Le=()=>Ie()?He().slice(10):He();b(()=>{Ne()||Ve(e=>e?.text.startsWith(`[compact] `)?null:e)});let[Re,ze]=v(new Map),Be=()=>{let e=n();return e?Re().get(e)??null:null},Ve=e=>{let t=n();t&&ze(n=>{let r=new Map(n),i=typeof e==`function`?e(n.get(t)??null):e;return i?r.set(t,{...i,at:Date.now()}):r.delete(t),r})},[He,R]=v(``),[z,Ue]=v(0),We=()=>z(),[Ge,Ke]=v(``),qe;b(()=>{if(!Be()){clearTimeout(qe),qe=void 0,R(``),Ke(``);return}qe||=setTimeout(()=>{qe=void 0,R(Be()?.text??``),Ke(Be()?.reasoning??``)},(Be()?.text.length??0)>2e4?250:(Be()?.text.length??0)>6e3?120:60)}),C(()=>clearTimeout(qe)),b(()=>{let e=He(),t=Be()?.reasoning??``;!e&&!t||ke()&&requestAnimationFrame(()=>{ke()&&tn(!0)})}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{en()&&(Ae(!0),Me(0),tn(!0))})};document.addEventListener(`visibilitychange`,e),C(()=>document.removeEventListener(`visibilitychange`,e))});let B=x(()=>e().find(e=>e.id===n())),[Je,Ye]=v(null);x(()=>{let e=new Set;for(let t of i())t.type===`tool_result`&&t.data?.name===`ask_user`&&e.add(String(t.data.callId));return e});let[Xe,Ze]=v([]),[Qe,$e]=v([]),[et,tt]=v(localStorage.getItem(`teapot.hideGhosts`)===`1`),[nt,rt]=v(!1),it=()=>Qe().filter(e=>!e.read).length,at=e=>{$e(t=>{let n=!1,r=t.map(t=>t.read||t.agentId!==e?t:(n=!0,{...t,read:!0}));return n?r:t})},ot=t=>{let n=Qe().filter(e=>!e.read&&e.agentId===t).length;for(let r of e())r.parent===t&&(n+=ot(r.id));return n},st=0,ct=e=>{$e(t=>[{...e,id:`n${++st}`,at:Date.now(),read:!1},...t].slice(0,50))},lt=(t,n)=>{let r=e().find(e=>e.id===t)?.id??t,i=typeof n.id==`string`?n.id:void 0;n.type===`message`&&n.data?.final===!0?ct({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300),eventId:i}):n.type===`question`?ct({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300),eventId:i}):n.type===`error`?ct({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300),eventId:i}):n.type===`progress`&&ct({agentId:t,kind:`progress`,title:`${r}: ${String(n.data.doing??`progress`)}`.slice(0,120),body:[n.data.recent&&`recent: ${n.data.recent}`,n.data.next&&`next: ${n.data.next}`].filter(Boolean).join(` · `).slice(0,300),eventId:i})},ut=e=>{let t=document.querySelector(`[data-eid="${e}"]`);t&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`flash-target`),setTimeout(()=>t.classList.remove(`flash-target`),1600))},dt=x(()=>{let e=new Map,t=new Set,n=new Map;for(let r of i())if(Nf.has(r.type)){if(r.type===`tool_call`){let e=n.get(r.data.callId)??[];e.push(r),n.set(r.data.callId,e)}else if(r.type===`tool_result`){let i=n.get(r.data.callId)?.shift();i&&(e.set(i.id,r),t.add(r.id))}}return{resFor:e,consumed:t}}),ft=x(()=>{let e=new Set,t=-1,n=-1;for(let e of i())e.type===`question`?t=e.seq:e.type===`prompt`&&e.data?.source===`user`?n=e.seq:e.type===`system_note`&&e.data?.event===`prompt-delivered`&&(n=Math.max(n,e.seq));if(t>=0&&n>t)for(let t of i())t.type===`question`&&t.seq<=n&&e.add(String(t.data?.callId??``));return e}),pt=x(()=>{let{consumed:e}=dt(),t=``;for(let e of i()){if(e._prevKind=t,!Nf.has(e.type))continue;let n=e.data??{};(e.type!==`message`||String(n.content??``).trim()!==``||String(n.reasoning??``).trim()===``)&&(t=e.type===`tool_result`?`tool`:e.type)}let n=i().filter(t=>{if(!Nf.has(t.type))return!1;let n=t.type===`tool_call`||t.type===`tool_result`?String(t.data?.name??``):``;if(n===`report_progress`||n===`ask_user`)return!1;if(t.type===`tool_result`)return!e.has(t.id);if(t.type===`message`){let e=String(t.data?.content??``);return e.trim()===``&&String(t.data?.reasoning??``).trim()!==``&&t._prevKind===`tool`||t.data?.progressEcho||!t.data?.final&&e.trim()===`(tool call)`?!1:e.trim()!==``||String(t.data?.reasoning??``).trim()!==``||!!t.data?.final}return!0}),r=[];for(let e of n)if(e.type===`sub`){let t=e.data,n=String(t?.type??`message`);if(n===`state`)continue;r.push({...e,type:n,data:{...t?.data,actor:t?.sub}})}else r.push(e);let a=e=>String(e??``).replace(/\s+/g,` `).trim().toLowerCase(),o=[];for(let e=0;e<r.length;e++){let t=r[e];if(t.type===`message`&&t.data?.role===`assistant`){let n=r[e-1],i=a(t.data.content);if(n?.type===`progress`){let e=n.data;if((i.includes(a(e.doing))||e.recent&&i.includes(a(e.recent)))&&i.length<=Math.max(200,a(e.doing).length*3))continue}if(n?.type===`decision`){let e=n.data,t=a(e.decision);if(t&&i.includes(t)&&i.length<=Math.max(300,t.length*3))continue}}o.push(t)}let s=new Set,c=new Set;for(let e of o){let t=e.data?.promptId;t&&(e.type===`prompt`&&e.data?.source===`user`&&c.add(String(t)),e.type===`system_note`&&e.data?.event===`prompt-delivered`&&s.add(String(t)))}let l=Xe().filter(e=>!e.promptId||!(s.has(e.promptId)&&c.has(e.promptId))).map(e=>ht(e));return[...o,...l]}),mt=new Map;function ht(e){let t=`${e.id}:${e.sent?`s`:`p`}`,n=mt.get(t);if(n)return n;mt.size>64&&mt.clear();let r={id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:B()?.session??``,branch:B()?.branch??`br0`,parent:null,type:`prompt`,data:{source:`user`,text:e.text,pending:!e.sent,...e.images?.length?{images:e.images}:{},...e.promptId?{promptId:e.promptId}:{}}};return mt.set(t,r),r}let gt=()=>$(`/api/config`).then(_).catch(()=>{}),[_t,vt]=v(!1);ee(()=>{let e=()=>vt(!0);window.addEventListener(`teapot:unauthorized`,e),C(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[yt,bt]=v(``),[xt,St]=v(!1),[Ct,wt]=v(!1),Tt=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==Tt?(Tt=t,wt(!1),bt(r)):t&&!Ct()&&bt(r)});let Et=async()=>{let e=document.getElementById(`todo-notify`)?.checked??!0;if(n())try{await $(`/api/agents/${n()}/todo`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:yt(),notify:e})}),wt(!1),Q(`tasks saved${e&&yt().trim()?` & notification queued`:``}`),Ot()}catch(e){Q(`save failed: ${e.message}`)}},Dt=x(()=>{let e=0,t=0;for(let n of yt().split(`
22
- `)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}}),Ot=()=>$(`/api/agents`).then(e=>t(t=>{let n=new Map(t.map(e=>[e.id,e]));return(e.agents??[]).map(e=>{let t=n.get(e.id);return t&&JSON.stringify(t)===JSON.stringify(e)?t:e})})).catch(()=>{}),kt=()=>$(`/api/metrics`).then(d).catch(()=>{}),[At,jt]=v([]),Mt=()=>$(`/api/tasks`).then(e=>jt(e.tasks)).catch(()=>{}),Nt=e=>At().filter(t=>t.agent===e),[Pt,Ft]=v((()=>{try{return new Set(JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`))}catch{return new Set}})()),It=e=>{let t=new Set(Pt());t.has(e)?t.delete(e):t.add(e),Ft(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))},Lt=x(()=>{let t=et()?e().filter(e=>!e.workspaceMissing):e(),n=new Map,r=[];for(let e of t)e.parent&&t.some(t=>t.id===e.parent)?(n.has(e.parent)||n.set(e.parent,[]),n.get(e.parent).unshift(e)):r.push(e);let i=[],a=(e,t)=>{for(let r of e){i.push({a:r,depth:t});let e=n.get(r.id);e?.length&&!Pt().has(r.id)&&a(e,t+1)}};return a(r,0),i}),[Rt,zt]=v(null),Bt=new Map;function Vt(e){return`${n()??`?`}:${e.id}`}function Ht(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=Vt(r),a=Bt.get(i);if(t[n]=a??r,!a&&(Bt.set(i,r),Bt.size>6e3)){let e=Bt.keys().next().value;e!==void 0&&Bt.delete(e)}}return t}let[Ut,Wt]=v(!1),[Gt,Kt]=v(!1),qt=0,Jt=-1;function Yt(e){a(t=>{let n=new Map;for(let e of t)n.set(e.id,e);for(let t of Ht(e))n.has(t.id)||n.set(t.id,t);return[...n.values()].sort((e,t)=>e.seq-t.seq)})}async function Xt(){let e=n();if(!e||Gt()||Ut())return;if(i().length>=o()){Kt(!0);return}let t=()=>{let e=$t();return e&&e.clientHeight>0?e:null},r=0;for(;r++<20&&!Gt()&&n()===e;){let r=t();if(r&&r.scrollHeight>r.clientHeight+40)return;if(i().length>=o()){Kt(!0);return}let a=i().length;if(await Zt(),i().length===a)return;ke()&&n()===e&&tn(!0)}}async function Zt(){let e=n(),t=i()[0];if(!(!e||!t||Ut()||Gt())){Wt(!0);try{let r=$t(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=Rt(),c=(await $(`/api/agents/${e}/events?limit=300&before=${encodeURIComponent(t.id)}${s?`&branch=${encodeURIComponent(s)}`:``}`)).events??[];if(c.length===0){Kt(!0);return}if(n()!==e||i()[0]?.id!==t.id)return;Yt(c),requestAnimationFrame(()=>{if(n()===e){let e=$t();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{Wt(!1)}}}async function Qt(e){let t=qt;try{let r=Rt(),i=t!==Jt||!c().length,[o,u,d]=await Promise.all([$(`/api/agents/${e}/events?limit=300${r?`&branch=${encodeURIComponent(r)}`:``}`),i?$(`/api/agents/${e}/branches`):Promise.resolve({branches:c()}),$(`/api/agents/${e}/skills`).catch(()=>({skills:[]}))]);if(i&&(Jt=t),t!==qt||n()!==e)return;a(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of Ht(o.events))t.set(e.id,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}),s(o.total??o.events.length),l(u.branches),Yn(d.skills??[])}catch{}}function $t(){return document.querySelector(`.feed`)}function V(){let e=document.querySelector(`.composer textarea`);return 80+Math.min(Math.max((e?.scrollHeight??0)-(e?.clientHeight??0),0),160)}function en(){let e=$t();return!e||e.scrollHeight-e.scrollTop-e.clientHeight<V()}function tn(e=!1){let t=$t();t&&(e||ke())&&(t.scrollTop=t.scrollHeight,Me(0))}let H=new Map;async function nn(e,t=!0){let c=n(),l=i(),u=o();if(qt++,c!==e){if(c&&l.length&&(H.set(c,{events:l,total:u,at:Date.now()}),H.size>6)){let e=[...H.entries()].sort((e,t)=>e[1].at-t[1].at)[0];e&&H.delete(e[0])}a([]),Bt.clear(),Pe(null),Me(0),Ae(!0),nr=!1,rr=void 0}r(e),h(f.get(e)??``),zt(null),Kt(!1),Wt(!1),Ze([]),localStorage.setItem(`teapot.session`,e),dn(e,t);let d=H.get(e);d?.events.length&&(Ht(d.events),a(Ht(d.events)),s(d.total),requestAnimationFrame(()=>{n()===e&&tn(!0)})),$(`/api/agents/${e}/load`,{method:`POST`}).then(Ot).catch(()=>{}),await Qt(e),n()===e&&(Pe(B()?.ctx?.compacting?{phase:String(B().ctx.compacting)}:null),requestAnimationFrame(()=>{n()===e&&tn(!0)}),Xt())}let[rn,an]=v(!1),U=null,on=null;C(()=>U?.close());let sn=!1,cn=null;document.addEventListener(`visibilitychange`,()=>cn?.()),C(()=>{cn=null});function ln(){let e=location.protocol===`https:`?`wss://`:`ws://`;U=new WebSocket(`${e}${location.host}/api/ws${Lf()}`),U.onopen=()=>an(!0),U.onclose=()=>{an(!1),setTimeout(ln,1500)},U.onerror=()=>U?.close();let r=new Set([`state`,`usage`,`session_start`]);U.onmessage=e=>{let i=JSON.parse(e.data);if(i.kind!==`ping`&&i.kind!==`pong`){if(i.kind===`llm-delta`){if(ze(e=>{let t=new Map(e);return t.set(i.agentId,{text:i.text??``,reasoning:i.reasoning??``,at:Date.now()}),t}),i.agentId===n()){let e=String(i.reasoning??``),t=String(i.text??``);e&&!t?z()||Ue(Date.now()):(t||!e&&z())&&Ue(0)}return}if(i.kind===`compaction-progress`){if(i.agentId!==n())return;i.phase===`done`?Pe(null):Pe({phase:i.phase,summarized:i.summarized});return}if(i.kind===`agent-update`&&i.snapshot){t(e=>{let t=e.findIndex(e=>e.id===i.snapshot.id),n=i.snapshot;if(t===-1)return[...e,n];let r=e[t];return JSON.stringify(r)===JSON.stringify(n)?e:e.map((e,r)=>r===t?n:e)});return}if(i.kind===`event`){let e=i.event?.type,t=i.event?.data??{};if((e===`system_note`&&t.event===`prompt-delivered`&&i.agentId===n()||e===`system_note`&&t.event===`prompt-cancelled`&&i.agentId===n())&&Ze(e=>e.filter(e=>e.promptId!==t.promptId)),r.has(e)&&!Pf.has(e)||(lt(i.agentId,i.event),i.event?.agent!==n()))return}if(document.visibilityState===`hidden`){sn=!0;return}on||=setTimeout(a,120)}},sn=!1;let a=async()=>{if(on=null,await Ot(),await kt(),n()){let e=i().at(-1)?.id,t=o();if(await Qt(n()),i().at(-1)?.id!==e){let e=Be();if(e){let t=[...i()].reverse().find(e=>e.type===`message`&&e.data?.role===`assistant`);(t&&(String(t.data.content??``)===e.text||String(t.data.reasoning??``)===e.reasoning)||B()?.status===`idle`)&&Ve(null)}ke()?(tn(!0),at(n())):Me(je()+Math.max(0,o()-t))}}};cn=()=>{document.visibilityState===`visible`&&sn&&(sn=!1,a())}}let un=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function dn(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let t=un();t&&e().some(e=>e.id===t)&&t!==n()&&nn(t,!1)}),b(()=>{let e=B(),t=e?`${e.status===`running`?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`;document.title=it()>0?`(${it()}) ${t}`:t}),window.addEventListener(`keydown`,e=>{let t=e.target;if(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)){e.key===`Escape`&&t.blur();return}if(e.key===`Escape`){if(S()){te(!1);return}if(w()){T(!1);return}if(Je()){Ye(null);return}if(D()){ie(!1);return}let e=B();if(e?.status===`running`){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(Ot);return}ne()&&window.innerWidth<=1100&&E(!1);return}if(!(S()||w())){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)re();else if(e.key===`t`)mn();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=Lt().map(e=>e.a);if(t.length===0)return;e.preventDefault();let r=t.findIndex(e=>e.id===n()),i=e.key===`ArrowDown`?Math.min(r+1,t.length-1):Math.max(r-1,0);i!==r&&nn(t[i].id)}}});let[fn,pn]=v(localStorage.getItem(`teapot.term`)===`1`),mn=()=>{let e=!fn();pn(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[hn,gn]=v([]),[_n,vn]=v(0),[yn,bn]=v(-1),[W,xn]=v(!1),[Sn,Cn]=v(0),[wn,Tn]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),En=new Map,Dn=[null,null],On=()=>hn()[Sn()===0?_n():yn()]??null;function kn(e){if(!hn()[e])return;let t=Sn(),n=t===0?_n():yn(),r=t===0?yn():_n(),i=e=>t===0?vn(e):bn(e),a=e=>t===0?bn(e):vn(e);if(r===e){a(n),i(e);return}n!==e&&i(e)}let An=()=>jn();function jn(e){let t=e??n();if(!t)return;let r=hn().filter(e=>e.agentId===t).length;if(r>=10){Q(`max 10 shells per agent (${t}) — that's already a lot`);return}hn().length+1;let i=r===0?{key:`${t}`,agentId:t,title:t}:{key:`${t}#${r+1}`,agentId:t,title:`${t}·${r+1}`};gn(e=>[...e,i]),Sn()===0?vn(hn().length):bn(hn().length)}function Mn(e){let t=hn()[e];if(!t)return;let n=En.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),En.delete(t.key)}let r=hn().filter((t,n)=>n!==e);gn(r);let i=t=>t===e?-1:t>e?t-1:t;vn(e=>Math.min(i(e),r.length-1)),bn(e=>e===-1?-1:Math.min(i(e),r.length-1))}function Nn(){for(let[,e]of En){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}En.clear()}function Pn(e,t){let n=En.get(e.key);if(n)n.el.parentElement!==t&&(t.appendChild(n.el),setTimeout(()=>{try{n.fit()}catch{}},30));else{let r=document.createElement(`div`);r.className=`termsession`,t.appendChild(r);let i=new Dc({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:jf()}),a=new Ac;i.loadAddon(a),i.open(r);let o=location.protocol===`https:`?`wss://`:`ws://`,s=new WebSocket(`${o}${location.host}/api/agents/${e.agentId}/term${Lf()}`);s.onmessage=e=>{let t=JSON.parse(e.data);t.kind===`data`?i.write(t.data):t.kind===`exit`&&i.write(`\r\n\x1b[2m[terminal exited ${t.code??``}]\x1b[0m\r\n`)},i.onData(e=>{s.readyState===WebSocket.OPEN&&s.send(JSON.stringify({kind:`input`,data:e}))});let c={cols:0,rows:0},l=[],u=()=>{try{a.fit()}catch{}(i.cols!==c.cols||i.rows!==c.rows)&&s.readyState===WebSocket.OPEN&&(c={cols:i.cols,rows:i.rows},s.send(JSON.stringify({kind:`resize`,cols:i.cols,rows:i.rows})))},d=new ResizeObserver(()=>{l[0]&&clearTimeout(l[0]),l[0]=setTimeout(u,250)});d.observe(r),setTimeout(u,60),n={el:r,term:i,fit:a,ws:s,ro:d},En.set(e.key,n)}return n}function Fn(e){let t=Dn[e];if(!t)return;let n=hn()[e===0?_n():yn()];if(!n){[...En.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=Pn(n,t);for(let[e,r]of En)e!==n.key&&r.el.parentElement===t&&r.el.remove();requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(Sn()===(e===0?0:1))try{r.term.focus()}catch{}})}b(()=>{hn(),W(),_n(),yn(),wn(),requestAnimationFrame(()=>{Fn(0),W()&&Fn(1)})}),b(()=>{if(!fn())return;let e=n();if(e){if(!hn().some(t=>t.agentId===e)&&hn().length===0)jn(e);else if(!hn().some(t=>t.agentId===e))jn(e);else{let t=hn().findIndex(t=>t.agentId===e);t>=0&&kn(t)}}});let In=e=>{e.preventDefault();let t=e.clientY,n=wn(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));Tn(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(wn())),requestAnimationFrame(()=>{Fn(0),W()&&Fn(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},Ln=()=>{let e=!W();if(xn(e),e){let e=hn().map((e,t)=>t).filter(e=>e!==_n());(yn()<0||yn()===_n()||yn()>=hn().length)&&bn(e[0]??-1)}requestAnimationFrame(()=>{Fn(0),W()&&Fn(1)})};C(Nn);let Rn=e=>t=>{Dn[e]=t,t&&requestAnimationFrame(()=>{Fn(e),W()&&Fn(1),setTimeout(()=>Fn(e),200)})};ee(()=>{gt(),Ot().then(()=>{let t=un()||localStorage.getItem(`teapot.session`)||``,n=e().find(e=>e.id===t)??e()[0];n&&nn(n.id,!1)}),kt(),Mt(),Hn(),ln();let t=setInterval(()=>{kt(),Mt()},3e4);C(()=>clearInterval(t))});let zn=[{cmd:`/start`,desc:`start working toward the goal`},{cmd:`/stop`,desc:`interrupt the running agent`},{cmd:`/fork`,desc:`branch the conversation here`},{cmd:`/goal`,desc:`/goal <text> — set goal & notify the agent`},{cmd:`/compact`,desc:`force a context compaction now`},{cmd:`/skill`,desc:`/skill <name> — force-load a skill and follow it`}],[Bn,Vn]=v([]),Hn=()=>$(`/api/personas`).then(e=>Vn(e.personas)).catch(()=>{}),[Un,Wn]=v(!1),Gn=()=>{let e=p().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},Kn=()=>{let t=Gn();return t===null?[]:[...Bn().map(e=>({key:e.key,label:`${e.label} — spawns a sub-agent`,kind:`persona`})),...e().filter(e=>e.id!==n()).map(e=>({key:e.id,label:`${e.status} — send directly`,kind:`agent`}))].filter(e=>e.key.toLowerCase().startsWith(t))},qn=new Set([`start`,`stop`,`fork`,`compact`]),[Jn,Yn]=v([]),[Xn,Zn]=v(-1),Qn=()=>{let e=p();if(!e.startsWith(`/`)||e.includes(`
22
+ `)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}}),Ot=()=>$(`/api/agents`).then(e=>t(t=>{let n=new Map(t.map(e=>[e.id,e]));return(e.agents??[]).map(e=>{let t=n.get(e.id);return t&&JSON.stringify(t)===JSON.stringify(e)?t:e})})).catch(()=>{}),kt=()=>$(`/api/metrics`).then(d).catch(()=>{}),[At,jt]=v([]),Mt=()=>$(`/api/tasks`).then(e=>jt(e.tasks)).catch(()=>{}),Nt=e=>At().filter(t=>t.agent===e),[Pt,Ft]=v((()=>{try{return new Set(JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`))}catch{return new Set}})()),It=e=>{let t=new Set(Pt());t.has(e)?t.delete(e):t.add(e),Ft(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))},Lt=x(()=>{let t=et()?e().filter(e=>!e.workspaceMissing):e(),n=new Map,r=[];for(let e of t)e.parent&&t.some(t=>t.id===e.parent)?(n.has(e.parent)||n.set(e.parent,[]),n.get(e.parent).unshift(e)):r.push(e);let i=[],a=(e,t)=>{for(let r of e){i.push({a:r,depth:t});let e=n.get(r.id);e?.length&&!Pt().has(r.id)&&a(e,t+1)}};return a(r,0),i}),[Rt,zt]=v(null),Bt=new Map;function Vt(e){return`${n()??`?`}:${e.id}`}function Ht(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=Vt(r),a=Bt.get(i);if(t[n]=a??r,!a&&(Bt.set(i,r),Bt.size>6e3)){let e=Bt.keys().next().value;e!==void 0&&Bt.delete(e)}}return t}let[Ut,Wt]=v(!1),[Gt,Kt]=v(!1),qt=0,Jt=-1;function Yt(e){a(t=>{let n=new Map;for(let e of t)n.set(e.id,e);for(let t of Ht(e))n.has(t.id)||n.set(t.id,t);return[...n.values()].sort((e,t)=>e.seq-t.seq)})}async function Xt(){let e=n();if(!e||Gt()||Ut())return;if(i().length>=o()){Kt(!0);return}let t=()=>{let e=$t();return e&&e.clientHeight>0?e:null},r=0;for(;r++<20&&!Gt()&&n()===e;){let r=t();if(r&&r.scrollHeight>r.clientHeight+40)return;if(i().length>=o()){Kt(!0);return}let a=i().length;if(await Zt(),i().length===a)return;ke()&&n()===e&&tn(!0)}}async function Zt(){let e=n(),t=i()[0];if(!(!e||!t||Ut()||Gt())){Wt(!0);try{let r=$t(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=Rt(),c=(await $(`/api/agents/${e}/events?limit=300&before=${encodeURIComponent(t.id)}${s?`&branch=${encodeURIComponent(s)}`:``}`)).events??[];if(c.length===0){Kt(!0);return}if(n()!==e||i()[0]?.id!==t.id)return;Yt(c),requestAnimationFrame(()=>{if(n()===e){let e=$t();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{Wt(!1)}}}async function Qt(e){let t=qt;try{let r=Rt(),i=t!==Jt||!c().length,[o,u,d]=await Promise.all([$(`/api/agents/${e}/events?limit=300${r?`&branch=${encodeURIComponent(r)}`:``}`),i?$(`/api/agents/${e}/branches`):Promise.resolve({branches:c()}),$(`/api/agents/${e}/skills`).catch(()=>({skills:[]}))]);if(i&&(Jt=t),t!==qt||n()!==e)return;a(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of Ht(o.events))t.set(e.id,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}),s(o.total??o.events.length),l(u.branches),Yn(d.skills??[])}catch{}}function $t(){return document.querySelector(`.feed`)}function V(){let e=document.querySelector(`.composer textarea`);return 24+Math.min(Math.max((e?.scrollHeight??0)-(e?.clientHeight??0),0),160)}function en(){let e=$t();return!e||e.scrollHeight-e.scrollTop-e.clientHeight<V()}function tn(e=!1){let t=$t();t&&(e||ke())&&(t.scrollTop=t.scrollHeight,Me(0))}let H=new Map;async function nn(e,t=!0){let c=n(),l=i(),u=o();if(qt++,c!==e){if(c&&l.length&&(H.set(c,{events:l,total:u,at:Date.now()}),H.size>6)){let e=[...H.entries()].sort((e,t)=>e[1].at-t[1].at)[0];e&&H.delete(e[0])}a([]),Bt.clear(),Pe(null),Me(0),Ae(!0),nr=!1,rr=void 0}r(e),h(f.get(e)??``),zt(null),Kt(!1),Wt(!1),Ze([]),localStorage.setItem(`teapot.session`,e),dn(e,t);let d=H.get(e);d?.events.length&&(Ht(d.events),a(Ht(d.events)),s(d.total),requestAnimationFrame(()=>{n()===e&&tn(!0)})),$(`/api/agents/${e}/load`,{method:`POST`}).then(Ot).catch(()=>{}),await Qt(e),n()===e&&(Pe(B()?.ctx?.compacting?{phase:String(B().ctx.compacting)}:null),requestAnimationFrame(()=>{n()===e&&tn(!0)}),Xt())}let[rn,an]=v(!1),U=null,on=null;C(()=>U?.close());let sn=!1,cn=null;document.addEventListener(`visibilitychange`,()=>cn?.()),C(()=>{cn=null});function ln(){let e=location.protocol===`https:`?`wss://`:`ws://`;U=new WebSocket(`${e}${location.host}/api/ws${Lf()}`),U.onopen=()=>an(!0),U.onclose=()=>{an(!1),setTimeout(ln,1500)},U.onerror=()=>U?.close();let r=new Set([`state`,`usage`,`session_start`]);U.onmessage=e=>{let i=JSON.parse(e.data);if(i.kind!==`ping`&&i.kind!==`pong`){if(i.kind===`llm-delta`){if(ze(e=>{let t=new Map(e);return t.set(i.agentId,{text:i.text??``,reasoning:i.reasoning??``,at:Date.now()}),t}),i.agentId===n()){let e=String(i.reasoning??``),t=String(i.text??``);e&&!t?z()||Ue(Date.now()):(t||!e&&z())&&Ue(0)}return}if(i.kind===`compaction-progress`){if(i.agentId!==n())return;i.phase===`done`?Pe(null):Pe({phase:i.phase,summarized:i.summarized});return}if(i.kind===`agent-update`&&i.snapshot){t(e=>{let t=e.findIndex(e=>e.id===i.snapshot.id),n=i.snapshot;if(t===-1)return[...e,n];let r=e[t];return JSON.stringify(r)===JSON.stringify(n)?e:e.map((e,r)=>r===t?n:e)});return}if(i.kind===`event`){let e=i.event?.type,t=i.event?.data??{};if((e===`system_note`&&t.event===`prompt-delivered`&&i.agentId===n()||e===`system_note`&&t.event===`prompt-cancelled`&&i.agentId===n())&&Ze(e=>e.filter(e=>e.promptId!==t.promptId)),r.has(e)&&!Pf.has(e)||(lt(i.agentId,i.event),i.event?.agent!==n()))return}if(document.visibilityState===`hidden`){sn=!0;return}on||=setTimeout(a,120)}},sn=!1;let a=async()=>{if(on=null,await Ot(),await kt(),n()){let e=i().at(-1)?.id,t=o();if(await Qt(n()),i().at(-1)?.id!==e){let e=Be();if(e&&e.text){let t=e.text.trim();(B()?.status!==`running`||i().some(e=>e.type===`message`&&e.data?.role===`assistant`&&String(e.data.content??``).trim()===t))&&Ve(null)}else e&&!e.text&&B()?.status!==`running`&&Ve(null);ke()?(tn(!0),at(n())):Me(je()+Math.max(0,o()-t))}}};cn=()=>{document.visibilityState===`visible`&&sn&&(sn=!1,a())}}let un=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function dn(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let t=un();t&&e().some(e=>e.id===t)&&t!==n()&&nn(t,!1)}),b(()=>{let e=B(),t=e?`${e.status===`running`?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`;document.title=it()>0?`(${it()}) ${t}`:t}),window.addEventListener(`keydown`,e=>{let t=e.target;if(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)){e.key===`Escape`&&t.blur();return}if(e.key===`Escape`){if(S()){te(!1);return}if(w()){T(!1);return}if(Je()){Ye(null);return}if(D()){ie(!1);return}let e=B();if(e?.status===`running`){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(Ot);return}ne()&&window.innerWidth<=1100&&E(!1);return}if(!(S()||w())){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)re();else if(e.key===`t`)mn();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=Lt().map(e=>e.a);if(t.length===0)return;e.preventDefault();let r=t.findIndex(e=>e.id===n()),i=e.key===`ArrowDown`?Math.min(r+1,t.length-1):Math.max(r-1,0);i!==r&&nn(t[i].id)}}});let[fn,pn]=v(localStorage.getItem(`teapot.term`)===`1`),mn=()=>{let e=!fn();pn(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[hn,gn]=v([]),[_n,vn]=v(0),[yn,bn]=v(-1),[W,xn]=v(!1),[Sn,Cn]=v(0),[wn,Tn]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),En=new Map,Dn=[null,null],On=()=>hn()[Sn()===0?_n():yn()]??null;function kn(e){if(!hn()[e])return;let t=Sn(),n=t===0?_n():yn(),r=t===0?yn():_n(),i=e=>t===0?vn(e):bn(e),a=e=>t===0?bn(e):vn(e);if(r===e){a(n),i(e);return}n!==e&&i(e)}let An=()=>jn();function jn(e){let t=e??n();if(!t)return;let r=hn().filter(e=>e.agentId===t).length;if(r>=10){Q(`max 10 shells per agent (${t}) — that's already a lot`);return}hn().length+1;let i=r===0?{key:`${t}`,agentId:t,title:t}:{key:`${t}#${r+1}`,agentId:t,title:`${t}·${r+1}`};gn(e=>[...e,i]),Sn()===0?vn(hn().length):bn(hn().length)}function Mn(e){let t=hn()[e];if(!t)return;let n=En.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),En.delete(t.key)}let r=hn().filter((t,n)=>n!==e);gn(r);let i=t=>t===e?-1:t>e?t-1:t;vn(e=>Math.min(i(e),r.length-1)),bn(e=>e===-1?-1:Math.min(i(e),r.length-1))}function Nn(){for(let[,e]of En){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}En.clear()}function Pn(e,t){let n=En.get(e.key);if(n)n.el.parentElement!==t&&(t.appendChild(n.el),setTimeout(()=>{try{n.fit()}catch{}},30));else{let r=document.createElement(`div`);r.className=`termsession`,t.appendChild(r);let i=new Dc({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:jf()}),a=new Ac;i.loadAddon(a),i.open(r);let o=location.protocol===`https:`?`wss://`:`ws://`,s=new WebSocket(`${o}${location.host}/api/agents/${e.agentId}/term${Lf()}`);s.onmessage=e=>{let t=JSON.parse(e.data);t.kind===`data`?i.write(t.data):t.kind===`exit`&&i.write(`\r\n\x1b[2m[terminal exited ${t.code??``}]\x1b[0m\r\n`)},i.onData(e=>{s.readyState===WebSocket.OPEN&&s.send(JSON.stringify({kind:`input`,data:e}))});let c={cols:0,rows:0},l=[],u=()=>{try{a.fit()}catch{}(i.cols!==c.cols||i.rows!==c.rows)&&s.readyState===WebSocket.OPEN&&(c={cols:i.cols,rows:i.rows},s.send(JSON.stringify({kind:`resize`,cols:i.cols,rows:i.rows})))},d=new ResizeObserver(()=>{l[0]&&clearTimeout(l[0]),l[0]=setTimeout(u,250)});d.observe(r),setTimeout(u,60),n={el:r,term:i,fit:a,ws:s,ro:d},En.set(e.key,n)}return n}function Fn(e){let t=Dn[e];if(!t)return;let n=hn()[e===0?_n():yn()];if(!n){[...En.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=Pn(n,t);for(let[e,r]of En)e!==n.key&&r.el.parentElement===t&&r.el.remove();requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(Sn()===(e===0?0:1))try{r.term.focus()}catch{}})}b(()=>{hn(),W(),_n(),yn(),wn(),requestAnimationFrame(()=>{Fn(0),W()&&Fn(1)})}),b(()=>{if(!fn())return;let e=n();if(e){if(!hn().some(t=>t.agentId===e)&&hn().length===0)jn(e);else if(!hn().some(t=>t.agentId===e))jn(e);else{let t=hn().findIndex(t=>t.agentId===e);t>=0&&kn(t)}}});let In=e=>{e.preventDefault();let t=e.clientY,n=wn(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));Tn(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(wn())),requestAnimationFrame(()=>{Fn(0),W()&&Fn(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},Ln=()=>{let e=!W();if(xn(e),e){let e=hn().map((e,t)=>t).filter(e=>e!==_n());(yn()<0||yn()===_n()||yn()>=hn().length)&&bn(e[0]??-1)}requestAnimationFrame(()=>{Fn(0),W()&&Fn(1)})};C(Nn);let Rn=e=>t=>{Dn[e]=t,t&&requestAnimationFrame(()=>{Fn(e),W()&&Fn(1),setTimeout(()=>Fn(e),200)})};ee(()=>{gt(),Ot().then(()=>{let t=un()||localStorage.getItem(`teapot.session`)||``,n=e().find(e=>e.id===t)??e()[0];n&&nn(n.id,!1)}),kt(),Mt(),Hn(),ln();let t=setInterval(()=>{kt(),Mt()},3e4);C(()=>clearInterval(t))});let zn=[{cmd:`/start`,desc:`start working toward the goal`},{cmd:`/stop`,desc:`interrupt the running agent`},{cmd:`/fork`,desc:`branch the conversation here`},{cmd:`/goal`,desc:`/goal <text> — set goal & notify the agent`},{cmd:`/compact`,desc:`force a context compaction now`},{cmd:`/skill`,desc:`/skill <name> — force-load a skill and follow it`}],[Bn,Vn]=v([]),Hn=()=>$(`/api/personas`).then(e=>Vn(e.personas)).catch(()=>{}),[Un,Wn]=v(!1),Gn=()=>{let e=p().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},Kn=()=>{let t=Gn();return t===null?[]:[...Bn().map(e=>({key:e.key,label:`${e.label} — spawns a sub-agent`,kind:`persona`})),...e().filter(e=>e.id!==n()).map(e=>({key:e.id,label:`${e.status} — send directly`,kind:`agent`}))].filter(e=>e.key.toLowerCase().startsWith(t))},qn=new Set([`start`,`stop`,`fork`,`compact`]),[Jn,Yn]=v([]),[Xn,Zn]=v(-1),Qn=()=>{let e=p();if(!e.startsWith(`/`)||e.includes(`
23
23
  `))return[];let t=e.match(/^\/([a-z]*)(?:\s+(.*))?$/i);if(!t)return[];let n=t[1].toLowerCase(),r=(t[2]??``).trim();if(!r&&n!==`skill`){let e=zn.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&qn.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=Jn().filter(e=>e.name.toLowerCase().startsWith(r.toLowerCase()));return e.length===1&&e[0].name.toLowerCase()===r.toLowerCase()?[]:e.map(e=>({insert:`/skill ${e.name} `,title:e.description||`(bundled skill)`}))}return[]},$n,er=()=>{if(!$n)return;tr=!0;let e=ke();$n.style.height=`auto`,$n.style.height=Ce()?``:`${Math.min($n.scrollHeight,360)}px`,requestAnimationFrame(()=>{let t=$t();e&&t&&(t.scrollTop=t.scrollHeight),tr=!1})},tr=!1,nr=!1,rr;b(()=>{p(),er()});let[ir,ar]=v([]),or=e=>{let t=Array.from(e).filter(e=>e.type.startsWith(`image/`));for(let e of t){if(e.size>8e6){Q(`"${e.name}" is over 8 MB — skipped`);continue}let t=new FileReader;t.onload=()=>{ar(n=>[...n,{url:String(t.result),name:e.name}].slice(0,4))},t.readAsDataURL(e)}},sr=async(e,t)=>{let r=t??n();if(!r)return;let i=ir();try{let t=await $(`/api/agents/${r}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:e,start:!0,...i.length?{images:i}:{}})});Ze(n=>[...n,{id:`@p${Date.now()}${Math.random().toString(36).slice(2,6)}`,text:e,at:Date.now(),promptId:t.promptId,...i.length?{images:i.map(e=>e.url)}:{}}]),ar([]),requestAnimationFrame(()=>requestAnimationFrame(()=>tn(!0)))}catch(t){h(e),console.error(`send failed:`,t)}},cr=async t=>{t.preventDefault();let r=n(),i=p().trim();if(!(!r||!i)){if(i.startsWith(`@`)){let t=i.indexOf(` `),r=(t===-1?i.slice(1):i.slice(1,t)).toLowerCase(),a=t===-1?``:i.slice(t+1).trim(),o=Bn().some(e=>e.key.toLowerCase()===r),s=e().some(e=>e.id.toLowerCase()===r);try{if(o){if(!a){Q(`usage: @${r} <task>`);return}Q(`🧩 spawned ${(await $(`/api/agents/${n()}/spawn`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({persona:r,task:a,context:Un()?`fork`:`none`})})).id}${Un()?` (forked context)`:``}`),Ot(),h(``)}else if(s){if(!a){Q(`usage: @${r} <message>`);return}await $(`/api/agents/${encodeURIComponent(r)}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:a,start:!0})}),Q(`→ delivered to @${r}`),h(``)}else{Q(`unknown @${r} — personas: ${Bn().map(e=>e.key).join(`, `)||`(none)`}`);return}}catch(e){Q(`@${r} failed: ${e.message}`)}return}if(i.startsWith(`/`)){let e=i.indexOf(` `),t=(e===-1?i.slice(1):i.slice(1,e)).toLowerCase(),n=e===-1?``:i.slice(e+1).trim();if(t===`goal`&&!n){h(`/goal `);return}if(t===`skill`&&!n){h(`/skill `);return}h(``);try{await lr(t,n)}catch(e){throw h(p()?`${i}\n${p()}`:i),e}return}h(``),await sr(i),Ce()&&Oe(!1)}},lr=async(e,t)=>{let r=n();if(!r)return;let i=(e,t)=>$(`/api/agents/${r}${e}`,{method:`POST`,headers:{"content-type":`application/json`},...t===void 0?{}:{body:JSON.stringify(t)}}).then(Ot);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await nn(r);else if(e===`compact`)Q((await i(`/compact`))?.ran?`context compacted`:`nothing to compact yet`);else if(e===`goal`){if(!t){Q(`usage: /goal <text>`);return}await i(`/goal`,{text:t,notify:!0}),Q(`goal saved & notification queued`)}else if(e===`skill`){if(!t){Q(`usage: /skill <name>`);return}await sr(`[harness] Force-load and follow the skill "${t}" now: call load_skill("${t}") and execute its playbook for the current task.`),Q(`skill "${t}" dispatched`)}else Q(`unknown command "${e}" — /start /stop /fork /goal /skill /compact`)}catch(t){Q(`/${e} failed: ${t.message}`)}},ur,dr=0;b(()=>{e(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!ur)return;let e=Math.min(dr,ur.scrollHeight);Math.abs(ur.scrollTop-e)>1&&(ur.scrollTop=e)})})});let fr=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then(Ot),[pr,mr]=v(``),[hr,gr]=v(``),[_r,vr]=v(!1),[yr,br]=v(!0),xr=``;b(()=>{let e=n();e&&(B()?.goal,e!==xr&&(xr=e,vr(!1),mr(``),gr(``)))});let Sr=async e=>{if(e.preventDefault(),!(!n()||!pr().trim()))try{await $(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:pr(),notify:yr(),...hr().trim()?{verify:hr()}:{}})}),mr(``),gr(``),vr(!1),Ot()}catch(e){Q(`goal save failed: ${e.message}`)}};return[A(M,{get when(){return g()?.needsSetup},fallback:null,get children(){return A(up,{onDone:()=>location.reload()})}}),A(M,{get when(){return _t()},get children(){var e=Fc();return e.firstChild.firstChild.nextSibling.addEventListener(`submit`,e=>{e.preventDefault();let t=document.getElementById(`pw-input`);localStorage.setItem(`teapot.token`,t.value),location.reload()}),e}}),A(M,{get when(){return!g()?.needsSetup},get children(){var o=Il(),s=o.firstChild,l=s.firstChild,d=l.nextSibling,f=d.firstChild,m=f.firstChild;m.firstChild;var _=f.nextSibling,v=_.firstChild.firstChild.nextSibling;v.firstChild;var S=v.nextSibling,ee=_.nextSibling,C=s.nextSibling,w=C.nextSibling;L(l,A(j,{get each(){return Lt()},children:({a:t,depth:r})=>(()=>{var i=Kl(),a=i.firstChild,o=a.nextSibling;return i.$$click=()=>nn(t.id),L(i,A(M,{get when(){return e().some(e=>e.parent===t.id)},get fallback(){return ql()},get children(){var e=Vl();return e.$$click=e=>{e.stopPropagation(),It(t.id)},L(e,()=>Pt().has(t.id)?`▸`:`▾`),y(()=>F(e,`title`,Pt().has(t.id)?`expand sub-agents`:`collapse sub-agents`)),e}}),a),L(o,()=>t.id),L(i,(()=>{var e=N(()=>!!t.workspaceMissing);return()=>e()?Jl():null})(),null),L(i,A(M,{get when(){return ot(t.id)>0},get children(){var e=Hl();return e.firstChild,L(e,()=>ot(t.id),null),y(()=>F(e,`title`,`${ot(t.id)} unread notification${ot(t.id)>1?`s`:``} (including sub-agents)`)),e}}),null),L(i,A(M,{get when(){return Pt().has(t.id)},get children(){return(()=>{let n=e().filter(e=>e.parent===t.id),r=n.filter(e=>e.status===`running`||e.status===`waiting`).length;return n.length>0?(()=>{var e=Yl();return e.firstChild,I(e,`subcount`+(r>0?` live`:``)),L(e,()=>n.length,null),L(e,r>0?` · ▶${r}`:``,null),y(()=>F(e,`title`,`${n.length} sub-agent${n.length>1?`s`:``} (${r} active)`)),e})():null})()}}),null),L(i,A(M,{get when(){return t.parent},get children(){return Ul()}}),null),L(i,A(M,{get when(){return Nt(t.id).length>0},get children(){var e=Wl();return y(()=>F(e,`title`,Nt(t.id).map(e=>`${e.id}: ${e.schedule}`).join(`
24
- `))),e}}),null),L(i,A(M,{get when(){return t.goal.status===`done`},get children(){return Gl()}}),null),y(e=>{var s=`agent-item`+(t.id===n()?` sel`:``)+(r>0?` sub-row`:``),c=r>0?`padding-left:${10+r*14}px`:``,l=t.parent?`sub-agent of @${t.parent}`:void 0,u=`dot ${t.status}`,d=t.workspaceMissing?` ghost`:``,f=t.workspaceMissing?`workspace not found on disk (${t.workspace}) — it will be created when this session runs`:void 0;return s!==e.e&&I(i,e.e=s),e.t=Te(i,c,e.t),l!==e.a&&F(i,`title`,e.a=l),u!==e.o&&I(a,e.o=u),d!==e.i&&I(o,e.i=d),f!==e.n&&F(o,`title`,e.n=f),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),i})()})),L(d,A(M,{get when(){return D()},get children(){var e=Lc(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;se(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),L(e,A(M,{get when(){return!oe()},get fallback(){return[(()=>{var e=Xl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{le(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),L(t,A(j,{get each(){return Af.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=Ql();return L(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=ce()),e})(),(()=>{var e=Zl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{de(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),L(t,A(j,{get each(){return Af.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=Ql();return L(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=ue()),e})()]},get children(){var e=Ic();return L(e,A(j,{each:Af,children:e=>(()=>{var t=$l(),n=t.firstChild;return t.$$click=()=>{ae(e.key),localStorage.setItem(`teapot.theme`,e.key)},L(n,()=>e.sw.map(e=>(()=>{var t=eu();return Ee(t,`background`,e),t})())),L(t,()=>e.label,null),y(n=>{var r=`themebtn`+(O()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&I(t,n.e=r),i!==n.t&&F(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=oe()),e}}),f),m.$$click=e=>{e.stopPropagation(),rt(!nt()),nt()||$e(e=>e.map(e=>({...e,read:!0})))},L(m,A(M,{get when(){return it()>0},get children(){var e=Rc();return L(e,it),e}}),null),L(f,A(Zf,{icon:`👻`,get active(){return et()},get title(){return et()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!et();if(tt(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&B()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&nn(t.id)}}}),null),L(f,A(Zf,{icon:`+`,title:`new agent`,onClick:()=>{gt(),te(!0)}}),null),L(f,A(Zf,{icon:`🎨`,title:`themes`,onClick:()=>ie(!D())}),null),L(f,A(Zf,{icon:`⚙`,title:`settings`,onClick:()=>{gt(),T(!0)}}),null),L(v,`0.22.5`,null),L(ee,A(M,{get when(){return u()},get children(){return[`master rss `,N(()=>u().rssMb),`MB · heap `,N(()=>u().heapUsedMb),`MB`,zc(),`load1 `,N(()=>u().loadavg1),` · up `,N(()=>Math.floor(u().uptimeSec/60)),`m`]}})),L(C,A(M,{get when(){return B()},get fallback(){return tu()},get children(){return[(()=>{var e=Uc(),t=e.firstChild.nextSibling,n=t.nextSibling,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling.nextSibling,s=o.nextSibling.nextSibling;s.nextSibling;var c=r.nextSibling;return L(t,()=>B().id),L(n,()=>B().status),L(e,A(M,{get when(){return(B().pendingPrompts??0)>0},get children(){var e=Bc(),t=e.firstChild.nextSibling;return t.nextSibling,L(e,()=>B().pendingPrompts,t),y(()=>F(e,`title`,`${B().pendingPrompts??0} message${(B().pendingPrompts??0)>1?`s`:``} from you waiting in the queue. They will be handed to the model at its next turn boundary — the timeline shows them as "pending (queued)…" until then, and each can be withdrawn with ✕ cancel while it's still queued.`)),e}}),r),L(e,A(M,{get when(){return Nt(B().id).length>0},get children(){var e=Vc();return e.firstChild,L(e,()=>Nt(B().id).length,null),y(()=>F(e,`title`,`scheduled tasks:\n${Nt(B().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
25
- `)}`)),e}}),r),L(r,()=>B().model,i),L(r,()=>B().session,a),L(r,()=>B().branch,o),L(r,()=>B().stats.turns,s),L(r,()=>B().stats.toolCalls,null),L(c,A(M,{get when(){return B().statusReason},get children(){var e=Hc();return y(()=>F(e,`title`,B().statusReason)),e}}),null),L(c,A(Zf,{icon:`⌨`,title:`terminal (t)`,onClick:mn}),null),L(c,A(Zf,{icon:`▤`,title:`toggle details panel (d)`,onClick:re}),null),y(()=>I(n,`badge ${B().status}`)),e})(),(()=>{var e=Xc();return e.addEventListener(`scroll`,e=>{if(tr)return;let t=e.currentTarget,r=en(),a=t.scrollHeight-t.scrollTop-t.clientHeight;if(!r&&rr!==void 0&&a>rr+8&&a>24?nr=!0:r&&(nr=!1),rr=a,nr&&!r){Ae(!1);return}r&&je()&&Me(0),Ae(r),t.scrollTop<=4&&n()&&!Ut()&&!Gt()&&i().length>0&&Zt()}),L(e,A(M,{get when(){return Ne()},children:e=>(()=>{var t=nu();return t.firstChild,L(t,(()=>{var t=N(()=>e().phase===`harvesting`);return()=>t()?`saving durable lessons…`:`summarizing ${e().summarized?Jf(e().summarized)+` `:``}older messages…`})(),null),t})()}),null),L(e,A(M,{get when(){return N(()=>!!Gt())()&&pt().length>0},get children(){return Wc()}}),null),L(e,A(M,{get when(){return Ut()},get children(){return Gc()}}),null),L(e,A(M,{get when(){return pt().length>0},get fallback(){return ru()},get children(){return[A(j,{get each(){return pt()},children:(e,t)=>A(Uf,{e,get prev(){return pt()[t()-1]},get res(){return dt().resFor.get(e.id)},onOption:e=>void sr(e),get answeredIds(){return ft()},get agentActive(){return B()?.status===`running`||B()?.status===`waiting`},onResize:()=>{ke()&&requestAnimationFrame(()=>tn(!0))},get onCancel(){return e.data?.pending&&e.data?.promptId&&e.data?.sent!==!0?()=>{let t=String(e.data.promptId);$(`/api/agents/${n()}/prompt/cancel`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({promptId:t})}).then(e=>{let n=String(e.text??``);h(p()?`${n}\n\n${p()}`:n),Ze(e=>e.filter(e=>e.promptId!==t)),Q(`message withdrawn — draft restored`)}).catch(()=>Q(`withdraw failed — it may have already been sent`))}:void 0},get onEdit(){return e.type===`prompt`&&e.data?.source===`user`?()=>Ye({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),A(M,{get when(){return Be()},get children(){var e=Yc(),t=e.firstChild.nextSibling;return t.firstChild,L(t,A(M,{get when(){return Ge()},get children(){var e=Kc(),t=e.firstChild;t.firstChild;var n=t.nextSibling;return L(t,A(Bf,{get startedAt(){return We()}}),null),De(e=>{b(()=>{Ge(),ke()&&(e.scrollTop=e.scrollHeight)})},n),L(n,Ge),e}}),null),L(t,A(M,{get when(){return He()},get fallback(){return iu()},get children(){return A(M,{get when(){return Ie()},get fallback(){return(()=>{var e=Jc();return y(()=>e.innerHTML=Fe(He()+`▍`)),e})()},get children(){return[qc(),(()=>{var e=Jc();return y(()=>e.innerHTML=Fe(Le()+`▍`)),e})()]}})}}),null),e}})]}}),null),e})(),A(M,{get when(){return fn()},get children(){var t=tl(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=r.nextSibling,c=s.firstChild;n.$$dblclick=()=>{Tn(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(wn()))},n.$$pointerdown=In,L(i,A(j,{get each(){return hn()},children:(e,t)=>(()=>{var n=au(),r=n.firstChild.nextSibling;return n.$$click=()=>kn(t()),L(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),Mn(t())},y(r=>{var i=`termtab`+(Sn()===0&&_n()===t()?` active`:``)+(W()&&Sn()===1&&yn()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&I(n,r.e=i),a!==r.t&&F(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),null),L(i,A(Zf,{icon:`+`,title:`new shell in this workspace`,onClick:An}),null),L(o,(()=>{var t=N(()=>!!On());return()=>t()?e().find(e=>e.id===On().agentId)?.workspace.split(`/`).filter(Boolean).pop():B()?.workspace})()),L(a,A(Zf,{icon:`◫`,get title(){return W()?`single pane`:`split panes (50/50)`},onClick:Ln}),null),L(a,A(Zf,{icon:`▾`,title:`hide the terminal (shells keep running; reopen with t) — close individual shells with their ✕ tab buttons`,onClick:mn}),null);var l=Rn(0);return typeof l==`function`&&De(l,c),c.$$pointerdown=()=>Cn(0),L(c,A(M,{get when(){return _n()<0||_n()>=hn().length},get children(){return Zc()}})),L(s,A(M,{get when(){return W()},get children(){return[Qc(),(()=>{var e=el(),t=Rn(1);return typeof t==`function`&&De(t,e),e.$$pointerdown=()=>Cn(1),L(e,A(M,{get when(){return yn()<0||yn()>=hn().length},get children(){return $c()}})),y(()=>e.classList.toggle(`focused`,Sn()===1)),e})()]}}),null),y(e=>{var n={height:`${wn()}px`,"--termh":`${wn()}px`},r=!!W(),i=Sn()===0;return e.e=Te(t,n,e.e),r!==e.t&&s.classList.toggle(`split`,e.t=r),i!==e.a&&c.classList.toggle(`focused`,e.a=i),e},{e:void 0,t:void 0,a:void 0}),t}}),(()=>{var e=sl(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling,o=t.nextSibling;L(e,A(M,{get when(){return!ke()||je()>0},get children(){var e=nl();return e.firstChild,e.$$click=()=>tn(!0),L(e,(()=>{var e=N(()=>je()>0);return()=>e()?`${je()} new message${je()>1?`s`:``}`:`jump to present`})(),null),e}}),t),L(e,A(M,{get when(){return Qn().length>0},get children(){var e=rl();return L(e,A(j,{get each(){return Qn()},children:(e,t)=>(()=>{var n=ou(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{h(e.insert),Zn(-1)},L(r,()=>e.insert.trim()),L(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===Xn()?` active`:``),a=e.title;return i!==r.e&&I(n,r.e=i),a!==r.t&&F(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),L(e,A(M,{get when(){return Kn().length>0},get children(){var e=rl();return L(e,A(j,{get each(){return Kn()},children:e=>(()=>{var t=su(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{h(`@${e.key} `),Zn(-1)},L(n,()=>e.key,null),L(r,()=>e.label),y(()=>F(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,cr),L(t,A(M,{get when(){return ir().length>0},get children(){var e=il(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return r.nextSibling,L(e,A(j,{get each(){return ir()},children:(e,t)=>(()=>{var n=cu(),r=n.firstChild,i=r.nextSibling;return i.$$click=()=>ar(e=>e.filter((e,n)=>n!==t())),y(t=>{var i=e.name,a=e.url,o=e.name;return i!==t.e&&F(n,`title`,t.e=i),a!==t.t&&F(r,`src`,t.t=a),o!==t.a&&F(r,`alt`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),n})()}),t),L(t,()=>ir().length,n),L(t,()=>ir().length>1?`s`:``,r),e}}),n),n.$$keydown=e=>{let t=Qn();if(t.length>0&&e.key===`ArrowDown`){e.preventDefault(),Zn(e=>Math.min(e+1,t.length-1));return}if(t.length>0&&e.key===`ArrowUp`){e.preventDefault(),Zn(e=>Math.max(e-1,0));return}if(t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&Xn()>=0){e.preventDefault(),h(t[Xn()].insert),Zn(-1);return}if(e.key===`Escape`&&t.length>0){Zn(-1);return}e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),cr(e))},n.$$input=e=>{h(e.currentTarget.value),Zn(0),er()},n.addEventListener(`paste`,e=>{let t=Array.from(e.clipboardData?.files??[]).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),or(t))});var s=$n;return typeof s==`function`?De(s,n):$n=n,L(t,A(M,{get when(){return N(()=>!!p().startsWith(`@`))()&&p().includes(` `)},get children(){var e=al(),t=e.firstChild;return t.addEventListener(`change`,e=>Wn(e.currentTarget.checked)),y(()=>t.checked=Un()),e}}),r),r.$$click=()=>{let e=!Ce();Oe(e),requestAnimationFrame(()=>er())},L(r,()=>Ce()?`⤡`:`⤢`),L(t,A(Zf,{icon:`📎`,title:`attach images (or paste them straight into the box)`,onClick:()=>document.getElementById(`composer-file`)?.click()}),i),L(t,A(M,{get when(){return ir().length},get children(){var e=ol();return e.firstChild,L(e,()=>ir().length,null),e}}),i),a.addEventListener(`change`,e=>{e.currentTarget.files?.length&&or(e.currentTarget.files),e.currentTarget.value=``}),L(o,()=>Df()||`enter send · shift+enter newline · ↑↓ sessions · / commands & focus · t terminal · d panel · esc interrupt · messages sent while the agent works queue up and land at the next turn boundary`),y(t=>{var i=`composer`+(Ce()?` maximized`:``),a=`message #${B().id} — / for commands · paste or 📎 to attach images`,o=Ce()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&I(e,t.e=i),a!==t.t&&F(n,`placeholder`,t.t=a),o!==t.a&&F(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),y(()=>n.value=p()),e})()]}})),w.addEventListener(`scroll`,e=>{dr=e.currentTarget.scrollTop});var E=ur;return typeof E==`function`?De(E,w):ur=w,L(w,A(M,{get when(){return B()},get children(){return[cl(),(()=>{var e=ll(),t=e.firstChild,n=t.firstChild.nextSibling,r=n.nextSibling,i=t.nextSibling,a=i.firstChild.nextSibling,o=i.nextSibling.firstChild.nextSibling,s=o.firstChild;return L(n,()=>B().id),L(r,()=>B().status),L(a,()=>B().workspace),L(o,()=>B().session,s),L(o,()=>B().branch,null),y(e=>{var t=`badge ${B().status}`,n=B().workspace;return t!==e.e&&I(r,e.e=t),n!==e.t&&F(a,`title`,e.t=n),e},{e:void 0,t:void 0}),e})(),A(M,{get when(){return B().id},keyed:!0,fallback:null,children:e=>A(op,{agentId:e,get workspace(){return B().workspace}})}),ul(),(()=>{var e=fl(),t=e.firstChild,r=t.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=r.nextSibling;return s.firstChild,t.addEventListener(`change`,e=>{he(e.currentTarget.value),xe(e.currentTarget.value)}),L(t,A(j,{get each(){return be()},children:e=>(()=>{var t=Ql();return t.value=e,L(t,e,null),L(t,()=>e===g().defaultProvider?` ★`:``,null),t})()})),i.$$input=e=>_e(e.currentTarget.value),L(a,A(j,{get each(){return ve()},children:e=>(()=>{var t=Ql();return y(()=>t.value=e.id),t})()})),o.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await $(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provider:me(),model:ge().trim()||void 0,contextWindowTokens:ve().find(e=>e.id===(ge().trim()||void 0))?.contextLength})}),t.textContent=`✓ applied`,Ot()}catch(e){alert(`model switch failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},L(s,()=>B().model,null),L(s,A(M,{get when(){return ve().length},get children(){return[` · `,N(()=>ve().length),` models loaded`]}}),null),L(e,A(M,{get when(){return P()},get children(){var e=dl();return L(e,P),e}}),null),y(()=>F(i,`placeholder`,B().model)),y(()=>t.value=me()),y(()=>i.value=ge()),e})(),pl(),(()=>{var i=hl(),o=i.firstChild,s=o.nextSibling,c=s.nextSibling;return we(o,`click`,B().status===`running`?fr(`/stop`):fr(`/start`),!0),L(o,()=>B().status===`running`?`■ stop`:`▶ start`),s.$$click=()=>$(`/api/agents/${B().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(()=>nn(B().id)),c.$$click=async()=>{let i=n();if(!i||!confirm(`remove agent ${i}? (log is kept)`))return;await $(`/api/agents/${i}`,{method:`DELETE`}).catch(()=>{});let o=e().filter(e=>e.id!==i);t(o),o[0]?nn(o[0].id):(r(null),a([]))},L(i,A(M,{get when(){return e().some(e=>e.parent===n())},get children(){var e=ml();return e.$$click=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),Ot())},e}}),null),y(e=>{var t=B().status===`running`?`danger`:`runbtn`,n=B().status===`running`?`interrupt: aborts the current LLM call; the running tool finishes first`:`run toward the goal (starts the loop)`;return t!==e.e&&I(o,e.e=t),n!==e.t&&F(o,`title`,e.t=n),e},{e:void 0,t:void 0}),i})(),(()=>{var e=gl(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-continue`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(Ot)}),y(()=>t.checked=B().autoContinue??!0),e})(),(()=>{var e=vl();return e.firstChild,L(e,A(M,{get when(){return!!B().goal.text.trim()},get fallback(){return lu()},get children(){var e=_l();return L(e,()=>B().goal.status),y(()=>I(e,`badge ${B().goal.status===`active`?`running`:B().goal.status}`)),e}}),null),e})(),(()=>{var e=yl();return e.firstChild,L(e,A(j,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=uu();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(Ot)},F(t,`title`,e===`active`?`agent keeps working toward the goal (with auto-continue)`:e===`done`?`mark achieved — auto-continue stops`:`parked on purpose — resume by setting active again`),L(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(B().goal.text.trim()&&B().goal.status===e?` on ${e}`:``),i=!!B().goal.text.trim()&&B().goal.status===e;return r!==n.e&&I(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),A(M,{get when(){return B().goal.text},get fallback(){return du()},get children(){return[(()=>{var e=bl(),t=e.firstChild;return y(()=>t.innerHTML=Fe(String(B().goal.text))),e})(),A(M,{get when(){return B().goal.verify},get children(){var e=xl(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Fe(String(B().goal.verify))),e}}),A(M,{get when(){return B().goal.audit},children:e=>(()=>{var t=fu(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return L(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),L(r,()=>qf(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=Fe(e().feedback);return r!==n.e&&I(t,n.e=r),a!==n.t&&(i.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t})()})]}}),Sl(),(()=>{var e=Cl(),t=e.firstChild,n=t.nextSibling,r=n.nextSibling.firstChild.firstChild;return e.addEventListener(`submit`,Sr),t.$$input=e=>{mr(e.currentTarget.value),vr(!0)},n.$$input=e=>{gr(e.currentTarget.value),vr(!0)},r.addEventListener(`change`,e=>br(e.currentTarget.checked)),y(()=>t.value=pr()),y(()=>n.value=hr()),y(()=>r.checked=yr()),e})(),(()=>{var e=Tl(),t=e.firstChild.nextSibling;return L(e,A(M,{get when(){return Dt().total>0},get children(){var e=wl(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,L(e,()=>Dt().done,t),L(e,()=>Dt().total,n),y(t=>Te(e,Dt().done===Dt().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),A(M,{get when(){return Dt().total>0},get children(){var e=El(),t=e.firstChild;return y(e=>{var n=`barfill `+(Dt().done===Dt().total?``:`warn`),r=`${Math.round(Dt().done/Dt().total*100)}%`;return n!==e.e&&I(t,e.e=n),r!==e.t&&Ee(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),A(M,{get when(){return xt()},get fallback(){return(()=>{var e=pu();return y(()=>e.innerHTML=wf(yt())),e})()},get children(){var e=Dl();return e.$$input=e=>{bt(e.currentTarget.value),wt(!0)},y(()=>e.value=yt()),e}}),(()=>{var e=Ol(),t=e.firstChild,n=t.nextSibling;return L(e,A(Zf,{get icon(){return xt()?`👁`:`✎`},get title(){return xt()?`rendered checklist`:`edit markdown`},onClick:()=>St(!xt())}),t),n.$$click=Et,e})(),kl(),A(M,{get when(){return B().latestProgress},get fallback(){return mu()},children:e=>(()=>{var t=yu(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return L(t,A(M,{get when(){return e().recent},get children(){var t=hu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=wf(e().recent)),t}}),i),L(t,A(M,{get when(){return e().problems},get children(){var t=gu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=wf(e().problems)),t}}),i),L(t,A(M,{get when(){return e().next},get children(){var t=_u(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=wf(e().next)),t}}),i),L(t,A(M,{get when(){return e().goalStatus},get children(){var t=vu(),n=t.firstChild.nextSibling;return L(n,()=>e().goalStatus),t}}),i),L(i,()=>qf(e().ts)),y(()=>r.innerHTML=wf(e().doing)),t})()}),Al(),(()=>{var e=Nl(),t=e.firstChild,r=t.firstChild,i=r.firstChild.nextSibling,a=r.nextSibling,o=a.firstChild.nextSibling,s=a.nextSibling.firstChild.nextSibling,c=t.nextSibling,l=c.firstChild.nextSibling,u=l.firstChild,d=u.nextSibling;return d.nextSibling,L(i,()=>B().stats.turns),L(o,()=>B().stats.toolCalls),L(s,()=>B().stats.compactions??0),L(l,()=>Jf(B().stats.inputTokens),u),L(l,()=>Jf(B().stats.outputTokens),d),L(c,A(M,{get when(){return(B().stats.cachedInputTokens??0)>0},get children(){var e=jl(),t=e.firstChild.nextSibling;return t.nextSibling,L(e,()=>Math.round(B().stats.cachedInputTokens/Math.max(1,B().stats.inputTokens)*1e3)/10,t),y(()=>F(e,`title`,`${Jf(B().stats.cachedInputTokens)} tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),L(e,A(M,{get when(){return(B().stats.costUsd??0)>0},get children(){var e=Ml(),t=e.firstChild.nextSibling;return t.firstChild,L(t,()=>Yf(B().stats.costUsd??0),null),y(()=>F(e,`title`,`≈ ${(B().stats.costUsd??0).toFixed(4)} this session, from the model's USD/token pricing and per-turn usage. Cached input is estimated at ~10% of the prompt rate; treat as an approximation, not an invoice.`)),e}}),null),L(e,A(M,{get when(){return B().ctx},keyed:!0,get fallback(){return bu()},children:e=>{let t=x(()=>{let t=e,n=ve().find(e=>e.id===B().model),r=t.window||n?.contextLength||0,i=r?Math.min(999,t.usedTokens/r*100):0;return{usedTokens:t.usedTokens,compactAt:t.compactAt,compacting:t.compacting,window:t.window,effectiveWindow:r,pct:i,cls:r?i>=85?`crit`:i>=70?`warn`:`ok`:``,derivedBudget:r?Math.round(r*.75):0,usingDerived:t.compactAtIsManual!==!0}}),r=()=>t(),i=e=>{let t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)};return(()=>{var e=Tu(),t=e.firstChild,a=t.firstChild.nextSibling,o=a.firstChild.nextSibling;o.nextSibling;var s=t.nextSibling,c=s.firstChild.nextSibling,l=c.firstChild,u=c.nextSibling,d=s.nextSibling,f=d.firstChild.firstChild,p=d.nextSibling,m=p.firstChild.nextSibling;return m.nextSibling,L(a,()=>Jf(r().usedTokens),o),L(t,A(M,{get when(){return r().effectiveWindow},get children(){var e=xu(),t=e.firstChild;return L(e,()=>i(r().pct),t),L(e,()=>Jf(r().effectiveWindow),null),y(()=>I(e,`pill ${r().cls}`)),e}}),null),L(e,A(M,{get when(){return r().effectiveWindow},get children(){var e=Su(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,r().pct)}%`;return n!==e.e&&I(t,e.e=n),i!==e.t&&Ee(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),s),L(c,()=>Jf(r().usingDerived?r().derivedBudget:r().compactAt),l),L(u,()=>r().usingDerived?` (75% of window)`:` (manual override)`),L(e,A(M,{get when(){return r().effectiveWindow},get children(){var e=Cu(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,Math.round(r().usedTokens/r().derivedBudget*100))}%`;return n!==e.e&&I(t,e.e=n),i!==e.t&&Ee(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),d),L(e,A(M,{get when(){return Ne()||r().compacting},get children(){var e=wu(),t=e.firstChild.nextSibling.nextSibling;return L(t,()=>Ne()?.phase??String(r().compacting)),e}}),d),f.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(Ot)}),L(p,()=>Jf(r().compactAt),m),y(()=>f.checked=B().autoCompact!==!1),e})()}}),null),e})(),Pl(),A(j,{get each(){return c()},children:e=>(()=>{var t=Eu(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=Rt()===e.branch?null:e.branch;zt(t),n()&&Qt(n())},L(r,()=>e.branch,null),L(r,()=>e.branch===B().branch?` (current)`:``,null),L(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===B().branch||e.branch===Rt()?` cur`:``),i=e.branch===Rt()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&I(t,n.e=r),i!==n.t&&F(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),Fl(),A(M,{get when(){return At().length>0},get fallback(){return Du()},get children(){return A(j,{get each(){return At()},children:e=>(()=>{var t=ku(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>nn(e.agent),L(i,()=>e.id),L(a,()=>e.agent,null),L(r,A(M,{get when(){return e.forked},get children(){return Ou()}}),null),L(o,()=>e.schedule,s),L(o,(()=>{var t=N(()=>!!e.next);return()=>t()?qf(e.next):`—`})(),null),L(o,(()=>{var t=N(()=>!!e.last);return()=>t()?` · last ${qf(e.last)}`:` · never ran`})(),null),L(c,()=>Xf(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${Xf(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&I(t,r.e=i),a!==r.t&&F(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}})),y(e=>{var t=`layout`+(ne()?``:` right-hidden`),n=`iconbtn notifbtn`+(it()>0?` has-unread`:``),r=it()>0?`${it()} unread notifications`:`notifications`,i=`conn`+(rn()?` ok`:``),a=rn()?`live (websocket)`:`reconnecting…`,s=`rightbar`+(ne()?` open`:``);return t!==e.e&&I(o,e.e=t),n!==e.t&&I(m,e.t=n),r!==e.a&&F(m,`title`,e.a=r),i!==e.o&&I(S,e.o=i),a!==e.i&&F(S,`title`,e.i=a),s!==e.n&&I(w,e.n=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),o}}),A(M,{get when(){return nt()},get children(){return[(()=>{var e=Ll();return e.$$click=()=>rt(!1),e})(),(()=>{var t=Bl(),r=t.firstChild.firstChild.nextSibling,i=r.firstChild;return L(r,A(M,{get when(){return Qe().length>0},get children(){var e=Rl();return e.$$click=()=>$e([]),e}}),i),i.$$click=()=>rt(!1),L(t,A(M,{get when(){return Qe().length>0},get fallback(){return Au()},get children(){var t=zl();return L(t,A(j,{get each(){return Qe()},children:t=>(()=>{var r=Mu(),i=r.firstChild.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling;return r.$$click=()=>{$e(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e)),n()!==t.agentId&&e().some(e=>e.id===t.agentId)&&nn(t.agentId),rt(!1),t.eventId&&setTimeout(()=>ut(t.eventId),n()===t.agentId?60:350)},L(i,(()=>{var e=N(()=>t.kind===`finish`);return()=>e()?`✅`:N(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),L(a,()=>t.title),L(o,()=>qf(new Date(t.at).toISOString())),s.$$click=e=>{e.stopPropagation(),$e(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e))},L(s,()=>t.read?`✓`:`○`),L(r,A(M,{get when(){return t.body},get children(){var e=ju();return L(e,()=>Kf(t.body,160)),e}}),null),y(e=>{var n=`notifitem `+t.kind+(t.read?` read`:``),i=`from ${t.agentId}`,a=t.read?`already read`:`mark as read`;return n!==e.e&&I(r,e.e=n),i!==e.t&&F(r,`title`,e.t=i),a!==e.a&&F(s,`title`,e.a=a),e},{e:void 0,t:void 0,a:void 0}),r})()})),t}}),null),t})()]}}),A(M,{get when(){return S()},get children(){return A(ep,{get providers(){return Object.keys(g().providers??{})},onClose:()=>te(!1),onCreated:e=>{te(!1),Ot(),nn(e)}})}}),A(M,{get when(){return w()},get children(){return A(dp,{get cfg(){return g()},onClose:()=>T(!1),onSaved:()=>{gt(),Mt()}})}}),A(M,{get when(){return Je()},fallback:null,children:e=>{let t=()=>i().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,i().length-t()-1),[a,o]=v(r()>0?`summarize`:`discard`);return A($f,{title:`edit prompt — forks the conversation`,onClose:()=>Ye(null),get children(){var t=Pu(),i=t.firstChild,s=i.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await $(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:a()})}),Ye(null),Ot();let t=n();t&&await nn(t)}catch(e){alert(`edit failed: ${e.message}`)}}),L(t,A(M,{get when(){return r()>0},get children(){var e=Nu(),t=e.firstChild,n=t.firstChild,i=t.nextSibling,s=i.firstChild,c=i.nextSibling.firstChild;return L(t,r,n),s.addEventListener(`change`,()=>o(`summarize`)),c.addEventListener(`change`,()=>o(`discard`)),y(()=>s.checked=a()===`summarize`),y(()=>c.checked=a()===`discard`),e}}),s),c.$$click=()=>Ye(null),y(()=>i.value=e().text),t}})}})]}function zf(e){let t=new Date(e.startedAt).getTime(),[n,r]=v(Date.now());ee(()=>{let e=setInterval(()=>r(Date.now()),500);C(()=>clearInterval(e))});let i=()=>Math.max(0,(n()-t)/1e3),a=()=>i()<60?`${i().toFixed(1)}s`:`${Math.floor(i()/60)}m ${Math.round(i()%60)}s`;return e.inline?(()=>{var t=Fu();return t.firstChild,L(t,a,null),L(t,(()=>{var t=N(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=Iu(),t=e.firstChild;return L(e,a,t),e})()}function Bf(e){let[t,n]=v(Date.now());ee(()=>{let e=setInterval(()=>n(Date.now()),500);C(()=>clearInterval(e))});let r=()=>Math.max(0,(t()-e.startedAt)/1e3);return(()=>{var e=Lu();return L(e,(()=>{var e=N(()=>r()<60);return()=>e()?`${r().toFixed(0)}s`:`${Math.floor(r()/60)}m ${Math.round(r()%60)}s`})()),e})()}function Vf(e){let t=e.e,n=e.res,r=!e.agentActive&&!n,i=t.data??{},a=String(i.name??`tool`),o=()=>n?String(n.data?.result??``):``,s=a,c=``,l=(()=>{var e=Ru();return L(e,()=>Kf(JSON.stringify(i.args??{},null,1),2e3)),e})(),u=e=>String(i.args?.[e]??``),d=()=>a===`bash`?u(`command`):u(`path`)||JSON.stringify(i.args??{},null,1),f=()=>a===`bash`?Number(u(`timeout_ms`))||void 0:a===`wait_children`?Number(u(`timeout_ms`))||3e5:Number(u(`timeout_ms`))||void 0,p=(e,t=1500)=>(()=>{var n=zu();return L(n,()=>Kf(e,t)),n})(),m=(e=4e3)=>n?[N(()=>p(o(),e)),(()=>{var e=Bu(),t=e.firstChild;return L(e,()=>n.data?.durationMs,t),L(e,()=>n.data?.ok===!1?` · FAILED`:``,null),L(e,A(Qf,{get text(){return o()}}),null),e})()]:Vu();try{switch(a){case`bash`:{let e=u(`command`),t=i.args?.background===!0,r=t?String(o()).match(/job (bg\d+)/)?.[1]??``:``;s=(t?`⏳ `:`$ `)+Xf(e,96);let a=u(`timeout_ms`)?` · timeout ${Math.round(Number(u(`timeout_ms`))/1e3)}s`:``;c=n?t?`background job${r?` ${r}`:``}${a}`:`${n.data?.durationMs??`?`}ms${a}`:null,l=[t?(()=>{var e=Hu(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling;return n.nextSibling,L(t,r||`?`,n),L(e,r?[` · kill with `,Uu()]:null,null),e})():null,N(()=>N(()=>e!==s.slice(2))()?p(e,800):null),N(()=>m(6e3))];break}case`read_file`:{s=u(`path`)||`(no path)`;let e=[];u(`pattern`)&&e.push(`grep /${Xf(u(`pattern`),40)}/`),Number(i.args?.offset)<0?e.push(`last ${-Number(i.args.offset)} lines`):i.args?.offset&&e.push(`from L${i.args.offset}`),i.args?.limit&&e.push(`≤${i.args.limit} lines`),c=e.join(` · `),l=m(6e3);break}case`write_file`:{let e=String(i.args?.content??``);s=u(`path`)||`(no path)`,c=`${Jf(e.length)} bytes`,l=[N(()=>p(e,1500)),N(()=>N(()=>e.length>1500)()?(()=>{var t=Wu(),n=t.firstChild;return L(t,()=>Jf(e.length),n),t})():null),n?(()=>{var e=Gu();return L(e,()=>Xf(o(),160)),e})():Ku()];break}case`edit_file`:s=u(`path`)||`(no path)`,c=i.args?.replace_all===!0?`replace all`:`unique spot`,l=[(()=>{var e=qu();return L(e,()=>Kf(`- `+u(`old_text`),900)),e})(),(()=>{var e=Ju();return L(e,()=>`+ `+Kf(u(`new_text`),900)),e})(),n?(()=>{var e=Yu(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,L(e,()=>Xf(o(),120),t),L(e,()=>n.data?.durationMs,r),e})():Xu()];break;case`apply_patch`:{let e=u(`patch`).split(`
24
+ `))),e}}),null),L(i,A(M,{get when(){return t.goal.status===`done`},get children(){return Gl()}}),null),y(e=>{var s=`agent-item`+(t.id===n()?` sel`:``)+(r>0?` sub-row`:``),c=r>0?`padding-left:${10+r*14}px`:``,l=t.parent?`sub-agent of @${t.parent}`:void 0,u=`dot ${t.status}`,d=t.workspaceMissing?` ghost`:``,f=t.workspaceMissing?`workspace not found on disk (${t.workspace}) — it will be created when this session runs`:void 0;return s!==e.e&&I(i,e.e=s),e.t=Te(i,c,e.t),l!==e.a&&F(i,`title`,e.a=l),u!==e.o&&I(a,e.o=u),d!==e.i&&I(o,e.i=d),f!==e.n&&F(o,`title`,e.n=f),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),i})()})),L(d,A(M,{get when(){return D()},get children(){var e=Lc(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;se(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),L(e,A(M,{get when(){return!oe()},get fallback(){return[(()=>{var e=Xl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{le(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),L(t,A(j,{get each(){return Af.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=Ql();return L(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=ce()),e})(),(()=>{var e=Zl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{de(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),L(t,A(j,{get each(){return Af.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=Ql();return L(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=ue()),e})()]},get children(){var e=Ic();return L(e,A(j,{each:Af,children:e=>(()=>{var t=$l(),n=t.firstChild;return t.$$click=()=>{ae(e.key),localStorage.setItem(`teapot.theme`,e.key)},L(n,()=>e.sw.map(e=>(()=>{var t=eu();return Ee(t,`background`,e),t})())),L(t,()=>e.label,null),y(n=>{var r=`themebtn`+(O()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&I(t,n.e=r),i!==n.t&&F(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=oe()),e}}),f),m.$$click=e=>{e.stopPropagation(),rt(!nt()),nt()||$e(e=>e.map(e=>({...e,read:!0})))},L(m,A(M,{get when(){return it()>0},get children(){var e=Rc();return L(e,it),e}}),null),L(f,A(Zf,{icon:`👻`,get active(){return et()},get title(){return et()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!et();if(tt(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&B()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&nn(t.id)}}}),null),L(f,A(Zf,{icon:`+`,title:`new agent`,onClick:()=>{gt(),te(!0)}}),null),L(f,A(Zf,{icon:`🎨`,title:`themes`,onClick:()=>ie(!D())}),null),L(f,A(Zf,{icon:`⚙`,title:`settings`,onClick:()=>{gt(),T(!0)}}),null),L(v,`0.22.7`,null),L(ee,A(M,{get when(){return u()},get children(){return[`master rss `,N(()=>u().rssMb),`MB · heap `,N(()=>u().heapUsedMb),`MB`,zc(),`load1 `,N(()=>u().loadavg1),` · up `,N(()=>Math.floor(u().uptimeSec/60)),`m`]}})),L(C,A(M,{get when(){return B()},get fallback(){return tu()},get children(){return[(()=>{var e=Uc(),t=e.firstChild.nextSibling,n=t.nextSibling,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling.nextSibling,s=o.nextSibling.nextSibling;s.nextSibling;var c=r.nextSibling;return L(t,()=>B().id),L(n,()=>B().status),L(e,A(M,{get when(){return(B().pendingPrompts??0)>0},get children(){var e=Bc(),t=e.firstChild.nextSibling;return t.nextSibling,L(e,()=>B().pendingPrompts,t),y(()=>F(e,`title`,`${B().pendingPrompts??0} message${(B().pendingPrompts??0)>1?`s`:``} from you waiting in the queue. They will be handed to the model at its next turn boundary — the timeline shows them as "pending (queued)…" until then, and each can be withdrawn with ✕ cancel while it's still queued.`)),e}}),r),L(e,A(M,{get when(){return Nt(B().id).length>0},get children(){var e=Vc();return e.firstChild,L(e,()=>Nt(B().id).length,null),y(()=>F(e,`title`,`scheduled tasks:\n${Nt(B().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
25
+ `)}`)),e}}),r),L(r,()=>B().model,i),L(r,()=>B().session,a),L(r,()=>B().branch,o),L(r,()=>B().stats.turns,s),L(r,()=>B().stats.toolCalls,null),L(c,A(M,{get when(){return B().statusReason},get children(){var e=Hc();return y(()=>F(e,`title`,B().statusReason)),e}}),null),L(c,A(Zf,{icon:`⌨`,title:`terminal (t)`,onClick:mn}),null),L(c,A(Zf,{icon:`▤`,title:`toggle details panel (d)`,onClick:re}),null),y(()=>I(n,`badge ${B().status}`)),e})(),(()=>{var e=Xc();return e.addEventListener(`scroll`,e=>{if(tr)return;let t=e.currentTarget,r=en(),a=t.scrollHeight-t.scrollTop-t.clientHeight;if(!r&&rr!==void 0&&a>rr+8&&a>24?nr=!0:r&&(nr=!1),rr=a,nr&&!r){Ae(!1);return}r&&je()&&Me(0),Ae(r),t.scrollTop<=4&&n()&&!Ut()&&!Gt()&&i().length>0&&Zt()}),L(e,A(M,{get when(){return Ne()},children:e=>(()=>{var t=nu();return t.firstChild,L(t,(()=>{var t=N(()=>e().phase===`harvesting`);return()=>t()?`saving durable lessons…`:`summarizing ${e().summarized?Jf(e().summarized)+` `:``}older messages…`})(),null),t})()}),null),L(e,A(M,{get when(){return N(()=>!!Gt())()&&pt().length>0},get children(){return Wc()}}),null),L(e,A(M,{get when(){return Ut()},get children(){return Gc()}}),null),L(e,A(M,{get when(){return pt().length>0},get fallback(){return ru()},get children(){return[A(j,{get each(){return pt()},children:(e,t)=>A(Uf,{e,get prev(){return pt()[t()-1]},get res(){return dt().resFor.get(e.id)},onOption:e=>void sr(e),get answeredIds(){return ft()},get agentActive(){return B()?.status===`running`||B()?.status===`waiting`},onResize:()=>{ke()&&requestAnimationFrame(()=>tn(!0))},get onCancel(){return e.data?.pending&&e.data?.promptId&&e.data?.sent!==!0?()=>{let t=String(e.data.promptId);$(`/api/agents/${n()}/prompt/cancel`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({promptId:t})}).then(e=>{let n=String(e.text??``);h(p()?`${n}\n\n${p()}`:n),Ze(e=>e.filter(e=>e.promptId!==t)),Q(`message withdrawn — draft restored`)}).catch(()=>Q(`withdraw failed — it may have already been sent`))}:void 0},get onEdit(){return e.type===`prompt`&&e.data?.source===`user`?()=>Ye({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),A(M,{get when(){return Be()},get children(){var e=Yc(),t=e.firstChild.nextSibling;return t.firstChild,L(t,A(M,{get when(){return Ge()},get children(){var e=Kc(),t=e.firstChild;t.firstChild;var n=t.nextSibling;return L(t,A(Bf,{get startedAt(){return We()}}),null),De(e=>{let t=!0;e.addEventListener(`scroll`,()=>{t=e.scrollHeight-e.scrollTop-e.clientHeight<24}),b(()=>{Ge(),t&&(e.scrollTop=e.scrollHeight)})},n),L(n,Ge),e}}),null),L(t,A(M,{get when(){return He()},get fallback(){return iu()},get children(){return A(M,{get when(){return Ie()},get fallback(){return(()=>{var e=Jc();return y(()=>e.innerHTML=Fe(He()+`▍`)),e})()},get children(){return[qc(),(()=>{var e=Jc();return y(()=>e.innerHTML=Fe(Le()+`▍`)),e})()]}})}}),null),e}})]}}),null),e})(),A(M,{get when(){return fn()},get children(){var t=tl(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=r.nextSibling,c=s.firstChild;n.$$dblclick=()=>{Tn(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(wn()))},n.$$pointerdown=In,L(i,A(j,{get each(){return hn()},children:(e,t)=>(()=>{var n=au(),r=n.firstChild.nextSibling;return n.$$click=()=>kn(t()),L(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),Mn(t())},y(r=>{var i=`termtab`+(Sn()===0&&_n()===t()?` active`:``)+(W()&&Sn()===1&&yn()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&I(n,r.e=i),a!==r.t&&F(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),null),L(i,A(Zf,{icon:`+`,title:`new shell in this workspace`,onClick:An}),null),L(o,(()=>{var t=N(()=>!!On());return()=>t()?e().find(e=>e.id===On().agentId)?.workspace.split(`/`).filter(Boolean).pop():B()?.workspace})()),L(a,A(Zf,{icon:`◫`,get title(){return W()?`single pane`:`split panes (50/50)`},onClick:Ln}),null),L(a,A(Zf,{icon:`▾`,title:`hide the terminal (shells keep running; reopen with t) — close individual shells with their ✕ tab buttons`,onClick:mn}),null);var l=Rn(0);return typeof l==`function`&&De(l,c),c.$$pointerdown=()=>Cn(0),L(c,A(M,{get when(){return _n()<0||_n()>=hn().length},get children(){return Zc()}})),L(s,A(M,{get when(){return W()},get children(){return[Qc(),(()=>{var e=el(),t=Rn(1);return typeof t==`function`&&De(t,e),e.$$pointerdown=()=>Cn(1),L(e,A(M,{get when(){return yn()<0||yn()>=hn().length},get children(){return $c()}})),y(()=>e.classList.toggle(`focused`,Sn()===1)),e})()]}}),null),y(e=>{var n={height:`${wn()}px`,"--termh":`${wn()}px`},r=!!W(),i=Sn()===0;return e.e=Te(t,n,e.e),r!==e.t&&s.classList.toggle(`split`,e.t=r),i!==e.a&&c.classList.toggle(`focused`,e.a=i),e},{e:void 0,t:void 0,a:void 0}),t}}),(()=>{var e=sl(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling,o=t.nextSibling;L(e,A(M,{get when(){return!ke()||je()>0},get children(){var e=nl();return e.firstChild,e.$$click=()=>tn(!0),L(e,(()=>{var e=N(()=>je()>0);return()=>e()?`${je()} new message${je()>1?`s`:``}`:`jump to present`})(),null),e}}),t),L(e,A(M,{get when(){return Qn().length>0},get children(){var e=rl();return L(e,A(j,{get each(){return Qn()},children:(e,t)=>(()=>{var n=ou(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{h(e.insert),Zn(-1)},L(r,()=>e.insert.trim()),L(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===Xn()?` active`:``),a=e.title;return i!==r.e&&I(n,r.e=i),a!==r.t&&F(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),L(e,A(M,{get when(){return Kn().length>0},get children(){var e=rl();return L(e,A(j,{get each(){return Kn()},children:e=>(()=>{var t=su(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{h(`@${e.key} `),Zn(-1)},L(n,()=>e.key,null),L(r,()=>e.label),y(()=>F(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,cr),L(t,A(M,{get when(){return ir().length>0},get children(){var e=il(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return r.nextSibling,L(e,A(j,{get each(){return ir()},children:(e,t)=>(()=>{var n=cu(),r=n.firstChild,i=r.nextSibling;return i.$$click=()=>ar(e=>e.filter((e,n)=>n!==t())),y(t=>{var i=e.name,a=e.url,o=e.name;return i!==t.e&&F(n,`title`,t.e=i),a!==t.t&&F(r,`src`,t.t=a),o!==t.a&&F(r,`alt`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),n})()}),t),L(t,()=>ir().length,n),L(t,()=>ir().length>1?`s`:``,r),e}}),n),n.$$keydown=e=>{let t=Qn();if(t.length>0&&e.key===`ArrowDown`){e.preventDefault(),Zn(e=>Math.min(e+1,t.length-1));return}if(t.length>0&&e.key===`ArrowUp`){e.preventDefault(),Zn(e=>Math.max(e-1,0));return}if(t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&Xn()>=0){e.preventDefault(),h(t[Xn()].insert),Zn(-1);return}if(e.key===`Escape`&&t.length>0){Zn(-1);return}e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),cr(e))},n.$$input=e=>{h(e.currentTarget.value),Zn(0),er()},n.addEventListener(`paste`,e=>{let t=Array.from(e.clipboardData?.files??[]).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),or(t))});var s=$n;return typeof s==`function`?De(s,n):$n=n,L(t,A(M,{get when(){return N(()=>!!p().startsWith(`@`))()&&p().includes(` `)},get children(){var e=al(),t=e.firstChild;return t.addEventListener(`change`,e=>Wn(e.currentTarget.checked)),y(()=>t.checked=Un()),e}}),r),r.$$click=()=>{let e=!Ce();Oe(e),requestAnimationFrame(()=>er())},L(r,()=>Ce()?`⤡`:`⤢`),L(t,A(Zf,{icon:`📎`,title:`attach images (or paste them straight into the box)`,onClick:()=>document.getElementById(`composer-file`)?.click()}),i),L(t,A(M,{get when(){return ir().length},get children(){var e=ol();return e.firstChild,L(e,()=>ir().length,null),e}}),i),a.addEventListener(`change`,e=>{e.currentTarget.files?.length&&or(e.currentTarget.files),e.currentTarget.value=``}),L(o,()=>Df()||`enter send · shift+enter newline · ↑↓ sessions · / commands & focus · t terminal · d panel · esc interrupt · messages sent while the agent works queue up and land at the next turn boundary`),y(t=>{var i=`composer`+(Ce()?` maximized`:``),a=`message #${B().id} — / for commands · paste or 📎 to attach images`,o=Ce()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&I(e,t.e=i),a!==t.t&&F(n,`placeholder`,t.t=a),o!==t.a&&F(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),y(()=>n.value=p()),e})()]}})),w.addEventListener(`scroll`,e=>{dr=e.currentTarget.scrollTop});var E=ur;return typeof E==`function`?De(E,w):ur=w,L(w,A(M,{get when(){return B()},get children(){return[cl(),(()=>{var e=ll(),t=e.firstChild,n=t.firstChild.nextSibling,r=n.nextSibling,i=t.nextSibling,a=i.firstChild.nextSibling,o=i.nextSibling.firstChild.nextSibling,s=o.firstChild;return L(n,()=>B().id),L(r,()=>B().status),L(a,()=>B().workspace),L(o,()=>B().session,s),L(o,()=>B().branch,null),y(e=>{var t=`badge ${B().status}`,n=B().workspace;return t!==e.e&&I(r,e.e=t),n!==e.t&&F(a,`title`,e.t=n),e},{e:void 0,t:void 0}),e})(),A(M,{get when(){return B().id},keyed:!0,fallback:null,children:e=>A(op,{agentId:e,get workspace(){return B().workspace}})}),ul(),(()=>{var e=fl(),t=e.firstChild,r=t.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=r.nextSibling;return s.firstChild,t.addEventListener(`change`,e=>{he(e.currentTarget.value),xe(e.currentTarget.value)}),L(t,A(j,{get each(){return be()},children:e=>(()=>{var t=Ql();return t.value=e,L(t,e,null),L(t,()=>e===g().defaultProvider?` ★`:``,null),t})()})),i.$$input=e=>_e(e.currentTarget.value),L(a,A(j,{get each(){return ve()},children:e=>(()=>{var t=Ql();return y(()=>t.value=e.id),t})()})),o.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await $(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provider:me(),model:ge().trim()||void 0,contextWindowTokens:ve().find(e=>e.id===(ge().trim()||void 0))?.contextLength})}),t.textContent=`✓ applied`,Ot()}catch(e){alert(`model switch failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},L(s,()=>B().model,null),L(s,A(M,{get when(){return ve().length},get children(){return[` · `,N(()=>ve().length),` models loaded`]}}),null),L(e,A(M,{get when(){return P()},get children(){var e=dl();return L(e,P),e}}),null),y(()=>F(i,`placeholder`,B().model)),y(()=>t.value=me()),y(()=>i.value=ge()),e})(),pl(),(()=>{var i=hl(),o=i.firstChild,s=o.nextSibling,c=s.nextSibling;return we(o,`click`,B().status===`running`?fr(`/stop`):fr(`/start`),!0),L(o,()=>B().status===`running`?`■ stop`:`▶ start`),s.$$click=()=>$(`/api/agents/${B().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(()=>nn(B().id)),c.$$click=async()=>{let i=n();if(!i||!confirm(`remove agent ${i}? (log is kept)`))return;await $(`/api/agents/${i}`,{method:`DELETE`}).catch(()=>{});let o=e().filter(e=>e.id!==i);t(o),o[0]?nn(o[0].id):(r(null),a([]))},L(i,A(M,{get when(){return e().some(e=>e.parent===n())},get children(){var e=ml();return e.$$click=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),Ot())},e}}),null),y(e=>{var t=B().status===`running`?`danger`:`runbtn`,n=B().status===`running`?`interrupt: aborts the current LLM call; the running tool finishes first`:`run toward the goal (starts the loop)`;return t!==e.e&&I(o,e.e=t),n!==e.t&&F(o,`title`,e.t=n),e},{e:void 0,t:void 0}),i})(),(()=>{var e=gl(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-continue`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(Ot)}),y(()=>t.checked=B().autoContinue??!0),e})(),(()=>{var e=vl();return e.firstChild,L(e,A(M,{get when(){return!!B().goal.text.trim()},get fallback(){return lu()},get children(){var e=_l();return L(e,()=>B().goal.status),y(()=>I(e,`badge ${B().goal.status===`active`?`running`:B().goal.status}`)),e}}),null),e})(),(()=>{var e=yl();return e.firstChild,L(e,A(j,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=uu();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(Ot)},F(t,`title`,e===`active`?`agent keeps working toward the goal (with auto-continue)`:e===`done`?`mark achieved — auto-continue stops`:`parked on purpose — resume by setting active again`),L(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(B().goal.text.trim()&&B().goal.status===e?` on ${e}`:``),i=!!B().goal.text.trim()&&B().goal.status===e;return r!==n.e&&I(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),A(M,{get when(){return B().goal.text},get fallback(){return du()},get children(){return[(()=>{var e=bl(),t=e.firstChild;return y(()=>t.innerHTML=Fe(String(B().goal.text))),e})(),A(M,{get when(){return B().goal.verify},get children(){var e=xl(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Fe(String(B().goal.verify))),e}}),A(M,{get when(){return B().goal.audit},children:e=>(()=>{var t=fu(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return L(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),L(r,()=>qf(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=Fe(e().feedback);return r!==n.e&&I(t,n.e=r),a!==n.t&&(i.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t})()})]}}),Sl(),(()=>{var e=Cl(),t=e.firstChild,n=t.nextSibling,r=n.nextSibling.firstChild.firstChild;return e.addEventListener(`submit`,Sr),t.$$input=e=>{mr(e.currentTarget.value),vr(!0)},n.$$input=e=>{gr(e.currentTarget.value),vr(!0)},r.addEventListener(`change`,e=>br(e.currentTarget.checked)),y(()=>t.value=pr()),y(()=>n.value=hr()),y(()=>r.checked=yr()),e})(),(()=>{var e=Tl(),t=e.firstChild.nextSibling;return L(e,A(M,{get when(){return Dt().total>0},get children(){var e=wl(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,L(e,()=>Dt().done,t),L(e,()=>Dt().total,n),y(t=>Te(e,Dt().done===Dt().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),A(M,{get when(){return Dt().total>0},get children(){var e=El(),t=e.firstChild;return y(e=>{var n=`barfill `+(Dt().done===Dt().total?``:`warn`),r=`${Math.round(Dt().done/Dt().total*100)}%`;return n!==e.e&&I(t,e.e=n),r!==e.t&&Ee(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),A(M,{get when(){return xt()},get fallback(){return(()=>{var e=pu();return y(()=>e.innerHTML=wf(yt())),e})()},get children(){var e=Dl();return e.$$input=e=>{bt(e.currentTarget.value),wt(!0)},y(()=>e.value=yt()),e}}),(()=>{var e=Ol(),t=e.firstChild,n=t.nextSibling;return L(e,A(Zf,{get icon(){return xt()?`👁`:`✎`},get title(){return xt()?`rendered checklist`:`edit markdown`},onClick:()=>St(!xt())}),t),n.$$click=Et,e})(),kl(),A(M,{get when(){return B().latestProgress},get fallback(){return mu()},children:e=>(()=>{var t=yu(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return L(t,A(M,{get when(){return e().recent},get children(){var t=hu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=wf(e().recent)),t}}),i),L(t,A(M,{get when(){return e().problems},get children(){var t=gu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=wf(e().problems)),t}}),i),L(t,A(M,{get when(){return e().next},get children(){var t=_u(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=wf(e().next)),t}}),i),L(t,A(M,{get when(){return e().goalStatus},get children(){var t=vu(),n=t.firstChild.nextSibling;return L(n,()=>e().goalStatus),t}}),i),L(i,()=>qf(e().ts)),y(()=>r.innerHTML=wf(e().doing)),t})()}),Al(),(()=>{var e=Nl(),t=e.firstChild,r=t.firstChild,i=r.firstChild.nextSibling,a=r.nextSibling,o=a.firstChild.nextSibling,s=a.nextSibling.firstChild.nextSibling,c=t.nextSibling,l=c.firstChild.nextSibling,u=l.firstChild,d=u.nextSibling;return d.nextSibling,L(i,()=>B().stats.turns),L(o,()=>B().stats.toolCalls),L(s,()=>B().stats.compactions??0),L(l,()=>Jf(B().stats.inputTokens),u),L(l,()=>Jf(B().stats.outputTokens),d),L(c,A(M,{get when(){return(B().stats.cachedInputTokens??0)>0},get children(){var e=jl(),t=e.firstChild.nextSibling;return t.nextSibling,L(e,()=>Math.round(B().stats.cachedInputTokens/Math.max(1,B().stats.inputTokens)*1e3)/10,t),y(()=>F(e,`title`,`${Jf(B().stats.cachedInputTokens)} tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),L(e,A(M,{get when(){return(B().stats.costUsd??0)>0},get children(){var e=Ml(),t=e.firstChild.nextSibling;return t.firstChild,L(t,()=>Yf(B().stats.costUsd??0),null),y(()=>F(e,`title`,`≈ ${(B().stats.costUsd??0).toFixed(4)} this session, from the model's USD/token pricing and per-turn usage. Cached input is estimated at ~10% of the prompt rate; treat as an approximation, not an invoice.`)),e}}),null),L(e,A(M,{get when(){return B().ctx},keyed:!0,get fallback(){return bu()},children:e=>{let t=x(()=>{let t=e,n=ve().find(e=>e.id===B().model),r=t.window||n?.contextLength||0,i=r?Math.min(999,t.usedTokens/r*100):0;return{usedTokens:t.usedTokens,compactAt:t.compactAt,compacting:t.compacting,window:t.window,effectiveWindow:r,pct:i,cls:r?i>=85?`crit`:i>=70?`warn`:`ok`:``,derivedBudget:r?Math.round(r*.75):0,usingDerived:t.compactAtIsManual!==!0}}),r=()=>t(),i=e=>{let t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)};return(()=>{var e=Tu(),t=e.firstChild,a=t.firstChild.nextSibling,o=a.firstChild.nextSibling;o.nextSibling;var s=t.nextSibling,c=s.firstChild.nextSibling,l=c.firstChild,u=c.nextSibling,d=s.nextSibling,f=d.firstChild.firstChild,p=d.nextSibling,m=p.firstChild.nextSibling;return m.nextSibling,L(a,()=>Jf(r().usedTokens),o),L(t,A(M,{get when(){return r().effectiveWindow},get children(){var e=xu(),t=e.firstChild;return L(e,()=>i(r().pct),t),L(e,()=>Jf(r().effectiveWindow),null),y(()=>I(e,`pill ${r().cls}`)),e}}),null),L(e,A(M,{get when(){return r().effectiveWindow},get children(){var e=Su(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,r().pct)}%`;return n!==e.e&&I(t,e.e=n),i!==e.t&&Ee(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),s),L(c,()=>Jf(r().usingDerived?r().derivedBudget:r().compactAt),l),L(u,()=>r().usingDerived?` (75% of window)`:` (manual override)`),L(e,A(M,{get when(){return r().effectiveWindow},get children(){var e=Cu(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,Math.round(r().usedTokens/r().derivedBudget*100))}%`;return n!==e.e&&I(t,e.e=n),i!==e.t&&Ee(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),d),L(e,A(M,{get when(){return Ne()||r().compacting},get children(){var e=wu(),t=e.firstChild.nextSibling.nextSibling;return L(t,()=>Ne()?.phase??String(r().compacting)),e}}),d),f.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(Ot)}),L(p,()=>Jf(r().compactAt),m),y(()=>f.checked=B().autoCompact!==!1),e})()}}),null),e})(),Pl(),A(j,{get each(){return c()},children:e=>(()=>{var t=Eu(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=Rt()===e.branch?null:e.branch;zt(t),n()&&Qt(n())},L(r,()=>e.branch,null),L(r,()=>e.branch===B().branch?` (current)`:``,null),L(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===B().branch||e.branch===Rt()?` cur`:``),i=e.branch===Rt()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&I(t,n.e=r),i!==n.t&&F(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),Fl(),A(M,{get when(){return At().length>0},get fallback(){return Du()},get children(){return A(j,{get each(){return At()},children:e=>(()=>{var t=ku(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>nn(e.agent),L(i,()=>e.id),L(a,()=>e.agent,null),L(r,A(M,{get when(){return e.forked},get children(){return Ou()}}),null),L(o,()=>e.schedule,s),L(o,(()=>{var t=N(()=>!!e.next);return()=>t()?qf(e.next):`—`})(),null),L(o,(()=>{var t=N(()=>!!e.last);return()=>t()?` · last ${qf(e.last)}`:` · never ran`})(),null),L(c,()=>Xf(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${Xf(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&I(t,r.e=i),a!==r.t&&F(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}})),y(e=>{var t=`layout`+(ne()?``:` right-hidden`),n=`iconbtn notifbtn`+(it()>0?` has-unread`:``),r=it()>0?`${it()} unread notifications`:`notifications`,i=`conn`+(rn()?` ok`:``),a=rn()?`live (websocket)`:`reconnecting…`,s=`rightbar`+(ne()?` open`:``);return t!==e.e&&I(o,e.e=t),n!==e.t&&I(m,e.t=n),r!==e.a&&F(m,`title`,e.a=r),i!==e.o&&I(S,e.o=i),a!==e.i&&F(S,`title`,e.i=a),s!==e.n&&I(w,e.n=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),o}}),A(M,{get when(){return nt()},get children(){return[(()=>{var e=Ll();return e.$$click=()=>rt(!1),e})(),(()=>{var t=Bl(),r=t.firstChild.firstChild.nextSibling,i=r.firstChild;return L(r,A(M,{get when(){return Qe().length>0},get children(){var e=Rl();return e.$$click=()=>$e([]),e}}),i),i.$$click=()=>rt(!1),L(t,A(M,{get when(){return Qe().length>0},get fallback(){return Au()},get children(){var t=zl();return L(t,A(j,{get each(){return Qe()},children:t=>(()=>{var r=Mu(),i=r.firstChild.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling;return r.$$click=()=>{$e(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e)),n()!==t.agentId&&e().some(e=>e.id===t.agentId)&&nn(t.agentId),rt(!1),t.eventId&&setTimeout(()=>ut(t.eventId),n()===t.agentId?60:350)},L(i,(()=>{var e=N(()=>t.kind===`finish`);return()=>e()?`✅`:N(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),L(a,()=>t.title),L(o,()=>qf(new Date(t.at).toISOString())),s.$$click=e=>{e.stopPropagation(),$e(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e))},L(s,()=>t.read?`✓`:`○`),L(r,A(M,{get when(){return t.body},get children(){var e=ju();return L(e,()=>Kf(t.body,160)),e}}),null),y(e=>{var n=`notifitem `+t.kind+(t.read?` read`:``),i=`from ${t.agentId}`,a=t.read?`already read`:`mark as read`;return n!==e.e&&I(r,e.e=n),i!==e.t&&F(r,`title`,e.t=i),a!==e.a&&F(s,`title`,e.a=a),e},{e:void 0,t:void 0,a:void 0}),r})()})),t}}),null),t})()]}}),A(M,{get when(){return S()},get children(){return A(ep,{get providers(){return Object.keys(g().providers??{})},onClose:()=>te(!1),onCreated:e=>{te(!1),Ot(),nn(e)}})}}),A(M,{get when(){return w()},get children(){return A(dp,{get cfg(){return g()},onClose:()=>T(!1),onSaved:()=>{gt(),Mt()}})}}),A(M,{get when(){return Je()},fallback:null,children:e=>{let t=()=>i().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,i().length-t()-1),[a,o]=v(r()>0?`summarize`:`discard`);return A($f,{title:`edit prompt — forks the conversation`,onClose:()=>Ye(null),get children(){var t=Pu(),i=t.firstChild,s=i.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await $(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:a()})}),Ye(null),Ot();let t=n();t&&await nn(t)}catch(e){alert(`edit failed: ${e.message}`)}}),L(t,A(M,{get when(){return r()>0},get children(){var e=Nu(),t=e.firstChild,n=t.firstChild,i=t.nextSibling,s=i.firstChild,c=i.nextSibling.firstChild;return L(t,r,n),s.addEventListener(`change`,()=>o(`summarize`)),c.addEventListener(`change`,()=>o(`discard`)),y(()=>s.checked=a()===`summarize`),y(()=>c.checked=a()===`discard`),e}}),s),c.$$click=()=>Ye(null),y(()=>i.value=e().text),t}})}})]}function zf(e){let t=new Date(e.startedAt).getTime(),[n,r]=v(Date.now());ee(()=>{let e=setInterval(()=>r(Date.now()),500);C(()=>clearInterval(e))});let i=()=>Math.max(0,(n()-t)/1e3),a=()=>i()<60?`${i().toFixed(1)}s`:`${Math.floor(i()/60)}m ${Math.round(i()%60)}s`;return e.inline?(()=>{var t=Fu();return t.firstChild,L(t,a,null),L(t,(()=>{var t=N(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=Iu(),t=e.firstChild;return L(e,a,t),e})()}function Bf(e){let[t,n]=v(Date.now());ee(()=>{let e=setInterval(()=>n(Date.now()),500);C(()=>clearInterval(e))});let r=()=>Math.max(0,(t()-e.startedAt)/1e3);return(()=>{var e=Lu();return L(e,(()=>{var e=N(()=>r()<60);return()=>e()?`${r().toFixed(0)}s`:`${Math.floor(r()/60)}m ${Math.round(r()%60)}s`})()),e})()}function Vf(e){let t=e.e,n=e.res,r=!e.agentActive&&!n,i=t.data??{},a=String(i.name??`tool`),o=()=>n?String(n.data?.result??``):``,s=a,c=``,l=(()=>{var e=Ru();return L(e,()=>Kf(JSON.stringify(i.args??{},null,1),2e3)),e})(),u=e=>String(i.args?.[e]??``),d=()=>a===`bash`?u(`command`):u(`path`)||JSON.stringify(i.args??{},null,1),f=()=>a===`bash`?Number(u(`timeout_ms`))||void 0:a===`wait_children`?Number(u(`timeout_ms`))||3e5:Number(u(`timeout_ms`))||void 0,p=(e,t=1500)=>(()=>{var n=zu();return L(n,()=>Kf(e,t)),n})(),m=(e=4e3)=>n?[N(()=>p(o(),e)),(()=>{var e=Bu(),t=e.firstChild;return L(e,()=>n.data?.durationMs,t),L(e,()=>n.data?.ok===!1?` · FAILED`:``,null),L(e,A(Qf,{get text(){return o()}}),null),e})()]:Vu();try{switch(a){case`bash`:{let e=u(`command`),t=i.args?.background===!0,r=t?String(o()).match(/job (bg\d+)/)?.[1]??``:``;s=(t?`⏳ `:`$ `)+Xf(e,96);let a=u(`timeout_ms`)?` · timeout ${Math.round(Number(u(`timeout_ms`))/1e3)}s`:``;c=n?t?`background job${r?` ${r}`:``}${a}`:`${n.data?.durationMs??`?`}ms${a}`:null,l=[t?(()=>{var e=Hu(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling;return n.nextSibling,L(t,r||`?`,n),L(e,r?[` · kill with `,Uu()]:null,null),e})():null,N(()=>N(()=>e!==s.slice(2))()?p(e,800):null),N(()=>m(6e3))];break}case`read_file`:{s=u(`path`)||`(no path)`;let e=[];u(`pattern`)&&e.push(`grep /${Xf(u(`pattern`),40)}/`),Number(i.args?.offset)<0?e.push(`last ${-Number(i.args.offset)} lines`):i.args?.offset&&e.push(`from L${i.args.offset}`),i.args?.limit&&e.push(`≤${i.args.limit} lines`),c=e.join(` · `),l=m(6e3);break}case`write_file`:{let e=String(i.args?.content??``);s=u(`path`)||`(no path)`,c=`${Jf(e.length)} bytes`,l=[N(()=>p(e,1500)),N(()=>N(()=>e.length>1500)()?(()=>{var t=Wu(),n=t.firstChild;return L(t,()=>Jf(e.length),n),t})():null),n?(()=>{var e=Gu();return L(e,()=>Xf(o(),160)),e})():Ku()];break}case`edit_file`:s=u(`path`)||`(no path)`,c=i.args?.replace_all===!0?`replace all`:`unique spot`,l=[(()=>{var e=qu();return L(e,()=>Kf(`- `+u(`old_text`),900)),e})(),(()=>{var e=Ju();return L(e,()=>`+ `+Kf(u(`new_text`),900)),e})(),n?(()=>{var e=Yu(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,L(e,()=>Xf(o(),120),t),L(e,()=>n.data?.durationMs,r),e})():Xu()];break;case`apply_patch`:{let e=u(`patch`).split(`
26
26
  `).filter(e=>e&&!/^---$/.test(e.trim())),t=e.map(e=>e.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/)?.[1]).filter(Boolean);s=t.length?`${t.length} file${t.length>1?`s`:``}: ${Xf(t.join(`, `),80)}`:`patch`;let r=e.slice(0,60);l=[(()=>{var t=Zu();return L(t,()=>r.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=Qu();return I(n,`pline`+t),L(n,(()=>{var t=N(()=>e.length>240);return()=>t()?e.slice(0,240)+`…`:e})()),n})()}),null),L(t,(()=>{var t=N(()=>e.length>60);return()=>t()?(()=>{var t=$u(),n=t.firstChild.nextSibling;return n.nextSibling,L(t,()=>e.length-60,n),t})():null})(),null),t})(),n?(()=>{var e=Gu();return L(e,()=>Xf(o().split(`
27
- `)[0]??``,140),null),L(e,()=>n.data?.ok===!1?` · FAILED`:``,null),e})():ed()];break}case`list_dir`:s=u(`path`)||`.`,l=m(4e3);break;case`read_url`:{let e=u(`url`);try{let t=new URL(e);e=t.host+t.pathname}catch{}s=Xf(e,70),c=`web`,l=[(()=>{var e=Gu();return L(e,A(M,{get when(){return/^https?:/i.test(u(`url`))},get fallback(){return(()=>{var e=nd();return L(e,()=>Xf(u(`url`),80)),e})()},get children(){var e=td();return y(()=>F(e,`href`,u(`url`))),e}})),e})(),N(()=>m(3e3))];break}case`bash_output`:{let e=u(`action`)||`read`;s=`bash_output ${u(`job_id`)||`(?)`}`,c=e,l=m(4e3);break}case`load_skill`:{s=`skill: ${u(`name`)}`;let e=o().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);l=n?[(()=>{var t=Jc();return y(()=>t.innerHTML=Fe(e)),t})(),(()=>{var e=Bu(),t=e.firstChild;return L(e,()=>n.data?.durationMs,t),e})()]:rd();break}case`save_skill`:{s=`skill: ${u(`name`)}`,c=Xf(u(`description`),60);let e=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];l=[N(()=>N(()=>!!e.length)()?(()=>{var t=id();return t.firstChild,L(t,()=>e.join(`, `),null),t})():null),n?(()=>{var e=Yu(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,L(e,()=>Xf(o(),160),t),L(e,()=>n.data?.durationMs,r),e})():ad()];break}}}catch{}return(()=>{var i=sd(),u=i.firstChild,p=u.firstChild;p.firstChild;var m=p.nextSibling,h=m.nextSibling;return i.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),F(i,`title`,`${a}${c?` — `+c:``}`),L(p,s,null),L(u,A(M,{get when(){return t.data?.actor},get children(){var e=od();return e.firstChild,L(e,()=>String(t.data.actor),null),e}}),m),L(m,()=>n?c||``:r?`(result missed)`:a===`bash`||f()?A(zf,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return f()}}):`running…`),L(h,A(Qf,{get text(){return d()},label:`⧉ cmd`,title:`copy the ${a} arguments`}),null),L(h,A(M,{when:n,get children(){return A(Qf,{get text(){return o()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),L(i,l,null),y(()=>I(i,`embed`+(n?n.data?.ok===!1?` fail`:` done`:r?` done`:` running`))),i})()}function Hf(e){let t=e.data??{};return e.type===`prompt`?String(t.text??``):e.type===`message`?`${typeof t.reasoning==`string`&&t.reasoning.trim()?`<reasoning>\n${t.reasoning}\n</reasoning>\n\n`:``}${String(t.content??``)}`:(e.type,``)}function Uf(e){let t=e.e,n=Mf(t),r=e=>{let t=e.data??{};return e.data?.actor?`sub:${String(e.data.actor)}`:e.type===`tool_call`||e.type===`tool_result`?`agent-tools`:e.type===`prompt`?`src:${String(t.source??`user`)}`:`type:${e.type}`},i=e.prev&&r(e.prev)===r(t)&&Mf(e.prev).name===n.name&&t.session===e.prev.session&&t.branch===e.prev.branch;if(t.type===`fork`){let e=t.data??{};return(()=>{var n=cd(),r=n.firstChild.nextSibling;return r.nextSibling,L(n,()=>String(e.fromBranch??`?`),r),L(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=t.data??{},n=e.event===`status`?`marked ${String(e.status??``)}`:Xf(String(e.text??``),80);return(()=>{var t=ld(),r=t.firstChild.nextSibling;return r.nextSibling,L(t,()=>String(e.event??``),r),L(t,n,null),t})()}if(t.type===`todo`)return(()=>{var e=ud(),n=e.firstChild.nextSibling;return n.nextSibling,L(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=dd(),n=e.firstChild;return L(e,()=>t.data.from,n),L(e,()=>t.data.to,null),L(e,(()=>{var e=N(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>I(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=fd(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,L(n,()=>String(t.data?.failures),r),L(n,()=>String(t.data?.limit),i),L(a,()=>String(t.data?.lastTool),o),L(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>F(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=pd(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,L(n,()=>String(t.data?.attempt),r),L(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=Qu();return I(r,`divider-msg`+(e?` err`:``)),L(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>F(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=md(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,L(e,()=>String(t.data?.tokensBefore??`?`),n),L(e,()=>String(t.data?.tokensAfter??`?`),r),L(e,()=>String(t.data?.mode??``),i),e})():null}return(()=>{var r=vd(),a=r.firstChild,o=a.nextSibling;return I(a,`avatar avghost`+(i?` ghosted`:``)),L(a,()=>i?``:n.icon),L(o,i&&(()=>{var e=yd();return y(()=>F(e,`title`,`${Ff(t.ts)} · ${t.branch}`)),e})(),null),L(o,A(M,{when:!i,get children(){var r=_d(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return L(i,()=>n.name),L(r,A(M,{get when(){return t.data?.actor},get children(){var e=od();return e.firstChild,L(e,()=>String(t.data.actor),null),e}}),a),L(a,(()=>{var e=N(()=>!!t.data?.pending);return()=>e()?`queued…`:Ff(t.ts)})()),L(o,()=>t.branch),L(r,A(M,{get when(){return e.onCancel},get children(){var t=hd();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),L(r,A(M,{get when(){return t.type!==`tool_call`},get children(){return A(Qf,{get text(){return Hf(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),L(r,A(M,{get when(){return e.onEdit},get children(){var t=gd();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Ee(i,`color`,n.color)),r}}),null),L(o,A(Gf,{e:t,get res(){return e.res},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get agentActive(){return e.agentActive},get onResize(){return e.onResize}}),null),y(e=>{var o=`msg`+(i?` grouped`:``)+(t.data?.pending?` pending`:``),s=t.id,c=i?`transparent`:n.color+`33`,l=i?`1px solid transparent`:`1px solid ${n.color}66`,u=i?`${Ff(t.ts)} · ${t.branch}`:void 0;return o!==e.e&&I(r,e.e=o),s!==e.t&&F(r,`data-eid`,e.t=s),c!==e.a&&Ee(a,`background`,e.a=c),l!==e.o&&Ee(a,`border`,e.o=l),u!==e.i&&F(a,`title`,e.i=u),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),r})()}function Wf(e){let[t,n]=v(``),r=()=>{let r=t().trim();!r||e.answered||(n(``),e.onOption?.(r))};return(()=>{var i=bd(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&F(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function Gf(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=Jc();return y(()=>e.innerHTML=wf(String(t.data.text??``))),e})(),A(M,{get when(){return e.length},get children(){var t=xd();return L(t,A(j,{each:e,children:e=>(()=>{var t=Sd();return F(t,`src`,e),t})()})),t}})]}case`message`:return[A(M,{get when(){return N(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=Cd(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return L(n,(()=>{var e=N(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Jf(String(t.data.reasoning).length)} — truncated)`:``})(),null),L(r,()=>Kf(String(t.data.reasoning),8e3)),e}}),(()=>{var e=Jc();return y(()=>e.innerHTML=wf(String(t.data.content??``))),e})(),A(M,{get when(){return t.data.interrupted},get children(){return wd()}}),A(M,{get when(){return t.data.final},get children(){var e=Td(),n=e.firstChild;return L(e,A(Qf,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return A(Vf,{e:t,get res(){return e.res},get agentActive(){return e.agentActive},get onResize(){return e.onResize}});case`tool_result`:{let e=String(t.data.result);return(()=>{var n=Ed(),r=n.firstChild,i=r.firstChild,a=r.nextSibling,o=a.nextSibling,s=o.firstChild;return L(i,()=>Xf(e,120)),L(r,A(Qf,{text:e}),null),L(a,()=>Kf(e,4e3)),L(o,()=>t.data.durationMs,s),L(o,()=>t.data.ok?``:` · FAILED`,null),y(()=>I(n,`embed`+(t.data.ok?``:` fail`))),n})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=Od(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return L(n,A(M,{get when(){return e.length},get children(){var t=Dd();return t.firstChild,L(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=wf(String(t.data?.decision??``)),r=wf(String(t.data?.rationale??``));return n!==e.e&&(i.innerHTML=e.e=n),r!==e.t&&(a.innerHTML=e.t=r),e},{e:void 0,t:void 0}),n})()}case`question`:{let n=Array.isArray(t.data?.options)?t.data.options:[],r=t.data?.callId?String(t.data.callId):``,i=e.answeredIds?.has(r)??!1;return(()=>{var r=jd(),a=r.firstChild;return a.firstChild,I(r,`embed question`+(i?` answered`:``)),L(a,()=>String(t.data?.question??``),null),L(r,A(M,{when:i,get children(){return kd()}}),null),L(r,A(M,{get when(){return n.length>0},get children(){var r=Ad();return L(r,A(j,{each:n,children:n=>(()=>{var r=Md();return r.$$click=()=>{let r=t.data?.actor;r?$(`/api/agents/${encodeURIComponent(String(r))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},r.disabled=i,L(r,n),r})()})),r}}),null),L(r,A(Wf,{answered:i,get onOption(){return e.onOption}}),null),r})()}case`progress`:return(()=>{var e=Nd(),n=e.firstChild.firstChild.nextSibling;return L(e,A(M,{get when(){return t.data.goalStatus},get children(){var e=vu(),n=e.firstChild.nextSibling;return L(n,()=>String(t.data.goalStatus)),e}}),null),L(e,A(M,{get when(){return t.data.recent},get children(){var e=hu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=wf(String(t.data.recent))),e}}),null),L(e,A(M,{get when(){return t.data.problems},get children(){var e=gu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=wf(String(t.data.problems))),e}}),null),L(e,A(M,{get when(){return t.data.next},get children(){var e=_u(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=wf(String(t.data.next))),e}}),null),y(()=>n.innerHTML=wf(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=Pd(),n=e.firstChild;return n.firstChild,L(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=Id(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,L(n,()=>String(t.data.mode??``),r),L(n,()=>Jf(Number(t.data.tokensBefore??0)),i),L(n,()=>Jf(Number(t.data.tokensAfter??0)),a),L(n,(()=>{var e=N(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),L(e,A(M,{get when(){return t.data.summary},get children(){return[Fd(),(()=>{var e=Jc();return y(()=>e.innerHTML=wf(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=Ld();return L(e,()=>Kf(JSON.stringify(t.data),200)),e})()}}function Kf(e,t){return e.length>t?e.slice(0,t)+` …`:e}function qf(e){let t=new Date(e).getTime()-Date.now(),n=Math.abs(t),r=n<9e4?`${Math.round(n/1e3)}s`:n<54e5?`${Math.round(n/6e4)}m`:`${(n/36e5).toFixed(1)}h`;return t>=0?`in ${r}`:`${r} ago`}function Jf(e){return e>=1e9?`${+(e/1e9).toFixed(1)}b`:e>=1e6?`${+(e/1e6).toFixed(1)}m`:e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Yf(e){return e>=100?Math.round(e).toLocaleString():e>=10?e.toFixed(1):e>=1?e.toFixed(2):e>=.01?e.toFixed(3):e.toFixed(4)}function Xf(e,t){return Kf(e.replace(/\s+/g,` `).trim(),t)}function Zf(e){return(()=>{var t=Rd(),n=t.firstChild;return we(t,`click`,e.onClick,!0),L(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&I(t,n.e=r),i!==n.t&&F(t,`title`,n.t=i),n.a=Te(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function Qf(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation();let r=e.text??``;if(!r){i(!0),setTimeout(()=>i(!1),1200);return}navigator.clipboard.writeText(r).then(()=>{n(!0),setTimeout(()=>n(!1),900)}).catch(()=>{try{let e=document.createElement(`textarea`);e.value=r,e.style.position=`fixed`,e.style.opacity=`0`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),e.remove(),n(!0),setTimeout(()=>n(!1),900)}catch{i(!0),setTimeout(()=>i(!1),1200)}})};return(()=>{var n=zd();return n.$$click=a,L(n,(()=>{var n=N(()=>!!t());return()=>n()?`✓`:N(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>F(n,`title`,e.title??`copy to clipboard`)),n})()}function $f(e){return(()=>{var t=Bd(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),L(r,()=>e.title),we(i,`click`,e.onClose,!0),L(n,()=>e.children,null),t})()}function ep(e){let[t,n]=v(`~`),[r,i]=v([]),[a,o]=v(``),[s,c]=v(e.providers[0]??``),[l,u]=v(``),[d,f]=v(``);async function p(e){let r=await $(`/api/fs?path=${encodeURIComponent(e??t())}`);n(r.path),h(r.parent??``),i(r.entries??[])}ee(()=>p(t()));let[m,h]=v(``),g=async n=>{n.preventDefault(),f(``);try{let n=await $(`/api/agents`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({workspace:t(),id:a(),provider:s()||void 0,model:l()||void 0,start:!1})});e.onCreated(n.agent.id)}catch(e){f(String(e.message))}};return A($f,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Hd(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,ee=S.firstChild.nextSibling,C=S.nextSibling,te=C.firstChild.nextSibling,w=C.nextSibling.firstChild.nextSibling,T=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),L(b,A(j,{get each(){return r()},children:e=>(()=>{var n=Ud();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),L(n,e,null),n})()})),ee.$$input=e=>o(e.currentTarget.value),te.addEventListener(`change`,e=>c(e.currentTarget.value)),L(te,A(j,{get each(){return e.providers},children:e=>(()=>{var t=Ql();return L(t,e),t})()})),w.$$input=e=>u(e.currentTarget.value),L(i,A(M,{get when(){return d()},get children(){var e=Vd();return L(e,d),e}}),T),y(()=>h.value=t()),y(()=>ee.value=a()),y(()=>te.value=s()),y(()=>w.value=l()),i}})}var tp=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),np=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),rp=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function ip(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=ap(e);return n===`image`?`🖼`:n===`video`?`🎬`:n===`audio`?`🎵`:[`ts`,`tsx`,`mts`,`cts`].includes(t)?`🟦`:[`js`,`mjs`,`cjs`,`jsx`].includes(t)?`🟨`:t===`json`||t===`jsonc`?`🧾`:t===`md`||t===`mdx`||t===`markdown`?`📝`:t===`css`||t===`scss`||t===`less`?`🎨`:t===`html`||t===`htm`||t===`svg`?`🌐`:[`py`,`pyi`].includes(t)?`🐍`:t===`rs`?`🦀`:t===`go`?`🐹`:t===`java`||t===`kt`||t===`kts`?`☕`:t===`rb`?`💎`:t===`php`?`🐘`:t===`c`||t===`h`||t===`cpp`||t===`hpp`||t===`cc`?`🧩`:t===`sh`||t===`bash`||t===`zsh`||t===`fish`?`🐚`:t===`sql`?`🗄`:t===`yml`||t===`yaml`||t===`toml`||t===`ini`||t===`conf`?`⚙`:t===`lock`?`🔒`:e===`Dockerfile`||t===`dockerfile`?`🐳`:t===`zip`||t===`gz`||t===`tar`||t===`tgz`||t===`bz2`?`📦`:t===`pdf`?`📕`:t===`txt`||t===`log`?`📄`:`·`}function ap(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return tp.has(t)?`image`:np.has(t)?`video`:rp.has(t)?`audio`:null}function op(e){let[t,n]=v(new Map),[r,i]=v(new Set),[a,o]=v(null),[s,c]=v(``),[l,u]=v(localStorage.getItem(`teapot.ignoreMode`)??`dim`),d=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(l())+1)%3];u(t),localStorage.setItem(`teapot.ignoreMode`,t)},f=e=>l()!==`hide`||!e.ignored,[p,m]=v(localStorage.getItem(`teapot.showHidden`)===`1`),h=()=>{let e=!p(),t=[``,...r()];Promise.all(t.map(async t=>({p:t,rows:await x(t,e)}))).then(t=>{m(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`),n(e=>{let n=new Map(e);for(let{p:e,rows:r}of t)r&&n.set(e,r);return n})})},g=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{},...t.ignored?{ignored:!0}:{}}));async function _(e){return x(e,p())}async function x(t,n){try{let r=new URLSearchParams;t&&r.set(`path`,t),n&&r.set(`hidden`,`1`);let i=await $(`/api/agents/${e.agentId}/tree?${r.toString()}`);return g(t,i.entries??[])}catch(e){return c(e.message),null}}let S=``;b(()=>{let t=e.agentId;t!==S&&(S=t,i(new Set),n(new Map),_(``).then(e=>{e&&S===t&&n(new Map([[``,e]]))}))});let ee=async e=>{let a=new Set(r());if(a.has(e.path)){a.delete(e.path),i(a);return}if(a.add(e.path),i(a),!t().has(e.path)){let t=await _(e.path);t&&n(n=>new Map(n).set(e.path,t))}},[te,w]=v(``),[T,ne]=v(!1),[E,re]=v(`code`),[D,ie]=v(``),[O,ae]=v(!1),oe=e=>/\.(md|markdown|mdx)$/i.test(e),se=0,ce=async e=>{let t=++se;w(``),ne(!0);try{let{highlightChunks:n}=await Pc(async()=>{let{highlightChunks:e}=await import(`./shiki-DTbWDwmF.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(se!==t)return;w(e=>e+r)}}catch{se===t&&w(``)}finally{se===t&&ne(!1)}};C(()=>{se++});let[le,ue]=v(null),de=async(t,n)=>{let r=ap(t.path);if(r){o({path:t.path,content:``,binary:!0}),ue({path:t.path,kind:r}),re(`media`);return}try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);ue(null),o({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),ie(r.content??``),re(r.binary?`code`:n),!r.binary&&n!==`md`&&ce({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},k=async()=>{let t=a();if(!(!t||O())){ae(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:D(),baseContent:t.content})}),o({...t,content:D()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
27
+ `)[0]??``,140),null),L(e,()=>n.data?.ok===!1?` · FAILED`:``,null),e})():ed()];break}case`list_dir`:s=u(`path`)||`.`,l=m(4e3);break;case`read_url`:{let e=u(`url`);try{let t=new URL(e);e=t.host+t.pathname}catch{}s=Xf(e,70),c=`web`,l=[(()=>{var e=Gu();return L(e,A(M,{get when(){return/^https?:/i.test(u(`url`))},get fallback(){return(()=>{var e=nd();return L(e,()=>Xf(u(`url`),80)),e})()},get children(){var e=td();return y(()=>F(e,`href`,u(`url`))),e}})),e})(),N(()=>m(3e3))];break}case`bash_output`:{let e=u(`action`)||`read`;s=`bash_output ${u(`job_id`)||`(?)`}`,c=e,l=m(4e3);break}case`load_skill`:{s=`skill: ${u(`name`)}`;let e=o().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);l=n?[(()=>{var t=Jc();return y(()=>t.innerHTML=Fe(e)),t})(),(()=>{var e=Bu(),t=e.firstChild;return L(e,()=>n.data?.durationMs,t),e})()]:rd();break}case`save_skill`:{s=`skill: ${u(`name`)}`,c=Xf(u(`description`),60);let e=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];l=[N(()=>N(()=>!!e.length)()?(()=>{var t=id();return t.firstChild,L(t,()=>e.join(`, `),null),t})():null),n?(()=>{var e=Yu(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,L(e,()=>Xf(o(),160),t),L(e,()=>n.data?.durationMs,r),e})():ad()];break}}}catch{}return(()=>{var i=sd(),u=i.firstChild,p=u.firstChild;p.firstChild;var m=p.nextSibling,h=m.nextSibling;return i.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),F(i,`title`,`${a}${c?` — `+c:``}`),L(p,s,null),L(u,A(M,{get when(){return t.data?.actor},get children(){var e=od();return e.firstChild,L(e,()=>String(t.data.actor),null),e}}),m),L(m,()=>n?c||``:r?`(result missed)`:a===`bash`||f()?A(zf,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return f()}}):`running…`),L(h,A(Qf,{get text(){return d()},label:`⧉ cmd`,title:`copy the ${a} arguments`}),null),L(h,A(M,{when:n,get children(){return A(Qf,{get text(){return o()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),L(i,l,null),y(()=>I(i,`embed`+(n?n.data?.ok===!1?` fail`:` done`:r?` done`:` running`))),i})()}function Hf(e){let t=e.data??{};return e.type===`prompt`?String(t.text??``):e.type===`message`?`${typeof t.reasoning==`string`&&t.reasoning.trim()?`<reasoning>\n${t.reasoning}\n</reasoning>\n\n`:``}${String(t.content??``)}`:(e.type,``)}function Uf(e){let t=e.e,n=Mf(t),r=e=>{let t=e.data??{};return e.data?.actor?`sub:${String(e.data.actor)}`:e.type===`tool_call`||e.type===`tool_result`?`agent-tools`:e.type===`prompt`?`src:${String(t.source??`user`)}`:`type:${e.type}`},i=e.prev&&r(e.prev)===r(t)&&Mf(e.prev).name===n.name&&t.session===e.prev.session&&t.branch===e.prev.branch;if(t.type===`fork`){let e=t.data??{};return(()=>{var n=cd(),r=n.firstChild.nextSibling;return r.nextSibling,L(n,()=>String(e.fromBranch??`?`),r),L(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=t.data??{},n=e.event===`status`?`marked ${String(e.status??``)}`:Xf(String(e.text??``),80);return(()=>{var t=ld(),r=t.firstChild.nextSibling;return r.nextSibling,L(t,()=>String(e.event??``),r),L(t,n,null),t})()}if(t.type===`todo`)return(()=>{var e=ud(),n=e.firstChild.nextSibling;return n.nextSibling,L(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=dd(),n=e.firstChild;return L(e,()=>t.data.from,n),L(e,()=>t.data.to,null),L(e,(()=>{var e=N(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>I(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=fd(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,L(n,()=>String(t.data?.failures),r),L(n,()=>String(t.data?.limit),i),L(a,()=>String(t.data?.lastTool),o),L(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>F(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=pd(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,L(n,()=>String(t.data?.attempt),r),L(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=Qu();return I(r,`divider-msg`+(e?` err`:``)),L(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>F(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=md(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,L(e,()=>String(t.data?.tokensBefore??`?`),n),L(e,()=>String(t.data?.tokensAfter??`?`),r),L(e,()=>String(t.data?.mode??``),i),e})():null}return(()=>{var r=vd(),a=r.firstChild,o=a.nextSibling;return I(a,`avatar avghost`+(i?` ghosted`:``)),L(a,()=>i?``:n.icon),L(o,i&&(()=>{var e=yd();return y(()=>F(e,`title`,`${Ff(t.ts)} · ${t.branch}`)),e})(),null),L(o,A(M,{when:!i,get children(){var r=_d(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return L(i,()=>n.name),L(r,A(M,{get when(){return t.data?.actor},get children(){var e=od();return e.firstChild,L(e,()=>String(t.data.actor),null),e}}),a),L(a,(()=>{var e=N(()=>!!t.data?.pending);return()=>e()?`queued…`:Ff(t.ts)})()),L(o,()=>t.branch),L(r,A(M,{get when(){return e.onCancel},get children(){var t=hd();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),L(r,A(M,{get when(){return t.type!==`tool_call`},get children(){return A(Qf,{get text(){return Hf(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),L(r,A(M,{get when(){return e.onEdit},get children(){var t=gd();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Ee(i,`color`,n.color)),r}}),null),L(o,A(Gf,{e:t,get res(){return e.res},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get agentActive(){return e.agentActive},get onResize(){return e.onResize}}),null),y(e=>{var o=`msg`+(i?` grouped`:``)+(t.data?.pending?` pending`:``),s=t.id,c=i?`transparent`:n.color+`33`,l=i?`1px solid transparent`:`1px solid ${n.color}66`,u=i?`${Ff(t.ts)} · ${t.branch}`:void 0;return o!==e.e&&I(r,e.e=o),s!==e.t&&F(r,`data-eid`,e.t=s),c!==e.a&&Ee(a,`background`,e.a=c),l!==e.o&&Ee(a,`border`,e.o=l),u!==e.i&&F(a,`title`,e.i=u),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),r})()}function Wf(e){let[t,n]=v(``),r=()=>{let r=t().trim();!r||e.answered||(n(``),e.onOption?.(r))};return(()=>{var i=bd(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&F(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function Gf(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=Jc();return y(()=>e.innerHTML=wf(String(t.data.text??``))),e})(),A(M,{get when(){return e.length},get children(){var t=xd();return L(t,A(j,{each:e,children:e=>(()=>{var t=Sd();return F(t,`src`,e),t})()})),t}})]}case`message`:return[A(M,{get when(){return N(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=Cd(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return L(n,(()=>{var e=N(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Jf(String(t.data.reasoning).length)} — truncated)`:``})(),null),L(r,()=>Kf(String(t.data.reasoning),8e3)),e}}),(()=>{var e=Jc();return y(()=>e.innerHTML=wf(String(t.data.content??``))),e})(),A(M,{get when(){return t.data.interrupted},get children(){return wd()}}),A(M,{get when(){return t.data.final},get children(){var e=Td(),n=e.firstChild;return L(e,A(Qf,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return A(Vf,{e:t,get res(){return e.res},get agentActive(){return e.agentActive},get onResize(){return e.onResize}});case`tool_result`:{let e=String(t.data.result);return(()=>{var n=Ed(),r=n.firstChild,i=r.firstChild,a=r.nextSibling,o=a.nextSibling,s=o.firstChild;return L(i,()=>Xf(e,120)),L(r,A(Qf,{text:e}),null),L(a,()=>Kf(e,4e3)),L(o,()=>t.data.durationMs,s),L(o,()=>t.data.ok?``:` · FAILED`,null),y(()=>I(n,`embed`+(t.data.ok?``:` fail`))),n})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=Od(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return L(n,A(M,{get when(){return e.length},get children(){var t=Dd();return t.firstChild,L(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=wf(String(t.data?.decision??``)),r=wf(String(t.data?.rationale??``));return n!==e.e&&(i.innerHTML=e.e=n),r!==e.t&&(a.innerHTML=e.t=r),e},{e:void 0,t:void 0}),n})()}case`question`:{let n=Array.isArray(t.data?.options)?t.data.options:[],r=t.data?.callId?String(t.data.callId):``,i=e.answeredIds?.has(r)??!1;return(()=>{var r=jd(),a=r.firstChild;return a.firstChild,I(r,`embed question`+(i?` answered`:``)),L(a,()=>String(t.data?.question??``),null),L(r,A(M,{when:i,get children(){return kd()}}),null),L(r,A(M,{get when(){return n.length>0},get children(){var r=Ad();return L(r,A(j,{each:n,children:n=>(()=>{var r=Md();return r.$$click=()=>{let r=t.data?.actor;r?$(`/api/agents/${encodeURIComponent(String(r))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},r.disabled=i,L(r,n),r})()})),r}}),null),L(r,A(Wf,{answered:i,get onOption(){return e.onOption}}),null),r})()}case`progress`:return(()=>{var e=Nd(),n=e.firstChild.firstChild.nextSibling;return L(e,A(M,{get when(){return t.data.goalStatus},get children(){var e=vu(),n=e.firstChild.nextSibling;return L(n,()=>String(t.data.goalStatus)),e}}),null),L(e,A(M,{get when(){return t.data.recent},get children(){var e=hu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=wf(String(t.data.recent))),e}}),null),L(e,A(M,{get when(){return t.data.problems},get children(){var e=gu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=wf(String(t.data.problems))),e}}),null),L(e,A(M,{get when(){return t.data.next},get children(){var e=_u(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=wf(String(t.data.next))),e}}),null),y(()=>n.innerHTML=wf(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=Pd(),n=e.firstChild;return n.firstChild,L(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=Id(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,L(n,()=>String(t.data.mode??``),r),L(n,()=>Jf(Number(t.data.tokensBefore??0)),i),L(n,()=>Jf(Number(t.data.tokensAfter??0)),a),L(n,(()=>{var e=N(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),L(e,A(M,{get when(){return t.data.summary},get children(){return[Fd(),(()=>{var e=Jc();return y(()=>e.innerHTML=wf(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=Ld();return L(e,()=>Kf(JSON.stringify(t.data),200)),e})()}}function Kf(e,t){return e.length>t?e.slice(0,t)+` …`:e}function qf(e){let t=new Date(e).getTime()-Date.now(),n=Math.abs(t),r=n<9e4?`${Math.round(n/1e3)}s`:n<54e5?`${Math.round(n/6e4)}m`:`${(n/36e5).toFixed(1)}h`;return t>=0?`in ${r}`:`${r} ago`}function Jf(e){return e>=1e9?`${+(e/1e9).toFixed(1)}b`:e>=1e6?`${+(e/1e6).toFixed(1)}m`:e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Yf(e){return e>=100?Math.round(e).toLocaleString():e>=10?e.toFixed(1):e>=1?e.toFixed(2):e>=.01?e.toFixed(3):e.toFixed(4)}function Xf(e,t){return Kf(e.replace(/\s+/g,` `).trim(),t)}function Zf(e){return(()=>{var t=Rd(),n=t.firstChild;return we(t,`click`,e.onClick,!0),L(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&I(t,n.e=r),i!==n.t&&F(t,`title`,n.t=i),n.a=Te(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function Qf(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation();let r=e.text??``;if(!r){i(!0),setTimeout(()=>i(!1),1200);return}navigator.clipboard.writeText(r).then(()=>{n(!0),setTimeout(()=>n(!1),900)}).catch(()=>{try{let e=document.createElement(`textarea`);e.value=r,e.style.position=`fixed`,e.style.opacity=`0`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),e.remove(),n(!0),setTimeout(()=>n(!1),900)}catch{i(!0),setTimeout(()=>i(!1),1200)}})};return(()=>{var n=zd();return n.$$click=a,L(n,(()=>{var n=N(()=>!!t());return()=>n()?`✓`:N(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>F(n,`title`,e.title??`copy to clipboard`)),n})()}function $f(e){return(()=>{var t=Bd(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),L(r,()=>e.title),we(i,`click`,e.onClose,!0),L(n,()=>e.children,null),t})()}function ep(e){let[t,n]=v(`~`),[r,i]=v([]),[a,o]=v(``),[s,c]=v(e.providers[0]??``),[l,u]=v(``),[d,f]=v(``);async function p(e){let r=await $(`/api/fs?path=${encodeURIComponent(e??t())}`);n(r.path),h(r.parent??``),i(r.entries??[])}ee(()=>p(t()));let[m,h]=v(``),g=async n=>{n.preventDefault(),f(``);try{let n=await $(`/api/agents`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({workspace:t(),id:a(),provider:s()||void 0,model:l()||void 0,start:!1})});e.onCreated(n.agent.id)}catch(e){f(String(e.message))}};return A($f,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Hd(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,ee=S.firstChild.nextSibling,C=S.nextSibling,te=C.firstChild.nextSibling,w=C.nextSibling.firstChild.nextSibling,T=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),L(b,A(j,{get each(){return r()},children:e=>(()=>{var n=Ud();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),L(n,e,null),n})()})),ee.$$input=e=>o(e.currentTarget.value),te.addEventListener(`change`,e=>c(e.currentTarget.value)),L(te,A(j,{get each(){return e.providers},children:e=>(()=>{var t=Ql();return L(t,e),t})()})),w.$$input=e=>u(e.currentTarget.value),L(i,A(M,{get when(){return d()},get children(){var e=Vd();return L(e,d),e}}),T),y(()=>h.value=t()),y(()=>ee.value=a()),y(()=>te.value=s()),y(()=>w.value=l()),i}})}var tp=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),np=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),rp=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function ip(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=ap(e);return n===`image`?`🖼`:n===`video`?`🎬`:n===`audio`?`🎵`:[`ts`,`tsx`,`mts`,`cts`].includes(t)?`🟦`:[`js`,`mjs`,`cjs`,`jsx`].includes(t)?`🟨`:t===`json`||t===`jsonc`?`🧾`:t===`md`||t===`mdx`||t===`markdown`?`📝`:t===`css`||t===`scss`||t===`less`?`🎨`:t===`html`||t===`htm`||t===`svg`?`🌐`:[`py`,`pyi`].includes(t)?`🐍`:t===`rs`?`🦀`:t===`go`?`🐹`:t===`java`||t===`kt`||t===`kts`?`☕`:t===`rb`?`💎`:t===`php`?`🐘`:t===`c`||t===`h`||t===`cpp`||t===`hpp`||t===`cc`?`🧩`:t===`sh`||t===`bash`||t===`zsh`||t===`fish`?`🐚`:t===`sql`?`🗄`:t===`yml`||t===`yaml`||t===`toml`||t===`ini`||t===`conf`?`⚙`:t===`lock`?`🔒`:e===`Dockerfile`||t===`dockerfile`?`🐳`:t===`zip`||t===`gz`||t===`tar`||t===`tgz`||t===`bz2`?`📦`:t===`pdf`?`📕`:t===`txt`||t===`log`?`📄`:`·`}function ap(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return tp.has(t)?`image`:np.has(t)?`video`:rp.has(t)?`audio`:null}function op(e){let[t,n]=v(new Map),[r,i]=v(new Set),[a,o]=v(null),[s,c]=v(``),[l,u]=v(localStorage.getItem(`teapot.ignoreMode`)??`dim`),d=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(l())+1)%3];u(t),localStorage.setItem(`teapot.ignoreMode`,t)},f=e=>l()!==`hide`||!e.ignored,[p,m]=v(localStorage.getItem(`teapot.showHidden`)===`1`),h=()=>{let e=!p(),t=[``,...r()];Promise.all(t.map(async t=>({p:t,rows:await x(t,e)}))).then(t=>{m(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`),n(e=>{let n=new Map(e);for(let{p:e,rows:r}of t)r&&n.set(e,r);return n})})},g=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{},...t.ignored?{ignored:!0}:{}}));async function _(e){return x(e,p())}async function x(t,n){try{let r=new URLSearchParams;t&&r.set(`path`,t),n&&r.set(`hidden`,`1`);let i=await $(`/api/agents/${e.agentId}/tree?${r.toString()}`);return g(t,i.entries??[])}catch(e){return c(e.message),null}}let S=``;b(()=>{let t=e.agentId;t!==S&&(S=t,i(new Set),n(new Map),_(``).then(e=>{e&&S===t&&n(new Map([[``,e]]))}))});let ee=async e=>{let a=new Set(r());if(a.has(e.path)){a.delete(e.path),i(a);return}if(a.add(e.path),i(a),!t().has(e.path)){let t=await _(e.path);t&&n(n=>new Map(n).set(e.path,t))}},[te,w]=v(``),[T,ne]=v(!1),[E,re]=v(`code`),[D,ie]=v(``),[O,ae]=v(!1),oe=e=>/\.(md|markdown|mdx)$/i.test(e),se=0,ce=async e=>{let t=++se;w(``),ne(!0);try{let{highlightChunks:n}=await Pc(async()=>{let{highlightChunks:e}=await import(`./shiki-DELzRiTA.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(se!==t)return;w(e=>e+r)}}catch{se===t&&w(``)}finally{se===t&&ne(!1)}};C(()=>{se++});let[le,ue]=v(null),de=async(t,n)=>{let r=ap(t.path);if(r){o({path:t.path,content:``,binary:!0}),ue({path:t.path,kind:r}),re(`media`);return}try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);ue(null),o({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),ie(r.content??``),re(r.binary?`code`:n),!r.binary&&n!==`md`&&ce({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},k=async()=>{let t=a();if(!(!t||O())){ae(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:D(),baseContent:t.content})}),o({...t,content:D()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
28
28
  OK = load the disk version into the editor (your edits are discarded)
29
29
  Cancel = keep editing your copy`)?(ie(r.current),o({...t,content:r.current}),Q(`loaded the current file from disk`)):Q(`kept your edits — use Save As via bash to force-write`)}finally{ae(!1)}}},fe=e=>!e.binary&&!e.truncated,pe=(e,n)=>[(()=>{var t=Gd(),i=t.firstChild,a=i.nextSibling;return t.$$click=()=>e.dir?void ee(e):void de(e,`code`),L(i,(()=>{var t=N(()=>!!e.dir);return()=>t()?r().has(e.path)?`▾`:`▸`:ip(e.name)})()),L(a,()=>e.name),L(t,A(M,{get when(){return N(()=>!e.dir)()&&e.size!==void 0},get children(){var t=Wd();return L(t,()=>Jf(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&l()===`dim`?` gitignored`:``),a=`padding-left:${n*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&I(t,r.e=i),r.t=Te(t,a,r.t),o!==r.a&&F(t,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),t})(),A(M,{get when(){return N(()=>!!e.dir)()&&r().has(e.path)},get children(){return A(j,{get each(){return(t().get(e.path)??[]).filter(f)},children:e=>pe(e,n+1)})}})],me=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace;return[(()=>{var e=Kd(),t=e.firstChild.nextSibling;return t.firstChild,L(t,me,null),L(e,A(Zf,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return N(()=>l()===`hide`)()?`🙈`:l()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${l()} — click to cycle (dim → hidden → shown)`},onClick:d}),null),L(e,A(Zf,{class:`filetoggle`,get icon(){return p()?`◉.`:`○.`},get title(){return p()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:h}),null),e})(),(()=>{var e=qd();return L(e,A(M,{get when(){return(t().get(``)??[]).length>0},get fallback(){return(()=>{var e=Jd();return L(e,()=>s()||`empty workspace`),e})()},get children(){return A(j,{get each(){return(t().get(``)??[]).filter(f)},children:e=>pe(e,0)})}})),e})(),A(M,{get when(){return a()},children:t=>A($f,{get title(){return`🗂 ${t().path}`},onClose:()=>{se++,o(null),ue(null)},get children(){return A(M,{get when(){return le()},get fallback(){return[(()=>{var e=$d(),n=e.firstChild;return L(e,A(M,{get when(){return N(()=>!!oe(t().path))()&&!t().binary},get children(){var e=Zd();return e.$$click=()=>re(`md`),y(()=>I(e,E()===`md`?`on`:``)),e}}),n),n.$$click=()=>{re(`code`),te()||ce({path:t().path,content:t().content,truncated:t().truncated})},L(e,A(M,{get when(){return fe(t())},get children(){var e=Qd();return e.$$click=()=>re(`edit`),y(()=>I(e,E()===`edit`?`on`:``)),e}}),null),y(()=>I(n,E()===`code`?`on`:``)),e})(),A(M,{get when(){return!t().binary},get fallback(){return tf()},get children(){return A(M,{get when(){return E()===`edit`},get fallback(){return A(M,{get when(){return N(()=>E()===`md`)()&&oe(t().path)},get fallback(){return A(sp,{get path(){return t().path},get content(){return t().content},get html(){return te()},get pending(){return T()},get truncated(){return!!t().truncated}})},get children(){var e=nf();return y(()=>e.innerHTML=Fe(t().content)),e}})},get children(){var e=ef(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>ie(e.currentTarget.value),F(n,`spellcheck`,!1),L(r,()=>Jf(D().length),i),a.$$click=()=>void k(),L(a,()=>O()?`saving…`:`💾 save`),y(()=>a.disabled=O()||D()===t().content),y(()=>n.value=D()),e}})}})]},get children(){var t=Xd(),n=t.firstChild,r=n.firstChild;return L(t,A(M,{get when(){return le().kind===`image`},get fallback(){return A(M,{get when(){return le().kind===`video`},get fallback(){return(()=>{var t=af();return y(()=>F(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(le().path)}`)),t})()},get children(){var t=rf();return y(()=>F(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(le().path)}`)),t}})},get children(){var t=Yd();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(le().path)}`,i=le().path.split(`/`).pop();return r!==n.e&&F(t,`src`,n.e=r),i!==n.t&&F(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),L(n,()=>le().kind,r),t}})}})})]}function sp(e){return[A(M,{get when(){return e.html},get fallback(){return N(()=>!!e.pending)()?(()=>{var t=cf(),n=t.firstChild.nextSibling;return n.nextSibling,L(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=lf();return L(t,()=>e.content),t})()},get children(){var t=of();return y(()=>t.innerHTML=e.html),t}}),A(M,{get when(){return e.truncated},get children(){return sf()}})]}var cp=[{key:`openrouter`,label:`OpenRouter`,url:`https://openrouter.ai/api/v1`,model:`anthropic/claude-sonnet-4`,hint:`400+ models behind one key — teapot sends app-attribution headers automatically`},{key:`orcarouter`,label:`OrcaRouter`,url:`https://api.orcarouter.ai/v1`,model:`orcarouter/auto`,hint:`zero-markup routing gateway — 'orcarouter/auto' grades each prompt and picks the model`},{key:`openai`,label:`OpenAI`,url:`https://api.openai.com/v1`,model:`gpt-4o-mini`},{key:`llamacpp`,label:`llama.cpp server`,url:`http://localhost:8080/v1`,model:``,hint:`free & local — start it with: llama-server -m ./model.gguf (any model name works)`}],lp={key:`custom`,label:`Custom`,url:``,model:``,hint:`any OpenAI-compatible /v1 endpoint — vLLM, LM Studio, llama.cpp, a company gateway… fill the fields below`};function up(e){let[t,n]=v(cp[0]),[r,i]=v(cp[0].url),[a,o]=v(``),[s,c]=v(cp[0].model),[l,u]=v([]),[d,f]=v(`~/teapot-workspace`),[p,m]=v(``),[h,g]=v(!1),[_,x]=v(``),S=e=>{n(e),e.key!==`custom`&&e.url&&(i(e.url),e.model&&c(e.model))};b(()=>{let e=r().trim(),t=a();if(!/^https?:\/\//.test(e)){u([]);return}let n=setTimeout(async()=>{try{let n=await $(`/api/setup/models?baseUrl=${encodeURIComponent(e)}${t?`&apiKey=${encodeURIComponent(t)}`:``}`);u(n.models??[])}catch{u([])}},600);C(()=>clearTimeout(n))});let ee=e=>{let t=l().find(t=>t.id===e.trim());if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${Jf(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},te=()=>ee(s()),w=async t=>{t.preventDefault(),x(``),g(!0);try{await $(`/api/setup`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({baseUrl:r(),apiKey:a()||void 0,model:s(),workspace:d(),...p()?{password:p()}:{}})}),e.onDone()}catch(e){x(e.message),g(!1)}};return(()=>{var e=pf(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,ee=x.firstChild.nextSibling,C=x.nextSibling,T=C.firstChild.nextSibling,ne=T.nextSibling,E=C.nextSibling,re=E.firstChild.nextSibling,D=re.firstChild.nextSibling,ie=re.nextSibling.firstChild.nextSibling,O=E.nextSibling;return n.addEventListener(`submit`,w),L(u,()=>[...cp,lp].map(e=>(()=>{var n=mf();return n.$$click=()=>S(e),L(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&I(n,r.e=i),a!==r.t&&F(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),L(n,A(M,{get when(){return t().hint},get children(){var e=uf();return L(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),L(b,()=>cp.map(e=>(()=>{var t=Ql();return y(()=>t.value=e.url),t})())),ee.$$input=e=>o(e.currentTarget.value),T.$$input=e=>c(e.currentTarget.value),L(ne,()=>l().map(e=>(()=>{var t=Ql();return y(()=>t.value=e.id),t})())),L(n,A(M,{get when(){return l().length>0},get fallback(){return hf()},get children(){var e=ff(),t=e.firstChild;return L(e,()=>l().length,t),L(e,A(M,{get when(){return te()},get children(){return[` · `,(()=>{var e=df();return L(e,te),e})()]}}),null),e}}),E),D.$$input=e=>f(e.currentTarget.value),ie.$$input=e=>m(e.currentTarget.value),L(n,A(M,{get when(){return _()},get children(){var e=Vd();return L(e,_),e}}),O),L(O,()=>h()?`saving…`:`finish setup`),y(e=>{var n=t().key===`llamacpp`?`(any name — serves whichever gguf is loaded)`:`(type to filter models from the endpoint)`,r=h();return n!==e.e&&F(T,`placeholder`,e.e=n),r!==e.t&&(O.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>ee.value=a()),y(()=>T.value=s()),y(()=>D.value=d()),y(()=>ie.value=p()),e})()}function dp(e){let[t,n]=v(Object.entries(e.cfg.providers??{}).map(([e,t])=>({name:e,baseUrl:t.baseUrl??``,apiKey:t.apiKey??``,model:t.model??``}))),[r,i]=v(e.cfg.defaultProvider??``),[a,o]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[s,c]=v(e.cfg.progressMinChars??4e3),[l,u]=v(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[d,f]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[p,m]=v(e.cfg.maxSpawnDepth??3),[h,g]=v((e.cfg.tasks??[]).map(e=>({...e}))),[_,b]=v(``),x=()=>(e.cfg.agents??[]).map(e=>e.id),S=()=>{let e={};for(let n of t()){if(!n.name.trim())return b(`provider name is required`),null;if(n.baseUrl&&!/^https?:\/\//.test(n.baseUrl))return b(`provider ${n.name}: baseUrl must start with http(s)://`),null;e[n.name.trim()]={baseUrl:n.baseUrl,...n.apiKey?{apiKey:n.apiKey}:{},...n.model?{model:n.model}:{}}}return e},ee=async t=>{t.preventDefault(),b(``);let n=S();if(!n)return;let i=h().filter(e=>e.id?.trim()||e.prompt?.trim()).map((e,t)=>({id:e.id?.trim()||`task-${t+1}`,agent:e.agent,schedule:e.schedule,prompt:e.prompt,...e.forked?{forked:!0}:{}}));for(let e of i){if(!e.agent){b(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){b(`task "${e.id}": schedule is required`);return}}try{await $(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:r()||void 0,progressIntervalMs:Math.max(1,a())*6e4,progressMinChars:Math.max(100,s()),...l()==null?{}:{contextTokenBudget:Math.max(1,l())*1e3},...d()>0?{contextWindowTokens:d()*1e3}:{},maxSpawnDepth:Math.max(0,p()),tasks:i})}),e.onSaved(),e.onClose()}catch(e){b(e.message)}},C=(e,t,n,r)=>(()=>{var i=gf(),a=i.firstChild;return F(i,`title`,r),L(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return A($f,{title:`settings`,get onClose(){return e.onClose},get children(){var v=_f(),b=v.firstChild,S=b.firstChild.nextSibling,te=S.nextSibling;te.firstChild;var w=te.nextSibling.firstChild.firstChild.nextSibling;w.firstChild;var T=b.nextSibling,ne=T.firstChild.nextSibling,E=ne.firstChild,re=E.firstChild.nextSibling,D=T.nextSibling,ie=D.firstChild.nextSibling,O=D.nextSibling;O.firstChild;var ae=O.nextSibling;return v.addEventListener(`submit`,ee),L(b,A(j,{get each(){return t()},children:(e,r)=>(()=>{var i=vf(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling;return a.$$input=e=>n(t().map((t,n)=>n===r()?{...t,name:e.currentTarget.value}:t)),o.$$input=e=>n(t().map((t,n)=>n===r()?{...t,baseUrl:e.currentTarget.value}:t)),s.$$input=e=>n(t().map((t,n)=>n===r()?{...t,apiKey:e.currentTarget.value}:t)),c.$$input=e=>n(t().map((t,n)=>n===r()?{...t,model:e.currentTarget.value}:t)),l.$$click=()=>n(t().filter((e,t)=>t!==r())),y(()=>a.value=e.name),y(()=>o.value=e.baseUrl),y(()=>s.value=e.apiKey),y(()=>c.value=e.model),i})()}),S),S.$$click=()=>n([...t(),{name:``,baseUrl:``,apiKey:``,model:``}]),L(te,A(j,{each:cp,children:e=>(()=>{var a=yf();return a.firstChild,a.$$click=()=>{let a=t().filter(t=>t.name!==e.key);n([...a,{name:e.key,baseUrl:e.url,apiKey:``,model:e.model}]),r()||i(e.key)},L(a,()=>e.label,null),y(()=>F(a,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),a})()}),null),w.addEventListener(`change`,e=>i(e.currentTarget.value)),L(w,A(j,{get each(){return[...new Set(t().map(e=>e.name.trim()).filter(Boolean))]},children:e=>(()=>{var t=Ql();return t.value=e,L(t,e),t})()}),null),L(ne,()=>C(`progress interval (min)`,a(),e=>o(e),`how often the harness asks for a progress report`),E),L(ne,()=>C(`progress min chars`,s(),e=>c(e),`progress prompts wait for this much real output`),E),re.$$input=e=>u(e.currentTarget.value===``?null:Number(e.currentTarget.value)),L(ne,()=>C(`context window (k tok)`,d(),e=>f(e),`model's real window — 0/blank hides the % gauge`),null),L(ne,()=>C(`max spawn depth`,p(),e=>m(e),`sub-agent nesting limit (0 = no spawning)`),null),L(D,A(M,{get when(){return h().length>0},get children(){return A(j,{get each(){return h()},children:(e,t)=>(()=>{var n=bf(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.firstChild,l=s.nextSibling,u=r.nextSibling;return i.$$input=e=>g(h().map((n,r)=>r===t()?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>g(h().map((n,r)=>r===t()?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>g(h().map((n,r)=>r===t()?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>g(h().map((n,r)=>r===t()?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>g(h().filter((e,n)=>n!==t())),u.$$input=e=>g(h().map((n,r)=>r===t()?{...n,prompt:e.currentTarget.value}:n)),y(()=>i.value=e.id),y(()=>a.value=e.agent),y(()=>o.value=e.schedule),y(()=>c.checked=!!e.forked),y(()=>u.value=e.prompt),n})()})}}),ie),ie.$$click=()=>g([...h(),{id:``,agent:x()[0]??``,schedule:`every 30m`,prompt:``}]),L(O,A(j,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=Sf(),n=t.firstChild,r=n.nextSibling;return L(n,()=>e.id),L(r,()=>e.workspace),L(t,A(M,{get when(){return e.parent},get children(){var t=xf();return t.firstChild,L(t,()=>e.parent,null),t}}),null),t})()}),null),L(v,A(M,{get when(){return _()},get children(){var e=Vd();return L(e,_),e}}),ae),y(()=>w.value=r()),y(()=>re.value=l()??``),v}})}Ce([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Se(()=>A(Rf,{}),document.getElementById(`root`));export{Pc as t};
30
- //# sourceMappingURL=index-C9akwFXI.js.map
30
+ //# sourceMappingURL=index-BXBPj05l.js.map