@google/gemini-cli 0.64.0-nightly.20261005.gfb972b2f8 → 0.64.0-preview.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/bundle/{chunk-PO2VSL43.js → chunk-2NQXIWQK.js} +5 -7
  2. package/bundle/{chunk-JUHOHELL.js → chunk-6OFXOGEG.js} +14846 -7842
  3. package/bundle/{chunk-EIWQ2LQQ.js → chunk-EBP6K2WG.js} +7 -7
  4. package/bundle/{chunk-EELKDWQ4.js → chunk-EDVFNWRG.js} +1 -1
  5. package/bundle/{chunk-EB43SHKX.js → chunk-EDYPRCAA.js} +2 -2
  6. package/bundle/{chunk-AQYLEGXG.js → chunk-HN74ORTP.js} +1 -1
  7. package/bundle/{chunk-H7GSTRIW.js → chunk-KCCVXZ52.js} +58 -71
  8. package/bundle/{chunk-JQYJUNLF.js → chunk-MLSLNORV.js} +3 -3
  9. package/bundle/{chunk-27FWUQTG.js → chunk-NX7TO2DU.js} +1 -1
  10. package/bundle/{chunk-NFSPTLUK.js → chunk-SDWOC67Z.js} +1 -1
  11. package/bundle/{chunk-2TCGCQ3U.js → chunk-UBGF6JU5.js} +1 -1
  12. package/bundle/{chunk-NALEOBWX.js → chunk-VBVCLWLA.js} +2 -2
  13. package/bundle/{chunk-UBR6TWNB.js → chunk-VJYKQD5D.js} +3 -3
  14. package/bundle/{chunk-Q5GLE3YW.js → chunk-Y2HXXBXI.js} +8 -9
  15. package/bundle/{chunk-OLLYWO5Q.js → chunk-ZOHM7BPT.js} +1 -1
  16. package/bundle/{chunk-CUFMYKIC.js → chunk-ZQW7OGUO.js} +3 -3
  17. package/bundle/{cleanup-4TGCO5X2.js → cleanup-GGCB2LVD.js} +2 -2
  18. package/bundle/{cleanup-6PBH36B7.js → cleanup-JRDG3OTL.js} +2 -2
  19. package/bundle/{dist-EKBAHHIJ.js → core-6HRWFQZW.js} +1 -1
  20. package/bundle/{devtoolsService-U6FKQ6JD.js → devtoolsService-MF6JKRUV.js} +3 -4
  21. package/bundle/{devtoolsService-DH4C7EZB.js → devtoolsService-XZCKFZP5.js} +2 -2
  22. package/bundle/{dist-UAE7T55Q.js → dist-7L3BRW6V.js} +1 -1
  23. package/bundle/{gemini-E3VK7GSB.js → gemini-JPMMQ3KA.js} +14 -14
  24. package/bundle/{gemini-IYF3YHXZ.js → gemini-QOQNG5VY.js} +198 -214
  25. package/bundle/gemini.js +7 -7
  26. package/bundle/{interactiveCli-WHZXRGLN.js → interactiveCli-R3P4A3FC.js} +293 -312
  27. package/bundle/{interactiveCli-T3HF2HRX.js → interactiveCli-UDWGRVJL.js} +8 -8
  28. package/bundle/{liteRtServerManager-X6UOQ3MA.js → liteRtServerManager-OVPUSK2T.js} +4 -4
  29. package/bundle/{liteRtServerManager-YUF3UXMU.js → liteRtServerManager-RAV63AGE.js} +4 -4
  30. package/bundle/{oauth2-provider-D4J3TFC3.js → oauth2-provider-FVTRRJZR.js} +1 -1
  31. package/bundle/{oauth2-provider-F7QKNLGE.js → oauth2-provider-XFP63FGJ.js} +72 -38
  32. package/bundle/{start-TO2FZTHQ.js → start-5O7TBK5L.js} +6 -6
  33. package/bundle/{start-U3PILSF7.js → start-VQQ2Q5KT.js} +6 -6
  34. package/package.json +1 -1
  35. package/bundle/chunk-6ISJPGCD.js +0 -154
  36. package/bundle/chunk-6LCUTDX7.js +0 -401196
  37. package/bundle/chunk-NBEG6GFX.js +0 -118
  38. package/bundle/chunk-PGYGRESN.js +0 -425
  39. package/bundle/chunk-QSGRHC6M.js +0 -1571
  40. package/bundle/chunk-UMTL4SBM.js +0 -103121
  41. package/bundle/chunk-UP3637TZ.js +0 -512
  42. package/bundle/chunk-XZLCMV4F.js +0 -17507
  43. package/bundle/cleanup-HQ46NIAL.js +0 -32
  44. package/bundle/devtoolsService-YL2CULLT.js +0 -4359
  45. package/bundle/dist-BVPLCCBS.js +0 -2252
  46. package/bundle/gemini-53BFSQPR.js +0 -17934
  47. package/bundle/interactiveCli-OHZNMG4G.js +0 -34979
  48. package/bundle/liteRtServerManager-KKZLBYK6.js +0 -65
  49. package/bundle/oauth2-provider-4V3LC2C5.js +0 -235
  50. package/bundle/start-JVWQ2CSF.js +0 -18
@@ -171,10 +171,10 @@ import {
171
171
  widestLineFromStyledChars,
172
172
  wordBreakStyledChars,
173
173
  wrapStyledChars
174
- } from "./chunk-EIWQ2LQQ.js";
174
+ } from "./chunk-EBP6K2WG.js";
175
175
  import {
176
176
  require_source
177
- } from "./chunk-OLLYWO5Q.js";
177
+ } from "./chunk-ZOHM7BPT.js";
178
178
  import {
179
179
  appEvents
180
180
  } from "./chunk-5PS3AYFU.js";
@@ -227,24 +227,24 @@ import {
227
227
  stripAnsi,
228
228
  stripUnsafeCharacters,
229
229
  toCodePoints
230
- } from "./chunk-AQYLEGXG.js";
230
+ } from "./chunk-HN74ORTP.js";
231
231
  import {
232
232
  handleAutoUpdate,
233
233
  isDevelopment,
234
234
  relaunchApp,
235
235
  setUpdateHandler
236
- } from "./chunk-EB43SHKX.js";
236
+ } from "./chunk-VBVCLWLA.js";
237
237
  import {
238
238
  isTodoList,
239
239
  mapCoreStatusToDisplayStatus,
240
240
  require_react
241
- } from "./chunk-Q5GLE3YW.js";
241
+ } from "./chunk-NX7TO2DU.js";
242
242
  import {
243
243
  registerCleanup,
244
244
  removeCleanup,
245
245
  runExitCleanup,
246
246
  setupTtyCheck
247
- } from "./chunk-NFSPTLUK.js";
247
+ } from "./chunk-UBGF6JU5.js";
248
248
  import {
249
249
  ACTIVATE_SKILL_TOOL_NAME,
250
250
  AGENT_TOOL_NAME,
@@ -449,7 +449,7 @@ import {
449
449
  validatePlanContent,
450
450
  validatePlanPath,
451
451
  writeToStdout
452
- } from "./chunk-JUHOHELL.js";
452
+ } from "./chunk-ZQW7OGUO.js";
453
453
  import "./chunk-664ZODQF.js";
454
454
  import "./chunk-IUUIT4SU.js";
455
455
  import "./chunk-L6PII3GR.js";
@@ -33954,7 +33954,7 @@ ${queuedText}` : queuedText;
33954
33954
  if (keyMatchers["app.showErrorDetails" /* SHOW_ERROR_DETAILS */](key)) {
33955
33955
  if (settings.merged.general.devtools) {
33956
33956
  void (async () => {
33957
- const { toggleDevToolsPanel } = await import("./devtoolsService-U6FKQ6JD.js");
33957
+ const { toggleDevToolsPanel } = await import("./devtoolsService-XZCKFZP5.js");
33958
33958
  await toggleDevToolsPanel(
33959
33959
  config,
33960
33960
  showErrorDetails,
@@ -3,11 +3,11 @@ import {
3
3
  DEFAULT_PORT,
4
4
  getBinaryPath,
5
5
  isServerRunning
6
- } from "./chunk-AQYLEGXG.js";
7
- import "./chunk-Q5GLE3YW.js";
6
+ } from "./chunk-HN74ORTP.js";
7
+ import "./chunk-NX7TO2DU.js";
8
8
  import {
9
9
  debugLogger
10
- } from "./chunk-JUHOHELL.js";
10
+ } from "./chunk-ZQW7OGUO.js";
11
11
  import "./chunk-664ZODQF.js";
12
12
  import "./chunk-IUUIT4SU.js";
13
13
  import "./chunk-L6PII3GR.js";
@@ -41,7 +41,7 @@ var LiteRtServerManager = class {
41
41
  `[LiteRtServerManager] Auto-starting LiteRT server on port ${port}...`
42
42
  );
43
43
  try {
44
- const { startServer } = await import("./start-JVWQ2CSF.js");
44
+ const { startServer } = await import("./start-VQQ2Q5KT.js");
45
45
  const started = await startServer(binaryPath, port);
46
46
  if (started) {
47
47
  debugLogger.log(`[LiteRtServerManager] Server started on port ${port}`);
@@ -3,11 +3,11 @@ import {
3
3
  DEFAULT_PORT,
4
4
  getBinaryPath,
5
5
  isServerRunning
6
- } from "./chunk-PO2VSL43.js";
7
- import "./chunk-UP3637TZ.js";
6
+ } from "./chunk-2NQXIWQK.js";
7
+ import "./chunk-Y2HXXBXI.js";
8
8
  import {
9
9
  debugLogger
10
- } from "./chunk-6LCUTDX7.js";
10
+ } from "./chunk-6OFXOGEG.js";
11
11
  import "./chunk-664ZODQF.js";
12
12
  import "./chunk-IUUIT4SU.js";
13
13
  import "./chunk-L6PII3GR.js";
@@ -41,7 +41,7 @@ var LiteRtServerManager = class {
41
41
  `[LiteRtServerManager] Auto-starting LiteRT server on port ${port}...`
42
42
  );
43
43
  try {
44
- const { startServer } = await import("./start-TO2FZTHQ.js");
44
+ const { startServer } = await import("./start-5O7TBK5L.js");
45
45
  const started = await startServer(binaryPath, port);
46
46
  if (started) {
47
47
  debugLogger.log(`[LiteRtServerManager] Server started on port ${port}`);
@@ -16,7 +16,7 @@ import {
16
16
  openBrowserSecurely,
17
17
  refreshAccessToken,
18
18
  startCallbackServer
19
- } from "./chunk-CUFMYKIC.js";
19
+ } from "./chunk-ZQW7OGUO.js";
20
20
  import "./chunk-664ZODQF.js";
21
21
  import "./chunk-IUUIT4SU.js";
22
22
  import "./chunk-L6PII3GR.js";
@@ -16,35 +16,35 @@ import {
16
16
  openBrowserSecurely,
17
17
  refreshAccessToken,
18
18
  startCallbackServer
19
- } from "./chunk-6LCUTDX7.js";
19
+ } from "./chunk-6OFXOGEG.js";
20
20
  import "./chunk-664ZODQF.js";
21
21
  import "./chunk-IUUIT4SU.js";
22
22
  import "./chunk-L6PII3GR.js";
23
23
  import "./chunk-34MYV7JD.js";
24
24
 
25
- // packages/core/dist/src/agents/auth-provider/oauth2-provider.js
25
+ // packages/core/src/agents/auth-provider/oauth2-provider.ts
26
26
  var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
27
- config;
28
- agentName;
29
- agentCardUrl;
30
- type = "oauth2";
31
- tokenStorage;
32
- cachedToken = null;
33
- /** Resolved OAuth URLs — may come from config or agent card. */
34
- authorizationUrl;
35
- tokenUrl;
36
- scopes;
37
27
  constructor(config, agentName, agentCard, agentCardUrl) {
38
28
  super();
39
29
  this.config = config;
40
30
  this.agentName = agentName;
41
31
  this.agentCardUrl = agentCardUrl;
42
- this.tokenStorage = new MCPOAuthTokenStorage(Storage.getA2AOAuthTokensPath(), "gemini-cli-a2a");
32
+ this.tokenStorage = new MCPOAuthTokenStorage(
33
+ Storage.getA2AOAuthTokensPath(),
34
+ "gemini-cli-a2a"
35
+ );
43
36
  this.authorizationUrl = config.authorization_url;
44
37
  this.tokenUrl = config.token_url;
45
38
  this.scopes = config.scopes;
46
39
  this.mergeAgentCardDefaults(agentCard);
47
40
  }
41
+ type = "oauth2";
42
+ tokenStorage;
43
+ cachedToken = null;
44
+ /** Resolved OAuth URLs — may come from config or agent card. */
45
+ authorizationUrl;
46
+ tokenUrl;
47
+ scopes;
48
48
  /**
49
49
  * Initialize the provider by loading any persisted token from storage.
50
50
  * Also discovers OAuth URLs from the agent card if not yet resolved.
@@ -56,7 +56,9 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
56
56
  const credentials = await this.tokenStorage.getCredentials(this.agentName);
57
57
  if (credentials && !this.tokenStorage.isTokenExpired(credentials.token)) {
58
58
  this.cachedToken = credentials.token;
59
- debugLogger.debug(`[OAuth2AuthProvider] Loaded valid cached token for "${this.agentName}"`);
59
+ debugLogger.debug(
60
+ `[OAuth2AuthProvider] Loaded valid cached token for "${this.agentName}"`
61
+ );
60
62
  }
61
63
  }
62
64
  /**
@@ -69,16 +71,25 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
69
71
  }
70
72
  if (this.cachedToken?.refreshToken && this.tokenUrl && this.config.client_id) {
71
73
  try {
72
- const refreshed = await refreshAccessToken({
73
- clientId: this.config.client_id,
74
- clientSecret: this.config.client_secret,
75
- scopes: this.scopes
76
- }, this.cachedToken.refreshToken, this.tokenUrl);
77
- this.cachedToken = this.toOAuthToken(refreshed, this.cachedToken.refreshToken);
74
+ const refreshed = await refreshAccessToken(
75
+ {
76
+ clientId: this.config.client_id,
77
+ clientSecret: this.config.client_secret,
78
+ scopes: this.scopes
79
+ },
80
+ this.cachedToken.refreshToken,
81
+ this.tokenUrl
82
+ );
83
+ this.cachedToken = this.toOAuthToken(
84
+ refreshed,
85
+ this.cachedToken.refreshToken
86
+ );
78
87
  await this.persistToken();
79
88
  return { Authorization: `Bearer ${this.cachedToken.accessToken}` };
80
89
  } catch (error) {
81
- debugLogger.debug(`[OAuth2AuthProvider] Refresh failed, falling back to interactive flow: ${getErrorMessage(error)}`);
90
+ debugLogger.debug(
91
+ `[OAuth2AuthProvider] Refresh failed, falling back to interactive flow: ${getErrorMessage(error)}`
92
+ );
82
93
  await this.tokenStorage.deleteCredentials(this.agentName);
83
94
  }
84
95
  }
@@ -97,7 +108,9 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
97
108
  return void 0;
98
109
  }
99
110
  this.authRetryCount++;
100
- debugLogger.debug("[OAuth2AuthProvider] Auth failure, clearing token and re-authenticating");
111
+ debugLogger.debug(
112
+ "[OAuth2AuthProvider] Auth failure, clearing token and re-authenticating"
113
+ );
101
114
  this.cachedToken = null;
102
115
  await this.tokenStorage.deleteCredentials(this.agentName);
103
116
  return this.headers();
@@ -110,8 +123,7 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
110
123
  * `securitySchemes` when not already provided via user config.
111
124
  */
112
125
  mergeAgentCardDefaults(agentCard) {
113
- if (!agentCard?.securitySchemes)
114
- return;
126
+ if (!agentCard?.securitySchemes) return;
115
127
  for (const scheme of Object.values(agentCard.securitySchemes)) {
116
128
  if (scheme.type === "oauth2" && scheme.flows.authorizationCode) {
117
129
  const flow = scheme.flows.authorizationCode;
@@ -127,15 +139,18 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
127
139
  * (which normalizes proto-format cards) and extract OAuth2 URLs.
128
140
  */
129
141
  async fetchAgentCardDefaults() {
130
- if (!this.agentCardUrl)
131
- return;
142
+ if (!this.agentCardUrl) return;
132
143
  try {
133
- debugLogger.debug(`[OAuth2AuthProvider] Fetching agent card from ${this.agentCardUrl}`);
144
+ debugLogger.debug(
145
+ `[OAuth2AuthProvider] Fetching agent card from ${this.agentCardUrl}`
146
+ );
134
147
  const resolver = new DefaultAgentCardResolver();
135
148
  const card = await resolver.resolve(this.agentCardUrl, "");
136
149
  this.mergeAgentCardDefaults(card);
137
150
  } catch (error) {
138
- debugLogger.warn(`[OAuth2AuthProvider] Could not fetch agent card for OAuth URL discovery: ${getErrorMessage(error)}`);
151
+ debugLogger.warn(
152
+ `[OAuth2AuthProvider] Could not fetch agent card for OAuth URL discovery: ${getErrorMessage(error)}`
153
+ );
139
154
  }
140
155
  }
141
156
  /**
@@ -143,10 +158,14 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
143
158
  */
144
159
  async authenticateInteractively() {
145
160
  if (!this.config.client_id) {
146
- throw new Error(`OAuth2 authentication for agent "${this.agentName}" requires a client_id. Add client_id to the auth config in your agent definition.`);
161
+ throw new Error(
162
+ `OAuth2 authentication for agent "${this.agentName}" requires a client_id. Add client_id to the auth config in your agent definition.`
163
+ );
147
164
  }
148
165
  if (!this.authorizationUrl || !this.tokenUrl) {
149
- throw new Error(`OAuth2 authentication for agent "${this.agentName}" requires authorization_url and token_url. Provide them in the auth config or ensure the agent card exposes an oauth2 security scheme.`);
166
+ throw new Error(
167
+ `OAuth2 authentication for agent "${this.agentName}" requires authorization_url and token_url. Provide them in the auth config or ensure the agent card exposes an oauth2 security scheme.`
168
+ );
150
169
  }
151
170
  const flowConfig = {
152
171
  clientId: this.config.client_id,
@@ -165,25 +184,36 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
165
184
  redirectPort,
166
185
  /* resource= */
167
186
  void 0
187
+ // No MCP resource parameter for A2A.
188
+ );
189
+ const consent = await getConsentForOauth(
190
+ `Authentication required for A2A agent: '${this.agentName}'.`
168
191
  );
169
- const consent = await getConsentForOauth(`Authentication required for A2A agent: '${this.agentName}'.`);
170
192
  if (!consent) {
171
193
  throw new FatalCancellationError("Authentication cancelled by user.");
172
194
  }
173
- coreEvents.emitFeedback("info", `\u2192 Opening your browser for OAuth sign-in...
195
+ coreEvents.emitFeedback(
196
+ "info",
197
+ `\u2192 Opening your browser for OAuth sign-in...
174
198
 
175
199
  If the browser does not open, copy and paste this URL into your browser:
176
200
  ${authUrl}
177
201
 
178
202
  \u{1F4A1} TIP: Triple-click to select the entire URL, then copy and paste it into your browser.
179
- \u26A0\uFE0F Make sure to copy the COMPLETE URL - it may wrap across multiple lines.`);
203
+ \u26A0\uFE0F Make sure to copy the COMPLETE URL - it may wrap across multiple lines.`
204
+ );
180
205
  try {
181
206
  await openBrowserSecurely(authUrl);
182
207
  } catch (error) {
183
- debugLogger.warn("Failed to open browser automatically:", getErrorMessage(error));
208
+ debugLogger.warn(
209
+ "Failed to open browser automatically:",
210
+ getErrorMessage(error)
211
+ );
184
212
  }
185
213
  const { code } = await callbackServer.response;
186
- debugLogger.debug("\u2713 Authorization code received, exchanging for tokens...");
214
+ debugLogger.debug(
215
+ "\u2713 Authorization code received, exchanging for tokens..."
216
+ );
187
217
  const tokenResponse = await exchangeCodeForToken(
188
218
  flowConfig,
189
219
  code,
@@ -220,9 +250,13 @@ ${authUrl}
220
250
  * Persist the current cached token to disk.
221
251
  */
222
252
  async persistToken() {
223
- if (!this.cachedToken)
224
- return;
225
- await this.tokenStorage.saveToken(this.agentName, this.cachedToken, this.config.client_id, this.tokenUrl);
253
+ if (!this.cachedToken) return;
254
+ await this.tokenStorage.saveToken(
255
+ this.agentName,
256
+ this.cachedToken,
257
+ this.config.client_id,
258
+ this.tokenUrl
259
+ );
226
260
  }
227
261
  };
228
262
  export {
@@ -2,12 +2,12 @@ const require = (await import('node:module')).createRequire(import.meta.url); co
2
2
  import {
3
3
  startCommand,
4
4
  startServer
5
- } from "./chunk-JQYJUNLF.js";
6
- import "./chunk-QSGRHC6M.js";
7
- import "./chunk-PO2VSL43.js";
8
- import "./chunk-UP3637TZ.js";
9
- import "./chunk-6ISJPGCD.js";
10
- import "./chunk-6LCUTDX7.js";
5
+ } from "./chunk-VJYKQD5D.js";
6
+ import "./chunk-EDVFNWRG.js";
7
+ import "./chunk-2NQXIWQK.js";
8
+ import "./chunk-Y2HXXBXI.js";
9
+ import "./chunk-SDWOC67Z.js";
10
+ import "./chunk-6OFXOGEG.js";
11
11
  import "./chunk-664ZODQF.js";
12
12
  import "./chunk-IUUIT4SU.js";
13
13
  import "./chunk-L6PII3GR.js";
@@ -2,12 +2,12 @@ const require = (await import('node:module')).createRequire(import.meta.url); co
2
2
  import {
3
3
  startCommand,
4
4
  startServer
5
- } from "./chunk-NBEG6GFX.js";
6
- import "./chunk-EELKDWQ4.js";
7
- import "./chunk-XZLCMV4F.js";
8
- import "./chunk-27FWUQTG.js";
9
- import "./chunk-2TCGCQ3U.js";
10
- import "./chunk-CUFMYKIC.js";
5
+ } from "./chunk-MLSLNORV.js";
6
+ import "./chunk-ZOHM7BPT.js";
7
+ import "./chunk-HN74ORTP.js";
8
+ import "./chunk-NX7TO2DU.js";
9
+ import "./chunk-UBGF6JU5.js";
10
+ import "./chunk-ZQW7OGUO.js";
11
11
  import "./chunk-664ZODQF.js";
12
12
  import "./chunk-IUUIT4SU.js";
13
13
  import "./chunk-L6PII3GR.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@google/gemini-cli",
3
- "version": "0.64.0-nightly.20261005.gfb972b2f8",
3
+ "version": "0.64.0-preview.0",
4
4
  "description": "Gemini CLI",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -1,154 +0,0 @@
1
- const require = (await import('node:module')).createRequire(import.meta.url); const __chunk_filename = (await import('node:url')).fileURLToPath(import.meta.url); const __chunk_dirname = (await import('node:path')).dirname(__chunk_filename);
2
- import {
3
- ExitCodes,
4
- Storage,
5
- isTelemetrySdkInitialized,
6
- resetBrowserSession,
7
- shutdownTelemetry
8
- } from "./chunk-6LCUTDX7.js";
9
-
10
- // packages/cli/src/utils/cleanup.ts
11
- import { promises as fs } from "node:fs";
12
- import { join } from "node:path";
13
- var cleanupFunctions = [];
14
- var syncCleanupFunctions = [];
15
- var configForTelemetry = null;
16
- var isShuttingDown = false;
17
- function registerCleanup(fn) {
18
- cleanupFunctions.push(fn);
19
- }
20
- function removeCleanup(fn) {
21
- const index = cleanupFunctions.indexOf(fn);
22
- if (index !== -1) {
23
- cleanupFunctions.splice(index, 1);
24
- }
25
- }
26
- function registerSyncCleanup(fn) {
27
- syncCleanupFunctions.push(fn);
28
- }
29
- function removeSyncCleanup(fn) {
30
- const index = syncCleanupFunctions.indexOf(fn);
31
- if (index !== -1) {
32
- syncCleanupFunctions.splice(index, 1);
33
- }
34
- }
35
- function resetCleanupForTesting() {
36
- cleanupFunctions.length = 0;
37
- syncCleanupFunctions.length = 0;
38
- configForTelemetry = null;
39
- isShuttingDown = false;
40
- }
41
- function runSyncCleanup() {
42
- for (const fn of syncCleanupFunctions) {
43
- try {
44
- fn();
45
- } catch {
46
- }
47
- }
48
- syncCleanupFunctions.length = 0;
49
- }
50
- function registerTelemetryConfig(config) {
51
- configForTelemetry = config;
52
- }
53
- async function runExitCleanup() {
54
- await drainStdin();
55
- runSyncCleanup();
56
- for (const fn of cleanupFunctions) {
57
- try {
58
- await fn();
59
- } catch {
60
- }
61
- }
62
- cleanupFunctions.length = 0;
63
- try {
64
- await resetBrowserSession();
65
- } catch {
66
- }
67
- if (configForTelemetry) {
68
- try {
69
- await configForTelemetry.dispose();
70
- } catch {
71
- }
72
- }
73
- if (configForTelemetry && isTelemetrySdkInitialized()) {
74
- try {
75
- await shutdownTelemetry(configForTelemetry);
76
- } catch {
77
- }
78
- }
79
- }
80
- async function drainStdin() {
81
- if (!process.stdin?.isTTY) return;
82
- process.stdin.resume().removeAllListeners("data").on("data", () => {
83
- });
84
- await new Promise((resolve) => setTimeout(resolve, 50));
85
- }
86
- async function gracefulShutdown(_reason) {
87
- if (isShuttingDown) {
88
- return;
89
- }
90
- isShuttingDown = true;
91
- await runExitCleanup();
92
- process.exit(ExitCodes.SUCCESS);
93
- }
94
- function setupSignalHandlers() {
95
- process.on("SIGHUP", () => gracefulShutdown("SIGHUP"));
96
- process.on("SIGTERM", () => gracefulShutdown("SIGTERM"));
97
- process.on("SIGINT", () => gracefulShutdown("SIGINT"));
98
- }
99
- function setupTtyCheck() {
100
- let intervalId = null;
101
- let isCheckingTty = false;
102
- intervalId = setInterval(async () => {
103
- if (isCheckingTty || isShuttingDown) {
104
- return;
105
- }
106
- if (process.env["SANDBOX"]) {
107
- return;
108
- }
109
- if (!process.stdin.isTTY && !process.stdout.isTTY) {
110
- isCheckingTty = true;
111
- if (intervalId) {
112
- clearInterval(intervalId);
113
- intervalId = null;
114
- }
115
- await gracefulShutdown("TTY loss");
116
- }
117
- }, 5e3);
118
- intervalId.unref();
119
- return () => {
120
- if (intervalId) {
121
- clearInterval(intervalId);
122
- intervalId = null;
123
- }
124
- };
125
- }
126
- async function cleanupCheckpoints() {
127
- const storage = new Storage(process.cwd());
128
- await storage.initialize();
129
- const tempDir = storage.getProjectTempDir();
130
- const checkpointsDir = join(tempDir, "checkpoints");
131
- try {
132
- await fs.rm(checkpointsDir, { recursive: true, force: true });
133
- } catch {
134
- }
135
- }
136
-
137
- export {
138
- registerCleanup,
139
- removeCleanup,
140
- registerSyncCleanup,
141
- removeSyncCleanup,
142
- resetCleanupForTesting,
143
- runSyncCleanup,
144
- registerTelemetryConfig,
145
- runExitCleanup,
146
- setupSignalHandlers,
147
- setupTtyCheck,
148
- cleanupCheckpoints
149
- };
150
- /**
151
- * @license
152
- * Copyright 2025 Google LLC
153
- * SPDX-License-Identifier: Apache-2.0
154
- */