@morphllm/morphsdk 0.2.145 → 0.2.146
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/{chunk-HBIW2XV2.js → chunk-4PBUB77N.js} +2 -2
- package/dist/{chunk-SUE4GYA2.js → chunk-BDHKL3MT.js} +2 -2
- package/dist/{chunk-S54SPKX3.js → chunk-BIQ7234U.js} +2 -2
- package/dist/{chunk-I3J46TSB.js → chunk-DKODF3YG.js} +4 -5
- package/dist/chunk-DKODF3YG.js.map +1 -0
- package/dist/{chunk-MRPASJBX.js → chunk-E45FW5EK.js} +2 -2
- package/dist/{chunk-BXRJYLRS.js → chunk-E4YKEKGW.js} +2 -2
- package/dist/{chunk-G23BI5CQ.js → chunk-EU7OLX4Z.js} +2 -2
- package/dist/chunk-EUHNJMWL.js +409 -0
- package/dist/chunk-EUHNJMWL.js.map +1 -0
- package/dist/{chunk-HE7K2QNQ.js → chunk-FBOJJ3UY.js} +17 -17
- package/dist/{chunk-HYRHI2UL.js → chunk-FIVYDIHX.js} +1 -1
- package/dist/{chunk-GXM3G7Z4.js → chunk-FYO46OT6.js} +2 -2
- package/dist/{chunk-GHPQYSSF.js → chunk-GJUB3ECP.js} +2 -2
- package/dist/{chunk-4Y2NM6JD.js → chunk-HZOTLGJH.js} +2 -42
- package/dist/chunk-HZOTLGJH.js.map +1 -0
- package/dist/{chunk-MTJ3PR4M.js → chunk-I7SFRYTX.js} +2 -2
- package/dist/{chunk-PX7ODEML.js → chunk-J2HIK4GB.js} +2 -2
- package/dist/{chunk-RZXS4ADX.js → chunk-JSWNBCGS.js} +2 -2
- package/dist/{chunk-GXCWKYGU.js → chunk-KYKRRF7E.js} +2 -2
- package/dist/{chunk-N7TTZIBK.js → chunk-MMBQKN4G.js} +2 -2
- package/dist/{chunk-B3AKP3RA.js → chunk-NF2QWJDY.js} +2 -31
- package/dist/chunk-NF2QWJDY.js.map +1 -0
- package/dist/{chunk-JMUAQQJU.js → chunk-NKUSUSVI.js} +3 -3
- package/dist/{chunk-VRV5UYTN.js → chunk-OV57JBMB.js} +2 -2
- package/dist/{chunk-EPIOAODF.js → chunk-Q36MNOFA.js} +2 -2
- package/dist/{chunk-JRBU4UNP.js → chunk-QRSWXP4K.js} +2 -2
- package/dist/{chunk-KELRCMA6.js → chunk-SJYAKVSS.js} +2 -2
- package/dist/{chunk-KELRCMA6.js.map → chunk-SJYAKVSS.js.map} +1 -1
- package/dist/{chunk-IRWHN55G.js → chunk-T564HFSH.js} +1 -1
- package/dist/{chunk-6CFKWZK3.js → chunk-UVNENJ6H.js} +3 -3
- package/dist/{chunk-5FCXLQJU.js → chunk-UYPWKQKV.js} +2 -2
- package/dist/{chunk-BAF33L6C.js → chunk-V73GO5AJ.js} +2 -2
- package/dist/chunk-VCKJ22DX.js +131 -0
- package/dist/chunk-VCKJ22DX.js.map +1 -0
- package/dist/{chunk-XL7R3XN5.js → chunk-VZ6VYRQB.js} +2 -2
- package/dist/{chunk-4LWMPKSB.js → chunk-YIETFYCL.js} +44 -71
- package/dist/chunk-YIETFYCL.js.map +1 -0
- package/dist/client.cjs +438 -426
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +27 -26
- package/dist/edge.cjs +1 -1
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.js +4 -4
- package/dist/{finish-Ddj1MPGt.d.ts → finish-DBKuo8yj.d.ts} +1 -1
- package/dist/index.cjs +438 -445
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -29
- package/dist/modelrouter/core.cjs +1 -1
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.js +3 -3
- package/dist/modelrouter/index.cjs +1 -1
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.js +3 -3
- package/dist/subagents/anthropic.cjs +434 -422
- package/dist/subagents/anthropic.cjs.map +1 -1
- package/dist/subagents/anthropic.js +9 -8
- package/dist/subagents/vercel.cjs +434 -422
- package/dist/subagents/vercel.cjs.map +1 -1
- package/dist/subagents/vercel.js +9 -8
- package/dist/tools/browser/anthropic.cjs +1 -1
- package/dist/tools/browser/anthropic.cjs.map +1 -1
- package/dist/tools/browser/anthropic.js +5 -5
- package/dist/tools/browser/core.cjs +1 -1
- package/dist/tools/browser/core.cjs.map +1 -1
- package/dist/tools/browser/core.js +4 -4
- package/dist/tools/browser/index.cjs +1 -1
- package/dist/tools/browser/index.cjs.map +1 -1
- package/dist/tools/browser/index.js +7 -7
- package/dist/tools/browser/openai.cjs +1 -1
- package/dist/tools/browser/openai.cjs.map +1 -1
- package/dist/tools/browser/openai.js +5 -5
- package/dist/tools/browser/profiles/core.cjs +1 -1
- package/dist/tools/browser/profiles/core.cjs.map +1 -1
- package/dist/tools/browser/profiles/core.js +3 -3
- package/dist/tools/browser/profiles/index.cjs +1 -1
- package/dist/tools/browser/profiles/index.cjs.map +1 -1
- package/dist/tools/browser/profiles/index.js +3 -3
- package/dist/tools/browser/vercel.cjs +1 -1
- package/dist/tools/browser/vercel.cjs.map +1 -1
- package/dist/tools/browser/vercel.js +5 -5
- package/dist/tools/codebase_search/anthropic.cjs +1 -1
- package/dist/tools/codebase_search/anthropic.cjs.map +1 -1
- package/dist/tools/codebase_search/anthropic.js +4 -4
- package/dist/tools/codebase_search/core.cjs +1 -1
- package/dist/tools/codebase_search/core.cjs.map +1 -1
- package/dist/tools/codebase_search/core.js +3 -3
- package/dist/tools/codebase_search/index.cjs +1 -1
- package/dist/tools/codebase_search/index.cjs.map +1 -1
- package/dist/tools/codebase_search/index.js +6 -6
- package/dist/tools/codebase_search/openai.cjs +1 -1
- package/dist/tools/codebase_search/openai.cjs.map +1 -1
- package/dist/tools/codebase_search/openai.js +4 -4
- package/dist/tools/codebase_search/vercel.cjs +1 -1
- package/dist/tools/codebase_search/vercel.cjs.map +1 -1
- package/dist/tools/codebase_search/vercel.js +4 -4
- package/dist/tools/fastapply/anthropic.cjs +1 -1
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +4 -4
- package/dist/tools/fastapply/apply.cjs +1 -1
- package/dist/tools/fastapply/apply.cjs.map +1 -1
- package/dist/tools/fastapply/apply.js +2 -2
- package/dist/tools/fastapply/core.cjs +1 -1
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.js +3 -3
- package/dist/tools/fastapply/index.cjs +1 -1
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.js +6 -6
- package/dist/tools/fastapply/openai.cjs +1 -1
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +4 -4
- package/dist/tools/fastapply/vercel.cjs +1 -1
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.js +4 -4
- package/dist/tools/index.cjs +1 -1
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +6 -6
- package/dist/tools/utils/resilience.cjs +1 -1
- package/dist/tools/utils/resilience.cjs.map +1 -1
- package/dist/tools/utils/resilience.js +2 -2
- package/dist/tools/warp_grep/agent/config.cjs +3 -4
- package/dist/tools/warp_grep/agent/config.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/config.d.ts +1 -2
- package/dist/tools/warp_grep/agent/config.js +1 -1
- package/dist/tools/warp_grep/agent/parser.cjs +121 -52
- package/dist/tools/warp_grep/agent/parser.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/parser.d.ts +5 -12
- package/dist/tools/warp_grep/agent/parser.js +3 -7
- package/dist/tools/warp_grep/agent/runner.cjs +416 -335
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.d.ts +3 -6
- package/dist/tools/warp_grep/agent/runner.js +6 -5
- package/dist/tools/warp_grep/agent/types.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/types.d.ts +3 -22
- package/dist/tools/warp_grep/anthropic.cjs +434 -422
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.js +9 -8
- package/dist/tools/warp_grep/client.cjs +434 -422
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.js +8 -7
- package/dist/tools/warp_grep/gemini.cjs +434 -422
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.js +8 -7
- package/dist/tools/warp_grep/gemini.js.map +1 -1
- package/dist/tools/warp_grep/harness.cjs +176 -164
- package/dist/tools/warp_grep/harness.cjs.map +1 -1
- package/dist/tools/warp_grep/harness.d.ts +38 -17
- package/dist/tools/warp_grep/harness.js +14 -15
- package/dist/tools/warp_grep/harness.js.map +1 -1
- package/dist/tools/warp_grep/index.cjs +434 -441
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.d.ts +1 -1
- package/dist/tools/warp_grep/index.js +10 -10
- package/dist/tools/warp_grep/openai.cjs +434 -422
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.js +9 -8
- package/dist/tools/warp_grep/providers/local.cjs +2 -43
- package/dist/tools/warp_grep/providers/local.cjs.map +1 -1
- package/dist/tools/warp_grep/providers/local.d.ts +1 -5
- package/dist/tools/warp_grep/providers/local.js +2 -2
- package/dist/tools/warp_grep/providers/remote.cjs +2 -32
- package/dist/tools/warp_grep/providers/remote.cjs.map +1 -1
- package/dist/tools/warp_grep/providers/remote.d.ts +1 -9
- package/dist/tools/warp_grep/providers/remote.js +2 -2
- package/dist/tools/warp_grep/providers/types.cjs.map +1 -1
- package/dist/tools/warp_grep/providers/types.d.ts +1 -14
- package/dist/tools/warp_grep/vercel.cjs +434 -422
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.js +9 -8
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-4LWMPKSB.js.map +0 -1
- package/dist/chunk-4Y2NM6JD.js.map +0 -1
- package/dist/chunk-B3AKP3RA.js.map +0 -1
- package/dist/chunk-CMSHXALI.js +0 -60
- package/dist/chunk-CMSHXALI.js.map +0 -1
- package/dist/chunk-I3J46TSB.js.map +0 -1
- package/dist/chunk-OPEQQGST.js +0 -396
- package/dist/chunk-OPEQQGST.js.map +0 -1
- /package/dist/{chunk-HBIW2XV2.js.map → chunk-4PBUB77N.js.map} +0 -0
- /package/dist/{chunk-SUE4GYA2.js.map → chunk-BDHKL3MT.js.map} +0 -0
- /package/dist/{chunk-S54SPKX3.js.map → chunk-BIQ7234U.js.map} +0 -0
- /package/dist/{chunk-MRPASJBX.js.map → chunk-E45FW5EK.js.map} +0 -0
- /package/dist/{chunk-BXRJYLRS.js.map → chunk-E4YKEKGW.js.map} +0 -0
- /package/dist/{chunk-G23BI5CQ.js.map → chunk-EU7OLX4Z.js.map} +0 -0
- /package/dist/{chunk-HE7K2QNQ.js.map → chunk-FBOJJ3UY.js.map} +0 -0
- /package/dist/{chunk-HYRHI2UL.js.map → chunk-FIVYDIHX.js.map} +0 -0
- /package/dist/{chunk-GXM3G7Z4.js.map → chunk-FYO46OT6.js.map} +0 -0
- /package/dist/{chunk-GHPQYSSF.js.map → chunk-GJUB3ECP.js.map} +0 -0
- /package/dist/{chunk-MTJ3PR4M.js.map → chunk-I7SFRYTX.js.map} +0 -0
- /package/dist/{chunk-PX7ODEML.js.map → chunk-J2HIK4GB.js.map} +0 -0
- /package/dist/{chunk-RZXS4ADX.js.map → chunk-JSWNBCGS.js.map} +0 -0
- /package/dist/{chunk-GXCWKYGU.js.map → chunk-KYKRRF7E.js.map} +0 -0
- /package/dist/{chunk-N7TTZIBK.js.map → chunk-MMBQKN4G.js.map} +0 -0
- /package/dist/{chunk-JMUAQQJU.js.map → chunk-NKUSUSVI.js.map} +0 -0
- /package/dist/{chunk-VRV5UYTN.js.map → chunk-OV57JBMB.js.map} +0 -0
- /package/dist/{chunk-EPIOAODF.js.map → chunk-Q36MNOFA.js.map} +0 -0
- /package/dist/{chunk-JRBU4UNP.js.map → chunk-QRSWXP4K.js.map} +0 -0
- /package/dist/{chunk-IRWHN55G.js.map → chunk-T564HFSH.js.map} +0 -0
- /package/dist/{chunk-6CFKWZK3.js.map → chunk-UVNENJ6H.js.map} +0 -0
- /package/dist/{chunk-5FCXLQJU.js.map → chunk-UYPWKQKV.js.map} +0 -0
- /package/dist/{chunk-BAF33L6C.js.map → chunk-V73GO5AJ.js.map} +0 -0
- /package/dist/{chunk-XL7R3XN5.js.map → chunk-VZ6VYRQB.js.map} +0 -0
|
@@ -41,12 +41,11 @@ var init_config = __esm({
|
|
|
41
41
|
return isNaN(parsed) || parsed <= 0 ? defaultMs : parsed;
|
|
42
42
|
};
|
|
43
43
|
AGENT_CONFIG = {
|
|
44
|
-
MAX_TURNS:
|
|
44
|
+
MAX_TURNS: 4,
|
|
45
45
|
/** Default timeout for model calls. Can be overridden via MORPH_WARP_GREP_TIMEOUT env var (in ms) */
|
|
46
46
|
TIMEOUT_MS: parseEnvTimeout(process.env.MORPH_WARP_GREP_TIMEOUT, 3e4),
|
|
47
|
-
MAX_CONTEXT_CHARS:
|
|
47
|
+
MAX_CONTEXT_CHARS: 54e4,
|
|
48
48
|
MAX_OUTPUT_LINES: 200,
|
|
49
|
-
MAX_LIST_RESULTS: 500,
|
|
50
49
|
MAX_READ_LINES: 800,
|
|
51
50
|
MAX_LIST_DEPTH: 3,
|
|
52
51
|
LIST_TIMEOUT_MS: 2e3
|
|
@@ -131,7 +130,7 @@ var init_config = __esm({
|
|
|
131
130
|
".*"
|
|
132
131
|
];
|
|
133
132
|
DEFAULT_EXCLUDES = (process.env.MORPH_WARP_GREP_EXCLUDE || "").split(",").map((s) => s.trim()).filter(Boolean).concat(BUILTIN_EXCLUDES);
|
|
134
|
-
DEFAULT_MODEL = "morph-warp-grep-v2
|
|
133
|
+
DEFAULT_MODEL = "morph-warp-grep-v2";
|
|
135
134
|
}
|
|
136
135
|
});
|
|
137
136
|
|
|
@@ -204,19 +203,19 @@ var init_ripgrep = __esm({
|
|
|
204
203
|
|
|
205
204
|
// tools/warp_grep/utils/paths.ts
|
|
206
205
|
function resolveUnderRepo(repoRoot, targetPath) {
|
|
207
|
-
const absRoot =
|
|
208
|
-
const resolved =
|
|
206
|
+
const absRoot = import_path3.default.resolve(repoRoot);
|
|
207
|
+
const resolved = import_path3.default.resolve(absRoot, targetPath);
|
|
209
208
|
ensureWithinRepo(absRoot, resolved);
|
|
210
209
|
return resolved;
|
|
211
210
|
}
|
|
212
211
|
function ensureWithinRepo(repoRoot, absTarget) {
|
|
213
|
-
const rel =
|
|
214
|
-
if (rel.startsWith("..") ||
|
|
212
|
+
const rel = import_path3.default.relative(import_path3.default.resolve(repoRoot), import_path3.default.resolve(absTarget));
|
|
213
|
+
if (rel.startsWith("..") || import_path3.default.isAbsolute(rel)) {
|
|
215
214
|
throw new Error(`Path outside repository root: ${absTarget}`);
|
|
216
215
|
}
|
|
217
216
|
}
|
|
218
217
|
function toRepoRelative(repoRoot, absPath) {
|
|
219
|
-
return
|
|
218
|
+
return import_path3.default.relative(import_path3.default.resolve(repoRoot), import_path3.default.resolve(absPath));
|
|
220
219
|
}
|
|
221
220
|
function isSymlink(p) {
|
|
222
221
|
try {
|
|
@@ -227,7 +226,7 @@ function isSymlink(p) {
|
|
|
227
226
|
}
|
|
228
227
|
}
|
|
229
228
|
function fixPathRepetition(fullPath) {
|
|
230
|
-
const segments = fullPath.split(
|
|
229
|
+
const segments = fullPath.split(import_path3.default.sep).filter(Boolean);
|
|
231
230
|
if (segments.length < 2) return null;
|
|
232
231
|
for (let len = Math.floor(segments.length / 2); len >= 1; len--) {
|
|
233
232
|
for (let i = 0; i <= segments.length - 2 * len; i++) {
|
|
@@ -235,7 +234,7 @@ function fixPathRepetition(fullPath) {
|
|
|
235
234
|
const second = segments.slice(i + len, i + 2 * len);
|
|
236
235
|
if (first.every((seg, idx) => seg === second[idx])) {
|
|
237
236
|
const fixed = [...segments.slice(0, i), ...segments.slice(i + len)];
|
|
238
|
-
return
|
|
237
|
+
return import_path3.default.sep + fixed.join(import_path3.default.sep);
|
|
239
238
|
}
|
|
240
239
|
}
|
|
241
240
|
}
|
|
@@ -259,12 +258,12 @@ function isTextualFile(filePath, maxBytes = 2e6) {
|
|
|
259
258
|
return false;
|
|
260
259
|
}
|
|
261
260
|
}
|
|
262
|
-
var import_fs,
|
|
261
|
+
var import_fs, import_path3;
|
|
263
262
|
var init_paths = __esm({
|
|
264
263
|
"tools/warp_grep/utils/paths.ts"() {
|
|
265
264
|
"use strict";
|
|
266
265
|
import_fs = __toESM(require("fs"), 1);
|
|
267
|
-
|
|
266
|
+
import_path3 = __toESM(require("path"), 1);
|
|
268
267
|
}
|
|
269
268
|
});
|
|
270
269
|
|
|
@@ -295,12 +294,12 @@ function shouldSkip2(name, allowNames) {
|
|
|
295
294
|
}
|
|
296
295
|
return false;
|
|
297
296
|
}
|
|
298
|
-
var import_promises2,
|
|
297
|
+
var import_promises2, import_path4, SKIP_NAMES2, SKIP_EXTENSIONS2, LocalRipgrepProvider;
|
|
299
298
|
var init_local = __esm({
|
|
300
299
|
"tools/warp_grep/providers/local.ts"() {
|
|
301
300
|
"use strict";
|
|
302
301
|
import_promises2 = __toESM(require("fs/promises"), 1);
|
|
303
|
-
|
|
302
|
+
import_path4 = __toESM(require("path"), 1);
|
|
304
303
|
init_ripgrep();
|
|
305
304
|
init_paths();
|
|
306
305
|
init_files();
|
|
@@ -402,7 +401,7 @@ var init_local = __esm({
|
|
|
402
401
|
}
|
|
403
402
|
const stat = await import_promises2.default.stat(abs).catch(() => null);
|
|
404
403
|
if (!stat) return { lines: [] };
|
|
405
|
-
const targetArg = abs ===
|
|
404
|
+
const targetArg = abs === import_path4.default.resolve(this.repoRoot) ? "." : toRepoRelative(this.repoRoot, abs);
|
|
406
405
|
const contextLines = params.context_lines !== void 0 ? String(params.context_lines) : "1";
|
|
407
406
|
const args = [
|
|
408
407
|
"--no-config",
|
|
@@ -557,7 +556,7 @@ Details: ${res.stderr}` : ""}`
|
|
|
557
556
|
if (timedOut || results.length >= maxResults) break;
|
|
558
557
|
if (shouldSkip2(entry.name, allowNames)) continue;
|
|
559
558
|
if (regex && !regex.test(entry.name)) continue;
|
|
560
|
-
const full =
|
|
559
|
+
const full = import_path4.default.join(dir, entry.name);
|
|
561
560
|
const isDir = entry.isDirectory();
|
|
562
561
|
results.push({
|
|
563
562
|
name: entry.name,
|
|
@@ -573,46 +572,6 @@ Details: ${res.stderr}` : ""}`
|
|
|
573
572
|
await walk(abs, 0);
|
|
574
573
|
return results;
|
|
575
574
|
}
|
|
576
|
-
async glob(params) {
|
|
577
|
-
let abs;
|
|
578
|
-
try {
|
|
579
|
-
abs = params.path ? resolveUnderRepo(this.repoRoot, params.path) : this.repoRoot;
|
|
580
|
-
} catch (err) {
|
|
581
|
-
return { files: [], searchDir: this.repoRoot, totalFound: 0, error: `[PATH ERROR] ${err instanceof Error ? err.message : String(err)}` };
|
|
582
|
-
}
|
|
583
|
-
const stat = await import_promises2.default.stat(abs).catch(() => null);
|
|
584
|
-
if (!stat || !stat.isDirectory()) {
|
|
585
|
-
return { files: [], searchDir: abs, totalFound: 0, error: `[PATH ERROR] Directory not found: ${params.path || "."}` };
|
|
586
|
-
}
|
|
587
|
-
const targetArg = abs === import_path5.default.resolve(this.repoRoot) ? "." : toRepoRelative(this.repoRoot, abs);
|
|
588
|
-
const args = [
|
|
589
|
-
"--no-config",
|
|
590
|
-
"--files",
|
|
591
|
-
"--color=never",
|
|
592
|
-
"-g",
|
|
593
|
-
params.pattern,
|
|
594
|
-
...this.excludes.filter((e) => !this.allowNames?.has(e)).flatMap((e) => ["-g", `!${e}`]),
|
|
595
|
-
targetArg || "."
|
|
596
|
-
];
|
|
597
|
-
const res = await runRipgrep(args, { cwd: this.repoRoot });
|
|
598
|
-
if (res.exitCode === -1) {
|
|
599
|
-
return { files: [], searchDir: abs, totalFound: 0, error: `[RIPGREP NOT AVAILABLE] ripgrep (rg) is required for glob search.` };
|
|
600
|
-
}
|
|
601
|
-
if (res.exitCode !== 0 && res.exitCode !== 1) {
|
|
602
|
-
return { files: [], searchDir: abs, totalFound: 0, error: `[GLOB ERROR] glob failed with exit code ${res.exitCode}${res.stderr ? `: ${res.stderr}` : ""}` };
|
|
603
|
-
}
|
|
604
|
-
const absRoot = import_path5.default.resolve(this.repoRoot);
|
|
605
|
-
const relFiles = (res.stdout || "").trim().split(/\r?\n/).filter((l) => l.length > 0);
|
|
606
|
-
const absFiles = relFiles.map((f) => import_path5.default.resolve(absRoot, f));
|
|
607
|
-
const withMtime = [];
|
|
608
|
-
for (const f of absFiles) {
|
|
609
|
-
const s = await import_promises2.default.stat(f).catch(() => null);
|
|
610
|
-
withMtime.push({ file: f, mtime: s?.mtimeMs ?? 0 });
|
|
611
|
-
}
|
|
612
|
-
withMtime.sort((a, b) => b.mtime - a.mtime);
|
|
613
|
-
const totalFound = withMtime.length;
|
|
614
|
-
return { files: withMtime.slice(0, 100).map((f) => f.file), searchDir: abs, totalFound };
|
|
615
|
-
}
|
|
616
575
|
};
|
|
617
576
|
}
|
|
618
577
|
});
|
|
@@ -628,58 +587,131 @@ module.exports = __toCommonJS(anthropic_exports);
|
|
|
628
587
|
init_config();
|
|
629
588
|
|
|
630
589
|
// tools/warp_grep/agent/parser.ts
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
const trimmed = rangeStr.trim();
|
|
635
|
-
if (!trimmed) continue;
|
|
636
|
-
const parts = trimmed.split("-").map((v) => parseInt(v.trim(), 10));
|
|
637
|
-
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
638
|
-
ranges.push([parts[0], parts[1]]);
|
|
639
|
-
} else if (Number.isFinite(parts[0])) {
|
|
640
|
-
ranges.push([parts[0], parts[0]]);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
if (ranges.length === 1) return { start: ranges[0][0], end: ranges[0][1] };
|
|
644
|
-
if (ranges.length > 1) return { lines: ranges };
|
|
645
|
-
return {};
|
|
590
|
+
var VALID_COMMANDS = ["list_directory", "ripgrep", "read", "finish"];
|
|
591
|
+
function isValidCommand(name) {
|
|
592
|
+
return VALID_COMMANDS.includes(name);
|
|
646
593
|
}
|
|
647
|
-
function
|
|
648
|
-
const
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
files.push({ path: filePath, lines: "*" });
|
|
661
|
-
continue;
|
|
594
|
+
function parseQwen3ToolCalls(text) {
|
|
595
|
+
const tools = [];
|
|
596
|
+
const toolCallRegex = /<tool_call>\s*<function=([a-z_][a-z0-9_]*)>([\s\S]*?)<\/function>\s*<\/tool_call>/gi;
|
|
597
|
+
let match;
|
|
598
|
+
while ((match = toolCallRegex.exec(text)) !== null) {
|
|
599
|
+
const funcName = match[1].toLowerCase();
|
|
600
|
+
const body = match[2];
|
|
601
|
+
if (!isValidCommand(funcName)) continue;
|
|
602
|
+
const params = {};
|
|
603
|
+
const paramRegex = /<parameter=([a-z_][a-z0-9_]*)>([\s\S]*?)<\/parameter>/gi;
|
|
604
|
+
let paramMatch;
|
|
605
|
+
while ((paramMatch = paramRegex.exec(body)) !== null) {
|
|
606
|
+
params[paramMatch[1].toLowerCase()] = paramMatch[2].trim();
|
|
662
607
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
608
|
+
if (funcName === "ripgrep") {
|
|
609
|
+
const pattern = params.pattern;
|
|
610
|
+
if (!pattern) continue;
|
|
611
|
+
const args = {
|
|
612
|
+
pattern,
|
|
613
|
+
path: params.path || ".",
|
|
614
|
+
...params.glob && { glob: params.glob },
|
|
615
|
+
...params.context_lines && { context_lines: parseInt(params.context_lines, 10) },
|
|
616
|
+
...params.case_sensitive && { case_sensitive: params.case_sensitive === "true" }
|
|
617
|
+
};
|
|
618
|
+
tools.push({ name: "grep", arguments: args });
|
|
619
|
+
} else if (funcName === "list_directory") {
|
|
620
|
+
const command = params.command;
|
|
621
|
+
const directPath = params.path;
|
|
622
|
+
let dirPath = directPath || ".";
|
|
623
|
+
if (!directPath && command) {
|
|
624
|
+
const tokens = command.trim().split(/\s+/);
|
|
625
|
+
const pathTokens = tokens.slice(1).filter((t) => !t.startsWith("-") && !t.startsWith("|") && !t.startsWith("\\("));
|
|
626
|
+
if (pathTokens.length > 0) {
|
|
627
|
+
dirPath = pathTokens[0];
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
tools.push({ name: "list_directory", arguments: { path: dirPath, pattern: params.pattern || null } });
|
|
631
|
+
} else if (funcName === "read") {
|
|
632
|
+
const filePath = params.path;
|
|
633
|
+
if (!filePath) continue;
|
|
634
|
+
const args = { path: filePath };
|
|
635
|
+
const linesStr = params.lines;
|
|
636
|
+
if (linesStr) {
|
|
637
|
+
const ranges = [];
|
|
638
|
+
for (const rangeStr of linesStr.split(",")) {
|
|
639
|
+
const trimmed = rangeStr.trim();
|
|
640
|
+
if (!trimmed) continue;
|
|
641
|
+
const [s, e] = trimmed.split("-").map((v) => parseInt(v.trim(), 10));
|
|
642
|
+
if (Number.isFinite(s) && Number.isFinite(e)) {
|
|
643
|
+
ranges.push([s, e]);
|
|
644
|
+
} else if (Number.isFinite(s)) {
|
|
645
|
+
ranges.push([s, s]);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if (ranges.length === 1) {
|
|
649
|
+
args.start = ranges[0][0];
|
|
650
|
+
args.end = ranges[0][1];
|
|
651
|
+
} else if (ranges.length > 1) {
|
|
652
|
+
args.lines = ranges;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
tools.push({ name: "read", arguments: args });
|
|
656
|
+
} else if (funcName === "finish") {
|
|
657
|
+
if (params.result && !params.files) {
|
|
658
|
+
tools.push({ name: "finish", arguments: { files: [], textResult: params.result } });
|
|
659
|
+
continue;
|
|
660
|
+
}
|
|
661
|
+
const filesStr = params.files;
|
|
662
|
+
if (!filesStr) {
|
|
663
|
+
tools.push({ name: "finish", arguments: { files: [], textResult: "No relevant code found." } });
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
const files = [];
|
|
667
|
+
for (const line of filesStr.split("\n")) {
|
|
668
|
+
const trimmed = line.trim();
|
|
669
|
+
if (!trimmed) continue;
|
|
670
|
+
const colonIdx = trimmed.indexOf(":");
|
|
671
|
+
if (colonIdx === -1) {
|
|
672
|
+
files.push({ path: trimmed, lines: "*" });
|
|
673
|
+
} else {
|
|
674
|
+
const filePath = trimmed.slice(0, colonIdx);
|
|
675
|
+
const rangesPart = trimmed.slice(colonIdx + 1);
|
|
676
|
+
const ranges = [];
|
|
677
|
+
for (const rangeStr of rangesPart.split(",")) {
|
|
678
|
+
const rt = rangeStr.trim();
|
|
679
|
+
if (!rt || rt === "*") {
|
|
680
|
+
files.push({ path: filePath, lines: "*" });
|
|
681
|
+
break;
|
|
682
|
+
}
|
|
683
|
+
const [s, e] = rt.split("-").map((v) => parseInt(v.trim(), 10));
|
|
684
|
+
if (Number.isFinite(s) && Number.isFinite(e)) {
|
|
685
|
+
ranges.push([s, e]);
|
|
686
|
+
} else if (Number.isFinite(s)) {
|
|
687
|
+
ranges.push([s, s]);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
if (ranges.length > 0) {
|
|
691
|
+
files.push({ path: filePath, lines: ranges });
|
|
692
|
+
} else if (!files.some((f) => f.path === filePath)) {
|
|
693
|
+
files.push({ path: filePath, lines: "*" });
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
if (files.length > 0) {
|
|
698
|
+
tools.push({ name: "finish", arguments: { files } });
|
|
699
|
+
} else {
|
|
700
|
+
tools.push({ name: "finish", arguments: { files: [], textResult: filesStr } });
|
|
672
701
|
}
|
|
673
702
|
}
|
|
674
|
-
files.push({ path: filePath, lines: ranges.length > 0 ? ranges : "*" });
|
|
675
703
|
}
|
|
676
|
-
return
|
|
677
|
-
}
|
|
678
|
-
function extractPathFromCommand(command) {
|
|
679
|
-
const tokens = command.trim().split(/\s+/);
|
|
680
|
-
const pathTokens = tokens.slice(1).filter((t) => !t.startsWith("-") && !t.startsWith("|") && !t.startsWith("\\("));
|
|
681
|
-
return pathTokens[0] || ".";
|
|
704
|
+
return tools;
|
|
682
705
|
}
|
|
706
|
+
var LLMResponseParser = class {
|
|
707
|
+
parse(text) {
|
|
708
|
+
if (typeof text !== "string") {
|
|
709
|
+
throw new TypeError("Command text must be a string.");
|
|
710
|
+
}
|
|
711
|
+
const withoutThink = text.replace(/<think>[\s\S]*?<\/think>/gi, "");
|
|
712
|
+
return parseQwen3ToolCalls(withoutThink);
|
|
713
|
+
}
|
|
714
|
+
};
|
|
683
715
|
|
|
684
716
|
// tools/warp_grep/agent/tools/grep.ts
|
|
685
717
|
async function toolGrep(provider, args) {
|
|
@@ -730,42 +762,29 @@ async function toolRead(provider, args) {
|
|
|
730
762
|
|
|
731
763
|
// tools/warp_grep/agent/tools/list_directory.ts
|
|
732
764
|
init_config();
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
const
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
return res.error;
|
|
757
|
-
}
|
|
758
|
-
if (!res.files.length) {
|
|
759
|
-
return "no matches";
|
|
760
|
-
}
|
|
761
|
-
const header = `Found ${res.totalFound} file(s) matching "${args.pattern}" within ${res.searchDir}, sorted by modification time (newest first):`;
|
|
762
|
-
const body = res.files.join("\n");
|
|
763
|
-
const truncated = res.totalFound > res.files.length ? `
|
|
764
|
-
[${res.totalFound - res.files.length} files truncated]` : "";
|
|
765
|
-
return `${header}
|
|
766
|
-
---
|
|
767
|
-
${body}
|
|
768
|
-
---${truncated}`;
|
|
765
|
+
async function toolListDirectory(provider, args) {
|
|
766
|
+
const maxResults = args.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES;
|
|
767
|
+
const initialDepth = args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
768
|
+
async function getListRecursive(currentDepth) {
|
|
769
|
+
const entries = await provider.listDirectory({
|
|
770
|
+
path: args.path,
|
|
771
|
+
pattern: args.pattern ?? null,
|
|
772
|
+
maxResults,
|
|
773
|
+
maxDepth: currentDepth
|
|
774
|
+
});
|
|
775
|
+
if (entries.length >= maxResults && currentDepth > 0) {
|
|
776
|
+
return getListRecursive(currentDepth - 1);
|
|
777
|
+
}
|
|
778
|
+
return { entries };
|
|
779
|
+
}
|
|
780
|
+
const { entries: list } = await getListRecursive(initialDepth);
|
|
781
|
+
if (!list.length) return "empty";
|
|
782
|
+
const tree = list.map((e) => {
|
|
783
|
+
const indent = " ".repeat(e.depth);
|
|
784
|
+
const name = e.type === "dir" ? `${e.name}/` : e.name;
|
|
785
|
+
return `${indent}${name}`;
|
|
786
|
+
}).join("\n");
|
|
787
|
+
return tree;
|
|
769
788
|
}
|
|
770
789
|
|
|
771
790
|
// tools/warp_grep/agent/tools/finish.ts
|
|
@@ -826,21 +845,32 @@ function mergeRanges(ranges) {
|
|
|
826
845
|
return merged;
|
|
827
846
|
}
|
|
828
847
|
|
|
829
|
-
// tools/warp_grep/agent/
|
|
830
|
-
var
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
if (m.role === "assistant") {
|
|
836
|
-
let size = typeof m.content === "string" ? m.content.length : 0;
|
|
837
|
-
if (m.tool_calls) {
|
|
838
|
-
size += m.tool_calls.reduce((s, tc) => s + tc.function.name.length + tc.function.arguments.length, 0);
|
|
848
|
+
// tools/warp_grep/agent/formatter.ts
|
|
849
|
+
var ToolOutputFormatter = class {
|
|
850
|
+
format(toolName, _args, output, options = {}) {
|
|
851
|
+
const name = (toolName ?? "").trim();
|
|
852
|
+
if (!name) {
|
|
853
|
+
return "";
|
|
839
854
|
}
|
|
840
|
-
|
|
855
|
+
const payload = output?.toString?.()?.trim?.() ?? "";
|
|
856
|
+
const isError = Boolean(options.isError);
|
|
857
|
+
if (!payload && !isError) {
|
|
858
|
+
return "";
|
|
859
|
+
}
|
|
860
|
+
return `<tool_response>
|
|
861
|
+
${payload}
|
|
862
|
+
</tool_response>`;
|
|
841
863
|
}
|
|
842
|
-
|
|
864
|
+
};
|
|
865
|
+
var sharedFormatter = new ToolOutputFormatter();
|
|
866
|
+
function formatAgentToolOutput(toolName, args, output, options = {}) {
|
|
867
|
+
return sharedFormatter.format(toolName, args, output, options);
|
|
843
868
|
}
|
|
869
|
+
|
|
870
|
+
// tools/warp_grep/agent/helpers.ts
|
|
871
|
+
var import_path = __toESM(require("path"), 1);
|
|
872
|
+
init_config();
|
|
873
|
+
var TRUNCATED_MARKER = "[truncated for context limit]";
|
|
844
874
|
function formatTurnMessage(turnsUsed, maxTurns) {
|
|
845
875
|
const turnsRemaining = maxTurns - turnsUsed;
|
|
846
876
|
if (turnsRemaining === 1) {
|
|
@@ -851,7 +881,7 @@ You have used ${turnsUsed} turns, you only have 1 turn remaining. You have run o
|
|
|
851
881
|
You have used ${turnsUsed} turn${turnsUsed === 1 ? "" : "s"} and have ${turnsRemaining} remaining`;
|
|
852
882
|
}
|
|
853
883
|
function calculateContextBudget(messages) {
|
|
854
|
-
const totalChars = messages.reduce((sum, m) => sum +
|
|
884
|
+
const totalChars = messages.reduce((sum, m) => sum + m.content.length, 0);
|
|
855
885
|
const maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS;
|
|
856
886
|
const percent = Math.round(totalChars / maxChars * 100);
|
|
857
887
|
const usedK = Math.round(totalChars / 1e3);
|
|
@@ -860,21 +890,24 @@ function calculateContextBudget(messages) {
|
|
|
860
890
|
}
|
|
861
891
|
async function buildInitialState(repoRoot, searchTerm, provider, options) {
|
|
862
892
|
const budget = calculateContextBudget([]);
|
|
863
|
-
const turnTag = `
|
|
893
|
+
const turnTag = `Turn 0/${AGENT_CONFIG.MAX_TURNS}`;
|
|
864
894
|
const treeDepth = options?.search_type === "node_modules" ? 1 : 2;
|
|
865
|
-
const absRoot = import_path2.default.resolve(repoRoot);
|
|
866
895
|
try {
|
|
867
896
|
const entries = await provider.listDirectory({
|
|
868
897
|
path: ".",
|
|
869
898
|
maxResults: AGENT_CONFIG.MAX_OUTPUT_LINES,
|
|
870
899
|
maxDepth: treeDepth
|
|
871
900
|
});
|
|
872
|
-
const
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
901
|
+
const treeLines = entries.map((e) => {
|
|
902
|
+
const indent = " ".repeat(e.depth);
|
|
903
|
+
const name = e.type === "dir" ? `${e.name}/` : e.name;
|
|
904
|
+
return `${indent}${name}`;
|
|
905
|
+
});
|
|
906
|
+
const repoName = import_path.default.basename(repoRoot);
|
|
907
|
+
const treeOutput = treeLines.length > 0 ? `${repoName}/
|
|
908
|
+
${treeLines.join("\n")}` : `${repoName}/`;
|
|
876
909
|
return `<repo_structure>
|
|
877
|
-
${
|
|
910
|
+
${treeOutput}
|
|
878
911
|
</repo_structure>
|
|
879
912
|
|
|
880
913
|
<search_string>
|
|
@@ -883,8 +916,9 @@ ${searchTerm}
|
|
|
883
916
|
${budget}
|
|
884
917
|
${turnTag}`;
|
|
885
918
|
} catch {
|
|
919
|
+
const repoName = import_path.default.basename(repoRoot);
|
|
886
920
|
return `<repo_structure>
|
|
887
|
-
${
|
|
921
|
+
${repoName}/
|
|
888
922
|
</repo_structure>
|
|
889
923
|
|
|
890
924
|
<search_string>
|
|
@@ -895,32 +929,26 @@ ${turnTag}`;
|
|
|
895
929
|
}
|
|
896
930
|
}
|
|
897
931
|
function enforceContextLimit(messages, maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS) {
|
|
898
|
-
const getTotalChars = () => messages.reduce((sum, m) => sum +
|
|
932
|
+
const getTotalChars = () => messages.reduce((sum, m) => sum + m.content.length, 0);
|
|
899
933
|
if (getTotalChars() <= maxChars) {
|
|
900
934
|
return messages;
|
|
901
935
|
}
|
|
902
|
-
const
|
|
936
|
+
const userIndices = [];
|
|
903
937
|
let firstUserSkipped = false;
|
|
904
938
|
for (let i = 0; i < messages.length; i++) {
|
|
905
|
-
|
|
906
|
-
if (m.role === "tool") {
|
|
907
|
-
truncatableIndices.push(i);
|
|
908
|
-
} else if (m.role === "user") {
|
|
939
|
+
if (messages[i].role === "user") {
|
|
909
940
|
if (!firstUserSkipped) {
|
|
910
941
|
firstUserSkipped = true;
|
|
911
942
|
continue;
|
|
912
943
|
}
|
|
913
|
-
|
|
944
|
+
userIndices.push(i);
|
|
914
945
|
}
|
|
915
946
|
}
|
|
916
|
-
for (const idx of
|
|
947
|
+
for (const idx of userIndices) {
|
|
917
948
|
if (getTotalChars() <= maxChars) {
|
|
918
949
|
break;
|
|
919
950
|
}
|
|
920
|
-
|
|
921
|
-
if (m.role === "tool" && m.content !== TRUNCATED_MARKER) {
|
|
922
|
-
messages[idx] = { role: "tool", tool_call_id: m.tool_call_id, content: TRUNCATED_MARKER };
|
|
923
|
-
} else if (m.role === "user" && m.content !== TRUNCATED_MARKER) {
|
|
951
|
+
if (messages[idx].content !== TRUNCATED_MARKER) {
|
|
924
952
|
messages[idx] = { role: "user", content: TRUNCATED_MARKER };
|
|
925
953
|
}
|
|
926
954
|
}
|
|
@@ -933,7 +961,7 @@ var import_openai = __toESM(require("openai"), 1);
|
|
|
933
961
|
// package.json
|
|
934
962
|
var package_default = {
|
|
935
963
|
name: "@morphllm/morphsdk",
|
|
936
|
-
version: "0.2.
|
|
964
|
+
version: "0.2.146",
|
|
937
965
|
description: "TypeScript SDK and CLI for Morph Fast Apply integration",
|
|
938
966
|
type: "module",
|
|
939
967
|
main: "./dist/index.cjs",
|
|
@@ -1172,115 +1200,9 @@ var package_default = {
|
|
|
1172
1200
|
var SDK_VERSION = package_default.version;
|
|
1173
1201
|
|
|
1174
1202
|
// tools/warp_grep/agent/runner.ts
|
|
1175
|
-
var
|
|
1203
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
1204
|
+
var parser = new LLMResponseParser();
|
|
1176
1205
|
var DEFAULT_API_URL = "https://api.morphllm.com";
|
|
1177
|
-
var TOOL_SPECS = [
|
|
1178
|
-
{
|
|
1179
|
-
type: "function",
|
|
1180
|
-
function: {
|
|
1181
|
-
name: "list_directory",
|
|
1182
|
-
description: "Execute ls or find commands to explore directory structure. Max 500 results. Common junk directories are excluded automatically.",
|
|
1183
|
-
parameters: {
|
|
1184
|
-
type: "object",
|
|
1185
|
-
properties: {
|
|
1186
|
-
command: {
|
|
1187
|
-
type: "string",
|
|
1188
|
-
description: "Full ls or find command (e.g. ls -la src/, find . -maxdepth 2 -type f -name '*.py', find . -type d, ls -d */)."
|
|
1189
|
-
}
|
|
1190
|
-
},
|
|
1191
|
-
required: ["command"]
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
},
|
|
1195
|
-
{
|
|
1196
|
-
type: "function",
|
|
1197
|
-
function: {
|
|
1198
|
-
name: "grep_search",
|
|
1199
|
-
description: "Search for a regex pattern in file contents. Returns matching lines with file paths and line numbers. Case-insensitive. Respects .gitignore.",
|
|
1200
|
-
parameters: {
|
|
1201
|
-
type: "object",
|
|
1202
|
-
properties: {
|
|
1203
|
-
pattern: {
|
|
1204
|
-
type: "string",
|
|
1205
|
-
description: "Regex pattern to search for in file contents (e.g. 'class\\s+\\w+Error', 'import|require|from', 'def (get|set|update)_user')."
|
|
1206
|
-
},
|
|
1207
|
-
path: {
|
|
1208
|
-
type: "string",
|
|
1209
|
-
description: "File or directory to search in. Defaults to current working directory."
|
|
1210
|
-
},
|
|
1211
|
-
glob: {
|
|
1212
|
-
type: "string",
|
|
1213
|
-
description: "Glob pattern to filter files (e.g. '*.py', '*.{ts,tsx,js,jsx,py,go}', 'src/**/*.go', '!*.test.*')."
|
|
1214
|
-
},
|
|
1215
|
-
limit: {
|
|
1216
|
-
type: "integer",
|
|
1217
|
-
description: "Limit output to first N matching lines. Shows all matches if not specified."
|
|
1218
|
-
}
|
|
1219
|
-
},
|
|
1220
|
-
required: ["pattern"]
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
},
|
|
1224
|
-
{
|
|
1225
|
-
type: "function",
|
|
1226
|
-
function: {
|
|
1227
|
-
name: "glob",
|
|
1228
|
-
description: "Find files by name/extension using glob patterns. Returns absolute paths sorted by modification time (newest first). Respects .gitignore. Max 100 results.",
|
|
1229
|
-
parameters: {
|
|
1230
|
-
type: "object",
|
|
1231
|
-
properties: {
|
|
1232
|
-
pattern: {
|
|
1233
|
-
type: "string",
|
|
1234
|
-
description: "Glob pattern to match files (e.g. '*.py', 'src/**/*.js', '*.{ts,tsx}', 'test_*.py')."
|
|
1235
|
-
},
|
|
1236
|
-
path: {
|
|
1237
|
-
type: "string",
|
|
1238
|
-
description: "Directory to search in. Defaults to repository root."
|
|
1239
|
-
}
|
|
1240
|
-
},
|
|
1241
|
-
required: ["pattern"]
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
},
|
|
1245
|
-
{
|
|
1246
|
-
type: "function",
|
|
1247
|
-
function: {
|
|
1248
|
-
name: "read",
|
|
1249
|
-
description: "Read entire files or specific line ranges using absolute paths.",
|
|
1250
|
-
parameters: {
|
|
1251
|
-
type: "object",
|
|
1252
|
-
properties: {
|
|
1253
|
-
path: {
|
|
1254
|
-
type: "string",
|
|
1255
|
-
description: "File path to read, using absolute path (e.g. '/home/ubuntu/repo/src/main.py' or windows path)."
|
|
1256
|
-
},
|
|
1257
|
-
lines: {
|
|
1258
|
-
type: "string",
|
|
1259
|
-
description: "Optional line range (e.g. '1-50' or '1-20,45-80'). Omit to read entire file."
|
|
1260
|
-
}
|
|
1261
|
-
},
|
|
1262
|
-
required: ["path"]
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
},
|
|
1266
|
-
{
|
|
1267
|
-
type: "function",
|
|
1268
|
-
function: {
|
|
1269
|
-
name: "finish",
|
|
1270
|
-
description: "Submit final answer with all relevant code locations. Include imports and over-include rather than miss context.",
|
|
1271
|
-
parameters: {
|
|
1272
|
-
type: "object",
|
|
1273
|
-
properties: {
|
|
1274
|
-
files: {
|
|
1275
|
-
type: "string",
|
|
1276
|
-
description: "One file per line as path:lines (e.g. 'src/auth.py:1-15,25-50\\nsrc/user.py'). Omit line range to include entire file."
|
|
1277
|
-
}
|
|
1278
|
-
},
|
|
1279
|
-
required: ["files"]
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
];
|
|
1284
1206
|
async function callModel(messages, model, options = {}) {
|
|
1285
1207
|
const baseUrl = options.morphApiUrl || DEFAULT_API_URL;
|
|
1286
1208
|
const apiKey = options.morphApiKey || process.env.MORPH_API_KEY || "";
|
|
@@ -1301,9 +1223,8 @@ async function callModel(messages, model, options = {}) {
|
|
|
1301
1223
|
data = await client.chat.completions.create({
|
|
1302
1224
|
model,
|
|
1303
1225
|
temperature: 0,
|
|
1304
|
-
max_tokens:
|
|
1226
|
+
max_tokens: 1024,
|
|
1305
1227
|
messages,
|
|
1306
|
-
tools: TOOL_SPECS,
|
|
1307
1228
|
...options.search_type ? { search_type: options.search_type } : {}
|
|
1308
1229
|
});
|
|
1309
1230
|
} catch (error) {
|
|
@@ -1315,87 +1236,187 @@ async function callModel(messages, model, options = {}) {
|
|
|
1315
1236
|
throw error;
|
|
1316
1237
|
}
|
|
1317
1238
|
const choice = data?.choices?.[0];
|
|
1318
|
-
const
|
|
1319
|
-
if (
|
|
1320
|
-
|
|
1321
|
-
throw new Error("Invalid response from model: no message in response");
|
|
1322
|
-
}
|
|
1323
|
-
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
1324
|
-
continue;
|
|
1325
|
-
}
|
|
1326
|
-
const toolCalls = (message.tool_calls || []).map((tc) => ({
|
|
1327
|
-
id: tc.id,
|
|
1328
|
-
type: "function",
|
|
1329
|
-
function: { name: tc.function.name, arguments: tc.function.arguments }
|
|
1330
|
-
}));
|
|
1331
|
-
if (message.content || toolCalls.length > 0) {
|
|
1332
|
-
return { content: message.content ?? null, tool_calls: toolCalls };
|
|
1239
|
+
const content = choice?.message?.content;
|
|
1240
|
+
if (content && typeof content === "string") {
|
|
1241
|
+
return content;
|
|
1333
1242
|
}
|
|
1334
1243
|
if (attempt === MAX_EMPTY_RETRIES) {
|
|
1335
1244
|
const finishReason = choice?.finish_reason ?? "unknown";
|
|
1245
|
+
const hasToolCalls = Array.isArray(choice?.message?.tool_calls) && choice.message.tool_calls.length > 0;
|
|
1246
|
+
const choicesLen = data?.choices?.length ?? 0;
|
|
1247
|
+
const contentType = content === null ? "null" : content === void 0 ? "undefined" : typeof content;
|
|
1336
1248
|
throw new Error(
|
|
1337
|
-
`Invalid response from model:
|
|
1249
|
+
`Invalid response from model: content=${contentType}, finish_reason=${finishReason}, has_tool_calls=${hasToolCalls}, choices_length=${choicesLen}`
|
|
1338
1250
|
);
|
|
1339
1251
|
}
|
|
1340
1252
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
1341
1253
|
}
|
|
1342
1254
|
throw new Error("Invalid response from model");
|
|
1343
1255
|
}
|
|
1344
|
-
function
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1256
|
+
async function runWarpGrep(config) {
|
|
1257
|
+
const totalStart = Date.now();
|
|
1258
|
+
const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
1259
|
+
const timings = { turns: [], timeout_ms: timeoutMs };
|
|
1260
|
+
const repoRoot = import_path2.default.resolve(config.repoRoot || process.cwd());
|
|
1261
|
+
const model = config.model || DEFAULT_MODEL;
|
|
1262
|
+
const messages = [];
|
|
1263
|
+
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
1264
|
+
const initialStateStart = Date.now();
|
|
1265
|
+
const initialState = await buildInitialState(repoRoot, config.searchTerm, config.provider, { search_type: config.search_type });
|
|
1266
|
+
timings.initial_state_ms = Date.now() - initialStateStart;
|
|
1267
|
+
messages.push({ role: "user", content: initialState });
|
|
1268
|
+
const provider = config.provider;
|
|
1269
|
+
const errors = [];
|
|
1270
|
+
let finishMeta;
|
|
1271
|
+
let terminationReason = "terminated";
|
|
1272
|
+
for (let turn = 1; turn <= maxTurns; turn += 1) {
|
|
1273
|
+
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
1274
|
+
enforceContextLimit(messages);
|
|
1275
|
+
const modelCallStart = Date.now();
|
|
1276
|
+
const assistantContent = await callModel(messages, model, {
|
|
1277
|
+
morphApiKey: config.morphApiKey,
|
|
1278
|
+
morphApiUrl: config.morphApiUrl,
|
|
1279
|
+
retryConfig: config.retryConfig,
|
|
1280
|
+
timeout: timeoutMs,
|
|
1281
|
+
search_type: config.search_type
|
|
1282
|
+
}).catch((e) => {
|
|
1283
|
+
const errMsg = e instanceof Error ? e.message : String(e);
|
|
1284
|
+
console.error(`[warp_grep] Morph API call failed on turn ${turn}:`, errMsg);
|
|
1285
|
+
errors.push({ message: errMsg });
|
|
1286
|
+
return "";
|
|
1287
|
+
});
|
|
1288
|
+
turnMetrics.morph_api_ms = Date.now() - modelCallStart;
|
|
1289
|
+
if (!assistantContent) {
|
|
1290
|
+
console.error(`[warp_grep] Empty response from Morph API on turn ${turn}. Errors so far:`, errors);
|
|
1291
|
+
timings.turns.push(turnMetrics);
|
|
1292
|
+
break;
|
|
1370
1293
|
}
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
});
|
|
1294
|
+
messages.push({ role: "assistant", content: assistantContent });
|
|
1295
|
+
const toolCalls = parser.parse(assistantContent);
|
|
1296
|
+
if (toolCalls.length === 0) {
|
|
1297
|
+
console.error(`[warp_grep] No tool calls parsed on turn ${turn}. Assistant content (first 500 chars):`, assistantContent.slice(0, 500));
|
|
1298
|
+
errors.push({ message: "No tool calls produced by the model. Your MCP is likely out of date! Update it by running: rm -rf ~/.npm/_npx && npm cache clean --force && npx -y @morphllm/morphmcp@latest" });
|
|
1299
|
+
terminationReason = "terminated";
|
|
1300
|
+
timings.turns.push(turnMetrics);
|
|
1301
|
+
break;
|
|
1376
1302
|
}
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1303
|
+
const finishCalls = toolCalls.filter((c) => c.name === "finish");
|
|
1304
|
+
const grepCalls = toolCalls.filter((c) => c.name === "grep");
|
|
1305
|
+
const listDirCalls = toolCalls.filter((c) => c.name === "list_directory");
|
|
1306
|
+
const readCalls = toolCalls.filter((c) => c.name === "read");
|
|
1307
|
+
const skipCalls = toolCalls.filter((c) => c.name === "_skip");
|
|
1308
|
+
const formatted = [];
|
|
1309
|
+
for (const c of skipCalls) {
|
|
1310
|
+
const msg = c.arguments?.message || "Command skipped due to parsing error";
|
|
1311
|
+
formatted.push(msg);
|
|
1380
1312
|
}
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1313
|
+
const allPromises = [];
|
|
1314
|
+
for (const c of grepCalls) {
|
|
1315
|
+
const args = c.arguments ?? {};
|
|
1316
|
+
allPromises.push(
|
|
1317
|
+
toolGrep(provider, args).then(
|
|
1318
|
+
({ output }) => formatAgentToolOutput("grep", args, output),
|
|
1319
|
+
(err) => formatAgentToolOutput("grep", args, String(err), { isError: true })
|
|
1320
|
+
)
|
|
1321
|
+
);
|
|
1322
|
+
}
|
|
1323
|
+
for (const c of listDirCalls) {
|
|
1324
|
+
const args = c.arguments ?? {};
|
|
1325
|
+
allPromises.push(
|
|
1326
|
+
toolListDirectory(provider, args).then(
|
|
1327
|
+
(p) => formatAgentToolOutput("list_directory", args, p),
|
|
1328
|
+
(err) => formatAgentToolOutput("list_directory", args, String(err), { isError: true })
|
|
1329
|
+
)
|
|
1330
|
+
);
|
|
1331
|
+
}
|
|
1332
|
+
for (const c of readCalls) {
|
|
1333
|
+
const args = c.arguments ?? {};
|
|
1334
|
+
allPromises.push(
|
|
1335
|
+
toolRead(provider, args).then(
|
|
1336
|
+
(p) => formatAgentToolOutput("read", args, p),
|
|
1337
|
+
(err) => formatAgentToolOutput("read", args, String(err), { isError: true })
|
|
1338
|
+
)
|
|
1339
|
+
);
|
|
1340
|
+
}
|
|
1341
|
+
const toolExecStart = Date.now();
|
|
1342
|
+
const allResults = await Promise.all(allPromises);
|
|
1343
|
+
turnMetrics.local_tools_ms = Date.now() - toolExecStart;
|
|
1344
|
+
for (const result of allResults) {
|
|
1345
|
+
formatted.push(result);
|
|
1346
|
+
}
|
|
1347
|
+
if (formatted.length > 0) {
|
|
1348
|
+
const turnMessage = formatTurnMessage(turn, maxTurns);
|
|
1349
|
+
const contextBudget = calculateContextBudget(messages);
|
|
1350
|
+
messages.push({ role: "user", content: formatted.join("\n") + turnMessage + "\n" + contextBudget });
|
|
1351
|
+
}
|
|
1352
|
+
timings.turns.push(turnMetrics);
|
|
1353
|
+
if (finishCalls.length) {
|
|
1354
|
+
const fc = finishCalls[0];
|
|
1355
|
+
const files = fc.arguments?.files ?? [];
|
|
1356
|
+
const textResult = fc.arguments?.textResult;
|
|
1357
|
+
finishMeta = { files };
|
|
1358
|
+
terminationReason = "completed";
|
|
1359
|
+
if (files.length === 0) {
|
|
1360
|
+
const payload2 = textResult || "No relevant code found.";
|
|
1361
|
+
timings.turns.push(turnMetrics);
|
|
1362
|
+
timings.total_ms = Date.now() - totalStart;
|
|
1363
|
+
return {
|
|
1364
|
+
terminationReason: "completed",
|
|
1365
|
+
messages,
|
|
1366
|
+
finish: { payload: payload2, metadata: finishMeta },
|
|
1367
|
+
timings
|
|
1368
|
+
};
|
|
1369
|
+
}
|
|
1370
|
+
break;
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
if (terminationReason !== "completed" || !finishMeta) {
|
|
1374
|
+
timings.total_ms = Date.now() - totalStart;
|
|
1375
|
+
return { terminationReason, messages, errors, timings };
|
|
1376
|
+
}
|
|
1377
|
+
const parts = ["Relevant context found:"];
|
|
1378
|
+
for (const f of finishMeta.files) {
|
|
1379
|
+
const ranges = f.lines === "*" ? "*" : Array.isArray(f.lines) ? f.lines.map(([s, e]) => `${s}-${e}`).join(", ") : "*";
|
|
1380
|
+
parts.push(`- ${f.path}: ${ranges}`);
|
|
1381
|
+
}
|
|
1382
|
+
const payload = parts.join("\n");
|
|
1383
|
+
const finishResolutionStart = Date.now();
|
|
1384
|
+
const fileReadErrors = [];
|
|
1385
|
+
const resolved = await readFinishFiles(
|
|
1386
|
+
repoRoot,
|
|
1387
|
+
finishMeta.files,
|
|
1388
|
+
async (p, s, e) => {
|
|
1389
|
+
try {
|
|
1390
|
+
const rr = await provider.read({ path: p, start: s, end: e });
|
|
1391
|
+
return rr.lines.map((l) => {
|
|
1392
|
+
const idx = l.indexOf("|");
|
|
1393
|
+
return idx >= 0 ? l.slice(idx + 1) : l;
|
|
1394
|
+
});
|
|
1395
|
+
} catch (err) {
|
|
1396
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
1397
|
+
fileReadErrors.push({ path: p, error: errorMsg });
|
|
1398
|
+
console.error(`[warp_grep] Failed to read file: ${p} - ${errorMsg}`);
|
|
1399
|
+
return [`[couldn't find: ${p}]`];
|
|
1387
1400
|
}
|
|
1388
|
-
return toolRead(provider, readArgs);
|
|
1389
1401
|
}
|
|
1390
|
-
|
|
1391
|
-
|
|
1402
|
+
);
|
|
1403
|
+
timings.finish_resolution_ms = Date.now() - finishResolutionStart;
|
|
1404
|
+
if (fileReadErrors.length > 0) {
|
|
1405
|
+
errors.push(...fileReadErrors.map((e) => ({ message: `File read error: ${e.path} - ${e.error}` })));
|
|
1392
1406
|
}
|
|
1407
|
+
timings.total_ms = Date.now() - totalStart;
|
|
1408
|
+
return {
|
|
1409
|
+
terminationReason: "completed",
|
|
1410
|
+
messages,
|
|
1411
|
+
finish: { payload, metadata: finishMeta, resolved },
|
|
1412
|
+
timings
|
|
1413
|
+
};
|
|
1393
1414
|
}
|
|
1394
1415
|
async function* runWarpGrepStreaming(config) {
|
|
1395
1416
|
const totalStart = Date.now();
|
|
1396
1417
|
const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
1397
1418
|
const timings = { turns: [], timeout_ms: timeoutMs };
|
|
1398
|
-
const repoRoot =
|
|
1419
|
+
const repoRoot = import_path2.default.resolve(config.repoRoot || process.cwd());
|
|
1399
1420
|
const model = config.model || DEFAULT_MODEL;
|
|
1400
1421
|
const messages = [];
|
|
1401
1422
|
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
@@ -1411,7 +1432,7 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1411
1432
|
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
1412
1433
|
enforceContextLimit(messages);
|
|
1413
1434
|
const modelCallStart = Date.now();
|
|
1414
|
-
const
|
|
1435
|
+
const assistantContent = await callModel(messages, model, {
|
|
1415
1436
|
morphApiKey: config.morphApiKey,
|
|
1416
1437
|
morphApiUrl: config.morphApiUrl,
|
|
1417
1438
|
retryConfig: config.retryConfig,
|
|
@@ -1419,45 +1440,90 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1419
1440
|
search_type: config.search_type
|
|
1420
1441
|
}).catch((e) => {
|
|
1421
1442
|
const errMsg = e instanceof Error ? e.message : String(e);
|
|
1422
|
-
console.error(`[warp_grep] Morph API call failed on turn ${turn}:`, errMsg);
|
|
1443
|
+
console.error(`[warp_grep:stream] Morph API call failed on turn ${turn}:`, errMsg);
|
|
1423
1444
|
errors.push({ message: errMsg });
|
|
1424
|
-
return
|
|
1445
|
+
return "";
|
|
1425
1446
|
});
|
|
1426
1447
|
turnMetrics.morph_api_ms = Date.now() - modelCallStart;
|
|
1427
|
-
if (!
|
|
1448
|
+
if (!assistantContent) {
|
|
1449
|
+
console.error(`[warp_grep:stream] Empty response from Morph API on turn ${turn}. Errors so far:`, errors);
|
|
1428
1450
|
timings.turns.push(turnMetrics);
|
|
1429
1451
|
break;
|
|
1430
1452
|
}
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
role: "assistant",
|
|
1434
|
-
content: response.content,
|
|
1435
|
-
...toolCalls.length > 0 ? { tool_calls: toolCalls } : {}
|
|
1436
|
-
});
|
|
1453
|
+
messages.push({ role: "assistant", content: assistantContent });
|
|
1454
|
+
const toolCalls = parser.parse(assistantContent);
|
|
1437
1455
|
if (toolCalls.length === 0) {
|
|
1438
|
-
console.error(`[warp_grep] No tool calls on turn ${turn}.
|
|
1439
|
-
errors.push({ message: "No tool calls produced by the model." });
|
|
1456
|
+
console.error(`[warp_grep:stream] No tool calls parsed on turn ${turn}. Assistant content (first 500 chars):`, assistantContent.slice(0, 500));
|
|
1457
|
+
errors.push({ message: "No tool calls produced by the model. Your MCP is likely out of date! Update it by running: rm -rf ~/.npm/_npx && npm cache clean --force && npx -y @morphllm/morphmcp@latest" });
|
|
1440
1458
|
terminationReason = "terminated";
|
|
1441
1459
|
timings.turns.push(turnMetrics);
|
|
1442
1460
|
break;
|
|
1443
1461
|
}
|
|
1444
1462
|
yield {
|
|
1445
1463
|
turn,
|
|
1446
|
-
toolCalls: toolCalls.map((
|
|
1447
|
-
name:
|
|
1448
|
-
arguments:
|
|
1464
|
+
toolCalls: toolCalls.map((c) => ({
|
|
1465
|
+
name: c.name,
|
|
1466
|
+
arguments: c.arguments ?? {}
|
|
1449
1467
|
}))
|
|
1450
1468
|
};
|
|
1451
|
-
const
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1469
|
+
const finishCalls = toolCalls.filter((c) => c.name === "finish");
|
|
1470
|
+
const grepCalls = toolCalls.filter((c) => c.name === "grep");
|
|
1471
|
+
const listDirCalls = toolCalls.filter((c) => c.name === "list_directory");
|
|
1472
|
+
const readCalls = toolCalls.filter((c) => c.name === "read");
|
|
1473
|
+
const skipCalls = toolCalls.filter((c) => c.name === "_skip");
|
|
1474
|
+
const formatted = [];
|
|
1475
|
+
for (const c of skipCalls) {
|
|
1476
|
+
const msg = c.arguments?.message || "Command skipped due to parsing error";
|
|
1477
|
+
formatted.push(msg);
|
|
1478
|
+
}
|
|
1479
|
+
const allPromises = [];
|
|
1480
|
+
for (const c of grepCalls) {
|
|
1481
|
+
const args = c.arguments ?? {};
|
|
1482
|
+
allPromises.push(
|
|
1483
|
+
toolGrep(provider, args).then(
|
|
1484
|
+
({ output }) => formatAgentToolOutput("grep", args, output),
|
|
1485
|
+
(err) => formatAgentToolOutput("grep", args, String(err), { isError: true })
|
|
1486
|
+
)
|
|
1487
|
+
);
|
|
1488
|
+
}
|
|
1489
|
+
for (const c of listDirCalls) {
|
|
1490
|
+
const args = c.arguments ?? {};
|
|
1491
|
+
allPromises.push(
|
|
1492
|
+
toolListDirectory(provider, args).then(
|
|
1493
|
+
(p) => formatAgentToolOutput("list_directory", args, p),
|
|
1494
|
+
(err) => formatAgentToolOutput("list_directory", args, String(err), { isError: true })
|
|
1495
|
+
)
|
|
1496
|
+
);
|
|
1497
|
+
}
|
|
1498
|
+
for (const c of readCalls) {
|
|
1499
|
+
const args = c.arguments ?? {};
|
|
1500
|
+
allPromises.push(
|
|
1501
|
+
toolRead(provider, args).then(
|
|
1502
|
+
(p) => formatAgentToolOutput("read", args, p),
|
|
1503
|
+
(err) => formatAgentToolOutput("read", args, String(err), { isError: true })
|
|
1504
|
+
)
|
|
1505
|
+
);
|
|
1506
|
+
}
|
|
1507
|
+
const toolExecStart = Date.now();
|
|
1508
|
+
const allResults = await Promise.all(allPromises);
|
|
1509
|
+
turnMetrics.local_tools_ms = Date.now() - toolExecStart;
|
|
1510
|
+
for (const result of allResults) {
|
|
1511
|
+
formatted.push(result);
|
|
1512
|
+
}
|
|
1513
|
+
if (formatted.length > 0) {
|
|
1514
|
+
const turnMessage = formatTurnMessage(turn, maxTurns);
|
|
1515
|
+
const contextBudget = calculateContextBudget(messages);
|
|
1516
|
+
messages.push({ role: "user", content: formatted.join("\n") + turnMessage + "\n" + contextBudget });
|
|
1517
|
+
}
|
|
1518
|
+
timings.turns.push(turnMetrics);
|
|
1519
|
+
if (finishCalls.length) {
|
|
1520
|
+
const fc = finishCalls[0];
|
|
1521
|
+
const files = fc.arguments?.files ?? [];
|
|
1522
|
+
const textResult = fc.arguments?.textResult;
|
|
1456
1523
|
finishMeta = { files };
|
|
1457
1524
|
terminationReason = "completed";
|
|
1458
1525
|
if (files.length === 0) {
|
|
1459
|
-
const payload2 =
|
|
1460
|
-
timings.turns.push(turnMetrics);
|
|
1526
|
+
const payload2 = textResult || "No relevant code found.";
|
|
1461
1527
|
timings.total_ms = Date.now() - totalStart;
|
|
1462
1528
|
return {
|
|
1463
1529
|
terminationReason: "completed",
|
|
@@ -1466,25 +1532,8 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1466
1532
|
timings
|
|
1467
1533
|
};
|
|
1468
1534
|
}
|
|
1469
|
-
timings.turns.push(turnMetrics);
|
|
1470
1535
|
break;
|
|
1471
1536
|
}
|
|
1472
|
-
const toolExecStart = Date.now();
|
|
1473
|
-
const results = await Promise.all(
|
|
1474
|
-
toolCalls.map(async (tc) => {
|
|
1475
|
-
const args = safeParseJSON(tc.function.arguments);
|
|
1476
|
-
const output = await executeTool(provider, tc.function.name, args, repoRoot).catch((err) => String(err));
|
|
1477
|
-
return { tool_call_id: tc.id, content: output };
|
|
1478
|
-
})
|
|
1479
|
-
);
|
|
1480
|
-
turnMetrics.local_tools_ms = Date.now() - toolExecStart;
|
|
1481
|
-
for (const result of results) {
|
|
1482
|
-
messages.push({ role: "tool", tool_call_id: result.tool_call_id, content: result.content });
|
|
1483
|
-
}
|
|
1484
|
-
const turnMsg = formatTurnMessage(turn, maxTurns);
|
|
1485
|
-
const budget = calculateContextBudget(messages);
|
|
1486
|
-
messages.push({ role: "user", content: turnMsg + "\n" + budget });
|
|
1487
|
-
timings.turns.push(turnMetrics);
|
|
1488
1537
|
}
|
|
1489
1538
|
if (terminationReason !== "completed" || !finishMeta) {
|
|
1490
1539
|
timings.total_ms = Date.now() - totalStart;
|
|
@@ -1528,14 +1577,6 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1528
1577
|
timings
|
|
1529
1578
|
};
|
|
1530
1579
|
}
|
|
1531
|
-
async function runWarpGrep(config) {
|
|
1532
|
-
const gen = runWarpGrepStreaming(config);
|
|
1533
|
-
let result = await gen.next();
|
|
1534
|
-
while (!result.done) {
|
|
1535
|
-
result = await gen.next();
|
|
1536
|
-
}
|
|
1537
|
-
return result.value;
|
|
1538
|
-
}
|
|
1539
1580
|
|
|
1540
1581
|
// tools/warp_grep/providers/remote.ts
|
|
1541
1582
|
init_config();
|
|
@@ -1715,35 +1756,6 @@ var RemoteCommandsProvider = class {
|
|
|
1715
1756
|
return [];
|
|
1716
1757
|
}
|
|
1717
1758
|
}
|
|
1718
|
-
/**
|
|
1719
|
-
* Glob search - finds files matching a pattern.
|
|
1720
|
-
* Falls back to a grep --files approach via the listDir command.
|
|
1721
|
-
*/
|
|
1722
|
-
async glob(params) {
|
|
1723
|
-
const searchPath = params.path || this.repoRoot;
|
|
1724
|
-
try {
|
|
1725
|
-
const stdout = await this.commands.listDir(searchPath, 10);
|
|
1726
|
-
const allPaths = (stdout || "").trim().split(/\r?\n/).filter((p) => p.length > 0);
|
|
1727
|
-
const globToRegex = (glob) => {
|
|
1728
|
-
const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
1729
|
-
return new RegExp(escaped);
|
|
1730
|
-
};
|
|
1731
|
-
const regex = globToRegex(params.pattern);
|
|
1732
|
-
const matched = allPaths.filter((p) => {
|
|
1733
|
-
const name = p.split("/").pop() || "";
|
|
1734
|
-
return regex.test(name) && !shouldSkip(name);
|
|
1735
|
-
});
|
|
1736
|
-
const totalFound = matched.length;
|
|
1737
|
-
return { files: matched.slice(0, 100), searchDir: searchPath, totalFound };
|
|
1738
|
-
} catch (error) {
|
|
1739
|
-
return {
|
|
1740
|
-
files: [],
|
|
1741
|
-
searchDir: searchPath,
|
|
1742
|
-
totalFound: 0,
|
|
1743
|
-
error: `[GLOB ERROR] ${error instanceof Error ? error.message : String(error)}`
|
|
1744
|
-
};
|
|
1745
|
-
}
|
|
1746
|
-
}
|
|
1747
1759
|
};
|
|
1748
1760
|
|
|
1749
1761
|
// tools/warp_grep/providers/code_storage_http.ts
|
|
@@ -1770,9 +1782,9 @@ function createCodeStorageHttpCommands(config) {
|
|
|
1770
1782
|
const { baseUrl, repoId, branch } = config;
|
|
1771
1783
|
const encodedRepoId = encodeURIComponent(repoId);
|
|
1772
1784
|
return {
|
|
1773
|
-
grep: (pattern,
|
|
1774
|
-
read: (
|
|
1775
|
-
listDir: (
|
|
1785
|
+
grep: (pattern, path5, glob) => post(`${baseUrl}/api/code-search/${encodedRepoId}/grep`, { pattern, path: path5, glob, branch }, "grep"),
|
|
1786
|
+
read: (path5, start, end) => post(`${baseUrl}/api/code-search/${encodedRepoId}/read`, { path: path5, start, end, branch }, "read"),
|
|
1787
|
+
listDir: (path5, maxDepth) => post(`${baseUrl}/api/code-search/${encodedRepoId}/list`, { path: path5, maxDepth, branch }, "list")
|
|
1776
1788
|
};
|
|
1777
1789
|
}
|
|
1778
1790
|
|