eve 0.26.0 → 0.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/src/cli/banner.d.ts +5 -0
  3. package/dist/src/cli/banner.js +1 -1
  4. package/dist/src/cli/dev/tui/blocks.d.ts +56 -8
  5. package/dist/src/cli/dev/tui/blocks.js +7 -7
  6. package/dist/src/cli/dev/tui/diagnostic-presentation.d.ts +2 -0
  7. package/dist/src/cli/dev/tui/diagnostic-presentation.js +3 -2
  8. package/dist/src/cli/dev/tui/file-content-cache.d.ts +35 -0
  9. package/dist/src/cli/dev/tui/file-content-cache.js +3 -0
  10. package/dist/src/cli/dev/tui/line-diff.d.ts +24 -0
  11. package/dist/src/cli/dev/tui/line-diff.js +1 -0
  12. package/dist/src/cli/dev/tui/markdown.d.ts +2 -1
  13. package/dist/src/cli/dev/tui/markdown.js +7 -3
  14. package/dist/src/cli/dev/tui/prompt-placeholder.d.ts +12 -0
  15. package/dist/src/cli/dev/tui/prompt-placeholder.js +1 -0
  16. package/dist/src/cli/dev/tui/question-panel.d.ts +24 -0
  17. package/dist/src/cli/dev/tui/question-panel.js +1 -0
  18. package/dist/src/cli/dev/tui/rail.d.ts +15 -0
  19. package/dist/src/cli/dev/tui/rail.js +1 -0
  20. package/dist/src/cli/dev/tui/runner.d.ts +22 -65
  21. package/dist/src/cli/dev/tui/runner.js +1 -1
  22. package/dist/src/cli/dev/tui/setup-commands.js +1 -1
  23. package/dist/src/cli/dev/tui/setup-issues.js +1 -1
  24. package/dist/src/cli/dev/tui/status-line.js +1 -1
  25. package/dist/src/cli/dev/tui/stream-format.d.ts +16 -3
  26. package/dist/src/cli/dev/tui/stream-format.js +1 -1
  27. package/dist/src/cli/dev/tui/subagent-pump.d.ts +127 -0
  28. package/dist/src/cli/dev/tui/subagent-pump.js +1 -0
  29. package/dist/src/cli/dev/tui/terminal-renderer.d.ts +34 -1
  30. package/dist/src/cli/dev/tui/terminal-renderer.js +11 -10
  31. package/dist/src/cli/dev/tui/test/mock-terminal.d.ts +7 -0
  32. package/dist/src/cli/dev/tui/test/mock-terminal.js +1 -1
  33. package/dist/src/cli/dev/tui/theme.d.ts +16 -2
  34. package/dist/src/cli/dev/tui/theme.js +1 -1
  35. package/dist/src/cli/dev/tui/todo-panel.d.ts +44 -0
  36. package/dist/src/cli/dev/tui/todo-panel.js +1 -0
  37. package/dist/src/cli/dev/tui/tool-block-groups.d.ts +40 -0
  38. package/dist/src/cli/dev/tui/tool-block-groups.js +1 -0
  39. package/dist/src/cli/dev/tui/tool-presentation.d.ts +67 -0
  40. package/dist/src/cli/dev/tui/tool-presentation.js +1 -0
  41. package/dist/src/cli/dev/tui/tool-rows.d.ts +15 -0
  42. package/dist/src/cli/dev/tui/tool-rows.js +2 -0
  43. package/dist/src/cli/dev/tui/turn-clock.d.ts +36 -0
  44. package/dist/src/cli/dev/tui/turn-clock.js +1 -0
  45. package/dist/src/cli/dev/tui/types.d.ts +2 -2
  46. package/dist/src/cli/dev/ui-options.js +1 -1
  47. package/dist/src/client/index.js +1 -1
  48. package/dist/src/client/session.js +1 -1
  49. package/dist/src/compiled/.vendor-stamp.json +2 -1
  50. package/dist/src/compiled/marked/LICENSE.md +44 -0
  51. package/dist/src/compiled/marked/index.d.ts +24 -0
  52. package/dist/src/compiled/marked/index.js +59 -0
  53. package/dist/src/evals/session.js +1 -1
  54. package/dist/src/execution/terminal-session-failure-step.js +1 -1
  55. package/dist/src/harness/tool-loop.js +2 -2
  56. package/dist/src/internal/application/package.js +1 -1
  57. package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response-from-manifest.js +1 -1
  58. package/dist/src/internal/nitro/routes/info.js +1 -1
  59. package/dist/src/internal/resolve-model-endpoint-status.d.ts +46 -3
  60. package/dist/src/internal/resolve-model-endpoint-status.js +1 -1
  61. package/dist/src/setup/flows/link.d.ts +13 -3
  62. package/dist/src/setup/flows/link.js +1 -1
  63. package/dist/src/setup/flows/model.d.ts +4 -3
  64. package/dist/src/setup/flows/model.js +1 -1
  65. package/dist/src/setup/flows/provider.d.ts +3 -1
  66. package/dist/src/setup/flows/provider.js +2 -2
  67. package/dist/src/setup/scaffold/create/project.js +1 -1
  68. package/package.json +2 -1
@@ -1,12 +1,13 @@
1
- import{PROMPT_COMMANDS,isPromptControlCommand,parsePromptCommand}from"./prompt-commands.js";import{summarizeToolArgs,summarizeToolResult}from"./tool-format.js";import{buildAgentHeader}from"./agent-header.js";import{renderAttentionRows,renderBlockLines}from"./blocks.js";import{dismissTypeahead,inlineCommandHint,isTypeaheadOpen,moveTypeaheadSelection,renderCommandSuggestions,selectedTypeaheadCommand,typeaheadCompletion,typeaheadFor}from"./command-typeahead.js";import{formatDevRebuildStatus,summarizeChangedFiles}from"./dev-rebuild-status.js";import{formatStoredDiagnostic,presentDiagnostic}from"./diagnostic-presentation.js";import{interruptedError}from"./errors.js";import{EMPTY_LINE,PromptHistory,applyLineEditorKey,deleteForward,layoutPromptInput,lineOf,movePromptLine,visibleLine}from"./line-editor.js";import{nextLogDisplayMode}from"./log-display-mode.js";import{initialModelEditorState,transitionModelEditor}from"./model-editor.js";import{initialProviderPickerState,transitionProviderPicker}from"./provider-picker.js";import{enterBadge,renderAcknowledgeQuestion,renderFlowPanel,renderModelEditorQuestion,renderSelectQuestion,renderTextQuestion}from"./setup-panel.js";import{buildStatusLine}from"./status-line.js";import{createTheme,detectUnicode}from"./theme.js";import{reduceSetupSelectInput,setupSelectionIntent}from"./setup-selection-input.js";import{formatAssistantResponseStats,isIncompletePaste,nextKey,sanitizePastedText,stripPasteStart,stripPromptControlCharacters,takeUntil}from"./stream-format.js";import{inspectError}from"#internal/logging.js";import{clipVisible,renderInputText,renderInputWithBlockCursor,stripAnsi,stripTerminalControls}from"#cli/ui/terminal-text.js";import{renderCursorRow}from"#setup/cli/option-row.js";import{initialSelectState,reduceSelect,searchActionQuery,selectValueAtCursor}from"#setup/cli/select-state.js";import{toErrorMessage}from"#shared/errors.js";import{StringDecoder}from"node:string_decoder";import{summarizeKnownError}from"#harness/semantic-errors/index.js";import{parseDevRebuildLogLine}from"#internal/nitro/host/dev-watcher-log.js";import{LiveRegion}from"#cli/ui/live-region.js";import{PROGRESS_PULSE_ASCII_GLYPH,PROGRESS_PULSE_GLYPH,isProgressPulseVisible}from"#cli/ui/progress-pulse.js";import{readGatewayServiceTier}from"#shared/gateway-service-tier.js";function isMultiSelectRequest(e){return e.kind===`multi`||e.kind===`searchable-multi`}function moveActionCursor(e,t,n){return n===0?void 0:e===void 0?t===`down`?0:n-1:(e+(t===`down`?1:-1)+n)%n}function completedTurnStatus(e,t){return e?`Interrupted`:t?`Ready`:`Done`}const STATUS={processing:`Working…`,toolResults:`Reading results…`,streaming:`Responding…`,executingTools:`Running tools…`,connectionAuth:`Waiting for connection authorization…`};var TerminalRenderer=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p=[];#m=new Map;#h=new Set;#g=[];#_=new Set;#v=new Map;#y=new Set;#b;#x=!1;#S;#C=[];#w;#T=0;#E;#D;#O=``;#k=0;#A=new PromptHistory;#j=!1;#M;#N={kind:`idle`};#P=STATUS.processing;#F=`eve`;#I=!1;#L=!1;#R=!0;#z=0;#B;#V;#H;#U=!1;#W;#G=``;#K=new StringDecoder(`utf8`);#q;#J;#Y;#X=!1;#Z=!1;#Q;#$;#ee;#te;#ne;#re=``;#ie=``;#ae;#oe;#se=0;#ce;#le;#ue;#de;#fe;setupFlow={begin:(e,t)=>this.#ge(e,t),end:e=>this.#_e(e?.preserveDiagnostics??!0),readSelect:e=>this.#ve(e),readEditableSelect:e=>this.#be(e),readProviderPicker:e=>this.#xe(e),readModelEditor:e=>this.#Se(e),readText:e=>this.#Ce(e),readAcknowledge:e=>this.#we(e),readChoice:e=>this.#ye(e),setStatus:e=>this.#Me(e),renderLine:(e,t)=>this.#Ne(e,t),renderOutput:e=>this.#Pe(e),waitForInterrupt:()=>this.#ke()};constructor(t){this.#e=t?.input??process.stdin,this.#t=t?.output??process.stdout,this.#n=new LiveRegion(this.#t),this.#r=createTheme({color:t?.color??!0,unicode:t?.unicode??detectUnicode()}),this.#i=t?.tools??`auto-collapsed`,this.#a=t?.reasoning??`full`,this.#o=t?.subagents??`auto-collapsed`,this.#s=t?.connectionAuth??`full`,this.#c=t?.assistantResponseStats??`tokensPerSecond`,this.#l=t?.captureForeignOutput??this.#t===process.stdout,this.#u=t?.diagnostics,this.#f=t?.logs??`none`,this.#d=t?.availablePromptCommands??PROMPT_COMMANDS}renderAgentHeader(e){this.#F=e.name,this.#b=e,this.#Fe();let t=this.#_t().join(`
2
- `);if(this.#x){t!==this.#S&&(this.#S=t,this.#Xe({kind:`agent-header`,body:t,live:!1})),this.#ft();return}this.#x=!0,this.#S=t,this.#n.flush(this.#_t(),[])}async readPrompt(e){this.#Fe(e),this.#Ye(),this.#j=!0,this.#N={kind:`idle`},this.#P=``;let r=lineOf(stripPromptControlCharacters(e?.initialDraft??``));return this.#A.begin(r.text),this.#pe(r),this.#M=typeaheadFor(this.#d,r.text),this.#We(),this.#ft(),await new Promise((e,i)=>{let apply=e=>{r=e,this.#Ke(),this.#pe(r),this.#M=typeaheadFor(this.#d,e.text,this.#M),this.#ft()},recall=e=>{e!==void 0&&apply(lineOf(e))},interrupt=()=>{this.#M=void 0,this.#Ge(),this.#Ie(),i(interruptedError())},suggestions=()=>this.#M!==void 0&&isTypeaheadOpen(this.#M)?this.#M:void 0,highlighted=()=>{let e=suggestions();return e===void 0?void 0:selectedTypeaheadCommand(e)};this.#W=i=>{let a=applyLineEditorKey(r,i,{multiline:!0});if(a!==void 0){apply(a);return}switch(i.type){case`up`:case`ctrl-p`:{let e=suggestions();if(e!==void 0){this.#M=moveTypeaheadSelection(e,-1),this.#ft();break}let t=movePromptLine(r,`up`);t===void 0?recall(this.#A.previous(r.text)):apply(t);break}case`down`:case`ctrl-n`:{let e=suggestions();if(e!==void 0){this.#M=moveTypeaheadSelection(e,1),this.#ft();break}let t=movePromptLine(r,`down`);t===void 0?recall(this.#A.next()):apply(t);break}case`tab`:{let e=highlighted();e!==void 0&&apply(lineOf(typeaheadCompletion(e)));break}case`escape`:{let e=suggestions();e!==void 0&&(this.#M=dismissTypeahead(e),this.#ft());break}case`enter`:{let i=highlighted(),a=i!==void 0&&parsePromptCommand(r.text)===null?typeaheadCompletion(i).trimEnd():r.text;this.#M=void 0,this.#A.add(a),this.#j=!1,this.#Ge(),this.#Je(),this.#P=STATUS.processing,isPromptControlCommand(a)?this.#Xe({kind:`command`,body:stripTerminalControls(a.trim()),live:!1}):(this.#Ze(a),this.#ce=a),this.#pe(EMPTY_LINE),this.#ft(),this.#Re(),e(a);break}case`ctrl-d`:r.text.length===0?interrupt():apply(deleteForward(r));break;case`ctrl-l`:this.#ht();break;case`ctrl-r`:this.#ft();break;case`ctrl-c`:r.text.length===0?interrupt():apply(EMPTY_LINE);break;default:break}},this.#Le()})}#pe(e){this.#O=e.text,this.#k=e.cursor}async renderStream(e,t){this.#Fe(t),this.#h.clear(),this.#j=!1,this.#N.kind!==`waiting`&&(this.#N={kind:`waiting`,startedAtMs:Date.now()}),this.#P=this.#T>0?STATUS.connectionAuth:STATUS.processing,this.#Qe(t?.submittedPrompt),t?.submittedPrompt!==void 0&&this.#u?.recordPrompt(),this.#L=!1,this.#Q=void 0,this.#$=void 0,this.#ee=void 0,this.#te=Date.now();let n={tools:t?.tools??this.#i,reasoning:t?.reasoning??this.#a,assistantResponseStats:t?.assistantResponseStats??this.#c};this.#qe(),this.#ft();let r=new Promise(e=>{this.#Y=e});this.#W=e=>this.#Ue(e),this.#Le();let i={text:new Map,reasoning:new Map,tools:new Map,hasPendingToolResults:!1};try{for await(let t of takeUntil(iterateTUIStream(e.events),r)){if(this.#L)break;this.#it(t,n,i)}}catch(e){let t=summarizeKnownError(e);t===null?this.#$e(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#$e(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#Y=void 0,this.#L&&e.abort?.(),this.#Re(),this.#Ye(),this.#N.kind===`waiting`&&(this.#N={kind:`idle`}),this.#P=completedTurnStatus(this.#L,t?.continueSession===!0),this.#rt(),this.#u?.reportStats(),this.#ft(),t?.continueSession||this.#Ie()}}async readToolApproval(e,t){return this.#Fe(t),this.#Ye(),this.#j=!1,this.#N={kind:`idle`},this.#P=`Approve ${formatToolApprovalTitle(e)}? (y/n)`,this.#L=!1,this.#ft(),await new Promise((t,n)=>{this.#W=r=>{switch(r.type){case`text`:{if(r.framing!==`unframed`)break;let n=r.value.toLowerCase();n===`y`?(this.#Je(),this.#P=STATUS.processing,this.#Re(),this.#ft(),t({approved:!0})):n===`n`&&(this.#Je(),this.#P=STATUS.processing,this.#me(e.toolCallId),this.#Re(),this.#ft(),t({approved:!1,reason:`Denied by user.`}));break}case`ctrl-r`:this.#ft();break;case`ctrl-c`:this.#L=!0,this.#Ie(),n(interruptedError());break;default:break}},this.#Le()})}async readInputQuestion(e,t){this.#Fe(t),this.#Ye(),this.#j=!1,this.#N={kind:`idle`},this.#L=!1;let n=e.options??[],r=n.length>0,i=(e.allowFreeform===!0||!r)&&r,a=n.length+ +!!i,o=questionSectionId(e.requestId),s=r?`select`:`text`,c=0,l=EMPTY_LINE,isOnFreeformRow=()=>i&&c===n.length,renderSection=()=>{this.#tt({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:formatQuestionContent(e,c,this.#r),preformatted:!0,live:!0})},repaintStatus=()=>{if(s===`select`){let e=isOnFreeformRow()?`type`:`select`;this.#P=`↑/↓ move · enter ${e} · Ctrl+C quit`,this.#j=!1}else this.#j=!0,this.#pe(l),this.#P=``;this.#ft()};renderSection(),s===`text`&&this.#We(),repaintStatus();let finalize=t=>{this.#tt({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:` ${this.#r.colors.green(this.#r.glyph.success)} ${stripTerminalControls(t.label)}`,preformatted:!0,live:!1}),this.#j=!1,this.#Je(),this.#P=STATUS.processing,this.#Ge(),this.#Re(),this.#ft();let n={};return t.optionId!==void 0&&(n.optionId=t.optionId),t.text!==void 0&&(n.text=t.text),n};return await new Promise((t,i)=>{this.#W=o=>{if(o.type===`ctrl-c`){if(s===`text`&&l.text.length>0){l=EMPTY_LINE,this.#Ke(),repaintStatus();return}this.#L=!0,this.#Ge(),this.#Ie(),i(interruptedError());return}if(o.type===`ctrl-r`){this.#ft();return}if(s===`select`){switch(o.type){case`up`:case`ctrl-p`:a>0&&(c=(c-1+a)%a,renderSection(),repaintStatus());break;case`down`:case`ctrl-n`:a>0&&(c=(c+1)%a,renderSection(),repaintStatus());break;case`enter`:{if(isOnFreeformRow()){s=`text`,l=EMPTY_LINE,this.#We(),repaintStatus();break}let e=n[c];e&&t(finalize({optionId:e.id,label:e.label}));break}default:break}return}let u=applyLineEditorKey(l,o,{multiline:!0});if(u!==void 0){l=u,this.#Ke(),repaintStatus();return}switch(o.type){case`up`:case`down`:{let e=movePromptLine(l,o.type);e!==void 0&&(l=e,this.#Ke(),repaintStatus());break}case`enter`:{let n=resolveQuestionText(l.text,e);if(n===void 0)break;t(finalize(n));break}case`escape`:if(r){if(l.text.length>0){l=EMPTY_LINE,this.#Ke(),repaintStatus();break}s=`select`,l=EMPTY_LINE,this.#j=!1,this.#Ge(),repaintStatus();break}l=EMPTY_LINE,this.#Ke(),repaintStatus();break;default:break}},this.#Le()})}upsertSubagentStep(e){if(this.#u?.recordSubagentDispatch(e.callId),this.#o===`hidden`)return;let t=stripTerminalControls(e.reasoning??``).trim(),n=stripTerminalControls(e.message??``).trim();if(!(t.length===0&&n.length===0)){if(this.#et(e.callId,e.subagentName),this.#o===`collapsed`){this.#ft();return}this.#tt({id:subagentStepSectionId(e.callId,e.sectionKey),kind:`subagent-step`,depth:1,reasoning:t,body:n,live:!e.finalized}),this.#ft()}}upsertSubagentTool(e){if(this.#u?.recordSubagentDispatch(e.callId),e.status===`failed`&&e.errorText!==void 0&&this.#u?.append({source:`tool`,summary:`${e.toolName} failed (subagent ${e.subagentName})`,detail:e.errorText}),this.#o===`hidden`)return;if(this.#et(e.callId,e.subagentName),this.#o===`collapsed`){this.#ft();return}let t=subagentToolStatus(e.status),n={id:subagentToolSectionId(e.callId,e.childCallId),kind:`subagent-tool`,depth:1,title:stripTerminalControls(e.toolName),subtitle:summarizeToolArgs(e.input),status:t,live:t===`running`||t===`approval`,expanded:this.#o===`full`,toolInput:e.input};e.output===void 0?e.errorText!==void 0&&(n.result=stripTerminalControls(e.errorText)):(n.result=summarizeToolResult(e.output),n.toolOutput=e.output),this.#tt(n),this.#ft()}markChildToolCallId(e){this.#_.add(e);let t=this.#v.get(e);t!==void 0&&(this.#nt(t),this.#v.delete(e),this.#ft())}#me(e){let t=this.#m.get(toolSectionId(e));t!==void 0&&(t.status=`denied`,t.live=!1)}upsertConnectionAuth(e){if(this.#s===`hidden`)return;let t=connectionAuthTerminalMessage(e.state);this.#tt({id:connectionAuthSectionId(e.name),kind:`connection-auth`,title:`${stripTerminalControls(e.name)} · authorization · ${e.state}`,body:formatConnectionAuthContent(e,t),preformatted:!0,live:t===void 0}),this.#ft()}setConnectionAuthPendingCount(e){let t=Math.max(0,e);if(t===this.#T)return;let n=this.#T>0;this.#T=t,t>0?(this.#P=STATUS.connectionAuth,this.#ft()):n&&(this.#P=STATUS.processing,this.#ft())}setVercelStatus(e){this.#E=e,this.#ft()}setRemoteConnectionStatus(e){this.#D=e,this.#ft()}reset(){this.#p=[],this.#m.clear(),this.#h.clear(),this.#w=void 0,this.#C.length=0,this.#g.length=0,this.#x=!1,this.#S=void 0,this.#_.clear(),this.#v.clear(),this.#y.clear(),this.#ce=void 0,this.#oe=void 0,this.#T=0,this.#Q=void 0,this.#$=void 0,this.#ee=void 0,this.#te=void 0,this.#I&&(this.#n.clearAll(),this.#ft())}renderNotice(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#Fe(),this.#Xe({kind:`notice`,body:t,live:!1}),this.#ft())}renderSandboxLog(e){let t=parseSandboxLogLine(stripTerminalControls(e));t!==void 0&&(this.#u?.append({source:`sandbox`,detail:t}),this.#Fe(),this.#Xe({kind:`sandbox`,body:t,live:!1}),this.#ft())}renderSetupWarning(e){let t=stripTerminalControls(e);if(t.trim().length===0){this.#he();return}this.#Fe(),this.#ue=t,this.#ft()}clearSetupWarning(){this.#he()}#he(){this.#ue!==void 0&&(this.#ue=void 0,this.#ft())}renderCommandInvocation(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;this.#Fe();let r={kind:`command`,body:n,live:!1};t===`failed`&&(r.status=`error`),this.#Xe(r),this.#ft()}renderCommandResult(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#Fe(),this.#Xe({kind:`result`,body:t,live:!1}),this.#ft())}#ge(e,t=`spinner`){this.#Fe(),this.#j=!1,this.#N={kind:`idle`},this.#P=``;let n=t===`pulse`?{kind:`pulse`,startedAtMs:Date.now()}:{kind:`spinner`};this.#le={title:stripTerminalControls(e),indicator:n,lines:[],outputBuffer:[]},this.#qe(),this.#ft()}#_e(e){this.#de=void 0,this.#je();let t=this.#le;if(t!==void 0){if(this.#le=void 0,this.#Ye(),e){let e=[];for(let n of t.lines){if(n.evidence===!0){e.push(n.text);continue}(n.tone===`warning`||n.tone===`error`)&&(e.length>0&&this.#Xe({kind:`flow`,title:`info`,body:e.join(`
3
- `),live:!1}),this.#Xe({kind:`flow`,title:n.tone,body:n.text,live:!1})),e=[]}}this.#ft()}}async#ve(e){let t=this.#Te(),n=isMultiSelectRequest(e),r=e.kind===`search`?e.searchAction:void 0,i=e.options,a={options:i,searchAction:r,submitRow:n};`initialValue`in e&&e.initialValue!==void 0&&(a.defaultValue=e.initialValue),`initialValues`in e&&e.initialValues!==void 0&&(a.initialValues=e.initialValues);let o=initialSelectState(a),s,c=!1,l=0,isCurrentSearch=e=>e===l,clearSearch=()=>{l+=1,c=!1,o=reduceSelect(o,{type:`clear`},{options:i,searchAction:r,submitRow:n}),this.#ft()},loadSearch=async(e,t)=>{c=!0,s=void 0;let a=++l;this.#ft();try{let s=await t(e);if(!isCurrentSearch(a))return;let c=o.filter;i=s,o={...initialSelectState({options:s,searchAction:r,submitRow:n}),filter:c}}catch(e){isCurrentSearch(a)&&(s=toErrorMessage(e))}finally{isCurrentSearch(a)&&(c=!1,this.#ft())}},u=e.notices;if(e.kind===`task-list`||e.kind===`search`&&e.layout===`task-list`){let n=t.taskListLineStart??t.lines.length,r=t.lines.slice(n).filter(e=>e.tone===`success`||e.tone===`warning`||e.tone===`error`).map(e=>({tone:e.tone,text:e.text}));u=[...e.notices??[],...r],t.taskListLineStart=t.lines.length,t.hideLinesWhileQuestion=!0}let panelState=()=>{let t={...e,options:i,select:o};return u!==void 0&&u.length>0&&(t.notices=u),s!==void 0&&(t.error=s),c&&(t.loadingFrame=this.#yt()),t};return t.question=e=>renderSelectQuestion(panelState(),this.#r,e),this.#ft(),await this.#Oe((t,a)=>{let close=e=>{l+=1,a(e)};if(c){t.type===`ctrl-c`?close(void 0):t.type===`escape`?clearSearch():t.type===`ctrl-r`&&this.#ft();return}let u={key:t,options:i,searchAction:r,select:o},d=reduceSetupSelectInput(n?{...u,kind:e.kind,required:e.required}:{...u,kind:e.kind});switch(d.kind){case`cancel`:close(void 0);return;case`repaint`:this.#ft();return;case`update`:o=d.select,s=void 0,this.#ft();return;case`submit`:{let e=searchActionQuery(d.values[0]??``),t=r?.load;if(e===void 0||t===void 0){close(d.values);return}loadSearch(e,t);return}case`error`:s=d.message,this.#ft();return;case`ignore`:return}}).promise}#ye(e){this.#Fe();let t=this.#Ee();t.status={kind:`progress`,text:stripTerminalControls(e.status)};let n;t.question=t=>renderSelectQuestion({kind:`actions`,context:e.context,actions:e.actions,cursor:n},this.#r,t),this.#ft();let r=this.#Oe((t,r)=>{let i=setupSelectionIntent(t);switch(i?.kind){case`cancel`:r(void 0);return;case`move`:n=moveActionCursor(n,i.direction,e.actions.length),this.#ft();return;case`repaint`:this.#ft();return;case`submit`:n!==void 0&&r(e.actions[n].value);return;case void 0:return}},()=>{t.status=void 0});return{choice:r.promise,close:()=>r.settle(void 0)}}async#be(e){let t=this.#Te(),n={options:e.options};e.initialValue!==void 0&&(n.defaultValue=e.initialValue);let r=initialSelectState(n),i=lineOf(``),a;t.question=t=>{let n={kind:`inline-edit`,layout:`task-list`,message:e.message,options:e.options,select:r,edit:{optionValue:e.editable.value,caretVisible:this.#R,editor:{kind:`rename`,editor:i,defaultValue:e.editable.defaultValue,formatHint:e.editable.formatHint}}};return a!==void 0&&(n.error=a),renderSelectQuestion(n,this.#r,t)};let onEditableRow=()=>selectValueAtCursor([...e.options],r.cursor)===e.editable.value,syncEditableRow=()=>{onEditableRow()?this.#We():(i=lineOf(``),this.#Ge())};return syncEditableRow(),this.#ft(),await this.#Oe((t,n)=>{let applyEditor=e=>{i=e,a=void 0,this.#Ke(),this.#ft()},applySelect=t=>{r=reduceSelect(r,t,{options:e.options}),a=void 0,syncEditableRow(),this.#ft()},submit=()=>{let t=selectValueAtCursor([...e.options],r.cursor);if(t===void 0)return;if(t!==e.editable.value){n({kind:`selected`,value:t});return}let o=(i.text||e.editable.defaultValue).trim(),s=e.editable.validate?.(o);if(s!==void 0){a=s,this.#ft();return}n(o===e.editable.defaultValue?{kind:`selected`,value:t}:{kind:`edited`,value:t,text:o})},o=setupSelectionIntent(t);switch(o?.kind){case`cancel`:n(void 0);return;case`move`:applySelect({type:o.direction});return;case`submit`:submit();return;case`repaint`:this.#ft();return;case void 0:break}if(!onEditableRow())return;let s=applyLineEditorKey(i,t);s!==void 0&&applyEditor(s)},()=>this.#Ge()).promise}async#xe(e){let t=this.#Te(),n=initialProviderPickerState(e.options,e.initialValue),r,cursorBadge=()=>{if(n.phase.kind!==`inactive`)return;let t=selectValueAtCursor([...e.options],n.select.cursor),r=e.options.find(e=>e.value===t);if(r!==void 0)return enterBadge(this.#r,r.checked===!0?`change`:void 0)};t.question=t=>{let r=cursorBadge(),i={kind:`inline-edit`,layout:`stacked`,message:e.message,options:e.options,select:n.select,edit:{optionValue:`own-key`,caretVisible:this.#R,editor:{kind:`key`,phase:n.phase}}};return r!==void 0&&(i.cursorBadge=r),renderSelectQuestion(i,this.#r,t)};let syncCaret=()=>{n.phase.kind===`editing`||n.phase.kind===`invalid`?this.#We():this.#Ge()};return syncCaret(),this.#ft(),await this.#Oe((t,i,a)=>{let dispatch=t=>{let o=transitionProviderPicker(n,t,e.options);switch(o.kind){case`ignore`:return;case`clear`:r?.abort(),r=void 0,n=o.state,syncCaret(),this.#ft();return;case`cancel`:i(void 0);return;case`render`:n=o.state,syncCaret(),this.#ft();return;case`validate`:{n=o.state,syncCaret(),this.#ft();let t=new AbortController;r=t;let i;try{i=e.validateInlineKey(o.key,t.signal)}catch(e){a(e);return}i.then(e=>{r!==t||t.signal.aborted||(r=void 0,dispatch({type:`validated`,validation:e}))},e=>{r!==t||t.signal.aborted||(r=void 0,a(e))});return}case`settle`:i(o.result);return}},o=setupSelectionIntent(t);switch(o?.kind){case`cancel`:dispatch({type:`cancel`});return;case`move`:dispatch({type:`move`,direction:o.direction});return;case`submit`:dispatch({type:`submit`});return;case`repaint`:this.#ft();return;case void 0:break}if(n.phase.kind!==`editing`&&n.phase.kind!==`invalid`)return;let s=applyLineEditorKey(n.phase.editor,t);s!==void 0&&(this.#Ke(),dispatch({type:`edit`,editor:s}))},()=>{r?.abort(),r=void 0,this.#Ge()}).promise}async#Se(e){let t=this.#Te(),n=initialModelEditorState(e);return t.question=t=>renderModelEditorQuestion({request:e,state:n},this.#r,t),this.#ft(),await this.#Oe((t,r)=>{let dispatch=t=>{let i=transitionModelEditor(n,t,e);switch(i.kind){case`ignore`:return;case`render`:n=i.state,this.#ft();return;case`cancel`:r(void 0);return;case`settle`:r(i.result);return}},i=setupSelectionIntent(t);switch(i?.kind){case`cancel`:dispatch({type:`cancel`});return;case`move`:dispatch({type:`move`,direction:i.direction});return;case`submit`:dispatch({type:`submit`});return;case`repaint`:this.#ft();return;case void 0:break}if(t.type===`left`||t.type===`right`){dispatch({type:`adjust`,direction:t.type});return}if(t.type===`tab`){dispatch({type:`adjust`,direction:`right`});return}if(t.type===`backspace`){dispatch({type:`backspace`});return}if(t.type===`text`)for(let e of t.value.replaceAll(`
4
- `,` `))e>=` `&&e!==``&&dispatch({type:`char`,char:e})}).promise}async#Ce(e){let t=this.#Te(),n=lineOf(``),r;return t.question=t=>{let i={message:e.message,editor:n,mask:e.mask===!0};return e.placeholder!==void 0&&(i.placeholder=e.placeholder),e.notices!==void 0&&(i.notices=e.notices),r!==void 0&&(i.error=r),renderTextQuestion(i,this.#r,t,this.#R)},this.#We(),this.#ft(),await this.#Oe((t,i)=>{let apply=e=>{n=e,r=void 0,this.#Ke(),this.#ft()},a=applyLineEditorKey(n,t);if(a!==void 0){apply(a);return}switch(t.type){case`ctrl-c`:case`escape`:i(void 0);return;case`ctrl-r`:this.#ft();return;case`enter`:{let t=n.text.length>0?n.text:e.defaultValue??``,a=e.validate?.(t);if(a!==void 0){r=a,this.#ft();return}i(t);return}default:return}},()=>this.#Ge()).promise}async#we(e){let t=this.#Te();return t.question=t=>renderAcknowledgeQuestion({message:e.message,lines:e.lines},this.#r,t),this.#ft(),await this.#Oe((e,t)=>{switch(e.type){case`enter`:case`escape`:case`ctrl-c`:t();return;case`ctrl-r`:this.#ft();return;default:return}}).promise}#Te(){return this.#Fe(),this.#j=!1,this.#N={kind:`idle`},this.#P=``,this.#Ee()}#Ee(){return this.#le===void 0&&(this.#le={title:``,indicator:{kind:`spinner`},lines:[],outputBuffer:[]}),this.#le}#De(){this.#le!==void 0&&(this.#le.question=void 0,this.#le.hideLinesWhileQuestion=!1),this.#W=void 0,this.#Re(),this.#Ae(),this.#ft()}#Oe(e,t){let n=!1,r,i,a=new Promise((e,t)=>{r=e,i=t}),settle=e=>{n||(n=!0,t?.(),this.#De(),r(e))},reject=e=>{n||(n=!0,t?.(),this.#De(),i(e))};return this.#W=t=>e(t,settle,reject),this.#Le(),{promise:a,settle}}#ke(){let e,t=new Promise(t=>{e=t});return this.#de=e,this.#Ae(),{promise:t,dispose:()=>{this.#de===e&&(this.#de=void 0,this.#je())}}}#Ae(){if(this.#de===void 0)return;let consumer=e=>{if(e.type===`ctrl-c`||e.type===`escape`){let e=this.#de;this.#de=void 0,this.#je(),e?.();return}e.type===`ctrl-r`&&this.#ft()};this.#fe=consumer,this.#W=consumer,this.#Le()}#je(){this.#fe!==void 0&&(this.#W===this.#fe&&this.#Re(),this.#fe=void 0)}#Me(e){let t=e===void 0?void 0:typeof e==`string`?{kind:`progress`,text:stripTerminalControls(e)}:{kind:`external-action`,text:stripTerminalControls(e.text),emphasis:stripTerminalControls(e.emphasis)};if(this.#le!==void 0){this.#le.status=t,t===void 0&&(this.#le.preview=void 0),this.#ft();return}if(t===void 0){this.#N={kind:`idle`},this.#P=``,this.#Ye(),this.#ft();return}this.#Fe(),this.#Je(),this.#P=t.text,this.#ft()}#Ne(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;let r=this.#le;if(r!==void 0){if(r.preview=void 0,t===`warning`||t===`error`)for(let e of r.outputBuffer)r.lines.push({text:e,tone:`info`,evidence:!0});r.outputBuffer=[],r.lines.push({text:n,tone:t}),this.#ft();return}this.#Fe(),this.#Xe({kind:`flow`,title:t,body:n,live:!1}),this.#ft()}#Pe(e){let t=stripTerminalControls(e);if(t.trim().length===0)return;let n=this.#le;if(n===void 0){this.#Ne(t,`info`);return}n.preview=t,n.outputBuffer.push(t),n.outputBuffer.length>40&&n.outputBuffer.shift(),this.#ft()}shutdown(){this.#Ie()}#Fe(e){this.#F=e?.title??this.#F,!this.#I&&(this.#I=!0,this.#n.reset(),this.#n.hideCursor(),this.#Ot(),this.#e.isTTY&&(this.#e.setRawMode?.(!0),this.#e.resume(),this.#n.emitBracketedPaste(!0)),this.#J=()=>this.#ft(),this.#t.on(`resize`,this.#J))}#Ie(){this.#Re(),this.#Ge(),this.#Ye(),this.#H!==void 0&&(clearTimeout(this.#H),this.#H=void 0),this.#U=!1,this.#I&&=(this.#Lt(),this.#ft(),this.#n.clear(),this.#n.showCursor(),this.#kt(),this.#n.newline(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1),this.#e.pause()),this.#J&&=(this.#t.off(`resize`,this.#J),void 0),!1)}#Le(){this.#e.off(`data`,this.#ze),this.#e.on(`data`,this.#ze)}#Re(){this.#e.off(`data`,this.#ze),this.#He(),this.#G=``,this.#K=new StringDecoder(`utf8`),this.#W=void 0}#ze=e=>{this.#He(),this.#G+=this.#K.write(e),this.#Ve(),this.#Be()};#Be(){if(this.#G===`\x1B`){this.#q=setTimeout(()=>{this.#G===`\x1B`&&(this.#G=``,this.#W?.({type:`escape`}))},30),this.#q.unref?.();return}if(isIncompletePaste(this.#G)){let e=this.#G;this.#q=setTimeout(()=>{if(this.#G!==e)return;let t=sanitizePastedText(stripPasteStart(e));this.#G=``,t.length>0&&this.#W?.({type:`text`,value:t,framing:`bracketed-paste`})},1e3),this.#q.unref?.()}}#Ve(){for(;this.#G.length>0;){let e=nextKey(this.#G);if(e.incomplete)return;this.#G=this.#G.slice(e.consumed),e.key&&e.key.type!==`ignore`&&this.#W?.(e.key)}}#He(){this.#q&&=(clearTimeout(this.#q),void 0)}#Ue(e){switch(e.type){case`ctrl-l`:case`ctrl-r`:this.#ft();break;case`ctrl-c`:this.#L||(this.#L=!0,this.#N={kind:`idle`},this.#P=`Interrupted`,this.#Y?.(),this.#ft());break;default:break}}#We(){this.#Ge(),this.#Ke(),this.#B=setInterval(()=>{this.#R=!this.#R,this.#ft()},500),this.#B.unref?.()}#Ge(){this.#B&&=(clearInterval(this.#B),void 0),this.#R=!0}#Ke(){this.#R=!0}#qe(){this.#Ye(),this.#V=setInterval(()=>{this.#z+=1,this.#ft()},90),this.#V.unref?.()}#Je(){this.#N={kind:`waiting`,startedAtMs:Date.now()},this.#qe()}#Ye(){this.#V&&=(clearInterval(this.#V),void 0)}#Xe(e){e.id!==this.#oe?.id&&this.#Lt(),this.#p.push(e),e.id&&this.#m.set(e.id,e)}#Ze(e){this.#Xe({kind:`user`,body:stripTerminalControls(e),live:!1}),this.#ft()}#Qe(e){if(e!=null){if(this.#ce===e){this.#ce=void 0;return}this.#Xe({kind:`user`,body:stripTerminalControls(e),live:!1})}}#$e(e,t,n={}){let r=stripTerminalControls(e),i=stripTerminalControls(t),a=n.detail===void 0?void 0:stripTerminalControls(n.detail),o=n.hint===void 0?void 0:stripTerminalControls(n.hint),s={source:`workflow`,summary:`${r}: ${i}`,detail:a??i};this.#u?.append(o===void 0?s:{...s,hint:o});let c={kind:`error`,title:r,body:i,live:!1};o!==void 0&&(c.hint=o),a!==void 0&&(c.detail=this.#u===void 0?a:`details: ${this.#u.displayPath}`),this.#Xe(c),this.#ft()}#et(e,t){this.#y.has(e)||(this.#y.add(e),this.#Xe({id:subagentHeaderId(e),kind:`subagent`,title:stripTerminalControls(t),live:!1}))}#tt(e){if(e.id&&this.#h.has(e.id))return;let t=e.id?this.#m.get(e.id):void 0;if(t){Object.assign(t,e);return}this.#Xe(e)}#nt(e){this.#p=this.#p.filter(t=>t.id!==e),this.#m.delete(e)}#rt(){for(let e of this.#p)e.status===`approval`||e.status===`running`||e.kind===`connection-auth`&&e.live||(e.live=!1)}#it(e,t,n){switch(e.type){case`step-start`:this.#at(n.hasPendingToolResults?STATUS.toolResults:STATUS.processing),n.hasPendingToolResults=!1;break;case`step-finish`:this.#u?.recordStepUsage(e.usage),this.#dt(e.usage),this.#ft();break;case`assistant-delta`:{let t=(n.text.get(e.id)??``)+stripTerminalControls(e.delta);this.#ot(t),this.#at(STATUS.streaming),n.text.set(e.id,t),this.#st(e.id,t,!0);break}case`assistant-complete`:{let t=n.text.get(e.id)??``,r=e.text!==void 0&&t.length===0?stripTerminalControls(e.text??``):t;this.#ot(r),n.text.set(e.id,r),this.#st(e.id,r,!1);break}case`reasoning-delta`:{if(t.reasoning===`hidden`)break;let r=(n.reasoning.get(e.id)??``)+stripTerminalControls(e.delta);this.#ot(r),this.#at(STATUS.streaming),n.reasoning.set(e.id,r),this.#ct(e.id,r,!0,t);break}case`reasoning-complete`:{if(t.reasoning===`hidden`)break;let r=n.reasoning.get(e.id)??``;this.#ot(r),this.#ct(e.id,r,!1,t);break}case`tool-call`:if(this.#u?.recordToolCall(e.toolName),t.tools===`hidden`)break;this.#at(STATUS.executingTools),this.#lt({input:e.input,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-approval-request`:{if(t.tools===`hidden`)break;let r=n.tools.get(e.toolCallId);if(r===void 0)break;this.#lt({...r,status:`approval`},t,n);break}case`tool-result`:{if(t.tools===`hidden`)break;let r=this.#ut(e.toolCallId,n);if(r===void 0)break;n.hasPendingToolResults=!0,this.#at(STATUS.toolResults),this.#lt({...r,output:e.output,status:`done`},t,n);break}case`tool-error`:{let r=this.#ut(e.toolCallId,n);if(this.#u?.append({source:`tool`,summary:`${r?.toolName??e.toolCallId} failed`,detail:e.errorText}),t.tools===`hidden`||r===void 0)break;n.hasPendingToolResults=!0,this.#at(STATUS.toolResults),this.#lt({...r,errorText:e.errorText,status:`error`},t,n);break}case`error`:this.#$e(`Error`,e.errorText,{detail:e.detail,hint:e.hint});break;case`finish`:this.#dt(e.usage),this.#ft();break}}#at(e){let t=this.#T>0?STATUS.connectionAuth:e;this.#P!==t&&(this.#P=t,this.#ft())}#ot(e){e.trim().length>0&&(this.#N={kind:`answering`})}#st(e,t,n){let r=stripTerminalControls(t).trim();r.length!==0&&(this.#tt({id:e,kind:`assistant`,body:r,live:n}),this.#ft())}#ct(e,t,n,r){let i=stripTerminalControls(t).trim();i.length!==0&&(this.#tt({id:e,kind:`reasoning`,body:i,collapsed:collapseReasoning(r.reasoning,n),live:n}),this.#ft())}#lt(e,t,n){if(n.tools.set(e.toolCallId,e),this.#_.has(e.toolCallId))return;let r=toolSectionId(e.toolCallId);this.#v.set(e.toolCallId,r),this.#tt(renderNativeToolBlock(e,r,t.tools===`full`)),this.#ft()}#ut(e,t){let n=t.tools.get(e);if(n!==void 0)return n;let r=this.#v.get(e)??toolSectionId(e),i=this.#m.get(r);if(!(i===void 0||i.kind!==`tool`))return{errorText:i.status===`error`&&typeof i.result==`string`?i.result:void 0,input:i.toolInput,output:i.toolOutput,status:i.status??`running`,toolCallId:e,toolName:i.title??`tool`}}#dt(e){if(e===void 0)return;let{inputTokens:t,outputTokens:n}=e;if((t!=null||n!=null)&&(this.#Q=(t??0)+(n??0)),this.#$=n??this.#$,this.#$!=null&&this.#te!==void 0){let e=(Date.now()-this.#te)/1e3;e>0&&(this.#ee=this.#$/e)}}#ft(){if(this.#I){if(this.#X){this.#Z=!0;return}this.#X=!0;try{do this.#Z=!1,this.#pt();while(this.#Z)}finally{this.#X=!1}}}#pt(){if(!this.#I)return;let e=this.#Et(),t=this.#St(e),n=Math.max(1,this.#Dt()-t.length),r=[],i=this.#w;for(;this.#p.length>0&&this.#p[0].live===!1;){let t=this.#p.shift();if(this.#g.push(t),t.id&&(this.#h.add(t.id),this.#m.delete(t.id)),this.#zt(t))continue;let n=this.#vt(t,e,i);i=previousBlockOf(t),this.#w=i,r.push(...n),this.#C.push(...n)}let a=[];for(let t of this.#p){if(this.#zt(t))continue;let n=this.#vt(t,e,i);i=previousBlockOf(t);for(let e=0;e<n.length;e+=1)a.push({block:t,row:n[e]})}let o=[...clipLiveRows(a.map(e=>e.row),n,e,this.#r),...t];r.length>0?this.#n.flush(r,o):this.#n.update(o)}#mt(){if(!this.#I)return;let e=this.#Et(),t=this.#St(e),n=Math.max(1,this.#Dt()-t.length),r=this.#w,i=[];for(let t of this.#p){if(this.#zt(t))continue;let n=this.#vt(t,e,r);r=previousBlockOf(t),i.push(...n)}let a=[...clipLiveRows(i,n,e,this.#r),...t];this.#n.clearAll(),this.#n.flush([...this.#_t(),...this.#C],a)}logDisplayMode(){return this.#f}setLogDisplayMode(e){e!==this.#f&&(this.#f=e,e===`all`&&this.flushDelayedDevBuildErrors(),this.#gt(),this.#I&&this.#mt())}flushDelayedDevBuildErrors(){let e=this.#ae;e!==void 0&&(this.#ae=void 0,this.#Xe({kind:`log`,title:`stderr`,body:e,live:!1}),this.#ft())}#ht(){this.#U=!0,this.#H!==void 0&&clearTimeout(this.#H),this.#H=setTimeout(()=>{this.#U=!1,this.#H=void 0,this.#ft()},5e3),this.setLogDisplayMode(nextLogDisplayMode(this.#f)),this.#ft()}#gt(){let e=this.#Et();this.#C.length=0;let t;for(let n of this.#g){if(this.#zt(n))continue;let r=this.#vt(n,e,t);t=previousBlockOf(n),this.#C.push(...r)}this.#w=t}#_t(){let e=this.#b;if(e===void 0)return[];let t={name:e.name,theme:this.#r,width:this.#Et()};return e.info!==void 0&&(t.info=e.info),e.tip!==void 0&&(t.tip=e.tip),buildAgentHeader(t)}#vt(e,t,n){let r={spinner:this.#yt()};n!==void 0&&(r.previous=n);let i=renderBlockLines(e,t,this.#r,r);return(e.depth??0)===0&&leadsWithGap(e,n)?[``,...i]:i}#yt(){return this.#r.spinner[this.#z%this.#r.spinner.length]??``}#bt(e,t){return isProgressPulseVisible(Date.now()-e)?t:` `}#xt(e,t){return e.indicator.kind===`spinner`?{glyph:this.#yt(),color:`yellow`}:{glyph:this.#bt(e.indicator.startedAtMs,this.#r.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH),color:t?.kind===`external-action`?`yellow`:`green`}}#St(e){let n=this.#r.colors,r=[``],i=this.#le;if(i!==void 0){let t=this.#xt(i,i.status),n=i.status===void 0?void 0:{...i.status,indicator:t},a;if(i.question!==void 0){let t=i.question(e);a={kind:`question`,rows:t},n!==void 0&&(a={kind:`question`,rows:t,status:n})}else n===void 0?a=i.preview===void 0?{kind:`idle`,indicator:t}:{kind:`preview`,text:i.preview,indicator:t}:(a={kind:`status`,status:n},i.preview!==void 0&&(a={kind:`status`,status:n,preview:i.preview}));let o={title:i.title,lines:i.hideLinesWhileQuestion===!0?[]:i.lines,content:a};return r.push(...renderFlowPanel(o,this.#r,e)),this.#wt(r,e),r}if(this.#ue!==void 0&&r.push(...renderAttentionRows(this.#ue,e,this.#r),``),this.#j){let i=this.#M===void 0?void 0:inlineCommandHint(this.#M);i===void 0&&this.#M!==void 0&&isTypeaheadOpen(this.#M)&&r.push(...renderCommandSuggestions(this.#M,this.#r,e));let a=isPromptControlCommand(this.#O),o=i?n.dim(` ${i}`):``,s=[];this.#Ct(s,e);let c=Math.max(1,this.#Dt()-1-r.length-1-s.length);return r.push(...promptInputRows({text:this.#O,cursor:this.#k,width:e,theme:this.#r,caretVisible:this.#R,isCommand:a,ghost:o,maxRows:c})),r.push(...s),r}let a=this.#N;if(a.kind===`answering`)return this.#Ct(r,e),r;let s=a.kind===`waiting`,c=s?n.green(this.#bt(a.startedAtMs,this.#r.unicode?`⊙`:`o`)):n.dim(this.#r.glyph.dot),d=this.#P.length>0?this.#P:`Ready`,p=s?n.dim(d):d,m=this.#Tt(),h=s?` `:``,g=m?`${h}${c} ${p} ${n.dim(this.#r.glyph.dot)} ${m}`:`${h}${c} ${p}`;r.push(clip(g,e));let _=[];return this.#Ct(_,e),s&&_.length>0&&r.push(``),r.push(..._),r}#Ct(e,t){let n=this.#D===void 0?``:` `,r=Math.max(1,t-n.length),i={theme:this.#r,width:r};this.#U&&(i.logLevel=this.#f);let a=this.#b?.serverUrl;if(a!==void 0&&this.#D===void 0){let e=new URL(a).port;e.length>0&&(i.serverPort=e)}let o=this.#b?.info?.agent.model;o?.id!==void 0&&(i.model=o.id),o?.reasoning!==void 0&&o.reasoning!==`provider-default`&&(i.reasoning=o.reasoning),readGatewayServiceTier(o?.providerOptions).kind===`priority`&&(i.fastMode=!0);let s=o?.endpoint;s!==void 0&&(i.endpoint=s),this.#E!==void 0&&(i.vercel=this.#E),this.#D!==void 0&&(i.remote=this.#D);let c=buildStatusLine(i);c!==void 0&&e.push(clip(`${n}${c}`,t))}#wt(e,t){if(this.#D===void 0)return;let n=Math.max(1,t-2),r=buildStatusLine({remote:this.#D,theme:this.#r,width:n});r!==void 0&&e.push(``,clip(` ${r}`,t))}#Tt(){let e=this.#r.colors,t=[],n=formatAssistantResponseStats({totalTokens:this.#Q,outputTokens:this.#$,tokensPerSecond:this.#ee},this.#c);return n&&t.push(n),t.length>0?e.dim(t.join(` ${this.#r.glyph.dot} `)):``}#Et(){return Math.max(20,this.#t.columns||80)}#Dt(){return Math.max(8,this.#t.rows||24)}#Ot(){if(this.#ne!==void 0||!this.#l)return;this.#re=``,this.#ie=``;let capture=(e,t)=>{let n=e.write.bind(e);return e.write=((e,n,r)=>{let i=typeof n==`string`?n:void 0,a=typeof n==`function`?n:r;return this.#jt(t,chunkToString(e,i)),a?.(),!0}),()=>{e.write=n}},e=capture(process.stdout,`stdout`),t=capture(process.stderr,`stderr`);this.#u?.subscribeLogRecords(e=>this.#At(e)),this.#ne=()=>{this.#u?.unsubscribeLogRecords(),e(),t()}}#kt(){let e=this.#ne;e!==void 0&&(this.#ne=void 0,e(),this.#re.length>0&&(this.#u?.append({source:`stdout`,detail:this.#re}),this.#Rt(`stdout`)&&process.stdout.write(`${this.#re}\n`),this.#re=``),this.#ie.length>0&&(this.#u?.append({source:`stderr`,detail:this.#ie}),this.#Rt(`stderr`)&&process.stderr.write(`${this.#ie}\n`),this.#ie=``))}#At(e){let t=e.fields===void 0?``:` ${JSON.stringify(e.fields)}`;this.#Nt(`[eve:${e.namespace}] ${e.message}${t}`),this.#ft()}#jt(e,t){let n=(e===`stdout`?this.#re:this.#ie)+t,r=n.lastIndexOf(`
5
- `),i=r===-1?n:n.slice(r+1);if(e===`stdout`?this.#re=i:this.#ie=i,r===-1)return;let a=stripAnsi(n.slice(0,r)).replace(/\s+$/u,``);a.trim().length!==0&&(this.#u?.append({source:e,detail:a}),e===`stdout`?this.#Mt(a):this.#Nt(a),this.#ft())}#Mt(e){let t=[],flushPending=()=>{if(t.length===0)return;let e=t.join(`
6
- `);t=[],e.trim().length!==0&&this.#Xe({kind:`log`,title:`stdout`,body:e,live:!1})};for(let n of e.split(`
7
- `)){let e=parseSandboxLogLine(n.trimEnd());if(e!==void 0){flushPending(),this.#Xe({kind:`sandbox`,body:e,live:!1});continue}let r=parseDevRebuildLogLine(n.trimEnd());if(r===void 0){t.push(n);continue}flushPending(),this.#Ft(r,n.trimEnd())}flushPending()}#Nt(e){let t=e.split(`
8
- `),n=t.findIndex(e=>parseDevRebuildLogLine(e.trimEnd())?.kind===`failed`);if(n===-1){if(this.#u===void 0){this.#Xe({kind:`log`,title:`stderr`,body:e,live:!1});return}let t=presentDiagnostic(e,this.#u.displayPath);if(t.kind===`inline`){this.#Xe({kind:`log`,title:`stderr`,body:t.text,live:!1});return}this.#Xe({kind:`log`,title:`stderr`,body:formatStoredDiagnostic(t),logVisibility:`stderr-only`,live:!1}),this.#Xe({kind:`log`,title:`stderr`,body:e,logVisibility:`all-only`,live:!1});return}let r=t.slice(0,n).join(`
9
- `);r.trim().length>0&&this.#Xe({kind:`log`,title:`stderr`,body:r,live:!1});let i=t.slice(n).join(`
10
- `);this.#Pt(i)}#Pt(e){if(this.#f===`all`){if(e.trim().length===0)return;this.#Xe({kind:`log`,title:`stderr`,body:e,live:!1});return}this.#ae=e}#Ft(e,t){let n=this.#It();if(e.kind===`failed`){this.#Pt(t);return}if(e.kind===`rebuilding`){let t=summarizeChangedFiles(e.events,e.more);if(n!==void 0){n.state.summary=t,n.block.body=formatDevRebuildStatus(t,`rebuilding`);return}let r=`dev-rebuild:${this.#se}`;this.#se+=1,this.#oe={id:r,summary:t},this.#Xe({kind:`log`,id:r,title:`stdout`,body:formatDevRebuildStatus(t,`rebuilding`),live:!0});return}if(n!==void 0){n.block.body=formatDevRebuildStatus(n.state.summary,e.kind),e.kind===`rebuilt`&&(this.#ae=void 0);return}e.kind===`rebuilt`&&(this.#ae=void 0),this.#Xe({kind:`log`,title:`stdout`,body:t,live:!1})}#It(){let e=this.#oe;if(e===void 0)return;let t=this.#m.get(e.id);if(!(t===void 0||t.live!==!0))return{state:e,block:t}}#Lt(){let e=this.#oe;if(e===void 0)return;this.#oe=void 0;let t=this.#m.get(e.id);t!==void 0&&(t.live=!1)}#Rt(e){switch(this.#f){case`none`:return!1;case`stderr`:return e===`stderr`;case`sandbox`:return e===`sandbox`;case`all`:return!0}}#zt(e){return e.kind===`sandbox`?!this.#Rt(`sandbox`):e.kind===`log`?e.logVisibility===`stderr-only`?this.#f!==`stderr`:e.logVisibility===`all-only`?this.#f!==`all`:!this.#Rt(e.title===`stderr`?`stderr`:`stdout`):!1}};function chunkToString(e,t){return typeof e==`string`?e:Buffer.from(e).toString(t)}async function*iterateTUIStream(e){if(e instanceof ReadableStream){let t=e.getReader();try{for(;;){let{done:e,value:n}=await t.read();if(e)return;yield n}}finally{t.releaseLock()}return}yield*e}function clip(e,t){return clipVisible(e,t)}function promptInputRows({text:e,cursor:t,width:n,theme:r,caretVisible:i,isCommand:a,ghost:o,maxRows:s}){let c=r.colors,style=e=>{let t=renderInputText(e);return a&&t.length>0?c.blue(t):t},l=layoutPromptInput({text:e,cursor:t}),u=Math.min(Math.max(1,s),l.rows.length),d=Math.max(0,Math.min(l.caretRow-u+1,l.rows.length-u)),f=c.cyan(r.glyph.prompt),p=c.dim(r.glyph.ellipsis),m=Math.max(1,n-4),h=[];for(let e=d;e<d+u;e+=1){let t=l.rows[e],a=e===0?f:` `;(e===d&&d>0||e===d+u-1&&d+u<l.rows.length)&&(a=p);let s;if(e===l.caretRow){let{before:e,under:n,after:a}=visibleLine({text:t.text,cursor:l.caretOffset},m,r.glyph.ellipsis);s=renderInputWithBlockCursor({before:e,under:n,after:a,visible:i,inverse:c.inverse,render:style}),o.length>0&&l.rows.length===1&&(s+=o)}else s=style(t.text);h.push(clip(` ${a} ${s}`,n))}return h.push(``),h}function previousBlockOf(e){let t={kind:e.kind};return e.title!==void 0&&(t.title=e.title),t}function leadsWithGap(e,t){if(e.kind===`sandbox`&&t?.kind===`sandbox`)return!1;if(t?.kind===`sandbox`&&e.kind!==`sandbox`)return!0;if(e.kind===`log`&&t?.kind===`log`)return t.title!==e.title;if(t?.kind===`log`&&e.kind!==`log`)return!0;switch(e.kind){case`user`:case`assistant`:case`reasoning`:case`subagent`:case`error`:case`notice`:case`question`:case`connection-auth`:case`sandbox`:case`log`:case`command`:case`warning`:case`flow`:case`agent-header`:return!0;default:return!1}}function parseSandboxLogLine(e){let t=e.trim();if(!t.startsWith(`eve: `))return;let n=t.slice(5);return/\bsandbox\b/i.test(n)&&!isLowValueSandboxLogLine(n)?n:void 0}function isLowValueSandboxLogLine(e){return/^initializing (?:\d+ )?sandbox templates?\b/i.test(e)||/^initialized \d+ sandbox\b/i.test(e)||/^reused cached sandbox template\b/i.test(e)||/^sandbox template "[^"]+" \([^)]+\): (checking|reusing|loading microsandbox runtime|microsandbox runtime ready)\b/i.test(e)}function clipLiveRows(e,t,n,r){if(e.length<=t)return[...e];if(t<=1)return[clip(hiddenRowsMarker(e.length,r),n)];let i=t-1;return[clip(hiddenRowsMarker(e.length-i,r),n),...e.slice(e.length-i)]}function hiddenRowsMarker(e,t){let n=e.toLocaleString(),r=e===1?`row`:`rows`;return t.colors.dim(`${t.glyph.dot} ${t.glyph.ellipsis} ${n} earlier ${r} hidden while streaming`)}function collapseReasoning(e,t){switch(e){case`collapsed`:return!0;case`auto-collapsed`:return!t;default:return!1}}function renderNativeToolBlock(e,t,n){let a={id:t,kind:`tool`,title:stripTerminalControls(e.toolName),subtitle:summarizeToolArgs(e.input),status:e.status,live:e.status===`running`||e.status===`approval`,expanded:n,toolInput:e.input};return e.output===void 0?e.errorText!==void 0&&(a.result=stripTerminalControls(e.errorText)):(a.result=summarizeToolResult(e.output),a.toolOutput=e.output),a}function subagentToolStatus(e){switch(e){case`approval-requested`:return`approval`;case`executing`:return`running`;case`done`:return`done`;case`failed`:return`error`}}function formatToolApprovalTitle(e){return stripTerminalControls(e.title??e.toolName)}function toolSectionId(e){return`tool:${e}`}function questionSectionId(e){return`question:${e}`}function subagentHeaderId(e){return`subagent:${e}:header`}function subagentStepSectionId(e,t){return`subagent:${e}:step:${t}`}function subagentToolSectionId(e,t){return`subagent:${e}:tool:${t}`}function connectionAuthSectionId(e){return`connection-auth:${e}`}function connectionAuthTerminalMessage(e){switch(e){case`authorized`:return`Authorization complete`;case`declined`:return`Authorization declined`;case`failed`:return`Authorization failed`;case`timed-out`:return`Authorization timed out`;case`required`:case`pending`:return}}function formatConnectionAuthContent(e,t){let n=[];if(t!==void 0)n.push(t);else{let t=stripTerminalControls(e.description);t.length>0&&n.push(t);let r=e.challenge;r?.url&&n.push(`URL: ${stripTerminalControls(r.url)}`),r?.userCode&&n.push(`Code: ${stripTerminalControls(r.userCode)}`),r?.expiresAt&&n.push(`Expires: ${stripTerminalControls(r.expiresAt)}`),r?.instructions&&n.push(stripTerminalControls(r.instructions))}if(e.reason!==void 0){let t=stripTerminalControls(e.reason);t.length>0&&n.push(`Reason: ${t}`)}return n.join(`
1
+ import{PROMPT_COMMANDS,isPromptControlCommand,parsePromptCommand}from"./prompt-commands.js";import{buildAgentHeader}from"./agent-header.js";import{renderAttentionRows,renderBlockLines}from"./blocks.js";import{dismissTypeahead,inlineCommandHint,isTypeaheadOpen,moveTypeaheadSelection,renderCommandSuggestions,selectedTypeaheadCommand,typeaheadCompletion,typeaheadFor}from"./command-typeahead.js";import{formatDevRebuildStatus,summarizeChangedFiles}from"./dev-rebuild-status.js";import{formatStoredDiagnostic,presentDiagnostic}from"./diagnostic-presentation.js";import{interruptedError}from"./errors.js";import{FileContentCache}from"./file-content-cache.js";import{EMPTY_LINE,PromptHistory,applyLineEditorKey,deleteForward,layoutPromptInput,lineOf,movePromptLine,visibleLine}from"./line-editor.js";import{nextLogDisplayMode}from"./log-display-mode.js";import{initialModelEditorState,transitionModelEditor}from"./model-editor.js";import{promptPlaceholder}from"./prompt-placeholder.js";import{initialProviderPickerState,transitionProviderPicker}from"./provider-picker.js";import{renderQuestionPanel}from"./question-panel.js";import{enterBadge,renderAcknowledgeQuestion,renderFlowPanel,renderModelEditorQuestion,renderSelectQuestion,renderTextQuestion}from"./setup-panel.js";import{buildStatusLine}from"./status-line.js";import{createTheme,detectUnicode}from"./theme.js";import{isPanelRoutedTool,presentPreparingTool,presentTool,readWriteFileInput,toolBaseName}from"./tool-presentation.js";import{groupToolBlocksForDisplay}from"./tool-block-groups.js";import{TurnClock}from"./turn-clock.js";import{allTodoItemsSettled,readTodoToolItems,renderFinishedTodoRows,renderTodoPanelRows}from"./todo-panel.js";import{reduceSetupSelectInput,setupSelectionIntent}from"./setup-selection-input.js";import{formatAssistantResponseStats,formatTokenFlow,formatTurnDuration,isIncompletePaste,nextKey,sanitizePastedText,stripPasteStart,stripPromptControlCharacters,takeUntil,typewriterText}from"./stream-format.js";import{inspectError}from"#internal/logging.js";import{eveVersionTag}from"#cli/banner.js";import{clipVisible,renderInputText,renderInputWithBlockCursor,stripAnsi,stripTerminalControls}from"#cli/ui/terminal-text.js";import{renderCursorRow}from"#setup/cli/option-row.js";import{initialSelectState,reduceSelect,searchActionQuery,selectValueAtCursor}from"#setup/cli/select-state.js";import{toErrorMessage}from"#shared/errors.js";import{StringDecoder}from"node:string_decoder";import{summarizeKnownError}from"#harness/semantic-errors/index.js";import{parseDevRebuildLogLine}from"#internal/nitro/host/dev-watcher-log.js";import{LiveRegion}from"#cli/ui/live-region.js";import{PROGRESS_PULSE_ASCII_GLYPH,PROGRESS_PULSE_GLYPH,isProgressPulseVisible}from"#cli/ui/progress-pulse.js";import{readGatewayServiceTier}from"#shared/gateway-service-tier.js";function isMultiSelectRequest(e){return e.kind===`multi`||e.kind===`searchable-multi`}function moveActionCursor(e,t,n){return n===0?void 0:e===void 0?t===`down`?0:n-1:(e+(t===`down`?1:-1)+n)%n}function completedTurnStatus(e,t){return e?`Interrupted`:t?`Ready`:`Done`}const STATUS={processing:`Working…`,connectionAuth:`Waiting for connection authorization…`};var TerminalRenderer=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p=[];#m=new Map;#h=new Set;#g=[];#_=new Set;#v=new Map;#y=0;#b=new Map;#x=new FileContentCache;#S=new Set;#C;#w=!1;#T;#E=[];#D;#O=0;#k;#A;#j=``;#M=0;#N=new PromptHistory;#P=!1;#F;#I=!1;#L=Date.now();#R=!1;#z=new TurnClock;#B=EMPTY_LINE;#V=!1;#H={kind:`idle`};#U;#W=STATUS.processing;#G;#K=`eve`;#q=!1;#J=!1;#Y=!1;#X=!1;#Z=!0;#Q=0;#$=Date.now();#ee;#te;#ne;#re=!1;#ie;#ae=``;#oe=new StringDecoder(`utf8`);#se;#ce;#le;#ue=!1;#de=!1;#fe;#pe;#me;#he;#ge;#_e;#ve;#ye=``;#be=``;#xe;#Se;#Ce=0;#we;#Te;#Ee;#De;#Oe;#ke;#Ae;#je;setupFlow={begin:(e,t)=>this.#Le(e,t),end:e=>this.#Re(e?.preserveDiagnostics??!0),readSelect:e=>this.#ze(e),readEditableSelect:e=>this.#Ve(e),readProviderPicker:e=>this.#He(e),readModelEditor:e=>this.#Ue(e),readText:e=>this.#We(e),readAcknowledge:e=>this.#Ge(e),readChoice:e=>this.#Be(e),setStatus:e=>this.#$e(e),renderLine:(e,t)=>this.#et(e,t),renderOutput:e=>this.#tt(e),waitForInterrupt:()=>this.#Xe()};constructor(t){this.#e=t?.input??process.stdin,this.#t=t?.output??process.stdout,this.#n=new LiveRegion(this.#t),this.#r=createTheme({color:t?.color??!0,unicode:t?.unicode??detectUnicode()}),this.#i=t?.tools??`auto-collapsed`,this.#a=t?.reasoning??`auto-collapsed`,this.#o=t?.subagents??`auto-collapsed`,this.#s=t?.connectionAuth??`full`,this.#c=t?.assistantResponseStats??`tokensPerSecond`,this.#me=t?.contextSize,this.#l=t?.captureForeignOutput??this.#t===process.stdout,this.#u=t?.diagnostics,this.#f=t?.logs??`none`,this.#d=t?.availablePromptCommands??PROMPT_COMMANDS}renderAgentHeader(e){this.#K=e.name,this.#C=e,this.#nt();let t=this.#Ut().join(`
2
+ `);if(this.#w){t!==this.#T&&(this.#T=t,this.#_t({kind:`agent-header`,body:t,live:!1})),this.#Rt();return}this.#w=!0,this.#T=t,this.#n.flush(this.#Ut(),[])}async readPrompt(e){this.#nt(e),this.#gt(),this.#yt(),this.#P=!0,this.#I=!0,this.#H={kind:`idle`},this.#W=``;let r=lineOf(stripPromptControlCharacters(e?.initialDraft??this.#B.text));return this.#B=EMPTY_LINE,this.#N.begin(r.text),this.#Me(r),this.#F=typeaheadFor(this.#d,r.text),this.#dt(),this.#Rt(),await new Promise((e,i)=>{this.#U=i;let apply=e=>{r=e,this.#pt(),this.#Me(r),this.#F=typeaheadFor(this.#d,e.text,this.#F),this.#Rt()},recall=e=>{e!==void 0&&apply(lineOf(e))},interrupt=()=>{this.#F=void 0,this.#ft(),this.#rt(),i(interruptedError())},suggestions=()=>this.#F!==void 0&&isTypeaheadOpen(this.#F)?this.#F:void 0,highlighted=()=>{let e=suggestions();return e===void 0?void 0:selectedTypeaheadCommand(e)};this.#ie=i=>{let a=applyLineEditorKey(r,i,{multiline:!0});if(a!==void 0){apply(a);return}switch(i.type){case`up`:case`ctrl-p`:{let e=suggestions();if(e!==void 0){this.#F=moveTypeaheadSelection(e,-1),this.#Rt();break}let t=movePromptLine(r,`up`);t===void 0?recall(this.#N.previous(r.text)):apply(t);break}case`down`:case`ctrl-n`:{let e=suggestions();if(e!==void 0){this.#F=moveTypeaheadSelection(e,1),this.#Rt();break}let t=movePromptLine(r,`down`);t===void 0?recall(this.#N.next()):apply(t);break}case`tab`:{let e=highlighted();e!==void 0&&apply(lineOf(typeaheadCompletion(e)));break}case`escape`:{let e=suggestions();e!==void 0&&(this.#F=dismissTypeahead(e),this.#Rt());break}case`enter`:{let i=highlighted(),a=i!==void 0&&parsePromptCommand(r.text)===null?typeaheadCompletion(i).trimEnd():r.text;if(a.trim().length===0)break;this.#F=void 0,this.#N.add(a),this.#P=!1,this.#ft(),this.#W=STATUS.processing,isPromptControlCommand(a)?this.#_t({kind:`command`,body:stripTerminalControls(a.trim()),live:!1}):(this.#ht(),this.#vt(a),this.#we=a,this.#z.arm()),this.#Me(EMPTY_LINE),this.#Rt(),this.#at(),e(a);break}case`ctrl-d`:r.text.length===0?interrupt():apply(deleteForward(r));break;case`ctrl-l`:this.#Vt();break;case`ctrl-r`:this.#Rt();break;case`ctrl-c`:r.text.length===0?interrupt():apply(EMPTY_LINE);break;default:break}},this.#it()})}#Me(e){this.#j=e.text,this.#M=e.cursor}async renderStream(e,t){this.#nt(t),this.#h.clear(),this.#P=!1,this.#H.kind!==`waiting`&&(this.#H={kind:`waiting`,startedAtMs:Date.now()}),this.#W=this.#O>0?STATUS.connectionAuth:STATUS.processing,this.#bt(t?.submittedPrompt),t?.submittedPrompt!==void 0&&this.#u?.recordPrompt(),t?.submittedPrompt!==void 0&&!this.#z.armed&&this.#z.arm(),this.#X=!1,this.#fe=void 0,this.#pe=void 0,this.#he=void 0,this.#ge=void 0,this.#_e=Date.now();let n={tools:t?.tools??this.#i,reasoning:t?.reasoning??this.#a,assistantResponseStats:t?.assistantResponseStats??this.#c};this.#mt(),this.#V=!0,this.#Rt();let r=new Promise(e=>{this.#le=e});this.#ie=e=>this.#ut(e),this.#it();let i={text:new Map,reasoning:new Map,tools:new Map};try{for await(let t of takeUntil(iterateTUIStream(e.events),r)){if(this.#X)break;this.#Et(t,n,i)}}catch(e){let t=summarizeKnownError(e);t===null?this.#xt(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#xt(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#le=void 0,this.#X&&e.abort?.(),this.#at(),this.#gt(),this.#V=!1,this.#H.kind===`waiting`&&(this.#H={kind:`idle`}),this.#W=completedTurnStatus(this.#X,t?.continueSession===!0),this.#Nt(i),this.#X&&this.#Mt(),this.#Tt(),this.#u?.reportStats(),this.#Rt(),t?.continueSession||this.#rt()}}async readToolApproval(e,t){return this.#nt(t),this.#gt(),this.#P=!1,this.#H={kind:`idle`},this.#W=`Approve ${formatToolApprovalTitle(e)}? (y/n)`,this.#X=!1,this.#Rt(),await new Promise((t,n)=>{this.#U=n,this.#ie=r=>{switch(r.type){case`text`:{if(r.framing!==`unframed`)break;let n=r.value.toLowerCase();n===`y`?(this.#ht(),this.#W=STATUS.processing,this.#at(),this.#Rt(),t({approved:!0})):n===`n`&&(this.#ht(),this.#W=STATUS.processing,this.#Pe(e.toolCallId),this.#at(),this.#Rt(),t({approved:!1,reason:`Denied by user.`}));break}case`ctrl-r`:this.#Rt();break;case`ctrl-c`:this.#X=!0,this.#rt(),n(interruptedError());break;default:break}},this.#it()})}async readInputQuestion(e,t){this.#nt(t),this.#gt(),this.#P=!1,this.#I=!1,this.#H={kind:`idle`},this.#X=!1;let n=e.options??[],r=n.length>0,i=(e.allowFreeform===!0||!r)&&r,a=n.length+ +!!i,o=questionSectionId(e.requestId),s=r?`overlay`:`text`,c=0,l=EMPTY_LINE,isOnFreeformRow=()=>i&&c===n.length,overlayPanel=t=>renderQuestionPanel({prompt:stripTerminalControls(e.prompt),options:n,cursor:c,allowFreeform:i,editor:l,caretVisible:this.#Z},this.#r,t),renderTextSection=()=>{this.#Ct({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:formatQuestionContent(e,void 0,this.#r),preformatted:!0,live:!0})},syncFreeformCaret=()=>{isOnFreeformRow()?this.#dt():(this.#ft(),this.#pt())};s===`overlay`?(s=`overlay`,this.#P=!1,this.#wt(o),this.#Te=overlayPanel,this.#W=``,syncFreeformCaret(),this.#Rt()):(s=`text`,this.#Te=void 0,renderTextSection(),this.#P=!0,this.#Me(l),this.#W=``,this.#dt(),this.#Rt());let finalize=t=>{this.#Te=void 0,this.#Ct({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#r.colors.dim(this.#r.glyph.elbow)} ${stripTerminalControls(t.label)}`,preformatted:!0,live:!1}),this.#P=!1,this.#ht(),this.#W=STATUS.processing,this.#ft(),this.#at(),this.#Rt();let n={};return t.optionId!==void 0&&(n.optionId=t.optionId),t.text!==void 0&&(n.text=t.text),n},dismiss=()=>{this.#Te=void 0,this.#Ct({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#r.colors.dim(this.#r.glyph.elbow)} ${this.#r.colors.dim(`Dismissed.`)}`,preformatted:!0,live:!1}),this.#P=!1,this.#W=``,this.#ft(),this.#at(),this.#Rt(),u(void 0)},moveCursor=e=>{a!==0&&(c=(c+e+a)%a,syncFreeformCaret(),this.#Rt())},selectOptionAt=e=>{let t=n[e];t&&u(finalize({optionId:t.id,label:t.label}))},u;return await new Promise((t,r)=>{this.#U=r,u=t,this.#ie=t=>{if(t.type===`ctrl-c`){if((s===`text`||isOnFreeformRow())&&l.text.length>0){l=EMPTY_LINE,this.#pt(),s===`text`&&this.#Me(l),this.#Rt();return}this.#X=!0,this.#Te=void 0,this.#ft(),this.#rt(),r(interruptedError());return}if(t.type===`ctrl-r`){this.#Rt();return}if(s===`overlay`){switch(t.type){case`up`:case`ctrl-p`:moveCursor(-1);break;case`down`:case`ctrl-n`:moveCursor(1);break;case`enter`:if(isOnFreeformRow()){let t=resolveQuestionText(l.text,e);t!==void 0&&u(finalize(t));break}selectOptionAt(c);break;case`escape`:if(isOnFreeformRow()&&l.text.length>0){l=EMPTY_LINE,this.#pt(),this.#Rt();break}dismiss();break;default:if(isOnFreeformRow()){let e=applyLineEditorKey(l,t);e!==void 0&&(l=e,this.#pt(),this.#Rt());break}if(t.type===`text`&&/^[1-9]$/u.test(t.value)){let e=Number(t.value)-1;e<n.length?selectOptionAt(e):e===n.length&&i&&(c=e,syncFreeformCaret(),this.#Rt())}break}return}let a=applyLineEditorKey(l,t,{multiline:!0});if(a!==void 0){l=a,this.#pt(),this.#Me(l),this.#Rt();return}switch(t.type){case`up`:case`down`:{let e=movePromptLine(l,t.type);e!==void 0&&(l=e,this.#pt(),this.#Me(l),this.#Rt());break}case`enter`:{let t=resolveQuestionText(l.text,e);if(t===void 0)break;u(finalize(t));break}case`escape`:if(l.text.length>0){l=EMPTY_LINE,this.#pt(),this.#Me(l),this.#Rt();break}dismiss();break;default:break}},this.#it()})}upsertSubagentStep(e){if(this.#u?.recordSubagentDispatch(e.callId),this.#o===`hidden`)return;let t=stripTerminalControls(e.reasoning??``).trim(),n=stripTerminalControls(e.message??``).trim();if(!(t.length===0&&n.length===0)){if(this.#St(e.callId,e.subagentName),this.#o===`collapsed`){this.#Rt();return}this.#Ct({id:subagentStepSectionId(e.callId,e.sectionKey),kind:`subagent-step`,subagentCallId:e.callId,depth:1,reasoning:t,body:n,collapsed:this.#o!==`full`,live:!e.finalized}),this.#Rt()}}upsertSubagentTool(e){if(this.#u?.recordSubagentDispatch(e.callId),e.status===`failed`&&e.errorText!==void 0&&this.#u?.append({source:`tool`,summary:`${e.toolName} failed (subagent ${e.subagentName})`,detail:e.errorText}),this.#o===`hidden`)return;if(this.#St(e.callId,e.subagentName),this.#o===`collapsed`){this.#Rt();return}let t=subagentToolStatus(e.status),n=e.status===`preparing`?presentPreparingTool(e.toolName):presentTool(e.toolName,e.input,this.#At({input:e.input,output:e.output,toolCallId:e.childCallId,toolName:e.toolName})),r={id:subagentToolSectionId(e.callId,e.childCallId),kind:`subagent-tool`,subagentCallId:e.callId,depth:1,title:stripTerminalControls(n.title),subtitle:stripTerminalControls(n.subtitle),status:t,live:t===`running`||t===`approval`,expanded:this.#o===`full`,toolName:e.toolName,toolGroup:n.group,toolInput:e.input};n.doneTitle!==void 0&&(r.doneTitle=stripTerminalControls(n.doneTitle)),n.detail!==void 0&&(r.detailLines=n.detail,r.keepDetailWhenDone=n.keepDetailWhenDone===!0),e.output===void 0?e.errorText!==void 0&&(r.result=stripTerminalControls(e.errorText)):(r.result=n.summarizeResult(e.output),r.toolOutput=e.output),this.#Ct(r),this.#Ne(e.callId),this.#Rt()}#Ne(e){applyCohortLiveness(this.#p.filter(t=>t.kind===`subagent-tool`&&t.subagentCallId===e).map(e=>({block:e,active:isActiveToolStatus(e.status)})))}removeSubagentTool(e){this.#wt(subagentToolSectionId(e.callId,e.childCallId)),this.#Rt()}subagents={begin:e=>this.beginSubagent(e),upsertStep:e=>this.upsertSubagentStep(e),upsertTool:e=>this.upsertSubagentTool(e),removeTool:e=>this.removeSubagentTool(e),complete:e=>this.completeSubagent(e),markChildToolCallId:e=>this.markChildToolCallId(e)};beginSubagent(e){if(this.#o===`hidden`)return;this.#St(e.callId,e.name);let t=this.#m.get(subagentHeaderId(e.callId));t?.status===`done`&&delete t.status,this.#Rt()}completeSubagent(e){let t=this.#m.get(subagentHeaderId(e.callId));t!==void 0&&(t.status=`done`,this.#Rt())}markChildToolCallId(e){this.#_.add(e);let t=this.#v.get(e);t!==void 0&&(this.#wt(t),this.#v.delete(e),this.#Rt())}#Pe(e){let t=this.#m.get(toolSectionId(e));t!==void 0&&(t.status=`denied`,t.live=!1)}upsertConnectionAuth(e){if(this.#s===`hidden`)return;let t=connectionAuthTerminalMessage(e.state);this.#Ct({id:connectionAuthSectionId(e.name),kind:`connection-auth`,title:`${stripTerminalControls(e.name)} · authorization · ${e.state}`,body:formatConnectionAuthContent(e,t),preformatted:!0,live:t===void 0}),this.#Rt()}setConnectionAuthPendingCount(e){let t=Math.max(0,e);if(t===this.#O)return;let n=this.#O>0;this.#O=t,t>0?(this.#W=STATUS.connectionAuth,this.#Rt()):n&&(this.#W=STATUS.processing,this.#Rt())}setVercelStatus(e){this.#k=e,this.#Rt()}setRemoteConnectionStatus(e){this.#A=e,this.#Rt()}reset(){this.#p=[],this.#m.clear(),this.#h.clear(),this.#D=void 0,this.#E.length=0,this.#g.length=0,this.#w=!1,this.#T=void 0,this.#Fe(),this.#R=!1,this.#we=void 0,this.#Se=void 0,this.#O=0,this.#fe=void 0,this.#pe=void 0,this.#he=void 0,this.#ge=void 0,this.#_e=void 0,this.#q&&(this.#n.clearAll(),this.#Rt())}renderSessionBoundary(){this.#yt(),this.#Fe();let e=this.#r.colors,t=this.#r.glyph,n=e.dim(`${t.cornerOpen}${t.dash.repeat(2)} Session restarted, clear context.`);this.#_t({kind:`session-boundary`,body:n,live:!1}),this.#Rt()}#Fe(){this.#_.clear(),this.#v.clear(),this.#S.clear(),this.#b.clear(),this.#Oe=void 0,this.#ke=void 0,this.#x.clear(),this.#z.reset()}renderNotice(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#nt(),this.#_t({kind:`notice`,body:t,live:!1}),this.#Rt())}renderSandboxLog(e){let t=parseSandboxLogLine(stripTerminalControls(e));t!==void 0&&(this.#u?.append({source:`sandbox`,detail:t}),this.#nt(),this.#_t({kind:`sandbox`,body:t,live:!1}),this.#Rt())}renderSetupWarning(e){let t=stripTerminalControls(e);if(t.trim().length===0){this.#Ie();return}this.#nt(),this.#De=t,this.#Rt()}clearSetupWarning(){this.#Ie()}#Ie(){this.#De!==void 0&&(this.#De=void 0,this.#Rt())}renderCommandInvocation(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;this.#nt();let r={kind:`command`,body:n,live:!1};t===`failed`&&(r.status=`error`),this.#_t(r),this.#Rt()}renderCommandResult(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#nt(),this.#_t({kind:`result`,body:t,live:!1}),this.#Rt())}#Le(e,t=`spinner`){this.#nt(),this.#P=!1,this.#H={kind:`idle`},this.#W=``;let n=t===`pulse`?{kind:`pulse`,startedAtMs:Date.now()}:{kind:`spinner`};this.#Ee={title:stripTerminalControls(e),indicator:n,lines:[],outputBuffer:[]},this.#mt(),this.#Rt()}#Re(e){this.#Ae=void 0,this.#Qe();let t=this.#Ee;if(t!==void 0){if(this.#Ee=void 0,this.#gt(),e){let e=[];for(let n of t.lines){if(n.evidence===!0){e.push(n.text);continue}(n.tone===`warning`||n.tone===`error`)&&(e.length>0&&this.#_t({kind:`flow`,title:`info`,body:e.join(`
3
+ `),live:!1}),this.#_t({kind:`flow`,title:n.tone,body:n.text,live:!1})),e=[]}}this.#Rt()}}async#ze(e){let t=this.#Ke(),n=isMultiSelectRequest(e),r=e.kind===`search`?e.searchAction:void 0,i=e.options,a={options:i,searchAction:r,submitRow:n};`initialValue`in e&&e.initialValue!==void 0&&(a.defaultValue=e.initialValue),`initialValues`in e&&e.initialValues!==void 0&&(a.initialValues=e.initialValues);let o=initialSelectState(a),s,c=!1,l=0,isCurrentSearch=e=>e===l,clearSearch=()=>{l+=1,c=!1,o=reduceSelect(o,{type:`clear`},{options:i,searchAction:r,submitRow:n}),this.#Rt()},loadSearch=async(e,t)=>{c=!0,s=void 0;let a=++l;this.#Rt();try{let s=await t(e);if(!isCurrentSearch(a))return;let c=o.filter;i=s,o={...initialSelectState({options:s,searchAction:r,submitRow:n}),filter:c}}catch(e){isCurrentSearch(a)&&(s=toErrorMessage(e))}finally{isCurrentSearch(a)&&(c=!1,this.#Rt())}},u=e.notices;if(e.kind===`task-list`||e.kind===`search`&&e.layout===`task-list`){let n=t.taskListLineStart??t.lines.length,r=t.lines.slice(n).filter(e=>e.tone===`success`||e.tone===`warning`||e.tone===`error`).map(e=>({tone:e.tone,text:e.text}));u=[...e.notices??[],...r],t.taskListLineStart=t.lines.length,t.hideLinesWhileQuestion=!0}let panelState=()=>{let t={...e,options:i,select:o};return u!==void 0&&u.length>0&&(t.notices=u),s!==void 0&&(t.error=s),c&&(t.loadingFrame=this.#Gt()),t};return t.question=e=>renderSelectQuestion(panelState(),this.#r,e),this.#Rt(),await this.#Ye((t,a)=>{let close=e=>{l+=1,a(e)};if(c){t.type===`ctrl-c`?close(void 0):t.type===`escape`?clearSearch():t.type===`ctrl-r`&&this.#Rt();return}let u={key:t,options:i,searchAction:r,select:o},d=reduceSetupSelectInput(n?{...u,kind:e.kind,required:e.required}:{...u,kind:e.kind});switch(d.kind){case`cancel`:close(void 0);return;case`repaint`:this.#Rt();return;case`update`:o=d.select,s=void 0,this.#Rt();return;case`submit`:{let e=searchActionQuery(d.values[0]??``),t=r?.load;if(e===void 0||t===void 0){close(d.values);return}loadSearch(e,t);return}case`error`:s=d.message,this.#Rt();return;case`ignore`:return}}).promise}#Be(e){this.#nt();let t=this.#qe();t.status={kind:`progress`,text:stripTerminalControls(e.status)};let n;t.question=t=>renderSelectQuestion({kind:`actions`,context:e.context,actions:e.actions,cursor:n},this.#r,t),this.#Rt();let r=this.#Ye((t,r)=>{let i=setupSelectionIntent(t);switch(i?.kind){case`cancel`:r(void 0);return;case`move`:n=moveActionCursor(n,i.direction,e.actions.length),this.#Rt();return;case`repaint`:this.#Rt();return;case`submit`:n!==void 0&&r(e.actions[n].value);return;case void 0:return}},()=>{t.status=void 0});return{choice:r.promise,close:()=>r.settle(void 0)}}async#Ve(e){let t=this.#Ke(),n={options:e.options};e.initialValue!==void 0&&(n.defaultValue=e.initialValue);let r=initialSelectState(n),i=lineOf(``),a;t.question=t=>{let n={kind:`inline-edit`,layout:`task-list`,message:e.message,options:e.options,select:r,edit:{optionValue:e.editable.value,caretVisible:this.#Z,editor:{kind:`rename`,editor:i,defaultValue:e.editable.defaultValue,formatHint:e.editable.formatHint}}};return a!==void 0&&(n.error=a),renderSelectQuestion(n,this.#r,t)};let onEditableRow=()=>selectValueAtCursor([...e.options],r.cursor)===e.editable.value,syncEditableRow=()=>{onEditableRow()?this.#dt():(i=lineOf(``),this.#ft())};return syncEditableRow(),this.#Rt(),await this.#Ye((t,n)=>{let applyEditor=e=>{i=e,a=void 0,this.#pt(),this.#Rt()},applySelect=t=>{r=reduceSelect(r,t,{options:e.options}),a=void 0,syncEditableRow(),this.#Rt()},submit=()=>{let t=selectValueAtCursor([...e.options],r.cursor);if(t===void 0)return;if(t!==e.editable.value){n({kind:`selected`,value:t});return}let o=(i.text||e.editable.defaultValue).trim(),s=e.editable.validate?.(o);if(s!==void 0){a=s,this.#Rt();return}n(o===e.editable.defaultValue?{kind:`selected`,value:t}:{kind:`edited`,value:t,text:o})},o=setupSelectionIntent(t);switch(o?.kind){case`cancel`:n(void 0);return;case`move`:applySelect({type:o.direction});return;case`submit`:submit();return;case`repaint`:this.#Rt();return;case void 0:break}if(!onEditableRow())return;let s=applyLineEditorKey(i,t);s!==void 0&&applyEditor(s)},()=>this.#ft()).promise}async#He(e){let t=this.#Ke(),n=initialProviderPickerState(e.options,e.initialValue),r,cursorBadge=()=>{if(n.phase.kind!==`inactive`)return;let t=selectValueAtCursor([...e.options],n.select.cursor),r=e.options.find(e=>e.value===t);if(r!==void 0)return enterBadge(this.#r,r.checked===!0?`change`:void 0)};t.question=t=>{let r=cursorBadge(),i={kind:`inline-edit`,layout:`stacked`,message:e.message,options:e.options,select:n.select,edit:{optionValue:`own-key`,caretVisible:this.#Z,editor:{kind:`key`,phase:n.phase}}};return r!==void 0&&(i.cursorBadge=r),renderSelectQuestion(i,this.#r,t)};let syncCaret=()=>{n.phase.kind===`editing`||n.phase.kind===`invalid`?this.#dt():this.#ft()};return syncCaret(),this.#Rt(),await this.#Ye((t,i,a)=>{let dispatch=t=>{let o=transitionProviderPicker(n,t,e.options);switch(o.kind){case`ignore`:return;case`clear`:r?.abort(),r=void 0,n=o.state,syncCaret(),this.#Rt();return;case`cancel`:i(void 0);return;case`render`:n=o.state,syncCaret(),this.#Rt();return;case`validate`:{n=o.state,syncCaret(),this.#Rt();let t=new AbortController;r=t;let i;try{i=e.validateInlineKey(o.key,t.signal)}catch(e){a(e);return}i.then(e=>{r!==t||t.signal.aborted||(r=void 0,dispatch({type:`validated`,validation:e}))},e=>{r!==t||t.signal.aborted||(r=void 0,a(e))});return}case`settle`:i(o.result);return}},o=setupSelectionIntent(t);switch(o?.kind){case`cancel`:dispatch({type:`cancel`});return;case`move`:dispatch({type:`move`,direction:o.direction});return;case`submit`:dispatch({type:`submit`});return;case`repaint`:this.#Rt();return;case void 0:break}if(n.phase.kind!==`editing`&&n.phase.kind!==`invalid`)return;let s=applyLineEditorKey(n.phase.editor,t);s!==void 0&&(this.#pt(),dispatch({type:`edit`,editor:s}))},()=>{r?.abort(),r=void 0,this.#ft()}).promise}async#Ue(e){let t=this.#Ke(),n=initialModelEditorState(e);return t.question=t=>renderModelEditorQuestion({request:e,state:n},this.#r,t),this.#Rt(),await this.#Ye((t,r)=>{let dispatch=t=>{let i=transitionModelEditor(n,t,e);switch(i.kind){case`ignore`:return;case`render`:n=i.state,this.#Rt();return;case`cancel`:r(void 0);return;case`settle`:r(i.result);return}},i=setupSelectionIntent(t);switch(i?.kind){case`cancel`:dispatch({type:`cancel`});return;case`move`:dispatch({type:`move`,direction:i.direction});return;case`submit`:dispatch({type:`submit`});return;case`repaint`:this.#Rt();return;case void 0:break}if(t.type===`left`||t.type===`right`){dispatch({type:`adjust`,direction:t.type});return}if(t.type===`tab`){dispatch({type:`adjust`,direction:`right`});return}if(t.type===`backspace`){dispatch({type:`backspace`});return}if(t.type===`text`)for(let e of t.value.replaceAll(`
4
+ `,` `))e>=` `&&e!==``&&dispatch({type:`char`,char:e})}).promise}async#We(e){let t=this.#Ke(),n=lineOf(``),r;return t.question=t=>{let i={message:e.message,editor:n,mask:e.mask===!0};return e.placeholder!==void 0&&(i.placeholder=e.placeholder),e.notices!==void 0&&(i.notices=e.notices),r!==void 0&&(i.error=r),renderTextQuestion(i,this.#r,t,this.#Z)},this.#dt(),this.#Rt(),await this.#Ye((t,i)=>{let apply=e=>{n=e,r=void 0,this.#pt(),this.#Rt()},a=applyLineEditorKey(n,t);if(a!==void 0){apply(a);return}switch(t.type){case`ctrl-c`:case`escape`:i(void 0);return;case`ctrl-r`:this.#Rt();return;case`enter`:{let t=n.text.length>0?n.text:e.defaultValue??``,a=e.validate?.(t);if(a!==void 0){r=a,this.#Rt();return}i(t);return}default:return}},()=>this.#ft()).promise}async#Ge(e){let t=this.#Ke();return t.question=t=>renderAcknowledgeQuestion({message:e.message,lines:e.lines},this.#r,t),this.#Rt(),await this.#Ye((e,t)=>{switch(e.type){case`enter`:case`escape`:case`ctrl-c`:t();return;case`ctrl-r`:this.#Rt();return;default:return}}).promise}#Ke(){return this.#nt(),this.#P=!1,this.#H={kind:`idle`},this.#W=``,this.#qe()}#qe(){return this.#Ee===void 0&&(this.#Ee={title:``,indicator:{kind:`spinner`},lines:[],outputBuffer:[],implicit:!0}),this.#Ee}#Je(){this.#Ee?.implicit===!0?this.#Ee=void 0:this.#Ee!==void 0&&(this.#Ee.question=void 0,this.#Ee.hideLinesWhileQuestion=!1),this.#ie=void 0,this.#at(),this.#Ee!==void 0&&this.#Ze(),this.#Rt()}#Ye(e,t){let n=!1,r,i,a=new Promise((e,t)=>{r=e,i=t}),settle=e=>{n||(n=!0,t?.(),this.#Je(),r(e))},reject=e=>{n||(n=!0,t?.(),this.#Je(),i(e))};return this.#lt(),this.#ie=t=>e(t,settle,reject),this.#it(),{promise:a,settle}}#Xe(){let e,t=new Promise(t=>{e=t});return this.#Ae=e,this.#Ze(),{promise:t,dispose:()=>{this.#Ae===e&&(this.#Ae=void 0,this.#Qe())}}}#Ze(){if(this.#Ae===void 0)return;let consumer=e=>{if(e.type===`ctrl-c`||e.type===`escape`){let e=this.#Ae;this.#Ae=void 0,this.#Qe(),e?.();return}e.type===`ctrl-r`&&this.#Rt()};this.#je=consumer,this.#lt(),this.#ie=consumer,this.#it()}#Qe(){this.#je!==void 0&&(this.#ie===this.#je&&this.#at(),this.#je=void 0)}#$e(e){let t=e===void 0?void 0:typeof e==`string`?{kind:`progress`,text:stripTerminalControls(e)}:{kind:`external-action`,text:stripTerminalControls(e.text),emphasis:stripTerminalControls(e.emphasis)};if(this.#Ee!==void 0){this.#Ee.status=t,t===void 0&&(this.#Ee.preview=void 0),this.#Rt();return}if(!(this.#P||this.#V)){if(t===void 0){this.#H={kind:`idle`},this.#G=void 0,this.#gt(),this.#Rt();return}this.#nt(),this.#ht(),this.#G=t.text,this.#Rt()}}#et(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;let r=this.#Ee;if(r!==void 0){if(r.preview=void 0,t===`warning`||t===`error`)for(let e of r.outputBuffer)r.lines.push({text:e,tone:`info`,evidence:!0});r.outputBuffer=[],r.lines.push({text:n,tone:t}),this.#Rt();return}this.#nt(),this.#_t({kind:`flow`,title:t,body:n,live:!1}),this.#Rt()}#tt(e){let t=stripTerminalControls(e);if(t.trim().length===0)return;let n=this.#Ee;if(n===void 0){this.#et(t,`info`);return}n.preview=t,n.outputBuffer.push(t),n.outputBuffer.length>40&&n.outputBuffer.shift(),this.#Rt()}shutdown(){this.#rt(),this.#J&&!this.#Y&&(this.#Y=!0,this.#t.write(`${this.#r.colors.dim(eveVersionTag())}\n`))}#nt(e){this.#K=e?.title??this.#K,e?.contextSize!==void 0&&(this.#me=e.contextSize),!this.#q&&(this.#q=!0,this.#J=!0,this.#n.reset(),this.#n.hideCursor(),this.#an(),this.#e.isTTY&&(this.#e.setRawMode?.(!0),this.#e.resume(),this.#n.emitBracketedPaste(!0)),this.#ce=()=>this.#Rt(),this.#t.on(`resize`,this.#ce))}#rt(){let e=this.#U;if(this.#U=void 0,e?.(interruptedError()),this.#at(),this.#ft(),this.#gt(),this.#ne!==void 0&&(clearTimeout(this.#ne),this.#ne=void 0),this.#re=!1,this.#q){this.#mn();for(let e of this.#p)e.kind===`log`&&e.id===void 0&&(e.live=!1);this.#Rt(),this.#n.clear(),this.#n.showCursor(),this.#on(),this.#n.newline(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1),this.#e.pause()),this.#ce&&=(this.#t.off(`resize`,this.#ce),void 0),this.#q=!1}}#it(){this.#e.off(`data`,this.#ot),this.#e.on(`data`,this.#ot),this.#ae.length>0&&queueMicrotask(()=>{this.#ie!==void 0&&this.#ae.length>0&&(this.#ct(),this.#st())})}#at(){this.#e.off(`data`,this.#ot),this.#lt(),this.#ie=void 0}#ot=e=>{this.#lt(),this.#ae+=this.#oe.write(e),this.#ct(),this.#st()};#st(){if(this.#ae===`\x1B`){this.#se=setTimeout(()=>{this.#ae===`\x1B`&&(this.#ae=``,this.#ie?.({type:`escape`}))},30),this.#se.unref?.();return}if(isIncompletePaste(this.#ae)){let e=this.#ae;this.#se=setTimeout(()=>{if(this.#ae!==e)return;let t=sanitizePastedText(stripPasteStart(e));this.#ae=``,t.length>0&&this.#ie?.({type:`text`,value:t,framing:`bracketed-paste`})},1e3),this.#se.unref?.()}}#ct(){for(;this.#ae.length>0;){let e=nextKey(this.#ae);if(e.incomplete)return;this.#ae=this.#ae.slice(e.consumed),e.key&&e.key.type!==`ignore`&&this.#ie?.(e.key)}}#lt(){this.#se&&=(clearTimeout(this.#se),void 0)}#ut(e){switch(e.type){case`ctrl-l`:case`ctrl-r`:this.#Rt();break;case`ctrl-c`:this.#X||(this.#X=!0,this.#H={kind:`idle`},this.#W=`Interrupted`,this.#le?.(),this.#Rt());break;case`enter`:break;default:{let t=applyLineEditorKey(this.#B,e,{multiline:!0});t!==void 0&&(this.#B=t,this.#Rt());break}}}#dt(){this.#ft(),this.#pt(),this.#ee=setInterval(()=>{this.#Z=!this.#Z,this.#Rt()},500),this.#ee.unref?.()}#ft(){this.#ee&&=(clearInterval(this.#ee),void 0),this.#Z=!0}#pt(){this.#Z=!0}#mt(){this.#gt(),this.#te=setInterval(()=>{this.#Q+=1,this.#Rt()},90),this.#te.unref?.()}#ht(){let e=Date.now();this.#$=e,this.#H={kind:`waiting`,startedAtMs:e},this.#mt()}#gt(){this.#te&&=(clearInterval(this.#te),void 0)}#_t(e){e.id!==this.#Se?.id&&this.#mn(),e.updateSeq=++this.#y,this.#p.push(e),e.id&&this.#m.set(e.id,e)}#vt(e){this.#R=!0,this.#_t({kind:`user`,body:stripTerminalControls(e),live:!1}),this.#Rt()}#yt(){let e=this.#z.settle();if(e===void 0||e.elapsedMs<=1e4&&e.inputTokens<=2e4)return;let t=`Done in ${this.#Xt(e.elapsedMs)}`,n=this.#pe??0;if(this.#me!==void 0&&this.#me>0&&n>0){let e=Math.round(n/this.#me*100);t+=` ${this.#r.glyph.dot} ${e}% context`}this.#_t({kind:`turn-stats`,body:t,live:!1})}#bt(e){if(e!=null){if(this.#we===e){this.#we=void 0;return}this.#_t({kind:`user`,body:stripTerminalControls(e),live:!1})}}#xt(e,t,n={}){let r=stripTerminalControls(e),i=stripTerminalControls(t),a=n.detail===void 0?void 0:stripTerminalControls(n.detail),o=n.hint===void 0?void 0:stripTerminalControls(n.hint),s={source:`workflow`,summary:`${r}: ${i}`,detail:a??i};this.#u?.append(o===void 0?s:{...s,hint:o});let c={kind:`error`,title:r,body:i,live:!1};o!==void 0&&(c.hint=o),a!==void 0&&(c.detail=this.#u===void 0?a:`details: ${this.#u.displayPath}`),this.#_t(c),this.#Rt()}#St(e,t){if(this.#S.has(e))return;this.#S.add(e);let n=stripTerminalControls(t),r=this.#b.get(n)??[];if(r.push(e),this.#b.set(n,r),r.length===2){let e=this.#m.get(subagentHeaderId(r[0]));e!==void 0&&(e.subtitle=`#1`)}let i={id:subagentHeaderId(e),kind:`subagent`,subagentCallId:e,title:n,live:!0};r.length>1&&(i.subtitle=`#${r.length}`),this.#_t(i)}#Ct(e){if(e.id&&this.#h.has(e.id))return;let t=e.id?this.#m.get(e.id):void 0;if(t){Object.assign(t,e),t.updateSeq=++this.#y;return}this.#_t(e)}#wt(e){this.#p=this.#p.filter(t=>t.id!==e),this.#m.delete(e)}#Tt(){for(let e of this.#p)e.status===`approval`||e.status===`running`||e.kind===`connection-auth`&&e.live||(e.live=!1)}#Et(e,t,n){switch(e.type){case`step-finish`:this.#u?.recordStepUsage(e.usage),e.usage!==void 0&&this.#z.addUsage(e.usage),this.#Nt(n),this.#Lt(e.usage),this.#Rt();break;case`assistant-delta`:{let t=(n.text.get(e.id)??``)+stripTerminalControls(e.delta);n.text.set(e.id,t),this.#Dt(e.id,t,!0);break}case`assistant-complete`:{let t=n.text.get(e.id)??``,r=e.text!==void 0&&t.length===0?stripTerminalControls(e.text??``):t;n.text.set(e.id,r),this.#Dt(e.id,r,!1);break}case`reasoning-delta`:{if(t.reasoning===`hidden`)break;let r=(n.reasoning.get(e.id)??``)+stripTerminalControls(e.delta);if(n.reasoning.set(e.id,r),t.reasoning===`full`){this.#Ot(e.id,r,!0,t);break}break}case`reasoning-complete`:{if(t.reasoning===`hidden`)break;let r=n.reasoning.get(e.id)??``;if(t.reasoning===`full`){this.#Ot(e.id,r,!1,t);break}break}case`tool-call-preparing`:if(t.tools===`hidden`||isPanelRoutedTool(e.toolName))break;this.#kt({input:void 0,preparing:!0,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-call`:if(this.#u?.recordToolCall(e.toolName),t.tools===`hidden`)break;this.#kt({input:e.input,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-approval-request`:{if(t.tools===`hidden`)break;let r=n.tools.get(e.toolCallId);if(r===void 0)break;this.#kt({...r,status:`approval`},t,n);break}case`tool-result`:{if(t.tools===`hidden`)break;let r=this.#It(e.toolCallId,n);if(r===void 0)break;this.#kt({...r,output:e.output,status:`done`},t,n);break}case`tool-error`:{let r=this.#It(e.toolCallId,n);if(this.#u?.append({source:`tool`,summary:`${r?.toolName??e.toolCallId} failed`,detail:e.errorText}),t.tools===`hidden`||r===void 0)break;this.#kt({...r,errorText:e.errorText,status:`error`},t,n);break}case`tool-rejected`:{if(t.tools===`hidden`)break;let r=this.#It(e.toolCallId,n);if(r===void 0)break;this.#kt({...r,errorText:e.reason,status:`denied`},t,n);break}case`error`:this.#xt(`Error`,e.errorText,{detail:e.detail,hint:e.hint});break;case`finish`:this.#Lt(e.usage),this.#Rt();break}}#Dt(e,t,n){let r=stripTerminalControls(t).trim();r.length!==0&&(this.#Ct({id:e,kind:`assistant`,body:r,live:n}),this.#Rt())}#Ot(e,t,n,r){let i=stripTerminalControls(t).trim();i.length!==0&&(this.#Ct({id:e,kind:`reasoning`,body:i,collapsed:collapseReasoning(r.reasoning,n),live:n}),this.#Rt())}#kt(e,t,n){if(n.tools.set(e.toolCallId,e),this.#_.has(e.toolCallId)||this.#Pt(e)||toolBaseName(e.toolName)===`ask_question`)return;let r=toolSectionId(e.toolCallId);this.#v.set(e.toolCallId,r);let i=this.#At(e);this.#Ct(renderNativeToolBlock(e,r,t.tools===`full`,i)),this.#Ft(n),this.#Rt()}#At(e){e.output!==void 0&&this.#x.observeRead(e.output);let t={};this.#jt(e.toolName)&&(t.isSubagent=!0);let n=readWriteFileInput(e.toolName,e.input);if(n===void 0)return t.isSubagent===!0?t:void 0;let r=this.#x.observeWrite({path:n.path,content:n.content,callId:e.toolCallId});r!==void 0&&(t.previousContent=r);let i=writeExistedFlag(e.output);return i!==void 0&&(t.existed=i),t}#jt(e){let t=this.#C?.info?.subagents.local;if(t===void 0||t.length===0)return!1;let n=toolBaseName(e);return t.some(e=>e.name===n)}#Mt(){for(let e of this.#p)e.kind!==`tool`&&e.kind!==`subagent-tool`||e.status===`running`&&(e.status=`error`,e.result=`interrupted`,e.live=!1)}#Nt(e){for(let[t,n]of e.tools){if(n.preparing!==!0)continue;e.tools.delete(t);let r=this.#v.get(t)??toolSectionId(t);this.#wt(r),this.#v.delete(t)}}#Pt(e){let t=readTodoToolItems(e.toolName,e.input);if(t===void 0)return!1;if(t.length>0&&allTodoItemsSettled(t)){let e=JSON.stringify(t);this.#ke!==e&&(this.#ke=e,this.#_t({kind:`todo-list`,body:renderFinishedTodoRows(t,this.#rn(),this.#r).join(`
5
+ `),live:!1})),this.#Oe=void 0}else this.#Oe=t.length>0?t:void 0,this.#ke=void 0;return this.#Rt(),!0}#Ft(e){let t=[];for(let n of e.tools.values()){if(this.#_.has(n.toolCallId))continue;let e=this.#v.get(n.toolCallId)??toolSectionId(n.toolCallId),r=this.#m.get(e);r?.kind===`tool`&&t.push({block:r,active:isActiveToolStatus(n.status)})}applyCohortLiveness(t)}#It(e,t){let n=t.tools.get(e);if(n!==void 0)return n;let r=this.#v.get(e)??toolSectionId(e),i=this.#m.get(r);if(!(i===void 0||i.kind!==`tool`))return{errorText:i.status===`error`&&typeof i.result==`string`?i.result:void 0,input:i.toolInput,output:i.toolOutput,status:i.status??`running`,toolCallId:e,toolName:i.toolName??i.title??`tool`}}#Lt(e){if(e===void 0)return;let{inputTokens:t,outputTokens:n}=e;if((t!=null||n!=null)&&(this.#fe=(t??0)+(n??0)),this.#pe=t??this.#pe,this.#he=n??this.#he,this.#he!=null&&this.#_e!==void 0){let e=(Date.now()-this.#_e)/1e3;e>0&&(this.#ge=this.#he/e)}}#Rt(){if(this.#q){if(this.#ue){this.#de=!0;return}this.#ue=!0;try{do this.#de=!1,this.#zt();while(this.#de)}finally{this.#ue=!1}}}#zt(){if(!this.#q)return;let e=this.#rn(),t=this.#Jt(e),n=Math.max(1,this.#in()-t.length),r=[],i=this.#D,a=groupToolBlocksForDisplay(this.#p),o=0;for(;o<a.length&&a[o].display.live===!1;)o+=1;if(o>0){let e=new Set(a.slice(0,o).flatMap(e=>e.members));for(let t=this.#p.length-1;t>=0;--t)e.has(this.#p[t])&&this.#p.splice(t,1)}for(let t of a.slice(0,o)){for(let e of t.members)this.#g.push(e),e.id&&(this.#h.add(e.id),this.#m.delete(e.id));if(this.#gn(t.display))continue;let n=this.#Wt(t.display,e,i);i=previousBlockOf(t.display),this.#D=i,r.push(...n),this.#E.push(...n)}let s=[];for(let{display:t}of a.slice(o)){if(this.#gn(t))continue;let n=this.#Wt(t,e,i);i=previousBlockOf(t);for(let e=0;e<n.length;e+=1)s.push({block:t,row:n[e]})}let c=[...clipLiveRows(s.map(e=>e.row),n,e,this.#r),...t];r.length>0?this.#n.flush(r,c):this.#n.update(c)}#Bt(){if(!this.#q)return;let e=this.#rn(),t=this.#Jt(e),n=Math.max(1,this.#in()-t.length),r=this.#D,i=[];for(let{display:t}of groupToolBlocksForDisplay(this.#p)){if(this.#gn(t))continue;let n=this.#Wt(t,e,r);r=previousBlockOf(t),i.push(...n)}let a=[...clipLiveRows(i,n,e,this.#r),...t];this.#n.clearAll(),this.#n.flush([...this.#Ut(),...this.#E],a)}logDisplayMode(){return this.#f}setLogDisplayMode(e){e!==this.#f&&(this.#f=e,e===`all`&&this.flushDelayedDevBuildErrors(),this.#Ht(),this.#q&&this.#Bt())}flushDelayedDevBuildErrors(){let e=this.#xe;e!==void 0&&(this.#xe=void 0,this.#_t({kind:`log`,title:`stderr`,body:e,live:!0}),this.#Rt())}#Vt(){this.#re=!0,this.#ne!==void 0&&clearTimeout(this.#ne),this.#ne=setTimeout(()=>{this.#re=!1,this.#ne=void 0,this.#Rt()},5e3),this.setLogDisplayMode(nextLogDisplayMode(this.#f)),this.#Rt()}#Ht(){let e=this.#rn();this.#E.length=0;let t;for(let{display:n}of groupToolBlocksForDisplay(this.#g,{logCoalescing:`runs`})){if(this.#gn(n))continue;let r=this.#Wt(n,e,t);t=previousBlockOf(n),this.#E.push(...r)}this.#D=t}#Ut(){let e=this.#C;if(e===void 0)return[];let t={name:e.name,theme:this.#r,width:this.#rn()};return e.info!==void 0&&(t.info=e.info),e.tip!==void 0&&(t.tip=e.tip),buildAgentHeader(t)}#Wt(e,t,n){let r={activityPulse:this.#Kt(this.#$,this.#r.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH)};n!==void 0&&(r.previous=n);let i=renderBlockLines(e,t,this.#r,r);return(e.depth??0)===0&&leadsWithGap(e,n)?[``,...i]:i}#Gt(){return this.#r.spinner[this.#Q%this.#r.spinner.length]??``}#Kt(e,t){return isProgressPulseVisible(Date.now()-e)?t:` `}#qt(e,t){return e.indicator.kind===`spinner`?{glyph:this.#Gt(),color:`yellow`}:{glyph:this.#Kt(e.indicator.startedAtMs,this.#r.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH),color:t?.kind===`external-action`?`yellow`:`green`}}#Jt(e){let n=this.#r.colors,r=[``];if(this.#Te!==void 0)return r.push(...this.#Te(e),``),this.#en(r,e),r;let a=this.#Ee;if(a!==void 0){let t=this.#qt(a,a.status),n=a.status===void 0?void 0:{...a.status,indicator:t},i;if(a.question!==void 0){let t=a.question(e);i={kind:`question`,rows:t},n!==void 0&&(i={kind:`question`,rows:t,status:n})}else n===void 0?i=a.preview===void 0?{kind:`idle`,indicator:t}:{kind:`preview`,text:a.preview,indicator:t}:(i={kind:`status`,status:n},a.preview!==void 0&&(i={kind:`status`,status:n,preview:a.preview}));let o={title:a.title,lines:a.hideLinesWhileQuestion===!0?[]:a.lines,content:i};return r.push(...renderFlowPanel(o,this.#r,e)),this.#tn(r,e),r}if(this.#Oe!==void 0&&r.push(...renderTodoPanelRows({items:this.#Oe,width:e,theme:this.#r,working:this.#V||this.#H.kind===`waiting`,pulse:this.#Kt(this.#$,this.#r.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH)}),``),this.#De!==void 0&&r.push(...renderAttentionRows(this.#De,e,this.#r),``),this.#P){let i=this.#F===void 0?void 0:inlineCommandHint(this.#F);i===void 0&&this.#F!==void 0&&isTypeaheadOpen(this.#F)&&r.push(...renderCommandSuggestions(this.#F,this.#r,e));let a=isPromptControlCommand(this.#j),o=i?n.dim(` ${i}`):``,l=[];this.#en(l,e);let d=Math.max(1,this.#in()-1-r.length-1-l.length),f={text:this.#j,cursor:this.#M,width:e,theme:this.#r,caretVisible:this.#Z,isCommand:a,ghost:o,maxRows:d};return this.#I&&this.#j.length===0&&(f.placeholder=this.#R?``:promptPlaceholder(Date.now()-this.#L)),r.push(...promptInputRows(f)),r.push(...l),r}let o=this.#H.kind===`waiting`&&this.#G===void 0;if(this.#V||o){r.push(this.#Yt(e)),this.#Qt(r,e);let t=[];return this.#en(t,e),!this.#V&&t.length>0&&r.push(``),r.push(...t),r}if(this.#B.text.length>0)return this.#$t(r,e,{inert:!1}),this.#en(r,e),r;let l=this.#G??(this.#W.length>0?this.#W:`Ready`),d=this.#nn(),f=n.dim(this.#r.glyph.dot),p=d?`${f} ${l} ${n.dim(this.#r.glyph.dot)} ${d}`:`${f} ${l}`;return r.push(clip(p,e)),this.#en(r,e),r}#Yt(e){let t=this.#r.colors,n=this.#Kt(this.#$,this.#r.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH),r=this.#H,i=this.#z.startedAtMs??this.#_e??(r.kind===`waiting`?r.startedAtMs:Date.now()),a=Date.now()-i,o=`${typewriterText(`Working for`,a,80)} ${this.#Xt(a)}`;return clip(`${t.yellow(n)} ${t.dim(o)}`,e)}#Xt(e){return`${formatTurnDuration(e)}${this.#Zt()}`}#Zt(){let{inputTokens:e,outputTokens:t}=this.#z.usage;return e===0&&t===0?``:` ${this.#r.glyph.dash.repeat(2)} ${formatTokenFlow({inputTokens:e,outputTokens:t},this.#r.glyph)}`}#Qt(e,t){this.#V&&this.#$t(e,t,{inert:!0})}#$t(e,t,n){e.push(``);let r={text:this.#B.text,cursor:this.#B.cursor,width:t,theme:this.#r,caretVisible:!0,isCommand:!1,ghost:``,maxRows:4,inert:n.inert};n.inert&&this.#B.text.length===0&&(r.placeholder=``),e.push(...promptInputRows(r))}#en(e,t){let n=this.#A===void 0?``:` `,r=Math.max(1,t-n.length),i={theme:this.#r,width:r};this.#re&&(i.logLevel=this.#f);let a=this.#C?.serverUrl;if(a!==void 0&&this.#A===void 0){let e=new URL(a).port;e.length>0&&(i.serverPort=e)}let o=this.#C?.info?.agent.model;o?.id!==void 0&&(i.model=o.id),o?.reasoning!==void 0&&o.reasoning!==`provider-default`&&(i.reasoning=o.reasoning),readGatewayServiceTier(o?.providerOptions).kind===`priority`&&(i.fastMode=!0);let s=o?.endpoint;s!==void 0&&(i.endpoint=s),this.#k!==void 0&&(i.vercel=this.#k),this.#A!==void 0&&(i.remote=this.#A);let c=buildStatusLine(i);c!==void 0&&e.push(clip(`${n}${c}`,t))}#tn(e,t){if(this.#A===void 0)return;let n=Math.max(1,t-2),r=buildStatusLine({remote:this.#A,theme:this.#r,width:n});r!==void 0&&e.push(``,clip(` ${r}`,t))}#nn(){let e=this.#r.colors,t=[],n=formatAssistantResponseStats({totalTokens:this.#fe,outputTokens:this.#he,tokensPerSecond:this.#ge},this.#c);return n&&t.push(n),t.length>0?e.dim(t.join(` ${this.#r.glyph.dot} `)):``}#rn(){return Math.max(20,this.#t.columns||80)}#in(){return Math.max(8,this.#t.rows||24)}#an(){if(this.#ve!==void 0||!this.#l)return;this.#ye=``,this.#be=``;let capture=(e,t)=>{let n=e.write.bind(e);return e.write=((e,n,r)=>{let i=typeof n==`string`?n:void 0,a=typeof n==`function`?n:r;return this.#cn(t,chunkToString(e,i)),a?.(),!0}),()=>{e.write=n}},e=capture(process.stdout,`stdout`),t=capture(process.stderr,`stderr`);this.#u?.subscribeLogRecords(e=>this.#sn(e)),this.#ve=()=>{this.#u?.unsubscribeLogRecords(),e(),t()}}#on(){let e=this.#ve;e!==void 0&&(this.#ve=void 0,e(),this.#ye.length>0&&(this.#u?.append({source:`stdout`,detail:this.#ye}),this.#hn(`stdout`)&&process.stdout.write(`${this.#ye}\n`),this.#ye=``),this.#be.length>0&&(this.#u?.append({source:`stderr`,detail:this.#be}),this.#hn(`stderr`)&&process.stderr.write(`${this.#be}\n`),this.#be=``))}#sn(e){let t=e.fields===void 0?``:` ${JSON.stringify(e.fields)}`;this.#un(`[eve:${e.namespace}] ${e.message}${t}`),this.#Rt()}#cn(e,t){let n=(e===`stdout`?this.#ye:this.#be)+t,r=n.lastIndexOf(`
6
+ `),i=r===-1?n:n.slice(r+1);if(e===`stdout`?this.#ye=i:this.#be=i,r===-1)return;let a=stripAnsi(n.slice(0,r)).replace(/\s+$/u,``);a.trim().length!==0&&(this.#u?.append({source:e,detail:a}),e===`stdout`?this.#ln(a):this.#un(a),this.#Rt())}#ln(e){let t=[],flushPending=()=>{if(t.length===0)return;let e=t.join(`
7
+ `);t=[],e.trim().length!==0&&this.#_t({kind:`log`,title:`stdout`,body:e,live:!0})};for(let n of e.split(`
8
+ `)){let e=parseSandboxLogLine(n.trimEnd());if(e!==void 0){flushPending(),this.#_t({kind:`sandbox`,body:e,live:!1});continue}let r=parseDevRebuildLogLine(n.trimEnd());if(r===void 0){t.push(n);continue}flushPending(),this.#fn(r,n.trimEnd())}flushPending()}#un(e){let t=e.split(`
9
+ `),n=t.findIndex(e=>parseDevRebuildLogLine(e.trimEnd())?.kind===`failed`);if(n===-1){if(this.#u===void 0){this.#_t({kind:`log`,title:`stderr`,body:e,live:!0});return}let t=presentDiagnostic(e,this.#u.displayPath);if(t.kind===`inline`){this.#_t({kind:`log`,title:`stderr`,body:t.text,live:!0});return}this.#_t({kind:`log`,title:`stderr`,body:formatStoredDiagnostic(t),logVisibility:`stderr-only`,live:!0}),this.#_t({kind:`log`,title:`stderr`,body:e,logVisibility:`all-only`,live:!0});return}let r=t.slice(0,n).join(`
10
+ `);r.trim().length>0&&this.#_t({kind:`log`,title:`stderr`,body:r,live:!0});let i=t.slice(n).join(`
11
+ `);this.#dn(i)}#dn(e){if(this.#f===`all`){if(e.trim().length===0)return;this.#_t({kind:`log`,title:`stderr`,body:e,live:!0});return}this.#xe=e}#fn(e,t){let n=this.#pn();if(e.kind===`failed`){this.#dn(t);return}if(e.kind===`rebuilding`){let t=summarizeChangedFiles(e.events,e.more);if(n!==void 0){n.state.summary=t,n.block.body=formatDevRebuildStatus(t,`rebuilding`);return}let r=`dev-rebuild:${this.#Ce}`;this.#Ce+=1,this.#Se={id:r,summary:t},this.#_t({kind:`log`,id:r,title:`stdout`,body:formatDevRebuildStatus(t,`rebuilding`),live:!0});return}if(n!==void 0){n.block.body=formatDevRebuildStatus(n.state.summary,e.kind),e.kind===`rebuilt`&&(this.#xe=void 0);return}e.kind===`rebuilt`&&(this.#xe=void 0),this.#_t({kind:`log`,title:`stdout`,body:t,live:!0})}#pn(){let e=this.#Se;if(e===void 0)return;let t=this.#m.get(e.id);if(!(t===void 0||t.live!==!0))return{state:e,block:t}}#mn(){let e=this.#Se;if(e===void 0)return;this.#Se=void 0;let t=this.#m.get(e.id);t!==void 0&&(t.live=!1)}#hn(e){switch(this.#f){case`none`:return!1;case`stderr`:return e===`stderr`;case`sandbox`:return e===`sandbox`;case`all`:return!0}}#gn(e){return e.kind===`sandbox`?!this.#hn(`sandbox`):e.kind===`log`?e.logVisibility===`stderr-only`?this.#f!==`stderr`:e.logVisibility===`all-only`?this.#f!==`all`:!this.#hn(e.title===`stderr`?`stderr`:`stdout`):!1}};function chunkToString(e,t){return typeof e==`string`?e:Buffer.from(e).toString(t)}async function*iterateTUIStream(e){if(e instanceof ReadableStream){let t=e.getReader();try{for(;;){let{done:e,value:n}=await t.read();if(e)return;yield n}}finally{t.releaseLock()}return}yield*e}function clip(e,t){return clipVisible(e,t)}function promptInputRows({text:e,cursor:t,width:n,theme:r,caretVisible:i,isCommand:a,ghost:o,maxRows:s,placeholder:c,inert:l}){let u=r.colors;if(e.length===0&&c!==void 0){let e=renderInputWithBlockCursor({...visibleLine({text:c,cursor:0},Math.max(1,n-3),r.glyph.ellipsis),visible:i,inverse:u.inverse,render:e=>u.dim(renderInputText(e))});return[clip(`${u.dim(r.glyph.promptIdle)} ${e}`,n),``]}let style=e=>{let t=renderInputText(e);return a&&t.length>0?u.blue(t):t},d=layoutPromptInput({text:e,cursor:t}),f=Math.min(Math.max(1,s),d.rows.length),p=Math.max(0,Math.min(d.caretRow-f+1,d.rows.length-f)),m=l===!0?u.dim(r.glyph.prompt):u.cyan(r.glyph.prompt),h=u.dim(r.glyph.ellipsis),g=Math.max(1,n-3),_=[];for(let e=p;e<p+f;e+=1){let t=d.rows[e],a=e===0?m:` `;(e===p&&p>0||e===p+f-1&&p+f<d.rows.length)&&(a=h);let s;if(e===d.caretRow){let{before:e,under:n,after:a}=visibleLine({text:t.text,cursor:d.caretOffset},g,r.glyph.ellipsis);s=renderInputWithBlockCursor({before:e,under:n,after:a,visible:i,inverse:u.inverse,render:style}),o.length>0&&d.rows.length===1&&(s+=o)}else s=style(t.text);_.push(clip(`${a} ${s}`,n))}return _.push(``),_}function previousBlockOf(e){let t={kind:e.kind};return e.title!==void 0&&(t.title=e.title),t}function isActiveToolStatus(e){return e===`running`||e===`approval`}function applyCohortLiveness(e){let t=e.some(e=>e.active);for(let n of e)n.block.live=t||n.active}function leadsWithGap(e,t){if(e.kind===`tool`&&(t?.kind===`user`||t?.kind===`assistant`||t?.kind===`question`))return!0;if(e.kind===`sandbox`&&t?.kind===`sandbox`)return!1;if(t?.kind===`sandbox`&&e.kind!==`sandbox`||t?.kind===`log`)return!0;switch(e.kind){case`user`:case`assistant`:case`reasoning`:case`subagent`:case`error`:case`notice`:case`question`:case`connection-auth`:case`sandbox`:case`log`:case`command`:case`warning`:case`flow`:case`turn-stats`:case`session-boundary`:case`todo-list`:case`agent-header`:return!0;default:return!1}}function parseSandboxLogLine(e){let t=e.trim();if(!t.startsWith(`eve: `))return;let n=t.slice(5);return/\bsandbox\b/i.test(n)&&!isLowValueSandboxLogLine(n)?n:void 0}function isLowValueSandboxLogLine(e){return/^initializing (?:\d+ )?sandbox templates?\b/i.test(e)||/^initialized \d+ sandbox\b/i.test(e)||/^reused cached sandbox template\b/i.test(e)||/^sandbox template "[^"]+" \([^)]+\): (checking|reusing|loading microsandbox runtime|microsandbox runtime ready)\b/i.test(e)}function clipLiveRows(e,t,n,r){if(e.length<=t)return[...e];if(t<=1)return[clip(hiddenRowsMarker(e.length,r),n)];let i=t-1;return[clip(hiddenRowsMarker(e.length-i,r),n),...e.slice(e.length-i)]}function hiddenRowsMarker(e,t){let n=e.toLocaleString(),r=e===1?`row`:`rows`;return t.colors.dim(`${t.glyph.dot} ${t.glyph.ellipsis} ${n} earlier ${r} hidden while streaming`)}function collapseReasoning(e,t){switch(e){case`collapsed`:return!0;case`auto-collapsed`:return!t;default:return!1}}function renderNativeToolBlock(e,t,n,r){let i=e.preparing===!0?presentPreparingTool(e.toolName,r):presentTool(e.toolName,e.input,r),a={id:t,kind:`tool`,title:stripTerminalControls(i.title),subtitle:stripTerminalControls(i.subtitle),status:e.status,live:e.status===`running`||e.status===`approval`,expanded:n,toolInput:e.input,toolName:e.toolName,toolGroup:i.group};return i.doneTitle!==void 0&&(a.doneTitle=stripTerminalControls(i.doneTitle)),i.detail!==void 0&&(a.detailLines=i.detail,a.keepDetailWhenDone=i.keepDetailWhenDone===!0),e.output===void 0?e.errorText!==void 0&&(a.result=stripTerminalControls(e.errorText)):(a.result=i.summarizeResult(e.output),a.toolOutput=e.output),a}function writeExistedFlag(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e.existed;return typeof t==`boolean`?t:void 0}function subagentToolStatus(e){switch(e){case`preparing`:return`running`;case`approval-requested`:return`approval`;case`executing`:return`running`;case`done`:return`done`;case`failed`:return`error`;case`rejected`:return`denied`}}function formatToolApprovalTitle(e){return stripTerminalControls(e.title??e.toolName)}function toolSectionId(e){return`tool:${e}`}function questionSectionId(e){return`question:${e}`}function subagentHeaderId(e){return`subagent:${e}:header`}function subagentStepSectionId(e,t){return`subagent:${e}:step:${t}`}function subagentToolSectionId(e,t){return`subagent:${e}:tool:${t}`}function connectionAuthSectionId(e){return`connection-auth:${e}`}function connectionAuthTerminalMessage(e){switch(e){case`authorized`:return`Authorization complete`;case`declined`:return`Authorization declined`;case`failed`:return`Authorization failed`;case`timed-out`:return`Authorization timed out`;case`required`:case`pending`:return}}function formatConnectionAuthContent(e,t){let n=[];if(t!==void 0)n.push(t);else{let t=stripTerminalControls(e.description);t.length>0&&n.push(t);let r=e.challenge;r?.url&&n.push(`URL: ${stripTerminalControls(r.url)}`),r?.userCode&&n.push(`Code: ${stripTerminalControls(r.userCode)}`),r?.expiresAt&&n.push(`Expires: ${stripTerminalControls(r.expiresAt)}`),r?.instructions&&n.push(stripTerminalControls(r.instructions))}if(e.reason!==void 0){let t=stripTerminalControls(e.reason);t.length>0&&n.push(`Reason: ${t}`)}return n.join(`
11
12
  `)}function formatQuestionContent(e,t,n){let r=n.colors,i=[],a=e.options??[];if(a.length>0){for(let[e,o]of a.entries()){let a=stripTerminalControls(o.label),s=o.description===void 0?``:stripTerminalControls(o.description),c=t===e,l=s.length>0?`${c?` `:` `}${r.dim(`— ${s}`)}`:``,u=renderCursorRow(c?`${n.glyph.selectedPointer} ${a}`:` ${a}`,c,r);i.push(`${u}${l}`)}if(e.allowFreeform===!0){let e=t===a.length,o=`Type your own answer`,s=e?`${n.glyph.selectedPointer} ${o}`:` ${r.dim(o)}`;i.push(renderCursorRow(s,e,r))}}else i.push(r.dim(` (type your answer)`));return i.join(`
12
13
  `)}function resolveQuestionText(e,t){let n=e.trim();if(n.length===0)return;let r=n.toLowerCase(),i=t.options??[];if(i.length>0){let e=matchQuestionOption(r,i);if(e!==void 0)return{optionId:e.id,label:e.label}}if(t.allowFreeform===!0||i.length===0)return{text:n,label:n}}function matchQuestionOption(e,t){let n=t.find(t=>t.id.toLowerCase()===e);if(n!==void 0)return n;let r=t.find(t=>t.label.toLowerCase()===e);if(r!==void 0)return r;let i=Number(e);if(Number.isInteger(i)&&i>0&&i<=t.length)return t[i-1]}export{TerminalRenderer};
@@ -34,5 +34,12 @@ export declare class MockScreen extends EventEmitter implements TerminalOutput {
34
34
  resize(columns: number, rows: number): void;
35
35
  snapshot(): string;
36
36
  rawOutput(): string;
37
+ /**
38
+ * Resolves once the runner parks at an idle prompt: a column-0 `›` row
39
+ * with no live turn bar on screen. A streaming turn keeps an identical
40
+ * `›` prompt anchored (Enter inert), so the glyph alone cannot signal
41
+ * readiness — the bar's absence is the discriminator.
42
+ */
43
+ waitForIdlePrompt(timeoutMs?: number): Promise<void>;
37
44
  waitForText(text: string, timeoutMs?: number, getDebugOutput?: () => string): Promise<void>;
38
45
  }
@@ -1,3 +1,3 @@
1
1
  import{EventEmitter}from"node:events";const ansiControlSequencePattern=RegExp(`^\x1B\\[([0-9?;]*)([ -/]*)([@-~])`);var MockUserInput=class extends EventEmitter{isTTY=!0;rawModes=[];resumeCalls=0;pauseCalls=0;setRawMode(e){return this.rawModes.push(e),this}resume(){return this.resumeCalls+=1,this}pause(){return this.pauseCalls+=1,this}type(e){this.emit(`data`,Buffer.from(e))}send(e){this.emit(`data`,Buffer.from(e))}enter(){this.send(`\r`)}backspace(){this.send(``)}up(){this.send(`\x1B[A`)}down(){this.send(`\x1B[B`)}left(){this.send(`\x1B[D`)}right(){this.send(`\x1B[C`)}ctrlC(){this.send(``)}ctrlN(){this.send(``)}ctrlP(){this.send(``)}},MockScreen=class extends EventEmitter{isTTY=!0;columns;rows;#e=``;#t=[];#n=0;#r=0;#i=[];constructor({columns:e,rows:t}){super(),this.columns=e,this.rows=t}write(e,t,n){let r=String(e);return this.#e+=r,this.#o(r),typeof t==`function`&&t(),n?.(),this.#a(),!0}resize(e,t){this.columns=e,this.rows=t,this.emit(`resize`)}snapshot(){return this.#t.join(`
2
- `)}rawOutput(){return this.#e}async waitForText(e,t=1e3,n=()=>this.snapshot()){this.snapshot().includes(e)||await new Promise((r,i)=>{let a={text:e,resolve:r,reject:i,timeout:setTimeout(()=>{this.#i=this.#i.filter(e=>e!==a),i(Error(`Timed out waiting for screen text: ${e}\n\nScreen:\n${n()}`))},t)};this.#i.push(a)})}#a(){let e=this.snapshot();for(let t of this.#i.slice())e.includes(t.text)&&(clearTimeout(t.timeout),this.#i=this.#i.filter(e=>e!==t),t.resolve())}#o(e){let t=0;for(;t<e.length;){if(e[t]===`\x1B`){let n=this.#s(e,t);if(n>t){t=n;continue}}let n=e[t];if(t+=1,n!==void 0){if(n===`
2
+ `)}rawOutput(){return this.#e}async waitForIdlePrompt(e=1e3){let t=Array.from({length:11},(e,t)=>`Working for`.slice(0,t+1)),n=RegExp(`^[▪* ] (?:${t.join(`|`)}) \\d`,`mu`),idle=()=>{let e=this.snapshot();return/^[›❯]/mu.test(e)&&!n.test(e)},r=Date.now()+e;for(;Date.now()<r;){if(idle())return;await new Promise(e=>setTimeout(e,25))}throw Error(`Timed out waiting for an idle prompt.\n\nScreen:\n${this.snapshot()}`)}async waitForText(e,t=1e3,n=()=>this.snapshot()){this.snapshot().includes(e)||await new Promise((r,i)=>{let a={text:e,resolve:r,reject:i,timeout:setTimeout(()=>{this.#i=this.#i.filter(e=>e!==a),i(Error(`Timed out waiting for screen text: ${e}\n\nScreen:\n${n()}`))},t)};this.#i.push(a)})}#a(){let e=this.snapshot();for(let t of this.#i.slice())e.includes(t.text)&&(clearTimeout(t.timeout),this.#i=this.#i.filter(e=>e!==t),t.resolve())}#o(e){let t=0;for(;t<e.length;){if(e[t]===`\x1B`){let n=this.#s(e,t);if(n>t){t=n;continue}}let n=e[t];if(t+=1,n!==void 0){if(n===`
3
3
  `){this.#n+=1,this.#r=0;continue}if(n===`\r`){this.#r=0;continue}this.#u(n)}}}#s(e,n){let r=e.slice(n).match(ansiControlSequencePattern);if(!r)return n;let[i,a=``,,o]=r,s=a.startsWith(`?`),c=a&&!s?a.split(`;`):[],first=e=>c[0]===void 0||c[0]===``?e:Number(c[0]);if(s)return n+i.length;switch(o){case`H`:case`f`:this.#n=first(1)-1,this.#r=(c[1]?Number(c[1]):1)-1;break;case`A`:this.#n=Math.max(0,this.#n-first(1));break;case`B`:this.#n+=first(1);break;case`C`:this.#r+=first(1);break;case`D`:this.#r=Math.max(0,this.#r-first(1));break;case`E`:this.#n+=first(1),this.#r=0;break;case`F`:this.#n=Math.max(0,this.#n-first(1)),this.#r=0;break;case`G`:this.#r=first(1)-1;break;case`J`:this.#c(first(0));break;case`K`:this.#l(first(0));break;default:break}return n+i.length}#c(e){if(e===2||e===3){this.#t=[],this.#n=0,this.#r=0;return}if(e===1){for(let e=0;e<this.#n;e+=1)this.#t[e]=``;this.#l(1);return}this.#l(0),this.#t.length=Math.min(this.#t.length,this.#n+1)}#l(e){let t=this.#t[this.#n]??``;if(e===2){this.#t[this.#n]=``;return}if(e===1){this.#t[this.#n]=` `.repeat(this.#r)+t.slice(this.#r);return}this.#t[this.#n]=t.slice(0,this.#r)}#u(e){let t=(this.#t[this.#n]??``).padEnd(this.#r,` `),n=t.slice(0,this.#r)+e+t.slice(this.#r+e.length);this.#t[this.#n]=n,this.#r+=e.length}};export{MockScreen,MockUserInput};
@@ -38,17 +38,27 @@ export interface ThemeColors {
38
38
  export interface ThemeGlyphs {
39
39
  /** `▲` — the Vercel/eve brand mark; prefixes the agent's own output. */
40
40
  brand: string;
41
- /** `▌` — left gutter bar marking a user message. */
41
+ /** `│` — left gutter bar marking a user message. */
42
42
  user: string;
43
43
  /** `○` — reasoning / "thinking" marker (Next.js "wait" glyph). */
44
44
  reasoning: string;
45
+ /** `▪` — static tool-activity mark (the settled form of the activity pulse). */
46
+ square: string;
47
+ /** `└` — closes a `│`-railed detail region under a tool header. */
48
+ corner: string;
49
+ /** `┌` — opens a region; pairs with `corner` at session boundaries. */
50
+ cornerOpen: string;
51
+ /** `⌝` — marks a provider endpoint authored in the agent's own code. */
52
+ external: string;
53
+ /** `⏺` — the in-progress todo item (pulses while the turn runs). */
54
+ dotActive: string;
45
55
  /** `✓` — a completed tool or success state. */
46
56
  success: string;
47
57
  /** `⨯` — an error or failed tool. */
48
58
  error: string;
49
59
  /** `⚠` — a warning / attention state. */
50
60
  warning: string;
51
- /** `◆` — a subagent region header. */
61
+ /** `※` — a subagent region header. */
52
62
  subagent: string;
53
63
  /** `│` — vertical rule drawn in the gutter to nest subagent output. */
54
64
  rule: string;
@@ -66,10 +76,14 @@ export interface ThemeGlyphs {
66
76
  option: string;
67
77
  /** `❯` — the input prompt mark. */
68
78
  prompt: string;
79
+ /** `›` — the prompt mark's quiet form while the buffer is empty. */
80
+ promptIdle: string;
69
81
  /** `⎿` — hangs a command's result under its invocation. */
70
82
  elbow: string;
71
83
  /** `▔` — strong full-width rule opening the bottom question panel. */
72
84
  hrule: string;
85
+ /** `─` — light rule segment framing the end-of-turn stats line. */
86
+ dash: string;
73
87
  /** `▏` — the synthetic input caret. */
74
88
  caret: string;
75
89
  /** `·` — inline separator for header / status segments. */
@@ -1 +1 @@
1
- function ansi(e,t,n){if(!n)return e=>e;let r=`[${e}m`,i=`[${t}m`;return e=>`${r}${e}${i}`}function ansi256(e,t){if(!t)return e=>e;let n=`[38;5;${e}m`;return e=>`${n}${e}`}const UNICODE_GLYPHS={brand:`▲`,user:`▌`,reasoning:`○`,success:`✓`,error:`⨯`,warning:`⚠`,subagent:`◆`,rule:`│`,question:`?`,connection:`●`,arrow:`→`,pointer:`▷`,selectedPointer:`▶`,option:`◦`,prompt:`❯`,elbow:`⎿`,hrule:`▔`,caret:`▏`,dot:`·`,ellipsis:`…`,arrowUp:`↑`,arrowDown:`↓`,fast:`↯`,trackFilled:`●`,trackCurrent:`◉`,trackEmpty:`○`,trackLine:`─`,enter:`↵`,validating:`▪`},ASCII_GLYPHS={brand:`>`,user:`|`,reasoning:`o`,success:`+`,error:`x`,warning:`!`,subagent:`*`,rule:`|`,question:`?`,connection:`*`,arrow:`->`,pointer:`>`,selectedPointer:`>`,option:`.`,prompt:`>`,elbow:"`-",hrule:`=`,caret:`_`,dot:`-`,ellipsis:`...`,arrowUp:`^`,arrowDown:`v`,fast:`>>`,trackFilled:`*`,trackCurrent:`O`,trackEmpty:`.`,trackLine:`-`,enter:`<-'`,validating:`o`},UNICODE_SPINNER=[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`],ASCII_SPINNER=[`-`,`\\`,`|`,`/`];function createTheme(i={}){let a=i.color??!0,o=i.unicode??!0;return{color:a,unicode:o,colors:{reset:ansi(0,0,a),bold:ansi(1,22,a),dim:ansi(2,22,a),inverse:ansi(7,27,a),italic:ansi(3,23,a),white:ansi(97,39,a),gray:ansi(90,39,a),cyan:ansi(36,39,a),green:ansi(32,39,a),red:ansi(31,39,a),yellow:ansi(33,39,a),magenta:ansi(35,39,a),blue:ansi(34,39,a),orange:ansi256(208,a)},glyph:o?UNICODE_GLYPHS:ASCII_GLYPHS,spinner:o?UNICODE_SPINNER:ASCII_SPINNER}}function detectUnicode(e=process.env){let t=e.EVE_TUI_UNICODE;return t===`0`||t===`false`?!1:t===`1`||t===`true`?!0:e.TERM===`dumb`?!1:process.platform===`win32`?!!(e.WT_SESSION||e.TERM_PROGRAM===`vscode`):!0}export{createTheme,detectUnicode};
1
+ function ansi(e,t,n){if(!n)return e=>e;let r=`[${e}m`,i=`[${t}m`;return e=>`${r}${e}${i}`}function ansi256(e,t){if(!t)return e=>e;let n=`[38;5;${e}m`;return e=>`${n}${e}`}const UNICODE_GLYPHS={brand:`▲`,user:`│`,reasoning:`○`,square:`▪`,corner:`└`,cornerOpen:`┌`,external:`⌝`,dotActive:`⏺`,success:`✓`,error:`⨯`,warning:`⚠`,subagent:`※`,rule:`│`,question:`?`,connection:`●`,arrow:`→`,pointer:`▷`,selectedPointer:`▶`,option:`◦`,prompt:`❯`,promptIdle:`›`,elbow:`⎿`,hrule:`▔`,dash:`─`,caret:`▏`,dot:`·`,ellipsis:`…`,arrowUp:`↑`,arrowDown:`↓`,fast:`↯`,trackFilled:`●`,trackCurrent:`◉`,trackEmpty:`○`,trackLine:`─`,enter:`↵`,validating:`▪`},ASCII_GLYPHS={brand:`>`,user:`|`,reasoning:`o`,square:`*`,corner:"`",cornerOpen:`,`,external:`^`,dotActive:`*`,success:`+`,error:`x`,warning:`!`,subagent:`*`,rule:`|`,question:`?`,connection:`*`,arrow:`->`,pointer:`>`,selectedPointer:`>`,option:`.`,prompt:`>`,promptIdle:`>`,elbow:"`-",hrule:`=`,dash:`-`,caret:`_`,dot:`-`,ellipsis:`...`,arrowUp:`^`,arrowDown:`v`,fast:`>>`,trackFilled:`*`,trackCurrent:`O`,trackEmpty:`.`,trackLine:`-`,enter:`<-'`,validating:`o`},UNICODE_SPINNER=[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`],ASCII_SPINNER=[`-`,`\\`,`|`,`/`];function createTheme(i={}){let a=i.color??!0,o=i.unicode??!0;return{color:a,unicode:o,colors:{reset:ansi(0,0,a),bold:ansi(1,22,a),dim:ansi(2,22,a),inverse:ansi(7,27,a),italic:ansi(3,23,a),white:ansi(97,39,a),gray:ansi(90,39,a),cyan:ansi(36,39,a),green:ansi(32,39,a),red:ansi(31,39,a),yellow:ansi(33,39,a),magenta:ansi(35,39,a),blue:ansi(34,39,a),orange:ansi256(208,a)},glyph:o?UNICODE_GLYPHS:ASCII_GLYPHS,spinner:o?UNICODE_SPINNER:ASCII_SPINNER}}function detectUnicode(e=process.env){let t=e.EVE_TUI_UNICODE;return t===`0`||t===`false`?!1:t===`1`||t===`true`?!0:e.TERM===`dumb`?!1:process.platform===`win32`?!!(e.WT_SESSION||e.TERM_PROGRAM===`vscode`):!0}export{createTheme,detectUnicode};
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The pinned todo panel: pure parsing and rendering for the task list the
3
+ * model maintains through the framework `todo` tool. The tool writes the
4
+ * whole list on every call, so the panel is driven entirely from tool-call
5
+ * inputs — no protocol addition and no durable client state. The renderer
6
+ * owns lifecycle (when a call updates the panel, when the finished list
7
+ * commits to the transcript); this module only reads inputs and paints rows.
8
+ */
9
+ import type { Theme } from "./theme.js";
10
+ /** One panel row parsed from the `todo` tool's replacement-write input. */
11
+ export interface TodoPanelItem {
12
+ readonly content: string;
13
+ readonly status: "pending" | "in_progress" | "completed" | "cancelled";
14
+ }
15
+ /**
16
+ * Extracts the panel items from a tool call when — and only when — it is a
17
+ * `todo` replacement write. Read-only calls (no `todos`) and malformed items
18
+ * return `undefined` so they fall through to the ordinary tool block.
19
+ */
20
+ export declare function readTodoToolItems(toolName: string, input: unknown): TodoPanelItem[] | undefined;
21
+ /** True when every item reached a terminal status (completed or cancelled). */
22
+ export declare function allTodoItemsSettled(items: readonly TodoPanelItem[]): boolean;
23
+ export interface TodoPanelRowsInput {
24
+ readonly items: readonly TodoPanelItem[];
25
+ readonly width: number;
26
+ readonly theme: Theme;
27
+ /** True while the turn is running: pulses the header and the active item. */
28
+ readonly working: boolean;
29
+ /** Current shared pulse frame (the glyph, or a space on the off beat). */
30
+ readonly pulse: string;
31
+ }
32
+ /**
33
+ * Paints the pinned panel, indented so its marks share the tool column.
34
+ * Settled items ride a `│` rail under the header; the
35
+ * first unsettled item closes the rail with `└` and everything after hangs
36
+ * indented — the list reads as progress flowing through the corner.
37
+ */
38
+ export declare function renderTodoPanelRows(input: TodoPanelRowsInput): string[];
39
+ /**
40
+ * The transcript form of a finished list: every item checked on the rail,
41
+ * closed by `└ Done`. Committed verbatim (pre-styled rows) once every item
42
+ * settles.
43
+ */
44
+ export declare function renderFinishedTodoRows(items: readonly TodoPanelItem[], width: number, theme: Theme): string[];
@@ -0,0 +1 @@
1
+ import"./rail.js";import{toolBaseName}from"./tool-presentation.js";import{clipVisible,stripTerminalControls}from"#cli/ui/terminal-text.js";const TODO_STATUSES=new Set([`pending`,`in_progress`,`completed`,`cancelled`]);function readTodoToolItems(t,i){if(toolBaseName(t)!==`todo`||typeof i!=`object`||!i||Array.isArray(i))return;let a=i.todos;if(!Array.isArray(a))return;let o=[];for(let e of a){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,i=t.content,a=t.status;if(typeof i!=`string`||typeof a!=`string`||!TODO_STATUSES.has(a))return;o.push({content:firstLine(stripTerminalControls(i)),status:a})}return o}function allTodoItemsSettled(e){return e.every(e=>e.status===`completed`||e.status===`cancelled`)}function renderTodoPanelRows(e){let{items:n,width:r,theme:i}=e,a=i.colors,o=i.glyph,s=n.filter(e=>e.status===`completed`||e.status===`cancelled`).length,c=[e.working?` ${a.gray(o.square)} ${a.dim(`Todo`)}`:` ${a.gray(o.square)} ${a.dim(`${s}/${n.length} tasks`)}`],l=!1;for(let t of n){let n=t.status===`completed`||t.status===`cancelled`,r;l?r=` `:n?r=a.dim(o.rule):(r=a.dim(o.corner),l=!0),c.push(` ${r} ${todoItemBody(t,e,i)}`)}return c.map(e=>clipVisible(e,r))}function renderFinishedTodoRows(e,n,r){let i=r.colors,a=r.glyph,o=[` ${i.green(a.success)} ${i.dim(`Todo`)}`];for(let t of e)o.push(` ${i.dim(a.rule)} ${settledMark(t,r)} ${i.dim(t.content)}`);return o.push(` ${i.dim(a.corner)} ${i.green(`Done`)}`),o.map(e=>clipVisible(e,n))}function settledMark(e,t){return e.status===`cancelled`?t.colors.red(t.glyph.error):t.colors.green(t.glyph.success)}function todoItemBody(e,t,n){let r=n.colors,i=n.glyph;switch(e.status){case`completed`:return`${r.green(i.success)} ${r.dim(e.content)}`;case`cancelled`:return`${r.red(i.error)} ${r.dim(e.content)}`;case`in_progress`:{let n=t.working?t.pulse.trim().length>0?i.dotActive:` `:i.dotActive;return`${r.yellow(n)} ${e.content}`}case`pending`:return`${r.dim(i.reasoning)} ${r.dim(e.content)}`}}function firstLine(e){return e.split(/\r?\n/u,1)[0]??``}export{allTodoItemsSettled,readTodoToolItems,renderFinishedTodoRows,renderTodoPanelRows};
@@ -0,0 +1,40 @@
1
+ import type { Block, DisplayBlock } from "./blocks.js";
2
+ export interface ToolBlockDisplayGroup {
3
+ readonly members: readonly Block[];
4
+ readonly display: DisplayBlock;
5
+ }
6
+ /**
7
+ * Coalesces presentation only; each member keeps its call id and lifecycle.
8
+ *
9
+ * A contiguous run of equivalent tool calls is partitioned by status, so a
10
+ * batch with interleaved outcomes renders as one succeeded aggregate and one
11
+ * failed aggregate instead of fragmenting on every status flip. A contiguous
12
+ * run of same-named subagent calls coalesces the repeated headers into one
13
+ * counted header, reorders the interleaved children call by call, and elides
14
+ * all but the newest {@link maxVisibleSubagentRunChildren} children behind a
15
+ * `… +N more` row. Captured log writes coalesce per
16
+ * {@link GroupToolBlocksOptions.logCoalescing}. Because of all this, a
17
+ * group's members are not always contiguous in the input: callers that
18
+ * consume a group must remove its members by identity, never by prefix
19
+ * length.
20
+ */
21
+ export interface GroupToolBlocksOptions {
22
+ /**
23
+ * How captured log writes coalesce. `"window"` (the default, for the live
24
+ * block window) merges every write of one source across the whole input
25
+ * into a single section appended after the rest — a process stream is
26
+ * continuous, so interleaved activity must not fragment it — and the
27
+ * section commits as one cluster at the turn boundary. `"runs"` (for
28
+ * committed-transcript rebuilds) merges only contiguous writes, so a
29
+ * `/loglevel` toggle re-renders history at its committed positions instead
30
+ * of relocating every past write to the end.
31
+ */
32
+ readonly logCoalescing?: "window" | "runs";
33
+ }
34
+ export declare function groupToolBlocksForDisplay(blocks: readonly Block[], options?: GroupToolBlocksOptions): ToolBlockDisplayGroup[];
35
+ /**
36
+ * A live subagent section shows only its most recently active child row;
37
+ * everything earlier collapses into a single `… (N more)` line under the
38
+ * header. The completed section's counted footnote carries the full story.
39
+ */
40
+ export declare const maxVisibleSubagentRunChildren = 1;
@@ -0,0 +1 @@
1
+ import{toolBaseName}from"./tool-presentation.js";function groupToolBlocksForDisplay(e,t={}){if((t.logCoalescing??`window`)===`window`){let t=new Map;for(let n of e){if(!isGroupableLogWrite(n))continue;let e=logBucketKey(n),r=t.get(e);r===void 0?t.set(e,[n]):r.push(n)}let n=new Map;for(let e of t.values())n.set(e.at(-1),coalesceLogBucket(e));return groupBlocks(e,n)}return groupBlocks(e)}function groupBlocks(e,t){let n=[];for(let r=0;r<e.length;){let i=e[r];if(isGroupableLogWrite(i)){if(t!==void 0){let e=t.get(i);e!==void 0&&n.push(e),r+=1;continue}let a=[i];for(;r+a.length<e.length&&isGroupableLogWrite(e[r+a.length]);)a.push(e[r+a.length]);n.push(...coalesceLogWrites(a)),r+=a.length;continue}if(i.kind===`subagent`&&i.subagentCallId!==void 0){let i=collectSubagentRun(e,r,t);n.push(...i.groups),r+=i.consumed;continue}if(isCondensableChildTool(i)){let t=[i];for(;r+t.length<e.length;){let n=e[r+t.length];if(n.subagentCallId!==i.subagentCallId||!isCondensableChildTool(n)&&!isItemizedChildFailure(n))break;t.push(n)}let a=e[r+t.length],o=t.filter(isCondensableChildTool);if(o.length>=2&&a?.kind===`subagent-step`&&a.subagentCallId===i.subagentCallId){n.push({members:o,display:condenseChildToolRun(o)});for(let e of t)isCondensableChildTool(e)||n.push({members:[e],display:e});r+=t.length;continue}}if(!isGroupable(i)){n.push({members:[i],display:i}),r+=1;continue}let a=[i];for(;r+a.length<e.length;){let t=e[r+a.length];if(!isGroupable(t)||!sameRun(i,t))break;a.push(t)}a.some(e=>e.status===`running`)&&a.length>1?n.push({members:a,display:aggregateLiveToolBlocks(a)}):n.push(...partitionRunByStatus(a)),r+=a.length}return n}function isGroupable(e){return(e.kind===`tool`||e.kind===`subagent-tool`)&&e.toolGroup!==void 0&&e.expanded!==!0&&(e.status===`running`||e.status===`error`||e.status===`done`&&e.result===void 0)}function sameRun(e,t){return t.kind===e.kind&&t.depth===e.depth&&t.live===e.live&&t.toolName===e.toolName}function partitionRunByStatus(e){let t=new Map;for(let n of e){let e=t.get(n.status);e===void 0?t.set(n.status,[n]):e.push(n)}return[...t.values()].map(e=>({members:e,display:e.length===1?e[0]:e[0].status===`done`?collapseSettledToolBlocks(e):aggregateToolBlocks(e)}))}const maxVisibleSubagentRunChildren=1;function isGroupableLogWrite(e){return e.kind===`log`&&e.id===void 0}function logBucketKey(e){return`${e.title??``}\u0000${e.logVisibility??``}`}function coalesceLogWrites(e){let t=new Map;for(let n of e){let e=logBucketKey(n),r=t.get(e);r===void 0?t.set(e,[n]):r.push(n)}return[...t.values()].map(coalesceLogBucket)}function coalesceLogBucket(e){if(e.length===1)return{members:e,display:e[0]};let t=e.at(-1),n={kind:`log`,live:e.some(e=>e.live!==!1),body:t.body??``,elided:e.length-1};return t.title!==void 0&&(n.title=t.title),t.logVisibility!==void 0&&(n.logVisibility=t.logVisibility),{members:e,display:n}}const RUN_PASS_THROUGH_KINDS=new Set([`log`,`sandbox`,`error`,`warning`,`notice`]);function collectSubagentRun(e,t,r){let i=e[t],a=[i],o=new Map([[i.subagentCallId,[]]]),s=[],c=1;for(;t+c<e.length;c+=1){let r=e[t+c];if(RUN_PASS_THROUGH_KINDS.has(r.kind)){s.push(r);continue}if(r.kind===`subagent`){if(r.subagentCallId===void 0||o.has(r.subagentCallId))break;a.push(r),o.set(r.subagentCallId,[]);continue}let i=r.subagentCallId===void 0?void 0:o.get(r.subagentCallId);if(i===void 0)break;i.push(r)}for(;s.length>0&&e[t+c-1]===s.at(-1);)s.pop(),--c;let l=[];for(let e of a){let t=o.get(e.subagentCallId),n=e.live!==!1||t.some(e=>e.live!==!1),r=n===(e.live!==!1)?e:{...e,live:n};if(e.status===`done`){let i=condensedChildSummary(t);l.push({members:[e],display:r}),l.push({members:t,display:{kind:`subagent-close`,subagentCallId:e.subagentCallId,live:n,body:i===void 0?`Done`:`Done. ${i}`}});continue}l.push({members:[e],display:r});let recency=e=>e.members.reduce((e,t)=>Math.max(e,updateRecency(t)),-1),i=groupToolBlocksForDisplay(t).slice().sort((e,t)=>recency(e)-recency(t)),a=i.slice(0,Math.max(0,i.length-1)),s=i.slice(a.length),c=a.flatMap(e=>e.members);c.length>0&&l.push({members:c,display:{kind:`subagent-step`,depth:1,live:n,elided:c.length}}),l.push(...s.slice(0,-1));let u=s.at(-1);u!==void 0&&l.push({members:u.members,display:{...u.display,closesRail:!0}})}for(let e of s){if(r!==void 0&&isGroupableLogWrite(e)){let t=r.get(e);t!==void 0&&l.push(t);continue}l.push({members:[e],display:e})}return{consumed:c,groups:l}}function aggregateToolBlocks(e){let t=e[0],n=t.toolGroup,r=e.length;return{...t,id:void 0,result:void 0,title:`${n.verb} ${r} ${r===1?n.singularNoun:n.pluralNoun}`,toolGroupItems:newestFirstItems(e)}}function aggregateLiveToolBlocks(e){return{...aggregateToolBlocks(e),status:`running`,live:!0}}function collapseSettledToolBlocks(e){let t=e[0],n=t.toolGroup,r=e.length,i=r===1?n.singularNoun:n.pluralNoun;return{...t,id:void 0,result:void 0,title:`${n.verb} ${r} ${i}`,doneTitle:`${n.pastVerb} ${r} ${i}`}}function isCondensableChildTool(e){return e.kind===`subagent-tool`&&e.status===`done`&&e.expanded!==!0}function isItemizedChildFailure(e){return e.kind===`subagent-tool`&&e.status===`error`&&e.expanded!==!0}function condensedRunTitle(e){let t=new Map;for(let n of e){let e=condensedKindCopy(n),r=`${e.pastVerb} ${e.pluralNoun}`,i=t.get(r);i===void 0?t.set(r,{copy:e,count:1}):i.count+=1}let n=[...t.values()].sort((e,t)=>t.count-e.count),r=n.slice(0,3).map(({copy:e,count:t})=>`${e.pastVerb} ${t} ${t===1?e.singularNoun:e.pluralNoun}`);return n.length>3?`${r.join(`, `)}, and more`:r.join(`, `)}function condensedChildSummary(e){let t=e.filter(e=>e.kind===`subagent-tool`);if(t.length===0)return;let n=t.filter(e=>e.status===`done`),r=t.filter(e=>e.status===`error`).length,i=[];return n.length>0&&i.push(condensedRunTitle(n)),r>0&&i.push(`${r} failed`),i.length>0?i.join(`, `):void 0}function condenseChildToolRun(e){let t=condensedRunTitle(e),n=e[0];return{kind:`subagent-tool`,subagentCallId:n.subagentCallId,depth:n.depth,live:n.live,status:`done`,title:t,doneTitle:t,subtitle:``}}function condensedKindCopy(t){let n=t.toolGroup;return n===void 0?toolBaseName(t.toolName??``)===`write_file`?{pastVerb:`Wrote`,singularNoun:`file`,pluralNoun:`files`}:{pastVerb:`Made`,singularNoun:`tool call`,pluralNoun:`tool calls`}:{pastVerb:n.pastVerb,singularNoun:n.singularNoun,pluralNoun:n.pluralNoun}}function updateRecency(e){return e.updateSeq??0}function newestFirstItems(e){return e.map((e,t)=>({member:e,order:updateRecency(e),position:t})).sort((e,t)=>t.order-e.order||t.position-e.position).map(({member:e})=>{let t={text:e.toolGroup.item};return e.status===`error`&&e.result!==void 0?{...t,result:e.result}:t})}export{groupToolBlocksForDisplay,maxVisibleSubagentRunChildren};
@@ -0,0 +1,67 @@
1
+ import { type ToolDetailLine } from "./line-diff.js";
2
+ /** Renderer-ready copy derived from a tool call without owning its lifecycle. */
3
+ export interface ToolPresentation {
4
+ readonly title: string;
5
+ readonly subtitle: string;
6
+ readonly summarizeResult: (output: unknown) => string | undefined;
7
+ readonly group?: ToolGroupPresentation;
8
+ /** Past-tense title used once the call settles successfully. */
9
+ readonly doneTitle?: string;
10
+ /** Salient body lines shown behind the `│` rail under the header. */
11
+ readonly detail?: readonly ToolDetailLine[];
12
+ /** When true, `detail` stays visible after the call settles (writes). */
13
+ readonly keepDetailWhenDone?: boolean;
14
+ }
15
+ /**
16
+ * Renderer-owned knowledge a presentation may fold in: what a write replaced
17
+ * (from the session's file-content cache) and whether the file existed (from
18
+ * the call's result, once it arrives).
19
+ */
20
+ export interface ToolPresentationContext {
21
+ readonly previousContent?: string;
22
+ readonly existed?: boolean;
23
+ /**
24
+ * True when the tool dispatches a named subagent (each subagent exposes a
25
+ * tool bearing its own name). The presentation reads as a delegation —
26
+ * `Delegate stock-price` — instead of a generic tool call.
27
+ */
28
+ readonly isSubagent?: boolean;
29
+ }
30
+ /** Copy needed to aggregate equivalent calls without merging their state. */
31
+ export interface ToolGroupPresentation {
32
+ readonly verb: string;
33
+ readonly pastVerb: string;
34
+ readonly singularNoun: string;
35
+ readonly pluralNoun: string;
36
+ readonly item: string;
37
+ }
38
+ /**
39
+ * Extracts a write tool call's full-replacement payload. Exported so the
40
+ * renderer can feed its file-content cache from the same contract the
41
+ * presentation reads.
42
+ */
43
+ export declare function readWriteFileInput(toolName: string, input: unknown): {
44
+ path: string;
45
+ content: string;
46
+ } | undefined;
47
+ /**
48
+ * Turns known tool contracts into concise activity copy. Unknown or malformed
49
+ * calls keep the generic formatter, so presentation can never break execution.
50
+ */
51
+ export declare function presentTool(toolName: string, input: unknown, context?: ToolPresentationContext): ToolPresentation;
52
+ /**
53
+ * Placeholder copy for a call whose input is still streaming from the model
54
+ * (`action.preparing`). Known tools lead with their activity verb so the row
55
+ * already reads as intent (`Fetch …`); unknown tools keep their name with a
56
+ * quiet hint. The full presentation replaces this once the input arrives.
57
+ */
58
+ export declare function presentPreparingTool(toolName: string, context?: ToolPresentationContext): ToolPresentation;
59
+ /**
60
+ * Tools whose whole story renders through a dedicated surface — the pinned
61
+ * todo panel, the question overlay — instead of a transcript tool block.
62
+ * Both the preparing announcement and the full call must agree on this
63
+ * set, or a panel-routed tool ghosts as a preparing block.
64
+ */
65
+ export declare function isPanelRoutedTool(toolName: string): boolean;
66
+ /** The tool's short name with any connection/server namespace stripped. */
67
+ export declare function toolBaseName(toolName: string): string;
@@ -0,0 +1 @@
1
+ import{summarizeToolArgs,summarizeToolResult}from"./tool-format.js";import{diffWriteDetail}from"./line-diff.js";import{stripTerminalControls}from"#cli/ui/terminal-text.js";const WRITE_FILE_VERB=`Write`,DELEGATE_VERB=`Delegate`,FINAL_OUTPUT_TITLE=`Return final output`,BUILTIN_TOOL_COPY={agent:{verb:`Delegate`,pastVerb:`Delegated`,argKey:`message`,singularNoun:`task`,pluralNoun:`tasks`},ask_question:{verb:`Ask`,pastVerb:`Asked`,argKey:`prompt`,singularNoun:`question`,pluralNoun:`questions`},bash:{verb:`Run`,pastVerb:`Ran`,argKey:`command`,singularNoun:`command`,pluralNoun:`commands`},connection_search:{verb:`Discover`,pastVerb:`Discovered`,argKey:`keywords`,singularNoun:`tool search`,pluralNoun:`tool searches`},glob:{verb:`Glob`,pastVerb:`Globbed`,argKey:`pattern`,singularNoun:`pattern`,pluralNoun:`patterns`},grep:{verb:`Grep`,pastVerb:`Grepped`,argKey:`pattern`,singularNoun:`pattern`,pluralNoun:`patterns`},load_skill:{verb:`Load`,pastVerb:`Loaded`,argKey:`skill`,singularNoun:`skill`,pluralNoun:`skills`},read_file:{verb:`Read`,pastVerb:`Read`,argKey:`filePath`,singularNoun:`file`,pluralNoun:`files`},web_fetch:{verb:`Fetch`,pastVerb:`Fetched`,argKey:`url`,singularNoun:`URL`,pluralNoun:`URLs`},web_search:{verb:`Search`,pastVerb:`Searched`,argKey:`query`,extractItem:e=>salientArg(e,`objective`)??salientArg(e,`search_query`)??salientArg(e,`searchQuery`)??webSearchActionArg(e),singularNoun:`query`,pluralNoun:`queries`}};function presentWriteFileTool(a,o,s){let c=readWriteFileInput(a,o);if(c===void 0)return{title:a,subtitle:summarizeToolArgs(o),summarizeResult:summarizeToolResult};let l=diffWriteDetail(s?.previousContent,c.content,s?.existed).map(e=>e.kind===`gap`?e:{...e,text:stripTerminalControls(e.text)});return{title:`${WRITE_FILE_VERB} ${salientLine(c.path)??c.path}`,doneTitle:`Wrote ${salientLine(c.path)??c.path}`,subtitle:``,summarizeResult:()=>void 0,detail:l,keepDetailWhenDone:!0}}function readWriteFileInput(e,t){if(toolBaseName(e)!==`write_file`||typeof t!=`object`||!t||Array.isArray(t))return;let n=t,r=n.filePath,i=n.content;if(!(typeof r!=`string`||r.trim().length===0)&&typeof i==`string`)return{path:r,content:i}}function presentTool(n,r,i){let c=toolBaseName(n);if(c===`todo`)return presentTodoTool(r);if(c===`write_file`)return presentWriteFileTool(n,r,i);if(i?.isSubagent===!0)return{title:`${DELEGATE_VERB} ${c}`,doneTitle:`Delegated ${c}`,subtitle:salientArg(r,`message`)??``,summarizeResult:()=>void 0};if(c===`final_output`)return{title:FINAL_OUTPUT_TITLE,subtitle:``,summarizeResult:()=>void 0};let l=BUILTIN_TOOL_COPY[c];if(l!==void 0){let e=salientArg(r,l.argKey)??l.extractItem?.(r);if(e!==void 0)return{title:`${l.verb} ${e}`,doneTitle:`${l.pastVerb} ${e}`,subtitle:``,summarizeResult:()=>void 0,group:{verb:l.verb,pastVerb:l.pastVerb,singularNoun:l.singularNoun,pluralNoun:l.pluralNoun,item:e}}}return{title:n,subtitle:summarizeToolArgs(r),summarizeResult:summarizeToolResult}}function presentPreparingTool(e,t){let n=toolBaseName(e);if(n===`final_output`)return{title:FINAL_OUTPUT_TITLE,subtitle:``,summarizeResult:()=>void 0};if(t?.isSubagent===!0)return{title:`${DELEGATE_VERB} ${n} …`,subtitle:``,summarizeResult:()=>void 0};let r=n===`write_file`?WRITE_FILE_VERB:BUILTIN_TOOL_COPY[n]?.verb;return{title:r===void 0?e:`${r} …`,subtitle:r===void 0?`preparing…`:``,summarizeResult:()=>void 0}}function isPanelRoutedTool(e){let t=toolBaseName(e);return t===`todo`||t===`ask_question`}function toolBaseName(e){return e.split(/[.:/]/u).at(-1)??e}function presentTodoTool(e){let t=typeof e==`object`&&e&&!Array.isArray(e)?e.todos:void 0;return Array.isArray(t)?{title:`Update todo list`,subtitle:`${t.length} task${t.length===1?``:`s`}`,summarizeResult:()=>void 0}:{title:`Read todo list`,subtitle:``,summarizeResult:()=>void 0}}function webSearchActionArg(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e.action;if(typeof t!=`object`||!t||Array.isArray(t))return;let n=t,r=n.queries;if(Array.isArray(r)){let e=r.filter(e=>typeof e==`string`).map(salientLine).filter(e=>e!==void 0).join(`, `);if(e.length>0)return e}for(let e of[`query`,`url`,`pattern`]){let t=n[e];if(typeof t==`string`){let e=salientLine(t);if(e!==void 0)return e}}}function salientArg(e,t){if(typeof e!=`object`||!e||Array.isArray(e))return;let n=e[t];if(typeof n==`string`)return salientLine(n)}function salientLine(e){let t=stripTerminalControls(e).split(/\r?\n/u).find(e=>e.trim().length>0)?.trim()??``;return t.length>0?t:void 0}export{isPanelRoutedTool,presentPreparingTool,presentTool,readWriteFileInput,toolBaseName};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Renders a tool block's terminal rows: the indented header (status glyph,
3
+ * verb-bold title, summarized args), the `│`-railed detail region —
4
+ * aggregated batch items or a write's diffed content — closed by a `└`
5
+ * corner, and the settled result line. Split from `blocks.ts` so the block
6
+ * model and its per-kind renderers stay separable concerns.
7
+ */
8
+ import type { DisplayBlock, RenderBlockContext } from "./blocks.js";
9
+ import type { Theme } from "./theme.js";
10
+ export declare function renderTool(block: DisplayBlock, width: number, theme: Theme, context: RenderBlockContext): string[];
11
+ /**
12
+ * An aggregated tool row lists at most this many member items; the rest
13
+ * collapse into a single `… (N more)` line above the closing corner.
14
+ */
15
+ export declare const maxVisibleToolGroupItems = 5;
@@ -0,0 +1,2 @@
1
+ import{formatValuePretty,truncate}from"./tool-format.js";import{elisionText}from"./rail.js";import{clipVisible,visibleLength,wrapVisibleLine}from"#cli/ui/terminal-text.js";function renderTool(e,t,n,r){return(e.depth??0)===0?renderToolRows(e,t-1,n,r).map(e=>` ${e}`):renderToolRows(e,t,n,r)}function renderToolRows(e,n,i,a){let{icon:o,accent:s}=toolGlyph(e.status??`running`,i,a),c=e.status===`done`&&e.doneTitle!==void 0?e.doneTitle:e.title??`tool`,l=n-3,u=clipVisible(c,l),d=` ${o} ${boldLeadingWord(u,i)}`,f=l-u.length-2,p=e.subtitle??``;p.length>0&&f>=6&&(d+=` ${i.colors.gray(truncate(p,f))}`);let m=[d],h=[];return e.toolGroupItems===void 0?!e.expanded&&showToolDetail(e)&&h.push(...detailLineRows(e.detailLines??[],n,i)):h.push(...toolGroupItemRows(e.toolGroupItems,n,i)),h.length>0&&m.push(...h,` ${i.colors.dim(i.glyph.corner)}`),e.expanded?m.push(...renderToolExpanded(e,n,i)):e.status===`done`&&e.result&&e.result.length>0?m.push(resultLine(i.glyph.arrow,e.result,n,i,s)):e.status===`error`&&e.result?m.push(errorDetailLine(e.result,n,i)):e.status===`denied`&&m.push(resultLine(i.glyph.arrow,`denied`,n,i,i.colors.yellow)),m}function boldLeadingWord(e,t){let n=e.indexOf(` `);return n===-1?t.colors.bold(e):`${t.colors.bold(e.slice(0,n))}${t.colors.dim(e.slice(n))}`}function showToolDetail(e){if(e.detailLines===void 0||e.detailLines.length===0)return!1;let t=e.status??`running`;return t===`running`||t===`approval`?!0:e.keepDetailWhenDone===!0}const maxVisibleToolGroupItems=5;function railRow(e,t){return` ${t.colors.dim(t.glyph.rule)} ${e}`}function elisionRow(e,t){return railRow(elisionText(e,t),t)}function toolGroupItemRows(e,t,n){let r=e.slice(0,5),i=e.length-r.length,a=itemRows(r,t,n);return i>0&&a.push(elisionRow(i,n)),a}function detailLineRows(e,t,n){let i=n.colors,a=e.slice(0,10),o=e.length-a.length,s=a.some(e=>e.kind===`added`||e.kind===`removed`),c=Math.max(1,t-(s?5:4)),l=a.map(e=>{if(e.kind===`gap`)return railRow(i.dim(n.glyph.ellipsis),n);let t=clipVisible(e.text,c);switch(e.kind){case`added`:return` ${i.dim(n.glyph.rule)}${i.green(`+`)} ${i.green(t)}`;case`removed`:return` ${i.dim(n.glyph.rule)}${i.red(`-`)} ${i.red(t)}`;default:return s?` ${i.dim(n.glyph.rule)} ${i.gray(t)}`:railRow(i.gray(t),n)}});return o>0&&l.push(elisionRow(o,n)),l}function itemRows(e,n,r){let a=Math.max(1,n-4);if(!e.some(e=>e.result!==void 0&&e.result.length>0))return e.map(e=>railRow(r.colors.gray(truncate(e.text,a)),r));let o=Math.min(Math.max(...e.map(e=>visibleLength(e.text))),Math.max(8,a-9)),s=Math.max(8,a-o-1);return e.map(e=>{let n=truncate(e.text,o);if(e.result===void 0||e.result.length===0)return railRow(r.colors.gray(n),r);let a=n+` `.repeat(Math.max(0,o-visibleLength(n)));return railRow(`${r.colors.gray(a)} ${r.colors.red(truncate(e.result,s))}`,r)})}function renderToolExpanded(t,n,r){let i=[],push=(t,o,s)=>{if(o!==void 0){i.push(` ${r.colors.dim(t)}`);for(let t of formatValuePretty(o).split(`
2
+ `))for(let e of wrapVisibleLine(t,Math.max(1,n-4)))i.push(` ${s(e)}`)}};return push(`input`,t.toolInput,r.colors.gray),t.status===`error`&&t.result?push(`error`,t.result,r.colors.red):push(`output`,t.toolOutput,r.colors.gray),i}function resultLine(e,n,r,i,a){let o=r-4;return` ${i.colors.dim(e)} ${a(truncate(n,o))}`}function errorDetailLine(e,n,r){let i=n-5;return` ${r.colors.dim(r.glyph.corner)} ${r.colors.red(truncate(e,i))}`}function toolGlyph(e,t,n){switch(e){case`done`:return{icon:t.colors.gray(t.glyph.square),accent:t.colors.gray};case`error`:return{icon:t.colors.red(t.glyph.error),accent:t.colors.red};case`denied`:return{icon:t.colors.yellow(t.glyph.warning),accent:t.colors.yellow};case`approval`:return{icon:t.colors.yellow(t.glyph.question),accent:t.colors.yellow};default:return{icon:t.colors.yellow(n.activityPulse),accent:t.colors.gray}}}export{maxVisibleToolGroupItems,renderTool};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * One turn's wall clock and summed token flow. "When did this turn start"
3
+ * is a single fact; this object is its single representation — armed once
4
+ * per turn (a prompt submit, or an `--input` turn arming itself), fed by
5
+ * step usage reports, and consumed exactly once by the end-of-turn coda.
6
+ * Multi-pass turns (question answers, connection authorizations) re-stream
7
+ * without re-arming, so one turn gets one coda.
8
+ */
9
+ export declare class TurnClock {
10
+ #private;
11
+ /** Starts the turn: resets the summed flow and stamps the clock. */
12
+ arm(): void;
13
+ get armed(): boolean;
14
+ get startedAtMs(): number | undefined;
15
+ get usage(): {
16
+ readonly inputTokens: number;
17
+ readonly outputTokens: number;
18
+ };
19
+ addUsage(usage: {
20
+ inputTokens?: number;
21
+ outputTokens?: number;
22
+ }): void;
23
+ /**
24
+ * Consumes the armed clock, returning the turn's elapsed time and summed
25
+ * flow — or `undefined` when no turn was armed (the coda's "already
26
+ * settled" signal). The flow survives the settle so a repaint between the
27
+ * coda and the next arm still reads the last turn's numbers.
28
+ */
29
+ settle(): {
30
+ elapsedMs: number;
31
+ inputTokens: number;
32
+ outputTokens: number;
33
+ } | undefined;
34
+ /** Drops the clock without a coda (conversation boundaries). */
35
+ reset(): void;
36
+ }
@@ -0,0 +1 @@
1
+ var TurnClock=class{#e;#t={inputTokens:0,outputTokens:0};arm(){this.#e=Date.now(),this.#t={inputTokens:0,outputTokens:0}}get armed(){return this.#e!==void 0}get startedAtMs(){return this.#e}get usage(){return this.#t}addUsage(e){this.#t.inputTokens+=e.inputTokens??0,this.#t.outputTokens+=e.outputTokens??0}settle(){let e=this.#e;if(e!==void 0)return this.#e=void 0,{elapsedMs:Date.now()-e,...this.#t}}reset(){this.#e=void 0,this.#t={inputTokens:0,outputTokens:0}}};export{TurnClock};