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/dist/types.d.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { ChildProcess } from "child_process";
|
|
2
|
+
/**
|
|
3
|
+
* Logger interface definition
|
|
4
|
+
* Compatible with OpenAI package Logger interface
|
|
5
|
+
*/
|
|
6
|
+
export interface Logger {
|
|
7
|
+
error: (...args: unknown[]) => void;
|
|
8
|
+
warn: (...args: unknown[]) => void;
|
|
9
|
+
info: (...args: unknown[]) => void;
|
|
10
|
+
debug: (...args: unknown[]) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface Message {
|
|
13
|
+
role: "user" | "assistant";
|
|
14
|
+
blocks: MessageBlock[];
|
|
15
|
+
}
|
|
16
|
+
export type MessageBlock = TextBlock | ErrorBlock | ToolBlock | ImageBlock | DiffBlock | CommandOutputBlock | CompressBlock | MemoryBlock | CustomCommandBlock;
|
|
17
|
+
export interface TextBlock {
|
|
18
|
+
type: "text";
|
|
19
|
+
content: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ErrorBlock {
|
|
22
|
+
type: "error";
|
|
23
|
+
content: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ToolBlock {
|
|
26
|
+
type: "tool";
|
|
27
|
+
parameters?: string;
|
|
28
|
+
result?: string;
|
|
29
|
+
shortResult?: string;
|
|
30
|
+
images?: Array<{
|
|
31
|
+
data: string;
|
|
32
|
+
mediaType?: string;
|
|
33
|
+
}>;
|
|
34
|
+
id?: string;
|
|
35
|
+
name?: string;
|
|
36
|
+
isRunning?: boolean;
|
|
37
|
+
success?: boolean;
|
|
38
|
+
error?: string | Error;
|
|
39
|
+
compactParams?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ImageBlock {
|
|
42
|
+
type: "image";
|
|
43
|
+
imageUrls?: string[];
|
|
44
|
+
}
|
|
45
|
+
export interface DiffBlock {
|
|
46
|
+
type: "diff";
|
|
47
|
+
path: string;
|
|
48
|
+
diffResult: Array<{
|
|
49
|
+
value: string;
|
|
50
|
+
added?: boolean;
|
|
51
|
+
removed?: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
}
|
|
54
|
+
export interface CommandOutputBlock {
|
|
55
|
+
type: "command_output";
|
|
56
|
+
command: string;
|
|
57
|
+
output: string;
|
|
58
|
+
isRunning: boolean;
|
|
59
|
+
exitCode: number | null;
|
|
60
|
+
}
|
|
61
|
+
export interface CompressBlock {
|
|
62
|
+
type: "compress";
|
|
63
|
+
content: string;
|
|
64
|
+
}
|
|
65
|
+
export interface MemoryBlock {
|
|
66
|
+
type: "memory";
|
|
67
|
+
content: string;
|
|
68
|
+
isSuccess: boolean;
|
|
69
|
+
memoryType?: "project" | "user";
|
|
70
|
+
storagePath?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface CustomCommandBlock {
|
|
73
|
+
type: "custom_command";
|
|
74
|
+
commandName: string;
|
|
75
|
+
content: string;
|
|
76
|
+
originalInput?: string;
|
|
77
|
+
}
|
|
78
|
+
export interface AIRequest {
|
|
79
|
+
content: string;
|
|
80
|
+
files: unknown[];
|
|
81
|
+
}
|
|
82
|
+
export interface AIResponse {
|
|
83
|
+
content: string;
|
|
84
|
+
status: "success" | "error";
|
|
85
|
+
error?: string;
|
|
86
|
+
}
|
|
87
|
+
export interface McpServerConfig {
|
|
88
|
+
command: string;
|
|
89
|
+
args?: string[];
|
|
90
|
+
env?: Record<string, string>;
|
|
91
|
+
}
|
|
92
|
+
export interface McpConfig {
|
|
93
|
+
mcpServers: Record<string, McpServerConfig>;
|
|
94
|
+
}
|
|
95
|
+
export interface McpTool {
|
|
96
|
+
name: string;
|
|
97
|
+
description?: string;
|
|
98
|
+
inputSchema: Record<string, unknown>;
|
|
99
|
+
}
|
|
100
|
+
export interface McpServerStatus {
|
|
101
|
+
name: string;
|
|
102
|
+
config: McpServerConfig;
|
|
103
|
+
status: "disconnected" | "connected" | "connecting" | "error";
|
|
104
|
+
tools?: McpTool[];
|
|
105
|
+
toolCount?: number;
|
|
106
|
+
capabilities?: string[];
|
|
107
|
+
lastConnected?: number;
|
|
108
|
+
error?: string;
|
|
109
|
+
}
|
|
110
|
+
export interface BackgroundShell {
|
|
111
|
+
id: string;
|
|
112
|
+
process: ChildProcess;
|
|
113
|
+
command: string;
|
|
114
|
+
startTime: number;
|
|
115
|
+
status: "running" | "completed" | "killed";
|
|
116
|
+
stdout: string;
|
|
117
|
+
stderr: string;
|
|
118
|
+
exitCode?: number;
|
|
119
|
+
runtime?: number;
|
|
120
|
+
}
|
|
121
|
+
export interface SlashCommand {
|
|
122
|
+
id: string;
|
|
123
|
+
name: string;
|
|
124
|
+
description: string;
|
|
125
|
+
handler: (args?: string) => Promise<void> | void;
|
|
126
|
+
}
|
|
127
|
+
export interface CustomSlashCommandConfig {
|
|
128
|
+
allowedTools?: string[];
|
|
129
|
+
model?: string;
|
|
130
|
+
description?: string;
|
|
131
|
+
}
|
|
132
|
+
export interface CustomSlashCommand {
|
|
133
|
+
id: string;
|
|
134
|
+
name: string;
|
|
135
|
+
description?: string;
|
|
136
|
+
filePath: string;
|
|
137
|
+
content: string;
|
|
138
|
+
config?: CustomSlashCommandConfig;
|
|
139
|
+
}
|
|
140
|
+
export interface SkillMetadata {
|
|
141
|
+
name: string;
|
|
142
|
+
description: string;
|
|
143
|
+
type: "personal" | "project";
|
|
144
|
+
skillPath: string;
|
|
145
|
+
}
|
|
146
|
+
export interface Skill extends SkillMetadata {
|
|
147
|
+
content: string;
|
|
148
|
+
frontmatter: SkillFrontmatter;
|
|
149
|
+
isValid: boolean;
|
|
150
|
+
errors: string[];
|
|
151
|
+
}
|
|
152
|
+
export interface SkillFrontmatter {
|
|
153
|
+
name: string;
|
|
154
|
+
description: string;
|
|
155
|
+
[key: string]: unknown;
|
|
156
|
+
}
|
|
157
|
+
export interface SkillCollection {
|
|
158
|
+
type: "personal" | "project";
|
|
159
|
+
basePath: string;
|
|
160
|
+
skills: Map<string, SkillMetadata>;
|
|
161
|
+
errors: SkillError[];
|
|
162
|
+
}
|
|
163
|
+
export interface SkillError {
|
|
164
|
+
skillPath: string;
|
|
165
|
+
message: string;
|
|
166
|
+
}
|
|
167
|
+
export interface SkillValidationResult {
|
|
168
|
+
isValid: boolean;
|
|
169
|
+
skill?: Skill;
|
|
170
|
+
errors: string[];
|
|
171
|
+
}
|
|
172
|
+
export interface SkillDiscoveryResult {
|
|
173
|
+
personalSkills: Map<string, SkillMetadata>;
|
|
174
|
+
projectSkills: Map<string, SkillMetadata>;
|
|
175
|
+
errors: SkillError[];
|
|
176
|
+
}
|
|
177
|
+
export interface SkillInvocationContext {
|
|
178
|
+
skillName: string;
|
|
179
|
+
}
|
|
180
|
+
export interface SkillToolArgs {
|
|
181
|
+
skill_name: string;
|
|
182
|
+
}
|
|
183
|
+
export interface SkillManagerOptions {
|
|
184
|
+
personalSkillsPath?: string;
|
|
185
|
+
scanTimeout?: number;
|
|
186
|
+
logger?: Logger;
|
|
187
|
+
}
|
|
188
|
+
export interface ParsedSkillFile {
|
|
189
|
+
frontmatter: SkillFrontmatter;
|
|
190
|
+
content: string;
|
|
191
|
+
skillMetadata: SkillMetadata;
|
|
192
|
+
validationErrors: string[];
|
|
193
|
+
isValid: boolean;
|
|
194
|
+
}
|
|
195
|
+
export interface SkillParseOptions {
|
|
196
|
+
validateMetadata?: boolean;
|
|
197
|
+
basePath?: string;
|
|
198
|
+
}
|
|
199
|
+
export declare const SKILL_DEFAULTS: {
|
|
200
|
+
readonly PERSONAL_SKILLS_DIR: ".wave/skills";
|
|
201
|
+
readonly PROJECT_SKILLS_DIR: ".wave/skills";
|
|
202
|
+
readonly SKILL_FILE_NAME: "SKILL.md";
|
|
203
|
+
readonly MAX_NAME_LENGTH: 64;
|
|
204
|
+
readonly MAX_DESCRIPTION_LENGTH: 1024;
|
|
205
|
+
readonly MIN_DESCRIPTION_LENGTH: 1;
|
|
206
|
+
readonly NAME_PATTERN: RegExp;
|
|
207
|
+
readonly MAX_METADATA_CACHE: 1000;
|
|
208
|
+
readonly MAX_CONTENT_CACHE: 100;
|
|
209
|
+
readonly SCAN_TIMEOUT: 5000;
|
|
210
|
+
readonly LOAD_TIMEOUT: 2000;
|
|
211
|
+
};
|
|
212
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAA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+
MAX_DESCRIPTION_LENGTH: 1024,
|
|
7
|
+
MIN_DESCRIPTION_LENGTH: 1,
|
|
8
|
+
NAME_PATTERN: /^[a-z0-9-]+$/,
|
|
9
|
+
MAX_METADATA_CACHE: 1000,
|
|
10
|
+
MAX_CONTENT_CACHE: 100,
|
|
11
|
+
SCAN_TIMEOUT: 5000,
|
|
12
|
+
LOAD_TIMEOUT: 2000,
|
|
13
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bash command history management module
|
|
3
|
+
* Used for persistent storage and searching of bash commands executed by users
|
|
4
|
+
*/
|
|
5
|
+
export interface BashHistoryEntry {
|
|
6
|
+
command: string;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
workdir: string;
|
|
9
|
+
}
|
|
10
|
+
export interface BashHistory {
|
|
11
|
+
commands: BashHistoryEntry[];
|
|
12
|
+
version: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Load bash history
|
|
16
|
+
*/
|
|
17
|
+
export declare const loadBashHistory: () => BashHistory;
|
|
18
|
+
/**
|
|
19
|
+
* Save bash history
|
|
20
|
+
*/
|
|
21
|
+
export declare const saveBashHistory: (history: BashHistory) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Add command to bash history
|
|
24
|
+
*/
|
|
25
|
+
export declare const addBashCommandToHistory: (command: string, workdir: string) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Search bash history by keywords
|
|
28
|
+
*/
|
|
29
|
+
export declare const searchBashHistory: (query: string, limit: number | undefined, workdir: string) => BashHistoryEntry[];
|
|
30
|
+
/**
|
|
31
|
+
* Get recently used bash commands
|
|
32
|
+
*/
|
|
33
|
+
export declare const getRecentBashCommands: (workdir: string, limit?: number) => BashHistoryEntry[];
|
|
34
|
+
/**
|
|
35
|
+
* Clear bash history
|
|
36
|
+
*/
|
|
37
|
+
export declare const clearBashHistory: () => void;
|
|
38
|
+
/**
|
|
39
|
+
* Get bash command statistics
|
|
40
|
+
*/
|
|
41
|
+
export declare const getBashCommandStats: () => {
|
|
42
|
+
totalCommands: number;
|
|
43
|
+
uniqueCommands: number;
|
|
44
|
+
workdirs: string[];
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=bashHistory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bashHistory.d.ts","sourceRoot":"","sources":["../../src/utils/bashHistory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;CACjB;AAkBD;;GAEG;AACH,eAAO,MAAM,eAAe,QAAO,WA+BlC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,SAAS,WAAW,KAAG,IAoBtD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAClC,SAAS,MAAM,EACf,SAAS,MAAM,KACd,IAkCF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAC5B,OAAO,MAAM,EACb,OAAO,MAAM,YAAK,EAClB,SAAS,MAAM,KACd,gBAAgB,EAiElB,CAAC;AAwBF;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAChC,SAAS,MAAM,EACf,QAAO,MAAW,KACjB,gBAAgB,EAclB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,QAAO,IAWnC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,QAAO;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,EAAE,CAAC;CAwBpB,CAAC"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bash command history management module
|
|
3
|
+
* Used for persistent storage and searching of bash commands executed by users
|
|
4
|
+
*/
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import { BASH_HISTORY_FILE, DATA_DIRECTORY } from "./constants.js";
|
|
7
|
+
const HISTORY_VERSION = 1;
|
|
8
|
+
const MAX_HISTORY_SIZE = 1000;
|
|
9
|
+
/**
|
|
10
|
+
* Ensure data directory exists
|
|
11
|
+
*/
|
|
12
|
+
const ensureDataDirectory = () => {
|
|
13
|
+
try {
|
|
14
|
+
if (!fs.existsSync(DATA_DIRECTORY)) {
|
|
15
|
+
fs.mkdirSync(DATA_DIRECTORY, { recursive: true });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// logger.debug("Failed to create data directory:", error);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Load bash history
|
|
24
|
+
*/
|
|
25
|
+
export const loadBashHistory = () => {
|
|
26
|
+
try {
|
|
27
|
+
ensureDataDirectory();
|
|
28
|
+
if (!fs.existsSync(BASH_HISTORY_FILE)) {
|
|
29
|
+
return {
|
|
30
|
+
commands: [],
|
|
31
|
+
version: HISTORY_VERSION,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const data = fs.readFileSync(BASH_HISTORY_FILE, "utf-8");
|
|
35
|
+
const history = JSON.parse(data);
|
|
36
|
+
// Version compatibility check
|
|
37
|
+
if (history.version !== HISTORY_VERSION) {
|
|
38
|
+
// logger.debug("Bash history version mismatch, resetting history");
|
|
39
|
+
return {
|
|
40
|
+
commands: [],
|
|
41
|
+
version: HISTORY_VERSION,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return history;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// logger.debug("Failed to load bash history:", error);
|
|
48
|
+
return {
|
|
49
|
+
commands: [],
|
|
50
|
+
version: HISTORY_VERSION,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Save bash history
|
|
56
|
+
*/
|
|
57
|
+
export const saveBashHistory = (history) => {
|
|
58
|
+
try {
|
|
59
|
+
// Skip saving to file when in test environment
|
|
60
|
+
if (process.env.NODE_ENV === "test") {
|
|
61
|
+
// logger.debug("Skipping bash history save in test environment");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
ensureDataDirectory();
|
|
65
|
+
// Limit history size
|
|
66
|
+
if (history.commands.length > MAX_HISTORY_SIZE) {
|
|
67
|
+
history.commands = history.commands.slice(-MAX_HISTORY_SIZE);
|
|
68
|
+
}
|
|
69
|
+
const data = JSON.stringify(history, null, 2);
|
|
70
|
+
fs.writeFileSync(BASH_HISTORY_FILE, data, "utf-8");
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// logger.debug("Failed to save bash history:", error);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Add command to bash history
|
|
78
|
+
*/
|
|
79
|
+
export const addBashCommandToHistory = (command, workdir) => {
|
|
80
|
+
try {
|
|
81
|
+
// Filter system-generated commands, do not add to history
|
|
82
|
+
if (command.startsWith("git add . && git commit -m")) {
|
|
83
|
+
// logger.debug("Skipping system-generated command:", { command, workdir });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const history = loadBashHistory();
|
|
87
|
+
const timestamp = Date.now();
|
|
88
|
+
// Check if it's a duplicate consecutive command to avoid duplicate recording
|
|
89
|
+
const lastCommand = history.commands[history.commands.length - 1];
|
|
90
|
+
if (lastCommand &&
|
|
91
|
+
lastCommand.command === command &&
|
|
92
|
+
lastCommand.workdir === workdir) {
|
|
93
|
+
// Update timestamp of the last record
|
|
94
|
+
lastCommand.timestamp = timestamp;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// Add new command record
|
|
98
|
+
history.commands.push({
|
|
99
|
+
command,
|
|
100
|
+
timestamp,
|
|
101
|
+
workdir,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
saveBashHistory(history);
|
|
105
|
+
// logger.debug("Added bash command to history:", { command, workdir });
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// logger.debug("Failed to add bash command to history:", error);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Search bash history by keywords
|
|
113
|
+
*/
|
|
114
|
+
export const searchBashHistory = (query, limit = 10, workdir) => {
|
|
115
|
+
try {
|
|
116
|
+
const history = loadBashHistory();
|
|
117
|
+
const normalizedQuery = query.toLowerCase().trim();
|
|
118
|
+
let filteredCommands = history.commands;
|
|
119
|
+
// Working directory filter
|
|
120
|
+
filteredCommands = filteredCommands.filter((entry) => entry.workdir === workdir);
|
|
121
|
+
if (!normalizedQuery) {
|
|
122
|
+
// If no search query, return recent commands (deduplicated)
|
|
123
|
+
const deduped = deduplicateCommands(filteredCommands);
|
|
124
|
+
return deduped.slice(-limit).reverse(); // Latest first
|
|
125
|
+
}
|
|
126
|
+
// Search by relevance
|
|
127
|
+
const matches = filteredCommands
|
|
128
|
+
.filter((entry) => {
|
|
129
|
+
// Command content matching
|
|
130
|
+
const command = entry.command.toLowerCase();
|
|
131
|
+
return command.includes(normalizedQuery);
|
|
132
|
+
})
|
|
133
|
+
.map((entry) => {
|
|
134
|
+
// Calculate match score
|
|
135
|
+
const command = entry.command.toLowerCase();
|
|
136
|
+
let score = 0;
|
|
137
|
+
// Exact match gets higher score
|
|
138
|
+
if (command.includes(normalizedQuery)) {
|
|
139
|
+
score += 10;
|
|
140
|
+
}
|
|
141
|
+
// Command prefix match gets higher score
|
|
142
|
+
if (command.startsWith(normalizedQuery)) {
|
|
143
|
+
score += 20;
|
|
144
|
+
}
|
|
145
|
+
// Word boundary match gets higher score
|
|
146
|
+
const words = command.split(/\s+/);
|
|
147
|
+
if (words.some((word) => word.startsWith(normalizedQuery))) {
|
|
148
|
+
score += 15;
|
|
149
|
+
}
|
|
150
|
+
// Timestamp influence (newer gets higher score)
|
|
151
|
+
score += entry.timestamp / 1000000; // Normalize timestamp
|
|
152
|
+
return { entry, score };
|
|
153
|
+
})
|
|
154
|
+
.sort((a, b) => b.score - a.score) // Sort by score descending
|
|
155
|
+
.map((item) => item.entry);
|
|
156
|
+
// Deduplicate search results, keep latest record
|
|
157
|
+
const dedupedMatches = deduplicateCommands(matches);
|
|
158
|
+
const result = dedupedMatches.slice(0, limit);
|
|
159
|
+
// logger.debug("Bash history search results:", { query, workdir: process.cwd(), originalCount: matches.length, dedupedCount: result.length });
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
// logger.debug("Failed to search bash history:", error);
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Deduplicate command list, keep latest record for each command
|
|
169
|
+
*/
|
|
170
|
+
const deduplicateCommands = (commands) => {
|
|
171
|
+
const commandMap = new Map();
|
|
172
|
+
// Iterate through all commands, keep latest record for each
|
|
173
|
+
for (const entry of commands) {
|
|
174
|
+
const existing = commandMap.get(entry.command);
|
|
175
|
+
if (!existing || entry.timestamp > existing.timestamp) {
|
|
176
|
+
commandMap.set(entry.command, entry);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// Sort by timestamp and return
|
|
180
|
+
return Array.from(commandMap.values()).sort((a, b) => a.timestamp - b.timestamp);
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Get recently used bash commands
|
|
184
|
+
*/
|
|
185
|
+
export const getRecentBashCommands = (workdir, limit = 10) => {
|
|
186
|
+
try {
|
|
187
|
+
const history = loadBashHistory();
|
|
188
|
+
const filtered = history.commands.filter((entry) => entry.workdir === workdir);
|
|
189
|
+
// Return recent commands after deduplication
|
|
190
|
+
const deduped = deduplicateCommands(filtered);
|
|
191
|
+
return deduped.slice(-limit).reverse(); // Latest first
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
// logger.debug("Failed to get recent bash commands:", error);
|
|
195
|
+
return [];
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Clear bash history
|
|
200
|
+
*/
|
|
201
|
+
export const clearBashHistory = () => {
|
|
202
|
+
try {
|
|
203
|
+
const history = {
|
|
204
|
+
commands: [],
|
|
205
|
+
version: HISTORY_VERSION,
|
|
206
|
+
};
|
|
207
|
+
saveBashHistory(history);
|
|
208
|
+
// logger.debug("Bash history cleared");
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
// logger.debug("Failed to clear bash history:", error);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Get bash command statistics
|
|
216
|
+
*/
|
|
217
|
+
export const getBashCommandStats = () => {
|
|
218
|
+
try {
|
|
219
|
+
const history = loadBashHistory();
|
|
220
|
+
const uniqueCommands = new Set(history.commands.map((entry) => entry.command));
|
|
221
|
+
const workdirs = Array.from(new Set(history.commands.map((entry) => entry.workdir)));
|
|
222
|
+
return {
|
|
223
|
+
totalCommands: history.commands.length,
|
|
224
|
+
uniqueCommands: uniqueCommands.size,
|
|
225
|
+
workdirs,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
// logger.debug("Failed to get bash command stats:", error);
|
|
230
|
+
return {
|
|
231
|
+
totalCommands: 0,
|
|
232
|
+
uniqueCommands: 0,
|
|
233
|
+
workdirs: [],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command Argument Parser
|
|
3
|
+
*
|
|
4
|
+
* Provides parameter substitution for custom slash commands similar to Claude's system:
|
|
5
|
+
* - $ARGUMENTS: All arguments as a single string
|
|
6
|
+
* - $1, $2, $3, etc.: Individual positional arguments
|
|
7
|
+
* - Supports quoted arguments with spaces
|
|
8
|
+
* - Handles escaped quotes within arguments
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Parse command arguments from a string, respecting quotes
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseCommandArguments(argsString: string): string[];
|
|
14
|
+
/**
|
|
15
|
+
* Substitute command parameters in content
|
|
16
|
+
*/
|
|
17
|
+
export declare function substituteCommandParameters(content: string, argsString: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Extract command name and arguments from a slash command input
|
|
20
|
+
* Example: "/fix-issue 123 high-priority" -> { command: "fix-issue", args: "123 high-priority" }
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseSlashCommandInput(input: string): {
|
|
23
|
+
command: string;
|
|
24
|
+
args: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Check if content contains parameter placeholders
|
|
28
|
+
*/
|
|
29
|
+
export declare function hasParameterPlaceholders(content: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Get all parameter placeholders used in content
|
|
32
|
+
*/
|
|
33
|
+
export declare function getUsedParameterPlaceholders(content: string): string[];
|
|
34
|
+
//# sourceMappingURL=commandArgumentParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandArgumentParser.d.ts","sourceRoot":"","sources":["../../src/utils/commandArgumentParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CA+DlE;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,MAAM,CAsBR;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,CAsBA;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEjE;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAGtE"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command Argument Parser
|
|
3
|
+
*
|
|
4
|
+
* Provides parameter substitution for custom slash commands similar to Claude's system:
|
|
5
|
+
* - $ARGUMENTS: All arguments as a single string
|
|
6
|
+
* - $1, $2, $3, etc.: Individual positional arguments
|
|
7
|
+
* - Supports quoted arguments with spaces
|
|
8
|
+
* - Handles escaped quotes within arguments
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Parse command arguments from a string, respecting quotes
|
|
12
|
+
*/
|
|
13
|
+
export function parseCommandArguments(argsString) {
|
|
14
|
+
if (!argsString.trim()) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
const args = [];
|
|
18
|
+
let current = "";
|
|
19
|
+
let inQuotes = false;
|
|
20
|
+
let quoteChar = "";
|
|
21
|
+
let escaped = false;
|
|
22
|
+
for (let i = 0; i < argsString.length; i++) {
|
|
23
|
+
const char = argsString[i];
|
|
24
|
+
const nextChar = argsString[i + 1];
|
|
25
|
+
if (escaped) {
|
|
26
|
+
current += char;
|
|
27
|
+
escaped = false;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (char === "\\") {
|
|
31
|
+
// Handle escape sequences
|
|
32
|
+
if (inQuotes && (nextChar === quoteChar || nextChar === "\\")) {
|
|
33
|
+
escaped = true;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
current += char;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (!inQuotes && (char === '"' || char === "'")) {
|
|
40
|
+
// Start quoted string
|
|
41
|
+
inQuotes = true;
|
|
42
|
+
quoteChar = char;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (inQuotes && char === quoteChar) {
|
|
46
|
+
// End quoted string
|
|
47
|
+
inQuotes = false;
|
|
48
|
+
quoteChar = "";
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (!inQuotes && /\s/.test(char)) {
|
|
52
|
+
// Whitespace outside quotes - end current argument
|
|
53
|
+
if (current) {
|
|
54
|
+
args.push(current);
|
|
55
|
+
current = "";
|
|
56
|
+
}
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
current += char;
|
|
60
|
+
}
|
|
61
|
+
// Add final argument if any
|
|
62
|
+
if (current) {
|
|
63
|
+
args.push(current);
|
|
64
|
+
}
|
|
65
|
+
return args;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Substitute command parameters in content
|
|
69
|
+
*/
|
|
70
|
+
export function substituteCommandParameters(content, argsString) {
|
|
71
|
+
const args = parseCommandArguments(argsString);
|
|
72
|
+
let result = content;
|
|
73
|
+
// Replace $ARGUMENTS with all arguments
|
|
74
|
+
result = result.replace(/\$ARGUMENTS/g, argsString);
|
|
75
|
+
// Replace positional parameters $1, $2, etc.
|
|
76
|
+
// Sort by parameter number (descending) to avoid replacing $10 with $1 + "0"
|
|
77
|
+
const positionalParams = [...result.matchAll(/\$(\d+)/g)]
|
|
78
|
+
.map((match) => parseInt(match[1], 10))
|
|
79
|
+
.filter((value, index, array) => array.indexOf(value) === index) // unique
|
|
80
|
+
.sort((a, b) => b - a); // descending order
|
|
81
|
+
for (const paramNum of positionalParams) {
|
|
82
|
+
const paramValue = args[paramNum - 1] || ""; // Arrays are 0-indexed, params are 1-indexed
|
|
83
|
+
const paramRegex = new RegExp(`\\$${paramNum}`, "g");
|
|
84
|
+
result = result.replace(paramRegex, paramValue);
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Extract command name and arguments from a slash command input
|
|
90
|
+
* Example: "/fix-issue 123 high-priority" -> { command: "fix-issue", args: "123 high-priority" }
|
|
91
|
+
*/
|
|
92
|
+
export function parseSlashCommandInput(input) {
|
|
93
|
+
const trimmed = input.trim();
|
|
94
|
+
if (!trimmed.startsWith("/")) {
|
|
95
|
+
throw new Error("Input must start with /");
|
|
96
|
+
}
|
|
97
|
+
const withoutSlash = trimmed.substring(1);
|
|
98
|
+
const firstSpaceIndex = withoutSlash.indexOf(" ");
|
|
99
|
+
if (firstSpaceIndex === -1) {
|
|
100
|
+
// No arguments
|
|
101
|
+
return {
|
|
102
|
+
command: withoutSlash,
|
|
103
|
+
args: "",
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
command: withoutSlash.substring(0, firstSpaceIndex),
|
|
108
|
+
args: withoutSlash.substring(firstSpaceIndex + 1).trim(),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Check if content contains parameter placeholders
|
|
113
|
+
*/
|
|
114
|
+
export function hasParameterPlaceholders(content) {
|
|
115
|
+
return /\$(?:ARGUMENTS|\d+)/.test(content);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get all parameter placeholders used in content
|
|
119
|
+
*/
|
|
120
|
+
export function getUsedParameterPlaceholders(content) {
|
|
121
|
+
const matches = content.match(/\$(?:ARGUMENTS|\d+)/g);
|
|
122
|
+
return matches ? [...new Set(matches)] : [];
|
|
123
|
+
}
|