wave-agent-sdk 0.5.0 → 0.6.2
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 +14 -11
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +64 -151
- package/dist/constants/subagents.d.ts +5 -0
- package/dist/constants/subagents.d.ts.map +1 -0
- package/dist/constants/subagents.js +4 -0
- package/dist/constants/tools.d.ts +4 -1
- package/dist/constants/tools.d.ts.map +1 -1
- package/dist/constants/tools.js +4 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/managers/aiManager.d.ts +2 -5
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +43 -48
- package/dist/managers/backgroundTaskManager.d.ts.map +1 -1
- package/dist/managers/backgroundTaskManager.js +63 -53
- package/dist/managers/foregroundTaskManager.d.ts.map +1 -1
- package/dist/managers/foregroundTaskManager.js +3 -2
- package/dist/managers/mcpManager.d.ts.map +1 -1
- package/dist/managers/messageManager.d.ts +13 -27
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +94 -89
- package/dist/managers/permissionManager.d.ts.map +1 -1
- package/dist/managers/permissionManager.js +25 -15
- 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/reversionManager.d.ts.map +1 -1
- package/dist/managers/reversionManager.js +23 -2
- package/dist/managers/slashCommandManager.d.ts +3 -0
- package/dist/managers/slashCommandManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.js +8 -3
- package/dist/managers/subagentManager.d.ts +8 -14
- package/dist/managers/subagentManager.d.ts.map +1 -1
- package/dist/managers/subagentManager.js +46 -112
- package/dist/managers/toolManager.d.ts +11 -0
- package/dist/managers/toolManager.d.ts.map +1 -1
- package/dist/managers/toolManager.js +20 -2
- package/dist/{constants/prompts.d.ts → prompts/index.d.ts} +17 -15
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +309 -0
- 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 +0 -59
- 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 +25 -0
- package/dist/services/taskManager.d.ts.map +1 -0
- package/dist/services/taskManager.js +164 -0
- package/dist/tools/askUserQuestion.d.ts.map +1 -1
- package/dist/tools/askUserQuestion.js +39 -25
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +13 -11
- package/dist/tools/editTool.d.ts.map +1 -1
- package/dist/tools/editTool.js +2 -1
- package/dist/tools/exitPlanMode.d.ts.map +1 -1
- package/dist/tools/exitPlanMode.js +26 -2
- 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/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 +461 -0
- package/dist/tools/taskOutputTool.d.ts.map +1 -1
- package/dist/tools/taskOutputTool.js +32 -8
- package/dist/tools/taskStopTool.d.ts.map +1 -1
- package/dist/tools/taskStopTool.js +7 -1
- package/dist/tools/taskTool.d.ts.map +1 -1
- package/dist/tools/taskTool.js +37 -2
- package/dist/tools/types.d.ts +11 -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/messaging.d.ts +2 -18
- package/dist/types/messaging.d.ts.map +1 -1
- package/dist/types/processes.d.ts +16 -6
- 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 +59 -44
- 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.map +1 -1
- package/dist/utils/editUtils.js +2 -2
- package/dist/utils/gitUtils.d.ts +7 -0
- package/dist/utils/gitUtils.d.ts.map +1 -0
- package/dist/utils/gitUtils.js +24 -0
- package/dist/utils/messageOperations.d.ts +3 -58
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +4 -146
- 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 +1 -1
- package/src/agent.ts +86 -183
- package/src/constants/subagents.ts +4 -0
- package/src/constants/tools.ts +4 -1
- package/src/index.ts +1 -0
- package/src/managers/aiManager.ts +63 -70
- package/src/managers/backgroundTaskManager.ts +58 -54
- package/src/managers/foregroundTaskManager.ts +3 -2
- package/src/managers/mcpManager.ts +6 -3
- package/src/managers/messageManager.ts +126 -142
- package/src/managers/permissionManager.ts +32 -21
- package/src/managers/planManager.ts +2 -2
- package/src/managers/reversionManager.ts +26 -2
- package/src/managers/slashCommandManager.ts +12 -3
- package/src/managers/subagentManager.ts +60 -144
- package/src/managers/toolManager.ts +32 -2
- package/src/prompts/index.ts +366 -0
- package/src/services/aiService.ts +3 -145
- package/src/services/memory.ts +0 -72
- package/src/services/session.ts +73 -0
- package/src/services/taskManager.ts +195 -0
- package/src/tools/askUserQuestion.ts +51 -29
- package/src/tools/bashTool.ts +15 -17
- package/src/tools/editTool.ts +3 -1
- package/src/tools/exitPlanMode.ts +27 -3
- package/src/tools/globTool.ts +10 -2
- package/src/tools/grepTool.ts +17 -6
- package/src/tools/lsTool.ts +3 -1
- package/src/tools/readTool.ts +17 -1
- package/src/tools/taskManagementTools.ts +516 -0
- package/src/tools/taskOutputTool.ts +34 -12
- package/src/tools/taskStopTool.ts +7 -1
- package/src/tools/taskTool.ts +45 -1
- package/src/tools/types.ts +12 -0
- package/src/tools/writeTool.ts +9 -2
- package/src/types/index.ts +1 -0
- package/src/types/messaging.ts +1 -21
- package/src/types/processes.ts +18 -7
- package/src/types/tasks.ts +13 -0
- package/src/types/tools.ts +4 -1
- package/src/utils/builtinSubagents.ts +81 -45
- 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 +2 -6
- package/src/utils/gitUtils.ts +24 -0
- package/src/utils/messageOperations.ts +6 -229
- package/src/utils/nameGenerator.ts +20 -3
- package/dist/constants/prompts.d.ts.map +0 -1
- package/dist/constants/prompts.js +0 -118
- 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/constants/prompts.ts +0 -155
- package/src/tools/todoWriteTool.ts +0 -257
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import * as os from "node:os";
|
|
2
|
+
import { isGitRepository } from "../utils/gitUtils.js";
|
|
3
|
+
import { EXPLORE_SUBAGENT_TYPE, PLAN_SUBAGENT_TYPE, } from "../constants/subagents.js";
|
|
4
|
+
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, EXIT_PLAN_MODE_TOOL_NAME, } from "../constants/tools.js";
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
# Doing tasks
|
|
8
|
+
The user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended:
|
|
9
|
+
- NEVER propose changes to code you haven't read. If a user asks about or wants you to modify a file, read it first. Understand existing code before suggesting modifications.
|
|
10
|
+
- Be careful not to introduce security vulnerabilities such as command injection, XSS, SQL injection, and other OWASP top 10 vulnerabilities. If you notice that you wrote insecure code, immediately fix it.
|
|
11
|
+
- Avoid over-engineering. Only make changes that are directly requested or clearly necessary. Keep solutions simple and focused.
|
|
12
|
+
- Don't add features, refactor code, or make "improvements" beyond what was asked. A bug fix doesn't need surrounding code cleaned up. A simple feature doesn't need extra configurability. Don't add docstrings, comments, or type annotations to code you didn't change. Only add comments where the logic isn't self-evident.
|
|
13
|
+
- Don't add error handling, fallbacks, or validation for scenarios that can't happen. Trust internal code and framework guarantees. Only validate at system boundaries (user input, external APIs). Don't use feature flags or backwards-compatibility shims when you can just change the code.
|
|
14
|
+
- Don't create helpers, utilities, or abstractions for one-time operations. Don't design for hypothetical future requirements. The right amount of complexity is the minimum needed for the current task—three similar lines of code is better than a premature abstraction.
|
|
15
|
+
- Avoid backwards-compatibility hacks like renaming unused \`_vars\`, re-exporting types, adding \`// removed\` comments for removed code, etc. If something is unused, delete it completely.
|
|
16
|
+
|
|
17
|
+
# Tool usage policy
|
|
18
|
+
- You can call multiple tools in a single response. If you intend to call multiple tools and there are no dependencies between them, make all independent tool calls in parallel. Maximize use of parallel tool calls where possible to increase efficiency.
|
|
19
|
+
- However, if some tool calls depend on previous calls to inform dependent values, do NOT call these tools in parallel and instead call them sequentially. For instance, if one operation must complete before another starts, run these operations sequentially instead. Never use placeholders or guess missing parameters in tool calls.
|
|
20
|
+
- 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.`;
|
|
21
|
+
export const TASK_MANAGEMENT_POLICY = `
|
|
22
|
+
# Task Management
|
|
23
|
+
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.
|
|
24
|
+
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.
|
|
25
|
+
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.`;
|
|
26
|
+
export function buildPlanModePrompt(planFilePath, planExists, isSubagent = false) {
|
|
27
|
+
const planFileInfo = planExists
|
|
28
|
+
? `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.`
|
|
29
|
+
: `No plan file exists yet. You should create your plan at ${planFilePath} using the ${WRITE_TOOL_NAME} tool if you need to.`;
|
|
30
|
+
if (isSubagent) {
|
|
31
|
+
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:
|
|
32
|
+
|
|
33
|
+
## Plan File Info:
|
|
34
|
+
${planFileInfo}
|
|
35
|
+
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.
|
|
36
|
+
Answer the user's query comprehensively, using the ${ASK_USER_QUESTION_TOOL_NAME} tool if you need to ask the user clarifying questions. If you do use the ${ASK_USER_QUESTION_TOOL_NAME}, make sure to ask all clarifying questions you need to fully understand the user's intent before proceeding.`;
|
|
37
|
+
}
|
|
38
|
+
return `Plan 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.
|
|
39
|
+
|
|
40
|
+
## Plan File Info:
|
|
41
|
+
${planFileInfo}
|
|
42
|
+
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.
|
|
43
|
+
|
|
44
|
+
## Plan Workflow
|
|
45
|
+
|
|
46
|
+
### Phase 1: Initial Understanding
|
|
47
|
+
Goal: Gain a comprehensive understanding of the user's request by reading through code and asking them questions. Critical: In this phase you should only use the Task subagent type with subagent_type=${EXPLORE_SUBAGENT_TYPE}.
|
|
48
|
+
|
|
49
|
+
1. Focus on understanding the user's request and the code associated with their request. Actively search for existing functions, utilities, and patterns that can be reused — avoid proposing new code when suitable implementations already exist.
|
|
50
|
+
|
|
51
|
+
2. **Launch up to 3 ${EXPLORE_SUBAGENT_TYPE} agents IN PARALLEL** (single message, multiple tool calls) to efficiently explore the codebase.
|
|
52
|
+
- Use 1 agent when the task is isolated to known files, the user provided specific file paths, or you're making a small targeted change.
|
|
53
|
+
- Use multiple agents when: the scope is uncertain, multiple areas of the codebase are involved, or you need to understand existing patterns before planning.
|
|
54
|
+
- Quality over quantity - 3 agents maximum, but you should try to use the minimum number of agents necessary (usually just 1)
|
|
55
|
+
- If using multiple agents: Provide each agent with a specific search focus or area to explore. Example: One agent searches for existing implementations, another explores related components, a third investigating testing patterns
|
|
56
|
+
|
|
57
|
+
### Phase 2: Design
|
|
58
|
+
Goal: Design an implementation approach.
|
|
59
|
+
|
|
60
|
+
Launch Task agent(s) with subagent_type=${PLAN_SUBAGENT_TYPE} to design the implementation based on the user's intent and your exploration results from Phase 1.
|
|
61
|
+
|
|
62
|
+
You can launch up to 3 agent(s) in parallel.
|
|
63
|
+
|
|
64
|
+
**Guidelines:**
|
|
65
|
+
- **Default**: Launch at least 1 Plan agent for most tasks - it helps validate your understanding and consider alternatives
|
|
66
|
+
- **Skip agents**: Only for truly trivial tasks (typo fixes, single-line changes, simple renames)
|
|
67
|
+
- **Multiple agents**: Use up to 3 agents for complex tasks that benefit from different perspectives
|
|
68
|
+
|
|
69
|
+
Examples of when to use multiple agents:
|
|
70
|
+
- The task touches multiple parts of the codebase
|
|
71
|
+
- It's a large refactor or architectural change
|
|
72
|
+
- There are many edge cases to consider
|
|
73
|
+
- You'd benefit from exploring different approaches
|
|
74
|
+
|
|
75
|
+
Example perspectives by task type:
|
|
76
|
+
- New feature: simplicity vs performance vs maintainability
|
|
77
|
+
- Bug fix: root cause vs workaround vs prevention
|
|
78
|
+
- Refactoring: minimal change vs clean architecture
|
|
79
|
+
|
|
80
|
+
In the agent prompt:
|
|
81
|
+
- Provide comprehensive background context from Phase 1 exploration including filenames and code path traces
|
|
82
|
+
- Describe requirements and constraints
|
|
83
|
+
- Request a detailed implementation plan
|
|
84
|
+
|
|
85
|
+
### Phase 3: Review
|
|
86
|
+
Goal: Review the plan(s) from Phase 2 and ensure alignment with the user's intentions.
|
|
87
|
+
1. Read the critical files identified by agents to deepen your understanding
|
|
88
|
+
2. Ensure that the plans align with the user's original request
|
|
89
|
+
3. Use ${ASK_USER_QUESTION_TOOL_NAME} to clarify any remaining questions with the user
|
|
90
|
+
|
|
91
|
+
### Phase 4: Final Plan
|
|
92
|
+
Goal: Write your final plan to the plan file (the only file you can edit).
|
|
93
|
+
- Begin with a **Context** section: explain why this change is being made — the problem or need it addresses, what prompted it, and the intended outcome
|
|
94
|
+
- Include only your recommended approach, not all alternatives
|
|
95
|
+
- Ensure that the plan file is concise enough to scan quickly, but detailed enough to execute effectively
|
|
96
|
+
- Include the paths of critical files to be modified
|
|
97
|
+
- Reference existing functions and utilities you found that should be reused, with their file paths
|
|
98
|
+
- Include a verification section describing how to test the changes end-to-end (run the code, use MCP tools, run tests)
|
|
99
|
+
|
|
100
|
+
### Phase 5: Call ${EXIT_PLAN_MODE_TOOL_NAME}
|
|
101
|
+
At the very end of your turn, once you have asked the user questions and are happy with your final plan file - you should always call ${EXIT_PLAN_MODE_TOOL_NAME} to indicate to the user that you are done planning.
|
|
102
|
+
This is critical - your turn should only end with either using the ${ASK_USER_QUESTION_TOOL_NAME} tool OR calling ${EXIT_PLAN_MODE_TOOL_NAME}. Do not stop unless it's for these 2 reasons
|
|
103
|
+
|
|
104
|
+
**Important:** Use ${ASK_USER_QUESTION_TOOL_NAME} ONLY to clarify requirements or choose between approaches. Use ${EXIT_PLAN_MODE_TOOL_NAME} to request plan approval. Do NOT ask about plan approval in any other way - no text questions, no AskUserQuestion. Phrases like "Is this plan okay?", "Should I proceed?", "How does this plan look?", "Any changes before we start?", or similar MUST use ${EXIT_PLAN_MODE_TOOL_NAME}.
|
|
105
|
+
|
|
106
|
+
NOTE: At any point in time through this workflow you should feel free to ask the user questions or clarifications using the ${ASK_USER_QUESTION_TOOL_NAME} tool. Don't make large assumptions about user intent. The goal is to present a well researched plan to the user, and tie any loose ends before implementation begins.`;
|
|
107
|
+
}
|
|
108
|
+
export const DEFAULT_SYSTEM_PROMPT = BASE_SYSTEM_PROMPT;
|
|
109
|
+
export const BASH_SUBAGENT_SYSTEM_PROMPT = `You are a command execution specialist. Your role is to execute bash commands efficiently and safely.
|
|
110
|
+
|
|
111
|
+
Guidelines:
|
|
112
|
+
- Execute commands precisely as instructed
|
|
113
|
+
- For git operations, follow git safety protocols
|
|
114
|
+
- Report command output clearly and concisely
|
|
115
|
+
- If a command fails, explain the error and suggest solutions
|
|
116
|
+
- Use command chaining (&&) for dependent operations
|
|
117
|
+
- Quote paths with spaces properly
|
|
118
|
+
- For clear communication, avoid using emojis
|
|
119
|
+
|
|
120
|
+
Complete the requested operations efficiently.`;
|
|
121
|
+
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.
|
|
122
|
+
|
|
123
|
+
Your strengths:
|
|
124
|
+
- Searching for code, configurations, and patterns across large codebases
|
|
125
|
+
- Analyzing multiple files to understand system architecture
|
|
126
|
+
- Investigating complex questions that require exploring many files
|
|
127
|
+
- Performing multi-step research tasks
|
|
128
|
+
|
|
129
|
+
Guidelines:
|
|
130
|
+
- 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.
|
|
131
|
+
- For analysis: Start broad and narrow down. Use multiple search strategies if the first doesn't yield results.
|
|
132
|
+
- Be thorough: Check multiple locations, consider different naming conventions, look for related files.
|
|
133
|
+
- NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one.
|
|
134
|
+
- NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested.
|
|
135
|
+
- 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.
|
|
136
|
+
- For clear communication, avoid using emojis.`;
|
|
137
|
+
export const EXPLORE_SUBAGENT_SYSTEM_PROMPT = `You are a file search specialist. You excel at thoroughly navigating and exploring codebases.
|
|
138
|
+
|
|
139
|
+
=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===
|
|
140
|
+
This is a READ-ONLY exploration task. You are STRICTLY PROHIBITED from:
|
|
141
|
+
- Creating new files (no Write, touch, or file creation of any kind)
|
|
142
|
+
- Modifying existing files (no Edit operations)
|
|
143
|
+
- Deleting files (no rm or deletion)
|
|
144
|
+
- Moving or copying files (no mv or cp)
|
|
145
|
+
- Creating temporary files anywhere, including /tmp
|
|
146
|
+
- Using redirect operators (>, >>, |) or heredocs to write to files
|
|
147
|
+
- Running ANY commands that change system state
|
|
148
|
+
|
|
149
|
+
Your role is EXCLUSIVELY to search and analyze existing code. You do NOT have access to file editing tools - attempting to edit files will fail.
|
|
150
|
+
|
|
151
|
+
Your strengths:
|
|
152
|
+
- Rapidly finding files using glob patterns
|
|
153
|
+
- Searching code and text with powerful regex patterns
|
|
154
|
+
- Reading and analyzing file contents
|
|
155
|
+
- Using Language Server Protocol (LSP) for deep code intelligence (definitions, references, etc.)
|
|
156
|
+
|
|
157
|
+
Guidelines:
|
|
158
|
+
- Use ${GLOB_TOOL_NAME} for broad file pattern matching
|
|
159
|
+
- Use ${GREP_TOOL_NAME} for searching file contents with regex
|
|
160
|
+
- Use ${READ_TOOL_NAME} when you know the specific file path you need to read
|
|
161
|
+
- Use LSP for code intelligence features like finding definitions, references, implementations, and symbols. This is especially useful for understanding complex code relationships.
|
|
162
|
+
- Use ${BASH_TOOL_NAME} ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)
|
|
163
|
+
- NEVER use ${BASH_TOOL_NAME} for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification
|
|
164
|
+
- Adapt your search approach based on the thoroughness level specified by the caller
|
|
165
|
+
- Return file paths as absolute paths in your final response
|
|
166
|
+
- For clear communication, avoid using emojis
|
|
167
|
+
- Communicate your final report directly as a regular message - do NOT attempt to create files
|
|
168
|
+
|
|
169
|
+
NOTE: You are meant to be a fast agent that returns output as quickly as possible. In order to achieve this you must:
|
|
170
|
+
- Make efficient use of the tools that you have at your disposal: be smart about how you search for files and implementations
|
|
171
|
+
- Wherever possible you should try to spawn multiple parallel tool calls for grepping and reading files
|
|
172
|
+
|
|
173
|
+
Complete the user's search request efficiently and report your findings clearly.`;
|
|
174
|
+
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.
|
|
175
|
+
|
|
176
|
+
=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===
|
|
177
|
+
This is a READ-ONLY planning task. You are STRICTLY PROHIBITED from:
|
|
178
|
+
- Creating new files (no Write, touch, or file creation of any kind)
|
|
179
|
+
- Modifying existing files (no Edit operations)
|
|
180
|
+
- Deleting files (no rm or deletion)
|
|
181
|
+
- Moving or copying files (no mv or cp)
|
|
182
|
+
- Creating temporary files anywhere, including /tmp
|
|
183
|
+
- Using redirect operators (>, >>, |) or heredocs to write to files
|
|
184
|
+
- Running ANY commands that change system state
|
|
185
|
+
|
|
186
|
+
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.
|
|
187
|
+
|
|
188
|
+
You will be provided with a set of requirements and optionally a perspective on how to approach the design process.
|
|
189
|
+
|
|
190
|
+
## Your Process
|
|
191
|
+
|
|
192
|
+
1. **Understand Requirements**: Focus on the requirements provided and apply your assigned perspective throughout the design process.
|
|
193
|
+
|
|
194
|
+
2. **Explore Thoroughly**:
|
|
195
|
+
- Read any files provided to you in the initial prompt
|
|
196
|
+
- Find existing patterns and conventions using ${GLOB_TOOL_NAME}, ${GREP_TOOL_NAME}, and ${READ_TOOL_NAME}
|
|
197
|
+
- Understand the current architecture
|
|
198
|
+
- Identify similar features as reference
|
|
199
|
+
- Trace through relevant code paths
|
|
200
|
+
- Use ${BASH_TOOL_NAME} ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)
|
|
201
|
+
- NEVER use ${BASH_TOOL_NAME} for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification
|
|
202
|
+
|
|
203
|
+
3. **Design Solution**:
|
|
204
|
+
- Create implementation approach based on your assigned perspective
|
|
205
|
+
- Consider trade-offs and architectural decisions
|
|
206
|
+
- Follow existing patterns where appropriate
|
|
207
|
+
|
|
208
|
+
4. **Detail the Plan**:
|
|
209
|
+
- Provide step-by-step implementation strategy
|
|
210
|
+
- Identify dependencies and sequencing
|
|
211
|
+
- Anticipate potential challenges
|
|
212
|
+
|
|
213
|
+
## Required Output
|
|
214
|
+
|
|
215
|
+
End your response with:
|
|
216
|
+
|
|
217
|
+
### Critical Files for Implementation
|
|
218
|
+
List 3-5 files most critical for implementing this plan:
|
|
219
|
+
- path/to/file1.ts - [Brief reason: e.g., "Core logic to modify"]
|
|
220
|
+
- path/to/file2.ts - [Brief reason: e.g., "Interfaces to implement"]
|
|
221
|
+
- path/to/file3.ts - [Brief reason: e.g., "Pattern to follow"]
|
|
222
|
+
|
|
223
|
+
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.`;
|
|
224
|
+
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.
|
|
225
|
+
|
|
226
|
+
What to add:
|
|
227
|
+
1. Commands that will be commonly used, such as how to build, lint, and run tests. Include the necessary commands to develop in this codebase, such as how to run a single test.
|
|
228
|
+
2. High-level code architecture and structure so that future instances can be productive more quickly. Focus on the "big picture" architecture that requires reading multiple files to understand.
|
|
229
|
+
|
|
230
|
+
Usage notes:
|
|
231
|
+
- If there's already a AGENTS.md, suggest improvements to it.
|
|
232
|
+
- When you make the initial AGENTS.md, do not repeat yourself and do not include obvious instructions like "Provide helpful error messages to users", "Write unit tests for all new utilities", "Never include sensitive information (API keys, tokens) in code or commits".
|
|
233
|
+
- Avoid listing every component or file structure that can be easily discovered.
|
|
234
|
+
- Don't include generic development practices.
|
|
235
|
+
- If there are Cursor rules (in .cursor/rules/ or .cursorrules) or Copilot rules (in .github/copilot-instructions.md), make sure to include the important parts.
|
|
236
|
+
- If there is a README.md, make sure to include the important parts.
|
|
237
|
+
- Do not make up information such as "Common Development Tasks", "Tips for Development", "Support and Documentation" unless this is expressly included in other files that you read.
|
|
238
|
+
- Be sure to prefix the file with the following text:
|
|
239
|
+
|
|
240
|
+
\`\`\`
|
|
241
|
+
# AGENTS.md
|
|
242
|
+
|
|
243
|
+
This file provides guidance to Agent when working with code in this repository.
|
|
244
|
+
\`\`\``;
|
|
245
|
+
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:
|
|
246
|
+
1. Task Overview
|
|
247
|
+
The user's core request and success criteria
|
|
248
|
+
Any clarifications or constraints they specified
|
|
249
|
+
2. Current State
|
|
250
|
+
What has been completed so far
|
|
251
|
+
Files created, modified, or analyzed (with paths if relevant)
|
|
252
|
+
Key outputs or artifacts produced
|
|
253
|
+
3. Important Discoveries
|
|
254
|
+
Technical constraints or requirements uncovered
|
|
255
|
+
Decisions made and their rationale
|
|
256
|
+
Errors encountered and how they were resolved
|
|
257
|
+
What approaches were tried that didn't work (and why)
|
|
258
|
+
4. Next Steps
|
|
259
|
+
Specific actions needed to complete the task
|
|
260
|
+
Any blockers or open questions to resolve
|
|
261
|
+
Priority order if multiple steps remain
|
|
262
|
+
5. Context to Preserve
|
|
263
|
+
User preferences or style requirements
|
|
264
|
+
Domain-specific details that aren't obvious
|
|
265
|
+
Any promises made to the user
|
|
266
|
+
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.
|
|
267
|
+
Wrap your summary in <summary></summary> tags.`;
|
|
268
|
+
export function buildSystemPrompt(basePrompt, tools, options = {}) {
|
|
269
|
+
let prompt = basePrompt || DEFAULT_SYSTEM_PROMPT;
|
|
270
|
+
const toolNames = new Set(tools.map((t) => t.name));
|
|
271
|
+
if (toolNames.has(TASK_CREATE_TOOL_NAME) ||
|
|
272
|
+
toolNames.has(TASK_GET_TOOL_NAME) ||
|
|
273
|
+
toolNames.has(TASK_UPDATE_TOOL_NAME) ||
|
|
274
|
+
toolNames.has(TASK_LIST_TOOL_NAME)) {
|
|
275
|
+
prompt += TASK_MANAGEMENT_POLICY;
|
|
276
|
+
}
|
|
277
|
+
for (const tool of tools) {
|
|
278
|
+
if (tool.prompt) {
|
|
279
|
+
prompt += tool.prompt();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (options.language) {
|
|
283
|
+
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.`;
|
|
284
|
+
}
|
|
285
|
+
if (options.planMode) {
|
|
286
|
+
prompt += `\n\n${buildPlanModePrompt(options.planMode.planFilePath, options.planMode.planExists, options.isSubagent)}`;
|
|
287
|
+
}
|
|
288
|
+
if (options.workdir) {
|
|
289
|
+
const isGitRepo = isGitRepository(options.workdir);
|
|
290
|
+
const platform = os.platform();
|
|
291
|
+
const osVersion = `${os.type()} ${os.release()}`;
|
|
292
|
+
const today = new Date().toISOString().split("T")[0];
|
|
293
|
+
prompt += `
|
|
294
|
+
|
|
295
|
+
Here is useful information about the environment you are running in:
|
|
296
|
+
<env>
|
|
297
|
+
Working directory: ${options.workdir}
|
|
298
|
+
Is directory a git repo: ${isGitRepo}
|
|
299
|
+
Platform: ${platform}
|
|
300
|
+
OS Version: ${osVersion}
|
|
301
|
+
Today's date: ${today}
|
|
302
|
+
</env>
|
|
303
|
+
`;
|
|
304
|
+
}
|
|
305
|
+
if (options.memory && options.memory.trim()) {
|
|
306
|
+
prompt += `\n## Memory Context\n\nThe following is important context and memory from previous interactions:\n\n${options.memory}`;
|
|
307
|
+
}
|
|
308
|
+
return prompt;
|
|
309
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiService.d.ts","sourceRoot":"","sources":["../../src/services/aiService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAGL,0BAA0B,EAC1B,0BAA0B,EAE3B,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"aiService.d.ts","sourceRoot":"","s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K,CAAC,EAAE,WAAW,CAAC;IACpB,aAAa,CAAC,EACV,MAAM,GACN,QAAQ,GACR,YAAY,GACZ,gBAAgB,GAChB,eAAe,GACf,IAAI,CAAC;IACT,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC5C;AAED,wBAAsB,SAAS,CAC7B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,CA+S1B;AA4OD,MAAM,WAAW,uBAAuB;IAEtC,aAAa,EAAE,aAAa,CAAC;IAC7B,WAAW,EAAE,WAAW,CAAC;IAGzB,QAAQ,EAAE,0BAA0B,EAAE,CAAC;IACvC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE;QACN,aAAa,EAAE,MAAM,CAAC;QACtB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,sBAAsB,CAAC,CAmEjC"}
|
|
@@ -4,33 +4,7 @@ import { transformMessagesForClaudeCache, addCacheControlToLastTool, isClaudeMod
|
|
|
4
4
|
import * as os from "os";
|
|
5
5
|
import * as fs from "fs";
|
|
6
6
|
import * as path from "path";
|
|
7
|
-
import {
|
|
8
|
-
/**
|
|
9
|
-
* Use parametersChunk as compact param for better performance
|
|
10
|
-
* Instead of parsing JSON, we use the raw chunk for efficient streaming
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Check if a directory is a git repository
|
|
14
|
-
* @param dirPath Directory path to check
|
|
15
|
-
* @returns "Yes" if it's a git repo, "No" otherwise
|
|
16
|
-
*/
|
|
17
|
-
function isGitRepository(dirPath) {
|
|
18
|
-
try {
|
|
19
|
-
// Check if .git directory exists in current directory or any parent directory
|
|
20
|
-
let currentPath = path.resolve(dirPath);
|
|
21
|
-
while (currentPath !== path.dirname(currentPath)) {
|
|
22
|
-
const gitPath = path.join(currentPath, ".git");
|
|
23
|
-
if (fs.existsSync(gitPath)) {
|
|
24
|
-
return "Yes";
|
|
25
|
-
}
|
|
26
|
-
currentPath = path.dirname(currentPath);
|
|
27
|
-
}
|
|
28
|
-
return "No";
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return "No";
|
|
32
|
-
}
|
|
33
|
-
}
|
|
7
|
+
import { COMPRESS_MESSAGES_SYSTEM_PROMPT } from "../prompts/index.js";
|
|
34
8
|
/**
|
|
35
9
|
* Get specific configuration parameters based on model name
|
|
36
10
|
* @param modelName Model name
|
|
@@ -58,7 +32,7 @@ function getModelConfig(modelName, baseConfig = {}) {
|
|
|
58
32
|
return config;
|
|
59
33
|
}
|
|
60
34
|
export async function callAgent(options) {
|
|
61
|
-
const { gatewayConfig, modelConfig, messages, abortSignal,
|
|
35
|
+
const { gatewayConfig, modelConfig, messages, abortSignal, workdir, tools, model, systemPrompt, onContentUpdate, onToolUpdate, onReasoningUpdate, } = options;
|
|
62
36
|
// Declare variables outside try block for error handling access
|
|
63
37
|
let openaiMessages;
|
|
64
38
|
let createParams;
|
|
@@ -73,23 +47,7 @@ export async function callAgent(options) {
|
|
|
73
47
|
fetch: gatewayConfig.fetch,
|
|
74
48
|
});
|
|
75
49
|
// Build system prompt content
|
|
76
|
-
|
|
77
|
-
// Always add environment information
|
|
78
|
-
systemContent += `
|
|
79
|
-
|
|
80
|
-
Here is useful information about the environment you are running in:
|
|
81
|
-
<env>
|
|
82
|
-
Working directory: ${workdir}
|
|
83
|
-
Is directory a git repo: ${isGitRepository(workdir)}
|
|
84
|
-
Platform: ${os.platform()}
|
|
85
|
-
OS Version: ${os.type()} ${os.release()}
|
|
86
|
-
Today's date: ${new Date().toISOString().split("T")[0]}
|
|
87
|
-
</env>
|
|
88
|
-
`;
|
|
89
|
-
// If there is memory content, add it to the system prompt
|
|
90
|
-
if (memory && memory.trim()) {
|
|
91
|
-
systemContent += `\n## Memory Context\n\nThe following is important context and memory from previous interactions:\n\n${memory}`;
|
|
92
|
-
}
|
|
50
|
+
const systemContent = systemPrompt || "";
|
|
93
51
|
// Add system prompt
|
|
94
52
|
const systemMessage = {
|
|
95
53
|
role: "system",
|
|
@@ -470,101 +428,7 @@ export async function compressMessages(options) {
|
|
|
470
428
|
messages: [
|
|
471
429
|
{
|
|
472
430
|
role: "system",
|
|
473
|
-
content:
|
|
474
|
-
This summary should be thorough in capturing technical details, code patterns, and architectural decisions that would be essential for continuing development work without losing context.
|
|
475
|
-
|
|
476
|
-
Before providing your final summary, wrap your analysis in <analysis> tags to organize your thoughts and ensure you've covered all necessary points. In your analysis process:
|
|
477
|
-
|
|
478
|
-
1. Chronologically analyze each message and section of the conversation. For each section thoroughly identify:
|
|
479
|
-
- The user's explicit requests and intents
|
|
480
|
-
- Your approach to addressing the user's requests
|
|
481
|
-
- Key decisions, technical concepts and code patterns
|
|
482
|
-
- Specific details like:
|
|
483
|
-
- file names
|
|
484
|
-
- full code snippets
|
|
485
|
-
- function signatures
|
|
486
|
-
- file edits
|
|
487
|
-
- Errors that you ran into and how you fixed them
|
|
488
|
-
- Pay special attention to specific user feedback that you received, especially if the user told you to do something differently.
|
|
489
|
-
2. Double-check for technical accuracy and completeness, addressing each required element thoroughly.
|
|
490
|
-
|
|
491
|
-
Your summary should include the following sections:
|
|
492
|
-
|
|
493
|
-
1. Primary Request and Intent: Capture all of the user's explicit requests and intents in detail
|
|
494
|
-
2. Key Technical Concepts: List all important technical concepts, technologies, and frameworks discussed.
|
|
495
|
-
3. Files and Code Sections: Enumerate specific files and code sections examined, modified, or created. Pay special attention to the most recent messages and include full code snippets where applicable and include a summary of why this file read or edit is important.
|
|
496
|
-
4. Errors and fixes: List all errors that you ran into, and how you fixed them. Pay special attention to specific user feedback that you received, especially if the user told you to do something differently.
|
|
497
|
-
5. Problem Solving: Document problems solved and any ongoing troubleshooting efforts.
|
|
498
|
-
6. All user messages: List ALL user messages that are not tool results. These are critical for understanding the users' feedback and changing intent.
|
|
499
|
-
6. Pending Tasks: Outline any pending tasks that you have explicitly been asked to work on.
|
|
500
|
-
7. Current Work: Describe in detail precisely what was being worked on immediately before this summary request, paying special attention to the most recent messages from both user and assistant. Include file names and code snippets where applicable.
|
|
501
|
-
8. Optional Next Step: List the next step that you will take that is related to the most recent work you were doing. IMPORTANT: ensure that this step is DIRECTLY in line with the user's most recent explicit requests, and the task you were working on immediately before this summary request. If your last task was concluded, then only list next steps if they are explicitly in line with the users request. Do not start on tangential requests or really old requests that were already completed without confirming with the user first.
|
|
502
|
-
If there is a next step, include direct quotes from the most recent conversation showing exactly what task you were working on and where you left off. This should be verbatim to ensure there's no drift in task interpretation.
|
|
503
|
-
|
|
504
|
-
Here's an example of how your output should be structured:
|
|
505
|
-
|
|
506
|
-
<example>
|
|
507
|
-
<analysis>
|
|
508
|
-
[Your thought process, ensuring all points are covered thoroughly and accurately]
|
|
509
|
-
</analysis>
|
|
510
|
-
|
|
511
|
-
<summary>
|
|
512
|
-
1. Primary Request and Intent:
|
|
513
|
-
[Detailed description]
|
|
514
|
-
|
|
515
|
-
2. Key Technical Concepts:
|
|
516
|
-
- [Concept 1]
|
|
517
|
-
- [Concept 2]
|
|
518
|
-
- [...]
|
|
519
|
-
|
|
520
|
-
3. Files and Code Sections:
|
|
521
|
-
- [File Name 1]
|
|
522
|
-
- [Summary of why this file is important]
|
|
523
|
-
- [Summary of the changes made to this file, if any]
|
|
524
|
-
- [Important Code Snippet]
|
|
525
|
-
- [File Name 2]
|
|
526
|
-
- [Important Code Snippet]
|
|
527
|
-
- [...]
|
|
528
|
-
|
|
529
|
-
4. Errors and fixes:
|
|
530
|
-
- [Detailed description of error 1]:
|
|
531
|
-
- [How you fixed the error]
|
|
532
|
-
- [User feedback on the error if any]
|
|
533
|
-
- [...]
|
|
534
|
-
|
|
535
|
-
5. Problem Solving:
|
|
536
|
-
[Description of solved problems and ongoing troubleshooting]
|
|
537
|
-
|
|
538
|
-
6. All user messages:
|
|
539
|
-
- [Detailed non tool use user message]
|
|
540
|
-
- [...]
|
|
541
|
-
|
|
542
|
-
7. Pending Tasks:
|
|
543
|
-
- [Task 1]
|
|
544
|
-
- [Task 2]
|
|
545
|
-
- [...]
|
|
546
|
-
|
|
547
|
-
8. Current Work:
|
|
548
|
-
[Precise description of current work]
|
|
549
|
-
|
|
550
|
-
9. Optional Next Step:
|
|
551
|
-
[Optional Next step to take]
|
|
552
|
-
|
|
553
|
-
</summary>
|
|
554
|
-
</example>
|
|
555
|
-
|
|
556
|
-
Please provide your summary based on the conversation so far, following this structure and ensuring precision and thoroughness in your response.
|
|
557
|
-
|
|
558
|
-
There may be additional summarization instructions provided in the included context. If so, remember to follow these instructions when creating the above summary. Examples of instructions include:
|
|
559
|
-
<example>
|
|
560
|
-
## Compact Instructions
|
|
561
|
-
When summarizing the conversation focus on typescript code changes and also remember the mistakes you made and how you fixed them.
|
|
562
|
-
</example>
|
|
563
|
-
|
|
564
|
-
<example>
|
|
565
|
-
# Summary instructions
|
|
566
|
-
When you are using compact - please focus on test output and code changes. Include file reads verbatim.
|
|
567
|
-
</example>`,
|
|
431
|
+
content: COMPRESS_MESSAGES_SYSTEM_PROMPT,
|
|
568
432
|
},
|
|
569
433
|
...messages,
|
|
570
434
|
{
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export declare const isMemoryMessage: (message: string) => boolean;
|
|
2
|
-
export declare const addMemory: (message: string, workdir: string) => Promise<void>;
|
|
3
1
|
export declare const ensureUserMemoryFile: () => Promise<void>;
|
|
4
|
-
export declare const addUserMemory: (message: string) => Promise<void>;
|
|
5
2
|
export declare const getUserMemoryContent: () => Promise<string>;
|
|
6
3
|
export declare const readMemoryFile: (workdir: string) => Promise<string>;
|
|
7
4
|
export declare const getCombinedMemoryContent: (workdir: string) => Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/services/memory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/services/memory.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,oBAAoB,QAAa,OAAO,CAAC,IAAI,CA4BzD,CAAC;AAEF,eAAO,MAAM,oBAAoB,QAAa,OAAO,CAAC,MAAM,CAa3D,CAAC;AAGF,eAAO,MAAM,cAAc,GAAU,SAAS,MAAM,KAAG,OAAO,CAAC,MAAM,CAqBpE,CAAC;AAGF,eAAO,MAAM,wBAAwB,GACnC,SAAS,MAAM,KACd,OAAO,CAAC,MAAM,CAoBhB,CAAC"}
|
package/dist/services/memory.js
CHANGED
|
@@ -3,46 +3,6 @@ import path from "path";
|
|
|
3
3
|
import { USER_MEMORY_FILE, DATA_DIRECTORY } from "../utils/constants.js";
|
|
4
4
|
import { logger } from "../utils/globalLogger.js";
|
|
5
5
|
// Project memory related methods
|
|
6
|
-
export const isMemoryMessage = (message) => {
|
|
7
|
-
return message.trim().startsWith("#");
|
|
8
|
-
};
|
|
9
|
-
export const addMemory = async (message, workdir) => {
|
|
10
|
-
if (!isMemoryMessage(message)) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
try {
|
|
14
|
-
const memoryFilePath = path.join(workdir, "AGENTS.md");
|
|
15
|
-
// Format memory entry, starting with -, no timestamp
|
|
16
|
-
const memoryEntry = `- ${message.substring(1).trim()}\n`;
|
|
17
|
-
// Check if file exists
|
|
18
|
-
let existingContent = "";
|
|
19
|
-
try {
|
|
20
|
-
existingContent = await fs.readFile(memoryFilePath, "utf-8");
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
// File does not exist, create new file
|
|
24
|
-
if (error.code === "ENOENT") {
|
|
25
|
-
logger.info("Memory file does not exist, will create new one", {
|
|
26
|
-
memoryFilePath,
|
|
27
|
-
});
|
|
28
|
-
existingContent =
|
|
29
|
-
"# Memory\n\nThis is the AI assistant's memory file, recording important information and context.\n\n";
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
// Append new memory entry to the end of the file
|
|
36
|
-
const updatedContent = existingContent + memoryEntry;
|
|
37
|
-
// Write file
|
|
38
|
-
await fs.writeFile(memoryFilePath, updatedContent, "utf-8");
|
|
39
|
-
logger.debug(`Memory added to ${memoryFilePath}:`, message);
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
logger.error("Failed to add memory:", error);
|
|
43
|
-
throw new Error(`Failed to add memory: ${error.message}`);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
6
|
// User memory related methods
|
|
47
7
|
export const ensureUserMemoryFile = async () => {
|
|
48
8
|
try {
|
|
@@ -72,25 +32,6 @@ export const ensureUserMemoryFile = async () => {
|
|
|
72
32
|
throw new Error(`Failed to ensure user memory file: ${error.message}`);
|
|
73
33
|
}
|
|
74
34
|
};
|
|
75
|
-
export const addUserMemory = async (message) => {
|
|
76
|
-
try {
|
|
77
|
-
// Ensure user memory file exists
|
|
78
|
-
await ensureUserMemoryFile();
|
|
79
|
-
// Format memory entry, starting with -
|
|
80
|
-
const memoryEntry = `- ${message.substring(1).trim()}\n`;
|
|
81
|
-
// Read existing content
|
|
82
|
-
const existingContent = await fs.readFile(USER_MEMORY_FILE, "utf-8");
|
|
83
|
-
// Append new memory entry to the end of the file
|
|
84
|
-
const updatedContent = existingContent + memoryEntry;
|
|
85
|
-
// Write file
|
|
86
|
-
await fs.writeFile(USER_MEMORY_FILE, updatedContent, "utf-8");
|
|
87
|
-
logger.debug(`User memory added to ${USER_MEMORY_FILE}:`, message);
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
logger.error("Failed to add user memory:", error);
|
|
91
|
-
throw new Error(`Failed to add user memory: ${error.message}`);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
35
|
export const getUserMemoryContent = async () => {
|
|
95
36
|
try {
|
|
96
37
|
await ensureUserMemoryFile();
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
import type { Message } from "../types/index.js";
|
|
18
18
|
export interface SessionData {
|
|
19
19
|
id: string;
|
|
20
|
+
rootSessionId?: string;
|
|
21
|
+
parentSessionId?: string;
|
|
20
22
|
messages: Message[];
|
|
21
23
|
metadata: {
|
|
22
24
|
workdir: string;
|
|
@@ -26,6 +28,8 @@ export interface SessionData {
|
|
|
26
28
|
}
|
|
27
29
|
export interface SessionMetadata {
|
|
28
30
|
id: string;
|
|
31
|
+
rootSessionId?: string;
|
|
32
|
+
parentSessionId?: string;
|
|
29
33
|
sessionType: "main" | "subagent";
|
|
30
34
|
subagentType?: string;
|
|
31
35
|
workdir: string;
|
|
@@ -86,7 +90,7 @@ export declare function createSession(sessionId: string, workdir: string, sessio
|
|
|
86
90
|
* @param workdir - Working directory for the session
|
|
87
91
|
* @param sessionType - Type of session ("main" or "subagent", defaults to "main")
|
|
88
92
|
*/
|
|
89
|
-
export declare function appendMessages(sessionId: string, newMessages: Message[], workdir: string, sessionType?: "main" | "subagent"): Promise<void>;
|
|
93
|
+
export declare function appendMessages(sessionId: string, newMessages: Message[], workdir: string, sessionType?: "main" | "subagent", rootSessionId?: string, parentSessionId?: string): Promise<void>;
|
|
90
94
|
/**
|
|
91
95
|
* Load session data from JSONL file (new approach)
|
|
92
96
|
*
|
|
@@ -171,4 +175,14 @@ export declare function truncateContent(content: string, maxLength?: number): st
|
|
|
171
175
|
* @returns Promise that resolves to session data or undefined
|
|
172
176
|
*/
|
|
173
177
|
export declare function handleSessionRestoration(restoreSessionId?: string, continueLastSession?: boolean, workdir?: string): Promise<SessionData | undefined>;
|
|
178
|
+
/**
|
|
179
|
+
* Load the full message thread by following parentSessionId links
|
|
180
|
+
* @param currentSessionId - The ID of the current session
|
|
181
|
+
* @param workdir - Working directory for the session
|
|
182
|
+
* @returns Promise that resolves to an array of all messages in the thread
|
|
183
|
+
*/
|
|
184
|
+
export declare function loadFullMessageThread(currentSessionId: string, workdir: string): Promise<{
|
|
185
|
+
messages: Message[];
|
|
186
|
+
sessionIds: string[];
|
|
187
|
+
}>;
|
|
174
188
|
//# sourceMappingURL=session.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/services/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAOjD,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,QAAQ,EAAE;QACR,OAAO,EAAE,MAAM,CAAC;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,iBAAiB,EAAE,MAAM,CAAC;KAC3B,CAAC;CACH;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,GAAG,UAAU,CAAC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,IAAI,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CACd,MAAM,EACN,IAAI,CAAC,eAAe,EAAE,IAAI,GAAG,cAAc,CAAC,GAAG;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE,CACxE,CAAC;IACF,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG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