eve 0.31.2 → 0.32.0

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 (221) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/src/chunks/{use-eve-agent-CF5D6jSV.js → use-eve-agent-CX87G1vU.js} +30 -5
  3. package/dist/src/chunks/{use-eve-agent-DbYZLG0h.js → use-eve-agent-DwyRde1N.js} +30 -5
  4. package/dist/src/cli/commands/integration-connect.d.ts +1 -0
  5. package/dist/src/cli/commands/integration-connect.js +1 -1
  6. package/dist/src/cli/commands/integration-setup.d.ts +4 -0
  7. package/dist/src/cli/commands/integration-setup.js +1 -1
  8. package/dist/src/cli/commands/register-integration-commands.js +1 -1
  9. package/dist/src/cli/commands/register-registry-commands.js +1 -1
  10. package/dist/src/cli/commands/registry-declared-setups.d.ts +23 -0
  11. package/dist/src/cli/commands/registry-declared-setups.js +1 -0
  12. package/dist/src/cli/commands/registry-metadata.d.ts +69 -0
  13. package/dist/src/cli/commands/registry-metadata.js +1 -1
  14. package/dist/src/cli/commands/registry-package.d.ts +3 -3
  15. package/dist/src/cli/commands/registry-package.js +1 -1
  16. package/dist/src/cli/commands/registry-presentation.d.ts +20 -0
  17. package/dist/src/cli/commands/registry-presentation.js +7 -0
  18. package/dist/src/cli/commands/registry-search-presentation.d.ts +16 -0
  19. package/dist/src/cli/commands/registry-search-presentation.js +6 -0
  20. package/dist/src/cli/commands/registry-setup-command.d.ts +5 -2
  21. package/dist/src/cli/commands/registry-setup-command.js +1 -2
  22. package/dist/src/cli/commands/registry.d.ts +16 -7
  23. package/dist/src/cli/commands/registry.js +1 -6
  24. package/dist/src/cli/commands/setup-answers.d.ts +2 -0
  25. package/dist/src/cli/commands/setup-answers.js +1 -0
  26. package/dist/src/cli/commands/setup-headless.d.ts +79 -0
  27. package/dist/src/cli/commands/setup-headless.js +1 -0
  28. package/dist/src/cli/dev/tui/runner.js +1 -1
  29. package/dist/src/cli/dev/tui/setup-commands.js +3 -3
  30. package/dist/src/cli/dev/tui/setup-flow.d.ts +8 -1
  31. package/dist/src/cli/dev/tui/terminal-renderer.js +12 -12
  32. package/dist/src/cli/dev/tui/traces/trace-conversation.d.ts +1 -1
  33. package/dist/src/cli/dev/tui/tui-prompter.js +1 -1
  34. package/dist/src/client/url.d.ts +5 -0
  35. package/dist/src/client/url.js +1 -1
  36. package/dist/src/compiled/.vendor-stamp.json +8 -8
  37. package/dist/src/compiled/@ai-sdk/anthropic/index.d.ts +33 -13
  38. package/dist/src/compiled/@ai-sdk/anthropic/index.js +4 -2
  39. package/dist/src/compiled/@ai-sdk/google/index.d.ts +50 -3
  40. package/dist/src/compiled/@ai-sdk/google/index.js +7 -7
  41. package/dist/src/compiled/@ai-sdk/mcp/index.d.ts +33 -3
  42. package/dist/src/compiled/@ai-sdk/mcp/index.js +1 -1
  43. package/dist/src/compiled/@ai-sdk/openai/index.d.ts +140 -9
  44. package/dist/src/compiled/@ai-sdk/openai/index.js +9 -6
  45. package/dist/src/compiled/@ai-sdk/otel/index.js +1 -1
  46. package/dist/src/compiled/@ai-sdk/provider/index.d.ts +300 -6
  47. package/dist/src/compiled/@ai-sdk/provider-utils/index.d.ts +70 -20
  48. package/dist/src/compiled/@opentelemetry/api/index.d.ts +2 -1
  49. package/dist/src/compiled/@photon-ai/chat-adapter-imessage/index.js +1 -1
  50. package/dist/src/compiled/@vercel/otel/index.d.ts +6 -0
  51. package/dist/src/compiled/@vercel/sandbox/index.js +1 -1
  52. package/dist/src/compiled/_chunks/node/undici-CUIybhQ2.js +95 -0
  53. package/dist/src/compiled/_chunks/workflow/dist-eUxFublw.js +77 -0
  54. package/dist/src/compiled/shadcn-registry/index.js +309 -215
  55. package/dist/src/compiler/extension-compatibility.d.ts +10 -10
  56. package/dist/src/compiler/extension-compatibility.js +1 -1
  57. package/dist/src/context/build-callback-context.js +1 -1
  58. package/dist/src/execution/authorization-callback-match.d.ts +14 -0
  59. package/dist/src/execution/authorization-callback-match.js +1 -0
  60. package/dist/src/execution/next-driver-action.d.ts +1 -0
  61. package/dist/src/execution/parked-delivery-wait.d.ts +16 -1
  62. package/dist/src/execution/parked-delivery-wait.js +1 -1
  63. package/dist/src/execution/sandbox/abort-bound-session.d.ts +1 -1
  64. package/dist/src/execution/sandbox/bindings/docker.js +1 -1
  65. package/dist/src/execution/sandbox/bindings/just-bash-runtime.js +1 -1
  66. package/dist/src/execution/sandbox/bindings/microsandbox-lifecycle.js +1 -1
  67. package/dist/src/execution/sandbox/bindings/microsandbox-runtime.d.ts +1 -0
  68. package/dist/src/execution/sandbox/bindings/microsandbox-runtime.js +1 -1
  69. package/dist/src/execution/sandbox/bindings/vercel.js +1 -1
  70. package/dist/src/execution/sandbox/ensure.js +1 -1
  71. package/dist/src/execution/session-command-inbox.d.ts +26 -1
  72. package/dist/src/execution/session-command-inbox.js +1 -1
  73. package/dist/src/execution/turn-execution-cursor.d.ts +1 -0
  74. package/dist/src/execution/turn-workflow.js +1 -1
  75. package/dist/src/execution/workflow-entry.js +1 -1
  76. package/dist/src/execution/workflow-steps.d.ts +3 -4
  77. package/dist/src/execution/workflow-steps.js +1 -1
  78. package/dist/src/harness/authorization.d.ts +24 -11
  79. package/dist/src/harness/authorization.js +1 -1
  80. package/dist/src/harness/input-extraction.js +1 -1
  81. package/dist/src/harness/input-requests.js +1 -1
  82. package/dist/src/harness/provider-tools.d.ts +1 -1
  83. package/dist/src/harness/provider-tools.js +1 -1
  84. package/dist/src/harness/tool-loop.js +2 -2
  85. package/dist/src/internal/application/package.js +1 -1
  86. package/dist/src/internal/authored-definition/connection.js +1 -1
  87. package/dist/src/packages/eve-catalog/src/index.js +1 -1
  88. package/dist/src/protocol/routes.d.ts +8 -6
  89. package/dist/src/protocol/routes.js +1 -1
  90. package/dist/src/public/channels/linear/linearChannel.d.ts +2 -0
  91. package/dist/src/public/channels/linear/linearChannel.js +1 -1
  92. package/dist/src/public/channels/linear/verify.js +1 -1
  93. package/dist/src/public/channels/slack/attachments.js +1 -1
  94. package/dist/src/public/channels/slack/defaults.js +1 -1
  95. package/dist/src/public/channels/slack/hitl.d.ts +14 -1
  96. package/dist/src/public/channels/slack/hitl.js +2 -2
  97. package/dist/src/public/connections/index.d.ts +1 -0
  98. package/dist/src/public/definitions/callback-context.d.ts +2 -2
  99. package/dist/src/public/definitions/connections/mcp.d.ts +9 -0
  100. package/dist/src/public/definitions/connections/openapi.d.ts +9 -0
  101. package/dist/src/public/definitions/connections/tool-call.d.ts +21 -0
  102. package/dist/src/public/definitions/connections/tool-call.js +1 -0
  103. package/dist/src/public/definitions/sandbox.d.ts +1 -1
  104. package/dist/src/public/definitions/tool.d.ts +9 -9
  105. package/dist/src/public/sandbox/index.d.ts +1 -1
  106. package/dist/src/public/tools/web-search.d.ts +2 -2
  107. package/dist/src/runtime/connections/callback-route.d.ts +4 -5
  108. package/dist/src/runtime/connections/callback-route.js +1 -1
  109. package/dist/src/runtime/connections/mcp-client.js +1 -1
  110. package/dist/src/runtime/connections/openapi-client.js +1 -1
  111. package/dist/src/runtime/connections/provided-arguments.d.ts +9 -0
  112. package/dist/src/runtime/connections/provided-arguments.js +1 -0
  113. package/dist/src/runtime/connections/scoped-authorization.js +1 -1
  114. package/dist/src/runtime/framework-tools/connection-search-dynamic.js +2 -2
  115. package/dist/src/runtime/framework-tools/todo.js +1 -1
  116. package/dist/src/runtime/input/types.d.ts +1 -4
  117. package/dist/src/runtime/resolve-connection.js +1 -1
  118. package/dist/src/runtime/types.d.ts +2 -0
  119. package/dist/src/sandbox/state.d.ts +1 -0
  120. package/dist/src/setup/ask-editable.d.ts +22 -0
  121. package/dist/src/setup/ask-editable.js +1 -0
  122. package/dist/src/setup/ask-signals.d.ts +23 -0
  123. package/dist/src/setup/ask-signals.js +1 -0
  124. package/dist/src/setup/ask.d.ts +24 -25
  125. package/dist/src/setup/ask.js +1 -1
  126. package/dist/src/setup/boxes/deploy-project.js +1 -1
  127. package/dist/src/setup/boxes/resolve-provisioning.js +1 -1
  128. package/dist/src/setup/connection-connector.js +3 -2
  129. package/dist/src/setup/flows/registry-session.d.ts +33 -0
  130. package/dist/src/setup/flows/registry-session.js +1 -0
  131. package/dist/src/setup/flows/registry.d.ts +16 -0
  132. package/dist/src/setup/flows/registry.js +1 -1
  133. package/dist/src/setup/index.js +1 -1
  134. package/dist/src/setup/integrations/discord/setup.d.ts +19 -7
  135. package/dist/src/setup/integrations/discord/setup.js +4 -3
  136. package/dist/src/setup/integrations/github/setup.d.ts +36 -7
  137. package/dist/src/setup/integrations/github/setup.js +2 -2
  138. package/dist/src/setup/integrations/linear/setup.d.ts +21 -9
  139. package/dist/src/setup/integrations/linear/setup.js +2 -2
  140. package/dist/src/setup/integrations/photon/management.d.ts +8 -1
  141. package/dist/src/setup/integrations/photon/management.js +1 -1
  142. package/dist/src/setup/integrations/photon/setup-flow.d.ts +28 -24
  143. package/dist/src/setup/integrations/photon/setup-flow.js +3 -3
  144. package/dist/src/setup/integrations/photon/setup.d.ts +1 -3
  145. package/dist/src/setup/integrations/photon/setup.js +1 -1
  146. package/dist/src/setup/integrations/registry.d.ts +1 -1
  147. package/dist/src/setup/integrations/registry.js +1 -1
  148. package/dist/src/setup/integrations/runner.d.ts +14 -11
  149. package/dist/src/setup/integrations/runner.js +1 -1
  150. package/dist/src/setup/integrations/shared/prerequisite.d.ts +17 -0
  151. package/dist/src/setup/integrations/shared/prerequisite.js +1 -0
  152. package/dist/src/setup/integrations/shared/ui.d.ts +22 -15
  153. package/dist/src/setup/integrations/shared/ui.js +2 -2
  154. package/dist/src/setup/integrations/shared/vercel-project.d.ts +11 -0
  155. package/dist/src/setup/integrations/shared/vercel-project.js +1 -0
  156. package/dist/src/setup/integrations/slack/setup.d.ts +25 -10
  157. package/dist/src/setup/integrations/slack/setup.js +1 -1
  158. package/dist/src/setup/integrations/types.d.ts +43 -13
  159. package/dist/src/setup/integrations/types.js +1 -1
  160. package/dist/src/setup/integrations/web/setup.d.ts +22 -3
  161. package/dist/src/setup/integrations/web/setup.js +1 -1
  162. package/dist/src/setup/prompter.d.ts +8 -0
  163. package/dist/src/setup/question-options.d.ts +15 -0
  164. package/dist/src/setup/question-options.js +1 -0
  165. package/dist/src/setup/registry-setup-client.d.ts +3 -4
  166. package/dist/src/setup/registry-setup-client.js +2 -2
  167. package/dist/src/setup/registry-setup-completion.d.ts +3 -0
  168. package/dist/src/setup/registry-setup-completion.js +1 -0
  169. package/dist/src/setup/registry-setup-protocol.d.ts +22 -3
  170. package/dist/src/setup/registry-setup-protocol.js +1 -1
  171. package/dist/src/setup/scaffold/create/add-to-project.js +1 -1
  172. package/dist/src/setup/scaffold/create/project.js +55 -3
  173. package/dist/src/setup/scaffold/update/channels.js +1 -1
  174. package/dist/src/setup/setup-question-wire.d.ts +48 -0
  175. package/dist/src/setup/setup-question-wire.js +1 -0
  176. package/dist/src/setup/slackbot.d.ts +5 -1
  177. package/dist/src/setup/slackbot.js +1 -1
  178. package/dist/src/setup/state.d.ts +2 -2
  179. package/dist/src/shared/sandbox-backend.d.ts +6 -0
  180. package/dist/src/shared/sandbox-session.d.ts +15 -0
  181. package/dist/src/shared/tool-definition.d.ts +2 -2
  182. package/dist/src/shared/tool-schema.d.ts +5 -4
  183. package/dist/src/shared/tool-schema.js +1 -1
  184. package/dist/src/svelte/index.js +1 -1
  185. package/dist/src/svelte/use-eve-agent.js +1 -1
  186. package/dist/src/tracing/agent-otel-provider.d.ts +5 -38
  187. package/dist/src/tracing/agent-otel-provider.js +2 -2
  188. package/dist/src/tracing/agent-span-id-generator.d.ts +15 -0
  189. package/dist/src/tracing/agent-span-id-generator.js +1 -0
  190. package/dist/src/tracing/agent-trace-context-store.d.ts +1 -1
  191. package/dist/src/tracing/agent-trace-context-store.js +1 -1
  192. package/dist/src/tracing/agent-trace-state.d.ts +41 -0
  193. package/dist/src/tracing/agent-trace-state.js +1 -0
  194. package/dist/src/tracing/local-instrumentation-runtime.js +1 -1
  195. package/dist/src/vue/index.js +1 -1
  196. package/dist/src/vue/use-eve-agent.js +1 -1
  197. package/docs/channels/chat-sdk.mdx +1 -1
  198. package/docs/channels/github.mdx +1 -1
  199. package/docs/channels/linear.mdx +4 -2
  200. package/docs/channels/overview.mdx +2 -2
  201. package/docs/channels/slack.mdx +154 -40
  202. package/docs/concepts/default-harness.md +3 -3
  203. package/docs/concepts/sessions-runs-and-streaming.md +1 -1
  204. package/docs/connections/mcp.mdx +35 -1
  205. package/docs/connections/openapi.mdx +24 -0
  206. package/docs/guides/dev-tui.md +58 -142
  207. package/docs/guides/dynamic-workflows.md +2 -0
  208. package/docs/guides/frontend/overview.mdx +4 -2
  209. package/docs/guides/hooks.md +25 -3
  210. package/docs/guides/session-context.md +18 -0
  211. package/docs/install-integrations.mdx +2 -0
  212. package/docs/reference/cli.md +5 -3
  213. package/docs/reference/typescript-api.md +1 -1
  214. package/docs/sandbox.mdx +25 -5
  215. package/docs/skills.mdx +12 -1
  216. package/docs/subagents.mdx +1 -1
  217. package/docs/tools/human-in-the-loop.md +1 -1
  218. package/docs/tutorial/ship-it.mdx +1 -1
  219. package/package.json +10 -10
  220. package/dist/src/compiled/_chunks/node/undici-DWL_MYmT.js +0 -95
  221. package/dist/src/compiled/_chunks/workflow/dist-CZxNEvEs.js +0 -79
@@ -1,15 +1,15 @@
1
- import{PROMPT_COMMANDS,isPromptControlCommand,parsePromptCommand}from"./prompt-commands.js";import{buildAgentHeader}from"./agent-header.js";import{renderAttentionRows,renderBlockLines}from"./blocks.js";import{copyTextToClipboard}from"./clipboard.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{MessageQueue,renderMessageQueueRows}from"./message-queue.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{formatAssistantResponseStats,formatTokenFlow,formatTurnDuration,isIncompleteOsc,isIncompletePaste,nextKey,sanitizePastedText,stripPasteStart,stripPromptControlCharacters,takeUntil,typewriterText}from"./stream-format.js";import{TraceViewerSession}from"./traces/trace-viewer-session.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{BACKGROUND_COLOR_QUERY,parseBackgroundColorReply}from"./terminal-background.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{AltScreen}from"#cli/ui/alt-screen.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){return e.interrupted?`Interrupted`:e.cancelled?`Cancelled`:e.continueSession?`Ready`:`Done`}const incompletePasteFlushMs=1e3,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=[];#h=new Map;#g=new Set;#_=[];#v=new Set;#y=new Map;#b=0;#x=new Map;#S=new FileContentCache;#C=new Set;#w;#T=!1;#E;#D=[];#O;#k=0;#A;#j;#M=``;#N=0;#P=new PromptHistory;#F=!1;#I;#L=!1;#R=Date.now();#z=!1;#B=new TurnClock;#V=EMPTY_LINE;#H=!1;#U={kind:`idle`};#W;#G=STATUS.processing;#K;#q=`eve`;#J=!1;#Y=!1;#X=!1;#Z=!1;#Q=!1;#$=!1;#ee;#te=!0;#ne=0;#re=Date.now();#ie;#ae;#oe;#se=!1;#ce;#le=``;#ue=new StringDecoder(`utf8`);#de;#fe;#pe;#me=!1;#he=!1;#ge;#_e;#ve;#ye;#be;#xe;#Se;#Ce=``;#we=``;#Te;#Ee;#De=0;#Oe;#ke;#Ae;#je;#Me;#Ne;#Pe=new MessageQueue;#Fe;#Ie=!1;#Le;#Re;#ze=!1;#Be;#Ve;#He;#Ue;#We;setupFlow={begin:(e,t)=>this.#Xe(e,t),end:e=>this.#Ze(e?.preserveDiagnostics??!0),readSelect:e=>this.#Qe(e),readEditableSelect:e=>this.#et(e),readProviderPicker:e=>this.#tt(e),readModelEditor:e=>this.#nt(e),readText:e=>this.#rt(e),readAcknowledge:e=>this.#it(e),readChoice:e=>this.#$e(e),setStatus:e=>this.#ft(e),renderLine:(e,t)=>this.#pt(e,t),renderOutput:e=>this.#mt(e),withInheritedStdio:e=>this.#ht(e),withExclusiveTerminal:e=>this.#ht(e),waitForInterrupt:e=>this.#lt(e)};traceViewer={open:e=>this.#_t(e)};constructor(t){this.#e=t?.input??process.stdin,this.#t=t?.output??process.stdout,this.#n=new LiveRegion(this.#t),this.#r=new AltScreen(this.#t),this.#i=createTheme({color:t?.color??!0,unicode:t?.unicode??detectUnicode()}),this.#a=t?.tools??`auto-collapsed`,this.#o=t?.reasoning??`auto-collapsed`,this.#s=t?.subagents??`auto-collapsed`,this.#c=t?.connectionAuth??`full`,this.#l=t?.assistantResponseStats??`tokensPerSecond`,this.#ve=t?.contextSize,this.#u=t?.captureForeignOutput??this.#t===process.stdout,this.#d=t?.diagnostics,this.#ee=t?.onExitRequest,this.#p=t?.logs??`none`,this.#f=t?.availablePromptCommands??PROMPT_COMMANDS}renderAgentHeader(e){this.#q=e.name,this.#w=e,this.#bt();let t=this.#ln().join(`
2
- `);if(this.#T){t!==this.#E&&(this.#E=t,this.#Lt({kind:`agent-header`,body:t,live:!1})),this.#in();return}this.#T=!0,this.#E=t,this.#n.flush(this.#ln(),[])}async readPrompt(e){this.#bt(e),this.#It(),this.#zt(),this.#F=!0,this.#L=!0,this.#U={kind:`idle`},this.#G=``,this.#$=!1;let r=this.#Pe.restoreDraft()?.split(`
1
+ import{PROMPT_COMMANDS,isPromptControlCommand,parsePromptCommand}from"./prompt-commands.js";import{buildAgentHeader}from"./agent-header.js";import{renderAttentionRows,renderBlockLines}from"./blocks.js";import{copyTextToClipboard}from"./clipboard.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{MessageQueue,renderMessageQueueRows}from"./message-queue.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{formatAssistantResponseStats,formatTokenFlow,formatTurnDuration,isIncompleteOsc,isIncompletePaste,nextKey,sanitizePastedText,stripPasteStart,stripPromptControlCharacters,takeUntil,typewriterText}from"./stream-format.js";import{TraceViewerSession}from"./traces/trace-viewer-session.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{BACKGROUND_COLOR_QUERY,parseBackgroundColorReply}from"./terminal-background.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{AltScreen}from"#cli/ui/alt-screen.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){return e.interrupted?`Interrupted`:e.cancelled?`Cancelled`:e.continueSession?`Ready`:`Done`}const incompletePasteFlushMs=1e3,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=[];#h=new Map;#g=new Set;#_=[];#v=new Set;#y=new Map;#b=0;#x=new Map;#S=new FileContentCache;#C=new Set;#w;#T=!1;#E;#D=[];#O;#k=0;#A;#j;#M=``;#N=0;#P=new PromptHistory;#F=!1;#I;#L=!1;#R=Date.now();#z=!1;#B=new TurnClock;#V=EMPTY_LINE;#H=!1;#U={kind:`idle`};#W;#G=STATUS.processing;#K;#q=`eve`;#J=!1;#Y=!1;#X=!1;#Z=!1;#Q=!1;#$=!1;#ee;#te=!0;#ne=0;#re=Date.now();#ie;#ae;#oe;#se=!1;#ce;#le=``;#ue=new StringDecoder(`utf8`);#de;#fe;#pe;#me=!1;#he=!1;#ge;#_e;#ve;#ye;#be;#xe;#Se;#Ce=``;#we=``;#Te;#Ee;#De=0;#Oe;#ke;#Ae;#je;#Me;#Ne;#Pe=new MessageQueue;#Fe;#Ie=!1;#Le;#Re;#ze=!1;#Be;#Ve;#He;#Ue;#We;setupFlow={begin:(e,t)=>this.#Xe(e,t),end:e=>this.#Ze(e?.preserveDiagnostics??!0),readSelect:e=>this.#Qe(e),readEditableSelect:e=>this.#et(e),readProviderPicker:e=>this.#tt(e),readModelEditor:e=>this.#nt(e),readText:e=>this.#rt(e),readAcknowledge:e=>this.#it(e),readChoice:e=>this.#$e(e),setStatus:e=>this.#ft(e),renderLine:(e,t)=>this.#pt(e,t),replaceContent:e=>this.#mt(e),renderOutput:e=>this.#ht(e),withInheritedStdio:e=>this.#gt(e),withExclusiveTerminal:e=>this.#gt(e),waitForInterrupt:e=>this.#lt(e)};traceViewer={open:e=>this.#vt(e)};constructor(t){this.#e=t?.input??process.stdin,this.#t=t?.output??process.stdout,this.#n=new LiveRegion(this.#t),this.#r=new AltScreen(this.#t),this.#i=createTheme({color:t?.color??!0,unicode:t?.unicode??detectUnicode()}),this.#a=t?.tools??`auto-collapsed`,this.#o=t?.reasoning??`auto-collapsed`,this.#s=t?.subagents??`auto-collapsed`,this.#c=t?.connectionAuth??`full`,this.#l=t?.assistantResponseStats??`tokensPerSecond`,this.#ve=t?.contextSize,this.#u=t?.captureForeignOutput??this.#t===process.stdout,this.#d=t?.diagnostics,this.#ee=t?.onExitRequest,this.#p=t?.logs??`none`,this.#f=t?.availablePromptCommands??PROMPT_COMMANDS}renderAgentHeader(e){this.#q=e.name,this.#w=e,this.#xt();let t=this.#un().join(`
2
+ `);if(this.#T){t!==this.#E&&(this.#E=t,this.#Rt({kind:`agent-header`,body:t,live:!1})),this.#an();return}this.#T=!0,this.#E=t,this.#n.flush(this.#un(),[])}async readPrompt(e){this.#xt(e),this.#Lt(),this.#Bt(),this.#F=!0,this.#L=!0,this.#U={kind:`idle`},this.#G=``,this.#$=!1;let r=this.#Pe.restoreDraft()?.split(`
3
3
  `).map(stripPromptControlCharacters).join(`
4
- `),i=stripPromptControlCharacters(e?.initialDraft??this.#V.text),a=lineOf(r===void 0?i:i.length===0?r:`${r}\n\n${i}`);return this.#V=EMPTY_LINE,this.#P.begin(a.text),this.#Ge(a),this.#I=typeaheadFor(this.#f,a.text),this.#jt(),this.#in(),await new Promise((e,r)=>{this.#W=r;let apply=e=>{a=e,this.#Nt(),this.#Ge(a),this.#I=typeaheadFor(this.#f,e.text,this.#I),this.#in()},recall=e=>{e!==void 0&&apply(lineOf(e))},interrupt=()=>{this.#I=void 0,this.#Mt(),this.#St(),r(interruptedError())},suggestions=()=>this.#I!==void 0&&isTypeaheadOpen(this.#I)?this.#I:void 0,highlighted=()=>{let e=suggestions();return e===void 0?void 0:selectedTypeaheadCommand(e)};this.#ce=r=>{r.type!==`ctrl-c`&&this.#$&&(this.#$=!1,this.#in());let i=applyLineEditorKey(a,r,{multiline:!0});if(i!==void 0){apply(i);return}switch(r.type){case`up`:case`ctrl-p`:{let e=suggestions();if(e!==void 0){this.#I=moveTypeaheadSelection(e,-1),this.#in();break}let t=movePromptLine(a,`up`);t===void 0?recall(this.#P.previous(a.text)):apply(t);break}case`down`:case`ctrl-n`:{let e=suggestions();if(e!==void 0){this.#I=moveTypeaheadSelection(e,1),this.#in();break}let t=movePromptLine(a,`down`);t===void 0?recall(this.#P.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.#I=dismissTypeahead(e),this.#in());break}case`enter`:{let r=highlighted(),i=r!==void 0&&parsePromptCommand(a.text)===null?typeaheadCompletion(r).trimEnd():a.text;if(i.trim().length===0)break;this.#I=void 0,this.#P.add(i),this.#F=!1,this.#Mt(),this.#G=STATUS.processing,isPromptControlCommand(i)?this.#Lt({kind:`command`,body:stripTerminalControls(i.trim()),live:!1}):(this.#Ft(),this.#Rt(i),this.#Oe=i,this.#B.arm()),this.#Ge(EMPTY_LINE),this.#in(),this.#wt(),e(i);break}case`ctrl-d`:a.text.length===0?(this.#gt(),interrupt()):apply(deleteForward(a));break;case`ctrl-l`:this.#sn();break;case`ctrl-r`:this.#in();break;case`ctrl-c`:if(this.#$){this.#gt(),interrupt();break}this.#$=!0,apply(EMPTY_LINE);break;default:break}},this.#Ct()})}#Ge(e){this.#M=e.text,this.#N=e.cursor}takeQueuedPrompt(){let e=this.#Pe.view().steering,t=this.#Pe.takePrompt();return t!==void 0&&(this.#Re=e?`steer`:`queue`),t}async renderStream(e,t){this.#bt(t),this.#g.clear(),this.#F=!1,this.#U.kind!==`waiting`&&(this.#U={kind:`waiting`,startedAtMs:Date.now()}),this.#G=this.#k>0?STATUS.connectionAuth:STATUS.processing,this.#Bt(t?.submittedPrompt),t?.submittedPrompt!==void 0&&this.#d?.recordPrompt(),t?.submittedPrompt!==void 0&&!this.#B.armed&&this.#B.arm(),this.#Z=!1,this.#Ie=!1,this.#ze=!1,this.#Be=t?.submittedPrompt,this.#Pe.beginTurn(),this.#Fe=e.cancel,this.#ge=void 0,this.#_e=void 0,this.#ye=void 0,this.#be=void 0,this.#xe=Date.now();let n={tools:t?.tools??this.#a,reasoning:t?.reasoning??this.#o,assistantResponseStats:t?.assistantResponseStats??this.#l};this.#Pt(),this.#H=!0,this.#in();let r=new Promise(e=>{this.#pe=e});this.#ce=e=>this.#At(e),this.#Ct();let i={text:new Map,reasoning:new Map,tools:new Map};try{for await(let t of takeUntil(iterateTUIStream(e.events),r)){if(this.#Z)break;this.#Kt(t,n,i)}}catch(e){let t=summarizeKnownError(e);t===null?this.#Vt(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#Vt(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#pe=void 0,this.#Z&&e.abort?.(),this.#Fe=void 0,this.#wt(),this.#It(),this.#H=!1,this.#U.kind===`waiting`&&(this.#U={kind:`idle`}),this.#G=completedTurnStatus({interrupted:this.#Z,cancelled:this.#Ie,continueSession:t?.continueSession===!0}),this.#$t(i),(this.#Z||this.#Ie)&&this.#Qt(),this.#Gt(),this.#d?.reportStats(),this.#in(),t?.continueSession||this.#St()}}async readToolApproval(e,t){return this.#bt(t),this.#It(),this.#F=!1,this.#U={kind:`idle`},this.#G=`Approve ${formatToolApprovalTitle(e)}? (y/n)`,this.#Z=!1,this.#in(),await new Promise((t,n)=>{this.#W=n,this.#ce=r=>{switch(r.type){case`text`:{if(r.framing!==`unframed`)break;let n=r.value.toLowerCase();n===`y`?(this.#Ft(),this.#G=STATUS.processing,this.#wt(),this.#in(),t({approved:!0})):n===`n`&&(this.#Ft(),this.#G=STATUS.processing,this.#qe(e.toolCallId),this.#wt(),this.#in(),t({approved:!1,reason:`Denied by user.`}));break}case`ctrl-r`:this.#in();break;case`ctrl-c`:this.#Z=!0,this.#St(),n(interruptedError());break;default:break}},this.#Ct()})}async readInputQuestion(e,t){this.#bt(t),this.#It(),this.#F=!1,this.#L=!1,this.#U={kind:`idle`},this.#Z=!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.#te},this.#i,t),renderTextSection=()=>{this.#Ut({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:formatQuestionContent(e,void 0,this.#i),preformatted:!0,live:!0})},syncFreeformCaret=()=>{isOnFreeformRow()?this.#jt():(this.#Mt(),this.#Nt())};s===`overlay`?(s=`overlay`,this.#F=!1,this.#Wt(o),this.#ke=overlayPanel,this.#G=``,syncFreeformCaret(),this.#in()):(s=`text`,this.#ke=void 0,renderTextSection(),this.#F=!0,this.#Ge(l),this.#G=``,this.#jt(),this.#in());let finalize=t=>{this.#ke=void 0,this.#Ut({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#i.colors.dim(this.#i.glyph.elbow)} ${stripTerminalControls(t.label)}`,preformatted:!0,live:!1}),this.#F=!1,this.#Ft(),this.#G=STATUS.processing,this.#Mt(),this.#wt(),this.#in();let n={};return t.optionId!==void 0&&(n.optionId=t.optionId),t.text!==void 0&&(n.text=t.text),n},dismiss=()=>{this.#ke=void 0,this.#Ut({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#i.colors.dim(this.#i.glyph.elbow)} ${this.#i.colors.dim(`Dismissed.`)}`,preformatted:!0,live:!1}),this.#F=!1,this.#G=``,this.#Mt(),this.#wt(),this.#in(),u(void 0)},moveCursor=e=>{a!==0&&(c=(c+e+a)%a,syncFreeformCaret(),this.#in())},selectOptionAt=e=>{let t=n[e];t&&u(finalize({optionId:t.id,label:t.label}))},u;return await new Promise((t,r)=>{this.#W=r,u=t,this.#ce=t=>{if(t.type===`ctrl-c`){if((s===`text`||isOnFreeformRow())&&l.text.length>0){l=EMPTY_LINE,this.#Nt(),s===`text`&&this.#Ge(l),this.#in();return}this.#Z=!0,this.#ke=void 0,this.#Mt(),this.#St(),r(interruptedError());return}if(t.type===`ctrl-r`){this.#in();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.#Nt(),this.#in();break}dismiss();break;default:if(isOnFreeformRow()){let e=applyLineEditorKey(l,t);e!==void 0&&(l=e,this.#Nt(),this.#in());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.#in())}break}return}let a=applyLineEditorKey(l,t,{multiline:!0});if(a!==void 0){l=a,this.#Nt(),this.#Ge(l),this.#in();return}switch(t.type){case`up`:case`down`:{let e=movePromptLine(l,t.type);e!==void 0&&(l=e,this.#Nt(),this.#Ge(l),this.#in());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.#Nt(),this.#Ge(l),this.#in();break}dismiss();break;default:break}},this.#Ct()})}upsertSubagentStep(e){if(this.#d?.recordSubagentDispatch(e.callId),this.#s===`hidden`)return;let t=stripTerminalControls(e.reasoning??``).trim(),n=stripTerminalControls(e.message??``).trim();if(!(t.length===0&&n.length===0)){if(this.#Ht(e.callId,e.subagentName),this.#s===`collapsed`){this.#in();return}this.#Ut({id:subagentStepSectionId(e.callId,e.sectionKey),kind:`subagent-step`,subagentCallId:e.callId,depth:1,reasoning:t,body:n,collapsed:this.#s!==`full`,live:!e.finalized}),this.#in()}}upsertSubagentTool(e){if(this.#d?.recordSubagentDispatch(e.callId),e.status===`failed`&&e.errorText!==void 0&&this.#d?.append({source:`tool`,summary:`${e.toolName} failed (subagent ${e.subagentName})`,detail:e.errorText}),this.#s===`hidden`)return;if(this.#Ht(e.callId,e.subagentName),this.#s===`collapsed`){this.#in();return}let t=subagentToolStatus(e.status),n=e.status===`preparing`?presentPreparingTool(e.toolName):presentTool(e.toolName,e.input,this.#Xt({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.#s===`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.#Ut(r),this.#Ke(e.callId),this.#in()}#Ke(e){applyCohortLiveness(this.#m.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.#in()}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.#s===`hidden`)return;this.#Ht(e.callId,e.name);let t=this.#h.get(subagentHeaderId(e.callId));t?.status===`done`&&delete t.status,this.#in()}completeSubagent(e){let t=this.#h.get(subagentHeaderId(e.callId));t!==void 0&&(t.status=`done`,this.#in())}markChildToolCallId(e){this.#v.add(e);let t=this.#y.get(e);t!==void 0&&(this.#Wt(t),this.#y.delete(e),this.#in())}#qe(e){let t=this.#h.get(toolSectionId(e));t!==void 0&&(t.status=`denied`,t.live=!1)}upsertConnectionAuth(e){if(this.#c===`hidden`)return;let t=connectionAuthTerminalMessage(e.state);this.#Ut({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.#in()}setConnectionAuthPendingCount(e){let t=Math.max(0,e);if(t===this.#k)return;let n=this.#k>0;this.#k=t,t>0?(this.#G=STATUS.connectionAuth,this.#in()):n&&(this.#G=STATUS.processing,this.#in())}setVercelStatus(e){this.#A=e,this.#in()}setRemoteConnectionStatus(e){this.#j=e,this.#in()}reset(){this.#m=[],this.#h.clear(),this.#g.clear(),this.#O=void 0,this.#D.length=0,this.#_.length=0,this.#T=!1,this.#E=void 0,this.#Je(),this.#z=!1,this.#Oe=void 0,this.#Ee=void 0,this.#k=0,this.#ge=void 0,this.#_e=void 0,this.#ye=void 0,this.#be=void 0,this.#xe=void 0,this.#J&&(this.#n.clearAll(),this.#in())}renderSessionBoundary(){this.#zt(),this.#Je();let e=this.#i.colors,t=this.#i.glyph,n=e.dim(`${t.cornerOpen}${t.dash.repeat(2)} Session restarted, clear context.`);this.#Lt({kind:`session-boundary`,body:n,live:!1}),this.#in()}#Je(){this.#v.clear(),this.#y.clear(),this.#C.clear(),this.#x.clear(),this.#Me=void 0,this.#Ne=void 0,this.#Pe.reset(),this.#Re=void 0,this.#S.clear(),this.#B.reset()}renderNotice(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#bt(),this.#Lt({kind:`notice`,body:t,live:!1}),this.#in())}renderSandboxLog(e){let t=parseSandboxLogLine(stripTerminalControls(e));t!==void 0&&(this.#d?.append({source:`sandbox`,detail:t}),this.#bt(),this.#Lt({kind:`sandbox`,body:t,live:!1}),this.#in())}renderSetupWarning(e){let t=stripTerminalControls(e);if(t.trim().length===0){this.#Ye();return}this.#bt(),this.#je=t,this.#in()}clearSetupWarning(){this.#Ye()}#Ye(){this.#je!==void 0&&(this.#je=void 0,this.#in())}renderCommandInvocation(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;this.#bt();let r={kind:`command`,body:n,live:!1};t===`failed`&&(r.status=`error`),this.#Lt(r),this.#in()}renderCommandResult(e,t){let n=stripTerminalControls(e);n.trim().length!==0&&(this.#bt(),this.#Lt(t===`success`?{kind:`result`,body:n,live:!1,status:`done`}:t===`error`?{kind:`flow`,title:t,body:n,live:!1}:{kind:`result`,body:n,live:!1}),this.#in())}#Xe(e,t=`spinner`){this.#bt(),this.#F=!1,this.#U={kind:`idle`},this.#G=``;let n=t===`pulse`?{kind:`pulse`,startedAtMs:Date.now()}:{kind:`spinner`};this.#Ae={title:stripTerminalControls(e),indicator:n,lines:[],outputBuffer:[]},this.#Pt(),this.#in()}#Ze(e){this.#Ve=void 0,this.#dt();let t=this.#Ae;if(t!==void 0){if(this.#Ae=void 0,this.#It(),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.#Lt({kind:`flow`,title:`info`,body:e.join(`
5
- `),live:!1}),this.#Lt({kind:`flow`,title:n.tone,body:n.text,live:!1})),e=[]}}this.#in()}}async#Qe(e){let t=this.#at(),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.#in()},loadSearch=async(e,t)=>{c=!0,s=void 0;let a=++l;this.#in();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.#in())}},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.#dn()),t};return t.question=e=>renderSelectQuestion(panelState(),this.#i,e),this.#in(),await this.#ct((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.#in();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.#in();return;case`update`:o=d.select,s=void 0,this.#in();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.#in();return;case`ignore`:return}}).promise}#$e(e){this.#bt();let t=this.#ot();t.status={kind:`progress`,text:stripTerminalControls(e.status),startedAtMs:Date.now()};let n;t.question=t=>renderSelectQuestion({kind:`actions`,context:e.context,actions:e.actions,cursor:n},this.#i,t),this.#in();let r=this.#ct((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.#in();return;case`repaint`:this.#in();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#et(e){let t=this.#at(),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.#te,editor:{kind:`rename`,editor:i,defaultValue:e.editable.defaultValue,formatHint:e.editable.formatHint}}};return a!==void 0&&(n.error=a),renderSelectQuestion(n,this.#i,t)};let onEditableRow=()=>selectValueAtCursor([...e.options],r.cursor)===e.editable.value,syncEditableRow=()=>{onEditableRow()?this.#jt():(i=lineOf(``),this.#Mt())};return syncEditableRow(),this.#in(),await this.#ct((t,n)=>{let applyEditor=e=>{i=e,a=void 0,this.#Nt(),this.#in()},applySelect=t=>{r=reduceSelect(r,t,{options:e.options}),a=void 0,syncEditableRow(),this.#in()},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.#in();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.#in();return;case void 0:break}if(!onEditableRow())return;let s=applyLineEditorKey(i,t);s!==void 0&&applyEditor(s)},()=>this.#Mt()).promise}async#tt(e){let t=this.#at(),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.#i,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.#te,editor:{kind:`key`,phase:n.phase}}};return r!==void 0&&(i.cursorBadge=r),renderSelectQuestion(i,this.#i,t)};let syncCaret=()=>{n.phase.kind===`editing`||n.phase.kind===`invalid`?this.#jt():this.#Mt()};return syncCaret(),this.#in(),await this.#ct((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.#in();return;case`cancel`:i(void 0);return;case`render`:n=o.state,syncCaret(),this.#in();return;case`validate`:{n=o.state,syncCaret(),this.#in();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.#in();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.#Nt(),dispatch({type:`edit`,editor:s}))},()=>{r?.abort(),r=void 0,this.#Mt()}).promise}async#nt(e){let t=this.#at(),n=initialModelEditorState(e);return t.question=t=>renderModelEditorQuestion({request:e,state:n},this.#i,t),this.#in(),await this.#ct((t,r)=>{let dispatch=t=>{let i=transitionModelEditor(n,t,e);switch(i.kind){case`ignore`:return;case`render`:n=i.state,this.#in();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.#in();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(`
6
- `,` `))e>=` `&&e!==``&&dispatch({type:`char`,char:e})}).promise}async#rt(e){let t=this.#at(),n=lineOf(``),r;return t.question=t=>{let i={message:e.message,editor:n,mask:e.mask===!0};return e.placeholder===void 0?e.defaultValue!==void 0&&(i.placeholder=e.defaultValue):i.placeholder=e.placeholder,e.notices!==void 0&&(i.notices=e.notices),r!==void 0&&(i.error=r),renderTextQuestion(i,this.#i,t,this.#te)},this.#jt(),this.#in(),await this.#ct((t,i)=>{let apply=e=>{n=e,r=void 0,this.#Nt(),this.#in()},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.#in();return;case`enter`:{let t=n.text.length>0?n.text:e.defaultValue??``,a=e.validate?.(t);if(a!==void 0){r=a,this.#in();return}i(t);return}default:return}},()=>this.#Mt()).promise}async#it(e){let t=this.#at();return t.question=t=>renderAcknowledgeQuestion({message:e.message,lines:e.lines},this.#i,t),this.#in(),await this.#ct((e,t)=>{switch(e.type){case`enter`:case`escape`:case`ctrl-c`:t();return;case`ctrl-r`:this.#in();return;default:return}}).promise}#at(){return this.#bt(),this.#F=!1,this.#U={kind:`idle`},this.#G=``,this.#ot()}#ot(){return this.#Ae===void 0&&(this.#Ae={title:``,indicator:{kind:`spinner`},lines:[],outputBuffer:[],implicit:!0}),this.#Ae}#st(){this.#Ae?.implicit===!0?this.#Ae=void 0:this.#Ae!==void 0&&(this.#Ae.question=void 0,this.#Ae.hideLinesWhileQuestion=!1),this.#ce=void 0,this.#wt(),this.#Ae!==void 0&&this.#ut(),this.#in()}#ct(e,t){let n=!1,r,i,a=new Promise((e,t)=>{r=e,i=t}),settle=e=>{n||(n=!0,t?.(),this.#st(),r(e))},reject=e=>{n||(n=!0,t?.(),this.#st(),i(e))};return this.#kt(),this.#ce=t=>{t.type===`ctrl-c`&&this.#gt(),e(t,settle,reject)},this.#Ct(),{promise:a,settle}}#lt(e){let t,n=new Promise(e=>{t=e});return this.#Ve=t,this.#ut(e?.interruptible??!0),{promise:n,dispose:()=>{this.#Ve===t&&(this.#Ve=void 0,this.#dt())}}}#ut(e=!0){if(this.#Ve===void 0)return;let consumer=t=>{if(e&&(t.type===`ctrl-c`||t.type===`escape`)){t.type===`ctrl-c`&&this.#gt();let e=this.#Ve;this.#Ve=void 0,this.#dt(),e?.();return}t.type===`ctrl-r`&&this.#in()};this.#He=consumer,this.#kt(),this.#ce=consumer,this.#Ct()}#dt(){this.#He!==void 0&&(this.#ce===this.#He&&this.#wt(),this.#He=void 0)}#ft(e){let t=e===void 0?void 0:typeof e==`string`?{kind:`progress`,text:stripTerminalControls(e),startedAtMs:Date.now()}:{kind:`external-action`,text:stripTerminalControls(e.text),emphasis:stripTerminalControls(e.emphasis),startedAtMs:Date.now()};if(this.#Ae!==void 0){this.#Ae.status=t,t===void 0&&(this.#Ae.preview=void 0),this.#in();return}if(!(this.#F||this.#H)){if(t===void 0){this.#U={kind:`idle`},this.#K=void 0,this.#It(),this.#in();return}this.#bt(),this.#Ft(),this.#K=t.text,this.#in()}}#pt(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;let r=this.#Ae;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.#in();return}this.#bt(),this.#Lt({kind:`flow`,title:t,body:n,live:!1}),this.#in()}#mt(e){let t=stripTerminalControls(e);if(t.trim().length===0)return;let n=this.#Ae;if(n===void 0){this.#pt(t,`info`);return}n.preview=t,n.outputBuffer.push(t),n.outputBuffer.length>40&&n.outputBuffer.shift(),this.#in()}async#ht(e){this.#le=``,this.#kt(),this.#Ve=void 0,this.#dt(),this.#wt(),this.#It(),this.#n.clear(),this.#n.showCursor(),this.#En(),this.#e.isTTY&&this.#e.setRawMode?.(!1),this.#e.pause();try{return await e()}finally{this.#e.isTTY&&this.#e.setRawMode?.(!0),this.#e.resume(),this.#le=``,this.#kt(),this.#n.hideCursor(),this.#Tn(),this.#Ae!==void 0&&(this.#Pt(),this.#ut()),this.#n.reset(),this.#in()}}setSessionId(e){this.#Le=e}shutdown(){if(this.#St(),this.#Y&&!this.#X){this.#X=!0;let e=this.#Le===void 0?``:` ${this.#i.glyph.dot} session ${this.#Le}`;this.#t.write(`${this.#i.colors.dim(`${eveVersionTag()}${e}`)}\n`)}}requestInterrupt(){this.#Z=!0,this.#Ae!==void 0&&this.#ce?.({type:`ctrl-c`}),this.#pe?.(),this.#St()}exitRequested(){return this.#Q}#gt(){this.#Q=!0,this.#ee?.()}async#_t(e){if(this.#Ue!==void 0||!this.#J)return;let t=new TraceViewerSession({...e,theme:this.#i,dimensions:()=>({width:this.#Cn(),height:this.#wn()}),paint:e=>this.#r.paint(e,this.#wn()),tracingDisabled:process.env.EVE_TRACES===`off`,copyText:e=>copyTextToClipboard(e,e=>this.#r.writeRaw(e)),terminalBackground:this.#We});this.#Ue=t,this.#r.enter(),this.#i.color&&this.#r.writeRaw(BACKGROUND_COLOR_QUERY),await new Promise(e=>{this.#yt=e,this.#ce=e=>{t.handleKey(e)===`close`&&this.#vt()},this.#Ct(),t.start()})}#vt(){let e=this.#Ue;if(e===void 0)return;this.#Ue=void 0,e.dispose(),this.#wt(),this.#r.exit(),this.#n.hideCursor(),this.#in(),this.#n.showCursor();let t=this.#yt;this.#yt=void 0,t?.()}#yt;#bt(e){this.#q=e?.title??this.#q,e?.contextSize!==void 0&&(this.#ve=e.contextSize),!this.#J&&(this.#J=!0,this.#Y=!0,this.#n.reset(),this.#n.hideCursor(),this.#Tn(),this.#e.isTTY&&(this.#e.setRawMode?.(!0),this.#e.resume(),this.#n.emitBracketedPaste(!0)),this.#fe=()=>this.#in(),this.#t.on(`resize`,this.#fe),process.on(`exit`,this.#xt))}#xt=()=>{this.#J&&(this.#r.exit(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1)),this.#n.showCursor())};#St(){this.#vt();let e=this.#W;if(this.#W=void 0,e?.(interruptedError()),this.#wt(),this.#Mt(),this.#It(),this.#oe!==void 0&&(clearTimeout(this.#oe),this.#oe=void 0),this.#se=!1,this.#J){this.#Pn();for(let e of this.#m)e.kind===`log`&&e.id===void 0&&(e.live=!1);this.#in(),this.#n.clear(),this.#n.showCursor(),this.#En(),this.#n.newline(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1),this.#e.pause()),this.#fe&&=(this.#t.off(`resize`,this.#fe),void 0),process.off(`exit`,this.#xt),this.#J=!1}}#Ct(){this.#e.off(`data`,this.#Tt),this.#e.on(`data`,this.#Tt),this.#le.length>0&&queueMicrotask(()=>{this.#ce!==void 0&&this.#le.length>0&&(this.#Dt(),this.#Et())})}#wt(){this.#e.off(`data`,this.#Tt),this.#kt(),this.#ce=void 0}#Tt=e=>{this.#kt(),this.#le+=this.#ue.write(e),this.#Dt(),this.#Et()};#Et(){if(this.#le===`\x1B`){this.#de=setTimeout(()=>{this.#le===`\x1B`&&(this.#le=``,this.#ce?.({type:`escape`}))},30),this.#de.unref?.();return}if(isIncompletePaste(this.#le)){let e=this.#le;this.#de=setTimeout(()=>{if(this.#le!==e)return;let t=sanitizePastedText(stripPasteStart(e));this.#le=``,t.length>0&&this.#ce?.({type:`text`,value:t,framing:`bracketed-paste`})},incompletePasteFlushMs),this.#de.unref?.();return}if(isIncompleteOsc(this.#le)){let e=this.#le;this.#de=setTimeout(()=>{this.#le===e&&(this.#le=``)},incompletePasteFlushMs),this.#de.unref?.()}}#Dt(){for(;this.#le.length>0;){let e=nextKey(this.#le);if(e.incomplete)return;if(this.#le=this.#le.slice(e.consumed),!(e.key===void 0||e.key.type===`ignore`)){if(e.key.type===`osc`){this.#Ot(e.key.value);continue}this.#ce?.(e.key)}}}#Ot(e){let t=parseBackgroundColorReply(e);t!==void 0&&(this.#We=t,this.#Ue?.setTerminalBackground(t))}#kt(){this.#de&&=(clearTimeout(this.#de),void 0)}#At(e){switch(e.type){case`ctrl-l`:case`ctrl-r`:this.#in();break;case`enter`:{let e=this.#V.text;if(e.trim().length===0)break;if(parsePromptCommand(e)?.type===`cancel`&&this.#Fe!==void 0){this.#V=EMPTY_LINE,this.#Pe.requestCancellation(),this.#ze=!0,this.renderCommandInvocation(e.trim()),this.renderCommandResult(`Turn cancellation requested.`),this.#Fe(),this.#in();break}this.#Pe.enqueue(e)&&(this.#V=EMPTY_LINE),this.#in();break}case`ctrl-c`:case`escape`:if(this.#Pe.idle&&this.#Fe===void 0)break;this.#Pe.handleEscape(),this.#ze=!0,this.#Fe?.(),this.#in();break;default:{let t=applyLineEditorKey(this.#V,e,{multiline:!0});t!==void 0&&(this.#V=t,this.#in());break}}}#jt(){this.#Mt(),this.#Nt(),this.#ie=setInterval(()=>{this.#te=!this.#te,this.#in()},500),this.#ie.unref?.()}#Mt(){this.#ie&&=(clearInterval(this.#ie),void 0),this.#te=!0}#Nt(){this.#te=!0}#Pt(){this.#It(),this.#ae=setInterval(()=>{this.#ne+=1,this.#in()},90),this.#ae.unref?.()}#Ft(){let e=Date.now();this.#re=e,this.#U={kind:`waiting`,startedAtMs:e},this.#Pt()}#It(){this.#ae&&=(clearInterval(this.#ae),void 0)}#Lt(e){e.id!==this.#Ee?.id&&this.#Pn(),e.updateSeq=++this.#b,this.#m.push(e),e.id&&this.#h.set(e.id,e)}#Rt(e){this.#z=!0,this.#Lt({kind:`user`,body:stripTerminalControls(e),live:!1}),this.#in()}#zt(){let e=this.#B.settle();if(e===void 0||e.elapsedMs<=1e4&&e.inputTokens<=2e4)return;let t=`Done in ${this.#gn(e.elapsedMs)}`,n=this.#_e??0;if(this.#ve!==void 0&&this.#ve>0&&n>0){let e=Math.round(n/this.#ve*100);t+=` ${this.#i.glyph.dot} ${e}% context`}this.#Lt({kind:`turn-stats`,body:t,live:!1})}#Bt(e){if(e==null)return;let t=this.#Re;if(this.#Re=void 0,this.#Oe===e){this.#Oe=void 0;return}let n={kind:`user`,body:stripTerminalControls(e),live:!1};t!==void 0&&(n.promptOrigin=t),this.#Lt(n)}#Vt(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.#d?.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.#d===void 0?a:`details: ${this.#d.displayPath}`),this.#Lt(c),this.#in()}#Ht(e,t){if(this.#C.has(e))return;this.#C.add(e);let n=stripTerminalControls(t),r=this.#x.get(n)??[];if(r.push(e),this.#x.set(n,r),r.length===2){let e=this.#h.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.#Lt(i)}#Ut(e){if(e.id&&this.#g.has(e.id))return;let t=e.id?this.#h.get(e.id):void 0;if(t){Object.assign(t,e),t.updateSeq=++this.#b;return}this.#Lt(e)}#Wt(e){this.#m=this.#m.filter(t=>t.id!==e),this.#h.delete(e)}#Gt(){for(let e of this.#m)e.status===`approval`||e.status===`running`||e.kind===`connection-auth`&&e.live||(e.live=!1)}#Kt(e,t,n){switch(e.type){case`step-finish`:this.#d?.recordStepUsage(e.usage),e.usage!==void 0&&this.#B.addUsage(e.usage),this.#$t(n),this.#rn(e.usage),this.#in();break;case`assistant-delta`:{let t=(n.text.get(e.id)??``)+stripTerminalControls(e.delta);n.text.set(e.id,t),this.#qt(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.#qt(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.#Jt(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.#Jt(e.id,r,!1,t);break}break}case`tool-call-preparing`:if(t.tools===`hidden`||isPanelRoutedTool(e.toolName))break;this.#Yt({input:void 0,preparing:!0,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-call`:if(this.#d?.recordToolCall(e.toolName),t.tools===`hidden`)break;this.#Yt({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.#Yt({...r,status:`approval`},t,n);break}case`tool-result`:{if(t.tools===`hidden`)break;let r=this.#nn(e.toolCallId,n);if(r===void 0)break;this.#Yt({...r,output:e.output,status:`done`},t,n);break}case`tool-error`:{let r=this.#nn(e.toolCallId,n);if(this.#d?.append({source:`tool`,summary:`${r?.toolName??e.toolCallId} failed`,detail:e.errorText}),t.tools===`hidden`||r===void 0)break;this.#Yt({...r,errorText:e.errorText,status:`error`},t,n);break}case`tool-rejected`:{if(t.tools===`hidden`)break;let r=this.#nn(e.toolCallId,n);if(r===void 0)break;this.#Yt({...r,errorText:e.reason,status:`denied`},t,n);break}case`error`:this.#Vt(`Error`,e.errorText,{detail:e.detail,hint:e.hint});break;case`turn-cancelled`:this.#Ie=!0,!this.#ze&&this.#Be!==void 0&&this.#V.text.length===0&&(this.#V=lineOf(this.#Be),this.renderNotice(`The turn was cancelled from outside this prompt — the message was restored to the input.`));break;case`finish`:this.#rn(e.usage),this.#in();break}}#qt(e,t,n){let r=stripTerminalControls(t).trim();r.length!==0&&(this.#Ut({id:e,kind:`assistant`,body:r,live:n}),this.#in())}#Jt(e,t,n,r){let i=stripTerminalControls(t).trim();i.length!==0&&(this.#Ut({id:e,kind:`reasoning`,body:i,collapsed:collapseReasoning(r.reasoning,n),live:n}),this.#in())}#Yt(e,t,n){if(n.tools.set(e.toolCallId,e),this.#v.has(e.toolCallId)||this.#en(e)||toolBaseName(e.toolName)===`ask_question`)return;let r=toolSectionId(e.toolCallId);this.#y.set(e.toolCallId,r);let i=this.#Xt(e);this.#Ut(renderNativeToolBlock(e,r,t.tools===`full`,i)),this.#tn(n),this.#in()}#Xt(e){e.output!==void 0&&this.#S.observeRead(e.output);let t={};this.#Zt(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.#S.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}#Zt(e){let t=this.#w?.info?.subagents.local;if(t===void 0||t.length===0)return!1;let n=toolBaseName(e);return t.some(e=>e.name===n)}#Qt(){for(let e of this.#m)e.kind!==`tool`&&e.kind!==`subagent-tool`||e.status===`running`&&(e.status=`error`,e.result=`interrupted`,e.live=!1)}#$t(e){for(let[t,n]of e.tools){if(n.preparing!==!0)continue;e.tools.delete(t);let r=this.#y.get(t)??toolSectionId(t);this.#Wt(r),this.#y.delete(t)}}#en(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.#Ne!==e&&(this.#Ne=e,this.#Lt({kind:`todo-list`,body:renderFinishedTodoRows(t,this.#Cn(),this.#i).join(`
7
- `),live:!1})),this.#Me=void 0}else this.#Me=t.length>0?t:void 0,this.#Ne=void 0;return this.#in(),!0}#tn(e){let t=[];for(let n of e.tools.values()){if(this.#v.has(n.toolCallId))continue;let e=this.#y.get(n.toolCallId)??toolSectionId(n.toolCallId),r=this.#h.get(e);r?.kind===`tool`&&t.push({block:r,active:isActiveToolStatus(n.status)})}applyCohortLiveness(t)}#nn(e,t){let n=t.tools.get(e);if(n!==void 0)return n;let r=this.#y.get(e)??toolSectionId(e),i=this.#h.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`}}#rn(e){if(e===void 0)return;let{inputTokens:t,outputTokens:n}=e;if((t!=null||n!=null)&&(this.#ge=(t??0)+(n??0)),this.#_e=t??this.#_e,this.#ye=n??this.#ye,this.#ye!=null&&this.#xe!==void 0){let e=(Date.now()-this.#xe)/1e3;e>0&&(this.#be=this.#ye/e)}}#in(){if(this.#J){if(this.#me){this.#he=!0;return}this.#me=!0;try{do this.#he=!1,this.#an();while(this.#he)}finally{this.#me=!1}}}#an(){if(!this.#J)return;if(this.#Ue!==void 0){this.#Ue.repaint();return}let e=this.#Cn(),t=this.#mn(e),n=Math.max(1,this.#wn()-t.length),r=[],i=this.#O,a=groupToolBlocksForDisplay(this.#m),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.#m.length-1;t>=0;--t)e.has(this.#m[t])&&this.#m.splice(t,1)}for(let t of a.slice(0,o)){for(let e of t.members)this.#_.push(e),e.id&&(this.#g.add(e.id),this.#h.delete(e.id));if(this.#In(t.display))continue;let n=this.#un(t.display,e,i);i=previousBlockOf(t.display),this.#O=i,r.push(...n),this.#D.push(...n)}let s=[];for(let{display:t}of a.slice(o)){if(this.#In(t))continue;let n=this.#un(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.#i),...t];r.length>0?this.#n.flush(r,c):this.#n.update(c)}#on(){if(!this.#J)return;let e=this.#Cn(),t=this.#mn(e),n=Math.max(1,this.#wn()-t.length),r=this.#O,i=[];for(let{display:t}of groupToolBlocksForDisplay(this.#m)){if(this.#In(t))continue;let n=this.#un(t,e,r);r=previousBlockOf(t),i.push(...n)}let a=[...clipLiveRows(i,n,e,this.#i),...t];this.#n.clearAll(),this.#n.flush([...this.#ln(),...this.#D],a)}logDisplayMode(){return this.#p}setLogDisplayMode(e){e!==this.#p&&(this.#p=e,e===`all`&&this.flushDelayedDevBuildErrors(),this.#cn(),this.#J&&this.#on())}flushDelayedDevBuildErrors(){let e=this.#Te;e!==void 0&&(this.#Te=void 0,this.#Lt({kind:`log`,title:`stderr`,body:e,live:!0}),this.#in())}#sn(){this.#se=!0,this.#oe!==void 0&&clearTimeout(this.#oe),this.#oe=setTimeout(()=>{this.#se=!1,this.#oe=void 0,this.#in()},5e3),this.setLogDisplayMode(nextLogDisplayMode(this.#p)),this.#in()}#cn(){let e=this.#Cn();this.#D.length=0;let t;for(let{display:n}of groupToolBlocksForDisplay(this.#_,{logCoalescing:`runs`})){if(this.#In(n))continue;let r=this.#un(n,e,t);t=previousBlockOf(n),this.#D.push(...r)}this.#O=t}#ln(){let e=this.#w;if(e===void 0)return[];let t={name:e.name,theme:this.#i,width:this.#Cn()};return e.info!==void 0&&(t.info=e.info),e.tip!==void 0&&(t.tip=e.tip),buildAgentHeader(t)}#un(e,t,n){let r={activityPulse:this.#fn(this.#re,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH)};n!==void 0&&(r.previous=n);let i=renderBlockLines(e,t,this.#i,r);return(e.depth??0)===0&&leadsWithGap(e,n)?[``,...i]:i}#dn(){return this.#i.spinner[this.#ne%this.#i.spinner.length]??``}#fn(e,t){return isProgressPulseVisible(Date.now()-e)?t:` `}#pn(e,t){return e.indicator.kind===`spinner`?{glyph:this.#dn(),color:`yellow`}:{glyph:this.#fn(e.indicator.startedAtMs,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH),color:t?.kind===`external-action`?`yellow`:`green`}}#mn(e){let n=this.#i.colors,r=[``];if(this.#ke!==void 0)return r.push(...this.#ke(e),``),this.#bn(r,e),r;let a=this.#Ae;if(a!==void 0){let t=this.#pn(a,a.status),n;if(a.status!==void 0){let{startedAtMs:e,...r}=a.status,i=Date.now()-e,o=i>=5e3?` ${formatTurnDuration(i)}`:``;n={...r,text:`${r.text}${o}`,indicator:t}}let 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.#i,e)),this.#xn(r,e),r}this.#je!==void 0&&r.push(...renderAttentionRows(this.#je,e,this.#i),``),this.#Me!==void 0&&r.push(...renderTodoPanelRows({items:this.#Me,width:e,theme:this.#i,working:this.#H||this.#U.kind===`waiting`,pulse:this.#fn(this.#re,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH)}),``);let o=renderMessageQueueRows({view:this.#Pe.view(),width:e,theme:this.#i,working:this.#H});if(o.length>0&&r.push(...o,``),this.#F){let i=this.#I===void 0?void 0:inlineCommandHint(this.#I);i===void 0&&this.#I!==void 0&&isTypeaheadOpen(this.#I)&&r.push(...renderCommandSuggestions(this.#I,this.#i,e)),this.#$&&r.push(clip(n.dim(`Press Ctrl+C again to exit`),e),``);let a=isPromptControlCommand(this.#M),o=i?n.dim(` ${i}`):``,s=[];this.#bn(s,e);let u=Math.max(1,this.#wn()-1-r.length-1-s.length),f={text:this.#M,cursor:this.#N,width:e,theme:this.#i,caretVisible:this.#te,isCommand:a,ghost:o,maxRows:u};return this.#L&&this.#M.length===0&&(f.placeholder=this.#z?``:promptPlaceholder(Date.now()-this.#R)),r.push(...promptInputRows(f)),r.push(...s),r}let s=this.#U.kind===`waiting`&&this.#K===void 0;if(this.#H||s){r.push(this.#hn(e)),this.#vn(r,e);let t=[];return this.#bn(t,e),!this.#H&&t.length>0&&r.push(``),r.push(...t),r}if(this.#V.text.length>0)return this.#yn(r,e,{inert:!1}),this.#bn(r,e),r;let u=this.#K??(this.#G.length>0?this.#G:`Ready`),f=this.#Sn(),p=n.dim(this.#i.glyph.dot),m=f?`${p} ${u} ${n.dim(this.#i.glyph.dot)} ${f}`:`${p} ${u}`;return r.push(clip(m,e)),this.#bn(r,e),r}#hn(e){let t=this.#i.colors,n=this.#fn(this.#re,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH),r=this.#U,i=this.#B.startedAtMs??this.#xe??(r.kind===`waiting`?r.startedAtMs:Date.now()),a=Date.now()-i,o=`${typewriterText(`Working for`,a,80)} ${this.#gn(a)}`;return clip(`${t.yellow(n)} ${t.dim(o)}`,e)}#gn(e){return`${formatTurnDuration(e)}${this.#_n()}`}#_n(){let{inputTokens:e,outputTokens:t}=this.#B.usage;return e===0&&t===0?``:` ${this.#i.glyph.dash.repeat(2)} ${formatTokenFlow({inputTokens:e,outputTokens:t},this.#i.glyph)}`}#vn(e,t){this.#H&&this.#yn(e,t,{inert:!0})}#yn(e,t,n){e.push(``);let r={text:this.#V.text,cursor:this.#V.cursor,width:t,theme:this.#i,caretVisible:!0,isCommand:!1,ghost:``,maxRows:4,inert:n.inert};n.inert&&this.#V.text.length===0&&(r.placeholder=``),e.push(...promptInputRows(r))}#bn(e,t){let n=this.#j===void 0?``:` `,r=Math.max(1,t-n.length),i={theme:this.#i,width:r};this.#se&&(i.logLevel=this.#p);let a=this.#w?.serverUrl;if(a!==void 0&&this.#j===void 0){let e=new URL(a).port;e.length>0&&(i.serverPort=e)}let o=this.#w?.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.#A!==void 0&&(i.vercel=this.#A),this.#j!==void 0&&(i.remote=this.#j);let c=buildStatusLine(i);c!==void 0&&e.push(clip(`${n}${c}`,t))}#xn(e,t){if(this.#j===void 0)return;let n=Math.max(1,t-2),r=buildStatusLine({remote:this.#j,theme:this.#i,width:n});r!==void 0&&e.push(``,clip(` ${r}`,t))}#Sn(){let e=this.#i.colors,t=[],n=formatAssistantResponseStats({totalTokens:this.#ge,outputTokens:this.#ye,tokensPerSecond:this.#be},this.#l);return n&&t.push(n),t.length>0?e.dim(t.join(` ${this.#i.glyph.dot} `)):``}#Cn(){return Math.max(20,this.#t.columns||80)}#wn(){return Math.max(8,this.#t.rows||24)}#Tn(){if(this.#Se!==void 0||!this.#u)return;this.#Ce=``,this.#we=``;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.#On(t,chunkToString(e,i)),a?.(),!0}),()=>{e.write=n}},e=capture(process.stdout,`stdout`),t=capture(process.stderr,`stderr`);this.#d?.subscribeLogRecords(e=>this.#Dn(e)),this.#Se=()=>{this.#d?.unsubscribeLogRecords(),e(),t()}}#En(){let e=this.#Se;e!==void 0&&(this.#Se=void 0,e(),this.#Ce.length>0&&(this.#d?.append({source:`stdout`,detail:this.#Ce}),this.#Fn(`stdout`)&&process.stdout.write(`${this.#Ce}\n`),this.#Ce=``),this.#we.length>0&&(this.#d?.append({source:`stderr`,detail:this.#we}),this.#Fn(`stderr`)&&process.stderr.write(`${this.#we}\n`),this.#we=``))}#Dn(e){let t=e.fields===void 0?``:` ${JSON.stringify(e.fields)}`;this.#An(`[eve:${e.namespace}] ${e.message}${t}`),this.#in()}#On(e,t){let n=(e===`stdout`?this.#Ce:this.#we)+t;if(e===`stdout`&&parseDevRebuildLogLine(n.trimEnd())!==void 0){this.#Ce=``,this.#d?.append({source:e,detail:n.trimEnd()}),this.#kn(n.trimEnd()),this.#in();return}let r=n.lastIndexOf(`
8
- `),i=r===-1?n:n.slice(r+1);if(e===`stdout`?this.#Ce=i:this.#we=i,r===-1)return;let a=stripAnsi(n.slice(0,r)).replace(/\s+$/u,``);a.trim().length!==0&&(this.#d?.append({source:e,detail:a}),e===`stdout`?this.#kn(a):this.#An(a),this.#in())}#kn(e){let t=[],flushPending=()=>{if(t.length===0)return;let e=t.join(`
9
- `);t=[],e.trim().length!==0&&this.#Lt({kind:`log`,title:`stdout`,body:e,live:!0})};for(let n of e.split(`
10
- `)){let e=parseSandboxLogLine(n.trimEnd());if(e!==void 0){flushPending(),this.#Lt({kind:`sandbox`,body:e,live:!1});continue}let r=parseDevRebuildLogLine(n.trimEnd());if(r===void 0){t.push(n);continue}flushPending(),this.#Mn(r,n.trimEnd())}flushPending()}#An(e){let t=e.split(`
11
- `),n=t.findIndex(e=>parseDevRebuildLogLine(e.trimEnd())?.kind===`failed`);if(n===-1){if(this.#d===void 0){this.#Lt({kind:`log`,title:`stderr`,body:e,live:!0});return}let t=presentDiagnostic(e,this.#d.displayPath);if(t.kind===`inline`){this.#Lt({kind:`log`,title:`stderr`,body:t.text,live:!0});return}this.#Lt({kind:`log`,title:`stderr`,body:formatStoredDiagnostic(t),logVisibility:`stderr-only`,live:!0}),this.#Lt({kind:`log`,title:`stderr`,body:e,logVisibility:`all-only`,live:!0});return}let r=t.slice(0,n).join(`
12
- `);r.trim().length>0&&this.#Lt({kind:`log`,title:`stderr`,body:r,live:!0});let i=t.slice(n).join(`
13
- `);this.#jn(i)}#jn(e){if(this.#p===`all`){if(e.trim().length===0)return;this.#Lt({kind:`log`,title:`stderr`,body:e,live:!0});return}this.#Te=e}#Mn(e,t){let n=this.#Nn();if(e.kind===`failed`){this.#jn(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.#De}`;this.#De+=1,this.#Ee={id:r,summary:t},this.#Lt({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.#Te=void 0);return}e.kind===`rebuilt`&&(this.#Te=void 0),this.#Lt({kind:`log`,title:`stdout`,body:t,live:!0})}#Nn(){let e=this.#Ee;if(e===void 0)return;let t=this.#h.get(e.id);if(!(t===void 0||t.live!==!0))return{state:e,block:t}}#Pn(){let e=this.#Ee;if(e===void 0)return;this.#Ee=void 0;let t=this.#h.get(e.id);t!==void 0&&(t.live=!1)}#Fn(e){switch(this.#p){case`none`:return!1;case`stderr`:return e===`stderr`;case`sandbox`:return e===`sandbox`;case`all`:return!0}}#In(e){return e.kind===`sandbox`?!this.#Fn(`sandbox`):e.kind===`log`?e.logVisibility===`stderr-only`?this.#p!==`stderr`:e.logVisibility===`all-only`?this.#p!==`all`:!this.#Fn(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(`
4
+ `),i=stripPromptControlCharacters(e?.initialDraft??this.#V.text),a=lineOf(r===void 0?i:i.length===0?r:`${r}\n\n${i}`);return this.#V=EMPTY_LINE,this.#P.begin(a.text),this.#Ge(a),this.#I=typeaheadFor(this.#f,a.text),this.#Mt(),this.#an(),await new Promise((e,r)=>{this.#W=r;let apply=e=>{a=e,this.#Pt(),this.#Ge(a),this.#I=typeaheadFor(this.#f,e.text,this.#I),this.#an()},recall=e=>{e!==void 0&&apply(lineOf(e))},interrupt=()=>{this.#I=void 0,this.#Nt(),this.#Ct(),r(interruptedError())},suggestions=()=>this.#I!==void 0&&isTypeaheadOpen(this.#I)?this.#I:void 0,highlighted=()=>{let e=suggestions();return e===void 0?void 0:selectedTypeaheadCommand(e)};this.#ce=r=>{r.type!==`ctrl-c`&&this.#$&&(this.#$=!1,this.#an());let i=applyLineEditorKey(a,r,{multiline:!0});if(i!==void 0){apply(i);return}switch(r.type){case`up`:case`ctrl-p`:{let e=suggestions();if(e!==void 0){this.#I=moveTypeaheadSelection(e,-1),this.#an();break}let t=movePromptLine(a,`up`);t===void 0?recall(this.#P.previous(a.text)):apply(t);break}case`down`:case`ctrl-n`:{let e=suggestions();if(e!==void 0){this.#I=moveTypeaheadSelection(e,1),this.#an();break}let t=movePromptLine(a,`down`);t===void 0?recall(this.#P.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.#I=dismissTypeahead(e),this.#an());break}case`enter`:{let r=highlighted(),i=r!==void 0&&parsePromptCommand(a.text)===null?typeaheadCompletion(r).trimEnd():a.text;if(i.trim().length===0)break;this.#I=void 0,this.#P.add(i),this.#F=!1,this.#Nt(),this.#G=STATUS.processing,isPromptControlCommand(i)?this.#Rt({kind:`command`,body:stripTerminalControls(i.trim()),live:!1}):(this.#It(),this.#zt(i),this.#Oe=i,this.#B.arm()),this.#Ge(EMPTY_LINE),this.#an(),this.#Tt(),e(i);break}case`ctrl-d`:a.text.length===0?(this.#_t(),interrupt()):apply(deleteForward(a));break;case`ctrl-l`:this.#cn();break;case`ctrl-r`:this.#an();break;case`ctrl-c`:if(this.#$){this.#_t(),interrupt();break}this.#$=!0,apply(EMPTY_LINE);break;default:break}},this.#wt()})}#Ge(e){this.#M=e.text,this.#N=e.cursor}takeQueuedPrompt(){let e=this.#Pe.view().steering,t=this.#Pe.takePrompt();return t!==void 0&&(this.#Re=e?`steer`:`queue`),t}async renderStream(e,t){this.#xt(t),this.#g.clear(),this.#F=!1,this.#U.kind!==`waiting`&&(this.#U={kind:`waiting`,startedAtMs:Date.now()}),this.#G=this.#k>0?STATUS.connectionAuth:STATUS.processing,this.#Vt(t?.submittedPrompt),t?.submittedPrompt!==void 0&&this.#d?.recordPrompt(),t?.submittedPrompt!==void 0&&!this.#B.armed&&this.#B.arm(),this.#Z=!1,this.#Ie=!1,this.#ze=!1,this.#Be=t?.submittedPrompt,this.#Pe.beginTurn(),this.#Fe=e.cancel,this.#ge=void 0,this.#_e=void 0,this.#ye=void 0,this.#be=void 0,this.#xe=Date.now();let n={tools:t?.tools??this.#a,reasoning:t?.reasoning??this.#o,assistantResponseStats:t?.assistantResponseStats??this.#l};this.#Ft(),this.#H=!0,this.#an();let r=new Promise(e=>{this.#pe=e});this.#ce=e=>this.#jt(e),this.#wt();let i={text:new Map,reasoning:new Map,tools:new Map};try{for await(let t of takeUntil(iterateTUIStream(e.events),r)){if(this.#Z)break;this.#qt(t,n,i)}}catch(e){let t=summarizeKnownError(e);t===null?this.#Ht(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#Ht(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#pe=void 0,this.#Z&&e.abort?.(),this.#Fe=void 0,this.#Tt(),this.#Lt(),this.#H=!1,this.#U.kind===`waiting`&&(this.#U={kind:`idle`}),this.#G=completedTurnStatus({interrupted:this.#Z,cancelled:this.#Ie,continueSession:t?.continueSession===!0}),this.#en(i),(this.#Z||this.#Ie)&&this.#$t(),this.#Kt(),this.#d?.reportStats(),this.#an(),t?.continueSession||this.#Ct()}}async readToolApproval(e,t){return this.#xt(t),this.#Lt(),this.#F=!1,this.#U={kind:`idle`},this.#G=`Approve ${formatToolApprovalTitle(e)}? (y/n)`,this.#Z=!1,this.#an(),await new Promise((t,n)=>{this.#W=n,this.#ce=r=>{switch(r.type){case`text`:{if(r.framing!==`unframed`)break;let n=r.value.toLowerCase();n===`y`?(this.#It(),this.#G=STATUS.processing,this.#Tt(),this.#an(),t({approved:!0})):n===`n`&&(this.#It(),this.#G=STATUS.processing,this.#qe(e.toolCallId),this.#Tt(),this.#an(),t({approved:!1,reason:`Denied by user.`}));break}case`ctrl-r`:this.#an();break;case`ctrl-c`:this.#Z=!0,this.#Ct(),n(interruptedError());break;default:break}},this.#wt()})}async readInputQuestion(e,t){this.#xt(t),this.#Lt(),this.#F=!1,this.#L=!1,this.#U={kind:`idle`},this.#Z=!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.#te},this.#i,t),renderTextSection=()=>{this.#Wt({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:formatQuestionContent(e,void 0,this.#i),preformatted:!0,live:!0})},syncFreeformCaret=()=>{isOnFreeformRow()?this.#Mt():(this.#Nt(),this.#Pt())};s===`overlay`?(s=`overlay`,this.#F=!1,this.#Gt(o),this.#ke=overlayPanel,this.#G=``,syncFreeformCaret(),this.#an()):(s=`text`,this.#ke=void 0,renderTextSection(),this.#F=!0,this.#Ge(l),this.#G=``,this.#Mt(),this.#an());let finalize=t=>{this.#ke=void 0,this.#Wt({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#i.colors.dim(this.#i.glyph.elbow)} ${stripTerminalControls(t.label)}`,preformatted:!0,live:!1}),this.#F=!1,this.#It(),this.#G=STATUS.processing,this.#Nt(),this.#Tt(),this.#an();let n={};return t.optionId!==void 0&&(n.optionId=t.optionId),t.text!==void 0&&(n.text=t.text),n},dismiss=()=>{this.#ke=void 0,this.#Wt({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#i.colors.dim(this.#i.glyph.elbow)} ${this.#i.colors.dim(`Dismissed.`)}`,preformatted:!0,live:!1}),this.#F=!1,this.#G=``,this.#Nt(),this.#Tt(),this.#an(),u(void 0)},moveCursor=e=>{a!==0&&(c=(c+e+a)%a,syncFreeformCaret(),this.#an())},selectOptionAt=e=>{let t=n[e];t&&u(finalize({optionId:t.id,label:t.label}))},u;return await new Promise((t,r)=>{this.#W=r,u=t,this.#ce=t=>{if(t.type===`ctrl-c`){if((s===`text`||isOnFreeformRow())&&l.text.length>0){l=EMPTY_LINE,this.#Pt(),s===`text`&&this.#Ge(l),this.#an();return}this.#Z=!0,this.#ke=void 0,this.#Nt(),this.#Ct(),r(interruptedError());return}if(t.type===`ctrl-r`){this.#an();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.#an();break}dismiss();break;default:if(isOnFreeformRow()){let e=applyLineEditorKey(l,t);e!==void 0&&(l=e,this.#Pt(),this.#an());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.#an())}break}return}let a=applyLineEditorKey(l,t,{multiline:!0});if(a!==void 0){l=a,this.#Pt(),this.#Ge(l),this.#an();return}switch(t.type){case`up`:case`down`:{let e=movePromptLine(l,t.type);e!==void 0&&(l=e,this.#Pt(),this.#Ge(l),this.#an());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.#Ge(l),this.#an();break}dismiss();break;default:break}},this.#wt()})}upsertSubagentStep(e){if(this.#d?.recordSubagentDispatch(e.callId),this.#s===`hidden`)return;let t=stripTerminalControls(e.reasoning??``).trim(),n=stripTerminalControls(e.message??``).trim();if(!(t.length===0&&n.length===0)){if(this.#Ut(e.callId,e.subagentName),this.#s===`collapsed`){this.#an();return}this.#Wt({id:subagentStepSectionId(e.callId,e.sectionKey),kind:`subagent-step`,subagentCallId:e.callId,depth:1,reasoning:t,body:n,collapsed:this.#s!==`full`,live:!e.finalized}),this.#an()}}upsertSubagentTool(e){if(this.#d?.recordSubagentDispatch(e.callId),e.status===`failed`&&e.errorText!==void 0&&this.#d?.append({source:`tool`,summary:`${e.toolName} failed (subagent ${e.subagentName})`,detail:e.errorText}),this.#s===`hidden`)return;if(this.#Ut(e.callId,e.subagentName),this.#s===`collapsed`){this.#an();return}let t=subagentToolStatus(e.status),n=e.status===`preparing`?presentPreparingTool(e.toolName):presentTool(e.toolName,e.input,this.#Zt({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.#s===`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.#Wt(r),this.#Ke(e.callId),this.#an()}#Ke(e){applyCohortLiveness(this.#m.filter(t=>t.kind===`subagent-tool`&&t.subagentCallId===e).map(e=>({block:e,active:isActiveToolStatus(e.status)})))}removeSubagentTool(e){this.#Gt(subagentToolSectionId(e.callId,e.childCallId)),this.#an()}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.#s===`hidden`)return;this.#Ut(e.callId,e.name);let t=this.#h.get(subagentHeaderId(e.callId));t?.status===`done`&&delete t.status,this.#an()}completeSubagent(e){let t=this.#h.get(subagentHeaderId(e.callId));t!==void 0&&(t.status=`done`,this.#an())}markChildToolCallId(e){this.#v.add(e);let t=this.#y.get(e);t!==void 0&&(this.#Gt(t),this.#y.delete(e),this.#an())}#qe(e){let t=this.#h.get(toolSectionId(e));t!==void 0&&(t.status=`denied`,t.live=!1)}upsertConnectionAuth(e){if(this.#c===`hidden`)return;let t=connectionAuthTerminalMessage(e.state);this.#Wt({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.#an()}setConnectionAuthPendingCount(e){let t=Math.max(0,e);if(t===this.#k)return;let n=this.#k>0;this.#k=t,t>0?(this.#G=STATUS.connectionAuth,this.#an()):n&&(this.#G=STATUS.processing,this.#an())}setVercelStatus(e){this.#A=e,this.#an()}setRemoteConnectionStatus(e){this.#j=e,this.#an()}reset(){this.#m=[],this.#h.clear(),this.#g.clear(),this.#O=void 0,this.#D.length=0,this.#_.length=0,this.#T=!1,this.#E=void 0,this.#Je(),this.#z=!1,this.#Oe=void 0,this.#Ee=void 0,this.#k=0,this.#ge=void 0,this.#_e=void 0,this.#ye=void 0,this.#be=void 0,this.#xe=void 0,this.#J&&(this.#n.clearAll(),this.#an())}renderSessionBoundary(){this.#Bt(),this.#Je();let e=this.#i.colors,t=this.#i.glyph,n=e.dim(`${t.cornerOpen}${t.dash.repeat(2)} Session restarted, clear context.`);this.#Rt({kind:`session-boundary`,body:n,live:!1}),this.#an()}#Je(){this.#v.clear(),this.#y.clear(),this.#C.clear(),this.#x.clear(),this.#Me=void 0,this.#Ne=void 0,this.#Pe.reset(),this.#Re=void 0,this.#S.clear(),this.#B.reset()}renderNotice(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#xt(),this.#Rt({kind:`notice`,body:t,live:!1}),this.#an())}renderSandboxLog(e){let t=parseSandboxLogLine(stripTerminalControls(e));t!==void 0&&(this.#d?.append({source:`sandbox`,detail:t}),this.#xt(),this.#Rt({kind:`sandbox`,body:t,live:!1}),this.#an())}renderSetupWarning(e){let t=stripTerminalControls(e);if(t.trim().length===0){this.#Ye();return}this.#xt(),this.#je=t,this.#an()}clearSetupWarning(){this.#Ye()}#Ye(){this.#je!==void 0&&(this.#je=void 0,this.#an())}renderCommandInvocation(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;this.#xt();let r={kind:`command`,body:n,live:!1};t===`failed`&&(r.status=`error`),this.#Rt(r),this.#an()}renderCommandResult(e,t){let n=stripTerminalControls(e);n.trim().length!==0&&(this.#xt(),this.#Rt(t===`success`?{kind:`result`,body:n,live:!1,status:`done`}:t===`error`?{kind:`flow`,title:t,body:n,live:!1}:{kind:`result`,body:n,live:!1}),this.#an())}#Xe(e,t=`spinner`){this.#xt(),this.#F=!1,this.#U={kind:`idle`},this.#G=``;let n=t===`pulse`?{kind:`pulse`,startedAtMs:Date.now()}:{kind:`spinner`};this.#Ae={title:stripTerminalControls(e),indicator:n,lines:[],outputBuffer:[]},this.#Ft(),this.#an()}#Ze(e){this.#Ve=void 0,this.#dt();let t=this.#Ae;if(t!==void 0){if(this.#Ae=void 0,this.#Lt(),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.#Rt({kind:`flow`,title:`info`,body:e.join(`
5
+ `),live:!1}),this.#Rt({kind:`flow`,title:n.tone,body:n.text,live:!1})),e=[]}}this.#an()}}async#Qe(e){let t=this.#at(),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.#an()},loadSearch=async(e,t)=>{c=!0,s=void 0;let a=++l;this.#an();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.#an())}},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.#fn()),t};return t.question=e=>renderSelectQuestion(panelState(),this.#i,e),this.#an(),await this.#ct((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.#an();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.#an();return;case`update`:o=d.select,s=void 0,this.#an();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.#an();return;case`ignore`:return}}).promise}#$e(e){this.#xt();let t=this.#ot();t.status={kind:`progress`,text:stripTerminalControls(e.status),startedAtMs:Date.now()};let n;t.question=t=>renderSelectQuestion({kind:`actions`,context:e.context,actions:e.actions,cursor:n},this.#i,t),this.#an();let r=this.#ct((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.#an();return;case`repaint`:this.#an();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#et(e){let t=this.#at(),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.#te,editor:{kind:`rename`,editor:i,defaultValue:e.editable.defaultValue,formatHint:e.editable.formatHint}}};return a!==void 0&&(n.error=a),renderSelectQuestion(n,this.#i,t)};let onEditableRow=()=>selectValueAtCursor([...e.options],r.cursor)===e.editable.value,syncEditableRow=()=>{onEditableRow()?this.#Mt():(i=lineOf(``),this.#Nt())};return syncEditableRow(),this.#an(),await this.#ct((t,n)=>{let applyEditor=e=>{i=e,a=void 0,this.#Pt(),this.#an()},applySelect=t=>{r=reduceSelect(r,t,{options:e.options}),a=void 0,syncEditableRow(),this.#an()},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.#an();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.#an();return;case void 0:break}if(!onEditableRow())return;let s=applyLineEditorKey(i,t);s!==void 0&&applyEditor(s)},()=>this.#Nt()).promise}async#tt(e){let t=this.#at(),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.#i,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.#te,editor:{kind:`key`,phase:n.phase}}};return r!==void 0&&(i.cursorBadge=r),renderSelectQuestion(i,this.#i,t)};let syncCaret=()=>{n.phase.kind===`editing`||n.phase.kind===`invalid`?this.#Mt():this.#Nt()};return syncCaret(),this.#an(),await this.#ct((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.#an();return;case`cancel`:i(void 0);return;case`render`:n=o.state,syncCaret(),this.#an();return;case`validate`:{n=o.state,syncCaret(),this.#an();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.#an();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.#Nt()}).promise}async#nt(e){let t=this.#at(),n=initialModelEditorState(e);return t.question=t=>renderModelEditorQuestion({request:e,state:n},this.#i,t),this.#an(),await this.#ct((t,r)=>{let dispatch=t=>{let i=transitionModelEditor(n,t,e);switch(i.kind){case`ignore`:return;case`render`:n=i.state,this.#an();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.#an();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(`
6
+ `,` `))e>=` `&&e!==``&&dispatch({type:`char`,char:e})}).promise}async#rt(e){let t=this.#at(),n=lineOf(``),r;return t.question=t=>{let i={message:e.message,editor:n,mask:e.mask===!0};return e.placeholder===void 0?e.defaultValue!==void 0&&(i.placeholder=e.defaultValue):i.placeholder=e.placeholder,e.notices!==void 0&&(i.notices=e.notices),r!==void 0&&(i.error=r),renderTextQuestion(i,this.#i,t,this.#te)},this.#Mt(),this.#an(),await this.#ct((t,i)=>{let apply=e=>{n=e,r=void 0,this.#Pt(),this.#an()},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.#an();return;case`enter`:{let t=n.text.length>0?n.text:e.defaultValue??``,a=e.validate?.(t);if(a!==void 0){r=a,this.#an();return}i(t);return}default:return}},()=>this.#Nt()).promise}async#it(e){let t=this.#at();return t.question=t=>renderAcknowledgeQuestion({message:e.message,lines:e.lines},this.#i,t),this.#an(),await this.#ct((e,t)=>{switch(e.type){case`enter`:case`escape`:case`ctrl-c`:t();return;case`ctrl-r`:this.#an();return;default:return}}).promise}#at(){return this.#xt(),this.#F=!1,this.#U={kind:`idle`},this.#G=``,this.#ot()}#ot(){return this.#Ae===void 0&&(this.#Ae={title:``,indicator:{kind:`spinner`},lines:[],outputBuffer:[],implicit:!0}),this.#Ae}#st(){this.#Ae?.implicit===!0?this.#Ae=void 0:this.#Ae!==void 0&&(this.#Ae.question=void 0,this.#Ae.hideLinesWhileQuestion=!1),this.#ce=void 0,this.#Tt(),this.#Ae!==void 0&&this.#ut(),this.#an()}#ct(e,t){let n=!1,r,i,a=new Promise((e,t)=>{r=e,i=t}),settle=e=>{n||(n=!0,t?.(),this.#st(),r(e))},reject=e=>{n||(n=!0,t?.(),this.#st(),i(e))};return this.#At(),this.#ce=t=>{t.type===`ctrl-c`&&this.#_t(),e(t,settle,reject)},this.#wt(),{promise:a,settle}}#lt(e){let t,n=new Promise(e=>{t=e});return this.#Ve=t,this.#ut(e?.interruptible??!0),{promise:n,dispose:()=>{this.#Ve===t&&(this.#Ve=void 0,this.#dt())}}}#ut(e=!0){if(this.#Ve===void 0)return;let consumer=t=>{if(e&&(t.type===`ctrl-c`||t.type===`escape`)){t.type===`ctrl-c`&&this.#_t();let e=this.#Ve;this.#Ve=void 0,this.#dt(),e?.();return}t.type===`ctrl-r`&&this.#an()};this.#He=consumer,this.#At(),this.#ce=consumer,this.#wt()}#dt(){this.#He!==void 0&&(this.#ce===this.#He&&this.#Tt(),this.#He=void 0)}#ft(e){let t=e===void 0?void 0:typeof e==`string`?{kind:`progress`,text:stripTerminalControls(e),startedAtMs:Date.now()}:{kind:`external-action`,text:stripTerminalControls(e.text),emphasis:stripTerminalControls(e.emphasis),startedAtMs:Date.now()};if(this.#Ae!==void 0){this.#Ae.status=t,t===void 0&&(this.#Ae.preview=void 0),this.#an();return}if(!(this.#F||this.#H)){if(t===void 0){this.#U={kind:`idle`},this.#K=void 0,this.#Lt(),this.#an();return}this.#xt(),this.#It(),this.#K=t.text,this.#an()}}#pt(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;let r=this.#Ae;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.#an();return}this.#xt(),this.#Rt({kind:`flow`,title:t,body:n,live:!1}),this.#an()}#mt(e){let t=this.#Ae;t!==void 0&&(t.lines=[],t.outputBuffer=[],t.preview=void 0,t.summary=e===void 0?void 0:{headline:stripTerminalControls(e.headline),facts:e.facts.map(e=>({label:stripTerminalControls(e.label),value:stripTerminalControls(e.value)}))},this.#an())}#ht(e){let t=stripTerminalControls(e);if(t.trim().length===0)return;let n=this.#Ae;if(n===void 0){this.#pt(t,`info`);return}n.preview=t,n.outputBuffer.push(t),n.outputBuffer.length>40&&n.outputBuffer.shift(),this.#an()}async#gt(e){this.#le=``,this.#At(),this.#Ve=void 0,this.#dt(),this.#Tt(),this.#Lt(),this.#n.clear(),this.#n.showCursor(),this.#Dn(),this.#e.isTTY&&this.#e.setRawMode?.(!1),this.#e.pause();try{return await e()}finally{this.#e.isTTY&&this.#e.setRawMode?.(!0),this.#e.resume(),this.#le=``,this.#At(),this.#n.hideCursor(),this.#En(),this.#Ae!==void 0&&(this.#Ft(),this.#ut()),this.#n.reset(),this.#an()}}setSessionId(e){this.#Le=e}shutdown(){if(this.#Ct(),this.#Y&&!this.#X){this.#X=!0;let e=this.#Le===void 0?``:` ${this.#i.glyph.dot} session ${this.#Le}`;this.#t.write(`${this.#i.colors.dim(`${eveVersionTag()}${e}`)}\n`)}}requestInterrupt(){this.#Z=!0,this.#Ae!==void 0&&this.#ce?.({type:`ctrl-c`}),this.#pe?.(),this.#Ct()}exitRequested(){return this.#Q}#_t(){this.#Q=!0,this.#ee?.()}async#vt(e){if(this.#Ue!==void 0||!this.#J)return;let t=new TraceViewerSession({...e,theme:this.#i,dimensions:()=>({width:this.#wn(),height:this.#Tn()}),paint:e=>this.#r.paint(e,this.#Tn()),tracingDisabled:process.env.EVE_TRACES===`off`,copyText:e=>copyTextToClipboard(e,e=>this.#r.writeRaw(e)),terminalBackground:this.#We});this.#Ue=t,this.#r.enter(),this.#i.color&&this.#r.writeRaw(BACKGROUND_COLOR_QUERY),await new Promise(e=>{this.#bt=e,this.#ce=e=>{t.handleKey(e)===`close`&&this.#yt()},this.#wt(),t.start()})}#yt(){let e=this.#Ue;if(e===void 0)return;this.#Ue=void 0,e.dispose(),this.#Tt(),this.#r.exit(),this.#n.hideCursor(),this.#an(),this.#n.showCursor();let t=this.#bt;this.#bt=void 0,t?.()}#bt;#xt(e){this.#q=e?.title??this.#q,e?.contextSize!==void 0&&(this.#ve=e.contextSize),!this.#J&&(this.#J=!0,this.#Y=!0,this.#n.reset(),this.#n.hideCursor(),this.#En(),this.#e.isTTY&&(this.#e.setRawMode?.(!0),this.#e.resume(),this.#n.emitBracketedPaste(!0)),this.#fe=()=>this.#an(),this.#t.on(`resize`,this.#fe),process.on(`exit`,this.#St))}#St=()=>{this.#J&&(this.#r.exit(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1)),this.#n.showCursor())};#Ct(){this.#yt();let e=this.#W;if(this.#W=void 0,e?.(interruptedError()),this.#Tt(),this.#Nt(),this.#Lt(),this.#oe!==void 0&&(clearTimeout(this.#oe),this.#oe=void 0),this.#se=!1,this.#J){this.#Fn();for(let e of this.#m)e.kind===`log`&&e.id===void 0&&(e.live=!1);this.#an(),this.#n.clear(),this.#n.showCursor(),this.#Dn(),this.#n.newline(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1),this.#e.pause()),this.#fe&&=(this.#t.off(`resize`,this.#fe),void 0),process.off(`exit`,this.#St),this.#J=!1}}#wt(){this.#e.off(`data`,this.#Et),this.#e.on(`data`,this.#Et),this.#le.length>0&&queueMicrotask(()=>{this.#ce!==void 0&&this.#le.length>0&&(this.#Ot(),this.#Dt())})}#Tt(){this.#e.off(`data`,this.#Et),this.#At(),this.#ce=void 0}#Et=e=>{this.#At(),this.#le+=this.#ue.write(e),this.#Ot(),this.#Dt()};#Dt(){if(this.#le===`\x1B`){this.#de=setTimeout(()=>{this.#le===`\x1B`&&(this.#le=``,this.#ce?.({type:`escape`}))},30),this.#de.unref?.();return}if(isIncompletePaste(this.#le)){let e=this.#le;this.#de=setTimeout(()=>{if(this.#le!==e)return;let t=sanitizePastedText(stripPasteStart(e));this.#le=``,t.length>0&&this.#ce?.({type:`text`,value:t,framing:`bracketed-paste`})},incompletePasteFlushMs),this.#de.unref?.();return}if(isIncompleteOsc(this.#le)){let e=this.#le;this.#de=setTimeout(()=>{this.#le===e&&(this.#le=``)},incompletePasteFlushMs),this.#de.unref?.()}}#Ot(){for(;this.#le.length>0;){let e=nextKey(this.#le);if(e.incomplete)return;if(this.#le=this.#le.slice(e.consumed),!(e.key===void 0||e.key.type===`ignore`)){if(e.key.type===`osc`){this.#kt(e.key.value);continue}this.#ce?.(e.key)}}}#kt(e){let t=parseBackgroundColorReply(e);t!==void 0&&(this.#We=t,this.#Ue?.setTerminalBackground(t))}#At(){this.#de&&=(clearTimeout(this.#de),void 0)}#jt(e){switch(e.type){case`ctrl-l`:case`ctrl-r`:this.#an();break;case`enter`:{let e=this.#V.text;if(e.trim().length===0)break;if(parsePromptCommand(e)?.type===`cancel`&&this.#Fe!==void 0){this.#V=EMPTY_LINE,this.#Pe.requestCancellation(),this.#ze=!0,this.renderCommandInvocation(e.trim()),this.renderCommandResult(`Turn cancellation requested.`),this.#Fe(),this.#an();break}this.#Pe.enqueue(e)&&(this.#V=EMPTY_LINE),this.#an();break}case`ctrl-c`:case`escape`:if(this.#Pe.idle&&this.#Fe===void 0)break;this.#Pe.handleEscape(),this.#ze=!0,this.#Fe?.(),this.#an();break;default:{let t=applyLineEditorKey(this.#V,e,{multiline:!0});t!==void 0&&(this.#V=t,this.#an());break}}}#Mt(){this.#Nt(),this.#Pt(),this.#ie=setInterval(()=>{this.#te=!this.#te,this.#an()},500),this.#ie.unref?.()}#Nt(){this.#ie&&=(clearInterval(this.#ie),void 0),this.#te=!0}#Pt(){this.#te=!0}#Ft(){this.#Lt(),this.#ae=setInterval(()=>{this.#ne+=1,this.#an()},90),this.#ae.unref?.()}#It(){let e=Date.now();this.#re=e,this.#U={kind:`waiting`,startedAtMs:e},this.#Ft()}#Lt(){this.#ae&&=(clearInterval(this.#ae),void 0)}#Rt(e){e.id!==this.#Ee?.id&&this.#Fn(),e.updateSeq=++this.#b,this.#m.push(e),e.id&&this.#h.set(e.id,e)}#zt(e){this.#z=!0,this.#Rt({kind:`user`,body:stripTerminalControls(e),live:!1}),this.#an()}#Bt(){let e=this.#B.settle();if(e===void 0||e.elapsedMs<=1e4&&e.inputTokens<=2e4)return;let t=`Done in ${this.#_n(e.elapsedMs)}`,n=this.#_e??0;if(this.#ve!==void 0&&this.#ve>0&&n>0){let e=Math.round(n/this.#ve*100);t+=` ${this.#i.glyph.dot} ${e}% context`}this.#Rt({kind:`turn-stats`,body:t,live:!1})}#Vt(e){if(e==null)return;let t=this.#Re;if(this.#Re=void 0,this.#Oe===e){this.#Oe=void 0;return}let n={kind:`user`,body:stripTerminalControls(e),live:!1};t!==void 0&&(n.promptOrigin=t),this.#Rt(n)}#Ht(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.#d?.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.#d===void 0?a:`details: ${this.#d.displayPath}`),this.#Rt(c),this.#an()}#Ut(e,t){if(this.#C.has(e))return;this.#C.add(e);let n=stripTerminalControls(t),r=this.#x.get(n)??[];if(r.push(e),this.#x.set(n,r),r.length===2){let e=this.#h.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.#Rt(i)}#Wt(e){if(e.id&&this.#g.has(e.id))return;let t=e.id?this.#h.get(e.id):void 0;if(t){Object.assign(t,e),t.updateSeq=++this.#b;return}this.#Rt(e)}#Gt(e){this.#m=this.#m.filter(t=>t.id!==e),this.#h.delete(e)}#Kt(){for(let e of this.#m)e.status===`approval`||e.status===`running`||e.kind===`connection-auth`&&e.live||(e.live=!1)}#qt(e,t,n){switch(e.type){case`step-finish`:this.#d?.recordStepUsage(e.usage),e.usage!==void 0&&this.#B.addUsage(e.usage),this.#en(n),this.#in(e.usage),this.#an();break;case`assistant-delta`:{let t=(n.text.get(e.id)??``)+stripTerminalControls(e.delta);n.text.set(e.id,t),this.#Jt(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.#Jt(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.#Yt(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.#Yt(e.id,r,!1,t);break}break}case`tool-call-preparing`:if(t.tools===`hidden`||isPanelRoutedTool(e.toolName))break;this.#Xt({input:void 0,preparing:!0,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-call`:if(this.#d?.recordToolCall(e.toolName),t.tools===`hidden`)break;this.#Xt({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.#Xt({...r,status:`approval`},t,n);break}case`tool-result`:{if(t.tools===`hidden`)break;let r=this.#rn(e.toolCallId,n);if(r===void 0)break;this.#Xt({...r,output:e.output,status:`done`},t,n);break}case`tool-error`:{let r=this.#rn(e.toolCallId,n);if(this.#d?.append({source:`tool`,summary:`${r?.toolName??e.toolCallId} failed`,detail:e.errorText}),t.tools===`hidden`||r===void 0)break;this.#Xt({...r,errorText:e.errorText,status:`error`},t,n);break}case`tool-rejected`:{if(t.tools===`hidden`)break;let r=this.#rn(e.toolCallId,n);if(r===void 0)break;this.#Xt({...r,errorText:e.reason,status:`denied`},t,n);break}case`error`:this.#Ht(`Error`,e.errorText,{detail:e.detail,hint:e.hint});break;case`turn-cancelled`:this.#Ie=!0,!this.#ze&&this.#Be!==void 0&&this.#V.text.length===0&&(this.#V=lineOf(this.#Be),this.renderNotice(`The turn was cancelled from outside this prompt — the message was restored to the input.`));break;case`finish`:this.#in(e.usage),this.#an();break}}#Jt(e,t,n){let r=stripTerminalControls(t).trim();r.length!==0&&(this.#Wt({id:e,kind:`assistant`,body:r,live:n}),this.#an())}#Yt(e,t,n,r){let i=stripTerminalControls(t).trim();i.length!==0&&(this.#Wt({id:e,kind:`reasoning`,body:i,collapsed:collapseReasoning(r.reasoning,n),live:n}),this.#an())}#Xt(e,t,n){if(n.tools.set(e.toolCallId,e),this.#v.has(e.toolCallId)||this.#tn(e)||toolBaseName(e.toolName)===`ask_question`)return;let r=toolSectionId(e.toolCallId);this.#y.set(e.toolCallId,r);let i=this.#Zt(e);this.#Wt(renderNativeToolBlock(e,r,t.tools===`full`,i)),this.#nn(n),this.#an()}#Zt(e){e.output!==void 0&&this.#S.observeRead(e.output);let t={};this.#Qt(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.#S.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}#Qt(e){let t=this.#w?.info?.subagents.local;if(t===void 0||t.length===0)return!1;let n=toolBaseName(e);return t.some(e=>e.name===n)}#$t(){for(let e of this.#m)e.kind!==`tool`&&e.kind!==`subagent-tool`||e.status===`running`&&(e.status=`error`,e.result=`interrupted`,e.live=!1)}#en(e){for(let[t,n]of e.tools){if(n.preparing!==!0)continue;e.tools.delete(t);let r=this.#y.get(t)??toolSectionId(t);this.#Gt(r),this.#y.delete(t)}}#tn(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.#Ne!==e&&(this.#Ne=e,this.#Rt({kind:`todo-list`,body:renderFinishedTodoRows(t,this.#wn(),this.#i).join(`
7
+ `),live:!1})),this.#Me=void 0}else this.#Me=t.length>0?t:void 0,this.#Ne=void 0;return this.#an(),!0}#nn(e){let t=[];for(let n of e.tools.values()){if(this.#v.has(n.toolCallId))continue;let e=this.#y.get(n.toolCallId)??toolSectionId(n.toolCallId),r=this.#h.get(e);r?.kind===`tool`&&t.push({block:r,active:isActiveToolStatus(n.status)})}applyCohortLiveness(t)}#rn(e,t){let n=t.tools.get(e);if(n!==void 0)return n;let r=this.#y.get(e)??toolSectionId(e),i=this.#h.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`}}#in(e){if(e===void 0)return;let{inputTokens:t,outputTokens:n}=e;if((t!=null||n!=null)&&(this.#ge=(t??0)+(n??0)),this.#_e=t??this.#_e,this.#ye=n??this.#ye,this.#ye!=null&&this.#xe!==void 0){let e=(Date.now()-this.#xe)/1e3;e>0&&(this.#be=this.#ye/e)}}#an(){if(this.#J){if(this.#me){this.#he=!0;return}this.#me=!0;try{do this.#he=!1,this.#on();while(this.#he)}finally{this.#me=!1}}}#on(){if(!this.#J)return;if(this.#Ue!==void 0){this.#Ue.repaint();return}let e=this.#wn(),t=this.#hn(e),n=Math.max(1,this.#Tn()-t.length),r=[],i=this.#O,a=groupToolBlocksForDisplay(this.#m),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.#m.length-1;t>=0;--t)e.has(this.#m[t])&&this.#m.splice(t,1)}for(let t of a.slice(0,o)){for(let e of t.members)this.#_.push(e),e.id&&(this.#g.add(e.id),this.#h.delete(e.id));if(this.#Ln(t.display))continue;let n=this.#dn(t.display,e,i);i=previousBlockOf(t.display),this.#O=i,r.push(...n),this.#D.push(...n)}let s=[];for(let{display:t}of a.slice(o)){if(this.#Ln(t))continue;let n=this.#dn(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.#i),...t];r.length>0?this.#n.flush(r,c):this.#n.update(c)}#sn(){if(!this.#J)return;let e=this.#wn(),t=this.#hn(e),n=Math.max(1,this.#Tn()-t.length),r=this.#O,i=[];for(let{display:t}of groupToolBlocksForDisplay(this.#m)){if(this.#Ln(t))continue;let n=this.#dn(t,e,r);r=previousBlockOf(t),i.push(...n)}let a=[...clipLiveRows(i,n,e,this.#i),...t];this.#n.clearAll(),this.#n.flush([...this.#un(),...this.#D],a)}logDisplayMode(){return this.#p}setLogDisplayMode(e){e!==this.#p&&(this.#p=e,e===`all`&&this.flushDelayedDevBuildErrors(),this.#ln(),this.#J&&this.#sn())}flushDelayedDevBuildErrors(){let e=this.#Te;e!==void 0&&(this.#Te=void 0,this.#Rt({kind:`log`,title:`stderr`,body:e,live:!0}),this.#an())}#cn(){this.#se=!0,this.#oe!==void 0&&clearTimeout(this.#oe),this.#oe=setTimeout(()=>{this.#se=!1,this.#oe=void 0,this.#an()},5e3),this.setLogDisplayMode(nextLogDisplayMode(this.#p)),this.#an()}#ln(){let e=this.#wn();this.#D.length=0;let t;for(let{display:n}of groupToolBlocksForDisplay(this.#_,{logCoalescing:`runs`})){if(this.#Ln(n))continue;let r=this.#dn(n,e,t);t=previousBlockOf(n),this.#D.push(...r)}this.#O=t}#un(){let e=this.#w;if(e===void 0)return[];let t={name:e.name,theme:this.#i,width:this.#wn()};return e.info!==void 0&&(t.info=e.info),e.tip!==void 0&&(t.tip=e.tip),buildAgentHeader(t)}#dn(e,t,n){let r={activityPulse:this.#pn(this.#re,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH)};n!==void 0&&(r.previous=n);let i=renderBlockLines(e,t,this.#i,r);return(e.depth??0)===0&&leadsWithGap(e,n)?[``,...i]:i}#fn(){return this.#i.spinner[this.#ne%this.#i.spinner.length]??``}#pn(e,t){return isProgressPulseVisible(Date.now()-e)?t:` `}#mn(e,t){return e.indicator.kind===`spinner`?{glyph:this.#fn(),color:`yellow`}:{glyph:this.#pn(e.indicator.startedAtMs,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH),color:t?.kind===`external-action`?`yellow`:`green`}}#hn(e){let n=this.#i.colors,r=[``];if(this.#ke!==void 0)return r.push(...this.#ke(e),``),this.#xn(r,e),r;let a=this.#Ae;if(a!==void 0){let t=this.#mn(a,a.status),n;if(a.status!==void 0){let{startedAtMs:e,...r}=a.status,i=Date.now()-e,o=i>=5e3?` ${formatTurnDuration(i)}`:``;n={...r,text:`${r.text}${o}`,indicator:t}}let 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.summary===void 0?a.hideLinesWhileQuestion===!0?[]:a.lines:[{text:a.summary.headline,tone:`success`},...a.summary.facts.map(e=>({text:`${e.label}: ${e.value}`,tone:`info`}))],content:i};return r.push(...renderFlowPanel(o,this.#i,e)),this.#Sn(r,e),r}this.#je!==void 0&&r.push(...renderAttentionRows(this.#je,e,this.#i),``),this.#Me!==void 0&&r.push(...renderTodoPanelRows({items:this.#Me,width:e,theme:this.#i,working:this.#H||this.#U.kind===`waiting`,pulse:this.#pn(this.#re,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH)}),``);let o=renderMessageQueueRows({view:this.#Pe.view(),width:e,theme:this.#i,working:this.#H});if(o.length>0&&r.push(...o,``),this.#F){let i=this.#I===void 0?void 0:inlineCommandHint(this.#I);i===void 0&&this.#I!==void 0&&isTypeaheadOpen(this.#I)&&r.push(...renderCommandSuggestions(this.#I,this.#i,e)),this.#$&&r.push(clip(n.dim(`Press Ctrl+C again to exit`),e),``);let a=isPromptControlCommand(this.#M),o=i?n.dim(` ${i}`):``,s=[];this.#xn(s,e);let u=Math.max(1,this.#Tn()-1-r.length-1-s.length),f={text:this.#M,cursor:this.#N,width:e,theme:this.#i,caretVisible:this.#te,isCommand:a,ghost:o,maxRows:u};return this.#L&&this.#M.length===0&&(f.placeholder=this.#z?``:promptPlaceholder(Date.now()-this.#R)),r.push(...promptInputRows(f)),r.push(...s),r}let s=this.#U.kind===`waiting`&&this.#K===void 0;if(this.#H||s){r.push(this.#gn(e)),this.#yn(r,e);let t=[];return this.#xn(t,e),!this.#H&&t.length>0&&r.push(``),r.push(...t),r}if(this.#V.text.length>0)return this.#bn(r,e,{inert:!1}),this.#xn(r,e),r;let u=this.#K??(this.#G.length>0?this.#G:`Ready`),f=this.#Cn(),p=n.dim(this.#i.glyph.dot),m=f?`${p} ${u} ${n.dim(this.#i.glyph.dot)} ${f}`:`${p} ${u}`;return r.push(clip(m,e)),this.#xn(r,e),r}#gn(e){let t=this.#i.colors,n=this.#pn(this.#re,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH),r=this.#U,i=this.#B.startedAtMs??this.#xe??(r.kind===`waiting`?r.startedAtMs:Date.now()),a=Date.now()-i,o=`${typewriterText(`Working for`,a,80)} ${this.#_n(a)}`;return clip(`${t.yellow(n)} ${t.dim(o)}`,e)}#_n(e){return`${formatTurnDuration(e)}${this.#vn()}`}#vn(){let{inputTokens:e,outputTokens:t}=this.#B.usage;return e===0&&t===0?``:` ${this.#i.glyph.dash.repeat(2)} ${formatTokenFlow({inputTokens:e,outputTokens:t},this.#i.glyph)}`}#yn(e,t){this.#H&&this.#bn(e,t,{inert:!0})}#bn(e,t,n){e.push(``);let r={text:this.#V.text,cursor:this.#V.cursor,width:t,theme:this.#i,caretVisible:!0,isCommand:!1,ghost:``,maxRows:4,inert:n.inert};n.inert&&this.#V.text.length===0&&(r.placeholder=``),e.push(...promptInputRows(r))}#xn(e,t){let n=this.#j===void 0?``:` `,r=Math.max(1,t-n.length),i={theme:this.#i,width:r};this.#se&&(i.logLevel=this.#p);let a=this.#w?.serverUrl;if(a!==void 0&&this.#j===void 0){let e=new URL(a).port;e.length>0&&(i.serverPort=e)}let o=this.#w?.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.#A!==void 0&&(i.vercel=this.#A),this.#j!==void 0&&(i.remote=this.#j);let c=buildStatusLine(i);c!==void 0&&e.push(clip(`${n}${c}`,t))}#Sn(e,t){if(this.#j===void 0)return;let n=Math.max(1,t-2),r=buildStatusLine({remote:this.#j,theme:this.#i,width:n});r!==void 0&&e.push(``,clip(` ${r}`,t))}#Cn(){let e=this.#i.colors,t=[],n=formatAssistantResponseStats({totalTokens:this.#ge,outputTokens:this.#ye,tokensPerSecond:this.#be},this.#l);return n&&t.push(n),t.length>0?e.dim(t.join(` ${this.#i.glyph.dot} `)):``}#wn(){return Math.max(20,this.#t.columns||80)}#Tn(){return Math.max(8,this.#t.rows||24)}#En(){if(this.#Se!==void 0||!this.#u)return;this.#Ce=``,this.#we=``;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.#kn(t,chunkToString(e,i)),a?.(),!0}),()=>{e.write=n}},e=capture(process.stdout,`stdout`),t=capture(process.stderr,`stderr`);this.#d?.subscribeLogRecords(e=>this.#On(e)),this.#Se=()=>{this.#d?.unsubscribeLogRecords(),e(),t()}}#Dn(){let e=this.#Se;e!==void 0&&(this.#Se=void 0,e(),this.#Ce.length>0&&(this.#d?.append({source:`stdout`,detail:this.#Ce}),this.#In(`stdout`)&&process.stdout.write(`${this.#Ce}\n`),this.#Ce=``),this.#we.length>0&&(this.#d?.append({source:`stderr`,detail:this.#we}),this.#In(`stderr`)&&process.stderr.write(`${this.#we}\n`),this.#we=``))}#On(e){let t=e.fields===void 0?``:` ${JSON.stringify(e.fields)}`;this.#jn(`[eve:${e.namespace}] ${e.message}${t}`),this.#an()}#kn(e,t){let n=(e===`stdout`?this.#Ce:this.#we)+t;if(e===`stdout`&&parseDevRebuildLogLine(n.trimEnd())!==void 0){this.#Ce=``,this.#d?.append({source:e,detail:n.trimEnd()}),this.#An(n.trimEnd()),this.#an();return}let r=n.lastIndexOf(`
8
+ `),i=r===-1?n:n.slice(r+1);if(e===`stdout`?this.#Ce=i:this.#we=i,r===-1)return;let a=stripAnsi(n.slice(0,r)).replace(/\s+$/u,``);a.trim().length!==0&&(this.#d?.append({source:e,detail:a}),e===`stdout`?this.#An(a):this.#jn(a),this.#an())}#An(e){let t=[],flushPending=()=>{if(t.length===0)return;let e=t.join(`
9
+ `);t=[],e.trim().length!==0&&this.#Rt({kind:`log`,title:`stdout`,body:e,live:!0})};for(let n of e.split(`
10
+ `)){let e=parseSandboxLogLine(n.trimEnd());if(e!==void 0){flushPending(),this.#Rt({kind:`sandbox`,body:e,live:!1});continue}let r=parseDevRebuildLogLine(n.trimEnd());if(r===void 0){t.push(n);continue}flushPending(),this.#Nn(r,n.trimEnd())}flushPending()}#jn(e){let t=e.split(`
11
+ `),n=t.findIndex(e=>parseDevRebuildLogLine(e.trimEnd())?.kind===`failed`);if(n===-1){if(this.#d===void 0){this.#Rt({kind:`log`,title:`stderr`,body:e,live:!0});return}let t=presentDiagnostic(e,this.#d.displayPath);if(t.kind===`inline`){this.#Rt({kind:`log`,title:`stderr`,body:t.text,live:!0});return}this.#Rt({kind:`log`,title:`stderr`,body:formatStoredDiagnostic(t),logVisibility:`stderr-only`,live:!0}),this.#Rt({kind:`log`,title:`stderr`,body:e,logVisibility:`all-only`,live:!0});return}let r=t.slice(0,n).join(`
12
+ `);r.trim().length>0&&this.#Rt({kind:`log`,title:`stderr`,body:r,live:!0});let i=t.slice(n).join(`
13
+ `);this.#Mn(i)}#Mn(e){if(this.#p===`all`){if(e.trim().length===0)return;this.#Rt({kind:`log`,title:`stderr`,body:e,live:!0});return}this.#Te=e}#Nn(e,t){let n=this.#Pn();if(e.kind===`failed`){this.#Mn(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.#De}`;this.#De+=1,this.#Ee={id:r,summary:t},this.#Rt({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.#Te=void 0);return}e.kind===`rebuilt`&&(this.#Te=void 0),this.#Rt({kind:`log`,title:`stdout`,body:t,live:!0})}#Pn(){let e=this.#Ee;if(e===void 0)return;let t=this.#h.get(e.id);if(!(t===void 0||t.live!==!0))return{state:e,block:t}}#Fn(){let e=this.#Ee;if(e===void 0)return;this.#Ee=void 0;let t=this.#h.get(e.id);t!==void 0&&(t.live=!1)}#In(e){switch(this.#p){case`none`:return!1;case`stderr`:return e===`stderr`;case`sandbox`:return e===`sandbox`;case`all`:return!0}}#Ln(e){return e.kind===`sandbox`?!this.#In(`sandbox`):e.kind===`log`?e.logVisibility===`stderr-only`?this.#p!==`stderr`:e.logVisibility===`all-only`?this.#p!==`all`:!this.#In(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(`
14
14
  `)}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(`
15
15
  `)}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};
@@ -11,7 +11,7 @@ import type { Theme } from "../theme.js";
11
11
  import type { TraceViewerSurfaces } from "./trace-surfaces.js";
12
12
  export interface ConversationItem {
13
13
  readonly kind: "system" | "user" | "assistant" | "tool";
14
- /** Detail-drawer source for this item (the turn marker span for users). */
14
+ /** Detail-drawer source for this item (the turn span for users). */
15
15
  readonly span: LocalTraceSpan;
16
16
  /** Tool name for tool items. */
17
17
  readonly name?: string;
@@ -1 +1 @@
1
- import{WizardCancelledError}from"#setup/step.js";import{searchActionQuery}from"#setup/cli/select-state.js";import{createSelectOptionCodec}from"#setup/cli/select-option-codec.js";function setupSelectRequest(e,t,n,r){let i={message:e.message,options:t};e.description!==void 0&&(i.description=e.description),e.metadata!==void 0&&(i.metadata=e.metadata);let withNotices=t=>(e.notices!==void 0&&(t.notices=e.notices),t);if(e.multiple===!0){if(e.hintLayout!==void 0)throw Error(`Multi-select setup questions do not support a hint layout.`);let t;return e.search===!0?(t={...i,kind:`searchable-multi`,required:e.required??!1},e.placeholder!==void 0&&(t.placeholder=e.placeholder)):t={...i,kind:`multi`,required:e.required??!1},e.initialValues!==void 0&&(t.initialValues=e.initialValues.map(n)),withNotices(t)}if(e.search===!0&&e.hintLayout===`stacked`)throw Error(`Searchable setup questions do not support a stacked hint layout.`);let a;if(e.search===!0){if(a={...i,kind:`search`},e.hintLayout===`inline`&&(a.layout=`task-list`),e.placeholder!==void 0&&(a.placeholder=e.placeholder),e.searchAction!==void 0){a.searchAction={label:e.searchAction.label};let t=e.searchAction.load;t!==void 0&&(a.searchAction.load=async e=>r(await t(e)))}}else{let t=e.hintLayout===`inline`?`task-list`:e.hintLayout??`single`;a={...i,kind:t}}return e.initialValue!==void 0&&(a.initialValue=n(e.initialValue)),withNotices(a)}function createTuiPrompter(r){function guardCancel(t){if(t===void 0)throw new WizardCancelledError;return t}async function select(e){let i=createSelectOptionCodec(e.options),a=setupSelectRequest(e,i.options,i.encode,i.encodeOptions),o=guardCancel(await r.readSelect(a)).map(n=>{let r=searchActionQuery(n);return r!==void 0&&e.multiple!==!0&&e.searchAction!==void 0?e.searchAction.value(r):i.decode(n)});if(e.multiple===!0)return o;let s=o[0];if(s===void 0)throw Error(`Single-select returned no option.`);return s}function line(e){return t=>r.renderLine(t,e)}return{async text(e){let t={message:e.message};return e.placeholder!==void 0&&(t.placeholder=e.placeholder),e.defaultValue!==void 0&&(t.defaultValue=e.defaultValue),e.validate!==void 0&&(t.validate=e.validate),e.notices!==void 0&&(t.notices=e.notices),guardCancel(await r.readText(t))},async password(e){let t={message:e.message,mask:!0};return e.validate!==void 0&&(t.validate=e.validate),guardCancel(await r.readText(t))},select,async selectEditable(e){let t=createSelectOptionCodec(e.options),i={value:t.encode(e.editable.value),defaultValue:e.editable.defaultValue,formatHint:e.editable.formatHint};e.editable.validate!==void 0&&(i.validate=e.editable.validate);let a={message:e.message,options:t.options,editable:i};e.initialValue!==void 0&&(a.initialValue=t.encode(e.initialValue));let o=guardCancel(await r.readEditableSelect(a)),s=t.decode(o.value);return o.kind===`edited`?{kind:`edited`,value:s,text:o.text}:{kind:`selected`,value:s}},async acknowledge(e){await r.readAcknowledge({message:e.message,lines:e.lines??[]})},awaitChoice(e){return r.readChoice(e)},note(e,t,n){let i=n?.tone===`success`?`success`:`warning`;t&&r.renderLine(t,i),r.renderLine(e,i)},intro(){},outro(){},withInheritedStdio:e=>r.withInheritedStdio(e),log:{message:line(`info`),info:line(`info`),success:line(`success`),warning:line(`warning`),error:line(`error`),commandOutput:e=>r.renderOutput(e),section(e,t){r.renderLine(e,`info`);for(let e of t)r.renderLine(` ${e}`,`info`)},spinner(e,t){r.setStatus(t?.kind===`external-action`?{kind:`external-action`,text:e,emphasis:t.emphasis}:e);let n=!1;return{stop(){n||(n=!0,r.setStatus(void 0))}}}}}}export{createTuiPrompter};
1
+ import{WizardCancelledError}from"#setup/step.js";import{searchActionQuery}from"#setup/cli/select-state.js";import{createSelectOptionCodec}from"#setup/cli/select-option-codec.js";function setupSelectRequest(e,t,n,r){let i={message:e.message,options:t};e.description!==void 0&&(i.description=e.description),e.metadata!==void 0&&(i.metadata=e.metadata);let withNotices=t=>(e.notices!==void 0&&(t.notices=e.notices),t);if(e.multiple===!0){if(e.hintLayout!==void 0)throw Error(`Multi-select setup questions do not support a hint layout.`);let t;return e.search===!0?(t={...i,kind:`searchable-multi`,required:e.required??!1},e.placeholder!==void 0&&(t.placeholder=e.placeholder)):t={...i,kind:`multi`,required:e.required??!1},e.initialValues!==void 0&&(t.initialValues=e.initialValues.map(n)),withNotices(t)}if(e.search===!0&&e.hintLayout===`stacked`)throw Error(`Searchable setup questions do not support a stacked hint layout.`);let a;if(e.search===!0){if(a={...i,kind:`search`},e.hintLayout===`inline`&&(a.layout=`task-list`),e.placeholder!==void 0&&(a.placeholder=e.placeholder),e.searchAction!==void 0){a.searchAction={label:e.searchAction.label};let t=e.searchAction.load;t!==void 0&&(a.searchAction.load=async e=>r(await t(e)))}}else{let t=e.hintLayout===`inline`?`task-list`:e.hintLayout??`single`;a={...i,kind:t}}return e.initialValue!==void 0&&(a.initialValue=n(e.initialValue)),withNotices(a)}function createTuiPrompter(r){function guardCancel(t){if(t===void 0)throw new WizardCancelledError;return t}async function select(e){let i=createSelectOptionCodec(e.options),a=setupSelectRequest(e,i.options,i.encode,i.encodeOptions),o=guardCancel(await r.readSelect(a)).map(n=>{let r=searchActionQuery(n);return r!==void 0&&e.multiple!==!0&&e.searchAction!==void 0?e.searchAction.value(r):i.decode(n)});if(e.multiple===!0)return o;let s=o[0];if(s===void 0)throw Error(`Single-select returned no option.`);return s}function line(e){return t=>r.renderLine(t,e)}return{async text(e){let t={message:e.message};return e.placeholder!==void 0&&(t.placeholder=e.placeholder),e.defaultValue!==void 0&&(t.defaultValue=e.defaultValue),e.validate!==void 0&&(t.validate=e.validate),e.notices!==void 0&&(t.notices=e.notices),guardCancel(await r.readText(t))},async password(e){let t={message:e.message,mask:!0};return e.validate!==void 0&&(t.validate=e.validate),guardCancel(await r.readText(t))},select,async selectEditable(e){let t=createSelectOptionCodec(e.options),i={value:t.encode(e.editable.value),defaultValue:e.editable.defaultValue,formatHint:e.editable.formatHint};e.editable.validate!==void 0&&(i.validate=e.editable.validate);let a={message:e.message,options:t.options,editable:i};e.initialValue!==void 0&&(a.initialValue=t.encode(e.initialValue));let o=guardCancel(await r.readEditableSelect(a)),s=t.decode(o.value);return o.kind===`edited`?{kind:`edited`,value:s,text:o.text}:{kind:`selected`,value:s}},async acknowledge(e){await r.readAcknowledge({message:e.message,lines:e.lines??[]})},awaitChoice(e){return r.readChoice(e)},note(e,t,n){let i=n?.tone===`success`?`success`:`warning`;t&&r.renderLine(t,i),r.renderLine(e,i)},intro(){},outro(){},replaceContent:e=>r.replaceContent?.(e),withInheritedStdio:e=>r.withInheritedStdio(e),log:{message:line(`info`),info:line(`info`),success:line(`success`),warning:line(`warning`),error:line(`error`),commandOutput:e=>r.renderOutput(e),section(e,t){r.renderLine(e,`info`);for(let e of t)r.renderLine(` ${e}`,`info`)},spinner(e,t){r.setStatus(t?.kind===`external-action`?{kind:`external-action`,text:e,emphasis:t.emphasis}:e);let n=!1;return{stop(){n||(n=!0,r.setStatus(void 0))}}}}}}export{createTuiPrompter};
@@ -4,5 +4,10 @@
4
4
  * `host` may be an absolute origin (`https://agent.example.com`) or a
5
5
  * same-origin prefix (`/api`). Prefixes are important for browser clients that
6
6
  * talk to an app-owned proxy instead of the eve deployment directly.
7
+ *
8
+ * `routePath` may carry its own query string (`/path?a=1`); it is split off
9
+ * before path joining — assigning it through `URL.pathname` would percent-
10
+ * encode the `?` into the final path segment. Explicit `searchParams` win
11
+ * over same-named embedded query params.
7
12
  */
8
13
  export declare function createClientUrl(host: string, routePath: string, searchParams?: Readonly<Record<string, string>>): string;
@@ -1 +1 @@
1
- function createClientUrl(e,t,n){let r=t.startsWith(`/`)?t:`/${t}`;if(isAbsoluteUrl(e)){let t=new URL(e);return t.pathname=`${trimTrailingSlash(t.pathname)}${r}`,mergeSearchParams(t.searchParams,n),t.hash=``,t.toString()}let i=new URL(e,`http://eve.local`),a=trimTrailingSlash(i.pathname);return mergeSearchParams(i.searchParams,n),`${a}${r}${formatSearch(i.searchParams)}`}function isAbsoluteUrl(e){return/^[a-z][a-z\d+\-.]*:/i.test(e)}function trimTrailingSlash(e){return e===`/`?``:e.endsWith(`/`)?e.slice(0,-1):e}function mergeSearchParams(e,t){if(t!==void 0)for(let[n,r]of Object.entries(t))e.set(n,r)}function formatSearch(e){let t=e.toString();return t.length===0?``:`?${t}`}export{createClientUrl};
1
+ function createClientUrl(e,t,n){let r=t.indexOf(`?`),i=r===-1?t:t.slice(0,r),a=r===-1?``:t.slice(r+1),o=i.startsWith(`/`)?i:`/${i}`;if(isAbsoluteUrl(e)){let t=new URL(e);return t.pathname=`${trimTrailingSlash(t.pathname)}${o}`,mergeEmbeddedQuery(t.searchParams,a),mergeSearchParams(t.searchParams,n),t.hash=``,t.toString()}let s=new URL(e,`http://eve.local`),c=trimTrailingSlash(s.pathname);return mergeEmbeddedQuery(s.searchParams,a),mergeSearchParams(s.searchParams,n),`${c}${o}${formatSearch(s.searchParams)}`}function mergeEmbeddedQuery(e,t){if(t.length!==0)for(let[n,r]of new URLSearchParams(t))e.append(n,r)}function isAbsoluteUrl(e){return/^[a-z][a-z\d+\-.]*:/i.test(e)}function trimTrailingSlash(e){return e===`/`?``:e.endsWith(`/`)?e.slice(0,-1):e}function mergeSearchParams(e,t){if(t!==void 0)for(let[n,r]of Object.entries(t))e.set(n,r)}function formatSearch(e){let t=e.toString();return t.length===0?``:`?${t}`}export{createClientUrl};
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "moduleVersions": {
3
3
  "@agentclientprotocol/sdk": "1.3.0",
4
- "@ai-sdk/anthropic": "4.0.18",
4
+ "@ai-sdk/anthropic": "4.0.36",
5
5
  "chat": "4.34.0",
6
6
  "@chat-adapter/slack": "4.34.0",
7
7
  "@chat-adapter/state-memory": "4.34.0",
@@ -11,21 +11,21 @@
11
11
  "experimental-ai-sdk-code-mode": "1.0.16",
12
12
  "eventsource-parser": "3.1.0",
13
13
  "env-runner": "0.1.16",
14
- "@ai-sdk/google": "4.0.21",
14
+ "@ai-sdk/google": "4.0.39",
15
15
  "gray-matter": "4.0.3",
16
16
  "jose": "6.2.3",
17
17
  "jsonc-parser": "3.3.1",
18
18
  "@types/json-schema": "7.0.15",
19
19
  "marked": "17.0.6",
20
- "@ai-sdk/mcp": "2.0.16",
21
- "@ai-sdk/openai": "4.0.17",
20
+ "@ai-sdk/mcp": "2.0.29",
21
+ "@ai-sdk/openai": "4.0.36",
22
22
  "@opentelemetry/api": "1.9.1",
23
23
  "@opentelemetry/otlp-transformer": "0.214.0",
24
- "@ai-sdk/otel": "1.0.34",
24
+ "@ai-sdk/otel": "1.0.58",
25
25
  "@photon-ai/chat-adapter-imessage": "3.2.0",
26
26
  "picocolors": "1.1.1",
27
- "@ai-sdk/provider": "4.0.4",
28
- "@ai-sdk/provider-utils": "5.0.13",
27
+ "@ai-sdk/provider": "4.0.7",
28
+ "@ai-sdk/provider-utils": "5.0.25",
29
29
  "semver": "7.8.4",
30
30
  "shadcn": "4.16.1",
31
31
  "@standard-schema/spec": "1.1.0",
@@ -43,5 +43,5 @@
43
43
  "zod": "4.4.3",
44
44
  "zod-validation-error": "5.0.0"
45
45
  },
46
- "scriptHash": "e20714a41a19b69ca8599dc01467ae8cce225eaa106301f1ec2e9adc5d2adcca"
46
+ "scriptHash": "45c4b6fa4673e0e66a5e30ac20944506245b15860d4588b69f686f80d4e19d5f"
47
47
  }
@@ -1,4 +1,4 @@
1
- import { JSONObject, ProviderV4, LanguageModelV4, FilesV4, SkillsV4 } from '#compiled/@ai-sdk/provider/index.js';
1
+ import { JSONObject, ProviderV4, Experimental_BatchLanguageModelV4, FilesV4, SkillsV4 } from '#compiled/@ai-sdk/provider/index.js';
2
2
  import { z } from '#compiled/zod/index.js';
3
3
  import * as _ai_sdk_provider_utils from '#compiled/@ai-sdk/provider-utils/index.js';
4
4
  import { ToolExecuteFunction, Tool, Experimental_SandboxSession, ProviderDefinedTool, FetchFunction } from '#compiled/@ai-sdk/provider-utils/index.js';
@@ -183,7 +183,20 @@ interface AnthropicMessageMetadata {
183
183
  } | null;
184
184
  }
185
185
 
186
- type AnthropicModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
186
+ type AnthropicModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
187
+ /**
188
+ * Anthropic provider options for system messages.
189
+ */
190
+ declare const anthropicSystemMessageProviderOptions: z.ZodObject<{
191
+ toolChanges: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
192
+ type: z.ZodLiteral<"tool_addition">;
193
+ toolName: z.ZodString;
194
+ }, z.core.$strip>, z.ZodObject<{
195
+ type: z.ZodLiteral<"tool_removal">;
196
+ toolName: z.ZodString;
197
+ }, z.core.$strip>]>>>;
198
+ }, z.core.$strip>;
199
+ type AnthropicSystemMessageProviderOptions = z.infer<typeof anthropicSystemMessageProviderOptions>;
187
200
  declare const anthropicLanguageModelOptions: z.ZodObject<{
188
201
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
189
202
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
@@ -254,7 +267,7 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
254
267
  us: "us";
255
268
  global: "global";
256
269
  }>>;
257
- fallbacks: z.ZodOptional<z.ZodArray<z.ZodObject<{
270
+ fallbacks: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"default">, z.ZodArray<z.ZodObject<{
258
271
  model: z.ZodString;
259
272
  max_tokens: z.ZodOptional<z.ZodNumber>;
260
273
  thinking: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
@@ -263,7 +276,7 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
263
276
  fast: "fast";
264
277
  standard: "standard";
265
278
  }>>;
266
- }, z.core.$strip>>>;
279
+ }, z.core.$strip>>]>>;
267
280
  anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>;
268
281
  contextManagement: z.ZodOptional<z.ZodObject<{
269
282
  edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -393,6 +406,8 @@ declare const anthropicTools: {
393
406
  *
394
407
  * @param model - The advisor model ID (required), e.g. `"claude-opus-4-8"`.
395
408
  * @param maxUses - Maximum advisor calls per request (per-request cap).
409
+ * @param maxTokens - Maximum advisor output tokens per call, including
410
+ * thinking and text. Minimum 1024; Anthropic recommends starting with 2048.
396
411
  * @param caching - Enables prompt caching for the advisor's transcript
397
412
  * across calls within a conversation. Worthwhile from ~3 advisor calls
398
413
  * per conversation.
@@ -400,15 +415,18 @@ declare const anthropicTools: {
400
415
  advisor_20260301: (args: Parameters<_ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {
401
416
  type: "advisor_result";
402
417
  text: string;
418
+ stopReason?: string;
403
419
  } | {
404
420
  type: "advisor_redacted_result";
405
421
  encryptedContent: string;
422
+ stopReason?: string;
406
423
  } | {
407
424
  type: "advisor_tool_result_error";
408
425
  errorCode: string;
409
426
  }, {
410
427
  model: string;
411
428
  maxUses?: number;
429
+ maxTokens?: number;
412
430
  caching?: {
413
431
  type: "ephemeral";
414
432
  ttl: "5m" | "1h";
@@ -416,9 +434,11 @@ declare const anthropicTools: {
416
434
  }, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{}, {
417
435
  type: "advisor_result";
418
436
  text: string;
437
+ stopReason?: string;
419
438
  } | {
420
439
  type: "advisor_redacted_result";
421
440
  encryptedContent: string;
441
+ stopReason?: string;
422
442
  } | {
423
443
  type: "advisor_tool_result_error";
424
444
  errorCode: string;
@@ -540,7 +560,7 @@ declare const anthropicTools: {
540
560
  new_start: number | null;
541
561
  old_lines: number | null;
542
562
  old_start: number | null;
543
- }, {}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{
563
+ }, {}, {}>>[0]) => _ai_sdk_provider_utils.Experimental_ToolCallerTool<_ai_sdk_provider_utils.ProviderExecutedTool<{
544
564
  type: "programmatic-tool-call";
545
565
  code: string;
546
566
  } | {
@@ -602,7 +622,7 @@ declare const anthropicTools: {
602
622
  new_start: number | null;
603
623
  old_lines: number | null;
604
624
  old_start: number | null;
605
- }, {}>;
625
+ }, {}>>;
606
626
  /**
607
627
  * Claude can analyze data, create visualizations, perform complex calculations,
608
628
  * run system commands, create and edit files, and process uploaded files directly within
@@ -686,7 +706,7 @@ declare const anthropicTools: {
686
706
  new_start: number | null;
687
707
  old_lines: number | null;
688
708
  old_start: number | null;
689
- }, {}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{
709
+ }, {}, {}>>[0]) => _ai_sdk_provider_utils.Experimental_ToolCallerTool<_ai_sdk_provider_utils.ProviderExecutedTool<{
690
710
  type: "programmatic-tool-call";
691
711
  code: string;
692
712
  } | {
@@ -757,7 +777,7 @@ declare const anthropicTools: {
757
777
  new_start: number | null;
758
778
  old_lines: number | null;
759
779
  old_start: number | null;
760
- }, {}>;
780
+ }, {}>>;
761
781
  /**
762
782
  * Claude can interact with computer environments through the computer use tool, which
763
783
  * provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.
@@ -1203,13 +1223,13 @@ interface AnthropicProvider extends ProviderV4 {
1203
1223
  /**
1204
1224
  * Creates a model for text generation.
1205
1225
  */
1206
- (modelId: AnthropicModelId): LanguageModelV4;
1226
+ (modelId: AnthropicModelId): Experimental_BatchLanguageModelV4;
1207
1227
  /**
1208
1228
  * Creates a model for text generation.
1209
1229
  */
1210
- languageModel(modelId: AnthropicModelId): LanguageModelV4;
1211
- chat(modelId: AnthropicModelId): LanguageModelV4;
1212
- messages(modelId: AnthropicModelId): LanguageModelV4;
1230
+ languageModel(modelId: AnthropicModelId): Experimental_BatchLanguageModelV4;
1231
+ chat(modelId: AnthropicModelId): Experimental_BatchLanguageModelV4;
1232
+ messages(modelId: AnthropicModelId): Experimental_BatchLanguageModelV4;
1213
1233
  /**
1214
1234
  * @deprecated Use `embeddingModel` instead.
1215
1235
  */
@@ -1284,4 +1304,4 @@ declare function forwardAnthropicContainerIdFromLastStep({ steps, }: {
1284
1304
 
1285
1305
  declare const VERSION: string;
1286
1306
 
1287
- export { type AnthropicLanguageModelOptions, type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicLanguageModelOptions as AnthropicProviderOptions, type AnthropicProviderSettings, type AnthropicToolOptions, type AnthropicUsageIteration, VERSION, anthropic, createAnthropic, forwardAnthropicContainerIdFromLastStep };
1307
+ export { type AnthropicLanguageModelOptions, type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicLanguageModelOptions as AnthropicProviderOptions, type AnthropicProviderSettings, type AnthropicSystemMessageProviderOptions, type AnthropicToolOptions, type AnthropicUsageIteration, VERSION, anthropic, createAnthropic, forwardAnthropicContainerIdFromLastStep };