eve 0.29.3 → 0.29.4
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 +18 -0
- package/dist/src/acp/adapter.d.ts +43 -0
- package/dist/src/acp/adapter.js +1 -0
- package/dist/src/acp/line-limit.d.ts +3 -0
- package/dist/src/acp/line-limit.js +1 -0
- package/dist/src/acp/server.d.ts +24 -0
- package/dist/src/acp/server.js +1 -0
- package/dist/src/chunks/{use-eve-agent-DaH3cf8K.js → use-eve-agent-8mofdZcO.js} +45 -10
- package/dist/src/chunks/{use-eve-agent-CyDt3Lny.js → use-eve-agent-bKJbH0k4.js} +45 -10
- package/dist/src/cli/acp/command.d.ts +22 -0
- package/dist/src/cli/acp/command.js +4 -0
- package/dist/src/cli/commands/agent-prompt/build-and-verify.md +4 -0
- package/dist/src/cli/commands/extension-init.js +1 -1
- package/dist/src/cli/commands/init-git.js +1 -1
- package/dist/src/cli/commands/init-repl.js +1 -1
- package/dist/src/cli/commands/init.js +1 -1
- package/dist/src/cli/commands/logs.js +2 -2
- package/dist/src/cli/commands/register-integration-commands.js +1 -1
- package/dist/src/cli/commands/register-registry-commands.js +1 -1
- package/dist/src/cli/commands/registry-project.js +1 -1
- package/dist/src/cli/commands/registry-setup-command.js +1 -1
- package/dist/src/cli/commands/registry.d.ts +14 -2
- package/dist/src/cli/commands/registry.js +1 -1
- package/dist/src/cli/commands/trace.d.ts +2 -2
- package/dist/src/cli/dev/command-options.d.ts +22 -0
- package/dist/src/cli/dev/command-options.js +1 -0
- package/dist/src/cli/dev/diagnostic-dump.js +1 -1
- package/dist/src/cli/dev/diagnostic-sink.js +1 -1
- package/dist/src/cli/dev/local-server-cleanup.js +1 -1
- package/dist/src/cli/dev/local-server-process.js +1 -1
- package/dist/src/cli/dev/tui/command-typeahead.js +1 -1
- package/dist/src/cli/dev/tui/remote-auth.d.ts +6 -3
- package/dist/src/cli/dev/tui/remote-connection-probe.js +1 -1
- package/dist/src/cli/dev/tui/runner.js +1 -1
- package/dist/src/cli/dev/tui/stream-format.d.ts +14 -0
- package/dist/src/cli/dev/tui/stream-format.js +2 -2
- package/dist/src/cli/dev/tui/terminal-background.d.ts +23 -0
- package/dist/src/cli/dev/tui/terminal-background.js +1 -0
- package/dist/src/cli/dev/tui/terminal-renderer.js +12 -12
- package/dist/src/cli/dev/tui/traces/trace-content.d.ts +7 -0
- package/dist/src/cli/dev/tui/traces/trace-content.js +2 -2
- package/dist/src/cli/dev/tui/traces/trace-conversation.d.ts +10 -5
- package/dist/src/cli/dev/tui/traces/trace-conversation.js +1 -1
- package/dist/src/cli/dev/tui/traces/trace-store.js +1 -1
- package/dist/src/cli/dev/tui/traces/trace-surfaces.d.ts +40 -0
- package/dist/src/cli/dev/tui/traces/trace-surfaces.js +1 -0
- package/dist/src/cli/dev/tui/traces/trace-view.d.ts +8 -1
- package/dist/src/cli/dev/tui/traces/trace-view.js +2 -2
- package/dist/src/cli/dev/tui/traces/trace-viewer-session.d.ts +13 -0
- package/dist/src/cli/dev/tui/traces/trace-viewer-session.js +1 -1
- package/dist/src/cli/dev/tui/traces/trace-viewer-state.js +1 -1
- package/dist/src/cli/dev/tui/tui.js +1 -1
- package/dist/src/cli/invoke/invoke.js +1 -1
- package/dist/src/cli/invoke/result.js +1 -1
- package/dist/src/cli/run.d.ts +3 -0
- package/dist/src/cli/run.js +3 -3
- package/dist/src/cli/ui/terminal-text.d.ts +0 -3
- package/dist/src/cli/ui/terminal-text.js +1 -1
- package/dist/src/client/index.d.ts +1 -1
- package/dist/src/client/open-stream.js +1 -1
- package/dist/src/client/session.d.ts +15 -1
- package/dist/src/client/session.js +1 -1
- package/dist/src/client/types.d.ts +9 -0
- package/dist/src/compiled/.vendor-stamp.json +2 -1
- package/dist/src/compiled/@agentclientprotocol/sdk/LICENSE +191 -0
- package/dist/src/compiled/@agentclientprotocol/sdk/index.d.ts +1835 -0
- package/dist/src/compiled/@agentclientprotocol/sdk/index.js +65 -0
- package/dist/src/compiled/@agentclientprotocol/sdk/jsonrpc.d.ts +603 -0
- package/dist/src/compiled/@agentclientprotocol/sdk/schema/guards.gen.d.ts +199 -0
- package/dist/src/compiled/@agentclientprotocol/sdk/schema/index.d.ts +51 -0
- package/dist/src/compiled/@agentclientprotocol/sdk/schema/types.gen.d.ts +6118 -0
- package/dist/src/compiled/@agentclientprotocol/sdk/stream.d.ts +35 -0
- package/dist/src/compiler/artifacts.js +1 -1
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/compiler/model-catalog.js +1 -1
- package/dist/src/compiler/normalize-sandbox.js +1 -1
- package/dist/src/compiler/workspace-resources.js +1 -1
- package/dist/src/discover/project-source.js +1 -1
- package/dist/src/evals/cli/eval.js +2 -2
- package/dist/src/evals/loaders/json.js +1 -1
- package/dist/src/evals/loaders/yaml.js +1 -1
- package/dist/src/evals/runner/artifacts.js +1 -1
- package/dist/src/evals/runner/discover.js +1 -1
- package/dist/src/evals/runner/reporters/junit.js +1 -1
- package/dist/src/evals/session.js +1 -1
- package/dist/src/execution/sandbox/bindings/docker-cli.js +1 -1
- package/dist/src/execution/sandbox/bindings/docker-templates.js +1 -1
- package/dist/src/execution/sandbox/bindings/just-bash-runtime.js +1 -1
- package/dist/src/execution/sandbox/bindings/just-bash.js +1 -1
- package/dist/src/execution/sandbox/bindings/local-backend-utils.js +1 -1
- package/dist/src/execution/sandbox/bindings/microsandbox-lifecycle.js +1 -1
- package/dist/src/execution/sandbox/bindings/microsandbox-metadata.js +1 -1
- package/dist/src/execution/sandbox/bindings/microsandbox-platform.js +1 -1
- package/dist/src/execution/sandbox/bindings/microsandbox-runtime.js +1 -1
- package/dist/src/execution/sandbox/bindings/microsandbox-templates.js +1 -1
- package/dist/src/execution/sandbox/development-cleanup.js +1 -1
- package/dist/src/execution/sandbox/template-prewarm-lock.js +1 -1
- package/dist/src/harness/attachment-staging.js +1 -1
- package/dist/src/internal/application/build-profile.js +1 -1
- package/dist/src/internal/application/build-workspace.js +1 -1
- package/dist/src/internal/application/cache-metadata.js +1 -1
- package/dist/src/internal/application/compiled-artifacts.js +8 -8
- package/dist/src/internal/application/optional-package-install.js +2 -2
- package/dist/src/internal/application/output-publication-artifacts.js +1 -1
- package/dist/src/internal/application/output-publication-journal.js +1 -1
- package/dist/src/internal/application/output-publication-lock.js +1 -1
- package/dist/src/internal/application/output-publication.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/application/paths.js +1 -1
- package/dist/src/internal/application/production-compiler-artifacts.js +1 -1
- package/dist/src/internal/application/tsconfig-dependencies.js +1 -1
- package/dist/src/internal/authored-asset-import-plugin.js +1 -1
- package/dist/src/internal/authored-module-loader.js +3 -3
- package/dist/src/internal/authored-package-tsconfig-paths.js +1 -1
- package/dist/src/internal/materialized-authored-modules.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-artifacts-retention.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-artifacts.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-source-snapshot-copy.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-source-snapshot.js +1 -1
- package/dist/src/internal/nitro/host/build-application.js +1 -1
- package/dist/src/internal/nitro/host/build-extension.js +1 -1
- package/dist/src/internal/nitro/host/build-vercel-agent-summary.js +1 -1
- package/dist/src/internal/nitro/host/configure-nitro-routes.js +3 -3
- package/dist/src/internal/nitro/host/copy-host-middleware.js +1 -1
- package/dist/src/internal/nitro/host/create-application-nitro.js +1 -1
- package/dist/src/internal/nitro/host/cron-handler-route.js +1 -1
- package/dist/src/internal/nitro/host/dev-authored-rebuild-coordinator.js +1 -1
- package/dist/src/internal/nitro/host/dev-authored-source-watcher.js +1 -1
- package/dist/src/internal/nitro/host/dev-host-fingerprint.js +1 -1
- package/dist/src/internal/nitro/host/dev-host-workspace.js +1 -1
- package/dist/src/internal/nitro/host/dev-server-http.js +1 -1
- package/dist/src/internal/nitro/host/dev-server-state.js +1 -1
- package/dist/src/internal/nitro/host/dev-workspace-extensions.js +1 -1
- package/dist/src/internal/nitro/host/extension-build-config.js +1 -1
- package/dist/src/internal/nitro/host/extension-declarations.js +2 -2
- package/dist/src/internal/nitro/host/extension-distribution.js +3 -3
- package/dist/src/internal/nitro/host/extension-state-usage.js +1 -1
- package/dist/src/internal/nitro/host/normalize-vercel-service-crons.js +1 -1
- package/dist/src/internal/nitro/host/start-development-server.js +2 -2
- package/dist/src/internal/nitro/host/start-production-server.js +2 -2
- package/dist/src/internal/nitro/host/types.d.ts +2 -0
- package/dist/src/internal/vercel/project-link.js +1 -1
- package/dist/src/internal/workflow/development-world-client.js +1 -1
- package/dist/src/internal/workflow-bundle/builder-support.js +6 -6
- package/dist/src/internal/workflow-bundle/builder.js +3 -3
- package/dist/src/internal/workflow-bundle/nitro-step-entry.js +2 -2
- package/dist/src/internal/workflow-bundle/vercel-workflow-output.js +1 -1
- package/dist/src/internal/workflow-bundle/workflow-builders.js +1 -1
- package/dist/src/public/channels/discord/discordChannel.js +1 -1
- package/dist/src/public/channels/discord/verify.js +1 -1
- package/dist/src/public/channels/github/auth.js +2 -2
- package/dist/src/public/channels/github/githubChannel.js +1 -1
- package/dist/src/public/channels/github/verify.js +1 -1
- package/dist/src/public/channels/linear/inbound.js +2 -2
- package/dist/src/public/channels/linear/linearChannel.js +1 -1
- package/dist/src/public/channels/linear/verify.js +1 -1
- package/dist/src/public/channels/teams/teamsChannel.js +1 -1
- package/dist/src/public/channels/telegram/verify.js +1 -1
- package/dist/src/public/channels/twilio/twilioChannel.js +1 -1
- package/dist/src/public/models/openai/chatgpt/auth.js +1 -1
- package/dist/src/public/next/server.js +2 -2
- package/dist/src/public/next/vercel-output-config.js +1 -1
- package/dist/src/public/nuxt/dev-server.js +1 -1
- package/dist/src/public/nuxt/vercel-services.js +1 -1
- package/dist/src/public/sveltekit/dev-server.js +1 -1
- package/dist/src/public/sveltekit/vercel-json.js +1 -1
- package/dist/src/runtime/framework-tools/file-state.js +1 -1
- package/dist/src/runtime/sandbox/keys.js +1 -1
- package/dist/src/runtime/workspace/seed-files.js +1 -1
- package/dist/src/setup/boxes/detect-ai-gateway.js +1 -1
- package/dist/src/setup/index.d.ts +1 -0
- package/dist/src/setup/index.js +1 -1
- package/dist/src/setup/integrations/discord/api.d.ts +15 -0
- package/dist/src/setup/integrations/discord/api.js +1 -0
- package/dist/src/setup/integrations/discord/connect.d.ts +24 -0
- package/dist/src/setup/integrations/discord/connect.js +1 -0
- package/dist/src/setup/integrations/discord/setup.d.ts +19 -0
- package/dist/src/setup/integrations/discord/setup.js +8 -0
- package/dist/src/setup/integrations/registry.js +1 -1
- package/dist/src/setup/package-manager.js +1 -1
- package/dist/src/setup/primitives/pm/pnpm.js +3 -3
- package/dist/src/setup/project-resolution.js +1 -1
- package/dist/src/setup/prompter.js +1 -1
- package/dist/src/setup/registry-setup-client.d.ts +6 -2
- package/dist/src/setup/registry-setup-client.js +1 -1
- package/dist/src/setup/scaffold/create/add-to-project.js +1 -1
- package/dist/src/setup/scaffold/create/extension.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +2 -9
- package/dist/src/setup/scaffold/files.js +1 -1
- package/dist/src/setup/scaffold/update/channels.js +2 -2
- package/dist/src/setup/scaffold/update/connections.js +1 -1
- package/dist/src/setup/scaffold/workspace-root.js +1 -1
- package/dist/src/setup/slack-connect-lifecycle.js +1 -1
- package/dist/src/setup/vercel-project-framework.js +1 -1
- package/dist/src/shared/guards.d.ts +2 -0
- package/dist/src/shared/guards.js +1 -1
- package/dist/src/shared/skill-package.js +1 -1
- package/dist/src/shared/skill-paths.d.ts +4 -4
- package/dist/src/shared/skill-paths.js +2 -2
- package/dist/src/shared/vercel-output-directory.js +1 -1
- package/dist/src/source-change/static-source-change.js +1 -1
- package/dist/src/svelte/index.js +1 -1
- package/dist/src/svelte/use-eve-agent.js +1 -1
- package/dist/src/tracing/local-instrumentation-runtime.js +1 -1
- package/dist/src/tracing/local-trace-reader.d.ts +22 -5
- package/dist/src/tracing/local-trace-reader.js +1 -1
- package/dist/src/tracing/local-trace-retention.js +1 -1
- package/dist/src/tracing/local-trace-span-processor.js +1 -1
- package/dist/src/vue/index.js +1 -1
- package/dist/src/vue/use-eve-agent.js +1 -1
- package/docs/channels/discord.mdx +30 -14
- package/docs/guides/acp.md +91 -0
- package/docs/guides/client/streaming.mdx +24 -0
- package/docs/guides/meta.json +1 -0
- package/docs/reference/cli.md +3 -0
- package/package.json +2 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import{PROMPT_COMMANDS,isPromptControlCommand,parsePromptCommand}from"./prompt-commands.js";import{buildAgentHeader}from"./agent-header.js";import{renderAttentionRows,renderBlockLines}from"./blocks.js";import{copyTextToClipboard}from"./clipboard.js";import{dismissTypeahead,inlineCommandHint,isTypeaheadOpen,moveTypeaheadSelection,renderCommandSuggestions,selectedTypeaheadCommand,typeaheadCompletion,typeaheadFor}from"./command-typeahead.js";import{formatDevRebuildStatus,summarizeChangedFiles}from"./dev-rebuild-status.js";import{formatStoredDiagnostic,presentDiagnostic}from"./diagnostic-presentation.js";import{interruptedError}from"./errors.js";import{FileContentCache}from"./file-content-cache.js";import{EMPTY_LINE,PromptHistory,applyLineEditorKey,deleteForward,layoutPromptInput,lineOf,movePromptLine,visibleLine}from"./line-editor.js";import{nextLogDisplayMode}from"./log-display-mode.js";import{MessageQueue,renderMessageQueueRows}from"./message-queue.js";import{initialModelEditorState,transitionModelEditor}from"./model-editor.js";import{promptPlaceholder}from"./prompt-placeholder.js";import{initialProviderPickerState,transitionProviderPicker}from"./provider-picker.js";import{renderQuestionPanel}from"./question-panel.js";import{enterBadge,renderAcknowledgeQuestion,renderFlowPanel,renderModelEditorQuestion,renderSelectQuestion,renderTextQuestion}from"./setup-panel.js";import{formatAssistantResponseStats,formatTokenFlow,formatTurnDuration,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.#
|
|
2
|
-
`);if(this.#T){t!==this.#E&&(this.#E=t,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,isIncompleteOsc,isIncompletePaste,nextKey,sanitizePastedText,stripPasteStart,stripPromptControlCharacters,takeUntil,typewriterText}from"./stream-format.js";import{TraceViewerSession}from"./traces/trace-viewer-session.js";import{buildStatusLine}from"./status-line.js";import{createTheme,detectUnicode}from"./theme.js";import{isPanelRoutedTool,presentPreparingTool,presentTool,readWriteFileInput,toolBaseName}from"./tool-presentation.js";import{groupToolBlocksForDisplay}from"./tool-block-groups.js";import{TurnClock}from"./turn-clock.js";import{allTodoItemsSettled,readTodoToolItems,renderFinishedTodoRows,renderTodoPanelRows}from"./todo-panel.js";import{reduceSetupSelectInput,setupSelectionIntent}from"./setup-selection-input.js";import{BACKGROUND_COLOR_QUERY,parseBackgroundColorReply}from"./terminal-background.js";import{inspectError}from"#internal/logging.js";import{eveVersionTag}from"#cli/banner.js";import{clipVisible,renderInputText,renderInputWithBlockCursor,stripAnsi,stripTerminalControls}from"#cli/ui/terminal-text.js";import{renderCursorRow}from"#setup/cli/option-row.js";import{initialSelectState,reduceSelect,searchActionQuery,selectValueAtCursor}from"#setup/cli/select-state.js";import{toErrorMessage}from"#shared/errors.js";import{StringDecoder}from"node:string_decoder";import{summarizeKnownError}from"#harness/semantic-errors/index.js";import{parseDevRebuildLogLine}from"#internal/nitro/host/dev-watcher-log.js";import{LiveRegion}from"#cli/ui/live-region.js";import{AltScreen}from"#cli/ui/alt-screen.js";import{PROGRESS_PULSE_ASCII_GLYPH,PROGRESS_PULSE_GLYPH,isProgressPulseVisible}from"#cli/ui/progress-pulse.js";import{readGatewayServiceTier}from"#shared/gateway-service-tier.js";function isMultiSelectRequest(e){return e.kind===`multi`||e.kind===`searchable-multi`}function moveActionCursor(e,t,n){return n===0?void 0:e===void 0?t===`down`?0:n-1:(e+(t===`down`?1:-1)+n)%n}function completedTurnStatus(e){return e.interrupted?`Interrupted`:e.cancelled?`Cancelled`:e.continueSession?`Ready`:`Done`}const incompletePasteFlushMs=1e3,STATUS={processing:`Working…`,connectionAuth:`Waiting for connection authorization…`};var TerminalRenderer=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m=[];#h=new Map;#g=new Set;#_=[];#v=new Set;#y=new Map;#b=0;#x=new Map;#S=new FileContentCache;#C=new Set;#w;#T=!1;#E;#D=[];#O;#k=0;#A;#j;#M=``;#N=0;#P=new PromptHistory;#F=!1;#I;#L=!1;#R=Date.now();#z=!1;#B=new TurnClock;#V=EMPTY_LINE;#H=!1;#U={kind:`idle`};#W;#G=STATUS.processing;#K;#q=`eve`;#J=!1;#Y=!1;#X=!1;#Z=!1;#Q=!1;#$;#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;#Ue;setupFlow={begin:(e,t)=>this.#Ye(e,t),end:e=>this.#Xe(e?.preserveDiagnostics??!0),readSelect:e=>this.#Ze(e),readEditableSelect:e=>this.#$e(e),readProviderPicker:e=>this.#et(e),readModelEditor:e=>this.#tt(e),readText:e=>this.#nt(e),readAcknowledge:e=>this.#rt(e),readChoice:e=>this.#Qe(e),setStatus:e=>this.#dt(e),renderLine:(e,t)=>this.#ft(e,t),renderOutput:e=>this.#pt(e),withInheritedStdio:e=>this.#mt(e),withExclusiveTerminal:e=>this.#mt(e),waitForInterrupt:e=>this.#ct(e)};traceViewer={open:e=>this.#gt(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.#yt();let t=this.#cn().join(`
|
|
2
|
+
`);if(this.#T){t!==this.#E&&(this.#E=t,this.#It({kind:`agent-header`,body:t,live:!1})),this.#rn();return}this.#T=!0,this.#E=t,this.#n.flush(this.#cn(),[])}async readPrompt(e){this.#yt(e),this.#Ft(),this.#Rt(),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.#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.#
|
|
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.#
|
|
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.#
|
|
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.#d===void 0){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.#We(a),this.#I=typeaheadFor(this.#f,a.text),this.#At(),this.#rn(),await new Promise((e,r)=>{this.#W=r;let apply=e=>{a=e,this.#Mt(),this.#We(a),this.#I=typeaheadFor(this.#f,e.text,this.#I),this.#rn()},recall=e=>{e!==void 0&&apply(lineOf(e))},interrupt=()=>{this.#I=void 0,this.#jt(),this.#xt(),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.#rn();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.#rn();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.#rn());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.#jt(),this.#G=STATUS.processing,isPromptControlCommand(i)?this.#It({kind:`command`,body:stripTerminalControls(i.trim()),live:!1}):(this.#Pt(),this.#Lt(i),this.#De=i,this.#B.arm()),this.#We(EMPTY_LINE),this.#rn(),this.#Ct(),e(i);break}case`ctrl-d`:a.text.length===0?(this.#ht(),interrupt()):apply(deleteForward(a));break;case`ctrl-l`:this.#on();break;case`ctrl-r`:this.#rn();break;case`ctrl-c`:a.text.length===0?(this.#ht(),interrupt()):apply(EMPTY_LINE);break;default:break}},this.#St()})}#We(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.#yt(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.#zt(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.#Nt(),this.#H=!0,this.#rn();let r=new Promise(e=>{this.#fe=e});this.#se=e=>this.#kt(e),this.#St();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.#Gt(t,n,i)}}catch(e){let t=summarizeKnownError(e);t===null?this.#Bt(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#Bt(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#fe=void 0,this.#Z&&e.abort?.(),this.#Pe=void 0,this.#Ct(),this.#Ft(),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.#Qt(i),(this.#Z||this.#Fe)&&this.#Zt(),this.#Wt(),this.#d?.reportStats(),this.#rn(),t?.continueSession||this.#xt()}}async readToolApproval(e,t){return this.#yt(t),this.#Ft(),this.#F=!1,this.#U={kind:`idle`},this.#G=`Approve ${formatToolApprovalTitle(e)}? (y/n)`,this.#Z=!1,this.#rn(),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.#Pt(),this.#G=STATUS.processing,this.#Ct(),this.#rn(),t({approved:!0})):n===`n`&&(this.#Pt(),this.#G=STATUS.processing,this.#Ke(e.toolCallId),this.#Ct(),this.#rn(),t({approved:!1,reason:`Denied by user.`}));break}case`ctrl-r`:this.#rn();break;case`ctrl-c`:this.#Z=!0,this.#xt(),n(interruptedError());break;default:break}},this.#St()})}async readInputQuestion(e,t){this.#yt(t),this.#Ft(),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.#Ht({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:formatQuestionContent(e,void 0,this.#i),preformatted:!0,live:!0})},syncFreeformCaret=()=>{isOnFreeformRow()?this.#At():(this.#jt(),this.#Mt())};s===`overlay`?(s=`overlay`,this.#F=!1,this.#Ut(o),this.#Oe=overlayPanel,this.#G=``,syncFreeformCaret(),this.#rn()):(s=`text`,this.#Oe=void 0,renderTextSection(),this.#F=!0,this.#We(l),this.#G=``,this.#At(),this.#rn());let finalize=t=>{this.#Oe=void 0,this.#Ht({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.#Pt(),this.#G=STATUS.processing,this.#jt(),this.#Ct(),this.#rn();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.#Ht({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.#jt(),this.#Ct(),this.#rn(),u(void 0)},moveCursor=e=>{a!==0&&(c=(c+e+a)%a,syncFreeformCaret(),this.#rn())},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.#Mt(),s===`text`&&this.#We(l),this.#rn();return}this.#Z=!0,this.#Oe=void 0,this.#jt(),this.#xt(),r(interruptedError());return}if(t.type===`ctrl-r`){this.#rn();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.#Mt(),this.#rn();break}dismiss();break;default:if(isOnFreeformRow()){let e=applyLineEditorKey(l,t);e!==void 0&&(l=e,this.#Mt(),this.#rn());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.#rn())}break}return}let a=applyLineEditorKey(l,t,{multiline:!0});if(a!==void 0){l=a,this.#Mt(),this.#We(l),this.#rn();return}switch(t.type){case`up`:case`down`:{let e=movePromptLine(l,t.type);e!==void 0&&(l=e,this.#Mt(),this.#We(l),this.#rn());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.#Mt(),this.#We(l),this.#rn();break}dismiss();break;default:break}},this.#St()})}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.#Vt(e.callId,e.subagentName),this.#s===`collapsed`){this.#rn();return}this.#Ht({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.#rn()}}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.#Vt(e.callId,e.subagentName),this.#s===`collapsed`){this.#rn();return}let t=subagentToolStatus(e.status),n=e.status===`preparing`?presentPreparingTool(e.toolName):presentTool(e.toolName,e.input,this.#Yt({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.#Ht(r),this.#Ge(e.callId),this.#rn()}#Ge(e){applyCohortLiveness(this.#m.filter(t=>t.kind===`subagent-tool`&&t.subagentCallId===e).map(e=>({block:e,active:isActiveToolStatus(e.status)})))}removeSubagentTool(e){this.#Ut(subagentToolSectionId(e.callId,e.childCallId)),this.#rn()}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.#Vt(e.callId,e.name);let t=this.#h.get(subagentHeaderId(e.callId));t?.status===`done`&&delete t.status,this.#rn()}completeSubagent(e){let t=this.#h.get(subagentHeaderId(e.callId));t!==void 0&&(t.status=`done`,this.#rn())}markChildToolCallId(e){this.#v.add(e);let t=this.#y.get(e);t!==void 0&&(this.#Ut(t),this.#y.delete(e),this.#rn())}#Ke(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.#Ht({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.#rn()}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.#rn()):n&&(this.#G=STATUS.processing,this.#rn())}setVercelStatus(e){this.#A=e,this.#rn()}setRemoteConnectionStatus(e){this.#j=e,this.#rn()}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.#qe(),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.#rn())}renderSessionBoundary(){this.#Rt(),this.#qe();let e=this.#i.colors,t=this.#i.glyph,n=e.dim(`${t.cornerOpen}${t.dash.repeat(2)} Session restarted, clear context.`);this.#It({kind:`session-boundary`,body:n,live:!1}),this.#rn()}#qe(){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.#yt(),this.#It({kind:`notice`,body:t,live:!1}),this.#rn())}renderSandboxLog(e){let t=parseSandboxLogLine(stripTerminalControls(e));t!==void 0&&(this.#d?.append({source:`sandbox`,detail:t}),this.#yt(),this.#It({kind:`sandbox`,body:t,live:!1}),this.#rn())}renderSetupWarning(e){let t=stripTerminalControls(e);if(t.trim().length===0){this.#Je();return}this.#yt(),this.#Ae=t,this.#rn()}clearSetupWarning(){this.#Je()}#Je(){this.#Ae!==void 0&&(this.#Ae=void 0,this.#rn())}renderCommandInvocation(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;this.#yt();let r={kind:`command`,body:n,live:!1};t===`failed`&&(r.status=`error`),this.#It(r),this.#rn()}renderCommandResult(e,t){let n=stripTerminalControls(e);n.trim().length!==0&&(this.#yt(),this.#It(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.#rn())}#Ye(e,t=`spinner`){this.#yt(),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.#Nt(),this.#rn()}#Xe(e){this.#Be=void 0,this.#ut();let t=this.#ke;if(t!==void 0){if(this.#ke=void 0,this.#Ft(),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.#It({kind:`flow`,title:`info`,body:e.join(`
|
|
5
|
+
`),live:!1}),this.#It({kind:`flow`,title:n.tone,body:n.text,live:!1})),e=[]}}this.#rn()}}async#Ze(e){let t=this.#it(),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.#rn()},loadSearch=async(e,t)=>{c=!0,s=void 0;let a=++l;this.#rn();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.#rn())}},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.#un()),t};return t.question=e=>renderSelectQuestion(panelState(),this.#i,e),this.#rn(),await this.#st((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.#rn();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.#rn();return;case`update`:o=d.select,s=void 0,this.#rn();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.#rn();return;case`ignore`:return}}).promise}#Qe(e){this.#yt();let t=this.#at();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.#rn();let r=this.#st((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.#rn();return;case`repaint`:this.#rn();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#$e(e){let t=this.#it(),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.#At():(i=lineOf(``),this.#jt())};return syncEditableRow(),this.#rn(),await this.#st((t,n)=>{let applyEditor=e=>{i=e,a=void 0,this.#Mt(),this.#rn()},applySelect=t=>{r=reduceSelect(r,t,{options:e.options}),a=void 0,syncEditableRow(),this.#rn()},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.#rn();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.#rn();return;case void 0:break}if(!onEditableRow())return;let s=applyLineEditorKey(i,t);s!==void 0&&applyEditor(s)},()=>this.#jt()).promise}async#et(e){let t=this.#it(),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.#At():this.#jt()};return syncCaret(),this.#rn(),await this.#st((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.#rn();return;case`cancel`:i(void 0);return;case`render`:n=o.state,syncCaret(),this.#rn();return;case`validate`:{n=o.state,syncCaret(),this.#rn();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.#rn();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.#Mt(),dispatch({type:`edit`,editor:s}))},()=>{r?.abort(),r=void 0,this.#jt()}).promise}async#tt(e){let t=this.#it(),n=initialModelEditorState(e);return t.question=t=>renderModelEditorQuestion({request:e,state:n},this.#i,t),this.#rn(),await this.#st((t,r)=>{let dispatch=t=>{let i=transitionModelEditor(n,t,e);switch(i.kind){case`ignore`:return;case`render`:n=i.state,this.#rn();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.#rn();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#nt(e){let t=this.#it(),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.#At(),this.#rn(),await this.#st((t,i)=>{let apply=e=>{n=e,r=void 0,this.#Mt(),this.#rn()},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.#rn();return;case`enter`:{let t=n.text.length>0?n.text:e.defaultValue??``,a=e.validate?.(t);if(a!==void 0){r=a,this.#rn();return}i(t);return}default:return}},()=>this.#jt()).promise}async#rt(e){let t=this.#it();return t.question=t=>renderAcknowledgeQuestion({message:e.message,lines:e.lines},this.#i,t),this.#rn(),await this.#st((e,t)=>{switch(e.type){case`enter`:case`escape`:case`ctrl-c`:t();return;case`ctrl-r`:this.#rn();return;default:return}}).promise}#it(){return this.#yt(),this.#F=!1,this.#U={kind:`idle`},this.#G=``,this.#at()}#at(){return this.#ke===void 0&&(this.#ke={title:``,indicator:{kind:`spinner`},lines:[],outputBuffer:[],implicit:!0}),this.#ke}#ot(){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.#Ct(),this.#ke!==void 0&&this.#lt(),this.#rn()}#st(e,t){let n=!1,r,i,a=new Promise((e,t)=>{r=e,i=t}),settle=e=>{n||(n=!0,t?.(),this.#ot(),r(e))},reject=e=>{n||(n=!0,t?.(),this.#ot(),i(e))};return this.#Ot(),this.#se=t=>{t.type===`ctrl-c`&&this.#ht(),e(t,settle,reject)},this.#St(),{promise:a,settle}}#ct(e){let t,n=new Promise(e=>{t=e});return this.#Be=t,this.#lt(e?.interruptible??!0),{promise:n,dispose:()=>{this.#Be===t&&(this.#Be=void 0,this.#ut())}}}#lt(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.#ht();let e=this.#Be;this.#Be=void 0,this.#ut(),e?.();return}t.type===`ctrl-r`&&this.#rn()};this.#Ve=consumer,this.#Ot(),this.#se=consumer,this.#St()}#ut(){this.#Ve!==void 0&&(this.#se===this.#Ve&&this.#Ct(),this.#Ve=void 0)}#dt(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.#rn();return}if(!(this.#F||this.#H)){if(t===void 0){this.#U={kind:`idle`},this.#K=void 0,this.#Ft(),this.#rn();return}this.#yt(),this.#Pt(),this.#K=t.text,this.#rn()}}#ft(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.#rn();return}this.#yt(),this.#It({kind:`flow`,title:t,body:n,live:!1}),this.#rn()}#pt(e){let t=stripTerminalControls(e);if(t.trim().length===0)return;let n=this.#ke;if(n===void 0){this.#ft(t,`info`);return}n.preview=t,n.outputBuffer.push(t),n.outputBuffer.length>40&&n.outputBuffer.shift(),this.#rn()}async#mt(e){this.#ce=``,this.#Ot(),this.#Be=void 0,this.#ut(),this.#Ct(),this.#Ft(),this.#n.clear(),this.#n.showCursor(),this.#Tn(),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.#Ot(),this.#n.hideCursor(),this.#wn(),this.#ke!==void 0&&(this.#Nt(),this.#lt()),this.#n.reset(),this.#rn()}}setSessionId(e){this.#Ie=e}shutdown(){if(this.#xt(),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.#xt()}exitRequested(){return this.#Q}#ht(){this.#Q=!0,this.#$?.()}async#gt(e){if(this.#He!==void 0||!this.#J)return;let t=new TraceViewerSession({...e,theme:this.#i,dimensions:()=>({width:this.#Sn(),height:this.#Cn()}),paint:e=>this.#r.paint(e,this.#Cn()),tracingDisabled:process.env.EVE_TRACES===`off`,copyText:e=>copyTextToClipboard(e,e=>this.#r.writeRaw(e)),terminalBackground:this.#Ue});this.#He=t,this.#r.enter(),this.#i.color&&this.#r.writeRaw(BACKGROUND_COLOR_QUERY),await new Promise(e=>{this.#vt=e,this.#se=e=>{t.handleKey(e)===`close`&&this.#_t()},this.#St(),t.start()})}#_t(){let e=this.#He;if(e===void 0)return;this.#He=void 0,e.dispose(),this.#Ct(),this.#r.exit(),this.#n.hideCursor(),this.#rn(),this.#n.showCursor();let t=this.#vt;this.#vt=void 0,t?.()}#vt;#yt(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.#wn(),this.#e.isTTY&&(this.#e.setRawMode?.(!0),this.#e.resume(),this.#n.emitBracketedPaste(!0)),this.#de=()=>this.#rn(),this.#t.on(`resize`,this.#de),process.on(`exit`,this.#bt))}#bt=()=>{this.#J&&(this.#r.exit(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1)),this.#n.showCursor())};#xt(){this.#_t();let e=this.#W;if(this.#W=void 0,e?.(interruptedError()),this.#Ct(),this.#jt(),this.#Ft(),this.#ae!==void 0&&(clearTimeout(this.#ae),this.#ae=void 0),this.#oe=!1,this.#J){this.#Nn();for(let e of this.#m)e.kind===`log`&&e.id===void 0&&(e.live=!1);this.#rn(),this.#n.clear(),this.#n.showCursor(),this.#Tn(),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.#bt),this.#J=!1}}#St(){this.#e.off(`data`,this.#wt),this.#e.on(`data`,this.#wt),this.#ce.length>0&&queueMicrotask(()=>{this.#se!==void 0&&this.#ce.length>0&&(this.#Et(),this.#Tt())})}#Ct(){this.#e.off(`data`,this.#wt),this.#Ot(),this.#se=void 0}#wt=e=>{this.#Ot(),this.#ce+=this.#le.write(e),this.#Et(),this.#Tt()};#Tt(){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`})},incompletePasteFlushMs),this.#ue.unref?.();return}if(isIncompleteOsc(this.#ce)){let e=this.#ce;this.#ue=setTimeout(()=>{this.#ce===e&&(this.#ce=``)},incompletePasteFlushMs),this.#ue.unref?.()}}#Et(){for(;this.#ce.length>0;){let e=nextKey(this.#ce);if(e.incomplete)return;if(this.#ce=this.#ce.slice(e.consumed),!(e.key===void 0||e.key.type===`ignore`)){if(e.key.type===`osc`){this.#Dt(e.key.value);continue}this.#se?.(e.key)}}}#Dt(e){let t=parseBackgroundColorReply(e);t!==void 0&&(this.#Ue=t,this.#He?.setTerminalBackground(t))}#Ot(){this.#ue&&=(clearTimeout(this.#ue),void 0)}#kt(e){switch(e.type){case`ctrl-l`:case`ctrl-r`:this.#rn();break;case`ctrl-c`:this.#Z||(this.#Z=!0,this.#U={kind:`idle`},this.#G=`Interrupted`,this.#fe?.(),this.#rn());break;case`enter`:{let e=this.#V.text;if(e.trim().length===0)break;this.#Ne.enqueue(e)&&(this.#V=EMPTY_LINE),this.#rn();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.#rn();break}default:{this.#Ne.disarm();let t=applyLineEditorKey(this.#V,e,{multiline:!0});t!==void 0&&(this.#V=t,this.#rn());break}}}#At(){this.#jt(),this.#Mt(),this.#re=setInterval(()=>{this.#ee=!this.#ee,this.#rn()},500),this.#re.unref?.()}#jt(){this.#re&&=(clearInterval(this.#re),void 0),this.#ee=!0}#Mt(){this.#ee=!0}#Nt(){this.#Ft(),this.#ie=setInterval(()=>{this.#te+=1,this.#rn()},90),this.#ie.unref?.()}#Pt(){let e=Date.now();this.#ne=e,this.#U={kind:`waiting`,startedAtMs:e},this.#Nt()}#Ft(){this.#ie&&=(clearInterval(this.#ie),void 0)}#It(e){e.id!==this.#Te?.id&&this.#Nn(),e.updateSeq=++this.#b,this.#m.push(e),e.id&&this.#h.set(e.id,e)}#Lt(e){this.#z=!0,this.#It({kind:`user`,body:stripTerminalControls(e),live:!1}),this.#rn()}#Rt(){let e=this.#B.settle();if(e===void 0||e.elapsedMs<=1e4&&e.inputTokens<=2e4)return;let t=`Done in ${this.#hn(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.#It({kind:`turn-stats`,body:t,live:!1})}#zt(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.#It(n)}#Bt(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.#It(c),this.#rn()}#Vt(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.#It(i)}#Ht(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.#It(e)}#Ut(e){this.#m=this.#m.filter(t=>t.id!==e),this.#h.delete(e)}#Wt(){for(let e of this.#m)e.status===`approval`||e.status===`running`||e.kind===`connection-auth`&&e.live||(e.live=!1)}#Gt(e,t,n){switch(e.type){case`step-finish`:this.#d?.recordStepUsage(e.usage),e.usage!==void 0&&this.#B.addUsage(e.usage),this.#Qt(n),this.#nn(e.usage),this.#rn();break;case`assistant-delta`:{let t=(n.text.get(e.id)??``)+stripTerminalControls(e.delta);n.text.set(e.id,t),this.#Kt(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.#Kt(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.#qt(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.#qt(e.id,r,!1,t);break}break}case`tool-call-preparing`:if(t.tools===`hidden`||isPanelRoutedTool(e.toolName))break;this.#Jt({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.#Jt({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.#Jt({...r,status:`approval`},t,n);break}case`tool-result`:{if(t.tools===`hidden`)break;let r=this.#tn(e.toolCallId,n);if(r===void 0)break;this.#Jt({...r,output:e.output,status:`done`},t,n);break}case`tool-error`:{let r=this.#tn(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.#Jt({...r,errorText:e.errorText,status:`error`},t,n);break}case`tool-rejected`:{if(t.tools===`hidden`)break;let r=this.#tn(e.toolCallId,n);if(r===void 0)break;this.#Jt({...r,errorText:e.reason,status:`denied`},t,n);break}case`error`:this.#Bt(`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.#nn(e.usage),this.#rn();break}}#Kt(e,t,n){let r=stripTerminalControls(t).trim();r.length!==0&&(this.#Ht({id:e,kind:`assistant`,body:r,live:n}),this.#rn())}#qt(e,t,n,r){let i=stripTerminalControls(t).trim();i.length!==0&&(this.#Ht({id:e,kind:`reasoning`,body:i,collapsed:collapseReasoning(r.reasoning,n),live:n}),this.#rn())}#Jt(e,t,n){if(n.tools.set(e.toolCallId,e),this.#v.has(e.toolCallId)||this.#$t(e)||toolBaseName(e.toolName)===`ask_question`)return;let r=toolSectionId(e.toolCallId);this.#y.set(e.toolCallId,r);let i=this.#Yt(e);this.#Ht(renderNativeToolBlock(e,r,t.tools===`full`,i)),this.#en(n),this.#rn()}#Yt(e){e.output!==void 0&&this.#S.observeRead(e.output);let t={};this.#Xt(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}#Xt(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)}#Zt(){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)}#Qt(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.#Ut(r),this.#y.delete(t)}}#$t(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.#It({kind:`todo-list`,body:renderFinishedTodoRows(t,this.#Sn(),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.#rn(),!0}#en(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)}#tn(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`}}#nn(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)}}#rn(){if(this.#J){if(this.#pe){this.#me=!0;return}this.#pe=!0;try{do this.#me=!1,this.#in();while(this.#me)}finally{this.#pe=!1}}}#in(){if(!this.#J)return;if(this.#He!==void 0){this.#He.repaint();return}let e=this.#Sn(),t=this.#pn(e),n=Math.max(1,this.#Cn()-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.#Fn(t.display))continue;let n=this.#ln(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.#Fn(t))continue;let n=this.#ln(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)}#an(){if(!this.#J)return;let e=this.#Sn(),t=this.#pn(e),n=Math.max(1,this.#Cn()-t.length),r=this.#O,i=[];for(let{display:t}of groupToolBlocksForDisplay(this.#m)){if(this.#Fn(t))continue;let n=this.#ln(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.#cn(),...this.#D],a)}logDisplayMode(){return this.#p}setLogDisplayMode(e){e!==this.#p&&(this.#p=e,e===`all`&&this.flushDelayedDevBuildErrors(),this.#sn(),this.#J&&this.#an())}flushDelayedDevBuildErrors(){let e=this.#we;e!==void 0&&(this.#we=void 0,this.#It({kind:`log`,title:`stderr`,body:e,live:!0}),this.#rn())}#on(){this.#oe=!0,this.#ae!==void 0&&clearTimeout(this.#ae),this.#ae=setTimeout(()=>{this.#oe=!1,this.#ae=void 0,this.#rn()},5e3),this.setLogDisplayMode(nextLogDisplayMode(this.#p)),this.#rn()}#sn(){let e=this.#Sn();this.#D.length=0;let t;for(let{display:n}of groupToolBlocksForDisplay(this.#_,{logCoalescing:`runs`})){if(this.#Fn(n))continue;let r=this.#ln(n,e,t);t=previousBlockOf(n),this.#D.push(...r)}this.#O=t}#cn(){let e=this.#w;if(e===void 0)return[];let t={name:e.name,theme:this.#i,width:this.#Sn()};return e.info!==void 0&&(t.info=e.info),e.tip!==void 0&&(t.tip=e.tip),buildAgentHeader(t)}#ln(e,t,n){let r={activityPulse:this.#dn(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}#un(){return this.#i.spinner[this.#te%this.#i.spinner.length]??``}#dn(e,t){return isProgressPulseVisible(Date.now()-e)?t:` `}#fn(e,t){return e.indicator.kind===`spinner`?{glyph:this.#un(),color:`yellow`}:{glyph:this.#dn(e.indicator.startedAtMs,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH),color:t?.kind===`external-action`?`yellow`:`green`}}#pn(e){let n=this.#i.colors,r=[``];if(this.#Oe!==void 0)return r.push(...this.#Oe(e),``),this.#yn(r,e),r;let a=this.#ke;if(a!==void 0){let t=this.#fn(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.#bn(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.#dn(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.#yn(s,e);let u=Math.max(1,this.#Cn()-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.#mn(e)),this.#_n(r,e);let t=[];return this.#yn(t,e),!this.#H&&t.length>0&&r.push(``),r.push(...t),r}if(this.#V.text.length>0)return this.#vn(r,e,{inert:!1}),this.#yn(r,e),r;let u=this.#K??(this.#G.length>0?this.#G:`Ready`),f=this.#xn(),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.#yn(r,e),r}#mn(e){let t=this.#i.colors,n=this.#dn(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.#hn(a)}`;return clip(`${t.yellow(n)} ${t.dim(o)}`,e)}#hn(e){return`${formatTurnDuration(e)}${this.#gn()}`}#gn(){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)}`}#_n(e,t){this.#H&&this.#vn(e,t,{inert:!0})}#vn(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))}#yn(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))}#bn(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))}#xn(){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} `)):``}#Sn(){return Math.max(20,this.#t.columns||80)}#Cn(){return Math.max(8,this.#t.rows||24)}#wn(){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.#Dn(t,chunkToString(e,i)),a?.(),!0}),()=>{e.write=n}},e=capture(process.stdout,`stdout`),t=capture(process.stderr,`stderr`);this.#d?.subscribeLogRecords(e=>this.#En(e)),this.#xe=()=>{this.#d?.unsubscribeLogRecords(),e(),t()}}#Tn(){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.#Pn(`stdout`)&&process.stdout.write(`${this.#Se}\n`),this.#Se=``),this.#Ce.length>0&&(this.#d?.append({source:`stderr`,detail:this.#Ce}),this.#Pn(`stderr`)&&process.stderr.write(`${this.#Ce}\n`),this.#Ce=``))}#En(e){let t=e.fields===void 0?``:` ${JSON.stringify(e.fields)}`;this.#kn(`[eve:${e.namespace}] ${e.message}${t}`),this.#rn()}#Dn(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.#On(n.trimEnd()),this.#rn();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.#On(a):this.#kn(a),this.#rn())}#On(e){let t=[],flushPending=()=>{if(t.length===0)return;let e=t.join(`
|
|
9
|
+
`);t=[],e.trim().length!==0&&this.#It({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.#It({kind:`sandbox`,body:e,live:!1});continue}let r=parseDevRebuildLogLine(n.trimEnd());if(r===void 0){t.push(n);continue}flushPending(),this.#jn(r,n.trimEnd())}flushPending()}#kn(e){let t=e.split(`
|
|
11
|
+
`),n=t.findIndex(e=>parseDevRebuildLogLine(e.trimEnd())?.kind===`failed`);if(n===-1){if(this.#d===void 0){this.#It({kind:`log`,title:`stderr`,body:e,live:!0});return}let t=presentDiagnostic(e,this.#d.displayPath);if(t.kind===`inline`){this.#It({kind:`log`,title:`stderr`,body:t.text,live:!0});return}this.#It({kind:`log`,title:`stderr`,body:formatStoredDiagnostic(t),logVisibility:`stderr-only`,live:!0}),this.#It({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.#It({kind:`log`,title:`stderr`,body:r,live:!0});let i=t.slice(n).join(`
|
|
13
|
+
`);this.#An(i)}#An(e){if(this.#p===`all`){if(e.trim().length===0)return;this.#It({kind:`log`,title:`stderr`,body:e,live:!0});return}this.#we=e}#jn(e,t){let n=this.#Mn();if(e.kind===`failed`){this.#An(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.#It({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.#It({kind:`log`,title:`stdout`,body:t,live:!0})}#Mn(){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}}#Nn(){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)}#Pn(e){switch(this.#p){case`none`:return!1;case`stderr`:return e===`stderr`;case`sandbox`:return e===`sandbox`;case`all`:return!0}}#Fn(e){return e.kind===`sandbox`?!this.#Pn(`sandbox`):e.kind===`log`?e.logVisibility===`stderr-only`?this.#p!==`stderr`:e.logVisibility===`all-only`?this.#p!==`all`:!this.#Pn(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};
|
|
@@ -17,6 +17,13 @@ import type { Theme } from "../theme.js";
|
|
|
17
17
|
* under the key.
|
|
18
18
|
*/
|
|
19
19
|
export declare function formatAttributeContent(key: string, value: unknown, theme: Theme, width: number): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Wraps text to `width`, splitting on embedded newlines so a multi-line payload
|
|
22
|
+
* keeps its shape, and stripping control bytes the frame must not carry.
|
|
23
|
+
*/
|
|
24
|
+
export declare function wrapPlainText(text: string, width: number): string[];
|
|
25
|
+
/** Formats a payload: JSON structure pretty-prints, anything else stays text. */
|
|
26
|
+
export declare function formatPayloadContent(text: string, width: number): string[];
|
|
20
27
|
/** Pretty-prints a JSON value with two-space indents, wrapped to `width`. */
|
|
21
28
|
export declare function prettyJson(value: unknown, width: number): string[];
|
|
22
29
|
/**
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{stripTerminalControls,visibleLength,wrapVisibleLine}from"#cli/ui/terminal-text.js";function formatAttributeContent(t,r,i
|
|
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};
|
|
1
|
+
import{stripTerminalControls,visibleLength,wrapVisibleLine}from"#cli/ui/terminal-text.js";function formatAttributeContent(t,n,r,i){if(typeof n!=`string`)return Array.isArray(n)?prettyJson(n,i):[stripTerminalControls(shortJson(n))];if(t===`ai.prompt.messages`){let e=messageTranscript(n,r,i);if(e!==void 0)return e}return formatPayloadContent(n,i)}function wrapPlainText(t,r){return splitEmbeddedNewlines([stripTerminalControls(t)]).flatMap(e=>wrapVisibleLine(e,r))}function formatPayloadContent(e,t){let n=parseJson(e);return n!==void 0&&(Array.isArray(n)||isRecord(n))?prettyJson(n,t):wrapPlainText(e,t)}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,formatPayloadContent,prettyJson,splitEmbeddedNewlines,wrapPlainText};
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { LocalTrace, LocalTraceSpan } from "#tracing/local-trace-reader.js";
|
|
10
10
|
import type { Theme } from "../theme.js";
|
|
11
|
+
import type { TraceViewerSurfaces } from "./trace-surfaces.js";
|
|
11
12
|
export interface ConversationItem {
|
|
12
13
|
readonly kind: "system" | "user" | "assistant" | "tool";
|
|
13
14
|
/** Detail-drawer source for this item (the turn marker span for users). */
|
|
@@ -46,12 +47,16 @@ export interface ConversationSubagent {
|
|
|
46
47
|
/** Builds the conversation flow for a trace, one item per message/action. */
|
|
47
48
|
export declare function buildConversationItems(trace: LocalTrace): ConversationItem[];
|
|
48
49
|
/**
|
|
49
|
-
* Renders one conversation card, width-clipped:
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
50
|
+
* Renders one conversation card, width-clipped: a title row (bold kind plus
|
|
51
|
+
* dim metadata, metrics right-aligned) over body rows. With `surfaces`
|
|
52
|
+
* (derived from the terminal's background via the OSC 11 probe) the card
|
|
53
|
+
* draws as two elevated bands; without them it falls back to a gutter rail —
|
|
54
|
+
* the same vocabulary the dev transcript uses. Both layouts occupy identical
|
|
55
|
+
* rows and columns, so scroll/click math and drag-copy column mapping never
|
|
56
|
+
* depend on whether the probe was answered. Collapsed cards cap their
|
|
57
|
+
* payloads; expanded ones render them in full.
|
|
53
58
|
*/
|
|
54
|
-
export declare function renderConversationItem(item: ConversationItem, width: number, theme: Theme, selected: boolean, expanded: boolean): string[];
|
|
59
|
+
export declare function renderConversationItem(item: ConversationItem, width: number, theme: Theme, selected: boolean, expanded: boolean, surfaces?: TraceViewerSurfaces): string[];
|
|
55
60
|
/** Rendered height of one card — the conversation viewport scrolls by lines. */
|
|
56
61
|
export declare function conversationItemLineCount(item: ConversationItem, width: number, theme: Theme, expanded: boolean): number;
|
|
57
62
|
/** Whether a card has content hidden behind the collapsed cap at this width. */
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{formatCompactTokenCount}from"../stream-format.js";import{
|
|
1
|
+
import{formatCompactTokenCount}from"../stream-format.js";import{formatPayloadContent,wrapPlainText}from"./trace-content.js";import{SURFACE_CLOSE}from"./trace-surfaces.js";import{formatElapsed}from"#cli/format-elapsed.js";import{compareLocalTraceSpans}from"#tracing/local-trace-reader.js";import{clipVisible,stripTerminalControls,visibleLength}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 i=[];for(let e of r){let r=turnSubagent(e),o=[],walk=e=>{o.push(e);for(let t of n.get(e.spanId)??[])walk(t)};if(walk(e),o.sort(compareLocalTraceSpans),i.length===0){let e=o.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&&i.push({item:{kind:`system`,durationMs:0,error:!1,span:e,subagent:r,text:t},order:0n})}let c=extractUserText(o.find(isModelSpan));c!==void 0&&i.push({item:{kind:`user`,durationMs:0,error:!1,span:e,subagent:r,text:c},order:e.startTimeNs});for(let e of o)if(isModelSpan(e)){let n=stringAttribute(e,`ai.response.text`),a=stringAttribute(e,`ai.response.reasoning`),o=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)&&(a===void 0||a.trim().length===0)&&!o&&!c&&e.statusCode!==2)continue;i.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:a,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`)))i.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`&&i.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 i.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(r,a,o,c,l,u){let{colors:d,glyph:f}=o,p=Math.max(8,a-8),m=conversationItemExpandable(r,a),h=o.color?u:void 0,g=h?.primaryText??d.white,_,v,y=[];if(r.kind===`tool`){let e=d.bold(g(r.name??`tool`));_=`${foldMarker(l,m,o)}${e}`,v=r.durationMs>0?d.dim(formatElapsed(r.durationMs)):``;let n=r.args===void 0?[]:formatPayloadContent(r.args,p),a=r.result===void 0?[]:formatPayloadContent(r.result,p),s=l?n:capLines(n,p),c=l?a:capLines(a,p);s.length>0&&y.push(``,d.dim(`Input:`),``,...s),c.length>0&&y.push(``,d.dim(`Output:`),``,...c)}else if(r.kind===`system`){_=`${foldMarker(l,m,o)}${d.bold(g(`system`))}`,v=d.dim(`~${formatCompactTokenCount(estimateTokens(r.text??``))} tokens`);let t=wrapPlainText(r.text??``,p);y.push(...l?t:capLines(t,p))}else if(r.kind===`assistant`){_=`${foldMarker(l,m,o)}${d.bold(g(`assistant`))}${r.model===void 0?``:d.dim(` · ${stripTerminalControls(r.model)}`)}`,v=assistantMetrics(r,f,d);let e=r.reasoning===void 0||r.reasoning.trim().length===0?[]:wrapPlainText(r.reasoning,p),t=r.text===void 0||r.text.trim().length===0?[]:wrapPlainText(r.text,p),i=(l?e:capLines(e,p)).map(e=>d.dim(e)),a=l?t:capLines(t,p);if(i.length>0&&(y.push(d.dim(`Thought:`),``,...i),a.length>0&&y.push(``)),y.push(...a),(r.text===void 0||r.text.trim().length===0)&&r.toolCallNames!==void 0&&r.toolCallNames.length>0){i.length>0&&y.push(``);for(let e of r.toolCallNames)y.push(d.dim(`→ ${e}`))}}else{let e=r.kind===`user`&&r.subagent!==void 0?`task`:r.kind;_=`${foldMarker(l,m,o)}${d.bold(g(e))}`,v=``;let t=r.text===void 0||r.text.trim().length===0?[]:wrapPlainText(r.text,p);y.push(...l?t:capLines(t,p))}if(r.subagent!==void 0){let e=r.subagent.name===void 0?`subagent`:`subagent:${r.subagent.name}`;_+=d.dim(` · ${e}`)}r.error&&(_+=` ${d.red(f.error)}`),!l&&m?y.push(`…`,``,d.dim(`Click to expand`)):l&&m&&y.push(``,d.dim(`Click to collapse`));let b=h===void 0?void 0:r.error?h.errorHeader:h.header,x=h===void 0?void 0:r.error?h.errorBody:h.body,S=railCell(o,c,r.error,h);return[cardRow(``,a,o,S,b),cardSplitRow(_,v,a,o,S,b),cardRow(``,a,o,S,b),cardRow(``,a,o,S,x),...y.map(e=>cardRow(e,a,o,S,x)),cardRow(``,a,o,S,x)]}function cardRow(e,t,n,i,a){let s=clipVisible(e,Math.max(1,t-8)),l=` `.repeat(Math.max(0,t-8-visibleLength(s)));return a===void 0||!n.color?` ${i} ${s}${l} `:` ${i}${a} ${s.replaceAll(`\x1B[0m`,`\x1b[0m${a}`)}\x1b[0m${a}${l} ${SURFACE_CLOSE} `}function railCell(e,t,n,r){let{colors:i,glyph:a}=e;if(t){let t=e.unicode?`▌`:a.rule;return r===void 0?i.white(t):r.primaryText(t)}return r===void 0?n?i.red(a.rule):i.dim(a.rule):` `}function cardSplitRow(e,t,n,r,i,a){if(visibleLength(t)===0)return cardRow(e,n,r,i,a);let s=Math.max(1,n-8),l=visibleLength(t),u=clipVisible(e,Math.max(1,s-l-2));return cardRow(`${u}${` `.repeat(Math.max(2,s-visibleLength(u)-l))}${t}`,n,r,i,a)}function assistantMetrics(t,n,r){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?``:r.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 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,r){let i=Math.max(8,r-8);if(e.kind===`tool`){let n=e.args===void 0?0:formatPayloadContent(e.args,i-2).length,r=e.result===void 0?0:formatPayloadContent(e.result,i-2).length;return n>3||r>3}if(e.kind===`system`)return wrapPlainText(e.text??``,i).length>3;if(e.kind===`user`)return(e.text===void 0||e.text.trim().length===0?0:wrapPlainText(e.text,i).length)>3;let a=e.reasoning===void 0||e.reasoning.trim().length===0?0:wrapPlainText(e.reasoning,i).length,o=e.text===void 0||e.text.trim().length===0?0:wrapPlainText(e.text,i).length;return a>3||o>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
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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{assembleLocalTrace,listLocalTraceIds,listLocalTraceSegments,readLocalTraceActivityMs,readLocalTraceSegment}from"#tracing/local-trace-reader.js";function createTraceStore(i){let a=new Map;return{async list(){let e=[];for(let n of await listLocalTraceIds(i.appRoot)){let t=await readLocalTraceActivityMs(i.appRoot,n);t!==void 0&&e.push({traceId:n,lastActivityMs:t})}return e.sort((e,t)=>t.lastActivityMs===e.lastActivityMs?e.traceId.localeCompare(t.traceId):t.lastActivityMs-e.lastActivityMs)},async read(t){let r=await listLocalTraceSegments(i.appRoot,t);if(r===void 0){a.delete(t);return}let o=a.get(t);o===void 0&&(o={seen:new Set,spans:new Map},a.set(t,o));let s=!1;for(let e of r)if(!o.seen.has(e)){o.seen.add(e);for(let n of await readLocalTraceSegment(i.appRoot,t,e))o.spans.has(n.spanId)||(o.spans.set(n.spanId,n),s=!0)}if(o.spans.size!==0)return(s||o.assembled===void 0)&&(o.assembled=assembleLocalTrace(t,[...o.spans.values()])),o.assembled}}}export{createTraceStore};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Card surfaces for the `/traces` viewer, derived from the terminal's own
|
|
3
|
+
* background color (the OSC 11 probe) so they look native in any theme: a
|
|
4
|
+
* dark background gets slightly lighter bands, a light background slightly
|
|
5
|
+
* darker ones, and error bands blend toward red from either side. When the
|
|
6
|
+
* terminal never answers the probe, the viewer falls back to gutter rails.
|
|
7
|
+
*/
|
|
8
|
+
import type { RgbColor } from "../terminal-background.js";
|
|
9
|
+
/** Truecolor background opens (`ESC[48;2;…m`) for the viewer's card bands. */
|
|
10
|
+
export interface TraceViewerSurfaces {
|
|
11
|
+
/** Card title band. */
|
|
12
|
+
readonly header: string;
|
|
13
|
+
/** Card body band, slightly more elevated than the header. */
|
|
14
|
+
readonly body: string;
|
|
15
|
+
readonly errorHeader: string;
|
|
16
|
+
readonly errorBody: string;
|
|
17
|
+
/**
|
|
18
|
+
* Style for primary text over the surfaces (card titles, selection bar,
|
|
19
|
+
* toast): truecolor white on dark backgrounds, truecolor black on light
|
|
20
|
+
* ones. The theme's fixed bright-white primary assumes a dark terminal
|
|
21
|
+
* and washes out on light backgrounds.
|
|
22
|
+
*/
|
|
23
|
+
readonly primaryText: (text: string) => string;
|
|
24
|
+
/**
|
|
25
|
+
* Style for secondary text (control hints, header metadata, drawer
|
|
26
|
+
* labels): a truecolor grey blended from the probed background toward the
|
|
27
|
+
* primary, so muted text keeps guaranteed contrast on any background.
|
|
28
|
+
*/
|
|
29
|
+
readonly mutedText: (text: string) => string;
|
|
30
|
+
}
|
|
31
|
+
/** Closes a surface, restoring the terminal's default background. */
|
|
32
|
+
export declare const SURFACE_CLOSE = "\u001B[49m";
|
|
33
|
+
/**
|
|
34
|
+
* Derives the viewer's card surfaces from the terminal's background color.
|
|
35
|
+
* Everything — bands and text styles alike — is truecolor: palette colors
|
|
36
|
+
* (SGR 30/97) and SGR dim are theme-remappable, so a terminal like ghostty
|
|
37
|
+
* can render them without contrast against the very background it reported.
|
|
38
|
+
* Truecolor is exempt from palette remapping and always lands as derived.
|
|
39
|
+
*/
|
|
40
|
+
export declare function deriveTraceViewerSurfaces(background: RgbColor): TraceViewerSurfaces;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const SURFACE_CLOSE=`\x1B[49m`,ERROR_ACCENT={r:230,g:105,b:123},WHITE={r:255,g:255,b:255},BLACK={r:0,g:0,b:0};function deriveTraceViewerSurfaces(e){let r=relativeLuminance(e)<.5?WHITE:BLACK,i=foregroundOpen(r),a=foregroundOpen(mix(e,r,.55));return{header:backgroundOpen(mix(e,r,.086)),body:backgroundOpen(mix(e,r,.141)),errorHeader:backgroundOpen(mix(e,ERROR_ACCENT,.3)),errorBody:backgroundOpen(mix(e,ERROR_ACCENT,.25)),primaryText:e=>`${i}${e}\x1b[39m`,mutedText:e=>`${a}${e}\x1b[39m`}}function backgroundOpen(e){return`\x1b[48;2;${e.r};${e.g};${e.b}m`}function foregroundOpen(e){return`\x1b[38;2;${e.r};${e.g};${e.b}m`}function mix(e,t,n){let blend=(e,t)=>Math.round(e+(t-e)*n);return{r:blend(e.r,t.r),g:blend(e.g,t.g),b:blend(e.b,t.b)}}function relativeLuminance(e){return(.2126*e.r+.7152*e.g+.0722*e.b)/255}export{SURFACE_CLOSE,deriveTraceViewerSurfaces};
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { LocalTraceSpan } from "#tracing/local-trace-reader.js";
|
|
9
9
|
import type { Theme } from "../theme.js";
|
|
10
|
+
import type { TraceViewerSurfaces } from "./trace-surfaces.js";
|
|
10
11
|
import type { TextSelectionRange, TraceViewerState } from "./trace-viewer-state.js";
|
|
11
12
|
export interface TraceViewerFrame {
|
|
12
13
|
readonly rows: readonly string[];
|
|
@@ -29,16 +30,22 @@ export interface RenderTraceViewerOptions {
|
|
|
29
30
|
readonly tracingDisabled?: boolean;
|
|
30
31
|
/** Transient confirmation shown in the header's top-right corner. */
|
|
31
32
|
readonly toast?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Card surfaces derived from the terminal's background (OSC 11 probe).
|
|
35
|
+
* Absent when the terminal never answered — cards fall back to rails.
|
|
36
|
+
*/
|
|
37
|
+
readonly surfaces?: TraceViewerSurfaces;
|
|
32
38
|
}
|
|
33
39
|
export declare function renderTraceViewer(state: TraceViewerState, options: RenderTraceViewerOptions): TraceViewerFrame;
|
|
34
40
|
export declare function renderSpanDetail(span: LocalTraceSpan, innerWidth: number, theme: Theme, options?: {
|
|
35
41
|
readonly excludeKeys?: ReadonlySet<string>;
|
|
42
|
+
readonly surfaces?: TraceViewerSurfaces;
|
|
36
43
|
}): string[];
|
|
37
44
|
/**
|
|
38
45
|
* Plain text covered by a drag selection over the conversation, extracted
|
|
39
46
|
* from the same rendered lines the user saw.
|
|
40
47
|
*/
|
|
41
|
-
export declare function conversationSelectionText(state: TraceViewerState, width: number, theme: Theme, selection: TextSelectionRange): string;
|
|
48
|
+
export declare function conversationSelectionText(state: TraceViewerState, width: number, theme: Theme, selection: TextSelectionRange, surfaces?: TraceViewerSurfaces): string;
|
|
42
49
|
/**
|
|
43
50
|
* Plain text covered by a drag selection over the details drawer, extracted
|
|
44
51
|
* from the same detail lines the frame painted. `totalWidth` is the full
|
|
@@ -1,2 +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),
|
|
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:
|
|
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=chromeStyles(i,t.surfaces),o=Math.max(1,r-3-3),s=e.panelOpen?panelWidthFor(n):0,c=Math.max(20,n-(s===0?0:s+1)),l=panelDetailLines(e,s,i,t.surfaces),u=o,d=[];if(d.push(...renderHeader(e,t)),e.traces.length===0)d.push(...renderEmptyState(t,i,o));else if(e.trace===void 0)d.push(...center(o,a.muted(`Loading trace…`)));else{let r=renderConversation(e,t,c,o);for(let t=0;t<o;t+=1){let i=r[t]??``;if(s===0){d.push(i);continue}let a=l[e.panelScroll+t]??``;e.textSelection!==void 0&&e.textSelection.region===`panel`&&(a=highlightSelection(a,e.panelScroll+t,e.textSelection,s)),d.push(joinPanels(i,c,a,n))}}return d.push(...renderFooter(e,n,i,t.surfaces)),t.toast!==void 0&&overlayToast(d,t.toast,n,i,t.surfaces),{rows:d,panelTotalRows:l.length,timelineViewportRows:o,panelViewportRows:u,contentWidth:c}}function chromeStyles(e,t){let n=e.color?t:void 0;return{muted:n?.mutedText??e.colors.dim,primary:n?.primaryText??(e=>e)}}function overlayToast(e,t,n,r,i){let a=` ${stripTerminalControls(t)} `,o=visibleLength(a),s=r.unicode?`▌`:r.glyph.rule,c=r.color?i:void 0,d=c===void 0?``:c.body,f=c?.primaryText??r.colors.white,p=r.color?`\x1B[0m`:``,m=[`${d}${f(s)}${` `.repeat(o)}${p}`,`${d}${f(s)}${f(a)}${p}`,`${d}${f(s)}${` `.repeat(o)}${p}`];for(let[t,r]of m.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,{muted:u,primary:f}=chromeStyles(r,s?.surfaces),p=[],m=stripTerminalControls(t.name);p.push(...wrapVisibleLine(c.bold(f(m)),n));let h=describeLocalTraceSpan(t).map(stripTerminalControls);h.length>0&&p.push(u(h.join(`, `))),p.push(``);let fact=(e,t)=>`${u(e.padEnd(10))}${t}`,g=t.statusCode===2;p.push(fact(`status`,g?c.red(`ERROR`):c.green(`ok`))),p.push(fact(`duration`,formatElapsed(durationMs(t.startTimeNs,t.endTimeNs)))),p.push(fact(`started`,clockTime(t.startTimeNs))),p.push(fact(`span`,t.spanId)),t.parentSpanId!==void 0&&p.push(fact(`parent`,t.parentSpanId)),t.scope!==void 0&&p.push(fact(`scope`,stripTerminalControls(t.scope))),p.push(``);let _=Object.keys(t.attributes).filter(e=>s?.excludeKeys?.has(e)!==!0).sort();if(_.length===0)p.push(u(`no attributes`));else{p.push(u(`attributes (${_.length})`));for(let i of _){let a=formatAttributeContent(i,t.attributes[i],r,n-2),o=stripTerminalControls(i);if(a.length===1)p.push(...wrapVisibleLine(`${u(o)} ${a[0]}`,n));else{p.push(u(o));for(let e of a)p.push(` ${e}`)}}}return p.map(e=>clipVisible(e,n))}function renderHeader(e,t){let{theme:n,width:r}=t,{colors:a,glyph:s}=n,{muted:c,primary:d}=chromeStyles(n,t.surfaces),f=[];if(e.trace?.agentName!==void 0&&f.push(stripTerminalControls(e.trace.agentName)),e.trace?.sessionId!==void 0&&f.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;f.push(clockTime(e.trace.startTimeNs),`${e.trace.spans.length} span${e.trace.spans.length===1?``:`s`}`,formatElapsed(durationMs(e.trace.startTimeNs,n)))}let p=`${a.bold(d(`${s.brand} traces`))}${f.length===0?``:c(` · ${f.join(` · `)}`)}`,m=e.traces.length===0?``:c(`[${e.traceIndex+1}/${e.traces.length}]`),h=[t.activeWindowEndNs===void 0?``:a.green(`● live`),m].filter(e=>e.length>0).join(` `);return[``,clipVisible(joinRight(` ${clipVisible(p,Math.max(0,r-visibleLength(h)-2))}`,h,r),r),``]}function renderConversation(e,t,n,r){let{theme:i}=t;if(e.conversationItems.length===0)return[chromeStyles(i,t.surfaces).muted(` No conversation content in this trace — content capture may be off (EVE_TRACES_CONTENT).`)];let a=conversationLines(e,n,i,t.surfaces).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,i){let a=[];for(let o=0;o<e.conversationItems.length;o+=1)a.push(...renderConversationItem(e.conversationItems[o],n,r,o===e.selectedRow,e.expandedItems.has(o),i),``);return a}function panelDetailLines(e,t,n,i){let a=selectedTraceViewerSpan(e);return!e.panelOpen||t<=0||a===void 0?[]:[``,...renderSpanDetail(a,Math.max(16,t-3),n,{excludeKeys:CONVERSATION_CONTENT_KEYS,surfaces:i}).map(e=>` ${e}`)]}function conversationSelectionText(e,t,n,r,i){return selectionText(conversationLines(e,t,n,i),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,r){let{colors:i}=n,{muted:a}=chromeStyles(n,r),[s,c]=n.unicode?[`↑↓`,`←→`]:[`^/v`,`</>`],l=e.panelFocus?`${s} scroll · tab cards · esc back`:`${s} select · ${c} expand · enter attrs · tab focus · [ ] traces · q close`,u=e.conversationItems.length,d=u===0?``:a(`item ${e.selectedRow+1}/${u}`),f=[e.notice===void 0?``:i.yellow(e.notice),d].filter(e=>e.length>0).join(a(` · `));return[``,clipVisible(` ${a(l)}`,t),clipVisible(f.length===0?``:` ${f}`,t)]}function renderEmptyState(e,t,n){let{muted:r,primary:i}=chromeStyles(t,e.surfaces),[a,o]=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.`];return center(n,t.colors.bold(i(a)),r(o))}function center(e,...t){let n=Array.from({length:e},()=>``),r=Math.max(0,Math.floor(e/2)-1);return t.forEach((t,i)=>{r+i<e&&(n[r+i]=t)}),n}function joinPanels(e,t,n,r){let i=Math.max(0,r-t-1);return`${padTo(e,t)} ${clipVisible(n,i)}`}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};
|