@polka-codes/cli 0.8.11 → 0.8.13
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 +556 -247
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -38429,7 +38429,7 @@ var require_public_api4 = __commonJS((exports) => {
|
|
|
38429
38429
|
});
|
|
38430
38430
|
|
|
38431
38431
|
// src/index.ts
|
|
38432
|
-
var
|
|
38432
|
+
var import_config3 = __toESM(require_config(), 1);
|
|
38433
38433
|
|
|
38434
38434
|
// ../../node_modules/commander/esm.mjs
|
|
38435
38435
|
var import__ = __toESM(require_commander(), 1);
|
|
@@ -38447,13 +38447,15 @@ var {
|
|
|
38447
38447
|
Help
|
|
38448
38448
|
} = import__.default;
|
|
38449
38449
|
// package.json
|
|
38450
|
-
var version = "0.8.
|
|
38450
|
+
var version = "0.8.13";
|
|
38451
38451
|
|
|
38452
38452
|
// ../core/src/AiService/AiServiceBase.ts
|
|
38453
38453
|
class AiServiceBase {
|
|
38454
38454
|
usageMeter;
|
|
38455
|
-
|
|
38456
|
-
|
|
38455
|
+
options;
|
|
38456
|
+
constructor(options) {
|
|
38457
|
+
this.options = options;
|
|
38458
|
+
this.usageMeter = options.usageMeter;
|
|
38457
38459
|
}
|
|
38458
38460
|
async* send(systemPrompt, messages) {
|
|
38459
38461
|
this.usageMeter.checkLimit();
|
|
@@ -41939,7 +41941,7 @@ class AnthropicService extends AiServiceBase {
|
|
|
41939
41941
|
#client;
|
|
41940
41942
|
model;
|
|
41941
41943
|
constructor(options) {
|
|
41942
|
-
super(options
|
|
41944
|
+
super(options);
|
|
41943
41945
|
this.#options = options;
|
|
41944
41946
|
this.#client = new Anthropic({
|
|
41945
41947
|
apiKey: options.apiKey,
|
|
@@ -47366,7 +47368,7 @@ class DeepSeekService extends AiServiceBase {
|
|
|
47366
47368
|
#client;
|
|
47367
47369
|
model;
|
|
47368
47370
|
constructor(options) {
|
|
47369
|
-
super(options
|
|
47371
|
+
super(options);
|
|
47370
47372
|
this.#client = new openai_default({
|
|
47371
47373
|
baseURL: "https://api.deepseek.com/v1",
|
|
47372
47374
|
apiKey: options.apiKey
|
|
@@ -47423,7 +47425,7 @@ class OllamaService extends AiServiceBase {
|
|
|
47423
47425
|
#client;
|
|
47424
47426
|
model;
|
|
47425
47427
|
constructor(options) {
|
|
47426
|
-
super(options
|
|
47428
|
+
super(options);
|
|
47427
47429
|
this.#client = new openai_default({
|
|
47428
47430
|
baseURL: `${options.baseUrl || "http://localhost:11434"}/v1`,
|
|
47429
47431
|
apiKey: "ollama"
|
|
@@ -47465,7 +47467,7 @@ class OpenRouterService extends AiServiceBase {
|
|
|
47465
47467
|
#modelProviderInfo;
|
|
47466
47468
|
model;
|
|
47467
47469
|
constructor(options) {
|
|
47468
|
-
super(options
|
|
47470
|
+
super(options);
|
|
47469
47471
|
if (!options.model) {
|
|
47470
47472
|
throw new Error("OpenRouter requires a model");
|
|
47471
47473
|
}
|
|
@@ -47757,73 +47759,98 @@ __export(exports_allTools, {
|
|
|
47757
47759
|
writeToFile: () => writeToFile_default,
|
|
47758
47760
|
updateKnowledge: () => updateKnowledge_default,
|
|
47759
47761
|
searchFiles: () => searchFiles_default,
|
|
47760
|
-
replaceInFile: () => replaceInFile_default,
|
|
47761
47762
|
renameFile: () => renameFile_default,
|
|
47762
47763
|
removeFile: () => removeFile_default,
|
|
47763
47764
|
readFile: () => readFile_default,
|
|
47764
47765
|
listFiles: () => listFiles_default,
|
|
47765
47766
|
handOver: () => handOver_default,
|
|
47766
47767
|
executeCommand: () => executeCommand_default,
|
|
47768
|
+
editFile: () => editFile_default,
|
|
47767
47769
|
delegate: () => delegate_default,
|
|
47768
47770
|
attemptCompletion: () => attemptCompletion_default,
|
|
47769
47771
|
askFollowupQuestion: () => askFollowupQuestion_default
|
|
47770
47772
|
});
|
|
47771
47773
|
|
|
47772
|
-
// ../core/src/tools/utils/
|
|
47773
|
-
var
|
|
47774
|
-
|
|
47775
|
-
|
|
47776
|
-
|
|
47777
|
-
|
|
47778
|
-
}
|
|
47779
|
-
if (blocks.length === 0) {
|
|
47780
|
-
throw new Error("No valid diff blocks found.");
|
|
47774
|
+
// ../core/src/tools/utils/editFile.ts
|
|
47775
|
+
var START_OF_FILE = "<<<START_OF_FILE>>>";
|
|
47776
|
+
var END_OF_FILE = "<<<END_OF_FILE>>>";
|
|
47777
|
+
var editFile = async (fileContent, operations) => {
|
|
47778
|
+
if (!operations || operations.length === 0) {
|
|
47779
|
+
throw new Error("At least one edit operation is required");
|
|
47781
47780
|
}
|
|
47782
|
-
const
|
|
47783
|
-
|
|
47784
|
-
|
|
47785
|
-
|
|
47786
|
-
|
|
47787
|
-
const trimmedSearch = search.trim();
|
|
47788
|
-
const trimmedContent = content.trim();
|
|
47789
|
-
const offset = content.indexOf(trimmedContent);
|
|
47790
|
-
index = trimmedContent.indexOf(trimmedSearch);
|
|
47791
|
-
if (index !== -1) {
|
|
47792
|
-
const absoluteIndex = offset + index;
|
|
47793
|
-
return content.slice(0, absoluteIndex) + replace + content.slice(absoluteIndex + trimmedSearch.length);
|
|
47794
|
-
}
|
|
47795
|
-
const normalizedSearch = trimmedSearch.replace(/\s+/g, " ");
|
|
47796
|
-
const normalizedContent = trimmedContent.replace(/\s+/g, " ");
|
|
47797
|
-
index = normalizedContent.indexOf(normalizedSearch);
|
|
47798
|
-
if (index !== -1) {
|
|
47799
|
-
let runningIndex = 0;
|
|
47800
|
-
let actualPos = offset;
|
|
47801
|
-
for (const segment of trimmedSearch.replace(/\s+/g, " ").split(" ")) {
|
|
47802
|
-
const segIndex = content.indexOf(segment, actualPos);
|
|
47803
|
-
if (segIndex === -1) {
|
|
47804
|
-
break;
|
|
47805
|
-
}
|
|
47806
|
-
if (runningIndex === 0) {
|
|
47807
|
-
actualPos = segIndex;
|
|
47808
|
-
} else {
|
|
47809
|
-
actualPos = segIndex + segment.length;
|
|
47810
|
-
}
|
|
47811
|
-
runningIndex++;
|
|
47812
|
-
}
|
|
47813
|
-
const strippedSearch = trimmedSearch.replace(/\s+/g, "");
|
|
47814
|
-
const endPos = actualPos;
|
|
47815
|
-
const startPos = endPos - strippedSearch.length;
|
|
47816
|
-
return content.slice(0, startPos) + replace + content.slice(endPos);
|
|
47817
|
-
}
|
|
47818
|
-
throw new Error(`Could not find the following text in file:
|
|
47819
|
-
${search}`);
|
|
47820
|
-
};
|
|
47821
|
-
let updatedFile = fileContent;
|
|
47822
|
-
for (const { search, replace } of blocks) {
|
|
47823
|
-
updatedFile = findAndReplace(updatedFile, search, replace);
|
|
47781
|
+
const originalLines = fileContent.split(`
|
|
47782
|
+
`);
|
|
47783
|
+
let updatedContent = fileContent;
|
|
47784
|
+
for (const operation of operations) {
|
|
47785
|
+
updatedContent = await applyEditOperation(updatedContent, operation, originalLines);
|
|
47824
47786
|
}
|
|
47825
|
-
return
|
|
47787
|
+
return updatedContent;
|
|
47826
47788
|
};
|
|
47789
|
+
async function applyEditOperation(fileContent, operation, originalLines) {
|
|
47790
|
+
const { before_text, after_text, new_text, before_text_line_start, after_text_line_start } = operation;
|
|
47791
|
+
if (before_text === START_OF_FILE && after_text === END_OF_FILE) {
|
|
47792
|
+
return new_text;
|
|
47793
|
+
}
|
|
47794
|
+
if (before_text === START_OF_FILE) {
|
|
47795
|
+
if (!after_text) {
|
|
47796
|
+
return new_text + fileContent;
|
|
47797
|
+
}
|
|
47798
|
+
const afterIndex = findTextWithHint(fileContent, after_text, after_text_line_start, originalLines);
|
|
47799
|
+
return new_text + fileContent.slice(afterIndex);
|
|
47800
|
+
}
|
|
47801
|
+
if (after_text === END_OF_FILE) {
|
|
47802
|
+
if (!before_text) {
|
|
47803
|
+
return fileContent + new_text;
|
|
47804
|
+
}
|
|
47805
|
+
const beforeIndex = findTextWithHint(fileContent, before_text, before_text_line_start, originalLines);
|
|
47806
|
+
const beforeEndIndex = beforeIndex + before_text.length;
|
|
47807
|
+
return fileContent.slice(0, beforeEndIndex) + new_text;
|
|
47808
|
+
}
|
|
47809
|
+
if (before_text && after_text) {
|
|
47810
|
+
const beforeIndex = findTextWithHint(fileContent, before_text, before_text_line_start, originalLines);
|
|
47811
|
+
const beforeEndIndex = beforeIndex + before_text.length;
|
|
47812
|
+
const afterIndex = findTextWithHint(fileContent, after_text, after_text_line_start, originalLines, beforeEndIndex);
|
|
47813
|
+
return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(afterIndex);
|
|
47814
|
+
}
|
|
47815
|
+
if (before_text) {
|
|
47816
|
+
const beforeIndex = findTextWithHint(fileContent, before_text, before_text_line_start, originalLines);
|
|
47817
|
+
const beforeEndIndex = beforeIndex + before_text.length;
|
|
47818
|
+
return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(beforeEndIndex);
|
|
47819
|
+
}
|
|
47820
|
+
if (after_text) {
|
|
47821
|
+
const afterIndex = findTextWithHint(fileContent, after_text, after_text_line_start, originalLines);
|
|
47822
|
+
return fileContent.slice(0, afterIndex) + new_text + fileContent.slice(afterIndex);
|
|
47823
|
+
}
|
|
47824
|
+
throw new Error("Either before_text or after_text must be specified");
|
|
47825
|
+
}
|
|
47826
|
+
function findTextWithHint(content, searchText, lineHint, originalLines, startIndex = 0) {
|
|
47827
|
+
if (lineHint && lineHint > 0 && lineHint <= originalLines.length) {
|
|
47828
|
+
const hintIndex = getLineStartIndex(originalLines, lineHint - 1);
|
|
47829
|
+
const searchRadius = 5;
|
|
47830
|
+
const windowStart = Math.max(0, hintIndex - searchRadius * 50);
|
|
47831
|
+
const windowEnd = Math.min(content.length, hintIndex + searchRadius * 50);
|
|
47832
|
+
const windowContent = content.slice(windowStart, windowEnd);
|
|
47833
|
+
const relativeIndex = windowContent.indexOf(searchText);
|
|
47834
|
+
if (relativeIndex !== -1) {
|
|
47835
|
+
const absoluteIndex = windowStart + relativeIndex;
|
|
47836
|
+
if (absoluteIndex >= startIndex) {
|
|
47837
|
+
return absoluteIndex;
|
|
47838
|
+
}
|
|
47839
|
+
}
|
|
47840
|
+
}
|
|
47841
|
+
const index = content.indexOf(searchText, startIndex);
|
|
47842
|
+
if (index === -1) {
|
|
47843
|
+
throw new Error(`Could not find text: ${searchText}`);
|
|
47844
|
+
}
|
|
47845
|
+
return index;
|
|
47846
|
+
}
|
|
47847
|
+
function getLineStartIndex(lines, lineIndex) {
|
|
47848
|
+
let index = 0;
|
|
47849
|
+
for (let i2 = 0;i2 < lineIndex && i2 < lines.length; i2++) {
|
|
47850
|
+
index += lines[i2].length + 1;
|
|
47851
|
+
}
|
|
47852
|
+
return index;
|
|
47853
|
+
}
|
|
47827
47854
|
// ../core/src/tools/utils/getArg.ts
|
|
47828
47855
|
var getString = (args, name, defaultValue) => {
|
|
47829
47856
|
if (typeof args !== "object" || Array.isArray(args)) {
|
|
@@ -47915,6 +47942,61 @@ var getArray = (args, name, defaultValue) => {
|
|
|
47915
47942
|
}
|
|
47916
47943
|
return [ret];
|
|
47917
47944
|
};
|
|
47945
|
+
// ../core/src/tools/utils/replaceInFile.ts
|
|
47946
|
+
var replaceInFile = async (fileContent, diff) => {
|
|
47947
|
+
const blockPattern = /<<<<<+ SEARCH\s*\r?\n([\s\S]*?)\r?\n=======[ \t]*\r?\n([\s\S]*?)\r?\n?>>>>>+ REPLACE/g;
|
|
47948
|
+
const blocks = [];
|
|
47949
|
+
for (let match = blockPattern.exec(diff);match !== null; match = blockPattern.exec(diff)) {
|
|
47950
|
+
blocks.push({ search: match[1], replace: match[2] });
|
|
47951
|
+
}
|
|
47952
|
+
if (blocks.length === 0) {
|
|
47953
|
+
throw new Error("No valid diff blocks found.");
|
|
47954
|
+
}
|
|
47955
|
+
const findAndReplace = (content, search, replace) => {
|
|
47956
|
+
let index = content.indexOf(search);
|
|
47957
|
+
if (index !== -1) {
|
|
47958
|
+
return content.slice(0, index) + replace + content.slice(index + search.length);
|
|
47959
|
+
}
|
|
47960
|
+
const trimmedSearch = search.trim();
|
|
47961
|
+
const trimmedContent = content.trim();
|
|
47962
|
+
const offset = content.indexOf(trimmedContent);
|
|
47963
|
+
index = trimmedContent.indexOf(trimmedSearch);
|
|
47964
|
+
if (index !== -1) {
|
|
47965
|
+
const absoluteIndex = offset + index;
|
|
47966
|
+
return content.slice(0, absoluteIndex) + replace + content.slice(absoluteIndex + trimmedSearch.length);
|
|
47967
|
+
}
|
|
47968
|
+
const normalizedSearch = trimmedSearch.replace(/\s+/g, " ");
|
|
47969
|
+
const normalizedContent = trimmedContent.replace(/\s+/g, " ");
|
|
47970
|
+
index = normalizedContent.indexOf(normalizedSearch);
|
|
47971
|
+
if (index !== -1) {
|
|
47972
|
+
let runningIndex = 0;
|
|
47973
|
+
let actualPos = offset;
|
|
47974
|
+
for (const segment of trimmedSearch.replace(/\s+/g, " ").split(" ")) {
|
|
47975
|
+
const segIndex = content.indexOf(segment, actualPos);
|
|
47976
|
+
if (segIndex === -1) {
|
|
47977
|
+
break;
|
|
47978
|
+
}
|
|
47979
|
+
if (runningIndex === 0) {
|
|
47980
|
+
actualPos = segIndex;
|
|
47981
|
+
} else {
|
|
47982
|
+
actualPos = segIndex + segment.length;
|
|
47983
|
+
}
|
|
47984
|
+
runningIndex++;
|
|
47985
|
+
}
|
|
47986
|
+
const strippedSearch = trimmedSearch.replace(/\s+/g, "");
|
|
47987
|
+
const endPos = actualPos;
|
|
47988
|
+
const startPos = endPos - strippedSearch.length;
|
|
47989
|
+
return content.slice(0, startPos) + replace + content.slice(endPos);
|
|
47990
|
+
}
|
|
47991
|
+
throw new Error(`Could not find the following text in file:
|
|
47992
|
+
${search}`);
|
|
47993
|
+
};
|
|
47994
|
+
let updatedFile = fileContent;
|
|
47995
|
+
for (const { search, replace } of blocks) {
|
|
47996
|
+
updatedFile = findAndReplace(updatedFile, search, replace);
|
|
47997
|
+
}
|
|
47998
|
+
return updatedFile;
|
|
47999
|
+
};
|
|
47918
48000
|
// ../core/src/tools/askFollowupQuestion.ts
|
|
47919
48001
|
var toolInfo = {
|
|
47920
48002
|
name: "ask_followup_question",
|
|
@@ -48158,11 +48240,11 @@ var delegate_default = {
|
|
|
48158
48240
|
// ../core/src/tools/executeCommand.ts
|
|
48159
48241
|
var toolInfo4 = {
|
|
48160
48242
|
name: "execute_command",
|
|
48161
|
-
description: "Run a single CLI command. The command is always executed in the project-root working directory (regardless of earlier commands). Prefer one-off shell commands over wrapper scripts for flexibility. After an `execute_command` call,
|
|
48243
|
+
description: "Run a single CLI command. The command is always executed in the project-root working directory (regardless of earlier commands). Prefer one-off shell commands over wrapper scripts for flexibility. **IMPORTANT**: After an `execute_command` call, you MUST stop and NOT allowed to make further tool calls in the same message.",
|
|
48162
48244
|
parameters: [
|
|
48163
48245
|
{
|
|
48164
48246
|
name: "command",
|
|
48165
|
-
description: "The exact command to run
|
|
48247
|
+
description: "The exact command to run (valid for the current OS). It must be correctly formatted and free of harmful instructions.",
|
|
48166
48248
|
required: true,
|
|
48167
48249
|
usageValue: "your-command-here"
|
|
48168
48250
|
},
|
|
@@ -48361,125 +48443,8 @@ var readFile_default = {
|
|
|
48361
48443
|
handler: handler6,
|
|
48362
48444
|
isAvailable: isAvailable6
|
|
48363
48445
|
};
|
|
48364
|
-
// ../core/src/tools/replaceInFile.ts
|
|
48365
|
-
var toolInfo7 = {
|
|
48366
|
-
name: "replace_in_file",
|
|
48367
|
-
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.",
|
|
48368
|
-
parameters: [
|
|
48369
|
-
{
|
|
48370
|
-
name: "path",
|
|
48371
|
-
description: "The path of the file to modify",
|
|
48372
|
-
required: true,
|
|
48373
|
-
usageValue: "File path here"
|
|
48374
|
-
},
|
|
48375
|
-
{
|
|
48376
|
-
name: "diff",
|
|
48377
|
-
description: `One or more SEARCH/REPLACE blocks following this exact format:
|
|
48378
|
-
\`\`\`
|
|
48379
|
-
<<<<<<< SEARCH
|
|
48380
|
-
[exact content to find]
|
|
48381
|
-
=======
|
|
48382
|
-
[new content to replace with]
|
|
48383
|
-
>>>>>>> REPLACE
|
|
48384
|
-
\`\`\`
|
|
48385
|
-
Critical rules:
|
|
48386
|
-
1. SEARCH content must match the associated file section to find EXACTLY:
|
|
48387
|
-
* Match character-for-character including whitespace, indentation, line endings
|
|
48388
|
-
* Include all comments, docstrings, etc.
|
|
48389
|
-
2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
|
|
48390
|
-
* Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
|
|
48391
|
-
* Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
|
|
48392
|
-
* When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
|
|
48393
|
-
3. Keep SEARCH/REPLACE blocks concise:
|
|
48394
|
-
* Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
|
|
48395
|
-
* Include just the changing lines, and a few surrounding lines if needed for uniqueness.
|
|
48396
|
-
* Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
|
|
48397
|
-
* Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
|
|
48398
|
-
4. Special operations:
|
|
48399
|
-
* To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
|
|
48400
|
-
* To delete code: Use empty REPLACE section`,
|
|
48401
|
-
required: true,
|
|
48402
|
-
usageValue: "Search and replace blocks here"
|
|
48403
|
-
}
|
|
48404
|
-
],
|
|
48405
|
-
examples: [
|
|
48406
|
-
{
|
|
48407
|
-
description: "Request to replace sections of content in a file",
|
|
48408
|
-
parameters: [
|
|
48409
|
-
{
|
|
48410
|
-
name: "path",
|
|
48411
|
-
value: "src/main.js"
|
|
48412
|
-
},
|
|
48413
|
-
{
|
|
48414
|
-
name: "diff",
|
|
48415
|
-
value: `
|
|
48416
|
-
<<<<<<< SEARCH
|
|
48417
|
-
import React from 'react';
|
|
48418
|
-
=======
|
|
48419
|
-
import React, { useState } from 'react';
|
|
48420
|
-
>>>>>>> REPLACE
|
|
48421
|
-
|
|
48422
|
-
<<<<<<< SEARCH
|
|
48423
|
-
function handleSubmit() {
|
|
48424
|
-
saveData();
|
|
48425
|
-
setLoading(false);
|
|
48426
|
-
}
|
|
48427
|
-
|
|
48428
|
-
=======
|
|
48429
|
-
>>>>>>> REPLACE
|
|
48430
|
-
|
|
48431
|
-
<<<<<<< SEARCH
|
|
48432
|
-
return (
|
|
48433
|
-
<div>
|
|
48434
|
-
=======
|
|
48435
|
-
function handleSubmit() {
|
|
48436
|
-
saveData();
|
|
48437
|
-
setLoading(false);
|
|
48438
|
-
}
|
|
48439
|
-
|
|
48440
|
-
return (
|
|
48441
|
-
<div>
|
|
48442
|
-
>>>>>>> REPLACE
|
|
48443
|
-
`
|
|
48444
|
-
}
|
|
48445
|
-
]
|
|
48446
|
-
}
|
|
48447
|
-
],
|
|
48448
|
-
permissionLevel: 2 /* Write */
|
|
48449
|
-
};
|
|
48450
|
-
var handler7 = async (provider, args) => {
|
|
48451
|
-
if (!provider.readFile || !provider.writeFile) {
|
|
48452
|
-
return {
|
|
48453
|
-
type: "Error" /* Error */,
|
|
48454
|
-
message: "Not possible to replace in file. Abort."
|
|
48455
|
-
};
|
|
48456
|
-
}
|
|
48457
|
-
const path = getString(args, "path");
|
|
48458
|
-
const diff = getString(args, "diff");
|
|
48459
|
-
const fileContent = await provider.readFile(path);
|
|
48460
|
-
if (fileContent == null) {
|
|
48461
|
-
return {
|
|
48462
|
-
type: "Error" /* Error */,
|
|
48463
|
-
message: `<error><replace_in_file_path>${path}</replace_in_file_path><error_message>File not found</error_message></error>`
|
|
48464
|
-
};
|
|
48465
|
-
}
|
|
48466
|
-
const result = await replaceInFile(fileContent, diff);
|
|
48467
|
-
await provider.writeFile(path, result);
|
|
48468
|
-
return {
|
|
48469
|
-
type: "Reply" /* Reply */,
|
|
48470
|
-
message: `<replace_in_file_path>${path}</replace_in_file_path>`
|
|
48471
|
-
};
|
|
48472
|
-
};
|
|
48473
|
-
var isAvailable7 = (provider) => {
|
|
48474
|
-
return !!provider.readFile && !!provider.writeFile;
|
|
48475
|
-
};
|
|
48476
|
-
var replaceInFile_default = {
|
|
48477
|
-
...toolInfo7,
|
|
48478
|
-
handler: handler7,
|
|
48479
|
-
isAvailable: isAvailable7
|
|
48480
|
-
};
|
|
48481
48446
|
// ../core/src/tools/searchFiles.ts
|
|
48482
|
-
var
|
|
48447
|
+
var toolInfo7 = {
|
|
48483
48448
|
name: "search_files",
|
|
48484
48449
|
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.",
|
|
48485
48450
|
parameters: [
|
|
@@ -48523,7 +48488,7 @@ var toolInfo8 = {
|
|
|
48523
48488
|
],
|
|
48524
48489
|
permissionLevel: 1 /* Read */
|
|
48525
48490
|
};
|
|
48526
|
-
var
|
|
48491
|
+
var handler7 = async (provider, args) => {
|
|
48527
48492
|
if (!provider.searchFiles) {
|
|
48528
48493
|
return {
|
|
48529
48494
|
type: "Error" /* Error */,
|
|
@@ -48546,18 +48511,18 @@ ${files.join(`
|
|
|
48546
48511
|
`
|
|
48547
48512
|
};
|
|
48548
48513
|
};
|
|
48549
|
-
var
|
|
48514
|
+
var isAvailable7 = (provider) => {
|
|
48550
48515
|
return !!provider.searchFiles;
|
|
48551
48516
|
};
|
|
48552
48517
|
var searchFiles_default = {
|
|
48553
|
-
...
|
|
48554
|
-
handler:
|
|
48555
|
-
isAvailable:
|
|
48518
|
+
...toolInfo7,
|
|
48519
|
+
handler: handler7,
|
|
48520
|
+
isAvailable: isAvailable7
|
|
48556
48521
|
};
|
|
48557
48522
|
// ../core/src/tools/updateKnowledge.ts
|
|
48558
48523
|
var import_yaml = __toESM(require_dist(), 1);
|
|
48559
48524
|
import { join } from "node:path";
|
|
48560
|
-
var
|
|
48525
|
+
var toolInfo8 = {
|
|
48561
48526
|
name: "update_knowledge",
|
|
48562
48527
|
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.",
|
|
48563
48528
|
parameters: [
|
|
@@ -48734,7 +48699,7 @@ function deepMerge(target, source) {
|
|
|
48734
48699
|
}
|
|
48735
48700
|
return output;
|
|
48736
48701
|
}
|
|
48737
|
-
var
|
|
48702
|
+
var handler8 = async (provider, args) => {
|
|
48738
48703
|
if (!provider.readFile || !provider.writeFile) {
|
|
48739
48704
|
return {
|
|
48740
48705
|
type: "Error" /* Error */,
|
|
@@ -48806,16 +48771,16 @@ var handler9 = async (provider, args) => {
|
|
|
48806
48771
|
};
|
|
48807
48772
|
}
|
|
48808
48773
|
};
|
|
48809
|
-
var
|
|
48774
|
+
var isAvailable8 = (provider) => {
|
|
48810
48775
|
return !!provider.readFile && !!provider.writeFile;
|
|
48811
48776
|
};
|
|
48812
48777
|
var updateKnowledge_default = {
|
|
48813
|
-
...
|
|
48814
|
-
handler:
|
|
48815
|
-
isAvailable:
|
|
48778
|
+
...toolInfo8,
|
|
48779
|
+
handler: handler8,
|
|
48780
|
+
isAvailable: isAvailable8
|
|
48816
48781
|
};
|
|
48817
48782
|
// ../core/src/tools/writeToFile.ts
|
|
48818
|
-
var
|
|
48783
|
+
var toolInfo9 = {
|
|
48819
48784
|
name: "write_to_file",
|
|
48820
48785
|
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 `>`.",
|
|
48821
48786
|
parameters: [
|
|
@@ -48860,7 +48825,7 @@ export default App;
|
|
|
48860
48825
|
],
|
|
48861
48826
|
permissionLevel: 2 /* Write */
|
|
48862
48827
|
};
|
|
48863
|
-
var
|
|
48828
|
+
var handler9 = async (provider, args) => {
|
|
48864
48829
|
if (!provider.writeFile) {
|
|
48865
48830
|
return {
|
|
48866
48831
|
type: "Error" /* Error */,
|
|
@@ -48875,16 +48840,16 @@ var handler10 = async (provider, args) => {
|
|
|
48875
48840
|
message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
|
|
48876
48841
|
};
|
|
48877
48842
|
};
|
|
48878
|
-
var
|
|
48843
|
+
var isAvailable9 = (provider) => {
|
|
48879
48844
|
return !!provider.writeFile;
|
|
48880
48845
|
};
|
|
48881
48846
|
var writeToFile_default = {
|
|
48882
|
-
...
|
|
48883
|
-
handler:
|
|
48884
|
-
isAvailable:
|
|
48847
|
+
...toolInfo9,
|
|
48848
|
+
handler: handler9,
|
|
48849
|
+
isAvailable: isAvailable9
|
|
48885
48850
|
};
|
|
48886
48851
|
// ../core/src/tools/handOver.ts
|
|
48887
|
-
var
|
|
48852
|
+
var toolInfo10 = {
|
|
48888
48853
|
name: "hand_over",
|
|
48889
48854
|
description: "Hand over the current task to another agent to complete. This tool MUST NOT to be used with any other tool.",
|
|
48890
48855
|
parameters: [
|
|
@@ -48938,7 +48903,7 @@ var toolInfo11 = {
|
|
|
48938
48903
|
],
|
|
48939
48904
|
permissionLevel: 0 /* None */
|
|
48940
48905
|
};
|
|
48941
|
-
var
|
|
48906
|
+
var handler10 = async (_provider, args) => {
|
|
48942
48907
|
const agentName = getString(args, "agent_name");
|
|
48943
48908
|
const task = getString(args, "task");
|
|
48944
48909
|
const context = getString(args, "context", undefined);
|
|
@@ -48951,16 +48916,16 @@ var handler11 = async (_provider, args) => {
|
|
|
48951
48916
|
files
|
|
48952
48917
|
};
|
|
48953
48918
|
};
|
|
48954
|
-
var
|
|
48919
|
+
var isAvailable10 = (_provider) => {
|
|
48955
48920
|
return true;
|
|
48956
48921
|
};
|
|
48957
48922
|
var handOver_default = {
|
|
48958
|
-
...
|
|
48959
|
-
handler:
|
|
48960
|
-
isAvailable:
|
|
48923
|
+
...toolInfo10,
|
|
48924
|
+
handler: handler10,
|
|
48925
|
+
isAvailable: isAvailable10
|
|
48961
48926
|
};
|
|
48962
48927
|
// ../core/src/tools/removeFile.ts
|
|
48963
|
-
var
|
|
48928
|
+
var toolInfo11 = {
|
|
48964
48929
|
name: "remove_file",
|
|
48965
48930
|
description: "Request to remove a file at the specified path.",
|
|
48966
48931
|
parameters: [
|
|
@@ -48984,7 +48949,7 @@ var toolInfo12 = {
|
|
|
48984
48949
|
],
|
|
48985
48950
|
permissionLevel: 2 /* Write */
|
|
48986
48951
|
};
|
|
48987
|
-
var
|
|
48952
|
+
var handler11 = async (provider, args) => {
|
|
48988
48953
|
if (!provider.removeFile) {
|
|
48989
48954
|
return {
|
|
48990
48955
|
type: "Error" /* Error */,
|
|
@@ -48998,27 +48963,27 @@ var handler12 = async (provider, args) => {
|
|
|
48998
48963
|
message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
|
|
48999
48964
|
};
|
|
49000
48965
|
};
|
|
49001
|
-
var
|
|
48966
|
+
var isAvailable11 = (provider) => {
|
|
49002
48967
|
return !!provider.removeFile;
|
|
49003
48968
|
};
|
|
49004
48969
|
var removeFile_default = {
|
|
49005
|
-
...
|
|
49006
|
-
handler:
|
|
49007
|
-
isAvailable:
|
|
48970
|
+
...toolInfo11,
|
|
48971
|
+
handler: handler11,
|
|
48972
|
+
isAvailable: isAvailable11
|
|
49008
48973
|
};
|
|
49009
48974
|
// ../core/src/tools/renameFile.ts
|
|
49010
|
-
var
|
|
48975
|
+
var toolInfo12 = {
|
|
49011
48976
|
name: "rename_file",
|
|
49012
48977
|
description: "Request to rename a file from source path to target path.",
|
|
49013
48978
|
parameters: [
|
|
49014
48979
|
{
|
|
49015
|
-
name: "
|
|
48980
|
+
name: "source_path",
|
|
49016
48981
|
description: "The current path of the file",
|
|
49017
48982
|
required: true,
|
|
49018
48983
|
usageValue: "Source file path here"
|
|
49019
48984
|
},
|
|
49020
48985
|
{
|
|
49021
|
-
name: "
|
|
48986
|
+
name: "target_path",
|
|
49022
48987
|
description: "The new path for the file",
|
|
49023
48988
|
required: true,
|
|
49024
48989
|
usageValue: "Target file path here"
|
|
@@ -49029,11 +48994,11 @@ var toolInfo13 = {
|
|
|
49029
48994
|
description: "Request to rename a file",
|
|
49030
48995
|
parameters: [
|
|
49031
48996
|
{
|
|
49032
|
-
name: "
|
|
48997
|
+
name: "source_path",
|
|
49033
48998
|
value: "src/old-name.js"
|
|
49034
48999
|
},
|
|
49035
49000
|
{
|
|
49036
|
-
name: "
|
|
49001
|
+
name: "target_path",
|
|
49037
49002
|
value: "src/new-name.js"
|
|
49038
49003
|
}
|
|
49039
49004
|
]
|
|
@@ -49041,29 +49006,308 @@ var toolInfo13 = {
|
|
|
49041
49006
|
],
|
|
49042
49007
|
permissionLevel: 2 /* Write */
|
|
49043
49008
|
};
|
|
49044
|
-
var
|
|
49009
|
+
var handler12 = async (provider, args) => {
|
|
49045
49010
|
if (!provider.renameFile) {
|
|
49046
49011
|
return {
|
|
49047
49012
|
type: "Error" /* Error */,
|
|
49048
49013
|
message: "Not possible to rename file. Abort."
|
|
49049
49014
|
};
|
|
49050
49015
|
}
|
|
49051
|
-
const sourcePath = getString(args, "
|
|
49052
|
-
const targetPath = getString(args, "
|
|
49016
|
+
const sourcePath = getString(args, "source_path");
|
|
49017
|
+
const targetPath = getString(args, "target_path");
|
|
49053
49018
|
await provider.renameFile(sourcePath, targetPath);
|
|
49054
49019
|
return {
|
|
49055
49020
|
type: "Reply" /* Reply */,
|
|
49056
49021
|
message: `<rename_file_path>${targetPath}</rename_file_path><status>Success</status>`
|
|
49057
49022
|
};
|
|
49058
49023
|
};
|
|
49059
|
-
var
|
|
49024
|
+
var isAvailable12 = (provider) => {
|
|
49060
49025
|
return !!provider.renameFile;
|
|
49061
49026
|
};
|
|
49062
49027
|
var renameFile_default = {
|
|
49028
|
+
...toolInfo12,
|
|
49029
|
+
handler: handler12,
|
|
49030
|
+
isAvailable: isAvailable12
|
|
49031
|
+
};
|
|
49032
|
+
// ../core/src/tools/editFile.ts
|
|
49033
|
+
var toolInfo13 = {
|
|
49034
|
+
name: "edit_file",
|
|
49035
|
+
description: "Request to edit file contents using before/after text anchors with flexible operations. Supports multiple edit operations in a single call.",
|
|
49036
|
+
parameters: [
|
|
49037
|
+
{
|
|
49038
|
+
name: "path",
|
|
49039
|
+
description: "The path of the file to edit",
|
|
49040
|
+
required: true,
|
|
49041
|
+
usageValue: "File path here"
|
|
49042
|
+
},
|
|
49043
|
+
{
|
|
49044
|
+
name: "operations",
|
|
49045
|
+
description: "Edit operation with before_text, after_text, new_text, and optional line range hints",
|
|
49046
|
+
required: true,
|
|
49047
|
+
allowMultiple: true,
|
|
49048
|
+
children: [
|
|
49049
|
+
{
|
|
49050
|
+
name: "before_text",
|
|
49051
|
+
description: `Text to find as the start anchor (use ${START_OF_FILE} for file start)`,
|
|
49052
|
+
required: false,
|
|
49053
|
+
usageValue: "Text before the edit location"
|
|
49054
|
+
},
|
|
49055
|
+
{
|
|
49056
|
+
name: "after_text",
|
|
49057
|
+
description: `Text to find as the end anchor (use ${END_OF_FILE} for file end)`,
|
|
49058
|
+
required: false,
|
|
49059
|
+
usageValue: "Text after the edit location"
|
|
49060
|
+
},
|
|
49061
|
+
{
|
|
49062
|
+
name: "new_text",
|
|
49063
|
+
description: "Text to replace the content between before_text and after_text",
|
|
49064
|
+
required: true,
|
|
49065
|
+
usageValue: "New text content"
|
|
49066
|
+
},
|
|
49067
|
+
{
|
|
49068
|
+
name: "before_text_line_start",
|
|
49069
|
+
description: "Optional line number hint for before_text location (1-based)",
|
|
49070
|
+
required: false,
|
|
49071
|
+
usageValue: "10"
|
|
49072
|
+
},
|
|
49073
|
+
{
|
|
49074
|
+
name: "after_text_line_start",
|
|
49075
|
+
description: "Optional line number hint for after_text location (1-based)",
|
|
49076
|
+
required: false,
|
|
49077
|
+
usageValue: "20"
|
|
49078
|
+
}
|
|
49079
|
+
],
|
|
49080
|
+
usageValue: "operations here"
|
|
49081
|
+
}
|
|
49082
|
+
],
|
|
49083
|
+
examples: [
|
|
49084
|
+
{
|
|
49085
|
+
description: "Replace content between two text anchors",
|
|
49086
|
+
parameters: [
|
|
49087
|
+
{
|
|
49088
|
+
name: "path",
|
|
49089
|
+
value: "src/main.ts"
|
|
49090
|
+
},
|
|
49091
|
+
{
|
|
49092
|
+
name: "operations",
|
|
49093
|
+
value: {
|
|
49094
|
+
before_text: "function oldFunction() {",
|
|
49095
|
+
after_text: "}",
|
|
49096
|
+
new_text: `
|
|
49097
|
+
return "new implementation";
|
|
49098
|
+
`
|
|
49099
|
+
}
|
|
49100
|
+
}
|
|
49101
|
+
]
|
|
49102
|
+
},
|
|
49103
|
+
{
|
|
49104
|
+
description: "Insert at start of file",
|
|
49105
|
+
parameters: [
|
|
49106
|
+
{
|
|
49107
|
+
name: "path",
|
|
49108
|
+
value: "src/header.ts"
|
|
49109
|
+
},
|
|
49110
|
+
{
|
|
49111
|
+
name: "operations",
|
|
49112
|
+
value: {
|
|
49113
|
+
before_text: START_OF_FILE,
|
|
49114
|
+
after_text: "export",
|
|
49115
|
+
new_text: `// File header comment
|
|
49116
|
+
`
|
|
49117
|
+
}
|
|
49118
|
+
}
|
|
49119
|
+
]
|
|
49120
|
+
},
|
|
49121
|
+
{
|
|
49122
|
+
description: "Multiple operations in one call",
|
|
49123
|
+
parameters: [
|
|
49124
|
+
{
|
|
49125
|
+
name: "path",
|
|
49126
|
+
value: "src/utils.ts"
|
|
49127
|
+
},
|
|
49128
|
+
{
|
|
49129
|
+
name: "operations",
|
|
49130
|
+
value: [
|
|
49131
|
+
{
|
|
49132
|
+
before_text: "import React",
|
|
49133
|
+
after_text: 'from "react"',
|
|
49134
|
+
new_text: ", { useState }"
|
|
49135
|
+
},
|
|
49136
|
+
{
|
|
49137
|
+
before_text: "function Component() {",
|
|
49138
|
+
after_text: "return (",
|
|
49139
|
+
new_text: `
|
|
49140
|
+
const [state, setState] = useState(false);
|
|
49141
|
+
`
|
|
49142
|
+
}
|
|
49143
|
+
]
|
|
49144
|
+
}
|
|
49145
|
+
]
|
|
49146
|
+
}
|
|
49147
|
+
],
|
|
49148
|
+
permissionLevel: 2 /* Write */
|
|
49149
|
+
};
|
|
49150
|
+
var handler13 = async (provider, args) => {
|
|
49151
|
+
if (!provider.readFile || !provider.writeFile) {
|
|
49152
|
+
return {
|
|
49153
|
+
type: "Error" /* Error */,
|
|
49154
|
+
message: "Not possible to edit file. Abort."
|
|
49155
|
+
};
|
|
49156
|
+
}
|
|
49157
|
+
const path = getString(args, "path");
|
|
49158
|
+
const operations = getArray(args, "operations");
|
|
49159
|
+
if (!operations || operations.length === 0) {
|
|
49160
|
+
return {
|
|
49161
|
+
type: "Error" /* Error */,
|
|
49162
|
+
message: `<error><edit_file_path>${path}</edit_file_path><error_message>At least one edit operation is required</error_message></error>`
|
|
49163
|
+
};
|
|
49164
|
+
}
|
|
49165
|
+
const fileContent = await provider.readFile(path);
|
|
49166
|
+
if (fileContent == null) {
|
|
49167
|
+
return {
|
|
49168
|
+
type: "Error" /* Error */,
|
|
49169
|
+
message: `<error><edit_file_path>${path}</edit_file_path><error_message>File not found</error_message></error>`
|
|
49170
|
+
};
|
|
49171
|
+
}
|
|
49172
|
+
try {
|
|
49173
|
+
const result = await editFile(fileContent, operations);
|
|
49174
|
+
await provider.writeFile(path, result);
|
|
49175
|
+
return {
|
|
49176
|
+
type: "Reply" /* Reply */,
|
|
49177
|
+
message: `<edit_file_path>${path}</edit_file_path>`
|
|
49178
|
+
};
|
|
49179
|
+
} catch (error) {
|
|
49180
|
+
return {
|
|
49181
|
+
type: "Error" /* Error */,
|
|
49182
|
+
message: `<error><edit_file_path>${path}</edit_file_path><error_message>${error instanceof Error ? error.message : String(error)}</error_message></error>`
|
|
49183
|
+
};
|
|
49184
|
+
}
|
|
49185
|
+
};
|
|
49186
|
+
var isAvailable13 = (provider) => {
|
|
49187
|
+
return !!provider.readFile && !!provider.writeFile;
|
|
49188
|
+
};
|
|
49189
|
+
var editFile_default = {
|
|
49063
49190
|
...toolInfo13,
|
|
49064
49191
|
handler: handler13,
|
|
49065
49192
|
isAvailable: isAvailable13
|
|
49066
49193
|
};
|
|
49194
|
+
// ../core/src/tools/replaceInFile.ts
|
|
49195
|
+
var toolInfo14 = {
|
|
49196
|
+
name: "replace_in_file",
|
|
49197
|
+
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.",
|
|
49198
|
+
parameters: [
|
|
49199
|
+
{
|
|
49200
|
+
name: "path",
|
|
49201
|
+
description: "The path of the file to modify",
|
|
49202
|
+
required: true,
|
|
49203
|
+
usageValue: "File path here"
|
|
49204
|
+
},
|
|
49205
|
+
{
|
|
49206
|
+
name: "diff",
|
|
49207
|
+
description: `One or more SEARCH/REPLACE blocks following this exact format:
|
|
49208
|
+
\`\`\`
|
|
49209
|
+
<<<<<<< SEARCH
|
|
49210
|
+
[exact content to find]
|
|
49211
|
+
=======
|
|
49212
|
+
[new content to replace with]
|
|
49213
|
+
>>>>>>> REPLACE
|
|
49214
|
+
\`\`\`
|
|
49215
|
+
Critical rules:
|
|
49216
|
+
1. SEARCH content must match the associated file section to find EXACTLY:
|
|
49217
|
+
* Match character-for-character including whitespace, indentation, line endings
|
|
49218
|
+
* Include all comments, docstrings, etc.
|
|
49219
|
+
2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
|
|
49220
|
+
* Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
|
|
49221
|
+
* Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
|
|
49222
|
+
* When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
|
|
49223
|
+
3. Keep SEARCH/REPLACE blocks concise:
|
|
49224
|
+
* Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
|
|
49225
|
+
* Include just the changing lines, and a few surrounding lines if needed for uniqueness.
|
|
49226
|
+
* Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
|
|
49227
|
+
* Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
|
|
49228
|
+
4. Special operations:
|
|
49229
|
+
* To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
|
|
49230
|
+
* To delete code: Use empty REPLACE section`,
|
|
49231
|
+
required: true,
|
|
49232
|
+
usageValue: "Search and replace blocks here"
|
|
49233
|
+
}
|
|
49234
|
+
],
|
|
49235
|
+
examples: [
|
|
49236
|
+
{
|
|
49237
|
+
description: "Request to replace sections of content in a file",
|
|
49238
|
+
parameters: [
|
|
49239
|
+
{
|
|
49240
|
+
name: "path",
|
|
49241
|
+
value: "src/main.js"
|
|
49242
|
+
},
|
|
49243
|
+
{
|
|
49244
|
+
name: "diff",
|
|
49245
|
+
value: `
|
|
49246
|
+
<<<<<<< SEARCH
|
|
49247
|
+
import React from 'react';
|
|
49248
|
+
=======
|
|
49249
|
+
import React, { useState } from 'react';
|
|
49250
|
+
>>>>>>> REPLACE
|
|
49251
|
+
|
|
49252
|
+
<<<<<<< SEARCH
|
|
49253
|
+
function handleSubmit() {
|
|
49254
|
+
saveData();
|
|
49255
|
+
setLoading(false);
|
|
49256
|
+
}
|
|
49257
|
+
|
|
49258
|
+
=======
|
|
49259
|
+
>>>>>>> REPLACE
|
|
49260
|
+
|
|
49261
|
+
<<<<<<< SEARCH
|
|
49262
|
+
return (
|
|
49263
|
+
<div>
|
|
49264
|
+
=======
|
|
49265
|
+
function handleSubmit() {
|
|
49266
|
+
saveData();
|
|
49267
|
+
setLoading(false);
|
|
49268
|
+
}
|
|
49269
|
+
|
|
49270
|
+
return (
|
|
49271
|
+
<div>
|
|
49272
|
+
>>>>>>> REPLACE
|
|
49273
|
+
`
|
|
49274
|
+
}
|
|
49275
|
+
]
|
|
49276
|
+
}
|
|
49277
|
+
],
|
|
49278
|
+
permissionLevel: 2 /* Write */
|
|
49279
|
+
};
|
|
49280
|
+
var handler14 = async (provider, args) => {
|
|
49281
|
+
if (!provider.readFile || !provider.writeFile) {
|
|
49282
|
+
return {
|
|
49283
|
+
type: "Error" /* Error */,
|
|
49284
|
+
message: "Not possible to replace in file. Abort."
|
|
49285
|
+
};
|
|
49286
|
+
}
|
|
49287
|
+
const path = getString(args, "path");
|
|
49288
|
+
const diff = getString(args, "diff");
|
|
49289
|
+
const fileContent = await provider.readFile(path);
|
|
49290
|
+
if (fileContent == null) {
|
|
49291
|
+
return {
|
|
49292
|
+
type: "Error" /* Error */,
|
|
49293
|
+
message: `<error><replace_in_file_path>${path}</replace_in_file_path><error_message>File not found</error_message></error>`
|
|
49294
|
+
};
|
|
49295
|
+
}
|
|
49296
|
+
const result = await replaceInFile(fileContent, diff);
|
|
49297
|
+
await provider.writeFile(path, result);
|
|
49298
|
+
return {
|
|
49299
|
+
type: "Reply" /* Reply */,
|
|
49300
|
+
message: `<replace_in_file_path>${path}</replace_in_file_path>`
|
|
49301
|
+
};
|
|
49302
|
+
};
|
|
49303
|
+
var isAvailable14 = (provider) => {
|
|
49304
|
+
return !!provider.readFile && !!provider.writeFile;
|
|
49305
|
+
};
|
|
49306
|
+
var replaceInFile_default = {
|
|
49307
|
+
...toolInfo14,
|
|
49308
|
+
handler: handler14,
|
|
49309
|
+
isAvailable: isAvailable14
|
|
49310
|
+
};
|
|
49067
49311
|
// ../core/src/getAvailableTools.ts
|
|
49068
49312
|
var getAvailableTools = ({
|
|
49069
49313
|
provider: provider2,
|
|
@@ -49276,7 +49520,7 @@ var toolUsePrompt = (tools, toolNamePrefix) => {
|
|
|
49276
49520
|
|
|
49277
49521
|
TOOL USE
|
|
49278
49522
|
|
|
49279
|
-
You have access to a set of tools that are executed upon the user's approval. You can use
|
|
49523
|
+
You have access to a set of tools that are executed upon the user's approval. You can use up to 5 tool calls per message, and will receive the results of those tool uses in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.
|
|
49280
49524
|
|
|
49281
49525
|
# Tool Use Formatting
|
|
49282
49526
|
|
|
@@ -49342,18 +49586,16 @@ ${tools.map((tool) => {
|
|
|
49342
49586
|
|
|
49343
49587
|
1. **Outline Your Thought Process**
|
|
49344
49588
|
- Before using a tool, wrap your reasoning inside \`<thinking>\` tags. Be concise—just enough to clarify your plan and the rationale behind selecting a specific tool.
|
|
49345
|
-
|
|
49346
49589
|
2. **Wait for Feedback**
|
|
49347
49590
|
- After using a tool, wait for the user's response indicating success/failure or any output logs. Do not assume the result of a tool without explicit confirmation.
|
|
49348
|
-
|
|
49349
49591
|
3. **Error Handling**
|
|
49350
49592
|
- If a tool fails or produces an unexpected result, analyze the error, decide on an alternative approach or tool, and proceed carefully.
|
|
49351
|
-
|
|
49352
49593
|
4. **Avoid Repetition**
|
|
49353
49594
|
- Do not quote or repeat previous commands or prompts verbatim. Move the conversation forward by focusing on the latest required action.
|
|
49354
|
-
|
|
49355
49595
|
5. **No Unnecessary Re-invocations**
|
|
49356
|
-
- Only invoke the same tool again if a genuine need arises (e.g., different parameters or updated context)
|
|
49596
|
+
- Only invoke the same tool again if a genuine need arises (e.g., different parameters or updated context).
|
|
49597
|
+
6. **Tool Call Limit**
|
|
49598
|
+
- Do not make more than 5 tool calls in a single message.`;
|
|
49357
49599
|
};
|
|
49358
49600
|
var agentsPrompt = (agents, name) => `
|
|
49359
49601
|
====
|
|
@@ -49480,6 +49722,9 @@ ${instance.prompt}`;
|
|
|
49480
49722
|
this.config = config;
|
|
49481
49723
|
this.#policies = policies;
|
|
49482
49724
|
}
|
|
49725
|
+
get parameters() {
|
|
49726
|
+
return this.ai.options.parameters;
|
|
49727
|
+
}
|
|
49483
49728
|
get messages() {
|
|
49484
49729
|
return this.#messages;
|
|
49485
49730
|
}
|
|
@@ -49676,8 +49921,8 @@ ${instance.prompt}`;
|
|
|
49676
49921
|
}
|
|
49677
49922
|
async#invokeTool(name, args) {
|
|
49678
49923
|
try {
|
|
49679
|
-
const
|
|
49680
|
-
if (!
|
|
49924
|
+
const handler15 = this.handlers[name]?.handler;
|
|
49925
|
+
if (!handler15) {
|
|
49681
49926
|
return {
|
|
49682
49927
|
type: "Error" /* Error */,
|
|
49683
49928
|
message: responsePrompts.errorInvokeTool(name, "Tool not found"),
|
|
@@ -49696,7 +49941,7 @@ ${instance.prompt}`;
|
|
|
49696
49941
|
if (resp) {
|
|
49697
49942
|
return resp;
|
|
49698
49943
|
}
|
|
49699
|
-
return await
|
|
49944
|
+
return await handler15(this.config.provider, args);
|
|
49700
49945
|
} catch (error) {
|
|
49701
49946
|
return {
|
|
49702
49947
|
type: "Error" /* Error */,
|
|
@@ -50035,7 +50280,7 @@ var editingFilesPrompt = (toolNamePrefix) => `
|
|
|
50035
50280
|
|
|
50036
50281
|
EDITING FILES
|
|
50037
50282
|
|
|
50038
|
-
You have
|
|
50283
|
+
You have two file-manipulation tools: **${toolNamePrefix}write_to_file** (full overwrite) and **${toolNamePrefix}edit_file** (targeted anchor-based edits). Choose the smallest safe operation for every change.
|
|
50039
50284
|
|
|
50040
50285
|
# ${toolNamePrefix}write_to_file
|
|
50041
50286
|
|
|
@@ -50047,16 +50292,16 @@ You have access to two tools for working with files: **${toolNamePrefix}write_to
|
|
|
50047
50292
|
|
|
50048
50293
|
- Initial file creation, such as when scaffolding a new project.
|
|
50049
50294
|
- Overwriting large boilerplate files where you want to replace the entire content at once.
|
|
50050
|
-
- When the complexity or number of changes would make ${toolNamePrefix}
|
|
50295
|
+
- When the complexity or number of changes would make ${toolNamePrefix}edit_file unwieldy or error-prone.
|
|
50051
50296
|
- When you need to completely restructure a file's content or change its fundamental organization.
|
|
50052
50297
|
|
|
50053
50298
|
## Important Considerations
|
|
50054
50299
|
|
|
50055
50300
|
- Using ${toolNamePrefix}write_to_file requires providing the file's complete final content.
|
|
50056
|
-
- If you only need to make small changes to an existing file, consider using ${toolNamePrefix}
|
|
50301
|
+
- If you only need to make small changes to an existing file, consider using ${toolNamePrefix}edit_file instead to avoid unnecessarily rewriting the entire file.
|
|
50057
50302
|
- While ${toolNamePrefix}write_to_file should not be your default choice, don't hesitate to use it when the situation truly calls for it.
|
|
50058
50303
|
|
|
50059
|
-
# ${toolNamePrefix}
|
|
50304
|
+
# ${toolNamePrefix}edit_file
|
|
50060
50305
|
|
|
50061
50306
|
## Purpose
|
|
50062
50307
|
|
|
@@ -50075,10 +50320,10 @@ You have access to two tools for working with files: **${toolNamePrefix}write_to
|
|
|
50075
50320
|
|
|
50076
50321
|
# Choosing the Appropriate Tool
|
|
50077
50322
|
|
|
50078
|
-
- **Default to ${toolNamePrefix}
|
|
50323
|
+
- **Default to ${toolNamePrefix}edit_file** for most changes. It keeps diffs small and reduces risk.
|
|
50079
50324
|
- **Use ${toolNamePrefix}write_to_file** when:
|
|
50080
50325
|
- Creating new files
|
|
50081
|
-
- The changes are so extensive that using ${toolNamePrefix}
|
|
50326
|
+
- The changes are so extensive that using ${toolNamePrefix}edit_file would be more complex or risky
|
|
50082
50327
|
- You need to completely reorganize or restructure a file
|
|
50083
50328
|
- The file is relatively small and the changes affect most of its content
|
|
50084
50329
|
- You're generating boilerplate or template files
|
|
@@ -50086,11 +50331,12 @@ You have access to two tools for working with files: **${toolNamePrefix}write_to
|
|
|
50086
50331
|
# Workflow Tips
|
|
50087
50332
|
|
|
50088
50333
|
1. Before editing, assess the scope of your changes and decide which tool to use.
|
|
50089
|
-
2. For targeted edits, apply ${toolNamePrefix}
|
|
50334
|
+
2. For targeted edits, apply ${toolNamePrefix}edit_file with carefully crafted before/after text anchors. If you need multiple changes, you can stack multiple operations within a single ${toolNamePrefix}edit_file call.
|
|
50090
50335
|
3. For major overhauls or initial file creation, rely on ${toolNamePrefix}write_to_file.
|
|
50091
|
-
4. Once the file has been edited with either ${toolNamePrefix}write_to_file or ${toolNamePrefix}
|
|
50336
|
+
4. Once the file has been edited with either ${toolNamePrefix}write_to_file or ${toolNamePrefix}edit_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 operations, since it reflects any auto-formatting or user-applied changes.
|
|
50092
50337
|
|
|
50093
|
-
|
|
50338
|
+
Picking the right tool keeps edits minimal, safe, and easy to review.
|
|
50339
|
+
`;
|
|
50094
50340
|
var rules = (toolNamePrefix) => `
|
|
50095
50341
|
====
|
|
50096
50342
|
|
|
@@ -50101,10 +50347,10 @@ RULES
|
|
|
50101
50347
|
For text files (e.g. README.md), append a footer with the same notice.
|
|
50102
50348
|
- Never describe what changed inside code comments; comments must focus on purpose or usage only.
|
|
50103
50349
|
- Before using ${toolNamePrefix}execute_command, consider SYSTEM INFORMATION to ensure commands suit the user's OS. If a command must run in a subdirectory, prepend a single \`cd childDir &&\` segment.
|
|
50104
|
-
- Use ${toolNamePrefix}search_files for broad analysis, then ${toolNamePrefix}read_file to inspect context, and finally ${toolNamePrefix}
|
|
50105
|
-
- Prefer ${toolNamePrefix}
|
|
50350
|
+
- Use ${toolNamePrefix}search_files for broad analysis, then ${toolNamePrefix}read_file to inspect context, and finally ${toolNamePrefix}edit_file or ${toolNamePrefix}write_to_file to modify.
|
|
50351
|
+
- Prefer ${toolNamePrefix}edit_file for focused edits; choose ${toolNamePrefix}write_to_file for new files or complete rewrites.
|
|
50106
50352
|
- When creating a new file, look for existing files with similar content or patterns; if found, read them and use their structure or conventions as a reference.
|
|
50107
|
-
-
|
|
50353
|
+
- Use before/after text anchors in ${toolNamePrefix}edit_file to target changes. If multiple operations are needed, list them in file order.
|
|
50108
50354
|
- Do not guess unseen content. Read existing files first unless creating new ones.
|
|
50109
50355
|
- Follow existing style, lint, and naming conventions. Ensure all changes compile and pass tests where applicable.
|
|
50110
50356
|
- ALWAYS wait for the user's confirmation after each tool call before starting the next step.
|
|
@@ -54480,6 +54726,65 @@ var KnowledgeManagementPolicy = (tools) => {
|
|
|
54480
54726
|
}
|
|
54481
54727
|
};
|
|
54482
54728
|
};
|
|
54729
|
+
// ../core/src/Agent/policies/TruncateContext.ts
|
|
54730
|
+
var DEFAULT_MAX_TOKENS_ESTIMATE = 8000;
|
|
54731
|
+
function getMaxTokens(agent) {
|
|
54732
|
+
const params = agent.parameters || {};
|
|
54733
|
+
if (params.maxTokens && typeof params.maxTokens === "number" && params.maxTokens > 0) {
|
|
54734
|
+
return params.maxTokens;
|
|
54735
|
+
}
|
|
54736
|
+
return DEFAULT_MAX_TOKENS_ESTIMATE;
|
|
54737
|
+
}
|
|
54738
|
+
function estimateTokens(text) {
|
|
54739
|
+
return Math.ceil(text.length / 4);
|
|
54740
|
+
}
|
|
54741
|
+
var TruncateContextPolicy = (tools) => {
|
|
54742
|
+
return {
|
|
54743
|
+
name: "truncatecontext" /* TruncateContext */,
|
|
54744
|
+
async onBeforeRequest(agent) {
|
|
54745
|
+
const messages = agent.messages;
|
|
54746
|
+
if (messages.length < 3) {
|
|
54747
|
+
return;
|
|
54748
|
+
}
|
|
54749
|
+
let totalTokens = 0;
|
|
54750
|
+
for (const msg of messages) {
|
|
54751
|
+
if (typeof msg.content === "string") {
|
|
54752
|
+
totalTokens += estimateTokens(msg.content);
|
|
54753
|
+
} else if (Array.isArray(msg.content)) {
|
|
54754
|
+
for (const block of msg.content) {
|
|
54755
|
+
if (typeof block === "object" && "text" in block && typeof block.text === "string") {
|
|
54756
|
+
totalTokens += estimateTokens(block.text);
|
|
54757
|
+
}
|
|
54758
|
+
}
|
|
54759
|
+
}
|
|
54760
|
+
}
|
|
54761
|
+
const maxTokens = getMaxTokens(agent);
|
|
54762
|
+
if (totalTokens <= maxTokens) {
|
|
54763
|
+
return;
|
|
54764
|
+
}
|
|
54765
|
+
const totalMessages = messages.length;
|
|
54766
|
+
const messagesToKeep = Math.ceil(totalMessages / 2);
|
|
54767
|
+
const minKeep = Math.max(2, messagesToKeep);
|
|
54768
|
+
if (minKeep >= totalMessages) {
|
|
54769
|
+
return;
|
|
54770
|
+
}
|
|
54771
|
+
const keepFromStart = Math.floor(minKeep / 2);
|
|
54772
|
+
const keepFromEnd = minKeep - keepFromStart;
|
|
54773
|
+
const startMessages = messages.slice(0, keepFromStart);
|
|
54774
|
+
const endMessages = messages.slice(-keepFromEnd);
|
|
54775
|
+
const truncatedCount = totalMessages - minKeep;
|
|
54776
|
+
const truncatedMessages = [
|
|
54777
|
+
...startMessages,
|
|
54778
|
+
{
|
|
54779
|
+
role: "user",
|
|
54780
|
+
content: `Note: ${truncatedCount} messages were truncated from the middle to prevent context overflow.`
|
|
54781
|
+
},
|
|
54782
|
+
...endMessages
|
|
54783
|
+
];
|
|
54784
|
+
agent.setMessages(truncatedMessages);
|
|
54785
|
+
}
|
|
54786
|
+
};
|
|
54787
|
+
};
|
|
54483
54788
|
// ../core/src/Agent/index.ts
|
|
54484
54789
|
var allAgents = [architectAgentInfo, coderAgentInfo, analyzerAgentInfo, codeFixerAgentInfo];
|
|
54485
54790
|
// ../core/src/AiTool/createNewProject.ts
|
|
@@ -59537,15 +59842,15 @@ function useKeypress(userHandler) {
|
|
|
59537
59842
|
signal.current = userHandler;
|
|
59538
59843
|
useEffect((rl) => {
|
|
59539
59844
|
let ignore = false;
|
|
59540
|
-
const
|
|
59845
|
+
const handler15 = withUpdates((_input, event) => {
|
|
59541
59846
|
if (ignore)
|
|
59542
59847
|
return;
|
|
59543
59848
|
signal.current(event, rl);
|
|
59544
59849
|
});
|
|
59545
|
-
rl.input.on("keypress",
|
|
59850
|
+
rl.input.on("keypress", handler15);
|
|
59546
59851
|
return () => {
|
|
59547
59852
|
ignore = true;
|
|
59548
|
-
rl.input.removeListener("keypress",
|
|
59853
|
+
rl.input.removeListener("keypress", handler15);
|
|
59549
59854
|
};
|
|
59550
59855
|
}, []);
|
|
59551
59856
|
}
|
|
@@ -59727,16 +60032,16 @@ class Emitter {
|
|
|
59727
60032
|
|
|
59728
60033
|
class SignalExitBase {
|
|
59729
60034
|
}
|
|
59730
|
-
var signalExitWrap = (
|
|
60035
|
+
var signalExitWrap = (handler15) => {
|
|
59731
60036
|
return {
|
|
59732
60037
|
onExit(cb, opts) {
|
|
59733
|
-
return
|
|
60038
|
+
return handler15.onExit(cb, opts);
|
|
59734
60039
|
},
|
|
59735
60040
|
load() {
|
|
59736
|
-
return
|
|
60041
|
+
return handler15.load();
|
|
59737
60042
|
},
|
|
59738
60043
|
unload() {
|
|
59739
|
-
return
|
|
60044
|
+
return handler15.unload();
|
|
59740
60045
|
}
|
|
59741
60046
|
};
|
|
59742
60047
|
};
|
|
@@ -61255,6 +61560,10 @@ class Runner {
|
|
|
61255
61560
|
this.#hasKnowledgeManagementPolicy = true;
|
|
61256
61561
|
console.log("KnowledgeManagementPolicy enabled");
|
|
61257
61562
|
break;
|
|
61563
|
+
case "truncatecontext" /* TruncateContext */:
|
|
61564
|
+
policies2.push(TruncateContextPolicy);
|
|
61565
|
+
console.log("TruncateContextPolicy enabled");
|
|
61566
|
+
break;
|
|
61258
61567
|
default:
|
|
61259
61568
|
console.log("Unknown policy:", policy);
|
|
61260
61569
|
break;
|