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.
Files changed (170) hide show
  1. package/README.md +32 -0
  2. package/dist/agent.d.ts +96 -0
  3. package/dist/agent.d.ts.map +1 -0
  4. package/dist/agent.js +286 -0
  5. package/dist/hooks/executor.d.ts +56 -0
  6. package/dist/hooks/executor.d.ts.map +1 -0
  7. package/dist/hooks/executor.js +312 -0
  8. package/dist/hooks/index.d.ts +17 -0
  9. package/dist/hooks/index.d.ts.map +1 -0
  10. package/dist/hooks/index.js +14 -0
  11. package/dist/hooks/manager.d.ts +90 -0
  12. package/dist/hooks/manager.d.ts.map +1 -0
  13. package/dist/hooks/manager.js +395 -0
  14. package/dist/hooks/matcher.d.ts +49 -0
  15. package/dist/hooks/matcher.d.ts.map +1 -0
  16. package/dist/hooks/matcher.js +147 -0
  17. package/dist/hooks/settings.d.ts +46 -0
  18. package/dist/hooks/settings.d.ts.map +1 -0
  19. package/dist/hooks/settings.js +100 -0
  20. package/dist/hooks/types.d.ts +80 -0
  21. package/dist/hooks/types.d.ts.map +1 -0
  22. package/dist/hooks/types.js +59 -0
  23. package/dist/index.d.ts +16 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +20 -0
  26. package/dist/managers/aiManager.d.ts +61 -0
  27. package/dist/managers/aiManager.d.ts.map +1 -0
  28. package/dist/managers/aiManager.js +415 -0
  29. package/dist/managers/backgroundBashManager.d.ts +27 -0
  30. package/dist/managers/backgroundBashManager.d.ts.map +1 -0
  31. package/dist/managers/backgroundBashManager.js +166 -0
  32. package/dist/managers/bashManager.d.ts +20 -0
  33. package/dist/managers/bashManager.d.ts.map +1 -0
  34. package/dist/managers/bashManager.js +66 -0
  35. package/dist/managers/mcpManager.d.ts +63 -0
  36. package/dist/managers/mcpManager.d.ts.map +1 -0
  37. package/dist/managers/mcpManager.js +378 -0
  38. package/dist/managers/messageManager.d.ts +85 -0
  39. package/dist/managers/messageManager.d.ts.map +1 -0
  40. package/dist/managers/messageManager.js +265 -0
  41. package/dist/managers/skillManager.d.ts +59 -0
  42. package/dist/managers/skillManager.d.ts.map +1 -0
  43. package/dist/managers/skillManager.js +317 -0
  44. package/dist/managers/slashCommandManager.d.ts +77 -0
  45. package/dist/managers/slashCommandManager.d.ts.map +1 -0
  46. package/dist/managers/slashCommandManager.js +208 -0
  47. package/dist/managers/toolManager.d.ts +23 -0
  48. package/dist/managers/toolManager.d.ts.map +1 -0
  49. package/dist/managers/toolManager.js +79 -0
  50. package/dist/services/aiService.d.ts +28 -0
  51. package/dist/services/aiService.d.ts.map +1 -0
  52. package/dist/services/aiService.js +180 -0
  53. package/dist/services/memory.d.ts +8 -0
  54. package/dist/services/memory.d.ts.map +1 -0
  55. package/dist/services/memory.js +128 -0
  56. package/dist/services/session.d.ts +54 -0
  57. package/dist/services/session.d.ts.map +1 -0
  58. package/dist/services/session.js +196 -0
  59. package/dist/tools/bashTool.d.ts +14 -0
  60. package/dist/tools/bashTool.d.ts.map +1 -0
  61. package/dist/tools/bashTool.js +351 -0
  62. package/dist/tools/deleteFileTool.d.ts +6 -0
  63. package/dist/tools/deleteFileTool.d.ts.map +1 -0
  64. package/dist/tools/deleteFileTool.js +67 -0
  65. package/dist/tools/editTool.d.ts +6 -0
  66. package/dist/tools/editTool.d.ts.map +1 -0
  67. package/dist/tools/editTool.js +168 -0
  68. package/dist/tools/globTool.d.ts +6 -0
  69. package/dist/tools/globTool.d.ts.map +1 -0
  70. package/dist/tools/globTool.js +113 -0
  71. package/dist/tools/grepTool.d.ts +6 -0
  72. package/dist/tools/grepTool.d.ts.map +1 -0
  73. package/dist/tools/grepTool.js +268 -0
  74. package/dist/tools/lsTool.d.ts +6 -0
  75. package/dist/tools/lsTool.d.ts.map +1 -0
  76. package/dist/tools/lsTool.js +160 -0
  77. package/dist/tools/multiEditTool.d.ts +6 -0
  78. package/dist/tools/multiEditTool.d.ts.map +1 -0
  79. package/dist/tools/multiEditTool.js +222 -0
  80. package/dist/tools/readTool.d.ts +6 -0
  81. package/dist/tools/readTool.d.ts.map +1 -0
  82. package/dist/tools/readTool.js +136 -0
  83. package/dist/tools/types.d.ts +35 -0
  84. package/dist/tools/types.d.ts.map +1 -0
  85. package/dist/tools/types.js +4 -0
  86. package/dist/tools/writeTool.d.ts +6 -0
  87. package/dist/tools/writeTool.d.ts.map +1 -0
  88. package/dist/tools/writeTool.js +138 -0
  89. package/dist/types.d.ts +212 -0
  90. package/dist/types.d.ts.map +1 -0
  91. package/dist/types.js +13 -0
  92. package/dist/utils/bashHistory.d.ts +46 -0
  93. package/dist/utils/bashHistory.d.ts.map +1 -0
  94. package/dist/utils/bashHistory.js +236 -0
  95. package/dist/utils/commandArgumentParser.d.ts +34 -0
  96. package/dist/utils/commandArgumentParser.d.ts.map +1 -0
  97. package/dist/utils/commandArgumentParser.js +123 -0
  98. package/dist/utils/constants.d.ts +27 -0
  99. package/dist/utils/constants.d.ts.map +1 -0
  100. package/dist/utils/constants.js +28 -0
  101. package/dist/utils/convertMessagesForAPI.d.ts +9 -0
  102. package/dist/utils/convertMessagesForAPI.d.ts.map +1 -0
  103. package/dist/utils/convertMessagesForAPI.js +189 -0
  104. package/dist/utils/customCommands.d.ts +14 -0
  105. package/dist/utils/customCommands.d.ts.map +1 -0
  106. package/dist/utils/customCommands.js +71 -0
  107. package/dist/utils/fileFilter.d.ts +26 -0
  108. package/dist/utils/fileFilter.d.ts.map +1 -0
  109. package/dist/utils/fileFilter.js +177 -0
  110. package/dist/utils/markdownParser.d.ts +27 -0
  111. package/dist/utils/markdownParser.d.ts.map +1 -0
  112. package/dist/utils/markdownParser.js +109 -0
  113. package/dist/utils/mcpUtils.d.ts +24 -0
  114. package/dist/utils/mcpUtils.d.ts.map +1 -0
  115. package/dist/utils/mcpUtils.js +51 -0
  116. package/dist/utils/messageOperations.d.ts +118 -0
  117. package/dist/utils/messageOperations.d.ts.map +1 -0
  118. package/dist/utils/messageOperations.js +334 -0
  119. package/dist/utils/path.d.ts +25 -0
  120. package/dist/utils/path.d.ts.map +1 -0
  121. package/dist/utils/path.js +109 -0
  122. package/dist/utils/skillParser.d.ts +18 -0
  123. package/dist/utils/skillParser.d.ts.map +1 -0
  124. package/dist/utils/skillParser.js +147 -0
  125. package/dist/utils/stringUtils.d.ts +13 -0
  126. package/dist/utils/stringUtils.d.ts.map +1 -0
  127. package/dist/utils/stringUtils.js +44 -0
  128. package/package.json +51 -0
  129. package/src/agent.ts +405 -0
  130. package/src/hooks/executor.ts +440 -0
  131. package/src/hooks/index.ts +52 -0
  132. package/src/hooks/manager.ts +618 -0
  133. package/src/hooks/matcher.ts +187 -0
  134. package/src/hooks/settings.ts +129 -0
  135. package/src/hooks/types.ts +169 -0
  136. package/src/index.ts +24 -0
  137. package/src/managers/aiManager.ts +573 -0
  138. package/src/managers/backgroundBashManager.ts +203 -0
  139. package/src/managers/bashManager.ts +97 -0
  140. package/src/managers/mcpManager.ts +493 -0
  141. package/src/managers/messageManager.ts +415 -0
  142. package/src/managers/skillManager.ts +404 -0
  143. package/src/managers/slashCommandManager.ts +293 -0
  144. package/src/managers/toolManager.ts +106 -0
  145. package/src/services/aiService.ts +252 -0
  146. package/src/services/memory.ts +149 -0
  147. package/src/services/session.ts +265 -0
  148. package/src/tools/bashTool.ts +402 -0
  149. package/src/tools/deleteFileTool.ts +81 -0
  150. package/src/tools/editTool.ts +192 -0
  151. package/src/tools/globTool.ts +135 -0
  152. package/src/tools/grepTool.ts +326 -0
  153. package/src/tools/lsTool.ts +187 -0
  154. package/src/tools/multiEditTool.ts +268 -0
  155. package/src/tools/readTool.ts +165 -0
  156. package/src/tools/types.ts +47 -0
  157. package/src/tools/writeTool.ts +163 -0
  158. package/src/types.ts +260 -0
  159. package/src/utils/bashHistory.ts +303 -0
  160. package/src/utils/commandArgumentParser.ts +153 -0
  161. package/src/utils/constants.ts +37 -0
  162. package/src/utils/convertMessagesForAPI.ts +236 -0
  163. package/src/utils/customCommands.ts +85 -0
  164. package/src/utils/fileFilter.ts +202 -0
  165. package/src/utils/markdownParser.ts +156 -0
  166. package/src/utils/mcpUtils.ts +81 -0
  167. package/src/utils/messageOperations.ts +506 -0
  168. package/src/utils/path.ts +118 -0
  169. package/src/utils/skillParser.ts +188 -0
  170. package/src/utils/stringUtils.ts +50 -0
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Application constants definition
3
+ */
4
+ /**
5
+ * Application data storage directory
6
+ * Used to store debug logs, command history and other data
7
+ */
8
+ export declare const DATA_DIRECTORY: string;
9
+ /**
10
+ * Bash command history file path
11
+ */
12
+ export declare const BASH_HISTORY_FILE: string;
13
+ /**
14
+ * Error log directory path
15
+ */
16
+ export declare const ERROR_LOG_DIRECTORY: string;
17
+ /**
18
+ * User-level memory file path
19
+ */
20
+ export declare const USER_MEMORY_FILE: string;
21
+ /**
22
+ * AI related constants
23
+ */
24
+ export declare const DEFAULT_TOKEN_LIMIT = 64000;
25
+ export declare const FAST_MODEL_ID: string;
26
+ export declare const AGENT_MODEL_ID: string;
27
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH;;;GAGG;AACH,eAAO,MAAM,cAAc,QAAmC,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,iBAAiB,QAAiD,CAAC;AAEhF;;GAEG;AACH,eAAO,MAAM,mBAAmB,QAA0C,CAAC;AAE3E;;GAEG;AACH,eAAO,MAAM,gBAAgB,QAA8C,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC,eAAO,MAAM,aAAa,QAAoD,CAAC;AAE/E,eAAO,MAAM,cAAc,QAC2B,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Application constants definition
3
+ */
4
+ import path from "path";
5
+ import os from "os";
6
+ /**
7
+ * Application data storage directory
8
+ * Used to store debug logs, command history and other data
9
+ */
10
+ export const DATA_DIRECTORY = path.join(os.homedir(), ".wave");
11
+ /**
12
+ * Bash command history file path
13
+ */
14
+ export const BASH_HISTORY_FILE = path.join(DATA_DIRECTORY, "bash-history.json");
15
+ /**
16
+ * Error log directory path
17
+ */
18
+ export const ERROR_LOG_DIRECTORY = path.join(DATA_DIRECTORY, "error-logs");
19
+ /**
20
+ * User-level memory file path
21
+ */
22
+ export const USER_MEMORY_FILE = path.join(DATA_DIRECTORY, "user-memory.md");
23
+ /**
24
+ * AI related constants
25
+ */
26
+ export const DEFAULT_TOKEN_LIMIT = 64000; // Default token limit
27
+ export const FAST_MODEL_ID = process.env.AIGW_FAST_MODEL || "gemini-2.5-flash";
28
+ export const AGENT_MODEL_ID = process.env.AIGW_MODEL || "claude-sonnet-4-20250514";
@@ -0,0 +1,9 @@
1
+ import type { Message } from "../types.js";
2
+ import { ChatCompletionMessageParam } from "openai/resources.js";
3
+ /**
4
+ * Convert message format to API call format, stopping when a compressed message is encountered
5
+ * @param messages Message list
6
+ * @returns Converted API message format list
7
+ */
8
+ export declare function convertMessagesForAPI(messages: Message[]): ChatCompletionMessageParam[];
9
+ //# sourceMappingURL=convertMessagesForAPI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertMessagesForAPI.d.ts","sourceRoot":"","sources":["../../src/utils/convertMessagesForAPI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAI3C,OAAO,EAEL,0BAA0B,EAC3B,MAAM,qBAAqB,CAAC;AAuB7B;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,OAAO,EAAE,GAClB,0BAA0B,EAAE,CAsM9B"}
@@ -0,0 +1,189 @@
1
+ import { convertImageToBase64 } from "./messageOperations.js";
2
+ import { stripAnsiColors } from "./stringUtils.js";
3
+ /**
4
+ * Safely handle tool call parameters, ensuring a legal JSON string is returned
5
+ * @param args Tool call parameters
6
+ * @returns Legal JSON string
7
+ */
8
+ function safeToolArguments(args) {
9
+ if (!args) {
10
+ return "{}";
11
+ }
12
+ try {
13
+ // Try to parse as JSON to validate format
14
+ JSON.parse(args);
15
+ return args;
16
+ }
17
+ catch {
18
+ // logger.error(`Invalid tool arguments: ${args}`);
19
+ // If not valid JSON, return a fallback empty object
20
+ return "{}";
21
+ }
22
+ }
23
+ /**
24
+ * Convert message format to API call format, stopping when a compressed message is encountered
25
+ * @param messages Message list
26
+ * @returns Converted API message format list
27
+ */
28
+ export function convertMessagesForAPI(messages) {
29
+ const recentMessages = [];
30
+ const startIndex = messages.length - 1;
31
+ for (let i = startIndex; i >= 0; i--) {
32
+ const message = messages[i];
33
+ // Check if a compression block is encountered, if so, stop iteration
34
+ if (message.role === "assistant" &&
35
+ message.blocks.some((block) => block.type === "compress")) {
36
+ // Add the content of the compression block as an assistant message to the history
37
+ const compressBlock = message.blocks.find((block) => block.type === "compress");
38
+ if (compressBlock && compressBlock.type === "compress") {
39
+ recentMessages.unshift({
40
+ role: "system",
41
+ content: `[Compressed Message Summary] ${compressBlock.content}`,
42
+ });
43
+ }
44
+ break;
45
+ }
46
+ // Skip empty assistant messages
47
+ if (message.role === "assistant" && message.blocks.length === 0) {
48
+ continue;
49
+ }
50
+ if (message.role === "assistant") {
51
+ // First check if there is a tool block, if so, add the tool message first
52
+ // Filter out incomplete tool blocks (no result or still running)
53
+ const toolBlocks = message.blocks.filter((block) => block.type === "tool");
54
+ const completedToolIds = new Set(); // Record completed tool IDs
55
+ if (toolBlocks.length > 0) {
56
+ toolBlocks.forEach((toolBlock) => {
57
+ // Only add completed tool blocks (i.e., not running)
58
+ if (toolBlock.id && !toolBlock.isRunning) {
59
+ completedToolIds.add(toolBlock.id);
60
+ // Check for image data
61
+ if (toolBlock.images && toolBlock.images.length > 0) {
62
+ // If there is an image, create a user message instead of a tool message
63
+ const contentParts = [];
64
+ // Add tool result as text
65
+ const toolResultText = `Tool result for ${toolBlock.name || "unknown tool"}:\n${stripAnsiColors(toolBlock.result || "")}`;
66
+ contentParts.push({
67
+ type: "text",
68
+ text: toolResultText,
69
+ });
70
+ // Add image
71
+ toolBlock.images.forEach((image) => {
72
+ const imageUrl = image.data.startsWith("data:")
73
+ ? image.data
74
+ : `data:${image.mediaType || "image/png"};base64,${image.data}`;
75
+ contentParts.push({
76
+ type: "image_url",
77
+ image_url: {
78
+ url: imageUrl,
79
+ detail: "auto",
80
+ },
81
+ });
82
+ });
83
+ // Add user message
84
+ recentMessages.unshift({
85
+ role: "user",
86
+ content: contentParts,
87
+ });
88
+ }
89
+ else {
90
+ // Normal tool message
91
+ recentMessages.unshift({
92
+ tool_call_id: toolBlock.id,
93
+ role: "tool",
94
+ content: stripAnsiColors(toolBlock.result || ""),
95
+ });
96
+ }
97
+ }
98
+ });
99
+ }
100
+ // Construct the content of the assistant message
101
+ let content = "";
102
+ let tool_calls = undefined;
103
+ // Construct content from text blocks
104
+ const textBlocks = message.blocks.filter((block) => block.type === "text");
105
+ if (textBlocks.length > 0) {
106
+ content = textBlocks.map((block) => block.content || "").join("\n");
107
+ }
108
+ // Construct tool calls from tool blocks
109
+ if (toolBlocks.length > 0) {
110
+ tool_calls = toolBlocks
111
+ .filter((toolBlock) => toolBlock.id && completedToolIds.has(toolBlock.id))
112
+ .map((toolBlock) => ({
113
+ id: toolBlock.id,
114
+ type: "function",
115
+ function: {
116
+ name: toolBlock.name || "",
117
+ arguments: safeToolArguments(String(toolBlock.parameters || "{}")),
118
+ },
119
+ }));
120
+ if (tool_calls.length === 0) {
121
+ tool_calls = undefined;
122
+ }
123
+ }
124
+ // Construct assistant message - only add if there is content or tool calls
125
+ if (content || tool_calls) {
126
+ const assistantMessage = {
127
+ role: "assistant",
128
+ content,
129
+ tool_calls,
130
+ };
131
+ recentMessages.unshift(assistantMessage);
132
+ }
133
+ }
134
+ else if (message.role === "user") {
135
+ // User messages converted to standard format
136
+ const contentParts = [];
137
+ message.blocks.forEach((block) => {
138
+ // Add text content
139
+ if (block.type === "text" && block.content) {
140
+ contentParts.push({
141
+ type: "text",
142
+ text: block.content,
143
+ });
144
+ }
145
+ // Handle custom command blocks - pass full content as text to AI
146
+ if (block.type === "custom_command" && block.content) {
147
+ contentParts.push({
148
+ type: "text",
149
+ text: block.content,
150
+ });
151
+ }
152
+ // If there is an image, add image content
153
+ if (block.type === "image" &&
154
+ block.imageUrls &&
155
+ block.imageUrls.length > 0) {
156
+ block.imageUrls.forEach((imageUrl) => {
157
+ // Check if it's already base64, convert if not
158
+ let finalImageUrl = imageUrl;
159
+ if (!imageUrl.startsWith("data:image/")) {
160
+ // If it's a file path, it needs to be converted to base64
161
+ try {
162
+ finalImageUrl = convertImageToBase64(imageUrl);
163
+ }
164
+ catch (error) {
165
+ console.error("Failed to convert image path to base64:", imageUrl, error);
166
+ // Skip this image, do not add to content
167
+ return;
168
+ }
169
+ }
170
+ contentParts.push({
171
+ type: "image_url",
172
+ image_url: {
173
+ url: finalImageUrl,
174
+ detail: "auto",
175
+ },
176
+ });
177
+ });
178
+ }
179
+ });
180
+ if (contentParts.length > 0) {
181
+ recentMessages.unshift({
182
+ role: "user",
183
+ content: contentParts,
184
+ });
185
+ }
186
+ }
187
+ }
188
+ return recentMessages;
189
+ }
@@ -0,0 +1,14 @@
1
+ import type { CustomSlashCommand } from "../types.js";
2
+ /**
3
+ * Get the project-specific commands directory
4
+ */
5
+ export declare function getProjectCommandsDir(workdir: string): string;
6
+ /**
7
+ * Get the user-specific commands directory
8
+ */
9
+ export declare function getUserCommandsDir(): string;
10
+ /**
11
+ * Load all custom slash commands from both project and user directories
12
+ */
13
+ export declare function loadCustomSlashCommands(workdir: string): CustomSlashCommand[];
14
+ //# sourceMappingURL=customCommands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customCommands.d.ts","sourceRoot":"","sources":["../../src/utils/customCommands.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGtD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AA6CD;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAkB7E"}
@@ -0,0 +1,71 @@
1
+ import { existsSync, readdirSync } from "fs";
2
+ import { join, extname, basename } from "path";
3
+ import { homedir } from "os";
4
+ import { parseMarkdownFile } from "./markdownParser.js";
5
+ /**
6
+ * Get the project-specific commands directory
7
+ */
8
+ export function getProjectCommandsDir(workdir) {
9
+ return join(workdir, ".wave", "commands");
10
+ }
11
+ /**
12
+ * Get the user-specific commands directory
13
+ */
14
+ export function getUserCommandsDir() {
15
+ return join(homedir(), ".wave", "commands");
16
+ }
17
+ /**
18
+ * Scan a directory for markdown command files
19
+ */
20
+ function scanCommandsDirectory(dirPath) {
21
+ if (!existsSync(dirPath)) {
22
+ return [];
23
+ }
24
+ const commands = [];
25
+ try {
26
+ const files = readdirSync(dirPath);
27
+ for (const file of files) {
28
+ if (extname(file) !== ".md") {
29
+ continue;
30
+ }
31
+ const filePath = join(dirPath, file);
32
+ const commandName = basename(file, ".md");
33
+ try {
34
+ const { content, config } = parseMarkdownFile(filePath);
35
+ commands.push({
36
+ id: commandName,
37
+ name: commandName,
38
+ description: config?.description, // Use description from frontmatter
39
+ filePath,
40
+ content,
41
+ config,
42
+ });
43
+ }
44
+ catch (error) {
45
+ console.warn(`Failed to load custom command from ${filePath}:`, error);
46
+ }
47
+ }
48
+ }
49
+ catch (error) {
50
+ console.warn(`Failed to scan commands directory ${dirPath}:`, error);
51
+ }
52
+ return commands;
53
+ }
54
+ /**
55
+ * Load all custom slash commands from both project and user directories
56
+ */
57
+ export function loadCustomSlashCommands(workdir) {
58
+ const projectCommands = scanCommandsDirectory(getProjectCommandsDir(workdir));
59
+ const userCommands = scanCommandsDirectory(getUserCommandsDir());
60
+ // Project commands take precedence over user commands with the same name
61
+ const commandMap = new Map();
62
+ // Add user commands first
63
+ for (const command of userCommands) {
64
+ commandMap.set(command.id, command);
65
+ }
66
+ // Add project commands (will overwrite user commands with same name)
67
+ for (const command of projectCommands) {
68
+ commandMap.set(command.id, command);
69
+ }
70
+ return Array.from(commandMap.values());
71
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Common ignore directory and file patterns
3
+ * Can be reused by multiple tools (glob, ripgrep, etc.)
4
+ */
5
+ export declare const COMMON_IGNORE_PATTERNS: {
6
+ dependencies: string[];
7
+ cache: string[];
8
+ editor: string[];
9
+ os: string[];
10
+ };
11
+ /**
12
+ * Get flat array of all common ignore patterns
13
+ */
14
+ export declare const getAllIgnorePatterns: () => string[];
15
+ /**
16
+ * Parse all .gitignore files in the working directory and its subdirectories and convert to glob patterns
17
+ * @param workdir Working directory
18
+ * @returns Array of glob ignore patterns
19
+ */
20
+ export declare const parseGitignoreToGlob: (workdir: string) => string[];
21
+ /**
22
+ * Get ignore patterns for glob search
23
+ * @param workdir Working directory for resolving .gitignore files
24
+ */
25
+ export declare const getGlobIgnorePatterns: (workdir?: string) => string[];
26
+ //# sourceMappingURL=fileFilter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileFilter.d.ts","sourceRoot":"","sources":["../../src/utils/fileFilter.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,sBAAsB;;;;;CAsBlC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,QAAO,MAAM,EAO7C,CAAC;AA4HF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,SAAS,MAAM,KAAG,MAAM,EAgB5D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAU,MAAM,KAAG,MAAM,EAS9D,CAAC"}
@@ -0,0 +1,177 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ /**
4
+ * Common ignore directory and file patterns
5
+ * Can be reused by multiple tools (glob, ripgrep, etc.)
6
+ */
7
+ export const COMMON_IGNORE_PATTERNS = {
8
+ // Dependencies and build directories
9
+ dependencies: [
10
+ "node_modules/**",
11
+ ".git/**",
12
+ "dist/**",
13
+ "build/**",
14
+ ".next/**",
15
+ "coverage/**",
16
+ ".nyc_output/**",
17
+ "tmp/**",
18
+ "temp/**",
19
+ ],
20
+ // Cache and temporary files
21
+ cache: ["*.log", "*.cache", ".DS_Store", "Thumbs.db", "*~", "*.swp", "*.swo"],
22
+ // Editor and IDE files
23
+ editor: [".vscode/**", ".idea/**", "*.sublime-*"],
24
+ // Operating system related
25
+ os: [".DS_Store", "Thumbs.db", "desktop.ini"],
26
+ };
27
+ /**
28
+ * Get flat array of all common ignore patterns
29
+ */
30
+ export const getAllIgnorePatterns = () => {
31
+ return [
32
+ ...COMMON_IGNORE_PATTERNS.dependencies,
33
+ ...COMMON_IGNORE_PATTERNS.cache,
34
+ ...COMMON_IGNORE_PATTERNS.editor,
35
+ ...COMMON_IGNORE_PATTERNS.os,
36
+ ];
37
+ };
38
+ /**
39
+ * Recursively find all .gitignore files in directory
40
+ * @param dir Directory to search
41
+ * @param maxDepth Maximum recursion depth to prevent too deep searches
42
+ * @returns Array of .gitignore file paths
43
+ */
44
+ const findAllGitignoreFiles = (dir, maxDepth = 5) => {
45
+ const gitignoreFiles = [];
46
+ if (maxDepth <= 0)
47
+ return gitignoreFiles;
48
+ try {
49
+ const items = fs.readdirSync(dir, { withFileTypes: true });
50
+ for (const item of items) {
51
+ const fullPath = path.join(dir, item.name);
52
+ if (item.isFile() && item.name === ".gitignore") {
53
+ gitignoreFiles.push(fullPath);
54
+ }
55
+ else if (item.isDirectory() && !shouldSkipDirectory(item.name)) {
56
+ // Recursively search subdirectories, but skip some obviously unnecessary directories
57
+ gitignoreFiles.push(...findAllGitignoreFiles(fullPath, maxDepth - 1));
58
+ }
59
+ }
60
+ }
61
+ catch {
62
+ // Ignore permission errors and other issues
63
+ }
64
+ return gitignoreFiles;
65
+ };
66
+ /**
67
+ * Determine whether to skip searching a directory
68
+ */
69
+ const shouldSkipDirectory = (dirName) => {
70
+ const skipDirs = [
71
+ "node_modules",
72
+ ".git",
73
+ "dist",
74
+ "build",
75
+ ".next",
76
+ "coverage",
77
+ ".nyc_output",
78
+ "tmp",
79
+ "temp",
80
+ ".cache",
81
+ ];
82
+ return skipDirs.includes(dirName);
83
+ };
84
+ /**
85
+ * Parse single .gitignore file content
86
+ * @param gitignorePath .gitignore file path
87
+ * @param basePath Base path for calculating relative paths
88
+ * @returns Array of parsed glob patterns
89
+ */
90
+ const parseGitignoreFile = (gitignorePath, basePath) => {
91
+ const patterns = [];
92
+ try {
93
+ if (fs.existsSync(gitignorePath)) {
94
+ const gitignoreContent = fs.readFileSync(gitignorePath, "utf8");
95
+ const gitignoreDir = path.dirname(gitignorePath);
96
+ // Calculate relative directory relative to base path
97
+ const relativeDirFromBase = path.relative(basePath, gitignoreDir);
98
+ const lines = gitignoreContent
99
+ .split("\n")
100
+ .map((line) => line.trim())
101
+ .filter((line) => line && !line.startsWith("#"));
102
+ for (const line of lines) {
103
+ // Skip negation rules (starting with !)
104
+ if (line.startsWith("!")) {
105
+ continue;
106
+ }
107
+ let pattern = line;
108
+ // Handle patterns starting with / (relative to current .gitignore file directory)
109
+ if (pattern.startsWith("/")) {
110
+ pattern = pattern.slice(1); // Remove leading /
111
+ }
112
+ // If .gitignore is in subdirectory, need to add path prefix
113
+ if (relativeDirFromBase && relativeDirFromBase !== ".") {
114
+ pattern = path.posix.join(relativeDirFromBase, pattern);
115
+ }
116
+ // If directory pattern (ending with /)
117
+ if (pattern.endsWith("/")) {
118
+ const dirName = pattern.slice(0, -1);
119
+ // For directory patterns, add both exact match and wildcard match
120
+ patterns.push(`${dirName}/**`); // Directory and all its sub-content
121
+ // If no path separators, it's a simple directory name, add global match
122
+ if (!dirName.includes("/") && !dirName.includes("*")) {
123
+ patterns.push(`**/${dirName}/**`); // Match directories of same name at any level
124
+ }
125
+ }
126
+ else {
127
+ // File pattern
128
+ patterns.push(pattern);
129
+ // If no wildcards and no extension, also treat as directory
130
+ if (!pattern.includes("*") && !pattern.includes(".")) {
131
+ patterns.push(`${pattern}/**`);
132
+ // Also add global match for simple directory names
133
+ if (!pattern.includes("/")) {
134
+ patterns.push(`**/${pattern}/**`);
135
+ }
136
+ }
137
+ }
138
+ }
139
+ }
140
+ }
141
+ catch {
142
+ // Ignore errors when reading .gitignore files
143
+ }
144
+ return patterns;
145
+ };
146
+ /**
147
+ * Parse all .gitignore files in the working directory and its subdirectories and convert to glob patterns
148
+ * @param workdir Working directory
149
+ * @returns Array of glob ignore patterns
150
+ */
151
+ export const parseGitignoreToGlob = (workdir) => {
152
+ const patterns = [];
153
+ try {
154
+ // Find all .gitignore files
155
+ const gitignoreFiles = findAllGitignoreFiles(workdir);
156
+ // Parse each .gitignore file
157
+ for (const gitignoreFile of gitignoreFiles) {
158
+ patterns.push(...parseGitignoreFile(gitignoreFile, workdir));
159
+ }
160
+ }
161
+ catch {
162
+ // Ignore errors during search process
163
+ }
164
+ return patterns;
165
+ };
166
+ /**
167
+ * Get ignore patterns for glob search
168
+ * @param workdir Working directory for resolving .gitignore files
169
+ */
170
+ export const getGlobIgnorePatterns = (workdir) => {
171
+ const patterns = getAllIgnorePatterns();
172
+ // If working directory is provided, parse .gitignore files
173
+ if (workdir) {
174
+ patterns.push(...parseGitignoreToGlob(workdir));
175
+ }
176
+ return patterns;
177
+ };
@@ -0,0 +1,27 @@
1
+ import type { CustomSlashCommandConfig } from "../types.js";
2
+ interface ParsedMarkdownFile {
3
+ content: string;
4
+ config?: CustomSlashCommandConfig;
5
+ }
6
+ /**
7
+ * Parse markdown file and extract config and content
8
+ */
9
+ export declare function parseMarkdownFile(filePath: string): ParsedMarkdownFile;
10
+ /**
11
+ * Parse and execute bash commands in markdown content
12
+ */
13
+ export interface BashCommandResult {
14
+ command: string;
15
+ output: string;
16
+ exitCode: number;
17
+ }
18
+ export declare function parseBashCommands(content: string): {
19
+ commands: string[];
20
+ processedContent: string;
21
+ };
22
+ /**
23
+ * Replace bash command placeholders with their outputs
24
+ */
25
+ export declare function replaceBashCommandsWithOutput(content: string, results: BashCommandResult[]): string;
26
+ export {};
27
+ //# sourceMappingURL=markdownParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdownParser.d.ts","sourceRoot":"","sources":["../../src/utils/markdownParser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAE5D,UAAU,kBAAkB;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,wBAAwB,CAAC;CACnC;AAwDD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,kBAAkB,CAsCtE;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG;IAClD,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAgBA;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,iBAAiB,EAAE,GAC3B,MAAM,CAcR"}