@averyyy/pi-coding-agent 0.99.1-piclient.1 → 1.0.0-piclient.1

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 (219) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/dist/bundle/chunks/anthropic-messages-UID2PALB.js +6 -0
  3. package/dist/bundle/chunks/anthropic.js +2 -2
  4. package/dist/bundle/chunks/{azure-openai-responses-YZ3Q2WVP.js → azure-openai-responses-WK37QQ3X.js} +1 -1
  5. package/dist/bundle/chunks/bedrock-converse-stream.js +2 -2
  6. package/dist/bundle/chunks/{chunk-7BINYQ2V.js → chunk-2LGHNI5Y.js} +44 -39
  7. package/dist/bundle/chunks/chunk-6D7LHLKG.js +2 -0
  8. package/dist/bundle/chunks/{chunk-W2DOMZSC.js → chunk-CWVWZD3J.js} +2 -2
  9. package/dist/bundle/chunks/chunk-GIUN2MS4.js +16 -0
  10. package/dist/bundle/chunks/{chunk-F6ORSP6L.js → chunk-KYK7L7MP.js} +18 -78
  11. package/dist/bundle/chunks/chunk-LD2P6SFZ.js +2 -0
  12. package/dist/bundle/chunks/chunk-LDPPAHPJ.js +4 -0
  13. package/dist/bundle/chunks/{chunk-3YXHSP6S.js → chunk-NEUJZQL3.js} +7 -9
  14. package/dist/bundle/chunks/chunk-OI6YFHHK.js +82 -0
  15. package/dist/bundle/chunks/{chunk-J4CWPC4N.js → chunk-OSKPX3Z5.js} +1 -1
  16. package/dist/bundle/chunks/chunk-SQXKOUF6.js +2 -0
  17. package/dist/bundle/chunks/chunk-VIV3CWXG.js +2 -0
  18. package/dist/bundle/chunks/{chunk-FJTXMIZI.js → chunk-Y5O5BZGX.js} +15 -29
  19. package/dist/bundle/chunks/{chunk-V7V43FNB.js → chunk-Z772OFUN.js} +2 -2
  20. package/dist/bundle/chunks/{cli-WF6HDHBO.js → cli-JE36AHMI.js} +8 -6
  21. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-XJQQYGGU.js → cloudflare-workers-ai-system-one-NPQN263E.js} +1 -1
  22. package/dist/bundle/chunks/codemode-worker.js +67 -8
  23. package/dist/bundle/chunks/execute-UX73LR4F.js +367 -0
  24. package/dist/bundle/chunks/{google-generative-ai-CQAKKJTA.js → google-generative-ai-OHRSHIE7.js} +1 -1
  25. package/dist/bundle/chunks/{google-vertex-AE36YXJU.js → google-vertex-KXEB3MVO.js} +1 -1
  26. package/dist/bundle/chunks/{https-proxy-agent-2VXB7436.js → https-proxy-agent-UDEHOBGS.js} +1 -1
  27. package/dist/bundle/chunks/{llama-cpp-classify-PJJYKPLD.js → llama-cpp-classify-XT44PI3C.js} +1 -1
  28. package/dist/bundle/chunks/{mistral-conversations-KEYTXJM7.js → mistral-conversations-DKVFNQL6.js} +1 -1
  29. package/dist/bundle/chunks/openai-chatgpt.js +1 -1
  30. package/dist/bundle/chunks/{openai-codex-responses-FUE7WESF.js → openai-codex-responses-WVERB76N.js} +1 -1
  31. package/dist/bundle/chunks/openai-codex.js +1 -1
  32. package/dist/bundle/chunks/{openai-completions-XW2Q5HVC.js → openai-completions-JXDDPZ23.js} +1 -1
  33. package/dist/bundle/chunks/{openai-responses-ZUXFVYPI.js → openai-responses-WDT74L23.js} +1 -1
  34. package/dist/bundle/chunks/{openrouter-images-TPQ4V6OR.js → openrouter-images-ZVXWCSIM.js} +1 -1
  35. package/dist/bundle/chunks/openrouter.js +1 -1
  36. package/dist/bundle/chunks/pi-logo-animation-APS4JS6B.js +2 -0
  37. package/dist/bundle/chunks/radius.js +1 -1
  38. package/dist/bundle/chunks/runtime-MPXPM7VL.js +2 -0
  39. package/dist/bundle/chunks/{typesafe-system-one-E7A4HNJI.js → typesafe-system-one-A4CZTQWZ.js} +1 -1
  40. package/dist/bundle/chunks/virtual-modules-XLXFDFIX.js +2 -0
  41. package/dist/bundle/cli-runtime.js +1 -1
  42. package/dist/bundle/index.js +1 -1
  43. package/dist/bundle/rpc-entry.js +1 -1
  44. package/dist/cli/args.js +2 -2
  45. package/dist/cli/args.js.map +1 -1
  46. package/dist/config.d.ts +5 -8
  47. package/dist/config.d.ts.map +1 -1
  48. package/dist/config.js +16 -13
  49. package/dist/config.js.map +1 -1
  50. package/dist/core/agent-session.d.ts +15 -1
  51. package/dist/core/agent-session.d.ts.map +1 -1
  52. package/dist/core/agent-session.js +51 -10
  53. package/dist/core/agent-session.js.map +1 -1
  54. package/dist/core/extensions/loader.d.ts.map +1 -1
  55. package/dist/core/extensions/loader.js +13 -1
  56. package/dist/core/extensions/loader.js.map +1 -1
  57. package/dist/core/extensions/types.d.ts +6 -1
  58. package/dist/core/extensions/types.d.ts.map +1 -1
  59. package/dist/core/extensions/types.js.map +1 -1
  60. package/dist/core/mcp-servers.d.ts +34 -7
  61. package/dist/core/mcp-servers.d.ts.map +1 -1
  62. package/dist/core/mcp-servers.js +52 -11
  63. package/dist/core/mcp-servers.js.map +1 -1
  64. package/dist/core/model-registry.d.ts +3 -1
  65. package/dist/core/model-registry.d.ts.map +1 -1
  66. package/dist/core/model-registry.js +4 -0
  67. package/dist/core/model-registry.js.map +1 -1
  68. package/dist/core/model-runtime.d.ts +6 -0
  69. package/dist/core/model-runtime.d.ts.map +1 -1
  70. package/dist/core/model-runtime.js +22 -18
  71. package/dist/core/model-runtime.js.map +1 -1
  72. package/dist/core/radius.d.ts +2 -0
  73. package/dist/core/radius.d.ts.map +1 -1
  74. package/dist/core/radius.js +2 -0
  75. package/dist/core/radius.js.map +1 -1
  76. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  77. package/dist/core/remote-catalog-provider.js +4 -9
  78. package/dist/core/remote-catalog-provider.js.map +1 -1
  79. package/dist/core/sdk.d.ts.map +1 -1
  80. package/dist/core/sdk.js +1 -0
  81. package/dist/core/sdk.js.map +1 -1
  82. package/dist/core/settings-manager.d.ts +7 -5
  83. package/dist/core/settings-manager.d.ts.map +1 -1
  84. package/dist/core/settings-manager.js +3 -2
  85. package/dist/core/settings-manager.js.map +1 -1
  86. package/dist/core/system-prompt.js +1 -1
  87. package/dist/core/system-prompt.js.map +1 -1
  88. package/dist/core/tools/bash.d.ts.map +1 -1
  89. package/dist/core/tools/bash.js +3 -5
  90. package/dist/core/tools/bash.js.map +1 -1
  91. package/dist/core/tools/renderers/bash.d.ts.map +1 -1
  92. package/dist/core/tools/renderers/bash.js +11 -31
  93. package/dist/core/tools/renderers/bash.js.map +1 -1
  94. package/dist/core/virtual-models.d.ts +2 -0
  95. package/dist/core/virtual-models.d.ts.map +1 -1
  96. package/dist/core/virtual-models.js +19 -12
  97. package/dist/core/virtual-models.js.map +1 -1
  98. package/dist/extensions/codemode/execute.d.ts.map +1 -1
  99. package/dist/extensions/codemode/execute.js +197 -51
  100. package/dist/extensions/codemode/execute.js.map +1 -1
  101. package/dist/extensions/codemode/renderer.d.ts.map +1 -1
  102. package/dist/extensions/codemode/renderer.js +43 -25
  103. package/dist/extensions/codemode/renderer.js.map +1 -1
  104. package/dist/extensions/codemode/tool.d.ts +12 -11
  105. package/dist/extensions/codemode/tool.d.ts.map +1 -1
  106. package/dist/extensions/codemode/tool.js +73 -129
  107. package/dist/extensions/codemode/tool.js.map +1 -1
  108. package/dist/extensions/codemode/worker.d.ts +1 -1
  109. package/dist/extensions/codemode/worker.js +1 -1
  110. package/dist/extensions/codemode/worker.js.map +1 -1
  111. package/dist/extensions/mcp/cli.d.ts.map +1 -1
  112. package/dist/extensions/mcp/cli.js +20 -5
  113. package/dist/extensions/mcp/cli.js.map +1 -1
  114. package/dist/extensions/mcp/config.d.ts +4 -2
  115. package/dist/extensions/mcp/config.d.ts.map +1 -1
  116. package/dist/extensions/mcp/config.js +14 -2
  117. package/dist/extensions/mcp/config.js.map +1 -1
  118. package/dist/extensions/mcp/index.d.ts +32 -8
  119. package/dist/extensions/mcp/index.d.ts.map +1 -1
  120. package/dist/extensions/mcp/index.js +220 -56
  121. package/dist/extensions/mcp/index.js.map +1 -1
  122. package/dist/extensions/mcp/oauth.d.ts +10 -7
  123. package/dist/extensions/mcp/oauth.d.ts.map +1 -1
  124. package/dist/extensions/mcp/oauth.js +56 -31
  125. package/dist/extensions/mcp/oauth.js.map +1 -1
  126. package/dist/extensions/mcp/runtime.d.ts +2 -0
  127. package/dist/extensions/mcp/runtime.d.ts.map +1 -1
  128. package/dist/extensions/mcp/runtime.js +16 -9
  129. package/dist/extensions/mcp/runtime.js.map +1 -1
  130. package/dist/extensions/mcp/tools.d.ts +5 -4
  131. package/dist/extensions/mcp/tools.d.ts.map +1 -1
  132. package/dist/extensions/mcp/tools.js +33 -15
  133. package/dist/extensions/mcp/tools.js.map +1 -1
  134. package/dist/extensions/mcp/ui.d.ts.map +1 -1
  135. package/dist/extensions/mcp/ui.js +4 -2
  136. package/dist/extensions/mcp/ui.js.map +1 -1
  137. package/dist/extensions/tool-search/tool.d.ts +5 -4
  138. package/dist/extensions/tool-search/tool.d.ts.map +1 -1
  139. package/dist/extensions/tool-search/tool.js +7 -28
  140. package/dist/extensions/tool-search/tool.js.map +1 -1
  141. package/dist/index.d.ts +1 -1
  142. package/dist/index.d.ts.map +1 -1
  143. package/dist/index.js.map +1 -1
  144. package/dist/main.d.ts.map +1 -1
  145. package/dist/main.js +6 -0
  146. package/dist/main.js.map +1 -1
  147. package/dist/modes/interactive/components/oauth-selector.d.ts +8 -2
  148. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  149. package/dist/modes/interactive/components/oauth-selector.js +24 -21
  150. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  151. package/dist/modes/interactive/components/pi-logo-animation.d.ts +68 -0
  152. package/dist/modes/interactive/components/pi-logo-animation.d.ts.map +1 -0
  153. package/dist/modes/interactive/components/pi-logo-animation.js +1086 -0
  154. package/dist/modes/interactive/components/pi-logo-animation.js.map +1 -0
  155. package/dist/modes/interactive/components/pi-logo-animation.lazy.d.ts +7 -0
  156. package/dist/modes/interactive/components/pi-logo-animation.lazy.d.ts.map +1 -0
  157. package/dist/modes/interactive/components/pi-logo-animation.lazy.js +12 -0
  158. package/dist/modes/interactive/components/pi-logo-animation.lazy.js.map +1 -0
  159. package/dist/modes/interactive/components/pi-logo.d.ts +7 -0
  160. package/dist/modes/interactive/components/pi-logo.d.ts.map +1 -1
  161. package/dist/modes/interactive/components/pi-logo.js +13 -1
  162. package/dist/modes/interactive/components/pi-logo.js.map +1 -1
  163. package/dist/modes/interactive/components/radius-login-selector.d.ts +15 -0
  164. package/dist/modes/interactive/components/radius-login-selector.d.ts.map +1 -0
  165. package/dist/modes/interactive/components/radius-login-selector.js +85 -0
  166. package/dist/modes/interactive/components/radius-login-selector.js.map +1 -0
  167. package/dist/modes/interactive/components/settings-selector.d.ts +3 -3
  168. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  169. package/dist/modes/interactive/components/settings-selector.js +5 -5
  170. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  171. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  172. package/dist/modes/interactive/components/user-message.js +5 -4
  173. package/dist/modes/interactive/components/user-message.js.map +1 -1
  174. package/dist/modes/interactive/components/visual-truncate.d.ts +27 -3
  175. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  176. package/dist/modes/interactive/components/visual-truncate.js +39 -6
  177. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  178. package/dist/modes/interactive/interactive-mode.d.ts +10 -0
  179. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  180. package/dist/modes/interactive/interactive-mode.js +153 -40
  181. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  182. package/dist/modes/interactive/theme/system-theme.d.ts +2 -1
  183. package/dist/modes/interactive/theme/system-theme.d.ts.map +1 -1
  184. package/dist/modes/interactive/theme/system-theme.js +16 -5
  185. package/dist/modes/interactive/theme/system-theme.js.map +1 -1
  186. package/docs/cli.md +8 -18
  187. package/docs/codemode.md +207 -0
  188. package/docs/docs.json +5 -1
  189. package/docs/environment-variables.md +2 -2
  190. package/docs/extensions.md +3 -3
  191. package/docs/index.md +1 -1
  192. package/docs/mcp.md +142 -82
  193. package/docs/models.md +22 -1
  194. package/docs/providers.md +18 -6
  195. package/docs/sdk.md +2 -2
  196. package/docs/settings.md +5 -3
  197. package/docs/usage.md +1 -1
  198. package/examples/extensions/built-in-tool-renderer.ts +16 -40
  199. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  200. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  201. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  202. package/examples/extensions/gondolin/package-lock.json +2 -2
  203. package/examples/extensions/gondolin/package.json +1 -1
  204. package/examples/extensions/minimal-mode.ts +24 -96
  205. package/examples/extensions/sandbox/package-lock.json +2 -2
  206. package/examples/extensions/sandbox/package.json +1 -1
  207. package/examples/extensions/with-deps/package-lock.json +2 -2
  208. package/examples/extensions/with-deps/package.json +1 -1
  209. package/examples/sdk/14-codemode-mcp.ts +2 -2
  210. package/package.json +10 -10
  211. package/dist/bundle/chunks/anthropic-messages-A6EXUBG6.js +0 -6
  212. package/dist/bundle/chunks/chunk-HSPCVFST.js +0 -2
  213. package/dist/bundle/chunks/chunk-KYJKN5BJ.js +0 -2
  214. package/dist/bundle/chunks/chunk-RO6I2QFQ.js +0 -4
  215. package/dist/bundle/chunks/chunk-WVKBMRQX.js +0 -82
  216. package/dist/bundle/chunks/chunk-XNGRGP62.js +0 -2
  217. package/dist/bundle/chunks/execute-AVGAUHMT.js +0 -308
  218. package/dist/bundle/chunks/runtime-6ZC4MGWD.js +0 -2
  219. package/dist/bundle/chunks/virtual-modules-H7OCXN6W.js +0 -2
@@ -39,6 +39,7 @@ import { cancelPiServerOperations, compactPiServer, hashStaticContext, } from ".
39
39
  import { hashPiServerProviderMessages } from "./pi-server-protocol.js";
40
40
  import { expandPromptTemplate } from "./prompt-templates.js";
41
41
  import { CURRENT_SESSION_VERSION, getLatestCompactionEntry, SessionManager, } from "./session-manager.js";
42
+ import { DEFAULT_TOOL_NAMES } from "./settings-manager.js";
42
43
  import { BUILTIN_PATH_PREFIX, createSyntheticSourceInfo, isSyntheticPath } from "./source-info.js";
43
44
  import { buildSystemPrompt, buildSystemPromptSections, diffSystemPromptSections, normalizeBuildSystemPromptOptions, } from "./system-prompt.js";
44
45
  import { createLocalBashOperations } from "./tools/bash.js";
@@ -235,6 +236,13 @@ export class AgentSession {
235
236
  _cwd;
236
237
  _extensionRunnerRef;
237
238
  _initialActiveToolNames;
239
+ /**
240
+ * Tools of the restored or reloaded loadout that are not registered yet, such as tools of MCP
241
+ * servers that are still connecting. They are activated when they are registered, and dropped when
242
+ * `setActiveToolsByName()` deactivates a tool or the next agent run starts.
243
+ */
244
+ _pendingToolNames = new Set();
245
+ _usesDefaultTools;
238
246
  _allowedToolNames;
239
247
  _excludedToolNames;
240
248
  _baseToolsOverride;
@@ -277,6 +285,7 @@ export class AgentSession {
277
285
  }
278
286
  this._extensionRunnerRef = config.extensionRunnerRef;
279
287
  this._initialActiveToolNames = config.initialActiveToolNames;
288
+ this._usesDefaultTools = config.usesDefaultTools ?? false;
280
289
  this._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : undefined;
281
290
  this._excludedToolNames = config.excludedToolNames ? new Set(config.excludedToolNames) : undefined;
282
291
  this._baseToolsOverride = config.baseToolsOverride;
@@ -1299,9 +1308,23 @@ export class AgentSession {
1299
1308
  * Changes take effect on the next agent turn.
1300
1309
  */
1301
1310
  setActiveToolsByName(toolNames) {
1311
+ const previous = this.getActiveToolNames();
1312
+ this._setActiveTools(toolNames);
1313
+ // A loadout that deactivates a tool replaces the restored one, whose pending tools are dropped.
1314
+ // One that only adds tools, like activating tool_search, keeps them.
1315
+ const active = new Set(this.getActiveToolNames());
1316
+ if (previous.some((name) => !active.has(name)))
1317
+ this._pendingToolNames.clear();
1318
+ }
1319
+ _setActiveTools(toolNames) {
1302
1320
  const tools = this._applyToolLoadout(toolNames);
1321
+ for (const tool of tools)
1322
+ this._pendingToolNames.delete(tool.name);
1303
1323
  this._rebuildSystemPrompt(tools.map((tool) => tool.name));
1304
1324
  }
1325
+ _isAllowedTool(name) {
1326
+ return (!this._allowedToolNames || this._allowedToolNames.has(name)) && !this._excludedToolNames?.has(name);
1327
+ }
1305
1328
  _getToolExposure(name) {
1306
1329
  return this._toolDefinitions.get(name)?.definition.exposure ?? "direct";
1307
1330
  }
@@ -1437,7 +1460,8 @@ export class AgentSession {
1437
1460
  const toolSnippets = {};
1438
1461
  for (const name of this._toolRegistry.keys()) {
1439
1462
  const snippet = this._toolPromptSnippets.get(name);
1440
- if (snippet)
1463
+ // Tools without a snippet are not listed. Hidden tools are only callable through another tool.
1464
+ if (snippet && !this._hiddenDeclarations.has(name))
1441
1465
  toolSnippets[name] = snippet;
1442
1466
  }
1443
1467
  const loaderSystemPrompt = this._resourceLoader.getSystemPrompt();
@@ -1468,6 +1492,8 @@ export class AgentSession {
1468
1492
  */
1469
1493
  _preparePromptAndToolLoadout(options, messages = this.agent.state.messages) {
1470
1494
  options.selectedTools = this._applyToolLoadout(options.selectedTools).map((tool) => tool.name);
1495
+ // The tool list must match the declarations the request carries, so hidden tools are not listed.
1496
+ options.toolSnippets = Object.fromEntries(Object.entries(options.toolSnippets).filter(([name]) => !this._hiddenDeclarations.has(name)));
1471
1497
  const sections = diffSystemPromptSections(getCurrentSystemMessage(messages)?.sections ?? {}, buildSystemPromptSections(options));
1472
1498
  return sections ? { role: "system", content: "", sections, timestamp: Date.now() } : undefined;
1473
1499
  }
@@ -1532,10 +1558,13 @@ export class AgentSession {
1532
1558
  * set, so the transcript's declarations are the whole loadout.
1533
1559
  */
1534
1560
  _restoreToolsFromTranscript() {
1561
+ this._pendingToolNames.clear();
1535
1562
  const current = getCurrentSystemMessage(this.sessionManager.buildSessionContext().messages);
1536
1563
  if (!current)
1537
1564
  return;
1538
- this.setActiveToolsByName((current.toolsAdded ?? []).map((tool) => tool.name));
1565
+ const names = (current.toolsAdded ?? []).map((tool) => tool.name);
1566
+ this._pendingToolNames = new Set(names.filter((name) => this._isAllowedTool(name)));
1567
+ this._setActiveTools(names);
1539
1568
  }
1540
1569
  // =========================================================================
1541
1570
  // Prompting
@@ -1545,6 +1574,9 @@ export class AgentSession {
1545
1574
  // Compaction before the prompt may have scheduled a retry; the new prompt replaces it.
1546
1575
  this._failedResponse = undefined;
1547
1576
  this._recordSelection();
1577
+ // The run records the loadout in the transcript; restored tools that did not register by now
1578
+ // are dropped, so a tool that never registers does not stay pending.
1579
+ this._pendingToolNames.clear();
1548
1580
  this._isAgentRunActive = true;
1549
1581
  try {
1550
1582
  await start();
@@ -3433,8 +3465,6 @@ export class AgentSession {
3433
3465
  const previousActivatedOnRegistration = new Set([...this._toolRegistry.keys()].filter((name) => this._isActivatedOnRegistration(name)));
3434
3466
  const previousActiveToolNames = this.getActiveToolNames();
3435
3467
  const allowedToolNames = this._allowedToolNames;
3436
- const excludedToolNames = this._excludedToolNames;
3437
- const isAllowedTool = (name) => (!allowedToolNames || allowedToolNames.has(name)) && !excludedToolNames?.has(name);
3438
3468
  const registeredTools = this._extensionRunner.getAllRegisteredTools();
3439
3469
  const allCustomTools = [
3440
3470
  ...registeredTools,
@@ -3442,9 +3472,9 @@ export class AgentSession {
3442
3472
  definition,
3443
3473
  sourceInfo: createSyntheticSourceInfo(`<sdk:${definition.name}>`, { source: "sdk" }),
3444
3474
  })),
3445
- ].filter((tool) => isAllowedTool(tool.definition.name));
3475
+ ].filter((tool) => this._isAllowedTool(tool.definition.name));
3446
3476
  const definitionRegistry = new Map(Array.from(this._baseToolDefinitions.entries())
3447
- .filter(([name]) => isAllowedTool(name))
3477
+ .filter(([name]) => this._isAllowedTool(name))
3448
3478
  .map(([name, definition]) => [
3449
3479
  name,
3450
3480
  {
@@ -3474,7 +3504,7 @@ export class AgentSession {
3474
3504
  const runner = this._extensionRunner;
3475
3505
  const wrappedExtensionTools = wrapRegisteredTools(allCustomTools, runner);
3476
3506
  const wrappedBuiltInTools = wrapRegisteredTools(Array.from(this._baseToolDefinitions.values())
3477
- .filter((definition) => isAllowedTool(definition.name))
3507
+ .filter((definition) => this._isAllowedTool(definition.name))
3478
3508
  .map((definition) => ({
3479
3509
  definition,
3480
3510
  sourceInfo: createSyntheticSourceInfo(`${BUILTIN_PATH_PREFIX}${definition.name}`, {
@@ -3486,7 +3516,7 @@ export class AgentSession {
3486
3516
  toolRegistry.set(tool.name, tool);
3487
3517
  }
3488
3518
  this._toolRegistry = toolRegistry;
3489
- const nextActiveToolNames = (options?.activeToolNames ? [...options.activeToolNames] : [...previousActiveToolNames]).filter((name) => isAllowedTool(name));
3519
+ const nextActiveToolNames = (options?.activeToolNames ? [...options.activeToolNames] : [...previousActiveToolNames]).filter((name) => this._isAllowedTool(name));
3490
3520
  if (allowedToolNames) {
3491
3521
  for (const toolName of this._toolRegistry.keys()) {
3492
3522
  // Naming a tool activates it even when it is not active by default.
@@ -3508,7 +3538,9 @@ export class AgentSession {
3508
3538
  }
3509
3539
  }
3510
3540
  }
3511
- this.setActiveToolsByName([...new Set(nextActiveToolNames)]);
3541
+ // Pending tools that are registered now become active.
3542
+ nextActiveToolNames.push(...this._pendingToolNames);
3543
+ this._setActiveTools([...new Set(nextActiveToolNames)]);
3512
3544
  }
3513
3545
  /** Whether activating the tool declares it to the model. */
3514
3546
  _isDeclarable(name) {
@@ -3559,12 +3591,21 @@ export class AgentSession {
3559
3591
  const previousFlagValues = oldRunner.getFlagValues();
3560
3592
  await emitSessionShutdownEvent(oldRunner, { type: "session_shutdown", reason: "reload" });
3561
3593
  oldRunner.invalidate();
3594
+ const previousDefaultTools = new Set(this._usesDefaultTools ? (this.settingsManager.getDefaultTools() ?? DEFAULT_TOOL_NAMES) : []);
3562
3595
  await this.settingsManager.reload();
3563
3596
  this.syncQueueModesFromSettings();
3564
3597
  resetApiProviders();
3565
3598
  await this._resourceLoader.reload();
3599
+ // Activate tools newly added to defaultTools. Removed ones stay active, and tools disabled
3600
+ // during the session stay disabled unless the setting newly adds them.
3601
+ const addedDefaultTools = this._usesDefaultTools
3602
+ ? (this.settingsManager.getDefaultTools() ?? DEFAULT_TOOL_NAMES).filter((name) => !previousDefaultTools.has(name))
3603
+ : [];
3604
+ // Tools the new extensions register later, such as MCP tools, are pending until then.
3605
+ for (const name of this.getActiveToolNames())
3606
+ this._pendingToolNames.add(name);
3566
3607
  this._buildRuntime({
3567
- activeToolNames: this.getActiveToolNames(),
3608
+ activeToolNames: [...this.getActiveToolNames(), ...addedDefaultTools],
3568
3609
  flagValues: previousFlagValues,
3569
3610
  includeAllExtensionTools: true,
3570
3611
  });