newcraw 1.0.2 → 1.0.4

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 (220) hide show
  1. package/dist/REPL-DECTPCL5.js +50 -0
  2. package/dist/{acp-J4WDYGRX.js → acp-HA476EHW.js} +69 -40
  3. package/dist/acp-HA476EHW.js.map +7 -0
  4. package/dist/{agentsValidate-UBOER2IN.js → agentsValidate-EDPFUUMG.js} +13 -10
  5. package/dist/{agentsValidate-UBOER2IN.js.map → agentsValidate-EDPFUUMG.js.map} +1 -1
  6. package/dist/{ask-MGUO3L35.js → ask-5SP4YYRD.js} +62 -52
  7. package/dist/ask-5SP4YYRD.js.map +7 -0
  8. package/dist/{autoUpdater-2GS6LRPK.js → autoUpdater-FFMM2DR7.js} +5 -4
  9. package/dist/chunk-2BVCVKKB.js +135 -0
  10. package/dist/chunk-2BVCVKKB.js.map +7 -0
  11. package/dist/{chunk-2C43OXE7.js → chunk-2JCTO2EY.js} +38 -59
  12. package/dist/chunk-2JCTO2EY.js.map +7 -0
  13. package/dist/{chunk-OJIMOLIC.js → chunk-3CKC4ABU.js} +3631 -7464
  14. package/dist/chunk-3CKC4ABU.js.map +7 -0
  15. package/dist/chunk-ARCEUG3V.js +88 -0
  16. package/dist/chunk-ARCEUG3V.js.map +7 -0
  17. package/dist/{chunk-RUXIBQ3B.js → chunk-BJYXLCRS.js} +4 -4
  18. package/dist/{chunk-VKI7ORIO.js → chunk-BMKE6FT5.js} +37 -18
  19. package/dist/{chunk-VKI7ORIO.js.map → chunk-BMKE6FT5.js.map} +1 -1
  20. package/dist/chunk-BQCOSNM3.js +93 -0
  21. package/dist/chunk-BQCOSNM3.js.map +7 -0
  22. package/dist/chunk-CHB5K4GI.js +107 -0
  23. package/dist/chunk-CHB5K4GI.js.map +7 -0
  24. package/dist/chunk-D4OZACS2.js +35 -0
  25. package/dist/chunk-EHQ2M5B4.js +166 -0
  26. package/dist/{chunk-ZYSVG4X3.js.map → chunk-EHQ2M5B4.js.map} +2 -2
  27. package/dist/chunk-EUBZGAIN.js +372 -0
  28. package/dist/chunk-EUBZGAIN.js.map +7 -0
  29. package/dist/{chunk-UYRR6F5S.js → chunk-FIMCETCB.js} +9 -3
  30. package/dist/{chunk-UYRR6F5S.js.map → chunk-FIMCETCB.js.map} +1 -1
  31. package/dist/{chunk-DEF3KFP7.js → chunk-GVLJUD6R.js} +4 -2
  32. package/dist/{chunk-DEF3KFP7.js.map → chunk-GVLJUD6R.js.map} +1 -1
  33. package/dist/chunk-HLBLZKZH.js +45 -0
  34. package/dist/chunk-HLBLZKZH.js.map +7 -0
  35. package/dist/{chunk-XS6PU75S.js → chunk-IVWPPTDM.js} +1 -1
  36. package/dist/{chunk-A7X6OCZE.js → chunk-IXFBUXQW.js} +1 -1
  37. package/dist/{chunk-HSJ6HYAO.js → chunk-IZZTKEZH.js} +18 -10
  38. package/dist/chunk-IZZTKEZH.js.map +7 -0
  39. package/dist/{chunk-2EFL22PV.js → chunk-JI4HCLK7.js} +7 -3
  40. package/dist/chunk-JI4HCLK7.js.map +7 -0
  41. package/dist/chunk-JLVECHVJ.js +36 -0
  42. package/dist/chunk-JLVECHVJ.js.map +7 -0
  43. package/dist/{chunk-XXU2NVOE.js → chunk-KJTPUTU7.js} +30 -6
  44. package/dist/chunk-KJTPUTU7.js.map +7 -0
  45. package/dist/{chunk-V5U6BHT2.js → chunk-KS646CDL.js} +7 -3
  46. package/dist/{chunk-V5U6BHT2.js.map → chunk-KS646CDL.js.map} +1 -1
  47. package/dist/{chunk-53A4JHFW.js → chunk-MJ3MLGVB.js} +23 -4
  48. package/dist/chunk-MJ3MLGVB.js.map +7 -0
  49. package/dist/chunk-MJLWBVZP.js +822 -0
  50. package/dist/chunk-MJLWBVZP.js.map +7 -0
  51. package/dist/chunk-MMF5RMLU.js +65 -0
  52. package/dist/chunk-MMF5RMLU.js.map +7 -0
  53. package/dist/{chunk-QH2M65BR.js → chunk-MUW3J7CP.js} +7 -3
  54. package/dist/{chunk-QH2M65BR.js.map → chunk-MUW3J7CP.js.map} +1 -1
  55. package/dist/{chunk-3LMXSKZ7.js → chunk-NFXLN6FJ.js} +1 -1
  56. package/dist/chunk-NT7RDVDA.js +33 -0
  57. package/dist/{chunk-KQSHIOZK.js.map → chunk-NT7RDVDA.js.map} +1 -1
  58. package/dist/{chunk-OZHBEG7U.js → chunk-O4EKE3YR.js} +15 -5
  59. package/dist/{chunk-OZHBEG7U.js.map → chunk-O4EKE3YR.js.map} +1 -1
  60. package/dist/chunk-Q2OBTLBI.js +5473 -0
  61. package/dist/chunk-Q2OBTLBI.js.map +7 -0
  62. package/dist/{chunk-WWDVA4NV.js → chunk-QJ7MQIHN.js} +22 -6
  63. package/dist/{chunk-WWDVA4NV.js.map → chunk-QJ7MQIHN.js.map} +1 -1
  64. package/dist/{chunk-N5OHRWG2.js → chunk-QSRXXZO7.js} +4 -2
  65. package/dist/{chunk-N5OHRWG2.js.map → chunk-QSRXXZO7.js.map} +1 -1
  66. package/dist/{chunk-GZTCXXSS.js → chunk-QT5GS374.js} +57 -46
  67. package/dist/{chunk-GZTCXXSS.js.map → chunk-QT5GS374.js.map} +1 -1
  68. package/dist/chunk-QX5Y5CE5.js +683 -0
  69. package/dist/{chunk-F3COCCAE.js.map → chunk-QX5Y5CE5.js.map} +1 -1
  70. package/dist/{chunk-IIFUDVGS.js → chunk-U6IF5D3J.js} +310 -177
  71. package/dist/chunk-U6IF5D3J.js.map +7 -0
  72. package/dist/{chunk-VQSCECTS.js → chunk-UPRKGNBR.js} +6 -4
  73. package/dist/{chunk-VQSCECTS.js.map → chunk-UPRKGNBR.js.map} +1 -1
  74. package/dist/chunk-UUCRNFMH.js +62 -0
  75. package/dist/chunk-UUCRNFMH.js.map +7 -0
  76. package/dist/chunk-UYWZQVH5.js +35 -0
  77. package/dist/chunk-UYWZQVH5.js.map +7 -0
  78. package/dist/{chunk-XMGUQHMF.js → chunk-VSSVN6WG.js} +11 -1
  79. package/dist/chunk-VSSVN6WG.js.map +7 -0
  80. package/dist/{chunk-VHS2MZQS.js → chunk-W7Q3VYAB.js} +9 -6
  81. package/dist/{chunk-VHS2MZQS.js.map → chunk-W7Q3VYAB.js.map} +1 -1
  82. package/dist/{chunk-JWXQNBBA.js → chunk-WAXMRSVR.js} +7 -1
  83. package/dist/{chunk-JWXQNBBA.js.map → chunk-WAXMRSVR.js.map} +1 -1
  84. package/dist/{chunk-BWYKUDJR.js → chunk-X3NER6FY.js} +14 -8
  85. package/dist/{chunk-BWYKUDJR.js.map → chunk-X3NER6FY.js.map} +1 -1
  86. package/dist/{chunk-IM33F5CM.js → chunk-XYQZLDRB.js} +1668 -1623
  87. package/dist/chunk-XYQZLDRB.js.map +7 -0
  88. package/dist/{chunk-LOIZNQOU.js → chunk-ZM5FMRLS.js} +9 -3
  89. package/dist/{chunk-LOIZNQOU.js.map → chunk-ZM5FMRLS.js.map} +1 -1
  90. package/dist/{chunk-755HIAI3.js → chunk-ZMO4E7IW.js} +3 -42
  91. package/dist/chunk-ZMO4E7IW.js.map +7 -0
  92. package/dist/{cli-KZGF3FV5.js → cli-4KO6TA5J.js} +251 -485
  93. package/dist/cli-4KO6TA5J.js.map +7 -0
  94. package/dist/commands-JSY7CGSU.js +54 -0
  95. package/dist/{config-GTJWCNPF.js → config-DQEFVW3Y.js} +9 -6
  96. package/dist/{context-WF3TTXQU.js → context-HVQCTO5R.js} +8 -7
  97. package/dist/{costTracker-2G3ZI2JF.js → costTracker-VSWW7SRT.js} +3 -2
  98. package/dist/{customCommands-QOWK57EX.js → customCommands-XCINU5TG.js} +6 -5
  99. package/dist/{env-37BAP7QF.js → env-ZOPEXWMF.js} +10 -7
  100. package/dist/{gateway-IZYO6YFJ.js → gateway-SUXSILQL.js} +542 -96
  101. package/dist/gateway-SUXSILQL.js.map +7 -0
  102. package/dist/identity-3KZQQVBG.js +16 -0
  103. package/dist/index.js +8 -6
  104. package/dist/index.js.map +1 -1
  105. package/dist/{kodeAgentSessionId-KTGFX2BE.js → kodeAgentSessionId-4SH24DVH.js} +1 -1
  106. package/dist/{kodeAgentSessionLoad-6F7SJXBC.js → kodeAgentSessionLoad-HB3BYVNG.js} +6 -5
  107. package/dist/{kodeAgentSessionResume-UEEDRJ3N.js → kodeAgentSessionResume-IGSZZY3G.js} +6 -5
  108. package/dist/{kodeAgentStreamJson-VIXFTYL5.js → kodeAgentStreamJson-4ZKIWKS3.js} +4 -2
  109. package/dist/{kodeAgentStreamJsonSession-XC3IPREZ.js → kodeAgentStreamJsonSession-4L76UC75.js} +15 -4
  110. package/dist/kodeAgentStreamJsonSession-4L76UC75.js.map +7 -0
  111. package/dist/{kodeAgentStructuredStdio-SI5C7AAD.js → kodeAgentStructuredStdio-5DCUC6V6.js} +3 -3
  112. package/dist/{kodeHooks-V36SHCTC.js → kodeHooks-H6DMC3XX.js} +6 -5
  113. package/dist/{llm-CYUDKJNR.js → llm-OJZ6DZVC.js} +306 -60
  114. package/dist/llm-OJZ6DZVC.js.map +7 -0
  115. package/dist/{llmLazy-IXVVBRTN.js → llmLazy-TDLZZDPL.js} +2 -2
  116. package/dist/{loader-OEJ6C3TN.js → loader-MOVYZ76M.js} +6 -5
  117. package/dist/{mcp-KE3SILMX.js → mcp-DUYSIR5L.js} +10 -9
  118. package/dist/{mentionProcessor-GAU2WAYB.js → mentionProcessor-EKVLXJN4.js} +14 -7
  119. package/dist/{mentionProcessor-GAU2WAYB.js.map → mentionProcessor-EKVLXJN4.js.map} +1 -1
  120. package/dist/{messages-WCSGGSEU.js → messages-23ICFVMC.js} +2 -2
  121. package/dist/{model-4TQIV5J2.js → model-FUBCTRTV.js} +10 -7
  122. package/dist/{openai-KTZV6F7N.js → openai-SMYIAIO4.js} +8 -7
  123. package/dist/{outputStyles-WX5RYQOA.js → outputStyles-HBOYJFBE.js} +6 -5
  124. package/dist/{pluginRuntime-JXMJZ2LC.js → pluginRuntime-ATZMDZA7.js} +11 -8
  125. package/dist/{pluginRuntime-JXMJZ2LC.js.map → pluginRuntime-ATZMDZA7.js.map} +1 -1
  126. package/dist/{pluginValidation-JNQZYLUP.js → pluginValidation-7CGOMT6F.js} +8 -7
  127. package/dist/prompts-MFESKNYZ.js +58 -0
  128. package/dist/query-BFEFOX4S.js +58 -0
  129. package/dist/{responsesStreaming-2AIT6GHG.js → responsesStreaming-JORGEFQC.js} +1 -1
  130. package/dist/{ripgrep-KDPQAMB2.js → ripgrep-KNJBCJIQ.js} +5 -4
  131. package/dist/sandbox-P3FR4G4D.js +63 -0
  132. package/dist/{skillMarketplace-IXAGP3Q2.js → skillMarketplace-PCMKVV4O.js} +5 -4
  133. package/dist/{state-MSCYLB6Y.js → state-XBYIQ7R4.js} +6 -3
  134. package/dist/structuredOutput-KAVFUV2Z.js +9 -0
  135. package/dist/theme-4ZSXUILR.js +15 -0
  136. package/dist/thinking-TTNUZUB3.js +18 -0
  137. package/dist/{toolPermissionContext-I3IXPVED.js → toolPermissionContext-JCQ5MFUT.js} +1 -1
  138. package/dist/toolPermissionContext-JCQ5MFUT.js.map +7 -0
  139. package/dist/toolPermissionContextState-R6ZGMKP6.js +24 -0
  140. package/dist/toolPermissionContextState-R6ZGMKP6.js.map +7 -0
  141. package/dist/{toolPermissionSettings-EUZKGZU2.js → toolPermissionSettings-GMEYTJEA.js} +9 -8
  142. package/dist/toolPermissionSettings-GMEYTJEA.js.map +7 -0
  143. package/dist/tools-7FVKB7BG.js +55 -0
  144. package/dist/tools-7FVKB7BG.js.map +7 -0
  145. package/dist/{userInput-LJL4CVOB.js → userInput-SZEUY5J6.js} +49 -34
  146. package/dist/{userInput-LJL4CVOB.js.map → userInput-SZEUY5J6.js.map} +1 -1
  147. package/dist/{uuid-VA3KVASX.js → uuid-RQH3OZ3W.js} +1 -1
  148. package/dist/uuid-RQH3OZ3W.js.map +7 -0
  149. package/dist/workspace-EP63OB5S.js +21 -0
  150. package/dist/workspace-EP63OB5S.js.map +7 -0
  151. package/package.json +2 -2
  152. package/web/dist/assets/index-XuLVvSQF.js +251 -0
  153. package/web/dist/assets/index-pSid9IlY.css +10 -0
  154. package/web/dist/index.html +2 -2
  155. package/dist/REPL-IAK7ZN2Z.js +0 -42
  156. package/dist/acp-J4WDYGRX.js.map +0 -7
  157. package/dist/ask-MGUO3L35.js.map +0 -7
  158. package/dist/chunk-2C43OXE7.js.map +0 -7
  159. package/dist/chunk-2EFL22PV.js.map +0 -7
  160. package/dist/chunk-53A4JHFW.js.map +0 -7
  161. package/dist/chunk-755HIAI3.js.map +0 -7
  162. package/dist/chunk-AXWJI6N5.js +0 -11
  163. package/dist/chunk-F3COCCAE.js +0 -654
  164. package/dist/chunk-HSJ6HYAO.js.map +0 -7
  165. package/dist/chunk-IIFUDVGS.js.map +0 -7
  166. package/dist/chunk-IM33F5CM.js.map +0 -7
  167. package/dist/chunk-KQSHIOZK.js +0 -24
  168. package/dist/chunk-OJIMOLIC.js.map +0 -7
  169. package/dist/chunk-XMGUQHMF.js.map +0 -7
  170. package/dist/chunk-XXU2NVOE.js.map +0 -7
  171. package/dist/chunk-ZYSVG4X3.js +0 -151
  172. package/dist/cli-KZGF3FV5.js.map +0 -7
  173. package/dist/commands-AVEBLFVS.js +0 -46
  174. package/dist/gateway-IZYO6YFJ.js.map +0 -7
  175. package/dist/kodeAgentStreamJsonSession-XC3IPREZ.js.map +0 -7
  176. package/dist/llm-CYUDKJNR.js.map +0 -7
  177. package/dist/prompts-LE6GK75N.js +0 -48
  178. package/dist/query-GGIP6PWG.js +0 -50
  179. package/dist/theme-GAMFOLBW.js +0 -14
  180. package/dist/tools-3HOUIDM3.js +0 -47
  181. package/web/dist/assets/index-COAJqX1Z.css +0 -1
  182. package/web/dist/assets/index-CzS_4LmC.js +0 -179
  183. /package/dist/{REPL-IAK7ZN2Z.js.map → REPL-DECTPCL5.js.map} +0 -0
  184. /package/dist/{autoUpdater-2GS6LRPK.js.map → autoUpdater-FFMM2DR7.js.map} +0 -0
  185. /package/dist/{chunk-RUXIBQ3B.js.map → chunk-BJYXLCRS.js.map} +0 -0
  186. /package/dist/{chunk-AXWJI6N5.js.map → chunk-D4OZACS2.js.map} +0 -0
  187. /package/dist/{chunk-XS6PU75S.js.map → chunk-IVWPPTDM.js.map} +0 -0
  188. /package/dist/{chunk-A7X6OCZE.js.map → chunk-IXFBUXQW.js.map} +0 -0
  189. /package/dist/{chunk-3LMXSKZ7.js.map → chunk-NFXLN6FJ.js.map} +0 -0
  190. /package/dist/{commands-AVEBLFVS.js.map → commands-JSY7CGSU.js.map} +0 -0
  191. /package/dist/{config-GTJWCNPF.js.map → config-DQEFVW3Y.js.map} +0 -0
  192. /package/dist/{context-WF3TTXQU.js.map → context-HVQCTO5R.js.map} +0 -0
  193. /package/dist/{costTracker-2G3ZI2JF.js.map → costTracker-VSWW7SRT.js.map} +0 -0
  194. /package/dist/{customCommands-QOWK57EX.js.map → customCommands-XCINU5TG.js.map} +0 -0
  195. /package/dist/{env-37BAP7QF.js.map → env-ZOPEXWMF.js.map} +0 -0
  196. /package/dist/{kodeAgentSessionId-KTGFX2BE.js.map → identity-3KZQQVBG.js.map} +0 -0
  197. /package/dist/{kodeAgentSessionLoad-6F7SJXBC.js.map → kodeAgentSessionId-4SH24DVH.js.map} +0 -0
  198. /package/dist/{kodeAgentSessionResume-UEEDRJ3N.js.map → kodeAgentSessionLoad-HB3BYVNG.js.map} +0 -0
  199. /package/dist/{kodeAgentStreamJson-VIXFTYL5.js.map → kodeAgentSessionResume-IGSZZY3G.js.map} +0 -0
  200. /package/dist/{kodeAgentStructuredStdio-SI5C7AAD.js.map → kodeAgentStreamJson-4ZKIWKS3.js.map} +0 -0
  201. /package/dist/{kodeHooks-V36SHCTC.js.map → kodeAgentStructuredStdio-5DCUC6V6.js.map} +0 -0
  202. /package/dist/{llmLazy-IXVVBRTN.js.map → kodeHooks-H6DMC3XX.js.map} +0 -0
  203. /package/dist/{loader-OEJ6C3TN.js.map → llmLazy-TDLZZDPL.js.map} +0 -0
  204. /package/dist/{mcp-KE3SILMX.js.map → loader-MOVYZ76M.js.map} +0 -0
  205. /package/dist/{messages-WCSGGSEU.js.map → mcp-DUYSIR5L.js.map} +0 -0
  206. /package/dist/{model-4TQIV5J2.js.map → messages-23ICFVMC.js.map} +0 -0
  207. /package/dist/{openai-KTZV6F7N.js.map → model-FUBCTRTV.js.map} +0 -0
  208. /package/dist/{outputStyles-WX5RYQOA.js.map → openai-SMYIAIO4.js.map} +0 -0
  209. /package/dist/{pluginValidation-JNQZYLUP.js.map → outputStyles-HBOYJFBE.js.map} +0 -0
  210. /package/dist/{prompts-LE6GK75N.js.map → pluginValidation-7CGOMT6F.js.map} +0 -0
  211. /package/dist/{query-GGIP6PWG.js.map → prompts-MFESKNYZ.js.map} +0 -0
  212. /package/dist/{responsesStreaming-2AIT6GHG.js.map → query-BFEFOX4S.js.map} +0 -0
  213. /package/dist/{ripgrep-KDPQAMB2.js.map → responsesStreaming-JORGEFQC.js.map} +0 -0
  214. /package/dist/{skillMarketplace-IXAGP3Q2.js.map → ripgrep-KNJBCJIQ.js.map} +0 -0
  215. /package/dist/{state-MSCYLB6Y.js.map → sandbox-P3FR4G4D.js.map} +0 -0
  216. /package/dist/{theme-GAMFOLBW.js.map → skillMarketplace-PCMKVV4O.js.map} +0 -0
  217. /package/dist/{toolPermissionContext-I3IXPVED.js.map → state-XBYIQ7R4.js.map} +0 -0
  218. /package/dist/{toolPermissionSettings-EUZKGZU2.js.map → structuredOutput-KAVFUV2Z.js.map} +0 -0
  219. /package/dist/{tools-3HOUIDM3.js.map → theme-4ZSXUILR.js.map} +0 -0
  220. /package/dist/{uuid-VA3KVASX.js.map → thinking-TTNUZUB3.js.map} +0 -0
@@ -1,68 +1,30 @@
1
1
  import { createRequire as __newcrawCreateRequire } from "node:module";
2
2
  const require = __newcrawCreateRequire(import.meta.url);
3
3
  import {
4
- MACRO
5
- } from "./chunk-ZYSVG4X3.js";
6
-
7
- // src/utils/state/index.ts
8
- import { cwd } from "process";
9
-
10
- // src/utils/bun/shell.ts
11
- import { spawn } from "child_process";
12
- import { existsSync as existsSync4, mkdirSync as mkdirSync4, realpathSync as realpathSync2, statSync as statSync3 } from "fs";
13
- import { randomUUID as randomUUID2 } from "crypto";
14
- import { homedir as homedir2 } from "os";
15
- import { basename, dirname as dirname3, isAbsolute as isAbsolute2, join as join5, resolve as resolve2 } from "path";
16
- import which from "which";
17
-
18
- // src/utils/log/index.ts
4
+ CONFIG_BASE_DIR,
5
+ PRODUCT_COMMAND,
6
+ init_product
7
+ } from "./chunk-UYWZQVH5.js";
19
8
  import {
20
- existsSync as existsSync2,
21
- mkdirSync as mkdirSync2,
22
- writeFileSync,
23
- readFileSync as readFileSync2,
24
- readdirSync,
25
- statSync,
26
- copyFileSync,
27
- promises as fsPromises
28
- } from "fs";
29
- import { dirname, join as join3 } from "path";
9
+ MACRO,
10
+ init_macros
11
+ } from "./chunk-EHQ2M5B4.js";
12
+ import {
13
+ __esm
14
+ } from "./chunk-D4OZACS2.js";
30
15
 
31
16
  // src/services/telemetry/sentry.ts
32
17
  function initSentry() {
33
18
  }
34
19
  async function captureException(error) {
35
20
  }
36
-
37
- // src/utils/log/index.ts
38
- import { randomUUID } from "crypto";
39
- import envPaths from "env-paths";
40
-
41
- // src/constants/product.ts
42
- var PRODUCT_NAME = "NewCraw";
43
- var PROJECT_FILE = "AGENTS.md";
44
- var PRODUCT_COMMAND = "newcraw";
45
- var CONFIG_BASE_DIR = ".newcraw";
46
- var CONFIG_FILE = ".newcraw.json";
47
- var GITHUB_ISSUES_REPO_URL = "https://github.com/YOUR_USERNAME/newcraw/issues";
48
- var ASCII_LOGO = `
49
- _ _ ____
50
- | \\ | | ___ __ __/ ___|_ __ __ ___ __
51
- | \\| | / _ \\\\ \\ /\\ / / | | '__/ _\` \\ \\ /\\ / /
52
- | |\\ || __/ \\ V V /| |___| | | (_| |\\ V V /
53
- |_| \\_| \\___| \\_/\\_/ \\____|_| \\__,_| \\_/\\_/
54
-
55
- `;
56
-
57
- // src/utils/plan/planMode.ts
58
- import { existsSync, mkdirSync, readFileSync, realpathSync } from "fs";
59
- import { randomBytes } from "crypto";
60
- import { isAbsolute, join as join2, relative, resolve, parse } from "path";
21
+ var init_sentry = __esm({
22
+ "src/services/telemetry/sentry.ts"() {
23
+ }
24
+ });
61
25
 
62
26
  // src/utils/system/execFileNoThrow.ts
63
27
  import { execFile } from "child_process";
64
- var MS_IN_SECOND = 1e3;
65
- var SECONDS_IN_MINUTE = 60;
66
28
  function execFileNoThrow(file, args, abortSignal, timeout = 10 * SECONDS_IN_MINUTE * MS_IN_SECOND, preserveOutputOnError = true) {
67
29
  return new Promise((resolve3) => {
68
30
  try {
@@ -98,799 +60,815 @@ function execFileNoThrow(file, args, abortSignal, timeout = 10 * SECONDS_IN_MINU
98
60
  }
99
61
  });
100
62
  }
63
+ var MS_IN_SECOND, SECONDS_IN_MINUTE;
64
+ var init_execFileNoThrow = __esm({
65
+ "src/utils/system/execFileNoThrow.ts"() {
66
+ init_state();
67
+ init_log();
68
+ MS_IN_SECOND = 1e3;
69
+ SECONDS_IN_MINUTE = 60;
70
+ }
71
+ });
101
72
 
102
73
  // src/utils/config/env.ts
103
74
  import { memoize } from "lodash-es";
104
75
  import { join } from "path";
105
76
  import { homedir } from "os";
106
- function getKodeBaseDir() {
77
+ function getNewcrawBaseDir() {
107
78
  return process.env.NEWCRAW_CONFIG_DIR ?? process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), CONFIG_BASE_DIR);
108
79
  }
109
80
  function getGlobalConfigFilePath() {
110
- return process.env.NEWCRAW_CONFIG_DIR || process.env.CLAUDE_CONFIG_DIR ? join(getKodeBaseDir(), "config.json") : join(homedir(), CONFIG_FILE);
81
+ return join(getNewcrawBaseDir(), "config.json");
111
82
  }
112
83
  function getMemoryDir() {
113
- return join(getKodeBaseDir(), "memory");
114
- }
115
- var NEWCRAW_BASE_DIR = getKodeBaseDir();
116
- var GLOBAL_CONFIG_FILE = getGlobalConfigFilePath();
117
- var MEMORY_DIR = getMemoryDir();
118
- var getIsDocker = memoize(async () => {
119
- const { code } = await execFileNoThrow("test", ["-f", "/.dockerenv"]);
120
- if (code !== 0) {
121
- return false;
84
+ return join(getNewcrawBaseDir(), "memory");
85
+ }
86
+ var NEWCRAW_BASE_DIR, GLOBAL_CONFIG_FILE, MEMORY_DIR, getIsDocker, hasInternetAccess, env;
87
+ var init_env = __esm({
88
+ "src/utils/config/env.ts"() {
89
+ init_execFileNoThrow();
90
+ init_product();
91
+ NEWCRAW_BASE_DIR = getNewcrawBaseDir();
92
+ GLOBAL_CONFIG_FILE = getGlobalConfigFilePath();
93
+ MEMORY_DIR = getMemoryDir();
94
+ getIsDocker = memoize(async () => {
95
+ const { code } = await execFileNoThrow("test", ["-f", "/.dockerenv"]);
96
+ if (code !== 0) {
97
+ return false;
98
+ }
99
+ return process.platform === "linux";
100
+ });
101
+ hasInternetAccess = memoize(async () => {
102
+ const offline = process.env.NEWCRAW_OFFLINE ?? process.env.OFFLINE ?? process.env.NO_NETWORK ?? "";
103
+ const normalized = String(offline).trim().toLowerCase();
104
+ if (["1", "true", "yes", "on"].includes(normalized)) return false;
105
+ return true;
106
+ });
107
+ env = {
108
+ getIsDocker,
109
+ hasInternetAccess,
110
+ isCI: Boolean(process.env.CI),
111
+ platform: process.platform === "win32" ? "windows" : process.platform === "darwin" ? "macos" : "linux",
112
+ nodeVersion: process.version,
113
+ terminal: process.env.TERM_PROGRAM
114
+ };
122
115
  }
123
- return process.platform === "linux";
124
- });
125
- var hasInternetAccess = memoize(async () => {
126
- const offline = process.env.NEWCRAW_OFFLINE ?? process.env.OFFLINE ?? process.env.NO_NETWORK ?? "";
127
- const normalized = String(offline).trim().toLowerCase();
128
- if (["1", "true", "yes", "on"].includes(normalized)) return false;
129
- return true;
130
116
  });
131
- var env = {
132
- getIsDocker,
133
- hasInternetAccess,
134
- isCI: Boolean(process.env.CI),
135
- platform: process.platform === "win32" ? "windows" : process.platform === "darwin" ? "macos" : "linux",
136
- nodeVersion: process.version,
137
- terminal: process.env.TERM_PROGRAM
138
- };
139
117
 
140
118
  // src/utils/plan/planSlugWords.ts
141
- var PLAN_SLUG_ADJECTIVES = [
142
- "abundant",
143
- "ancient",
144
- "bright",
145
- "calm",
146
- "cheerful",
147
- "clever",
148
- "cozy",
149
- "curious",
150
- "dapper",
151
- "dazzling",
152
- "deep",
153
- "delightful",
154
- "eager",
155
- "elegant",
156
- "enchanted",
157
- "fancy",
158
- "fluffy",
159
- "gentle",
160
- "gleaming",
161
- "golden",
162
- "graceful",
163
- "happy",
164
- "hidden",
165
- "humble",
166
- "jolly",
167
- "joyful",
168
- "keen",
169
- "kind",
170
- "lively",
171
- "lovely",
172
- "lucky",
173
- "luminous",
174
- "magical",
175
- "majestic",
176
- "mellow",
177
- "merry",
178
- "mighty",
179
- "misty",
180
- "noble",
181
- "peaceful",
182
- "playful",
183
- "polished",
184
- "precious",
185
- "proud",
186
- "quiet",
187
- "quirky",
188
- "radiant",
189
- "rosy",
190
- "serene",
191
- "shiny",
192
- "silly",
193
- "sleepy",
194
- "smooth",
195
- "snazzy",
196
- "snug",
197
- "snuggly",
198
- "soft",
199
- "sparkling",
200
- "spicy",
201
- "splendid",
202
- "sprightly",
203
- "starry",
204
- "steady",
205
- "sunny",
206
- "swift",
207
- "tender",
208
- "tidy",
209
- "toasty",
210
- "tranquil",
211
- "twinkly",
212
- "valiant",
213
- "vast",
214
- "velvet",
215
- "vivid",
216
- "warm",
217
- "whimsical",
218
- "wild",
219
- "wise",
220
- "witty",
221
- "wondrous",
222
- "zany",
223
- "zesty",
224
- "zippy",
225
- "breezy",
226
- "bubbly",
227
- "buzzing",
228
- "cheeky",
229
- "cosmic",
230
- "cozy",
231
- "crispy",
232
- "crystalline",
233
- "cuddly",
234
- "drifting",
235
- "dreamy",
236
- "effervescent",
237
- "ethereal",
238
- "fizzy",
239
- "flickering",
240
- "floating",
241
- "floofy",
242
- "fluttering",
243
- "foamy",
244
- "frolicking",
245
- "fuzzy",
246
- "giggly",
247
- "glimmering",
248
- "glistening",
249
- "glittery",
250
- "glowing",
251
- "goofy",
252
- "groovy",
253
- "harmonic",
254
- "hazy",
255
- "humming",
256
- "iridescent",
257
- "jaunty",
258
- "jazzy",
259
- "jiggly",
260
- "melodic",
261
- "moonlit",
262
- "mossy",
263
- "nifty",
264
- "peppy",
265
- "prancy",
266
- "purrfect",
267
- "purring",
268
- "quizzical",
269
- "rippling",
270
- "rustling",
271
- "shimmering",
272
- "shimmying",
273
- "snappy",
274
- "snoopy",
275
- "squishy",
276
- "swirling",
277
- "ticklish",
278
- "tingly",
279
- "twinkling",
280
- "velvety",
281
- "wiggly",
282
- "wobbly",
283
- "woolly",
284
- "zazzy",
285
- "abstract",
286
- "adaptive",
287
- "agile",
288
- "async",
289
- "atomic",
290
- "binary",
291
- "cached",
292
- "compiled",
293
- "composed",
294
- "compressed",
295
- "concurrent",
296
- "cryptic",
297
- "curried",
298
- "declarative",
299
- "delegated",
300
- "distributed",
301
- "dynamic",
302
- "eager",
303
- "elegant",
304
- "encapsulated",
305
- "enumerated",
306
- "eventual",
307
- "expressive",
308
- "federated",
309
- "functional",
310
- "generic",
311
- "greedy",
312
- "hashed",
313
- "idempotent",
314
- "immutable",
315
- "imperative",
316
- "indexed",
317
- "inherited",
318
- "iterative",
319
- "lazy",
320
- "lexical",
321
- "linear",
322
- "linked",
323
- "logical",
324
- "memoized",
325
- "modular",
326
- "mutable",
327
- "nested",
328
- "optimized",
329
- "parallel",
330
- "parsed",
331
- "partitioned",
332
- "piped",
333
- "polymorphic",
334
- "pure",
335
- "reactive",
336
- "recursive",
337
- "refactored",
338
- "reflective",
339
- "replicated",
340
- "resilient",
341
- "robust",
342
- "scalable",
343
- "sequential",
344
- "serialized",
345
- "sharded",
346
- "sorted",
347
- "staged",
348
- "stateful",
349
- "stateless",
350
- "streamed",
351
- "structured",
352
- "synchronous",
353
- "synthetic",
354
- "temporal",
355
- "transient",
356
- "typed",
357
- "unified",
358
- "validated",
359
- "vectorized",
360
- "virtual"
361
- ];
362
- var PLAN_SLUG_VERBS = [
363
- "baking",
364
- "beaming",
365
- "booping",
366
- "bouncing",
367
- "brewing",
368
- "bubbling",
369
- "chasing",
370
- "churning",
371
- "coalescing",
372
- "conjuring",
373
- "cooking",
374
- "crafting",
375
- "crunching",
376
- "cuddling",
377
- "dancing",
378
- "dazzling",
379
- "discovering",
380
- "doodling",
381
- "dreaming",
382
- "drifting",
383
- "enchanting",
384
- "exploring",
385
- "finding",
386
- "floating",
387
- "fluttering",
388
- "foraging",
389
- "forging",
390
- "frolicking",
391
- "gathering",
392
- "giggling",
393
- "gliding",
394
- "greeting",
395
- "growing",
396
- "hatching",
397
- "herding",
398
- "honking",
399
- "hopping",
400
- "hugging",
401
- "humming",
402
- "imagining",
403
- "inventing",
404
- "jingling",
405
- "juggling",
406
- "jumping",
407
- "kindling",
408
- "knitting",
409
- "launching",
410
- "leaping",
411
- "mapping",
412
- "marinating",
413
- "meandering",
414
- "mixing",
415
- "moseying",
416
- "munching",
417
- "napping",
418
- "nibbling",
419
- "noodling",
420
- "orbiting",
421
- "painting",
422
- "percolating",
423
- "petting",
424
- "plotting",
425
- "pondering",
426
- "popping",
427
- "prancing",
428
- "purring",
429
- "puzzling",
430
- "questing",
431
- "riding",
432
- "roaming",
433
- "rolling",
434
- "sauteeing",
435
- "scribbling",
436
- "seeking",
437
- "shimmying",
438
- "singing",
439
- "skipping",
440
- "sleeping",
441
- "snacking",
442
- "sniffing",
443
- "snuggling",
444
- "soaring",
445
- "sparking",
446
- "spinning",
447
- "splashing",
448
- "sprouting",
449
- "squishing",
450
- "stargazing",
451
- "stirring",
452
- "strolling",
453
- "swimming",
454
- "swinging",
455
- "tickling",
456
- "tinkering",
457
- "toasting",
458
- "tumbling",
459
- "twirling",
460
- "waddling",
461
- "wandering",
462
- "watching",
463
- "weaving",
464
- "whistling",
465
- "wibbling",
466
- "wiggling",
467
- "wishing",
468
- "wobbling",
469
- "wondering",
470
- "yawning",
471
- "zooming"
472
- ];
473
- var PLAN_SLUG_NOUNS = [
474
- "aurora",
475
- "avalanche",
476
- "blossom",
477
- "breeze",
478
- "brook",
479
- "bubble",
480
- "canyon",
481
- "cascade",
482
- "cloud",
483
- "clover",
484
- "comet",
485
- "coral",
486
- "cosmos",
487
- "creek",
488
- "crescent",
489
- "crystal",
490
- "dawn",
491
- "dewdrop",
492
- "dusk",
493
- "eclipse",
494
- "ember",
495
- "feather",
496
- "fern",
497
- "firefly",
498
- "flame",
499
- "flurry",
500
- "fog",
501
- "forest",
502
- "frost",
503
- "galaxy",
504
- "garden",
505
- "glacier",
506
- "glade",
507
- "grove",
508
- "harbor",
509
- "horizon",
510
- "island",
511
- "lagoon",
512
- "lake",
513
- "leaf",
514
- "lightning",
515
- "meadow",
516
- "meteor",
517
- "mist",
518
- "moon",
519
- "moonbeam",
520
- "mountain",
521
- "nebula",
522
- "nova",
523
- "ocean",
524
- "orbit",
525
- "pebble",
526
- "petal",
527
- "pine",
528
- "planet",
529
- "pond",
530
- "puddle",
531
- "quasar",
532
- "rain",
533
- "rainbow",
534
- "reef",
535
- "ripple",
536
- "river",
537
- "shore",
538
- "sky",
539
- "snowflake",
540
- "spark",
541
- "spring",
542
- "star",
543
- "stardust",
544
- "starlight",
545
- "storm",
546
- "stream",
547
- "summit",
548
- "sun",
549
- "sunbeam",
550
- "sunrise",
551
- "sunset",
552
- "thunder",
553
- "tide",
554
- "twilight",
555
- "valley",
556
- "volcano",
557
- "waterfall",
558
- "wave",
559
- "willow",
560
- "wind",
561
- "alpaca",
562
- "axolotl",
563
- "badger",
564
- "bear",
565
- "beaver",
566
- "bee",
567
- "bird",
568
- "bumblebee",
569
- "bunny",
570
- "cat",
571
- "chipmunk",
572
- "crab",
573
- "crane",
574
- "deer",
575
- "dolphin",
576
- "dove",
577
- "dragon",
578
- "dragonfly",
579
- "duckling",
580
- "eagle",
581
- "elephant",
582
- "falcon",
583
- "finch",
584
- "flamingo",
585
- "fox",
586
- "frog",
587
- "giraffe",
588
- "goose",
589
- "hamster",
590
- "hare",
591
- "hedgehog",
592
- "hippo",
593
- "hummingbird",
594
- "jellyfish",
595
- "kitten",
596
- "koala",
597
- "ladybug",
598
- "lark",
599
- "lemur",
600
- "llama",
601
- "lobster",
602
- "lynx",
603
- "manatee",
604
- "meerkat",
605
- "moth",
606
- "narwhal",
607
- "newt",
608
- "octopus",
609
- "otter",
610
- "owl",
611
- "panda",
612
- "parrot",
613
- "peacock",
614
- "pelican",
615
- "penguin",
616
- "phoenix",
617
- "piglet",
618
- "platypus",
619
- "pony",
620
- "porcupine",
621
- "puffin",
622
- "puppy",
623
- "quail",
624
- "quokka",
625
- "rabbit",
626
- "raccoon",
627
- "raven",
628
- "robin",
629
- "salamander",
630
- "seahorse",
631
- "seal",
632
- "sloth",
633
- "snail",
634
- "sparrow",
635
- "sphinx",
636
- "squid",
637
- "squirrel",
638
- "starfish",
639
- "swan",
640
- "tiger",
641
- "toucan",
642
- "turtle",
643
- "unicorn",
644
- "walrus",
645
- "whale",
646
- "wolf",
647
- "wombat",
648
- "wren",
649
- "yeti",
650
- "zebra",
651
- "acorn",
652
- "anchor",
653
- "balloon",
654
- "beacon",
655
- "biscuit",
656
- "blanket",
657
- "bonbon",
658
- "book",
659
- "boot",
660
- "cake",
661
- "candle",
662
- "candy",
663
- "castle",
664
- "charm",
665
- "clock",
666
- "cocoa",
667
- "cookie",
668
- "crayon",
669
- "crown",
670
- "cupcake",
671
- "donut",
672
- "dream",
673
- "fairy",
674
- "fiddle",
675
- "flask",
676
- "flute",
677
- "fountain",
678
- "gadget",
679
- "gem",
680
- "gizmo",
681
- "globe",
682
- "goblet",
683
- "hammock",
684
- "harp",
685
- "haven",
686
- "hearth",
687
- "honey",
688
- "journal",
689
- "kazoo",
690
- "kettle",
691
- "key",
692
- "kite",
693
- "lantern",
694
- "lemon",
695
- "lighthouse",
696
- "locket",
697
- "lollipop",
698
- "mango",
699
- "map",
700
- "marble",
701
- "marshmallow",
702
- "melody",
703
- "mitten",
704
- "mochi",
705
- "muffin",
706
- "music",
707
- "nest",
708
- "noodle",
709
- "oasis",
710
- "origami",
711
- "pancake",
712
- "parasol",
713
- "peach",
714
- "pearl",
715
- "pebble",
716
- "pie",
717
- "pillow",
718
- "pinwheel",
719
- "pixel",
720
- "pizza",
721
- "plum",
722
- "popcorn",
723
- "pretzel",
724
- "prism",
725
- "pudding",
726
- "pumpkin",
727
- "puzzle",
728
- "quiche",
729
- "quill",
730
- "quilt",
731
- "riddle",
732
- "rocket",
733
- "rose",
734
- "scone",
735
- "scroll",
736
- "shell",
737
- "sketch",
738
- "snowglobe",
739
- "sonnet",
740
- "sparkle",
741
- "spindle",
742
- "sprout",
743
- "sundae",
744
- "swing",
745
- "taco",
746
- "teacup",
747
- "teapot",
748
- "thimble",
749
- "toast",
750
- "token",
751
- "tome",
752
- "tower",
753
- "treasure",
754
- "treehouse",
755
- "trinket",
756
- "truffle",
757
- "tulip",
758
- "umbrella",
759
- "waffle",
760
- "wand",
761
- "whisper",
762
- "whistle",
763
- "widget",
764
- "wreath",
765
- "zephyr",
766
- "abelson",
767
- "adleman",
768
- "aho",
769
- "allen",
770
- "babbage",
771
- "bachman",
772
- "backus",
773
- "barto",
774
- "bengio",
775
- "bentley",
776
- "blum",
777
- "boole",
778
- "brooks",
779
- "catmull",
780
- "cerf",
781
- "cherny",
782
- "church",
783
- "clarke",
784
- "cocke",
785
- "codd",
786
- "conway",
787
- "cook",
788
- "corbato",
789
- "cray",
790
- "curry",
791
- "dahl",
792
- "diffie",
793
- "dijkstra",
794
- "dongarra",
795
- "eich",
796
- "emerson",
797
- "engelbart",
798
- "feigenbaum",
799
- "floyd",
800
- "gosling",
801
- "graham",
802
- "gray",
803
- "hamming",
804
- "hanrahan",
805
- "hartmanis",
806
- "hejlsberg",
807
- "hellman",
808
- "hennessy",
809
- "hickey",
810
- "hinton",
811
- "hoare",
812
- "hollerith",
813
- "hopcroft",
814
- "hopper",
815
- "iverson",
816
- "kahan",
817
- "kahn",
818
- "karp",
819
- "kay",
820
- "kernighan",
821
- "knuth",
822
- "kurzweil",
823
- "lamport",
824
- "lampson",
825
- "lecun",
826
- "lerdorf",
827
- "liskov",
828
- "lovelace",
829
- "matsumoto",
830
- "mccarthy",
831
- "metcalfe",
832
- "micali",
833
- "milner",
834
- "minsky",
835
- "moler",
836
- "moore",
837
- "naur",
838
- "neumann",
839
- "newell",
840
- "nygaard",
841
- "papert",
842
- "parnas",
843
- "pascal",
844
- "patterson",
845
- "pearl",
846
- "perlis",
847
- "pike",
848
- "pnueli",
849
- "rabin",
850
- "reddy",
851
- "ritchie",
852
- "rivest",
853
- "rossum",
854
- "russell",
855
- "scott",
856
- "sedgewick",
857
- "shamir",
858
- "shannon",
859
- "sifakis",
860
- "simon",
861
- "stallman",
862
- "stearns",
863
- "steele",
864
- "stonebraker",
865
- "stroustrup",
866
- "sutherland",
867
- "sutton",
868
- "tarjan",
869
- "thacker",
870
- "thompson",
871
- "torvalds",
872
- "turing",
873
- "ullman",
874
- "valiant",
875
- "wadler",
876
- "wall",
877
- "wigderson",
878
- "wilkes",
879
- "wilkinson",
880
- "wirth",
881
- "wozniak",
882
- "yao"
883
- ];
119
+ var PLAN_SLUG_ADJECTIVES, PLAN_SLUG_VERBS, PLAN_SLUG_NOUNS;
120
+ var init_planSlugWords = __esm({
121
+ "src/utils/plan/planSlugWords.ts"() {
122
+ PLAN_SLUG_ADJECTIVES = [
123
+ "abundant",
124
+ "ancient",
125
+ "bright",
126
+ "calm",
127
+ "cheerful",
128
+ "clever",
129
+ "cozy",
130
+ "curious",
131
+ "dapper",
132
+ "dazzling",
133
+ "deep",
134
+ "delightful",
135
+ "eager",
136
+ "elegant",
137
+ "enchanted",
138
+ "fancy",
139
+ "fluffy",
140
+ "gentle",
141
+ "gleaming",
142
+ "golden",
143
+ "graceful",
144
+ "happy",
145
+ "hidden",
146
+ "humble",
147
+ "jolly",
148
+ "joyful",
149
+ "keen",
150
+ "kind",
151
+ "lively",
152
+ "lovely",
153
+ "lucky",
154
+ "luminous",
155
+ "magical",
156
+ "majestic",
157
+ "mellow",
158
+ "merry",
159
+ "mighty",
160
+ "misty",
161
+ "noble",
162
+ "peaceful",
163
+ "playful",
164
+ "polished",
165
+ "precious",
166
+ "proud",
167
+ "quiet",
168
+ "quirky",
169
+ "radiant",
170
+ "rosy",
171
+ "serene",
172
+ "shiny",
173
+ "silly",
174
+ "sleepy",
175
+ "smooth",
176
+ "snazzy",
177
+ "snug",
178
+ "snuggly",
179
+ "soft",
180
+ "sparkling",
181
+ "spicy",
182
+ "splendid",
183
+ "sprightly",
184
+ "starry",
185
+ "steady",
186
+ "sunny",
187
+ "swift",
188
+ "tender",
189
+ "tidy",
190
+ "toasty",
191
+ "tranquil",
192
+ "twinkly",
193
+ "valiant",
194
+ "vast",
195
+ "velvet",
196
+ "vivid",
197
+ "warm",
198
+ "whimsical",
199
+ "wild",
200
+ "wise",
201
+ "witty",
202
+ "wondrous",
203
+ "zany",
204
+ "zesty",
205
+ "zippy",
206
+ "breezy",
207
+ "bubbly",
208
+ "buzzing",
209
+ "cheeky",
210
+ "cosmic",
211
+ "cozy",
212
+ "crispy",
213
+ "crystalline",
214
+ "cuddly",
215
+ "drifting",
216
+ "dreamy",
217
+ "effervescent",
218
+ "ethereal",
219
+ "fizzy",
220
+ "flickering",
221
+ "floating",
222
+ "floofy",
223
+ "fluttering",
224
+ "foamy",
225
+ "frolicking",
226
+ "fuzzy",
227
+ "giggly",
228
+ "glimmering",
229
+ "glistening",
230
+ "glittery",
231
+ "glowing",
232
+ "goofy",
233
+ "groovy",
234
+ "harmonic",
235
+ "hazy",
236
+ "humming",
237
+ "iridescent",
238
+ "jaunty",
239
+ "jazzy",
240
+ "jiggly",
241
+ "melodic",
242
+ "moonlit",
243
+ "mossy",
244
+ "nifty",
245
+ "peppy",
246
+ "prancy",
247
+ "purrfect",
248
+ "purring",
249
+ "quizzical",
250
+ "rippling",
251
+ "rustling",
252
+ "shimmering",
253
+ "shimmying",
254
+ "snappy",
255
+ "snoopy",
256
+ "squishy",
257
+ "swirling",
258
+ "ticklish",
259
+ "tingly",
260
+ "twinkling",
261
+ "velvety",
262
+ "wiggly",
263
+ "wobbly",
264
+ "woolly",
265
+ "zazzy",
266
+ "abstract",
267
+ "adaptive",
268
+ "agile",
269
+ "async",
270
+ "atomic",
271
+ "binary",
272
+ "cached",
273
+ "compiled",
274
+ "composed",
275
+ "compressed",
276
+ "concurrent",
277
+ "cryptic",
278
+ "curried",
279
+ "declarative",
280
+ "delegated",
281
+ "distributed",
282
+ "dynamic",
283
+ "eager",
284
+ "elegant",
285
+ "encapsulated",
286
+ "enumerated",
287
+ "eventual",
288
+ "expressive",
289
+ "federated",
290
+ "functional",
291
+ "generic",
292
+ "greedy",
293
+ "hashed",
294
+ "idempotent",
295
+ "immutable",
296
+ "imperative",
297
+ "indexed",
298
+ "inherited",
299
+ "iterative",
300
+ "lazy",
301
+ "lexical",
302
+ "linear",
303
+ "linked",
304
+ "logical",
305
+ "memoized",
306
+ "modular",
307
+ "mutable",
308
+ "nested",
309
+ "optimized",
310
+ "parallel",
311
+ "parsed",
312
+ "partitioned",
313
+ "piped",
314
+ "polymorphic",
315
+ "pure",
316
+ "reactive",
317
+ "recursive",
318
+ "refactored",
319
+ "reflective",
320
+ "replicated",
321
+ "resilient",
322
+ "robust",
323
+ "scalable",
324
+ "sequential",
325
+ "serialized",
326
+ "sharded",
327
+ "sorted",
328
+ "staged",
329
+ "stateful",
330
+ "stateless",
331
+ "streamed",
332
+ "structured",
333
+ "synchronous",
334
+ "synthetic",
335
+ "temporal",
336
+ "transient",
337
+ "typed",
338
+ "unified",
339
+ "validated",
340
+ "vectorized",
341
+ "virtual"
342
+ ];
343
+ PLAN_SLUG_VERBS = [
344
+ "baking",
345
+ "beaming",
346
+ "booping",
347
+ "bouncing",
348
+ "brewing",
349
+ "bubbling",
350
+ "chasing",
351
+ "churning",
352
+ "coalescing",
353
+ "conjuring",
354
+ "cooking",
355
+ "crafting",
356
+ "crunching",
357
+ "cuddling",
358
+ "dancing",
359
+ "dazzling",
360
+ "discovering",
361
+ "doodling",
362
+ "dreaming",
363
+ "drifting",
364
+ "enchanting",
365
+ "exploring",
366
+ "finding",
367
+ "floating",
368
+ "fluttering",
369
+ "foraging",
370
+ "forging",
371
+ "frolicking",
372
+ "gathering",
373
+ "giggling",
374
+ "gliding",
375
+ "greeting",
376
+ "growing",
377
+ "hatching",
378
+ "herding",
379
+ "honking",
380
+ "hopping",
381
+ "hugging",
382
+ "humming",
383
+ "imagining",
384
+ "inventing",
385
+ "jingling",
386
+ "juggling",
387
+ "jumping",
388
+ "kindling",
389
+ "knitting",
390
+ "launching",
391
+ "leaping",
392
+ "mapping",
393
+ "marinating",
394
+ "meandering",
395
+ "mixing",
396
+ "moseying",
397
+ "munching",
398
+ "napping",
399
+ "nibbling",
400
+ "noodling",
401
+ "orbiting",
402
+ "painting",
403
+ "percolating",
404
+ "petting",
405
+ "plotting",
406
+ "pondering",
407
+ "popping",
408
+ "prancing",
409
+ "purring",
410
+ "puzzling",
411
+ "questing",
412
+ "riding",
413
+ "roaming",
414
+ "rolling",
415
+ "sauteeing",
416
+ "scribbling",
417
+ "seeking",
418
+ "shimmying",
419
+ "singing",
420
+ "skipping",
421
+ "sleeping",
422
+ "snacking",
423
+ "sniffing",
424
+ "snuggling",
425
+ "soaring",
426
+ "sparking",
427
+ "spinning",
428
+ "splashing",
429
+ "sprouting",
430
+ "squishing",
431
+ "stargazing",
432
+ "stirring",
433
+ "strolling",
434
+ "swimming",
435
+ "swinging",
436
+ "tickling",
437
+ "tinkering",
438
+ "toasting",
439
+ "tumbling",
440
+ "twirling",
441
+ "waddling",
442
+ "wandering",
443
+ "watching",
444
+ "weaving",
445
+ "whistling",
446
+ "wibbling",
447
+ "wiggling",
448
+ "wishing",
449
+ "wobbling",
450
+ "wondering",
451
+ "yawning",
452
+ "zooming"
453
+ ];
454
+ PLAN_SLUG_NOUNS = [
455
+ "aurora",
456
+ "avalanche",
457
+ "blossom",
458
+ "breeze",
459
+ "brook",
460
+ "bubble",
461
+ "canyon",
462
+ "cascade",
463
+ "cloud",
464
+ "clover",
465
+ "comet",
466
+ "coral",
467
+ "cosmos",
468
+ "creek",
469
+ "crescent",
470
+ "crystal",
471
+ "dawn",
472
+ "dewdrop",
473
+ "dusk",
474
+ "eclipse",
475
+ "ember",
476
+ "feather",
477
+ "fern",
478
+ "firefly",
479
+ "flame",
480
+ "flurry",
481
+ "fog",
482
+ "forest",
483
+ "frost",
484
+ "galaxy",
485
+ "garden",
486
+ "glacier",
487
+ "glade",
488
+ "grove",
489
+ "harbor",
490
+ "horizon",
491
+ "island",
492
+ "lagoon",
493
+ "lake",
494
+ "leaf",
495
+ "lightning",
496
+ "meadow",
497
+ "meteor",
498
+ "mist",
499
+ "moon",
500
+ "moonbeam",
501
+ "mountain",
502
+ "nebula",
503
+ "nova",
504
+ "ocean",
505
+ "orbit",
506
+ "pebble",
507
+ "petal",
508
+ "pine",
509
+ "planet",
510
+ "pond",
511
+ "puddle",
512
+ "quasar",
513
+ "rain",
514
+ "rainbow",
515
+ "reef",
516
+ "ripple",
517
+ "river",
518
+ "shore",
519
+ "sky",
520
+ "snowflake",
521
+ "spark",
522
+ "spring",
523
+ "star",
524
+ "stardust",
525
+ "starlight",
526
+ "storm",
527
+ "stream",
528
+ "summit",
529
+ "sun",
530
+ "sunbeam",
531
+ "sunrise",
532
+ "sunset",
533
+ "thunder",
534
+ "tide",
535
+ "twilight",
536
+ "valley",
537
+ "volcano",
538
+ "waterfall",
539
+ "wave",
540
+ "willow",
541
+ "wind",
542
+ "alpaca",
543
+ "axolotl",
544
+ "badger",
545
+ "bear",
546
+ "beaver",
547
+ "bee",
548
+ "bird",
549
+ "bumblebee",
550
+ "bunny",
551
+ "cat",
552
+ "chipmunk",
553
+ "crab",
554
+ "crane",
555
+ "deer",
556
+ "dolphin",
557
+ "dove",
558
+ "dragon",
559
+ "dragonfly",
560
+ "duckling",
561
+ "eagle",
562
+ "elephant",
563
+ "falcon",
564
+ "finch",
565
+ "flamingo",
566
+ "fox",
567
+ "frog",
568
+ "giraffe",
569
+ "goose",
570
+ "hamster",
571
+ "hare",
572
+ "hedgehog",
573
+ "hippo",
574
+ "hummingbird",
575
+ "jellyfish",
576
+ "kitten",
577
+ "koala",
578
+ "ladybug",
579
+ "lark",
580
+ "lemur",
581
+ "llama",
582
+ "lobster",
583
+ "lynx",
584
+ "manatee",
585
+ "meerkat",
586
+ "moth",
587
+ "narwhal",
588
+ "newt",
589
+ "octopus",
590
+ "otter",
591
+ "owl",
592
+ "panda",
593
+ "parrot",
594
+ "peacock",
595
+ "pelican",
596
+ "penguin",
597
+ "phoenix",
598
+ "piglet",
599
+ "platypus",
600
+ "pony",
601
+ "porcupine",
602
+ "puffin",
603
+ "puppy",
604
+ "quail",
605
+ "quokka",
606
+ "rabbit",
607
+ "raccoon",
608
+ "raven",
609
+ "robin",
610
+ "salamander",
611
+ "seahorse",
612
+ "seal",
613
+ "sloth",
614
+ "snail",
615
+ "sparrow",
616
+ "sphinx",
617
+ "squid",
618
+ "squirrel",
619
+ "starfish",
620
+ "swan",
621
+ "tiger",
622
+ "toucan",
623
+ "turtle",
624
+ "unicorn",
625
+ "walrus",
626
+ "whale",
627
+ "wolf",
628
+ "wombat",
629
+ "wren",
630
+ "yeti",
631
+ "zebra",
632
+ "acorn",
633
+ "anchor",
634
+ "balloon",
635
+ "beacon",
636
+ "biscuit",
637
+ "blanket",
638
+ "bonbon",
639
+ "book",
640
+ "boot",
641
+ "cake",
642
+ "candle",
643
+ "candy",
644
+ "castle",
645
+ "charm",
646
+ "clock",
647
+ "cocoa",
648
+ "cookie",
649
+ "crayon",
650
+ "crown",
651
+ "cupcake",
652
+ "donut",
653
+ "dream",
654
+ "fairy",
655
+ "fiddle",
656
+ "flask",
657
+ "flute",
658
+ "fountain",
659
+ "gadget",
660
+ "gem",
661
+ "gizmo",
662
+ "globe",
663
+ "goblet",
664
+ "hammock",
665
+ "harp",
666
+ "haven",
667
+ "hearth",
668
+ "honey",
669
+ "journal",
670
+ "kazoo",
671
+ "kettle",
672
+ "key",
673
+ "kite",
674
+ "lantern",
675
+ "lemon",
676
+ "lighthouse",
677
+ "locket",
678
+ "lollipop",
679
+ "mango",
680
+ "map",
681
+ "marble",
682
+ "marshmallow",
683
+ "melody",
684
+ "mitten",
685
+ "mochi",
686
+ "muffin",
687
+ "music",
688
+ "nest",
689
+ "noodle",
690
+ "oasis",
691
+ "origami",
692
+ "pancake",
693
+ "parasol",
694
+ "peach",
695
+ "pearl",
696
+ "pebble",
697
+ "pie",
698
+ "pillow",
699
+ "pinwheel",
700
+ "pixel",
701
+ "pizza",
702
+ "plum",
703
+ "popcorn",
704
+ "pretzel",
705
+ "prism",
706
+ "pudding",
707
+ "pumpkin",
708
+ "puzzle",
709
+ "quiche",
710
+ "quill",
711
+ "quilt",
712
+ "riddle",
713
+ "rocket",
714
+ "rose",
715
+ "scone",
716
+ "scroll",
717
+ "shell",
718
+ "sketch",
719
+ "snowglobe",
720
+ "sonnet",
721
+ "sparkle",
722
+ "spindle",
723
+ "sprout",
724
+ "sundae",
725
+ "swing",
726
+ "taco",
727
+ "teacup",
728
+ "teapot",
729
+ "thimble",
730
+ "toast",
731
+ "token",
732
+ "tome",
733
+ "tower",
734
+ "treasure",
735
+ "treehouse",
736
+ "trinket",
737
+ "truffle",
738
+ "tulip",
739
+ "umbrella",
740
+ "waffle",
741
+ "wand",
742
+ "whisper",
743
+ "whistle",
744
+ "widget",
745
+ "wreath",
746
+ "zephyr",
747
+ "abelson",
748
+ "adleman",
749
+ "aho",
750
+ "allen",
751
+ "babbage",
752
+ "bachman",
753
+ "backus",
754
+ "barto",
755
+ "bengio",
756
+ "bentley",
757
+ "blum",
758
+ "boole",
759
+ "brooks",
760
+ "catmull",
761
+ "cerf",
762
+ "cherny",
763
+ "church",
764
+ "clarke",
765
+ "cocke",
766
+ "codd",
767
+ "conway",
768
+ "cook",
769
+ "corbato",
770
+ "cray",
771
+ "curry",
772
+ "dahl",
773
+ "diffie",
774
+ "dijkstra",
775
+ "dongarra",
776
+ "eich",
777
+ "emerson",
778
+ "engelbart",
779
+ "feigenbaum",
780
+ "floyd",
781
+ "gosling",
782
+ "graham",
783
+ "gray",
784
+ "hamming",
785
+ "hanrahan",
786
+ "hartmanis",
787
+ "hejlsberg",
788
+ "hellman",
789
+ "hennessy",
790
+ "hickey",
791
+ "hinton",
792
+ "hoare",
793
+ "hollerith",
794
+ "hopcroft",
795
+ "hopper",
796
+ "iverson",
797
+ "kahan",
798
+ "kahn",
799
+ "karp",
800
+ "kay",
801
+ "kernighan",
802
+ "knuth",
803
+ "kurzweil",
804
+ "lamport",
805
+ "lampson",
806
+ "lecun",
807
+ "lerdorf",
808
+ "liskov",
809
+ "lovelace",
810
+ "matsumoto",
811
+ "mccarthy",
812
+ "metcalfe",
813
+ "micali",
814
+ "milner",
815
+ "minsky",
816
+ "moler",
817
+ "moore",
818
+ "naur",
819
+ "neumann",
820
+ "newell",
821
+ "nygaard",
822
+ "papert",
823
+ "parnas",
824
+ "pascal",
825
+ "patterson",
826
+ "pearl",
827
+ "perlis",
828
+ "pike",
829
+ "pnueli",
830
+ "rabin",
831
+ "reddy",
832
+ "ritchie",
833
+ "rivest",
834
+ "rossum",
835
+ "russell",
836
+ "scott",
837
+ "sedgewick",
838
+ "shamir",
839
+ "shannon",
840
+ "sifakis",
841
+ "simon",
842
+ "stallman",
843
+ "stearns",
844
+ "steele",
845
+ "stonebraker",
846
+ "stroustrup",
847
+ "sutherland",
848
+ "sutton",
849
+ "tarjan",
850
+ "thacker",
851
+ "thompson",
852
+ "torvalds",
853
+ "turing",
854
+ "ullman",
855
+ "valiant",
856
+ "wadler",
857
+ "wall",
858
+ "wigderson",
859
+ "wilkes",
860
+ "wilkinson",
861
+ "wirth",
862
+ "wozniak",
863
+ "yao"
864
+ ];
865
+ }
866
+ });
884
867
 
885
868
  // src/utils/plan/planMode.ts
886
- var DEFAULT_CONVERSATION_KEY = "default";
887
- var MAX_SLUG_ATTEMPTS = 10;
888
- var TURNS_BETWEEN_ATTACHMENTS = 5;
889
- var planModeEnabledByConversationKey = /* @__PURE__ */ new Map();
890
- var planSlugCache = /* @__PURE__ */ new Map();
891
- var planModeFlagsByConversationKey = /* @__PURE__ */ new Map();
892
- var planModeAttachmentStateByAgentKey = /* @__PURE__ */ new Map();
893
- var activePlanConversationKey = null;
869
+ import { existsSync, mkdirSync, readFileSync, realpathSync } from "fs";
870
+ import { randomBytes } from "crypto";
871
+ import { isAbsolute, join as join2, relative, resolve, parse } from "path";
894
872
  function getConversationKey(context) {
895
873
  const messageLogName = context?.options?.messageLogName ?? DEFAULT_CONVERSATION_KEY;
896
874
  const forkNumber = context?.options?.forkNumber ?? 0;
@@ -1179,7 +1157,7 @@ function hydratePlanSlugFromMessages(messages, context) {
1179
1157
  return false;
1180
1158
  }
1181
1159
  function getPlanDirectory() {
1182
- const dir = join2(getKodeBaseDir(), "plans");
1160
+ const dir = join2(getNewcrawBaseDir(), "plans");
1183
1161
  if (!existsSync(dir)) {
1184
1162
  mkdirSync(dir, { recursive: true });
1185
1163
  }
@@ -1217,11 +1195,36 @@ function readPlanFile(agentId, conversationKey) {
1217
1195
  planFilePath
1218
1196
  };
1219
1197
  }
1198
+ var DEFAULT_CONVERSATION_KEY, MAX_SLUG_ATTEMPTS, TURNS_BETWEEN_ATTACHMENTS, planModeEnabledByConversationKey, planSlugCache, planModeFlagsByConversationKey, planModeAttachmentStateByAgentKey, activePlanConversationKey;
1199
+ var init_planMode = __esm({
1200
+ "src/utils/plan/planMode.ts"() {
1201
+ init_env();
1202
+ init_planSlugWords();
1203
+ DEFAULT_CONVERSATION_KEY = "default";
1204
+ MAX_SLUG_ATTEMPTS = 10;
1205
+ TURNS_BETWEEN_ATTACHMENTS = 5;
1206
+ planModeEnabledByConversationKey = /* @__PURE__ */ new Map();
1207
+ planSlugCache = /* @__PURE__ */ new Map();
1208
+ planModeFlagsByConversationKey = /* @__PURE__ */ new Map();
1209
+ planModeAttachmentStateByAgentKey = /* @__PURE__ */ new Map();
1210
+ activePlanConversationKey = null;
1211
+ }
1212
+ });
1220
1213
 
1221
1214
  // src/utils/log/index.ts
1222
- var IN_MEMORY_ERROR_LOG = [];
1223
- var MAX_IN_MEMORY_ERRORS = 100;
1224
- var PERMISSION_ERROR_CODES = /* @__PURE__ */ new Set(["EACCES", "EPERM", "EROFS"]);
1215
+ import {
1216
+ existsSync as existsSync2,
1217
+ mkdirSync as mkdirSync2,
1218
+ writeFileSync,
1219
+ readFileSync as readFileSync2,
1220
+ readdirSync,
1221
+ statSync,
1222
+ copyFileSync,
1223
+ promises as fsPromises
1224
+ } from "fs";
1225
+ import { dirname, join as join3 } from "path";
1226
+ import { randomUUID } from "crypto";
1227
+ import envPaths from "env-paths";
1225
1228
  function isPermissionError(error) {
1226
1229
  return typeof error === "object" && error !== null && "code" in error && PERMISSION_ERROR_CODES.has(error.code ?? "");
1227
1230
  }
@@ -1248,8 +1251,6 @@ function safeWriteFile(path, data, encoding = "utf8") {
1248
1251
  throw error;
1249
1252
  }
1250
1253
  }
1251
- var SESSION_ID = randomUUID();
1252
- var paths = envPaths(PRODUCT_COMMAND);
1253
1254
  function getProjectDir(cwd2) {
1254
1255
  return cwd2.replace(/[^a-zA-Z0-9]/g, "-");
1255
1256
  }
@@ -1257,30 +1258,11 @@ function getLegacyCacheRoot() {
1257
1258
  return process.env.NEWCRAW_LEGACY_CACHE_ROOT ?? paths.cache;
1258
1259
  }
1259
1260
  function getNewLogRoot() {
1260
- return process.env.NEWCRAW_LOG_ROOT ?? getKodeBaseDir();
1261
- }
1262
- var CACHE_PATHS = {
1263
- errors: () => join3(getNewLogRoot(), getProjectDir(process.cwd()), "errors"),
1264
- messages: () => join3(getNewLogRoot(), getProjectDir(process.cwd()), "messages"),
1265
- mcpLogs: (serverName) => join3(
1266
- getLegacyCacheRoot(),
1267
- getProjectDir(process.cwd()),
1268
- `mcp-logs-${serverName}`
1269
- )
1270
- };
1271
- var LEGACY_CACHE_PATHS = {
1272
- errors: () => join3(getLegacyCacheRoot(), getProjectDir(process.cwd()), "errors"),
1273
- messages: () => join3(getLegacyCacheRoot(), getProjectDir(process.cwd()), "messages"),
1274
- mcpLogs: (serverName) => join3(
1275
- getLegacyCacheRoot(),
1276
- getProjectDir(process.cwd()),
1277
- `mcp-logs-${serverName}`
1278
- )
1279
- };
1261
+ return process.env.NEWCRAW_LOG_ROOT ?? getNewcrawBaseDir();
1262
+ }
1280
1263
  function dateToFilename(date) {
1281
1264
  return date.toISOString().replace(/[:.]/g, "-");
1282
1265
  }
1283
- var DATE = dateToFilename(/* @__PURE__ */ new Date());
1284
1266
  function getErrorsPath() {
1285
1267
  return join3(CACHE_PATHS.errors(), DATE + ".txt");
1286
1268
  }
@@ -1290,8 +1272,6 @@ function getMessagesPath(messageLogName, forkNumber, sidechainNumber) {
1290
1272
  `${messageLogName}${forkNumber > 0 ? `-${forkNumber}` : ""}${sidechainNumber > 0 ? `-sidechain-${sidechainNumber}` : ""}.json`
1291
1273
  );
1292
1274
  }
1293
- var MIGRATION_MESSAGE_LOG_LIMIT = 50;
1294
- var didMigrateMessageLogs = false;
1295
1275
  function migrateLegacyMessageLogsIfNeeded() {
1296
1276
  if (didMigrateMessageLogs) return;
1297
1277
  didMigrateMessageLogs = true;
@@ -1567,6 +1547,42 @@ function logMCPError(serverName, error) {
1567
1547
  } catch {
1568
1548
  }
1569
1549
  }
1550
+ var IN_MEMORY_ERROR_LOG, MAX_IN_MEMORY_ERRORS, PERMISSION_ERROR_CODES, SESSION_ID, paths, CACHE_PATHS, LEGACY_CACHE_PATHS, DATE, MIGRATION_MESSAGE_LOG_LIMIT, didMigrateMessageLogs;
1551
+ var init_log = __esm({
1552
+ "src/utils/log/index.ts"() {
1553
+ init_sentry();
1554
+ init_macros();
1555
+ init_product();
1556
+ init_planMode();
1557
+ init_env();
1558
+ IN_MEMORY_ERROR_LOG = [];
1559
+ MAX_IN_MEMORY_ERRORS = 100;
1560
+ PERMISSION_ERROR_CODES = /* @__PURE__ */ new Set(["EACCES", "EPERM", "EROFS"]);
1561
+ SESSION_ID = randomUUID();
1562
+ paths = envPaths(PRODUCT_COMMAND);
1563
+ CACHE_PATHS = {
1564
+ errors: () => join3(getNewLogRoot(), getProjectDir(process.cwd()), "errors"),
1565
+ messages: () => join3(getNewLogRoot(), getProjectDir(process.cwd()), "messages"),
1566
+ mcpLogs: (serverName) => join3(
1567
+ getLegacyCacheRoot(),
1568
+ getProjectDir(process.cwd()),
1569
+ `mcp-logs-${serverName}`
1570
+ )
1571
+ };
1572
+ LEGACY_CACHE_PATHS = {
1573
+ errors: () => join3(getLegacyCacheRoot(), getProjectDir(process.cwd()), "errors"),
1574
+ messages: () => join3(getLegacyCacheRoot(), getProjectDir(process.cwd()), "messages"),
1575
+ mcpLogs: (serverName) => join3(
1576
+ getLegacyCacheRoot(),
1577
+ getProjectDir(process.cwd()),
1578
+ `mcp-logs-${serverName}`
1579
+ )
1580
+ };
1581
+ DATE = dateToFilename(/* @__PURE__ */ new Date());
1582
+ MIGRATION_MESSAGE_LOG_LIMIT = 50;
1583
+ didMigrateMessageLogs = false;
1584
+ }
1585
+ });
1570
1586
 
1571
1587
  // src/utils/log/taskOutputStore.ts
1572
1588
  import {
@@ -1581,9 +1597,8 @@ import { dirname as dirname2, join as join4 } from "path";
1581
1597
  function getProjectDir2(cwd2) {
1582
1598
  return cwd2.replace(/[^a-zA-Z0-9]/g, "-");
1583
1599
  }
1584
- var PROJECT_ROOT = process.cwd();
1585
1600
  function getTaskOutputsDir() {
1586
- return join4(getKodeBaseDir(), getProjectDir2(PROJECT_ROOT), "tasks");
1601
+ return join4(getNewcrawBaseDir(), getProjectDir2(PROJECT_ROOT), "tasks");
1587
1602
  }
1588
1603
  function getTaskOutputFilePath(taskId) {
1589
1604
  return join4(getTaskOutputsDir(), `${taskId}.output`);
@@ -1619,8 +1634,21 @@ function readTaskOutput(taskId) {
1619
1634
  return "";
1620
1635
  }
1621
1636
  }
1637
+ var PROJECT_ROOT;
1638
+ var init_taskOutputStore = __esm({
1639
+ "src/utils/log/taskOutputStore.ts"() {
1640
+ init_env();
1641
+ PROJECT_ROOT = process.cwd();
1642
+ }
1643
+ });
1622
1644
 
1623
1645
  // src/utils/bun/shell.ts
1646
+ import { spawn } from "child_process";
1647
+ import { existsSync as existsSync4, mkdirSync as mkdirSync4, realpathSync as realpathSync2, statSync as statSync3 } from "fs";
1648
+ import { randomUUID as randomUUID2 } from "crypto";
1649
+ import { homedir as homedir2 } from "os";
1650
+ import { basename, dirname as dirname3, isAbsolute as isAbsolute2, join as join5, resolve as resolve2 } from "path";
1651
+ import which from "which";
1624
1652
  function whichSync(bin) {
1625
1653
  try {
1626
1654
  return which.sync(bin, { nothrow: true }) ?? null;
@@ -2098,393 +2126,521 @@ function renderBashNotification(notification) {
2098
2126
  "</bash-notification>"
2099
2127
  ].join("\n");
2100
2128
  }
2101
- var BunShell = class _BunShell {
2102
- cwd;
2103
- isAlive = true;
2104
- currentProcess = null;
2105
- abortController = null;
2106
- backgroundProcesses = /* @__PURE__ */ new Map();
2107
- constructor(cwd2) {
2108
- this.cwd = cwd2;
2109
- }
2110
- static instance = null;
2111
- static restart() {
2112
- if (_BunShell.instance) {
2113
- _BunShell.instance.close();
2114
- _BunShell.instance = null;
2115
- }
2116
- }
2117
- static getInstance() {
2118
- if (!_BunShell.instance || !_BunShell.instance.isAlive) {
2119
- _BunShell.instance = new _BunShell(process.cwd());
2120
- }
2121
- return _BunShell.instance;
2122
- }
2123
- static getShellCmdForPlatform(platform, command, _env = process.env) {
2124
- if (platform === "win32") {
2125
- return [resolvePowerShellPath(), "-NoProfile", "-NonInteractive", "-Command", command];
2126
- }
2127
- const sh = existsSync4("/bin/sh") ? "/bin/sh" : "sh";
2128
- return [sh, "-c", command];
2129
- }
2130
- getShellCmd(command) {
2131
- return _BunShell.getShellCmdForPlatform(
2132
- process.platform,
2133
- command,
2134
- process.env
2135
- );
2136
- }
2137
- buildSandboxCmd(command, sandbox) {
2138
- if (!sandbox.enabled) return null;
2139
- const platform = sandbox.__platformOverride ?? process.platform;
2140
- const needsNetworkRestriction = sandbox.needsNetworkRestriction !== void 0 ? sandbox.needsNetworkRestriction : sandbox.allowNetwork === true ? false : true;
2141
- const writeConfig = sandbox.writeConfig ?? (sandbox.writableRoots && sandbox.writableRoots.length > 0 ? { allowOnly: sandbox.writableRoots.filter(Boolean) } : void 0);
2142
- const readConfig = sandbox.readConfig;
2143
- const hasReadRestrictions = (readConfig?.denyOnly?.length ?? 0) > 0;
2144
- const hasWriteRestrictions = writeConfig !== void 0;
2145
- const hasNetworkRestrictions = needsNetworkRestriction === true;
2146
- if (!hasReadRestrictions && !hasWriteRestrictions && !hasNetworkRestrictions) {
2147
- return null;
2148
- }
2149
- const binShell = sandbox.binShell ?? (whichSync("bash") ? "bash" : "sh");
2150
- const binShellPath = whichOrSelf(binShell);
2151
- const cwd2 = sandbox.chdir || this.cwd;
2152
- if (platform === "linux") {
2153
- const bwrapPath = sandbox.__bwrapPathOverride !== void 0 ? sandbox.__bwrapPathOverride : whichSync("bwrap") ?? whichSync("bubblewrap");
2154
- if (!bwrapPath) {
2155
- return null;
2129
+ var BunShell;
2130
+ var init_shell = __esm({
2131
+ "src/utils/bun/shell.ts"() {
2132
+ init_log();
2133
+ init_taskOutputStore();
2134
+ BunShell = class _BunShell {
2135
+ cwd;
2136
+ isAlive = true;
2137
+ currentProcess = null;
2138
+ abortController = null;
2139
+ backgroundProcesses = /* @__PURE__ */ new Map();
2140
+ constructor(cwd2) {
2141
+ this.cwd = cwd2;
2156
2142
  }
2157
- try {
2158
- mkdirSync4("/tmp/newcraw", { recursive: true });
2159
- } catch {
2160
- }
2161
- const cmd = buildLinuxBwrapCommand({
2162
- bwrapPath,
2163
- command,
2164
- needsNetworkRestriction,
2165
- readConfig,
2166
- writeConfig,
2167
- enableWeakerNestedSandbox: sandbox.enableWeakerNestedSandbox,
2168
- binShellPath,
2169
- cwd: cwd2
2170
- });
2171
- return { cmd };
2172
- }
2173
- if (platform === "darwin") {
2174
- const sandboxExecPath = sandbox.__sandboxExecPathOverride !== void 0 ? sandbox.__sandboxExecPathOverride : existsSync4("/usr/bin/sandbox-exec") ? "/usr/bin/sandbox-exec" : whichSync("sandbox-exec");
2175
- if (!sandboxExecPath) {
2176
- return null;
2177
- }
2178
- try {
2179
- mkdirSync4("/tmp/newcraw", { recursive: true });
2180
- } catch {
2181
- }
2182
- try {
2183
- mkdirSync4("/private/tmp/newcraw", { recursive: true });
2184
- } catch {
2185
- }
2186
- return {
2187
- cmd: buildMacosSandboxExecCommand({
2188
- sandboxExecPath,
2189
- binShellPath,
2190
- command,
2191
- needsNetworkRestriction,
2192
- httpProxyPort: sandbox.httpProxyPort,
2193
- socksProxyPort: sandbox.socksProxyPort,
2194
- allowUnixSockets: sandbox.allowUnixSockets,
2195
- allowAllUnixSockets: sandbox.allowAllUnixSockets,
2196
- allowLocalBinding: sandbox.allowLocalBinding,
2197
- readConfig,
2198
- writeConfig
2199
- })
2200
- };
2201
- }
2202
- return null;
2203
- }
2204
- isSandboxInitFailure(stderr) {
2205
- const s = stderr.toLowerCase();
2206
- return s.includes("bwrap:") || s.includes("bubblewrap") || s.includes("namespace") && s.includes("failed");
2207
- }
2208
- startStreamReader(stream, append) {
2209
- if (!stream) return;
2210
- try {
2211
- ;
2212
- stream.setEncoding?.("utf8");
2213
- } catch {
2214
- }
2215
- stream.on("data", (chunk) => {
2216
- append(
2217
- typeof chunk === "string" ? chunk : Buffer.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk)
2218
- );
2219
- });
2220
- stream.on("error", (err) => {
2221
- logError(`Stream read error: ${err}`);
2222
- });
2223
- }
2224
- createCancellableTextCollector(stream, options) {
2225
- let text = "";
2226
- const collectText = options?.collectText !== false;
2227
- if (!stream) {
2228
- return {
2229
- getText: () => text,
2230
- done: Promise.resolve(),
2231
- cancel: async () => {
2143
+ static instance = null;
2144
+ static restart() {
2145
+ if (_BunShell.instance) {
2146
+ _BunShell.instance.close();
2147
+ _BunShell.instance = null;
2232
2148
  }
2233
- };
2234
- }
2235
- let cancelled = false;
2236
- let resolveDone = null;
2237
- const done = new Promise((resolve3) => {
2238
- resolveDone = resolve3;
2239
- });
2240
- const finish = () => {
2241
- if (!resolveDone) return;
2242
- resolveDone();
2243
- resolveDone = null;
2244
- };
2245
- const onData = (chunk) => {
2246
- if (cancelled) return;
2247
- const s = typeof chunk === "string" ? chunk : Buffer.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk);
2248
- if (collectText) text += s;
2249
- options?.onChunk?.(s);
2250
- };
2251
- const onEnd = () => {
2252
- cleanup();
2253
- finish();
2254
- };
2255
- const onClose = () => {
2256
- cleanup();
2257
- finish();
2258
- };
2259
- const cleanup = () => {
2260
- stream.off("data", onData);
2261
- stream.off("end", onEnd);
2262
- stream.off("close", onClose);
2263
- stream.off("error", onError);
2264
- };
2265
- const onError = (err) => {
2266
- if (!cancelled) {
2267
- logError(`Stream read error: ${err}`);
2268
- }
2269
- cleanup();
2270
- finish();
2271
- };
2272
- try {
2273
- ;
2274
- stream.setEncoding?.("utf8");
2275
- } catch {
2276
- }
2277
- stream.on("data", onData);
2278
- stream.once("end", onEnd);
2279
- stream.once("close", onClose);
2280
- stream.once("error", onError);
2281
- return {
2282
- getText: () => text,
2283
- done,
2284
- cancel: async () => {
2285
- if (cancelled) return;
2286
- cancelled = true;
2287
- cleanup();
2288
- finish();
2289
- }
2290
- };
2291
- }
2292
- static makeBackgroundTaskId() {
2293
- return `b${randomUUID2().replace(/-/g, "").slice(0, 6)}`;
2294
- }
2295
- execPromotable(command, abortSignal, timeout, options) {
2296
- const DEFAULT_TIMEOUT = 12e4;
2297
- const commandTimeout = timeout ?? DEFAULT_TIMEOUT;
2298
- const startedAt = Date.now();
2299
- const sandbox = options?.sandbox;
2300
- const shouldAttemptSandbox = sandbox?.enabled === true;
2301
- const executionCwd = shouldAttemptSandbox && sandbox?.chdir ? sandbox.chdir : this.cwd;
2302
- if (abortSignal?.aborted) {
2303
- return {
2304
- get status() {
2305
- return "killed";
2306
- },
2307
- background: () => null,
2308
- kill: () => {
2309
- },
2310
- result: Promise.resolve({
2311
- stdout: "",
2312
- stderr: "Command aborted before execution",
2313
- code: 145,
2314
- interrupted: true
2315
- })
2316
- };
2317
- }
2318
- const sandboxCmd = shouldAttemptSandbox ? this.buildSandboxCmd(command, sandbox) : null;
2319
- if (shouldAttemptSandbox && sandbox?.require && !sandboxCmd) {
2320
- return {
2321
- get status() {
2322
- return "killed";
2323
- },
2324
- background: () => null,
2325
- kill: () => {
2326
- },
2327
- result: Promise.resolve({
2328
- stdout: "",
2329
- stderr: "System sandbox is required but unavailable (missing bubblewrap or unsupported platform).",
2330
- code: 2,
2331
- interrupted: false
2332
- })
2333
- };
2334
- }
2335
- const cmdToRun = sandboxCmd ? sandboxCmd.cmd : this.getShellCmd(command);
2336
- const internalAbortController = new AbortController();
2337
- this.abortController = internalAbortController;
2338
- let status = "running";
2339
- let backgroundProcess = null;
2340
- let backgroundTaskId = null;
2341
- let stdout = "";
2342
- let stderr = "";
2343
- let wasAborted = false;
2344
- let wasBackgrounded = false;
2345
- let timeoutHandle = null;
2346
- let timedOut = false;
2347
- let onTimeoutCb = null;
2348
- const countNonEmptyLines = (chunk) => chunk.split("\n").filter((line) => line.length > 0).length;
2349
- const spawnedProcess = spawnWithExited({ cmd: cmdToRun, cwd: executionCwd });
2350
- this.currentProcess = spawnedProcess;
2351
- const onAbort = () => {
2352
- if (status === "backgrounded") return;
2353
- wasAborted = true;
2354
- try {
2355
- internalAbortController.abort();
2356
- } catch {
2357
2149
  }
2358
- try {
2359
- spawnedProcess.kill();
2360
- } catch {
2150
+ static getInstance() {
2151
+ if (!_BunShell.instance || !_BunShell.instance.isAlive) {
2152
+ _BunShell.instance = new _BunShell(process.cwd());
2153
+ }
2154
+ return _BunShell.instance;
2361
2155
  }
2362
- if (backgroundProcess) backgroundProcess.interrupted = true;
2363
- };
2364
- const clearForegroundGuards = () => {
2365
- if (timeoutHandle) {
2366
- clearTimeout(timeoutHandle);
2367
- timeoutHandle = null;
2156
+ static getShellCmdForPlatform(platform, command, _env = process.env) {
2157
+ if (platform === "win32") {
2158
+ return [resolvePowerShellPath(), "-NoProfile", "-NonInteractive", "-Command", command];
2159
+ }
2160
+ const sh = existsSync4("/bin/sh") ? "/bin/sh" : "sh";
2161
+ return [sh, "-c", command];
2368
2162
  }
2369
- if (abortSignal) {
2370
- abortSignal.removeEventListener("abort", onAbort);
2163
+ getShellCmd(command) {
2164
+ return _BunShell.getShellCmdForPlatform(
2165
+ process.platform,
2166
+ command,
2167
+ process.env
2168
+ );
2371
2169
  }
2372
- };
2373
- if (abortSignal) {
2374
- abortSignal.addEventListener("abort", onAbort, { once: true });
2375
- if (abortSignal.aborted) onAbort();
2376
- }
2377
- const stdoutCollector = this.createCancellableTextCollector(
2378
- spawnedProcess.stdout,
2379
- {
2380
- collectText: false,
2381
- onChunk: (chunk) => {
2382
- stdout += chunk;
2383
- options?.onStdoutChunk?.(chunk);
2384
- if (backgroundProcess) {
2385
- backgroundProcess.stdout = stdout;
2386
- appendTaskOutput(backgroundProcess.id, chunk);
2387
- backgroundProcess.stdoutLineCount += countNonEmptyLines(chunk);
2170
+ buildSandboxCmd(command, sandbox) {
2171
+ if (!sandbox.enabled) return null;
2172
+ const platform = sandbox.__platformOverride ?? process.platform;
2173
+ const needsNetworkRestriction = sandbox.needsNetworkRestriction !== void 0 ? sandbox.needsNetworkRestriction : sandbox.allowNetwork === true ? false : true;
2174
+ const writeConfig = sandbox.writeConfig ?? (sandbox.writableRoots && sandbox.writableRoots.length > 0 ? { allowOnly: sandbox.writableRoots.filter(Boolean) } : void 0);
2175
+ const readConfig = sandbox.readConfig;
2176
+ const hasReadRestrictions = (readConfig?.denyOnly?.length ?? 0) > 0;
2177
+ const hasWriteRestrictions = writeConfig !== void 0;
2178
+ const hasNetworkRestrictions = needsNetworkRestriction === true;
2179
+ if (!hasReadRestrictions && !hasWriteRestrictions && !hasNetworkRestrictions) {
2180
+ return null;
2181
+ }
2182
+ const binShell = sandbox.binShell ?? (whichSync("bash") ? "bash" : "sh");
2183
+ const binShellPath = whichOrSelf(binShell);
2184
+ const cwd2 = sandbox.chdir || this.cwd;
2185
+ if (platform === "linux") {
2186
+ const bwrapPath = sandbox.__bwrapPathOverride !== void 0 ? sandbox.__bwrapPathOverride : whichSync("bwrap") ?? whichSync("bubblewrap");
2187
+ if (!bwrapPath) {
2188
+ return null;
2189
+ }
2190
+ try {
2191
+ mkdirSync4("/tmp/newcraw", { recursive: true });
2192
+ } catch {
2388
2193
  }
2194
+ const cmd = buildLinuxBwrapCommand({
2195
+ bwrapPath,
2196
+ command,
2197
+ needsNetworkRestriction,
2198
+ readConfig,
2199
+ writeConfig,
2200
+ enableWeakerNestedSandbox: sandbox.enableWeakerNestedSandbox,
2201
+ binShellPath,
2202
+ cwd: cwd2
2203
+ });
2204
+ return { cmd };
2389
2205
  }
2390
- }
2391
- );
2392
- const stderrCollector = this.createCancellableTextCollector(
2393
- spawnedProcess.stderr,
2394
- {
2395
- collectText: false,
2396
- onChunk: (chunk) => {
2397
- stderr += chunk;
2398
- options?.onStderrChunk?.(chunk);
2399
- if (backgroundProcess) {
2400
- backgroundProcess.stderr = stderr;
2401
- appendTaskOutput(backgroundProcess.id, chunk);
2402
- backgroundProcess.stderrLineCount += countNonEmptyLines(chunk);
2206
+ if (platform === "darwin") {
2207
+ const sandboxExecPath = sandbox.__sandboxExecPathOverride !== void 0 ? sandbox.__sandboxExecPathOverride : existsSync4("/usr/bin/sandbox-exec") ? "/usr/bin/sandbox-exec" : whichSync("sandbox-exec");
2208
+ if (!sandboxExecPath) {
2209
+ return null;
2403
2210
  }
2211
+ try {
2212
+ mkdirSync4("/tmp/newcraw", { recursive: true });
2213
+ } catch {
2214
+ }
2215
+ try {
2216
+ mkdirSync4("/private/tmp/newcraw", { recursive: true });
2217
+ } catch {
2218
+ }
2219
+ return {
2220
+ cmd: buildMacosSandboxExecCommand({
2221
+ sandboxExecPath,
2222
+ binShellPath,
2223
+ command,
2224
+ needsNetworkRestriction,
2225
+ httpProxyPort: sandbox.httpProxyPort,
2226
+ socksProxyPort: sandbox.socksProxyPort,
2227
+ allowUnixSockets: sandbox.allowUnixSockets,
2228
+ allowAllUnixSockets: sandbox.allowAllUnixSockets,
2229
+ allowLocalBinding: sandbox.allowLocalBinding,
2230
+ readConfig,
2231
+ writeConfig
2232
+ })
2233
+ };
2404
2234
  }
2235
+ return null;
2405
2236
  }
2406
- );
2407
- timeoutHandle = setTimeout(() => {
2408
- if (status !== "running") return;
2409
- if (onTimeoutCb) {
2410
- onTimeoutCb(background);
2411
- return;
2412
- }
2413
- timedOut = true;
2414
- try {
2415
- spawnedProcess.kill();
2416
- } catch {
2237
+ isSandboxInitFailure(stderr) {
2238
+ const s = stderr.toLowerCase();
2239
+ return s.includes("bwrap:") || s.includes("bubblewrap") || s.includes("namespace") && s.includes("failed");
2417
2240
  }
2418
- try {
2419
- internalAbortController.abort();
2420
- } catch {
2241
+ startStreamReader(stream, append) {
2242
+ if (!stream) return;
2243
+ try {
2244
+ ;
2245
+ stream.setEncoding?.("utf8");
2246
+ } catch {
2247
+ }
2248
+ stream.on("data", (chunk) => {
2249
+ append(
2250
+ typeof chunk === "string" ? chunk : Buffer.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk)
2251
+ );
2252
+ });
2253
+ stream.on("error", (err) => {
2254
+ logError(`Stream read error: ${err}`);
2255
+ });
2421
2256
  }
2422
- }, commandTimeout);
2423
- const background = (bashId) => {
2424
- if (backgroundTaskId) return { bashId: backgroundTaskId };
2425
- if (status !== "running") return null;
2426
- backgroundTaskId = bashId ?? _BunShell.makeBackgroundTaskId();
2427
- const outputFile = touchTaskOutputFile(backgroundTaskId);
2428
- if (stdout) appendTaskOutput(backgroundTaskId, stdout);
2429
- if (stderr) appendTaskOutput(backgroundTaskId, stderr);
2430
- status = "backgrounded";
2431
- wasBackgrounded = true;
2432
- clearForegroundGuards();
2433
- backgroundProcess = {
2434
- id: backgroundTaskId,
2435
- command,
2436
- stdout,
2437
- stderr,
2438
- stdoutCursor: 0,
2439
- stderrCursor: 0,
2440
- stdoutLineCount: countNonEmptyLines(stdout),
2441
- stderrLineCount: countNonEmptyLines(stderr),
2442
- lastReportedStdoutLines: 0,
2443
- lastReportedStderrLines: 0,
2444
- code: null,
2445
- interrupted: false,
2446
- killed: false,
2447
- timedOut: false,
2448
- completionStatusSentInAttachment: false,
2449
- notified: false,
2450
- startedAt,
2451
- timeoutAt: Number.POSITIVE_INFINITY,
2452
- process: spawnedProcess,
2453
- abortController: internalAbortController,
2454
- timeoutHandle: null,
2455
- cwd: executionCwd,
2456
- outputFile
2457
- };
2458
- this.backgroundProcesses.set(backgroundTaskId, backgroundProcess);
2459
- this.currentProcess = null;
2460
- this.abortController = null;
2461
- return { bashId: backgroundTaskId };
2462
- };
2463
- const kill = () => {
2464
- status = "killed";
2465
- try {
2466
- spawnedProcess.kill();
2467
- } catch {
2257
+ createCancellableTextCollector(stream, options) {
2258
+ let text = "";
2259
+ const collectText = options?.collectText !== false;
2260
+ if (!stream) {
2261
+ return {
2262
+ getText: () => text,
2263
+ done: Promise.resolve(),
2264
+ cancel: async () => {
2265
+ }
2266
+ };
2267
+ }
2268
+ let cancelled = false;
2269
+ let resolveDone = null;
2270
+ const done = new Promise((resolve3) => {
2271
+ resolveDone = resolve3;
2272
+ });
2273
+ const finish = () => {
2274
+ if (!resolveDone) return;
2275
+ resolveDone();
2276
+ resolveDone = null;
2277
+ };
2278
+ const onData = (chunk) => {
2279
+ if (cancelled) return;
2280
+ const s = typeof chunk === "string" ? chunk : Buffer.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk);
2281
+ if (collectText) text += s;
2282
+ options?.onChunk?.(s);
2283
+ };
2284
+ const onEnd = () => {
2285
+ cleanup();
2286
+ finish();
2287
+ };
2288
+ const onClose = () => {
2289
+ cleanup();
2290
+ finish();
2291
+ };
2292
+ const cleanup = () => {
2293
+ stream.off("data", onData);
2294
+ stream.off("end", onEnd);
2295
+ stream.off("close", onClose);
2296
+ stream.off("error", onError);
2297
+ };
2298
+ const onError = (err) => {
2299
+ if (!cancelled) {
2300
+ logError(`Stream read error: ${err}`);
2301
+ }
2302
+ cleanup();
2303
+ finish();
2304
+ };
2305
+ try {
2306
+ ;
2307
+ stream.setEncoding?.("utf8");
2308
+ } catch {
2309
+ }
2310
+ stream.on("data", onData);
2311
+ stream.once("end", onEnd);
2312
+ stream.once("close", onClose);
2313
+ stream.once("error", onError);
2314
+ return {
2315
+ getText: () => text,
2316
+ done,
2317
+ cancel: async () => {
2318
+ if (cancelled) return;
2319
+ cancelled = true;
2320
+ cleanup();
2321
+ finish();
2322
+ }
2323
+ };
2468
2324
  }
2469
- try {
2470
- internalAbortController.abort();
2471
- } catch {
2325
+ static makeBackgroundTaskId() {
2326
+ return `b${randomUUID2().replace(/-/g, "").slice(0, 6)}`;
2472
2327
  }
2473
- if (backgroundProcess) {
2474
- backgroundProcess.interrupted = true;
2475
- backgroundProcess.killed = true;
2328
+ execPromotable(command, abortSignal, timeout, options) {
2329
+ const DEFAULT_TIMEOUT = 12e4;
2330
+ const commandTimeout = timeout ?? DEFAULT_TIMEOUT;
2331
+ const startedAt = Date.now();
2332
+ const sandbox = options?.sandbox;
2333
+ const shouldAttemptSandbox = sandbox?.enabled === true;
2334
+ const executionCwd = shouldAttemptSandbox && sandbox?.chdir ? sandbox.chdir : this.cwd;
2335
+ if (abortSignal?.aborted) {
2336
+ return {
2337
+ get status() {
2338
+ return "killed";
2339
+ },
2340
+ background: () => null,
2341
+ kill: () => {
2342
+ },
2343
+ result: Promise.resolve({
2344
+ stdout: "",
2345
+ stderr: "Command aborted before execution",
2346
+ code: 145,
2347
+ interrupted: true
2348
+ })
2349
+ };
2350
+ }
2351
+ const sandboxCmd = shouldAttemptSandbox ? this.buildSandboxCmd(command, sandbox) : null;
2352
+ if (shouldAttemptSandbox && sandbox?.require && !sandboxCmd) {
2353
+ return {
2354
+ get status() {
2355
+ return "killed";
2356
+ },
2357
+ background: () => null,
2358
+ kill: () => {
2359
+ },
2360
+ result: Promise.resolve({
2361
+ stdout: "",
2362
+ stderr: "System sandbox is required but unavailable (missing bubblewrap or unsupported platform).",
2363
+ code: 2,
2364
+ interrupted: false
2365
+ })
2366
+ };
2367
+ }
2368
+ const cmdToRun = sandboxCmd ? sandboxCmd.cmd : this.getShellCmd(command);
2369
+ const internalAbortController = new AbortController();
2370
+ this.abortController = internalAbortController;
2371
+ let status = "running";
2372
+ let backgroundProcess = null;
2373
+ let backgroundTaskId = null;
2374
+ let stdout = "";
2375
+ let stderr = "";
2376
+ let wasAborted = false;
2377
+ let wasBackgrounded = false;
2378
+ let timeoutHandle = null;
2379
+ let timedOut = false;
2380
+ let onTimeoutCb = null;
2381
+ const countNonEmptyLines = (chunk) => chunk.split("\n").filter((line) => line.length > 0).length;
2382
+ const spawnedProcess = spawnWithExited({ cmd: cmdToRun, cwd: executionCwd });
2383
+ this.currentProcess = spawnedProcess;
2384
+ const onAbort = () => {
2385
+ if (status === "backgrounded") return;
2386
+ wasAborted = true;
2387
+ try {
2388
+ internalAbortController.abort();
2389
+ } catch {
2390
+ }
2391
+ try {
2392
+ spawnedProcess.kill();
2393
+ } catch {
2394
+ }
2395
+ if (backgroundProcess) backgroundProcess.interrupted = true;
2396
+ };
2397
+ const clearForegroundGuards = () => {
2398
+ if (timeoutHandle) {
2399
+ clearTimeout(timeoutHandle);
2400
+ timeoutHandle = null;
2401
+ }
2402
+ if (abortSignal) {
2403
+ abortSignal.removeEventListener("abort", onAbort);
2404
+ }
2405
+ };
2406
+ if (abortSignal) {
2407
+ abortSignal.addEventListener("abort", onAbort, { once: true });
2408
+ if (abortSignal.aborted) onAbort();
2409
+ }
2410
+ const stdoutCollector = this.createCancellableTextCollector(
2411
+ spawnedProcess.stdout,
2412
+ {
2413
+ collectText: false,
2414
+ onChunk: (chunk) => {
2415
+ stdout += chunk;
2416
+ options?.onStdoutChunk?.(chunk);
2417
+ if (backgroundProcess) {
2418
+ backgroundProcess.stdout = stdout;
2419
+ appendTaskOutput(backgroundProcess.id, chunk);
2420
+ backgroundProcess.stdoutLineCount += countNonEmptyLines(chunk);
2421
+ }
2422
+ }
2423
+ }
2424
+ );
2425
+ const stderrCollector = this.createCancellableTextCollector(
2426
+ spawnedProcess.stderr,
2427
+ {
2428
+ collectText: false,
2429
+ onChunk: (chunk) => {
2430
+ stderr += chunk;
2431
+ options?.onStderrChunk?.(chunk);
2432
+ if (backgroundProcess) {
2433
+ backgroundProcess.stderr = stderr;
2434
+ appendTaskOutput(backgroundProcess.id, chunk);
2435
+ backgroundProcess.stderrLineCount += countNonEmptyLines(chunk);
2436
+ }
2437
+ }
2438
+ }
2439
+ );
2440
+ timeoutHandle = setTimeout(() => {
2441
+ if (status !== "running") return;
2442
+ if (onTimeoutCb) {
2443
+ onTimeoutCb(background);
2444
+ return;
2445
+ }
2446
+ timedOut = true;
2447
+ try {
2448
+ spawnedProcess.kill();
2449
+ } catch {
2450
+ }
2451
+ try {
2452
+ internalAbortController.abort();
2453
+ } catch {
2454
+ }
2455
+ }, commandTimeout);
2456
+ const background = (bashId) => {
2457
+ if (backgroundTaskId) return { bashId: backgroundTaskId };
2458
+ if (status !== "running") return null;
2459
+ backgroundTaskId = bashId ?? _BunShell.makeBackgroundTaskId();
2460
+ const outputFile = touchTaskOutputFile(backgroundTaskId);
2461
+ if (stdout) appendTaskOutput(backgroundTaskId, stdout);
2462
+ if (stderr) appendTaskOutput(backgroundTaskId, stderr);
2463
+ status = "backgrounded";
2464
+ wasBackgrounded = true;
2465
+ clearForegroundGuards();
2466
+ backgroundProcess = {
2467
+ id: backgroundTaskId,
2468
+ command,
2469
+ stdout,
2470
+ stderr,
2471
+ stdoutCursor: 0,
2472
+ stderrCursor: 0,
2473
+ stdoutLineCount: countNonEmptyLines(stdout),
2474
+ stderrLineCount: countNonEmptyLines(stderr),
2475
+ lastReportedStdoutLines: 0,
2476
+ lastReportedStderrLines: 0,
2477
+ code: null,
2478
+ interrupted: false,
2479
+ killed: false,
2480
+ timedOut: false,
2481
+ completionStatusSentInAttachment: false,
2482
+ notified: false,
2483
+ startedAt,
2484
+ timeoutAt: Number.POSITIVE_INFINITY,
2485
+ process: spawnedProcess,
2486
+ abortController: internalAbortController,
2487
+ timeoutHandle: null,
2488
+ cwd: executionCwd,
2489
+ outputFile
2490
+ };
2491
+ this.backgroundProcesses.set(backgroundTaskId, backgroundProcess);
2492
+ this.currentProcess = null;
2493
+ this.abortController = null;
2494
+ return { bashId: backgroundTaskId };
2495
+ };
2496
+ const kill = () => {
2497
+ status = "killed";
2498
+ try {
2499
+ spawnedProcess.kill();
2500
+ } catch {
2501
+ }
2502
+ try {
2503
+ internalAbortController.abort();
2504
+ } catch {
2505
+ }
2506
+ if (backgroundProcess) {
2507
+ backgroundProcess.interrupted = true;
2508
+ backgroundProcess.killed = true;
2509
+ }
2510
+ };
2511
+ const result = (async () => {
2512
+ try {
2513
+ await spawnedProcess.exited;
2514
+ if (status === "running" || status === "backgrounded")
2515
+ status = "completed";
2516
+ if (backgroundProcess) {
2517
+ backgroundProcess.code = spawnedProcess.exitCode ?? 0;
2518
+ backgroundProcess.interrupted = backgroundProcess.interrupted || wasAborted || internalAbortController.signal.aborted;
2519
+ }
2520
+ if (!wasBackgrounded) {
2521
+ await Promise.race([
2522
+ Promise.allSettled([stdoutCollector.done, stderrCollector.done]),
2523
+ new Promise((resolve3) => setTimeout(resolve3, 250))
2524
+ ]);
2525
+ await Promise.allSettled([
2526
+ stdoutCollector.cancel(),
2527
+ stderrCollector.cancel()
2528
+ ]);
2529
+ }
2530
+ const interrupted = wasAborted || abortSignal?.aborted === true || internalAbortController.signal.aborted === true || timedOut;
2531
+ let code = spawnedProcess.exitCode;
2532
+ if (!Number.isFinite(code)) {
2533
+ code = interrupted ? 143 : 0;
2534
+ }
2535
+ const stderrWithTimeout = timedOut ? [`Command timed out`, stderr].filter(Boolean).join("\n") : stderr;
2536
+ const stderrAnnotated = sandboxCmd ? maybeAnnotateMacosSandboxStderr(stderrWithTimeout, sandbox) : stderrWithTimeout;
2537
+ return {
2538
+ stdout,
2539
+ stderr: stderrAnnotated,
2540
+ code,
2541
+ interrupted
2542
+ };
2543
+ } finally {
2544
+ clearForegroundGuards();
2545
+ if (this.currentProcess === spawnedProcess) {
2546
+ this.currentProcess = null;
2547
+ this.abortController = null;
2548
+ }
2549
+ }
2550
+ })();
2551
+ const execHandle = {
2552
+ get status() {
2553
+ return status;
2554
+ },
2555
+ background,
2556
+ kill,
2557
+ result
2558
+ };
2559
+ execHandle.onTimeout = (cb) => {
2560
+ onTimeoutCb = cb;
2561
+ };
2562
+ result.then((r) => {
2563
+ if (!backgroundProcess || !backgroundTaskId) return;
2564
+ backgroundProcess.code = r.code;
2565
+ backgroundProcess.interrupted = r.interrupted;
2566
+ }).catch(() => {
2567
+ if (!backgroundProcess) return;
2568
+ backgroundProcess.code = backgroundProcess.code ?? 2;
2569
+ });
2570
+ return execHandle;
2476
2571
  }
2477
- };
2478
- const result = (async () => {
2479
- try {
2480
- await spawnedProcess.exited;
2481
- if (status === "running" || status === "backgrounded")
2482
- status = "completed";
2483
- if (backgroundProcess) {
2484
- backgroundProcess.code = spawnedProcess.exitCode ?? 0;
2485
- backgroundProcess.interrupted = backgroundProcess.interrupted || wasAborted || internalAbortController.signal.aborted;
2572
+ async exec(command, abortSignal, timeout, options) {
2573
+ const DEFAULT_TIMEOUT = 12e4;
2574
+ const commandTimeout = timeout ?? DEFAULT_TIMEOUT;
2575
+ this.abortController = new AbortController();
2576
+ let wasAborted = false;
2577
+ const onAbort = () => {
2578
+ wasAborted = true;
2579
+ try {
2580
+ this.abortController?.abort();
2581
+ } catch {
2582
+ }
2583
+ try {
2584
+ this.currentProcess?.kill();
2585
+ } catch {
2586
+ }
2587
+ };
2588
+ if (abortSignal) {
2589
+ abortSignal.addEventListener("abort", onAbort, { once: true });
2486
2590
  }
2487
- if (!wasBackgrounded) {
2591
+ const sandbox = options?.sandbox;
2592
+ const shouldAttemptSandbox = sandbox?.enabled === true;
2593
+ const executionCwd = shouldAttemptSandbox && sandbox?.chdir ? sandbox.chdir : this.cwd;
2594
+ const runOnce = async (cmd, cwdOverride) => {
2595
+ this.currentProcess = spawnWithExited({
2596
+ cmd,
2597
+ cwd: cwdOverride ?? executionCwd
2598
+ });
2599
+ const stdoutCollector = this.createCancellableTextCollector(
2600
+ this.currentProcess.stdout,
2601
+ { onChunk: options?.onStdoutChunk }
2602
+ );
2603
+ const stderrCollector = this.createCancellableTextCollector(
2604
+ this.currentProcess.stderr,
2605
+ { onChunk: options?.onStderrChunk }
2606
+ );
2607
+ let timeoutHandle = null;
2608
+ const timeoutPromise = new Promise((resolve3) => {
2609
+ timeoutHandle = setTimeout(() => resolve3("timeout"), commandTimeout);
2610
+ });
2611
+ const result = await Promise.race([
2612
+ this.currentProcess.exited.then(() => "completed"),
2613
+ timeoutPromise
2614
+ ]);
2615
+ if (timeoutHandle) clearTimeout(timeoutHandle);
2616
+ if (result === "timeout") {
2617
+ try {
2618
+ this.currentProcess.kill();
2619
+ } catch {
2620
+ }
2621
+ try {
2622
+ this.abortController.abort();
2623
+ } catch {
2624
+ }
2625
+ try {
2626
+ await this.currentProcess.exited;
2627
+ } catch {
2628
+ }
2629
+ await Promise.race([
2630
+ Promise.allSettled([stdoutCollector.done, stderrCollector.done]),
2631
+ new Promise((resolve3) => setTimeout(resolve3, 250))
2632
+ ]);
2633
+ await Promise.allSettled([
2634
+ stdoutCollector.cancel(),
2635
+ stderrCollector.cancel()
2636
+ ]);
2637
+ return {
2638
+ stdout: "",
2639
+ stderr: "Command timed out",
2640
+ code: 143,
2641
+ interrupted: true
2642
+ };
2643
+ }
2488
2644
  await Promise.race([
2489
2645
  Promise.allSettled([stdoutCollector.done, stderrCollector.done]),
2490
2646
  new Promise((resolve3) => setTimeout(resolve3, 250))
@@ -2493,415 +2649,292 @@ var BunShell = class _BunShell {
2493
2649
  stdoutCollector.cancel(),
2494
2650
  stderrCollector.cancel()
2495
2651
  ]);
2496
- }
2497
- const interrupted = wasAborted || abortSignal?.aborted === true || internalAbortController.signal.aborted === true || timedOut;
2498
- let code = spawnedProcess.exitCode;
2499
- if (!Number.isFinite(code)) {
2500
- code = interrupted ? 143 : 0;
2501
- }
2502
- const stderrWithTimeout = timedOut ? [`Command timed out`, stderr].filter(Boolean).join("\n") : stderr;
2503
- const stderrAnnotated = sandboxCmd ? maybeAnnotateMacosSandboxStderr(stderrWithTimeout, sandbox) : stderrWithTimeout;
2504
- return {
2505
- stdout,
2506
- stderr: stderrAnnotated,
2507
- code,
2508
- interrupted
2652
+ const stdout = stdoutCollector.getText();
2653
+ const stderr = stderrCollector.getText();
2654
+ const interrupted = wasAborted || abortSignal?.aborted === true || this.abortController?.signal.aborted === true;
2655
+ const exitCode = this.currentProcess.exitCode ?? (interrupted ? 143 : 0);
2656
+ return {
2657
+ stdout,
2658
+ stderr,
2659
+ code: exitCode,
2660
+ interrupted
2661
+ };
2509
2662
  };
2510
- } finally {
2511
- clearForegroundGuards();
2512
- if (this.currentProcess === spawnedProcess) {
2663
+ try {
2664
+ if (shouldAttemptSandbox) {
2665
+ const sandboxCmd = this.buildSandboxCmd(command, sandbox);
2666
+ if (!sandboxCmd) {
2667
+ if (sandbox?.require) {
2668
+ return {
2669
+ stdout: "",
2670
+ stderr: "System sandbox is required but unavailable (missing bubblewrap or unsupported platform).",
2671
+ code: 2,
2672
+ interrupted: false
2673
+ };
2674
+ }
2675
+ const fallback = await runOnce(this.getShellCmd(command));
2676
+ return {
2677
+ ...fallback,
2678
+ stderr: `[sandbox] unavailable, ran without isolation.
2679
+ ${fallback.stderr}`.trim()
2680
+ };
2681
+ }
2682
+ const sandboxed = await runOnce(sandboxCmd.cmd);
2683
+ sandboxed.stderr = maybeAnnotateMacosSandboxStderr(
2684
+ sandboxed.stderr,
2685
+ sandbox
2686
+ );
2687
+ if (!sandboxed.interrupted && sandboxed.code !== 0 && this.isSandboxInitFailure(sandboxed.stderr) && !sandbox?.require) {
2688
+ const fallback = await runOnce(this.getShellCmd(command));
2689
+ return {
2690
+ ...fallback,
2691
+ stderr: `[sandbox] failed to start, ran without isolation.
2692
+ ${fallback.stderr}`.trim()
2693
+ };
2694
+ }
2695
+ return sandboxed;
2696
+ }
2697
+ return await runOnce(this.getShellCmd(command));
2698
+ } catch (error) {
2699
+ if (this.abortController.signal.aborted) {
2700
+ this.currentProcess?.kill();
2701
+ return {
2702
+ stdout: "",
2703
+ stderr: "Command was interrupted",
2704
+ code: 143,
2705
+ interrupted: true
2706
+ };
2707
+ }
2708
+ const errorStr = error instanceof Error ? error.message : String(error);
2709
+ logError(`Shell execution error: ${errorStr}`);
2710
+ return {
2711
+ stdout: "",
2712
+ stderr: errorStr,
2713
+ code: 2,
2714
+ interrupted: false
2715
+ };
2716
+ } finally {
2717
+ if (abortSignal) {
2718
+ abortSignal.removeEventListener("abort", onAbort);
2719
+ }
2513
2720
  this.currentProcess = null;
2514
2721
  this.abortController = null;
2515
2722
  }
2516
2723
  }
2517
- })();
2518
- const execHandle = {
2519
- get status() {
2520
- return status;
2521
- },
2522
- background,
2523
- kill,
2524
- result
2525
- };
2526
- execHandle.onTimeout = (cb) => {
2527
- onTimeoutCb = cb;
2528
- };
2529
- result.then((r) => {
2530
- if (!backgroundProcess || !backgroundTaskId) return;
2531
- backgroundProcess.code = r.code;
2532
- backgroundProcess.interrupted = r.interrupted;
2533
- }).catch(() => {
2534
- if (!backgroundProcess) return;
2535
- backgroundProcess.code = backgroundProcess.code ?? 2;
2536
- });
2537
- return execHandle;
2538
- }
2539
- async exec(command, abortSignal, timeout, options) {
2540
- const DEFAULT_TIMEOUT = 12e4;
2541
- const commandTimeout = timeout ?? DEFAULT_TIMEOUT;
2542
- this.abortController = new AbortController();
2543
- let wasAborted = false;
2544
- const onAbort = () => {
2545
- wasAborted = true;
2546
- try {
2547
- this.abortController?.abort();
2548
- } catch {
2724
+ execInBackground(command, timeout, options) {
2725
+ const DEFAULT_TIMEOUT = 12e4;
2726
+ const commandTimeout = timeout ?? DEFAULT_TIMEOUT;
2727
+ const abortController = new AbortController();
2728
+ const sandbox = options?.sandbox;
2729
+ const sandboxCmd = sandbox?.enabled === true ? this.buildSandboxCmd(command, sandbox) : null;
2730
+ const executionCwd = sandbox?.enabled === true && sandbox?.chdir ? sandbox.chdir : this.cwd;
2731
+ if (sandbox?.enabled === true && sandbox?.require && !sandboxCmd) {
2732
+ throw new Error(
2733
+ "System sandbox is required but unavailable (missing bubblewrap or unsupported platform)."
2734
+ );
2735
+ }
2736
+ const cmdToRun = sandboxCmd ? sandboxCmd.cmd : this.getShellCmd(command);
2737
+ const bashId = _BunShell.makeBackgroundTaskId();
2738
+ const outputFile = touchTaskOutputFile(bashId);
2739
+ const process2 = spawnWithExited({ cmd: cmdToRun, cwd: executionCwd });
2740
+ const timeoutHandle = setTimeout(() => {
2741
+ abortController.abort();
2742
+ backgroundProcess.timedOut = true;
2743
+ process2.kill();
2744
+ }, commandTimeout);
2745
+ const backgroundProcess = {
2746
+ id: bashId,
2747
+ command,
2748
+ stdout: "",
2749
+ stderr: "",
2750
+ stdoutCursor: 0,
2751
+ stderrCursor: 0,
2752
+ stdoutLineCount: 0,
2753
+ stderrLineCount: 0,
2754
+ lastReportedStdoutLines: 0,
2755
+ lastReportedStderrLines: 0,
2756
+ code: null,
2757
+ interrupted: false,
2758
+ killed: false,
2759
+ timedOut: false,
2760
+ completionStatusSentInAttachment: false,
2761
+ notified: false,
2762
+ startedAt: Date.now(),
2763
+ timeoutAt: Date.now() + commandTimeout,
2764
+ process: process2,
2765
+ abortController,
2766
+ timeoutHandle,
2767
+ cwd: executionCwd,
2768
+ outputFile
2769
+ };
2770
+ const countNonEmptyLines = (chunk) => chunk.split("\n").filter((line) => line.length > 0).length;
2771
+ this.startStreamReader(process2.stdout, (chunk) => {
2772
+ backgroundProcess.stdout += chunk;
2773
+ appendTaskOutput(bashId, chunk);
2774
+ backgroundProcess.stdoutLineCount += countNonEmptyLines(chunk);
2775
+ });
2776
+ this.startStreamReader(process2.stderr, (chunk) => {
2777
+ backgroundProcess.stderr += chunk;
2778
+ appendTaskOutput(bashId, chunk);
2779
+ backgroundProcess.stderrLineCount += countNonEmptyLines(chunk);
2780
+ });
2781
+ process2.exited.then(() => {
2782
+ backgroundProcess.code = process2.exitCode ?? 0;
2783
+ backgroundProcess.interrupted = backgroundProcess.interrupted || abortController.signal.aborted;
2784
+ if (sandbox?.enabled === true) {
2785
+ backgroundProcess.stderr = maybeAnnotateMacosSandboxStderr(
2786
+ backgroundProcess.stderr,
2787
+ sandbox
2788
+ );
2789
+ }
2790
+ if (backgroundProcess.timeoutHandle) {
2791
+ clearTimeout(backgroundProcess.timeoutHandle);
2792
+ backgroundProcess.timeoutHandle = null;
2793
+ }
2794
+ });
2795
+ this.backgroundProcesses.set(bashId, backgroundProcess);
2796
+ return { bashId };
2549
2797
  }
2550
- try {
2551
- this.currentProcess?.kill();
2552
- } catch {
2798
+ getBackgroundOutput(shellId) {
2799
+ const proc = this.backgroundProcesses.get(shellId);
2800
+ if (!proc) return null;
2801
+ const running = proc.code === null && !proc.interrupted;
2802
+ return {
2803
+ stdout: proc.stdout,
2804
+ stderr: proc.stderr,
2805
+ code: proc.code,
2806
+ interrupted: proc.interrupted,
2807
+ killed: proc.killed,
2808
+ timedOut: proc.timedOut,
2809
+ running,
2810
+ command: proc.command,
2811
+ cwd: proc.cwd,
2812
+ startedAt: proc.startedAt,
2813
+ timeoutAt: proc.timeoutAt,
2814
+ outputFile: proc.outputFile
2815
+ };
2553
2816
  }
2554
- };
2555
- if (abortSignal) {
2556
- abortSignal.addEventListener("abort", onAbort, { once: true });
2557
- }
2558
- const sandbox = options?.sandbox;
2559
- const shouldAttemptSandbox = sandbox?.enabled === true;
2560
- const executionCwd = shouldAttemptSandbox && sandbox?.chdir ? sandbox.chdir : this.cwd;
2561
- const runOnce = async (cmd, cwdOverride) => {
2562
- this.currentProcess = spawnWithExited({
2563
- cmd,
2564
- cwd: cwdOverride ?? executionCwd
2565
- });
2566
- const stdoutCollector = this.createCancellableTextCollector(
2567
- this.currentProcess.stdout,
2568
- { onChunk: options?.onStdoutChunk }
2569
- );
2570
- const stderrCollector = this.createCancellableTextCollector(
2571
- this.currentProcess.stderr,
2572
- { onChunk: options?.onStderrChunk }
2573
- );
2574
- let timeoutHandle = null;
2575
- const timeoutPromise = new Promise((resolve3) => {
2576
- timeoutHandle = setTimeout(() => resolve3("timeout"), commandTimeout);
2577
- });
2578
- const result = await Promise.race([
2579
- this.currentProcess.exited.then(() => "completed"),
2580
- timeoutPromise
2581
- ]);
2582
- if (timeoutHandle) clearTimeout(timeoutHandle);
2583
- if (result === "timeout") {
2584
- try {
2585
- this.currentProcess.kill();
2586
- } catch {
2587
- }
2588
- try {
2589
- this.abortController.abort();
2590
- } catch {
2591
- }
2592
- try {
2593
- await this.currentProcess.exited;
2594
- } catch {
2817
+ readBackgroundOutput(bashId, options) {
2818
+ const proc = this.backgroundProcesses.get(bashId);
2819
+ if (!proc) return null;
2820
+ const stdoutDelta = proc.stdout.slice(proc.stdoutCursor);
2821
+ const stderrDelta = proc.stderr.slice(proc.stderrCursor);
2822
+ proc.stdoutCursor = proc.stdout.length;
2823
+ proc.stderrCursor = proc.stderr.length;
2824
+ const stdoutLines = stdoutDelta === "" ? 0 : stdoutDelta.split("\n").length;
2825
+ const stderrLines = stderrDelta === "" ? 0 : stderrDelta.split("\n").length;
2826
+ let stdoutToReturn = stdoutDelta;
2827
+ let stderrToReturn = stderrDelta;
2828
+ const filter = options?.filter?.trim();
2829
+ if (filter) {
2830
+ const regex = new RegExp(filter, "i");
2831
+ stdoutToReturn = stdoutDelta.split("\n").filter((line) => regex.test(line)).join("\n");
2832
+ stderrToReturn = stderrDelta.split("\n").filter((line) => regex.test(line)).join("\n");
2595
2833
  }
2596
- await Promise.race([
2597
- Promise.allSettled([stdoutCollector.done, stderrCollector.done]),
2598
- new Promise((resolve3) => setTimeout(resolve3, 250))
2599
- ]);
2600
- await Promise.allSettled([
2601
- stdoutCollector.cancel(),
2602
- stderrCollector.cancel()
2603
- ]);
2834
+ const status = proc.killed ? "killed" : proc.code === null ? "running" : proc.code === 0 ? "completed" : "failed";
2604
2835
  return {
2605
- stdout: "",
2606
- stderr: "Command timed out",
2607
- code: 143,
2608
- interrupted: true
2836
+ shellId: bashId,
2837
+ command: proc.command,
2838
+ cwd: proc.cwd,
2839
+ startedAt: proc.startedAt,
2840
+ timeoutAt: proc.timeoutAt,
2841
+ status,
2842
+ exitCode: proc.code,
2843
+ stdout: stdoutToReturn,
2844
+ stderr: stderrToReturn,
2845
+ stdoutLines,
2846
+ stderrLines,
2847
+ ...filter ? { filterPattern: filter } : {}
2609
2848
  };
2610
2849
  }
2611
- await Promise.race([
2612
- Promise.allSettled([stdoutCollector.done, stderrCollector.done]),
2613
- new Promise((resolve3) => setTimeout(resolve3, 250))
2614
- ]);
2615
- await Promise.allSettled([
2616
- stdoutCollector.cancel(),
2617
- stderrCollector.cancel()
2618
- ]);
2619
- const stdout = stdoutCollector.getText();
2620
- const stderr = stderrCollector.getText();
2621
- const interrupted = wasAborted || abortSignal?.aborted === true || this.abortController?.signal.aborted === true;
2622
- const exitCode = this.currentProcess.exitCode ?? (interrupted ? 143 : 0);
2623
- return {
2624
- stdout,
2625
- stderr,
2626
- code: exitCode,
2627
- interrupted
2628
- };
2629
- };
2630
- try {
2631
- if (shouldAttemptSandbox) {
2632
- const sandboxCmd = this.buildSandboxCmd(command, sandbox);
2633
- if (!sandboxCmd) {
2634
- if (sandbox?.require) {
2635
- return {
2636
- stdout: "",
2637
- stderr: "System sandbox is required but unavailable (missing bubblewrap or unsupported platform).",
2638
- code: 2,
2639
- interrupted: false
2640
- };
2850
+ killBackgroundShell(shellId) {
2851
+ const proc = this.backgroundProcesses.get(shellId);
2852
+ if (!proc) return false;
2853
+ try {
2854
+ proc.interrupted = true;
2855
+ proc.killed = true;
2856
+ proc.abortController.abort();
2857
+ proc.process.kill();
2858
+ if (proc.timeoutHandle) {
2859
+ clearTimeout(proc.timeoutHandle);
2860
+ proc.timeoutHandle = null;
2641
2861
  }
2642
- const fallback = await runOnce(this.getShellCmd(command));
2643
- return {
2644
- ...fallback,
2645
- stderr: `[sandbox] unavailable, ran without isolation.
2646
- ${fallback.stderr}`.trim()
2647
- };
2862
+ return true;
2863
+ } catch {
2864
+ return false;
2648
2865
  }
2649
- const sandboxed = await runOnce(sandboxCmd.cmd);
2650
- sandboxed.stderr = maybeAnnotateMacosSandboxStderr(
2651
- sandboxed.stderr,
2652
- sandbox
2653
- );
2654
- if (!sandboxed.interrupted && sandboxed.code !== 0 && this.isSandboxInitFailure(sandboxed.stderr) && !sandbox?.require) {
2655
- const fallback = await runOnce(this.getShellCmd(command));
2656
- return {
2657
- ...fallback,
2658
- stderr: `[sandbox] failed to start, ran without isolation.
2659
- ${fallback.stderr}`.trim()
2660
- };
2866
+ }
2867
+ listBackgroundShells() {
2868
+ return Array.from(this.backgroundProcesses.values());
2869
+ }
2870
+ pwd() {
2871
+ return this.cwd;
2872
+ }
2873
+ async setCwd(cwd2) {
2874
+ const resolved = isAbsolute2(cwd2) ? cwd2 : resolve2(this.cwd, cwd2);
2875
+ if (!existsSync4(resolved)) {
2876
+ throw new Error(`Path "${resolved}" does not exist`);
2661
2877
  }
2662
- return sandboxed;
2878
+ this.cwd = resolved;
2663
2879
  }
2664
- return await runOnce(this.getShellCmd(command));
2665
- } catch (error) {
2666
- if (this.abortController.signal.aborted) {
2880
+ killChildren() {
2881
+ this.abortController?.abort();
2667
2882
  this.currentProcess?.kill();
2668
- return {
2669
- stdout: "",
2670
- stderr: "Command was interrupted",
2671
- code: 143,
2672
- interrupted: true
2673
- };
2883
+ for (const bg of Array.from(this.backgroundProcesses.keys())) {
2884
+ this.killBackgroundShell(bg);
2885
+ }
2674
2886
  }
2675
- const errorStr = error instanceof Error ? error.message : String(error);
2676
- logError(`Shell execution error: ${errorStr}`);
2677
- return {
2678
- stdout: "",
2679
- stderr: errorStr,
2680
- code: 2,
2681
- interrupted: false
2682
- };
2683
- } finally {
2684
- if (abortSignal) {
2685
- abortSignal.removeEventListener("abort", onAbort);
2887
+ close() {
2888
+ this.isAlive = false;
2889
+ this.killChildren();
2686
2890
  }
2687
- this.currentProcess = null;
2688
- this.abortController = null;
2689
- }
2690
- }
2691
- execInBackground(command, timeout, options) {
2692
- const DEFAULT_TIMEOUT = 12e4;
2693
- const commandTimeout = timeout ?? DEFAULT_TIMEOUT;
2694
- const abortController = new AbortController();
2695
- const sandbox = options?.sandbox;
2696
- const sandboxCmd = sandbox?.enabled === true ? this.buildSandboxCmd(command, sandbox) : null;
2697
- const executionCwd = sandbox?.enabled === true && sandbox?.chdir ? sandbox.chdir : this.cwd;
2698
- if (sandbox?.enabled === true && sandbox?.require && !sandboxCmd) {
2699
- throw new Error(
2700
- "System sandbox is required but unavailable (missing bubblewrap or unsupported platform)."
2701
- );
2702
- }
2703
- const cmdToRun = sandboxCmd ? sandboxCmd.cmd : this.getShellCmd(command);
2704
- const bashId = _BunShell.makeBackgroundTaskId();
2705
- const outputFile = touchTaskOutputFile(bashId);
2706
- const process2 = spawnWithExited({ cmd: cmdToRun, cwd: executionCwd });
2707
- const timeoutHandle = setTimeout(() => {
2708
- abortController.abort();
2709
- backgroundProcess.timedOut = true;
2710
- process2.kill();
2711
- }, commandTimeout);
2712
- const backgroundProcess = {
2713
- id: bashId,
2714
- command,
2715
- stdout: "",
2716
- stderr: "",
2717
- stdoutCursor: 0,
2718
- stderrCursor: 0,
2719
- stdoutLineCount: 0,
2720
- stderrLineCount: 0,
2721
- lastReportedStdoutLines: 0,
2722
- lastReportedStderrLines: 0,
2723
- code: null,
2724
- interrupted: false,
2725
- killed: false,
2726
- timedOut: false,
2727
- completionStatusSentInAttachment: false,
2728
- notified: false,
2729
- startedAt: Date.now(),
2730
- timeoutAt: Date.now() + commandTimeout,
2731
- process: process2,
2732
- abortController,
2733
- timeoutHandle,
2734
- cwd: executionCwd,
2735
- outputFile
2736
- };
2737
- const countNonEmptyLines = (chunk) => chunk.split("\n").filter((line) => line.length > 0).length;
2738
- this.startStreamReader(process2.stdout, (chunk) => {
2739
- backgroundProcess.stdout += chunk;
2740
- appendTaskOutput(bashId, chunk);
2741
- backgroundProcess.stdoutLineCount += countNonEmptyLines(chunk);
2742
- });
2743
- this.startStreamReader(process2.stderr, (chunk) => {
2744
- backgroundProcess.stderr += chunk;
2745
- appendTaskOutput(bashId, chunk);
2746
- backgroundProcess.stderrLineCount += countNonEmptyLines(chunk);
2747
- });
2748
- process2.exited.then(() => {
2749
- backgroundProcess.code = process2.exitCode ?? 0;
2750
- backgroundProcess.interrupted = backgroundProcess.interrupted || abortController.signal.aborted;
2751
- if (sandbox?.enabled === true) {
2752
- backgroundProcess.stderr = maybeAnnotateMacosSandboxStderr(
2753
- backgroundProcess.stderr,
2754
- sandbox
2755
- );
2891
+ flushBashNotifications() {
2892
+ const processes = Array.from(this.backgroundProcesses.values());
2893
+ const statusFor = (proc) => proc.killed ? "killed" : proc.code === null ? "running" : proc.code === 0 ? "completed" : "failed";
2894
+ const notifications = [];
2895
+ for (const proc of processes) {
2896
+ if (proc.notified) continue;
2897
+ const status = statusFor(proc);
2898
+ if (status === "running") continue;
2899
+ notifications.push({
2900
+ type: "bash_notification",
2901
+ taskId: proc.id,
2902
+ description: proc.command,
2903
+ outputFile: proc.outputFile || getTaskOutputFilePath(proc.id),
2904
+ status,
2905
+ ...proc.code !== null ? { exitCode: proc.code } : {}
2906
+ });
2907
+ proc.notified = true;
2908
+ }
2909
+ return notifications;
2756
2910
  }
2757
- if (backgroundProcess.timeoutHandle) {
2758
- clearTimeout(backgroundProcess.timeoutHandle);
2759
- backgroundProcess.timeoutHandle = null;
2911
+ flushBackgroundShellStatusAttachments() {
2912
+ const processes = Array.from(this.backgroundProcesses.values());
2913
+ const statusFor = (proc) => proc.killed ? "killed" : proc.code === null ? "running" : proc.code === 0 ? "completed" : "failed";
2914
+ const progressAttachments = [];
2915
+ for (const proc of processes) {
2916
+ if (statusFor(proc) !== "running") continue;
2917
+ const stdoutDelta = proc.stdoutLineCount - proc.lastReportedStdoutLines;
2918
+ const stderrDelta = proc.stderrLineCount - proc.lastReportedStderrLines;
2919
+ if (stdoutDelta === 0 && stderrDelta === 0) continue;
2920
+ proc.lastReportedStdoutLines = proc.stdoutLineCount;
2921
+ proc.lastReportedStderrLines = proc.stderrLineCount;
2922
+ progressAttachments.push({
2923
+ type: "task_progress",
2924
+ taskId: proc.id,
2925
+ stdoutLineDelta: stdoutDelta,
2926
+ stderrLineDelta: stderrDelta,
2927
+ outputFile: proc.outputFile || getTaskOutputFilePath(proc.id)
2928
+ });
2929
+ }
2930
+ return progressAttachments;
2760
2931
  }
2761
- });
2762
- this.backgroundProcesses.set(bashId, backgroundProcess);
2763
- return { bashId };
2764
- }
2765
- getBackgroundOutput(shellId) {
2766
- const proc = this.backgroundProcesses.get(shellId);
2767
- if (!proc) return null;
2768
- const running = proc.code === null && !proc.interrupted;
2769
- return {
2770
- stdout: proc.stdout,
2771
- stderr: proc.stderr,
2772
- code: proc.code,
2773
- interrupted: proc.interrupted,
2774
- killed: proc.killed,
2775
- timedOut: proc.timedOut,
2776
- running,
2777
- command: proc.command,
2778
- cwd: proc.cwd,
2779
- startedAt: proc.startedAt,
2780
- timeoutAt: proc.timeoutAt,
2781
- outputFile: proc.outputFile
2782
2932
  };
2783
2933
  }
2784
- readBackgroundOutput(bashId, options) {
2785
- const proc = this.backgroundProcesses.get(bashId);
2786
- if (!proc) return null;
2787
- const stdoutDelta = proc.stdout.slice(proc.stdoutCursor);
2788
- const stderrDelta = proc.stderr.slice(proc.stderrCursor);
2789
- proc.stdoutCursor = proc.stdout.length;
2790
- proc.stderrCursor = proc.stderr.length;
2791
- const stdoutLines = stdoutDelta === "" ? 0 : stdoutDelta.split("\n").length;
2792
- const stderrLines = stderrDelta === "" ? 0 : stderrDelta.split("\n").length;
2793
- let stdoutToReturn = stdoutDelta;
2794
- let stderrToReturn = stderrDelta;
2795
- const filter = options?.filter?.trim();
2796
- if (filter) {
2797
- const regex = new RegExp(filter, "i");
2798
- stdoutToReturn = stdoutDelta.split("\n").filter((line) => regex.test(line)).join("\n");
2799
- stderrToReturn = stderrDelta.split("\n").filter((line) => regex.test(line)).join("\n");
2800
- }
2801
- const status = proc.killed ? "killed" : proc.code === null ? "running" : proc.code === 0 ? "completed" : "failed";
2802
- return {
2803
- shellId: bashId,
2804
- command: proc.command,
2805
- cwd: proc.cwd,
2806
- startedAt: proc.startedAt,
2807
- timeoutAt: proc.timeoutAt,
2808
- status,
2809
- exitCode: proc.code,
2810
- stdout: stdoutToReturn,
2811
- stderr: stderrToReturn,
2812
- stdoutLines,
2813
- stderrLines,
2814
- ...filter ? { filterPattern: filter } : {}
2815
- };
2816
- }
2817
- killBackgroundShell(shellId) {
2818
- const proc = this.backgroundProcesses.get(shellId);
2819
- if (!proc) return false;
2820
- try {
2821
- proc.interrupted = true;
2822
- proc.killed = true;
2823
- proc.abortController.abort();
2824
- proc.process.kill();
2825
- if (proc.timeoutHandle) {
2826
- clearTimeout(proc.timeoutHandle);
2827
- proc.timeoutHandle = null;
2828
- }
2829
- return true;
2830
- } catch {
2831
- return false;
2832
- }
2833
- }
2834
- listBackgroundShells() {
2835
- return Array.from(this.backgroundProcesses.values());
2836
- }
2837
- pwd() {
2838
- return this.cwd;
2839
- }
2840
- async setCwd(cwd2) {
2841
- const resolved = isAbsolute2(cwd2) ? cwd2 : resolve2(this.cwd, cwd2);
2842
- if (!existsSync4(resolved)) {
2843
- throw new Error(`Path "${resolved}" does not exist`);
2844
- }
2845
- this.cwd = resolved;
2846
- }
2847
- killChildren() {
2848
- this.abortController?.abort();
2849
- this.currentProcess?.kill();
2850
- for (const bg of Array.from(this.backgroundProcesses.keys())) {
2851
- this.killBackgroundShell(bg);
2852
- }
2853
- }
2854
- close() {
2855
- this.isAlive = false;
2856
- this.killChildren();
2857
- }
2858
- flushBashNotifications() {
2859
- const processes = Array.from(this.backgroundProcesses.values());
2860
- const statusFor = (proc) => proc.killed ? "killed" : proc.code === null ? "running" : proc.code === 0 ? "completed" : "failed";
2861
- const notifications = [];
2862
- for (const proc of processes) {
2863
- if (proc.notified) continue;
2864
- const status = statusFor(proc);
2865
- if (status === "running") continue;
2866
- notifications.push({
2867
- type: "bash_notification",
2868
- taskId: proc.id,
2869
- description: proc.command,
2870
- outputFile: proc.outputFile || getTaskOutputFilePath(proc.id),
2871
- status,
2872
- ...proc.code !== null ? { exitCode: proc.code } : {}
2873
- });
2874
- proc.notified = true;
2875
- }
2876
- return notifications;
2877
- }
2878
- flushBackgroundShellStatusAttachments() {
2879
- const processes = Array.from(this.backgroundProcesses.values());
2880
- const statusFor = (proc) => proc.killed ? "killed" : proc.code === null ? "running" : proc.code === 0 ? "completed" : "failed";
2881
- const progressAttachments = [];
2882
- for (const proc of processes) {
2883
- if (statusFor(proc) !== "running") continue;
2884
- const stdoutDelta = proc.stdoutLineCount - proc.lastReportedStdoutLines;
2885
- const stderrDelta = proc.stderrLineCount - proc.lastReportedStderrLines;
2886
- if (stdoutDelta === 0 && stderrDelta === 0) continue;
2887
- proc.lastReportedStdoutLines = proc.stdoutLineCount;
2888
- proc.lastReportedStderrLines = proc.stderrLineCount;
2889
- progressAttachments.push({
2890
- type: "task_progress",
2891
- taskId: proc.id,
2892
- stdoutLineDelta: stdoutDelta,
2893
- stderrLineDelta: stderrDelta,
2894
- outputFile: proc.outputFile || getTaskOutputFilePath(proc.id)
2895
- });
2896
- }
2897
- return progressAttachments;
2898
- }
2899
- };
2934
+ });
2900
2935
 
2901
2936
  // src/utils/state/index.ts
2902
- var STATE = {
2903
- originalCwd: cwd()
2904
- };
2937
+ import { cwd } from "process";
2905
2938
  async function setCwd(cwd2) {
2906
2939
  await BunShell.getInstance().setCwd(cwd2);
2907
2940
  }
@@ -2914,37 +2947,47 @@ function getOriginalCwd() {
2914
2947
  function getCwd() {
2915
2948
  return BunShell.getInstance().pwd();
2916
2949
  }
2950
+ var STATE;
2951
+ var init_state = __esm({
2952
+ "src/utils/state/index.ts"() {
2953
+ init_shell();
2954
+ STATE = {
2955
+ originalCwd: cwd()
2956
+ };
2957
+ }
2958
+ });
2917
2959
 
2918
2960
  export {
2919
2961
  initSentry,
2920
2962
  captureException,
2921
- PRODUCT_NAME,
2922
- PROJECT_FILE,
2923
- PRODUCT_COMMAND,
2924
- CONFIG_BASE_DIR,
2925
- GITHUB_ISSUES_REPO_URL,
2926
- ASCII_LOGO,
2963
+ init_sentry,
2927
2964
  getTaskOutputFilePath,
2928
2965
  readTaskOutput,
2966
+ init_taskOutputStore,
2929
2967
  detectRuntimeShell,
2930
2968
  renderBackgroundShellStatusAttachment,
2931
2969
  renderBashNotification,
2932
2970
  BunShell,
2971
+ init_shell,
2933
2972
  setCwd,
2934
2973
  setOriginalCwd,
2935
2974
  getOriginalCwd,
2936
2975
  getCwd,
2976
+ init_state,
2937
2977
  execFileNoThrow,
2938
- getKodeBaseDir,
2978
+ init_execFileNoThrow,
2979
+ getNewcrawBaseDir,
2939
2980
  getGlobalConfigFilePath,
2940
2981
  getMemoryDir,
2941
2982
  NEWCRAW_BASE_DIR,
2942
2983
  GLOBAL_CONFIG_FILE,
2943
2984
  MEMORY_DIR,
2944
2985
  env,
2986
+ init_env,
2945
2987
  PLAN_SLUG_ADJECTIVES,
2946
2988
  PLAN_SLUG_VERBS,
2947
2989
  PLAN_SLUG_NOUNS,
2990
+ init_planSlugWords,
2948
2991
  getPlanConversationKey,
2949
2992
  setActivePlanConversationKey,
2950
2993
  getPlanModeSystemPromptAdditions,
@@ -2955,6 +2998,7 @@ export {
2955
2998
  getPlanFilePath,
2956
2999
  isMainPlanFilePathForActiveConversation,
2957
3000
  readPlanFile,
3001
+ init_planMode,
2958
3002
  SESSION_ID,
2959
3003
  CACHE_PATHS,
2960
3004
  dateToFilename,
@@ -2966,5 +3010,6 @@ export {
2966
3010
  getNextAvailableLogForkNumber,
2967
3011
  getNextAvailableLogSidechainNumber,
2968
3012
  formatDate,
2969
- logMCPError
3013
+ logMCPError,
3014
+ init_log
2970
3015
  };