@machina.ai/cell-cli 1.0.17-rc1 → 1.0.21-rc1

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 (490) hide show
  1. package/dist/package.json +11 -8
  2. package/dist/src/commands/mcp/add.d.ts +7 -0
  3. package/dist/src/commands/mcp/add.js +166 -0
  4. package/dist/src/commands/mcp/add.js.map +1 -0
  5. package/dist/src/commands/mcp/list.d.ts +8 -0
  6. package/dist/src/commands/mcp/list.js +110 -0
  7. package/dist/src/commands/mcp/list.js.map +1 -0
  8. package/dist/src/commands/mcp/remove.d.ts +7 -0
  9. package/dist/src/commands/mcp/remove.js +44 -0
  10. package/dist/src/commands/mcp/remove.js.map +1 -0
  11. package/dist/src/commands/mcp.d.ts +7 -0
  12. package/dist/src/commands/mcp.js +23 -0
  13. package/dist/src/commands/mcp.js.map +1 -0
  14. package/dist/src/config/auth.test.d.ts +6 -0
  15. package/dist/src/config/auth.test.js +28 -0
  16. package/dist/src/config/auth.test.js.map +1 -0
  17. package/dist/src/config/config.d.ts +3 -3
  18. package/dist/src/config/config.js +138 -69
  19. package/dist/src/config/config.js.map +1 -1
  20. package/dist/src/config/keyBindings.d.ts +66 -0
  21. package/dist/src/config/keyBindings.js +141 -0
  22. package/dist/src/config/keyBindings.js.map +1 -0
  23. package/dist/src/config/keyBindings.test.d.ts +6 -0
  24. package/dist/src/config/keyBindings.test.js +51 -0
  25. package/dist/src/config/keyBindings.test.js.map +1 -0
  26. package/dist/src/config/sandboxConfig.js +3 -3
  27. package/dist/src/config/sandboxConfig.js.map +1 -1
  28. package/dist/src/config/settings.d.ts +3 -54
  29. package/dist/src/config/settings.js +58 -38
  30. package/dist/src/config/settings.js.map +1 -1
  31. package/dist/src/config/settingsSchema.d.ts +533 -0
  32. package/dist/src/config/settingsSchema.js +507 -0
  33. package/dist/src/config/settingsSchema.js.map +1 -0
  34. package/dist/src/config/settingsSchema.test.d.ts +6 -0
  35. package/dist/src/config/settingsSchema.test.js +195 -0
  36. package/dist/src/config/settingsSchema.test.js.map +1 -0
  37. package/dist/src/config/trustedFolders.d.ts +37 -0
  38. package/dist/src/config/trustedFolders.js +118 -0
  39. package/dist/src/config/trustedFolders.js.map +1 -0
  40. package/dist/src/config/trustedFolders.test.d.ts +6 -0
  41. package/dist/src/config/trustedFolders.test.js +160 -0
  42. package/dist/src/config/trustedFolders.test.js.map +1 -0
  43. package/dist/src/gemini.js +54 -37
  44. package/dist/src/gemini.js.map +1 -1
  45. package/dist/src/gemini.test.d.ts +6 -0
  46. package/dist/src/gemini.test.js +193 -0
  47. package/dist/src/gemini.test.js.map +1 -0
  48. package/dist/src/generated/git-commit.d.ts +2 -1
  49. package/dist/src/generated/git-commit.js +2 -1
  50. package/dist/src/generated/git-commit.js.map +1 -1
  51. package/dist/src/nonInteractiveCli.js +22 -17
  52. package/dist/src/nonInteractiveCli.js.map +1 -1
  53. package/dist/src/services/BuiltinCommandLoader.js +5 -2
  54. package/dist/src/services/BuiltinCommandLoader.js.map +1 -1
  55. package/dist/src/services/BuiltinCommandLoader.test.d.ts +6 -0
  56. package/dist/src/services/BuiltinCommandLoader.test.js +108 -0
  57. package/dist/src/services/BuiltinCommandLoader.test.js.map +1 -0
  58. package/dist/src/services/CommandService.test.d.ts +6 -0
  59. package/dist/src/services/CommandService.test.js +232 -0
  60. package/dist/src/services/CommandService.test.js.map +1 -0
  61. package/dist/src/services/FileCommandLoader.js +10 -8
  62. package/dist/src/services/FileCommandLoader.js.map +1 -1
  63. package/dist/src/services/McpPromptLoader.js +3 -3
  64. package/dist/src/services/McpPromptLoader.js.map +1 -1
  65. package/dist/src/services/prompt-processors/argumentProcessor.d.ts +2 -7
  66. package/dist/src/services/prompt-processors/argumentProcessor.js +2 -10
  67. package/dist/src/services/prompt-processors/argumentProcessor.js.map +1 -1
  68. package/dist/src/services/prompt-processors/shellProcessor.d.ts +16 -13
  69. package/dist/src/services/prompt-processors/shellProcessor.js +133 -40
  70. package/dist/src/services/prompt-processors/shellProcessor.js.map +1 -1
  71. package/dist/src/services/prompt-processors/types.d.ts +2 -0
  72. package/dist/src/services/prompt-processors/types.js +2 -0
  73. package/dist/src/services/prompt-processors/types.js.map +1 -1
  74. package/dist/src/test-utils/customMatchers.d.ts +14 -0
  75. package/dist/src/test-utils/customMatchers.js +46 -0
  76. package/dist/src/test-utils/customMatchers.js.map +1 -0
  77. package/dist/src/test-utils/mockCommandContext.d.ts +18 -0
  78. package/dist/src/test-utils/mockCommandContext.js +86 -0
  79. package/dist/src/test-utils/mockCommandContext.js.map +1 -0
  80. package/dist/src/test-utils/mockCommandContext.test.d.ts +6 -0
  81. package/dist/src/test-utils/mockCommandContext.test.js +51 -0
  82. package/dist/src/test-utils/mockCommandContext.test.js.map +1 -0
  83. package/dist/src/test-utils/render.d.ts +8 -0
  84. package/dist/src/test-utils/render.js +10 -0
  85. package/dist/src/test-utils/render.js.map +1 -0
  86. package/dist/src/ui/App.js +146 -37
  87. package/dist/src/ui/App.js.map +1 -1
  88. package/dist/src/ui/IdeIntegrationNudge.d.ts +16 -0
  89. package/dist/src/ui/IdeIntegrationNudge.js +52 -0
  90. package/dist/src/ui/IdeIntegrationNudge.js.map +1 -0
  91. package/dist/src/ui/commands/aboutCommand.js +9 -5
  92. package/dist/src/ui/commands/aboutCommand.js.map +1 -1
  93. package/dist/src/ui/commands/bugCommand.js +13 -5
  94. package/dist/src/ui/commands/bugCommand.js.map +1 -1
  95. package/dist/src/ui/commands/chatCommand.js +23 -6
  96. package/dist/src/ui/commands/chatCommand.js.map +1 -1
  97. package/dist/src/ui/commands/directoryCommand.js +2 -4
  98. package/dist/src/ui/commands/directoryCommand.js.map +1 -1
  99. package/dist/src/ui/commands/docsCommand.js +1 -1
  100. package/dist/src/ui/commands/docsCommand.js.map +1 -1
  101. package/dist/src/ui/commands/ideCommand.js +110 -42
  102. package/dist/src/ui/commands/ideCommand.js.map +1 -1
  103. package/dist/src/ui/commands/mcpCommand.js +7 -3
  104. package/dist/src/ui/commands/mcpCommand.js.map +1 -1
  105. package/dist/src/ui/commands/settingsCommand.d.ts +7 -0
  106. package/dist/src/ui/commands/settingsCommand.js +16 -0
  107. package/dist/src/ui/commands/settingsCommand.js.map +1 -0
  108. package/dist/src/ui/commands/setupGithubCommand.js +86 -19
  109. package/dist/src/ui/commands/setupGithubCommand.js.map +1 -1
  110. package/dist/src/ui/commands/setupGithubCommand.test.d.ts +6 -0
  111. package/dist/src/ui/commands/setupGithubCommand.test.js +74 -0
  112. package/dist/src/ui/commands/setupGithubCommand.test.js.map +1 -0
  113. package/dist/src/ui/commands/terminalSetupCommand.d.ts +13 -0
  114. package/dist/src/ui/commands/terminalSetupCommand.js +41 -0
  115. package/dist/src/ui/commands/terminalSetupCommand.js.map +1 -0
  116. package/dist/src/ui/commands/types.d.ts +14 -2
  117. package/dist/src/ui/commands/types.js.map +1 -1
  118. package/dist/src/ui/components/AboutBox.d.ts +1 -0
  119. package/dist/src/ui/components/AboutBox.js +1 -1
  120. package/dist/src/ui/components/AboutBox.js.map +1 -1
  121. package/dist/src/ui/components/AsciiArt.d.ts +2 -1
  122. package/dist/src/ui/components/AsciiArt.js +22 -11
  123. package/dist/src/ui/components/AsciiArt.js.map +1 -1
  124. package/dist/src/ui/components/AuthDialog.js +12 -6
  125. package/dist/src/ui/components/AuthDialog.js.map +1 -1
  126. package/dist/src/ui/components/AuthDialog.test.d.ts +6 -0
  127. package/dist/src/ui/components/AuthDialog.test.js +114 -0
  128. package/dist/src/ui/components/AuthDialog.test.js.map +1 -0
  129. package/dist/src/ui/components/AuthInProgress.js +5 -4
  130. package/dist/src/ui/components/AuthInProgress.js.map +1 -1
  131. package/dist/src/ui/components/ContextSummaryDisplay.js +22 -25
  132. package/dist/src/ui/components/ContextSummaryDisplay.js.map +1 -1
  133. package/dist/src/ui/components/ContextUsageDisplay.d.ts +9 -0
  134. package/dist/src/ui/components/ContextUsageDisplay.js +14 -0
  135. package/dist/src/ui/components/ContextUsageDisplay.js.map +1 -0
  136. package/dist/src/ui/components/DebugProfiler.js +5 -4
  137. package/dist/src/ui/components/DebugProfiler.js.map +1 -1
  138. package/dist/src/ui/components/EditorSettingsDialog.js +6 -5
  139. package/dist/src/ui/components/EditorSettingsDialog.js.map +1 -1
  140. package/dist/src/ui/components/FolderTrustDialog.d.ts +16 -0
  141. package/dist/src/ui/components/FolderTrustDialog.js +39 -0
  142. package/dist/src/ui/components/FolderTrustDialog.js.map +1 -0
  143. package/dist/src/ui/components/FolderTrustDialog.test.d.ts +6 -0
  144. package/dist/src/ui/components/FolderTrustDialog.test.js +26 -0
  145. package/dist/src/ui/components/FolderTrustDialog.test.js.map +1 -0
  146. package/dist/src/ui/components/Footer.d.ts +1 -0
  147. package/dist/src/ui/components/Footer.js +16 -6
  148. package/dist/src/ui/components/Footer.js.map +1 -1
  149. package/dist/src/ui/components/Header.d.ts +0 -1
  150. package/dist/src/ui/components/Header.js +13 -5
  151. package/dist/src/ui/components/Header.js.map +1 -1
  152. package/dist/src/ui/components/Header.test.d.ts +6 -0
  153. package/dist/src/ui/components/Header.test.js +44 -0
  154. package/dist/src/ui/components/Header.test.js.map +1 -0
  155. package/dist/src/ui/components/HistoryItemDisplay.js +1 -1
  156. package/dist/src/ui/components/HistoryItemDisplay.js.map +1 -1
  157. package/dist/src/ui/components/HistoryItemDisplay.test.d.ts +6 -0
  158. package/dist/src/ui/components/HistoryItemDisplay.test.js +91 -0
  159. package/dist/src/ui/components/HistoryItemDisplay.test.js.map +1 -0
  160. package/dist/src/ui/components/InputPrompt.d.ts +1 -0
  161. package/dist/src/ui/components/InputPrompt.js +98 -35
  162. package/dist/src/ui/components/InputPrompt.js.map +1 -1
  163. package/dist/src/ui/components/LoadingIndicator.js +10 -5
  164. package/dist/src/ui/components/LoadingIndicator.js.map +1 -1
  165. package/dist/src/ui/components/LoadingIndicator.test.d.ts +6 -0
  166. package/dist/src/ui/components/LoadingIndicator.test.js +190 -0
  167. package/dist/src/ui/components/LoadingIndicator.test.js.map +1 -0
  168. package/dist/src/ui/components/SettingsDialog.d.ts +14 -0
  169. package/dist/src/ui/components/SettingsDialog.js +519 -0
  170. package/dist/src/ui/components/SettingsDialog.js.map +1 -0
  171. package/dist/src/ui/components/SettingsDialog.test.d.ts +6 -0
  172. package/dist/src/ui/components/SettingsDialog.test.js +568 -0
  173. package/dist/src/ui/components/SettingsDialog.test.js.map +1 -0
  174. package/dist/src/ui/components/ShellConfirmationDialog.js +7 -5
  175. package/dist/src/ui/components/ShellConfirmationDialog.js.map +1 -1
  176. package/dist/src/ui/components/ShellConfirmationDialog.test.d.ts +6 -0
  177. package/dist/src/ui/components/ShellConfirmationDialog.test.js +40 -0
  178. package/dist/src/ui/components/ShellConfirmationDialog.test.js.map +1 -0
  179. package/dist/src/ui/components/StatsDisplay.js +8 -7
  180. package/dist/src/ui/components/StatsDisplay.js.map +1 -1
  181. package/dist/src/ui/components/SuggestionsDisplay.js +1 -1
  182. package/dist/src/ui/components/SuggestionsDisplay.js.map +1 -1
  183. package/dist/src/ui/components/ThemeDialog.js +10 -20
  184. package/dist/src/ui/components/ThemeDialog.js.map +1 -1
  185. package/dist/src/ui/components/messages/DiffRenderer.js +10 -1
  186. package/dist/src/ui/components/messages/DiffRenderer.js.map +1 -1
  187. package/dist/src/ui/components/messages/DiffRenderer.test.d.ts +6 -0
  188. package/dist/src/ui/components/messages/DiffRenderer.test.js +239 -0
  189. package/dist/src/ui/components/messages/DiffRenderer.test.js.map +1 -0
  190. package/dist/src/ui/components/messages/InfoMessage.js +2 -1
  191. package/dist/src/ui/components/messages/InfoMessage.js.map +1 -1
  192. package/dist/src/ui/components/messages/ToolConfirmationMessage.js +36 -14
  193. package/dist/src/ui/components/messages/ToolConfirmationMessage.js.map +1 -1
  194. package/dist/src/ui/components/messages/ToolConfirmationMessage.test.d.ts +6 -0
  195. package/dist/src/ui/components/messages/ToolConfirmationMessage.test.js +37 -0
  196. package/dist/src/ui/components/messages/ToolConfirmationMessage.test.js.map +1 -0
  197. package/dist/src/ui/components/messages/ToolMessage.test.d.ts +6 -0
  198. package/dist/src/ui/components/messages/ToolMessage.test.js +118 -0
  199. package/dist/src/ui/components/messages/ToolMessage.test.js.map +1 -0
  200. package/dist/src/ui/components/shared/MaxSizedBox.js +1 -1
  201. package/dist/src/ui/components/shared/MaxSizedBox.js.map +1 -1
  202. package/dist/src/ui/components/shared/MaxSizedBox.test.d.ts +6 -0
  203. package/dist/src/ui/components/shared/MaxSizedBox.test.js +154 -0
  204. package/dist/src/ui/components/shared/MaxSizedBox.test.js.map +1 -0
  205. package/dist/src/ui/components/shared/RadioButtonSelect.js +11 -9
  206. package/dist/src/ui/components/shared/RadioButtonSelect.js.map +1 -1
  207. package/dist/src/ui/components/shared/RadioButtonSelect.test.d.ts +6 -0
  208. package/dist/src/ui/components/shared/RadioButtonSelect.test.js +111 -0
  209. package/dist/src/ui/components/shared/RadioButtonSelect.test.js.map +1 -0
  210. package/dist/src/ui/components/shared/text-buffer.d.ts +17 -4
  211. package/dist/src/ui/components/shared/text-buffer.js +262 -80
  212. package/dist/src/ui/components/shared/text-buffer.js.map +1 -1
  213. package/dist/src/ui/components/shared/vim-buffer-actions.js +139 -152
  214. package/dist/src/ui/components/shared/vim-buffer-actions.js.map +1 -1
  215. package/dist/src/ui/contexts/KeypressContext.d.ts +30 -0
  216. package/dist/src/ui/contexts/KeypressContext.js +309 -0
  217. package/dist/src/ui/contexts/KeypressContext.js.map +1 -0
  218. package/dist/src/ui/contexts/KeypressContext.test.d.ts +6 -0
  219. package/dist/src/ui/contexts/KeypressContext.test.js +219 -0
  220. package/dist/src/ui/contexts/KeypressContext.test.js.map +1 -0
  221. package/dist/src/ui/contexts/SessionContext.d.ts +3 -0
  222. package/dist/src/ui/contexts/SessionContext.js +2 -1
  223. package/dist/src/ui/contexts/SessionContext.js.map +1 -1
  224. package/dist/src/ui/contexts/SettingsContext.d.ts +9 -0
  225. package/dist/src/ui/contexts/SettingsContext.js +15 -0
  226. package/dist/src/ui/contexts/SettingsContext.js.map +1 -0
  227. package/dist/src/ui/hooks/atCommandProcessor.js +16 -13
  228. package/dist/src/ui/hooks/atCommandProcessor.js.map +1 -1
  229. package/dist/src/ui/hooks/atCommandProcessor.test.d.ts +6 -0
  230. package/dist/src/ui/hooks/atCommandProcessor.test.js +809 -0
  231. package/dist/src/ui/hooks/atCommandProcessor.test.js.map +1 -0
  232. package/dist/src/ui/hooks/shellCommandProcessor.test.d.ts +6 -0
  233. package/dist/src/ui/hooks/shellCommandProcessor.test.js +328 -0
  234. package/dist/src/ui/hooks/shellCommandProcessor.test.js.map +1 -0
  235. package/dist/src/ui/hooks/slashCommandProcessor.d.ts +6 -2
  236. package/dist/src/ui/hooks/slashCommandProcessor.js +121 -57
  237. package/dist/src/ui/hooks/slashCommandProcessor.js.map +1 -1
  238. package/dist/src/ui/hooks/useAtCompletion.d.ts +23 -0
  239. package/dist/src/ui/hooks/useAtCompletion.js +178 -0
  240. package/dist/src/ui/hooks/useAtCompletion.js.map +1 -0
  241. package/dist/src/ui/hooks/useAutoAcceptIndicator.js +5 -5
  242. package/dist/src/ui/hooks/useAutoAcceptIndicator.js.map +1 -1
  243. package/dist/src/ui/hooks/useAutoAcceptIndicator.test.d.ts +6 -0
  244. package/dist/src/ui/hooks/useAutoAcceptIndicator.test.js +191 -0
  245. package/dist/src/ui/hooks/useAutoAcceptIndicator.test.js.map +1 -0
  246. package/dist/src/ui/hooks/useCommandCompletion.d.ts +6 -1
  247. package/dist/src/ui/hooks/useCommandCompletion.js +95 -383
  248. package/dist/src/ui/hooks/useCommandCompletion.js.map +1 -1
  249. package/dist/src/ui/hooks/useEditorSettings.test.d.ts +6 -0
  250. package/dist/src/ui/hooks/useEditorSettings.test.js +164 -0
  251. package/dist/src/ui/hooks/useEditorSettings.test.js.map +1 -0
  252. package/dist/src/ui/hooks/useFocus.d.ts +4 -0
  253. package/dist/src/ui/hooks/useFocus.js +4 -4
  254. package/dist/src/ui/hooks/useFocus.js.map +1 -1
  255. package/dist/src/ui/hooks/useFolderTrust.d.ts +12 -0
  256. package/dist/src/ui/hooks/useFolderTrust.js +55 -0
  257. package/dist/src/ui/hooks/useFolderTrust.js.map +1 -0
  258. package/dist/src/ui/hooks/useGeminiStream.d.ts +2 -1
  259. package/dist/src/ui/hooks/useGeminiStream.js +35 -22
  260. package/dist/src/ui/hooks/useGeminiStream.js.map +1 -1
  261. package/dist/src/ui/hooks/useGitBranchName.test.d.ts +6 -0
  262. package/dist/src/ui/hooks/useGitBranchName.test.js +175 -0
  263. package/dist/src/ui/hooks/useGitBranchName.test.js.map +1 -0
  264. package/dist/src/ui/hooks/useHistoryManager.test.d.ts +6 -0
  265. package/dist/src/ui/hooks/useHistoryManager.test.js +171 -0
  266. package/dist/src/ui/hooks/useHistoryManager.test.js.map +1 -0
  267. package/dist/src/ui/hooks/useInputHistory.test.d.ts +6 -0
  268. package/dist/src/ui/hooks/useInputHistory.test.js +207 -0
  269. package/dist/src/ui/hooks/useInputHistory.test.js.map +1 -0
  270. package/dist/src/ui/hooks/useKeypress.d.ts +4 -16
  271. package/dist/src/ui/hooks/useKeypress.js +8 -140
  272. package/dist/src/ui/hooks/useKeypress.js.map +1 -1
  273. package/dist/src/ui/hooks/useKittyKeyboardProtocol.d.ts +15 -0
  274. package/dist/src/ui/hooks/useKittyKeyboardProtocol.js +20 -0
  275. package/dist/src/ui/hooks/useKittyKeyboardProtocol.js.map +1 -0
  276. package/dist/src/ui/hooks/useLoadingIndicator.test.d.ts +6 -0
  277. package/dist/src/ui/hooks/useLoadingIndicator.test.js +91 -0
  278. package/dist/src/ui/hooks/useLoadingIndicator.test.js.map +1 -0
  279. package/dist/src/ui/hooks/useMessageQueue.d.ts +22 -0
  280. package/dist/src/ui/hooks/useMessageQueue.js +49 -0
  281. package/dist/src/ui/hooks/useMessageQueue.js.map +1 -0
  282. package/dist/src/ui/hooks/useMessageQueue.test.d.ts +6 -0
  283. package/dist/src/ui/hooks/useMessageQueue.test.js +158 -0
  284. package/dist/src/ui/hooks/useMessageQueue.test.js.map +1 -0
  285. package/dist/src/ui/hooks/usePhraseCycler.js +2 -5
  286. package/dist/src/ui/hooks/usePhraseCycler.js.map +1 -1
  287. package/dist/src/ui/hooks/usePrivacySettings.js +6 -2
  288. package/dist/src/ui/hooks/usePrivacySettings.js.map +1 -1
  289. package/dist/src/ui/hooks/usePrivacySettings.test.d.ts +6 -0
  290. package/dist/src/ui/hooks/usePrivacySettings.test.js +154 -0
  291. package/dist/src/ui/hooks/usePrivacySettings.test.js.map +1 -0
  292. package/dist/src/ui/hooks/useReactToolScheduler.d.ts +1 -1
  293. package/dist/src/ui/hooks/useReactToolScheduler.js +18 -16
  294. package/dist/src/ui/hooks/useReactToolScheduler.js.map +1 -1
  295. package/dist/src/ui/hooks/useReverseSearchCompletion.js +4 -2
  296. package/dist/src/ui/hooks/useReverseSearchCompletion.js.map +1 -1
  297. package/dist/src/ui/hooks/useReverseSearchCompletion.test.d.ts +6 -0
  298. package/dist/src/ui/hooks/useReverseSearchCompletion.test.js +163 -0
  299. package/dist/src/ui/hooks/useReverseSearchCompletion.test.js.map +1 -0
  300. package/dist/src/ui/hooks/useSettingsCommand.d.ts +10 -0
  301. package/dist/src/ui/hooks/useSettingsCommand.js +21 -0
  302. package/dist/src/ui/hooks/useSettingsCommand.js.map +1 -0
  303. package/dist/src/ui/hooks/useShellHistory.test.d.ts +6 -0
  304. package/dist/src/ui/hooks/useShellHistory.test.js +159 -0
  305. package/dist/src/ui/hooks/useShellHistory.test.js.map +1 -0
  306. package/dist/src/ui/hooks/useSlashCompletion.d.ts +20 -0
  307. package/dist/src/ui/hooks/useSlashCompletion.js +135 -0
  308. package/dist/src/ui/hooks/useSlashCompletion.js.map +1 -0
  309. package/dist/src/ui/hooks/useSlashCompletion.test.d.ts +6 -0
  310. package/dist/src/ui/hooks/useSlashCompletion.test.js +272 -0
  311. package/dist/src/ui/hooks/useSlashCompletion.test.js.map +1 -0
  312. package/dist/src/ui/hooks/useThemeCommand.js +1 -1
  313. package/dist/src/ui/hooks/useThemeCommand.js.map +1 -1
  314. package/dist/src/ui/hooks/useTimer.test.d.ts +6 -0
  315. package/dist/src/ui/hooks/useTimer.test.js +90 -0
  316. package/dist/src/ui/hooks/useTimer.test.js.map +1 -0
  317. package/dist/src/ui/hooks/useToolScheduler.test.d.ts +6 -0
  318. package/dist/src/ui/hooks/useToolScheduler.test.js +846 -0
  319. package/dist/src/ui/hooks/useToolScheduler.test.js.map +1 -0
  320. package/dist/src/ui/hooks/vim.js +13 -4
  321. package/dist/src/ui/hooks/vim.js.map +1 -1
  322. package/dist/src/ui/keyMatchers.d.ts +26 -0
  323. package/dist/src/ui/keyMatchers.js +68 -0
  324. package/dist/src/ui/keyMatchers.js.map +1 -0
  325. package/dist/src/ui/keyMatchers.test.d.ts +6 -0
  326. package/dist/src/ui/keyMatchers.test.js +276 -0
  327. package/dist/src/ui/keyMatchers.test.js.map +1 -0
  328. package/dist/src/ui/privacy/CloudFreePrivacyNotice.js +5 -4
  329. package/dist/src/ui/privacy/CloudFreePrivacyNotice.js.map +1 -1
  330. package/dist/src/ui/privacy/CloudPaidPrivacyNotice.js +5 -4
  331. package/dist/src/ui/privacy/CloudPaidPrivacyNotice.js.map +1 -1
  332. package/dist/src/ui/privacy/GeminiPrivacyNotice.js +5 -4
  333. package/dist/src/ui/privacy/GeminiPrivacyNotice.js.map +1 -1
  334. package/dist/src/ui/semantic-colors.d.ts +7 -0
  335. package/dist/src/ui/semantic-colors.js +24 -0
  336. package/dist/src/ui/semantic-colors.js.map +1 -0
  337. package/dist/src/ui/themes/ansi-light.js +2 -1
  338. package/dist/src/ui/themes/ansi-light.js.map +1 -1
  339. package/dist/src/ui/themes/ansi.js +2 -1
  340. package/dist/src/ui/themes/ansi.js.map +1 -1
  341. package/dist/src/ui/themes/atom-one-dark.js +2 -1
  342. package/dist/src/ui/themes/atom-one-dark.js.map +1 -1
  343. package/dist/src/ui/themes/ayu-light.js +2 -1
  344. package/dist/src/ui/themes/ayu-light.js.map +1 -1
  345. package/dist/src/ui/themes/ayu.js +2 -1
  346. package/dist/src/ui/themes/ayu.js.map +1 -1
  347. package/dist/src/ui/themes/color-utils.test.d.ts +6 -0
  348. package/dist/src/ui/themes/color-utils.test.js +197 -0
  349. package/dist/src/ui/themes/color-utils.test.js.map +1 -0
  350. package/dist/src/ui/themes/default-light.js +2 -1
  351. package/dist/src/ui/themes/default-light.js.map +1 -1
  352. package/dist/src/ui/themes/default.js +2 -1
  353. package/dist/src/ui/themes/default.js.map +1 -1
  354. package/dist/src/ui/themes/dracula.js +2 -1
  355. package/dist/src/ui/themes/dracula.js.map +1 -1
  356. package/dist/src/ui/themes/github-dark.js +2 -1
  357. package/dist/src/ui/themes/github-dark.js.map +1 -1
  358. package/dist/src/ui/themes/github-light.js +2 -1
  359. package/dist/src/ui/themes/github-light.js.map +1 -1
  360. package/dist/src/ui/themes/googlecode.js +2 -1
  361. package/dist/src/ui/themes/googlecode.js.map +1 -1
  362. package/dist/src/ui/themes/no-color.js +30 -1
  363. package/dist/src/ui/themes/no-color.js.map +1 -1
  364. package/dist/src/ui/themes/semantic-tokens.d.ts +37 -0
  365. package/dist/src/ui/themes/semantic-tokens.js +94 -0
  366. package/dist/src/ui/themes/semantic-tokens.js.map +1 -0
  367. package/dist/src/ui/themes/shades-of-purple.js +2 -1
  368. package/dist/src/ui/themes/shades-of-purple.js.map +1 -1
  369. package/dist/src/ui/themes/theme-manager.d.ts +6 -0
  370. package/dist/src/ui/themes/theme-manager.js +8 -1
  371. package/dist/src/ui/themes/theme-manager.js.map +1 -1
  372. package/dist/src/ui/themes/theme-manager.test.d.ts +6 -0
  373. package/dist/src/ui/themes/theme-manager.test.js +83 -0
  374. package/dist/src/ui/themes/theme-manager.test.js.map +1 -0
  375. package/dist/src/ui/themes/theme.d.ts +45 -2
  376. package/dist/src/ui/themes/theme.js +92 -107
  377. package/dist/src/ui/themes/theme.js.map +1 -1
  378. package/dist/src/ui/themes/xcode.js +2 -1
  379. package/dist/src/ui/themes/xcode.js.map +1 -1
  380. package/dist/src/ui/types.d.ts +3 -1
  381. package/dist/src/ui/types.js.map +1 -1
  382. package/dist/src/ui/utils/CodeColorizer.d.ts +2 -1
  383. package/dist/src/ui/utils/CodeColorizer.js +5 -4
  384. package/dist/src/ui/utils/CodeColorizer.js.map +1 -1
  385. package/dist/src/ui/utils/ConsolePatcher.d.ts +3 -1
  386. package/dist/src/ui/utils/ConsolePatcher.js +18 -8
  387. package/dist/src/ui/utils/ConsolePatcher.js.map +1 -1
  388. package/dist/src/ui/utils/InlineMarkdownRenderer.js +8 -1
  389. package/dist/src/ui/utils/InlineMarkdownRenderer.js.map +1 -1
  390. package/dist/src/ui/utils/MarkdownDisplay.js +4 -2
  391. package/dist/src/ui/utils/MarkdownDisplay.js.map +1 -1
  392. package/dist/src/ui/utils/MarkdownDisplay.test.d.ts +6 -0
  393. package/dist/src/ui/utils/MarkdownDisplay.test.js +151 -0
  394. package/dist/src/ui/utils/MarkdownDisplay.test.js.map +1 -0
  395. package/dist/src/ui/utils/clipboardUtils.test.d.ts +6 -0
  396. package/dist/src/ui/utils/clipboardUtils.test.js +65 -0
  397. package/dist/src/ui/utils/clipboardUtils.test.js.map +1 -0
  398. package/dist/src/ui/utils/commandUtils.d.ts +1 -0
  399. package/dist/src/ui/utils/commandUtils.js +22 -1
  400. package/dist/src/ui/utils/commandUtils.js.map +1 -1
  401. package/dist/src/ui/utils/commandUtils.test.d.ts +6 -0
  402. package/dist/src/ui/utils/commandUtils.test.js +294 -0
  403. package/dist/src/ui/utils/commandUtils.test.js.map +1 -0
  404. package/dist/src/ui/utils/computeStats.js +3 -1
  405. package/dist/src/ui/utils/computeStats.js.map +1 -1
  406. package/dist/src/ui/utils/displayUtils.test.d.ts +6 -0
  407. package/dist/src/ui/utils/displayUtils.test.js +42 -0
  408. package/dist/src/ui/utils/displayUtils.test.js.map +1 -0
  409. package/dist/src/ui/utils/formatters.test.d.ts +6 -0
  410. package/dist/src/ui/utils/formatters.test.js +56 -0
  411. package/dist/src/ui/utils/formatters.test.js.map +1 -0
  412. package/dist/src/ui/utils/isNarrowWidth.d.ts +6 -0
  413. package/dist/src/ui/utils/isNarrowWidth.js +9 -0
  414. package/dist/src/ui/utils/isNarrowWidth.js.map +1 -0
  415. package/dist/src/ui/utils/kittyProtocolDetector.d.ts +13 -0
  416. package/dist/src/ui/utils/kittyProtocolDetector.js +88 -0
  417. package/dist/src/ui/utils/kittyProtocolDetector.js.map +1 -0
  418. package/dist/src/ui/utils/markdownUtilities.test.d.ts +6 -0
  419. package/dist/src/ui/utils/markdownUtilities.test.js +42 -0
  420. package/dist/src/ui/utils/markdownUtilities.test.js.map +1 -0
  421. package/dist/src/ui/utils/platformConstants.d.ts +43 -0
  422. package/dist/src/ui/utils/platformConstants.js +44 -0
  423. package/dist/src/ui/utils/platformConstants.js.map +1 -0
  424. package/dist/src/ui/utils/terminalSetup.d.ts +30 -0
  425. package/dist/src/ui/utils/terminalSetup.js +281 -0
  426. package/dist/src/ui/utils/terminalSetup.js.map +1 -0
  427. package/dist/src/ui/utils/updateCheck.js +1 -1
  428. package/dist/src/ui/utils/updateCheck.js.map +1 -1
  429. package/dist/src/ui/utils/updateCheck.test.d.ts +6 -0
  430. package/dist/src/ui/utils/updateCheck.test.js +145 -0
  431. package/dist/src/ui/utils/updateCheck.test.js.map +1 -0
  432. package/dist/src/utils/checks.d.ts +19 -0
  433. package/dist/src/utils/checks.js +24 -0
  434. package/dist/src/utils/checks.js.map +1 -0
  435. package/dist/src/utils/cleanup.d.ts +2 -2
  436. package/dist/src/utils/cleanup.js +2 -2
  437. package/dist/src/utils/cleanup.js.map +1 -1
  438. package/dist/src/utils/dialogScopeUtils.d.ts +31 -0
  439. package/dist/src/utils/dialogScopeUtils.js +48 -0
  440. package/dist/src/utils/dialogScopeUtils.js.map +1 -0
  441. package/dist/src/utils/gitUtils.d.ts +21 -1
  442. package/dist/src/utils/gitUtils.js +68 -3
  443. package/dist/src/utils/gitUtils.js.map +1 -1
  444. package/dist/src/utils/gitUtils.test.d.ts +6 -0
  445. package/dist/src/utils/gitUtils.test.js +113 -0
  446. package/dist/src/utils/gitUtils.test.js.map +1 -0
  447. package/dist/src/utils/installationInfo.test.d.ts +6 -0
  448. package/dist/src/utils/installationInfo.test.js +242 -0
  449. package/dist/src/utils/installationInfo.test.js.map +1 -0
  450. package/dist/src/utils/readStdin.js +10 -0
  451. package/dist/src/utils/readStdin.js.map +1 -1
  452. package/dist/src/utils/sandbox.js +443 -420
  453. package/dist/src/utils/sandbox.js.map +1 -1
  454. package/dist/src/utils/settingsUtils.d.ts +134 -0
  455. package/dist/src/utils/settingsUtils.js +336 -0
  456. package/dist/src/utils/settingsUtils.js.map +1 -0
  457. package/dist/src/utils/settingsUtils.test.d.ts +6 -0
  458. package/dist/src/utils/settingsUtils.test.js +514 -0
  459. package/dist/src/utils/settingsUtils.test.js.map +1 -0
  460. package/dist/src/utils/userStartupWarnings.test.d.ts +6 -0
  461. package/dist/src/utils/userStartupWarnings.test.js +67 -0
  462. package/dist/src/utils/userStartupWarnings.test.js.map +1 -0
  463. package/dist/src/utils/version.js +1 -1
  464. package/dist/src/utils/version.js.map +1 -1
  465. package/dist/src/validateNonInterActiveAuth.js +3 -3
  466. package/dist/src/validateNonInterActiveAuth.js.map +1 -1
  467. package/dist/src/zed-integration/acp.d.ts +63 -0
  468. package/dist/src/{acp → zed-integration}/acp.js +76 -44
  469. package/dist/src/zed-integration/acp.js.map +1 -0
  470. package/dist/src/zed-integration/fileSystemService.d.ts +19 -0
  471. package/dist/src/zed-integration/fileSystemService.js +43 -0
  472. package/dist/src/zed-integration/fileSystemService.js.map +1 -0
  473. package/dist/src/zed-integration/schema.d.ts +11679 -0
  474. package/dist/src/zed-integration/schema.js +305 -0
  475. package/dist/src/zed-integration/schema.js.map +1 -0
  476. package/dist/src/zed-integration/zedIntegration.d.ts +10 -0
  477. package/dist/src/{acp/acpPeer.js → zed-integration/zedIntegration.js} +336 -169
  478. package/dist/src/zed-integration/zedIntegration.js.map +1 -0
  479. package/dist/tsconfig.tsbuildinfo +1 -1
  480. package/package.json +13 -9
  481. package/dist/src/acp/acp.d.ts +0 -208
  482. package/dist/src/acp/acp.js.map +0 -1
  483. package/dist/src/acp/acpPeer.d.ts +0 -8
  484. package/dist/src/acp/acpPeer.js.map +0 -1
  485. package/dist/src/ui/components/IDEContextDetailDisplay.d.ts +0 -12
  486. package/dist/src/ui/components/IDEContextDetailDisplay.js +0 -12
  487. package/dist/src/ui/components/IDEContextDetailDisplay.js.map +0 -1
  488. package/dist/src/ui/utils/errorParsing.d.ts +0 -7
  489. package/dist/src/ui/utils/errorParsing.js +0 -90
  490. package/dist/src/ui/utils/errorParsing.js.map +0 -1
@@ -11,6 +11,7 @@ import { readFile } from 'node:fs/promises';
11
11
  import { quote, parse } from 'shell-quote';
12
12
  import { USER_SETTINGS_DIR, SETTINGS_DIRECTORY_NAME, } from '../config/settings.js';
13
13
  import { promisify } from 'util';
14
+ import { ConsolePatcher } from '../ui/utils/ConsolePatcher.js';
14
15
  const execAsync = promisify(exec);
15
16
  function getContainerPath(hostPath) {
16
17
  if (os.platform() !== 'win32') {
@@ -53,7 +54,7 @@ const BUILTIN_SEATBELT_PROFILES = [
53
54
  * @returns {Promise<boolean>} A promise that resolves to true if the current user's UID/GID should be used, false otherwise.
54
55
  */
55
56
  async function shouldUseCurrentUserInSandbox() {
56
- const envVar = process.env.SANDBOX_SET_UID_GID?.toLowerCase().trim();
57
+ const envVar = process.env['SANDBOX_SET_UID_GID']?.toLowerCase().trim();
57
58
  if (envVar === '1' || envVar === 'true') {
58
59
  return true;
59
60
  }
@@ -90,7 +91,7 @@ function parseImageName(image) {
90
91
  return tag ? `${name}-${tag}` : name;
91
92
  }
92
93
  function ports() {
93
- return (process.env.SANDBOX_PORTS ?? '')
94
+ return (process.env['SANDBOX_PORTS'] ?? '')
94
95
  .split(',')
95
96
  .filter((p) => p.trim())
96
97
  .map((p) => p.trim());
@@ -101,8 +102,8 @@ function entrypoint(workdir) {
101
102
  const shellCmds = [];
102
103
  const pathSeparator = isWindows ? ';' : ':';
103
104
  let pathSuffix = '';
104
- if (process.env.PATH) {
105
- const paths = process.env.PATH.split(pathSeparator);
105
+ if (process.env['PATH']) {
106
+ const paths = process.env['PATH'].split(pathSeparator);
106
107
  for (const p of paths) {
107
108
  const containerPath = getContainerPath(p);
108
109
  if (containerPath.toLowerCase().startsWith(containerWorkdir.toLowerCase())) {
@@ -114,8 +115,8 @@ function entrypoint(workdir) {
114
115
  shellCmds.push(`export PATH="$PATH${pathSuffix}";`);
115
116
  }
116
117
  let pythonPathSuffix = '';
117
- if (process.env.PYTHONPATH) {
118
- const paths = process.env.PYTHONPATH.split(pathSeparator);
118
+ if (process.env['PYTHONPATH']) {
119
+ const paths = process.env['PYTHONPATH'].split(pathSeparator);
119
120
  for (const p of paths) {
120
121
  const containerPath = getContainerPath(p);
121
122
  if (containerPath.toLowerCase().startsWith(containerWorkdir.toLowerCase())) {
@@ -132,110 +133,451 @@ function entrypoint(workdir) {
132
133
  }
133
134
  ports().forEach((p) => shellCmds.push(`socat TCP4-LISTEN:${p},bind=$(hostname -i),fork,reuseaddr TCP4:127.0.0.1:${p} 2> /dev/null &`));
134
135
  const cliArgs = process.argv.slice(2).map((arg) => quote([arg]));
135
- const cliCmd = process.env.NODE_ENV === 'development'
136
- ? process.env.DEBUG
136
+ const cliCmd = process.env['NODE_ENV'] === 'development'
137
+ ? process.env['DEBUG']
137
138
  ? 'npm run debug --'
138
139
  : 'npm rebuild && npm run start --'
139
- : process.env.DEBUG
140
- ? `node --inspect-brk=0.0.0.0:${process.env.DEBUG_PORT || '9229'} $(which gemini)`
140
+ : process.env['DEBUG']
141
+ ? `node --inspect-brk=0.0.0.0:${process.env['DEBUG_PORT'] || '9229'} $(which gemini)`
141
142
  : 'gemini';
142
143
  const args = [...shellCmds, cliCmd, ...cliArgs];
143
144
  return ['bash', '-c', args.join(' ')];
144
145
  }
145
146
  export async function start_sandbox(config, nodeArgs = [], cliConfig) {
146
- if (config.command === 'sandbox-exec') {
147
- // disallow BUILD_SANDBOX
148
- if (process.env.BUILD_SANDBOX) {
149
- console.error('ERROR: cannot BUILD_SANDBOX when using macOS Seatbelt');
150
- process.exit(1);
147
+ const patcher = new ConsolePatcher({
148
+ debugMode: cliConfig?.getDebugMode() || !!process.env['DEBUG'],
149
+ stderr: true,
150
+ });
151
+ patcher.patch();
152
+ try {
153
+ if (config.command === 'sandbox-exec') {
154
+ // disallow BUILD_SANDBOX
155
+ if (process.env['BUILD_SANDBOX']) {
156
+ console.error('ERROR: cannot BUILD_SANDBOX when using macOS Seatbelt');
157
+ process.exit(1);
158
+ }
159
+ const profile = (process.env['SEATBELT_PROFILE'] ??= 'permissive-open');
160
+ let profileFile = new URL(`sandbox-macos-${profile}.sb`, import.meta.url)
161
+ .pathname;
162
+ // if profile name is not recognized, then look for file under project settings directory
163
+ if (!BUILTIN_SEATBELT_PROFILES.includes(profile)) {
164
+ profileFile = path.join(SETTINGS_DIRECTORY_NAME, `sandbox-macos-${profile}.sb`);
165
+ }
166
+ if (!fs.existsSync(profileFile)) {
167
+ console.error(`ERROR: missing macos seatbelt profile file '${profileFile}'`);
168
+ process.exit(1);
169
+ }
170
+ // Log on STDERR so it doesn't clutter the output on STDOUT
171
+ console.error(`using macos seatbelt (profile: ${profile}) ...`);
172
+ // if DEBUG is set, convert to --inspect-brk in NODE_OPTIONS
173
+ const nodeOptions = [
174
+ ...(process.env['DEBUG'] ? ['--inspect-brk'] : []),
175
+ ...nodeArgs,
176
+ ].join(' ');
177
+ const args = [
178
+ '-D',
179
+ `TARGET_DIR=${fs.realpathSync(process.cwd())}`,
180
+ '-D',
181
+ `TMP_DIR=${fs.realpathSync(os.tmpdir())}`,
182
+ '-D',
183
+ `HOME_DIR=${fs.realpathSync(os.homedir())}`,
184
+ '-D',
185
+ `CACHE_DIR=${fs.realpathSync(execSync(`getconf DARWIN_USER_CACHE_DIR`).toString().trim())}`,
186
+ ];
187
+ // Add included directories from the workspace context
188
+ // Always add 5 INCLUDE_DIR parameters to ensure .sb files can reference them
189
+ const MAX_INCLUDE_DIRS = 5;
190
+ const targetDir = fs.realpathSync(cliConfig?.getTargetDir() || '');
191
+ const includedDirs = [];
192
+ if (cliConfig) {
193
+ const workspaceContext = cliConfig.getWorkspaceContext();
194
+ const directories = workspaceContext.getDirectories();
195
+ // Filter out TARGET_DIR
196
+ for (const dir of directories) {
197
+ const realDir = fs.realpathSync(dir);
198
+ if (realDir !== targetDir) {
199
+ includedDirs.push(realDir);
200
+ }
201
+ }
202
+ }
203
+ for (let i = 0; i < MAX_INCLUDE_DIRS; i++) {
204
+ let dirPath = '/dev/null'; // Default to a safe path that won't cause issues
205
+ if (i < includedDirs.length) {
206
+ dirPath = includedDirs[i];
207
+ }
208
+ args.push('-D', `INCLUDE_DIR_${i}=${dirPath}`);
209
+ }
210
+ args.push('-f', profileFile, 'sh', '-c', [
211
+ `SANDBOX=sandbox-exec`,
212
+ `NODE_OPTIONS="${nodeOptions}"`,
213
+ ...process.argv.map((arg) => quote([arg])),
214
+ ].join(' '));
215
+ // start and set up proxy if GEMINI_SANDBOX_PROXY_COMMAND is set
216
+ const proxyCommand = process.env['GEMINI_SANDBOX_PROXY_COMMAND'];
217
+ let proxyProcess = undefined;
218
+ let sandboxProcess = undefined;
219
+ const sandboxEnv = { ...process.env };
220
+ if (proxyCommand) {
221
+ const proxy = process.env['HTTPS_PROXY'] ||
222
+ process.env['https_proxy'] ||
223
+ process.env['HTTP_PROXY'] ||
224
+ process.env['http_proxy'] ||
225
+ 'http://localhost:8877';
226
+ sandboxEnv['HTTPS_PROXY'] = proxy;
227
+ sandboxEnv['https_proxy'] = proxy; // lower-case can be required, e.g. for curl
228
+ sandboxEnv['HTTP_PROXY'] = proxy;
229
+ sandboxEnv['http_proxy'] = proxy;
230
+ const noProxy = process.env['NO_PROXY'] || process.env['no_proxy'];
231
+ if (noProxy) {
232
+ sandboxEnv['NO_PROXY'] = noProxy;
233
+ sandboxEnv['no_proxy'] = noProxy;
234
+ }
235
+ proxyProcess = spawn(proxyCommand, {
236
+ stdio: ['ignore', 'pipe', 'pipe'],
237
+ shell: true,
238
+ detached: true,
239
+ });
240
+ // install handlers to stop proxy on exit/signal
241
+ const stopProxy = () => {
242
+ console.log('stopping proxy ...');
243
+ if (proxyProcess?.pid) {
244
+ process.kill(-proxyProcess.pid, 'SIGTERM');
245
+ }
246
+ };
247
+ process.on('exit', stopProxy);
248
+ process.on('SIGINT', stopProxy);
249
+ process.on('SIGTERM', stopProxy);
250
+ // commented out as it disrupts ink rendering
251
+ // proxyProcess.stdout?.on('data', (data) => {
252
+ // console.info(data.toString());
253
+ // });
254
+ proxyProcess.stderr?.on('data', (data) => {
255
+ console.error(data.toString());
256
+ });
257
+ proxyProcess.on('close', (code, signal) => {
258
+ console.error(`ERROR: proxy command '${proxyCommand}' exited with code ${code}, signal ${signal}`);
259
+ if (sandboxProcess?.pid) {
260
+ process.kill(-sandboxProcess.pid, 'SIGTERM');
261
+ }
262
+ process.exit(1);
263
+ });
264
+ console.log('waiting for proxy to start ...');
265
+ await execAsync(`until timeout 0.25 curl -s http://localhost:8877; do sleep 0.25; done`);
266
+ }
267
+ // spawn child and let it inherit stdio
268
+ sandboxProcess = spawn(config.command, args, {
269
+ stdio: 'inherit',
270
+ });
271
+ await new Promise((resolve) => sandboxProcess?.on('close', resolve));
272
+ return;
151
273
  }
152
- const profile = (process.env.SEATBELT_PROFILE ??= 'permissive-open');
153
- let profileFile = new URL(`sandbox-macos-${profile}.sb`, import.meta.url)
154
- .pathname;
155
- // if profile name is not recognized, then look for file under project settings directory
156
- if (!BUILTIN_SEATBELT_PROFILES.includes(profile)) {
157
- profileFile = path.join(SETTINGS_DIRECTORY_NAME, `sandbox-macos-${profile}.sb`);
274
+ console.error(`hopping into sandbox (command: ${config.command}) ...`);
275
+ // determine full path for gemini-cli to distinguish linked vs installed setting
276
+ const gcPath = fs.realpathSync(process.argv[1]);
277
+ const projectSandboxDockerfile = path.join(SETTINGS_DIRECTORY_NAME, 'sandbox.Dockerfile');
278
+ const isCustomProjectSandbox = fs.existsSync(projectSandboxDockerfile);
279
+ const image = config.image;
280
+ const workdir = path.resolve(process.cwd());
281
+ const containerWorkdir = getContainerPath(workdir);
282
+ // if BUILD_SANDBOX is set, then call scripts/build_sandbox.js under gemini-cli repo
283
+ //
284
+ // note this can only be done with binary linked from gemini-cli repo
285
+ if (process.env['BUILD_SANDBOX']) {
286
+ if (!gcPath.includes('gemini-cli/packages/')) {
287
+ console.error('ERROR: cannot build sandbox using installed gemini binary; ' +
288
+ 'run `npm link ./packages/cli` under gemini-cli repo to switch to linked binary.');
289
+ process.exit(1);
290
+ }
291
+ else {
292
+ console.error('building sandbox ...');
293
+ const gcRoot = gcPath.split('/packages/')[0];
294
+ // if project folder has sandbox.Dockerfile under project settings folder, use that
295
+ let buildArgs = '';
296
+ const projectSandboxDockerfile = path.join(SETTINGS_DIRECTORY_NAME, 'sandbox.Dockerfile');
297
+ if (isCustomProjectSandbox) {
298
+ console.error(`using ${projectSandboxDockerfile} for sandbox`);
299
+ buildArgs += `-f ${path.resolve(projectSandboxDockerfile)} -i ${image}`;
300
+ }
301
+ execSync(`cd ${gcRoot} && node scripts/build_sandbox.js -s ${buildArgs}`, {
302
+ stdio: 'inherit',
303
+ env: {
304
+ ...process.env,
305
+ GEMINI_SANDBOX: config.command, // in case sandbox is enabled via flags (see config.ts under cli package)
306
+ },
307
+ });
308
+ }
158
309
  }
159
- if (!fs.existsSync(profileFile)) {
160
- console.error(`ERROR: missing macos seatbelt profile file '${profileFile}'`);
310
+ // stop if image is missing
311
+ if (!(await ensureSandboxImageIsPresent(config.command, image))) {
312
+ const remedy = image === LOCAL_DEV_SANDBOX_IMAGE_NAME
313
+ ? 'Try running `npm run build:all` or `npm run build:sandbox` under the gemini-cli repo to build it locally, or check the image name and your network connection.'
314
+ : 'Please check the image name, your network connection, or notify gemini-cli-dev@google.com if the issue persists.';
315
+ console.error(`ERROR: Sandbox image '${image}' is missing or could not be pulled. ${remedy}`);
161
316
  process.exit(1);
162
317
  }
163
- // Log on STDERR so it doesn't clutter the output on STDOUT
164
- console.error(`using macos seatbelt (profile: ${profile}) ...`);
165
- // if DEBUG is set, convert to --inspect-brk in NODE_OPTIONS
166
- const nodeOptions = [
167
- ...(process.env.DEBUG ? ['--inspect-brk'] : []),
168
- ...nodeArgs,
169
- ].join(' ');
170
- const args = [
171
- '-D',
172
- `TARGET_DIR=${fs.realpathSync(process.cwd())}`,
173
- '-D',
174
- `TMP_DIR=${fs.realpathSync(os.tmpdir())}`,
175
- '-D',
176
- `HOME_DIR=${fs.realpathSync(os.homedir())}`,
177
- '-D',
178
- `CACHE_DIR=${fs.realpathSync(execSync(`getconf DARWIN_USER_CACHE_DIR`).toString().trim())}`,
179
- ];
180
- // Add included directories from the workspace context
181
- // Always add 5 INCLUDE_DIR parameters to ensure .sb files can reference them
182
- const MAX_INCLUDE_DIRS = 5;
183
- const targetDir = fs.realpathSync(cliConfig?.getTargetDir() || '');
184
- const includedDirs = [];
185
- if (cliConfig) {
186
- const workspaceContext = cliConfig.getWorkspaceContext();
187
- const directories = workspaceContext.getDirectories();
188
- // Filter out TARGET_DIR
189
- for (const dir of directories) {
190
- const realDir = fs.realpathSync(dir);
191
- if (realDir !== targetDir) {
192
- includedDirs.push(realDir);
318
+ // use interactive mode and auto-remove container on exit
319
+ // run init binary inside container to forward signals & reap zombies
320
+ const args = ['run', '-i', '--rm', '--init', '--workdir', containerWorkdir];
321
+ // add custom flags from SANDBOX_FLAGS
322
+ if (process.env['SANDBOX_FLAGS']) {
323
+ const flags = parse(process.env['SANDBOX_FLAGS'], process.env).filter((f) => typeof f === 'string');
324
+ args.push(...flags);
325
+ }
326
+ // add TTY only if stdin is TTY as well, i.e. for piped input don't init TTY in container
327
+ if (process.stdin.isTTY) {
328
+ args.push('-t');
329
+ }
330
+ // mount current directory as working directory in sandbox (set via --workdir)
331
+ args.push('--volume', `${workdir}:${containerWorkdir}`);
332
+ // mount user settings directory inside container, after creating if missing
333
+ // note user/home changes inside sandbox and we mount at BOTH paths for consistency
334
+ const userSettingsDirOnHost = USER_SETTINGS_DIR;
335
+ const userSettingsDirInSandbox = getContainerPath(`/home/node/${SETTINGS_DIRECTORY_NAME}`);
336
+ if (!fs.existsSync(userSettingsDirOnHost)) {
337
+ fs.mkdirSync(userSettingsDirOnHost);
338
+ }
339
+ args.push('--volume', `${userSettingsDirOnHost}:${userSettingsDirInSandbox}`);
340
+ if (userSettingsDirInSandbox !== userSettingsDirOnHost) {
341
+ args.push('--volume', `${userSettingsDirOnHost}:${getContainerPath(userSettingsDirOnHost)}`);
342
+ }
343
+ // mount os.tmpdir() as os.tmpdir() inside container
344
+ args.push('--volume', `${os.tmpdir()}:${getContainerPath(os.tmpdir())}`);
345
+ // mount gcloud config directory if it exists
346
+ const gcloudConfigDir = path.join(os.homedir(), '.config', 'gcloud');
347
+ if (fs.existsSync(gcloudConfigDir)) {
348
+ args.push('--volume', `${gcloudConfigDir}:${getContainerPath(gcloudConfigDir)}:ro`);
349
+ }
350
+ // mount ADC file if GOOGLE_APPLICATION_CREDENTIALS is set
351
+ if (process.env['GOOGLE_APPLICATION_CREDENTIALS']) {
352
+ const adcFile = process.env['GOOGLE_APPLICATION_CREDENTIALS'];
353
+ if (fs.existsSync(adcFile)) {
354
+ args.push('--volume', `${adcFile}:${getContainerPath(adcFile)}:ro`);
355
+ args.push('--env', `GOOGLE_APPLICATION_CREDENTIALS=${getContainerPath(adcFile)}`);
356
+ }
357
+ }
358
+ // mount paths listed in SANDBOX_MOUNTS
359
+ if (process.env['SANDBOX_MOUNTS']) {
360
+ for (let mount of process.env['SANDBOX_MOUNTS'].split(',')) {
361
+ if (mount.trim()) {
362
+ // parse mount as from:to:opts
363
+ let [from, to, opts] = mount.trim().split(':');
364
+ to = to || from; // default to mount at same path inside container
365
+ opts = opts || 'ro'; // default to read-only
366
+ mount = `${from}:${to}:${opts}`;
367
+ // check that from path is absolute
368
+ if (!path.isAbsolute(from)) {
369
+ console.error(`ERROR: path '${from}' listed in SANDBOX_MOUNTS must be absolute`);
370
+ process.exit(1);
371
+ }
372
+ // check that from path exists on host
373
+ if (!fs.existsSync(from)) {
374
+ console.error(`ERROR: missing mount path '${from}' listed in SANDBOX_MOUNTS`);
375
+ process.exit(1);
376
+ }
377
+ console.error(`SANDBOX_MOUNTS: ${from} -> ${to} (${opts})`);
378
+ args.push('--volume', mount);
193
379
  }
194
380
  }
195
381
  }
196
- for (let i = 0; i < MAX_INCLUDE_DIRS; i++) {
197
- let dirPath = '/dev/null'; // Default to a safe path that won't cause issues
198
- if (i < includedDirs.length) {
199
- dirPath = includedDirs[i];
382
+ // expose env-specified ports on the sandbox
383
+ ports().forEach((p) => args.push('--publish', `${p}:${p}`));
384
+ // if DEBUG is set, expose debugging port
385
+ if (process.env['DEBUG']) {
386
+ const debugPort = process.env['DEBUG_PORT'] || '9229';
387
+ args.push(`--publish`, `${debugPort}:${debugPort}`);
388
+ }
389
+ // copy proxy environment variables, replacing localhost with SANDBOX_PROXY_NAME
390
+ // copy as both upper-case and lower-case as is required by some utilities
391
+ // GEMINI_SANDBOX_PROXY_COMMAND implies HTTPS_PROXY unless HTTP_PROXY is set
392
+ const proxyCommand = process.env['GEMINI_SANDBOX_PROXY_COMMAND'];
393
+ if (proxyCommand) {
394
+ let proxy = process.env['HTTPS_PROXY'] ||
395
+ process.env['https_proxy'] ||
396
+ process.env['HTTP_PROXY'] ||
397
+ process.env['http_proxy'] ||
398
+ 'http://localhost:8877';
399
+ proxy = proxy.replace('localhost', SANDBOX_PROXY_NAME);
400
+ if (proxy) {
401
+ args.push('--env', `HTTPS_PROXY=${proxy}`);
402
+ args.push('--env', `https_proxy=${proxy}`); // lower-case can be required, e.g. for curl
403
+ args.push('--env', `HTTP_PROXY=${proxy}`);
404
+ args.push('--env', `http_proxy=${proxy}`);
405
+ }
406
+ const noProxy = process.env['NO_PROXY'] || process.env['no_proxy'];
407
+ if (noProxy) {
408
+ args.push('--env', `NO_PROXY=${noProxy}`);
409
+ args.push('--env', `no_proxy=${noProxy}`);
410
+ }
411
+ // if using proxy, switch to internal networking through proxy
412
+ if (proxy) {
413
+ execSync(`${config.command} network inspect ${SANDBOX_NETWORK_NAME} || ${config.command} network create --internal ${SANDBOX_NETWORK_NAME}`);
414
+ args.push('--network', SANDBOX_NETWORK_NAME);
415
+ // if proxy command is set, create a separate network w/ host access (i.e. non-internal)
416
+ // we will run proxy in its own container connected to both host network and internal network
417
+ // this allows proxy to work even on rootless podman on macos with host<->vm<->container isolation
418
+ if (proxyCommand) {
419
+ execSync(`${config.command} network inspect ${SANDBOX_PROXY_NAME} || ${config.command} network create ${SANDBOX_PROXY_NAME}`);
420
+ }
421
+ }
422
+ }
423
+ // name container after image, plus numeric suffix to avoid conflicts
424
+ const imageName = parseImageName(image);
425
+ let index = 0;
426
+ const containerNameCheck = execSync(`${config.command} ps -a --format "{{.Names}}"`)
427
+ .toString()
428
+ .trim();
429
+ while (containerNameCheck.includes(`${imageName}-${index}`)) {
430
+ index++;
431
+ }
432
+ const containerName = `${imageName}-${index}`;
433
+ args.push('--name', containerName, '--hostname', containerName);
434
+ // copy GEMINI_API_KEY(s)
435
+ if (process.env['GEMINI_API_KEY']) {
436
+ args.push('--env', `GEMINI_API_KEY=${process.env['GEMINI_API_KEY']}`);
437
+ }
438
+ if (process.env['GOOGLE_API_KEY']) {
439
+ args.push('--env', `GOOGLE_API_KEY=${process.env['GOOGLE_API_KEY']}`);
440
+ }
441
+ // copy GOOGLE_GENAI_USE_VERTEXAI
442
+ if (process.env['GOOGLE_GENAI_USE_VERTEXAI']) {
443
+ args.push('--env', `GOOGLE_GENAI_USE_VERTEXAI=${process.env['GOOGLE_GENAI_USE_VERTEXAI']}`);
444
+ }
445
+ // copy GOOGLE_GENAI_USE_GCA
446
+ if (process.env['GOOGLE_GENAI_USE_GCA']) {
447
+ args.push('--env', `GOOGLE_GENAI_USE_GCA=${process.env['GOOGLE_GENAI_USE_GCA']}`);
448
+ }
449
+ // copy GOOGLE_CLOUD_PROJECT
450
+ if (process.env['GOOGLE_CLOUD_PROJECT']) {
451
+ args.push('--env', `GOOGLE_CLOUD_PROJECT=${process.env['GOOGLE_CLOUD_PROJECT']}`);
452
+ }
453
+ // copy GOOGLE_CLOUD_LOCATION
454
+ if (process.env['GOOGLE_CLOUD_LOCATION']) {
455
+ args.push('--env', `GOOGLE_CLOUD_LOCATION=${process.env['GOOGLE_CLOUD_LOCATION']}`);
456
+ }
457
+ // copy GEMINI_MODEL
458
+ if (process.env['GEMINI_MODEL']) {
459
+ args.push('--env', `GEMINI_MODEL=${process.env['GEMINI_MODEL']}`);
460
+ }
461
+ // copy TERM and COLORTERM to try to maintain terminal setup
462
+ if (process.env['TERM']) {
463
+ args.push('--env', `TERM=${process.env['TERM']}`);
464
+ }
465
+ if (process.env['COLORTERM']) {
466
+ args.push('--env', `COLORTERM=${process.env['COLORTERM']}`);
467
+ }
468
+ // Pass through IDE mode environment variables
469
+ for (const envVar of [
470
+ 'CELL_CLI_IDE_SERVER_PORT',
471
+ 'CELL_CLI_IDE_WORKSPACE_PATH',
472
+ 'TERM_PROGRAM',
473
+ ]) {
474
+ if (process.env[envVar]) {
475
+ args.push('--env', `${envVar}=${process.env[envVar]}`);
476
+ }
477
+ }
478
+ // copy VIRTUAL_ENV if under working directory
479
+ // also mount-replace VIRTUAL_ENV directory with <project_settings>/sandbox.venv
480
+ // sandbox can then set up this new VIRTUAL_ENV directory using sandbox.bashrc (see below)
481
+ // directory will be empty if not set up, which is still preferable to having host binaries
482
+ if (process.env['VIRTUAL_ENV']
483
+ ?.toLowerCase()
484
+ .startsWith(workdir.toLowerCase())) {
485
+ const sandboxVenvPath = path.resolve(SETTINGS_DIRECTORY_NAME, 'sandbox.venv');
486
+ if (!fs.existsSync(sandboxVenvPath)) {
487
+ fs.mkdirSync(sandboxVenvPath, { recursive: true });
488
+ }
489
+ args.push('--volume', `${sandboxVenvPath}:${getContainerPath(process.env['VIRTUAL_ENV'])}`);
490
+ args.push('--env', `VIRTUAL_ENV=${getContainerPath(process.env['VIRTUAL_ENV'])}`);
491
+ }
492
+ // copy additional environment variables from SANDBOX_ENV
493
+ if (process.env['SANDBOX_ENV']) {
494
+ for (let env of process.env['SANDBOX_ENV'].split(',')) {
495
+ if ((env = env.trim())) {
496
+ if (env.includes('=')) {
497
+ console.error(`SANDBOX_ENV: ${env}`);
498
+ args.push('--env', env);
499
+ }
500
+ else {
501
+ console.error('ERROR: SANDBOX_ENV must be a comma-separated list of key=value pairs');
502
+ process.exit(1);
503
+ }
504
+ }
200
505
  }
201
- args.push('-D', `INCLUDE_DIR_${i}=${dirPath}`);
202
506
  }
203
- args.push('-f', profileFile, 'sh', '-c', [
204
- `SANDBOX=sandbox-exec`,
205
- `NODE_OPTIONS="${nodeOptions}"`,
206
- ...process.argv.map((arg) => quote([arg])),
207
- ].join(' '));
507
+ // copy NODE_OPTIONS
508
+ const existingNodeOptions = process.env['NODE_OPTIONS'] || '';
509
+ const allNodeOptions = [
510
+ ...(existingNodeOptions ? [existingNodeOptions] : []),
511
+ ...nodeArgs,
512
+ ].join(' ');
513
+ if (allNodeOptions.length > 0) {
514
+ args.push('--env', `NODE_OPTIONS="${allNodeOptions}"`);
515
+ }
516
+ // set SANDBOX as container name
517
+ args.push('--env', `SANDBOX=${containerName}`);
518
+ // for podman only, use empty --authfile to skip unnecessary auth refresh overhead
519
+ if (config.command === 'podman') {
520
+ const emptyAuthFilePath = path.join(os.tmpdir(), 'empty_auth.json');
521
+ fs.writeFileSync(emptyAuthFilePath, '{}', 'utf-8');
522
+ args.push('--authfile', emptyAuthFilePath);
523
+ }
524
+ // Determine if the current user's UID/GID should be passed to the sandbox.
525
+ // See shouldUseCurrentUserInSandbox for more details.
526
+ let userFlag = '';
527
+ const finalEntrypoint = entrypoint(workdir);
528
+ if (process.env['GEMINI_CLI_INTEGRATION_TEST'] === 'true') {
529
+ args.push('--user', 'root');
530
+ userFlag = '--user root';
531
+ }
532
+ else if (await shouldUseCurrentUserInSandbox()) {
533
+ // For the user-creation logic to work, the container must start as root.
534
+ // The entrypoint script then handles dropping privileges to the correct user.
535
+ args.push('--user', 'root');
536
+ const uid = execSync('id -u').toString().trim();
537
+ const gid = execSync('id -g').toString().trim();
538
+ // Instead of passing --user to the main sandbox container, we let it
539
+ // start as root, then create a user with the host's UID/GID, and
540
+ // finally switch to that user to run the gemini process. This is
541
+ // necessary on Linux to ensure the user exists within the
542
+ // container's /etc/passwd file, which is required by os.userInfo().
543
+ const username = 'gemini';
544
+ const homeDir = getContainerPath(os.homedir());
545
+ const setupUserCommands = [
546
+ // Use -f with groupadd to avoid errors if the group already exists.
547
+ `groupadd -f -g ${gid} ${username}`,
548
+ // Create user only if it doesn't exist. Use -o for non-unique UID.
549
+ `id -u ${username} &>/dev/null || useradd -o -u ${uid} -g ${gid} -d ${homeDir} -s /bin/bash ${username}`,
550
+ ].join(' && ');
551
+ const originalCommand = finalEntrypoint[2];
552
+ const escapedOriginalCommand = originalCommand.replace(/'/g, "'\\''");
553
+ // Use `su -p` to preserve the environment.
554
+ const suCommand = `su -p ${username} -c '${escapedOriginalCommand}'`;
555
+ // The entrypoint is always `['bash', '-c', '<command>']`, so we modify the command part.
556
+ finalEntrypoint[2] = `${setupUserCommands} && ${suCommand}`;
557
+ // We still need userFlag for the simpler proxy container, which does not have this issue.
558
+ userFlag = `--user ${uid}:${gid}`;
559
+ // When forcing a UID in the sandbox, $HOME can be reset to '/', so we copy $HOME as well.
560
+ args.push('--env', `HOME=${os.homedir()}`);
561
+ }
562
+ // push container image name
563
+ args.push(image);
564
+ // push container entrypoint (including args)
565
+ args.push(...finalEntrypoint);
208
566
  // start and set up proxy if GEMINI_SANDBOX_PROXY_COMMAND is set
209
- const proxyCommand = process.env.GEMINI_SANDBOX_PROXY_COMMAND;
210
567
  let proxyProcess = undefined;
211
568
  let sandboxProcess = undefined;
212
- const sandboxEnv = { ...process.env };
213
569
  if (proxyCommand) {
214
- const proxy = process.env.HTTPS_PROXY ||
215
- process.env.https_proxy ||
216
- process.env.HTTP_PROXY ||
217
- process.env.http_proxy ||
218
- 'http://localhost:8877';
219
- sandboxEnv['HTTPS_PROXY'] = proxy;
220
- sandboxEnv['https_proxy'] = proxy; // lower-case can be required, e.g. for curl
221
- sandboxEnv['HTTP_PROXY'] = proxy;
222
- sandboxEnv['http_proxy'] = proxy;
223
- const noProxy = process.env.NO_PROXY || process.env.no_proxy;
224
- if (noProxy) {
225
- sandboxEnv['NO_PROXY'] = noProxy;
226
- sandboxEnv['no_proxy'] = noProxy;
227
- }
228
- proxyProcess = spawn(proxyCommand, {
570
+ // run proxyCommand in its own container
571
+ const proxyContainerCommand = `${config.command} run --rm --init ${userFlag} --name ${SANDBOX_PROXY_NAME} --network ${SANDBOX_PROXY_NAME} -p 8877:8877 -v ${process.cwd()}:${workdir} --workdir ${workdir} ${image} ${proxyCommand}`;
572
+ proxyProcess = spawn(proxyContainerCommand, {
229
573
  stdio: ['ignore', 'pipe', 'pipe'],
230
574
  shell: true,
231
575
  detached: true,
232
576
  });
233
577
  // install handlers to stop proxy on exit/signal
234
578
  const stopProxy = () => {
235
- console.log('stopping proxy ...');
236
- if (proxyProcess?.pid) {
237
- process.kill(-proxyProcess.pid, 'SIGTERM');
238
- }
579
+ console.log('stopping proxy container ...');
580
+ execSync(`${config.command} rm -f ${SANDBOX_PROXY_NAME}`);
239
581
  };
240
582
  process.on('exit', stopProxy);
241
583
  process.on('SIGINT', stopProxy);
@@ -245,10 +587,10 @@ export async function start_sandbox(config, nodeArgs = [], cliConfig) {
245
587
  // console.info(data.toString());
246
588
  // });
247
589
  proxyProcess.stderr?.on('data', (data) => {
248
- console.error(data.toString());
590
+ console.error(data.toString().trim());
249
591
  });
250
592
  proxyProcess.on('close', (code, signal) => {
251
- console.error(`ERROR: proxy command '${proxyCommand}' exited with code ${code}, signal ${signal}`);
593
+ console.error(`ERROR: proxy container command '${proxyContainerCommand}' exited with code ${code}, signal ${signal}`);
252
594
  if (sandboxProcess?.pid) {
253
595
  process.kill(-sandboxProcess.pid, 'SIGTERM');
254
596
  }
@@ -256,348 +598,29 @@ export async function start_sandbox(config, nodeArgs = [], cliConfig) {
256
598
  });
257
599
  console.log('waiting for proxy to start ...');
258
600
  await execAsync(`until timeout 0.25 curl -s http://localhost:8877; do sleep 0.25; done`);
601
+ // connect proxy container to sandbox network
602
+ // (workaround for older versions of docker that don't support multiple --network args)
603
+ await execAsync(`${config.command} network connect ${SANDBOX_NETWORK_NAME} ${SANDBOX_PROXY_NAME}`);
259
604
  }
260
605
  // spawn child and let it inherit stdio
261
606
  sandboxProcess = spawn(config.command, args, {
262
607
  stdio: 'inherit',
263
608
  });
264
- await new Promise((resolve) => sandboxProcess?.on('close', resolve));
265
- return;
266
- }
267
- console.error(`hopping into sandbox (command: ${config.command}) ...`);
268
- // determine full path for gemini-cli to distinguish linked vs installed setting
269
- const gcPath = fs.realpathSync(process.argv[1]);
270
- const projectSandboxDockerfile = path.join(SETTINGS_DIRECTORY_NAME, 'sandbox.Dockerfile');
271
- const isCustomProjectSandbox = fs.existsSync(projectSandboxDockerfile);
272
- const image = config.image;
273
- const workdir = path.resolve(process.cwd());
274
- const containerWorkdir = getContainerPath(workdir);
275
- // if BUILD_SANDBOX is set, then call scripts/build_sandbox.js under gemini-cli repo
276
- //
277
- // note this can only be done with binary linked from gemini-cli repo
278
- if (process.env.BUILD_SANDBOX) {
279
- if (!gcPath.includes('gemini-cli/packages/')) {
280
- console.error('ERROR: cannot build sandbox using installed gemini binary; ' +
281
- 'run `npm link ./packages/cli` under gemini-cli repo to switch to linked binary.');
282
- process.exit(1);
283
- }
284
- else {
285
- console.error('building sandbox ...');
286
- const gcRoot = gcPath.split('/packages/')[0];
287
- // if project folder has sandbox.Dockerfile under project settings folder, use that
288
- let buildArgs = '';
289
- const projectSandboxDockerfile = path.join(SETTINGS_DIRECTORY_NAME, 'sandbox.Dockerfile');
290
- if (isCustomProjectSandbox) {
291
- console.error(`using ${projectSandboxDockerfile} for sandbox`);
292
- buildArgs += `-f ${path.resolve(projectSandboxDockerfile)} -i ${image}`;
293
- }
294
- execSync(`cd ${gcRoot} && node scripts/build_sandbox.js -s ${buildArgs}`, {
295
- stdio: 'inherit',
296
- env: {
297
- ...process.env,
298
- GEMINI_SANDBOX: config.command, // in case sandbox is enabled via flags (see config.ts under cli package)
299
- },
300
- });
301
- }
302
- }
303
- // stop if image is missing
304
- if (!(await ensureSandboxImageIsPresent(config.command, image))) {
305
- const remedy = image === LOCAL_DEV_SANDBOX_IMAGE_NAME
306
- ? 'Try running `npm run build:all` or `npm run build:sandbox` under the gemini-cli repo to build it locally, or check the image name and your network connection.'
307
- : 'Please check the image name, your network connection, or notify gemini-cli-dev@google.com if the issue persists.';
308
- console.error(`ERROR: Sandbox image '${image}' is missing or could not be pulled. ${remedy}`);
309
- process.exit(1);
310
- }
311
- // use interactive mode and auto-remove container on exit
312
- // run init binary inside container to forward signals & reap zombies
313
- const args = ['run', '-i', '--rm', '--init', '--workdir', containerWorkdir];
314
- // add custom flags from SANDBOX_FLAGS
315
- if (process.env.SANDBOX_FLAGS) {
316
- const flags = parse(process.env.SANDBOX_FLAGS, process.env).filter((f) => typeof f === 'string');
317
- args.push(...flags);
318
- }
319
- // add TTY only if stdin is TTY as well, i.e. for piped input don't init TTY in container
320
- if (process.stdin.isTTY) {
321
- args.push('-t');
322
- }
323
- // mount current directory as working directory in sandbox (set via --workdir)
324
- args.push('--volume', `${workdir}:${containerWorkdir}`);
325
- // mount user settings directory inside container, after creating if missing
326
- // note user/home changes inside sandbox and we mount at BOTH paths for consistency
327
- const userSettingsDirOnHost = USER_SETTINGS_DIR;
328
- const userSettingsDirInSandbox = getContainerPath(`/home/node/${SETTINGS_DIRECTORY_NAME}`);
329
- if (!fs.existsSync(userSettingsDirOnHost)) {
330
- fs.mkdirSync(userSettingsDirOnHost);
331
- }
332
- args.push('--volume', `${userSettingsDirOnHost}:${userSettingsDirInSandbox}`);
333
- if (userSettingsDirInSandbox !== userSettingsDirOnHost) {
334
- args.push('--volume', `${userSettingsDirOnHost}:${getContainerPath(userSettingsDirOnHost)}`);
335
- }
336
- // mount os.tmpdir() as os.tmpdir() inside container
337
- args.push('--volume', `${os.tmpdir()}:${getContainerPath(os.tmpdir())}`);
338
- // mount gcloud config directory if it exists
339
- const gcloudConfigDir = path.join(os.homedir(), '.config', 'gcloud');
340
- if (fs.existsSync(gcloudConfigDir)) {
341
- args.push('--volume', `${gcloudConfigDir}:${getContainerPath(gcloudConfigDir)}:ro`);
342
- }
343
- // mount ADC file if GOOGLE_APPLICATION_CREDENTIALS is set
344
- if (process.env.GOOGLE_APPLICATION_CREDENTIALS) {
345
- const adcFile = process.env.GOOGLE_APPLICATION_CREDENTIALS;
346
- if (fs.existsSync(adcFile)) {
347
- args.push('--volume', `${adcFile}:${getContainerPath(adcFile)}:ro`);
348
- args.push('--env', `GOOGLE_APPLICATION_CREDENTIALS=${getContainerPath(adcFile)}`);
349
- }
350
- }
351
- // mount paths listed in SANDBOX_MOUNTS
352
- if (process.env.SANDBOX_MOUNTS) {
353
- for (let mount of process.env.SANDBOX_MOUNTS.split(',')) {
354
- if (mount.trim()) {
355
- // parse mount as from:to:opts
356
- let [from, to, opts] = mount.trim().split(':');
357
- to = to || from; // default to mount at same path inside container
358
- opts = opts || 'ro'; // default to read-only
359
- mount = `${from}:${to}:${opts}`;
360
- // check that from path is absolute
361
- if (!path.isAbsolute(from)) {
362
- console.error(`ERROR: path '${from}' listed in SANDBOX_MOUNTS must be absolute`);
363
- process.exit(1);
364
- }
365
- // check that from path exists on host
366
- if (!fs.existsSync(from)) {
367
- console.error(`ERROR: missing mount path '${from}' listed in SANDBOX_MOUNTS`);
368
- process.exit(1);
369
- }
370
- console.error(`SANDBOX_MOUNTS: ${from} -> ${to} (${opts})`);
371
- args.push('--volume', mount);
372
- }
373
- }
374
- }
375
- // expose env-specified ports on the sandbox
376
- ports().forEach((p) => args.push('--publish', `${p}:${p}`));
377
- // if DEBUG is set, expose debugging port
378
- if (process.env.DEBUG) {
379
- const debugPort = process.env.DEBUG_PORT || '9229';
380
- args.push(`--publish`, `${debugPort}:${debugPort}`);
381
- }
382
- // copy proxy environment variables, replacing localhost with SANDBOX_PROXY_NAME
383
- // copy as both upper-case and lower-case as is required by some utilities
384
- // GEMINI_SANDBOX_PROXY_COMMAND implies HTTPS_PROXY unless HTTP_PROXY is set
385
- const proxyCommand = process.env.GEMINI_SANDBOX_PROXY_COMMAND;
386
- if (proxyCommand) {
387
- let proxy = process.env.HTTPS_PROXY ||
388
- process.env.https_proxy ||
389
- process.env.HTTP_PROXY ||
390
- process.env.http_proxy ||
391
- 'http://localhost:8877';
392
- proxy = proxy.replace('localhost', SANDBOX_PROXY_NAME);
393
- if (proxy) {
394
- args.push('--env', `HTTPS_PROXY=${proxy}`);
395
- args.push('--env', `https_proxy=${proxy}`); // lower-case can be required, e.g. for curl
396
- args.push('--env', `HTTP_PROXY=${proxy}`);
397
- args.push('--env', `http_proxy=${proxy}`);
398
- }
399
- const noProxy = process.env.NO_PROXY || process.env.no_proxy;
400
- if (noProxy) {
401
- args.push('--env', `NO_PROXY=${noProxy}`);
402
- args.push('--env', `no_proxy=${noProxy}`);
403
- }
404
- // if using proxy, switch to internal networking through proxy
405
- if (proxy) {
406
- execSync(`${config.command} network inspect ${SANDBOX_NETWORK_NAME} || ${config.command} network create --internal ${SANDBOX_NETWORK_NAME}`);
407
- args.push('--network', SANDBOX_NETWORK_NAME);
408
- // if proxy command is set, create a separate network w/ host access (i.e. non-internal)
409
- // we will run proxy in its own container connected to both host network and internal network
410
- // this allows proxy to work even on rootless podman on macos with host<->vm<->container isolation
411
- if (proxyCommand) {
412
- execSync(`${config.command} network inspect ${SANDBOX_PROXY_NAME} || ${config.command} network create ${SANDBOX_PROXY_NAME}`);
413
- }
414
- }
415
- }
416
- // name container after image, plus numeric suffix to avoid conflicts
417
- const imageName = parseImageName(image);
418
- let index = 0;
419
- const containerNameCheck = execSync(`${config.command} ps -a --format "{{.Names}}"`)
420
- .toString()
421
- .trim();
422
- while (containerNameCheck.includes(`${imageName}-${index}`)) {
423
- index++;
424
- }
425
- const containerName = `${imageName}-${index}`;
426
- args.push('--name', containerName, '--hostname', containerName);
427
- // copy GEMINI_API_KEY(s)
428
- if (process.env.GEMINI_API_KEY) {
429
- args.push('--env', `GEMINI_API_KEY=${process.env.GEMINI_API_KEY}`);
430
- }
431
- if (process.env.GOOGLE_API_KEY) {
432
- args.push('--env', `GOOGLE_API_KEY=${process.env.GOOGLE_API_KEY}`);
433
- }
434
- // copy GOOGLE_GENAI_USE_VERTEXAI
435
- if (process.env.GOOGLE_GENAI_USE_VERTEXAI) {
436
- args.push('--env', `GOOGLE_GENAI_USE_VERTEXAI=${process.env.GOOGLE_GENAI_USE_VERTEXAI}`);
437
- }
438
- // copy GOOGLE_GENAI_USE_GCA
439
- if (process.env.GOOGLE_GENAI_USE_GCA) {
440
- args.push('--env', `GOOGLE_GENAI_USE_GCA=${process.env.GOOGLE_GENAI_USE_GCA}`);
441
- }
442
- // copy GOOGLE_CLOUD_PROJECT
443
- if (process.env.GOOGLE_CLOUD_PROJECT) {
444
- args.push('--env', `GOOGLE_CLOUD_PROJECT=${process.env.GOOGLE_CLOUD_PROJECT}`);
445
- }
446
- // copy GOOGLE_CLOUD_LOCATION
447
- if (process.env.GOOGLE_CLOUD_LOCATION) {
448
- args.push('--env', `GOOGLE_CLOUD_LOCATION=${process.env.GOOGLE_CLOUD_LOCATION}`);
449
- }
450
- // copy GEMINI_MODEL
451
- if (process.env.GEMINI_MODEL) {
452
- args.push('--env', `GEMINI_MODEL=${process.env.GEMINI_MODEL}`);
453
- }
454
- // copy TERM and COLORTERM to try to maintain terminal setup
455
- if (process.env.TERM) {
456
- args.push('--env', `TERM=${process.env.TERM}`);
457
- }
458
- if (process.env.COLORTERM) {
459
- args.push('--env', `COLORTERM=${process.env.COLORTERM}`);
460
- }
461
- // copy VIRTUAL_ENV if under working directory
462
- // also mount-replace VIRTUAL_ENV directory with <project_settings>/sandbox.venv
463
- // sandbox can then set up this new VIRTUAL_ENV directory using sandbox.bashrc (see below)
464
- // directory will be empty if not set up, which is still preferable to having host binaries
465
- if (process.env.VIRTUAL_ENV?.toLowerCase().startsWith(workdir.toLowerCase())) {
466
- const sandboxVenvPath = path.resolve(SETTINGS_DIRECTORY_NAME, 'sandbox.venv');
467
- if (!fs.existsSync(sandboxVenvPath)) {
468
- fs.mkdirSync(sandboxVenvPath, { recursive: true });
469
- }
470
- args.push('--volume', `${sandboxVenvPath}:${getContainerPath(process.env.VIRTUAL_ENV)}`);
471
- args.push('--env', `VIRTUAL_ENV=${getContainerPath(process.env.VIRTUAL_ENV)}`);
472
- }
473
- // copy additional environment variables from SANDBOX_ENV
474
- if (process.env.SANDBOX_ENV) {
475
- for (let env of process.env.SANDBOX_ENV.split(',')) {
476
- if ((env = env.trim())) {
477
- if (env.includes('=')) {
478
- console.error(`SANDBOX_ENV: ${env}`);
479
- args.push('--env', env);
480
- }
481
- else {
482
- console.error('ERROR: SANDBOX_ENV must be a comma-separated list of key=value pairs');
483
- process.exit(1);
484
- }
485
- }
486
- }
487
- }
488
- // copy NODE_OPTIONS
489
- const existingNodeOptions = process.env.NODE_OPTIONS || '';
490
- const allNodeOptions = [
491
- ...(existingNodeOptions ? [existingNodeOptions] : []),
492
- ...nodeArgs,
493
- ].join(' ');
494
- if (allNodeOptions.length > 0) {
495
- args.push('--env', `NODE_OPTIONS="${allNodeOptions}"`);
496
- }
497
- // set SANDBOX as container name
498
- args.push('--env', `SANDBOX=${containerName}`);
499
- // for podman only, use empty --authfile to skip unnecessary auth refresh overhead
500
- if (config.command === 'podman') {
501
- const emptyAuthFilePath = path.join(os.tmpdir(), 'empty_auth.json');
502
- fs.writeFileSync(emptyAuthFilePath, '{}', 'utf-8');
503
- args.push('--authfile', emptyAuthFilePath);
504
- }
505
- // Determine if the current user's UID/GID should be passed to the sandbox.
506
- // See shouldUseCurrentUserInSandbox for more details.
507
- let userFlag = '';
508
- const finalEntrypoint = entrypoint(workdir);
509
- if (process.env.GEMINI_CLI_INTEGRATION_TEST === 'true') {
510
- args.push('--user', 'root');
511
- userFlag = '--user root';
512
- }
513
- else if (await shouldUseCurrentUserInSandbox()) {
514
- // For the user-creation logic to work, the container must start as root.
515
- // The entrypoint script then handles dropping privileges to the correct user.
516
- args.push('--user', 'root');
517
- const uid = execSync('id -u').toString().trim();
518
- const gid = execSync('id -g').toString().trim();
519
- // Instead of passing --user to the main sandbox container, we let it
520
- // start as root, then create a user with the host's UID/GID, and
521
- // finally switch to that user to run the gemini process. This is
522
- // necessary on Linux to ensure the user exists within the
523
- // container's /etc/passwd file, which is required by os.userInfo().
524
- const username = 'gemini';
525
- const homeDir = getContainerPath(os.homedir());
526
- const setupUserCommands = [
527
- // Use -f with groupadd to avoid errors if the group already exists.
528
- `groupadd -f -g ${gid} ${username}`,
529
- // Create user only if it doesn't exist. Use -o for non-unique UID.
530
- `id -u ${username} &>/dev/null || useradd -o -u ${uid} -g ${gid} -d ${homeDir} -s /bin/bash ${username}`,
531
- ].join(' && ');
532
- const originalCommand = finalEntrypoint[2];
533
- const escapedOriginalCommand = originalCommand.replace(/'/g, "'\\''");
534
- // Use `su -p` to preserve the environment.
535
- const suCommand = `su -p ${username} -c '${escapedOriginalCommand}'`;
536
- // The entrypoint is always `['bash', '-c', '<command>']`, so we modify the command part.
537
- finalEntrypoint[2] = `${setupUserCommands} && ${suCommand}`;
538
- // We still need userFlag for the simpler proxy container, which does not have this issue.
539
- userFlag = `--user ${uid}:${gid}`;
540
- // When forcing a UID in the sandbox, $HOME can be reset to '/', so we copy $HOME as well.
541
- args.push('--env', `HOME=${os.homedir()}`);
542
- }
543
- // push container image name
544
- args.push(image);
545
- // push container entrypoint (including args)
546
- args.push(...finalEntrypoint);
547
- // start and set up proxy if GEMINI_SANDBOX_PROXY_COMMAND is set
548
- let proxyProcess = undefined;
549
- let sandboxProcess = undefined;
550
- if (proxyCommand) {
551
- // run proxyCommand in its own container
552
- const proxyContainerCommand = `${config.command} run --rm --init ${userFlag} --name ${SANDBOX_PROXY_NAME} --network ${SANDBOX_PROXY_NAME} -p 8877:8877 -v ${process.cwd()}:${workdir} --workdir ${workdir} ${image} ${proxyCommand}`;
553
- proxyProcess = spawn(proxyContainerCommand, {
554
- stdio: ['ignore', 'pipe', 'pipe'],
555
- shell: true,
556
- detached: true,
557
- });
558
- // install handlers to stop proxy on exit/signal
559
- const stopProxy = () => {
560
- console.log('stopping proxy container ...');
561
- execSync(`${config.command} rm -f ${SANDBOX_PROXY_NAME}`);
562
- };
563
- process.on('exit', stopProxy);
564
- process.on('SIGINT', stopProxy);
565
- process.on('SIGTERM', stopProxy);
566
- // commented out as it disrupts ink rendering
567
- // proxyProcess.stdout?.on('data', (data) => {
568
- // console.info(data.toString());
569
- // });
570
- proxyProcess.stderr?.on('data', (data) => {
571
- console.error(data.toString().trim());
609
+ sandboxProcess.on('error', (err) => {
610
+ console.error('Sandbox process error:', err);
572
611
  });
573
- proxyProcess.on('close', (code, signal) => {
574
- console.error(`ERROR: proxy container command '${proxyContainerCommand}' exited with code ${code}, signal ${signal}`);
575
- if (sandboxProcess?.pid) {
576
- process.kill(-sandboxProcess.pid, 'SIGTERM');
577
- }
578
- process.exit(1);
612
+ await new Promise((resolve) => {
613
+ sandboxProcess?.on('close', (code, signal) => {
614
+ if (code !== 0) {
615
+ console.log(`Sandbox process exited with code: ${code}, signal: ${signal}`);
616
+ }
617
+ resolve();
618
+ });
579
619
  });
580
- console.log('waiting for proxy to start ...');
581
- await execAsync(`until timeout 0.25 curl -s http://localhost:8877; do sleep 0.25; done`);
582
- // connect proxy container to sandbox network
583
- // (workaround for older versions of docker that don't support multiple --network args)
584
- await execAsync(`${config.command} network connect ${SANDBOX_NETWORK_NAME} ${SANDBOX_PROXY_NAME}`);
585
620
  }
586
- // spawn child and let it inherit stdio
587
- sandboxProcess = spawn(config.command, args, {
588
- stdio: 'inherit',
589
- });
590
- sandboxProcess.on('error', (err) => {
591
- console.error('Sandbox process error:', err);
592
- });
593
- await new Promise((resolve) => {
594
- sandboxProcess?.on('close', (code, signal) => {
595
- if (code !== 0) {
596
- console.log(`Sandbox process exited with code: ${code}, signal: ${signal}`);
597
- }
598
- resolve();
599
- });
600
- });
621
+ finally {
622
+ patcher.cleanup();
623
+ }
601
624
  }
602
625
  // Helper functions to ensure sandbox image is present
603
626
  async function imageExists(sandbox, image) {