@polka-codes/runner 0.8.17 → 0.8.19
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 +231 -288
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32748,7 +32748,7 @@ var {
|
|
|
32748
32748
|
Help
|
|
32749
32749
|
} = import__.default;
|
|
32750
32750
|
// package.json
|
|
32751
|
-
var version = "0.8.
|
|
32751
|
+
var version = "0.8.19";
|
|
32752
32752
|
|
|
32753
32753
|
// src/runner.ts
|
|
32754
32754
|
import { execSync } from "node:child_process";
|
|
@@ -42037,13 +42037,13 @@ __export(exports_allTools, {
|
|
|
42037
42037
|
writeToFile: () => writeToFile_default,
|
|
42038
42038
|
updateKnowledge: () => updateKnowledge_default,
|
|
42039
42039
|
searchFiles: () => searchFiles_default,
|
|
42040
|
+
replaceInFile: () => replaceInFile_default,
|
|
42040
42041
|
renameFile: () => renameFile_default,
|
|
42041
42042
|
removeFile: () => removeFile_default,
|
|
42042
42043
|
readFile: () => readFile_default,
|
|
42043
42044
|
listFiles: () => listFiles_default,
|
|
42044
42045
|
handOver: () => handOver_default,
|
|
42045
42046
|
executeCommand: () => executeCommand_default,
|
|
42046
|
-
editFile: () => editFile_default,
|
|
42047
42047
|
delegate: () => delegate_default,
|
|
42048
42048
|
attemptCompletion: () => attemptCompletion_default,
|
|
42049
42049
|
askFollowupQuestion: () => askFollowupQuestion_default
|
|
@@ -42056,78 +42056,31 @@ var editFile = async (fileContent, operations) => {
|
|
|
42056
42056
|
if (!operations || operations.length === 0) {
|
|
42057
42057
|
throw new Error("At least one edit operation is required");
|
|
42058
42058
|
}
|
|
42059
|
-
const originalLines = fileContent.split(`
|
|
42060
|
-
`);
|
|
42061
42059
|
let updatedContent = fileContent;
|
|
42062
42060
|
for (const operation of operations) {
|
|
42063
|
-
updatedContent = await applyEditOperation(updatedContent, operation
|
|
42061
|
+
updatedContent = await applyEditOperation(updatedContent, operation);
|
|
42064
42062
|
}
|
|
42065
42063
|
return updatedContent;
|
|
42066
42064
|
};
|
|
42067
|
-
async function applyEditOperation(fileContent, operation
|
|
42068
|
-
const {
|
|
42069
|
-
if (
|
|
42070
|
-
|
|
42071
|
-
}
|
|
42072
|
-
if (start_anchor === START_OF_FILE) {
|
|
42073
|
-
if (!end_anchor) {
|
|
42074
|
-
return new_text + fileContent;
|
|
42075
|
-
}
|
|
42076
|
-
const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
|
|
42077
|
-
return new_text + fileContent.slice(afterIndex);
|
|
42065
|
+
async function applyEditOperation(fileContent, operation) {
|
|
42066
|
+
const { search, replace } = operation;
|
|
42067
|
+
if (search === START_OF_FILE && replace === END_OF_FILE) {
|
|
42068
|
+
throw new Error("Cannot search for START_OF_FILE and replace with END_OF_FILE");
|
|
42078
42069
|
}
|
|
42079
|
-
if (
|
|
42080
|
-
|
|
42081
|
-
return fileContent + new_text;
|
|
42082
|
-
}
|
|
42083
|
-
const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
|
|
42084
|
-
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
42085
|
-
return fileContent.slice(0, beforeEndIndex) + new_text;
|
|
42086
|
-
}
|
|
42087
|
-
if (start_anchor && end_anchor) {
|
|
42088
|
-
const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
|
|
42089
|
-
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
42090
|
-
const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines, beforeEndIndex);
|
|
42091
|
-
return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(afterIndex);
|
|
42070
|
+
if (search === END_OF_FILE && replace === START_OF_FILE) {
|
|
42071
|
+
throw new Error("Cannot search for END_OF_FILE and replace with START_OF_FILE");
|
|
42092
42072
|
}
|
|
42093
|
-
if (
|
|
42094
|
-
|
|
42095
|
-
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
42096
|
-
return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(beforeEndIndex);
|
|
42073
|
+
if (search === START_OF_FILE) {
|
|
42074
|
+
return replace + fileContent;
|
|
42097
42075
|
}
|
|
42098
|
-
if (
|
|
42099
|
-
|
|
42100
|
-
return fileContent.slice(0, afterIndex) + new_text + fileContent.slice(afterIndex);
|
|
42076
|
+
if (search === END_OF_FILE) {
|
|
42077
|
+
return fileContent + replace;
|
|
42101
42078
|
}
|
|
42102
|
-
|
|
42103
|
-
}
|
|
42104
|
-
function findTextWithHint(content, searchText, lineHint, originalLines, startIndex = 0) {
|
|
42105
|
-
if (lineHint && lineHint > 0 && lineHint <= originalLines.length) {
|
|
42106
|
-
const hintIndex = getLineStartIndex(originalLines, lineHint - 1);
|
|
42107
|
-
const searchRadius = 5;
|
|
42108
|
-
const windowStart = Math.max(0, hintIndex - searchRadius * 50);
|
|
42109
|
-
const windowEnd = Math.min(content.length, hintIndex + searchRadius * 50);
|
|
42110
|
-
const windowContent = content.slice(windowStart, windowEnd);
|
|
42111
|
-
const relativeIndex = windowContent.indexOf(searchText);
|
|
42112
|
-
if (relativeIndex !== -1) {
|
|
42113
|
-
const absoluteIndex = windowStart + relativeIndex;
|
|
42114
|
-
if (absoluteIndex >= startIndex) {
|
|
42115
|
-
return absoluteIndex;
|
|
42116
|
-
}
|
|
42117
|
-
}
|
|
42118
|
-
}
|
|
42119
|
-
const index = content.indexOf(searchText, startIndex);
|
|
42079
|
+
const index = fileContent.indexOf(search);
|
|
42120
42080
|
if (index === -1) {
|
|
42121
|
-
throw new Error(`Could not find text: ${
|
|
42122
|
-
}
|
|
42123
|
-
return index;
|
|
42124
|
-
}
|
|
42125
|
-
function getLineStartIndex(lines, lineIndex) {
|
|
42126
|
-
let index = 0;
|
|
42127
|
-
for (let i2 = 0;i2 < lineIndex && i2 < lines.length; i2++) {
|
|
42128
|
-
index += lines[i2].length + 1;
|
|
42081
|
+
throw new Error(`Could not find text: ${search}`);
|
|
42129
42082
|
}
|
|
42130
|
-
return index;
|
|
42083
|
+
return fileContent.slice(0, index) + replace + fileContent.slice(index + search.length);
|
|
42131
42084
|
}
|
|
42132
42085
|
// ../core/src/tools/utils/getArg.ts
|
|
42133
42086
|
var getString = (args, name, defaultValue) => {
|
|
@@ -42721,8 +42674,125 @@ var readFile_default = {
|
|
|
42721
42674
|
handler: handler6,
|
|
42722
42675
|
isAvailable: isAvailable6
|
|
42723
42676
|
};
|
|
42724
|
-
// ../core/src/tools/
|
|
42677
|
+
// ../core/src/tools/replaceInFile.ts
|
|
42725
42678
|
var toolInfo7 = {
|
|
42679
|
+
name: "replace_in_file",
|
|
42680
|
+
description: "Request to replace sections of content in an existing file using SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file.",
|
|
42681
|
+
parameters: [
|
|
42682
|
+
{
|
|
42683
|
+
name: "path",
|
|
42684
|
+
description: "The path of the file to modify",
|
|
42685
|
+
required: true,
|
|
42686
|
+
usageValue: "File path here"
|
|
42687
|
+
},
|
|
42688
|
+
{
|
|
42689
|
+
name: "diff",
|
|
42690
|
+
description: `One or more SEARCH/REPLACE blocks following this exact format:
|
|
42691
|
+
\`\`\`
|
|
42692
|
+
<<<<<<< SEARCH
|
|
42693
|
+
[exact content to find]
|
|
42694
|
+
=======
|
|
42695
|
+
[new content to replace with]
|
|
42696
|
+
>>>>>>> REPLACE
|
|
42697
|
+
\`\`\`
|
|
42698
|
+
Critical rules:
|
|
42699
|
+
1. SEARCH content must match the associated file section to find EXACTLY:
|
|
42700
|
+
* Match character-for-character including whitespace, indentation, line endings
|
|
42701
|
+
* Include all comments, docstrings, etc.
|
|
42702
|
+
2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
|
|
42703
|
+
* Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
|
|
42704
|
+
* Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
|
|
42705
|
+
* When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
|
|
42706
|
+
3. Keep SEARCH/REPLACE blocks concise:
|
|
42707
|
+
* Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
|
|
42708
|
+
* Include just the changing lines, and a few surrounding lines if needed for uniqueness.
|
|
42709
|
+
* Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
|
|
42710
|
+
* Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
|
|
42711
|
+
4. Special operations:
|
|
42712
|
+
* To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
|
|
42713
|
+
* To delete code: Use empty REPLACE section`,
|
|
42714
|
+
required: true,
|
|
42715
|
+
usageValue: "Search and replace blocks here"
|
|
42716
|
+
}
|
|
42717
|
+
],
|
|
42718
|
+
examples: [
|
|
42719
|
+
{
|
|
42720
|
+
description: "Request to replace sections of content in a file",
|
|
42721
|
+
parameters: [
|
|
42722
|
+
{
|
|
42723
|
+
name: "path",
|
|
42724
|
+
value: "src/main.js"
|
|
42725
|
+
},
|
|
42726
|
+
{
|
|
42727
|
+
name: "diff",
|
|
42728
|
+
value: `
|
|
42729
|
+
<<<<<<< SEARCH
|
|
42730
|
+
import React from 'react';
|
|
42731
|
+
=======
|
|
42732
|
+
import React, { useState } from 'react';
|
|
42733
|
+
>>>>>>> REPLACE
|
|
42734
|
+
|
|
42735
|
+
<<<<<<< SEARCH
|
|
42736
|
+
function handleSubmit() {
|
|
42737
|
+
saveData();
|
|
42738
|
+
setLoading(false);
|
|
42739
|
+
}
|
|
42740
|
+
|
|
42741
|
+
=======
|
|
42742
|
+
>>>>>>> REPLACE
|
|
42743
|
+
|
|
42744
|
+
<<<<<<< SEARCH
|
|
42745
|
+
return (
|
|
42746
|
+
<div>
|
|
42747
|
+
=======
|
|
42748
|
+
function handleSubmit() {
|
|
42749
|
+
saveData();
|
|
42750
|
+
setLoading(false);
|
|
42751
|
+
}
|
|
42752
|
+
|
|
42753
|
+
return (
|
|
42754
|
+
<div>
|
|
42755
|
+
>>>>>>> REPLACE
|
|
42756
|
+
`
|
|
42757
|
+
}
|
|
42758
|
+
]
|
|
42759
|
+
}
|
|
42760
|
+
],
|
|
42761
|
+
permissionLevel: 2 /* Write */
|
|
42762
|
+
};
|
|
42763
|
+
var handler7 = async (provider, args) => {
|
|
42764
|
+
if (!provider.readFile || !provider.writeFile) {
|
|
42765
|
+
return {
|
|
42766
|
+
type: "Error" /* Error */,
|
|
42767
|
+
message: "Not possible to replace in file. Abort."
|
|
42768
|
+
};
|
|
42769
|
+
}
|
|
42770
|
+
const path = getString(args, "path");
|
|
42771
|
+
const diff = getString(args, "diff");
|
|
42772
|
+
const fileContent = await provider.readFile(path);
|
|
42773
|
+
if (fileContent == null) {
|
|
42774
|
+
return {
|
|
42775
|
+
type: "Error" /* Error */,
|
|
42776
|
+
message: `<error><replace_in_file_path>${path}</replace_in_file_path><error_message>File not found</error_message></error>`
|
|
42777
|
+
};
|
|
42778
|
+
}
|
|
42779
|
+
const result = await replaceInFile(fileContent, diff);
|
|
42780
|
+
await provider.writeFile(path, result);
|
|
42781
|
+
return {
|
|
42782
|
+
type: "Reply" /* Reply */,
|
|
42783
|
+
message: `<replace_in_file_path>${path}</replace_in_file_path>`
|
|
42784
|
+
};
|
|
42785
|
+
};
|
|
42786
|
+
var isAvailable7 = (provider) => {
|
|
42787
|
+
return !!provider.readFile && !!provider.writeFile;
|
|
42788
|
+
};
|
|
42789
|
+
var replaceInFile_default = {
|
|
42790
|
+
...toolInfo7,
|
|
42791
|
+
handler: handler7,
|
|
42792
|
+
isAvailable: isAvailable7
|
|
42793
|
+
};
|
|
42794
|
+
// ../core/src/tools/searchFiles.ts
|
|
42795
|
+
var toolInfo8 = {
|
|
42726
42796
|
name: "search_files",
|
|
42727
42797
|
description: "Request to perform a regex search across files in a specified directory, outputting context-rich results that include surrounding lines. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.",
|
|
42728
42798
|
parameters: [
|
|
@@ -42766,7 +42836,7 @@ var toolInfo7 = {
|
|
|
42766
42836
|
],
|
|
42767
42837
|
permissionLevel: 1 /* Read */
|
|
42768
42838
|
};
|
|
42769
|
-
var
|
|
42839
|
+
var handler8 = async (provider, args) => {
|
|
42770
42840
|
if (!provider.searchFiles) {
|
|
42771
42841
|
return {
|
|
42772
42842
|
type: "Error" /* Error */,
|
|
@@ -42789,18 +42859,18 @@ ${files.join(`
|
|
|
42789
42859
|
`
|
|
42790
42860
|
};
|
|
42791
42861
|
};
|
|
42792
|
-
var
|
|
42862
|
+
var isAvailable8 = (provider) => {
|
|
42793
42863
|
return !!provider.searchFiles;
|
|
42794
42864
|
};
|
|
42795
42865
|
var searchFiles_default = {
|
|
42796
|
-
...
|
|
42797
|
-
handler:
|
|
42798
|
-
isAvailable:
|
|
42866
|
+
...toolInfo8,
|
|
42867
|
+
handler: handler8,
|
|
42868
|
+
isAvailable: isAvailable8
|
|
42799
42869
|
};
|
|
42800
42870
|
// ../core/src/tools/updateKnowledge.ts
|
|
42801
42871
|
var import_yaml = __toESM(require_dist(), 1);
|
|
42802
42872
|
import { join } from "node:path";
|
|
42803
|
-
var
|
|
42873
|
+
var toolInfo9 = {
|
|
42804
42874
|
name: "update_knowledge",
|
|
42805
42875
|
description: "Update knowledge in a knowledge.ai.yml file with smart merging capabilities. This tool lets you add, update, or remove information using path-based updates and special directives.",
|
|
42806
42876
|
parameters: [
|
|
@@ -42977,7 +43047,7 @@ function deepMerge(target, source) {
|
|
|
42977
43047
|
}
|
|
42978
43048
|
return output;
|
|
42979
43049
|
}
|
|
42980
|
-
var
|
|
43050
|
+
var handler9 = async (provider, args) => {
|
|
42981
43051
|
if (!provider.readFile || !provider.writeFile) {
|
|
42982
43052
|
return {
|
|
42983
43053
|
type: "Error" /* Error */,
|
|
@@ -43049,16 +43119,16 @@ var handler8 = async (provider, args) => {
|
|
|
43049
43119
|
};
|
|
43050
43120
|
}
|
|
43051
43121
|
};
|
|
43052
|
-
var
|
|
43122
|
+
var isAvailable9 = (provider) => {
|
|
43053
43123
|
return !!provider.readFile && !!provider.writeFile;
|
|
43054
43124
|
};
|
|
43055
43125
|
var updateKnowledge_default = {
|
|
43056
|
-
...
|
|
43057
|
-
handler:
|
|
43058
|
-
isAvailable:
|
|
43126
|
+
...toolInfo9,
|
|
43127
|
+
handler: handler9,
|
|
43128
|
+
isAvailable: isAvailable9
|
|
43059
43129
|
};
|
|
43060
43130
|
// ../core/src/tools/writeToFile.ts
|
|
43061
|
-
var
|
|
43131
|
+
var toolInfo10 = {
|
|
43062
43132
|
name: "write_to_file",
|
|
43063
43133
|
description: "Request to write content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. This tool will automatically create any directories needed to write the file. Ensure that the output content does not include incorrect escaped character patterns such as `<` and `>`.",
|
|
43064
43134
|
parameters: [
|
|
@@ -43103,7 +43173,7 @@ export default App;
|
|
|
43103
43173
|
],
|
|
43104
43174
|
permissionLevel: 2 /* Write */
|
|
43105
43175
|
};
|
|
43106
|
-
var
|
|
43176
|
+
var handler10 = async (provider, args) => {
|
|
43107
43177
|
if (!provider.writeFile) {
|
|
43108
43178
|
return {
|
|
43109
43179
|
type: "Error" /* Error */,
|
|
@@ -43118,16 +43188,16 @@ var handler9 = async (provider, args) => {
|
|
|
43118
43188
|
message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
|
|
43119
43189
|
};
|
|
43120
43190
|
};
|
|
43121
|
-
var
|
|
43191
|
+
var isAvailable10 = (provider) => {
|
|
43122
43192
|
return !!provider.writeFile;
|
|
43123
43193
|
};
|
|
43124
43194
|
var writeToFile_default = {
|
|
43125
|
-
...
|
|
43126
|
-
handler:
|
|
43127
|
-
isAvailable:
|
|
43195
|
+
...toolInfo10,
|
|
43196
|
+
handler: handler10,
|
|
43197
|
+
isAvailable: isAvailable10
|
|
43128
43198
|
};
|
|
43129
43199
|
// ../core/src/tools/handOver.ts
|
|
43130
|
-
var
|
|
43200
|
+
var toolInfo11 = {
|
|
43131
43201
|
name: "hand_over",
|
|
43132
43202
|
description: "Hand over the current task to another agent to complete. This tool MUST NOT to be used with any other tool.",
|
|
43133
43203
|
parameters: [
|
|
@@ -43181,7 +43251,7 @@ var toolInfo10 = {
|
|
|
43181
43251
|
],
|
|
43182
43252
|
permissionLevel: 0 /* None */
|
|
43183
43253
|
};
|
|
43184
|
-
var
|
|
43254
|
+
var handler11 = async (_provider, args) => {
|
|
43185
43255
|
const agentName = getString(args, "agent_name");
|
|
43186
43256
|
const task = getString(args, "task");
|
|
43187
43257
|
const context = getString(args, "context", undefined);
|
|
@@ -43194,16 +43264,16 @@ var handler10 = async (_provider, args) => {
|
|
|
43194
43264
|
files
|
|
43195
43265
|
};
|
|
43196
43266
|
};
|
|
43197
|
-
var
|
|
43267
|
+
var isAvailable11 = (_provider) => {
|
|
43198
43268
|
return true;
|
|
43199
43269
|
};
|
|
43200
43270
|
var handOver_default = {
|
|
43201
|
-
...
|
|
43202
|
-
handler:
|
|
43203
|
-
isAvailable:
|
|
43271
|
+
...toolInfo11,
|
|
43272
|
+
handler: handler11,
|
|
43273
|
+
isAvailable: isAvailable11
|
|
43204
43274
|
};
|
|
43205
43275
|
// ../core/src/tools/removeFile.ts
|
|
43206
|
-
var
|
|
43276
|
+
var toolInfo12 = {
|
|
43207
43277
|
name: "remove_file",
|
|
43208
43278
|
description: "Request to remove a file at the specified path.",
|
|
43209
43279
|
parameters: [
|
|
@@ -43227,7 +43297,7 @@ var toolInfo11 = {
|
|
|
43227
43297
|
],
|
|
43228
43298
|
permissionLevel: 2 /* Write */
|
|
43229
43299
|
};
|
|
43230
|
-
var
|
|
43300
|
+
var handler12 = async (provider, args) => {
|
|
43231
43301
|
if (!provider.removeFile) {
|
|
43232
43302
|
return {
|
|
43233
43303
|
type: "Error" /* Error */,
|
|
@@ -43241,16 +43311,16 @@ var handler11 = async (provider, args) => {
|
|
|
43241
43311
|
message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
|
|
43242
43312
|
};
|
|
43243
43313
|
};
|
|
43244
|
-
var
|
|
43314
|
+
var isAvailable12 = (provider) => {
|
|
43245
43315
|
return !!provider.removeFile;
|
|
43246
43316
|
};
|
|
43247
43317
|
var removeFile_default = {
|
|
43248
|
-
...
|
|
43249
|
-
handler:
|
|
43250
|
-
isAvailable:
|
|
43318
|
+
...toolInfo12,
|
|
43319
|
+
handler: handler12,
|
|
43320
|
+
isAvailable: isAvailable12
|
|
43251
43321
|
};
|
|
43252
43322
|
// ../core/src/tools/renameFile.ts
|
|
43253
|
-
var
|
|
43323
|
+
var toolInfo13 = {
|
|
43254
43324
|
name: "rename_file",
|
|
43255
43325
|
description: "Request to rename a file from source path to target path.",
|
|
43256
43326
|
parameters: [
|
|
@@ -43284,7 +43354,7 @@ var toolInfo12 = {
|
|
|
43284
43354
|
],
|
|
43285
43355
|
permissionLevel: 2 /* Write */
|
|
43286
43356
|
};
|
|
43287
|
-
var
|
|
43357
|
+
var handler13 = async (provider, args) => {
|
|
43288
43358
|
if (!provider.renameFile) {
|
|
43289
43359
|
return {
|
|
43290
43360
|
type: "Error" /* Error */,
|
|
@@ -43299,18 +43369,18 @@ var handler12 = async (provider, args) => {
|
|
|
43299
43369
|
message: `<rename_file_path>${targetPath}</rename_file_path><status>Success</status>`
|
|
43300
43370
|
};
|
|
43301
43371
|
};
|
|
43302
|
-
var
|
|
43372
|
+
var isAvailable13 = (provider) => {
|
|
43303
43373
|
return !!provider.renameFile;
|
|
43304
43374
|
};
|
|
43305
43375
|
var renameFile_default = {
|
|
43306
|
-
...
|
|
43307
|
-
handler:
|
|
43308
|
-
isAvailable:
|
|
43376
|
+
...toolInfo13,
|
|
43377
|
+
handler: handler13,
|
|
43378
|
+
isAvailable: isAvailable13
|
|
43309
43379
|
};
|
|
43310
43380
|
// ../core/src/tools/editFile.ts
|
|
43311
|
-
var
|
|
43381
|
+
var toolInfo14 = {
|
|
43312
43382
|
name: "edit_file",
|
|
43313
|
-
description: "Request to edit file contents using
|
|
43383
|
+
description: "Request to edit file contents using search/replace operations. Supports multiple edit operations in a single call.",
|
|
43314
43384
|
parameters: [
|
|
43315
43385
|
{
|
|
43316
43386
|
name: "path",
|
|
@@ -43320,39 +43390,21 @@ var toolInfo13 = {
|
|
|
43320
43390
|
},
|
|
43321
43391
|
{
|
|
43322
43392
|
name: "operations",
|
|
43323
|
-
description: "Edit operation with
|
|
43393
|
+
description: "Edit operation with search and replace parameters",
|
|
43324
43394
|
required: true,
|
|
43325
43395
|
allowMultiple: true,
|
|
43326
43396
|
children: [
|
|
43327
43397
|
{
|
|
43328
|
-
name: "
|
|
43329
|
-
description: `Text to
|
|
43330
|
-
required: false,
|
|
43331
|
-
usageValue: "Text before the edit location"
|
|
43332
|
-
},
|
|
43333
|
-
{
|
|
43334
|
-
name: "end_anchor",
|
|
43335
|
-
description: `Text to find as the end anchor (use ${END_OF_FILE} for file end)`,
|
|
43336
|
-
required: false,
|
|
43337
|
-
usageValue: "Text after the edit location"
|
|
43338
|
-
},
|
|
43339
|
-
{
|
|
43340
|
-
name: "new_text",
|
|
43341
|
-
description: "Text to replace the content between start_anchor and end_anchor",
|
|
43398
|
+
name: "search",
|
|
43399
|
+
description: `Text to search for and replace (use ${START_OF_FILE} to insert at file start, ${END_OF_FILE} to insert at file end)`,
|
|
43342
43400
|
required: true,
|
|
43343
|
-
usageValue: "
|
|
43401
|
+
usageValue: "Text to find and replace"
|
|
43344
43402
|
},
|
|
43345
43403
|
{
|
|
43346
|
-
name: "
|
|
43347
|
-
description: "
|
|
43348
|
-
required:
|
|
43349
|
-
usageValue: "
|
|
43350
|
-
},
|
|
43351
|
-
{
|
|
43352
|
-
name: "end_anchor_line_start",
|
|
43353
|
-
description: "Optional line number hint for end_anchor location (1-based)",
|
|
43354
|
-
required: false,
|
|
43355
|
-
usageValue: "20"
|
|
43404
|
+
name: "replace",
|
|
43405
|
+
description: "Text to replace the search text with",
|
|
43406
|
+
required: true,
|
|
43407
|
+
usageValue: "Replacement text"
|
|
43356
43408
|
}
|
|
43357
43409
|
],
|
|
43358
43410
|
usageValue: "operations here"
|
|
@@ -43360,7 +43412,7 @@ var toolInfo13 = {
|
|
|
43360
43412
|
],
|
|
43361
43413
|
examples: [
|
|
43362
43414
|
{
|
|
43363
|
-
description: "Replace
|
|
43415
|
+
description: "Replace specific text",
|
|
43364
43416
|
parameters: [
|
|
43365
43417
|
{
|
|
43366
43418
|
name: "path",
|
|
@@ -43369,11 +43421,12 @@ var toolInfo13 = {
|
|
|
43369
43421
|
{
|
|
43370
43422
|
name: "operations",
|
|
43371
43423
|
value: {
|
|
43372
|
-
|
|
43373
|
-
|
|
43374
|
-
|
|
43424
|
+
search: `function oldFunction() {
|
|
43425
|
+
return 42;
|
|
43426
|
+
}`,
|
|
43427
|
+
replace: `function newFunction() {
|
|
43375
43428
|
return "new implementation";
|
|
43376
|
-
`
|
|
43429
|
+
}`
|
|
43377
43430
|
}
|
|
43378
43431
|
}
|
|
43379
43432
|
]
|
|
@@ -43388,9 +43441,8 @@ var toolInfo13 = {
|
|
|
43388
43441
|
{
|
|
43389
43442
|
name: "operations",
|
|
43390
43443
|
value: {
|
|
43391
|
-
|
|
43392
|
-
|
|
43393
|
-
new_text: `// File header comment
|
|
43444
|
+
search: START_OF_FILE,
|
|
43445
|
+
replace: `// File header comment
|
|
43394
43446
|
`
|
|
43395
43447
|
}
|
|
43396
43448
|
}
|
|
@@ -43407,25 +43459,42 @@ var toolInfo13 = {
|
|
|
43407
43459
|
name: "operations",
|
|
43408
43460
|
value: [
|
|
43409
43461
|
{
|
|
43410
|
-
|
|
43411
|
-
|
|
43412
|
-
new_text: ", { useState }"
|
|
43462
|
+
search: 'import React from "react"',
|
|
43463
|
+
replace: 'import React, { useState } from "react"'
|
|
43413
43464
|
},
|
|
43414
43465
|
{
|
|
43415
|
-
|
|
43416
|
-
|
|
43417
|
-
|
|
43466
|
+
search: `function Component() {
|
|
43467
|
+
return (`,
|
|
43468
|
+
replace: `function Component() {
|
|
43418
43469
|
const [state, setState] = useState(false);
|
|
43419
|
-
`
|
|
43470
|
+
return (`
|
|
43420
43471
|
}
|
|
43421
43472
|
]
|
|
43422
43473
|
}
|
|
43423
43474
|
]
|
|
43475
|
+
},
|
|
43476
|
+
{
|
|
43477
|
+
description: "Append content at end of file",
|
|
43478
|
+
parameters: [
|
|
43479
|
+
{
|
|
43480
|
+
name: "path",
|
|
43481
|
+
value: "src/footer.ts"
|
|
43482
|
+
},
|
|
43483
|
+
{
|
|
43484
|
+
name: "operations",
|
|
43485
|
+
value: {
|
|
43486
|
+
search: END_OF_FILE,
|
|
43487
|
+
replace: `
|
|
43488
|
+
// End of file appended comment
|
|
43489
|
+
`
|
|
43490
|
+
}
|
|
43491
|
+
}
|
|
43492
|
+
]
|
|
43424
43493
|
}
|
|
43425
43494
|
],
|
|
43426
43495
|
permissionLevel: 2 /* Write */
|
|
43427
43496
|
};
|
|
43428
|
-
var
|
|
43497
|
+
var handler14 = async (provider, args) => {
|
|
43429
43498
|
if (!provider.readFile || !provider.writeFile) {
|
|
43430
43499
|
return {
|
|
43431
43500
|
type: "Error" /* Error */,
|
|
@@ -43461,127 +43530,10 @@ var handler13 = async (provider, args) => {
|
|
|
43461
43530
|
};
|
|
43462
43531
|
}
|
|
43463
43532
|
};
|
|
43464
|
-
var isAvailable13 = (provider) => {
|
|
43465
|
-
return !!provider.readFile && !!provider.writeFile;
|
|
43466
|
-
};
|
|
43467
|
-
var editFile_default = {
|
|
43468
|
-
...toolInfo13,
|
|
43469
|
-
handler: handler13,
|
|
43470
|
-
isAvailable: isAvailable13
|
|
43471
|
-
};
|
|
43472
|
-
// ../core/src/tools/replaceInFile.ts
|
|
43473
|
-
var toolInfo14 = {
|
|
43474
|
-
name: "replace_in_file",
|
|
43475
|
-
description: "Request to replace sections of content in an existing file using SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file.",
|
|
43476
|
-
parameters: [
|
|
43477
|
-
{
|
|
43478
|
-
name: "path",
|
|
43479
|
-
description: "The path of the file to modify",
|
|
43480
|
-
required: true,
|
|
43481
|
-
usageValue: "File path here"
|
|
43482
|
-
},
|
|
43483
|
-
{
|
|
43484
|
-
name: "diff",
|
|
43485
|
-
description: `One or more SEARCH/REPLACE blocks following this exact format:
|
|
43486
|
-
\`\`\`
|
|
43487
|
-
<<<<<<< SEARCH
|
|
43488
|
-
[exact content to find]
|
|
43489
|
-
=======
|
|
43490
|
-
[new content to replace with]
|
|
43491
|
-
>>>>>>> REPLACE
|
|
43492
|
-
\`\`\`
|
|
43493
|
-
Critical rules:
|
|
43494
|
-
1. SEARCH content must match the associated file section to find EXACTLY:
|
|
43495
|
-
* Match character-for-character including whitespace, indentation, line endings
|
|
43496
|
-
* Include all comments, docstrings, etc.
|
|
43497
|
-
2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
|
|
43498
|
-
* Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
|
|
43499
|
-
* Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
|
|
43500
|
-
* When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
|
|
43501
|
-
3. Keep SEARCH/REPLACE blocks concise:
|
|
43502
|
-
* Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
|
|
43503
|
-
* Include just the changing lines, and a few surrounding lines if needed for uniqueness.
|
|
43504
|
-
* Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
|
|
43505
|
-
* Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
|
|
43506
|
-
4. Special operations:
|
|
43507
|
-
* To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
|
|
43508
|
-
* To delete code: Use empty REPLACE section`,
|
|
43509
|
-
required: true,
|
|
43510
|
-
usageValue: "Search and replace blocks here"
|
|
43511
|
-
}
|
|
43512
|
-
],
|
|
43513
|
-
examples: [
|
|
43514
|
-
{
|
|
43515
|
-
description: "Request to replace sections of content in a file",
|
|
43516
|
-
parameters: [
|
|
43517
|
-
{
|
|
43518
|
-
name: "path",
|
|
43519
|
-
value: "src/main.js"
|
|
43520
|
-
},
|
|
43521
|
-
{
|
|
43522
|
-
name: "diff",
|
|
43523
|
-
value: `
|
|
43524
|
-
<<<<<<< SEARCH
|
|
43525
|
-
import React from 'react';
|
|
43526
|
-
=======
|
|
43527
|
-
import React, { useState } from 'react';
|
|
43528
|
-
>>>>>>> REPLACE
|
|
43529
|
-
|
|
43530
|
-
<<<<<<< SEARCH
|
|
43531
|
-
function handleSubmit() {
|
|
43532
|
-
saveData();
|
|
43533
|
-
setLoading(false);
|
|
43534
|
-
}
|
|
43535
|
-
|
|
43536
|
-
=======
|
|
43537
|
-
>>>>>>> REPLACE
|
|
43538
|
-
|
|
43539
|
-
<<<<<<< SEARCH
|
|
43540
|
-
return (
|
|
43541
|
-
<div>
|
|
43542
|
-
=======
|
|
43543
|
-
function handleSubmit() {
|
|
43544
|
-
saveData();
|
|
43545
|
-
setLoading(false);
|
|
43546
|
-
}
|
|
43547
|
-
|
|
43548
|
-
return (
|
|
43549
|
-
<div>
|
|
43550
|
-
>>>>>>> REPLACE
|
|
43551
|
-
`
|
|
43552
|
-
}
|
|
43553
|
-
]
|
|
43554
|
-
}
|
|
43555
|
-
],
|
|
43556
|
-
permissionLevel: 2 /* Write */
|
|
43557
|
-
};
|
|
43558
|
-
var handler14 = async (provider, args) => {
|
|
43559
|
-
if (!provider.readFile || !provider.writeFile) {
|
|
43560
|
-
return {
|
|
43561
|
-
type: "Error" /* Error */,
|
|
43562
|
-
message: "Not possible to replace in file. Abort."
|
|
43563
|
-
};
|
|
43564
|
-
}
|
|
43565
|
-
const path = getString(args, "path");
|
|
43566
|
-
const diff = getString(args, "diff");
|
|
43567
|
-
const fileContent = await provider.readFile(path);
|
|
43568
|
-
if (fileContent == null) {
|
|
43569
|
-
return {
|
|
43570
|
-
type: "Error" /* Error */,
|
|
43571
|
-
message: `<error><replace_in_file_path>${path}</replace_in_file_path><error_message>File not found</error_message></error>`
|
|
43572
|
-
};
|
|
43573
|
-
}
|
|
43574
|
-
const result = await replaceInFile(fileContent, diff);
|
|
43575
|
-
await provider.writeFile(path, result);
|
|
43576
|
-
return {
|
|
43577
|
-
type: "Reply" /* Reply */,
|
|
43578
|
-
message: `<replace_in_file_path>${path}</replace_in_file_path>`
|
|
43579
|
-
};
|
|
43580
|
-
};
|
|
43581
43533
|
var isAvailable14 = (provider) => {
|
|
43582
43534
|
return !!provider.readFile && !!provider.writeFile;
|
|
43583
43535
|
};
|
|
43584
|
-
var
|
|
43536
|
+
var editFile_default = {
|
|
43585
43537
|
...toolInfo14,
|
|
43586
43538
|
handler: handler14,
|
|
43587
43539
|
isAvailable: isAvailable14
|
|
@@ -43967,7 +43919,6 @@ class AgentBase {
|
|
|
43967
43919
|
config;
|
|
43968
43920
|
handlers;
|
|
43969
43921
|
#messages = [];
|
|
43970
|
-
#originalTask;
|
|
43971
43922
|
#policies;
|
|
43972
43923
|
constructor(name, ai, config) {
|
|
43973
43924
|
this.ai = ai;
|
|
@@ -44013,7 +43964,6 @@ ${instance.prompt}`;
|
|
|
44013
43964
|
await this.config.callback?.(event);
|
|
44014
43965
|
}
|
|
44015
43966
|
async start(prompt) {
|
|
44016
|
-
this.#originalTask = prompt;
|
|
44017
43967
|
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
44018
43968
|
return await this.#processLoop(prompt);
|
|
44019
43969
|
}
|
|
@@ -44140,41 +44090,31 @@ ${instance.prompt}`;
|
|
|
44140
44090
|
if (toolResponses.length > 0) {
|
|
44141
44091
|
break outer;
|
|
44142
44092
|
}
|
|
44143
|
-
const handOverResp = {
|
|
44144
|
-
...toolResp,
|
|
44145
|
-
originalTask: this.#originalTask
|
|
44146
|
-
};
|
|
44147
44093
|
await this.#callback({
|
|
44148
44094
|
kind: "ToolHandOver" /* ToolHandOver */,
|
|
44149
44095
|
agent: this,
|
|
44150
44096
|
tool: content.name,
|
|
44151
|
-
agentName:
|
|
44152
|
-
task:
|
|
44153
|
-
context:
|
|
44154
|
-
files:
|
|
44155
|
-
originalTask: handOverResp.originalTask
|
|
44097
|
+
agentName: toolResp.agentName,
|
|
44098
|
+
task: toolResp.task,
|
|
44099
|
+
context: toolResp.context,
|
|
44100
|
+
files: toolResp.files
|
|
44156
44101
|
});
|
|
44157
|
-
return { type: "exit", reason:
|
|
44102
|
+
return { type: "exit", reason: toolResp };
|
|
44158
44103
|
}
|
|
44159
44104
|
case "Delegate" /* Delegate */: {
|
|
44160
44105
|
if (toolResponses.length > 0) {
|
|
44161
44106
|
break outer;
|
|
44162
44107
|
}
|
|
44163
|
-
const delegateResp = {
|
|
44164
|
-
...toolResp,
|
|
44165
|
-
originalTask: this.#originalTask
|
|
44166
|
-
};
|
|
44167
44108
|
await this.#callback({
|
|
44168
44109
|
kind: "ToolDelegate" /* ToolDelegate */,
|
|
44169
44110
|
agent: this,
|
|
44170
44111
|
tool: content.name,
|
|
44171
|
-
agentName:
|
|
44172
|
-
task:
|
|
44173
|
-
context:
|
|
44174
|
-
files:
|
|
44175
|
-
originalTask: delegateResp.originalTask
|
|
44112
|
+
agentName: toolResp.agentName,
|
|
44113
|
+
task: toolResp.task,
|
|
44114
|
+
context: toolResp.context,
|
|
44115
|
+
files: toolResp.files
|
|
44176
44116
|
});
|
|
44177
|
-
return { type: "exit", reason:
|
|
44117
|
+
return { type: "exit", reason: toolResp };
|
|
44178
44118
|
}
|
|
44179
44119
|
case "Pause" /* Pause */: {
|
|
44180
44120
|
await this.#callback({ kind: "ToolPause" /* ToolPause */, agent: this, tool: content.name, object: toolResp.object });
|
|
@@ -44398,6 +44338,7 @@ var codeFixerAgentInfo = {
|
|
|
44398
44338
|
class MultiAgent {
|
|
44399
44339
|
#config;
|
|
44400
44340
|
#agents = [];
|
|
44341
|
+
#originalTask;
|
|
44401
44342
|
constructor(config) {
|
|
44402
44343
|
this.#config = config;
|
|
44403
44344
|
}
|
|
@@ -44405,11 +44346,11 @@ class MultiAgent {
|
|
|
44405
44346
|
switch (exitReason.type) {
|
|
44406
44347
|
case "HandOver" /* HandOver */: {
|
|
44407
44348
|
this.#agents.pop();
|
|
44408
|
-
const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files,
|
|
44349
|
+
const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, this.#originalTask) ?? exitReason.task;
|
|
44409
44350
|
return await this.#startTask(exitReason.agentName, prompt);
|
|
44410
44351
|
}
|
|
44411
44352
|
case "Delegate" /* Delegate */: {
|
|
44412
|
-
const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files,
|
|
44353
|
+
const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, this.#originalTask) ?? exitReason.task;
|
|
44413
44354
|
const delegateResult = await this.#startTask(exitReason.agentName, prompt);
|
|
44414
44355
|
switch (delegateResult.type) {
|
|
44415
44356
|
case "HandOver" /* HandOver */:
|
|
@@ -44441,7 +44382,9 @@ class MultiAgent {
|
|
|
44441
44382
|
if (this.#agents.length > 0) {
|
|
44442
44383
|
throw new Error("An active agent already exists");
|
|
44443
44384
|
}
|
|
44444
|
-
|
|
44385
|
+
this.#originalTask = options.task;
|
|
44386
|
+
return this.#startTask(options.agentName, `<task>${options.task}</task>
|
|
44387
|
+
<context>${options.context}</context>`);
|
|
44445
44388
|
}
|
|
44446
44389
|
async continueTask(userMessage) {
|
|
44447
44390
|
if (!this.#agents.length) {
|
|
@@ -48859,8 +48802,8 @@ var executeAgentTool = async (definition, agent, params) => {
|
|
|
48859
48802
|
}
|
|
48860
48803
|
const exitReason = await agent.startTask({
|
|
48861
48804
|
agentName: definition.agent,
|
|
48862
|
-
task:
|
|
48863
|
-
|
|
48805
|
+
task: definition.prompt,
|
|
48806
|
+
context: definition.formatInput(params)
|
|
48864
48807
|
});
|
|
48865
48808
|
if (exitReason.type === "Exit" /* Exit */) {
|
|
48866
48809
|
return definition.parseOutput(exitReason.message);
|