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