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,112 +0,0 @@
1
- import path from "node:path";
2
- import fs from "node:fs/promises";
3
- import os from "node:os";
4
- import { generateRandomName } from "../utils/nameGenerator.js";
5
-
6
- import { Container } from "../utils/container.js";
7
- import { MessageManager } from "./messageManager.js";
8
- import { PermissionManager } from "./permissionManager.js";
9
- import type { PermissionMode } from "../types/permissions.js";
10
-
11
- /**
12
- * Manages plan files for plan mode
13
- */
14
- import { logger } from "../utils/globalLogger.js";
15
-
16
- export class PlanManager {
17
- private planDir: string;
18
- private currentPlanFilePath: string | null = null;
19
- private planEntryReminderPending: boolean = false;
20
-
21
- constructor(private container: Container) {
22
- this.planDir = path.join(os.homedir(), ".wave", "plans");
23
- }
24
-
25
- /**
26
- * Ensures the plan directory exists and generates a new plan file path with a random name
27
- */
28
- public async getOrGeneratePlanFilePath(seed?: string): Promise<{
29
- path: string;
30
- name: string;
31
- }> {
32
- try {
33
- await fs.mkdir(this.planDir, { recursive: true });
34
- } catch (error) {
35
- logger?.error(`Failed to create plan directory: ${this.planDir}`, error);
36
- throw error;
37
- }
38
- const name = generateRandomName(seed);
39
- const filePath = path.join(this.planDir, `${name}.md`);
40
-
41
- if (this.currentPlanFilePath !== filePath) {
42
- try {
43
- await fs.unlink(filePath);
44
- } catch (error) {
45
- if (
46
- error instanceof Error &&
47
- (error as Error & { code?: string }).code !== "ENOENT"
48
- ) {
49
- logger?.error(
50
- `Failed to remove existing plan file: ${filePath}`,
51
- error,
52
- );
53
- }
54
- }
55
- this.currentPlanFilePath = filePath;
56
- }
57
-
58
- logger?.info(`Generated plan file path: ${filePath}`);
59
- return { path: filePath, name };
60
- }
61
-
62
- /**
63
- * Returns the directory where plan files are stored
64
- */
65
- public getPlanDir(): string {
66
- return this.planDir;
67
- }
68
-
69
- /**
70
- * Handle plan mode transition, generating or clearing plan file path
71
- * @param mode - The current effective permission mode
72
- */
73
- public handlePlanModeTransition(mode: PermissionMode): void {
74
- const permissionManager =
75
- this.container.get<PermissionManager>("PermissionManager");
76
- const messageManager = this.container.get<MessageManager>("MessageManager");
77
-
78
- const previousMode = this.container.get<PermissionMode>("PermissionMode");
79
-
80
- if (mode === "plan") {
81
- // Entering plan mode: clear any pending exit attachment
82
- // (prevents sending both plan_mode and plan_mode_exit on rapid toggle)
83
- permissionManager?.setNeedsPlanModeExitAttachment(false);
84
- this.planEntryReminderPending = true;
85
-
86
- this.getOrGeneratePlanFilePath(messageManager?.getRootSessionId())
87
- .then(({ path }) => {
88
- logger?.debug("Plan file path generated", { path });
89
- permissionManager?.setPlanFilePath(path);
90
- })
91
- .catch((error) => {
92
- logger?.error("Failed to generate plan file path", error);
93
- });
94
- } else if (previousMode === "plan") {
95
- // Leaving plan mode: set flags for exit notification and re-entry detection
96
- permissionManager?.setHasExitedPlanMode(true);
97
- permissionManager?.setNeedsPlanModeExitAttachment(true);
98
- permissionManager?.setPlanFilePath(undefined);
99
- this.planEntryReminderPending = false;
100
- } else {
101
- permissionManager?.setPlanFilePath(undefined);
102
- }
103
- }
104
-
105
- public isPlanEntryReminderPending(): boolean {
106
- return this.planEntryReminderPending;
107
- }
108
-
109
- public consumePlanEntryReminder(): void {
110
- this.planEntryReminderPending = false;
111
- }
112
- }
@@ -1,330 +0,0 @@
1
- import { logger } from "../utils/globalLogger.js";
2
- import { Plugin, PluginConfig } from "../types/index.js";
3
- import { PluginLoader } from "../services/pluginLoader.js";
4
- import * as path from "path";
5
- import { existsSync, readdirSync } from "fs";
6
- import { getBuiltinPluginsDir } from "../utils/configPaths.js";
7
- import { SkillManager } from "./skillManager.js";
8
- import { HookManager } from "./hookManager.js";
9
- import { LspManager } from "./lspManager.js";
10
- import { McpManager } from "./mcpManager.js";
11
- import { SlashCommandManager } from "./slashCommandManager.js";
12
- import { SubagentManager } from "./subagentManager.js";
13
- import { MarketplaceService } from "../services/MarketplaceService.js";
14
- import { ConfigurationService } from "../services/configurationService.js";
15
- import { Container } from "../utils/container.js";
16
-
17
- export interface PluginManagerOptions {
18
- workdir: string;
19
- enabledPlugins?: Record<string, boolean>;
20
- }
21
-
22
- export class PluginManager {
23
- private plugins = new Map<string, Plugin>();
24
- private workdir: string;
25
- private enabledPlugins: Record<string, boolean>;
26
-
27
- constructor(
28
- private container: Container,
29
- options: PluginManagerOptions,
30
- ) {
31
- this.workdir = options.workdir;
32
- this.enabledPlugins = options.enabledPlugins || {};
33
- }
34
-
35
- private get skillManager(): SkillManager | undefined {
36
- return this.container.get<SkillManager>("SkillManager");
37
- }
38
-
39
- private get hookManager(): HookManager | undefined {
40
- return this.container.get<HookManager>("HookManager");
41
- }
42
-
43
- private get lspManager(): LspManager | undefined {
44
- return this.container.get<LspManager>("LspManager");
45
- }
46
-
47
- private get mcpManager(): McpManager | undefined {
48
- return this.container.get<McpManager>("McpManager");
49
- }
50
-
51
- private get slashCommandManager(): SlashCommandManager | undefined {
52
- return this.container.get<SlashCommandManager>("SlashCommandManager");
53
- }
54
-
55
- private get configurationService(): ConfigurationService | undefined {
56
- return this.container.get<ConfigurationService>("ConfigurationService");
57
- }
58
-
59
- private get subagentManager(): SubagentManager | undefined {
60
- return this.container.get<SubagentManager>("SubagentManager");
61
- }
62
-
63
- /**
64
- * Update enabled plugins configuration
65
- */
66
- updateEnabledPlugins(enabledPlugins: Record<string, boolean>): void {
67
- this.enabledPlugins = enabledPlugins;
68
- }
69
-
70
- /**
71
- * Load plugins installed via marketplace
72
- */
73
- private async loadInstalledPlugins(): Promise<void> {
74
- try {
75
- // If configurationService is provided, use it to get the latest merged enabled plugins
76
- if (this.configurationService) {
77
- this.enabledPlugins = this.configurationService.getMergedEnabledPlugins(
78
- this.workdir,
79
- );
80
- }
81
-
82
- const marketplaceService = new MarketplaceService(
83
- this.workdir,
84
- this.configurationService,
85
- );
86
-
87
- // Trigger auto-update for marketplaces in the background
88
- if (!process.env.VITEST) {
89
- marketplaceService.autoUpdateAll().catch((error) => {
90
- logger?.error("Background marketplace auto-update failed:", error);
91
- });
92
- }
93
-
94
- let installedRegistry = await marketplaceService.getInstalledPlugins();
95
- const knownMarketplaces = await marketplaceService.listMarketplaces();
96
-
97
- // Identify missing enabled plugins and auto-install them if marketplace is known
98
- for (const pluginId of Object.keys(this.enabledPlugins)) {
99
- if (this.enabledPlugins[pluginId] !== true) continue;
100
-
101
- const [name, marketplaceName] = pluginId.split("@");
102
- if (!name || !marketplaceName) continue;
103
- // `@builtin` entries are loaded by loadBuiltinPlugins, not the marketplace.
104
- if (marketplaceName === "builtin") continue;
105
-
106
- const isInstalled = installedRegistry.plugins.some(
107
- (p) => p.name === name && p.marketplace === marketplaceName,
108
- );
109
-
110
- if (!isInstalled) {
111
- const isMarketplaceKnown = knownMarketplaces.some(
112
- (m) => m.name === marketplaceName,
113
- );
114
-
115
- if (isMarketplaceKnown) {
116
- // Pre-check: verify the plugin still exists in the marketplace manifest
117
- // before acquiring the lock in installPlugin (which can block ~8s during autoUpdate)
118
- const marketplace = knownMarketplaces.find(
119
- (m) => m.name === marketplaceName,
120
- );
121
- if (!marketplace) continue;
122
- try {
123
- const marketplacePath = marketplaceService.getMarketplacePath(
124
- marketplace.source,
125
- );
126
- const manifest =
127
- await marketplaceService.loadMarketplaceManifest(
128
- marketplacePath,
129
- );
130
- const pluginExists = manifest.plugins.some(
131
- (p) => p.name === name,
132
- );
133
- if (!pluginExists) {
134
- logger?.warn(
135
- `Plugin ${pluginId} is enabled but no longer exists in marketplace ${marketplaceName}. Removing from enabledPlugins.`,
136
- );
137
- await this.configurationService?.removeEnabledPlugin(
138
- this.workdir,
139
- "user",
140
- pluginId,
141
- );
142
- continue;
143
- }
144
- } catch {
145
- // Manifest read failed — marketplace may not be cloned yet, try to clone/update it
146
- try {
147
- await marketplaceService.updateMarketplace(marketplaceName);
148
- } catch (updateError) {
149
- logger?.warn(
150
- `Failed to clone/update marketplace ${marketplaceName}: ${updateError instanceof Error ? updateError.message : String(updateError)}`,
151
- );
152
- }
153
- }
154
-
155
- logger?.info(`Auto-installing missing plugin: ${pluginId}`);
156
- try {
157
- await marketplaceService.installPlugin(pluginId);
158
- } catch (installError) {
159
- if (
160
- installError instanceof Error &&
161
- installError.message.includes("not found in marketplace")
162
- ) {
163
- logger?.warn(
164
- `Plugin ${pluginId} no longer found in marketplace. Removing from enabledPlugins.`,
165
- );
166
- await this.configurationService?.removeEnabledPlugin(
167
- this.workdir,
168
- "user",
169
- pluginId,
170
- );
171
- } else {
172
- logger?.error(
173
- `Failed to auto-install plugin ${pluginId}:`,
174
- installError,
175
- );
176
- }
177
- }
178
- } else {
179
- logger?.warn(
180
- `Plugin ${pluginId} is enabled but marketplace ${marketplaceName} is unknown. Skipping auto-install.`,
181
- );
182
- }
183
- }
184
- }
185
-
186
- // Refresh registry after potential auto-installs
187
- installedRegistry = await marketplaceService.getInstalledPlugins();
188
-
189
- for (const p of installedRegistry.plugins) {
190
- const pluginId = `${p.name}@${p.marketplace}`;
191
- if (this.enabledPlugins[pluginId] !== true) {
192
- logger?.debug(`Plugin ${pluginId} is not enabled via configuration`);
193
- continue;
194
- }
195
- await this.loadSinglePlugin(p.cachePath);
196
- }
197
- } catch (error) {
198
- logger?.error("Failed to load installed plugins:", error);
199
- }
200
- }
201
-
202
- /**
203
- * Load a single plugin from an absolute path
204
- */
205
- private async loadSinglePlugin(absolutePath: string): Promise<void> {
206
- try {
207
- const manifest = await PluginLoader.loadManifest(absolutePath);
208
-
209
- if (this.plugins.has(manifest.name)) {
210
- // If already loaded (e.g. via explicit config), skip
211
- logger?.warn(`Plugin with name '${manifest.name}' is already loaded`);
212
- return;
213
- }
214
-
215
- const plugin: Plugin = {
216
- ...manifest,
217
- path: absolutePath,
218
- commands: PluginLoader.loadCommands(absolutePath),
219
- skills: await PluginLoader.loadSkills(absolutePath),
220
- agents: await PluginLoader.loadAgents(absolutePath),
221
- lspConfig: await PluginLoader.loadLspConfig(absolutePath),
222
- mcpConfig: await PluginLoader.loadMcpConfig(absolutePath),
223
- hooksConfig: await PluginLoader.loadHooksConfig(absolutePath),
224
- };
225
-
226
- // Register components with managers
227
- if (this.slashCommandManager && plugin.commands.length > 0) {
228
- this.slashCommandManager.registerPluginCommands(
229
- plugin.name,
230
- plugin.commands,
231
- );
232
- }
233
-
234
- if (this.skillManager && plugin.skills.length > 0) {
235
- this.skillManager.registerPluginSkills(plugin.name, plugin.skills);
236
- }
237
-
238
- if (this.lspManager && plugin.lspConfig) {
239
- for (const [language, config] of Object.entries(plugin.lspConfig)) {
240
- const configWithPluginRoot = { ...config, pluginRoot: plugin.path };
241
- this.lspManager.registerServer(language, configWithPluginRoot);
242
- }
243
- }
244
-
245
- if (this.mcpManager && plugin.mcpConfig) {
246
- for (const [name, config] of Object.entries(
247
- plugin.mcpConfig.mcpServers,
248
- )) {
249
- const configWithPluginRoot = { ...config, pluginRoot: plugin.path };
250
- this.mcpManager.addServer(name, configWithPluginRoot);
251
- }
252
- }
253
-
254
- if (this.hookManager && plugin.hooksConfig) {
255
- this.hookManager.registerPluginHooks(plugin.path, plugin.hooksConfig);
256
- }
257
-
258
- if (this.subagentManager && plugin.agents.length > 0) {
259
- this.subagentManager.registerPluginAgents(plugin.name, plugin.agents);
260
- }
261
-
262
- this.plugins.set(manifest.name, plugin);
263
- logger?.debug(`Loaded plugin: ${manifest.name} v${manifest.version}`);
264
- } catch (error) {
265
- logger?.error(`Failed to load plugin from ${absolutePath}`, error);
266
- }
267
- }
268
-
269
- /**
270
- * Load plugins from configuration
271
- * @param configs Array of plugin configurations
272
- */
273
- async loadPlugins(configs: PluginConfig[]): Promise<void> {
274
- // Load plugins from configuration (e.g. --plugin-dir) first to give them higher priority
275
- for (const config of configs) {
276
- if (config.type !== "local") {
277
- logger?.warn(`Unsupported plugin type: ${config.type}`);
278
- continue;
279
- }
280
-
281
- const absolutePath = path.isAbsolute(config.path)
282
- ? config.path
283
- : path.resolve(this.workdir, config.path);
284
-
285
- await this.loadSinglePlugin(absolutePath);
286
- }
287
-
288
- // Load installed plugins from marketplace
289
- await this.loadInstalledPlugins();
290
-
291
- // Load built-in plugins bundled with the SDK (lowest priority)
292
- await this.loadBuiltinPlugins();
293
- }
294
-
295
- /**
296
- * Load built-in plugins bundled with the SDK (e.g. sdd).
297
- * Opt-in via `enabledPlugins`, keyed `<name>@builtin` (default off, consistent
298
- * with marketplace plugins). Lowest priority: explicit config and marketplace
299
- * plugins win on name conflicts (loadSinglePlugin skips duplicates).
300
- */
301
- private async loadBuiltinPlugins(): Promise<void> {
302
- try {
303
- const builtinDir = getBuiltinPluginsDir();
304
- if (!existsSync(builtinDir)) return;
305
-
306
- // The builtin plugin directory name is the plugin name by convention.
307
- for (const entry of readdirSync(builtinDir, { withFileTypes: true })) {
308
- if (!entry.isDirectory()) continue;
309
- if (this.enabledPlugins[`${entry.name}@builtin`] !== true) continue;
310
- await this.loadSinglePlugin(path.join(builtinDir, entry.name));
311
- }
312
- } catch (error) {
313
- logger?.error("Failed to load built-in plugins:", error);
314
- }
315
- }
316
-
317
- /**
318
- * Get all loaded plugins
319
- */
320
- getPlugins(): Plugin[] {
321
- return Array.from(this.plugins.values());
322
- }
323
-
324
- /**
325
- * Get a plugin by name
326
- */
327
- getPlugin(name: string): Plugin | undefined {
328
- return this.plugins.get(name);
329
- }
330
- }
@@ -1,124 +0,0 @@
1
- import { ConfigurationService } from "../services/configurationService.js";
2
- import { PluginManager } from "./pluginManager.js";
3
- import { Logger } from "../types/index.js";
4
- import { Scope } from "../types/configuration.js";
5
-
6
- export interface PluginScopeManagerOptions {
7
- workdir: string;
8
- configurationService: ConfigurationService;
9
- pluginManager: PluginManager;
10
- logger?: Logger;
11
- }
12
-
13
- export class PluginScopeManager {
14
- private workdir: string;
15
- private configurationService: ConfigurationService;
16
- private pluginManager: PluginManager;
17
- private logger?: Logger;
18
-
19
- constructor(options: PluginScopeManagerOptions) {
20
- this.workdir = options.workdir;
21
- this.configurationService = options.configurationService;
22
- this.pluginManager = options.pluginManager;
23
- this.logger = options.logger;
24
- }
25
-
26
- /**
27
- * Enable a plugin in the specified scope
28
- */
29
- async enablePlugin(scope: Scope, pluginId: string): Promise<void> {
30
- await this.configurationService.updateEnabledPlugin(
31
- this.workdir,
32
- scope,
33
- pluginId,
34
- true,
35
- );
36
- this.logger?.info(`Enabled plugin ${pluginId} in ${scope} scope`);
37
- this.refreshPluginManager();
38
- }
39
-
40
- /**
41
- * Disable a plugin in the specified scope
42
- */
43
- async disablePlugin(scope: Scope, pluginId: string): Promise<void> {
44
- await this.configurationService.updateEnabledPlugin(
45
- this.workdir,
46
- scope,
47
- pluginId,
48
- false,
49
- );
50
- this.logger?.info(`Disabled plugin ${pluginId} in ${scope} scope`);
51
- this.refreshPluginManager();
52
- }
53
-
54
- /**
55
- * Get the merged enabled state of all plugins
56
- */
57
- getMergedEnabledPlugins(): Record<string, boolean> {
58
- return this.configurationService.getMergedEnabledPlugins(this.workdir);
59
- }
60
-
61
- /**
62
- * Find the scope where a plugin is currently enabled/disabled.
63
- * Priority: local > project > user
64
- */
65
- findPluginScope(pluginId: string): Scope | null {
66
- const projectPaths = this.configurationService.getConfigurationPaths(
67
- this.workdir,
68
- ).projectPaths; // [local, json]
69
- const userPaths = this.configurationService.getConfigurationPaths(
70
- this.workdir,
71
- ).userPaths; // [local, json]
72
-
73
- const checkPaths: { path: string; scope: Scope }[] = [
74
- { path: projectPaths[0], scope: "local" },
75
- { path: projectPaths[1], scope: "project" },
76
- { path: userPaths[0], scope: "user" }, // user local is still user scope
77
- { path: userPaths[1], scope: "user" },
78
- ];
79
-
80
- for (const { path, scope } of checkPaths) {
81
- const config = this.configurationService.loadWaveConfigFromFile(path);
82
- if (config?.enabledPlugins && pluginId in config.enabledPlugins) {
83
- return scope;
84
- }
85
- }
86
-
87
- return null;
88
- }
89
-
90
- /**
91
- * Remove a plugin from all scopes (user, project, local)
92
- * This is useful when uninstalling a plugin to clean up all configuration
93
- */
94
- async removePluginFromAllScopes(pluginId: string): Promise<void> {
95
- const scopes: Scope[] = ["user", "project", "local"];
96
-
97
- for (const scope of scopes) {
98
- try {
99
- await this.configurationService.removeEnabledPlugin(
100
- this.workdir,
101
- scope,
102
- pluginId,
103
- );
104
- } catch (error) {
105
- // Continue removing from other scopes even if one fails
106
- this.logger?.warn(
107
- `Failed to remove plugin ${pluginId} from ${scope} scope: ${error instanceof Error ? error.message : String(error)}`,
108
- );
109
- }
110
- }
111
-
112
- this.refreshPluginManager();
113
- }
114
-
115
- /**
116
- * Refresh the plugin manager with the latest configuration
117
- * Note: This only updates the configuration, it doesn't reload plugins.
118
- * Reloading plugins might require a more complex logic (unloading/loading).
119
- */
120
- private refreshPluginManager(): void {
121
- const enabledPlugins = this.getMergedEnabledPlugins();
122
- this.pluginManager.updateEnabledPlugins(enabledPlugins);
123
- }
124
- }