wave-agent-sdk 1.0.5 → 1.0.7

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 (202) hide show
  1. package/dist/agent.d.ts +34 -1
  2. package/dist/agent.js +49 -4
  3. package/dist/index.d.ts +3 -1
  4. package/dist/index.js +1 -1
  5. package/dist/managers/aiManager.d.ts +36 -0
  6. package/dist/managers/aiManager.js +240 -11
  7. package/dist/managers/messageManager.d.ts +2 -4
  8. package/dist/managers/messageManager.js +14 -7
  9. package/dist/managers/slashCommandManager.js +28 -0
  10. package/dist/managers/subagentManager.d.ts +0 -2
  11. package/dist/services/aiService.d.ts +2 -3
  12. package/dist/services/aiService.js +4 -18
  13. package/dist/services/configurationService.d.ts +7 -0
  14. package/dist/services/configurationService.js +10 -0
  15. package/dist/telemetry/instrumentation.d.ts +1 -1
  16. package/dist/telemetry/instrumentation.js +57 -28
  17. package/dist/tools/bashTool.js +16 -6
  18. package/dist/tools/grepTool.js +11 -3
  19. package/dist/types/core.d.ts +1 -34
  20. package/dist/types/index.d.ts +4 -0
  21. package/dist/types/messaging.d.ts +2 -0
  22. package/dist/utils/cacheControlUtils.d.ts +5 -27
  23. package/dist/utils/cacheControlUtils.js +12 -73
  24. package/dist/utils/containerSetup.js +0 -3
  25. package/dist/utils/messageOperations.d.ts +2 -1
  26. package/dist/utils/messageOperations.js +2 -1
  27. package/dist/utils/notificationXml.js +5 -0
  28. package/dist/utils/ripgrep.d.ts +4 -4
  29. package/dist/utils/ripgrep.js +4 -27
  30. package/package.json +20 -8
  31. package/bin/rg +0 -79
  32. package/dist/managers/forkedAgentManager.d.ts +0 -50
  33. package/dist/managers/forkedAgentManager.js +0 -130
  34. package/scripts/install_ripgrep.js +0 -111
  35. package/scripts/postinstall.js +0 -38
  36. package/src/agent.ts +0 -1271
  37. package/src/constants/subagents.ts +0 -4
  38. package/src/constants/toolLimits.ts +0 -15
  39. package/src/constants/tools.ts +0 -24
  40. package/src/core/plugin.ts +0 -237
  41. package/src/core/session.ts +0 -9
  42. package/src/index.ts +0 -38
  43. package/src/managers/MemoryRuleManager.ts +0 -198
  44. package/src/managers/aiManager.ts +0 -2429
  45. package/src/managers/backgroundTaskManager.ts +0 -480
  46. package/src/managers/bangManager.ts +0 -119
  47. package/src/managers/cronManager.ts +0 -401
  48. package/src/managers/foregroundTaskManager.ts +0 -30
  49. package/src/managers/forkedAgentManager.ts +0 -216
  50. package/src/managers/hookManager.ts +0 -1089
  51. package/src/managers/liveConfigManager.ts +0 -445
  52. package/src/managers/lspManager.ts +0 -470
  53. package/src/managers/mcpManager.ts +0 -1010
  54. package/src/managers/messageManager.ts +0 -1184
  55. package/src/managers/messageQueue.ts +0 -157
  56. package/src/managers/permissionManager.ts +0 -1140
  57. package/src/managers/planManager.ts +0 -112
  58. package/src/managers/pluginManager.ts +0 -330
  59. package/src/managers/pluginScopeManager.ts +0 -124
  60. package/src/managers/reversionManager.ts +0 -178
  61. package/src/managers/skillManager.ts +0 -578
  62. package/src/managers/slashCommandManager.ts +0 -564
  63. package/src/managers/subagentManager.ts +0 -915
  64. package/src/managers/toolManager.ts +0 -489
  65. package/src/managers/workflowManager.ts +0 -493
  66. package/src/prompts/autoMemory.ts +0 -33
  67. package/src/prompts/autoMemoryExtraction.ts +0 -146
  68. package/src/prompts/index.ts +0 -506
  69. package/src/prompts/planModeReminders.ts +0 -126
  70. package/src/services/GitService.ts +0 -131
  71. package/src/services/MarketplaceService.ts +0 -1052
  72. package/src/services/MemoryRuleService.ts +0 -71
  73. package/src/services/aiService.ts +0 -919
  74. package/src/services/authService.ts +0 -565
  75. package/src/services/autoMemoryService.ts +0 -280
  76. package/src/services/configurationService.ts +0 -1520
  77. package/src/services/fileWatcher.ts +0 -319
  78. package/src/services/hook.ts +0 -348
  79. package/src/services/initializationService.ts +0 -357
  80. package/src/services/interactionService.ts +0 -229
  81. package/src/services/jsonlHandler.ts +0 -295
  82. package/src/services/memory.ts +0 -234
  83. package/src/services/pluginLoader.ts +0 -252
  84. package/src/services/remoteSettingsService.ts +0 -366
  85. package/src/services/reversionService.ts +0 -122
  86. package/src/services/session.ts +0 -917
  87. package/src/services/taskManager.ts +0 -321
  88. package/src/telemetry/events.ts +0 -65
  89. package/src/telemetry/instrumentation.ts +0 -499
  90. package/src/telemetry/sessionTracing.ts +0 -348
  91. package/src/tools/agentTool.ts +0 -322
  92. package/src/tools/askUserQuestion.ts +0 -160
  93. package/src/tools/bashTool.ts +0 -621
  94. package/src/tools/buildTool.ts +0 -61
  95. package/src/tools/cronCreateTool.ts +0 -161
  96. package/src/tools/cronDeleteTool.ts +0 -51
  97. package/src/tools/cronListTool.ts +0 -47
  98. package/src/tools/editTool.ts +0 -313
  99. package/src/tools/enterPlanMode.ts +0 -124
  100. package/src/tools/enterWorktreeTool.ts +0 -190
  101. package/src/tools/exitPlanMode.ts +0 -139
  102. package/src/tools/exitWorktreeTool.ts +0 -236
  103. package/src/tools/globTool.ts +0 -167
  104. package/src/tools/grepTool.ts +0 -399
  105. package/src/tools/lspTool.ts +0 -883
  106. package/src/tools/readTool.ts +0 -426
  107. package/src/tools/skillTool.ts +0 -248
  108. package/src/tools/taskManagementTools.ts +0 -574
  109. package/src/tools/taskStopTool.ts +0 -78
  110. package/src/tools/types.ts +0 -137
  111. package/src/tools/webFetchTool.ts +0 -373
  112. package/src/tools/workflowTool.ts +0 -205
  113. package/src/tools/writeTool.ts +0 -267
  114. package/src/types/agent.ts +0 -128
  115. package/src/types/auth.ts +0 -19
  116. package/src/types/commands.ts +0 -30
  117. package/src/types/config.ts +0 -43
  118. package/src/types/configuration.ts +0 -168
  119. package/src/types/core.ts +0 -105
  120. package/src/types/cron.ts +0 -13
  121. package/src/types/environment.ts +0 -106
  122. package/src/types/fileSearch.ts +0 -4
  123. package/src/types/history.ts +0 -7
  124. package/src/types/hooks.ts +0 -256
  125. package/src/types/index.ts +0 -41
  126. package/src/types/lsp.ts +0 -98
  127. package/src/types/marketplace.ts +0 -71
  128. package/src/types/mcp.ts +0 -43
  129. package/src/types/memoryRule.ts +0 -31
  130. package/src/types/messaging.ts +0 -114
  131. package/src/types/permissions.ts +0 -80
  132. package/src/types/plugins.ts +0 -39
  133. package/src/types/processes.ts +0 -99
  134. package/src/types/reversion.ts +0 -29
  135. package/src/types/session.ts +0 -12
  136. package/src/types/skills.ts +0 -108
  137. package/src/types/tasks.ts +0 -13
  138. package/src/types/telemetry.ts +0 -98
  139. package/src/types/tools.ts +0 -44
  140. package/src/types/workflow.ts +0 -6
  141. package/src/utils/abortUtils.ts +0 -118
  142. package/src/utils/atomicWrite.ts +0 -61
  143. package/src/utils/bashParser.ts +0 -899
  144. package/src/utils/cacheControlUtils.ts +0 -426
  145. package/src/utils/commandArgumentParser.ts +0 -161
  146. package/src/utils/commandPathResolver.ts +0 -88
  147. package/src/utils/configPaths.ts +0 -220
  148. package/src/utils/configValidator.ts +0 -100
  149. package/src/utils/constants.ts +0 -39
  150. package/src/utils/container.ts +0 -92
  151. package/src/utils/containerSetup.ts +0 -371
  152. package/src/utils/convertMessagesForAPI.ts +0 -326
  153. package/src/utils/cronTasks.ts +0 -128
  154. package/src/utils/cronTasksLock.ts +0 -182
  155. package/src/utils/cronToHuman.ts +0 -99
  156. package/src/utils/customCommands.ts +0 -95
  157. package/src/utils/editUtils.ts +0 -20
  158. package/src/utils/fileFormat.ts +0 -40
  159. package/src/utils/fileSearch.ts +0 -151
  160. package/src/utils/fileUtils.ts +0 -223
  161. package/src/utils/gitUtils.ts +0 -315
  162. package/src/utils/globalLogger.ts +0 -128
  163. package/src/utils/groupMessagesByApiRound.ts +0 -121
  164. package/src/utils/hookMatcher.ts +0 -176
  165. package/src/utils/markdownParser.ts +0 -317
  166. package/src/utils/mcpUtils.ts +0 -138
  167. package/src/utils/messageOperations.ts +0 -659
  168. package/src/utils/modelCapabilities.ts +0 -30
  169. package/src/utils/nameGenerator.ts +0 -99
  170. package/src/utils/notificationXml.ts +0 -57
  171. package/src/utils/openaiClient.ts +0 -251
  172. package/src/utils/parseCronExpression.ts +0 -78
  173. package/src/utils/path.ts +0 -72
  174. package/src/utils/pathEncoder.ts +0 -400
  175. package/src/utils/pathSafety.ts +0 -40
  176. package/src/utils/promptHistory.ts +0 -168
  177. package/src/utils/ripgrep.ts +0 -35
  178. package/src/utils/shellResolver.ts +0 -190
  179. package/src/utils/skillParser.ts +0 -246
  180. package/src/utils/stringUtils.ts +0 -156
  181. package/src/utils/subagentParser.ts +0 -279
  182. package/src/utils/taskReminder.ts +0 -96
  183. package/src/utils/tokenCalculation.ts +0 -43
  184. package/src/utils/tokenEstimate.ts +0 -34
  185. package/src/utils/toolResultStorage.ts +0 -117
  186. package/src/utils/worktreeSession.ts +0 -26
  187. package/src/utils/worktreeUtils.ts +0 -786
  188. package/src/workflow/budgetTracker.ts +0 -34
  189. package/src/workflow/concurrencyLimiter.ts +0 -47
  190. package/src/workflow/journal.ts +0 -95
  191. package/src/workflow/progressReporter.ts +0 -141
  192. package/src/workflow/runState.ts +0 -65
  193. package/src/workflow/scriptRuntime.ts +0 -274
  194. package/src/workflow/structuredOutput.ts +0 -123
  195. package/src/workflow/types.ts +0 -101
  196. package/src/workflow/workflowApis.ts +0 -410
  197. package/vendor/ripgrep/linux-aarch64/rg +0 -0
  198. package/vendor/ripgrep/linux-x86_64/rg +0 -0
  199. package/vendor/ripgrep/macos-aarch64/rg +0 -0
  200. package/vendor/ripgrep/macos-x86_64/rg +0 -0
  201. package/vendor/ripgrep/windows-aarch64/rg.exe +0 -0
  202. package/vendor/ripgrep/windows-x86_64/rg.exe +0 -0
@@ -1,4 +0,0 @@
1
- export const BASH_SUBAGENT_TYPE = "Bash";
2
- export const EXPLORE_SUBAGENT_TYPE = "Explore";
3
- export const PLAN_SUBAGENT_TYPE = "Plan";
4
- export const GENERAL_PURPOSE_SUBAGENT_TYPE = "general-purpose";
@@ -1,15 +0,0 @@
1
- /**
2
- * Tool output size limits matching Claude Code patterns.
3
- */
4
-
5
- /** System-wide default max result size in characters. */
6
- export const DEFAULT_MAX_RESULT_SIZE_CHARS = 50_000;
7
-
8
- /** Per-command cap for bash tool output before persistence. */
9
- export const BASH_MAX_OUTPUT_CHARS = 30_000;
10
-
11
- /** Per-command cap for skill bash substitution (inline/block). */
12
- export const SKILL_BASH_MAX_OUTPUT_CHARS = 30_000;
13
-
14
- /** Preview size in characters when output is persisted to disk. */
15
- export const PREVIEW_SIZE_BYTES = 2_048;
@@ -1,24 +0,0 @@
1
- export const ASK_USER_QUESTION_TOOL_NAME = "AskUserQuestion";
2
- export const BASH_TOOL_NAME = "Bash";
3
- export const TASK_STOP_TOOL_NAME = "TaskStop";
4
- export const EDIT_TOOL_NAME = "Edit";
5
- export const ENTER_PLAN_MODE_TOOL_NAME = "EnterPlanMode";
6
- export const EXIT_PLAN_MODE_TOOL_NAME = "ExitPlanMode";
7
- export const GLOB_TOOL_NAME = "Glob";
8
- export const GREP_TOOL_NAME = "Grep";
9
- export const LSP_TOOL_NAME = "LSP";
10
- export const READ_TOOL_NAME = "Read";
11
- export const SKILL_TOOL_NAME = "Skill";
12
- export const AGENT_TOOL_NAME = "Agent";
13
- export const TASK_CREATE_TOOL_NAME = "TaskCreate";
14
- export const TASK_GET_TOOL_NAME = "TaskGet";
15
- export const TASK_UPDATE_TOOL_NAME = "TaskUpdate";
16
- export const TASK_LIST_TOOL_NAME = "TaskList";
17
- export const WRITE_TOOL_NAME = "Write";
18
- export const CRON_CREATE_TOOL_NAME = "CronCreate";
19
- export const CRON_DELETE_TOOL_NAME = "CronDelete";
20
- export const CRON_LIST_TOOL_NAME = "CronList";
21
- export const WEB_FETCH_TOOL_NAME = "WebFetch";
22
- export const ENTER_WORKTREE_TOOL_NAME = "EnterWorktree";
23
- export const EXIT_WORKTREE_TOOL_NAME = "ExitWorktree";
24
- export const WORKFLOW_TOOL_NAME = "Workflow";
@@ -1,237 +0,0 @@
1
- import { Container } from "../utils/container.js";
2
- import { PluginManager } from "../managers/pluginManager.js";
3
- import { PluginScopeManager } from "../managers/pluginScopeManager.js";
4
- import { MarketplaceService } from "../services/MarketplaceService.js";
5
- import { ConfigurationService } from "../services/configurationService.js";
6
- import {
7
- Scope,
8
- InstalledPlugin,
9
- KnownMarketplace,
10
- MarketplaceManifest,
11
- InstalledPluginsRegistry,
12
- MarketplacePluginStatus,
13
- } from "../types/index.js";
14
-
15
- /**
16
- * PluginCore
17
- *
18
- * Encapsulates plugin management logic, providing a high-level API for
19
- * installing, uninstalling, enabling, and disabling plugins.
20
- */
21
- export class PluginCore {
22
- private container: Container;
23
- private pluginManager: PluginManager;
24
- private pluginScopeManager: PluginScopeManager;
25
- private marketplaceService: MarketplaceService;
26
- private configurationService: ConfigurationService;
27
- private workdir: string;
28
-
29
- constructor(workdir: string = process.cwd()) {
30
- this.workdir = workdir;
31
- this.container = new Container();
32
- this.configurationService = new ConfigurationService();
33
- this.marketplaceService = new MarketplaceService(
34
- this.workdir,
35
- this.configurationService,
36
- );
37
-
38
- // Wire up ConfigurationService in the container for PluginManager to use
39
- this.container.register("ConfigurationService", this.configurationService);
40
-
41
- this.pluginManager = new PluginManager(this.container, {
42
- workdir: this.workdir,
43
- });
44
-
45
- this.pluginScopeManager = new PluginScopeManager({
46
- workdir: this.workdir,
47
- configurationService: this.configurationService,
48
- pluginManager: this.pluginManager,
49
- });
50
- }
51
-
52
- /**
53
- * Installs a plugin from a marketplace
54
- */
55
- async installPlugin(
56
- pluginId: string,
57
- scope?: Scope,
58
- ): Promise<InstalledPlugin> {
59
- const installedPlugin =
60
- await this.marketplaceService.installPlugin(pluginId);
61
- if (scope) {
62
- await this.enablePlugin(pluginId, scope);
63
- }
64
- return installedPlugin;
65
- }
66
-
67
- /**
68
- * Uninstalls a plugin and removes it from all configuration scopes
69
- */
70
- async uninstallPlugin(pluginId: string): Promise<void> {
71
- await this.marketplaceService.uninstallPlugin(pluginId);
72
- await this.pluginScopeManager.removePluginFromAllScopes(pluginId);
73
- }
74
-
75
- /**
76
- * Enables a plugin in the specified scope. If no scope is provided, it tries to find
77
- * the scope where the plugin is already configured, or defaults to "user".
78
- */
79
- async enablePlugin(pluginId: string, scope?: Scope): Promise<Scope> {
80
- const targetScope = scope || this.findPluginScope(pluginId) || "user";
81
- await this.pluginScopeManager.enablePlugin(targetScope, pluginId);
82
- return targetScope;
83
- }
84
-
85
- /**
86
- * Disables a plugin in the specified scope. If no scope is provided, it tries to find
87
- * the scope where the plugin is already configured, or defaults to "user".
88
- */
89
- async disablePlugin(pluginId: string, scope?: Scope): Promise<Scope> {
90
- const targetScope = scope || this.findPluginScope(pluginId) || "user";
91
- await this.pluginScopeManager.disablePlugin(targetScope, pluginId);
92
- return targetScope;
93
- }
94
-
95
- /**
96
- * Updates an installed plugin to the latest version from its marketplace
97
- */
98
- async updatePlugin(pluginId: string): Promise<InstalledPlugin> {
99
- return await this.marketplaceService.updatePlugin(pluginId);
100
- }
101
-
102
- /**
103
- * Toggles auto-update for a marketplace
104
- */
105
- async toggleAutoUpdate(name: string, enabled: boolean): Promise<void> {
106
- await this.marketplaceService.toggleAutoUpdate(name, enabled);
107
- }
108
-
109
- /**
110
- * Lists all plugins from all registered marketplaces with their installation and enabled status
111
- */
112
- async listPlugins(): Promise<{
113
- plugins: MarketplacePluginStatus[];
114
- mergedEnabled: Record<string, boolean>;
115
- }> {
116
- const installedPlugins =
117
- await this.marketplaceService.getInstalledPlugins();
118
- const marketplaces = await this.marketplaceService.listMarketplaces();
119
- const mergedEnabled = this.configurationService.getMergedEnabledPlugins(
120
- this.workdir,
121
- );
122
-
123
- const allMarketplacePlugins: MarketplacePluginStatus[] = [];
124
-
125
- for (const m of marketplaces) {
126
- try {
127
- const manifest = await this.marketplaceService.loadMarketplaceManifest(
128
- this.marketplaceService.getMarketplacePath(m.source),
129
- );
130
- manifest.plugins.forEach((p) => {
131
- const pluginId = `${p.name}@${m.name}`;
132
- const installed = installedPlugins.plugins.find(
133
- (ip) => ip.name === p.name && ip.marketplace === m.name,
134
- );
135
- allMarketplacePlugins.push({
136
- ...p,
137
- marketplace: m.name,
138
- installed: !!installed,
139
- version: installed?.version,
140
- cachePath: installed?.cachePath,
141
- projectPath: installed?.projectPath,
142
- scope:
143
- this.pluginScopeManager.findPluginScope(pluginId) || undefined,
144
- });
145
- });
146
- } catch {
147
- // Skip marketplaces that fail to load
148
- }
149
- }
150
-
151
- return {
152
- plugins: allMarketplacePlugins,
153
- mergedEnabled,
154
- };
155
- }
156
-
157
- /**
158
- * Adds a new marketplace
159
- */
160
- async addMarketplace(
161
- input: string,
162
- scope: Scope = "user",
163
- ): Promise<KnownMarketplace> {
164
- return await this.marketplaceService.addMarketplace(input, scope);
165
- }
166
-
167
- /**
168
- * Removes a marketplace by name
169
- */
170
- async removeMarketplace(name: string, scope?: Scope): Promise<void> {
171
- await this.marketplaceService.removeMarketplace(name, scope);
172
- }
173
-
174
- /**
175
- * Updates a specific marketplace or all marketplaces
176
- */
177
- async updateMarketplace(name?: string): Promise<void> {
178
- await this.marketplaceService.updateMarketplace(name);
179
- }
180
-
181
- /**
182
- * Lists all registered marketplaces
183
- */
184
- async listMarketplaces(): Promise<KnownMarketplace[]> {
185
- return await this.marketplaceService.listMarketplaces();
186
- }
187
-
188
- /**
189
- * Gets the registry of all installed plugins
190
- */
191
- async getInstalledPlugins(): Promise<InstalledPluginsRegistry> {
192
- return await this.marketplaceService.getInstalledPlugins();
193
- }
194
-
195
- /**
196
- * Gets the merged enabled state of all plugins across all scopes
197
- */
198
- getMergedEnabledPlugins(): Record<string, boolean> {
199
- return this.configurationService.getMergedEnabledPlugins(this.workdir);
200
- }
201
-
202
- /**
203
- * Loads a marketplace manifest from a local path
204
- */
205
- async loadMarketplaceManifest(
206
- marketplacePath: string,
207
- ): Promise<MarketplaceManifest> {
208
- return await this.marketplaceService.loadMarketplaceManifest(
209
- marketplacePath,
210
- );
211
- }
212
-
213
- /**
214
- * Resolves the local path for a marketplace
215
- */
216
- getMarketplacePath(marketplace: KnownMarketplace): string {
217
- return this.marketplaceService.getMarketplacePath(marketplace.source);
218
- }
219
-
220
- /**
221
- * Finds the scope where a plugin is currently enabled/disabled
222
- */
223
- findPluginScope(pluginId: string): Scope | null {
224
- return this.pluginScopeManager.findPluginScope(pluginId);
225
- }
226
-
227
- /**
228
- * Removes a plugin from the enabled plugins in the specified scope
229
- */
230
- async removeEnabledPlugin(scope: Scope, pluginId: string): Promise<void> {
231
- await this.configurationService.removeEnabledPlugin(
232
- this.workdir,
233
- scope,
234
- pluginId,
235
- );
236
- }
237
- }
@@ -1,9 +0,0 @@
1
- export {
2
- listSessions,
3
- listAllSessions,
4
- truncateContent,
5
- loadSessionFromJsonl,
6
- loadFullMessageThread,
7
- deleteSession,
8
- } from "../services/session.js";
9
- export type { SessionMetadata, SessionData } from "../services/session.js";
package/src/index.ts DELETED
@@ -1,38 +0,0 @@
1
- // Export all services
2
- export * from "./core/session.js";
3
- export * from "./services/authService.js";
4
-
5
- // Export constants
6
- export * from "./constants/tools.js";
7
-
8
- // Export main agent
9
- export * from "./agent.js";
10
- export * from "./core/plugin.js";
11
- export * from "./managers/cronManager.js";
12
- export * from "./managers/messageQueue.js";
13
-
14
- // Export all utilities
15
- export * from "./utils/bashParser.js";
16
- export * from "./utils/convertMessagesForAPI.js";
17
- export * from "./utils/modelCapabilities.js";
18
- export * from "./utils/fileSearch.js";
19
- export * from "./utils/globalLogger.js";
20
- export * from "./utils/mcpUtils.js";
21
- export * from "./utils/messageOperations.js";
22
- export * from "./utils/notificationXml.js";
23
- export * from "./utils/path.js";
24
- export * from "./utils/promptHistory.js";
25
- export * from "./utils/stringUtils.js";
26
- export * from "./utils/customCommands.js";
27
- export * from "./utils/hookMatcher.js";
28
- export * from "./utils/tokenCalculation.js";
29
- export * from "./utils/gitUtils.js";
30
- export * from "./utils/nameGenerator.js";
31
- export * from "./utils/worktreeSession.js";
32
- export * from "./utils/worktreeUtils.js";
33
- export { loadMergedWaveConfig } from "./services/configurationService.js";
34
- export * from "./types/index.js";
35
-
36
- // Export tool building utilities
37
- export * from "./tools/buildTool.js";
38
- export type { ToolPlugin, ToolResult, ToolContext } from "./tools/types.js";
@@ -1,198 +0,0 @@
1
- import type { MemoryRule } from "../types/memoryRule.js";
2
- import { MemoryRuleService } from "../services/MemoryRuleService.js";
3
- import * as fs from "node:fs/promises";
4
- import * as path from "node:path";
5
- import * as os from "node:os";
6
- import { logger } from "../utils/globalLogger.js";
7
-
8
- import { Container } from "../utils/container.js";
9
-
10
- export interface MemoryRuleRegistryState {
11
- /** All discovered rules, indexed by ID */
12
- rules: Record<string, MemoryRule>;
13
- /** Set of active rule IDs based on the current context */
14
- activeRuleIds: Set<string>;
15
- }
16
-
17
- export interface MemoryRuleManagerOptions {
18
- workdir: string;
19
- }
20
-
21
- export class MemoryRuleManager {
22
- private state: MemoryRuleRegistryState = {
23
- rules: {},
24
- activeRuleIds: new Set(),
25
- };
26
-
27
- private workdir: string;
28
- private service: MemoryRuleService;
29
-
30
- constructor(
31
- private container: Container,
32
- options: MemoryRuleManagerOptions,
33
- ) {
34
- this.workdir = options.workdir;
35
- this.service = new MemoryRuleService();
36
- }
37
-
38
- /**
39
- * Scans .wave/rules and ~/.wave/rules for memory rule files.
40
- */
41
- async discoverRules(): Promise<void> {
42
- const projectWaveRulesDir = path.join(this.workdir, ".wave", "rules");
43
- const projectClaudeRulesDir = path.join(this.workdir, ".claude", "rules");
44
- const userWaveRulesDir = path.join(os.homedir(), ".wave", "rules");
45
- const userClaudeRulesDir = path.join(os.homedir(), ".claude", "rules");
46
-
47
- logger.debug(`Scanning for modular memory rules...`);
48
- logger.debug(` User rules directory: ${userWaveRulesDir}`);
49
- logger.debug(` Project rules directory: ${projectWaveRulesDir}`);
50
-
51
- const newRules: Record<string, MemoryRule> = {};
52
-
53
- // Scan order: userClaude → userWave → projectClaude → projectWave
54
- // Later writes override, so .wave takes priority over .claude
55
- await this.scanDirectory(userClaudeRulesDir, "user", newRules);
56
- await this.scanDirectory(userWaveRulesDir, "user", newRules);
57
- await this.scanDirectory(projectClaudeRulesDir, "project", newRules);
58
- await this.scanDirectory(projectWaveRulesDir, "project", newRules);
59
-
60
- this.state.rules = newRules;
61
- const ruleCount = Object.keys(newRules).length;
62
- logger.debug(`Discovered ${ruleCount} modular memory rules`);
63
- }
64
-
65
- private async scanDirectory(
66
- dir: string,
67
- source: "project" | "user",
68
- registry: Record<string, MemoryRule>,
69
- visited: Set<string> = new Set(),
70
- ): Promise<void> {
71
- const realDir = await fs.realpath(dir).catch(() => dir);
72
- if (visited.has(realDir)) {
73
- logger.warn(
74
- `Circular symlink detected or directory already visited: ${dir}`,
75
- );
76
- return;
77
- }
78
- visited.add(realDir);
79
-
80
- try {
81
- const entries = await fs.readdir(dir, { withFileTypes: true });
82
- for (const entry of entries) {
83
- const fullPath = path.join(dir, entry.name);
84
- const isDirectory =
85
- typeof entry.isDirectory === "function" ? entry.isDirectory() : false;
86
- const isSymbolicLink =
87
- typeof entry.isSymbolicLink === "function"
88
- ? entry.isSymbolicLink()
89
- : false;
90
- const isFile =
91
- typeof entry.isFile === "function" ? entry.isFile() : false;
92
-
93
- if (isDirectory) {
94
- await this.scanDirectory(fullPath, source, registry, visited);
95
- } else if (isSymbolicLink) {
96
- const stats = await fs.stat(fullPath);
97
- if (stats.isDirectory()) {
98
- await this.scanDirectory(fullPath, source, registry, visited);
99
- } else if (stats.isFile() && entry.name.endsWith(".md")) {
100
- await this.loadRuleFile(fullPath, source, registry);
101
- }
102
- } else if (isFile && entry.name.endsWith(".md")) {
103
- await this.loadRuleFile(fullPath, source, registry);
104
- } else if (
105
- !isDirectory &&
106
- !isSymbolicLink &&
107
- !isFile &&
108
- entry.name.endsWith(".md")
109
- ) {
110
- // Fallback for simple string arrays or incomplete mocks
111
- await this.loadRuleFile(fullPath, source, registry);
112
- }
113
- }
114
- } catch (error) {
115
- // Ignore if directory doesn't exist
116
- if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
117
- logger.error(`Error scanning memory rules directory ${dir}:`, error);
118
- }
119
- }
120
- }
121
-
122
- private async loadRuleFile(
123
- filePath: string,
124
- source: "project" | "user",
125
- registry: Record<string, MemoryRule>,
126
- ): Promise<void> {
127
- try {
128
- const content = await fs.readFile(filePath, "utf-8");
129
- const rule = this.service.parseRule(content, filePath, source);
130
-
131
- // Determine rulesRoot dynamically based on actual file path
132
- let rulesRoot: string;
133
- if (source === "project") {
134
- if (filePath.includes(path.join(".claude", "rules"))) {
135
- rulesRoot = path.join(this.workdir, ".claude", "rules");
136
- } else {
137
- rulesRoot = path.join(this.workdir, ".wave", "rules");
138
- }
139
- } else {
140
- if (filePath.includes(path.join(".claude", "rules"))) {
141
- rulesRoot = path.join(os.homedir(), ".claude", "rules");
142
- } else {
143
- rulesRoot = path.join(os.homedir(), ".wave", "rules");
144
- }
145
- }
146
-
147
- const relativeId = path.relative(rulesRoot, filePath);
148
- rule.id = relativeId;
149
- registry[rule.id] = rule;
150
- logger.debug(`Loaded memory rule: ${relativeId} from ${filePath}`);
151
- } catch (error) {
152
- logger.error(`Failed to parse memory rule at ${filePath}:`, error);
153
- }
154
- }
155
-
156
- /**
157
- * Returns the union of all active memory rules based on the provided file paths.
158
- */
159
- getActiveRules(filesInContext: string[]): MemoryRule[] {
160
- const activeRules: MemoryRule[] = [];
161
- for (const rule of Object.values(this.state.rules)) {
162
- if (this.service.isRuleActive(rule, filesInContext, this.workdir)) {
163
- activeRules.push(rule);
164
- }
165
- }
166
- return activeRules;
167
- }
168
-
169
- /**
170
- * Returns rules split by type:
171
- * - unconditional: rules with no `paths` metadata (always active)
172
- * - conditional: rules with `paths` metadata that match filesInContext
173
- */
174
- getActiveRulesSplit(filesInContext: string[]): {
175
- unconditional: MemoryRule[];
176
- conditional: MemoryRule[];
177
- } {
178
- const unconditional: MemoryRule[] = [];
179
- const conditional: MemoryRule[] = [];
180
- for (const rule of Object.values(this.state.rules)) {
181
- if (!rule.metadata.paths || rule.metadata.paths.length === 0) {
182
- unconditional.push(rule);
183
- } else if (
184
- this.service.isRuleActive(rule, filesInContext, this.workdir)
185
- ) {
186
- conditional.push(rule);
187
- }
188
- }
189
- return { unconditional, conditional };
190
- }
191
-
192
- /**
193
- * Reloads rules from disk.
194
- */
195
- async reload(): Promise<void> {
196
- await this.discoverRules();
197
- }
198
- }