wave-agent-sdk 0.6.1 → 0.6.3
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 +0 -5
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +3 -67
- 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/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +9 -25
- package/dist/managers/backgroundTaskManager.d.ts.map +1 -1
- package/dist/managers/backgroundTaskManager.js +4 -0
- package/dist/managers/messageManager.d.ts +0 -18
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +1 -36
- package/dist/managers/reversionManager.d.ts.map +1 -1
- package/dist/managers/reversionManager.js +23 -2
- package/dist/managers/slashCommandManager.js +1 -1
- package/dist/managers/subagentManager.d.ts +4 -14
- package/dist/managers/subagentManager.d.ts.map +1 -1
- package/dist/managers/subagentManager.js +35 -109
- package/dist/{constants/prompts.d.ts → prompts/index.d.ts} +7 -8
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/{constants/prompts.js → prompts/index.js} +127 -11
- package/dist/services/aiService.js +1 -1
- package/dist/services/taskManager.d.ts +5 -1
- package/dist/services/taskManager.d.ts.map +1 -1
- package/dist/services/taskManager.js +6 -0
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +34 -29
- package/dist/tools/exitPlanMode.js +1 -1
- package/dist/tools/taskManagementTools.d.ts.map +1 -1
- package/dist/tools/taskManagementTools.js +8 -0
- package/dist/tools/taskTool.d.ts.map +1 -1
- package/dist/tools/taskTool.js +32 -2
- package/dist/tools/types.d.ts +2 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/types/messaging.d.ts +1 -11
- package/dist/types/messaging.d.ts.map +1 -1
- package/dist/types/processes.d.ts +5 -0
- package/dist/types/processes.d.ts.map +1 -1
- package/dist/utils/builtinSubagents.d.ts.map +1 -1
- package/dist/utils/builtinSubagents.js +28 -50
- 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 +1 -23
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +0 -49
- package/package.json +1 -1
- package/src/agent.ts +3 -89
- package/src/constants/subagents.ts +4 -0
- package/src/managers/aiManager.ts +9 -25
- package/src/managers/backgroundTaskManager.ts +5 -0
- package/src/managers/messageManager.ts +0 -80
- package/src/managers/reversionManager.ts +26 -2
- package/src/managers/slashCommandManager.ts +1 -1
- package/src/managers/subagentManager.ts +42 -145
- package/src/{constants/prompts.ts → prompts/index.ts} +136 -13
- package/src/services/aiService.ts +1 -1
- package/src/services/taskManager.ts +8 -1
- package/src/tools/bashTool.ts +35 -30
- package/src/tools/exitPlanMode.ts +1 -1
- package/src/tools/taskManagementTools.ts +18 -0
- package/src/tools/taskTool.ts +39 -1
- package/src/tools/types.ts +2 -0
- package/src/types/messaging.ts +0 -12
- package/src/types/processes.ts +5 -0
- package/src/utils/builtinSubagents.ts +41 -51
- package/src/utils/editUtils.ts +2 -6
- package/src/utils/gitUtils.ts +24 -0
- package/src/utils/messageOperations.ts +1 -93
- package/dist/constants/prompts.d.ts.map +0 -1
|
@@ -114,6 +114,15 @@ NOTE that you should not use this tool if there is only one trivial task to do.
|
|
|
114
114
|
|
|
115
115
|
const taskId = await taskManager.createTask(task);
|
|
116
116
|
|
|
117
|
+
if (context.reversionManager && context.messageId) {
|
|
118
|
+
const taskPath = taskManager.getTaskPath(taskId);
|
|
119
|
+
await context.reversionManager.recordSnapshot(
|
|
120
|
+
context.messageId,
|
|
121
|
+
taskPath,
|
|
122
|
+
"create",
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
117
126
|
return {
|
|
118
127
|
success: true,
|
|
119
128
|
content: `Task created with ID: ${taskId}`,
|
|
@@ -324,6 +333,15 @@ Set up task dependencies:
|
|
|
324
333
|
};
|
|
325
334
|
}
|
|
326
335
|
|
|
336
|
+
if (context.reversionManager && context.messageId) {
|
|
337
|
+
const taskPath = taskManager.getTaskPath(taskId);
|
|
338
|
+
await context.reversionManager.recordSnapshot(
|
|
339
|
+
context.messageId,
|
|
340
|
+
taskPath,
|
|
341
|
+
"modify",
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
|
|
327
345
|
const updatedFields: string[] = [];
|
|
328
346
|
|
|
329
347
|
const updatedTask: Task = {
|
package/src/tools/taskTool.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ToolPlugin, ToolResult, ToolContext } from "./types.js";
|
|
2
2
|
import type { SubagentManager } from "../managers/subagentManager.js";
|
|
3
|
+
import { EXPLORE_SUBAGENT_TYPE } from "../constants/subagents.js";
|
|
3
4
|
import { TASK_TOOL_NAME } from "../constants/tools.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -61,7 +62,7 @@ export function createTaskTool(subagentManager: SubagentManager): ToolPlugin {
|
|
|
61
62
|
prompt: () => `
|
|
62
63
|
- When doing file search, prefer to use the ${TASK_TOOL_NAME} tool in order to reduce context usage.
|
|
63
64
|
- You should proactively use the ${TASK_TOOL_NAME} tool with specialized agents when the task at hand matches the agent's description.
|
|
64
|
-
- 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
|
|
65
|
+
- 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_SUBAGENT_TYPE} instead of running search commands directly.`,
|
|
65
66
|
|
|
66
67
|
execute: async (
|
|
67
68
|
args: Record<string, unknown>,
|
|
@@ -120,6 +121,36 @@ export function createTaskTool(subagentManager: SubagentManager): ToolPlugin {
|
|
|
120
121
|
});
|
|
121
122
|
}
|
|
122
123
|
|
|
124
|
+
// Set up callback to update shortResult with tool names, tool count and tokens
|
|
125
|
+
const updateShortResult = () => {
|
|
126
|
+
const messages = instance.messageManager.getMessages();
|
|
127
|
+
const tokens = instance.messageManager.getlatestTotalTokens();
|
|
128
|
+
const lastTools = instance.lastTools;
|
|
129
|
+
|
|
130
|
+
// Count tool blocks in messages
|
|
131
|
+
let toolCount = 0;
|
|
132
|
+
messages.forEach((msg) => {
|
|
133
|
+
msg.blocks.forEach((block) => {
|
|
134
|
+
if (block.type === "tool") {
|
|
135
|
+
toolCount++;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
let shortResult = "";
|
|
141
|
+
if (lastTools.length > 0) {
|
|
142
|
+
shortResult += `${lastTools.join(", ")} `;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
shortResult += `(${toolCount} tools`;
|
|
146
|
+
if (tokens > 0) {
|
|
147
|
+
shortResult += ` | ${tokens.toLocaleString()} tokens`;
|
|
148
|
+
}
|
|
149
|
+
shortResult += ")";
|
|
150
|
+
|
|
151
|
+
context.onShortResultUpdate?.(shortResult);
|
|
152
|
+
};
|
|
153
|
+
|
|
123
154
|
// Create subagent instance and execute task
|
|
124
155
|
const instance = await subagentManager.createInstance(
|
|
125
156
|
configuration,
|
|
@@ -129,8 +160,12 @@ export function createTaskTool(subagentManager: SubagentManager): ToolPlugin {
|
|
|
129
160
|
subagent_type,
|
|
130
161
|
},
|
|
131
162
|
run_in_background,
|
|
163
|
+
updateShortResult,
|
|
132
164
|
);
|
|
133
165
|
|
|
166
|
+
// Initial update
|
|
167
|
+
updateShortResult();
|
|
168
|
+
|
|
134
169
|
let isBackgrounded = false;
|
|
135
170
|
|
|
136
171
|
// Register for backgrounding if not already in background
|
|
@@ -171,6 +206,9 @@ export function createTaskTool(subagentManager: SubagentManager): ToolPlugin {
|
|
|
171
206
|
});
|
|
172
207
|
}
|
|
173
208
|
|
|
209
|
+
// Cleanup subagent instance after task completion
|
|
210
|
+
subagentManager.cleanupInstance(instance.subagentId);
|
|
211
|
+
|
|
174
212
|
return resolve({
|
|
175
213
|
success: true,
|
|
176
214
|
content: result,
|
package/src/tools/types.ts
CHANGED
|
@@ -67,4 +67,6 @@ export interface ToolContext {
|
|
|
67
67
|
taskManager: import("../services/taskManager.js").TaskManager;
|
|
68
68
|
/** Current session ID */
|
|
69
69
|
sessionId?: string;
|
|
70
|
+
/** Callback to update the short result of the current tool block */
|
|
71
|
+
onShortResultUpdate?: (shortResult: string) => void;
|
|
70
72
|
}
|
package/src/types/messaging.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { Usage } from "./core.js";
|
|
7
|
-
import type { SubagentConfiguration } from "../utils/subagentParser.js";
|
|
8
7
|
|
|
9
8
|
export enum MessageSource {
|
|
10
9
|
USER = "user",
|
|
@@ -26,7 +25,6 @@ export type MessageBlock =
|
|
|
26
25
|
| ImageBlock
|
|
27
26
|
| CommandOutputBlock
|
|
28
27
|
| CompressBlock
|
|
29
|
-
| SubagentBlock
|
|
30
28
|
| ReasoningBlock
|
|
31
29
|
| FileHistoryBlock;
|
|
32
30
|
|
|
@@ -88,16 +86,6 @@ export interface CompressBlock {
|
|
|
88
86
|
sessionId: string;
|
|
89
87
|
}
|
|
90
88
|
|
|
91
|
-
export interface SubagentBlock {
|
|
92
|
-
type: "subagent";
|
|
93
|
-
subagentId: string;
|
|
94
|
-
subagentName: string;
|
|
95
|
-
status: "active" | "completed" | "error" | "aborted";
|
|
96
|
-
sessionId: string;
|
|
97
|
-
configuration: SubagentConfiguration;
|
|
98
|
-
runInBackground?: boolean;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
89
|
export interface ReasoningBlock {
|
|
102
90
|
type: "reasoning";
|
|
103
91
|
content: string;
|
package/src/types/processes.ts
CHANGED
|
@@ -29,6 +29,11 @@ export interface BackgroundTaskBase {
|
|
|
29
29
|
* This allows tasks to define their own cleanup/abortion logic.
|
|
30
30
|
*/
|
|
31
31
|
onStop?: () => void | Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Optional subagent ID associated with this task.
|
|
34
|
+
* Used for cleanup when the task is stopped.
|
|
35
|
+
*/
|
|
36
|
+
subagentId?: string;
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
export interface BackgroundShell extends BackgroundTaskBase {
|
|
@@ -1,9 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BASH_SUBAGENT_TYPE,
|
|
3
|
+
EXPLORE_SUBAGENT_TYPE,
|
|
4
|
+
PLAN_SUBAGENT_TYPE,
|
|
5
|
+
GENERAL_PURPOSE_SUBAGENT_TYPE,
|
|
6
|
+
} from "../constants/subagents.js";
|
|
1
7
|
import {
|
|
2
8
|
BASH_SUBAGENT_SYSTEM_PROMPT,
|
|
3
9
|
GENERAL_PURPOSE_SYSTEM_PROMPT,
|
|
4
10
|
PLAN_SUBAGENT_SYSTEM_PROMPT,
|
|
5
|
-
|
|
6
|
-
|
|
11
|
+
EXPLORE_SUBAGENT_SYSTEM_PROMPT,
|
|
12
|
+
} from "../prompts/index.js";
|
|
13
|
+
import {
|
|
14
|
+
BASH_TOOL_NAME,
|
|
15
|
+
GLOB_TOOL_NAME,
|
|
16
|
+
GREP_TOOL_NAME,
|
|
17
|
+
READ_TOOL_NAME,
|
|
18
|
+
LS_TOOL_NAME,
|
|
19
|
+
LSP_TOOL_NAME,
|
|
20
|
+
} from "../constants/tools.js";
|
|
7
21
|
import type { SubagentConfiguration } from "./subagentParser.js";
|
|
8
22
|
|
|
9
23
|
/**
|
|
@@ -26,13 +40,13 @@ export function getBuiltinSubagents(): SubagentConfiguration[] {
|
|
|
26
40
|
*/
|
|
27
41
|
function createBashSubagent(): SubagentConfiguration {
|
|
28
42
|
return {
|
|
29
|
-
name:
|
|
43
|
+
name: BASH_SUBAGENT_TYPE,
|
|
30
44
|
description:
|
|
31
45
|
"Command execution specialist for running bash commands. Use this for git operations, command execution, and other terminal tasks.",
|
|
32
46
|
systemPrompt: BASH_SUBAGENT_SYSTEM_PROMPT,
|
|
33
47
|
tools: [BASH_TOOL_NAME],
|
|
34
48
|
model: "inherit",
|
|
35
|
-
filePath:
|
|
49
|
+
filePath: `<builtin:${BASH_SUBAGENT_TYPE}>`,
|
|
36
50
|
scope: "builtin",
|
|
37
51
|
priority: 3,
|
|
38
52
|
};
|
|
@@ -44,11 +58,11 @@ function createBashSubagent(): SubagentConfiguration {
|
|
|
44
58
|
*/
|
|
45
59
|
function createGeneralPurposeSubagent(): SubagentConfiguration {
|
|
46
60
|
return {
|
|
47
|
-
name:
|
|
61
|
+
name: GENERAL_PURPOSE_SUBAGENT_TYPE,
|
|
48
62
|
description:
|
|
49
63
|
"General-purpose agent for researching complex questions, searching for code, and executing multi-step tasks. When you are searching for a keyword or file and are not confident that you will find the right match in the first few tries use this agent to perform the search for you.",
|
|
50
64
|
systemPrompt: GENERAL_PURPOSE_SYSTEM_PROMPT,
|
|
51
|
-
filePath:
|
|
65
|
+
filePath: `<builtin:${GENERAL_PURPOSE_SUBAGENT_TYPE}>`,
|
|
52
66
|
scope: "builtin",
|
|
53
67
|
priority: 3,
|
|
54
68
|
};
|
|
@@ -59,55 +73,24 @@ function createGeneralPurposeSubagent(): SubagentConfiguration {
|
|
|
59
73
|
* Specialized for codebase exploration and file search tasks
|
|
60
74
|
*/
|
|
61
75
|
function createExploreSubagent(): SubagentConfiguration {
|
|
62
|
-
const systemPrompt = `You are a file search specialist. You excel at thoroughly navigating and exploring codebases.
|
|
63
|
-
|
|
64
|
-
=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===
|
|
65
|
-
This is a READ-ONLY exploration task. You are STRICTLY PROHIBITED from:
|
|
66
|
-
- Creating new files (no Write, touch, or file creation of any kind)
|
|
67
|
-
- Modifying existing files (no Edit operations)
|
|
68
|
-
- Deleting files (no rm or deletion)
|
|
69
|
-
- Moving or copying files (no mv or cp)
|
|
70
|
-
- Creating temporary files anywhere, including /tmp
|
|
71
|
-
- Using redirect operators (>, >>, |) or heredocs to write to files
|
|
72
|
-
- Running ANY commands that change system state
|
|
73
|
-
|
|
74
|
-
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.
|
|
75
|
-
|
|
76
|
-
Your strengths:
|
|
77
|
-
- Rapidly finding files using glob patterns
|
|
78
|
-
- Searching code and text with powerful regex patterns
|
|
79
|
-
- Reading and analyzing file contents
|
|
80
|
-
- Using Language Server Protocol (LSP) for deep code intelligence (definitions, references, etc.)
|
|
81
|
-
|
|
82
|
-
Guidelines:
|
|
83
|
-
- Use Glob for broad file pattern matching
|
|
84
|
-
- Use Grep for searching file contents with regex
|
|
85
|
-
- Use Read when you know the specific file path you need to read
|
|
86
|
-
- Use LSP for code intelligence features like finding definitions, references, implementations, and symbols. This is especially useful for understanding complex code relationships.
|
|
87
|
-
- Use Bash ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)
|
|
88
|
-
- NEVER use Bash for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification
|
|
89
|
-
- Adapt your search approach based on the thoroughness level specified by the caller
|
|
90
|
-
- Return file paths as absolute paths in your final response
|
|
91
|
-
- For clear communication, avoid using emojis
|
|
92
|
-
- Communicate your final report directly as a regular message - do NOT attempt to create files
|
|
93
|
-
|
|
94
|
-
NOTE: You are meant to be a fast agent that returns output as quickly as possible. In order to achieve this you must:
|
|
95
|
-
- Make efficient use of the tools that you have at your disposal: be smart about how you search for files and implementations
|
|
96
|
-
- Wherever possible you should try to spawn multiple parallel tool calls for grepping and reading files
|
|
97
|
-
|
|
98
|
-
Complete the user's search request efficiently and report your findings clearly.`;
|
|
99
|
-
|
|
100
76
|
// Define allowed tools for read-only operations
|
|
101
|
-
const allowedTools = [
|
|
77
|
+
const allowedTools = [
|
|
78
|
+
GLOB_TOOL_NAME,
|
|
79
|
+
GREP_TOOL_NAME,
|
|
80
|
+
READ_TOOL_NAME,
|
|
81
|
+
BASH_TOOL_NAME,
|
|
82
|
+
LS_TOOL_NAME,
|
|
83
|
+
LSP_TOOL_NAME,
|
|
84
|
+
];
|
|
102
85
|
|
|
103
86
|
return {
|
|
104
|
-
name:
|
|
87
|
+
name: EXPLORE_SUBAGENT_TYPE,
|
|
105
88
|
description:
|
|
106
89
|
'Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. "src/components/**/*.tsx"), search code for keywords (eg. "API endpoints"), or answer questions about the codebase (eg. "how do API endpoints work?"). When calling this agent, specify the desired thoroughness level: "quick" for basic searches, "medium" for moderate exploration, or "very thorough" for comprehensive analysis across multiple locations and naming conventions.',
|
|
107
|
-
systemPrompt,
|
|
90
|
+
systemPrompt: EXPLORE_SUBAGENT_SYSTEM_PROMPT,
|
|
108
91
|
tools: allowedTools,
|
|
109
92
|
model: "fastModel", // Special value that will use parent's fastModel
|
|
110
|
-
filePath:
|
|
93
|
+
filePath: `<builtin:${EXPLORE_SUBAGENT_TYPE}>`,
|
|
111
94
|
scope: "builtin",
|
|
112
95
|
priority: 3, // Lowest priority - can be overridden by user configs
|
|
113
96
|
};
|
|
@@ -119,16 +102,23 @@ Complete the user's search request efficiently and report your findings clearly.
|
|
|
119
102
|
*/
|
|
120
103
|
function createPlanSubagent(): SubagentConfiguration {
|
|
121
104
|
// Define allowed tools for read-only operations
|
|
122
|
-
const allowedTools = [
|
|
105
|
+
const allowedTools = [
|
|
106
|
+
GLOB_TOOL_NAME,
|
|
107
|
+
GREP_TOOL_NAME,
|
|
108
|
+
READ_TOOL_NAME,
|
|
109
|
+
BASH_TOOL_NAME,
|
|
110
|
+
LS_TOOL_NAME,
|
|
111
|
+
LSP_TOOL_NAME,
|
|
112
|
+
];
|
|
123
113
|
|
|
124
114
|
return {
|
|
125
|
-
name:
|
|
115
|
+
name: PLAN_SUBAGENT_TYPE,
|
|
126
116
|
description:
|
|
127
117
|
"Software architect agent for designing implementation plans. Use this when you need to plan the implementation strategy for a task. Returns step-by-step plans, identifies critical files, and considers architectural trade-offs.",
|
|
128
118
|
systemPrompt: PLAN_SUBAGENT_SYSTEM_PROMPT,
|
|
129
119
|
tools: allowedTools,
|
|
130
120
|
model: "inherit", // Uses parent agent's model
|
|
131
|
-
filePath:
|
|
121
|
+
filePath: `<builtin:${PLAN_SUBAGENT_TYPE}>`,
|
|
132
122
|
scope: "builtin",
|
|
133
123
|
priority: 3, // Lowest priority - can be overridden by user configs
|
|
134
124
|
};
|
package/src/utils/editUtils.ts
CHANGED
|
@@ -77,12 +77,8 @@ export function analyzeEditMismatch(
|
|
|
77
77
|
if (actualLine === expectedLine) {
|
|
78
78
|
reportLines.push(`${lineNum.toString().padStart(4)} | ${actualLine}`);
|
|
79
79
|
} else {
|
|
80
|
-
reportLines.push(
|
|
81
|
-
|
|
82
|
-
);
|
|
83
|
-
reportLines.push(
|
|
84
|
-
`${lineNum.toString().padStart(4)} | + ${actualLine} (actual)`,
|
|
85
|
-
);
|
|
80
|
+
reportLines.push(`${lineNum.toString().padStart(4)} | - ${expectedLine}`);
|
|
81
|
+
reportLines.push(`${lineNum.toString().padStart(4)} | + ${actualLine}`);
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
84
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import * as fsSync from "node:fs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Check if a directory is a git repository
|
|
6
|
+
* @param dirPath Directory path
|
|
7
|
+
* @returns "Yes" if it's a git repository, "No" otherwise
|
|
8
|
+
*/
|
|
9
|
+
export function isGitRepository(dirPath: string): string {
|
|
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
|
+
} catch {
|
|
22
|
+
return "No";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Message, Usage } from "../types/index.js";
|
|
2
2
|
import { MessageSource } from "../types/index.js";
|
|
3
|
-
import type { SubagentConfiguration } from "./subagentParser.js";
|
|
4
3
|
import { readFileSync } from "fs";
|
|
5
4
|
import { extname } from "path";
|
|
6
5
|
import { ChatCompletionMessageFunctionToolCall } from "openai/resources.js";
|
|
@@ -22,7 +21,7 @@ export interface AddUserMessageParams extends UserMessageParams {
|
|
|
22
21
|
export interface UpdateToolBlockParams {
|
|
23
22
|
messages: Message[];
|
|
24
23
|
id: string;
|
|
25
|
-
parameters
|
|
24
|
+
parameters?: string;
|
|
26
25
|
result?: string;
|
|
27
26
|
success?: boolean;
|
|
28
27
|
error?: string;
|
|
@@ -365,97 +364,6 @@ export const completeCommandInMessage = ({
|
|
|
365
364
|
return newMessages;
|
|
366
365
|
};
|
|
367
366
|
|
|
368
|
-
// Subagent block message operations
|
|
369
|
-
export interface AddSubagentBlockParams {
|
|
370
|
-
messages: Message[];
|
|
371
|
-
subagentId: string;
|
|
372
|
-
subagentName: string;
|
|
373
|
-
status: "active" | "completed" | "error" | "aborted";
|
|
374
|
-
sessionId: string;
|
|
375
|
-
configuration: SubagentConfiguration;
|
|
376
|
-
runInBackground?: boolean;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
export interface UpdateSubagentBlockParams {
|
|
380
|
-
messages: Message[];
|
|
381
|
-
subagentId: string;
|
|
382
|
-
status: "active" | "completed" | "error" | "aborted";
|
|
383
|
-
sessionId?: string;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
export const addSubagentBlockToMessage = ({
|
|
387
|
-
messages,
|
|
388
|
-
subagentId,
|
|
389
|
-
subagentName,
|
|
390
|
-
status,
|
|
391
|
-
sessionId,
|
|
392
|
-
configuration,
|
|
393
|
-
runInBackground,
|
|
394
|
-
}: AddSubagentBlockParams): Message[] => {
|
|
395
|
-
const newMessages = [...messages];
|
|
396
|
-
|
|
397
|
-
// Find the last assistant message or create one
|
|
398
|
-
let lastAssistantMessage = newMessages[newMessages.length - 1];
|
|
399
|
-
|
|
400
|
-
if (!lastAssistantMessage || lastAssistantMessage.role !== "assistant") {
|
|
401
|
-
// Create new assistant message if the last message is not from assistant
|
|
402
|
-
lastAssistantMessage = {
|
|
403
|
-
id: `msg-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
|
|
404
|
-
role: "assistant",
|
|
405
|
-
blocks: [],
|
|
406
|
-
};
|
|
407
|
-
newMessages.push(lastAssistantMessage);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// Add subagent block
|
|
411
|
-
lastAssistantMessage.blocks.push({
|
|
412
|
-
type: "subagent",
|
|
413
|
-
subagentId,
|
|
414
|
-
subagentName,
|
|
415
|
-
status,
|
|
416
|
-
sessionId,
|
|
417
|
-
configuration,
|
|
418
|
-
runInBackground,
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
return newMessages;
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
export const updateSubagentBlockInMessage = (
|
|
425
|
-
messages: Message[],
|
|
426
|
-
subagentId: string,
|
|
427
|
-
updates: Partial<{
|
|
428
|
-
status: "active" | "completed" | "error" | "aborted";
|
|
429
|
-
sessionId: string;
|
|
430
|
-
runInBackground: boolean;
|
|
431
|
-
}>,
|
|
432
|
-
): Message[] => {
|
|
433
|
-
const newMessages = [...messages];
|
|
434
|
-
|
|
435
|
-
// Find and update the subagent block
|
|
436
|
-
for (let i = newMessages.length - 1; i >= 0; i--) {
|
|
437
|
-
const message = newMessages[i];
|
|
438
|
-
if (message.role === "assistant") {
|
|
439
|
-
for (const block of message.blocks) {
|
|
440
|
-
if (block.type === "subagent" && block.subagentId === subagentId) {
|
|
441
|
-
if (updates.status !== undefined) {
|
|
442
|
-
block.status = updates.status;
|
|
443
|
-
}
|
|
444
|
-
if (updates.sessionId !== undefined) {
|
|
445
|
-
block.sessionId = updates.sessionId;
|
|
446
|
-
}
|
|
447
|
-
if (updates.runInBackground !== undefined) {
|
|
448
|
-
block.runInBackground = updates.runInBackground;
|
|
449
|
-
}
|
|
450
|
-
return newMessages;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
return newMessages;
|
|
457
|
-
};
|
|
458
|
-
|
|
459
367
|
/**
|
|
460
368
|
* Removes the last user message from the messages array
|
|
461
369
|
* Used for hook error handling when the user prompt needs to be erased
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/constants/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAe/C,eAAO,MAAM,kBAAkB,ksFAe8G,CAAC;AAE9I,eAAO,MAAM,sBAAsB,moBAImH,CAAC;AAEvJ,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,OAAO,GAClB,MAAM,CAWR;AAED,eAAO,MAAM,qBAAqB,ksFAAqB,CAAC;AAExD,eAAO,MAAM,2BAA2B,igBAWO,CAAC;AAEhD,eAAO,MAAM,6BAA6B,izCAeK,CAAC;AAEhD,eAAO,MAAM,2BAA2B,25EAiDyG,CAAC;AAElJ,eAAO,MAAM,WAAW,kkDAoBjB,CAAC;AAER,eAAO,MAAM,+BAA+B,20CAsBG,CAAC;AAEhD,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,KAAK,EAAE,UAAU,EAAE,EACnB,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE;QACT,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,OAAO,CAAC;KACrB,CAAC;CACE,GACL,MAAM,CA8CR"}
|