@bastani/atomic 0.9.38-alpha.9 → 0.9.39-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/CHANGELOG.md +119 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +16 -0
  3. package/dist/builtin/intercom/index.bundle.mjs +216 -2
  4. package/dist/builtin/intercom/package.json +1 -1
  5. package/dist/builtin/mcp/package.json +1 -1
  6. package/dist/builtin/subagents/CHANGELOG.md +16 -0
  7. package/dist/builtin/subagents/package.json +1 -1
  8. package/dist/builtin/subagents/src/extension/index.bundle.mjs +16 -1
  9. package/dist/builtin/web-access/CHANGELOG.md +7 -0
  10. package/dist/builtin/web-access/package.json +1 -1
  11. package/dist/builtin/workflows/CHANGELOG.md +74 -0
  12. package/dist/builtin/workflows/package.json +1 -1
  13. package/dist/builtin/workflows/src/durable/journal/resolution.d.ts +2 -15
  14. package/dist/builtin/workflows/src/extension/index.bundle.mjs +532 -64
  15. package/dist/builtin/workflows/src/index.js +301 -27
  16. package/dist/cli.js +13 -6
  17. package/dist/cli.js.map +1 -1
  18. package/dist/config.d.ts +1 -0
  19. package/dist/config.d.ts.map +1 -1
  20. package/dist/config.js +1 -0
  21. package/dist/config.js.map +1 -1
  22. package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
  23. package/dist/core/agent-session-extension-bindings.js +4 -1
  24. package/dist/core/agent-session-extension-bindings.js.map +1 -1
  25. package/dist/core/agent-session-methods.d.ts +1 -0
  26. package/dist/core/agent-session-methods.d.ts.map +1 -1
  27. package/dist/core/agent-session-methods.js.map +1 -1
  28. package/dist/core/agent-session-prompt.d.ts.map +1 -1
  29. package/dist/core/agent-session-prompt.js +57 -15
  30. package/dist/core/agent-session-prompt.js.map +1 -1
  31. package/dist/core/agent-session-types.d.ts +1 -0
  32. package/dist/core/agent-session-types.d.ts.map +1 -1
  33. package/dist/core/agent-session-types.js.map +1 -1
  34. package/dist/core/agent-session.d.ts +1 -0
  35. package/dist/core/agent-session.d.ts.map +1 -1
  36. package/dist/core/agent-session.js +2 -0
  37. package/dist/core/agent-session.js.map +1 -1
  38. package/dist/core/export-html/index.d.ts.map +1 -1
  39. package/dist/core/export-html/index.js +13 -10
  40. package/dist/core/export-html/index.js.map +1 -1
  41. package/dist/core/extensions/api-types.d.ts +2 -0
  42. package/dist/core/extensions/api-types.d.ts.map +1 -1
  43. package/dist/core/extensions/api-types.js.map +1 -1
  44. package/dist/core/extensions/context-types.d.ts +5 -0
  45. package/dist/core/extensions/context-types.d.ts.map +1 -1
  46. package/dist/core/extensions/context-types.js.map +1 -1
  47. package/dist/core/extensions/loader-api.d.ts.map +1 -1
  48. package/dist/core/extensions/loader-api.js +4 -0
  49. package/dist/core/extensions/loader-api.js.map +1 -1
  50. package/dist/core/extensions/runner-context.d.ts.map +1 -1
  51. package/dist/core/extensions/runner-context.js +1 -0
  52. package/dist/core/extensions/runner-context.js.map +1 -1
  53. package/dist/core/extensions/runner.d.ts +1 -0
  54. package/dist/core/extensions/runner.d.ts.map +1 -1
  55. package/dist/core/extensions/runner.js +3 -0
  56. package/dist/core/extensions/runner.js.map +1 -1
  57. package/dist/core/extensions/runtime-types.d.ts +1 -0
  58. package/dist/core/extensions/runtime-types.d.ts.map +1 -1
  59. package/dist/core/extensions/runtime-types.js.map +1 -1
  60. package/dist/core/queued-input-admission.d.ts +20 -0
  61. package/dist/core/queued-input-admission.d.ts.map +1 -0
  62. package/dist/core/queued-input-admission.js +55 -0
  63. package/dist/core/queued-input-admission.js.map +1 -0
  64. package/dist/core/sdk-types.d.ts +7 -1
  65. package/dist/core/sdk-types.d.ts.map +1 -1
  66. package/dist/core/sdk-types.js.map +1 -1
  67. package/dist/core/sdk.js +1 -0
  68. package/dist/core/sdk.js.map +1 -1
  69. package/dist/core/session-manager-core.d.ts +1 -0
  70. package/dist/core/session-manager-core.d.ts.map +1 -1
  71. package/dist/core/session-manager-core.js +12 -0
  72. package/dist/core/session-manager-core.js.map +1 -1
  73. package/dist/core/storage/provider.d.ts +14 -0
  74. package/dist/core/storage/provider.d.ts.map +1 -1
  75. package/dist/core/storage/provider.js.map +1 -1
  76. package/dist/core/storage/session/legacy-session-store.d.ts +4 -1
  77. package/dist/core/storage/session/legacy-session-store.d.ts.map +1 -1
  78. package/dist/core/storage/session/legacy-session-store.js +42 -2
  79. package/dist/core/storage/session/legacy-session-store.js.map +1 -1
  80. package/dist/core/storage/session/legacy-session-summary.d.ts +8 -0
  81. package/dist/core/storage/session/legacy-session-summary.d.ts.map +1 -1
  82. package/dist/core/storage/session/legacy-session-summary.js +42 -2
  83. package/dist/core/storage/session/legacy-session-summary.js.map +1 -1
  84. package/dist/extensions/mcp/client/transports/streamable-http.js +9 -8
  85. package/dist/extensions/mcp/client/transports/streamable-http.js.map +1 -1
  86. package/dist/modes/interactive/components/chat-session-host-actions.d.ts +4 -0
  87. package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -1
  88. package/dist/modes/interactive/components/chat-session-host-actions.js +104 -30
  89. package/dist/modes/interactive/components/chat-session-host-actions.js.map +1 -1
  90. package/dist/modes/interactive/components/chat-session-host-events.d.ts.map +1 -1
  91. package/dist/modes/interactive/components/chat-session-host-events.js +1 -0
  92. package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -1
  93. package/dist/modes/interactive/components/chat-session-host-state.d.ts +4 -0
  94. package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -1
  95. package/dist/modes/interactive/components/chat-session-host-state.js +4 -0
  96. package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -1
  97. package/dist/modes/interactive/components/session-selector.js +4 -3
  98. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  99. package/dist/modes/interactive/interactive-input-handling.js +8 -2
  100. package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
  101. package/dist/modes/interactive/interactive-mode-base.d.ts +4 -0
  102. package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
  103. package/dist/modes/interactive/interactive-mode-base.js +4 -0
  104. package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
  105. package/dist/modes/interactive/interactive-process-lifecycle.js +8 -2
  106. package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -1
  107. package/dist/modes/interactive/interactive-queueing.js +94 -73
  108. package/dist/modes/interactive/interactive-queueing.js.map +1 -1
  109. package/dist/modes/interactive/interactive-session-runtime.js +1 -0
  110. package/dist/modes/interactive/interactive-session-runtime.js.map +1 -1
  111. package/dist/modes/interactive-engine/create-isolated-runtime.d.ts.map +1 -1
  112. package/dist/modes/interactive-engine/create-isolated-runtime.js +2 -0
  113. package/dist/modes/interactive-engine/create-isolated-runtime.js.map +1 -1
  114. package/dist/modes/interactive-engine/engine-heap.d.ts +24 -0
  115. package/dist/modes/interactive-engine/engine-heap.d.ts.map +1 -0
  116. package/dist/modes/interactive-engine/engine-heap.js +88 -0
  117. package/dist/modes/interactive-engine/engine-heap.js.map +1 -0
  118. package/dist/modes/rpc/rpc-client-api.d.ts +1 -0
  119. package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
  120. package/dist/modes/rpc/rpc-client-api.js +3 -0
  121. package/dist/modes/rpc/rpc-client-api.js.map +1 -1
  122. package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
  123. package/dist/modes/rpc/rpc-command-handler.js +7 -0
  124. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  125. package/dist/modes/rpc/rpc-types.d.ts +9 -0
  126. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  127. package/dist/modes/rpc/rpc-types.js.map +1 -1
  128. package/dist/utils/heap-relaunch.d.ts +14 -0
  129. package/dist/utils/heap-relaunch.d.ts.map +1 -0
  130. package/dist/utils/heap-relaunch.js +59 -0
  131. package/dist/utils/heap-relaunch.js.map +1 -0
  132. package/docs/environment-variables.md +2 -1
  133. package/docs/intercom/reference.md +1 -1
  134. package/docs/rpc/protocol.md +23 -0
  135. package/docs/sdk/web-server.md +1 -1
  136. package/docs/sdk.md +10 -1
  137. package/docs/session-format.md +1 -0
  138. package/docs/sessions.md +2 -0
  139. package/docs/settings.md +1 -1
  140. package/docs/usage.md +2 -0
  141. package/docs/workflows/api-reference.md +1 -1
  142. package/docs/workflows/operations.md +5 -1
  143. package/npm-shrinkwrap.json +32 -32
  144. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"interactive-mode-base.js","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-mode-base.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACN,YAAY,EACZ,aAAa,EAEb,sBAAsB,GAGtB,MAAM,wBAAwB,CAAC;AAKhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAE3F,OAAO,EAAE,4BAA4B,EAAE,MAAM,kCAAkC,CAAC;AAEhF,OAAO,EAAE,gCAAgC,EAAE,MAAM,yBAAyB,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EASN,SAAS,EAET,YAAY,EAMZ,eAAe,EACf,kBAAkB,EAClB,cAAc,EAEd,0BAA0B,EAC1B,kBAAkB,EAIlB,cAAc,EACd,mBAAmB,EAInB,KAAK,EACL,mBAAmB,EACnB,OAAO,GACP,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAE/E,OAAO,EACN,oBAAoB,EACpB,6BAA6B,EAC7B,oCAAoC,GAGpC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,kFAAkF;AAClF,MAAM,oCAAoC,GAAG;IAC5C,sBAAsB;IACtB,wBAAwB;IACxB,0BAA0B;IAC1B,4BAA4B;IAC5B,sBAAsB;I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CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC;YACnE,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;SAC/C,CAAC,EACH;YACC,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY;YACvD,kBAAkB,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC;SACpE,EACD,CAAC,OAAO,EAAE,EAAE;YACX,IAAI,CAAC,gCAAgC,GAAG,OAAO,CAAC;YAChD,IAAI,CAAC,aAAa,CAAC,mBAAmB,GAAG,OAAO,CAAC;YACjD,OAAO,GAAG,EAAE;gBACX,IAAI,IAAI,CAAC,gCAAgC,KAAK,OAAO;oBAAE,IAAI,CAAC,gCAAgC,GAAG,SAAS,CAAC;gBACzG,IAAI,IAAI,CAAC,aAAa,CAAC,mBAAmB,KAAK,OAAO;oBACrD,IAAI,CAAC,aAAa,CAAC,mBAAmB,GAAG,SAAS,CAAC;YACrD,CAAC,CAAC;QACH,CAAC,EACD,IAAI,CAAC,WAAW,EAChB,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,sBAAsB,CAAC,KAAK,CAAC,EAC3D,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CACnD,CAAC;IACH,CAAC;IAED,0DAA0D;IAC1D,MAAM,CAAU,gBAAgB,GAAG,EAAE,CAAC;IAEtC;;;;OAIG;IACH,cAAc,GAAG,KAAK,CAAC;IACvB,yBAAyB,GAAG,KAAK,CAAC;CAClC","sourcesContent":["/**\n * Shared state and constructor wiring for interactive mode.\n * Responsibility-specific behavior is installed by sibling modules.\n */\nimport {\n\tisKeyRelease,\n\tisViewportTUI,\n\ttype ScrollView,\n\tsetCapabilityOverrides,\n\ttype TuiInputListener,\n\ttype WheelScrollLines,\n} from \"@earendil-works/pi-tui\";\nimport type { AgentSessionQueuePauseControl } from \"../../core/agent-session-methods.ts\";\nimport type { MarkdownTransformer } from \"../../core/extensions/types.ts\";\nimport type { FullscreenExitOutput, MermaidRenderingMode } from \"../../core/settings-manager.ts\";\nimport type { EarlyInputSnapshot } from \"../../main-early-input.ts\";\nimport { readClipboardText } from \"../../utils/clipboard.js\";\nimport { renderEngineDiagnostic } from \"../interactive-engine/engine-diagnostic-view.js\";\nimport { attachInteractiveEngineHost } from \"../interactive-engine/extension-ui-bridge.ts\";\nimport type { RemoteToolExecutionComponent } from \"../interactive-engine/remote-renderer.ts\";\nimport { KeybindingsReloadCoordinator } from \"../rpc/rpc-keybindings-reload.ts\";\nimport type { AtomicWorkingLoader } from \"./components/atomic-working-status.ts\";\nimport { createMermaidMarkdownTransformer } from \"./components/mermaid.ts\";\nimport type { TranscriptOverlayReserve } from \"./components/reserved-bottom-overlay.ts\";\nimport { WidgetContainer } from \"./components/scroll-widget.js\";\nimport {\n\ttype AgentSession,\n\ttype AgentSessionRuntime,\n\ttype AssistantMessage,\n\ttype AssistantMessageComponent,\n\ttype AutocompleteProvider,\n\ttype AutocompleteProviderFactory,\n\ttype BashExecutionComponent,\n\ttype Component,\n\tContainer,\n\ttype CountdownTimer,\n\tCustomEditor,\n\ttype EditorComponent,\n\ttype EditorFactory,\n\ttype ExtensionEditorComponent,\n\ttype ExtensionInputComponent,\n\ttype ExtensionSelectorComponent,\n\tFooterComponent,\n\tFooterDataProvider,\n\tgetEditorTheme,\n\ttype HostCustomUiStateListener,\n\tInteractiveThemeController,\n\tKeybindingsManager,\n\ttype Loader,\n\ttype LoaderIndicatorOptions,\n\ttype Spacer,\n\tsetKeybindings,\n\tsetRegisteredThemes,\n\ttype Text,\n\ttype ToolExecutionComponent,\n\ttype TUI,\n\ttheme,\n\tUsageMeterComponent,\n\tVERSION,\n} from \"./interactive-mode-deps.ts\";\nimport type {} from \"./interactive-mode-surface.ts\";\nimport type { CompactionQueuedMessage, InteractiveModeOptions } from \"./interactive-mode-types.ts\";\nimport { StartupChatContainer } from \"./interactive-startup-chat-container.ts\";\nimport type { InteractiveSubmission } from \"./interactive-submission.ts\";\nimport {\n\tcreateInteractiveTui,\n\tcreateInteractiveTuiReference,\n\thandleFocusedOverlayInternalUiAction,\n\ttype InteractiveTui,\n\ttype InternalUiActionResult,\n} from \"./interactive-tui.ts\";\nimport { ProgramStatusReporter } from \"./program-status-reporter.ts\";\n\n/** Move the transcript and nothing else: what a reserving overlay may release. */\nconst FULLSCREEN_TRANSCRIPT_SCROLL_ACTIONS = [\n\t\"tui.altScreen.pageUp\",\n\t\"tui.altScreen.pageDown\",\n\t\"tui.altScreen.halfPageUp\",\n\t\"tui.altScreen.halfPageDown\",\n\t\"tui.altScreen.lineUp\",\n\t\"tui.altScreen.lineDown\",\n\t\"tui.altScreen.previousPrompt\",\n\t\"tui.altScreen.nextPrompt\",\n\t\"tui.altScreen.top\",\n\t\"tui.altScreen.bottom\",\n] as const;\n\nconst FULLSCREEN_VIEWPORT_ACTIONS = FULLSCREEN_TRANSCRIPT_SCROLL_ACTIONS;\n\nexport function isFullscreenViewportAction(data: string, keybindings: KeybindingsManager): boolean {\n\treturn FULLSCREEN_VIEWPORT_ACTIONS.some((action) => keybindings.matches(data, action));\n}\n\n/**\n * Whether a key scrolls the transcript. A reserving overlay — the\n * `ask_user_question` dialog, an extension component with\n * `reserveTranscriptRows` — declines these so the strip above it still pages\n * and jumps (#2378), and keeps everything else.\n */\nexport function isFullscreenTranscriptScrollAction(data: string, keybindings: KeybindingsManager): boolean {\n\treturn FULLSCREEN_TRANSCRIPT_SCROLL_ACTIONS.some((action) => keybindings.matches(data, action));\n}\n\n/**\n * Decide whether the fullscreen viewport should run before the focused\n * component. `isMouseInput` is classified by pi-tui's own mouse predicate in\n * `AtomicTuiAltScreen`, so this policy does not duplicate terminal grammars.\n * Mouse deferral is limited to actual overlays so inline components do not\n * disable pi-tui's application-owned transcript selection path.\n *\n * **Who owns viewport keys while an overlay is focused.** pi-tui 0.84.2 added\n * `shouldDeferViewportInputToOverlay()` (upstream #7894) and answers \"the\n * overlay\". Atomic answers \"the overlay first, the transcript with whatever it\n * declines\" (#2378 / PR #2381): the actions in `FULLSCREEN_VIEWPORT_ACTIONS`\n * and wheel reports are offered to the focused overlay, and\n * `AtomicTuiAltScreen` replays what it does not consume into pi-tui's viewport\n * listener. Atomic's answer stands, because a mounted dialog that keeps its\n * selection keys must not also freeze the transcript behind it.\n *\n * **The list covers every `tui.altScreen.*` scroll action pi-tui defines.**\n * An action a focused overlay declines still reaches the transcript, so the\n * shortcut is never simply lost.\n *\n * **A focused overlay with no `handleInput` is still an overlay.** The handler\n * is optional — `ExtensionCustomComponent` marks it `handleInput?` and\n * `docs/tui.md` documents it as optional — and a component that cannot answer\n * declines by definition. Answering \"the viewport owns it\" for that shape\n * would hand the key to pi-tui, whose native deferral then drops it because an\n * overlay holds focus, so the transcript would freeze behind a component that\n * never asked for the key. A handler-less overlay therefore takes the same\n * route as one that returns `false`: nothing to offer, then replay. Only a\n * focused component that is *not* an overlay keeps the shortcut, because\n * pi-tui defers nothing to it.\n */\nexport function shouldHandleFullscreenViewportInput(\n\tfocused: Component | null,\n\teditor: Component,\n\tdata: string,\n\tisMouseInput: boolean,\n\tfocusedIsOverlay: boolean,\n\tkeybindings: KeybindingsManager,\n\t_focusedIsViewportSearch = false,\n): boolean {\n\tif (focused === editor || !focused) return true;\n\tif (!focused.handleInput && !focusedIsOverlay) return true;\n\tif (isMouseInput) return !focusedIsOverlay;\n\tif (focusedIsOverlay && keybindings.matches(data, \"app.thinking.toggle\")) return false;\n\treturn !isFullscreenViewportAction(data, keybindings);\n}\n\nfunction isCommandLikeStartupInput(text: string): boolean {\n\tconst trimmed = text.trimStart();\n\treturn trimmed.startsWith(\"/\") || trimmed.startsWith(\"!\");\n}\n\nexport function seedStartupInput(\n\tpendingUserInputs: InteractiveSubmission[],\n\teditor: { setText(text: string): void },\n\tstartupInput: EarlyInputSnapshot | undefined,\n\tstartupReplayInputs: string[] = [],\n\tsetStartupDraftText?: (text: string) => void,\n\tsetStartupReplayActiveInput?: (text: string) => void,\n): void {\n\tif (!startupInput) return;\n\tlet commandReplayStarted = false;\n\tfor (const submission of startupInput.submissions) {\n\t\tif (commandReplayStarted) {\n\t\t\tstartupReplayInputs.push(submission);\n\t\t} else if (isCommandLikeStartupInput(submission)) {\n\t\t\tconst commandText = submission.trim();\n\t\t\tcommandReplayStarted = true;\n\t\t\teditor.setText(commandText);\n\t\t\tsetStartupReplayActiveInput?.(commandText);\n\t\t} else {\n\t\t\tpendingUserInputs.push({ text: submission, draft: submission });\n\t\t}\n\t}\n\tif (startupInput.text.length === 0) return;\n\tif (commandReplayStarted) {\n\t\tsetStartupDraftText?.(startupInput.text);\n\t} else {\n\t\teditor.setText(startupInput.text);\n\t}\n}\n\nexport interface InteractiveTuiInputSubscription {\n\thandler: TuiInputListener;\n\tunsubscribe: () => void;\n}\n\ninterface WorkingStatusEditor extends EditorComponent {\n\treadonly embedWorkingStatus: boolean;\n\tsetWorkingStatusIndicator(indicator: AtomicWorkingLoader | undefined): void;\n}\n\nfunction isWorkingStatusEditor(editor: EditorComponent): editor is WorkingStatusEditor {\n\treturn (\n\t\t\"embedWorkingStatus\" in editor &&\n\t\teditor.embedWorkingStatus === true &&\n\t\t\"setWorkingStatusIndicator\" in editor &&\n\t\ttypeof editor.setWorkingStatusIndicator === \"function\"\n\t);\n}\n\nexport class InteractiveModeBase {\n\truntimeHost: AgentSessionRuntime;\n\n\tui: TUI;\n\tprivate renderer: InteractiveTui;\n\treadonly programStatus = new ProgramStatusReporter(\n\t\t() => this.ui.terminal,\n\t\t() => this.sessionManager.getSessionName(),\n\t);\n\n\tresetTranscriptSelection(): void {\n\t\tif (this.renderer.mode === \"fullscreen\") this.renderer.resetTextSelection();\n\t}\n\n\tprivate readonly shouldHandleViewportInput = (\n\t\tdata: string,\n\t\tisMouseInput: boolean,\n\t\tfocusedIsOverlay: boolean,\n\t\tfocusedIsViewportSearch: boolean,\n\t): boolean => {\n\t\treturn shouldHandleFullscreenViewportInput(\n\t\t\tthis.renderer.getFocusedComponent(),\n\t\t\tthis.editor,\n\t\t\tdata,\n\t\t\tisMouseInput,\n\t\t\tfocusedIsOverlay,\n\t\t\tthis.keybindings,\n\t\t\tfocusedIsViewportSearch,\n\t\t);\n\t};\n\tprivate readonly onOverlayUnhandledInput = (data: string): boolean => this.handleOverlayUnhandledInput(data);\n\tprivate readonly onOverlayInternalUiAction = (url: string): InternalUiActionResult =>\n\t\thandleFocusedOverlayInternalUiAction(this.renderer, url);\n\n\t/** Dispatch the host thinking action after a focused workflow overlay declines input. */\n\thandleOverlayUnhandledInput(data: string): boolean {\n\t\tif (isKeyRelease(data) || !this.keybindings.matches(data, \"app.thinking.toggle\")) return false;\n\t\t// Reuse the default editor's action dispatcher even while a workflow\n\t\t// overlay owns focus. This keeps the host binding and its user remap as\n\t\t// the source of truth instead of calling the implementation directly.\n\t\treturn this.defaultEditor.handleInput(data);\n\t}\n\n\tsetFullscreenCopyOnSelect(enabled: boolean): void {\n\t\tif (this.renderer.mode === \"fullscreen\") this.renderer.setCopyOnSelect(enabled);\n\t}\n\n\tsetFullscreenWheelScrollLines(lines: WheelScrollLines): void {\n\t\tif (this.renderer.mode === \"fullscreen\") this.renderer.setWheelScrollLines(lines);\n\t}\n\n\tprivate readonly onRightClickPaste = (): void => {\n\t\tvoid this.handleRightClickPaste();\n\t};\n\n\tchatContainer: Container;\n\tdocumentContainer: Container;\n\n\ttranscriptScrollView: ScrollView | undefined;\n\n\tfullscreenLayoutRoot: Component | undefined;\n\n\tresourceDisclosureContainer: Container;\n\tstartupNoticesContainer: Container;\n\tpendingMessagesContainer: Container;\n\n\tstatusContainer: Container;\n\n\tdefaultEditor: CustomEditor;\n\n\teditor: EditorComponent;\n\n\teditorComponentFactory: EditorFactory | undefined;\n\n\tautocompleteProvider: AutocompleteProvider | undefined;\n\n\tautocompleteProviderWrappers: AutocompleteProviderFactory[] = [];\n\n\tfdPath: string | undefined;\n\n\teditorContainer: Container;\n\n\tactiveSelectorToken: object | undefined;\n\n\tactiveSelectorDispose: (() => void) | undefined;\n\n\tfooter: FooterComponent;\n\tfooterContainer: Container;\n\n\tusageMeter: UsageMeterComponent;\n\n\tfooterDataProvider: FooterDataProvider;\n\n\t// Stored so the same manager can be injected into custom editors, selectors, and extension UI.\n\tkeybindings: KeybindingsManager;\n\n\treloadCoordinator: KeybindingsReloadCoordinator;\n\n\tinteractiveEngineShortcutHandler: ((data: string) => boolean) | undefined;\n\n\tdisposeInteractiveEngineHost: () => void = () => {};\n\tdisposeMarkitDiagnosticSink: () => void = () => {};\n\n\tversion: string;\n\n\tisInitialized = false;\n\n\tonInputCallback?: (submission: InteractiveSubmission) => void;\n\n\tpendingUserInputs: InteractiveSubmission[] = [];\n\n\tstartupReplayInputs: string[] = [];\n\n\tstartupReplayActiveInput: string | undefined = undefined;\n\n\tstartupDraftText: string | undefined = undefined;\n\tworkingIndicatorEmbedded = false;\n\n\tdeferredRenderedUserInputs: string[] = [];\n\n\tdeferredRenderedUserInputComponents = new Map<string, Component[][]>();\n\n\tloadingAnimation: Loader | AtomicWorkingLoader | undefined = undefined;\n\n\tworkingMessage: string | undefined = undefined;\n\n\tworkingVisible = true;\n\n\tworkingIndicatorOptions: LoaderIndicatorOptions | undefined = undefined;\n\n\treadonly defaultWorkingMessage = \"Working\";\n\n\treadonly defaultHiddenThinkingLabel = \"Thinking...\";\n\n\thiddenThinkingLabel = this.defaultHiddenThinkingLabel;\n\n\tlastSigintTime = 0;\n\n\tlastEscapeTime = 0;\n\n\tchangelogMarkdown: string | undefined = undefined;\n\n\tstartupNoticesShown = false;\n\t/** Last model-catalog warning already shown, so the deferred re-read only speaks on a change. */\n\treportedModelCatalogWarning: string | undefined;\n\tstartupNoticesPrepared = false;\n\n\tanthropicSubscriptionWarningShown = false;\n\n\tfirstRunNoticeVisible = false;\n\n\thadLastChangelogVersionAtStartup = false;\n\n\tfirstRunOnboardingNoticeComponents: Component[] = [];\n\n\tautoTrustOnReloadCwd: string | undefined;\n\n\t// Status line tracking (for mutating immediately-sequential status updates)\n\tlastStatusSpacer: Spacer | undefined = undefined;\n\n\tlastStatusText: Text | undefined = undefined;\n\n\t/** Leading spacer added once for the managed-tool startup status block. */\n\tmanagedToolStatusStarted = false;\n\t/** Invalidates readiness callbacks after the transcript is rebuilt for another session. */\n\tmanagedToolStatusGeneration = 0;\n\n\t// Streaming message tracking\n\tstreamingComponent: AssistantMessageComponent | undefined = undefined;\n\n\tstreamingMessage: AssistantMessage | undefined = undefined;\n\n\t// Tool execution tracking: toolCallId -> component\n\tpendingTools = new Map<string, ToolExecutionComponent | RemoteToolExecutionComponent>();\n\n\t// Tool output expansion state\n\ttoolOutputExpanded = false;\n\n\t// Thinking block visibility state\n\thideThinkingBlock = false;\n\toutputPad: 0 | 1 = 1;\n\n\tmermaidMarkdownTransformer: MarkdownTransformer = createMermaidMarkdownTransformer({\n\t\tgetMode: () => this.settingsManager.getMermaidRenderingMode(),\n\t\ttheme,\n\t});\n\tmermaidMarkdownTransformerMode: MermaidRenderingMode | undefined;\n\n\t// Skill commands: command name -> skill file path\n\tskillCommands = new Map<string, string>();\n\n\t// Agent subscription unsubscribe function\n\tunsubscribe?: () => void;\n\n\tsignalCleanupHandlers: Array<() => void> = [];\n\n\t// Track if editor is in bash mode (text starts with !)\n\tisBashMode = false;\n\n\t// Track current bash execution component\n\tbashComponent: BashExecutionComponent | undefined = undefined;\n\n\t// Track pending bash components (shown in pending area, moved to chat on submit)\n\tpendingBashComponents: BashExecutionComponent[] = [];\n\n\t// Auto-compaction state\n\tautoCompactionLoader: AtomicWorkingLoader | undefined = undefined;\n\n\tautoCompactionEscapeHandler?: () => void;\n\n\t/** True once the pre-compaction Escape handler has been captured for restore. */\n\tautoCompactionEscapeHandlerSaved = false;\n\n\t/** True while `runUserPromptTurn()` owns the working loader. */\n\tpromptTurnWorkingLoaderActive = false;\n\n\t// Auto-retry state\n\tretryLoader: AtomicWorkingLoader | undefined = undefined;\n\tfallbackLoader: Loader | undefined = undefined;\n\n\tretryCountdown: CountdownTimer | undefined = undefined;\n\n\tretryEscapeHandler?: () => void;\n\n\t// Messages queued while compaction is running\n\tcompactionQueuedMessages: CompactionQueuedMessage[] = [];\n\n\t/** Keeps input queued while automatic compaction hands off to a manual request. */\n\tmanualCompactionTakeoverPending = false;\n\n\t// Deferred extension load state (first paint happens before extensions load)\n\tdeferredStartupPending = false;\n\tinitialStartupBinding = false;\n\tdeferredStartupPromise: Promise<void> | undefined = undefined;\n\tstartupTrustReleased = false;\n\n\tinputHandlerReadyRecorded = false;\n\n\tfirstSubmitRecorded = false;\n\n\t// Shutdown state\n\tshutdownRequested = false;\n\n\t// Extension UI state\n\textensionSelector: ExtensionSelectorComponent | undefined = undefined;\n\n\textensionInput: ExtensionInputComponent | undefined = undefined;\n\n\textensionEditor: ExtensionEditorComponent | undefined = undefined;\n\n\ttuiInputSubscriptions = new Set<InteractiveTuiInputSubscription>();\n\n\textensionTerminalInputSubscriptions = new Set<InteractiveTuiInputSubscription>();\n\n\ttuiRendererChangeListeners = new Set<() => void>();\n\n\tblockingInlineCustomUiDepth = 0;\n\n\tnavigationInlineCustomUiDepth = 0;\n\n\tdeferredInlineCustomUiFocusDepth = 0;\n\n\tpendingInlineCustomUiFocus: Component | undefined = undefined;\n\n\t/** Pending inline mounts in display order, oldest first. */\n\tinlineCustomUiStack: { component: Component }[] = [];\n\n\thostCustomUiStateListeners = new Set<HostCustomUiStateListener>();\n\n\twidgetReleaseListeners = new Map<string, Set<() => void>>();\n\n\ttranscriptOverlayReserve: TranscriptOverlayReserve | undefined = undefined;\n\n\tthemeController: InteractiveThemeController;\n\n\t// Extension widgets (components rendered above/below the editor)\n\textensionWidgetsAbove = new Map<string, Component & { dispose?(): void }>();\n\n\textensionWidgetsBelow = new Map<string, Component & { dispose?(): void }>();\n\n\twidgetContainerAbove!: Container;\n\n\twidgetContainerBelow!: Container;\n\n\t// Custom footer from extension (undefined = use built-in footer)\n\tcustomFooter: (Component & { dispose?(): void }) | undefined = undefined;\n\n\t// Header container that holds the built-in or custom header\n\theaderContainer: Container;\n\n\t// Built-in header (logo + keybinding hints + changelog)\n\tbuiltInHeader: Component | undefined = undefined;\n\n\t// Custom header from extension (undefined = use built-in header)\n\tcustomHeader: (Component & { dispose?(): void }) | undefined = undefined;\n\n\t// Convenience accessors\n\tget session(): AgentSession & AgentSessionQueuePauseControl {\n\t\treturn this.runtimeHost.session as AgentSession & AgentSessionQueuePauseControl;\n\t}\n\n\t/** Includes the short handoff window that an isolated engine cannot mirror. */\n\tget compactionActive(): boolean {\n\t\treturn this.session.isCompacting || this.manualCompactionTakeoverPending;\n\t}\n\n\tget agent() {\n\t\treturn this.session.agent;\n\t}\n\n\tget sessionManager() {\n\t\treturn this.session.sessionManager;\n\t}\n\n\tget settingsManager() {\n\t\treturn this.session.settingsManager;\n\t}\n\n\t/**\n\t * Tears down the selector that owns `editorContainer`, including in-flight\n\t * work such as a model catalog refresh.\n\t *\n\t * This lives on the base class so behavior modules can dispose a selector\n\t * without relying on `interactive-selectors.ts` load order.\n\t */\n\tdisposeActiveSelector(): void {\n\t\tconst dispose = this.activeSelectorDispose;\n\t\tthis.activeSelectorToken = undefined;\n\t\tthis.activeSelectorDispose = undefined;\n\t\tdispose?.();\n\t}\n\n\taddTuiInputListener(handler: TuiInputListener): () => void {\n\t\tconst subscription: InteractiveTuiInputSubscription = {\n\t\t\thandler,\n\t\t\tunsubscribe: this.ui.addInputListener(handler),\n\t\t};\n\t\tthis.tuiInputSubscriptions.add(subscription);\n\t\treturn () => {\n\t\t\tsubscription.unsubscribe();\n\t\t\tthis.tuiInputSubscriptions.delete(subscription);\n\t\t};\n\t}\n\n\trebindTuiInputListeners(): void {\n\t\tfor (const subscription of this.tuiInputSubscriptions) {\n\t\t\tsubscription.unsubscribe();\n\t\t\tsubscription.unsubscribe = this.ui.addInputListener(subscription.handler);\n\t\t}\n\t}\n\n\tonTuiRendererChange(listener: () => void): () => void {\n\t\tthis.tuiRendererChangeListeners.add(listener);\n\t\treturn () => this.tuiRendererChangeListeners.delete(listener);\n\t}\n\n\tmountInteractiveTui(tui: TUI, components: readonly Component[]): void {\n\t\tfor (const component of components) tui.addChild(component);\n\t\tif (isViewportTUI(tui)) {\n\t\t\tif (!this.fullscreenLayoutRoot) throw new Error(\"Fullscreen layout is not initialized\");\n\t\t\ttui.setLayoutRoot(this.fullscreenLayoutRoot);\n\t\t}\n\t}\n\n\tprivate async handleRightClickPaste(): Promise<void> {\n\t\tconst target = this.renderer.getFocusedComponent();\n\t\tconst handleInput = target?.handleInput;\n\t\tif (!target || !handleInput) return;\n\t\ttry {\n\t\t\tconst text = await readClipboardText();\n\t\t\tif (!text || this.renderer.getFocusedComponent() !== target) return;\n\t\t\thandleInput.call(target, `\\x1b[200~${text}\\x1b[201~`);\n\t\t\tthis.ui.requestRender();\n\t\t} catch {\n\t\t\t// Clipboard paste is best-effort; permission and native-module failures are common.\n\t\t}\n\t}\n\n\tstopInteractiveTui(fullscreenExitOutput: FullscreenExitOutput): void {\n\t\tconst isFullscreen = this.renderer.mode === \"fullscreen\";\n\t\tif (isFullscreen && fullscreenExitOutput === \"transcript\") {\n\t\t\t// Atomic has no regular renderer to switch into, so pi-tui's own\n\t\t\t// exit paint is the only painter: its stop renders the layout root\n\t\t\t// at natural height onto the main screen. The docked fullscreen\n\t\t\t// layout squeezes its scroll view to `basis` (one row) at natural\n\t\t\t// height, so hand it the document container directly — the exit\n\t\t\t// paint then carries the whole transcript. Drop overlays first so\n\t\t\t// what gets painted is the transcript, not the focused dialog.\n\t\t\twhile (this.renderer.hasOverlayEntries) this.renderer.hideOverlay();\n\t\t\tif (isViewportTUI(this.renderer)) this.renderer.setLayoutRoot(this.documentContainer);\n\t\t}\n\t\t// `resume-hint` keeps whatever the alternate screen held: the prior\n\t\t// shell contents reappear and shutdown prints only the resume line.\n\t\tthis.ui.stop({ preserveScreen: isFullscreen && fullscreenExitOutput === \"resume-hint\" });\n\t\tthis.disposeMarkitDiagnosticSink();\n\t}\n\n\tdeclare options: InteractiveModeOptions;\n\n\tsetEditorWorkingStatusIndicator(indicator: AtomicWorkingLoader | undefined): boolean {\n\t\tthis.defaultEditor.setWorkingStatusIndicator(undefined);\n\t\tif (!isWorkingStatusEditor(this.editor)) return false;\n\t\tthis.editor.setWorkingStatusIndicator(indicator);\n\t\treturn true;\n\t}\n\n\tconstructor(runtimeHost: AgentSessionRuntime, options: InteractiveModeOptions = {}) {\n\t\tthis.runtimeHost = runtimeHost;\n\t\tthis.options = options;\n\t\tthis.deferredStartupPending = Boolean(options.deferredExtensionLoad);\n\t\tthis.autoTrustOnReloadCwd = options.autoTrustOnReloadCwd;\n\t\tthis.runtimeHost.setBeforeSessionInvalidate(() => {\n\t\t\tthis.resetExtensionUI();\n\t\t});\n\t\tthis.runtimeHost.setRebindSession(async () => {\n\t\t\tawait this.rebindCurrentSession();\n\t\t\t// A rebound session can carry a different settings manager; re-apply\n\t\t\t// the theme so the live selection tracks the session that is current.\n\t\t\tawait this.themeController.applyFromSettings();\n\t\t});\n\t\tsetCapabilityOverrides(this.settingsManager.getTerminalCapabilityOverrides());\n\t\tthis.version = VERSION;\n\t\tthis.renderer = createInteractiveTui({\n\t\t\tshowHardwareCursor: this.settingsManager.getShowHardwareCursor(),\n\t\t\tlogDirectory: runtimeHost.services.agentDir,\n\t\t\tterminal: options.terminal,\n\t\t\tcopyOnSelect: this.settingsManager.getFullscreenCopyOnSelect(),\n\t\t\twheelScrollLines: this.settingsManager.getFullscreenWheelScrollLines(),\n\t\t\tonRightClickPaste: this.onRightClickPaste,\n\t\t\tshouldHandleViewportInput: this.shouldHandleViewportInput,\n\t\t\tonOverlayUnhandledInput: this.onOverlayUnhandledInput,\n\t\t\tonOverlayInternalUiAction: this.onOverlayInternalUiAction,\n\t\t\tonOverlayRender: () => this.programStatus.resend(),\n\t\t\tonInternalUiAction: () => {\n\t\t\t\tthis.jumpToTranscriptEnd();\n\t\t\t\treturn undefined;\n\t\t\t},\n\t\t});\n\t\tthis.ui = createInteractiveTuiReference(() => this.renderer);\n\t\tthis.ui.setClearOnShrink(this.settingsManager.getClearOnShrink());\n\t\tthis.headerContainer = new Container();\n\t\tthis.documentContainer = new Container();\n\t\tthis.documentContainer.addChild(this.headerContainer);\n\t\tthis.chatContainer = new StartupChatContainer();\n\t\tthis.documentContainer.addChild(this.chatContainer);\n\t\tthis.resourceDisclosureContainer = new Container();\n\t\tthis.startupNoticesContainer = new Container();\n\t\t// The isolated engine can emit session_start UI requests as soon as its\n\t\t// bridge attaches below, before init() mounts chat in the TUI. Reserve the\n\t\t// ordering slots now so those messages can never precede RESOURCES.\n\t\tthis.chatContainer.addChild(this.resourceDisclosureContainer);\n\t\tthis.chatContainer.addChild(this.startupNoticesContainer);\n\t\tthis.pendingMessagesContainer = new Container();\n\t\tthis.statusContainer = new Container();\n\t\tthis.widgetContainerAbove = new WidgetContainer();\n\t\tthis.widgetContainerBelow = new WidgetContainer();\n\t\tthis.keybindings = KeybindingsManager.create(runtimeHost.services.agentDir);\n\t\tthis.reloadCoordinator = new KeybindingsReloadCoordinator(this.keybindings);\n\t\tsetKeybindings(this.keybindings);\n\t\tconst editorPaddingX = this.settingsManager.getEditorPaddingX();\n\t\tconst autocompleteMaxVisible = this.settingsManager.getAutocompleteMaxVisible();\n\t\tthis.defaultEditor = new CustomEditor(this.ui, getEditorTheme(), this.keybindings, {\n\t\t\tpaddingX: editorPaddingX,\n\t\t\tautocompleteMaxVisible,\n\t\t});\n\n\t\tthis.editor = this.defaultEditor;\n\t\tthis.editorContainer = new Container();\n\t\tthis.editorContainer.addChild(this.editor as Component);\n\t\tthis.footerDataProvider = new FooterDataProvider(this.sessionManager.getCwd());\n\t\tthis.footer = new FooterComponent(\n\t\t\tthis.session,\n\t\t\tthis.footerDataProvider,\n\t\t\tundefined,\n\t\t\t() => this.navigationInlineCustomUiDepth > 0,\n\t\t);\n\t\tthis.footerContainer = new Container();\n\t\tthis.footerContainer.addChild(this.footer);\n\t\tthis.usageMeter = new UsageMeterComponent(this.session);\n\t\tthis.usageMeter.setAutoCompactEnabled(this.session.autoCompactionEnabled);\n\n\t\t// Load hide thinking block setting\n\t\tthis.hideThinkingBlock = this.settingsManager.getHideThinkingBlock();\n\t\tthis.outputPad = this.settingsManager.getOutputPad();\n\n\t\t// Register themes from resource loader and initialize\n\t\tsetRegisteredThemes(this.session.resourceLoader.getThemes().themes);\n\t\tthis.themeController = new InteractiveThemeController(this.ui, {\n\t\t\tgetSettingsManager: () => this.settingsManager,\n\t\t\tshowError: (message) => this.showError(message),\n\t\t\tonChanged: () => this.updateEditorBorderColor(),\n\t\t\tinitialThemeSetting: options.initialThemeSetting,\n\t\t});\n\t\tthis.disposeInteractiveEngineHost = attachInteractiveEngineHost(\n\t\t\truntimeHost,\n\t\t\tthis.createExtensionUIContext(),\n\t\t\t(diagnostic) =>\n\t\t\t\trenderEngineDiagnostic(diagnostic, {\n\t\t\t\t\tstopWorkingLoader: () => this.stopWorkingLoader(),\n\t\t\t\t\tshowStatus: (message, persist) => this.showStatus(message, persist),\n\t\t\t\t\tshowError: (message) => this.showError(message),\n\t\t\t\t}),\n\t\t\t{\n\t\t\t\tisFullscreen: () => this.renderer.mode === \"fullscreen\",\n\t\t\t\tonRendererReplaced: (listener) => this.onTuiRendererChange(listener),\n\t\t\t},\n\t\t\t(handler) => {\n\t\t\t\tthis.interactiveEngineShortcutHandler = handler;\n\t\t\t\tthis.defaultEditor.onExtensionShortcut = handler;\n\t\t\t\treturn () => {\n\t\t\t\t\tif (this.interactiveEngineShortcutHandler === handler) this.interactiveEngineShortcutHandler = undefined;\n\t\t\t\t\tif (this.defaultEditor.onExtensionShortcut === handler)\n\t\t\t\t\t\tthis.defaultEditor.onExtensionShortcut = undefined;\n\t\t\t\t};\n\t\t\t},\n\t\t\tthis.keybindings,\n\t\t\t(frame) => this.programStatus.handleWorkflowActivity(frame),\n\t\t\t(event) => this.programStatus.handleUIPrompt(event),\n\t\t);\n\t}\n\n\t// Maximum total widget lines to prevent viewport overflow\n\tstatic readonly MAX_WIDGET_LINES = 10;\n\n\t/**\n\t * Gracefully shutdown the agent.\n\t * Stops the TUI before emitting shutdown events so extension UI cleanup cannot\n\t * repaint the final frame while the process is exiting.\n\t */\n\tisShuttingDown = false;\n\tinstallChangeWarningShown = false;\n}\n"]}
1
+ {"version":3,"file":"interactive-mode-base.js","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-mode-base.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACN,YAAY,EACZ,aAAa,EAEb,sBAAsB,GAGtB,MAAM,wBAAwB,CAAC;AAKhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAE3F,OAAO,EAAE,4BAA4B,EAAE,MAAM,kCAAkC,CAAC;AAEhF,OAAO,EAAE,gCAAgC,EAAE,MAAM,yBAAyB,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EASN,SAAS,EAET,YAAY,EAMZ,eAAe,EACf,kBAAkB,EAClB,cAAc,EAEd,0BAA0B,EAC1B,kBAAkB,EAIlB,cAAc,EACd,mBAAmB,EAInB,KAAK,EACL,mBAAmB,EACnB,OAAO,GACP,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAE/E,OAAO,EACN,oBAAoB,EACpB,6BAA6B,EAC7B,oCAAoC,GAGpC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,kFAAkF;AAClF,MAAM,oCAAoC,GAAG;IAC5C,sBAAsB;IACtB,wBAAwB;IACxB,0BAA0B;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mode.\n * Responsibility-specific behavior is installed by sibling modules.\n */\nimport {\n\tisKeyRelease,\n\tisViewportTUI,\n\ttype ScrollView,\n\tsetCapabilityOverrides,\n\ttype TuiInputListener,\n\ttype WheelScrollLines,\n} from \"@earendil-works/pi-tui\";\nimport type { AgentSessionQueuePauseControl } from \"../../core/agent-session-methods.ts\";\nimport type { MarkdownTransformer } from \"../../core/extensions/types.ts\";\nimport type { FullscreenExitOutput, MermaidRenderingMode } from \"../../core/settings-manager.ts\";\nimport type { EarlyInputSnapshot } from \"../../main-early-input.ts\";\nimport { readClipboardText } from \"../../utils/clipboard.js\";\nimport { renderEngineDiagnostic } from \"../interactive-engine/engine-diagnostic-view.js\";\nimport { attachInteractiveEngineHost } from \"../interactive-engine/extension-ui-bridge.ts\";\nimport type { RemoteToolExecutionComponent } from \"../interactive-engine/remote-renderer.ts\";\nimport { KeybindingsReloadCoordinator } from \"../rpc/rpc-keybindings-reload.ts\";\nimport type { AtomicWorkingLoader } from \"./components/atomic-working-status.ts\";\nimport { createMermaidMarkdownTransformer } from \"./components/mermaid.ts\";\nimport type { TranscriptOverlayReserve } from \"./components/reserved-bottom-overlay.ts\";\nimport { WidgetContainer } from \"./components/scroll-widget.js\";\nimport {\n\ttype AgentSession,\n\ttype AgentSessionRuntime,\n\ttype AssistantMessage,\n\ttype AssistantMessageComponent,\n\ttype AutocompleteProvider,\n\ttype AutocompleteProviderFactory,\n\ttype BashExecutionComponent,\n\ttype Component,\n\tContainer,\n\ttype CountdownTimer,\n\tCustomEditor,\n\ttype EditorComponent,\n\ttype EditorFactory,\n\ttype ExtensionEditorComponent,\n\ttype ExtensionInputComponent,\n\ttype ExtensionSelectorComponent,\n\tFooterComponent,\n\tFooterDataProvider,\n\tgetEditorTheme,\n\ttype HostCustomUiStateListener,\n\tInteractiveThemeController,\n\tKeybindingsManager,\n\ttype Loader,\n\ttype LoaderIndicatorOptions,\n\ttype Spacer,\n\tsetKeybindings,\n\tsetRegisteredThemes,\n\ttype Text,\n\ttype ToolExecutionComponent,\n\ttype TUI,\n\ttheme,\n\tUsageMeterComponent,\n\tVERSION,\n} from \"./interactive-mode-deps.ts\";\nimport type {} from \"./interactive-mode-surface.ts\";\nimport type { CompactionQueuedMessage, InteractiveModeOptions } from \"./interactive-mode-types.ts\";\nimport { StartupChatContainer } from \"./interactive-startup-chat-container.ts\";\nimport type { InteractiveSubmission } from \"./interactive-submission.ts\";\nimport {\n\tcreateInteractiveTui,\n\tcreateInteractiveTuiReference,\n\thandleFocusedOverlayInternalUiAction,\n\ttype InteractiveTui,\n\ttype InternalUiActionResult,\n} from \"./interactive-tui.ts\";\nimport { ProgramStatusReporter } from \"./program-status-reporter.ts\";\n\n/** Move the transcript and nothing else: what a reserving overlay may release. */\nconst FULLSCREEN_TRANSCRIPT_SCROLL_ACTIONS = [\n\t\"tui.altScreen.pageUp\",\n\t\"tui.altScreen.pageDown\",\n\t\"tui.altScreen.halfPageUp\",\n\t\"tui.altScreen.halfPageDown\",\n\t\"tui.altScreen.lineUp\",\n\t\"tui.altScreen.lineDown\",\n\t\"tui.altScreen.previousPrompt\",\n\t\"tui.altScreen.nextPrompt\",\n\t\"tui.altScreen.top\",\n\t\"tui.altScreen.bottom\",\n] as const;\n\nconst FULLSCREEN_VIEWPORT_ACTIONS = FULLSCREEN_TRANSCRIPT_SCROLL_ACTIONS;\n\nexport function isFullscreenViewportAction(data: string, keybindings: KeybindingsManager): boolean {\n\treturn FULLSCREEN_VIEWPORT_ACTIONS.some((action) => keybindings.matches(data, action));\n}\n\n/**\n * Whether a key scrolls the transcript. A reserving overlay — the\n * `ask_user_question` dialog, an extension component with\n * `reserveTranscriptRows` — declines these so the strip above it still pages\n * and jumps (#2378), and keeps everything else.\n */\nexport function isFullscreenTranscriptScrollAction(data: string, keybindings: KeybindingsManager): boolean {\n\treturn FULLSCREEN_TRANSCRIPT_SCROLL_ACTIONS.some((action) => keybindings.matches(data, action));\n}\n\n/**\n * Decide whether the fullscreen viewport should run before the focused\n * component. `isMouseInput` is classified by pi-tui's own mouse predicate in\n * `AtomicTuiAltScreen`, so this policy does not duplicate terminal grammars.\n * Mouse deferral is limited to actual overlays so inline components do not\n * disable pi-tui's application-owned transcript selection path.\n *\n * **Who owns viewport keys while an overlay is focused.** pi-tui 0.84.2 added\n * `shouldDeferViewportInputToOverlay()` (upstream #7894) and answers \"the\n * overlay\". Atomic answers \"the overlay first, the transcript with whatever it\n * declines\" (#2378 / PR #2381): the actions in `FULLSCREEN_VIEWPORT_ACTIONS`\n * and wheel reports are offered to the focused overlay, and\n * `AtomicTuiAltScreen` replays what it does not consume into pi-tui's viewport\n * listener. Atomic's answer stands, because a mounted dialog that keeps its\n * selection keys must not also freeze the transcript behind it.\n *\n * **The list covers every `tui.altScreen.*` scroll action pi-tui defines.**\n * An action a focused overlay declines still reaches the transcript, so the\n * shortcut is never simply lost.\n *\n * **A focused overlay with no `handleInput` is still an overlay.** The handler\n * is optional — `ExtensionCustomComponent` marks it `handleInput?` and\n * `docs/tui.md` documents it as optional — and a component that cannot answer\n * declines by definition. Answering \"the viewport owns it\" for that shape\n * would hand the key to pi-tui, whose native deferral then drops it because an\n * overlay holds focus, so the transcript would freeze behind a component that\n * never asked for the key. A handler-less overlay therefore takes the same\n * route as one that returns `false`: nothing to offer, then replay. Only a\n * focused component that is *not* an overlay keeps the shortcut, because\n * pi-tui defers nothing to it.\n */\nexport function shouldHandleFullscreenViewportInput(\n\tfocused: Component | null,\n\teditor: Component,\n\tdata: string,\n\tisMouseInput: boolean,\n\tfocusedIsOverlay: boolean,\n\tkeybindings: KeybindingsManager,\n\t_focusedIsViewportSearch = false,\n): boolean {\n\tif (focused === editor || !focused) return true;\n\tif (!focused.handleInput && !focusedIsOverlay) return true;\n\tif (isMouseInput) return !focusedIsOverlay;\n\tif (focusedIsOverlay && keybindings.matches(data, \"app.thinking.toggle\")) return false;\n\treturn !isFullscreenViewportAction(data, keybindings);\n}\n\nfunction isCommandLikeStartupInput(text: string): boolean {\n\tconst trimmed = text.trimStart();\n\treturn trimmed.startsWith(\"/\") || trimmed.startsWith(\"!\");\n}\n\nexport function seedStartupInput(\n\tpendingUserInputs: InteractiveSubmission[],\n\teditor: { setText(text: string): void },\n\tstartupInput: EarlyInputSnapshot | undefined,\n\tstartupReplayInputs: string[] = [],\n\tsetStartupDraftText?: (text: string) => void,\n\tsetStartupReplayActiveInput?: (text: string) => void,\n): void {\n\tif (!startupInput) return;\n\tlet commandReplayStarted = false;\n\tfor (const submission of startupInput.submissions) {\n\t\tif (commandReplayStarted) {\n\t\t\tstartupReplayInputs.push(submission);\n\t\t} else if (isCommandLikeStartupInput(submission)) {\n\t\t\tconst commandText = submission.trim();\n\t\t\tcommandReplayStarted = true;\n\t\t\teditor.setText(commandText);\n\t\t\tsetStartupReplayActiveInput?.(commandText);\n\t\t} else {\n\t\t\tpendingUserInputs.push({ text: submission, draft: submission });\n\t\t}\n\t}\n\tif (startupInput.text.length === 0) return;\n\tif (commandReplayStarted) {\n\t\tsetStartupDraftText?.(startupInput.text);\n\t} else {\n\t\teditor.setText(startupInput.text);\n\t}\n}\n\nexport interface InteractiveTuiInputSubscription {\n\thandler: TuiInputListener;\n\tunsubscribe: () => void;\n}\n\ninterface WorkingStatusEditor extends EditorComponent {\n\treadonly embedWorkingStatus: boolean;\n\tsetWorkingStatusIndicator(indicator: AtomicWorkingLoader | undefined): void;\n}\n\nfunction isWorkingStatusEditor(editor: EditorComponent): editor is WorkingStatusEditor {\n\treturn (\n\t\t\"embedWorkingStatus\" in editor &&\n\t\teditor.embedWorkingStatus === true &&\n\t\t\"setWorkingStatusIndicator\" in editor &&\n\t\ttypeof editor.setWorkingStatusIndicator === \"function\"\n\t);\n}\n\nexport class InteractiveModeBase {\n\truntimeHost: AgentSessionRuntime;\n\n\tui: TUI;\n\tprivate renderer: InteractiveTui;\n\treadonly programStatus = new ProgramStatusReporter(\n\t\t() => this.ui.terminal,\n\t\t() => this.sessionManager.getSessionName(),\n\t);\n\n\tresetTranscriptSelection(): void {\n\t\tif (this.renderer.mode === \"fullscreen\") this.renderer.resetTextSelection();\n\t}\n\n\tprivate readonly shouldHandleViewportInput = (\n\t\tdata: string,\n\t\tisMouseInput: boolean,\n\t\tfocusedIsOverlay: boolean,\n\t\tfocusedIsViewportSearch: boolean,\n\t): boolean => {\n\t\treturn shouldHandleFullscreenViewportInput(\n\t\t\tthis.renderer.getFocusedComponent(),\n\t\t\tthis.editor,\n\t\t\tdata,\n\t\t\tisMouseInput,\n\t\t\tfocusedIsOverlay,\n\t\t\tthis.keybindings,\n\t\t\tfocusedIsViewportSearch,\n\t\t);\n\t};\n\tprivate readonly onOverlayUnhandledInput = (data: string): boolean => this.handleOverlayUnhandledInput(data);\n\tprivate readonly onOverlayInternalUiAction = (url: string): InternalUiActionResult =>\n\t\thandleFocusedOverlayInternalUiAction(this.renderer, url);\n\n\t/** Dispatch the host thinking action after a focused workflow overlay declines input. */\n\thandleOverlayUnhandledInput(data: string): boolean {\n\t\tif (isKeyRelease(data) || !this.keybindings.matches(data, \"app.thinking.toggle\")) return false;\n\t\t// Reuse the default editor's action dispatcher even while a workflow\n\t\t// overlay owns focus. This keeps the host binding and its user remap as\n\t\t// the source of truth instead of calling the implementation directly.\n\t\treturn this.defaultEditor.handleInput(data);\n\t}\n\n\tsetFullscreenCopyOnSelect(enabled: boolean): void {\n\t\tif (this.renderer.mode === \"fullscreen\") this.renderer.setCopyOnSelect(enabled);\n\t}\n\n\tsetFullscreenWheelScrollLines(lines: WheelScrollLines): void {\n\t\tif (this.renderer.mode === \"fullscreen\") this.renderer.setWheelScrollLines(lines);\n\t}\n\n\tprivate readonly onRightClickPaste = (): void => {\n\t\tvoid this.handleRightClickPaste();\n\t};\n\n\tchatContainer: Container;\n\tdocumentContainer: Container;\n\n\ttranscriptScrollView: ScrollView | undefined;\n\n\tfullscreenLayoutRoot: Component | undefined;\n\n\tresourceDisclosureContainer: Container;\n\tstartupNoticesContainer: Container;\n\tpendingMessagesContainer: Container;\n\n\tstatusContainer: Container;\n\n\tdefaultEditor: CustomEditor;\n\n\teditor: EditorComponent;\n\n\teditorComponentFactory: EditorFactory | undefined;\n\n\tautocompleteProvider: AutocompleteProvider | undefined;\n\n\tautocompleteProviderWrappers: AutocompleteProviderFactory[] = [];\n\n\tfdPath: string | undefined;\n\n\teditorContainer: Container;\n\n\tactiveSelectorToken: object | undefined;\n\n\tactiveSelectorDispose: (() => void) | undefined;\n\n\tfooter: FooterComponent;\n\tfooterContainer: Container;\n\n\tusageMeter: UsageMeterComponent;\n\n\tfooterDataProvider: FooterDataProvider;\n\n\t// Stored so the same manager can be injected into custom editors, selectors, and extension UI.\n\tkeybindings: KeybindingsManager;\n\n\treloadCoordinator: KeybindingsReloadCoordinator;\n\n\tinteractiveEngineShortcutHandler: ((data: string) => boolean) | undefined;\n\n\tdisposeInteractiveEngineHost: () => void = () => {};\n\tdisposeMarkitDiagnosticSink: () => void = () => {};\n\n\tversion: string;\n\n\tisInitialized = false;\n\n\tonInputCallback?: (submission: InteractiveSubmission) => void;\n\n\tpendingUserInputs: InteractiveSubmission[] = [];\n\n\tstartupReplayInputs: string[] = [];\n\n\tstartupReplayActiveInput: string | undefined = undefined;\n\n\tstartupDraftText: string | undefined = undefined;\n\tworkingIndicatorEmbedded = false;\n\n\tdeferredRenderedUserInputs: string[] = [];\n\n\tdeferredRenderedUserInputComponents = new Map<string, Component[][]>();\n\n\tloadingAnimation: Loader | AtomicWorkingLoader | undefined = undefined;\n\n\tworkingMessage: string | undefined = undefined;\n\n\tworkingVisible = true;\n\n\tworkingIndicatorOptions: LoaderIndicatorOptions | undefined = undefined;\n\n\treadonly defaultWorkingMessage = \"Working\";\n\n\treadonly defaultHiddenThinkingLabel = \"Thinking...\";\n\n\thiddenThinkingLabel = this.defaultHiddenThinkingLabel;\n\n\tlastSigintTime = 0;\n\n\tlastEscapeTime = 0;\n\n\tchangelogMarkdown: string | undefined = undefined;\n\n\tstartupNoticesShown = false;\n\t/** Last model-catalog warning already shown, so the deferred re-read only speaks on a change. */\n\treportedModelCatalogWarning: string | undefined;\n\tstartupNoticesPrepared = false;\n\n\tanthropicSubscriptionWarningShown = false;\n\n\tfirstRunNoticeVisible = false;\n\n\thadLastChangelogVersionAtStartup = false;\n\n\tfirstRunOnboardingNoticeComponents: Component[] = [];\n\n\tautoTrustOnReloadCwd: string | undefined;\n\n\t// Status line tracking (for mutating immediately-sequential status updates)\n\tlastStatusSpacer: Spacer | undefined = undefined;\n\n\tlastStatusText: Text | undefined = undefined;\n\n\t/** Leading spacer added once for the managed-tool startup status block. */\n\tmanagedToolStatusStarted = false;\n\t/** Invalidates readiness callbacks after the transcript is rebuilt for another session. */\n\tmanagedToolStatusGeneration = 0;\n\n\t// Streaming message tracking\n\tstreamingComponent: AssistantMessageComponent | undefined = undefined;\n\n\tstreamingMessage: AssistantMessage | undefined = undefined;\n\n\t// Tool execution tracking: toolCallId -> component\n\tpendingTools = new Map<string, ToolExecutionComponent | RemoteToolExecutionComponent>();\n\n\t// Tool output expansion state\n\ttoolOutputExpanded = false;\n\n\t// Thinking block visibility state\n\thideThinkingBlock = false;\n\toutputPad: 0 | 1 = 1;\n\n\tmermaidMarkdownTransformer: MarkdownTransformer = createMermaidMarkdownTransformer({\n\t\tgetMode: () => this.settingsManager.getMermaidRenderingMode(),\n\t\ttheme,\n\t});\n\tmermaidMarkdownTransformerMode: MermaidRenderingMode | undefined;\n\n\t// Skill commands: command name -> skill file path\n\tskillCommands = new Map<string, string>();\n\n\t// Agent subscription unsubscribe function\n\tunsubscribe?: () => void;\n\n\tsignalCleanupHandlers: Array<() => void> = [];\n\n\t// Track if editor is in bash mode (text starts with !)\n\tisBashMode = false;\n\n\t// Track current bash execution component\n\tbashComponent: BashExecutionComponent | undefined = undefined;\n\n\t// Track pending bash components (shown in pending area, moved to chat on submit)\n\tpendingBashComponents: BashExecutionComponent[] = [];\n\n\t// Auto-compaction state\n\tautoCompactionLoader: AtomicWorkingLoader | undefined = undefined;\n\n\tautoCompactionEscapeHandler?: () => void;\n\n\t/** True once the pre-compaction Escape handler has been captured for restore. */\n\tautoCompactionEscapeHandlerSaved = false;\n\n\t/** True while `runUserPromptTurn()` owns the working loader. */\n\tpromptTurnWorkingLoaderActive = false;\n\n\t// Auto-retry state\n\tretryLoader: AtomicWorkingLoader | undefined = undefined;\n\tfallbackLoader: Loader | undefined = undefined;\n\n\tretryCountdown: CountdownTimer | undefined = undefined;\n\n\tretryEscapeHandler?: () => void;\n\n\t// Messages queued while compaction is running\n\tcompactionQueuedMessages: CompactionQueuedMessage[] = [];\n\n\t/** True while queued compaction messages are being sent one at a time. */\n\tcompactionFlushPending = false;\n\n\t/** A queued message failed to send and waits at the front of the queue; later input queues behind it. */\n\tcompactionSendFailed = false;\n\n\t/** Keeps input queued while automatic compaction hands off to a manual request. */\n\tmanualCompactionTakeoverPending = false;\n\n\t// Deferred extension load state (first paint happens before extensions load)\n\tdeferredStartupPending = false;\n\tinitialStartupBinding = false;\n\tdeferredStartupPromise: Promise<void> | undefined = undefined;\n\tstartupTrustReleased = false;\n\n\tinputHandlerReadyRecorded = false;\n\n\tfirstSubmitRecorded = false;\n\n\t// Shutdown state\n\tshutdownRequested = false;\n\n\t// Extension UI state\n\textensionSelector: ExtensionSelectorComponent | undefined = undefined;\n\n\textensionInput: ExtensionInputComponent | undefined = undefined;\n\n\textensionEditor: ExtensionEditorComponent | undefined = undefined;\n\n\ttuiInputSubscriptions = new Set<InteractiveTuiInputSubscription>();\n\n\textensionTerminalInputSubscriptions = new Set<InteractiveTuiInputSubscription>();\n\n\ttuiRendererChangeListeners = new Set<() => void>();\n\n\tblockingInlineCustomUiDepth = 0;\n\n\tnavigationInlineCustomUiDepth = 0;\n\n\tdeferredInlineCustomUiFocusDepth = 0;\n\n\tpendingInlineCustomUiFocus: Component | undefined = undefined;\n\n\t/** Pending inline mounts in display order, oldest first. */\n\tinlineCustomUiStack: { component: Component }[] = [];\n\n\thostCustomUiStateListeners = new Set<HostCustomUiStateListener>();\n\n\twidgetReleaseListeners = new Map<string, Set<() => void>>();\n\n\ttranscriptOverlayReserve: TranscriptOverlayReserve | undefined = undefined;\n\n\tthemeController: InteractiveThemeController;\n\n\t// Extension widgets (components rendered above/below the editor)\n\textensionWidgetsAbove = new Map<string, Component & { dispose?(): void }>();\n\n\textensionWidgetsBelow = new Map<string, Component & { dispose?(): void }>();\n\n\twidgetContainerAbove!: Container;\n\n\twidgetContainerBelow!: Container;\n\n\t// Custom footer from extension (undefined = use built-in footer)\n\tcustomFooter: (Component & { dispose?(): void }) | undefined = undefined;\n\n\t// Header container that holds the built-in or custom header\n\theaderContainer: Container;\n\n\t// Built-in header (logo + keybinding hints + changelog)\n\tbuiltInHeader: Component | undefined = undefined;\n\n\t// Custom header from extension (undefined = use built-in header)\n\tcustomHeader: (Component & { dispose?(): void }) | undefined = undefined;\n\n\t// Convenience accessors\n\tget session(): AgentSession & AgentSessionQueuePauseControl {\n\t\treturn this.runtimeHost.session as AgentSession & AgentSessionQueuePauseControl;\n\t}\n\n\t/** Includes the short handoff window that an isolated engine cannot mirror. */\n\tget compactionActive(): boolean {\n\t\treturn this.session.isCompacting || this.manualCompactionTakeoverPending;\n\t}\n\n\tget agent() {\n\t\treturn this.session.agent;\n\t}\n\n\tget sessionManager() {\n\t\treturn this.session.sessionManager;\n\t}\n\n\tget settingsManager() {\n\t\treturn this.session.settingsManager;\n\t}\n\n\t/**\n\t * Tears down the selector that owns `editorContainer`, including in-flight\n\t * work such as a model catalog refresh.\n\t *\n\t * This lives on the base class so behavior modules can dispose a selector\n\t * without relying on `interactive-selectors.ts` load order.\n\t */\n\tdisposeActiveSelector(): void {\n\t\tconst dispose = this.activeSelectorDispose;\n\t\tthis.activeSelectorToken = undefined;\n\t\tthis.activeSelectorDispose = undefined;\n\t\tdispose?.();\n\t}\n\n\taddTuiInputListener(handler: TuiInputListener): () => void {\n\t\tconst subscription: InteractiveTuiInputSubscription = {\n\t\t\thandler,\n\t\t\tunsubscribe: this.ui.addInputListener(handler),\n\t\t};\n\t\tthis.tuiInputSubscriptions.add(subscription);\n\t\treturn () => {\n\t\t\tsubscription.unsubscribe();\n\t\t\tthis.tuiInputSubscriptions.delete(subscription);\n\t\t};\n\t}\n\n\trebindTuiInputListeners(): void {\n\t\tfor (const subscription of this.tuiInputSubscriptions) {\n\t\t\tsubscription.unsubscribe();\n\t\t\tsubscription.unsubscribe = this.ui.addInputListener(subscription.handler);\n\t\t}\n\t}\n\n\tonTuiRendererChange(listener: () => void): () => void {\n\t\tthis.tuiRendererChangeListeners.add(listener);\n\t\treturn () => this.tuiRendererChangeListeners.delete(listener);\n\t}\n\n\tmountInteractiveTui(tui: TUI, components: readonly Component[]): void {\n\t\tfor (const component of components) tui.addChild(component);\n\t\tif (isViewportTUI(tui)) {\n\t\t\tif (!this.fullscreenLayoutRoot) throw new Error(\"Fullscreen layout is not initialized\");\n\t\t\ttui.setLayoutRoot(this.fullscreenLayoutRoot);\n\t\t}\n\t}\n\n\tprivate async handleRightClickPaste(): Promise<void> {\n\t\tconst target = this.renderer.getFocusedComponent();\n\t\tconst handleInput = target?.handleInput;\n\t\tif (!target || !handleInput) return;\n\t\ttry {\n\t\t\tconst text = await readClipboardText();\n\t\t\tif (!text || this.renderer.getFocusedComponent() !== target) return;\n\t\t\thandleInput.call(target, `\\x1b[200~${text}\\x1b[201~`);\n\t\t\tthis.ui.requestRender();\n\t\t} catch {\n\t\t\t// Clipboard paste is best-effort; permission and native-module failures are common.\n\t\t}\n\t}\n\n\tstopInteractiveTui(fullscreenExitOutput: FullscreenExitOutput): void {\n\t\tconst isFullscreen = this.renderer.mode === \"fullscreen\";\n\t\tif (isFullscreen && fullscreenExitOutput === \"transcript\") {\n\t\t\t// Atomic has no regular renderer to switch into, so pi-tui's own\n\t\t\t// exit paint is the only painter: its stop renders the layout root\n\t\t\t// at natural height onto the main screen. The docked fullscreen\n\t\t\t// layout squeezes its scroll view to `basis` (one row) at natural\n\t\t\t// height, so hand it the document container directly — the exit\n\t\t\t// paint then carries the whole transcript. Drop overlays first so\n\t\t\t// what gets painted is the transcript, not the focused dialog.\n\t\t\twhile (this.renderer.hasOverlayEntries) this.renderer.hideOverlay();\n\t\t\tif (isViewportTUI(this.renderer)) this.renderer.setLayoutRoot(this.documentContainer);\n\t\t}\n\t\t// `resume-hint` keeps whatever the alternate screen held: the prior\n\t\t// shell contents reappear and shutdown prints only the resume line.\n\t\tthis.ui.stop({ preserveScreen: isFullscreen && fullscreenExitOutput === \"resume-hint\" });\n\t\tthis.disposeMarkitDiagnosticSink();\n\t}\n\n\tdeclare options: InteractiveModeOptions;\n\n\tsetEditorWorkingStatusIndicator(indicator: AtomicWorkingLoader | undefined): boolean {\n\t\tthis.defaultEditor.setWorkingStatusIndicator(undefined);\n\t\tif (!isWorkingStatusEditor(this.editor)) return false;\n\t\tthis.editor.setWorkingStatusIndicator(indicator);\n\t\treturn true;\n\t}\n\n\tconstructor(runtimeHost: AgentSessionRuntime, options: InteractiveModeOptions = {}) {\n\t\tthis.runtimeHost = runtimeHost;\n\t\tthis.options = options;\n\t\tthis.deferredStartupPending = Boolean(options.deferredExtensionLoad);\n\t\tthis.autoTrustOnReloadCwd = options.autoTrustOnReloadCwd;\n\t\tthis.runtimeHost.setBeforeSessionInvalidate(() => {\n\t\t\tthis.resetExtensionUI();\n\t\t});\n\t\tthis.runtimeHost.setRebindSession(async () => {\n\t\t\tawait this.rebindCurrentSession();\n\t\t\t// A rebound session can carry a different settings manager; re-apply\n\t\t\t// the theme so the live selection tracks the session that is current.\n\t\t\tawait this.themeController.applyFromSettings();\n\t\t});\n\t\tsetCapabilityOverrides(this.settingsManager.getTerminalCapabilityOverrides());\n\t\tthis.version = VERSION;\n\t\tthis.renderer = createInteractiveTui({\n\t\t\tshowHardwareCursor: this.settingsManager.getShowHardwareCursor(),\n\t\t\tlogDirectory: runtimeHost.services.agentDir,\n\t\t\tterminal: options.terminal,\n\t\t\tcopyOnSelect: this.settingsManager.getFullscreenCopyOnSelect(),\n\t\t\twheelScrollLines: this.settingsManager.getFullscreenWheelScrollLines(),\n\t\t\tonRightClickPaste: this.onRightClickPaste,\n\t\t\tshouldHandleViewportInput: this.shouldHandleViewportInput,\n\t\t\tonOverlayUnhandledInput: this.onOverlayUnhandledInput,\n\t\t\tonOverlayInternalUiAction: this.onOverlayInternalUiAction,\n\t\t\tonOverlayRender: () => this.programStatus.resend(),\n\t\t\tonInternalUiAction: () => {\n\t\t\t\tthis.jumpToTranscriptEnd();\n\t\t\t\treturn undefined;\n\t\t\t},\n\t\t});\n\t\tthis.ui = createInteractiveTuiReference(() => this.renderer);\n\t\tthis.ui.setClearOnShrink(this.settingsManager.getClearOnShrink());\n\t\tthis.headerContainer = new Container();\n\t\tthis.documentContainer = new Container();\n\t\tthis.documentContainer.addChild(this.headerContainer);\n\t\tthis.chatContainer = new StartupChatContainer();\n\t\tthis.documentContainer.addChild(this.chatContainer);\n\t\tthis.resourceDisclosureContainer = new Container();\n\t\tthis.startupNoticesContainer = new Container();\n\t\t// The isolated engine can emit session_start UI requests as soon as its\n\t\t// bridge attaches below, before init() mounts chat in the TUI. Reserve the\n\t\t// ordering slots now so those messages can never precede RESOURCES.\n\t\tthis.chatContainer.addChild(this.resourceDisclosureContainer);\n\t\tthis.chatContainer.addChild(this.startupNoticesContainer);\n\t\tthis.pendingMessagesContainer = new Container();\n\t\tthis.statusContainer = new Container();\n\t\tthis.widgetContainerAbove = new WidgetContainer();\n\t\tthis.widgetContainerBelow = new WidgetContainer();\n\t\tthis.keybindings = KeybindingsManager.create(runtimeHost.services.agentDir);\n\t\tthis.reloadCoordinator = new KeybindingsReloadCoordinator(this.keybindings);\n\t\tsetKeybindings(this.keybindings);\n\t\tconst editorPaddingX = this.settingsManager.getEditorPaddingX();\n\t\tconst autocompleteMaxVisible = this.settingsManager.getAutocompleteMaxVisible();\n\t\tthis.defaultEditor = new CustomEditor(this.ui, getEditorTheme(), this.keybindings, {\n\t\t\tpaddingX: editorPaddingX,\n\t\t\tautocompleteMaxVisible,\n\t\t});\n\n\t\tthis.editor = this.defaultEditor;\n\t\tthis.editorContainer = new Container();\n\t\tthis.editorContainer.addChild(this.editor as Component);\n\t\tthis.footerDataProvider = new FooterDataProvider(this.sessionManager.getCwd());\n\t\tthis.footer = new FooterComponent(\n\t\t\tthis.session,\n\t\t\tthis.footerDataProvider,\n\t\t\tundefined,\n\t\t\t() => this.navigationInlineCustomUiDepth > 0,\n\t\t);\n\t\tthis.footerContainer = new Container();\n\t\tthis.footerContainer.addChild(this.footer);\n\t\tthis.usageMeter = new UsageMeterComponent(this.session);\n\t\tthis.usageMeter.setAutoCompactEnabled(this.session.autoCompactionEnabled);\n\n\t\t// Load hide thinking block setting\n\t\tthis.hideThinkingBlock = this.settingsManager.getHideThinkingBlock();\n\t\tthis.outputPad = this.settingsManager.getOutputPad();\n\n\t\t// Register themes from resource loader and initialize\n\t\tsetRegisteredThemes(this.session.resourceLoader.getThemes().themes);\n\t\tthis.themeController = new InteractiveThemeController(this.ui, {\n\t\t\tgetSettingsManager: () => this.settingsManager,\n\t\t\tshowError: (message) => this.showError(message),\n\t\t\tonChanged: () => this.updateEditorBorderColor(),\n\t\t\tinitialThemeSetting: options.initialThemeSetting,\n\t\t});\n\t\tthis.disposeInteractiveEngineHost = attachInteractiveEngineHost(\n\t\t\truntimeHost,\n\t\t\tthis.createExtensionUIContext(),\n\t\t\t(diagnostic) =>\n\t\t\t\trenderEngineDiagnostic(diagnostic, {\n\t\t\t\t\tstopWorkingLoader: () => this.stopWorkingLoader(),\n\t\t\t\t\tshowStatus: (message, persist) => this.showStatus(message, persist),\n\t\t\t\t\tshowError: (message) => this.showError(message),\n\t\t\t\t}),\n\t\t\t{\n\t\t\t\tisFullscreen: () => this.renderer.mode === \"fullscreen\",\n\t\t\t\tonRendererReplaced: (listener) => this.onTuiRendererChange(listener),\n\t\t\t},\n\t\t\t(handler) => {\n\t\t\t\tthis.interactiveEngineShortcutHandler = handler;\n\t\t\t\tthis.defaultEditor.onExtensionShortcut = handler;\n\t\t\t\treturn () => {\n\t\t\t\t\tif (this.interactiveEngineShortcutHandler === handler) this.interactiveEngineShortcutHandler = undefined;\n\t\t\t\t\tif (this.defaultEditor.onExtensionShortcut === handler)\n\t\t\t\t\t\tthis.defaultEditor.onExtensionShortcut = undefined;\n\t\t\t\t};\n\t\t\t},\n\t\t\tthis.keybindings,\n\t\t\t(frame) => this.programStatus.handleWorkflowActivity(frame),\n\t\t\t(event) => this.programStatus.handleUIPrompt(event),\n\t\t);\n\t}\n\n\t// Maximum total widget lines to prevent viewport overflow\n\tstatic readonly MAX_WIDGET_LINES = 10;\n\n\t/**\n\t * Gracefully shutdown the agent.\n\t * Stops the TUI before emitting shutdown events so extension UI cleanup cannot\n\t * repaint the final frame while the process is exiting.\n\t */\n\tisShuttingDown = false;\n\tinstallChangeWarningShown = false;\n}\n"]}
@@ -230,8 +230,9 @@ InteractiveModeBase.prototype.handleFollowUp = async function () {
230
230
  throw error;
231
231
  }
232
232
  };
233
- // Queue input during compaction (extension commands execute immediately)
234
- if (this.compactionActive) {
233
+ // Queue input behind compaction-queued messages (extension commands execute immediately)
234
+ if (this.compactionActive ||
235
+ (!this.session.queuedMessagesPaused && (this.compactionFlushPending || this.compactionSendFailed))) {
235
236
  if (this.isExtensionCommand(text)) {
236
237
  this.editor.addToHistory?.(text);
237
238
  this.editor.setText("");
@@ -242,6 +243,11 @@ InteractiveModeBase.prototype.handleFollowUp = async function () {
242
243
  }
243
244
  return;
244
245
  }
246
+ // A paused submission releases the session queue before its own turn, so move held
247
+ // messages there first to keep them ahead of this one.
248
+ if (this.session.queuedMessagesPaused && this.compactionSendFailed && !this.compactionFlushPending) {
249
+ await this.flushCompactionQueue({ willRetry: false });
250
+ }
245
251
  // Alt+Enter queues a follow-up message (waits until agent finishes)
246
252
  // This handles extension commands (execute immediately), prompt template expansion, and queueing
247
253
  if (this.session.isStreaming) {
@@ -1 +1 @@
1
- {"version":3,"file":"interactive-process-lifecycle.js","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-process-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0EAA0E;IAC1E,2EAA2E;IAC3E,4EAA4E;IAC5E,2EAA2E;IAC3E,0EAA0E;SACrE,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;AACF,CAAC,CAAC;AAEF,mBAAmB,CAAC,SAAS,CAAC,aAAa,GAAG;IAC7C,MAAM,QAAQ,GAAG,IAAI,CAAC,6BAA6B,EAAE,CAAC;IACtD,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACpB,IAAI,CAAC,UAAU,CAAC,+BAA+B,CAAC,CAAC;IAClD,CAAC;AACF,CAAC,CAAC","sourcesContent":["import { findExtensionStackMatches } from \"../../core/crash-log.ts\";\nimport { terminateInteractiveEngine } from \"../interactive-engine/extension-ui-bridge.ts\";\nimport { InteractiveModeBase } from \"./interactive-mode-base.ts\";\nimport { APP_TITLE, chalk, killTrackedDetachedChildren } from \"./interactive-mode-deps.ts\";\nimport { formatCrashExtensionHint, formatResumeCommand, isDeadTerminalError } from \"./interactive-mode-helpers.ts\";\nimport { pauseAndAbortInteractiveSession } from \"./interactive-pause.ts\";\nimport { restoreFailedSubmissionDraft } from \"./interactive-prompt-restore.ts\";\nimport { isWindowsSubshellActive, openWindowsSubshell } from \"./interactive-windows-subshell.ts\";\n\nconst SHUTDOWN_INPUT_DRAIN_MAX_MS = 250;\nconst SHUTDOWN_INPUT_DRAIN_IDLE_MS = 50;\n\nInteractiveModeBase.prototype.handleCtrlC = function (this: InteractiveModeBase): void {\n\tif (isWindowsSubshellActive(this)) return;\n\t// When the agent is doing work, Ctrl+C interrupts it (matching Escape and\n\t// common CLI muscle memory) instead of clearing/exiting the editor. Only\n\t// fall back to the clear / double-press-exit behavior when idle.\n\tif (this.interruptActiveOperation()) {\n\t\t// Reset the double-press window so a follow-up Ctrl+C after the abort\n\t\t// does not immediately exit.\n\t\tthis.lastSigintTime = 0;\n\t\treturn;\n\t}\n\tconst now = Date.now();\n\tif (now - this.lastSigintTime < 500) {\n\t\tvoid this.shutdown();\n\t} else {\n\t\tthis.clearEditor();\n\t\tthis.lastSigintTime = now;\n\t}\n};\n\nInteractiveModeBase.prototype.interruptActiveOperation = function (this: InteractiveModeBase): boolean {\n\t// Mirror the Escape interrupt paths so Ctrl+C aborts whichever operation is\n\t// currently running. Returns true when something was aborted.\n\t//\n\t// Escalate first when the interactive engine owes a cooperative abort or the\n\t// heartbeat watchdog calls it unresponsive: that is the explicit termination\n\t// the watchdog advertises with \"Esc interrupt · Ctrl+C terminate\". Every\n\t// cooperative route below would otherwise queue another request for a child\n\t// that cannot answer.\n\tif (terminateInteractiveEngine(this.runtimeHost)) {\n\t\treturn true;\n\t}\n\tif (this.session.isStreaming || this.session.agent.hasQueuedMessages()) {\n\t\tpauseAndAbortInteractiveSession(this);\n\t\treturn true;\n\t}\n\tif (this.session.isBashRunning) {\n\t\tthis.session.abortBash();\n\t\treturn true;\n\t}\n\tif (this.session.isCompacting) {\n\t\tthis.session.abortCompaction();\n\t\treturn true;\n\t}\n\tif (this.session.isRetrying) {\n\t\tthis.session.abortRetry();\n\t\treturn true;\n\t}\n\treturn false;\n};\n\nInteractiveModeBase.prototype.handleCtrlD = function (this: InteractiveModeBase): void {\n\t// Only called when editor is empty (enforced by CustomEditor)\n\tvoid this.shutdown();\n};\n\nInteractiveModeBase.prototype.shutdown = async function (\n\tthis: InteractiveModeBase,\n\toptions?: { fromSignal?: boolean },\n): Promise<void> {\n\tif (this.isShuttingDown) return;\n\tthis.isShuttingDown = true;\n\t// Keep signal handlers registered until terminal cleanup has completed.\n\t// `signal-exit` checks the listener list during the same SIGTERM/SIGHUP\n\t// dispatch and re-sends the signal if only its own listeners remain.\n\n\tif (options?.fromSignal) {\n\t\tawait this.runtimeHost.dispose({ fromSignal: true });\n\t\tthis.themeController.disableAutoSync();\n\t\t// Drain any in-flight Kitty key release events briefly before stopping.\n\t\t// Keep this bounded so Ctrl+C exits do not feel stalled on Windows.\n\t\tawait this.ui.terminal.drainInput(SHUTDOWN_INPUT_DRAIN_MAX_MS, SHUTDOWN_INPUT_DRAIN_IDLE_MS);\n\t\tthis.stop();\n\t\tprocess.exit(0);\n\t}\n\n\t// Drain any in-flight Kitty key release events briefly before stopping.\n\t// Keep this bounded so Ctrl+C exits do not feel stalled on Windows.\n\tthis.themeController.disableAutoSync();\n\tawait this.ui.terminal.drainInput(SHUTDOWN_INPUT_DRAIN_MAX_MS, SHUTDOWN_INPUT_DRAIN_IDLE_MS);\n\n\tthis.stop();\n\tawait this.runtimeHost.dispose();\n\tconst resumeCommand = formatResumeCommand(this.sessionManager);\n\tif (resumeCommand) {\n\t\tprocess.stdout.write(`${chalk.dim(\"To resume this session:\")} ${resumeCommand}\\n`);\n\t}\n\tprocess.exit(0);\n};\n\nInteractiveModeBase.prototype.emergencyTerminalExit = function (this: InteractiveModeBase): never {\n\tthis.isShuttingDown = true;\n\tthis.unregisterSignalHandlers();\n\tkillTrackedDetachedChildren();\n\t// The terminal is gone. Do not run normal shutdown because TUI and\n\t// extension cleanup can write restore sequences and re-trigger EIO.\n\tprocess.exit(129);\n};\n\nInteractiveModeBase.prototype.uncaughtCrash = function (this: InteractiveModeBase, error: Error): never {\n\tif (isDeadTerminalError(error) && (error as NodeJS.ErrnoException).syscall === \"setRawMode\") {\n\t\tthis.emergencyTerminalExit();\n\t}\n\tif (this.isShuttingDown) {\n\t\tprocess.exit(1);\n\t}\n\tthis.isShuttingDown = true;\n\ttry {\n\t\tthis.unregisterSignalHandlers();\n\t} catch {}\n\ttry {\n\t\tkillTrackedDetachedChildren();\n\t} catch {}\n\ttry {\n\t\tthis.ui.stop();\n\t} catch {}\n\tconsole.error(`${APP_TITLE} exiting due to uncaughtException:`);\n\tconsole.error(error);\n\tconst extensionHint = this.getCrashExtensionHint(error);\n\tif (extensionHint) console.error(`\\n${extensionHint}`);\n\tprocess.exit(1);\n};\n\nInteractiveModeBase.prototype.getCrashExtensionHint = function (\n\tthis: InteractiveModeBase,\n\terror: unknown,\n): string | undefined {\n\ttry {\n\t\treturn formatCrashExtensionHint(\n\t\t\tfindExtensionStackMatches(\n\t\t\t\terror instanceof Error ? error.stack : undefined,\n\t\t\t\tthis.session.resourceLoader.getExtensions().extensions,\n\t\t\t),\n\t\t);\n\t} catch {\n\t\treturn undefined;\n\t}\n};\n\nInteractiveModeBase.prototype.checkShutdownRequested = async function (this: InteractiveModeBase): Promise<void> {\n\tif (!this.shutdownRequested) return;\n\tawait this.shutdown();\n};\n\nInteractiveModeBase.prototype.registerSignalHandlers = function (this: InteractiveModeBase): void {\n\tthis.unregisterSignalHandlers();\n\n\tconst signals: NodeJS.Signals[] = [\"SIGTERM\"];\n\tif (process.platform !== \"win32\") {\n\t\tsignals.push(\"SIGHUP\");\n\t}\n\n\tfor (const signal of signals) {\n\t\tconst handler = () => {\n\t\t\tkillTrackedDetachedChildren();\n\t\t\tvoid this.shutdown({ fromSignal: true });\n\t\t};\n\t\tprocess.prependListener(signal, handler);\n\t\tthis.signalCleanupHandlers.push(() => process.off(signal, handler));\n\t}\n\n\tconst sigintHandler = () => {\n\t\tthis.handleCtrlC();\n\t};\n\tprocess.prependListener(\"SIGINT\", sigintHandler);\n\tthis.signalCleanupHandlers.push(() => process.off(\"SIGINT\", sigintHandler));\n\n\tconst terminalErrorHandler = (error: Error) => {\n\t\tif (isDeadTerminalError(error)) {\n\t\t\tthis.emergencyTerminalExit();\n\t\t}\n\t\tthrow error;\n\t};\n\tfor (const stream of [process.stdin, process.stdout, process.stderr]) {\n\t\tstream.on(\"error\", terminalErrorHandler);\n\t\tthis.signalCleanupHandlers.push(() => stream.off(\"error\", terminalErrorHandler));\n\t}\n\n\t// Restore the terminal before the process dies on any uncaught throw.\n\t// Without this, an unhandled exception from extension code (or anywhere\n\t// in pi) leaves the terminal in raw mode with no cursor.\n\tconst uncaughtExceptionHandler = (error: Error) => this.uncaughtCrash(error);\n\tprocess.prependListener(\"uncaughtException\", uncaughtExceptionHandler);\n\tthis.signalCleanupHandlers.push(() => process.off(\"uncaughtException\", uncaughtExceptionHandler));\n};\n\nInteractiveModeBase.prototype.unregisterSignalHandlers = function (this: InteractiveModeBase): void {\n\tfor (const cleanup of this.signalCleanupHandlers) {\n\t\tcleanup();\n\t}\n\tthis.signalCleanupHandlers = [];\n};\n\nInteractiveModeBase.prototype.handleCtrlZ = function (this: InteractiveModeBase): void {\n\tif (process.platform === \"win32\") {\n\t\tvoid openWindowsSubshell(this).catch((error: Error) =>\n\t\t\tthis.showStatus(`PowerShell subshell failed: ${error.message}`),\n\t\t);\n\t\treturn;\n\t}\n\n\t// Keep the event loop alive while suspended. Without this, stopping the TUI\n\t// can leave Node with no ref'ed handles, causing the process to exit on fg\n\t// before the SIGCONT handler gets a chance to restore the terminal.\n\tconst suspendKeepAlive = setInterval(() => {}, 2 ** 30);\n\n\t// Ignore SIGINT while suspended so Ctrl+C in the terminal does not\n\t// kill the backgrounded process. The handler is removed on resume.\n\tconst ignoreSigint = () => {};\n\tprocess.on(\"SIGINT\", ignoreSigint);\n\n\t// Set up handler to restore TUI when resumed\n\tprocess.once(\"SIGCONT\", () => {\n\t\tclearInterval(suspendKeepAlive);\n\t\tprocess.removeListener(\"SIGINT\", ignoreSigint);\n\t\tthis.ui.start();\n\t\tthis.ui.requestRender(true);\n\t});\n\n\ttry {\n\t\t// Stop the TUI (restore terminal to normal mode)\n\t\tthis.ui.stop();\n\n\t\t// Send SIGTSTP to process group (pid=0 means all processes in group)\n\t\tprocess.kill(0, \"SIGTSTP\");\n\t} catch (error) {\n\t\tclearInterval(suspendKeepAlive);\n\t\tprocess.removeListener(\"SIGINT\", ignoreSigint);\n\t\tthrow error;\n\t}\n};\n\nInteractiveModeBase.prototype.handleFollowUp = async function (this: InteractiveModeBase): Promise<void> {\n\tconst rawText = this.editor.getExpandedText?.() ?? this.editor.getText();\n\tconst text = rawText.trim();\n\tif (!text) return;\n\n\t// Alt+Enter dispatches straight to the engine, exactly like the direct\n\t// branches of the Enter handler, so it needs the same send-failure restore:\n\t// otherwise a queued follow-up submitted while the engine is gone is lost.\n\tconst dispatch = async (send: () => Promise<void>): Promise<void> => {\n\t\ttry {\n\t\t\tawait send();\n\t\t} catch (error) {\n\t\t\tif (!restoreFailedSubmissionDraft(this, error, rawText)) throw error;\n\t\t}\n\t};\n\n\t// Queue input during compaction (extension commands execute immediately)\n\tif (this.compactionActive) {\n\t\tif (this.isExtensionCommand(text)) {\n\t\t\tthis.editor.addToHistory?.(text);\n\t\t\tthis.editor.setText(\"\");\n\t\t\tawait dispatch(() => this.session.prompt(text));\n\t\t} else {\n\t\t\tthis.queueCompactionMessage(text, \"followUp\");\n\t\t}\n\t\treturn;\n\t}\n\n\t// Alt+Enter queues a follow-up message (waits until agent finishes)\n\t// This handles extension commands (execute immediately), prompt template expansion, and queueing\n\tif (this.session.isStreaming) {\n\t\tthis.editor.addToHistory?.(text);\n\t\tthis.editor.setText(\"\");\n\t\tawait dispatch(async () => {\n\t\t\tawait this.session.prompt(text, { streamingBehavior: \"followUp\" });\n\t\t\tthis.updatePendingMessagesDisplay();\n\t\t\tthis.ui.requestRender();\n\t\t});\n\t}\n\t// If not streaming, Alt+Enter acts like regular Enter (trigger onSubmit).\n\t// Hand over the raw expanded buffer, not the trimmed text: Alt+Enter is an\n\t// app action, so CustomEditor returns before its own pre-trim snapshot runs\n\t// and the submit handler's only draft is this argument. It trims the value\n\t// itself for delivery, so the agent still receives the normalized prompt.\n\telse if (this.editor.onSubmit) {\n\t\tthis.editor.setText(\"\");\n\t\tthis.editor.onSubmit(rawText);\n\t}\n};\n\nInteractiveModeBase.prototype.handleDequeue = function (this: InteractiveModeBase): void {\n\tconst restored = this.restoreQueuedMessagesToEditor();\n\tif (restored === 0) {\n\t\tthis.showStatus(\"No queued messages to restore\");\n\t}\n};\n"]}
1
+ {"version":3,"file":"interactive-process-lifecycle.js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I,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACxB,MAAM,QAAQ,CAAC,KAAK,IAAI,EAAE;YACzB,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,iBAAiB,EAAE,UAAU,EAAE,CAAC,CAAC;YACnE,IAAI,CAAC,4BAA4B,EAAE,CAAC;YACpC,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC;QACzB,CAAC,CAAC,CAAC;IACJ,CAAC;IACD,0EAA0E;IAC1E,2EAA2E;IAC3E,4EAA4E;IAC5E,2EAA2E;IAC3E,0EAA0E;SACrE,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;AACF,CAAC,CAAC;AAEF,mBAAmB,CAAC,SAAS,CAAC,aAAa,GAAG;IAC7C,MAAM,QAAQ,GAAG,IAAI,CAAC,6BAA6B,EAAE,CAAC;IACtD,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACpB,IAAI,CAAC,UAAU,CAAC,+BAA+B,CAAC,CAAC;IAClD,CAAC;AACF,CAAC,CAAC","sourcesContent":["import { findExtensionStackMatches } from \"../../core/crash-log.ts\";\nimport { terminateInteractiveEngine } from \"../interactive-engine/extension-ui-bridge.ts\";\nimport { InteractiveModeBase } from \"./interactive-mode-base.ts\";\nimport { APP_TITLE, chalk, killTrackedDetachedChildren } from \"./interactive-mode-deps.ts\";\nimport { formatCrashExtensionHint, formatResumeCommand, isDeadTerminalError } from \"./interactive-mode-helpers.ts\";\nimport { pauseAndAbortInteractiveSession } from \"./interactive-pause.ts\";\nimport { restoreFailedSubmissionDraft } from \"./interactive-prompt-restore.ts\";\nimport { isWindowsSubshellActive, openWindowsSubshell } from \"./interactive-windows-subshell.ts\";\n\nconst SHUTDOWN_INPUT_DRAIN_MAX_MS = 250;\nconst SHUTDOWN_INPUT_DRAIN_IDLE_MS = 50;\n\nInteractiveModeBase.prototype.handleCtrlC = function (this: InteractiveModeBase): void {\n\tif (isWindowsSubshellActive(this)) return;\n\t// When the agent is doing work, Ctrl+C interrupts it (matching Escape and\n\t// common CLI muscle memory) instead of clearing/exiting the editor. Only\n\t// fall back to the clear / double-press-exit behavior when idle.\n\tif (this.interruptActiveOperation()) {\n\t\t// Reset the double-press window so a follow-up Ctrl+C after the abort\n\t\t// does not immediately exit.\n\t\tthis.lastSigintTime = 0;\n\t\treturn;\n\t}\n\tconst now = Date.now();\n\tif (now - this.lastSigintTime < 500) {\n\t\tvoid this.shutdown();\n\t} else {\n\t\tthis.clearEditor();\n\t\tthis.lastSigintTime = now;\n\t}\n};\n\nInteractiveModeBase.prototype.interruptActiveOperation = function (this: InteractiveModeBase): boolean {\n\t// Mirror the Escape interrupt paths so Ctrl+C aborts whichever operation is\n\t// currently running. Returns true when something was aborted.\n\t//\n\t// Escalate first when the interactive engine owes a cooperative abort or the\n\t// heartbeat watchdog calls it unresponsive: that is the explicit termination\n\t// the watchdog advertises with \"Esc interrupt · Ctrl+C terminate\". Every\n\t// cooperative route below would otherwise queue another request for a child\n\t// that cannot answer.\n\tif (terminateInteractiveEngine(this.runtimeHost)) {\n\t\treturn true;\n\t}\n\tif (this.session.isStreaming || this.session.agent.hasQueuedMessages()) {\n\t\tpauseAndAbortInteractiveSession(this);\n\t\treturn true;\n\t}\n\tif (this.session.isBashRunning) {\n\t\tthis.session.abortBash();\n\t\treturn true;\n\t}\n\tif (this.session.isCompacting) {\n\t\tthis.session.abortCompaction();\n\t\treturn true;\n\t}\n\tif (this.session.isRetrying) {\n\t\tthis.session.abortRetry();\n\t\treturn true;\n\t}\n\treturn false;\n};\n\nInteractiveModeBase.prototype.handleCtrlD = function (this: InteractiveModeBase): void {\n\t// Only called when editor is empty (enforced by CustomEditor)\n\tvoid this.shutdown();\n};\n\nInteractiveModeBase.prototype.shutdown = async function (\n\tthis: InteractiveModeBase,\n\toptions?: { fromSignal?: boolean },\n): Promise<void> {\n\tif (this.isShuttingDown) return;\n\tthis.isShuttingDown = true;\n\t// Keep signal handlers registered until terminal cleanup has completed.\n\t// `signal-exit` checks the listener list during the same SIGTERM/SIGHUP\n\t// dispatch and re-sends the signal if only its own listeners remain.\n\n\tif (options?.fromSignal) {\n\t\tawait this.runtimeHost.dispose({ fromSignal: true });\n\t\tthis.themeController.disableAutoSync();\n\t\t// Drain any in-flight Kitty key release events briefly before stopping.\n\t\t// Keep this bounded so Ctrl+C exits do not feel stalled on Windows.\n\t\tawait this.ui.terminal.drainInput(SHUTDOWN_INPUT_DRAIN_MAX_MS, SHUTDOWN_INPUT_DRAIN_IDLE_MS);\n\t\tthis.stop();\n\t\tprocess.exit(0);\n\t}\n\n\t// Drain any in-flight Kitty key release events briefly before stopping.\n\t// Keep this bounded so Ctrl+C exits do not feel stalled on Windows.\n\tthis.themeController.disableAutoSync();\n\tawait this.ui.terminal.drainInput(SHUTDOWN_INPUT_DRAIN_MAX_MS, SHUTDOWN_INPUT_DRAIN_IDLE_MS);\n\n\tthis.stop();\n\tawait this.runtimeHost.dispose();\n\tconst resumeCommand = formatResumeCommand(this.sessionManager);\n\tif (resumeCommand) {\n\t\tprocess.stdout.write(`${chalk.dim(\"To resume this session:\")} ${resumeCommand}\\n`);\n\t}\n\tprocess.exit(0);\n};\n\nInteractiveModeBase.prototype.emergencyTerminalExit = function (this: InteractiveModeBase): never {\n\tthis.isShuttingDown = true;\n\tthis.unregisterSignalHandlers();\n\tkillTrackedDetachedChildren();\n\t// The terminal is gone. Do not run normal shutdown because TUI and\n\t// extension cleanup can write restore sequences and re-trigger EIO.\n\tprocess.exit(129);\n};\n\nInteractiveModeBase.prototype.uncaughtCrash = function (this: InteractiveModeBase, error: Error): never {\n\tif (isDeadTerminalError(error) && (error as NodeJS.ErrnoException).syscall === \"setRawMode\") {\n\t\tthis.emergencyTerminalExit();\n\t}\n\tif (this.isShuttingDown) {\n\t\tprocess.exit(1);\n\t}\n\tthis.isShuttingDown = true;\n\ttry {\n\t\tthis.unregisterSignalHandlers();\n\t} catch {}\n\ttry {\n\t\tkillTrackedDetachedChildren();\n\t} catch {}\n\ttry {\n\t\tthis.ui.stop();\n\t} catch {}\n\tconsole.error(`${APP_TITLE} exiting due to uncaughtException:`);\n\tconsole.error(error);\n\tconst extensionHint = this.getCrashExtensionHint(error);\n\tif (extensionHint) console.error(`\\n${extensionHint}`);\n\tprocess.exit(1);\n};\n\nInteractiveModeBase.prototype.getCrashExtensionHint = function (\n\tthis: InteractiveModeBase,\n\terror: unknown,\n): string | undefined {\n\ttry {\n\t\treturn formatCrashExtensionHint(\n\t\t\tfindExtensionStackMatches(\n\t\t\t\terror instanceof Error ? error.stack : undefined,\n\t\t\t\tthis.session.resourceLoader.getExtensions().extensions,\n\t\t\t),\n\t\t);\n\t} catch {\n\t\treturn undefined;\n\t}\n};\n\nInteractiveModeBase.prototype.checkShutdownRequested = async function (this: InteractiveModeBase): Promise<void> {\n\tif (!this.shutdownRequested) return;\n\tawait this.shutdown();\n};\n\nInteractiveModeBase.prototype.registerSignalHandlers = function (this: InteractiveModeBase): void {\n\tthis.unregisterSignalHandlers();\n\n\tconst signals: NodeJS.Signals[] = [\"SIGTERM\"];\n\tif (process.platform !== \"win32\") {\n\t\tsignals.push(\"SIGHUP\");\n\t}\n\n\tfor (const signal of signals) {\n\t\tconst handler = () => {\n\t\t\tkillTrackedDetachedChildren();\n\t\t\tvoid this.shutdown({ fromSignal: true });\n\t\t};\n\t\tprocess.prependListener(signal, handler);\n\t\tthis.signalCleanupHandlers.push(() => process.off(signal, handler));\n\t}\n\n\tconst sigintHandler = () => {\n\t\tthis.handleCtrlC();\n\t};\n\tprocess.prependListener(\"SIGINT\", sigintHandler);\n\tthis.signalCleanupHandlers.push(() => process.off(\"SIGINT\", sigintHandler));\n\n\tconst terminalErrorHandler = (error: Error) => {\n\t\tif (isDeadTerminalError(error)) {\n\t\t\tthis.emergencyTerminalExit();\n\t\t}\n\t\tthrow error;\n\t};\n\tfor (const stream of [process.stdin, process.stdout, process.stderr]) {\n\t\tstream.on(\"error\", terminalErrorHandler);\n\t\tthis.signalCleanupHandlers.push(() => stream.off(\"error\", terminalErrorHandler));\n\t}\n\n\t// Restore the terminal before the process dies on any uncaught throw.\n\t// Without this, an unhandled exception from extension code (or anywhere\n\t// in pi) leaves the terminal in raw mode with no cursor.\n\tconst uncaughtExceptionHandler = (error: Error) => this.uncaughtCrash(error);\n\tprocess.prependListener(\"uncaughtException\", uncaughtExceptionHandler);\n\tthis.signalCleanupHandlers.push(() => process.off(\"uncaughtException\", uncaughtExceptionHandler));\n};\n\nInteractiveModeBase.prototype.unregisterSignalHandlers = function (this: InteractiveModeBase): void {\n\tfor (const cleanup of this.signalCleanupHandlers) {\n\t\tcleanup();\n\t}\n\tthis.signalCleanupHandlers = [];\n};\n\nInteractiveModeBase.prototype.handleCtrlZ = function (this: InteractiveModeBase): void {\n\tif (process.platform === \"win32\") {\n\t\tvoid openWindowsSubshell(this).catch((error: Error) =>\n\t\t\tthis.showStatus(`PowerShell subshell failed: ${error.message}`),\n\t\t);\n\t\treturn;\n\t}\n\n\t// Keep the event loop alive while suspended. Without this, stopping the TUI\n\t// can leave Node with no ref'ed handles, causing the process to exit on fg\n\t// before the SIGCONT handler gets a chance to restore the terminal.\n\tconst suspendKeepAlive = setInterval(() => {}, 2 ** 30);\n\n\t// Ignore SIGINT while suspended so Ctrl+C in the terminal does not\n\t// kill the backgrounded process. The handler is removed on resume.\n\tconst ignoreSigint = () => {};\n\tprocess.on(\"SIGINT\", ignoreSigint);\n\n\t// Set up handler to restore TUI when resumed\n\tprocess.once(\"SIGCONT\", () => {\n\t\tclearInterval(suspendKeepAlive);\n\t\tprocess.removeListener(\"SIGINT\", ignoreSigint);\n\t\tthis.ui.start();\n\t\tthis.ui.requestRender(true);\n\t});\n\n\ttry {\n\t\t// Stop the TUI (restore terminal to normal mode)\n\t\tthis.ui.stop();\n\n\t\t// Send SIGTSTP to process group (pid=0 means all processes in group)\n\t\tprocess.kill(0, \"SIGTSTP\");\n\t} catch (error) {\n\t\tclearInterval(suspendKeepAlive);\n\t\tprocess.removeListener(\"SIGINT\", ignoreSigint);\n\t\tthrow error;\n\t}\n};\n\nInteractiveModeBase.prototype.handleFollowUp = async function (this: InteractiveModeBase): Promise<void> {\n\tconst rawText = this.editor.getExpandedText?.() ?? this.editor.getText();\n\tconst text = rawText.trim();\n\tif (!text) return;\n\n\t// Alt+Enter dispatches straight to the engine, exactly like the direct\n\t// branches of the Enter handler, so it needs the same send-failure restore:\n\t// otherwise a queued follow-up submitted while the engine is gone is lost.\n\tconst dispatch = async (send: () => Promise<void>): Promise<void> => {\n\t\ttry {\n\t\t\tawait send();\n\t\t} catch (error) {\n\t\t\tif (!restoreFailedSubmissionDraft(this, error, rawText)) throw error;\n\t\t}\n\t};\n\n\t// Queue input behind compaction-queued messages (extension commands execute immediately)\n\tif (\n\t\tthis.compactionActive ||\n\t\t(!this.session.queuedMessagesPaused && (this.compactionFlushPending || this.compactionSendFailed))\n\t) {\n\t\tif (this.isExtensionCommand(text)) {\n\t\t\tthis.editor.addToHistory?.(text);\n\t\t\tthis.editor.setText(\"\");\n\t\t\tawait dispatch(() => this.session.prompt(text));\n\t\t} else {\n\t\t\tthis.queueCompactionMessage(text, \"followUp\");\n\t\t}\n\t\treturn;\n\t}\n\n\t// A paused submission releases the session queue before its own turn, so move held\n\t// messages there first to keep them ahead of this one.\n\tif (this.session.queuedMessagesPaused && this.compactionSendFailed && !this.compactionFlushPending) {\n\t\tawait this.flushCompactionQueue({ willRetry: false });\n\t}\n\n\t// Alt+Enter queues a follow-up message (waits until agent finishes)\n\t// This handles extension commands (execute immediately), prompt template expansion, and queueing\n\tif (this.session.isStreaming) {\n\t\tthis.editor.addToHistory?.(text);\n\t\tthis.editor.setText(\"\");\n\t\tawait dispatch(async () => {\n\t\t\tawait this.session.prompt(text, { streamingBehavior: \"followUp\" });\n\t\t\tthis.updatePendingMessagesDisplay();\n\t\t\tthis.ui.requestRender();\n\t\t});\n\t}\n\t// If not streaming, Alt+Enter acts like regular Enter (trigger onSubmit).\n\t// Hand over the raw expanded buffer, not the trimmed text: Alt+Enter is an\n\t// app action, so CustomEditor returns before its own pre-trim snapshot runs\n\t// and the submit handler's only draft is this argument. It trims the value\n\t// itself for delivery, so the agent still receives the normalized prompt.\n\telse if (this.editor.onSubmit) {\n\t\tthis.editor.setText(\"\");\n\t\tthis.editor.onSubmit(rawText);\n\t}\n};\n\nInteractiveModeBase.prototype.handleDequeue = function (this: InteractiveModeBase): void {\n\tconst restored = this.restoreQueuedMessagesToEditor();\n\tif (restored === 0) {\n\t\tthis.showStatus(\"No queued messages to restore\");\n\t}\n};\n"]}
@@ -21,6 +21,7 @@ InteractiveModeBase.prototype.clearAllQueues = function (options) {
21
21
  .filter((msg) => msg.mode === "followUp")
22
22
  .map((msg) => msg.text);
23
23
  this.compactionQueuedMessages = [];
24
+ this.compactionSendFailed = false;
24
25
  return {
25
26
  steering: [...steering, ...compactionSteering],
26
27
  followUp: [...followUp, ...compactionFollowUp],
@@ -68,7 +69,12 @@ InteractiveModeBase.prototype.queueCompactionMessage = function (text, mode) {
68
69
  this.editor.addToHistory?.(text);
69
70
  this.editor.setText("");
70
71
  this.updatePendingMessagesDisplay();
71
- this.showStatus("Queued message for after compaction");
72
+ if (this.compactionActive) {
73
+ this.showStatus("Queued message for after compaction");
74
+ return;
75
+ }
76
+ if (!this.compactionFlushPending)
77
+ void this.flushCompactionQueue({ willRetry: false });
72
78
  };
73
79
  InteractiveModeBase.prototype.isExtensionCommand = function (text) {
74
80
  if (!text.startsWith("/"))
@@ -79,85 +85,100 @@ InteractiveModeBase.prototype.isExtensionCommand = function (text) {
79
85
  return !!extensionRunner.getCommand(commandName);
80
86
  };
81
87
  InteractiveModeBase.prototype.flushCompactionQueue = async function (options) {
82
- if (this.compactionQueuedMessages.length === 0) {
88
+ if (this.compactionFlushPending || this.compactionQueuedMessages.length === 0)
83
89
  return;
90
+ this.compactionFlushPending = true;
91
+ this.compactionSendFailed = false;
92
+ try {
93
+ await sendCompactionQueue(this, options?.willRetry === true);
84
94
  }
85
- const queuedMessages = [...this.compactionQueuedMessages];
86
- this.compactionQueuedMessages = [];
87
- this.updatePendingMessagesDisplay();
88
- const restoreQueue = (error, messages = queuedMessages) => {
89
- this.compactionQueuedMessages = [
90
- ...messages,
91
- ...this.compactionQueuedMessages.filter((message) => !messages.includes(message)),
92
- ];
95
+ finally {
96
+ this.compactionFlushPending = false;
93
97
  this.updatePendingMessagesDisplay();
94
- this.showError(`Failed to send queued message${messages.length > 1 ? "s" : ""}: ${error instanceof Error ? error.message : String(error)}`);
95
- };
96
- try {
97
- if (!options?.willRetry && (this.session.isStreaming || this.session.queuedMessagesPaused)) {
98
- await Promise.all(queuedMessages.map((message) => this.session.prompt(message.text, { streamingBehavior: message.mode })));
99
- this.updatePendingMessagesDisplay();
100
- return;
101
- }
102
- if (options?.willRetry) {
103
- // When retry is pending, queue messages for the retry turn
104
- for (const message of queuedMessages) {
105
- if (this.isExtensionCommand(message.text)) {
106
- await this.session.prompt(message.text);
107
- }
108
- else if (message.mode === "followUp") {
109
- await this.session.followUp(message.text);
110
- }
111
- else {
112
- await this.session.steer(message.text);
113
- }
114
- }
115
- this.updatePendingMessagesDisplay();
116
- return;
117
- }
118
- // Find first non-extension-command message to use as prompt
119
- const firstPromptIndex = queuedMessages.findIndex((message) => !this.isExtensionCommand(message.text));
120
- if (firstPromptIndex === -1) {
121
- // All extension commands - execute them all
122
- for (const message of queuedMessages) {
123
- await this.session.prompt(message.text);
124
- }
125
- return;
126
- }
127
- // Execute any extension commands before the first prompt
128
- const preCommands = queuedMessages.slice(0, firstPromptIndex);
129
- const firstPrompt = queuedMessages[firstPromptIndex];
130
- const rest = queuedMessages.slice(firstPromptIndex + 1);
131
- for (const message of preCommands) {
132
- await this.session.prompt(message.text);
98
+ }
99
+ const arrivedAfterDrain = this.compactionQueuedMessages.length > 0 && !this.compactionSendFailed && !this.compactionActive;
100
+ if (arrivedAfterDrain)
101
+ await this.flushCompactionQueue(options);
102
+ };
103
+ async function sendCompactionQueue(mode, willRetry) {
104
+ const queueOnly = !willRetry && (mode.session.isStreaming || mode.session.queuedMessagesPaused);
105
+ if (queueOnly) {
106
+ await drainCompactionQueue(mode, (message) => mode.session.prompt(message.text, { streamingBehavior: message.mode }));
107
+ return;
108
+ }
109
+ if (!willRetry && !(await startCompactionQueuePrompt(mode)))
110
+ return;
111
+ await drainCompactionQueue(mode, (message) => {
112
+ if (mode.isExtensionCommand(message.text))
113
+ return mode.session.prompt(message.text);
114
+ if (message.mode === "followUp")
115
+ return mode.session.followUp(message.text);
116
+ return mode.session.steer(message.text);
117
+ });
118
+ }
119
+ function showCompactionQueueError(mode, error) {
120
+ mode.showError(`Failed to send queued message: ${error instanceof Error ? error.message : String(error)}`);
121
+ }
122
+ function takeNextCompactionMessage(mode) {
123
+ const [next, ...rest] = mode.compactionQueuedMessages;
124
+ mode.compactionQueuedMessages = rest;
125
+ mode.updatePendingMessagesDisplay();
126
+ return next;
127
+ }
128
+ function returnCompactionMessage(mode, message, error) {
129
+ mode.compactionQueuedMessages = [message, ...mode.compactionQueuedMessages];
130
+ mode.compactionSendFailed = true;
131
+ mode.updatePendingMessagesDisplay();
132
+ showCompactionQueueError(mode, error);
133
+ }
134
+ /**
135
+ * Deliver messages one at a time from the front of the compaction queue. Input submitted meanwhile
136
+ * joins the back of that queue, so a failed message returns to the front ahead of everything after it.
137
+ */
138
+ async function drainCompactionQueue(mode, deliver, limit = Number.POSITIVE_INFINITY) {
139
+ for (let delivered = 0; delivered < limit; delivered++) {
140
+ const message = takeNextCompactionMessage(mode);
141
+ if (!message)
142
+ break;
143
+ try {
144
+ await deliver(message);
133
145
  }
134
- // Start a prompt when idle, or preserve its delivery mode if a run is
135
- // still winding down after compaction.
136
- const promptPromise = this.session
137
- .prompt(firstPrompt.text, { streamingBehavior: firstPrompt.mode })
138
- .catch((error) => {
139
- restoreQueue(error, [firstPrompt]);
140
- });
141
- // Queue remaining messages
142
- for (const message of rest) {
143
- if (this.isExtensionCommand(message.text)) {
144
- await this.session.prompt(message.text);
145
- }
146
- else if (message.mode === "followUp") {
147
- await this.session.followUp(message.text);
148
- }
149
- else {
150
- await this.session.steer(message.text);
151
- }
146
+ catch (error) {
147
+ returnCompactionMessage(mode, message, error);
148
+ return false;
152
149
  }
153
- this.updatePendingMessagesDisplay();
154
- void promptPromise;
155
150
  }
156
- catch (error) {
157
- this.session.clearQueue();
158
- restoreQueue(error);
151
+ return true;
152
+ }
153
+ /**
154
+ * Run leading extension commands, then start the first prompt. The rest of the batch stays in the
155
+ * compaction queue until that prompt is accepted, so a rejected prompt is restored ahead of it.
156
+ */
157
+ async function startCompactionQueuePrompt(mode) {
158
+ const firstPromptIndex = mode.compactionQueuedMessages.findIndex((message) => !mode.isExtensionCommand(message.text));
159
+ const leadingCommands = firstPromptIndex === -1 ? mode.compactionQueuedMessages.length : firstPromptIndex;
160
+ const ranCommands = await drainCompactionQueue(mode, (message) => mode.session.prompt(message.text), leadingCommands);
161
+ if (!ranCommands)
162
+ return false;
163
+ const first = takeNextCompactionMessage(mode);
164
+ if (!first)
165
+ return false;
166
+ let accept;
167
+ const accepted = new Promise((resolve) => {
168
+ accept = resolve;
169
+ });
170
+ const prompt = mode.session.prompt(first.text, {
171
+ streamingBehavior: first.mode,
172
+ preflightResult: (success) => accept(success),
173
+ });
174
+ prompt.then(() => accept(true), () => accept(false));
175
+ if (await accepted) {
176
+ prompt.catch((error) => showCompactionQueueError(mode, error));
177
+ return true;
159
178
  }
160
- };
179
+ returnCompactionMessage(mode, first, await prompt.then(() => undefined, (error) => error));
180
+ return false;
181
+ }
161
182
  InteractiveModeBase.prototype.flushPendingBashComponents = function () {
162
183
  for (const component of this.pendingBashComponents) {
163
184
  this.pendingMessagesContainer.removeChild(component);