wave-agent-sdk 0.0.7 → 0.0.10

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 (240) hide show
  1. package/dist/agent.d.ts +105 -24
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +438 -53
  4. package/dist/index.d.ts +4 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +4 -0
  7. package/dist/managers/aiManager.d.ts +18 -7
  8. package/dist/managers/aiManager.d.ts.map +1 -1
  9. package/dist/managers/aiManager.js +254 -142
  10. package/dist/managers/backgroundBashManager.d.ts.map +1 -1
  11. package/dist/managers/backgroundBashManager.js +11 -9
  12. package/dist/managers/hookManager.d.ts +6 -6
  13. package/dist/managers/hookManager.d.ts.map +1 -1
  14. package/dist/managers/hookManager.js +81 -39
  15. package/dist/managers/liveConfigManager.d.ts +95 -0
  16. package/dist/managers/liveConfigManager.d.ts.map +1 -0
  17. package/dist/managers/liveConfigManager.js +442 -0
  18. package/dist/managers/lspManager.d.ts +43 -0
  19. package/dist/managers/lspManager.d.ts.map +1 -0
  20. package/dist/managers/lspManager.js +326 -0
  21. package/dist/managers/messageManager.d.ts +41 -24
  22. package/dist/managers/messageManager.d.ts.map +1 -1
  23. package/dist/managers/messageManager.js +184 -73
  24. package/dist/managers/permissionManager.d.ts +66 -0
  25. package/dist/managers/permissionManager.d.ts.map +1 -0
  26. package/dist/managers/permissionManager.js +208 -0
  27. package/dist/managers/skillManager.d.ts +1 -0
  28. package/dist/managers/skillManager.d.ts.map +1 -1
  29. package/dist/managers/skillManager.js +2 -1
  30. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  31. package/dist/managers/slashCommandManager.js +4 -2
  32. package/dist/managers/subagentManager.d.ts +42 -6
  33. package/dist/managers/subagentManager.d.ts.map +1 -1
  34. package/dist/managers/subagentManager.js +213 -62
  35. package/dist/managers/toolManager.d.ts +38 -1
  36. package/dist/managers/toolManager.d.ts.map +1 -1
  37. package/dist/managers/toolManager.js +66 -2
  38. package/dist/services/aiService.d.ts +15 -5
  39. package/dist/services/aiService.d.ts.map +1 -1
  40. package/dist/services/aiService.js +446 -77
  41. package/dist/services/configurationService.d.ts +116 -0
  42. package/dist/services/configurationService.d.ts.map +1 -0
  43. package/dist/services/configurationService.js +585 -0
  44. package/dist/services/fileWatcher.d.ts +69 -0
  45. package/dist/services/fileWatcher.d.ts.map +1 -0
  46. package/dist/services/fileWatcher.js +212 -0
  47. package/dist/services/hook.d.ts +5 -40
  48. package/dist/services/hook.d.ts.map +1 -1
  49. package/dist/services/hook.js +47 -109
  50. package/dist/services/jsonlHandler.d.ts +71 -0
  51. package/dist/services/jsonlHandler.d.ts.map +1 -0
  52. package/dist/services/jsonlHandler.js +236 -0
  53. package/dist/services/memory.d.ts.map +1 -1
  54. package/dist/services/memory.js +33 -11
  55. package/dist/services/session.d.ts +116 -52
  56. package/dist/services/session.d.ts.map +1 -1
  57. package/dist/services/session.js +415 -143
  58. package/dist/tools/bashTool.d.ts.map +1 -1
  59. package/dist/tools/bashTool.js +77 -17
  60. package/dist/tools/deleteFileTool.d.ts.map +1 -1
  61. package/dist/tools/deleteFileTool.js +27 -1
  62. package/dist/tools/editTool.d.ts.map +1 -1
  63. package/dist/tools/editTool.js +33 -8
  64. package/dist/tools/lspTool.d.ts +6 -0
  65. package/dist/tools/lspTool.d.ts.map +1 -0
  66. package/dist/tools/lspTool.js +589 -0
  67. package/dist/tools/multiEditTool.d.ts.map +1 -1
  68. package/dist/tools/multiEditTool.js +30 -10
  69. package/dist/tools/readTool.d.ts.map +1 -1
  70. package/dist/tools/readTool.js +113 -3
  71. package/dist/tools/skillTool.js +2 -2
  72. package/dist/tools/todoWriteTool.d.ts.map +1 -1
  73. package/dist/tools/todoWriteTool.js +23 -0
  74. package/dist/tools/types.d.ts +11 -8
  75. package/dist/tools/types.d.ts.map +1 -1
  76. package/dist/tools/writeTool.d.ts.map +1 -1
  77. package/dist/tools/writeTool.js +30 -15
  78. package/dist/types/commands.d.ts +4 -1
  79. package/dist/types/commands.d.ts.map +1 -1
  80. package/dist/types/config.d.ts +4 -0
  81. package/dist/types/config.d.ts.map +1 -1
  82. package/dist/types/configuration.d.ts +69 -0
  83. package/dist/types/configuration.d.ts.map +1 -0
  84. package/dist/types/configuration.js +8 -0
  85. package/dist/types/core.d.ts +45 -0
  86. package/dist/types/core.d.ts.map +1 -1
  87. package/dist/types/environment.d.ts +83 -0
  88. package/dist/types/environment.d.ts.map +1 -0
  89. package/dist/types/environment.js +21 -0
  90. package/dist/types/fileSearch.d.ts +5 -0
  91. package/dist/types/fileSearch.d.ts.map +1 -0
  92. package/dist/types/fileSearch.js +1 -0
  93. package/dist/types/hooks.d.ts +18 -3
  94. package/dist/types/hooks.d.ts.map +1 -1
  95. package/dist/types/hooks.js +8 -8
  96. package/dist/types/index.d.ts +7 -0
  97. package/dist/types/index.d.ts.map +1 -1
  98. package/dist/types/index.js +7 -0
  99. package/dist/types/lsp.d.ts +90 -0
  100. package/dist/types/lsp.d.ts.map +1 -0
  101. package/dist/types/lsp.js +4 -0
  102. package/dist/types/messaging.d.ts +19 -12
  103. package/dist/types/messaging.d.ts.map +1 -1
  104. package/dist/types/permissions.d.ts +35 -0
  105. package/dist/types/permissions.d.ts.map +1 -0
  106. package/dist/types/permissions.js +12 -0
  107. package/dist/types/session.d.ts +15 -0
  108. package/dist/types/session.d.ts.map +1 -0
  109. package/dist/types/session.js +7 -0
  110. package/dist/types/skills.d.ts +1 -0
  111. package/dist/types/skills.d.ts.map +1 -1
  112. package/dist/types/tools.d.ts +35 -0
  113. package/dist/types/tools.d.ts.map +1 -0
  114. package/dist/types/tools.js +4 -0
  115. package/dist/utils/abortUtils.d.ts +34 -0
  116. package/dist/utils/abortUtils.d.ts.map +1 -0
  117. package/dist/utils/abortUtils.js +92 -0
  118. package/dist/utils/bashHistory.d.ts +4 -0
  119. package/dist/utils/bashHistory.d.ts.map +1 -1
  120. package/dist/utils/bashHistory.js +48 -30
  121. package/dist/utils/builtinSubagents.d.ts +7 -0
  122. package/dist/utils/builtinSubagents.d.ts.map +1 -0
  123. package/dist/utils/builtinSubagents.js +65 -0
  124. package/dist/utils/cacheControlUtils.d.ts +96 -0
  125. package/dist/utils/cacheControlUtils.d.ts.map +1 -0
  126. package/dist/utils/cacheControlUtils.js +324 -0
  127. package/dist/utils/commandPathResolver.d.ts +52 -0
  128. package/dist/utils/commandPathResolver.d.ts.map +1 -0
  129. package/dist/utils/commandPathResolver.js +145 -0
  130. package/dist/utils/configPaths.d.ts +85 -0
  131. package/dist/utils/configPaths.d.ts.map +1 -0
  132. package/dist/utils/configPaths.js +121 -0
  133. package/dist/utils/constants.d.ts +1 -13
  134. package/dist/utils/constants.d.ts.map +1 -1
  135. package/dist/utils/constants.js +2 -14
  136. package/dist/utils/convertMessagesForAPI.d.ts +2 -1
  137. package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
  138. package/dist/utils/convertMessagesForAPI.js +39 -18
  139. package/dist/utils/customCommands.d.ts.map +1 -1
  140. package/dist/utils/customCommands.js +66 -21
  141. package/dist/utils/fileSearch.d.ts +14 -0
  142. package/dist/utils/fileSearch.d.ts.map +1 -0
  143. package/dist/utils/fileSearch.js +88 -0
  144. package/dist/utils/fileUtils.d.ts +27 -0
  145. package/dist/utils/fileUtils.d.ts.map +1 -0
  146. package/dist/utils/fileUtils.js +145 -0
  147. package/dist/utils/globalLogger.d.ts +88 -0
  148. package/dist/utils/globalLogger.d.ts.map +1 -0
  149. package/dist/utils/globalLogger.js +120 -0
  150. package/dist/utils/largeOutputHandler.d.ts +15 -0
  151. package/dist/utils/largeOutputHandler.d.ts.map +1 -0
  152. package/dist/utils/largeOutputHandler.js +40 -0
  153. package/dist/utils/markdownParser.d.ts.map +1 -1
  154. package/dist/utils/markdownParser.js +1 -17
  155. package/dist/utils/mcpUtils.d.ts.map +1 -1
  156. package/dist/utils/mcpUtils.js +25 -3
  157. package/dist/utils/messageOperations.d.ts +20 -18
  158. package/dist/utils/messageOperations.d.ts.map +1 -1
  159. package/dist/utils/messageOperations.js +30 -38
  160. package/dist/utils/pathEncoder.d.ts +108 -0
  161. package/dist/utils/pathEncoder.d.ts.map +1 -0
  162. package/dist/utils/pathEncoder.js +279 -0
  163. package/dist/utils/subagentParser.d.ts +2 -2
  164. package/dist/utils/subagentParser.d.ts.map +1 -1
  165. package/dist/utils/subagentParser.js +12 -8
  166. package/dist/utils/tokenCalculation.d.ts +26 -0
  167. package/dist/utils/tokenCalculation.d.ts.map +1 -0
  168. package/dist/utils/tokenCalculation.js +36 -0
  169. package/dist/utils/tokenEstimator.d.ts +39 -0
  170. package/dist/utils/tokenEstimator.d.ts.map +1 -0
  171. package/dist/utils/tokenEstimator.js +55 -0
  172. package/package.json +6 -6
  173. package/src/agent.ts +586 -78
  174. package/src/index.ts +4 -0
  175. package/src/managers/aiManager.ts +341 -192
  176. package/src/managers/backgroundBashManager.ts +11 -9
  177. package/src/managers/hookManager.ts +102 -54
  178. package/src/managers/liveConfigManager.ts +634 -0
  179. package/src/managers/lspManager.ts +434 -0
  180. package/src/managers/messageManager.ts +258 -121
  181. package/src/managers/permissionManager.ts +276 -0
  182. package/src/managers/skillManager.ts +3 -1
  183. package/src/managers/slashCommandManager.ts +5 -3
  184. package/src/managers/subagentManager.ts +295 -76
  185. package/src/managers/toolManager.ts +95 -3
  186. package/src/services/aiService.ts +656 -84
  187. package/src/services/configurationService.ts +762 -0
  188. package/src/services/fileWatcher.ts +300 -0
  189. package/src/services/hook.ts +54 -144
  190. package/src/services/jsonlHandler.ts +303 -0
  191. package/src/services/memory.ts +34 -11
  192. package/src/services/session.ts +522 -173
  193. package/src/tools/bashTool.ts +94 -20
  194. package/src/tools/deleteFileTool.ts +38 -1
  195. package/src/tools/editTool.ts +44 -9
  196. package/src/tools/lspTool.ts +760 -0
  197. package/src/tools/multiEditTool.ts +41 -11
  198. package/src/tools/readTool.ts +127 -3
  199. package/src/tools/skillTool.ts +2 -2
  200. package/src/tools/todoWriteTool.ts +33 -1
  201. package/src/tools/types.ts +15 -9
  202. package/src/tools/writeTool.ts +43 -16
  203. package/src/types/commands.ts +6 -1
  204. package/src/types/config.ts +5 -0
  205. package/src/types/configuration.ts +73 -0
  206. package/src/types/core.ts +55 -0
  207. package/src/types/environment.ts +104 -0
  208. package/src/types/fileSearch.ts +4 -0
  209. package/src/types/hooks.ts +32 -16
  210. package/src/types/index.ts +7 -0
  211. package/src/types/lsp.ts +96 -0
  212. package/src/types/messaging.ts +21 -14
  213. package/src/types/permissions.ts +48 -0
  214. package/src/types/session.ts +20 -0
  215. package/src/types/skills.ts +1 -0
  216. package/src/types/tools.ts +38 -0
  217. package/src/utils/abortUtils.ts +118 -0
  218. package/src/utils/bashHistory.ts +55 -31
  219. package/src/utils/builtinSubagents.ts +71 -0
  220. package/src/utils/cacheControlUtils.ts +475 -0
  221. package/src/utils/commandPathResolver.ts +189 -0
  222. package/src/utils/configPaths.ts +163 -0
  223. package/src/utils/constants.ts +2 -17
  224. package/src/utils/convertMessagesForAPI.ts +44 -18
  225. package/src/utils/customCommands.ts +90 -22
  226. package/src/utils/fileSearch.ts +107 -0
  227. package/src/utils/fileUtils.ts +160 -0
  228. package/src/utils/globalLogger.ts +128 -0
  229. package/src/utils/largeOutputHandler.ts +55 -0
  230. package/src/utils/markdownParser.ts +1 -19
  231. package/src/utils/mcpUtils.ts +34 -3
  232. package/src/utils/messageOperations.ts +47 -53
  233. package/src/utils/pathEncoder.ts +394 -0
  234. package/src/utils/subagentParser.ts +13 -9
  235. package/src/utils/tokenCalculation.ts +43 -0
  236. package/src/utils/tokenEstimator.ts +68 -0
  237. package/dist/utils/configResolver.d.ts +0 -38
  238. package/dist/utils/configResolver.d.ts.map +0 -1
  239. package/dist/utils/configResolver.js +0 -106
  240. package/src/utils/configResolver.ts +0 -142
@@ -0,0 +1,442 @@
1
+ /**
2
+ * Live Configuration Manager
3
+ *
4
+ * Orchestrates live configuration reload functionality including:
5
+ * - Hook configuration watching and reloading
6
+ * - Configuration file watching for settings.json files
7
+ * - Coordination between file watchers and configuration updates
8
+ */
9
+ import { existsSync } from "fs";
10
+ import { FileWatcherService, } from "../services/fileWatcher.js";
11
+ import { getProjectConfigPaths, getUserConfigPaths, } from "../utils/configPaths.js";
12
+ import { isValidHookEvent, isValidHookEventConfig } from "../types/hooks.js";
13
+ import { ConfigurationService } from "../services/configurationService.js";
14
+ import { ensureGlobalGitIgnore } from "../utils/fileUtils.js";
15
+ export class LiveConfigManager {
16
+ constructor(options) {
17
+ this.isInitialized = false;
18
+ // Configuration state
19
+ this.currentConfiguration = null;
20
+ this.lastValidConfiguration = null;
21
+ this.isWatching = false;
22
+ this.reloadInProgress = false;
23
+ this.workdir = options.workdir;
24
+ this.logger = options.logger;
25
+ this.hookManager = options.hookManager;
26
+ this.permissionManager = options.permissionManager;
27
+ this.configurationService =
28
+ options.configurationService || new ConfigurationService();
29
+ this.fileWatcher = new FileWatcherService(this.logger);
30
+ this.setupFileWatcherEvents();
31
+ }
32
+ /**
33
+ * Initialize configuration watching
34
+ * Maps to FR-004: System MUST watch settings.json files
35
+ * Supports watching multiple file paths (e.g., settings.local.json and settings.json)
36
+ */
37
+ async initializeWatching(userPaths, projectPaths) {
38
+ try {
39
+ this.logger?.info("Live Config: Initializing configuration watching...");
40
+ this.userConfigPaths = userPaths;
41
+ this.projectConfigPaths = projectPaths;
42
+ // Load initial configuration
43
+ await this.reloadConfiguration();
44
+ // Start watching user configs that exist
45
+ for (const userPath of userPaths) {
46
+ if (existsSync(userPath)) {
47
+ this.logger?.debug(`Live Config: Starting to watch user config: ${userPath}`);
48
+ await this.fileWatcher.watchFile(userPath, (event) => this.handleFileChange(event, "user"));
49
+ }
50
+ else {
51
+ this.logger?.debug(`Live Config: User config file does not exist: ${userPath}`);
52
+ }
53
+ }
54
+ // Start watching project configs that exist
55
+ if (projectPaths) {
56
+ for (const projectPath of projectPaths) {
57
+ if (existsSync(projectPath)) {
58
+ if (projectPath.endsWith("settings.local.json")) {
59
+ await ensureGlobalGitIgnore("**/.wave/settings.local.json");
60
+ }
61
+ this.logger?.debug(`Live Config: Starting to watch project config: ${projectPath}`);
62
+ await this.fileWatcher.watchFile(projectPath, (event) => this.handleFileChange(event, "project"));
63
+ }
64
+ else {
65
+ this.logger?.debug(`Live Config: Project config file does not exist: ${projectPath}`);
66
+ }
67
+ }
68
+ }
69
+ this.isWatching = true;
70
+ this.logger?.info("Live Config: Configuration watching initialized successfully");
71
+ }
72
+ catch (error) {
73
+ const errorMessage = `Failed to initialize configuration watching: ${error.message}`;
74
+ this.logger?.error(`Live Config: ${errorMessage}`);
75
+ throw new Error(errorMessage);
76
+ }
77
+ }
78
+ /**
79
+ * Get current configuration
80
+ */
81
+ getCurrentConfiguration() {
82
+ return this.currentConfiguration ? { ...this.currentConfiguration } : null;
83
+ }
84
+ /**
85
+ * Initialize configuration management with file watching
86
+ */
87
+ async initialize() {
88
+ if (this.isInitialized) {
89
+ this.logger?.debug("Already initialized");
90
+ return;
91
+ }
92
+ try {
93
+ // Get configuration file paths
94
+ const { userPaths, projectPaths } = this.getConfigurationPaths();
95
+ // Initialize configuration watching
96
+ await this.initializeWatching(userPaths, projectPaths);
97
+ this.isInitialized = true;
98
+ this.logger?.info("Live configuration management initialized with file watching");
99
+ }
100
+ catch (error) {
101
+ this.logger?.error(`Failed to initialize: ${error.message}`);
102
+ throw error;
103
+ }
104
+ }
105
+ /**
106
+ * Shutdown configuration management and cleanup resources
107
+ */
108
+ async shutdown() {
109
+ if (!this.isInitialized) {
110
+ return;
111
+ }
112
+ try {
113
+ this.logger?.info("Live Config: Shutting down configuration manager...");
114
+ this.isWatching = false;
115
+ // Cleanup file watcher
116
+ await this.fileWatcher.cleanup();
117
+ // Clean up state
118
+ this.currentConfiguration = null;
119
+ this.lastValidConfiguration = null;
120
+ this.isInitialized = false;
121
+ this.logger?.info("Live configuration management shutdown completed");
122
+ }
123
+ catch (error) {
124
+ this.logger?.error(`Error during shutdown: ${error.message}`);
125
+ throw error;
126
+ }
127
+ }
128
+ /**
129
+ * Reload configuration from files
130
+ * Maps to FR-008: Continue with previous valid configuration on errors
131
+ */
132
+ async reloadConfiguration() {
133
+ if (this.reloadInProgress) {
134
+ this.logger?.debug("Live Config: Reload already in progress, skipping");
135
+ return this.currentConfiguration || {};
136
+ }
137
+ this.reloadInProgress = true;
138
+ try {
139
+ this.logger?.debug("Live Config: Reloading configuration from files...");
140
+ // Load merged configuration using ConfigurationService
141
+ const loadResult = await this.configurationService.loadMergedConfiguration(this.workdir);
142
+ const newConfig = loadResult.configuration;
143
+ // Check for errors during loading
144
+ if (!loadResult.success) {
145
+ const errorMessage = loadResult.error || "Configuration loading failed with unknown error";
146
+ this.logger?.error(`Live Config: Configuration loading failed: ${errorMessage}`);
147
+ // Log warnings if any
148
+ if (loadResult.warnings && loadResult.warnings.length > 0) {
149
+ this.logger?.warn(`Live Config: Configuration warnings: ${loadResult.warnings.join("; ")}`);
150
+ }
151
+ // Use fallback configuration if available
152
+ if (this.lastValidConfiguration) {
153
+ this.logger?.info("Live Config: Using previous valid configuration due to loading errors");
154
+ this.currentConfiguration = this.lastValidConfiguration;
155
+ // Apply environment variables to configuration service if configured
156
+ if (this.lastValidConfiguration.env) {
157
+ this.configurationService.setEnvironmentVars(this.lastValidConfiguration.env);
158
+ }
159
+ // Update hook manager if available
160
+ if (this.hookManager) {
161
+ this.hookManager.loadConfigurationFromWaveConfig(this.lastValidConfiguration);
162
+ }
163
+ return this.currentConfiguration;
164
+ }
165
+ else {
166
+ this.logger?.warn("Live Config: No previous valid configuration available, using empty config");
167
+ this.currentConfiguration = {};
168
+ return this.currentConfiguration;
169
+ }
170
+ }
171
+ // Log success with detailed information
172
+ if (newConfig) {
173
+ this.logger?.info(`Live Config: Configuration loaded successfully from ${loadResult.sourcePath || "merged sources"}`);
174
+ // Log detailed configuration info
175
+ const hookCount = Object.keys(newConfig.hooks || {}).length;
176
+ const envCount = Object.keys(newConfig.env || {}).length;
177
+ this.logger?.debug(`Live Config: Loaded ${hookCount} hook events and ${envCount} environment variables`);
178
+ }
179
+ else {
180
+ this.logger?.info("Live Config: No configuration found (using empty configuration)");
181
+ }
182
+ // Log warnings from successful loading
183
+ if (loadResult.warnings && loadResult.warnings.length > 0) {
184
+ this.logger?.warn(`Live Config: Configuration warnings: ${loadResult.warnings.join("; ")}`);
185
+ }
186
+ // Validate new configuration if it exists
187
+ if (newConfig) {
188
+ const validation = this.validateConfiguration(newConfig);
189
+ if (!validation.valid) {
190
+ const errorMessage = `Configuration validation failed: ${validation.errors.join(", ")}`;
191
+ this.logger?.error(`Live Config: ${errorMessage}`);
192
+ // Use previous valid configuration for error recovery
193
+ if (this.lastValidConfiguration) {
194
+ this.logger?.info("Live Config: Using previous valid configuration due to validation errors");
195
+ this.currentConfiguration = this.lastValidConfiguration;
196
+ // Apply environment variables to configuration service if configured
197
+ if (this.lastValidConfiguration.env) {
198
+ this.configurationService.setEnvironmentVars(this.lastValidConfiguration.env);
199
+ }
200
+ // Update hook manager if available
201
+ if (this.hookManager) {
202
+ this.hookManager.loadConfigurationFromWaveConfig(this.lastValidConfiguration);
203
+ }
204
+ return this.currentConfiguration;
205
+ }
206
+ else {
207
+ this.logger?.warn("Live Config: No previous valid configuration available, using empty config");
208
+ this.currentConfiguration = {};
209
+ return this.currentConfiguration;
210
+ }
211
+ }
212
+ }
213
+ // Detect changes between old and new configuration
214
+ this.detectChanges(this.currentConfiguration, newConfig);
215
+ // Update current configuration
216
+ this.currentConfiguration = newConfig || {};
217
+ // Save as last valid configuration if it's valid and not empty
218
+ if (newConfig && (newConfig.hooks || newConfig.env)) {
219
+ this.lastValidConfiguration = { ...newConfig };
220
+ this.logger?.debug("Live Config: Saved current configuration as last valid backup");
221
+ }
222
+ // Note: Environment variables are already applied by loadMergedConfiguration()
223
+ // No need to set them again here as currentConfiguration === newConfig
224
+ // Update hook manager if available
225
+ if (this.hookManager) {
226
+ this.hookManager.loadConfigurationFromWaveConfig(this.currentConfiguration);
227
+ }
228
+ // Update permission manager if available
229
+ if (this.permissionManager) {
230
+ if (this.currentConfiguration.defaultMode) {
231
+ this.permissionManager.updateConfiguredDefaultMode(this.currentConfiguration.defaultMode);
232
+ }
233
+ if (this.currentConfiguration.permissions?.allow) {
234
+ this.permissionManager.updateAllowedRules(this.currentConfiguration.permissions.allow);
235
+ }
236
+ }
237
+ this.logger?.info(`Live Config: Configuration reload completed successfully with ${Object.keys(newConfig?.hooks || {}).length} event types and ${Object.keys(newConfig?.env || {}).length} environment variables`);
238
+ return this.currentConfiguration;
239
+ }
240
+ catch (error) {
241
+ const errorMessage = `Configuration reload failed with exception: ${error.message}`;
242
+ this.logger?.error(`Live Config: ${errorMessage}`);
243
+ // Use previous valid configuration for error recovery
244
+ if (this.lastValidConfiguration) {
245
+ this.logger?.info("Live Config: Using previous valid configuration due to reload exception");
246
+ this.currentConfiguration = this.lastValidConfiguration;
247
+ // Apply environment variables to configuration service if configured
248
+ if (this.lastValidConfiguration.env) {
249
+ this.configurationService.setEnvironmentVars(this.lastValidConfiguration.env);
250
+ }
251
+ // Update hook manager if available
252
+ if (this.hookManager) {
253
+ this.hookManager.loadConfigurationFromWaveConfig(this.lastValidConfiguration);
254
+ }
255
+ }
256
+ else {
257
+ this.logger?.warn("Live Config: No previous valid configuration available, using empty config");
258
+ this.currentConfiguration = {};
259
+ }
260
+ return this.currentConfiguration;
261
+ }
262
+ finally {
263
+ this.reloadInProgress = false;
264
+ }
265
+ }
266
+ /**
267
+ * Reload configuration from files (public method)
268
+ */
269
+ async reload() {
270
+ this.logger?.info("Manually reloading configuration...");
271
+ return await this.reloadConfiguration();
272
+ }
273
+ /**
274
+ * Check if watching is active
275
+ */
276
+ isWatchingActive() {
277
+ return this.isWatching;
278
+ }
279
+ /**
280
+ * Get watcher status for monitoring
281
+ */
282
+ getWatcherStatus() {
283
+ const statuses = this.fileWatcher.getAllWatcherStatuses();
284
+ return {
285
+ isActive: this.isWatching,
286
+ configurationLoaded: this.currentConfiguration !== null,
287
+ hasValidConfiguration: this.lastValidConfiguration !== null,
288
+ reloadInProgress: this.reloadInProgress,
289
+ watchedFiles: statuses.map((s) => ({
290
+ path: s.path,
291
+ isActive: s.isActive,
292
+ method: s.method,
293
+ errorCount: s.errorCount,
294
+ })),
295
+ };
296
+ }
297
+ setupFileWatcherEvents() {
298
+ this.fileWatcher.on("watcherError", (error) => {
299
+ this.logger?.error(`Live Config: File watcher error: ${error.message}`);
300
+ });
301
+ }
302
+ async handleFileChange(event, source) {
303
+ this.logger?.debug(`Live Config: File ${event.type} detected for ${source} config: ${event.path}`);
304
+ try {
305
+ // Handle file deletion
306
+ if (event.type === "delete") {
307
+ this.logger?.info(`Live Config: ${source} config file deleted: ${event.path}`);
308
+ // Reload configuration without the deleted file
309
+ await this.reloadConfiguration();
310
+ return;
311
+ }
312
+ // Handle file creation or modification
313
+ if (event.type === "change" || event.type === "create") {
314
+ this.logger?.info(`Live Config: ${source} config file ${event.type}: ${event.path}`);
315
+ if (source === "project" &&
316
+ event.path.endsWith("settings.local.json") &&
317
+ event.type === "create") {
318
+ await ensureGlobalGitIgnore("**/.wave/settings.local.json");
319
+ }
320
+ // Add small delay to ensure file write is complete
321
+ await new Promise((resolve) => setTimeout(resolve, 50));
322
+ // Reload configuration
323
+ await this.reloadConfiguration();
324
+ }
325
+ }
326
+ catch (error) {
327
+ this.logger?.error(`Live Config: Error handling file change for ${source} config: ${error.message}`);
328
+ }
329
+ }
330
+ /**
331
+ * Validate configuration structure and content
332
+ */
333
+ validateConfiguration(config) {
334
+ const errors = [];
335
+ if (!config || typeof config !== "object") {
336
+ return { valid: false, errors: ["Configuration must be an object"] };
337
+ }
338
+ // Validate defaultMode if present
339
+ if (config.defaultMode !== undefined) {
340
+ if (config.defaultMode !== "default" &&
341
+ config.defaultMode !== "bypassPermissions" &&
342
+ config.defaultMode !== "acceptEdits") {
343
+ errors.push(`Invalid defaultMode: "${config.defaultMode}". Must be "default", "bypassPermissions" or "acceptEdits"`);
344
+ }
345
+ }
346
+ // Validate hooks if present
347
+ if (config.hooks) {
348
+ if (typeof config.hooks !== "object") {
349
+ errors.push("hooks property must be an object");
350
+ }
351
+ else {
352
+ // Validate each hook event
353
+ for (const [eventName, eventConfigs] of Object.entries(config.hooks)) {
354
+ // Validate event name
355
+ if (!isValidHookEvent(eventName)) {
356
+ errors.push(`Invalid hook event: ${eventName}`);
357
+ continue;
358
+ }
359
+ // Validate event configurations
360
+ if (!Array.isArray(eventConfigs)) {
361
+ errors.push(`Hook event ${eventName} must be an array of configurations`);
362
+ continue;
363
+ }
364
+ eventConfigs.forEach((eventConfig, index) => {
365
+ if (!isValidHookEventConfig(eventConfig)) {
366
+ errors.push(`Invalid hook event configuration at ${eventName}[${index}]`);
367
+ }
368
+ });
369
+ }
370
+ }
371
+ }
372
+ // Validate environment variables if present
373
+ if (config.env) {
374
+ if (typeof config.env !== "object" || Array.isArray(config.env)) {
375
+ errors.push("env property must be an object");
376
+ }
377
+ else {
378
+ for (const [key, value] of Object.entries(config.env)) {
379
+ if (typeof key !== "string" || key.trim() === "") {
380
+ errors.push(`Invalid environment variable key: ${key}`);
381
+ }
382
+ if (typeof value !== "string") {
383
+ errors.push(`Environment variable ${key} must have a string value`);
384
+ }
385
+ }
386
+ }
387
+ }
388
+ return {
389
+ valid: errors.length === 0,
390
+ errors,
391
+ };
392
+ }
393
+ detectChanges(oldConfig, newConfig) {
394
+ const added = [];
395
+ const modified = [];
396
+ const removed = [];
397
+ // Handle environment variables changes
398
+ const oldEnv = oldConfig?.env || {};
399
+ const newEnv = newConfig?.env || {};
400
+ for (const key of Object.keys(newEnv)) {
401
+ if (!(key in oldEnv)) {
402
+ added.push(`env.${key}`);
403
+ }
404
+ else if (oldEnv[key] !== newEnv[key]) {
405
+ modified.push(`env.${key}`);
406
+ }
407
+ }
408
+ for (const key of Object.keys(oldEnv)) {
409
+ if (!(key in newEnv)) {
410
+ removed.push(`env.${key}`);
411
+ }
412
+ }
413
+ // Handle hooks changes (simplified)
414
+ const oldHooks = oldConfig?.hooks || {};
415
+ const newHooks = newConfig?.hooks || {};
416
+ for (const event of Object.keys(newHooks)) {
417
+ if (isValidHookEvent(event)) {
418
+ if (!(event in oldHooks)) {
419
+ added.push(`hooks.${event}`);
420
+ }
421
+ else if (JSON.stringify(oldHooks[event]) !== JSON.stringify(newHooks[event])) {
422
+ modified.push(`hooks.${event}`);
423
+ }
424
+ }
425
+ }
426
+ for (const event of Object.keys(oldHooks)) {
427
+ if (isValidHookEvent(event) && !(event in newHooks)) {
428
+ removed.push(`hooks.${event}`);
429
+ }
430
+ }
431
+ return { added, modified, removed };
432
+ }
433
+ /**
434
+ * Get configuration file paths for user and project settings
435
+ * Returns paths in priority order (local.json first, then .json)
436
+ */
437
+ getConfigurationPaths() {
438
+ const userPaths = getUserConfigPaths();
439
+ const projectPaths = getProjectConfigPaths(this.workdir);
440
+ return { userPaths, projectPaths };
441
+ }
442
+ }
@@ -0,0 +1,43 @@
1
+ import { ChildProcess } from "child_process";
2
+ import { Logger, LspServerConfig, ILspManager } from "../types/index.js";
3
+ interface LspProcess {
4
+ process: ChildProcess;
5
+ config: LspServerConfig;
6
+ language: string;
7
+ initialized: boolean;
8
+ requestId: number;
9
+ pendingRequests: Map<number, {
10
+ resolve: (value: unknown) => void;
11
+ reject: (reason?: unknown) => void;
12
+ }>;
13
+ openedFiles: Set<string>;
14
+ }
15
+ export declare class LspManager implements ILspManager {
16
+ private processes;
17
+ private workdir;
18
+ private logger?;
19
+ private config;
20
+ constructor(options?: {
21
+ logger?: Logger;
22
+ });
23
+ initialize(workdir: string): Promise<void>;
24
+ registerServer(language: string, config: LspServerConfig): void;
25
+ private loadConfig;
26
+ getProcessForFile(filePath: string): Promise<LspProcess | null>;
27
+ private startServer;
28
+ private handleMessage;
29
+ private sendRequest;
30
+ private sendNotification;
31
+ execute(args: {
32
+ operation: string;
33
+ filePath: string;
34
+ line: number;
35
+ character: number;
36
+ }): Promise<{
37
+ success: boolean;
38
+ content: string;
39
+ }>;
40
+ cleanup(): Promise<void>;
41
+ }
42
+ export {};
43
+ //# sourceMappingURL=lspManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lspManager.d.ts","sourceRoot":"","sources":["../../src/managers/lspManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAS,MAAM,eAAe,CAAC;AACpD,OAAO,EACL,MAAM,EAEN,eAAe,EACf,WAAW,EAEZ,MAAM,mBAAmB,CAAC;AAI3B,UAAU,UAAU;IAClB,OAAO,EAAE,YAAY,CAAC;IACtB,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,GAAG,CAClB,MAAM,EACN;QAAE,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;QAAC,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;KAAE,CAC1E,CAAC;IACF,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC1B;AAED,qBAAa,UAAW,YAAW,WAAW;IAC5C,OAAO,CAAC,SAAS,CAAsC;IACvD,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,MAAM,CAAiB;gBAEnB,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO;IAIvC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKhD,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI;YAKjD,UAAU;IAclB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;YA0BvD,WAAW;IAoGzB,OAAO,CAAC,aAAa;YAiBP,WAAW;YA0CX,gBAAgB;IAgBxB,OAAO,CAAC,IAAI,EAAE;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;KACnB,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAoJ5C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAqB/B"}