wave-agent-sdk 1.0.5 → 1.0.6

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 (193) hide show
  1. package/dist/agent.d.ts +23 -1
  2. package/dist/agent.js +34 -4
  3. package/dist/managers/aiManager.d.ts +36 -0
  4. package/dist/managers/aiManager.js +240 -8
  5. package/dist/managers/messageManager.d.ts +1 -3
  6. package/dist/managers/messageManager.js +13 -6
  7. package/dist/managers/slashCommandManager.js +28 -0
  8. package/dist/managers/subagentManager.d.ts +0 -2
  9. package/dist/telemetry/instrumentation.d.ts +1 -1
  10. package/dist/telemetry/instrumentation.js +57 -28
  11. package/dist/tools/bashTool.js +16 -6
  12. package/dist/tools/grepTool.js +11 -3
  13. package/dist/types/index.d.ts +3 -0
  14. package/dist/types/messaging.d.ts +2 -0
  15. package/dist/utils/containerSetup.js +0 -3
  16. package/dist/utils/messageOperations.d.ts +2 -1
  17. package/dist/utils/messageOperations.js +2 -1
  18. package/dist/utils/notificationXml.js +5 -0
  19. package/dist/utils/ripgrep.d.ts +4 -4
  20. package/dist/utils/ripgrep.js +4 -27
  21. package/package.json +20 -8
  22. package/bin/rg +0 -79
  23. package/dist/managers/forkedAgentManager.d.ts +0 -50
  24. package/dist/managers/forkedAgentManager.js +0 -130
  25. package/scripts/install_ripgrep.js +0 -111
  26. package/scripts/postinstall.js +0 -38
  27. package/src/agent.ts +0 -1271
  28. package/src/constants/subagents.ts +0 -4
  29. package/src/constants/toolLimits.ts +0 -15
  30. package/src/constants/tools.ts +0 -24
  31. package/src/core/plugin.ts +0 -237
  32. package/src/core/session.ts +0 -9
  33. package/src/index.ts +0 -38
  34. package/src/managers/MemoryRuleManager.ts +0 -198
  35. package/src/managers/aiManager.ts +0 -2429
  36. package/src/managers/backgroundTaskManager.ts +0 -480
  37. package/src/managers/bangManager.ts +0 -119
  38. package/src/managers/cronManager.ts +0 -401
  39. package/src/managers/foregroundTaskManager.ts +0 -30
  40. package/src/managers/forkedAgentManager.ts +0 -216
  41. package/src/managers/hookManager.ts +0 -1089
  42. package/src/managers/liveConfigManager.ts +0 -445
  43. package/src/managers/lspManager.ts +0 -470
  44. package/src/managers/mcpManager.ts +0 -1010
  45. package/src/managers/messageManager.ts +0 -1184
  46. package/src/managers/messageQueue.ts +0 -157
  47. package/src/managers/permissionManager.ts +0 -1140
  48. package/src/managers/planManager.ts +0 -112
  49. package/src/managers/pluginManager.ts +0 -330
  50. package/src/managers/pluginScopeManager.ts +0 -124
  51. package/src/managers/reversionManager.ts +0 -178
  52. package/src/managers/skillManager.ts +0 -578
  53. package/src/managers/slashCommandManager.ts +0 -564
  54. package/src/managers/subagentManager.ts +0 -915
  55. package/src/managers/toolManager.ts +0 -489
  56. package/src/managers/workflowManager.ts +0 -493
  57. package/src/prompts/autoMemory.ts +0 -33
  58. package/src/prompts/autoMemoryExtraction.ts +0 -146
  59. package/src/prompts/index.ts +0 -506
  60. package/src/prompts/planModeReminders.ts +0 -126
  61. package/src/services/GitService.ts +0 -131
  62. package/src/services/MarketplaceService.ts +0 -1052
  63. package/src/services/MemoryRuleService.ts +0 -71
  64. package/src/services/aiService.ts +0 -919
  65. package/src/services/authService.ts +0 -565
  66. package/src/services/autoMemoryService.ts +0 -280
  67. package/src/services/configurationService.ts +0 -1520
  68. package/src/services/fileWatcher.ts +0 -319
  69. package/src/services/hook.ts +0 -348
  70. package/src/services/initializationService.ts +0 -357
  71. package/src/services/interactionService.ts +0 -229
  72. package/src/services/jsonlHandler.ts +0 -295
  73. package/src/services/memory.ts +0 -234
  74. package/src/services/pluginLoader.ts +0 -252
  75. package/src/services/remoteSettingsService.ts +0 -366
  76. package/src/services/reversionService.ts +0 -122
  77. package/src/services/session.ts +0 -917
  78. package/src/services/taskManager.ts +0 -321
  79. package/src/telemetry/events.ts +0 -65
  80. package/src/telemetry/instrumentation.ts +0 -499
  81. package/src/telemetry/sessionTracing.ts +0 -348
  82. package/src/tools/agentTool.ts +0 -322
  83. package/src/tools/askUserQuestion.ts +0 -160
  84. package/src/tools/bashTool.ts +0 -621
  85. package/src/tools/buildTool.ts +0 -61
  86. package/src/tools/cronCreateTool.ts +0 -161
  87. package/src/tools/cronDeleteTool.ts +0 -51
  88. package/src/tools/cronListTool.ts +0 -47
  89. package/src/tools/editTool.ts +0 -313
  90. package/src/tools/enterPlanMode.ts +0 -124
  91. package/src/tools/enterWorktreeTool.ts +0 -190
  92. package/src/tools/exitPlanMode.ts +0 -139
  93. package/src/tools/exitWorktreeTool.ts +0 -236
  94. package/src/tools/globTool.ts +0 -167
  95. package/src/tools/grepTool.ts +0 -399
  96. package/src/tools/lspTool.ts +0 -883
  97. package/src/tools/readTool.ts +0 -426
  98. package/src/tools/skillTool.ts +0 -248
  99. package/src/tools/taskManagementTools.ts +0 -574
  100. package/src/tools/taskStopTool.ts +0 -78
  101. package/src/tools/types.ts +0 -137
  102. package/src/tools/webFetchTool.ts +0 -373
  103. package/src/tools/workflowTool.ts +0 -205
  104. package/src/tools/writeTool.ts +0 -267
  105. package/src/types/agent.ts +0 -128
  106. package/src/types/auth.ts +0 -19
  107. package/src/types/commands.ts +0 -30
  108. package/src/types/config.ts +0 -43
  109. package/src/types/configuration.ts +0 -168
  110. package/src/types/core.ts +0 -105
  111. package/src/types/cron.ts +0 -13
  112. package/src/types/environment.ts +0 -106
  113. package/src/types/fileSearch.ts +0 -4
  114. package/src/types/history.ts +0 -7
  115. package/src/types/hooks.ts +0 -256
  116. package/src/types/index.ts +0 -41
  117. package/src/types/lsp.ts +0 -98
  118. package/src/types/marketplace.ts +0 -71
  119. package/src/types/mcp.ts +0 -43
  120. package/src/types/memoryRule.ts +0 -31
  121. package/src/types/messaging.ts +0 -114
  122. package/src/types/permissions.ts +0 -80
  123. package/src/types/plugins.ts +0 -39
  124. package/src/types/processes.ts +0 -99
  125. package/src/types/reversion.ts +0 -29
  126. package/src/types/session.ts +0 -12
  127. package/src/types/skills.ts +0 -108
  128. package/src/types/tasks.ts +0 -13
  129. package/src/types/telemetry.ts +0 -98
  130. package/src/types/tools.ts +0 -44
  131. package/src/types/workflow.ts +0 -6
  132. package/src/utils/abortUtils.ts +0 -118
  133. package/src/utils/atomicWrite.ts +0 -61
  134. package/src/utils/bashParser.ts +0 -899
  135. package/src/utils/cacheControlUtils.ts +0 -426
  136. package/src/utils/commandArgumentParser.ts +0 -161
  137. package/src/utils/commandPathResolver.ts +0 -88
  138. package/src/utils/configPaths.ts +0 -220
  139. package/src/utils/configValidator.ts +0 -100
  140. package/src/utils/constants.ts +0 -39
  141. package/src/utils/container.ts +0 -92
  142. package/src/utils/containerSetup.ts +0 -371
  143. package/src/utils/convertMessagesForAPI.ts +0 -326
  144. package/src/utils/cronTasks.ts +0 -128
  145. package/src/utils/cronTasksLock.ts +0 -182
  146. package/src/utils/cronToHuman.ts +0 -99
  147. package/src/utils/customCommands.ts +0 -95
  148. package/src/utils/editUtils.ts +0 -20
  149. package/src/utils/fileFormat.ts +0 -40
  150. package/src/utils/fileSearch.ts +0 -151
  151. package/src/utils/fileUtils.ts +0 -223
  152. package/src/utils/gitUtils.ts +0 -315
  153. package/src/utils/globalLogger.ts +0 -128
  154. package/src/utils/groupMessagesByApiRound.ts +0 -121
  155. package/src/utils/hookMatcher.ts +0 -176
  156. package/src/utils/markdownParser.ts +0 -317
  157. package/src/utils/mcpUtils.ts +0 -138
  158. package/src/utils/messageOperations.ts +0 -659
  159. package/src/utils/modelCapabilities.ts +0 -30
  160. package/src/utils/nameGenerator.ts +0 -99
  161. package/src/utils/notificationXml.ts +0 -57
  162. package/src/utils/openaiClient.ts +0 -251
  163. package/src/utils/parseCronExpression.ts +0 -78
  164. package/src/utils/path.ts +0 -72
  165. package/src/utils/pathEncoder.ts +0 -400
  166. package/src/utils/pathSafety.ts +0 -40
  167. package/src/utils/promptHistory.ts +0 -168
  168. package/src/utils/ripgrep.ts +0 -35
  169. package/src/utils/shellResolver.ts +0 -190
  170. package/src/utils/skillParser.ts +0 -246
  171. package/src/utils/stringUtils.ts +0 -156
  172. package/src/utils/subagentParser.ts +0 -279
  173. package/src/utils/taskReminder.ts +0 -96
  174. package/src/utils/tokenCalculation.ts +0 -43
  175. package/src/utils/tokenEstimate.ts +0 -34
  176. package/src/utils/toolResultStorage.ts +0 -117
  177. package/src/utils/worktreeSession.ts +0 -26
  178. package/src/utils/worktreeUtils.ts +0 -786
  179. package/src/workflow/budgetTracker.ts +0 -34
  180. package/src/workflow/concurrencyLimiter.ts +0 -47
  181. package/src/workflow/journal.ts +0 -95
  182. package/src/workflow/progressReporter.ts +0 -141
  183. package/src/workflow/runState.ts +0 -65
  184. package/src/workflow/scriptRuntime.ts +0 -274
  185. package/src/workflow/structuredOutput.ts +0 -123
  186. package/src/workflow/types.ts +0 -101
  187. package/src/workflow/workflowApis.ts +0 -410
  188. package/vendor/ripgrep/linux-aarch64/rg +0 -0
  189. package/vendor/ripgrep/linux-x86_64/rg +0 -0
  190. package/vendor/ripgrep/macos-aarch64/rg +0 -0
  191. package/vendor/ripgrep/macos-x86_64/rg +0 -0
  192. package/vendor/ripgrep/windows-aarch64/rg.exe +0 -0
  193. package/vendor/ripgrep/windows-x86_64/rg.exe +0 -0
@@ -1,489 +0,0 @@
1
- import type { ToolContext, ToolPlugin, ToolResult } from "../tools/types.js";
2
- import { bashTool } from "../tools/bashTool.js";
3
- import { taskStopTool } from "../tools/taskStopTool.js";
4
- import { editTool } from "../tools/editTool.js";
5
- import { writeTool } from "../tools/writeTool.js";
6
- import { exitPlanModeTool } from "../tools/exitPlanMode.js";
7
- import { enterPlanModeTool } from "../tools/enterPlanMode.js";
8
- import { askUserQuestionTool } from "../tools/askUserQuestion.js";
9
- import { cronCreateTool } from "../tools/cronCreateTool.js";
10
- import { cronDeleteTool } from "../tools/cronDeleteTool.js";
11
- import { cronListTool } from "../tools/cronListTool.js";
12
- import { webFetchTool } from "../tools/webFetchTool.js";
13
- // New tools
14
- import { globTool } from "../tools/globTool.js";
15
- import { grepTool } from "../tools/grepTool.js";
16
- import { readTool } from "../tools/readTool.js";
17
- import { lspTool } from "../tools/lspTool.js";
18
- import { agentTool } from "../tools/agentTool.js";
19
- import { skillTool } from "../tools/skillTool.js";
20
- import {
21
- taskCreateTool,
22
- taskGetTool,
23
- taskUpdateTool,
24
- taskListTool,
25
- } from "../tools/taskManagementTools.js";
26
- import { enterWorktreeTool } from "../tools/enterWorktreeTool.js";
27
- import { exitWorktreeTool } from "../tools/exitWorktreeTool.js";
28
- import { workflowTool } from "../tools/workflowTool.js";
29
- import { McpManager } from "./mcpManager.js";
30
- import { PermissionManager } from "./permissionManager.js";
31
- import { ChatCompletionFunctionTool } from "openai/resources.js";
32
- import type {
33
- PermissionMode,
34
- PermissionCallback,
35
- ILspManager,
36
- } from "../types/index.js";
37
- import type { SubagentManager } from "./subagentManager.js";
38
- import type { SkillManager } from "./skillManager.js";
39
-
40
- import { ReversionManager } from "./reversionManager.js";
41
- import * as aiService from "../services/aiService.js";
42
-
43
- import { Container } from "../utils/container.js";
44
-
45
- import { logger } from "../utils/globalLogger.js";
46
-
47
- import type { SubagentConfiguration } from "../utils/subagentParser.js";
48
- import type { SkillMetadata } from "../types/skills.js";
49
- import { startToolSpan, endToolSpan } from "../telemetry/sessionTracing.js";
50
-
51
- export interface ToolManagerOptions {
52
- container: Container;
53
- /** Optional list of tool names to enable */
54
- tools?: string[];
55
- /** Custom tools to register alongside built-in tools */
56
- customTools?: ToolPlugin[];
57
- }
58
-
59
- /**
60
- * Tool Manager
61
- *
62
- * Manages tool registration and execution with optional permission system integration.
63
- * Supports both built-in tools and MCP (Model Context Protocol) tools.
64
- */
65
- class ToolManager {
66
- private toolsRegistry = new Map<string, ToolPlugin>();
67
- private tools?: string[];
68
- private customTools?: ToolPlugin[];
69
- private container: Container;
70
-
71
- constructor(options: ToolManagerOptions) {
72
- this.container = options.container;
73
- this.tools = options.tools;
74
- this.customTools = options.customTools;
75
- }
76
-
77
- private get mcpManager(): McpManager {
78
- return this.container.get<McpManager>("McpManager")!;
79
- }
80
-
81
- /**
82
- * Register a new tool
83
- */
84
- public register(tool: ToolPlugin): void {
85
- this.toolsRegistry.set(tool.name, tool);
86
- }
87
-
88
- /**
89
- * Initialize built-in tools. Can be called with dependencies for tools that require them.
90
- *
91
- * This method can be called multiple times safely. When called without dependencies,
92
- * it registers basic tools (Bash, Read, Write, TaskCreate, etc.). When called with
93
- * dependencies, it also registers tools that require managers (Agent, Skill).
94
- *
95
- * @param deps Optional dependencies for advanced tools
96
- * @param deps.subagentManager SubagentManager instance for Agent tool
97
- * @param deps.skillManager SkillManager instance for Skill tool
98
- *
99
- * @example
100
- * ```typescript
101
- * // Initialize basic tools only
102
- * toolManager.initializeBuiltInTools();
103
- *
104
- * // Initialize all tools including those requiring dependencies
105
- * toolManager.initializeBuiltInTools({
106
- * subagentManager: mySubagentManager,
107
- * skillManager: mySkillManager
108
- * });
109
- * ```
110
- */
111
- public initializeBuiltInTools(): void {
112
- const builtInTools = [
113
- bashTool,
114
- taskStopTool,
115
- editTool,
116
- writeTool,
117
- exitPlanModeTool,
118
- enterPlanModeTool,
119
- askUserQuestionTool,
120
- globTool,
121
- grepTool,
122
- readTool,
123
- lspTool,
124
- agentTool,
125
- skillTool,
126
- taskCreateTool,
127
- taskGetTool,
128
- taskUpdateTool,
129
- taskListTool,
130
- cronCreateTool,
131
- cronDeleteTool,
132
- cronListTool,
133
- webFetchTool,
134
- enterWorktreeTool,
135
- exitWorktreeTool,
136
- workflowTool,
137
- ];
138
-
139
- for (const tool of builtInTools) {
140
- if (this.shouldEnableTool(tool.name)) {
141
- this.toolsRegistry.set(tool.name, tool);
142
- }
143
- }
144
-
145
- // Register custom tools
146
- for (const tool of this.customTools || []) {
147
- if (this.shouldEnableTool(tool.name)) {
148
- this.toolsRegistry.set(tool.name, tool);
149
- }
150
- }
151
- }
152
-
153
- /**
154
- * Check if a tool should be enabled based on tools configuration and permission rules
155
- */
156
- private shouldEnableTool(name: string): boolean {
157
- const permissionManager =
158
- this.container.get<PermissionManager>("PermissionManager");
159
-
160
- // If tool is explicitly denied by name in permission rules, filter it out
161
- if (permissionManager?.isToolDenied(name)) {
162
- return false;
163
- }
164
-
165
- if (!this.tools) {
166
- return true;
167
- }
168
- return this.tools.some(
169
- (toolName) => toolName.toLowerCase() === name.toLowerCase(),
170
- );
171
- }
172
-
173
- /**
174
- * Execute a tool by name with the provided arguments and context
175
- *
176
- * Enhances the context with permission-related fields before execution:
177
- * - permissionMode: The current permission mode (default or bypassPermissions)
178
- * - canUseToolCallback: Custom permission callback if provided
179
- * - permissionManager: The PermissionManager instance for permission checks
180
- *
181
- * @param name - Name of the tool to execute
182
- * @param args - Arguments to pass to the tool
183
- * @param context - Execution context for the tool
184
- * @returns Promise resolving to the tool execution result
185
- */
186
- async execute(
187
- name: string,
188
- args: Record<string, unknown>,
189
- context: ToolContext,
190
- ): Promise<ToolResult> {
191
- const permissionManager =
192
- this.container.get<PermissionManager>("PermissionManager");
193
- const permissionMode = this.container.has("PermissionMode")
194
- ? this.container.get<PermissionMode>("PermissionMode")
195
- : undefined;
196
-
197
- // Resolve effective permission mode (CLI override > configuration > default)
198
- const effectivePermissionMode = permissionManager
199
- ? permissionManager.getCurrentEffectiveMode(permissionMode)
200
- : permissionMode || "default";
201
-
202
- // Enhance context with permission-related fields
203
- const canUseToolCallback = this.container.has("CanUseToolCallback")
204
- ? this.container.get<PermissionCallback>("CanUseToolCallback")
205
- : undefined;
206
-
207
- const enhancedContext: ToolContext = {
208
- ...context,
209
- permissionMode: effectivePermissionMode,
210
- canUseToolCallback,
211
- permissionManager,
212
- toolManager: this,
213
- taskManager:
214
- this.container.get<import("../services/taskManager.js").TaskManager>(
215
- "TaskManager",
216
- )!,
217
- reversionManager:
218
- this.container.get<ReversionManager>("ReversionManager")!,
219
- backgroundTaskManager: this.container.get<
220
- import("./backgroundTaskManager.js").BackgroundTaskManager
221
- >("BackgroundTaskManager")!,
222
- foregroundTaskManager: this.container.get<
223
- import("../types/processes.js").IForegroundTaskManager
224
- >("ForegroundTaskManager")!,
225
- mcpManager: this.mcpManager,
226
- lspManager: this.container.get<ILspManager>("LspManager")!,
227
- subagentManager: this.container.has("SubagentManager")
228
- ? this.container.get<SubagentManager>("SubagentManager")
229
- : undefined,
230
- skillManager: this.container.has("SkillManager")
231
- ? this.container.get<SkillManager>("SkillManager")
232
- : undefined,
233
- cronManager: this.container.has("CronManager")
234
- ? this.container.get<import("./cronManager.js").CronManager>(
235
- "CronManager",
236
- )
237
- : undefined,
238
- aiManager: this.container.has("AIManager")
239
- ? this.container.get<import("./aiManager.js").AIManager>("AIManager")
240
- : undefined,
241
- aiService: aiService,
242
- messageManager:
243
- this.container.get<import("./messageManager.js").MessageManager>(
244
- "MessageManager",
245
- )!,
246
- hookManager: this.container.has("HookManager")
247
- ? this.container.get<import("./hookManager.js").HookManager>(
248
- "HookManager",
249
- )
250
- : undefined,
251
- workflowManager: this.container.has("WorkflowManager")
252
- ? this.container.get<import("./workflowManager.js").WorkflowManager>(
253
- "WorkflowManager",
254
- )
255
- : undefined,
256
- sessionEnv: this.container.has("ConfigurationService")
257
- ? this.container
258
- .get<
259
- import("../services/configurationService.js").ConfigurationService
260
- >("ConfigurationService")
261
- ?.getMergedEnv?.()
262
- : undefined,
263
- sessionId: context.sessionId,
264
- toolCallId: context.toolCallId,
265
- };
266
-
267
- // OpenTelemetry: start tool span
268
- startToolSpan(name, args);
269
- const toolStartTime = Date.now();
270
-
271
- logger?.debug("Executing tool with enhanced context", {
272
- toolName: name,
273
- permissionMode,
274
- effectivePermissionMode,
275
- hasPermissionManager: !!permissionManager,
276
- });
277
-
278
- // Check if it's an MCP tool first
279
- if (this.mcpManager.isMcpTool(name)) {
280
- try {
281
- const result = await this.mcpManager.executeMcpToolByRegistry(
282
- name,
283
- args,
284
- enhancedContext,
285
- );
286
- endToolSpan({
287
- success: result.success,
288
- durationMs: Date.now() - toolStartTime,
289
- output: result.content,
290
- });
291
- return result;
292
- } catch (error) {
293
- endToolSpan({
294
- success: false,
295
- error: error instanceof Error ? error.message : String(error),
296
- durationMs: Date.now() - toolStartTime,
297
- });
298
- return {
299
- success: false,
300
- content: "",
301
- error: error instanceof Error ? error.message : String(error),
302
- };
303
- }
304
- }
305
-
306
- // Check built-in tools
307
- const plugin = this.toolsRegistry.get(name);
308
- if (plugin) {
309
- try {
310
- const result = await plugin.execute(args, enhancedContext);
311
- endToolSpan({
312
- success: result.success,
313
- durationMs: Date.now() - toolStartTime,
314
- output: result.content,
315
- });
316
- return result;
317
- } catch (error) {
318
- logger?.error("Tool execution failed", {
319
- toolName: name,
320
- error: error instanceof Error ? error.message : String(error),
321
- });
322
- endToolSpan({
323
- success: false,
324
- error: error instanceof Error ? error.message : String(error),
325
- durationMs: Date.now() - toolStartTime,
326
- });
327
- return {
328
- success: false,
329
- content: "",
330
- error: error instanceof Error ? error.message : String(error),
331
- };
332
- }
333
- }
334
-
335
- logger?.warn("Tool not found", { toolName: name });
336
- endToolSpan({
337
- success: false,
338
- error: `Tool '${name}' not found`,
339
- durationMs: Date.now() - toolStartTime,
340
- });
341
- return {
342
- success: false,
343
- content: "",
344
- error: `Tool '${name}' not found`,
345
- };
346
- }
347
-
348
- list(): ToolPlugin[] {
349
- const permissionManager =
350
- this.container.get<PermissionManager>("PermissionManager");
351
- const builtInTools = Array.from(this.toolsRegistry.values()).filter(
352
- (tool) => !permissionManager?.isToolDenied(tool.name),
353
- );
354
- const mcpTools = this.mcpManager
355
- .getMcpToolPlugins()
356
- .filter((tool) => !permissionManager?.isToolDenied(tool.name));
357
- return [...builtInTools, ...mcpTools];
358
- }
359
-
360
- getToolsConfig(options?: {
361
- availableSubagents?: SubagentConfiguration[];
362
- availableSkills?: SkillMetadata[];
363
- workdir?: string;
364
- isSubagent?: boolean;
365
- }): ChatCompletionFunctionTool[] {
366
- const permissionManager =
367
- this.container.get<PermissionManager>("PermissionManager");
368
- const builtInToolsConfig = Array.from(this.toolsRegistry.values())
369
- .filter((tool) => {
370
- // If tool is explicitly denied by name in permission rules, filter it out
371
- if (permissionManager?.isToolDenied(tool.name)) {
372
- return false;
373
- }
374
- return true;
375
- })
376
- .map((tool) => {
377
- // Create a copy of the tool config to avoid modifying the original
378
- const config = {
379
- ...tool.config,
380
- function: {
381
- ...tool.config.function,
382
- },
383
- };
384
- // Override description with prompt if available
385
- if (tool.prompt) {
386
- config.function.description = tool.prompt(options);
387
- }
388
- return config;
389
- });
390
- const mcpToolsConfig = this.mcpManager
391
- .getMcpToolsConfig()
392
- .filter((tool) => {
393
- if (permissionManager?.isToolDenied(tool.function.name)) {
394
- return false;
395
- }
396
- return true;
397
- });
398
- return [...builtInToolsConfig, ...mcpToolsConfig];
399
- }
400
-
401
- /**
402
- * Get the list of registered tool plugins
403
- */
404
- public getTools(): ToolPlugin[] {
405
- return Array.from(this.toolsRegistry.values());
406
- }
407
-
408
- /**
409
- * Check whether a tool is safe to execute in parallel with other tools.
410
- * Built-in tools default to safe (parallel); Edit and Write opt out.
411
- * MCP tools are conservatively non-safe (can't inspect side effects).
412
- */
413
- public isConcurrencySafe(name: string): boolean {
414
- // MCP tools are conservatively non-safe
415
- if (this.mcpManager.isMcpTool(name)) {
416
- return false;
417
- }
418
- const plugin = this.toolsRegistry.get(name);
419
- if (plugin) {
420
- return plugin.isConcurrencySafe ?? true;
421
- }
422
- // Unknown tools are conservatively non-safe
423
- return false;
424
- }
425
-
426
- /**
427
- * Get the current permission mode
428
- */
429
- public getPermissionMode(): PermissionMode {
430
- const permissionManager =
431
- this.container.get<PermissionManager>("PermissionManager");
432
- const permissionMode = this.container.has("PermissionMode")
433
- ? this.container.get<PermissionMode>("PermissionMode")
434
- : undefined;
435
-
436
- if (permissionManager) {
437
- return permissionManager.getCurrentEffectiveMode(permissionMode);
438
- }
439
- return permissionMode || "default";
440
- }
441
-
442
- /**
443
- * Set the permission mode
444
- * @param mode - The new permission mode
445
- */
446
- public setPermissionMode(mode: PermissionMode): void {
447
- this.container.register("PermissionMode", mode);
448
- }
449
-
450
- /**
451
- * Request a full permission mode transition (planManager + UI callback).
452
- * Used by tools like EnterPlanMode in bypass mode where the canUseTool
453
- * callback (which normally handles the transition) is not invoked.
454
- * In normal mode, the callback already handles the transition.
455
- */
456
- public requestPermissionModeChange(mode: PermissionMode): void {
457
- if (this.container.has("PermissionModeTransition")) {
458
- const transition = this.container.get<(mode: PermissionMode) => void>(
459
- "PermissionModeTransition",
460
- );
461
- if (transition) {
462
- transition(mode);
463
- return;
464
- }
465
- }
466
- this.setPermissionMode(mode);
467
- }
468
-
469
- /**
470
- * Get the permission manager
471
- */
472
- public getPermissionManager(): PermissionManager | undefined {
473
- return this.container.get<PermissionManager>("PermissionManager");
474
- }
475
-
476
- /**
477
- * Get the task manager
478
- */
479
- public getTaskManager():
480
- | import("../services/taskManager.js").TaskManager
481
- | undefined {
482
- return this.container.get<import("../services/taskManager.js").TaskManager>(
483
- "TaskManager",
484
- );
485
- }
486
- }
487
-
488
- // Export tool registry class and types
489
- export { ToolManager };