@polka-codes/core 0.8.20 → 0.8.22
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 +497 -684
- package/dist/index.d.ts +0 -2
- package/dist/index.js +160 -231
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { replaceInFileHelper } from './_tsup-dts-rollup.js';
|
|
2
|
-
export { editFileHelper } from './_tsup-dts-rollup.js';
|
|
3
2
|
export { AiServiceProvider } from './_tsup-dts-rollup.js';
|
|
4
3
|
export { defaultModels } from './_tsup-dts-rollup.js';
|
|
5
4
|
export { createService } from './_tsup-dts-rollup.js';
|
|
@@ -62,7 +61,6 @@ export { ToolUse } from './_tsup-dts-rollup.js';
|
|
|
62
61
|
export { AssistantMessageContent } from './_tsup-dts-rollup.js';
|
|
63
62
|
export { KnowledgeManagementPolicy } from './_tsup-dts-rollup.js';
|
|
64
63
|
export { TruncateContextPolicy } from './_tsup-dts-rollup.js';
|
|
65
|
-
export { editFile } from './_tsup-dts-rollup.js';
|
|
66
64
|
export { allTools } from './_tsup-dts-rollup.js';
|
|
67
65
|
export { FilesystemProvider } from './_tsup-dts-rollup.js';
|
|
68
66
|
export { CommandProvider } from './_tsup-dts-rollup.js';
|
package/dist/index.js
CHANGED
|
@@ -914,40 +914,6 @@ var ToolResponseType = /* @__PURE__ */ ((ToolResponseType2) => {
|
|
|
914
914
|
return ToolResponseType2;
|
|
915
915
|
})(ToolResponseType || {});
|
|
916
916
|
|
|
917
|
-
// src/tools/utils/editFile.ts
|
|
918
|
-
var START_OF_FILE = "<<<START_OF_FILE>>>";
|
|
919
|
-
var END_OF_FILE = "<<<END_OF_FILE>>>";
|
|
920
|
-
var editFile = async (fileContent, operations) => {
|
|
921
|
-
if (!operations || operations.length === 0) {
|
|
922
|
-
throw new Error("At least one edit operation is required");
|
|
923
|
-
}
|
|
924
|
-
let updatedContent = fileContent;
|
|
925
|
-
for (const operation of operations) {
|
|
926
|
-
updatedContent = await applyEditOperation(updatedContent, operation);
|
|
927
|
-
}
|
|
928
|
-
return updatedContent;
|
|
929
|
-
};
|
|
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");
|
|
934
|
-
}
|
|
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");
|
|
937
|
-
}
|
|
938
|
-
if (search === START_OF_FILE) {
|
|
939
|
-
return replace + fileContent;
|
|
940
|
-
}
|
|
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}`);
|
|
947
|
-
}
|
|
948
|
-
return fileContent.slice(0, index) + replace + fileContent.slice(index + search.length);
|
|
949
|
-
}
|
|
950
|
-
|
|
951
917
|
// src/tools/utils/getArg.ts
|
|
952
918
|
var getString = (args, name, defaultValue) => {
|
|
953
919
|
if (typeof args !== "object" || Array.isArray(args)) {
|
|
@@ -1559,29 +1525,29 @@ var toolInfo7 = {
|
|
|
1559
1525
|
{
|
|
1560
1526
|
name: "diff",
|
|
1561
1527
|
description: `One or more SEARCH/REPLACE blocks following this exact format:
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1528
|
+
\`\`\`
|
|
1529
|
+
<<<<<<< SEARCH
|
|
1530
|
+
[exact content to find]
|
|
1531
|
+
=======
|
|
1532
|
+
[new content to replace with]
|
|
1533
|
+
>>>>>>> REPLACE
|
|
1534
|
+
\`\`\`
|
|
1535
|
+
Critical rules:
|
|
1536
|
+
1. SEARCH content must match the associated file section to find EXACTLY:
|
|
1537
|
+
* Match character-for-character including whitespace, indentation, line endings
|
|
1538
|
+
* Include all comments, docstrings, etc.
|
|
1539
|
+
2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
|
|
1540
|
+
* Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
|
|
1541
|
+
* Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
|
|
1542
|
+
* When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
|
|
1543
|
+
3. Keep SEARCH/REPLACE blocks concise:
|
|
1544
|
+
* Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
|
|
1545
|
+
* Include just the changing lines, and a few surrounding lines if needed for uniqueness.
|
|
1546
|
+
* Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
|
|
1547
|
+
* Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
|
|
1548
|
+
4. Special operations:
|
|
1549
|
+
* To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
|
|
1550
|
+
* To delete code: Use empty REPLACE section`,
|
|
1585
1551
|
required: true,
|
|
1586
1552
|
usageValue: "Search and replace blocks here"
|
|
1587
1553
|
}
|
|
@@ -1624,6 +1590,73 @@ function handleSubmit() {
|
|
|
1624
1590
|
return (
|
|
1625
1591
|
<div>
|
|
1626
1592
|
>>>>>>> REPLACE
|
|
1593
|
+
`
|
|
1594
|
+
}
|
|
1595
|
+
]
|
|
1596
|
+
},
|
|
1597
|
+
{
|
|
1598
|
+
description: "Request to perform a simple, single-line replacement",
|
|
1599
|
+
parameters: [
|
|
1600
|
+
{
|
|
1601
|
+
name: "path",
|
|
1602
|
+
value: "src/config.js"
|
|
1603
|
+
},
|
|
1604
|
+
{
|
|
1605
|
+
name: "diff",
|
|
1606
|
+
value: `
|
|
1607
|
+
<<<<<<< SEARCH
|
|
1608
|
+
const API_URL = 'https://api.example.com';
|
|
1609
|
+
=======
|
|
1610
|
+
const API_URL = 'https://api.staging.example.com';
|
|
1611
|
+
>>>>>>> REPLACE
|
|
1612
|
+
`
|
|
1613
|
+
}
|
|
1614
|
+
]
|
|
1615
|
+
},
|
|
1616
|
+
{
|
|
1617
|
+
description: "Request to add a new function to a file",
|
|
1618
|
+
parameters: [
|
|
1619
|
+
{
|
|
1620
|
+
name: "path",
|
|
1621
|
+
value: "src/utils.js"
|
|
1622
|
+
},
|
|
1623
|
+
{
|
|
1624
|
+
name: "diff",
|
|
1625
|
+
value: `
|
|
1626
|
+
<<<<<<< SEARCH
|
|
1627
|
+
function helperA() {
|
|
1628
|
+
// ...
|
|
1629
|
+
}
|
|
1630
|
+
=======
|
|
1631
|
+
function helperA() {
|
|
1632
|
+
// ...
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
function newHelper() {
|
|
1636
|
+
// implementation
|
|
1637
|
+
}
|
|
1638
|
+
>>>>>>> REPLACE
|
|
1639
|
+
`
|
|
1640
|
+
}
|
|
1641
|
+
]
|
|
1642
|
+
},
|
|
1643
|
+
{
|
|
1644
|
+
description: "Request to delete a block of code from a file",
|
|
1645
|
+
parameters: [
|
|
1646
|
+
{
|
|
1647
|
+
name: "path",
|
|
1648
|
+
value: "src/app.js"
|
|
1649
|
+
},
|
|
1650
|
+
{
|
|
1651
|
+
name: "diff",
|
|
1652
|
+
value: `
|
|
1653
|
+
<<<<<<< SEARCH
|
|
1654
|
+
function oldFeature() {
|
|
1655
|
+
// This is no longer needed
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
=======
|
|
1659
|
+
>>>>>>> REPLACE
|
|
1627
1660
|
`
|
|
1628
1661
|
}
|
|
1629
1662
|
]
|
|
@@ -1740,8 +1773,59 @@ var searchFiles_default = {
|
|
|
1740
1773
|
};
|
|
1741
1774
|
|
|
1742
1775
|
// src/tools/updateKnowledge.ts
|
|
1743
|
-
import { join } from "node:path";
|
|
1744
1776
|
import YAML from "yaml";
|
|
1777
|
+
|
|
1778
|
+
// src/path.ts
|
|
1779
|
+
function dirname(path) {
|
|
1780
|
+
if (path.length === 0) return ".";
|
|
1781
|
+
const isRooted = path[0] === "/";
|
|
1782
|
+
let end = path.length - 1;
|
|
1783
|
+
while (end > 0 && path[end] === "/") end--;
|
|
1784
|
+
const idx = path.lastIndexOf("/", end);
|
|
1785
|
+
if (idx < 0) {
|
|
1786
|
+
return isRooted ? "/" : ".";
|
|
1787
|
+
}
|
|
1788
|
+
if (isRooted && idx === 0) {
|
|
1789
|
+
return "/";
|
|
1790
|
+
}
|
|
1791
|
+
return path.slice(0, idx);
|
|
1792
|
+
}
|
|
1793
|
+
function normalize(path) {
|
|
1794
|
+
const isAbsolute = path.startsWith("/");
|
|
1795
|
+
const segments = path.split("/").filter(Boolean);
|
|
1796
|
+
const stack = [];
|
|
1797
|
+
for (const seg of segments) {
|
|
1798
|
+
if (seg === ".") continue;
|
|
1799
|
+
if (seg === "..") {
|
|
1800
|
+
if (stack.length && stack[stack.length - 1] !== "..") {
|
|
1801
|
+
stack.pop();
|
|
1802
|
+
} else if (!isAbsolute) {
|
|
1803
|
+
stack.push("..");
|
|
1804
|
+
}
|
|
1805
|
+
} else {
|
|
1806
|
+
stack.push(seg);
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
let result = stack.join("/");
|
|
1810
|
+
if (!result && !isAbsolute) return ".";
|
|
1811
|
+
if (result && path.endsWith("/")) result += "/";
|
|
1812
|
+
return (isAbsolute ? "/" : "") + result;
|
|
1813
|
+
}
|
|
1814
|
+
function join(...parts) {
|
|
1815
|
+
if (parts.length === 0) return ".";
|
|
1816
|
+
let combined = "";
|
|
1817
|
+
for (const p of parts) {
|
|
1818
|
+
if (typeof p !== "string") {
|
|
1819
|
+
throw new TypeError("Arguments to join must be strings");
|
|
1820
|
+
}
|
|
1821
|
+
if (p) {
|
|
1822
|
+
combined = combined ? `${combined}/${p}` : p;
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
return normalize(combined);
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
// src/tools/updateKnowledge.ts
|
|
1745
1829
|
var toolInfo9 = {
|
|
1746
1830
|
name: "update_knowledge",
|
|
1747
1831
|
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.",
|
|
@@ -2251,158 +2335,6 @@ var renameFile_default = {
|
|
|
2251
2335
|
isAvailable: isAvailable13
|
|
2252
2336
|
};
|
|
2253
2337
|
|
|
2254
|
-
// src/tools/editFile.ts
|
|
2255
|
-
var toolInfo14 = {
|
|
2256
|
-
name: "edit_file",
|
|
2257
|
-
description: "Request to edit file contents using search/replace operations. Supports multiple edit operations in a single call.",
|
|
2258
|
-
parameters: [
|
|
2259
|
-
{
|
|
2260
|
-
name: "path",
|
|
2261
|
-
description: "The path of the file to edit",
|
|
2262
|
-
required: true,
|
|
2263
|
-
usageValue: "File path here"
|
|
2264
|
-
},
|
|
2265
|
-
{
|
|
2266
|
-
name: "operations",
|
|
2267
|
-
description: "Edit operation with search and replace parameters",
|
|
2268
|
-
required: true,
|
|
2269
|
-
allowMultiple: true,
|
|
2270
|
-
children: [
|
|
2271
|
-
{
|
|
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)`,
|
|
2274
|
-
required: true,
|
|
2275
|
-
usageValue: "Text to find and replace"
|
|
2276
|
-
},
|
|
2277
|
-
{
|
|
2278
|
-
name: "replace",
|
|
2279
|
-
description: "Text to replace the search text with",
|
|
2280
|
-
required: true,
|
|
2281
|
-
usageValue: "Replacement text"
|
|
2282
|
-
}
|
|
2283
|
-
],
|
|
2284
|
-
usageValue: "operations here"
|
|
2285
|
-
}
|
|
2286
|
-
],
|
|
2287
|
-
examples: [
|
|
2288
|
-
{
|
|
2289
|
-
description: "Replace specific text",
|
|
2290
|
-
parameters: [
|
|
2291
|
-
{
|
|
2292
|
-
name: "path",
|
|
2293
|
-
value: "src/main.ts"
|
|
2294
|
-
},
|
|
2295
|
-
{
|
|
2296
|
-
name: "operations",
|
|
2297
|
-
value: {
|
|
2298
|
-
search: "function oldFunction() {\n return 42;\n}",
|
|
2299
|
-
replace: 'function newFunction() {\n return "new implementation";\n}'
|
|
2300
|
-
}
|
|
2301
|
-
}
|
|
2302
|
-
]
|
|
2303
|
-
},
|
|
2304
|
-
{
|
|
2305
|
-
description: "Insert at start of file",
|
|
2306
|
-
parameters: [
|
|
2307
|
-
{
|
|
2308
|
-
name: "path",
|
|
2309
|
-
value: "src/header.ts"
|
|
2310
|
-
},
|
|
2311
|
-
{
|
|
2312
|
-
name: "operations",
|
|
2313
|
-
value: {
|
|
2314
|
-
search: START_OF_FILE,
|
|
2315
|
-
replace: "// File header comment\n"
|
|
2316
|
-
}
|
|
2317
|
-
}
|
|
2318
|
-
]
|
|
2319
|
-
},
|
|
2320
|
-
{
|
|
2321
|
-
description: "Multiple operations in one call",
|
|
2322
|
-
parameters: [
|
|
2323
|
-
{
|
|
2324
|
-
name: "path",
|
|
2325
|
-
value: "src/utils.ts"
|
|
2326
|
-
},
|
|
2327
|
-
{
|
|
2328
|
-
name: "operations",
|
|
2329
|
-
value: [
|
|
2330
|
-
{
|
|
2331
|
-
search: 'import React from "react"',
|
|
2332
|
-
replace: 'import React, { useState } from "react"'
|
|
2333
|
-
},
|
|
2334
|
-
{
|
|
2335
|
-
search: "function Component() {\n return (",
|
|
2336
|
-
replace: "function Component() {\n const [state, setState] = useState(false);\n return ("
|
|
2337
|
-
}
|
|
2338
|
-
]
|
|
2339
|
-
}
|
|
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
|
-
]
|
|
2357
|
-
}
|
|
2358
|
-
],
|
|
2359
|
-
permissionLevel: 2 /* Write */
|
|
2360
|
-
};
|
|
2361
|
-
var handler14 = async (provider, args) => {
|
|
2362
|
-
if (!provider.readFile || !provider.writeFile) {
|
|
2363
|
-
return {
|
|
2364
|
-
type: "Error" /* Error */,
|
|
2365
|
-
message: "Not possible to edit file. Abort."
|
|
2366
|
-
};
|
|
2367
|
-
}
|
|
2368
|
-
const path = getString(args, "path");
|
|
2369
|
-
const operations = getArray(args, "operations");
|
|
2370
|
-
if (!operations || operations.length === 0) {
|
|
2371
|
-
return {
|
|
2372
|
-
type: "Error" /* Error */,
|
|
2373
|
-
message: `<error><edit_file_path>${path}</edit_file_path><error_message>At least one edit operation is required</error_message></error>`
|
|
2374
|
-
};
|
|
2375
|
-
}
|
|
2376
|
-
const fileContent = await provider.readFile(path);
|
|
2377
|
-
if (fileContent == null) {
|
|
2378
|
-
return {
|
|
2379
|
-
type: "Error" /* Error */,
|
|
2380
|
-
message: `<error><edit_file_path>${path}</edit_file_path><error_message>File not found</error_message></error>`
|
|
2381
|
-
};
|
|
2382
|
-
}
|
|
2383
|
-
try {
|
|
2384
|
-
const result = await editFile(fileContent, operations);
|
|
2385
|
-
await provider.writeFile(path, result);
|
|
2386
|
-
return {
|
|
2387
|
-
type: "Reply" /* Reply */,
|
|
2388
|
-
message: `<edit_file_path>${path}</edit_file_path>`
|
|
2389
|
-
};
|
|
2390
|
-
} catch (error) {
|
|
2391
|
-
return {
|
|
2392
|
-
type: "Error" /* Error */,
|
|
2393
|
-
message: `<error><edit_file_path>${path}</edit_file_path><error_message>${error instanceof Error ? error.message : String(error)}</error_message></error>`
|
|
2394
|
-
};
|
|
2395
|
-
}
|
|
2396
|
-
};
|
|
2397
|
-
var isAvailable14 = (provider) => {
|
|
2398
|
-
return !!provider.readFile && !!provider.writeFile;
|
|
2399
|
-
};
|
|
2400
|
-
var editFile_default = {
|
|
2401
|
-
...toolInfo14,
|
|
2402
|
-
handler: handler14,
|
|
2403
|
-
isAvailable: isAvailable14
|
|
2404
|
-
};
|
|
2405
|
-
|
|
2406
2338
|
// src/getAvailableTools.ts
|
|
2407
2339
|
var getAvailableTools = ({
|
|
2408
2340
|
provider,
|
|
@@ -2623,6 +2555,8 @@ Tool use is formatted using XML-style tags. The tool name is enclosed in opening
|
|
|
2623
2555
|
...
|
|
2624
2556
|
</${toolNamePrefix}tool_name>
|
|
2625
2557
|
|
|
2558
|
+
**It is crucial that all tags are correctly nested and closed.**
|
|
2559
|
+
|
|
2626
2560
|
## Array Parameters
|
|
2627
2561
|
|
|
2628
2562
|
To create an array of values for a parameter, repeat the parameter tag multiple times:
|
|
@@ -2657,7 +2591,7 @@ You can also combine array parameters with nested objects:
|
|
|
2657
2591
|
</${parameterPrefix}key>
|
|
2658
2592
|
</${toolNamePrefix}example_tool>
|
|
2659
2593
|
|
|
2660
|
-
Always adhere to this format
|
|
2594
|
+
Always adhere to this format, ensuring every opening tag has a matching closing tag, to ensure proper parsing and execution.
|
|
2661
2595
|
|
|
2662
2596
|
NEVER surround tool use with triple backticks (\`\`\`).
|
|
2663
2597
|
|
|
@@ -3009,8 +2943,8 @@ ${instance.prompt}`;
|
|
|
3009
2943
|
}
|
|
3010
2944
|
async #invokeTool(name, args) {
|
|
3011
2945
|
try {
|
|
3012
|
-
const
|
|
3013
|
-
if (!
|
|
2946
|
+
const handler14 = this.handlers[name]?.handler;
|
|
2947
|
+
if (!handler14) {
|
|
3014
2948
|
return {
|
|
3015
2949
|
type: "Error" /* Error */,
|
|
3016
2950
|
message: responsePrompts.errorInvokeTool(name, "Tool not found"),
|
|
@@ -3029,7 +2963,7 @@ ${instance.prompt}`;
|
|
|
3029
2963
|
if (resp) {
|
|
3030
2964
|
return resp;
|
|
3031
2965
|
}
|
|
3032
|
-
return await
|
|
2966
|
+
return await handler14(this.config.provider, args);
|
|
3033
2967
|
} catch (error) {
|
|
3034
2968
|
return {
|
|
3035
2969
|
type: "Error" /* Error */,
|
|
@@ -3387,7 +3321,7 @@ var editingFilesPrompt = (toolNamePrefix) => `
|
|
|
3387
3321
|
|
|
3388
3322
|
EDITING FILES
|
|
3389
3323
|
|
|
3390
|
-
You have two file-manipulation tools: **${toolNamePrefix}write_to_file** (full overwrite) and **${toolNamePrefix}
|
|
3324
|
+
You have two file-manipulation tools: **${toolNamePrefix}write_to_file** (full overwrite) and **${toolNamePrefix}replace_in_file** (targeted anchor-based edits). Choose the smallest safe operation for every change.
|
|
3391
3325
|
|
|
3392
3326
|
# ${toolNamePrefix}write_to_file
|
|
3393
3327
|
|
|
@@ -3399,16 +3333,16 @@ You have two file-manipulation tools: **${toolNamePrefix}write_to_file** (full o
|
|
|
3399
3333
|
|
|
3400
3334
|
- Initial file creation, such as when scaffolding a new project.
|
|
3401
3335
|
- Overwriting large boilerplate files where you want to replace the entire content at once.
|
|
3402
|
-
- When the complexity or number of changes would make ${toolNamePrefix}
|
|
3336
|
+
- When the complexity or number of changes would make ${toolNamePrefix}replace_in_file unwieldy or error-prone.
|
|
3403
3337
|
- When you need to completely restructure a file's content or change its fundamental organization.
|
|
3404
3338
|
|
|
3405
3339
|
## Important Considerations
|
|
3406
3340
|
|
|
3407
3341
|
- Using ${toolNamePrefix}write_to_file requires providing the file's complete final content.
|
|
3408
|
-
- If you only need to make small changes to an existing file, consider using ${toolNamePrefix}
|
|
3342
|
+
- If you only need to make small changes to an existing file, consider using ${toolNamePrefix}replace_in_file instead to avoid unnecessarily rewriting the entire file.
|
|
3409
3343
|
- While ${toolNamePrefix}write_to_file should not be your default choice, don't hesitate to use it when the situation truly calls for it.
|
|
3410
3344
|
|
|
3411
|
-
# ${toolNamePrefix}
|
|
3345
|
+
# ${toolNamePrefix}replace_in_file
|
|
3412
3346
|
|
|
3413
3347
|
## Purpose
|
|
3414
3348
|
|
|
@@ -3427,10 +3361,10 @@ You have two file-manipulation tools: **${toolNamePrefix}write_to_file** (full o
|
|
|
3427
3361
|
|
|
3428
3362
|
# Choosing the Appropriate Tool
|
|
3429
3363
|
|
|
3430
|
-
- **Default to ${toolNamePrefix}
|
|
3364
|
+
- **Default to ${toolNamePrefix}replace_in_file** for most changes. It keeps diffs small and reduces risk.
|
|
3431
3365
|
- **Use ${toolNamePrefix}write_to_file** when:
|
|
3432
3366
|
- Creating new files
|
|
3433
|
-
- The changes are so extensive that using ${toolNamePrefix}
|
|
3367
|
+
- The changes are so extensive that using ${toolNamePrefix}replace_in_file would be more complex or risky
|
|
3434
3368
|
- You need to completely reorganize or restructure a file
|
|
3435
3369
|
- The file is relatively small and the changes affect most of its content
|
|
3436
3370
|
- You're generating boilerplate or template files
|
|
@@ -3438,9 +3372,9 @@ You have two file-manipulation tools: **${toolNamePrefix}write_to_file** (full o
|
|
|
3438
3372
|
# Workflow Tips
|
|
3439
3373
|
|
|
3440
3374
|
1. Before editing, assess the scope of your changes and decide which tool to use.
|
|
3441
|
-
2. For targeted edits, apply ${toolNamePrefix}
|
|
3375
|
+
2. For targeted edits, apply ${toolNamePrefix}replace_in_file with carefully crafted before/after text anchors. If you need multiple changes, you can stack multiple operations within a single ${toolNamePrefix}replace_in_file call.
|
|
3442
3376
|
3. For major overhauls or initial file creation, rely on ${toolNamePrefix}write_to_file.
|
|
3443
|
-
4. Once the file has been edited with either ${toolNamePrefix}write_to_file or ${toolNamePrefix}
|
|
3377
|
+
4. Once the file has been edited with either ${toolNamePrefix}write_to_file or ${toolNamePrefix}replace_in_file, the system will provide you with the final state of the modified file. Use this updated content as the reference point for any subsequent operations, since it reflects any auto-formatting or user-applied changes.
|
|
3444
3378
|
|
|
3445
3379
|
Picking the right tool keeps edits minimal, safe, and easy to review.
|
|
3446
3380
|
`;
|
|
@@ -3454,10 +3388,10 @@ RULES
|
|
|
3454
3388
|
For text files (e.g. README.md), append a footer with the same notice.
|
|
3455
3389
|
- Never describe what changed inside code comments; comments must focus on purpose or usage only.
|
|
3456
3390
|
- Before using ${toolNamePrefix}execute_command, consider SYSTEM INFORMATION to ensure commands suit the user's OS. If a command must run in a subdirectory, prepend a single \`cd childDir &&\` segment.
|
|
3457
|
-
- Use ${toolNamePrefix}search_files for broad analysis, then ${toolNamePrefix}read_file to inspect context, and finally ${toolNamePrefix}
|
|
3458
|
-
- Prefer ${toolNamePrefix}
|
|
3391
|
+
- Use ${toolNamePrefix}search_files for broad analysis, then ${toolNamePrefix}read_file to inspect context, and finally ${toolNamePrefix}replace_in_file or ${toolNamePrefix}write_to_file to modify.
|
|
3392
|
+
- Prefer ${toolNamePrefix}replace_in_file for focused edits; choose ${toolNamePrefix}write_to_file for new files or complete rewrites.
|
|
3459
3393
|
- When creating a new file, look for existing files with similar content or patterns; if found, read them and use their structure or conventions as a reference.
|
|
3460
|
-
- Use before/after text anchors in ${toolNamePrefix}
|
|
3394
|
+
- Use before/after text anchors in ${toolNamePrefix}replace_in_file to target changes. If multiple operations are needed, list them in file order.
|
|
3461
3395
|
- Do not guess unseen content. Read existing files first unless creating new ones.
|
|
3462
3396
|
- Follow existing style, lint, and naming conventions. Ensure all changes compile and pass tests where applicable.
|
|
3463
3397
|
- ALWAYS wait for the user's confirmation after each tool call before starting the next step.
|
|
@@ -3662,9 +3596,6 @@ var MultiAgent = class {
|
|
|
3662
3596
|
}
|
|
3663
3597
|
};
|
|
3664
3598
|
|
|
3665
|
-
// src/Agent/policies/KnowledgeManagement.ts
|
|
3666
|
-
import { dirname, join as join2 } from "node:path";
|
|
3667
|
-
|
|
3668
3599
|
// src/config.ts
|
|
3669
3600
|
import { z } from "zod";
|
|
3670
3601
|
var providerModelSchema = z.object({
|
|
@@ -3828,7 +3759,7 @@ var KnowledgeManagementPolicy = (tools) => {
|
|
|
3828
3759
|
if (path === ".") {
|
|
3829
3760
|
continue;
|
|
3830
3761
|
}
|
|
3831
|
-
const fullpath =
|
|
3762
|
+
const fullpath = join(path, "knowledge.ai.yml");
|
|
3832
3763
|
if (!readFiles.has(fullpath)) {
|
|
3833
3764
|
allFullPaths.push(fullpath);
|
|
3834
3765
|
readFiles.add(fullpath);
|
|
@@ -4356,8 +4287,6 @@ export {
|
|
|
4356
4287
|
deepSeekModels,
|
|
4357
4288
|
defaultModels,
|
|
4358
4289
|
delegate_default as delegate,
|
|
4359
|
-
editFile_default as editFile,
|
|
4360
|
-
editFile as editFileHelper,
|
|
4361
4290
|
executeAgentTool,
|
|
4362
4291
|
executeCommand_default as executeCommand,
|
|
4363
4292
|
executeTool,
|