@google/gemini-cli-a2a-server 0.13.0-nightly.20251030.42c79c64 → 0.13.0-nightly.20251101.caf2ca14

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.
@@ -285600,6 +285600,7 @@ var HybridTokenStorage = class extends BaseTokenStorage {
285600
285600
  import * as path14 from "node:path";
285601
285601
  import * as os5 from "node:os";
285602
285602
  import { promises as fs21 } from "node:fs";
285603
+ init_events();
285603
285604
  var KEYCHAIN_SERVICE_NAME = "gemini-cli-oauth";
285604
285605
  var MAIN_ACCOUNT_KEY = "main-account";
285605
285606
  var OAuthCredentialStorage = class {
@@ -286671,8 +286672,9 @@ var DeclarativeTool = class {
286671
286672
  isOutputMarkdown;
286672
286673
  canUpdateOutput;
286673
286674
  messageBus;
286675
+ extensionName;
286674
286676
  extensionId;
286675
- constructor(name4, displayName, description, kind, parameterSchema, isOutputMarkdown = true, canUpdateOutput = false, messageBus, extensionId) {
286677
+ constructor(name4, displayName, description, kind, parameterSchema, isOutputMarkdown = true, canUpdateOutput = false, messageBus, extensionName, extensionId) {
286676
286678
  this.name = name4;
286677
286679
  this.displayName = displayName;
286678
286680
  this.description = description;
@@ -286681,6 +286683,7 @@ var DeclarativeTool = class {
286681
286683
  this.isOutputMarkdown = isOutputMarkdown;
286682
286684
  this.canUpdateOutput = canUpdateOutput;
286683
286685
  this.messageBus = messageBus;
286686
+ this.extensionName = extensionName;
286684
286687
  this.extensionId = extensionId;
286685
286688
  }
286686
286689
  get schema() {
@@ -286987,8 +286990,9 @@ var DiscoveredMCPTool = class _DiscoveredMCPTool extends BaseDeclarativeTool {
286987
286990
  parameterSchema;
286988
286991
  trust;
286989
286992
  cliConfig;
286993
+ extensionName;
286990
286994
  extensionId;
286991
- constructor(mcpTool, serverName, serverToolName, description, parameterSchema, trust, nameOverride, cliConfig, extensionId, messageBus) {
286995
+ constructor(mcpTool, serverName, serverToolName, description, parameterSchema, trust, nameOverride, cliConfig, extensionName, extensionId, messageBus) {
286992
286996
  super(
286993
286997
  nameOverride ?? generateValidName(serverToolName),
286994
286998
  `${serverToolName} (${serverName} MCP Server)`,
@@ -287000,6 +287004,7 @@ var DiscoveredMCPTool = class _DiscoveredMCPTool extends BaseDeclarativeTool {
287000
287004
  false,
287001
287005
  // canUpdateOutput,
287002
287006
  messageBus,
287007
+ extensionName,
287003
287008
  extensionId
287004
287009
  );
287005
287010
  this.mcpTool = mcpTool;
@@ -287008,10 +287013,11 @@ var DiscoveredMCPTool = class _DiscoveredMCPTool extends BaseDeclarativeTool {
287008
287013
  this.parameterSchema = parameterSchema;
287009
287014
  this.trust = trust;
287010
287015
  this.cliConfig = cliConfig;
287016
+ this.extensionName = extensionName;
287011
287017
  this.extensionId = extensionId;
287012
287018
  }
287013
287019
  asFullyQualifiedTool() {
287014
- return new _DiscoveredMCPTool(this.mcpTool, this.serverName, this.serverToolName, this.description, this.parameterSchema, this.trust, `${this.serverName}__${this.serverToolName}`, this.cliConfig, this.extensionId, this.messageBus);
287020
+ return new _DiscoveredMCPTool(this.mcpTool, this.serverName, this.serverToolName, this.description, this.parameterSchema, this.trust, `${this.serverName}__${this.serverToolName}`, this.cliConfig, this.extensionName, this.extensionId, this.messageBus);
287015
287021
  }
287016
287022
  createInvocation(params, _messageBus, _toolName, _displayName) {
287017
287023
  return new DiscoveredMCPToolInvocation(this.mcpTool, this.serverName, this.serverToolName, this.displayName, this.trust, params, this.cliConfig, _messageBus);
@@ -287183,7 +287189,7 @@ var InstallationManager = class {
287183
287189
  }
287184
287190
  return installationId;
287185
287191
  } catch (error) {
287186
- console.error("Error accessing installation ID file, generating ephemeral ID:", error);
287192
+ debugLogger.warn("Error accessing installation ID file, generating ephemeral ID:", error);
287187
287193
  return "123456789";
287188
287194
  }
287189
287195
  }
@@ -287210,6 +287216,7 @@ var API_REQUEST_LATENCY = "gemini_cli.api.request.latency";
287210
287216
  var TOKEN_USAGE = "gemini_cli.token.usage";
287211
287217
  var SESSION_COUNT = "gemini_cli.session.count";
287212
287218
  var FILE_OPERATION_COUNT = "gemini_cli.file.operation.count";
287219
+ var LINES_CHANGED = "gemini_cli.lines.changed";
287213
287220
  var INVALID_CHUNK_COUNT = "gemini_cli.chat.invalid_chunk.count";
287214
287221
  var CONTENT_RETRY_COUNT = "gemini_cli.chat.content_retry.count";
287215
287222
  var CONTENT_RETRY_FAILURE_COUNT = "gemini_cli.chat.content_retry_failure.count";
@@ -287233,6 +287240,7 @@ var REGRESSION_DETECTION = "gemini_cli.performance.regression";
287233
287240
  var REGRESSION_PERCENTAGE_CHANGE = "gemini_cli.performance.regression.percentage_change";
287234
287241
  var BASELINE_COMPARISON = "gemini_cli.performance.baseline.comparison";
287235
287242
  var FLICKER_FRAME_COUNT = "gemini_cli.ui.flicker.count";
287243
+ var SLOW_RENDER_LATENCY = "gemini_cli.ui.slow_render.latency";
287236
287244
  var EXIT_FAIL_COUNT = "gemini_cli.exit.fail.count";
287237
287245
  var baseMetricDefinition = {
287238
287246
  getCommonAttributes
@@ -287268,6 +287276,12 @@ var COUNTER_DEFINITIONS = {
287268
287276
  assign: (c4) => fileOperationCounter = c4,
287269
287277
  attributes: {}
287270
287278
  },
287279
+ [LINES_CHANGED]: {
287280
+ description: "Number of lines changed (from file diffs).",
287281
+ valueType: ValueType.INT,
287282
+ assign: (c4) => linesChangedCounter = c4,
287283
+ attributes: {}
287284
+ },
287271
287285
  [INVALID_CHUNK_COUNT]: {
287272
287286
  description: "Counts invalid chunks received from a stream.",
287273
287287
  valueType: ValueType.INT,
@@ -287352,6 +287366,13 @@ var HISTOGRAM_DEFINITIONS = {
287352
287366
  assign: (h2) => agentDurationHistogram = h2,
287353
287367
  attributes: {}
287354
287368
  },
287369
+ [SLOW_RENDER_LATENCY]: {
287370
+ description: "Counts UI frames that take too long to render.",
287371
+ unit: "ms",
287372
+ valueType: ValueType.INT,
287373
+ assign: (h2) => slowRenderHistogram = h2,
287374
+ attributes: {}
287375
+ },
287355
287376
  [AGENT_TURNS]: {
287356
287377
  description: "Number of turns taken by agents.",
287357
287378
  unit: "turns",
@@ -287512,6 +287533,7 @@ var apiRequestLatencyHistogram;
287512
287533
  var tokenUsageCounter;
287513
287534
  var sessionCounter;
287514
287535
  var fileOperationCounter;
287536
+ var linesChangedCounter;
287515
287537
  var chatCompressionCounter;
287516
287538
  var invalidChunkCounter;
287517
287539
  var contentRetryCounter;
@@ -287524,6 +287546,7 @@ var agentDurationHistogram;
287524
287546
  var agentTurnsHistogram;
287525
287547
  var flickerFrameCounter;
287526
287548
  var exitFailCounter;
287549
+ var slowRenderHistogram;
287527
287550
  var genAiClientTokenUsageHistogram;
287528
287551
  var genAiClientOperationDurationHistogram;
287529
287552
  var startupTimeHistogram;
@@ -287627,6 +287650,17 @@ function recordFileOperationMetric(config2, attributes) {
287627
287650
  ...attributes
287628
287651
  });
287629
287652
  }
287653
+ function recordLinesChanged(config2, lines, changeType, attributes) {
287654
+ if (!linesChangedCounter || !isMetricsInitialized)
287655
+ return;
287656
+ if (!Number.isFinite(lines) || lines <= 0)
287657
+ return;
287658
+ linesChangedCounter.add(lines, {
287659
+ ...baseMetricDefinition.getCommonAttributes(config2),
287660
+ type: changeType,
287661
+ ...attributes ?? {}
287662
+ });
287663
+ }
287630
287664
  function recordContentRetry(config2) {
287631
287665
  if (!contentRetryCounter || !isMetricsInitialized)
287632
287666
  return;
@@ -288020,6 +288054,7 @@ var ToolCallEvent = class {
288020
288054
  tool_type;
288021
288055
  content_length;
288022
288056
  mcp_server_name;
288057
+ extension_name;
288023
288058
  extension_id;
288024
288059
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
288025
288060
  metadata;
@@ -288039,6 +288074,7 @@ var ToolCallEvent = class {
288039
288074
  if (typeof call.tool !== "undefined" && call.tool instanceof DiscoveredMCPTool) {
288040
288075
  this.tool_type = "mcp";
288041
288076
  this.mcp_server_name = call.tool.serverName;
288077
+ this.extension_name = call.tool.extensionName;
288042
288078
  this.extension_id = call.tool.extensionId;
288043
288079
  } else {
288044
288080
  this.tool_type = "native";
@@ -288082,6 +288118,7 @@ var ToolCallEvent = class {
288082
288118
  tool_type: this.tool_type,
288083
288119
  content_length: this.content_length,
288084
288120
  mcp_server_name: this.mcp_server_name,
288121
+ extension_name: this.extension_name,
288085
288122
  extension_id: this.extension_id,
288086
288123
  metadata: this.metadata
288087
288124
  };
@@ -288967,8 +289004,8 @@ var Float64Vector = import_vector.default.Float64Vector;
288967
289004
  var PointerVector = import_vector.default.PointerVector;
288968
289005
 
288969
289006
  // packages/core/dist/src/generated/git-commit.js
288970
- var GIT_COMMIT_INFO = "42c79c64";
288971
- var CLI_VERSION = "0.13.0-nightly.20251030.42c79c64";
289007
+ var GIT_COMMIT_INFO = "caf2ca14";
289008
+ var CLI_VERSION = "0.13.0-nightly.20251101.caf2ca14";
288972
289009
 
288973
289010
  // packages/core/dist/src/ide/detect-ide.js
288974
289011
  var IDE_DEFINITIONS = {
@@ -289415,6 +289452,12 @@ var ClearcutLogger = class _ClearcutLogger {
289415
289452
  }
289416
289453
  }
289417
289454
  }
289455
+ if (event.extension_id) {
289456
+ data.push({
289457
+ gemini_cli_key: EventMetadataKey.GEMINI_CLI_EXTENSION_ID,
289458
+ value: event.extension_id
289459
+ });
289460
+ }
289418
289461
  const logEvent = this.createLogEvent(EventNames.TOOL_CALL, data);
289419
289462
  this.enqueueLogEvent(logEvent);
289420
289463
  this.flushIfNeeded();
@@ -289595,6 +289638,12 @@ var ClearcutLogger = class _ClearcutLogger {
289595
289638
  value: JSON.stringify(event.status)
289596
289639
  });
289597
289640
  }
289641
+ if (event.extension_id) {
289642
+ data.push({
289643
+ gemini_cli_key: EventMetadataKey.GEMINI_CLI_EXTENSION_ID,
289644
+ value: event.extension_id
289645
+ });
289646
+ }
289598
289647
  this.enqueueLogEvent(this.createLogEvent(EventNames.SLASH_COMMAND, data));
289599
289648
  this.flushIfNeeded();
289600
289649
  }
@@ -290139,7 +290188,6 @@ var GcpLogExporter = class {
290139
290188
  }
290140
290189
  }
290141
290190
  }, {
290142
- session_id: log.attributes?.["session.id"],
290143
290191
  ...log.attributes,
290144
290192
  ...log.resource?.attributes,
290145
290193
  message: log.body
@@ -291093,14 +291141,22 @@ function logToolCall(config2, event) {
291093
291141
  function_name: event.function_name,
291094
291142
  success: event.success,
291095
291143
  decision: event.decision,
291096
- tool_type: event.tool_type,
291097
- ...event.metadata ? {
291098
- model_added_lines: event.metadata["model_added_lines"],
291099
- model_removed_lines: event.metadata["model_removed_lines"],
291100
- user_added_lines: event.metadata["user_added_lines"],
291101
- user_removed_lines: event.metadata["user_removed_lines"]
291102
- } : {}
291144
+ tool_type: event.tool_type
291103
291145
  });
291146
+ if (event.metadata) {
291147
+ const added = event.metadata["model_added_lines"];
291148
+ if (typeof added === "number" && added > 0) {
291149
+ recordLinesChanged(config2, added, "added", {
291150
+ function_name: event.function_name
291151
+ });
291152
+ }
291153
+ const removed = event.metadata["model_removed_lines"];
291154
+ if (typeof removed === "number" && removed > 0) {
291155
+ recordLinesChanged(config2, removed, "removed", {
291156
+ function_name: event.function_name
291157
+ });
291158
+ }
291159
+ }
291104
291160
  }
291105
291161
  function logToolOutputTruncated(config2, event) {
291106
291162
  ClearcutLogger.getInstance(config2)?.logToolOutputTruncatedEvent(event);
@@ -291709,7 +291765,7 @@ async function createContentGenerator(config2, gcConfig, sessionId2) {
291709
291765
  if (gcConfig.fakeResponses) {
291710
291766
  return FakeContentGenerator.fromFile(gcConfig.fakeResponses);
291711
291767
  }
291712
- const version3 = "0.13.0-nightly.20251030.42c79c64";
291768
+ const version3 = "0.13.0-nightly.20251101.caf2ca14";
291713
291769
  const userAgent = `GeminiCLI/${version3} (${process.platform}; ${process.arch})`;
291714
291770
  const baseHeaders = {
291715
291771
  "User-Agent": userAgent
@@ -299243,6 +299299,7 @@ var OAuthUtils = class {
299243
299299
  };
299244
299300
 
299245
299301
  // packages/core/dist/src/mcp/google-auth-provider.js
299302
+ init_events();
299246
299303
  var ALLOWED_HOSTS = [/^.+\.googleapis\.com$/, /^(.*\.)?luci\.app$/];
299247
299304
  var GoogleCredentialProvider = class {
299248
299305
  config;
@@ -299292,7 +299349,7 @@ var GoogleCredentialProvider = class {
299292
299349
  const client = await this.auth.getClient();
299293
299350
  const accessTokenResponse = await client.getAccessToken();
299294
299351
  if (!accessTokenResponse.token) {
299295
- console.error("Failed to get access token from Google ADC");
299352
+ coreEvents.emitFeedback("error", "Failed to get access token from Google ADC");
299296
299353
  return void 0;
299297
299354
  }
299298
299355
  const newToken = {
@@ -299506,6 +299563,7 @@ async function openBrowserSecurely(url4) {
299506
299563
  }
299507
299564
 
299508
299565
  // packages/core/dist/src/mcp/oauth-token-storage.js
299566
+ init_events();
299509
299567
  import { promises as fs25 } from "node:fs";
299510
299568
  import * as path17 from "node:path";
299511
299569
  var MCPOAuthTokenStorage = class {
@@ -299667,6 +299725,7 @@ var MCPOAuthTokenStorage = class {
299667
299725
  };
299668
299726
 
299669
299727
  // packages/core/dist/src/mcp/oauth-provider.js
299728
+ init_events();
299670
299729
  var OAUTH_DISPLAY_MESSAGE_EVENT = "oauth-display-message";
299671
299730
  var REDIRECT_PORT = 7777;
299672
299731
  var REDIRECT_PATH = "/oauth/callback";
@@ -300131,10 +300190,10 @@ ${authUrl}
300131
300190
  const tokenFingerprint = crypto18.createHash("sha256").update(savedToken.token.accessToken).digest("hex").slice(0, 8);
300132
300191
  debugLogger.debug(`\u2713 Token verification successful (fingerprint: ${tokenFingerprint})`);
300133
300192
  } else {
300134
- console.error("Token verification failed: token not found or invalid after save");
300193
+ debugLogger.warn("Token verification failed: token not found or invalid after save");
300135
300194
  }
300136
300195
  } catch (saveError) {
300137
- console.error(`Failed to save token: ${getErrorMessage(saveError)}`);
300196
+ debugLogger.error("Failed to save auth token.", saveError);
300138
300197
  throw saveError;
300139
300198
  }
300140
300199
  return token2;
@@ -300175,7 +300234,7 @@ ${authUrl}
300175
300234
  await this.tokenStorage.saveToken(serverName, newToken, config2.clientId, credentials.tokenUrl, credentials.mcpServerUrl);
300176
300235
  return newToken.accessToken;
300177
300236
  } catch (error) {
300178
- console.error(`Failed to refresh token: ${getErrorMessage(error)}`);
300237
+ coreEvents.emitFeedback("error", "Failed to refresh auth token.", error);
300179
300238
  await this.tokenStorage.deleteCredentials(serverName);
300180
300239
  }
300181
300240
  }
@@ -300264,6 +300323,7 @@ var McpClient = class {
300264
300323
  if (this.status !== MCPServerStatus.CONNECTED) {
300265
300324
  return;
300266
300325
  }
300326
+ this.toolRegistry.removeMcpToolsByServer(this.serverName);
300267
300327
  this.updateStatus(MCPServerStatus.DISCONNECTING);
300268
300328
  const client = this.client;
300269
300329
  this.client = void 0;
@@ -300445,7 +300505,7 @@ async function discoverTools(mcpServerName, mcpServerConfig, mcpClient, cliConfi
300445
300505
  if (!isEnabled(funcDecl, mcpServerName, mcpServerConfig)) {
300446
300506
  continue;
300447
300507
  }
300448
- const tool2 = new DiscoveredMCPTool(mcpCallableTool, mcpServerName, funcDecl.name, funcDecl.description ?? "", funcDecl.parametersJsonSchema ?? { type: "object", properties: {} }, mcpServerConfig.trust, void 0, cliConfig, mcpServerConfig.extension?.id, messageBus);
300508
+ const tool2 = new DiscoveredMCPTool(mcpCallableTool, mcpServerName, funcDecl.name, funcDecl.description ?? "", funcDecl.parametersJsonSchema ?? { type: "object", properties: {} }, mcpServerConfig.trust, void 0, cliConfig, mcpServerConfig.extension?.name, mcpServerConfig.extension?.id, messageBus);
300449
300509
  if (cliConfig.getDebugMode?.() && cliConfig.getEnableMessageBusIntegration?.()) {
300450
300510
  debugLogger.log(`[DEBUG] Discovered MCP tool '${funcDecl.name}' from server '${mcpServerName}' with messageBus: ${messageBus ? "YES" : "NO"}`);
300451
300511
  }
@@ -300829,40 +300889,123 @@ init_events();
300829
300889
  var McpClientManager = class {
300830
300890
  clients = /* @__PURE__ */ new Map();
300831
300891
  toolRegistry;
300892
+ cliConfig;
300893
+ // If we have ongoing MCP client discovery, this completes once that is done.
300894
+ discoveryPromise;
300832
300895
  discoveryState = MCPDiscoveryState.NOT_STARTED;
300833
300896
  eventEmitter;
300834
- constructor(toolRegistry, eventEmitter) {
300897
+ constructor(toolRegistry, cliConfig, eventEmitter) {
300835
300898
  this.toolRegistry = toolRegistry;
300899
+ this.cliConfig = cliConfig;
300836
300900
  this.eventEmitter = eventEmitter;
300901
+ if (this.cliConfig.getEnableExtensionReloading()) {
300902
+ this.cliConfig.getExtensionLoader().extensionEvents().on("extensionLoaded", (event) => this.loadExtension(event.extension)).on("extensionEnabled", (event) => this.loadExtension(event.extension)).on("extensionDisabled", (event) => this.unloadExtension(event.extension)).on("extensionUnloaded", (event) => this.unloadExtension(event.extension));
300903
+ }
300904
+ }
300905
+ /**
300906
+ * For all the MCP servers associated with this extension:
300907
+ *
300908
+ * - Removes all its MCP servers from the global configuration object.
300909
+ * - Disconnects all MCP clients from their servers.
300910
+ * - Updates the Gemini chat configuration to load the new tools.
300911
+ */
300912
+ async unloadExtension(extension) {
300913
+ debugLogger.log(`Unloading extension: ${extension.name}`);
300914
+ await Promise.all(Object.keys(extension.mcpServers ?? {}).map((name4) => {
300915
+ const newMcpServers = {
300916
+ ...this.cliConfig.getMcpServers()
300917
+ };
300918
+ delete newMcpServers[name4];
300919
+ this.cliConfig.setMcpServers(newMcpServers);
300920
+ return this.disconnectClient(name4);
300921
+ }));
300922
+ this.cliConfig.getGeminiClient().setTools();
300923
+ }
300924
+ /**
300925
+ * For all the MCP servers associated with this extension:
300926
+ *
300927
+ * - Adds all its MCP servers to the global configuration object.
300928
+ * - Connects MCP clients to each server and discovers their tools.
300929
+ * - Updates the Gemini chat configuration to load the new tools.
300930
+ */
300931
+ async loadExtension(extension) {
300932
+ debugLogger.log(`Loading extension: ${extension.name}`);
300933
+ await Promise.all(Object.entries(extension.mcpServers ?? {}).map(([name4, config2]) => {
300934
+ this.cliConfig.setMcpServers({
300935
+ ...this.cliConfig.getMcpServers(),
300936
+ [name4]: config2
300937
+ });
300938
+ return this.discoverMcpTools(name4, config2);
300939
+ }));
300940
+ this.cliConfig.getGeminiClient().setTools();
300941
+ }
300942
+ async disconnectClient(name4) {
300943
+ const existing = this.clients.get(name4);
300944
+ if (existing) {
300945
+ try {
300946
+ this.clients.delete(name4);
300947
+ this.eventEmitter?.emit("mcp-client-update", this.clients);
300948
+ await existing.disconnect();
300949
+ } catch (error) {
300950
+ debugLogger.warn(`Error stopping client '${name4}': ${getErrorMessage(error)}`);
300951
+ }
300952
+ }
300953
+ }
300954
+ discoverMcpTools(name4, config2) {
300955
+ if (!this.cliConfig.isTrustedFolder()) {
300956
+ return;
300957
+ }
300958
+ if (config2.extension && !config2.extension.isActive) {
300959
+ return;
300960
+ }
300961
+ const currentDiscoveryPromise = new Promise((resolve13, _reject) => {
300962
+ (async () => {
300963
+ try {
300964
+ await this.disconnectClient(name4);
300965
+ const client = new McpClient(name4, config2, this.toolRegistry, this.cliConfig.getPromptRegistry(), this.cliConfig.getWorkspaceContext(), this.cliConfig.getDebugMode());
300966
+ this.clients.set(name4, client);
300967
+ this.eventEmitter?.emit("mcp-client-update", this.clients);
300968
+ try {
300969
+ await client.connect();
300970
+ await client.discover(this.cliConfig);
300971
+ this.eventEmitter?.emit("mcp-client-update", this.clients);
300972
+ } catch (error) {
300973
+ this.eventEmitter?.emit("mcp-client-update", this.clients);
300974
+ coreEvents.emitFeedback("error", `Error during discovery for server '${name4}': ${getErrorMessage(error)}`, error);
300975
+ }
300976
+ } finally {
300977
+ resolve13();
300978
+ }
300979
+ })();
300980
+ });
300981
+ if (this.discoveryPromise) {
300982
+ this.discoveryPromise = this.discoveryPromise.then(() => currentDiscoveryPromise);
300983
+ } else {
300984
+ this.discoveryState = MCPDiscoveryState.IN_PROGRESS;
300985
+ this.discoveryPromise = currentDiscoveryPromise;
300986
+ }
300987
+ const currentPromise = this.discoveryPromise;
300988
+ currentPromise.then((_) => {
300989
+ if (currentPromise === this.discoveryPromise) {
300990
+ this.discoveryPromise = void 0;
300991
+ this.discoveryState = MCPDiscoveryState.COMPLETED;
300992
+ }
300993
+ });
300994
+ return currentPromise;
300837
300995
  }
300838
300996
  /**
300839
300997
  * Initiates the tool discovery process for all configured MCP servers.
300840
300998
  * It connects to each server, discovers its available tools, and registers
300841
300999
  * them with the `ToolRegistry`.
300842
301000
  */
300843
- async discoverAllMcpTools(cliConfig) {
300844
- if (!cliConfig.isTrustedFolder()) {
301001
+ async discoverAllMcpTools() {
301002
+ if (!this.cliConfig.isTrustedFolder()) {
300845
301003
  return;
300846
301004
  }
300847
301005
  await this.stop();
300848
- const servers = populateMcpServerCommand(cliConfig.getMcpServers() || {}, cliConfig.getMcpServerCommand());
300849
- this.discoveryState = MCPDiscoveryState.IN_PROGRESS;
301006
+ const servers = populateMcpServerCommand(this.cliConfig.getMcpServers() || {}, this.cliConfig.getMcpServerCommand());
300850
301007
  this.eventEmitter?.emit("mcp-client-update", this.clients);
300851
- const discoveryPromises = Object.entries(servers).filter(([_, config2]) => !config2.extension || config2.extension.isActive).map(async ([name4, config2]) => {
300852
- const client = new McpClient(name4, config2, this.toolRegistry, cliConfig.getPromptRegistry(), cliConfig.getWorkspaceContext(), cliConfig.getDebugMode());
300853
- this.clients.set(name4, client);
300854
- this.eventEmitter?.emit("mcp-client-update", this.clients);
300855
- try {
300856
- await client.connect();
300857
- await client.discover(cliConfig);
300858
- this.eventEmitter?.emit("mcp-client-update", this.clients);
300859
- } catch (error) {
300860
- this.eventEmitter?.emit("mcp-client-update", this.clients);
300861
- coreEvents.emitFeedback("error", `Error during discovery for server '${name4}': ${getErrorMessage(error)}`, error);
300862
- }
300863
- });
300864
- await Promise.all(discoveryPromises);
300865
- this.discoveryState = MCPDiscoveryState.COMPLETED;
301008
+ await Promise.all(Object.entries(servers).map(async ([name4, config2]) => this.discoverMcpTools(name4, config2)));
300866
301009
  }
300867
301010
  /**
300868
301011
  * Stops all running local MCP servers and closes all client connections.
@@ -300873,7 +301016,7 @@ var McpClientManager = class {
300873
301016
  try {
300874
301017
  await client.disconnect();
300875
301018
  } catch (error) {
300876
- console.error(`Error stopping client '${name4}': ${getErrorMessage(error)}`);
301019
+ coreEvents.emitFeedback("error", `Error stopping client '${name4}':`, error);
300877
301020
  }
300878
301021
  });
300879
301022
  await Promise.all(disconnectionPromises);
@@ -301010,7 +301153,7 @@ var ToolRegistry = class {
301010
301153
  messageBus;
301011
301154
  constructor(config2, eventEmitter) {
301012
301155
  this.config = config2;
301013
- this.mcpClientManager = new McpClientManager(this, eventEmitter);
301156
+ this.mcpClientManager = new McpClientManager(this, config2, eventEmitter);
301014
301157
  }
301015
301158
  setMessageBus(messageBus) {
301016
301159
  this.messageBus = messageBus;
@@ -301059,7 +301202,7 @@ var ToolRegistry = class {
301059
301202
  this.removeDiscoveredTools();
301060
301203
  this.config.getPromptRegistry().clear();
301061
301204
  await this.discoverAndRegisterToolsFromCommand();
301062
- await this.mcpClientManager.discoverAllMcpTools(this.config);
301205
+ await this.mcpClientManager.discoverAllMcpTools();
301063
301206
  }
301064
301207
  /**
301065
301208
  * Discovers tools from project (if available and configured).
@@ -301069,7 +301212,7 @@ var ToolRegistry = class {
301069
301212
  async discoverMcpTools() {
301070
301213
  this.removeDiscoveredTools();
301071
301214
  this.config.getPromptRegistry().clear();
301072
- await this.mcpClientManager.discoverAllMcpTools(this.config);
301215
+ await this.mcpClientManager.discoverAllMcpTools();
301073
301216
  }
301074
301217
  /**
301075
301218
  * Restarts all MCP servers and re-discovers tools.
@@ -325240,12 +325383,12 @@ function deleteTempFiles(oldPath, newPath) {
325240
325383
  try {
325241
325384
  fs37.unlinkSync(oldPath);
325242
325385
  } catch {
325243
- console.error(`Error deleting temp diff file: ${oldPath}`);
325386
+ debugLogger.error(`Error deleting temp diff file: ${oldPath}`);
325244
325387
  }
325245
325388
  try {
325246
325389
  fs37.unlinkSync(newPath);
325247
325390
  } catch {
325248
- console.error(`Error deleting temp diff file: ${newPath}`);
325391
+ debugLogger.error(`Error deleting temp diff file: ${newPath}`);
325249
325392
  }
325250
325393
  }
325251
325394
  async function modifyWithEditor(originalParams, modifyContext, editorType, _abortSignal, onEditorClose) {
@@ -325531,8 +325674,7 @@ function classifyGoogleError(error) {
325531
325674
  for (const violation of quotaFailure.violations) {
325532
325675
  const quotaId = violation.quotaId ?? "";
325533
325676
  if (quotaId.includes("PerDay") || quotaId.includes("Daily")) {
325534
- return new TerminalQuotaError(`${googleApiError.message}
325535
- Expected quota reset within 24h.`, googleApiError);
325677
+ return new TerminalQuotaError(`You have exhausted your daily quota on this model.`, googleApiError);
325536
325678
  }
325537
325679
  }
325538
325680
  }
@@ -325561,8 +325703,7 @@ Expected quota reset within 24h.`, googleApiError);
325561
325703
  }
325562
325704
  const quotaLimit = errorInfo.metadata?.["quota_limit"] ?? "";
325563
325705
  if (quotaLimit.includes("PerDay") || quotaLimit.includes("Daily")) {
325564
- return new TerminalQuotaError(`${googleApiError.message}
325565
- Expected quota reset within 24h.`, googleApiError);
325706
+ return new TerminalQuotaError(`You have exhausted your daily quota on this model.`, googleApiError);
325566
325707
  }
325567
325708
  }
325568
325709
  if (retryInfo?.retryDelay) {
@@ -326441,8 +326582,7 @@ var EditToolInvocation2 = class extends BaseToolInvocation {
326441
326582
  "Proposed",
326442
326583
  DEFAULT_DIFF_OPTIONS
326443
326584
  );
326444
- const originallyProposedContent = this.params.ai_proposed_string || this.params.new_string;
326445
- const diffStat = getDiffStat(fileName, editData.currentContent ?? "", originallyProposedContent, this.params.new_string);
326585
+ const diffStat = getDiffStat(fileName, editData.currentContent ?? "", editData.newContent, this.params.new_string);
326446
326586
  displayResult = {
326447
326587
  fileDiff,
326448
326588
  fileName,
@@ -339873,6 +340013,7 @@ var GeminiChat = class {
339873
340013
  // model.
339874
340014
  sendPromise = Promise.resolve();
339875
340015
  chatRecordingService;
340016
+ lastPromptTokenCount;
339876
340017
  constructor(config2, generationConfig = {}, history = []) {
339877
340018
  this.config = config2;
339878
340019
  this.generationConfig = generationConfig;
@@ -339880,6 +340021,7 @@ var GeminiChat = class {
339880
340021
  validateHistory2(history);
339881
340022
  this.chatRecordingService = new ChatRecordingService(config2);
339882
340023
  this.chatRecordingService.initialize();
340024
+ this.lastPromptTokenCount = Math.ceil(JSON.stringify(this.history).length / 4);
339883
340025
  }
339884
340026
  setSystemInstruction(sysInstr) {
339885
340027
  this.generationConfig.systemInstruction = sysInstr;
@@ -340095,7 +340237,7 @@ This error was probably caused by cyclic schema references in one of the followi
340095
340237
  if (chunk2.usageMetadata) {
340096
340238
  this.chatRecordingService.recordMessageTokens(chunk2.usageMetadata);
340097
340239
  if (chunk2.usageMetadata.promptTokenCount !== void 0) {
340098
- uiTelemetryService.setLastPromptTokenCount(chunk2.usageMetadata.promptTokenCount);
340240
+ this.lastPromptTokenCount = chunk2.usageMetadata.promptTokenCount;
340099
340241
  }
340100
340242
  }
340101
340243
  yield chunk2;
@@ -340126,6 +340268,9 @@ This error was probably caused by cyclic schema references in one of the followi
340126
340268
  }
340127
340269
  this.history.push({ role: "model", parts: consolidatedParts });
340128
340270
  }
340271
+ getLastPromptTokenCount() {
340272
+ return this.lastPromptTokenCount;
340273
+ }
340129
340274
  /**
340130
340275
  * Gets the chat recording service instance.
340131
340276
  */
@@ -340886,7 +341031,10 @@ var LoopDetectionService = class {
340886
341031
  * @returns true if a loop is detected, false otherwise
340887
341032
  */
340888
341033
  addAndCheck(event) {
340889
- if (this.loopDetected || this.disabledForSession) {
341034
+ if (this.disabledForSession) {
341035
+ return false;
341036
+ }
341037
+ if (this.loopDetected) {
340890
341038
  return this.loopDetected;
340891
341039
  }
340892
341040
  switch (event.type) {
@@ -341144,7 +341292,7 @@ var LoopDetectionService = class {
341144
341292
  };
341145
341293
 
341146
341294
  // packages/core/dist/src/services/chatCompressionService.js
341147
- var COMPRESSION_TOKEN_THRESHOLD = 0.7;
341295
+ var DEFAULT_COMPRESSION_TOKEN_THRESHOLD = 0.2;
341148
341296
  var COMPRESSION_PRESERVE_THRESHOLD = 0.3;
341149
341297
  function findCompressSplitPoint(contents, fraction) {
341150
341298
  if (fraction <= 0 || fraction >= 1) {
@@ -341184,10 +341332,9 @@ var ChatCompressionService = class {
341184
341332
  }
341185
341333
  };
341186
341334
  }
341187
- const originalTokenCount = uiTelemetryService.getLastPromptTokenCount();
341188
- const contextPercentageThreshold = config2.getChatCompression()?.contextPercentageThreshold;
341335
+ const originalTokenCount = chat.getLastPromptTokenCount();
341189
341336
  if (!force) {
341190
- const threshold = contextPercentageThreshold ?? COMPRESSION_TOKEN_THRESHOLD;
341337
+ const threshold = config2.getCompressionThreshold() ?? DEFAULT_COMPRESSION_TOKEN_THRESHOLD;
341191
341338
  if (originalTokenCount < threshold * tokenLimit(model)) {
341192
341339
  return {
341193
341340
  newHistory: null,
@@ -341257,7 +341404,6 @@ var ChatCompressionService = class {
341257
341404
  }
341258
341405
  };
341259
341406
  } else {
341260
- uiTelemetryService.setLastPromptTokenCount(newTokenCount);
341261
341407
  return {
341262
341408
  newHistory: extraHistory,
341263
341409
  info: {
@@ -341300,8 +341446,14 @@ var GeminiClient = class {
341300
341446
  this.compressionService = new ChatCompressionService();
341301
341447
  this.lastPromptId = this.config.getSessionId();
341302
341448
  }
341449
+ updateTelemetryTokenCount() {
341450
+ if (this.chat) {
341451
+ uiTelemetryService.setLastPromptTokenCount(this.chat.getLastPromptTokenCount());
341452
+ }
341453
+ }
341303
341454
  async initialize() {
341304
341455
  this.chat = await this.startChat();
341456
+ this.updateTelemetryTokenCount();
341305
341457
  }
341306
341458
  getContentGeneratorOrFail() {
341307
341459
  if (!this.config.getContentGenerator()) {
@@ -341339,6 +341491,7 @@ var GeminiClient = class {
341339
341491
  }
341340
341492
  async resetChat() {
341341
341493
  this.chat = await this.startChat();
341494
+ this.updateTelemetryTokenCount();
341342
341495
  }
341343
341496
  getChatRecordingService() {
341344
341497
  return this.chat?.getChatRecordingService();
@@ -341536,7 +341689,7 @@ var GeminiClient = class {
341536
341689
  }
341537
341690
  const modelForLimitCheck = this._getEffectiveModelForCurrentTurn();
341538
341691
  const estimatedRequestTokenCount = Math.floor(JSON.stringify(request3).length / 4);
341539
- const remainingTokenCount = tokenLimit(modelForLimitCheck) - uiTelemetryService.getLastPromptTokenCount();
341692
+ const remainingTokenCount = tokenLimit(modelForLimitCheck) - this.getChat().getLastPromptTokenCount();
341540
341693
  if (estimatedRequestTokenCount > remainingTokenCount * 0.95) {
341541
341694
  yield {
341542
341695
  type: GeminiEventType.ContextWindowWillOverflow,
@@ -341595,6 +341748,7 @@ var GeminiClient = class {
341595
341748
  return turn;
341596
341749
  }
341597
341750
  yield event;
341751
+ this.updateTelemetryTokenCount();
341598
341752
  if (event.type === GeminiEventType.InvalidStream) {
341599
341753
  if (this.config.getContinueOnFailedApiCall()) {
341600
341754
  if (isInvalidStreamRetry) {
@@ -341682,6 +341836,7 @@ var GeminiClient = class {
341682
341836
  } else if (info2.compressionStatus === CompressionStatus.COMPRESSED) {
341683
341837
  if (newHistory) {
341684
341838
  this.chat = await this.startChat(newHistory);
341839
+ this.updateTelemetryTokenCount();
341685
341840
  this.forceFullIdeContext = true;
341686
341841
  }
341687
341842
  }
@@ -349526,13 +349681,14 @@ var Config = class {
349526
349681
  listExtensions;
349527
349682
  _extensionLoader;
349528
349683
  _enabledExtensions;
349684
+ enableExtensionReloading;
349529
349685
  _blockedMcpServers;
349530
349686
  fallbackModelHandler;
349531
349687
  quotaErrorOccurred = false;
349532
349688
  summarizeToolOutput;
349533
349689
  experimentalZedIntegration = false;
349534
349690
  loadMemoryFromIncludeDirectories = false;
349535
- chatCompression;
349691
+ compressionThreshold;
349536
349692
  interactive;
349537
349693
  ptyInfo;
349538
349694
  trustedFolder;
@@ -349620,7 +349776,7 @@ var Config = class {
349620
349776
  this.folderTrust = params.folderTrust ?? false;
349621
349777
  this.ideMode = params.ideMode ?? false;
349622
349778
  this.loadMemoryFromIncludeDirectories = params.loadMemoryFromIncludeDirectories ?? false;
349623
- this.chatCompression = params.chatCompression;
349779
+ this.compressionThreshold = params.compressionThreshold;
349624
349780
  this.interactive = params.interactive ?? false;
349625
349781
  this.ptyInfo = params.ptyInfo ?? "child_process";
349626
349782
  this.trustedFolder = params.trustedFolder;
@@ -349640,9 +349796,7 @@ var Config = class {
349640
349796
  this.useWriteTodos = params.useWriteTodos ?? false;
349641
349797
  this.initialUseModelRouter = params.useModelRouter ?? false;
349642
349798
  this.useModelRouter = this.initialUseModelRouter;
349643
- this.disableModelRouterForAuth = params.disableModelRouterForAuth ?? [
349644
- AuthType2.LOGIN_WITH_GOOGLE
349645
- ];
349799
+ this.disableModelRouterForAuth = params.disableModelRouterForAuth ?? [];
349646
349800
  this.enableMessageBusIntegration = params.enableMessageBusIntegration ?? false;
349647
349801
  this.codebaseInvestigatorSettings = {
349648
349802
  enabled: params.codebaseInvestigatorSettings?.enabled ?? false,
@@ -349654,6 +349808,7 @@ var Config = class {
349654
349808
  this.continueOnFailedApiCall = params.continueOnFailedApiCall ?? true;
349655
349809
  this.enableShellOutputEfficiency = params.enableShellOutputEfficiency ?? true;
349656
349810
  this.extensionManagement = params.extensionManagement ?? true;
349811
+ this.enableExtensionReloading = params.enableExtensionReloading ?? false;
349657
349812
  this.storage = new Storage2(this.targetDir);
349658
349813
  this.fakeResponses = params.fakeResponses;
349659
349814
  this.recordResponses = params.recordResponses;
@@ -349707,8 +349862,6 @@ var Config = class {
349707
349862
  if (this.model === DEFAULT_GEMINI_MODEL_AUTO) {
349708
349863
  this.model = DEFAULT_GEMINI_MODEL;
349709
349864
  }
349710
- } else if (this.useModelRouter && this.model === DEFAULT_GEMINI_MODEL) {
349711
- this.model = DEFAULT_GEMINI_MODEL_AUTO;
349712
349865
  }
349713
349866
  if (this.contentGeneratorConfig?.authType === AuthType2.USE_GEMINI && authMethod === AuthType2.LOGIN_WITH_GOOGLE) {
349714
349867
  this.geminiClient.stripThoughtsFromHistory();
@@ -349827,6 +349980,9 @@ var Config = class {
349827
349980
  getMcpServers() {
349828
349981
  return this.mcpServers;
349829
349982
  }
349983
+ setMcpServers(mcpServers) {
349984
+ this.mcpServers = mcpServers;
349985
+ }
349830
349986
  getUserMemory() {
349831
349987
  return this.userMemory;
349832
349988
  }
@@ -349957,6 +350113,9 @@ var Config = class {
349957
350113
  getEnabledExtensions() {
349958
350114
  return this._enabledExtensions;
349959
350115
  }
350116
+ getEnableExtensionReloading() {
350117
+ return this.enableExtensionReloading;
350118
+ }
349960
350119
  getBlockedMcpServers() {
349961
350120
  return this._blockedMcpServers;
349962
350121
  }
@@ -350004,8 +350163,8 @@ var Config = class {
350004
350163
  setFileSystemService(fileSystemService) {
350005
350164
  this.fileSystemService = fileSystemService;
350006
350165
  }
350007
- getChatCompression() {
350008
- return this.chatCompression;
350166
+ getCompressionThreshold() {
350167
+ return this.compressionThreshold;
350009
350168
  }
350010
350169
  isInteractiveShellEnabled() {
350011
350170
  return this.interactive && this.ptyInfo !== "child_process" && this.enableInteractiveShell;