@polka-codes/core 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.
@@ -1105,7 +1105,7 @@ export { _default_13 as renameFile_alias_2 }
1105
1105
  declare const _default_14: {
1106
1106
  handler: ToolHandler<{
1107
1107
  readonly name: "edit_file";
1108
- readonly description: "Request to edit file contents using before/after text anchors with flexible operations. Supports multiple edit operations in a single call.";
1108
+ readonly description: "Request to edit file contents using search/replace operations. Supports multiple edit operations in a single call.";
1109
1109
  readonly parameters: [{
1110
1110
  readonly name: "path";
1111
1111
  readonly description: "The path of the file to edit";
@@ -1113,48 +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 start_anchor, end_anchor, new_text, and optional line range hints";
1116
+ readonly description: "Edit operation with search and replace parameters";
1117
1117
  readonly required: true;
1118
1118
  readonly allowMultiple: true;
1119
1119
  readonly children: [{
1120
- readonly name: "start_anchor";
1121
- readonly description: "Text to find as the start anchor (use <<<START_OF_FILE>>> for file start)";
1122
- readonly required: false;
1123
- readonly usageValue: "Text before the edit location";
1124
- }, {
1125
- readonly name: "end_anchor";
1126
- readonly description: "Text to find as the end anchor (use <<<END_OF_FILE>>> for file end)";
1127
- readonly required: false;
1128
- readonly usageValue: "Text after the edit location";
1129
- }, {
1130
- readonly name: "new_text";
1131
- readonly description: "Text to replace the content between start_anchor and end_anchor";
1120
+ readonly name: "search";
1121
+ readonly description: "Text to search for and replace (use <<<START_OF_FILE>>> to insert at file start, <<<END_OF_FILE>>> to insert at file end)";
1132
1122
  readonly required: true;
1133
- readonly usageValue: "New text content";
1123
+ readonly usageValue: "Text to find and replace";
1134
1124
  }, {
1135
- readonly name: "start_anchor_line_start";
1136
- readonly description: "Optional line number hint for start_anchor location (1-based)";
1137
- readonly required: false;
1138
- readonly usageValue: "10";
1139
- }, {
1140
- readonly name: "end_anchor_line_start";
1141
- readonly description: "Optional line number hint for end_anchor location (1-based)";
1142
- readonly required: false;
1143
- readonly usageValue: "20";
1125
+ readonly name: "replace";
1126
+ readonly description: "Text to replace the search text with";
1127
+ readonly required: true;
1128
+ readonly usageValue: "Replacement text";
1144
1129
  }];
1145
1130
  readonly usageValue: "operations here";
1146
1131
  }];
1147
1132
  readonly examples: [{
1148
- readonly description: "Replace content between two text anchors";
1133
+ readonly description: "Replace specific text";
1149
1134
  readonly parameters: [{
1150
1135
  readonly name: "path";
1151
1136
  readonly value: "src/main.ts";
1152
1137
  }, {
1153
1138
  readonly name: "operations";
1154
1139
  readonly value: {
1155
- readonly start_anchor: "function oldFunction() {";
1156
- readonly end_anchor: "}";
1157
- readonly new_text: "\n return \"new implementation\";\n";
1140
+ readonly search: "function oldFunction() {\n return 42;\n}";
1141
+ readonly replace: "function newFunction() {\n return \"new implementation\";\n}";
1158
1142
  };
1159
1143
  }];
1160
1144
  }, {
@@ -1165,9 +1149,8 @@ declare const _default_14: {
1165
1149
  }, {
1166
1150
  readonly name: "operations";
1167
1151
  readonly value: {
1168
- readonly start_anchor: "<<<START_OF_FILE>>>";
1169
- readonly end_anchor: "export";
1170
- readonly new_text: "// File header comment\n";
1152
+ readonly search: "<<<START_OF_FILE>>>";
1153
+ readonly replace: "// File header comment\n";
1171
1154
  };
1172
1155
  }];
1173
1156
  }, {
@@ -1178,21 +1161,31 @@ declare const _default_14: {
1178
1161
  }, {
1179
1162
  readonly name: "operations";
1180
1163
  readonly value: [{
1181
- readonly start_anchor: "import React";
1182
- readonly end_anchor: "from \"react\"";
1183
- readonly new_text: ", { useState }";
1164
+ readonly search: "import React from \"react\"";
1165
+ readonly replace: "import React, { useState } from \"react\"";
1184
1166
  }, {
1185
- readonly start_anchor: "function Component() {";
1186
- readonly end_anchor: "return (";
1187
- readonly new_text: "\n const [state, setState] = useState(false);\n ";
1167
+ readonly search: "function Component() {\n return (";
1168
+ readonly replace: "function Component() {\n const [state, setState] = useState(false);\n return (";
1188
1169
  }];
1189
1170
  }];
1171
+ }, {
1172
+ readonly description: "Append content at end of file";
1173
+ readonly parameters: [{
1174
+ readonly name: "path";
1175
+ readonly value: "src/footer.ts";
1176
+ }, {
1177
+ readonly name: "operations";
1178
+ readonly value: {
1179
+ readonly search: "<<<END_OF_FILE>>>";
1180
+ readonly replace: "\n// End of file appended comment\n";
1181
+ };
1182
+ }];
1190
1183
  }];
1191
1184
  readonly permissionLevel: PermissionLevel.Write;
1192
1185
  }, FilesystemProvider>;
1193
1186
  isAvailable: (provider: FilesystemProvider) => boolean;
1194
1187
  name: "edit_file";
1195
- description: "Request to edit file contents using before/after text anchors with flexible operations. Supports multiple edit operations in a single call.";
1188
+ description: "Request to edit file contents using search/replace operations. Supports multiple edit operations in a single call.";
1196
1189
  parameters: [{
1197
1190
  readonly name: "path";
1198
1191
  readonly description: "The path of the file to edit";
@@ -1200,48 +1193,32 @@ declare const _default_14: {
1200
1193
  readonly usageValue: "File path here";
1201
1194
  }, {
1202
1195
  readonly name: "operations";
1203
- readonly description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints";
1196
+ readonly description: "Edit operation with search and replace parameters";
1204
1197
  readonly required: true;
1205
1198
  readonly allowMultiple: true;
1206
1199
  readonly children: [{
1207
- readonly name: "start_anchor";
1208
- readonly description: "Text to find as the start anchor (use <<<START_OF_FILE>>> for file start)";
1209
- readonly required: false;
1210
- readonly usageValue: "Text before the edit location";
1211
- }, {
1212
- readonly name: "end_anchor";
1213
- readonly description: "Text to find as the end anchor (use <<<END_OF_FILE>>> for file end)";
1214
- readonly required: false;
1215
- readonly usageValue: "Text after the edit location";
1216
- }, {
1217
- readonly name: "new_text";
1218
- readonly description: "Text to replace the content between start_anchor and end_anchor";
1200
+ readonly name: "search";
1201
+ readonly description: "Text to search for and replace (use <<<START_OF_FILE>>> to insert at file start, <<<END_OF_FILE>>> to insert at file end)";
1219
1202
  readonly required: true;
1220
- readonly usageValue: "New text content";
1221
- }, {
1222
- readonly name: "start_anchor_line_start";
1223
- readonly description: "Optional line number hint for start_anchor location (1-based)";
1224
- readonly required: false;
1225
- readonly usageValue: "10";
1203
+ readonly usageValue: "Text to find and replace";
1226
1204
  }, {
1227
- readonly name: "end_anchor_line_start";
1228
- readonly description: "Optional line number hint for end_anchor location (1-based)";
1229
- readonly required: false;
1230
- readonly usageValue: "20";
1205
+ readonly name: "replace";
1206
+ readonly description: "Text to replace the search text with";
1207
+ readonly required: true;
1208
+ readonly usageValue: "Replacement text";
1231
1209
  }];
1232
1210
  readonly usageValue: "operations here";
1233
1211
  }];
1234
1212
  examples: [{
1235
- readonly description: "Replace content between two text anchors";
1213
+ readonly description: "Replace specific text";
1236
1214
  readonly parameters: [{
1237
1215
  readonly name: "path";
1238
1216
  readonly value: "src/main.ts";
1239
1217
  }, {
1240
1218
  readonly name: "operations";
1241
1219
  readonly value: {
1242
- readonly start_anchor: "function oldFunction() {";
1243
- readonly end_anchor: "}";
1244
- readonly new_text: "\n return \"new implementation\";\n";
1220
+ readonly search: "function oldFunction() {\n return 42;\n}";
1221
+ readonly replace: "function newFunction() {\n return \"new implementation\";\n}";
1245
1222
  };
1246
1223
  }];
1247
1224
  }, {
@@ -1252,9 +1229,8 @@ declare const _default_14: {
1252
1229
  }, {
1253
1230
  readonly name: "operations";
1254
1231
  readonly value: {
1255
- readonly start_anchor: "<<<START_OF_FILE>>>";
1256
- readonly end_anchor: "export";
1257
- readonly new_text: "// File header comment\n";
1232
+ readonly search: "<<<START_OF_FILE>>>";
1233
+ readonly replace: "// File header comment\n";
1258
1234
  };
1259
1235
  }];
1260
1236
  }, {
@@ -1265,15 +1241,25 @@ declare const _default_14: {
1265
1241
  }, {
1266
1242
  readonly name: "operations";
1267
1243
  readonly value: [{
1268
- readonly start_anchor: "import React";
1269
- readonly end_anchor: "from \"react\"";
1270
- readonly new_text: ", { useState }";
1244
+ readonly search: "import React from \"react\"";
1245
+ readonly replace: "import React, { useState } from \"react\"";
1271
1246
  }, {
1272
- readonly start_anchor: "function Component() {";
1273
- readonly end_anchor: "return (";
1274
- readonly new_text: "\n const [state, setState] = useState(false);\n ";
1247
+ readonly search: "function Component() {\n return (";
1248
+ readonly replace: "function Component() {\n const [state, setState] = useState(false);\n return (";
1275
1249
  }];
1276
1250
  }];
1251
+ }, {
1252
+ readonly description: "Append content at end of file";
1253
+ readonly parameters: [{
1254
+ readonly name: "path";
1255
+ readonly value: "src/footer.ts";
1256
+ }, {
1257
+ readonly name: "operations";
1258
+ readonly value: {
1259
+ readonly search: "<<<END_OF_FILE>>>";
1260
+ readonly replace: "\n// End of file appended comment\n";
1261
+ };
1262
+ }];
1277
1263
  }];
1278
1264
  permissionLevel: PermissionLevel.Write;
1279
1265
  };
@@ -1983,7 +1969,7 @@ export { defaultModels }
1983
1969
  export { defaultModels as defaultModels_alias_1 }
1984
1970
 
1985
1971
  /**
1986
- * Apply multiple edit operations to file content using before/after text anchors
1972
+ * Apply multiple edit operations to file content using search/replace pattern.
1987
1973
  * @param fileContent - The original file content
1988
1974
  * @param operations - Array of edit operations to apply
1989
1975
  * @returns The modified file content
@@ -1995,12 +1981,12 @@ export { editFile_2 as editFile_alias_4 }
1995
1981
 
1996
1982
  export declare const editingFilesPrompt: (toolNamePrefix: string) => string;
1997
1983
 
1984
+ /**
1985
+ * Edit operation using search/replace pattern
1986
+ */
1998
1987
  declare interface EditOperation {
1999
- start_anchor?: string;
2000
- end_anchor?: string;
2001
- new_text: string;
2002
- start_anchor_line_start?: number;
2003
- end_anchor_line_start?: number;
1988
+ search: string;
1989
+ replace: string;
2004
1990
  }
2005
1991
  export { EditOperation }
2006
1992
  export { EditOperation as EditOperation_alias_1 }
@@ -2540,6 +2526,7 @@ declare class MultiAgent {
2540
2526
  startTask(options: {
2541
2527
  agentName: string;
2542
2528
  task: string;
2529
+ context: string;
2543
2530
  }): Promise<ExitReason>;
2544
2531
  continueTask(userMessage: string): Promise<ExitReason>;
2545
2532
  get hasActiveAgent(): boolean;
@@ -2852,7 +2839,6 @@ declare interface TaskEventToolHandOverDelegate extends TaskEventBase {
2852
2839
  task: string;
2853
2840
  context?: string;
2854
2841
  files?: string[];
2855
- originalTask?: string;
2856
2842
  }
2857
2843
  export { TaskEventToolHandOverDelegate }
2858
2844
  export { TaskEventToolHandOverDelegate as TaskEventToolHandOverDelegate_alias_1 }
@@ -3198,7 +3184,7 @@ export declare const toolInfo_alias_2: {
3198
3184
 
3199
3185
  export declare const toolInfo_alias_3: {
3200
3186
  readonly name: "edit_file";
3201
- readonly description: "Request to edit file contents using before/after text anchors with flexible operations. Supports multiple edit operations in a single call.";
3187
+ readonly description: "Request to edit file contents using search/replace operations. Supports multiple edit operations in a single call.";
3202
3188
  readonly parameters: [{
3203
3189
  readonly name: "path";
3204
3190
  readonly description: "The path of the file to edit";
@@ -3206,48 +3192,32 @@ export declare const toolInfo_alias_3: {
3206
3192
  readonly usageValue: "File path here";
3207
3193
  }, {
3208
3194
  readonly name: "operations";
3209
- readonly description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints";
3195
+ readonly description: "Edit operation with search and replace parameters";
3210
3196
  readonly required: true;
3211
3197
  readonly allowMultiple: true;
3212
3198
  readonly children: [{
3213
- readonly name: "start_anchor";
3214
- readonly description: "Text to find as the start anchor (use <<<START_OF_FILE>>> for file start)";
3215
- readonly required: false;
3216
- readonly usageValue: "Text before the edit location";
3217
- }, {
3218
- readonly name: "end_anchor";
3219
- readonly description: "Text to find as the end anchor (use <<<END_OF_FILE>>> for file end)";
3220
- readonly required: false;
3221
- readonly usageValue: "Text after the edit location";
3222
- }, {
3223
- readonly name: "new_text";
3224
- readonly description: "Text to replace the content between start_anchor and end_anchor";
3199
+ readonly name: "search";
3200
+ readonly description: "Text to search for and replace (use <<<START_OF_FILE>>> to insert at file start, <<<END_OF_FILE>>> to insert at file end)";
3225
3201
  readonly required: true;
3226
- readonly usageValue: "New text content";
3202
+ readonly usageValue: "Text to find and replace";
3227
3203
  }, {
3228
- readonly name: "start_anchor_line_start";
3229
- readonly description: "Optional line number hint for start_anchor location (1-based)";
3230
- readonly required: false;
3231
- readonly usageValue: "10";
3232
- }, {
3233
- readonly name: "end_anchor_line_start";
3234
- readonly description: "Optional line number hint for end_anchor location (1-based)";
3235
- readonly required: false;
3236
- readonly usageValue: "20";
3204
+ readonly name: "replace";
3205
+ readonly description: "Text to replace the search text with";
3206
+ readonly required: true;
3207
+ readonly usageValue: "Replacement text";
3237
3208
  }];
3238
3209
  readonly usageValue: "operations here";
3239
3210
  }];
3240
3211
  readonly examples: [{
3241
- readonly description: "Replace content between two text anchors";
3212
+ readonly description: "Replace specific text";
3242
3213
  readonly parameters: [{
3243
3214
  readonly name: "path";
3244
3215
  readonly value: "src/main.ts";
3245
3216
  }, {
3246
3217
  readonly name: "operations";
3247
3218
  readonly value: {
3248
- readonly start_anchor: "function oldFunction() {";
3249
- readonly end_anchor: "}";
3250
- readonly new_text: "\n return \"new implementation\";\n";
3219
+ readonly search: "function oldFunction() {\n return 42;\n}";
3220
+ readonly replace: "function newFunction() {\n return \"new implementation\";\n}";
3251
3221
  };
3252
3222
  }];
3253
3223
  }, {
@@ -3258,9 +3228,8 @@ export declare const toolInfo_alias_3: {
3258
3228
  }, {
3259
3229
  readonly name: "operations";
3260
3230
  readonly value: {
3261
- readonly start_anchor: "<<<START_OF_FILE>>>";
3262
- readonly end_anchor: "export";
3263
- readonly new_text: "// File header comment\n";
3231
+ readonly search: "<<<START_OF_FILE>>>";
3232
+ readonly replace: "// File header comment\n";
3264
3233
  };
3265
3234
  }];
3266
3235
  }, {
@@ -3271,15 +3240,25 @@ export declare const toolInfo_alias_3: {
3271
3240
  }, {
3272
3241
  readonly name: "operations";
3273
3242
  readonly value: [{
3274
- readonly start_anchor: "import React";
3275
- readonly end_anchor: "from \"react\"";
3276
- readonly new_text: ", { useState }";
3243
+ readonly search: "import React from \"react\"";
3244
+ readonly replace: "import React, { useState } from \"react\"";
3277
3245
  }, {
3278
- readonly start_anchor: "function Component() {";
3279
- readonly end_anchor: "return (";
3280
- readonly new_text: "\n const [state, setState] = useState(false);\n ";
3246
+ readonly search: "function Component() {\n return (";
3247
+ readonly replace: "function Component() {\n const [state, setState] = useState(false);\n return (";
3281
3248
  }];
3282
3249
  }];
3250
+ }, {
3251
+ readonly description: "Append content at end of file";
3252
+ readonly parameters: [{
3253
+ readonly name: "path";
3254
+ readonly value: "src/footer.ts";
3255
+ }, {
3256
+ readonly name: "operations";
3257
+ readonly value: {
3258
+ readonly search: "<<<END_OF_FILE>>>";
3259
+ readonly replace: "\n// End of file appended comment\n";
3260
+ };
3261
+ }];
3283
3262
  }];
3284
3263
  readonly permissionLevel: PermissionLevel.Write;
3285
3264
  };
@@ -3489,7 +3468,6 @@ declare type ToolResponseDelegate = {
3489
3468
  task: string;
3490
3469
  context?: string;
3491
3470
  files?: string[];
3492
- originalTask?: string;
3493
3471
  };
3494
3472
  export { ToolResponseDelegate }
3495
3473
  export { ToolResponseDelegate as ToolResponseDelegate_alias_1 }
@@ -3516,7 +3494,6 @@ declare type ToolResponseHandOver = {
3516
3494
  task: string;
3517
3495
  context?: string;
3518
3496
  files?: string[];
3519
- originalTask?: string;
3520
3497
  };
3521
3498
  export { ToolResponseHandOver }
3522
3499
  export { ToolResponseHandOver as ToolResponseHandOver_alias_1 }
package/dist/index.js CHANGED
@@ -921,77 +921,31 @@ var editFile = async (fileContent, operations) => {
921
921
  if (!operations || operations.length === 0) {
922
922
  throw new Error("At least one edit operation is required");
923
923
  }
924
- const originalLines = fileContent.split("\n");
925
924
  let updatedContent = fileContent;
926
925
  for (const operation of operations) {
927
- updatedContent = await applyEditOperation(updatedContent, operation, originalLines);
926
+ updatedContent = await applyEditOperation(updatedContent, operation);
928
927
  }
929
928
  return updatedContent;
930
929
  };
931
- async function applyEditOperation(fileContent, operation, originalLines) {
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
- return new_text;
935
- }
936
- if (start_anchor === START_OF_FILE) {
937
- if (!end_anchor) {
938
- return new_text + fileContent;
939
- }
940
- const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
941
- return new_text + fileContent.slice(afterIndex);
930
+ async function applyEditOperation(fileContent, operation) {
931
+ const { search, replace } = operation;
932
+ if (search === START_OF_FILE && replace === END_OF_FILE) {
933
+ throw new Error("Cannot search for START_OF_FILE and replace with END_OF_FILE");
942
934
  }
943
- if (end_anchor === END_OF_FILE) {
944
- if (!start_anchor) {
945
- return fileContent + new_text;
946
- }
947
- const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
948
- const beforeEndIndex = beforeIndex + start_anchor.length;
949
- return fileContent.slice(0, beforeEndIndex) + new_text;
950
- }
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
- return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(afterIndex);
956
- }
957
- if (start_anchor) {
958
- const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
959
- const beforeEndIndex = beforeIndex + start_anchor.length;
960
- return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(beforeEndIndex);
961
- }
962
- if (end_anchor) {
963
- const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
964
- return fileContent.slice(0, afterIndex) + new_text + fileContent.slice(afterIndex);
965
- }
966
- throw new Error("Either start_anchor or end_anchor must be specified");
967
- }
968
- function findTextWithHint(content, searchText, lineHint, originalLines, startIndex = 0) {
969
- if (lineHint && lineHint > 0 && lineHint <= originalLines.length) {
970
- const hintIndex = getLineStartIndex(originalLines, lineHint - 1);
971
- const searchRadius = 5;
972
- const windowStart = Math.max(0, hintIndex - searchRadius * 50);
973
- const windowEnd = Math.min(content.length, hintIndex + searchRadius * 50);
974
- const windowContent = content.slice(windowStart, windowEnd);
975
- const relativeIndex = windowContent.indexOf(searchText);
976
- if (relativeIndex !== -1) {
977
- const absoluteIndex = windowStart + relativeIndex;
978
- if (absoluteIndex >= startIndex) {
979
- return absoluteIndex;
980
- }
981
- }
935
+ if (search === END_OF_FILE && replace === START_OF_FILE) {
936
+ throw new Error("Cannot search for END_OF_FILE and replace with START_OF_FILE");
982
937
  }
983
- const index = content.indexOf(searchText, startIndex);
984
- if (index === -1) {
985
- throw new Error(`Could not find text: ${searchText}`);
938
+ if (search === START_OF_FILE) {
939
+ return replace + fileContent;
986
940
  }
987
- return index;
988
- }
989
- function getLineStartIndex(lines, lineIndex) {
990
- let index = 0;
991
- for (let i = 0; i < lineIndex && i < lines.length; i++) {
992
- index += lines[i].length + 1;
941
+ if (search === END_OF_FILE) {
942
+ return fileContent + replace;
993
943
  }
994
- return index;
944
+ const index = fileContent.indexOf(search);
945
+ if (index === -1) {
946
+ throw new Error(`Could not find text: ${search}`);
947
+ }
948
+ return fileContent.slice(0, index) + replace + fileContent.slice(index + search.length);
995
949
  }
996
950
 
997
951
  // src/tools/utils/getArg.ts
@@ -1373,7 +1327,6 @@ var handler3 = async (_provider, args) => {
1373
1327
  task,
1374
1328
  context,
1375
1329
  files
1376
- // originalTask will be set by AgentBase
1377
1330
  };
1378
1331
  };
1379
1332
  var isAvailable3 = (_provider) => {
@@ -2062,7 +2015,6 @@ var handler10 = async (_provider, args) => {
2062
2015
  task,
2063
2016
  context,
2064
2017
  files
2065
- // originalTask will be set by AgentBase
2066
2018
  };
2067
2019
  };
2068
2020
  var isAvailable10 = (_provider) => {
@@ -2184,7 +2136,7 @@ var renameFile_default = {
2184
2136
  // src/tools/editFile.ts
2185
2137
  var toolInfo13 = {
2186
2138
  name: "edit_file",
2187
- description: "Request to edit file contents using before/after text anchors with flexible operations. Supports multiple edit operations in a single call.",
2139
+ description: "Request to edit file contents using search/replace operations. Supports multiple edit operations in a single call.",
2188
2140
  parameters: [
2189
2141
  {
2190
2142
  name: "path",
@@ -2194,39 +2146,21 @@ var toolInfo13 = {
2194
2146
  },
2195
2147
  {
2196
2148
  name: "operations",
2197
- description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints",
2149
+ description: "Edit operation with search and replace parameters",
2198
2150
  required: true,
2199
2151
  allowMultiple: true,
2200
2152
  children: [
2201
2153
  {
2202
- name: "start_anchor",
2203
- description: `Text to find as the start anchor (use ${START_OF_FILE} for file start)`,
2204
- required: false,
2205
- usageValue: "Text before the edit location"
2206
- },
2207
- {
2208
- name: "end_anchor",
2209
- description: `Text to find as the end anchor (use ${END_OF_FILE} for file end)`,
2210
- required: false,
2211
- usageValue: "Text after the edit location"
2212
- },
2213
- {
2214
- name: "new_text",
2215
- description: "Text to replace the content between start_anchor and end_anchor",
2154
+ name: "search",
2155
+ description: `Text to search for and replace (use ${START_OF_FILE} to insert at file start, ${END_OF_FILE} to insert at file end)`,
2216
2156
  required: true,
2217
- usageValue: "New text content"
2157
+ usageValue: "Text to find and replace"
2218
2158
  },
2219
2159
  {
2220
- name: "start_anchor_line_start",
2221
- description: "Optional line number hint for start_anchor location (1-based)",
2222
- required: false,
2223
- usageValue: "10"
2224
- },
2225
- {
2226
- name: "end_anchor_line_start",
2227
- description: "Optional line number hint for end_anchor location (1-based)",
2228
- required: false,
2229
- usageValue: "20"
2160
+ name: "replace",
2161
+ description: "Text to replace the search text with",
2162
+ required: true,
2163
+ usageValue: "Replacement text"
2230
2164
  }
2231
2165
  ],
2232
2166
  usageValue: "operations here"
@@ -2234,7 +2168,7 @@ var toolInfo13 = {
2234
2168
  ],
2235
2169
  examples: [
2236
2170
  {
2237
- description: "Replace content between two text anchors",
2171
+ description: "Replace specific text",
2238
2172
  parameters: [
2239
2173
  {
2240
2174
  name: "path",
@@ -2243,9 +2177,8 @@ var toolInfo13 = {
2243
2177
  {
2244
2178
  name: "operations",
2245
2179
  value: {
2246
- start_anchor: "function oldFunction() {",
2247
- end_anchor: "}",
2248
- new_text: '\n return "new implementation";\n'
2180
+ search: "function oldFunction() {\n return 42;\n}",
2181
+ replace: 'function newFunction() {\n return "new implementation";\n}'
2249
2182
  }
2250
2183
  }
2251
2184
  ]
@@ -2260,9 +2193,8 @@ var toolInfo13 = {
2260
2193
  {
2261
2194
  name: "operations",
2262
2195
  value: {
2263
- start_anchor: START_OF_FILE,
2264
- end_anchor: "export",
2265
- new_text: "// File header comment\n"
2196
+ search: START_OF_FILE,
2197
+ replace: "// File header comment\n"
2266
2198
  }
2267
2199
  }
2268
2200
  ]
@@ -2278,18 +2210,32 @@ var toolInfo13 = {
2278
2210
  name: "operations",
2279
2211
  value: [
2280
2212
  {
2281
- start_anchor: "import React",
2282
- end_anchor: 'from "react"',
2283
- new_text: ", { useState }"
2213
+ search: 'import React from "react"',
2214
+ replace: 'import React, { useState } from "react"'
2284
2215
  },
2285
2216
  {
2286
- start_anchor: "function Component() {",
2287
- end_anchor: "return (",
2288
- new_text: "\n const [state, setState] = useState(false);\n "
2217
+ search: "function Component() {\n return (",
2218
+ replace: "function Component() {\n const [state, setState] = useState(false);\n return ("
2289
2219
  }
2290
2220
  ]
2291
2221
  }
2292
2222
  ]
2223
+ },
2224
+ {
2225
+ description: "Append content at end of file",
2226
+ parameters: [
2227
+ {
2228
+ name: "path",
2229
+ value: "src/footer.ts"
2230
+ },
2231
+ {
2232
+ name: "operations",
2233
+ value: {
2234
+ search: END_OF_FILE,
2235
+ replace: "\n// End of file appended comment\n"
2236
+ }
2237
+ }
2238
+ ]
2293
2239
  }
2294
2240
  ],
2295
2241
  permissionLevel: 2 /* Write */
@@ -2850,7 +2796,6 @@ var AgentBase = class {
2850
2796
  config;
2851
2797
  handlers;
2852
2798
  #messages = [];
2853
- #originalTask;
2854
2799
  #policies;
2855
2800
  constructor(name, ai, config) {
2856
2801
  this.ai = ai;
@@ -2896,7 +2841,6 @@ ${instance.prompt}`;
2896
2841
  await this.config.callback?.(event);
2897
2842
  }
2898
2843
  async start(prompt6) {
2899
- this.#originalTask = prompt6;
2900
2844
  this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
2901
2845
  return await this.#processLoop(prompt6);
2902
2846
  }
@@ -3022,41 +2966,31 @@ ${instance.prompt}`;
3022
2966
  if (toolResponses.length > 0) {
3023
2967
  break outer;
3024
2968
  }
3025
- const handOverResp = {
3026
- ...toolResp,
3027
- originalTask: this.#originalTask
3028
- };
3029
2969
  await this.#callback({
3030
2970
  kind: "ToolHandOver" /* ToolHandOver */,
3031
2971
  agent: this,
3032
2972
  tool: content.name,
3033
- agentName: handOverResp.agentName,
3034
- task: handOverResp.task,
3035
- context: handOverResp.context,
3036
- files: handOverResp.files,
3037
- originalTask: handOverResp.originalTask
2973
+ agentName: toolResp.agentName,
2974
+ task: toolResp.task,
2975
+ context: toolResp.context,
2976
+ files: toolResp.files
3038
2977
  });
3039
- return { type: "exit", reason: handOverResp };
2978
+ return { type: "exit", reason: toolResp };
3040
2979
  }
3041
2980
  case "Delegate" /* Delegate */: {
3042
2981
  if (toolResponses.length > 0) {
3043
2982
  break outer;
3044
2983
  }
3045
- const delegateResp = {
3046
- ...toolResp,
3047
- originalTask: this.#originalTask
3048
- };
3049
2984
  await this.#callback({
3050
2985
  kind: "ToolDelegate" /* ToolDelegate */,
3051
2986
  agent: this,
3052
2987
  tool: content.name,
3053
- agentName: delegateResp.agentName,
3054
- task: delegateResp.task,
3055
- context: delegateResp.context,
3056
- files: delegateResp.files,
3057
- originalTask: delegateResp.originalTask
2988
+ agentName: toolResp.agentName,
2989
+ task: toolResp.task,
2990
+ context: toolResp.context,
2991
+ files: toolResp.files
3058
2992
  });
3059
- return { type: "exit", reason: delegateResp };
2993
+ return { type: "exit", reason: toolResp };
3060
2994
  }
3061
2995
  case "Pause" /* Pause */: {
3062
2996
  await this.#callback({ kind: "ToolPause" /* ToolPause */, agent: this, tool: content.name, object: toolResp.object });
@@ -3660,6 +3594,7 @@ var coderAgentInfo = {
3660
3594
  var MultiAgent = class {
3661
3595
  #config;
3662
3596
  #agents = [];
3597
+ #originalTask;
3663
3598
  constructor(config) {
3664
3599
  this.#config = config;
3665
3600
  }
@@ -3672,7 +3607,7 @@ var MultiAgent = class {
3672
3607
  exitReason.task,
3673
3608
  exitReason.context,
3674
3609
  exitReason.files,
3675
- exitReason.originalTask
3610
+ this.#originalTask
3676
3611
  ) ?? exitReason.task;
3677
3612
  return await this.#startTask(exitReason.agentName, prompt6);
3678
3613
  }
@@ -3682,7 +3617,7 @@ var MultiAgent = class {
3682
3617
  exitReason.task,
3683
3618
  exitReason.context,
3684
3619
  exitReason.files,
3685
- exitReason.originalTask
3620
+ this.#originalTask
3686
3621
  ) ?? exitReason.task;
3687
3622
  const delegateResult = await this.#startTask(exitReason.agentName, prompt6);
3688
3623
  switch (delegateResult.type) {
@@ -3715,7 +3650,9 @@ var MultiAgent = class {
3715
3650
  if (this.#agents.length > 0) {
3716
3651
  throw new Error("An active agent already exists");
3717
3652
  }
3718
- return this.#startTask(options.agentName, options.task);
3653
+ this.#originalTask = options.task;
3654
+ return this.#startTask(options.agentName, `<task>${options.task}</task>
3655
+ <context>${options.context}</context>`);
3719
3656
  }
3720
3657
  async continueTask(userMessage) {
3721
3658
  if (!this.#agents.length) {
@@ -4363,8 +4300,8 @@ var executeAgentTool = async (definition, agent, params) => {
4363
4300
  }
4364
4301
  const exitReason = await agent.startTask({
4365
4302
  agentName: definition.agent,
4366
- task: `<task>${definition.prompt}</task>
4367
- <context>${definition.formatInput(params)}</context>`
4303
+ task: definition.prompt,
4304
+ context: definition.formatInput(params)
4368
4305
  });
4369
4306
  if (exitReason.type === "Exit" /* Exit */) {
4370
4307
  return definition.parseOutput(exitReason.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/core",
3
- "version": "0.8.17",
3
+ "version": "0.8.18",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",