@google/gemini-cli-core 0.1.15 → 0.1.16-nightly.250805.99ba2f64

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 (229) hide show
  1. package/README.md +32 -0
  2. package/dist/google-gemini-cli-core-0.1.16.tgz +0 -0
  3. package/dist/src/code_assist/converter.d.ts +2 -1
  4. package/dist/src/code_assist/converter.js +2 -1
  5. package/dist/src/code_assist/converter.js.map +1 -1
  6. package/dist/src/code_assist/converter.test.js +13 -10
  7. package/dist/src/code_assist/converter.test.js.map +1 -1
  8. package/dist/src/code_assist/server.d.ts +2 -2
  9. package/dist/src/code_assist/server.js +4 -4
  10. package/dist/src/code_assist/server.js.map +1 -1
  11. package/dist/src/code_assist/server.test.js +9 -9
  12. package/dist/src/code_assist/server.test.js.map +1 -1
  13. package/dist/src/code_assist/setup.js +1 -1
  14. package/dist/src/code_assist/setup.js.map +1 -1
  15. package/dist/src/code_assist/setup.test.js +2 -2
  16. package/dist/src/code_assist/setup.test.js.map +1 -1
  17. package/dist/src/config/config.d.ts +19 -7
  18. package/dist/src/config/config.js +53 -15
  19. package/dist/src/config/config.js.map +1 -1
  20. package/dist/src/config/config.test.js +93 -0
  21. package/dist/src/config/config.test.js.map +1 -1
  22. package/dist/src/config/flashFallback.test.js +23 -47
  23. package/dist/src/config/flashFallback.test.js.map +1 -1
  24. package/dist/src/config/models.d.ts +1 -0
  25. package/dist/src/config/models.js +1 -0
  26. package/dist/src/config/models.js.map +1 -1
  27. package/dist/src/core/client.d.ts +3 -1
  28. package/dist/src/core/client.js +74 -23
  29. package/dist/src/core/client.js.map +1 -1
  30. package/dist/src/core/client.test.js +167 -21
  31. package/dist/src/core/client.test.js.map +1 -1
  32. package/dist/src/core/contentGenerator.d.ts +2 -2
  33. package/dist/src/core/contentGenerator.js.map +1 -1
  34. package/dist/src/core/coreToolScheduler.d.ts +1 -3
  35. package/dist/src/core/coreToolScheduler.js +25 -16
  36. package/dist/src/core/coreToolScheduler.js.map +1 -1
  37. package/dist/src/core/coreToolScheduler.test.js +76 -1
  38. package/dist/src/core/coreToolScheduler.test.js.map +1 -1
  39. package/dist/src/core/geminiChat.js +3 -2
  40. package/dist/src/core/geminiChat.js.map +1 -1
  41. package/dist/src/core/geminiChat.test.js +2 -2
  42. package/dist/src/core/geminiChat.test.js.map +1 -1
  43. package/dist/src/core/logger.d.ts +1 -0
  44. package/dist/src/core/logger.js +22 -8
  45. package/dist/src/core/logger.js.map +1 -1
  46. package/dist/src/core/logger.test.js +60 -9
  47. package/dist/src/core/logger.test.js.map +1 -1
  48. package/dist/src/core/nonInteractiveToolExecutor.js +11 -3
  49. package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
  50. package/dist/src/core/prompts.js +1 -1
  51. package/dist/src/core/tokenLimits.js +1 -0
  52. package/dist/src/core/tokenLimits.js.map +1 -1
  53. package/dist/src/core/turn.d.ts +3 -0
  54. package/dist/src/core/turn.js +3 -0
  55. package/dist/src/core/turn.js.map +1 -1
  56. package/dist/src/ide/detect-ide.d.ts +10 -0
  57. package/dist/src/ide/detect-ide.js +27 -0
  58. package/dist/src/ide/detect-ide.js.map +1 -0
  59. package/dist/src/ide/ide-client.d.ts +19 -7
  60. package/dist/src/ide/ide-client.js +100 -36
  61. package/dist/src/ide/ide-client.js.map +1 -1
  62. package/dist/src/ide/ide-installer.d.ts +14 -0
  63. package/dist/src/ide/ide-installer.js +109 -0
  64. package/dist/src/ide/ide-installer.js.map +1 -0
  65. package/dist/src/ide/ide-installer.test.d.ts +6 -0
  66. package/dist/src/ide/ide-installer.test.js +55 -0
  67. package/dist/src/ide/ide-installer.test.js.map +1 -0
  68. package/dist/src/ide/ideContext.d.ts +212 -107
  69. package/dist/src/ide/ideContext.js +45 -44
  70. package/dist/src/ide/ideContext.js.map +1 -1
  71. package/dist/src/ide/ideContext.test.js +254 -100
  72. package/dist/src/ide/ideContext.test.js.map +1 -1
  73. package/dist/src/index.d.ts +4 -0
  74. package/dist/src/index.js +4 -0
  75. package/dist/src/index.js.map +1 -1
  76. package/dist/src/mcp/oauth-provider.js +3 -3
  77. package/dist/src/mcp/oauth-provider.js.map +1 -1
  78. package/dist/src/mcp/oauth-provider.test.js +9 -8
  79. package/dist/src/mcp/oauth-provider.test.js.map +1 -1
  80. package/dist/src/mcp/oauth-utils.js +2 -2
  81. package/dist/src/mcp/oauth-utils.js.map +1 -1
  82. package/dist/src/mcp/oauth-utils.test.js +1 -1
  83. package/dist/src/mcp/oauth-utils.test.js.map +1 -1
  84. package/dist/src/services/loopDetectionService.d.ts +3 -0
  85. package/dist/src/services/loopDetectionService.js +18 -0
  86. package/dist/src/services/loopDetectionService.js.map +1 -1
  87. package/dist/src/services/loopDetectionService.test.js +90 -11
  88. package/dist/src/services/loopDetectionService.test.js.map +1 -1
  89. package/dist/src/services/shellExecutionService.js +7 -4
  90. package/dist/src/services/shellExecutionService.js.map +1 -1
  91. package/dist/src/services/shellExecutionService.test.js +11 -5
  92. package/dist/src/services/shellExecutionService.test.js.map +1 -1
  93. package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +4 -2
  94. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +83 -35
  95. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
  96. package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +6 -1
  97. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +19 -0
  98. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
  99. package/dist/src/telemetry/constants.d.ts +2 -1
  100. package/dist/src/telemetry/constants.js +2 -1
  101. package/dist/src/telemetry/constants.js.map +1 -1
  102. package/dist/src/telemetry/index.d.ts +2 -2
  103. package/dist/src/telemetry/index.js +2 -2
  104. package/dist/src/telemetry/index.js.map +1 -1
  105. package/dist/src/telemetry/loggers.d.ts +3 -2
  106. package/dist/src/telemetry/loggers.js +21 -5
  107. package/dist/src/telemetry/loggers.js.map +1 -1
  108. package/dist/src/telemetry/loggers.test.circular.js +2 -0
  109. package/dist/src/telemetry/loggers.test.circular.js.map +1 -1
  110. package/dist/src/telemetry/loggers.test.js +8 -3
  111. package/dist/src/telemetry/loggers.test.js.map +1 -1
  112. package/dist/src/telemetry/telemetry.test.js +2 -0
  113. package/dist/src/telemetry/telemetry.test.js.map +1 -1
  114. package/dist/src/telemetry/types.d.ts +19 -4
  115. package/dist/src/telemetry/types.js +30 -4
  116. package/dist/src/telemetry/types.js.map +1 -1
  117. package/dist/src/telemetry/uiTelemetry.test.js +3 -0
  118. package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
  119. package/dist/src/test-utils/mockWorkspaceContext.d.ts +13 -0
  120. package/dist/src/test-utils/mockWorkspaceContext.js +24 -0
  121. package/dist/src/test-utils/mockWorkspaceContext.js.map +1 -0
  122. package/dist/src/tools/edit.js +27 -3
  123. package/dist/src/tools/edit.js.map +1 -1
  124. package/dist/src/tools/edit.test.js +104 -1
  125. package/dist/src/tools/edit.test.js.map +1 -1
  126. package/dist/src/tools/glob.js +53 -17
  127. package/dist/src/tools/glob.js.map +1 -1
  128. package/dist/src/tools/glob.test.js +25 -2
  129. package/dist/src/tools/glob.test.js.map +1 -1
  130. package/dist/src/tools/grep.d.ts +1 -1
  131. package/dist/src/tools/grep.js +81 -29
  132. package/dist/src/tools/grep.js.map +1 -1
  133. package/dist/src/tools/grep.test.js +72 -5
  134. package/dist/src/tools/grep.test.js.map +1 -1
  135. package/dist/src/tools/ls.js +4 -3
  136. package/dist/src/tools/ls.js.map +1 -1
  137. package/dist/src/tools/ls.test.d.ts +6 -0
  138. package/dist/src/tools/ls.test.js +356 -0
  139. package/dist/src/tools/ls.test.js.map +1 -0
  140. package/dist/src/tools/mcp-client.d.ts +1 -1
  141. package/dist/src/tools/mcp-client.js +37 -31
  142. package/dist/src/tools/mcp-client.js.map +1 -1
  143. package/dist/src/tools/mcp-client.test.js +34 -0
  144. package/dist/src/tools/mcp-client.test.js.map +1 -1
  145. package/dist/src/tools/memoryTool.d.ts +17 -2
  146. package/dist/src/tools/memoryTool.js +130 -13
  147. package/dist/src/tools/memoryTool.js.map +1 -1
  148. package/dist/src/tools/memoryTool.test.js +88 -3
  149. package/dist/src/tools/memoryTool.test.js.map +1 -1
  150. package/dist/src/tools/read-file.js +8 -6
  151. package/dist/src/tools/read-file.js.map +1 -1
  152. package/dist/src/tools/read-file.test.js +30 -2
  153. package/dist/src/tools/read-file.test.js.map +1 -1
  154. package/dist/src/tools/read-many-files.js +22 -12
  155. package/dist/src/tools/read-many-files.js.map +1 -1
  156. package/dist/src/tools/read-many-files.test.js +35 -2
  157. package/dist/src/tools/read-many-files.test.js.map +1 -1
  158. package/dist/src/tools/shell.js +8 -4
  159. package/dist/src/tools/shell.js.map +1 -1
  160. package/dist/src/tools/shell.test.js +33 -1
  161. package/dist/src/tools/shell.test.js.map +1 -1
  162. package/dist/src/tools/tool-error.d.ts +22 -0
  163. package/dist/src/tools/tool-error.js +27 -0
  164. package/dist/src/tools/tool-error.js.map +1 -0
  165. package/dist/src/tools/tool-registry.test.js +8 -0
  166. package/dist/src/tools/tool-registry.test.js.map +1 -1
  167. package/dist/src/tools/tools.d.ts +8 -0
  168. package/dist/src/tools/tools.js.map +1 -1
  169. package/dist/src/tools/write-file.js +7 -5
  170. package/dist/src/tools/write-file.js.map +1 -1
  171. package/dist/src/tools/write-file.test.js +56 -2
  172. package/dist/src/tools/write-file.test.js.map +1 -1
  173. package/dist/src/utils/bfsFileSearch.js +51 -27
  174. package/dist/src/utils/bfsFileSearch.js.map +1 -1
  175. package/dist/src/utils/bfsFileSearch.test.js +59 -0
  176. package/dist/src/utils/bfsFileSearch.test.js.map +1 -1
  177. package/dist/src/utils/editCorrector.js +2 -2
  178. package/dist/src/utils/editCorrector.js.map +1 -1
  179. package/dist/src/utils/editor.d.ts +1 -1
  180. package/dist/src/utils/editor.js +9 -0
  181. package/dist/src/utils/editor.js.map +1 -1
  182. package/dist/src/utils/editor.test.js +21 -1
  183. package/dist/src/utils/editor.test.js.map +1 -1
  184. package/dist/src/utils/fileUtils.js +12 -1
  185. package/dist/src/utils/fileUtils.js.map +1 -1
  186. package/dist/src/utils/fileUtils.test.js +29 -1
  187. package/dist/src/utils/fileUtils.test.js.map +1 -1
  188. package/dist/src/utils/flashFallback.integration.test.js +8 -0
  189. package/dist/src/utils/flashFallback.integration.test.js.map +1 -1
  190. package/dist/src/utils/memoryDiscovery.d.ts +1 -1
  191. package/dist/src/utils/memoryDiscovery.js +54 -75
  192. package/dist/src/utils/memoryDiscovery.js.map +1 -1
  193. package/dist/src/utils/memoryDiscovery.test.js +4 -3
  194. package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
  195. package/dist/src/utils/memoryImportProcessor.d.ts +19 -12
  196. package/dist/src/utils/memoryImportProcessor.js +241 -82
  197. package/dist/src/utils/memoryImportProcessor.js.map +1 -1
  198. package/dist/src/utils/memoryImportProcessor.test.js +595 -50
  199. package/dist/src/utils/memoryImportProcessor.test.js.map +1 -1
  200. package/dist/src/utils/nextSpeakerChecker.js +3 -23
  201. package/dist/src/utils/nextSpeakerChecker.js.map +1 -1
  202. package/dist/src/utils/nextSpeakerChecker.test.js +2 -2
  203. package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -1
  204. package/dist/src/utils/paths.d.ts +11 -2
  205. package/dist/src/utils/paths.js +24 -7
  206. package/dist/src/utils/paths.js.map +1 -1
  207. package/dist/src/utils/paths.test.d.ts +6 -0
  208. package/dist/src/utils/paths.test.js +153 -0
  209. package/dist/src/utils/paths.test.js.map +1 -0
  210. package/dist/src/utils/retry.d.ts +3 -0
  211. package/dist/src/utils/retry.js.map +1 -1
  212. package/dist/src/utils/retry.test.js.map +1 -1
  213. package/dist/src/utils/secure-browser-launcher.d.ts +23 -0
  214. package/dist/src/utils/secure-browser-launcher.js +164 -0
  215. package/dist/src/utils/secure-browser-launcher.js.map +1 -0
  216. package/dist/src/utils/secure-browser-launcher.test.d.ts +6 -0
  217. package/dist/src/utils/secure-browser-launcher.test.js +149 -0
  218. package/dist/src/utils/secure-browser-launcher.test.js.map +1 -0
  219. package/dist/src/utils/summarizer.js +2 -2
  220. package/dist/src/utils/summarizer.js.map +1 -1
  221. package/dist/src/utils/workspaceContext.d.ts +47 -0
  222. package/dist/src/utils/workspaceContext.js +106 -0
  223. package/dist/src/utils/workspaceContext.js.map +1 -0
  224. package/dist/src/utils/workspaceContext.test.d.ts +6 -0
  225. package/dist/src/utils/workspaceContext.test.js +209 -0
  226. package/dist/src/utils/workspaceContext.test.js.map +1 -0
  227. package/dist/tsconfig.tsbuildinfo +1 -1
  228. package/package.json +2 -1
  229. package/dist/google-gemini-cli-core-0.1.13.tgz +0 -0
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Opens a URL in the default browser using platform-specific commands.
8
+ * This implementation avoids shell injection vulnerabilities by:
9
+ * 1. Validating the URL to ensure it's HTTP/HTTPS only
10
+ * 2. Using execFile instead of exec to avoid shell interpretation
11
+ * 3. Passing the URL as an argument rather than constructing a command string
12
+ *
13
+ * @param url The URL to open
14
+ * @throws Error if the URL is invalid or if opening the browser fails
15
+ */
16
+ export declare function openBrowserSecurely(url: string): Promise<void>;
17
+ /**
18
+ * Checks if the current environment should attempt to launch a browser.
19
+ * This is the same logic as in browser.ts for consistency.
20
+ *
21
+ * @returns True if the tool should attempt to launch a browser
22
+ */
23
+ export declare function shouldLaunchBrowser(): boolean;
@@ -0,0 +1,164 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { execFile } from 'node:child_process';
7
+ import { promisify } from 'node:util';
8
+ import { platform } from 'node:os';
9
+ import { URL } from 'node:url';
10
+ const execFileAsync = promisify(execFile);
11
+ /**
12
+ * Validates that a URL is safe to open in a browser.
13
+ * Only allows HTTP and HTTPS URLs to prevent command injection.
14
+ *
15
+ * @param url The URL to validate
16
+ * @throws Error if the URL is invalid or uses an unsafe protocol
17
+ */
18
+ function validateUrl(url) {
19
+ let parsedUrl;
20
+ try {
21
+ parsedUrl = new URL(url);
22
+ }
23
+ catch (_error) {
24
+ throw new Error(`Invalid URL: ${url}`);
25
+ }
26
+ // Only allow HTTP and HTTPS protocols
27
+ if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
28
+ throw new Error(`Unsafe protocol: ${parsedUrl.protocol}. Only HTTP and HTTPS are allowed.`);
29
+ }
30
+ // Additional validation: ensure no newlines or control characters
31
+ // eslint-disable-next-line no-control-regex
32
+ if (/[\r\n\x00-\x1f]/.test(url)) {
33
+ throw new Error('URL contains invalid characters');
34
+ }
35
+ }
36
+ /**
37
+ * Opens a URL in the default browser using platform-specific commands.
38
+ * This implementation avoids shell injection vulnerabilities by:
39
+ * 1. Validating the URL to ensure it's HTTP/HTTPS only
40
+ * 2. Using execFile instead of exec to avoid shell interpretation
41
+ * 3. Passing the URL as an argument rather than constructing a command string
42
+ *
43
+ * @param url The URL to open
44
+ * @throws Error if the URL is invalid or if opening the browser fails
45
+ */
46
+ export async function openBrowserSecurely(url) {
47
+ // Validate the URL first
48
+ validateUrl(url);
49
+ const platformName = platform();
50
+ let command;
51
+ let args;
52
+ switch (platformName) {
53
+ case 'darwin':
54
+ // macOS
55
+ command = 'open';
56
+ args = [url];
57
+ break;
58
+ case 'win32':
59
+ // Windows - use PowerShell with Start-Process
60
+ // This avoids the cmd.exe shell which is vulnerable to injection
61
+ command = 'powershell.exe';
62
+ args = [
63
+ '-NoProfile',
64
+ '-NonInteractive',
65
+ '-WindowStyle',
66
+ 'Hidden',
67
+ '-Command',
68
+ `Start-Process '${url.replace(/'/g, "''")}'`,
69
+ ];
70
+ break;
71
+ case 'linux':
72
+ case 'freebsd':
73
+ case 'openbsd':
74
+ // Linux and BSD variants
75
+ // Try xdg-open first, fall back to other options
76
+ command = 'xdg-open';
77
+ args = [url];
78
+ break;
79
+ default:
80
+ throw new Error(`Unsupported platform: ${platformName}`);
81
+ }
82
+ const options = {
83
+ // Don't inherit parent's environment to avoid potential issues
84
+ env: {
85
+ ...process.env,
86
+ // Ensure we're not in a shell that might interpret special characters
87
+ SHELL: undefined,
88
+ },
89
+ // Detach the browser process so it doesn't block
90
+ detached: true,
91
+ stdio: 'ignore',
92
+ };
93
+ try {
94
+ await execFileAsync(command, args, options);
95
+ }
96
+ catch (error) {
97
+ // For Linux, try fallback commands if xdg-open fails
98
+ if ((platformName === 'linux' ||
99
+ platformName === 'freebsd' ||
100
+ platformName === 'openbsd') &&
101
+ command === 'xdg-open') {
102
+ const fallbackCommands = [
103
+ 'gnome-open',
104
+ 'kde-open',
105
+ 'firefox',
106
+ 'chromium',
107
+ 'google-chrome',
108
+ ];
109
+ for (const fallbackCommand of fallbackCommands) {
110
+ try {
111
+ await execFileAsync(fallbackCommand, [url], options);
112
+ return; // Success!
113
+ }
114
+ catch {
115
+ // Try next command
116
+ continue;
117
+ }
118
+ }
119
+ }
120
+ // Re-throw the error if all attempts failed
121
+ throw new Error(`Failed to open browser: ${error instanceof Error ? error.message : 'Unknown error'}`);
122
+ }
123
+ }
124
+ /**
125
+ * Checks if the current environment should attempt to launch a browser.
126
+ * This is the same logic as in browser.ts for consistency.
127
+ *
128
+ * @returns True if the tool should attempt to launch a browser
129
+ */
130
+ export function shouldLaunchBrowser() {
131
+ // A list of browser names that indicate we should not attempt to open a
132
+ // web browser for the user.
133
+ const browserBlocklist = ['www-browser'];
134
+ const browserEnv = process.env.BROWSER;
135
+ if (browserEnv && browserBlocklist.includes(browserEnv)) {
136
+ return false;
137
+ }
138
+ // Common environment variables used in CI/CD or other non-interactive shells.
139
+ if (process.env.CI || process.env.DEBIAN_FRONTEND === 'noninteractive') {
140
+ return false;
141
+ }
142
+ // The presence of SSH_CONNECTION indicates a remote session.
143
+ // We should not attempt to launch a browser unless a display is explicitly available
144
+ // (checked below for Linux).
145
+ const isSSH = !!process.env.SSH_CONNECTION;
146
+ // On Linux, the presence of a display server is a strong indicator of a GUI.
147
+ if (platform() === 'linux') {
148
+ // These are environment variables that can indicate a running compositor on Linux.
149
+ const displayVariables = ['DISPLAY', 'WAYLAND_DISPLAY', 'MIR_SOCKET'];
150
+ const hasDisplay = displayVariables.some((v) => !!process.env[v]);
151
+ if (!hasDisplay) {
152
+ return false;
153
+ }
154
+ }
155
+ // If in an SSH session on a non-Linux OS (e.g., macOS), don't launch browser.
156
+ // The Linux case is handled above (it's allowed if DISPLAY is set).
157
+ if (isSSH && platform() !== 'linux') {
158
+ return false;
159
+ }
160
+ // For non-Linux OSes, we generally assume a GUI is available
161
+ // unless other signals (like SSH) suggest otherwise.
162
+ return true;
163
+ }
164
+ //# sourceMappingURL=secure-browser-launcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-browser-launcher.js","sourceRoot":"","sources":["../../../src/utils/secure-browser-launcher.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,GAAW;IAC9B,IAAI,SAAc,CAAC;IAEnB,IAAI,CAAC;QACH,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,gBAAgB,GAAG,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,sCAAsC;IACtC,IAAI,SAAS,CAAC,QAAQ,KAAK,OAAO,IAAI,SAAS,CAAC,QAAQ,KAAK,QAAQ,EAAE,C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AAC,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,KAAK,gBAAgB,EAAE,CAAC;QACvE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,6DAA6D;IAC7D,qFAAqF;IACrF,6BAA6B;IAC7B,MAAM,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IAE3C,6EAA6E;IAC7E,IAAI,QAAQ,EAAE,KAAK,OAAO,EAAE,CAAC;QAC3B,mFAAmF;QACnF,MAAM,gBAAgB,GAAG,CAAC,SAAS,EAAE,iBAAiB,EAAE,YAAY,CAAC,CAAC;QACtE,MAAM,UAAU,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAClE,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,8EAA8E;IAC9E,oEAAoE;IACpE,IAAI,KAAK,IAAI,QAAQ,EAAE,KAAK,OAAO,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,6DAA6D;IAC7D,qDAAqD;IACrD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export {};
@@ -0,0 +1,149 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
7
+ import { openBrowserSecurely } from './secure-browser-launcher.js';
8
+ // Create mock function using vi.hoisted
9
+ const mockExecFile = vi.hoisted(() => vi.fn());
10
+ // Mock modules
11
+ vi.mock('node:child_process');
12
+ vi.mock('node:util', () => ({
13
+ promisify: () => mockExecFile,
14
+ }));
15
+ describe('secure-browser-launcher', () => {
16
+ let originalPlatform;
17
+ beforeEach(() => {
18
+ vi.clearAllMocks();
19
+ mockExecFile.mockResolvedValue({ stdout: '', stderr: '' });
20
+ originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform');
21
+ });
22
+ afterEach(() => {
23
+ if (originalPlatform) {
24
+ Object.defineProperty(process, 'platform', originalPlatform);
25
+ }
26
+ });
27
+ function setPlatform(platform) {
28
+ Object.defineProperty(process, 'platform', {
29
+ value: platform,
30
+ configurable: true,
31
+ });
32
+ }
33
+ describe('URL validation', () => {
34
+ it('should allow valid HTTP URLs', async () => {
35
+ setPlatform('darwin');
36
+ await openBrowserSecurely('http://example.com');
37
+ expect(mockExecFile).toHaveBeenCalledWith('open', ['http://example.com'], expect.any(Object));
38
+ });
39
+ it('should allow valid HTTPS URLs', async () => {
40
+ setPlatform('darwin');
41
+ await openBrowserSecurely('https://example.com');
42
+ expect(mockExecFile).toHaveBeenCalledWith('open', ['https://example.com'], expect.any(Object));
43
+ });
44
+ it('should reject non-HTTP(S) protocols', async () => {
45
+ await expect(openBrowserSecurely('file:///etc/passwd')).rejects.toThrow('Unsafe protocol');
46
+ await expect(openBrowserSecurely('javascript:alert(1)')).rejects.toThrow('Unsafe protocol');
47
+ await expect(openBrowserSecurely('ftp://example.com')).rejects.toThrow('Unsafe protocol');
48
+ });
49
+ it('should reject invalid URLs', async () => {
50
+ await expect(openBrowserSecurely('not-a-url')).rejects.toThrow('Invalid URL');
51
+ await expect(openBrowserSecurely('')).rejects.toThrow('Invalid URL');
52
+ });
53
+ it('should reject URLs with control characters', async () => {
54
+ await expect(openBrowserSecurely('http://example.com\nmalicious-command')).rejects.toThrow('invalid characters');
55
+ await expect(openBrowserSecurely('http://example.com\rmalicious-command')).rejects.toThrow('invalid characters');
56
+ await expect(openBrowserSecurely('http://example.com\x00')).rejects.toThrow('invalid characters');
57
+ });
58
+ });
59
+ describe('Command injection prevention', () => {
60
+ it('should prevent PowerShell command injection on Windows', async () => {
61
+ setPlatform('win32');
62
+ // The POC from the vulnerability report
63
+ const maliciousUrl = "http://127.0.0.1:8080/?param=example#$(Invoke-Expression([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('Y2FsYy5leGU='))))";
64
+ await openBrowserSecurely(maliciousUrl);
65
+ // Verify that execFile was called (not exec) and the URL is passed safely
66
+ expect(mockExecFile).toHaveBeenCalledWith('powershell.exe', [
67
+ '-NoProfile',
68
+ '-NonInteractive',
69
+ '-WindowStyle',
70
+ 'Hidden',
71
+ '-Command',
72
+ `Start-Process '${maliciousUrl.replace(/'/g, "''")}'`,
73
+ ], expect.any(Object));
74
+ });
75
+ it('should handle URLs with special shell characters safely', async () => {
76
+ setPlatform('darwin');
77
+ const urlsWithSpecialChars = [
78
+ 'http://example.com/path?param=value&other=$value',
79
+ 'http://example.com/path#fragment;command',
80
+ 'http://example.com/$(whoami)',
81
+ 'http://example.com/`command`',
82
+ 'http://example.com/|pipe',
83
+ 'http://example.com/>redirect',
84
+ ];
85
+ for (const url of urlsWithSpecialChars) {
86
+ await openBrowserSecurely(url);
87
+ // Verify the URL is passed as an argument, not interpreted by shell
88
+ expect(mockExecFile).toHaveBeenCalledWith('open', [url], expect.any(Object));
89
+ }
90
+ });
91
+ it('should properly escape single quotes in URLs on Windows', async () => {
92
+ setPlatform('win32');
93
+ const urlWithSingleQuotes = "http://example.com/path?name=O'Brien&test='value'";
94
+ await openBrowserSecurely(urlWithSingleQuotes);
95
+ // Verify that single quotes are escaped by doubling them
96
+ expect(mockExecFile).toHaveBeenCalledWith('powershell.exe', [
97
+ '-NoProfile',
98
+ '-NonInteractive',
99
+ '-WindowStyle',
100
+ 'Hidden',
101
+ '-Command',
102
+ `Start-Process 'http://example.com/path?name=O''Brien&test=''value'''`,
103
+ ], expect.any(Object));
104
+ });
105
+ });
106
+ describe('Platform-specific behavior', () => {
107
+ it('should use correct command on macOS', async () => {
108
+ setPlatform('darwin');
109
+ await openBrowserSecurely('https://example.com');
110
+ expect(mockExecFile).toHaveBeenCalledWith('open', ['https://example.com'], expect.any(Object));
111
+ });
112
+ it('should use PowerShell on Windows', async () => {
113
+ setPlatform('win32');
114
+ await openBrowserSecurely('https://example.com');
115
+ expect(mockExecFile).toHaveBeenCalledWith('powershell.exe', expect.arrayContaining([
116
+ '-Command',
117
+ `Start-Process 'https://example.com'`,
118
+ ]), expect.any(Object));
119
+ });
120
+ it('should use xdg-open on Linux', async () => {
121
+ setPlatform('linux');
122
+ await openBrowserSecurely('https://example.com');
123
+ expect(mockExecFile).toHaveBeenCalledWith('xdg-open', ['https://example.com'], expect.any(Object));
124
+ });
125
+ it('should throw on unsupported platforms', async () => {
126
+ setPlatform('aix');
127
+ await expect(openBrowserSecurely('https://example.com')).rejects.toThrow('Unsupported platform');
128
+ });
129
+ });
130
+ describe('Error handling', () => {
131
+ it('should handle browser launch failures gracefully', async () => {
132
+ setPlatform('darwin');
133
+ mockExecFile.mockRejectedValueOnce(new Error('Command not found'));
134
+ await expect(openBrowserSecurely('https://example.com')).rejects.toThrow('Failed to open browser');
135
+ });
136
+ it('should try fallback browsers on Linux', async () => {
137
+ setPlatform('linux');
138
+ // First call to xdg-open fails
139
+ mockExecFile.mockRejectedValueOnce(new Error('Command not found'));
140
+ // Second call to gnome-open succeeds
141
+ mockExecFile.mockResolvedValueOnce({ stdout: '', stderr: '' });
142
+ await openBrowserSecurely('https://example.com');
143
+ expect(mockExecFile).toHaveBeenCalledTimes(2);
144
+ expect(mockExecFile).toHaveBeenNthCalledWith(1, 'xdg-open', ['https://example.com'], expect.any(Object));
145
+ expect(mockExecFile).toHaveBeenNthCalledWith(2, 'gnome-open', ['https://example.com'], expect.any(Object));
146
+ });
147
+ });
148
+ });
149
+ //# sourceMappingURL=secure-browser-launcher.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-browser-launcher.test.js","sourceRoot":"","sources":["../../../src/utils/secure-browser-launcher.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;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CAAC,qBAAqB,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;YAE/D,MAAM,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;YAEjD,MAAM,CAAC,YAAY,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;YAC9C,MAAM,CAAC,YAAY,CAAC,CAAC,uBAAuB,CAC1C,CAAC,EACD,UAAU,EACV,CAAC,qBAAqB,CAAC,EACvB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CACnB,CAAC;YACF,MAAM,CAAC,YAAY,CAAC,CAAC,uBAAuB,CAC1C,CAAC,EACD,YAAY,EACZ,CAAC,qBAAqB,CAAC,EACvB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CACnB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -3,7 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
6
+ import { DEFAULT_GEMINI_FLASH_LITE_MODEL } from '../config/models.js';
7
7
  import { getResponseText, partToString } from './partUtils.js';
8
8
  /**
9
9
  * The default summarizer for tool results.
@@ -40,7 +40,7 @@ export async function summarizeToolOutput(textToSummarize, geminiClient, abortSi
40
40
  maxOutputTokens,
41
41
  };
42
42
  try {
43
- const parsedResponse = (await geminiClient.generateContent(contents, toolOutputSummarizerConfig, abortSignal, DEFAULT_GEMINI_FLASH_MODEL));
43
+ const parsedResponse = (await geminiClient.generateContent(contents, toolOutputSummarizerConfig, abortSignal, DEFAULT_GEMINI_FLASH_LITE_MODEL));
44
44
  return getResponseText(parsedResponse) || textToSummarize;
45
45
  }
46
46
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"summarizer.js","sourceRoot":"","sources":["../../../src/utils/summarizer.ts"],"names":[],"mappings":"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AC,OAAO,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAC;IAEhD,MAAM,QAAQ,GAAc,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;IAC1E,MAAM,0BAA0B,GAA0B;QACxD,eAAe;KAChB,CAAC;IACF,IAAI,CAAC;QACH,MAAM,cAAc,GAAG,CAAC,MAAM,YAAY,CAAC,eAAe,CACxD,QAAQ,EACR,0BAA0B,EAC1B,WAAW,EACX,+BAA+B,CAChC,CAAuC,CAAC;QACzC,OAAO,eAAe,CAAC,cAAc,CAAC,IAAI,eAAe,CAAC;IAC5D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;QACzD,OAAO,eAAe,CAAC;IACzB,CAAC;AACH,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * WorkspaceContext manages multiple workspace directories and validates paths
8
+ * against them. This allows the CLI to operate on files from multiple directories
9
+ * in a single session.
10
+ */
11
+ export declare class WorkspaceContext {
12
+ private directories;
13
+ /**
14
+ * Creates a new WorkspaceContext with the given initial directory and optional additional directories.
15
+ * @param initialDirectory The initial working directory (usually cwd)
16
+ * @param additionalDirectories Optional array of additional directories to include
17
+ */
18
+ constructor(initialDirectory: string, additionalDirectories?: string[]);
19
+ /**
20
+ * Adds a directory to the workspace.
21
+ * @param directory The directory path to add (can be relative or absolute)
22
+ * @param basePath Optional base path for resolving relative paths (defaults to cwd)
23
+ */
24
+ addDirectory(directory: string, basePath?: string): void;
25
+ /**
26
+ * Internal method to add a directory with validation.
27
+ */
28
+ private addDirectoryInternal;
29
+ /**
30
+ * Gets a copy of all workspace directories.
31
+ * @returns Array of absolute directory paths
32
+ */
33
+ getDirectories(): readonly string[];
34
+ /**
35
+ * Checks if a given path is within any of the workspace directories.
36
+ * @param pathToCheck The path to validate
37
+ * @returns True if the path is within the workspace, false otherwise
38
+ */
39
+ isPathWithinWorkspace(pathToCheck: string): boolean;
40
+ /**
41
+ * Checks if a path is within a given root directory.
42
+ * @param pathToCheck The absolute path to check
43
+ * @param rootDirectory The absolute root directory
44
+ * @returns True if the path is within the root directory, false otherwise
45
+ */
46
+ private isPathWithinRoot;
47
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import * as fs from 'fs';
7
+ import * as path from 'path';
8
+ /**
9
+ * WorkspaceContext manages multiple workspace directories and validates paths
10
+ * against them. This allows the CLI to operate on files from multiple directories
11
+ * in a single session.
12
+ */
13
+ export class WorkspaceContext {
14
+ directories;
15
+ /**
16
+ * Creates a new WorkspaceContext with the given initial directory and optional additional directories.
17
+ * @param initialDirectory The initial working directory (usually cwd)
18
+ * @param additionalDirectories Optional array of additional directories to include
19
+ */
20
+ constructor(initialDirectory, additionalDirectories = []) {
21
+ this.directories = new Set();
22
+ this.addDirectoryInternal(initialDirectory);
23
+ for (const dir of additionalDirectories) {
24
+ this.addDirectoryInternal(dir);
25
+ }
26
+ }
27
+ /**
28
+ * Adds a directory to the workspace.
29
+ * @param directory The directory path to add (can be relative or absolute)
30
+ * @param basePath Optional base path for resolving relative paths (defaults to cwd)
31
+ */
32
+ addDirectory(directory, basePath = process.cwd()) {
33
+ this.addDirectoryInternal(directory, basePath);
34
+ }
35
+ /**
36
+ * Internal method to add a directory with validation.
37
+ */
38
+ addDirectoryInternal(directory, basePath = process.cwd()) {
39
+ const absolutePath = path.isAbsolute(directory)
40
+ ? directory
41
+ : path.resolve(basePath, directory);
42
+ if (!fs.existsSync(absolutePath)) {
43
+ throw new Error(`Directory does not exist: ${absolutePath}`);
44
+ }
45
+ const stats = fs.statSync(absolutePath);
46
+ if (!stats.isDirectory()) {
47
+ throw new Error(`Path is not a directory: ${absolutePath}`);
48
+ }
49
+ let realPath;
50
+ try {
51
+ realPath = fs.realpathSync(absolutePath);
52
+ }
53
+ catch (_error) {
54
+ throw new Error(`Failed to resolve path: ${absolutePath}`);
55
+ }
56
+ this.directories.add(realPath);
57
+ }
58
+ /**
59
+ * Gets a copy of all workspace directories.
60
+ * @returns Array of absolute directory paths
61
+ */
62
+ getDirectories() {
63
+ return Array.from(this.directories);
64
+ }
65
+ /**
66
+ * Checks if a given path is within any of the workspace directories.
67
+ * @param pathToCheck The path to validate
68
+ * @returns True if the path is within the workspace, false otherwise
69
+ */
70
+ isPathWithinWorkspace(pathToCheck) {
71
+ try {
72
+ const absolutePath = path.resolve(pathToCheck);
73
+ let resolvedPath = absolutePath;
74
+ if (fs.existsSync(absolutePath)) {
75
+ try {
76
+ resolvedPath = fs.realpathSync(absolutePath);
77
+ }
78
+ catch (_error) {
79
+ return false;
80
+ }
81
+ }
82
+ for (const dir of this.directories) {
83
+ if (this.isPathWithinRoot(resolvedPath, dir)) {
84
+ return true;
85
+ }
86
+ }
87
+ return false;
88
+ }
89
+ catch (_error) {
90
+ return false;
91
+ }
92
+ }
93
+ /**
94
+ * Checks if a path is within a given root directory.
95
+ * @param pathToCheck The absolute path to check
96
+ * @param rootDirectory The absolute root directory
97
+ * @returns True if the path is within the root directory, false otherwise
98
+ */
99
+ isPathWithinRoot(pathToCheck, rootDirectory) {
100
+ const relative = path.relative(rootDirectory, pathToCheck);
101
+ return (!relative.startsWith(`..${path.sep}`) &&
102
+ relative !== '..' &&
103
+ !path.isAbsolute(relative));
104
+ }
105
+ }
106
+ //# sourceMappingURL=workspaceContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspaceContext.js","sourceRoot":"","sources":["../../../src/utils/workspaceContext.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IA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