@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
|
});
|
|
@@ -633,58 +592,131 @@ module.exports = __toCommonJS(anthropic_exports);
|
|
|
633
592
|
init_config();
|
|
634
593
|
|
|
635
594
|
// tools/warp_grep/agent/parser.ts
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
const trimmed = rangeStr.trim();
|
|
640
|
-
if (!trimmed) continue;
|
|
641
|
-
const parts = trimmed.split("-").map((v) => parseInt(v.trim(), 10));
|
|
642
|
-
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
643
|
-
ranges.push([parts[0], parts[1]]);
|
|
644
|
-
} else if (Number.isFinite(parts[0])) {
|
|
645
|
-
ranges.push([parts[0], parts[0]]);
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
if (ranges.length === 1) return { start: ranges[0][0], end: ranges[0][1] };
|
|
649
|
-
if (ranges.length > 1) return { lines: ranges };
|
|
650
|
-
return {};
|
|
595
|
+
var VALID_COMMANDS = ["list_directory", "ripgrep", "read", "finish"];
|
|
596
|
+
function isValidCommand(name) {
|
|
597
|
+
return VALID_COMMANDS.includes(name);
|
|
651
598
|
}
|
|
652
|
-
function
|
|
653
|
-
const
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
const
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
599
|
+
function parseQwen3ToolCalls(text) {
|
|
600
|
+
const tools = [];
|
|
601
|
+
const toolCallRegex = /<tool_call>\s*<function=([a-z_][a-z0-9_]*)>([\s\S]*?)<\/function>\s*<\/tool_call>/gi;
|
|
602
|
+
let match;
|
|
603
|
+
while ((match = toolCallRegex.exec(text)) !== null) {
|
|
604
|
+
const funcName = match[1].toLowerCase();
|
|
605
|
+
const body = match[2];
|
|
606
|
+
if (!isValidCommand(funcName)) continue;
|
|
607
|
+
const params = {};
|
|
608
|
+
const paramRegex = /<parameter=([a-z_][a-z0-9_]*)>([\s\S]*?)<\/parameter>/gi;
|
|
609
|
+
let paramMatch;
|
|
610
|
+
while ((paramMatch = paramRegex.exec(body)) !== null) {
|
|
611
|
+
params[paramMatch[1].toLowerCase()] = paramMatch[2].trim();
|
|
661
612
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
613
|
+
if (funcName === "ripgrep") {
|
|
614
|
+
const pattern = params.pattern;
|
|
615
|
+
if (!pattern) continue;
|
|
616
|
+
const args = {
|
|
617
|
+
pattern,
|
|
618
|
+
path: params.path || ".",
|
|
619
|
+
...params.glob && { glob: params.glob },
|
|
620
|
+
...params.context_lines && { context_lines: parseInt(params.context_lines, 10) },
|
|
621
|
+
...params.case_sensitive && { case_sensitive: params.case_sensitive === "true" }
|
|
622
|
+
};
|
|
623
|
+
tools.push({ name: "grep", arguments: args });
|
|
624
|
+
} else if (funcName === "list_directory") {
|
|
625
|
+
const command = params.command;
|
|
626
|
+
const directPath = params.path;
|
|
627
|
+
let dirPath = directPath || ".";
|
|
628
|
+
if (!directPath && command) {
|
|
629
|
+
const tokens = command.trim().split(/\s+/);
|
|
630
|
+
const pathTokens = tokens.slice(1).filter((t) => !t.startsWith("-") && !t.startsWith("|") && !t.startsWith("\\("));
|
|
631
|
+
if (pathTokens.length > 0) {
|
|
632
|
+
dirPath = pathTokens[0];
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
tools.push({ name: "list_directory", arguments: { path: dirPath, pattern: params.pattern || null } });
|
|
636
|
+
} else if (funcName === "read") {
|
|
637
|
+
const filePath = params.path;
|
|
638
|
+
if (!filePath) continue;
|
|
639
|
+
const args = { path: filePath };
|
|
640
|
+
const linesStr = params.lines;
|
|
641
|
+
if (linesStr) {
|
|
642
|
+
const ranges = [];
|
|
643
|
+
for (const rangeStr of linesStr.split(",")) {
|
|
644
|
+
const trimmed = rangeStr.trim();
|
|
645
|
+
if (!trimmed) continue;
|
|
646
|
+
const [s, e] = trimmed.split("-").map((v) => parseInt(v.trim(), 10));
|
|
647
|
+
if (Number.isFinite(s) && Number.isFinite(e)) {
|
|
648
|
+
ranges.push([s, e]);
|
|
649
|
+
} else if (Number.isFinite(s)) {
|
|
650
|
+
ranges.push([s, s]);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
if (ranges.length === 1) {
|
|
654
|
+
args.start = ranges[0][0];
|
|
655
|
+
args.end = ranges[0][1];
|
|
656
|
+
} else if (ranges.length > 1) {
|
|
657
|
+
args.lines = ranges;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
tools.push({ name: "read", arguments: args });
|
|
661
|
+
} else if (funcName === "finish") {
|
|
662
|
+
if (params.result && !params.files) {
|
|
663
|
+
tools.push({ name: "finish", arguments: { files: [], textResult: params.result } });
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
const filesStr = params.files;
|
|
667
|
+
if (!filesStr) {
|
|
668
|
+
tools.push({ name: "finish", arguments: { files: [], textResult: "No relevant code found." } });
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
const files = [];
|
|
672
|
+
for (const line of filesStr.split("\n")) {
|
|
673
|
+
const trimmed = line.trim();
|
|
674
|
+
if (!trimmed) continue;
|
|
675
|
+
const colonIdx = trimmed.indexOf(":");
|
|
676
|
+
if (colonIdx === -1) {
|
|
677
|
+
files.push({ path: trimmed, lines: "*" });
|
|
678
|
+
} else {
|
|
679
|
+
const filePath = trimmed.slice(0, colonIdx);
|
|
680
|
+
const rangesPart = trimmed.slice(colonIdx + 1);
|
|
681
|
+
const ranges = [];
|
|
682
|
+
for (const rangeStr of rangesPart.split(",")) {
|
|
683
|
+
const rt = rangeStr.trim();
|
|
684
|
+
if (!rt || rt === "*") {
|
|
685
|
+
files.push({ path: filePath, lines: "*" });
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
const [s, e] = rt.split("-").map((v) => parseInt(v.trim(), 10));
|
|
689
|
+
if (Number.isFinite(s) && Number.isFinite(e)) {
|
|
690
|
+
ranges.push([s, e]);
|
|
691
|
+
} else if (Number.isFinite(s)) {
|
|
692
|
+
ranges.push([s, s]);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
if (ranges.length > 0) {
|
|
696
|
+
files.push({ path: filePath, lines: ranges });
|
|
697
|
+
} else if (!files.some((f) => f.path === filePath)) {
|
|
698
|
+
files.push({ path: filePath, lines: "*" });
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
if (files.length > 0) {
|
|
703
|
+
tools.push({ name: "finish", arguments: { files } });
|
|
704
|
+
} else {
|
|
705
|
+
tools.push({ name: "finish", arguments: { files: [], textResult: filesStr } });
|
|
677
706
|
}
|
|
678
707
|
}
|
|
679
|
-
files.push({ path: filePath, lines: ranges.length > 0 ? ranges : "*" });
|
|
680
708
|
}
|
|
681
|
-
return
|
|
682
|
-
}
|
|
683
|
-
function extractPathFromCommand(command) {
|
|
684
|
-
const tokens = command.trim().split(/\s+/);
|
|
685
|
-
const pathTokens = tokens.slice(1).filter((t) => !t.startsWith("-") && !t.startsWith("|") && !t.startsWith("\\("));
|
|
686
|
-
return pathTokens[0] || ".";
|
|
709
|
+
return tools;
|
|
687
710
|
}
|
|
711
|
+
var LLMResponseParser = class {
|
|
712
|
+
parse(text) {
|
|
713
|
+
if (typeof text !== "string") {
|
|
714
|
+
throw new TypeError("Command text must be a string.");
|
|
715
|
+
}
|
|
716
|
+
const withoutThink = text.replace(/<think>[\s\S]*?<\/think>/gi, "");
|
|
717
|
+
return parseQwen3ToolCalls(withoutThink);
|
|
718
|
+
}
|
|
719
|
+
};
|
|
688
720
|
|
|
689
721
|
// tools/warp_grep/agent/tools/grep.ts
|
|
690
722
|
async function toolGrep(provider, args) {
|
|
@@ -735,42 +767,29 @@ async function toolRead(provider, args) {
|
|
|
735
767
|
|
|
736
768
|
// tools/warp_grep/agent/tools/list_directory.ts
|
|
737
769
|
init_config();
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
const
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
return res.error;
|
|
762
|
-
}
|
|
763
|
-
if (!res.files.length) {
|
|
764
|
-
return "no matches";
|
|
765
|
-
}
|
|
766
|
-
const header = `Found ${res.totalFound} file(s) matching "${args.pattern}" within ${res.searchDir}, sorted by modification time (newest first):`;
|
|
767
|
-
const body = res.files.join("\n");
|
|
768
|
-
const truncated = res.totalFound > res.files.length ? `
|
|
769
|
-
[${res.totalFound - res.files.length} files truncated]` : "";
|
|
770
|
-
return `${header}
|
|
771
|
-
---
|
|
772
|
-
${body}
|
|
773
|
-
---${truncated}`;
|
|
770
|
+
async function toolListDirectory(provider, args) {
|
|
771
|
+
const maxResults = args.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES;
|
|
772
|
+
const initialDepth = args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
773
|
+
async function getListRecursive(currentDepth) {
|
|
774
|
+
const entries = await provider.listDirectory({
|
|
775
|
+
path: args.path,
|
|
776
|
+
pattern: args.pattern ?? null,
|
|
777
|
+
maxResults,
|
|
778
|
+
maxDepth: currentDepth
|
|
779
|
+
});
|
|
780
|
+
if (entries.length >= maxResults && currentDepth > 0) {
|
|
781
|
+
return getListRecursive(currentDepth - 1);
|
|
782
|
+
}
|
|
783
|
+
return { entries };
|
|
784
|
+
}
|
|
785
|
+
const { entries: list } = await getListRecursive(initialDepth);
|
|
786
|
+
if (!list.length) return "empty";
|
|
787
|
+
const tree = list.map((e) => {
|
|
788
|
+
const indent = " ".repeat(e.depth);
|
|
789
|
+
const name = e.type === "dir" ? `${e.name}/` : e.name;
|
|
790
|
+
return `${indent}${name}`;
|
|
791
|
+
}).join("\n");
|
|
792
|
+
return tree;
|
|
774
793
|
}
|
|
775
794
|
|
|
776
795
|
// tools/warp_grep/agent/tools/finish.ts
|
|
@@ -831,21 +850,32 @@ function mergeRanges(ranges) {
|
|
|
831
850
|
return merged;
|
|
832
851
|
}
|
|
833
852
|
|
|
834
|
-
// tools/warp_grep/agent/
|
|
835
|
-
var
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
if (m.role === "assistant") {
|
|
841
|
-
let size = typeof m.content === "string" ? m.content.length : 0;
|
|
842
|
-
if (m.tool_calls) {
|
|
843
|
-
size += m.tool_calls.reduce((s, tc) => s + tc.function.name.length + tc.function.arguments.length, 0);
|
|
853
|
+
// tools/warp_grep/agent/formatter.ts
|
|
854
|
+
var ToolOutputFormatter = class {
|
|
855
|
+
format(toolName, _args, output, options = {}) {
|
|
856
|
+
const name = (toolName ?? "").trim();
|
|
857
|
+
if (!name) {
|
|
858
|
+
return "";
|
|
844
859
|
}
|
|
845
|
-
|
|
860
|
+
const payload = output?.toString?.()?.trim?.() ?? "";
|
|
861
|
+
const isError = Boolean(options.isError);
|
|
862
|
+
if (!payload && !isError) {
|
|
863
|
+
return "";
|
|
864
|
+
}
|
|
865
|
+
return `<tool_response>
|
|
866
|
+
${payload}
|
|
867
|
+
</tool_response>`;
|
|
846
868
|
}
|
|
847
|
-
|
|
869
|
+
};
|
|
870
|
+
var sharedFormatter = new ToolOutputFormatter();
|
|
871
|
+
function formatAgentToolOutput(toolName, args, output, options = {}) {
|
|
872
|
+
return sharedFormatter.format(toolName, args, output, options);
|
|
848
873
|
}
|
|
874
|
+
|
|
875
|
+
// tools/warp_grep/agent/helpers.ts
|
|
876
|
+
var import_path = __toESM(require("path"), 1);
|
|
877
|
+
init_config();
|
|
878
|
+
var TRUNCATED_MARKER = "[truncated for context limit]";
|
|
849
879
|
function formatTurnMessage(turnsUsed, maxTurns) {
|
|
850
880
|
const turnsRemaining = maxTurns - turnsUsed;
|
|
851
881
|
if (turnsRemaining === 1) {
|
|
@@ -856,7 +886,7 @@ You have used ${turnsUsed} turns, you only have 1 turn remaining. You have run o
|
|
|
856
886
|
You have used ${turnsUsed} turn${turnsUsed === 1 ? "" : "s"} and have ${turnsRemaining} remaining`;
|
|
857
887
|
}
|
|
858
888
|
function calculateContextBudget(messages) {
|
|
859
|
-
const totalChars = messages.reduce((sum, m) => sum +
|
|
889
|
+
const totalChars = messages.reduce((sum, m) => sum + m.content.length, 0);
|
|
860
890
|
const maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS;
|
|
861
891
|
const percent = Math.round(totalChars / maxChars * 100);
|
|
862
892
|
const usedK = Math.round(totalChars / 1e3);
|
|
@@ -865,21 +895,24 @@ function calculateContextBudget(messages) {
|
|
|
865
895
|
}
|
|
866
896
|
async function buildInitialState(repoRoot, searchTerm, provider, options) {
|
|
867
897
|
const budget = calculateContextBudget([]);
|
|
868
|
-
const turnTag = `
|
|
898
|
+
const turnTag = `Turn 0/${AGENT_CONFIG.MAX_TURNS}`;
|
|
869
899
|
const treeDepth = options?.search_type === "node_modules" ? 1 : 2;
|
|
870
|
-
const absRoot = import_path2.default.resolve(repoRoot);
|
|
871
900
|
try {
|
|
872
901
|
const entries = await provider.listDirectory({
|
|
873
902
|
path: ".",
|
|
874
903
|
maxResults: AGENT_CONFIG.MAX_OUTPUT_LINES,
|
|
875
904
|
maxDepth: treeDepth
|
|
876
905
|
});
|
|
877
|
-
const
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
906
|
+
const treeLines = entries.map((e) => {
|
|
907
|
+
const indent = " ".repeat(e.depth);
|
|
908
|
+
const name = e.type === "dir" ? `${e.name}/` : e.name;
|
|
909
|
+
return `${indent}${name}`;
|
|
910
|
+
});
|
|
911
|
+
const repoName = import_path.default.basename(repoRoot);
|
|
912
|
+
const treeOutput = treeLines.length > 0 ? `${repoName}/
|
|
913
|
+
${treeLines.join("\n")}` : `${repoName}/`;
|
|
881
914
|
return `<repo_structure>
|
|
882
|
-
${
|
|
915
|
+
${treeOutput}
|
|
883
916
|
</repo_structure>
|
|
884
917
|
|
|
885
918
|
<search_string>
|
|
@@ -888,8 +921,9 @@ ${searchTerm}
|
|
|
888
921
|
${budget}
|
|
889
922
|
${turnTag}`;
|
|
890
923
|
} catch {
|
|
924
|
+
const repoName = import_path.default.basename(repoRoot);
|
|
891
925
|
return `<repo_structure>
|
|
892
|
-
${
|
|
926
|
+
${repoName}/
|
|
893
927
|
</repo_structure>
|
|
894
928
|
|
|
895
929
|
<search_string>
|
|
@@ -900,32 +934,26 @@ ${turnTag}`;
|
|
|
900
934
|
}
|
|
901
935
|
}
|
|
902
936
|
function enforceContextLimit(messages, maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS) {
|
|
903
|
-
const getTotalChars = () => messages.reduce((sum, m) => sum +
|
|
937
|
+
const getTotalChars = () => messages.reduce((sum, m) => sum + m.content.length, 0);
|
|
904
938
|
if (getTotalChars() <= maxChars) {
|
|
905
939
|
return messages;
|
|
906
940
|
}
|
|
907
|
-
const
|
|
941
|
+
const userIndices = [];
|
|
908
942
|
let firstUserSkipped = false;
|
|
909
943
|
for (let i = 0; i < messages.length; i++) {
|
|
910
|
-
|
|
911
|
-
if (m.role === "tool") {
|
|
912
|
-
truncatableIndices.push(i);
|
|
913
|
-
} else if (m.role === "user") {
|
|
944
|
+
if (messages[i].role === "user") {
|
|
914
945
|
if (!firstUserSkipped) {
|
|
915
946
|
firstUserSkipped = true;
|
|
916
947
|
continue;
|
|
917
948
|
}
|
|
918
|
-
|
|
949
|
+
userIndices.push(i);
|
|
919
950
|
}
|
|
920
951
|
}
|
|
921
|
-
for (const idx of
|
|
952
|
+
for (const idx of userIndices) {
|
|
922
953
|
if (getTotalChars() <= maxChars) {
|
|
923
954
|
break;
|
|
924
955
|
}
|
|
925
|
-
|
|
926
|
-
if (m.role === "tool" && m.content !== TRUNCATED_MARKER) {
|
|
927
|
-
messages[idx] = { role: "tool", tool_call_id: m.tool_call_id, content: TRUNCATED_MARKER };
|
|
928
|
-
} else if (m.role === "user" && m.content !== TRUNCATED_MARKER) {
|
|
956
|
+
if (messages[idx].content !== TRUNCATED_MARKER) {
|
|
929
957
|
messages[idx] = { role: "user", content: TRUNCATED_MARKER };
|
|
930
958
|
}
|
|
931
959
|
}
|
|
@@ -938,7 +966,7 @@ var import_openai = __toESM(require("openai"), 1);
|
|
|
938
966
|
// package.json
|
|
939
967
|
var package_default = {
|
|
940
968
|
name: "@morphllm/morphsdk",
|
|
941
|
-
version: "0.2.
|
|
969
|
+
version: "0.2.146",
|
|
942
970
|
description: "TypeScript SDK and CLI for Morph Fast Apply integration",
|
|
943
971
|
type: "module",
|
|
944
972
|
main: "./dist/index.cjs",
|
|
@@ -1177,115 +1205,9 @@ var package_default = {
|
|
|
1177
1205
|
var SDK_VERSION = package_default.version;
|
|
1178
1206
|
|
|
1179
1207
|
// tools/warp_grep/agent/runner.ts
|
|
1180
|
-
var
|
|
1208
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
1209
|
+
var parser = new LLMResponseParser();
|
|
1181
1210
|
var DEFAULT_API_URL = "https://api.morphllm.com";
|
|
1182
|
-
var TOOL_SPECS = [
|
|
1183
|
-
{
|
|
1184
|
-
type: "function",
|
|
1185
|
-
function: {
|
|
1186
|
-
name: "list_directory",
|
|
1187
|
-
description: "Execute ls or find commands to explore directory structure. Max 500 results. Common junk directories are excluded automatically.",
|
|
1188
|
-
parameters: {
|
|
1189
|
-
type: "object",
|
|
1190
|
-
properties: {
|
|
1191
|
-
command: {
|
|
1192
|
-
type: "string",
|
|
1193
|
-
description: "Full ls or find command (e.g. ls -la src/, find . -maxdepth 2 -type f -name '*.py', find . -type d, ls -d */)."
|
|
1194
|
-
}
|
|
1195
|
-
},
|
|
1196
|
-
required: ["command"]
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
},
|
|
1200
|
-
{
|
|
1201
|
-
type: "function",
|
|
1202
|
-
function: {
|
|
1203
|
-
name: "grep_search",
|
|
1204
|
-
description: "Search for a regex pattern in file contents. Returns matching lines with file paths and line numbers. Case-insensitive. Respects .gitignore.",
|
|
1205
|
-
parameters: {
|
|
1206
|
-
type: "object",
|
|
1207
|
-
properties: {
|
|
1208
|
-
pattern: {
|
|
1209
|
-
type: "string",
|
|
1210
|
-
description: "Regex pattern to search for in file contents (e.g. 'class\\s+\\w+Error', 'import|require|from', 'def (get|set|update)_user')."
|
|
1211
|
-
},
|
|
1212
|
-
path: {
|
|
1213
|
-
type: "string",
|
|
1214
|
-
description: "File or directory to search in. Defaults to current working directory."
|
|
1215
|
-
},
|
|
1216
|
-
glob: {
|
|
1217
|
-
type: "string",
|
|
1218
|
-
description: "Glob pattern to filter files (e.g. '*.py', '*.{ts,tsx,js,jsx,py,go}', 'src/**/*.go', '!*.test.*')."
|
|
1219
|
-
},
|
|
1220
|
-
limit: {
|
|
1221
|
-
type: "integer",
|
|
1222
|
-
description: "Limit output to first N matching lines. Shows all matches if not specified."
|
|
1223
|
-
}
|
|
1224
|
-
},
|
|
1225
|
-
required: ["pattern"]
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
},
|
|
1229
|
-
{
|
|
1230
|
-
type: "function",
|
|
1231
|
-
function: {
|
|
1232
|
-
name: "glob",
|
|
1233
|
-
description: "Find files by name/extension using glob patterns. Returns absolute paths sorted by modification time (newest first). Respects .gitignore. Max 100 results.",
|
|
1234
|
-
parameters: {
|
|
1235
|
-
type: "object",
|
|
1236
|
-
properties: {
|
|
1237
|
-
pattern: {
|
|
1238
|
-
type: "string",
|
|
1239
|
-
description: "Glob pattern to match files (e.g. '*.py', 'src/**/*.js', '*.{ts,tsx}', 'test_*.py')."
|
|
1240
|
-
},
|
|
1241
|
-
path: {
|
|
1242
|
-
type: "string",
|
|
1243
|
-
description: "Directory to search in. Defaults to repository root."
|
|
1244
|
-
}
|
|
1245
|
-
},
|
|
1246
|
-
required: ["pattern"]
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
},
|
|
1250
|
-
{
|
|
1251
|
-
type: "function",
|
|
1252
|
-
function: {
|
|
1253
|
-
name: "read",
|
|
1254
|
-
description: "Read entire files or specific line ranges using absolute paths.",
|
|
1255
|
-
parameters: {
|
|
1256
|
-
type: "object",
|
|
1257
|
-
properties: {
|
|
1258
|
-
path: {
|
|
1259
|
-
type: "string",
|
|
1260
|
-
description: "File path to read, using absolute path (e.g. '/home/ubuntu/repo/src/main.py' or windows path)."
|
|
1261
|
-
},
|
|
1262
|
-
lines: {
|
|
1263
|
-
type: "string",
|
|
1264
|
-
description: "Optional line range (e.g. '1-50' or '1-20,45-80'). Omit to read entire file."
|
|
1265
|
-
}
|
|
1266
|
-
},
|
|
1267
|
-
required: ["path"]
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
},
|
|
1271
|
-
{
|
|
1272
|
-
type: "function",
|
|
1273
|
-
function: {
|
|
1274
|
-
name: "finish",
|
|
1275
|
-
description: "Submit final answer with all relevant code locations. Include imports and over-include rather than miss context.",
|
|
1276
|
-
parameters: {
|
|
1277
|
-
type: "object",
|
|
1278
|
-
properties: {
|
|
1279
|
-
files: {
|
|
1280
|
-
type: "string",
|
|
1281
|
-
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."
|
|
1282
|
-
}
|
|
1283
|
-
},
|
|
1284
|
-
required: ["files"]
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
];
|
|
1289
1211
|
async function callModel(messages, model, options = {}) {
|
|
1290
1212
|
const baseUrl = options.morphApiUrl || DEFAULT_API_URL;
|
|
1291
1213
|
const apiKey = options.morphApiKey || process.env.MORPH_API_KEY || "";
|
|
@@ -1306,9 +1228,8 @@ async function callModel(messages, model, options = {}) {
|
|
|
1306
1228
|
data = await client.chat.completions.create({
|
|
1307
1229
|
model,
|
|
1308
1230
|
temperature: 0,
|
|
1309
|
-
max_tokens:
|
|
1231
|
+
max_tokens: 1024,
|
|
1310
1232
|
messages,
|
|
1311
|
-
tools: TOOL_SPECS,
|
|
1312
1233
|
...options.search_type ? { search_type: options.search_type } : {}
|
|
1313
1234
|
});
|
|
1314
1235
|
} catch (error) {
|
|
@@ -1320,87 +1241,187 @@ async function callModel(messages, model, options = {}) {
|
|
|
1320
1241
|
throw error;
|
|
1321
1242
|
}
|
|
1322
1243
|
const choice = data?.choices?.[0];
|
|
1323
|
-
const
|
|
1324
|
-
if (
|
|
1325
|
-
|
|
1326
|
-
throw new Error("Invalid response from model: no message in response");
|
|
1327
|
-
}
|
|
1328
|
-
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
1329
|
-
continue;
|
|
1330
|
-
}
|
|
1331
|
-
const toolCalls = (message.tool_calls || []).map((tc) => ({
|
|
1332
|
-
id: tc.id,
|
|
1333
|
-
type: "function",
|
|
1334
|
-
function: { name: tc.function.name, arguments: tc.function.arguments }
|
|
1335
|
-
}));
|
|
1336
|
-
if (message.content || toolCalls.length > 0) {
|
|
1337
|
-
return { content: message.content ?? null, tool_calls: toolCalls };
|
|
1244
|
+
const content = choice?.message?.content;
|
|
1245
|
+
if (content && typeof content === "string") {
|
|
1246
|
+
return content;
|
|
1338
1247
|
}
|
|
1339
1248
|
if (attempt === MAX_EMPTY_RETRIES) {
|
|
1340
1249
|
const finishReason = choice?.finish_reason ?? "unknown";
|
|
1250
|
+
const hasToolCalls = Array.isArray(choice?.message?.tool_calls) && choice.message.tool_calls.length > 0;
|
|
1251
|
+
const choicesLen = data?.choices?.length ?? 0;
|
|
1252
|
+
const contentType = content === null ? "null" : content === void 0 ? "undefined" : typeof content;
|
|
1341
1253
|
throw new Error(
|
|
1342
|
-
`Invalid response from model:
|
|
1254
|
+
`Invalid response from model: content=${contentType}, finish_reason=${finishReason}, has_tool_calls=${hasToolCalls}, choices_length=${choicesLen}`
|
|
1343
1255
|
);
|
|
1344
1256
|
}
|
|
1345
1257
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
1346
1258
|
}
|
|
1347
1259
|
throw new Error("Invalid response from model");
|
|
1348
1260
|
}
|
|
1349
|
-
function
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1261
|
+
async function runWarpGrep(config) {
|
|
1262
|
+
const totalStart = Date.now();
|
|
1263
|
+
const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
1264
|
+
const timings = { turns: [], timeout_ms: timeoutMs };
|
|
1265
|
+
const repoRoot = import_path2.default.resolve(config.repoRoot || process.cwd());
|
|
1266
|
+
const model = config.model || DEFAULT_MODEL;
|
|
1267
|
+
const messages = [];
|
|
1268
|
+
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
1269
|
+
const initialStateStart = Date.now();
|
|
1270
|
+
const initialState = await buildInitialState(repoRoot, config.searchTerm, config.provider, { search_type: config.search_type });
|
|
1271
|
+
timings.initial_state_ms = Date.now() - initialStateStart;
|
|
1272
|
+
messages.push({ role: "user", content: initialState });
|
|
1273
|
+
const provider = config.provider;
|
|
1274
|
+
const errors = [];
|
|
1275
|
+
let finishMeta;
|
|
1276
|
+
let terminationReason = "terminated";
|
|
1277
|
+
for (let turn = 1; turn <= maxTurns; turn += 1) {
|
|
1278
|
+
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
1279
|
+
enforceContextLimit(messages);
|
|
1280
|
+
const modelCallStart = Date.now();
|
|
1281
|
+
const assistantContent = await callModel(messages, model, {
|
|
1282
|
+
morphApiKey: config.morphApiKey,
|
|
1283
|
+
morphApiUrl: config.morphApiUrl,
|
|
1284
|
+
retryConfig: config.retryConfig,
|
|
1285
|
+
timeout: timeoutMs,
|
|
1286
|
+
search_type: config.search_type
|
|
1287
|
+
}).catch((e) => {
|
|
1288
|
+
const errMsg = e instanceof Error ? e.message : String(e);
|
|
1289
|
+
console.error(`[warp_grep] Morph API call failed on turn ${turn}:`, errMsg);
|
|
1290
|
+
errors.push({ message: errMsg });
|
|
1291
|
+
return "";
|
|
1292
|
+
});
|
|
1293
|
+
turnMetrics.morph_api_ms = Date.now() - modelCallStart;
|
|
1294
|
+
if (!assistantContent) {
|
|
1295
|
+
console.error(`[warp_grep] Empty response from Morph API on turn ${turn}. Errors so far:`, errors);
|
|
1296
|
+
timings.turns.push(turnMetrics);
|
|
1297
|
+
break;
|
|
1375
1298
|
}
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
});
|
|
1299
|
+
messages.push({ role: "assistant", content: assistantContent });
|
|
1300
|
+
const toolCalls = parser.parse(assistantContent);
|
|
1301
|
+
if (toolCalls.length === 0) {
|
|
1302
|
+
console.error(`[warp_grep] No tool calls parsed on turn ${turn}. Assistant content (first 500 chars):`, assistantContent.slice(0, 500));
|
|
1303
|
+
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" });
|
|
1304
|
+
terminationReason = "terminated";
|
|
1305
|
+
timings.turns.push(turnMetrics);
|
|
1306
|
+
break;
|
|
1381
1307
|
}
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1308
|
+
const finishCalls = toolCalls.filter((c) => c.name === "finish");
|
|
1309
|
+
const grepCalls = toolCalls.filter((c) => c.name === "grep");
|
|
1310
|
+
const listDirCalls = toolCalls.filter((c) => c.name === "list_directory");
|
|
1311
|
+
const readCalls = toolCalls.filter((c) => c.name === "read");
|
|
1312
|
+
const skipCalls = toolCalls.filter((c) => c.name === "_skip");
|
|
1313
|
+
const formatted = [];
|
|
1314
|
+
for (const c of skipCalls) {
|
|
1315
|
+
const msg = c.arguments?.message || "Command skipped due to parsing error";
|
|
1316
|
+
formatted.push(msg);
|
|
1385
1317
|
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1318
|
+
const allPromises = [];
|
|
1319
|
+
for (const c of grepCalls) {
|
|
1320
|
+
const args = c.arguments ?? {};
|
|
1321
|
+
allPromises.push(
|
|
1322
|
+
toolGrep(provider, args).then(
|
|
1323
|
+
({ output }) => formatAgentToolOutput("grep", args, output),
|
|
1324
|
+
(err) => formatAgentToolOutput("grep", args, String(err), { isError: true })
|
|
1325
|
+
)
|
|
1326
|
+
);
|
|
1327
|
+
}
|
|
1328
|
+
for (const c of listDirCalls) {
|
|
1329
|
+
const args = c.arguments ?? {};
|
|
1330
|
+
allPromises.push(
|
|
1331
|
+
toolListDirectory(provider, args).then(
|
|
1332
|
+
(p) => formatAgentToolOutput("list_directory", args, p),
|
|
1333
|
+
(err) => formatAgentToolOutput("list_directory", args, String(err), { isError: true })
|
|
1334
|
+
)
|
|
1335
|
+
);
|
|
1336
|
+
}
|
|
1337
|
+
for (const c of readCalls) {
|
|
1338
|
+
const args = c.arguments ?? {};
|
|
1339
|
+
allPromises.push(
|
|
1340
|
+
toolRead(provider, args).then(
|
|
1341
|
+
(p) => formatAgentToolOutput("read", args, p),
|
|
1342
|
+
(err) => formatAgentToolOutput("read", args, String(err), { isError: true })
|
|
1343
|
+
)
|
|
1344
|
+
);
|
|
1345
|
+
}
|
|
1346
|
+
const toolExecStart = Date.now();
|
|
1347
|
+
const allResults = await Promise.all(allPromises);
|
|
1348
|
+
turnMetrics.local_tools_ms = Date.now() - toolExecStart;
|
|
1349
|
+
for (const result of allResults) {
|
|
1350
|
+
formatted.push(result);
|
|
1351
|
+
}
|
|
1352
|
+
if (formatted.length > 0) {
|
|
1353
|
+
const turnMessage = formatTurnMessage(turn, maxTurns);
|
|
1354
|
+
const contextBudget = calculateContextBudget(messages);
|
|
1355
|
+
messages.push({ role: "user", content: formatted.join("\n") + turnMessage + "\n" + contextBudget });
|
|
1356
|
+
}
|
|
1357
|
+
timings.turns.push(turnMetrics);
|
|
1358
|
+
if (finishCalls.length) {
|
|
1359
|
+
const fc = finishCalls[0];
|
|
1360
|
+
const files = fc.arguments?.files ?? [];
|
|
1361
|
+
const textResult = fc.arguments?.textResult;
|
|
1362
|
+
finishMeta = { files };
|
|
1363
|
+
terminationReason = "completed";
|
|
1364
|
+
if (files.length === 0) {
|
|
1365
|
+
const payload2 = textResult || "No relevant code found.";
|
|
1366
|
+
timings.turns.push(turnMetrics);
|
|
1367
|
+
timings.total_ms = Date.now() - totalStart;
|
|
1368
|
+
return {
|
|
1369
|
+
terminationReason: "completed",
|
|
1370
|
+
messages,
|
|
1371
|
+
finish: { payload: payload2, metadata: finishMeta },
|
|
1372
|
+
timings
|
|
1373
|
+
};
|
|
1374
|
+
}
|
|
1375
|
+
break;
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
if (terminationReason !== "completed" || !finishMeta) {
|
|
1379
|
+
timings.total_ms = Date.now() - totalStart;
|
|
1380
|
+
return { terminationReason, messages, errors, timings };
|
|
1381
|
+
}
|
|
1382
|
+
const parts = ["Relevant context found:"];
|
|
1383
|
+
for (const f of finishMeta.files) {
|
|
1384
|
+
const ranges = f.lines === "*" ? "*" : Array.isArray(f.lines) ? f.lines.map(([s, e]) => `${s}-${e}`).join(", ") : "*";
|
|
1385
|
+
parts.push(`- ${f.path}: ${ranges}`);
|
|
1386
|
+
}
|
|
1387
|
+
const payload = parts.join("\n");
|
|
1388
|
+
const finishResolutionStart = Date.now();
|
|
1389
|
+
const fileReadErrors = [];
|
|
1390
|
+
const resolved = await readFinishFiles(
|
|
1391
|
+
repoRoot,
|
|
1392
|
+
finishMeta.files,
|
|
1393
|
+
async (p, s, e) => {
|
|
1394
|
+
try {
|
|
1395
|
+
const rr = await provider.read({ path: p, start: s, end: e });
|
|
1396
|
+
return rr.lines.map((l) => {
|
|
1397
|
+
const idx = l.indexOf("|");
|
|
1398
|
+
return idx >= 0 ? l.slice(idx + 1) : l;
|
|
1399
|
+
});
|
|
1400
|
+
} catch (err) {
|
|
1401
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
1402
|
+
fileReadErrors.push({ path: p, error: errorMsg });
|
|
1403
|
+
console.error(`[warp_grep] Failed to read file: ${p} - ${errorMsg}`);
|
|
1404
|
+
return [`[couldn't find: ${p}]`];
|
|
1392
1405
|
}
|
|
1393
|
-
return toolRead(provider, readArgs);
|
|
1394
1406
|
}
|
|
1395
|
-
|
|
1396
|
-
|
|
1407
|
+
);
|
|
1408
|
+
timings.finish_resolution_ms = Date.now() - finishResolutionStart;
|
|
1409
|
+
if (fileReadErrors.length > 0) {
|
|
1410
|
+
errors.push(...fileReadErrors.map((e) => ({ message: `File read error: ${e.path} - ${e.error}` })));
|
|
1397
1411
|
}
|
|
1412
|
+
timings.total_ms = Date.now() - totalStart;
|
|
1413
|
+
return {
|
|
1414
|
+
terminationReason: "completed",
|
|
1415
|
+
messages,
|
|
1416
|
+
finish: { payload, metadata: finishMeta, resolved },
|
|
1417
|
+
timings
|
|
1418
|
+
};
|
|
1398
1419
|
}
|
|
1399
1420
|
async function* runWarpGrepStreaming(config) {
|
|
1400
1421
|
const totalStart = Date.now();
|
|
1401
1422
|
const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
1402
1423
|
const timings = { turns: [], timeout_ms: timeoutMs };
|
|
1403
|
-
const repoRoot =
|
|
1424
|
+
const repoRoot = import_path2.default.resolve(config.repoRoot || process.cwd());
|
|
1404
1425
|
const model = config.model || DEFAULT_MODEL;
|
|
1405
1426
|
const messages = [];
|
|
1406
1427
|
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
@@ -1416,7 +1437,7 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1416
1437
|
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
1417
1438
|
enforceContextLimit(messages);
|
|
1418
1439
|
const modelCallStart = Date.now();
|
|
1419
|
-
const
|
|
1440
|
+
const assistantContent = await callModel(messages, model, {
|
|
1420
1441
|
morphApiKey: config.morphApiKey,
|
|
1421
1442
|
morphApiUrl: config.morphApiUrl,
|
|
1422
1443
|
retryConfig: config.retryConfig,
|
|
@@ -1424,45 +1445,90 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1424
1445
|
search_type: config.search_type
|
|
1425
1446
|
}).catch((e) => {
|
|
1426
1447
|
const errMsg = e instanceof Error ? e.message : String(e);
|
|
1427
|
-
console.error(`[warp_grep] Morph API call failed on turn ${turn}:`, errMsg);
|
|
1448
|
+
console.error(`[warp_grep:stream] Morph API call failed on turn ${turn}:`, errMsg);
|
|
1428
1449
|
errors.push({ message: errMsg });
|
|
1429
|
-
return
|
|
1450
|
+
return "";
|
|
1430
1451
|
});
|
|
1431
1452
|
turnMetrics.morph_api_ms = Date.now() - modelCallStart;
|
|
1432
|
-
if (!
|
|
1453
|
+
if (!assistantContent) {
|
|
1454
|
+
console.error(`[warp_grep:stream] Empty response from Morph API on turn ${turn}. Errors so far:`, errors);
|
|
1433
1455
|
timings.turns.push(turnMetrics);
|
|
1434
1456
|
break;
|
|
1435
1457
|
}
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
role: "assistant",
|
|
1439
|
-
content: response.content,
|
|
1440
|
-
...toolCalls.length > 0 ? { tool_calls: toolCalls } : {}
|
|
1441
|
-
});
|
|
1458
|
+
messages.push({ role: "assistant", content: assistantContent });
|
|
1459
|
+
const toolCalls = parser.parse(assistantContent);
|
|
1442
1460
|
if (toolCalls.length === 0) {
|
|
1443
|
-
console.error(`[warp_grep] No tool calls on turn ${turn}.
|
|
1444
|
-
errors.push({ message: "No tool calls produced by the model." });
|
|
1461
|
+
console.error(`[warp_grep:stream] No tool calls parsed on turn ${turn}. Assistant content (first 500 chars):`, assistantContent.slice(0, 500));
|
|
1462
|
+
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" });
|
|
1445
1463
|
terminationReason = "terminated";
|
|
1446
1464
|
timings.turns.push(turnMetrics);
|
|
1447
1465
|
break;
|
|
1448
1466
|
}
|
|
1449
1467
|
yield {
|
|
1450
1468
|
turn,
|
|
1451
|
-
toolCalls: toolCalls.map((
|
|
1452
|
-
name:
|
|
1453
|
-
arguments:
|
|
1469
|
+
toolCalls: toolCalls.map((c) => ({
|
|
1470
|
+
name: c.name,
|
|
1471
|
+
arguments: c.arguments ?? {}
|
|
1454
1472
|
}))
|
|
1455
1473
|
};
|
|
1456
|
-
const
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1474
|
+
const finishCalls = toolCalls.filter((c) => c.name === "finish");
|
|
1475
|
+
const grepCalls = toolCalls.filter((c) => c.name === "grep");
|
|
1476
|
+
const listDirCalls = toolCalls.filter((c) => c.name === "list_directory");
|
|
1477
|
+
const readCalls = toolCalls.filter((c) => c.name === "read");
|
|
1478
|
+
const skipCalls = toolCalls.filter((c) => c.name === "_skip");
|
|
1479
|
+
const formatted = [];
|
|
1480
|
+
for (const c of skipCalls) {
|
|
1481
|
+
const msg = c.arguments?.message || "Command skipped due to parsing error";
|
|
1482
|
+
formatted.push(msg);
|
|
1483
|
+
}
|
|
1484
|
+
const allPromises = [];
|
|
1485
|
+
for (const c of grepCalls) {
|
|
1486
|
+
const args = c.arguments ?? {};
|
|
1487
|
+
allPromises.push(
|
|
1488
|
+
toolGrep(provider, args).then(
|
|
1489
|
+
({ output }) => formatAgentToolOutput("grep", args, output),
|
|
1490
|
+
(err) => formatAgentToolOutput("grep", args, String(err), { isError: true })
|
|
1491
|
+
)
|
|
1492
|
+
);
|
|
1493
|
+
}
|
|
1494
|
+
for (const c of listDirCalls) {
|
|
1495
|
+
const args = c.arguments ?? {};
|
|
1496
|
+
allPromises.push(
|
|
1497
|
+
toolListDirectory(provider, args).then(
|
|
1498
|
+
(p) => formatAgentToolOutput("list_directory", args, p),
|
|
1499
|
+
(err) => formatAgentToolOutput("list_directory", args, String(err), { isError: true })
|
|
1500
|
+
)
|
|
1501
|
+
);
|
|
1502
|
+
}
|
|
1503
|
+
for (const c of readCalls) {
|
|
1504
|
+
const args = c.arguments ?? {};
|
|
1505
|
+
allPromises.push(
|
|
1506
|
+
toolRead(provider, args).then(
|
|
1507
|
+
(p) => formatAgentToolOutput("read", args, p),
|
|
1508
|
+
(err) => formatAgentToolOutput("read", args, String(err), { isError: true })
|
|
1509
|
+
)
|
|
1510
|
+
);
|
|
1511
|
+
}
|
|
1512
|
+
const toolExecStart = Date.now();
|
|
1513
|
+
const allResults = await Promise.all(allPromises);
|
|
1514
|
+
turnMetrics.local_tools_ms = Date.now() - toolExecStart;
|
|
1515
|
+
for (const result of allResults) {
|
|
1516
|
+
formatted.push(result);
|
|
1517
|
+
}
|
|
1518
|
+
if (formatted.length > 0) {
|
|
1519
|
+
const turnMessage = formatTurnMessage(turn, maxTurns);
|
|
1520
|
+
const contextBudget = calculateContextBudget(messages);
|
|
1521
|
+
messages.push({ role: "user", content: formatted.join("\n") + turnMessage + "\n" + contextBudget });
|
|
1522
|
+
}
|
|
1523
|
+
timings.turns.push(turnMetrics);
|
|
1524
|
+
if (finishCalls.length) {
|
|
1525
|
+
const fc = finishCalls[0];
|
|
1526
|
+
const files = fc.arguments?.files ?? [];
|
|
1527
|
+
const textResult = fc.arguments?.textResult;
|
|
1461
1528
|
finishMeta = { files };
|
|
1462
1529
|
terminationReason = "completed";
|
|
1463
1530
|
if (files.length === 0) {
|
|
1464
|
-
const payload2 =
|
|
1465
|
-
timings.turns.push(turnMetrics);
|
|
1531
|
+
const payload2 = textResult || "No relevant code found.";
|
|
1466
1532
|
timings.total_ms = Date.now() - totalStart;
|
|
1467
1533
|
return {
|
|
1468
1534
|
terminationReason: "completed",
|
|
@@ -1471,25 +1537,8 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1471
1537
|
timings
|
|
1472
1538
|
};
|
|
1473
1539
|
}
|
|
1474
|
-
timings.turns.push(turnMetrics);
|
|
1475
1540
|
break;
|
|
1476
1541
|
}
|
|
1477
|
-
const toolExecStart = Date.now();
|
|
1478
|
-
const results = await Promise.all(
|
|
1479
|
-
toolCalls.map(async (tc) => {
|
|
1480
|
-
const args = safeParseJSON(tc.function.arguments);
|
|
1481
|
-
const output = await executeTool(provider, tc.function.name, args, repoRoot).catch((err) => String(err));
|
|
1482
|
-
return { tool_call_id: tc.id, content: output };
|
|
1483
|
-
})
|
|
1484
|
-
);
|
|
1485
|
-
turnMetrics.local_tools_ms = Date.now() - toolExecStart;
|
|
1486
|
-
for (const result of results) {
|
|
1487
|
-
messages.push({ role: "tool", tool_call_id: result.tool_call_id, content: result.content });
|
|
1488
|
-
}
|
|
1489
|
-
const turnMsg = formatTurnMessage(turn, maxTurns);
|
|
1490
|
-
const budget = calculateContextBudget(messages);
|
|
1491
|
-
messages.push({ role: "user", content: turnMsg + "\n" + budget });
|
|
1492
|
-
timings.turns.push(turnMetrics);
|
|
1493
1542
|
}
|
|
1494
1543
|
if (terminationReason !== "completed" || !finishMeta) {
|
|
1495
1544
|
timings.total_ms = Date.now() - totalStart;
|
|
@@ -1533,14 +1582,6 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1533
1582
|
timings
|
|
1534
1583
|
};
|
|
1535
1584
|
}
|
|
1536
|
-
async function runWarpGrep(config) {
|
|
1537
|
-
const gen = runWarpGrepStreaming(config);
|
|
1538
|
-
let result = await gen.next();
|
|
1539
|
-
while (!result.done) {
|
|
1540
|
-
result = await gen.next();
|
|
1541
|
-
}
|
|
1542
|
-
return result.value;
|
|
1543
|
-
}
|
|
1544
1585
|
|
|
1545
1586
|
// tools/warp_grep/providers/remote.ts
|
|
1546
1587
|
init_config();
|
|
@@ -1720,35 +1761,6 @@ var RemoteCommandsProvider = class {
|
|
|
1720
1761
|
return [];
|
|
1721
1762
|
}
|
|
1722
1763
|
}
|
|
1723
|
-
/**
|
|
1724
|
-
* Glob search - finds files matching a pattern.
|
|
1725
|
-
* Falls back to a grep --files approach via the listDir command.
|
|
1726
|
-
*/
|
|
1727
|
-
async glob(params) {
|
|
1728
|
-
const searchPath = params.path || this.repoRoot;
|
|
1729
|
-
try {
|
|
1730
|
-
const stdout = await this.commands.listDir(searchPath, 10);
|
|
1731
|
-
const allPaths = (stdout || "").trim().split(/\r?\n/).filter((p) => p.length > 0);
|
|
1732
|
-
const globToRegex = (glob) => {
|
|
1733
|
-
const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
1734
|
-
return new RegExp(escaped);
|
|
1735
|
-
};
|
|
1736
|
-
const regex = globToRegex(params.pattern);
|
|
1737
|
-
const matched = allPaths.filter((p) => {
|
|
1738
|
-
const name = p.split("/").pop() || "";
|
|
1739
|
-
return regex.test(name) && !shouldSkip(name);
|
|
1740
|
-
});
|
|
1741
|
-
const totalFound = matched.length;
|
|
1742
|
-
return { files: matched.slice(0, 100), searchDir: searchPath, totalFound };
|
|
1743
|
-
} catch (error) {
|
|
1744
|
-
return {
|
|
1745
|
-
files: [],
|
|
1746
|
-
searchDir: searchPath,
|
|
1747
|
-
totalFound: 0,
|
|
1748
|
-
error: `[GLOB ERROR] ${error instanceof Error ? error.message : String(error)}`
|
|
1749
|
-
};
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
1764
|
};
|
|
1753
1765
|
|
|
1754
1766
|
// tools/warp_grep/providers/code_storage_http.ts
|
|
@@ -1775,9 +1787,9 @@ function createCodeStorageHttpCommands(config) {
|
|
|
1775
1787
|
const { baseUrl, repoId, branch } = config;
|
|
1776
1788
|
const encodedRepoId = encodeURIComponent(repoId);
|
|
1777
1789
|
return {
|
|
1778
|
-
grep: (pattern,
|
|
1779
|
-
read: (
|
|
1780
|
-
listDir: (
|
|
1790
|
+
grep: (pattern, path5, glob) => post(`${baseUrl}/api/code-search/${encodedRepoId}/grep`, { pattern, path: path5, glob, branch }, "grep"),
|
|
1791
|
+
read: (path5, start, end) => post(`${baseUrl}/api/code-search/${encodedRepoId}/read`, { path: path5, start, end, branch }, "read"),
|
|
1792
|
+
listDir: (path5, maxDepth) => post(`${baseUrl}/api/code-search/${encodedRepoId}/list`, { path: path5, maxDepth, branch }, "list")
|
|
1781
1793
|
};
|
|
1782
1794
|
}
|
|
1783
1795
|
|