erosolar-cli 1.7.344 → 1.7.346

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 (328) 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/sessionStore.d.ts +0 -2
  97. package/dist/core/sessionStore.d.ts.map +1 -1
  98. package/dist/core/sessionStore.js +0 -1
  99. package/dist/core/sessionStore.js.map +1 -1
  100. package/dist/core/toolPreconditions.d.ts.map +1 -1
  101. package/dist/core/toolPreconditions.js +14 -0
  102. package/dist/core/toolPreconditions.js.map +1 -1
  103. package/dist/core/toolRuntime.d.ts +1 -22
  104. package/dist/core/toolRuntime.d.ts.map +1 -1
  105. package/dist/core/toolRuntime.js +5 -0
  106. package/dist/core/toolRuntime.js.map +1 -1
  107. package/dist/core/toolValidation.d.ts.map +1 -1
  108. package/dist/core/toolValidation.js +3 -14
  109. package/dist/core/toolValidation.js.map +1 -1
  110. package/dist/core/unified/errors.d.ts +189 -0
  111. package/dist/core/unified/errors.d.ts.map +1 -0
  112. package/dist/core/unified/errors.js +497 -0
  113. package/dist/core/unified/errors.js.map +1 -0
  114. package/dist/core/unified/index.d.ts +19 -0
  115. package/dist/core/unified/index.d.ts.map +1 -0
  116. package/dist/core/unified/index.js +68 -0
  117. package/dist/core/unified/index.js.map +1 -0
  118. package/dist/core/unified/schema.d.ts +101 -0
  119. package/dist/core/unified/schema.d.ts.map +1 -0
  120. package/dist/core/unified/schema.js +350 -0
  121. package/dist/core/unified/schema.js.map +1 -0
  122. package/dist/core/unified/toolRuntime.d.ts +179 -0
  123. package/dist/core/unified/toolRuntime.d.ts.map +1 -0
  124. package/dist/core/unified/toolRuntime.js +517 -0
  125. package/dist/core/unified/toolRuntime.js.map +1 -0
  126. package/dist/core/unified/tools.d.ts +127 -0
  127. package/dist/core/unified/tools.d.ts.map +1 -0
  128. package/dist/core/unified/tools.js +1333 -0
  129. package/dist/core/unified/tools.js.map +1 -0
  130. package/dist/core/unified/types.d.ts +352 -0
  131. package/dist/core/unified/types.d.ts.map +1 -0
  132. package/dist/core/unified/types.js +12 -0
  133. package/dist/core/unified/types.js.map +1 -0
  134. package/dist/core/unified/version.d.ts +209 -0
  135. package/dist/core/unified/version.d.ts.map +1 -0
  136. package/dist/core/unified/version.js +454 -0
  137. package/dist/core/unified/version.js.map +1 -0
  138. package/dist/core/validationRunner.d.ts +3 -1
  139. package/dist/core/validationRunner.d.ts.map +1 -1
  140. package/dist/core/validationRunner.js.map +1 -1
  141. package/dist/headless/headlessApp.d.ts.map +1 -1
  142. package/dist/headless/headlessApp.js +0 -21
  143. package/dist/headless/headlessApp.js.map +1 -1
  144. package/dist/mcp/sseClient.d.ts.map +1 -1
  145. package/dist/mcp/sseClient.js +18 -9
  146. package/dist/mcp/sseClient.js.map +1 -1
  147. package/dist/plugins/tools/build/buildPlugin.d.ts +6 -0
  148. package/dist/plugins/tools/build/buildPlugin.d.ts.map +1 -1
  149. package/dist/plugins/tools/build/buildPlugin.js +10 -4
  150. package/dist/plugins/tools/build/buildPlugin.js.map +1 -1
  151. package/dist/plugins/tools/nodeDefaults.d.ts.map +1 -1
  152. package/dist/plugins/tools/nodeDefaults.js +2 -0
  153. package/dist/plugins/tools/nodeDefaults.js.map +1 -1
  154. package/dist/plugins/tools/security/securityPlugin.d.ts +3 -0
  155. package/dist/plugins/tools/security/securityPlugin.d.ts.map +1 -0
  156. package/dist/plugins/tools/security/securityPlugin.js +12 -0
  157. package/dist/plugins/tools/security/securityPlugin.js.map +1 -0
  158. package/dist/runtime/agentSession.d.ts +2 -2
  159. package/dist/runtime/agentSession.d.ts.map +1 -1
  160. package/dist/runtime/agentSession.js +2 -2
  161. package/dist/runtime/agentSession.js.map +1 -1
  162. package/dist/security/active-stack-security.d.ts +112 -0
  163. package/dist/security/active-stack-security.d.ts.map +1 -0
  164. package/dist/security/active-stack-security.js +296 -0
  165. package/dist/security/active-stack-security.js.map +1 -0
  166. package/dist/security/advanced-persistence-research.d.ts +92 -0
  167. package/dist/security/advanced-persistence-research.d.ts.map +1 -0
  168. package/dist/security/advanced-persistence-research.js +195 -0
  169. package/dist/security/advanced-persistence-research.js.map +1 -0
  170. package/dist/security/advanced-targeting.d.ts +119 -0
  171. package/dist/security/advanced-targeting.d.ts.map +1 -0
  172. package/dist/security/advanced-targeting.js +233 -0
  173. package/dist/security/advanced-targeting.js.map +1 -0
  174. package/dist/security/assessment/vulnerabilityAssessment.d.ts +104 -0
  175. package/dist/security/assessment/vulnerabilityAssessment.d.ts.map +1 -0
  176. package/dist/security/assessment/vulnerabilityAssessment.js +315 -0
  177. package/dist/security/assessment/vulnerabilityAssessment.js.map +1 -0
  178. package/dist/security/authorization/securityAuthorization.d.ts +88 -0
  179. package/dist/security/authorization/securityAuthorization.d.ts.map +1 -0
  180. package/dist/security/authorization/securityAuthorization.js +172 -0
  181. package/dist/security/authorization/securityAuthorization.js.map +1 -0
  182. package/dist/security/comprehensive-targeting.d.ts +85 -0
  183. package/dist/security/comprehensive-targeting.d.ts.map +1 -0
  184. package/dist/security/comprehensive-targeting.js +438 -0
  185. package/dist/security/comprehensive-targeting.js.map +1 -0
  186. package/dist/security/global-security-integration.d.ts +91 -0
  187. package/dist/security/global-security-integration.d.ts.map +1 -0
  188. package/dist/security/global-security-integration.js +218 -0
  189. package/dist/security/global-security-integration.js.map +1 -0
  190. package/dist/security/index.d.ts +38 -0
  191. package/dist/security/index.d.ts.map +1 -0
  192. package/dist/security/index.js +47 -0
  193. package/dist/security/index.js.map +1 -0
  194. package/dist/security/persistence-analyzer.d.ts +56 -0
  195. package/dist/security/persistence-analyzer.d.ts.map +1 -0
  196. package/dist/security/persistence-analyzer.js +187 -0
  197. package/dist/security/persistence-analyzer.js.map +1 -0
  198. package/dist/security/persistence-cli.d.ts +36 -0
  199. package/dist/security/persistence-cli.d.ts.map +1 -0
  200. package/dist/security/persistence-cli.js +160 -0
  201. package/dist/security/persistence-cli.js.map +1 -0
  202. package/dist/security/persistence-research.d.ts +92 -0
  203. package/dist/security/persistence-research.d.ts.map +1 -0
  204. package/dist/security/persistence-research.js +364 -0
  205. package/dist/security/persistence-research.js.map +1 -0
  206. package/dist/security/research/persistenceResearch.d.ts +97 -0
  207. package/dist/security/research/persistenceResearch.d.ts.map +1 -0
  208. package/dist/security/research/persistenceResearch.js +282 -0
  209. package/dist/security/research/persistenceResearch.js.map +1 -0
  210. package/dist/security/security-integration.d.ts +74 -0
  211. package/dist/security/security-integration.d.ts.map +1 -0
  212. package/dist/security/security-integration.js +137 -0
  213. package/dist/security/security-integration.js.map +1 -0
  214. package/dist/security/security-testing-framework.d.ts +112 -0
  215. package/dist/security/security-testing-framework.d.ts.map +1 -0
  216. package/dist/security/security-testing-framework.js +364 -0
  217. package/dist/security/security-testing-framework.js.map +1 -0
  218. package/dist/security/simulation/attackSimulation.d.ts +93 -0
  219. package/dist/security/simulation/attackSimulation.d.ts.map +1 -0
  220. package/dist/security/simulation/attackSimulation.js +341 -0
  221. package/dist/security/simulation/attackSimulation.js.map +1 -0
  222. package/dist/security/strategic-operations.d.ts +100 -0
  223. package/dist/security/strategic-operations.d.ts.map +1 -0
  224. package/dist/security/strategic-operations.js +276 -0
  225. package/dist/security/strategic-operations.js.map +1 -0
  226. package/dist/security/tool-security-wrapper.d.ts +58 -0
  227. package/dist/security/tool-security-wrapper.d.ts.map +1 -0
  228. package/dist/security/tool-security-wrapper.js +156 -0
  229. package/dist/security/tool-security-wrapper.js.map +1 -0
  230. package/dist/shell/claudeCodeStreamHandler.d.ts +145 -0
  231. package/dist/shell/claudeCodeStreamHandler.d.ts.map +1 -0
  232. package/dist/shell/claudeCodeStreamHandler.js +322 -0
  233. package/dist/shell/claudeCodeStreamHandler.js.map +1 -0
  234. package/dist/shell/inputQueueManager.d.ts +144 -0
  235. package/dist/shell/inputQueueManager.d.ts.map +1 -0
  236. package/dist/shell/inputQueueManager.js +290 -0
  237. package/dist/shell/inputQueueManager.js.map +1 -0
  238. package/dist/shell/interactiveShell.d.ts +7 -19
  239. package/dist/shell/interactiveShell.d.ts.map +1 -1
  240. package/dist/shell/interactiveShell.js +166 -271
  241. package/dist/shell/interactiveShell.js.map +1 -1
  242. package/dist/shell/metricsTracker.d.ts +60 -0
  243. package/dist/shell/metricsTracker.d.ts.map +1 -0
  244. package/dist/shell/metricsTracker.js +119 -0
  245. package/dist/shell/metricsTracker.js.map +1 -0
  246. package/dist/shell/shellApp.d.ts +0 -2
  247. package/dist/shell/shellApp.d.ts.map +1 -1
  248. package/dist/shell/shellApp.js +9 -82
  249. package/dist/shell/shellApp.js.map +1 -1
  250. package/dist/shell/streamingOutputManager.d.ts +115 -0
  251. package/dist/shell/streamingOutputManager.d.ts.map +1 -0
  252. package/dist/shell/streamingOutputManager.js +225 -0
  253. package/dist/shell/streamingOutputManager.js.map +1 -0
  254. package/dist/shell/systemPrompt.d.ts.map +1 -1
  255. package/dist/shell/systemPrompt.js +4 -1
  256. package/dist/shell/systemPrompt.js.map +1 -1
  257. package/dist/shell/terminalInput.d.ts +120 -218
  258. package/dist/shell/terminalInput.d.ts.map +1 -1
  259. package/dist/shell/terminalInput.js +537 -932
  260. package/dist/shell/terminalInput.js.map +1 -1
  261. package/dist/shell/terminalInputAdapter.d.ts +21 -99
  262. package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
  263. package/dist/shell/terminalInputAdapter.js +30 -135
  264. package/dist/shell/terminalInputAdapter.js.map +1 -1
  265. package/dist/subagents/taskRunner.d.ts +1 -7
  266. package/dist/subagents/taskRunner.d.ts.map +1 -1
  267. package/dist/subagents/taskRunner.js +47 -180
  268. package/dist/subagents/taskRunner.js.map +1 -1
  269. package/dist/tools/securityTools.d.ts +22 -0
  270. package/dist/tools/securityTools.d.ts.map +1 -0
  271. package/dist/tools/securityTools.js +448 -0
  272. package/dist/tools/securityTools.js.map +1 -0
  273. package/dist/ui/ShellUIAdapter.d.ts +1 -7
  274. package/dist/ui/ShellUIAdapter.d.ts.map +1 -1
  275. package/dist/ui/ShellUIAdapter.js +18 -42
  276. package/dist/ui/ShellUIAdapter.js.map +1 -1
  277. package/dist/ui/display.d.ts +45 -24
  278. package/dist/ui/display.d.ts.map +1 -1
  279. package/dist/ui/display.js +259 -140
  280. package/dist/ui/display.js.map +1 -1
  281. package/dist/ui/persistentPrompt.d.ts +50 -0
  282. package/dist/ui/persistentPrompt.d.ts.map +1 -0
  283. package/dist/ui/persistentPrompt.js +92 -0
  284. package/dist/ui/persistentPrompt.js.map +1 -0
  285. package/dist/ui/terminalUISchema.d.ts +195 -0
  286. package/dist/ui/terminalUISchema.d.ts.map +1 -0
  287. package/dist/ui/terminalUISchema.js +113 -0
  288. package/dist/ui/terminalUISchema.js.map +1 -0
  289. package/dist/ui/theme.d.ts.map +1 -1
  290. package/dist/ui/theme.js +8 -6
  291. package/dist/ui/theme.js.map +1 -1
  292. package/dist/ui/toolDisplay.d.ts +158 -0
  293. package/dist/ui/toolDisplay.d.ts.map +1 -1
  294. package/dist/ui/toolDisplay.js +348 -0
  295. package/dist/ui/toolDisplay.js.map +1 -1
  296. package/dist/ui/unified/layout.d.ts +0 -20
  297. package/dist/ui/unified/layout.d.ts.map +1 -1
  298. package/dist/ui/unified/layout.js +216 -29
  299. package/dist/ui/unified/layout.js.map +1 -1
  300. package/package.json +4 -4
  301. package/scripts/deploy-security-capabilities.js +178 -0
  302. package/dist/core/hooks.d.ts +0 -113
  303. package/dist/core/hooks.d.ts.map +0 -1
  304. package/dist/core/hooks.js +0 -267
  305. package/dist/core/hooks.js.map +0 -1
  306. package/dist/core/metricsTracker.d.ts +0 -122
  307. package/dist/core/metricsTracker.d.ts.map +0 -1
  308. package/dist/core/metricsTracker.js.map +0 -1
  309. package/dist/core/securityAssessment.d.ts +0 -91
  310. package/dist/core/securityAssessment.d.ts.map +0 -1
  311. package/dist/core/securityAssessment.js +0 -580
  312. package/dist/core/securityAssessment.js.map +0 -1
  313. package/dist/core/verification.d.ts +0 -137
  314. package/dist/core/verification.d.ts.map +0 -1
  315. package/dist/core/verification.js +0 -323
  316. package/dist/core/verification.js.map +0 -1
  317. package/dist/subagents/agentConfig.d.ts +0 -27
  318. package/dist/subagents/agentConfig.d.ts.map +0 -1
  319. package/dist/subagents/agentConfig.js +0 -89
  320. package/dist/subagents/agentConfig.js.map +0 -1
  321. package/dist/subagents/agentRegistry.d.ts +0 -33
  322. package/dist/subagents/agentRegistry.d.ts.map +0 -1
  323. package/dist/subagents/agentRegistry.js +0 -162
  324. package/dist/subagents/agentRegistry.js.map +0 -1
  325. package/dist/utils/frontmatter.d.ts +0 -10
  326. package/dist/utils/frontmatter.d.ts.map +0 -1
  327. package/dist/utils/frontmatter.js +0 -78
  328. package/dist/utils/frontmatter.js.map +0 -1
@@ -0,0 +1,322 @@
1
+ /**
2
+ * ClaudeCodeStreamHandler - Complete streaming I/O handler following Claude Code's approach
3
+ *
4
+ * This module combines StreamingOutputManager and InputQueueManager to provide
5
+ * the complete Claude Code streaming experience:
6
+ *
7
+ * 1. Natural Output Flow
8
+ * - Streaming output just writes to stdout normally
9
+ * - Cursor stays where it is after each write
10
+ * - Lines scroll up naturally as new content appears
11
+ * - NO scroll regions, NO save/restore cursor during streaming
12
+ *
13
+ * 2. Readline Handles Input
14
+ * - Uses Node.js readline module
15
+ * - Input prompt naturally moves up as output streams above it
16
+ * - User can type while streaming - input is queued in memory, not rendered
17
+ *
18
+ * 3. Queue-Based Approach
19
+ * User types during streaming → Input stored in queue → Processed after streaming ends
20
+ *
21
+ * 4. The Key Insight
22
+ * The cursor is NEVER moved during streaming. Output just appends at current position.
23
+ * The "input at bottom" effect comes from:
24
+ * - New output pushes older content (including the prompt) upward
25
+ * - After streaming ends, a new prompt is shown at the bottom
26
+ */
27
+ import * as readline from 'node:readline';
28
+ import { EventEmitter } from 'node:events';
29
+ import { getStreamingOutputManager } from './streamingOutputManager.js';
30
+ import { getInputQueueManager } from './inputQueueManager.js';
31
+ import { writeLock } from '../ui/writeLock.js';
32
+ /**
33
+ * Coordinates streaming output and queued input for Claude Code style UX.
34
+ */
35
+ export class ClaudeCodeStreamHandler extends EventEmitter {
36
+ outputManager;
37
+ inputManager;
38
+ writeStream;
39
+ readStream;
40
+ rl = null;
41
+ keypressHandler = null;
42
+ originalStdoutWrite = null;
43
+ isOutputSuppressed = false;
44
+ constructor(writeStream = process.stdout, readStream = process.stdin) {
45
+ super();
46
+ this.writeStream = writeStream;
47
+ this.readStream = readStream;
48
+ this.outputManager = getStreamingOutputManager();
49
+ this.inputManager = getInputQueueManager();
50
+ // Forward events
51
+ this.inputManager.on('input-queued', (input) => {
52
+ this.emit('input-queued', input);
53
+ });
54
+ }
55
+ /**
56
+ * Attach to an existing readline interface
57
+ * Call this after creating your readline.Interface
58
+ */
59
+ attachToReadline(rl) {
60
+ this.rl = rl;
61
+ this.setupKeypressCapture();
62
+ }
63
+ /**
64
+ * Set up keypress capturing for queued input during streaming
65
+ */
66
+ setupKeypressCapture() {
67
+ if (!this.readStream || !this.readStream.isTTY) {
68
+ return;
69
+ }
70
+ // Enable keypress events if not already enabled
71
+ if (this.readStream.listenerCount('keypress') === 0 && this.rl) {
72
+ readline.emitKeypressEvents(this.readStream, this.rl);
73
+ }
74
+ // Ensure raw mode for keypress events
75
+ if (this.readStream.setRawMode && !this.readStream.isRaw) {
76
+ this.readStream.setRawMode(true);
77
+ }
78
+ this.keypressHandler = (_str, key) => {
79
+ // Only capture when streaming
80
+ if (!this.outputManager.isStreaming() || !this.inputManager.isCapturing()) {
81
+ return;
82
+ }
83
+ // Handle special keys
84
+ if (key) {
85
+ // Ctrl+C - interrupt
86
+ if (key.ctrl && key.name === 'c') {
87
+ this.inputManager.handleInterrupt();
88
+ return;
89
+ }
90
+ // Enter - submit queued input
91
+ if (key.name === 'return' || key.name === 'enter') {
92
+ this.inputManager.handleSubmit();
93
+ return;
94
+ }
95
+ // Backspace
96
+ if (key.name === 'backspace') {
97
+ this.inputManager.handleBackspace();
98
+ return;
99
+ }
100
+ // Delete
101
+ if (key.name === 'delete') {
102
+ this.inputManager.handleDelete();
103
+ return;
104
+ }
105
+ // Arrow keys
106
+ if (key.name === 'left') {
107
+ this.inputManager.handleCursorLeft();
108
+ return;
109
+ }
110
+ if (key.name === 'right') {
111
+ this.inputManager.handleCursorRight();
112
+ return;
113
+ }
114
+ // Ignore other control sequences during capture
115
+ if (key.ctrl || key.meta) {
116
+ return;
117
+ }
118
+ }
119
+ // Regular character input
120
+ if (_str && _str.length > 0 && !key?.ctrl && !key?.meta) {
121
+ this.inputManager.handleChar(_str);
122
+ }
123
+ };
124
+ this.readStream.prependListener('keypress', this.keypressHandler);
125
+ }
126
+ /**
127
+ * Begin streaming mode
128
+ *
129
+ * Claude Code approach:
130
+ * - Start capturing input to queue
131
+ * - Suppress readline echo (characters typed go to queue, not screen)
132
+ * - Output flows naturally to stdout
133
+ */
134
+ startStreaming() {
135
+ if (this.outputManager.isStreaming()) {
136
+ return;
137
+ }
138
+ // Start both managers
139
+ this.outputManager.startStream();
140
+ this.inputManager.startCapturing();
141
+ // Suppress readline's output so typed characters don't appear
142
+ this.suppressReadlineOutput();
143
+ this.emit('streaming-start');
144
+ }
145
+ /**
146
+ * End streaming mode
147
+ *
148
+ * Claude Code approach:
149
+ * - Stop capturing (any remaining buffer is preserved)
150
+ * - Restore readline echo
151
+ * - Return streaming statistics
152
+ */
153
+ endStreaming() {
154
+ // Get remaining buffer before stopping capture
155
+ const remainingBuffer = this.inputManager.stopCapturing();
156
+ // If there's unsubmitted content in buffer, preserve it for next prompt
157
+ if (remainingBuffer && remainingBuffer.trim()) {
158
+ // The remaining buffer will be shown when readline prompts again
159
+ // We could queue it, but leaving it as-is is more intuitive
160
+ }
161
+ // Restore readline output
162
+ this.restoreReadlineOutput();
163
+ // End output streaming
164
+ const stats = this.outputManager.endStream();
165
+ const result = {
166
+ ...stats,
167
+ queuedInputs: this.inputManager.getQueueLength(),
168
+ };
169
+ this.emit('streaming-end', stats);
170
+ return result;
171
+ }
172
+ /**
173
+ * Write content during streaming
174
+ * Just writes naturally to stdout - no cursor manipulation
175
+ */
176
+ write(content) {
177
+ this.outputManager.writeChunk(content);
178
+ }
179
+ /**
180
+ * Write a complete line during streaming
181
+ */
182
+ writeLine(line = '') {
183
+ this.outputManager.writeLine(line);
184
+ }
185
+ /**
186
+ * Check if currently streaming
187
+ */
188
+ isStreaming() {
189
+ return this.outputManager.isStreaming();
190
+ }
191
+ /**
192
+ * Get current state
193
+ */
194
+ getState() {
195
+ const outputStats = this.outputManager.getStats();
196
+ return {
197
+ isStreaming: this.outputManager.isStreaming(),
198
+ queuedCount: this.inputManager.getQueueLength(),
199
+ charsWritten: outputStats.chars,
200
+ linesWritten: outputStats.lines,
201
+ elapsedMs: outputStats.elapsed,
202
+ };
203
+ }
204
+ /**
205
+ * Check if there are queued inputs to process
206
+ */
207
+ hasQueuedInput() {
208
+ return this.inputManager.hasQueuedInput();
209
+ }
210
+ /**
211
+ * Get the next queued input
212
+ */
213
+ getNextQueuedInput() {
214
+ return this.inputManager.dequeue();
215
+ }
216
+ /**
217
+ * Get all queued inputs
218
+ */
219
+ getAllQueuedInputs() {
220
+ return this.inputManager.getQueue();
221
+ }
222
+ /**
223
+ * Clear all queued inputs
224
+ */
225
+ clearQueue() {
226
+ this.inputManager.clearQueue();
227
+ }
228
+ /**
229
+ * Get queue summary for display
230
+ */
231
+ getQueueSummary() {
232
+ return this.inputManager.getQueueSummary();
233
+ }
234
+ /**
235
+ * Suppress readline's output during streaming
236
+ * Characters typed will be captured but not displayed
237
+ */
238
+ suppressReadlineOutput() {
239
+ if (this.isOutputSuppressed) {
240
+ return;
241
+ }
242
+ // Save original write function
243
+ this.originalStdoutWrite = this.writeStream.write.bind(this.writeStream);
244
+ // Replace with filtered version that suppresses readline echo
245
+ const outputManager = this.outputManager;
246
+ const originalWrite = this.originalStdoutWrite;
247
+ this.writeStream.write = function (chunk, encodingOrCallback, callback) {
248
+ const text = typeof chunk === 'string' ? chunk : chunk.toString();
249
+ // During streaming, only allow output from the streaming manager
250
+ // Suppress readline's echo of typed characters (single character writes)
251
+ if (outputManager.isStreaming()) {
252
+ // Allow newlines and multi-character writes (likely streaming content)
253
+ if (text.length === 1 && !text.includes('\n') && !text.includes('\r')) {
254
+ // Single character during streaming - likely user typing, suppress it
255
+ if (typeof encodingOrCallback === 'function') {
256
+ encodingOrCallback(null);
257
+ return true;
258
+ }
259
+ if (callback) {
260
+ callback(null);
261
+ }
262
+ return true;
263
+ }
264
+ }
265
+ // Pass through everything else
266
+ // If lock is already held, write directly - we're in a protected context
267
+ // This prevents queuing issues where content gets delayed during streaming
268
+ if (writeLock.isLocked()) {
269
+ return originalWrite(chunk, encodingOrCallback, callback);
270
+ }
271
+ let result = true;
272
+ writeLock.withLock(() => {
273
+ result = originalWrite(chunk, encodingOrCallback, callback);
274
+ }, 'claudeCodeStreamHandler.stdout');
275
+ return result;
276
+ };
277
+ this.isOutputSuppressed = true;
278
+ }
279
+ /**
280
+ * Restore readline's normal output
281
+ */
282
+ restoreReadlineOutput() {
283
+ if (!this.isOutputSuppressed || !this.originalStdoutWrite) {
284
+ return;
285
+ }
286
+ this.writeStream.write = this.originalStdoutWrite;
287
+ this.originalStdoutWrite = null;
288
+ this.isOutputSuppressed = false;
289
+ }
290
+ /**
291
+ * Cleanup when done
292
+ */
293
+ dispose() {
294
+ // Restore output if suppressed
295
+ this.restoreReadlineOutput();
296
+ // Remove keypress handler
297
+ if (this.keypressHandler && this.readStream) {
298
+ this.readStream.off('keypress', this.keypressHandler);
299
+ this.keypressHandler = null;
300
+ }
301
+ // Clear queue
302
+ this.inputManager.clearQueue();
303
+ this.rl = null;
304
+ }
305
+ }
306
+ /**
307
+ * Singleton instance for global use
308
+ */
309
+ let globalInstance = null;
310
+ export function getClaudeCodeStreamHandler() {
311
+ if (!globalInstance) {
312
+ globalInstance = new ClaudeCodeStreamHandler();
313
+ }
314
+ return globalInstance;
315
+ }
316
+ export function resetClaudeCodeStreamHandler() {
317
+ if (globalInstance) {
318
+ globalInstance.dispose();
319
+ }
320
+ globalInstance = null;
321
+ }
322
+ //# sourceMappingURL=claudeCodeStreamHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claudeCodeStreamHandler.js","sourceRoot":"","sources":["../../src/shell/claudeCodeStreamHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAA0B,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAChG,OAAO,EAAqB,oBAAoB,EAAoB,MAAM,wBAAwB,CAAC;A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AAI,CAAC;AAE1D,MAAM,UAAU,0BAA0B;IACxC,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,cAAc,GAAG,IAAI,uBAAuB,EAAE,CAAC;IACjD,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,4BAA4B;IAC1C,IAAI,cAAc,EAAE,CAAC;QACnB,cAAc,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IACD,cAAc,GAAG,IAAI,CAAC;AACxB,CAAC"}
@@ -0,0 +1,144 @@
1
+ /**
2
+ * InputQueueManager - Queue-based input handling for Claude Code style streaming
3
+ *
4
+ * Key principles from Claude Code:
5
+ * 1. Readline handles input - Uses Node.js readline module
6
+ * 2. User can type while streaming - Input is queued in memory, not rendered
7
+ * 3. Queue-based approach: User types → stored in queue → processed after streaming ends
8
+ *
9
+ * The key insight is that the cursor is never moved during streaming.
10
+ * Input is captured "invisibly" while streaming, then processed when streaming ends.
11
+ */
12
+ import { EventEmitter } from 'node:events';
13
+ export interface QueuedInput {
14
+ id: string;
15
+ text: string;
16
+ timestamp: number;
17
+ type: 'message' | 'command' | 'interrupt';
18
+ }
19
+ export interface InputQueueState {
20
+ isCapturing: boolean;
21
+ buffer: string;
22
+ cursorPosition: number;
23
+ queue: QueuedInput[];
24
+ }
25
+ export interface InputQueueEvents {
26
+ 'input-queued': (input: QueuedInput) => void;
27
+ 'input-processed': (input: QueuedInput) => void;
28
+ 'queue-cleared': () => void;
29
+ 'capture-start': () => void;
30
+ 'capture-end': () => void;
31
+ }
32
+ /**
33
+ * Manages input queuing during streaming output.
34
+ *
35
+ * When streaming is active:
36
+ * - Captures keystrokes into a buffer
37
+ * - On Enter, queues the input for later processing
38
+ * - Provides methods to process queue after streaming ends
39
+ */
40
+ export declare class InputQueueManager extends EventEmitter {
41
+ private state;
42
+ private inputIdCounter;
43
+ private readonly maxQueueSize;
44
+ private readonly maxBufferLength;
45
+ constructor(options?: {
46
+ maxQueueSize?: number;
47
+ maxBufferLength?: number;
48
+ });
49
+ /**
50
+ * Start capturing input (during streaming)
51
+ * Input will be buffered and queued, not immediately processed
52
+ */
53
+ startCapturing(): void;
54
+ /**
55
+ * Stop capturing input (after streaming ends)
56
+ * Returns any remaining buffer content
57
+ */
58
+ stopCapturing(): string;
59
+ /**
60
+ * Check if currently capturing input
61
+ */
62
+ isCapturing(): boolean;
63
+ /**
64
+ * Handle a character input
65
+ * During capturing, adds to buffer; otherwise ignored
66
+ */
67
+ handleChar(char: string): void;
68
+ /**
69
+ * Handle backspace
70
+ */
71
+ handleBackspace(): void;
72
+ /**
73
+ * Handle delete key
74
+ */
75
+ handleDelete(): void;
76
+ /**
77
+ * Handle cursor left
78
+ */
79
+ handleCursorLeft(): void;
80
+ /**
81
+ * Handle cursor right
82
+ */
83
+ handleCursorRight(): void;
84
+ /**
85
+ * Handle Enter - queue the current buffer
86
+ * Returns the queued input or null if buffer was empty
87
+ */
88
+ handleSubmit(): QueuedInput | null;
89
+ /**
90
+ * Handle Ctrl+C during capture - queue an interrupt
91
+ */
92
+ handleInterrupt(): QueuedInput;
93
+ /**
94
+ * Get current buffer contents (for display purposes)
95
+ */
96
+ getBuffer(): string;
97
+ /**
98
+ * Get current cursor position
99
+ */
100
+ getCursorPosition(): number;
101
+ /**
102
+ * Get the number of queued inputs
103
+ */
104
+ getQueueLength(): number;
105
+ /**
106
+ * Check if there are queued inputs
107
+ */
108
+ hasQueuedInput(): boolean;
109
+ /**
110
+ * Get the next queued input without removing it
111
+ */
112
+ peekQueue(): QueuedInput | undefined;
113
+ /**
114
+ * Get and remove the next queued input
115
+ */
116
+ dequeue(): QueuedInput | undefined;
117
+ /**
118
+ * Get all queued inputs (copy)
119
+ */
120
+ getQueue(): QueuedInput[];
121
+ /**
122
+ * Clear all queued inputs
123
+ */
124
+ clearQueue(): void;
125
+ /**
126
+ * Clear the current buffer
127
+ */
128
+ clearBuffer(): void;
129
+ /**
130
+ * Set the buffer content directly (for paste handling)
131
+ */
132
+ setBuffer(content: string, cursorPos?: number): void;
133
+ /**
134
+ * Get queue summary for display
135
+ */
136
+ getQueueSummary(): string;
137
+ /**
138
+ * Get full state (for debugging)
139
+ */
140
+ getState(): InputQueueState;
141
+ }
142
+ export declare function getInputQueueManager(): InputQueueManager;
143
+ export declare function resetInputQueueManager(): void;
144
+ //# sourceMappingURL=inputQueueManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputQueueManager.d.ts","sourceRoot":"","sources":["../../src/shell/inputQueueManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,CAAC;CAC3C;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,WAAW,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAC7C,iBAAiB,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAChD,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,qBAAa,iBAAkB,SAAQ,YAAY;IACjD,OAAO,CAAC,KAAK,CAKX;IAEF,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAE7B,OAAO,GAAE;QAAE,YAA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