erosolar-cli 1.7.302 → 1.7.303

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 (323) hide show
  1. package/README.md +148 -24
  2. package/dist/alpha-zero/agentWrapper.d.ts +84 -0
  3. package/dist/alpha-zero/agentWrapper.d.ts.map +1 -0
  4. package/dist/alpha-zero/agentWrapper.js +171 -0
  5. package/dist/alpha-zero/agentWrapper.js.map +1 -0
  6. package/dist/alpha-zero/codeEvaluator.d.ts +25 -0
  7. package/dist/alpha-zero/codeEvaluator.d.ts.map +1 -0
  8. package/dist/alpha-zero/codeEvaluator.js +273 -0
  9. package/dist/alpha-zero/codeEvaluator.js.map +1 -0
  10. package/dist/alpha-zero/competitiveRunner.d.ts +66 -0
  11. package/dist/alpha-zero/competitiveRunner.d.ts.map +1 -0
  12. package/dist/alpha-zero/competitiveRunner.js +224 -0
  13. package/dist/alpha-zero/competitiveRunner.js.map +1 -0
  14. package/dist/alpha-zero/index.d.ts +67 -0
  15. package/dist/alpha-zero/index.d.ts.map +1 -0
  16. package/dist/alpha-zero/index.js +99 -0
  17. package/dist/alpha-zero/index.js.map +1 -0
  18. package/dist/alpha-zero/introspection.d.ts +128 -0
  19. package/dist/alpha-zero/introspection.d.ts.map +1 -0
  20. package/dist/alpha-zero/introspection.js +300 -0
  21. package/dist/alpha-zero/introspection.js.map +1 -0
  22. package/dist/alpha-zero/metricsTracker.d.ts +71 -0
  23. package/dist/alpha-zero/metricsTracker.d.ts.map +1 -0
  24. package/dist/{core → alpha-zero}/metricsTracker.js +5 -2
  25. package/dist/alpha-zero/metricsTracker.js.map +1 -0
  26. package/dist/alpha-zero/security/core.d.ts +125 -0
  27. package/dist/alpha-zero/security/core.d.ts.map +1 -0
  28. package/dist/alpha-zero/security/core.js +271 -0
  29. package/dist/alpha-zero/security/core.js.map +1 -0
  30. package/dist/alpha-zero/security/google.d.ts +125 -0
  31. package/dist/alpha-zero/security/google.d.ts.map +1 -0
  32. package/dist/alpha-zero/security/google.js +311 -0
  33. package/dist/alpha-zero/security/google.js.map +1 -0
  34. package/dist/alpha-zero/security/googleLoader.d.ts +17 -0
  35. package/dist/alpha-zero/security/googleLoader.d.ts.map +1 -0
  36. package/dist/alpha-zero/security/googleLoader.js +41 -0
  37. package/dist/alpha-zero/security/googleLoader.js.map +1 -0
  38. package/dist/alpha-zero/security/index.d.ts +29 -0
  39. package/dist/alpha-zero/security/index.d.ts.map +1 -0
  40. package/dist/alpha-zero/security/index.js +32 -0
  41. package/dist/alpha-zero/security/index.js.map +1 -0
  42. package/dist/alpha-zero/security/simulation.d.ts +124 -0
  43. package/dist/alpha-zero/security/simulation.d.ts.map +1 -0
  44. package/dist/alpha-zero/security/simulation.js +277 -0
  45. package/dist/alpha-zero/security/simulation.js.map +1 -0
  46. package/dist/alpha-zero/selfModification.d.ts +109 -0
  47. package/dist/alpha-zero/selfModification.d.ts.map +1 -0
  48. package/dist/alpha-zero/selfModification.js +233 -0
  49. package/dist/alpha-zero/selfModification.js.map +1 -0
  50. package/dist/alpha-zero/types.d.ts +170 -0
  51. package/dist/alpha-zero/types.d.ts.map +1 -0
  52. package/dist/alpha-zero/types.js +31 -0
  53. package/dist/alpha-zero/types.js.map +1 -0
  54. package/dist/bin/erosolar.js +1 -3
  55. package/dist/bin/erosolar.js.map +1 -1
  56. package/dist/capabilities/agentSpawningCapability.d.ts.map +1 -1
  57. package/dist/capabilities/agentSpawningCapability.js +31 -56
  58. package/dist/capabilities/agentSpawningCapability.js.map +1 -1
  59. package/dist/capabilities/securityTestingCapability.d.ts +13 -0
  60. package/dist/capabilities/securityTestingCapability.d.ts.map +1 -0
  61. package/dist/capabilities/securityTestingCapability.js +25 -0
  62. package/dist/capabilities/securityTestingCapability.js.map +1 -0
  63. package/dist/contracts/agent-schemas.json +15 -0
  64. package/dist/contracts/tools.schema.json +9 -0
  65. package/dist/core/agent.d.ts +2 -2
  66. package/dist/core/agent.d.ts.map +1 -1
  67. package/dist/core/agent.js.map +1 -1
  68. package/dist/core/aiFlowOptimizer.d.ts +26 -0
  69. package/dist/core/aiFlowOptimizer.d.ts.map +1 -0
  70. package/dist/core/aiFlowOptimizer.js +31 -0
  71. package/dist/core/aiFlowOptimizer.js.map +1 -0
  72. package/dist/core/aiOptimizationEngine.d.ts +158 -0
  73. package/dist/core/aiOptimizationEngine.d.ts.map +1 -0
  74. package/dist/core/aiOptimizationEngine.js +428 -0
  75. package/dist/core/aiOptimizationEngine.js.map +1 -0
  76. package/dist/core/aiOptimizationIntegration.d.ts +93 -0
  77. package/dist/core/aiOptimizationIntegration.d.ts.map +1 -0
  78. package/dist/core/aiOptimizationIntegration.js +250 -0
  79. package/dist/core/aiOptimizationIntegration.js.map +1 -0
  80. package/dist/core/customCommands.d.ts +0 -1
  81. package/dist/core/customCommands.d.ts.map +1 -1
  82. package/dist/core/customCommands.js +0 -3
  83. package/dist/core/customCommands.js.map +1 -1
  84. package/dist/core/enhancedErrorRecovery.d.ts +100 -0
  85. package/dist/core/enhancedErrorRecovery.d.ts.map +1 -0
  86. package/dist/core/enhancedErrorRecovery.js +345 -0
  87. package/dist/core/enhancedErrorRecovery.js.map +1 -0
  88. package/dist/core/hooksSystem.d.ts +65 -0
  89. package/dist/core/hooksSystem.d.ts.map +1 -0
  90. package/dist/core/hooksSystem.js +273 -0
  91. package/dist/core/hooksSystem.js.map +1 -0
  92. package/dist/core/memorySystem.d.ts +48 -0
  93. package/dist/core/memorySystem.d.ts.map +1 -0
  94. package/dist/core/memorySystem.js +271 -0
  95. package/dist/core/memorySystem.js.map +1 -0
  96. package/dist/core/toolPreconditions.d.ts.map +1 -1
  97. package/dist/core/toolPreconditions.js +14 -0
  98. package/dist/core/toolPreconditions.js.map +1 -1
  99. package/dist/core/toolRuntime.d.ts +1 -22
  100. package/dist/core/toolRuntime.d.ts.map +1 -1
  101. package/dist/core/toolRuntime.js +5 -0
  102. package/dist/core/toolRuntime.js.map +1 -1
  103. package/dist/core/toolValidation.d.ts.map +1 -1
  104. package/dist/core/toolValidation.js +3 -14
  105. package/dist/core/toolValidation.js.map +1 -1
  106. package/dist/core/unified/errors.d.ts +189 -0
  107. package/dist/core/unified/errors.d.ts.map +1 -0
  108. package/dist/core/unified/errors.js +497 -0
  109. package/dist/core/unified/errors.js.map +1 -0
  110. package/dist/core/unified/index.d.ts +19 -0
  111. package/dist/core/unified/index.d.ts.map +1 -0
  112. package/dist/core/unified/index.js +68 -0
  113. package/dist/core/unified/index.js.map +1 -0
  114. package/dist/core/unified/schema.d.ts +101 -0
  115. package/dist/core/unified/schema.d.ts.map +1 -0
  116. package/dist/core/unified/schema.js +350 -0
  117. package/dist/core/unified/schema.js.map +1 -0
  118. package/dist/core/unified/toolRuntime.d.ts +179 -0
  119. package/dist/core/unified/toolRuntime.d.ts.map +1 -0
  120. package/dist/core/unified/toolRuntime.js +517 -0
  121. package/dist/core/unified/toolRuntime.js.map +1 -0
  122. package/dist/core/unified/tools.d.ts +127 -0
  123. package/dist/core/unified/tools.d.ts.map +1 -0
  124. package/dist/core/unified/tools.js +1333 -0
  125. package/dist/core/unified/tools.js.map +1 -0
  126. package/dist/core/unified/types.d.ts +352 -0
  127. package/dist/core/unified/types.d.ts.map +1 -0
  128. package/dist/core/unified/types.js +12 -0
  129. package/dist/core/unified/types.js.map +1 -0
  130. package/dist/core/unified/version.d.ts +209 -0
  131. package/dist/core/unified/version.d.ts.map +1 -0
  132. package/dist/core/unified/version.js +454 -0
  133. package/dist/core/unified/version.js.map +1 -0
  134. package/dist/core/validationRunner.d.ts +3 -1
  135. package/dist/core/validationRunner.d.ts.map +1 -1
  136. package/dist/core/validationRunner.js.map +1 -1
  137. package/dist/headless/headlessApp.d.ts.map +1 -1
  138. package/dist/headless/headlessApp.js +0 -21
  139. package/dist/headless/headlessApp.js.map +1 -1
  140. package/dist/mcp/sseClient.d.ts.map +1 -1
  141. package/dist/mcp/sseClient.js +18 -9
  142. package/dist/mcp/sseClient.js.map +1 -1
  143. package/dist/plugins/tools/build/buildPlugin.d.ts +6 -0
  144. package/dist/plugins/tools/build/buildPlugin.d.ts.map +1 -1
  145. package/dist/plugins/tools/build/buildPlugin.js +10 -4
  146. package/dist/plugins/tools/build/buildPlugin.js.map +1 -1
  147. package/dist/plugins/tools/nodeDefaults.d.ts.map +1 -1
  148. package/dist/plugins/tools/nodeDefaults.js +2 -0
  149. package/dist/plugins/tools/nodeDefaults.js.map +1 -1
  150. package/dist/plugins/tools/security/securityPlugin.d.ts +3 -0
  151. package/dist/plugins/tools/security/securityPlugin.d.ts.map +1 -0
  152. package/dist/plugins/tools/security/securityPlugin.js +12 -0
  153. package/dist/plugins/tools/security/securityPlugin.js.map +1 -0
  154. package/dist/runtime/agentSession.d.ts +2 -2
  155. package/dist/runtime/agentSession.d.ts.map +1 -1
  156. package/dist/runtime/agentSession.js +2 -2
  157. package/dist/runtime/agentSession.js.map +1 -1
  158. package/dist/security/active-stack-security.d.ts +112 -0
  159. package/dist/security/active-stack-security.d.ts.map +1 -0
  160. package/dist/security/active-stack-security.js +296 -0
  161. package/dist/security/active-stack-security.js.map +1 -0
  162. package/dist/security/advanced-persistence-research.d.ts +92 -0
  163. package/dist/security/advanced-persistence-research.d.ts.map +1 -0
  164. package/dist/security/advanced-persistence-research.js +195 -0
  165. package/dist/security/advanced-persistence-research.js.map +1 -0
  166. package/dist/security/advanced-targeting.d.ts +119 -0
  167. package/dist/security/advanced-targeting.d.ts.map +1 -0
  168. package/dist/security/advanced-targeting.js +233 -0
  169. package/dist/security/advanced-targeting.js.map +1 -0
  170. package/dist/security/assessment/vulnerabilityAssessment.d.ts +104 -0
  171. package/dist/security/assessment/vulnerabilityAssessment.d.ts.map +1 -0
  172. package/dist/security/assessment/vulnerabilityAssessment.js +315 -0
  173. package/dist/security/assessment/vulnerabilityAssessment.js.map +1 -0
  174. package/dist/security/authorization/securityAuthorization.d.ts +88 -0
  175. package/dist/security/authorization/securityAuthorization.d.ts.map +1 -0
  176. package/dist/security/authorization/securityAuthorization.js +172 -0
  177. package/dist/security/authorization/securityAuthorization.js.map +1 -0
  178. package/dist/security/comprehensive-targeting.d.ts +85 -0
  179. package/dist/security/comprehensive-targeting.d.ts.map +1 -0
  180. package/dist/security/comprehensive-targeting.js +438 -0
  181. package/dist/security/comprehensive-targeting.js.map +1 -0
  182. package/dist/security/global-security-integration.d.ts +91 -0
  183. package/dist/security/global-security-integration.d.ts.map +1 -0
  184. package/dist/security/global-security-integration.js +218 -0
  185. package/dist/security/global-security-integration.js.map +1 -0
  186. package/dist/security/index.d.ts +38 -0
  187. package/dist/security/index.d.ts.map +1 -0
  188. package/dist/security/index.js +47 -0
  189. package/dist/security/index.js.map +1 -0
  190. package/dist/security/persistence-analyzer.d.ts +56 -0
  191. package/dist/security/persistence-analyzer.d.ts.map +1 -0
  192. package/dist/security/persistence-analyzer.js +187 -0
  193. package/dist/security/persistence-analyzer.js.map +1 -0
  194. package/dist/security/persistence-cli.d.ts +36 -0
  195. package/dist/security/persistence-cli.d.ts.map +1 -0
  196. package/dist/security/persistence-cli.js +160 -0
  197. package/dist/security/persistence-cli.js.map +1 -0
  198. package/dist/security/persistence-research.d.ts +92 -0
  199. package/dist/security/persistence-research.d.ts.map +1 -0
  200. package/dist/security/persistence-research.js +364 -0
  201. package/dist/security/persistence-research.js.map +1 -0
  202. package/dist/security/research/persistenceResearch.d.ts +97 -0
  203. package/dist/security/research/persistenceResearch.d.ts.map +1 -0
  204. package/dist/security/research/persistenceResearch.js +282 -0
  205. package/dist/security/research/persistenceResearch.js.map +1 -0
  206. package/dist/security/security-integration.d.ts +74 -0
  207. package/dist/security/security-integration.d.ts.map +1 -0
  208. package/dist/security/security-integration.js +137 -0
  209. package/dist/security/security-integration.js.map +1 -0
  210. package/dist/security/security-testing-framework.d.ts +112 -0
  211. package/dist/security/security-testing-framework.d.ts.map +1 -0
  212. package/dist/security/security-testing-framework.js +364 -0
  213. package/dist/security/security-testing-framework.js.map +1 -0
  214. package/dist/security/simulation/attackSimulation.d.ts +93 -0
  215. package/dist/security/simulation/attackSimulation.d.ts.map +1 -0
  216. package/dist/security/simulation/attackSimulation.js +341 -0
  217. package/dist/security/simulation/attackSimulation.js.map +1 -0
  218. package/dist/security/strategic-operations.d.ts +100 -0
  219. package/dist/security/strategic-operations.d.ts.map +1 -0
  220. package/dist/security/strategic-operations.js +276 -0
  221. package/dist/security/strategic-operations.js.map +1 -0
  222. package/dist/security/tool-security-wrapper.d.ts +58 -0
  223. package/dist/security/tool-security-wrapper.d.ts.map +1 -0
  224. package/dist/security/tool-security-wrapper.js +156 -0
  225. package/dist/security/tool-security-wrapper.js.map +1 -0
  226. package/dist/shell/claudeCodeStreamHandler.d.ts +145 -0
  227. package/dist/shell/claudeCodeStreamHandler.d.ts.map +1 -0
  228. package/dist/shell/claudeCodeStreamHandler.js +322 -0
  229. package/dist/shell/claudeCodeStreamHandler.js.map +1 -0
  230. package/dist/shell/inputQueueManager.d.ts +144 -0
  231. package/dist/shell/inputQueueManager.d.ts.map +1 -0
  232. package/dist/shell/inputQueueManager.js +290 -0
  233. package/dist/shell/inputQueueManager.js.map +1 -0
  234. package/dist/shell/interactiveShell.d.ts +7 -16
  235. package/dist/shell/interactiveShell.d.ts.map +1 -1
  236. package/dist/shell/interactiveShell.js +163 -223
  237. package/dist/shell/interactiveShell.js.map +1 -1
  238. package/dist/shell/metricsTracker.d.ts +60 -0
  239. package/dist/shell/metricsTracker.d.ts.map +1 -0
  240. package/dist/shell/metricsTracker.js +119 -0
  241. package/dist/shell/metricsTracker.js.map +1 -0
  242. package/dist/shell/shellApp.d.ts +0 -2
  243. package/dist/shell/shellApp.d.ts.map +1 -1
  244. package/dist/shell/shellApp.js +9 -40
  245. package/dist/shell/shellApp.js.map +1 -1
  246. package/dist/shell/streamingOutputManager.d.ts +115 -0
  247. package/dist/shell/streamingOutputManager.d.ts.map +1 -0
  248. package/dist/shell/streamingOutputManager.js +225 -0
  249. package/dist/shell/streamingOutputManager.js.map +1 -0
  250. package/dist/shell/systemPrompt.d.ts.map +1 -1
  251. package/dist/shell/systemPrompt.js +4 -1
  252. package/dist/shell/systemPrompt.js.map +1 -1
  253. package/dist/shell/terminalInput.d.ts +126 -111
  254. package/dist/shell/terminalInput.d.ts.map +1 -1
  255. package/dist/shell/terminalInput.js +639 -496
  256. package/dist/shell/terminalInput.js.map +1 -1
  257. package/dist/shell/terminalInputAdapter.d.ts +20 -47
  258. package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
  259. package/dist/shell/terminalInputAdapter.js +30 -53
  260. package/dist/shell/terminalInputAdapter.js.map +1 -1
  261. package/dist/subagents/taskRunner.d.ts +1 -7
  262. package/dist/subagents/taskRunner.d.ts.map +1 -1
  263. package/dist/subagents/taskRunner.js +47 -180
  264. package/dist/subagents/taskRunner.js.map +1 -1
  265. package/dist/tools/securityTools.d.ts +22 -0
  266. package/dist/tools/securityTools.d.ts.map +1 -0
  267. package/dist/tools/securityTools.js +448 -0
  268. package/dist/tools/securityTools.js.map +1 -0
  269. package/dist/ui/ShellUIAdapter.d.ts.map +1 -1
  270. package/dist/ui/ShellUIAdapter.js +12 -13
  271. package/dist/ui/ShellUIAdapter.js.map +1 -1
  272. package/dist/ui/display.d.ts +45 -24
  273. package/dist/ui/display.d.ts.map +1 -1
  274. package/dist/ui/display.js +259 -140
  275. package/dist/ui/display.js.map +1 -1
  276. package/dist/ui/persistentPrompt.d.ts +50 -0
  277. package/dist/ui/persistentPrompt.d.ts.map +1 -0
  278. package/dist/ui/persistentPrompt.js +92 -0
  279. package/dist/ui/persistentPrompt.js.map +1 -0
  280. package/dist/ui/terminalUISchema.d.ts +195 -0
  281. package/dist/ui/terminalUISchema.d.ts.map +1 -0
  282. package/dist/ui/terminalUISchema.js +113 -0
  283. package/dist/ui/terminalUISchema.js.map +1 -0
  284. package/dist/ui/theme.d.ts.map +1 -1
  285. package/dist/ui/theme.js +8 -6
  286. package/dist/ui/theme.js.map +1 -1
  287. package/dist/ui/toolDisplay.d.ts +158 -0
  288. package/dist/ui/toolDisplay.d.ts.map +1 -1
  289. package/dist/ui/toolDisplay.js +348 -0
  290. package/dist/ui/toolDisplay.js.map +1 -1
  291. package/dist/ui/unified/layout.d.ts +0 -1
  292. package/dist/ui/unified/layout.d.ts.map +1 -1
  293. package/dist/ui/unified/layout.js +25 -15
  294. package/dist/ui/unified/layout.js.map +1 -1
  295. package/package.json +4 -4
  296. package/scripts/deploy-security-capabilities.js +178 -0
  297. package/dist/core/hooks.d.ts +0 -113
  298. package/dist/core/hooks.d.ts.map +0 -1
  299. package/dist/core/hooks.js +0 -267
  300. package/dist/core/hooks.js.map +0 -1
  301. package/dist/core/metricsTracker.d.ts +0 -122
  302. package/dist/core/metricsTracker.d.ts.map +0 -1
  303. package/dist/core/metricsTracker.js.map +0 -1
  304. package/dist/core/securityAssessment.d.ts +0 -91
  305. package/dist/core/securityAssessment.d.ts.map +0 -1
  306. package/dist/core/securityAssessment.js +0 -580
  307. package/dist/core/securityAssessment.js.map +0 -1
  308. package/dist/core/verification.d.ts +0 -137
  309. package/dist/core/verification.d.ts.map +0 -1
  310. package/dist/core/verification.js +0 -323
  311. package/dist/core/verification.js.map +0 -1
  312. package/dist/subagents/agentConfig.d.ts +0 -27
  313. package/dist/subagents/agentConfig.d.ts.map +0 -1
  314. package/dist/subagents/agentConfig.js +0 -89
  315. package/dist/subagents/agentConfig.js.map +0 -1
  316. package/dist/subagents/agentRegistry.d.ts +0 -33
  317. package/dist/subagents/agentRegistry.d.ts.map +0 -1
  318. package/dist/subagents/agentRegistry.js +0 -162
  319. package/dist/subagents/agentRegistry.js.map +0 -1
  320. package/dist/utils/frontmatter.d.ts +0 -10
  321. package/dist/utils/frontmatter.d.ts.map +0 -1
  322. package/dist/utils/frontmatter.js +0 -78
  323. package/dist/utils/frontmatter.js.map +0 -1
@@ -3,18 +3,15 @@
3
3
  *
4
4
  * Design principles:
5
5
  * - Single source of truth for input state
6
- * - Content flows naturally from top to bottom (no scroll region pinning)
7
6
  * - Native bracketed paste support (no heuristics)
8
7
  * - Clean cursor model with render-time wrapping
9
8
  * - State machine for different input modes
10
9
  * - No readline dependency for display
11
10
  */
12
11
  import { EventEmitter } from 'node:events';
13
- import { isMultilinePaste } from '../core/multilinePasteHandler.js';
12
+ import { isMultilinePaste, generatePasteSummary } from '../core/multilinePasteHandler.js';
14
13
  import { writeLock } from '../ui/writeLock.js';
15
- import { renderDivider, renderStatusLine } from '../ui/unified/layout.js';
16
- import { isStreamingMode } from '../ui/globalWriteLock.js';
17
- import { formatThinking } from '../ui/toolDisplay.js';
14
+ import { UI_COLORS, DEFAULT_UI_CONFIG, } from '../ui/terminalUISchema.js';
18
15
  // ANSI escape codes
19
16
  const ESC = {
20
17
  // Cursor control
@@ -24,6 +21,9 @@ const ESC = {
24
21
  SHOW: '\x1b[?25h',
25
22
  TO: (row, col) => `\x1b[${row};${col}H`,
26
23
  TO_COL: (col) => `\x1b[${col}G`,
24
+ // Screen control
25
+ CLEAR_SCREEN: '\x1b[2J',
26
+ HOME: '\x1b[H',
27
27
  // Line control
28
28
  CLEAR_LINE: '\x1b[2K',
29
29
  CLEAR_TO_END: '\x1b[0J',
@@ -69,44 +69,48 @@ export class TerminalInput extends EventEmitter {
69
69
  statusMessage = null;
70
70
  overrideStatusMessage = null; // Secondary status (warnings, etc.)
71
71
  streamingLabel = null; // Streaming progress indicator
72
- metaElapsedSeconds = null; // Optional elapsed time for header line
73
- metaTokensUsed = null; // Optional token usage
74
- metaTokenLimit = null; // Optional token window
75
- metaThinkingMs = null; // Optional thinking duration
76
- metaThinkingHasContent = false; // Whether collapsed thinking content exists
77
72
  lastRenderContent = '';
78
73
  lastRenderCursor = -1;
79
74
  renderDirty = false;
80
75
  isRendering = false;
76
+ flowModeRenderedLines = 0; // Track lines rendered for clearing
77
+ inputAreaStartRow = 0; // Track absolute row position of input area
78
+ contentEndRow = 0; // Row where content ends (for idle mode positioning)
79
+ scrollRegionActive = false; // Track if scroll region is enabled for streaming
80
+ // Command suggestions (Claude Code style auto-complete)
81
+ commandSuggestions = [];
82
+ filteredSuggestions = [];
83
+ selectedSuggestionIndex = 0;
84
+ showSuggestions = false;
81
85
  // Lifecycle
82
86
  disposed = false;
83
87
  enabled = true;
84
88
  contextUsage = null;
85
- contextAutoCompactThreshold = 90;
86
- // Track current content row in scroll region (starts at top, moves down)
87
- contentRow = 1;
88
- thinkingModeLabel = null;
89
89
  editMode = 'display-edits';
90
90
  verificationEnabled = true;
91
91
  autoContinueEnabled = false;
92
92
  verificationHotkey = 'alt+v';
93
93
  autoContinueHotkey = 'alt+c';
94
- thinkingHotkey = '/thinking';
95
- modelLabel = null;
96
- providerLabel = null;
97
- // Streaming render throttle
98
- lastStreamingRender = 0;
99
- streamingRenderInterval = 250; // ms between renders during streaming
94
+ // Output interceptor cleanup
95
+ outputInterceptorCleanup;
96
+ // Metrics tracking for status bar
97
+ streamingStartTime = null;
98
+ thinkingEnabled = true;
99
+ modelInfo = null; // Provider · Model info
100
+ // Streaming input area render timer (updates elapsed time display)
100
101
  streamingRenderTimer = null;
102
+ // Unified UI initialization flag
103
+ unifiedUIInitialized = false;
101
104
  constructor(writeStream = process.stdout, config = {}) {
102
105
  super();
103
106
  this.out = writeStream;
107
+ // Use schema defaults for configuration consistency
104
108
  this.config = {
105
- maxLines: config.maxLines ?? 1000,
106
- maxLength: config.maxLength ?? 10000,
109
+ maxLines: config.maxLines ?? DEFAULT_UI_CONFIG.inputArea.maxLines,
110
+ maxLength: config.maxLength ?? DEFAULT_UI_CONFIG.inputArea.maxLength,
107
111
  maxQueueSize: config.maxQueueSize ?? 100,
108
- promptChar: config.promptChar ?? '> ',
109
- continuationChar: config.continuationChar ?? '│ ',
112
+ promptChar: config.promptChar ?? DEFAULT_UI_CONFIG.inputArea.promptChar,
113
+ continuationChar: config.continuationChar ?? DEFAULT_UI_CONFIG.inputArea.continuationChar,
110
114
  };
111
115
  }
112
116
  // ===========================================================================
@@ -185,36 +189,429 @@ export class TerminalInput extends EventEmitter {
185
189
  if (handled)
186
190
  return;
187
191
  }
192
+ // Handle '?' for help hint (if buffer is empty)
193
+ if (str === '?' && this.buffer.length === 0) {
194
+ this.emit('showHelp');
195
+ return;
196
+ }
188
197
  // Insert printable characters
189
198
  if (str && !key?.ctrl && !key?.meta) {
190
199
  this.insertText(str);
191
200
  }
192
201
  }
202
+ // Banner content to write on init (set via setBannerContent before initializeUnifiedUI)
203
+ bannerContent = null;
204
+ /**
205
+ * Set banner content to be written when unified UI initializes.
206
+ */
207
+ setBannerContent(content) {
208
+ this.bannerContent = content;
209
+ }
210
+ /**
211
+ * Initialize the unified UI system.
212
+ *
213
+ * Layout:
214
+ * 1. Clear screen
215
+ * 2. Write banner at top
216
+ * 3. Track content end position
217
+ * 4. Render floating input area below banner
218
+ */
219
+ initializeUnifiedUI() {
220
+ if (this.unifiedUIInitialized) {
221
+ return;
222
+ }
223
+ // Hide cursor during setup
224
+ this.write(ESC.HIDE);
225
+ // Clear screen and go home
226
+ this.write(ESC.HOME);
227
+ this.write(ESC.CLEAR_SCREEN);
228
+ // Write banner at top and track where it ends
229
+ let bannerLines = 0;
230
+ if (this.bannerContent) {
231
+ const lines = this.bannerContent.split('\n');
232
+ bannerLines = lines.length + 2; // +2 for the trailing \n\n
233
+ process.stdout.write(this.bannerContent + '\n\n');
234
+ }
235
+ // Set content end row so input renders right after banner
236
+ this.contentEndRow = bannerLines > 0 ? bannerLines : 1;
237
+ // Mark initialized
238
+ this.unifiedUIInitialized = true;
239
+ // Render floating input area below the banner
240
+ this.renderFloatingInputArea();
241
+ }
242
+ /**
243
+ * Clear the input area at its tracked position.
244
+ * Returns true if something was cleared.
245
+ */
246
+ clearInputArea() {
247
+ if (this.inputAreaStartRow > 0 && this.flowModeRenderedLines > 0) {
248
+ for (let i = 0; i < this.flowModeRenderedLines; i++) {
249
+ this.write(ESC.TO(this.inputAreaStartRow + i, 1));
250
+ this.write(ESC.CLEAR_LINE);
251
+ }
252
+ return true;
253
+ }
254
+ return false;
255
+ }
256
+ /**
257
+ * Reset input area tracking state.
258
+ */
259
+ resetInputAreaTracking() {
260
+ this.inputAreaStartRow = 0;
261
+ this.flowModeRenderedLines = 0;
262
+ }
263
+ /**
264
+ * Enable scroll region - content scrolls above, input area protected below.
265
+ * The scroll region ends just above where the chat box will be rendered.
266
+ */
267
+ enableScrollRegion() {
268
+ const { rows } = this.getSize();
269
+ const linesNeeded = 5 + (this.modelInfo ? 1 : 0);
270
+ // Calculate where chat box will be (floating below content)
271
+ let chatBoxStartRow;
272
+ if (this.contentEndRow > 0) {
273
+ chatBoxStartRow = Math.min(this.contentEndRow + 1, rows - linesNeeded + 1);
274
+ }
275
+ else {
276
+ // Default to terminal bottom if no content yet
277
+ chatBoxStartRow = rows - linesNeeded + 1;
278
+ }
279
+ chatBoxStartRow = Math.max(1, chatBoxStartRow);
280
+ // Scroll region ends just before the chat box
281
+ const scrollBottom = Math.max(1, chatBoxStartRow - 1);
282
+ this.write(ESC.SET_SCROLL(1, scrollBottom));
283
+ this.scrollRegionActive = true;
284
+ }
285
+ /**
286
+ * Disable scroll region - return to normal terminal mode.
287
+ */
288
+ disableScrollRegion() {
289
+ if (!this.scrollRegionActive)
290
+ return;
291
+ this.write(ESC.RESET_SCROLL);
292
+ this.scrollRegionActive = false;
293
+ }
294
+ /**
295
+ * Render input area floating below content.
296
+ * During streaming, positions based on contentEndRow (persistent bottom floating).
297
+ */
298
+ renderInputAreaAtBottom() {
299
+ const { rows, cols } = this.getSize();
300
+ const divider = '─'.repeat(cols - 1);
301
+ const { dim: DIM, reset: R } = UI_COLORS;
302
+ // Calculate lines needed
303
+ const linesNeeded = 5 + (this.modelInfo ? 1 : 0);
304
+ // Calculate starting row: float below content, but don't go past terminal bounds
305
+ let startRow;
306
+ if (this.contentEndRow > 0) {
307
+ // Float below content
308
+ startRow = this.contentEndRow + 1;
309
+ }
310
+ else {
311
+ // Default to terminal bottom if no content tracked yet
312
+ startRow = rows - linesNeeded + 1;
313
+ }
314
+ // Ensure we don't exceed terminal bounds
315
+ startRow = Math.min(startRow, rows - linesNeeded + 1);
316
+ startRow = Math.max(1, startRow);
317
+ // Save cursor and hide during render
318
+ this.write(ESC.SAVE);
319
+ this.write(ESC.HIDE);
320
+ let currentRow = startRow;
321
+ // Clear input area lines
322
+ for (let r = startRow; r <= rows; r++) {
323
+ this.write(ESC.TO(r, 1));
324
+ this.write(ESC.CLEAR_LINE);
325
+ }
326
+ // Status bar (shows streaming status)
327
+ this.write(ESC.TO(currentRow, 1));
328
+ this.write(this.buildStatusBar(cols));
329
+ currentRow++;
330
+ // Model info line (if set)
331
+ if (this.modelInfo) {
332
+ this.write(ESC.TO(currentRow, 1));
333
+ let modelLine = `${DIM}${this.modelInfo}${R}`;
334
+ if (this.contextUsage !== null) {
335
+ const rem = Math.max(0, 100 - this.contextUsage);
336
+ if (rem < 10)
337
+ modelLine += ` ${UI_COLORS.red}⚠ ctx: ${rem}%${R}`;
338
+ else if (rem < 25)
339
+ modelLine += ` ${UI_COLORS.yellow}! ctx: ${rem}%${R}`;
340
+ else
341
+ modelLine += ` ${DIM}· ctx: ${rem}%${R}`;
342
+ }
343
+ this.write(modelLine);
344
+ currentRow++;
345
+ }
346
+ // Top divider
347
+ this.write(ESC.TO(currentRow, 1));
348
+ this.write(divider);
349
+ currentRow++;
350
+ // Input line with prompt and buffer content
351
+ const { lines } = this.wrapBuffer(cols - 4);
352
+ const displayLine = lines[0] ?? '';
353
+ this.write(ESC.TO(currentRow, 1));
354
+ this.write(ESC.BG_DARK + ESC.DIM + this.config.promptChar + ESC.RESET);
355
+ this.write(ESC.BG_DARK + displayLine);
356
+ const padding = Math.max(0, cols - this.config.promptChar.length - displayLine.length - 1);
357
+ if (padding > 0)
358
+ this.write(' '.repeat(padding));
359
+ this.write(ESC.RESET);
360
+ currentRow++;
361
+ // Bottom divider
362
+ this.write(ESC.TO(currentRow, 1));
363
+ this.write(divider);
364
+ currentRow++;
365
+ // Mode controls
366
+ this.write(ESC.TO(currentRow, 1));
367
+ this.write(this.buildModeControls(cols));
368
+ // Track position
369
+ this.inputAreaStartRow = startRow;
370
+ this.flowModeRenderedLines = currentRow - startRow + 1;
371
+ // Restore cursor position (back to scroll region if streaming)
372
+ this.write(ESC.RESTORE);
373
+ this.write(ESC.SHOW);
374
+ // Update tracking
375
+ this.lastRenderContent = this.buffer;
376
+ this.lastRenderCursor = this.cursor;
377
+ }
378
+ /**
379
+ * Render floating input area below current content.
380
+ * This is "bottom floating" - follows content, not pinned to terminal bottom.
381
+ * Uses absolute positioning to prevent duplicates.
382
+ */
383
+ renderFloatingInputArea() {
384
+ const { rows, cols } = this.getSize();
385
+ const divider = '─'.repeat(cols - 1);
386
+ const { dim: DIM, reset: R } = UI_COLORS;
387
+ // Calculate lines needed for input area
388
+ const linesNeeded = 5 + (this.modelInfo ? 1 : 0);
389
+ // FIRST: Clear any previously rendered input area
390
+ this.clearInputArea();
391
+ // Hide cursor during render
392
+ this.write(ESC.HIDE);
393
+ // Calculate where to render: after current content
394
+ // Use contentEndRow if set, otherwise estimate from terminal bottom
395
+ let startRow;
396
+ if (this.contentEndRow > 0) {
397
+ startRow = this.contentEndRow + 1;
398
+ }
399
+ else {
400
+ // Render near bottom, leaving space for input area
401
+ startRow = Math.max(1, rows - linesNeeded);
402
+ }
403
+ // Ensure we don't go past terminal bounds
404
+ startRow = Math.min(startRow, rows - linesNeeded + 1);
405
+ startRow = Math.max(1, startRow);
406
+ // Track this position
407
+ this.inputAreaStartRow = startRow;
408
+ let currentRow = startRow;
409
+ // Status bar
410
+ this.write(ESC.TO(currentRow, 1));
411
+ this.write(this.buildStatusBar(cols));
412
+ currentRow++;
413
+ // Model info line (if set)
414
+ if (this.modelInfo) {
415
+ this.write(ESC.TO(currentRow, 1));
416
+ let modelLine = `${DIM}${this.modelInfo}${R}`;
417
+ if (this.contextUsage !== null) {
418
+ const rem = Math.max(0, 100 - this.contextUsage);
419
+ if (rem < 10)
420
+ modelLine += ` ${UI_COLORS.red}⚠ ctx: ${rem}%${R}`;
421
+ else if (rem < 25)
422
+ modelLine += ` ${UI_COLORS.yellow}! ctx: ${rem}%${R}`;
423
+ else
424
+ modelLine += ` ${DIM}· ctx: ${rem}%${R}`;
425
+ }
426
+ this.write(modelLine);
427
+ currentRow++;
428
+ }
429
+ // Top divider
430
+ this.write(ESC.TO(currentRow, 1));
431
+ this.write(divider);
432
+ currentRow++;
433
+ // Input line with prompt and buffer content
434
+ const { lines, cursorCol } = this.wrapBuffer(cols - 4);
435
+ const displayLine = lines[0] ?? '';
436
+ const inputRow = currentRow;
437
+ this.write(ESC.TO(currentRow, 1));
438
+ this.write(ESC.BG_DARK + ESC.DIM + this.config.promptChar + ESC.RESET);
439
+ this.write(ESC.BG_DARK + displayLine);
440
+ const padding = Math.max(0, cols - this.config.promptChar.length - displayLine.length - 1);
441
+ if (padding > 0)
442
+ this.write(' '.repeat(padding));
443
+ this.write(ESC.RESET);
444
+ currentRow++;
445
+ // Bottom divider
446
+ this.write(ESC.TO(currentRow, 1));
447
+ this.write(divider);
448
+ currentRow++;
449
+ // Mode controls
450
+ this.write(ESC.TO(currentRow, 1));
451
+ this.write(this.buildModeControls(cols));
452
+ // Track lines rendered
453
+ this.flowModeRenderedLines = currentRow - startRow + 1;
454
+ // Position cursor in input line for typing
455
+ this.write(ESC.TO(inputRow, this.config.promptChar.length + 1 + cursorCol));
456
+ // Show cursor
457
+ this.write(ESC.SHOW);
458
+ // Update tracking
459
+ this.lastRenderContent = this.buffer;
460
+ this.lastRenderCursor = this.cursor;
461
+ }
193
462
  /**
194
463
  * Set the input mode
195
464
  *
196
- * Content flows naturally - no scroll region pinning.
465
+ * During streaming: dynamic scroll region + chat box floats below content
466
+ * After streaming: chat box floats below content (no scroll region)
197
467
  */
198
468
  setMode(mode) {
199
469
  const prevMode = this.mode;
200
470
  this.mode = mode;
201
471
  if (mode === 'streaming' && prevMode !== 'streaming') {
202
- this.resetStreamingRenderThrottle();
472
+ // Track streaming start time for elapsed display
473
+ this.streamingStartTime = Date.now();
474
+ // Ensure unified UI is initialized
475
+ if (!this.unifiedUIInitialized) {
476
+ this.initializeUnifiedUI();
477
+ }
478
+ // Clear any floating input area first
479
+ this.clearInputArea();
480
+ this.resetInputAreaTracking();
481
+ // Enable scroll region - ends just before where chat box will be
482
+ this.enableScrollRegion();
483
+ // Render chat box floating below content
484
+ this.renderInputAreaAtBottom();
485
+ // Position cursor at content end (or start of scroll region) for streaming
486
+ const cursorRow = this.contentEndRow > 0 ? this.contentEndRow : 1;
487
+ this.write(ESC.TO(cursorRow, 1));
203
488
  this.renderDirty = true;
204
- this.render();
205
489
  }
206
490
  else if (mode !== 'streaming' && prevMode === 'streaming') {
207
- // Streaming ended - render the input area
208
- this.resetStreamingRenderThrottle();
209
- this.forceRender();
491
+ // Stop streaming render timer (if any)
492
+ if (this.streamingRenderTimer) {
493
+ clearInterval(this.streamingRenderTimer);
494
+ this.streamingRenderTimer = null;
495
+ }
496
+ // Reset streaming time
497
+ this.streamingStartTime = null;
498
+ // Disable scroll region
499
+ this.disableScrollRegion();
500
+ // Clear bottom input area
501
+ this.clearInputArea();
502
+ this.resetInputAreaTracking();
503
+ // Render floating input area below content
504
+ writeLock.withLock(() => {
505
+ this.renderFloatingInputArea();
506
+ }, 'terminalInput.streamingEnd');
507
+ }
508
+ }
509
+ /**
510
+ * Set the row where content ends (for idle mode positioning).
511
+ * Input area will render starting from this row + 1.
512
+ */
513
+ setContentEndRow(row) {
514
+ const prevRow = this.contentEndRow;
515
+ this.contentEndRow = Math.max(0, row);
516
+ // During streaming, dynamically adjust scroll region and chat box position
517
+ if (this.mode === 'streaming' && this.scrollRegionActive && this.contentEndRow !== prevRow) {
518
+ // Re-enable scroll region with new boundaries
519
+ this.enableScrollRegion();
520
+ // Re-render chat box at new position (floating below content)
521
+ this.renderInputAreaAtBottom();
522
+ }
523
+ else {
524
+ this.renderDirty = true;
525
+ this.scheduleRender();
526
+ }
527
+ }
528
+ /**
529
+ * Set available slash commands for auto-complete suggestions.
530
+ */
531
+ setCommands(commands) {
532
+ this.commandSuggestions = commands;
533
+ this.updateSuggestions();
534
+ }
535
+ /**
536
+ * Update filtered suggestions based on current input.
537
+ */
538
+ updateSuggestions() {
539
+ const input = this.buffer.trim();
540
+ // Only show suggestions when input starts with "/"
541
+ if (!input.startsWith('/')) {
542
+ this.showSuggestions = false;
543
+ this.filteredSuggestions = [];
544
+ this.selectedSuggestionIndex = 0;
545
+ return;
546
+ }
547
+ const query = input.toLowerCase();
548
+ this.filteredSuggestions = this.commandSuggestions.filter(cmd => cmd.command.toLowerCase().startsWith(query) ||
549
+ cmd.command.toLowerCase().includes(query.slice(1)));
550
+ // Show suggestions if we have matches
551
+ this.showSuggestions = this.filteredSuggestions.length > 0;
552
+ // Keep selection in bounds
553
+ if (this.selectedSuggestionIndex >= this.filteredSuggestions.length) {
554
+ this.selectedSuggestionIndex = Math.max(0, this.filteredSuggestions.length - 1);
210
555
  }
211
556
  }
212
557
  /**
213
- * Legacy method - no longer used (content flows naturally).
214
- * @deprecated Use setContentRow instead
558
+ * Select next suggestion (arrow down / tab).
559
+ */
560
+ selectNextSuggestion() {
561
+ if (!this.showSuggestions || this.filteredSuggestions.length === 0)
562
+ return;
563
+ this.selectedSuggestionIndex = (this.selectedSuggestionIndex + 1) % this.filteredSuggestions.length;
564
+ this.renderDirty = true;
565
+ this.scheduleRender();
566
+ }
567
+ /**
568
+ * Select previous suggestion (arrow up / shift+tab).
569
+ */
570
+ selectPrevSuggestion() {
571
+ if (!this.showSuggestions || this.filteredSuggestions.length === 0)
572
+ return;
573
+ this.selectedSuggestionIndex = this.selectedSuggestionIndex === 0
574
+ ? this.filteredSuggestions.length - 1
575
+ : this.selectedSuggestionIndex - 1;
576
+ this.renderDirty = true;
577
+ this.scheduleRender();
578
+ }
579
+ /**
580
+ * Accept current suggestion and insert into buffer.
581
+ */
582
+ acceptSuggestion() {
583
+ if (!this.showSuggestions || this.filteredSuggestions.length === 0)
584
+ return false;
585
+ const selected = this.filteredSuggestions[this.selectedSuggestionIndex];
586
+ if (!selected)
587
+ return false;
588
+ // Replace buffer with selected command
589
+ this.buffer = selected.command + ' ';
590
+ this.cursor = this.buffer.length;
591
+ this.showSuggestions = false;
592
+ this.renderDirty = true;
593
+ this.scheduleRender();
594
+ return true;
595
+ }
596
+ /**
597
+ * Check if suggestions are visible.
598
+ */
599
+ areSuggestionsVisible() {
600
+ return this.showSuggestions && this.filteredSuggestions.length > 0;
601
+ }
602
+ /**
603
+ * Toggle thinking/reasoning mode
604
+ */
605
+ toggleThinking() {
606
+ this.thinkingEnabled = !this.thinkingEnabled;
607
+ this.emit('thinkingToggle', this.thinkingEnabled);
608
+ this.scheduleRender();
609
+ }
610
+ /**
611
+ * Get thinking enabled state
215
612
  */
216
- setPinnedHeaderLines(_count) {
217
- // No-op: scroll region pinning removed
613
+ isThinkingEnabled() {
614
+ return this.thinkingEnabled;
218
615
  }
219
616
  /**
220
617
  * Get current mode
@@ -247,14 +644,17 @@ export class TerminalInput extends EventEmitter {
247
644
  }
248
645
  /**
249
646
  * Clear the buffer
647
+ * @param skipRender - If true, don't trigger a re-render (used during submit flow)
250
648
  */
251
- clear() {
649
+ clear(skipRender = false) {
252
650
  this.buffer = '';
253
651
  this.cursor = 0;
254
652
  this.historyIndex = -1;
255
653
  this.tempInput = '';
256
654
  this.pastePlaceholders = [];
257
- this.scheduleRender();
655
+ if (!skipRender) {
656
+ this.scheduleRender();
657
+ }
258
658
  }
259
659
  /**
260
660
  * Get queued inputs
@@ -325,37 +725,6 @@ export class TerminalInput extends EventEmitter {
325
725
  this.streamingLabel = next;
326
726
  this.scheduleRender();
327
727
  }
328
- /**
329
- * Surface meta status just above the divider (e.g., elapsed time or token usage).
330
- */
331
- setMetaStatus(meta) {
332
- const nextElapsed = typeof meta.elapsedSeconds === 'number' && Number.isFinite(meta.elapsedSeconds) && meta.elapsedSeconds >= 0
333
- ? Math.floor(meta.elapsedSeconds)
334
- : null;
335
- const nextTokens = typeof meta.tokensUsed === 'number' && Number.isFinite(meta.tokensUsed) && meta.tokensUsed >= 0
336
- ? Math.floor(meta.tokensUsed)
337
- : null;
338
- const nextLimit = typeof meta.tokenLimit === 'number' && Number.isFinite(meta.tokenLimit) && meta.tokenLimit > 0
339
- ? Math.floor(meta.tokenLimit)
340
- : null;
341
- const nextThinking = typeof meta.thinkingMs === 'number' && Number.isFinite(meta.thinkingMs) && meta.thinkingMs >= 0
342
- ? Math.floor(meta.thinkingMs)
343
- : null;
344
- const nextThinkingHasContent = !!meta.thinkingHasContent;
345
- if (this.metaElapsedSeconds === nextElapsed &&
346
- this.metaTokensUsed === nextTokens &&
347
- this.metaTokenLimit === nextLimit &&
348
- this.metaThinkingMs === nextThinking &&
349
- this.metaThinkingHasContent === nextThinkingHasContent) {
350
- return;
351
- }
352
- this.metaElapsedSeconds = nextElapsed;
353
- this.metaTokensUsed = nextTokens;
354
- this.metaTokenLimit = nextLimit;
355
- this.metaThinkingMs = nextThinking;
356
- this.metaThinkingHasContent = nextThinkingHasContent;
357
- this.scheduleRender();
358
- }
359
728
  /**
360
729
  * Keep mode toggles (verification/auto-continue) visible in the control bar.
361
730
  * Hotkey labels remain stable so the bar looks the same before/during streaming.
@@ -365,22 +734,26 @@ export class TerminalInput extends EventEmitter {
365
734
  const nextAutoContinue = !!options.autoContinueEnabled;
366
735
  const nextVerifyHotkey = options.verificationHotkey ?? this.verificationHotkey;
367
736
  const nextAutoHotkey = options.autoContinueHotkey ?? this.autoContinueHotkey;
368
- const nextThinkingHotkey = options.thinkingHotkey ?? this.thinkingHotkey;
369
- const nextThinkingLabel = options.thinkingModeLabel === undefined ? this.thinkingModeLabel : (options.thinkingModeLabel || null);
370
737
  if (this.verificationEnabled === nextVerification &&
371
738
  this.autoContinueEnabled === nextAutoContinue &&
372
739
  this.verificationHotkey === nextVerifyHotkey &&
373
- this.autoContinueHotkey === nextAutoHotkey &&
374
- this.thinkingHotkey === nextThinkingHotkey &&
375
- this.thinkingModeLabel === nextThinkingLabel) {
740
+ this.autoContinueHotkey === nextAutoHotkey) {
376
741
  return;
377
742
  }
378
743
  this.verificationEnabled = nextVerification;
379
744
  this.autoContinueEnabled = nextAutoContinue;
380
745
  this.verificationHotkey = nextVerifyHotkey;
381
746
  this.autoContinueHotkey = nextAutoHotkey;
382
- this.thinkingHotkey = nextThinkingHotkey;
383
- this.thinkingModeLabel = nextThinkingLabel;
747
+ this.scheduleRender();
748
+ }
749
+ /**
750
+ * Set the model info string (e.g., "OpenAI · gpt-4")
751
+ * This is displayed persistently above the input area.
752
+ */
753
+ setModelInfo(info) {
754
+ if (this.modelInfo === info)
755
+ return;
756
+ this.modelInfo = info;
384
757
  this.scheduleRender();
385
758
  }
386
759
  /**
@@ -393,154 +766,38 @@ export class TerminalInput extends EventEmitter {
393
766
  this.scheduleRender();
394
767
  }
395
768
  /**
396
- * Surface model/provider context in the controls bar.
397
- */
398
- setModelContext(options) {
399
- const nextModel = options.model?.trim() || null;
400
- const nextProvider = options.provider?.trim() || null;
401
- if (this.modelLabel === nextModel && this.providerLabel === nextProvider) {
402
- return;
403
- }
404
- this.modelLabel = nextModel;
405
- this.providerLabel = nextProvider;
406
- this.scheduleRender();
407
- }
408
- /**
409
- * Render the floating input area at contentRow.
410
- *
411
- * The chat box "floats" - it renders right below the last streamed content.
412
- * As content is added, contentRow advances, and the chat box moves down.
413
- * No scroll regions - pure floating behavior.
769
+ * Render the input area.
770
+ * During streaming: renders at terminal bottom (with scroll region)
771
+ * After streaming: renders floating below content
414
772
  */
415
773
  render() {
416
774
  if (!this.canRender())
417
775
  return;
418
776
  if (this.isRendering)
419
777
  return;
420
- const streamingActive = this.mode === 'streaming' || isStreamingMode();
421
- // During streaming, throttle re-renders
422
- if (streamingActive && this.lastStreamingRender > 0) {
423
- const elapsed = Date.now() - this.lastStreamingRender;
424
- const waitMs = Math.max(0, this.streamingRenderInterval - elapsed);
425
- if (waitMs > 0) {
426
- this.renderDirty = true;
427
- this.scheduleStreamingRender(waitMs);
428
- return;
429
- }
430
- }
431
778
  const shouldSkip = !this.renderDirty &&
432
779
  this.buffer === this.lastRenderContent &&
433
780
  this.cursor === this.lastRenderCursor;
434
781
  this.renderDirty = false;
782
+ // Skip if nothing changed (unless explicitly forced)
435
783
  if (shouldSkip) {
436
784
  return;
437
785
  }
786
+ // If write lock is held, defer render
438
787
  if (writeLock.isLocked()) {
439
788
  writeLock.safeWrite(() => this.render());
440
789
  return;
441
790
  }
442
- this.renderFloatingInputArea();
443
- }
444
- /**
445
- * Core floating input area renderer.
446
- * Chat box always floats at contentRow (below streamed content).
447
- * This creates "persistent bottom floating" behavior.
448
- */
449
- renderFloatingInputArea() {
450
- const { rows, cols } = this.getSize();
451
- const maxWidth = Math.max(8, cols - 4);
452
- const streamingActive = this.mode === 'streaming' || isStreamingMode();
453
- // Wrap buffer into display lines
454
- const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
455
- const maxVisible = Math.max(1, Math.min(this.config.maxLines, rows - 3));
456
- const displayLines = Math.min(lines.length, maxVisible);
457
- const metaLines = this.buildMetaLines(cols - 2);
458
- // Calculate display window (keep cursor visible)
459
- let startLine = 0;
460
- if (lines.length > displayLines) {
461
- startLine = Math.max(0, cursorLine - displayLines + 1);
462
- startLine = Math.min(startLine, lines.length - displayLines);
463
- }
464
- const visibleLines = lines.slice(startLine, startLine + displayLines);
465
- const adjustedCursorLine = cursorLine - startLine;
466
- // Chat box height
467
- const chatBoxHeight = metaLines.length + 1 + displayLines + 1;
468
- // Chat box floats at contentRow - right below the last content
469
- // This is "persistent bottom floating" - always at bottom of content
470
- const chatBoxStartRow = this.contentRow;
471
- writeLock.lock('terminalInput.renderFloating');
472
791
  this.isRendering = true;
792
+ writeLock.lock('terminalInput.render');
473
793
  try {
474
- // Hide cursor during render
475
- this.write(ESC.HIDE);
476
- this.write(ESC.RESET);
477
- // Clear the chat box area
478
- for (let i = 0; i < chatBoxHeight; i++) {
479
- this.write(ESC.TO(chatBoxStartRow + i, 1));
480
- this.write(ESC.CLEAR_LINE);
481
- }
482
- let currentRow = chatBoxStartRow;
483
- // Meta/status header
484
- for (const metaLine of metaLines) {
485
- this.write(ESC.TO(currentRow, 1));
486
- this.write(metaLine);
487
- currentRow += 1;
794
+ if (this.mode === 'streaming' && this.scrollRegionActive) {
795
+ // During streaming: render at bottom (protected by scroll region)
796
+ this.renderInputAreaAtBottom();
488
797
  }
489
- // Separator line
490
- this.write(ESC.TO(currentRow, 1));
491
- this.write(renderDivider(cols - 2));
492
- currentRow += 1;
493
- // Render input lines
494
- let finalRow = currentRow;
495
- let finalCol = 3;
496
- for (let i = 0; i < visibleLines.length; i++) {
497
- const rowNum = currentRow + i;
498
- this.write(ESC.TO(rowNum, 1));
499
- const line = visibleLines[i] ?? '';
500
- const isFirstLine = (startLine + i) === 0;
501
- const isCursorLine = i === adjustedCursorLine;
502
- this.write(ESC.BG_DARK);
503
- this.write(ESC.DIM);
504
- this.write(isFirstLine ? this.config.promptChar : this.config.continuationChar);
505
- this.write(ESC.RESET);
506
- this.write(ESC.BG_DARK);
507
- if (isCursorLine) {
508
- const col = Math.min(cursorCol, line.length);
509
- const before = line.slice(0, col);
510
- const at = col < line.length ? line[col] : ' ';
511
- const after = col < line.length ? line.slice(col + 1) : '';
512
- this.write(before);
513
- this.write(ESC.REVERSE + ESC.BOLD);
514
- this.write(at);
515
- this.write(ESC.RESET + ESC.BG_DARK);
516
- this.write(after);
517
- finalRow = rowNum;
518
- finalCol = this.config.promptChar.length + col + 1;
519
- }
520
- else {
521
- this.write(line);
522
- }
523
- // Pad to edge
524
- const lineLen = this.config.promptChar.length + line.length + (isCursorLine && cursorCol >= line.length ? 1 : 0);
525
- const padding = Math.max(0, cols - lineLen - 1);
526
- if (padding > 0)
527
- this.write(' '.repeat(padding));
528
- this.write(ESC.RESET);
529
- }
530
- // Mode controls line
531
- const controlRow = currentRow + visibleLines.length;
532
- this.write(ESC.TO(controlRow, 1));
533
- this.write(this.buildModeControls(cols));
534
- // Position cursor in input box
535
- this.write(ESC.TO(finalRow, Math.min(finalCol, cols)));
536
- this.write(ESC.SHOW);
537
- // Update state
538
- this.lastRenderContent = this.buffer;
539
- this.lastRenderCursor = this.cursor;
540
- this.lastStreamingRender = streamingActive ? Date.now() : 0;
541
- if (this.streamingRenderTimer) {
542
- clearTimeout(this.streamingRenderTimer);
543
- this.streamingRenderTimer = null;
798
+ else {
799
+ // Idle: render floating below content
800
+ this.renderFloatingInputArea();
544
801
  }
545
802
  }
546
803
  finally {
@@ -549,217 +806,99 @@ export class TerminalInput extends EventEmitter {
549
806
  }
550
807
  }
551
808
  /**
552
- * Build one or more compact meta lines above the divider (thinking, status, usage).
553
- * During streaming, shows model line pinned above streaming info.
809
+ * Build status bar showing streaming/ready status and key info.
810
+ * This is the TOP line above the input area - minimal Claude Code style.
554
811
  */
555
- buildMetaLines(width) {
556
- const streamingActive = this.mode === 'streaming' || isStreamingMode();
557
- const lines = [];
558
- // Model line should ALWAYS be shown (pinned above streaming content)
559
- if (this.modelLabel) {
560
- const modelText = this.providerLabel
561
- ? `model ${this.modelLabel} @ ${this.providerLabel}`
562
- : `model ${this.modelLabel}`;
563
- lines.push(renderStatusLine([{ text: modelText, tone: 'info' }], width));
564
- }
565
- // During streaming, add a compact status line with essential info
566
- if (streamingActive) {
567
- const parts = [];
568
- // Essential streaming info
569
- if (this.metaThinkingMs !== null) {
570
- parts.push({ text: formatThinking(this.metaThinkingMs, this.metaThinkingHasContent), tone: 'info' });
571
- }
572
- if (this.metaElapsedSeconds !== null) {
573
- parts.push({ text: this.formatElapsedLabel(this.metaElapsedSeconds), tone: 'muted' });
574
- }
575
- parts.push({ text: 'esc to stop', tone: 'warn' });
576
- if (parts.length) {
577
- lines.push(renderStatusLine(parts, width));
812
+ buildStatusBar(cols) {
813
+ const maxWidth = cols - 2;
814
+ const parts = [];
815
+ // Streaming status with elapsed time (left side)
816
+ if (this.mode === 'streaming') {
817
+ let statusText = '● Streaming';
818
+ if (this.streamingStartTime) {
819
+ const elapsed = Math.floor((Date.now() - this.streamingStartTime) / 1000);
820
+ const mins = Math.floor(elapsed / 60);
821
+ const secs = elapsed % 60;
822
+ statusText += mins > 0 ? ` ${mins}m ${secs}s` : ` ${secs}s`;
578
823
  }
579
- return lines;
580
- }
581
- // Non-streaming: show full status info (model line already added above)
582
- if (this.metaThinkingMs !== null) {
583
- const thinkingText = formatThinking(this.metaThinkingMs, this.metaThinkingHasContent);
584
- lines.push(renderStatusLine([{ text: thinkingText, tone: 'info' }], width));
585
- }
586
- const statusParts = [];
587
- const statusLabel = this.statusMessage ?? this.streamingLabel;
588
- if (statusLabel) {
589
- statusParts.push({ text: statusLabel, tone: 'info' });
824
+ parts.push(`\x1b[32m${statusText}\x1b[0m`); // Green
590
825
  }
591
- if (this.metaElapsedSeconds !== null) {
592
- statusParts.push({ text: this.formatElapsedLabel(this.metaElapsedSeconds), tone: 'muted' });
826
+ // Queue indicator during streaming
827
+ if (this.mode === 'streaming' && this.queue.length > 0) {
828
+ parts.push(`\x1b[36mqueued: ${this.queue.length}\x1b[0m`); // Cyan
593
829
  }
594
- const tokensRemaining = this.computeTokensRemaining();
595
- if (tokensRemaining !== null) {
596
- statusParts.push({ text: `↓ ${tokensRemaining}`, tone: 'muted' });
597
- }
598
- if (statusParts.length) {
599
- lines.push(renderStatusLine(statusParts, width));
830
+ // Paste indicator
831
+ if (this.pastePlaceholders.length > 0) {
832
+ const totalLines = this.pastePlaceholders.reduce((sum, p) => sum + p.lineCount, 0);
833
+ parts.push(`\x1b[36m📋 ${totalLines}L\x1b[0m`);
600
834
  }
601
- const usageParts = [];
602
- if (this.metaTokensUsed !== null) {
603
- const formattedUsed = this.formatTokenCount(this.metaTokensUsed);
604
- const formattedLimit = this.metaTokenLimit ? `/${this.formatTokenCount(this.metaTokenLimit)}` : '';
605
- usageParts.push({ text: `tokens ${formattedUsed}${formattedLimit}`, tone: 'muted' });
835
+ // Override/warning status
836
+ if (this.overrideStatusMessage) {
837
+ parts.push(`\x1b[33m⚠ ${this.overrideStatusMessage}\x1b[0m`); // Yellow
606
838
  }
607
- if (this.contextUsage !== null) {
608
- const tone = this.contextUsage >= 75 ? 'warn' : 'muted';
609
- const left = Math.max(0, 100 - this.contextUsage);
610
- usageParts.push({ text: `context used ${this.contextUsage}% (${left}% left)`, tone });
839
+ // If idle with empty buffer, show quick shortcuts
840
+ if (this.mode !== 'streaming' && this.buffer.length === 0 && parts.length === 0) {
841
+ return `${ESC.DIM}Type a message or / for commands${ESC.RESET}`;
611
842
  }
612
- if (this.queue.length > 0) {
613
- usageParts.push({ text: `queued ${this.queue.length}`, tone: 'info' });
843
+ // Multi-line indicator
844
+ if (this.buffer.includes('\n')) {
845
+ parts.push(`${ESC.DIM}${this.buffer.split('\n').length}L${ESC.RESET}`);
614
846
  }
615
- if (usageParts.length) {
616
- lines.push(renderStatusLine(usageParts, width));
847
+ if (parts.length === 0) {
848
+ return ''; // Empty status bar when idle
617
849
  }
618
- return lines;
850
+ const joined = parts.join(`${ESC.DIM} · ${ESC.RESET}`);
851
+ return joined.slice(0, maxWidth);
619
852
  }
620
853
  /**
621
- * Build Claude Code style mode controls line.
622
- * Combines streaming label + override status + main status for simultaneous display.
854
+ * Build mode controls line showing toggles and context info.
855
+ * This is the BOTTOM line below the input area - Claude Code style layout with erosolar features.
856
+ *
857
+ * Layout: [toggles on left] ... [context info on right]
623
858
  */
624
859
  buildModeControls(cols) {
625
- const width = Math.max(8, cols - 2);
626
- const leftParts = [];
627
- const rightParts = [];
628
- if (this.streamingLabel) {
629
- leftParts.push({ text: `◐ ${this.streamingLabel}`, tone: 'info' });
630
- }
631
- if (this.overrideStatusMessage) {
632
- leftParts.push({ text: `⚠ ${this.overrideStatusMessage}`, tone: 'warn' });
633
- }
634
- if (this.statusMessage) {
635
- leftParts.push({ text: this.statusMessage, tone: this.streamingLabel ? 'muted' : 'info' });
636
- }
637
- const editHotkey = this.formatHotkey('shift+tab');
638
- const editLabel = this.editMode === 'display-edits' ? 'edits: accept' : 'edits: ask';
639
- const editTone = this.editMode === 'display-edits' ? 'success' : 'muted';
640
- leftParts.push({ text: `${editHotkey} ${editLabel}`, tone: editTone });
641
- const verifyHotkey = this.formatHotkey(this.verificationHotkey);
642
- const verifyLabel = this.verificationEnabled ? 'verify:on' : 'verify:off';
643
- leftParts.push({ text: `${verifyHotkey} ${verifyLabel}`, tone: this.verificationEnabled ? 'success' : 'muted' });
644
- const continueHotkey = this.formatHotkey(this.autoContinueHotkey);
645
- const continueLabel = this.autoContinueEnabled ? 'auto:on' : 'auto:off';
646
- leftParts.push({ text: `${continueHotkey} ${continueLabel}`, tone: this.autoContinueEnabled ? 'info' : 'muted' });
647
- if (this.queue.length > 0 && this.mode !== 'streaming') {
648
- leftParts.push({ text: `queued ${this.queue.length}`, tone: 'info' });
649
- }
650
- if (this.buffer.includes('\n')) {
651
- const lineCount = this.buffer.split('\n').length;
652
- leftParts.push({ text: `${lineCount} lines`, tone: 'muted' });
653
- }
654
- if (this.pastePlaceholders.length > 0) {
655
- const latest = this.pastePlaceholders[this.pastePlaceholders.length - 1];
656
- leftParts.push({
657
- text: `paste #${latest.id} +${latest.lineCount} lines (⌫ to drop)`,
658
- tone: 'info',
659
- });
660
- }
661
- const contextRemaining = this.computeContextRemaining();
662
- if (this.thinkingModeLabel) {
663
- const thinkingHotkey = this.formatHotkey(this.thinkingHotkey);
664
- rightParts.push({ text: `${thinkingHotkey} thinking:${this.thinkingModeLabel}`, tone: 'info' });
665
- }
666
- // Show model in controls only when NOT streaming (during streaming it's in meta lines)
667
- const streamingActive = this.mode === 'streaming' || isStreamingMode();
668
- if (this.modelLabel && !streamingActive) {
669
- const modelText = this.providerLabel ? `${this.modelLabel} @ ${this.providerLabel}` : this.modelLabel;
670
- rightParts.push({ text: modelText, tone: 'muted' });
671
- }
672
- if (contextRemaining !== null) {
673
- const tone = contextRemaining <= 10 ? 'warn' : 'muted';
674
- const label = contextRemaining === 0 && this.contextUsage !== null
675
- ? 'Context auto-compact imminent'
676
- : `Context left until auto-compact: ${contextRemaining}%`;
677
- rightParts.push({ text: label, tone });
678
- }
679
- if (!rightParts.length || width < 60) {
680
- const merged = rightParts.length ? [...leftParts, ...rightParts] : leftParts;
681
- return renderStatusLine(merged, width);
682
- }
683
- const leftWidth = Math.max(12, Math.floor(width * 0.6));
684
- const rightWidth = Math.max(14, width - leftWidth - 1);
685
- const leftText = renderStatusLine(leftParts, leftWidth);
686
- const rightText = renderStatusLine(rightParts, rightWidth);
687
- const spacing = Math.max(1, width - this.visibleLength(leftText) - this.visibleLength(rightText));
688
- return `${leftText}${' '.repeat(spacing)}${rightText}`;
689
- }
690
- formatHotkey(hotkey) {
691
- const normalized = hotkey.trim().toLowerCase();
692
- if (!normalized)
693
- return hotkey;
694
- const parts = normalized.split('+').filter(Boolean);
695
- const map = {
696
- shift: '⇧',
697
- sh: '⇧',
698
- alt: '⌥',
699
- option: '⌥',
700
- opt: '⌥',
701
- ctrl: '⌃',
702
- control: '⌃',
703
- cmd: '⌘',
704
- meta: '⌘',
705
- };
706
- const formatted = parts
707
- .map((part) => {
708
- const symbol = map[part];
709
- if (symbol)
710
- return symbol;
711
- return part.length === 1 ? part.toUpperCase() : part.toUpperCase();
712
- })
713
- .join('');
714
- return formatted || hotkey;
715
- }
716
- computeContextRemaining() {
717
- if (this.contextUsage === null) {
718
- return null;
719
- }
720
- return Math.max(0, this.contextAutoCompactThreshold - this.contextUsage);
721
- }
722
- computeTokensRemaining() {
723
- if (this.metaTokensUsed === null || this.metaTokenLimit === null) {
724
- return null;
725
- }
726
- const remaining = Math.max(0, this.metaTokenLimit - this.metaTokensUsed);
727
- return this.formatTokenCount(remaining);
728
- }
729
- formatElapsedLabel(seconds) {
730
- if (seconds < 60) {
731
- return `${seconds}s`;
732
- }
733
- const mins = Math.floor(seconds / 60);
734
- const secs = seconds % 60;
735
- return secs > 0 ? `${mins}m ${secs}s` : `${mins}m`;
736
- }
737
- formatTokenCount(value) {
738
- if (!Number.isFinite(value)) {
739
- return `${value}`;
740
- }
741
- if (value >= 1_000_000) {
742
- return `${(value / 1_000_000).toFixed(1)}M`;
860
+ const maxWidth = cols - 2;
861
+ // Use schema-defined colors for consistency
862
+ const { green: GREEN, yellow: YELLOW, cyan: CYAN, magenta: MAGENTA, red: RED, dim: DIM, reset: R } = UI_COLORS;
863
+ // Mode toggles with colors (following ModeControlsSchema)
864
+ const toggles = [];
865
+ // Edit mode (green=auto, yellow=ask) - per schema.editMode
866
+ if (this.editMode === 'display-edits') {
867
+ toggles.push(`${GREEN}⏵⏵ auto-edit${R}`);
743
868
  }
744
- if (value >= 1_000) {
745
- return `${(value / 1_000).toFixed(1)}k`;
746
- }
747
- return `${Math.round(value)}`;
748
- }
749
- visibleLength(value) {
750
- const ansiPattern = /\u001B\[[0-?]*[ -/]*[@-~]/g;
751
- return value.replace(ansiPattern, '').length;
752
- }
753
- /**
754
- * Debug-only snapshot used by tests to assert rendered strings without
755
- * needing a TTY. Not used by production code.
756
- */
757
- getDebugUiSnapshot(width) {
758
- const cols = Math.max(8, width ?? this.getSize().cols);
759
- return {
760
- meta: this.buildMetaLines(cols - 2),
761
- controls: this.buildModeControls(cols),
762
- };
869
+ else {
870
+ toggles.push(`${YELLOW}⏸⏸ ask-first${R}`);
871
+ }
872
+ // Thinking mode (cyan when on) - per schema.thinkingMode
873
+ toggles.push(this.thinkingEnabled ? `${CYAN}💭 think${R}` : `${DIM}○ think${R}`);
874
+ // Verification (green when on) - per schema.verificationMode
875
+ toggles.push(this.verificationEnabled ? `${GREEN}✓ verify${R}` : `${DIM}○ verify${R}`);
876
+ // Auto-continue (magenta when on) - per schema.autoContinueMode
877
+ toggles.push(this.autoContinueEnabled ? `${MAGENTA}↻ auto${R}` : `${DIM}○ auto${R}`);
878
+ const leftPart = toggles.join(`${DIM} · ${R}`) + `${DIM} (⇧⇥)${R}`;
879
+ // Context usage with color - per schema.contextUsage thresholds
880
+ let rightPart = '';
881
+ if (this.contextUsage !== null) {
882
+ const rem = Math.max(0, 100 - this.contextUsage);
883
+ // Thresholds: critical < 10%, warning < 25%
884
+ if (rem < 10)
885
+ rightPart = `${RED}⚠ ctx: ${rem}%${R}`;
886
+ else if (rem < 25)
887
+ rightPart = `${YELLOW}! ctx: ${rem}%${R}`;
888
+ else
889
+ rightPart = `${DIM}ctx: ${rem}%${R}`;
890
+ }
891
+ // Calculate visible lengths (strip ANSI)
892
+ const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
893
+ const leftLen = strip(leftPart).length;
894
+ const rightLen = strip(rightPart).length;
895
+ if (leftLen + rightLen < maxWidth - 4) {
896
+ return `${leftPart}${' '.repeat(maxWidth - leftLen - rightLen)}${rightPart}`;
897
+ }
898
+ if (rightLen > 0 && leftLen + 8 < maxWidth) {
899
+ return `${leftPart} ${rightPart}`;
900
+ }
901
+ return leftPart;
763
902
  }
764
903
  /**
765
904
  * Force a re-render
@@ -782,65 +921,20 @@ export class TerminalInput extends EventEmitter {
782
921
  handleResize() {
783
922
  this.lastRenderContent = '';
784
923
  this.lastRenderCursor = -1;
785
- this.resetStreamingRenderThrottle();
786
924
  this.scheduleRender();
787
925
  }
788
926
  /**
789
- * Stream content above the floating chat box.
790
- *
791
- * This is the CLEAN method for streaming - no output interceptor needed.
792
- * 1. Position cursor at contentRow
793
- * 2. Write content directly (overwrites any chat box visually)
794
- * 3. Advance contentRow by newlines
795
- * 4. Re-render chat box at new position
796
- *
797
- * The chat box always re-renders after content, so it appears to "float" below.
798
- */
799
- streamContent(content) {
800
- if (!content)
801
- return;
802
- // Position cursor at contentRow and write content
803
- this.write(ESC.TO(this.contentRow, 1));
804
- this.write(content);
805
- // Advance contentRow by number of newlines
806
- const newlines = (content.match(/\n/g) || []).length;
807
- this.contentRow += newlines;
808
- // Re-render chat box at new position (below the content just written)
809
- this.forceRender();
810
- }
811
- /**
812
- * @deprecated Use streamContent() instead
813
- * Register with display's output interceptor - kept for backwards compatibility
814
- */
815
- registerOutputInterceptor(_display) {
816
- // No-op: Use streamContent() for cleaner floating chat box behavior
817
- }
818
- /**
819
- * @deprecated Use streamContent() instead
820
- * Write content above the floating chat box.
927
+ * Register with display's output interceptor (kept for API compatibility).
928
+ * With unified floating input, no special cursor manipulation is needed.
821
929
  */
822
- writeToScrollRegion(content) {
823
- this.streamContent(content);
824
- }
825
- /**
826
- * Reset content position to row 1.
827
- * Does NOT clear the terminal - content starts from current position.
828
- */
829
- resetContentPosition() {
830
- this.contentRow = 1;
831
- }
832
- /**
833
- * Set the content row explicitly (used after banner is written).
834
- * This tells the input where content should start flowing from.
835
- */
836
- setContentRow(row) {
837
- this.contentRow = Math.max(1, row);
838
- }
839
- /**
840
- * Get the current content row position.
841
- */
842
- getContentRow() {
843
- return this.contentRow;
930
+ registerOutputInterceptor(display) {
931
+ if (this.outputInterceptorCleanup) {
932
+ this.outputInterceptorCleanup();
933
+ }
934
+ this.outputInterceptorCleanup = display.registerOutputInterceptor({
935
+ beforeWrite: () => { },
936
+ afterWrite: () => { },
937
+ });
844
938
  }
845
939
  /**
846
940
  * Dispose and clean up
@@ -848,9 +942,18 @@ export class TerminalInput extends EventEmitter {
848
942
  dispose() {
849
943
  if (this.disposed)
850
944
  return;
945
+ // Clean up streaming render timer
946
+ if (this.streamingRenderTimer) {
947
+ clearInterval(this.streamingRenderTimer);
948
+ this.streamingRenderTimer = null;
949
+ }
950
+ // Clean up output interceptor
951
+ if (this.outputInterceptorCleanup) {
952
+ this.outputInterceptorCleanup();
953
+ this.outputInterceptorCleanup = undefined;
954
+ }
851
955
  this.disposed = true;
852
956
  this.enabled = false;
853
- this.resetStreamingRenderThrottle();
854
957
  this.disableBracketedPaste();
855
958
  this.buffer = '';
856
959
  this.queue = [];
@@ -955,7 +1058,22 @@ export class TerminalInput extends EventEmitter {
955
1058
  this.toggleEditMode();
956
1059
  return true;
957
1060
  }
958
- this.insertText(' ');
1061
+ // Tab: toggle paste expansion if in placeholder, otherwise toggle thinking
1062
+ if (this.findPlaceholderAt(this.cursor)) {
1063
+ this.togglePasteExpansion();
1064
+ }
1065
+ else {
1066
+ this.toggleThinking();
1067
+ }
1068
+ return true;
1069
+ case 'escape':
1070
+ // Esc: interrupt if streaming, otherwise clear buffer
1071
+ if (this.mode === 'streaming') {
1072
+ this.emit('interrupt');
1073
+ }
1074
+ else if (this.buffer.length > 0) {
1075
+ this.clear();
1076
+ }
959
1077
  return true;
960
1078
  }
961
1079
  return false;
@@ -973,6 +1091,7 @@ export class TerminalInput extends EventEmitter {
973
1091
  this.insertPlainText(chunk, insertPos);
974
1092
  this.cursor = insertPos + chunk.length;
975
1093
  this.emit('change', this.buffer);
1094
+ this.updateSuggestions();
976
1095
  this.scheduleRender();
977
1096
  }
978
1097
  insertNewline() {
@@ -997,6 +1116,7 @@ export class TerminalInput extends EventEmitter {
997
1116
  this.cursor = Math.max(0, this.cursor - 1);
998
1117
  }
999
1118
  this.emit('change', this.buffer);
1119
+ this.updateSuggestions();
1000
1120
  this.scheduleRender();
1001
1121
  }
1002
1122
  deleteForward() {
@@ -1224,12 +1344,13 @@ export class TerminalInput extends EventEmitter {
1224
1344
  timestamp: Date.now(),
1225
1345
  });
1226
1346
  this.emit('queue', text);
1227
- this.clear(); // Clear immediately for queued input
1347
+ this.clear(); // Clear immediately for queued input, re-render to update queue display
1228
1348
  }
1229
1349
  else {
1230
- // In idle mode, clear the input first, then emit submit.
1231
- // The prompt will be logged as a visible message by the caller.
1232
- this.clear();
1350
+ // In idle mode, clear the input WITHOUT rendering.
1351
+ // The caller will display the user message and start streaming.
1352
+ // We'll render the input area again after streaming ends.
1353
+ this.clear(true); // Skip render - streaming will handle display
1233
1354
  this.emit('submit', text);
1234
1355
  }
1235
1356
  }
@@ -1246,9 +1367,7 @@ export class TerminalInput extends EventEmitter {
1246
1367
  if (available <= 0)
1247
1368
  return;
1248
1369
  const chunk = clean.slice(0, available);
1249
- const isMultiline = isMultilinePaste(chunk);
1250
- const isShortMultiline = isMultiline && this.shouldInlineMultiline(chunk);
1251
- if (isMultiline && !isShortMultiline) {
1370
+ if (isMultilinePaste(chunk)) {
1252
1371
  this.insertPastePlaceholder(chunk);
1253
1372
  }
1254
1373
  else {
@@ -1384,19 +1503,17 @@ export class TerminalInput extends EventEmitter {
1384
1503
  this.shiftPlaceholders(position, text.length);
1385
1504
  this.buffer = this.buffer.slice(0, position) + text + this.buffer.slice(position);
1386
1505
  }
1387
- shouldInlineMultiline(content) {
1388
- const lines = content.split('\n').length;
1389
- const maxInlineLines = 4;
1390
- const maxInlineChars = 240;
1391
- return lines <= maxInlineLines && content.length <= maxInlineChars;
1392
- }
1393
1506
  findPlaceholderAt(position) {
1394
1507
  return this.pastePlaceholders.find((ph) => position >= ph.start && position < ph.end) ?? null;
1395
1508
  }
1396
- buildPlaceholder(lineCount) {
1509
+ buildPlaceholder(summary) {
1397
1510
  const id = ++this.pasteCounter;
1398
- const plural = lineCount === 1 ? '' : 's';
1399
- const placeholder = `[Pasted text #${id} +${lineCount} line${plural}]`;
1511
+ const lang = summary.language ? ` ${summary.language.toUpperCase()}` : '';
1512
+ // Show first line preview (truncated)
1513
+ const preview = summary.preview.length > 30
1514
+ ? `${summary.preview.slice(0, 30)}...`
1515
+ : summary.preview;
1516
+ const placeholder = `[📋 #${id}${lang} ${summary.lineCount}L] "${preview}"`;
1400
1517
  return { id, placeholder };
1401
1518
  }
1402
1519
  insertPastePlaceholder(content) {
@@ -1404,21 +1521,67 @@ export class TerminalInput extends EventEmitter {
1404
1521
  if (available <= 0)
1405
1522
  return;
1406
1523
  const cleanContent = content.slice(0, available);
1407
- const lineCount = cleanContent.split('\n').length;
1408
- const { id, placeholder } = this.buildPlaceholder(lineCount);
1524
+ const summary = generatePasteSummary(cleanContent);
1525
+ // For short pastes (< 5 lines), show full content instead of placeholder
1526
+ if (summary.lineCount < 5) {
1527
+ const placeholder = this.findPlaceholderAt(this.cursor);
1528
+ const insertPos = placeholder && this.cursor > placeholder.start ? placeholder.end : this.cursor;
1529
+ this.insertPlainText(cleanContent, insertPos);
1530
+ this.cursor = insertPos + cleanContent.length;
1531
+ return;
1532
+ }
1533
+ const { id, placeholder } = this.buildPlaceholder(summary);
1409
1534
  const insertPos = this.cursor;
1410
1535
  this.shiftPlaceholders(insertPos, placeholder.length);
1411
1536
  this.pastePlaceholders.push({
1412
1537
  id,
1413
1538
  content: cleanContent,
1414
- lineCount,
1539
+ lineCount: summary.lineCount,
1415
1540
  placeholder,
1416
1541
  start: insertPos,
1417
1542
  end: insertPos + placeholder.length,
1543
+ summary,
1544
+ expanded: false,
1418
1545
  });
1419
1546
  this.buffer = this.buffer.slice(0, insertPos) + placeholder + this.buffer.slice(insertPos);
1420
1547
  this.cursor = insertPos + placeholder.length;
1421
1548
  }
1549
+ /**
1550
+ * Toggle expansion of a paste placeholder at the current cursor position.
1551
+ * When expanded, shows first 3 and last 2 lines of the content.
1552
+ */
1553
+ togglePasteExpansion() {
1554
+ const placeholder = this.findPlaceholderAt(this.cursor);
1555
+ if (!placeholder)
1556
+ return false;
1557
+ placeholder.expanded = !placeholder.expanded;
1558
+ // Update the placeholder text in buffer
1559
+ const newPlaceholder = placeholder.expanded
1560
+ ? this.buildExpandedPlaceholder(placeholder)
1561
+ : this.buildPlaceholder(placeholder.summary).placeholder;
1562
+ const lengthDiff = newPlaceholder.length - placeholder.placeholder.length;
1563
+ // Update buffer
1564
+ this.buffer =
1565
+ this.buffer.slice(0, placeholder.start) +
1566
+ newPlaceholder +
1567
+ this.buffer.slice(placeholder.end);
1568
+ // Update placeholder tracking
1569
+ placeholder.placeholder = newPlaceholder;
1570
+ placeholder.end = placeholder.start + newPlaceholder.length;
1571
+ // Shift other placeholders
1572
+ this.shiftPlaceholders(placeholder.end, lengthDiff, placeholder.id);
1573
+ this.scheduleRender();
1574
+ return true;
1575
+ }
1576
+ buildExpandedPlaceholder(ph) {
1577
+ const lines = ph.content.split('\n');
1578
+ const firstLines = lines.slice(0, 3).map(l => l.slice(0, 60)).join('\n');
1579
+ const lastLines = lines.length > 5
1580
+ ? '\n...\n' + lines.slice(-2).map(l => l.slice(0, 60)).join('\n')
1581
+ : '';
1582
+ const lang = ph.summary.language ? ` ${ph.summary.language.toUpperCase()}` : '';
1583
+ return `[📋 #${ph.id}${lang} ${ph.lineCount}L ▼]\n${firstLines}${lastLines}\n[/📋 #${ph.id}]`;
1584
+ }
1422
1585
  deletePlaceholder(placeholder) {
1423
1586
  const length = placeholder.end - placeholder.start;
1424
1587
  this.buffer = this.buffer.slice(0, placeholder.start) + this.buffer.slice(placeholder.end);
@@ -1426,11 +1589,7 @@ export class TerminalInput extends EventEmitter {
1426
1589
  this.shiftPlaceholders(placeholder.end, -length, placeholder.id);
1427
1590
  this.cursor = placeholder.start;
1428
1591
  }
1429
- updateContextUsage(value, autoCompactThreshold) {
1430
- if (typeof autoCompactThreshold === 'number' && Number.isFinite(autoCompactThreshold)) {
1431
- const boundedThreshold = Math.max(1, Math.min(100, Math.round(autoCompactThreshold)));
1432
- this.contextAutoCompactThreshold = boundedThreshold;
1433
- }
1592
+ updateContextUsage(value) {
1434
1593
  if (value === null || !Number.isFinite(value)) {
1435
1594
  this.contextUsage = null;
1436
1595
  }
@@ -1457,22 +1616,6 @@ export class TerminalInput extends EventEmitter {
1457
1616
  const next = this.editMode === 'display-edits' ? 'ask-permission' : 'display-edits';
1458
1617
  this.setEditMode(next);
1459
1618
  }
1460
- scheduleStreamingRender(delayMs) {
1461
- if (this.streamingRenderTimer)
1462
- return;
1463
- const wait = Math.max(16, delayMs);
1464
- this.streamingRenderTimer = setTimeout(() => {
1465
- this.streamingRenderTimer = null;
1466
- this.render();
1467
- }, wait);
1468
- }
1469
- resetStreamingRenderThrottle() {
1470
- if (this.streamingRenderTimer) {
1471
- clearTimeout(this.streamingRenderTimer);
1472
- this.streamingRenderTimer = null;
1473
- }
1474
- this.lastStreamingRender = 0;
1475
- }
1476
1619
  scheduleRender() {
1477
1620
  if (!this.canRender())
1478
1621
  return;