@trenchwork/coder 1.3.0

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 (560) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +173 -0
  3. package/agents/trenchwork-code.rules.json +199 -0
  4. package/dist/bin/deepseek.d.ts +3 -0
  5. package/dist/bin/deepseek.d.ts.map +1 -0
  6. package/dist/bin/deepseek.js +23 -0
  7. package/dist/bin/deepseek.js.map +1 -0
  8. package/dist/capabilities/baseCapability.d.ts +72 -0
  9. package/dist/capabilities/baseCapability.d.ts.map +1 -0
  10. package/dist/capabilities/baseCapability.js +183 -0
  11. package/dist/capabilities/baseCapability.js.map +1 -0
  12. package/dist/capabilities/bashCapability.d.ts +13 -0
  13. package/dist/capabilities/bashCapability.d.ts.map +1 -0
  14. package/dist/capabilities/bashCapability.js +24 -0
  15. package/dist/capabilities/bashCapability.js.map +1 -0
  16. package/dist/capabilities/editCapability.d.ts +17 -0
  17. package/dist/capabilities/editCapability.d.ts.map +1 -0
  18. package/dist/capabilities/editCapability.js +27 -0
  19. package/dist/capabilities/editCapability.js.map +1 -0
  20. package/dist/capabilities/enhancedGitCapability.d.ts +7 -0
  21. package/dist/capabilities/enhancedGitCapability.d.ts.map +1 -0
  22. package/dist/capabilities/enhancedGitCapability.js +220 -0
  23. package/dist/capabilities/enhancedGitCapability.js.map +1 -0
  24. package/dist/capabilities/filesystemCapability.d.ts +13 -0
  25. package/dist/capabilities/filesystemCapability.d.ts.map +1 -0
  26. package/dist/capabilities/filesystemCapability.js +24 -0
  27. package/dist/capabilities/filesystemCapability.js.map +1 -0
  28. package/dist/capabilities/gitHistoryCapability.d.ts +6 -0
  29. package/dist/capabilities/gitHistoryCapability.d.ts.map +1 -0
  30. package/dist/capabilities/gitHistoryCapability.js +184 -0
  31. package/dist/capabilities/gitHistoryCapability.js.map +1 -0
  32. package/dist/capabilities/hitlCapability.d.ts +18 -0
  33. package/dist/capabilities/hitlCapability.d.ts.map +1 -0
  34. package/dist/capabilities/hitlCapability.js +29 -0
  35. package/dist/capabilities/hitlCapability.js.map +1 -0
  36. package/dist/capabilities/index.d.ts +11 -0
  37. package/dist/capabilities/index.d.ts.map +1 -0
  38. package/dist/capabilities/index.js +16 -0
  39. package/dist/capabilities/index.js.map +1 -0
  40. package/dist/capabilities/memoryCapability.d.ts +10 -0
  41. package/dist/capabilities/memoryCapability.d.ts.map +1 -0
  42. package/dist/capabilities/memoryCapability.js +22 -0
  43. package/dist/capabilities/memoryCapability.js.map +1 -0
  44. package/dist/capabilities/notebookCapability.d.ts +6 -0
  45. package/dist/capabilities/notebookCapability.d.ts.map +1 -0
  46. package/dist/capabilities/notebookCapability.js +17 -0
  47. package/dist/capabilities/notebookCapability.js.map +1 -0
  48. package/dist/capabilities/searchCapability.d.ts +19 -0
  49. package/dist/capabilities/searchCapability.d.ts.map +1 -0
  50. package/dist/capabilities/searchCapability.js +29 -0
  51. package/dist/capabilities/searchCapability.js.map +1 -0
  52. package/dist/capabilities/skillCapability.d.ts +6 -0
  53. package/dist/capabilities/skillCapability.d.ts.map +1 -0
  54. package/dist/capabilities/skillCapability.js +17 -0
  55. package/dist/capabilities/skillCapability.js.map +1 -0
  56. package/dist/capabilities/todoCapability.d.ts +11 -0
  57. package/dist/capabilities/todoCapability.d.ts.map +1 -0
  58. package/dist/capabilities/todoCapability.js +22 -0
  59. package/dist/capabilities/todoCapability.js.map +1 -0
  60. package/dist/capabilities/toolManifest.d.ts +3 -0
  61. package/dist/capabilities/toolManifest.d.ts.map +1 -0
  62. package/dist/capabilities/toolManifest.js +163 -0
  63. package/dist/capabilities/toolManifest.js.map +1 -0
  64. package/dist/capabilities/toolRegistry.d.ts +25 -0
  65. package/dist/capabilities/toolRegistry.d.ts.map +1 -0
  66. package/dist/capabilities/toolRegistry.js +150 -0
  67. package/dist/capabilities/toolRegistry.js.map +1 -0
  68. package/dist/capabilities/unifiedCodingCapability.d.ts +62 -0
  69. package/dist/capabilities/unifiedCodingCapability.d.ts.map +1 -0
  70. package/dist/capabilities/unifiedCodingCapability.js +790 -0
  71. package/dist/capabilities/unifiedCodingCapability.js.map +1 -0
  72. package/dist/capabilities/webCapability.d.ts +23 -0
  73. package/dist/capabilities/webCapability.d.ts.map +1 -0
  74. package/dist/capabilities/webCapability.js +33 -0
  75. package/dist/capabilities/webCapability.js.map +1 -0
  76. package/dist/config.d.ts +25 -0
  77. package/dist/config.d.ts.map +1 -0
  78. package/dist/config.js +181 -0
  79. package/dist/config.js.map +1 -0
  80. package/dist/contracts/agent-profiles.schema.json +25 -0
  81. package/dist/contracts/agent-schemas.json +158 -0
  82. package/dist/contracts/models.schema.json +9 -0
  83. package/dist/contracts/module-schema.json +367 -0
  84. package/dist/contracts/schemas/agent-profile.schema.json +157 -0
  85. package/dist/contracts/schemas/agent-rules.schema.json +238 -0
  86. package/dist/contracts/schemas/agent-schemas.schema.json +528 -0
  87. package/dist/contracts/schemas/agent.schema.json +90 -0
  88. package/dist/contracts/schemas/tool-selection.schema.json +174 -0
  89. package/dist/contracts/tools.schema.json +42 -0
  90. package/dist/contracts/unified-schema.json +40 -0
  91. package/dist/contracts/v1/agent.d.ts +225 -0
  92. package/dist/contracts/v1/agent.d.ts.map +1 -0
  93. package/dist/contracts/v1/agent.js +8 -0
  94. package/dist/contracts/v1/agent.js.map +1 -0
  95. package/dist/contracts/v1/agentProfileManifest.d.ts +60 -0
  96. package/dist/contracts/v1/agentProfileManifest.d.ts.map +1 -0
  97. package/dist/contracts/v1/agentProfileManifest.js +9 -0
  98. package/dist/contracts/v1/agentProfileManifest.js.map +1 -0
  99. package/dist/contracts/v1/agentRules.d.ts +60 -0
  100. package/dist/contracts/v1/agentRules.d.ts.map +1 -0
  101. package/dist/contracts/v1/agentRules.js +10 -0
  102. package/dist/contracts/v1/agentRules.js.map +1 -0
  103. package/dist/contracts/v1/provider.d.ts +149 -0
  104. package/dist/contracts/v1/provider.d.ts.map +1 -0
  105. package/dist/contracts/v1/provider.js +7 -0
  106. package/dist/contracts/v1/provider.js.map +1 -0
  107. package/dist/contracts/v1/tool.d.ts +136 -0
  108. package/dist/contracts/v1/tool.d.ts.map +1 -0
  109. package/dist/contracts/v1/tool.js +7 -0
  110. package/dist/contracts/v1/tool.js.map +1 -0
  111. package/dist/contracts/v1/toolAccess.d.ts +43 -0
  112. package/dist/contracts/v1/toolAccess.d.ts.map +1 -0
  113. package/dist/contracts/v1/toolAccess.js +9 -0
  114. package/dist/contracts/v1/toolAccess.js.map +1 -0
  115. package/dist/core/adversarial.d.ts +38 -0
  116. package/dist/core/adversarial.d.ts.map +1 -0
  117. package/dist/core/adversarial.js +106 -0
  118. package/dist/core/adversarial.js.map +1 -0
  119. package/dist/core/adversarialCorrection.d.ts +22 -0
  120. package/dist/core/adversarialCorrection.d.ts.map +1 -0
  121. package/dist/core/adversarialCorrection.js +25 -0
  122. package/dist/core/adversarialCorrection.js.map +1 -0
  123. package/dist/core/agent.d.ts +331 -0
  124. package/dist/core/agent.d.ts.map +1 -0
  125. package/dist/core/agent.js +1637 -0
  126. package/dist/core/agent.js.map +1 -0
  127. package/dist/core/agentProfileManifest.d.ts +3 -0
  128. package/dist/core/agentProfileManifest.d.ts.map +1 -0
  129. package/dist/core/agentProfileManifest.js +188 -0
  130. package/dist/core/agentProfileManifest.js.map +1 -0
  131. package/dist/core/agentProfiles.d.ts +22 -0
  132. package/dist/core/agentProfiles.d.ts.map +1 -0
  133. package/dist/core/agentProfiles.js +35 -0
  134. package/dist/core/agentProfiles.js.map +1 -0
  135. package/dist/core/agentRegistry.d.ts +111 -0
  136. package/dist/core/agentRegistry.d.ts.map +1 -0
  137. package/dist/core/agentRegistry.js +229 -0
  138. package/dist/core/agentRegistry.js.map +1 -0
  139. package/dist/core/agentRulebook.d.ts +11 -0
  140. package/dist/core/agentRulebook.d.ts.map +1 -0
  141. package/dist/core/agentRulebook.js +136 -0
  142. package/dist/core/agentRulebook.js.map +1 -0
  143. package/dist/core/agentSchemaLoader.d.ts +131 -0
  144. package/dist/core/agentSchemaLoader.d.ts.map +1 -0
  145. package/dist/core/agentSchemaLoader.js +235 -0
  146. package/dist/core/agentSchemaLoader.js.map +1 -0
  147. package/dist/core/aiErrorFixer.d.ts +57 -0
  148. package/dist/core/aiErrorFixer.d.ts.map +1 -0
  149. package/dist/core/aiErrorFixer.js +214 -0
  150. package/dist/core/aiErrorFixer.js.map +1 -0
  151. package/dist/core/bashCommandGuidance.d.ts +16 -0
  152. package/dist/core/bashCommandGuidance.d.ts.map +1 -0
  153. package/dist/core/bashCommandGuidance.js +40 -0
  154. package/dist/core/bashCommandGuidance.js.map +1 -0
  155. package/dist/core/compactionNote.d.ts +13 -0
  156. package/dist/core/compactionNote.d.ts.map +1 -0
  157. package/dist/core/compactionNote.js +13 -0
  158. package/dist/core/compactionNote.js.map +1 -0
  159. package/dist/core/constants.d.ts +31 -0
  160. package/dist/core/constants.d.ts.map +1 -0
  161. package/dist/core/constants.js +62 -0
  162. package/dist/core/constants.js.map +1 -0
  163. package/dist/core/contextManager.d.ts +271 -0
  164. package/dist/core/contextManager.d.ts.map +1 -0
  165. package/dist/core/contextManager.js +1076 -0
  166. package/dist/core/contextManager.js.map +1 -0
  167. package/dist/core/contextUsage.d.ts +28 -0
  168. package/dist/core/contextUsage.d.ts.map +1 -0
  169. package/dist/core/contextUsage.js +62 -0
  170. package/dist/core/contextUsage.js.map +1 -0
  171. package/dist/core/contextWindow.d.ts +42 -0
  172. package/dist/core/contextWindow.d.ts.map +1 -0
  173. package/dist/core/contextWindow.js +127 -0
  174. package/dist/core/contextWindow.js.map +1 -0
  175. package/dist/core/customCommands.d.ts +19 -0
  176. package/dist/core/customCommands.d.ts.map +1 -0
  177. package/dist/core/customCommands.js +85 -0
  178. package/dist/core/customCommands.js.map +1 -0
  179. package/dist/core/diffPanel.d.ts +30 -0
  180. package/dist/core/diffPanel.d.ts.map +1 -0
  181. package/dist/core/diffPanel.js +48 -0
  182. package/dist/core/diffPanel.js.map +1 -0
  183. package/dist/core/errorClassification.d.ts +44 -0
  184. package/dist/core/errorClassification.d.ts.map +1 -0
  185. package/dist/core/errorClassification.js +333 -0
  186. package/dist/core/errorClassification.js.map +1 -0
  187. package/dist/core/errors/apiKeyErrors.d.ts +11 -0
  188. package/dist/core/errors/apiKeyErrors.d.ts.map +1 -0
  189. package/dist/core/errors/apiKeyErrors.js +159 -0
  190. package/dist/core/errors/apiKeyErrors.js.map +1 -0
  191. package/dist/core/errors/errorTypes.d.ts +111 -0
  192. package/dist/core/errors/errorTypes.d.ts.map +1 -0
  193. package/dist/core/errors/errorTypes.js +345 -0
  194. package/dist/core/errors/errorTypes.js.map +1 -0
  195. package/dist/core/errors/index.d.ts +50 -0
  196. package/dist/core/errors/index.d.ts.map +1 -0
  197. package/dist/core/errors/index.js +156 -0
  198. package/dist/core/errors/index.js.map +1 -0
  199. package/dist/core/errors/networkErrors.d.ts +14 -0
  200. package/dist/core/errors/networkErrors.d.ts.map +1 -0
  201. package/dist/core/errors/networkErrors.js +53 -0
  202. package/dist/core/errors/networkErrors.js.map +1 -0
  203. package/dist/core/errors/safetyValidator.d.ts +109 -0
  204. package/dist/core/errors/safetyValidator.d.ts.map +1 -0
  205. package/dist/core/errors/safetyValidator.js +272 -0
  206. package/dist/core/errors/safetyValidator.js.map +1 -0
  207. package/dist/core/errors.d.ts +4 -0
  208. package/dist/core/errors.d.ts.map +1 -0
  209. package/dist/core/errors.js +33 -0
  210. package/dist/core/errors.js.map +1 -0
  211. package/dist/core/failureRegistry.d.ts +30 -0
  212. package/dist/core/failureRegistry.d.ts.map +1 -0
  213. package/dist/core/failureRegistry.js +74 -0
  214. package/dist/core/failureRegistry.js.map +1 -0
  215. package/dist/core/fileMentions.d.ts +40 -0
  216. package/dist/core/fileMentions.d.ts.map +1 -0
  217. package/dist/core/fileMentions.js +136 -0
  218. package/dist/core/fileMentions.js.map +1 -0
  219. package/dist/core/finalResponseFormatter.d.ts +10 -0
  220. package/dist/core/finalResponseFormatter.d.ts.map +1 -0
  221. package/dist/core/finalResponseFormatter.js +14 -0
  222. package/dist/core/finalResponseFormatter.js.map +1 -0
  223. package/dist/core/guardrails.d.ts +146 -0
  224. package/dist/core/guardrails.d.ts.map +1 -0
  225. package/dist/core/guardrails.js +361 -0
  226. package/dist/core/guardrails.js.map +1 -0
  227. package/dist/core/hitl.d.ts +119 -0
  228. package/dist/core/hitl.d.ts.map +1 -0
  229. package/dist/core/hitl.js +396 -0
  230. package/dist/core/hitl.js.map +1 -0
  231. package/dist/core/hooks.d.ts +95 -0
  232. package/dist/core/hooks.d.ts.map +1 -0
  233. package/dist/core/hooks.js +236 -0
  234. package/dist/core/hooks.js.map +1 -0
  235. package/dist/core/hostedAuth.d.ts +88 -0
  236. package/dist/core/hostedAuth.d.ts.map +1 -0
  237. package/dist/core/hostedAuth.js +219 -0
  238. package/dist/core/hostedAuth.js.map +1 -0
  239. package/dist/core/inputProtection.d.ts +122 -0
  240. package/dist/core/inputProtection.d.ts.map +1 -0
  241. package/dist/core/inputProtection.js +422 -0
  242. package/dist/core/inputProtection.js.map +1 -0
  243. package/dist/core/modelDiscovery.d.ts +102 -0
  244. package/dist/core/modelDiscovery.d.ts.map +1 -0
  245. package/dist/core/modelDiscovery.js +416 -0
  246. package/dist/core/modelDiscovery.js.map +1 -0
  247. package/dist/core/multilinePasteHandler.d.ts +35 -0
  248. package/dist/core/multilinePasteHandler.d.ts.map +1 -0
  249. package/dist/core/multilinePasteHandler.js +81 -0
  250. package/dist/core/multilinePasteHandler.js.map +1 -0
  251. package/dist/core/permissionMode.d.ts +40 -0
  252. package/dist/core/permissionMode.d.ts.map +1 -0
  253. package/dist/core/permissionMode.js +86 -0
  254. package/dist/core/permissionMode.js.map +1 -0
  255. package/dist/core/postWriteDiagnostics.d.ts +32 -0
  256. package/dist/core/postWriteDiagnostics.d.ts.map +1 -0
  257. package/dist/core/postWriteDiagnostics.js +127 -0
  258. package/dist/core/postWriteDiagnostics.js.map +1 -0
  259. package/dist/core/preferences.d.ts +66 -0
  260. package/dist/core/preferences.d.ts.map +1 -0
  261. package/dist/core/preferences.js +310 -0
  262. package/dist/core/preferences.js.map +1 -0
  263. package/dist/core/quota.d.ts +61 -0
  264. package/dist/core/quota.d.ts.map +1 -0
  265. package/dist/core/quota.js +104 -0
  266. package/dist/core/quota.js.map +1 -0
  267. package/dist/core/quotaErrors.d.ts +42 -0
  268. package/dist/core/quotaErrors.d.ts.map +1 -0
  269. package/dist/core/quotaErrors.js +86 -0
  270. package/dist/core/quotaErrors.js.map +1 -0
  271. package/dist/core/refusalDetection.d.ts +2 -0
  272. package/dist/core/refusalDetection.d.ts.map +1 -0
  273. package/dist/core/refusalDetection.js +51 -0
  274. package/dist/core/refusalDetection.js.map +1 -0
  275. package/dist/core/relativeTime.d.ts +8 -0
  276. package/dist/core/relativeTime.d.ts.map +1 -0
  277. package/dist/core/relativeTime.js +29 -0
  278. package/dist/core/relativeTime.js.map +1 -0
  279. package/dist/core/resultVerification.d.ts +48 -0
  280. package/dist/core/resultVerification.d.ts.map +1 -0
  281. package/dist/core/resultVerification.js +127 -0
  282. package/dist/core/resultVerification.js.map +1 -0
  283. package/dist/core/rewind.d.ts +14 -0
  284. package/dist/core/rewind.d.ts.map +1 -0
  285. package/dist/core/rewind.js +25 -0
  286. package/dist/core/rewind.js.map +1 -0
  287. package/dist/core/schemaValidator.d.ts +49 -0
  288. package/dist/core/schemaValidator.d.ts.map +1 -0
  289. package/dist/core/schemaValidator.js +234 -0
  290. package/dist/core/schemaValidator.js.map +1 -0
  291. package/dist/core/secretStore.d.ts +59 -0
  292. package/dist/core/secretStore.d.ts.map +1 -0
  293. package/dist/core/secretStore.js +278 -0
  294. package/dist/core/secretStore.js.map +1 -0
  295. package/dist/core/sessionStorage.d.ts +10 -0
  296. package/dist/core/sessionStorage.d.ts.map +1 -0
  297. package/dist/core/sessionStorage.js +46 -0
  298. package/dist/core/sessionStorage.js.map +1 -0
  299. package/dist/core/sessionStore.d.ts +35 -0
  300. package/dist/core/sessionStore.d.ts.map +1 -0
  301. package/dist/core/sessionStore.js +190 -0
  302. package/dist/core/sessionStore.js.map +1 -0
  303. package/dist/core/shutdown.d.ts +34 -0
  304. package/dist/core/shutdown.d.ts.map +1 -0
  305. package/dist/core/shutdown.js +186 -0
  306. package/dist/core/shutdown.js.map +1 -0
  307. package/dist/core/slashCommands.d.ts +38 -0
  308. package/dist/core/slashCommands.d.ts.map +1 -0
  309. package/dist/core/slashCommands.js +72 -0
  310. package/dist/core/slashCommands.js.map +1 -0
  311. package/dist/core/subAgentNote.d.ts +15 -0
  312. package/dist/core/subAgentNote.d.ts.map +1 -0
  313. package/dist/core/subAgentNote.js +16 -0
  314. package/dist/core/subAgentNote.js.map +1 -0
  315. package/dist/core/sudoPasswordManager.d.ts +52 -0
  316. package/dist/core/sudoPasswordManager.d.ts.map +1 -0
  317. package/dist/core/sudoPasswordManager.js +115 -0
  318. package/dist/core/sudoPasswordManager.js.map +1 -0
  319. package/dist/core/taskCompletionDetector.d.ts +117 -0
  320. package/dist/core/taskCompletionDetector.d.ts.map +1 -0
  321. package/dist/core/taskCompletionDetector.js +532 -0
  322. package/dist/core/taskCompletionDetector.js.map +1 -0
  323. package/dist/core/testFailureMonitor.d.ts +67 -0
  324. package/dist/core/testFailureMonitor.d.ts.map +1 -0
  325. package/dist/core/testFailureMonitor.js +262 -0
  326. package/dist/core/testFailureMonitor.js.map +1 -0
  327. package/dist/core/thinkingVerbs.d.ts +31 -0
  328. package/dist/core/thinkingVerbs.d.ts.map +1 -0
  329. package/dist/core/thinkingVerbs.js +58 -0
  330. package/dist/core/thinkingVerbs.js.map +1 -0
  331. package/dist/core/toolPreconditions.d.ts +34 -0
  332. package/dist/core/toolPreconditions.d.ts.map +1 -0
  333. package/dist/core/toolPreconditions.js +242 -0
  334. package/dist/core/toolPreconditions.js.map +1 -0
  335. package/dist/core/toolRuntime.d.ts +193 -0
  336. package/dist/core/toolRuntime.d.ts.map +1 -0
  337. package/dist/core/toolRuntime.js +526 -0
  338. package/dist/core/toolRuntime.js.map +1 -0
  339. package/dist/core/turnGovernor.d.ts +63 -0
  340. package/dist/core/turnGovernor.d.ts.map +1 -0
  341. package/dist/core/turnGovernor.js +94 -0
  342. package/dist/core/turnGovernor.js.map +1 -0
  343. package/dist/core/types/utilityTypes.d.ts +183 -0
  344. package/dist/core/types/utilityTypes.d.ts.map +1 -0
  345. package/dist/core/types/utilityTypes.js +273 -0
  346. package/dist/core/types/utilityTypes.js.map +1 -0
  347. package/dist/core/types.d.ts +334 -0
  348. package/dist/core/types.d.ts.map +1 -0
  349. package/dist/core/types.js +76 -0
  350. package/dist/core/types.js.map +1 -0
  351. package/dist/core/updateChecker.d.ts +148 -0
  352. package/dist/core/updateChecker.d.ts.map +1 -0
  353. package/dist/core/updateChecker.js +605 -0
  354. package/dist/core/updateChecker.js.map +1 -0
  355. package/dist/core/usage.d.ts +28 -0
  356. package/dist/core/usage.d.ts.map +1 -0
  357. package/dist/core/usage.js +77 -0
  358. package/dist/core/usage.js.map +1 -0
  359. package/dist/headless/interactiveShell.d.ts +47 -0
  360. package/dist/headless/interactiveShell.d.ts.map +1 -0
  361. package/dist/headless/interactiveShell.js +2495 -0
  362. package/dist/headless/interactiveShell.js.map +1 -0
  363. package/dist/leanAgent.d.ts +73 -0
  364. package/dist/leanAgent.d.ts.map +1 -0
  365. package/dist/leanAgent.js +177 -0
  366. package/dist/leanAgent.js.map +1 -0
  367. package/dist/plugins/providers/deepseek/index.d.ts +12 -0
  368. package/dist/plugins/providers/deepseek/index.d.ts.map +1 -0
  369. package/dist/plugins/providers/deepseek/index.js +123 -0
  370. package/dist/plugins/providers/deepseek/index.js.map +1 -0
  371. package/dist/plugins/providers/index.d.ts +2 -0
  372. package/dist/plugins/providers/index.d.ts.map +1 -0
  373. package/dist/plugins/providers/index.js +10 -0
  374. package/dist/plugins/providers/index.js.map +1 -0
  375. package/dist/providers/baseProvider.d.ts +140 -0
  376. package/dist/providers/baseProvider.d.ts.map +1 -0
  377. package/dist/providers/baseProvider.js +230 -0
  378. package/dist/providers/baseProvider.js.map +1 -0
  379. package/dist/providers/openaiChatCompletionsProvider.d.ts +70 -0
  380. package/dist/providers/openaiChatCompletionsProvider.d.ts.map +1 -0
  381. package/dist/providers/openaiChatCompletionsProvider.js +971 -0
  382. package/dist/providers/openaiChatCompletionsProvider.js.map +1 -0
  383. package/dist/providers/providerFactory.d.ts +22 -0
  384. package/dist/providers/providerFactory.d.ts.map +1 -0
  385. package/dist/providers/providerFactory.js +25 -0
  386. package/dist/providers/providerFactory.js.map +1 -0
  387. package/dist/providers/resilientProvider.d.ts +96 -0
  388. package/dist/providers/resilientProvider.d.ts.map +1 -0
  389. package/dist/providers/resilientProvider.js +251 -0
  390. package/dist/providers/resilientProvider.js.map +1 -0
  391. package/dist/runtime/agentController.d.ts +137 -0
  392. package/dist/runtime/agentController.d.ts.map +1 -0
  393. package/dist/runtime/agentController.js +784 -0
  394. package/dist/runtime/agentController.js.map +1 -0
  395. package/dist/runtime/agentHost.d.ts +61 -0
  396. package/dist/runtime/agentHost.d.ts.map +1 -0
  397. package/dist/runtime/agentHost.js +158 -0
  398. package/dist/runtime/agentHost.js.map +1 -0
  399. package/dist/runtime/agentSession.d.ts +49 -0
  400. package/dist/runtime/agentSession.d.ts.map +1 -0
  401. package/dist/runtime/agentSession.js +218 -0
  402. package/dist/runtime/agentSession.js.map +1 -0
  403. package/dist/runtime/agentSpawningWiring.d.ts +32 -0
  404. package/dist/runtime/agentSpawningWiring.d.ts.map +1 -0
  405. package/dist/runtime/agentSpawningWiring.js +114 -0
  406. package/dist/runtime/agentSpawningWiring.js.map +1 -0
  407. package/dist/runtime/node.d.ts +7 -0
  408. package/dist/runtime/node.d.ts.map +1 -0
  409. package/dist/runtime/node.js +50 -0
  410. package/dist/runtime/node.js.map +1 -0
  411. package/dist/runtime/universal.d.ts +18 -0
  412. package/dist/runtime/universal.d.ts.map +1 -0
  413. package/dist/runtime/universal.js +21 -0
  414. package/dist/runtime/universal.js.map +1 -0
  415. package/dist/shell/liveStatus.d.ts +27 -0
  416. package/dist/shell/liveStatus.d.ts.map +1 -0
  417. package/dist/shell/liveStatus.js +53 -0
  418. package/dist/shell/liveStatus.js.map +1 -0
  419. package/dist/shell/systemPrompt.d.ts +12 -0
  420. package/dist/shell/systemPrompt.d.ts.map +1 -0
  421. package/dist/shell/systemPrompt.js +16 -0
  422. package/dist/shell/systemPrompt.js.map +1 -0
  423. package/dist/shell/toolPresentation.d.ts +54 -0
  424. package/dist/shell/toolPresentation.d.ts.map +1 -0
  425. package/dist/shell/toolPresentation.js +334 -0
  426. package/dist/shell/toolPresentation.js.map +1 -0
  427. package/dist/tools/bashTools.d.ts +11 -0
  428. package/dist/tools/bashTools.d.ts.map +1 -0
  429. package/dist/tools/bashTools.js +785 -0
  430. package/dist/tools/bashTools.js.map +1 -0
  431. package/dist/tools/diffUtils.d.ts +43 -0
  432. package/dist/tools/diffUtils.d.ts.map +1 -0
  433. package/dist/tools/diffUtils.js +607 -0
  434. package/dist/tools/diffUtils.js.map +1 -0
  435. package/dist/tools/editTools.d.ts +29 -0
  436. package/dist/tools/editTools.d.ts.map +1 -0
  437. package/dist/tools/editTools.js +792 -0
  438. package/dist/tools/editTools.js.map +1 -0
  439. package/dist/tools/fileChangeTracker.d.ts +47 -0
  440. package/dist/tools/fileChangeTracker.d.ts.map +1 -0
  441. package/dist/tools/fileChangeTracker.js +154 -0
  442. package/dist/tools/fileChangeTracker.js.map +1 -0
  443. package/dist/tools/fileReadTracker.d.ts +69 -0
  444. package/dist/tools/fileReadTracker.d.ts.map +1 -0
  445. package/dist/tools/fileReadTracker.js +213 -0
  446. package/dist/tools/fileReadTracker.js.map +1 -0
  447. package/dist/tools/fileTools.d.ts +3 -0
  448. package/dist/tools/fileTools.d.ts.map +1 -0
  449. package/dist/tools/fileTools.js +389 -0
  450. package/dist/tools/fileTools.js.map +1 -0
  451. package/dist/tools/grepTools.d.ts +3 -0
  452. package/dist/tools/grepTools.d.ts.map +1 -0
  453. package/dist/tools/grepTools.js +137 -0
  454. package/dist/tools/grepTools.js.map +1 -0
  455. package/dist/tools/hitlTools.d.ts +7 -0
  456. package/dist/tools/hitlTools.d.ts.map +1 -0
  457. package/dist/tools/hitlTools.js +185 -0
  458. package/dist/tools/hitlTools.js.map +1 -0
  459. package/dist/tools/memoryTools.d.ts +27 -0
  460. package/dist/tools/memoryTools.d.ts.map +1 -0
  461. package/dist/tools/memoryTools.js +197 -0
  462. package/dist/tools/memoryTools.js.map +1 -0
  463. package/dist/tools/notebookTools.d.ts +20 -0
  464. package/dist/tools/notebookTools.d.ts.map +1 -0
  465. package/dist/tools/notebookTools.js +140 -0
  466. package/dist/tools/notebookTools.js.map +1 -0
  467. package/dist/tools/searchTools.d.ts +12 -0
  468. package/dist/tools/searchTools.d.ts.map +1 -0
  469. package/dist/tools/searchTools.js +414 -0
  470. package/dist/tools/searchTools.js.map +1 -0
  471. package/dist/tools/skillTools.d.ts +24 -0
  472. package/dist/tools/skillTools.d.ts.map +1 -0
  473. package/dist/tools/skillTools.js +140 -0
  474. package/dist/tools/skillTools.js.map +1 -0
  475. package/dist/tools/todoTools.d.ts +23 -0
  476. package/dist/tools/todoTools.d.ts.map +1 -0
  477. package/dist/tools/todoTools.js +120 -0
  478. package/dist/tools/todoTools.js.map +1 -0
  479. package/dist/tools/webTools.d.ts +26 -0
  480. package/dist/tools/webTools.d.ts.map +1 -0
  481. package/dist/tools/webTools.js +467 -0
  482. package/dist/tools/webTools.js.map +1 -0
  483. package/dist/ui/ink/App.d.ts +53 -0
  484. package/dist/ui/ink/App.d.ts.map +1 -0
  485. package/dist/ui/ink/App.js +13 -0
  486. package/dist/ui/ink/App.js.map +1 -0
  487. package/dist/ui/ink/ChatStatic.d.ts +30 -0
  488. package/dist/ui/ink/ChatStatic.d.ts.map +1 -0
  489. package/dist/ui/ink/ChatStatic.js +83 -0
  490. package/dist/ui/ink/ChatStatic.js.map +1 -0
  491. package/dist/ui/ink/InkPromptController.d.ts +321 -0
  492. package/dist/ui/ink/InkPromptController.d.ts.map +1 -0
  493. package/dist/ui/ink/InkPromptController.js +667 -0
  494. package/dist/ui/ink/InkPromptController.js.map +1 -0
  495. package/dist/ui/ink/Menu.d.ts +21 -0
  496. package/dist/ui/ink/Menu.d.ts.map +1 -0
  497. package/dist/ui/ink/Menu.js +61 -0
  498. package/dist/ui/ink/Menu.js.map +1 -0
  499. package/dist/ui/ink/Prompt.d.ts +47 -0
  500. package/dist/ui/ink/Prompt.d.ts.map +1 -0
  501. package/dist/ui/ink/Prompt.js +571 -0
  502. package/dist/ui/ink/Prompt.js.map +1 -0
  503. package/dist/ui/ink/StatusLine.d.ts +35 -0
  504. package/dist/ui/ink/StatusLine.d.ts.map +1 -0
  505. package/dist/ui/ink/StatusLine.js +66 -0
  506. package/dist/ui/ink/StatusLine.js.map +1 -0
  507. package/dist/ui/ink/pasteBuffer.d.ts +44 -0
  508. package/dist/ui/ink/pasteBuffer.d.ts.map +1 -0
  509. package/dist/ui/ink/pasteBuffer.js +73 -0
  510. package/dist/ui/ink/pasteBuffer.js.map +1 -0
  511. package/dist/ui/theme.d.ts +351 -0
  512. package/dist/ui/theme.d.ts.map +1 -0
  513. package/dist/ui/theme.js +435 -0
  514. package/dist/ui/theme.js.map +1 -0
  515. package/dist/utils/analytics.d.ts +2 -0
  516. package/dist/utils/analytics.d.ts.map +1 -0
  517. package/dist/utils/analytics.js +51 -0
  518. package/dist/utils/analytics.js.map +1 -0
  519. package/dist/utils/asyncUtils.d.ts +95 -0
  520. package/dist/utils/asyncUtils.d.ts.map +1 -0
  521. package/dist/utils/asyncUtils.js +286 -0
  522. package/dist/utils/asyncUtils.js.map +1 -0
  523. package/dist/utils/debugLogger.d.ts +6 -0
  524. package/dist/utils/debugLogger.d.ts.map +1 -0
  525. package/dist/utils/debugLogger.js +39 -0
  526. package/dist/utils/debugLogger.js.map +1 -0
  527. package/dist/utils/errorUtils.d.ts +12 -0
  528. package/dist/utils/errorUtils.d.ts.map +1 -0
  529. package/dist/utils/errorUtils.js +83 -0
  530. package/dist/utils/errorUtils.js.map +1 -0
  531. package/dist/utils/frontmatter.d.ts +10 -0
  532. package/dist/utils/frontmatter.d.ts.map +1 -0
  533. package/dist/utils/frontmatter.js +78 -0
  534. package/dist/utils/frontmatter.js.map +1 -0
  535. package/dist/utils/packageInfo.d.ts +14 -0
  536. package/dist/utils/packageInfo.d.ts.map +1 -0
  537. package/dist/utils/packageInfo.js +45 -0
  538. package/dist/utils/packageInfo.js.map +1 -0
  539. package/dist/utils/planFormatter.d.ts +34 -0
  540. package/dist/utils/planFormatter.d.ts.map +1 -0
  541. package/dist/utils/planFormatter.js +141 -0
  542. package/dist/utils/planFormatter.js.map +1 -0
  543. package/dist/utils/securityUtils.d.ts +132 -0
  544. package/dist/utils/securityUtils.d.ts.map +1 -0
  545. package/dist/utils/securityUtils.js +324 -0
  546. package/dist/utils/securityUtils.js.map +1 -0
  547. package/dist/utils/statusReporter.d.ts +6 -0
  548. package/dist/utils/statusReporter.d.ts.map +1 -0
  549. package/dist/utils/statusReporter.js +26 -0
  550. package/dist/utils/statusReporter.js.map +1 -0
  551. package/dist/workspace.d.ts +8 -0
  552. package/dist/workspace.d.ts.map +1 -0
  553. package/dist/workspace.js +135 -0
  554. package/dist/workspace.js.map +1 -0
  555. package/dist/workspace.validator.d.ts +49 -0
  556. package/dist/workspace.validator.d.ts.map +1 -0
  557. package/dist/workspace.validator.js +215 -0
  558. package/dist/workspace.validator.js.map +1 -0
  559. package/package.json +116 -0
  560. package/scripts/postinstall.cjs +56 -0
@@ -0,0 +1,667 @@
1
+ /**
2
+ * InkPromptController — the CLI's prompt controller, backed by the Ink
3
+ * renderer. Constructed via createPromptController(); it is the only
4
+ * renderer the shell uses.
5
+ *
6
+ * Goal: satisfy every method that src/headless/interactiveShell.ts calls
7
+ * so the rest of the codebase doesn't notice the swap. Live methods
8
+ * (status, history, secret mode, menu) drive an Ink reconciler commit;
9
+ * decorative methods that don't yet have an Ink implementation are
10
+ * marked as TODOs and behave as no-ops, with the call recorded so
11
+ * future hardening can fill the gaps with real behaviour rather than
12
+ * silent drift.
13
+ *
14
+ * Renderer shim: interactiveShell.ts also calls a handful of methods
15
+ * directly via promptController.getRenderer() — addEvent, addOutputTap,
16
+ * captureInput, clearBuffer, setSecretMode, forceRender. We expose a
17
+ * facade implementing exactly those.
18
+ */
19
+ import { EventEmitter } from 'node:events';
20
+ import { cyclePermissionMode, permissionHint, permissionStatusChip } from '../../core/permissionMode.js';
21
+ import { isGenericThinking } from '../../core/thinkingVerbs.js';
22
+ /** Map RendererEventType (UnifiedUIRenderer) to ChatItem.kind. */
23
+ const EVENT_KIND_MAP = {
24
+ banner: 'banner',
25
+ system: 'system',
26
+ error: 'error',
27
+ response: 'assistant',
28
+ stream: 'assistant',
29
+ thought: 'system',
30
+ tool: 'tool',
31
+ 'tool-call': 'tool',
32
+ 'tool-result': 'toolResult',
33
+ raw: 'system',
34
+ streaming: 'system',
35
+ };
36
+ /**
37
+ * The minimal subset of the legacy UnifiedUIRenderer that
38
+ * interactiveShell.ts actually calls. Backed by Ink state under the
39
+ * hood. Method signatures match the legacy renderer exactly — the
40
+ * caller can't tell which implementation it's holding.
41
+ */
42
+ class InkRendererShim extends EventEmitter {
43
+ owner;
44
+ taps = new Set();
45
+ resolveCapture = null;
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ constructor(owner) {
48
+ super();
49
+ this.owner = owner;
50
+ }
51
+ addEvent(type, content) {
52
+ // Always feed the taps first — they observe the raw event stream
53
+ // even if the type is filtered out of the visible history.
54
+ for (const tap of this.taps) {
55
+ try {
56
+ tap(type, content);
57
+ }
58
+ catch { /* tap errors must not break rendering */ }
59
+ }
60
+ // Thoughts are the model's pre-response reasoning. Showing them as
61
+ // plain chat lines (which my previous map did) leaks "The user
62
+ // just said 'hi' — this is a greeting…" into the visible
63
+ // transcript right above the actual answer. Drop them from the
64
+ // chat surface; debug mode can re-enable later.
65
+ if (type === 'thought' || type === 'streaming')
66
+ return;
67
+ if (type === 'stream') {
68
+ // Coalesce streaming deltas into a single growing assistant
69
+ // message. Pre-fix this rendered "Hi How can I help you today"
70
+ // as one word per line because each delta became its own
71
+ // ChatItem. Now the in-progress message lives in
72
+ // owner._streamingText and renders in a non-Static slot above
73
+ // the prompt; on the next non-stream event (typically the
74
+ // 'response' completion) we commit it as a Static entry.
75
+ this.owner._appendStreamingDelta(content);
76
+ return;
77
+ }
78
+ if (type === 'response') {
79
+ // Streaming is finishing. Replace the in-progress text with the
80
+ // canonical final content (the streamed chunks may have lost
81
+ // formatting under markdown wrapping) and commit to history.
82
+ this.owner._commitStreaming(content);
83
+ return;
84
+ }
85
+ // Non-streaming events: a brand-new committed history entry. Also
86
+ // finalises any in-progress streaming message in case the model
87
+ // emitted a tool/system event between deltas.
88
+ this.owner._finalizeStreamingIfAny();
89
+ const kind = EVENT_KIND_MAP[type] ?? 'system';
90
+ this.owner._appendHistoryEntry({ id: `e-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`, kind, text: content });
91
+ }
92
+ addOutputTap(fn) {
93
+ this.taps.add(fn);
94
+ return () => { this.taps.delete(fn); };
95
+ }
96
+ /**
97
+ * Resolve the next user submission with the typed text. Used by the
98
+ * sudo-password capture flow in interactiveShell.ts.
99
+ *
100
+ * Implementation: stash a resolver, swap the prompt callbacks for one
101
+ * that resolves it, restore on submit. The owner runs setSecretMode
102
+ * around the call site.
103
+ */
104
+ captureInput(_opts = {}) {
105
+ return new Promise((resolve) => {
106
+ this.resolveCapture = resolve;
107
+ this.owner._installCaptureHandler((text) => {
108
+ const trim = _opts.trim !== false;
109
+ const value = trim ? text.trim() : text;
110
+ if (this.resolveCapture) {
111
+ const r = this.resolveCapture;
112
+ this.resolveCapture = null;
113
+ this.owner._restoreSubmitHandler();
114
+ if (_opts.resetBuffer !== false)
115
+ this.owner._setBuffer('');
116
+ r(value);
117
+ }
118
+ });
119
+ });
120
+ }
121
+ clearBuffer() {
122
+ this.owner._setBuffer('');
123
+ }
124
+ setSecretMode(enabled) {
125
+ this.owner._setSecretMode(enabled);
126
+ }
127
+ /** No-op. Ink owns its render loop; manual force is unnecessary. */
128
+ forceRender() { }
129
+ /** Shape parity with the legacy renderer; returns a fixed false. */
130
+ supportsInlinePanel() { return true; }
131
+ /**
132
+ * Used by interactiveShell.ts when re-rendering a tool result after
133
+ * the user expands it. Live update: append a new history entry with
134
+ * the expanded content.
135
+ */
136
+ expandLastToolResult() { return false; }
137
+ getCollapsedResultCount() { return 0; }
138
+ // Live follow-up queue (Claude Code parity). interactiveShell.ts drives the
139
+ // queue through getRenderer() (this shim), but the state lives on the owning
140
+ // controller — proxy through so the call doesn't throw "is not a function"
141
+ // and crash the shell when a prompt is submitted while the agent is busy.
142
+ setFollowUpQueueMode(on) { this.owner.setFollowUpQueueMode(on); }
143
+ setQueuedPrompts(prompts) { this.owner.setQueuedPrompts(prompts); }
144
+ addUserHistoryItem(text) { this.owner.addUserHistoryItem(text); }
145
+ }
146
+ export class InkPromptController extends EventEmitter {
147
+ callbacks;
148
+ // ink module + App component imported lazily on start() so non-Ink
149
+ // codepaths don't pay the React parse cost.
150
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
151
+ inkRender = null;
152
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
153
+ React = null;
154
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
155
+ AppComponent = null;
156
+ inst = null;
157
+ shim = new InkRendererShim(this);
158
+ stdin;
159
+ stdout;
160
+ // In-progress assistant message — accumulates 'stream' deltas. While
161
+ // non-null it renders below <Static> in a regular Ink Box so the text
162
+ // grows in place. Committed to history on 'response' (or finalised
163
+ // when any non-stream event arrives mid-flight).
164
+ streamingText = '';
165
+ // Monotonic suffix for ChatItem ids: Date.now() alone collides when several
166
+ // entries are appended in the same millisecond (e.g. the synchronous /resume
167
+ // replay), producing duplicate React keys in <Static>.
168
+ idSeq = 0;
169
+ // ── live state ────────────────────────────────────────────────
170
+ statusMain = null;
171
+ statusOverride = null;
172
+ statusStreaming = null;
173
+ activityMessage = null;
174
+ mode = 'idle';
175
+ metaInfo = {};
176
+ // ms timestamp the current spinner run began — drives the elapsed counter in
177
+ // StatusLine. Set when the UI transitions into a spinning state, cleared when
178
+ // it stops, so each working run reports its own elapsed time.
179
+ spinStart = null;
180
+ history = [];
181
+ suggestions = [];
182
+ inlinePanel = null;
183
+ secretMode = false;
184
+ editMode = 'display-edits';
185
+ pinnedPrompt = null;
186
+ modeToggleState = {
187
+ autoMode: 'on',
188
+ autoContinueHotkey: '⌥G',
189
+ hitlMode: 'off',
190
+ hitlHotkey: '⌥V',
191
+ };
192
+ buffer = '';
193
+ // Submitted prompts (oldest→newest) for Up/Down shell history navigation.
194
+ promptHistory = [];
195
+ // Workspace files (repo-relative) for @-mention autocomplete.
196
+ completionFiles = [];
197
+ // Set by InkRendererShim.captureInput — temporarily replaces onSubmit.
198
+ captureSubmit = null;
199
+ menuCallback = null;
200
+ menuItems = [];
201
+ // Live follow-up queue (Claude Code parity): when true, the onSubmit wrapper
202
+ // skips appending the user line to permanent <Static> history. The line is
203
+ // shown only in the transient queued region (App) until its turn is dequeued.
204
+ // At dequeue time the shell calls addUserHistoryItem just before processPrompt.
205
+ followUpQueueMode = false;
206
+ queuedPrompts = [];
207
+ menuTitle;
208
+ menuOpen = false;
209
+ started = false;
210
+ disposed = false;
211
+ // Resolves once Ink has finished its async mount (the dynamic ink/react/App
212
+ // imports + first render). Callers that drive events right after start()
213
+ // must await this, or a fast process.exit() can pre-empt the mount and the
214
+ // first frame never reaches stdout (empty-output flake under CPU contention).
215
+ resolveReady;
216
+ readyPromise = new Promise((r) => { this.resolveReady = r; });
217
+ constructor(stdin, stdout, callbacks) {
218
+ super();
219
+ this.stdin = stdin;
220
+ this.stdout = stdout;
221
+ this.callbacks = callbacks;
222
+ }
223
+ // ── lifecycle ─────────────────────────────────────────────────
224
+ /**
225
+ * Async start so the Ink + React modules can be loaded via dynamic
226
+ * import (the dist build emits ESM under `module: NodeNext`, where
227
+ * `require()` mixed with top-level await is a hard error in Node 22+).
228
+ * Call sites that go through createPromptController() should await
229
+ * .start(); the legacy controller's start() is sync, so the IPrompt
230
+ * interface defines start() as `void` and we coerce here.
231
+ */
232
+ start() { void this.startAsync(); }
233
+ /** Resolves once Ink has mounted and rendered its first frame. */
234
+ whenReady() { return this.readyPromise; }
235
+ async startAsync() {
236
+ if (this.started || this.disposed) {
237
+ this.resolveReady();
238
+ return;
239
+ }
240
+ this.started = true;
241
+ try {
242
+ const [ink, react, appMod] = await Promise.all([
243
+ import('ink'),
244
+ import('react'),
245
+ import('./App.js'),
246
+ ]);
247
+ this.React = react;
248
+ this.AppComponent = appMod.App;
249
+ this.inkRender = ink.render;
250
+ this.inst = this.inkRender(this.buildTree(), {
251
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
252
+ stdin: this.stdin,
253
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
254
+ stdout: this.stdout,
255
+ // exitOnCtrlC=false so the host's onCtrlC callback fires first.
256
+ exitOnCtrlC: false,
257
+ });
258
+ }
259
+ finally {
260
+ // Always resolve — a waiter must never hang even if mount throws.
261
+ this.resolveReady();
262
+ }
263
+ }
264
+ stop() {
265
+ if (this.disposed)
266
+ return;
267
+ this.disposed = true;
268
+ this.started = false;
269
+ try {
270
+ this.inst?.unmount();
271
+ }
272
+ catch { /* ignore */ }
273
+ this.inst = null;
274
+ }
275
+ dispose() { this.stop(); }
276
+ /** Manual repaint hook — Ink owns its tick, so render/forceRender are coalesced into a rerender(). */
277
+ render() { this.rerender(); }
278
+ forceRender() { this.rerender(); }
279
+ handleResize() { }
280
+ /**
281
+ * Reset the chat surface (the shell's /clear). Ink's <Static> is
282
+ * append-only — it slices items from an internal index that only grows
283
+ * — so shrinking the history array cannot clear committed scrollback.
284
+ * The only correct reset is to unmount, clear the terminal while Ink is
285
+ * NOT mounted (so the escape can't desync a live render), and remount
286
+ * with empty history; the fresh <Static> restarts at index 0.
287
+ */
288
+ clearScreen() {
289
+ this.history = [];
290
+ this.streamingText = '';
291
+ if (this.inst && this.inkRender && this.React && this.AppComponent) {
292
+ try {
293
+ this.inst.unmount();
294
+ }
295
+ catch { /* ignore */ }
296
+ this.inst = null;
297
+ // \x1b[3J also drops scrollback so the cleared content can't be scrolled to.
298
+ try {
299
+ this.stdout.write('\x1b[2J\x1b[3J\x1b[H');
300
+ }
301
+ catch { /* ignore */ }
302
+ this.inst = this.inkRender(this.buildTree(), {
303
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
304
+ stdin: this.stdin,
305
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
306
+ stdout: this.stdout,
307
+ exitOnCtrlC: false,
308
+ });
309
+ }
310
+ else {
311
+ this.rerender();
312
+ }
313
+ }
314
+ // ── status / activity / streaming ─────────────────────────────
315
+ setStatusMessage(message) { this.statusMain = (message?.trim() || null); this.rerender(); }
316
+ setOverrideStatus(message) { this.statusOverride = (message?.trim() || null); this.rerender(); }
317
+ setStreamingLabel(label) { this.statusStreaming = (label?.trim() || null); this.rerender(); }
318
+ setStatusLine(status) {
319
+ if ('main' in status)
320
+ this.statusMain = status.main?.trim() || null;
321
+ if ('override' in status)
322
+ this.statusOverride = status.override?.trim() || null;
323
+ if ('streaming' in status)
324
+ this.statusStreaming = status.streaming?.trim() || null;
325
+ this.rerender();
326
+ }
327
+ clearAllStatus() {
328
+ this.statusMain = null;
329
+ this.statusOverride = null;
330
+ this.statusStreaming = null;
331
+ this.activityMessage = null;
332
+ this.rerender();
333
+ }
334
+ setActivityMessage(message) { this.activityMessage = message; this.rerender(); }
335
+ setStreaming(streaming) { this.mode = streaming ? 'streaming' : 'idle'; this.rerender(); }
336
+ getMode() { return this.mode; }
337
+ setContextUsage(percentage) {
338
+ if (percentage !== null) {
339
+ this.metaInfo.contextPercent = percentage;
340
+ this.rerender();
341
+ }
342
+ }
343
+ setMetaStatus(meta) {
344
+ if (typeof meta.elapsedSeconds === 'number' && Number.isFinite(meta.elapsedSeconds) && meta.elapsedSeconds >= 0) {
345
+ const m = Math.floor(meta.elapsedSeconds / 60);
346
+ const s = meta.elapsedSeconds % 60;
347
+ this.metaInfo.sessionTime = `${m}:${s < 10 ? '0' : ''}${s}`;
348
+ }
349
+ if (typeof meta.tokensUsed === 'number' && meta.tokensUsed >= 0) {
350
+ this.metaInfo.tokensUsed = meta.tokensUsed;
351
+ }
352
+ if (meta.tokensUsed != null && meta.tokenLimit != null) {
353
+ this.metaInfo.contextPercent = meta.tokenLimit > 0 ? Math.round((meta.tokensUsed / meta.tokenLimit) * 100) : 0;
354
+ }
355
+ this.rerender();
356
+ }
357
+ setModelContext(options) {
358
+ if (options.model !== undefined)
359
+ this.metaInfo.model = options.model || undefined;
360
+ if (options.provider !== undefined)
361
+ this.metaInfo.provider = options.provider || undefined;
362
+ this.rerender();
363
+ }
364
+ setChromeMeta(meta) {
365
+ if (meta.workspace !== undefined)
366
+ this.metaInfo.workspace = meta.workspace;
367
+ if (meta.directory !== undefined)
368
+ this.metaInfo.directory = meta.directory;
369
+ this.rerender();
370
+ }
371
+ // ── toggles ───────────────────────────────────────────────────
372
+ setModeToggles(options) {
373
+ this.modeToggleState = { ...this.modeToggleState, ...options };
374
+ this.rerender();
375
+ }
376
+ setDebugMode(enabled) { this.modeToggleState.debugEnabled = enabled; this.rerender(); }
377
+ toggleAutoContinue() {
378
+ this.modeToggleState.autoMode = this.modeToggleState.autoMode === 'off' ? 'on' : 'off';
379
+ this.rerender();
380
+ this.callbacks.onToggleAutoContinue?.();
381
+ }
382
+ getAutoMode() { return this.modeToggleState.autoMode; }
383
+ setAutoMode(mode) { this.modeToggleState.autoMode = mode; this.rerender(); }
384
+ toggleHITL() {
385
+ this.modeToggleState.hitlMode = this.modeToggleState.hitlMode === 'off' ? 'on' : 'off';
386
+ this.rerender();
387
+ this.callbacks.onToggleHITL?.();
388
+ }
389
+ getHITLMode() { return this.modeToggleState.hitlMode; }
390
+ getModeToggleState() { return this.modeToggleState; }
391
+ // ── inline panel / pinned prompt / menu / suggestions ──────
392
+ setAvailableCommands(commands) {
393
+ this.suggestions = commands.map((c) => ({ label: c.command, hint: c.description }));
394
+ this.rerender();
395
+ }
396
+ setInlinePanel(lines) { this.inlinePanel = [...lines]; this.rerender(); }
397
+ clearInlinePanel() { this.inlinePanel = null; this.rerender(); }
398
+ supportsInlinePanel() { return true; }
399
+ setPinnedPrompt(text) { this.pinnedPrompt = text; this.rerender(); }
400
+ getPinnedPrompt() { return this.pinnedPrompt; }
401
+ clearPinnedPrompt() { this.pinnedPrompt = null; this.rerender(); }
402
+ setMenu(items, options, callback) {
403
+ this.menuItems = items;
404
+ this.menuCallback = callback;
405
+ this.menuTitle = options.title;
406
+ this.menuOpen = true;
407
+ this.rerender();
408
+ }
409
+ closeMenu() { this.resolveMenu(null); }
410
+ isMenuActive() { return this.menuOpen; }
411
+ /** Close the menu and fire the stored callback exactly once. */
412
+ resolveMenu(item) {
413
+ if (!this.menuOpen)
414
+ return;
415
+ this.menuOpen = false;
416
+ const callback = this.menuCallback;
417
+ this.menuCallback = null;
418
+ this.menuItems = [];
419
+ this.menuTitle = undefined;
420
+ this.rerender();
421
+ if (callback) {
422
+ try {
423
+ callback(item);
424
+ }
425
+ catch { /* selection-handler errors must not break the UI */ }
426
+ }
427
+ }
428
+ // ── input buffer ──────────────────────────────────────────────
429
+ setSecretMode(enabled) { this.secretMode = enabled; this.rerender(); }
430
+ setEditMode(mode) { this.editMode = mode; this.callbacks.onEditModeChange?.(mode); }
431
+ applyEditMode(mode) { this.setEditMode(mode); }
432
+ getEditMode() { return this.editMode; }
433
+ /**
434
+ * The input buffer in the Ink path is owned by the Prompt component,
435
+ * not by this controller. We keep `this.buffer` as a snapshot for
436
+ * legacy callers asking for getBuffer/getCursor; updates flow when the
437
+ * Prompt's onSubmit / clear actions fire. setBuffer drives a new
438
+ * `initial` prop on the next mount.
439
+ */
440
+ getBuffer() { return this.buffer; }
441
+ getCursor() { return this.buffer.length; }
442
+ setBuffer(text, _cursorPos) { this.buffer = text; this.rerender(); }
443
+ clear() { this.buffer = ''; this.rerender(); }
444
+ // Live follow-up queue support (see followUpQueueMode comment above)
445
+ setFollowUpQueueMode(on) { this.followUpQueueMode = !!on; this.rerender(); }
446
+ setQueuedPrompts(prompts) { this.queuedPrompts = Array.isArray(prompts) ? prompts.slice() : []; this.rerender(); }
447
+ setCompletionFiles(files) { this.completionFiles = Array.isArray(files) ? files : []; this.rerender(); }
448
+ addUserHistoryItem(text) {
449
+ const t = (text || '').trim();
450
+ if (!t)
451
+ return;
452
+ this.history = [...this.history, { id: `u-${Date.now()}-q-${this.idSeq++}`, kind: 'user', text: t }];
453
+ this.rerender();
454
+ }
455
+ // ── renderer facade ───────────────────────────────────────────
456
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
457
+ getRenderer() { return this.shim; }
458
+ // ── internal ──────────────────────────────────────────────────
459
+ /** Append history (used by the renderer shim's addEvent). */
460
+ _appendHistoryEntry(item) {
461
+ this.history = [...this.history, item];
462
+ this.rerender();
463
+ }
464
+ /**
465
+ * Streaming accumulators. Deltas append to streamingText, which App
466
+ * renders live as the dynamic region below ChatStatic (<Static>). The
467
+ * old duplication bug — partial text orphaned in scrollback when a
468
+ * Static item appended below it — cannot recur: ChatStatic is the ONLY
469
+ * Static node and renders first, so nothing Static ever appends below
470
+ * the live region, and _commitStreaming pushes history + clears
471
+ * streamingText in a single atomic rerender.
472
+ */
473
+ _appendStreamingDelta(delta) {
474
+ this.streamingText = (this.streamingText || '') + (delta || '');
475
+ this.rerender();
476
+ }
477
+ _commitStreaming(finalText) {
478
+ // The real delta path ends with addEvent('response', '\n') — the body
479
+ // lives in the accumulated streamingText, NOT in finalText. The
480
+ // non-delta path carries the full text in finalText with an empty
481
+ // streamingText. A tools run emits a "Next steps" addendum as a
482
+ // distinct response. So: commit the buffered body if present, then
483
+ // commit finalText when it is real and not a duplicate of the body.
484
+ const incoming = (finalText || '').trim();
485
+ const buffered = (this.streamingText || '').trim();
486
+ this.streamingText = '';
487
+ const additions = [];
488
+ if (buffered)
489
+ additions.push({ id: `r-${Date.now()}-b-${this.idSeq++}`, kind: 'assistant', text: buffered });
490
+ if (incoming && incoming !== buffered)
491
+ additions.push({ id: `r-${Date.now()}-c-${this.idSeq++}`, kind: 'assistant', text: incoming });
492
+ if (additions.length)
493
+ this.history = [...this.history, ...additions];
494
+ // Single rerender: ChatStatic gains the entries AND the live region
495
+ // (streamingMessage) goes null in the same commit — atomic swap, no
496
+ // duplicate of the streamed body in scrollback.
497
+ this.rerender();
498
+ }
499
+ _finalizeStreamingIfAny() {
500
+ if (!this.streamingText)
501
+ return;
502
+ const text = this.streamingText.trim();
503
+ this.streamingText = '';
504
+ if (text) {
505
+ this.history = [...this.history, { id: `r-${Date.now()}-${this.idSeq++}`, kind: 'assistant', text }];
506
+ }
507
+ // No rerender — the caller is about to push another history entry
508
+ // and rerender once. Avoid the double commit.
509
+ }
510
+ /** Shift+Tab from the Prompt: advance the permission mode and repaint. */
511
+ cyclePermissionModeFromUI() {
512
+ const next = cyclePermissionMode();
513
+ this.rerender();
514
+ this.callbacks.onCyclePermissionMode?.(next);
515
+ }
516
+ _setBuffer(text) { this.buffer = text; this.rerender(); }
517
+ _setSecretMode(enabled) { this.secretMode = enabled; this.rerender(); }
518
+ _installCaptureHandler(handler) { this.captureSubmit = handler; this.rerender(); }
519
+ _restoreSubmitHandler() { this.captureSubmit = null; this.rerender(); }
520
+ rerender() {
521
+ if (!this.inst)
522
+ return;
523
+ try {
524
+ this.inst.rerender(this.buildTree());
525
+ }
526
+ catch { /* swallow rerender races */ }
527
+ }
528
+ buildTree() {
529
+ const composedStatus = this.statusOverride
530
+ || (this.mode === 'streaming' ? this.statusStreaming : null)
531
+ || this.activityMessage
532
+ || this.statusMain;
533
+ const modeChips = this.formatModeChips();
534
+ const spinning = this.mode === 'streaming' || Boolean(this.activityMessage);
535
+ const thinkingGerund = spinning && isGenericThinking(composedStatus);
536
+ // Stamp the start of a working run on the rising edge; clear it when the
537
+ // spinner stops so the next run's elapsed counter restarts from zero.
538
+ if (spinning) {
539
+ if (this.spinStart == null)
540
+ this.spinStart = Date.now();
541
+ }
542
+ else {
543
+ this.spinStart = null;
544
+ }
545
+ return this.React.createElement(this.AppComponent, {
546
+ history: this.history,
547
+ streamingMessage: this.streamingText || null,
548
+ status: {
549
+ message: composedStatus,
550
+ modeMessage: modeChips,
551
+ spinning,
552
+ startTime: this.spinStart,
553
+ tokensUsed: this.metaInfo.tokensUsed ?? null,
554
+ thinkingGerund,
555
+ },
556
+ suggestions: this.suggestions.length ? this.suggestions : undefined,
557
+ inlinePanel: this.inlinePanel && this.inlinePanel.length ? this.inlinePanel : undefined,
558
+ permissionHint: permissionHint(),
559
+ queuedPrompts: this.queuedPrompts.length ? this.queuedPrompts : undefined,
560
+ menu: this.menuOpen ? {
561
+ items: this.menuItems,
562
+ title: this.menuTitle,
563
+ onSelect: (item) => this.resolveMenu(item),
564
+ onCancel: () => this.resolveMenu(null),
565
+ } : undefined,
566
+ prompt: {
567
+ initial: this.buffer,
568
+ secret: this.secretMode,
569
+ onSubmit: (text) => {
570
+ if (this.captureSubmit) {
571
+ this.captureSubmit(text);
572
+ return;
573
+ }
574
+ // Commit the user's submitted text into history before
575
+ // dispatching to the host. The legacy renderer auto-emitted
576
+ // an 'addEvent("prompt", text)' on its own submit path; the
577
+ // Ink path didn't, so submitted prompts vanished from the
578
+ // chat surface. Symptom: user typed "hi", saw the agent
579
+ // respond, but their own "hi" was never in the transcript.
580
+ // Skip secret submissions (passwords) and slash commands —
581
+ // both are interpreted by the host, not user-visible
582
+ // history. Keeps history aligned with what the agent saw.
583
+ //
584
+ // For live follow-up queue (while isProcessing): we *skip* the
585
+ // permanent history append here. The text lives only in the
586
+ // transient queuedPrompts region (App) until the shell dequeues
587
+ // it and calls addUserHistoryItem right before starting its turn.
588
+ // This guarantees response always appears immediately after its
589
+ // triggering user line (correct ordering, no clumping).
590
+ const trimmed = text.trim();
591
+ if (!this.secretMode && trimmed && !trimmed.startsWith('/')) {
592
+ if (!this.followUpQueueMode) {
593
+ this.history = [
594
+ ...this.history,
595
+ { id: `u-${Date.now()}-${this.idSeq++}`, kind: 'user', text: trimmed },
596
+ ];
597
+ }
598
+ }
599
+ // Record into the Up/Down shell history (skip secrets + consecutive
600
+ // dupes; cap to keep it bounded).
601
+ if (!this.secretMode && trimmed && this.promptHistory[this.promptHistory.length - 1] !== trimmed) {
602
+ this.promptHistory.push(trimmed);
603
+ if (this.promptHistory.length > 200)
604
+ this.promptHistory.shift();
605
+ }
606
+ this.buffer = '';
607
+ this.rerender();
608
+ this.callbacks.onSubmit(text);
609
+ },
610
+ onCancel: () => {
611
+ this.callbacks.onCtrlC?.({ hadBuffer: this.buffer.length > 0 });
612
+ this.callbacks.onInterrupt();
613
+ },
614
+ onCyclePermissionMode: () => this.cyclePermissionModeFromUI(),
615
+ onExpandToolResult: () => this.callbacks.onExpandToolResult?.(),
616
+ onEscape: () => this.callbacks.onEscape?.(),
617
+ onShowShortcuts: () => this.callbacks.onShowShortcuts?.(),
618
+ panelOpen: Boolean(this.inlinePanel && this.inlinePanel.length),
619
+ onDismissPanel: () => this.callbacks.onDismissPanel?.(),
620
+ history: this.promptHistory,
621
+ completionFiles: this.completionFiles,
622
+ },
623
+ });
624
+ }
625
+ /**
626
+ * The dim mode line under the spinner. Claude Code keeps this minimal and
627
+ * emoji-free: product, model, context left, then active toggles. The cwd and
628
+ * elapsed time deliberately don't live here (cwd is in the welcome box;
629
+ * elapsed rides the spinner).
630
+ */
631
+ formatModeChips() {
632
+ const parts = ['trenchwork-coder'];
633
+ const meta = this.metaInfo;
634
+ if (meta.model)
635
+ parts.push(meta.model);
636
+ if (meta.contextPercent != null) {
637
+ const left = Math.max(0, 100 - meta.contextPercent);
638
+ parts.push(`${left}% context left`);
639
+ }
640
+ const permChip = permissionStatusChip();
641
+ if (permChip)
642
+ parts.push(permChip);
643
+ if (this.modeToggleState.autoMode === 'on')
644
+ parts.push('auto');
645
+ if (this.modeToggleState.hitlMode === 'on')
646
+ parts.push('HITL');
647
+ if (this.modeToggleState.debugEnabled)
648
+ parts.push('debug');
649
+ if (this.pinnedPrompt)
650
+ parts.push(this.pinnedPrompt.slice(0, 40));
651
+ // The inline panel now renders as its own block (see App.inlinePanel); it
652
+ // no longer leaks its first line into the meta chips.
653
+ return parts.length ? parts.join(' · ') : null;
654
+ }
655
+ }
656
+ /**
657
+ * Factory — returns the Ink-backed controller. Ink is now the only
658
+ * renderer; the legacy UnifiedUIRenderer + PromptController have been
659
+ * removed. interactiveShell.ts exits early on non-TTY so Ink's
660
+ * raw-mode requirement is always satisfied here. Plain mode
661
+ * (NO_COLOR / TERM=dumb) still flows through Ink — Ink itself
662
+ * down-styles when colours are disabled.
663
+ */
664
+ export async function createPromptController(stdin, stdout, callbacks) {
665
+ return new InkPromptController(stdin, stdout, callbacks);
666
+ }
667
+ //# sourceMappingURL=InkPromptController.js.map