erosolar-cli 1.7.324 → 1.7.325

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 +21 -5
  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 +164 -233
  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 +116 -140
  254. package/dist/shell/terminalInput.d.ts.map +1 -1
  255. package/dist/shell/terminalInput.js +512 -543
  256. package/dist/shell/terminalInput.js.map +1 -1
  257. package/dist/shell/terminalInputAdapter.d.ts +20 -71
  258. package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
  259. package/dist/shell/terminalInputAdapter.js +30 -87
  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,20 +3,15 @@
3
3
  *
4
4
  * Design principles:
5
5
  * - Single source of truth for input state
6
- * - Hybrid floating/scroll approach:
7
- * - Initially: chat box floats below content
8
- * - When terminal fills: scroll region activates, chat box pins to bottom
9
6
  * - Native bracketed paste support (no heuristics)
10
7
  * - Clean cursor model with render-time wrapping
11
8
  * - State machine for different input modes
12
9
  * - No readline dependency for display
13
10
  */
14
11
  import { EventEmitter } from 'node:events';
15
- import { isMultilinePaste } from '../core/multilinePasteHandler.js';
12
+ import { isMultilinePaste, generatePasteSummary } from '../core/multilinePasteHandler.js';
16
13
  import { writeLock } from '../ui/writeLock.js';
17
- import { renderDivider, renderStatusLine } from '../ui/unified/layout.js';
18
- import { isStreamingMode } from '../ui/globalWriteLock.js';
19
- import { formatThinking } from '../ui/toolDisplay.js';
14
+ import { UI_COLORS, DEFAULT_UI_CONFIG, } from '../ui/terminalUISchema.js';
20
15
  // ANSI escape codes
21
16
  const ESC = {
22
17
  // Cursor control
@@ -26,15 +21,12 @@ const ESC = {
26
21
  SHOW: '\x1b[?25h',
27
22
  TO: (row, col) => `\x1b[${row};${col}H`,
28
23
  TO_COL: (col) => `\x1b[${col}G`,
24
+ // Screen control
25
+ CLEAR_SCREEN: '\x1b[2J',
26
+ HOME: '\x1b[H',
29
27
  // Line control
30
28
  CLEAR_LINE: '\x1b[2K',
31
29
  CLEAR_TO_END: '\x1b[0J',
32
- // Screen control
33
- HOME: '\x1b[H',
34
- CLEAR_SCREEN: '\x1b[2J',
35
- // Scroll region
36
- SET_SCROLL: (top, bottom) => `\x1b[${top};${bottom}r`,
37
- RESET_SCROLL: '\x1b[r',
38
30
  // Style
39
31
  RESET: '\x1b[0m',
40
32
  DIM: '\x1b[2m',
@@ -74,46 +66,47 @@ export class TerminalInput extends EventEmitter {
74
66
  statusMessage = null;
75
67
  overrideStatusMessage = null; // Secondary status (warnings, etc.)
76
68
  streamingLabel = null; // Streaming progress indicator
77
- metaElapsedSeconds = null; // Optional elapsed time for header line
78
- metaTokensUsed = null; // Optional token usage
79
- metaTokenLimit = null; // Optional token window
80
- metaThinkingMs = null; // Optional thinking duration
81
- metaThinkingHasContent = false; // Whether collapsed thinking content exists
82
69
  lastRenderContent = '';
83
70
  lastRenderCursor = -1;
84
71
  renderDirty = false;
85
72
  isRendering = false;
73
+ flowModeRenderedLines = 0; // Track lines rendered for clearing
74
+ inputAreaStartRow = 0; // Track absolute row position of input area
75
+ contentEndRow = 0; // Row where content ends (chat box renders below this)
76
+ // Command suggestions (Claude Code style auto-complete)
77
+ commandSuggestions = [];
78
+ filteredSuggestions = [];
79
+ selectedSuggestionIndex = 0;
80
+ showSuggestions = false;
86
81
  // Lifecycle
87
82
  disposed = false;
88
83
  enabled = true;
89
84
  contextUsage = null;
90
- contextAutoCompactThreshold = 90;
91
- // Track current content row (starts at top, moves down)
92
- contentRow = 1;
93
- // Track if scroll region is currently active
94
- scrollRegionActive = false;
95
- thinkingModeLabel = null;
96
85
  editMode = 'display-edits';
97
86
  verificationEnabled = true;
98
87
  autoContinueEnabled = false;
99
88
  verificationHotkey = 'alt+v';
100
89
  autoContinueHotkey = 'alt+c';
101
- thinkingHotkey = '/thinking';
102
- modelLabel = null;
103
- providerLabel = null;
104
- // Streaming render throttle
105
- lastStreamingRender = 0;
106
- streamingRenderInterval = 250; // ms between renders during streaming
90
+ // Output interceptor cleanup
91
+ outputInterceptorCleanup;
92
+ // Metrics tracking for status bar
93
+ streamingStartTime = null;
94
+ thinkingEnabled = true;
95
+ modelInfo = null; // Provider · Model info
96
+ // Streaming input area render timer (updates elapsed time display)
107
97
  streamingRenderTimer = null;
98
+ // Unified UI initialization flag
99
+ unifiedUIInitialized = false;
108
100
  constructor(writeStream = process.stdout, config = {}) {
109
101
  super();
110
102
  this.out = writeStream;
103
+ // Use schema defaults for configuration consistency
111
104
  this.config = {
112
- maxLines: config.maxLines ?? 1000,
113
- maxLength: config.maxLength ?? 10000,
105
+ maxLines: config.maxLines ?? DEFAULT_UI_CONFIG.inputArea.maxLines,
106
+ maxLength: config.maxLength ?? DEFAULT_UI_CONFIG.inputArea.maxLength,
114
107
  maxQueueSize: config.maxQueueSize ?? 100,
115
- promptChar: config.promptChar ?? '> ',
116
- continuationChar: config.continuationChar ?? '│ ',
108
+ promptChar: config.promptChar ?? DEFAULT_UI_CONFIG.inputArea.promptChar,
109
+ continuationChar: config.continuationChar ?? DEFAULT_UI_CONFIG.inputArea.continuationChar,
117
110
  };
118
111
  }
119
112
  // ===========================================================================
@@ -192,36 +185,293 @@ export class TerminalInput extends EventEmitter {
192
185
  if (handled)
193
186
  return;
194
187
  }
188
+ // Handle '?' for help hint (if buffer is empty)
189
+ if (str === '?' && this.buffer.length === 0) {
190
+ this.emit('showHelp');
191
+ return;
192
+ }
195
193
  // Insert printable characters
196
194
  if (str && !key?.ctrl && !key?.meta) {
197
195
  this.insertText(str);
198
196
  }
199
197
  }
198
+ // Banner content to write on init (set via setBannerContent before initializeUnifiedUI)
199
+ bannerContent = null;
200
+ /**
201
+ * Set banner content to be written when unified UI initializes.
202
+ */
203
+ setBannerContent(content) {
204
+ this.bannerContent = content;
205
+ }
206
+ /**
207
+ * Initialize the unified UI system with BOTTOM PINNED chat box.
208
+ *
209
+ * Layout:
210
+ * 1. Clear screen
211
+ * 2. Write banner at top
212
+ * 3. Set content cursor row after banner
213
+ * 4. Render chat box at bottom (sets up scroll region)
214
+ */
215
+ initializeUnifiedUI() {
216
+ if (this.unifiedUIInitialized) {
217
+ return;
218
+ }
219
+ // Hide cursor during setup
220
+ this.write(ESC.HIDE);
221
+ // Clear screen and go home
222
+ this.write(ESC.HOME);
223
+ this.write(ESC.CLEAR_SCREEN);
224
+ // Write banner at top
225
+ let bannerLines = 0;
226
+ if (this.bannerContent) {
227
+ const lines = this.bannerContent.split('\n');
228
+ bannerLines = lines.length + 2; // +2 for trailing \n\n
229
+ process.stdout.write(this.bannerContent + '\n\n');
230
+ }
231
+ // Set content cursor row after banner
232
+ this.contentCursorRow = bannerLines > 0 ? bannerLines + 1 : 1;
233
+ // Mark initialized
234
+ this.unifiedUIInitialized = true;
235
+ // Render chat box at bottom (sets scroll region)
236
+ this.renderFloatingInputArea();
237
+ // Position cursor at content row and show
238
+ this.write(ESC.TO(this.contentCursorRow, 1));
239
+ this.write(ESC.SHOW);
240
+ }
241
+ /**
242
+ * Clear the input area at its tracked position.
243
+ * Returns true if something was cleared.
244
+ */
245
+ clearInputArea() {
246
+ if (this.inputAreaStartRow > 0 && this.flowModeRenderedLines > 0) {
247
+ for (let i = 0; i < this.flowModeRenderedLines; i++) {
248
+ this.write(ESC.TO(this.inputAreaStartRow + i, 1));
249
+ this.write(ESC.CLEAR_LINE);
250
+ }
251
+ return true;
252
+ }
253
+ return false;
254
+ }
255
+ /**
256
+ * Reset input area tracking state.
257
+ */
258
+ resetInputAreaTracking() {
259
+ this.inputAreaStartRow = 0;
260
+ this.flowModeRenderedLines = 0;
261
+ }
262
+ /**
263
+ * Render chat box - BOTTOM PINNED with scroll region (SSE).
264
+ * Chat box is always at terminal bottom, content scrolls above it.
265
+ */
266
+ renderFloatingInputArea() {
267
+ const { rows, cols } = this.getSize();
268
+ const divider = '─'.repeat(cols);
269
+ const { dim: DIM, reset: R } = UI_COLORS;
270
+ // Chat box is 4 lines: divider + input + divider + controls
271
+ const chatBoxHeight = 4;
272
+ const chatBoxStartRow = rows - chatBoxHeight + 1;
273
+ const scrollRegionBottom = chatBoxStartRow - 1;
274
+ // Save cursor position BEFORE changing scroll region
275
+ this.write('\x1b7');
276
+ // Set scroll region to protect chat box area
277
+ // Content scrolls in rows 1 to (chatBoxStartRow - 1)
278
+ this.write(`\x1b[1;${scrollRegionBottom}r`);
279
+ // Hide cursor during render
280
+ this.write(ESC.HIDE);
281
+ // Track position
282
+ this.inputAreaStartRow = chatBoxStartRow;
283
+ let currentRow = chatBoxStartRow;
284
+ // Helper to write a line at absolute position (clears then writes)
285
+ const writeLine = (content) => {
286
+ this.write(ESC.TO(currentRow, 1));
287
+ this.write(ESC.CLEAR_LINE);
288
+ this.write(content);
289
+ currentRow++;
290
+ };
291
+ // Top divider
292
+ writeLine(`${DIM}${divider}${R}`);
293
+ // Input line with > prompt
294
+ const { lines, cursorCol } = this.wrapBuffer(cols - 3);
295
+ const displayLine = lines[0] ?? '';
296
+ const inputRow = currentRow;
297
+ writeLine(`${DIM}>${R} ${displayLine}`);
298
+ // Bottom divider
299
+ writeLine(`${DIM}${divider}${R}`);
300
+ // Mode controls line - Claude Code style
301
+ this.write(ESC.TO(currentRow, 1));
302
+ this.write(ESC.CLEAR_LINE);
303
+ this.write(this.buildClaudeStyleControls(cols));
304
+ // Track lines rendered
305
+ this.flowModeRenderedLines = chatBoxHeight;
306
+ // Restore cursor to where it was before rendering
307
+ this.write('\x1b8');
308
+ // Show cursor
309
+ this.write(ESC.SHOW);
310
+ // Update tracking
311
+ this.lastRenderContent = this.buffer;
312
+ this.lastRenderCursor = this.cursor;
313
+ }
314
+ /**
315
+ * Build Claude Code style controls line.
316
+ * Shows: edit mode indicator (shift+tab to cycle)
317
+ */
318
+ buildClaudeStyleControls(cols) {
319
+ const { dim: DIM, green: GREEN, yellow: YELLOW, cyan: CYAN, reset: R } = UI_COLORS;
320
+ // Edit mode indicator
321
+ let editModeText;
322
+ if (this.editMode === 'display-edits') {
323
+ editModeText = `${GREEN}⏵⏵${R} accept edits on`;
324
+ }
325
+ else {
326
+ editModeText = `${YELLOW}⏸⏸${R} ask before edit`;
327
+ }
328
+ // Build controls line
329
+ const parts = [` ${editModeText} ${DIM}(shift+tab to cycle)${R}`];
330
+ // Add thinking mode if enabled
331
+ if (this.thinkingEnabled) {
332
+ parts.push(`${CYAN}💭${R}`);
333
+ }
334
+ // Add context usage if available
335
+ if (this.contextUsage !== null) {
336
+ const rem = Math.max(0, 100 - this.contextUsage);
337
+ if (rem < 10) {
338
+ parts.push(`${UI_COLORS.red}ctx ${rem}%${R}`);
339
+ }
340
+ else if (rem < 25) {
341
+ parts.push(`${YELLOW}ctx ${rem}%${R}`);
342
+ }
343
+ }
344
+ return parts.join(` ${DIM}·${R} `);
345
+ }
200
346
  /**
201
347
  * Set the input mode
202
348
  *
203
- * Content flows naturally - no scroll region pinning.
349
+ * BOTTOM PINNED with SSE: Chat box stays at terminal bottom.
350
+ * Scroll region protects chat box, content scrolls above it.
204
351
  */
205
352
  setMode(mode) {
206
353
  const prevMode = this.mode;
207
354
  this.mode = mode;
208
355
  if (mode === 'streaming' && prevMode !== 'streaming') {
209
- this.resetStreamingRenderThrottle();
356
+ // Track streaming start time for elapsed display
357
+ this.streamingStartTime = Date.now();
358
+ // Ensure unified UI is initialized
359
+ if (!this.unifiedUIInitialized) {
360
+ this.initializeUnifiedUI();
361
+ }
362
+ // Re-render to ensure scroll region is set correctly
210
363
  this.renderDirty = true;
211
- this.render();
364
+ this.scheduleRender();
212
365
  }
213
366
  else if (mode !== 'streaming' && prevMode === 'streaming') {
214
- // Streaming ended - render the input area
215
- this.resetStreamingRenderThrottle();
216
- this.forceRender();
367
+ // Stop streaming render timer (if any)
368
+ if (this.streamingRenderTimer) {
369
+ clearInterval(this.streamingRenderTimer);
370
+ this.streamingRenderTimer = null;
371
+ }
372
+ // Reset streaming time
373
+ this.streamingStartTime = null;
374
+ // Re-render chat box
375
+ this.renderDirty = true;
376
+ this.scheduleRender();
217
377
  }
218
378
  }
219
379
  /**
220
- * Legacy method - no longer used (content flows naturally).
221
- * @deprecated Use setContentRow instead
380
+ * Set the row where content ends (for idle mode positioning).
381
+ * Input area will render starting from this row + 1.
222
382
  */
223
- setPinnedHeaderLines(_count) {
224
- // No-op: scroll region pinning removed
383
+ setContentEndRow(row) {
384
+ this.contentEndRow = Math.max(0, row);
385
+ this.renderDirty = true;
386
+ this.scheduleRender();
387
+ }
388
+ /**
389
+ * Set available slash commands for auto-complete suggestions.
390
+ */
391
+ setCommands(commands) {
392
+ this.commandSuggestions = commands;
393
+ this.updateSuggestions();
394
+ }
395
+ /**
396
+ * Update filtered suggestions based on current input.
397
+ */
398
+ updateSuggestions() {
399
+ const input = this.buffer.trim();
400
+ // Only show suggestions when input starts with "/"
401
+ if (!input.startsWith('/')) {
402
+ this.showSuggestions = false;
403
+ this.filteredSuggestions = [];
404
+ this.selectedSuggestionIndex = 0;
405
+ return;
406
+ }
407
+ const query = input.toLowerCase();
408
+ this.filteredSuggestions = this.commandSuggestions.filter(cmd => cmd.command.toLowerCase().startsWith(query) ||
409
+ cmd.command.toLowerCase().includes(query.slice(1)));
410
+ // Show suggestions if we have matches
411
+ this.showSuggestions = this.filteredSuggestions.length > 0;
412
+ // Keep selection in bounds
413
+ if (this.selectedSuggestionIndex >= this.filteredSuggestions.length) {
414
+ this.selectedSuggestionIndex = Math.max(0, this.filteredSuggestions.length - 1);
415
+ }
416
+ }
417
+ /**
418
+ * Select next suggestion (arrow down / tab).
419
+ */
420
+ selectNextSuggestion() {
421
+ if (!this.showSuggestions || this.filteredSuggestions.length === 0)
422
+ return;
423
+ this.selectedSuggestionIndex = (this.selectedSuggestionIndex + 1) % this.filteredSuggestions.length;
424
+ this.renderDirty = true;
425
+ this.scheduleRender();
426
+ }
427
+ /**
428
+ * Select previous suggestion (arrow up / shift+tab).
429
+ */
430
+ selectPrevSuggestion() {
431
+ if (!this.showSuggestions || this.filteredSuggestions.length === 0)
432
+ return;
433
+ this.selectedSuggestionIndex = this.selectedSuggestionIndex === 0
434
+ ? this.filteredSuggestions.length - 1
435
+ : this.selectedSuggestionIndex - 1;
436
+ this.renderDirty = true;
437
+ this.scheduleRender();
438
+ }
439
+ /**
440
+ * Accept current suggestion and insert into buffer.
441
+ */
442
+ acceptSuggestion() {
443
+ if (!this.showSuggestions || this.filteredSuggestions.length === 0)
444
+ return false;
445
+ const selected = this.filteredSuggestions[this.selectedSuggestionIndex];
446
+ if (!selected)
447
+ return false;
448
+ // Replace buffer with selected command
449
+ this.buffer = selected.command + ' ';
450
+ this.cursor = this.buffer.length;
451
+ this.showSuggestions = false;
452
+ this.renderDirty = true;
453
+ this.scheduleRender();
454
+ return true;
455
+ }
456
+ /**
457
+ * Check if suggestions are visible.
458
+ */
459
+ areSuggestionsVisible() {
460
+ return this.showSuggestions && this.filteredSuggestions.length > 0;
461
+ }
462
+ /**
463
+ * Toggle thinking/reasoning mode
464
+ */
465
+ toggleThinking() {
466
+ this.thinkingEnabled = !this.thinkingEnabled;
467
+ this.emit('thinkingToggle', this.thinkingEnabled);
468
+ this.scheduleRender();
469
+ }
470
+ /**
471
+ * Get thinking enabled state
472
+ */
473
+ isThinkingEnabled() {
474
+ return this.thinkingEnabled;
225
475
  }
226
476
  /**
227
477
  * Get current mode
@@ -254,14 +504,17 @@ export class TerminalInput extends EventEmitter {
254
504
  }
255
505
  /**
256
506
  * Clear the buffer
507
+ * @param skipRender - If true, don't trigger a re-render (used during submit flow)
257
508
  */
258
- clear() {
509
+ clear(skipRender = false) {
259
510
  this.buffer = '';
260
511
  this.cursor = 0;
261
512
  this.historyIndex = -1;
262
513
  this.tempInput = '';
263
514
  this.pastePlaceholders = [];
264
- this.scheduleRender();
515
+ if (!skipRender) {
516
+ this.scheduleRender();
517
+ }
265
518
  }
266
519
  /**
267
520
  * Get queued inputs
@@ -332,37 +585,6 @@ export class TerminalInput extends EventEmitter {
332
585
  this.streamingLabel = next;
333
586
  this.scheduleRender();
334
587
  }
335
- /**
336
- * Surface meta status just above the divider (e.g., elapsed time or token usage).
337
- */
338
- setMetaStatus(meta) {
339
- const nextElapsed = typeof meta.elapsedSeconds === 'number' && Number.isFinite(meta.elapsedSeconds) && meta.elapsedSeconds >= 0
340
- ? Math.floor(meta.elapsedSeconds)
341
- : null;
342
- const nextTokens = typeof meta.tokensUsed === 'number' && Number.isFinite(meta.tokensUsed) && meta.tokensUsed >= 0
343
- ? Math.floor(meta.tokensUsed)
344
- : null;
345
- const nextLimit = typeof meta.tokenLimit === 'number' && Number.isFinite(meta.tokenLimit) && meta.tokenLimit > 0
346
- ? Math.floor(meta.tokenLimit)
347
- : null;
348
- const nextThinking = typeof meta.thinkingMs === 'number' && Number.isFinite(meta.thinkingMs) && meta.thinkingMs >= 0
349
- ? Math.floor(meta.thinkingMs)
350
- : null;
351
- const nextThinkingHasContent = !!meta.thinkingHasContent;
352
- if (this.metaElapsedSeconds === nextElapsed &&
353
- this.metaTokensUsed === nextTokens &&
354
- this.metaTokenLimit === nextLimit &&
355
- this.metaThinkingMs === nextThinking &&
356
- this.metaThinkingHasContent === nextThinkingHasContent) {
357
- return;
358
- }
359
- this.metaElapsedSeconds = nextElapsed;
360
- this.metaTokensUsed = nextTokens;
361
- this.metaTokenLimit = nextLimit;
362
- this.metaThinkingMs = nextThinking;
363
- this.metaThinkingHasContent = nextThinkingHasContent;
364
- this.scheduleRender();
365
- }
366
588
  /**
367
589
  * Keep mode toggles (verification/auto-continue) visible in the control bar.
368
590
  * Hotkey labels remain stable so the bar looks the same before/during streaming.
@@ -372,22 +594,26 @@ export class TerminalInput extends EventEmitter {
372
594
  const nextAutoContinue = !!options.autoContinueEnabled;
373
595
  const nextVerifyHotkey = options.verificationHotkey ?? this.verificationHotkey;
374
596
  const nextAutoHotkey = options.autoContinueHotkey ?? this.autoContinueHotkey;
375
- const nextThinkingHotkey = options.thinkingHotkey ?? this.thinkingHotkey;
376
- const nextThinkingLabel = options.thinkingModeLabel === undefined ? this.thinkingModeLabel : (options.thinkingModeLabel || null);
377
597
  if (this.verificationEnabled === nextVerification &&
378
598
  this.autoContinueEnabled === nextAutoContinue &&
379
599
  this.verificationHotkey === nextVerifyHotkey &&
380
- this.autoContinueHotkey === nextAutoHotkey &&
381
- this.thinkingHotkey === nextThinkingHotkey &&
382
- this.thinkingModeLabel === nextThinkingLabel) {
600
+ this.autoContinueHotkey === nextAutoHotkey) {
383
601
  return;
384
602
  }
385
603
  this.verificationEnabled = nextVerification;
386
604
  this.autoContinueEnabled = nextAutoContinue;
387
605
  this.verificationHotkey = nextVerifyHotkey;
388
606
  this.autoContinueHotkey = nextAutoHotkey;
389
- this.thinkingHotkey = nextThinkingHotkey;
390
- this.thinkingModeLabel = nextThinkingLabel;
607
+ this.scheduleRender();
608
+ }
609
+ /**
610
+ * Set the model info string (e.g., "OpenAI · gpt-4")
611
+ * This is displayed persistently above the input area.
612
+ */
613
+ setModelInfo(info) {
614
+ if (this.modelInfo === info)
615
+ return;
616
+ this.modelInfo = info;
391
617
  this.scheduleRender();
392
618
  }
393
619
  /**
@@ -400,157 +626,33 @@ export class TerminalInput extends EventEmitter {
400
626
  this.scheduleRender();
401
627
  }
402
628
  /**
403
- * Surface model/provider context in the controls bar.
404
- */
405
- setModelContext(options) {
406
- const nextModel = options.model?.trim() || null;
407
- const nextProvider = options.provider?.trim() || null;
408
- if (this.modelLabel === nextModel && this.providerLabel === nextProvider) {
409
- return;
410
- }
411
- this.modelLabel = nextModel;
412
- this.providerLabel = nextProvider;
413
- this.scheduleRender();
414
- }
415
- /**
416
- * Render the floating input area at contentRow.
417
- *
418
- * The chat box "floats" - it renders right below the last streamed content.
419
- * As content is added, contentRow advances, and the chat box moves down.
420
- * No scroll regions - pure floating behavior.
629
+ * Render the input area.
630
+ * During streaming: renders at terminal bottom (with scroll region)
631
+ * After streaming: renders floating below content
421
632
  */
422
633
  render() {
423
634
  if (!this.canRender())
424
635
  return;
425
636
  if (this.isRendering)
426
637
  return;
427
- const streamingActive = this.mode === 'streaming' || isStreamingMode();
428
- // During streaming, throttle re-renders
429
- if (streamingActive && this.lastStreamingRender > 0) {
430
- const elapsed = Date.now() - this.lastStreamingRender;
431
- const waitMs = Math.max(0, this.streamingRenderInterval - elapsed);
432
- if (waitMs > 0) {
433
- this.renderDirty = true;
434
- this.scheduleStreamingRender(waitMs);
435
- return;
436
- }
437
- }
438
638
  const shouldSkip = !this.renderDirty &&
439
639
  this.buffer === this.lastRenderContent &&
440
640
  this.cursor === this.lastRenderCursor;
441
641
  this.renderDirty = false;
642
+ // Skip if nothing changed (unless explicitly forced)
442
643
  if (shouldSkip) {
443
644
  return;
444
645
  }
646
+ // If write lock is held, defer render
445
647
  if (writeLock.isLocked()) {
446
648
  writeLock.safeWrite(() => this.render());
447
649
  return;
448
650
  }
449
- this.renderFloatingInputArea();
450
- }
451
- /**
452
- * Core floating input area renderer.
453
- * Chat box always floats at contentRow (below streamed content).
454
- * This creates "persistent bottom floating" behavior.
455
- */
456
- renderFloatingInputArea() {
457
- const { rows, cols } = this.getSize();
458
- const maxWidth = Math.max(8, cols - 4);
459
- const streamingActive = this.mode === 'streaming' || isStreamingMode();
460
- // Wrap buffer into display lines
461
- const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
462
- const maxVisible = Math.max(1, Math.min(this.config.maxLines, rows - 3));
463
- const displayLines = Math.min(lines.length, maxVisible);
464
- const metaLines = this.buildMetaLines(cols - 2);
465
- // Calculate display window (keep cursor visible)
466
- let startLine = 0;
467
- if (lines.length > displayLines) {
468
- startLine = Math.max(0, cursorLine - displayLines + 1);
469
- startLine = Math.min(startLine, lines.length - displayLines);
470
- }
471
- const visibleLines = lines.slice(startLine, startLine + displayLines);
472
- const adjustedCursorLine = cursorLine - startLine;
473
- // Chat box height (must match getChatBoxHeight calculation)
474
- const chatBoxHeight = metaLines.length + 1 + displayLines + 1;
475
- // Always pin chat box at bottom of terminal
476
- const chatBoxStartRow = Math.max(1, rows - chatBoxHeight + 1);
477
- writeLock.lock('terminalInput.renderFloating');
478
651
  this.isRendering = true;
652
+ writeLock.lock('terminalInput.render');
479
653
  try {
480
- // Hide cursor during render
481
- this.write(ESC.HIDE);
482
- this.write(ESC.RESET);
483
- // Clear the chat box area
484
- for (let i = 0; i < chatBoxHeight; i++) {
485
- const row = chatBoxStartRow + i;
486
- if (row <= rows) {
487
- this.write(ESC.TO(row, 1));
488
- this.write(ESC.CLEAR_LINE);
489
- }
490
- }
491
- let currentRow = chatBoxStartRow;
492
- // Meta/status header
493
- for (const metaLine of metaLines) {
494
- this.write(ESC.TO(currentRow, 1));
495
- this.write(metaLine);
496
- currentRow += 1;
497
- }
498
- // Separator line
499
- this.write(ESC.TO(currentRow, 1));
500
- this.write(renderDivider(cols - 2));
501
- currentRow += 1;
502
- // Render input lines
503
- let finalRow = currentRow;
504
- let finalCol = 3;
505
- for (let i = 0; i < visibleLines.length; i++) {
506
- const rowNum = currentRow + i;
507
- this.write(ESC.TO(rowNum, 1));
508
- const line = visibleLines[i] ?? '';
509
- const isFirstLine = (startLine + i) === 0;
510
- const isCursorLine = i === adjustedCursorLine;
511
- this.write(ESC.BG_DARK);
512
- this.write(ESC.DIM);
513
- this.write(isFirstLine ? this.config.promptChar : this.config.continuationChar);
514
- this.write(ESC.RESET);
515
- this.write(ESC.BG_DARK);
516
- if (isCursorLine) {
517
- const col = Math.min(cursorCol, line.length);
518
- const before = line.slice(0, col);
519
- const at = col < line.length ? line[col] : ' ';
520
- const after = col < line.length ? line.slice(col + 1) : '';
521
- this.write(before);
522
- this.write(ESC.REVERSE + ESC.BOLD);
523
- this.write(at);
524
- this.write(ESC.RESET + ESC.BG_DARK);
525
- this.write(after);
526
- finalRow = rowNum;
527
- finalCol = this.config.promptChar.length + col + 1;
528
- }
529
- else {
530
- this.write(line);
531
- }
532
- // Pad to edge
533
- const lineLen = this.config.promptChar.length + line.length + (isCursorLine && cursorCol >= line.length ? 1 : 0);
534
- const padding = Math.max(0, cols - lineLen - 1);
535
- if (padding > 0)
536
- this.write(' '.repeat(padding));
537
- this.write(ESC.RESET);
538
- }
539
- // Mode controls line
540
- const controlRow = currentRow + visibleLines.length;
541
- this.write(ESC.TO(controlRow, 1));
542
- this.write(this.buildModeControls(cols));
543
- // Position cursor in input box
544
- this.write(ESC.TO(finalRow, Math.min(finalCol, cols)));
545
- this.write(ESC.SHOW);
546
- // Update state
547
- this.lastRenderContent = this.buffer;
548
- this.lastRenderCursor = this.cursor;
549
- this.lastStreamingRender = streamingActive ? Date.now() : 0;
550
- if (this.streamingRenderTimer) {
551
- clearTimeout(this.streamingRenderTimer);
552
- this.streamingRenderTimer = null;
553
- }
654
+ // Always render floating right after content (no wasted space)
655
+ this.renderFloatingInputArea();
554
656
  }
555
657
  finally {
556
658
  writeLock.unlock();
@@ -558,181 +660,99 @@ export class TerminalInput extends EventEmitter {
558
660
  }
559
661
  }
560
662
  /**
561
- * Build compact meta line above the divider.
562
- * Shows model/provider and key metrics in a single line.
563
- * Status message is shown in mode controls to avoid duplication.
663
+ * Build status bar showing streaming/ready status and key info.
664
+ * This is the TOP line above the input area - minimal Claude Code style.
564
665
  */
565
- buildMetaLines(width) {
666
+ buildStatusBar(cols) {
667
+ const maxWidth = cols - 2;
566
668
  const parts = [];
567
- // Model/provider info
568
- if (this.modelLabel) {
569
- const modelText = this.providerLabel
570
- ? `${this.modelLabel} @ ${this.providerLabel}`
571
- : this.modelLabel;
572
- parts.push({ text: modelText, tone: 'info' });
573
- }
574
- // Elapsed time
575
- if (this.metaElapsedSeconds !== null) {
576
- parts.push({ text: this.formatElapsedLabel(this.metaElapsedSeconds), tone: 'muted' });
577
- }
578
- // Token usage (compact)
579
- if (this.metaTokensUsed !== null) {
580
- const formattedUsed = this.formatTokenCount(this.metaTokensUsed);
581
- const formattedLimit = this.metaTokenLimit ? `/${this.formatTokenCount(this.metaTokenLimit)}` : '';
582
- parts.push({ text: `${formattedUsed}${formattedLimit}`, tone: 'muted' });
583
- }
584
- // Context remaining (only show if concerning)
585
- const tokensRemaining = this.computeTokensRemaining();
586
- if (tokensRemaining !== null) {
587
- parts.push({ text: `↓${tokensRemaining}`, tone: 'muted' });
588
- }
589
- // Thinking indicator
590
- if (this.metaThinkingMs !== null) {
591
- parts.push({ text: formatThinking(this.metaThinkingMs, this.metaThinkingHasContent), tone: 'info' });
592
- }
593
- if (!parts.length) {
594
- return [];
595
- }
596
- return [renderStatusLine(parts, width)];
597
- }
598
- /**
599
- * Build Claude Code style mode controls line.
600
- * Combines streaming label + override status + main status for simultaneous display.
601
- */
602
- buildModeControls(cols) {
603
- const width = Math.max(8, cols - 2);
604
- const leftParts = [];
605
- const rightParts = [];
606
- if (this.streamingLabel) {
607
- leftParts.push({ text: `◐ ${this.streamingLabel}`, tone: 'info' });
608
- }
609
- if (this.overrideStatusMessage) {
610
- leftParts.push({ text: `⚠ ${this.overrideStatusMessage}`, tone: 'warn' });
611
- }
612
- if (this.statusMessage) {
613
- leftParts.push({ text: this.statusMessage, tone: this.streamingLabel ? 'muted' : 'info' });
614
- }
615
- const editHotkey = this.formatHotkey('shift+tab');
616
- const editLabel = this.editMode === 'display-edits' ? 'edits: accept' : 'edits: ask';
617
- const editTone = this.editMode === 'display-edits' ? 'success' : 'muted';
618
- leftParts.push({ text: `${editHotkey} ${editLabel}`, tone: editTone });
619
- const verifyHotkey = this.formatHotkey(this.verificationHotkey);
620
- const verifyLabel = this.verificationEnabled ? 'verify:on' : 'verify:off';
621
- leftParts.push({ text: `${verifyHotkey} ${verifyLabel}`, tone: this.verificationEnabled ? 'success' : 'muted' });
622
- const continueHotkey = this.formatHotkey(this.autoContinueHotkey);
623
- const continueLabel = this.autoContinueEnabled ? 'auto:on' : 'auto:off';
624
- leftParts.push({ text: `${continueHotkey} ${continueLabel}`, tone: this.autoContinueEnabled ? 'info' : 'muted' });
625
- if (this.queue.length > 0 && this.mode !== 'streaming') {
626
- leftParts.push({ text: `queued ${this.queue.length}`, tone: 'info' });
669
+ // Streaming status with elapsed time (left side)
670
+ if (this.mode === 'streaming') {
671
+ let statusText = '● Streaming';
672
+ if (this.streamingStartTime) {
673
+ const elapsed = Math.floor((Date.now() - this.streamingStartTime) / 1000);
674
+ const mins = Math.floor(elapsed / 60);
675
+ const secs = elapsed % 60;
676
+ statusText += mins > 0 ? ` ${mins}m ${secs}s` : ` ${secs}s`;
677
+ }
678
+ parts.push(`\x1b[32m${statusText}\x1b[0m`); // Green
627
679
  }
628
- if (this.buffer.includes('\n')) {
629
- const lineCount = this.buffer.split('\n').length;
630
- leftParts.push({ text: `${lineCount} lines`, tone: 'muted' });
680
+ // Queue indicator during streaming
681
+ if (this.mode === 'streaming' && this.queue.length > 0) {
682
+ parts.push(`\x1b[36mqueued: ${this.queue.length}\x1b[0m`); // Cyan
631
683
  }
684
+ // Paste indicator
632
685
  if (this.pastePlaceholders.length > 0) {
633
- const latest = this.pastePlaceholders[this.pastePlaceholders.length - 1];
634
- leftParts.push({
635
- text: `paste #${latest.id} +${latest.lineCount} lines (⌫ to drop)`,
636
- tone: 'info',
637
- });
638
- }
639
- const contextRemaining = this.computeContextRemaining();
640
- if (this.thinkingModeLabel) {
641
- const thinkingHotkey = this.formatHotkey(this.thinkingHotkey);
642
- rightParts.push({ text: `${thinkingHotkey} thinking:${this.thinkingModeLabel}`, tone: 'info' });
643
- }
644
- // Model info is now in meta lines only - no duplication here
645
- if (contextRemaining !== null) {
646
- const tone = contextRemaining <= 10 ? 'warn' : 'muted';
647
- const label = contextRemaining === 0 && this.contextUsage !== null
648
- ? 'Context auto-compact imminent'
649
- : `Context left until auto-compact: ${contextRemaining}%`;
650
- rightParts.push({ text: label, tone });
651
- }
652
- if (!rightParts.length || width < 60) {
653
- const merged = rightParts.length ? [...leftParts, ...rightParts] : leftParts;
654
- return renderStatusLine(merged, width);
655
- }
656
- const leftWidth = Math.max(12, Math.floor(width * 0.6));
657
- const rightWidth = Math.max(14, width - leftWidth - 1);
658
- const leftText = renderStatusLine(leftParts, leftWidth);
659
- const rightText = renderStatusLine(rightParts, rightWidth);
660
- const spacing = Math.max(1, width - this.visibleLength(leftText) - this.visibleLength(rightText));
661
- return `${leftText}${' '.repeat(spacing)}${rightText}`;
662
- }
663
- formatHotkey(hotkey) {
664
- const normalized = hotkey.trim().toLowerCase();
665
- if (!normalized)
666
- return hotkey;
667
- const parts = normalized.split('+').filter(Boolean);
668
- const map = {
669
- shift: '⇧',
670
- sh: '⇧',
671
- alt: '⌥',
672
- option: '⌥',
673
- opt: '⌥',
674
- ctrl: '⌃',
675
- control: '⌃',
676
- cmd: '⌘',
677
- meta: '⌘',
678
- };
679
- const formatted = parts
680
- .map((part) => {
681
- const symbol = map[part];
682
- if (symbol)
683
- return symbol;
684
- return part.length === 1 ? part.toUpperCase() : part.toUpperCase();
685
- })
686
- .join('');
687
- return formatted || hotkey;
688
- }
689
- computeContextRemaining() {
690
- if (this.contextUsage === null) {
691
- return null;
686
+ const totalLines = this.pastePlaceholders.reduce((sum, p) => sum + p.lineCount, 0);
687
+ parts.push(`\x1b[36m📋 ${totalLines}L\x1b[0m`);
692
688
  }
693
- return Math.max(0, this.contextAutoCompactThreshold - this.contextUsage);
694
- }
695
- computeTokensRemaining() {
696
- if (this.metaTokensUsed === null || this.metaTokenLimit === null) {
697
- return null;
698
- }
699
- const remaining = Math.max(0, this.metaTokenLimit - this.metaTokensUsed);
700
- return this.formatTokenCount(remaining);
701
- }
702
- formatElapsedLabel(seconds) {
703
- if (seconds < 60) {
704
- return `${seconds}s`;
689
+ // Override/warning status
690
+ if (this.overrideStatusMessage) {
691
+ parts.push(`\x1b[33m⚠ ${this.overrideStatusMessage}\x1b[0m`); // Yellow
705
692
  }
706
- const mins = Math.floor(seconds / 60);
707
- const secs = seconds % 60;
708
- return secs > 0 ? `${mins}m ${secs}s` : `${mins}m`;
709
- }
710
- formatTokenCount(value) {
711
- if (!Number.isFinite(value)) {
712
- return `${value}`;
693
+ // If idle with empty buffer, show quick shortcuts
694
+ if (this.mode !== 'streaming' && this.buffer.length === 0 && parts.length === 0) {
695
+ return `${ESC.DIM}Type a message or / for commands${ESC.RESET}`;
713
696
  }
714
- if (value >= 1_000_000) {
715
- return `${(value / 1_000_000).toFixed(1)}M`;
697
+ // Multi-line indicator
698
+ if (this.buffer.includes('\n')) {
699
+ parts.push(`${ESC.DIM}${this.buffer.split('\n').length}L${ESC.RESET}`);
716
700
  }
717
- if (value >= 1_000) {
718
- return `${(value / 1_000).toFixed(1)}k`;
701
+ if (parts.length === 0) {
702
+ return ''; // Empty status bar when idle
719
703
  }
720
- return `${Math.round(value)}`;
721
- }
722
- visibleLength(value) {
723
- const ansiPattern = /\u001B\[[0-?]*[ -/]*[@-~]/g;
724
- return value.replace(ansiPattern, '').length;
704
+ const joined = parts.join(`${ESC.DIM} · ${ESC.RESET}`);
705
+ return joined.slice(0, maxWidth);
725
706
  }
726
707
  /**
727
- * Debug-only snapshot used by tests to assert rendered strings without
728
- * needing a TTY. Not used by production code.
708
+ * Build mode controls line showing toggles and context info.
709
+ * This is the BOTTOM line below the input area - Claude Code style layout with erosolar features.
710
+ *
711
+ * Layout: [toggles on left] ... [context info on right]
729
712
  */
730
- getDebugUiSnapshot(width) {
731
- const cols = Math.max(8, width ?? this.getSize().cols);
732
- return {
733
- meta: this.buildMetaLines(cols - 2),
734
- controls: this.buildModeControls(cols),
735
- };
713
+ buildModeControls(cols) {
714
+ const maxWidth = cols - 2;
715
+ // Use schema-defined colors for consistency
716
+ const { green: GREEN, yellow: YELLOW, cyan: CYAN, magenta: MAGENTA, red: RED, dim: DIM, reset: R } = UI_COLORS;
717
+ // Mode toggles with colors (following ModeControlsSchema)
718
+ const toggles = [];
719
+ // Edit mode (green=auto, yellow=ask) - per schema.editMode
720
+ if (this.editMode === 'display-edits') {
721
+ toggles.push(`${GREEN}⏵⏵ auto-edit${R}`);
722
+ }
723
+ else {
724
+ toggles.push(`${YELLOW}⏸⏸ ask-first${R}`);
725
+ }
726
+ // Thinking mode (cyan when on) - per schema.thinkingMode
727
+ toggles.push(this.thinkingEnabled ? `${CYAN}💭 think${R}` : `${DIM}○ think${R}`);
728
+ // Verification (green when on) - per schema.verificationMode
729
+ toggles.push(this.verificationEnabled ? `${GREEN}✓ verify${R}` : `${DIM}○ verify${R}`);
730
+ // Auto-continue (magenta when on) - per schema.autoContinueMode
731
+ toggles.push(this.autoContinueEnabled ? `${MAGENTA}↻ auto${R}` : `${DIM}○ auto${R}`);
732
+ const leftPart = toggles.join(`${DIM} · ${R}`) + `${DIM} (⇧⇥)${R}`;
733
+ // Context usage with color - per schema.contextUsage thresholds
734
+ let rightPart = '';
735
+ if (this.contextUsage !== null) {
736
+ const rem = Math.max(0, 100 - this.contextUsage);
737
+ // Thresholds: critical < 10%, warning < 25%
738
+ if (rem < 10)
739
+ rightPart = `${RED}⚠ ctx: ${rem}%${R}`;
740
+ else if (rem < 25)
741
+ rightPart = `${YELLOW}! ctx: ${rem}%${R}`;
742
+ else
743
+ rightPart = `${DIM}ctx: ${rem}%${R}`;
744
+ }
745
+ // Calculate visible lengths (strip ANSI)
746
+ const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
747
+ const leftLen = strip(leftPart).length;
748
+ const rightLen = strip(rightPart).length;
749
+ if (leftLen + rightLen < maxWidth - 4) {
750
+ return `${leftPart}${' '.repeat(maxWidth - leftLen - rightLen)}${rightPart}`;
751
+ }
752
+ if (rightLen > 0 && leftLen + 8 < maxWidth) {
753
+ return `${leftPart} ${rightPart}`;
754
+ }
755
+ return leftPart;
736
756
  }
737
757
  /**
738
758
  * Force a re-render
@@ -755,133 +775,32 @@ export class TerminalInput extends EventEmitter {
755
775
  handleResize() {
756
776
  this.lastRenderContent = '';
757
777
  this.lastRenderCursor = -1;
758
- this.resetStreamingRenderThrottle();
759
778
  this.scheduleRender();
760
779
  }
780
+ // Track current content row for writing
781
+ contentCursorRow = 1;
761
782
  /**
762
- * Enter streaming mode.
763
- */
764
- enterStreamingScrollRegion() {
765
- this.scrollRegionActive = true;
766
- this.streamingCursorRow = this.contentRow;
767
- }
768
- streamingCursorRow = 1;
769
- /**
770
- * Exit streaming mode and render final chat box.
771
- */
772
- exitStreamingScrollRegion() {
773
- this.scrollRegionActive = false;
774
- this.write('\n');
775
- this.forceRender();
776
- }
777
- /**
778
- * Stream content with persistent bottom chat box.
779
- *
780
- * Approach:
781
- * 1. Save cursor position
782
- * 2. Write content at cursor position
783
- * 3. Save new cursor position
784
- * 4. Render chat box at bottom of terminal
785
- * 5. Restore cursor position for next write
783
+ * Register with display's output interceptor.
784
+ * With scroll regions (SSE), explicitly position cursor before writes.
786
785
  */
787
- streamContent(content) {
788
- if (!content)
789
- return;
790
- writeLock.lock('streamContent');
791
- try {
792
- const { rows } = this.getSize();
793
- const chatBoxHeight = this.getChatBoxHeight();
794
- // Move to streaming position and write content
795
- this.write(ESC.TO(this.streamingCursorRow, 1));
796
- this.write(content);
797
- // Track position
798
- const newlines = (content.match(/\n/g) || []).length;
799
- this.streamingCursorRow += newlines;
800
- // If content would overlap chat box, scroll up
801
- const maxRow = rows - chatBoxHeight;
802
- if (this.streamingCursorRow > maxRow) {
803
- // Scroll content up by moving to top and inserting newlines
804
- const overflow = this.streamingCursorRow - maxRow;
805
- this.write(ESC.TO(1, 1));
806
- for (let i = 0; i < overflow; i++) {
807
- this.write('\n');
786
+ registerOutputInterceptor(display) {
787
+ if (this.outputInterceptorCleanup) {
788
+ this.outputInterceptorCleanup();
789
+ }
790
+ this.outputInterceptorCleanup = display.registerOutputInterceptor({
791
+ beforeWrite: () => {
792
+ // Ensure scroll region is active (content area above chat box)
793
+ if (this.inputAreaStartRow > 1) {
794
+ this.write(`\x1b[1;${this.inputAreaStartRow - 1}r`);
808
795
  }
809
- this.streamingCursorRow = maxRow;
810
- }
811
- this.contentRow = this.streamingCursorRow;
812
- }
813
- finally {
814
- writeLock.unlock();
815
- }
816
- // Throttle chat box re-renders
817
- this.scheduleStreamingRender(100);
818
- }
819
- /**
820
- * Enable scroll region (no-op in floating mode).
821
- */
822
- enableScrollRegion() {
823
- // No-op: using pure floating approach
824
- }
825
- /**
826
- * Disable scroll region (no-op in floating mode).
827
- */
828
- disableScrollRegion() {
829
- // No-op: using pure floating approach
830
- }
831
- /**
832
- * Calculate chat box height.
833
- */
834
- getChatBoxHeight() {
835
- return 6; // Fixed: meta + divider + input + controls + buffer
836
- }
837
- /**
838
- * @deprecated Use streamContent() instead
839
- * Register with display's output interceptor - kept for backwards compatibility
840
- */
841
- registerOutputInterceptor(_display) {
842
- // No-op: Use streamContent() for cleaner floating chat box behavior
843
- }
844
- /**
845
- * @deprecated Use streamContent() instead
846
- * Write content above the floating chat box.
847
- */
848
- writeToScrollRegion(content) {
849
- this.streamContent(content);
850
- }
851
- /**
852
- * Clear the entire terminal screen and reset content position.
853
- * This removes all content including the launching command.
854
- */
855
- clearScreen() {
856
- writeLock.lock('clearScreen');
857
- try {
858
- this.write(ESC.HOME);
859
- this.write(ESC.CLEAR_SCREEN);
860
- this.contentRow = 1;
861
- }
862
- finally {
863
- writeLock.unlock();
864
- }
865
- }
866
- /**
867
- * Reset content position to row 1.
868
- * Does NOT clear the terminal - content starts from current position.
869
- */
870
- resetContentPosition() {
871
- this.contentRow = 1;
872
- }
873
- /**
874
- * Set the content row explicitly (used after banner is written).
875
- * This tells the input where content should start flowing from.
876
- */
877
- setContentRow(row) {
878
- this.contentRow = Math.max(1, row);
879
- }
880
- /**
881
- * Get the current content row position.
882
- */
883
- getContentRow() {
884
- return this.contentRow;
796
+ // Don't reposition cursor - let it stay where content should be written
797
+ // The chat box render already positions cursor at contentCursorRow
798
+ },
799
+ afterWrite: () => {
800
+ // Content has been written; cursor is now at the new position
801
+ // No action needed - renderFloatingInputArea will position cursor correctly
802
+ },
803
+ });
885
804
  }
886
805
  /**
887
806
  * Dispose and clean up
@@ -889,10 +808,20 @@ export class TerminalInput extends EventEmitter {
889
808
  dispose() {
890
809
  if (this.disposed)
891
810
  return;
811
+ // Clean up streaming render timer
812
+ if (this.streamingRenderTimer) {
813
+ clearInterval(this.streamingRenderTimer);
814
+ this.streamingRenderTimer = null;
815
+ }
816
+ // Clean up output interceptor
817
+ if (this.outputInterceptorCleanup) {
818
+ this.outputInterceptorCleanup();
819
+ this.outputInterceptorCleanup = undefined;
820
+ }
821
+ // Reset scroll region before disposing
822
+ this.write('\x1b[r');
892
823
  this.disposed = true;
893
824
  this.enabled = false;
894
- this.disableScrollRegion();
895
- this.resetStreamingRenderThrottle();
896
825
  this.disableBracketedPaste();
897
826
  this.buffer = '';
898
827
  this.queue = [];
@@ -997,7 +926,22 @@ export class TerminalInput extends EventEmitter {
997
926
  this.toggleEditMode();
998
927
  return true;
999
928
  }
1000
- this.insertText(' ');
929
+ // Tab: toggle paste expansion if in placeholder, otherwise toggle thinking
930
+ if (this.findPlaceholderAt(this.cursor)) {
931
+ this.togglePasteExpansion();
932
+ }
933
+ else {
934
+ this.toggleThinking();
935
+ }
936
+ return true;
937
+ case 'escape':
938
+ // Esc: interrupt if streaming, otherwise clear buffer
939
+ if (this.mode === 'streaming') {
940
+ this.emit('interrupt');
941
+ }
942
+ else if (this.buffer.length > 0) {
943
+ this.clear();
944
+ }
1001
945
  return true;
1002
946
  }
1003
947
  return false;
@@ -1015,6 +959,7 @@ export class TerminalInput extends EventEmitter {
1015
959
  this.insertPlainText(chunk, insertPos);
1016
960
  this.cursor = insertPos + chunk.length;
1017
961
  this.emit('change', this.buffer);
962
+ this.updateSuggestions();
1018
963
  this.scheduleRender();
1019
964
  }
1020
965
  insertNewline() {
@@ -1039,6 +984,7 @@ export class TerminalInput extends EventEmitter {
1039
984
  this.cursor = Math.max(0, this.cursor - 1);
1040
985
  }
1041
986
  this.emit('change', this.buffer);
987
+ this.updateSuggestions();
1042
988
  this.scheduleRender();
1043
989
  }
1044
990
  deleteForward() {
@@ -1266,12 +1212,13 @@ export class TerminalInput extends EventEmitter {
1266
1212
  timestamp: Date.now(),
1267
1213
  });
1268
1214
  this.emit('queue', text);
1269
- this.clear(); // Clear immediately for queued input
1215
+ this.clear(); // Clear immediately for queued input, re-render to update queue display
1270
1216
  }
1271
1217
  else {
1272
- // In idle mode, clear the input first, then emit submit.
1273
- // The prompt will be logged as a visible message by the caller.
1274
- this.clear();
1218
+ // In idle mode, clear the input WITHOUT rendering.
1219
+ // The caller will display the user message and start streaming.
1220
+ // We'll render the input area again after streaming ends.
1221
+ this.clear(true); // Skip render - streaming will handle display
1275
1222
  this.emit('submit', text);
1276
1223
  }
1277
1224
  }
@@ -1288,9 +1235,7 @@ export class TerminalInput extends EventEmitter {
1288
1235
  if (available <= 0)
1289
1236
  return;
1290
1237
  const chunk = clean.slice(0, available);
1291
- const isMultiline = isMultilinePaste(chunk);
1292
- const isShortMultiline = isMultiline && this.shouldInlineMultiline(chunk);
1293
- if (isMultiline && !isShortMultiline) {
1238
+ if (isMultilinePaste(chunk)) {
1294
1239
  this.insertPastePlaceholder(chunk);
1295
1240
  }
1296
1241
  else {
@@ -1426,19 +1371,17 @@ export class TerminalInput extends EventEmitter {
1426
1371
  this.shiftPlaceholders(position, text.length);
1427
1372
  this.buffer = this.buffer.slice(0, position) + text + this.buffer.slice(position);
1428
1373
  }
1429
- shouldInlineMultiline(content) {
1430
- const lines = content.split('\n').length;
1431
- const maxInlineLines = 4;
1432
- const maxInlineChars = 240;
1433
- return lines <= maxInlineLines && content.length <= maxInlineChars;
1434
- }
1435
1374
  findPlaceholderAt(position) {
1436
1375
  return this.pastePlaceholders.find((ph) => position >= ph.start && position < ph.end) ?? null;
1437
1376
  }
1438
- buildPlaceholder(lineCount) {
1377
+ buildPlaceholder(summary) {
1439
1378
  const id = ++this.pasteCounter;
1440
- const plural = lineCount === 1 ? '' : 's';
1441
- const placeholder = `[Pasted text #${id} +${lineCount} line${plural}]`;
1379
+ const lang = summary.language ? ` ${summary.language.toUpperCase()}` : '';
1380
+ // Show first line preview (truncated)
1381
+ const preview = summary.preview.length > 30
1382
+ ? `${summary.preview.slice(0, 30)}...`
1383
+ : summary.preview;
1384
+ const placeholder = `[📋 #${id}${lang} ${summary.lineCount}L] "${preview}"`;
1442
1385
  return { id, placeholder };
1443
1386
  }
1444
1387
  insertPastePlaceholder(content) {
@@ -1446,21 +1389,67 @@ export class TerminalInput extends EventEmitter {
1446
1389
  if (available <= 0)
1447
1390
  return;
1448
1391
  const cleanContent = content.slice(0, available);
1449
- const lineCount = cleanContent.split('\n').length;
1450
- const { id, placeholder } = this.buildPlaceholder(lineCount);
1392
+ const summary = generatePasteSummary(cleanContent);
1393
+ // For short pastes (< 5 lines), show full content instead of placeholder
1394
+ if (summary.lineCount < 5) {
1395
+ const placeholder = this.findPlaceholderAt(this.cursor);
1396
+ const insertPos = placeholder && this.cursor > placeholder.start ? placeholder.end : this.cursor;
1397
+ this.insertPlainText(cleanContent, insertPos);
1398
+ this.cursor = insertPos + cleanContent.length;
1399
+ return;
1400
+ }
1401
+ const { id, placeholder } = this.buildPlaceholder(summary);
1451
1402
  const insertPos = this.cursor;
1452
1403
  this.shiftPlaceholders(insertPos, placeholder.length);
1453
1404
  this.pastePlaceholders.push({
1454
1405
  id,
1455
1406
  content: cleanContent,
1456
- lineCount,
1407
+ lineCount: summary.lineCount,
1457
1408
  placeholder,
1458
1409
  start: insertPos,
1459
1410
  end: insertPos + placeholder.length,
1411
+ summary,
1412
+ expanded: false,
1460
1413
  });
1461
1414
  this.buffer = this.buffer.slice(0, insertPos) + placeholder + this.buffer.slice(insertPos);
1462
1415
  this.cursor = insertPos + placeholder.length;
1463
1416
  }
1417
+ /**
1418
+ * Toggle expansion of a paste placeholder at the current cursor position.
1419
+ * When expanded, shows first 3 and last 2 lines of the content.
1420
+ */
1421
+ togglePasteExpansion() {
1422
+ const placeholder = this.findPlaceholderAt(this.cursor);
1423
+ if (!placeholder)
1424
+ return false;
1425
+ placeholder.expanded = !placeholder.expanded;
1426
+ // Update the placeholder text in buffer
1427
+ const newPlaceholder = placeholder.expanded
1428
+ ? this.buildExpandedPlaceholder(placeholder)
1429
+ : this.buildPlaceholder(placeholder.summary).placeholder;
1430
+ const lengthDiff = newPlaceholder.length - placeholder.placeholder.length;
1431
+ // Update buffer
1432
+ this.buffer =
1433
+ this.buffer.slice(0, placeholder.start) +
1434
+ newPlaceholder +
1435
+ this.buffer.slice(placeholder.end);
1436
+ // Update placeholder tracking
1437
+ placeholder.placeholder = newPlaceholder;
1438
+ placeholder.end = placeholder.start + newPlaceholder.length;
1439
+ // Shift other placeholders
1440
+ this.shiftPlaceholders(placeholder.end, lengthDiff, placeholder.id);
1441
+ this.scheduleRender();
1442
+ return true;
1443
+ }
1444
+ buildExpandedPlaceholder(ph) {
1445
+ const lines = ph.content.split('\n');
1446
+ const firstLines = lines.slice(0, 3).map(l => l.slice(0, 60)).join('\n');
1447
+ const lastLines = lines.length > 5
1448
+ ? '\n...\n' + lines.slice(-2).map(l => l.slice(0, 60)).join('\n')
1449
+ : '';
1450
+ const lang = ph.summary.language ? ` ${ph.summary.language.toUpperCase()}` : '';
1451
+ return `[📋 #${ph.id}${lang} ${ph.lineCount}L ▼]\n${firstLines}${lastLines}\n[/📋 #${ph.id}]`;
1452
+ }
1464
1453
  deletePlaceholder(placeholder) {
1465
1454
  const length = placeholder.end - placeholder.start;
1466
1455
  this.buffer = this.buffer.slice(0, placeholder.start) + this.buffer.slice(placeholder.end);
@@ -1468,11 +1457,7 @@ export class TerminalInput extends EventEmitter {
1468
1457
  this.shiftPlaceholders(placeholder.end, -length, placeholder.id);
1469
1458
  this.cursor = placeholder.start;
1470
1459
  }
1471
- updateContextUsage(value, autoCompactThreshold) {
1472
- if (typeof autoCompactThreshold === 'number' && Number.isFinite(autoCompactThreshold)) {
1473
- const boundedThreshold = Math.max(1, Math.min(100, Math.round(autoCompactThreshold)));
1474
- this.contextAutoCompactThreshold = boundedThreshold;
1475
- }
1460
+ updateContextUsage(value) {
1476
1461
  if (value === null || !Number.isFinite(value)) {
1477
1462
  this.contextUsage = null;
1478
1463
  }
@@ -1499,22 +1484,6 @@ export class TerminalInput extends EventEmitter {
1499
1484
  const next = this.editMode === 'display-edits' ? 'ask-permission' : 'display-edits';
1500
1485
  this.setEditMode(next);
1501
1486
  }
1502
- scheduleStreamingRender(delayMs) {
1503
- if (this.streamingRenderTimer)
1504
- return;
1505
- const wait = Math.max(16, delayMs);
1506
- this.streamingRenderTimer = setTimeout(() => {
1507
- this.streamingRenderTimer = null;
1508
- this.render();
1509
- }, wait);
1510
- }
1511
- resetStreamingRenderThrottle() {
1512
- if (this.streamingRenderTimer) {
1513
- clearTimeout(this.streamingRenderTimer);
1514
- this.streamingRenderTimer = null;
1515
- }
1516
- this.lastStreamingRender = 0;
1517
- }
1518
1487
  scheduleRender() {
1519
1488
  if (!this.canRender())
1520
1489
  return;