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
package/dist/index.d.ts
CHANGED
|
@@ -3,10 +3,13 @@ export * from "./services/memory.js";
|
|
|
3
3
|
export * from "./services/session.js";
|
|
4
4
|
export * from "./services/hook.js";
|
|
5
5
|
export * from "./services/jsonlHandler.js";
|
|
6
|
+
export * from "./services/configurationService.js";
|
|
6
7
|
export * from "./agent.js";
|
|
7
8
|
export * from "./utils/bashHistory.js";
|
|
9
|
+
export * from "./utils/bashParser.js";
|
|
8
10
|
export * from "./utils/convertMessagesForAPI.js";
|
|
9
11
|
export * from "./utils/fileFilter.js";
|
|
12
|
+
export * from "./utils/fileSearch.js";
|
|
10
13
|
export * from "./utils/globalLogger.js";
|
|
11
14
|
export * from "./utils/mcpUtils.js";
|
|
12
15
|
export * from "./utils/messageOperations.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AAGnD,cAAc,YAAY,CAAC;AAG3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AAGvC,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,12 +4,15 @@ export * from "./services/memory.js";
|
|
|
4
4
|
export * from "./services/session.js";
|
|
5
5
|
export * from "./services/hook.js";
|
|
6
6
|
export * from "./services/jsonlHandler.js";
|
|
7
|
+
export * from "./services/configurationService.js"; // New configuration management service
|
|
7
8
|
// Export main agent
|
|
8
9
|
export * from "./agent.js";
|
|
9
10
|
// Export all utilities
|
|
10
11
|
export * from "./utils/bashHistory.js";
|
|
12
|
+
export * from "./utils/bashParser.js";
|
|
11
13
|
export * from "./utils/convertMessagesForAPI.js";
|
|
12
14
|
export * from "./utils/fileFilter.js";
|
|
15
|
+
export * from "./utils/fileSearch.js";
|
|
13
16
|
export * from "./utils/globalLogger.js";
|
|
14
17
|
export * from "./utils/mcpUtils.js";
|
|
15
18
|
export * from "./utils/messageOperations.js";
|
|
@@ -17,9 +17,12 @@ export interface AIManagerOptions {
|
|
|
17
17
|
workdir: string;
|
|
18
18
|
systemPrompt?: string;
|
|
19
19
|
subagentType?: string;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
/**Whether to use streaming mode for AI responses - defaults to true */
|
|
21
|
+
stream?: boolean;
|
|
22
|
+
getGatewayConfig: () => GatewayConfig;
|
|
23
|
+
getModelConfig: () => ModelConfig;
|
|
24
|
+
getTokenLimit: () => number;
|
|
25
|
+
getEnvironmentVars?: () => Record<string, string>;
|
|
23
26
|
}
|
|
24
27
|
export declare class AIManager {
|
|
25
28
|
isLoading: boolean;
|
|
@@ -33,42 +36,17 @@ export declare class AIManager {
|
|
|
33
36
|
private workdir;
|
|
34
37
|
private systemPrompt?;
|
|
35
38
|
private subagentType?;
|
|
36
|
-
private
|
|
37
|
-
private
|
|
38
|
-
private
|
|
39
|
+
private stream;
|
|
40
|
+
private getGatewayConfigFn;
|
|
41
|
+
private getModelConfigFn;
|
|
42
|
+
private getTokenLimitFn;
|
|
43
|
+
private getEnvironmentVarsFn?;
|
|
39
44
|
constructor(options: AIManagerOptions);
|
|
45
|
+
getGatewayConfig(): GatewayConfig;
|
|
46
|
+
getModelConfig(): ModelConfig;
|
|
47
|
+
getTokenLimit(): number;
|
|
40
48
|
private isCompressing;
|
|
41
49
|
private callbacks;
|
|
42
|
-
/**
|
|
43
|
-
* Update gateway configuration at runtime for live config reload
|
|
44
|
-
* @param newConfig - New gateway configuration
|
|
45
|
-
*/
|
|
46
|
-
updateGatewayConfig(newConfig: GatewayConfig): void;
|
|
47
|
-
/**
|
|
48
|
-
* Update model configuration at runtime for live config reload
|
|
49
|
-
* @param newConfig - New model configuration
|
|
50
|
-
*/
|
|
51
|
-
updateModelConfig(newConfig: ModelConfig): void;
|
|
52
|
-
/**
|
|
53
|
-
* Update token limit at runtime for live config reload
|
|
54
|
-
* @param newLimit - New token limit
|
|
55
|
-
*/
|
|
56
|
-
updateTokenLimit(newLimit: number): void;
|
|
57
|
-
/**
|
|
58
|
-
* Update all configurations at once for live config reload
|
|
59
|
-
* @param newGatewayConfig - New gateway configuration
|
|
60
|
-
* @param newModelConfig - New model configuration
|
|
61
|
-
* @param newTokenLimit - New token limit
|
|
62
|
-
*/
|
|
63
|
-
updateConfiguration(newGatewayConfig: GatewayConfig, newModelConfig: ModelConfig, newTokenLimit: number): void;
|
|
64
|
-
/**
|
|
65
|
-
* Get current configuration for debugging
|
|
66
|
-
*/
|
|
67
|
-
getCurrentConfiguration(): {
|
|
68
|
-
gatewayConfig: GatewayConfig;
|
|
69
|
-
modelConfig: ModelConfig;
|
|
70
|
-
tokenLimit: number;
|
|
71
|
-
};
|
|
72
50
|
/**
|
|
73
51
|
* Get filtered tool configuration
|
|
74
52
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiManager.d.ts","sourceRoot":"","sources":["../../src/managers/aiManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aiManager.d.ts","sourceRoot":"","sources":["../../src/managers/aiManager.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,MAAM,EACN,aAAa,EACb,WAAW,EACX,KAAK,EACN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,MAAM,WAAW,kBAAkB;IACjC,wBAAwB,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,KAAK,IAAI,CAAC;IAC5D,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACvC;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,cAAc,CAAC;IAC/B,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAC9C,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,gBAAgB,EAAE,MAAM,aAAa,CAAC;IACtC,cAAc,EAAE,MAAM,WAAW,CAAC;IAClC,aAAa,EAAE,MAAM,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnD;AAED,qBAAa,SAAS;IACb,SAAS,EAAE,OAAO,CAAS;IAClC,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,mBAAmB,CAAgC;IAC3D,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,qBAAqB,CAAC,CAAwB;IACtD,OAAO,CAAC,WAAW,CAAC,CAAc;IAClC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAAC,CAAS;IAC9B,OAAO,CAAC,YAAY,CAAC,CAAS;IAC9B,OAAO,CAAC,MAAM,CAAU;IAGxB,OAAO,CAAC,kBAAkB,CAAsB;IAChD,OAAO,CAAC,gBAAgB,CAAoB;IAC5C,OAAO,CAAC,eAAe,CAAe;IACtC,OAAO,CAAC,oBAAoB,CAAC,CAA+B;gBAEhD,OAAO,EAAE,gBAAgB;IAoB9B,gBAAgB,IAAI,aAAa;IAIjC,cAAc,IAAI,WAAW;IAI7B,aAAa,IAAI,MAAM;IAI9B,OAAO,CAAC,aAAa,CAAkB;IACvC,OAAO,CAAC,SAAS,CAAqB;IAEtC;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAYvB,YAAY,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI;IAItC,cAAc,IAAI,IAAI;IAuB7B,OAAO,CAAC,qBAAqB;YAqBf,8BAA8B;IA+ErC,gBAAgB,IAAI,OAAO;IAI3B,gBAAgB,CAAC,aAAa,EAAE,OAAO,GAAG,IAAI;IAOxC,aAAa,CACxB,OAAO,GAAE;QACP,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;KACpB,GACL,OAAO,CAAC,IAAI,CAAC;IA2YhB;;;;OAIG;YACW,gBAAgB;IAiE9B;;;OAGG;YACW,sBAAsB;IA6DpC;;OAEG;YACW,uBAAuB;CAwDtC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { callAgent, compressMessages } from "../services/aiService.js";
|
|
1
|
+
import { callAgent, compressMessages, } from "../services/aiService.js";
|
|
2
2
|
import { getMessagesToCompress } from "../utils/messageOperations.js";
|
|
3
3
|
import { convertMessagesForAPI } from "../utils/convertMessagesForAPI.js";
|
|
4
4
|
import { calculateComprehensiveTotalTokens } from "../utils/tokenCalculation.js";
|
|
@@ -17,58 +17,23 @@ export class AIManager {
|
|
|
17
17
|
this.workdir = options.workdir;
|
|
18
18
|
this.systemPrompt = options.systemPrompt;
|
|
19
19
|
this.subagentType = options.subagentType; // Store subagent type
|
|
20
|
+
this.stream = options.stream ?? true; // Default to true if not specified
|
|
20
21
|
this.callbacks = options.callbacks ?? {};
|
|
21
|
-
// Store
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
22
|
+
// Store configuration getter functions for dynamic resolution
|
|
23
|
+
this.getGatewayConfigFn = options.getGatewayConfig;
|
|
24
|
+
this.getModelConfigFn = options.getModelConfig;
|
|
25
|
+
this.getTokenLimitFn = options.getTokenLimit;
|
|
26
|
+
this.getEnvironmentVarsFn = options.getEnvironmentVars;
|
|
25
27
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*/
|
|
30
|
-
updateGatewayConfig(newConfig) {
|
|
31
|
-
this.logger?.info(`Live Config: Updating AIManager gateway config - baseURL: ${newConfig.baseURL}`);
|
|
32
|
-
this.gatewayConfig = newConfig;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Update model configuration at runtime for live config reload
|
|
36
|
-
* @param newConfig - New model configuration
|
|
37
|
-
*/
|
|
38
|
-
updateModelConfig(newConfig) {
|
|
39
|
-
this.logger?.info(`Live Config: Updating AIManager model config - agent: ${newConfig.agentModel}, fast: ${newConfig.fastModel}`);
|
|
40
|
-
this.modelConfig = newConfig;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Update token limit at runtime for live config reload
|
|
44
|
-
* @param newLimit - New token limit
|
|
45
|
-
*/
|
|
46
|
-
updateTokenLimit(newLimit) {
|
|
47
|
-
this.logger?.info(`Live Config: Updating AIManager token limit: ${newLimit}`);
|
|
48
|
-
this.tokenLimit = newLimit;
|
|
28
|
+
// Getter methods for accessing dynamic configuration
|
|
29
|
+
getGatewayConfig() {
|
|
30
|
+
return this.getGatewayConfigFn();
|
|
49
31
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
* @param newGatewayConfig - New gateway configuration
|
|
53
|
-
* @param newModelConfig - New model configuration
|
|
54
|
-
* @param newTokenLimit - New token limit
|
|
55
|
-
*/
|
|
56
|
-
updateConfiguration(newGatewayConfig, newModelConfig, newTokenLimit) {
|
|
57
|
-
this.logger?.info("Live Config: Updating all AIManager configuration");
|
|
58
|
-
this.gatewayConfig = newGatewayConfig;
|
|
59
|
-
this.modelConfig = newModelConfig;
|
|
60
|
-
this.tokenLimit = newTokenLimit;
|
|
61
|
-
this.logger?.info(`Live Config: Configuration updated - model: ${newModelConfig.agentModel}, tokenLimit: ${newTokenLimit}`);
|
|
32
|
+
getModelConfig() {
|
|
33
|
+
return this.getModelConfigFn();
|
|
62
34
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*/
|
|
66
|
-
getCurrentConfiguration() {
|
|
67
|
-
return {
|
|
68
|
-
gatewayConfig: { ...this.gatewayConfig },
|
|
69
|
-
modelConfig: { ...this.modelConfig },
|
|
70
|
-
tokenLimit: this.tokenLimit,
|
|
71
|
-
};
|
|
35
|
+
getTokenLimit() {
|
|
36
|
+
return this.getTokenLimitFn();
|
|
72
37
|
}
|
|
73
38
|
/**
|
|
74
39
|
* Get filtered tool configuration
|
|
@@ -135,8 +100,8 @@ export class AIManager {
|
|
|
135
100
|
if (usage.total_tokens +
|
|
136
101
|
(usage.cache_read_input_tokens || 0) +
|
|
137
102
|
(usage.cache_creation_input_tokens || 0) >
|
|
138
|
-
this.
|
|
139
|
-
this.logger?.debug(`Token usage exceeded ${this.
|
|
103
|
+
this.getTokenLimit()) {
|
|
104
|
+
this.logger?.debug(`Token usage exceeded ${this.getTokenLimit()}, compressing messages...`);
|
|
140
105
|
// Check if messages need compression
|
|
141
106
|
const { messagesToCompress, insertIndex } = getMessagesToCompress(this.messageManager.getMessages(), 7);
|
|
142
107
|
// If there are messages to compress, perform compression
|
|
@@ -147,8 +112,8 @@ export class AIManager {
|
|
|
147
112
|
this.setIsCompressing(true);
|
|
148
113
|
try {
|
|
149
114
|
const compressionResult = await compressMessages({
|
|
150
|
-
gatewayConfig: this.
|
|
151
|
-
modelConfig: this.
|
|
115
|
+
gatewayConfig: this.getGatewayConfig(),
|
|
116
|
+
modelConfig: this.getModelConfig(),
|
|
152
117
|
messages: recentChatMessages,
|
|
153
118
|
abortSignal: abortController.signal,
|
|
154
119
|
});
|
|
@@ -159,7 +124,7 @@ export class AIManager {
|
|
|
159
124
|
prompt_tokens: compressionResult.usage.prompt_tokens,
|
|
160
125
|
completion_tokens: compressionResult.usage.completion_tokens,
|
|
161
126
|
total_tokens: compressionResult.usage.total_tokens,
|
|
162
|
-
model: this.
|
|
127
|
+
model: this.getModelConfig().fastModel,
|
|
163
128
|
operation_type: "compress",
|
|
164
129
|
};
|
|
165
130
|
}
|
|
@@ -222,12 +187,13 @@ export class AIManager {
|
|
|
222
187
|
try {
|
|
223
188
|
// Get combined memory content
|
|
224
189
|
const combinedMemory = await memory.getCombinedMemoryContent(this.workdir);
|
|
225
|
-
//
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
190
|
+
// Track if assistant message has been created
|
|
191
|
+
let assistantMessageCreated = false;
|
|
192
|
+
this.logger?.debug("modelConfig in sendAIMessage", this.getModelConfig());
|
|
193
|
+
// Call AI service with streaming callbacks if enabled
|
|
194
|
+
const callAgentOptions = {
|
|
195
|
+
gatewayConfig: this.getGatewayConfig(),
|
|
196
|
+
modelConfig: this.getModelConfig(),
|
|
231
197
|
messages: recentMessages,
|
|
232
198
|
sessionId: this.messageManager.getSessionId(),
|
|
233
199
|
abortSignal: abortController.signal,
|
|
@@ -236,14 +202,25 @@ export class AIManager {
|
|
|
236
202
|
tools: this.getFilteredToolsConfig(allowedTools), // Pass filtered tool configuration
|
|
237
203
|
model: model, // Use passed model
|
|
238
204
|
systemPrompt: this.systemPrompt, // Pass custom system prompt
|
|
239
|
-
|
|
240
|
-
|
|
205
|
+
};
|
|
206
|
+
// Add streaming callbacks only if streaming is enabled
|
|
207
|
+
if (this.stream) {
|
|
208
|
+
callAgentOptions.onContentUpdate = (content) => {
|
|
209
|
+
// Create assistant message on first chunk if not already created
|
|
210
|
+
if (!assistantMessageCreated) {
|
|
211
|
+
this.messageManager.addAssistantMessage();
|
|
212
|
+
assistantMessageCreated = true;
|
|
213
|
+
}
|
|
241
214
|
this.messageManager.updateCurrentMessageContent(content);
|
|
242
|
-
}
|
|
243
|
-
onToolUpdate
|
|
215
|
+
};
|
|
216
|
+
callAgentOptions.onToolUpdate = (toolCall) => {
|
|
217
|
+
// Create assistant message on first tool update if not already created
|
|
218
|
+
if (!assistantMessageCreated) {
|
|
219
|
+
this.messageManager.addAssistantMessage();
|
|
220
|
+
assistantMessageCreated = true;
|
|
221
|
+
}
|
|
244
222
|
// Use parametersChunk as compact param for better performance
|
|
245
223
|
// No need to extract params or generate compact params during streaming
|
|
246
|
-
this.logger?.debug("Tool streaming update:", toolCall);
|
|
247
224
|
// Update tool block with streaming parameters using parametersChunk as compact param
|
|
248
225
|
this.messageManager.updateToolBlock({
|
|
249
226
|
id: toolCall.id,
|
|
@@ -253,8 +230,26 @@ export class AIManager {
|
|
|
253
230
|
compactParams: toolCall.parameters?.split("\n").pop()?.slice(-30),
|
|
254
231
|
stage: toolCall.stage || "streaming", // Default to streaming if stage not provided
|
|
255
232
|
});
|
|
256
|
-
}
|
|
257
|
-
|
|
233
|
+
};
|
|
234
|
+
callAgentOptions.onReasoningUpdate = (reasoning) => {
|
|
235
|
+
// Create assistant message on first reasoning update if not already created
|
|
236
|
+
if (!assistantMessageCreated) {
|
|
237
|
+
this.messageManager.addAssistantMessage();
|
|
238
|
+
assistantMessageCreated = true;
|
|
239
|
+
}
|
|
240
|
+
this.messageManager.updateCurrentMessageReasoning(reasoning);
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
const result = await callAgent(callAgentOptions);
|
|
244
|
+
const createdByStreaming = assistantMessageCreated;
|
|
245
|
+
// For non-streaming mode, create assistant message after callAgent returns
|
|
246
|
+
// Also create if streaming mode but no streaming callbacks were called (e.g., when content comes directly in result)
|
|
247
|
+
if (!this.stream ||
|
|
248
|
+
(!assistantMessageCreated &&
|
|
249
|
+
(result.content || result.tool_calls || result.reasoning_content))) {
|
|
250
|
+
this.messageManager.addAssistantMessage();
|
|
251
|
+
assistantMessageCreated = true;
|
|
252
|
+
}
|
|
258
253
|
// Log finish reason and response headers if available
|
|
259
254
|
if (result.finish_reason) {
|
|
260
255
|
this.logger?.debug(`AI response finished with reason: ${result.finish_reason}`);
|
|
@@ -263,11 +258,16 @@ export class AIManager {
|
|
|
263
258
|
Object.keys(result.response_headers).length > 0) {
|
|
264
259
|
this.logger?.debug("AI response headers:", result.response_headers);
|
|
265
260
|
}
|
|
266
|
-
if (result.
|
|
267
|
-
|
|
261
|
+
if (result.additionalFields &&
|
|
262
|
+
Object.keys(result.additionalFields).length > 0) {
|
|
263
|
+
this.messageManager.mergeAssistantAdditionalFields(result.additionalFields);
|
|
264
|
+
}
|
|
265
|
+
// Handle result reasoning content from non-streaming mode
|
|
266
|
+
if (result.reasoning_content && !createdByStreaming) {
|
|
267
|
+
this.messageManager.updateCurrentMessageReasoning(result.reasoning_content);
|
|
268
268
|
}
|
|
269
269
|
// Handle result content from non-streaming mode
|
|
270
|
-
if (result.content) {
|
|
270
|
+
if (result.content && !createdByStreaming) {
|
|
271
271
|
this.messageManager.updateCurrentMessageContent(result.content);
|
|
272
272
|
}
|
|
273
273
|
// Handle usage tracking for agent operations
|
|
@@ -277,7 +277,7 @@ export class AIManager {
|
|
|
277
277
|
prompt_tokens: result.usage.prompt_tokens,
|
|
278
278
|
completion_tokens: result.usage.completion_tokens,
|
|
279
279
|
total_tokens: result.usage.total_tokens,
|
|
280
|
-
model: model || this.
|
|
280
|
+
model: model || this.getModelConfig().agentModel,
|
|
281
281
|
operation_type: "agent",
|
|
282
282
|
// Preserve cache fields if present
|
|
283
283
|
...(result.usage.cache_read_input_tokens !== undefined && {
|
|
@@ -390,12 +390,6 @@ export class AIManager {
|
|
|
390
390
|
name: toolName,
|
|
391
391
|
shortResult: toolResult.shortResult,
|
|
392
392
|
});
|
|
393
|
-
// If tool returns diff information, add diff block
|
|
394
|
-
if (toolResult.success &&
|
|
395
|
-
toolResult.diffResult &&
|
|
396
|
-
toolResult.filePath) {
|
|
397
|
-
this.messageManager.addDiffBlock(toolResult.filePath, toolResult.diffResult);
|
|
398
|
-
}
|
|
399
393
|
// Execute PostToolUse hooks after successful tool completion
|
|
400
394
|
await this.executePostToolUseHooks(toolId, toolName, toolArgs, toolResult);
|
|
401
395
|
}
|
|
@@ -487,6 +481,7 @@ export class AIManager {
|
|
|
487
481
|
cwd: this.workdir,
|
|
488
482
|
subagentType: this.subagentType, // Include subagent type in hook context
|
|
489
483
|
// Stop hooks don't need toolName, toolInput, toolResponse, or userPrompt
|
|
484
|
+
env: this.getEnvironmentVarsFn?.() || {}, // Include configuration environment variables
|
|
490
485
|
};
|
|
491
486
|
const results = await this.hookManager.executeHooks(hookName, context);
|
|
492
487
|
// Process hook results to handle exit codes and appropriate responses
|
|
@@ -535,6 +530,7 @@ export class AIManager {
|
|
|
535
530
|
cwd: this.workdir,
|
|
536
531
|
toolInput,
|
|
537
532
|
subagentType: this.subagentType, // Include subagent type in hook context
|
|
533
|
+
env: this.getEnvironmentVarsFn?.() || {}, // Include configuration environment variables
|
|
538
534
|
};
|
|
539
535
|
const results = await this.hookManager.executeHooks("PreToolUse", context);
|
|
540
536
|
// Process hook results to handle exit codes and determine if tool should be blocked
|
|
@@ -580,6 +576,7 @@ export class AIManager {
|
|
|
580
576
|
toolInput,
|
|
581
577
|
toolResponse,
|
|
582
578
|
subagentType: this.subagentType, // Include subagent type in hook context
|
|
579
|
+
env: this.getEnvironmentVarsFn?.() || {}, // Include configuration environment variables
|
|
583
580
|
};
|
|
584
581
|
const results = await this.hookManager.executeHooks("PostToolUse", context);
|
|
585
582
|
// Process hook results to handle exit codes and update tool results
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backgroundBashManager.d.ts","sourceRoot":"","sources":["../../src/managers/backgroundBashManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"backgroundBashManager.d.ts","sourceRoot":"","sources":["../../src/managers/backgroundBashManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,WAAW,8BAA8B;IAC7C,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;CACtD;AAED,MAAM,WAAW,4BAA4B;IAC3C,SAAS,CAAC,EAAE,8BAA8B,CAAC;IAC3C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAsC;IACpD,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,SAAS,CAAiC;IAClD,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,4BAA4B;IAKjD,OAAO,CAAC,kBAAkB;IAInB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;IAsErD,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAIjD,YAAY,IAAI,eAAe,EAAE;IAIjC,SAAS,CACd,EAAE,EAAE,MAAM,EACV,MAAM,CAAC,EAAE,MAAM,GACd;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAiCrD,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAmD9B,OAAO,IAAI,IAAI;CAUvB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
2
|
import { logger } from "../utils/globalLogger.js";
|
|
3
|
+
import { stripAnsiColors } from "../utils/stringUtils.js";
|
|
3
4
|
export class BackgroundBashManager {
|
|
4
5
|
constructor(options) {
|
|
5
6
|
this.shells = new Map();
|
|
@@ -42,11 +43,11 @@ export class BackgroundBashManager {
|
|
|
42
43
|
}, timeout);
|
|
43
44
|
}
|
|
44
45
|
child.stdout?.on("data", (data) => {
|
|
45
|
-
shell.stdout += data.toString();
|
|
46
|
+
shell.stdout += stripAnsiColors(data.toString());
|
|
46
47
|
this.notifyShellsChange();
|
|
47
48
|
});
|
|
48
49
|
child.stderr?.on("data", (data) => {
|
|
49
|
-
shell.stderr += data.toString();
|
|
50
|
+
shell.stderr += stripAnsiColors(data.toString());
|
|
50
51
|
this.notifyShellsChange();
|
|
51
52
|
});
|
|
52
53
|
child.on("exit", (code) => {
|
|
@@ -63,7 +64,7 @@ export class BackgroundBashManager {
|
|
|
63
64
|
clearTimeout(timeoutHandle);
|
|
64
65
|
}
|
|
65
66
|
shell.status = "completed";
|
|
66
|
-
shell.stderr += `\nProcess error: ${error.message}`;
|
|
67
|
+
shell.stderr += `\nProcess error: ${stripAnsiColors(error.message)}`;
|
|
67
68
|
shell.exitCode = 1;
|
|
68
69
|
shell.runtime = Date.now() - startTime;
|
|
69
70
|
this.notifyShellsChange();
|
|
@@ -10,7 +10,6 @@ import type { Logger } from "../types/index.js";
|
|
|
10
10
|
import type { MessageManager } from "./messageManager.js";
|
|
11
11
|
export declare class HookManager {
|
|
12
12
|
private configuration;
|
|
13
|
-
private environmentVars;
|
|
14
13
|
private readonly matcher;
|
|
15
14
|
private readonly logger?;
|
|
16
15
|
private readonly workdir;
|
|
@@ -21,10 +20,10 @@ export declare class HookManager {
|
|
|
21
20
|
*/
|
|
22
21
|
loadConfiguration(userHooks?: PartialHookConfiguration, projectHooks?: PartialHookConfiguration): void;
|
|
23
22
|
/**
|
|
24
|
-
* Load configuration from
|
|
25
|
-
*
|
|
23
|
+
* Load hooks configuration from a pre-loaded WaveConfiguration
|
|
24
|
+
* Configuration loading is now handled by ConfigurationService
|
|
26
25
|
*/
|
|
27
|
-
|
|
26
|
+
loadConfigurationFromWaveConfig(waveConfig: WaveConfiguration | null): void;
|
|
28
27
|
/**
|
|
29
28
|
* Execute hooks for a specific event
|
|
30
29
|
*/
|
|
@@ -65,10 +64,6 @@ export declare class HookManager {
|
|
|
65
64
|
* Get current configuration
|
|
66
65
|
*/
|
|
67
66
|
getConfiguration(): PartialHookConfiguration | undefined;
|
|
68
|
-
/**
|
|
69
|
-
* Get current environment variables
|
|
70
|
-
*/
|
|
71
|
-
getEnvironmentVars(): Record<string, string> | undefined;
|
|
72
67
|
/**
|
|
73
68
|
* Clear current configuration
|
|
74
69
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hookManager.d.ts","sourceRoot":"","sources":["../../src/managers/hookManager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,KAAK,SAAS,EAEd,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,4BAA4B,EACjC,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EAItB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"hookManager.d.ts","sourceRoot":"","sources":["../../src/managers/hookManager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,KAAK,SAAS,EAEd,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,4BAA4B,EACjC,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EAItB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,qBAAa,WAAW;IACtB,OAAO,CAAC,aAAa,CAAuC;IAC5D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAG/B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,WAA+B,EACxC,MAAM,CAAC,EAAE,MAAM;IAOjB;;;OAGG;IACH,iBAAiB,CACf,SAAS,CAAC,EAAE,wBAAwB,EACpC,YAAY,CAAC,EAAE,wBAAwB,GACtC,IAAI;IAyBP;;;OAGG;IACH,+BAA+B,CAAC,UAAU,EAAE,iBAAiB,GAAG,IAAI,GAAG,IAAI;IAqC3E;;OAEG;IACG,YAAY,CAChB,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,oBAAoB,GAAG,4BAA4B,GAC3D,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAyHjC;;;OAGG;IACH,kBAAkB,CAChB,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,mBAAmB,EAAE,EAC9B,cAAc,CAAC,EAAE,cAAc,EAC/B,MAAM,CAAC,EAAE,MAAM,EACf,cAAc,CAAC,EAAE,MAAM,GACtB;QACD,WAAW,EAAE,OAAO,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB;IAuCD;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAezB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAsE3B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAQ9B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO;IAWtD;;OAEG;IACH,qBAAqB,CAAC,MAAM,EAAE,iBAAiB,GAAG,gBAAgB;IA8DlE;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAyCpC;;OAEG;IACH,gBAAgB,IAAI,wBAAwB,GAAG,SAAS;IAOxD;;OAEG;IACH,kBAAkB,IAAI,IAAI;IAI1B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAsDhC;;OAEG;IACH,OAAO,CAAC,wBAAwB;IA8BhC;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAa/B;;OAEG;IACH,OAAO,CAAC,aAAa;IAiCrB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA2C3B;;OAEG;IACH,qBAAqB,IAAI;QACvB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,aAAa,EAAE,MAAM,CAAC;QACtB,cAAc,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;KAC3C;CA+CF"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { HookConfigurationError, isValidHookEvent, isValidHookEventConfig, } from "../types/hooks.js";
|
|
8
8
|
import { HookMatcher } from "../utils/hookMatcher.js";
|
|
9
|
-
import { executeCommand, isCommandSafe
|
|
9
|
+
import { executeCommand, isCommandSafe } from "../services/hook.js";
|
|
10
10
|
import { MessageSource } from "../types/index.js";
|
|
11
11
|
export class HookManager {
|
|
12
12
|
constructor(workdir, matcher = new HookMatcher(), logger) {
|
|
@@ -36,35 +36,31 @@ export class HookManager {
|
|
|
36
36
|
this.configuration = merged;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
* Load configuration from
|
|
40
|
-
*
|
|
39
|
+
* Load hooks configuration from a pre-loaded WaveConfiguration
|
|
40
|
+
* Configuration loading is now handled by ConfigurationService
|
|
41
41
|
*/
|
|
42
|
-
|
|
42
|
+
loadConfigurationFromWaveConfig(waveConfig) {
|
|
43
43
|
try {
|
|
44
|
-
this.logger?.debug(`[HookManager] Loading configuration...`);
|
|
45
|
-
|
|
46
|
-
this.logger?.debug(`[HookManager] Merged config result:`, mergedWaveConfig);
|
|
47
|
-
this.configuration = mergedWaveConfig?.hooks || undefined;
|
|
48
|
-
this.environmentVars = mergedWaveConfig?.env || undefined;
|
|
44
|
+
this.logger?.debug(`[HookManager] Loading hooks configuration from pre-loaded config...`);
|
|
45
|
+
this.configuration = waveConfig?.hooks || undefined;
|
|
49
46
|
// Validate the loaded configuration if it exists
|
|
50
|
-
if (
|
|
51
|
-
const validation = this.validatePartialConfiguration(
|
|
47
|
+
if (waveConfig?.hooks) {
|
|
48
|
+
const validation = this.validatePartialConfiguration(waveConfig.hooks);
|
|
52
49
|
if (!validation.valid) {
|
|
53
|
-
throw new HookConfigurationError("
|
|
50
|
+
throw new HookConfigurationError("provided configuration", validation.errors);
|
|
54
51
|
}
|
|
55
52
|
}
|
|
56
|
-
this.logger?.debug(`[HookManager]
|
|
53
|
+
this.logger?.debug(`[HookManager] Hooks configuration loaded successfully with ${Object.keys(waveConfig?.hooks || {}).length} event types`);
|
|
57
54
|
}
|
|
58
55
|
catch (error) {
|
|
59
56
|
// If loading fails, start with undefined configuration (no hooks)
|
|
60
57
|
this.configuration = undefined;
|
|
61
|
-
|
|
62
|
-
// Re-throw configuration errors, but handle file system errors gracefully
|
|
58
|
+
// Re-throw configuration errors, but handle other errors gracefully
|
|
63
59
|
if (error instanceof HookConfigurationError) {
|
|
64
60
|
throw error;
|
|
65
61
|
}
|
|
66
62
|
else {
|
|
67
|
-
this.logger?.warn(
|
|
63
|
+
this.logger?.warn(`[HookManager] Failed to load configuration, continuing with no hooks: ${error.message}`);
|
|
68
64
|
}
|
|
69
65
|
}
|
|
70
66
|
}
|
|
@@ -110,7 +106,7 @@ export class HookManager {
|
|
|
110
106
|
const hookCommand = config.hooks[commandIndex];
|
|
111
107
|
try {
|
|
112
108
|
this.logger?.debug(`[HookManager] Executing command ${commandIndex + 1}/${config.hooks.length} in configuration ${configIndex + 1}`);
|
|
113
|
-
const result = await executeCommand(hookCommand.command, context, undefined
|
|
109
|
+
const result = await executeCommand(hookCommand.command, context, undefined);
|
|
114
110
|
results.push(result);
|
|
115
111
|
// Report individual command result
|
|
116
112
|
if (result.success) {
|
|
@@ -228,6 +224,17 @@ export class HookManager {
|
|
|
228
224
|
source: MessageSource.HOOK,
|
|
229
225
|
});
|
|
230
226
|
return { shouldBlock: true, errorMessage };
|
|
227
|
+
case "Notification":
|
|
228
|
+
// For notification hooks with exit code 2, only show stderr in error block
|
|
229
|
+
messageManager.addErrorBlock(errorMessage);
|
|
230
|
+
return { shouldBlock: false };
|
|
231
|
+
case "SubagentStop":
|
|
232
|
+
// Similar to Stop, show error and allow blocking
|
|
233
|
+
messageManager.addUserMessage({
|
|
234
|
+
content: errorMessage,
|
|
235
|
+
source: MessageSource.HOOK,
|
|
236
|
+
});
|
|
237
|
+
return { shouldBlock: true, errorMessage };
|
|
231
238
|
default:
|
|
232
239
|
return { shouldBlock: false };
|
|
233
240
|
}
|
|
@@ -343,15 +350,6 @@ export class HookManager {
|
|
|
343
350
|
// Deep clone to prevent external modification
|
|
344
351
|
return JSON.parse(JSON.stringify(this.configuration));
|
|
345
352
|
}
|
|
346
|
-
/**
|
|
347
|
-
* Get current environment variables
|
|
348
|
-
*/
|
|
349
|
-
getEnvironmentVars() {
|
|
350
|
-
if (!this.environmentVars)
|
|
351
|
-
return undefined;
|
|
352
|
-
// Deep clone to prevent external modification
|
|
353
|
-
return JSON.parse(JSON.stringify(this.environmentVars));
|
|
354
|
-
}
|
|
355
353
|
/**
|
|
356
354
|
* Clear current configuration
|
|
357
355
|
*/
|
|
@@ -386,7 +384,10 @@ export class HookManager {
|
|
|
386
384
|
}
|
|
387
385
|
}
|
|
388
386
|
// Validate non-tool events don't have unexpected tool names
|
|
389
|
-
if ((event === "UserPromptSubmit" ||
|
|
387
|
+
if ((event === "UserPromptSubmit" ||
|
|
388
|
+
event === "Stop" ||
|
|
389
|
+
event === "Notification" ||
|
|
390
|
+
event === "SubagentStop") &&
|
|
390
391
|
context.toolName !== undefined) {
|
|
391
392
|
this.logger?.warn(`[HookManager] ${event} event has unexpected toolName in context: ${context.toolName}`);
|
|
392
393
|
}
|
|
@@ -433,7 +434,10 @@ export class HookManager {
|
|
|
433
434
|
*/
|
|
434
435
|
configApplies(config, event, toolName) {
|
|
435
436
|
// For events that don't use matchers, config always applies
|
|
436
|
-
if (event === "UserPromptSubmit" ||
|
|
437
|
+
if (event === "UserPromptSubmit" ||
|
|
438
|
+
event === "Stop" ||
|
|
439
|
+
event === "Notification" ||
|
|
440
|
+
event === "SubagentStop") {
|
|
437
441
|
return true;
|
|
438
442
|
}
|
|
439
443
|
// For tool-based events, check matcher if present
|
|
@@ -467,7 +471,11 @@ export class HookManager {
|
|
|
467
471
|
}
|
|
468
472
|
}
|
|
469
473
|
// Validate that non-tool events don't have matchers
|
|
470
|
-
if ((event === "UserPromptSubmit" ||
|
|
474
|
+
if ((event === "UserPromptSubmit" ||
|
|
475
|
+
event === "Stop" ||
|
|
476
|
+
event === "Notification" ||
|
|
477
|
+
event === "SubagentStop") &&
|
|
478
|
+
config.matcher) {
|
|
471
479
|
errors.push(`${prefix}: Event ${event} should not have a matcher`);
|
|
472
480
|
}
|
|
473
481
|
// Validate commands
|
|
@@ -493,6 +501,7 @@ export class HookManager {
|
|
|
493
501
|
UserPromptSubmit: 0,
|
|
494
502
|
Stop: 0,
|
|
495
503
|
SubagentStop: 0,
|
|
504
|
+
Notification: 0,
|
|
496
505
|
},
|
|
497
506
|
};
|
|
498
507
|
}
|
|
@@ -502,6 +511,7 @@ export class HookManager {
|
|
|
502
511
|
UserPromptSubmit: 0,
|
|
503
512
|
Stop: 0,
|
|
504
513
|
SubagentStop: 0,
|
|
514
|
+
Notification: 0,
|
|
505
515
|
};
|
|
506
516
|
let totalConfigs = 0;
|
|
507
517
|
let totalCommands = 0;
|