wave-agent-sdk 0.0.1
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/README.md +32 -0
- package/dist/agent.d.ts +96 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +286 -0
- package/dist/hooks/executor.d.ts +56 -0
- package/dist/hooks/executor.d.ts.map +1 -0
- package/dist/hooks/executor.js +312 -0
- package/dist/hooks/index.d.ts +17 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +14 -0
- package/dist/hooks/manager.d.ts +90 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +395 -0
- package/dist/hooks/matcher.d.ts +49 -0
- package/dist/hooks/matcher.d.ts.map +1 -0
- package/dist/hooks/matcher.js +147 -0
- package/dist/hooks/settings.d.ts +46 -0
- package/dist/hooks/settings.d.ts.map +1 -0
- package/dist/hooks/settings.js +100 -0
- package/dist/hooks/types.d.ts +80 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +59 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/managers/aiManager.d.ts +61 -0
- package/dist/managers/aiManager.d.ts.map +1 -0
- package/dist/managers/aiManager.js +415 -0
- package/dist/managers/backgroundBashManager.d.ts +27 -0
- package/dist/managers/backgroundBashManager.d.ts.map +1 -0
- package/dist/managers/backgroundBashManager.js +166 -0
- package/dist/managers/bashManager.d.ts +20 -0
- package/dist/managers/bashManager.d.ts.map +1 -0
- package/dist/managers/bashManager.js +66 -0
- package/dist/managers/mcpManager.d.ts +63 -0
- package/dist/managers/mcpManager.d.ts.map +1 -0
- package/dist/managers/mcpManager.js +378 -0
- package/dist/managers/messageManager.d.ts +85 -0
- package/dist/managers/messageManager.d.ts.map +1 -0
- package/dist/managers/messageManager.js +265 -0
- package/dist/managers/skillManager.d.ts +59 -0
- package/dist/managers/skillManager.d.ts.map +1 -0
- package/dist/managers/skillManager.js +317 -0
- package/dist/managers/slashCommandManager.d.ts +77 -0
- package/dist/managers/slashCommandManager.d.ts.map +1 -0
- package/dist/managers/slashCommandManager.js +208 -0
- package/dist/managers/toolManager.d.ts +23 -0
- package/dist/managers/toolManager.d.ts.map +1 -0
- package/dist/managers/toolManager.js +79 -0
- package/dist/services/aiService.d.ts +28 -0
- package/dist/services/aiService.d.ts.map +1 -0
- package/dist/services/aiService.js +180 -0
- package/dist/services/memory.d.ts +8 -0
- package/dist/services/memory.d.ts.map +1 -0
- package/dist/services/memory.js +128 -0
- package/dist/services/session.d.ts +54 -0
- package/dist/services/session.d.ts.map +1 -0
- package/dist/services/session.js +196 -0
- package/dist/tools/bashTool.d.ts +14 -0
- package/dist/tools/bashTool.d.ts.map +1 -0
- package/dist/tools/bashTool.js +351 -0
- package/dist/tools/deleteFileTool.d.ts +6 -0
- package/dist/tools/deleteFileTool.d.ts.map +1 -0
- package/dist/tools/deleteFileTool.js +67 -0
- package/dist/tools/editTool.d.ts +6 -0
- package/dist/tools/editTool.d.ts.map +1 -0
- package/dist/tools/editTool.js +168 -0
- package/dist/tools/globTool.d.ts +6 -0
- package/dist/tools/globTool.d.ts.map +1 -0
- package/dist/tools/globTool.js +113 -0
- package/dist/tools/grepTool.d.ts +6 -0
- package/dist/tools/grepTool.d.ts.map +1 -0
- package/dist/tools/grepTool.js +268 -0
- package/dist/tools/lsTool.d.ts +6 -0
- package/dist/tools/lsTool.d.ts.map +1 -0
- package/dist/tools/lsTool.js +160 -0
- package/dist/tools/multiEditTool.d.ts +6 -0
- package/dist/tools/multiEditTool.d.ts.map +1 -0
- package/dist/tools/multiEditTool.js +222 -0
- package/dist/tools/readTool.d.ts +6 -0
- package/dist/tools/readTool.d.ts.map +1 -0
- package/dist/tools/readTool.js +136 -0
- package/dist/tools/types.d.ts +35 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +4 -0
- package/dist/tools/writeTool.d.ts +6 -0
- package/dist/tools/writeTool.d.ts.map +1 -0
- package/dist/tools/writeTool.js +138 -0
- package/dist/types.d.ts +212 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/utils/bashHistory.d.ts +46 -0
- package/dist/utils/bashHistory.d.ts.map +1 -0
- package/dist/utils/bashHistory.js +236 -0
- package/dist/utils/commandArgumentParser.d.ts +34 -0
- package/dist/utils/commandArgumentParser.d.ts.map +1 -0
- package/dist/utils/commandArgumentParser.js +123 -0
- package/dist/utils/constants.d.ts +27 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +28 -0
- package/dist/utils/convertMessagesForAPI.d.ts +9 -0
- package/dist/utils/convertMessagesForAPI.d.ts.map +1 -0
- package/dist/utils/convertMessagesForAPI.js +189 -0
- package/dist/utils/customCommands.d.ts +14 -0
- package/dist/utils/customCommands.d.ts.map +1 -0
- package/dist/utils/customCommands.js +71 -0
- package/dist/utils/fileFilter.d.ts +26 -0
- package/dist/utils/fileFilter.d.ts.map +1 -0
- package/dist/utils/fileFilter.js +177 -0
- package/dist/utils/markdownParser.d.ts +27 -0
- package/dist/utils/markdownParser.d.ts.map +1 -0
- package/dist/utils/markdownParser.js +109 -0
- package/dist/utils/mcpUtils.d.ts +24 -0
- package/dist/utils/mcpUtils.d.ts.map +1 -0
- package/dist/utils/mcpUtils.js +51 -0
- package/dist/utils/messageOperations.d.ts +118 -0
- package/dist/utils/messageOperations.d.ts.map +1 -0
- package/dist/utils/messageOperations.js +334 -0
- package/dist/utils/path.d.ts +25 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/path.js +109 -0
- package/dist/utils/skillParser.d.ts +18 -0
- package/dist/utils/skillParser.d.ts.map +1 -0
- package/dist/utils/skillParser.js +147 -0
- package/dist/utils/stringUtils.d.ts +13 -0
- package/dist/utils/stringUtils.d.ts.map +1 -0
- package/dist/utils/stringUtils.js +44 -0
- package/package.json +51 -0
- package/src/agent.ts +405 -0
- package/src/hooks/executor.ts +440 -0
- package/src/hooks/index.ts +52 -0
- package/src/hooks/manager.ts +618 -0
- package/src/hooks/matcher.ts +187 -0
- package/src/hooks/settings.ts +129 -0
- package/src/hooks/types.ts +169 -0
- package/src/index.ts +24 -0
- package/src/managers/aiManager.ts +573 -0
- package/src/managers/backgroundBashManager.ts +203 -0
- package/src/managers/bashManager.ts +97 -0
- package/src/managers/mcpManager.ts +493 -0
- package/src/managers/messageManager.ts +415 -0
- package/src/managers/skillManager.ts +404 -0
- package/src/managers/slashCommandManager.ts +293 -0
- package/src/managers/toolManager.ts +106 -0
- package/src/services/aiService.ts +252 -0
- package/src/services/memory.ts +149 -0
- package/src/services/session.ts +265 -0
- package/src/tools/bashTool.ts +402 -0
- package/src/tools/deleteFileTool.ts +81 -0
- package/src/tools/editTool.ts +192 -0
- package/src/tools/globTool.ts +135 -0
- package/src/tools/grepTool.ts +326 -0
- package/src/tools/lsTool.ts +187 -0
- package/src/tools/multiEditTool.ts +268 -0
- package/src/tools/readTool.ts +165 -0
- package/src/tools/types.ts +47 -0
- package/src/tools/writeTool.ts +163 -0
- package/src/types.ts +260 -0
- package/src/utils/bashHistory.ts +303 -0
- package/src/utils/commandArgumentParser.ts +153 -0
- package/src/utils/constants.ts +37 -0
- package/src/utils/convertMessagesForAPI.ts +236 -0
- package/src/utils/customCommands.ts +85 -0
- package/src/utils/fileFilter.ts +202 -0
- package/src/utils/markdownParser.ts +156 -0
- package/src/utils/mcpUtils.ts +81 -0
- package/src/utils/messageOperations.ts +506 -0
- package/src/utils/path.ts +118 -0
- package/src/utils/skillParser.ts +188 -0
- package/src/utils/stringUtils.ts +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Wave Agent SDK
|
|
2
|
+
|
|
3
|
+
SDK for building AI-powered development tools and agents.
|
|
4
|
+
|
|
5
|
+
This package provides the core functionality for building AI-powered development assistants.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install wave-agent-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
See [examples](./examples) for usage examples.
|
|
16
|
+
|
|
17
|
+
## Development
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Install dependencies
|
|
21
|
+
pnpm install
|
|
22
|
+
|
|
23
|
+
# Build
|
|
24
|
+
pnpm build
|
|
25
|
+
|
|
26
|
+
# Test
|
|
27
|
+
pnpm test
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
MIT
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type MessageManagerCallbacks } from "./managers/messageManager.js";
|
|
2
|
+
import { type McpManagerCallbacks } from "./managers/mcpManager.js";
|
|
3
|
+
import { type BackgroundBashManagerCallbacks } from "./managers/backgroundBashManager.js";
|
|
4
|
+
import type { SlashCommand, CustomSlashCommand } from "./types.js";
|
|
5
|
+
import type { Message, Logger, McpServerStatus } from "./types.js";
|
|
6
|
+
export interface AgentOptions {
|
|
7
|
+
callbacks?: AgentCallbacks;
|
|
8
|
+
restoreSessionId?: string;
|
|
9
|
+
continueLastSession?: boolean;
|
|
10
|
+
logger?: Logger;
|
|
11
|
+
/**Add optional initial messages parameter for testing convenience */
|
|
12
|
+
messages?: Message[];
|
|
13
|
+
/**Working directory - if not specified, use process.cwd() */
|
|
14
|
+
workdir?: string;
|
|
15
|
+
/**Optional custom system prompt - if provided, replaces default system prompt */
|
|
16
|
+
systemPrompt?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface AgentCallbacks extends MessageManagerCallbacks, BackgroundBashManagerCallbacks, McpManagerCallbacks {
|
|
19
|
+
}
|
|
20
|
+
export declare class Agent {
|
|
21
|
+
private messageManager;
|
|
22
|
+
private aiManager;
|
|
23
|
+
private callbacks;
|
|
24
|
+
private bashManager;
|
|
25
|
+
private backgroundBashManager;
|
|
26
|
+
private logger?;
|
|
27
|
+
private toolManager;
|
|
28
|
+
private mcpManager;
|
|
29
|
+
private slashCommandManager;
|
|
30
|
+
private hookManager;
|
|
31
|
+
private workdir;
|
|
32
|
+
private systemPrompt?;
|
|
33
|
+
private constructor();
|
|
34
|
+
get sessionId(): string;
|
|
35
|
+
get messages(): Message[];
|
|
36
|
+
get latestTotalTokens(): number;
|
|
37
|
+
get userInputHistory(): string[];
|
|
38
|
+
/** Get working directory */
|
|
39
|
+
get workingDirectory(): string;
|
|
40
|
+
/** Get AI loading status */
|
|
41
|
+
get isLoading(): boolean;
|
|
42
|
+
/** Get message compression status */
|
|
43
|
+
get isCompressing(): boolean;
|
|
44
|
+
/** Get bash command execution status */
|
|
45
|
+
get isCommandRunning(): boolean;
|
|
46
|
+
/** Get background bash shell output */
|
|
47
|
+
getBackgroundShellOutput(id: string, filter?: string): {
|
|
48
|
+
stdout: string;
|
|
49
|
+
stderr: string;
|
|
50
|
+
status: string;
|
|
51
|
+
} | null;
|
|
52
|
+
/** Kill background bash shell */
|
|
53
|
+
killBackgroundShell(id: string): boolean;
|
|
54
|
+
/** Static async factory method */
|
|
55
|
+
static create(options: AgentOptions): Promise<Agent>;
|
|
56
|
+
/** Private initialization method, handles async initialization logic */
|
|
57
|
+
private initialize;
|
|
58
|
+
abortAIMessage(): void;
|
|
59
|
+
/** Execute bash command */
|
|
60
|
+
executeBashCommand(command: string): Promise<void>;
|
|
61
|
+
/** Clear messages and input history */
|
|
62
|
+
clearMessages(): void;
|
|
63
|
+
/** Unified interrupt method, interrupts both AI messages and command execution */
|
|
64
|
+
abortMessage(): void;
|
|
65
|
+
/** Add to input history */
|
|
66
|
+
private addToInputHistory;
|
|
67
|
+
/** Interrupt bash command execution */
|
|
68
|
+
abortBashCommand(): void;
|
|
69
|
+
/** Interrupt slash command execution */
|
|
70
|
+
abortSlashCommand(): void;
|
|
71
|
+
/** Destroy managers, clean up resources */
|
|
72
|
+
destroy(): Promise<void>;
|
|
73
|
+
sendMessage(content: string, images?: Array<{
|
|
74
|
+
path: string;
|
|
75
|
+
mimeType: string;
|
|
76
|
+
}>): Promise<void>;
|
|
77
|
+
/** Save memory to project or user memory file */
|
|
78
|
+
saveMemory(message: string, type: "project" | "user"): Promise<void>;
|
|
79
|
+
/** Get all MCP server status */
|
|
80
|
+
getMcpServers(): McpServerStatus[];
|
|
81
|
+
/** Connect MCP server */
|
|
82
|
+
connectMcpServer(serverName: string): Promise<boolean>;
|
|
83
|
+
/** Disconnect MCP server */
|
|
84
|
+
disconnectMcpServer(serverName: string): Promise<boolean>;
|
|
85
|
+
/** Get all available slash commands */
|
|
86
|
+
getSlashCommands(): SlashCommand[];
|
|
87
|
+
/** Check if slash command exists */
|
|
88
|
+
hasSlashCommand(commandId: string): boolean;
|
|
89
|
+
/** Reload custom commands */
|
|
90
|
+
reloadCustomCommands(): void;
|
|
91
|
+
/** Get custom command details */
|
|
92
|
+
getCustomCommand(commandId: string): CustomSlashCommand | undefined;
|
|
93
|
+
/** Get all custom commands */
|
|
94
|
+
getCustomCommands(): CustomSlashCommand[];
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,8BAA8B,CAAC;AAItC,OAAO,EAAc,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEhF,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,qCAAqC,CAAC;AAE7C,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGnE,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,gBAAgB,CAAC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C,SAAS,EAAE,MAAM,GAAG,OAAO;IAIlD,6BAA6B;IACtB,oBAAoB,IAAI,IAAI;IAInC,iCAAiC;IAC1B,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAI1E,8BAA8B;IACvB,iBAAiB,IAAI,kBAAkB,EAAE;CAGjD"}
|
package/dist/agent.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { MessageManager, } from "./managers/messageManager.js";
|
|
2
|
+
import { AIManager } from "./managers/aiManager.js";
|
|
3
|
+
import { ToolManager } from "./managers/toolManager.js";
|
|
4
|
+
import * as memory from "./services/memory.js";
|
|
5
|
+
import { McpManager } from "./managers/mcpManager.js";
|
|
6
|
+
import { BashManager } from "./managers/bashManager.js";
|
|
7
|
+
import { BackgroundBashManager, } from "./managers/backgroundBashManager.js";
|
|
8
|
+
import { SlashCommandManager } from "./managers/slashCommandManager.js";
|
|
9
|
+
import { HookManager } from "./hooks/index.js";
|
|
10
|
+
export class Agent {
|
|
11
|
+
// Private constructor to prevent direct instantiation
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.bashManager = null;
|
|
14
|
+
const { callbacks = {}, logger, workdir, systemPrompt } = options;
|
|
15
|
+
this.callbacks = callbacks;
|
|
16
|
+
this.logger = logger; // Save the passed logger
|
|
17
|
+
this.workdir = workdir || process.cwd(); // Set working directory, default to current working directory
|
|
18
|
+
this.systemPrompt = systemPrompt; // Save custom system prompt
|
|
19
|
+
this.backgroundBashManager = new BackgroundBashManager({
|
|
20
|
+
callbacks,
|
|
21
|
+
workdir: this.workdir,
|
|
22
|
+
});
|
|
23
|
+
this.mcpManager = new McpManager({ callbacks, logger: this.logger }); // Initialize MCP manager
|
|
24
|
+
this.toolManager = new ToolManager({ mcpManager: this.mcpManager }); // Initialize tool registry, pass MCP manager
|
|
25
|
+
this.hookManager = new HookManager(this.workdir, undefined, undefined, this.logger); // Initialize hooks manager
|
|
26
|
+
// Initialize MessageManager
|
|
27
|
+
this.messageManager = new MessageManager({
|
|
28
|
+
callbacks,
|
|
29
|
+
workdir: this.workdir,
|
|
30
|
+
logger: this.logger,
|
|
31
|
+
});
|
|
32
|
+
// Initialize AI manager
|
|
33
|
+
this.aiManager = new AIManager({
|
|
34
|
+
messageManager: this.messageManager,
|
|
35
|
+
toolManager: this.toolManager,
|
|
36
|
+
logger: this.logger,
|
|
37
|
+
backgroundBashManager: this.backgroundBashManager,
|
|
38
|
+
hookManager: this.hookManager,
|
|
39
|
+
callbacks,
|
|
40
|
+
workdir: this.workdir,
|
|
41
|
+
systemPrompt: this.systemPrompt,
|
|
42
|
+
});
|
|
43
|
+
// Initialize command manager
|
|
44
|
+
this.slashCommandManager = new SlashCommandManager({
|
|
45
|
+
messageManager: this.messageManager,
|
|
46
|
+
aiManager: this.aiManager,
|
|
47
|
+
workdir: this.workdir,
|
|
48
|
+
logger: this.logger,
|
|
49
|
+
});
|
|
50
|
+
// Initialize bash manager
|
|
51
|
+
this.bashManager = new BashManager({
|
|
52
|
+
messageManager: this.messageManager,
|
|
53
|
+
workdir: this.workdir,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
// Public getter methods
|
|
57
|
+
get sessionId() {
|
|
58
|
+
return this.messageManager.getSessionId();
|
|
59
|
+
}
|
|
60
|
+
get messages() {
|
|
61
|
+
return this.messageManager.getMessages();
|
|
62
|
+
}
|
|
63
|
+
get latestTotalTokens() {
|
|
64
|
+
return this.messageManager.getlatestTotalTokens();
|
|
65
|
+
}
|
|
66
|
+
get userInputHistory() {
|
|
67
|
+
return this.messageManager.getUserInputHistory();
|
|
68
|
+
}
|
|
69
|
+
/** Get working directory */
|
|
70
|
+
get workingDirectory() {
|
|
71
|
+
return this.workdir;
|
|
72
|
+
}
|
|
73
|
+
/** Get AI loading status */
|
|
74
|
+
get isLoading() {
|
|
75
|
+
return this.aiManager.isLoading;
|
|
76
|
+
}
|
|
77
|
+
/** Get message compression status */
|
|
78
|
+
get isCompressing() {
|
|
79
|
+
return this.aiManager.getIsCompressing();
|
|
80
|
+
}
|
|
81
|
+
/** Get bash command execution status */
|
|
82
|
+
get isCommandRunning() {
|
|
83
|
+
return this.bashManager?.isCommandRunning ?? false;
|
|
84
|
+
}
|
|
85
|
+
/** Get background bash shell output */
|
|
86
|
+
getBackgroundShellOutput(id, filter) {
|
|
87
|
+
return this.backgroundBashManager.getOutput(id, filter);
|
|
88
|
+
}
|
|
89
|
+
/** Kill background bash shell */
|
|
90
|
+
killBackgroundShell(id) {
|
|
91
|
+
return this.backgroundBashManager.killShell(id);
|
|
92
|
+
}
|
|
93
|
+
/** Static async factory method */
|
|
94
|
+
static async create(options) {
|
|
95
|
+
const instance = new Agent(options);
|
|
96
|
+
await instance.initialize({
|
|
97
|
+
restoreSessionId: options.restoreSessionId,
|
|
98
|
+
continueLastSession: options.continueLastSession,
|
|
99
|
+
messages: options.messages,
|
|
100
|
+
});
|
|
101
|
+
return instance;
|
|
102
|
+
}
|
|
103
|
+
/** Private initialization method, handles async initialization logic */
|
|
104
|
+
async initialize(options) {
|
|
105
|
+
// Initialize MCP servers with auto-connect
|
|
106
|
+
try {
|
|
107
|
+
await this.mcpManager.initialize(this.workdir, true);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
this.logger?.error("Failed to initialize MCP servers:", error);
|
|
111
|
+
// Don't throw error to prevent app startup failure
|
|
112
|
+
}
|
|
113
|
+
// Initialize hooks configuration
|
|
114
|
+
try {
|
|
115
|
+
// Load hooks configuration from user and project settings
|
|
116
|
+
this.logger?.info("Loading hooks configuration...");
|
|
117
|
+
this.hookManager.loadConfigurationFromSettings();
|
|
118
|
+
this.logger?.debug("Hooks system initialized successfully");
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
this.logger?.error("Failed to initialize hooks system:", error);
|
|
122
|
+
// Don't throw error to prevent app startup failure
|
|
123
|
+
}
|
|
124
|
+
// Handle session restoration or set provided messages
|
|
125
|
+
if (options?.messages) {
|
|
126
|
+
// If messages are provided, use them directly (useful for testing)
|
|
127
|
+
this.messageManager.setMessages(options.messages);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// Otherwise, handle session restoration
|
|
131
|
+
await this.messageManager.handleSessionRestoration(options?.restoreSessionId, options?.continueLastSession);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
abortAIMessage() {
|
|
135
|
+
this.aiManager.abortAIMessage();
|
|
136
|
+
}
|
|
137
|
+
/** Execute bash command */
|
|
138
|
+
async executeBashCommand(command) {
|
|
139
|
+
// Add user message to history (but not displayed in UI)
|
|
140
|
+
this.addToInputHistory(`!${command}`);
|
|
141
|
+
await this.bashManager?.executeCommand(command);
|
|
142
|
+
}
|
|
143
|
+
/** Clear messages and input history */
|
|
144
|
+
clearMessages() {
|
|
145
|
+
this.messageManager.clearMessages();
|
|
146
|
+
}
|
|
147
|
+
/** Unified interrupt method, interrupts both AI messages and command execution */
|
|
148
|
+
abortMessage() {
|
|
149
|
+
this.abortAIMessage();
|
|
150
|
+
this.abortBashCommand();
|
|
151
|
+
this.abortSlashCommand();
|
|
152
|
+
}
|
|
153
|
+
/** Add to input history */
|
|
154
|
+
addToInputHistory(input) {
|
|
155
|
+
this.messageManager.addToInputHistory(input);
|
|
156
|
+
}
|
|
157
|
+
/** Interrupt bash command execution */
|
|
158
|
+
abortBashCommand() {
|
|
159
|
+
this.bashManager?.abortCommand();
|
|
160
|
+
}
|
|
161
|
+
/** Interrupt slash command execution */
|
|
162
|
+
abortSlashCommand() {
|
|
163
|
+
this.slashCommandManager.abortCurrentCommand();
|
|
164
|
+
}
|
|
165
|
+
/** Destroy managers, clean up resources */
|
|
166
|
+
async destroy() {
|
|
167
|
+
this.messageManager.saveSession();
|
|
168
|
+
this.abortAIMessage();
|
|
169
|
+
this.abortBashCommand();
|
|
170
|
+
this.abortSlashCommand();
|
|
171
|
+
// Cleanup background bash manager
|
|
172
|
+
this.backgroundBashManager.cleanup();
|
|
173
|
+
// Cleanup MCP connections
|
|
174
|
+
await this.mcpManager.cleanup();
|
|
175
|
+
}
|
|
176
|
+
async sendMessage(content, images) {
|
|
177
|
+
try {
|
|
178
|
+
// Handle slash command - check if it's a slash command (starts with /)
|
|
179
|
+
if (content.startsWith("/")) {
|
|
180
|
+
const command = content.trim();
|
|
181
|
+
if (!command || command === "/")
|
|
182
|
+
return;
|
|
183
|
+
// Parse and validate slash command
|
|
184
|
+
const { isValid, commandId, args } = this.slashCommandManager.parseAndValidateSlashCommand(command);
|
|
185
|
+
if (isValid && commandId !== undefined) {
|
|
186
|
+
// Execute valid slash command
|
|
187
|
+
await this.slashCommandManager.executeCommand(commandId, args);
|
|
188
|
+
// Add slash command to history
|
|
189
|
+
this.addToInputHistory(command);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
// If command doesn't exist, continue as normal message processing
|
|
193
|
+
// Don't add to history, let normal message processing logic below handle it
|
|
194
|
+
}
|
|
195
|
+
// Handle normal AI message
|
|
196
|
+
// Add user message to history
|
|
197
|
+
this.addToInputHistory(content);
|
|
198
|
+
// Execute UserPromptSubmit hooks before processing the prompt
|
|
199
|
+
if (this.hookManager) {
|
|
200
|
+
try {
|
|
201
|
+
await this.hookManager.executeHooks("UserPromptSubmit", {
|
|
202
|
+
event: "UserPromptSubmit",
|
|
203
|
+
projectDir: this.workdir,
|
|
204
|
+
timestamp: new Date(),
|
|
205
|
+
// UserPromptSubmit doesn't need toolName
|
|
206
|
+
sessionId: this.sessionId,
|
|
207
|
+
transcriptPath: this.messageManager.getTranscriptPath(),
|
|
208
|
+
cwd: this.workdir,
|
|
209
|
+
userPrompt: content,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
this.logger?.warn("UserPromptSubmit hooks execution failed:", error);
|
|
214
|
+
// Continue processing even if hooks fail
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// Add user message, will automatically sync to UI
|
|
218
|
+
this.messageManager.addUserMessage(content, images?.map((img) => ({
|
|
219
|
+
path: img.path,
|
|
220
|
+
mimeType: img.mimeType,
|
|
221
|
+
})));
|
|
222
|
+
// Send AI message
|
|
223
|
+
await this.aiManager.sendAIMessage();
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
console.error("Failed to add user message:", error);
|
|
227
|
+
// Loading state will be automatically updated by the useEffect that watches messages
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/** Save memory to project or user memory file */
|
|
231
|
+
async saveMemory(message, type) {
|
|
232
|
+
try {
|
|
233
|
+
if (type === "project") {
|
|
234
|
+
await memory.addMemory(message, this.workdir);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
await memory.addUserMemory(message);
|
|
238
|
+
}
|
|
239
|
+
// Add successful MemoryBlock to the last assistant message
|
|
240
|
+
const memoryText = message.substring(1).trim();
|
|
241
|
+
const typeLabel = type === "project" ? "Project Memory" : "User Memory";
|
|
242
|
+
const storagePath = type === "project" ? "WAVE.md" : "user-memory.md";
|
|
243
|
+
this.messageManager.addMemoryBlock(`${typeLabel}: ${memoryText}`, true, type, storagePath);
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
// Add failed MemoryBlock to the last assistant message
|
|
247
|
+
const typeLabel = type === "project" ? "Project Memory" : "User Memory";
|
|
248
|
+
const storagePath = type === "project" ? "WAVE.md" : "user-memory.md";
|
|
249
|
+
this.messageManager.addMemoryBlock(`${typeLabel} add failed: ${error instanceof Error ? error.message : String(error)}`, false, type, storagePath);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// ========== MCP Management Methods ==========
|
|
253
|
+
/** Get all MCP server status */
|
|
254
|
+
getMcpServers() {
|
|
255
|
+
return this.mcpManager.getAllServers();
|
|
256
|
+
}
|
|
257
|
+
/** Connect MCP server */
|
|
258
|
+
async connectMcpServer(serverName) {
|
|
259
|
+
return await this.mcpManager.connectServer(serverName);
|
|
260
|
+
}
|
|
261
|
+
/** Disconnect MCP server */
|
|
262
|
+
async disconnectMcpServer(serverName) {
|
|
263
|
+
return await this.mcpManager.disconnectServer(serverName);
|
|
264
|
+
}
|
|
265
|
+
// ========== Slash Command Management Methods ==========
|
|
266
|
+
/** Get all available slash commands */
|
|
267
|
+
getSlashCommands() {
|
|
268
|
+
return this.slashCommandManager.getCommands();
|
|
269
|
+
}
|
|
270
|
+
/** Check if slash command exists */
|
|
271
|
+
hasSlashCommand(commandId) {
|
|
272
|
+
return this.slashCommandManager.hasCommand(commandId);
|
|
273
|
+
}
|
|
274
|
+
/** Reload custom commands */
|
|
275
|
+
reloadCustomCommands() {
|
|
276
|
+
this.slashCommandManager.reloadCustomCommands();
|
|
277
|
+
}
|
|
278
|
+
/** Get custom command details */
|
|
279
|
+
getCustomCommand(commandId) {
|
|
280
|
+
return this.slashCommandManager.getCustomCommand(commandId);
|
|
281
|
+
}
|
|
282
|
+
/** Get all custom commands */
|
|
283
|
+
getCustomCommands() {
|
|
284
|
+
return this.slashCommandManager.getCustomCommands();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook Command Executor
|
|
3
|
+
*
|
|
4
|
+
* Handles the execution of hook commands in isolated processes with proper
|
|
5
|
+
* timeout handling, environment variable injection, and cross-platform support.
|
|
6
|
+
*/
|
|
7
|
+
import { type HookExecutionContext, type HookExecutionResult, type HookExecutionOptions, type ExtendedHookExecutionContext } from "./types.js";
|
|
8
|
+
import type { Logger } from "../types.js";
|
|
9
|
+
export interface IHookExecutor {
|
|
10
|
+
executeCommand(command: string, context: HookExecutionContext | ExtendedHookExecutionContext, options?: HookExecutionOptions): Promise<HookExecutionResult>;
|
|
11
|
+
executeCommands(commands: string[], context: HookExecutionContext | ExtendedHookExecutionContext, options?: HookExecutionOptions): Promise<HookExecutionResult[]>;
|
|
12
|
+
isCommandSafe(command: string): boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare class HookExecutor implements IHookExecutor {
|
|
15
|
+
private readonly defaultTimeout;
|
|
16
|
+
private readonly maxTimeout;
|
|
17
|
+
private readonly logger?;
|
|
18
|
+
private readonly skipExecution;
|
|
19
|
+
constructor(logger?: Logger, options?: {
|
|
20
|
+
skipExecution?: boolean;
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Execute a single hook command in an isolated process
|
|
24
|
+
*/
|
|
25
|
+
executeCommand(command: string, context: HookExecutionContext | ExtendedHookExecutionContext, options?: HookExecutionOptions): Promise<HookExecutionResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Execute multiple commands in sequence
|
|
28
|
+
* Stops on first failure unless configured otherwise
|
|
29
|
+
*/
|
|
30
|
+
executeCommands(commands: string[], context: HookExecutionContext | ExtendedHookExecutionContext, options?: HookExecutionOptions): Promise<HookExecutionResult[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Validate command safety to prevent injection attacks
|
|
33
|
+
*/
|
|
34
|
+
isCommandSafe(command: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Build environment variables for hook execution
|
|
37
|
+
*/
|
|
38
|
+
private buildEnvironment;
|
|
39
|
+
/**
|
|
40
|
+
* Resolve environment variables in command string
|
|
41
|
+
*/
|
|
42
|
+
private resolveEnvironmentVariables;
|
|
43
|
+
/**
|
|
44
|
+
* Get process statistics for monitoring
|
|
45
|
+
*/
|
|
46
|
+
getExecutionStats(): {
|
|
47
|
+
platform: NodeJS.Platform;
|
|
48
|
+
defaultTimeout: number;
|
|
49
|
+
maxTimeout: number;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Test if the executor can run commands on this platform
|
|
53
|
+
*/
|
|
54
|
+
isSupported(): boolean;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/hooks/executor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAC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