wave-agent-sdk 0.11.0 → 0.11.2
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/builtin/skills/init/SKILL.md +26 -0
- package/builtin/skills/settings/ENV.md +64 -0
- package/{src/builtin-skills → builtin/skills}/settings/HOOKS.md +12 -0
- package/builtin/skills/settings/MCP.md +55 -0
- package/builtin/skills/settings/MEMORY_RULES.md +60 -0
- package/{src/builtin-skills → builtin/skills}/settings/SKILL.md +22 -15
- package/builtin/skills/settings/SKILLS.md +63 -0
- package/builtin/skills/settings/SUBAGENTS.md +60 -0
- package/builtin/subagents/bash.md +18 -0
- package/builtin/subagents/explore.md +42 -0
- package/builtin/subagents/general-purpose.md +20 -0
- package/builtin/subagents/plan.md +55 -0
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +7 -0
- package/dist/managers/slashCommandManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.js +0 -16
- package/dist/prompts/index.d.ts +2 -6
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +3 -136
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +41 -2
- package/dist/tools/types.d.ts +2 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/configPaths.d.ts +4 -0
- package/dist/utils/configPaths.d.ts.map +1 -1
- package/dist/utils/configPaths.js +11 -9
- package/dist/utils/fileSearch.d.ts.map +1 -1
- package/dist/utils/fileSearch.js +7 -1
- package/dist/utils/subagentParser.d.ts.map +1 -1
- package/dist/utils/subagentParser.js +14 -4
- package/package.json +3 -2
- package/src/managers/aiManager.ts +7 -0
- package/src/managers/slashCommandManager.ts +0 -19
- package/src/prompts/index.ts +3 -144
- package/src/tools/bashTool.ts +48 -2
- package/src/tools/types.ts +2 -0
- package/src/utils/configPaths.ts +12 -10
- package/src/utils/fileSearch.ts +7 -1
- package/src/utils/subagentParser.ts +16 -6
- package/dist/builtin-skills/builtin-skills/loop/parsing.ts +0 -159
- package/dist/builtin-skills/builtin-skills/settings/HOOKS.md +0 -82
- package/dist/builtin-skills/builtin-skills/settings/SKILL.md +0 -86
- package/dist/builtin-skills/loop/parsing.d.ts +0 -13
- package/dist/builtin-skills/loop/parsing.d.ts.map +0 -1
- package/dist/builtin-skills/loop/parsing.js +0 -125
- package/dist/utils/builtinSubagents.d.ts +0 -7
- package/dist/utils/builtinSubagents.d.ts.map +0 -1
- package/dist/utils/builtinSubagents.js +0 -94
- package/src/builtin-skills/loop/SKILL.md +0 -53
- package/src/builtin-skills/loop/parsing.ts +0 -159
- package/src/utils/builtinSubagents.ts +0 -122
- /package/{dist/builtin-skills/builtin-skills → builtin/skills}/loop/SKILL.md +0 -0
package/src/prompts/index.ts
CHANGED
|
@@ -9,16 +9,14 @@ import {
|
|
|
9
9
|
} from "../constants/subagents.js";
|
|
10
10
|
import {
|
|
11
11
|
ASK_USER_QUESTION_TOOL_NAME,
|
|
12
|
-
BASH_TOOL_NAME,
|
|
13
12
|
EDIT_TOOL_NAME,
|
|
14
|
-
GLOB_TOOL_NAME,
|
|
15
|
-
GREP_TOOL_NAME,
|
|
16
|
-
READ_TOOL_NAME,
|
|
17
13
|
WRITE_TOOL_NAME,
|
|
18
14
|
EXIT_PLAN_MODE_TOOL_NAME,
|
|
19
15
|
AGENT_TOOL_NAME,
|
|
20
16
|
} from "../constants/tools.js";
|
|
21
17
|
|
|
18
|
+
export const MAX_PARALLEL_TOOL_CALLS = 3;
|
|
19
|
+
|
|
22
20
|
export const BASE_SYSTEM_PROMPT = `You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
|
|
23
21
|
|
|
24
22
|
# Doing tasks
|
|
@@ -34,6 +32,7 @@ The user will primarily request you perform software engineering tasks. This inc
|
|
|
34
32
|
export const TOOL_POLICY = `
|
|
35
33
|
# Tool usage policy
|
|
36
34
|
- You can call multiple tools in a single response. If you intend to call multiple tools and there are no dependencies between them, make all independent tool calls in parallel. Maximize use of parallel tool calls where possible to increase efficiency.
|
|
35
|
+
- **Limit**: You MUST NOT call more than ${MAX_PARALLEL_TOOL_CALLS} tools in parallel in a single response.
|
|
37
36
|
- However, if some tool calls depend on previous calls to inform dependent values, do NOT call these tools in parallel and instead call them sequentially. For instance, if one operation must complete before another starts, run these operations sequentially instead. Never use placeholders or guess missing parameters in tool calls.
|
|
38
37
|
- If the user specifies that they want you to run tools "in parallel", you MUST send a single message with multiple tool use content blocks.`;
|
|
39
38
|
|
|
@@ -128,146 +127,6 @@ NOTE: At any point in time through this workflow you should feel free to ask the
|
|
|
128
127
|
|
|
129
128
|
export const DEFAULT_SYSTEM_PROMPT = BASE_SYSTEM_PROMPT;
|
|
130
129
|
|
|
131
|
-
export const BASH_SUBAGENT_SYSTEM_PROMPT = `You are a command execution specialist. Your role is to execute bash commands efficiently and safely.
|
|
132
|
-
|
|
133
|
-
Guidelines:
|
|
134
|
-
- Execute commands precisely as instructed
|
|
135
|
-
- For git operations, follow git safety protocols
|
|
136
|
-
- Report command output clearly and concisely
|
|
137
|
-
- If a command fails, explain the error and suggest solutions
|
|
138
|
-
- Use command chaining (&&) for dependent operations
|
|
139
|
-
- Quote paths with spaces properly
|
|
140
|
-
- For clear communication, avoid using emojis
|
|
141
|
-
|
|
142
|
-
Complete the requested operations efficiently.`;
|
|
143
|
-
|
|
144
|
-
export const GENERAL_PURPOSE_SYSTEM_PROMPT = `You are an agent. Given the user's message, you should use the tools available to complete the task. Do what has been asked; nothing more, nothing less. When you complete the task simply respond with a detailed writeup.
|
|
145
|
-
|
|
146
|
-
Your strengths:
|
|
147
|
-
- Searching for code, configurations, and patterns across large codebases
|
|
148
|
-
- Analyzing multiple files to understand system architecture
|
|
149
|
-
- Investigating complex questions that require exploring many files
|
|
150
|
-
- Performing multi-step research tasks
|
|
151
|
-
|
|
152
|
-
Guidelines:
|
|
153
|
-
- For file searches: Use ${GREP_TOOL_NAME} or ${GLOB_TOOL_NAME} when you need to search broadly. Use ${READ_TOOL_NAME} when you know the specific file path.
|
|
154
|
-
- For analysis: Start broad and narrow down. Use multiple search strategies if the first doesn't yield results.
|
|
155
|
-
- Be thorough: Check multiple locations, consider different naming conventions, look for related files.
|
|
156
|
-
- NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one.
|
|
157
|
-
- NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested.
|
|
158
|
-
- In your final response always share relevant file names and code snippets. Any file paths you return in your response MUST be absolute. Do NOT use relative paths.
|
|
159
|
-
- For clear communication, avoid using emojis.`;
|
|
160
|
-
|
|
161
|
-
export const EXPLORE_SUBAGENT_SYSTEM_PROMPT = `You are a file search specialist. You excel at thoroughly navigating and exploring codebases.
|
|
162
|
-
|
|
163
|
-
=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===
|
|
164
|
-
This is a READ-ONLY exploration task. You are STRICTLY PROHIBITED from:
|
|
165
|
-
- Creating new files (no Write, touch, or file creation of any kind)
|
|
166
|
-
- Modifying existing files (no Edit operations)
|
|
167
|
-
- Moving or copying files (no mv or cp)
|
|
168
|
-
- Creating temporary files anywhere, including /tmp
|
|
169
|
-
- Using redirect operators (>, >>, |) or heredocs to write to files
|
|
170
|
-
- Running ANY commands that change system state
|
|
171
|
-
|
|
172
|
-
Your role is EXCLUSIVELY to search and analyze existing code. You do NOT have access to file editing tools - attempting to edit files will fail.
|
|
173
|
-
|
|
174
|
-
Your strengths:
|
|
175
|
-
- Rapidly finding files using glob patterns
|
|
176
|
-
- Searching code and text with powerful regex patterns
|
|
177
|
-
- Reading and analyzing file contents
|
|
178
|
-
- Using Language Server Protocol (LSP) for deep code intelligence (definitions, references, etc.)
|
|
179
|
-
|
|
180
|
-
Guidelines:
|
|
181
|
-
- Use ${GLOB_TOOL_NAME} for broad file pattern matching
|
|
182
|
-
- Use ${GREP_TOOL_NAME} for searching file contents with regex
|
|
183
|
-
- Use ${READ_TOOL_NAME} when you know the specific file path you need to read
|
|
184
|
-
- Use LSP for code intelligence features like finding definitions, references, implementations, and symbols. This is especially useful for understanding complex code relationships.
|
|
185
|
-
- Use ${BASH_TOOL_NAME} ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)
|
|
186
|
-
- NEVER use ${BASH_TOOL_NAME} for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification
|
|
187
|
-
- Adapt your search approach based on the thoroughness level specified by the caller
|
|
188
|
-
- Return file paths as absolute paths in your final response
|
|
189
|
-
- For clear communication, avoid using emojis
|
|
190
|
-
- Communicate your final report directly as a regular message - do NOT attempt to create files
|
|
191
|
-
|
|
192
|
-
NOTE: You are meant to be a fast agent that returns output as quickly as possible. In order to achieve this you must:
|
|
193
|
-
- Make efficient use of the tools that you have at your disposal: be smart about how you search for files and implementations
|
|
194
|
-
- Wherever possible you should try to spawn multiple parallel tool calls for grepping and reading files
|
|
195
|
-
|
|
196
|
-
Complete the user's search request efficiently and report your findings clearly.`;
|
|
197
|
-
|
|
198
|
-
export const PLAN_SUBAGENT_SYSTEM_PROMPT = `You are a software architect and planning specialist. Your role is to explore the codebase and design implementation plans.
|
|
199
|
-
|
|
200
|
-
=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===
|
|
201
|
-
This is a READ-ONLY planning task. You are STRICTLY PROHIBITED from:
|
|
202
|
-
- Creating new files (no Write, touch, or file creation of any kind)
|
|
203
|
-
- Modifying existing files (no Edit operations)
|
|
204
|
-
- Moving or copying files (no mv or cp)
|
|
205
|
-
- Creating temporary files anywhere, including /tmp
|
|
206
|
-
- Using redirect operators (>, >>, |) or heredocs to write to files
|
|
207
|
-
- Running ANY commands that change system state
|
|
208
|
-
|
|
209
|
-
Your role is EXCLUSIVELY to explore the codebase and design implementation plans. You do NOT have access to file editing tools - attempting to edit files will fail.
|
|
210
|
-
|
|
211
|
-
You will be provided with a set of requirements and optionally a perspective on how to approach the design process.
|
|
212
|
-
|
|
213
|
-
## Your Process
|
|
214
|
-
|
|
215
|
-
1. **Understand Requirements**: Focus on the requirements provided and apply your assigned perspective throughout the design process.
|
|
216
|
-
|
|
217
|
-
2. **Explore Thoroughly**:
|
|
218
|
-
- Read any files provided to you in the initial prompt
|
|
219
|
-
- Find existing patterns and conventions using ${GLOB_TOOL_NAME}, ${GREP_TOOL_NAME}, and ${READ_TOOL_NAME}
|
|
220
|
-
- Understand the current architecture
|
|
221
|
-
- Identify similar features as reference
|
|
222
|
-
- Trace through relevant code paths
|
|
223
|
-
- Use ${BASH_TOOL_NAME} ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)
|
|
224
|
-
- NEVER use ${BASH_TOOL_NAME} for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification
|
|
225
|
-
|
|
226
|
-
3. **Design Solution**:
|
|
227
|
-
- Create implementation approach based on your assigned perspective
|
|
228
|
-
- Consider trade-offs and architectural decisions
|
|
229
|
-
- Follow existing patterns where appropriate
|
|
230
|
-
|
|
231
|
-
4. **Detail the Plan**:
|
|
232
|
-
- Provide step-by-step implementation strategy
|
|
233
|
-
- Identify dependencies and sequencing
|
|
234
|
-
- Anticipate potential challenges
|
|
235
|
-
|
|
236
|
-
## Required Output
|
|
237
|
-
|
|
238
|
-
End your response with:
|
|
239
|
-
|
|
240
|
-
### Critical Files for Implementation
|
|
241
|
-
List 3-5 files most critical for implementing this plan:
|
|
242
|
-
- path/to/file1.ts - [Brief reason: e.g., "Core logic to modify"]
|
|
243
|
-
- path/to/file2.ts - [Brief reason: e.g., "Interfaces to implement"]
|
|
244
|
-
- path/to/file3.ts - [Brief reason: e.g., "Pattern to follow"]
|
|
245
|
-
|
|
246
|
-
REMEMBER: You can ONLY explore and plan. You CANNOT and MUST NOT write, edit, or modify any files. You do NOT have access to file editing tools.`;
|
|
247
|
-
|
|
248
|
-
export const INIT_PROMPT = `Please analyze this codebase and create a AGENTS.md file, which will be given to future instances of Agent to operate in this repository.
|
|
249
|
-
|
|
250
|
-
What to add:
|
|
251
|
-
1. Commands that will be commonly used, such as how to build, lint, and run tests. Include the necessary commands to develop in this codebase, such as how to run a single test.
|
|
252
|
-
2. High-level code architecture and structure so that future instances can be productive more quickly. Focus on the "big picture" architecture that requires reading multiple files to understand.
|
|
253
|
-
|
|
254
|
-
Usage notes:
|
|
255
|
-
- If there's already a AGENTS.md, suggest improvements to it.
|
|
256
|
-
- When you make the initial AGENTS.md, do not repeat yourself and do not include obvious instructions like "Provide helpful error messages to users", "Write unit tests for all new utilities", "Never include sensitive information (API keys, tokens) in code or commits".
|
|
257
|
-
- Avoid listing every component or file structure that can be easily discovered.
|
|
258
|
-
- Don't include generic development practices.
|
|
259
|
-
- If there are Cursor rules (in .cursor/rules/ or .cursorrules) or Copilot rules (in .github/copilot-instructions.md), make sure to include the important parts.
|
|
260
|
-
- Do NOT include rules from .wave/rules/ as they are automatically loaded by the system.
|
|
261
|
-
- If there is a README.md, make sure to include the important parts.
|
|
262
|
-
- Do not make up information such as "Common Development Tasks", "Tips for Development", "Support and Documentation" unless this is expressly included in other files that you read.
|
|
263
|
-
- Be sure to prefix the file with the following text:
|
|
264
|
-
|
|
265
|
-
\`\`\`
|
|
266
|
-
# AGENTS.md
|
|
267
|
-
|
|
268
|
-
This file provides guidance to Agent when working with code in this repository.
|
|
269
|
-
\`\`\``;
|
|
270
|
-
|
|
271
130
|
export const COMPRESS_MESSAGES_SYSTEM_PROMPT = `You have been working on the task described above but have not yet completed it. Write a continuation summary that will allow you (or another instance of yourself) to resume work efficiently in a future context window where the conversation history will be replaced with this summary. Your summary should be structured, concise, and actionable. Include:
|
|
272
131
|
1. Task Overview
|
|
273
132
|
The user's core request and success criteria
|
package/src/tools/bashTool.ts
CHANGED
|
@@ -45,6 +45,20 @@ function processOutput(output: string): string {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Simple throttle function to limit the frequency of updates.
|
|
50
|
+
*/
|
|
51
|
+
function throttle(func: () => void, limit: number) {
|
|
52
|
+
let inThrottle: boolean;
|
|
53
|
+
return function () {
|
|
54
|
+
if (!inThrottle) {
|
|
55
|
+
func();
|
|
56
|
+
inThrottle = true;
|
|
57
|
+
setTimeout(() => (inThrottle = false), limit);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
48
62
|
/**
|
|
49
63
|
* Bash command execution tool - supports both foreground and background execution
|
|
50
64
|
*/
|
|
@@ -232,6 +246,35 @@ Usage notes:
|
|
|
232
246
|
let errorBuffer = "";
|
|
233
247
|
let isAborted = false;
|
|
234
248
|
let isBackgrounded = false;
|
|
249
|
+
let isFinished = false;
|
|
250
|
+
|
|
251
|
+
const updateRealtimeResults = throttle(() => {
|
|
252
|
+
if (isAborted || isBackgrounded || isFinished) return;
|
|
253
|
+
|
|
254
|
+
const combinedOutput =
|
|
255
|
+
outputBuffer + (errorBuffer ? "\n" + errorBuffer : "");
|
|
256
|
+
|
|
257
|
+
// Update shortResult: last 3 lines
|
|
258
|
+
if (context.onShortResultUpdate) {
|
|
259
|
+
const tail = combinedOutput.slice(-5000);
|
|
260
|
+
const lines = tail.trim().split("\n");
|
|
261
|
+
const shortResult =
|
|
262
|
+
lines.length <= 3
|
|
263
|
+
? lines.join("\n")
|
|
264
|
+
: `... +${lines.length - 3} lines\n` + lines.slice(-3).join("\n");
|
|
265
|
+
context.onShortResultUpdate(shortResult);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Update full result
|
|
269
|
+
if (context.onResultUpdate) {
|
|
270
|
+
const content =
|
|
271
|
+
combinedOutput.length <= MAX_OUTPUT_LENGTH
|
|
272
|
+
? combinedOutput
|
|
273
|
+
: combinedOutput.substring(0, MAX_OUTPUT_LENGTH) +
|
|
274
|
+
"\n\n... (output truncated)";
|
|
275
|
+
context.onResultUpdate(content);
|
|
276
|
+
}
|
|
277
|
+
}, 1000);
|
|
235
278
|
|
|
236
279
|
const foregroundTaskId = `bash_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
237
280
|
|
|
@@ -346,6 +389,7 @@ Usage notes:
|
|
|
346
389
|
if (!isAborted && !isBackgrounded && !runInBackground) {
|
|
347
390
|
const chunk = stripAnsiColors(data.toString());
|
|
348
391
|
outputBuffer += chunk;
|
|
392
|
+
updateRealtimeResults();
|
|
349
393
|
}
|
|
350
394
|
});
|
|
351
395
|
|
|
@@ -353,10 +397,12 @@ Usage notes:
|
|
|
353
397
|
if (!isAborted && !isBackgrounded && !runInBackground) {
|
|
354
398
|
const chunk = stripAnsiColors(data.toString());
|
|
355
399
|
errorBuffer += chunk;
|
|
400
|
+
updateRealtimeResults();
|
|
356
401
|
}
|
|
357
402
|
});
|
|
358
403
|
|
|
359
404
|
child.on("exit", (code) => {
|
|
405
|
+
isFinished = true;
|
|
360
406
|
if (context.foregroundTaskManager) {
|
|
361
407
|
context.foregroundTaskManager.unregisterForegroundTask(
|
|
362
408
|
foregroundTaskId,
|
|
@@ -381,8 +427,7 @@ Usage notes:
|
|
|
381
427
|
const shortResult =
|
|
382
428
|
lines.length <= 3
|
|
383
429
|
? lines.join("\n")
|
|
384
|
-
: lines.slice(
|
|
385
|
-
`\n... +${lines.length - 3} lines`;
|
|
430
|
+
: `... +${lines.length - 3} lines\n` + lines.slice(-3).join("\n");
|
|
386
431
|
|
|
387
432
|
resolve({
|
|
388
433
|
success: exitCode === 0,
|
|
@@ -397,6 +442,7 @@ Usage notes:
|
|
|
397
442
|
});
|
|
398
443
|
|
|
399
444
|
child.on("error", (error) => {
|
|
445
|
+
isFinished = true;
|
|
400
446
|
if (context.foregroundTaskManager) {
|
|
401
447
|
context.foregroundTaskManager.unregisterForegroundTask(
|
|
402
448
|
foregroundTaskId,
|
package/src/tools/types.ts
CHANGED
|
@@ -87,4 +87,6 @@ export interface ToolContext {
|
|
|
87
87
|
toolCallId?: string;
|
|
88
88
|
/** Callback to update the short result of the current tool block */
|
|
89
89
|
onShortResultUpdate?: (shortResult: string) => void;
|
|
90
|
+
/** Callback to update the full result of the current tool block */
|
|
91
|
+
onResultUpdate?: (result: string) => void;
|
|
90
92
|
}
|
package/src/utils/configPaths.ts
CHANGED
|
@@ -22,16 +22,18 @@ const __dirname = dirname(__filename);
|
|
|
22
22
|
* Get the builtin skills directory path
|
|
23
23
|
*/
|
|
24
24
|
export function getBuiltinSkillsDir(): string {
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
// Builtin skills are now in the 'builtin/skills' directory at the root of the package
|
|
26
|
+
// Relative to this file (src/utils/configPaths.ts), it's ../../builtin/skills
|
|
27
|
+
return join(__dirname, "..", "..", "builtin", "skills");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get the builtin subagents directory path
|
|
32
|
+
*/
|
|
33
|
+
export function getBuiltinSubagentsDir(): string {
|
|
34
|
+
// Builtin subagents are now in the 'builtin/subagents' directory at the root of the package
|
|
35
|
+
// Relative to this file (src/utils/configPaths.ts), it's ../../builtin/subagents
|
|
36
|
+
return join(__dirname, "..", "..", "builtin", "subagents");
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
/**
|
package/src/utils/fileSearch.ts
CHANGED
|
@@ -4,6 +4,8 @@ import fuzzysort from "fuzzysort";
|
|
|
4
4
|
import type { FileItem } from "../types/fileSearch.js";
|
|
5
5
|
import { logger } from "./globalLogger.js";
|
|
6
6
|
|
|
7
|
+
const EXCLUDED_FILES = [".git", ".DS_Store"];
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* Execute ripgrep to get all file paths
|
|
9
11
|
*/
|
|
@@ -39,7 +41,11 @@ async function getAllFiles(workingDirectory: string): Promise<string[]> {
|
|
|
39
41
|
const files = stdout
|
|
40
42
|
.trim()
|
|
41
43
|
.split("\n")
|
|
42
|
-
.filter((f) =>
|
|
44
|
+
.filter((f) => {
|
|
45
|
+
if (f.length === 0) return false;
|
|
46
|
+
const parts = f.split(/[/\\]/);
|
|
47
|
+
return !parts.some((part) => EXCLUDED_FILES.includes(part));
|
|
48
|
+
})
|
|
43
49
|
.map((f) => f.replace(/\\/g, "/")); // Normalize to forward slashes
|
|
44
50
|
resolve(files);
|
|
45
51
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync, readdirSync, statSync } from "fs";
|
|
2
|
-
import { join, extname } from "path";
|
|
2
|
+
import { join, extname, basename } from "path";
|
|
3
3
|
import { logger } from "./globalLogger.js";
|
|
4
|
+
import { getBuiltinSubagentsDir } from "./configPaths.js";
|
|
4
5
|
|
|
5
6
|
export interface SubagentConfiguration {
|
|
6
7
|
name: string;
|
|
@@ -122,18 +123,27 @@ function validateConfiguration(
|
|
|
122
123
|
*/
|
|
123
124
|
function parseSubagentFile(
|
|
124
125
|
filePath: string,
|
|
125
|
-
scope: "project" | "user",
|
|
126
|
+
scope: "project" | "user" | "builtin",
|
|
126
127
|
): SubagentConfiguration {
|
|
127
128
|
try {
|
|
128
129
|
const content = readFileSync(filePath, "utf-8");
|
|
129
130
|
const { frontmatter, body } = parseFrontmatter(content);
|
|
130
131
|
|
|
132
|
+
// Use filename as default name if not specified in frontmatter
|
|
133
|
+
if (!frontmatter.name) {
|
|
134
|
+
frontmatter.name = basename(filePath, extname(filePath));
|
|
135
|
+
}
|
|
136
|
+
|
|
131
137
|
validateConfiguration(frontmatter, filePath);
|
|
132
138
|
|
|
133
139
|
if (!body.trim()) {
|
|
134
140
|
throw new Error(`Empty system prompt in ${filePath}`);
|
|
135
141
|
}
|
|
136
142
|
|
|
143
|
+
let priority = 1;
|
|
144
|
+
if (scope === "user") priority = 2;
|
|
145
|
+
if (scope === "builtin") priority = 3;
|
|
146
|
+
|
|
137
147
|
return {
|
|
138
148
|
name: frontmatter.name!,
|
|
139
149
|
description: frontmatter.description!,
|
|
@@ -142,7 +152,7 @@ function parseSubagentFile(
|
|
|
142
152
|
systemPrompt: body,
|
|
143
153
|
filePath,
|
|
144
154
|
scope,
|
|
145
|
-
priority
|
|
155
|
+
priority,
|
|
146
156
|
};
|
|
147
157
|
} catch (error) {
|
|
148
158
|
throw new Error(
|
|
@@ -156,7 +166,7 @@ function parseSubagentFile(
|
|
|
156
166
|
*/
|
|
157
167
|
function scanSubagentDirectory(
|
|
158
168
|
dirPath: string,
|
|
159
|
-
scope: "project" | "user",
|
|
169
|
+
scope: "project" | "user" | "builtin",
|
|
160
170
|
): SubagentConfiguration[] {
|
|
161
171
|
const configurations: SubagentConfiguration[] = [];
|
|
162
172
|
|
|
@@ -194,10 +204,10 @@ export async function loadSubagentConfigurations(
|
|
|
194
204
|
): Promise<SubagentConfiguration[]> {
|
|
195
205
|
const projectDir = join(workdir, ".wave", "agents");
|
|
196
206
|
const userDir = join(process.env.HOME || "~", ".wave", "agents");
|
|
207
|
+
const builtinDir = getBuiltinSubagentsDir();
|
|
197
208
|
|
|
198
209
|
// Load configurations from all sources
|
|
199
|
-
const
|
|
200
|
-
const builtinConfigs = getBuiltinSubagents();
|
|
210
|
+
const builtinConfigs = scanSubagentDirectory(builtinDir, "builtin");
|
|
201
211
|
const projectConfigs = scanSubagentDirectory(projectDir, "project");
|
|
202
212
|
const userConfigs = scanSubagentDirectory(userDir, "user");
|
|
203
213
|
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
export interface ParsedLoop {
|
|
2
|
-
interval: string;
|
|
3
|
-
prompt: string;
|
|
4
|
-
originalInterval?: string;
|
|
5
|
-
roundedTo?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function parseLoopInput(
|
|
9
|
-
input: string,
|
|
10
|
-
defaultInterval: string = "10m",
|
|
11
|
-
): ParsedLoop {
|
|
12
|
-
const trimmedInput = input.trim();
|
|
13
|
-
if (!trimmedInput) {
|
|
14
|
-
return { interval: defaultInterval, prompt: "" };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// 1. Leading token: ^\d+[smhd]$
|
|
18
|
-
const tokens = trimmedInput.split(/\s+/);
|
|
19
|
-
if (tokens[0].match(/^\d+[smhd]$/)) {
|
|
20
|
-
const interval = tokens[0];
|
|
21
|
-
const prompt = tokens.slice(1).join(" ");
|
|
22
|
-
return { interval, prompt };
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// 2. Trailing "every" clause: every <N><unit> or every <N> <unit-word>
|
|
26
|
-
// Units: s, m, h, d, second(s), minute(s), hour(s), day(s)
|
|
27
|
-
const everyRegex =
|
|
28
|
-
/\s+every\s+(\d+)\s*(s|m|h|d|seconds?|minutes?|hours?|days?)$/i;
|
|
29
|
-
const match = trimmedInput.match(everyRegex);
|
|
30
|
-
if (match) {
|
|
31
|
-
const n = match[1];
|
|
32
|
-
const unitWord = match[2].toLowerCase();
|
|
33
|
-
const unit = unitWord[0];
|
|
34
|
-
const interval = `${n}${unit}`;
|
|
35
|
-
const prompt = trimmedInput.substring(0, match.index).trim();
|
|
36
|
-
return { interval, prompt };
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// 3. Default
|
|
40
|
-
return { interval: defaultInterval, prompt: trimmedInput };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const CLEAN_MINUTES = [1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30];
|
|
44
|
-
const CLEAN_HOURS = [1, 2, 3, 4, 6, 8, 12];
|
|
45
|
-
|
|
46
|
-
function getNearestClean(value: number, cleanValues: number[]): number {
|
|
47
|
-
let nearest = cleanValues[0];
|
|
48
|
-
let minDiff = Math.abs(value - nearest);
|
|
49
|
-
for (const clean of cleanValues) {
|
|
50
|
-
const diff = Math.abs(value - clean);
|
|
51
|
-
if (diff < minDiff) {
|
|
52
|
-
minDiff = diff;
|
|
53
|
-
nearest = clean;
|
|
54
|
-
} else if (diff === minDiff) {
|
|
55
|
-
// If equal diff, prefer the larger one? Or smaller?
|
|
56
|
-
// Let's prefer the larger one to be less frequent
|
|
57
|
-
if (clean > nearest) {
|
|
58
|
-
nearest = clean;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return nearest;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function intervalToCron(interval: string): {
|
|
66
|
-
cron: string;
|
|
67
|
-
roundedTo?: string;
|
|
68
|
-
cadence: string;
|
|
69
|
-
} {
|
|
70
|
-
const match = interval.match(/^(\d+)([smhd])$/);
|
|
71
|
-
if (!match) {
|
|
72
|
-
throw new Error(`Invalid interval format: ${interval}`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
let n = parseInt(match[1], 10);
|
|
76
|
-
const unit = match[2];
|
|
77
|
-
let roundedTo: string | undefined;
|
|
78
|
-
|
|
79
|
-
if (unit === "s") {
|
|
80
|
-
const minutes = Math.ceil(n / 60);
|
|
81
|
-
const result = intervalToCron(`${minutes}m`);
|
|
82
|
-
return {
|
|
83
|
-
...result,
|
|
84
|
-
roundedTo:
|
|
85
|
-
result.roundedTo || (minutes * 60 !== n ? `${minutes}m` : undefined),
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (unit === "m") {
|
|
90
|
-
if (n >= 60) {
|
|
91
|
-
const hours = Math.round(n / 60);
|
|
92
|
-
const result = intervalToCron(`${hours}h`);
|
|
93
|
-
return {
|
|
94
|
-
...result,
|
|
95
|
-
roundedTo:
|
|
96
|
-
result.roundedTo || (hours * 60 !== n ? `${hours}h` : undefined),
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!CLEAN_MINUTES.includes(n)) {
|
|
101
|
-
const nearest = getNearestClean(n, CLEAN_MINUTES);
|
|
102
|
-
roundedTo = `${nearest}m`;
|
|
103
|
-
n = nearest;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// For minutes, we use */N. Thundering herd is less of an issue for high frequency,
|
|
107
|
-
// but we could still offset it. However, the spec says "random minute for approximate requests like 'hourly'".
|
|
108
|
-
// So for minutes, we'll stick to */N.
|
|
109
|
-
return {
|
|
110
|
-
cron: `*/${n} * * * *`,
|
|
111
|
-
roundedTo,
|
|
112
|
-
cadence: `every ${n} minute${n > 1 ? "s" : ""}`,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (unit === "h") {
|
|
117
|
-
if (n > 23) {
|
|
118
|
-
const days = Math.round(n / 24);
|
|
119
|
-
const result = intervalToCron(`${days}d`);
|
|
120
|
-
return {
|
|
121
|
-
...result,
|
|
122
|
-
roundedTo:
|
|
123
|
-
result.roundedTo || (days * 24 !== n ? `${days}d` : undefined),
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (!CLEAN_HOURS.includes(n)) {
|
|
128
|
-
const nearest = getNearestClean(n, CLEAN_HOURS);
|
|
129
|
-
roundedTo = `${nearest}h`;
|
|
130
|
-
n = nearest;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Thundering herd prevention: pick a random minute
|
|
134
|
-
const randomMinute = Math.floor(Math.random() * 60);
|
|
135
|
-
return {
|
|
136
|
-
cron: `${randomMinute} */${n} * * *`,
|
|
137
|
-
roundedTo,
|
|
138
|
-
cadence: `every ${n} hour${n > 1 ? "s" : ""}`,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (unit === "d") {
|
|
143
|
-
if (![1, 2, 3, 4, 5, 6, 7, 10, 14, 30].includes(n)) {
|
|
144
|
-
// For days, we don't have a strict "clean" list in spec, but let's use some common ones if needed.
|
|
145
|
-
// Actually, cron supports any */N for days.
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Thundering herd prevention: pick a random minute and hour
|
|
149
|
-
const randomMinute = Math.floor(Math.random() * 60);
|
|
150
|
-
const randomHour = Math.floor(Math.random() * 24);
|
|
151
|
-
return {
|
|
152
|
-
cron: `${randomMinute} ${randomHour} */${n} * *`,
|
|
153
|
-
roundedTo,
|
|
154
|
-
cadence: `every ${n} day${n > 1 ? "s" : ""}`,
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
throw new Error(`Unsupported unit: ${unit}`);
|
|
159
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# Wave Hooks Configuration
|
|
2
|
-
|
|
3
|
-
Hooks allow you to automate tasks when certain events occur in Wave. This document provides detailed guidance on how to configure hooks in `settings.json`.
|
|
4
|
-
|
|
5
|
-
## Hook Events
|
|
6
|
-
|
|
7
|
-
Wave supports the following hook events:
|
|
8
|
-
|
|
9
|
-
- `PreToolUse`: Triggered before a tool is executed.
|
|
10
|
-
- `PostToolUse`: Triggered after a tool has finished executing.
|
|
11
|
-
- `UserPromptSubmit`: Triggered when a user submits a prompt.
|
|
12
|
-
- `PermissionRequest`: Triggered when Wave requests permission to use a tool.
|
|
13
|
-
- `Stop`: Triggered when Wave finishes its response cycle (no more tool calls).
|
|
14
|
-
- `SubagentStop`: Triggered when a subagent finishes its response cycle.
|
|
15
|
-
- `WorktreeCreate`: Triggered when a new worktree is created.
|
|
16
|
-
|
|
17
|
-
## Hook Configuration Structure
|
|
18
|
-
|
|
19
|
-
Hooks are configured in the `hooks` field of `settings.json`. Each event can have multiple hook configurations.
|
|
20
|
-
|
|
21
|
-
```json
|
|
22
|
-
{
|
|
23
|
-
"hooks": {
|
|
24
|
-
"PreToolUse": [
|
|
25
|
-
{
|
|
26
|
-
"matcher": "Write",
|
|
27
|
-
"hooks": [
|
|
28
|
-
{
|
|
29
|
-
"command": "pnpm lint",
|
|
30
|
-
"description": "Run lint before writing files"
|
|
31
|
-
}
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
],
|
|
35
|
-
"PermissionRequest": [
|
|
36
|
-
{
|
|
37
|
-
"matcher": "Bash",
|
|
38
|
-
"hooks": [
|
|
39
|
-
{
|
|
40
|
-
"command": "echo \"Permission requested for Bash tool\" >> hooks.log",
|
|
41
|
-
"description": "Log permission requests for Bash"
|
|
42
|
-
}
|
|
43
|
-
]
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## Hook Configuration Fields
|
|
51
|
-
|
|
52
|
-
- `matcher`: (Optional) A pattern to match against the tool name (e.g., "Write", "Read*", "/^Edit/"). Only applicable for `PreToolUse`, `PostToolUse`, and `PermissionRequest`.
|
|
53
|
-
- `hooks`: An array of hook commands to execute.
|
|
54
|
-
- `command`: The shell command to execute.
|
|
55
|
-
- `description`: A brief description of the hook's purpose.
|
|
56
|
-
- `async`: (Optional) Whether the hook should run in the background without blocking (default: `false`).
|
|
57
|
-
- `timeout`: (Optional) Maximum execution time in seconds (default: `600`).
|
|
58
|
-
|
|
59
|
-
## Hook Input JSON
|
|
60
|
-
|
|
61
|
-
Wave provides detailed context to hook processes via `stdin` as a JSON object. This allows hooks to make informed decisions based on the current state.
|
|
62
|
-
|
|
63
|
-
### Common Fields
|
|
64
|
-
- `session_id`: The current session ID.
|
|
65
|
-
- `transcript_path`: Path to the session transcript file (JSON).
|
|
66
|
-
- `cwd`: The current working directory.
|
|
67
|
-
- `hook_event_name`: The name of the triggering event.
|
|
68
|
-
|
|
69
|
-
### Event-Specific Fields
|
|
70
|
-
- `tool_name`: (PreToolUse, PostToolUse, PermissionRequest) The name of the tool.
|
|
71
|
-
- `tool_input`: (PreToolUse, PostToolUse, PermissionRequest) The input parameters passed to the tool.
|
|
72
|
-
- `tool_response`: (PostToolUse) The result of the tool execution.
|
|
73
|
-
- `user_prompt`: (UserPromptSubmit) The text submitted by the user.
|
|
74
|
-
- `subagent_type`: (If executed by a subagent) The type of the subagent.
|
|
75
|
-
- `name`: (WorktreeCreate) The name of the new worktree.
|
|
76
|
-
|
|
77
|
-
## Best Practices
|
|
78
|
-
|
|
79
|
-
- **Keep hooks fast**: Long-running hooks can slow down your workflow unless they are `async`.
|
|
80
|
-
- **Use descriptive names**: Help yourself and others understand what each hook does.
|
|
81
|
-
- **Test your hooks**: Run the commands manually first to ensure they work as expected.
|
|
82
|
-
- **Use local overrides**: For machine-specific hooks, use `.wave/settings.local.json`.
|