wave-agent-sdk 0.4.0 → 0.6.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/dist/agent.d.ts +42 -11
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +114 -115
- package/dist/constants/prompts.d.ts +18 -14
- package/dist/constants/prompts.d.ts.map +1 -1
- package/dist/constants/prompts.js +130 -54
- package/dist/constants/tools.d.ts +6 -3
- package/dist/constants/tools.d.ts.map +1 -1
- package/dist/constants/tools.js +6 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/managers/MemoryRuleManager.js +1 -1
- package/dist/managers/aiManager.d.ts +5 -3
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +57 -20
- package/dist/managers/backgroundBashManager.d.ts.map +1 -1
- package/dist/managers/backgroundBashManager.js +1 -0
- package/dist/managers/backgroundTaskManager.d.ts +35 -0
- package/dist/managers/backgroundTaskManager.d.ts.map +1 -0
- package/dist/managers/backgroundTaskManager.js +255 -0
- package/dist/managers/foregroundTaskManager.d.ts +9 -0
- package/dist/managers/foregroundTaskManager.d.ts.map +1 -0
- package/dist/managers/foregroundTaskManager.js +21 -0
- package/dist/managers/liveConfigManager.d.ts +1 -1
- package/dist/managers/lspManager.d.ts.map +1 -1
- package/dist/managers/lspManager.js +3 -1
- package/dist/managers/mcpManager.d.ts.map +1 -1
- package/dist/managers/messageManager.d.ts +26 -12
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +138 -64
- package/dist/managers/permissionManager.d.ts.map +1 -1
- package/dist/managers/permissionManager.js +26 -22
- package/dist/managers/planManager.d.ts +1 -1
- package/dist/managers/planManager.d.ts.map +1 -1
- package/dist/managers/planManager.js +2 -2
- package/dist/managers/pluginManager.d.ts.map +1 -1
- package/dist/managers/pluginManager.js +3 -2
- package/dist/managers/slashCommandManager.d.ts +6 -0
- package/dist/managers/slashCommandManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.js +8 -2
- package/dist/managers/subagentManager.d.ts +15 -2
- package/dist/managers/subagentManager.d.ts.map +1 -1
- package/dist/managers/subagentManager.js +153 -39
- package/dist/managers/toolManager.d.ts +18 -1
- package/dist/managers/toolManager.d.ts.map +1 -1
- package/dist/managers/toolManager.js +29 -5
- package/dist/services/GitService.d.ts.map +1 -1
- package/dist/services/GitService.js +6 -2
- package/dist/services/MarketplaceService.d.ts +2 -2
- package/dist/services/MarketplaceService.d.ts.map +1 -1
- package/dist/services/MarketplaceService.js +18 -11
- package/dist/services/MemoryRuleService.d.ts +1 -1
- package/dist/services/MemoryRuleService.d.ts.map +1 -1
- package/dist/services/MemoryRuleService.js +13 -2
- package/dist/services/aiService.d.ts +0 -1
- package/dist/services/aiService.d.ts.map +1 -1
- package/dist/services/aiService.js +4 -140
- package/dist/services/memory.d.ts +0 -3
- package/dist/services/memory.d.ts.map +1 -1
- package/dist/services/memory.js +1 -60
- package/dist/services/session.d.ts +15 -1
- package/dist/services/session.d.ts.map +1 -1
- package/dist/services/session.js +57 -1
- package/dist/services/taskManager.d.ts +21 -0
- package/dist/services/taskManager.d.ts.map +1 -0
- package/dist/services/taskManager.js +158 -0
- package/dist/tools/askUserQuestion.d.ts.map +1 -1
- package/dist/tools/askUserQuestion.js +39 -25
- package/dist/tools/bashTool.d.ts +0 -8
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +48 -172
- package/dist/tools/editTool.d.ts.map +1 -1
- package/dist/tools/editTool.js +8 -6
- package/dist/tools/exitPlanMode.d.ts.map +1 -1
- package/dist/tools/exitPlanMode.js +25 -1
- package/dist/tools/globTool.d.ts.map +1 -1
- package/dist/tools/globTool.js +8 -2
- package/dist/tools/grepTool.d.ts.map +1 -1
- package/dist/tools/grepTool.js +17 -6
- package/dist/tools/lsTool.d.ts.map +1 -1
- package/dist/tools/lsTool.js +3 -1
- package/dist/tools/multiEditTool.d.ts.map +1 -1
- package/dist/tools/multiEditTool.js +7 -6
- package/dist/tools/readTool.d.ts.map +1 -1
- package/dist/tools/readTool.js +16 -1
- package/dist/tools/taskManagementTools.d.ts +6 -0
- package/dist/tools/taskManagementTools.d.ts.map +1 -0
- package/dist/tools/taskManagementTools.js +453 -0
- package/dist/tools/taskOutputTool.d.ts +3 -0
- package/dist/tools/taskOutputTool.d.ts.map +1 -0
- package/dist/tools/taskOutputTool.js +173 -0
- package/dist/tools/taskStopTool.d.ts +3 -0
- package/dist/tools/taskStopTool.d.ts.map +1 -0
- package/dist/tools/taskStopTool.js +71 -0
- package/dist/tools/taskTool.d.ts.map +1 -1
- package/dist/tools/taskTool.js +110 -63
- package/dist/tools/types.d.ts +12 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/writeTool.d.ts.map +1 -1
- package/dist/tools/writeTool.js +9 -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/marketplace.d.ts +1 -0
- package/dist/types/marketplace.d.ts.map +1 -1
- package/dist/types/messaging.d.ts +3 -8
- package/dist/types/messaging.d.ts.map +1 -1
- package/dist/types/processes.d.ts +29 -4
- package/dist/types/processes.d.ts.map +1 -1
- package/dist/types/tasks.d.ts +13 -0
- package/dist/types/tasks.d.ts.map +1 -0
- package/dist/types/tasks.js +1 -0
- package/dist/types/tools.d.ts +4 -1
- package/dist/types/tools.d.ts.map +1 -1
- package/dist/utils/builtinSubagents.d.ts.map +1 -1
- package/dist/utils/builtinSubagents.js +38 -1
- package/dist/utils/cacheControlUtils.d.ts.map +1 -1
- package/dist/utils/cacheControlUtils.js +18 -12
- package/dist/utils/constants.d.ts +0 -4
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +0 -4
- package/dist/utils/convertMessagesForAPI.js +2 -2
- package/dist/utils/editUtils.d.ts +2 -11
- package/dist/utils/editUtils.d.ts.map +1 -1
- package/dist/utils/editUtils.js +52 -79
- package/dist/utils/messageOperations.d.ts +5 -36
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +9 -98
- package/dist/utils/nameGenerator.d.ts +1 -1
- package/dist/utils/nameGenerator.d.ts.map +1 -1
- package/dist/utils/nameGenerator.js +19 -3
- package/package.json +5 -5
- package/src/agent.ts +157 -134
- package/src/constants/prompts.ts +156 -65
- package/src/constants/tools.ts +6 -3
- package/src/index.ts +1 -0
- package/src/managers/MemoryRuleManager.ts +1 -1
- package/src/managers/aiManager.ts +77 -35
- package/src/managers/backgroundBashManager.ts +1 -0
- package/src/managers/backgroundTaskManager.ts +305 -0
- package/src/managers/foregroundTaskManager.ts +27 -0
- package/src/managers/lspManager.ts +3 -1
- package/src/managers/mcpManager.ts +6 -3
- package/src/managers/messageManager.ts +185 -75
- package/src/managers/permissionManager.ts +33 -28
- package/src/managers/planManager.ts +2 -2
- package/src/managers/pluginManager.ts +4 -3
- package/src/managers/slashCommandManager.ts +15 -2
- package/src/managers/subagentManager.ts +194 -35
- package/src/managers/toolManager.ts +48 -6
- package/src/services/GitService.ts +6 -2
- package/src/services/MarketplaceService.ts +30 -12
- package/src/services/MemoryRuleService.ts +18 -6
- package/src/services/aiService.ts +3 -145
- package/src/services/memory.ts +1 -73
- package/src/services/session.ts +73 -0
- package/src/services/taskManager.ts +188 -0
- package/src/tools/askUserQuestion.ts +51 -29
- package/src/tools/bashTool.ts +63 -196
- package/src/tools/editTool.ts +9 -18
- package/src/tools/exitPlanMode.ts +26 -2
- package/src/tools/globTool.ts +10 -2
- package/src/tools/grepTool.ts +17 -6
- package/src/tools/lsTool.ts +3 -1
- package/src/tools/multiEditTool.ts +7 -18
- package/src/tools/readTool.ts +17 -1
- package/src/tools/taskManagementTools.ts +498 -0
- package/src/tools/taskOutputTool.ts +196 -0
- package/src/tools/taskStopTool.ts +78 -0
- package/src/tools/taskTool.ts +136 -74
- package/src/tools/types.ts +13 -0
- package/src/tools/writeTool.ts +9 -2
- package/src/types/index.ts +1 -0
- package/src/types/marketplace.ts +1 -0
- package/src/types/messaging.ts +2 -9
- package/src/types/processes.ts +39 -4
- package/src/types/tasks.ts +13 -0
- package/src/types/tools.ts +4 -1
- package/src/utils/builtinSubagents.ts +47 -1
- package/src/utils/cacheControlUtils.ts +26 -18
- package/src/utils/constants.ts +0 -5
- package/src/utils/convertMessagesForAPI.ts +2 -2
- package/src/utils/editUtils.ts +65 -103
- package/src/utils/messageOperations.ts +12 -136
- package/src/utils/nameGenerator.ts +20 -3
- package/dist/tools/todoWriteTool.d.ts +0 -6
- package/dist/tools/todoWriteTool.d.ts.map +0 -1
- package/dist/tools/todoWriteTool.js +0 -220
- package/src/tools/todoWriteTool.ts +0 -257
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ASK_USER_QUESTION_TOOL_NAME, BASH_TOOL_NAME, EDIT_TOOL_NAME, GLOB_TOOL_NAME, GREP_TOOL_NAME,
|
|
1
|
+
import { ASK_USER_QUESTION_TOOL_NAME, BASH_TOOL_NAME, EDIT_TOOL_NAME, GLOB_TOOL_NAME, GREP_TOOL_NAME, READ_TOOL_NAME, TASK_CREATE_TOOL_NAME, TASK_GET_TOOL_NAME, TASK_UPDATE_TOOL_NAME, TASK_LIST_TOOL_NAME, WRITE_TOOL_NAME, } from "./tools.js";
|
|
2
2
|
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.
|
|
3
3
|
|
|
4
4
|
# Doing tasks
|
|
@@ -17,25 +17,33 @@ The user will primarily request you perform software engineering tasks. This inc
|
|
|
17
17
|
- 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.`;
|
|
18
18
|
export const TASK_MANAGEMENT_POLICY = `
|
|
19
19
|
# Task Management
|
|
20
|
-
You have access to the ${
|
|
20
|
+
You have access to the ${TASK_CREATE_TOOL_NAME}, ${TASK_GET_TOOL_NAME}, ${TASK_UPDATE_TOOL_NAME}, and ${TASK_LIST_TOOL_NAME} tools to help you manage and plan tasks. Use these tools VERY frequently to ensure that you are tracking your tasks and giving the user visibility into your progress.
|
|
21
21
|
These tools are also EXTREMELY helpful for planning tasks, and for breaking down larger complex tasks into smaller steps. If you do not use this tool when planning, you may forget to do important tasks - and that is unacceptable.
|
|
22
|
-
It is critical that you mark
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export const SEARCH_FILE_POLICY = ` ${LS_TOOL_NAME}/${GLOB_TOOL_NAME}/${GREP_TOOL_NAME} for searching and listing files instead of find/ls/grep`;
|
|
35
|
-
export const BASH_POLICY = `
|
|
36
|
-
- 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.
|
|
37
|
-
- 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 to run the calls in parallel.`;
|
|
22
|
+
It is critical that you mark tasks as completed as soon as you are done with a task. Do not batch up multiple tasks before marking them as completed.`;
|
|
23
|
+
export function buildPlanModePrompt(planFilePath, planExists) {
|
|
24
|
+
const planFileInfo = planExists
|
|
25
|
+
? `A plan file already exists at ${planFilePath}. You can read it and make incremental edits using the ${EDIT_TOOL_NAME} tool if you need to.`
|
|
26
|
+
: `No plan file exists yet. You should create your plan at ${planFilePath} using the ${WRITE_TOOL_NAME} tool if you need to.`;
|
|
27
|
+
return `Plan mode is active. The user indicated that they do not want you to execute yet -- you MUST NOT make any edits, run any non-readonly tools (including changing configs or making commits), or otherwise make any changes to the system. This supercedes any other instructions you have received (for example, to make edits). Instead, you should:
|
|
28
|
+
|
|
29
|
+
## Plan File Info:
|
|
30
|
+
${planFileInfo}
|
|
31
|
+
You should build your plan incrementally by writing to or editing this file. NOTE that this is the only file you are allowed to edit - other than this you are only allowed to take READ-ONLY actions.
|
|
32
|
+
Answer the user's query comprehensively. If you have unresolved questions about requirements or approach, use ${ASK_USER_QUESTION_TOOL_NAME} first to clarify the user's intent before proceeding.`;
|
|
33
|
+
}
|
|
38
34
|
export const DEFAULT_SYSTEM_PROMPT = BASE_SYSTEM_PROMPT;
|
|
35
|
+
export const BASH_SUBAGENT_SYSTEM_PROMPT = `You are a command execution specialist. Your role is to execute bash commands efficiently and safely.
|
|
36
|
+
|
|
37
|
+
Guidelines:
|
|
38
|
+
- Execute commands precisely as instructed
|
|
39
|
+
- For git operations, follow git safety protocols
|
|
40
|
+
- Report command output clearly and concisely
|
|
41
|
+
- If a command fails, explain the error and suggest solutions
|
|
42
|
+
- Use command chaining (&&) for dependent operations
|
|
43
|
+
- Quote paths with spaces properly
|
|
44
|
+
- For clear communication, avoid using emojis
|
|
45
|
+
|
|
46
|
+
Complete the requested operations efficiently.`;
|
|
39
47
|
export const GENERAL_PURPOSE_SYSTEM_PROMPT = `You are an agent. Given the user's message, you should use the tools available to complete the task. Do what has been asked; nothing more, nothing less. When you complete the task simply respond with a detailed writeup.
|
|
40
48
|
|
|
41
49
|
Your strengths:
|
|
@@ -45,13 +53,63 @@ Your strengths:
|
|
|
45
53
|
- Performing multi-step research tasks
|
|
46
54
|
|
|
47
55
|
Guidelines:
|
|
48
|
-
- For file searches: Use
|
|
56
|
+
- For file searches: Use ${GREP_TOOL_NAME} or ${GLOB_TOOL_NAME} when you need to search broadly. Use ${READ_TOOL_NAME} when you know the specific file path.
|
|
49
57
|
- For analysis: Start broad and narrow down. Use multiple search strategies if the first doesn't yield results.
|
|
50
58
|
- Be thorough: Check multiple locations, consider different naming conventions, look for related files.
|
|
51
59
|
- NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one.
|
|
52
60
|
- NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested.
|
|
53
61
|
- In your final response always share relevant file names and code snippets. Any file paths you return in your response MUST be absolute. Do NOT use relative paths.
|
|
54
62
|
- For clear communication, avoid using emojis.`;
|
|
63
|
+
export const PLAN_SUBAGENT_SYSTEM_PROMPT = `You are a software architect and planning specialist. Your role is to explore the codebase and design implementation plans.
|
|
64
|
+
|
|
65
|
+
=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===
|
|
66
|
+
This is a READ-ONLY planning task. You are STRICTLY PROHIBITED from:
|
|
67
|
+
- Creating new files (no Write, touch, or file creation of any kind)
|
|
68
|
+
- Modifying existing files (no Edit operations)
|
|
69
|
+
- Deleting files (no rm or deletion)
|
|
70
|
+
- Moving or copying files (no mv or cp)
|
|
71
|
+
- Creating temporary files anywhere, including /tmp
|
|
72
|
+
- Using redirect operators (>, >>, |) or heredocs to write to files
|
|
73
|
+
- Running ANY commands that change system state
|
|
74
|
+
|
|
75
|
+
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.
|
|
76
|
+
|
|
77
|
+
You will be provided with a set of requirements and optionally a perspective on how to approach the design process.
|
|
78
|
+
|
|
79
|
+
## Your Process
|
|
80
|
+
|
|
81
|
+
1. **Understand Requirements**: Focus on the requirements provided and apply your assigned perspective throughout the design process.
|
|
82
|
+
|
|
83
|
+
2. **Explore Thoroughly**:
|
|
84
|
+
- Read any files provided to you in the initial prompt
|
|
85
|
+
- Find existing patterns and conventions using ${GLOB_TOOL_NAME}, ${GREP_TOOL_NAME}, and ${READ_TOOL_NAME}
|
|
86
|
+
- Understand the current architecture
|
|
87
|
+
- Identify similar features as reference
|
|
88
|
+
- Trace through relevant code paths
|
|
89
|
+
- Use ${BASH_TOOL_NAME} ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)
|
|
90
|
+
- NEVER use ${BASH_TOOL_NAME} for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification
|
|
91
|
+
|
|
92
|
+
3. **Design Solution**:
|
|
93
|
+
- Create implementation approach based on your assigned perspective
|
|
94
|
+
- Consider trade-offs and architectural decisions
|
|
95
|
+
- Follow existing patterns where appropriate
|
|
96
|
+
|
|
97
|
+
4. **Detail the Plan**:
|
|
98
|
+
- Provide step-by-step implementation strategy
|
|
99
|
+
- Identify dependencies and sequencing
|
|
100
|
+
- Anticipate potential challenges
|
|
101
|
+
|
|
102
|
+
## Required Output
|
|
103
|
+
|
|
104
|
+
End your response with:
|
|
105
|
+
|
|
106
|
+
### Critical Files for Implementation
|
|
107
|
+
List 3-5 files most critical for implementing this plan:
|
|
108
|
+
- path/to/file1.ts - [Brief reason: e.g., "Core logic to modify"]
|
|
109
|
+
- path/to/file2.ts - [Brief reason: e.g., "Interfaces to implement"]
|
|
110
|
+
- path/to/file3.ts - [Brief reason: e.g., "Pattern to follow"]
|
|
111
|
+
|
|
112
|
+
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.`;
|
|
55
113
|
export const INIT_PROMPT = `Please analyze this codebase and create a AGENTS.md file, which will be given to future instances of Agent to operate in this repository.
|
|
56
114
|
|
|
57
115
|
What to add:
|
|
@@ -73,46 +131,64 @@ Usage notes:
|
|
|
73
131
|
|
|
74
132
|
This file provides guidance to Agent when working with code in this repository.
|
|
75
133
|
\`\`\``;
|
|
76
|
-
export
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
134
|
+
export const COMPRESS_MESSAGES_SYSTEM_PROMPT = `You have been working on the task described above but have not yet completed it. Write a continuation summary that will allow you (or another instance of yourself) to resume work efficiently in a future context window where the conversation history will be replaced with this summary. Your summary should be structured, concise, and actionable. Include:
|
|
135
|
+
1. Task Overview
|
|
136
|
+
The user's core request and success criteria
|
|
137
|
+
Any clarifications or constraints they specified
|
|
138
|
+
2. Current State
|
|
139
|
+
What has been completed so far
|
|
140
|
+
Files created, modified, or analyzed (with paths if relevant)
|
|
141
|
+
Key outputs or artifacts produced
|
|
142
|
+
3. Important Discoveries
|
|
143
|
+
Technical constraints or requirements uncovered
|
|
144
|
+
Decisions made and their rationale
|
|
145
|
+
Errors encountered and how they were resolved
|
|
146
|
+
What approaches were tried that didn't work (and why)
|
|
147
|
+
4. Next Steps
|
|
148
|
+
Specific actions needed to complete the task
|
|
149
|
+
Any blockers or open questions to resolve
|
|
150
|
+
Priority order if multiple steps remain
|
|
151
|
+
5. Context to Preserve
|
|
152
|
+
User preferences or style requirements
|
|
153
|
+
Domain-specific details that aren't obvious
|
|
154
|
+
Any promises made to the user
|
|
155
|
+
Be concise but complete—err on the side of including information that would prevent duplicate work or repeated mistakes. Write in a way that enables immediate resumption of the task.
|
|
156
|
+
Wrap your summary in <summary></summary> tags.`;
|
|
157
|
+
export function buildSystemPrompt(basePrompt, tools, options = {}) {
|
|
158
|
+
let prompt = basePrompt || DEFAULT_SYSTEM_PROMPT;
|
|
159
|
+
const toolNames = new Set(tools.map((t) => t.name));
|
|
160
|
+
if (toolNames.has(TASK_CREATE_TOOL_NAME) ||
|
|
161
|
+
toolNames.has(TASK_GET_TOOL_NAME) ||
|
|
162
|
+
toolNames.has(TASK_UPDATE_TOOL_NAME) ||
|
|
163
|
+
toolNames.has(TASK_LIST_TOOL_NAME)) {
|
|
80
164
|
prompt += TASK_MANAGEMENT_POLICY;
|
|
81
165
|
}
|
|
82
|
-
|
|
83
|
-
prompt
|
|
166
|
+
for (const tool of tools) {
|
|
167
|
+
if (tool.prompt) {
|
|
168
|
+
prompt += tool.prompt();
|
|
169
|
+
}
|
|
84
170
|
}
|
|
85
|
-
if (
|
|
86
|
-
prompt +=
|
|
171
|
+
if (options.language) {
|
|
172
|
+
prompt += `\n\n# Language\nAlways respond in ${options.language}. Technical terms (e.g., code, tool names, file paths) should remain in their original language or English where appropriate.`;
|
|
87
173
|
}
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
parts.push(WRITE_FILE_POLICY);
|
|
104
|
-
}
|
|
105
|
-
if (toolNames.has(LS_TOOL_NAME) ||
|
|
106
|
-
toolNames.has(GLOB_TOOL_NAME) ||
|
|
107
|
-
toolNames.has(GREP_TOOL_NAME)) {
|
|
108
|
-
parts.push(SEARCH_FILE_POLICY);
|
|
109
|
-
}
|
|
110
|
-
if (parts.length > 0) {
|
|
111
|
-
prompt += FILE_TOOL_POLICY_PREFIX + parts.join(",") + ".";
|
|
112
|
-
}
|
|
174
|
+
if (options.planMode) {
|
|
175
|
+
prompt += `\n\n${buildPlanModePrompt(options.planMode.planFilePath, options.planMode.planExists)}`;
|
|
176
|
+
}
|
|
177
|
+
if (options.workdir) {
|
|
178
|
+
prompt += `
|
|
179
|
+
|
|
180
|
+
Here is useful information about the environment you are running in:
|
|
181
|
+
<env>
|
|
182
|
+
Working directory: ${options.workdir}
|
|
183
|
+
Is directory a git repo: ${options.isGitRepo || "No"}
|
|
184
|
+
Platform: ${options.platform || ""}
|
|
185
|
+
OS Version: ${options.osVersion || ""}
|
|
186
|
+
Today's date: ${options.today || new Date().toISOString().split("T")[0]}
|
|
187
|
+
</env>
|
|
188
|
+
`;
|
|
113
189
|
}
|
|
114
|
-
if (
|
|
115
|
-
prompt +=
|
|
190
|
+
if (options.memory && options.memory.trim()) {
|
|
191
|
+
prompt += `\n## Memory Context\n\nThe following is important context and memory from previous interactions:\n\n${options.memory}`;
|
|
116
192
|
}
|
|
117
193
|
return prompt;
|
|
118
194
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const ASK_USER_QUESTION_TOOL_NAME = "AskUserQuestion";
|
|
2
2
|
export declare const BASH_TOOL_NAME = "Bash";
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
3
|
+
export declare const TASK_OUTPUT_TOOL_NAME = "TaskOutput";
|
|
4
|
+
export declare const TASK_STOP_TOOL_NAME = "TaskStop";
|
|
5
5
|
export declare const DELETE_FILE_TOOL_NAME = "Delete";
|
|
6
6
|
export declare const EDIT_TOOL_NAME = "Edit";
|
|
7
7
|
export declare const EXIT_PLAN_MODE_TOOL_NAME = "ExitPlanMode";
|
|
@@ -13,6 +13,9 @@ export declare const MULTI_EDIT_TOOL_NAME = "MultiEdit";
|
|
|
13
13
|
export declare const READ_TOOL_NAME = "Read";
|
|
14
14
|
export declare const SKILL_TOOL_NAME = "Skill";
|
|
15
15
|
export declare const TASK_TOOL_NAME = "Task";
|
|
16
|
-
export declare const
|
|
16
|
+
export declare const TASK_CREATE_TOOL_NAME = "TaskCreate";
|
|
17
|
+
export declare const TASK_GET_TOOL_NAME = "TaskGet";
|
|
18
|
+
export declare const TASK_UPDATE_TOOL_NAME = "TaskUpdate";
|
|
19
|
+
export declare const TASK_LIST_TOOL_NAME = "TaskList";
|
|
17
20
|
export declare const WRITE_TOOL_NAME = "Write";
|
|
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,CAAC;AAClD,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAC9C,eAAO,MAAM,qBAAqB,WAAW,CAAC;AAC9C,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,wBAAwB,iBAAiB,CAAC;AACvD,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,aAAa,QAAQ,CAAC;AACnC,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAChD,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,eAAe,UAAU,CAAC;AACvC,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,
|
|
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,CAAC;AAClD,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAC9C,eAAO,MAAM,qBAAqB,WAAW,CAAC;AAC9C,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,wBAAwB,iBAAiB,CAAC;AACvD,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,aAAa,QAAQ,CAAC;AACnC,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAChD,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,eAAe,UAAU,CAAC;AACvC,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAClD,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAC5C,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAClD,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAC9C,eAAO,MAAM,eAAe,UAAU,CAAC"}
|
package/dist/constants/tools.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const ASK_USER_QUESTION_TOOL_NAME = "AskUserQuestion";
|
|
2
2
|
export const BASH_TOOL_NAME = "Bash";
|
|
3
|
-
export const
|
|
4
|
-
export const
|
|
3
|
+
export const TASK_OUTPUT_TOOL_NAME = "TaskOutput";
|
|
4
|
+
export const TASK_STOP_TOOL_NAME = "TaskStop";
|
|
5
5
|
export const DELETE_FILE_TOOL_NAME = "Delete";
|
|
6
6
|
export const EDIT_TOOL_NAME = "Edit";
|
|
7
7
|
export const EXIT_PLAN_MODE_TOOL_NAME = "ExitPlanMode";
|
|
@@ -13,5 +13,8 @@ export const MULTI_EDIT_TOOL_NAME = "MultiEdit";
|
|
|
13
13
|
export const READ_TOOL_NAME = "Read";
|
|
14
14
|
export const SKILL_TOOL_NAME = "Skill";
|
|
15
15
|
export const TASK_TOOL_NAME = "Task";
|
|
16
|
-
export const
|
|
16
|
+
export const TASK_CREATE_TOOL_NAME = "TaskCreate";
|
|
17
|
+
export const TASK_GET_TOOL_NAME = "TaskGet";
|
|
18
|
+
export const TASK_UPDATE_TOOL_NAME = "TaskUpdate";
|
|
19
|
+
export const TASK_LIST_TOOL_NAME = "TaskList";
|
|
17
20
|
export const WRITE_TOOL_NAME = "Write";
|
package/dist/index.d.ts
CHANGED
|
@@ -21,5 +21,6 @@ export * from "./utils/promptHistory.js";
|
|
|
21
21
|
export * from "./utils/stringUtils.js";
|
|
22
22
|
export * from "./utils/customCommands.js";
|
|
23
23
|
export * from "./utils/hookMatcher.js";
|
|
24
|
+
export * from "./utils/tokenCalculation.js";
|
|
24
25
|
export * from "./types/index.js";
|
|
25
26
|
//# sourceMappingURL=index.d.ts.map
|
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,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AAGjD,cAAc,sBAAsB,CAAC;AAGrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AAGjD,cAAc,YAAY,CAAC;AAG3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,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;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AAGjD,cAAc,sBAAsB,CAAC;AAGrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AAGjD,cAAc,YAAY,CAAC;AAG3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,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;AAG5C,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -26,5 +26,6 @@ export * from "./utils/promptHistory.js";
|
|
|
26
26
|
export * from "./utils/stringUtils.js";
|
|
27
27
|
export * from "./utils/customCommands.js";
|
|
28
28
|
export * from "./utils/hookMatcher.js";
|
|
29
|
+
export * from "./utils/tokenCalculation.js";
|
|
29
30
|
// Export types
|
|
30
31
|
export * from "./types/index.js";
|
|
@@ -109,7 +109,7 @@ export class MemoryRuleManager {
|
|
|
109
109
|
getActiveRules(filesInContext) {
|
|
110
110
|
const activeRules = [];
|
|
111
111
|
for (const rule of Object.values(this.state.rules)) {
|
|
112
|
-
if (this.service.isRuleActive(rule, filesInContext)) {
|
|
112
|
+
if (this.service.isRuleActive(rule, filesInContext, this.workdir)) {
|
|
113
113
|
activeRules.push(rule);
|
|
114
114
|
}
|
|
115
115
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Logger, GatewayConfig, ModelConfig, Usage } from "../types/index.js";
|
|
2
2
|
import type { ToolManager } from "./toolManager.js";
|
|
3
3
|
import type { MessageManager } from "./messageManager.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { BackgroundTaskManager } from "./backgroundTaskManager.js";
|
|
5
5
|
import type { HookManager } from "./hookManager.js";
|
|
6
6
|
import type { PermissionManager } from "./permissionManager.js";
|
|
7
7
|
export interface AIManagerCallbacks {
|
|
@@ -11,8 +11,9 @@ export interface AIManagerCallbacks {
|
|
|
11
11
|
export interface AIManagerOptions {
|
|
12
12
|
messageManager: MessageManager;
|
|
13
13
|
toolManager: ToolManager;
|
|
14
|
+
taskManager: import("../services/taskManager.js").TaskManager;
|
|
14
15
|
logger?: Logger;
|
|
15
|
-
|
|
16
|
+
backgroundTaskManager?: BackgroundTaskManager;
|
|
16
17
|
hookManager?: HookManager;
|
|
17
18
|
permissionManager?: PermissionManager;
|
|
18
19
|
callbacks?: AIManagerCallbacks;
|
|
@@ -35,7 +36,8 @@ export declare class AIManager {
|
|
|
35
36
|
private logger?;
|
|
36
37
|
private toolManager;
|
|
37
38
|
private messageManager;
|
|
38
|
-
private
|
|
39
|
+
private taskManager;
|
|
40
|
+
private backgroundTaskManager?;
|
|
39
41
|
private hookManager?;
|
|
40
42
|
private reversionManager?;
|
|
41
43
|
private permissionManager?;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiManager.d.ts","sourceRoot":"","sources":["../../src/managers/aiManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aiManager.d.ts","sourceRoot":"","sources":["../../src/managers/aiManager.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,MAAM,EACN,aAAa,EACb,WAAW,EACX,KAAK,EACN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAoBhE,MAAM,WAAW,kBAAkB;IACjC,wBAAwB,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,KAAK,IAAI,CAAC;IAC5D,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACvC;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,cAAc,CAAC;IAC/B,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,OAAO,4BAA4B,EAAE,WAAW,CAAC;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAC9C,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,uBAAuB,EAAE,gBAAgB,CAAC;IACpE,uEAAuE;IACvE,MAAM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vB,YAAY,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI;IAItC,cAAc,IAAI,IAAI;IAuB7B,OAAO,CAAC,qBAAqB;YAsBf,8BAA8B;IA6ErC,gBAAgB,IAAI,OAAO;IAI3B,gBAAgB,CAAC,aAAa,EAAE,OAAO,GAAG,IAAI;IAOxC,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,iEAAiE;QACjE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;KACf,GACL,OAAO,CAAC,IAAI,CAAC;IA4fhB;;;;OAIG;YACW,gBAAgB;IAiE9B;;;OAGG;YACW,sBAAsB;IA6DpC;;OAEG;YACW,uBAAuB;CAwDtC"}
|
|
@@ -1,10 +1,28 @@
|
|
|
1
|
+
import * as os from "node:os";
|
|
2
|
+
import * as path from "node:path";
|
|
1
3
|
import { callAgent, compressMessages, } from "../services/aiService.js";
|
|
2
|
-
import { getMessagesToCompress } from "../utils/messageOperations.js";
|
|
3
4
|
import { convertMessagesForAPI } from "../utils/convertMessagesForAPI.js";
|
|
4
5
|
import { calculateComprehensiveTotalTokens } from "../utils/tokenCalculation.js";
|
|
5
|
-
import * as
|
|
6
|
+
import * as fsSync from "node:fs";
|
|
6
7
|
import * as fs from "node:fs/promises";
|
|
7
|
-
import {
|
|
8
|
+
import { buildSystemPrompt } from "../constants/prompts.js";
|
|
9
|
+
function isGitRepository(dirPath) {
|
|
10
|
+
try {
|
|
11
|
+
// Check if .git directory exists in current directory or any parent directory
|
|
12
|
+
let currentPath = path.resolve(dirPath);
|
|
13
|
+
while (currentPath !== path.dirname(currentPath)) {
|
|
14
|
+
const gitPath = path.join(currentPath, ".git");
|
|
15
|
+
if (fsSync.existsSync(gitPath)) {
|
|
16
|
+
return "Yes";
|
|
17
|
+
}
|
|
18
|
+
currentPath = path.dirname(currentPath);
|
|
19
|
+
}
|
|
20
|
+
return "No";
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return "No";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
8
26
|
export class AIManager {
|
|
9
27
|
constructor(options) {
|
|
10
28
|
this.isLoading = false;
|
|
@@ -13,7 +31,8 @@ export class AIManager {
|
|
|
13
31
|
this.isCompressing = false;
|
|
14
32
|
this.messageManager = options.messageManager;
|
|
15
33
|
this.toolManager = options.toolManager;
|
|
16
|
-
this.
|
|
34
|
+
this.taskManager = options.taskManager;
|
|
35
|
+
this.backgroundTaskManager = options.backgroundTaskManager;
|
|
17
36
|
this.hookManager = options.hookManager;
|
|
18
37
|
this.reversionManager = options.reversionManager;
|
|
19
38
|
this.permissionManager = options.permissionManager;
|
|
@@ -88,6 +107,7 @@ export class AIManager {
|
|
|
88
107
|
if (toolPlugin?.formatCompactParams) {
|
|
89
108
|
const context = {
|
|
90
109
|
workdir: this.workdir,
|
|
110
|
+
taskManager: this.taskManager,
|
|
91
111
|
};
|
|
92
112
|
return toolPlugin.formatCompactParams(toolArgs, context);
|
|
93
113
|
}
|
|
@@ -111,7 +131,7 @@ export class AIManager {
|
|
|
111
131
|
this.getMaxInputTokens()) {
|
|
112
132
|
this.logger?.debug(`Token usage exceeded ${this.getMaxInputTokens()}, compressing messages...`);
|
|
113
133
|
// Check if messages need compression
|
|
114
|
-
const
|
|
134
|
+
const messagesToCompress = this.messageManager.getMessages();
|
|
115
135
|
// If there are messages to compress, perform compression
|
|
116
136
|
if (messagesToCompress.length > 0) {
|
|
117
137
|
const recentChatMessages = convertMessagesForAPI(messagesToCompress);
|
|
@@ -138,7 +158,7 @@ export class AIManager {
|
|
|
138
158
|
};
|
|
139
159
|
}
|
|
140
160
|
// Execute message reconstruction and sessionId update after compression
|
|
141
|
-
this.messageManager.compressMessagesAndUpdateSession(
|
|
161
|
+
this.messageManager.compressMessagesAndUpdateSession(compressionResult.content, compressionUsage);
|
|
142
162
|
// Notify Agent to add to usage tracking
|
|
143
163
|
if (compressionUsage && this.callbacks?.onUsageAdded) {
|
|
144
164
|
this.callbacks.onUsageAdded(compressionUsage);
|
|
@@ -198,20 +218,18 @@ export class AIManager {
|
|
|
198
218
|
const recentMessages = convertMessagesForAPI(this.messageManager.getMessages());
|
|
199
219
|
try {
|
|
200
220
|
// Get combined memory content
|
|
201
|
-
const combinedMemory = await
|
|
221
|
+
const combinedMemory = await this.messageManager.getCombinedMemory();
|
|
202
222
|
// Track if assistant message has been created
|
|
203
223
|
let assistantMessageCreated = false;
|
|
204
224
|
this.logger?.debug("modelConfig in sendAIMessage", this.getModelConfig());
|
|
205
225
|
// Get current permission mode and plan file path
|
|
206
226
|
const currentMode = this.permissionManager?.getCurrentEffectiveMode(this.getModelConfig().permissionMode);
|
|
207
227
|
const toolsConfig = this.getFilteredToolsConfig(tools);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
effectiveSystemPrompt = (effectiveSystemPrompt || "") + languagePrompt;
|
|
214
|
-
}
|
|
228
|
+
const toolNames = new Set(toolsConfig.map((t) => t.function.name));
|
|
229
|
+
const filteredToolPlugins = this.toolManager
|
|
230
|
+
.getTools()
|
|
231
|
+
.filter((t) => toolNames.has(t.name));
|
|
232
|
+
let planModeOptions;
|
|
215
233
|
if (currentMode === "plan") {
|
|
216
234
|
const planFilePath = this.permissionManager?.getPlanFilePath();
|
|
217
235
|
if (planFilePath) {
|
|
@@ -223,8 +241,7 @@ export class AIManager {
|
|
|
223
241
|
catch {
|
|
224
242
|
planExists = false;
|
|
225
243
|
}
|
|
226
|
-
|
|
227
|
-
effectiveSystemPrompt = (effectiveSystemPrompt || "") + reminder;
|
|
244
|
+
planModeOptions = { planFilePath, planExists };
|
|
228
245
|
}
|
|
229
246
|
}
|
|
230
247
|
// Call AI service with streaming callbacks if enabled
|
|
@@ -234,11 +251,19 @@ export class AIManager {
|
|
|
234
251
|
messages: recentMessages,
|
|
235
252
|
sessionId: this.messageManager.getSessionId(),
|
|
236
253
|
abortSignal: abortController.signal,
|
|
237
|
-
memory: combinedMemory, // Pass combined memory content
|
|
238
254
|
workdir: this.workdir, // Pass working directory
|
|
239
255
|
tools: toolsConfig, // Pass filtered tool configuration
|
|
240
256
|
model: model, // Use passed model
|
|
241
|
-
systemPrompt:
|
|
257
|
+
systemPrompt: buildSystemPrompt(this.systemPrompt, filteredToolPlugins, {
|
|
258
|
+
workdir: this.workdir,
|
|
259
|
+
isGitRepo: isGitRepository(this.workdir),
|
|
260
|
+
platform: os.platform(),
|
|
261
|
+
osVersion: `${os.type()} ${os.release()}`,
|
|
262
|
+
today: new Date().toISOString().split("T")[0],
|
|
263
|
+
memory: combinedMemory,
|
|
264
|
+
language: this.getLanguage(),
|
|
265
|
+
planMode: planModeOptions,
|
|
266
|
+
}), // Pass custom system prompt
|
|
242
267
|
maxTokens: maxTokens, // Pass max tokens override
|
|
243
268
|
};
|
|
244
269
|
// Add streaming callbacks only if streaming is enabled
|
|
@@ -420,9 +445,11 @@ export class AIManager {
|
|
|
420
445
|
// Create tool execution context
|
|
421
446
|
const context = {
|
|
422
447
|
abortSignal: toolAbortController.signal,
|
|
423
|
-
|
|
448
|
+
backgroundTaskManager: this.backgroundTaskManager,
|
|
424
449
|
workdir: this.workdir,
|
|
425
450
|
messageId: this.messageManager.getMessages().slice(-1)[0]?.id,
|
|
451
|
+
sessionId: this.messageManager.getSessionId(),
|
|
452
|
+
taskManager: this.taskManager,
|
|
426
453
|
};
|
|
427
454
|
// Execute tool
|
|
428
455
|
const toolResult = await this.toolManager.execute(functionToolCall.function?.name || "", toolArgs, context);
|
|
@@ -437,6 +464,7 @@ export class AIManager {
|
|
|
437
464
|
stage: "end",
|
|
438
465
|
name: toolName,
|
|
439
466
|
shortResult: toolResult.shortResult,
|
|
467
|
+
isManuallyBackgrounded: toolResult.isManuallyBackgrounded,
|
|
440
468
|
});
|
|
441
469
|
// Execute PostToolUse hooks after successful tool completion
|
|
442
470
|
await this.executePostToolUseHooks(toolId, toolName, toolArgs, toolResult);
|
|
@@ -454,6 +482,7 @@ export class AIManager {
|
|
|
454
482
|
stage: "end",
|
|
455
483
|
name: toolName,
|
|
456
484
|
compactParams,
|
|
485
|
+
isManuallyBackgrounded: false,
|
|
457
486
|
});
|
|
458
487
|
}
|
|
459
488
|
});
|
|
@@ -473,7 +502,15 @@ export class AIManager {
|
|
|
473
502
|
}
|
|
474
503
|
// Check interruption status
|
|
475
504
|
const isCurrentlyAborted = abortController.signal.aborted || toolAbortController.signal.aborted;
|
|
476
|
-
if
|
|
505
|
+
// Check if all tools were manually backgrounded
|
|
506
|
+
const lastMessage = this.messageManager.getMessages()[this.messageManager.getMessages().length - 1];
|
|
507
|
+
const toolBlocks = lastMessage?.blocks.filter((block) => block.type === "tool") || [];
|
|
508
|
+
const hasBackgrounded = toolBlocks.length > 0 &&
|
|
509
|
+
toolBlocks.some((block) => block.isManuallyBackgrounded);
|
|
510
|
+
if (hasBackgrounded) {
|
|
511
|
+
this.logger?.info("Some tools were manually backgrounded, stopping recursion.");
|
|
512
|
+
}
|
|
513
|
+
else if (!isCurrentlyAborted) {
|
|
477
514
|
// Recursively call AI service, increment recursion depth, and pass same configuration
|
|
478
515
|
await this.sendAIMessage({
|
|
479
516
|
recursionDepth: recursionDepth + 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backgroundBashManager.d.ts","sourceRoot":"","sources":["../../src/managers/backgroundBashManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,WAAW,8BAA8B;IAC7C,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;CACtD;AAED,MAAM,WAAW,4BAA4B;IAC3C,SAAS,CAAC,EAAE,8BAA8B,CAAC;IAC3C,OAAO,EAAE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E,EAAE,MAAM,GAAG,OAAO;IAmD9B,OAAO,IAAI,IAAI;CAUvB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type ChildProcess } from "child_process";
|
|
2
|
+
import { BackgroundTask } from "../types/processes.js";
|
|
3
|
+
export interface BackgroundTaskManagerCallbacks {
|
|
4
|
+
onTasksChange?: (tasks: BackgroundTask[]) => void;
|
|
5
|
+
}
|
|
6
|
+
export interface BackgroundTaskManagerOptions {
|
|
7
|
+
callbacks?: BackgroundTaskManagerCallbacks;
|
|
8
|
+
workdir: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class BackgroundTaskManager {
|
|
11
|
+
private tasks;
|
|
12
|
+
private nextId;
|
|
13
|
+
private callbacks;
|
|
14
|
+
private workdir;
|
|
15
|
+
constructor(options: BackgroundTaskManagerOptions);
|
|
16
|
+
private notifyTasksChange;
|
|
17
|
+
generateId(): string;
|
|
18
|
+
addTask(task: BackgroundTask): void;
|
|
19
|
+
getTask(id: string): BackgroundTask | undefined;
|
|
20
|
+
getAllTasks(): BackgroundTask[];
|
|
21
|
+
startShell(command: string, timeout?: number): {
|
|
22
|
+
id: string;
|
|
23
|
+
child: ChildProcess;
|
|
24
|
+
detach: () => void;
|
|
25
|
+
};
|
|
26
|
+
adoptProcess(child: ChildProcess, command: string, initialStdout?: string, initialStderr?: string): string;
|
|
27
|
+
getOutput(id: string, filter?: string): {
|
|
28
|
+
stdout: string;
|
|
29
|
+
stderr: string;
|
|
30
|
+
status: string;
|
|
31
|
+
} | null;
|
|
32
|
+
stopTask(id: string): boolean;
|
|
33
|
+
cleanup(): void;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=backgroundTaskManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backgroundTaskManager.d.ts","sourceRoot":"","sources":["../../src/managers/backgroundTaskManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;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