@morphllm/morphsdk 0.2.202 → 0.2.203
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-2PPYWRMZ.js +3 -4
- package/dist/{chunk-SIFDK4AA.js → chunk-2UIOCSVJ.js} +3 -24
- package/dist/chunk-44OIEPIO.js +4 -23
- package/dist/chunk-4EQQGUZ7.cjs +104 -0
- package/dist/chunk-4OUGA3KS.js +1 -5
- package/dist/chunk-4R5MDGL6.cjs +280 -0
- package/dist/chunk-65W4I66Q.cjs +103 -0
- package/dist/{chunk-3CPI6ZIC.js → chunk-66THRMD7.js} +10 -35
- package/dist/chunk-6TZCVTW5.js +3 -4
- package/dist/chunk-6WP7EA4F.js +2 -4
- package/dist/chunk-74A4HLIO.cjs +42 -0
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/chunk-7NA7X7W2.cjs +77 -0
- package/dist/chunk-7PJYY46L.cjs +2 -0
- package/dist/chunk-AFF6XYKL.cjs +71 -0
- package/dist/{chunk-2XU3XXUE.js → chunk-AJBZA23L.js} +3 -25
- package/dist/chunk-AWFZKS27.cjs +11 -0
- package/dist/{chunk-LVKKICOB.js → chunk-AXEKIRRY.js} +22 -62
- package/dist/chunk-B3FD67F2.cjs +256 -0
- package/dist/chunk-BJBWWIZV.cjs +2 -0
- package/dist/{chunk-UAZKHSEU.js → chunk-E3XNKAMI.js} +5 -15
- package/dist/{chunk-VQDDL3UH.js → chunk-E7FLETFO.js} +2 -8
- package/dist/{chunk-YAM6P5OQ.js → chunk-EI2M567U.js} +2 -6
- package/dist/chunk-EJTL2BOZ.cjs +42 -0
- package/dist/chunk-ETBRAKVV.js +1 -5
- package/dist/{chunk-6OYJC4TZ.js → chunk-EZ2OFDBJ.js} +5 -19
- package/dist/chunk-FBOZIVVQ.js +1 -0
- package/dist/{chunk-CAWQEHKP.js → chunk-GDFPZ3NJ.js} +4 -19
- package/dist/{chunk-UKXCGQPS.js → chunk-GIQAIHUI.js} +8 -33
- package/dist/chunk-GSUQGDCL.cjs +235 -0
- package/dist/{chunk-D6YJ5X3C.js → chunk-H3HRSRR5.js} +4 -12
- package/dist/chunk-HDP4QAZL.js +1 -4
- package/dist/chunk-HMLYJVZM.cjs +410 -0
- package/dist/chunk-IPJA3ZS6.cjs +10 -0
- package/dist/{chunk-XPHNS7NW.js → chunk-IUM6CQYX.js} +3 -12
- package/dist/{chunk-26K5EJD3.js → chunk-J56Q6C4Y.js} +4 -18
- package/dist/chunk-JBTR3FQD.cjs +135 -0
- package/dist/chunk-JNQKQKHS.cjs +81 -0
- package/dist/chunk-JOZC4T6C.cjs +168 -0
- package/dist/{chunk-JEVLCA5C.js → chunk-JUGNTIVU.js} +6 -19
- package/dist/{chunk-NFPRKZQ5.js → chunk-JY6COF3X.js} +5 -22
- package/dist/{chunk-ICCGLO6V.js → chunk-KLVJIC2O.js} +5 -17
- package/dist/chunk-KSZYOX6S.cjs +91 -0
- package/dist/chunk-KVGZ2TSG.cjs +274 -0
- package/dist/chunk-LDM7RNNN.js +1 -0
- package/dist/{chunk-65TUD7JV.js → chunk-LLQH6CCB.js} +10 -28
- package/dist/chunk-M34E2AMK.js +1 -5
- package/dist/chunk-MF56KEI4.js +1 -4
- package/dist/chunk-MLKGABMK.js +1 -3
- package/dist/chunk-MLPZKUCO.js +4 -5
- package/dist/chunk-MWXJ6DZ2.cjs +21 -0
- package/dist/{chunk-IBRBSDLT.js → chunk-N7UKZ5X7.js} +2 -6
- package/dist/chunk-NDUC7OV6.cjs +74 -0
- package/dist/{chunk-PDSIWL7I.js → chunk-NLACTMZT.js} +6 -19
- package/dist/chunk-NNKBKENK.cjs +15 -0
- package/dist/chunk-NRG6QX3L.js +1 -3
- package/dist/chunk-OCCGJ4S6.js +8 -0
- package/dist/chunk-ODY2NKQU.cjs +50 -0
- package/dist/chunk-OM5ZSXQW.cjs +91 -0
- package/dist/chunk-OOEORM7H.cjs +334 -0
- package/dist/chunk-OPDWMD4Q.js +1 -3
- package/dist/chunk-OSL4CNSO.js +7 -23
- package/dist/chunk-OXXMTDOY.cjs +86 -0
- package/dist/chunk-PA3UTI4A.js +1 -4
- package/dist/chunk-QEEAIXL5.cjs +74 -0
- package/dist/chunk-RYVW7RUM.js +2 -6
- package/dist/chunk-S6QBPXBI.cjs +107 -0
- package/dist/chunk-TL34BLQD.cjs +10 -0
- package/dist/chunk-TPZHMD7J.cjs +72 -0
- package/dist/chunk-UAPK3AIJ.js +1 -10
- package/dist/chunk-UF5IKELS.cjs +26 -0
- package/dist/chunk-UNX7V6P6.cjs +60 -0
- package/dist/chunk-UUCRWJJR.cjs +313 -0
- package/dist/chunk-VDFLPO7B.cjs +396 -0
- package/dist/chunk-VHD7CW5O.cjs +43 -0
- package/dist/chunk-VL4QNALG.cjs +50 -0
- package/dist/chunk-WR7LSUIR.cjs +213 -0
- package/dist/chunk-XE6D4J63.cjs +72 -0
- package/dist/chunk-ZLG2M2I4.cjs +21 -0
- package/dist/chunk-ZSHVXDA2.js +4 -10
- package/dist/client.cjs +40 -4360
- package/dist/client.js +32 -37
- package/dist/core/client.cjs +10 -476
- package/dist/core/client.js +6 -11
- package/dist/core/error.cjs +8 -251
- package/dist/core/error.js +4 -9
- package/dist/core/index.cjs +20 -488
- package/dist/core/index.js +8 -19
- package/dist/core/resource.cjs +9 -33
- package/dist/core/resource.js +2 -7
- package/dist/edge.cjs +62 -1111
- package/dist/edge.js +10 -42
- package/dist/index.cjs +115 -4431
- package/dist/index.js +39 -87
- package/dist/modelrouter/core.cjs +28 -648
- package/dist/modelrouter/core.js +8 -21
- package/dist/modelrouter/index.cjs +28 -648
- package/dist/modelrouter/index.js +8 -21
- package/dist/modelrouter/types.cjs +1 -17
- package/dist/modelrouter/types.js +1 -0
- package/dist/subagents/anthropic.cjs +27 -2784
- package/dist/subagents/anthropic.js +19 -24
- package/dist/subagents/index.cjs +14 -95
- package/dist/subagents/index.js +2 -11
- package/dist/subagents/prompts.cjs +14 -93
- package/dist/subagents/prompts.js +2 -11
- package/dist/subagents/types.cjs +1 -17
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/vercel.cjs +27 -2761
- package/dist/subagents/vercel.js +19 -24
- package/dist/tools/compact/core.cjs +12 -548
- package/dist/tools/compact/core.js +8 -13
- package/dist/tools/compact/index.cjs +17 -595
- package/dist/tools/compact/index.js +9 -17
- package/dist/tools/compact/types.cjs +1 -17
- package/dist/tools/compact/types.js +1 -0
- package/dist/tools/fastapply/anthropic.cjs +27 -891
- package/dist/tools/fastapply/anthropic.js +11 -24
- package/dist/tools/fastapply/apply.cjs +28 -672
- package/dist/tools/fastapply/apply.js +4 -19
- package/dist/tools/fastapply/core.cjs +37 -1061
- package/dist/tools/fastapply/core.js +9 -29
- package/dist/tools/fastapply/index.cjs +62 -1062
- package/dist/tools/fastapply/index.js +14 -44
- package/dist/tools/fastapply/openai.cjs +32 -901
- package/dist/tools/fastapply/openai.js +11 -26
- package/dist/tools/fastapply/prompts.cjs +10 -62
- package/dist/tools/fastapply/prompts.js +2 -9
- package/dist/tools/fastapply/types.cjs +1 -17
- package/dist/tools/fastapply/types.js +1 -0
- package/dist/tools/fastapply/vercel.cjs +25 -897
- package/dist/tools/fastapply/vercel.js +11 -22
- package/dist/tools/index.cjs +62 -1062
- package/dist/tools/index.js +14 -44
- package/dist/tools/utils/resilience.cjs +15 -312
- package/dist/tools/utils/resilience.js +3 -12
- package/dist/tools/warp_grep/agent/config.cjs +16 -127
- package/dist/tools/warp_grep/agent/config.js +2 -11
- package/dist/tools/warp_grep/agent/formatter.cjs +12 -48
- package/dist/tools/warp_grep/agent/formatter.js +2 -9
- package/dist/tools/warp_grep/agent/parser.cjs +16 -83
- package/dist/tools/warp_grep/agent/parser.js +2 -11
- package/dist/tools/warp_grep/agent/runner.cjs +15 -1081
- package/dist/tools/warp_grep/agent/runner.js +7 -14
- package/dist/tools/warp_grep/agent/types.cjs +1 -17
- package/dist/tools/warp_grep/agent/types.js +1 -0
- package/dist/tools/warp_grep/anthropic.cjs +47 -2561
- package/dist/tools/warp_grep/anthropic.js +19 -35
- package/dist/tools/warp_grep/client.cjs +49 -2471
- package/dist/tools/warp_grep/client.js +17 -34
- package/dist/tools/warp_grep/gemini.cjs +48 -2490
- package/dist/tools/warp_grep/gemini.js +21 -41
- package/dist/tools/warp_grep/harness.cjs +81 -936
- package/dist/tools/warp_grep/harness.js +12 -51
- package/dist/tools/warp_grep/index.cjs +124 -2575
- package/dist/tools/warp_grep/index.js +24 -87
- package/dist/tools/warp_grep/openai.cjs +53 -2575
- package/dist/tools/warp_grep/openai.js +19 -37
- package/dist/tools/warp_grep/providers/code_storage_http.cjs +12 -65
- package/dist/tools/warp_grep/providers/code_storage_http.js +2 -9
- package/dist/tools/warp_grep/providers/local.cjs +10 -589
- package/dist/tools/warp_grep/providers/local.js +6 -11
- package/dist/tools/warp_grep/providers/remote.cjs +8 -331
- package/dist/tools/warp_grep/providers/remote.js +3 -8
- package/dist/tools/warp_grep/providers/types.cjs +1 -17
- package/dist/tools/warp_grep/providers/types.js +1 -0
- package/dist/tools/warp_grep/utils/files.cjs +9 -42
- package/dist/tools/warp_grep/utils/files.js +2 -7
- package/dist/tools/warp_grep/utils/github.cjs +9 -43
- package/dist/tools/warp_grep/utils/github.js +2 -7
- package/dist/tools/warp_grep/utils/paths.cjs +28 -104
- package/dist/tools/warp_grep/utils/paths.js +2 -17
- package/dist/tools/warp_grep/utils/ripgrep.cjs +9 -103
- package/dist/tools/warp_grep/utils/ripgrep.js +2 -7
- package/dist/tools/warp_grep/vercel.cjs +53 -2557
- package/dist/tools/warp_grep/vercel.js +19 -37
- package/dist/version.cjs +7 -225
- package/dist/version.js +2 -7
- package/package.json +2 -2
- package/dist/chunk-E6TL6MIH.js +0 -203
|
@@ -1,922 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// tools/warp_grep/harness.ts
|
|
31
|
-
var harness_exports = {};
|
|
32
|
-
__export(harness_exports, {
|
|
33
|
-
AGENT_CONFIG: () => AGENT_CONFIG,
|
|
34
|
-
DEFAULT_EXCLUDES: () => DEFAULT_EXCLUDES,
|
|
35
|
-
LocalRipgrepProvider: () => LocalRipgrepProvider,
|
|
36
|
-
buildInitialState: () => buildInitialState,
|
|
37
|
-
calculateContextBudget: () => calculateContextBudget,
|
|
38
|
-
extractPathFromCommand: () => extractPathFromCommand,
|
|
39
|
-
formatListDirectoryTree: () => formatListDirectoryTree,
|
|
40
|
-
formatToolResult: () => formatAgentToolOutput,
|
|
41
|
-
formatTurnMessage: () => formatTurnMessage,
|
|
42
|
-
normalizeFinishFiles: () => normalizeFinishFiles,
|
|
43
|
-
parseFinishFiles: () => parseFinishFiles,
|
|
44
|
-
parseReadLines: () => parseReadLines,
|
|
45
|
-
readFinishFiles: () => readFinishFiles,
|
|
46
|
-
resolveFinishFiles: () => resolveFinishFiles,
|
|
47
|
-
toolGlob: () => toolGlob,
|
|
48
|
-
toolGrep: () => toolGrep,
|
|
49
|
-
toolListDirectory: () => toolListDirectory,
|
|
50
|
-
toolRead: () => toolRead
|
|
51
|
-
});
|
|
52
|
-
module.exports = __toCommonJS(harness_exports);
|
|
53
|
-
|
|
54
|
-
// tools/warp_grep/agent/parser.ts
|
|
55
|
-
function parseReadLines(linesStr) {
|
|
56
|
-
const ranges = [];
|
|
57
|
-
for (const rangeStr of linesStr.split(",")) {
|
|
58
|
-
const trimmed = rangeStr.trim();
|
|
59
|
-
if (!trimmed) continue;
|
|
60
|
-
const parts = trimmed.split("-").map((v) => parseInt(v.trim(), 10));
|
|
61
|
-
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
62
|
-
ranges.push([parts[0], parts[1]]);
|
|
63
|
-
} else if (Number.isFinite(parts[0])) {
|
|
64
|
-
ranges.push([parts[0], parts[0]]);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (ranges.length === 1) return { start: ranges[0][0], end: ranges[0][1] };
|
|
68
|
-
if (ranges.length > 1) return { lines: ranges };
|
|
69
|
-
return {};
|
|
70
|
-
}
|
|
71
|
-
function parseFinishFiles(filesStr) {
|
|
72
|
-
const files = [];
|
|
73
|
-
for (const line of filesStr.trim().split(/\s+/)) {
|
|
74
|
-
const trimmed = line.trim();
|
|
75
|
-
if (!trimmed) continue;
|
|
76
|
-
const searchFrom = /^[A-Za-z]:/.test(trimmed) ? 2 : 0;
|
|
77
|
-
const colonIdx = trimmed.indexOf(":", searchFrom);
|
|
78
|
-
if (colonIdx === -1) {
|
|
79
|
-
files.push({ path: trimmed, lines: "*" });
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
const filePath = trimmed.slice(0, colonIdx);
|
|
83
|
-
const rangesPart = trimmed.slice(colonIdx + 1);
|
|
84
|
-
if (!rangesPart.trim() || rangesPart.trim() === "*") {
|
|
85
|
-
files.push({ path: filePath, lines: "*" });
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
const ranges = [];
|
|
89
|
-
for (const rangeStr of rangesPart.split(",")) {
|
|
90
|
-
const rt = rangeStr.trim();
|
|
91
|
-
if (!rt) continue;
|
|
92
|
-
const parts = rt.split("-").map((v) => parseInt(v.trim(), 10));
|
|
93
|
-
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
94
|
-
ranges.push([parts[0], parts[1]]);
|
|
95
|
-
} else if (Number.isFinite(parts[0])) {
|
|
96
|
-
ranges.push([parts[0], parts[0]]);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
files.push({ path: filePath, lines: ranges.length > 0 ? ranges : "*" });
|
|
100
|
-
}
|
|
101
|
-
return files;
|
|
102
|
-
}
|
|
103
|
-
function extractPathFromCommand(command) {
|
|
104
|
-
const tokens = command.trim().split(/\s+/);
|
|
105
|
-
const pathTokens = tokens.slice(1).filter((t) => !t.startsWith("-") && !t.startsWith("|") && !t.startsWith("\\("));
|
|
106
|
-
return pathTokens[0] || ".";
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// tools/warp_grep/agent/formatter.ts
|
|
110
|
-
var ToolOutputFormatter = class {
|
|
111
|
-
format(toolName, _args, output, options = {}) {
|
|
112
|
-
const name = (toolName ?? "").trim();
|
|
113
|
-
if (!name) {
|
|
114
|
-
return "";
|
|
115
|
-
}
|
|
116
|
-
const payload = output?.toString?.()?.trim?.() ?? "";
|
|
117
|
-
const isError = Boolean(options.isError);
|
|
118
|
-
if (!payload && !isError) {
|
|
119
|
-
return "";
|
|
120
|
-
}
|
|
121
|
-
return `<tool_response>
|
|
122
|
-
${payload}
|
|
123
|
-
</tool_response>`;
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
var sharedFormatter = new ToolOutputFormatter();
|
|
127
|
-
function formatAgentToolOutput(toolName, args, output, options = {}) {
|
|
128
|
-
return sharedFormatter.format(toolName, args, output, options);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// tools/warp_grep/agent/helpers.ts
|
|
132
|
-
var import_path = __toESM(require("path"), 1);
|
|
133
|
-
|
|
134
|
-
// tools/warp_grep/agent/config.ts
|
|
135
|
-
var parseEnvTimeout = (envValue, defaultMs) => {
|
|
136
|
-
if (!envValue) return defaultMs;
|
|
137
|
-
const parsed = parseInt(envValue, 10);
|
|
138
|
-
return isNaN(parsed) || parsed <= 0 ? defaultMs : parsed;
|
|
139
|
-
};
|
|
140
|
-
var AGENT_CONFIG = {
|
|
141
|
-
MAX_TURNS: 6,
|
|
142
|
-
/** Default timeout for model calls. Can be overridden via MORPH_WARP_GREP_TIMEOUT env var (in ms) */
|
|
143
|
-
TIMEOUT_MS: parseEnvTimeout(process.env.MORPH_WARP_GREP_TIMEOUT, 6e4),
|
|
144
|
-
MAX_CONTEXT_CHARS: 321600,
|
|
145
|
-
MAX_OUTPUT_LINES: 200,
|
|
146
|
-
MAX_LIST_RESULTS: 500,
|
|
147
|
-
MAX_READ_LINES: 800,
|
|
148
|
-
MAX_LIST_DEPTH: 3,
|
|
149
|
-
LIST_TIMEOUT_MS: 2e3
|
|
150
|
-
};
|
|
151
|
-
var BUILTIN_EXCLUDES = [
|
|
152
|
-
// Version control
|
|
153
|
-
".git",
|
|
154
|
-
".svn",
|
|
155
|
-
".hg",
|
|
156
|
-
".bzr",
|
|
157
|
-
// Dependencies
|
|
158
|
-
"node_modules",
|
|
159
|
-
"bower_components",
|
|
160
|
-
".pnpm",
|
|
161
|
-
".yarn",
|
|
162
|
-
"vendor",
|
|
163
|
-
"packages",
|
|
164
|
-
"Pods",
|
|
165
|
-
".bundle",
|
|
166
|
-
// Python
|
|
167
|
-
"__pycache__",
|
|
168
|
-
".pytest_cache",
|
|
169
|
-
".mypy_cache",
|
|
170
|
-
".ruff_cache",
|
|
171
|
-
".venv",
|
|
172
|
-
"venv",
|
|
173
|
-
".tox",
|
|
174
|
-
".nox",
|
|
175
|
-
".eggs",
|
|
176
|
-
"*.egg-info",
|
|
177
|
-
// Build outputs
|
|
178
|
-
"dist",
|
|
179
|
-
"build",
|
|
180
|
-
"out",
|
|
181
|
-
"output",
|
|
182
|
-
"target",
|
|
183
|
-
"_build",
|
|
184
|
-
".next",
|
|
185
|
-
".nuxt",
|
|
186
|
-
".output",
|
|
187
|
-
".vercel",
|
|
188
|
-
".netlify",
|
|
189
|
-
// Cache directories
|
|
190
|
-
".cache",
|
|
191
|
-
".parcel-cache",
|
|
192
|
-
".turbo",
|
|
193
|
-
".nx",
|
|
194
|
-
".gradle",
|
|
195
|
-
// IDE/Editor
|
|
196
|
-
".idea",
|
|
197
|
-
".vscode",
|
|
198
|
-
".vs",
|
|
199
|
-
// Coverage
|
|
200
|
-
"coverage",
|
|
201
|
-
".coverage",
|
|
202
|
-
"htmlcov",
|
|
203
|
-
".nyc_output",
|
|
204
|
-
// Temporary
|
|
205
|
-
"tmp",
|
|
206
|
-
"temp",
|
|
207
|
-
".tmp",
|
|
208
|
-
".temp",
|
|
209
|
-
// Lock files
|
|
210
|
-
"package-lock.json",
|
|
211
|
-
"yarn.lock",
|
|
212
|
-
"pnpm-lock.yaml",
|
|
213
|
-
"bun.lockb",
|
|
214
|
-
"Cargo.lock",
|
|
215
|
-
"Gemfile.lock",
|
|
216
|
-
"poetry.lock",
|
|
217
|
-
// Binary/minified
|
|
218
|
-
"*.min.js",
|
|
219
|
-
"*.min.css",
|
|
220
|
-
"*.bundle.js",
|
|
221
|
-
"*.wasm",
|
|
222
|
-
"*.so",
|
|
223
|
-
"*.dll",
|
|
224
|
-
"*.pyc",
|
|
225
|
-
"*.map",
|
|
226
|
-
"*.js.map",
|
|
227
|
-
// Hidden directories catch-all
|
|
228
|
-
".*"
|
|
229
|
-
];
|
|
230
|
-
var DEFAULT_EXCLUDES = (process.env.MORPH_WARP_GREP_EXCLUDE || "").split(",").map((s) => s.trim()).filter(Boolean).concat(BUILTIN_EXCLUDES);
|
|
231
|
-
|
|
232
|
-
// tools/warp_grep/agent/helpers.ts
|
|
233
|
-
function getMessageSize(m) {
|
|
234
|
-
if (m.role === "tool") return m.content.length;
|
|
235
|
-
if (m.role === "assistant") {
|
|
236
|
-
let size = typeof m.content === "string" ? m.content.length : 0;
|
|
237
|
-
if (m.tool_calls) {
|
|
238
|
-
size += m.tool_calls.reduce((s, tc) => s + tc.function.name.length + tc.function.arguments.length, 0);
|
|
239
|
-
}
|
|
240
|
-
return size;
|
|
241
|
-
}
|
|
242
|
-
return m.content.length;
|
|
243
|
-
}
|
|
244
|
-
function formatTurnMessage(turnsUsed, maxTurns) {
|
|
245
|
-
const turnsRemaining = maxTurns - turnsUsed;
|
|
246
|
-
if (turnsRemaining === 1) {
|
|
247
|
-
return `
|
|
248
|
-
You have used ${turnsUsed} turns, you only have 1 turn remaining. You have run out of turns to explore the code base and MUST call the finish tool now`;
|
|
249
|
-
}
|
|
250
|
-
return `
|
|
251
|
-
You have used ${turnsUsed} turn${turnsUsed === 1 ? "" : "s"} and have ${turnsRemaining} remaining`;
|
|
252
|
-
}
|
|
253
|
-
function calculateContextBudget(messages) {
|
|
254
|
-
const totalChars = messages.reduce((sum, m) => sum + getMessageSize(m), 0);
|
|
255
|
-
const maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS;
|
|
256
|
-
const percent = Math.floor(totalChars / maxChars * 100);
|
|
257
|
-
const usedK = Math.floor(totalChars / 1e3);
|
|
258
|
-
const maxK = Math.floor(maxChars / 1e3);
|
|
259
|
-
return `<context_budget>${percent}% (${usedK}K/${maxK}K chars)</context_budget>`;
|
|
260
|
-
}
|
|
261
|
-
async function buildInitialState(repoRoot, searchTerm, provider, options) {
|
|
262
|
-
const budget = calculateContextBudget([]);
|
|
263
|
-
const turnTag = `You have used 0 turns and have ${AGENT_CONFIG.MAX_TURNS} remaining`;
|
|
264
|
-
const treeDepth = options?.search_type === "node_modules" ? 1 : 2;
|
|
265
|
-
const absRoot = repoRoot;
|
|
266
|
-
try {
|
|
267
|
-
const entries = await provider.listDirectory({
|
|
268
|
-
path: ".",
|
|
269
|
-
maxResults: AGENT_CONFIG.MAX_OUTPUT_LINES,
|
|
270
|
-
maxDepth: treeDepth
|
|
271
|
-
});
|
|
272
|
-
const lines = [absRoot];
|
|
273
|
-
for (const e of entries) {
|
|
274
|
-
lines.push(import_path.default.join(absRoot, e.path));
|
|
275
|
-
}
|
|
276
|
-
return `<repo_structure>
|
|
277
|
-
${lines.join("\n")}
|
|
278
|
-
</repo_structure>
|
|
279
|
-
|
|
280
|
-
<search_string>
|
|
281
|
-
${searchTerm}
|
|
282
|
-
</search_string>
|
|
283
|
-
${budget}
|
|
284
|
-
${turnTag}`;
|
|
285
|
-
} catch {
|
|
286
|
-
return `<repo_structure>
|
|
287
|
-
${absRoot}
|
|
288
|
-
</repo_structure>
|
|
289
|
-
|
|
290
|
-
<search_string>
|
|
291
|
-
${searchTerm}
|
|
292
|
-
</search_string>
|
|
293
|
-
${budget}
|
|
294
|
-
${turnTag}`;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
function formatListDirectoryTree(entries) {
|
|
298
|
-
if (!entries.length) return "empty";
|
|
299
|
-
return entries.map((e) => {
|
|
300
|
-
const indent = " ".repeat(e.depth);
|
|
301
|
-
const name = e.type === "dir" ? `${e.name}/` : e.name;
|
|
302
|
-
return `${indent}${name}`;
|
|
303
|
-
}).join("\n");
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
// tools/warp_grep/agent/tools/grep.ts
|
|
307
|
-
async function toolGrep(provider, args) {
|
|
308
|
-
const res = await provider.grep(args);
|
|
309
|
-
if (res.error) {
|
|
310
|
-
return { output: res.error };
|
|
311
|
-
}
|
|
312
|
-
if (!res.lines.length) {
|
|
313
|
-
return { output: "no matches" };
|
|
314
|
-
}
|
|
315
|
-
return { output: res.lines.join("\n") };
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// tools/warp_grep/agent/tools/read.ts
|
|
319
|
-
function isValidRange(start, end) {
|
|
320
|
-
return typeof start === "number" && typeof end === "number" && Number.isFinite(start) && Number.isFinite(end) && start > 0 && end >= start;
|
|
321
|
-
}
|
|
322
|
-
async function toolRead(provider, args) {
|
|
323
|
-
if (args.lines && Array.isArray(args.lines) && args.lines.length > 0) {
|
|
324
|
-
const validRanges = [];
|
|
325
|
-
for (const range of args.lines) {
|
|
326
|
-
if (Array.isArray(range) && range.length >= 2 && isValidRange(range[0], range[1])) {
|
|
327
|
-
validRanges.push([range[0], range[1]]);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
if (validRanges.length === 0) {
|
|
331
|
-
const res2 = await provider.read({ path: args.path });
|
|
332
|
-
if (res2.error) return res2.error;
|
|
333
|
-
if (!res2.lines.length) return "(empty file)";
|
|
334
|
-
return res2.lines.join("\n");
|
|
335
|
-
}
|
|
336
|
-
const chunks = [];
|
|
337
|
-
for (const [start, end] of validRanges) {
|
|
338
|
-
const res2 = await provider.read({ path: args.path, start, end });
|
|
339
|
-
if (res2.error) return res2.error;
|
|
340
|
-
chunks.push(res2.lines.join("\n"));
|
|
341
|
-
}
|
|
342
|
-
if (chunks.every((c) => c === "")) return "(empty file)";
|
|
343
|
-
return chunks.join("\n...\n");
|
|
344
|
-
}
|
|
345
|
-
const res = await provider.read({ path: args.path, start: args.start, end: args.end });
|
|
346
|
-
if (res.error) {
|
|
347
|
-
return res.error;
|
|
348
|
-
}
|
|
349
|
-
if (!res.lines.length) return "(empty file)";
|
|
350
|
-
return res.lines.join("\n");
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// tools/warp_grep/agent/tools/list_directory.ts
|
|
354
|
-
var import_path2 = __toESM(require("path"), 1);
|
|
355
|
-
async function toolListDirectory(provider, args, repoRoot) {
|
|
356
|
-
const maxResults = args.maxResults ?? AGENT_CONFIG.MAX_LIST_RESULTS;
|
|
357
|
-
const maxDepth = args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
358
|
-
const entries = await provider.listDirectory({
|
|
359
|
-
path: args.path,
|
|
360
|
-
pattern: args.pattern ?? null,
|
|
361
|
-
maxResults,
|
|
362
|
-
maxDepth
|
|
363
|
-
});
|
|
364
|
-
if (!entries.length) return "empty";
|
|
365
|
-
if (repoRoot) {
|
|
366
|
-
const absRoot = repoRoot;
|
|
367
|
-
const lines = entries.map((e) => import_path2.default.join(absRoot, e.path));
|
|
368
|
-
return lines.join("\n");
|
|
369
|
-
}
|
|
370
|
-
return entries.map((e) => e.path).join("\n");
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// tools/warp_grep/agent/tools/glob.ts
|
|
374
|
-
async function toolGlob(provider, args) {
|
|
375
|
-
const res = await provider.glob(args);
|
|
376
|
-
if (res.error) {
|
|
377
|
-
return res.error;
|
|
378
|
-
}
|
|
379
|
-
if (!res.files.length) {
|
|
380
|
-
return "no matches";
|
|
381
|
-
}
|
|
382
|
-
const header = `Found ${res.totalFound} file(s) matching "${args.pattern}" within ${res.searchDir}, sorted by modification time (newest first):`;
|
|
383
|
-
const body = res.files.join("\n");
|
|
384
|
-
const truncated = res.totalFound > res.files.length ? `
|
|
385
|
-
[${res.totalFound - res.files.length} files truncated]` : "";
|
|
386
|
-
return `${header}
|
|
387
|
-
---
|
|
388
|
-
${body}
|
|
389
|
-
---${truncated}`;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// tools/warp_grep/agent/tools/finish.ts
|
|
393
|
-
function isValidRange2(range) {
|
|
394
|
-
return Array.isArray(range) && range.length >= 2 && typeof range[0] === "number" && typeof range[1] === "number" && Number.isFinite(range[0]) && Number.isFinite(range[1]) && range[0] > 0 && range[1] >= range[0];
|
|
395
|
-
}
|
|
396
|
-
function extractValidRanges(lines) {
|
|
397
|
-
if (!Array.isArray(lines)) return null;
|
|
398
|
-
const valid = [];
|
|
399
|
-
for (const range of lines) {
|
|
400
|
-
if (isValidRange2(range)) {
|
|
401
|
-
valid.push([range[0], range[1]]);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return valid.length > 0 ? valid : null;
|
|
405
|
-
}
|
|
406
|
-
function normalizeFinishFiles(files) {
|
|
407
|
-
return files.map((f) => {
|
|
408
|
-
if (f.lines === "*") return { path: f.path, lines: "*" };
|
|
409
|
-
const validRanges = extractValidRanges(f.lines);
|
|
410
|
-
if (!validRanges) return { path: f.path, lines: "*" };
|
|
411
|
-
return { path: f.path, lines: mergeRanges(validRanges) };
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
async function readFinishFiles(repoRoot, files, reader) {
|
|
415
|
-
const out = [];
|
|
416
|
-
for (const f of files) {
|
|
417
|
-
const validRanges = f.lines === "*" ? null : extractValidRanges(f.lines);
|
|
418
|
-
if (f.lines === "*" || !validRanges) {
|
|
419
|
-
const lines = await reader(f.path);
|
|
420
|
-
out.push({ path: f.path, ranges: "*", content: lines.join("\n") });
|
|
421
|
-
} else {
|
|
422
|
-
const ranges = mergeRanges(validRanges);
|
|
423
|
-
const chunks = [];
|
|
424
|
-
for (let i = 0; i < ranges.length; i++) {
|
|
425
|
-
const [s, e] = ranges[i];
|
|
426
|
-
if (i === 0 && s > 1) {
|
|
427
|
-
chunks.push(`// ... existing code, block starting at line ${s} ...`);
|
|
428
|
-
} else if (i > 0) {
|
|
429
|
-
chunks.push(`// ... existing code, block starting at line ${s} ...`);
|
|
430
|
-
}
|
|
431
|
-
const lines = await reader(f.path, s, e);
|
|
432
|
-
chunks.push(lines.join("\n"));
|
|
433
|
-
}
|
|
434
|
-
out.push({ path: f.path, ranges, content: chunks.join("\n") });
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
return out;
|
|
438
|
-
}
|
|
439
|
-
function mergeRanges(ranges) {
|
|
440
|
-
if (!ranges.length) return [];
|
|
441
|
-
const sorted = [...ranges].sort((a, b) => a[0] - b[0]);
|
|
442
|
-
const merged = [];
|
|
443
|
-
let [cs, ce] = sorted[0];
|
|
444
|
-
for (let i = 1; i < sorted.length; i++) {
|
|
445
|
-
const [s, e] = sorted[i];
|
|
446
|
-
if (s <= ce + 1) {
|
|
447
|
-
ce = Math.max(ce, e);
|
|
448
|
-
} else {
|
|
449
|
-
merged.push([cs, ce]);
|
|
450
|
-
cs = s;
|
|
451
|
-
ce = e;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
merged.push([cs, ce]);
|
|
455
|
-
return merged;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
// tools/warp_grep/providers/local.ts
|
|
459
|
-
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
460
|
-
var import_path4 = __toESM(require("path"), 1);
|
|
461
|
-
|
|
462
|
-
// tools/warp_grep/utils/ripgrep.ts
|
|
463
|
-
var import_child_process = require("child_process");
|
|
464
|
-
var resolvedRgPath = null;
|
|
465
|
-
var rgPathChecked = false;
|
|
466
|
-
function spawnRg(rgBinary, args, opts) {
|
|
467
|
-
return new Promise((resolve) => {
|
|
468
|
-
const child = (0, import_child_process.spawn)(rgBinary, args, {
|
|
469
|
-
cwd: opts?.cwd,
|
|
470
|
-
env: { ...process.env, ...opts?.env || {} },
|
|
471
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
472
|
-
});
|
|
473
|
-
let stdout = "";
|
|
474
|
-
let stderr = "";
|
|
475
|
-
child.stdout.on("data", (d) => stdout += d.toString());
|
|
476
|
-
child.stderr.on("data", (d) => stderr += d.toString());
|
|
477
|
-
child.on("close", (code) => {
|
|
478
|
-
resolve({ stdout, stderr, exitCode: typeof code === "number" ? code : -1 });
|
|
479
|
-
});
|
|
480
|
-
child.on("error", () => {
|
|
481
|
-
resolve({ stdout: "", stderr: "Failed to spawn ripgrep.", exitCode: -1 });
|
|
482
|
-
});
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
async function preferredRgPath() {
|
|
486
|
-
try {
|
|
487
|
-
return (await import("@vscode/ripgrep")).rgPath ?? "rg";
|
|
488
|
-
} catch {
|
|
489
|
-
return "rg";
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
function isBinaryFailure(result) {
|
|
493
|
-
if (result.exitCode === -1) return true;
|
|
494
|
-
if (result.stderr.includes("jemalloc") || result.stderr.includes("Unsupported system page size")) return true;
|
|
495
|
-
if (result.exitCode === 134) return true;
|
|
496
|
-
return false;
|
|
497
|
-
}
|
|
498
|
-
async function runRipgrep(args, opts) {
|
|
499
|
-
if (rgPathChecked && resolvedRgPath) {
|
|
500
|
-
return spawnRg(resolvedRgPath, args, opts);
|
|
501
|
-
}
|
|
502
|
-
if (!rgPathChecked) {
|
|
503
|
-
const rgPath = await preferredRgPath();
|
|
504
|
-
const result = await spawnRg(rgPath, args, opts);
|
|
505
|
-
if (!isBinaryFailure(result)) {
|
|
506
|
-
resolvedRgPath = rgPath;
|
|
507
|
-
rgPathChecked = true;
|
|
508
|
-
return result;
|
|
509
|
-
}
|
|
510
|
-
const fallbackResult = await spawnRg("rg", args, opts);
|
|
511
|
-
if (!isBinaryFailure(fallbackResult)) {
|
|
512
|
-
resolvedRgPath = "rg";
|
|
513
|
-
rgPathChecked = true;
|
|
514
|
-
return fallbackResult;
|
|
515
|
-
}
|
|
516
|
-
rgPathChecked = true;
|
|
517
|
-
return {
|
|
518
|
-
stdout: "",
|
|
519
|
-
stderr: "Failed to spawn ripgrep. Neither bundled nor system rg is available.",
|
|
520
|
-
exitCode: -1
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
return {
|
|
524
|
-
stdout: "",
|
|
525
|
-
stderr: "Failed to spawn ripgrep. Neither bundled nor system rg is available.",
|
|
526
|
-
exitCode: -1
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// tools/warp_grep/utils/paths.ts
|
|
531
|
-
var import_fs = __toESM(require("fs"), 1);
|
|
532
|
-
var import_path3 = __toESM(require("path"), 1);
|
|
533
|
-
function resolveUnderRepo(repoRoot, targetPath) {
|
|
534
|
-
const absRoot = import_path3.default.resolve(repoRoot);
|
|
535
|
-
const resolved = import_path3.default.resolve(absRoot, targetPath);
|
|
536
|
-
ensureWithinRepo(absRoot, resolved);
|
|
537
|
-
return resolved;
|
|
538
|
-
}
|
|
539
|
-
function ensureWithinRepo(repoRoot, absTarget) {
|
|
540
|
-
const rel = import_path3.default.relative(import_path3.default.resolve(repoRoot), import_path3.default.resolve(absTarget));
|
|
541
|
-
if (rel.startsWith("..") || import_path3.default.isAbsolute(rel)) {
|
|
542
|
-
throw new Error(`Path outside repository root: ${absTarget}`);
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
function toRepoRelative(repoRoot, absPath) {
|
|
546
|
-
return import_path3.default.relative(import_path3.default.resolve(repoRoot), import_path3.default.resolve(absPath));
|
|
547
|
-
}
|
|
548
|
-
function isSymlink(p) {
|
|
549
|
-
try {
|
|
550
|
-
const st = import_fs.default.lstatSync(p);
|
|
551
|
-
return st.isSymbolicLink();
|
|
552
|
-
} catch {
|
|
553
|
-
return false;
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
function fixPathRepetition(fullPath) {
|
|
557
|
-
const segments = fullPath.split(import_path3.default.sep).filter(Boolean);
|
|
558
|
-
if (segments.length < 2) return null;
|
|
559
|
-
for (let len = Math.floor(segments.length / 2); len >= 1; len--) {
|
|
560
|
-
for (let i = 0; i <= segments.length - 2 * len; i++) {
|
|
561
|
-
const first = segments.slice(i, i + len);
|
|
562
|
-
const second = segments.slice(i + len, i + 2 * len);
|
|
563
|
-
if (first.every((seg, idx) => seg === second[idx])) {
|
|
564
|
-
const fixed = [...segments.slice(0, i), ...segments.slice(i + len)];
|
|
565
|
-
return import_path3.default.sep + fixed.join(import_path3.default.sep);
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
return null;
|
|
570
|
-
}
|
|
571
|
-
function isTextualFile(filePath, maxBytes = 2e6) {
|
|
572
|
-
try {
|
|
573
|
-
const st = import_fs.default.statSync(filePath);
|
|
574
|
-
if (!st.isFile()) return false;
|
|
575
|
-
if (st.size > maxBytes) return false;
|
|
576
|
-
const fd = import_fs.default.openSync(filePath, "r");
|
|
577
|
-
const buf = Buffer.alloc(512);
|
|
578
|
-
const read = import_fs.default.readSync(fd, buf, 0, buf.length, 0);
|
|
579
|
-
import_fs.default.closeSync(fd);
|
|
580
|
-
for (let i = 0; i < read; i++) {
|
|
581
|
-
const c = buf[i];
|
|
582
|
-
if (c === 0) return false;
|
|
583
|
-
}
|
|
584
|
-
return true;
|
|
585
|
-
} catch {
|
|
586
|
-
return false;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
// tools/warp_grep/utils/files.ts
|
|
591
|
-
var import_promises = __toESM(require("fs/promises"), 1);
|
|
592
|
-
async function readAllLines(filePath) {
|
|
593
|
-
const content = await import_promises.default.readFile(filePath, "utf8");
|
|
594
|
-
return content.split(/\r?\n/);
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
// tools/warp_grep/providers/local.ts
|
|
598
|
-
var SKIP_NAMES = /* @__PURE__ */ new Set([
|
|
599
|
-
// Version control
|
|
600
|
-
".git",
|
|
601
|
-
".svn",
|
|
602
|
-
".hg",
|
|
603
|
-
".bzr",
|
|
604
|
-
// Dependencies
|
|
605
|
-
"node_modules",
|
|
606
|
-
"bower_components",
|
|
607
|
-
".pnpm",
|
|
608
|
-
".yarn",
|
|
609
|
-
"vendor",
|
|
610
|
-
"Pods",
|
|
611
|
-
".bundle",
|
|
612
|
-
// Python
|
|
613
|
-
"__pycache__",
|
|
614
|
-
".pytest_cache",
|
|
615
|
-
".mypy_cache",
|
|
616
|
-
".ruff_cache",
|
|
617
|
-
".venv",
|
|
618
|
-
"venv",
|
|
619
|
-
".tox",
|
|
620
|
-
".nox",
|
|
621
|
-
".eggs",
|
|
622
|
-
// Build outputs
|
|
623
|
-
"dist",
|
|
624
|
-
"build",
|
|
625
|
-
"out",
|
|
626
|
-
"output",
|
|
627
|
-
"target",
|
|
628
|
-
"_build",
|
|
629
|
-
".next",
|
|
630
|
-
".nuxt",
|
|
631
|
-
".output",
|
|
632
|
-
".vercel",
|
|
633
|
-
".netlify",
|
|
634
|
-
// Cache
|
|
635
|
-
".cache",
|
|
636
|
-
".parcel-cache",
|
|
637
|
-
".turbo",
|
|
638
|
-
".nx",
|
|
639
|
-
".gradle",
|
|
640
|
-
// IDE
|
|
641
|
-
".idea",
|
|
642
|
-
".vscode",
|
|
643
|
-
".vs",
|
|
644
|
-
// Coverage
|
|
645
|
-
"coverage",
|
|
646
|
-
".coverage",
|
|
647
|
-
"htmlcov",
|
|
648
|
-
".nyc_output",
|
|
649
|
-
// Temp
|
|
650
|
-
"tmp",
|
|
651
|
-
"temp",
|
|
652
|
-
".tmp",
|
|
653
|
-
".temp",
|
|
654
|
-
// Lock files
|
|
655
|
-
"package-lock.json",
|
|
656
|
-
"yarn.lock",
|
|
657
|
-
"pnpm-lock.yaml",
|
|
658
|
-
"bun.lockb",
|
|
659
|
-
"Cargo.lock",
|
|
660
|
-
"Gemfile.lock",
|
|
661
|
-
"poetry.lock"
|
|
662
|
-
]);
|
|
663
|
-
var SKIP_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
664
|
-
".min.js",
|
|
665
|
-
".min.css",
|
|
666
|
-
".bundle.js",
|
|
667
|
-
".wasm",
|
|
668
|
-
".so",
|
|
669
|
-
".dll",
|
|
670
|
-
".pyc",
|
|
671
|
-
".map",
|
|
672
|
-
".js.map"
|
|
673
|
-
]);
|
|
674
|
-
function shouldSkip(name, allowNames) {
|
|
675
|
-
if (allowNames?.has(name)) return false;
|
|
676
|
-
if (SKIP_NAMES.has(name)) return true;
|
|
677
|
-
if (name.startsWith(".")) return true;
|
|
678
|
-
for (const ext of SKIP_EXTENSIONS) {
|
|
679
|
-
if (name.endsWith(ext)) return true;
|
|
680
|
-
}
|
|
681
|
-
return false;
|
|
682
|
-
}
|
|
683
|
-
var LocalRipgrepProvider = class {
|
|
684
|
-
constructor(repoRoot, excludes = DEFAULT_EXCLUDES, options) {
|
|
685
|
-
this.repoRoot = repoRoot;
|
|
686
|
-
this.excludes = excludes;
|
|
687
|
-
if (options?.allowNames?.length) {
|
|
688
|
-
this.allowNames = new Set(options.allowNames);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
allowNames;
|
|
692
|
-
async grep(params) {
|
|
693
|
-
let abs;
|
|
694
|
-
try {
|
|
695
|
-
abs = resolveUnderRepo(this.repoRoot, params.path);
|
|
696
|
-
} catch (err) {
|
|
697
|
-
return {
|
|
698
|
-
lines: [],
|
|
699
|
-
error: `[PATH ERROR] ${err instanceof Error ? err.message : String(err)}`
|
|
700
|
-
};
|
|
701
|
-
}
|
|
702
|
-
const stat = await import_promises2.default.stat(abs).catch(() => null);
|
|
703
|
-
if (!stat) return { lines: [] };
|
|
704
|
-
const targetArg = abs === import_path4.default.resolve(this.repoRoot) ? "." : toRepoRelative(this.repoRoot, abs);
|
|
705
|
-
const contextLines = params.context_lines !== void 0 ? String(params.context_lines) : "1";
|
|
706
|
-
const args = [
|
|
707
|
-
"--no-config",
|
|
708
|
-
"--no-heading",
|
|
709
|
-
"--with-filename",
|
|
710
|
-
"--line-number",
|
|
711
|
-
"--color=never",
|
|
712
|
-
"--trim",
|
|
713
|
-
"--max-columns=400",
|
|
714
|
-
"-C",
|
|
715
|
-
contextLines,
|
|
716
|
-
...params.case_sensitive === false ? ["--ignore-case"] : [],
|
|
717
|
-
...params.glob ? ["--glob", params.glob] : [],
|
|
718
|
-
...this.excludes.filter((e) => !this.allowNames?.has(e)).flatMap((e) => ["-g", `!${e}`]),
|
|
719
|
-
params.pattern,
|
|
720
|
-
targetArg || "."
|
|
721
|
-
];
|
|
722
|
-
const res = await runRipgrep(args, { cwd: this.repoRoot });
|
|
723
|
-
if (res.exitCode === -1) {
|
|
724
|
-
return {
|
|
725
|
-
lines: [],
|
|
726
|
-
error: `[RIPGREP NOT AVAILABLE] ripgrep (rg) is required but failed to execute. Please install it:
|
|
727
|
-
\u2022 macOS: brew install ripgrep
|
|
728
|
-
\u2022 Ubuntu/Debian: apt install ripgrep
|
|
729
|
-
\u2022 Windows: choco install ripgrep
|
|
730
|
-
\u2022 Or visit: https://github.com/BurntSushi/ripgrep#installation
|
|
731
|
-
Exit code: ${res.exitCode}${res.stderr ? `
|
|
732
|
-
Details: ${res.stderr}` : ""}`
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
if (res.exitCode !== 0 && res.exitCode !== 1) {
|
|
736
|
-
return {
|
|
737
|
-
lines: [],
|
|
738
|
-
error: `[RIPGREP ERROR] grep failed with exit code ${res.exitCode}${res.stderr ? `: ${res.stderr}` : ""}`
|
|
739
|
-
};
|
|
740
|
-
}
|
|
741
|
-
const lines = (res.stdout || "").trim().split(/\r?\n/).filter((l) => l.length > 0);
|
|
742
|
-
if (lines.length > AGENT_CONFIG.MAX_OUTPUT_LINES) {
|
|
743
|
-
const truncated = lines.slice(0, AGENT_CONFIG.MAX_OUTPUT_LINES);
|
|
744
|
-
truncated.push(`... (output truncated at ${AGENT_CONFIG.MAX_OUTPUT_LINES} of ${lines.length} lines)`);
|
|
745
|
-
return { lines: truncated };
|
|
746
|
-
}
|
|
747
|
-
return { lines };
|
|
748
|
-
}
|
|
749
|
-
async read(params) {
|
|
750
|
-
let abs;
|
|
751
|
-
try {
|
|
752
|
-
abs = resolveUnderRepo(this.repoRoot, params.path);
|
|
753
|
-
} catch (err) {
|
|
754
|
-
return {
|
|
755
|
-
lines: [],
|
|
756
|
-
error: `[PATH ERROR] ${err instanceof Error ? err.message : String(err)}`
|
|
757
|
-
};
|
|
758
|
-
}
|
|
759
|
-
let stat = await import_promises2.default.stat(abs).catch(() => null);
|
|
760
|
-
if (!stat || !stat.isFile()) {
|
|
761
|
-
const fixedPath = fixPathRepetition(abs);
|
|
762
|
-
if (fixedPath) {
|
|
763
|
-
const fixedStat = await import_promises2.default.stat(fixedPath).catch(() => null);
|
|
764
|
-
if (fixedStat?.isFile()) {
|
|
765
|
-
abs = fixedPath;
|
|
766
|
-
stat = fixedStat;
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
if (!stat || !stat.isFile()) {
|
|
771
|
-
return {
|
|
772
|
-
lines: [],
|
|
773
|
-
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.`
|
|
774
|
-
};
|
|
775
|
-
}
|
|
776
|
-
if (isSymlink(abs)) {
|
|
777
|
-
return {
|
|
778
|
-
lines: [],
|
|
779
|
-
error: `[SYMLINK] You tried to read "${params.path}" but this is a symlink. Try reading the actual file it points to instead.`
|
|
780
|
-
};
|
|
781
|
-
}
|
|
782
|
-
if (!isTextualFile(abs)) {
|
|
783
|
-
return {
|
|
784
|
-
lines: [],
|
|
785
|
-
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.`
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
let lines;
|
|
789
|
-
try {
|
|
790
|
-
lines = await readAllLines(abs);
|
|
791
|
-
} catch (err) {
|
|
792
|
-
return {
|
|
793
|
-
lines: [],
|
|
794
|
-
error: `[READ ERROR] Failed to read "${params.path}": ${err instanceof Error ? err.message : String(err)}`
|
|
795
|
-
};
|
|
796
|
-
}
|
|
797
|
-
const total = lines.length;
|
|
798
|
-
const rawStart = params.start;
|
|
799
|
-
const rawEnd = params.end;
|
|
800
|
-
let s = 1;
|
|
801
|
-
let e = total;
|
|
802
|
-
const startValid = rawStart === void 0 || Number.isFinite(rawStart) && rawStart > 0;
|
|
803
|
-
const endValid = rawEnd === void 0 || Number.isFinite(rawEnd) && rawEnd > 0;
|
|
804
|
-
if (startValid && endValid) {
|
|
805
|
-
s = rawStart ?? 1;
|
|
806
|
-
e = Math.min(rawEnd ?? total, total);
|
|
807
|
-
if (s > total && total > 0 || s > e) {
|
|
808
|
-
s = 1;
|
|
809
|
-
e = total;
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
const out = [];
|
|
813
|
-
for (let i = s; i <= e; i += 1) {
|
|
814
|
-
const content = lines[i - 1] ?? "";
|
|
815
|
-
out.push(`${i}|${content}`);
|
|
816
|
-
}
|
|
817
|
-
if (out.length > AGENT_CONFIG.MAX_READ_LINES) {
|
|
818
|
-
const truncated = out.slice(0, AGENT_CONFIG.MAX_READ_LINES);
|
|
819
|
-
truncated.push(`... (output truncated at ${AGENT_CONFIG.MAX_READ_LINES} of ${out.length} lines)`);
|
|
820
|
-
return { lines: truncated };
|
|
821
|
-
}
|
|
822
|
-
return { lines: out };
|
|
823
|
-
}
|
|
824
|
-
async listDirectory(params) {
|
|
825
|
-
let abs;
|
|
826
|
-
try {
|
|
827
|
-
abs = resolveUnderRepo(this.repoRoot, params.path);
|
|
828
|
-
} catch {
|
|
829
|
-
return [];
|
|
830
|
-
}
|
|
831
|
-
const stat = await import_promises2.default.stat(abs).catch(() => null);
|
|
832
|
-
if (!stat || !stat.isDirectory()) {
|
|
833
|
-
return [];
|
|
834
|
-
}
|
|
835
|
-
const maxResults = params.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES;
|
|
836
|
-
const maxDepth = params.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
837
|
-
const regex = params.pattern ? new RegExp(params.pattern) : null;
|
|
838
|
-
const repoRoot = this.repoRoot;
|
|
839
|
-
const allowNames = this.allowNames;
|
|
840
|
-
const results = [];
|
|
841
|
-
let timedOut = false;
|
|
842
|
-
const startTime = Date.now();
|
|
843
|
-
async function walk(dir, depth) {
|
|
844
|
-
if (Date.now() - startTime > AGENT_CONFIG.LIST_TIMEOUT_MS) {
|
|
845
|
-
timedOut = true;
|
|
846
|
-
return;
|
|
847
|
-
}
|
|
848
|
-
if (depth > maxDepth || results.length >= maxResults) return;
|
|
849
|
-
let entries;
|
|
850
|
-
try {
|
|
851
|
-
entries = await import_promises2.default.readdir(dir, { withFileTypes: true });
|
|
852
|
-
} catch {
|
|
853
|
-
return;
|
|
854
|
-
}
|
|
855
|
-
for (const entry of entries) {
|
|
856
|
-
if (timedOut || results.length >= maxResults) break;
|
|
857
|
-
if (shouldSkip(entry.name, allowNames)) continue;
|
|
858
|
-
if (regex && !regex.test(entry.name)) continue;
|
|
859
|
-
const full = import_path4.default.join(dir, entry.name);
|
|
860
|
-
const isDir = entry.isDirectory();
|
|
861
|
-
results.push({
|
|
862
|
-
name: entry.name,
|
|
863
|
-
path: toRepoRelative(repoRoot, full),
|
|
864
|
-
type: isDir ? "dir" : "file",
|
|
865
|
-
depth
|
|
866
|
-
});
|
|
867
|
-
if (isDir) {
|
|
868
|
-
await walk(full, depth + 1);
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
await walk(abs, 0);
|
|
873
|
-
return results;
|
|
874
|
-
}
|
|
875
|
-
async glob(params) {
|
|
876
|
-
let abs;
|
|
877
|
-
try {
|
|
878
|
-
abs = params.path ? resolveUnderRepo(this.repoRoot, params.path) : this.repoRoot;
|
|
879
|
-
} catch (err) {
|
|
880
|
-
return { files: [], searchDir: this.repoRoot, totalFound: 0, error: `[PATH ERROR] ${err instanceof Error ? err.message : String(err)}` };
|
|
881
|
-
}
|
|
882
|
-
const stat = await import_promises2.default.stat(abs).catch(() => null);
|
|
883
|
-
if (!stat || !stat.isDirectory()) {
|
|
884
|
-
return { files: [], searchDir: abs, totalFound: 0, error: `[PATH ERROR] Directory not found: ${params.path || "."}` };
|
|
885
|
-
}
|
|
886
|
-
const targetArg = abs === import_path4.default.resolve(this.repoRoot) ? "." : toRepoRelative(this.repoRoot, abs);
|
|
887
|
-
const args = [
|
|
888
|
-
"--no-config",
|
|
889
|
-
"--files",
|
|
890
|
-
"--color=never",
|
|
891
|
-
"-g",
|
|
892
|
-
params.pattern,
|
|
893
|
-
...this.excludes.filter((e) => !this.allowNames?.has(e)).flatMap((e) => ["-g", `!${e}`]),
|
|
894
|
-
targetArg || "."
|
|
895
|
-
];
|
|
896
|
-
const res = await runRipgrep(args, { cwd: this.repoRoot });
|
|
897
|
-
if (res.exitCode === -1) {
|
|
898
|
-
return { files: [], searchDir: abs, totalFound: 0, error: `[RIPGREP NOT AVAILABLE] ripgrep (rg) is required for glob search.` };
|
|
899
|
-
}
|
|
900
|
-
if (res.exitCode !== 0 && res.exitCode !== 1) {
|
|
901
|
-
return { files: [], searchDir: abs, totalFound: 0, error: `[GLOB ERROR] glob failed with exit code ${res.exitCode}${res.stderr ? `: ${res.stderr}` : ""}` };
|
|
902
|
-
}
|
|
903
|
-
const absRoot = import_path4.default.resolve(this.repoRoot);
|
|
904
|
-
const relFiles = (res.stdout || "").trim().split(/\r?\n/).filter((l) => l.length > 0);
|
|
905
|
-
const absFiles = relFiles.map((f) => import_path4.default.resolve(absRoot, f));
|
|
906
|
-
const withMtime = [];
|
|
907
|
-
for (const f of absFiles) {
|
|
908
|
-
const s = await import_promises2.default.stat(f).catch(() => null);
|
|
909
|
-
withMtime.push({ file: f, mtime: s?.mtimeMs ?? 0 });
|
|
910
|
-
}
|
|
911
|
-
withMtime.sort((a, b) => b.mtime - a.mtime);
|
|
912
|
-
const totalFound = withMtime.length;
|
|
913
|
-
return { files: withMtime.slice(0, 100).map((f) => f.file), searchDir: abs, totalFound };
|
|
914
|
-
}
|
|
915
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkOOEORM7H_cjs = require('../../chunk-OOEORM7H.cjs');
|
|
4
|
+
require('../../chunk-XE6D4J63.cjs');
|
|
5
|
+
require('../../chunk-NNKBKENK.cjs');
|
|
6
|
+
require('../../chunk-QEEAIXL5.cjs');
|
|
7
|
+
var chunkUF5IKELS_cjs = require('../../chunk-UF5IKELS.cjs');
|
|
8
|
+
var chunkKVGZ2TSG_cjs = require('../../chunk-KVGZ2TSG.cjs');
|
|
9
|
+
var chunk4EQQGUZ7_cjs = require('../../chunk-4EQQGUZ7.cjs');
|
|
10
|
+
var chunkUNX7V6P6_cjs = require('../../chunk-UNX7V6P6.cjs');
|
|
11
|
+
require('../../chunk-75ZPJI57.cjs');
|
|
916
12
|
|
|
917
13
|
// tools/warp_grep/harness.ts
|
|
918
14
|
async function resolveFinishFiles(provider, files) {
|
|
919
|
-
return readFinishFiles("", files, async (p, s, e) => {
|
|
15
|
+
return chunkKVGZ2TSG_cjs.readFinishFiles("", files, async (p, s, e) => {
|
|
920
16
|
const r = await provider.read({ path: p, start: s, end: e });
|
|
921
17
|
return r.lines.map((l) => {
|
|
922
18
|
const idx = l.indexOf("|");
|
|
@@ -924,24 +20,73 @@ async function resolveFinishFiles(provider, files) {
|
|
|
924
20
|
});
|
|
925
21
|
});
|
|
926
22
|
}
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
23
|
+
|
|
24
|
+
Object.defineProperty(exports, "LocalRipgrepProvider", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return chunkOOEORM7H_cjs.LocalRipgrepProvider; }
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "formatToolResult", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return chunkUF5IKELS_cjs.formatAgentToolOutput; }
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, "buildInitialState", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () { return chunkKVGZ2TSG_cjs.buildInitialState; }
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "calculateContextBudget", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return chunkKVGZ2TSG_cjs.calculateContextBudget; }
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "formatListDirectoryTree", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () { return chunkKVGZ2TSG_cjs.formatListDirectoryTree; }
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(exports, "formatTurnMessage", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function () { return chunkKVGZ2TSG_cjs.formatTurnMessage; }
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "normalizeFinishFiles", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () { return chunkKVGZ2TSG_cjs.normalizeFinishFiles; }
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(exports, "readFinishFiles", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () { return chunkKVGZ2TSG_cjs.readFinishFiles; }
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(exports, "toolGlob", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function () { return chunkKVGZ2TSG_cjs.toolGlob; }
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "toolGrep", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () { return chunkKVGZ2TSG_cjs.toolGrep; }
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(exports, "toolListDirectory", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () { return chunkKVGZ2TSG_cjs.toolListDirectory; }
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(exports, "toolRead", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function () { return chunkKVGZ2TSG_cjs.toolRead; }
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "AGENT_CONFIG", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () { return chunk4EQQGUZ7_cjs.AGENT_CONFIG; }
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(exports, "DEFAULT_EXCLUDES", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () { return chunk4EQQGUZ7_cjs.DEFAULT_EXCLUDES; }
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(exports, "extractPathFromCommand", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function () { return chunkUNX7V6P6_cjs.extractPathFromCommand; }
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, "parseFinishFiles", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () { return chunkUNX7V6P6_cjs.parseFinishFiles; }
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(exports, "parseReadLines", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
get: function () { return chunkUNX7V6P6_cjs.parseReadLines; }
|
|
947
91
|
});
|
|
92
|
+
exports.resolveFinishFiles = resolveFinishFiles;
|