wave-agent-sdk 0.6.5 → 0.7.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 (174) hide show
  1. package/dist/agent.d.ts +8 -0
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +49 -240
  4. package/dist/constants/tools.d.ts +0 -2
  5. package/dist/constants/tools.d.ts.map +1 -1
  6. package/dist/constants/tools.js +0 -2
  7. package/dist/core/plugin.d.ts +86 -0
  8. package/dist/core/plugin.d.ts.map +1 -0
  9. package/dist/core/plugin.js +164 -0
  10. package/dist/index.d.ts +1 -4
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +1 -5
  13. package/dist/managers/MemoryRuleManager.d.ts +3 -1
  14. package/dist/managers/MemoryRuleManager.d.ts.map +1 -1
  15. package/dist/managers/MemoryRuleManager.js +2 -1
  16. package/dist/managers/aiManager.d.ts +13 -23
  17. package/dist/managers/aiManager.d.ts.map +1 -1
  18. package/dist/managers/aiManager.js +59 -32
  19. package/dist/managers/backgroundTaskManager.d.ts +3 -1
  20. package/dist/managers/backgroundTaskManager.d.ts.map +1 -1
  21. package/dist/managers/backgroundTaskManager.js +2 -1
  22. package/dist/managers/bashManager.d.ts +4 -4
  23. package/dist/managers/bashManager.d.ts.map +1 -1
  24. package/dist/managers/bashManager.js +5 -2
  25. package/dist/managers/foregroundTaskManager.d.ts +3 -0
  26. package/dist/managers/foregroundTaskManager.d.ts.map +1 -1
  27. package/dist/managers/foregroundTaskManager.js +2 -1
  28. package/dist/managers/hookManager.d.ts +3 -3
  29. package/dist/managers/hookManager.d.ts.map +1 -1
  30. package/dist/managers/hookManager.js +20 -19
  31. package/dist/managers/liveConfigManager.d.ts +6 -13
  32. package/dist/managers/liveConfigManager.d.ts.map +1 -1
  33. package/dist/managers/liveConfigManager.js +50 -45
  34. package/dist/managers/lspManager.d.ts +4 -5
  35. package/dist/managers/lspManager.d.ts.map +1 -1
  36. package/dist/managers/lspManager.js +13 -12
  37. package/dist/managers/mcpManager.d.ts +3 -2
  38. package/dist/managers/mcpManager.d.ts.map +1 -1
  39. package/dist/managers/mcpManager.js +16 -15
  40. package/dist/managers/messageManager.d.ts +5 -7
  41. package/dist/managers/messageManager.d.ts.map +1 -1
  42. package/dist/managers/messageManager.js +12 -7
  43. package/dist/managers/permissionManager.d.ts +6 -4
  44. package/dist/managers/permissionManager.d.ts.map +1 -1
  45. package/dist/managers/permissionManager.js +39 -63
  46. package/dist/managers/planManager.d.ts +4 -6
  47. package/dist/managers/planManager.d.ts.map +1 -1
  48. package/dist/managers/planManager.js +18 -4
  49. package/dist/managers/pluginManager.d.ts +10 -22
  50. package/dist/managers/pluginManager.d.ts.map +1 -1
  51. package/dist/managers/pluginManager.js +27 -14
  52. package/dist/managers/reversionManager.d.ts +4 -3
  53. package/dist/managers/reversionManager.d.ts.map +1 -1
  54. package/dist/managers/reversionManager.js +5 -2
  55. package/dist/managers/skillManager.d.ts +3 -2
  56. package/dist/managers/skillManager.d.ts.map +1 -1
  57. package/dist/managers/skillManager.js +15 -14
  58. package/dist/managers/slashCommandManager.d.ts +9 -16
  59. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  60. package/dist/managers/slashCommandManager.js +21 -10
  61. package/dist/managers/subagentManager.d.ts +7 -17
  62. package/dist/managers/subagentManager.d.ts.map +1 -1
  63. package/dist/managers/subagentManager.js +41 -34
  64. package/dist/managers/toolManager.d.ts +15 -38
  65. package/dist/managers/toolManager.d.ts.map +1 -1
  66. package/dist/managers/toolManager.js +66 -56
  67. package/dist/prompts/index.d.ts +6 -2
  68. package/dist/prompts/index.d.ts.map +1 -1
  69. package/dist/prompts/index.js +8 -4
  70. package/dist/services/MarketplaceService.d.ts.map +1 -1
  71. package/dist/services/MarketplaceService.js +13 -0
  72. package/dist/services/aiService.d.ts +4 -0
  73. package/dist/services/aiService.d.ts.map +1 -1
  74. package/dist/services/aiService.js +47 -7
  75. package/dist/services/configurationService.d.ts.map +1 -1
  76. package/dist/services/configurationService.js +30 -11
  77. package/dist/services/taskManager.d.ts +3 -1
  78. package/dist/services/taskManager.d.ts.map +1 -1
  79. package/dist/services/taskManager.js +2 -1
  80. package/dist/tools/bashTool.js +2 -2
  81. package/dist/tools/editTool.d.ts.map +1 -1
  82. package/dist/tools/editTool.js +9 -1
  83. package/dist/tools/readTool.d.ts.map +1 -1
  84. package/dist/tools/readTool.js +2 -2
  85. package/dist/tools/skillTool.d.ts +2 -4
  86. package/dist/tools/skillTool.d.ts.map +1 -1
  87. package/dist/tools/skillTool.js +61 -61
  88. package/dist/tools/taskOutputTool.js +1 -1
  89. package/dist/tools/taskTool.d.ts +2 -4
  90. package/dist/tools/taskTool.d.ts.map +1 -1
  91. package/dist/tools/taskTool.js +192 -187
  92. package/dist/tools/types.d.ts +11 -1
  93. package/dist/tools/types.d.ts.map +1 -1
  94. package/dist/tools/writeTool.d.ts.map +1 -1
  95. package/dist/tools/writeTool.js +4 -2
  96. package/dist/types/marketplace.d.ts +8 -0
  97. package/dist/types/marketplace.d.ts.map +1 -1
  98. package/dist/types/permissions.d.ts +1 -1
  99. package/dist/types/permissions.d.ts.map +1 -1
  100. package/dist/types/permissions.js +1 -3
  101. package/dist/types/skills.d.ts +0 -2
  102. package/dist/types/skills.d.ts.map +1 -1
  103. package/dist/types/tools.d.ts +0 -15
  104. package/dist/types/tools.d.ts.map +1 -1
  105. package/dist/utils/container.d.ts +31 -0
  106. package/dist/utils/container.d.ts.map +1 -0
  107. package/dist/utils/container.js +79 -0
  108. package/dist/utils/containerSetup.d.ts +26 -0
  109. package/dist/utils/containerSetup.d.ts.map +1 -0
  110. package/dist/utils/containerSetup.js +165 -0
  111. package/dist/utils/editUtils.d.ts +0 -3
  112. package/dist/utils/editUtils.d.ts.map +1 -1
  113. package/dist/utils/editUtils.js +4 -3
  114. package/dist/utils/hookMatcher.d.ts +1 -1
  115. package/dist/utils/hookMatcher.d.ts.map +1 -1
  116. package/dist/utils/hookMatcher.js +2 -2
  117. package/dist/utils/openaiClient.js +2 -2
  118. package/dist/utils/stringUtils.d.ts +6 -0
  119. package/dist/utils/stringUtils.d.ts.map +1 -1
  120. package/dist/utils/stringUtils.js +8 -0
  121. package/package.json +1 -1
  122. package/src/agent.ts +60 -282
  123. package/src/constants/tools.ts +0 -2
  124. package/src/core/plugin.ts +224 -0
  125. package/src/index.ts +1 -6
  126. package/src/managers/MemoryRuleManager.ts +6 -1
  127. package/src/managers/aiManager.ts +83 -58
  128. package/src/managers/backgroundTaskManager.ts +5 -1
  129. package/src/managers/bashManager.ts +9 -4
  130. package/src/managers/foregroundTaskManager.ts +3 -0
  131. package/src/managers/hookManager.ts +21 -23
  132. package/src/managers/liveConfigManager.ts +57 -53
  133. package/src/managers/lspManager.ts +14 -19
  134. package/src/managers/mcpManager.ts +20 -20
  135. package/src/managers/messageManager.ts +19 -12
  136. package/src/managers/permissionManager.ts +45 -70
  137. package/src/managers/planManager.ts +26 -7
  138. package/src/managers/pluginManager.ts +37 -33
  139. package/src/managers/reversionManager.ts +5 -3
  140. package/src/managers/skillManager.ts +19 -20
  141. package/src/managers/slashCommandManager.ts +30 -25
  142. package/src/managers/subagentManager.ts +53 -53
  143. package/src/managers/toolManager.ts +91 -90
  144. package/src/prompts/index.ts +13 -5
  145. package/src/services/MarketplaceService.ts +13 -0
  146. package/src/services/aiService.ts +61 -15
  147. package/src/services/configurationService.ts +34 -13
  148. package/src/services/taskManager.ts +5 -1
  149. package/src/tools/bashTool.ts +2 -2
  150. package/src/tools/editTool.ts +9 -1
  151. package/src/tools/readTool.ts +2 -2
  152. package/src/tools/skillTool.ts +75 -71
  153. package/src/tools/taskOutputTool.ts +1 -1
  154. package/src/tools/taskTool.ts +224 -225
  155. package/src/tools/types.ts +12 -1
  156. package/src/tools/writeTool.ts +4 -2
  157. package/src/types/marketplace.ts +9 -0
  158. package/src/types/permissions.ts +0 -4
  159. package/src/types/skills.ts +0 -3
  160. package/src/types/tools.ts +0 -17
  161. package/src/utils/container.ts +92 -0
  162. package/src/utils/containerSetup.ts +256 -0
  163. package/src/utils/editUtils.ts +4 -3
  164. package/src/utils/hookMatcher.ts +2 -2
  165. package/src/utils/openaiClient.ts +2 -2
  166. package/src/utils/stringUtils.ts +9 -0
  167. package/dist/tools/deleteFileTool.d.ts +0 -6
  168. package/dist/tools/deleteFileTool.d.ts.map +0 -1
  169. package/dist/tools/deleteFileTool.js +0 -100
  170. package/dist/tools/multiEditTool.d.ts +0 -6
  171. package/dist/tools/multiEditTool.d.ts.map +0 -1
  172. package/dist/tools/multiEditTool.js +0 -246
  173. package/src/tools/deleteFileTool.ts +0 -127
  174. package/src/tools/multiEditTool.ts +0 -306
@@ -8,6 +8,9 @@ import type {
8
8
  PermissionCallback,
9
9
  } from "../types/permissions.js";
10
10
 
11
+ import type { SubagentConfiguration } from "../utils/subagentParser.js";
12
+ import type { SkillMetadata } from "../types/skills.js";
13
+
11
14
  export interface ToolPlugin {
12
15
  name: string;
13
16
  config: ChatCompletionFunctionTool;
@@ -22,7 +25,11 @@ export interface ToolPlugin {
22
25
  /**
23
26
  * Optional function to provide a prompt to be added to the system prompt
24
27
  */
25
- prompt?: () => string;
28
+ prompt?: (args?: {
29
+ availableSubagents?: SubagentConfiguration[];
30
+ availableSkills?: SkillMetadata[];
31
+ workdir?: string;
32
+ }) => string;
26
33
  }
27
34
 
28
35
  export interface ToolResult {
@@ -65,6 +72,10 @@ export interface ToolContext {
65
72
  foregroundTaskManager?: import("../types/processes.js").IForegroundTaskManager;
66
73
  /** Task manager instance for task management */
67
74
  taskManager: import("../services/taskManager.js").TaskManager;
75
+ /** Subagent manager instance for task delegation */
76
+ subagentManager?: import("../managers/subagentManager.js").SubagentManager;
77
+ /** Skill manager instance for skill invocation */
78
+ skillManager?: import("../managers/skillManager.js").SkillManager;
68
79
  /** Current session ID */
69
80
  sessionId?: string;
70
81
  /** Callback to update the short result of the current tool block */
@@ -3,6 +3,7 @@ import { dirname } from "path";
3
3
  import { logger } from "../utils/globalLogger.js";
4
4
  import type { ToolPlugin, ToolResult, ToolContext } from "./types.js";
5
5
  import { resolvePath, getDisplayPath } from "../utils/path.js";
6
+ import { READ_TOOL_NAME } from "../constants/tools.js";
6
7
 
7
8
  /**
8
9
  * File Write Tool Plugin
@@ -32,10 +33,11 @@ export const writeTool: ToolPlugin = {
32
33
  },
33
34
  },
34
35
  },
35
- prompt: () => `
36
+ prompt: () => `Writes a file to the local filesystem.
37
+
36
38
  Usage:
37
39
  - This tool will overwrite the existing file if there is one at the provided path.
38
- - If this is an existing file, you MUST use the Read tool first to read the file's contents. This tool will fail if you did not read the file first.
40
+ - If this is an existing file, you MUST use the \`${READ_TOOL_NAME}\` tool first to read the file's contents. This tool will fail if you did not read the file first.
39
41
  - ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
40
42
  - NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.
41
43
  - Only use emojis if the user explicitly requests it. Avoid writing emojis to files unless asked.
@@ -11,6 +11,15 @@ export interface MarketplacePluginEntry {
11
11
  description: string;
12
12
  }
13
13
 
14
+ export interface MarketplacePluginStatus extends MarketplacePluginEntry {
15
+ marketplace: string;
16
+ installed: boolean;
17
+ version?: string;
18
+ cachePath?: string;
19
+ projectPath?: string;
20
+ scope?: Scope;
21
+ }
22
+
14
23
  export interface MarketplaceManifest {
15
24
  name: string;
16
25
  owner: MarketplaceOwner;
@@ -10,8 +10,6 @@ import {
10
10
  } from "./tools.js";
11
11
  import {
12
12
  EDIT_TOOL_NAME,
13
- MULTI_EDIT_TOOL_NAME,
14
- DELETE_FILE_TOOL_NAME,
15
13
  BASH_TOOL_NAME,
16
14
  WRITE_TOOL_NAME,
17
15
  EXIT_PLAN_MODE_TOOL_NAME,
@@ -61,8 +59,6 @@ export interface ToolPermissionContext {
61
59
  /** List of tools that require permission checks in default mode */
62
60
  export const RESTRICTED_TOOLS = [
63
61
  EDIT_TOOL_NAME,
64
- MULTI_EDIT_TOOL_NAME,
65
- DELETE_FILE_TOOL_NAME,
66
62
  BASH_TOOL_NAME,
67
63
  WRITE_TOOL_NAME,
68
64
  EXIT_PLAN_MODE_TOOL_NAME,
@@ -3,8 +3,6 @@
3
3
  * Dependencies: Core (Logger)
4
4
  */
5
5
 
6
- import type { Logger } from "./core.js";
7
-
8
6
  export interface SkillMetadata {
9
7
  name: string;
10
8
  description: string;
@@ -60,7 +58,6 @@ export interface SkillToolArgs {
60
58
  export interface SkillManagerOptions {
61
59
  personalSkillsPath?: string;
62
60
  scanTimeout?: number;
63
- logger?: Logger;
64
61
  workdir?: string;
65
62
  }
66
63
 
@@ -33,15 +33,6 @@ export interface WriteToolParameters {
33
33
  content: string;
34
34
  }
35
35
 
36
- /**
37
- * Parameters for a single edit operation in the Edit tool
38
- */
39
- export interface EditOperation {
40
- old_string: string;
41
- new_string: string;
42
- replace_all?: boolean;
43
- }
44
-
45
36
  /**
46
37
  * Parameters for the Edit tool
47
38
  */
@@ -51,11 +42,3 @@ export interface EditToolParameters {
51
42
  new_string: string;
52
43
  replace_all?: boolean;
53
44
  }
54
-
55
- /**
56
- * Parameters for the MultiEdit tool
57
- */
58
- export interface MultiEditToolParameters {
59
- file_path: string;
60
- edits: EditOperation[];
61
- }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * A simple Dependency Injection container to manage late-binding dependencies
3
+ * and resolve circular references.
4
+ */
5
+ export class Container {
6
+ private services = new Map<string, unknown>();
7
+ private factories = new Map<string, () => unknown>();
8
+ private parent?: Container;
9
+
10
+ constructor(parent?: Container) {
11
+ this.parent = parent;
12
+ }
13
+
14
+ /**
15
+ * Create a child container that inherits from this container
16
+ */
17
+ createChild(): Container {
18
+ return new Container(this);
19
+ }
20
+
21
+ /**
22
+ * Register a singleton instance
23
+ */
24
+ register<T>(token: string, instance: T): void {
25
+ this.services.set(token, instance);
26
+ }
27
+
28
+ /**
29
+ * Register a factory function for lazy resolution
30
+ */
31
+ provide<T>(token: string, factory: () => T): void {
32
+ this.factories.set(token, factory);
33
+ }
34
+
35
+ /**
36
+ * Resolve a service by token
37
+ */
38
+ get<T>(token: string): T | undefined {
39
+ if (this.services.has(token)) {
40
+ return this.services.get(token) as T;
41
+ }
42
+
43
+ const factory = this.factories.get(token);
44
+ if (factory) {
45
+ const instance = factory() as T;
46
+ this.services.set(token, instance);
47
+ return instance;
48
+ }
49
+
50
+ if (this.parent) {
51
+ return this.parent.get<T>(token);
52
+ }
53
+
54
+ return undefined;
55
+ }
56
+
57
+ /**
58
+ * Check if a service exists
59
+ */
60
+ has(token: string): boolean {
61
+ return (
62
+ this.services.has(token) ||
63
+ this.factories.has(token) ||
64
+ (this.parent ? this.parent.has(token) : false)
65
+ );
66
+ }
67
+ }
68
+
69
+ // Example usage for ToolManager:
70
+ /*
71
+ const container = new Container();
72
+
73
+ // 1. Provide managers lazily
74
+ container.provide('SubagentManager', () => new SubagentManager(...));
75
+ container.provide('SkillManager', () => new SkillManager(...));
76
+
77
+ // 2. ToolManager can now resolve them only when needed (e.g., in execute)
78
+ class ToolManager {
79
+ constructor(private container: Container) {}
80
+
81
+ async execute(name: string, args: any, context: any) {
82
+ const enhancedContext = {
83
+ ...context,
84
+ subagentManager: this.container.has('SubagentManager')
85
+ ? this.container.get('SubagentManager')
86
+ : undefined,
87
+ // ...
88
+ };
89
+ // ...
90
+ }
91
+ }
92
+ */
@@ -0,0 +1,256 @@
1
+ import { Container } from "./container.js";
2
+ import { ForegroundTaskManager } from "../managers/foregroundTaskManager.js";
3
+ import { BackgroundTaskManager } from "../managers/backgroundTaskManager.js";
4
+ import { TaskManager } from "../services/taskManager.js";
5
+ import { MessageManager } from "../managers/messageManager.js";
6
+ import { AIManager } from "../managers/aiManager.js";
7
+ import { ToolManager } from "../managers/toolManager.js";
8
+ import { McpManager } from "../managers/mcpManager.js";
9
+ import { LspManager } from "../managers/lspManager.js";
10
+ import { PermissionManager } from "../managers/permissionManager.js";
11
+ import { PlanManager } from "../managers/planManager.js";
12
+ import { HookManager } from "../managers/hookManager.js";
13
+ import { SkillManager } from "../managers/skillManager.js";
14
+ import { SlashCommandManager } from "../managers/slashCommandManager.js";
15
+ import { PluginManager } from "../managers/pluginManager.js";
16
+ import { BashManager } from "../managers/bashManager.js";
17
+ import { MemoryRuleManager } from "../managers/MemoryRuleManager.js";
18
+ import { ReversionManager } from "../managers/reversionManager.js";
19
+ import { SubagentManager } from "../managers/subagentManager.js";
20
+ import { LiveConfigManager } from "../managers/liveConfigManager.js";
21
+ import { ConfigurationService } from "../services/configurationService.js";
22
+ import { ReversionService } from "../services/reversionService.js";
23
+ import type { AgentOptions } from "../agent.js";
24
+ import type {
25
+ PermissionMode,
26
+ Usage,
27
+ Task,
28
+ BackgroundTask,
29
+ ToolPermissionContext,
30
+ } from "../types/index.js";
31
+ import type { GatewayConfig, ModelConfig } from "../types/config.js";
32
+
33
+ import { logger } from "./globalLogger.js";
34
+
35
+ export interface AgentContainerSetupOptions {
36
+ options: AgentOptions;
37
+ workdir: string;
38
+ configurationService: ConfigurationService;
39
+ systemPrompt?: string;
40
+ stream: boolean;
41
+
42
+ // Callbacks to Agent methods
43
+ onSessionIdChange: (sessionId: string) => void;
44
+ onTasksChange: (tasks: BackgroundTask[]) => void;
45
+ onSessionTasksChange: (tasks: Task[]) => void;
46
+ onPermissionModeChange: (mode: PermissionMode) => void;
47
+ handlePlanModeTransition: (mode: PermissionMode) => void;
48
+ setPermissionMode: (mode: PermissionMode) => void;
49
+ addPermissionRule: (rule: string) => Promise<void>;
50
+ addUsage: (usage: Usage) => void;
51
+
52
+ // Getters
53
+ getGatewayConfig: () => GatewayConfig;
54
+ getModelConfig: () => ModelConfig;
55
+ getMaxInputTokens: () => number;
56
+ getLanguage: () => string | undefined;
57
+ }
58
+
59
+ export function setupAgentContainer(
60
+ setupOptions: AgentContainerSetupOptions,
61
+ ): Container {
62
+ const {
63
+ options,
64
+ workdir,
65
+ configurationService,
66
+ systemPrompt,
67
+ stream,
68
+ onSessionIdChange,
69
+ onTasksChange,
70
+ onSessionTasksChange,
71
+ onPermissionModeChange,
72
+ handlePlanModeTransition,
73
+ setPermissionMode,
74
+ addPermissionRule,
75
+ addUsage,
76
+ getGatewayConfig,
77
+ getModelConfig,
78
+ getMaxInputTokens,
79
+ getLanguage,
80
+ } = setupOptions;
81
+
82
+ const callbacks = options.callbacks || {};
83
+ const container = new Container();
84
+
85
+ const foregroundTaskManager = new ForegroundTaskManager(container);
86
+ container.register("ForegroundTaskManager", foregroundTaskManager);
87
+ container.register("ConfigurationService", configurationService);
88
+
89
+ const memoryRuleManager = new MemoryRuleManager(container, { workdir });
90
+ container.register("MemoryRuleManager", memoryRuleManager);
91
+
92
+ const messageManager = new MessageManager(container, {
93
+ callbacks: {
94
+ ...callbacks,
95
+ onSessionIdChange: (sessionId) => {
96
+ onSessionIdChange(sessionId);
97
+ callbacks.onSessionIdChange?.(sessionId);
98
+ },
99
+ },
100
+ workdir,
101
+ });
102
+ container.register("MessageManager", messageManager);
103
+
104
+ const resolvedTaskListId =
105
+ configurationService.getEnvironmentVars().WAVE_TASK_LIST_ID ||
106
+ process.env.WAVE_TASK_LIST_ID ||
107
+ messageManager.getRootSessionId();
108
+
109
+ const taskManager = new TaskManager(container, resolvedTaskListId);
110
+ container.register("TaskManager", taskManager);
111
+ taskManager.on("tasksChange", async () => {
112
+ const tasks = await taskManager.listTasks();
113
+ onSessionTasksChange(tasks);
114
+ });
115
+
116
+ const backgroundTaskManager = new BackgroundTaskManager(container, {
117
+ callbacks: {
118
+ ...callbacks,
119
+ onTasksChange: (tasks) => {
120
+ onTasksChange(tasks);
121
+ callbacks.onTasksChange?.(tasks);
122
+ },
123
+ },
124
+ workdir,
125
+ });
126
+ container.register("BackgroundTaskManager", backgroundTaskManager);
127
+
128
+ const mcpManager = new McpManager(container, { callbacks });
129
+ container.register("McpManager", mcpManager);
130
+
131
+ const lspManager = options.lspManager || new LspManager(container);
132
+ container.register("LspManager", lspManager);
133
+
134
+ const permissionManager = new PermissionManager(container, { workdir });
135
+ container.register("PermissionManager", permissionManager);
136
+ permissionManager.setOnConfiguredDefaultModeChange((mode) => {
137
+ handlePlanModeTransition(mode);
138
+ onPermissionModeChange(mode);
139
+ });
140
+
141
+ const planManager = new PlanManager(container);
142
+ container.register("PlanManager", planManager);
143
+
144
+ const hookManager = new HookManager(container, workdir);
145
+ container.register("HookManager", hookManager);
146
+
147
+ const skillManager = new SkillManager(container, { workdir });
148
+ container.register("SkillManager", skillManager);
149
+
150
+ container.register(
151
+ "ReversionService",
152
+ new ReversionService(messageManager.getTranscriptPath()),
153
+ );
154
+ const reversionManager = new ReversionManager(container);
155
+ container.register("ReversionManager", reversionManager);
156
+
157
+ const canUseToolWithNotification = options.canUseTool
158
+ ? async (context: ToolPermissionContext) => {
159
+ try {
160
+ const notificationMessage = `Claude needs your permission to use ${context.toolName}`;
161
+ await hookManager.executeHooks("Notification", {
162
+ event: "Notification",
163
+ projectDir: workdir,
164
+ timestamp: new Date(),
165
+ sessionId: messageManager.getSessionId(),
166
+ transcriptPath: messageManager.getTranscriptPath(),
167
+ cwd: workdir,
168
+ message: notificationMessage,
169
+ notificationType: "permission_prompt",
170
+ env: configurationService.getEnvironmentVars(),
171
+ });
172
+ } catch (error) {
173
+ logger.warn("Failed to execute notification hooks", {
174
+ toolName: context.toolName,
175
+ error: error instanceof Error ? error.message : String(error),
176
+ });
177
+ }
178
+
179
+ const decision = await options.canUseTool!(context);
180
+
181
+ if (decision.newPermissionMode) {
182
+ setPermissionMode(decision.newPermissionMode);
183
+ }
184
+
185
+ if (decision.newPermissionRule) {
186
+ await addPermissionRule(decision.newPermissionRule);
187
+ }
188
+
189
+ return decision;
190
+ }
191
+ : undefined;
192
+
193
+ const toolManager = new ToolManager({
194
+ container,
195
+ tools: options.tools,
196
+ });
197
+ container.register("ToolManager", toolManager);
198
+
199
+ container.register("PermissionMode", options.permissionMode);
200
+ container.register("CanUseToolCallback", canUseToolWithNotification);
201
+
202
+ const liveConfigManager = new LiveConfigManager(container, { workdir });
203
+ container.register("LiveConfigManager", liveConfigManager);
204
+
205
+ const subagentManager = new SubagentManager(container, {
206
+ workdir,
207
+ callbacks: {
208
+ onSubagentUserMessageAdded: callbacks.onSubagentUserMessageAdded,
209
+ onSubagentAssistantMessageAdded:
210
+ callbacks.onSubagentAssistantMessageAdded,
211
+ onSubagentAssistantContentUpdated:
212
+ callbacks.onSubagentAssistantContentUpdated,
213
+ onSubagentAssistantReasoningUpdated:
214
+ callbacks.onSubagentAssistantReasoningUpdated,
215
+ onSubagentToolBlockUpdated: callbacks.onSubagentToolBlockUpdated,
216
+ onSubagentMessagesChange: callbacks.onSubagentMessagesChange,
217
+ onSubagentLatestTotalTokensChange:
218
+ callbacks.onSubagentLatestTotalTokensChange,
219
+ },
220
+ getGatewayConfig,
221
+ getModelConfig,
222
+ getMaxInputTokens,
223
+ getLanguage,
224
+ getEnvironmentVars: () => configurationService.getEnvironmentVars(),
225
+ onUsageAdded: (usage: Usage) => addUsage(usage),
226
+ });
227
+ container.register("SubagentManager", subagentManager);
228
+
229
+ const aiManager = new AIManager(container, {
230
+ callbacks: {
231
+ ...callbacks,
232
+ onUsageAdded: (usage: Usage) => addUsage(usage),
233
+ },
234
+ workdir,
235
+ systemPrompt,
236
+ stream,
237
+ getGatewayConfig,
238
+ getModelConfig,
239
+ getMaxInputTokens,
240
+ getLanguage,
241
+ getEnvironmentVars: () => configurationService.getEnvironmentVars(),
242
+ });
243
+ container.register("AIManager", aiManager);
244
+
245
+ const slashCommandManager = new SlashCommandManager(container, { workdir });
246
+ container.register("SlashCommandManager", slashCommandManager);
247
+ slashCommandManager.initialize();
248
+
249
+ const pluginManager = new PluginManager(container, { workdir });
250
+ container.register("PluginManager", pluginManager);
251
+
252
+ const bashManager = new BashManager(container, { workdir });
253
+ container.register("BashManager", bashManager);
254
+
255
+ return container;
256
+ }
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Utility functions for file editing tools
3
3
  */
4
+ import { formatLineNumberPrefix } from "./stringUtils.js";
4
5
 
5
6
  /**
6
7
  * Escape regular expression special characters
@@ -75,10 +76,10 @@ export function analyzeEditMismatch(
75
76
  const expectedLine = searchLines[j];
76
77
 
77
78
  if (actualLine === expectedLine) {
78
- reportLines.push(`${lineNum.toString().padStart(4)} | ${actualLine}`);
79
+ reportLines.push(`${formatLineNumberPrefix(lineNum)}${actualLine}`);
79
80
  } else {
80
- reportLines.push(`${lineNum.toString().padStart(4)} | - ${expectedLine}`);
81
- reportLines.push(`${lineNum.toString().padStart(4)} | + ${actualLine}`);
81
+ reportLines.push(`${formatLineNumberPrefix(lineNum)}- ${expectedLine}`);
82
+ reportLines.push(`${formatLineNumberPrefix(lineNum)}+ ${actualLine}`);
82
83
  }
83
84
  }
84
85
 
@@ -131,8 +131,8 @@ export class HookMatcher {
131
131
  * Get all tool names that would match this pattern from a given list
132
132
  * Useful for testing and validation
133
133
  */
134
- getMatches(pattern: string, toolNames: string[]): string[] {
135
- return toolNames.filter((toolName) => this.matches(pattern, toolName));
134
+ getMatches(pattern: string, tools: string[]): string[] {
135
+ return tools.filter((toolName) => this.matches(pattern, toolName));
136
136
  }
137
137
 
138
138
  /**
@@ -86,8 +86,8 @@ export class OpenAIClient {
86
86
 
87
87
  const fetchFn = (customFetch as typeof fetch) || fetch;
88
88
  let lastError: (Error & { status?: number; body?: unknown }) | undefined;
89
- const maxRetries = 3;
90
- const initialDelay = 1000;
89
+ const maxRetries = 5;
90
+ const initialDelay = 2000;
91
91
 
92
92
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
93
93
  if (attempt > 0) {
@@ -82,3 +82,12 @@ export const stripAnsiColors = (text: string): string => {
82
82
  const ansiEscapeRegex = new RegExp(`${escapeChar}\\[[0-9;]*[a-zA-Z]`, "g");
83
83
  return text.replace(ansiEscapeRegex, "");
84
84
  };
85
+
86
+ /**
87
+ * Format a line number prefix in cat -n style (padStart(6) + tab)
88
+ * @param lineNumber The line number
89
+ * @returns Formatted line number prefix
90
+ */
91
+ export function formatLineNumberPrefix(lineNumber: number): string {
92
+ return `${lineNumber.toString().padStart(6)}\t`;
93
+ }
@@ -1,6 +0,0 @@
1
- import type { ToolPlugin } from "./types.js";
2
- /**
3
- * Delete file tool plugin
4
- */
5
- export declare const deleteFileTool: ToolPlugin;
6
- //# sourceMappingURL=deleteFileTool.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deleteFileTool.d.ts","sourceRoot":"","sources":["../../src/tools/deleteFileTool.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AAItE;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,UAqH5B,CAAC"}
@@ -1,100 +0,0 @@
1
- import { unlink } from "fs/promises";
2
- import { logger } from "../utils/globalLogger.js";
3
- import { resolvePath, getDisplayPath } from "../utils/path.js";
4
- import { DELETE_FILE_TOOL_NAME } from "../constants/tools.js";
5
- /**
6
- * Delete file tool plugin
7
- */
8
- export const deleteFileTool = {
9
- name: DELETE_FILE_TOOL_NAME,
10
- config: {
11
- type: "function",
12
- function: {
13
- name: DELETE_FILE_TOOL_NAME,
14
- description: `Deletes a file at the specified path. The operation will fail gracefully if:
15
- - The file doesn't exist
16
- - The operation is rejected for security reasons
17
- - The file cannot be deleted`,
18
- parameters: {
19
- type: "object",
20
- properties: {
21
- target_file: {
22
- type: "string",
23
- description: "The path of the file to delete, relative to the workspace root.",
24
- },
25
- },
26
- required: ["target_file"],
27
- },
28
- },
29
- },
30
- execute: async (args, context) => {
31
- const targetFile = args.target_file;
32
- if (!targetFile || typeof targetFile !== "string") {
33
- return {
34
- success: false,
35
- content: "",
36
- error: "target_file parameter is required and must be a string",
37
- };
38
- }
39
- try {
40
- const filePath = resolvePath(targetFile, context.workdir);
41
- // Permission check after validation but before real operation
42
- // Permission check after validation but before real operation
43
- if (context.permissionManager) {
44
- try {
45
- const permissionContext = context.permissionManager.createContext(DELETE_FILE_TOOL_NAME, context.permissionMode || "default", context.canUseToolCallback, { target_file: targetFile });
46
- const permissionResult = await context.permissionManager.checkPermission(permissionContext);
47
- if (permissionResult.behavior === "deny") {
48
- return {
49
- success: false,
50
- content: "",
51
- error: `${DELETE_FILE_TOOL_NAME} operation denied, reason: ${permissionResult.message || "No reason provided"}`,
52
- };
53
- }
54
- }
55
- catch {
56
- return {
57
- success: false,
58
- content: "",
59
- error: "Permission check failed",
60
- };
61
- }
62
- }
63
- // Record snapshot for reversion
64
- let snapshotId;
65
- if (context.reversionManager && context.messageId) {
66
- snapshotId = await context.reversionManager.recordSnapshot(context.messageId, filePath, "delete");
67
- }
68
- // Delete file
69
- await unlink(filePath);
70
- // Commit snapshot on success
71
- if (context.reversionManager && snapshotId) {
72
- await context.reversionManager.commitSnapshot(snapshotId);
73
- }
74
- logger.debug(`Successfully deleted file: ${filePath}`);
75
- return {
76
- success: true,
77
- content: `Successfully deleted file: ${targetFile}`,
78
- shortResult: "File deleted",
79
- };
80
- }
81
- catch (error) {
82
- if (error.code === "ENOENT") {
83
- return {
84
- success: false,
85
- content: "",
86
- error: `File does not exist: ${targetFile}`,
87
- };
88
- }
89
- return {
90
- success: false,
91
- content: "",
92
- error: error instanceof Error ? error.message : String(error),
93
- };
94
- }
95
- },
96
- formatCompactParams: (params, context) => {
97
- const targetFile = params.target_file;
98
- return getDisplayPath(targetFile || "", context.workdir);
99
- },
100
- };
@@ -1,6 +0,0 @@
1
- import type { ToolPlugin } from "./types.js";
2
- /**
3
- * Multi-edit tool plugin
4
- */
5
- export declare const multiEditTool: ToolPlugin;
6
- //# sourceMappingURL=multiEditTool.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multiEditTool.d.ts","sourceRoot":"","sources":["../../src/tools/multiEditTool.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AA6BtE;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,UA+Q3B,CAAC"}