@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,785 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { mkdir } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ import { reportToolProgress } from '../core/toolRuntime.js';
5
+ import { validateBashCommand } from '../core/errors/safetyValidator.js';
6
+ import { analyzeBashFlow } from '../core/bashCommandGuidance.js';
7
+ import { buildError } from '../core/errors.js';
8
+ import { verifiedSuccess, verifiedFailure, analyzeOutput, OutputPatterns, createCommandCheck, } from '../core/resultVerification.js';
9
+ import { createErrorFixer } from '../core/aiErrorFixer.js';
10
+ import { logDebug } from '../utils/debugLogger.js';
11
+ import { createTestMonitor } from '../core/testFailureMonitor.js';
12
+ import { getSudoPassword, invalidateSudoPassword } from '../core/sudoPasswordManager.js';
13
+ // ANSI color codes for enhanced output
14
+ const ANSI_RESET = '\x1b[0m';
15
+ const ANSI_RED = '\x1b[31m';
16
+ const ANSI_GREEN = '\x1b[32m';
17
+ const ANSI_YELLOW = '\x1b[33m';
18
+ const ANSI_BLUE = '\x1b[34m';
19
+ const ANSI_CYAN = '\x1b[36m';
20
+ const ANSI_DIM = '\x1b[2m';
21
+ const ANSI_BOLD = '\x1b[1m';
22
+ const ANSI_RED_BOLD = '\x1b[1;31m';
23
+ const ANSI_GREEN_BOLD = '\x1b[1;32m';
24
+ const ANSI_YELLOW_BOLD = '\x1b[1;33m';
25
+ // ============================================================================
26
+ // Background Shell Manager (consolidated from backgroundBashTools.ts)
27
+ // ============================================================================
28
+ class BackgroundShell {
29
+ id;
30
+ command;
31
+ workingDir;
32
+ process;
33
+ outputBuffer = [];
34
+ errorBuffer = [];
35
+ lastReadPosition = 0;
36
+ lastErrorReadPosition = 0;
37
+ isRunning = false;
38
+ exitCode;
39
+ constructor(id, command, workingDir) {
40
+ this.id = id;
41
+ this.command = command;
42
+ this.workingDir = workingDir;
43
+ }
44
+ start() {
45
+ this.process = spawn('bash', ['-c', this.command], {
46
+ cwd: this.workingDir,
47
+ stdio: ['ignore', 'pipe', 'pipe'],
48
+ });
49
+ this.isRunning = true;
50
+ this.process.stdout?.on('data', (data) => {
51
+ this.outputBuffer.push(data.toString());
52
+ });
53
+ this.process.stderr?.on('data', (data) => {
54
+ this.errorBuffer.push(data.toString());
55
+ });
56
+ this.process.on('exit', (code) => {
57
+ this.exitCode = code ?? 0;
58
+ this.isRunning = false;
59
+ });
60
+ }
61
+ getNewOutput(filter) {
62
+ const allOutput = this.outputBuffer.join('');
63
+ const newOutput = allOutput.substring(this.lastReadPosition);
64
+ this.lastReadPosition = allOutput.length;
65
+ // stderr is incremental too — track its own read position so a poll returns
66
+ // only NEW error output, not the entire stderr history re-dumped each time.
67
+ const allError = this.errorBuffer.join('');
68
+ const newError = allError.substring(this.lastErrorReadPosition);
69
+ this.lastErrorReadPosition = allError.length;
70
+ let stdout = newOutput;
71
+ let stderr = newError;
72
+ if (filter) {
73
+ stdout = newOutput.split('\n').filter(line => filter.test(line)).join('\n');
74
+ stderr = newError.split('\n').filter(line => filter.test(line)).join('\n');
75
+ }
76
+ return {
77
+ stdout,
78
+ stderr,
79
+ status: this.isRunning ? 'running' : `exited with code ${this.exitCode}`,
80
+ };
81
+ }
82
+ kill() {
83
+ if (this.process) {
84
+ this.process.kill('SIGTERM');
85
+ setTimeout(() => {
86
+ if (this.process && !this.process.killed) {
87
+ this.process.kill('SIGKILL');
88
+ }
89
+ }, 5000);
90
+ }
91
+ }
92
+ }
93
+ class BackgroundShellManager {
94
+ shells = new Map();
95
+ nextId = 1;
96
+ createShell(command, workingDir) {
97
+ const shellId = `shell_${this.nextId++}`;
98
+ const shell = new BackgroundShell(shellId, command, workingDir);
99
+ this.shells.set(shellId, shell);
100
+ shell.start();
101
+ return shellId;
102
+ }
103
+ getShell(shellId) {
104
+ return this.shells.get(shellId);
105
+ }
106
+ killShell(shellId) {
107
+ const shell = this.shells.get(shellId);
108
+ if (shell) {
109
+ shell.kill();
110
+ this.shells.delete(shellId);
111
+ return true;
112
+ }
113
+ return false;
114
+ }
115
+ listShells() {
116
+ return Array.from(this.shells.keys());
117
+ }
118
+ }
119
+ // Global shell manager instance
120
+ const shellManager = new BackgroundShellManager();
121
+ /**
122
+ * Number of currently running background shells. Used by the chat-box footer.
123
+ */
124
+ export function getBackgroundShellCount() {
125
+ return shellManager.listShells().length;
126
+ }
127
+ async function execWithStreaming(command, options) {
128
+ const MAX_BUFFER_BYTES = 1_000_000; // ~1MB per stream to prevent OOM on chatty commands
129
+ return new Promise((resolve, reject) => {
130
+ const stdout = [];
131
+ const stderr = [];
132
+ let stdoutBytes = 0;
133
+ let stderrBytes = 0;
134
+ let stdoutTruncated = false;
135
+ let stderrTruncated = false;
136
+ let lineCount = 0;
137
+ let killed = false;
138
+ let earlyAbort = false;
139
+ let abortReason;
140
+ const child = spawn('bash', ['-c', command], {
141
+ cwd: options.cwd,
142
+ env: options.env,
143
+ stdio: ['ignore', 'pipe', 'pipe'],
144
+ });
145
+ const timeoutId = setTimeout(() => {
146
+ killed = true;
147
+ child.kill('SIGTERM');
148
+ setTimeout(() => child.kill('SIGKILL'), 1000);
149
+ }, options.timeout);
150
+ // Early abort function for test failures
151
+ const triggerEarlyAbort = (reason) => {
152
+ if (earlyAbort)
153
+ return; // Already aborting
154
+ earlyAbort = true;
155
+ abortReason = reason;
156
+ logDebug(`[Bash] Early abort triggered: ${reason}`);
157
+ reportToolProgress({
158
+ current: lineCount,
159
+ message: `⚡ Early abort: ${reason}`,
160
+ });
161
+ child.kill('SIGTERM');
162
+ setTimeout(() => {
163
+ if (!child.killed) {
164
+ child.kill('SIGKILL');
165
+ }
166
+ }, 2000);
167
+ };
168
+ const processLine = (line, isStderr) => {
169
+ lineCount++;
170
+ const trimmedLine = line.slice(0, 80);
171
+ reportToolProgress({
172
+ current: lineCount,
173
+ message: isStderr ? `stderr: ${trimmedLine}` : trimmedLine,
174
+ });
175
+ // Feed line to test monitor for real-time failure detection
176
+ if (options.testMonitor && !earlyAbort) {
177
+ const shouldAbort = options.testMonitor.processLine(line);
178
+ if (shouldAbort) {
179
+ const state = options.testMonitor.getState();
180
+ triggerEarlyAbort(state.abortReason || 'Test failures detected');
181
+ }
182
+ }
183
+ };
184
+ const appendChunk = (chunks, data, isStdout) => {
185
+ const byteLength = data.length;
186
+ const used = isStdout ? stdoutBytes : stderrBytes;
187
+ const available = MAX_BUFFER_BYTES - used;
188
+ if (available <= 0) {
189
+ if (isStdout)
190
+ stdoutTruncated = true;
191
+ else
192
+ stderrTruncated = true;
193
+ return;
194
+ }
195
+ const slice = byteLength > available ? data.subarray(0, available) : data;
196
+ chunks.push(slice.toString());
197
+ const consumed = slice.length; // Buffer length in bytes
198
+ if (isStdout) {
199
+ stdoutBytes += consumed;
200
+ if (byteLength > available)
201
+ stdoutTruncated = true;
202
+ }
203
+ else {
204
+ stderrBytes += consumed;
205
+ if (byteLength > available)
206
+ stderrTruncated = true;
207
+ }
208
+ };
209
+ let stdoutBuffer = '';
210
+ child.stdout?.on('data', (data) => {
211
+ const text = data.toString();
212
+ appendChunk(stdout, data, true);
213
+ stdoutBuffer += text;
214
+ if (stdoutBuffer.length > 4096) {
215
+ stdoutBuffer = stdoutBuffer.slice(-2048);
216
+ }
217
+ const lines = stdoutBuffer.split('\n');
218
+ stdoutBuffer = lines.pop() || '';
219
+ for (const line of lines) {
220
+ if (line.trim())
221
+ processLine(line, false);
222
+ }
223
+ });
224
+ let stderrBuffer = '';
225
+ child.stderr?.on('data', (data) => {
226
+ const text = data.toString();
227
+ appendChunk(stderr, data, false);
228
+ stderrBuffer += text;
229
+ if (stderrBuffer.length > 4096) {
230
+ stderrBuffer = stderrBuffer.slice(-2048);
231
+ }
232
+ const lines = stderrBuffer.split('\n');
233
+ stderrBuffer = lines.pop() || '';
234
+ for (const line of lines) {
235
+ if (line.trim())
236
+ processLine(line, true);
237
+ }
238
+ });
239
+ const buildOutput = (chunks, truncated) => {
240
+ const output = chunks.join('');
241
+ if (!truncated)
242
+ return output;
243
+ const limitKb = Math.round(MAX_BUFFER_BYTES / 1024);
244
+ const notice = `\n[output truncated after ${limitKb}KB to protect memory; rerun with narrower command to see full output]`;
245
+ return output ? `${output}${notice}` : notice.trim();
246
+ };
247
+ child.on('close', (code) => {
248
+ clearTimeout(timeoutId);
249
+ if (stdoutBuffer.trim())
250
+ processLine(stdoutBuffer, false);
251
+ if (stderrBuffer.trim())
252
+ processLine(stderrBuffer, true);
253
+ const stdoutText = buildOutput(stdout, stdoutTruncated);
254
+ const stderrText = buildOutput(stderr, stderrTruncated);
255
+ if (killed && !earlyAbort) {
256
+ reject({ killed: true, stdout: stdoutText, stderr: stderrText, code });
257
+ }
258
+ else {
259
+ const result = {
260
+ stdout: stdoutText,
261
+ stderr: stderrText,
262
+ exitCode: earlyAbort ? 1 : (code ?? 0),
263
+ };
264
+ if (earlyAbort && options.testMonitor) {
265
+ result.earlyAbort = true;
266
+ result.abortReason = abortReason;
267
+ result.abortMessage = options.testMonitor.formatAbortMessage();
268
+ }
269
+ resolve(result);
270
+ }
271
+ });
272
+ child.on('error', (error) => {
273
+ clearTimeout(timeoutId);
274
+ reject(error);
275
+ });
276
+ });
277
+ }
278
+ /**
279
+ * Execute a sudo command with password authentication
280
+ * Uses -S flag to read password from stdin
281
+ */
282
+ async function execSudoWithPassword(command, password, options) {
283
+ const MAX_BUFFER_BYTES = 1_000_000;
284
+ return new Promise((resolve, reject) => {
285
+ const stdout = [];
286
+ const stderr = [];
287
+ let stdoutBytes = 0;
288
+ let stderrBytes = 0;
289
+ let stdoutTruncated = false;
290
+ let stderrTruncated = false;
291
+ let lineCount = 0;
292
+ let killed = false;
293
+ let passwordSent = false;
294
+ // Use sudo -S to read password from stdin, -k to ignore cached credentials
295
+ // This ensures we always use our provided password
296
+ const sudoCommand = command.replace(/^\s*sudo\s+/, 'sudo -S ');
297
+ const child = spawn('bash', ['-c', sudoCommand], {
298
+ cwd: options.cwd,
299
+ env: options.env,
300
+ stdio: ['pipe', 'pipe', 'pipe'], // Connect stdin for password
301
+ });
302
+ const timeoutId = setTimeout(() => {
303
+ killed = true;
304
+ child.kill('SIGTERM');
305
+ setTimeout(() => child.kill('SIGKILL'), 1000);
306
+ }, options.timeout);
307
+ const processLine = (line, isStderr) => {
308
+ // Filter out password prompt from output
309
+ if (line.includes('[sudo] password') || line.includes('Password:')) {
310
+ return;
311
+ }
312
+ lineCount++;
313
+ const trimmedLine = line.slice(0, 80);
314
+ reportToolProgress({
315
+ current: lineCount,
316
+ message: isStderr ? `stderr: ${trimmedLine}` : trimmedLine,
317
+ });
318
+ };
319
+ const appendChunk = (chunks, data, isStdout) => {
320
+ const byteLength = data.length;
321
+ const used = isStdout ? stdoutBytes : stderrBytes;
322
+ const available = MAX_BUFFER_BYTES - used;
323
+ if (available <= 0) {
324
+ if (isStdout)
325
+ stdoutTruncated = true;
326
+ else
327
+ stderrTruncated = true;
328
+ return;
329
+ }
330
+ const slice = byteLength > available ? data.subarray(0, available) : data;
331
+ chunks.push(slice.toString());
332
+ const consumed = slice.length;
333
+ if (isStdout) {
334
+ stdoutBytes += consumed;
335
+ if (byteLength > available)
336
+ stdoutTruncated = true;
337
+ }
338
+ else {
339
+ stderrBytes += consumed;
340
+ if (byteLength > available)
341
+ stderrTruncated = true;
342
+ }
343
+ };
344
+ let stdoutBuffer = '';
345
+ child.stdout?.on('data', (data) => {
346
+ const text = data.toString();
347
+ appendChunk(stdout, data, true);
348
+ stdoutBuffer += text;
349
+ if (stdoutBuffer.length > 4096) {
350
+ stdoutBuffer = stdoutBuffer.slice(-2048);
351
+ }
352
+ const lines = stdoutBuffer.split('\n');
353
+ stdoutBuffer = lines.pop() || '';
354
+ for (const line of lines) {
355
+ if (line.trim())
356
+ processLine(line, false);
357
+ }
358
+ });
359
+ let stderrBuffer = '';
360
+ child.stderr?.on('data', (data) => {
361
+ const text = data.toString();
362
+ // Send password when sudo prompts for it
363
+ if (!passwordSent && (text.includes('[sudo] password') || text.includes('Password:'))) {
364
+ child.stdin?.write(password + '\n');
365
+ child.stdin?.end();
366
+ passwordSent = true;
367
+ reportToolProgress({ current: 0, message: 'Authenticating with sudo…' });
368
+ return; // Don't add password prompt to output
369
+ }
370
+ // Filter password prompt lines from output
371
+ const filteredText = text.split('\n')
372
+ .filter(line => !line.includes('[sudo] password') && !line.includes('Password:'))
373
+ .join('\n');
374
+ if (filteredText) {
375
+ appendChunk(stderr, Buffer.from(filteredText), false);
376
+ stderrBuffer += filteredText;
377
+ if (stderrBuffer.length > 4096) {
378
+ stderrBuffer = stderrBuffer.slice(-2048);
379
+ }
380
+ const lines = stderrBuffer.split('\n');
381
+ stderrBuffer = lines.pop() || '';
382
+ for (const line of lines) {
383
+ if (line.trim())
384
+ processLine(line, true);
385
+ }
386
+ }
387
+ });
388
+ // Send password immediately after spawn for cases where prompt comes fast
389
+ setTimeout(() => {
390
+ if (!passwordSent && child.stdin?.writable) {
391
+ child.stdin?.write(password + '\n');
392
+ child.stdin?.end();
393
+ passwordSent = true;
394
+ }
395
+ }, 100);
396
+ const buildOutput = (chunks, truncated) => {
397
+ const output = chunks.join('');
398
+ // Filter out any remaining password-related lines
399
+ const filtered = output.split('\n')
400
+ .filter(line => !line.includes('[sudo] password') && !line.includes('Password:') && !line.includes('Sorry, try again'))
401
+ .join('\n');
402
+ if (!truncated)
403
+ return filtered;
404
+ const limitKb = Math.round(MAX_BUFFER_BYTES / 1024);
405
+ const notice = `\n[output truncated after ${limitKb}KB to protect memory]`;
406
+ return filtered ? `${filtered}${notice}` : notice.trim();
407
+ };
408
+ child.on('close', (code) => {
409
+ clearTimeout(timeoutId);
410
+ if (stdoutBuffer.trim())
411
+ processLine(stdoutBuffer, false);
412
+ if (stderrBuffer.trim())
413
+ processLine(stderrBuffer, true);
414
+ const stdoutText = buildOutput(stdout, stdoutTruncated);
415
+ const stderrText = buildOutput(stderr, stderrTruncated);
416
+ // Check for authentication failure
417
+ const combinedOutput = stdoutText + stderrText;
418
+ if (combinedOutput.includes('Sorry, try again') ||
419
+ combinedOutput.includes('incorrect password') ||
420
+ combinedOutput.includes('Authentication failure') ||
421
+ (code !== 0 && combinedOutput.includes('sudo:'))) {
422
+ // Invalid password - invalidate cache
423
+ invalidateSudoPassword();
424
+ }
425
+ if (killed) {
426
+ reject({ killed: true, stdout: stdoutText, stderr: stderrText, code });
427
+ }
428
+ else {
429
+ resolve({
430
+ stdout: stdoutText,
431
+ stderr: stderrText,
432
+ exitCode: code ?? 0,
433
+ });
434
+ }
435
+ });
436
+ child.on('error', (error) => {
437
+ clearTimeout(timeoutId);
438
+ reject(error);
439
+ });
440
+ });
441
+ }
442
+ // ============================================================================
443
+ // Utility Functions
444
+ // ============================================================================
445
+ // Keep the shell responsive while long commands run
446
+ function findGuiLauncher(_command) {
447
+ return null;
448
+ }
449
+ const errorFixerCache = new Map();
450
+ function getErrorFixer(workingDir) {
451
+ let fixer = errorFixerCache.get(workingDir);
452
+ if (!fixer) {
453
+ fixer = createErrorFixer({ workingDir });
454
+ errorFixerCache.set(workingDir, fixer);
455
+ }
456
+ return fixer;
457
+ }
458
+ /**
459
+ * Smart timeout detection based on command type
460
+ */
461
+ function getSmartTimeout(command) {
462
+ const cmd = command.toLowerCase().trim();
463
+ // Long-running commands that legitimately take time
464
+ if (cmd.includes('npm install') || cmd.includes('yarn install') || cmd.includes('pnpm install')) {
465
+ return 10 * 60 * 1000; // 10 minutes for package installs
466
+ }
467
+ if (cmd.includes('npm run build') || cmd.includes('yarn build') || cmd.includes('make')) {
468
+ return 10 * 60 * 1000; // 10 minutes for builds
469
+ }
470
+ if (cmd.includes('docker build') || cmd.includes('docker-compose')) {
471
+ return 15 * 60 * 1000; // 15 minutes for docker builds
472
+ }
473
+ if (cmd.includes('npm test') || cmd.includes('yarn test') || cmd.includes('pytest') || cmd.includes('jest')) {
474
+ return 10 * 60 * 1000; // 10 minutes for tests
475
+ }
476
+ if (cmd.includes('git clone') || cmd.includes('git fetch') || cmd.includes('git pull')) {
477
+ return 5 * 60 * 1000; // 5 minutes for git network ops
478
+ }
479
+ // Default timeout for most commands - prevents hung commands from blocking
480
+ return 2 * 60 * 1000; // 2 minutes default
481
+ }
482
+ const sandboxCache = new Map();
483
+ async function ensureSandboxPaths(workingDir) {
484
+ let pending = sandboxCache.get(workingDir);
485
+ if (!pending) {
486
+ pending = createSandboxPaths(workingDir);
487
+ sandboxCache.set(workingDir, pending);
488
+ }
489
+ return pending;
490
+ }
491
+ async function createSandboxPaths(workingDir) {
492
+ const root = join(workingDir, '.trenchwork', 'shell-sandbox');
493
+ const home = join(root, 'home');
494
+ const cache = join(root, 'cache');
495
+ const config = join(root, 'config');
496
+ const data = join(root, 'data');
497
+ const tmp = join(root, 'tmp');
498
+ await Promise.all([home, cache, config, data, tmp].map((dir) => mkdir(dir, { recursive: true })));
499
+ return { root, home, cache, config, data, tmp };
500
+ }
501
+ /**
502
+ * Detect if a command needs access to the real home directory for cloud CLI credentials.
503
+ * Commands like firebase, gcloud, aws, az, kubectl require access to stored credentials.
504
+ */
505
+ function needsRealHome(command) {
506
+ const cloudCliPatterns = [
507
+ /\bfirebase\b/i, // Firebase CLI
508
+ /\bgcloud\b/i, // Google Cloud CLI
509
+ /\bgsutil\b/i, // Google Cloud Storage
510
+ /\baws\b/i, // AWS CLI
511
+ /\baz\b/i, // Azure CLI
512
+ /\bkubectl\b/i, // Kubernetes
513
+ /\bhelm\b/i, // Helm
514
+ /\bdocker\b/i, // Docker (for registry auth)
515
+ /\bnpm\s+publish\b/i, // npm publish (needs npm auth)
516
+ /\byarn\s+publish\b/i, // yarn publish
517
+ /\bpnpm\s+publish\b/i, // pnpm publish
518
+ /\bgh\b/i, // GitHub CLI
519
+ /\bvercel\b/i, // Vercel CLI
520
+ /\bnetlify\b/i, // Netlify CLI
521
+ /\bheroku\b/i, // Heroku CLI
522
+ /\bfly\b/i, // Fly.io CLI
523
+ /\bsupabase\b/i, // Supabase CLI
524
+ /\bwrangler\b/i, // Cloudflare Workers
525
+ ];
526
+ return cloudCliPatterns.some(pattern => pattern.test(command));
527
+ }
528
+ export async function buildSandboxEnv(workingDir, options) {
529
+ const envPreference = process.env['TRENCHWORK_PRESERVE_HOME'];
530
+ // Preserve home if: env var set, option passed, or command needs cloud CLI credentials
531
+ const commandNeedsHome = options?.command ? needsRealHome(options.command) : false;
532
+ const preserveHome = envPreference === '1' ? true :
533
+ envPreference === '0' ? false :
534
+ Boolean(options?.preserveHome) || commandNeedsHome;
535
+ const paths = await ensureSandboxPaths(workingDir);
536
+ const env = {
537
+ ...process.env,
538
+ TRENCHWORK_SANDBOX_ROOT: paths.root,
539
+ TRENCHWORK_SANDBOX_HOME: paths.home,
540
+ TRENCHWORK_SANDBOX_TMP: paths.tmp,
541
+ };
542
+ if (!preserveHome) {
543
+ env['HOME'] = paths.home;
544
+ env['XDG_CACHE_HOME'] = paths.cache;
545
+ env['XDG_CONFIG_HOME'] = paths.config;
546
+ env['XDG_DATA_HOME'] = paths.data;
547
+ }
548
+ // Always sandbox temp directories for safety
549
+ env['TMPDIR'] = paths.tmp;
550
+ env['TMP'] = paths.tmp;
551
+ env['TEMP'] = paths.tmp;
552
+ return env;
553
+ }
554
+ // ============================================================================
555
+ // Main Tool Factory
556
+ // ============================================================================
557
+ export function createBashTools(workingDir) {
558
+ return [
559
+ // Main bash execution tool
560
+ {
561
+ name: 'execute_bash',
562
+ description: 'Execute a bash command. Commands auto-timeout based on type. Use run_in_background: true for servers/watchers.',
563
+ parameters: {
564
+ type: 'object',
565
+ properties: {
566
+ command: { type: 'string', description: 'The bash command to execute' },
567
+ timeout: { type: 'number', description: 'Timeout in milliseconds (smart defaults apply)' },
568
+ run_in_background: { type: 'boolean', description: 'Run in background for long-running processes' },
569
+ },
570
+ required: ['command'],
571
+ },
572
+ handler: async (args) => {
573
+ const command = args['command'];
574
+ const runInBackground = args['run_in_background'] === true;
575
+ const userTimeout = args['timeout'];
576
+ const timeout = userTimeout ?? getSmartTimeout(command);
577
+ // Check if this is a sudo command
578
+ const isSudoCommand = /^\s*sudo\s+/i.test(command);
579
+ // Block commands that typically require passwords or interactive input (except sudo which we handle)
580
+ const interactiveCommands = /\b(passwd|su\s|login|ssh\s(?!-o)|sftp|ftp|mysql\s+-p|psql\s+-W)\b/i;
581
+ if (interactiveCommands.test(command)) {
582
+ return 'Skipped: Command requires interactive authentication. Use non-interactive alternatives.';
583
+ }
584
+ // Flow guidance (debug only - don't pollute chat)
585
+ const flowWarnings = analyzeBashFlow(command);
586
+ for (const warning of flowWarnings) {
587
+ const suffix = warning.suggestion ? ` — ${warning.suggestion}` : '';
588
+ logDebug(`[Bash Flow] ${warning.message}${suffix}`);
589
+ }
590
+ // Safety validation (informational only)
591
+ const validation = validateBashCommand(command);
592
+ if (!validation.valid) {
593
+ logDebug(`[Bash Safety] Command validation failed: ${validation.error?.message || 'Unknown error'}`);
594
+ }
595
+ // Safety warnings (debug only - don't pollute chat)
596
+ if (validation.warnings.length > 0) {
597
+ for (const warning of validation.warnings) {
598
+ logDebug(`[Bash Safety] WARNING: ${warning}`);
599
+ }
600
+ }
601
+ // GUI blocking check
602
+ const guiBlocked = findGuiLauncher(command);
603
+ if (guiBlocked) {
604
+ logDebug(`[Bash Safety] GUI launcher detected: ${guiBlocked}`);
605
+ }
606
+ // Background execution
607
+ if (runInBackground) {
608
+ const shellId = shellManager.createShell(command, workingDir);
609
+ return `Background shell started: ${shellId}\n\nUse BashOutput with bash_id="${shellId}" to monitor.\nUse KillShell with shell_id="${shellId}" to terminate.`;
610
+ }
611
+ // Foreground execution
612
+ const startTime = Date.now();
613
+ const usesRealHome = needsRealHome(command);
614
+ // Create test monitor for test commands to enable early abort on failures
615
+ const testMonitor = createTestMonitor(command);
616
+ if (testMonitor) {
617
+ logDebug(`[Bash] Test command detected, enabling failure monitoring with early abort`);
618
+ }
619
+ try {
620
+ const env = await buildSandboxEnv(workingDir, { command });
621
+ // Report sandbox status for visibility
622
+ const sandboxStatus = usesRealHome
623
+ ? `${ANSI_CYAN}🔓 Using real credentials (cloud CLI detected)${ANSI_RESET}`
624
+ : `${ANSI_DIM}🔒 Sandboxed environment${ANSI_RESET}`;
625
+ reportToolProgress({ current: 0, message: sandboxStatus });
626
+ let result;
627
+ // Handle sudo commands with password authentication
628
+ if (isSudoCommand) {
629
+ logDebug('[Bash] Sudo command detected, requesting password');
630
+ reportToolProgress({ current: 0, message: 'Sudo command detected, requesting password…' });
631
+ const password = await getSudoPassword();
632
+ if (!password) {
633
+ return `${ANSI_YELLOW}Sudo command cancelled: No password provided.${ANSI_RESET}\n\nTo run this command, you need to provide your sudo password when prompted.`;
634
+ }
635
+ result = await execSudoWithPassword(command, password, { cwd: workingDir, timeout, env, testMonitor });
636
+ }
637
+ else {
638
+ result = await execWithStreaming(command, { cwd: workingDir, timeout, env, testMonitor });
639
+ }
640
+ const { stdout, stderr, exitCode, earlyAbort, abortMessage } = result;
641
+ const durationMs = Date.now() - startTime;
642
+ const combinedOutput = [stdout, stderr].filter(Boolean).join('\n');
643
+ // Handle early abort from test monitor - encourage replanning
644
+ if (earlyAbort && testMonitor) {
645
+ const state = testMonitor.getState();
646
+ const suggestions = [
647
+ 'REPLAN: Fix the identified issues before running tests again',
648
+ ...state.suggestions,
649
+ ];
650
+ return verifiedFailure(`${ANSI_YELLOW_BOLD}Test run aborted early - replan recommended${ANSI_RESET}`, `Command: ${command}\n\n${ANSI_YELLOW}The test run was stopped early to save time.${ANSI_RESET}\n\n` +
651
+ `${abortMessage || ''}\n\n` +
652
+ `${ANSI_DIM}Partial output:${ANSI_RESET}\n${combinedOutput || '(none)'}`, suggestions, [
653
+ { check: 'Early abort', passed: false, details: state.abortReason || 'Multiple test failures' },
654
+ { check: 'Failed tests', passed: false, details: `${state.failedTests.length} test file(s) failed` },
655
+ ], durationMs);
656
+ }
657
+ const commandLower = command.toLowerCase().trim();
658
+ let patterns = OutputPatterns.command;
659
+ if (commandLower.startsWith('git ') || commandLower === 'git')
660
+ patterns = OutputPatterns.git;
661
+ else if (commandLower.startsWith('npm ') || commandLower.startsWith('npx '))
662
+ patterns = OutputPatterns.npm;
663
+ const analysis = analyzeOutput(combinedOutput, patterns, exitCode);
664
+ const commandCheck = createCommandCheck('Command execution', exitCode, combinedOutput);
665
+ if (exitCode !== 0) {
666
+ const errorFixer = getErrorFixer(workingDir);
667
+ const aiErrors = errorFixer.analyzeOutput(combinedOutput, command);
668
+ const aiGuidance = aiErrors.length > 0 ? errorFixer.formatForAI(aiErrors) : '';
669
+ const suggestions = ['Review the error message', 'Fix the issue and retry'];
670
+ const firstError = aiErrors[0];
671
+ if (firstError?.suggestedFixes[0]) {
672
+ suggestions.unshift(`AI Suggestion: ${firstError.suggestedFixes[0].description}`);
673
+ }
674
+ // Add replan suggestion for test failures
675
+ if (testMonitor && testMonitor.getState().failedTests.length > 0) {
676
+ suggestions.unshift('REPLAN: Multiple test failures detected - consider fixing incrementally');
677
+ }
678
+ return verifiedFailure(`Command failed with exit code ${exitCode}`, `Command: ${command}\n\nOutput:\n${combinedOutput || '(none)'}${aiGuidance}`, suggestions, [commandCheck], durationMs);
679
+ }
680
+ if (analysis.isFailure) {
681
+ return verifiedFailure(`Command completed with exit code 0 but output indicates failure`, `Command: ${command}\n\n${ANSI_RED_BOLD}Output:${ANSI_RESET}\n${combinedOutput || '(no output)'}`, ['Review the error message in the output', 'Fix the underlying issue and retry'], [commandCheck, { check: 'Output analysis', passed: false, details: `Failure pattern: ${analysis.matchedPattern}` }], durationMs);
682
+ }
683
+ const envLabel = usesRealHome ? `${ANSI_CYAN}[real credentials]${ANSI_RESET}` : `${ANSI_DIM}[sandboxed]${ANSI_RESET}`;
684
+ return verifiedSuccess(combinedOutput.trim() ? `Command executed successfully ${envLabel}` : `Command executed successfully (no output) ${envLabel}`, `Command: ${command}${combinedOutput.trim() ? `\n\n${ANSI_GREEN_BOLD}Output:${ANSI_RESET}\n${combinedOutput}` : ''}`, [commandCheck, ...(analysis.isSuccess ? [{ check: 'Output analysis', passed: true, details: `Success pattern matched` }] : [])], durationMs);
685
+ }
686
+ catch (error) {
687
+ const execError = error;
688
+ const durationMs = Date.now() - startTime;
689
+ const exitCode = execError.code ?? 1;
690
+ const combinedError = [execError.stdout, execError.stderr, execError.message].filter(Boolean).join('\n');
691
+ if (execError.killed) {
692
+ return verifiedFailure(`Command timed out after ${timeout}ms`, `Command: ${command}\n\nPartial output:\n${combinedError || '(none)'}`, ['Increase timeout if command legitimately needs more time', 'Check if command is hanging'], [{ check: 'Timeout', passed: false, details: `Exceeded ${timeout}ms` }], durationMs);
693
+ }
694
+ const errorFixer = getErrorFixer(workingDir);
695
+ const aiErrors = errorFixer.analyzeOutput(combinedError, command);
696
+ const aiGuidance = aiErrors.length > 0 ? errorFixer.formatForAI(aiErrors) : '';
697
+ const suggestions = ['Review the error message', 'Fix the issue and retry'];
698
+ const firstError = aiErrors[0];
699
+ if (firstError?.suggestedFixes[0]) {
700
+ suggestions.unshift(`AI Suggestion: ${firstError.suggestedFixes[0].description}`);
701
+ }
702
+ return verifiedFailure(`Command failed with exit code ${exitCode}`, `Command: ${command}\n\nError output:\n${combinedError || '(none)'}${aiGuidance}`, suggestions, [createCommandCheck('Command execution', exitCode, combinedError)], durationMs);
703
+ }
704
+ },
705
+ },
706
+ // Background shell output retrieval
707
+ {
708
+ name: 'BashOutput',
709
+ description: 'Retrieve output from a running or completed background bash shell.',
710
+ parameters: {
711
+ type: 'object',
712
+ properties: {
713
+ bash_id: { type: 'string', description: 'The ID of the background shell' },
714
+ filter: { type: 'string', description: 'Optional regex to filter output lines' },
715
+ },
716
+ required: ['bash_id'],
717
+ additionalProperties: false,
718
+ },
719
+ handler: async (args) => {
720
+ const bashId = args['bash_id'];
721
+ const filterStr = args['filter'];
722
+ if (typeof bashId !== 'string' || !bashId.trim()) {
723
+ return 'Error: bash_id must be a non-empty string.';
724
+ }
725
+ try {
726
+ const shell = shellManager.getShell(bashId);
727
+ if (!shell) {
728
+ const available = shellManager.listShells();
729
+ return `Error: Shell "${bashId}" not found.\n\nAvailable: ${available.length > 0 ? available.join(', ') : 'none'}`;
730
+ }
731
+ const filter = filterStr && typeof filterStr === 'string' ? new RegExp(filterStr) : undefined;
732
+ const { stdout, stderr, status } = shell.getNewOutput(filter);
733
+ const parts = [`Shell: ${bashId}`, `Status: ${status}`];
734
+ if (stdout) {
735
+ parts.push('\n=== New Output ===');
736
+ parts.push(stdout);
737
+ }
738
+ if (stderr) {
739
+ parts.push('\n=== Errors ===');
740
+ parts.push(stderr);
741
+ }
742
+ if (!stdout && !stderr)
743
+ parts.push('\n(No new output)');
744
+ return parts.join('\n');
745
+ }
746
+ catch (error) {
747
+ return buildError('retrieving shell output', error, { bash_id: bashId });
748
+ }
749
+ },
750
+ },
751
+ // Kill background shell
752
+ {
753
+ name: 'KillShell',
754
+ description: 'Kill a running background bash shell by its ID.',
755
+ parameters: {
756
+ type: 'object',
757
+ properties: {
758
+ shell_id: { type: 'string', description: 'The ID of the background shell to kill' },
759
+ },
760
+ required: ['shell_id'],
761
+ additionalProperties: false,
762
+ },
763
+ handler: async (args) => {
764
+ const shellId = args['shell_id'];
765
+ if (typeof shellId !== 'string' || !shellId.trim()) {
766
+ return 'Error: shell_id must be a non-empty string.';
767
+ }
768
+ try {
769
+ const success = shellManager.killShell(shellId);
770
+ if (success) {
771
+ return `Shell "${shellId}" has been terminated.`;
772
+ }
773
+ else {
774
+ const available = shellManager.listShells();
775
+ return `Error: Shell "${shellId}" not found.\n\nAvailable: ${available.length > 0 ? available.join(', ') : 'none'}`;
776
+ }
777
+ }
778
+ catch (error) {
779
+ return buildError('killing shell', error, { shell_id: shellId });
780
+ }
781
+ },
782
+ },
783
+ ];
784
+ }
785
+ //# sourceMappingURL=bashTools.js.map