@di-code/coding-agent 0.1.3 → 0.1.6

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 (147) hide show
  1. package/README.md +91 -30
  2. package/dist/cli.d.ts +15 -0
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js +96 -17
  5. package/dist/cli.js.map +1 -1
  6. package/dist/core/clipboard-image.d.ts +3 -3
  7. package/dist/core/clipboard-image.d.ts.map +1 -1
  8. package/dist/core/clipboard-image.js +26 -13
  9. package/dist/core/clipboard-image.js.map +1 -1
  10. package/dist/core/context-builder.d.ts.map +1 -1
  11. package/dist/core/context-builder.js +6 -2
  12. package/dist/core/context-builder.js.map +1 -1
  13. package/dist/core/image-input.d.ts +1 -1
  14. package/dist/core/image-input.d.ts.map +1 -1
  15. package/dist/core/image-input.js +55 -10
  16. package/dist/core/image-input.js.map +1 -1
  17. package/dist/core/resources/loader.d.ts.map +1 -1
  18. package/dist/core/resources/loader.js +15 -42
  19. package/dist/core/resources/loader.js.map +1 -1
  20. package/dist/core/resources/types.d.ts +6 -9
  21. package/dist/core/resources/types.d.ts.map +1 -1
  22. package/dist/core/resources/types.js.map +1 -1
  23. package/dist/core/session/session-manager.d.ts +12 -1
  24. package/dist/core/session/session-manager.d.ts.map +1 -1
  25. package/dist/core/session/session-manager.js +66 -3
  26. package/dist/core/session/session-manager.js.map +1 -1
  27. package/dist/core/session/session-storage.d.ts.map +1 -1
  28. package/dist/core/session/session-storage.js +30 -15
  29. package/dist/core/session/session-storage.js.map +1 -1
  30. package/dist/core/session/types.d.ts +6 -1
  31. package/dist/core/session/types.d.ts.map +1 -1
  32. package/dist/core/session/types.js +1 -1
  33. package/dist/core/session/types.js.map +1 -1
  34. package/dist/core/session.d.ts +38 -3
  35. package/dist/core/session.d.ts.map +1 -1
  36. package/dist/core/session.js +167 -9
  37. package/dist/core/session.js.map +1 -1
  38. package/dist/core/system-prompt.js +2 -2
  39. package/dist/core/system-prompt.js.map +1 -1
  40. package/dist/core/tools/bash.d.ts +2 -2
  41. package/dist/core/tools/bash.d.ts.map +1 -1
  42. package/dist/core/tools/bash.js.map +1 -1
  43. package/dist/core/tools/edit-diff.d.ts +25 -0
  44. package/dist/core/tools/edit-diff.d.ts.map +1 -0
  45. package/dist/core/tools/edit-diff.js +136 -0
  46. package/dist/core/tools/edit-diff.js.map +1 -0
  47. package/dist/core/tools/edit.d.ts +13 -4
  48. package/dist/core/tools/edit.d.ts.map +1 -1
  49. package/dist/core/tools/edit.js +64 -30
  50. package/dist/core/tools/edit.js.map +1 -1
  51. package/dist/core/tools/file-search.d.ts +14 -0
  52. package/dist/core/tools/file-search.d.ts.map +1 -0
  53. package/dist/core/tools/file-search.js +99 -0
  54. package/dist/core/tools/file-search.js.map +1 -0
  55. package/dist/core/tools/glob.d.ts +11 -0
  56. package/dist/core/tools/glob.d.ts.map +1 -0
  57. package/dist/core/tools/glob.js +44 -0
  58. package/dist/core/tools/glob.js.map +1 -0
  59. package/dist/core/tools/grep.d.ts +13 -0
  60. package/dist/core/tools/grep.d.ts.map +1 -0
  61. package/dist/core/tools/grep.js +67 -0
  62. package/dist/core/tools/grep.js.map +1 -0
  63. package/dist/core/tools/load-skill.d.ts +10 -0
  64. package/dist/core/tools/load-skill.d.ts.map +1 -0
  65. package/dist/core/tools/load-skill.js +22 -0
  66. package/dist/core/tools/load-skill.js.map +1 -0
  67. package/dist/core/tools/path-boundary.d.ts +2 -0
  68. package/dist/core/tools/path-boundary.d.ts.map +1 -1
  69. package/dist/core/tools/path-boundary.js +4 -0
  70. package/dist/core/tools/path-boundary.js.map +1 -1
  71. package/dist/core/tools/read.d.ts +2 -2
  72. package/dist/core/tools/read.d.ts.map +1 -1
  73. package/dist/core/tools/read.js.map +1 -1
  74. package/dist/core/tools/write.d.ts +2 -2
  75. package/dist/core/tools/write.d.ts.map +1 -1
  76. package/dist/core/tools/write.js.map +1 -1
  77. package/dist/core/user-data.d.ts +3 -0
  78. package/dist/core/user-data.d.ts.map +1 -0
  79. package/dist/core/user-data.js +8 -0
  80. package/dist/core/user-data.js.map +1 -0
  81. package/dist/entry.js +22 -2
  82. package/dist/entry.js.map +1 -1
  83. package/dist/extensions/runtime.js +2 -2
  84. package/dist/extensions/runtime.js.map +1 -1
  85. package/dist/i18n.d.ts +5 -0
  86. package/dist/i18n.d.ts.map +1 -0
  87. package/dist/i18n.js +223 -0
  88. package/dist/i18n.js.map +1 -0
  89. package/dist/index.d.ts +3 -0
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +3 -0
  92. package/dist/index.js.map +1 -1
  93. package/dist/main.d.ts +20 -1
  94. package/dist/main.d.ts.map +1 -1
  95. package/dist/main.js +272 -17
  96. package/dist/main.js.map +1 -1
  97. package/dist/mcp/config.d.ts +33 -0
  98. package/dist/mcp/config.d.ts.map +1 -0
  99. package/dist/mcp/config.js +211 -0
  100. package/dist/mcp/config.js.map +1 -0
  101. package/dist/mcp/loader.d.ts +21 -0
  102. package/dist/mcp/loader.d.ts.map +1 -0
  103. package/dist/mcp/loader.js +60 -0
  104. package/dist/mcp/loader.js.map +1 -0
  105. package/dist/mcp/tool-adapter.d.ts +5 -0
  106. package/dist/mcp/tool-adapter.d.ts.map +1 -0
  107. package/dist/mcp/tool-adapter.js +149 -0
  108. package/dist/mcp/tool-adapter.js.map +1 -0
  109. package/dist/modes/interactive-components.d.ts +2 -0
  110. package/dist/modes/interactive-components.d.ts.map +1 -1
  111. package/dist/modes/interactive-components.js +55 -31
  112. package/dist/modes/interactive-components.js.map +1 -1
  113. package/dist/modes/interactive-diff.d.ts +8 -0
  114. package/dist/modes/interactive-diff.d.ts.map +1 -0
  115. package/dist/modes/interactive-diff.js +78 -0
  116. package/dist/modes/interactive-diff.js.map +1 -0
  117. package/dist/modes/interactive-layout.d.ts +4 -0
  118. package/dist/modes/interactive-layout.d.ts.map +1 -1
  119. package/dist/modes/interactive-layout.js +4 -0
  120. package/dist/modes/interactive-layout.js.map +1 -1
  121. package/dist/modes/interactive-state.d.ts +5 -0
  122. package/dist/modes/interactive-state.d.ts.map +1 -1
  123. package/dist/modes/interactive-state.js +65 -11
  124. package/dist/modes/interactive-state.js.map +1 -1
  125. package/dist/modes/interactive.d.ts +19 -0
  126. package/dist/modes/interactive.d.ts.map +1 -1
  127. package/dist/modes/interactive.js +351 -52
  128. package/dist/modes/interactive.js.map +1 -1
  129. package/dist/modes/tree-selector.d.ts +30 -0
  130. package/dist/modes/tree-selector.d.ts.map +1 -0
  131. package/dist/modes/tree-selector.js +205 -0
  132. package/dist/modes/tree-selector.js.map +1 -0
  133. package/dist/plugins/loader.d.ts +19 -1
  134. package/dist/plugins/loader.d.ts.map +1 -1
  135. package/dist/plugins/loader.js +21 -2
  136. package/dist/plugins/loader.js.map +1 -1
  137. package/dist/provider-onboarding.d.ts +8 -1
  138. package/dist/provider-onboarding.d.ts.map +1 -1
  139. package/dist/provider-onboarding.js +160 -40
  140. package/dist/provider-onboarding.js.map +1 -1
  141. package/dist/rpc-entry.js +1 -1
  142. package/dist/rpc-entry.js.map +1 -1
  143. package/dist/startup.d.ts +34 -3
  144. package/dist/startup.d.ts.map +1 -1
  145. package/dist/startup.js +407 -87
  146. package/dist/startup.js.map +1 -1
  147. package/package.json +7 -4
@@ -1 +1 @@
1
- {"version":3,"file":"interactive.js","sourceRoot":"","sources":["../../src/modes/interactive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAEN,4BAA4B,EAC5B,MAAM,EACN,GAAG,EACH,UAAU,EAEV,UAAU,EACV,YAAY,GAEZ,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,2BAA2B,EAC3B,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,GACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAA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AAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QACjC,OAAO,mBAAmB,KAAK,CAAC,YAAY,UAAU,KAAK,CAAC,WAAW,WAAW,KAAK,CAAC,YAAY,UAAU,KAAK,CAAC,WAAW,UAAU,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,sBAAsB,IAAI,KAAK,CAAC,aAAa,EAAE,CAAC;IACvO,CAAC;IAEO,KAAK,CAAC,mBAAmB;QAChC,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACpD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,2CAA2C,CAAC,CAAC;YACtE,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,OAAO;QACR,CAAC;QACD,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAC/B,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAAC;QACxD,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAI,CAAC;YACJ,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAAC;QACzD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAClF,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC;YAChC,IAAI,CAAC,OAAO,EAAE,CAAC;QAChB,CAAC;IACF,CAAC;CACD","sourcesContent":["import { statSync } from \"node:fs\";\nimport { extname, resolve } from \"node:path\";\nimport {\n\ttype AutocompleteProvider,\n\tCombinedAutocompleteProvider,\n\tEditor,\n\tKey,\n\tmatchesKey,\n\ttype OverlayHandle,\n\tSelectList,\n\tSettingsList,\n\ttype TUI,\n} from \"@di-code/tui\";\nimport {\n\tcleanupStaleClipboardImages,\n\tclipboardImageDirectory,\n\tisClipboardImagePath,\n\treadClipboardImagePath,\n\tremoveClipboardImage,\n} from \"../core/clipboard-image.ts\";\nimport { extractImageAttachments } from \"../core/image-input.ts\";\nimport type { AgentSession, AgentSessionEvent } from \"../core/session.ts\";\nimport type { ExtensionHost } from \"../extensions/runtime.ts\";\nimport {\n\tAutocompleteMenu,\n\tInteractiveChat,\n\tInteractiveComposer,\n\tInteractiveFooter,\n\tInteractiveHeader,\n\ttype InteractiveViewState,\n} from \"./interactive-components.ts\";\nimport { InteractiveLayout } from \"./interactive-layout.ts\";\nimport { InteractiveProjection } from \"./interactive-state.ts\";\n\nexport type { AgentSessionEvent };\nexport type { InteractiveMessage, InteractiveProcessItem, InteractiveState } from \"./interactive-state.ts\";\nexport { InteractiveProjection } from \"./interactive-state.ts\";\n\nconst IMAGE_EXTENSIONS = new Set([\".gif\", \".jpeg\", \".jpg\", \".png\", \".webp\"]);\nconst PASTE_IMAGE_KEY = process.platform === \"win32\" ? Key.alt(\"v\") : Key.ctrl(\"v\");\nconst PASTE_IMAGE_SHORTCUT = process.platform === \"win32\" ? \"Alt+V\" : \"Ctrl+V\";\n\nfunction asImageAttachmentReference(pasted: string, cwd: string): string {\n\tif (pasted.includes(\"\\n\")) return pasted;\n\tconst candidate = pasted.trim().replace(/^(?:\"([\\s\\S]*)\"|'([\\s\\S]*)')$/, \"$1$2\");\n\tif (!candidate || !IMAGE_EXTENSIONS.has(extname(candidate).toLowerCase())) return pasted;\n\ttry {\n\t\tif (!statSync(resolve(cwd, candidate)).isFile()) return pasted;\n\t} catch {\n\t\treturn pasted;\n\t}\n\treturn `@\"${candidate.replaceAll('\"', '\\\\\"')}\" `;\n}\n\nfunction normalizeDroppedImagePrompt(prompt: string, cwd: string): string {\n\tconst normalized = asImageAttachmentReference(prompt, cwd);\n\tif (normalized !== prompt) return normalized;\n\tconst prefix = /^((?:(?:[A-Za-z]:[\\\\/])|(?:\\.\\.?[\\\\/])|\\/)[\\s\\S]*?\\.(?:gif|jpe?g|png|webp))([\\s\\S]*)$/i.exec(prompt);\n\tif (!prefix) return prompt;\n\tconst imageReference = asImageAttachmentReference(prefix[1] ?? \"\", cwd);\n\treturn imageReference === prefix[1]\n\t\t? prompt\n\t\t: `${imageReference}${normalizeDroppedImagePrompt(prefix[2] ?? \"\", cwd)}`;\n}\n\nexport interface InteractiveModeOptions {\n\treadonly session: AgentSession;\n\treadonly tui: TUI;\n\treadonly onExit?: () => void;\n\treadonly sessions?: readonly InteractiveSessionChoice[];\n\treadonly extensionHost?: ExtensionHost;\n\treadonly readClipboardImagePath?: (directory?: string) => Promise<string | null>;\n}\n\nexport interface InteractiveSessionChoice {\n\treadonly id: string;\n\treadonly label: string;\n\treadonly description?: string;\n\topen(): AgentSession | Promise<AgentSession>;\n}\n\nexport class InteractiveMode {\n\tprivate readonly projection = new InteractiveProjection();\n\tprivate readonly root: InteractiveLayout;\n\tprivate readonly editor: Editor;\n\tprivate session: AgentSession;\n\tprivate readonly tui: TUI;\n\tprivate readonly sessionChoices: readonly InteractiveSessionChoice[];\n\tprivate readonly extensionHost?: ExtensionHost;\n\tprivate readonly readClipboardImagePath: (directory?: string) => Promise<string | null>;\n\tprivate clipboardDirectory: string;\n\tprivate readonly clipboardFiles = new Set<string>();\n\tprivate unsubscribeSession?: () => void;\n\tprivate sessionSwitching = false;\n\tprivate promptInFlight = false;\n\tprivate compactionInFlight = false;\n\tprivate activeAbort?: AbortController;\n\tprivate started = false;\n\tprivate lastFailedPrompt?: string;\n\tprivate queuedPrompts: string[] = [];\n\tprivate readonly onExit?: () => void;\n\tprivate theme: \"dark\" | \"light\" = \"dark\";\n\tprivate overlay?: OverlayHandle;\n\tprivate autocompleteOverlay?: OverlayHandle;\n\tprivate spinnerTimer?: ReturnType<typeof setInterval>;\n\tprivate shutdownEmitted = false;\n\tprivate preserveClipboardFiles = false;\n\n\tconstructor(options: InteractiveModeOptions) {\n\t\tthis.session = options.session;\n\t\tthis.tui = options.tui;\n\t\tthis.onExit = options.onExit;\n\t\tthis.sessionChoices = [...(options.sessions ?? [])];\n\t\tthis.extensionHost = options.extensionHost;\n\t\tthis.readClipboardImagePath = options.readClipboardImagePath ?? readClipboardImagePath;\n\t\tthis.clipboardDirectory = clipboardImageDirectory(this.session.allowedRoot);\n\t\tconst commands = [\n\t\t\t{ name: \"help\", description: \"Show interactive commands\" },\n\t\t\t{ name: \"clear\", description: \"Clear visible messages\" },\n\t\t\t{ name: \"model\", description: \"Open the model selector\" },\n\t\t\t{ name: \"session\", description: \"Open the session selector\" },\n\t\t\t{ name: \"theme\", description: \"Open the theme selector\" },\n\t\t\t{ name: \"settings\", description: \"Open the settings selector\" },\n\t\t\t{ name: \"compact\", description: \"Compact the persisted context now\" },\n\t\t\t{ name: \"usage\", description: \"Show token and cost usage\" },\n\t\t\t{ name: \"retry\", description: \"Retry the last failed prompt\" },\n\t\t] as const;\n\t\tconst allCommands = [...commands, ...(this.extensionHost?.listCommands() ?? [])];\n\t\tconst autocomplete: AutocompleteProvider = {\n\t\t\tgetSuggestions: (context, autocompleteOptions) =>\n\t\t\t\tnew CombinedAutocompleteProvider(allCommands, this.session.allowedRoot).getSuggestions(\n\t\t\t\t\tcontext,\n\t\t\t\t\tautocompleteOptions,\n\t\t\t\t),\n\t\t\tapplyCompletion: (context, item, prefix) =>\n\t\t\t\tnew CombinedAutocompleteProvider(allCommands, this.session.allowedRoot).applyCompletion(context, item, prefix),\n\t\t};\n\t\tthis.editor = new Editor({\n\t\t\tmaxHeight: 3,\n\t\t\tautocomplete,\n\t\t});\n\t\tthis.editor.onSubmit = (text) => void this.submit(text);\n\t\tthis.editor.onEscape = () => this.activeAbort?.abort();\n\t\tthis.editor.onCommand = (data) => this.handleCommand(data);\n\t\tthis.editor.onInterrupt = () => this.exit();\n\t\tthis.editor.onChange = () => {\n\t\t\tif (!this.preserveClipboardFiles) {\n\t\t\t\tvoid this.cleanupUnreferencedClipboardFiles().catch((cause) => {\n\t\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t\t\tthis.refresh();\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\t\tthis.editor.onAutocompleteChange = () => this.updateAutocompleteOverlay();\n\t\tconst readViewState = (): InteractiveViewState => ({\n\t\t\t...this.projection.state,\n\t\t\tmodel: this.session.modelId,\n\t\t\ttheme: this.theme,\n\t\t\tpasteImageShortcut: PASTE_IMAGE_SHORTCUT,\n\t\t});\n\t\tthis.root = new InteractiveLayout({\n\t\t\theader: new InteractiveHeader(readViewState),\n\t\t\tchat: new InteractiveChat(readViewState),\n\t\t\tcomposer: new InteractiveComposer(readViewState),\n\t\t\teditor: this.editor,\n\t\t\tfooter: new InteractiveFooter(readViewState),\n\t\t});\n\t\tthis.tui.addChild(this.root);\n\t\tthis.tui.setFocus(this.editor);\n\t}\n\n\tstart(initialPrompt?: string): void {\n\t\tif (this.started) throw new Error(\"Interactive mode is already started\");\n\t\tthis.started = true;\n\t\tthis.shutdownEmitted = false;\n\t\tvoid this.extensionHost?.emit({ type: \"session_start\", cwd: this.session.allowedRoot });\n\t\tthis.projection.replaceTranscript(this.session.transcript);\n\t\tthis.projection.setUsage(this.session.usage);\n\t\tthis.subscribeToSession();\n\t\tvoid cleanupStaleClipboardImages(this.session.allowedRoot).catch((cause) => {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\tthis.refresh();\n\t\t});\n\t\ttry {\n\t\t\tthis.tui.start();\n\t\t} catch (cause) {\n\t\t\tthis.started = false;\n\t\t\tthis.unsubscribeSession?.();\n\t\t\tthis.unsubscribeSession = undefined;\n\t\t\tthrow cause;\n\t\t}\n\t\tthis.startSpinnerTimer();\n\t\tif (initialPrompt?.trim()) void this.submit(initialPrompt);\n\t}\n\n\tstop(): void {\n\t\tif (!this.started && !this.unsubscribeSession) return;\n\t\tthis.started = false;\n\t\tthis.activeAbort?.abort();\n\t\tthis.activeAbort = undefined;\n\t\tthis.stopSpinnerTimer();\n\t\tthis.projection.clearTransientProcess();\n\t\tthis.closeOverlay();\n\t\tthis.closeAutocompleteOverlay();\n\t\tthis.unsubscribeSession?.();\n\t\tthis.unsubscribeSession = undefined;\n\t\tvoid this.cleanupClipboardFiles();\n\t\tthis.tui.stop({ finalLines: this.root.renderTranscript(this.tui.columns) });\n\t\tif (!this.shutdownEmitted) {\n\t\t\tthis.shutdownEmitted = true;\n\t\t\tvoid this.extensionHost?.emit({ type: \"session_shutdown\", reason: \"user\" });\n\t\t}\n\t}\n\n\tprivate exit(): void {\n\t\tthis.stop();\n\t\tthis.onExit?.();\n\t}\n\n\tprivate handleCommand(data: string): boolean {\n\t\tif (data === \"\\x14\") {\n\t\t\tthis.openThemeSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x13\") {\n\t\t\tthis.openSettingsSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x0f\") {\n\t\t\tthis.openModelSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x0c\") {\n\t\t\tthis.openSessionSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x12\" && this.lastFailedPrompt && !this.promptInFlight) {\n\t\t\tvoid this.submit(this.lastFailedPrompt, true);\n\t\t\treturn true;\n\t\t}\n\t\tif (matchesKey(data, PASTE_IMAGE_KEY)) {\n\t\t\tvoid this.attachClipboardImage();\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tprivate async attachClipboardImage(): Promise<void> {\n\t\ttry {\n\t\t\tconst path = await this.readClipboardImagePath(this.clipboardDirectory);\n\t\t\tif (!path) {\n\t\t\t\tthis.projection.setStatus(\"Clipboard has no supported image.\");\n\t\t\t} else {\n\t\t\t\tthis.editor.insertTextAtCursor(path);\n\t\t\t\tif (isClipboardImagePath(path, this.clipboardDirectory)) this.clipboardFiles.add(path);\n\t\t\t}\n\t\t} catch (cause) {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t}\n\t\tthis.refresh();\n\t}\n\n\tprivate openThemeSelector(): void {\n\t\tconst list = new SelectList([\n\t\t\t{ value: \"dark\", label: \"Dark\", description: \"Dark terminal theme\" },\n\t\t\t{ value: \"light\", label: \"Light\", description: \"Light terminal theme\" },\n\t\t]);\n\t\tlist.onSelect = (item) => {\n\t\t\tthis.theme = item.value === \"light\" ? \"light\" : \"dark\";\n\t\t\tthis.projection.setStatus(`theme=${this.theme}`);\n\t\t\tthis.closeOverlay();\n\t\t\tthis.refresh();\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate openModelSelector(): void {\n\t\tconst list = new SelectList(\n\t\t\tthis.session.availableModels.map((model) => ({\n\t\t\t\tvalue: model.id,\n\t\t\t\tlabel: model.name,\n\t\t\t\tdescription: `${model.provider} / ${model.id} / context ${model.contextWindow}`,\n\t\t\t})),\n\t\t);\n\t\tlist.onSelect = (item) => {\n\t\t\ttry {\n\t\t\t\tthis.session.setModel(item.value);\n\t\t\t\tthis.projection.setStatus(`model=${item.value}`);\n\t\t\t\tthis.closeOverlay();\n\t\t\t\tthis.refresh();\n\t\t\t} catch (cause) {\n\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t}\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate openSessionSelector(): void {\n\t\tconst list = new SelectList([\n\t\t\t{\n\t\t\t\tvalue: \"__current__\",\n\t\t\t\tlabel: \"Current session\",\n\t\t\t\tdescription: this.session.sessionFile ?? \"In-memory session\",\n\t\t\t},\n\t\t\t...this.sessionChoices.map((choice) => ({\n\t\t\t\tvalue: choice.id,\n\t\t\t\tlabel: choice.label,\n\t\t\t\t...(choice.description ? { description: choice.description } : {}),\n\t\t\t})),\n\t\t]);\n\t\tlist.onSelect = (item) => {\n\t\t\tif (item.value === \"__current__\") {\n\t\t\t\tthis.projection.setStatus(\"session=current\");\n\t\t\t\tthis.closeOverlay();\n\t\t\t\tthis.refresh();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst choice = this.sessionChoices.find((candidate) => candidate.id === item.value);\n\t\t\tif (!choice) return;\n\t\t\tthis.closeOverlay();\n\t\t\tvoid this.switchSession(choice);\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate openSettingsSelector(): void {\n\t\tconst list = new SettingsList([\n\t\t\t{\n\t\t\t\tid: \"compaction\",\n\t\t\t\tlabel: \"Context compaction\",\n\t\t\t\tcurrentValue: this.session.compactionEnabled ? \"on\" : \"off\",\n\t\t\t\tvalues: [\"on\", \"off\"],\n\t\t\t\tdescription: \"Summarize older persisted context before the model limit is reached.\",\n\t\t\t},\n\t\t]);\n\t\tlist.onChange = (id, value) => {\n\t\t\tif (id !== \"compaction\") return;\n\t\t\ttry {\n\t\t\t\tconst enabled = this.session.setCompactionEnabled(value === \"on\");\n\t\t\t\tlist.updateValue(id, enabled ? \"on\" : \"off\");\n\t\t\t\tthis.projection.setStatus(\n\t\t\t\t\tenabled === (value === \"on\")\n\t\t\t\t\t\t? `compaction=${enabled ? \"on\" : \"off\"}`\n\t\t\t\t\t\t: \"compaction unavailable without a persisted session\",\n\t\t\t\t);\n\t\t\t} catch (cause) {\n\t\t\t\tlist.updateValue(id, this.session.compactionEnabled ? \"on\" : \"off\");\n\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t\tthis.closeOverlay();\n\t\t\t}\n\t\t\tthis.refresh();\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate showOverlay(component: SelectList | SettingsList): void {\n\t\tthis.editor.cancelAutocomplete();\n\t\tthis.closeAutocompleteOverlay();\n\t\tthis.closeOverlay();\n\t\tthis.overlay = this.tui.showOverlay(component, {\n\t\t\twidth: \"70%\",\n\t\t\tmaxHeight: \"60%\",\n\t\t\tanchor: \"center\",\n\t\t\tmargin: 1,\n\t\t});\n\t}\n\n\tprivate closeOverlay(): void {\n\t\tthis.overlay?.hide();\n\t\tthis.overlay = undefined;\n\t}\n\n\tprivate updateAutocompleteOverlay(): void {\n\t\tthis.closeAutocompleteOverlay();\n\t\tif (!this.editor.isShowingAutocomplete()) {\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tconst menu = new AutocompleteMenu(() => ({\n\t\t\titems: this.editor.getAutocompleteItems(),\n\t\t\tindex: this.editor.getAutocompleteIndex(),\n\t\t}));\n\t\tthis.autocompleteOverlay = this.tui.showOverlay(menu, {\n\t\t\twidth: \"55%\",\n\t\t\tmaxHeight: 8,\n\t\t\tanchor: \"bottom-left\",\n\t\t\tmargin: 1,\n\t\t\tnonCapturing: true,\n\t\t});\n\t\tthis.refresh();\n\t}\n\n\tprivate closeAutocompleteOverlay(): void {\n\t\tthis.autocompleteOverlay?.hide();\n\t\tthis.autocompleteOverlay = undefined;\n\t}\n\n\tprivate refresh(): void {\n\t\tthis.root.invalidate();\n\t\tthis.tui.requestRender();\n\t}\n\n\tprivate startSpinnerTimer(): void {\n\t\tthis.stopSpinnerTimer();\n\t\tthis.spinnerTimer = setInterval(() => {\n\t\t\tif (this.projection.advanceSpinner()) this.refresh();\n\t\t}, 120);\n\t\tthis.spinnerTimer.unref?.();\n\t}\n\n\tprivate stopSpinnerTimer(): void {\n\t\tif (this.spinnerTimer) clearInterval(this.spinnerTimer);\n\t\tthis.spinnerTimer = undefined;\n\t}\n\n\tprivate subscribeToSession(): void {\n\t\tthis.unsubscribeSession?.();\n\t\tthis.unsubscribeSession = this.session.subscribeSession((event) => {\n\t\t\tif (!this.started) return;\n\t\t\tthis.projection.apply(event);\n\t\t\tthis.refresh();\n\t\t});\n\t}\n\n\tprivate async switchSession(choice: InteractiveSessionChoice): Promise<void> {\n\t\tif (this.promptInFlight || this.sessionSwitching) {\n\t\t\tthis.projection.setError(\"Cannot switch sessions while a prompt is running.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tthis.sessionSwitching = true;\n\t\tthis.projection.setStatus(`opening session=${choice.id}`);\n\t\tthis.refresh();\n\t\ttry {\n\t\t\tconst next = await choice.open();\n\t\t\tif (!this.started) return;\n\t\t\tthis.unsubscribeSession?.();\n\t\t\tthis.session = next;\n\t\t\tthis.clipboardDirectory = clipboardImageDirectory(next.allowedRoot);\n\t\t\tvoid cleanupStaleClipboardImages(next.allowedRoot);\n\t\t\tthis.queuedPrompts = [];\n\t\t\tthis.projection.setQueue([]);\n\t\t\tthis.projection.replaceTranscript(next.transcript);\n\t\t\tthis.projection.setUsage(next.usage);\n\t\t\tthis.projection.setStatus(`session=${choice.id}`);\n\t\t\tthis.subscribeToSession();\n\t\t} catch (cause) {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t} finally {\n\t\t\tthis.sessionSwitching = false;\n\t\t}\n\t\tthis.refresh();\n\t}\n\n\tprivate async submit(text: string, retry = false): Promise<void> {\n\t\tconst prompt = text.trim();\n\t\tif (prompt.length === 0 || !this.started) return;\n\t\tif (prompt.startsWith(\"/\")) {\n\t\t\tthis.editor.setValue(\"\");\n\t\t\tthis.handleSlashCommand(prompt);\n\t\t\treturn;\n\t\t}\n\t\tif (this.sessionSwitching) {\n\t\t\tthis.projection.setError(\"A session is opening; wait before submitting a prompt.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (this.compactionInFlight) {\n\t\t\tthis.projection.setError(\"A compaction is running; wait before submitting a prompt.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (this.promptInFlight) {\n\t\t\tthis.queuedPrompts.push(prompt);\n\t\t\tthis.projection.setQueue(this.queuedPrompts);\n\t\t\tthis.root.invalidate();\n\t\t\tthis.tui.requestRender();\n\t\t\treturn;\n\t\t}\n\t\tthis.promptInFlight = true;\n\t\tthis.activeAbort = new AbortController();\n\t\tthis.projection.setRetrying(retry);\n\t\ttry {\n\t\t\tconst input = await extractImageAttachments(\n\t\t\t\tnormalizeDroppedImagePrompt(prompt, this.session.allowedRoot),\n\t\t\t\tthis.session.allowedRoot,\n\t\t\t);\n\t\t\tthis.preserveClipboardFiles = true;\n\t\t\tthis.editor.setValue(\"\");\n\t\t\tconst result = await this.session.promptWithImages(input.text, input.images, this.activeAbort.signal);\n\t\t\tif (result.stopReason === \"error\" || result.stopReason === \"aborted\") this.lastFailedPrompt = prompt;\n\t\t\telse {\n\t\t\t\tthis.lastFailedPrompt = undefined;\n\t\t\t\tawait this.cleanupClipboardFiles();\n\t\t\t}\n\t\t} catch (cause) {\n\t\t\tthis.lastFailedPrompt = prompt;\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t} finally {\n\t\t\tthis.preserveClipboardFiles = false;\n\t\t\tthis.promptInFlight = false;\n\t\t\tthis.activeAbort = undefined;\n\t\t\tthis.projection.setRetrying(false);\n\t\t\tconst next = this.queuedPrompts.shift();\n\t\t\tthis.projection.setQueue(this.queuedPrompts);\n\t\t\tthis.root.invalidate();\n\t\t\tthis.tui.requestRender();\n\t\t\tif (next && this.started) void this.submit(next);\n\t\t}\n\t}\n\n\tprivate async cleanupUnreferencedClipboardFiles(): Promise<void> {\n\t\tconst text = this.editor.getValue();\n\t\tconst files = [...this.clipboardFiles].filter((path) => !text.includes(path));\n\t\tawait Promise.all(files.map((path) => removeClipboardImage(path, this.clipboardDirectory)));\n\t\tfor (const path of files) this.clipboardFiles.delete(path);\n\t}\n\n\tprivate async cleanupClipboardFiles(): Promise<void> {\n\t\tconst files = [...this.clipboardFiles];\n\t\tawait Promise.all(files.map((path) => removeClipboardImage(path, this.clipboardDirectory)));\n\t\tfor (const path of files) this.clipboardFiles.delete(path);\n\t}\n\n\tprivate handleSlashCommand(input: string): void {\n\t\tconst trimmed = input.slice(1).trim();\n\t\tconst [rawCommand = \"\", ...argParts] = trimmed.split(/\\s+/);\n\t\tconst command = rawCommand.toLowerCase();\n\t\tconst args = argParts.join(\" \");\n\t\tswitch (command) {\n\t\t\tcase \"help\":\n\t\t\t\tthis.projection.setStatus(\"commands: /clear /model /session /theme /settings /compact /usage /retry\");\n\t\t\t\tbreak;\n\t\t\tcase \"clear\":\n\t\t\t\tthis.projection.clearVisibleMessages();\n\t\t\t\tthis.projection.setStatus(\"visible messages cleared\");\n\t\t\t\tbreak;\n\t\t\tcase \"model\":\n\t\t\t\tthis.openModelSelector();\n\t\t\t\treturn;\n\t\t\tcase \"session\":\n\t\t\t\tthis.openSessionSelector();\n\t\t\t\treturn;\n\t\t\tcase \"theme\":\n\t\t\t\tthis.openThemeSelector();\n\t\t\t\treturn;\n\t\t\tcase \"settings\":\n\t\t\t\tthis.openSettingsSelector();\n\t\t\t\treturn;\n\t\t\tcase \"compact\":\n\t\t\t\tvoid this.runManualCompaction();\n\t\t\t\treturn;\n\t\t\tcase \"usage\":\n\t\t\t\tthis.projection.setStatus(this.formatUsage());\n\t\t\t\tbreak;\n\t\t\tcase \"retry\":\n\t\t\t\tif (this.lastFailedPrompt && !this.promptInFlight) void this.submit(this.lastFailedPrompt, true);\n\t\t\t\telse this.projection.setStatus(\"nothing to retry\");\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tif (this.extensionHost?.listCommands().some((entry) => entry.name === command)) {\n\t\t\t\t\tvoid this.extensionHost.runCommand(command, args).catch((cause) => {\n\t\t\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t\t\t\tthis.refresh();\n\t\t\t\t\t});\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tthis.projection.setError(`Unknown command: /${command}`);\n\t\t\t}\n\t\t}\n\t\tthis.refresh();\n\t}\n\n\tprivate formatUsage(): string {\n\t\tconst usage = this.session.usage;\n\t\treturn `usage: requests=${usage.requestCount} input=${usage.inputTokens} output=${usage.outputTokens} total=${usage.totalTokens} cost=$${usage.cost.total.toFixed(4)} context=${usage.estimatedContextTokens}/${usage.contextWindow}`;\n\t}\n\n\tprivate async runManualCompaction(): Promise<void> {\n\t\tif (this.promptInFlight || this.compactionInFlight) {\n\t\t\tthis.projection.setError(\"Cannot compact while a prompt is running.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tthis.compactionInFlight = true;\n\t\tthis.projection.setStatus(\"starting manual compaction\");\n\t\tthis.refresh();\n\t\ttry {\n\t\t\tawait this.session.compact();\n\t\t\tthis.projection.setStatus(\"manual compaction complete\");\n\t\t} catch (cause) {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t} finally {\n\t\t\tthis.compactionInFlight = false;\n\t\t\tthis.refresh();\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"interactive.js","sourceRoot":"","sources":["../../src/modes/interactive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAEN,4BAA4B,EAE5B,MAAM,EACN,GAAG,EACH,UAAU,EAEV,UAAU,EACV,YAAY,GAGZ,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,2BAA2B,EAC3B,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,GACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAGjE,OAAO,EAAE,cAAc,EAAe,SAAS,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAEN,iCAAiC,GACjC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,MA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C;gBAAS,CAAC;YACV,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC;YAChC,IAAI,CAAC,OAAO,EAAE,CAAC;QAChB,CAAC;IACF,CAAC;CACD","sourcesContent":["import { statSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { extname, join, resolve } from \"node:path\";\nimport {\n\ttype AutocompleteProvider,\n\tCombinedAutocompleteProvider,\n\ttype Component,\n\tEditor,\n\tKey,\n\tmatchesKey,\n\ttype OverlayHandle,\n\tSelectList,\n\tSettingsList,\n\ttype SlashCommand,\n\ttype TUI,\n} from \"@di-code/tui\";\nimport {\n\tcleanupStaleClipboardImages,\n\tclipboardImageDirectory,\n\tisClipboardImagePath,\n\treadClipboardImagePath,\n\tremoveClipboardImage,\n} from \"../core/clipboard-image.ts\";\nimport { extractImageAttachments } from \"../core/image-input.ts\";\nimport type { AgentSession, AgentSessionEvent } from \"../core/session.ts\";\nimport type { ExtensionHost } from \"../extensions/runtime.ts\";\nimport { DEFAULT_LOCALE, type Locale, translate } from \"../i18n.ts\";\nimport {\n\ttype InteractiveProviderOnboardingOptions,\n\tshowInteractiveProviderOnboarding,\n} from \"../provider-onboarding.ts\";\nimport { removeGlobalProviderApiKey, saveGlobalLocale } from \"../startup.ts\";\nimport {\n\tAutocompleteMenu,\n\tInteractiveChat,\n\tInteractiveComposer,\n\tInteractiveFooter,\n\tInteractiveHeader,\n\ttype InteractiveViewState,\n} from \"./interactive-components.ts\";\nimport { InteractiveLayout } from \"./interactive-layout.ts\";\nimport { InteractiveProjection } from \"./interactive-state.ts\";\nimport { TreeSelector } from \"./tree-selector.ts\";\n\nexport type { AgentSessionEvent };\nexport type { InteractiveMessage, InteractiveProcessItem, InteractiveState } from \"./interactive-state.ts\";\nexport { InteractiveProjection } from \"./interactive-state.ts\";\n\nconst IMAGE_EXTENSIONS = new Set([\".gif\", \".jpeg\", \".jpg\", \".png\", \".webp\"]);\nconst PASTE_IMAGE_KEY = process.platform === \"win32\" ? Key.alt(\"v\") : Key.ctrl(\"v\");\nconst PASTE_IMAGE_SHORTCUT = process.platform === \"win32\" ? \"Alt+V\" : \"Ctrl+V\";\n\nfunction builtinSlashCommands(locale: Locale): readonly SlashCommand[] {\n\tconst t = (key: string) => translate(locale, key);\n\treturn [\n\t\t{ name: \"help\", description: t(\"showInteractiveCommands\") },\n\t\t{ name: \"clear\", description: t(\"clearVisibleMessages\") },\n\t\t{ name: \"model\", description: t(\"openModelSelector\") },\n\t\t{ name: \"session\", description: t(\"openSessionSelector\") },\n\t\t{ name: \"tree\", description: t(\"openTreeSelector\") },\n\t\t{ name: \"theme\", description: t(\"openThemeSelector\") },\n\t\t{ name: \"settings\", description: t(\"openSettingsSelector\") },\n\t\t{ name: \"login\", description: t(\"chooseProvider\") },\n\t\t{ name: \"logout\", description: t(\"removeProviderKey\") },\n\t\t{ name: \"compact\", description: t(\"compactContext\") },\n\t\t{ name: \"usage\", description: t(\"showUsage\") },\n\t\t{ name: \"retry\", description: t(\"retryPrompt\") },\n\t\t{ name: \"steer\", description: t(\"steerAgent\") },\n\t];\n}\n\nfunction asImageAttachmentReference(pasted: string, cwd: string): string {\n\tif (pasted.includes(\"\\n\")) return pasted;\n\tconst candidate = pasted.trim().replace(/^(?:\"([\\s\\S]*)\"|'([\\s\\S]*)')$/, \"$1$2\");\n\tif (!candidate || !IMAGE_EXTENSIONS.has(extname(candidate).toLowerCase())) return pasted;\n\ttry {\n\t\tif (!statSync(resolve(cwd, candidate)).isFile()) return pasted;\n\t} catch {\n\t\treturn pasted;\n\t}\n\treturn `@\"${candidate.replaceAll('\"', '\\\\\"')}\" `;\n}\n\nfunction normalizeDroppedImagePrompt(prompt: string, cwd: string): string {\n\tconst normalized = asImageAttachmentReference(prompt, cwd);\n\tif (normalized !== prompt) return normalized;\n\tconst prefix = /^((?:(?:[A-Za-z]:[\\\\/])|(?:\\.\\.?[\\\\/])|\\/)[\\s\\S]*?\\.(?:gif|jpe?g|png|webp))([\\s\\S]*)$/i.exec(prompt);\n\tif (!prefix) return prompt;\n\tconst imageReference = asImageAttachmentReference(prefix[1] ?? \"\", cwd);\n\treturn imageReference === prefix[1]\n\t\t? prompt\n\t\t: `${imageReference}${normalizeDroppedImagePrompt(prefix[2] ?? \"\", cwd)}`;\n}\n\nfunction steeringCommandArgument(prompt: string): string | undefined {\n\tconst match = /^\\/steer(?:\\s+([\\s\\S]*))?$/i.exec(prompt);\n\treturn match ? (match[1] ?? \"\").trim() : undefined;\n}\n\nexport interface InteractiveModeOptions {\n\treadonly session: AgentSession;\n\treadonly tui: TUI;\n\treadonly onExit?: () => void;\n\treadonly sessions?: readonly InteractiveSessionChoice[];\n\treadonly extensionHost?: ExtensionHost;\n\treadonly providerOnboarding?: Omit<InteractiveProviderOnboardingOptions, \"tui\">;\n\t/** User data directory that owns clipboard image temporaries. */\n\treadonly agentDir?: string;\n\treadonly readClipboardImagePath?: (directory?: string) => Promise<string | null>;\n\treadonly locale?: Locale;\n}\n\nexport interface InteractiveSessionChoice {\n\treadonly id: string;\n\treadonly label: string;\n\treadonly description?: string;\n\topen(): AgentSession | Promise<AgentSession>;\n}\n\nexport class InteractiveMode {\n\tprivate readonly projection = new InteractiveProjection();\n\tprivate readonly root: InteractiveLayout;\n\tprivate readonly editor: Editor;\n\tprivate session: AgentSession;\n\tprivate readonly tui: TUI;\n\tprivate readonly sessionChoices: readonly InteractiveSessionChoice[];\n\tprivate readonly extensionHost?: ExtensionHost;\n\tprivate readonly providerOnboarding?: Omit<InteractiveProviderOnboardingOptions, \"tui\">;\n\tprivate readonly agentDir: string;\n\tprivate readonly readClipboardImagePath: (directory?: string) => Promise<string | null>;\n\tprivate clipboardDirectory: string;\n\tprivate readonly clipboardFiles = new Set<string>();\n\tprivate unsubscribeSession?: () => void;\n\tprivate sessionSwitching = false;\n\tprivate promptInFlight = false;\n\tprivate compactionInFlight = false;\n\tprivate activeAbort?: AbortController;\n\tprivate started = false;\n\tprivate lastFailedPrompt?: string;\n\tprivate queuedPrompts: string[] = [];\n\tprivate steeringPrompts: string[] = [];\n\tprivate readonly onExit?: () => void;\n\tprivate theme: \"dark\" | \"light\" = \"dark\";\n\tprivate overlay?: OverlayHandle;\n\tprivate autocompleteOverlay?: OverlayHandle;\n\tprivate spinnerTimer?: ReturnType<typeof setInterval>;\n\tprivate shutdownEmitted = false;\n\tprivate preserveClipboardFiles = false;\n\tprivate locale: Locale;\n\n\tconstructor(options: InteractiveModeOptions) {\n\t\tthis.session = options.session;\n\t\tthis.projection.configureFilePreview(this.session.allowedRoot, () => this.refresh());\n\t\tthis.tui = options.tui;\n\t\tthis.onExit = options.onExit;\n\t\tthis.sessionChoices = [...(options.sessions ?? [])];\n\t\tthis.extensionHost = options.extensionHost;\n\t\tthis.providerOnboarding = options.providerOnboarding;\n\t\tthis.agentDir = resolve(options.agentDir ?? join(homedir(), \".di-code\"));\n\t\tthis.locale = options.locale ?? DEFAULT_LOCALE;\n\t\tthis.readClipboardImagePath = options.readClipboardImagePath ?? readClipboardImagePath;\n\t\tthis.clipboardDirectory = clipboardImageDirectory(this.agentDir, this.session.allowedRoot);\n\t\tconst autocomplete: AutocompleteProvider = {\n\t\t\tgetSuggestions: (context, autocompleteOptions) =>\n\t\t\t\tnew CombinedAutocompleteProvider(this.listSlashCommands(), this.session.allowedRoot).getSuggestions(\n\t\t\t\t\tcontext,\n\t\t\t\t\tautocompleteOptions,\n\t\t\t\t),\n\t\t\tapplyCompletion: (context, item, prefix) =>\n\t\t\t\tnew CombinedAutocompleteProvider(this.listSlashCommands(), this.session.allowedRoot).applyCompletion(\n\t\t\t\t\tcontext,\n\t\t\t\t\titem,\n\t\t\t\t\tprefix,\n\t\t\t\t),\n\t\t};\n\t\tthis.editor = new Editor({\n\t\t\tmaxHeight: 3,\n\t\t\tautocomplete,\n\t\t});\n\t\tthis.editor.onSubmit = (text) => void this.submit(text);\n\t\tthis.editor.onEscape = () => this.activeAbort?.abort();\n\t\tthis.editor.onCommand = (data) => this.handleCommand(data);\n\t\tthis.editor.onInterrupt = () => this.exit();\n\t\tthis.editor.onChange = () => {\n\t\t\tif (!this.preserveClipboardFiles) {\n\t\t\t\tvoid this.cleanupUnreferencedClipboardFiles().catch((cause) => {\n\t\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t\t\tthis.refresh();\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\t\tthis.editor.onAutocompleteChange = () => this.updateAutocompleteOverlay();\n\t\tconst readViewState = (): InteractiveViewState => ({\n\t\t\t...this.projection.state,\n\t\t\tmodel: `${this.session.modelId}${this.session.thinkingLevel ? `(${this.session.thinkingLevel})` : \"\"}`,\n\t\t\ttheme: this.theme,\n\t\t\tlocale: this.locale,\n\t\t\tpasteImageShortcut: PASTE_IMAGE_SHORTCUT,\n\t\t});\n\t\tthis.root = new InteractiveLayout({\n\t\t\theader: new InteractiveHeader(readViewState),\n\t\t\tchat: new InteractiveChat(readViewState),\n\t\t\tcomposer: new InteractiveComposer(readViewState),\n\t\t\teditor: this.editor,\n\t\t\tfooter: new InteractiveFooter(readViewState),\n\t\t});\n\t\tthis.tui.addChild(this.root);\n\t\tthis.tui.setFocus(this.editor);\n\t}\n\n\tstart(initialPrompt?: string): void {\n\t\tif (this.started) throw new Error(\"Interactive mode is already started\");\n\t\tthis.started = true;\n\t\tthis.shutdownEmitted = false;\n\t\tvoid this.extensionHost?.emit({ type: \"session_start\", cwd: this.session.allowedRoot });\n\t\tthis.projection.replaceTranscript(this.session.transcript);\n\t\tthis.projection.setUsage(this.session.usage);\n\t\tthis.subscribeToSession();\n\t\tvoid cleanupStaleClipboardImages(this.agentDir, this.session.allowedRoot).catch((cause) => {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\tthis.refresh();\n\t\t});\n\t\ttry {\n\t\t\tthis.tui.start();\n\t\t} catch (cause) {\n\t\t\tthis.started = false;\n\t\t\tthis.unsubscribeSession?.();\n\t\t\tthis.unsubscribeSession = undefined;\n\t\t\tthrow cause;\n\t\t}\n\t\tthis.startSpinnerTimer();\n\t\tif (initialPrompt?.trim()) void this.submit(initialPrompt);\n\t}\n\n\tstop(): void {\n\t\tif (!this.started && !this.unsubscribeSession) return;\n\t\tthis.started = false;\n\t\tthis.activeAbort?.abort();\n\t\tthis.activeAbort = undefined;\n\t\tthis.stopSpinnerTimer();\n\t\tthis.projection.clearTransientProcess();\n\t\tthis.closeOverlay();\n\t\tthis.closeAutocompleteOverlay();\n\t\tthis.unsubscribeSession?.();\n\t\tthis.unsubscribeSession = undefined;\n\t\tvoid this.cleanupClipboardFiles();\n\t\tthis.tui.stop({ finalLines: this.root.renderTranscript(this.tui.columns) });\n\t\tif (!this.shutdownEmitted) {\n\t\t\tthis.shutdownEmitted = true;\n\t\t\tvoid this.extensionHost?.emit({ type: \"session_shutdown\", reason: \"user\" });\n\t\t}\n\t}\n\n\tprivate exit(): void {\n\t\tthis.stop();\n\t\tthis.onExit?.();\n\t}\n\n\tprivate handleCommand(data: string): boolean {\n\t\tif (matchesKey(data, Key.alt(\"s\"))) {\n\t\t\tvoid this.submitSteering(this.editor.getValue());\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x1b[Z\") {\n\t\t\ttry {\n\t\t\t\tconst level = this.session.cycleThinkingLevel();\n\t\t\t\tthis.projection.setStatus(level ? `thinking=${level}` : \"Current model does not support thinking levels.\");\n\t\t\t} catch (cause) {\n\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t}\n\t\t\tthis.refresh();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x14\") {\n\t\t\tthis.openThemeSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x13\") {\n\t\t\tthis.openSettingsSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x0f\") {\n\t\t\tthis.openModelSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x0c\") {\n\t\t\tthis.openSessionSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x12\" && this.lastFailedPrompt && !this.promptInFlight) {\n\t\t\tvoid this.submit(this.lastFailedPrompt, true);\n\t\t\treturn true;\n\t\t}\n\t\tif (matchesKey(data, PASTE_IMAGE_KEY)) {\n\t\t\tvoid this.attachClipboardImage();\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tprivate async attachClipboardImage(): Promise<void> {\n\t\ttry {\n\t\t\tconst path = await this.readClipboardImagePath(this.clipboardDirectory);\n\t\t\tif (!path) {\n\t\t\t\tthis.projection.setStatus(\n\t\t\t\t\tthis.locale === \"zh-CN\" ? \"剪贴板中没有受支持的图片。\" : \"Clipboard has no supported image.\",\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthis.editor.insertTextAtCursor(path);\n\t\t\t\tif (isClipboardImagePath(path, this.clipboardDirectory)) this.clipboardFiles.add(path);\n\t\t\t}\n\t\t} catch (cause) {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t}\n\t\tthis.refresh();\n\t}\n\n\tprivate openThemeSelector(): void {\n\t\tconst t = (key: string) => translate(this.locale, key);\n\t\tconst list = new SelectList([\n\t\t\t{ value: \"dark\", label: t(\"dark\"), description: t(\"darkTheme\") },\n\t\t\t{ value: \"light\", label: t(\"light\"), description: t(\"lightTheme\") },\n\t\t]);\n\t\tlist.onSelect = (item) => {\n\t\t\tthis.theme = item.value === \"light\" ? \"light\" : \"dark\";\n\t\t\tthis.projection.setStatus(`theme=${this.theme}`);\n\t\t\tthis.closeOverlay();\n\t\t\tthis.refresh();\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate openModelSelector(): void {\n\t\tconst list = new SelectList(\n\t\t\tthis.session.availableModels.map((model) => ({\n\t\t\t\tvalue: model.id,\n\t\t\t\tlabel: model.name,\n\t\t\t\tdescription: `${model.provider} / ${model.id} / context ${model.contextWindow}`,\n\t\t\t})),\n\t\t);\n\t\tlist.onSelect = (item) => {\n\t\t\ttry {\n\t\t\t\tthis.session.setModel(item.value);\n\t\t\t\tthis.projection.setStatus(`model=${item.value}`);\n\t\t\t\tthis.closeOverlay();\n\t\t\t\tthis.refresh();\n\t\t\t} catch (cause) {\n\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t}\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate openSessionSelector(): void {\n\t\tconst t = (key: string) => translate(this.locale, key);\n\t\tconst list = new SelectList([\n\t\t\t{\n\t\t\t\tvalue: \"__current__\",\n\t\t\t\tlabel: t(\"currentSession\"),\n\t\t\t\tdescription: this.session.sessionFile ?? t(\"inMemorySession\"),\n\t\t\t},\n\t\t\t...this.sessionChoices.map((choice) => ({\n\t\t\t\tvalue: choice.id,\n\t\t\t\tlabel: choice.label,\n\t\t\t\t...(choice.description ? { description: choice.description } : {}),\n\t\t\t})),\n\t\t]);\n\t\tlist.onSelect = (item) => {\n\t\t\tif (item.value === \"__current__\") {\n\t\t\t\tthis.projection.setStatus(\"session=current\");\n\t\t\t\tthis.closeOverlay();\n\t\t\t\tthis.refresh();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst choice = this.sessionChoices.find((candidate) => candidate.id === item.value);\n\t\t\tif (!choice) return;\n\t\t\tthis.closeOverlay();\n\t\t\tvoid this.switchSession(choice);\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate openTreeSelector(): void {\n\t\tif (this.promptInFlight || this.compactionInFlight || this.sessionSwitching) {\n\t\t\tthis.projection.setError(\n\t\t\t\tthis.locale === \"zh-CN\"\n\t\t\t\t\t? \"提示词运行时不能浏览会话树。\"\n\t\t\t\t\t: \"Cannot browse the session tree while a prompt is running.\",\n\t\t\t);\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (this.session.sessionTree.length === 0) {\n\t\t\tthis.projection.setStatus(\n\t\t\t\tthis.locale === \"zh-CN\" ? \"当前会话还没有历史节点。\" : \"The current session has no history nodes.\",\n\t\t\t);\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tconst selector = new TreeSelector({\n\t\t\tnodes: this.session.sessionTree,\n\t\t\tleafId: this.session.sessionLeafId,\n\t\t\tlocale: this.locale,\n\t\t\tonContinue: (entry) => {\n\t\t\t\tthis.closeOverlay();\n\t\t\t\tvoid this.navigateTreeEntry(entry.id);\n\t\t\t},\n\t\t\tonEdit: (entry) => {\n\t\t\t\tif (entry.type !== \"message\" || entry.message.role !== \"user\") {\n\t\t\t\t\tthis.projection.setError(\n\t\t\t\t\t\tthis.locale === \"zh-CN\" ? \"只能编辑历史用户消息。\" : \"Only historical user messages can be edited.\",\n\t\t\t\t\t);\n\t\t\t\t\tthis.refresh();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.closeOverlay();\n\t\t\t\tvoid this.navigateTreeEntry(entry.id);\n\t\t\t},\n\t\t\tonSummarize: (entry) => {\n\t\t\t\tthis.closeOverlay();\n\t\t\t\tvoid this.summarizeTreeBranch(entry.id);\n\t\t\t},\n\t\t\tonCancel: () => this.closeOverlay(),\n\t\t});\n\t\tthis.showOverlay(selector, true, \"80%\");\n\t}\n\n\tprivate async navigateTreeEntry(entryId: string): Promise<boolean> {\n\t\ttry {\n\t\t\tconst result = await this.session.navigateTree(entryId);\n\t\t\tif (!this.started) return false;\n\t\t\tthis.projection.replaceTranscript(this.session.transcript);\n\t\t\tthis.editor.setValue(result.editorText ?? \"\");\n\t\t\tthis.projection.setStatus(\n\t\t\t\tresult.imagesOmitted\n\t\t\t\t\t? this.locale === \"zh-CN\"\n\t\t\t\t\t\t? \"已恢复文本;请重新附加图片。\"\n\t\t\t\t\t\t: \"Text restored; reattach images before sending.\"\n\t\t\t\t\t: `tree=${result.selectedEntryId}`,\n\t\t\t);\n\t\t\treturn true;\n\t\t} catch (cause) {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\treturn false;\n\t\t} finally {\n\t\t\tthis.refresh();\n\t\t}\n\t}\n\n\tprivate async summarizeTreeBranch(entryId: string): Promise<void> {\n\t\tif (this.compactionInFlight || this.promptInFlight) return;\n\t\tthis.compactionInFlight = true;\n\t\tthis.projection.setStatus(this.locale === \"zh-CN\" ? \"正在为分支生成摘要。\" : \"Summarizing selected branch.\");\n\t\tthis.refresh();\n\t\ttry {\n\t\t\tif (!(await this.navigateTreeEntry(entryId))) return;\n\t\t\tawait this.session.compact();\n\t\t\tthis.editor.setValue(\"\");\n\t\t\tthis.projection.replaceTranscript(this.session.transcript);\n\t\t\tthis.projection.setStatus(this.locale === \"zh-CN\" ? \"摘要分支已创建。\" : \"Summary branch created.\");\n\t\t} catch (cause) {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t} finally {\n\t\t\tthis.compactionInFlight = false;\n\t\t\tthis.refresh();\n\t\t}\n\t}\n\n\tprivate openSettingsSelector(): void {\n\t\tconst t = (key: string) => translate(this.locale, key);\n\t\tconst list = new SettingsList(\n\t\t\t[\n\t\t\t\t{\n\t\t\t\t\tid: \"compaction\",\n\t\t\t\t\tlabel: t(\"contextCompaction\"),\n\t\t\t\t\tcurrentValue: this.session.compactionEnabled ? t(\"on\") : t(\"off\"),\n\t\t\t\t\tvalues: [t(\"on\"), t(\"off\")],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: \"locale\",\n\t\t\t\t\tlabel: t(\"language\"),\n\t\t\t\t\tcurrentValue: this.locale,\n\t\t\t\t\tvalues: [\"en\", \"zh-CN\"],\n\t\t\t\t},\n\t\t\t],\n\t\t\t{ title: t(\"settings\") },\n\t\t);\n\t\tlist.onChange = (id, value) => {\n\t\t\tif (id === \"locale\") {\n\t\t\t\tthis.locale = value === \"zh-CN\" ? \"zh-CN\" : \"en\";\n\t\t\t\tvoid saveGlobalLocale(this.agentDir, this.locale).catch((cause) => {\n\t\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t\t\tthis.refresh();\n\t\t\t\t});\n\t\t\t\tthis.closeOverlay();\n\t\t\t\tthis.openSettingsSelector();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (id !== \"compaction\") return;\n\t\t\ttry {\n\t\t\t\tconst enabled = this.session.setCompactionEnabled(value === t(\"on\"));\n\t\t\t\tlist.updateValue(id, enabled ? t(\"on\") : t(\"off\"));\n\t\t\t\tthis.projection.setStatus(\n\t\t\t\t\tenabled === (value === t(\"on\")) ? `compaction=${enabled ? t(\"on\") : t(\"off\")}` : t(\"compactionUnavailable\"),\n\t\t\t\t);\n\t\t\t} catch (cause) {\n\t\t\t\tlist.updateValue(id, this.session.compactionEnabled ? t(\"on\") : t(\"off\"));\n\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t\tthis.closeOverlay();\n\t\t\t}\n\t\t\tthis.refresh();\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate showOverlay(component: Component, preserveLastLine = false, maxHeight: \"60%\" | \"80%\" = \"60%\"): void {\n\t\tthis.editor.cancelAutocomplete();\n\t\tthis.closeAutocompleteOverlay();\n\t\tthis.closeOverlay();\n\t\tthis.overlay = this.tui.showOverlay(component, {\n\t\t\twidth: \"70%\",\n\t\t\tmaxHeight,\n\t\t\tanchor: \"center\",\n\t\t\tmargin: 1,\n\t\t\tpreserveLastLine,\n\t\t});\n\t}\n\n\tprivate closeOverlay(): void {\n\t\tthis.overlay?.hide();\n\t\tthis.overlay = undefined;\n\t}\n\n\tprivate updateAutocompleteOverlay(): void {\n\t\tthis.closeAutocompleteOverlay();\n\t\tif (!this.editor.isShowingAutocomplete()) {\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tconst menu = new AutocompleteMenu(() => ({\n\t\t\titems: this.editor.getAutocompleteItems(),\n\t\t\tindex: this.editor.getAutocompleteIndex(),\n\t\t}));\n\t\tconst editorBounds = this.root.getEditorBounds(this.tui.columns);\n\t\tthis.autocompleteOverlay = this.tui.showOverlay(menu, {\n\t\t\twidth: \"55%\",\n\t\t\tmaxHeight: 9,\n\t\t\tanchor: \"bottom-left\",\n\t\t\tplacement: {\n\t\t\t\tanchorRow: editorBounds.end - 1,\n\t\t\t\tavoidStartRow: editorBounds.start,\n\t\t\t\tpreferred: \"below\",\n\t\t\t},\n\t\t\tmargin: 1,\n\t\t\tpreserveLastLine: true,\n\t\t\tnonCapturing: true,\n\t\t});\n\t\tthis.refresh();\n\t}\n\n\tprivate closeAutocompleteOverlay(): void {\n\t\tthis.autocompleteOverlay?.hide();\n\t\tthis.autocompleteOverlay = undefined;\n\t}\n\n\tprivate refresh(): void {\n\t\tthis.root.invalidate();\n\t\tthis.tui.requestRender();\n\t}\n\n\tprivate startSpinnerTimer(): void {\n\t\tthis.stopSpinnerTimer();\n\t\tthis.spinnerTimer = setInterval(() => {\n\t\t\tif (this.projection.advanceSpinner()) this.refresh();\n\t\t}, 120);\n\t\tthis.spinnerTimer.unref?.();\n\t}\n\n\tprivate stopSpinnerTimer(): void {\n\t\tif (this.spinnerTimer) clearInterval(this.spinnerTimer);\n\t\tthis.spinnerTimer = undefined;\n\t}\n\n\tprivate subscribeToSession(): void {\n\t\tthis.unsubscribeSession?.();\n\t\tthis.unsubscribeSession = this.session.subscribeSession((event) => {\n\t\t\tif (!this.started) return;\n\t\t\tif (event.type === \"tree_navigated\") {\n\t\t\t\tthis.projection.replaceTranscript(this.session.transcript);\n\t\t\t\tthis.refresh();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"queue_update\") {\n\t\t\t\tthis.steeringPrompts = [...event.steering];\n\t\t\t\tthis.refreshQueue();\n\t\t\t\tthis.refresh();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.projection.apply(event);\n\t\t\tthis.refresh();\n\t\t});\n\t}\n\n\tprivate async switchSession(choice: InteractiveSessionChoice): Promise<void> {\n\t\tif (this.promptInFlight || this.sessionSwitching) {\n\t\t\tthis.projection.setError(\n\t\t\t\tthis.locale === \"zh-CN\" ? \"提示词运行时不能切换会话。\" : \"Cannot switch sessions while a prompt is running.\",\n\t\t\t);\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tthis.sessionSwitching = true;\n\t\tthis.projection.setStatus(`opening session=${choice.id}`);\n\t\tthis.refresh();\n\t\ttry {\n\t\t\tconst next = await choice.open();\n\t\t\tif (!this.started) return;\n\t\t\tthis.unsubscribeSession?.();\n\t\t\tthis.session = next;\n\t\t\tthis.projection.configureFilePreview(next.allowedRoot, () => this.refresh());\n\t\t\tthis.clipboardDirectory = clipboardImageDirectory(this.agentDir, next.allowedRoot);\n\t\t\tvoid cleanupStaleClipboardImages(this.agentDir, next.allowedRoot);\n\t\t\tthis.queuedPrompts = [];\n\t\t\tthis.steeringPrompts = [];\n\t\t\tthis.refreshQueue();\n\t\t\tthis.projection.replaceTranscript(next.transcript);\n\t\t\tthis.projection.setUsage(next.usage);\n\t\t\tthis.projection.setStatus(`session=${choice.id}`);\n\t\t\tthis.subscribeToSession();\n\t\t} catch (cause) {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t} finally {\n\t\t\tthis.sessionSwitching = false;\n\t\t}\n\t\tthis.refresh();\n\t}\n\n\tprivate async submit(text: string, retry = false): Promise<void> {\n\t\tconst prompt = text.trim();\n\t\tif (prompt.length === 0 || !this.started) return;\n\t\tconst steeringArgument = steeringCommandArgument(prompt);\n\t\tif (steeringArgument !== undefined) {\n\t\t\tawait this.submitSteering(steeringArgument);\n\t\t\treturn;\n\t\t}\n\t\tif (prompt.startsWith(\"/\") && !this.isLoadedSkillCommand(prompt)) {\n\t\t\tthis.editor.setValue(\"\");\n\t\t\tthis.handleSlashCommand(prompt);\n\t\t\treturn;\n\t\t}\n\t\tif (this.sessionSwitching) {\n\t\t\tthis.projection.setError(\n\t\t\t\tthis.locale === \"zh-CN\"\n\t\t\t\t\t? \"会话正在打开,请等待后再提交提示词。\"\n\t\t\t\t\t: \"A session is opening; wait before submitting a prompt.\",\n\t\t\t);\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (this.compactionInFlight) {\n\t\t\tthis.projection.setError(\n\t\t\t\tthis.locale === \"zh-CN\"\n\t\t\t\t\t? \"正在压缩上下文,请等待后再提交提示词。\"\n\t\t\t\t\t: \"A compaction is running; wait before submitting a prompt.\",\n\t\t\t);\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (this.promptInFlight) {\n\t\t\tthis.queuedPrompts.push(prompt);\n\t\t\tthis.refreshQueue();\n\t\t\tthis.root.invalidate();\n\t\t\tthis.tui.requestRender();\n\t\t\treturn;\n\t\t}\n\t\tthis.promptInFlight = true;\n\t\tthis.activeAbort = new AbortController();\n\t\tthis.projection.setRetrying(retry);\n\t\ttry {\n\t\t\tconst input = await extractImageAttachments(\n\t\t\t\tnormalizeDroppedImagePrompt(prompt, this.session.allowedRoot),\n\t\t\t\tthis.session.allowedRoot,\n\t\t\t);\n\t\t\tthis.preserveClipboardFiles = true;\n\t\t\tthis.editor.setValue(\"\");\n\t\t\tconst result = await this.session.promptWithImages(input.text, input.images, this.activeAbort.signal);\n\t\t\tif (result.stopReason === \"error\" || result.stopReason === \"aborted\") this.lastFailedPrompt = prompt;\n\t\t\telse {\n\t\t\t\tthis.lastFailedPrompt = undefined;\n\t\t\t\tawait this.cleanupClipboardFiles();\n\t\t\t}\n\t\t} catch (cause) {\n\t\t\tthis.lastFailedPrompt = prompt;\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t} finally {\n\t\t\tthis.preserveClipboardFiles = false;\n\t\t\tthis.promptInFlight = false;\n\t\t\tthis.activeAbort = undefined;\n\t\t\tthis.projection.setRetrying(false);\n\t\t\tconst next = this.queuedPrompts.shift();\n\t\t\tthis.refreshQueue();\n\t\t\tthis.root.invalidate();\n\t\t\tthis.tui.requestRender();\n\t\t\tif (next && this.started) void this.submit(next);\n\t\t}\n\t}\n\n\tprivate async submitSteering(text: string): Promise<void> {\n\t\tconst prompt = text.trim();\n\t\tif (prompt.length === 0) {\n\t\t\tthis.projection.setError(this.locale === \"zh-CN\" ? \"引导内容不能为空。\" : \"Steering content must not be empty.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (this.sessionSwitching) {\n\t\t\tthis.projection.setError(\n\t\t\t\tthis.locale === \"zh-CN\"\n\t\t\t\t\t? \"会话正在打开,请等待后再引导 Agent。\"\n\t\t\t\t\t: \"A session is opening; wait before steering the agent.\",\n\t\t\t);\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (this.compactionInFlight) {\n\t\t\tthis.projection.setError(\n\t\t\t\tthis.locale === \"zh-CN\"\n\t\t\t\t\t? \"正在压缩上下文,请等待后再引导 Agent。\"\n\t\t\t\t\t: \"A compaction is running; wait before steering the agent.\",\n\t\t\t);\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (!this.promptInFlight) {\n\t\t\tthis.projection.setError(\n\t\t\t\tthis.locale === \"zh-CN\"\n\t\t\t\t\t? \"只能在提示词运行时引导 Agent。\"\n\t\t\t\t\t: \"Steering is only available while a prompt is running.\",\n\t\t\t);\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tconst input = await extractImageAttachments(\n\t\t\t\tnormalizeDroppedImagePrompt(prompt, this.session.allowedRoot),\n\t\t\t\tthis.session.allowedRoot,\n\t\t\t);\n\t\t\tawait this.session.steerWithImages(input.text, input.images);\n\t\t\tthis.editor.setValue(\"\");\n\t\t} catch (cause) {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t}\n\t\tthis.refresh();\n\t}\n\n\tprivate refreshQueue(): void {\n\t\tthis.projection.setQueue([\n\t\t\t...this.steeringPrompts.map((prompt) => `steer: ${prompt}`),\n\t\t\t...this.queuedPrompts.map((prompt) => `queued: ${prompt}`),\n\t\t]);\n\t}\n\n\tprivate async cleanupUnreferencedClipboardFiles(): Promise<void> {\n\t\tconst text = this.editor.getValue();\n\t\tconst files = [...this.clipboardFiles].filter((path) => !text.includes(path));\n\t\tawait Promise.all(files.map((path) => removeClipboardImage(path, this.clipboardDirectory)));\n\t\tfor (const path of files) this.clipboardFiles.delete(path);\n\t}\n\n\tprivate async cleanupClipboardFiles(): Promise<void> {\n\t\tconst files = [...this.clipboardFiles];\n\t\tawait Promise.all(files.map((path) => removeClipboardImage(path, this.clipboardDirectory)));\n\t\tfor (const path of files) this.clipboardFiles.delete(path);\n\t}\n\n\tprivate handleSlashCommand(input: string): void {\n\t\tconst trimmed = input.slice(1).trim();\n\t\tconst [rawCommand = \"\", ...argParts] = trimmed.split(/\\s+/);\n\t\tconst command = rawCommand.toLowerCase();\n\t\tconst args = argParts.join(\" \");\n\t\tswitch (command) {\n\t\t\tcase \"help\":\n\t\t\t\tthis.projection.setStatus(\n\t\t\t\t\t`commands: ${this.listSlashCommands()\n\t\t\t\t\t\t.map((item) => `/${item.name}`)\n\t\t\t\t\t\t.join(\" \")}`,\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase \"clear\":\n\t\t\t\tthis.projection.clearVisibleMessages();\n\t\t\t\tthis.projection.setStatus(translate(this.locale, \"visibleMessagesCleared\"));\n\t\t\t\tbreak;\n\t\t\tcase \"model\":\n\t\t\t\tthis.openModelSelector();\n\t\t\t\treturn;\n\t\t\tcase \"session\":\n\t\t\t\tthis.openSessionSelector();\n\t\t\t\treturn;\n\t\t\tcase \"tree\":\n\t\t\t\tthis.openTreeSelector();\n\t\t\t\treturn;\n\t\t\tcase \"theme\":\n\t\t\t\tthis.openThemeSelector();\n\t\t\t\treturn;\n\t\t\tcase \"settings\":\n\t\t\t\tthis.openSettingsSelector();\n\t\t\t\treturn;\n\t\t\tcase \"login\":\n\t\t\t\tthis.openProviderLogin();\n\t\t\t\treturn;\n\t\t\tcase \"logout\":\n\t\t\t\tvoid this.logoutProvider();\n\t\t\t\treturn;\n\t\t\tcase \"compact\":\n\t\t\t\tvoid this.runManualCompaction();\n\t\t\t\treturn;\n\t\t\tcase \"usage\":\n\t\t\t\tthis.projection.setStatus(this.formatUsage());\n\t\t\t\tbreak;\n\t\t\tcase \"retry\":\n\t\t\t\tif (this.lastFailedPrompt && !this.promptInFlight) void this.submit(this.lastFailedPrompt, true);\n\t\t\t\telse this.projection.setStatus(translate(this.locale, \"nothingToRetry\"));\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tif (this.extensionHost?.listCommands().some((entry) => entry.name === command)) {\n\t\t\t\t\tvoid this.extensionHost.runCommand(command, args).catch((cause) => {\n\t\t\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t\t\t\tthis.refresh();\n\t\t\t\t\t});\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tthis.projection.setError(`Unknown command: /${command}`);\n\t\t\t}\n\t\t}\n\t\tthis.refresh();\n\t}\n\n\tprivate openProviderLogin(): void {\n\t\tif (!this.providerOnboarding) {\n\t\t\tthis.projection.setError(\"Provider login is unavailable in this session.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (this.promptInFlight || this.sessionSwitching) {\n\t\t\tthis.projection.setError(\"Cannot change Provider while a prompt is running.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tthis.editor.cancelAutocomplete();\n\t\tthis.closeAutocompleteOverlay();\n\t\tvoid showInteractiveProviderOnboarding({\n\t\t\t...this.providerOnboarding,\n\t\t\tconfiguration: { ...this.providerOnboarding.configuration, locale: this.locale },\n\t\t\ttui: this.tui,\n\t\t})\n\t\t\t.then((runtime) => {\n\t\t\t\tif (!this.started) return;\n\t\t\t\tthis.tui.setFocus(this.editor);\n\t\t\t\tif (!runtime) {\n\t\t\t\t\tthis.refresh();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.session.setRuntime(runtime.provider, runtime.model);\n\t\t\t\tthis.projection.setStatus(`provider=${runtime.provider.id} model=${runtime.model.id}`);\n\t\t\t\tthis.refresh();\n\t\t\t})\n\t\t\t.catch((cause) => {\n\t\t\t\tif (this.started) this.tui.setFocus(this.editor);\n\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t\tthis.refresh();\n\t\t\t});\n\t}\n\n\tprivate async logoutProvider(): Promise<void> {\n\t\tif (!this.providerOnboarding) {\n\t\t\tthis.projection.setError(\"Provider logout is unavailable in this session.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (this.promptInFlight || this.sessionSwitching) {\n\t\t\tthis.projection.setError(\"Cannot change Provider while a prompt is running.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tconst providerId = this.session.providerId;\n\t\ttry {\n\t\t\tconst removed = await removeGlobalProviderApiKey(this.providerOnboarding.agentDir, providerId);\n\t\t\tif (!removed) {\n\t\t\t\tthis.projection.setStatus(`no global API key stored for provider=${providerId}`);\n\t\t\t\tthis.refresh();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.projection.setStatus(\n\t\t\t\t`global API key removed for provider=${providerId}; it remains active until this session ends`,\n\t\t\t);\n\t\t} catch (cause) {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t}\n\t\tthis.refresh();\n\t}\n\n\tprivate listSlashCommands(): readonly SlashCommand[] {\n\t\tconst skills = this.session.availableSkills.map((skill) => ({\n\t\t\tname: `skill:${skill.name}`,\n\t\t\tdescription: skill.description,\n\t\t}));\n\t\treturn [...builtinSlashCommands(this.locale), ...(this.extensionHost?.listCommands() ?? []), ...skills];\n\t}\n\n\tprivate isLoadedSkillCommand(input: string): boolean {\n\t\tconst name = /^\\/skill:([a-z0-9]+(?:-[a-z0-9]+)*)(?:\\s|$)/.exec(input)?.[1];\n\t\treturn name !== undefined && this.session.availableSkills.some((skill) => skill.name === name);\n\t}\n\n\tprivate formatUsage(): string {\n\t\tconst usage = this.session.usage;\n\t\tif (this.locale === \"zh-CN\") {\n\t\t\treturn `用量:请求=${usage.requestCount} 输入=${usage.inputTokens} 输出=${usage.outputTokens} 总计=${usage.totalTokens} 费用=$${usage.cost.total.toFixed(4)} 上下文=${usage.estimatedContextTokens}/${usage.contextWindow}`;\n\t\t}\n\t\treturn `usage: requests=${usage.requestCount} input=${usage.inputTokens} output=${usage.outputTokens} total=${usage.totalTokens} cost=$${usage.cost.total.toFixed(4)} context=${usage.estimatedContextTokens}/${usage.contextWindow}`;\n\t}\n\n\tprivate async runManualCompaction(): Promise<void> {\n\t\tif (this.promptInFlight || this.compactionInFlight) {\n\t\t\tthis.projection.setError(\n\t\t\t\tthis.locale === \"zh-CN\" ? \"提示词运行时不能压缩上下文。\" : \"Cannot compact while a prompt is running.\",\n\t\t\t);\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tthis.compactionInFlight = true;\n\t\tthis.projection.setStatus(translate(this.locale, \"manualCompactionStarting\"));\n\t\tthis.refresh();\n\t\ttry {\n\t\t\tawait this.session.compact();\n\t\t\tthis.projection.setStatus(translate(this.locale, \"manualCompactionComplete\"));\n\t\t} catch (cause) {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t} finally {\n\t\t\tthis.compactionInFlight = false;\n\t\t\tthis.refresh();\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import { type Component, type Focusable } from "@di-code/tui";
2
+ import type { SessionEntry, SessionTreeNode } from "../core/session/types.ts";
3
+ import { type Locale } from "../i18n.ts";
4
+ export interface TreeSelectorOptions {
5
+ readonly nodes: readonly SessionTreeNode[];
6
+ readonly leafId?: string;
7
+ readonly locale: Locale;
8
+ onContinue?(entry: SessionEntry): void;
9
+ onEdit?(entry: SessionEntry): void;
10
+ onSummarize?(entry: SessionEntry): void;
11
+ onCancel?(): void;
12
+ }
13
+ /** Compact, keyboard-driven session tree browser. It only renders and delegates all state changes to its caller. */
14
+ export declare class TreeSelector implements Component, Focusable {
15
+ focused: boolean;
16
+ private readonly options;
17
+ private readonly nodes;
18
+ private selectedIndex;
19
+ constructor(options: TreeSelectorOptions);
20
+ invalidate(): void;
21
+ render(width: number): string[];
22
+ handleInput(data: string): void;
23
+ private renderNode;
24
+ private renderPrefix;
25
+ private entryDisplay;
26
+ private actionHint;
27
+ private move;
28
+ private select;
29
+ }
30
+ //# sourceMappingURL=tree-selector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree-selector.d.ts","sourceRoot":"","sources":["../../src/modes/tree-selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAmC,MAAM,cAAc,CAAC;AAC/F,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,KAAK,MAAM,EAAa,MAAM,YAAY,CAAC;AAyBpD,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,KAAK,EAAE,SAAS,eAAe,EAAE,CAAC;IAC3C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACvC,MAAM,CAAC,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACnC,WAAW,CAAC,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,IAAI,IAAI,CAAC;CAClB;AA4FD,oHAAoH;AACpH,qBAAa,YAAa,YAAW,SAAS,EAAE,SAAS;IACxD,OAAO,UAAS;IAChB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAC9C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA0B;IAChD,OAAO,CAAC,aAAa,CAAK;gBAEd,OAAO,EAAE,mBAAmB;IAOxC,UAAU,IAAI,IAAI;IAElB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IAwB/B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAwB/B,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,IAAI;IAKZ,OAAO,CAAC,MAAM;CAOd"}
@@ -0,0 +1,205 @@
1
+ import { Key, matchesKey, SelectionPanel } from "@di-code/tui";
2
+ import { translate } from "../i18n.js";
3
+ const RESET_FOREGROUND = "\x1b[39m";
4
+ const CYAN = "\x1b[38;5;45m";
5
+ const GREEN = "\x1b[38;5;114m";
6
+ const YELLOW = "\x1b[38;5;222m";
7
+ const RED = "\x1b[38;5;210m";
8
+ const DIM = "\x1b[38;5;245m";
9
+ const MAX_VISIBLE_NODES = 12;
10
+ function paint(color, text) {
11
+ // Reset only the foreground so a selected row keeps its background across coloured fragments.
12
+ return `${color}${text}${RESET_FOREGROUND}`;
13
+ }
14
+ function singleLine(value) {
15
+ return value
16
+ .replace(/[\r\n\t]+/g, " ")
17
+ .replace(/\s+/g, " ")
18
+ .trim();
19
+ }
20
+ function textContent(entry) {
21
+ if (entry.type === "summary")
22
+ return singleLine(entry.summary);
23
+ return singleLine(entry.message.content
24
+ .filter((content) => content.type === "text")
25
+ .map((content) => content.text)
26
+ .join(" "));
27
+ }
28
+ function flattenTree(nodes, leafId) {
29
+ const parents = new Map();
30
+ const raw = [];
31
+ const stack = [];
32
+ const multipleRoots = nodes.length > 1;
33
+ for (let index = nodes.length - 1; index >= 0; index -= 1) {
34
+ const node = nodes[index];
35
+ if (!node)
36
+ continue;
37
+ stack.push({
38
+ node,
39
+ indent: multipleRoots ? 1 : 0,
40
+ justBranched: multipleRoots,
41
+ showConnector: multipleRoots,
42
+ isLast: index === nodes.length - 1,
43
+ gutters: [],
44
+ });
45
+ }
46
+ while (stack.length > 0) {
47
+ const current = stack.pop();
48
+ if (!current)
49
+ continue;
50
+ raw.push({
51
+ entry: current.node.entry,
52
+ indent: current.indent,
53
+ showConnector: current.showConnector,
54
+ isLast: current.isLast,
55
+ gutters: current.gutters,
56
+ });
57
+ const children = current.node.children;
58
+ const multipleChildren = children.length > 1;
59
+ const childIndent = multipleChildren
60
+ ? current.indent + 1
61
+ : current.justBranched && current.indent > 0
62
+ ? current.indent + 1
63
+ : current.indent;
64
+ const childGutters = current.showConnector && current.indent > 0
65
+ ? [...current.gutters, { level: current.indent - 1, continues: !current.isLast }]
66
+ : current.gutters;
67
+ for (let index = children.length - 1; index >= 0; index -= 1) {
68
+ const child = children[index];
69
+ if (!child)
70
+ continue;
71
+ parents.set(child.entry.id, current.node.entry.id);
72
+ stack.push({
73
+ node: child,
74
+ indent: childIndent,
75
+ justBranched: multipleChildren,
76
+ showConnector: multipleChildren,
77
+ isLast: index === children.length - 1,
78
+ gutters: childGutters,
79
+ });
80
+ }
81
+ }
82
+ const currentPath = new Set();
83
+ for (let current = leafId; current; current = parents.get(current))
84
+ currentPath.add(current);
85
+ return raw.map((node) => ({ ...node, isCurrentPath: currentPath.has(node.entry.id) }));
86
+ }
87
+ /** Compact, keyboard-driven session tree browser. It only renders and delegates all state changes to its caller. */
88
+ export class TreeSelector {
89
+ focused = false;
90
+ options;
91
+ nodes;
92
+ selectedIndex = 0;
93
+ constructor(options) {
94
+ this.options = options;
95
+ this.nodes = flattenTree(options.nodes, options.leafId);
96
+ const selected = this.nodes.findIndex((node) => node.entry.id === options.leafId);
97
+ if (selected >= 0)
98
+ this.selectedIndex = selected;
99
+ }
100
+ invalidate() { }
101
+ render(width) {
102
+ if (width <= 0)
103
+ return [];
104
+ if (this.nodes.length === 0)
105
+ return new SelectionPanel({ emptyText: translate(this.options.locale, "treeEmpty"), total: 0 }).render(width);
106
+ const start = Math.max(0, Math.min(this.selectedIndex - Math.floor(MAX_VISIBLE_NODES / 2), this.nodes.length - MAX_VISIBLE_NODES));
107
+ const end = Math.min(this.nodes.length, start + MAX_VISIBLE_NODES);
108
+ const rows = [];
109
+ for (let index = start; index < end; index += 1) {
110
+ const node = this.nodes[index];
111
+ if (node)
112
+ rows.push(this.renderNode(node));
113
+ }
114
+ return new SelectionPanel({
115
+ rows,
116
+ selectedIndex: this.selectedIndex - start,
117
+ position: this.selectedIndex + 1,
118
+ total: this.nodes.length,
119
+ hint: this.actionHint(),
120
+ }).render(width);
121
+ }
122
+ handleInput(data) {
123
+ if (matchesKey(data, Key.up)) {
124
+ this.move(-1);
125
+ return;
126
+ }
127
+ if (matchesKey(data, Key.down)) {
128
+ this.move(1);
129
+ return;
130
+ }
131
+ if (matchesKey(data, Key.enter)) {
132
+ this.select("continue");
133
+ return;
134
+ }
135
+ if (matchesKey(data, Key.escape) || matchesKey(data, Key.ctrl("c"))) {
136
+ this.options.onCancel?.();
137
+ return;
138
+ }
139
+ if (matchesKey(data, "e")) {
140
+ this.select("edit");
141
+ return;
142
+ }
143
+ if (matchesKey(data, "s"))
144
+ this.select("summarize");
145
+ }
146
+ renderNode(node) {
147
+ const prefix = this.renderPrefix(node);
148
+ const currentPath = node.isCurrentPath ? paint(CYAN, "• ") : " ";
149
+ const content = this.entryDisplay(node.entry);
150
+ return `${prefix}${currentPath}${content}`;
151
+ }
152
+ renderPrefix(node) {
153
+ const levels = [];
154
+ for (let level = 0; level < node.indent; level += 1) {
155
+ const gutter = node.gutters.find((candidate) => candidate.level === level);
156
+ if (gutter) {
157
+ levels.push(paint(DIM, gutter.continues ? "│ " : " "));
158
+ }
159
+ else if (node.showConnector && level === node.indent - 1) {
160
+ levels.push(paint(DIM, node.isLast ? "└─ " : "├─ "));
161
+ }
162
+ else {
163
+ levels.push(" ");
164
+ }
165
+ }
166
+ return levels.join("");
167
+ }
168
+ entryDisplay(entry) {
169
+ const text = textContent(entry);
170
+ if (entry.type === "summary")
171
+ return `${paint(YELLOW, "summary: ")}${text || paint(DIM, "(empty)")}`;
172
+ if (entry.message.role === "user")
173
+ return `${paint(CYAN, "user: ")}${text || paint(DIM, "(empty)")}`;
174
+ if (entry.message.role === "assistant") {
175
+ if (text)
176
+ return `${paint(GREEN, "assistant: ")}${text}`;
177
+ if (entry.message.stopReason === "aborted")
178
+ return `${paint(GREEN, "assistant: ")}${paint(DIM, "(aborted)")}`;
179
+ if (entry.message.stopReason === "error")
180
+ return `${paint(GREEN, "assistant: ")}${paint(RED, "(error)")}`;
181
+ return `${paint(GREEN, "assistant: ")}${paint(DIM, "(no text)")}`;
182
+ }
183
+ return `${paint(DIM, `${entry.message.toolName}: `)}${text || paint(DIM, "(no text)")}`;
184
+ }
185
+ actionHint() {
186
+ return `Enter ${translate(this.options.locale, "treeContinue")} · e ${translate(this.options.locale, "treeEdit")} · s ${translate(this.options.locale, "treeSummarize")} · Esc ${translate(this.options.locale, "treeCancel")}`;
187
+ }
188
+ move(direction) {
189
+ if (this.nodes.length === 0)
190
+ return;
191
+ this.selectedIndex = (this.selectedIndex + direction + this.nodes.length) % this.nodes.length;
192
+ }
193
+ select(action) {
194
+ const entry = this.nodes[this.selectedIndex]?.entry;
195
+ if (!entry)
196
+ return;
197
+ if (action === "continue")
198
+ this.options.onContinue?.(entry);
199
+ else if (action === "edit")
200
+ this.options.onEdit?.(entry);
201
+ else
202
+ this.options.onSummarize?.(entry);
203
+ }
204
+ }
205
+ //# sourceMappingURL=tree-selector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree-selector.js","sourceRoot":"","sources":["../../src/modes/tree-selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,GAAG,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE/F,OAAO,EAAe,SAAS,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,gBAAgB,GAAG,UAAU,CAAC;AACpC,MAAM,IAAI,GAAG,eAAe,CAAC;AAC7B,MAA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esKey, SelectionPanel } from \"@di-code/tui\";\nimport type { SessionEntry, SessionTreeNode } from \"../core/session/types.ts\";\nimport { type Locale, translate } from \"../i18n.ts\";\n\nconst RESET_FOREGROUND = \"\\x1b[39m\";\nconst CYAN = \"\\x1b[38;5;45m\";\nconst GREEN = \"\\x1b[38;5;114m\";\nconst YELLOW = \"\\x1b[38;5;222m\";\nconst RED = \"\\x1b[38;5;210m\";\nconst DIM = \"\\x1b[38;5;245m\";\nconst MAX_VISIBLE_NODES = 12;\n\ninterface FlatTreeNode {\n\treadonly entry: SessionEntry;\n\t/** Visual indentation only grows where the session graph actually branches. */\n\treadonly indent: number;\n\treadonly showConnector: boolean;\n\treadonly isLast: boolean;\n\treadonly gutters: readonly TreeGutter[];\n\treadonly isCurrentPath: boolean;\n}\n\ninterface TreeGutter {\n\treadonly level: number;\n\treadonly continues: boolean;\n}\n\nexport interface TreeSelectorOptions {\n\treadonly nodes: readonly SessionTreeNode[];\n\treadonly leafId?: string;\n\treadonly locale: Locale;\n\tonContinue?(entry: SessionEntry): void;\n\tonEdit?(entry: SessionEntry): void;\n\tonSummarize?(entry: SessionEntry): void;\n\tonCancel?(): void;\n}\n\nfunction paint(color: string, text: string): string {\n\t// Reset only the foreground so a selected row keeps its background across coloured fragments.\n\treturn `${color}${text}${RESET_FOREGROUND}`;\n}\n\nfunction singleLine(value: string): string {\n\treturn value\n\t\t.replace(/[\\r\\n\\t]+/g, \" \")\n\t\t.replace(/\\s+/g, \" \")\n\t\t.trim();\n}\n\nfunction textContent(entry: SessionEntry): string {\n\tif (entry.type === \"summary\") return singleLine(entry.summary);\n\treturn singleLine(\n\t\tentry.message.content\n\t\t\t.filter((content) => content.type === \"text\")\n\t\t\t.map((content) => content.text)\n\t\t\t.join(\" \"),\n\t);\n}\n\nfunction flattenTree(nodes: readonly SessionTreeNode[], leafId: string | undefined): FlatTreeNode[] {\n\tconst parents = new Map<string, string>();\n\tconst raw: Array<Omit<FlatTreeNode, \"isCurrentPath\">> = [];\n\ttype PendingNode = {\n\t\treadonly node: SessionTreeNode;\n\t\treadonly indent: number;\n\t\treadonly justBranched: boolean;\n\t\treadonly showConnector: boolean;\n\t\treadonly isLast: boolean;\n\t\treadonly gutters: readonly TreeGutter[];\n\t};\n\tconst stack: PendingNode[] = [];\n\tconst multipleRoots = nodes.length > 1;\n\n\tfor (let index = nodes.length - 1; index >= 0; index -= 1) {\n\t\tconst node = nodes[index];\n\t\tif (!node) continue;\n\t\tstack.push({\n\t\t\tnode,\n\t\t\tindent: multipleRoots ? 1 : 0,\n\t\t\tjustBranched: multipleRoots,\n\t\t\tshowConnector: multipleRoots,\n\t\t\tisLast: index === nodes.length - 1,\n\t\t\tgutters: [],\n\t\t});\n\t}\n\n\twhile (stack.length > 0) {\n\t\tconst current = stack.pop();\n\t\tif (!current) continue;\n\t\traw.push({\n\t\t\tentry: current.node.entry,\n\t\t\tindent: current.indent,\n\t\t\tshowConnector: current.showConnector,\n\t\t\tisLast: current.isLast,\n\t\t\tgutters: current.gutters,\n\t\t});\n\t\tconst children = current.node.children;\n\t\tconst multipleChildren = children.length > 1;\n\t\tconst childIndent = multipleChildren\n\t\t\t? current.indent + 1\n\t\t\t: current.justBranched && current.indent > 0\n\t\t\t\t? current.indent + 1\n\t\t\t\t: current.indent;\n\t\tconst childGutters =\n\t\t\tcurrent.showConnector && current.indent > 0\n\t\t\t\t? [...current.gutters, { level: current.indent - 1, continues: !current.isLast }]\n\t\t\t\t: current.gutters;\n\t\tfor (let index = children.length - 1; index >= 0; index -= 1) {\n\t\t\tconst child = children[index];\n\t\t\tif (!child) continue;\n\t\t\tparents.set(child.entry.id, current.node.entry.id);\n\t\t\tstack.push({\n\t\t\t\tnode: child,\n\t\t\t\tindent: childIndent,\n\t\t\t\tjustBranched: multipleChildren,\n\t\t\t\tshowConnector: multipleChildren,\n\t\t\t\tisLast: index === children.length - 1,\n\t\t\t\tgutters: childGutters,\n\t\t\t});\n\t\t}\n\t}\n\n\tconst currentPath = new Set<string>();\n\tfor (let current = leafId; current; current = parents.get(current)) currentPath.add(current);\n\treturn raw.map((node) => ({ ...node, isCurrentPath: currentPath.has(node.entry.id) }));\n}\n\n/** Compact, keyboard-driven session tree browser. It only renders and delegates all state changes to its caller. */\nexport class TreeSelector implements Component, Focusable {\n\tfocused = false;\n\tprivate readonly options: TreeSelectorOptions;\n\tprivate readonly nodes: readonly FlatTreeNode[];\n\tprivate selectedIndex = 0;\n\n\tconstructor(options: TreeSelectorOptions) {\n\t\tthis.options = options;\n\t\tthis.nodes = flattenTree(options.nodes, options.leafId);\n\t\tconst selected = this.nodes.findIndex((node) => node.entry.id === options.leafId);\n\t\tif (selected >= 0) this.selectedIndex = selected;\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tif (width <= 0) return [];\n\t\tif (this.nodes.length === 0)\n\t\t\treturn new SelectionPanel({ emptyText: translate(this.options.locale, \"treeEmpty\"), total: 0 }).render(width);\n\n\t\tconst start = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(MAX_VISIBLE_NODES / 2), this.nodes.length - MAX_VISIBLE_NODES),\n\t\t);\n\t\tconst end = Math.min(this.nodes.length, start + MAX_VISIBLE_NODES);\n\t\tconst rows: string[] = [];\n\t\tfor (let index = start; index < end; index += 1) {\n\t\t\tconst node = this.nodes[index];\n\t\t\tif (node) rows.push(this.renderNode(node));\n\t\t}\n\t\treturn new SelectionPanel({\n\t\t\trows,\n\t\t\tselectedIndex: this.selectedIndex - start,\n\t\t\tposition: this.selectedIndex + 1,\n\t\t\ttotal: this.nodes.length,\n\t\t\thint: this.actionHint(),\n\t\t}).render(width);\n\t}\n\n\thandleInput(data: string): void {\n\t\tif (matchesKey(data, Key.up)) {\n\t\t\tthis.move(-1);\n\t\t\treturn;\n\t\t}\n\t\tif (matchesKey(data, Key.down)) {\n\t\t\tthis.move(1);\n\t\t\treturn;\n\t\t}\n\t\tif (matchesKey(data, Key.enter)) {\n\t\t\tthis.select(\"continue\");\n\t\t\treturn;\n\t\t}\n\t\tif (matchesKey(data, Key.escape) || matchesKey(data, Key.ctrl(\"c\"))) {\n\t\t\tthis.options.onCancel?.();\n\t\t\treturn;\n\t\t}\n\t\tif (matchesKey(data, \"e\")) {\n\t\t\tthis.select(\"edit\");\n\t\t\treturn;\n\t\t}\n\t\tif (matchesKey(data, \"s\")) this.select(\"summarize\");\n\t}\n\n\tprivate renderNode(node: FlatTreeNode): string {\n\t\tconst prefix = this.renderPrefix(node);\n\t\tconst currentPath = node.isCurrentPath ? paint(CYAN, \"• \") : \" \";\n\t\tconst content = this.entryDisplay(node.entry);\n\t\treturn `${prefix}${currentPath}${content}`;\n\t}\n\n\tprivate renderPrefix(node: FlatTreeNode): string {\n\t\tconst levels: string[] = [];\n\t\tfor (let level = 0; level < node.indent; level += 1) {\n\t\t\tconst gutter = node.gutters.find((candidate) => candidate.level === level);\n\t\t\tif (gutter) {\n\t\t\t\tlevels.push(paint(DIM, gutter.continues ? \"│ \" : \" \"));\n\t\t\t} else if (node.showConnector && level === node.indent - 1) {\n\t\t\t\tlevels.push(paint(DIM, node.isLast ? \"└─ \" : \"├─ \"));\n\t\t\t} else {\n\t\t\t\tlevels.push(\" \");\n\t\t\t}\n\t\t}\n\t\treturn levels.join(\"\");\n\t}\n\n\tprivate entryDisplay(entry: SessionEntry): string {\n\t\tconst text = textContent(entry);\n\t\tif (entry.type === \"summary\") return `${paint(YELLOW, \"summary: \")}${text || paint(DIM, \"(empty)\")}`;\n\t\tif (entry.message.role === \"user\") return `${paint(CYAN, \"user: \")}${text || paint(DIM, \"(empty)\")}`;\n\t\tif (entry.message.role === \"assistant\") {\n\t\t\tif (text) return `${paint(GREEN, \"assistant: \")}${text}`;\n\t\t\tif (entry.message.stopReason === \"aborted\") return `${paint(GREEN, \"assistant: \")}${paint(DIM, \"(aborted)\")}`;\n\t\t\tif (entry.message.stopReason === \"error\") return `${paint(GREEN, \"assistant: \")}${paint(RED, \"(error)\")}`;\n\t\t\treturn `${paint(GREEN, \"assistant: \")}${paint(DIM, \"(no text)\")}`;\n\t\t}\n\t\treturn `${paint(DIM, `${entry.message.toolName}: `)}${text || paint(DIM, \"(no text)\")}`;\n\t}\n\n\tprivate actionHint(): string {\n\t\treturn `Enter ${translate(this.options.locale, \"treeContinue\")} · e ${translate(this.options.locale, \"treeEdit\")} · s ${translate(this.options.locale, \"treeSummarize\")} · Esc ${translate(this.options.locale, \"treeCancel\")}`;\n\t}\n\n\tprivate move(direction: -1 | 1): void {\n\t\tif (this.nodes.length === 0) return;\n\t\tthis.selectedIndex = (this.selectedIndex + direction + this.nodes.length) % this.nodes.length;\n\t}\n\n\tprivate select(action: \"continue\" | \"edit\" | \"summarize\"): void {\n\t\tconst entry = this.nodes[this.selectedIndex]?.entry;\n\t\tif (!entry) return;\n\t\tif (action === \"continue\") this.options.onContinue?.(entry);\n\t\telse if (action === \"edit\") this.options.onEdit?.(entry);\n\t\telse this.options.onSummarize?.(entry);\n\t}\n}\n"]}
@@ -1,6 +1,22 @@
1
1
  import { type ExtensionHost } from "../extensions/runtime.ts";
2
2
  import type { ProjectTrustManager } from "../extensions/trust.ts";
3
- import type { DiscoveredPlugin, PluginDiagnostic } from "./types.ts";
3
+ import type { DiscoveredPlugin, PluginDiagnostic, PluginDiagnosticStage } from "./types.ts";
4
+ /** A plugin loading transition emitted after its manifest is discovered. */
5
+ export type PluginLoadStatus = {
6
+ readonly state: "loading";
7
+ readonly pluginId: string;
8
+ } | {
9
+ readonly state: "loaded";
10
+ readonly pluginId: string;
11
+ readonly tools: number;
12
+ readonly commands: number;
13
+ } | {
14
+ readonly state: "failed";
15
+ readonly pluginId?: string;
16
+ readonly sourcePath: string;
17
+ readonly stage: Extract<PluginDiagnosticStage, "manifest" | "import">;
18
+ readonly message: string;
19
+ };
4
20
  export interface PluginLoadOptions {
5
21
  readonly cwd: string;
6
22
  readonly agentDir?: string;
@@ -8,6 +24,8 @@ export interface PluginLoadOptions {
8
24
  readonly trustManager?: ProjectTrustManager;
9
25
  readonly mode?: "interactive" | "print" | "json";
10
26
  readonly explicitPaths?: readonly string[];
27
+ /** Observes packaged plugin import outcomes without affecting the loader. */
28
+ readonly onPluginLoadStatus?: (status: PluginLoadStatus) => void;
11
29
  }
12
30
  export interface PluginLoadResult {
13
31
  readonly host: ExtensionHost;
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/plugins/loader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,0BAA0B,CAAC;AAC9E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAIlE,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAErE,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAClC,QAAQ,CAAC,YAAY,CAAC,EAAE,mBAAmB,CAAC;IAC5C,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,GAAG,MAAM,CAAC;IACjD,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3C;AAED,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAC7C,QAAQ,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,CAAC;CAClD;AA0BD,wBAAsB,WAAW,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAyDvF"}
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/plugins/loader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAk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