erosolar-cli 1.7.299 → 1.7.301

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (323) hide show
  1. package/README.md +148 -24
  2. package/dist/alpha-zero/agentWrapper.d.ts +84 -0
  3. package/dist/alpha-zero/agentWrapper.d.ts.map +1 -0
  4. package/dist/alpha-zero/agentWrapper.js +171 -0
  5. package/dist/alpha-zero/agentWrapper.js.map +1 -0
  6. package/dist/alpha-zero/codeEvaluator.d.ts +25 -0
  7. package/dist/alpha-zero/codeEvaluator.d.ts.map +1 -0
  8. package/dist/alpha-zero/codeEvaluator.js +273 -0
  9. package/dist/alpha-zero/codeEvaluator.js.map +1 -0
  10. package/dist/alpha-zero/competitiveRunner.d.ts +66 -0
  11. package/dist/alpha-zero/competitiveRunner.d.ts.map +1 -0
  12. package/dist/alpha-zero/competitiveRunner.js +224 -0
  13. package/dist/alpha-zero/competitiveRunner.js.map +1 -0
  14. package/dist/alpha-zero/index.d.ts +67 -0
  15. package/dist/alpha-zero/index.d.ts.map +1 -0
  16. package/dist/alpha-zero/index.js +99 -0
  17. package/dist/alpha-zero/index.js.map +1 -0
  18. package/dist/alpha-zero/introspection.d.ts +128 -0
  19. package/dist/alpha-zero/introspection.d.ts.map +1 -0
  20. package/dist/alpha-zero/introspection.js +300 -0
  21. package/dist/alpha-zero/introspection.js.map +1 -0
  22. package/dist/alpha-zero/metricsTracker.d.ts +71 -0
  23. package/dist/alpha-zero/metricsTracker.d.ts.map +1 -0
  24. package/dist/{core → alpha-zero}/metricsTracker.js +5 -2
  25. package/dist/alpha-zero/metricsTracker.js.map +1 -0
  26. package/dist/alpha-zero/security/core.d.ts +125 -0
  27. package/dist/alpha-zero/security/core.d.ts.map +1 -0
  28. package/dist/alpha-zero/security/core.js +271 -0
  29. package/dist/alpha-zero/security/core.js.map +1 -0
  30. package/dist/alpha-zero/security/google.d.ts +125 -0
  31. package/dist/alpha-zero/security/google.d.ts.map +1 -0
  32. package/dist/alpha-zero/security/google.js +311 -0
  33. package/dist/alpha-zero/security/google.js.map +1 -0
  34. package/dist/alpha-zero/security/googleLoader.d.ts +17 -0
  35. package/dist/alpha-zero/security/googleLoader.d.ts.map +1 -0
  36. package/dist/alpha-zero/security/googleLoader.js +41 -0
  37. package/dist/alpha-zero/security/googleLoader.js.map +1 -0
  38. package/dist/alpha-zero/security/index.d.ts +29 -0
  39. package/dist/alpha-zero/security/index.d.ts.map +1 -0
  40. package/dist/alpha-zero/security/index.js +32 -0
  41. package/dist/alpha-zero/security/index.js.map +1 -0
  42. package/dist/alpha-zero/security/simulation.d.ts +124 -0
  43. package/dist/alpha-zero/security/simulation.d.ts.map +1 -0
  44. package/dist/alpha-zero/security/simulation.js +277 -0
  45. package/dist/alpha-zero/security/simulation.js.map +1 -0
  46. package/dist/alpha-zero/selfModification.d.ts +109 -0
  47. package/dist/alpha-zero/selfModification.d.ts.map +1 -0
  48. package/dist/alpha-zero/selfModification.js +233 -0
  49. package/dist/alpha-zero/selfModification.js.map +1 -0
  50. package/dist/alpha-zero/types.d.ts +170 -0
  51. package/dist/alpha-zero/types.d.ts.map +1 -0
  52. package/dist/alpha-zero/types.js +31 -0
  53. package/dist/alpha-zero/types.js.map +1 -0
  54. package/dist/bin/erosolar.js +1 -3
  55. package/dist/bin/erosolar.js.map +1 -1
  56. package/dist/capabilities/agentSpawningCapability.d.ts.map +1 -1
  57. package/dist/capabilities/agentSpawningCapability.js +31 -56
  58. package/dist/capabilities/agentSpawningCapability.js.map +1 -1
  59. package/dist/capabilities/securityTestingCapability.d.ts +13 -0
  60. package/dist/capabilities/securityTestingCapability.d.ts.map +1 -0
  61. package/dist/capabilities/securityTestingCapability.js +25 -0
  62. package/dist/capabilities/securityTestingCapability.js.map +1 -0
  63. package/dist/contracts/agent-schemas.json +15 -0
  64. package/dist/contracts/tools.schema.json +9 -0
  65. package/dist/core/agent.d.ts +2 -2
  66. package/dist/core/agent.d.ts.map +1 -1
  67. package/dist/core/agent.js.map +1 -1
  68. package/dist/core/aiFlowOptimizer.d.ts +26 -0
  69. package/dist/core/aiFlowOptimizer.d.ts.map +1 -0
  70. package/dist/core/aiFlowOptimizer.js +31 -0
  71. package/dist/core/aiFlowOptimizer.js.map +1 -0
  72. package/dist/core/aiOptimizationEngine.d.ts +158 -0
  73. package/dist/core/aiOptimizationEngine.d.ts.map +1 -0
  74. package/dist/core/aiOptimizationEngine.js +428 -0
  75. package/dist/core/aiOptimizationEngine.js.map +1 -0
  76. package/dist/core/aiOptimizationIntegration.d.ts +93 -0
  77. package/dist/core/aiOptimizationIntegration.d.ts.map +1 -0
  78. package/dist/core/aiOptimizationIntegration.js +250 -0
  79. package/dist/core/aiOptimizationIntegration.js.map +1 -0
  80. package/dist/core/customCommands.d.ts +0 -1
  81. package/dist/core/customCommands.d.ts.map +1 -1
  82. package/dist/core/customCommands.js +0 -3
  83. package/dist/core/customCommands.js.map +1 -1
  84. package/dist/core/enhancedErrorRecovery.d.ts +100 -0
  85. package/dist/core/enhancedErrorRecovery.d.ts.map +1 -0
  86. package/dist/core/enhancedErrorRecovery.js +345 -0
  87. package/dist/core/enhancedErrorRecovery.js.map +1 -0
  88. package/dist/core/hooksSystem.d.ts +65 -0
  89. package/dist/core/hooksSystem.d.ts.map +1 -0
  90. package/dist/core/hooksSystem.js +273 -0
  91. package/dist/core/hooksSystem.js.map +1 -0
  92. package/dist/core/memorySystem.d.ts +48 -0
  93. package/dist/core/memorySystem.d.ts.map +1 -0
  94. package/dist/core/memorySystem.js +271 -0
  95. package/dist/core/memorySystem.js.map +1 -0
  96. package/dist/core/toolPreconditions.d.ts.map +1 -1
  97. package/dist/core/toolPreconditions.js +14 -0
  98. package/dist/core/toolPreconditions.js.map +1 -1
  99. package/dist/core/toolRuntime.d.ts +1 -22
  100. package/dist/core/toolRuntime.d.ts.map +1 -1
  101. package/dist/core/toolRuntime.js +5 -0
  102. package/dist/core/toolRuntime.js.map +1 -1
  103. package/dist/core/toolValidation.d.ts.map +1 -1
  104. package/dist/core/toolValidation.js +3 -14
  105. package/dist/core/toolValidation.js.map +1 -1
  106. package/dist/core/unified/errors.d.ts +189 -0
  107. package/dist/core/unified/errors.d.ts.map +1 -0
  108. package/dist/core/unified/errors.js +497 -0
  109. package/dist/core/unified/errors.js.map +1 -0
  110. package/dist/core/unified/index.d.ts +19 -0
  111. package/dist/core/unified/index.d.ts.map +1 -0
  112. package/dist/core/unified/index.js +68 -0
  113. package/dist/core/unified/index.js.map +1 -0
  114. package/dist/core/unified/schema.d.ts +101 -0
  115. package/dist/core/unified/schema.d.ts.map +1 -0
  116. package/dist/core/unified/schema.js +350 -0
  117. package/dist/core/unified/schema.js.map +1 -0
  118. package/dist/core/unified/toolRuntime.d.ts +179 -0
  119. package/dist/core/unified/toolRuntime.d.ts.map +1 -0
  120. package/dist/core/unified/toolRuntime.js +517 -0
  121. package/dist/core/unified/toolRuntime.js.map +1 -0
  122. package/dist/core/unified/tools.d.ts +127 -0
  123. package/dist/core/unified/tools.d.ts.map +1 -0
  124. package/dist/core/unified/tools.js +1333 -0
  125. package/dist/core/unified/tools.js.map +1 -0
  126. package/dist/core/unified/types.d.ts +352 -0
  127. package/dist/core/unified/types.d.ts.map +1 -0
  128. package/dist/core/unified/types.js +12 -0
  129. package/dist/core/unified/types.js.map +1 -0
  130. package/dist/core/unified/version.d.ts +209 -0
  131. package/dist/core/unified/version.d.ts.map +1 -0
  132. package/dist/core/unified/version.js +454 -0
  133. package/dist/core/unified/version.js.map +1 -0
  134. package/dist/core/validationRunner.d.ts +3 -1
  135. package/dist/core/validationRunner.d.ts.map +1 -1
  136. package/dist/core/validationRunner.js.map +1 -1
  137. package/dist/headless/headlessApp.d.ts.map +1 -1
  138. package/dist/headless/headlessApp.js +0 -21
  139. package/dist/headless/headlessApp.js.map +1 -1
  140. package/dist/mcp/sseClient.d.ts.map +1 -1
  141. package/dist/mcp/sseClient.js +18 -9
  142. package/dist/mcp/sseClient.js.map +1 -1
  143. package/dist/plugins/tools/build/buildPlugin.d.ts +6 -0
  144. package/dist/plugins/tools/build/buildPlugin.d.ts.map +1 -1
  145. package/dist/plugins/tools/build/buildPlugin.js +10 -4
  146. package/dist/plugins/tools/build/buildPlugin.js.map +1 -1
  147. package/dist/plugins/tools/nodeDefaults.d.ts.map +1 -1
  148. package/dist/plugins/tools/nodeDefaults.js +2 -0
  149. package/dist/plugins/tools/nodeDefaults.js.map +1 -1
  150. package/dist/plugins/tools/security/securityPlugin.d.ts +3 -0
  151. package/dist/plugins/tools/security/securityPlugin.d.ts.map +1 -0
  152. package/dist/plugins/tools/security/securityPlugin.js +12 -0
  153. package/dist/plugins/tools/security/securityPlugin.js.map +1 -0
  154. package/dist/runtime/agentSession.d.ts +2 -2
  155. package/dist/runtime/agentSession.d.ts.map +1 -1
  156. package/dist/runtime/agentSession.js +2 -2
  157. package/dist/runtime/agentSession.js.map +1 -1
  158. package/dist/security/active-stack-security.d.ts +112 -0
  159. package/dist/security/active-stack-security.d.ts.map +1 -0
  160. package/dist/security/active-stack-security.js +296 -0
  161. package/dist/security/active-stack-security.js.map +1 -0
  162. package/dist/security/advanced-persistence-research.d.ts +92 -0
  163. package/dist/security/advanced-persistence-research.d.ts.map +1 -0
  164. package/dist/security/advanced-persistence-research.js +195 -0
  165. package/dist/security/advanced-persistence-research.js.map +1 -0
  166. package/dist/security/advanced-targeting.d.ts +119 -0
  167. package/dist/security/advanced-targeting.d.ts.map +1 -0
  168. package/dist/security/advanced-targeting.js +233 -0
  169. package/dist/security/advanced-targeting.js.map +1 -0
  170. package/dist/security/assessment/vulnerabilityAssessment.d.ts +104 -0
  171. package/dist/security/assessment/vulnerabilityAssessment.d.ts.map +1 -0
  172. package/dist/security/assessment/vulnerabilityAssessment.js +315 -0
  173. package/dist/security/assessment/vulnerabilityAssessment.js.map +1 -0
  174. package/dist/security/authorization/securityAuthorization.d.ts +88 -0
  175. package/dist/security/authorization/securityAuthorization.d.ts.map +1 -0
  176. package/dist/security/authorization/securityAuthorization.js +172 -0
  177. package/dist/security/authorization/securityAuthorization.js.map +1 -0
  178. package/dist/security/comprehensive-targeting.d.ts +85 -0
  179. package/dist/security/comprehensive-targeting.d.ts.map +1 -0
  180. package/dist/security/comprehensive-targeting.js +438 -0
  181. package/dist/security/comprehensive-targeting.js.map +1 -0
  182. package/dist/security/global-security-integration.d.ts +91 -0
  183. package/dist/security/global-security-integration.d.ts.map +1 -0
  184. package/dist/security/global-security-integration.js +218 -0
  185. package/dist/security/global-security-integration.js.map +1 -0
  186. package/dist/security/index.d.ts +38 -0
  187. package/dist/security/index.d.ts.map +1 -0
  188. package/dist/security/index.js +47 -0
  189. package/dist/security/index.js.map +1 -0
  190. package/dist/security/persistence-analyzer.d.ts +56 -0
  191. package/dist/security/persistence-analyzer.d.ts.map +1 -0
  192. package/dist/security/persistence-analyzer.js +187 -0
  193. package/dist/security/persistence-analyzer.js.map +1 -0
  194. package/dist/security/persistence-cli.d.ts +36 -0
  195. package/dist/security/persistence-cli.d.ts.map +1 -0
  196. package/dist/security/persistence-cli.js +160 -0
  197. package/dist/security/persistence-cli.js.map +1 -0
  198. package/dist/security/persistence-research.d.ts +92 -0
  199. package/dist/security/persistence-research.d.ts.map +1 -0
  200. package/dist/security/persistence-research.js +364 -0
  201. package/dist/security/persistence-research.js.map +1 -0
  202. package/dist/security/research/persistenceResearch.d.ts +97 -0
  203. package/dist/security/research/persistenceResearch.d.ts.map +1 -0
  204. package/dist/security/research/persistenceResearch.js +282 -0
  205. package/dist/security/research/persistenceResearch.js.map +1 -0
  206. package/dist/security/security-integration.d.ts +74 -0
  207. package/dist/security/security-integration.d.ts.map +1 -0
  208. package/dist/security/security-integration.js +137 -0
  209. package/dist/security/security-integration.js.map +1 -0
  210. package/dist/security/security-testing-framework.d.ts +112 -0
  211. package/dist/security/security-testing-framework.d.ts.map +1 -0
  212. package/dist/security/security-testing-framework.js +364 -0
  213. package/dist/security/security-testing-framework.js.map +1 -0
  214. package/dist/security/simulation/attackSimulation.d.ts +93 -0
  215. package/dist/security/simulation/attackSimulation.d.ts.map +1 -0
  216. package/dist/security/simulation/attackSimulation.js +341 -0
  217. package/dist/security/simulation/attackSimulation.js.map +1 -0
  218. package/dist/security/strategic-operations.d.ts +100 -0
  219. package/dist/security/strategic-operations.d.ts.map +1 -0
  220. package/dist/security/strategic-operations.js +276 -0
  221. package/dist/security/strategic-operations.js.map +1 -0
  222. package/dist/security/tool-security-wrapper.d.ts +58 -0
  223. package/dist/security/tool-security-wrapper.d.ts.map +1 -0
  224. package/dist/security/tool-security-wrapper.js +156 -0
  225. package/dist/security/tool-security-wrapper.js.map +1 -0
  226. package/dist/shell/claudeCodeStreamHandler.d.ts +145 -0
  227. package/dist/shell/claudeCodeStreamHandler.d.ts.map +1 -0
  228. package/dist/shell/claudeCodeStreamHandler.js +322 -0
  229. package/dist/shell/claudeCodeStreamHandler.js.map +1 -0
  230. package/dist/shell/inputQueueManager.d.ts +144 -0
  231. package/dist/shell/inputQueueManager.d.ts.map +1 -0
  232. package/dist/shell/inputQueueManager.js +290 -0
  233. package/dist/shell/inputQueueManager.js.map +1 -0
  234. package/dist/shell/interactiveShell.d.ts +7 -16
  235. package/dist/shell/interactiveShell.d.ts.map +1 -1
  236. package/dist/shell/interactiveShell.js +159 -221
  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 +106 -98
  254. package/dist/shell/terminalInput.d.ts.map +1 -1
  255. package/dist/shell/terminalInput.js +477 -514
  256. package/dist/shell/terminalInput.js.map +1 -1
  257. package/dist/shell/terminalInputAdapter.d.ts +20 -41
  258. package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
  259. package/dist/shell/terminalInputAdapter.js +30 -45
  260. package/dist/shell/terminalInputAdapter.js.map +1 -1
  261. package/dist/subagents/taskRunner.d.ts +1 -7
  262. package/dist/subagents/taskRunner.d.ts.map +1 -1
  263. package/dist/subagents/taskRunner.js +47 -180
  264. package/dist/subagents/taskRunner.js.map +1 -1
  265. package/dist/tools/securityTools.d.ts +22 -0
  266. package/dist/tools/securityTools.d.ts.map +1 -0
  267. package/dist/tools/securityTools.js +448 -0
  268. package/dist/tools/securityTools.js.map +1 -0
  269. package/dist/ui/ShellUIAdapter.d.ts.map +1 -1
  270. package/dist/ui/ShellUIAdapter.js +12 -13
  271. package/dist/ui/ShellUIAdapter.js.map +1 -1
  272. package/dist/ui/display.d.ts +45 -24
  273. package/dist/ui/display.d.ts.map +1 -1
  274. package/dist/ui/display.js +259 -140
  275. package/dist/ui/display.js.map +1 -1
  276. package/dist/ui/persistentPrompt.d.ts +50 -0
  277. package/dist/ui/persistentPrompt.d.ts.map +1 -0
  278. package/dist/ui/persistentPrompt.js +92 -0
  279. package/dist/ui/persistentPrompt.js.map +1 -0
  280. package/dist/ui/terminalUISchema.d.ts +195 -0
  281. package/dist/ui/terminalUISchema.d.ts.map +1 -0
  282. package/dist/ui/terminalUISchema.js +113 -0
  283. package/dist/ui/terminalUISchema.js.map +1 -0
  284. package/dist/ui/theme.d.ts.map +1 -1
  285. package/dist/ui/theme.js +8 -6
  286. package/dist/ui/theme.js.map +1 -1
  287. package/dist/ui/toolDisplay.d.ts +158 -0
  288. package/dist/ui/toolDisplay.d.ts.map +1 -1
  289. package/dist/ui/toolDisplay.js +348 -0
  290. package/dist/ui/toolDisplay.js.map +1 -1
  291. package/dist/ui/unified/layout.d.ts +0 -1
  292. package/dist/ui/unified/layout.d.ts.map +1 -1
  293. package/dist/ui/unified/layout.js +25 -15
  294. package/dist/ui/unified/layout.js.map +1 -1
  295. package/package.json +4 -4
  296. package/scripts/deploy-security-capabilities.js +178 -0
  297. package/dist/core/hooks.d.ts +0 -113
  298. package/dist/core/hooks.d.ts.map +0 -1
  299. package/dist/core/hooks.js +0 -267
  300. package/dist/core/hooks.js.map +0 -1
  301. package/dist/core/metricsTracker.d.ts +0 -122
  302. package/dist/core/metricsTracker.d.ts.map +0 -1
  303. package/dist/core/metricsTracker.js.map +0 -1
  304. package/dist/core/securityAssessment.d.ts +0 -91
  305. package/dist/core/securityAssessment.d.ts.map +0 -1
  306. package/dist/core/securityAssessment.js +0 -580
  307. package/dist/core/securityAssessment.js.map +0 -1
  308. package/dist/core/verification.d.ts +0 -137
  309. package/dist/core/verification.d.ts.map +0 -1
  310. package/dist/core/verification.js +0 -323
  311. package/dist/core/verification.js.map +0 -1
  312. package/dist/subagents/agentConfig.d.ts +0 -27
  313. package/dist/subagents/agentConfig.d.ts.map +0 -1
  314. package/dist/subagents/agentConfig.js +0 -89
  315. package/dist/subagents/agentConfig.js.map +0 -1
  316. package/dist/subagents/agentRegistry.d.ts +0 -33
  317. package/dist/subagents/agentRegistry.d.ts.map +0 -1
  318. package/dist/subagents/agentRegistry.js +0 -162
  319. package/dist/subagents/agentRegistry.js.map +0 -1
  320. package/dist/utils/frontmatter.d.ts +0 -10
  321. package/dist/utils/frontmatter.d.ts.map +0 -1
  322. package/dist/utils/frontmatter.js +0 -78
  323. package/dist/utils/frontmatter.js.map +0 -1
@@ -3,18 +3,15 @@
3
3
  *
4
4
  * Design principles:
5
5
  * - Single source of truth for input state
6
- * - Content flows naturally from top to bottom (no scroll region pinning)
7
6
  * - Native bracketed paste support (no heuristics)
8
7
  * - Clean cursor model with render-time wrapping
9
8
  * - State machine for different input modes
10
9
  * - No readline dependency for display
11
10
  */
12
11
  import { EventEmitter } from 'node:events';
13
- import { isMultilinePaste } from '../core/multilinePasteHandler.js';
12
+ import { isMultilinePaste, generatePasteSummary } from '../core/multilinePasteHandler.js';
14
13
  import { writeLock } from '../ui/writeLock.js';
15
- import { renderDivider, renderStatusLine } from '../ui/unified/layout.js';
16
- import { isStreamingMode } from '../ui/globalWriteLock.js';
17
- import { formatThinking } from '../ui/toolDisplay.js';
14
+ import { UI_COLORS, DEFAULT_UI_CONFIG, } from '../ui/terminalUISchema.js';
18
15
  // ANSI escape codes
19
16
  const ESC = {
20
17
  // Cursor control
@@ -24,12 +21,12 @@ const ESC = {
24
21
  SHOW: '\x1b[?25h',
25
22
  TO: (row, col) => `\x1b[${row};${col}H`,
26
23
  TO_COL: (col) => `\x1b[${col}G`,
24
+ // Screen control
25
+ CLEAR_SCREEN: '\x1b[2J',
26
+ HOME: '\x1b[H',
27
27
  // Line control
28
28
  CLEAR_LINE: '\x1b[2K',
29
29
  CLEAR_TO_END: '\x1b[0J',
30
- // Scroll region
31
- SET_SCROLL: (top, bottom) => `\x1b[${top};${bottom}r`,
32
- RESET_SCROLL: '\x1b[r',
33
30
  // Style
34
31
  RESET: '\x1b[0m',
35
32
  DIM: '\x1b[2m',
@@ -69,46 +66,47 @@ export class TerminalInput extends EventEmitter {
69
66
  statusMessage = null;
70
67
  overrideStatusMessage = null; // Secondary status (warnings, etc.)
71
68
  streamingLabel = null; // Streaming progress indicator
72
- metaElapsedSeconds = null; // Optional elapsed time for header line
73
- metaTokensUsed = null; // Optional token usage
74
- metaTokenLimit = null; // Optional token window
75
- metaThinkingMs = null; // Optional thinking duration
76
- metaThinkingHasContent = false; // Whether collapsed thinking content exists
77
69
  lastRenderContent = '';
78
70
  lastRenderCursor = -1;
79
71
  renderDirty = false;
80
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 (for idle mode positioning)
76
+ // Command suggestions (Claude Code style auto-complete)
77
+ commandSuggestions = [];
78
+ filteredSuggestions = [];
79
+ selectedSuggestionIndex = 0;
80
+ showSuggestions = false;
81
81
  // Lifecycle
82
82
  disposed = false;
83
83
  enabled = true;
84
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;
89
85
  editMode = 'display-edits';
90
86
  verificationEnabled = true;
91
87
  autoContinueEnabled = false;
92
88
  verificationHotkey = 'alt+v';
93
89
  autoContinueHotkey = 'alt+c';
94
- thinkingHotkey = '/thinking';
95
- modelLabel = null;
96
- providerLabel = null;
97
90
  // Output interceptor cleanup
98
91
  outputInterceptorCleanup;
99
- // Streaming render throttle
100
- lastStreamingRender = 0;
101
- streamingRenderInterval = 250; // ms between renders during streaming
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)
102
97
  streamingRenderTimer = null;
98
+ // Unified UI initialization flag
99
+ unifiedUIInitialized = false;
103
100
  constructor(writeStream = process.stdout, config = {}) {
104
101
  super();
105
102
  this.out = writeStream;
103
+ // Use schema defaults for configuration consistency
106
104
  this.config = {
107
- maxLines: config.maxLines ?? 1000,
108
- maxLength: config.maxLength ?? 10000,
105
+ maxLines: config.maxLines ?? DEFAULT_UI_CONFIG.inputArea.maxLines,
106
+ maxLength: config.maxLength ?? DEFAULT_UI_CONFIG.inputArea.maxLength,
109
107
  maxQueueSize: config.maxQueueSize ?? 100,
110
- promptChar: config.promptChar ?? '> ',
111
- continuationChar: config.continuationChar ?? '│ ',
108
+ promptChar: config.promptChar ?? DEFAULT_UI_CONFIG.inputArea.promptChar,
109
+ continuationChar: config.continuationChar ?? DEFAULT_UI_CONFIG.inputArea.continuationChar,
112
110
  };
113
111
  }
114
112
  // ===========================================================================
@@ -187,36 +185,288 @@ export class TerminalInput extends EventEmitter {
187
185
  if (handled)
188
186
  return;
189
187
  }
188
+ // Handle '?' for help hint (if buffer is empty)
189
+ if (str === '?' && this.buffer.length === 0) {
190
+ this.emit('showHelp');
191
+ return;
192
+ }
190
193
  // Insert printable characters
191
194
  if (str && !key?.ctrl && !key?.meta) {
192
195
  this.insertText(str);
193
196
  }
194
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.
208
+ *
209
+ * Layout:
210
+ * 1. Clear screen
211
+ * 2. Write banner at top
212
+ * 3. Track content end position
213
+ * 4. Render floating input area below banner
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 and track where it ends
225
+ let bannerLines = 0;
226
+ if (this.bannerContent) {
227
+ const lines = this.bannerContent.split('\n');
228
+ bannerLines = lines.length + 2; // +2 for the trailing \n\n
229
+ process.stdout.write(this.bannerContent + '\n\n');
230
+ }
231
+ // Set content end row so input renders right after banner
232
+ this.contentEndRow = bannerLines > 0 ? bannerLines : 1;
233
+ // Mark initialized
234
+ this.unifiedUIInitialized = true;
235
+ // Render floating input area below the banner
236
+ this.renderFloatingInputArea();
237
+ }
238
+ /**
239
+ * Clear the input area at its tracked position.
240
+ * Returns true if something was cleared.
241
+ */
242
+ clearInputArea() {
243
+ if (this.inputAreaStartRow > 0 && this.flowModeRenderedLines > 0) {
244
+ for (let i = 0; i < this.flowModeRenderedLines; i++) {
245
+ this.write(ESC.TO(this.inputAreaStartRow + i, 1));
246
+ this.write(ESC.CLEAR_LINE);
247
+ }
248
+ return true;
249
+ }
250
+ return false;
251
+ }
252
+ /**
253
+ * Reset input area tracking state.
254
+ */
255
+ resetInputAreaTracking() {
256
+ this.inputAreaStartRow = 0;
257
+ this.flowModeRenderedLines = 0;
258
+ }
259
+ /**
260
+ * Render floating input area below current content.
261
+ * This is "bottom floating" - follows content, not pinned to terminal bottom.
262
+ * Uses absolute positioning to prevent duplicates.
263
+ */
264
+ renderFloatingInputArea() {
265
+ const { rows, cols } = this.getSize();
266
+ const divider = '─'.repeat(cols - 1);
267
+ const { dim: DIM, reset: R } = UI_COLORS;
268
+ // Calculate lines needed for input area
269
+ const linesNeeded = 5 + (this.modelInfo ? 1 : 0);
270
+ // FIRST: Clear any previously rendered input area
271
+ this.clearInputArea();
272
+ // Hide cursor during render
273
+ this.write(ESC.HIDE);
274
+ // Calculate where to render: after current content
275
+ // Use contentEndRow if set, otherwise estimate from terminal bottom
276
+ let startRow;
277
+ if (this.contentEndRow > 0) {
278
+ startRow = this.contentEndRow + 1;
279
+ }
280
+ else {
281
+ // Render near bottom, leaving space for input area
282
+ startRow = Math.max(1, rows - linesNeeded);
283
+ }
284
+ // Ensure we don't go past terminal bounds
285
+ startRow = Math.min(startRow, rows - linesNeeded + 1);
286
+ startRow = Math.max(1, startRow);
287
+ // Track this position
288
+ this.inputAreaStartRow = startRow;
289
+ let currentRow = startRow;
290
+ // Status bar
291
+ this.write(ESC.TO(currentRow, 1));
292
+ this.write(this.buildStatusBar(cols));
293
+ currentRow++;
294
+ // Model info line (if set)
295
+ if (this.modelInfo) {
296
+ this.write(ESC.TO(currentRow, 1));
297
+ let modelLine = `${DIM}${this.modelInfo}${R}`;
298
+ if (this.contextUsage !== null) {
299
+ const rem = Math.max(0, 100 - this.contextUsage);
300
+ if (rem < 10)
301
+ modelLine += ` ${UI_COLORS.red}⚠ ctx: ${rem}%${R}`;
302
+ else if (rem < 25)
303
+ modelLine += ` ${UI_COLORS.yellow}! ctx: ${rem}%${R}`;
304
+ else
305
+ modelLine += ` ${DIM}· ctx: ${rem}%${R}`;
306
+ }
307
+ this.write(modelLine);
308
+ currentRow++;
309
+ }
310
+ // Top divider
311
+ this.write(ESC.TO(currentRow, 1));
312
+ this.write(divider);
313
+ currentRow++;
314
+ // Input line with prompt and buffer content
315
+ const { lines, cursorCol } = this.wrapBuffer(cols - 4);
316
+ const displayLine = lines[0] ?? '';
317
+ const inputRow = currentRow;
318
+ this.write(ESC.TO(currentRow, 1));
319
+ this.write(ESC.BG_DARK + ESC.DIM + this.config.promptChar + ESC.RESET);
320
+ this.write(ESC.BG_DARK + displayLine);
321
+ const padding = Math.max(0, cols - this.config.promptChar.length - displayLine.length - 1);
322
+ if (padding > 0)
323
+ this.write(' '.repeat(padding));
324
+ this.write(ESC.RESET);
325
+ currentRow++;
326
+ // Bottom divider
327
+ this.write(ESC.TO(currentRow, 1));
328
+ this.write(divider);
329
+ currentRow++;
330
+ // Mode controls
331
+ this.write(ESC.TO(currentRow, 1));
332
+ this.write(this.buildModeControls(cols));
333
+ // Track lines rendered
334
+ this.flowModeRenderedLines = currentRow - startRow + 1;
335
+ // Position cursor in input line for typing
336
+ this.write(ESC.TO(inputRow, this.config.promptChar.length + 1 + cursorCol));
337
+ // Show cursor
338
+ this.write(ESC.SHOW);
339
+ // Update tracking
340
+ this.lastRenderContent = this.buffer;
341
+ this.lastRenderCursor = this.cursor;
342
+ }
195
343
  /**
196
344
  * Set the input mode
197
345
  *
198
- * Content flows naturally - no scroll region pinning.
346
+ * Unified floating input - input area always floats below content.
199
347
  */
200
348
  setMode(mode) {
201
349
  const prevMode = this.mode;
202
350
  this.mode = mode;
203
351
  if (mode === 'streaming' && prevMode !== 'streaming') {
204
- this.resetStreamingRenderThrottle();
352
+ // Track streaming start time for elapsed display
353
+ this.streamingStartTime = Date.now();
354
+ // Ensure unified UI is initialized
355
+ if (!this.unifiedUIInitialized) {
356
+ this.initializeUnifiedUI();
357
+ }
205
358
  this.renderDirty = true;
206
- this.render();
359
+ this.scheduleRender();
207
360
  }
208
361
  else if (mode !== 'streaming' && prevMode === 'streaming') {
209
- // Streaming ended - render the input area
210
- this.resetStreamingRenderThrottle();
211
- this.forceRender();
362
+ // Stop streaming render timer (if any)
363
+ if (this.streamingRenderTimer) {
364
+ clearInterval(this.streamingRenderTimer);
365
+ this.streamingRenderTimer = null;
366
+ }
367
+ // Reset streaming time
368
+ this.streamingStartTime = null;
369
+ // Re-render floating input area
370
+ this.renderDirty = true;
371
+ this.scheduleRender();
372
+ }
373
+ }
374
+ /**
375
+ * Set the row where content ends (for idle mode positioning).
376
+ * Input area will render starting from this row + 1.
377
+ */
378
+ setContentEndRow(row) {
379
+ this.contentEndRow = Math.max(0, row);
380
+ this.renderDirty = true;
381
+ this.scheduleRender();
382
+ }
383
+ /**
384
+ * Set available slash commands for auto-complete suggestions.
385
+ */
386
+ setCommands(commands) {
387
+ this.commandSuggestions = commands;
388
+ this.updateSuggestions();
389
+ }
390
+ /**
391
+ * Update filtered suggestions based on current input.
392
+ */
393
+ updateSuggestions() {
394
+ const input = this.buffer.trim();
395
+ // Only show suggestions when input starts with "/"
396
+ if (!input.startsWith('/')) {
397
+ this.showSuggestions = false;
398
+ this.filteredSuggestions = [];
399
+ this.selectedSuggestionIndex = 0;
400
+ return;
401
+ }
402
+ const query = input.toLowerCase();
403
+ this.filteredSuggestions = this.commandSuggestions.filter(cmd => cmd.command.toLowerCase().startsWith(query) ||
404
+ cmd.command.toLowerCase().includes(query.slice(1)));
405
+ // Show suggestions if we have matches
406
+ this.showSuggestions = this.filteredSuggestions.length > 0;
407
+ // Keep selection in bounds
408
+ if (this.selectedSuggestionIndex >= this.filteredSuggestions.length) {
409
+ this.selectedSuggestionIndex = Math.max(0, this.filteredSuggestions.length - 1);
212
410
  }
213
411
  }
214
412
  /**
215
- * Legacy method - no longer used (content flows naturally).
216
- * @deprecated Use setContentRow instead
413
+ * Select next suggestion (arrow down / tab).
414
+ */
415
+ selectNextSuggestion() {
416
+ if (!this.showSuggestions || this.filteredSuggestions.length === 0)
417
+ return;
418
+ this.selectedSuggestionIndex = (this.selectedSuggestionIndex + 1) % this.filteredSuggestions.length;
419
+ this.renderDirty = true;
420
+ this.scheduleRender();
421
+ }
422
+ /**
423
+ * Select previous suggestion (arrow up / shift+tab).
424
+ */
425
+ selectPrevSuggestion() {
426
+ if (!this.showSuggestions || this.filteredSuggestions.length === 0)
427
+ return;
428
+ this.selectedSuggestionIndex = this.selectedSuggestionIndex === 0
429
+ ? this.filteredSuggestions.length - 1
430
+ : this.selectedSuggestionIndex - 1;
431
+ this.renderDirty = true;
432
+ this.scheduleRender();
433
+ }
434
+ /**
435
+ * Accept current suggestion and insert into buffer.
436
+ */
437
+ acceptSuggestion() {
438
+ if (!this.showSuggestions || this.filteredSuggestions.length === 0)
439
+ return false;
440
+ const selected = this.filteredSuggestions[this.selectedSuggestionIndex];
441
+ if (!selected)
442
+ return false;
443
+ // Replace buffer with selected command
444
+ this.buffer = selected.command + ' ';
445
+ this.cursor = this.buffer.length;
446
+ this.showSuggestions = false;
447
+ this.renderDirty = true;
448
+ this.scheduleRender();
449
+ return true;
450
+ }
451
+ /**
452
+ * Check if suggestions are visible.
453
+ */
454
+ areSuggestionsVisible() {
455
+ return this.showSuggestions && this.filteredSuggestions.length > 0;
456
+ }
457
+ /**
458
+ * Toggle thinking/reasoning mode
459
+ */
460
+ toggleThinking() {
461
+ this.thinkingEnabled = !this.thinkingEnabled;
462
+ this.emit('thinkingToggle', this.thinkingEnabled);
463
+ this.scheduleRender();
464
+ }
465
+ /**
466
+ * Get thinking enabled state
217
467
  */
218
- setPinnedHeaderLines(_count) {
219
- // No-op: scroll region pinning removed
468
+ isThinkingEnabled() {
469
+ return this.thinkingEnabled;
220
470
  }
221
471
  /**
222
472
  * Get current mode
@@ -249,14 +499,17 @@ export class TerminalInput extends EventEmitter {
249
499
  }
250
500
  /**
251
501
  * Clear the buffer
502
+ * @param skipRender - If true, don't trigger a re-render (used during submit flow)
252
503
  */
253
- clear() {
504
+ clear(skipRender = false) {
254
505
  this.buffer = '';
255
506
  this.cursor = 0;
256
507
  this.historyIndex = -1;
257
508
  this.tempInput = '';
258
509
  this.pastePlaceholders = [];
259
- this.scheduleRender();
510
+ if (!skipRender) {
511
+ this.scheduleRender();
512
+ }
260
513
  }
261
514
  /**
262
515
  * Get queued inputs
@@ -327,37 +580,6 @@ export class TerminalInput extends EventEmitter {
327
580
  this.streamingLabel = next;
328
581
  this.scheduleRender();
329
582
  }
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
- }
361
583
  /**
362
584
  * Keep mode toggles (verification/auto-continue) visible in the control bar.
363
585
  * Hotkey labels remain stable so the bar looks the same before/during streaming.
@@ -367,22 +589,26 @@ export class TerminalInput extends EventEmitter {
367
589
  const nextAutoContinue = !!options.autoContinueEnabled;
368
590
  const nextVerifyHotkey = options.verificationHotkey ?? this.verificationHotkey;
369
591
  const nextAutoHotkey = options.autoContinueHotkey ?? this.autoContinueHotkey;
370
- const nextThinkingHotkey = options.thinkingHotkey ?? this.thinkingHotkey;
371
- const nextThinkingLabel = options.thinkingModeLabel === undefined ? this.thinkingModeLabel : (options.thinkingModeLabel || null);
372
592
  if (this.verificationEnabled === nextVerification &&
373
593
  this.autoContinueEnabled === nextAutoContinue &&
374
594
  this.verificationHotkey === nextVerifyHotkey &&
375
- this.autoContinueHotkey === nextAutoHotkey &&
376
- this.thinkingHotkey === nextThinkingHotkey &&
377
- this.thinkingModeLabel === nextThinkingLabel) {
595
+ this.autoContinueHotkey === nextAutoHotkey) {
378
596
  return;
379
597
  }
380
598
  this.verificationEnabled = nextVerification;
381
599
  this.autoContinueEnabled = nextAutoContinue;
382
600
  this.verificationHotkey = nextVerifyHotkey;
383
601
  this.autoContinueHotkey = nextAutoHotkey;
384
- this.thinkingHotkey = nextThinkingHotkey;
385
- this.thinkingModeLabel = nextThinkingLabel;
602
+ this.scheduleRender();
603
+ }
604
+ /**
605
+ * Set the model info string (e.g., "OpenAI · gpt-4")
606
+ * This is displayed persistently above the input area.
607
+ */
608
+ setModelInfo(info) {
609
+ if (this.modelInfo === info)
610
+ return;
611
+ this.modelInfo = info;
386
612
  this.scheduleRender();
387
613
  }
388
614
  /**
@@ -395,155 +621,30 @@ export class TerminalInput extends EventEmitter {
395
621
  this.scheduleRender();
396
622
  }
397
623
  /**
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.
412
- *
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.
624
+ * Render the input area - always floating below content.
416
625
  */
417
626
  render() {
418
627
  if (!this.canRender())
419
628
  return;
420
629
  if (this.isRendering)
421
630
  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
- }
433
631
  const shouldSkip = !this.renderDirty &&
434
632
  this.buffer === this.lastRenderContent &&
435
633
  this.cursor === this.lastRenderCursor;
436
634
  this.renderDirty = false;
635
+ // Skip if nothing changed (unless explicitly forced)
437
636
  if (shouldSkip) {
438
637
  return;
439
638
  }
639
+ // If write lock is held, defer render
440
640
  if (writeLock.isLocked()) {
441
641
  writeLock.safeWrite(() => this.render());
442
642
  return;
443
643
  }
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');
474
644
  this.isRendering = true;
645
+ writeLock.lock('terminalInput.render');
475
646
  try {
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);
483
- }
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;
546
- }
647
+ this.renderFloatingInputArea();
547
648
  }
548
649
  finally {
549
650
  writeLock.unlock();
@@ -551,217 +652,99 @@ export class TerminalInput extends EventEmitter {
551
652
  }
552
653
  }
553
654
  /**
554
- * Build one or more compact meta lines above the divider (thinking, status, usage).
555
- * During streaming, shows model line pinned above streaming info.
655
+ * Build status bar showing streaming/ready status and key info.
656
+ * This is the TOP line above the input area - minimal Claude Code style.
556
657
  */
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' });
573
- }
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));
658
+ buildStatusBar(cols) {
659
+ const maxWidth = cols - 2;
660
+ const parts = [];
661
+ // Streaming status with elapsed time (left side)
662
+ if (this.mode === 'streaming') {
663
+ let statusText = '● Streaming';
664
+ if (this.streamingStartTime) {
665
+ const elapsed = Math.floor((Date.now() - this.streamingStartTime) / 1000);
666
+ const mins = Math.floor(elapsed / 60);
667
+ const secs = elapsed % 60;
668
+ statusText += mins > 0 ? ` ${mins}m ${secs}s` : ` ${secs}s`;
580
669
  }
581
- return lines;
582
- }
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));
670
+ parts.push(`\x1b[32m${statusText}\x1b[0m`); // Green
587
671
  }
588
- const statusParts = [];
589
- const statusLabel = this.statusMessage ?? this.streamingLabel;
590
- if (statusLabel) {
591
- statusParts.push({ text: statusLabel, tone: 'info' });
672
+ // Queue indicator during streaming
673
+ if (this.mode === 'streaming' && this.queue.length > 0) {
674
+ parts.push(`\x1b[36mqueued: ${this.queue.length}\x1b[0m`); // Cyan
592
675
  }
593
- if (this.metaElapsedSeconds !== null) {
594
- statusParts.push({ text: this.formatElapsedLabel(this.metaElapsedSeconds), tone: 'muted' });
595
- }
596
- const tokensRemaining = this.computeTokensRemaining();
597
- if (tokensRemaining !== null) {
598
- statusParts.push({ text: `↓ ${tokensRemaining}`, tone: 'muted' });
599
- }
600
- if (statusParts.length) {
601
- lines.push(renderStatusLine(statusParts, width));
676
+ // Paste indicator
677
+ if (this.pastePlaceholders.length > 0) {
678
+ const totalLines = this.pastePlaceholders.reduce((sum, p) => sum + p.lineCount, 0);
679
+ parts.push(`\x1b[36m📋 ${totalLines}L\x1b[0m`);
602
680
  }
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' });
681
+ // Override/warning status
682
+ if (this.overrideStatusMessage) {
683
+ parts.push(`\x1b[33m⚠ ${this.overrideStatusMessage}\x1b[0m`); // Yellow
608
684
  }
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 });
685
+ // If idle with empty buffer, show quick shortcuts
686
+ if (this.mode !== 'streaming' && this.buffer.length === 0 && parts.length === 0) {
687
+ return `${ESC.DIM}Type a message or / for commands${ESC.RESET}`;
613
688
  }
614
- if (this.queue.length > 0) {
615
- usageParts.push({ text: `queued ${this.queue.length}`, tone: 'info' });
689
+ // Multi-line indicator
690
+ if (this.buffer.includes('\n')) {
691
+ parts.push(`${ESC.DIM}${this.buffer.split('\n').length}L${ESC.RESET}`);
616
692
  }
617
- if (usageParts.length) {
618
- lines.push(renderStatusLine(usageParts, width));
693
+ if (parts.length === 0) {
694
+ return ''; // Empty status bar when idle
619
695
  }
620
- return lines;
696
+ const joined = parts.join(`${ESC.DIM} · ${ESC.RESET}`);
697
+ return joined.slice(0, maxWidth);
621
698
  }
622
699
  /**
623
- * Build Claude Code style mode controls line.
624
- * Combines streaming label + override status + main status for simultaneous display.
700
+ * Build mode controls line showing toggles and context info.
701
+ * This is the BOTTOM line below the input area - Claude Code style layout with erosolar features.
702
+ *
703
+ * Layout: [toggles on left] ... [context info on right]
625
704
  */
626
705
  buildModeControls(cols) {
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' });
706
+ const maxWidth = cols - 2;
707
+ // Use schema-defined colors for consistency
708
+ const { green: GREEN, yellow: YELLOW, cyan: CYAN, magenta: MAGENTA, red: RED, dim: DIM, reset: R } = UI_COLORS;
709
+ // Mode toggles with colors (following ModeControlsSchema)
710
+ const toggles = [];
711
+ // Edit mode (green=auto, yellow=ask) - per schema.editMode
712
+ if (this.editMode === 'display-edits') {
713
+ toggles.push(`${GREEN}⏵⏵ auto-edit${R}`);
632
714
  }
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
- };
715
+ else {
716
+ toggles.push(`${YELLOW}⏸⏸ ask-first${R}`);
717
+ }
718
+ // Thinking mode (cyan when on) - per schema.thinkingMode
719
+ toggles.push(this.thinkingEnabled ? `${CYAN}💭 think${R}` : `${DIM}○ think${R}`);
720
+ // Verification (green when on) - per schema.verificationMode
721
+ toggles.push(this.verificationEnabled ? `${GREEN}✓ verify${R}` : `${DIM}○ verify${R}`);
722
+ // Auto-continue (magenta when on) - per schema.autoContinueMode
723
+ toggles.push(this.autoContinueEnabled ? `${MAGENTA}↻ auto${R}` : `${DIM}○ auto${R}`);
724
+ const leftPart = toggles.join(`${DIM} · ${R}`) + `${DIM} (⇧⇥)${R}`;
725
+ // Context usage with color - per schema.contextUsage thresholds
726
+ let rightPart = '';
727
+ if (this.contextUsage !== null) {
728
+ const rem = Math.max(0, 100 - this.contextUsage);
729
+ // Thresholds: critical < 10%, warning < 25%
730
+ if (rem < 10)
731
+ rightPart = `${RED}⚠ ctx: ${rem}%${R}`;
732
+ else if (rem < 25)
733
+ rightPart = `${YELLOW}! ctx: ${rem}%${R}`;
734
+ else
735
+ rightPart = `${DIM}ctx: ${rem}%${R}`;
736
+ }
737
+ // Calculate visible lengths (strip ANSI)
738
+ const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
739
+ const leftLen = strip(leftPart).length;
740
+ const rightLen = strip(rightPart).length;
741
+ if (leftLen + rightLen < maxWidth - 4) {
742
+ return `${leftPart}${' '.repeat(maxWidth - leftLen - rightLen)}${rightPart}`;
743
+ }
744
+ if (rightLen > 0 && leftLen + 8 < maxWidth) {
745
+ return `${leftPart} ${rightPart}`;
746
+ }
747
+ return leftPart;
765
748
  }
766
749
  /**
767
750
  * Force a re-render
@@ -784,91 +767,32 @@ export class TerminalInput extends EventEmitter {
784
767
  handleResize() {
785
768
  this.lastRenderContent = '';
786
769
  this.lastRenderCursor = -1;
787
- this.resetStreamingRenderThrottle();
788
770
  this.scheduleRender();
789
771
  }
790
772
  /**
791
- * Register with display's output interceptor to position cursor correctly.
792
- * Output is written at contentRow, which advances as content is written.
773
+ * Register with display's output interceptor (kept for API compatibility).
774
+ * With unified floating input, no special cursor manipulation is needed.
793
775
  */
794
776
  registerOutputInterceptor(display) {
795
777
  if (this.outputInterceptorCleanup) {
796
778
  this.outputInterceptorCleanup();
797
779
  }
798
780
  this.outputInterceptorCleanup = display.registerOutputInterceptor({
799
- beforeWrite: () => {
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));
811
- },
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();
818
- },
781
+ beforeWrite: () => { },
782
+ afterWrite: () => { },
819
783
  });
820
784
  }
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
- }
866
785
  /**
867
786
  * Dispose and clean up
868
787
  */
869
788
  dispose() {
870
789
  if (this.disposed)
871
790
  return;
791
+ // Clean up streaming render timer
792
+ if (this.streamingRenderTimer) {
793
+ clearInterval(this.streamingRenderTimer);
794
+ this.streamingRenderTimer = null;
795
+ }
872
796
  // Clean up output interceptor
873
797
  if (this.outputInterceptorCleanup) {
874
798
  this.outputInterceptorCleanup();
@@ -876,7 +800,6 @@ export class TerminalInput extends EventEmitter {
876
800
  }
877
801
  this.disposed = true;
878
802
  this.enabled = false;
879
- this.resetStreamingRenderThrottle();
880
803
  this.disableBracketedPaste();
881
804
  this.buffer = '';
882
805
  this.queue = [];
@@ -981,7 +904,22 @@ export class TerminalInput extends EventEmitter {
981
904
  this.toggleEditMode();
982
905
  return true;
983
906
  }
984
- this.insertText(' ');
907
+ // Tab: toggle paste expansion if in placeholder, otherwise toggle thinking
908
+ if (this.findPlaceholderAt(this.cursor)) {
909
+ this.togglePasteExpansion();
910
+ }
911
+ else {
912
+ this.toggleThinking();
913
+ }
914
+ return true;
915
+ case 'escape':
916
+ // Esc: interrupt if streaming, otherwise clear buffer
917
+ if (this.mode === 'streaming') {
918
+ this.emit('interrupt');
919
+ }
920
+ else if (this.buffer.length > 0) {
921
+ this.clear();
922
+ }
985
923
  return true;
986
924
  }
987
925
  return false;
@@ -999,6 +937,7 @@ export class TerminalInput extends EventEmitter {
999
937
  this.insertPlainText(chunk, insertPos);
1000
938
  this.cursor = insertPos + chunk.length;
1001
939
  this.emit('change', this.buffer);
940
+ this.updateSuggestions();
1002
941
  this.scheduleRender();
1003
942
  }
1004
943
  insertNewline() {
@@ -1023,6 +962,7 @@ export class TerminalInput extends EventEmitter {
1023
962
  this.cursor = Math.max(0, this.cursor - 1);
1024
963
  }
1025
964
  this.emit('change', this.buffer);
965
+ this.updateSuggestions();
1026
966
  this.scheduleRender();
1027
967
  }
1028
968
  deleteForward() {
@@ -1250,12 +1190,13 @@ export class TerminalInput extends EventEmitter {
1250
1190
  timestamp: Date.now(),
1251
1191
  });
1252
1192
  this.emit('queue', text);
1253
- this.clear(); // Clear immediately for queued input
1193
+ this.clear(); // Clear immediately for queued input, re-render to update queue display
1254
1194
  }
1255
1195
  else {
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();
1196
+ // In idle mode, clear the input WITHOUT rendering.
1197
+ // The caller will display the user message and start streaming.
1198
+ // We'll render the input area again after streaming ends.
1199
+ this.clear(true); // Skip render - streaming will handle display
1259
1200
  this.emit('submit', text);
1260
1201
  }
1261
1202
  }
@@ -1272,9 +1213,7 @@ export class TerminalInput extends EventEmitter {
1272
1213
  if (available <= 0)
1273
1214
  return;
1274
1215
  const chunk = clean.slice(0, available);
1275
- const isMultiline = isMultilinePaste(chunk);
1276
- const isShortMultiline = isMultiline && this.shouldInlineMultiline(chunk);
1277
- if (isMultiline && !isShortMultiline) {
1216
+ if (isMultilinePaste(chunk)) {
1278
1217
  this.insertPastePlaceholder(chunk);
1279
1218
  }
1280
1219
  else {
@@ -1410,19 +1349,17 @@ export class TerminalInput extends EventEmitter {
1410
1349
  this.shiftPlaceholders(position, text.length);
1411
1350
  this.buffer = this.buffer.slice(0, position) + text + this.buffer.slice(position);
1412
1351
  }
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
- }
1419
1352
  findPlaceholderAt(position) {
1420
1353
  return this.pastePlaceholders.find((ph) => position >= ph.start && position < ph.end) ?? null;
1421
1354
  }
1422
- buildPlaceholder(lineCount) {
1355
+ buildPlaceholder(summary) {
1423
1356
  const id = ++this.pasteCounter;
1424
- const plural = lineCount === 1 ? '' : 's';
1425
- const placeholder = `[Pasted text #${id} +${lineCount} line${plural}]`;
1357
+ const lang = summary.language ? ` ${summary.language.toUpperCase()}` : '';
1358
+ // Show first line preview (truncated)
1359
+ const preview = summary.preview.length > 30
1360
+ ? `${summary.preview.slice(0, 30)}...`
1361
+ : summary.preview;
1362
+ const placeholder = `[📋 #${id}${lang} ${summary.lineCount}L] "${preview}"`;
1426
1363
  return { id, placeholder };
1427
1364
  }
1428
1365
  insertPastePlaceholder(content) {
@@ -1430,21 +1367,67 @@ export class TerminalInput extends EventEmitter {
1430
1367
  if (available <= 0)
1431
1368
  return;
1432
1369
  const cleanContent = content.slice(0, available);
1433
- const lineCount = cleanContent.split('\n').length;
1434
- const { id, placeholder } = this.buildPlaceholder(lineCount);
1370
+ const summary = generatePasteSummary(cleanContent);
1371
+ // For short pastes (< 5 lines), show full content instead of placeholder
1372
+ if (summary.lineCount < 5) {
1373
+ const placeholder = this.findPlaceholderAt(this.cursor);
1374
+ const insertPos = placeholder && this.cursor > placeholder.start ? placeholder.end : this.cursor;
1375
+ this.insertPlainText(cleanContent, insertPos);
1376
+ this.cursor = insertPos + cleanContent.length;
1377
+ return;
1378
+ }
1379
+ const { id, placeholder } = this.buildPlaceholder(summary);
1435
1380
  const insertPos = this.cursor;
1436
1381
  this.shiftPlaceholders(insertPos, placeholder.length);
1437
1382
  this.pastePlaceholders.push({
1438
1383
  id,
1439
1384
  content: cleanContent,
1440
- lineCount,
1385
+ lineCount: summary.lineCount,
1441
1386
  placeholder,
1442
1387
  start: insertPos,
1443
1388
  end: insertPos + placeholder.length,
1389
+ summary,
1390
+ expanded: false,
1444
1391
  });
1445
1392
  this.buffer = this.buffer.slice(0, insertPos) + placeholder + this.buffer.slice(insertPos);
1446
1393
  this.cursor = insertPos + placeholder.length;
1447
1394
  }
1395
+ /**
1396
+ * Toggle expansion of a paste placeholder at the current cursor position.
1397
+ * When expanded, shows first 3 and last 2 lines of the content.
1398
+ */
1399
+ togglePasteExpansion() {
1400
+ const placeholder = this.findPlaceholderAt(this.cursor);
1401
+ if (!placeholder)
1402
+ return false;
1403
+ placeholder.expanded = !placeholder.expanded;
1404
+ // Update the placeholder text in buffer
1405
+ const newPlaceholder = placeholder.expanded
1406
+ ? this.buildExpandedPlaceholder(placeholder)
1407
+ : this.buildPlaceholder(placeholder.summary).placeholder;
1408
+ const lengthDiff = newPlaceholder.length - placeholder.placeholder.length;
1409
+ // Update buffer
1410
+ this.buffer =
1411
+ this.buffer.slice(0, placeholder.start) +
1412
+ newPlaceholder +
1413
+ this.buffer.slice(placeholder.end);
1414
+ // Update placeholder tracking
1415
+ placeholder.placeholder = newPlaceholder;
1416
+ placeholder.end = placeholder.start + newPlaceholder.length;
1417
+ // Shift other placeholders
1418
+ this.shiftPlaceholders(placeholder.end, lengthDiff, placeholder.id);
1419
+ this.scheduleRender();
1420
+ return true;
1421
+ }
1422
+ buildExpandedPlaceholder(ph) {
1423
+ const lines = ph.content.split('\n');
1424
+ const firstLines = lines.slice(0, 3).map(l => l.slice(0, 60)).join('\n');
1425
+ const lastLines = lines.length > 5
1426
+ ? '\n...\n' + lines.slice(-2).map(l => l.slice(0, 60)).join('\n')
1427
+ : '';
1428
+ const lang = ph.summary.language ? ` ${ph.summary.language.toUpperCase()}` : '';
1429
+ return `[📋 #${ph.id}${lang} ${ph.lineCount}L ▼]\n${firstLines}${lastLines}\n[/📋 #${ph.id}]`;
1430
+ }
1448
1431
  deletePlaceholder(placeholder) {
1449
1432
  const length = placeholder.end - placeholder.start;
1450
1433
  this.buffer = this.buffer.slice(0, placeholder.start) + this.buffer.slice(placeholder.end);
@@ -1452,11 +1435,7 @@ export class TerminalInput extends EventEmitter {
1452
1435
  this.shiftPlaceholders(placeholder.end, -length, placeholder.id);
1453
1436
  this.cursor = placeholder.start;
1454
1437
  }
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
- }
1438
+ updateContextUsage(value) {
1460
1439
  if (value === null || !Number.isFinite(value)) {
1461
1440
  this.contextUsage = null;
1462
1441
  }
@@ -1483,22 +1462,6 @@ export class TerminalInput extends EventEmitter {
1483
1462
  const next = this.editMode === 'display-edits' ? 'ask-permission' : 'display-edits';
1484
1463
  this.setEditMode(next);
1485
1464
  }
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
- }
1502
1465
  scheduleRender() {
1503
1466
  if (!this.canRender())
1504
1467
  return;