@polka-codes/core 0.4.3 → 0.4.4
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/index.js +423 -124
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2877,6 +2877,7 @@ class AiServiceBase {
|
|
|
2877
2877
|
totalCost: 0
|
|
2878
2878
|
};
|
|
2879
2879
|
let resp = "";
|
|
2880
|
+
let reasoning = "";
|
|
2880
2881
|
for await (const chunk of stream) {
|
|
2881
2882
|
switch (chunk.type) {
|
|
2882
2883
|
case "usage":
|
|
@@ -2889,10 +2890,13 @@ class AiServiceBase {
|
|
|
2889
2890
|
case "text":
|
|
2890
2891
|
resp += chunk.text;
|
|
2891
2892
|
break;
|
|
2893
|
+
case "reasoning":
|
|
2894
|
+
reasoning += chunk.text;
|
|
2892
2895
|
}
|
|
2893
2896
|
}
|
|
2894
2897
|
return {
|
|
2895
2898
|
response: resp,
|
|
2899
|
+
reasoning,
|
|
2896
2900
|
usage
|
|
2897
2901
|
};
|
|
2898
2902
|
}
|
|
@@ -7884,6 +7888,12 @@ class DeepSeekService extends AiServiceBase {
|
|
|
7884
7888
|
});
|
|
7885
7889
|
for await (const chunk of stream) {
|
|
7886
7890
|
const delta = chunk.choices[0]?.delta;
|
|
7891
|
+
if (delta?.reasoning_content) {
|
|
7892
|
+
yield {
|
|
7893
|
+
type: "reasoning",
|
|
7894
|
+
text: delta.reasoning_content
|
|
7895
|
+
};
|
|
7896
|
+
}
|
|
7887
7897
|
if (delta?.content) {
|
|
7888
7898
|
yield {
|
|
7889
7899
|
type: "text",
|
|
@@ -7964,6 +7974,15 @@ var createService = (provider, options) => {
|
|
|
7964
7974
|
}
|
|
7965
7975
|
};
|
|
7966
7976
|
// src/tool.ts
|
|
7977
|
+
var ToolResponseType;
|
|
7978
|
+
((ToolResponseType2) => {
|
|
7979
|
+
ToolResponseType2["Reply"] = "Reply";
|
|
7980
|
+
ToolResponseType2["Exit"] = "Exit";
|
|
7981
|
+
ToolResponseType2["Invalid"] = "Invalid";
|
|
7982
|
+
ToolResponseType2["Error"] = "Error";
|
|
7983
|
+
ToolResponseType2["Interrupted"] = "Interrupted";
|
|
7984
|
+
ToolResponseType2["HandOver"] = "HandOver";
|
|
7985
|
+
})(ToolResponseType ||= {});
|
|
7967
7986
|
var getAvailableTools = (provider, allTools) => {
|
|
7968
7987
|
return allTools.filter((tool) => tool.isAvailable(provider));
|
|
7969
7988
|
};
|
|
@@ -8116,6 +8135,95 @@ By adhering to these guidelines:
|
|
|
8116
8135
|
- You confirm each step’s results before proceeding.
|
|
8117
8136
|
- You provide only the necessary information in user-facing replies to prevent re-interpretation as new commands.`;
|
|
8118
8137
|
};
|
|
8138
|
+
var agentsPrompt = (agents, name) => `
|
|
8139
|
+
====
|
|
8140
|
+
|
|
8141
|
+
AVAILABLE AGENTS
|
|
8142
|
+
|
|
8143
|
+
The following agents are available for task handover:
|
|
8144
|
+
${agents.map((agent) => `
|
|
8145
|
+
- **${agent.name}**
|
|
8146
|
+
- Responsibilities:
|
|
8147
|
+
${agent.responsibilities.map((resp) => ` - ${resp}`).join(`
|
|
8148
|
+
`)}`).join(`
|
|
8149
|
+
`)}
|
|
8150
|
+
|
|
8151
|
+
- **Current Agent Role**
|
|
8152
|
+
You are currently acting as **${name}**. If you identify the task is beyond your current scope, use the handover tool to transition to the other agent. Include sufficient context so the new agent can seamlessly continue the work.
|
|
8153
|
+
`;
|
|
8154
|
+
var capabilities = (toolNamePrefix) => `
|
|
8155
|
+
====
|
|
8156
|
+
|
|
8157
|
+
CAPABILITIES
|
|
8158
|
+
|
|
8159
|
+
- You have access to a range of tools to aid you in your work. These tools help you effectively accomplish a wide range of tasks, such as writing code, making edits or improvements to existing files, understanding the current state of a project, performing system operations, and much more.
|
|
8160
|
+
- When the user initially gives you a task, a recursive list of all filepaths in the current working directory will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further.
|
|
8161
|
+
- You can use ${toolNamePrefix}search_files to perform regex searches across files in a specified directory, outputting context-rich results that include surrounding lines. This is particularly useful for understanding code patterns, finding specific implementations, or identifying areas that need refactoring.
|
|
8162
|
+
- You can use the ${toolNamePrefix}list_code_definition_names tool to get an overview of source code definitions for all files at the top level of a specified directory. This can be particularly useful when you need to understand the broader context and relationships between certain parts of the code. You may need to call this tool multiple times to understand various parts of the codebase related to the task.
|
|
8163
|
+
\t- For example, when asked to make edits or improvements you might analyze the file structure in the initial environment_details to get an overview of the project, then use ${toolNamePrefix}list_code_definition_names to get further insight using source code definitions for files located in relevant directories, then ${toolNamePrefix}read_file to examine the contents of relevant files, analyze the code and suggest improvements or make necessary edits, then use the ${toolNamePrefix}replace_in_file tool to implement changes. If you refactored code that could affect other parts of the codebase, you could use ${toolNamePrefix}search_files to ensure you update other files as needed.
|
|
8164
|
+
- You can use the ${toolNamePrefix}execute_command tool to run commands on the user's computer whenever you feel it can help accomplish the user's task. When you need to execute a CLI command, you must provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, since they are more flexible and easier to run. Interactive and long-running commands are allowed, since the commands are run in the user's VSCode terminal. The user may keep commands running in the background and you will be kept updated on their status along the way. Each command you execute is run in a new terminal instance.`;
|
|
8165
|
+
var systemInformation = (info) => `
|
|
8166
|
+
====
|
|
8167
|
+
|
|
8168
|
+
SYSTEM INFORMATION
|
|
8169
|
+
|
|
8170
|
+
Operating System: ${info.os}`;
|
|
8171
|
+
var interactiveMode = (interactive) => {
|
|
8172
|
+
if (interactive) {
|
|
8173
|
+
return `
|
|
8174
|
+
====
|
|
8175
|
+
|
|
8176
|
+
INTERACTIVE MODE
|
|
8177
|
+
|
|
8178
|
+
You are in interactive mode. This means you may ask user questions to gather additional information to complete the task.
|
|
8179
|
+
`;
|
|
8180
|
+
}
|
|
8181
|
+
return `
|
|
8182
|
+
====
|
|
8183
|
+
|
|
8184
|
+
NON-INTERACTIVE MODE
|
|
8185
|
+
|
|
8186
|
+
You are in non-interactive mode. This means you will not be able to ask user questions to gather additional information to complete the task. You should try to use available tools to accomplish the task. If unable to precede further, you may try to end the task and provide a reason.
|
|
8187
|
+
`;
|
|
8188
|
+
};
|
|
8189
|
+
var customInstructions = (customInstructions2) => {
|
|
8190
|
+
const joined = customInstructions2.join(`
|
|
8191
|
+
`);
|
|
8192
|
+
if (joined.trim() === "") {
|
|
8193
|
+
return "";
|
|
8194
|
+
}
|
|
8195
|
+
return `
|
|
8196
|
+
====
|
|
8197
|
+
|
|
8198
|
+
USER'S CUSTOM INSTRUCTIONS
|
|
8199
|
+
|
|
8200
|
+
The following additional instructions are provided by the user, and should be followed to the best of your ability without interfering with the TOOL USE guidelines.
|
|
8201
|
+
|
|
8202
|
+
${joined}`;
|
|
8203
|
+
};
|
|
8204
|
+
var customScripts = (commands) => {
|
|
8205
|
+
const joined = Object.entries(commands).map(([name, command]) => {
|
|
8206
|
+
if (typeof command === "string") {
|
|
8207
|
+
return `- ${name}
|
|
8208
|
+
- Command: \`${command}\``;
|
|
8209
|
+
}
|
|
8210
|
+
return `- ${name}
|
|
8211
|
+
- Command: \`${command.command}\`
|
|
8212
|
+
- Description: ${command.description}`;
|
|
8213
|
+
}).join(`
|
|
8214
|
+
`);
|
|
8215
|
+
if (joined.trim() === "") {
|
|
8216
|
+
return "";
|
|
8217
|
+
}
|
|
8218
|
+
return `
|
|
8219
|
+
====
|
|
8220
|
+
|
|
8221
|
+
USER'S CUSTOM COMMANDS
|
|
8222
|
+
|
|
8223
|
+
The following additional commands are provided by the user, and should be followed to the best of your ability without interfering with the TOOL USE guidelines.
|
|
8224
|
+
|
|
8225
|
+
${joined}`;
|
|
8226
|
+
};
|
|
8119
8227
|
var responsePrompts = {
|
|
8120
8228
|
errorInvokeTool: (tool, error) => `An error occurred while invoking the tool "${tool}": ${error}`,
|
|
8121
8229
|
requireUseTool: "Error: You must use a tool before proceeding",
|
|
@@ -8128,20 +8236,34 @@ ${result}
|
|
|
8128
8236
|
};
|
|
8129
8237
|
|
|
8130
8238
|
// src/Agent/AgentBase.ts
|
|
8131
|
-
var
|
|
8132
|
-
((
|
|
8133
|
-
|
|
8134
|
-
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
|
|
8239
|
+
var TaskEventKind;
|
|
8240
|
+
((TaskEventKind2) => {
|
|
8241
|
+
TaskEventKind2["StartRequest"] = "StartRequest";
|
|
8242
|
+
TaskEventKind2["EndRequest"] = "EndRequest";
|
|
8243
|
+
TaskEventKind2["Usage"] = "Usage";
|
|
8244
|
+
TaskEventKind2["Text"] = "Text";
|
|
8245
|
+
TaskEventKind2["Reasoning"] = "Reasoning";
|
|
8246
|
+
TaskEventKind2["ToolUse"] = "ToolUse";
|
|
8247
|
+
TaskEventKind2["ToolReply"] = "ToolReply";
|
|
8248
|
+
TaskEventKind2["ToolInvalid"] = "ToolInvalid";
|
|
8249
|
+
TaskEventKind2["ToolError"] = "ToolError";
|
|
8250
|
+
TaskEventKind2["ToolInterrupted"] = "ToolInterrupted";
|
|
8251
|
+
TaskEventKind2["ToolHandOver"] = "ToolHandOver";
|
|
8252
|
+
TaskEventKind2["MaxIterationsReached"] = "MaxIterationsReached";
|
|
8253
|
+
TaskEventKind2["EndTask"] = "EndTask";
|
|
8254
|
+
})(TaskEventKind ||= {});
|
|
8138
8255
|
|
|
8139
8256
|
class AgentBase {
|
|
8140
8257
|
ai;
|
|
8141
8258
|
config;
|
|
8142
8259
|
handlers;
|
|
8143
|
-
constructor(ai, config) {
|
|
8260
|
+
constructor(name, ai, config) {
|
|
8144
8261
|
this.ai = ai;
|
|
8262
|
+
if (config.agents && Object.keys(config.agents).length > 0) {
|
|
8263
|
+
const agents = agentsPrompt(config.agents, name);
|
|
8264
|
+
config.systemPrompt += `
|
|
8265
|
+
${agents}`;
|
|
8266
|
+
}
|
|
8145
8267
|
this.config = config;
|
|
8146
8268
|
const handlers = {};
|
|
8147
8269
|
for (const tool of config.tools) {
|
|
@@ -8178,24 +8300,26 @@ class AgentBase {
|
|
|
8178
8300
|
let nextRequest = userMessage;
|
|
8179
8301
|
while (nextRequest) {
|
|
8180
8302
|
if (taskInfo.messages.length > taskInfo.options.maxIterations * 2) {
|
|
8181
|
-
callback({ kind: "
|
|
8182
|
-
return ["MaxIterations"
|
|
8303
|
+
callback({ kind: "MaxIterationsReached" /* MaxIterationsReached */, info: taskInfo });
|
|
8304
|
+
return ["MaxIterations", taskInfo];
|
|
8183
8305
|
}
|
|
8184
8306
|
const response = await this.#request(taskInfo, nextRequest, callback);
|
|
8185
8307
|
const [newMessage, exitReason] = await this.#handleResponse(taskInfo, response, callback);
|
|
8186
8308
|
if (exitReason) {
|
|
8309
|
+
callback({ kind: "EndTask" /* EndTask */, info: taskInfo });
|
|
8187
8310
|
return [exitReason, taskInfo];
|
|
8188
8311
|
}
|
|
8189
8312
|
nextRequest = newMessage;
|
|
8190
8313
|
}
|
|
8191
|
-
callback({ kind: "
|
|
8192
|
-
return ["
|
|
8314
|
+
callback({ kind: "EndTask" /* EndTask */, info: taskInfo });
|
|
8315
|
+
return [{ type: "Exit" /* Exit */, message: "Task completed successfully" }, taskInfo];
|
|
8193
8316
|
}
|
|
8194
|
-
async continueTask(userMessage, taskInfo, callback) {
|
|
8317
|
+
async continueTask(userMessage, taskInfo, callback = () => {
|
|
8318
|
+
}) {
|
|
8195
8319
|
return await this.#processLoop(userMessage, taskInfo, callback);
|
|
8196
8320
|
}
|
|
8197
8321
|
async#request(info, userMessage, callback) {
|
|
8198
|
-
await callback({ kind: "
|
|
8322
|
+
await callback({ kind: "StartRequest" /* StartRequest */, info, userMessage });
|
|
8199
8323
|
info.messages.push({
|
|
8200
8324
|
role: "user",
|
|
8201
8325
|
content: userMessage
|
|
@@ -8210,11 +8334,14 @@ class AgentBase {
|
|
|
8210
8334
|
info.cacheWriteTokens = chunk.cacheWriteTokens ?? 0;
|
|
8211
8335
|
info.cacheReadTokens = chunk.cacheReadTokens ?? 0;
|
|
8212
8336
|
info.totalCost = chunk.totalCost;
|
|
8213
|
-
await callback({ kind: "
|
|
8337
|
+
await callback({ kind: "Usage" /* Usage */, info });
|
|
8214
8338
|
break;
|
|
8215
8339
|
case "text":
|
|
8216
8340
|
currentAssistantMessage += chunk.text;
|
|
8217
|
-
await callback({ kind: "
|
|
8341
|
+
await callback({ kind: "Text" /* Text */, info, newText: chunk.text });
|
|
8342
|
+
break;
|
|
8343
|
+
case "reasoning":
|
|
8344
|
+
await callback({ kind: "Reasoning" /* Reasoning */, info, newText: chunk.text });
|
|
8218
8345
|
break;
|
|
8219
8346
|
}
|
|
8220
8347
|
}
|
|
@@ -8226,41 +8353,53 @@ class AgentBase {
|
|
|
8226
8353
|
content: currentAssistantMessage
|
|
8227
8354
|
});
|
|
8228
8355
|
const ret = parseAssistantMessage(currentAssistantMessage, this.config.tools, this.config.toolNamePrefix);
|
|
8229
|
-
await callback({ kind: "
|
|
8356
|
+
await callback({ kind: "EndRequest" /* EndRequest */, info });
|
|
8230
8357
|
return ret;
|
|
8231
8358
|
}
|
|
8232
8359
|
async#handleResponse(info, response, callback) {
|
|
8233
8360
|
const toolReponses = [];
|
|
8234
|
-
|
|
8235
|
-
|
|
8236
|
-
|
|
8237
|
-
|
|
8238
|
-
|
|
8239
|
-
|
|
8240
|
-
|
|
8241
|
-
|
|
8242
|
-
|
|
8243
|
-
|
|
8244
|
-
|
|
8245
|
-
|
|
8246
|
-
|
|
8247
|
-
|
|
8248
|
-
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
|
|
8252
|
-
|
|
8253
|
-
|
|
8254
|
-
|
|
8255
|
-
|
|
8256
|
-
|
|
8257
|
-
|
|
8258
|
-
|
|
8361
|
+
outer:
|
|
8362
|
+
for (const content of response) {
|
|
8363
|
+
switch (content.type) {
|
|
8364
|
+
case "text":
|
|
8365
|
+
break;
|
|
8366
|
+
case "tool_use": {
|
|
8367
|
+
await callback({ kind: "ToolUse" /* ToolUse */, info, tool: content.name });
|
|
8368
|
+
const toolResp = await this.#invokeTool(content.name, content.params);
|
|
8369
|
+
switch (toolResp.type) {
|
|
8370
|
+
case "Reply" /* Reply */:
|
|
8371
|
+
await callback({ kind: "ToolReply" /* ToolReply */, info, tool: content.name });
|
|
8372
|
+
toolReponses.push({ tool: content.name, response: toolResp.message });
|
|
8373
|
+
break;
|
|
8374
|
+
case "Exit" /* Exit */:
|
|
8375
|
+
return [undefined, toolResp];
|
|
8376
|
+
case "Invalid" /* Invalid */:
|
|
8377
|
+
await callback({ kind: "ToolInvalid" /* ToolInvalid */, info, tool: content.name });
|
|
8378
|
+
toolReponses.push({ tool: content.name, response: toolResp.message });
|
|
8379
|
+
break outer;
|
|
8380
|
+
case "Error" /* Error */:
|
|
8381
|
+
await callback({ kind: "ToolError" /* ToolError */, info, tool: content.name });
|
|
8382
|
+
toolReponses.push({ tool: content.name, response: toolResp.message });
|
|
8383
|
+
break outer;
|
|
8384
|
+
case "Interrupted" /* Interrupted */:
|
|
8385
|
+
await callback({ kind: "ToolInterrupted" /* ToolInterrupted */, info, tool: content.name });
|
|
8386
|
+
return [undefined, toolResp];
|
|
8387
|
+
case "HandOver" /* HandOver */:
|
|
8388
|
+
await callback({
|
|
8389
|
+
kind: "ToolHandOver" /* ToolHandOver */,
|
|
8390
|
+
info,
|
|
8391
|
+
tool: content.name,
|
|
8392
|
+
agentName: toolResp.agentName,
|
|
8393
|
+
task: toolResp.task,
|
|
8394
|
+
context: toolResp.context,
|
|
8395
|
+
files: toolResp.files
|
|
8396
|
+
});
|
|
8397
|
+
return [undefined, toolResp];
|
|
8398
|
+
}
|
|
8399
|
+
break;
|
|
8259
8400
|
}
|
|
8260
|
-
break;
|
|
8261
8401
|
}
|
|
8262
8402
|
}
|
|
8263
|
-
}
|
|
8264
8403
|
if (toolReponses.length === 0 && !this.config.interactive) {
|
|
8265
8404
|
return [responsePrompts.requireUseTool, undefined];
|
|
8266
8405
|
}
|
|
@@ -8328,6 +8467,7 @@ __export(exports_allTools, {
|
|
|
8328
8467
|
readFile: () => readFile_default,
|
|
8329
8468
|
listFiles: () => listFiles_default,
|
|
8330
8469
|
listCodeDefinitionNames: () => listCodeDefinitionNames_default,
|
|
8470
|
+
handOver: () => handOver_default,
|
|
8331
8471
|
executeCommand: () => executeCommand_default,
|
|
8332
8472
|
attemptCompletion: () => attemptCompletion_default,
|
|
8333
8473
|
askFollowupQuestion: () => askFollowupQuestion_default
|
|
@@ -8391,14 +8531,14 @@ ${search}`);
|
|
|
8391
8531
|
// src/tools/utils/getArg.ts
|
|
8392
8532
|
var getString = (args, name, defaultValue) => {
|
|
8393
8533
|
const ret = args[name] ?? defaultValue;
|
|
8394
|
-
if (
|
|
8534
|
+
if (ret === undefined) {
|
|
8395
8535
|
throw new Error(`Missing required argument: ${name}`);
|
|
8396
8536
|
}
|
|
8397
8537
|
return ret;
|
|
8398
8538
|
};
|
|
8399
8539
|
var getStringArray = (args, name, defaultValue) => {
|
|
8400
8540
|
const ret = args[name];
|
|
8401
|
-
if (
|
|
8541
|
+
if (ret === undefined) {
|
|
8402
8542
|
if (defaultValue === undefined) {
|
|
8403
8543
|
throw new Error(`Missing required argument: ${name}`);
|
|
8404
8544
|
}
|
|
@@ -8408,7 +8548,7 @@ var getStringArray = (args, name, defaultValue) => {
|
|
|
8408
8548
|
};
|
|
8409
8549
|
var getBoolean = (args, name, defaultValue) => {
|
|
8410
8550
|
const ret = args[name];
|
|
8411
|
-
if (
|
|
8551
|
+
if (ret === undefined) {
|
|
8412
8552
|
if (defaultValue === undefined) {
|
|
8413
8553
|
throw new Error(`Missing required argument: ${name}`);
|
|
8414
8554
|
}
|
|
@@ -8425,7 +8565,7 @@ var getBoolean = (args, name, defaultValue) => {
|
|
|
8425
8565
|
};
|
|
8426
8566
|
var getInt = (args, name, defaultValue) => {
|
|
8427
8567
|
const ret = args[name];
|
|
8428
|
-
if (
|
|
8568
|
+
if (ret === undefined) {
|
|
8429
8569
|
if (defaultValue === undefined) {
|
|
8430
8570
|
throw new Error(`Missing required argument: ${name}`);
|
|
8431
8571
|
}
|
|
@@ -9047,6 +9187,81 @@ var writeToFile_default = {
|
|
|
9047
9187
|
handler: handler9,
|
|
9048
9188
|
isAvailable: isAvailable9
|
|
9049
9189
|
};
|
|
9190
|
+
// src/tools/handOver.ts
|
|
9191
|
+
var toolInfo10 = {
|
|
9192
|
+
name: "hand_over",
|
|
9193
|
+
description: "Hand over the current task to another agent to complete",
|
|
9194
|
+
parameters: [
|
|
9195
|
+
{
|
|
9196
|
+
name: "agent_name",
|
|
9197
|
+
description: "The name of the agent to hand over the task to",
|
|
9198
|
+
required: true,
|
|
9199
|
+
usageValue: "Name of the target agent"
|
|
9200
|
+
},
|
|
9201
|
+
{
|
|
9202
|
+
name: "task",
|
|
9203
|
+
description: "The task to be completed by the target agent",
|
|
9204
|
+
required: true,
|
|
9205
|
+
usageValue: "Task description"
|
|
9206
|
+
},
|
|
9207
|
+
{
|
|
9208
|
+
name: "context",
|
|
9209
|
+
description: "The context information for the task",
|
|
9210
|
+
required: true,
|
|
9211
|
+
usageValue: "Context information"
|
|
9212
|
+
},
|
|
9213
|
+
{
|
|
9214
|
+
name: "files",
|
|
9215
|
+
description: "The files relevant to the task",
|
|
9216
|
+
required: true,
|
|
9217
|
+
usageValue: "Relevant files"
|
|
9218
|
+
}
|
|
9219
|
+
],
|
|
9220
|
+
examples: [
|
|
9221
|
+
{
|
|
9222
|
+
description: "Hand over a coding task to the coder agent",
|
|
9223
|
+
parameters: [
|
|
9224
|
+
{
|
|
9225
|
+
name: "agent_name",
|
|
9226
|
+
value: "Coder"
|
|
9227
|
+
},
|
|
9228
|
+
{
|
|
9229
|
+
name: "task",
|
|
9230
|
+
value: "Implement the login feature"
|
|
9231
|
+
},
|
|
9232
|
+
{
|
|
9233
|
+
name: "context",
|
|
9234
|
+
value: "We need a secure login system with email and password"
|
|
9235
|
+
},
|
|
9236
|
+
{
|
|
9237
|
+
name: "files",
|
|
9238
|
+
value: "src/auth/login.ts,src/auth/types.ts"
|
|
9239
|
+
}
|
|
9240
|
+
]
|
|
9241
|
+
}
|
|
9242
|
+
]
|
|
9243
|
+
};
|
|
9244
|
+
var handler10 = async (_provider, args) => {
|
|
9245
|
+
const agentName = getString(args, "agent_name");
|
|
9246
|
+
const task = getString(args, "task");
|
|
9247
|
+
const context = getString(args, "context", undefined);
|
|
9248
|
+
const files = getStringArray(args, "files", []);
|
|
9249
|
+
return {
|
|
9250
|
+
type: "HandOver" /* HandOver */,
|
|
9251
|
+
agentName,
|
|
9252
|
+
task,
|
|
9253
|
+
context,
|
|
9254
|
+
files
|
|
9255
|
+
};
|
|
9256
|
+
};
|
|
9257
|
+
var isAvailable10 = (_provider) => {
|
|
9258
|
+
return true;
|
|
9259
|
+
};
|
|
9260
|
+
var handOver_default = {
|
|
9261
|
+
...toolInfo10,
|
|
9262
|
+
handler: handler10,
|
|
9263
|
+
isAvailable: isAvailable10
|
|
9264
|
+
};
|
|
9050
9265
|
// src/Agent/CoderAgent/prompts.ts
|
|
9051
9266
|
var basePrompt = "You are a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.";
|
|
9052
9267
|
var editingFilesPrompt = (toolNamePrefix) => `
|
|
@@ -9110,17 +9325,6 @@ You have access to two tools for working with files: **${toolNamePrefix}write_to
|
|
|
9110
9325
|
4. Once the file has been edited with either ${toolNamePrefix}write_to_file or ${toolNamePrefix}replace_in_file, the system will provide you with the final state of the modified file. Use this updated content as the reference point for any subsequent SEARCH/REPLACE operations, since it reflects any auto-formatting or user-applied changes.
|
|
9111
9326
|
|
|
9112
9327
|
By thoughtfully selecting between ${toolNamePrefix}write_to_file and ${toolNamePrefix}replace_in_file, you can make your file editing process smoother, safer, and more efficient.`;
|
|
9113
|
-
var capabilities = (toolNamePrefix) => `
|
|
9114
|
-
====
|
|
9115
|
-
|
|
9116
|
-
CAPABILITIES
|
|
9117
|
-
|
|
9118
|
-
- You have access to a range of tools to aid you in your work. These tools help you effectively accomplish a wide range of tasks, such as writing code, making edits or improvements to existing files, understanding the current state of a project, performing system operations, and much more.
|
|
9119
|
-
- When the user initially gives you a task, a recursive list of all filepaths in the current working directory will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further.
|
|
9120
|
-
- You can use ${toolNamePrefix}search_files to perform regex searches across files in a specified directory, outputting context-rich results that include surrounding lines. This is particularly useful for understanding code patterns, finding specific implementations, or identifying areas that need refactoring.
|
|
9121
|
-
- You can use the ${toolNamePrefix}list_code_definition_names tool to get an overview of source code definitions for all files at the top level of a specified directory. This can be particularly useful when you need to understand the broader context and relationships between certain parts of the code. You may need to call this tool multiple times to understand various parts of the codebase related to the task.
|
|
9122
|
-
\t- For example, when asked to make edits or improvements you might analyze the file structure in the initial environment_details to get an overview of the project, then use ${toolNamePrefix}list_code_definition_names to get further insight using source code definitions for files located in relevant directories, then ${toolNamePrefix}read_file to examine the contents of relevant files, analyze the code and suggest improvements or make necessary edits, then use the ${toolNamePrefix}replace_in_file tool to implement changes. If you refactored code that could affect other parts of the codebase, you could use ${toolNamePrefix}search_files to ensure you update other files as needed.
|
|
9123
|
-
- You can use the ${toolNamePrefix}execute_command tool to run commands on the user's computer whenever you feel it can help accomplish the user's task. When you need to execute a CLI command, you must provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, since they are more flexible and easier to run. Interactive and long-running commands are allowed, since the commands are run in the user's VSCode terminal. The user may keep commands running in the background and you will be kept updated on their status along the way. Each command you execute is run in a new terminal instance.`;
|
|
9124
9328
|
var rules = (toolNamePrefix) => `
|
|
9125
9329
|
====
|
|
9126
9330
|
|
|
@@ -9135,7 +9339,9 @@ RULES
|
|
|
9135
9339
|
- When creating a new project (such as an app, website, or any software project), organize all new files within a dedicated project directory unless the user specifies otherwise. Use appropriate file paths when creating files, as the ${toolNamePrefix}write_to_file tool will automatically create any necessary directories. Structure the project logically, adhering to best practices for the specific type of project being created. Unless otherwise specified, new projects should be easily run without additional setup, for example most projects can be built in HTML, CSS, and JavaScript - which you can open in a browser.
|
|
9136
9340
|
- Be sure to consider the type of project (e.g. Python, JavaScript, web application) when determining the appropriate structure and files to include. Also consider what files may be most relevant to accomplishing the task, for example looking at a project's manifest file would help you understand the project's dependencies, which you could incorporate into any code you write.
|
|
9137
9341
|
- When making changes to code, always consider the context in which the code is being used. Ensure that your changes are compatible with the existing codebase and that they follow the project's coding standards and best practices.
|
|
9342
|
+
- **Adhere to any established coding style, linting rules, or naming conventions if they are known or can be inferred from the existing codebase, to maintain consistency.**
|
|
9138
9343
|
- When you want to modify a file, use the ${toolNamePrefix}replace_in_file or ${toolNamePrefix}write_to_file tool directly with the desired changes. You do not need to display the changes before using the tool.
|
|
9344
|
+
- **Do not guess or hallucinate file content that has not been explicitly provided or read. Always read an existing file with \`${toolNamePrefix}read_file\` (or rely on content the user directly provided) before modifying it, unless you are creating a brand-new file.**
|
|
9139
9345
|
- Do not ask for more information than necessary. Use the tools provided to accomplish the user's request efficiently and effectively. When you've completed your task, you must use the ${toolNamePrefix}attempt_completion tool to present the result to the user.
|
|
9140
9346
|
- The user may provide a file's contents directly in their message, in which case you shouldn't use the ${toolNamePrefix}read_file tool to get the file contents again since you already have it.
|
|
9141
9347
|
- Your goal is to try to accomplish the user's task, NOT engage in a back and forth conversation.
|
|
@@ -9157,68 +9363,6 @@ You accomplish a given task iteratively, breaking it down into clear steps and w
|
|
|
9157
9363
|
3. Remember, you have extensive capabilities with access to a wide range of tools that can be used in powerful and clever ways as necessary to accomplish each goal. Before calling a tool, do some analysis within <thinking></thinking> tags. First, analyze the file structure provided in environment_details to gain context and insights for proceeding effectively. Then, think about which of the provided tools is the most relevant tool to accomplish the user's task. Next, go through each of the required parameters of the relevant tool and determine if the user has directly provided or given enough information to infer a value. When deciding if the parameter can be inferred, carefully consider all the context to see if it supports a specific value. If all of the required parameters are present or can be reasonably inferred, close the thinking tag and proceed with the tool use.
|
|
9158
9364
|
4. Once you've completed the user's task, you must use the ${toolNamePrefix}attempt_completion tool to present the result of the task to the user.
|
|
9159
9365
|
5. The user may provide feedback, which you can use to make improvements and try again. But DO NOT continue in pointless back and forth conversations, i.e. don't end your responses with questions or offers for further assistance.`;
|
|
9160
|
-
var systemInformation = (info) => `
|
|
9161
|
-
====
|
|
9162
|
-
|
|
9163
|
-
SYSTEM INFORMATION
|
|
9164
|
-
|
|
9165
|
-
Operating System: ${info.os}`;
|
|
9166
|
-
var customInstructions = (customInstructions2) => {
|
|
9167
|
-
const joined = customInstructions2.join(`
|
|
9168
|
-
`);
|
|
9169
|
-
if (joined.trim() === "") {
|
|
9170
|
-
return "";
|
|
9171
|
-
}
|
|
9172
|
-
return `
|
|
9173
|
-
====
|
|
9174
|
-
|
|
9175
|
-
USER'S CUSTOM INSTRUCTIONS
|
|
9176
|
-
|
|
9177
|
-
The following additional instructions are provided by the user, and should be followed to the best of your ability without interfering with the TOOL USE guidelines.
|
|
9178
|
-
|
|
9179
|
-
${joined}`;
|
|
9180
|
-
};
|
|
9181
|
-
var customScripts = (commands) => {
|
|
9182
|
-
const joined = Object.entries(commands).map(([name, command]) => {
|
|
9183
|
-
if (typeof command === "string") {
|
|
9184
|
-
return `- ${name}
|
|
9185
|
-
- Command: \`${command}\``;
|
|
9186
|
-
}
|
|
9187
|
-
return `- ${name}
|
|
9188
|
-
- Command: \`${command.command}\`
|
|
9189
|
-
- Description: ${command.description}`;
|
|
9190
|
-
}).join(`
|
|
9191
|
-
`);
|
|
9192
|
-
if (joined.trim() === "") {
|
|
9193
|
-
return "";
|
|
9194
|
-
}
|
|
9195
|
-
return `
|
|
9196
|
-
====
|
|
9197
|
-
|
|
9198
|
-
USER'S CUSTOM COMMANDS
|
|
9199
|
-
|
|
9200
|
-
The following additional commands are provided by the user, and should be followed to the best of your ability without interfering with the TOOL USE guidelines.
|
|
9201
|
-
|
|
9202
|
-
${joined}`;
|
|
9203
|
-
};
|
|
9204
|
-
var interactiveMode = (interactive) => {
|
|
9205
|
-
if (interactive) {
|
|
9206
|
-
return `
|
|
9207
|
-
====
|
|
9208
|
-
|
|
9209
|
-
INTERACTIVE MODE
|
|
9210
|
-
|
|
9211
|
-
You are in interactive mode. This means you may ask user questions to gather additional information to complete the task.
|
|
9212
|
-
`;
|
|
9213
|
-
}
|
|
9214
|
-
return `
|
|
9215
|
-
====
|
|
9216
|
-
|
|
9217
|
-
NON-INTERACTIVE MODE
|
|
9218
|
-
|
|
9219
|
-
You are in non-interactive mode. This means you will not be able to ask user questions to gather additional information to complete the task. You should try to use available tools to accomplish the task. If unable to precede further, you may try to end the task and provide a reason.
|
|
9220
|
-
`;
|
|
9221
|
-
};
|
|
9222
9366
|
var fullSystemPrompt = (info, tools, toolNamePrefix, instructions, scripts, interactive) => `
|
|
9223
9367
|
${basePrompt}
|
|
9224
9368
|
${toolUsePrompt(tools, toolNamePrefix)}
|
|
@@ -9241,13 +9385,161 @@ class CoderAgent extends AgentBase {
|
|
|
9241
9385
|
const systemPrompt = fullSystemPrompt({
|
|
9242
9386
|
os: options.os
|
|
9243
9387
|
}, tools, toolNamePrefix, options.customInstructions ?? [], options.scripts ?? {}, options.interactive);
|
|
9244
|
-
super(options.ai, {
|
|
9388
|
+
super(coderAgentInfo.name, options.ai, {
|
|
9389
|
+
systemPrompt,
|
|
9390
|
+
tools,
|
|
9391
|
+
toolNamePrefix,
|
|
9392
|
+
provider: options.provider,
|
|
9393
|
+
interactive: options.interactive,
|
|
9394
|
+
agents: options.agents
|
|
9395
|
+
});
|
|
9396
|
+
}
|
|
9397
|
+
}
|
|
9398
|
+
var coderAgentInfo = {
|
|
9399
|
+
name: "Coder",
|
|
9400
|
+
responsibilities: [
|
|
9401
|
+
"Editing and refactoring existing code.",
|
|
9402
|
+
"Creating new features or modules.",
|
|
9403
|
+
"Running tests and analyzing test results.",
|
|
9404
|
+
"Maintaining coding standards, lint rules, and general code quality."
|
|
9405
|
+
]
|
|
9406
|
+
};
|
|
9407
|
+
// src/Agent/ArchitectAgent/prompts.ts
|
|
9408
|
+
var fullSystemPrompt2 = (info, tools, toolNamePrefix, instructions, scripts, interactive) => `
|
|
9409
|
+
# Architect Agent
|
|
9410
|
+
|
|
9411
|
+
## Role
|
|
9412
|
+
You are the **Architect** agent, responsible for:
|
|
9413
|
+
1. **Task Analysis** – Understand requirements.
|
|
9414
|
+
2. **File Identification** – Find and select relevant files.
|
|
9415
|
+
3. **File Reading** – Use the provided tools to gather information from these files.
|
|
9416
|
+
4. **Implementation Plan** – Draft a concise plan detailing steps, resources, and dependencies.
|
|
9417
|
+
5. **Review & Improve** – Evaluate and refine the plan.
|
|
9418
|
+
6. **Handover** – Provide the final plan, context, and files to the **Coder** agent.
|
|
9419
|
+
|
|
9420
|
+
> **Note**: The **Architect** agent must not make any direct modifications. Your role is limited to creating the implementation plan and handing it over to the **Coder** agent, who will perform any actual changes.
|
|
9421
|
+
|
|
9422
|
+
## Rules
|
|
9423
|
+
1. **Consistency**: Maintain alignment with the user’s instructions and the system’s objectives at all times.
|
|
9424
|
+
2. **Relevance**: Only read and use files directly related to the task. Avoid unnecessary or tangential information.
|
|
9425
|
+
3. **Conciseness**: Keep all communications and plans succinct, avoiding superfluous or repetitive details.
|
|
9426
|
+
4. **Accuracy**: Ensure the information you gather and any conclusions you draw are correct and verifiable.
|
|
9427
|
+
5. **Clarity**: Present the final plan and any supporting details in a structured and easily understandable format.
|
|
9428
|
+
6. **Minimal Queries**: Ask clarifying questions only when essential, and avoid repeated questioning that does not add value.
|
|
9429
|
+
|
|
9430
|
+
## Steps
|
|
9431
|
+
1. **Analyze Task**
|
|
9432
|
+
- Gather and understand the user’s requirements.
|
|
9433
|
+
- Note any potential constraints or objectives that may influence the plan.
|
|
9434
|
+
|
|
9435
|
+
2. **Identify Relevant Files**
|
|
9436
|
+
- Determine which files or documents are necessary.
|
|
9437
|
+
- Justify why these files are relevant.
|
|
9438
|
+
|
|
9439
|
+
3. **Read Files via Tools**
|
|
9440
|
+
- Utilize the provided tools to access and extract information from the identified files.
|
|
9441
|
+
- Summarize key insights or data for the solution.
|
|
9442
|
+
|
|
9443
|
+
4. **Create Implementation Plan**
|
|
9444
|
+
- Outline tasks, define milestones, and detail resources or dependencies.
|
|
9445
|
+
- Provide clear, concise instructions for each step.
|
|
9446
|
+
|
|
9447
|
+
5. **Review & Improve**
|
|
9448
|
+
- Check the plan for consistency, clarity, and feasibility.
|
|
9449
|
+
- Make adjustments or refinements to ensure accuracy and efficiency.
|
|
9450
|
+
|
|
9451
|
+
6. **Handover**
|
|
9452
|
+
- Deliver the final implementation plan, context, and relevant files to the **Coder** agent.
|
|
9453
|
+
- Provide any additional instructions or clarifications needed for successful implementation.
|
|
9454
|
+
${toolUsePrompt(tools, toolNamePrefix)}
|
|
9455
|
+
${capabilities(toolNamePrefix)}
|
|
9456
|
+
${systemInformation(info)}
|
|
9457
|
+
${customInstructions(instructions)}
|
|
9458
|
+
${customScripts(scripts)}
|
|
9459
|
+
${interactiveMode(interactive)}
|
|
9460
|
+
`;
|
|
9461
|
+
|
|
9462
|
+
// src/Agent/ArchitectAgent/index.ts
|
|
9463
|
+
class ArchitectAgent extends AgentBase {
|
|
9464
|
+
constructor(options) {
|
|
9465
|
+
const agentTools = [
|
|
9466
|
+
...options.additionalTools ?? [],
|
|
9467
|
+
askFollowupQuestion_default,
|
|
9468
|
+
attemptCompletion_default,
|
|
9469
|
+
handOver_default,
|
|
9470
|
+
listCodeDefinitionNames_default,
|
|
9471
|
+
listFiles_default,
|
|
9472
|
+
readFile_default,
|
|
9473
|
+
searchFiles_default
|
|
9474
|
+
];
|
|
9475
|
+
const tools = getAvailableTools(options.provider, agentTools);
|
|
9476
|
+
const toolNamePrefix = "tool_";
|
|
9477
|
+
const systemPrompt = fullSystemPrompt2({
|
|
9478
|
+
os: options.os
|
|
9479
|
+
}, tools, toolNamePrefix, options.customInstructions ?? [], options.scripts ?? {}, options.interactive);
|
|
9480
|
+
super(architectAgentInfo.name, options.ai, {
|
|
9245
9481
|
systemPrompt,
|
|
9246
9482
|
tools,
|
|
9247
9483
|
toolNamePrefix,
|
|
9248
9484
|
provider: options.provider,
|
|
9249
|
-
interactive: options.interactive
|
|
9485
|
+
interactive: options.interactive,
|
|
9486
|
+
agents: options.agents
|
|
9487
|
+
});
|
|
9488
|
+
}
|
|
9489
|
+
}
|
|
9490
|
+
var architectAgentInfo = {
|
|
9491
|
+
name: "Architect",
|
|
9492
|
+
responsibilities: [
|
|
9493
|
+
"Analyzing the user’s overall task and requirements.",
|
|
9494
|
+
"Creating plans and making higher-level decisions about system structure and design.",
|
|
9495
|
+
"Reviewing and analyzing existing code or components for maintainability and scalability.",
|
|
9496
|
+
"Laying out the roadmap for implementation."
|
|
9497
|
+
]
|
|
9498
|
+
};
|
|
9499
|
+
// src/Agent/MultiAgent.ts
|
|
9500
|
+
class MultiAgent {
|
|
9501
|
+
#config;
|
|
9502
|
+
#activeAgent = null;
|
|
9503
|
+
constructor(config) {
|
|
9504
|
+
this.#config = config;
|
|
9505
|
+
}
|
|
9506
|
+
get model() {
|
|
9507
|
+
return this.#activeAgent?.model;
|
|
9508
|
+
}
|
|
9509
|
+
async#startTask(agentName, task, context, callback) {
|
|
9510
|
+
this.#activeAgent = await this.#config.createAgent(agentName);
|
|
9511
|
+
const [exitReason, info] = await this.#activeAgent.startTask({
|
|
9512
|
+
task,
|
|
9513
|
+
context,
|
|
9514
|
+
callback
|
|
9250
9515
|
});
|
|
9516
|
+
if (typeof exitReason === "string") {
|
|
9517
|
+
return [exitReason, info];
|
|
9518
|
+
}
|
|
9519
|
+
if (exitReason.type === "HandOver") {
|
|
9520
|
+
const context2 = await this.#config.getContext(agentName, exitReason.context, exitReason.files);
|
|
9521
|
+
const [exitReason2, info2] = await this.#startTask(exitReason.agentName, exitReason.task, context2, callback);
|
|
9522
|
+
info2.inputTokens += info.inputTokens;
|
|
9523
|
+
info2.outputTokens += info.outputTokens;
|
|
9524
|
+
info2.cacheWriteTokens += info.cacheWriteTokens;
|
|
9525
|
+
info2.cacheReadTokens += info.cacheReadTokens;
|
|
9526
|
+
info2.totalCost = (info.totalCost ?? 0) + (info2.totalCost ?? 0);
|
|
9527
|
+
return [exitReason2, info2];
|
|
9528
|
+
}
|
|
9529
|
+
return [exitReason, info];
|
|
9530
|
+
}
|
|
9531
|
+
async startTask(options) {
|
|
9532
|
+
if (this.#activeAgent) {
|
|
9533
|
+
throw new Error("An active agent already exists");
|
|
9534
|
+
}
|
|
9535
|
+
return this.#startTask(options.agentName, options.task, options.context, options.callback);
|
|
9536
|
+
}
|
|
9537
|
+
async continueTask(userMessage, taskInfo, callback = () => {
|
|
9538
|
+
}) {
|
|
9539
|
+
if (!this.#activeAgent) {
|
|
9540
|
+
throw new Error("No active agent");
|
|
9541
|
+
}
|
|
9542
|
+
return this.#activeAgent.continueTask(userMessage, taskInfo, callback);
|
|
9251
9543
|
}
|
|
9252
9544
|
}
|
|
9253
9545
|
// src/AiTool/generateGitCommitMessage.ts
|
|
@@ -9425,6 +9717,8 @@ export {
|
|
|
9425
9717
|
makeTool,
|
|
9426
9718
|
listFiles_default as listFiles,
|
|
9427
9719
|
listCodeDefinitionNames_default as listCodeDefinitionNames,
|
|
9720
|
+
handOver_default as handOver,
|
|
9721
|
+
getAvailableTools,
|
|
9428
9722
|
generateGithubPullRequestDetails,
|
|
9429
9723
|
generateGitCommitMessage,
|
|
9430
9724
|
executeTool,
|
|
@@ -9433,14 +9727,19 @@ export {
|
|
|
9433
9727
|
deepSeekModels,
|
|
9434
9728
|
deepSeekDefaultModelId,
|
|
9435
9729
|
createService,
|
|
9730
|
+
coderAgentInfo,
|
|
9436
9731
|
attemptCompletion_default as attemptCompletion,
|
|
9437
9732
|
askFollowupQuestion_default as askFollowupQuestion,
|
|
9733
|
+
architectAgentInfo,
|
|
9438
9734
|
anthropicModels,
|
|
9439
9735
|
anthropicDefaultModelId,
|
|
9440
9736
|
exports_allTools as allTools,
|
|
9737
|
+
ToolResponseType,
|
|
9738
|
+
TaskEventKind,
|
|
9739
|
+
MultiAgent,
|
|
9441
9740
|
MockProvider,
|
|
9442
|
-
ExitReason,
|
|
9443
9741
|
CoderAgent,
|
|
9742
|
+
ArchitectAgent,
|
|
9444
9743
|
AiServiceProvider,
|
|
9445
9744
|
AgentBase
|
|
9446
9745
|
};
|