@polka-codes/core 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/_tsup-dts-rollup.d.ts +52 -52
- package/dist/index.js +35 -35
- package/package.json +1 -1
|
@@ -1113,32 +1113,32 @@ declare const _default_14: {
|
|
|
1113
1113
|
readonly usageValue: "File path here";
|
|
1114
1114
|
}, {
|
|
1115
1115
|
readonly name: "operations";
|
|
1116
|
-
readonly description: "Edit operation with
|
|
1116
|
+
readonly description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints";
|
|
1117
1117
|
readonly required: true;
|
|
1118
1118
|
readonly allowMultiple: true;
|
|
1119
1119
|
readonly children: [{
|
|
1120
|
-
readonly name: "
|
|
1120
|
+
readonly name: "start_anchor";
|
|
1121
1121
|
readonly description: "Text to find as the start anchor (use <<<START_OF_FILE>>> for file start)";
|
|
1122
1122
|
readonly required: false;
|
|
1123
1123
|
readonly usageValue: "Text before the edit location";
|
|
1124
1124
|
}, {
|
|
1125
|
-
readonly name: "
|
|
1125
|
+
readonly name: "end_anchor";
|
|
1126
1126
|
readonly description: "Text to find as the end anchor (use <<<END_OF_FILE>>> for file end)";
|
|
1127
1127
|
readonly required: false;
|
|
1128
1128
|
readonly usageValue: "Text after the edit location";
|
|
1129
1129
|
}, {
|
|
1130
1130
|
readonly name: "new_text";
|
|
1131
|
-
readonly description: "Text to replace the content between
|
|
1131
|
+
readonly description: "Text to replace the content between start_anchor and end_anchor";
|
|
1132
1132
|
readonly required: true;
|
|
1133
1133
|
readonly usageValue: "New text content";
|
|
1134
1134
|
}, {
|
|
1135
|
-
readonly name: "
|
|
1136
|
-
readonly description: "Optional line number hint for
|
|
1135
|
+
readonly name: "start_anchor_line_start";
|
|
1136
|
+
readonly description: "Optional line number hint for start_anchor location (1-based)";
|
|
1137
1137
|
readonly required: false;
|
|
1138
1138
|
readonly usageValue: "10";
|
|
1139
1139
|
}, {
|
|
1140
|
-
readonly name: "
|
|
1141
|
-
readonly description: "Optional line number hint for
|
|
1140
|
+
readonly name: "end_anchor_line_start";
|
|
1141
|
+
readonly description: "Optional line number hint for end_anchor location (1-based)";
|
|
1142
1142
|
readonly required: false;
|
|
1143
1143
|
readonly usageValue: "20";
|
|
1144
1144
|
}];
|
|
@@ -1152,8 +1152,8 @@ declare const _default_14: {
|
|
|
1152
1152
|
}, {
|
|
1153
1153
|
readonly name: "operations";
|
|
1154
1154
|
readonly value: {
|
|
1155
|
-
readonly
|
|
1156
|
-
readonly
|
|
1155
|
+
readonly start_anchor: "function oldFunction() {";
|
|
1156
|
+
readonly end_anchor: "}";
|
|
1157
1157
|
readonly new_text: "\n return \"new implementation\";\n";
|
|
1158
1158
|
};
|
|
1159
1159
|
}];
|
|
@@ -1165,8 +1165,8 @@ declare const _default_14: {
|
|
|
1165
1165
|
}, {
|
|
1166
1166
|
readonly name: "operations";
|
|
1167
1167
|
readonly value: {
|
|
1168
|
-
readonly
|
|
1169
|
-
readonly
|
|
1168
|
+
readonly start_anchor: "<<<START_OF_FILE>>>";
|
|
1169
|
+
readonly end_anchor: "export";
|
|
1170
1170
|
readonly new_text: "// File header comment\n";
|
|
1171
1171
|
};
|
|
1172
1172
|
}];
|
|
@@ -1178,12 +1178,12 @@ declare const _default_14: {
|
|
|
1178
1178
|
}, {
|
|
1179
1179
|
readonly name: "operations";
|
|
1180
1180
|
readonly value: [{
|
|
1181
|
-
readonly
|
|
1182
|
-
readonly
|
|
1181
|
+
readonly start_anchor: "import React";
|
|
1182
|
+
readonly end_anchor: "from \"react\"";
|
|
1183
1183
|
readonly new_text: ", { useState }";
|
|
1184
1184
|
}, {
|
|
1185
|
-
readonly
|
|
1186
|
-
readonly
|
|
1185
|
+
readonly start_anchor: "function Component() {";
|
|
1186
|
+
readonly end_anchor: "return (";
|
|
1187
1187
|
readonly new_text: "\n const [state, setState] = useState(false);\n ";
|
|
1188
1188
|
}];
|
|
1189
1189
|
}];
|
|
@@ -1200,32 +1200,32 @@ declare const _default_14: {
|
|
|
1200
1200
|
readonly usageValue: "File path here";
|
|
1201
1201
|
}, {
|
|
1202
1202
|
readonly name: "operations";
|
|
1203
|
-
readonly description: "Edit operation with
|
|
1203
|
+
readonly description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints";
|
|
1204
1204
|
readonly required: true;
|
|
1205
1205
|
readonly allowMultiple: true;
|
|
1206
1206
|
readonly children: [{
|
|
1207
|
-
readonly name: "
|
|
1207
|
+
readonly name: "start_anchor";
|
|
1208
1208
|
readonly description: "Text to find as the start anchor (use <<<START_OF_FILE>>> for file start)";
|
|
1209
1209
|
readonly required: false;
|
|
1210
1210
|
readonly usageValue: "Text before the edit location";
|
|
1211
1211
|
}, {
|
|
1212
|
-
readonly name: "
|
|
1212
|
+
readonly name: "end_anchor";
|
|
1213
1213
|
readonly description: "Text to find as the end anchor (use <<<END_OF_FILE>>> for file end)";
|
|
1214
1214
|
readonly required: false;
|
|
1215
1215
|
readonly usageValue: "Text after the edit location";
|
|
1216
1216
|
}, {
|
|
1217
1217
|
readonly name: "new_text";
|
|
1218
|
-
readonly description: "Text to replace the content between
|
|
1218
|
+
readonly description: "Text to replace the content between start_anchor and end_anchor";
|
|
1219
1219
|
readonly required: true;
|
|
1220
1220
|
readonly usageValue: "New text content";
|
|
1221
1221
|
}, {
|
|
1222
|
-
readonly name: "
|
|
1223
|
-
readonly description: "Optional line number hint for
|
|
1222
|
+
readonly name: "start_anchor_line_start";
|
|
1223
|
+
readonly description: "Optional line number hint for start_anchor location (1-based)";
|
|
1224
1224
|
readonly required: false;
|
|
1225
1225
|
readonly usageValue: "10";
|
|
1226
1226
|
}, {
|
|
1227
|
-
readonly name: "
|
|
1228
|
-
readonly description: "Optional line number hint for
|
|
1227
|
+
readonly name: "end_anchor_line_start";
|
|
1228
|
+
readonly description: "Optional line number hint for end_anchor location (1-based)";
|
|
1229
1229
|
readonly required: false;
|
|
1230
1230
|
readonly usageValue: "20";
|
|
1231
1231
|
}];
|
|
@@ -1239,8 +1239,8 @@ declare const _default_14: {
|
|
|
1239
1239
|
}, {
|
|
1240
1240
|
readonly name: "operations";
|
|
1241
1241
|
readonly value: {
|
|
1242
|
-
readonly
|
|
1243
|
-
readonly
|
|
1242
|
+
readonly start_anchor: "function oldFunction() {";
|
|
1243
|
+
readonly end_anchor: "}";
|
|
1244
1244
|
readonly new_text: "\n return \"new implementation\";\n";
|
|
1245
1245
|
};
|
|
1246
1246
|
}];
|
|
@@ -1252,8 +1252,8 @@ declare const _default_14: {
|
|
|
1252
1252
|
}, {
|
|
1253
1253
|
readonly name: "operations";
|
|
1254
1254
|
readonly value: {
|
|
1255
|
-
readonly
|
|
1256
|
-
readonly
|
|
1255
|
+
readonly start_anchor: "<<<START_OF_FILE>>>";
|
|
1256
|
+
readonly end_anchor: "export";
|
|
1257
1257
|
readonly new_text: "// File header comment\n";
|
|
1258
1258
|
};
|
|
1259
1259
|
}];
|
|
@@ -1265,12 +1265,12 @@ declare const _default_14: {
|
|
|
1265
1265
|
}, {
|
|
1266
1266
|
readonly name: "operations";
|
|
1267
1267
|
readonly value: [{
|
|
1268
|
-
readonly
|
|
1269
|
-
readonly
|
|
1268
|
+
readonly start_anchor: "import React";
|
|
1269
|
+
readonly end_anchor: "from \"react\"";
|
|
1270
1270
|
readonly new_text: ", { useState }";
|
|
1271
1271
|
}, {
|
|
1272
|
-
readonly
|
|
1273
|
-
readonly
|
|
1272
|
+
readonly start_anchor: "function Component() {";
|
|
1273
|
+
readonly end_anchor: "return (";
|
|
1274
1274
|
readonly new_text: "\n const [state, setState] = useState(false);\n ";
|
|
1275
1275
|
}];
|
|
1276
1276
|
}];
|
|
@@ -1996,11 +1996,11 @@ export { editFile_2 as editFile_alias_4 }
|
|
|
1996
1996
|
export declare const editingFilesPrompt: (toolNamePrefix: string) => string;
|
|
1997
1997
|
|
|
1998
1998
|
declare interface EditOperation {
|
|
1999
|
-
|
|
2000
|
-
|
|
1999
|
+
start_anchor?: string;
|
|
2000
|
+
end_anchor?: string;
|
|
2001
2001
|
new_text: string;
|
|
2002
|
-
|
|
2003
|
-
|
|
2002
|
+
start_anchor_line_start?: number;
|
|
2003
|
+
end_anchor_line_start?: number;
|
|
2004
2004
|
}
|
|
2005
2005
|
export { EditOperation }
|
|
2006
2006
|
export { EditOperation as EditOperation_alias_1 }
|
|
@@ -3206,32 +3206,32 @@ export declare const toolInfo_alias_3: {
|
|
|
3206
3206
|
readonly usageValue: "File path here";
|
|
3207
3207
|
}, {
|
|
3208
3208
|
readonly name: "operations";
|
|
3209
|
-
readonly description: "Edit operation with
|
|
3209
|
+
readonly description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints";
|
|
3210
3210
|
readonly required: true;
|
|
3211
3211
|
readonly allowMultiple: true;
|
|
3212
3212
|
readonly children: [{
|
|
3213
|
-
readonly name: "
|
|
3213
|
+
readonly name: "start_anchor";
|
|
3214
3214
|
readonly description: "Text to find as the start anchor (use <<<START_OF_FILE>>> for file start)";
|
|
3215
3215
|
readonly required: false;
|
|
3216
3216
|
readonly usageValue: "Text before the edit location";
|
|
3217
3217
|
}, {
|
|
3218
|
-
readonly name: "
|
|
3218
|
+
readonly name: "end_anchor";
|
|
3219
3219
|
readonly description: "Text to find as the end anchor (use <<<END_OF_FILE>>> for file end)";
|
|
3220
3220
|
readonly required: false;
|
|
3221
3221
|
readonly usageValue: "Text after the edit location";
|
|
3222
3222
|
}, {
|
|
3223
3223
|
readonly name: "new_text";
|
|
3224
|
-
readonly description: "Text to replace the content between
|
|
3224
|
+
readonly description: "Text to replace the content between start_anchor and end_anchor";
|
|
3225
3225
|
readonly required: true;
|
|
3226
3226
|
readonly usageValue: "New text content";
|
|
3227
3227
|
}, {
|
|
3228
|
-
readonly name: "
|
|
3229
|
-
readonly description: "Optional line number hint for
|
|
3228
|
+
readonly name: "start_anchor_line_start";
|
|
3229
|
+
readonly description: "Optional line number hint for start_anchor location (1-based)";
|
|
3230
3230
|
readonly required: false;
|
|
3231
3231
|
readonly usageValue: "10";
|
|
3232
3232
|
}, {
|
|
3233
|
-
readonly name: "
|
|
3234
|
-
readonly description: "Optional line number hint for
|
|
3233
|
+
readonly name: "end_anchor_line_start";
|
|
3234
|
+
readonly description: "Optional line number hint for end_anchor location (1-based)";
|
|
3235
3235
|
readonly required: false;
|
|
3236
3236
|
readonly usageValue: "20";
|
|
3237
3237
|
}];
|
|
@@ -3245,8 +3245,8 @@ export declare const toolInfo_alias_3: {
|
|
|
3245
3245
|
}, {
|
|
3246
3246
|
readonly name: "operations";
|
|
3247
3247
|
readonly value: {
|
|
3248
|
-
readonly
|
|
3249
|
-
readonly
|
|
3248
|
+
readonly start_anchor: "function oldFunction() {";
|
|
3249
|
+
readonly end_anchor: "}";
|
|
3250
3250
|
readonly new_text: "\n return \"new implementation\";\n";
|
|
3251
3251
|
};
|
|
3252
3252
|
}];
|
|
@@ -3258,8 +3258,8 @@ export declare const toolInfo_alias_3: {
|
|
|
3258
3258
|
}, {
|
|
3259
3259
|
readonly name: "operations";
|
|
3260
3260
|
readonly value: {
|
|
3261
|
-
readonly
|
|
3262
|
-
readonly
|
|
3261
|
+
readonly start_anchor: "<<<START_OF_FILE>>>";
|
|
3262
|
+
readonly end_anchor: "export";
|
|
3263
3263
|
readonly new_text: "// File header comment\n";
|
|
3264
3264
|
};
|
|
3265
3265
|
}];
|
|
@@ -3271,12 +3271,12 @@ export declare const toolInfo_alias_3: {
|
|
|
3271
3271
|
}, {
|
|
3272
3272
|
readonly name: "operations";
|
|
3273
3273
|
readonly value: [{
|
|
3274
|
-
readonly
|
|
3275
|
-
readonly
|
|
3274
|
+
readonly start_anchor: "import React";
|
|
3275
|
+
readonly end_anchor: "from \"react\"";
|
|
3276
3276
|
readonly new_text: ", { useState }";
|
|
3277
3277
|
}, {
|
|
3278
|
-
readonly
|
|
3279
|
-
readonly
|
|
3278
|
+
readonly start_anchor: "function Component() {";
|
|
3279
|
+
readonly end_anchor: "return (";
|
|
3280
3280
|
readonly new_text: "\n const [state, setState] = useState(false);\n ";
|
|
3281
3281
|
}];
|
|
3282
3282
|
}];
|
package/dist/index.js
CHANGED
|
@@ -929,41 +929,41 @@ var editFile = async (fileContent, operations) => {
|
|
|
929
929
|
return updatedContent;
|
|
930
930
|
};
|
|
931
931
|
async function applyEditOperation(fileContent, operation, originalLines) {
|
|
932
|
-
const {
|
|
933
|
-
if (
|
|
932
|
+
const { start_anchor, end_anchor, new_text, start_anchor_line_start, end_anchor_line_start } = operation;
|
|
933
|
+
if (start_anchor === START_OF_FILE && end_anchor === END_OF_FILE) {
|
|
934
934
|
return new_text;
|
|
935
935
|
}
|
|
936
|
-
if (
|
|
937
|
-
if (!
|
|
936
|
+
if (start_anchor === START_OF_FILE) {
|
|
937
|
+
if (!end_anchor) {
|
|
938
938
|
return new_text + fileContent;
|
|
939
939
|
}
|
|
940
|
-
const afterIndex = findTextWithHint(fileContent,
|
|
940
|
+
const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
|
|
941
941
|
return new_text + fileContent.slice(afterIndex);
|
|
942
942
|
}
|
|
943
|
-
if (
|
|
944
|
-
if (!
|
|
943
|
+
if (end_anchor === END_OF_FILE) {
|
|
944
|
+
if (!start_anchor) {
|
|
945
945
|
return fileContent + new_text;
|
|
946
946
|
}
|
|
947
|
-
const beforeIndex = findTextWithHint(fileContent,
|
|
948
|
-
const beforeEndIndex = beforeIndex +
|
|
947
|
+
const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
|
|
948
|
+
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
949
949
|
return fileContent.slice(0, beforeEndIndex) + new_text;
|
|
950
950
|
}
|
|
951
|
-
if (
|
|
952
|
-
const beforeIndex = findTextWithHint(fileContent,
|
|
953
|
-
const beforeEndIndex = beforeIndex +
|
|
954
|
-
const afterIndex = findTextWithHint(fileContent,
|
|
951
|
+
if (start_anchor && end_anchor) {
|
|
952
|
+
const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
|
|
953
|
+
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
954
|
+
const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines, beforeEndIndex);
|
|
955
955
|
return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(afterIndex);
|
|
956
956
|
}
|
|
957
|
-
if (
|
|
958
|
-
const beforeIndex = findTextWithHint(fileContent,
|
|
959
|
-
const beforeEndIndex = beforeIndex +
|
|
957
|
+
if (start_anchor) {
|
|
958
|
+
const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
|
|
959
|
+
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
960
960
|
return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(beforeEndIndex);
|
|
961
961
|
}
|
|
962
|
-
if (
|
|
963
|
-
const afterIndex = findTextWithHint(fileContent,
|
|
962
|
+
if (end_anchor) {
|
|
963
|
+
const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
|
|
964
964
|
return fileContent.slice(0, afterIndex) + new_text + fileContent.slice(afterIndex);
|
|
965
965
|
}
|
|
966
|
-
throw new Error("Either
|
|
966
|
+
throw new Error("Either start_anchor or end_anchor must be specified");
|
|
967
967
|
}
|
|
968
968
|
function findTextWithHint(content, searchText, lineHint, originalLines, startIndex = 0) {
|
|
969
969
|
if (lineHint && lineHint > 0 && lineHint <= originalLines.length) {
|
|
@@ -2194,37 +2194,37 @@ var toolInfo13 = {
|
|
|
2194
2194
|
},
|
|
2195
2195
|
{
|
|
2196
2196
|
name: "operations",
|
|
2197
|
-
description: "Edit operation with
|
|
2197
|
+
description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints",
|
|
2198
2198
|
required: true,
|
|
2199
2199
|
allowMultiple: true,
|
|
2200
2200
|
children: [
|
|
2201
2201
|
{
|
|
2202
|
-
name: "
|
|
2202
|
+
name: "start_anchor",
|
|
2203
2203
|
description: `Text to find as the start anchor (use ${START_OF_FILE} for file start)`,
|
|
2204
2204
|
required: false,
|
|
2205
2205
|
usageValue: "Text before the edit location"
|
|
2206
2206
|
},
|
|
2207
2207
|
{
|
|
2208
|
-
name: "
|
|
2208
|
+
name: "end_anchor",
|
|
2209
2209
|
description: `Text to find as the end anchor (use ${END_OF_FILE} for file end)`,
|
|
2210
2210
|
required: false,
|
|
2211
2211
|
usageValue: "Text after the edit location"
|
|
2212
2212
|
},
|
|
2213
2213
|
{
|
|
2214
2214
|
name: "new_text",
|
|
2215
|
-
description: "Text to replace the content between
|
|
2215
|
+
description: "Text to replace the content between start_anchor and end_anchor",
|
|
2216
2216
|
required: true,
|
|
2217
2217
|
usageValue: "New text content"
|
|
2218
2218
|
},
|
|
2219
2219
|
{
|
|
2220
|
-
name: "
|
|
2221
|
-
description: "Optional line number hint for
|
|
2220
|
+
name: "start_anchor_line_start",
|
|
2221
|
+
description: "Optional line number hint for start_anchor location (1-based)",
|
|
2222
2222
|
required: false,
|
|
2223
2223
|
usageValue: "10"
|
|
2224
2224
|
},
|
|
2225
2225
|
{
|
|
2226
|
-
name: "
|
|
2227
|
-
description: "Optional line number hint for
|
|
2226
|
+
name: "end_anchor_line_start",
|
|
2227
|
+
description: "Optional line number hint for end_anchor location (1-based)",
|
|
2228
2228
|
required: false,
|
|
2229
2229
|
usageValue: "20"
|
|
2230
2230
|
}
|
|
@@ -2243,8 +2243,8 @@ var toolInfo13 = {
|
|
|
2243
2243
|
{
|
|
2244
2244
|
name: "operations",
|
|
2245
2245
|
value: {
|
|
2246
|
-
|
|
2247
|
-
|
|
2246
|
+
start_anchor: "function oldFunction() {",
|
|
2247
|
+
end_anchor: "}",
|
|
2248
2248
|
new_text: '\n return "new implementation";\n'
|
|
2249
2249
|
}
|
|
2250
2250
|
}
|
|
@@ -2260,8 +2260,8 @@ var toolInfo13 = {
|
|
|
2260
2260
|
{
|
|
2261
2261
|
name: "operations",
|
|
2262
2262
|
value: {
|
|
2263
|
-
|
|
2264
|
-
|
|
2263
|
+
start_anchor: START_OF_FILE,
|
|
2264
|
+
end_anchor: "export",
|
|
2265
2265
|
new_text: "// File header comment\n"
|
|
2266
2266
|
}
|
|
2267
2267
|
}
|
|
@@ -2278,13 +2278,13 @@ var toolInfo13 = {
|
|
|
2278
2278
|
name: "operations",
|
|
2279
2279
|
value: [
|
|
2280
2280
|
{
|
|
2281
|
-
|
|
2282
|
-
|
|
2281
|
+
start_anchor: "import React",
|
|
2282
|
+
end_anchor: 'from "react"',
|
|
2283
2283
|
new_text: ", { useState }"
|
|
2284
2284
|
},
|
|
2285
2285
|
{
|
|
2286
|
-
|
|
2287
|
-
|
|
2286
|
+
start_anchor: "function Component() {",
|
|
2287
|
+
end_anchor: "return (",
|
|
2288
2288
|
new_text: "\n const [state, setState] = useState(false);\n "
|
|
2289
2289
|
}
|
|
2290
2290
|
]
|