@polka-codes/core 0.8.18 → 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.d.ts CHANGED
@@ -62,7 +62,7 @@ export { ToolUse } from './_tsup-dts-rollup.js';
62
62
  export { AssistantMessageContent } from './_tsup-dts-rollup.js';
63
63
  export { KnowledgeManagementPolicy } from './_tsup-dts-rollup.js';
64
64
  export { TruncateContextPolicy } from './_tsup-dts-rollup.js';
65
- export { replaceInFile } from './_tsup-dts-rollup.js';
65
+ export { editFile } from './_tsup-dts-rollup.js';
66
66
  export { allTools } from './_tsup-dts-rollup.js';
67
67
  export { FilesystemProvider } from './_tsup-dts-rollup.js';
68
68
  export { CommandProvider } from './_tsup-dts-rollup.js';
@@ -75,13 +75,13 @@ export { delegate } from './_tsup-dts-rollup.js';
75
75
  export { executeCommand } from './_tsup-dts-rollup.js';
76
76
  export { listFiles } from './_tsup-dts-rollup.js';
77
77
  export { readFile } from './_tsup-dts-rollup.js';
78
+ export { replaceInFile } from './_tsup-dts-rollup.js';
78
79
  export { searchFiles } from './_tsup-dts-rollup.js';
79
80
  export { updateKnowledge } from './_tsup-dts-rollup.js';
80
81
  export { writeToFile } from './_tsup-dts-rollup.js';
81
82
  export { handOver } from './_tsup-dts-rollup.js';
82
83
  export { removeFile } from './_tsup-dts-rollup.js';
83
84
  export { renameFile } from './_tsup-dts-rollup.js';
84
- export { editFile } from './_tsup-dts-rollup.js';
85
85
  export { AnthropicModelId } from './_tsup-dts-rollup.js';
86
86
  export { anthropicDefaultModelId } from './_tsup-dts-rollup.js';
87
87
  export { anthropicModels } from './_tsup-dts-rollup.js';
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
@@ -1545,8 +1545,126 @@ var readFile_default = {
1545
1545
  isAvailable: isAvailable6
1546
1546
  };
1547
1547
 
1548
- // src/tools/searchFiles.ts
1548
+ // src/tools/replaceInFile.ts
1549
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 = {
1550
1668
  name: "search_files",
1551
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.",
1552
1670
  parameters: [
@@ -1590,7 +1708,7 @@ var toolInfo7 = {
1590
1708
  ],
1591
1709
  permissionLevel: 1 /* Read */
1592
1710
  };
1593
- var handler7 = async (provider, args) => {
1711
+ var handler8 = async (provider, args) => {
1594
1712
  if (!provider.searchFiles) {
1595
1713
  return {
1596
1714
  type: "Error" /* Error */,
@@ -1612,19 +1730,19 @@ ${files.join("\n")}
1612
1730
  `
1613
1731
  };
1614
1732
  };
1615
- var isAvailable7 = (provider) => {
1733
+ var isAvailable8 = (provider) => {
1616
1734
  return !!provider.searchFiles;
1617
1735
  };
1618
1736
  var searchFiles_default = {
1619
- ...toolInfo7,
1620
- handler: handler7,
1621
- isAvailable: isAvailable7
1737
+ ...toolInfo8,
1738
+ handler: handler8,
1739
+ isAvailable: isAvailable8
1622
1740
  };
1623
1741
 
1624
1742
  // src/tools/updateKnowledge.ts
1625
1743
  import { join } from "node:path";
1626
1744
  import YAML from "yaml";
1627
- var toolInfo8 = {
1745
+ var toolInfo9 = {
1628
1746
  name: "update_knowledge",
1629
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.",
1630
1748
  parameters: [
@@ -1798,7 +1916,7 @@ function deepMerge(target, source) {
1798
1916
  }
1799
1917
  return output;
1800
1918
  }
1801
- var handler8 = async (provider, args) => {
1919
+ var handler9 = async (provider, args) => {
1802
1920
  if (!provider.readFile || !provider.writeFile) {
1803
1921
  return {
1804
1922
  type: "Error" /* Error */,
@@ -1870,17 +1988,17 @@ var handler8 = async (provider, args) => {
1870
1988
  };
1871
1989
  }
1872
1990
  };
1873
- var isAvailable8 = (provider) => {
1991
+ var isAvailable9 = (provider) => {
1874
1992
  return !!provider.readFile && !!provider.writeFile;
1875
1993
  };
1876
1994
  var updateKnowledge_default = {
1877
- ...toolInfo8,
1878
- handler: handler8,
1879
- isAvailable: isAvailable8
1995
+ ...toolInfo9,
1996
+ handler: handler9,
1997
+ isAvailable: isAvailable9
1880
1998
  };
1881
1999
 
1882
2000
  // src/tools/writeToFile.ts
1883
- var toolInfo9 = {
2001
+ var toolInfo10 = {
1884
2002
  name: "write_to_file",
1885
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;`.",
1886
2004
  parameters: [
@@ -1925,7 +2043,7 @@ export default App;
1925
2043
  ],
1926
2044
  permissionLevel: 2 /* Write */
1927
2045
  };
1928
- var handler9 = async (provider, args) => {
2046
+ var handler10 = async (provider, args) => {
1929
2047
  if (!provider.writeFile) {
1930
2048
  return {
1931
2049
  type: "Error" /* Error */,
@@ -1940,17 +2058,17 @@ var handler9 = async (provider, args) => {
1940
2058
  message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
1941
2059
  };
1942
2060
  };
1943
- var isAvailable9 = (provider) => {
2061
+ var isAvailable10 = (provider) => {
1944
2062
  return !!provider.writeFile;
1945
2063
  };
1946
2064
  var writeToFile_default = {
1947
- ...toolInfo9,
1948
- handler: handler9,
1949
- isAvailable: isAvailable9
2065
+ ...toolInfo10,
2066
+ handler: handler10,
2067
+ isAvailable: isAvailable10
1950
2068
  };
1951
2069
 
1952
2070
  // src/tools/handOver.ts
1953
- var toolInfo10 = {
2071
+ var toolInfo11 = {
1954
2072
  name: "hand_over",
1955
2073
  description: "Hand over the current task to another agent to complete. This tool MUST NOT to be used with any other tool.",
1956
2074
  parameters: [
@@ -2004,7 +2122,7 @@ var toolInfo10 = {
2004
2122
  ],
2005
2123
  permissionLevel: 0 /* None */
2006
2124
  };
2007
- var handler10 = async (_provider, args) => {
2125
+ var handler11 = async (_provider, args) => {
2008
2126
  const agentName = getString(args, "agent_name");
2009
2127
  const task = getString(args, "task");
2010
2128
  const context = getString(args, "context", void 0);
@@ -2017,17 +2135,17 @@ var handler10 = async (_provider, args) => {
2017
2135
  files
2018
2136
  };
2019
2137
  };
2020
- var isAvailable10 = (_provider) => {
2138
+ var isAvailable11 = (_provider) => {
2021
2139
  return true;
2022
2140
  };
2023
2141
  var handOver_default = {
2024
- ...toolInfo10,
2025
- handler: handler10,
2026
- isAvailable: isAvailable10
2142
+ ...toolInfo11,
2143
+ handler: handler11,
2144
+ isAvailable: isAvailable11
2027
2145
  };
2028
2146
 
2029
2147
  // src/tools/removeFile.ts
2030
- var toolInfo11 = {
2148
+ var toolInfo12 = {
2031
2149
  name: "remove_file",
2032
2150
  description: "Request to remove a file at the specified path.",
2033
2151
  parameters: [
@@ -2051,7 +2169,7 @@ var toolInfo11 = {
2051
2169
  ],
2052
2170
  permissionLevel: 2 /* Write */
2053
2171
  };
2054
- var handler11 = async (provider, args) => {
2172
+ var handler12 = async (provider, args) => {
2055
2173
  if (!provider.removeFile) {
2056
2174
  return {
2057
2175
  type: "Error" /* Error */,
@@ -2065,17 +2183,17 @@ var handler11 = async (provider, args) => {
2065
2183
  message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
2066
2184
  };
2067
2185
  };
2068
- var isAvailable11 = (provider) => {
2186
+ var isAvailable12 = (provider) => {
2069
2187
  return !!provider.removeFile;
2070
2188
  };
2071
2189
  var removeFile_default = {
2072
- ...toolInfo11,
2073
- handler: handler11,
2074
- isAvailable: isAvailable11
2190
+ ...toolInfo12,
2191
+ handler: handler12,
2192
+ isAvailable: isAvailable12
2075
2193
  };
2076
2194
 
2077
2195
  // src/tools/renameFile.ts
2078
- var toolInfo12 = {
2196
+ var toolInfo13 = {
2079
2197
  name: "rename_file",
2080
2198
  description: "Request to rename a file from source path to target path.",
2081
2199
  parameters: [
@@ -2109,7 +2227,7 @@ var toolInfo12 = {
2109
2227
  ],
2110
2228
  permissionLevel: 2 /* Write */
2111
2229
  };
2112
- var handler12 = async (provider, args) => {
2230
+ var handler13 = async (provider, args) => {
2113
2231
  if (!provider.renameFile) {
2114
2232
  return {
2115
2233
  type: "Error" /* Error */,
@@ -2124,17 +2242,17 @@ var handler12 = async (provider, args) => {
2124
2242
  message: `<rename_file_path>${targetPath}</rename_file_path><status>Success</status>`
2125
2243
  };
2126
2244
  };
2127
- var isAvailable12 = (provider) => {
2245
+ var isAvailable13 = (provider) => {
2128
2246
  return !!provider.renameFile;
2129
2247
  };
2130
2248
  var renameFile_default = {
2131
- ...toolInfo12,
2132
- handler: handler12,
2133
- isAvailable: isAvailable12
2249
+ ...toolInfo13,
2250
+ handler: handler13,
2251
+ isAvailable: isAvailable13
2134
2252
  };
2135
2253
 
2136
2254
  // src/tools/editFile.ts
2137
- var toolInfo13 = {
2255
+ var toolInfo14 = {
2138
2256
  name: "edit_file",
2139
2257
  description: "Request to edit file contents using search/replace operations. Supports multiple edit operations in a single call.",
2140
2258
  parameters: [
@@ -2240,7 +2358,7 @@ var toolInfo13 = {
2240
2358
  ],
2241
2359
  permissionLevel: 2 /* Write */
2242
2360
  };
2243
- var handler13 = async (provider, args) => {
2361
+ var handler14 = async (provider, args) => {
2244
2362
  if (!provider.readFile || !provider.writeFile) {
2245
2363
  return {
2246
2364
  type: "Error" /* Error */,
@@ -2276,128 +2394,10 @@ var handler13 = async (provider, args) => {
2276
2394
  };
2277
2395
  }
2278
2396
  };
2279
- var isAvailable13 = (provider) => {
2280
- return !!provider.readFile && !!provider.writeFile;
2281
- };
2282
- var editFile_default = {
2283
- ...toolInfo13,
2284
- handler: handler13,
2285
- isAvailable: isAvailable13
2286
- };
2287
-
2288
- // src/tools/replaceInFile.ts
2289
- var toolInfo14 = {
2290
- name: "replace_in_file",
2291
- 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.",
2292
- parameters: [
2293
- {
2294
- name: "path",
2295
- description: "The path of the file to modify",
2296
- required: true,
2297
- usageValue: "File path here"
2298
- },
2299
- {
2300
- name: "diff",
2301
- description: `One or more SEARCH/REPLACE blocks following this exact format:
2302
- \`\`\`
2303
- <<<<<<< SEARCH
2304
- [exact content to find]
2305
- =======
2306
- [new content to replace with]
2307
- >>>>>>> REPLACE
2308
- \`\`\`
2309
- Critical rules:
2310
- 1. SEARCH content must match the associated file section to find EXACTLY:
2311
- * Match character-for-character including whitespace, indentation, line endings
2312
- * Include all comments, docstrings, etc.
2313
- 2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
2314
- * Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
2315
- * Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
2316
- * When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
2317
- 3. Keep SEARCH/REPLACE blocks concise:
2318
- * Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
2319
- * Include just the changing lines, and a few surrounding lines if needed for uniqueness.
2320
- * Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
2321
- * Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
2322
- 4. Special operations:
2323
- * To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
2324
- * To delete code: Use empty REPLACE section`,
2325
- required: true,
2326
- usageValue: "Search and replace blocks here"
2327
- }
2328
- ],
2329
- examples: [
2330
- {
2331
- description: "Request to replace sections of content in a file",
2332
- parameters: [
2333
- {
2334
- name: "path",
2335
- value: "src/main.js"
2336
- },
2337
- {
2338
- name: "diff",
2339
- value: `
2340
- <<<<<<< SEARCH
2341
- import React from 'react';
2342
- =======
2343
- import React, { useState } from 'react';
2344
- >>>>>>> REPLACE
2345
-
2346
- <<<<<<< SEARCH
2347
- function handleSubmit() {
2348
- saveData();
2349
- setLoading(false);
2350
- }
2351
-
2352
- =======
2353
- >>>>>>> REPLACE
2354
-
2355
- <<<<<<< SEARCH
2356
- return (
2357
- <div>
2358
- =======
2359
- function handleSubmit() {
2360
- saveData();
2361
- setLoading(false);
2362
- }
2363
-
2364
- return (
2365
- <div>
2366
- >>>>>>> REPLACE
2367
- `
2368
- }
2369
- ]
2370
- }
2371
- ],
2372
- permissionLevel: 2 /* Write */
2373
- };
2374
- var handler14 = async (provider, args) => {
2375
- if (!provider.readFile || !provider.writeFile) {
2376
- return {
2377
- type: "Error" /* Error */,
2378
- message: "Not possible to replace in file. Abort."
2379
- };
2380
- }
2381
- const path = getString(args, "path");
2382
- const diff = getString(args, "diff");
2383
- const fileContent = await provider.readFile(path);
2384
- if (fileContent == null) {
2385
- return {
2386
- type: "Error" /* Error */,
2387
- message: `<error><replace_in_file_path>${path}</replace_in_file_path><error_message>File not found</error_message></error>`
2388
- };
2389
- }
2390
- const result = await replaceInFile(fileContent, diff);
2391
- await provider.writeFile(path, result);
2392
- return {
2393
- type: "Reply" /* Reply */,
2394
- message: `<replace_in_file_path>${path}</replace_in_file_path>`
2395
- };
2396
- };
2397
2397
  var isAvailable14 = (provider) => {
2398
2398
  return !!provider.readFile && !!provider.writeFile;
2399
2399
  };
2400
- var replaceInFile_default = {
2400
+ var editFile_default = {
2401
2401
  ...toolInfo14,
2402
2402
  handler: handler14,
2403
2403
  isAvailable: isAvailable14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/core",
3
- "version": "0.8.18",
3
+ "version": "0.8.19",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",