erosolar-cli 1.7.296 → 1.7.297

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