wave-agent-sdk 0.5.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 (152) hide show
  1. package/dist/agent.d.ts +14 -6
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +65 -88
  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 +4 -1
  8. package/dist/constants/tools.d.ts.map +1 -1
  9. package/dist/constants/tools.js +4 -1
  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/aiManager.d.ts +2 -5
  14. package/dist/managers/aiManager.d.ts.map +1 -1
  15. package/dist/managers/aiManager.js +59 -48
  16. package/dist/managers/backgroundTaskManager.d.ts.map +1 -1
  17. package/dist/managers/backgroundTaskManager.js +59 -53
  18. package/dist/managers/foregroundTaskManager.d.ts.map +1 -1
  19. package/dist/managers/foregroundTaskManager.js +3 -2
  20. package/dist/managers/mcpManager.d.ts.map +1 -1
  21. package/dist/managers/messageManager.d.ts +14 -10
  22. package/dist/managers/messageManager.d.ts.map +1 -1
  23. package/dist/managers/messageManager.js +102 -62
  24. package/dist/managers/permissionManager.d.ts.map +1 -1
  25. package/dist/managers/permissionManager.js +25 -15
  26. package/dist/managers/planManager.d.ts +1 -1
  27. package/dist/managers/planManager.d.ts.map +1 -1
  28. package/dist/managers/planManager.js +2 -2
  29. package/dist/managers/slashCommandManager.d.ts +3 -0
  30. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  31. package/dist/managers/slashCommandManager.js +7 -2
  32. package/dist/managers/subagentManager.d.ts +4 -0
  33. package/dist/managers/subagentManager.d.ts.map +1 -1
  34. package/dist/managers/subagentManager.js +22 -14
  35. package/dist/managers/toolManager.d.ts +11 -0
  36. package/dist/managers/toolManager.d.ts.map +1 -1
  37. package/dist/managers/toolManager.js +20 -2
  38. package/dist/services/aiService.d.ts +0 -1
  39. package/dist/services/aiService.d.ts.map +1 -1
  40. package/dist/services/aiService.js +4 -140
  41. package/dist/services/memory.d.ts +0 -3
  42. package/dist/services/memory.d.ts.map +1 -1
  43. package/dist/services/memory.js +0 -59
  44. package/dist/services/session.d.ts +15 -1
  45. package/dist/services/session.d.ts.map +1 -1
  46. package/dist/services/session.js +57 -1
  47. package/dist/services/taskManager.d.ts +21 -0
  48. package/dist/services/taskManager.d.ts.map +1 -0
  49. package/dist/services/taskManager.js +158 -0
  50. package/dist/tools/askUserQuestion.d.ts.map +1 -1
  51. package/dist/tools/askUserQuestion.js +39 -25
  52. package/dist/tools/bashTool.d.ts.map +1 -1
  53. package/dist/tools/bashTool.js +7 -9
  54. package/dist/tools/editTool.d.ts.map +1 -1
  55. package/dist/tools/editTool.js +2 -1
  56. package/dist/tools/exitPlanMode.d.ts.map +1 -1
  57. package/dist/tools/exitPlanMode.js +25 -1
  58. package/dist/tools/globTool.d.ts.map +1 -1
  59. package/dist/tools/globTool.js +8 -2
  60. package/dist/tools/grepTool.d.ts.map +1 -1
  61. package/dist/tools/grepTool.js +17 -6
  62. package/dist/tools/lsTool.d.ts.map +1 -1
  63. package/dist/tools/lsTool.js +3 -1
  64. package/dist/tools/readTool.d.ts.map +1 -1
  65. package/dist/tools/readTool.js +16 -1
  66. package/dist/tools/taskManagementTools.d.ts +6 -0
  67. package/dist/tools/taskManagementTools.d.ts.map +1 -0
  68. package/dist/tools/taskManagementTools.js +453 -0
  69. package/dist/tools/taskOutputTool.d.ts.map +1 -1
  70. package/dist/tools/taskOutputTool.js +32 -8
  71. package/dist/tools/taskStopTool.d.ts.map +1 -1
  72. package/dist/tools/taskStopTool.js +7 -1
  73. package/dist/tools/taskTool.d.ts.map +1 -1
  74. package/dist/tools/taskTool.js +6 -1
  75. package/dist/tools/types.d.ts +9 -0
  76. package/dist/tools/types.d.ts.map +1 -1
  77. package/dist/tools/writeTool.d.ts.map +1 -1
  78. package/dist/tools/writeTool.js +9 -1
  79. package/dist/types/index.d.ts +1 -0
  80. package/dist/types/index.d.ts.map +1 -1
  81. package/dist/types/index.js +1 -0
  82. package/dist/types/messaging.d.ts +2 -8
  83. package/dist/types/messaging.d.ts.map +1 -1
  84. package/dist/types/processes.d.ts +11 -6
  85. package/dist/types/processes.d.ts.map +1 -1
  86. package/dist/types/tasks.d.ts +13 -0
  87. package/dist/types/tasks.d.ts.map +1 -0
  88. package/dist/types/tasks.js +1 -0
  89. package/dist/types/tools.d.ts +4 -1
  90. package/dist/types/tools.d.ts.map +1 -1
  91. package/dist/utils/builtinSubagents.d.ts.map +1 -1
  92. package/dist/utils/builtinSubagents.js +38 -1
  93. package/dist/utils/cacheControlUtils.d.ts.map +1 -1
  94. package/dist/utils/cacheControlUtils.js +18 -12
  95. package/dist/utils/constants.d.ts +0 -4
  96. package/dist/utils/constants.d.ts.map +1 -1
  97. package/dist/utils/constants.js +0 -4
  98. package/dist/utils/convertMessagesForAPI.js +2 -2
  99. package/dist/utils/messageOperations.d.ts +2 -35
  100. package/dist/utils/messageOperations.d.ts.map +1 -1
  101. package/dist/utils/messageOperations.js +4 -97
  102. package/dist/utils/nameGenerator.d.ts +1 -1
  103. package/dist/utils/nameGenerator.d.ts.map +1 -1
  104. package/dist/utils/nameGenerator.js +19 -3
  105. package/package.json +1 -1
  106. package/src/agent.ts +90 -101
  107. package/src/constants/prompts.ts +156 -65
  108. package/src/constants/tools.ts +4 -1
  109. package/src/index.ts +1 -0
  110. package/src/managers/aiManager.ts +79 -70
  111. package/src/managers/backgroundTaskManager.ts +53 -54
  112. package/src/managers/foregroundTaskManager.ts +3 -2
  113. package/src/managers/mcpManager.ts +6 -3
  114. package/src/managers/messageManager.ts +137 -73
  115. package/src/managers/permissionManager.ts +32 -21
  116. package/src/managers/planManager.ts +2 -2
  117. package/src/managers/slashCommandManager.ts +11 -2
  118. package/src/managers/subagentManager.ts +33 -14
  119. package/src/managers/toolManager.ts +32 -2
  120. package/src/services/aiService.ts +3 -145
  121. package/src/services/memory.ts +0 -72
  122. package/src/services/session.ts +73 -0
  123. package/src/services/taskManager.ts +188 -0
  124. package/src/tools/askUserQuestion.ts +51 -29
  125. package/src/tools/bashTool.ts +9 -15
  126. package/src/tools/editTool.ts +3 -1
  127. package/src/tools/exitPlanMode.ts +26 -2
  128. package/src/tools/globTool.ts +10 -2
  129. package/src/tools/grepTool.ts +17 -6
  130. package/src/tools/lsTool.ts +3 -1
  131. package/src/tools/readTool.ts +17 -1
  132. package/src/tools/taskManagementTools.ts +498 -0
  133. package/src/tools/taskOutputTool.ts +34 -12
  134. package/src/tools/taskStopTool.ts +7 -1
  135. package/src/tools/taskTool.ts +7 -1
  136. package/src/tools/types.ts +10 -0
  137. package/src/tools/writeTool.ts +9 -2
  138. package/src/types/index.ts +1 -0
  139. package/src/types/messaging.ts +1 -9
  140. package/src/types/processes.ts +13 -7
  141. package/src/types/tasks.ts +13 -0
  142. package/src/types/tools.ts +4 -1
  143. package/src/utils/builtinSubagents.ts +47 -1
  144. package/src/utils/cacheControlUtils.ts +26 -18
  145. package/src/utils/constants.ts +0 -5
  146. package/src/utils/convertMessagesForAPI.ts +2 -2
  147. package/src/utils/messageOperations.ts +5 -136
  148. package/src/utils/nameGenerator.ts +20 -3
  149. package/dist/tools/todoWriteTool.d.ts +0 -6
  150. package/dist/tools/todoWriteTool.d.ts.map +0 -1
  151. package/dist/tools/todoWriteTool.js +0 -220
  152. 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
  }
@@ -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,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,oBAAoB,cAAc,CAAC;AAChD,eAAO,MAAM,eAAe,UAAU,CAAC"}
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"}
@@ -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;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;AAGvC,cAAc,kBAAkB,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";
@@ -11,6 +11,7 @@ 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;
@@ -35,6 +36,7 @@ export declare class AIManager {
35
36
  private logger?;
36
37
  private toolManager;
37
38
  private messageManager;
39
+ private taskManager;
38
40
  private backgroundTaskManager?;
39
41
  private hookManager?;
40
42
  private reversionManager?;
@@ -61,11 +63,6 @@ export declare class AIManager {
61
63
  private getFilteredToolsConfig;
62
64
  setIsLoading(isLoading: boolean): void;
63
65
  abortAIMessage(): void;
64
- /**
65
- * Abort the AI recursion loop immediately.
66
- * This is used when a tool is backgrounded via Ctrl-B, even if no foreground task was active.
67
- */
68
- abortRecursion(): void;
69
66
  private generateCompactParams;
70
67
  private handleTokenUsageAndCompression;
71
68
  getIsCompressing(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"aiManager.d.ts","sourceRoot":"","sources":["../../src/managers/aiManager.ts"],"names":[],"mappings":"AASA,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,E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../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";
6
+ import * as fsSync from "node:fs";
5
7
  import * as fs from "node:fs/promises";
6
- 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
+ }
7
26
  export class AIManager {
8
27
  constructor(options) {
9
28
  this.isLoading = false;
@@ -12,6 +31,7 @@ export class AIManager {
12
31
  this.isCompressing = false;
13
32
  this.messageManager = options.messageManager;
14
33
  this.toolManager = options.toolManager;
34
+ this.taskManager = options.taskManager;
15
35
  this.backgroundTaskManager = options.backgroundTaskManager;
16
36
  this.hookManager = options.hookManager;
17
37
  this.reversionManager = options.reversionManager;
@@ -78,14 +98,6 @@ export class AIManager {
78
98
  }
79
99
  this.setIsLoading(false);
80
100
  }
81
- /**
82
- * Abort the AI recursion loop immediately.
83
- * This is used when a tool is backgrounded via Ctrl-B, even if no foreground task was active.
84
- */
85
- abortRecursion() {
86
- this.logger?.info("Aborting AI recursion loop");
87
- this.abortAIMessage();
88
- }
89
101
  // Helper method to generate compactParams
90
102
  generateCompactParams(toolName, toolArgs) {
91
103
  try {
@@ -95,6 +107,7 @@ export class AIManager {
95
107
  if (toolPlugin?.formatCompactParams) {
96
108
  const context = {
97
109
  workdir: this.workdir,
110
+ taskManager: this.taskManager,
98
111
  };
99
112
  return toolPlugin.formatCompactParams(toolArgs, context);
100
113
  }
@@ -118,7 +131,7 @@ export class AIManager {
118
131
  this.getMaxInputTokens()) {
119
132
  this.logger?.debug(`Token usage exceeded ${this.getMaxInputTokens()}, compressing messages...`);
120
133
  // Check if messages need compression
121
- const { messagesToCompress, insertIndex } = getMessagesToCompress(this.messageManager.getMessages());
134
+ const messagesToCompress = this.messageManager.getMessages();
122
135
  // If there are messages to compress, perform compression
123
136
  if (messagesToCompress.length > 0) {
124
137
  const recentChatMessages = convertMessagesForAPI(messagesToCompress);
@@ -145,7 +158,7 @@ export class AIManager {
145
158
  };
146
159
  }
147
160
  // Execute message reconstruction and sessionId update after compression
148
- this.messageManager.compressMessagesAndUpdateSession(insertIndex, compressionResult.content, compressionUsage);
161
+ this.messageManager.compressMessagesAndUpdateSession(compressionResult.content, compressionUsage);
149
162
  // Notify Agent to add to usage tracking
150
163
  if (compressionUsage && this.callbacks?.onUsageAdded) {
151
164
  this.callbacks.onUsageAdded(compressionUsage);
@@ -176,6 +189,8 @@ export class AIManager {
176
189
  if (recursionDepth === 0 && this.isLoading) {
177
190
  return;
178
191
  }
192
+ // Save session in each recursion to ensure message persistence
193
+ await this.messageManager.saveSession();
179
194
  // Only create new AbortControllers for the initial call (recursionDepth === 0)
180
195
  // For recursive calls, reuse existing controllers to maintain abort signal
181
196
  let abortController;
@@ -189,12 +204,9 @@ export class AIManager {
189
204
  }
190
205
  else {
191
206
  // Reuse existing controllers for recursive calls
192
- // Fallback to new controllers if they were cleared (should not happen in normal flow but good for tests)
193
- abortController = this.abortController || new AbortController();
194
- toolAbortController = this.toolAbortController || new AbortController();
207
+ abortController = this.abortController;
208
+ toolAbortController = this.toolAbortController;
195
209
  }
196
- // Save session in each recursion to ensure message persistence
197
- await this.messageManager.saveSession();
198
210
  // Only set loading state for the initial call
199
211
  if (recursionDepth === 0) {
200
212
  this.setIsLoading(true);
@@ -213,13 +225,11 @@ export class AIManager {
213
225
  // Get current permission mode and plan file path
214
226
  const currentMode = this.permissionManager?.getCurrentEffectiveMode(this.getModelConfig().permissionMode);
215
227
  const toolsConfig = this.getFilteredToolsConfig(tools);
216
- let effectiveSystemPrompt = buildSystemPrompt(this.systemPrompt || DEFAULT_SYSTEM_PROMPT, toolsConfig);
217
- // Inject language prompt if configured
218
- const language = this.getLanguage();
219
- if (language) {
220
- 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.`;
221
- effectiveSystemPrompt = (effectiveSystemPrompt || "") + languagePrompt;
222
- }
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;
223
233
  if (currentMode === "plan") {
224
234
  const planFilePath = this.permissionManager?.getPlanFilePath();
225
235
  if (planFilePath) {
@@ -231,8 +241,7 @@ export class AIManager {
231
241
  catch {
232
242
  planExists = false;
233
243
  }
234
- 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.`;
235
- effectiveSystemPrompt = (effectiveSystemPrompt || "") + reminder;
244
+ planModeOptions = { planFilePath, planExists };
236
245
  }
237
246
  }
238
247
  // Call AI service with streaming callbacks if enabled
@@ -242,11 +251,19 @@ export class AIManager {
242
251
  messages: recentMessages,
243
252
  sessionId: this.messageManager.getSessionId(),
244
253
  abortSignal: abortController.signal,
245
- memory: combinedMemory, // Pass combined memory content
246
254
  workdir: this.workdir, // Pass working directory
247
255
  tools: toolsConfig, // Pass filtered tool configuration
248
256
  model: model, // Use passed model
249
- 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
250
267
  maxTokens: maxTokens, // Pass max tokens override
251
268
  };
252
269
  // Add streaming callbacks only if streaming is enabled
@@ -431,19 +448,11 @@ export class AIManager {
431
448
  backgroundTaskManager: this.backgroundTaskManager,
432
449
  workdir: this.workdir,
433
450
  messageId: this.messageManager.getMessages().slice(-1)[0]?.id,
451
+ sessionId: this.messageManager.getSessionId(),
452
+ taskManager: this.taskManager,
434
453
  };
435
454
  // Execute tool
436
455
  const toolResult = await this.toolManager.execute(functionToolCall.function?.name || "", toolArgs, context);
437
- // Check if the tool was backgrounded via Ctrl-B
438
- // If it was backgrounded, we should abort the AI recursion
439
- if (toolResult.success &&
440
- toolResult.content.includes("Command was manually backgrounded by user")) {
441
- this.logger?.info(`Tool ${toolName} was backgrounded via Ctrl-B, aborting AI recursion`);
442
- // Use abortAIMessage directly instead of abortRecursion to avoid double logging
443
- // and ensure we don't trigger the "Request was aborted" error block
444
- this.abortAIMessage();
445
- return;
446
- }
447
456
  // Update message state - tool execution completed
448
457
  this.messageManager.updateToolBlock({
449
458
  id: toolId,
@@ -455,6 +464,7 @@ export class AIManager {
455
464
  stage: "end",
456
465
  name: toolName,
457
466
  shortResult: toolResult.shortResult,
467
+ isManuallyBackgrounded: toolResult.isManuallyBackgrounded,
458
468
  });
459
469
  // Execute PostToolUse hooks after successful tool completion
460
470
  await this.executePostToolUseHooks(toolId, toolName, toolArgs, toolResult);
@@ -472,6 +482,7 @@ export class AIManager {
472
482
  stage: "end",
473
483
  name: toolName,
474
484
  compactParams,
485
+ isManuallyBackgrounded: false,
475
486
  });
476
487
  }
477
488
  });
@@ -491,7 +502,15 @@ export class AIManager {
491
502
  }
492
503
  // Check interruption status
493
504
  const isCurrentlyAborted = abortController.signal.aborted || toolAbortController.signal.aborted;
494
- 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) {
495
514
  // Recursively call AI service, increment recursion depth, and pass same configuration
496
515
  await this.sendAIMessage({
497
516
  recursionDepth: recursionDepth + 1,
@@ -504,15 +523,7 @@ export class AIManager {
504
523
  }
505
524
  }
506
525
  catch (error) {
507
- // Check if the error is an abort error
508
- // Use the local variables to avoid null reference if this.abortController was cleared
509
- const isCurrentlyAborted = abortController.signal.aborted || toolAbortController.signal.aborted;
510
- if (isCurrentlyAborted) {
511
- this.logger?.info("AI message processing was aborted");
512
- }
513
- else {
514
- this.messageManager.addErrorBlock(error instanceof Error ? error.message : "Unknown error occurred");
515
- }
526
+ this.messageManager.addErrorBlock(error instanceof Error ? error.message : "Unknown error occurred");
516
527
  }
517
528
  finally {
518
529
  // Only execute cleanup and hooks for the initial call
@@ -1 +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;IA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