@polka-codes/cli-shared 0.8.16 → 0.8.17
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 +35 -35
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -36799,41 +36799,41 @@ var editFile = async (fileContent, operations) => {
|
|
|
36799
36799
|
return updatedContent;
|
|
36800
36800
|
};
|
|
36801
36801
|
async function applyEditOperation(fileContent, operation, originalLines) {
|
|
36802
|
-
const {
|
|
36803
|
-
if (
|
|
36802
|
+
const { start_anchor, end_anchor, new_text, start_anchor_line_start, end_anchor_line_start } = operation;
|
|
36803
|
+
if (start_anchor === START_OF_FILE && end_anchor === END_OF_FILE) {
|
|
36804
36804
|
return new_text;
|
|
36805
36805
|
}
|
|
36806
|
-
if (
|
|
36807
|
-
if (!
|
|
36806
|
+
if (start_anchor === START_OF_FILE) {
|
|
36807
|
+
if (!end_anchor) {
|
|
36808
36808
|
return new_text + fileContent;
|
|
36809
36809
|
}
|
|
36810
|
-
const afterIndex = findTextWithHint(fileContent,
|
|
36810
|
+
const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
|
|
36811
36811
|
return new_text + fileContent.slice(afterIndex);
|
|
36812
36812
|
}
|
|
36813
|
-
if (
|
|
36814
|
-
if (!
|
|
36813
|
+
if (end_anchor === END_OF_FILE) {
|
|
36814
|
+
if (!start_anchor) {
|
|
36815
36815
|
return fileContent + new_text;
|
|
36816
36816
|
}
|
|
36817
|
-
const beforeIndex = findTextWithHint(fileContent,
|
|
36818
|
-
const beforeEndIndex = beforeIndex +
|
|
36817
|
+
const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
|
|
36818
|
+
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
36819
36819
|
return fileContent.slice(0, beforeEndIndex) + new_text;
|
|
36820
36820
|
}
|
|
36821
|
-
if (
|
|
36822
|
-
const beforeIndex = findTextWithHint(fileContent,
|
|
36823
|
-
const beforeEndIndex = beforeIndex +
|
|
36824
|
-
const afterIndex = findTextWithHint(fileContent,
|
|
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
36825
|
return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(afterIndex);
|
|
36826
36826
|
}
|
|
36827
|
-
if (
|
|
36828
|
-
const beforeIndex = findTextWithHint(fileContent,
|
|
36829
|
-
const beforeEndIndex = beforeIndex +
|
|
36827
|
+
if (start_anchor) {
|
|
36828
|
+
const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
|
|
36829
|
+
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
36830
36830
|
return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(beforeEndIndex);
|
|
36831
36831
|
}
|
|
36832
|
-
if (
|
|
36833
|
-
const afterIndex = findTextWithHint(fileContent,
|
|
36832
|
+
if (end_anchor) {
|
|
36833
|
+
const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
|
|
36834
36834
|
return fileContent.slice(0, afterIndex) + new_text + fileContent.slice(afterIndex);
|
|
36835
36835
|
}
|
|
36836
|
-
throw new Error("Either
|
|
36836
|
+
throw new Error("Either start_anchor or end_anchor must be specified");
|
|
36837
36837
|
}
|
|
36838
36838
|
function findTextWithHint(content, searchText, lineHint, originalLines, startIndex = 0) {
|
|
36839
36839
|
if (lineHint && lineHint > 0 && lineHint <= originalLines.length) {
|
|
@@ -38054,37 +38054,37 @@ var toolInfo13 = {
|
|
|
38054
38054
|
},
|
|
38055
38055
|
{
|
|
38056
38056
|
name: "operations",
|
|
38057
|
-
description: "Edit operation with
|
|
38057
|
+
description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints",
|
|
38058
38058
|
required: true,
|
|
38059
38059
|
allowMultiple: true,
|
|
38060
38060
|
children: [
|
|
38061
38061
|
{
|
|
38062
|
-
name: "
|
|
38062
|
+
name: "start_anchor",
|
|
38063
38063
|
description: `Text to find as the start anchor (use ${START_OF_FILE} for file start)`,
|
|
38064
38064
|
required: false,
|
|
38065
38065
|
usageValue: "Text before the edit location"
|
|
38066
38066
|
},
|
|
38067
38067
|
{
|
|
38068
|
-
name: "
|
|
38068
|
+
name: "end_anchor",
|
|
38069
38069
|
description: `Text to find as the end anchor (use ${END_OF_FILE} for file end)`,
|
|
38070
38070
|
required: false,
|
|
38071
38071
|
usageValue: "Text after the edit location"
|
|
38072
38072
|
},
|
|
38073
38073
|
{
|
|
38074
38074
|
name: "new_text",
|
|
38075
|
-
description: "Text to replace the content between
|
|
38075
|
+
description: "Text to replace the content between start_anchor and end_anchor",
|
|
38076
38076
|
required: true,
|
|
38077
38077
|
usageValue: "New text content"
|
|
38078
38078
|
},
|
|
38079
38079
|
{
|
|
38080
|
-
name: "
|
|
38081
|
-
description: "Optional line number hint for
|
|
38080
|
+
name: "start_anchor_line_start",
|
|
38081
|
+
description: "Optional line number hint for start_anchor location (1-based)",
|
|
38082
38082
|
required: false,
|
|
38083
38083
|
usageValue: "10"
|
|
38084
38084
|
},
|
|
38085
38085
|
{
|
|
38086
|
-
name: "
|
|
38087
|
-
description: "Optional line number hint for
|
|
38086
|
+
name: "end_anchor_line_start",
|
|
38087
|
+
description: "Optional line number hint for end_anchor location (1-based)",
|
|
38088
38088
|
required: false,
|
|
38089
38089
|
usageValue: "20"
|
|
38090
38090
|
}
|
|
@@ -38103,8 +38103,8 @@ var toolInfo13 = {
|
|
|
38103
38103
|
{
|
|
38104
38104
|
name: "operations",
|
|
38105
38105
|
value: {
|
|
38106
|
-
|
|
38107
|
-
|
|
38106
|
+
start_anchor: "function oldFunction() {",
|
|
38107
|
+
end_anchor: "}",
|
|
38108
38108
|
new_text: `
|
|
38109
38109
|
return "new implementation";
|
|
38110
38110
|
`
|
|
@@ -38122,8 +38122,8 @@ var toolInfo13 = {
|
|
|
38122
38122
|
{
|
|
38123
38123
|
name: "operations",
|
|
38124
38124
|
value: {
|
|
38125
|
-
|
|
38126
|
-
|
|
38125
|
+
start_anchor: START_OF_FILE,
|
|
38126
|
+
end_anchor: "export",
|
|
38127
38127
|
new_text: `// File header comment
|
|
38128
38128
|
`
|
|
38129
38129
|
}
|
|
@@ -38141,13 +38141,13 @@ var toolInfo13 = {
|
|
|
38141
38141
|
name: "operations",
|
|
38142
38142
|
value: [
|
|
38143
38143
|
{
|
|
38144
|
-
|
|
38145
|
-
|
|
38144
|
+
start_anchor: "import React",
|
|
38145
|
+
end_anchor: 'from "react"',
|
|
38146
38146
|
new_text: ", { useState }"
|
|
38147
38147
|
},
|
|
38148
38148
|
{
|
|
38149
|
-
|
|
38150
|
-
|
|
38149
|
+
start_anchor: "function Component() {",
|
|
38150
|
+
end_anchor: "return (",
|
|
38151
38151
|
new_text: `
|
|
38152
38152
|
const [state, setState] = useState(false);
|
|
38153
38153
|
`
|