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.
- package/dist/agent.d.ts +105 -24
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +438 -53
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/managers/aiManager.d.ts +18 -7
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +254 -142
- package/dist/managers/backgroundBashManager.d.ts.map +1 -1
- package/dist/managers/backgroundBashManager.js +11 -9
- package/dist/managers/hookManager.d.ts +6 -6
- package/dist/managers/hookManager.d.ts.map +1 -1
- package/dist/managers/hookManager.js +81 -39
- package/dist/managers/liveConfigManager.d.ts +95 -0
- package/dist/managers/liveConfigManager.d.ts.map +1 -0
- package/dist/managers/liveConfigManager.js +442 -0
- package/dist/managers/lspManager.d.ts +43 -0
- package/dist/managers/lspManager.d.ts.map +1 -0
- package/dist/managers/lspManager.js +326 -0
- package/dist/managers/messageManager.d.ts +41 -24
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +184 -73
- package/dist/managers/permissionManager.d.ts +66 -0
- package/dist/managers/permissionManager.d.ts.map +1 -0
- package/dist/managers/permissionManager.js +208 -0
- package/dist/managers/skillManager.d.ts +1 -0
- package/dist/managers/skillManager.d.ts.map +1 -1
- package/dist/managers/skillManager.js +2 -1
- package/dist/managers/slashCommandManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.js +4 -2
- package/dist/managers/subagentManager.d.ts +42 -6
- package/dist/managers/subagentManager.d.ts.map +1 -1
- package/dist/managers/subagentManager.js +213 -62
- package/dist/managers/toolManager.d.ts +38 -1
- package/dist/managers/toolManager.d.ts.map +1 -1
- package/dist/managers/toolManager.js +66 -2
- package/dist/services/aiService.d.ts +15 -5
- package/dist/services/aiService.d.ts.map +1 -1
- package/dist/services/aiService.js +446 -77
- package/dist/services/configurationService.d.ts +116 -0
- package/dist/services/configurationService.d.ts.map +1 -0
- package/dist/services/configurationService.js +585 -0
- package/dist/services/fileWatcher.d.ts +69 -0
- package/dist/services/fileWatcher.d.ts.map +1 -0
- package/dist/services/fileWatcher.js +212 -0
- package/dist/services/hook.d.ts +5 -40
- package/dist/services/hook.d.ts.map +1 -1
- package/dist/services/hook.js +47 -109
- package/dist/services/jsonlHandler.d.ts +71 -0
- package/dist/services/jsonlHandler.d.ts.map +1 -0
- package/dist/services/jsonlHandler.js +236 -0
- package/dist/services/memory.d.ts.map +1 -1
- package/dist/services/memory.js +33 -11
- package/dist/services/session.d.ts +116 -52
- package/dist/services/session.d.ts.map +1 -1
- package/dist/services/session.js +415 -143
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +77 -17
- package/dist/tools/deleteFileTool.d.ts.map +1 -1
- package/dist/tools/deleteFileTool.js +27 -1
- package/dist/tools/editTool.d.ts.map +1 -1
- package/dist/tools/editTool.js +33 -8
- package/dist/tools/lspTool.d.ts +6 -0
- package/dist/tools/lspTool.d.ts.map +1 -0
- package/dist/tools/lspTool.js +589 -0
- package/dist/tools/multiEditTool.d.ts.map +1 -1
- package/dist/tools/multiEditTool.js +30 -10
- package/dist/tools/readTool.d.ts.map +1 -1
- package/dist/tools/readTool.js +113 -3
- package/dist/tools/skillTool.js +2 -2
- package/dist/tools/todoWriteTool.d.ts.map +1 -1
- package/dist/tools/todoWriteTool.js +23 -0
- package/dist/tools/types.d.ts +11 -8
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/writeTool.d.ts.map +1 -1
- package/dist/tools/writeTool.js +30 -15
- package/dist/types/commands.d.ts +4 -1
- package/dist/types/commands.d.ts.map +1 -1
- package/dist/types/config.d.ts +4 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/configuration.d.ts +69 -0
- package/dist/types/configuration.d.ts.map +1 -0
- package/dist/types/configuration.js +8 -0
- package/dist/types/core.d.ts +45 -0
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/environment.d.ts +83 -0
- package/dist/types/environment.d.ts.map +1 -0
- package/dist/types/environment.js +21 -0
- package/dist/types/fileSearch.d.ts +5 -0
- package/dist/types/fileSearch.d.ts.map +1 -0
- package/dist/types/fileSearch.js +1 -0
- package/dist/types/hooks.d.ts +18 -3
- package/dist/types/hooks.d.ts.map +1 -1
- package/dist/types/hooks.js +8 -8
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +7 -0
- package/dist/types/lsp.d.ts +90 -0
- package/dist/types/lsp.d.ts.map +1 -0
- package/dist/types/lsp.js +4 -0
- package/dist/types/messaging.d.ts +19 -12
- package/dist/types/messaging.d.ts.map +1 -1
- package/dist/types/permissions.d.ts +35 -0
- package/dist/types/permissions.d.ts.map +1 -0
- package/dist/types/permissions.js +12 -0
- package/dist/types/session.d.ts +15 -0
- package/dist/types/session.d.ts.map +1 -0
- package/dist/types/session.js +7 -0
- package/dist/types/skills.d.ts +1 -0
- package/dist/types/skills.d.ts.map +1 -1
- package/dist/types/tools.d.ts +35 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +4 -0
- package/dist/utils/abortUtils.d.ts +34 -0
- package/dist/utils/abortUtils.d.ts.map +1 -0
- package/dist/utils/abortUtils.js +92 -0
- package/dist/utils/bashHistory.d.ts +4 -0
- package/dist/utils/bashHistory.d.ts.map +1 -1
- package/dist/utils/bashHistory.js +48 -30
- package/dist/utils/builtinSubagents.d.ts +7 -0
- package/dist/utils/builtinSubagents.d.ts.map +1 -0
- package/dist/utils/builtinSubagents.js +65 -0
- package/dist/utils/cacheControlUtils.d.ts +96 -0
- package/dist/utils/cacheControlUtils.d.ts.map +1 -0
- package/dist/utils/cacheControlUtils.js +324 -0
- package/dist/utils/commandPathResolver.d.ts +52 -0
- package/dist/utils/commandPathResolver.d.ts.map +1 -0
- package/dist/utils/commandPathResolver.js +145 -0
- package/dist/utils/configPaths.d.ts +85 -0
- package/dist/utils/configPaths.d.ts.map +1 -0
- package/dist/utils/configPaths.js +121 -0
- package/dist/utils/constants.d.ts +1 -13
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +2 -14
- package/dist/utils/convertMessagesForAPI.d.ts +2 -1
- package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
- package/dist/utils/convertMessagesForAPI.js +39 -18
- package/dist/utils/customCommands.d.ts.map +1 -1
- package/dist/utils/customCommands.js +66 -21
- package/dist/utils/fileSearch.d.ts +14 -0
- package/dist/utils/fileSearch.d.ts.map +1 -0
- package/dist/utils/fileSearch.js +88 -0
- package/dist/utils/fileUtils.d.ts +27 -0
- package/dist/utils/fileUtils.d.ts.map +1 -0
- package/dist/utils/fileUtils.js +145 -0
- package/dist/utils/globalLogger.d.ts +88 -0
- package/dist/utils/globalLogger.d.ts.map +1 -0
- package/dist/utils/globalLogger.js +120 -0
- package/dist/utils/largeOutputHandler.d.ts +15 -0
- package/dist/utils/largeOutputHandler.d.ts.map +1 -0
- package/dist/utils/largeOutputHandler.js +40 -0
- package/dist/utils/markdownParser.d.ts.map +1 -1
- package/dist/utils/markdownParser.js +1 -17
- package/dist/utils/mcpUtils.d.ts.map +1 -1
- package/dist/utils/mcpUtils.js +25 -3
- package/dist/utils/messageOperations.d.ts +20 -18
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +30 -38
- package/dist/utils/pathEncoder.d.ts +108 -0
- package/dist/utils/pathEncoder.d.ts.map +1 -0
- package/dist/utils/pathEncoder.js +279 -0
- package/dist/utils/subagentParser.d.ts +2 -2
- package/dist/utils/subagentParser.d.ts.map +1 -1
- package/dist/utils/subagentParser.js +12 -8
- package/dist/utils/tokenCalculation.d.ts +26 -0
- package/dist/utils/tokenCalculation.d.ts.map +1 -0
- package/dist/utils/tokenCalculation.js +36 -0
- package/dist/utils/tokenEstimator.d.ts +39 -0
- package/dist/utils/tokenEstimator.d.ts.map +1 -0
- package/dist/utils/tokenEstimator.js +55 -0
- package/package.json +6 -6
- package/src/agent.ts +586 -78
- package/src/index.ts +4 -0
- package/src/managers/aiManager.ts +341 -192
- package/src/managers/backgroundBashManager.ts +11 -9
- package/src/managers/hookManager.ts +102 -54
- package/src/managers/liveConfigManager.ts +634 -0
- package/src/managers/lspManager.ts +434 -0
- package/src/managers/messageManager.ts +258 -121
- package/src/managers/permissionManager.ts +276 -0
- package/src/managers/skillManager.ts +3 -1
- package/src/managers/slashCommandManager.ts +5 -3
- package/src/managers/subagentManager.ts +295 -76
- package/src/managers/toolManager.ts +95 -3
- package/src/services/aiService.ts +656 -84
- package/src/services/configurationService.ts +762 -0
- package/src/services/fileWatcher.ts +300 -0
- package/src/services/hook.ts +54 -144
- package/src/services/jsonlHandler.ts +303 -0
- package/src/services/memory.ts +34 -11
- package/src/services/session.ts +522 -173
- package/src/tools/bashTool.ts +94 -20
- package/src/tools/deleteFileTool.ts +38 -1
- package/src/tools/editTool.ts +44 -9
- package/src/tools/lspTool.ts +760 -0
- package/src/tools/multiEditTool.ts +41 -11
- package/src/tools/readTool.ts +127 -3
- package/src/tools/skillTool.ts +2 -2
- package/src/tools/todoWriteTool.ts +33 -1
- package/src/tools/types.ts +15 -9
- package/src/tools/writeTool.ts +43 -16
- package/src/types/commands.ts +6 -1
- package/src/types/config.ts +5 -0
- package/src/types/configuration.ts +73 -0
- package/src/types/core.ts +55 -0
- package/src/types/environment.ts +104 -0
- package/src/types/fileSearch.ts +4 -0
- package/src/types/hooks.ts +32 -16
- package/src/types/index.ts +7 -0
- package/src/types/lsp.ts +96 -0
- package/src/types/messaging.ts +21 -14
- package/src/types/permissions.ts +48 -0
- package/src/types/session.ts +20 -0
- package/src/types/skills.ts +1 -0
- package/src/types/tools.ts +38 -0
- package/src/utils/abortUtils.ts +118 -0
- package/src/utils/bashHistory.ts +55 -31
- package/src/utils/builtinSubagents.ts +71 -0
- package/src/utils/cacheControlUtils.ts +475 -0
- package/src/utils/commandPathResolver.ts +189 -0
- package/src/utils/configPaths.ts +163 -0
- package/src/utils/constants.ts +2 -17
- package/src/utils/convertMessagesForAPI.ts +44 -18
- package/src/utils/customCommands.ts +90 -22
- package/src/utils/fileSearch.ts +107 -0
- package/src/utils/fileUtils.ts +160 -0
- package/src/utils/globalLogger.ts +128 -0
- package/src/utils/largeOutputHandler.ts +55 -0
- package/src/utils/markdownParser.ts +1 -19
- package/src/utils/mcpUtils.ts +34 -3
- package/src/utils/messageOperations.ts +47 -53
- package/src/utils/pathEncoder.ts +394 -0
- package/src/utils/subagentParser.ts +13 -9
- package/src/utils/tokenCalculation.ts +43 -0
- package/src/utils/tokenEstimator.ts +68 -0
- package/dist/utils/configResolver.d.ts +0 -38
- package/dist/utils/configResolver.d.ts.map +0 -1
- package/dist/utils/configResolver.js +0 -106
- 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"}
|