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.
Files changed (190) hide show
  1. package/dist/agent.d.ts +42 -11
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +114 -115
  4. package/dist/constants/prompts.d.ts +18 -14
  5. package/dist/constants/prompts.d.ts.map +1 -1
  6. package/dist/constants/prompts.js +130 -54
  7. package/dist/constants/tools.d.ts +6 -3
  8. package/dist/constants/tools.d.ts.map +1 -1
  9. package/dist/constants/tools.js +6 -3
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +1 -0
  13. package/dist/managers/MemoryRuleManager.js +1 -1
  14. package/dist/managers/aiManager.d.ts +5 -3
  15. package/dist/managers/aiManager.d.ts.map +1 -1
  16. package/dist/managers/aiManager.js +57 -20
  17. package/dist/managers/backgroundBashManager.d.ts.map +1 -1
  18. package/dist/managers/backgroundBashManager.js +1 -0
  19. package/dist/managers/backgroundTaskManager.d.ts +35 -0
  20. package/dist/managers/backgroundTaskManager.d.ts.map +1 -0
  21. package/dist/managers/backgroundTaskManager.js +255 -0
  22. package/dist/managers/foregroundTaskManager.d.ts +9 -0
  23. package/dist/managers/foregroundTaskManager.d.ts.map +1 -0
  24. package/dist/managers/foregroundTaskManager.js +21 -0
  25. package/dist/managers/liveConfigManager.d.ts +1 -1
  26. package/dist/managers/lspManager.d.ts.map +1 -1
  27. package/dist/managers/lspManager.js +3 -1
  28. package/dist/managers/mcpManager.d.ts.map +1 -1
  29. package/dist/managers/messageManager.d.ts +26 -12
  30. package/dist/managers/messageManager.d.ts.map +1 -1
  31. package/dist/managers/messageManager.js +138 -64
  32. package/dist/managers/permissionManager.d.ts.map +1 -1
  33. package/dist/managers/permissionManager.js +26 -22
  34. package/dist/managers/planManager.d.ts +1 -1
  35. package/dist/managers/planManager.d.ts.map +1 -1
  36. package/dist/managers/planManager.js +2 -2
  37. package/dist/managers/pluginManager.d.ts.map +1 -1
  38. package/dist/managers/pluginManager.js +3 -2
  39. package/dist/managers/slashCommandManager.d.ts +6 -0
  40. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  41. package/dist/managers/slashCommandManager.js +8 -2
  42. package/dist/managers/subagentManager.d.ts +15 -2
  43. package/dist/managers/subagentManager.d.ts.map +1 -1
  44. package/dist/managers/subagentManager.js +153 -39
  45. package/dist/managers/toolManager.d.ts +18 -1
  46. package/dist/managers/toolManager.d.ts.map +1 -1
  47. package/dist/managers/toolManager.js +29 -5
  48. package/dist/services/GitService.d.ts.map +1 -1
  49. package/dist/services/GitService.js +6 -2
  50. package/dist/services/MarketplaceService.d.ts +2 -2
  51. package/dist/services/MarketplaceService.d.ts.map +1 -1
  52. package/dist/services/MarketplaceService.js +18 -11
  53. package/dist/services/MemoryRuleService.d.ts +1 -1
  54. package/dist/services/MemoryRuleService.d.ts.map +1 -1
  55. package/dist/services/MemoryRuleService.js +13 -2
  56. package/dist/services/aiService.d.ts +0 -1
  57. package/dist/services/aiService.d.ts.map +1 -1
  58. package/dist/services/aiService.js +4 -140
  59. package/dist/services/memory.d.ts +0 -3
  60. package/dist/services/memory.d.ts.map +1 -1
  61. package/dist/services/memory.js +1 -60
  62. package/dist/services/session.d.ts +15 -1
  63. package/dist/services/session.d.ts.map +1 -1
  64. package/dist/services/session.js +57 -1
  65. package/dist/services/taskManager.d.ts +21 -0
  66. package/dist/services/taskManager.d.ts.map +1 -0
  67. package/dist/services/taskManager.js +158 -0
  68. package/dist/tools/askUserQuestion.d.ts.map +1 -1
  69. package/dist/tools/askUserQuestion.js +39 -25
  70. package/dist/tools/bashTool.d.ts +0 -8
  71. package/dist/tools/bashTool.d.ts.map +1 -1
  72. package/dist/tools/bashTool.js +48 -172
  73. package/dist/tools/editTool.d.ts.map +1 -1
  74. package/dist/tools/editTool.js +8 -6
  75. package/dist/tools/exitPlanMode.d.ts.map +1 -1
  76. package/dist/tools/exitPlanMode.js +25 -1
  77. package/dist/tools/globTool.d.ts.map +1 -1
  78. package/dist/tools/globTool.js +8 -2
  79. package/dist/tools/grepTool.d.ts.map +1 -1
  80. package/dist/tools/grepTool.js +17 -6
  81. package/dist/tools/lsTool.d.ts.map +1 -1
  82. package/dist/tools/lsTool.js +3 -1
  83. package/dist/tools/multiEditTool.d.ts.map +1 -1
  84. package/dist/tools/multiEditTool.js +7 -6
  85. package/dist/tools/readTool.d.ts.map +1 -1
  86. package/dist/tools/readTool.js +16 -1
  87. package/dist/tools/taskManagementTools.d.ts +6 -0
  88. package/dist/tools/taskManagementTools.d.ts.map +1 -0
  89. package/dist/tools/taskManagementTools.js +453 -0
  90. package/dist/tools/taskOutputTool.d.ts +3 -0
  91. package/dist/tools/taskOutputTool.d.ts.map +1 -0
  92. package/dist/tools/taskOutputTool.js +173 -0
  93. package/dist/tools/taskStopTool.d.ts +3 -0
  94. package/dist/tools/taskStopTool.d.ts.map +1 -0
  95. package/dist/tools/taskStopTool.js +71 -0
  96. package/dist/tools/taskTool.d.ts.map +1 -1
  97. package/dist/tools/taskTool.js +110 -63
  98. package/dist/tools/types.d.ts +12 -0
  99. package/dist/tools/types.d.ts.map +1 -1
  100. package/dist/tools/writeTool.d.ts.map +1 -1
  101. package/dist/tools/writeTool.js +9 -1
  102. package/dist/types/index.d.ts +1 -0
  103. package/dist/types/index.d.ts.map +1 -1
  104. package/dist/types/index.js +1 -0
  105. package/dist/types/marketplace.d.ts +1 -0
  106. package/dist/types/marketplace.d.ts.map +1 -1
  107. package/dist/types/messaging.d.ts +3 -8
  108. package/dist/types/messaging.d.ts.map +1 -1
  109. package/dist/types/processes.d.ts +29 -4
  110. package/dist/types/processes.d.ts.map +1 -1
  111. package/dist/types/tasks.d.ts +13 -0
  112. package/dist/types/tasks.d.ts.map +1 -0
  113. package/dist/types/tasks.js +1 -0
  114. package/dist/types/tools.d.ts +4 -1
  115. package/dist/types/tools.d.ts.map +1 -1
  116. package/dist/utils/builtinSubagents.d.ts.map +1 -1
  117. package/dist/utils/builtinSubagents.js +38 -1
  118. package/dist/utils/cacheControlUtils.d.ts.map +1 -1
  119. package/dist/utils/cacheControlUtils.js +18 -12
  120. package/dist/utils/constants.d.ts +0 -4
  121. package/dist/utils/constants.d.ts.map +1 -1
  122. package/dist/utils/constants.js +0 -4
  123. package/dist/utils/convertMessagesForAPI.js +2 -2
  124. package/dist/utils/editUtils.d.ts +2 -11
  125. package/dist/utils/editUtils.d.ts.map +1 -1
  126. package/dist/utils/editUtils.js +52 -79
  127. package/dist/utils/messageOperations.d.ts +5 -36
  128. package/dist/utils/messageOperations.d.ts.map +1 -1
  129. package/dist/utils/messageOperations.js +9 -98
  130. package/dist/utils/nameGenerator.d.ts +1 -1
  131. package/dist/utils/nameGenerator.d.ts.map +1 -1
  132. package/dist/utils/nameGenerator.js +19 -3
  133. package/package.json +5 -5
  134. package/src/agent.ts +157 -134
  135. package/src/constants/prompts.ts +156 -65
  136. package/src/constants/tools.ts +6 -3
  137. package/src/index.ts +1 -0
  138. package/src/managers/MemoryRuleManager.ts +1 -1
  139. package/src/managers/aiManager.ts +77 -35
  140. package/src/managers/backgroundBashManager.ts +1 -0
  141. package/src/managers/backgroundTaskManager.ts +305 -0
  142. package/src/managers/foregroundTaskManager.ts +27 -0
  143. package/src/managers/lspManager.ts +3 -1
  144. package/src/managers/mcpManager.ts +6 -3
  145. package/src/managers/messageManager.ts +185 -75
  146. package/src/managers/permissionManager.ts +33 -28
  147. package/src/managers/planManager.ts +2 -2
  148. package/src/managers/pluginManager.ts +4 -3
  149. package/src/managers/slashCommandManager.ts +15 -2
  150. package/src/managers/subagentManager.ts +194 -35
  151. package/src/managers/toolManager.ts +48 -6
  152. package/src/services/GitService.ts +6 -2
  153. package/src/services/MarketplaceService.ts +30 -12
  154. package/src/services/MemoryRuleService.ts +18 -6
  155. package/src/services/aiService.ts +3 -145
  156. package/src/services/memory.ts +1 -73
  157. package/src/services/session.ts +73 -0
  158. package/src/services/taskManager.ts +188 -0
  159. package/src/tools/askUserQuestion.ts +51 -29
  160. package/src/tools/bashTool.ts +63 -196
  161. package/src/tools/editTool.ts +9 -18
  162. package/src/tools/exitPlanMode.ts +26 -2
  163. package/src/tools/globTool.ts +10 -2
  164. package/src/tools/grepTool.ts +17 -6
  165. package/src/tools/lsTool.ts +3 -1
  166. package/src/tools/multiEditTool.ts +7 -18
  167. package/src/tools/readTool.ts +17 -1
  168. package/src/tools/taskManagementTools.ts +498 -0
  169. package/src/tools/taskOutputTool.ts +196 -0
  170. package/src/tools/taskStopTool.ts +78 -0
  171. package/src/tools/taskTool.ts +136 -74
  172. package/src/tools/types.ts +13 -0
  173. package/src/tools/writeTool.ts +9 -2
  174. package/src/types/index.ts +1 -0
  175. package/src/types/marketplace.ts +1 -0
  176. package/src/types/messaging.ts +2 -9
  177. package/src/types/processes.ts +39 -4
  178. package/src/types/tasks.ts +13 -0
  179. package/src/types/tools.ts +4 -1
  180. package/src/utils/builtinSubagents.ts +47 -1
  181. package/src/utils/cacheControlUtils.ts +26 -18
  182. package/src/utils/constants.ts +0 -5
  183. package/src/utils/convertMessagesForAPI.ts +2 -2
  184. package/src/utils/editUtils.ts +65 -103
  185. package/src/utils/messageOperations.ts +12 -136
  186. package/src/utils/nameGenerator.ts +20 -3
  187. package/dist/tools/todoWriteTool.d.ts +0 -6
  188. package/dist/tools/todoWriteTool.d.ts.map +0 -1
  189. package/dist/tools/todoWriteTool.js +0 -220
  190. 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, LS_TOOL_NAME, MULTI_EDIT_TOOL_NAME, READ_TOOL_NAME, TASK_TOOL_NAME, TODO_WRITE_TOOL_NAME, WRITE_TOOL_NAME, } from "./tools.js";
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 ${TODO_WRITE_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.
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 todos as completed as soon as you are done with a task. Do not batch up multiple tasks before marking them as completed.`;
23
- export const ASK_USER_POLICY = `
24
- # Asking questions as you work
25
- You have access to the ${ASK_USER_QUESTION_TOOL_NAME} tool to ask the user questions when you need clarification, want to validate assumptions, or need to make a decision you're unsure about. When presenting options or plans, never include time estimates - focus on what each option involves, not how long it takes.`;
26
- export const SUBAGENT_POLICY = `
27
- - When doing file search, prefer to use the ${TASK_TOOL_NAME} tool in order to reduce context usage.
28
- - You should proactively use the ${TASK_TOOL_NAME} tool with specialized agents when the task at hand matches the agent's description.
29
- - VERY IMPORTANT: When exploring the codebase to gather context or to answer a question that is not a needle query for a specific file/class/function, it is CRITICAL that you use the ${TASK_TOOL_NAME} tool with subagent_type=Explore instead of running search commands directly.`;
30
- export const FILE_TOOL_POLICY_PREFIX = `\n- Use specialized tools instead of bash commands when possible, as this provides a better user experience. For file operations, use dedicated tools:`;
31
- export const READ_FILE_POLICY = ` ${READ_TOOL_NAME} for reading files instead of cat/head/tail`;
32
- export const EDIT_FILE_POLICY = ` ${EDIT_TOOL_NAME}/${MULTI_EDIT_TOOL_NAME} for editing instead of sed/awk`;
33
- export const WRITE_FILE_POLICY = ` ${WRITE_TOOL_NAME} for creating files instead of cat with heredoc or echo redirection`;
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 Grep or Glob when you need to search broadly. Use Read when you know the specific file path.
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 function buildSystemPrompt(basePrompt, tools) {
77
- let prompt = basePrompt;
78
- const toolNames = new Set(tools.map((t) => t.function?.name || t.name).filter(Boolean));
79
- if (toolNames.has(TODO_WRITE_TOOL_NAME)) {
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
- if (toolNames.has(ASK_USER_QUESTION_TOOL_NAME)) {
83
- prompt += ASK_USER_POLICY;
166
+ for (const tool of tools) {
167
+ if (tool.prompt) {
168
+ prompt += tool.prompt();
169
+ }
84
170
  }
85
- if (toolNames.has(TASK_TOOL_NAME)) {
86
- prompt += SUBAGENT_POLICY;
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 (toolNames.has(READ_TOOL_NAME) ||
89
- toolNames.has(EDIT_TOOL_NAME) ||
90
- toolNames.has(MULTI_EDIT_TOOL_NAME) ||
91
- toolNames.has(WRITE_TOOL_NAME) ||
92
- toolNames.has(LS_TOOL_NAME) ||
93
- toolNames.has(GLOB_TOOL_NAME) ||
94
- toolNames.has(GREP_TOOL_NAME)) {
95
- const parts = [];
96
- if (toolNames.has(READ_TOOL_NAME)) {
97
- parts.push(READ_FILE_POLICY);
98
- }
99
- if (toolNames.has(EDIT_TOOL_NAME) || toolNames.has(MULTI_EDIT_TOOL_NAME)) {
100
- parts.push(EDIT_FILE_POLICY);
101
- }
102
- if (toolNames.has(WRITE_TOOL_NAME)) {
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 (toolNames.has(BASH_TOOL_NAME)) {
115
- prompt += BASH_POLICY;
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 BASH_OUTPUT_TOOL_NAME = "BashOutput";
4
- export declare const KILL_BASH_TOOL_NAME = "KillBash";
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 TODO_WRITE_TOOL_NAME = "TodoWrite";
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,CA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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"}
@@ -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 BASH_OUTPUT_TOOL_NAME = "BashOutput";
4
- export const KILL_BASH_TOOL_NAME = "KillBash";
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 TODO_WRITE_TOOL_NAME = "TodoWrite";
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,yBAAyB,CAAC;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BAAwB,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 { BackgroundBashManager } from "./backgroundBashManager.js";
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
- backgroundBashManager?: BackgroundBashManager;
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 backgroundBashManager?;
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":"AAUA,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;AAMhE,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,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,CAAC,EAAE,OAAO,CAAC;IAEjB,gBAAgB,EAAE,MAAM,aAAa,CAA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B,CAAsB;IAChD,OAAO,CAAC,gBAAgB,CAAoB;IAC5C,OAAO,CAAC,mBAAmB,CAAe;IAC1C,OAAO,CAAC,aAAa,CAA2B;IAChD,OAAO,CAAC,oBAAoB,CAAC,CAA+B;gBAEhD,OAAO,EAAE,gBAAgB;IAwB9B,gBAAgB,IAAI,aAAa;IAIjC,cAAc,IAAI,WAAW;IAI7B,iBAAiB,IAAI,MAAM;IAI3B,WAAW,IAAI,MAAM,GAAG,SAAS;IAIxC,OAAO,CAAC,aAAa,CAAkB;IACvC,OAAO,CAAC,SAAS,CAAqB;IAEtC;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAYvB,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 memory from "../services/memory.js";
6
+ import * as fsSync from "node:fs";
6
7
  import * as fs from "node:fs/promises";
7
- import { DEFAULT_SYSTEM_PROMPT, buildSystemPrompt, } from "../constants/prompts.js";
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.backgroundBashManager = options.backgroundBashManager;
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 { messagesToCompress, insertIndex } = getMessagesToCompress(this.messageManager.getMessages());
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(insertIndex, compressionResult.content, compressionUsage);
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 memory.getCombinedMemoryContent(this.workdir);
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
- let effectiveSystemPrompt = buildSystemPrompt(this.systemPrompt || DEFAULT_SYSTEM_PROMPT, toolsConfig);
209
- // Inject language prompt if configured
210
- const language = this.getLanguage();
211
- if (language) {
212
- const languagePrompt = `\n\n# Language\nAlways respond in ${language}. Technical terms (e.g., code, tool names, file paths) should remain in their original language or English where appropriate.`;
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
- const reminder = `\n\nPlan mode is active. The user indicated that they do not want you to execute yet -- you MUST NOT make any edits (with the exception of the plan file mentioned below), 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.\n\n## Plan File Info:\n${planExists ? `A plan file already exists at ${planFilePath}. You can read it and make incremental edits using the Edit tool if you need to.` : `No plan file exists yet. You should create your plan at ${planFilePath} using the Write tool if you need to.`}\nYou 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. You may also use the AskUserQuestion tool to gather requirements or clarify intent before finalizing your plan.`;
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: effectiveSystemPrompt, // Pass custom system prompt
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
- backgroundBashManager: this.backgroundBashManager,
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 (!isCurrentlyAborted) {
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,E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AAC,kBAAkB;IAInB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;IAuErD,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAIjD,YAAY,IAAI,eAAe,EAAE;IAIjC,SAAS,CACd,EAAE,EAAE,MAAM,EACV,MAAM,CAAC,EAAE,MAAM,GACd;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAiCrD,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAmD9B,OAAO,IAAI,IAAI;CAUvB"}
@@ -24,6 +24,7 @@ export class BackgroundBashManager {
24
24
  });
25
25
  const shell = {
26
26
  id,
27
+ type: "shell",
27
28
  process: child,
28
29
  command,
29
30
  startTime,
@@ -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;AACzD,OAAO,EAAE,cAAc,EAAmB,MAAM,uBAAuB,CAAC;AAIxE,MAAM,WAAW,8BAA8B;IAC7C,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,IAAI,CAAC;CACnD;AAED,MAAM,WAAW,4BAA4B;IAC3C,SAAS,CAAC,EAAE,8BAA8B,CAAC;IAC3C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,qBAAqB;IAChC,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,SAAS,CAAiC;IAClD,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,4BAA4B;IAKjD,OAAO,CAAC,iBAAiB;IAIlB,UAAU,IAAI,MAAM;IAIpB,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IAKnC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAI/C,WAAW,IAAI,cAAc,EAAE;IAI/B,UAAU,CACf,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,GACf;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,YAAY,CAAC;QAAC,MAAM,EAAE,MAAM,IAAI,CAAA;KAAE;IA8GnD,YAAY,CACjB,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,MAAM,EACf,aAAa,GAAE,MAAW,EAC1B,aAAa,GAAE,MAAW,GACzB,MAAM;IAoEF,SAAS,CACd,EAAE,EAAE,MAAM,EACV,MAAM,CAAC,EAAE,MAAM,GACd;QAAE,MAAM,E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