@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
|
});
|
|
@@ -592,131 +633,58 @@ module.exports = __toCommonJS(anthropic_exports);
|
|
|
592
633
|
init_config();
|
|
593
634
|
|
|
594
635
|
// tools/warp_grep/agent/parser.ts
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
636
|
+
function parseReadLines(linesStr) {
|
|
637
|
+
const ranges = [];
|
|
638
|
+
for (const rangeStr of linesStr.split(",")) {
|
|
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 {};
|
|
598
651
|
}
|
|
599
|
-
function
|
|
600
|
-
const
|
|
601
|
-
const
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
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();
|
|
652
|
+
function parseFinishFiles(filesStr) {
|
|
653
|
+
const files = [];
|
|
654
|
+
for (const line of filesStr.trim().split(/\s+/)) {
|
|
655
|
+
const trimmed = line.trim();
|
|
656
|
+
if (!trimmed) continue;
|
|
657
|
+
const colonIdx = trimmed.indexOf(":");
|
|
658
|
+
if (colonIdx === -1) {
|
|
659
|
+
files.push({ path: trimmed, lines: "*" });
|
|
660
|
+
continue;
|
|
612
661
|
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
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 } });
|
|
662
|
+
const filePath = trimmed.slice(0, colonIdx);
|
|
663
|
+
const rangesPart = trimmed.slice(colonIdx + 1);
|
|
664
|
+
if (!rangesPart.trim() || rangesPart.trim() === "*") {
|
|
665
|
+
files.push({ path: filePath, lines: "*" });
|
|
666
|
+
continue;
|
|
667
|
+
}
|
|
668
|
+
const ranges = [];
|
|
669
|
+
for (const rangeStr of rangesPart.split(",")) {
|
|
670
|
+
const rt = rangeStr.trim();
|
|
671
|
+
if (!rt) continue;
|
|
672
|
+
const parts = rt.split("-").map((v) => parseInt(v.trim(), 10));
|
|
673
|
+
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
674
|
+
ranges.push([parts[0], parts[1]]);
|
|
675
|
+
} else if (Number.isFinite(parts[0])) {
|
|
676
|
+
ranges.push([parts[0], parts[0]]);
|
|
706
677
|
}
|
|
707
678
|
}
|
|
679
|
+
files.push({ path: filePath, lines: ranges.length > 0 ? ranges : "*" });
|
|
708
680
|
}
|
|
709
|
-
return
|
|
681
|
+
return files;
|
|
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] || ".";
|
|
710
687
|
}
|
|
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
|
-
};
|
|
720
688
|
|
|
721
689
|
// tools/warp_grep/agent/tools/grep.ts
|
|
722
690
|
async function toolGrep(provider, args) {
|
|
@@ -767,29 +735,42 @@ async function toolRead(provider, args) {
|
|
|
767
735
|
|
|
768
736
|
// tools/warp_grep/agent/tools/list_directory.ts
|
|
769
737
|
init_config();
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
const
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
738
|
+
var import_path = __toESM(require("path"), 1);
|
|
739
|
+
async function toolListDirectory(provider, args, repoRoot) {
|
|
740
|
+
const maxResults = args.maxResults ?? AGENT_CONFIG.MAX_LIST_RESULTS;
|
|
741
|
+
const maxDepth = args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
742
|
+
const entries = await provider.listDirectory({
|
|
743
|
+
path: args.path,
|
|
744
|
+
pattern: args.pattern ?? null,
|
|
745
|
+
maxResults,
|
|
746
|
+
maxDepth
|
|
747
|
+
});
|
|
748
|
+
if (!entries.length) return "empty";
|
|
749
|
+
if (repoRoot) {
|
|
750
|
+
const absRoot = import_path.default.resolve(repoRoot);
|
|
751
|
+
const lines = entries.map((e) => import_path.default.join(absRoot, e.path));
|
|
752
|
+
return lines.join("\n");
|
|
753
|
+
}
|
|
754
|
+
return entries.map((e) => e.path).join("\n");
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// tools/warp_grep/agent/tools/glob.ts
|
|
758
|
+
async function toolGlob(provider, args) {
|
|
759
|
+
const res = await provider.glob(args);
|
|
760
|
+
if (res.error) {
|
|
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}`;
|
|
793
774
|
}
|
|
794
775
|
|
|
795
776
|
// tools/warp_grep/agent/tools/finish.ts
|
|
@@ -850,32 +831,21 @@ function mergeRanges(ranges) {
|
|
|
850
831
|
return merged;
|
|
851
832
|
}
|
|
852
833
|
|
|
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 "";
|
|
859
|
-
}
|
|
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>`;
|
|
868
|
-
}
|
|
869
|
-
};
|
|
870
|
-
var sharedFormatter = new ToolOutputFormatter();
|
|
871
|
-
function formatAgentToolOutput(toolName, args, output, options = {}) {
|
|
872
|
-
return sharedFormatter.format(toolName, args, output, options);
|
|
873
|
-
}
|
|
874
|
-
|
|
875
834
|
// tools/warp_grep/agent/helpers.ts
|
|
876
|
-
var
|
|
835
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
877
836
|
init_config();
|
|
878
837
|
var TRUNCATED_MARKER = "[truncated for context limit]";
|
|
838
|
+
function getMessageSize(m) {
|
|
839
|
+
if (m.role === "tool") return m.content.length;
|
|
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);
|
|
844
|
+
}
|
|
845
|
+
return size;
|
|
846
|
+
}
|
|
847
|
+
return m.content.length;
|
|
848
|
+
}
|
|
879
849
|
function formatTurnMessage(turnsUsed, maxTurns) {
|
|
880
850
|
const turnsRemaining = maxTurns - turnsUsed;
|
|
881
851
|
if (turnsRemaining === 1) {
|
|
@@ -886,33 +856,30 @@ You have used ${turnsUsed} turns, you only have 1 turn remaining. You have run o
|
|
|
886
856
|
You have used ${turnsUsed} turn${turnsUsed === 1 ? "" : "s"} and have ${turnsRemaining} remaining`;
|
|
887
857
|
}
|
|
888
858
|
function calculateContextBudget(messages) {
|
|
889
|
-
const totalChars = messages.reduce((sum, m) => sum + m
|
|
859
|
+
const totalChars = messages.reduce((sum, m) => sum + getMessageSize(m), 0);
|
|
890
860
|
const maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS;
|
|
891
|
-
const percent = Math.
|
|
892
|
-
const usedK = Math.
|
|
893
|
-
const maxK = Math.
|
|
894
|
-
return `<context_budget>${percent}% (${usedK}K/${maxK}K chars
|
|
861
|
+
const percent = Math.floor(totalChars / maxChars * 100);
|
|
862
|
+
const usedK = Math.floor(totalChars / 1e3);
|
|
863
|
+
const maxK = Math.floor(maxChars / 1e3);
|
|
864
|
+
return `<context_budget>${percent}% (${usedK}K/${maxK}K chars)</context_budget>`;
|
|
895
865
|
}
|
|
896
866
|
async function buildInitialState(repoRoot, searchTerm, provider, options) {
|
|
897
867
|
const budget = calculateContextBudget([]);
|
|
898
|
-
const turnTag = `
|
|
868
|
+
const turnTag = `You have used 0 turns and have ${AGENT_CONFIG.MAX_TURNS} remaining`;
|
|
899
869
|
const treeDepth = options?.search_type === "node_modules" ? 1 : 2;
|
|
870
|
+
const absRoot = import_path2.default.resolve(repoRoot);
|
|
900
871
|
try {
|
|
901
872
|
const entries = await provider.listDirectory({
|
|
902
873
|
path: ".",
|
|
903
874
|
maxResults: AGENT_CONFIG.MAX_OUTPUT_LINES,
|
|
904
875
|
maxDepth: treeDepth
|
|
905
876
|
});
|
|
906
|
-
const
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
});
|
|
911
|
-
const repoName = import_path.default.basename(repoRoot);
|
|
912
|
-
const treeOutput = treeLines.length > 0 ? `${repoName}/
|
|
913
|
-
${treeLines.join("\n")}` : `${repoName}/`;
|
|
877
|
+
const lines = [absRoot];
|
|
878
|
+
for (const e of entries) {
|
|
879
|
+
lines.push(import_path2.default.join(absRoot, e.path));
|
|
880
|
+
}
|
|
914
881
|
return `<repo_structure>
|
|
915
|
-
${
|
|
882
|
+
${lines.join("\n")}
|
|
916
883
|
</repo_structure>
|
|
917
884
|
|
|
918
885
|
<search_string>
|
|
@@ -921,9 +888,8 @@ ${searchTerm}
|
|
|
921
888
|
${budget}
|
|
922
889
|
${turnTag}`;
|
|
923
890
|
} catch {
|
|
924
|
-
const repoName = import_path.default.basename(repoRoot);
|
|
925
891
|
return `<repo_structure>
|
|
926
|
-
${
|
|
892
|
+
${absRoot}
|
|
927
893
|
</repo_structure>
|
|
928
894
|
|
|
929
895
|
<search_string>
|
|
@@ -934,26 +900,32 @@ ${turnTag}`;
|
|
|
934
900
|
}
|
|
935
901
|
}
|
|
936
902
|
function enforceContextLimit(messages, maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS) {
|
|
937
|
-
const getTotalChars = () => messages.reduce((sum, m) => sum + m
|
|
903
|
+
const getTotalChars = () => messages.reduce((sum, m) => sum + getMessageSize(m), 0);
|
|
938
904
|
if (getTotalChars() <= maxChars) {
|
|
939
905
|
return messages;
|
|
940
906
|
}
|
|
941
|
-
const
|
|
907
|
+
const truncatableIndices = [];
|
|
942
908
|
let firstUserSkipped = false;
|
|
943
909
|
for (let i = 0; i < messages.length; i++) {
|
|
944
|
-
|
|
910
|
+
const m = messages[i];
|
|
911
|
+
if (m.role === "tool") {
|
|
912
|
+
truncatableIndices.push(i);
|
|
913
|
+
} else if (m.role === "user") {
|
|
945
914
|
if (!firstUserSkipped) {
|
|
946
915
|
firstUserSkipped = true;
|
|
947
916
|
continue;
|
|
948
917
|
}
|
|
949
|
-
|
|
918
|
+
truncatableIndices.push(i);
|
|
950
919
|
}
|
|
951
920
|
}
|
|
952
|
-
for (const idx of
|
|
921
|
+
for (const idx of truncatableIndices) {
|
|
953
922
|
if (getTotalChars() <= maxChars) {
|
|
954
923
|
break;
|
|
955
924
|
}
|
|
956
|
-
|
|
925
|
+
const m = messages[idx];
|
|
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) {
|
|
957
929
|
messages[idx] = { role: "user", content: TRUNCATED_MARKER };
|
|
958
930
|
}
|
|
959
931
|
}
|
|
@@ -966,7 +938,7 @@ var import_openai = __toESM(require("openai"), 1);
|
|
|
966
938
|
// package.json
|
|
967
939
|
var package_default = {
|
|
968
940
|
name: "@morphllm/morphsdk",
|
|
969
|
-
version: "0.2.
|
|
941
|
+
version: "0.2.148",
|
|
970
942
|
description: "TypeScript SDK and CLI for Morph Fast Apply integration",
|
|
971
943
|
type: "module",
|
|
972
944
|
main: "./dist/index.cjs",
|
|
@@ -1205,9 +1177,115 @@ var package_default = {
|
|
|
1205
1177
|
var SDK_VERSION = package_default.version;
|
|
1206
1178
|
|
|
1207
1179
|
// tools/warp_grep/agent/runner.ts
|
|
1208
|
-
var
|
|
1209
|
-
var parser = new LLMResponseParser();
|
|
1180
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
1210
1181
|
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
|
+
];
|
|
1211
1289
|
async function callModel(messages, model, options = {}) {
|
|
1212
1290
|
const baseUrl = options.morphApiUrl || DEFAULT_API_URL;
|
|
1213
1291
|
const apiKey = options.morphApiKey || process.env.MORPH_API_KEY || "";
|
|
@@ -1228,8 +1306,9 @@ async function callModel(messages, model, options = {}) {
|
|
|
1228
1306
|
data = await client.chat.completions.create({
|
|
1229
1307
|
model,
|
|
1230
1308
|
temperature: 0,
|
|
1231
|
-
max_tokens:
|
|
1309
|
+
max_tokens: 2048,
|
|
1232
1310
|
messages,
|
|
1311
|
+
tools: TOOL_SPECS,
|
|
1233
1312
|
...options.search_type ? { search_type: options.search_type } : {}
|
|
1234
1313
|
});
|
|
1235
1314
|
} catch (error) {
|
|
@@ -1241,187 +1320,87 @@ async function callModel(messages, model, options = {}) {
|
|
|
1241
1320
|
throw error;
|
|
1242
1321
|
}
|
|
1243
1322
|
const choice = data?.choices?.[0];
|
|
1244
|
-
const
|
|
1245
|
-
if (
|
|
1246
|
-
|
|
1323
|
+
const message = choice?.message;
|
|
1324
|
+
if (!message) {
|
|
1325
|
+
if (attempt === MAX_EMPTY_RETRIES) {
|
|
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 };
|
|
1247
1338
|
}
|
|
1248
1339
|
if (attempt === MAX_EMPTY_RETRIES) {
|
|
1249
1340
|
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;
|
|
1253
1341
|
throw new Error(
|
|
1254
|
-
`Invalid response from model: content
|
|
1342
|
+
`Invalid response from model: no content and no tool_calls, finish_reason=${finishReason}`
|
|
1255
1343
|
);
|
|
1256
1344
|
}
|
|
1257
1345
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
1258
1346
|
}
|
|
1259
1347
|
throw new Error("Invalid response from model");
|
|
1260
1348
|
}
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
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;
|
|
1298
|
-
}
|
|
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;
|
|
1307
|
-
}
|
|
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);
|
|
1317
|
-
}
|
|
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);
|
|
1349
|
+
function safeParseJSON(s) {
|
|
1350
|
+
try {
|
|
1351
|
+
return JSON.parse(s);
|
|
1352
|
+
} catch {
|
|
1353
|
+
return {};
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
async function executeTool(provider, name, args, repoRoot) {
|
|
1357
|
+
switch (name) {
|
|
1358
|
+
case "grep_search": {
|
|
1359
|
+
const grepArgs = {
|
|
1360
|
+
pattern: args.pattern,
|
|
1361
|
+
path: args.path || "."
|
|
1362
|
+
};
|
|
1363
|
+
if (args.glob) grepArgs.glob = args.glob;
|
|
1364
|
+
if (args.case_sensitive !== void 0) grepArgs.case_sensitive = args.case_sensitive;
|
|
1365
|
+
const result = await toolGrep(provider, grepArgs);
|
|
1366
|
+
let output = result.output;
|
|
1367
|
+
if (args.limit && typeof args.limit === "number") {
|
|
1368
|
+
const lines = output.split("\n");
|
|
1369
|
+
if (lines.length > args.limit) {
|
|
1370
|
+
output = lines.slice(0, args.limit).join("\n") + `
|
|
1371
|
+
... (truncated at ${args.limit} lines)`;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
return output;
|
|
1351
1375
|
}
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1376
|
+
case "glob": {
|
|
1377
|
+
return toolGlob(provider, {
|
|
1378
|
+
pattern: args.pattern,
|
|
1379
|
+
path: args.path
|
|
1380
|
+
});
|
|
1356
1381
|
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
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;
|
|
1382
|
+
case "list_directory": {
|
|
1383
|
+
const dirPath = extractPathFromCommand(args.command || ".");
|
|
1384
|
+
return toolListDirectory(provider, { path: dirPath }, repoRoot);
|
|
1376
1385
|
}
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
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}]`];
|
|
1386
|
+
case "read": {
|
|
1387
|
+
const readArgs = {
|
|
1388
|
+
path: args.path
|
|
1389
|
+
};
|
|
1390
|
+
if (args.lines && typeof args.lines === "string") {
|
|
1391
|
+
Object.assign(readArgs, parseReadLines(args.lines));
|
|
1405
1392
|
}
|
|
1393
|
+
return toolRead(provider, readArgs);
|
|
1406
1394
|
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
if (fileReadErrors.length > 0) {
|
|
1410
|
-
errors.push(...fileReadErrors.map((e) => ({ message: `File read error: ${e.path} - ${e.error}` })));
|
|
1395
|
+
default:
|
|
1396
|
+
return `Unknown tool: ${name}`;
|
|
1411
1397
|
}
|
|
1412
|
-
timings.total_ms = Date.now() - totalStart;
|
|
1413
|
-
return {
|
|
1414
|
-
terminationReason: "completed",
|
|
1415
|
-
messages,
|
|
1416
|
-
finish: { payload, metadata: finishMeta, resolved },
|
|
1417
|
-
timings
|
|
1418
|
-
};
|
|
1419
1398
|
}
|
|
1420
1399
|
async function* runWarpGrepStreaming(config) {
|
|
1421
1400
|
const totalStart = Date.now();
|
|
1422
1401
|
const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
1423
1402
|
const timings = { turns: [], timeout_ms: timeoutMs };
|
|
1424
|
-
const repoRoot =
|
|
1403
|
+
const repoRoot = import_path3.default.resolve(config.repoRoot || process.cwd());
|
|
1425
1404
|
const model = config.model || DEFAULT_MODEL;
|
|
1426
1405
|
const messages = [];
|
|
1427
1406
|
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
@@ -1437,7 +1416,7 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1437
1416
|
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
1438
1417
|
enforceContextLimit(messages);
|
|
1439
1418
|
const modelCallStart = Date.now();
|
|
1440
|
-
const
|
|
1419
|
+
const response = await callModel(messages, model, {
|
|
1441
1420
|
morphApiKey: config.morphApiKey,
|
|
1442
1421
|
morphApiUrl: config.morphApiUrl,
|
|
1443
1422
|
retryConfig: config.retryConfig,
|
|
@@ -1445,90 +1424,45 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1445
1424
|
search_type: config.search_type
|
|
1446
1425
|
}).catch((e) => {
|
|
1447
1426
|
const errMsg = e instanceof Error ? e.message : String(e);
|
|
1448
|
-
console.error(`[warp_grep
|
|
1427
|
+
console.error(`[warp_grep] Morph API call failed on turn ${turn}:`, errMsg);
|
|
1449
1428
|
errors.push({ message: errMsg });
|
|
1450
|
-
return
|
|
1429
|
+
return null;
|
|
1451
1430
|
});
|
|
1452
1431
|
turnMetrics.morph_api_ms = Date.now() - modelCallStart;
|
|
1453
|
-
if (!
|
|
1454
|
-
console.error(`[warp_grep:stream] Empty response from Morph API on turn ${turn}. Errors so far:`, errors);
|
|
1432
|
+
if (!response) {
|
|
1455
1433
|
timings.turns.push(turnMetrics);
|
|
1456
1434
|
break;
|
|
1457
1435
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1436
|
+
const toolCalls = response.tool_calls;
|
|
1437
|
+
messages.push({
|
|
1438
|
+
role: "assistant",
|
|
1439
|
+
content: response.content,
|
|
1440
|
+
...toolCalls.length > 0 ? { tool_calls: toolCalls } : {}
|
|
1441
|
+
});
|
|
1460
1442
|
if (toolCalls.length === 0) {
|
|
1461
|
-
console.error(`[warp_grep
|
|
1462
|
-
errors.push({ message: "No tool calls produced by the model.
|
|
1443
|
+
console.error(`[warp_grep] No tool calls on turn ${turn}. Content: ${(response.content || "").slice(0, 500)}`);
|
|
1444
|
+
errors.push({ message: "No tool calls produced by the model." });
|
|
1463
1445
|
terminationReason = "terminated";
|
|
1464
1446
|
timings.turns.push(turnMetrics);
|
|
1465
1447
|
break;
|
|
1466
1448
|
}
|
|
1467
1449
|
yield {
|
|
1468
1450
|
turn,
|
|
1469
|
-
toolCalls: toolCalls.map((
|
|
1470
|
-
name:
|
|
1471
|
-
arguments:
|
|
1451
|
+
toolCalls: toolCalls.map((tc) => ({
|
|
1452
|
+
name: tc.function.name,
|
|
1453
|
+
arguments: safeParseJSON(tc.function.arguments)
|
|
1472
1454
|
}))
|
|
1473
1455
|
};
|
|
1474
|
-
const
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
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;
|
|
1456
|
+
const finishCall = toolCalls.find((tc) => tc.function.name === "finish");
|
|
1457
|
+
if (finishCall) {
|
|
1458
|
+
const args = safeParseJSON(finishCall.function.arguments);
|
|
1459
|
+
const filesStr = args.files || "";
|
|
1460
|
+
const files = parseFinishFiles(filesStr);
|
|
1528
1461
|
finishMeta = { files };
|
|
1529
1462
|
terminationReason = "completed";
|
|
1530
1463
|
if (files.length === 0) {
|
|
1531
|
-
const payload2 =
|
|
1464
|
+
const payload2 = filesStr || "No relevant code found.";
|
|
1465
|
+
timings.turns.push(turnMetrics);
|
|
1532
1466
|
timings.total_ms = Date.now() - totalStart;
|
|
1533
1467
|
return {
|
|
1534
1468
|
terminationReason: "completed",
|
|
@@ -1537,8 +1471,25 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1537
1471
|
timings
|
|
1538
1472
|
};
|
|
1539
1473
|
}
|
|
1474
|
+
timings.turns.push(turnMetrics);
|
|
1540
1475
|
break;
|
|
1541
1476
|
}
|
|
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);
|
|
1542
1493
|
}
|
|
1543
1494
|
if (terminationReason !== "completed" || !finishMeta) {
|
|
1544
1495
|
timings.total_ms = Date.now() - totalStart;
|
|
@@ -1556,17 +1507,22 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1556
1507
|
repoRoot,
|
|
1557
1508
|
finishMeta.files,
|
|
1558
1509
|
async (p, s, e) => {
|
|
1510
|
+
let resolvedPath = p;
|
|
1511
|
+
if (!p.startsWith(repoRoot)) {
|
|
1512
|
+
const relative = p.startsWith("/") ? p.slice(1) : p;
|
|
1513
|
+
resolvedPath = import_path3.default.join(repoRoot, relative);
|
|
1514
|
+
}
|
|
1559
1515
|
try {
|
|
1560
|
-
const rr = await provider.read({ path:
|
|
1516
|
+
const rr = await provider.read({ path: resolvedPath, start: s, end: e });
|
|
1561
1517
|
return rr.lines.map((l) => {
|
|
1562
1518
|
const idx = l.indexOf("|");
|
|
1563
1519
|
return idx >= 0 ? l.slice(idx + 1) : l;
|
|
1564
1520
|
});
|
|
1565
1521
|
} catch (err) {
|
|
1566
1522
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
1567
|
-
fileReadErrors.push({ path:
|
|
1568
|
-
console.error(`[warp_grep] Failed to read file: ${
|
|
1569
|
-
return [`[couldn't find: ${
|
|
1523
|
+
fileReadErrors.push({ path: resolvedPath, error: errorMsg });
|
|
1524
|
+
console.error(`[warp_grep] Failed to read file: ${resolvedPath} - ${errorMsg}`);
|
|
1525
|
+
return [`[couldn't find: ${resolvedPath}]`];
|
|
1570
1526
|
}
|
|
1571
1527
|
}
|
|
1572
1528
|
);
|
|
@@ -1582,6 +1538,14 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1582
1538
|
timings
|
|
1583
1539
|
};
|
|
1584
1540
|
}
|
|
1541
|
+
async function runWarpGrep(config) {
|
|
1542
|
+
const gen = runWarpGrepStreaming(config);
|
|
1543
|
+
let result = await gen.next();
|
|
1544
|
+
while (!result.done) {
|
|
1545
|
+
result = await gen.next();
|
|
1546
|
+
}
|
|
1547
|
+
return result.value;
|
|
1548
|
+
}
|
|
1585
1549
|
|
|
1586
1550
|
// tools/warp_grep/providers/remote.ts
|
|
1587
1551
|
init_config();
|
|
@@ -1761,6 +1725,35 @@ var RemoteCommandsProvider = class {
|
|
|
1761
1725
|
return [];
|
|
1762
1726
|
}
|
|
1763
1727
|
}
|
|
1728
|
+
/**
|
|
1729
|
+
* Glob search - finds files matching a pattern.
|
|
1730
|
+
* Falls back to a grep --files approach via the listDir command.
|
|
1731
|
+
*/
|
|
1732
|
+
async glob(params) {
|
|
1733
|
+
const searchPath = params.path || this.repoRoot;
|
|
1734
|
+
try {
|
|
1735
|
+
const stdout = await this.commands.listDir(searchPath, 10);
|
|
1736
|
+
const allPaths = (stdout || "").trim().split(/\r?\n/).filter((p) => p.length > 0);
|
|
1737
|
+
const globToRegex = (glob) => {
|
|
1738
|
+
const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
1739
|
+
return new RegExp(escaped);
|
|
1740
|
+
};
|
|
1741
|
+
const regex = globToRegex(params.pattern);
|
|
1742
|
+
const matched = allPaths.filter((p) => {
|
|
1743
|
+
const name = p.split("/").pop() || "";
|
|
1744
|
+
return regex.test(name) && !shouldSkip(name);
|
|
1745
|
+
});
|
|
1746
|
+
const totalFound = matched.length;
|
|
1747
|
+
return { files: matched.slice(0, 100), searchDir: searchPath, totalFound };
|
|
1748
|
+
} catch (error) {
|
|
1749
|
+
return {
|
|
1750
|
+
files: [],
|
|
1751
|
+
searchDir: searchPath,
|
|
1752
|
+
totalFound: 0,
|
|
1753
|
+
error: `[GLOB ERROR] ${error instanceof Error ? error.message : String(error)}`
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1764
1757
|
};
|
|
1765
1758
|
|
|
1766
1759
|
// tools/warp_grep/providers/code_storage_http.ts
|
|
@@ -1787,9 +1780,9 @@ function createCodeStorageHttpCommands(config) {
|
|
|
1787
1780
|
const { baseUrl, repoId, branch } = config;
|
|
1788
1781
|
const encodedRepoId = encodeURIComponent(repoId);
|
|
1789
1782
|
return {
|
|
1790
|
-
grep: (pattern,
|
|
1791
|
-
read: (
|
|
1792
|
-
listDir: (
|
|
1783
|
+
grep: (pattern, path6, glob) => post(`${baseUrl}/api/code-search/${encodedRepoId}/grep`, { pattern, path: path6, glob, branch }, "grep"),
|
|
1784
|
+
read: (path6, start, end) => post(`${baseUrl}/api/code-search/${encodedRepoId}/read`, { path: path6, start, end, branch }, "read"),
|
|
1785
|
+
listDir: (path6, maxDepth) => post(`${baseUrl}/api/code-search/${encodedRepoId}/list`, { path: path6, maxDepth, branch }, "list")
|
|
1793
1786
|
};
|
|
1794
1787
|
}
|
|
1795
1788
|
|