agentool 1.1.0 → 1.1.1
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/ask-user/index.cjs +5 -2
- package/dist/ask-user/index.d.cts +10 -1
- package/dist/ask-user/index.d.ts +10 -1
- package/dist/ask-user/index.js +5 -2
- package/dist/bash/index.cjs +5 -2
- package/dist/bash/index.d.cts +14 -1
- package/dist/bash/index.d.ts +14 -1
- package/dist/bash/index.js +5 -2
- package/dist/{chunk-IEX4NOVN.cjs → chunk-2JBLVFB7.cjs} +30 -4
- package/dist/{chunk-K77GC2QI.js → chunk-2JF3ZF2J.js} +32 -2
- package/dist/{chunk-UDIG7332.js → chunk-2WSZCOJP.js} +40 -4
- package/dist/chunk-3FT4ZPB2.cjs +65 -0
- package/dist/{chunk-VLNDEVKS.js → chunk-3LGXZLBH.js} +46 -8
- package/dist/{chunk-G3ITTPGX.js → chunk-4MXDQEPA.js} +12 -1
- package/dist/{chunk-CGTPF6IS.js → chunk-4UUSERSH.js} +31 -7
- package/dist/{chunk-I6KFFQPV.cjs → chunk-5T3SQYI4.cjs} +34 -4
- package/dist/chunk-6ULQG2W2.cjs +99 -0
- package/dist/chunk-ABXTBB2N.cjs +67 -0
- package/dist/{chunk-CAEVLIQB.cjs → chunk-BIAODQ2P.cjs} +17 -1
- package/dist/chunk-CJA76MKM.js +59 -0
- package/dist/chunk-CM3VRCNX.cjs +59 -0
- package/dist/{chunk-SUSAPI5W.cjs → chunk-CXBWF5ON.cjs} +51 -4
- package/dist/{chunk-5O55DKOB.cjs → chunk-G6ZVJA4V.cjs} +30 -4
- package/dist/{chunk-P6Z5XFDS.js → chunk-GPHCXS2S.js} +41 -15
- package/dist/chunk-HG5T47NA.cjs +77 -0
- package/dist/chunk-HO4NIRU5.js +65 -0
- package/dist/{chunk-HZAQRHBT.js → chunk-IBC4QCGR.js} +27 -2
- package/dist/chunk-JYTOARJV.cjs +69 -0
- package/dist/chunk-KONXT2SF.cjs +8 -0
- package/dist/chunk-KUFZFNPT.cjs +61 -0
- package/dist/chunk-L7R4UZSK.js +61 -0
- package/dist/{chunk-FV2R5FFQ.cjs → chunk-LNAR3NJQ.cjs} +47 -9
- package/dist/chunk-M74OQYNK.js +69 -0
- package/dist/{chunk-5TDZF4IM.cjs → chunk-NQIV6LBH.cjs} +42 -6
- package/dist/chunk-NTGDU5X3.js +67 -0
- package/dist/{chunk-ONBH74ZV.cjs → chunk-OYLTQJXT.cjs} +32 -8
- package/dist/{chunk-6PQLFDGT.js → chunk-PWBVB6MN.js} +17 -1
- package/dist/{chunk-HNP7JDQC.cjs → chunk-RIGL3JTS.cjs} +41 -5
- package/dist/chunk-SFDZRLSX.cjs +91 -0
- package/dist/{chunk-ZFQZWXOI.cjs → chunk-T6STO7PS.cjs} +58 -7
- package/dist/{chunk-LPV5CN2K.js → chunk-TI4ZZ3IJ.js} +32 -2
- package/dist/{chunk-S7IVHOA6.js → chunk-TM5L4HA5.js} +54 -3
- package/dist/{chunk-4YI2H55A.js → chunk-TXZ3BMMR.js} +49 -2
- package/dist/{chunk-IRRNYFI5.js → chunk-UCA6LURO.js} +28 -2
- package/dist/{chunk-EA3YV7ZG.js → chunk-VE4U27HI.js} +35 -15
- package/dist/{chunk-E6NBEYZD.js → chunk-VHLY7LQE.js} +7 -5
- package/dist/{chunk-FW3UJ622.cjs → chunk-VPRUYL4T.cjs} +34 -4
- package/dist/{chunk-3VO6NETR.cjs → chunk-VPV6WG5V.cjs} +41 -21
- package/dist/{chunk-L5JH4I77.cjs → chunk-VQSWMGG7.cjs} +8 -6
- package/dist/{chunk-4HIATLKI.js → chunk-VZRXTFS4.js} +28 -2
- package/dist/chunk-WCR62UZ3.js +67 -0
- package/dist/chunk-X6ZY2KFU.js +8 -0
- package/dist/chunk-XGDE7S2D.cjs +67 -0
- package/dist/chunk-XPTW45XY.js +77 -0
- package/dist/{chunk-YPPPGGLA.cjs → chunk-YCWJVQYO.cjs} +28 -3
- package/dist/chunk-YGXLT6SS.js +91 -0
- package/dist/{chunk-5NW4OGRI.cjs → chunk-YTPZHJDC.cjs} +12 -1
- package/dist/{chunk-XAQGZ374.js → chunk-ZHVRP3EH.js} +40 -4
- package/dist/context-compaction/index.cjs +5 -2
- package/dist/context-compaction/index.d.cts +11 -1
- package/dist/context-compaction/index.d.ts +11 -1
- package/dist/context-compaction/index.js +5 -2
- package/dist/diff/index.cjs +6 -2
- package/dist/diff/index.d.cts +12 -2
- package/dist/diff/index.d.ts +12 -2
- package/dist/diff/index.js +7 -3
- package/dist/edit/index.cjs +7 -3
- package/dist/edit/index.d.cts +13 -3
- package/dist/edit/index.d.ts +13 -3
- package/dist/edit/index.js +8 -4
- package/dist/glob/index.cjs +5 -2
- package/dist/glob/index.d.cts +13 -3
- package/dist/glob/index.d.ts +13 -3
- package/dist/glob/index.js +5 -2
- package/dist/grep/index.cjs +6 -2
- package/dist/grep/index.d.cts +13 -3
- package/dist/grep/index.d.ts +13 -3
- package/dist/grep/index.js +6 -2
- package/dist/http-request/index.cjs +5 -2
- package/dist/http-request/index.d.cts +11 -1
- package/dist/http-request/index.d.ts +11 -1
- package/dist/http-request/index.js +5 -2
- package/dist/index.cjs +68 -25
- package/dist/index.d.cts +21 -21
- package/dist/index.d.ts +21 -21
- package/dist/index.js +73 -30
- package/dist/lsp/index.cjs +6 -2
- package/dist/lsp/index.d.cts +10 -1
- package/dist/lsp/index.d.ts +10 -1
- package/dist/lsp/index.js +6 -2
- package/dist/memory/index.cjs +6 -2
- package/dist/memory/index.d.cts +10 -1
- package/dist/memory/index.d.ts +10 -1
- package/dist/memory/index.js +6 -2
- package/dist/multi-edit/index.cjs +7 -4
- package/dist/multi-edit/index.d.cts +12 -2
- package/dist/multi-edit/index.d.ts +12 -2
- package/dist/multi-edit/index.js +7 -4
- package/dist/read/index.cjs +6 -3
- package/dist/read/index.d.cts +11 -1
- package/dist/read/index.d.ts +11 -1
- package/dist/read/index.js +6 -3
- package/dist/sleep/index.cjs +5 -2
- package/dist/sleep/index.d.cts +11 -1
- package/dist/sleep/index.d.ts +11 -1
- package/dist/sleep/index.js +5 -2
- package/dist/task-create/index.cjs +7 -3
- package/dist/task-create/index.d.cts +10 -1
- package/dist/task-create/index.d.ts +10 -1
- package/dist/task-create/index.js +7 -3
- package/dist/task-get/index.cjs +7 -3
- package/dist/task-get/index.d.cts +10 -1
- package/dist/task-get/index.d.ts +10 -1
- package/dist/task-get/index.js +7 -3
- package/dist/task-list/index.cjs +7 -3
- package/dist/task-list/index.d.cts +10 -1
- package/dist/task-list/index.d.ts +10 -1
- package/dist/task-list/index.js +7 -3
- package/dist/task-update/index.cjs +7 -3
- package/dist/task-update/index.d.cts +12 -3
- package/dist/task-update/index.d.ts +12 -3
- package/dist/task-update/index.js +7 -3
- package/dist/tool-search/index.cjs +5 -2
- package/dist/tool-search/index.d.cts +10 -1
- package/dist/tool-search/index.d.ts +10 -1
- package/dist/tool-search/index.js +5 -2
- package/dist/web-fetch/index.cjs +5 -2
- package/dist/web-fetch/index.d.cts +11 -1
- package/dist/web-fetch/index.d.ts +11 -1
- package/dist/web-fetch/index.js +5 -2
- package/dist/web-search/index.cjs +5 -2
- package/dist/web-search/index.d.cts +10 -1
- package/dist/web-search/index.d.ts +10 -1
- package/dist/web-search/index.js +5 -2
- package/dist/write/index.cjs +6 -3
- package/dist/write/index.d.cts +13 -3
- package/dist/write/index.d.ts +13 -3
- package/dist/write/index.js +6 -3
- package/package.json +1 -1
- package/dist/chunk-3EPGFWZV.cjs +0 -30
- package/dist/chunk-44AFQ2B7.js +0 -30
- package/dist/chunk-4HXAKPQH.cjs +0 -36
- package/dist/chunk-56CL4JCW.cjs +0 -53
- package/dist/chunk-6DJSWTWQ.cjs +0 -40
- package/dist/chunk-ACGW44YT.js +0 -47
- package/dist/chunk-ECYT46FP.js +0 -40
- package/dist/chunk-HDKXSKMO.js +0 -30
- package/dist/chunk-HNUL2CID.cjs +0 -34
- package/dist/chunk-LK6SQH2G.cjs +0 -30
- package/dist/chunk-LTE5NG4D.js +0 -53
- package/dist/chunk-MF7CJVIZ.js +0 -40
- package/dist/chunk-OM2UFTGS.cjs +0 -47
- package/dist/chunk-OXLQ7QVL.cjs +0 -40
- package/dist/chunk-TMW3XKKJ.js +0 -34
- package/dist/chunk-VXZ4RKJI.js +0 -36
- package/dist/chunk-ZBLQV6UO.cjs +0 -73
|
@@ -1,9 +1,38 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
var _chunkKONXT2SFcjs = require('./chunk-KONXT2SF.cjs');
|
|
4
|
+
|
|
5
|
+
// src/http-request/index.ts
|
|
2
6
|
var _ai = require('ai');
|
|
3
7
|
var _zod = require('zod');
|
|
8
|
+
|
|
9
|
+
// src/http-request/prompt.ts
|
|
10
|
+
function getPrompt(config = {}) {
|
|
11
|
+
const timeout = _nullishCoalesce(config.timeout, () => ( 3e4));
|
|
12
|
+
return `Make an HTTP request to a URL. Returns the raw response status, headers, and body as JSON.
|
|
13
|
+
|
|
14
|
+
Supports GET, POST, PUT, PATCH, DELETE, and HEAD methods.
|
|
15
|
+
|
|
16
|
+
## When to Use
|
|
17
|
+
- For API interactions: REST calls, webhook triggers, service health checks
|
|
18
|
+
- When you need full control over HTTP method, headers, and request body
|
|
19
|
+
- When you need the raw response (status codes, headers) not just content
|
|
20
|
+
|
|
21
|
+
## When NOT to Use
|
|
22
|
+
- To read a web page for its content \u2014 use the web fetch tool instead (it converts HTML to markdown)
|
|
23
|
+
- To search the web \u2014 use the web search tool instead
|
|
24
|
+
|
|
25
|
+
## Usage Guidelines
|
|
26
|
+
- Default timeout: ${timeout}ms. Override with the timeout parameter.
|
|
27
|
+
- Request body is sent for POST, PUT, and PATCH methods
|
|
28
|
+
- Response is returned as JSON with status, statusText, headers, and body fields
|
|
29
|
+
- Default headers from config are merged with per-request headers (per-request takes precedence)`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/http-request/index.ts
|
|
4
33
|
function createHttpRequest(config = {}) {
|
|
5
34
|
return _ai.tool.call(void 0, {
|
|
6
|
-
description:
|
|
35
|
+
description: _nullishCoalesce(config.description, () => ( getPrompt(config))),
|
|
7
36
|
inputSchema: _zod.z.object({
|
|
8
37
|
method: _zod.z.enum(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"]).describe("HTTP method"),
|
|
9
38
|
url: _zod.z.string().describe("The URL to send the request to"),
|
|
@@ -44,7 +73,7 @@ function createHttpRequest(config = {}) {
|
|
|
44
73
|
if (error instanceof Error && error.name === "AbortError") {
|
|
45
74
|
return `Error [http-request]: Request timed out after ${effectiveTimeout}ms for ${method} ${url}. Try increasing the timeout or verify the server is responsive.`;
|
|
46
75
|
}
|
|
47
|
-
const msg =
|
|
76
|
+
const msg = _chunkKONXT2SFcjs.extractErrorMessage.call(void 0, error);
|
|
48
77
|
return `Error [http-request]: ${method} ${url} failed: ${msg}. Verify the URL is correct and the server is reachable.`;
|
|
49
78
|
}
|
|
50
79
|
}
|
|
@@ -55,4 +84,5 @@ var httpRequest = createHttpRequest();
|
|
|
55
84
|
|
|
56
85
|
|
|
57
86
|
|
|
58
|
-
|
|
87
|
+
|
|
88
|
+
exports.getPrompt = getPrompt; exports.createHttpRequest = createHttpRequest; exports.httpRequest = httpRequest;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkYTPZHJDCcjs = require('./chunk-YTPZHJDC.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkBIAODQ2Pcjs = require('./chunk-BIAODQ2P.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkQZ5GS6HWcjs = require('./chunk-QZ5GS6HW.cjs');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunkKONXT2SFcjs = require('./chunk-KONXT2SF.cjs');
|
|
17
|
+
|
|
18
|
+
// src/edit/index.ts
|
|
19
|
+
var _ai = require('ai');
|
|
20
|
+
var _zod = require('zod');
|
|
21
|
+
|
|
22
|
+
// src/edit/prompt.ts
|
|
23
|
+
function getPrompt() {
|
|
24
|
+
return `Perform an exact string replacement in a file. Locates old_string and replaces it with new_string.
|
|
25
|
+
|
|
26
|
+
Supports absolute paths, relative paths, and tilde (~) expansion. Includes curly-quote fallback matching and quote-style preservation.
|
|
27
|
+
|
|
28
|
+
## When to Use
|
|
29
|
+
- To make targeted changes to existing files
|
|
30
|
+
- To rename variables, update configuration values, or fix bugs
|
|
31
|
+
- Prefer this over the file writing tool for modifying existing files \u2014 it only changes what you specify
|
|
32
|
+
|
|
33
|
+
## When NOT to Use
|
|
34
|
+
- To create a new file from scratch \u2014 use the file writing tool instead
|
|
35
|
+
- To make many changes at once \u2014 consider the multi-edit tool for batch operations
|
|
36
|
+
|
|
37
|
+
## Usage Guidelines
|
|
38
|
+
- The edit will fail if \`old_string\` is not found in the file
|
|
39
|
+
- When \`replace_all\` is false (default), \`old_string\` must appear exactly once in the file. If it appears multiple times, provide more surrounding context to make it unique, or set \`replace_all: true\`
|
|
40
|
+
- Use \`replace_all: true\` for renaming a variable or string across the entire file
|
|
41
|
+
- Preserve exact indentation (tabs/spaces) from the original file in both old_string and new_string
|
|
42
|
+
- old_string and new_string must be different`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/edit/index.ts
|
|
46
|
+
function createEdit(config = {}) {
|
|
47
|
+
return _ai.tool.call(void 0, {
|
|
48
|
+
description: _nullishCoalesce(config.description, () => ( getPrompt())),
|
|
49
|
+
inputSchema: _zod.z.object({
|
|
50
|
+
file_path: _zod.z.string().describe("The absolute path to the file to modify"),
|
|
51
|
+
old_string: _zod.z.string().describe("The exact string to find and replace"),
|
|
52
|
+
new_string: _zod.z.string().describe("The replacement string"),
|
|
53
|
+
replace_all: _zod.z.boolean().default(false).optional().describe("Replace all occurrences (default: false)")
|
|
54
|
+
}),
|
|
55
|
+
execute: async ({ file_path, old_string, new_string, replace_all }) => {
|
|
56
|
+
try {
|
|
57
|
+
const resolved = _chunkQZ5GS6HWcjs.expandPath.call(void 0, file_path, config.cwd);
|
|
58
|
+
let content;
|
|
59
|
+
try {
|
|
60
|
+
content = await _chunkBIAODQ2Pcjs.readTextContent.call(void 0, resolved);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
const msg = _chunkKONXT2SFcjs.extractErrorMessage.call(void 0, err);
|
|
63
|
+
return `Error [edit]: Cannot read file "${resolved}": ${msg}`;
|
|
64
|
+
}
|
|
65
|
+
if (old_string === new_string) {
|
|
66
|
+
return "Error [edit]: old_string and new_string are identical \u2014 nothing to change.";
|
|
67
|
+
}
|
|
68
|
+
const actualOld = _chunkYTPZHJDCcjs.findActualString.call(void 0, content, old_string);
|
|
69
|
+
if (actualOld === null) {
|
|
70
|
+
const preview = content.slice(0, 200);
|
|
71
|
+
return `Error [edit]: old_string not found in "${resolved}". File starts with:
|
|
72
|
+
${preview}`;
|
|
73
|
+
}
|
|
74
|
+
if (!replace_all) {
|
|
75
|
+
const count = _chunkYTPZHJDCcjs.countOccurrences.call(void 0, content, actualOld);
|
|
76
|
+
if (count > 1) {
|
|
77
|
+
return `Error [edit]: old_string appears ${count} times in "${resolved}". Use replace_all to replace every occurrence, or provide a more specific string.`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const styledNew = _chunkYTPZHJDCcjs.preserveQuoteStyle.call(void 0, old_string, actualOld, new_string);
|
|
81
|
+
const updated = _chunkYTPZHJDCcjs.applyEditToFile.call(void 0, content, actualOld, styledNew, replace_all);
|
|
82
|
+
await _chunkBIAODQ2Pcjs.writeTextContent.call(void 0, resolved, updated);
|
|
83
|
+
const snippet = styledNew.length > 0 ? styledNew.slice(0, 200) : "(deletion)";
|
|
84
|
+
return `Successfully edited "${resolved}". Replacement snippet:
|
|
85
|
+
${snippet}`;
|
|
86
|
+
} catch (error) {
|
|
87
|
+
const msg = _chunkKONXT2SFcjs.extractErrorMessage.call(void 0, error);
|
|
88
|
+
return `Error [edit]: ${msg}`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
var edit = createEdit();
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
exports.getPrompt = getPrompt; exports.createEdit = createEdit; exports.edit = edit;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkBIAODQ2Pcjs = require('./chunk-BIAODQ2P.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkQZ5GS6HWcjs = require('./chunk-QZ5GS6HW.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkKONXT2SFcjs = require('./chunk-KONXT2SF.cjs');
|
|
11
|
+
|
|
12
|
+
// src/write/index.ts
|
|
13
|
+
var _ai = require('ai');
|
|
14
|
+
var _zod = require('zod');
|
|
15
|
+
|
|
16
|
+
// src/write/prompt.ts
|
|
17
|
+
function getPrompt() {
|
|
18
|
+
return `Write text content to a file, creating parent directories as needed. If the file already exists it is overwritten entirely.
|
|
19
|
+
|
|
20
|
+
Supports absolute paths, relative paths, and tilde (~) expansion.
|
|
21
|
+
|
|
22
|
+
## When to Use
|
|
23
|
+
- To create new files that don't exist yet
|
|
24
|
+
- To completely rewrite an existing file's content
|
|
25
|
+
- When the changes are so extensive that targeted editing would be impractical
|
|
26
|
+
|
|
27
|
+
## When NOT to Use
|
|
28
|
+
- To make small, targeted changes to an existing file \u2014 use the file editing tool instead (it only changes what you specify and is less error-prone)
|
|
29
|
+
- Prefer the editing tool for modifications; reserve this tool for creating new files or complete rewrites
|
|
30
|
+
|
|
31
|
+
## Usage Guidelines
|
|
32
|
+
- This tool overwrites the entire file \u2014 make sure you include all desired content, not just the changes
|
|
33
|
+
- Parent directories are created automatically if they don't exist
|
|
34
|
+
- Read the existing file first before overwriting it, so you don't accidentally lose content`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/write/index.ts
|
|
38
|
+
function createWrite(config = {}) {
|
|
39
|
+
const cwd = _nullishCoalesce(config.cwd, () => ( process.cwd()));
|
|
40
|
+
return _ai.tool.call(void 0, {
|
|
41
|
+
description: _nullishCoalesce(config.description, () => ( getPrompt())),
|
|
42
|
+
inputSchema: _zod.z.object({
|
|
43
|
+
file_path: _zod.z.string().describe("The absolute path to the file to write (must be absolute, not relative)"),
|
|
44
|
+
content: _zod.z.string().describe("Text content to write to the file")
|
|
45
|
+
}),
|
|
46
|
+
execute: async ({ file_path, content }) => {
|
|
47
|
+
try {
|
|
48
|
+
const absolutePath = _chunkQZ5GS6HWcjs.expandPath.call(void 0, file_path, cwd);
|
|
49
|
+
const existed = await _chunkBIAODQ2Pcjs.pathExists.call(void 0, absolutePath);
|
|
50
|
+
await _chunkBIAODQ2Pcjs.writeTextContent.call(void 0, absolutePath, content);
|
|
51
|
+
const bytes = Buffer.byteLength(content, "utf-8");
|
|
52
|
+
const verb = existed ? "Updated" : "Created";
|
|
53
|
+
return `${verb} file: ${absolutePath} (${bytes} bytes)`;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
const message = _chunkKONXT2SFcjs.extractErrorMessage.call(void 0, error);
|
|
56
|
+
return `Error [write]: Failed to write file: ${message}`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
var write = createWrite();
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
exports.getPrompt = getPrompt; exports.createWrite = createWrite; exports.write = write;
|
|
@@ -25,6 +25,18 @@ async function pathExists(path) {
|
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
async function readTextContent(filePath) {
|
|
29
|
+
return _promises.readFile.call(void 0, filePath, "utf-8");
|
|
30
|
+
}
|
|
31
|
+
async function listDirectory(dirPath) {
|
|
32
|
+
return _promises.readdir.call(void 0, dirPath);
|
|
33
|
+
}
|
|
34
|
+
async function removeFile(filePath) {
|
|
35
|
+
await _promises.unlink.call(void 0, filePath);
|
|
36
|
+
}
|
|
37
|
+
async function getFileStats(filePath) {
|
|
38
|
+
return _promises.stat.call(void 0, filePath);
|
|
39
|
+
}
|
|
28
40
|
async function readFileInRange(filePath, offset = 0, maxLines) {
|
|
29
41
|
const stats = await _promises.stat.call(void 0, filePath);
|
|
30
42
|
if (stats.isDirectory()) {
|
|
@@ -114,4 +126,8 @@ function readFileInRangeStreaming(filePath, offset, maxLines) {
|
|
|
114
126
|
|
|
115
127
|
|
|
116
128
|
|
|
117
|
-
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
exports.addLineNumbers = addLineNumbers; exports.writeTextContent = writeTextContent; exports.pathExists = pathExists; exports.readTextContent = readTextContent; exports.listDirectory = listDirectory; exports.removeFile = removeFile; exports.getFileStats = getFileStats; exports.readFileInRange = readFileInRange;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
extractErrorMessage
|
|
3
|
+
} from "./chunk-X6ZY2KFU.js";
|
|
4
|
+
|
|
5
|
+
// src/web-search/index.ts
|
|
6
|
+
import { tool } from "ai";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
|
|
9
|
+
// src/web-search/prompt.ts
|
|
10
|
+
function getPrompt() {
|
|
11
|
+
return `Search the web for information using a search query. Results can be filtered by allowed or blocked domains.
|
|
12
|
+
|
|
13
|
+
Requires an onSearch callback to be configured \u2014 the application provides the actual search implementation.
|
|
14
|
+
|
|
15
|
+
## When to Use
|
|
16
|
+
- To find current information beyond the model's training data
|
|
17
|
+
- To look up documentation, recent news, or real-time data
|
|
18
|
+
- To verify facts or find authoritative sources
|
|
19
|
+
|
|
20
|
+
## When NOT to Use
|
|
21
|
+
- To read a specific URL whose address you already know \u2014 use the web fetch tool instead
|
|
22
|
+
- To search file contents in the local codebase \u2014 use the dedicated content search tool instead
|
|
23
|
+
|
|
24
|
+
## Usage Guidelines
|
|
25
|
+
- After answering a question using search results, include a "Sources:" section listing the relevant URLs
|
|
26
|
+
- Use the current year when searching for recent information or documentation
|
|
27
|
+
- Use \`allowed_domains\` to restrict results to specific sites (e.g., ["docs.python.org"])
|
|
28
|
+
- Use \`blocked_domains\` to exclude specific sites from results`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/web-search/index.ts
|
|
32
|
+
function createWebSearch(config = {}) {
|
|
33
|
+
return tool({
|
|
34
|
+
description: config.description ?? getPrompt(),
|
|
35
|
+
inputSchema: z.object({
|
|
36
|
+
query: z.string().min(2).describe("The search query to use"),
|
|
37
|
+
allowed_domains: z.array(z.string()).optional().describe("Only include search results from these domains"),
|
|
38
|
+
blocked_domains: z.array(z.string()).optional().describe("Never include search results from these domains")
|
|
39
|
+
}),
|
|
40
|
+
execute: async ({ query, allowed_domains, blocked_domains }) => {
|
|
41
|
+
try {
|
|
42
|
+
if (!config.onSearch) {
|
|
43
|
+
return "Error [web-search]: No search callback configured. Provide onSearch via createWebSearch({ onSearch: async (query, opts) => ... })";
|
|
44
|
+
}
|
|
45
|
+
return await config.onSearch(query, { allowed_domains, blocked_domains });
|
|
46
|
+
} catch (error) {
|
|
47
|
+
const msg = extractErrorMessage(error);
|
|
48
|
+
return `Error [web-search]: ${msg}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
var webSearch = createWebSearch();
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
getPrompt,
|
|
57
|
+
createWebSearch,
|
|
58
|
+
webSearch
|
|
59
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
var _chunkKONXT2SFcjs = require('./chunk-KONXT2SF.cjs');
|
|
4
|
+
|
|
5
|
+
// src/web-search/index.ts
|
|
6
|
+
var _ai = require('ai');
|
|
7
|
+
var _zod = require('zod');
|
|
8
|
+
|
|
9
|
+
// src/web-search/prompt.ts
|
|
10
|
+
function getPrompt() {
|
|
11
|
+
return `Search the web for information using a search query. Results can be filtered by allowed or blocked domains.
|
|
12
|
+
|
|
13
|
+
Requires an onSearch callback to be configured \u2014 the application provides the actual search implementation.
|
|
14
|
+
|
|
15
|
+
## When to Use
|
|
16
|
+
- To find current information beyond the model's training data
|
|
17
|
+
- To look up documentation, recent news, or real-time data
|
|
18
|
+
- To verify facts or find authoritative sources
|
|
19
|
+
|
|
20
|
+
## When NOT to Use
|
|
21
|
+
- To read a specific URL whose address you already know \u2014 use the web fetch tool instead
|
|
22
|
+
- To search file contents in the local codebase \u2014 use the dedicated content search tool instead
|
|
23
|
+
|
|
24
|
+
## Usage Guidelines
|
|
25
|
+
- After answering a question using search results, include a "Sources:" section listing the relevant URLs
|
|
26
|
+
- Use the current year when searching for recent information or documentation
|
|
27
|
+
- Use \`allowed_domains\` to restrict results to specific sites (e.g., ["docs.python.org"])
|
|
28
|
+
- Use \`blocked_domains\` to exclude specific sites from results`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/web-search/index.ts
|
|
32
|
+
function createWebSearch(config = {}) {
|
|
33
|
+
return _ai.tool.call(void 0, {
|
|
34
|
+
description: _nullishCoalesce(config.description, () => ( getPrompt())),
|
|
35
|
+
inputSchema: _zod.z.object({
|
|
36
|
+
query: _zod.z.string().min(2).describe("The search query to use"),
|
|
37
|
+
allowed_domains: _zod.z.array(_zod.z.string()).optional().describe("Only include search results from these domains"),
|
|
38
|
+
blocked_domains: _zod.z.array(_zod.z.string()).optional().describe("Never include search results from these domains")
|
|
39
|
+
}),
|
|
40
|
+
execute: async ({ query, allowed_domains, blocked_domains }) => {
|
|
41
|
+
try {
|
|
42
|
+
if (!config.onSearch) {
|
|
43
|
+
return "Error [web-search]: No search callback configured. Provide onSearch via createWebSearch({ onSearch: async (query, opts) => ... })";
|
|
44
|
+
}
|
|
45
|
+
return await config.onSearch(query, { allowed_domains, blocked_domains });
|
|
46
|
+
} catch (error) {
|
|
47
|
+
const msg = _chunkKONXT2SFcjs.extractErrorMessage.call(void 0, error);
|
|
48
|
+
return `Error [web-search]: ${msg}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
var webSearch = createWebSearch();
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
exports.getPrompt = getPrompt; exports.createWebSearch = createWebSearch; exports.webSearch = webSearch;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkKONXT2SFcjs = require('./chunk-KONXT2SF.cjs');
|
|
4
|
+
|
|
5
|
+
// src/bash/index.ts
|
|
2
6
|
var _ai = require('ai');
|
|
3
7
|
var _zod = require('zod');
|
|
4
8
|
|
|
@@ -103,12 +107,54 @@ async function executeShell(command, options) {
|
|
|
103
107
|
});
|
|
104
108
|
}
|
|
105
109
|
|
|
110
|
+
// src/bash/prompt.ts
|
|
111
|
+
function getPrompt(config = {}) {
|
|
112
|
+
const timeout = _nullishCoalesce(config.timeout, () => ( 12e4));
|
|
113
|
+
const timeoutMin = timeout / 6e4;
|
|
114
|
+
const shell = _nullishCoalesce(config.shell, () => ( "$SHELL or /bin/bash"));
|
|
115
|
+
return `Execute a shell command and return its output (stdout, stderr, exit code).
|
|
116
|
+
|
|
117
|
+
Runs the command in ${shell} with \`-c\`. The working directory persists between calls.
|
|
118
|
+
|
|
119
|
+
## When to Use
|
|
120
|
+
- Build commands, git operations, system administration, installing packages
|
|
121
|
+
- Running scripts, compiling code, process management
|
|
122
|
+
- Any shell task that doesn't have a dedicated tool available
|
|
123
|
+
|
|
124
|
+
## When NOT to Use
|
|
125
|
+
- Reading file contents \u2014 use the dedicated file reading tool instead
|
|
126
|
+
- Searching file contents \u2014 use the dedicated content search tool instead
|
|
127
|
+
- Finding files by name/pattern \u2014 use the dedicated file search tool instead
|
|
128
|
+
- Editing files \u2014 use the dedicated file editing tool instead
|
|
129
|
+
- Writing new files \u2014 use the dedicated file writing tool instead
|
|
130
|
+
Prefer dedicated tools over shell equivalents (e.g., don't use cat, head, tail, sed, awk, grep, find, or echo when a dedicated tool exists). Dedicated tools provide better output formatting and permission handling.
|
|
131
|
+
|
|
132
|
+
## Usage Guidelines
|
|
133
|
+
- Default timeout: ${timeout}ms (${timeoutMin} minutes). Override with the timeout parameter.
|
|
134
|
+
- Timeout escalation: SIGTERM first, then SIGKILL after 5-second grace period.
|
|
135
|
+
- Output is capped at 10 MB per stream (stdout/stderr).
|
|
136
|
+
- Always quote file paths containing spaces with double quotes.
|
|
137
|
+
- When issuing multiple commands:
|
|
138
|
+
- Independent commands: make separate tool calls in parallel.
|
|
139
|
+
- Sequential with dependency: chain with \`&&\`.
|
|
140
|
+
- Sequential ignoring failures: chain with \`;\`.
|
|
141
|
+
- Do NOT use newlines to separate commands.
|
|
142
|
+
- Avoid unnecessary \`sleep\` commands:
|
|
143
|
+
- Don't sleep between commands that can run immediately.
|
|
144
|
+
- Don't retry failing commands in a sleep loop \u2014 diagnose the root cause.
|
|
145
|
+
- If you must sleep, keep it short (1-5 seconds).
|
|
146
|
+
- For git commands:
|
|
147
|
+
- Prefer creating new commits rather than amending existing ones.
|
|
148
|
+
- Never skip hooks (--no-verify) unless the user explicitly requests it.
|
|
149
|
+
- Before destructive operations (reset --hard, push --force), consider safer alternatives.`;
|
|
150
|
+
}
|
|
151
|
+
|
|
106
152
|
// src/bash/index.ts
|
|
107
153
|
function createBash(config = {}) {
|
|
108
154
|
const cwd = _nullishCoalesce(config.cwd, () => ( process.cwd()));
|
|
109
155
|
const timeout = _nullishCoalesce(config.timeout, () => ( 12e4));
|
|
110
156
|
return _ai.tool.call(void 0, {
|
|
111
|
-
description:
|
|
157
|
+
description: _nullishCoalesce(config.description, () => ( getPrompt(config))),
|
|
112
158
|
inputSchema: _zod.z.object({
|
|
113
159
|
command: _zod.z.string().describe("The shell command to execute"),
|
|
114
160
|
timeout: _zod.z.number().optional().describe("Timeout in milliseconds (default: 120000)"),
|
|
@@ -128,7 +174,7 @@ ${result.stderr}`);
|
|
|
128
174
|
if (result.exitCode !== 0) parts.push(`Exit code: ${result.exitCode}`);
|
|
129
175
|
return parts.length > 0 ? parts.join("\n") : `Command completed with exit code ${result.exitCode}`;
|
|
130
176
|
} catch (error) {
|
|
131
|
-
const msg =
|
|
177
|
+
const msg = _chunkKONXT2SFcjs.extractErrorMessage.call(void 0, error);
|
|
132
178
|
return `Error [bash]: Failed to execute command: ${msg}`;
|
|
133
179
|
}
|
|
134
180
|
}
|
|
@@ -139,4 +185,5 @@ var bash = createBash();
|
|
|
139
185
|
|
|
140
186
|
|
|
141
187
|
|
|
142
|
-
|
|
188
|
+
|
|
189
|
+
exports.getPrompt = getPrompt; exports.createBash = createBash; exports.bash = bash;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkKONXT2SFcjs = require('./chunk-KONXT2SF.cjs');
|
|
4
|
+
|
|
5
|
+
// src/web-fetch/index.ts
|
|
2
6
|
var _ai = require('ai');
|
|
3
7
|
var _zod = require('zod');
|
|
4
8
|
|
|
@@ -73,10 +77,31 @@ async function fetchUrl(url, options) {
|
|
|
73
77
|
};
|
|
74
78
|
}
|
|
75
79
|
|
|
80
|
+
// src/web-fetch/prompt.ts
|
|
81
|
+
function getPrompt(config = {}) {
|
|
82
|
+
const timeout = _nullishCoalesce(config.timeout, () => ( 3e4));
|
|
83
|
+
return `Fetch a URL and return its content. HTML pages are automatically converted to markdown for easier reading. JSON and other text content is returned as-is.
|
|
84
|
+
|
|
85
|
+
## When to Use
|
|
86
|
+
- To retrieve and read web page content, documentation, or articles
|
|
87
|
+
- To fetch API responses, JSON data, or raw text from URLs
|
|
88
|
+
- To check what a web page contains
|
|
89
|
+
|
|
90
|
+
## When NOT to Use
|
|
91
|
+
- For API interactions that need custom HTTP methods (POST, PUT, DELETE) \u2014 use the dedicated HTTP request tool instead
|
|
92
|
+
- For searching the web \u2014 use the dedicated web search tool instead
|
|
93
|
+
|
|
94
|
+
## Usage Guidelines
|
|
95
|
+
- Content is truncated at 100,000 characters to manage context size
|
|
96
|
+
- The URL must be a fully-formed valid URL (e.g., https://example.com)
|
|
97
|
+
- Timeout: ${timeout}ms
|
|
98
|
+
- This tool is read-only \u2014 it does not modify any files or state`;
|
|
99
|
+
}
|
|
100
|
+
|
|
76
101
|
// src/web-fetch/index.ts
|
|
77
102
|
function createWebFetch(config = {}) {
|
|
78
103
|
return _ai.tool.call(void 0, {
|
|
79
|
-
description:
|
|
104
|
+
description: _nullishCoalesce(config.description, () => ( getPrompt(config))),
|
|
80
105
|
inputSchema: _zod.z.object({
|
|
81
106
|
url: _zod.z.string().url().describe("The URL to fetch")
|
|
82
107
|
}),
|
|
@@ -98,7 +123,7 @@ function createWebFetch(config = {}) {
|
|
|
98
123
|
parts.push(result.content);
|
|
99
124
|
return parts.join("\n");
|
|
100
125
|
} catch (error) {
|
|
101
|
-
const msg =
|
|
126
|
+
const msg = _chunkKONXT2SFcjs.extractErrorMessage.call(void 0, error);
|
|
102
127
|
return `Error [web-fetch]: Failed to fetch ${url}: ${msg}`;
|
|
103
128
|
}
|
|
104
129
|
}
|
|
@@ -109,4 +134,5 @@ var webFetch = createWebFetch();
|
|
|
109
134
|
|
|
110
135
|
|
|
111
136
|
|
|
112
|
-
|
|
137
|
+
|
|
138
|
+
exports.getPrompt = getPrompt; exports.createWebFetch = createWebFetch; exports.webFetch = webFetch;
|
|
@@ -1,19 +1,51 @@
|
|
|
1
1
|
import {
|
|
2
2
|
applyEditToFile,
|
|
3
|
+
countOccurrences,
|
|
3
4
|
findActualString,
|
|
4
5
|
preserveQuoteStyle
|
|
5
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-4MXDQEPA.js";
|
|
7
|
+
import {
|
|
8
|
+
readTextContent,
|
|
9
|
+
writeTextContent
|
|
10
|
+
} from "./chunk-PWBVB6MN.js";
|
|
6
11
|
import {
|
|
7
12
|
expandPath
|
|
8
13
|
} from "./chunk-I3ONDY7P.js";
|
|
14
|
+
import {
|
|
15
|
+
extractErrorMessage
|
|
16
|
+
} from "./chunk-X6ZY2KFU.js";
|
|
9
17
|
|
|
10
18
|
// src/edit/index.ts
|
|
11
|
-
import { readFile, writeFile } from "fs/promises";
|
|
12
19
|
import { tool } from "ai";
|
|
13
20
|
import { z } from "zod";
|
|
21
|
+
|
|
22
|
+
// src/edit/prompt.ts
|
|
23
|
+
function getPrompt() {
|
|
24
|
+
return `Perform an exact string replacement in a file. Locates old_string and replaces it with new_string.
|
|
25
|
+
|
|
26
|
+
Supports absolute paths, relative paths, and tilde (~) expansion. Includes curly-quote fallback matching and quote-style preservation.
|
|
27
|
+
|
|
28
|
+
## When to Use
|
|
29
|
+
- To make targeted changes to existing files
|
|
30
|
+
- To rename variables, update configuration values, or fix bugs
|
|
31
|
+
- Prefer this over the file writing tool for modifying existing files \u2014 it only changes what you specify
|
|
32
|
+
|
|
33
|
+
## When NOT to Use
|
|
34
|
+
- To create a new file from scratch \u2014 use the file writing tool instead
|
|
35
|
+
- To make many changes at once \u2014 consider the multi-edit tool for batch operations
|
|
36
|
+
|
|
37
|
+
## Usage Guidelines
|
|
38
|
+
- The edit will fail if \`old_string\` is not found in the file
|
|
39
|
+
- When \`replace_all\` is false (default), \`old_string\` must appear exactly once in the file. If it appears multiple times, provide more surrounding context to make it unique, or set \`replace_all: true\`
|
|
40
|
+
- Use \`replace_all: true\` for renaming a variable or string across the entire file
|
|
41
|
+
- Preserve exact indentation (tabs/spaces) from the original file in both old_string and new_string
|
|
42
|
+
- old_string and new_string must be different`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/edit/index.ts
|
|
14
46
|
function createEdit(config = {}) {
|
|
15
47
|
return tool({
|
|
16
|
-
description:
|
|
48
|
+
description: config.description ?? getPrompt(),
|
|
17
49
|
inputSchema: z.object({
|
|
18
50
|
file_path: z.string().describe("The absolute path to the file to modify"),
|
|
19
51
|
old_string: z.string().describe("The exact string to find and replace"),
|
|
@@ -25,9 +57,9 @@ function createEdit(config = {}) {
|
|
|
25
57
|
const resolved = expandPath(file_path, config.cwd);
|
|
26
58
|
let content;
|
|
27
59
|
try {
|
|
28
|
-
content = await
|
|
60
|
+
content = await readTextContent(resolved);
|
|
29
61
|
} catch (err) {
|
|
30
|
-
const msg =
|
|
62
|
+
const msg = extractErrorMessage(err);
|
|
31
63
|
return `Error [edit]: Cannot read file "${resolved}": ${msg}`;
|
|
32
64
|
}
|
|
33
65
|
if (old_string === new_string) {
|
|
@@ -40,26 +72,19 @@ function createEdit(config = {}) {
|
|
|
40
72
|
${preview}`;
|
|
41
73
|
}
|
|
42
74
|
if (!replace_all) {
|
|
43
|
-
|
|
44
|
-
let pos = 0;
|
|
45
|
-
while (pos < content.length) {
|
|
46
|
-
const idx = content.indexOf(actualOld, pos);
|
|
47
|
-
if (idx === -1) break;
|
|
48
|
-
count++;
|
|
49
|
-
pos = idx + 1;
|
|
50
|
-
}
|
|
75
|
+
const count = countOccurrences(content, actualOld);
|
|
51
76
|
if (count > 1) {
|
|
52
77
|
return `Error [edit]: old_string appears ${count} times in "${resolved}". Use replace_all to replace every occurrence, or provide a more specific string.`;
|
|
53
78
|
}
|
|
54
79
|
}
|
|
55
80
|
const styledNew = preserveQuoteStyle(old_string, actualOld, new_string);
|
|
56
81
|
const updated = applyEditToFile(content, actualOld, styledNew, replace_all);
|
|
57
|
-
await
|
|
82
|
+
await writeTextContent(resolved, updated);
|
|
58
83
|
const snippet = styledNew.length > 0 ? styledNew.slice(0, 200) : "(deletion)";
|
|
59
84
|
return `Successfully edited "${resolved}". Replacement snippet:
|
|
60
85
|
${snippet}`;
|
|
61
86
|
} catch (error) {
|
|
62
|
-
const msg =
|
|
87
|
+
const msg = extractErrorMessage(error);
|
|
63
88
|
return `Error [edit]: ${msg}`;
|
|
64
89
|
}
|
|
65
90
|
}
|
|
@@ -68,6 +93,7 @@ ${snippet}`;
|
|
|
68
93
|
var edit = createEdit();
|
|
69
94
|
|
|
70
95
|
export {
|
|
96
|
+
getPrompt,
|
|
71
97
|
createEdit,
|
|
72
98
|
edit
|
|
73
99
|
};
|