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