@polka-codes/cli 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 +237 -294
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -38447,7 +38447,7 @@ var {
|
|
|
38447
38447
|
Help
|
|
38448
38448
|
} = import__.default;
|
|
38449
38449
|
// package.json
|
|
38450
|
-
var version = "0.8.
|
|
38450
|
+
var version = "0.8.19";
|
|
38451
38451
|
|
|
38452
38452
|
// ../core/src/AiService/AiServiceBase.ts
|
|
38453
38453
|
class AiServiceBase {
|
|
@@ -47746,13 +47746,13 @@ __export(exports_allTools, {
|
|
|
47746
47746
|
writeToFile: () => writeToFile_default,
|
|
47747
47747
|
updateKnowledge: () => updateKnowledge_default,
|
|
47748
47748
|
searchFiles: () => searchFiles_default,
|
|
47749
|
+
replaceInFile: () => replaceInFile_default,
|
|
47749
47750
|
renameFile: () => renameFile_default,
|
|
47750
47751
|
removeFile: () => removeFile_default,
|
|
47751
47752
|
readFile: () => readFile_default,
|
|
47752
47753
|
listFiles: () => listFiles_default,
|
|
47753
47754
|
handOver: () => handOver_default,
|
|
47754
47755
|
executeCommand: () => executeCommand_default,
|
|
47755
|
-
editFile: () => editFile_default,
|
|
47756
47756
|
delegate: () => delegate_default,
|
|
47757
47757
|
attemptCompletion: () => attemptCompletion_default,
|
|
47758
47758
|
askFollowupQuestion: () => askFollowupQuestion_default
|
|
@@ -47765,78 +47765,31 @@ var editFile = async (fileContent, operations) => {
|
|
|
47765
47765
|
if (!operations || operations.length === 0) {
|
|
47766
47766
|
throw new Error("At least one edit operation is required");
|
|
47767
47767
|
}
|
|
47768
|
-
const originalLines = fileContent.split(`
|
|
47769
|
-
`);
|
|
47770
47768
|
let updatedContent = fileContent;
|
|
47771
47769
|
for (const operation of operations) {
|
|
47772
|
-
updatedContent = await applyEditOperation(updatedContent, operation
|
|
47770
|
+
updatedContent = await applyEditOperation(updatedContent, operation);
|
|
47773
47771
|
}
|
|
47774
47772
|
return updatedContent;
|
|
47775
47773
|
};
|
|
47776
|
-
async function applyEditOperation(fileContent, operation
|
|
47777
|
-
const {
|
|
47778
|
-
if (
|
|
47779
|
-
|
|
47780
|
-
}
|
|
47781
|
-
if (start_anchor === START_OF_FILE) {
|
|
47782
|
-
if (!end_anchor) {
|
|
47783
|
-
return new_text + fileContent;
|
|
47784
|
-
}
|
|
47785
|
-
const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
|
|
47786
|
-
return new_text + fileContent.slice(afterIndex);
|
|
47787
|
-
}
|
|
47788
|
-
if (end_anchor === END_OF_FILE) {
|
|
47789
|
-
if (!start_anchor) {
|
|
47790
|
-
return fileContent + new_text;
|
|
47791
|
-
}
|
|
47792
|
-
const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
|
|
47793
|
-
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
47794
|
-
return fileContent.slice(0, beforeEndIndex) + new_text;
|
|
47795
|
-
}
|
|
47796
|
-
if (start_anchor && end_anchor) {
|
|
47797
|
-
const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
|
|
47798
|
-
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
47799
|
-
const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines, beforeEndIndex);
|
|
47800
|
-
return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(afterIndex);
|
|
47801
|
-
}
|
|
47802
|
-
if (start_anchor) {
|
|
47803
|
-
const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
|
|
47804
|
-
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
47805
|
-
return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(beforeEndIndex);
|
|
47806
|
-
}
|
|
47807
|
-
if (end_anchor) {
|
|
47808
|
-
const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
|
|
47809
|
-
return fileContent.slice(0, afterIndex) + new_text + fileContent.slice(afterIndex);
|
|
47810
|
-
}
|
|
47811
|
-
throw new Error("Either start_anchor or end_anchor must be specified");
|
|
47812
|
-
}
|
|
47813
|
-
function findTextWithHint(content, searchText, lineHint, originalLines, startIndex = 0) {
|
|
47814
|
-
if (lineHint && lineHint > 0 && lineHint <= originalLines.length) {
|
|
47815
|
-
const hintIndex = getLineStartIndex(originalLines, lineHint - 1);
|
|
47816
|
-
const searchRadius = 5;
|
|
47817
|
-
const windowStart = Math.max(0, hintIndex - searchRadius * 50);
|
|
47818
|
-
const windowEnd = Math.min(content.length, hintIndex + searchRadius * 50);
|
|
47819
|
-
const windowContent = content.slice(windowStart, windowEnd);
|
|
47820
|
-
const relativeIndex = windowContent.indexOf(searchText);
|
|
47821
|
-
if (relativeIndex !== -1) {
|
|
47822
|
-
const absoluteIndex = windowStart + relativeIndex;
|
|
47823
|
-
if (absoluteIndex >= startIndex) {
|
|
47824
|
-
return absoluteIndex;
|
|
47825
|
-
}
|
|
47826
|
-
}
|
|
47827
|
-
}
|
|
47828
|
-
const index = content.indexOf(searchText, startIndex);
|
|
47829
|
-
if (index === -1) {
|
|
47830
|
-
throw new Error(`Could not find text: ${searchText}`);
|
|
47774
|
+
async function applyEditOperation(fileContent, operation) {
|
|
47775
|
+
const { search, replace } = operation;
|
|
47776
|
+
if (search === START_OF_FILE && replace === END_OF_FILE) {
|
|
47777
|
+
throw new Error("Cannot search for START_OF_FILE and replace with END_OF_FILE");
|
|
47831
47778
|
}
|
|
47832
|
-
|
|
47833
|
-
|
|
47834
|
-
|
|
47835
|
-
|
|
47836
|
-
|
|
47837
|
-
|
|
47779
|
+
if (search === END_OF_FILE && replace === START_OF_FILE) {
|
|
47780
|
+
throw new Error("Cannot search for END_OF_FILE and replace with START_OF_FILE");
|
|
47781
|
+
}
|
|
47782
|
+
if (search === START_OF_FILE) {
|
|
47783
|
+
return replace + fileContent;
|
|
47784
|
+
}
|
|
47785
|
+
if (search === END_OF_FILE) {
|
|
47786
|
+
return fileContent + replace;
|
|
47838
47787
|
}
|
|
47839
|
-
|
|
47788
|
+
const index = fileContent.indexOf(search);
|
|
47789
|
+
if (index === -1) {
|
|
47790
|
+
throw new Error(`Could not find text: ${search}`);
|
|
47791
|
+
}
|
|
47792
|
+
return fileContent.slice(0, index) + replace + fileContent.slice(index + search.length);
|
|
47840
47793
|
}
|
|
47841
47794
|
// ../core/src/tools/utils/getArg.ts
|
|
47842
47795
|
var getString = (args, name, defaultValue) => {
|
|
@@ -48430,8 +48383,125 @@ var readFile_default = {
|
|
|
48430
48383
|
handler: handler6,
|
|
48431
48384
|
isAvailable: isAvailable6
|
|
48432
48385
|
};
|
|
48433
|
-
// ../core/src/tools/
|
|
48386
|
+
// ../core/src/tools/replaceInFile.ts
|
|
48434
48387
|
var toolInfo7 = {
|
|
48388
|
+
name: "replace_in_file",
|
|
48389
|
+
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.",
|
|
48390
|
+
parameters: [
|
|
48391
|
+
{
|
|
48392
|
+
name: "path",
|
|
48393
|
+
description: "The path of the file to modify",
|
|
48394
|
+
required: true,
|
|
48395
|
+
usageValue: "File path here"
|
|
48396
|
+
},
|
|
48397
|
+
{
|
|
48398
|
+
name: "diff",
|
|
48399
|
+
description: `One or more SEARCH/REPLACE blocks following this exact format:
|
|
48400
|
+
\`\`\`
|
|
48401
|
+
<<<<<<< SEARCH
|
|
48402
|
+
[exact content to find]
|
|
48403
|
+
=======
|
|
48404
|
+
[new content to replace with]
|
|
48405
|
+
>>>>>>> REPLACE
|
|
48406
|
+
\`\`\`
|
|
48407
|
+
Critical rules:
|
|
48408
|
+
1. SEARCH content must match the associated file section to find EXACTLY:
|
|
48409
|
+
* Match character-for-character including whitespace, indentation, line endings
|
|
48410
|
+
* Include all comments, docstrings, etc.
|
|
48411
|
+
2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
|
|
48412
|
+
* Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
|
|
48413
|
+
* Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
|
|
48414
|
+
* When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
|
|
48415
|
+
3. Keep SEARCH/REPLACE blocks concise:
|
|
48416
|
+
* Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
|
|
48417
|
+
* Include just the changing lines, and a few surrounding lines if needed for uniqueness.
|
|
48418
|
+
* Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
|
|
48419
|
+
* Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
|
|
48420
|
+
4. Special operations:
|
|
48421
|
+
* To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
|
|
48422
|
+
* To delete code: Use empty REPLACE section`,
|
|
48423
|
+
required: true,
|
|
48424
|
+
usageValue: "Search and replace blocks here"
|
|
48425
|
+
}
|
|
48426
|
+
],
|
|
48427
|
+
examples: [
|
|
48428
|
+
{
|
|
48429
|
+
description: "Request to replace sections of content in a file",
|
|
48430
|
+
parameters: [
|
|
48431
|
+
{
|
|
48432
|
+
name: "path",
|
|
48433
|
+
value: "src/main.js"
|
|
48434
|
+
},
|
|
48435
|
+
{
|
|
48436
|
+
name: "diff",
|
|
48437
|
+
value: `
|
|
48438
|
+
<<<<<<< SEARCH
|
|
48439
|
+
import React from 'react';
|
|
48440
|
+
=======
|
|
48441
|
+
import React, { useState } from 'react';
|
|
48442
|
+
>>>>>>> REPLACE
|
|
48443
|
+
|
|
48444
|
+
<<<<<<< SEARCH
|
|
48445
|
+
function handleSubmit() {
|
|
48446
|
+
saveData();
|
|
48447
|
+
setLoading(false);
|
|
48448
|
+
}
|
|
48449
|
+
|
|
48450
|
+
=======
|
|
48451
|
+
>>>>>>> REPLACE
|
|
48452
|
+
|
|
48453
|
+
<<<<<<< SEARCH
|
|
48454
|
+
return (
|
|
48455
|
+
<div>
|
|
48456
|
+
=======
|
|
48457
|
+
function handleSubmit() {
|
|
48458
|
+
saveData();
|
|
48459
|
+
setLoading(false);
|
|
48460
|
+
}
|
|
48461
|
+
|
|
48462
|
+
return (
|
|
48463
|
+
<div>
|
|
48464
|
+
>>>>>>> REPLACE
|
|
48465
|
+
`
|
|
48466
|
+
}
|
|
48467
|
+
]
|
|
48468
|
+
}
|
|
48469
|
+
],
|
|
48470
|
+
permissionLevel: 2 /* Write */
|
|
48471
|
+
};
|
|
48472
|
+
var handler7 = async (provider, args) => {
|
|
48473
|
+
if (!provider.readFile || !provider.writeFile) {
|
|
48474
|
+
return {
|
|
48475
|
+
type: "Error" /* Error */,
|
|
48476
|
+
message: "Not possible to replace in file. Abort."
|
|
48477
|
+
};
|
|
48478
|
+
}
|
|
48479
|
+
const path = getString(args, "path");
|
|
48480
|
+
const diff = getString(args, "diff");
|
|
48481
|
+
const fileContent = await provider.readFile(path);
|
|
48482
|
+
if (fileContent == null) {
|
|
48483
|
+
return {
|
|
48484
|
+
type: "Error" /* Error */,
|
|
48485
|
+
message: `<error><replace_in_file_path>${path}</replace_in_file_path><error_message>File not found</error_message></error>`
|
|
48486
|
+
};
|
|
48487
|
+
}
|
|
48488
|
+
const result = await replaceInFile(fileContent, diff);
|
|
48489
|
+
await provider.writeFile(path, result);
|
|
48490
|
+
return {
|
|
48491
|
+
type: "Reply" /* Reply */,
|
|
48492
|
+
message: `<replace_in_file_path>${path}</replace_in_file_path>`
|
|
48493
|
+
};
|
|
48494
|
+
};
|
|
48495
|
+
var isAvailable7 = (provider) => {
|
|
48496
|
+
return !!provider.readFile && !!provider.writeFile;
|
|
48497
|
+
};
|
|
48498
|
+
var replaceInFile_default = {
|
|
48499
|
+
...toolInfo7,
|
|
48500
|
+
handler: handler7,
|
|
48501
|
+
isAvailable: isAvailable7
|
|
48502
|
+
};
|
|
48503
|
+
// ../core/src/tools/searchFiles.ts
|
|
48504
|
+
var toolInfo8 = {
|
|
48435
48505
|
name: "search_files",
|
|
48436
48506
|
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.",
|
|
48437
48507
|
parameters: [
|
|
@@ -48475,7 +48545,7 @@ var toolInfo7 = {
|
|
|
48475
48545
|
],
|
|
48476
48546
|
permissionLevel: 1 /* Read */
|
|
48477
48547
|
};
|
|
48478
|
-
var
|
|
48548
|
+
var handler8 = async (provider, args) => {
|
|
48479
48549
|
if (!provider.searchFiles) {
|
|
48480
48550
|
return {
|
|
48481
48551
|
type: "Error" /* Error */,
|
|
@@ -48498,18 +48568,18 @@ ${files.join(`
|
|
|
48498
48568
|
`
|
|
48499
48569
|
};
|
|
48500
48570
|
};
|
|
48501
|
-
var
|
|
48571
|
+
var isAvailable8 = (provider) => {
|
|
48502
48572
|
return !!provider.searchFiles;
|
|
48503
48573
|
};
|
|
48504
48574
|
var searchFiles_default = {
|
|
48505
|
-
...
|
|
48506
|
-
handler:
|
|
48507
|
-
isAvailable:
|
|
48575
|
+
...toolInfo8,
|
|
48576
|
+
handler: handler8,
|
|
48577
|
+
isAvailable: isAvailable8
|
|
48508
48578
|
};
|
|
48509
48579
|
// ../core/src/tools/updateKnowledge.ts
|
|
48510
48580
|
var import_yaml = __toESM(require_dist(), 1);
|
|
48511
48581
|
import { join } from "node:path";
|
|
48512
|
-
var
|
|
48582
|
+
var toolInfo9 = {
|
|
48513
48583
|
name: "update_knowledge",
|
|
48514
48584
|
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.",
|
|
48515
48585
|
parameters: [
|
|
@@ -48686,7 +48756,7 @@ function deepMerge(target, source) {
|
|
|
48686
48756
|
}
|
|
48687
48757
|
return output;
|
|
48688
48758
|
}
|
|
48689
|
-
var
|
|
48759
|
+
var handler9 = async (provider, args) => {
|
|
48690
48760
|
if (!provider.readFile || !provider.writeFile) {
|
|
48691
48761
|
return {
|
|
48692
48762
|
type: "Error" /* Error */,
|
|
@@ -48758,16 +48828,16 @@ var handler8 = async (provider, args) => {
|
|
|
48758
48828
|
};
|
|
48759
48829
|
}
|
|
48760
48830
|
};
|
|
48761
|
-
var
|
|
48831
|
+
var isAvailable9 = (provider) => {
|
|
48762
48832
|
return !!provider.readFile && !!provider.writeFile;
|
|
48763
48833
|
};
|
|
48764
48834
|
var updateKnowledge_default = {
|
|
48765
|
-
...
|
|
48766
|
-
handler:
|
|
48767
|
-
isAvailable:
|
|
48835
|
+
...toolInfo9,
|
|
48836
|
+
handler: handler9,
|
|
48837
|
+
isAvailable: isAvailable9
|
|
48768
48838
|
};
|
|
48769
48839
|
// ../core/src/tools/writeToFile.ts
|
|
48770
|
-
var
|
|
48840
|
+
var toolInfo10 = {
|
|
48771
48841
|
name: "write_to_file",
|
|
48772
48842
|
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 `>`.",
|
|
48773
48843
|
parameters: [
|
|
@@ -48812,7 +48882,7 @@ export default App;
|
|
|
48812
48882
|
],
|
|
48813
48883
|
permissionLevel: 2 /* Write */
|
|
48814
48884
|
};
|
|
48815
|
-
var
|
|
48885
|
+
var handler10 = async (provider, args) => {
|
|
48816
48886
|
if (!provider.writeFile) {
|
|
48817
48887
|
return {
|
|
48818
48888
|
type: "Error" /* Error */,
|
|
@@ -48827,16 +48897,16 @@ var handler9 = async (provider, args) => {
|
|
|
48827
48897
|
message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
|
|
48828
48898
|
};
|
|
48829
48899
|
};
|
|
48830
|
-
var
|
|
48900
|
+
var isAvailable10 = (provider) => {
|
|
48831
48901
|
return !!provider.writeFile;
|
|
48832
48902
|
};
|
|
48833
48903
|
var writeToFile_default = {
|
|
48834
|
-
...
|
|
48835
|
-
handler:
|
|
48836
|
-
isAvailable:
|
|
48904
|
+
...toolInfo10,
|
|
48905
|
+
handler: handler10,
|
|
48906
|
+
isAvailable: isAvailable10
|
|
48837
48907
|
};
|
|
48838
48908
|
// ../core/src/tools/handOver.ts
|
|
48839
|
-
var
|
|
48909
|
+
var toolInfo11 = {
|
|
48840
48910
|
name: "hand_over",
|
|
48841
48911
|
description: "Hand over the current task to another agent to complete. This tool MUST NOT to be used with any other tool.",
|
|
48842
48912
|
parameters: [
|
|
@@ -48890,7 +48960,7 @@ var toolInfo10 = {
|
|
|
48890
48960
|
],
|
|
48891
48961
|
permissionLevel: 0 /* None */
|
|
48892
48962
|
};
|
|
48893
|
-
var
|
|
48963
|
+
var handler11 = async (_provider, args) => {
|
|
48894
48964
|
const agentName = getString(args, "agent_name");
|
|
48895
48965
|
const task = getString(args, "task");
|
|
48896
48966
|
const context = getString(args, "context", undefined);
|
|
@@ -48903,16 +48973,16 @@ var handler10 = async (_provider, args) => {
|
|
|
48903
48973
|
files
|
|
48904
48974
|
};
|
|
48905
48975
|
};
|
|
48906
|
-
var
|
|
48976
|
+
var isAvailable11 = (_provider) => {
|
|
48907
48977
|
return true;
|
|
48908
48978
|
};
|
|
48909
48979
|
var handOver_default = {
|
|
48910
|
-
...
|
|
48911
|
-
handler:
|
|
48912
|
-
isAvailable:
|
|
48980
|
+
...toolInfo11,
|
|
48981
|
+
handler: handler11,
|
|
48982
|
+
isAvailable: isAvailable11
|
|
48913
48983
|
};
|
|
48914
48984
|
// ../core/src/tools/removeFile.ts
|
|
48915
|
-
var
|
|
48985
|
+
var toolInfo12 = {
|
|
48916
48986
|
name: "remove_file",
|
|
48917
48987
|
description: "Request to remove a file at the specified path.",
|
|
48918
48988
|
parameters: [
|
|
@@ -48936,7 +49006,7 @@ var toolInfo11 = {
|
|
|
48936
49006
|
],
|
|
48937
49007
|
permissionLevel: 2 /* Write */
|
|
48938
49008
|
};
|
|
48939
|
-
var
|
|
49009
|
+
var handler12 = async (provider, args) => {
|
|
48940
49010
|
if (!provider.removeFile) {
|
|
48941
49011
|
return {
|
|
48942
49012
|
type: "Error" /* Error */,
|
|
@@ -48950,16 +49020,16 @@ var handler11 = async (provider, args) => {
|
|
|
48950
49020
|
message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
|
|
48951
49021
|
};
|
|
48952
49022
|
};
|
|
48953
|
-
var
|
|
49023
|
+
var isAvailable12 = (provider) => {
|
|
48954
49024
|
return !!provider.removeFile;
|
|
48955
49025
|
};
|
|
48956
49026
|
var removeFile_default = {
|
|
48957
|
-
...
|
|
48958
|
-
handler:
|
|
48959
|
-
isAvailable:
|
|
49027
|
+
...toolInfo12,
|
|
49028
|
+
handler: handler12,
|
|
49029
|
+
isAvailable: isAvailable12
|
|
48960
49030
|
};
|
|
48961
49031
|
// ../core/src/tools/renameFile.ts
|
|
48962
|
-
var
|
|
49032
|
+
var toolInfo13 = {
|
|
48963
49033
|
name: "rename_file",
|
|
48964
49034
|
description: "Request to rename a file from source path to target path.",
|
|
48965
49035
|
parameters: [
|
|
@@ -48993,7 +49063,7 @@ var toolInfo12 = {
|
|
|
48993
49063
|
],
|
|
48994
49064
|
permissionLevel: 2 /* Write */
|
|
48995
49065
|
};
|
|
48996
|
-
var
|
|
49066
|
+
var handler13 = async (provider, args) => {
|
|
48997
49067
|
if (!provider.renameFile) {
|
|
48998
49068
|
return {
|
|
48999
49069
|
type: "Error" /* Error */,
|
|
@@ -49008,18 +49078,18 @@ var handler12 = async (provider, args) => {
|
|
|
49008
49078
|
message: `<rename_file_path>${targetPath}</rename_file_path><status>Success</status>`
|
|
49009
49079
|
};
|
|
49010
49080
|
};
|
|
49011
|
-
var
|
|
49081
|
+
var isAvailable13 = (provider) => {
|
|
49012
49082
|
return !!provider.renameFile;
|
|
49013
49083
|
};
|
|
49014
49084
|
var renameFile_default = {
|
|
49015
|
-
...
|
|
49016
|
-
handler:
|
|
49017
|
-
isAvailable:
|
|
49085
|
+
...toolInfo13,
|
|
49086
|
+
handler: handler13,
|
|
49087
|
+
isAvailable: isAvailable13
|
|
49018
49088
|
};
|
|
49019
49089
|
// ../core/src/tools/editFile.ts
|
|
49020
|
-
var
|
|
49090
|
+
var toolInfo14 = {
|
|
49021
49091
|
name: "edit_file",
|
|
49022
|
-
description: "Request to edit file contents using
|
|
49092
|
+
description: "Request to edit file contents using search/replace operations. Supports multiple edit operations in a single call.",
|
|
49023
49093
|
parameters: [
|
|
49024
49094
|
{
|
|
49025
49095
|
name: "path",
|
|
@@ -49029,39 +49099,21 @@ var toolInfo13 = {
|
|
|
49029
49099
|
},
|
|
49030
49100
|
{
|
|
49031
49101
|
name: "operations",
|
|
49032
|
-
description: "Edit operation with
|
|
49102
|
+
description: "Edit operation with search and replace parameters",
|
|
49033
49103
|
required: true,
|
|
49034
49104
|
allowMultiple: true,
|
|
49035
49105
|
children: [
|
|
49036
49106
|
{
|
|
49037
|
-
name: "
|
|
49038
|
-
description: `Text to
|
|
49039
|
-
required: false,
|
|
49040
|
-
usageValue: "Text before the edit location"
|
|
49041
|
-
},
|
|
49042
|
-
{
|
|
49043
|
-
name: "end_anchor",
|
|
49044
|
-
description: `Text to find as the end anchor (use ${END_OF_FILE} for file end)`,
|
|
49045
|
-
required: false,
|
|
49046
|
-
usageValue: "Text after the edit location"
|
|
49047
|
-
},
|
|
49048
|
-
{
|
|
49049
|
-
name: "new_text",
|
|
49050
|
-
description: "Text to replace the content between start_anchor and end_anchor",
|
|
49107
|
+
name: "search",
|
|
49108
|
+
description: `Text to search for and replace (use ${START_OF_FILE} to insert at file start, ${END_OF_FILE} to insert at file end)`,
|
|
49051
49109
|
required: true,
|
|
49052
|
-
usageValue: "
|
|
49053
|
-
},
|
|
49054
|
-
{
|
|
49055
|
-
name: "start_anchor_line_start",
|
|
49056
|
-
description: "Optional line number hint for start_anchor location (1-based)",
|
|
49057
|
-
required: false,
|
|
49058
|
-
usageValue: "10"
|
|
49110
|
+
usageValue: "Text to find and replace"
|
|
49059
49111
|
},
|
|
49060
49112
|
{
|
|
49061
|
-
name: "
|
|
49062
|
-
description: "
|
|
49063
|
-
required:
|
|
49064
|
-
usageValue: "
|
|
49113
|
+
name: "replace",
|
|
49114
|
+
description: "Text to replace the search text with",
|
|
49115
|
+
required: true,
|
|
49116
|
+
usageValue: "Replacement text"
|
|
49065
49117
|
}
|
|
49066
49118
|
],
|
|
49067
49119
|
usageValue: "operations here"
|
|
@@ -49069,7 +49121,7 @@ var toolInfo13 = {
|
|
|
49069
49121
|
],
|
|
49070
49122
|
examples: [
|
|
49071
49123
|
{
|
|
49072
|
-
description: "Replace
|
|
49124
|
+
description: "Replace specific text",
|
|
49073
49125
|
parameters: [
|
|
49074
49126
|
{
|
|
49075
49127
|
name: "path",
|
|
@@ -49078,11 +49130,12 @@ var toolInfo13 = {
|
|
|
49078
49130
|
{
|
|
49079
49131
|
name: "operations",
|
|
49080
49132
|
value: {
|
|
49081
|
-
|
|
49082
|
-
|
|
49083
|
-
|
|
49133
|
+
search: `function oldFunction() {
|
|
49134
|
+
return 42;
|
|
49135
|
+
}`,
|
|
49136
|
+
replace: `function newFunction() {
|
|
49084
49137
|
return "new implementation";
|
|
49085
|
-
`
|
|
49138
|
+
}`
|
|
49086
49139
|
}
|
|
49087
49140
|
}
|
|
49088
49141
|
]
|
|
@@ -49097,9 +49150,8 @@ var toolInfo13 = {
|
|
|
49097
49150
|
{
|
|
49098
49151
|
name: "operations",
|
|
49099
49152
|
value: {
|
|
49100
|
-
|
|
49101
|
-
|
|
49102
|
-
new_text: `// File header comment
|
|
49153
|
+
search: START_OF_FILE,
|
|
49154
|
+
replace: `// File header comment
|
|
49103
49155
|
`
|
|
49104
49156
|
}
|
|
49105
49157
|
}
|
|
@@ -49116,25 +49168,42 @@ var toolInfo13 = {
|
|
|
49116
49168
|
name: "operations",
|
|
49117
49169
|
value: [
|
|
49118
49170
|
{
|
|
49119
|
-
|
|
49120
|
-
|
|
49121
|
-
new_text: ", { useState }"
|
|
49171
|
+
search: 'import React from "react"',
|
|
49172
|
+
replace: 'import React, { useState } from "react"'
|
|
49122
49173
|
},
|
|
49123
49174
|
{
|
|
49124
|
-
|
|
49125
|
-
|
|
49126
|
-
|
|
49175
|
+
search: `function Component() {
|
|
49176
|
+
return (`,
|
|
49177
|
+
replace: `function Component() {
|
|
49127
49178
|
const [state, setState] = useState(false);
|
|
49128
|
-
`
|
|
49179
|
+
return (`
|
|
49129
49180
|
}
|
|
49130
49181
|
]
|
|
49131
49182
|
}
|
|
49132
49183
|
]
|
|
49184
|
+
},
|
|
49185
|
+
{
|
|
49186
|
+
description: "Append content at end of file",
|
|
49187
|
+
parameters: [
|
|
49188
|
+
{
|
|
49189
|
+
name: "path",
|
|
49190
|
+
value: "src/footer.ts"
|
|
49191
|
+
},
|
|
49192
|
+
{
|
|
49193
|
+
name: "operations",
|
|
49194
|
+
value: {
|
|
49195
|
+
search: END_OF_FILE,
|
|
49196
|
+
replace: `
|
|
49197
|
+
// End of file appended comment
|
|
49198
|
+
`
|
|
49199
|
+
}
|
|
49200
|
+
}
|
|
49201
|
+
]
|
|
49133
49202
|
}
|
|
49134
49203
|
],
|
|
49135
49204
|
permissionLevel: 2 /* Write */
|
|
49136
49205
|
};
|
|
49137
|
-
var
|
|
49206
|
+
var handler14 = async (provider, args) => {
|
|
49138
49207
|
if (!provider.readFile || !provider.writeFile) {
|
|
49139
49208
|
return {
|
|
49140
49209
|
type: "Error" /* Error */,
|
|
@@ -49170,127 +49239,10 @@ var handler13 = async (provider, args) => {
|
|
|
49170
49239
|
};
|
|
49171
49240
|
}
|
|
49172
49241
|
};
|
|
49173
|
-
var isAvailable13 = (provider) => {
|
|
49174
|
-
return !!provider.readFile && !!provider.writeFile;
|
|
49175
|
-
};
|
|
49176
|
-
var editFile_default = {
|
|
49177
|
-
...toolInfo13,
|
|
49178
|
-
handler: handler13,
|
|
49179
|
-
isAvailable: isAvailable13
|
|
49180
|
-
};
|
|
49181
|
-
// ../core/src/tools/replaceInFile.ts
|
|
49182
|
-
var toolInfo14 = {
|
|
49183
|
-
name: "replace_in_file",
|
|
49184
|
-
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.",
|
|
49185
|
-
parameters: [
|
|
49186
|
-
{
|
|
49187
|
-
name: "path",
|
|
49188
|
-
description: "The path of the file to modify",
|
|
49189
|
-
required: true,
|
|
49190
|
-
usageValue: "File path here"
|
|
49191
|
-
},
|
|
49192
|
-
{
|
|
49193
|
-
name: "diff",
|
|
49194
|
-
description: `One or more SEARCH/REPLACE blocks following this exact format:
|
|
49195
|
-
\`\`\`
|
|
49196
|
-
<<<<<<< SEARCH
|
|
49197
|
-
[exact content to find]
|
|
49198
|
-
=======
|
|
49199
|
-
[new content to replace with]
|
|
49200
|
-
>>>>>>> REPLACE
|
|
49201
|
-
\`\`\`
|
|
49202
|
-
Critical rules:
|
|
49203
|
-
1. SEARCH content must match the associated file section to find EXACTLY:
|
|
49204
|
-
* Match character-for-character including whitespace, indentation, line endings
|
|
49205
|
-
* Include all comments, docstrings, etc.
|
|
49206
|
-
2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
|
|
49207
|
-
* Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
|
|
49208
|
-
* Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
|
|
49209
|
-
* When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
|
|
49210
|
-
3. Keep SEARCH/REPLACE blocks concise:
|
|
49211
|
-
* Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
|
|
49212
|
-
* Include just the changing lines, and a few surrounding lines if needed for uniqueness.
|
|
49213
|
-
* Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
|
|
49214
|
-
* Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
|
|
49215
|
-
4. Special operations:
|
|
49216
|
-
* To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
|
|
49217
|
-
* To delete code: Use empty REPLACE section`,
|
|
49218
|
-
required: true,
|
|
49219
|
-
usageValue: "Search and replace blocks here"
|
|
49220
|
-
}
|
|
49221
|
-
],
|
|
49222
|
-
examples: [
|
|
49223
|
-
{
|
|
49224
|
-
description: "Request to replace sections of content in a file",
|
|
49225
|
-
parameters: [
|
|
49226
|
-
{
|
|
49227
|
-
name: "path",
|
|
49228
|
-
value: "src/main.js"
|
|
49229
|
-
},
|
|
49230
|
-
{
|
|
49231
|
-
name: "diff",
|
|
49232
|
-
value: `
|
|
49233
|
-
<<<<<<< SEARCH
|
|
49234
|
-
import React from 'react';
|
|
49235
|
-
=======
|
|
49236
|
-
import React, { useState } from 'react';
|
|
49237
|
-
>>>>>>> REPLACE
|
|
49238
|
-
|
|
49239
|
-
<<<<<<< SEARCH
|
|
49240
|
-
function handleSubmit() {
|
|
49241
|
-
saveData();
|
|
49242
|
-
setLoading(false);
|
|
49243
|
-
}
|
|
49244
|
-
|
|
49245
|
-
=======
|
|
49246
|
-
>>>>>>> REPLACE
|
|
49247
|
-
|
|
49248
|
-
<<<<<<< SEARCH
|
|
49249
|
-
return (
|
|
49250
|
-
<div>
|
|
49251
|
-
=======
|
|
49252
|
-
function handleSubmit() {
|
|
49253
|
-
saveData();
|
|
49254
|
-
setLoading(false);
|
|
49255
|
-
}
|
|
49256
|
-
|
|
49257
|
-
return (
|
|
49258
|
-
<div>
|
|
49259
|
-
>>>>>>> REPLACE
|
|
49260
|
-
`
|
|
49261
|
-
}
|
|
49262
|
-
]
|
|
49263
|
-
}
|
|
49264
|
-
],
|
|
49265
|
-
permissionLevel: 2 /* Write */
|
|
49266
|
-
};
|
|
49267
|
-
var handler14 = async (provider, args) => {
|
|
49268
|
-
if (!provider.readFile || !provider.writeFile) {
|
|
49269
|
-
return {
|
|
49270
|
-
type: "Error" /* Error */,
|
|
49271
|
-
message: "Not possible to replace in file. Abort."
|
|
49272
|
-
};
|
|
49273
|
-
}
|
|
49274
|
-
const path = getString(args, "path");
|
|
49275
|
-
const diff = getString(args, "diff");
|
|
49276
|
-
const fileContent = await provider.readFile(path);
|
|
49277
|
-
if (fileContent == null) {
|
|
49278
|
-
return {
|
|
49279
|
-
type: "Error" /* Error */,
|
|
49280
|
-
message: `<error><replace_in_file_path>${path}</replace_in_file_path><error_message>File not found</error_message></error>`
|
|
49281
|
-
};
|
|
49282
|
-
}
|
|
49283
|
-
const result = await replaceInFile(fileContent, diff);
|
|
49284
|
-
await provider.writeFile(path, result);
|
|
49285
|
-
return {
|
|
49286
|
-
type: "Reply" /* Reply */,
|
|
49287
|
-
message: `<replace_in_file_path>${path}</replace_in_file_path>`
|
|
49288
|
-
};
|
|
49289
|
-
};
|
|
49290
49242
|
var isAvailable14 = (provider) => {
|
|
49291
49243
|
return !!provider.readFile && !!provider.writeFile;
|
|
49292
49244
|
};
|
|
49293
|
-
var
|
|
49245
|
+
var editFile_default = {
|
|
49294
49246
|
...toolInfo14,
|
|
49295
49247
|
handler: handler14,
|
|
49296
49248
|
isAvailable: isAvailable14
|
|
@@ -49676,7 +49628,6 @@ class AgentBase {
|
|
|
49676
49628
|
config;
|
|
49677
49629
|
handlers;
|
|
49678
49630
|
#messages = [];
|
|
49679
|
-
#originalTask;
|
|
49680
49631
|
#policies;
|
|
49681
49632
|
constructor(name, ai, config) {
|
|
49682
49633
|
this.ai = ai;
|
|
@@ -49722,7 +49673,6 @@ ${instance.prompt}`;
|
|
|
49722
49673
|
await this.config.callback?.(event);
|
|
49723
49674
|
}
|
|
49724
49675
|
async start(prompt) {
|
|
49725
|
-
this.#originalTask = prompt;
|
|
49726
49676
|
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
49727
49677
|
return await this.#processLoop(prompt);
|
|
49728
49678
|
}
|
|
@@ -49849,41 +49799,31 @@ ${instance.prompt}`;
|
|
|
49849
49799
|
if (toolResponses.length > 0) {
|
|
49850
49800
|
break outer;
|
|
49851
49801
|
}
|
|
49852
|
-
const handOverResp = {
|
|
49853
|
-
...toolResp,
|
|
49854
|
-
originalTask: this.#originalTask
|
|
49855
|
-
};
|
|
49856
49802
|
await this.#callback({
|
|
49857
49803
|
kind: "ToolHandOver" /* ToolHandOver */,
|
|
49858
49804
|
agent: this,
|
|
49859
49805
|
tool: content.name,
|
|
49860
|
-
agentName:
|
|
49861
|
-
task:
|
|
49862
|
-
context:
|
|
49863
|
-
files:
|
|
49864
|
-
originalTask: handOverResp.originalTask
|
|
49806
|
+
agentName: toolResp.agentName,
|
|
49807
|
+
task: toolResp.task,
|
|
49808
|
+
context: toolResp.context,
|
|
49809
|
+
files: toolResp.files
|
|
49865
49810
|
});
|
|
49866
|
-
return { type: "exit", reason:
|
|
49811
|
+
return { type: "exit", reason: toolResp };
|
|
49867
49812
|
}
|
|
49868
49813
|
case "Delegate" /* Delegate */: {
|
|
49869
49814
|
if (toolResponses.length > 0) {
|
|
49870
49815
|
break outer;
|
|
49871
49816
|
}
|
|
49872
|
-
const delegateResp = {
|
|
49873
|
-
...toolResp,
|
|
49874
|
-
originalTask: this.#originalTask
|
|
49875
|
-
};
|
|
49876
49817
|
await this.#callback({
|
|
49877
49818
|
kind: "ToolDelegate" /* ToolDelegate */,
|
|
49878
49819
|
agent: this,
|
|
49879
49820
|
tool: content.name,
|
|
49880
|
-
agentName:
|
|
49881
|
-
task:
|
|
49882
|
-
context:
|
|
49883
|
-
files:
|
|
49884
|
-
originalTask: delegateResp.originalTask
|
|
49821
|
+
agentName: toolResp.agentName,
|
|
49822
|
+
task: toolResp.task,
|
|
49823
|
+
context: toolResp.context,
|
|
49824
|
+
files: toolResp.files
|
|
49885
49825
|
});
|
|
49886
|
-
return { type: "exit", reason:
|
|
49826
|
+
return { type: "exit", reason: toolResp };
|
|
49887
49827
|
}
|
|
49888
49828
|
case "Pause" /* Pause */: {
|
|
49889
49829
|
await this.#callback({ kind: "ToolPause" /* ToolPause */, agent: this, tool: content.name, object: toolResp.object });
|
|
@@ -50463,6 +50403,7 @@ var coderAgentInfo = {
|
|
|
50463
50403
|
class MultiAgent {
|
|
50464
50404
|
#config;
|
|
50465
50405
|
#agents = [];
|
|
50406
|
+
#originalTask;
|
|
50466
50407
|
constructor(config) {
|
|
50467
50408
|
this.#config = config;
|
|
50468
50409
|
}
|
|
@@ -50470,11 +50411,11 @@ class MultiAgent {
|
|
|
50470
50411
|
switch (exitReason.type) {
|
|
50471
50412
|
case "HandOver" /* HandOver */: {
|
|
50472
50413
|
this.#agents.pop();
|
|
50473
|
-
const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files,
|
|
50414
|
+
const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, this.#originalTask) ?? exitReason.task;
|
|
50474
50415
|
return await this.#startTask(exitReason.agentName, prompt);
|
|
50475
50416
|
}
|
|
50476
50417
|
case "Delegate" /* Delegate */: {
|
|
50477
|
-
const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files,
|
|
50418
|
+
const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, this.#originalTask) ?? exitReason.task;
|
|
50478
50419
|
const delegateResult = await this.#startTask(exitReason.agentName, prompt);
|
|
50479
50420
|
switch (delegateResult.type) {
|
|
50480
50421
|
case "HandOver" /* HandOver */:
|
|
@@ -50506,7 +50447,9 @@ class MultiAgent {
|
|
|
50506
50447
|
if (this.#agents.length > 0) {
|
|
50507
50448
|
throw new Error("An active agent already exists");
|
|
50508
50449
|
}
|
|
50509
|
-
|
|
50450
|
+
this.#originalTask = options.task;
|
|
50451
|
+
return this.#startTask(options.agentName, `<task>${options.task}</task>
|
|
50452
|
+
<context>${options.context}</context>`);
|
|
50510
50453
|
}
|
|
50511
50454
|
async continueTask(userMessage) {
|
|
50512
50455
|
if (!this.#agents.length) {
|
|
@@ -55132,8 +55075,8 @@ var executeAgentTool = async (definition, agent, params) => {
|
|
|
55132
55075
|
}
|
|
55133
55076
|
const exitReason = await agent.startTask({
|
|
55134
55077
|
agentName: definition.agent,
|
|
55135
|
-
task:
|
|
55136
|
-
|
|
55078
|
+
task: definition.prompt,
|
|
55079
|
+
context: definition.formatInput(params)
|
|
55137
55080
|
});
|
|
55138
55081
|
if (exitReason.type === "Exit" /* Exit */) {
|
|
55139
55082
|
return definition.parseOutput(exitReason.message);
|
|
@@ -61660,8 +61603,8 @@ ${fileList.join(`
|
|
|
61660
61603
|
const finalContext = await this.#defaultContext(agentName);
|
|
61661
61604
|
const exitReason = await this.multiAgent.startTask({
|
|
61662
61605
|
agentName,
|
|
61663
|
-
task
|
|
61664
|
-
|
|
61606
|
+
task,
|
|
61607
|
+
context: finalContext
|
|
61665
61608
|
});
|
|
61666
61609
|
return exitReason;
|
|
61667
61610
|
}
|