@morphllm/morphsdk 0.2.101 → 0.2.103
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-TIPPVPZV.js → chunk-25APYVON.js} +2 -2
- package/dist/chunk-2MAUPERG.js +129 -0
- package/dist/chunk-2MAUPERG.js.map +1 -0
- package/dist/{chunk-QH4BSXOD.js → chunk-4CZPXV6R.js} +8 -7
- package/dist/chunk-4CZPXV6R.js.map +1 -0
- package/dist/{chunk-5VVF4NH6.js → chunk-4IOC2D5Y.js} +2 -1
- package/dist/chunk-4IOC2D5Y.js.map +1 -0
- package/dist/{chunk-AIXF4GQC.js → chunk-AFLEE2PO.js} +2 -2
- package/dist/{chunk-CP4NZGRY.js → chunk-EMMSRY32.js} +3 -3
- package/dist/chunk-EMMSRY32.js.map +1 -0
- package/dist/{chunk-QZNGKOCZ.js → chunk-HDRLLCAD.js} +4 -4
- package/dist/{chunk-BKIM7SNY.js → chunk-I3IN742Q.js} +4 -4
- package/dist/{chunk-7UYDS6OX.js → chunk-KQP6ZPYB.js} +4 -4
- package/dist/{chunk-VJU3BRET.js → chunk-LE66XCOI.js} +1 -1
- package/dist/chunk-LE66XCOI.js.map +1 -0
- package/dist/{chunk-OTPYEYMZ.js → chunk-MY4OU4ON.js} +2 -2
- package/dist/{chunk-UBX7QYBD.js → chunk-O5DA5V5S.js} +4 -4
- package/dist/{chunk-GJU7UOFL.js → chunk-OUEJ6XEO.js} +4 -4
- package/dist/{chunk-IP7OGZMD.js → chunk-QOEZARHG.js} +2 -2
- package/dist/{chunk-L5WXPMCH.js → chunk-QUIGATZE.js} +2 -2
- package/dist/{chunk-3R7IF4U5.js → chunk-SITZC3U6.js} +2 -2
- package/dist/chunk-TLC3QKE6.js +114 -0
- package/dist/chunk-TLC3QKE6.js.map +1 -0
- package/dist/{chunk-ZMQI7MNC.js → chunk-Y2OTK5WC.js} +17 -17
- package/dist/chunk-Y2OTK5WC.js.map +1 -0
- package/dist/{chunk-4KMBU6T3.js → chunk-YJZP5ZL5.js} +4 -4
- package/dist/{chunk-76DJEQEP.js → chunk-ZRLEAPZV.js} +4 -4
- package/dist/{chunk-BGEEES52.js → chunk-ZROQPUCQ.js} +7 -7
- package/dist/client.cjs +2922 -2839
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +1 -0
- package/dist/client.js +20 -23
- package/dist/edge.cjs +437 -0
- package/dist/edge.cjs.map +1 -0
- package/dist/edge.d.ts +5 -0
- package/dist/edge.js +25 -0
- package/dist/edge.js.map +1 -0
- package/dist/git/client.cjs.map +1 -1
- package/dist/git/client.js +1 -1
- package/dist/git/index.cjs.map +1 -1
- package/dist/git/index.js +1 -1
- package/dist/index.cjs +1982 -1888
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +30 -28
- package/dist/modelrouter/core.cjs +2 -2
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.js +1 -1
- package/dist/modelrouter/index.cjs +2 -2
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.js +1 -1
- package/dist/tools/browser/anthropic.cjs.map +1 -1
- package/dist/tools/browser/anthropic.js +2 -2
- package/dist/tools/browser/core.cjs +1 -0
- package/dist/tools/browser/core.cjs.map +1 -1
- package/dist/tools/browser/core.js +1 -1
- package/dist/tools/browser/index.cjs +1 -0
- package/dist/tools/browser/index.cjs.map +1 -1
- package/dist/tools/browser/index.js +6 -6
- package/dist/tools/browser/openai.cjs.map +1 -1
- package/dist/tools/browser/openai.js +2 -2
- package/dist/tools/browser/types.cjs.map +1 -1
- package/dist/tools/browser/types.d.ts +2 -0
- package/dist/tools/browser/vercel.cjs.map +1 -1
- package/dist/tools/browser/vercel.js +2 -2
- package/dist/tools/codebase_search/anthropic.js +2 -2
- package/dist/tools/codebase_search/index.js +6 -6
- package/dist/tools/codebase_search/openai.js +2 -2
- package/dist/tools/codebase_search/vercel.js +2 -2
- package/dist/tools/fastapply/anthropic.cjs +109 -40
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +3 -2
- package/dist/tools/fastapply/apply.cjs +227 -0
- package/dist/tools/fastapply/apply.cjs.map +1 -0
- package/dist/tools/fastapply/apply.d.ts +59 -0
- package/dist/tools/fastapply/apply.js +15 -0
- package/dist/tools/fastapply/apply.js.map +1 -0
- package/dist/tools/fastapply/core.cjs +156 -116
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.d.ts +5 -41
- package/dist/tools/fastapply/core.js +6 -2
- package/dist/tools/fastapply/index.cjs +113 -76
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.d.ts +2 -1
- package/dist/tools/fastapply/index.js +11 -9
- package/dist/tools/fastapply/openai.cjs +110 -41
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +3 -2
- package/dist/tools/fastapply/vercel.cjs +110 -41
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.js +3 -2
- package/dist/tools/index.cjs +113 -76
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.js +11 -9
- package/dist/tools/warp_grep/agent/runner.js +3 -3
- package/dist/tools/warp_grep/anthropic.cjs +549 -500
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.js +5 -9
- package/dist/tools/warp_grep/client.cjs +550 -501
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.js +4 -8
- package/dist/tools/warp_grep/gemini.cjs +549 -500
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.js +4 -8
- package/dist/tools/warp_grep/gemini.js.map +1 -1
- package/dist/tools/warp_grep/harness.js +12 -12
- package/dist/tools/warp_grep/index.cjs +559 -501
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.js +12 -12
- package/dist/tools/warp_grep/openai.cjs +549 -500
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.js +5 -9
- package/dist/tools/warp_grep/providers/local.js +2 -2
- package/dist/tools/warp_grep/vercel.cjs +549 -500
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.js +5 -9
- package/package.json +7 -2
- package/dist/chunk-5VVF4NH6.js.map +0 -1
- package/dist/chunk-CKTA4AXM.js +0 -233
- package/dist/chunk-CKTA4AXM.js.map +0 -1
- package/dist/chunk-CP4NZGRY.js.map +0 -1
- package/dist/chunk-QH4BSXOD.js.map +0 -1
- package/dist/chunk-VJU3BRET.js.map +0 -1
- package/dist/chunk-ZMQI7MNC.js.map +0 -1
- /package/dist/{chunk-TIPPVPZV.js.map → chunk-25APYVON.js.map} +0 -0
- /package/dist/{chunk-AIXF4GQC.js.map → chunk-AFLEE2PO.js.map} +0 -0
- /package/dist/{chunk-QZNGKOCZ.js.map → chunk-HDRLLCAD.js.map} +0 -0
- /package/dist/{chunk-BKIM7SNY.js.map → chunk-I3IN742Q.js.map} +0 -0
- /package/dist/{chunk-7UYDS6OX.js.map → chunk-KQP6ZPYB.js.map} +0 -0
- /package/dist/{chunk-OTPYEYMZ.js.map → chunk-MY4OU4ON.js.map} +0 -0
- /package/dist/{chunk-UBX7QYBD.js.map → chunk-O5DA5V5S.js.map} +0 -0
- /package/dist/{chunk-GJU7UOFL.js.map → chunk-OUEJ6XEO.js.map} +0 -0
- /package/dist/{chunk-IP7OGZMD.js.map → chunk-QOEZARHG.js.map} +0 -0
- /package/dist/{chunk-L5WXPMCH.js.map → chunk-QUIGATZE.js.map} +0 -0
- /package/dist/{chunk-3R7IF4U5.js.map → chunk-SITZC3U6.js.map} +0 -0
- /package/dist/{chunk-4KMBU6T3.js.map → chunk-YJZP5ZL5.js.map} +0 -0
- /package/dist/{chunk-76DJEQEP.js.map → chunk-ZRLEAPZV.js.map} +0 -0
- /package/dist/{chunk-BGEEES52.js.map → chunk-ZROQPUCQ.js.map} +0 -0
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
8
11
|
var __export = (target, all) => {
|
|
9
12
|
for (var name in all)
|
|
10
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -27,6 +30,540 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
30
|
));
|
|
28
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
32
|
|
|
33
|
+
// tools/warp_grep/agent/config.ts
|
|
34
|
+
var parseEnvTimeout, AGENT_CONFIG, BUILTIN_EXCLUDES, DEFAULT_EXCLUDES, DEFAULT_MODEL;
|
|
35
|
+
var init_config = __esm({
|
|
36
|
+
"tools/warp_grep/agent/config.ts"() {
|
|
37
|
+
"use strict";
|
|
38
|
+
parseEnvTimeout = (envValue, defaultMs) => {
|
|
39
|
+
if (!envValue) return defaultMs;
|
|
40
|
+
const parsed = parseInt(envValue, 10);
|
|
41
|
+
return isNaN(parsed) || parsed <= 0 ? defaultMs : parsed;
|
|
42
|
+
};
|
|
43
|
+
AGENT_CONFIG = {
|
|
44
|
+
MAX_TURNS: 4,
|
|
45
|
+
/** Default timeout for model calls. Can be overridden via MORPH_WARP_GREP_TIMEOUT env var (in ms) */
|
|
46
|
+
TIMEOUT_MS: parseEnvTimeout(process.env.MORPH_WARP_GREP_TIMEOUT, 3e4),
|
|
47
|
+
MAX_CONTEXT_CHARS: 54e4,
|
|
48
|
+
MAX_OUTPUT_LINES: 200,
|
|
49
|
+
MAX_READ_LINES: 800,
|
|
50
|
+
MAX_LIST_DEPTH: 3,
|
|
51
|
+
LIST_TIMEOUT_MS: 2e3
|
|
52
|
+
};
|
|
53
|
+
BUILTIN_EXCLUDES = [
|
|
54
|
+
// Version control
|
|
55
|
+
".git",
|
|
56
|
+
".svn",
|
|
57
|
+
".hg",
|
|
58
|
+
".bzr",
|
|
59
|
+
// Dependencies
|
|
60
|
+
"node_modules",
|
|
61
|
+
"bower_components",
|
|
62
|
+
".pnpm",
|
|
63
|
+
".yarn",
|
|
64
|
+
"vendor",
|
|
65
|
+
"packages",
|
|
66
|
+
"Pods",
|
|
67
|
+
".bundle",
|
|
68
|
+
// Python
|
|
69
|
+
"__pycache__",
|
|
70
|
+
".pytest_cache",
|
|
71
|
+
".mypy_cache",
|
|
72
|
+
".ruff_cache",
|
|
73
|
+
".venv",
|
|
74
|
+
"venv",
|
|
75
|
+
".tox",
|
|
76
|
+
".nox",
|
|
77
|
+
".eggs",
|
|
78
|
+
"*.egg-info",
|
|
79
|
+
// Build outputs
|
|
80
|
+
"dist",
|
|
81
|
+
"build",
|
|
82
|
+
"out",
|
|
83
|
+
"output",
|
|
84
|
+
"target",
|
|
85
|
+
"_build",
|
|
86
|
+
".next",
|
|
87
|
+
".nuxt",
|
|
88
|
+
".output",
|
|
89
|
+
".vercel",
|
|
90
|
+
".netlify",
|
|
91
|
+
// Cache directories
|
|
92
|
+
".cache",
|
|
93
|
+
".parcel-cache",
|
|
94
|
+
".turbo",
|
|
95
|
+
".nx",
|
|
96
|
+
".gradle",
|
|
97
|
+
// IDE/Editor
|
|
98
|
+
".idea",
|
|
99
|
+
".vscode",
|
|
100
|
+
".vs",
|
|
101
|
+
// Coverage
|
|
102
|
+
"coverage",
|
|
103
|
+
".coverage",
|
|
104
|
+
"htmlcov",
|
|
105
|
+
".nyc_output",
|
|
106
|
+
// Temporary
|
|
107
|
+
"tmp",
|
|
108
|
+
"temp",
|
|
109
|
+
".tmp",
|
|
110
|
+
".temp",
|
|
111
|
+
// Lock files
|
|
112
|
+
"package-lock.json",
|
|
113
|
+
"yarn.lock",
|
|
114
|
+
"pnpm-lock.yaml",
|
|
115
|
+
"bun.lockb",
|
|
116
|
+
"Cargo.lock",
|
|
117
|
+
"Gemfile.lock",
|
|
118
|
+
"poetry.lock",
|
|
119
|
+
// Binary/minified
|
|
120
|
+
"*.min.js",
|
|
121
|
+
"*.min.css",
|
|
122
|
+
"*.bundle.js",
|
|
123
|
+
"*.wasm",
|
|
124
|
+
"*.so",
|
|
125
|
+
"*.dll",
|
|
126
|
+
"*.pyc",
|
|
127
|
+
"*.map",
|
|
128
|
+
"*.js.map",
|
|
129
|
+
// Hidden directories catch-all
|
|
130
|
+
".*"
|
|
131
|
+
];
|
|
132
|
+
DEFAULT_EXCLUDES = (process.env.MORPH_WARP_GREP_EXCLUDE || "").split(",").map((s) => s.trim()).filter(Boolean).concat(BUILTIN_EXCLUDES);
|
|
133
|
+
DEFAULT_MODEL = "morph-warp-grep-v1";
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// tools/warp_grep/utils/ripgrep.ts
|
|
138
|
+
function spawnRg(rgBinary, args, opts) {
|
|
139
|
+
return new Promise((resolve) => {
|
|
140
|
+
const child = (0, import_child_process.spawn)(rgBinary, args, {
|
|
141
|
+
cwd: opts?.cwd,
|
|
142
|
+
env: { ...process.env, ...opts?.env || {} },
|
|
143
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
144
|
+
});
|
|
145
|
+
let stdout = "";
|
|
146
|
+
let stderr = "";
|
|
147
|
+
child.stdout.on("data", (d) => stdout += d.toString());
|
|
148
|
+
child.stderr.on("data", (d) => stderr += d.toString());
|
|
149
|
+
child.on("close", (code) => {
|
|
150
|
+
resolve({ stdout, stderr, exitCode: typeof code === "number" ? code : -1 });
|
|
151
|
+
});
|
|
152
|
+
child.on("error", () => {
|
|
153
|
+
resolve({ stdout: "", stderr: "Failed to spawn ripgrep.", exitCode: -1 });
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function isBinaryFailure(result) {
|
|
158
|
+
if (result.exitCode === -1) return true;
|
|
159
|
+
if (result.stderr.includes("jemalloc") || result.stderr.includes("Unsupported system page size")) return true;
|
|
160
|
+
if (result.exitCode === 134) return true;
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
async function runRipgrep(args, opts) {
|
|
164
|
+
if (rgPathChecked && resolvedRgPath) {
|
|
165
|
+
return spawnRg(resolvedRgPath, args, opts);
|
|
166
|
+
}
|
|
167
|
+
if (!rgPathChecked) {
|
|
168
|
+
const result = await spawnRg(import_ripgrep.rgPath, args, opts);
|
|
169
|
+
if (!isBinaryFailure(result)) {
|
|
170
|
+
resolvedRgPath = import_ripgrep.rgPath;
|
|
171
|
+
rgPathChecked = true;
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
const fallbackResult = await spawnRg("rg", args, opts);
|
|
175
|
+
if (!isBinaryFailure(fallbackResult)) {
|
|
176
|
+
resolvedRgPath = "rg";
|
|
177
|
+
rgPathChecked = true;
|
|
178
|
+
return fallbackResult;
|
|
179
|
+
}
|
|
180
|
+
rgPathChecked = true;
|
|
181
|
+
return {
|
|
182
|
+
stdout: "",
|
|
183
|
+
stderr: "Failed to spawn ripgrep. Neither bundled nor system rg is available.",
|
|
184
|
+
exitCode: -1
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
stdout: "",
|
|
189
|
+
stderr: "Failed to spawn ripgrep. Neither bundled nor system rg is available.",
|
|
190
|
+
exitCode: -1
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
var import_child_process, import_ripgrep, resolvedRgPath, rgPathChecked;
|
|
194
|
+
var init_ripgrep = __esm({
|
|
195
|
+
"tools/warp_grep/utils/ripgrep.ts"() {
|
|
196
|
+
"use strict";
|
|
197
|
+
import_child_process = require("child_process");
|
|
198
|
+
import_ripgrep = require("@vscode/ripgrep");
|
|
199
|
+
resolvedRgPath = null;
|
|
200
|
+
rgPathChecked = false;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// tools/warp_grep/utils/paths.ts
|
|
205
|
+
function resolveUnderRepo(repoRoot, targetPath) {
|
|
206
|
+
const absRoot = import_path3.default.resolve(repoRoot);
|
|
207
|
+
const resolved = import_path3.default.resolve(absRoot, targetPath);
|
|
208
|
+
ensureWithinRepo(absRoot, resolved);
|
|
209
|
+
return resolved;
|
|
210
|
+
}
|
|
211
|
+
function ensureWithinRepo(repoRoot, absTarget) {
|
|
212
|
+
const rel = import_path3.default.relative(import_path3.default.resolve(repoRoot), import_path3.default.resolve(absTarget));
|
|
213
|
+
if (rel.startsWith("..") || import_path3.default.isAbsolute(rel)) {
|
|
214
|
+
throw new Error(`Path outside repository root: ${absTarget}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function toRepoRelative(repoRoot, absPath) {
|
|
218
|
+
return import_path3.default.relative(import_path3.default.resolve(repoRoot), import_path3.default.resolve(absPath));
|
|
219
|
+
}
|
|
220
|
+
function isSymlink(p) {
|
|
221
|
+
try {
|
|
222
|
+
const st = import_fs.default.lstatSync(p);
|
|
223
|
+
return st.isSymbolicLink();
|
|
224
|
+
} catch {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function fixPathRepetition(fullPath) {
|
|
229
|
+
const segments = fullPath.split(import_path3.default.sep).filter(Boolean);
|
|
230
|
+
if (segments.length < 2) return null;
|
|
231
|
+
for (let len = Math.floor(segments.length / 2); len >= 1; len--) {
|
|
232
|
+
for (let i = 0; i <= segments.length - 2 * len; i++) {
|
|
233
|
+
const first = segments.slice(i, i + len);
|
|
234
|
+
const second = segments.slice(i + len, i + 2 * len);
|
|
235
|
+
if (first.every((seg, idx) => seg === second[idx])) {
|
|
236
|
+
const fixed = [...segments.slice(0, i), ...segments.slice(i + len)];
|
|
237
|
+
return import_path3.default.sep + fixed.join(import_path3.default.sep);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
function isTextualFile(filePath, maxBytes = 2e6) {
|
|
244
|
+
try {
|
|
245
|
+
const st = import_fs.default.statSync(filePath);
|
|
246
|
+
if (!st.isFile()) return false;
|
|
247
|
+
if (st.size > maxBytes) return false;
|
|
248
|
+
const fd = import_fs.default.openSync(filePath, "r");
|
|
249
|
+
const buf = Buffer.alloc(512);
|
|
250
|
+
const read = import_fs.default.readSync(fd, buf, 0, buf.length, 0);
|
|
251
|
+
import_fs.default.closeSync(fd);
|
|
252
|
+
for (let i = 0; i < read; i++) {
|
|
253
|
+
const c = buf[i];
|
|
254
|
+
if (c === 0) return false;
|
|
255
|
+
}
|
|
256
|
+
return true;
|
|
257
|
+
} catch {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
var import_fs, import_path3;
|
|
262
|
+
var init_paths = __esm({
|
|
263
|
+
"tools/warp_grep/utils/paths.ts"() {
|
|
264
|
+
"use strict";
|
|
265
|
+
import_fs = __toESM(require("fs"), 1);
|
|
266
|
+
import_path3 = __toESM(require("path"), 1);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
// tools/warp_grep/utils/files.ts
|
|
271
|
+
async function readAllLines(filePath) {
|
|
272
|
+
const content = await import_promises.default.readFile(filePath, "utf8");
|
|
273
|
+
return content.split(/\r?\n/);
|
|
274
|
+
}
|
|
275
|
+
var import_promises;
|
|
276
|
+
var init_files = __esm({
|
|
277
|
+
"tools/warp_grep/utils/files.ts"() {
|
|
278
|
+
"use strict";
|
|
279
|
+
import_promises = __toESM(require("fs/promises"), 1);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// tools/warp_grep/providers/local.ts
|
|
284
|
+
var local_exports = {};
|
|
285
|
+
__export(local_exports, {
|
|
286
|
+
LocalRipgrepProvider: () => LocalRipgrepProvider
|
|
287
|
+
});
|
|
288
|
+
function shouldSkip2(name) {
|
|
289
|
+
if (SKIP_NAMES2.has(name)) return true;
|
|
290
|
+
if (name.startsWith(".")) return true;
|
|
291
|
+
for (const ext of SKIP_EXTENSIONS2) {
|
|
292
|
+
if (name.endsWith(ext)) return true;
|
|
293
|
+
}
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
var import_promises2, import_path4, SKIP_NAMES2, SKIP_EXTENSIONS2, LocalRipgrepProvider;
|
|
297
|
+
var init_local = __esm({
|
|
298
|
+
"tools/warp_grep/providers/local.ts"() {
|
|
299
|
+
"use strict";
|
|
300
|
+
import_promises2 = __toESM(require("fs/promises"), 1);
|
|
301
|
+
import_path4 = __toESM(require("path"), 1);
|
|
302
|
+
init_ripgrep();
|
|
303
|
+
init_paths();
|
|
304
|
+
init_files();
|
|
305
|
+
init_config();
|
|
306
|
+
SKIP_NAMES2 = /* @__PURE__ */ new Set([
|
|
307
|
+
// Version control
|
|
308
|
+
".git",
|
|
309
|
+
".svn",
|
|
310
|
+
".hg",
|
|
311
|
+
".bzr",
|
|
312
|
+
// Dependencies
|
|
313
|
+
"node_modules",
|
|
314
|
+
"bower_components",
|
|
315
|
+
".pnpm",
|
|
316
|
+
".yarn",
|
|
317
|
+
"vendor",
|
|
318
|
+
"Pods",
|
|
319
|
+
".bundle",
|
|
320
|
+
// Python
|
|
321
|
+
"__pycache__",
|
|
322
|
+
".pytest_cache",
|
|
323
|
+
".mypy_cache",
|
|
324
|
+
".ruff_cache",
|
|
325
|
+
".venv",
|
|
326
|
+
"venv",
|
|
327
|
+
".tox",
|
|
328
|
+
".nox",
|
|
329
|
+
".eggs",
|
|
330
|
+
// Build outputs
|
|
331
|
+
"dist",
|
|
332
|
+
"build",
|
|
333
|
+
"out",
|
|
334
|
+
"output",
|
|
335
|
+
"target",
|
|
336
|
+
"_build",
|
|
337
|
+
".next",
|
|
338
|
+
".nuxt",
|
|
339
|
+
".output",
|
|
340
|
+
".vercel",
|
|
341
|
+
".netlify",
|
|
342
|
+
// Cache
|
|
343
|
+
".cache",
|
|
344
|
+
".parcel-cache",
|
|
345
|
+
".turbo",
|
|
346
|
+
".nx",
|
|
347
|
+
".gradle",
|
|
348
|
+
// IDE
|
|
349
|
+
".idea",
|
|
350
|
+
".vscode",
|
|
351
|
+
".vs",
|
|
352
|
+
// Coverage
|
|
353
|
+
"coverage",
|
|
354
|
+
".coverage",
|
|
355
|
+
"htmlcov",
|
|
356
|
+
".nyc_output",
|
|
357
|
+
// Temp
|
|
358
|
+
"tmp",
|
|
359
|
+
"temp",
|
|
360
|
+
".tmp",
|
|
361
|
+
".temp",
|
|
362
|
+
// Lock files
|
|
363
|
+
"package-lock.json",
|
|
364
|
+
"yarn.lock",
|
|
365
|
+
"pnpm-lock.yaml",
|
|
366
|
+
"bun.lockb",
|
|
367
|
+
"Cargo.lock",
|
|
368
|
+
"Gemfile.lock",
|
|
369
|
+
"poetry.lock"
|
|
370
|
+
]);
|
|
371
|
+
SKIP_EXTENSIONS2 = /* @__PURE__ */ new Set([
|
|
372
|
+
".min.js",
|
|
373
|
+
".min.css",
|
|
374
|
+
".bundle.js",
|
|
375
|
+
".wasm",
|
|
376
|
+
".so",
|
|
377
|
+
".dll",
|
|
378
|
+
".pyc",
|
|
379
|
+
".map",
|
|
380
|
+
".js.map"
|
|
381
|
+
]);
|
|
382
|
+
LocalRipgrepProvider = class {
|
|
383
|
+
constructor(repoRoot, excludes = DEFAULT_EXCLUDES) {
|
|
384
|
+
this.repoRoot = repoRoot;
|
|
385
|
+
this.excludes = excludes;
|
|
386
|
+
}
|
|
387
|
+
async grep(params) {
|
|
388
|
+
let abs;
|
|
389
|
+
try {
|
|
390
|
+
abs = resolveUnderRepo(this.repoRoot, params.path);
|
|
391
|
+
} catch (err) {
|
|
392
|
+
return {
|
|
393
|
+
lines: [],
|
|
394
|
+
error: `[PATH ERROR] ${err instanceof Error ? err.message : String(err)}`
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
const stat = await import_promises2.default.stat(abs).catch(() => null);
|
|
398
|
+
if (!stat) return { lines: [] };
|
|
399
|
+
const targetArg = abs === import_path4.default.resolve(this.repoRoot) ? "." : toRepoRelative(this.repoRoot, abs);
|
|
400
|
+
const args = [
|
|
401
|
+
"--no-config",
|
|
402
|
+
"--no-heading",
|
|
403
|
+
"--with-filename",
|
|
404
|
+
"--line-number",
|
|
405
|
+
"--color=never",
|
|
406
|
+
"--trim",
|
|
407
|
+
"--max-columns=400",
|
|
408
|
+
"-C",
|
|
409
|
+
"1",
|
|
410
|
+
...params.glob ? ["--glob", params.glob] : [],
|
|
411
|
+
...this.excludes.flatMap((e) => ["-g", `!${e}`]),
|
|
412
|
+
params.pattern,
|
|
413
|
+
targetArg || "."
|
|
414
|
+
];
|
|
415
|
+
const res = await runRipgrep(args, { cwd: this.repoRoot });
|
|
416
|
+
if (res.exitCode === -1) {
|
|
417
|
+
return {
|
|
418
|
+
lines: [],
|
|
419
|
+
error: `[RIPGREP NOT AVAILABLE] ripgrep (rg) is required but failed to execute. Please install it:
|
|
420
|
+
\u2022 macOS: brew install ripgrep
|
|
421
|
+
\u2022 Ubuntu/Debian: apt install ripgrep
|
|
422
|
+
\u2022 Windows: choco install ripgrep
|
|
423
|
+
\u2022 Or visit: https://github.com/BurntSushi/ripgrep#installation
|
|
424
|
+
Exit code: ${res.exitCode}${res.stderr ? `
|
|
425
|
+
Details: ${res.stderr}` : ""}`
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
if (res.exitCode !== 0 && res.exitCode !== 1) {
|
|
429
|
+
return {
|
|
430
|
+
lines: [],
|
|
431
|
+
error: `[RIPGREP ERROR] grep failed with exit code ${res.exitCode}${res.stderr ? `: ${res.stderr}` : ""}`
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
const lines = (res.stdout || "").trim().split(/\r?\n/).filter((l) => l.length > 0);
|
|
435
|
+
if (lines.length > AGENT_CONFIG.MAX_OUTPUT_LINES) {
|
|
436
|
+
return {
|
|
437
|
+
lines: [],
|
|
438
|
+
error: "query not specific enough, tool tried to return too much context and failed"
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
return { lines };
|
|
442
|
+
}
|
|
443
|
+
async read(params) {
|
|
444
|
+
let abs;
|
|
445
|
+
try {
|
|
446
|
+
abs = resolveUnderRepo(this.repoRoot, params.path);
|
|
447
|
+
} catch (err) {
|
|
448
|
+
return {
|
|
449
|
+
lines: [],
|
|
450
|
+
error: `[PATH ERROR] ${err instanceof Error ? err.message : String(err)}`
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
let stat = await import_promises2.default.stat(abs).catch(() => null);
|
|
454
|
+
if (!stat || !stat.isFile()) {
|
|
455
|
+
const fixedPath = fixPathRepetition(abs);
|
|
456
|
+
if (fixedPath) {
|
|
457
|
+
const fixedStat = await import_promises2.default.stat(fixedPath).catch(() => null);
|
|
458
|
+
if (fixedStat?.isFile()) {
|
|
459
|
+
abs = fixedPath;
|
|
460
|
+
stat = fixedStat;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (!stat || !stat.isFile()) {
|
|
465
|
+
return {
|
|
466
|
+
lines: [],
|
|
467
|
+
error: `[FILE NOT FOUND] You tried to read "${params.path}" but there is no file at this path. Double-check the path exists and is spelled correctly.`
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
if (isSymlink(abs)) {
|
|
471
|
+
return {
|
|
472
|
+
lines: [],
|
|
473
|
+
error: `[SYMLINK] You tried to read "${params.path}" but this is a symlink. Try reading the actual file it points to instead.`
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
if (!isTextualFile(abs)) {
|
|
477
|
+
return {
|
|
478
|
+
lines: [],
|
|
479
|
+
error: `[UNREADABLE FILE] You tried to read "${params.path}" but this file is either too large or not a text file, so it cannot be read. Try a different file.`
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
let lines;
|
|
483
|
+
try {
|
|
484
|
+
lines = await readAllLines(abs);
|
|
485
|
+
} catch (err) {
|
|
486
|
+
return {
|
|
487
|
+
lines: [],
|
|
488
|
+
error: `[READ ERROR] Failed to read "${params.path}": ${err instanceof Error ? err.message : String(err)}`
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
const total = lines.length;
|
|
492
|
+
const rawStart = params.start;
|
|
493
|
+
const rawEnd = params.end;
|
|
494
|
+
let s = 1;
|
|
495
|
+
let e = total;
|
|
496
|
+
const startValid = rawStart === void 0 || Number.isFinite(rawStart) && rawStart > 0;
|
|
497
|
+
const endValid = rawEnd === void 0 || Number.isFinite(rawEnd) && rawEnd > 0;
|
|
498
|
+
if (startValid && endValid) {
|
|
499
|
+
s = rawStart ?? 1;
|
|
500
|
+
e = Math.min(rawEnd ?? total, total);
|
|
501
|
+
if (s > total && total > 0 || s > e) {
|
|
502
|
+
s = 1;
|
|
503
|
+
e = total;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
const out = [];
|
|
507
|
+
for (let i = s; i <= e; i += 1) {
|
|
508
|
+
const content = lines[i - 1] ?? "";
|
|
509
|
+
out.push(`${i}|${content}`);
|
|
510
|
+
}
|
|
511
|
+
if (out.length > AGENT_CONFIG.MAX_READ_LINES) {
|
|
512
|
+
const truncated = out.slice(0, AGENT_CONFIG.MAX_READ_LINES);
|
|
513
|
+
truncated.push(`... [truncated: showing ${AGENT_CONFIG.MAX_READ_LINES} of ${out.length} lines]`);
|
|
514
|
+
return { lines: truncated };
|
|
515
|
+
}
|
|
516
|
+
return { lines: out };
|
|
517
|
+
}
|
|
518
|
+
async listDirectory(params) {
|
|
519
|
+
let abs;
|
|
520
|
+
try {
|
|
521
|
+
abs = resolveUnderRepo(this.repoRoot, params.path);
|
|
522
|
+
} catch {
|
|
523
|
+
return [];
|
|
524
|
+
}
|
|
525
|
+
const stat = await import_promises2.default.stat(abs).catch(() => null);
|
|
526
|
+
if (!stat || !stat.isDirectory()) {
|
|
527
|
+
return [];
|
|
528
|
+
}
|
|
529
|
+
const maxResults = params.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES;
|
|
530
|
+
const maxDepth = params.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
531
|
+
const regex = params.pattern ? new RegExp(params.pattern) : null;
|
|
532
|
+
const repoRoot = this.repoRoot;
|
|
533
|
+
const results = [];
|
|
534
|
+
let timedOut = false;
|
|
535
|
+
const startTime = Date.now();
|
|
536
|
+
async function walk(dir, depth) {
|
|
537
|
+
if (Date.now() - startTime > AGENT_CONFIG.LIST_TIMEOUT_MS) {
|
|
538
|
+
timedOut = true;
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
if (depth > maxDepth || results.length >= maxResults) return;
|
|
542
|
+
const entries = await import_promises2.default.readdir(dir, { withFileTypes: true });
|
|
543
|
+
for (const entry of entries) {
|
|
544
|
+
if (timedOut || results.length >= maxResults) break;
|
|
545
|
+
if (shouldSkip2(entry.name)) continue;
|
|
546
|
+
if (regex && !regex.test(entry.name)) continue;
|
|
547
|
+
const full = import_path4.default.join(dir, entry.name);
|
|
548
|
+
const isDir = entry.isDirectory();
|
|
549
|
+
results.push({
|
|
550
|
+
name: entry.name,
|
|
551
|
+
path: toRepoRelative(repoRoot, full),
|
|
552
|
+
type: isDir ? "dir" : "file",
|
|
553
|
+
depth
|
|
554
|
+
});
|
|
555
|
+
if (isDir) {
|
|
556
|
+
await walk(full, depth + 1);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
await walk(abs, 0);
|
|
561
|
+
return results;
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
|
|
30
567
|
// tools/warp_grep/anthropic.ts
|
|
31
568
|
var anthropic_exports = {};
|
|
32
569
|
__export(anthropic_exports, {
|
|
@@ -38,103 +575,8 @@ __export(anthropic_exports, {
|
|
|
38
575
|
});
|
|
39
576
|
module.exports = __toCommonJS(anthropic_exports);
|
|
40
577
|
|
|
41
|
-
// tools/warp_grep/agent/
|
|
42
|
-
|
|
43
|
-
if (!envValue) return defaultMs;
|
|
44
|
-
const parsed = parseInt(envValue, 10);
|
|
45
|
-
return isNaN(parsed) || parsed <= 0 ? defaultMs : parsed;
|
|
46
|
-
};
|
|
47
|
-
var AGENT_CONFIG = {
|
|
48
|
-
MAX_TURNS: 4,
|
|
49
|
-
/** Default timeout for model calls. Can be overridden via MORPH_WARP_GREP_TIMEOUT env var (in ms) */
|
|
50
|
-
TIMEOUT_MS: parseEnvTimeout(process.env.MORPH_WARP_GREP_TIMEOUT, 3e4),
|
|
51
|
-
MAX_CONTEXT_CHARS: 54e4,
|
|
52
|
-
MAX_OUTPUT_LINES: 200,
|
|
53
|
-
MAX_READ_LINES: 800,
|
|
54
|
-
MAX_LIST_DEPTH: 3,
|
|
55
|
-
LIST_TIMEOUT_MS: 2e3
|
|
56
|
-
};
|
|
57
|
-
var BUILTIN_EXCLUDES = [
|
|
58
|
-
// Version control
|
|
59
|
-
".git",
|
|
60
|
-
".svn",
|
|
61
|
-
".hg",
|
|
62
|
-
".bzr",
|
|
63
|
-
// Dependencies
|
|
64
|
-
"node_modules",
|
|
65
|
-
"bower_components",
|
|
66
|
-
".pnpm",
|
|
67
|
-
".yarn",
|
|
68
|
-
"vendor",
|
|
69
|
-
"packages",
|
|
70
|
-
"Pods",
|
|
71
|
-
".bundle",
|
|
72
|
-
// Python
|
|
73
|
-
"__pycache__",
|
|
74
|
-
".pytest_cache",
|
|
75
|
-
".mypy_cache",
|
|
76
|
-
".ruff_cache",
|
|
77
|
-
".venv",
|
|
78
|
-
"venv",
|
|
79
|
-
".tox",
|
|
80
|
-
".nox",
|
|
81
|
-
".eggs",
|
|
82
|
-
"*.egg-info",
|
|
83
|
-
// Build outputs
|
|
84
|
-
"dist",
|
|
85
|
-
"build",
|
|
86
|
-
"out",
|
|
87
|
-
"output",
|
|
88
|
-
"target",
|
|
89
|
-
"_build",
|
|
90
|
-
".next",
|
|
91
|
-
".nuxt",
|
|
92
|
-
".output",
|
|
93
|
-
".vercel",
|
|
94
|
-
".netlify",
|
|
95
|
-
// Cache directories
|
|
96
|
-
".cache",
|
|
97
|
-
".parcel-cache",
|
|
98
|
-
".turbo",
|
|
99
|
-
".nx",
|
|
100
|
-
".gradle",
|
|
101
|
-
// IDE/Editor
|
|
102
|
-
".idea",
|
|
103
|
-
".vscode",
|
|
104
|
-
".vs",
|
|
105
|
-
// Coverage
|
|
106
|
-
"coverage",
|
|
107
|
-
".coverage",
|
|
108
|
-
"htmlcov",
|
|
109
|
-
".nyc_output",
|
|
110
|
-
// Temporary
|
|
111
|
-
"tmp",
|
|
112
|
-
"temp",
|
|
113
|
-
".tmp",
|
|
114
|
-
".temp",
|
|
115
|
-
// Lock files
|
|
116
|
-
"package-lock.json",
|
|
117
|
-
"yarn.lock",
|
|
118
|
-
"pnpm-lock.yaml",
|
|
119
|
-
"bun.lockb",
|
|
120
|
-
"Cargo.lock",
|
|
121
|
-
"Gemfile.lock",
|
|
122
|
-
"poetry.lock",
|
|
123
|
-
// Binary/minified
|
|
124
|
-
"*.min.js",
|
|
125
|
-
"*.min.css",
|
|
126
|
-
"*.bundle.js",
|
|
127
|
-
"*.wasm",
|
|
128
|
-
"*.so",
|
|
129
|
-
"*.dll",
|
|
130
|
-
"*.pyc",
|
|
131
|
-
"*.map",
|
|
132
|
-
"*.js.map",
|
|
133
|
-
// Hidden directories catch-all
|
|
134
|
-
".*"
|
|
135
|
-
];
|
|
136
|
-
var DEFAULT_EXCLUDES = (process.env.MORPH_WARP_GREP_EXCLUDE || "").split(",").map((s) => s.trim()).filter(Boolean).concat(BUILTIN_EXCLUDES);
|
|
137
|
-
var DEFAULT_MODEL = "morph-warp-grep-v1";
|
|
578
|
+
// tools/warp_grep/agent/runner.ts
|
|
579
|
+
init_config();
|
|
138
580
|
|
|
139
581
|
// tools/warp_grep/agent/prompt.ts
|
|
140
582
|
var SYSTEM_PROMPT = `You are a code search agent. Your task is to find all relevant code for a given search_string.
|
|
@@ -650,6 +1092,7 @@ async function toolRead(provider, args) {
|
|
|
650
1092
|
}
|
|
651
1093
|
|
|
652
1094
|
// tools/warp_grep/agent/tools/list_directory.ts
|
|
1095
|
+
init_config();
|
|
653
1096
|
async function toolListDirectory(provider, args) {
|
|
654
1097
|
const maxResults = args.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES;
|
|
655
1098
|
const initialDepth = args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
@@ -824,6 +1267,7 @@ function formatAgentToolOutput(toolName, args, output, options = {}) {
|
|
|
824
1267
|
|
|
825
1268
|
// tools/warp_grep/agent/helpers.ts
|
|
826
1269
|
var import_path = __toESM(require("path"), 1);
|
|
1270
|
+
init_config();
|
|
827
1271
|
var TRUNCATED_MARKER = "[truncated for context limit]";
|
|
828
1272
|
function formatTurnMessage(turnsUsed, maxTurns) {
|
|
829
1273
|
const turnsRemaining = maxTurns - turnsUsed;
|
|
@@ -1083,139 +1527,8 @@ async function runWarpGrep(config) {
|
|
|
1083
1527
|
};
|
|
1084
1528
|
}
|
|
1085
1529
|
|
|
1086
|
-
// tools/warp_grep/providers/
|
|
1087
|
-
|
|
1088
|
-
var import_path4 = __toESM(require("path"), 1);
|
|
1089
|
-
|
|
1090
|
-
// tools/warp_grep/utils/ripgrep.ts
|
|
1091
|
-
var import_child_process = require("child_process");
|
|
1092
|
-
var import_ripgrep = require("@vscode/ripgrep");
|
|
1093
|
-
var resolvedRgPath = null;
|
|
1094
|
-
var rgPathChecked = false;
|
|
1095
|
-
function spawnRg(rgBinary, args, opts) {
|
|
1096
|
-
return new Promise((resolve) => {
|
|
1097
|
-
const child = (0, import_child_process.spawn)(rgBinary, args, {
|
|
1098
|
-
cwd: opts?.cwd,
|
|
1099
|
-
env: { ...process.env, ...opts?.env || {} },
|
|
1100
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
1101
|
-
});
|
|
1102
|
-
let stdout = "";
|
|
1103
|
-
let stderr = "";
|
|
1104
|
-
child.stdout.on("data", (d) => stdout += d.toString());
|
|
1105
|
-
child.stderr.on("data", (d) => stderr += d.toString());
|
|
1106
|
-
child.on("close", (code) => {
|
|
1107
|
-
resolve({ stdout, stderr, exitCode: typeof code === "number" ? code : -1 });
|
|
1108
|
-
});
|
|
1109
|
-
child.on("error", () => {
|
|
1110
|
-
resolve({ stdout: "", stderr: "Failed to spawn ripgrep.", exitCode: -1 });
|
|
1111
|
-
});
|
|
1112
|
-
});
|
|
1113
|
-
}
|
|
1114
|
-
function isBinaryFailure(result) {
|
|
1115
|
-
if (result.exitCode === -1) return true;
|
|
1116
|
-
if (result.stderr.includes("jemalloc") || result.stderr.includes("Unsupported system page size")) return true;
|
|
1117
|
-
if (result.exitCode === 134) return true;
|
|
1118
|
-
return false;
|
|
1119
|
-
}
|
|
1120
|
-
async function runRipgrep(args, opts) {
|
|
1121
|
-
if (rgPathChecked && resolvedRgPath) {
|
|
1122
|
-
return spawnRg(resolvedRgPath, args, opts);
|
|
1123
|
-
}
|
|
1124
|
-
if (!rgPathChecked) {
|
|
1125
|
-
const result = await spawnRg(import_ripgrep.rgPath, args, opts);
|
|
1126
|
-
if (!isBinaryFailure(result)) {
|
|
1127
|
-
resolvedRgPath = import_ripgrep.rgPath;
|
|
1128
|
-
rgPathChecked = true;
|
|
1129
|
-
return result;
|
|
1130
|
-
}
|
|
1131
|
-
const fallbackResult = await spawnRg("rg", args, opts);
|
|
1132
|
-
if (!isBinaryFailure(fallbackResult)) {
|
|
1133
|
-
resolvedRgPath = "rg";
|
|
1134
|
-
rgPathChecked = true;
|
|
1135
|
-
return fallbackResult;
|
|
1136
|
-
}
|
|
1137
|
-
rgPathChecked = true;
|
|
1138
|
-
return {
|
|
1139
|
-
stdout: "",
|
|
1140
|
-
stderr: "Failed to spawn ripgrep. Neither bundled nor system rg is available.",
|
|
1141
|
-
exitCode: -1
|
|
1142
|
-
};
|
|
1143
|
-
}
|
|
1144
|
-
return {
|
|
1145
|
-
stdout: "",
|
|
1146
|
-
stderr: "Failed to spawn ripgrep. Neither bundled nor system rg is available.",
|
|
1147
|
-
exitCode: -1
|
|
1148
|
-
};
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
|
-
// tools/warp_grep/utils/paths.ts
|
|
1152
|
-
var import_fs = __toESM(require("fs"), 1);
|
|
1153
|
-
var import_path3 = __toESM(require("path"), 1);
|
|
1154
|
-
function resolveUnderRepo(repoRoot, targetPath) {
|
|
1155
|
-
const absRoot = import_path3.default.resolve(repoRoot);
|
|
1156
|
-
const resolved = import_path3.default.resolve(absRoot, targetPath);
|
|
1157
|
-
ensureWithinRepo(absRoot, resolved);
|
|
1158
|
-
return resolved;
|
|
1159
|
-
}
|
|
1160
|
-
function ensureWithinRepo(repoRoot, absTarget) {
|
|
1161
|
-
const rel = import_path3.default.relative(import_path3.default.resolve(repoRoot), import_path3.default.resolve(absTarget));
|
|
1162
|
-
if (rel.startsWith("..") || import_path3.default.isAbsolute(rel)) {
|
|
1163
|
-
throw new Error(`Path outside repository root: ${absTarget}`);
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
function toRepoRelative(repoRoot, absPath) {
|
|
1167
|
-
return import_path3.default.relative(import_path3.default.resolve(repoRoot), import_path3.default.resolve(absPath));
|
|
1168
|
-
}
|
|
1169
|
-
function isSymlink(p) {
|
|
1170
|
-
try {
|
|
1171
|
-
const st = import_fs.default.lstatSync(p);
|
|
1172
|
-
return st.isSymbolicLink();
|
|
1173
|
-
} catch {
|
|
1174
|
-
return false;
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
function fixPathRepetition(fullPath) {
|
|
1178
|
-
const segments = fullPath.split(import_path3.default.sep).filter(Boolean);
|
|
1179
|
-
if (segments.length < 2) return null;
|
|
1180
|
-
for (let len = Math.floor(segments.length / 2); len >= 1; len--) {
|
|
1181
|
-
for (let i = 0; i <= segments.length - 2 * len; i++) {
|
|
1182
|
-
const first = segments.slice(i, i + len);
|
|
1183
|
-
const second = segments.slice(i + len, i + 2 * len);
|
|
1184
|
-
if (first.every((seg, idx) => seg === second[idx])) {
|
|
1185
|
-
const fixed = [...segments.slice(0, i), ...segments.slice(i + len)];
|
|
1186
|
-
return import_path3.default.sep + fixed.join(import_path3.default.sep);
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
return null;
|
|
1191
|
-
}
|
|
1192
|
-
function isTextualFile(filePath, maxBytes = 2e6) {
|
|
1193
|
-
try {
|
|
1194
|
-
const st = import_fs.default.statSync(filePath);
|
|
1195
|
-
if (!st.isFile()) return false;
|
|
1196
|
-
if (st.size > maxBytes) return false;
|
|
1197
|
-
const fd = import_fs.default.openSync(filePath, "r");
|
|
1198
|
-
const buf = Buffer.alloc(512);
|
|
1199
|
-
const read = import_fs.default.readSync(fd, buf, 0, buf.length, 0);
|
|
1200
|
-
import_fs.default.closeSync(fd);
|
|
1201
|
-
for (let i = 0; i < read; i++) {
|
|
1202
|
-
const c = buf[i];
|
|
1203
|
-
if (c === 0) return false;
|
|
1204
|
-
}
|
|
1205
|
-
return true;
|
|
1206
|
-
} catch {
|
|
1207
|
-
return false;
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
|
-
// tools/warp_grep/utils/files.ts
|
|
1212
|
-
var import_promises = __toESM(require("fs/promises"), 1);
|
|
1213
|
-
async function readAllLines(filePath) {
|
|
1214
|
-
const content = await import_promises.default.readFile(filePath, "utf8");
|
|
1215
|
-
return content.split(/\r?\n/);
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
// tools/warp_grep/providers/local.ts
|
|
1530
|
+
// tools/warp_grep/providers/remote.ts
|
|
1531
|
+
init_config();
|
|
1219
1532
|
var SKIP_NAMES = /* @__PURE__ */ new Set([
|
|
1220
1533
|
// Version control
|
|
1221
1534
|
".git",
|
|
@@ -1300,274 +1613,6 @@ function shouldSkip(name) {
|
|
|
1300
1613
|
}
|
|
1301
1614
|
return false;
|
|
1302
1615
|
}
|
|
1303
|
-
var LocalRipgrepProvider = class {
|
|
1304
|
-
constructor(repoRoot, excludes = DEFAULT_EXCLUDES) {
|
|
1305
|
-
this.repoRoot = repoRoot;
|
|
1306
|
-
this.excludes = excludes;
|
|
1307
|
-
}
|
|
1308
|
-
async grep(params) {
|
|
1309
|
-
let abs;
|
|
1310
|
-
try {
|
|
1311
|
-
abs = resolveUnderRepo(this.repoRoot, params.path);
|
|
1312
|
-
} catch (err) {
|
|
1313
|
-
return {
|
|
1314
|
-
lines: [],
|
|
1315
|
-
error: `[PATH ERROR] ${err instanceof Error ? err.message : String(err)}`
|
|
1316
|
-
};
|
|
1317
|
-
}
|
|
1318
|
-
const stat = await import_promises2.default.stat(abs).catch(() => null);
|
|
1319
|
-
if (!stat) return { lines: [] };
|
|
1320
|
-
const targetArg = abs === import_path4.default.resolve(this.repoRoot) ? "." : toRepoRelative(this.repoRoot, abs);
|
|
1321
|
-
const args = [
|
|
1322
|
-
"--no-config",
|
|
1323
|
-
"--no-heading",
|
|
1324
|
-
"--with-filename",
|
|
1325
|
-
"--line-number",
|
|
1326
|
-
"--color=never",
|
|
1327
|
-
"--trim",
|
|
1328
|
-
"--max-columns=400",
|
|
1329
|
-
"-C",
|
|
1330
|
-
"1",
|
|
1331
|
-
...params.glob ? ["--glob", params.glob] : [],
|
|
1332
|
-
...this.excludes.flatMap((e) => ["-g", `!${e}`]),
|
|
1333
|
-
params.pattern,
|
|
1334
|
-
targetArg || "."
|
|
1335
|
-
];
|
|
1336
|
-
const res = await runRipgrep(args, { cwd: this.repoRoot });
|
|
1337
|
-
if (res.exitCode === -1) {
|
|
1338
|
-
return {
|
|
1339
|
-
lines: [],
|
|
1340
|
-
error: `[RIPGREP NOT AVAILABLE] ripgrep (rg) is required but failed to execute. Please install it:
|
|
1341
|
-
\u2022 macOS: brew install ripgrep
|
|
1342
|
-
\u2022 Ubuntu/Debian: apt install ripgrep
|
|
1343
|
-
\u2022 Windows: choco install ripgrep
|
|
1344
|
-
\u2022 Or visit: https://github.com/BurntSushi/ripgrep#installation
|
|
1345
|
-
Exit code: ${res.exitCode}${res.stderr ? `
|
|
1346
|
-
Details: ${res.stderr}` : ""}`
|
|
1347
|
-
};
|
|
1348
|
-
}
|
|
1349
|
-
if (res.exitCode !== 0 && res.exitCode !== 1) {
|
|
1350
|
-
return {
|
|
1351
|
-
lines: [],
|
|
1352
|
-
error: `[RIPGREP ERROR] grep failed with exit code ${res.exitCode}${res.stderr ? `: ${res.stderr}` : ""}`
|
|
1353
|
-
};
|
|
1354
|
-
}
|
|
1355
|
-
const lines = (res.stdout || "").trim().split(/\r?\n/).filter((l) => l.length > 0);
|
|
1356
|
-
if (lines.length > AGENT_CONFIG.MAX_OUTPUT_LINES) {
|
|
1357
|
-
return {
|
|
1358
|
-
lines: [],
|
|
1359
|
-
error: "query not specific enough, tool tried to return too much context and failed"
|
|
1360
|
-
};
|
|
1361
|
-
}
|
|
1362
|
-
return { lines };
|
|
1363
|
-
}
|
|
1364
|
-
async read(params) {
|
|
1365
|
-
let abs;
|
|
1366
|
-
try {
|
|
1367
|
-
abs = resolveUnderRepo(this.repoRoot, params.path);
|
|
1368
|
-
} catch (err) {
|
|
1369
|
-
return {
|
|
1370
|
-
lines: [],
|
|
1371
|
-
error: `[PATH ERROR] ${err instanceof Error ? err.message : String(err)}`
|
|
1372
|
-
};
|
|
1373
|
-
}
|
|
1374
|
-
let stat = await import_promises2.default.stat(abs).catch(() => null);
|
|
1375
|
-
if (!stat || !stat.isFile()) {
|
|
1376
|
-
const fixedPath = fixPathRepetition(abs);
|
|
1377
|
-
if (fixedPath) {
|
|
1378
|
-
const fixedStat = await import_promises2.default.stat(fixedPath).catch(() => null);
|
|
1379
|
-
if (fixedStat?.isFile()) {
|
|
1380
|
-
abs = fixedPath;
|
|
1381
|
-
stat = fixedStat;
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
if (!stat || !stat.isFile()) {
|
|
1386
|
-
return {
|
|
1387
|
-
lines: [],
|
|
1388
|
-
error: `[FILE NOT FOUND] You tried to read "${params.path}" but there is no file at this path. Double-check the path exists and is spelled correctly.`
|
|
1389
|
-
};
|
|
1390
|
-
}
|
|
1391
|
-
if (isSymlink(abs)) {
|
|
1392
|
-
return {
|
|
1393
|
-
lines: [],
|
|
1394
|
-
error: `[SYMLINK] You tried to read "${params.path}" but this is a symlink. Try reading the actual file it points to instead.`
|
|
1395
|
-
};
|
|
1396
|
-
}
|
|
1397
|
-
if (!isTextualFile(abs)) {
|
|
1398
|
-
return {
|
|
1399
|
-
lines: [],
|
|
1400
|
-
error: `[UNREADABLE FILE] You tried to read "${params.path}" but this file is either too large or not a text file, so it cannot be read. Try a different file.`
|
|
1401
|
-
};
|
|
1402
|
-
}
|
|
1403
|
-
let lines;
|
|
1404
|
-
try {
|
|
1405
|
-
lines = await readAllLines(abs);
|
|
1406
|
-
} catch (err) {
|
|
1407
|
-
return {
|
|
1408
|
-
lines: [],
|
|
1409
|
-
error: `[READ ERROR] Failed to read "${params.path}": ${err instanceof Error ? err.message : String(err)}`
|
|
1410
|
-
};
|
|
1411
|
-
}
|
|
1412
|
-
const total = lines.length;
|
|
1413
|
-
const rawStart = params.start;
|
|
1414
|
-
const rawEnd = params.end;
|
|
1415
|
-
let s = 1;
|
|
1416
|
-
let e = total;
|
|
1417
|
-
const startValid = rawStart === void 0 || Number.isFinite(rawStart) && rawStart > 0;
|
|
1418
|
-
const endValid = rawEnd === void 0 || Number.isFinite(rawEnd) && rawEnd > 0;
|
|
1419
|
-
if (startValid && endValid) {
|
|
1420
|
-
s = rawStart ?? 1;
|
|
1421
|
-
e = Math.min(rawEnd ?? total, total);
|
|
1422
|
-
if (s > total && total > 0 || s > e) {
|
|
1423
|
-
s = 1;
|
|
1424
|
-
e = total;
|
|
1425
|
-
}
|
|
1426
|
-
}
|
|
1427
|
-
const out = [];
|
|
1428
|
-
for (let i = s; i <= e; i += 1) {
|
|
1429
|
-
const content = lines[i - 1] ?? "";
|
|
1430
|
-
out.push(`${i}|${content}`);
|
|
1431
|
-
}
|
|
1432
|
-
if (out.length > AGENT_CONFIG.MAX_READ_LINES) {
|
|
1433
|
-
const truncated = out.slice(0, AGENT_CONFIG.MAX_READ_LINES);
|
|
1434
|
-
truncated.push(`... [truncated: showing ${AGENT_CONFIG.MAX_READ_LINES} of ${out.length} lines]`);
|
|
1435
|
-
return { lines: truncated };
|
|
1436
|
-
}
|
|
1437
|
-
return { lines: out };
|
|
1438
|
-
}
|
|
1439
|
-
async listDirectory(params) {
|
|
1440
|
-
let abs;
|
|
1441
|
-
try {
|
|
1442
|
-
abs = resolveUnderRepo(this.repoRoot, params.path);
|
|
1443
|
-
} catch {
|
|
1444
|
-
return [];
|
|
1445
|
-
}
|
|
1446
|
-
const stat = await import_promises2.default.stat(abs).catch(() => null);
|
|
1447
|
-
if (!stat || !stat.isDirectory()) {
|
|
1448
|
-
return [];
|
|
1449
|
-
}
|
|
1450
|
-
const maxResults = params.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES;
|
|
1451
|
-
const maxDepth = params.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
1452
|
-
const regex = params.pattern ? new RegExp(params.pattern) : null;
|
|
1453
|
-
const repoRoot = this.repoRoot;
|
|
1454
|
-
const results = [];
|
|
1455
|
-
let timedOut = false;
|
|
1456
|
-
const startTime = Date.now();
|
|
1457
|
-
async function walk(dir, depth) {
|
|
1458
|
-
if (Date.now() - startTime > AGENT_CONFIG.LIST_TIMEOUT_MS) {
|
|
1459
|
-
timedOut = true;
|
|
1460
|
-
return;
|
|
1461
|
-
}
|
|
1462
|
-
if (depth > maxDepth || results.length >= maxResults) return;
|
|
1463
|
-
const entries = await import_promises2.default.readdir(dir, { withFileTypes: true });
|
|
1464
|
-
for (const entry of entries) {
|
|
1465
|
-
if (timedOut || results.length >= maxResults) break;
|
|
1466
|
-
if (shouldSkip(entry.name)) continue;
|
|
1467
|
-
if (regex && !regex.test(entry.name)) continue;
|
|
1468
|
-
const full = import_path4.default.join(dir, entry.name);
|
|
1469
|
-
const isDir = entry.isDirectory();
|
|
1470
|
-
results.push({
|
|
1471
|
-
name: entry.name,
|
|
1472
|
-
path: toRepoRelative(repoRoot, full),
|
|
1473
|
-
type: isDir ? "dir" : "file",
|
|
1474
|
-
depth
|
|
1475
|
-
});
|
|
1476
|
-
if (isDir) {
|
|
1477
|
-
await walk(full, depth + 1);
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
|
-
await walk(abs, 0);
|
|
1482
|
-
return results;
|
|
1483
|
-
}
|
|
1484
|
-
};
|
|
1485
|
-
|
|
1486
|
-
// tools/warp_grep/providers/remote.ts
|
|
1487
|
-
var SKIP_NAMES2 = /* @__PURE__ */ new Set([
|
|
1488
|
-
// Version control
|
|
1489
|
-
".git",
|
|
1490
|
-
".svn",
|
|
1491
|
-
".hg",
|
|
1492
|
-
".bzr",
|
|
1493
|
-
// Dependencies
|
|
1494
|
-
"node_modules",
|
|
1495
|
-
"bower_components",
|
|
1496
|
-
".pnpm",
|
|
1497
|
-
".yarn",
|
|
1498
|
-
"vendor",
|
|
1499
|
-
"Pods",
|
|
1500
|
-
".bundle",
|
|
1501
|
-
// Python
|
|
1502
|
-
"__pycache__",
|
|
1503
|
-
".pytest_cache",
|
|
1504
|
-
".mypy_cache",
|
|
1505
|
-
".ruff_cache",
|
|
1506
|
-
".venv",
|
|
1507
|
-
"venv",
|
|
1508
|
-
".tox",
|
|
1509
|
-
".nox",
|
|
1510
|
-
".eggs",
|
|
1511
|
-
// Build outputs
|
|
1512
|
-
"dist",
|
|
1513
|
-
"build",
|
|
1514
|
-
"out",
|
|
1515
|
-
"output",
|
|
1516
|
-
"target",
|
|
1517
|
-
"_build",
|
|
1518
|
-
".next",
|
|
1519
|
-
".nuxt",
|
|
1520
|
-
".output",
|
|
1521
|
-
".vercel",
|
|
1522
|
-
".netlify",
|
|
1523
|
-
// Cache
|
|
1524
|
-
".cache",
|
|
1525
|
-
".parcel-cache",
|
|
1526
|
-
".turbo",
|
|
1527
|
-
".nx",
|
|
1528
|
-
".gradle",
|
|
1529
|
-
// IDE
|
|
1530
|
-
".idea",
|
|
1531
|
-
".vscode",
|
|
1532
|
-
".vs",
|
|
1533
|
-
// Coverage
|
|
1534
|
-
"coverage",
|
|
1535
|
-
".coverage",
|
|
1536
|
-
"htmlcov",
|
|
1537
|
-
".nyc_output",
|
|
1538
|
-
// Temp
|
|
1539
|
-
"tmp",
|
|
1540
|
-
"temp",
|
|
1541
|
-
".tmp",
|
|
1542
|
-
".temp",
|
|
1543
|
-
// Lock files
|
|
1544
|
-
"package-lock.json",
|
|
1545
|
-
"yarn.lock",
|
|
1546
|
-
"pnpm-lock.yaml",
|
|
1547
|
-
"bun.lockb",
|
|
1548
|
-
"Cargo.lock",
|
|
1549
|
-
"Gemfile.lock",
|
|
1550
|
-
"poetry.lock"
|
|
1551
|
-
]);
|
|
1552
|
-
var SKIP_EXTENSIONS2 = /* @__PURE__ */ new Set([
|
|
1553
|
-
".min.js",
|
|
1554
|
-
".min.css",
|
|
1555
|
-
".bundle.js",
|
|
1556
|
-
".wasm",
|
|
1557
|
-
".so",
|
|
1558
|
-
".dll",
|
|
1559
|
-
".pyc",
|
|
1560
|
-
".map",
|
|
1561
|
-
".js.map"
|
|
1562
|
-
]);
|
|
1563
|
-
function shouldSkip2(name) {
|
|
1564
|
-
if (SKIP_NAMES2.has(name)) return true;
|
|
1565
|
-
if (name.startsWith(".")) return true;
|
|
1566
|
-
for (const ext of SKIP_EXTENSIONS2) {
|
|
1567
|
-
if (name.endsWith(ext)) return true;
|
|
1568
|
-
}
|
|
1569
|
-
return false;
|
|
1570
|
-
}
|
|
1571
1616
|
var RemoteCommandsProvider = class {
|
|
1572
1617
|
constructor(repoRoot, commands) {
|
|
1573
1618
|
this.repoRoot = repoRoot;
|
|
@@ -1639,7 +1684,7 @@ var RemoteCommandsProvider = class {
|
|
|
1639
1684
|
for (const fullPath of paths) {
|
|
1640
1685
|
if (fullPath === params.path || fullPath === this.repoRoot) continue;
|
|
1641
1686
|
const name = fullPath.split("/").pop() || "";
|
|
1642
|
-
if (
|
|
1687
|
+
if (shouldSkip(name)) continue;
|
|
1643
1688
|
if (regex && !regex.test(name)) continue;
|
|
1644
1689
|
let relativePath = fullPath;
|
|
1645
1690
|
if (fullPath.startsWith(this.repoRoot)) {
|
|
@@ -1664,9 +1709,13 @@ var RemoteCommandsProvider = class {
|
|
|
1664
1709
|
};
|
|
1665
1710
|
|
|
1666
1711
|
// tools/warp_grep/client.ts
|
|
1712
|
+
async function getLocalProvider(repoRoot, excludes) {
|
|
1713
|
+
const { LocalRipgrepProvider: LocalRipgrepProvider2 } = await Promise.resolve().then(() => (init_local(), local_exports));
|
|
1714
|
+
return new LocalRipgrepProvider2(repoRoot, excludes);
|
|
1715
|
+
}
|
|
1667
1716
|
async function executeToolCall(input, config) {
|
|
1668
1717
|
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
1669
|
-
const provider = config.remoteCommands ? new RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ??
|
|
1718
|
+
const provider = config.remoteCommands ? new RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ?? await getLocalProvider(config.repoRoot, config.excludes);
|
|
1670
1719
|
const result = await runWarpGrep({
|
|
1671
1720
|
query: parsed.query,
|
|
1672
1721
|
repoRoot: config.repoRoot,
|