wave-agent-sdk 0.0.8 → 0.0.11
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 +92 -23
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +351 -137
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/managers/aiManager.d.ts +14 -36
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +74 -77
- package/dist/managers/backgroundBashManager.d.ts.map +1 -1
- package/dist/managers/backgroundBashManager.js +4 -3
- package/dist/managers/hookManager.d.ts +3 -8
- package/dist/managers/hookManager.d.ts.map +1 -1
- package/dist/managers/hookManager.js +39 -29
- package/dist/managers/liveConfigManager.d.ts +55 -18
- package/dist/managers/liveConfigManager.d.ts.map +1 -1
- package/dist/managers/liveConfigManager.js +372 -90
- 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 +8 -16
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +52 -74
- package/dist/managers/permissionManager.d.ts +75 -0
- package/dist/managers/permissionManager.d.ts.map +1 -0
- package/dist/managers/permissionManager.js +368 -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 +0 -1
- package/dist/managers/subagentManager.d.ts +8 -23
- package/dist/managers/subagentManager.d.ts.map +1 -1
- package/dist/managers/subagentManager.js +97 -117
- 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 +3 -1
- package/dist/services/aiService.d.ts.map +1 -1
- package/dist/services/aiService.js +123 -30
- 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.map +1 -1
- package/dist/services/fileWatcher.js +5 -6
- package/dist/services/hook.d.ts +7 -124
- package/dist/services/hook.d.ts.map +1 -1
- package/dist/services/hook.js +46 -458
- package/dist/services/jsonlHandler.d.ts +24 -15
- package/dist/services/jsonlHandler.d.ts.map +1 -1
- package/dist/services/jsonlHandler.js +67 -88
- package/dist/services/memory.d.ts +0 -9
- package/dist/services/memory.d.ts.map +1 -1
- package/dist/services/memory.js +2 -49
- package/dist/services/session.d.ts +82 -33
- package/dist/services/session.d.ts.map +1 -1
- package/dist/services/session.js +275 -181
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +109 -11
- package/dist/tools/deleteFileTool.d.ts.map +1 -1
- package/dist/tools/deleteFileTool.js +25 -0
- package/dist/tools/editTool.d.ts.map +1 -1
- package/dist/tools/editTool.js +30 -6
- 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 +26 -7
- package/dist/tools/readTool.d.ts.map +1 -1
- package/dist/tools/readTool.js +111 -2
- 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 +25 -9
- package/dist/types/commands.d.ts +0 -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 +10 -0
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/environment.d.ts +41 -0
- package/dist/types/environment.d.ts.map +1 -1
- 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 +11 -2
- package/dist/types/hooks.d.ts.map +1 -1
- package/dist/types/hooks.js +1 -7
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +5 -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 +6 -11
- package/dist/types/messaging.d.ts.map +1 -1
- package/dist/types/permissions.d.ts +39 -0
- package/dist/types/permissions.d.ts.map +1 -0
- package/dist/types/permissions.js +12 -0
- package/dist/types/session.d.ts +1 -6
- package/dist/types/session.d.ts.map +1 -1
- 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 +21 -4
- package/dist/utils/bashParser.d.ts +24 -0
- package/dist/utils/bashParser.d.ts.map +1 -0
- package/dist/utils/bashParser.js +413 -0
- 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 +8 -33
- package/dist/utils/cacheControlUtils.d.ts.map +1 -1
- package/dist/utils/cacheControlUtils.js +83 -126
- package/dist/utils/constants.d.ts +0 -12
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +1 -13
- package/dist/utils/convertMessagesForAPI.d.ts +2 -1
- package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
- package/dist/utils/convertMessagesForAPI.js +33 -14
- 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 +14 -2
- package/dist/utils/fileUtils.d.ts.map +1 -1
- package/dist/utils/fileUtils.js +101 -17
- package/dist/utils/globalLogger.d.ts +0 -14
- package/dist/utils/globalLogger.d.ts.map +1 -1
- package/dist/utils/globalLogger.js +0 -16
- package/dist/utils/markdownParser.d.ts.map +1 -1
- package/dist/utils/markdownParser.js +1 -17
- package/dist/utils/messageOperations.d.ts +1 -11
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +7 -24
- package/dist/utils/pathEncoder.d.ts +4 -0
- package/dist/utils/pathEncoder.d.ts.map +1 -1
- package/dist/utils/pathEncoder.js +16 -9
- package/dist/utils/pathSafety.d.ts +10 -0
- package/dist/utils/pathSafety.d.ts.map +1 -0
- package/dist/utils/pathSafety.js +23 -0
- package/dist/utils/subagentParser.d.ts +2 -2
- package/dist/utils/subagentParser.d.ts.map +1 -1
- package/dist/utils/subagentParser.js +10 -7
- package/package.json +9 -9
- package/src/agent.ts +475 -216
- package/src/index.ts +3 -0
- package/src/managers/aiManager.ts +107 -111
- package/src/managers/backgroundBashManager.ts +4 -3
- package/src/managers/hookManager.ts +44 -39
- package/src/managers/liveConfigManager.ts +524 -138
- package/src/managers/lspManager.ts +434 -0
- package/src/managers/messageManager.ts +73 -103
- package/src/managers/permissionManager.ts +480 -0
- package/src/managers/skillManager.ts +3 -1
- package/src/managers/slashCommandManager.ts +1 -2
- package/src/managers/subagentManager.ts +116 -159
- package/src/managers/toolManager.ts +95 -3
- package/src/services/aiService.ts +207 -26
- package/src/services/configurationService.ts +762 -0
- package/src/services/fileWatcher.ts +5 -6
- package/src/services/hook.ts +50 -631
- package/src/services/jsonlHandler.ts +84 -100
- package/src/services/memory.ts +2 -59
- package/src/services/session.ts +338 -213
- package/src/tools/bashTool.ts +126 -13
- package/src/tools/deleteFileTool.ts +36 -0
- package/src/tools/editTool.ts +41 -7
- package/src/tools/lspTool.ts +760 -0
- package/src/tools/multiEditTool.ts +37 -8
- package/src/tools/readTool.ts +125 -2
- 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 +36 -10
- package/src/types/commands.ts +0 -1
- package/src/types/config.ts +5 -0
- package/src/types/configuration.ts +73 -0
- package/src/types/core.ts +11 -0
- package/src/types/environment.ts +44 -0
- package/src/types/fileSearch.ts +4 -0
- package/src/types/hooks.ts +14 -11
- package/src/types/index.ts +5 -0
- package/src/types/lsp.ts +96 -0
- package/src/types/messaging.ts +8 -13
- package/src/types/permissions.ts +52 -0
- package/src/types/session.ts +3 -8
- 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 +28 -4
- package/src/utils/bashParser.ts +444 -0
- package/src/utils/builtinSubagents.ts +71 -0
- package/src/utils/cacheControlUtils.ts +106 -171
- package/src/utils/constants.ts +1 -16
- package/src/utils/convertMessagesForAPI.ts +38 -14
- package/src/utils/fileSearch.ts +107 -0
- package/src/utils/fileUtils.ts +114 -19
- package/src/utils/globalLogger.ts +0 -17
- package/src/utils/markdownParser.ts +1 -19
- package/src/utils/messageOperations.ts +7 -35
- package/src/utils/pathEncoder.ts +24 -9
- package/src/utils/pathSafety.ts +26 -0
- package/src/utils/subagentParser.ts +11 -8
- package/dist/constants/events.d.ts +0 -28
- package/dist/constants/events.d.ts.map +0 -1
- package/dist/constants/events.js +0 -27
- package/dist/services/configurationWatcher.d.ts +0 -120
- package/dist/services/configurationWatcher.d.ts.map +0 -1
- package/dist/services/configurationWatcher.js +0 -439
- package/dist/services/memoryStore.d.ts +0 -81
- package/dist/services/memoryStore.d.ts.map +0 -1
- package/dist/services/memoryStore.js +0 -200
- package/dist/types/memoryStore.d.ts +0 -82
- package/dist/types/memoryStore.d.ts.map +0 -1
- package/dist/types/memoryStore.js +0 -7
- package/dist/utils/configResolver.d.ts +0 -65
- package/dist/utils/configResolver.d.ts.map +0 -1
- package/dist/utils/configResolver.js +0 -210
- package/src/constants/events.ts +0 -38
- package/src/services/configurationWatcher.ts +0 -622
- package/src/services/memoryStore.ts +0 -279
- package/src/types/memoryStore.ts +0 -94
- package/src/utils/configResolver.ts +0 -302
|
@@ -3,85 +3,168 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Orchestrates live configuration reload functionality including:
|
|
5
5
|
* - Hook configuration watching and reloading
|
|
6
|
-
* -
|
|
6
|
+
* - Configuration file watching for settings.json files
|
|
7
7
|
* - Coordination between file watchers and configuration updates
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import { existsSync } from "fs";
|
|
10
11
|
import type { Logger } from "../types/index.js";
|
|
11
12
|
import {
|
|
12
|
-
|
|
13
|
-
type
|
|
14
|
-
} from "../services/
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
import { configResolver } from "../utils/configResolver.js";
|
|
18
|
-
import { join } from "path";
|
|
13
|
+
FileWatcherService,
|
|
14
|
+
type FileWatchEvent,
|
|
15
|
+
} from "../services/fileWatcher.js";
|
|
16
|
+
import type { HookManager } from "./hookManager.js";
|
|
17
|
+
import type { PermissionManager } from "./permissionManager.js";
|
|
19
18
|
import {
|
|
20
|
-
getUserConfigPaths,
|
|
21
19
|
getProjectConfigPaths,
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
getUserConfigPaths,
|
|
21
|
+
} from "@/utils/configPaths.js";
|
|
22
|
+
import type { WaveConfiguration, ValidationResult } from "../types/hooks.js";
|
|
23
|
+
import { isValidHookEvent, isValidHookEventConfig } from "../types/hooks.js";
|
|
24
|
+
import { ConfigurationService } from "../services/configurationService.js";
|
|
25
|
+
import { ensureGlobalGitIgnore } from "../utils/fileUtils.js";
|
|
26
|
+
|
|
27
|
+
import type { ConfigurationLoadResult } from "../types/configuration.js";
|
|
24
28
|
|
|
25
29
|
export interface LiveConfigManagerOptions {
|
|
26
30
|
workdir: string;
|
|
27
31
|
logger?: Logger;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
changeType: "add" | "change" | "unlink",
|
|
32
|
-
) => Promise<void>; // Callback for memory store file changes
|
|
32
|
+
hookManager?: HookManager;
|
|
33
|
+
permissionManager?: PermissionManager;
|
|
34
|
+
configurationService?: ConfigurationService;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
export class LiveConfigManager {
|
|
36
38
|
private readonly workdir: string;
|
|
37
39
|
private readonly logger?: Logger;
|
|
38
|
-
private readonly
|
|
39
|
-
private readonly
|
|
40
|
-
filePath: string,
|
|
41
|
-
changeType: "add" | "change" | "unlink",
|
|
42
|
-
) => Promise<void>;
|
|
43
|
-
private configurationWatcher?: ConfigurationWatcher;
|
|
40
|
+
private readonly hookManager?: HookManager;
|
|
41
|
+
private readonly permissionManager?: PermissionManager;
|
|
44
42
|
private isInitialized: boolean = false;
|
|
43
|
+
private readonly configurationService: ConfigurationService;
|
|
44
|
+
|
|
45
|
+
// Configuration state
|
|
46
|
+
private currentConfiguration: WaveConfiguration | null = null;
|
|
47
|
+
private lastValidConfiguration: WaveConfiguration | null = null;
|
|
48
|
+
|
|
49
|
+
// File watching state
|
|
50
|
+
private fileWatcher: FileWatcherService;
|
|
51
|
+
private userConfigPaths?: string[];
|
|
52
|
+
private projectConfigPaths?: string[];
|
|
53
|
+
private isWatching: boolean = false;
|
|
54
|
+
private reloadInProgress: boolean = false;
|
|
45
55
|
|
|
46
56
|
constructor(options: LiveConfigManagerOptions) {
|
|
47
57
|
this.workdir = options.workdir;
|
|
48
58
|
this.logger = options.logger;
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
59
|
+
this.hookManager = options.hookManager;
|
|
60
|
+
this.permissionManager = options.permissionManager;
|
|
61
|
+
this.configurationService =
|
|
62
|
+
options.configurationService || new ConfigurationService();
|
|
63
|
+
this.fileWatcher = new FileWatcherService(this.logger);
|
|
64
|
+
this.setupFileWatcherEvents();
|
|
51
65
|
}
|
|
52
66
|
|
|
53
67
|
/**
|
|
54
|
-
* Initialize
|
|
68
|
+
* Initialize configuration watching
|
|
69
|
+
* Maps to FR-004: System MUST watch settings.json files
|
|
70
|
+
* Supports watching multiple file paths (e.g., settings.local.json and settings.json)
|
|
71
|
+
*/
|
|
72
|
+
private async initializeWatching(
|
|
73
|
+
userPaths: string[],
|
|
74
|
+
projectPaths?: string[],
|
|
75
|
+
): Promise<void> {
|
|
76
|
+
try {
|
|
77
|
+
this.logger?.info("Live Config: Initializing configuration watching...");
|
|
78
|
+
|
|
79
|
+
this.userConfigPaths = userPaths;
|
|
80
|
+
this.projectConfigPaths = projectPaths;
|
|
81
|
+
|
|
82
|
+
// Load initial configuration
|
|
83
|
+
await this.reloadConfiguration();
|
|
84
|
+
|
|
85
|
+
// Start watching user configs that exist
|
|
86
|
+
for (const userPath of userPaths) {
|
|
87
|
+
if (existsSync(userPath)) {
|
|
88
|
+
this.logger?.debug(
|
|
89
|
+
`Live Config: Starting to watch user config: ${userPath}`,
|
|
90
|
+
);
|
|
91
|
+
await this.fileWatcher.watchFile(userPath, (event) =>
|
|
92
|
+
this.handleFileChange(event, "user"),
|
|
93
|
+
);
|
|
94
|
+
} else {
|
|
95
|
+
this.logger?.debug(
|
|
96
|
+
`Live Config: User config file does not exist: ${userPath}`,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Start watching project configs that exist
|
|
102
|
+
if (projectPaths) {
|
|
103
|
+
for (const projectPath of projectPaths) {
|
|
104
|
+
if (existsSync(projectPath)) {
|
|
105
|
+
if (projectPath.endsWith("settings.local.json")) {
|
|
106
|
+
await ensureGlobalGitIgnore("**/.wave/settings.local.json");
|
|
107
|
+
}
|
|
108
|
+
this.logger?.debug(
|
|
109
|
+
`Live Config: Starting to watch project config: ${projectPath}`,
|
|
110
|
+
);
|
|
111
|
+
await this.fileWatcher.watchFile(projectPath, (event) =>
|
|
112
|
+
this.handleFileChange(event, "project"),
|
|
113
|
+
);
|
|
114
|
+
} else {
|
|
115
|
+
this.logger?.debug(
|
|
116
|
+
`Live Config: Project config file does not exist: ${projectPath}`,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
this.isWatching = true;
|
|
123
|
+
this.logger?.info(
|
|
124
|
+
"Live Config: Configuration watching initialized successfully",
|
|
125
|
+
);
|
|
126
|
+
} catch (error) {
|
|
127
|
+
const errorMessage = `Failed to initialize configuration watching: ${(error as Error).message}`;
|
|
128
|
+
this.logger?.error(`Live Config: ${errorMessage}`);
|
|
129
|
+
throw new Error(errorMessage);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Get current configuration
|
|
135
|
+
*/
|
|
136
|
+
getCurrentConfiguration(): WaveConfiguration | null {
|
|
137
|
+
return this.currentConfiguration ? { ...this.currentConfiguration } : null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Initialize configuration management with file watching
|
|
55
142
|
*/
|
|
56
143
|
async initialize(): Promise<void> {
|
|
57
144
|
if (this.isInitialized) {
|
|
58
|
-
this.logger?.debug("
|
|
145
|
+
this.logger?.debug("Already initialized");
|
|
59
146
|
return;
|
|
60
147
|
}
|
|
61
148
|
|
|
62
149
|
try {
|
|
63
|
-
//
|
|
64
|
-
|
|
150
|
+
// Get configuration file paths
|
|
151
|
+
const { userPaths, projectPaths } = this.getConfigurationPaths();
|
|
65
152
|
|
|
66
|
-
// Initialize
|
|
67
|
-
|
|
68
|
-
await this.initializeMemoryStoreWatching();
|
|
69
|
-
}
|
|
153
|
+
// Initialize configuration watching
|
|
154
|
+
await this.initializeWatching(userPaths, projectPaths);
|
|
70
155
|
|
|
71
156
|
this.isInitialized = true;
|
|
72
157
|
this.logger?.info(
|
|
73
|
-
"Live
|
|
158
|
+
"Live configuration management initialized with file watching",
|
|
74
159
|
);
|
|
75
160
|
} catch (error) {
|
|
76
|
-
this.logger?.error(
|
|
77
|
-
`Live Config: Failed to initialize: ${(error as Error).message}`,
|
|
78
|
-
);
|
|
161
|
+
this.logger?.error(`Failed to initialize: ${(error as Error).message}`);
|
|
79
162
|
throw error;
|
|
80
163
|
}
|
|
81
164
|
}
|
|
82
165
|
|
|
83
166
|
/**
|
|
84
|
-
* Shutdown
|
|
167
|
+
* Shutdown configuration management and cleanup resources
|
|
85
168
|
*/
|
|
86
169
|
async shutdown(): Promise<void> {
|
|
87
170
|
if (!this.isInitialized) {
|
|
@@ -89,148 +172,451 @@ export class LiveConfigManager {
|
|
|
89
172
|
}
|
|
90
173
|
|
|
91
174
|
try {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
175
|
+
this.logger?.info("Live Config: Shutting down configuration manager...");
|
|
176
|
+
|
|
177
|
+
this.isWatching = false;
|
|
178
|
+
|
|
179
|
+
// Cleanup file watcher
|
|
180
|
+
await this.fileWatcher.cleanup();
|
|
181
|
+
|
|
182
|
+
// Clean up state
|
|
183
|
+
this.currentConfiguration = null;
|
|
184
|
+
this.lastValidConfiguration = null;
|
|
96
185
|
|
|
97
186
|
this.isInitialized = false;
|
|
98
|
-
this.logger?.info(
|
|
99
|
-
"Live Config: Live configuration management shutdown completed",
|
|
100
|
-
);
|
|
187
|
+
this.logger?.info("Live configuration management shutdown completed");
|
|
101
188
|
} catch (error) {
|
|
102
|
-
this.logger?.error(
|
|
103
|
-
`Live Config: Error during shutdown: ${(error as Error).message}`,
|
|
104
|
-
);
|
|
189
|
+
this.logger?.error(`Error during shutdown: ${(error as Error).message}`);
|
|
105
190
|
throw error;
|
|
106
191
|
}
|
|
107
192
|
}
|
|
108
193
|
|
|
109
194
|
/**
|
|
110
|
-
*
|
|
195
|
+
* Reload configuration from files
|
|
196
|
+
* Maps to FR-008: Continue with previous valid configuration on errors
|
|
111
197
|
*/
|
|
112
|
-
private async
|
|
113
|
-
this.
|
|
114
|
-
this.
|
|
115
|
-
this.
|
|
116
|
-
|
|
198
|
+
private async reloadConfiguration(): Promise<WaveConfiguration> {
|
|
199
|
+
if (this.reloadInProgress) {
|
|
200
|
+
this.logger?.debug("Live Config: Reload already in progress, skipping");
|
|
201
|
+
return this.currentConfiguration || {};
|
|
202
|
+
}
|
|
117
203
|
|
|
118
|
-
|
|
119
|
-
this.configurationWatcher.on(
|
|
120
|
-
CONFIGURATION_EVENTS.CONFIGURATION_CHANGE,
|
|
121
|
-
(event: ConfigurationChangeEvent) => {
|
|
122
|
-
this.handleConfigurationChange(event);
|
|
123
|
-
},
|
|
124
|
-
);
|
|
204
|
+
this.reloadInProgress = true;
|
|
125
205
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
await this.configurationWatcher.initializeWatching(userPaths, projectPaths);
|
|
129
|
-
this.logger?.info("Live Config: Configuration watching initialized");
|
|
130
|
-
}
|
|
206
|
+
try {
|
|
207
|
+
this.logger?.debug("Live Config: Reloading configuration from files...");
|
|
131
208
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (!this.onMemoryStoreFileChanged || !this.configurationWatcher) {
|
|
137
|
-
this.logger?.debug(
|
|
138
|
-
"Live Config: Memory store callback or configuration watcher not available, skipping AGENTS.md watching",
|
|
139
|
-
);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
209
|
+
// Load merged configuration using ConfigurationService
|
|
210
|
+
const loadResult: ConfigurationLoadResult =
|
|
211
|
+
await this.configurationService.loadMergedConfiguration(this.workdir);
|
|
212
|
+
const newConfig = loadResult.configuration;
|
|
142
213
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
await this.handleMemoryStoreFileChange(event);
|
|
151
|
-
},
|
|
152
|
-
);
|
|
214
|
+
// Check for errors during loading
|
|
215
|
+
if (!loadResult.success) {
|
|
216
|
+
const errorMessage =
|
|
217
|
+
loadResult.error || "Configuration loading failed with unknown error";
|
|
218
|
+
this.logger?.error(
|
|
219
|
+
`Live Config: Configuration loading failed: ${errorMessage}`,
|
|
220
|
+
);
|
|
153
221
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
}
|
|
222
|
+
// Log warnings if any
|
|
223
|
+
if (loadResult.warnings && loadResult.warnings.length > 0) {
|
|
224
|
+
this.logger?.warn(
|
|
225
|
+
`Live Config: Configuration warnings: ${loadResult.warnings.join("; ")}`,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
162
228
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
);
|
|
229
|
+
// Use fallback configuration if available
|
|
230
|
+
if (this.lastValidConfiguration) {
|
|
231
|
+
this.logger?.info(
|
|
232
|
+
"Live Config: Using previous valid configuration due to loading errors",
|
|
233
|
+
);
|
|
234
|
+
this.currentConfiguration = this.lastValidConfiguration;
|
|
170
235
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
236
|
+
// Apply environment variables to configuration service if configured
|
|
237
|
+
if (this.lastValidConfiguration.env) {
|
|
238
|
+
this.configurationService.setEnvironmentVars(
|
|
239
|
+
this.lastValidConfiguration.env,
|
|
240
|
+
);
|
|
241
|
+
}
|
|
174
242
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
243
|
+
// Update hook manager if available
|
|
244
|
+
if (this.hookManager) {
|
|
245
|
+
this.hookManager.loadConfigurationFromWaveConfig(
|
|
246
|
+
this.lastValidConfiguration,
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return this.currentConfiguration;
|
|
251
|
+
} else {
|
|
252
|
+
this.logger?.warn(
|
|
253
|
+
"Live Config: No previous valid configuration available, using empty config",
|
|
254
|
+
);
|
|
255
|
+
this.currentConfiguration = {};
|
|
256
|
+
return this.currentConfiguration;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Log success with detailed information
|
|
261
|
+
if (newConfig) {
|
|
262
|
+
this.logger?.info(
|
|
263
|
+
`Live Config: Configuration loaded successfully from ${loadResult.sourcePath || "merged sources"}`,
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
// Log detailed configuration info
|
|
267
|
+
const hookCount = Object.keys(newConfig.hooks || {}).length;
|
|
268
|
+
const envCount = Object.keys(newConfig.env || {}).length;
|
|
269
|
+
this.logger?.debug(
|
|
270
|
+
`Live Config: Loaded ${hookCount} hook events and ${envCount} environment variables`,
|
|
271
|
+
);
|
|
272
|
+
} else {
|
|
273
|
+
this.logger?.info(
|
|
274
|
+
"Live Config: No configuration found (using empty configuration)",
|
|
183
275
|
);
|
|
184
276
|
}
|
|
185
|
-
}
|
|
186
277
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
278
|
+
// Log warnings from successful loading
|
|
279
|
+
if (loadResult.warnings && loadResult.warnings.length > 0) {
|
|
280
|
+
this.logger?.warn(
|
|
281
|
+
`Live Config: Configuration warnings: ${loadResult.warnings.join("; ")}`,
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Validate new configuration if it exists
|
|
286
|
+
if (newConfig) {
|
|
287
|
+
const validation = this.validateConfiguration(newConfig);
|
|
288
|
+
if (!validation.valid) {
|
|
289
|
+
const errorMessage = `Configuration validation failed: ${validation.errors.join(", ")}`;
|
|
290
|
+
this.logger?.error(`Live Config: ${errorMessage}`);
|
|
291
|
+
|
|
292
|
+
// Use previous valid configuration for error recovery
|
|
293
|
+
if (this.lastValidConfiguration) {
|
|
294
|
+
this.logger?.info(
|
|
295
|
+
"Live Config: Using previous valid configuration due to validation errors",
|
|
296
|
+
);
|
|
297
|
+
this.currentConfiguration = this.lastValidConfiguration;
|
|
298
|
+
|
|
299
|
+
// Apply environment variables to configuration service if configured
|
|
300
|
+
if (this.lastValidConfiguration.env) {
|
|
301
|
+
this.configurationService.setEnvironmentVars(
|
|
302
|
+
this.lastValidConfiguration.env,
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Update hook manager if available
|
|
307
|
+
if (this.hookManager) {
|
|
308
|
+
this.hookManager.loadConfigurationFromWaveConfig(
|
|
309
|
+
this.lastValidConfiguration,
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return this.currentConfiguration;
|
|
314
|
+
} else {
|
|
315
|
+
this.logger?.warn(
|
|
316
|
+
"Live Config: No previous valid configuration available, using empty config",
|
|
317
|
+
);
|
|
318
|
+
this.currentConfiguration = {};
|
|
319
|
+
return this.currentConfiguration;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Detect changes between old and new configuration
|
|
325
|
+
this.detectChanges(this.currentConfiguration, newConfig);
|
|
326
|
+
|
|
327
|
+
// Update current configuration
|
|
328
|
+
this.currentConfiguration = newConfig || {};
|
|
329
|
+
|
|
330
|
+
// Save as last valid configuration if it's valid and not empty
|
|
331
|
+
if (newConfig && (newConfig.hooks || newConfig.env)) {
|
|
332
|
+
this.lastValidConfiguration = { ...newConfig };
|
|
333
|
+
this.logger?.debug(
|
|
334
|
+
"Live Config: Saved current configuration as last valid backup",
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Note: Environment variables are already applied by loadMergedConfiguration()
|
|
339
|
+
// No need to set them again here as currentConfiguration === newConfig
|
|
340
|
+
|
|
341
|
+
// Update hook manager if available
|
|
342
|
+
if (this.hookManager) {
|
|
343
|
+
this.hookManager.loadConfigurationFromWaveConfig(
|
|
344
|
+
this.currentConfiguration,
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Update permission manager if available
|
|
349
|
+
if (this.permissionManager) {
|
|
350
|
+
if (this.currentConfiguration.defaultMode) {
|
|
351
|
+
this.permissionManager.updateConfiguredDefaultMode(
|
|
352
|
+
this.currentConfiguration.defaultMode,
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
if (this.currentConfiguration.permissions?.allow) {
|
|
356
|
+
this.permissionManager.updateAllowedRules(
|
|
357
|
+
this.currentConfiguration.permissions.allow,
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
190
362
|
this.logger?.info(
|
|
191
|
-
`Live Config: Configuration
|
|
363
|
+
`Live Config: Configuration reload completed successfully with ${Object.keys(newConfig?.hooks || {}).length} event types and ${Object.keys(newConfig?.env || {}).length} environment variables`,
|
|
192
364
|
);
|
|
365
|
+
|
|
366
|
+
return this.currentConfiguration;
|
|
367
|
+
} catch (error) {
|
|
368
|
+
const errorMessage = `Configuration reload failed with exception: ${(error as Error).message}`;
|
|
369
|
+
this.logger?.error(`Live Config: ${errorMessage}`);
|
|
370
|
+
|
|
371
|
+
// Use previous valid configuration for error recovery
|
|
372
|
+
if (this.lastValidConfiguration) {
|
|
373
|
+
this.logger?.info(
|
|
374
|
+
"Live Config: Using previous valid configuration due to reload exception",
|
|
375
|
+
);
|
|
376
|
+
this.currentConfiguration = this.lastValidConfiguration;
|
|
377
|
+
|
|
378
|
+
// Apply environment variables to configuration service if configured
|
|
379
|
+
if (this.lastValidConfiguration.env) {
|
|
380
|
+
this.configurationService.setEnvironmentVars(
|
|
381
|
+
this.lastValidConfiguration.env,
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// Update hook manager if available
|
|
386
|
+
if (this.hookManager) {
|
|
387
|
+
this.hookManager.loadConfigurationFromWaveConfig(
|
|
388
|
+
this.lastValidConfiguration,
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
} else {
|
|
392
|
+
this.logger?.warn(
|
|
393
|
+
"Live Config: No previous valid configuration available, using empty config",
|
|
394
|
+
);
|
|
395
|
+
this.currentConfiguration = {};
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return this.currentConfiguration;
|
|
399
|
+
} finally {
|
|
400
|
+
this.reloadInProgress = false;
|
|
193
401
|
}
|
|
194
402
|
}
|
|
195
403
|
|
|
196
404
|
/**
|
|
197
|
-
*
|
|
405
|
+
* Reload configuration from files (public method)
|
|
198
406
|
*/
|
|
199
|
-
|
|
407
|
+
async reload(): Promise<WaveConfiguration> {
|
|
408
|
+
this.logger?.info("Manually reloading configuration...");
|
|
409
|
+
return await this.reloadConfiguration();
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Check if watching is active
|
|
414
|
+
*/
|
|
415
|
+
isWatchingActive(): boolean {
|
|
416
|
+
return this.isWatching;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Get watcher status for monitoring
|
|
421
|
+
*/
|
|
422
|
+
getWatcherStatus() {
|
|
423
|
+
const statuses = this.fileWatcher.getAllWatcherStatuses();
|
|
424
|
+
return {
|
|
425
|
+
isActive: this.isWatching,
|
|
426
|
+
configurationLoaded: this.currentConfiguration !== null,
|
|
427
|
+
hasValidConfiguration: this.lastValidConfiguration !== null,
|
|
428
|
+
reloadInProgress: this.reloadInProgress,
|
|
429
|
+
watchedFiles: statuses.map((s) => ({
|
|
430
|
+
path: s.path,
|
|
431
|
+
isActive: s.isActive,
|
|
432
|
+
method: s.method,
|
|
433
|
+
errorCount: s.errorCount,
|
|
434
|
+
})),
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
private setupFileWatcherEvents(): void {
|
|
439
|
+
this.fileWatcher.on("watcherError", (error: Error) => {
|
|
440
|
+
this.logger?.error(`Live Config: File watcher error: ${error.message}`);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
private async handleFileChange(
|
|
200
445
|
event: FileWatchEvent,
|
|
446
|
+
source: "user" | "project",
|
|
201
447
|
): Promise<void> {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
448
|
+
this.logger?.debug(
|
|
449
|
+
`Live Config: File ${event.type} detected for ${source} config: ${event.path}`,
|
|
450
|
+
);
|
|
205
451
|
|
|
206
452
|
try {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
453
|
+
// Handle file deletion
|
|
454
|
+
if (event.type === "delete") {
|
|
455
|
+
this.logger?.info(
|
|
456
|
+
`Live Config: ${source} config file deleted: ${event.path}`,
|
|
457
|
+
);
|
|
458
|
+
// Reload configuration without the deleted file
|
|
459
|
+
await this.reloadConfiguration();
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
210
462
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
: event.type
|
|
215
|
-
|
|
216
|
-
: "change";
|
|
217
|
-
await this.onMemoryStoreFileChanged(event.path, changeType);
|
|
463
|
+
// Handle file creation or modification
|
|
464
|
+
if (event.type === "change" || event.type === "create") {
|
|
465
|
+
this.logger?.info(
|
|
466
|
+
`Live Config: ${source} config file ${event.type}: ${event.path}`,
|
|
467
|
+
);
|
|
218
468
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
469
|
+
if (
|
|
470
|
+
source === "project" &&
|
|
471
|
+
event.path.endsWith("settings.local.json") &&
|
|
472
|
+
event.type === "create"
|
|
473
|
+
) {
|
|
474
|
+
await ensureGlobalGitIgnore("**/.wave/settings.local.json");
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// Add small delay to ensure file write is complete
|
|
478
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
479
|
+
|
|
480
|
+
// Reload configuration
|
|
481
|
+
await this.reloadConfiguration();
|
|
482
|
+
}
|
|
222
483
|
} catch (error) {
|
|
223
484
|
this.logger?.error(
|
|
224
|
-
`Live Config:
|
|
485
|
+
`Live Config: Error handling file change for ${source} config: ${(error as Error).message}`,
|
|
225
486
|
);
|
|
226
487
|
}
|
|
227
488
|
}
|
|
228
489
|
|
|
229
490
|
/**
|
|
230
|
-
*
|
|
491
|
+
* Validate configuration structure and content
|
|
231
492
|
*/
|
|
232
|
-
|
|
233
|
-
|
|
493
|
+
private validateConfiguration(config: WaveConfiguration): ValidationResult {
|
|
494
|
+
const errors: string[] = [];
|
|
495
|
+
|
|
496
|
+
if (!config || typeof config !== "object") {
|
|
497
|
+
return { valid: false, errors: ["Configuration must be an object"] };
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// Validate defaultMode if present
|
|
501
|
+
if (config.defaultMode !== undefined) {
|
|
502
|
+
if (
|
|
503
|
+
config.defaultMode !== "default" &&
|
|
504
|
+
config.defaultMode !== "bypassPermissions" &&
|
|
505
|
+
config.defaultMode !== "acceptEdits"
|
|
506
|
+
) {
|
|
507
|
+
errors.push(
|
|
508
|
+
`Invalid defaultMode: "${config.defaultMode}". Must be "default", "bypassPermissions" or "acceptEdits"`,
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// Validate hooks if present
|
|
514
|
+
if (config.hooks) {
|
|
515
|
+
if (typeof config.hooks !== "object") {
|
|
516
|
+
errors.push("hooks property must be an object");
|
|
517
|
+
} else {
|
|
518
|
+
// Validate each hook event
|
|
519
|
+
for (const [eventName, eventConfigs] of Object.entries(config.hooks)) {
|
|
520
|
+
// Validate event name
|
|
521
|
+
if (!isValidHookEvent(eventName)) {
|
|
522
|
+
errors.push(`Invalid hook event: ${eventName}`);
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// Validate event configurations
|
|
527
|
+
if (!Array.isArray(eventConfigs)) {
|
|
528
|
+
errors.push(
|
|
529
|
+
`Hook event ${eventName} must be an array of configurations`,
|
|
530
|
+
);
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
eventConfigs.forEach((eventConfig, index) => {
|
|
535
|
+
if (!isValidHookEventConfig(eventConfig)) {
|
|
536
|
+
errors.push(
|
|
537
|
+
`Invalid hook event configuration at ${eventName}[${index}]`,
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// Validate environment variables if present
|
|
546
|
+
if (config.env) {
|
|
547
|
+
if (typeof config.env !== "object" || Array.isArray(config.env)) {
|
|
548
|
+
errors.push("env property must be an object");
|
|
549
|
+
} else {
|
|
550
|
+
for (const [key, value] of Object.entries(config.env)) {
|
|
551
|
+
if (typeof key !== "string" || key.trim() === "") {
|
|
552
|
+
errors.push(`Invalid environment variable key: ${key}`);
|
|
553
|
+
}
|
|
554
|
+
if (typeof value !== "string") {
|
|
555
|
+
errors.push(`Environment variable ${key} must have a string value`);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
return {
|
|
562
|
+
valid: errors.length === 0,
|
|
563
|
+
errors,
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
private detectChanges(
|
|
568
|
+
oldConfig: WaveConfiguration | null,
|
|
569
|
+
newConfig: WaveConfiguration | null,
|
|
570
|
+
): {
|
|
571
|
+
added: string[];
|
|
572
|
+
modified: string[];
|
|
573
|
+
removed: string[];
|
|
574
|
+
} {
|
|
575
|
+
const added: string[] = [];
|
|
576
|
+
const modified: string[] = [];
|
|
577
|
+
const removed: string[] = [];
|
|
578
|
+
|
|
579
|
+
// Handle environment variables changes
|
|
580
|
+
const oldEnv = oldConfig?.env || {};
|
|
581
|
+
const newEnv = newConfig?.env || {};
|
|
582
|
+
|
|
583
|
+
for (const key of Object.keys(newEnv)) {
|
|
584
|
+
if (!(key in oldEnv)) {
|
|
585
|
+
added.push(`env.${key}`);
|
|
586
|
+
} else if (oldEnv[key] !== newEnv[key]) {
|
|
587
|
+
modified.push(`env.${key}`);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
for (const key of Object.keys(oldEnv)) {
|
|
592
|
+
if (!(key in newEnv)) {
|
|
593
|
+
removed.push(`env.${key}`);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// Handle hooks changes (simplified)
|
|
598
|
+
const oldHooks = oldConfig?.hooks || {};
|
|
599
|
+
const newHooks = newConfig?.hooks || {};
|
|
600
|
+
|
|
601
|
+
for (const event of Object.keys(newHooks)) {
|
|
602
|
+
if (isValidHookEvent(event)) {
|
|
603
|
+
if (!(event in oldHooks)) {
|
|
604
|
+
added.push(`hooks.${event}`);
|
|
605
|
+
} else if (
|
|
606
|
+
JSON.stringify(oldHooks[event]) !== JSON.stringify(newHooks[event])
|
|
607
|
+
) {
|
|
608
|
+
modified.push(`hooks.${event}`);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
for (const event of Object.keys(oldHooks)) {
|
|
614
|
+
if (isValidHookEvent(event) && !(event in newHooks)) {
|
|
615
|
+
removed.push(`hooks.${event}`);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
return { added, modified, removed };
|
|
234
620
|
}
|
|
235
621
|
|
|
236
622
|
/**
|