wave-agent-sdk 0.14.3 → 0.15.0
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/settings/SKILLS.md +34 -6
- package/dist/agent.d.ts +0 -5
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +0 -15
- package/dist/constants/toolLimits.d.ts +10 -0
- package/dist/constants/toolLimits.d.ts.map +1 -0
- package/dist/constants/toolLimits.js +9 -0
- package/dist/managers/aiManager.d.ts +3 -5
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +107 -104
- package/dist/managers/forkedAgentManager.d.ts +1 -0
- package/dist/managers/forkedAgentManager.d.ts.map +1 -1
- package/dist/managers/forkedAgentManager.js +1 -0
- package/dist/managers/hookManager.d.ts +0 -4
- package/dist/managers/hookManager.d.ts.map +1 -1
- package/dist/managers/hookManager.js +0 -25
- package/dist/managers/permissionManager.d.ts +1 -1
- package/dist/managers/permissionManager.d.ts.map +1 -1
- package/dist/managers/permissionManager.js +5 -5
- package/dist/managers/subagentManager.d.ts +1 -0
- package/dist/managers/subagentManager.d.ts.map +1 -1
- package/dist/managers/subagentManager.js +1 -0
- package/dist/prompts/index.d.ts +0 -1
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +3 -4
- package/dist/services/aiService.d.ts.map +1 -1
- package/dist/services/aiService.js +10 -8
- package/dist/services/autoMemoryService.d.ts.map +1 -1
- package/dist/services/autoMemoryService.js +1 -0
- package/dist/services/hook.d.ts +0 -4
- package/dist/services/hook.d.ts.map +1 -1
- package/dist/services/hook.js +0 -10
- package/dist/services/session.d.ts.map +1 -1
- package/dist/services/session.js +4 -1
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +2 -45
- package/dist/tools/editTool.js +1 -1
- package/dist/tools/types.d.ts +0 -3
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/types/agent.d.ts +0 -1
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/hooks.d.ts +1 -5
- package/dist/types/hooks.d.ts.map +1 -1
- package/dist/types/hooks.js +0 -1
- package/dist/utils/constants.d.ts +2 -2
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +2 -2
- package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
- package/dist/utils/convertMessagesForAPI.js +16 -8
- package/dist/utils/editUtils.d.ts +5 -2
- package/dist/utils/editUtils.d.ts.map +1 -1
- package/dist/utils/editUtils.js +3 -57
- package/dist/utils/markdownParser.d.ts +8 -1
- package/dist/utils/markdownParser.d.ts.map +1 -1
- package/dist/utils/markdownParser.js +64 -11
- package/dist/utils/openaiClient.d.ts.map +1 -1
- package/dist/utils/openaiClient.js +0 -11
- package/dist/utils/stringUtils.d.ts +8 -0
- package/dist/utils/stringUtils.d.ts.map +1 -1
- package/dist/utils/stringUtils.js +45 -0
- package/package.json +1 -1
- package/src/agent.ts +0 -17
- package/src/constants/toolLimits.ts +12 -0
- package/src/managers/aiManager.ts +141 -148
- package/src/managers/forkedAgentManager.ts +3 -0
- package/src/managers/hookManager.ts +0 -32
- package/src/managers/permissionManager.ts +6 -6
- package/src/managers/subagentManager.ts +2 -0
- package/src/prompts/index.ts +3 -5
- package/src/services/aiService.ts +10 -12
- package/src/services/autoMemoryService.ts +1 -0
- package/src/services/hook.ts +0 -15
- package/src/services/session.ts +6 -1
- package/src/tools/bashTool.ts +2 -51
- package/src/tools/editTool.ts +1 -1
- package/src/tools/types.ts +0 -3
- package/src/types/agent.ts +0 -1
- package/src/types/hooks.ts +1 -7
- package/src/utils/constants.ts +2 -2
- package/src/utils/convertMessagesForAPI.ts +15 -8
- package/src/utils/editUtils.ts +3 -73
- package/src/utils/markdownParser.ts +85 -11
- package/src/utils/openaiClient.ts +0 -11
- package/src/utils/stringUtils.ts +43 -0
|
@@ -42,6 +42,9 @@ When this skill is invoked, follow these steps:
|
|
|
42
42
|
- `allowed-tools`: (Optional) List of tools the skill can use.
|
|
43
43
|
- `context: fork`: (Optional) Run the skill in a separate subagent.
|
|
44
44
|
- `agent`: (Optional) Specify the subagent type (default: `general-purpose`).
|
|
45
|
+
- `disable-model-invocation`: (Optional, default: `false`) Set to `true` to hide the skill from the AI's available skills list. The skill can still be invoked by users via slash commands.
|
|
46
|
+
- `user-invocable`: (Optional, default: `true`) Set to `false` to hide the skill from the `/` slash command menu. The AI can still invoke it unless `disable-model-invocation` is also set.
|
|
47
|
+
- `model`: (Optional) Override the AI model used for skill execution (e.g., `"gpt-4o"`, `"o3-mini"`).
|
|
45
48
|
|
|
46
49
|
## Skill Locations
|
|
47
50
|
|
|
@@ -57,21 +60,46 @@ Project skills take precedence over user skills with the same name.
|
|
|
57
60
|
- **AI-Invoked**: The agent automatically discovers and uses skills based on their `description`.
|
|
58
61
|
- **User-Invoked**: Use slash commands in the CLI (e.g., `/my-skill`).
|
|
59
62
|
|
|
60
|
-
##
|
|
63
|
+
## Bash Command Substitution
|
|
61
64
|
|
|
62
|
-
You can embed
|
|
65
|
+
You can embed shell commands in skill content using two syntaxes. Commands are executed and their output is inserted inline when the skill is invoked.
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
### Inline Syntax
|
|
68
|
+
|
|
69
|
+
Use `!`command`` for single-line commands:
|
|
66
70
|
|
|
71
|
+
```markdown
|
|
67
72
|
Current git status: !`git status --short`
|
|
73
|
+
```
|
|
68
74
|
|
|
69
|
-
|
|
75
|
+
### Block Syntax
|
|
76
|
+
|
|
77
|
+
Use ` ```! ` code blocks for multi-line commands:
|
|
78
|
+
|
|
79
|
+
```markdown
|
|
80
|
+
```!
|
|
81
|
+
git log --oneline -10
|
|
82
|
+
```
|
|
70
83
|
```
|
|
71
84
|
|
|
85
|
+
Blocks are processed before inline commands, with results replaced in order of appearance.
|
|
86
|
+
|
|
87
|
+
### Output Limits
|
|
88
|
+
|
|
89
|
+
- Output is capped at **30,000 characters** per command.
|
|
90
|
+
- When truncated, a 2,048-character preview is shown along with a temp file path containing the full output.
|
|
91
|
+
|
|
92
|
+
### Safe Replacement
|
|
93
|
+
|
|
94
|
+
Shell output containing special strings like `$$`, `$&`, `$'` is replaced safely without corruption.
|
|
95
|
+
|
|
96
|
+
### Empty Commands
|
|
97
|
+
|
|
98
|
+
Empty or whitespace-only commands are silently skipped.
|
|
99
|
+
|
|
72
100
|
## Best Practices
|
|
73
101
|
|
|
74
102
|
- **Clear Descriptions**: Write descriptions that help the AI understand exactly when the skill is relevant.
|
|
75
103
|
- **Modular Design**: Keep skills focused on a single task or capability.
|
|
76
104
|
- **Use `${WAVE_SKILL_DIR}`**: Use this placeholder to reference files within the skill directory.
|
|
77
|
-
- **
|
|
105
|
+
- **Bash Commands**: Use `!`command`` for inline output or ` ```! ` blocks for multi-line commands. Keep outputs concise.
|
package/dist/agent.d.ts
CHANGED
|
@@ -66,11 +66,6 @@ export declare class Agent {
|
|
|
66
66
|
get latestTotalTokens(): number;
|
|
67
67
|
/** Get working directory */
|
|
68
68
|
get workingDirectory(): string;
|
|
69
|
-
/**
|
|
70
|
-
* Set the working directory
|
|
71
|
-
* @param newCwd - The new working directory
|
|
72
|
-
*/
|
|
73
|
-
setWorkdir(newCwd: string): void;
|
|
74
69
|
/** Get project memory content */
|
|
75
70
|
get projectMemory(): string;
|
|
76
71
|
/** Get user memory content */
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAYA,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAO9E,OAAO,EACL,YAAY,EACZ,kBAAkB,EAElB,YAAY,EACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,OAAO,EAEP,eAAe,EACf,aAAa,EACb,WAAW,EACX,KAAK,EACL,cAAc,EACd,cAAc,EACf,MAAM,kBAAkB,CAAC;AAe1B,qBAAa,KAAK;IAChB,O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ACI,oBAAoB,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAIxD;;OAEG;IACI,iBAAiB,IAAI,cAAc;IAI1C;;;OAGG;IACI,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IASpD;;;OAGG;IACU,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ1D;;OAEG;IACU,oBAAoB,IAAI,OAAO,CAAC;QAC3C,QAAQ,EAAE,OAAO,EAAE,CAAC;QACpB,UAAU,EAAE,MAAM,EAAE,CAAC;KACtB,CAAC;IAIF;;OAEG;IACI,eAAe,IAAI,MAAM,GAAG,SAAS;IAI5C;;OAEG;IACI,eAAe,IAAI,MAAM,EAAE;IAOlC;;OAEG;IACI,mBAAmB,IAAI,MAAM,EAAE;IAItC;;OAEG;IACU,eAAe,CAC1B,OAAO,EAAE,OAAO,wBAAwB,EAAE,qBAAqB,GAC9D,OAAO,CAAC,OAAO,wBAAwB,EAAE,kBAAkB,CAAC;IAI/D;;;OAGG;IACU,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3D;;;;OAIG;IACI,mBAAmB,CACxB,UAAU,EAAE,MAAM,GACjB,OAAO,+BAA+B,EAAE,gBAAgB,GAAG,IAAI;IAIlE;;OAEG;IACH,IAAW,UAAU,IAAI,MAAM,CAE9B;CACF"}
|
package/dist/agent.js
CHANGED
|
@@ -120,12 +120,6 @@ export class Agent {
|
|
|
120
120
|
this.pendingNotificationPromises.push(pendingPromise);
|
|
121
121
|
}
|
|
122
122
|
};
|
|
123
|
-
// Wire up CWD change callback from AIManager to sync Agent's workdir
|
|
124
|
-
this.aiManager.setOnCwdChange((newCwd) => {
|
|
125
|
-
this.workdir = newCwd;
|
|
126
|
-
this.container.register("Workdir", newCwd);
|
|
127
|
-
this.options.callbacks?.onWorkdirChange?.(newCwd);
|
|
128
|
-
});
|
|
129
123
|
// Wire up message queue to process when agent becomes idle
|
|
130
124
|
this.messageQueue.onMessageEnqueued = () => {
|
|
131
125
|
// If the AI is NOT loading and command is not running, trigger dequeue
|
|
@@ -178,15 +172,6 @@ export class Agent {
|
|
|
178
172
|
get workingDirectory() {
|
|
179
173
|
return this.workdir;
|
|
180
174
|
}
|
|
181
|
-
/**
|
|
182
|
-
* Set the working directory
|
|
183
|
-
* @param newCwd - The new working directory
|
|
184
|
-
*/
|
|
185
|
-
setWorkdir(newCwd) {
|
|
186
|
-
this.workdir = newCwd;
|
|
187
|
-
this.container.register("Workdir", newCwd);
|
|
188
|
-
this.options.callbacks?.onWorkdirChange?.(newCwd);
|
|
189
|
-
}
|
|
190
175
|
/** Get project memory content */
|
|
191
176
|
get projectMemory() {
|
|
192
177
|
return this._projectMemoryContent;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool output size limits matching Claude Code patterns.
|
|
3
|
+
*/
|
|
4
|
+
/** System-wide default max result size in characters. */
|
|
5
|
+
export declare const DEFAULT_MAX_RESULT_SIZE_CHARS = 50000;
|
|
6
|
+
/** Per-command cap for skill bash substitution (inline/block). */
|
|
7
|
+
export declare const SKILL_BASH_MAX_OUTPUT_CHARS = 30000;
|
|
8
|
+
/** Preview size in characters when output is persisted to disk. */
|
|
9
|
+
export declare const PREVIEW_SIZE_BYTES = 2048;
|
|
10
|
+
//# sourceMappingURL=toolLimits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolLimits.d.ts","sourceRoot":"","sources":["../../src/constants/toolLimits.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,yDAAyD;AACzD,eAAO,MAAM,6BAA6B,QAAS,CAAC;AAEpD,kEAAkE;AAClE,eAAO,MAAM,2BAA2B,QAAS,CAAC;AAElD,mEAAmE;AACnE,eAAO,MAAM,kBAAkB,OAAQ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool output size limits matching Claude Code patterns.
|
|
3
|
+
*/
|
|
4
|
+
/** System-wide default max result size in characters. */
|
|
5
|
+
export const DEFAULT_MAX_RESULT_SIZE_CHARS = 50000;
|
|
6
|
+
/** Per-command cap for skill bash substitution (inline/block). */
|
|
7
|
+
export const SKILL_BASH_MAX_OUTPUT_CHARS = 30000;
|
|
8
|
+
/** Preview size in characters when output is persisted to disk. */
|
|
9
|
+
export const PREVIEW_SIZE_BYTES = 2048;
|
|
@@ -3,7 +3,6 @@ import { Container } from "../utils/container.js";
|
|
|
3
3
|
export interface AIManagerCallbacks {
|
|
4
4
|
onCompactionStateChange?: (isCompacting: boolean) => void;
|
|
5
5
|
onUsageAdded?: (usage: Usage) => void;
|
|
6
|
-
onCwdChange?: (newCwd: string) => void;
|
|
7
6
|
}
|
|
8
7
|
export interface AIManagerOptions {
|
|
9
8
|
callbacks?: AIManagerCallbacks;
|
|
@@ -14,6 +13,8 @@ export interface AIManagerOptions {
|
|
|
14
13
|
stream?: boolean;
|
|
15
14
|
/**Optional model override (e.g. for subagents) */
|
|
16
15
|
modelOverride?: string;
|
|
16
|
+
/**Optional max turns limit to prevent runaway recursion (e.g. for auto-memory extraction) */
|
|
17
|
+
maxTurns?: number;
|
|
17
18
|
}
|
|
18
19
|
export declare class AIManager {
|
|
19
20
|
private container;
|
|
@@ -22,13 +23,12 @@ export declare class AIManager {
|
|
|
22
23
|
onLoadingChange?: (loading: boolean) => void;
|
|
23
24
|
private toolAbortController;
|
|
24
25
|
private workdir;
|
|
25
|
-
private originalWorkdir;
|
|
26
26
|
private systemPrompt?;
|
|
27
27
|
private subagentType?;
|
|
28
28
|
private stream;
|
|
29
29
|
private modelOverride?;
|
|
30
|
-
private _onCwdChange?;
|
|
31
30
|
private consecutiveCompactionFailures;
|
|
31
|
+
private readonly maxTurns?;
|
|
32
32
|
constructor(container: Container, options: AIManagerOptions);
|
|
33
33
|
private get toolManager();
|
|
34
34
|
private get messageManager();
|
|
@@ -45,8 +45,6 @@ export declare class AIManager {
|
|
|
45
45
|
getLanguage(): string | undefined;
|
|
46
46
|
getAutoMemoryEnabled(): boolean;
|
|
47
47
|
getWorkdir(): string;
|
|
48
|
-
getOriginalWorkdir(): string;
|
|
49
|
-
setOnCwdChange(callback: (newCwd: string) => void): void;
|
|
50
48
|
private isCompacting;
|
|
51
49
|
private callbacks;
|
|
52
50
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiManager.d.ts","sourceRoot":"","sources":["../../src/managers/aiManager.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,KAAK,EAGN,MAAM,mBAAmB,CAAC;AAY3B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"aiManager.d.ts","sourceRoot":"","sources":["../../src/managers/aiManager.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,KAAK,EAGN,MAAM,mBAAmB,CAAC;AAY3B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAOlD,MAAM,WAAW,kBAAkB;IACjC,uBAAuB,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,KAAK,IAAI,CAAC;IAC1D,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACvC;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kDAAkD;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6FAA6F;IAC7F,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,SAAS;IAelB,OAAO,CAAC,SAAS;IAdZ,SAAS,EAAE,OA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B;IAED,OAAO,KAAK,YAAY,GAEvB;IAEY,aAAa,CACxB,OAAO,GAAE;QACP,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,oEAAoE;QACpE,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,CAAC;KACf,GACL,OAAO,CAAC,IAAI,CAAC;IAspBhB;;;;OAIG;YACW,gBAAgB;IAkF9B;;;OAGG;YACW,sBAAsB;IA+DpC;;OAEG;YACW,uBAAuB;CA0DtC"}
|
|
@@ -5,6 +5,7 @@ import { parseTaskNotificationXml } from "../utils/notificationXml.js";
|
|
|
5
5
|
import { calculateComprehensiveTotalTokens } from "../utils/tokenCalculation.js";
|
|
6
6
|
import * as fs from "node:fs/promises";
|
|
7
7
|
import { buildSystemPrompt } from "../prompts/index.js";
|
|
8
|
+
import { recoverTruncatedJson } from "../utils/stringUtils.js";
|
|
8
9
|
import { logger } from "../utils/globalLogger.js";
|
|
9
10
|
export class AIManager {
|
|
10
11
|
// Service overrides
|
|
@@ -16,13 +17,12 @@ export class AIManager {
|
|
|
16
17
|
this.consecutiveCompactionFailures = 0;
|
|
17
18
|
this.isCompacting = false;
|
|
18
19
|
this.workdir = options.workdir;
|
|
19
|
-
this.originalWorkdir = options.workdir;
|
|
20
20
|
this.systemPrompt = options.systemPrompt;
|
|
21
21
|
this.subagentType = options.subagentType; // Store subagent type
|
|
22
22
|
this.stream = options.stream ?? true; // Default to true if not specified
|
|
23
23
|
this.callbacks = options.callbacks ?? {};
|
|
24
24
|
this.modelOverride = options.modelOverride;
|
|
25
|
-
this.
|
|
25
|
+
this.maxTurns = options.maxTurns;
|
|
26
26
|
}
|
|
27
27
|
get toolManager() {
|
|
28
28
|
return this.container.get("ToolManager");
|
|
@@ -83,12 +83,6 @@ export class AIManager {
|
|
|
83
83
|
getWorkdir() {
|
|
84
84
|
return this.workdir;
|
|
85
85
|
}
|
|
86
|
-
getOriginalWorkdir() {
|
|
87
|
-
return this.originalWorkdir;
|
|
88
|
-
}
|
|
89
|
-
setOnCwdChange(callback) {
|
|
90
|
-
this._onCwdChange = callback;
|
|
91
|
-
}
|
|
92
86
|
/**
|
|
93
87
|
* Get filtered tool configuration based on tools list
|
|
94
88
|
*/
|
|
@@ -141,7 +135,6 @@ export class AIManager {
|
|
|
141
135
|
if (toolPlugin?.formatCompactParams) {
|
|
142
136
|
const context = {
|
|
143
137
|
workdir: this.workdir,
|
|
144
|
-
originalWorkdir: this.originalWorkdir,
|
|
145
138
|
taskManager: this.taskManager,
|
|
146
139
|
};
|
|
147
140
|
return toolPlugin.formatCompactParams(toolArgs, context);
|
|
@@ -454,7 +447,6 @@ export class AIManager {
|
|
|
454
447
|
model: model, // Use passed model
|
|
455
448
|
systemPrompt: buildSystemPrompt(this.systemPrompt, filteredToolPlugins, {
|
|
456
449
|
workdir: this.workdir,
|
|
457
|
-
originalWorkdir: this.originalWorkdir,
|
|
458
450
|
memory: combinedMemory,
|
|
459
451
|
language: this.getLanguage(),
|
|
460
452
|
isSubagent: !!this.subagentType,
|
|
@@ -584,35 +576,45 @@ export class AIManager {
|
|
|
584
576
|
const toolName = functionToolCall.function?.name || "";
|
|
585
577
|
// Safely parse tool parameters, handle tools without parameters
|
|
586
578
|
let toolArgs = {};
|
|
579
|
+
let jsonRecovered = false;
|
|
587
580
|
const argsString = functionToolCall.function?.arguments?.trim();
|
|
588
581
|
if (!argsString || argsString === "") {
|
|
589
582
|
// Tool without parameters, use empty object
|
|
590
583
|
toolArgs = {};
|
|
591
584
|
}
|
|
592
585
|
else {
|
|
586
|
+
let recoveredArgs = argsString;
|
|
593
587
|
try {
|
|
594
588
|
toolArgs = JSON.parse(argsString);
|
|
595
589
|
}
|
|
596
|
-
catch
|
|
597
|
-
//
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
590
|
+
catch {
|
|
591
|
+
// Attempt to recover truncated JSON (e.g., missing closing braces)
|
|
592
|
+
recoveredArgs = recoverTruncatedJson(argsString);
|
|
593
|
+
try {
|
|
594
|
+
toolArgs = JSON.parse(recoveredArgs);
|
|
595
|
+
jsonRecovered = true;
|
|
596
|
+
logger.warn(`Recovered truncated JSON for tool "${toolName}"`);
|
|
597
|
+
}
|
|
598
|
+
catch (parseError) {
|
|
599
|
+
let errorMessage = `Failed to parse tool arguments`;
|
|
600
|
+
if (result.finish_reason === "length") {
|
|
601
|
+
errorMessage +=
|
|
602
|
+
" (output truncated, please reduce your output)";
|
|
603
|
+
}
|
|
604
|
+
logger?.error(errorMessage, parseError);
|
|
605
|
+
this.messageManager.updateToolBlock({
|
|
606
|
+
id: toolId,
|
|
607
|
+
parameters: argsString,
|
|
608
|
+
result: errorMessage,
|
|
609
|
+
success: false,
|
|
610
|
+
error: errorMessage,
|
|
611
|
+
stage: "end",
|
|
612
|
+
name: toolName,
|
|
613
|
+
compactParams: "",
|
|
614
|
+
timestamp: Date.now(),
|
|
615
|
+
});
|
|
616
|
+
return;
|
|
602
617
|
}
|
|
603
|
-
logger?.error(errorMessage, parseError);
|
|
604
|
-
this.messageManager.updateToolBlock({
|
|
605
|
-
id: toolId,
|
|
606
|
-
parameters: argsString,
|
|
607
|
-
result: errorMessage,
|
|
608
|
-
success: false,
|
|
609
|
-
error: errorMessage,
|
|
610
|
-
stage: "end",
|
|
611
|
-
name: toolName,
|
|
612
|
-
compactParams: "",
|
|
613
|
-
timestamp: Date.now(),
|
|
614
|
-
});
|
|
615
|
-
return;
|
|
616
618
|
}
|
|
617
619
|
}
|
|
618
620
|
const compactParams = this.generateCompactParams(toolName, toolArgs);
|
|
@@ -648,7 +650,6 @@ export class AIManager {
|
|
|
648
650
|
abortSignal: toolAbortController.signal,
|
|
649
651
|
backgroundTaskManager: this.backgroundTaskManager,
|
|
650
652
|
workdir: this.workdir,
|
|
651
|
-
originalWorkdir: this.originalWorkdir,
|
|
652
653
|
messageId: this.messageManager.getMessages().slice(-1)[0]?.id,
|
|
653
654
|
sessionId: this.messageManager.getSessionId(),
|
|
654
655
|
toolCallId: toolId,
|
|
@@ -667,26 +668,21 @@ export class AIManager {
|
|
|
667
668
|
stage: "running", // Keep it in running stage while updating result
|
|
668
669
|
});
|
|
669
670
|
},
|
|
670
|
-
onCwdChange: async (newCwd) => {
|
|
671
|
-
const oldCwd = this.workdir;
|
|
672
|
-
this.workdir = newCwd;
|
|
673
|
-
this._onCwdChange?.(newCwd);
|
|
674
|
-
if (this.hookManager) {
|
|
675
|
-
const sessionId = this.messageManager.getSessionId();
|
|
676
|
-
const transcriptPath = this.messageManager.getTranscriptPath();
|
|
677
|
-
const env = Object.fromEntries(Object.entries(process.env).filter((e) => e[1] !== undefined));
|
|
678
|
-
await this.hookManager.executeCwdChangedHooks(oldCwd, newCwd, sessionId, transcriptPath, env);
|
|
679
|
-
}
|
|
680
|
-
},
|
|
681
671
|
};
|
|
682
672
|
// Execute tool
|
|
683
673
|
const toolResult = await this.toolManager.execute(functionToolCall.function?.name || "", toolArgs, context);
|
|
674
|
+
// Build result content, adding truncation warning if JSON was recovered
|
|
675
|
+
let toolResultContent = toolResult.content ||
|
|
676
|
+
(toolResult.error ? `Error: ${toolResult.error}` : "");
|
|
677
|
+
if (jsonRecovered) {
|
|
678
|
+
toolResultContent +=
|
|
679
|
+
"\n\n⚠️ Tool arguments were truncated (likely exceeded max output tokens). Please reduce your output or split into multiple tool calls.";
|
|
680
|
+
}
|
|
684
681
|
// Update message state - tool execution completed
|
|
685
682
|
this.messageManager.updateToolBlock({
|
|
686
683
|
id: toolId,
|
|
687
684
|
parameters: argsString,
|
|
688
|
-
result:
|
|
689
|
-
(toolResult.error ? `Error: ${toolResult.error}` : ""),
|
|
685
|
+
result: toolResultContent,
|
|
690
686
|
success: toolResult.success,
|
|
691
687
|
error: toolResult.error,
|
|
692
688
|
stage: "end",
|
|
@@ -727,75 +723,82 @@ export class AIManager {
|
|
|
727
723
|
this.messageManager.finalizeStreamingBlocks();
|
|
728
724
|
// Check if there are tool operations or response was truncated, if so automatically initiate next AI service call
|
|
729
725
|
if (toolCalls.length > 0 || result.finish_reason === "length") {
|
|
730
|
-
//
|
|
731
|
-
if (this.
|
|
732
|
-
|
|
733
|
-
if (snapshots.length > 0) {
|
|
734
|
-
this.messageManager.addFileHistoryBlock(snapshots);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
// Check interruption status
|
|
738
|
-
const isCurrentlyAborted = abortController.signal.aborted || toolAbortController.signal.aborted;
|
|
739
|
-
// Check if all tools were manually backgrounded
|
|
740
|
-
const lastMessage = this.messageManager.getMessages()[this.messageManager.getMessages().length - 1];
|
|
741
|
-
const toolBlocks = lastMessage?.blocks.filter((block) => block.type === "tool") || [];
|
|
742
|
-
const hasBackgrounded = toolBlocks.length > 0 &&
|
|
743
|
-
toolBlocks.some((block) => block.isManuallyBackgrounded);
|
|
744
|
-
if (hasBackgrounded) {
|
|
745
|
-
logger?.info("Some tools were manually backgrounded, stopping recursion.");
|
|
726
|
+
// Check maxTurns limit before recursing
|
|
727
|
+
if (this.maxTurns && recursionDepth + 1 >= this.maxTurns) {
|
|
728
|
+
logger?.debug(`Max turns (${this.maxTurns}) reached, stopping recursion.`);
|
|
746
729
|
}
|
|
747
|
-
else
|
|
748
|
-
//
|
|
749
|
-
if (
|
|
750
|
-
this.
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
}
|
|
730
|
+
else {
|
|
731
|
+
// Record committed snapshots to message history
|
|
732
|
+
if (this.reversionManager) {
|
|
733
|
+
const snapshots = this.reversionManager.getAndClearCommittedSnapshots();
|
|
734
|
+
if (snapshots.length > 0) {
|
|
735
|
+
this.messageManager.addFileHistoryBlock(snapshots);
|
|
736
|
+
}
|
|
754
737
|
}
|
|
755
|
-
//
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
738
|
+
// Check interruption status
|
|
739
|
+
const isCurrentlyAborted = abortController.signal.aborted ||
|
|
740
|
+
toolAbortController.signal.aborted;
|
|
741
|
+
// Check if all tools were manually backgrounded
|
|
742
|
+
const lastMessage = this.messageManager.getMessages()[this.messageManager.getMessages().length - 1];
|
|
743
|
+
const toolBlocks = lastMessage?.blocks.filter((block) => block.type === "tool") || [];
|
|
744
|
+
const hasBackgrounded = toolBlocks.length > 0 &&
|
|
745
|
+
toolBlocks.some((block) => block.isManuallyBackgrounded);
|
|
746
|
+
if (hasBackgrounded) {
|
|
747
|
+
logger?.info("Some tools were manually backgrounded, stopping recursion.");
|
|
748
|
+
}
|
|
749
|
+
else if (!isCurrentlyAborted) {
|
|
750
|
+
// If response was truncated, add a hidden continuation message
|
|
751
|
+
if (result.finish_reason === "length") {
|
|
752
|
+
this.messageManager.addUserMessage({
|
|
753
|
+
content: "Output token limit hit. Resume directly — no apology, no recap of what you were doing. Pick up mid-thought if that is where the cut happened. Break remaining work into smaller pieces.",
|
|
754
|
+
isMeta: true,
|
|
755
|
+
});
|
|
768
756
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
757
|
+
// Duplicate Tool Call Detection
|
|
758
|
+
if (toolCalls.length > 0) {
|
|
759
|
+
const messages = this.messageManager.getMessages();
|
|
760
|
+
// Find the most recent assistant message BEFORE the current one that has tool blocks
|
|
761
|
+
// The current assistant message is messages[messages.length - 1]
|
|
762
|
+
let previousAssistantWithTools;
|
|
763
|
+
for (let i = messages.length - 2; i >= 0; i--) {
|
|
764
|
+
const msg = messages[i];
|
|
765
|
+
if (msg.role === "assistant" &&
|
|
766
|
+
msg.blocks.some((b) => b.type === "tool")) {
|
|
767
|
+
previousAssistantWithTools = msg;
|
|
768
|
+
break;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
if (previousAssistantWithTools) {
|
|
772
|
+
const previousToolBlocks = previousAssistantWithTools.blocks.filter((b) => b.type === "tool");
|
|
773
|
+
for (const currentToolCall of toolCalls) {
|
|
774
|
+
const currentName = currentToolCall.function?.name;
|
|
775
|
+
const currentArgs = currentToolCall.function?.arguments;
|
|
776
|
+
const isDuplicate = previousToolBlocks.some((prevBlock) => prevBlock.name === currentName &&
|
|
777
|
+
prevBlock.parameters === currentArgs);
|
|
778
|
+
if (isDuplicate && currentName) {
|
|
779
|
+
const toolId = currentToolCall.id;
|
|
780
|
+
const lastMessage = messages[messages.length - 1];
|
|
781
|
+
const toolBlock = lastMessage.blocks.find((b) => b.type === "tool" && b.id === toolId);
|
|
782
|
+
if (toolBlock) {
|
|
783
|
+
const warning = `\n\nNote: You just called this tool with the same arguments in the previous turn. Please ensure you are not in a loop and consider if you need to change your approach.`;
|
|
784
|
+
this.messageManager.updateToolBlock({
|
|
785
|
+
id: toolId,
|
|
786
|
+
result: (toolBlock.result || "") + warning,
|
|
787
|
+
stage: "end",
|
|
788
|
+
});
|
|
789
|
+
}
|
|
787
790
|
}
|
|
788
791
|
}
|
|
789
792
|
}
|
|
790
793
|
}
|
|
794
|
+
// Recursively call AI service, increment recursion depth, and pass same configuration
|
|
795
|
+
await this.sendAIMessage({
|
|
796
|
+
recursionDepth: recursionDepth + 1,
|
|
797
|
+
model,
|
|
798
|
+
allowedRules,
|
|
799
|
+
maxTokens,
|
|
800
|
+
});
|
|
791
801
|
}
|
|
792
|
-
// Recursively call AI service, increment recursion depth, and pass same configuration
|
|
793
|
-
await this.sendAIMessage({
|
|
794
|
-
recursionDepth: recursionDepth + 1,
|
|
795
|
-
model,
|
|
796
|
-
allowedRules,
|
|
797
|
-
maxTokens,
|
|
798
|
-
});
|
|
799
802
|
}
|
|
800
803
|
}
|
|
801
804
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forkedAgentManager.d.ts","sourceRoot":"","sources":["../../src/managers/forkedAgentManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAEzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE9D,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC;IAC3B,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;CAC5C;AAED,MAAM,WAAW,2BAA2B;IAC1C,yBAAyB,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,IAAI,CAAC;CACnE;AAED,qBAAa,kBAAkB;IAK3B,OAAO,CAAC,SAAS;IAJnB,OAAO,CAAC,WAAW,CAAuC;IAC1D,OAAO,CAAC,SAAS,CAA8B;gBAGrC,SAAS,EAAE,SAAS,EAC5B,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,2BAA2B,CAAA;KAAO;IAK3D,OAAO,KAAK,eAAe,GAE1B;IAED;;;OAGG;IACG,cAAc,CAClB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,OAAO,EAAE,EACnB,UAAU,EAAE;QACV,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QACxB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,sBAAsB,CAAC,EAAE,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"forkedAgentManager.d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AM,CAAC;YA0BJ,WAAW;IA6EzB;;OAEG;IACH,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAazB;;OAEG;IACH,OAAO,IAAI,IAAI;IASf;;OAEG;IACH,cAAc,IAAI,gBAAgB,EAAE;IAIpC,OAAO,CAAC,YAAY;CAKrB"}
|
|
@@ -48,6 +48,7 @@ export class ForkedAgentManager {
|
|
|
48
48
|
allowedTools: parameters.allowedTools,
|
|
49
49
|
model: parameters.model,
|
|
50
50
|
permissionModeOverride: parameters.permissionModeOverride,
|
|
51
|
+
maxTurns: parameters.maxTurns,
|
|
51
52
|
}, false);
|
|
52
53
|
// Pre-load the message manager with conversation history
|
|
53
54
|
instance.messageManager.setMessages(messages);
|
|
@@ -98,10 +98,6 @@ export declare class HookManager {
|
|
|
98
98
|
totalCommands: number;
|
|
99
99
|
eventBreakdown: Record<HookEvent, number>;
|
|
100
100
|
};
|
|
101
|
-
/**
|
|
102
|
-
* Execute CwdChanged hooks.
|
|
103
|
-
*/
|
|
104
|
-
executeCwdChangedHooks(oldCwd: string, newCwd: string, sessionId: string, transcriptPath: string, env: Record<string, string>): Promise<HookExecutionResult[]>;
|
|
105
101
|
/**
|
|
106
102
|
* Register hooks provided by a plugin
|
|
107
103
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hookManager.d.ts","sourceRoot":"","sources":["../../src/managers/hookManager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,KAAK,SAAS,EAEd,KAAK,oBAAoB,EACzB,KAAK,4BAA4B,EACjC,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EAItB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,iBAAiB,EACjB,wBAAwB,EACzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,q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C5B,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,EACxC,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,EACtB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC;QACT,OAAO,EAAE,mBAAmB,EAAE,CAAC;QAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC7B,CAAC;IA8CF;;;;OAIG;IACG,sBAAsB,CAC1B,MAAM,EAAE,gBAAgB,EACxB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,mBAAmB,EAAE,CAAC;CAuBlC"}
|
|
@@ -472,7 +472,6 @@ export class HookManager {
|
|
|
472
472
|
event === "Stop" ||
|
|
473
473
|
event === "SubagentStop" ||
|
|
474
474
|
event === "WorktreeCreate" ||
|
|
475
|
-
event === "CwdChanged" ||
|
|
476
475
|
event === "SessionStart" ||
|
|
477
476
|
event === "SessionEnd") {
|
|
478
477
|
return true;
|
|
@@ -547,7 +546,6 @@ export class HookManager {
|
|
|
547
546
|
SubagentStop: 0,
|
|
548
547
|
PermissionRequest: 0,
|
|
549
548
|
WorktreeCreate: 0,
|
|
550
|
-
CwdChanged: 0,
|
|
551
549
|
SessionStart: 0,
|
|
552
550
|
SessionEnd: 0,
|
|
553
551
|
},
|
|
@@ -561,7 +559,6 @@ export class HookManager {
|
|
|
561
559
|
SubagentStop: 0,
|
|
562
560
|
PermissionRequest: 0,
|
|
563
561
|
WorktreeCreate: 0,
|
|
564
|
-
CwdChanged: 0,
|
|
565
562
|
SessionStart: 0,
|
|
566
563
|
SessionEnd: 0,
|
|
567
564
|
};
|
|
@@ -581,28 +578,6 @@ export class HookManager {
|
|
|
581
578
|
eventBreakdown,
|
|
582
579
|
};
|
|
583
580
|
}
|
|
584
|
-
/**
|
|
585
|
-
* Execute CwdChanged hooks.
|
|
586
|
-
*/
|
|
587
|
-
async executeCwdChangedHooks(oldCwd, newCwd, sessionId, transcriptPath, env) {
|
|
588
|
-
const context = {
|
|
589
|
-
event: "CwdChanged",
|
|
590
|
-
projectDir: this.workdir,
|
|
591
|
-
timestamp: new Date(),
|
|
592
|
-
sessionId,
|
|
593
|
-
transcriptPath,
|
|
594
|
-
cwd: newCwd,
|
|
595
|
-
oldCwd,
|
|
596
|
-
newCwd,
|
|
597
|
-
env,
|
|
598
|
-
};
|
|
599
|
-
const results = await this.executeHooks("CwdChanged", context);
|
|
600
|
-
if (results.length > 0) {
|
|
601
|
-
// For CwdChanged hooks, we don't block, just log errors
|
|
602
|
-
this.processHookResults("CwdChanged", results);
|
|
603
|
-
}
|
|
604
|
-
return results;
|
|
605
|
-
}
|
|
606
581
|
/**
|
|
607
582
|
* Register hooks provided by a plugin
|
|
608
583
|
*/
|
|
@@ -41,7 +41,7 @@ export declare class PermissionManager {
|
|
|
41
41
|
private planFilePath?;
|
|
42
42
|
private worktreeName?;
|
|
43
43
|
private mainRepoRoot?;
|
|
44
|
-
private
|
|
44
|
+
private workdir?;
|
|
45
45
|
private onConfiguredPermissionModeChange?;
|
|
46
46
|
private _logger?;
|
|
47
47
|
constructor(container: Container, options?: PermissionManagerOptions);
|