wave-agent-sdk 0.12.0 → 0.12.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/README.md +0 -13
- package/builtin/skills/settings/ENV.md +4 -0
- package/builtin/skills/settings/HOOKS.md +4 -0
- package/builtin/skills/settings/MODELS.md +4 -0
- package/builtin/skills/settings/SKILL.md +5 -1
- package/builtin/skills/settings/SKILLS.md +13 -0
- package/dist/agent.d.ts +2 -2
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +3 -2
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +0 -4
- package/dist/managers/backgroundTaskManager.d.ts.map +1 -1
- package/dist/managers/backgroundTaskManager.js +9 -2
- package/dist/managers/cronManager.d.ts.map +1 -1
- package/dist/managers/cronManager.js +1 -0
- package/dist/managers/permissionManager.d.ts.map +1 -1
- package/dist/managers/permissionManager.js +9 -5
- package/dist/managers/slashCommandManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.js +2 -0
- package/dist/prompts/index.d.ts +11 -3
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +97 -11
- package/dist/services/configurationService.d.ts +1 -1
- package/dist/services/configurationService.d.ts.map +1 -1
- package/dist/services/configurationService.js +26 -15
- package/dist/services/fileWatcher.d.ts.map +1 -1
- package/dist/services/fileWatcher.js +12 -2
- package/dist/services/hook.d.ts.map +1 -1
- package/dist/services/hook.js +6 -1
- package/dist/services/session.d.ts.map +1 -1
- package/dist/services/session.js +2 -14
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +30 -19
- package/dist/tools/webFetchTool.d.ts.map +1 -1
- package/dist/tools/webFetchTool.js +1 -1
- package/dist/tools/writeTool.d.ts.map +1 -1
- package/dist/tools/writeTool.js +6 -0
- package/dist/types/core.d.ts +2 -0
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/core.js +2 -0
- package/dist/utils/bashParser.d.ts +4 -0
- package/dist/utils/bashParser.d.ts.map +1 -1
- package/dist/utils/bashParser.js +23 -0
- package/dist/utils/messageOperations.d.ts +10 -0
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +51 -0
- package/dist/utils/stringUtils.d.ts +4 -0
- package/dist/utils/stringUtils.d.ts.map +1 -1
- package/dist/utils/stringUtils.js +21 -0
- package/package.json +1 -1
- package/src/agent.ts +3 -2
- package/src/managers/aiManager.ts +0 -6
- package/src/managers/backgroundTaskManager.ts +9 -2
- package/src/managers/cronManager.ts +1 -0
- package/src/managers/permissionManager.ts +9 -4
- package/src/managers/slashCommandManager.ts +2 -0
- package/src/prompts/index.ts +111 -9
- package/src/services/configurationService.ts +34 -20
- package/src/services/fileWatcher.ts +13 -2
- package/src/services/hook.ts +4 -1
- package/src/services/session.ts +2 -21
- package/src/tools/bashTool.ts +32 -22
- package/src/tools/webFetchTool.ts +3 -2
- package/src/tools/writeTool.ts +10 -0
- package/src/types/core.ts +4 -0
- package/src/utils/bashParser.ts +24 -0
- package/src/utils/messageOperations.ts +57 -0
- package/src/utils/stringUtils.ts +20 -0
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
hasWriteRedirections,
|
|
24
24
|
isBashHeredocWrite,
|
|
25
25
|
getSmartPrefix,
|
|
26
|
+
isDangerousFind,
|
|
26
27
|
DANGEROUS_COMMANDS,
|
|
27
28
|
} from "../utils/bashParser.js";
|
|
28
29
|
import { isPathInside } from "../utils/pathSafety.js";
|
|
@@ -48,6 +49,7 @@ const SAFE_COMMANDS = [
|
|
|
48
49
|
"tail",
|
|
49
50
|
"wc",
|
|
50
51
|
"sleep",
|
|
52
|
+
"find",
|
|
51
53
|
];
|
|
52
54
|
|
|
53
55
|
const DEFAULT_ALLOWED_RULES = [
|
|
@@ -77,6 +79,7 @@ const DEFAULT_ALLOWED_RULES = [
|
|
|
77
79
|
"Bash(git count-objects*)",
|
|
78
80
|
"Bash(echo*)",
|
|
79
81
|
"Bash(ls*)",
|
|
82
|
+
"Bash(find*)",
|
|
80
83
|
"Bash(which*)",
|
|
81
84
|
"Bash(type*)",
|
|
82
85
|
"Bash(hostname*)",
|
|
@@ -851,7 +854,8 @@ export class PermissionManager {
|
|
|
851
854
|
cmd === "head" ||
|
|
852
855
|
cmd === "tail" ||
|
|
853
856
|
cmd === "wc" ||
|
|
854
|
-
cmd === "sleep"
|
|
857
|
+
cmd === "sleep" ||
|
|
858
|
+
(cmd === "find" && !isDangerousFind(part))
|
|
855
859
|
) {
|
|
856
860
|
return true;
|
|
857
861
|
}
|
|
@@ -887,7 +891,7 @@ export class PermissionManager {
|
|
|
887
891
|
}
|
|
888
892
|
|
|
889
893
|
// Check if this specific part is allowed by any rule
|
|
890
|
-
if (
|
|
894
|
+
if (isDefaultRules && (hasWrite || isDangerousFind(part))) {
|
|
891
895
|
return false;
|
|
892
896
|
}
|
|
893
897
|
|
|
@@ -965,7 +969,8 @@ export class PermissionManager {
|
|
|
965
969
|
cmd === "head" ||
|
|
966
970
|
cmd === "tail" ||
|
|
967
971
|
cmd === "wc" ||
|
|
968
|
-
cmd === "sleep"
|
|
972
|
+
cmd === "sleep" ||
|
|
973
|
+
(cmd === "find" && !isDangerousFind(part))
|
|
969
974
|
) {
|
|
970
975
|
isSafe = true;
|
|
971
976
|
} else {
|
|
@@ -998,7 +1003,7 @@ export class PermissionManager {
|
|
|
998
1003
|
const cmd = commandMatch[1];
|
|
999
1004
|
const args = commandMatch[2]?.trim() || "";
|
|
1000
1005
|
|
|
1001
|
-
if (DANGEROUS_COMMANDS.includes(cmd)) {
|
|
1006
|
+
if (DANGEROUS_COMMANDS.includes(cmd) || isDangerousFind(part)) {
|
|
1002
1007
|
continue;
|
|
1003
1008
|
}
|
|
1004
1009
|
|
package/src/prompts/index.ts
CHANGED
|
@@ -13,29 +13,81 @@ import {
|
|
|
13
13
|
WRITE_TOOL_NAME,
|
|
14
14
|
EXIT_PLAN_MODE_TOOL_NAME,
|
|
15
15
|
AGENT_TOOL_NAME,
|
|
16
|
+
BASH_TOOL_NAME,
|
|
17
|
+
READ_TOOL_NAME,
|
|
18
|
+
GLOB_TOOL_NAME,
|
|
19
|
+
GREP_TOOL_NAME,
|
|
16
20
|
} from "../constants/tools.js";
|
|
17
21
|
|
|
18
22
|
export const MAX_PARALLEL_TOOL_CALLS = 3;
|
|
19
23
|
|
|
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
|
|
24
|
+
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.`;
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
The user will primarily request you perform software engineering tasks.
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
+
export const DOING_TASKS_PROMPT = `# Doing tasks
|
|
27
|
+
- The user will primarily request you to perform software engineering tasks. These may include solving bugs, adding new functionality, refactoring code, explaining code, and more. When given an unclear or generic instruction, consider it in the context of these software engineering tasks and the current working directory. For example, if the user asks you to change "methodName" to snake case, do not reply with just "method_name", instead find the method in the code and modify the code.
|
|
28
|
+
- You are highly capable and often allow users to complete ambitious tasks that would otherwise be too complex or take too long. You should defer to user judgement about whether a task is too large to attempt.
|
|
29
|
+
- If you notice the user's request is based on a misconception, or spot a bug adjacent to what they asked about, say so. You're a collaborator, not just an executor—users benefit from your judgment, not just your compliance.
|
|
30
|
+
- In general, do not propose changes to code you haven't read. If a user asks about or wants you to modify a file, read it first. Understand existing code before suggesting modifications.
|
|
31
|
+
- Do not create files unless they're absolutely necessary for achieving your goal. Generally prefer editing an existing file to creating a new one, as this prevents file bloat and builds on existing work more effectively.
|
|
32
|
+
- If an approach fails, diagnose why before switching tactics—read the error, check your assumptions, try a focused fix. Don't retry the identical action blindly, but don't abandon a viable approach after a single failure either. Escalate to the user with ${ASK_USER_QUESTION_TOOL_NAME} only when you're genuinely stuck after investigation, not as a first response to friction.
|
|
33
|
+
- Be careful not to introduce security vulnerabilities such as command injection, XSS, SQL injection, and other OWASP top 10 vulnerabilities. If you notice that you wrote insecure code, immediately fix it. Prioritize writing safe, secure, and correct code.
|
|
26
34
|
- Avoid over-engineering. Only make changes that are directly requested or clearly necessary. Keep solutions simple and focused.
|
|
27
35
|
- Don't add features, refactor code, or make "improvements" beyond what was asked. A bug fix doesn't need surrounding code cleaned up. A simple feature doesn't need extra configurability. Don't add docstrings, comments, or type annotations to code you didn't change. Only add comments where the logic isn't self-evident.
|
|
28
36
|
- Don't add error handling, fallbacks, or validation for scenarios that can't happen. Trust internal code and framework guarantees. Only validate at system boundaries (user input, external APIs). Don't use feature flags or backwards-compatibility shims when you can just change the code.
|
|
29
|
-
- Don't create helpers, utilities, or abstractions for one-time operations. Don't design for hypothetical future requirements. The right amount of complexity is the
|
|
30
|
-
- Avoid backwards-compatibility hacks like renaming unused
|
|
37
|
+
- Don't create helpers, utilities, or abstractions for one-time operations. Don't design for hypothetical future requirements. The right amount of complexity is what the task actually requires—no speculative abstractions, but no half-finished implementations either. Three similar lines of code is better than a premature abstraction.
|
|
38
|
+
- Avoid backwards-compatibility hacks like renaming unused _vars, re-exporting types, adding // removed comments for removed code, etc. If you are certain that something is unused, you can delete it completely.
|
|
39
|
+
- Report outcomes faithfully: if tests fail, say so with the relevant output; if you did not run a verification step, say that rather than implying it succeeded. Never claim "all tests pass" when output shows failures, never suppress or simplify failing checks (tests, lints, type errors) to manufacture a green result, and never characterize incomplete or broken work as done. Equally, when a check did pass or a task is complete, state it plainly — do not hedge confirmed results with unnecessary disclaimers, downgrade finished work to "partial," or re-verify things you already checked. The goal is an accurate report, not a defensive one.
|
|
40
|
+
- Before reporting a task complete, verify it actually works: run the test, execute the script, check the output. Minimum complexity means no gold-plating, not skipping the finish line. If you can't verify (no test exists, can't run the code), say so explicitly rather than claiming success.`;
|
|
31
41
|
|
|
32
|
-
export const
|
|
33
|
-
|
|
42
|
+
export const EXECUTING_ACTIONS_PROMPT = `# Executing actions with care
|
|
43
|
+
|
|
44
|
+
Carefully consider the reversibility and blast radius of actions. Generally you can freely take local, reversible actions like editing files or running tests. But for actions that are hard to reverse, affect shared systems beyond your local environment, or could otherwise be risky or destructive, check with the user before proceeding. The cost of pausing to confirm is low, while the cost of an unwanted action (lost work, unintended messages sent, deleted branches) can be very high. For actions like these, consider the context, the action, and user instructions, and by default transparently communicate the action and ask for confirmation before proceeding.
|
|
45
|
+
|
|
46
|
+
Examples of the kind of risky actions that warrant user confirmation:
|
|
47
|
+
- Destructive operations: deleting files/branches, dropping database tables, killing processes, rm -rf, overwriting uncommitted changes
|
|
48
|
+
- Hard-to-reverse operations: force-pushing (can also overwrite upstream), git reset --hard, amending published commits, removing or downgrading packages/dependencies, modifying CI/CD pipelines
|
|
49
|
+
- Actions visible to others or that affect shared state: pushing code, creating/closing/commenting on PRs or issues, sending messages (Slack, email, GitHub), posting to external services
|
|
50
|
+
|
|
51
|
+
When you encounter an obstacle, do not use destructive actions as a shortcut to simply make it go away. For instance, try to identify root causes and fix underlying issues rather than bypassing safety checks (e.g. --no-verify). If you discover unexpected state like unfamiliar files, branches, or configuration, investigate before deleting or overwriting, as it may represent the user's in-progress work. For example, typically resolve merge conflicts rather than discarding changes. In short: only take risky actions carefully, and when in doubt, ask before acting. Follow both the spirit and letter of these instructions - measure twice, cut once.`;
|
|
52
|
+
|
|
53
|
+
export const TOOL_POLICY = `# Using your tools
|
|
54
|
+
|
|
55
|
+
- Do NOT use the ${BASH_TOOL_NAME} to run commands when a relevant dedicated tool is provided. Using dedicated tools allows the user to better understand and review your work. This is CRITICAL to assisting the user:
|
|
56
|
+
- To read files use ${READ_TOOL_NAME} instead of cat, head, tail, or sed
|
|
57
|
+
- To edit files use ${EDIT_TOOL_NAME} instead of sed or awk
|
|
58
|
+
- To create files use ${WRITE_TOOL_NAME} instead of cat with heredoc or echo redirection
|
|
59
|
+
- To search for files use ${GLOB_TOOL_NAME} instead of find or ls
|
|
60
|
+
- To search the content of files, use ${GREP_TOOL_NAME} instead of grep or rg
|
|
61
|
+
- Reserve using the ${BASH_TOOL_NAME} exclusively for system commands and terminal operations that require shell execution. If you are unsure and there is a relevant dedicated tool, default to using the dedicated tool and only fallback on using the ${BASH_TOOL_NAME} tool for these if it is absolutely necessary.
|
|
34
62
|
- 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
63
|
- **Limit**: You MUST NOT call more than ${MAX_PARALLEL_TOOL_CALLS} tools in parallel in a single response.
|
|
36
64
|
- 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.
|
|
37
65
|
- 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.`;
|
|
38
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Reference: /home/liuyiqi/github/claude-code/src/constants/prompts.ts getOutputEfficiencySection
|
|
69
|
+
*/
|
|
70
|
+
export const OUTPUT_EFFICIENCY_PROMPT = `# Output efficiency
|
|
71
|
+
|
|
72
|
+
IMPORTANT: Go straight to the point. Try the simplest approach first without going in circles. Do not overdo it. Be extra concise.
|
|
73
|
+
|
|
74
|
+
Keep your text output brief and direct. Lead with the answer or action, not the reasoning. Skip filler words, preamble, and unnecessary transitions. Do not restate what the user said — just do it. When explaining, include only what is necessary for the user to understand.
|
|
75
|
+
|
|
76
|
+
Focus text output on:
|
|
77
|
+
- Decisions that need the user's input
|
|
78
|
+
- High-level status updates at natural milestones
|
|
79
|
+
- Errors or blockers that change the plan
|
|
80
|
+
|
|
81
|
+
If you can say it in one sentence, don't use three. Prefer short, direct sentences over long explanations. This does not apply to code or tool calls.`;
|
|
82
|
+
|
|
83
|
+
export const TONE_AND_STYLE_PROMPT = `# Tone and style
|
|
84
|
+
|
|
85
|
+
- Only use emojis if the user explicitly requests it. Avoid using emojis in all communication unless asked.
|
|
86
|
+
- Your responses should be short and concise.
|
|
87
|
+
- When referencing specific functions or pieces of code include the pattern file_path:line_number to allow the user to easily navigate to the source code location.
|
|
88
|
+
- When referencing GitHub issues or pull requests, use the owner/repo#123 format (e.g. anthropics/claude-code#100) so they render as clickable links.
|
|
89
|
+
- Do not use a colon before tool calls. Your tool calls may not be shown directly in the output, so text like "Let me read the file:" followed by a read tool call should just be "Let me read the file." with a period.`;
|
|
90
|
+
|
|
39
91
|
export function buildPlanModePrompt(
|
|
40
92
|
planFilePath: string,
|
|
41
93
|
planExists: boolean,
|
|
@@ -177,10 +229,16 @@ export function buildSystemPrompt(
|
|
|
177
229
|
} = {},
|
|
178
230
|
): string {
|
|
179
231
|
let prompt = basePrompt || DEFAULT_SYSTEM_PROMPT;
|
|
232
|
+
prompt += `\n\n${DOING_TASKS_PROMPT}`;
|
|
233
|
+
prompt += `\n\n${EXECUTING_ACTIONS_PROMPT}`;
|
|
234
|
+
|
|
180
235
|
if (tools.length > 0) {
|
|
181
236
|
prompt += `\n\n${TOOL_POLICY}`;
|
|
182
237
|
}
|
|
183
238
|
|
|
239
|
+
prompt += `\n\n${OUTPUT_EFFICIENCY_PROMPT}`;
|
|
240
|
+
prompt += `\n\n${TONE_AND_STYLE_PROMPT}`;
|
|
241
|
+
|
|
184
242
|
if (options.permissionMode === "dontAsk") {
|
|
185
243
|
prompt += `\n\n# Permission Mode\nThe user has selected the 'dontAsk' permission mode. In this mode, any restricted tool call that does not match a pre-approved rule in 'permissions.allow' or 'temporaryRules' will be automatically denied without prompting the user. You will receive a 'Permission denied' error for such calls. This is intended to prevent interruptions for untrusted tools while allowing pre-approved ones to run seamlessly.`;
|
|
186
244
|
}
|
|
@@ -198,6 +256,12 @@ export function buildSystemPrompt(
|
|
|
198
256
|
const platform = os.platform();
|
|
199
257
|
const osVersion = `${os.type()} ${os.release()}`;
|
|
200
258
|
const today = new Date().toISOString().split("T")[0];
|
|
259
|
+
const shell = process.env.SHELL || "unknown";
|
|
260
|
+
const shellName = shell.includes("zsh")
|
|
261
|
+
? "zsh"
|
|
262
|
+
: shell.includes("bash")
|
|
263
|
+
? "bash"
|
|
264
|
+
: shell;
|
|
201
265
|
|
|
202
266
|
prompt += `
|
|
203
267
|
|
|
@@ -206,6 +270,7 @@ Here is useful information about the environment you are running in:
|
|
|
206
270
|
Working directory: ${options.workdir}
|
|
207
271
|
Is directory a git repo: ${isGitRepo}
|
|
208
272
|
Platform: ${platform}
|
|
273
|
+
Shell: ${shellName}
|
|
209
274
|
OS Version: ${osVersion}
|
|
210
275
|
Today's date: ${today}
|
|
211
276
|
</env>
|
|
@@ -225,3 +290,40 @@ Today's date: ${today}
|
|
|
225
290
|
|
|
226
291
|
return prompt;
|
|
227
292
|
}
|
|
293
|
+
|
|
294
|
+
export function enhanceSystemPromptWithEnvDetails(
|
|
295
|
+
existingSystemPrompt: string,
|
|
296
|
+
workdir: string,
|
|
297
|
+
): string {
|
|
298
|
+
const isGitRepo = isGitRepository(workdir);
|
|
299
|
+
const platform = os.platform();
|
|
300
|
+
const osVersion = `${os.type()} ${os.release()}`;
|
|
301
|
+
const today = new Date().toISOString().split("T")[0];
|
|
302
|
+
const shell = process.env.SHELL || "unknown";
|
|
303
|
+
const shellName = shell.includes("zsh")
|
|
304
|
+
? "zsh"
|
|
305
|
+
: shell.includes("bash")
|
|
306
|
+
? "bash"
|
|
307
|
+
: shell;
|
|
308
|
+
|
|
309
|
+
const notes = `Notes:
|
|
310
|
+
- Agent threads always have their cwd reset between bash calls, as a result please only use absolute file paths.
|
|
311
|
+
- In your final response, share file paths (always absolute, never relative) that are relevant to the task. Include code snippets only when the exact text is load-bearing (e.g., a bug you found, a function signature the caller asked for) — do not recap code you merely read.
|
|
312
|
+
- For clear communication with the user the assistant MUST avoid using emojis.
|
|
313
|
+
- Do not use a colon before tool calls. Text like "Let me read the file:" followed by a read tool call should just be "Let me read the file." with a period.`;
|
|
314
|
+
|
|
315
|
+
return `${existingSystemPrompt}
|
|
316
|
+
|
|
317
|
+
${notes}
|
|
318
|
+
|
|
319
|
+
Here is useful information about the environment you are running in:
|
|
320
|
+
<env>
|
|
321
|
+
Working directory: ${workdir}
|
|
322
|
+
Is directory a git repo: ${isGitRepo}
|
|
323
|
+
Platform: ${platform}
|
|
324
|
+
Shell: ${shellName}
|
|
325
|
+
OS Version: ${osVersion}
|
|
326
|
+
Today's date: ${today}
|
|
327
|
+
</env>
|
|
328
|
+
`;
|
|
329
|
+
}
|
|
@@ -458,22 +458,40 @@ export class ConfigurationService {
|
|
|
458
458
|
maxTokens?: number,
|
|
459
459
|
permissionMode?: PermissionMode,
|
|
460
460
|
): ModelConfig {
|
|
461
|
-
//
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
461
|
+
// Resolve agent model: override > options > env (settings.json) > process.env
|
|
462
|
+
const resolvedAgentModel =
|
|
463
|
+
model ||
|
|
464
|
+
this.options.model ||
|
|
465
|
+
this.env.WAVE_MODEL ||
|
|
466
|
+
process.env.WAVE_MODEL;
|
|
467
|
+
|
|
468
|
+
// Resolve fast model: override > options > env (settings.json) > process.env
|
|
469
|
+
const resolvedFastModel =
|
|
470
|
+
fastModel ||
|
|
471
|
+
this.options.fastModel ||
|
|
472
|
+
this.env.WAVE_FAST_MODEL ||
|
|
473
|
+
process.env.WAVE_FAST_MODEL;
|
|
474
|
+
|
|
475
|
+
// Validate required fields
|
|
476
|
+
if (!resolvedAgentModel) {
|
|
477
|
+
throw new ConfigurationError(CONFIG_ERRORS.MISSING_MODEL, "model", {
|
|
478
|
+
constructor: model,
|
|
479
|
+
environment: process.env.WAVE_MODEL,
|
|
480
|
+
settings: this.env.WAVE_MODEL,
|
|
481
|
+
});
|
|
482
|
+
}
|
|
474
483
|
|
|
475
|
-
resolvedFastModel
|
|
476
|
-
|
|
484
|
+
if (!resolvedFastModel) {
|
|
485
|
+
throw new ConfigurationError(
|
|
486
|
+
CONFIG_ERRORS.MISSING_FAST_MODEL,
|
|
487
|
+
"fastModel",
|
|
488
|
+
{
|
|
489
|
+
constructor: fastModel,
|
|
490
|
+
environment: process.env.WAVE_FAST_MODEL,
|
|
491
|
+
settings: this.env.WAVE_FAST_MODEL,
|
|
492
|
+
},
|
|
493
|
+
);
|
|
494
|
+
}
|
|
477
495
|
|
|
478
496
|
// Resolve max output tokens
|
|
479
497
|
const resolvedMaxTokens = this.resolveMaxOutputTokens(maxTokens);
|
|
@@ -616,15 +634,11 @@ export class ConfigurationService {
|
|
|
616
634
|
}
|
|
617
635
|
|
|
618
636
|
/**
|
|
619
|
-
* Get all configured models from settings.json and
|
|
637
|
+
* Get all configured models from settings.json and environment
|
|
620
638
|
*/
|
|
621
639
|
getConfiguredModels(): string[] {
|
|
622
|
-
const DEFAULT_AGENT_MODEL = "gemini-3-flash";
|
|
623
640
|
const models = new Set<string>();
|
|
624
641
|
|
|
625
|
-
// Add default model
|
|
626
|
-
models.add(DEFAULT_AGENT_MODEL);
|
|
627
|
-
|
|
628
642
|
// Add current model from options or environment
|
|
629
643
|
const currentModel =
|
|
630
644
|
this.options.model || this.env.WAVE_MODEL || process.env.WAVE_MODEL;
|
|
@@ -167,11 +167,14 @@ export class FileWatcherService extends EventEmitter {
|
|
|
167
167
|
*/
|
|
168
168
|
async cleanup(): Promise<void> {
|
|
169
169
|
const paths = Array.from(this.watchers.keys());
|
|
170
|
-
|
|
170
|
+
for (const path of paths) {
|
|
171
|
+
await this.unwatchFile(path);
|
|
172
|
+
}
|
|
171
173
|
|
|
172
174
|
if (this.globalWatcher) {
|
|
173
|
-
|
|
175
|
+
const watcher = this.globalWatcher;
|
|
174
176
|
this.globalWatcher = null;
|
|
177
|
+
await watcher.close();
|
|
175
178
|
}
|
|
176
179
|
}
|
|
177
180
|
|
|
@@ -190,6 +193,14 @@ export class FileWatcherService extends EventEmitter {
|
|
|
190
193
|
interval: entry.config.pollInterval,
|
|
191
194
|
});
|
|
192
195
|
|
|
196
|
+
// Unref the global watcher to allow natural exit if it's the only thing left
|
|
197
|
+
// (chokidar watchers keep the process alive by default)
|
|
198
|
+
// Note: some platforms might need additional handling
|
|
199
|
+
const watcher = this.globalWatcher as unknown as { unref?: () => void };
|
|
200
|
+
if (watcher.unref) {
|
|
201
|
+
watcher.unref();
|
|
202
|
+
}
|
|
203
|
+
|
|
193
204
|
this.setupGlobalWatcherEvents();
|
|
194
205
|
}
|
|
195
206
|
|
package/src/services/hook.ts
CHANGED
|
@@ -158,12 +158,13 @@ export async function executeCommand(
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
// Set up timeout
|
|
161
|
+
let forceKillTimeoutHandle: NodeJS.Timeout | undefined;
|
|
161
162
|
const timeoutHandle = setTimeout(() => {
|
|
162
163
|
timedOut = true;
|
|
163
164
|
childProcess.kill("SIGTERM");
|
|
164
165
|
|
|
165
166
|
// Force kill after additional delay
|
|
166
|
-
setTimeout(() => {
|
|
167
|
+
forceKillTimeoutHandle = setTimeout(() => {
|
|
167
168
|
if (!childProcess.killed) {
|
|
168
169
|
childProcess.kill("SIGKILL");
|
|
169
170
|
}
|
|
@@ -205,6 +206,7 @@ export async function executeCommand(
|
|
|
205
206
|
// Handle process completion
|
|
206
207
|
childProcess.on("close", (code: number | null) => {
|
|
207
208
|
clearTimeout(timeoutHandle);
|
|
209
|
+
if (forceKillTimeoutHandle) clearTimeout(forceKillTimeoutHandle);
|
|
208
210
|
const duration = Date.now() - startTime;
|
|
209
211
|
|
|
210
212
|
resolve({
|
|
@@ -220,6 +222,7 @@ export async function executeCommand(
|
|
|
220
222
|
// Handle process errors
|
|
221
223
|
childProcess.on("error", (error: Error) => {
|
|
222
224
|
clearTimeout(timeoutHandle);
|
|
225
|
+
if (forceKillTimeoutHandle) clearTimeout(forceKillTimeoutHandle);
|
|
223
226
|
const duration = Date.now() - startTime;
|
|
224
227
|
|
|
225
228
|
resolve({
|
package/src/services/session.ts
CHANGED
|
@@ -25,6 +25,7 @@ import { PathEncoder } from "../utils/pathEncoder.js";
|
|
|
25
25
|
import { JsonlHandler } from "../services/jsonlHandler.js";
|
|
26
26
|
import { extractLatestTotalTokens } from "../utils/tokenCalculation.js";
|
|
27
27
|
import { logger } from "../utils/globalLogger.js";
|
|
28
|
+
import { getMessageContent } from "../utils/messageOperations.js";
|
|
28
29
|
|
|
29
30
|
export interface SessionData {
|
|
30
31
|
id: string;
|
|
@@ -842,27 +843,7 @@ export async function getFirstMessageContent(
|
|
|
842
843
|
try {
|
|
843
844
|
const message = JSON.parse(firstLine) as Message;
|
|
844
845
|
|
|
845
|
-
|
|
846
|
-
const textBlock = message.blocks.find((block) => block.type === "text");
|
|
847
|
-
if (textBlock && "content" in textBlock) {
|
|
848
|
-
return textBlock.content;
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
const commandBlock = message.blocks.find(
|
|
852
|
-
(block) => block.type === "bang",
|
|
853
|
-
);
|
|
854
|
-
if (commandBlock && "command" in commandBlock) {
|
|
855
|
-
return commandBlock.command;
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
const compressBlock = message.blocks.find(
|
|
859
|
-
(block) => block.type === "compress",
|
|
860
|
-
);
|
|
861
|
-
if (compressBlock && "content" in compressBlock) {
|
|
862
|
-
return compressBlock.content;
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
return null;
|
|
846
|
+
return getMessageContent(message) || null;
|
|
866
847
|
} catch (error) {
|
|
867
848
|
logger.warn(
|
|
868
849
|
`Failed to parse first message in session ${sessionId}:`,
|
package/src/tools/bashTool.ts
CHANGED
|
@@ -44,20 +44,6 @@ function processOutput(output: string): string {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
/**
|
|
48
|
-
* Simple throttle function to limit the frequency of updates.
|
|
49
|
-
*/
|
|
50
|
-
function throttle(func: () => void, limit: number) {
|
|
51
|
-
let inThrottle: boolean;
|
|
52
|
-
return function () {
|
|
53
|
-
if (!inThrottle) {
|
|
54
|
-
func();
|
|
55
|
-
inThrottle = true;
|
|
56
|
-
setTimeout(() => (inThrottle = false), limit);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
47
|
/**
|
|
62
48
|
* Bash command execution tool - supports both foreground and background execution
|
|
63
49
|
*/
|
|
@@ -122,8 +108,8 @@ Usage notes:
|
|
|
122
108
|
- You can use the \`run_in_background\` parameter to run the command in the background, which allows you to continue working while the command runs. You can monitor the output using the ${READ_TOOL_NAME} tool as it becomes available. You do not need to use '&' at the end of the command when using this parameter.
|
|
123
109
|
- Avoid using ${BASH_TOOL_NAME} with the \`find\`, \`sed\`, \`awk\`, or \`echo\` commands, unless explicitly instructed or when these commands are truly necessary for the task. Instead, always prefer using the dedicated tools for these commands:
|
|
124
110
|
- File search: Use ${GLOB_TOOL_NAME} (NOT find or ls)
|
|
125
|
-
- Content search: Use ${GREP_TOOL_NAME}
|
|
126
|
-
- Read files: Use ${READ_TOOL_NAME}
|
|
111
|
+
- Content search: Use ${GREP_TOOL_NAME} (NOT grep or rg)
|
|
112
|
+
- Read files: Use ${READ_TOOL_NAME} (NOT cat/head/tail)
|
|
127
113
|
- Edit files: Use ${EDIT_TOOL_NAME} (NOT sed/awk)
|
|
128
114
|
- Write files: Use ${WRITE_TOOL_NAME} (NOT echo >/cat <<EOF)
|
|
129
115
|
- Communication: Output text directly (NOT echo/printf)
|
|
@@ -141,7 +127,28 @@ Usage notes:
|
|
|
141
127
|
</bad-example>
|
|
142
128
|
|
|
143
129
|
- Reserve bash tools exclusively for actual system commands and terminal operations that require shell execution. NEVER use bash echo or other command-line tools to communicate thoughts, explanations, or instructions to the user. Output all communication directly in your response text instead.
|
|
144
|
-
- When making multiple bash tool calls, you MUST send a single message with multiple tools calls to run the calls in parallel. For example, if you need to run "git status" and "git diff", send a single message with two tool calls in parallel
|
|
130
|
+
- When making multiple bash tool calls, you MUST send a single message with multiple tools calls to run the calls in parallel. For example, if you need to run "git status" and "git diff", send a single message with two tool calls in parallel.
|
|
131
|
+
|
|
132
|
+
# Git operations
|
|
133
|
+
Git Safety Protocol:
|
|
134
|
+
- NEVER update the git config
|
|
135
|
+
- NEVER run destructive git commands (push --force, reset --hard, checkout ., restore ., clean -f, branch -D) unless the user explicitly requests these actions. Taking unauthorized destructive actions is unhelpful and can result in lost work, so it's best to ONLY run these commands when given direct instructions
|
|
136
|
+
- NEVER skip hooks (--no-verify, --no-gpg-sign, etc) unless the user explicitly requests it
|
|
137
|
+
- NEVER run force push to main/master, warn the user if they request it
|
|
138
|
+
- CRITICAL: Always create NEW commits rather than amending, unless the user explicitly requests a git amend. When a pre-commit hook fails, the commit did NOT happen — so --amend would modify the PREVIOUS commit, which may result in destroying work or losing previous changes. Instead, after hook failure, fix the issue, re-stage, and create a NEW commit
|
|
139
|
+
- When staging files, prefer adding specific files by name rather than using "git add -A" or "git add .", which can accidentally include sensitive files (.env, credentials) or large binaries
|
|
140
|
+
- NEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTANT to only commit when explicitly asked, otherwise the user will feel that you are being too proactive
|
|
141
|
+
- IMPORTANT: Never use git commands with the -i flag (like git rebase -i or git add -i) since they require interactive input which is not supported.
|
|
142
|
+
|
|
143
|
+
Use the gh command via the Bash tool for GitHub-related tasks including working with issues, pull requests, checks, and releases. If given a Github URL use the gh command to get the information needed.
|
|
144
|
+
|
|
145
|
+
# Avoid unnecessary sleep commands
|
|
146
|
+
- Do not sleep between commands that can run immediately — just run them.
|
|
147
|
+
- If your command is long running and you would like to be notified when it finishes — use \`run_in_background\`. No sleep needed.
|
|
148
|
+
- Do not retry failing commands in a sleep loop — diagnose the root cause.
|
|
149
|
+
- If waiting for a background task you started with \`run_in_background\`, you will be notified when it completes — do not poll.
|
|
150
|
+
- If you must poll an external process, use a check command (e.g. \`gh run view\`) rather than sleeping first.
|
|
151
|
+
- If you must sleep, keep the duration short (1-5 seconds) to avoid blocking the user.`,
|
|
145
152
|
execute: async (
|
|
146
153
|
args: Record<string, unknown>,
|
|
147
154
|
context: ToolContext,
|
|
@@ -247,7 +254,7 @@ Usage notes:
|
|
|
247
254
|
let isBackgrounded = false;
|
|
248
255
|
let isFinished = false;
|
|
249
256
|
|
|
250
|
-
const updateRealtimeResults =
|
|
257
|
+
const updateRealtimeResults = () => {
|
|
251
258
|
if (isAborted || isBackgrounded || isFinished) return;
|
|
252
259
|
|
|
253
260
|
const combinedOutput =
|
|
@@ -273,7 +280,7 @@ Usage notes:
|
|
|
273
280
|
"\n\n... (output truncated)";
|
|
274
281
|
context.onResultUpdate(content);
|
|
275
282
|
}
|
|
276
|
-
}
|
|
283
|
+
};
|
|
277
284
|
|
|
278
285
|
const foregroundTaskId = `bash_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
279
286
|
|
|
@@ -362,11 +369,14 @@ Usage notes:
|
|
|
362
369
|
}
|
|
363
370
|
}
|
|
364
371
|
|
|
372
|
+
const processedOutput = processOutput(
|
|
373
|
+
outputBuffer + (errorBuffer ? "\n" + errorBuffer : ""),
|
|
374
|
+
);
|
|
365
375
|
resolve({
|
|
366
376
|
success: false,
|
|
367
|
-
content:
|
|
368
|
-
|
|
369
|
-
|
|
377
|
+
content: processedOutput
|
|
378
|
+
? `${processedOutput}\n\n${reason}`
|
|
379
|
+
: reason,
|
|
370
380
|
error: reason,
|
|
371
381
|
});
|
|
372
382
|
}
|
|
@@ -29,7 +29,7 @@ setInterval(() => {
|
|
|
29
29
|
cache.delete(url);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
}, CACHE_TTL);
|
|
32
|
+
}, CACHE_TTL).unref();
|
|
33
33
|
|
|
34
34
|
export const webFetchTool: ToolPlugin = {
|
|
35
35
|
name: WEB_FETCH_TOOL_NAME,
|
|
@@ -158,7 +158,8 @@ Usage notes:
|
|
|
158
158
|
return {
|
|
159
159
|
success: false,
|
|
160
160
|
content: markdown,
|
|
161
|
-
error:
|
|
161
|
+
error:
|
|
162
|
+
"AI Manager or AI Service not available for processing content",
|
|
162
163
|
};
|
|
163
164
|
}
|
|
164
165
|
|
package/src/tools/writeTool.ts
CHANGED
|
@@ -142,6 +142,16 @@ Usage:
|
|
|
142
142
|
// Record snapshot for reversion
|
|
143
143
|
let snapshotId: string | undefined;
|
|
144
144
|
if (context.reversionManager && context.messageId) {
|
|
145
|
+
// Log memory usage before large operations if in debug mode
|
|
146
|
+
if (process.env.LOG_LEVEL === "DEBUG") {
|
|
147
|
+
const usage = process.memoryUsage();
|
|
148
|
+
logger.debug(
|
|
149
|
+
`[Memory Before Write] RSS: ${Math.round(usage.rss / 1024 / 1024)}MB, ` +
|
|
150
|
+
`Heap: ${Math.round(usage.heapUsed / 1024 / 1024)}/${Math.round(usage.heapTotal / 1024 / 1024)}MB`,
|
|
151
|
+
{ filePath, contentLength: content.length },
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
145
155
|
snapshotId = await context.reversionManager.recordSnapshot(
|
|
146
156
|
context.messageId,
|
|
147
157
|
resolvedPath,
|
package/src/types/core.ts
CHANGED
|
@@ -98,6 +98,10 @@ export class ConfigurationError extends Error {
|
|
|
98
98
|
export const CONFIG_ERRORS = {
|
|
99
99
|
MISSING_BASE_URL:
|
|
100
100
|
"Gateway configuration requires baseURL. Provide via constructor or WAVE_BASE_URL environment variable.",
|
|
101
|
+
MISSING_MODEL:
|
|
102
|
+
"Agent configuration requires model. Provide via constructor or WAVE_MODEL environment variable.",
|
|
103
|
+
MISSING_FAST_MODEL:
|
|
104
|
+
"Agent configuration requires fastModel. Provide via constructor or WAVE_FAST_MODEL environment variable.",
|
|
101
105
|
INVALID_WAVE_MAX_INPUT_TOKENS: "Token limit must be a positive integer.",
|
|
102
106
|
EMPTY_BASE_URL: "Base URL cannot be empty string.",
|
|
103
107
|
} as const;
|
package/src/utils/bashParser.ts
CHANGED
|
@@ -610,6 +610,30 @@ function shouldStopAtArg(arg: string): boolean {
|
|
|
610
610
|
return false;
|
|
611
611
|
}
|
|
612
612
|
|
|
613
|
+
/**
|
|
614
|
+
* Checks if a find command is dangerous (e.g., contains -exec, -delete, etc.).
|
|
615
|
+
*/
|
|
616
|
+
export function isDangerousFind(command: string): boolean {
|
|
617
|
+
const stripped = stripRedirections(stripEnvVars(command));
|
|
618
|
+
const tokens = stripped.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g) || [];
|
|
619
|
+
if (tokens.length === 0 || tokens[0] !== "find") return false;
|
|
620
|
+
|
|
621
|
+
const dangerousFlags = [
|
|
622
|
+
"-exec",
|
|
623
|
+
"-execdir",
|
|
624
|
+
"-ok",
|
|
625
|
+
"-okdir",
|
|
626
|
+
"-delete",
|
|
627
|
+
"-fprint",
|
|
628
|
+
"-fprint0",
|
|
629
|
+
"-fprintf",
|
|
630
|
+
];
|
|
631
|
+
return tokens.some((token) => {
|
|
632
|
+
const unquoted = token.replace(/^(['"])(.*)\1$/, "$2");
|
|
633
|
+
return dangerousFlags.includes(unquoted);
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
|
|
613
637
|
/**
|
|
614
638
|
* Extracts a "smart prefix" from a bash command based on common developer tools.
|
|
615
639
|
* Returns null if the command is blacklisted or cannot be safely prefix-matched.
|