@polka-codes/cli-shared 0.8.17 → 0.8.18
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 +73 -130
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -36790,78 +36790,31 @@ var editFile = async (fileContent, operations) => {
|
|
|
36790
36790
|
if (!operations || operations.length === 0) {
|
|
36791
36791
|
throw new Error("At least one edit operation is required");
|
|
36792
36792
|
}
|
|
36793
|
-
const originalLines = fileContent.split(`
|
|
36794
|
-
`);
|
|
36795
36793
|
let updatedContent = fileContent;
|
|
36796
36794
|
for (const operation of operations) {
|
|
36797
|
-
updatedContent = await applyEditOperation(updatedContent, operation
|
|
36795
|
+
updatedContent = await applyEditOperation(updatedContent, operation);
|
|
36798
36796
|
}
|
|
36799
36797
|
return updatedContent;
|
|
36800
36798
|
};
|
|
36801
|
-
async function applyEditOperation(fileContent, operation
|
|
36802
|
-
const {
|
|
36803
|
-
if (
|
|
36804
|
-
|
|
36805
|
-
}
|
|
36806
|
-
if (start_anchor === START_OF_FILE) {
|
|
36807
|
-
if (!end_anchor) {
|
|
36808
|
-
return new_text + fileContent;
|
|
36809
|
-
}
|
|
36810
|
-
const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
|
|
36811
|
-
return new_text + fileContent.slice(afterIndex);
|
|
36799
|
+
async function applyEditOperation(fileContent, operation) {
|
|
36800
|
+
const { search, replace } = operation;
|
|
36801
|
+
if (search === START_OF_FILE && replace === END_OF_FILE) {
|
|
36802
|
+
throw new Error("Cannot search for START_OF_FILE and replace with END_OF_FILE");
|
|
36812
36803
|
}
|
|
36813
|
-
if (
|
|
36814
|
-
|
|
36815
|
-
return fileContent + new_text;
|
|
36816
|
-
}
|
|
36817
|
-
const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
|
|
36818
|
-
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
36819
|
-
return fileContent.slice(0, beforeEndIndex) + new_text;
|
|
36820
|
-
}
|
|
36821
|
-
if (start_anchor && end_anchor) {
|
|
36822
|
-
const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
|
|
36823
|
-
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
36824
|
-
const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines, beforeEndIndex);
|
|
36825
|
-
return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(afterIndex);
|
|
36804
|
+
if (search === END_OF_FILE && replace === START_OF_FILE) {
|
|
36805
|
+
throw new Error("Cannot search for END_OF_FILE and replace with START_OF_FILE");
|
|
36826
36806
|
}
|
|
36827
|
-
if (
|
|
36828
|
-
|
|
36829
|
-
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
36830
|
-
return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(beforeEndIndex);
|
|
36807
|
+
if (search === START_OF_FILE) {
|
|
36808
|
+
return replace + fileContent;
|
|
36831
36809
|
}
|
|
36832
|
-
if (
|
|
36833
|
-
|
|
36834
|
-
return fileContent.slice(0, afterIndex) + new_text + fileContent.slice(afterIndex);
|
|
36810
|
+
if (search === END_OF_FILE) {
|
|
36811
|
+
return fileContent + replace;
|
|
36835
36812
|
}
|
|
36836
|
-
|
|
36837
|
-
}
|
|
36838
|
-
function findTextWithHint(content, searchText, lineHint, originalLines, startIndex = 0) {
|
|
36839
|
-
if (lineHint && lineHint > 0 && lineHint <= originalLines.length) {
|
|
36840
|
-
const hintIndex = getLineStartIndex(originalLines, lineHint - 1);
|
|
36841
|
-
const searchRadius = 5;
|
|
36842
|
-
const windowStart = Math.max(0, hintIndex - searchRadius * 50);
|
|
36843
|
-
const windowEnd = Math.min(content.length, hintIndex + searchRadius * 50);
|
|
36844
|
-
const windowContent = content.slice(windowStart, windowEnd);
|
|
36845
|
-
const relativeIndex = windowContent.indexOf(searchText);
|
|
36846
|
-
if (relativeIndex !== -1) {
|
|
36847
|
-
const absoluteIndex = windowStart + relativeIndex;
|
|
36848
|
-
if (absoluteIndex >= startIndex) {
|
|
36849
|
-
return absoluteIndex;
|
|
36850
|
-
}
|
|
36851
|
-
}
|
|
36852
|
-
}
|
|
36853
|
-
const index = content.indexOf(searchText, startIndex);
|
|
36813
|
+
const index = fileContent.indexOf(search);
|
|
36854
36814
|
if (index === -1) {
|
|
36855
|
-
throw new Error(`Could not find text: ${
|
|
36856
|
-
}
|
|
36857
|
-
return index;
|
|
36858
|
-
}
|
|
36859
|
-
function getLineStartIndex(lines, lineIndex) {
|
|
36860
|
-
let index = 0;
|
|
36861
|
-
for (let i2 = 0;i2 < lineIndex && i2 < lines.length; i2++) {
|
|
36862
|
-
index += lines[i2].length + 1;
|
|
36815
|
+
throw new Error(`Could not find text: ${search}`);
|
|
36863
36816
|
}
|
|
36864
|
-
return index;
|
|
36817
|
+
return fileContent.slice(0, index) + replace + fileContent.slice(index + search.length);
|
|
36865
36818
|
}
|
|
36866
36819
|
// ../core/src/tools/utils/getArg.ts
|
|
36867
36820
|
var getString = (args, name, defaultValue) => {
|
|
@@ -38044,7 +37997,7 @@ var renameFile_default = {
|
|
|
38044
37997
|
// ../core/src/tools/editFile.ts
|
|
38045
37998
|
var toolInfo13 = {
|
|
38046
37999
|
name: "edit_file",
|
|
38047
|
-
description: "Request to edit file contents using
|
|
38000
|
+
description: "Request to edit file contents using search/replace operations. Supports multiple edit operations in a single call.",
|
|
38048
38001
|
parameters: [
|
|
38049
38002
|
{
|
|
38050
38003
|
name: "path",
|
|
@@ -38054,39 +38007,21 @@ var toolInfo13 = {
|
|
|
38054
38007
|
},
|
|
38055
38008
|
{
|
|
38056
38009
|
name: "operations",
|
|
38057
|
-
description: "Edit operation with
|
|
38010
|
+
description: "Edit operation with search and replace parameters",
|
|
38058
38011
|
required: true,
|
|
38059
38012
|
allowMultiple: true,
|
|
38060
38013
|
children: [
|
|
38061
38014
|
{
|
|
38062
|
-
name: "
|
|
38063
|
-
description: `Text to
|
|
38064
|
-
required: false,
|
|
38065
|
-
usageValue: "Text before the edit location"
|
|
38066
|
-
},
|
|
38067
|
-
{
|
|
38068
|
-
name: "end_anchor",
|
|
38069
|
-
description: `Text to find as the end anchor (use ${END_OF_FILE} for file end)`,
|
|
38070
|
-
required: false,
|
|
38071
|
-
usageValue: "Text after the edit location"
|
|
38072
|
-
},
|
|
38073
|
-
{
|
|
38074
|
-
name: "new_text",
|
|
38075
|
-
description: "Text to replace the content between start_anchor and end_anchor",
|
|
38015
|
+
name: "search",
|
|
38016
|
+
description: `Text to search for and replace (use ${START_OF_FILE} to insert at file start, ${END_OF_FILE} to insert at file end)`,
|
|
38076
38017
|
required: true,
|
|
38077
|
-
usageValue: "
|
|
38018
|
+
usageValue: "Text to find and replace"
|
|
38078
38019
|
},
|
|
38079
38020
|
{
|
|
38080
|
-
name: "
|
|
38081
|
-
description: "
|
|
38082
|
-
required:
|
|
38083
|
-
usageValue: "
|
|
38084
|
-
},
|
|
38085
|
-
{
|
|
38086
|
-
name: "end_anchor_line_start",
|
|
38087
|
-
description: "Optional line number hint for end_anchor location (1-based)",
|
|
38088
|
-
required: false,
|
|
38089
|
-
usageValue: "20"
|
|
38021
|
+
name: "replace",
|
|
38022
|
+
description: "Text to replace the search text with",
|
|
38023
|
+
required: true,
|
|
38024
|
+
usageValue: "Replacement text"
|
|
38090
38025
|
}
|
|
38091
38026
|
],
|
|
38092
38027
|
usageValue: "operations here"
|
|
@@ -38094,7 +38029,7 @@ var toolInfo13 = {
|
|
|
38094
38029
|
],
|
|
38095
38030
|
examples: [
|
|
38096
38031
|
{
|
|
38097
|
-
description: "Replace
|
|
38032
|
+
description: "Replace specific text",
|
|
38098
38033
|
parameters: [
|
|
38099
38034
|
{
|
|
38100
38035
|
name: "path",
|
|
@@ -38103,11 +38038,12 @@ var toolInfo13 = {
|
|
|
38103
38038
|
{
|
|
38104
38039
|
name: "operations",
|
|
38105
38040
|
value: {
|
|
38106
|
-
|
|
38107
|
-
|
|
38108
|
-
|
|
38041
|
+
search: `function oldFunction() {
|
|
38042
|
+
return 42;
|
|
38043
|
+
}`,
|
|
38044
|
+
replace: `function newFunction() {
|
|
38109
38045
|
return "new implementation";
|
|
38110
|
-
`
|
|
38046
|
+
}`
|
|
38111
38047
|
}
|
|
38112
38048
|
}
|
|
38113
38049
|
]
|
|
@@ -38122,9 +38058,8 @@ var toolInfo13 = {
|
|
|
38122
38058
|
{
|
|
38123
38059
|
name: "operations",
|
|
38124
38060
|
value: {
|
|
38125
|
-
|
|
38126
|
-
|
|
38127
|
-
new_text: `// File header comment
|
|
38061
|
+
search: START_OF_FILE,
|
|
38062
|
+
replace: `// File header comment
|
|
38128
38063
|
`
|
|
38129
38064
|
}
|
|
38130
38065
|
}
|
|
@@ -38141,20 +38076,37 @@ var toolInfo13 = {
|
|
|
38141
38076
|
name: "operations",
|
|
38142
38077
|
value: [
|
|
38143
38078
|
{
|
|
38144
|
-
|
|
38145
|
-
|
|
38146
|
-
new_text: ", { useState }"
|
|
38079
|
+
search: 'import React from "react"',
|
|
38080
|
+
replace: 'import React, { useState } from "react"'
|
|
38147
38081
|
},
|
|
38148
38082
|
{
|
|
38149
|
-
|
|
38150
|
-
|
|
38151
|
-
|
|
38083
|
+
search: `function Component() {
|
|
38084
|
+
return (`,
|
|
38085
|
+
replace: `function Component() {
|
|
38152
38086
|
const [state, setState] = useState(false);
|
|
38153
|
-
`
|
|
38087
|
+
return (`
|
|
38154
38088
|
}
|
|
38155
38089
|
]
|
|
38156
38090
|
}
|
|
38157
38091
|
]
|
|
38092
|
+
},
|
|
38093
|
+
{
|
|
38094
|
+
description: "Append content at end of file",
|
|
38095
|
+
parameters: [
|
|
38096
|
+
{
|
|
38097
|
+
name: "path",
|
|
38098
|
+
value: "src/footer.ts"
|
|
38099
|
+
},
|
|
38100
|
+
{
|
|
38101
|
+
name: "operations",
|
|
38102
|
+
value: {
|
|
38103
|
+
search: END_OF_FILE,
|
|
38104
|
+
replace: `
|
|
38105
|
+
// End of file appended comment
|
|
38106
|
+
`
|
|
38107
|
+
}
|
|
38108
|
+
}
|
|
38109
|
+
]
|
|
38158
38110
|
}
|
|
38159
38111
|
],
|
|
38160
38112
|
permissionLevel: 2 /* Write */
|
|
@@ -38701,7 +38653,6 @@ class AgentBase {
|
|
|
38701
38653
|
config;
|
|
38702
38654
|
handlers;
|
|
38703
38655
|
#messages = [];
|
|
38704
|
-
#originalTask;
|
|
38705
38656
|
#policies;
|
|
38706
38657
|
constructor(name, ai, config) {
|
|
38707
38658
|
this.ai = ai;
|
|
@@ -38747,7 +38698,6 @@ ${instance.prompt}`;
|
|
|
38747
38698
|
await this.config.callback?.(event);
|
|
38748
38699
|
}
|
|
38749
38700
|
async start(prompt) {
|
|
38750
|
-
this.#originalTask = prompt;
|
|
38751
38701
|
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
38752
38702
|
return await this.#processLoop(prompt);
|
|
38753
38703
|
}
|
|
@@ -38874,41 +38824,31 @@ ${instance.prompt}`;
|
|
|
38874
38824
|
if (toolResponses.length > 0) {
|
|
38875
38825
|
break outer;
|
|
38876
38826
|
}
|
|
38877
|
-
const handOverResp = {
|
|
38878
|
-
...toolResp,
|
|
38879
|
-
originalTask: this.#originalTask
|
|
38880
|
-
};
|
|
38881
38827
|
await this.#callback({
|
|
38882
38828
|
kind: "ToolHandOver" /* ToolHandOver */,
|
|
38883
38829
|
agent: this,
|
|
38884
38830
|
tool: content.name,
|
|
38885
|
-
agentName:
|
|
38886
|
-
task:
|
|
38887
|
-
context:
|
|
38888
|
-
files:
|
|
38889
|
-
originalTask: handOverResp.originalTask
|
|
38831
|
+
agentName: toolResp.agentName,
|
|
38832
|
+
task: toolResp.task,
|
|
38833
|
+
context: toolResp.context,
|
|
38834
|
+
files: toolResp.files
|
|
38890
38835
|
});
|
|
38891
|
-
return { type: "exit", reason:
|
|
38836
|
+
return { type: "exit", reason: toolResp };
|
|
38892
38837
|
}
|
|
38893
38838
|
case "Delegate" /* Delegate */: {
|
|
38894
38839
|
if (toolResponses.length > 0) {
|
|
38895
38840
|
break outer;
|
|
38896
38841
|
}
|
|
38897
|
-
const delegateResp = {
|
|
38898
|
-
...toolResp,
|
|
38899
|
-
originalTask: this.#originalTask
|
|
38900
|
-
};
|
|
38901
38842
|
await this.#callback({
|
|
38902
38843
|
kind: "ToolDelegate" /* ToolDelegate */,
|
|
38903
38844
|
agent: this,
|
|
38904
38845
|
tool: content.name,
|
|
38905
|
-
agentName:
|
|
38906
|
-
task:
|
|
38907
|
-
context:
|
|
38908
|
-
files:
|
|
38909
|
-
originalTask: delegateResp.originalTask
|
|
38846
|
+
agentName: toolResp.agentName,
|
|
38847
|
+
task: toolResp.task,
|
|
38848
|
+
context: toolResp.context,
|
|
38849
|
+
files: toolResp.files
|
|
38910
38850
|
});
|
|
38911
|
-
return { type: "exit", reason:
|
|
38851
|
+
return { type: "exit", reason: toolResp };
|
|
38912
38852
|
}
|
|
38913
38853
|
case "Pause" /* Pause */: {
|
|
38914
38854
|
await this.#callback({ kind: "ToolPause" /* ToolPause */, agent: this, tool: content.name, object: toolResp.object });
|
|
@@ -39132,6 +39072,7 @@ var codeFixerAgentInfo = {
|
|
|
39132
39072
|
class MultiAgent {
|
|
39133
39073
|
#config;
|
|
39134
39074
|
#agents = [];
|
|
39075
|
+
#originalTask;
|
|
39135
39076
|
constructor(config) {
|
|
39136
39077
|
this.#config = config;
|
|
39137
39078
|
}
|
|
@@ -39139,11 +39080,11 @@ class MultiAgent {
|
|
|
39139
39080
|
switch (exitReason.type) {
|
|
39140
39081
|
case "HandOver" /* HandOver */: {
|
|
39141
39082
|
this.#agents.pop();
|
|
39142
|
-
const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files,
|
|
39083
|
+
const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, this.#originalTask) ?? exitReason.task;
|
|
39143
39084
|
return await this.#startTask(exitReason.agentName, prompt);
|
|
39144
39085
|
}
|
|
39145
39086
|
case "Delegate" /* Delegate */: {
|
|
39146
|
-
const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files,
|
|
39087
|
+
const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, this.#originalTask) ?? exitReason.task;
|
|
39147
39088
|
const delegateResult = await this.#startTask(exitReason.agentName, prompt);
|
|
39148
39089
|
switch (delegateResult.type) {
|
|
39149
39090
|
case "HandOver" /* HandOver */:
|
|
@@ -39175,7 +39116,9 @@ class MultiAgent {
|
|
|
39175
39116
|
if (this.#agents.length > 0) {
|
|
39176
39117
|
throw new Error("An active agent already exists");
|
|
39177
39118
|
}
|
|
39178
|
-
|
|
39119
|
+
this.#originalTask = options.task;
|
|
39120
|
+
return this.#startTask(options.agentName, `<task>${options.task}</task>
|
|
39121
|
+
<context>${options.context}</context>`);
|
|
39179
39122
|
}
|
|
39180
39123
|
async continueTask(userMessage) {
|
|
39181
39124
|
if (!this.#agents.length) {
|
|
@@ -43593,8 +43536,8 @@ var executeAgentTool = async (definition, agent, params) => {
|
|
|
43593
43536
|
}
|
|
43594
43537
|
const exitReason = await agent.startTask({
|
|
43595
43538
|
agentName: definition.agent,
|
|
43596
|
-
task:
|
|
43597
|
-
|
|
43539
|
+
task: definition.prompt,
|
|
43540
|
+
context: definition.formatInput(params)
|
|
43598
43541
|
});
|
|
43599
43542
|
if (exitReason.type === "Exit" /* Exit */) {
|
|
43600
43543
|
return definition.parseOutput(exitReason.message);
|