wave-agent-sdk 0.10.4 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builtin/skills/init/SKILL.md +26 -0
- package/builtin/skills/loop/SKILL.md +53 -0
- package/builtin/skills/settings/ENV.md +64 -0
- package/builtin/skills/settings/HOOKS.md +94 -0
- package/builtin/skills/settings/MCP.md +55 -0
- package/builtin/skills/settings/MEMORY_RULES.md +60 -0
- package/{dist/builtin-skills → builtin/skills}/settings/SKILL.md +23 -16
- 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/agent.d.ts +8 -6
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +12 -9
- package/dist/constants/tools.d.ts +3 -0
- package/dist/constants/tools.d.ts.map +1 -1
- package/dist/constants/tools.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/managers/aiManager.d.ts +0 -2
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +53 -14
- package/dist/managers/cronManager.d.ts +19 -0
- package/dist/managers/cronManager.d.ts.map +1 -0
- package/dist/managers/cronManager.js +124 -0
- package/dist/managers/hookManager.d.ts.map +1 -1
- package/dist/managers/hookManager.js +21 -13
- package/dist/managers/liveConfigManager.js +1 -1
- package/dist/managers/mcpManager.d.ts +1 -1
- package/dist/managers/mcpManager.d.ts.map +1 -1
- package/dist/managers/mcpManager.js +10 -2
- package/dist/managers/messageManager.d.ts +0 -1
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/permissionManager.d.ts +27 -7
- package/dist/managers/permissionManager.d.ts.map +1 -1
- package/dist/managers/permissionManager.js +119 -14
- package/dist/managers/slashCommandManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.js +7 -12
- package/dist/managers/subagentManager.d.ts +3 -0
- package/dist/managers/subagentManager.d.ts.map +1 -1
- package/dist/managers/subagentManager.js +10 -17
- package/dist/managers/toolManager.d.ts +1 -1
- package/dist/managers/toolManager.d.ts.map +1 -1
- package/dist/managers/toolManager.js +28 -4
- package/dist/prompts/index.d.ts +0 -5
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +1 -136
- package/dist/services/configurationService.d.ts.map +1 -1
- package/dist/services/configurationService.js +8 -7
- package/dist/services/hook.d.ts.map +1 -1
- package/dist/services/hook.js +3 -10
- package/dist/services/initializationService.js +2 -2
- package/dist/services/jsonlHandler.d.ts.map +1 -1
- package/dist/services/jsonlHandler.js +3 -0
- package/dist/services/reversionService.d.ts +2 -2
- package/dist/services/reversionService.d.ts.map +1 -1
- package/dist/services/reversionService.js +3 -3
- package/dist/services/session.d.ts.map +1 -1
- package/dist/services/session.js +18 -11
- package/dist/tools/agentTool.js +1 -1
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +5 -5
- package/dist/tools/cronCreateTool.d.ts +3 -0
- package/dist/tools/cronCreateTool.d.ts.map +1 -0
- package/dist/tools/cronCreateTool.js +59 -0
- package/dist/tools/cronDeleteTool.d.ts +3 -0
- package/dist/tools/cronDeleteTool.d.ts.map +1 -0
- package/dist/tools/cronDeleteTool.js +38 -0
- package/dist/tools/cronListTool.d.ts +3 -0
- package/dist/tools/cronListTool.d.ts.map +1 -0
- package/dist/tools/cronListTool.js +30 -0
- package/dist/tools/skillTool.d.ts +0 -3
- package/dist/tools/skillTool.d.ts.map +1 -1
- package/dist/tools/skillTool.js +4 -3
- package/dist/tools/taskOutputTool.d.ts.map +1 -1
- package/dist/tools/taskOutputTool.js +15 -8
- package/dist/tools/types.d.ts +2 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/types/agent.d.ts +10 -0
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/configuration.d.ts +1 -1
- package/dist/types/configuration.d.ts.map +1 -1
- package/dist/types/cron.d.ts +10 -0
- package/dist/types/cron.d.ts.map +1 -0
- package/dist/types/cron.js +1 -0
- package/dist/types/hooks.d.ts +1 -5
- package/dist/types/hooks.d.ts.map +1 -1
- package/dist/types/hooks.js +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/messaging.d.ts +1 -1
- package/dist/types/messaging.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/containerSetup.d.ts.map +1 -1
- package/dist/utils/containerSetup.js +40 -13
- package/dist/utils/fileSearch.d.ts.map +1 -1
- package/dist/utils/fileSearch.js +7 -1
- package/dist/utils/mcpUtils.d.ts +2 -2
- package/dist/utils/mcpUtils.d.ts.map +1 -1
- package/dist/utils/mcpUtils.js +1 -5
- package/dist/utils/subagentParser.d.ts.map +1 -1
- package/dist/utils/subagentParser.js +14 -4
- package/package.json +4 -2
- package/src/agent.ts +17 -12
- package/src/constants/tools.ts +3 -0
- package/src/index.ts +1 -0
- package/src/managers/aiManager.ts +72 -24
- package/src/managers/cronManager.ts +167 -0
- package/src/managers/hookManager.ts +27 -13
- package/src/managers/liveConfigManager.ts +2 -2
- package/src/managers/mcpManager.ts +23 -2
- package/src/managers/messageManager.ts +0 -6
- package/src/managers/permissionManager.ts +154 -18
- package/src/managers/slashCommandManager.ts +7 -14
- package/src/managers/subagentManager.ts +15 -19
- package/src/managers/toolManager.ts +37 -4
- package/src/prompts/index.ts +0 -144
- package/src/services/configurationService.ts +8 -7
- package/src/services/hook.ts +5 -11
- package/src/services/initializationService.ts +3 -3
- package/src/services/jsonlHandler.ts +4 -0
- package/src/services/reversionService.ts +9 -4
- package/src/services/session.ts +19 -12
- package/src/tools/agentTool.ts +1 -1
- package/src/tools/bashTool.ts +6 -5
- package/src/tools/cronCreateTool.ts +73 -0
- package/src/tools/cronDeleteTool.ts +47 -0
- package/src/tools/cronListTool.ts +38 -0
- package/src/tools/skillTool.ts +6 -4
- package/src/tools/taskOutputTool.ts +14 -8
- package/src/tools/types.ts +2 -0
- package/src/types/agent.ts +10 -0
- package/src/types/configuration.ts +1 -1
- package/src/types/cron.ts +9 -0
- package/src/types/hooks.ts +5 -9
- package/src/types/index.ts +1 -0
- package/src/types/messaging.ts +1 -1
- package/src/utils/configPaths.ts +12 -10
- package/src/utils/containerSetup.ts +50 -16
- package/src/utils/fileSearch.ts +7 -1
- package/src/utils/mcpUtils.ts +2 -5
- package/src/utils/subagentParser.ts +16 -6
- package/dist/builtin-skills/settings/HOOKS.md +0 -95
- 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/settings/HOOKS.md +0 -95
- package/src/builtin-skills/settings/SKILL.md +0 -86
- package/src/utils/builtinSubagents.ts +0 -122
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Software architect agent for designing implementation plans. Use this when you need to plan the implementation strategy for a task. Returns step-by-step plans, identifies critical files, and considers architectural trade-offs.
|
|
3
|
+
tools: [Glob, Grep, Read, Bash, LSP]
|
|
4
|
+
model: inherit
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
You are a software architect and planning specialist. Your role is to explore the codebase and design implementation plans.
|
|
8
|
+
|
|
9
|
+
=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===
|
|
10
|
+
This is a READ-ONLY planning task. You are STRICTLY PROHIBITED from:
|
|
11
|
+
- Creating new files (no Write, touch, or file creation of any kind)
|
|
12
|
+
- Modifying existing files (no Edit operations)
|
|
13
|
+
- Moving or copying files (no mv or cp)
|
|
14
|
+
- Creating temporary files anywhere, including /tmp
|
|
15
|
+
- Using redirect operators (>, >>, |) or heredocs to write to files
|
|
16
|
+
- Running ANY commands that change system state
|
|
17
|
+
|
|
18
|
+
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.
|
|
19
|
+
|
|
20
|
+
You will be provided with a set of requirements and optionally a perspective on how to approach the design process.
|
|
21
|
+
|
|
22
|
+
## Your Process
|
|
23
|
+
|
|
24
|
+
1. **Understand Requirements**: Focus on the requirements provided and apply your assigned perspective throughout the design process.
|
|
25
|
+
|
|
26
|
+
2. **Explore Thoroughly**:
|
|
27
|
+
- Read any files provided to you in the initial prompt
|
|
28
|
+
- Find existing patterns and conventions using Glob, Grep, and Read
|
|
29
|
+
- Understand the current architecture
|
|
30
|
+
- Identify similar features as reference
|
|
31
|
+
- Trace through relevant code paths
|
|
32
|
+
- Use Bash ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)
|
|
33
|
+
- NEVER use Bash for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification
|
|
34
|
+
|
|
35
|
+
3. **Design Solution**:
|
|
36
|
+
- Create implementation approach based on your assigned perspective
|
|
37
|
+
- Consider trade-offs and architectural decisions
|
|
38
|
+
- Follow existing patterns where appropriate
|
|
39
|
+
|
|
40
|
+
4. **Detail the Plan**:
|
|
41
|
+
- Provide step-by-step implementation strategy
|
|
42
|
+
- Identify dependencies and sequencing
|
|
43
|
+
- Anticipate potential challenges
|
|
44
|
+
|
|
45
|
+
## Required Output
|
|
46
|
+
|
|
47
|
+
End your response with:
|
|
48
|
+
|
|
49
|
+
### Critical Files for Implementation
|
|
50
|
+
List 3-5 files most critical for implementing this plan:
|
|
51
|
+
- path/to/file1.ts - [Brief reason: e.g., "Core logic to modify"]
|
|
52
|
+
- path/to/file2.ts - [Brief reason: e.g., "Interfaces to implement"]
|
|
53
|
+
- path/to/file3.ts - [Brief reason: e.g., "Pattern to follow"]
|
|
54
|
+
|
|
55
|
+
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.
|
package/dist/agent.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare class Agent {
|
|
|
15
15
|
private slashCommandManager;
|
|
16
16
|
private pluginManager;
|
|
17
17
|
private skillManager;
|
|
18
|
+
private cronManager;
|
|
18
19
|
private hookManager;
|
|
19
20
|
private reversionManager;
|
|
20
21
|
private memoryRuleManager;
|
|
@@ -141,7 +142,7 @@ export declare class Agent {
|
|
|
141
142
|
abortAIMessage(): void;
|
|
142
143
|
/** Execute bash command */
|
|
143
144
|
executeBashCommand(command: string): Promise<void>;
|
|
144
|
-
clearMessages(): void
|
|
145
|
+
clearMessages(): Promise<void>;
|
|
145
146
|
/** Unified interrupt method, interrupts both AI messages and command execution */
|
|
146
147
|
abortMessage(): void;
|
|
147
148
|
/** Interrupt bash command execution */
|
|
@@ -162,11 +163,6 @@ export declare class Agent {
|
|
|
162
163
|
backgroundCurrentTask(): Promise<void>;
|
|
163
164
|
/** Destroy managers, clean up resources */
|
|
164
165
|
destroy(): Promise<void>;
|
|
165
|
-
/**
|
|
166
|
-
* Get a subagent instance by its ID
|
|
167
|
-
* @param subagentId - The ID of the subagent instance
|
|
168
|
-
*/
|
|
169
|
-
getSubagentInstance(subagentId: string): import("./managers/subagentManager.js").SubagentInstance | null;
|
|
170
166
|
/**
|
|
171
167
|
* Trigger the rewind UI callback
|
|
172
168
|
*/
|
|
@@ -263,6 +259,12 @@ export declare class Agent {
|
|
|
263
259
|
* @param rule - The rule to add (e.g., "Bash(ls)")
|
|
264
260
|
*/
|
|
265
261
|
addPermissionRule(rule: string): Promise<void>;
|
|
262
|
+
/**
|
|
263
|
+
* Get subagent instance by ID
|
|
264
|
+
* @param subagentId - The ID of the subagent instance
|
|
265
|
+
* @returns The subagent instance or null if not found
|
|
266
|
+
*/
|
|
267
|
+
getSubagentInstance(subagentId: string): import("./managers/subagentManager.js").SubagentInstance | null;
|
|
266
268
|
/**
|
|
267
269
|
* Get the current task list ID
|
|
268
270
|
*/
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAgBA,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;AAY1B,qBAAa,KAAK;IAChB,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,SAAS,CAAY;IAE7B,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,qBAAqB,CAAwB;IACrD,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,UAAU,CAAc;IAChC,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,mBAAmB,CAAsB;IACjD,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,qBAAqB,CAAwB;IACrD,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,oBAAoB,CAAuB;IACnD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAAC,C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,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
|
@@ -87,6 +87,7 @@ export class Agent {
|
|
|
87
87
|
this.slashCommandManager = this.container.get("SlashCommandManager");
|
|
88
88
|
this.pluginManager = this.container.get("PluginManager");
|
|
89
89
|
this.bangManager = this.container.get("BangManager");
|
|
90
|
+
this.cronManager = this.container.get("CronManager");
|
|
90
91
|
// Set initial permission mode if provided
|
|
91
92
|
if (options.permissionMode) {
|
|
92
93
|
this.setPermissionMode(options.permissionMode);
|
|
@@ -272,8 +273,8 @@ export class Agent {
|
|
|
272
273
|
async executeBashCommand(command) {
|
|
273
274
|
await this.bangManager?.executeCommand(command);
|
|
274
275
|
}
|
|
275
|
-
clearMessages() {
|
|
276
|
-
this.
|
|
276
|
+
async clearMessages() {
|
|
277
|
+
await this.slashCommandManager.executeCommand("clear");
|
|
277
278
|
}
|
|
278
279
|
/** Unified interrupt method, interrupts both AI messages and command execution */
|
|
279
280
|
abortMessage() {
|
|
@@ -314,6 +315,7 @@ export class Agent {
|
|
|
314
315
|
this.abortAIMessage(); // This will abort tools including Agent tool (subagents)
|
|
315
316
|
this.abortBashCommand();
|
|
316
317
|
this.abortSlashCommand();
|
|
318
|
+
this.cronManager.stop();
|
|
317
319
|
// Cleanup background task manager
|
|
318
320
|
this.backgroundTaskManager.cleanup();
|
|
319
321
|
// Cleanup MCP connections
|
|
@@ -335,13 +337,6 @@ export class Agent {
|
|
|
335
337
|
}
|
|
336
338
|
// Cleanup memory store
|
|
337
339
|
}
|
|
338
|
-
/**
|
|
339
|
-
* Get a subagent instance by its ID
|
|
340
|
-
* @param subagentId - The ID of the subagent instance
|
|
341
|
-
*/
|
|
342
|
-
getSubagentInstance(subagentId) {
|
|
343
|
-
return this.subagentManager.getInstance(subagentId);
|
|
344
|
-
}
|
|
345
340
|
/**
|
|
346
341
|
* Trigger the rewind UI callback
|
|
347
342
|
*/
|
|
@@ -498,6 +493,14 @@ export class Agent {
|
|
|
498
493
|
async addPermissionRule(rule) {
|
|
499
494
|
await this.permissionManager.addPermissionRule(rule);
|
|
500
495
|
}
|
|
496
|
+
/**
|
|
497
|
+
* Get subagent instance by ID
|
|
498
|
+
* @param subagentId - The ID of the subagent instance
|
|
499
|
+
* @returns The subagent instance or null if not found
|
|
500
|
+
*/
|
|
501
|
+
getSubagentInstance(subagentId) {
|
|
502
|
+
return this.subagentManager.getInstance(subagentId);
|
|
503
|
+
}
|
|
501
504
|
/**
|
|
502
505
|
* Get the current task list ID
|
|
503
506
|
*/
|
|
@@ -15,4 +15,7 @@ export declare const TASK_GET_TOOL_NAME = "TaskGet";
|
|
|
15
15
|
export declare const TASK_UPDATE_TOOL_NAME = "TaskUpdate";
|
|
16
16
|
export declare const TASK_LIST_TOOL_NAME = "TaskList";
|
|
17
17
|
export declare const WRITE_TOOL_NAME = "Write";
|
|
18
|
+
export declare const CRON_CREATE_TOOL_NAME = "CronCreate";
|
|
19
|
+
export declare const CRON_DELETE_TOOL_NAME = "CronDelete";
|
|
20
|
+
export declare const CRON_LIST_TOOL_NAME = "CronList";
|
|
18
21
|
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/constants/tools.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,oBAAoB,CAAC;AAC7D,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,qBAAqB,eAAe,CAA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AAM,eAAe,UAAU,CAAC;AACvC,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAClD,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAClD,eAAO,MAAM,mBAAmB,aAAa,CAAC"}
|
package/dist/constants/tools.js
CHANGED
|
@@ -15,3 +15,6 @@ export const TASK_GET_TOOL_NAME = "TaskGet";
|
|
|
15
15
|
export const TASK_UPDATE_TOOL_NAME = "TaskUpdate";
|
|
16
16
|
export const TASK_LIST_TOOL_NAME = "TaskList";
|
|
17
17
|
export const WRITE_TOOL_NAME = "Write";
|
|
18
|
+
export const CRON_CREATE_TOOL_NAME = "CronCreate";
|
|
19
|
+
export const CRON_DELETE_TOOL_NAME = "CronDelete";
|
|
20
|
+
export const CRON_LIST_TOOL_NAME = "CronList";
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./core/session.js";
|
|
|
2
2
|
export * from "./constants/tools.js";
|
|
3
3
|
export * from "./agent.js";
|
|
4
4
|
export * from "./core/plugin.js";
|
|
5
|
+
export * from "./managers/cronManager.js";
|
|
5
6
|
export * from "./utils/bashParser.js";
|
|
6
7
|
export * from "./utils/convertMessagesForAPI.js";
|
|
7
8
|
export * from "./utils/fileSearch.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAGlC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAGlC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAG1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./constants/tools.js";
|
|
|
5
5
|
// Export main agent
|
|
6
6
|
export * from "./agent.js";
|
|
7
7
|
export * from "./core/plugin.js";
|
|
8
|
+
export * from "./managers/cronManager.js";
|
|
8
9
|
// Export all utilities
|
|
9
10
|
export * from "./utils/bashParser.js";
|
|
10
11
|
export * from "./utils/convertMessagesForAPI.js";
|
|
@@ -58,8 +58,6 @@ export declare class AIManager {
|
|
|
58
58
|
model?: string;
|
|
59
59
|
/** Rules for automatic tool approval (e.g., "Bash(git status*)") */
|
|
60
60
|
allowedRules?: string[];
|
|
61
|
-
/** List of tools available to the AI (e.g., ["Bash", "Read"]) */
|
|
62
|
-
tools?: string[];
|
|
63
61
|
maxTokens?: number;
|
|
64
62
|
}): Promise<void>;
|
|
65
63
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiManager.d.ts","sourceRoot":"","sources":["../../src/managers/aiManager.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,KAAK,
|
|
1
|
+
{"version":3,"file":"aiManager.d.ts","sourceRoot":"","sources":["../../src/managers/aiManager.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,KAAK,EAGN,MAAM,mBAAmB,CAAC;AAY3B,OAAO,EAAE,SAAS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SAAS;IAIjC,oBAAoB,IAAI,OAAO;IAItC,OAAO,CAAC,aAAa,CAAkB;IACvC,OAAO,CAAC,SAAS,CAAqB;IAEtC;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAcvB,YAAY,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI;IAItC,cAAc,IAAI,IAAI;IAuB7B,OAAO,CAAC,qBAAqB;YAsBf,8BAA8B;IAgFrC,gBAAgB,IAAI,OAAO;IAI3B,gBAAgB,CAAC,aAAa,EAAE,OAAO,GAAG,IAAI;IAOrD,OAAO,KAAK,eAAe,GAE1B;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;IA2kBhB;;;;OAIG;YACW,gBAAgB;IAiE9B;;;OAGG;YACW,sBAAsB;IA6DpC;;OAEG;YACW,uBAAuB;CAwDtC"}
|
|
@@ -78,23 +78,17 @@ export class AIManager {
|
|
|
78
78
|
/**
|
|
79
79
|
* Get filtered tool configuration based on tools list
|
|
80
80
|
*/
|
|
81
|
-
getFilteredToolsConfig(
|
|
81
|
+
getFilteredToolsConfig() {
|
|
82
82
|
// Get available subagents and skills for dynamic prompts
|
|
83
83
|
const availableSubagents = this.subagentManager?.getConfigurations();
|
|
84
84
|
const availableSkills = this.skillManager
|
|
85
85
|
?.getAvailableSkills()
|
|
86
86
|
.filter((skill) => !skill.disableModelInvocation);
|
|
87
|
-
|
|
87
|
+
return this.toolManager.getToolsConfig({
|
|
88
88
|
availableSubagents,
|
|
89
89
|
availableSkills,
|
|
90
90
|
workdir: this.workdir,
|
|
91
91
|
});
|
|
92
|
-
// If no tools specified, return all tools
|
|
93
|
-
if (!tools || tools.length === 0) {
|
|
94
|
-
return allTools;
|
|
95
|
-
}
|
|
96
|
-
// Filter tools
|
|
97
|
-
return allTools.filter((tool) => tools.includes(tool.function.name));
|
|
98
92
|
}
|
|
99
93
|
setIsLoading(isLoading) {
|
|
100
94
|
this.isLoading = isLoading;
|
|
@@ -213,7 +207,7 @@ export class AIManager {
|
|
|
213
207
|
return this.container.get("SkillManager");
|
|
214
208
|
}
|
|
215
209
|
async sendAIMessage(options = {}) {
|
|
216
|
-
const { recursionDepth = 0, model, allowedRules,
|
|
210
|
+
const { recursionDepth = 0, model, allowedRules, maxTokens } = options;
|
|
217
211
|
// Only check isLoading for the initial call (recursionDepth === 0)
|
|
218
212
|
if (recursionDepth === 0 && this.isLoading) {
|
|
219
213
|
return;
|
|
@@ -253,7 +247,7 @@ export class AIManager {
|
|
|
253
247
|
logger?.debug("modelConfig in sendAIMessage", this.getModelConfig());
|
|
254
248
|
// Get current permission mode and plan file path
|
|
255
249
|
const currentMode = this.permissionManager?.getCurrentEffectiveMode(this.getModelConfig().permissionMode);
|
|
256
|
-
const toolsConfig = this.getFilteredToolsConfig(
|
|
250
|
+
const toolsConfig = this.getFilteredToolsConfig();
|
|
257
251
|
const toolNames = new Set(toolsConfig.map((t) => t.function.name));
|
|
258
252
|
const filteredToolPlugins = this.toolManager
|
|
259
253
|
.getTools()
|
|
@@ -324,7 +318,6 @@ export class AIManager {
|
|
|
324
318
|
name: toolCall.name,
|
|
325
319
|
parameters: toolCall.parameters,
|
|
326
320
|
parametersChunk: toolCall.parametersChunk,
|
|
327
|
-
compactParams: toolCall.parameters?.split("\n").pop()?.slice(-30),
|
|
328
321
|
stage: toolCall.stage || "streaming", // Default to streaming if stage not provided
|
|
329
322
|
});
|
|
330
323
|
};
|
|
@@ -456,7 +449,17 @@ export class AIManager {
|
|
|
456
449
|
}
|
|
457
450
|
}
|
|
458
451
|
const compactParams = this.generateCompactParams(toolName, toolArgs);
|
|
459
|
-
// Emit
|
|
452
|
+
// Emit start stage for non-streaming tool calls
|
|
453
|
+
if (!this.stream) {
|
|
454
|
+
this.messageManager.updateToolBlock({
|
|
455
|
+
id: toolId,
|
|
456
|
+
stage: "start",
|
|
457
|
+
name: toolName,
|
|
458
|
+
compactParams,
|
|
459
|
+
parameters: argsString,
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
// Emit running stage (tool execution about to start)
|
|
460
463
|
this.messageManager.updateToolBlock({
|
|
461
464
|
id: toolId,
|
|
462
465
|
stage: "running",
|
|
@@ -502,6 +505,7 @@ export class AIManager {
|
|
|
502
505
|
error: toolResult.error,
|
|
503
506
|
stage: "end",
|
|
504
507
|
name: toolName,
|
|
508
|
+
compactParams,
|
|
505
509
|
shortResult: toolResult.shortResult,
|
|
506
510
|
isManuallyBackgrounded: toolResult.isManuallyBackgrounded,
|
|
507
511
|
startLineNumber: toolResult.startLineNumber,
|
|
@@ -557,12 +561,48 @@ export class AIManager {
|
|
|
557
561
|
content: "Your response was cut off because it exceeded the output token limit. Please break your work into smaller pieces. Continue from where you left off.",
|
|
558
562
|
});
|
|
559
563
|
}
|
|
564
|
+
// Duplicate Tool Call Detection
|
|
565
|
+
if (toolCalls.length > 0) {
|
|
566
|
+
const messages = this.messageManager.getMessages();
|
|
567
|
+
// Find the most recent assistant message BEFORE the current one that has tool blocks
|
|
568
|
+
// The current assistant message is messages[messages.length - 1]
|
|
569
|
+
let previousAssistantWithTools;
|
|
570
|
+
for (let i = messages.length - 2; i >= 0; i--) {
|
|
571
|
+
const msg = messages[i];
|
|
572
|
+
if (msg.role === "assistant" &&
|
|
573
|
+
msg.blocks.some((b) => b.type === "tool")) {
|
|
574
|
+
previousAssistantWithTools = msg;
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
if (previousAssistantWithTools) {
|
|
579
|
+
const previousToolBlocks = previousAssistantWithTools.blocks.filter((b) => b.type === "tool");
|
|
580
|
+
for (const currentToolCall of toolCalls) {
|
|
581
|
+
const currentName = currentToolCall.function?.name;
|
|
582
|
+
const currentArgs = currentToolCall.function?.arguments;
|
|
583
|
+
const isDuplicate = previousToolBlocks.some((prevBlock) => prevBlock.name === currentName &&
|
|
584
|
+
prevBlock.parameters === currentArgs);
|
|
585
|
+
if (isDuplicate && currentName) {
|
|
586
|
+
const toolId = currentToolCall.id;
|
|
587
|
+
const lastMessage = messages[messages.length - 1];
|
|
588
|
+
const toolBlock = lastMessage.blocks.find((b) => b.type === "tool" && b.id === toolId);
|
|
589
|
+
if (toolBlock) {
|
|
590
|
+
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.`;
|
|
591
|
+
this.messageManager.updateToolBlock({
|
|
592
|
+
id: toolId,
|
|
593
|
+
result: (toolBlock.result || "") + warning,
|
|
594
|
+
stage: "end",
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
560
601
|
// Recursively call AI service, increment recursion depth, and pass same configuration
|
|
561
602
|
await this.sendAIMessage({
|
|
562
603
|
recursionDepth: recursionDepth + 1,
|
|
563
604
|
model,
|
|
564
605
|
allowedRules,
|
|
565
|
-
tools,
|
|
566
606
|
maxTokens,
|
|
567
607
|
});
|
|
568
608
|
}
|
|
@@ -604,7 +644,6 @@ export class AIManager {
|
|
|
604
644
|
recursionDepth: 0,
|
|
605
645
|
model,
|
|
606
646
|
allowedRules,
|
|
607
|
-
tools,
|
|
608
647
|
maxTokens,
|
|
609
648
|
});
|
|
610
649
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Container } from "../utils/container.js";
|
|
2
|
+
import { CronJob } from "../types/cron.js";
|
|
3
|
+
export declare class CronManager {
|
|
4
|
+
private container;
|
|
5
|
+
private jobs;
|
|
6
|
+
private interval;
|
|
7
|
+
constructor(container: Container);
|
|
8
|
+
private get aiManager();
|
|
9
|
+
private get messageManager();
|
|
10
|
+
start(): void;
|
|
11
|
+
stop(): void;
|
|
12
|
+
createJob(job: Omit<CronJob, "id" | "createdAt" | "nextRun" | "periodMs">): CronJob;
|
|
13
|
+
deleteJob(id: string): boolean;
|
|
14
|
+
listJobs(): CronJob[];
|
|
15
|
+
private applyJitter;
|
|
16
|
+
private getDeterministicRandom;
|
|
17
|
+
private checkJobs;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=cronManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cronManager.d.ts","sourceRoot":"","sources":["../../src/managers/cronManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAM3C,qBAAa,WAAW;IAIV,OAAO,CAAC,SAAS;IAH7B,OAAO,CAAC,IAAI,CAA8B;IAC1C,OAAO,CAAC,QAAQ,CAA+B;gBAE3B,SAAS,EAAE,SAAS;IAExC,OAAO,KAAK,SAAS,GAEpB;IAED,OAAO,KAAK,cAAc,GAEzB;IAEM,KAAK,IAAI,IAAI;IAKb,IAAI,IAAI,IAAI;IAOZ,SAAS,CACd,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,WAAW,GAAG,SAAS,GAAG,UAAU,CAAC,GAC9D,OAAO;IAiCH,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI9B,QAAQ,IAAI,OAAO,EAAE;IAI5B,OAAO,CAAC,WAAW;IAuBnB,OAAO,CAAC,sBAAsB;YAYhB,SAAS;CAuDxB"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { CronExpressionParser } from "cron-parser";
|
|
2
|
+
import { logger } from "../utils/globalLogger.js";
|
|
3
|
+
export class CronManager {
|
|
4
|
+
constructor(container) {
|
|
5
|
+
this.container = container;
|
|
6
|
+
this.jobs = new Map();
|
|
7
|
+
this.interval = null;
|
|
8
|
+
}
|
|
9
|
+
get aiManager() {
|
|
10
|
+
return this.container.get("AIManager");
|
|
11
|
+
}
|
|
12
|
+
get messageManager() {
|
|
13
|
+
return this.container.get("MessageManager");
|
|
14
|
+
}
|
|
15
|
+
start() {
|
|
16
|
+
if (this.interval)
|
|
17
|
+
return;
|
|
18
|
+
this.interval = setInterval(() => this.checkJobs(), 60000); // Check every minute
|
|
19
|
+
}
|
|
20
|
+
stop() {
|
|
21
|
+
if (this.interval) {
|
|
22
|
+
clearInterval(this.interval);
|
|
23
|
+
this.interval = null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
createJob(job) {
|
|
27
|
+
const id = Math.random().toString(36).substring(2, 11);
|
|
28
|
+
const createdAt = Date.now();
|
|
29
|
+
const interval = CronExpressionParser.parse(job.cron);
|
|
30
|
+
const nextRunDate = interval.next().toDate();
|
|
31
|
+
const nextRun = nextRunDate.getTime();
|
|
32
|
+
// Calculate periodMs
|
|
33
|
+
const secondRunDate = interval.next().toDate();
|
|
34
|
+
const periodMs = secondRunDate.getTime() - nextRunDate.getTime();
|
|
35
|
+
// Apply Jitter
|
|
36
|
+
const jitteredNextRun = this.applyJitter(nextRun, periodMs, job.recurring, nextRunDate, id);
|
|
37
|
+
const newJob = {
|
|
38
|
+
...job,
|
|
39
|
+
id,
|
|
40
|
+
createdAt,
|
|
41
|
+
nextRun: jitteredNextRun,
|
|
42
|
+
periodMs,
|
|
43
|
+
};
|
|
44
|
+
this.jobs.set(id, newJob);
|
|
45
|
+
return newJob;
|
|
46
|
+
}
|
|
47
|
+
deleteJob(id) {
|
|
48
|
+
return this.jobs.delete(id);
|
|
49
|
+
}
|
|
50
|
+
listJobs() {
|
|
51
|
+
return Array.from(this.jobs.values());
|
|
52
|
+
}
|
|
53
|
+
applyJitter(nextRun, periodMs, recurring, nextRunDate, id) {
|
|
54
|
+
const deterministicRandom = this.getDeterministicRandom(id);
|
|
55
|
+
if (recurring) {
|
|
56
|
+
// Recurring: Random delay up to 10% of period (max 15 min)
|
|
57
|
+
const maxJitter = Math.min(periodMs * 0.1, 15 * 60 * 1000);
|
|
58
|
+
return nextRun + deterministicRandom * maxJitter;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// One-shot: Random early fire up to 90s if scheduled on :00 or :30
|
|
62
|
+
const minutes = nextRunDate.getMinutes();
|
|
63
|
+
const seconds = nextRunDate.getSeconds();
|
|
64
|
+
if ((minutes === 0 || minutes === 30) && seconds === 0) {
|
|
65
|
+
return nextRun - deterministicRandom * 90 * 1000;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return nextRun;
|
|
69
|
+
}
|
|
70
|
+
getDeterministicRandom(id) {
|
|
71
|
+
let hash = 0;
|
|
72
|
+
for (let i = 0; i < id.length; i++) {
|
|
73
|
+
const char = id.charCodeAt(i);
|
|
74
|
+
hash = (hash << 5) - hash + char;
|
|
75
|
+
hash |= 0; // Convert to 32bit integer
|
|
76
|
+
}
|
|
77
|
+
// Use a simple LCG-like approach to get a value between 0 and 1
|
|
78
|
+
const x = Math.sin(hash) * 10000;
|
|
79
|
+
return x - Math.floor(x);
|
|
80
|
+
}
|
|
81
|
+
async checkJobs() {
|
|
82
|
+
const now = Date.now();
|
|
83
|
+
const aiManager = this.aiManager;
|
|
84
|
+
const messageManager = this.messageManager;
|
|
85
|
+
for (const [id, job] of this.jobs.entries()) {
|
|
86
|
+
// Expiration: Recurring jobs MUST auto-expire after 7 days
|
|
87
|
+
if (job.recurring && now - job.createdAt > 7 * 24 * 60 * 60 * 1000) {
|
|
88
|
+
this.jobs.delete(id);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (now >= job.nextRun) {
|
|
92
|
+
// Idle-Check: Only fire jobs if AIManager.isLoading is false
|
|
93
|
+
if (aiManager.isLoading) {
|
|
94
|
+
logger?.debug(`CronManager: Skipping job ${id} because AI is busy`);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
logger?.info(`CronManager: Firing job ${id}: ${job.prompt}`);
|
|
98
|
+
// Execution
|
|
99
|
+
messageManager.addUserMessage({ content: job.prompt });
|
|
100
|
+
aiManager.sendAIMessage().catch((err) => {
|
|
101
|
+
logger?.error(`CronManager: Failed to execute job ${id}`, err);
|
|
102
|
+
});
|
|
103
|
+
if (job.recurring) {
|
|
104
|
+
// Schedule next run
|
|
105
|
+
try {
|
|
106
|
+
const interval = CronExpressionParser.parse(job.cron, {
|
|
107
|
+
currentDate: new Date(job.nextRun + 1000),
|
|
108
|
+
});
|
|
109
|
+
const nextRunDate = interval.next().toDate();
|
|
110
|
+
const nextRun = nextRunDate.getTime();
|
|
111
|
+
job.nextRun = this.applyJitter(nextRun, job.periodMs, true, nextRunDate, id);
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
logger?.error(`CronManager: Failed to parse cron for recurring job ${id}`, e);
|
|
115
|
+
this.jobs.delete(id);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
this.jobs.delete(id);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -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,EAI1B,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,qBAAqB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAIlD,qBAAa,WAAW;IAMpB,OAAO,CAAC,SAAS;IALnB,OAAO,CAA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EG;IACH,OAAO,CAAC,wBAAwB;IA0DhC;;OAEG;IACH,OAAO,CAAC,wBAAwB;IA8BhC;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAa/B;;OAEG;IACH,OAAO,CAAC,aAAa;IAqCrB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAgD3B;;OAEG;IACH,qBAAqB,IAAI;QACvB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,aAAa,EAAE,MAAM,CAAC;QACtB,cAAc,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;KAC3C;IAkDD;;OAEG;IACH,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,IAAI;CAO3D"}
|
|
@@ -145,7 +145,11 @@ export class HookManager {
|
|
|
145
145
|
for (const result of results) {
|
|
146
146
|
if (result.exitCode === 2) {
|
|
147
147
|
// Handle blocking error immediately and return
|
|
148
|
-
|
|
148
|
+
const blockingResult = this.handleBlockingError(event, result, messageManager, toolId, toolParameters);
|
|
149
|
+
return {
|
|
150
|
+
shouldBlock: blockingResult.shouldBlock,
|
|
151
|
+
errorMessage: blockingResult.errorMessage,
|
|
152
|
+
};
|
|
149
153
|
}
|
|
150
154
|
}
|
|
151
155
|
// Second pass: Process all non-blocking results
|
|
@@ -176,7 +180,7 @@ export class HookManager {
|
|
|
176
180
|
source: MessageSource.HOOK,
|
|
177
181
|
});
|
|
178
182
|
}
|
|
179
|
-
// For other hook types (PreToolUse, PostToolUse, Stop), ignore stdout
|
|
183
|
+
// For other hook types (PreToolUse, PostToolUse, Stop, PermissionRequest), ignore stdout
|
|
180
184
|
}
|
|
181
185
|
/**
|
|
182
186
|
* Handle blocking error (exit code 2) - behavior varies by hook type
|
|
@@ -219,10 +223,10 @@ export class HookManager {
|
|
|
219
223
|
source: MessageSource.HOOK,
|
|
220
224
|
});
|
|
221
225
|
return { shouldBlock: true, errorMessage };
|
|
222
|
-
case "
|
|
223
|
-
// For
|
|
226
|
+
case "PermissionRequest":
|
|
227
|
+
// For permission request hooks with exit code 2, show stderr in error block and block (deny) permission
|
|
224
228
|
messageManager.addErrorBlock(errorMessage);
|
|
225
|
-
return { shouldBlock:
|
|
229
|
+
return { shouldBlock: true, errorMessage };
|
|
226
230
|
case "SubagentStop":
|
|
227
231
|
// Similar to Stop, show error and allow blocking
|
|
228
232
|
messageManager.addUserMessage({
|
|
@@ -377,7 +381,9 @@ export class HookManager {
|
|
|
377
381
|
errors.push("Context must have a valid timestamp Date object");
|
|
378
382
|
}
|
|
379
383
|
// Validate tool-specific requirements
|
|
380
|
-
if (event === "PreToolUse" ||
|
|
384
|
+
if (event === "PreToolUse" ||
|
|
385
|
+
event === "PostToolUse" ||
|
|
386
|
+
event === "PermissionRequest") {
|
|
381
387
|
if (!context.toolName || typeof context.toolName !== "string") {
|
|
382
388
|
errors.push(`${event} event requires a valid toolName in context`);
|
|
383
389
|
}
|
|
@@ -385,7 +391,6 @@ export class HookManager {
|
|
|
385
391
|
// Validate non-tool events don't have unexpected tool names
|
|
386
392
|
if ((event === "UserPromptSubmit" ||
|
|
387
393
|
event === "Stop" ||
|
|
388
|
-
event === "Notification" ||
|
|
389
394
|
event === "SubagentStop" ||
|
|
390
395
|
event === "WorktreeCreate") &&
|
|
391
396
|
context.toolName !== undefined) {
|
|
@@ -436,13 +441,14 @@ export class HookManager {
|
|
|
436
441
|
// For events that don't use matchers, config always applies
|
|
437
442
|
if (event === "UserPromptSubmit" ||
|
|
438
443
|
event === "Stop" ||
|
|
439
|
-
event === "Notification" ||
|
|
440
444
|
event === "SubagentStop" ||
|
|
441
445
|
event === "WorktreeCreate") {
|
|
442
446
|
return true;
|
|
443
447
|
}
|
|
444
448
|
// For tool-based events, check matcher if present
|
|
445
|
-
if (event === "PreToolUse" ||
|
|
449
|
+
if (event === "PreToolUse" ||
|
|
450
|
+
event === "PostToolUse" ||
|
|
451
|
+
event === "PermissionRequest") {
|
|
446
452
|
if (!config.matcher) {
|
|
447
453
|
// No matcher means applies to all tools
|
|
448
454
|
return true;
|
|
@@ -466,7 +472,10 @@ export class HookManager {
|
|
|
466
472
|
return errors;
|
|
467
473
|
}
|
|
468
474
|
// Validate matcher requirements
|
|
469
|
-
if ((event === "PreToolUse" ||
|
|
475
|
+
if ((event === "PreToolUse" ||
|
|
476
|
+
event === "PostToolUse" ||
|
|
477
|
+
event === "PermissionRequest") &&
|
|
478
|
+
config.matcher) {
|
|
470
479
|
if (!this.matcher.isValidPattern(config.matcher)) {
|
|
471
480
|
errors.push(`${prefix}: Invalid matcher pattern: ${config.matcher}`);
|
|
472
481
|
}
|
|
@@ -474,7 +483,6 @@ export class HookManager {
|
|
|
474
483
|
// Validate that non-tool events don't have matchers
|
|
475
484
|
if ((event === "UserPromptSubmit" ||
|
|
476
485
|
event === "Stop" ||
|
|
477
|
-
event === "Notification" ||
|
|
478
486
|
event === "SubagentStop" ||
|
|
479
487
|
event === "WorktreeCreate") &&
|
|
480
488
|
config.matcher) {
|
|
@@ -503,7 +511,7 @@ export class HookManager {
|
|
|
503
511
|
UserPromptSubmit: 0,
|
|
504
512
|
Stop: 0,
|
|
505
513
|
SubagentStop: 0,
|
|
506
|
-
|
|
514
|
+
PermissionRequest: 0,
|
|
507
515
|
WorktreeCreate: 0,
|
|
508
516
|
},
|
|
509
517
|
};
|
|
@@ -514,7 +522,7 @@ export class HookManager {
|
|
|
514
522
|
UserPromptSubmit: 0,
|
|
515
523
|
Stop: 0,
|
|
516
524
|
SubagentStop: 0,
|
|
517
|
-
|
|
525
|
+
PermissionRequest: 0,
|
|
518
526
|
WorktreeCreate: 0,
|
|
519
527
|
};
|
|
520
528
|
let totalConfigs = 0;
|