@polka-codes/core 0.8.17 → 0.8.19

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 CHANGED
@@ -882,13 +882,13 @@ __export(allTools_exports, {
882
882
  askFollowupQuestion: () => askFollowupQuestion_default,
883
883
  attemptCompletion: () => attemptCompletion_default,
884
884
  delegate: () => delegate_default,
885
- editFile: () => editFile_default,
886
885
  executeCommand: () => executeCommand_default,
887
886
  handOver: () => handOver_default,
888
887
  listFiles: () => listFiles_default,
889
888
  readFile: () => readFile_default,
890
889
  removeFile: () => removeFile_default,
891
890
  renameFile: () => renameFile_default,
891
+ replaceInFile: () => replaceInFile_default,
892
892
  searchFiles: () => searchFiles_default,
893
893
  updateKnowledge: () => updateKnowledge_default,
894
894
  writeToFile: () => writeToFile_default
@@ -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;
943
+ }
944
+ const index = fileContent.indexOf(search);
945
+ if (index === -1) {
946
+ throw new Error(`Could not find text: ${search}`);
993
947
  }
994
- return index;
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) => {
@@ -1592,8 +1545,126 @@ var readFile_default = {
1592
1545
  isAvailable: isAvailable6
1593
1546
  };
1594
1547
 
1595
- // src/tools/searchFiles.ts
1548
+ // src/tools/replaceInFile.ts
1596
1549
  var toolInfo7 = {
1550
+ name: "replace_in_file",
1551
+ 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.",
1552
+ parameters: [
1553
+ {
1554
+ name: "path",
1555
+ description: "The path of the file to modify",
1556
+ required: true,
1557
+ usageValue: "File path here"
1558
+ },
1559
+ {
1560
+ name: "diff",
1561
+ description: `One or more SEARCH/REPLACE blocks following this exact format:
1562
+ \`\`\`
1563
+ <<<<<<< SEARCH
1564
+ [exact content to find]
1565
+ =======
1566
+ [new content to replace with]
1567
+ >>>>>>> REPLACE
1568
+ \`\`\`
1569
+ Critical rules:
1570
+ 1. SEARCH content must match the associated file section to find EXACTLY:
1571
+ * Match character-for-character including whitespace, indentation, line endings
1572
+ * Include all comments, docstrings, etc.
1573
+ 2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
1574
+ * Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
1575
+ * Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
1576
+ * When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
1577
+ 3. Keep SEARCH/REPLACE blocks concise:
1578
+ * Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
1579
+ * Include just the changing lines, and a few surrounding lines if needed for uniqueness.
1580
+ * Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
1581
+ * Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
1582
+ 4. Special operations:
1583
+ * To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
1584
+ * To delete code: Use empty REPLACE section`,
1585
+ required: true,
1586
+ usageValue: "Search and replace blocks here"
1587
+ }
1588
+ ],
1589
+ examples: [
1590
+ {
1591
+ description: "Request to replace sections of content in a file",
1592
+ parameters: [
1593
+ {
1594
+ name: "path",
1595
+ value: "src/main.js"
1596
+ },
1597
+ {
1598
+ name: "diff",
1599
+ value: `
1600
+ <<<<<<< SEARCH
1601
+ import React from 'react';
1602
+ =======
1603
+ import React, { useState } from 'react';
1604
+ >>>>>>> REPLACE
1605
+
1606
+ <<<<<<< SEARCH
1607
+ function handleSubmit() {
1608
+ saveData();
1609
+ setLoading(false);
1610
+ }
1611
+
1612
+ =======
1613
+ >>>>>>> REPLACE
1614
+
1615
+ <<<<<<< SEARCH
1616
+ return (
1617
+ <div>
1618
+ =======
1619
+ function handleSubmit() {
1620
+ saveData();
1621
+ setLoading(false);
1622
+ }
1623
+
1624
+ return (
1625
+ <div>
1626
+ >>>>>>> REPLACE
1627
+ `
1628
+ }
1629
+ ]
1630
+ }
1631
+ ],
1632
+ permissionLevel: 2 /* Write */
1633
+ };
1634
+ var handler7 = async (provider, args) => {
1635
+ if (!provider.readFile || !provider.writeFile) {
1636
+ return {
1637
+ type: "Error" /* Error */,
1638
+ message: "Not possible to replace in file. Abort."
1639
+ };
1640
+ }
1641
+ const path = getString(args, "path");
1642
+ const diff = getString(args, "diff");
1643
+ const fileContent = await provider.readFile(path);
1644
+ if (fileContent == null) {
1645
+ return {
1646
+ type: "Error" /* Error */,
1647
+ message: `<error><replace_in_file_path>${path}</replace_in_file_path><error_message>File not found</error_message></error>`
1648
+ };
1649
+ }
1650
+ const result = await replaceInFile(fileContent, diff);
1651
+ await provider.writeFile(path, result);
1652
+ return {
1653
+ type: "Reply" /* Reply */,
1654
+ message: `<replace_in_file_path>${path}</replace_in_file_path>`
1655
+ };
1656
+ };
1657
+ var isAvailable7 = (provider) => {
1658
+ return !!provider.readFile && !!provider.writeFile;
1659
+ };
1660
+ var replaceInFile_default = {
1661
+ ...toolInfo7,
1662
+ handler: handler7,
1663
+ isAvailable: isAvailable7
1664
+ };
1665
+
1666
+ // src/tools/searchFiles.ts
1667
+ var toolInfo8 = {
1597
1668
  name: "search_files",
1598
1669
  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.",
1599
1670
  parameters: [
@@ -1637,7 +1708,7 @@ var toolInfo7 = {
1637
1708
  ],
1638
1709
  permissionLevel: 1 /* Read */
1639
1710
  };
1640
- var handler7 = async (provider, args) => {
1711
+ var handler8 = async (provider, args) => {
1641
1712
  if (!provider.searchFiles) {
1642
1713
  return {
1643
1714
  type: "Error" /* Error */,
@@ -1659,19 +1730,19 @@ ${files.join("\n")}
1659
1730
  `
1660
1731
  };
1661
1732
  };
1662
- var isAvailable7 = (provider) => {
1733
+ var isAvailable8 = (provider) => {
1663
1734
  return !!provider.searchFiles;
1664
1735
  };
1665
1736
  var searchFiles_default = {
1666
- ...toolInfo7,
1667
- handler: handler7,
1668
- isAvailable: isAvailable7
1737
+ ...toolInfo8,
1738
+ handler: handler8,
1739
+ isAvailable: isAvailable8
1669
1740
  };
1670
1741
 
1671
1742
  // src/tools/updateKnowledge.ts
1672
1743
  import { join } from "node:path";
1673
1744
  import YAML from "yaml";
1674
- var toolInfo8 = {
1745
+ var toolInfo9 = {
1675
1746
  name: "update_knowledge",
1676
1747
  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.",
1677
1748
  parameters: [
@@ -1845,7 +1916,7 @@ function deepMerge(target, source) {
1845
1916
  }
1846
1917
  return output;
1847
1918
  }
1848
- var handler8 = async (provider, args) => {
1919
+ var handler9 = async (provider, args) => {
1849
1920
  if (!provider.readFile || !provider.writeFile) {
1850
1921
  return {
1851
1922
  type: "Error" /* Error */,
@@ -1917,17 +1988,17 @@ var handler8 = async (provider, args) => {
1917
1988
  };
1918
1989
  }
1919
1990
  };
1920
- var isAvailable8 = (provider) => {
1991
+ var isAvailable9 = (provider) => {
1921
1992
  return !!provider.readFile && !!provider.writeFile;
1922
1993
  };
1923
1994
  var updateKnowledge_default = {
1924
- ...toolInfo8,
1925
- handler: handler8,
1926
- isAvailable: isAvailable8
1995
+ ...toolInfo9,
1996
+ handler: handler9,
1997
+ isAvailable: isAvailable9
1927
1998
  };
1928
1999
 
1929
2000
  // src/tools/writeToFile.ts
1930
- var toolInfo9 = {
2001
+ var toolInfo10 = {
1931
2002
  name: "write_to_file",
1932
2003
  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 `&lt;` and `&gt;`.",
1933
2004
  parameters: [
@@ -1972,7 +2043,7 @@ export default App;
1972
2043
  ],
1973
2044
  permissionLevel: 2 /* Write */
1974
2045
  };
1975
- var handler9 = async (provider, args) => {
2046
+ var handler10 = async (provider, args) => {
1976
2047
  if (!provider.writeFile) {
1977
2048
  return {
1978
2049
  type: "Error" /* Error */,
@@ -1987,17 +2058,17 @@ var handler9 = async (provider, args) => {
1987
2058
  message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
1988
2059
  };
1989
2060
  };
1990
- var isAvailable9 = (provider) => {
2061
+ var isAvailable10 = (provider) => {
1991
2062
  return !!provider.writeFile;
1992
2063
  };
1993
2064
  var writeToFile_default = {
1994
- ...toolInfo9,
1995
- handler: handler9,
1996
- isAvailable: isAvailable9
2065
+ ...toolInfo10,
2066
+ handler: handler10,
2067
+ isAvailable: isAvailable10
1997
2068
  };
1998
2069
 
1999
2070
  // src/tools/handOver.ts
2000
- var toolInfo10 = {
2071
+ var toolInfo11 = {
2001
2072
  name: "hand_over",
2002
2073
  description: "Hand over the current task to another agent to complete. This tool MUST NOT to be used with any other tool.",
2003
2074
  parameters: [
@@ -2051,7 +2122,7 @@ var toolInfo10 = {
2051
2122
  ],
2052
2123
  permissionLevel: 0 /* None */
2053
2124
  };
2054
- var handler10 = async (_provider, args) => {
2125
+ var handler11 = async (_provider, args) => {
2055
2126
  const agentName = getString(args, "agent_name");
2056
2127
  const task = getString(args, "task");
2057
2128
  const context = getString(args, "context", void 0);
@@ -2062,20 +2133,19 @@ var handler10 = async (_provider, args) => {
2062
2133
  task,
2063
2134
  context,
2064
2135
  files
2065
- // originalTask will be set by AgentBase
2066
2136
  };
2067
2137
  };
2068
- var isAvailable10 = (_provider) => {
2138
+ var isAvailable11 = (_provider) => {
2069
2139
  return true;
2070
2140
  };
2071
2141
  var handOver_default = {
2072
- ...toolInfo10,
2073
- handler: handler10,
2074
- isAvailable: isAvailable10
2142
+ ...toolInfo11,
2143
+ handler: handler11,
2144
+ isAvailable: isAvailable11
2075
2145
  };
2076
2146
 
2077
2147
  // src/tools/removeFile.ts
2078
- var toolInfo11 = {
2148
+ var toolInfo12 = {
2079
2149
  name: "remove_file",
2080
2150
  description: "Request to remove a file at the specified path.",
2081
2151
  parameters: [
@@ -2099,7 +2169,7 @@ var toolInfo11 = {
2099
2169
  ],
2100
2170
  permissionLevel: 2 /* Write */
2101
2171
  };
2102
- var handler11 = async (provider, args) => {
2172
+ var handler12 = async (provider, args) => {
2103
2173
  if (!provider.removeFile) {
2104
2174
  return {
2105
2175
  type: "Error" /* Error */,
@@ -2113,17 +2183,17 @@ var handler11 = async (provider, args) => {
2113
2183
  message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
2114
2184
  };
2115
2185
  };
2116
- var isAvailable11 = (provider) => {
2186
+ var isAvailable12 = (provider) => {
2117
2187
  return !!provider.removeFile;
2118
2188
  };
2119
2189
  var removeFile_default = {
2120
- ...toolInfo11,
2121
- handler: handler11,
2122
- isAvailable: isAvailable11
2190
+ ...toolInfo12,
2191
+ handler: handler12,
2192
+ isAvailable: isAvailable12
2123
2193
  };
2124
2194
 
2125
2195
  // src/tools/renameFile.ts
2126
- var toolInfo12 = {
2196
+ var toolInfo13 = {
2127
2197
  name: "rename_file",
2128
2198
  description: "Request to rename a file from source path to target path.",
2129
2199
  parameters: [
@@ -2157,7 +2227,7 @@ var toolInfo12 = {
2157
2227
  ],
2158
2228
  permissionLevel: 2 /* Write */
2159
2229
  };
2160
- var handler12 = async (provider, args) => {
2230
+ var handler13 = async (provider, args) => {
2161
2231
  if (!provider.renameFile) {
2162
2232
  return {
2163
2233
  type: "Error" /* Error */,
@@ -2172,19 +2242,19 @@ var handler12 = async (provider, args) => {
2172
2242
  message: `<rename_file_path>${targetPath}</rename_file_path><status>Success</status>`
2173
2243
  };
2174
2244
  };
2175
- var isAvailable12 = (provider) => {
2245
+ var isAvailable13 = (provider) => {
2176
2246
  return !!provider.renameFile;
2177
2247
  };
2178
2248
  var renameFile_default = {
2179
- ...toolInfo12,
2180
- handler: handler12,
2181
- isAvailable: isAvailable12
2249
+ ...toolInfo13,
2250
+ handler: handler13,
2251
+ isAvailable: isAvailable13
2182
2252
  };
2183
2253
 
2184
2254
  // src/tools/editFile.ts
2185
- var toolInfo13 = {
2255
+ var toolInfo14 = {
2186
2256
  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.",
2257
+ description: "Request to edit file contents using search/replace operations. Supports multiple edit operations in a single call.",
2188
2258
  parameters: [
2189
2259
  {
2190
2260
  name: "path",
@@ -2194,39 +2264,21 @@ var toolInfo13 = {
2194
2264
  },
2195
2265
  {
2196
2266
  name: "operations",
2197
- description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints",
2267
+ description: "Edit operation with search and replace parameters",
2198
2268
  required: true,
2199
2269
  allowMultiple: true,
2200
2270
  children: [
2201
2271
  {
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",
2272
+ name: "search",
2273
+ 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
2274
  required: true,
2217
- usageValue: "New text content"
2275
+ usageValue: "Text to find and replace"
2218
2276
  },
2219
2277
  {
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"
2278
+ name: "replace",
2279
+ description: "Text to replace the search text with",
2280
+ required: true,
2281
+ usageValue: "Replacement text"
2230
2282
  }
2231
2283
  ],
2232
2284
  usageValue: "operations here"
@@ -2234,7 +2286,7 @@ var toolInfo13 = {
2234
2286
  ],
2235
2287
  examples: [
2236
2288
  {
2237
- description: "Replace content between two text anchors",
2289
+ description: "Replace specific text",
2238
2290
  parameters: [
2239
2291
  {
2240
2292
  name: "path",
@@ -2243,9 +2295,8 @@ var toolInfo13 = {
2243
2295
  {
2244
2296
  name: "operations",
2245
2297
  value: {
2246
- start_anchor: "function oldFunction() {",
2247
- end_anchor: "}",
2248
- new_text: '\n return "new implementation";\n'
2298
+ search: "function oldFunction() {\n return 42;\n}",
2299
+ replace: 'function newFunction() {\n return "new implementation";\n}'
2249
2300
  }
2250
2301
  }
2251
2302
  ]
@@ -2260,9 +2311,8 @@ var toolInfo13 = {
2260
2311
  {
2261
2312
  name: "operations",
2262
2313
  value: {
2263
- start_anchor: START_OF_FILE,
2264
- end_anchor: "export",
2265
- new_text: "// File header comment\n"
2314
+ search: START_OF_FILE,
2315
+ replace: "// File header comment\n"
2266
2316
  }
2267
2317
  }
2268
2318
  ]
@@ -2278,23 +2328,37 @@ var toolInfo13 = {
2278
2328
  name: "operations",
2279
2329
  value: [
2280
2330
  {
2281
- start_anchor: "import React",
2282
- end_anchor: 'from "react"',
2283
- new_text: ", { useState }"
2331
+ search: 'import React from "react"',
2332
+ replace: 'import React, { useState } from "react"'
2284
2333
  },
2285
2334
  {
2286
- start_anchor: "function Component() {",
2287
- end_anchor: "return (",
2288
- new_text: "\n const [state, setState] = useState(false);\n "
2335
+ search: "function Component() {\n return (",
2336
+ replace: "function Component() {\n const [state, setState] = useState(false);\n return ("
2289
2337
  }
2290
2338
  ]
2291
2339
  }
2292
2340
  ]
2341
+ },
2342
+ {
2343
+ description: "Append content at end of file",
2344
+ parameters: [
2345
+ {
2346
+ name: "path",
2347
+ value: "src/footer.ts"
2348
+ },
2349
+ {
2350
+ name: "operations",
2351
+ value: {
2352
+ search: END_OF_FILE,
2353
+ replace: "\n// End of file appended comment\n"
2354
+ }
2355
+ }
2356
+ ]
2293
2357
  }
2294
2358
  ],
2295
2359
  permissionLevel: 2 /* Write */
2296
2360
  };
2297
- var handler13 = async (provider, args) => {
2361
+ var handler14 = async (provider, args) => {
2298
2362
  if (!provider.readFile || !provider.writeFile) {
2299
2363
  return {
2300
2364
  type: "Error" /* Error */,
@@ -2330,128 +2394,10 @@ var handler13 = async (provider, args) => {
2330
2394
  };
2331
2395
  }
2332
2396
  };
2333
- var isAvailable13 = (provider) => {
2334
- return !!provider.readFile && !!provider.writeFile;
2335
- };
2336
- var editFile_default = {
2337
- ...toolInfo13,
2338
- handler: handler13,
2339
- isAvailable: isAvailable13
2340
- };
2341
-
2342
- // src/tools/replaceInFile.ts
2343
- var toolInfo14 = {
2344
- name: "replace_in_file",
2345
- 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.",
2346
- parameters: [
2347
- {
2348
- name: "path",
2349
- description: "The path of the file to modify",
2350
- required: true,
2351
- usageValue: "File path here"
2352
- },
2353
- {
2354
- name: "diff",
2355
- description: `One or more SEARCH/REPLACE blocks following this exact format:
2356
- \`\`\`
2357
- <<<<<<< SEARCH
2358
- [exact content to find]
2359
- =======
2360
- [new content to replace with]
2361
- >>>>>>> REPLACE
2362
- \`\`\`
2363
- Critical rules:
2364
- 1. SEARCH content must match the associated file section to find EXACTLY:
2365
- * Match character-for-character including whitespace, indentation, line endings
2366
- * Include all comments, docstrings, etc.
2367
- 2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
2368
- * Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
2369
- * Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
2370
- * When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
2371
- 3. Keep SEARCH/REPLACE blocks concise:
2372
- * Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
2373
- * Include just the changing lines, and a few surrounding lines if needed for uniqueness.
2374
- * Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
2375
- * Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
2376
- 4. Special operations:
2377
- * To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
2378
- * To delete code: Use empty REPLACE section`,
2379
- required: true,
2380
- usageValue: "Search and replace blocks here"
2381
- }
2382
- ],
2383
- examples: [
2384
- {
2385
- description: "Request to replace sections of content in a file",
2386
- parameters: [
2387
- {
2388
- name: "path",
2389
- value: "src/main.js"
2390
- },
2391
- {
2392
- name: "diff",
2393
- value: `
2394
- <<<<<<< SEARCH
2395
- import React from 'react';
2396
- =======
2397
- import React, { useState } from 'react';
2398
- >>>>>>> REPLACE
2399
-
2400
- <<<<<<< SEARCH
2401
- function handleSubmit() {
2402
- saveData();
2403
- setLoading(false);
2404
- }
2405
-
2406
- =======
2407
- >>>>>>> REPLACE
2408
-
2409
- <<<<<<< SEARCH
2410
- return (
2411
- <div>
2412
- =======
2413
- function handleSubmit() {
2414
- saveData();
2415
- setLoading(false);
2416
- }
2417
-
2418
- return (
2419
- <div>
2420
- >>>>>>> REPLACE
2421
- `
2422
- }
2423
- ]
2424
- }
2425
- ],
2426
- permissionLevel: 2 /* Write */
2427
- };
2428
- var handler14 = async (provider, args) => {
2429
- if (!provider.readFile || !provider.writeFile) {
2430
- return {
2431
- type: "Error" /* Error */,
2432
- message: "Not possible to replace in file. Abort."
2433
- };
2434
- }
2435
- const path = getString(args, "path");
2436
- const diff = getString(args, "diff");
2437
- const fileContent = await provider.readFile(path);
2438
- if (fileContent == null) {
2439
- return {
2440
- type: "Error" /* Error */,
2441
- message: `<error><replace_in_file_path>${path}</replace_in_file_path><error_message>File not found</error_message></error>`
2442
- };
2443
- }
2444
- const result = await replaceInFile(fileContent, diff);
2445
- await provider.writeFile(path, result);
2446
- return {
2447
- type: "Reply" /* Reply */,
2448
- message: `<replace_in_file_path>${path}</replace_in_file_path>`
2449
- };
2450
- };
2451
2397
  var isAvailable14 = (provider) => {
2452
2398
  return !!provider.readFile && !!provider.writeFile;
2453
2399
  };
2454
- var replaceInFile_default = {
2400
+ var editFile_default = {
2455
2401
  ...toolInfo14,
2456
2402
  handler: handler14,
2457
2403
  isAvailable: isAvailable14
@@ -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);