eve 0.29.2 → 0.29.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/src/channel/types.d.ts +15 -0
- package/dist/src/cli/commands/integration-setup.d.ts +3 -7
- package/dist/src/cli/commands/integration-setup.js +1 -1
- package/dist/src/cli/commands/registry.d.ts +1 -0
- package/dist/src/cli/commands/registry.js +1 -1
- package/dist/src/cli/commands/trace.d.ts +7 -24
- package/dist/src/cli/commands/trace.js +7 -5
- package/dist/src/cli/dev/tui/blocks.js +1 -1
- package/dist/src/cli/dev/tui/clipboard.d.ts +17 -0
- package/dist/src/cli/dev/tui/clipboard.js +1 -0
- package/dist/src/cli/dev/tui/command-typeahead.js +1 -1
- package/dist/src/cli/dev/tui/prompt-commands.d.ts +3 -0
- package/dist/src/cli/dev/tui/prompt-commands.js +1 -1
- package/dist/src/cli/dev/tui/remote-auth.js +1 -1
- package/dist/src/cli/dev/tui/runner.d.ts +6 -0
- package/dist/src/cli/dev/tui/runner.js +1 -1
- package/dist/src/cli/dev/tui/stream-format.d.ts +8 -0
- package/dist/src/cli/dev/tui/stream-format.js +1 -1
- package/dist/src/cli/dev/tui/terminal-renderer.d.ts +3 -0
- package/dist/src/cli/dev/tui/terminal-renderer.js +12 -12
- package/dist/src/cli/dev/tui/test/mock-terminal.js +3 -3
- package/dist/src/cli/dev/tui/traces/trace-content.d.ts +28 -0
- package/dist/src/cli/dev/tui/traces/trace-content.js +2 -0
- package/dist/src/cli/dev/tui/traces/trace-conversation.d.ts +58 -0
- package/dist/src/cli/dev/tui/traces/trace-conversation.js +2 -0
- package/dist/src/cli/dev/tui/traces/trace-store.d.ts +27 -0
- package/dist/src/cli/dev/tui/traces/trace-store.js +1 -0
- package/dist/src/cli/dev/tui/traces/trace-view.d.ts +48 -0
- package/dist/src/cli/dev/tui/traces/trace-view.js +2 -0
- package/dist/src/cli/dev/tui/traces/trace-viewer-session.d.ts +41 -0
- package/dist/src/cli/dev/tui/traces/trace-viewer-session.js +1 -0
- package/dist/src/cli/dev/tui/traces/trace-viewer-state.d.ts +110 -0
- package/dist/src/cli/dev/tui/traces/trace-viewer-state.js +1 -0
- package/dist/src/cli/ui/alt-screen.d.ts +42 -0
- package/dist/src/cli/ui/alt-screen.js +1 -0
- package/dist/src/cli/ui/terminal-text.d.ts +4 -0
- package/dist/src/cli/ui/terminal-text.js +1 -1
- package/dist/src/compiled/.vendor-stamp.json +2 -1
- package/dist/src/compiled/@photon-ai/chat-adapter-imessage/LICENSE +21 -0
- package/dist/src/compiled/@photon-ai/chat-adapter-imessage/_spectrum-core.d.ts +3 -0
- package/dist/src/compiled/@photon-ai/chat-adapter-imessage/_spectrum-imessage.d.ts +2 -0
- package/dist/src/compiled/@photon-ai/chat-adapter-imessage/index.d.ts +496 -0
- package/dist/src/compiled/@photon-ai/chat-adapter-imessage/index.js +137 -0
- package/dist/src/compiled/@vercel/sandbox/index.js +13 -107
- package/dist/src/compiled/_chunks/node/auth-BS3UoyvT.js +2 -0
- package/dist/src/compiled/_chunks/node/compat-Dm2n85Mx.js +1 -0
- package/dist/src/compiled/_chunks/node/schemas-DtQwuPdM.js +65 -0
- package/dist/src/compiled/_chunks/node/undici-DWL_MYmT.js +95 -0
- package/dist/src/compiled/_chunks/node/version-Cztrk7z6.js +1 -0
- package/dist/src/compiled/shadcn-registry/index.js +461 -893
- package/dist/src/context/keys.d.ts +3 -1
- package/dist/src/context/keys.js +1 -1
- package/dist/src/execution/delegated-parent-notification.js +1 -1
- package/dist/src/execution/delegated-parent-result.js +1 -1
- package/dist/src/execution/dispatch-runtime-actions-step.js +1 -1
- package/dist/src/execution/runtime-context.js +1 -1
- package/dist/src/execution/sandbox/glob-tool.js +3 -3
- package/dist/src/execution/sandbox/grep-tool.js +1 -1
- package/dist/src/execution/sandbox/read-file-tool.js +3 -3
- package/dist/src/execution/sandbox/require-sandbox.d.ts +3 -3
- package/dist/src/execution/sandbox/require-sandbox.js +1 -1
- package/dist/src/execution/sandbox/write-file-tool.js +1 -1
- package/dist/src/execution/subagent-adapter-state.d.ts +39 -0
- package/dist/src/execution/subagent-adapter-state.js +1 -0
- package/dist/src/execution/subagent-adapter.d.ts +0 -34
- package/dist/src/execution/subagent-adapter.js +1 -1
- package/dist/src/execution/subagent-tool.d.ts +2 -1
- package/dist/src/execution/subagent-tool.js +1 -1
- package/dist/src/execution/workflow-steps.js +1 -1
- package/dist/src/harness/instrumentation-lifecycle.d.ts +18 -0
- package/dist/src/harness/instrumentation-native-events.d.ts +3 -1
- package/dist/src/harness/instrumentation-native-events.js +1 -1
- package/dist/src/harness/parent-lineage.d.ts +11 -0
- package/dist/src/harness/parent-lineage.js +1 -0
- package/dist/src/harness/tool-loop.js +2 -2
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/nitro/host/local-tracing-runtime-plugin.js +1 -1
- package/dist/src/packages/eve-catalog/src/index.js +1 -1
- package/dist/src/public/channels/chat-sdk/chatSdkChannel.d.ts +7 -0
- package/dist/src/public/channels/chat-sdk/chatSdkChannel.js +2 -2
- package/dist/src/public/channels/photon/inboundContent.d.ts +4 -0
- package/dist/src/public/channels/photon/inboundContent.js +1 -0
- package/dist/src/public/channels/photon/index.d.ts +1 -0
- package/dist/src/public/channels/photon/index.js +1 -0
- package/dist/src/public/channels/photon/photonIMessageChannel.d.ts +54 -0
- package/dist/src/public/channels/photon/photonIMessageChannel.js +1 -0
- package/dist/src/runtime/channels/registry.js +1 -1
- package/dist/src/runtime/framework-tools/glob.js +1 -1
- package/dist/src/runtime/framework-tools/grep.js +1 -1
- package/dist/src/runtime/framework-tools/read-file.js +1 -1
- package/dist/src/runtime/framework-tools/write-file.js +1 -1
- package/dist/src/setup/boxes/resolve-provisioning.js +1 -1
- package/dist/src/setup/connect-provisioning.d.ts +32 -0
- package/dist/src/setup/connect-provisioning.js +1 -0
- package/dist/src/setup/flows/login.js +1 -1
- package/dist/src/setup/flows/registry.js +1 -1
- package/dist/src/setup/integrations/photon/connect.d.ts +40 -0
- package/dist/src/setup/integrations/photon/connect.js +1 -0
- package/dist/src/setup/integrations/photon/management.d.ts +34 -0
- package/dist/src/setup/integrations/photon/management.js +1 -0
- package/dist/src/setup/integrations/photon/setup-flow.d.ts +39 -0
- package/dist/src/setup/integrations/photon/setup-flow.js +20 -0
- package/dist/src/setup/integrations/photon/setup.d.ts +3 -0
- package/dist/src/setup/integrations/photon/setup.js +1 -0
- package/dist/src/setup/integrations/registry.d.ts +6 -0
- package/dist/src/setup/integrations/registry.js +1 -0
- package/dist/src/setup/integrations/runner.d.ts +25 -0
- package/dist/src/setup/integrations/runner.js +1 -0
- package/dist/src/setup/integrations/{channels → shared}/environment.d.ts +3 -3
- package/dist/src/setup/integrations/shared/environment.js +1 -0
- package/dist/src/setup/integrations/shared/scaffold.d.ts +19 -0
- package/dist/src/setup/integrations/shared/scaffold.js +1 -0
- package/dist/src/setup/integrations/{channels → shared}/ui.d.ts +3 -3
- package/dist/src/setup/integrations/shared/ui.js +2 -0
- package/dist/src/setup/integrations/slack/setup.d.ts +16 -0
- package/dist/src/setup/integrations/slack/setup.js +1 -0
- package/dist/src/setup/integrations/types.d.ts +26 -0
- package/dist/src/setup/integrations/web/setup.d.ts +3 -0
- package/dist/src/setup/integrations/web/setup.js +1 -0
- package/dist/src/setup/primitives/run-vercel.d.ts +2 -7
- package/dist/src/setup/primitives/run-vercel.js +1 -1
- package/dist/src/setup/scaffold/create/add-to-project.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +2 -2
- package/dist/src/setup/scaffold/update/channels.js +1 -1
- package/dist/src/setup/scaffold/update/connections.js +1 -1
- package/dist/src/setup/slack-connect-lifecycle.d.ts +2 -8
- package/dist/src/setup/slack-connect-lifecycle.js +1 -1
- package/dist/src/setup/state.d.ts +0 -12
- package/dist/src/setup/state.js +1 -1
- package/dist/src/shared/skill-paths.d.ts +10 -0
- package/dist/src/shared/skill-paths.js +2 -2
- package/dist/src/tracing/agent-otel-content.d.ts +32 -0
- package/dist/src/tracing/agent-otel-content.js +4 -0
- package/dist/src/{harness → tracing}/agent-otel-provider.d.ts +10 -1
- package/dist/src/tracing/agent-otel-provider.js +2 -0
- package/dist/src/{harness → tracing}/agent-trace-context-store.d.ts +8 -1
- package/dist/src/tracing/agent-trace-context-store.js +1 -0
- package/dist/src/{harness → tracing}/agent-trace-span-processor.d.ts +5 -1
- package/dist/src/tracing/agent-trace-span-processor.js +1 -0
- package/dist/src/tracing/local-instrumentation-runtime.js +1 -0
- package/dist/src/tracing/local-trace-reader.d.ts +57 -0
- package/dist/src/tracing/local-trace-reader.js +1 -0
- package/dist/src/{harness → tracing}/local-trace-retention.js +1 -1
- package/dist/src/{harness → tracing}/local-trace-span-processor.js +1 -1
- package/docs/channels/chat-sdk.mdx +18 -1
- package/docs/channels/meta.json +1 -0
- package/docs/channels/overview.mdx +1 -1
- package/docs/channels/photon.mdx +78 -0
- package/docs/concepts/default-harness.md +2 -0
- package/docs/guides/dev-tui.md +20 -1
- package/docs/guides/instrumentation.md +8 -7
- package/docs/reference/cli.md +9 -1
- package/docs/sandbox.mdx +1 -1
- package/package.json +7 -1
- package/dist/src/compiled/_chunks/node/auth-DMsLOrh7.js +0 -2
- package/dist/src/compiled/_chunks/node/version-BQBAL95V.js +0 -64
- package/dist/src/harness/agent-otel-provider.js +0 -1
- package/dist/src/harness/agent-trace-context-store.js +0 -1
- package/dist/src/harness/agent-trace-span-processor.js +0 -1
- package/dist/src/harness/local-instrumentation-runtime.js +0 -1
- package/dist/src/setup/integrations/channels/environment.js +0 -1
- package/dist/src/setup/integrations/channels/index.d.ts +0 -7
- package/dist/src/setup/integrations/channels/index.js +0 -1
- package/dist/src/setup/integrations/channels/runner.d.ts +0 -7
- package/dist/src/setup/integrations/channels/runner.js +0 -1
- package/dist/src/setup/integrations/channels/setup.d.ts +0 -130
- package/dist/src/setup/integrations/channels/setup.js +0 -2
- package/dist/src/setup/integrations/channels/slack.d.ts +0 -3
- package/dist/src/setup/integrations/channels/slack.js +0 -1
- package/dist/src/setup/integrations/channels/types.d.ts +0 -49
- package/dist/src/setup/integrations/channels/ui.js +0 -2
- package/dist/src/setup/integrations/channels/web.d.ts +0 -3
- package/dist/src/setup/integrations/channels/web.js +0 -1
- /package/dist/src/setup/integrations/{channels/types.js → types.js} +0 -0
- /package/dist/src/{harness → tracing}/local-instrumentation-runtime.d.ts +0 -0
- /package/dist/src/{harness → tracing}/local-trace-retention.d.ts +0 -0
- /package/dist/src/{harness → tracing}/local-trace-span-processor.d.ts +0 -0
|
@@ -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{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{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{
|
|
2
|
-
`);if(this.#
|
|
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,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{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 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;#$;#ee=!0;#te=0;#ne=Date.now();#re;#ie;#ae;#oe=!1;#se;#ce=``;#le=new StringDecoder(`utf8`);#ue;#de;#fe;#pe=!1;#me=!1;#he;#ge;#_e;#ve;#ye;#be;#xe;#Se=``;#Ce=``;#we;#Te;#Ee=0;#De;#Oe;#ke;#Ae;#je;#Me;#Ne=new MessageQueue;#Pe;#Fe=!1;#Ie;#Le;#Re=!1;#ze;#Be;#Ve;#He;setupFlow={begin:(e,t)=>this.#Je(e,t),end:e=>this.#Ye(e?.preserveDiagnostics??!0),readSelect:e=>this.#Xe(e),readEditableSelect:e=>this.#Qe(e),readProviderPicker:e=>this.#$e(e),readModelEditor:e=>this.#et(e),readText:e=>this.#tt(e),readAcknowledge:e=>this.#nt(e),readChoice:e=>this.#Ze(e),setStatus:e=>this.#ut(e),renderLine:(e,t)=>this.#dt(e,t),renderOutput:e=>this.#ft(e),withInheritedStdio:e=>this.#pt(e),withExclusiveTerminal:e=>this.#pt(e),waitForInterrupt:e=>this.#st(e)};traceViewer={open:e=>this.#ht(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.#_e=t?.contextSize,this.#u=t?.captureForeignOutput??this.#t===process.stdout,this.#d=t?.diagnostics,this.#$=t?.onExitRequest,this.#p=t?.logs??`none`,this.#f=t?.availablePromptCommands??PROMPT_COMMANDS}renderAgentHeader(e){this.#q=e.name,this.#w=e,this.#vt();let t=this.#on().join(`
|
|
2
|
+
`);if(this.#T){t!==this.#E&&(this.#E=t,this.#Pt({kind:`agent-header`,body:t,live:!1})),this.#tn();return}this.#T=!0,this.#E=t,this.#n.flush(this.#on(),[])}async readPrompt(e){this.#vt(e),this.#Nt(),this.#It(),this.#F=!0,this.#L=!0,this.#U={kind:`idle`},this.#G=``;let r=this.#Ne.restoreDraft()?.split(`
|
|
3
3
|
`).map(stripPromptControlCharacters).join(`
|
|
4
|
-
`),i=stripPromptControlCharacters(e?.initialDraft??this.#B.text),a=lineOf(r===void 0?i:i.length===0?r:`${r}\n\n${i}`);return this.#B=EMPTY_LINE,this.#N.begin(a.text),this.#Ve(a),this.#F=typeaheadFor(this.#d,a.text),this.#Ct(),this.#Xt(),await new Promise((e,r)=>{this.#U=r;let apply=e=>{a=e,this.#Tt(),this.#Ve(a),this.#F=typeaheadFor(this.#d,e.text,this.#F),this.#Xt()},recall=e=>{e!==void 0&&apply(lineOf(e))},interrupt=()=>{this.#F=void 0,this.#wt(),this.#ht(),r(interruptedError())},suggestions=()=>this.#F!==void 0&&isTypeaheadOpen(this.#F)?this.#F:void 0,highlighted=()=>{let e=suggestions();return e===void 0?void 0:selectedTypeaheadCommand(e)};this.#oe=r=>{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.#F=moveTypeaheadSelection(e,-1),this.#Xt();break}let t=movePromptLine(a,`up`);t===void 0?recall(this.#N.previous(a.text)):apply(t);break}case`down`:case`ctrl-n`:{let e=suggestions();if(e!==void 0){this.#F=moveTypeaheadSelection(e,1),this.#Xt();break}let t=movePromptLine(a,`down`);t===void 0?recall(this.#N.next()):apply(t);break}case`tab`:{let e=highlighted();e!==void 0&&apply(lineOf(typeaheadCompletion(e)));break}case`escape`:{let e=suggestions();e!==void 0&&(this.#F=dismissTypeahead(e),this.#Xt());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.#F=void 0,this.#N.add(i),this.#P=!1,this.#wt(),this.#W=STATUS.processing,isPromptControlCommand(i)?this.#kt({kind:`command`,body:stripTerminalControls(i.trim()),live:!1}):(this.#Dt(),this.#At(i),this.#Ee=i,this.#z.arm()),this.#Ve(EMPTY_LINE),this.#Xt(),this.#_t(),e(i);break}case`ctrl-d`:a.text.length===0?(this.#ft(),interrupt()):apply(deleteForward(a));break;case`ctrl-l`:this.#$t();break;case`ctrl-r`:this.#Xt();break;case`ctrl-c`:a.text.length===0?(this.#ft(),interrupt()):apply(EMPTY_LINE);break;default:break}},this.#gt()})}#Ve(e){this.#j=e.text,this.#M=e.cursor}takeQueuedPrompt(){let e=this.#Me.view().steering,t=this.#Me.takePrompt();return t!==void 0&&(this.#Ie=e?`steer`:`queue`),t}async renderStream(e,t){this.#pt(t),this.#h.clear(),this.#P=!1,this.#H.kind!==`waiting`&&(this.#H={kind:`waiting`,startedAtMs:Date.now()}),this.#W=this.#O>0?STATUS.connectionAuth:STATUS.processing,this.#Mt(t?.submittedPrompt),t?.submittedPrompt!==void 0&&this.#u?.recordPrompt(),t?.submittedPrompt!==void 0&&!this.#z.armed&&this.#z.arm(),this.#X=!1,this.#Pe=!1,this.#Le=!1,this.#Re=t?.submittedPrompt,this.#Me.beginTurn(),this.#Ne=e.cancel,this.#me=void 0,this.#he=void 0,this.#_e=void 0,this.#ve=void 0,this.#ye=Date.now();let n={tools:t?.tools??this.#i,reasoning:t?.reasoning??this.#a,assistantResponseStats:t?.assistantResponseStats??this.#c};this.#Et(),this.#V=!0,this.#Xt();let r=new Promise(e=>{this.#de=e});this.#oe=e=>this.#St(e),this.#gt();let i={text:new Map,reasoning:new Map,tools:new Map};try{for await(let t of takeUntil(iterateTUIStream(e.events),r)){if(this.#X)break;this.#Rt(t,n,i)}}catch(e){let t=summarizeKnownError(e);t===null?this.#Nt(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#Nt(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#de=void 0,this.#X&&e.abort?.(),this.#Ne=void 0,this.#_t(),this.#Ot(),this.#V=!1,this.#H.kind===`waiting`&&(this.#H={kind:`idle`}),this.#W=completedTurnStatus({interrupted:this.#X,cancelled:this.#Pe,continueSession:t?.continueSession===!0}),this.#Gt(i),(this.#X||this.#Pe)&&this.#Wt(),this.#Lt(),this.#u?.reportStats(),this.#Xt(),t?.continueSession||this.#ht()}}async readToolApproval(e,t){return this.#pt(t),this.#Ot(),this.#P=!1,this.#H={kind:`idle`},this.#W=`Approve ${formatToolApprovalTitle(e)}? (y/n)`,this.#X=!1,this.#Xt(),await new Promise((t,n)=>{this.#U=n,this.#oe=r=>{switch(r.type){case`text`:{if(r.framing!==`unframed`)break;let n=r.value.toLowerCase();n===`y`?(this.#Dt(),this.#W=STATUS.processing,this.#_t(),this.#Xt(),t({approved:!0})):n===`n`&&(this.#Dt(),this.#W=STATUS.processing,this.#Ue(e.toolCallId),this.#_t(),this.#Xt(),t({approved:!1,reason:`Denied by user.`}));break}case`ctrl-r`:this.#Xt();break;case`ctrl-c`:this.#X=!0,this.#ht(),n(interruptedError());break;default:break}},this.#gt()})}async readInputQuestion(e,t){this.#pt(t),this.#Ot(),this.#P=!1,this.#I=!1,this.#H={kind:`idle`},this.#X=!1;let n=e.options??[],r=n.length>0,i=(e.allowFreeform===!0||!r)&&r,a=n.length+ +!!i,o=questionSectionId(e.requestId),s=r?`overlay`:`text`,c=0,l=EMPTY_LINE,isOnFreeformRow=()=>i&&c===n.length,overlayPanel=t=>renderQuestionPanel({prompt:stripTerminalControls(e.prompt),options:n,cursor:c,allowFreeform:i,editor:l,caretVisible:this.#$},this.#r,t),renderTextSection=()=>{this.#Ft({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:formatQuestionContent(e,void 0,this.#r),preformatted:!0,live:!0})},syncFreeformCaret=()=>{isOnFreeformRow()?this.#Ct():(this.#wt(),this.#Tt())};s===`overlay`?(s=`overlay`,this.#P=!1,this.#It(o),this.#De=overlayPanel,this.#W=``,syncFreeformCaret(),this.#Xt()):(s=`text`,this.#De=void 0,renderTextSection(),this.#P=!0,this.#Ve(l),this.#W=``,this.#Ct(),this.#Xt());let finalize=t=>{this.#De=void 0,this.#Ft({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#r.colors.dim(this.#r.glyph.elbow)} ${stripTerminalControls(t.label)}`,preformatted:!0,live:!1}),this.#P=!1,this.#Dt(),this.#W=STATUS.processing,this.#wt(),this.#_t(),this.#Xt();let n={};return t.optionId!==void 0&&(n.optionId=t.optionId),t.text!==void 0&&(n.text=t.text),n},dismiss=()=>{this.#De=void 0,this.#Ft({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#r.colors.dim(this.#r.glyph.elbow)} ${this.#r.colors.dim(`Dismissed.`)}`,preformatted:!0,live:!1}),this.#P=!1,this.#W=``,this.#wt(),this.#_t(),this.#Xt(),u(void 0)},moveCursor=e=>{a!==0&&(c=(c+e+a)%a,syncFreeformCaret(),this.#Xt())},selectOptionAt=e=>{let t=n[e];t&&u(finalize({optionId:t.id,label:t.label}))},u;return await new Promise((t,r)=>{this.#U=r,u=t,this.#oe=t=>{if(t.type===`ctrl-c`){if((s===`text`||isOnFreeformRow())&&l.text.length>0){l=EMPTY_LINE,this.#Tt(),s===`text`&&this.#Ve(l),this.#Xt();return}this.#X=!0,this.#De=void 0,this.#wt(),this.#ht(),r(interruptedError());return}if(t.type===`ctrl-r`){this.#Xt();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.#Tt(),this.#Xt();break}dismiss();break;default:if(isOnFreeformRow()){let e=applyLineEditorKey(l,t);e!==void 0&&(l=e,this.#Tt(),this.#Xt());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.#Xt())}break}return}let a=applyLineEditorKey(l,t,{multiline:!0});if(a!==void 0){l=a,this.#Tt(),this.#Ve(l),this.#Xt();return}switch(t.type){case`up`:case`down`:{let e=movePromptLine(l,t.type);e!==void 0&&(l=e,this.#Tt(),this.#Ve(l),this.#Xt());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.#Tt(),this.#Ve(l),this.#Xt();break}dismiss();break;default:break}},this.#gt()})}upsertSubagentStep(e){if(this.#u?.recordSubagentDispatch(e.callId),this.#o===`hidden`)return;let t=stripTerminalControls(e.reasoning??``).trim(),n=stripTerminalControls(e.message??``).trim();if(!(t.length===0&&n.length===0)){if(this.#Pt(e.callId,e.subagentName),this.#o===`collapsed`){this.#Xt();return}this.#Ft({id:subagentStepSectionId(e.callId,e.sectionKey),kind:`subagent-step`,subagentCallId:e.callId,depth:1,reasoning:t,body:n,collapsed:this.#o!==`full`,live:!e.finalized}),this.#Xt()}}upsertSubagentTool(e){if(this.#u?.recordSubagentDispatch(e.callId),e.status===`failed`&&e.errorText!==void 0&&this.#u?.append({source:`tool`,summary:`${e.toolName} failed (subagent ${e.subagentName})`,detail:e.errorText}),this.#o===`hidden`)return;if(this.#Pt(e.callId,e.subagentName),this.#o===`collapsed`){this.#Xt();return}let t=subagentToolStatus(e.status),n=e.status===`preparing`?presentPreparingTool(e.toolName):presentTool(e.toolName,e.input,this.#Ht({input:e.input,output:e.output,toolCallId:e.childCallId,toolName:e.toolName})),r={id:subagentToolSectionId(e.callId,e.childCallId),kind:`subagent-tool`,subagentCallId:e.callId,depth:1,title:stripTerminalControls(n.title),subtitle:stripTerminalControls(n.subtitle),status:t,live:t===`running`||t===`approval`,expanded:this.#o===`full`,toolName:e.toolName,toolGroup:n.group,toolInput:e.input};n.doneTitle!==void 0&&(r.doneTitle=stripTerminalControls(n.doneTitle)),n.detail!==void 0&&(r.detailLines=n.detail,r.keepDetailWhenDone=n.keepDetailWhenDone===!0),e.output===void 0?e.errorText!==void 0&&(r.result=stripTerminalControls(e.errorText)):(r.result=n.summarizeResult(e.output),r.toolOutput=e.output),this.#Ft(r),this.#He(e.callId),this.#Xt()}#He(e){applyCohortLiveness(this.#p.filter(t=>t.kind===`subagent-tool`&&t.subagentCallId===e).map(e=>({block:e,active:isActiveToolStatus(e.status)})))}removeSubagentTool(e){this.#It(subagentToolSectionId(e.callId,e.childCallId)),this.#Xt()}subagents={begin:e=>this.beginSubagent(e),upsertStep:e=>this.upsertSubagentStep(e),upsertTool:e=>this.upsertSubagentTool(e),removeTool:e=>this.removeSubagentTool(e),complete:e=>this.completeSubagent(e),markChildToolCallId:e=>this.markChildToolCallId(e)};beginSubagent(e){if(this.#o===`hidden`)return;this.#Pt(e.callId,e.name);let t=this.#m.get(subagentHeaderId(e.callId));t?.status===`done`&&delete t.status,this.#Xt()}completeSubagent(e){let t=this.#m.get(subagentHeaderId(e.callId));t!==void 0&&(t.status=`done`,this.#Xt())}markChildToolCallId(e){this.#_.add(e);let t=this.#v.get(e);t!==void 0&&(this.#It(t),this.#v.delete(e),this.#Xt())}#Ue(e){let t=this.#m.get(toolSectionId(e));t!==void 0&&(t.status=`denied`,t.live=!1)}upsertConnectionAuth(e){if(this.#s===`hidden`)return;let t=connectionAuthTerminalMessage(e.state);this.#Ft({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.#Xt()}setConnectionAuthPendingCount(e){let t=Math.max(0,e);if(t===this.#O)return;let n=this.#O>0;this.#O=t,t>0?(this.#W=STATUS.connectionAuth,this.#Xt()):n&&(this.#W=STATUS.processing,this.#Xt())}setVercelStatus(e){this.#k=e,this.#Xt()}setRemoteConnectionStatus(e){this.#A=e,this.#Xt()}reset(){this.#p=[],this.#m.clear(),this.#h.clear(),this.#D=void 0,this.#E.length=0,this.#g.length=0,this.#w=!1,this.#T=void 0,this.#We(),this.#R=!1,this.#Ee=void 0,this.#we=void 0,this.#O=0,this.#me=void 0,this.#he=void 0,this.#_e=void 0,this.#ve=void 0,this.#ye=void 0,this.#q&&(this.#n.clearAll(),this.#Xt())}renderSessionBoundary(){this.#jt(),this.#We();let e=this.#r.colors,t=this.#r.glyph,n=e.dim(`${t.cornerOpen}${t.dash.repeat(2)} Session restarted, clear context.`);this.#kt({kind:`session-boundary`,body:n,live:!1}),this.#Xt()}#We(){this.#_.clear(),this.#v.clear(),this.#S.clear(),this.#b.clear(),this.#Ae=void 0,this.#je=void 0,this.#Me.reset(),this.#Ie=void 0,this.#x.clear(),this.#z.reset()}renderNotice(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#pt(),this.#kt({kind:`notice`,body:t,live:!1}),this.#Xt())}renderSandboxLog(e){let t=parseSandboxLogLine(stripTerminalControls(e));t!==void 0&&(this.#u?.append({source:`sandbox`,detail:t}),this.#pt(),this.#kt({kind:`sandbox`,body:t,live:!1}),this.#Xt())}renderSetupWarning(e){let t=stripTerminalControls(e);if(t.trim().length===0){this.#Ge();return}this.#pt(),this.#ke=t,this.#Xt()}clearSetupWarning(){this.#Ge()}#Ge(){this.#ke!==void 0&&(this.#ke=void 0,this.#Xt())}renderCommandInvocation(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;this.#pt();let r={kind:`command`,body:n,live:!1};t===`failed`&&(r.status=`error`),this.#kt(r),this.#Xt()}renderCommandResult(e,t){let n=stripTerminalControls(e);n.trim().length!==0&&(this.#pt(),this.#kt(t===void 0?{kind:`result`,body:n,live:!1}:{kind:`flow`,title:t,body:n,live:!1}),this.#Xt())}#Ke(e,t=`spinner`){this.#pt(),this.#P=!1,this.#H={kind:`idle`},this.#W=``;let n=t===`pulse`?{kind:`pulse`,startedAtMs:Date.now()}:{kind:`spinner`};this.#Oe={title:stripTerminalControls(e),indicator:n,lines:[],outputBuffer:[]},this.#Et(),this.#Xt()}#qe(e){this.#ze=void 0,this.#st();let t=this.#Oe;if(t!==void 0){if(this.#Oe=void 0,this.#Ot(),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.#kt({kind:`flow`,title:`info`,body:e.join(`
|
|
5
|
-
`),live:!1}),this.#
|
|
6
|
-
`,` `))e>=` `&&e!==``&&dispatch({type:`char`,char:e})}).promise}async#$e(e){let t=this.#tt(),n=lineOf(``),r;return t.question=t=>{let i={message:e.message,editor:n,mask:e.mask===!0};return e.placeholder!==void 0&&(i.placeholder=e.placeholder),e.notices!==void 0&&(i.notices=e.notices),r!==void 0&&(i.error=r),renderTextQuestion(i,this.#r,t,this.#$)},this.#Ct(),this.#Xt(),await this.#it((t,i)=>{let apply=e=>{n=e,r=void 0,this.#Tt(),this.#Xt()},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.#Xt();return;case`enter`:{let t=n.text.length>0?n.text:e.defaultValue??``,a=e.validate?.(t);if(a!==void 0){r=a,this.#Xt();return}i(t);return}default:return}},()=>this.#wt()).promise}async#et(e){let t=this.#tt();return t.question=t=>renderAcknowledgeQuestion({message:e.message,lines:e.lines},this.#r,t),this.#Xt(),await this.#it((e,t)=>{switch(e.type){case`enter`:case`escape`:case`ctrl-c`:t();return;case`ctrl-r`:this.#Xt();return;default:return}}).promise}#tt(){return this.#pt(),this.#P=!1,this.#H={kind:`idle`},this.#W=``,this.#nt()}#nt(){return this.#Oe===void 0&&(this.#Oe={title:``,indicator:{kind:`spinner`},lines:[],outputBuffer:[],implicit:!0}),this.#Oe}#rt(){this.#Oe?.implicit===!0?this.#Oe=void 0:this.#Oe!==void 0&&(this.#Oe.question=void 0,this.#Oe.hideLinesWhileQuestion=!1),this.#oe=void 0,this.#_t(),this.#Oe!==void 0&&this.#ot(),this.#Xt()}#it(e,t){let n=!1,r,i,a=new Promise((e,t)=>{r=e,i=t}),settle=e=>{n||(n=!0,t?.(),this.#rt(),r(e))},reject=e=>{n||(n=!0,t?.(),this.#rt(),i(e))};return this.#xt(),this.#oe=t=>{t.type===`ctrl-c`&&this.#ft(),e(t,settle,reject)},this.#gt(),{promise:a,settle}}#at(e){let t,n=new Promise(e=>{t=e});return this.#ze=t,this.#ot(e?.interruptible??!0),{promise:n,dispose:()=>{this.#ze===t&&(this.#ze=void 0,this.#st())}}}#ot(e=!0){if(this.#ze===void 0)return;let consumer=t=>{if(e&&(t.type===`ctrl-c`||t.type===`escape`)){t.type===`ctrl-c`&&this.#ft();let e=this.#ze;this.#ze=void 0,this.#st(),e?.();return}t.type===`ctrl-r`&&this.#Xt()};this.#Be=consumer,this.#xt(),this.#oe=consumer,this.#gt()}#st(){this.#Be!==void 0&&(this.#oe===this.#Be&&this.#_t(),this.#Be=void 0)}#ct(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.#Oe!==void 0){this.#Oe.status=t,t===void 0&&(this.#Oe.preview=void 0),this.#Xt();return}if(!(this.#P||this.#V)){if(t===void 0){this.#H={kind:`idle`},this.#G=void 0,this.#Ot(),this.#Xt();return}this.#pt(),this.#Dt(),this.#G=t.text,this.#Xt()}}#lt(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;let r=this.#Oe;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.#Xt();return}this.#pt(),this.#kt({kind:`flow`,title:t,body:n,live:!1}),this.#Xt()}#ut(e){let t=stripTerminalControls(e);if(t.trim().length===0)return;let n=this.#Oe;if(n===void 0){this.#lt(t,`info`);return}n.preview=t,n.outputBuffer.push(t),n.outputBuffer.length>40&&n.outputBuffer.shift(),this.#Xt()}async#dt(e){this.#se=``,this.#xt(),this.#ze=void 0,this.#st(),this.#_t(),this.#Ot(),this.#n.clear(),this.#n.showCursor(),this.#vn(),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.#se=``,this.#xt(),this.#n.hideCursor(),this.#_n(),this.#Oe!==void 0&&(this.#Et(),this.#ot()),this.#n.reset(),this.#Xt()}}setSessionId(e){this.#Fe=e}shutdown(){if(this.#ht(),this.#J&&!this.#Y){this.#Y=!0;let e=this.#Fe===void 0?``:` ${this.#r.glyph.dot} session ${this.#Fe}`;this.#t.write(`${this.#r.colors.dim(`${eveVersionTag()}${e}`)}\n`)}}requestInterrupt(){this.#X=!0,this.#Oe!==void 0&&this.#oe?.({type:`ctrl-c`}),this.#de?.(),this.#ht()}exitRequested(){return this.#Z}#ft(){this.#Z=!0,this.#Q?.()}#pt(e){this.#K=e?.title??this.#K,e?.contextSize!==void 0&&(this.#ge=e.contextSize),!this.#q&&(this.#q=!0,this.#J=!0,this.#n.reset(),this.#n.hideCursor(),this.#_n(),this.#e.isTTY&&(this.#e.setRawMode?.(!0),this.#e.resume(),this.#n.emitBracketedPaste(!0)),this.#ue=()=>this.#Xt(),this.#t.on(`resize`,this.#ue),process.on(`exit`,this.#mt))}#mt=()=>{this.#q&&(this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1)),this.#n.showCursor())};#ht(){let e=this.#U;if(this.#U=void 0,e?.(interruptedError()),this.#_t(),this.#wt(),this.#Ot(),this.#ie!==void 0&&(clearTimeout(this.#ie),this.#ie=void 0),this.#ae=!1,this.#q){this.#En();for(let e of this.#p)e.kind===`log`&&e.id===void 0&&(e.live=!1);this.#Xt(),this.#n.clear(),this.#n.showCursor(),this.#vn(),this.#n.newline(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1),this.#e.pause()),this.#ue&&=(this.#t.off(`resize`,this.#ue),void 0),process.off(`exit`,this.#mt),this.#q=!1}}#gt(){this.#e.off(`data`,this.#vt),this.#e.on(`data`,this.#vt),this.#se.length>0&&queueMicrotask(()=>{this.#oe!==void 0&&this.#se.length>0&&(this.#bt(),this.#yt())})}#_t(){this.#e.off(`data`,this.#vt),this.#xt(),this.#oe=void 0}#vt=e=>{this.#xt(),this.#se+=this.#ce.write(e),this.#bt(),this.#yt()};#yt(){if(this.#se===`\x1B`){this.#le=setTimeout(()=>{this.#se===`\x1B`&&(this.#se=``,this.#oe?.({type:`escape`}))},30),this.#le.unref?.();return}if(isIncompletePaste(this.#se)){let e=this.#se;this.#le=setTimeout(()=>{if(this.#se!==e)return;let t=sanitizePastedText(stripPasteStart(e));this.#se=``,t.length>0&&this.#oe?.({type:`text`,value:t,framing:`bracketed-paste`})},1e3),this.#le.unref?.()}}#bt(){for(;this.#se.length>0;){let e=nextKey(this.#se);if(e.incomplete)return;this.#se=this.#se.slice(e.consumed),e.key&&e.key.type!==`ignore`&&this.#oe?.(e.key)}}#xt(){this.#le&&=(clearTimeout(this.#le),void 0)}#St(e){switch(e.type){case`ctrl-l`:case`ctrl-r`:this.#Xt();break;case`ctrl-c`:this.#X||(this.#X=!0,this.#H={kind:`idle`},this.#W=`Interrupted`,this.#de?.(),this.#Xt());break;case`enter`:{let e=this.#B.text;if(e.trim().length===0)break;this.#Me.enqueue(e)&&(this.#B=EMPTY_LINE),this.#Xt();break}case`escape`:{if(this.#Me.idle&&this.#Ne===void 0)break;let e=this.#Me.handleEscape();(e===`steer`||e===`cancel`)&&(this.#Le=!0,this.#Ne?.()),this.#Xt();break}default:{this.#Me.disarm();let t=applyLineEditorKey(this.#B,e,{multiline:!0});t!==void 0&&(this.#B=t,this.#Xt());break}}}#Ct(){this.#wt(),this.#Tt(),this.#ne=setInterval(()=>{this.#$=!this.#$,this.#Xt()},500),this.#ne.unref?.()}#wt(){this.#ne&&=(clearInterval(this.#ne),void 0),this.#$=!0}#Tt(){this.#$=!0}#Et(){this.#Ot(),this.#re=setInterval(()=>{this.#ee+=1,this.#Xt()},90),this.#re.unref?.()}#Dt(){let e=Date.now();this.#te=e,this.#H={kind:`waiting`,startedAtMs:e},this.#Et()}#Ot(){this.#re&&=(clearInterval(this.#re),void 0)}#kt(e){e.id!==this.#we?.id&&this.#En(),e.updateSeq=++this.#y,this.#p.push(e),e.id&&this.#m.set(e.id,e)}#At(e){this.#R=!0,this.#kt({kind:`user`,body:stripTerminalControls(e),live:!1}),this.#Xt()}#jt(){let e=this.#z.settle();if(e===void 0||e.elapsedMs<=1e4&&e.inputTokens<=2e4)return;let t=`Done in ${this.#cn(e.elapsedMs)}`,n=this.#he??0;if(this.#ge!==void 0&&this.#ge>0&&n>0){let e=Math.round(n/this.#ge*100);t+=` ${this.#r.glyph.dot} ${e}% context`}this.#kt({kind:`turn-stats`,body:t,live:!1})}#Mt(e){if(e==null)return;let t=this.#Ie;if(this.#Ie=void 0,this.#Ee===e){this.#Ee=void 0;return}let n={kind:`user`,body:stripTerminalControls(e),live:!1};t!==void 0&&(n.promptOrigin=t),this.#kt(n)}#Nt(e,t,n={}){let r=stripTerminalControls(e),i=stripTerminalControls(t),a=n.detail===void 0?void 0:stripTerminalControls(n.detail),o=n.hint===void 0?void 0:stripTerminalControls(n.hint),s={source:`workflow`,summary:`${r}: ${i}`,detail:a??i};this.#u?.append(o===void 0?s:{...s,hint:o});let c={kind:`error`,title:r,body:i,live:!1};o!==void 0&&(c.hint=o),a!==void 0&&(c.detail=this.#u===void 0?a:`details: ${this.#u.displayPath}`),this.#kt(c),this.#Xt()}#Pt(e,t){if(this.#S.has(e))return;this.#S.add(e);let n=stripTerminalControls(t),r=this.#b.get(n)??[];if(r.push(e),this.#b.set(n,r),r.length===2){let e=this.#m.get(subagentHeaderId(r[0]));e!==void 0&&(e.subtitle=`#1`)}let i={id:subagentHeaderId(e),kind:`subagent`,subagentCallId:e,title:n,live:!0};r.length>1&&(i.subtitle=`#${r.length}`),this.#kt(i)}#Ft(e){if(e.id&&this.#h.has(e.id))return;let t=e.id?this.#m.get(e.id):void 0;if(t){Object.assign(t,e),t.updateSeq=++this.#y;return}this.#kt(e)}#It(e){this.#p=this.#p.filter(t=>t.id!==e),this.#m.delete(e)}#Lt(){for(let e of this.#p)e.status===`approval`||e.status===`running`||e.kind===`connection-auth`&&e.live||(e.live=!1)}#Rt(e,t,n){switch(e.type){case`step-finish`:this.#u?.recordStepUsage(e.usage),e.usage!==void 0&&this.#z.addUsage(e.usage),this.#Gt(n),this.#Yt(e.usage),this.#Xt();break;case`assistant-delta`:{let t=(n.text.get(e.id)??``)+stripTerminalControls(e.delta);n.text.set(e.id,t),this.#zt(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.#zt(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.#Bt(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.#Bt(e.id,r,!1,t);break}break}case`tool-call-preparing`:if(t.tools===`hidden`||isPanelRoutedTool(e.toolName))break;this.#Vt({input:void 0,preparing:!0,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-call`:if(this.#u?.recordToolCall(e.toolName),t.tools===`hidden`)break;this.#Vt({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.#Vt({...r,status:`approval`},t,n);break}case`tool-result`:{if(t.tools===`hidden`)break;let r=this.#Jt(e.toolCallId,n);if(r===void 0)break;this.#Vt({...r,output:e.output,status:`done`},t,n);break}case`tool-error`:{let r=this.#Jt(e.toolCallId,n);if(this.#u?.append({source:`tool`,summary:`${r?.toolName??e.toolCallId} failed`,detail:e.errorText}),t.tools===`hidden`||r===void 0)break;this.#Vt({...r,errorText:e.errorText,status:`error`},t,n);break}case`tool-rejected`:{if(t.tools===`hidden`)break;let r=this.#Jt(e.toolCallId,n);if(r===void 0)break;this.#Vt({...r,errorText:e.reason,status:`denied`},t,n);break}case`error`:this.#Nt(`Error`,e.errorText,{detail:e.detail,hint:e.hint});break;case`turn-cancelled`:this.#Pe=!0,!this.#Le&&this.#Re!==void 0&&this.#B.text.length===0&&(this.#B=lineOf(this.#Re),this.renderNotice(`The turn was cancelled from outside this prompt — the message was restored to the input.`));break;case`finish`:this.#Yt(e.usage),this.#Xt();break}}#zt(e,t,n){let r=stripTerminalControls(t).trim();r.length!==0&&(this.#Ft({id:e,kind:`assistant`,body:r,live:n}),this.#Xt())}#Bt(e,t,n,r){let i=stripTerminalControls(t).trim();i.length!==0&&(this.#Ft({id:e,kind:`reasoning`,body:i,collapsed:collapseReasoning(r.reasoning,n),live:n}),this.#Xt())}#Vt(e,t,n){if(n.tools.set(e.toolCallId,e),this.#_.has(e.toolCallId)||this.#Kt(e)||toolBaseName(e.toolName)===`ask_question`)return;let r=toolSectionId(e.toolCallId);this.#v.set(e.toolCallId,r);let i=this.#Ht(e);this.#Ft(renderNativeToolBlock(e,r,t.tools===`full`,i)),this.#qt(n),this.#Xt()}#Ht(e){e.output!==void 0&&this.#x.observeRead(e.output);let t={};this.#Ut(e.toolName)&&(t.isSubagent=!0);let n=readWriteFileInput(e.toolName,e.input);if(n===void 0)return t.isSubagent===!0?t:void 0;let r=this.#x.observeWrite({path:n.path,content:n.content,callId:e.toolCallId});r!==void 0&&(t.previousContent=r);let i=writeExistedFlag(e.output);return i!==void 0&&(t.existed=i),t}#Ut(e){let t=this.#C?.info?.subagents.local;if(t===void 0||t.length===0)return!1;let n=toolBaseName(e);return t.some(e=>e.name===n)}#Wt(){for(let e of this.#p)e.kind!==`tool`&&e.kind!==`subagent-tool`||e.status===`running`&&(e.status=`error`,e.result=`interrupted`,e.live=!1)}#Gt(e){for(let[t,n]of e.tools){if(n.preparing!==!0)continue;e.tools.delete(t);let r=this.#v.get(t)??toolSectionId(t);this.#It(r),this.#v.delete(t)}}#Kt(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.#je!==e&&(this.#je=e,this.#kt({kind:`todo-list`,body:renderFinishedTodoRows(t,this.#hn(),this.#r).join(`
|
|
7
|
-
`),live:!1})),this.#
|
|
8
|
-
`),i=r===-1?n:n.slice(r+1);if(e===`stdout`?this.#
|
|
9
|
-
`);t=[],e.trim().length!==0&&this.#
|
|
10
|
-
`)){let e=parseSandboxLogLine(n.trimEnd());if(e!==void 0){flushPending(),this.#
|
|
11
|
-
`),n=t.findIndex(e=>parseDevRebuildLogLine(e.trimEnd())?.kind===`failed`);if(n===-1){if(this.#
|
|
12
|
-
`);r.trim().length>0&&this.#
|
|
13
|
-
`);this.#
|
|
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.#Ue(a),this.#I=typeaheadFor(this.#f,a.text),this.#Ot(),this.#tn(),await new Promise((e,r)=>{this.#W=r;let apply=e=>{a=e,this.#At(),this.#Ue(a),this.#I=typeaheadFor(this.#f,e.text,this.#I),this.#tn()},recall=e=>{e!==void 0&&apply(lineOf(e))},interrupt=()=>{this.#I=void 0,this.#kt(),this.#bt(),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.#se=r=>{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.#tn();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.#tn();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.#tn());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.#kt(),this.#G=STATUS.processing,isPromptControlCommand(i)?this.#Pt({kind:`command`,body:stripTerminalControls(i.trim()),live:!1}):(this.#Mt(),this.#Ft(i),this.#De=i,this.#B.arm()),this.#Ue(EMPTY_LINE),this.#tn(),this.#St(),e(i);break}case`ctrl-d`:a.text.length===0?(this.#mt(),interrupt()):apply(deleteForward(a));break;case`ctrl-l`:this.#in();break;case`ctrl-r`:this.#tn();break;case`ctrl-c`:a.text.length===0?(this.#mt(),interrupt()):apply(EMPTY_LINE);break;default:break}},this.#xt()})}#Ue(e){this.#M=e.text,this.#N=e.cursor}takeQueuedPrompt(){let e=this.#Ne.view().steering,t=this.#Ne.takePrompt();return t!==void 0&&(this.#Le=e?`steer`:`queue`),t}async renderStream(e,t){this.#vt(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.#Lt(t?.submittedPrompt),t?.submittedPrompt!==void 0&&this.#d?.recordPrompt(),t?.submittedPrompt!==void 0&&!this.#B.armed&&this.#B.arm(),this.#Z=!1,this.#Fe=!1,this.#Re=!1,this.#ze=t?.submittedPrompt,this.#Ne.beginTurn(),this.#Pe=e.cancel,this.#he=void 0,this.#ge=void 0,this.#ve=void 0,this.#ye=void 0,this.#be=Date.now();let n={tools:t?.tools??this.#a,reasoning:t?.reasoning??this.#o,assistantResponseStats:t?.assistantResponseStats??this.#l};this.#jt(),this.#H=!0,this.#tn();let r=new Promise(e=>{this.#fe=e});this.#se=e=>this.#Dt(e),this.#xt();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.#Ut(t,n,i)}}catch(e){let t=summarizeKnownError(e);t===null?this.#Rt(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#Rt(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#fe=void 0,this.#Z&&e.abort?.(),this.#Pe=void 0,this.#St(),this.#Nt(),this.#H=!1,this.#U.kind===`waiting`&&(this.#U={kind:`idle`}),this.#G=completedTurnStatus({interrupted:this.#Z,cancelled:this.#Fe,continueSession:t?.continueSession===!0}),this.#Xt(i),(this.#Z||this.#Fe)&&this.#Yt(),this.#Ht(),this.#d?.reportStats(),this.#tn(),t?.continueSession||this.#bt()}}async readToolApproval(e,t){return this.#vt(t),this.#Nt(),this.#F=!1,this.#U={kind:`idle`},this.#G=`Approve ${formatToolApprovalTitle(e)}? (y/n)`,this.#Z=!1,this.#tn(),await new Promise((t,n)=>{this.#W=n,this.#se=r=>{switch(r.type){case`text`:{if(r.framing!==`unframed`)break;let n=r.value.toLowerCase();n===`y`?(this.#Mt(),this.#G=STATUS.processing,this.#St(),this.#tn(),t({approved:!0})):n===`n`&&(this.#Mt(),this.#G=STATUS.processing,this.#Ge(e.toolCallId),this.#St(),this.#tn(),t({approved:!1,reason:`Denied by user.`}));break}case`ctrl-r`:this.#tn();break;case`ctrl-c`:this.#Z=!0,this.#bt(),n(interruptedError());break;default:break}},this.#xt()})}async readInputQuestion(e,t){this.#vt(t),this.#Nt(),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.#ee},this.#i,t),renderTextSection=()=>{this.#Bt({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:formatQuestionContent(e,void 0,this.#i),preformatted:!0,live:!0})},syncFreeformCaret=()=>{isOnFreeformRow()?this.#Ot():(this.#kt(),this.#At())};s===`overlay`?(s=`overlay`,this.#F=!1,this.#Vt(o),this.#Oe=overlayPanel,this.#G=``,syncFreeformCaret(),this.#tn()):(s=`text`,this.#Oe=void 0,renderTextSection(),this.#F=!0,this.#Ue(l),this.#G=``,this.#Ot(),this.#tn());let finalize=t=>{this.#Oe=void 0,this.#Bt({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.#Mt(),this.#G=STATUS.processing,this.#kt(),this.#St(),this.#tn();let n={};return t.optionId!==void 0&&(n.optionId=t.optionId),t.text!==void 0&&(n.text=t.text),n},dismiss=()=>{this.#Oe=void 0,this.#Bt({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.#kt(),this.#St(),this.#tn(),u(void 0)},moveCursor=e=>{a!==0&&(c=(c+e+a)%a,syncFreeformCaret(),this.#tn())},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.#se=t=>{if(t.type===`ctrl-c`){if((s===`text`||isOnFreeformRow())&&l.text.length>0){l=EMPTY_LINE,this.#At(),s===`text`&&this.#Ue(l),this.#tn();return}this.#Z=!0,this.#Oe=void 0,this.#kt(),this.#bt(),r(interruptedError());return}if(t.type===`ctrl-r`){this.#tn();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.#At(),this.#tn();break}dismiss();break;default:if(isOnFreeformRow()){let e=applyLineEditorKey(l,t);e!==void 0&&(l=e,this.#At(),this.#tn());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.#tn())}break}return}let a=applyLineEditorKey(l,t,{multiline:!0});if(a!==void 0){l=a,this.#At(),this.#Ue(l),this.#tn();return}switch(t.type){case`up`:case`down`:{let e=movePromptLine(l,t.type);e!==void 0&&(l=e,this.#At(),this.#Ue(l),this.#tn());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.#At(),this.#Ue(l),this.#tn();break}dismiss();break;default:break}},this.#xt()})}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.#zt(e.callId,e.subagentName),this.#s===`collapsed`){this.#tn();return}this.#Bt({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.#tn()}}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.#zt(e.callId,e.subagentName),this.#s===`collapsed`){this.#tn();return}let t=subagentToolStatus(e.status),n=e.status===`preparing`?presentPreparingTool(e.toolName):presentTool(e.toolName,e.input,this.#qt({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.#Bt(r),this.#We(e.callId),this.#tn()}#We(e){applyCohortLiveness(this.#m.filter(t=>t.kind===`subagent-tool`&&t.subagentCallId===e).map(e=>({block:e,active:isActiveToolStatus(e.status)})))}removeSubagentTool(e){this.#Vt(subagentToolSectionId(e.callId,e.childCallId)),this.#tn()}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.#zt(e.callId,e.name);let t=this.#h.get(subagentHeaderId(e.callId));t?.status===`done`&&delete t.status,this.#tn()}completeSubagent(e){let t=this.#h.get(subagentHeaderId(e.callId));t!==void 0&&(t.status=`done`,this.#tn())}markChildToolCallId(e){this.#v.add(e);let t=this.#y.get(e);t!==void 0&&(this.#Vt(t),this.#y.delete(e),this.#tn())}#Ge(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.#Bt({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.#tn()}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.#tn()):n&&(this.#G=STATUS.processing,this.#tn())}setVercelStatus(e){this.#A=e,this.#tn()}setRemoteConnectionStatus(e){this.#j=e,this.#tn()}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.#Ke(),this.#z=!1,this.#De=void 0,this.#Te=void 0,this.#k=0,this.#he=void 0,this.#ge=void 0,this.#ve=void 0,this.#ye=void 0,this.#be=void 0,this.#J&&(this.#n.clearAll(),this.#tn())}renderSessionBoundary(){this.#It(),this.#Ke();let e=this.#i.colors,t=this.#i.glyph,n=e.dim(`${t.cornerOpen}${t.dash.repeat(2)} Session restarted, clear context.`);this.#Pt({kind:`session-boundary`,body:n,live:!1}),this.#tn()}#Ke(){this.#v.clear(),this.#y.clear(),this.#C.clear(),this.#x.clear(),this.#je=void 0,this.#Me=void 0,this.#Ne.reset(),this.#Le=void 0,this.#S.clear(),this.#B.reset()}renderNotice(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#vt(),this.#Pt({kind:`notice`,body:t,live:!1}),this.#tn())}renderSandboxLog(e){let t=parseSandboxLogLine(stripTerminalControls(e));t!==void 0&&(this.#d?.append({source:`sandbox`,detail:t}),this.#vt(),this.#Pt({kind:`sandbox`,body:t,live:!1}),this.#tn())}renderSetupWarning(e){let t=stripTerminalControls(e);if(t.trim().length===0){this.#qe();return}this.#vt(),this.#Ae=t,this.#tn()}clearSetupWarning(){this.#qe()}#qe(){this.#Ae!==void 0&&(this.#Ae=void 0,this.#tn())}renderCommandInvocation(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;this.#vt();let r={kind:`command`,body:n,live:!1};t===`failed`&&(r.status=`error`),this.#Pt(r),this.#tn()}renderCommandResult(e,t){let n=stripTerminalControls(e);n.trim().length!==0&&(this.#vt(),this.#Pt(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.#tn())}#Je(e,t=`spinner`){this.#vt(),this.#F=!1,this.#U={kind:`idle`},this.#G=``;let n=t===`pulse`?{kind:`pulse`,startedAtMs:Date.now()}:{kind:`spinner`};this.#ke={title:stripTerminalControls(e),indicator:n,lines:[],outputBuffer:[]},this.#jt(),this.#tn()}#Ye(e){this.#Be=void 0,this.#lt();let t=this.#ke;if(t!==void 0){if(this.#ke=void 0,this.#Nt(),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.#Pt({kind:`flow`,title:`info`,body:e.join(`
|
|
5
|
+
`),live:!1}),this.#Pt({kind:`flow`,title:n.tone,body:n.text,live:!1})),e=[]}}this.#tn()}}async#Xe(e){let t=this.#rt(),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.#tn()},loadSearch=async(e,t)=>{c=!0,s=void 0;let a=++l;this.#tn();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.#tn())}},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.#cn()),t};return t.question=e=>renderSelectQuestion(panelState(),this.#i,e),this.#tn(),await this.#ot((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.#tn();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.#tn();return;case`update`:o=d.select,s=void 0,this.#tn();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.#tn();return;case`ignore`:return}}).promise}#Ze(e){this.#vt();let t=this.#it();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.#tn();let r=this.#ot((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.#tn();return;case`repaint`:this.#tn();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#Qe(e){let t=this.#rt(),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.#ee,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.#Ot():(i=lineOf(``),this.#kt())};return syncEditableRow(),this.#tn(),await this.#ot((t,n)=>{let applyEditor=e=>{i=e,a=void 0,this.#At(),this.#tn()},applySelect=t=>{r=reduceSelect(r,t,{options:e.options}),a=void 0,syncEditableRow(),this.#tn()},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.#tn();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.#tn();return;case void 0:break}if(!onEditableRow())return;let s=applyLineEditorKey(i,t);s!==void 0&&applyEditor(s)},()=>this.#kt()).promise}async#$e(e){let t=this.#rt(),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.#ee,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.#Ot():this.#kt()};return syncCaret(),this.#tn(),await this.#ot((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.#tn();return;case`cancel`:i(void 0);return;case`render`:n=o.state,syncCaret(),this.#tn();return;case`validate`:{n=o.state,syncCaret(),this.#tn();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.#tn();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.#At(),dispatch({type:`edit`,editor:s}))},()=>{r?.abort(),r=void 0,this.#kt()}).promise}async#et(e){let t=this.#rt(),n=initialModelEditorState(e);return t.question=t=>renderModelEditorQuestion({request:e,state:n},this.#i,t),this.#tn(),await this.#ot((t,r)=>{let dispatch=t=>{let i=transitionModelEditor(n,t,e);switch(i.kind){case`ignore`:return;case`render`:n=i.state,this.#tn();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.#tn();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#tt(e){let t=this.#rt(),n=lineOf(``),r;return t.question=t=>{let i={message:e.message,editor:n,mask:e.mask===!0};return e.placeholder!==void 0&&(i.placeholder=e.placeholder),e.notices!==void 0&&(i.notices=e.notices),r!==void 0&&(i.error=r),renderTextQuestion(i,this.#i,t,this.#ee)},this.#Ot(),this.#tn(),await this.#ot((t,i)=>{let apply=e=>{n=e,r=void 0,this.#At(),this.#tn()},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.#tn();return;case`enter`:{let t=n.text.length>0?n.text:e.defaultValue??``,a=e.validate?.(t);if(a!==void 0){r=a,this.#tn();return}i(t);return}default:return}},()=>this.#kt()).promise}async#nt(e){let t=this.#rt();return t.question=t=>renderAcknowledgeQuestion({message:e.message,lines:e.lines},this.#i,t),this.#tn(),await this.#ot((e,t)=>{switch(e.type){case`enter`:case`escape`:case`ctrl-c`:t();return;case`ctrl-r`:this.#tn();return;default:return}}).promise}#rt(){return this.#vt(),this.#F=!1,this.#U={kind:`idle`},this.#G=``,this.#it()}#it(){return this.#ke===void 0&&(this.#ke={title:``,indicator:{kind:`spinner`},lines:[],outputBuffer:[],implicit:!0}),this.#ke}#at(){this.#ke?.implicit===!0?this.#ke=void 0:this.#ke!==void 0&&(this.#ke.question=void 0,this.#ke.hideLinesWhileQuestion=!1),this.#se=void 0,this.#St(),this.#ke!==void 0&&this.#ct(),this.#tn()}#ot(e,t){let n=!1,r,i,a=new Promise((e,t)=>{r=e,i=t}),settle=e=>{n||(n=!0,t?.(),this.#at(),r(e))},reject=e=>{n||(n=!0,t?.(),this.#at(),i(e))};return this.#Et(),this.#se=t=>{t.type===`ctrl-c`&&this.#mt(),e(t,settle,reject)},this.#xt(),{promise:a,settle}}#st(e){let t,n=new Promise(e=>{t=e});return this.#Be=t,this.#ct(e?.interruptible??!0),{promise:n,dispose:()=>{this.#Be===t&&(this.#Be=void 0,this.#lt())}}}#ct(e=!0){if(this.#Be===void 0)return;let consumer=t=>{if(e&&(t.type===`ctrl-c`||t.type===`escape`)){t.type===`ctrl-c`&&this.#mt();let e=this.#Be;this.#Be=void 0,this.#lt(),e?.();return}t.type===`ctrl-r`&&this.#tn()};this.#Ve=consumer,this.#Et(),this.#se=consumer,this.#xt()}#lt(){this.#Ve!==void 0&&(this.#se===this.#Ve&&this.#St(),this.#Ve=void 0)}#ut(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.#ke!==void 0){this.#ke.status=t,t===void 0&&(this.#ke.preview=void 0),this.#tn();return}if(!(this.#F||this.#H)){if(t===void 0){this.#U={kind:`idle`},this.#K=void 0,this.#Nt(),this.#tn();return}this.#vt(),this.#Mt(),this.#K=t.text,this.#tn()}}#dt(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;let r=this.#ke;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.#tn();return}this.#vt(),this.#Pt({kind:`flow`,title:t,body:n,live:!1}),this.#tn()}#ft(e){let t=stripTerminalControls(e);if(t.trim().length===0)return;let n=this.#ke;if(n===void 0){this.#dt(t,`info`);return}n.preview=t,n.outputBuffer.push(t),n.outputBuffer.length>40&&n.outputBuffer.shift(),this.#tn()}async#pt(e){this.#ce=``,this.#Et(),this.#Be=void 0,this.#lt(),this.#St(),this.#Nt(),this.#n.clear(),this.#n.showCursor(),this.#Cn(),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.#ce=``,this.#Et(),this.#n.hideCursor(),this.#Sn(),this.#ke!==void 0&&(this.#jt(),this.#ct()),this.#n.reset(),this.#tn()}}setSessionId(e){this.#Ie=e}shutdown(){if(this.#bt(),this.#Y&&!this.#X){this.#X=!0;let e=this.#Ie===void 0?``:` ${this.#i.glyph.dot} session ${this.#Ie}`;this.#t.write(`${this.#i.colors.dim(`${eveVersionTag()}${e}`)}\n`)}}requestInterrupt(){this.#Z=!0,this.#ke!==void 0&&this.#se?.({type:`ctrl-c`}),this.#fe?.(),this.#bt()}exitRequested(){return this.#Q}#mt(){this.#Q=!0,this.#$?.()}async#ht(e){if(this.#He!==void 0||!this.#J)return;let t=new TraceViewerSession({...e,theme:this.#i,dimensions:()=>({width:this.#bn(),height:this.#xn()}),paint:e=>this.#r.paint(e,this.#xn()),tracingDisabled:process.env.EVE_TRACES===`off`,copyText:e=>copyTextToClipboard(e,e=>this.#r.writeRaw(e))});this.#He=t,this.#r.enter(),await new Promise(e=>{this.#_t=e,this.#se=e=>{t.handleKey(e)===`close`&&this.#gt()},this.#xt(),t.start()})}#gt(){let e=this.#He;if(e===void 0)return;this.#He=void 0,e.dispose(),this.#St(),this.#r.exit(),this.#n.hideCursor(),this.#tn(),this.#n.showCursor();let t=this.#_t;this.#_t=void 0,t?.()}#_t;#vt(e){this.#q=e?.title??this.#q,e?.contextSize!==void 0&&(this.#_e=e.contextSize),!this.#J&&(this.#J=!0,this.#Y=!0,this.#n.reset(),this.#n.hideCursor(),this.#Sn(),this.#e.isTTY&&(this.#e.setRawMode?.(!0),this.#e.resume(),this.#n.emitBracketedPaste(!0)),this.#de=()=>this.#tn(),this.#t.on(`resize`,this.#de),process.on(`exit`,this.#yt))}#yt=()=>{this.#J&&(this.#r.exit(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1)),this.#n.showCursor())};#bt(){this.#gt();let e=this.#W;if(this.#W=void 0,e?.(interruptedError()),this.#St(),this.#kt(),this.#Nt(),this.#ae!==void 0&&(clearTimeout(this.#ae),this.#ae=void 0),this.#oe=!1,this.#J){this.#jn();for(let e of this.#m)e.kind===`log`&&e.id===void 0&&(e.live=!1);this.#tn(),this.#n.clear(),this.#n.showCursor(),this.#Cn(),this.#n.newline(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1),this.#e.pause()),this.#de&&=(this.#t.off(`resize`,this.#de),void 0),process.off(`exit`,this.#yt),this.#J=!1}}#xt(){this.#e.off(`data`,this.#Ct),this.#e.on(`data`,this.#Ct),this.#ce.length>0&&queueMicrotask(()=>{this.#se!==void 0&&this.#ce.length>0&&(this.#Tt(),this.#wt())})}#St(){this.#e.off(`data`,this.#Ct),this.#Et(),this.#se=void 0}#Ct=e=>{this.#Et(),this.#ce+=this.#le.write(e),this.#Tt(),this.#wt()};#wt(){if(this.#ce===`\x1B`){this.#ue=setTimeout(()=>{this.#ce===`\x1B`&&(this.#ce=``,this.#se?.({type:`escape`}))},30),this.#ue.unref?.();return}if(isIncompletePaste(this.#ce)){let e=this.#ce;this.#ue=setTimeout(()=>{if(this.#ce!==e)return;let t=sanitizePastedText(stripPasteStart(e));this.#ce=``,t.length>0&&this.#se?.({type:`text`,value:t,framing:`bracketed-paste`})},1e3),this.#ue.unref?.()}}#Tt(){for(;this.#ce.length>0;){let e=nextKey(this.#ce);if(e.incomplete)return;this.#ce=this.#ce.slice(e.consumed),e.key&&e.key.type!==`ignore`&&this.#se?.(e.key)}}#Et(){this.#ue&&=(clearTimeout(this.#ue),void 0)}#Dt(e){switch(e.type){case`ctrl-l`:case`ctrl-r`:this.#tn();break;case`ctrl-c`:this.#Z||(this.#Z=!0,this.#U={kind:`idle`},this.#G=`Interrupted`,this.#fe?.(),this.#tn());break;case`enter`:{let e=this.#V.text;if(e.trim().length===0)break;this.#Ne.enqueue(e)&&(this.#V=EMPTY_LINE),this.#tn();break}case`escape`:{if(this.#Ne.idle&&this.#Pe===void 0)break;let e=this.#Ne.handleEscape();(e===`steer`||e===`cancel`)&&(this.#Re=!0,this.#Pe?.()),this.#tn();break}default:{this.#Ne.disarm();let t=applyLineEditorKey(this.#V,e,{multiline:!0});t!==void 0&&(this.#V=t,this.#tn());break}}}#Ot(){this.#kt(),this.#At(),this.#re=setInterval(()=>{this.#ee=!this.#ee,this.#tn()},500),this.#re.unref?.()}#kt(){this.#re&&=(clearInterval(this.#re),void 0),this.#ee=!0}#At(){this.#ee=!0}#jt(){this.#Nt(),this.#ie=setInterval(()=>{this.#te+=1,this.#tn()},90),this.#ie.unref?.()}#Mt(){let e=Date.now();this.#ne=e,this.#U={kind:`waiting`,startedAtMs:e},this.#jt()}#Nt(){this.#ie&&=(clearInterval(this.#ie),void 0)}#Pt(e){e.id!==this.#Te?.id&&this.#jn(),e.updateSeq=++this.#b,this.#m.push(e),e.id&&this.#h.set(e.id,e)}#Ft(e){this.#z=!0,this.#Pt({kind:`user`,body:stripTerminalControls(e),live:!1}),this.#tn()}#It(){let e=this.#B.settle();if(e===void 0||e.elapsedMs<=1e4&&e.inputTokens<=2e4)return;let t=`Done in ${this.#pn(e.elapsedMs)}`,n=this.#ge??0;if(this.#_e!==void 0&&this.#_e>0&&n>0){let e=Math.round(n/this.#_e*100);t+=` ${this.#i.glyph.dot} ${e}% context`}this.#Pt({kind:`turn-stats`,body:t,live:!1})}#Lt(e){if(e==null)return;let t=this.#Le;if(this.#Le=void 0,this.#De===e){this.#De=void 0;return}let n={kind:`user`,body:stripTerminalControls(e),live:!1};t!==void 0&&(n.promptOrigin=t),this.#Pt(n)}#Rt(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.#Pt(c),this.#tn()}#zt(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.#Pt(i)}#Bt(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.#Pt(e)}#Vt(e){this.#m=this.#m.filter(t=>t.id!==e),this.#h.delete(e)}#Ht(){for(let e of this.#m)e.status===`approval`||e.status===`running`||e.kind===`connection-auth`&&e.live||(e.live=!1)}#Ut(e,t,n){switch(e.type){case`step-finish`:this.#d?.recordStepUsage(e.usage),e.usage!==void 0&&this.#B.addUsage(e.usage),this.#Xt(n),this.#en(e.usage),this.#tn();break;case`assistant-delta`:{let t=(n.text.get(e.id)??``)+stripTerminalControls(e.delta);n.text.set(e.id,t),this.#Wt(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.#Wt(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.#Gt(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.#Gt(e.id,r,!1,t);break}break}case`tool-call-preparing`:if(t.tools===`hidden`||isPanelRoutedTool(e.toolName))break;this.#Kt({input:void 0,preparing:!0,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-call`:if(this.#d?.recordToolCall(e.toolName),t.tools===`hidden`)break;this.#Kt({input:e.input,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-approval-request`:{if(t.tools===`hidden`)break;let r=n.tools.get(e.toolCallId);if(r===void 0)break;this.#Kt({...r,status:`approval`},t,n);break}case`tool-result`:{if(t.tools===`hidden`)break;let r=this.#$t(e.toolCallId,n);if(r===void 0)break;this.#Kt({...r,output:e.output,status:`done`},t,n);break}case`tool-error`:{let r=this.#$t(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.#Kt({...r,errorText:e.errorText,status:`error`},t,n);break}case`tool-rejected`:{if(t.tools===`hidden`)break;let r=this.#$t(e.toolCallId,n);if(r===void 0)break;this.#Kt({...r,errorText:e.reason,status:`denied`},t,n);break}case`error`:this.#Rt(`Error`,e.errorText,{detail:e.detail,hint:e.hint});break;case`turn-cancelled`:this.#Fe=!0,!this.#Re&&this.#ze!==void 0&&this.#V.text.length===0&&(this.#V=lineOf(this.#ze),this.renderNotice(`The turn was cancelled from outside this prompt — the message was restored to the input.`));break;case`finish`:this.#en(e.usage),this.#tn();break}}#Wt(e,t,n){let r=stripTerminalControls(t).trim();r.length!==0&&(this.#Bt({id:e,kind:`assistant`,body:r,live:n}),this.#tn())}#Gt(e,t,n,r){let i=stripTerminalControls(t).trim();i.length!==0&&(this.#Bt({id:e,kind:`reasoning`,body:i,collapsed:collapseReasoning(r.reasoning,n),live:n}),this.#tn())}#Kt(e,t,n){if(n.tools.set(e.toolCallId,e),this.#v.has(e.toolCallId)||this.#Zt(e)||toolBaseName(e.toolName)===`ask_question`)return;let r=toolSectionId(e.toolCallId);this.#y.set(e.toolCallId,r);let i=this.#qt(e);this.#Bt(renderNativeToolBlock(e,r,t.tools===`full`,i)),this.#Qt(n),this.#tn()}#qt(e){e.output!==void 0&&this.#S.observeRead(e.output);let t={};this.#Jt(e.toolName)&&(t.isSubagent=!0);let n=readWriteFileInput(e.toolName,e.input);if(n===void 0)return t.isSubagent===!0?t:void 0;let r=this.#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}#Jt(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)}#Yt(){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)}#Xt(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.#Vt(r),this.#y.delete(t)}}#Zt(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.#Me!==e&&(this.#Me=e,this.#Pt({kind:`todo-list`,body:renderFinishedTodoRows(t,this.#bn(),this.#i).join(`
|
|
7
|
+
`),live:!1})),this.#je=void 0}else this.#je=t.length>0?t:void 0,this.#Me=void 0;return this.#tn(),!0}#Qt(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)}#$t(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`}}#en(e){if(e===void 0)return;let{inputTokens:t,outputTokens:n}=e;if((t!=null||n!=null)&&(this.#he=(t??0)+(n??0)),this.#ge=t??this.#ge,this.#ve=n??this.#ve,this.#ve!=null&&this.#be!==void 0){let e=(Date.now()-this.#be)/1e3;e>0&&(this.#ye=this.#ve/e)}}#tn(){if(this.#J){if(this.#pe){this.#me=!0;return}this.#pe=!0;try{do this.#me=!1,this.#nn();while(this.#me)}finally{this.#pe=!1}}}#nn(){if(!this.#J)return;if(this.#He!==void 0){this.#He.repaint();return}let e=this.#bn(),t=this.#dn(e),n=Math.max(1,this.#xn()-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.#Nn(t.display))continue;let n=this.#sn(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.#Nn(t))continue;let n=this.#sn(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)}#rn(){if(!this.#J)return;let e=this.#bn(),t=this.#dn(e),n=Math.max(1,this.#xn()-t.length),r=this.#O,i=[];for(let{display:t}of groupToolBlocksForDisplay(this.#m)){if(this.#Nn(t))continue;let n=this.#sn(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.#on(),...this.#D],a)}logDisplayMode(){return this.#p}setLogDisplayMode(e){e!==this.#p&&(this.#p=e,e===`all`&&this.flushDelayedDevBuildErrors(),this.#an(),this.#J&&this.#rn())}flushDelayedDevBuildErrors(){let e=this.#we;e!==void 0&&(this.#we=void 0,this.#Pt({kind:`log`,title:`stderr`,body:e,live:!0}),this.#tn())}#in(){this.#oe=!0,this.#ae!==void 0&&clearTimeout(this.#ae),this.#ae=setTimeout(()=>{this.#oe=!1,this.#ae=void 0,this.#tn()},5e3),this.setLogDisplayMode(nextLogDisplayMode(this.#p)),this.#tn()}#an(){let e=this.#bn();this.#D.length=0;let t;for(let{display:n}of groupToolBlocksForDisplay(this.#_,{logCoalescing:`runs`})){if(this.#Nn(n))continue;let r=this.#sn(n,e,t);t=previousBlockOf(n),this.#D.push(...r)}this.#O=t}#on(){let e=this.#w;if(e===void 0)return[];let t={name:e.name,theme:this.#i,width:this.#bn()};return e.info!==void 0&&(t.info=e.info),e.tip!==void 0&&(t.tip=e.tip),buildAgentHeader(t)}#sn(e,t,n){let r={activityPulse:this.#ln(this.#ne,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}#cn(){return this.#i.spinner[this.#te%this.#i.spinner.length]??``}#ln(e,t){return isProgressPulseVisible(Date.now()-e)?t:` `}#un(e,t){return e.indicator.kind===`spinner`?{glyph:this.#cn(),color:`yellow`}:{glyph:this.#ln(e.indicator.startedAtMs,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH),color:t?.kind===`external-action`?`yellow`:`green`}}#dn(e){let n=this.#i.colors,r=[``];if(this.#Oe!==void 0)return r.push(...this.#Oe(e),``),this.#_n(r,e),r;let a=this.#ke;if(a!==void 0){let t=this.#un(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.#vn(r,e),r}this.#Ae!==void 0&&r.push(...renderAttentionRows(this.#Ae,e,this.#i),``),this.#je!==void 0&&r.push(...renderTodoPanelRows({items:this.#je,width:e,theme:this.#i,working:this.#H||this.#U.kind===`waiting`,pulse:this.#ln(this.#ne,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH)}),``);let o=renderMessageQueueRows({view:this.#Ne.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));let a=isPromptControlCommand(this.#M),o=i?n.dim(` ${i}`):``,s=[];this.#_n(s,e);let u=Math.max(1,this.#xn()-1-r.length-1-s.length),f={text:this.#M,cursor:this.#N,width:e,theme:this.#i,caretVisible:this.#ee,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.#fn(e)),this.#hn(r,e);let t=[];return this.#_n(t,e),!this.#H&&t.length>0&&r.push(``),r.push(...t),r}if(this.#V.text.length>0)return this.#gn(r,e,{inert:!1}),this.#_n(r,e),r;let u=this.#K??(this.#G.length>0?this.#G:`Ready`),f=this.#yn(),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.#_n(r,e),r}#fn(e){let t=this.#i.colors,n=this.#ln(this.#ne,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH),r=this.#U,i=this.#B.startedAtMs??this.#be??(r.kind===`waiting`?r.startedAtMs:Date.now()),a=Date.now()-i,o=`${typewriterText(`Working for`,a,80)} ${this.#pn(a)}`;return clip(`${t.yellow(n)} ${t.dim(o)}`,e)}#pn(e){return`${formatTurnDuration(e)}${this.#mn()}`}#mn(){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)}`}#hn(e,t){this.#H&&this.#gn(e,t,{inert:!0})}#gn(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))}#_n(e,t){let n=this.#j===void 0?``:` `,r=Math.max(1,t-n.length),i={theme:this.#i,width:r};this.#oe&&(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))}#vn(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))}#yn(){let e=this.#i.colors,t=[],n=formatAssistantResponseStats({totalTokens:this.#he,outputTokens:this.#ve,tokensPerSecond:this.#ye},this.#l);return n&&t.push(n),t.length>0?e.dim(t.join(` ${this.#i.glyph.dot} `)):``}#bn(){return Math.max(20,this.#t.columns||80)}#xn(){return Math.max(8,this.#t.rows||24)}#Sn(){if(this.#xe!==void 0||!this.#u)return;this.#Se=``,this.#Ce=``;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.#Tn(t,chunkToString(e,i)),a?.(),!0}),()=>{e.write=n}},e=capture(process.stdout,`stdout`),t=capture(process.stderr,`stderr`);this.#d?.subscribeLogRecords(e=>this.#wn(e)),this.#xe=()=>{this.#d?.unsubscribeLogRecords(),e(),t()}}#Cn(){let e=this.#xe;e!==void 0&&(this.#xe=void 0,e(),this.#Se.length>0&&(this.#d?.append({source:`stdout`,detail:this.#Se}),this.#Mn(`stdout`)&&process.stdout.write(`${this.#Se}\n`),this.#Se=``),this.#Ce.length>0&&(this.#d?.append({source:`stderr`,detail:this.#Ce}),this.#Mn(`stderr`)&&process.stderr.write(`${this.#Ce}\n`),this.#Ce=``))}#wn(e){let t=e.fields===void 0?``:` ${JSON.stringify(e.fields)}`;this.#Dn(`[eve:${e.namespace}] ${e.message}${t}`),this.#tn()}#Tn(e,t){let n=(e===`stdout`?this.#Se:this.#Ce)+t;if(e===`stdout`&&parseDevRebuildLogLine(n.trimEnd())!==void 0){this.#Se=``,this.#d?.append({source:e,detail:n.trimEnd()}),this.#En(n.trimEnd()),this.#tn();return}let r=n.lastIndexOf(`
|
|
8
|
+
`),i=r===-1?n:n.slice(r+1);if(e===`stdout`?this.#Se=i:this.#Ce=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.#En(a):this.#Dn(a),this.#tn())}#En(e){let t=[],flushPending=()=>{if(t.length===0)return;let e=t.join(`
|
|
9
|
+
`);t=[],e.trim().length!==0&&this.#Pt({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.#Pt({kind:`sandbox`,body:e,live:!1});continue}let r=parseDevRebuildLogLine(n.trimEnd());if(r===void 0){t.push(n);continue}flushPending(),this.#kn(r,n.trimEnd())}flushPending()}#Dn(e){let t=e.split(`
|
|
11
|
+
`),n=t.findIndex(e=>parseDevRebuildLogLine(e.trimEnd())?.kind===`failed`);if(n===-1){if(this.#d===void 0){this.#Pt({kind:`log`,title:`stderr`,body:e,live:!0});return}let t=presentDiagnostic(e,this.#d.displayPath);if(t.kind===`inline`){this.#Pt({kind:`log`,title:`stderr`,body:t.text,live:!0});return}this.#Pt({kind:`log`,title:`stderr`,body:formatStoredDiagnostic(t),logVisibility:`stderr-only`,live:!0}),this.#Pt({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.#Pt({kind:`log`,title:`stderr`,body:r,live:!0});let i=t.slice(n).join(`
|
|
13
|
+
`);this.#On(i)}#On(e){if(this.#p===`all`){if(e.trim().length===0)return;this.#Pt({kind:`log`,title:`stderr`,body:e,live:!0});return}this.#we=e}#kn(e,t){let n=this.#An();if(e.kind===`failed`){this.#On(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.#Ee}`;this.#Ee+=1,this.#Te={id:r,summary:t},this.#Pt({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.#we=void 0);return}e.kind===`rebuilt`&&(this.#we=void 0),this.#Pt({kind:`log`,title:`stdout`,body:t,live:!0})}#An(){let e=this.#Te;if(e===void 0)return;let t=this.#h.get(e.id);if(!(t===void 0||t.live!==!0))return{state:e,block:t}}#jn(){let e=this.#Te;if(e===void 0)return;this.#Te=void 0;let t=this.#h.get(e.id);t!==void 0&&(t.live=!1)}#Mn(e){switch(this.#p){case`none`:return!1;case`stderr`:return e===`stderr`;case`sandbox`:return e===`sandbox`;case`all`:return!0}}#Nn(e){return e.kind===`sandbox`?!this.#Mn(`sandbox`):e.kind===`log`?e.logVisibility===`stderr-only`?this.#p!==`stderr`:e.logVisibility===`all-only`?this.#p!==`all`:!this.#Mn(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};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{EventEmitter}from"node:events";const ansiControlSequencePattern=RegExp(`^\x1B\\[([0-9?;]*)([ -/]*)([@-~])`);var MockUserInput=class extends EventEmitter{isTTY=!0;rawModes=[];resumeCalls=0;pauseCalls=0;setRawMode(e){return this.rawModes.push(e),this}resume(){return this.resumeCalls+=1,this}pause(){return this.pauseCalls+=1,this}type(e){this.emit(`data`,Buffer.from(e))}send(e){this.emit(`data`,Buffer.from(e))}enter(){this.send(`\r`)}backspace(){this.send(``)}up(){this.send(`\x1B[A`)}down(){this.send(`\x1B[B`)}left(){this.send(`\x1B[D`)}right(){this.send(`\x1B[C`)}ctrlC(){this.send(``)}ctrlN(){this.send(``)}ctrlP(){this.send(``)}},MockScreen=class extends EventEmitter{isTTY=!0;columns;rows;#e=``;#t=[];#n=0;#r=0;#i=[];constructor({columns:e,rows:t}){super(),this.columns=e,this.rows=t}write(e,t,n){let r=String(e);return this.#e+=r,this.#
|
|
2
|
-
`)}rawOutput(){return this.#e}async waitForIdlePrompt(e=1e3){let t=Array.from({length:11},(e,t)=>`Working for`.slice(0,t+1)),n=RegExp(`^[▪* ] (?:${t.join(`|`)}) \\d`,`mu`),idle=()=>{let e=this.snapshot();return/^[›❯]/mu.test(e)&&!n.test(e)},r=Date.now()+e;for(;Date.now()<r;){if(idle())return;await new Promise(e=>setTimeout(e,25))}throw Error(`Timed out waiting for an idle prompt.\n\nScreen:\n${this.snapshot()}`)}async waitForText(e,t=1e3,n=()=>this.snapshot()){this.snapshot().includes(e)||await new Promise((r,i)=>{let a={text:e,resolve:r,reject:i,timeout:setTimeout(()=>{this.#
|
|
3
|
-
`){this.#n+=1,this.#r=0;continue}if(n===`\r`){this.#r=0;continue}this.#
|
|
1
|
+
import{EventEmitter}from"node:events";const ansiControlSequencePattern=RegExp(`^\x1B\\[([0-9?;]*)([ -/]*)([@-~])`);var MockUserInput=class extends EventEmitter{isTTY=!0;rawModes=[];resumeCalls=0;pauseCalls=0;setRawMode(e){return this.rawModes.push(e),this}resume(){return this.resumeCalls+=1,this}pause(){return this.pauseCalls+=1,this}type(e){this.emit(`data`,Buffer.from(e))}send(e){this.emit(`data`,Buffer.from(e))}enter(){this.send(`\r`)}backspace(){this.send(``)}up(){this.send(`\x1B[A`)}down(){this.send(`\x1B[B`)}left(){this.send(`\x1B[D`)}right(){this.send(`\x1B[C`)}ctrlC(){this.send(``)}ctrlN(){this.send(``)}ctrlP(){this.send(``)}},MockScreen=class extends EventEmitter{isTTY=!0;columns;rows;#e=``;#t=[];#n=0;#r=0;#i;#a=[];constructor({columns:e,rows:t}){super(),this.columns=e,this.rows=t}write(e,t,n){let r=String(e);return this.#e+=r,this.#s(r),typeof t==`function`&&t(),n?.(),this.#o(),!0}resize(e,t){this.columns=e,this.rows=t,this.emit(`resize`)}snapshot(){return this.#t.join(`
|
|
2
|
+
`)}rawOutput(){return this.#e}async waitForIdlePrompt(e=1e3){let t=Array.from({length:11},(e,t)=>`Working for`.slice(0,t+1)),n=RegExp(`^[▪* ] (?:${t.join(`|`)}) \\d`,`mu`),idle=()=>{let e=this.snapshot();return/^[›❯]/mu.test(e)&&!n.test(e)},r=Date.now()+e;for(;Date.now()<r;){if(idle())return;await new Promise(e=>setTimeout(e,25))}throw Error(`Timed out waiting for an idle prompt.\n\nScreen:\n${this.snapshot()}`)}async waitForText(e,t=1e3,n=()=>this.snapshot()){this.snapshot().includes(e)||await new Promise((r,i)=>{let a={text:e,resolve:r,reject:i,timeout:setTimeout(()=>{this.#a=this.#a.filter(e=>e!==a),i(Error(`Timed out waiting for screen text: ${e}\n\nScreen:\n${n()}`))},t)};this.#a.push(a)})}#o(){let e=this.snapshot();for(let t of this.#a.slice())e.includes(t.text)&&(clearTimeout(t.timeout),this.#a=this.#a.filter(e=>e!==t),t.resolve())}#s(e){let t=0;for(;t<e.length;){if(e[t]===`\x1B`){let n=this.#c(e,t);if(n>t){t=n;continue}}let n=e[t];if(t+=1,n!==void 0){if(n===`
|
|
3
|
+
`){this.#n+=1,this.#r=0;continue}if(n===`\r`){this.#r=0;continue}this.#d(n)}}}#c(e,n){let r=e.slice(n).match(ansiControlSequencePattern);if(!r)return n;let[i,a=``,,o]=r,s=a.startsWith(`?`),c=a&&!s?a.split(`;`):[],first=e=>c[0]===void 0||c[0]===``?e:Number(c[0]);if(s)return a===`?1049`&&(o===`h`||o===`l`)&&(o===`h`?(this.#i={lines:this.#t,cursorLine:this.#n,cursorColumn:this.#r},this.#t=[],this.#n=0,this.#r=0):this.#i!==void 0&&(this.#t=this.#i.lines,this.#n=this.#i.cursorLine,this.#r=this.#i.cursorColumn,this.#i=void 0)),n+i.length;switch(o){case`H`:case`f`:this.#n=first(1)-1,this.#r=(c[1]?Number(c[1]):1)-1;break;case`A`:this.#n=Math.max(0,this.#n-first(1));break;case`B`:this.#n+=first(1);break;case`C`:this.#r+=first(1);break;case`D`:this.#r=Math.max(0,this.#r-first(1));break;case`E`:this.#n+=first(1),this.#r=0;break;case`F`:this.#n=Math.max(0,this.#n-first(1)),this.#r=0;break;case`G`:this.#r=first(1)-1;break;case`J`:this.#l(first(0));break;case`K`:this.#u(first(0));break;default:break}return n+i.length}#l(e){if(e===2||e===3){this.#t=[],this.#n=0,this.#r=0;return}if(e===1){for(let e=0;e<this.#n;e+=1)this.#t[e]=``;this.#u(1);return}this.#u(0),this.#t.length=Math.min(this.#t.length,this.#n+1)}#u(e){let t=this.#t[this.#n]??``;if(e===2){this.#t[this.#n]=``;return}if(e===1){this.#t[this.#n]=` `.repeat(this.#r)+t.slice(this.#r);return}this.#t[this.#n]=t.slice(0,this.#r)}#d(e){let t=(this.#t[this.#n]??``).padEnd(this.#r,` `),n=t.slice(0,this.#r)+e+t.slice(this.#r+e.length);this.#t[this.#n]=n,this.#r+=e.length}};export{MockScreen,MockUserInput};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats span attribute values for the `/traces` detail panel. Payload
|
|
3
|
+
* attributes render as readable structure — prompt messages as a chat-like
|
|
4
|
+
* transcript with role-prefixed blocks and hanging indents, JSON as
|
|
5
|
+
* pretty-printed blocks — instead of one wrapped blob. Provider transport
|
|
6
|
+
* noise was already stripped at capture time (see `agent-otel-provider.ts`),
|
|
7
|
+
* so what remains here is presentation only.
|
|
8
|
+
*
|
|
9
|
+
* Every returned line fits the given width; wrapped continuations keep a
|
|
10
|
+
* two-space hanging indent so they read as part of their block.
|
|
11
|
+
*/
|
|
12
|
+
import type { Theme } from "../theme.js";
|
|
13
|
+
/**
|
|
14
|
+
* Formats one attribute's value into display lines, each at most `width`
|
|
15
|
+
* columns. A single scalar stays on one line so the panel can keep it beside
|
|
16
|
+
* its key; multi-line content comes back unindented for the caller to nest
|
|
17
|
+
* under the key.
|
|
18
|
+
*/
|
|
19
|
+
export declare function formatAttributeContent(key: string, value: unknown, theme: Theme, width: number): string[];
|
|
20
|
+
/** Pretty-prints a JSON value with two-space indents, wrapped to `width`. */
|
|
21
|
+
export declare function prettyJson(value: unknown, width: number): string[];
|
|
22
|
+
/**
|
|
23
|
+
* Payload text can carry real newlines (tool results frequently end with one).
|
|
24
|
+
* Left raw, they split a composed frame row and inject phantom lines into the
|
|
25
|
+
* frame. Split them into real display lines; a trailing newline's empty tail
|
|
26
|
+
* is dropped.
|
|
27
|
+
*/
|
|
28
|
+
export declare function splitEmbeddedNewlines(lines: readonly string[]): string[];
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{stripTerminalControls,visibleLength,wrapVisibleLine}from"#cli/ui/terminal-text.js";function formatAttributeContent(t,r,i,a){if(typeof r!=`string`)return Array.isArray(r)?prettyJson(r,a):[stripTerminalControls(shortJson(r))];if(t===`ai.prompt.messages`){let e=messageTranscript(r,i,a);if(e!==void 0)return e}let o=parseJson(r);return o!==void 0&&(Array.isArray(o)||isRecord(o))?prettyJson(o,a):splitEmbeddedNewlines([stripTerminalControls(r)]).flatMap(e=>wrapVisibleLine(e,a))}function messageTranscript(t,n,r){let i=parseJson(t);if(!Array.isArray(i))return;let a=0,o=[];for(let e of i){if(isRecord(e)&&isRecord(e[`eve.truncated`])){let t=e[`eve.truncated`].omittedMessages;if(typeof t==`number`){a+=t;continue}}o.push(e)}if(!o.every(e=>typeof e.role==`string`))return;let{colors:s}=n,c=[];a>0&&c.push(s.dim(`… ${a} earlier message${a===1?``:`s`} omitted (long context)`));for(let t of o){let n=messageContentParts(t.content),i=t.role===`tool`?toolRoleLabel(n):stripTerminalControls(String(t.role));n.forEach((e,t)=>{let n=t===0?`${s.dim(`${i}:`)} `:` `;c.push(...wrapPrefixed(n,e.text,e.dim?s.dim:void 0,r))})}return c}function toolRoleLabel(e){let t=e.find(e=>e.name!==void 0);return t?.name===void 0?`tool`:`tool ${t.name}`}function messageContentParts(t){if(typeof t==`string`)return[{text:stripTerminalControls(t)}];if(!Array.isArray(t))return[{text:shortJson(t)}];let n=[];for(let r of t){if(!isRecord(r)||typeof r.type!=`string`){n.push({text:shortJson(r)});continue}if(r.type===`text`&&typeof r.text==`string`)n.push({text:stripTerminalControls(r.text)});else if(r.type===`reasoning`){let t=typeof r.text==`string`?stripTerminalControls(r.text.trim()):``;n.push({dim:!0,text:t.length>0?`⟨reasoning⟩ ${t}`:`⟨reasoning⟩`})}else if(r.type===`tool-call`&&typeof r.toolName==`string`){let t=stripTerminalControls(r.toolName);n.push({name:t,text:`→ ${t}(${shortJson(r.input)})`})}else if(r.type===`tool-result`&&typeof r.toolName==`string`){let t=stripTerminalControls(r.toolName);n.push({name:t,text:toolOutputText(r.output)})}else n.push({text:shortJson(r)})}return n.length===0&&n.push({text:shortJson(t)}),n}function toolOutputText(t){return isRecord(t)&&typeof t.type==`string`&&`value`in t?t.type===`text`&&typeof t.value==`string`?stripTerminalControls(t.value):shortJson(t.value):shortJson(t)}function prettyJson(e,t){return JSON.stringify(e,null,2).split(`
|
|
2
|
+
`).flatMap(e=>wrapHanging(e,t,t))}function wrapPrefixed(e,n,r,i){let a=r??(e=>e),o=[];return splitEmbeddedNewlines([n]).forEach((n,r)=>{let s=r===0?e:` `,c=r===0?visibleLength(e):2;wrapHanging(n,i,Math.max(8,i-c)).forEach((e,t)=>{o.push(t===0?`${s}${a(e)}`:` ${a(e)}`)})}),o}function wrapHanging(e,r,i){let a=wrapVisibleLine(e,Math.max(8,r-2));if(visibleLength(a[0]??``)<=i)return a;let[o,...s]=wrapVisibleLine(a[0]??``,Math.max(8,i));return[o??``,...s,...a.slice(1)]}function splitEmbeddedNewlines(e){let t=e.flatMap(e=>e.split(/\r\n|\r|\n/));for(;t.length>1&&t[t.length-1]===``;)t.pop();return t}function shortJson(e){try{return JSON.stringify(e)??String(e)}catch{return String(e)}}function parseJson(e){try{return JSON.parse(e)}catch{return}}function isRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}export{formatAttributeContent,prettyJson,splitEmbeddedNewlines};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversation view for the `/traces` viewer: the same trace, re-told as a
|
|
3
|
+
* flow of user messages, assistant replies, and tool calls instead of a
|
|
4
|
+
* latency waterfall. Items are built from the span tree (turns in order,
|
|
5
|
+
* subtrees in time order) with text pulled from the content attributes —
|
|
6
|
+
* the user's message from the turn's first model prompt, replies and tool
|
|
7
|
+
* calls from response/tool spans.
|
|
8
|
+
*/
|
|
9
|
+
import type { LocalTrace, LocalTraceSpan } from "#tracing/local-trace-reader.js";
|
|
10
|
+
import type { Theme } from "../theme.js";
|
|
11
|
+
export interface ConversationItem {
|
|
12
|
+
readonly kind: "system" | "user" | "assistant" | "tool";
|
|
13
|
+
/** Detail-drawer source for this item (the turn marker span for users). */
|
|
14
|
+
readonly span: LocalTraceSpan;
|
|
15
|
+
/** Tool name for tool items. */
|
|
16
|
+
readonly name?: string;
|
|
17
|
+
/** Message text for system/user/assistant items. */
|
|
18
|
+
readonly text?: string;
|
|
19
|
+
/** Model reasoning for assistant items (shown dim above the reply). */
|
|
20
|
+
readonly reasoning?: string;
|
|
21
|
+
/** Tool names from the model's tool-call decision (shown when no text). */
|
|
22
|
+
readonly toolCallNames?: readonly string[];
|
|
23
|
+
/** Raw JSON for tool input / output. */
|
|
24
|
+
readonly args?: string;
|
|
25
|
+
readonly result?: string;
|
|
26
|
+
/** Assistant card metadata. */
|
|
27
|
+
readonly model?: string;
|
|
28
|
+
readonly inputTokens?: number;
|
|
29
|
+
readonly outputTokens?: number;
|
|
30
|
+
/** Gateway-reported inference cost in USD (from the ancestor step span). */
|
|
31
|
+
readonly costUsd?: number;
|
|
32
|
+
/** Set when the item's turn was delegated by another turn (a subagent). */
|
|
33
|
+
readonly subagent?: ConversationSubagent;
|
|
34
|
+
readonly durationMs: number;
|
|
35
|
+
readonly error: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** Dispatch lineage for a subagent turn, read from the turn span. */
|
|
38
|
+
export interface ConversationSubagent {
|
|
39
|
+
/** Subagent name, when the turn arrived through the subagent adapter. */
|
|
40
|
+
readonly name?: string;
|
|
41
|
+
/** Turn id of the dispatching parent turn. */
|
|
42
|
+
readonly parentTurnId: string;
|
|
43
|
+
/** Tool call id of the dispatch, when recorded. */
|
|
44
|
+
readonly parentCallId?: string;
|
|
45
|
+
}
|
|
46
|
+
/** Builds the conversation flow for a trace, one item per message/action. */
|
|
47
|
+
export declare function buildConversationItems(trace: LocalTrace): ConversationItem[];
|
|
48
|
+
/**
|
|
49
|
+
* Renders one conversation card, width-clipped: message kinds (system, user,
|
|
50
|
+
* assistant) as rounded text bubbles, tool calls as bordered boxes. Collapsed
|
|
51
|
+
* cards cap their payloads; expanded ones render them in full. The system
|
|
52
|
+
* bubble is title-only until expanded.
|
|
53
|
+
*/
|
|
54
|
+
export declare function renderConversationItem(item: ConversationItem, width: number, theme: Theme, selected: boolean, expanded: boolean): string[];
|
|
55
|
+
/** Rendered height of one card — the conversation viewport scrolls by lines. */
|
|
56
|
+
export declare function conversationItemLineCount(item: ConversationItem, width: number, theme: Theme, expanded: boolean): number;
|
|
57
|
+
/** Whether a card has content hidden behind the collapsed cap at this width. */
|
|
58
|
+
export declare function conversationItemExpandable(item: ConversationItem, width: number): boolean;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{formatCompactTokenCount}from"../stream-format.js";import{prettyJson,splitEmbeddedNewlines}from"./trace-content.js";import{formatElapsed}from"#cli/format-elapsed.js";import{compareLocalTraceSpans}from"#tracing/local-trace-reader.js";import{clipVisible,stripTerminalControls,visibleLength,wrapVisibleLine}from"#cli/ui/terminal-text.js";function buildConversationItems(e){let t=new Map(e.spans.map(e=>[e.spanId,e])),n=new Map;for(let t of e.spans){if(t.parentSpanId===void 0)continue;let e=n.get(t.parentSpanId)??[];e.push(t),n.set(t.parentSpanId,e)}for(let e of n.values())e.sort(compareLocalTraceSpans);let r=e.spans.filter(e=>e.name===`agent.turn`);r.sort(compareLocalTraceSpans);let a=[];for(let e of r){let r=turnSubagent(e),s=[],walk=e=>{s.push(e);for(let t of n.get(e.spanId)??[])walk(t)};if(walk(e),s.sort(compareLocalTraceSpans),a.length===0){let e=s.find(e=>isModelSpan(e)&&typeof e.attributes[`ai.prompt.system`]==`string`),t=e?.attributes[`ai.prompt.system`];e!==void 0&&typeof t==`string`&&t.length>0&&a.push({item:{kind:`system`,durationMs:0,error:!1,span:e,subagent:r,text:t},order:0n})}let c=extractUserText(s.find(isModelSpan));c!==void 0&&a.push({item:{kind:`user`,durationMs:0,error:!1,span:e,subagent:r,text:c},order:e.startTimeNs});for(let e of s)if(isModelSpan(e)){let n=stringAttribute(e,`ai.response.text`),i=stringAttribute(e,`ai.response.reasoning`),s=numberAttribute(e,`agent.usage.input_tokens`)!==void 0||numberAttribute(e,`agent.usage.output_tokens`)!==void 0,c=e.attributes[`ai.response.tool_calls`]!==void 0;if((n===void 0||n.trim().length===0)&&(i===void 0||i.trim().length===0)&&!s&&!c&&e.statusCode!==2)continue;a.push({item:{kind:`assistant`,costUsd:stepCostUsd(e,t),durationMs:spanDurationMs(e),error:e.statusCode===2,inputTokens:numberAttribute(e,`agent.usage.input_tokens`),model:stringAttribute(e,`gen_ai.request.model`),outputTokens:numberAttribute(e,`agent.usage.output_tokens`),reasoning:i,span:e,subagent:r,text:n,toolCallNames:c?parseToolCallNames(stringAttribute(e,`ai.response.tool_calls`)):void 0},order:e.startTimeNs});for(let t of parseProviderToolResults(stringAttribute(e,`ai.response.tool_results`)))a.push({item:{kind:`tool`,args:t.args,durationMs:0,error:t.error,name:stripTerminalControls(t.name),result:t.result,span:e,subagent:r},order:e.startTimeNs})}else e.name===`ai.toolCall`&&a.push({item:{kind:`tool`,args:stringAttribute(e,`gen_ai.tool.call.arguments`),durationMs:spanDurationMs(e),error:e.statusCode===2,name:stripTerminalControls(stringAttribute(e,`gen_ai.tool.name`)??`tool`),result:unwrapJsonString(stringAttribute(e,`gen_ai.tool.call.result`)),span:e,subagent:r},order:e.startTimeNs})}return a.sort((e,t)=>e.order===t.order?0:e.order<t.order?-1:1).map(e=>e.item)}function turnSubagent(e){let t=stringAttribute(e,`agent.parent.turn.id`);if(t===void 0)return;let n=stringAttribute(e,`agent.subagent.name`);return{name:n===void 0?void 0:stripTerminalControls(n),parentCallId:stringAttribute(e,`agent.parent.call_id`),parentTurnId:t}}function renderConversationItem(t,n,i,a,s){let{colors:c,glyph:d}=i,f=Math.max(8,n-8),p=conversationItemExpandable(t,n),m,h,g=[];if(t.kind===`tool`){let e=c.bold(c.white(t.name??`tool`));m=`${foldMarker(s,p,i)}${e}`,h=t.durationMs>0?c.dim(formatElapsed(t.durationMs)):``;let n=t.args===void 0?[]:payloadJsonLines(t.args,f),a=t.result===void 0?[]:payloadJsonLines(t.result,f),o=s?n:capLines(n,f),l=s?a:capLines(a,f);o.length>0&&g.push(``,c.dim(`Input:`),``,...o),l.length>0&&g.push(``,c.dim(`Output:`),``,...l)}else if(t.kind===`system`){m=`${foldMarker(s,p,i)}${c.bold(c.white(`system`))}`,h=c.dim(`~${formatCompactTokenCount(estimateTokens(t.text??``))} tokens`);let n=wrapText(t.text??``,f);g.push(...s?n:capLines(n,f))}else if(t.kind===`assistant`){m=`${foldMarker(s,p,i)}${c.bold(c.white(`assistant`))}${t.model===void 0?``:c.dim(` · ${stripTerminalControls(t.model)}`)}`,h=assistantMetrics(t,d,c);let e=t.reasoning===void 0||t.reasoning.trim().length===0?[]:payloadLines(t.reasoning,f),n=t.text===void 0||t.text.trim().length===0?[]:payloadLines(t.text,f),r=(s?e:capLines(e,f)).map(e=>c.dim(e)),a=s?n:capLines(n,f);if(r.length>0&&(g.push(c.dim(`Thought:`),``,...r),a.length>0&&g.push(``)),g.push(...a),(t.text===void 0||t.text.trim().length===0)&&t.toolCallNames!==void 0&&t.toolCallNames.length>0){r.length>0&&g.push(``);for(let e of t.toolCallNames)g.push(c.dim(`→ ${e}`))}}else{let e=t.kind===`user`&&t.subagent!==void 0?`task`:t.kind;m=`${foldMarker(s,p,i)}${c.bold(c.white(e))}`,h=``;let n=t.text===void 0||t.text.trim().length===0?[]:payloadLines(t.text,f);g.push(...s?n:capLines(n,f))}if(t.subagent!==void 0){let e=t.subagent.name===void 0?`subagent`:`subagent:${t.subagent.name}`;m+=c.dim(` · ${e}`)}!s&&p?g.push(`…`,``,c.dim(`Click to expand`)):s&&p&&g.push(``,c.dim(`Click to collapse`));let _=t.error?CARD_ERROR_SURFACE_HEADER:CARD_SURFACE_HEADER,v=t.error?CARD_ERROR_SURFACE_BODY:CARD_SURFACE_BODY;return[cardRow(``,n,i,a,_),cardSplitRow(m,h,n,i,a,_),cardRow(``,n,i,a,_),cardRow(``,n,i,a,v),...g.map(e=>cardRow(e,n,i,a,v)),cardRow(``,n,i,a,v)]}const CARD_SURFACE_HEADER=`\x1B[48;2;22;22;22m`,CARD_SURFACE_BODY=`\x1B[48;2;36;36;36m`,CARD_ERROR_SURFACE_HEADER=`\x1B[48;2;69;32;37m`,CARD_ERROR_SURFACE_BODY=`\x1B[48;2;58;26;31m`;function cardRow(e,t,n,r,i){let o=r?n.colors.white(`▌`):` `,c=clipVisible(e,Math.max(1,t-8)),l=` `.repeat(Math.max(0,t-8-visibleLength(c)));return n.color?` ${o}${i} ${c}[0m${i}${l} [49m `:` ${o} ${c}${l} `}function cardSplitRow(e,t,n,r,i,o){if(visibleLength(t)===0)return cardRow(e,n,r,i,o);let c=Math.max(1,n-8),l=visibleLength(t),u=clipVisible(e,Math.max(1,c-l-2));return cardRow(`${u}${` `.repeat(Math.max(2,c-visibleLength(u)-l))}${t}`,n,r,i,o)}function assistantMetrics(t,n,i){let a=[];return t.durationMs>0&&a.push(formatElapsed(t.durationMs)),t.inputTokens!==void 0&&a.push(`${n.arrowUp}${formatCompactTokenCount(t.inputTokens)}`),t.outputTokens!==void 0&&a.push(`${n.arrowDown}${formatCompactTokenCount(t.outputTokens)}`),t.costUsd!==void 0&&a.push(formatCost(t.costUsd)),a.length===0?``:i.dim(a.join(` · `))}function formatCost(e){return e>=.01?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function stepCostUsd(e,t){let n=e;for(;n.parentSpanId!==void 0;){if(n=t.get(n.parentSpanId),n===void 0)return;if(n.name===`agent.step`)return numberAttribute(n,`gen_ai.usage.cost`)}}function foldMarker(e,t,n){return e?`${n.colors.dim(`▾`)} `:t?`${n.colors.dim(`▸`)} `:``}function wrapText(e,t){return splitEmbeddedNewlines([stripTerminalControls(e)]).flatMap(e=>wrapVisibleLine(e,t))}function payloadLines(e,t){return wrapText(e,t)}function payloadJsonLines(e,n){try{let r=JSON.parse(e);if(typeof r==`object`&&r)return prettyJson(r,n)}catch{}return payloadLines(e,n)}function capLines(e,t){return e.length<=3?[...e]:[...e.slice(0,2),clipVisible(e[2],Math.max(1,t))]}function conversationItemLineCount(e,t,n,r){return renderConversationItem(e,t,n,!1,r).length}function conversationItemExpandable(e,t){let n=Math.max(8,t-8);if(e.kind===`tool`){let t=e.args===void 0?0:payloadJsonLines(e.args,n-2).length,r=e.result===void 0?0:payloadJsonLines(e.result,n-2).length;return t>3||r>3}if(e.kind===`system`)return wrapText(e.text??``,n).length>3;if(e.kind===`user`)return(e.text===void 0||e.text.trim().length===0?0:payloadLines(e.text,n).length)>3;let r=e.reasoning===void 0||e.reasoning.trim().length===0?0:payloadLines(e.reasoning,n).length,i=e.text===void 0||e.text.trim().length===0?0:payloadLines(e.text,n).length;return r>3||i>3}function estimateTokens(e){return Math.ceil(e.length/4)}function extractUserText(e){if(e===void 0)return;let t=e.attributes[`ai.prompt.messages`];if(typeof t!=`string`)return;let n;try{n=JSON.parse(t)}catch{return}if(Array.isArray(n))for(let e=n.length-1;e>=0;--e){let t=n[e];if(!isRecord(t)||t.role!==`user`)continue;let r=contentText(t.content).trim();if(r.length>0)return r}}function contentText(e){return typeof e==`string`?e:Array.isArray(e)?e.filter(e=>isRecord(e)&&e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(`
|
|
2
|
+
`):``}function unwrapJsonString(e){if(e!==void 0)try{let t=JSON.parse(e);return typeof t==`string`?t:e}catch{return e}}function isModelSpan(e){return e.name.startsWith(`ai.`)&&e.name.includes(`do`)}function parseToolCallNames(e){if(e!==void 0)try{let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>isRecord(e)&&typeof e.toolName==`string`).map(e=>e.toolName):void 0}catch{return}}function parseProviderToolResults(e){if(e===void 0)return[];try{let t=JSON.parse(e);if(!Array.isArray(t))return[];let asText=e=>typeof e==`string`?e:e===void 0?void 0:JSON.stringify(e);return t.filter(isRecord).map(e=>{let t=`error`in e;return{args:asText(e.input),error:t,name:typeof e.toolName==`string`?e.toolName:`tool`,result:asText(t?e.error:e.output)}})}catch{return[]}}function stringAttribute(e,t){let n=e.attributes[t];return typeof n==`string`?n:void 0}function numberAttribute(e,t){let n=e.attributes[t];return typeof n==`number`?n:void 0}function spanDurationMs(e){return Math.max(0,Number(e.endTimeNs-e.startTimeNs)/1e6)}function isRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}export{buildConversationItems,conversationItemExpandable,conversationItemLineCount,renderConversationItem};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live reader over the local trace spool for the `/traces` viewer.
|
|
3
|
+
*
|
|
4
|
+
* The spool's segments are immutable — one file per span, written atomically,
|
|
5
|
+
* never rewritten — so reads cache parsed spans by span id and only parse
|
|
6
|
+
* files that appeared since the last poll. Listing stats directories instead
|
|
7
|
+
* of parsing spans, keeping a 1s poll cheap even with a large spool.
|
|
8
|
+
*/
|
|
9
|
+
import type { LocalTrace } from "#tracing/local-trace-reader.js";
|
|
10
|
+
export interface TraceStoreEntry {
|
|
11
|
+
readonly traceId: string;
|
|
12
|
+
/** Mtime of the trace's segments directory — the instant it last received a span. */
|
|
13
|
+
readonly lastActivityMs: number;
|
|
14
|
+
}
|
|
15
|
+
export interface TraceStore {
|
|
16
|
+
/** Lists stored traces, most recent activity first. */
|
|
17
|
+
list(): Promise<readonly TraceStoreEntry[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Reads one trace, parsing only segments not seen by earlier reads.
|
|
20
|
+
* Returns `undefined` when the trace is missing or has no valid spans
|
|
21
|
+
* (e.g. retention pruned it between list and read).
|
|
22
|
+
*/
|
|
23
|
+
read(traceId: string): Promise<LocalTrace | undefined>;
|
|
24
|
+
}
|
|
25
|
+
export declare function createTraceStore(options: {
|
|
26
|
+
readonly appRoot: string;
|
|
27
|
+
}): TraceStore;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{join}from"node:path";import{readFile,readdir,stat}from"node:fs/promises";import{assembleLocalTrace,parseLocalTraceSegment}from"#tracing/local-trace-reader.js";import{resolveLocalTraceSchemaDirectory,resolveLocalTraceSegmentsDirectory}from"#tracing/local-trace-span-processor.js";const TRACE_ID_PATTERN=/^[0-9a-f]{32}$/u,SPAN_FILE_PATTERN=/^[0-9a-f]{16}\.otlp\.json$/u;function createTraceStore(s){let c=resolveLocalTraceSchemaDirectory(s.appRoot),l=new Map;return{async list(){let e;try{e=await readdir(c,{withFileTypes:!0})}catch(e){if(isMissing(e))return[];throw e}let t=[];for(let n of e)if(!(!n.isDirectory()||!TRACE_ID_PATTERN.test(n.name)))try{let e=await stat(resolveLocalTraceSegmentsDirectory(s.appRoot,n.name));t.push({traceId:n.name,lastActivityMs:e.mtimeMs})}catch(e){if(!isMissing(e))throw e}return t.sort((e,t)=>t.lastActivityMs===e.lastActivityMs?e.traceId.localeCompare(t.traceId):t.lastActivityMs-e.lastActivityMs)},async read(a){let o=resolveLocalTraceSegmentsDirectory(s.appRoot,a),c;try{c=await readdir(o,{withFileTypes:!0})}catch(e){if(isMissing(e)){l.delete(a);return}throw e}let u=l.get(a);u===void 0&&(u={seen:new Set,spans:new Map},l.set(a,u));let d=!1;for(let n of c){if(!n.isFile()||!SPAN_FILE_PATTERN.test(n.name)||u.seen.has(n.name))continue;u.seen.add(n.name);let r;try{let i=join(o,n.name);if((await stat(i)).size>8388608)continue;r=await readFile(i,`utf8`)}catch{continue}for(let e of parseLocalTraceSegment(r,a))u.spans.has(e.spanId)||(u.spans.set(e.spanId,e),d=!0)}if(u.spans.size!==0)return(d||u.assembled===void 0)&&(u.assembled=assembleLocalTrace(a,[...u.spans.values()])),u.assembled}}}function isMissing(e){return e.code===`ENOENT`}export{createTraceStore};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure frame renderer for the `/traces` conversation viewer: state in,
|
|
3
|
+
* styled rows out. The layout is a header (trace identity), a body (the
|
|
4
|
+
* conversation cards, plus the optional details drawer on the right), and a
|
|
5
|
+
* footer (key hints + position/notice). Every row is clipped to the
|
|
6
|
+
* terminal width so the alt-screen painter can write rows verbatim.
|
|
7
|
+
*/
|
|
8
|
+
import type { LocalTraceSpan } from "#tracing/local-trace-reader.js";
|
|
9
|
+
import type { Theme } from "../theme.js";
|
|
10
|
+
import type { TextSelectionRange, TraceViewerState } from "./trace-viewer-state.js";
|
|
11
|
+
export interface TraceViewerFrame {
|
|
12
|
+
readonly rows: readonly string[];
|
|
13
|
+
/** Detail rows the panel has for the selected span — fed back into key handling. */
|
|
14
|
+
readonly panelTotalRows: number;
|
|
15
|
+
/** Body rows available to the conversation. */
|
|
16
|
+
readonly timelineViewportRows: number;
|
|
17
|
+
/** Body rows available to the panel. */
|
|
18
|
+
readonly panelViewportRows: number;
|
|
19
|
+
/** Column width the body renders at (expandability is width-dependent). */
|
|
20
|
+
readonly contentWidth: number;
|
|
21
|
+
}
|
|
22
|
+
export interface RenderTraceViewerOptions {
|
|
23
|
+
readonly width: number;
|
|
24
|
+
readonly height: number;
|
|
25
|
+
readonly theme: Theme;
|
|
26
|
+
/** The viewed trace received spans recently — the window extends to "now". */
|
|
27
|
+
readonly activeWindowEndNs?: bigint;
|
|
28
|
+
/** Tracing is disabled via `EVE_TRACES=off` (empty-state copy). */
|
|
29
|
+
readonly tracingDisabled?: boolean;
|
|
30
|
+
/** Transient confirmation shown in the header's top-right corner. */
|
|
31
|
+
readonly toast?: string;
|
|
32
|
+
}
|
|
33
|
+
export declare function renderTraceViewer(state: TraceViewerState, options: RenderTraceViewerOptions): TraceViewerFrame;
|
|
34
|
+
export declare function renderSpanDetail(span: LocalTraceSpan, innerWidth: number, theme: Theme, options?: {
|
|
35
|
+
readonly excludeKeys?: ReadonlySet<string>;
|
|
36
|
+
}): string[];
|
|
37
|
+
/**
|
|
38
|
+
* Plain text covered by a drag selection over the conversation, extracted
|
|
39
|
+
* from the same rendered lines the user saw.
|
|
40
|
+
*/
|
|
41
|
+
export declare function conversationSelectionText(state: TraceViewerState, width: number, theme: Theme, selection: TextSelectionRange): string;
|
|
42
|
+
/**
|
|
43
|
+
* Plain text covered by a drag selection over the details drawer, extracted
|
|
44
|
+
* from the same detail lines the frame painted. `totalWidth` is the full
|
|
45
|
+
* terminal width — the drawer's width derives from it exactly as rendering
|
|
46
|
+
* does, so columns map to the same cells the user selected.
|
|
47
|
+
*/
|
|
48
|
+
export declare function panelSelectionText(state: TraceViewerState, totalWidth: number, theme: Theme, selection: TextSelectionRange): string;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{formatAttributeContent}from"./trace-content.js";import{renderConversationItem}from"./trace-conversation.js";import{orderedTextSelection,selectedTraceViewerSpan}from"./trace-viewer-state.js";import{formatElapsed}from"#cli/format-elapsed.js";import{describeLocalTraceSpan}from"#tracing/local-trace-reader.js";import{clipVisible,sliceVisible,stripAnsi,stripTerminalControls,visibleLength,wrapVisibleLine}from"#cli/ui/terminal-text.js";function renderTraceViewer(e,t){let{width:n,height:r,theme:i}=t,a=Math.max(1,r-3-3),o=e.panelOpen?panelWidthFor(n):0,s=Math.max(20,n-(o===0?0:o+1)),c=panelDetailLines(e,o,i),l=a,u=[];if(u.push(...renderHeader(e,t)),e.traces.length===0)u.push(...padBody(renderEmptyState(t,i,a),a));else if(e.trace===void 0)u.push(...padBody(center(a,i.colors.dim(`Loading trace…`)),a));else{let r=renderConversation(e,t,s,a);for(let t=0;t<a;t+=1){let i=r[t]??``;if(o===0){u.push(i);continue}let a=c[e.panelScroll+t]??``;e.textSelection!==void 0&&e.textSelection.region===`panel`&&(a=highlightSelection(a,e.panelScroll+t,e.textSelection,o)),u.push(joinPanels(i,s,` `,a,n))}}return u.push(...renderFooter(e,n,i)),t.toast!==void 0&&overlayToast(u,t.toast,n,i),{rows:u.map(e=>withViewerBase(e,n,i)),panelTotalRows:c.length,timelineViewportRows:a,panelViewportRows:l,contentWidth:s}}const VIEWER_BASE_OPEN=`\x1B[48;2;0;0;0m`,VIEWER_BASE_REOPEN=`\x1b[0m${VIEWER_BASE_OPEN}`,VIEWER_BASE_REOPEN_BG=`\x1b[49m${VIEWER_BASE_OPEN}`;function withViewerBase(e,t,n){if(!n.color)return e;let r=visibleLength(e)>=t?e:e+` `.repeat(t-visibleLength(e));return`${VIEWER_BASE_OPEN}${r.replaceAll(`\x1B[0m`,VIEWER_BASE_REOPEN).replaceAll(`\x1B[49m`,VIEWER_BASE_REOPEN_BG)}[0m`}const TOAST_SURFACE=`\x1B[48;2;36;36;36m`,TOAST_BAR=`\x1B[38;2;210;210;210m▌\x1B[39m`;function overlayToast(e,t,n,r){let i=` ${stripTerminalControls(t)} `,a=visibleLength(i),o=r.color?[`${TOAST_SURFACE}${TOAST_BAR}${` `.repeat(a)}\x1b[0m`,`${TOAST_SURFACE}${TOAST_BAR}[97m${i}\x1b[0m`,`${TOAST_SURFACE}${TOAST_BAR}${` `.repeat(a)}\x1b[0m`]:[`▌${` `.repeat(a)}`,`▌${i}`,`▌${` `.repeat(a)}`];for(let[t,r]of o.entries()){let i=2+t;if(i>=e.length)break;e[i]=overlayRight(e[i],r,n,1)}}function overlayRight(e,t,n,r){let i=Math.max(0,n-r-visibleLength(t)),a=visibleLength(e);return`${sliceVisible(a<i?e+` `.repeat(i-a):e,i)}\x1b[0m${t}`}const CONVERSATION_CONTENT_KEYS=new Set([`ai.prompt.messages`,`ai.prompt.system`,`ai.response.reasoning`,`ai.response.text`,`ai.response.tool_calls`,`ai.response.tool_results`,`gen_ai.tool.call.arguments`,`gen_ai.tool.call.result`]);function renderSpanDetail(t,n,r,s){let{colors:c}=r,u=[],f=stripTerminalControls(t.name);u.push(...wrapVisibleLine(c.bold(f),n));let p=describeLocalTraceSpan(t).map(stripTerminalControls);p.length>0&&u.push(c.dim(p.join(`, `))),u.push(``);let fact=(e,t)=>`${c.dim(e.padEnd(10))}${t}`,m=t.statusCode===2;u.push(fact(`status`,m?c.red(`ERROR`):c.green(`ok`))),u.push(fact(`duration`,formatElapsed(durationMs(t.startTimeNs,t.endTimeNs)))),u.push(fact(`started`,clockTime(t.startTimeNs))),u.push(fact(`span`,t.spanId)),t.parentSpanId!==void 0&&u.push(fact(`parent`,t.parentSpanId)),t.scope!==void 0&&u.push(fact(`scope`,stripTerminalControls(t.scope))),u.push(``);let h=Object.keys(t.attributes).filter(e=>s?.excludeKeys?.has(e)!==!0).sort();if(h.length===0)u.push(c.dim(`no attributes`));else{u.push(c.dim(`attributes (${h.length})`));for(let i of h){let a=formatAttributeContent(i,t.attributes[i],r,n-2),o=stripTerminalControls(i);if(a.length===1)u.push(...wrapVisibleLine(`${c.dim(o)} ${a[0]}`,n));else{u.push(c.dim(o));for(let e of a)u.push(` ${e}`)}}}return u.map(e=>clipVisible(e,n))}function renderHeader(e,t){let{theme:n,width:r}=t,{colors:a,glyph:s}=n,c=[];if(e.trace?.agentName!==void 0&&c.push(stripTerminalControls(e.trace.agentName)),e.trace?.sessionId!==void 0&&c.push(`session ${stripTerminalControls(e.trace.sessionId)}`),e.trace!==void 0){let n=t.activeWindowEndNs!==void 0&&t.activeWindowEndNs>e.trace.endTimeNs?t.activeWindowEndNs:e.trace.endTimeNs;c.push(clockTime(e.trace.startTimeNs),`${e.trace.spans.length} span${e.trace.spans.length===1?``:`s`}`,formatElapsed(durationMs(e.trace.startTimeNs,n)))}let d=`${a.bold(`${s.brand} traces`)}${c.length===0?``:a.dim(` · ${c.join(` · `)}`)}`,f=e.traces.length===0?``:a.dim(`[${e.traceIndex+1}/${e.traces.length}]`),p=[t.activeWindowEndNs===void 0?``:a.green(`● live`),f].filter(e=>e.length>0).join(` `);return[``,clipVisible(joinRight(` ${clipVisible(d,Math.max(0,r-visibleLength(p)-2))}`,p,r),r),``]}function renderConversation(e,t,n,r){let{theme:i}=t;if(e.conversationItems.length===0)return[i.colors.dim(` No conversation content in this trace — content capture may be off (EVE_TRACES_CONTENT).`)];let a=conversationLines(e,n,i).slice(e.scrollRow,e.scrollRow+r);return e.textSelection===void 0||e.textSelection.region!==`conversation`?a:a.map((t,r)=>highlightSelection(t,e.scrollRow+r,e.textSelection,n))}function conversationLines(e,n,r){let i=[];for(let a=0;a<e.conversationItems.length;a+=1)i.push(...renderConversationItem(e.conversationItems[a],n,r,a===e.selectedRow,e.expandedItems.has(a)),``);return i}function panelDetailLines(e,t,n){let i=selectedTraceViewerSpan(e);return!e.panelOpen||t<=0||i===void 0?[]:[``,...renderSpanDetail(i,Math.max(16,t-3),n,{excludeKeys:CONVERSATION_CONTENT_KEYS}).map(e=>` ${e}`)]}function conversationSelectionText(e,t,n,r){return selectionText(conversationLines(e,t,n),r)}function panelSelectionText(e,t,n,r){return selectionText(panelDetailLines(e,e.panelOpen?panelWidthFor(t):0,n),r)}function selectionText(e,t){let{start:r,end:i}=orderedTextSelection(t),a=[];for(let t=Math.max(0,r.line);t<=i.line&&t<e.length;t+=1){let n=stripAnsi(e[t]),o=t===r.line?r.column:0,l=t===i.line?i.column+1:1/0,u=l===1/0?n:sliceVisible(n,l),d=sliceVisible(n,o).length;a.push(u.slice(d).trimEnd())}return a.join(`
|
|
2
|
+
`)}function highlightSelection(e,t,r,i){let{start:a,end:o}=orderedTextSelection(r);if(t<a.line||t>o.line)return e;let c=t===a.line?a.column:0,l=t===o.line?o.column+1:i,d=visibleLength(e),f=d<l?e+` `.repeat(l-d):e,p=sliceVisible(f,c),m=sliceVisible(f,l),h=m.slice(p.length),g=f.slice(m.length);return h.length===0?e:`${p}\x1b[7m${h.replaceAll(`\x1B[0m`,`\x1B[0m\x1B[7m`)}\x1b[27m${g}`}function renderFooter(e,t,n){let{colors:r}=n,[i,a]=n.unicode?[`↑↓`,`←→`]:[`^/v`,`</>`],s=e.panelFocus?`${i} scroll · tab cards · esc back`:`${i} select · ${a} expand · enter attrs · tab focus · [ ] traces · q close`,c=e.conversationItems.length,l=c===0?``:r.dim(`item ${e.selectedRow+1}/${c}`),u=[e.notice===void 0?``:r.yellow(e.notice),l].filter(e=>e.length>0).join(r.dim(` · `));return[``,clipVisible(` ${r.dim(s)}`,t),clipVisible(u.length===0?``:` ${u}`,t)]}function renderEmptyState(e,t,n){let[r,i]=e.tracingDisabled===!0?[`Tracing is disabled (EVE_TRACES=off).`,`Re-enable it and spans stream in live.`]:[`No local traces yet.`,`Chat with your agent — spans stream in live.`],a=Array.from({length:n},()=>``),o=Math.max(0,Math.floor(n/2)-1);return o<n&&(a[o]=t.colors.bold(r)),o+1<n&&(a[o+1]=t.colors.dim(i)),a}function center(e,t){let n=Math.max(0,Math.floor(e/2)-1),r=Array.from({length:e},()=>``);return n<r.length&&(r[n]=t),r}function padBody(e,t){let n=[...e];for(;n.length<t;)n.push(``);return n.slice(0,t)}function joinPanels(e,t,n,r,i){let a=Math.max(0,i-t-1);return`${padTo(e,t)}${n}${clipVisible(r,a)}`}function joinRight(e,t,n){if(t.length===0)return e;let r=Math.max(1,n-visibleLength(e)-visibleLength(t));return`${e}${` `.repeat(r)}${t}`}function padTo(e,t){let n=visibleLength(e);return n>=t?clipVisible(e,t):e+` `.repeat(t-n)}function panelWidthFor(e){return e<42?0:Math.min(64,Math.max(20,Math.floor(e*.42)),e-20-1)}function durationMs(e,t){return Math.max(0,Number(t-e)/1e6)}function clockTime(e){let t=new Date(Number(e/1000000n)),pad=(e,t=2)=>String(e).padStart(t,`0`);return`${pad(t.getHours())}:${pad(t.getMinutes())}:${pad(t.getSeconds())}.${pad(t.getMilliseconds(),3)}`}export{conversationSelectionText,panelSelectionText,renderSpanDetail,renderTraceViewer};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owns one open `/traces` viewer: the store poller, the navigation state, and
|
|
3
|
+
* frame production. The terminal renderer wires it to the alt screen and the
|
|
4
|
+
* keyboard; everything else lives here so `terminal-renderer.ts` stays small
|
|
5
|
+
* and the poll/repaint lifecycle is testable without a TTY.
|
|
6
|
+
*/
|
|
7
|
+
import type { TerminalKey } from "../stream-format.js";
|
|
8
|
+
import type { Theme } from "../theme.js";
|
|
9
|
+
import type { TraceStore } from "./trace-store.js";
|
|
10
|
+
export interface TraceViewerOpenOptions {
|
|
11
|
+
readonly appRoot: string;
|
|
12
|
+
/** Current chat session — its trace opens first. */
|
|
13
|
+
readonly sessionId?: string;
|
|
14
|
+
/** Optional trace id (prefix) from `/traces <trace>`. */
|
|
15
|
+
readonly reference?: string;
|
|
16
|
+
}
|
|
17
|
+
/** The renderer capability the runner's `/traces` dispatch awaits. */
|
|
18
|
+
export interface TraceViewerRenderer {
|
|
19
|
+
open(options: TraceViewerOpenOptions): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export interface TraceViewerSessionOptions extends TraceViewerOpenOptions {
|
|
22
|
+
readonly theme: Theme;
|
|
23
|
+
readonly paint: (rows: readonly string[]) => void;
|
|
24
|
+
readonly dimensions: () => {
|
|
25
|
+
readonly width: number;
|
|
26
|
+
readonly height: number;
|
|
27
|
+
};
|
|
28
|
+
readonly tracingDisabled?: boolean;
|
|
29
|
+
readonly store?: TraceStore;
|
|
30
|
+
/** Receives drag-selected text (wired to the clipboard by the renderer). */
|
|
31
|
+
readonly copyText?: (text: string) => void;
|
|
32
|
+
}
|
|
33
|
+
export declare class TraceViewerSession {
|
|
34
|
+
#private;
|
|
35
|
+
constructor(options: TraceViewerSessionOptions);
|
|
36
|
+
start(): void;
|
|
37
|
+
/** Feeds one key through the reducer; returns `"close"` when the viewer should close. */
|
|
38
|
+
handleKey(key: TerminalKey): "close" | undefined;
|
|
39
|
+
repaint(): void;
|
|
40
|
+
dispose(): void;
|
|
41
|
+
}
|