@morphllm/morphsdk 0.2.56 → 0.2.58
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/anthropic-CaFUHxBW.d.ts +89 -0
- package/dist/{chunk-SALJ2K6S.js → chunk-2CASO3ZO.js} +60 -98
- package/dist/chunk-2CASO3ZO.js.map +1 -0
- package/dist/chunk-374N3GIA.js +118 -0
- package/dist/chunk-374N3GIA.js.map +1 -0
- package/dist/chunk-3IQIT6MC.js +65 -0
- package/dist/chunk-3IQIT6MC.js.map +1 -0
- package/dist/chunk-4VGOBA2J.js +57 -0
- package/dist/chunk-4VGOBA2J.js.map +1 -0
- package/dist/chunk-527P5X2E.js +98 -0
- package/dist/chunk-527P5X2E.js.map +1 -0
- package/dist/chunk-6N6ZYZYD.js +74 -0
- package/dist/chunk-6N6ZYZYD.js.map +1 -0
- package/dist/chunk-6Y5JB4JC.js +195 -0
- package/dist/chunk-6Y5JB4JC.js.map +1 -0
- package/dist/{chunk-WSSSSBWU.js → chunk-7EIHYJSG.js} +18 -18
- package/dist/chunk-7EIHYJSG.js.map +1 -0
- package/dist/{chunk-TICMYDII.js → chunk-APP75CBN.js} +33 -16
- package/dist/chunk-APP75CBN.js.map +1 -0
- package/dist/chunk-ILJ3J5IA.js +72 -0
- package/dist/chunk-ILJ3J5IA.js.map +1 -0
- package/dist/chunk-ISWL67SF.js +1 -0
- package/dist/chunk-KW7OEGZK.js +9 -0
- package/dist/chunk-KW7OEGZK.js.map +1 -0
- package/dist/chunk-Q5AHGIQO.js +205 -0
- package/dist/chunk-Q5AHGIQO.js.map +1 -0
- package/dist/{chunk-TJIUA27P.js → chunk-XT5ZO6ES.js} +9 -5
- package/dist/chunk-XT5ZO6ES.js.map +1 -0
- package/dist/{chunk-LVPVVLTI.js → chunk-YV75OQTE.js} +105 -17
- package/dist/chunk-YV75OQTE.js.map +1 -0
- package/dist/{chunk-ZJIIICRA.js → chunk-ZO4PPFCZ.js} +60 -29
- package/dist/chunk-ZO4PPFCZ.js.map +1 -0
- package/dist/{client-CFoR--IU.d.ts → client-CextMMm9.d.ts} +10 -15
- package/dist/client.cjs +698 -466
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +3 -2
- package/dist/client.js +14 -15
- package/dist/finish-kXAcUJyB.d.ts +33 -0
- package/dist/gemini-CE80Pbdy.d.ts +117 -0
- package/dist/index.cjs +711 -466
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +16 -16
- package/dist/openai-Fvpqln7F.d.ts +89 -0
- package/dist/tools/warp_grep/agent/config.cjs +8 -4
- package/dist/tools/warp_grep/agent/config.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/config.d.ts +7 -2
- package/dist/tools/warp_grep/agent/config.js +1 -1
- package/dist/tools/warp_grep/agent/formatter.cjs +32 -15
- package/dist/tools/warp_grep/agent/formatter.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/formatter.d.ts +1 -1
- package/dist/tools/warp_grep/agent/formatter.js +1 -1
- package/dist/tools/warp_grep/agent/parser.cjs +104 -17
- package/dist/tools/warp_grep/agent/parser.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/parser.d.ts +3 -5
- package/dist/tools/warp_grep/agent/parser.js +1 -3
- package/dist/tools/warp_grep/agent/prompt.cjs +132 -56
- package/dist/tools/warp_grep/agent/prompt.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/prompt.d.ts +1 -1
- package/dist/tools/warp_grep/agent/prompt.js +1 -1
- package/dist/tools/warp_grep/agent/runner.cjs +466 -313
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.d.ts +1 -0
- package/dist/tools/warp_grep/agent/runner.js +6 -9
- package/dist/tools/warp_grep/agent/types.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/types.d.ts +9 -2
- package/dist/tools/warp_grep/anthropic.cjs +656 -380
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.d.ts +4 -74
- package/dist/tools/warp_grep/anthropic.js +13 -16
- package/dist/tools/warp_grep/client.cjs +1593 -0
- package/dist/tools/warp_grep/client.cjs.map +1 -0
- package/dist/tools/warp_grep/client.d.ts +87 -0
- package/dist/tools/warp_grep/client.js +26 -0
- package/dist/tools/warp_grep/gemini.cjs +1587 -0
- package/dist/tools/warp_grep/gemini.cjs.map +1 -0
- package/dist/tools/warp_grep/gemini.d.ts +7 -0
- package/dist/tools/warp_grep/gemini.js +34 -0
- package/dist/tools/warp_grep/harness.cjs +1195 -0
- package/dist/tools/warp_grep/harness.cjs.map +1 -0
- package/dist/tools/warp_grep/harness.d.ts +107 -0
- package/dist/tools/warp_grep/harness.js +68 -0
- package/dist/tools/warp_grep/harness.js.map +1 -0
- package/dist/tools/warp_grep/index.cjs +818 -466
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.d.ts +11 -6
- package/dist/tools/warp_grep/index.js +43 -23
- package/dist/tools/warp_grep/openai.cjs +656 -378
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.d.ts +4 -74
- package/dist/tools/warp_grep/openai.js +13 -14
- package/dist/tools/warp_grep/providers/local.cjs +66 -27
- package/dist/tools/warp_grep/providers/local.cjs.map +1 -1
- package/dist/tools/warp_grep/providers/local.d.ts +4 -9
- package/dist/tools/warp_grep/providers/local.js +2 -2
- package/dist/tools/warp_grep/providers/remote.cjs +211 -0
- package/dist/tools/warp_grep/providers/remote.cjs.map +1 -0
- package/dist/tools/warp_grep/providers/remote.d.ts +67 -0
- package/dist/tools/warp_grep/providers/remote.js +9 -0
- package/dist/tools/warp_grep/providers/types.cjs.map +1 -1
- package/dist/tools/warp_grep/providers/types.d.ts +7 -15
- package/dist/tools/warp_grep/vercel.cjs +668 -397
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.d.ts +4 -51
- package/dist/tools/warp_grep/vercel.js +16 -15
- package/dist/types-a_hxdPI6.d.ts +144 -0
- package/dist/vercel-3yjvfmVB.d.ts +66 -0
- package/package.json +17 -2
- package/dist/chunk-4ZHDBKBY.js +0 -83
- package/dist/chunk-4ZHDBKBY.js.map +0 -1
- package/dist/chunk-73RQWOQC.js +0 -16
- package/dist/chunk-73RQWOQC.js.map +0 -1
- package/dist/chunk-7OQOOB3R.js +0 -1
- package/dist/chunk-EK7OQPWD.js +0 -44
- package/dist/chunk-EK7OQPWD.js.map +0 -1
- package/dist/chunk-GJURLQ3L.js +0 -77
- package/dist/chunk-GJURLQ3L.js.map +0 -1
- package/dist/chunk-HQO45BAJ.js +0 -14
- package/dist/chunk-HQO45BAJ.js.map +0 -1
- package/dist/chunk-LVPVVLTI.js.map +0 -1
- package/dist/chunk-NDZO5IPV.js +0 -121
- package/dist/chunk-NDZO5IPV.js.map +0 -1
- package/dist/chunk-QVRXBAMM.js +0 -107
- package/dist/chunk-QVRXBAMM.js.map +0 -1
- package/dist/chunk-SALJ2K6S.js.map +0 -1
- package/dist/chunk-TICMYDII.js.map +0 -1
- package/dist/chunk-TJIUA27P.js.map +0 -1
- package/dist/chunk-UIRJE422.js +0 -70
- package/dist/chunk-UIRJE422.js.map +0 -1
- package/dist/chunk-WETRQJGU.js +0 -129
- package/dist/chunk-WETRQJGU.js.map +0 -1
- package/dist/chunk-WSSSSBWU.js.map +0 -1
- package/dist/chunk-ZJIIICRA.js.map +0 -1
- package/dist/core-CpkYEi_T.d.ts +0 -158
- package/dist/tools/warp_grep/agent/grep_helpers.cjs +0 -148
- package/dist/tools/warp_grep/agent/grep_helpers.cjs.map +0 -1
- package/dist/tools/warp_grep/agent/grep_helpers.d.ts +0 -16
- package/dist/tools/warp_grep/agent/grep_helpers.js +0 -14
- package/dist/tools/warp_grep/tools/analyse.cjs +0 -40
- package/dist/tools/warp_grep/tools/analyse.cjs.map +0 -1
- package/dist/tools/warp_grep/tools/analyse.d.ts +0 -10
- package/dist/tools/warp_grep/tools/analyse.js +0 -8
- package/dist/tools/warp_grep/tools/finish.cjs +0 -69
- package/dist/tools/warp_grep/tools/finish.cjs.map +0 -1
- package/dist/tools/warp_grep/tools/finish.d.ts +0 -10
- package/dist/tools/warp_grep/tools/finish.js +0 -10
- package/dist/tools/warp_grep/tools/grep.cjs +0 -38
- package/dist/tools/warp_grep/tools/grep.cjs.map +0 -1
- package/dist/tools/warp_grep/tools/grep.d.ts +0 -8
- package/dist/tools/warp_grep/tools/grep.js +0 -15
- package/dist/tools/warp_grep/tools/grep.js.map +0 -1
- package/dist/tools/warp_grep/tools/read.cjs +0 -38
- package/dist/tools/warp_grep/tools/read.cjs.map +0 -1
- package/dist/tools/warp_grep/tools/read.d.ts +0 -9
- package/dist/tools/warp_grep/tools/read.js +0 -8
- package/dist/tools/warp_grep/tools/read.js.map +0 -1
- package/dist/tools/warp_grep/utils/format.cjs +0 -42
- package/dist/tools/warp_grep/utils/format.cjs.map +0 -1
- package/dist/tools/warp_grep/utils/format.d.ts +0 -4
- package/dist/tools/warp_grep/utils/format.js +0 -18
- package/dist/tools/warp_grep/utils/format.js.map +0 -1
- /package/dist/{chunk-7OQOOB3R.js.map → chunk-ISWL67SF.js.map} +0 -0
- /package/dist/tools/warp_grep/{agent/grep_helpers.js.map → client.js.map} +0 -0
- /package/dist/tools/warp_grep/{tools/analyse.js.map → gemini.js.map} +0 -0
- /package/dist/tools/warp_grep/{tools/finish.js.map → providers/remote.js.map} +0 -0
|
@@ -0,0 +1,1195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
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
|
+
LLMResponseParser: () => LLMResponseParser,
|
|
36
|
+
LocalRipgrepProvider: () => LocalRipgrepProvider,
|
|
37
|
+
SYSTEM_PROMPT: () => SYSTEM_PROMPT,
|
|
38
|
+
buildInitialState: () => buildInitialState,
|
|
39
|
+
calculateContextBudget: () => calculateContextBudget,
|
|
40
|
+
formatListDirectoryTree: () => formatListDirectoryTree,
|
|
41
|
+
formatToolResult: () => formatAgentToolOutput,
|
|
42
|
+
formatTurnMessage: () => formatTurnMessage,
|
|
43
|
+
getSystemPrompt: () => getSystemPrompt,
|
|
44
|
+
normalizeFinishFiles: () => normalizeFinishFiles,
|
|
45
|
+
parseToolCalls: () => parseToolCalls,
|
|
46
|
+
readFinishFiles: () => readFinishFiles,
|
|
47
|
+
resolveFinishFiles: () => resolveFinishFiles,
|
|
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
|
+
var VALID_COMMANDS = ["list_directory", "grep", "read", "finish"];
|
|
56
|
+
function isValidCommand(name) {
|
|
57
|
+
return VALID_COMMANDS.includes(name);
|
|
58
|
+
}
|
|
59
|
+
function getXmlElementText(xml, tagName) {
|
|
60
|
+
const regex = new RegExp(`<${tagName}>([\\s\\S]*?)</${tagName}>`, "i");
|
|
61
|
+
const match = xml.match(regex);
|
|
62
|
+
return match ? match[1].trim() : null;
|
|
63
|
+
}
|
|
64
|
+
function parseNestedXmlTools(text) {
|
|
65
|
+
const tools = [];
|
|
66
|
+
const toolRegex = /<([a-z_][a-z0-9_]*)>([\s\S]*?)<\/\1>/gi;
|
|
67
|
+
let match;
|
|
68
|
+
while ((match = toolRegex.exec(text)) !== null) {
|
|
69
|
+
const rawToolName = match[1].toLowerCase();
|
|
70
|
+
const content = match[2];
|
|
71
|
+
if (!isValidCommand(rawToolName)) continue;
|
|
72
|
+
const toolName = rawToolName;
|
|
73
|
+
if (toolName === "list_directory") {
|
|
74
|
+
const path4 = getXmlElementText(content, "path");
|
|
75
|
+
const pattern = getXmlElementText(content, "pattern");
|
|
76
|
+
if (path4) {
|
|
77
|
+
tools.push({ name: "list_directory", arguments: { path: path4, pattern } });
|
|
78
|
+
}
|
|
79
|
+
} else if (toolName === "grep") {
|
|
80
|
+
const pattern = getXmlElementText(content, "pattern");
|
|
81
|
+
const subDir = getXmlElementText(content, "sub_dir");
|
|
82
|
+
const glob = getXmlElementText(content, "glob");
|
|
83
|
+
if (pattern) {
|
|
84
|
+
tools.push({
|
|
85
|
+
name: "grep",
|
|
86
|
+
arguments: {
|
|
87
|
+
pattern,
|
|
88
|
+
path: subDir || ".",
|
|
89
|
+
...glob && { glob }
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
} else if (toolName === "read") {
|
|
94
|
+
const path4 = getXmlElementText(content, "path");
|
|
95
|
+
const linesStr = getXmlElementText(content, "lines");
|
|
96
|
+
if (path4) {
|
|
97
|
+
const args = { path: path4 };
|
|
98
|
+
if (linesStr) {
|
|
99
|
+
const ranges = [];
|
|
100
|
+
for (const rangeStr of linesStr.split(",")) {
|
|
101
|
+
const trimmed = rangeStr.trim();
|
|
102
|
+
if (!trimmed) continue;
|
|
103
|
+
const [s, e] = trimmed.split("-").map((v) => parseInt(v.trim(), 10));
|
|
104
|
+
if (Number.isFinite(s) && Number.isFinite(e)) {
|
|
105
|
+
ranges.push([s, e]);
|
|
106
|
+
} else if (Number.isFinite(s)) {
|
|
107
|
+
ranges.push([s, s]);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (ranges.length === 1) {
|
|
111
|
+
args.start = ranges[0][0];
|
|
112
|
+
args.end = ranges[0][1];
|
|
113
|
+
} else if (ranges.length > 1) {
|
|
114
|
+
args.lines = ranges;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
tools.push({ name: "read", arguments: args });
|
|
118
|
+
}
|
|
119
|
+
} else if (toolName === "finish") {
|
|
120
|
+
const fileRegex = /<file>([\s\S]*?)<\/file>/gi;
|
|
121
|
+
const files = [];
|
|
122
|
+
let fileMatch;
|
|
123
|
+
while ((fileMatch = fileRegex.exec(content)) !== null) {
|
|
124
|
+
const fileContent = fileMatch[1];
|
|
125
|
+
const filePath = getXmlElementText(fileContent, "path");
|
|
126
|
+
const linesStr = getXmlElementText(fileContent, "lines");
|
|
127
|
+
if (filePath && linesStr) {
|
|
128
|
+
const ranges = [];
|
|
129
|
+
for (const rangeStr of linesStr.split(",")) {
|
|
130
|
+
if (rangeStr.trim() === "*") {
|
|
131
|
+
ranges.push([1, 999999]);
|
|
132
|
+
} else {
|
|
133
|
+
const [s, e] = rangeStr.split("-").map((v) => parseInt(v.trim(), 10));
|
|
134
|
+
if (Number.isFinite(s) && Number.isFinite(e)) {
|
|
135
|
+
ranges.push([s, e]);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (ranges.length > 0) {
|
|
140
|
+
files.push({ path: filePath, lines: ranges });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (files.length > 0) {
|
|
145
|
+
tools.push({ name: "finish", arguments: { files } });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return tools;
|
|
150
|
+
}
|
|
151
|
+
function preprocessText(text) {
|
|
152
|
+
let processed = text.replace(/<think>[\s\S]*?<\/think>/gi, "");
|
|
153
|
+
const nestedTools = parseNestedXmlTools(processed);
|
|
154
|
+
const openingTagRegex = /<tool_call>|<tool>/gi;
|
|
155
|
+
const closingTagRegex = /<\/tool_call>|<\/tool>/gi;
|
|
156
|
+
const openingMatches = processed.match(openingTagRegex) || [];
|
|
157
|
+
const closingMatches = processed.match(closingTagRegex) || [];
|
|
158
|
+
if (openingMatches.length > closingMatches.length) {
|
|
159
|
+
const lastClosingMatch = /<\/tool_call>|<\/tool>/gi;
|
|
160
|
+
let lastClosingIndex = -1;
|
|
161
|
+
let match;
|
|
162
|
+
while ((match = lastClosingMatch.exec(processed)) !== null) {
|
|
163
|
+
lastClosingIndex = match.index + match[0].length;
|
|
164
|
+
}
|
|
165
|
+
if (lastClosingIndex > 0) {
|
|
166
|
+
processed = processed.slice(0, lastClosingIndex);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const toolCallLines = [];
|
|
170
|
+
const toolTagRegex = /<tool_call>([\s\S]*?)<\/tool_call>|<tool>([\s\S]*?)<\/tool>/gi;
|
|
171
|
+
let tagMatch;
|
|
172
|
+
while ((tagMatch = toolTagRegex.exec(processed)) !== null) {
|
|
173
|
+
const content = (tagMatch[1] || tagMatch[2] || "").trim();
|
|
174
|
+
if (content) {
|
|
175
|
+
const lines = content.split(/\r?\n/).map((l) => l.trim()).filter((l) => l);
|
|
176
|
+
toolCallLines.push(...lines);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const allLines = processed.split(/\r?\n/).map((l) => l.trim());
|
|
180
|
+
for (const line of allLines) {
|
|
181
|
+
if (!line) continue;
|
|
182
|
+
if (line.startsWith("<")) continue;
|
|
183
|
+
const firstWord = line.split(/\s/)[0];
|
|
184
|
+
if (VALID_COMMANDS.includes(firstWord)) {
|
|
185
|
+
if (!toolCallLines.includes(line)) {
|
|
186
|
+
toolCallLines.push(line);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return { lines: toolCallLines, nestedTools };
|
|
191
|
+
}
|
|
192
|
+
var LLMResponseParser = class {
|
|
193
|
+
finishSpecSplitRe = /,(?=[^,\s]+:)/;
|
|
194
|
+
parse(text) {
|
|
195
|
+
if (typeof text !== "string") {
|
|
196
|
+
throw new TypeError("Command text must be a string.");
|
|
197
|
+
}
|
|
198
|
+
const { lines, nestedTools } = preprocessText(text);
|
|
199
|
+
const commands = [...nestedTools];
|
|
200
|
+
let finishAccumulator = null;
|
|
201
|
+
lines.forEach((line) => {
|
|
202
|
+
if (!line || line.startsWith("#")) return;
|
|
203
|
+
const parts = this.splitLine(line);
|
|
204
|
+
if (parts.length === 0) return;
|
|
205
|
+
const cmd = parts[0];
|
|
206
|
+
switch (cmd) {
|
|
207
|
+
case "list_directory":
|
|
208
|
+
this.handleListDirectory(parts, line, commands);
|
|
209
|
+
break;
|
|
210
|
+
case "grep":
|
|
211
|
+
this.handleGrep(parts, line, commands);
|
|
212
|
+
break;
|
|
213
|
+
case "read":
|
|
214
|
+
this.handleRead(parts, line, commands);
|
|
215
|
+
break;
|
|
216
|
+
case "finish":
|
|
217
|
+
finishAccumulator = this.handleFinish(parts, line, commands, finishAccumulator);
|
|
218
|
+
break;
|
|
219
|
+
default:
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
if (finishAccumulator) {
|
|
224
|
+
const map = finishAccumulator;
|
|
225
|
+
const entries = [...map.entries()];
|
|
226
|
+
const filesPayload = entries.map(([path4, ranges]) => ({
|
|
227
|
+
path: path4,
|
|
228
|
+
lines: [...ranges].sort((a, b) => a[0] - b[0])
|
|
229
|
+
}));
|
|
230
|
+
commands.push({ name: "finish", arguments: { files: filesPayload } });
|
|
231
|
+
}
|
|
232
|
+
return commands;
|
|
233
|
+
}
|
|
234
|
+
splitLine(line) {
|
|
235
|
+
const parts = [];
|
|
236
|
+
let current = "";
|
|
237
|
+
let inSingle = false;
|
|
238
|
+
for (let i = 0; i < line.length; i++) {
|
|
239
|
+
const ch = line[i];
|
|
240
|
+
if (ch === "'" && line[i - 1] !== "\\") {
|
|
241
|
+
inSingle = !inSingle;
|
|
242
|
+
current += ch;
|
|
243
|
+
} else if (!inSingle && /\s/.test(ch)) {
|
|
244
|
+
if (current) {
|
|
245
|
+
parts.push(current);
|
|
246
|
+
current = "";
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
current += ch;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (current) parts.push(current);
|
|
253
|
+
return parts;
|
|
254
|
+
}
|
|
255
|
+
/** Helper to create a _skip tool call with an error message */
|
|
256
|
+
skip(message) {
|
|
257
|
+
return { name: "_skip", arguments: { message } };
|
|
258
|
+
}
|
|
259
|
+
handleListDirectory(parts, rawLine, commands) {
|
|
260
|
+
if (parts.length < 2) {
|
|
261
|
+
commands.push(this.skip(
|
|
262
|
+
`[SKIPPED] Your command "${rawLine}" is missing a path. Correct format: list_directory <path> [pattern]. Example: list_directory src/`
|
|
263
|
+
));
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const path4 = parts[1];
|
|
267
|
+
const pattern = parts[2]?.replace(/^"|"$/g, "") ?? null;
|
|
268
|
+
commands.push({ name: "list_directory", arguments: { path: path4, pattern } });
|
|
269
|
+
}
|
|
270
|
+
handleGrep(parts, rawLine, commands) {
|
|
271
|
+
if (parts.length < 3) {
|
|
272
|
+
commands.push(this.skip(
|
|
273
|
+
`[SKIPPED] Your command "${rawLine}" is missing arguments. Correct format: grep '<pattern>' <path>. Example: grep 'TODO' src/`
|
|
274
|
+
));
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
let pat = parts[1];
|
|
278
|
+
if (pat.startsWith("'") && pat.endsWith("'")) {
|
|
279
|
+
pat = pat.slice(1, -1);
|
|
280
|
+
}
|
|
281
|
+
if (!pat) {
|
|
282
|
+
commands.push(this.skip(
|
|
283
|
+
`[SKIPPED] Your command "${rawLine}" has an empty pattern. Provide a non-empty search pattern. Example: grep 'function' src/`
|
|
284
|
+
));
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
commands.push({ name: "grep", arguments: { pattern: pat, path: parts[2] } });
|
|
288
|
+
}
|
|
289
|
+
handleRead(parts, rawLine, commands) {
|
|
290
|
+
if (parts.length < 2) {
|
|
291
|
+
commands.push(this.skip(
|
|
292
|
+
`[SKIPPED] Your command "${rawLine}" is missing a path. Correct format: read <path> or read <path>:<start>-<end>. Example: read src/index.ts:1-50`
|
|
293
|
+
));
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const spec = parts[1];
|
|
297
|
+
const rangeIdx = spec.indexOf(":");
|
|
298
|
+
if (rangeIdx === -1) {
|
|
299
|
+
commands.push({ name: "read", arguments: { path: spec } });
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const filePath = spec.slice(0, rangeIdx);
|
|
303
|
+
const range = spec.slice(rangeIdx + 1);
|
|
304
|
+
const [s, e] = range.split("-").map((v) => parseInt(v, 10));
|
|
305
|
+
if (!Number.isFinite(s) || !Number.isFinite(e)) {
|
|
306
|
+
commands.push({ name: "read", arguments: { path: filePath } });
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
commands.push({ name: "read", arguments: { path: filePath, start: s, end: e } });
|
|
310
|
+
}
|
|
311
|
+
handleFinish(parts, rawLine, commands, acc) {
|
|
312
|
+
const map = acc ?? /* @__PURE__ */ new Map();
|
|
313
|
+
const args = parts.slice(1);
|
|
314
|
+
for (const token of args) {
|
|
315
|
+
const [filePath, rangesText] = token.split(":", 2);
|
|
316
|
+
if (!filePath || !rangesText) {
|
|
317
|
+
commands.push(this.skip(
|
|
318
|
+
`[SKIPPED] Invalid finish token "${token}". Correct format: finish <path>:<start>-<end>. Example: finish src/index.ts:1-50`
|
|
319
|
+
));
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
const rangeSpecs = rangesText.split(",").filter(Boolean);
|
|
323
|
+
for (const spec of rangeSpecs) {
|
|
324
|
+
const [s, e] = spec.split("-").map((v) => parseInt(v, 10));
|
|
325
|
+
if (!Number.isFinite(s) || !Number.isFinite(e) || e < s) {
|
|
326
|
+
commands.push(this.skip(
|
|
327
|
+
`[SKIPPED] Invalid range "${spec}" in "${token}". Ranges must be <start>-<end> where start <= end. Example: 1-50`
|
|
328
|
+
));
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
const arr = map.get(filePath) ?? [];
|
|
332
|
+
arr.push([s, e]);
|
|
333
|
+
map.set(filePath, arr);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return map;
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// tools/warp_grep/agent/prompt.ts
|
|
341
|
+
var SYSTEM_PROMPT = `You are a code search agent. Your task is to find all relevant code for a given search_string.
|
|
342
|
+
|
|
343
|
+
### workflow
|
|
344
|
+
You have exactly 4 turns. The 4th turn MUST be a \`finish\` call. Each turn allows up to 8 parallel tool calls.
|
|
345
|
+
|
|
346
|
+
- Turn 1: Map the territory OR dive deep (based on search_string specificity)
|
|
347
|
+
- Turn 2-3: Refine based on findings
|
|
348
|
+
- Turn 4: MUST call \`finish\` with all relevant code locations
|
|
349
|
+
- You MAY call \`finish\` early if confident\u2014but never before at least 1 search turn.
|
|
350
|
+
- The user strongly prefers if you can call the finish tool early, but you must be correct
|
|
351
|
+
|
|
352
|
+
Remember, if the task feels easy to you, it is strongly desirable to call 'finish' early using fewer turns, but quality over speed
|
|
353
|
+
|
|
354
|
+
### tools
|
|
355
|
+
Tool calls use nested XML elements:
|
|
356
|
+
\`\`\`xml
|
|
357
|
+
<tool_name>
|
|
358
|
+
<parameter>value</parameter>
|
|
359
|
+
</tool_name>
|
|
360
|
+
\`\`\`
|
|
361
|
+
|
|
362
|
+
### \`list_directory\`
|
|
363
|
+
Directory tree view. Shows structure of a path, optionally filtered by regex pattern.
|
|
364
|
+
|
|
365
|
+
Elements:
|
|
366
|
+
- \`<path>\` (required): Directory path to list (use \`.\` for repo root)
|
|
367
|
+
- \`<pattern>\` (optional): Regex to filter results
|
|
368
|
+
|
|
369
|
+
Examples:
|
|
370
|
+
\`\`\`
|
|
371
|
+
<list_directory>
|
|
372
|
+
<path>src/services</path>
|
|
373
|
+
</list_directory>
|
|
374
|
+
|
|
375
|
+
<list_directory>
|
|
376
|
+
<path>lib/utils</path>
|
|
377
|
+
<pattern>.*\\.(ts|js)$</pattern>
|
|
378
|
+
</list_directory>
|
|
379
|
+
\`\`\`
|
|
380
|
+
|
|
381
|
+
### \`read\`
|
|
382
|
+
Read file contents. Supports multiple line ranges.
|
|
383
|
+
- Returns numbered lines for easy reference
|
|
384
|
+
- ALWAYS include import statements (usually lines 1-20). Better to over-include than miss context.
|
|
385
|
+
|
|
386
|
+
Elements:
|
|
387
|
+
- \`<path>\` (required): File path to read
|
|
388
|
+
- \`<lines>\` (optional): Line ranges like "1-50,75-80,100-120" (omit to read entire file)
|
|
389
|
+
|
|
390
|
+
Examples:
|
|
391
|
+
\`\`\`
|
|
392
|
+
<read>
|
|
393
|
+
<path>src/main.py</path>
|
|
394
|
+
</read>
|
|
395
|
+
|
|
396
|
+
<read>
|
|
397
|
+
<path>src/auth.py</path>
|
|
398
|
+
<lines>1-20,45-80,150-200</lines>
|
|
399
|
+
</read>
|
|
400
|
+
\`\`\`
|
|
401
|
+
|
|
402
|
+
### \`grep\`
|
|
403
|
+
Search for pattern matches across files. Returns matches with 1 line of context above and below.
|
|
404
|
+
- Match lines use \`:\` separator \u2192 \`filepath:linenum:content\`
|
|
405
|
+
- Context lines use \`-\` separator \u2192 \`filepath-linenum-content\`
|
|
406
|
+
|
|
407
|
+
Elements:
|
|
408
|
+
- \`<pattern>\` (required): Search pattern (regex). Use \`(a|b)\` for OR patterns.
|
|
409
|
+
- \`<sub_dir>\` (optional): Subdirectory to search in (defaults to \`.\`)
|
|
410
|
+
- \`<glob>\` (optional): File pattern filter like \`*.py\` or \`*.{ts,tsx}\`
|
|
411
|
+
|
|
412
|
+
Examples:
|
|
413
|
+
\`\`\`
|
|
414
|
+
<grep>
|
|
415
|
+
<pattern>(authenticate|authorize|login)</pattern>
|
|
416
|
+
<sub_dir>src/auth/</sub_dir>
|
|
417
|
+
</grep>
|
|
418
|
+
|
|
419
|
+
<grep>
|
|
420
|
+
<pattern>class.*(Service|Controller)</pattern>
|
|
421
|
+
<glob>*.{ts,js}</glob>
|
|
422
|
+
</grep>
|
|
423
|
+
|
|
424
|
+
<grep>
|
|
425
|
+
<pattern>(DB_HOST|DATABASE_URL|connection)</pattern>
|
|
426
|
+
<glob>*.{py,yaml,env}</glob>
|
|
427
|
+
<sub_dir>lib/</sub_dir>
|
|
428
|
+
</grep>
|
|
429
|
+
\`\`\`
|
|
430
|
+
|
|
431
|
+
### \`finish\`
|
|
432
|
+
Submit final answer with all relevant code locations. Uses nested \`<file>\` elements.
|
|
433
|
+
|
|
434
|
+
File elements:
|
|
435
|
+
- \`<path>\` (required): File path
|
|
436
|
+
- \`<lines>\` (optional): Line ranges like "1-50,75-80" (\`*\` for entire file)
|
|
437
|
+
|
|
438
|
+
ALWAYS include import statements (usually lines 1-20). Better to over-include than miss context.
|
|
439
|
+
|
|
440
|
+
Examples:
|
|
441
|
+
\`\`\`
|
|
442
|
+
<finish>
|
|
443
|
+
<file>
|
|
444
|
+
<path>src/auth.py</path>
|
|
445
|
+
<lines>1-15,25-50,75-80</lines>
|
|
446
|
+
</file>
|
|
447
|
+
<file>
|
|
448
|
+
<path>src/models/user.py</path>
|
|
449
|
+
<lines>*</lines>
|
|
450
|
+
</file>
|
|
451
|
+
</finish>
|
|
452
|
+
\`\`\`
|
|
453
|
+
</tools>
|
|
454
|
+
|
|
455
|
+
<strategy>
|
|
456
|
+
**Before your first tool call, classify the search_string:**
|
|
457
|
+
|
|
458
|
+
| Search_string Type | Round 1 Strategy | Early Finish? |
|
|
459
|
+
|------------|------------------|---------------|
|
|
460
|
+
| **Specific** (function name, error string, unique identifier) | 8 parallel greps on likely paths | Often by round 2 |
|
|
461
|
+
| **Conceptual** (how does X work, where is Y handled) | list_directory + 2-3 broad greps | Rarely early |
|
|
462
|
+
| **Exploratory** (find all tests, list API endpoints) | list_directory at multiple depths | Usually needs 3 rounds |
|
|
463
|
+
|
|
464
|
+
**Parallel call patterns:**
|
|
465
|
+
- **Shotgun grep**: Same pattern, 8 different directories\u2014fast coverage
|
|
466
|
+
- **Variant grep**: 8 pattern variations (synonyms, naming conventions)\u2014catches inconsistent codebases
|
|
467
|
+
- **Funnel**: 1 list_directory + 7 greps\u2014orient and search simultaneously
|
|
468
|
+
- **Deep read**: 8 reads on files you already identified\u2014gather full context fast
|
|
469
|
+
|
|
470
|
+
**Tool call expectations:**
|
|
471
|
+
- Low quality tool calls are ones that give back sparse information. This either means they are not well thought out and are not educated guesses OR, they are too broad and give back too many results.
|
|
472
|
+
- High quality tool calls strike a balance between complexity in the tool call to exclude results we know we don't want, and how wide the search space is so that we don't miss anything. It is ok to start off with wider search spaces, but is imperative that you use your intuition from there on out and seek high quality tool calls only.
|
|
473
|
+
- You are not starting blind, you have some information about root level repo structure going in, so use that to prevent making trivial repo wide queries.
|
|
474
|
+
- The grep tool shows you which file path and line numbers the pattern was found in, use this information smartly when trying to read the file.
|
|
475
|
+
</strategy>
|
|
476
|
+
|
|
477
|
+
<output_format>
|
|
478
|
+
EVERY response MUST follow this exact format:
|
|
479
|
+
|
|
480
|
+
1. First, wrap your reasoning in \`<think>...</think>\` tags containing:
|
|
481
|
+
- Search_string classification (specific/conceptual/exploratory)
|
|
482
|
+
- Confidence estimate (can I finish in 1-2 rounds?)
|
|
483
|
+
- This round's parallel strategy
|
|
484
|
+
- What signals would let me finish early?
|
|
485
|
+
|
|
486
|
+
2. Then, output up to 8 tool calls using nested XML elements.
|
|
487
|
+
|
|
488
|
+
Example:
|
|
489
|
+
\`\`\`
|
|
490
|
+
<think>
|
|
491
|
+
This is a specific search_string about authentication. I'll grep for auth-related patterns.
|
|
492
|
+
High confidence I can finish in 2 rounds if I find the auth module. I have already been shown the repo's structure at root
|
|
493
|
+
Strategy: Shotgun grep across likely directories.
|
|
494
|
+
</think>
|
|
495
|
+
<grep>
|
|
496
|
+
<pattern>(authenticate|login|session)</pattern>
|
|
497
|
+
<sub_dir>src/auth/</sub_dir>
|
|
498
|
+
</grep>
|
|
499
|
+
<grep>
|
|
500
|
+
<pattern>(middleware|interceptor)</pattern>
|
|
501
|
+
<glob>*.{ts,js}</glob>
|
|
502
|
+
</grep>
|
|
503
|
+
<list_directory>
|
|
504
|
+
<path>src/auth</path>
|
|
505
|
+
</list_directory>
|
|
506
|
+
\`\`\`
|
|
507
|
+
|
|
508
|
+
Finishing example:
|
|
509
|
+
\`\`\`
|
|
510
|
+
<think>
|
|
511
|
+
I think I have a rough idea, but this is my last turn so I must call the finish tool regardless.
|
|
512
|
+
</think>
|
|
513
|
+
<finish>
|
|
514
|
+
<file>
|
|
515
|
+
<path>src/auth/login.py</path>
|
|
516
|
+
<lines>1-50</lines>
|
|
517
|
+
</file>
|
|
518
|
+
<file>
|
|
519
|
+
<path>src/middleware/session.py</path>
|
|
520
|
+
<lines>10-80</lines>
|
|
521
|
+
</file>
|
|
522
|
+
</finish>
|
|
523
|
+
\`\`\`
|
|
524
|
+
|
|
525
|
+
No commentary outside \`<think>\`. No explanations after tool calls.
|
|
526
|
+
</output_format>
|
|
527
|
+
|
|
528
|
+
<finishing_requirements>
|
|
529
|
+
When calling \`finish\`:
|
|
530
|
+
- Include the import section (typically lines 1-20) of each file
|
|
531
|
+
- Include all function/class definitions that are relevant
|
|
532
|
+
- Include any type definitions, interfaces, or constants used
|
|
533
|
+
- Better to over-include than leave the user missing context
|
|
534
|
+
- If unsure about boundaries, include more rather than less
|
|
535
|
+
</finishing_requirements>`;
|
|
536
|
+
function getSystemPrompt() {
|
|
537
|
+
return SYSTEM_PROMPT;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// tools/warp_grep/agent/formatter.ts
|
|
541
|
+
var ToolOutputFormatter = class {
|
|
542
|
+
format(toolName, args, output, options = {}) {
|
|
543
|
+
const name = (toolName ?? "").trim();
|
|
544
|
+
if (!name) {
|
|
545
|
+
return "";
|
|
546
|
+
}
|
|
547
|
+
const payload = output?.toString?.()?.trim?.() ?? "";
|
|
548
|
+
const isError = Boolean(options.isError);
|
|
549
|
+
const safeArgs = args ?? {};
|
|
550
|
+
if (!payload && !isError) {
|
|
551
|
+
return "";
|
|
552
|
+
}
|
|
553
|
+
switch (name) {
|
|
554
|
+
case "read":
|
|
555
|
+
return this.formatRead(safeArgs, payload, isError);
|
|
556
|
+
case "list_directory":
|
|
557
|
+
return this.formatListDirectory(safeArgs, payload, isError);
|
|
558
|
+
case "grep":
|
|
559
|
+
return this.formatGrep(safeArgs, payload, isError);
|
|
560
|
+
default:
|
|
561
|
+
return payload ? `<tool_output>
|
|
562
|
+
${payload}
|
|
563
|
+
</tool_output>` : "";
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
formatRead(args, payload, isError) {
|
|
567
|
+
if (isError) {
|
|
568
|
+
return payload;
|
|
569
|
+
}
|
|
570
|
+
const path4 = this.asString(args.path) || "...";
|
|
571
|
+
const start = args.start;
|
|
572
|
+
const end = args.end;
|
|
573
|
+
const linesArray = args.lines;
|
|
574
|
+
const attributes = [`path="${path4}"`];
|
|
575
|
+
if (linesArray && linesArray.length > 0) {
|
|
576
|
+
const rangeStr = linesArray.map(([s, e]) => `${s}-${e}`).join(",");
|
|
577
|
+
attributes.push(`lines="${rangeStr}"`);
|
|
578
|
+
} else if (start !== void 0 && end !== void 0) {
|
|
579
|
+
attributes.push(`lines="${start}-${end}"`);
|
|
580
|
+
}
|
|
581
|
+
return `<read ${attributes.join(" ")}>
|
|
582
|
+
${payload}
|
|
583
|
+
</read>`;
|
|
584
|
+
}
|
|
585
|
+
formatListDirectory(args, payload, isError) {
|
|
586
|
+
const path4 = this.asString(args.path) || ".";
|
|
587
|
+
const pattern = this.asString(args.pattern);
|
|
588
|
+
const attributes = [`path="${path4}"`];
|
|
589
|
+
if (pattern) {
|
|
590
|
+
attributes.push(`pattern="${pattern}"`);
|
|
591
|
+
}
|
|
592
|
+
if (isError) {
|
|
593
|
+
attributes.push('status="error"');
|
|
594
|
+
}
|
|
595
|
+
return `<list_directory ${attributes.join(" ")}>
|
|
596
|
+
${payload}
|
|
597
|
+
</list_directory>`;
|
|
598
|
+
}
|
|
599
|
+
formatGrep(args, payload, isError) {
|
|
600
|
+
const pattern = this.asString(args.pattern);
|
|
601
|
+
const subDir = this.asString(args.path);
|
|
602
|
+
const glob = this.asString(args.glob);
|
|
603
|
+
const attributes = [];
|
|
604
|
+
if (pattern !== void 0) {
|
|
605
|
+
attributes.push(`pattern="${pattern}"`);
|
|
606
|
+
}
|
|
607
|
+
if (subDir !== void 0) {
|
|
608
|
+
attributes.push(`sub_dir="${subDir}"`);
|
|
609
|
+
}
|
|
610
|
+
if (glob !== void 0) {
|
|
611
|
+
attributes.push(`glob="${glob}"`);
|
|
612
|
+
}
|
|
613
|
+
if (isError) {
|
|
614
|
+
attributes.push('status="error"');
|
|
615
|
+
}
|
|
616
|
+
const attrText = attributes.length ? ` ${attributes.join(" ")}` : "";
|
|
617
|
+
return `<grep${attrText}>
|
|
618
|
+
${payload}
|
|
619
|
+
</grep>`;
|
|
620
|
+
}
|
|
621
|
+
asString(value) {
|
|
622
|
+
if (value === null || value === void 0) {
|
|
623
|
+
return void 0;
|
|
624
|
+
}
|
|
625
|
+
return String(value);
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
var sharedFormatter = new ToolOutputFormatter();
|
|
629
|
+
function formatAgentToolOutput(toolName, args, output, options = {}) {
|
|
630
|
+
return sharedFormatter.format(toolName, args, output, options);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// tools/warp_grep/agent/helpers.ts
|
|
634
|
+
var import_path = __toESM(require("path"), 1);
|
|
635
|
+
|
|
636
|
+
// tools/warp_grep/agent/config.ts
|
|
637
|
+
var AGENT_CONFIG = {
|
|
638
|
+
MAX_TURNS: 4,
|
|
639
|
+
TIMEOUT_MS: 3e4,
|
|
640
|
+
MAX_CONTEXT_CHARS: 54e4,
|
|
641
|
+
MAX_OUTPUT_LINES: 200,
|
|
642
|
+
MAX_READ_LINES: 800,
|
|
643
|
+
MAX_LIST_DEPTH: 3,
|
|
644
|
+
LIST_TIMEOUT_MS: 2e3
|
|
645
|
+
};
|
|
646
|
+
var BUILTIN_EXCLUDES = [
|
|
647
|
+
// Version control
|
|
648
|
+
".git",
|
|
649
|
+
".svn",
|
|
650
|
+
".hg",
|
|
651
|
+
".bzr",
|
|
652
|
+
// Dependencies
|
|
653
|
+
"node_modules",
|
|
654
|
+
"bower_components",
|
|
655
|
+
".pnpm",
|
|
656
|
+
".yarn",
|
|
657
|
+
"vendor",
|
|
658
|
+
"packages",
|
|
659
|
+
"Pods",
|
|
660
|
+
".bundle",
|
|
661
|
+
// Python
|
|
662
|
+
"__pycache__",
|
|
663
|
+
".pytest_cache",
|
|
664
|
+
".mypy_cache",
|
|
665
|
+
".ruff_cache",
|
|
666
|
+
".venv",
|
|
667
|
+
"venv",
|
|
668
|
+
".tox",
|
|
669
|
+
".nox",
|
|
670
|
+
".eggs",
|
|
671
|
+
"*.egg-info",
|
|
672
|
+
// Build outputs
|
|
673
|
+
"dist",
|
|
674
|
+
"build",
|
|
675
|
+
"out",
|
|
676
|
+
"output",
|
|
677
|
+
"target",
|
|
678
|
+
"_build",
|
|
679
|
+
".next",
|
|
680
|
+
".nuxt",
|
|
681
|
+
".output",
|
|
682
|
+
".vercel",
|
|
683
|
+
".netlify",
|
|
684
|
+
// Cache directories
|
|
685
|
+
".cache",
|
|
686
|
+
".parcel-cache",
|
|
687
|
+
".turbo",
|
|
688
|
+
".nx",
|
|
689
|
+
".gradle",
|
|
690
|
+
// IDE/Editor
|
|
691
|
+
".idea",
|
|
692
|
+
".vscode",
|
|
693
|
+
".vs",
|
|
694
|
+
// Coverage
|
|
695
|
+
"coverage",
|
|
696
|
+
".coverage",
|
|
697
|
+
"htmlcov",
|
|
698
|
+
".nyc_output",
|
|
699
|
+
// Temporary
|
|
700
|
+
"tmp",
|
|
701
|
+
"temp",
|
|
702
|
+
".tmp",
|
|
703
|
+
".temp",
|
|
704
|
+
// Lock files
|
|
705
|
+
"package-lock.json",
|
|
706
|
+
"yarn.lock",
|
|
707
|
+
"pnpm-lock.yaml",
|
|
708
|
+
"bun.lockb",
|
|
709
|
+
"Cargo.lock",
|
|
710
|
+
"Gemfile.lock",
|
|
711
|
+
"poetry.lock",
|
|
712
|
+
// Binary/minified
|
|
713
|
+
"*.min.js",
|
|
714
|
+
"*.min.css",
|
|
715
|
+
"*.bundle.js",
|
|
716
|
+
"*.wasm",
|
|
717
|
+
"*.so",
|
|
718
|
+
"*.dll",
|
|
719
|
+
"*.pyc",
|
|
720
|
+
"*.map",
|
|
721
|
+
"*.js.map",
|
|
722
|
+
// Hidden directories catch-all
|
|
723
|
+
".*"
|
|
724
|
+
];
|
|
725
|
+
var DEFAULT_EXCLUDES = (process.env.MORPH_WARP_GREP_EXCLUDE || "").split(",").map((s) => s.trim()).filter(Boolean).concat(BUILTIN_EXCLUDES);
|
|
726
|
+
|
|
727
|
+
// tools/warp_grep/agent/helpers.ts
|
|
728
|
+
function formatTurnMessage(turnsUsed, maxTurns) {
|
|
729
|
+
const turnsRemaining = maxTurns - turnsUsed;
|
|
730
|
+
if (turnsRemaining === 1) {
|
|
731
|
+
return `
|
|
732
|
+
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`;
|
|
733
|
+
}
|
|
734
|
+
return `
|
|
735
|
+
You have used ${turnsUsed} turn${turnsUsed === 1 ? "" : "s"} and have ${turnsRemaining} remaining`;
|
|
736
|
+
}
|
|
737
|
+
function calculateContextBudget(messages) {
|
|
738
|
+
const totalChars = messages.reduce((sum, m) => sum + m.content.length, 0);
|
|
739
|
+
const maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS;
|
|
740
|
+
const percent = Math.round(totalChars / maxChars * 100);
|
|
741
|
+
const usedK = Math.round(totalChars / 1e3);
|
|
742
|
+
const maxK = Math.round(maxChars / 1e3);
|
|
743
|
+
return `<context_budget>${percent}% (${usedK}K/${maxK}K chars)</context_budget>`;
|
|
744
|
+
}
|
|
745
|
+
async function buildInitialState(repoRoot, query, provider) {
|
|
746
|
+
try {
|
|
747
|
+
const entries = await provider.listDirectory({
|
|
748
|
+
path: ".",
|
|
749
|
+
maxResults: AGENT_CONFIG.MAX_OUTPUT_LINES,
|
|
750
|
+
maxDepth: 2
|
|
751
|
+
});
|
|
752
|
+
const treeLines = entries.map((e) => {
|
|
753
|
+
const indent = " ".repeat(e.depth);
|
|
754
|
+
const name = e.type === "dir" ? `${e.name}/` : e.name;
|
|
755
|
+
return `${indent}${name}`;
|
|
756
|
+
});
|
|
757
|
+
const repoName = import_path.default.basename(repoRoot);
|
|
758
|
+
const treeOutput = treeLines.length > 0 ? `${repoName}/
|
|
759
|
+
${treeLines.join("\n")}` : `${repoName}/`;
|
|
760
|
+
return `<repo_structure>
|
|
761
|
+
${treeOutput}
|
|
762
|
+
</repo_structure>
|
|
763
|
+
|
|
764
|
+
<search_string>
|
|
765
|
+
${query}
|
|
766
|
+
</search_string>`;
|
|
767
|
+
} catch {
|
|
768
|
+
const repoName = import_path.default.basename(repoRoot);
|
|
769
|
+
return `<repo_structure>
|
|
770
|
+
${repoName}/
|
|
771
|
+
</repo_structure>
|
|
772
|
+
|
|
773
|
+
<search_string>
|
|
774
|
+
${query}
|
|
775
|
+
</search_string>`;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
function formatListDirectoryTree(entries) {
|
|
779
|
+
if (!entries.length) return "empty";
|
|
780
|
+
return entries.map((e) => {
|
|
781
|
+
const indent = " ".repeat(e.depth);
|
|
782
|
+
const name = e.type === "dir" ? `${e.name}/` : e.name;
|
|
783
|
+
return `${indent}${name}`;
|
|
784
|
+
}).join("\n");
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// tools/warp_grep/agent/tools/grep.ts
|
|
788
|
+
async function toolGrep(provider, args) {
|
|
789
|
+
const res = await provider.grep(args);
|
|
790
|
+
if (res.error) {
|
|
791
|
+
return { output: res.error };
|
|
792
|
+
}
|
|
793
|
+
if (!res.lines.length) {
|
|
794
|
+
return { output: "no matches" };
|
|
795
|
+
}
|
|
796
|
+
return { output: res.lines.join("\n") };
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// tools/warp_grep/agent/tools/read.ts
|
|
800
|
+
async function toolRead(provider, args) {
|
|
801
|
+
if (args.lines && args.lines.length > 0) {
|
|
802
|
+
const chunks = [];
|
|
803
|
+
for (const [start, end] of args.lines) {
|
|
804
|
+
const res2 = await provider.read({ path: args.path, start, end });
|
|
805
|
+
if (res2.error) return res2.error;
|
|
806
|
+
chunks.push(res2.lines.join("\n"));
|
|
807
|
+
}
|
|
808
|
+
if (chunks.every((c) => c === "")) return "(empty file)";
|
|
809
|
+
return chunks.join("\n...\n");
|
|
810
|
+
}
|
|
811
|
+
const res = await provider.read({ path: args.path, start: args.start, end: args.end });
|
|
812
|
+
if (res.error) {
|
|
813
|
+
return res.error;
|
|
814
|
+
}
|
|
815
|
+
if (!res.lines.length) return "(empty file)";
|
|
816
|
+
return res.lines.join("\n");
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// tools/warp_grep/agent/tools/list_directory.ts
|
|
820
|
+
async function toolListDirectory(provider, args) {
|
|
821
|
+
const list = await provider.listDirectory({
|
|
822
|
+
path: args.path,
|
|
823
|
+
pattern: args.pattern ?? null,
|
|
824
|
+
maxResults: args.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES,
|
|
825
|
+
maxDepth: args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH
|
|
826
|
+
});
|
|
827
|
+
if (!list.length) return "empty";
|
|
828
|
+
if (list.length >= AGENT_CONFIG.MAX_OUTPUT_LINES) {
|
|
829
|
+
return "query not specific enough, tool called tried to return too much context and failed";
|
|
830
|
+
}
|
|
831
|
+
return list.map((e) => {
|
|
832
|
+
const indent = " ".repeat(e.depth);
|
|
833
|
+
const name = e.type === "dir" ? `${e.name}/` : e.name;
|
|
834
|
+
return `${indent}${name}`;
|
|
835
|
+
}).join("\n");
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
// tools/warp_grep/agent/tools/finish.ts
|
|
839
|
+
function normalizeFinishFiles(files) {
|
|
840
|
+
return files.map((f) => {
|
|
841
|
+
const merged = mergeRanges(f.lines);
|
|
842
|
+
return { path: f.path, lines: merged };
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
async function readFinishFiles(repoRoot, files, reader) {
|
|
846
|
+
const out = [];
|
|
847
|
+
for (const f of files) {
|
|
848
|
+
const ranges = mergeRanges(f.lines);
|
|
849
|
+
const chunks = [];
|
|
850
|
+
for (const [s, e] of ranges) {
|
|
851
|
+
const lines = await reader(f.path, s, e);
|
|
852
|
+
chunks.push(lines.join("\n"));
|
|
853
|
+
}
|
|
854
|
+
out.push({ path: f.path, ranges, content: chunks.join("\n") });
|
|
855
|
+
}
|
|
856
|
+
return out;
|
|
857
|
+
}
|
|
858
|
+
function mergeRanges(ranges) {
|
|
859
|
+
if (!ranges.length) return [];
|
|
860
|
+
const sorted = [...ranges].sort((a, b) => a[0] - b[0]);
|
|
861
|
+
const merged = [];
|
|
862
|
+
let [cs, ce] = sorted[0];
|
|
863
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
864
|
+
const [s, e] = sorted[i];
|
|
865
|
+
if (s <= ce + 1) {
|
|
866
|
+
ce = Math.max(ce, e);
|
|
867
|
+
} else {
|
|
868
|
+
merged.push([cs, ce]);
|
|
869
|
+
cs = s;
|
|
870
|
+
ce = e;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
merged.push([cs, ce]);
|
|
874
|
+
return merged;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// tools/warp_grep/providers/local.ts
|
|
878
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
879
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
880
|
+
|
|
881
|
+
// tools/warp_grep/utils/ripgrep.ts
|
|
882
|
+
var import_child_process = require("child_process");
|
|
883
|
+
var import_ripgrep = require("@vscode/ripgrep");
|
|
884
|
+
var resolvedRgPath = null;
|
|
885
|
+
var rgPathChecked = false;
|
|
886
|
+
function spawnRg(rgBinary, args, opts) {
|
|
887
|
+
return new Promise((resolve) => {
|
|
888
|
+
const child = (0, import_child_process.spawn)(rgBinary, args, {
|
|
889
|
+
cwd: opts?.cwd,
|
|
890
|
+
env: { ...process.env, ...opts?.env || {} },
|
|
891
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
892
|
+
});
|
|
893
|
+
let stdout = "";
|
|
894
|
+
let stderr = "";
|
|
895
|
+
child.stdout.on("data", (d) => stdout += d.toString());
|
|
896
|
+
child.stderr.on("data", (d) => stderr += d.toString());
|
|
897
|
+
child.on("close", (code) => {
|
|
898
|
+
resolve({ stdout, stderr, exitCode: typeof code === "number" ? code : -1 });
|
|
899
|
+
});
|
|
900
|
+
child.on("error", () => {
|
|
901
|
+
resolve({ stdout: "", stderr: "Failed to spawn ripgrep.", exitCode: -1 });
|
|
902
|
+
});
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
function isBinaryFailure(result) {
|
|
906
|
+
if (result.exitCode === -1) return true;
|
|
907
|
+
if (result.stderr.includes("jemalloc") || result.stderr.includes("Unsupported system page size")) return true;
|
|
908
|
+
if (result.exitCode === 134) return true;
|
|
909
|
+
return false;
|
|
910
|
+
}
|
|
911
|
+
async function runRipgrep(args, opts) {
|
|
912
|
+
if (rgPathChecked && resolvedRgPath) {
|
|
913
|
+
return spawnRg(resolvedRgPath, args, opts);
|
|
914
|
+
}
|
|
915
|
+
if (!rgPathChecked) {
|
|
916
|
+
const result = await spawnRg(import_ripgrep.rgPath, args, opts);
|
|
917
|
+
if (!isBinaryFailure(result)) {
|
|
918
|
+
resolvedRgPath = import_ripgrep.rgPath;
|
|
919
|
+
rgPathChecked = true;
|
|
920
|
+
return result;
|
|
921
|
+
}
|
|
922
|
+
const fallbackResult = await spawnRg("rg", args, opts);
|
|
923
|
+
if (!isBinaryFailure(fallbackResult)) {
|
|
924
|
+
resolvedRgPath = "rg";
|
|
925
|
+
rgPathChecked = true;
|
|
926
|
+
return fallbackResult;
|
|
927
|
+
}
|
|
928
|
+
rgPathChecked = true;
|
|
929
|
+
return {
|
|
930
|
+
stdout: "",
|
|
931
|
+
stderr: "Failed to spawn ripgrep. Neither bundled nor system rg is available.",
|
|
932
|
+
exitCode: -1
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
return {
|
|
936
|
+
stdout: "",
|
|
937
|
+
stderr: "Failed to spawn ripgrep. Neither bundled nor system rg is available.",
|
|
938
|
+
exitCode: -1
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// tools/warp_grep/utils/paths.ts
|
|
943
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
944
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
945
|
+
function resolveUnderRepo(repoRoot, targetPath) {
|
|
946
|
+
const absRoot = import_path2.default.resolve(repoRoot);
|
|
947
|
+
const resolved = import_path2.default.resolve(absRoot, targetPath);
|
|
948
|
+
ensureWithinRepo(absRoot, resolved);
|
|
949
|
+
return resolved;
|
|
950
|
+
}
|
|
951
|
+
function ensureWithinRepo(repoRoot, absTarget) {
|
|
952
|
+
const rel = import_path2.default.relative(import_path2.default.resolve(repoRoot), import_path2.default.resolve(absTarget));
|
|
953
|
+
if (rel.startsWith("..") || import_path2.default.isAbsolute(rel)) {
|
|
954
|
+
throw new Error(`Path outside repository root: ${absTarget}`);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
function toRepoRelative(repoRoot, absPath) {
|
|
958
|
+
return import_path2.default.relative(import_path2.default.resolve(repoRoot), import_path2.default.resolve(absPath));
|
|
959
|
+
}
|
|
960
|
+
function isSymlink(p) {
|
|
961
|
+
try {
|
|
962
|
+
const st = import_fs.default.lstatSync(p);
|
|
963
|
+
return st.isSymbolicLink();
|
|
964
|
+
} catch {
|
|
965
|
+
return false;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
function isTextualFile(filePath, maxBytes = 2e6) {
|
|
969
|
+
try {
|
|
970
|
+
const st = import_fs.default.statSync(filePath);
|
|
971
|
+
if (!st.isFile()) return false;
|
|
972
|
+
if (st.size > maxBytes) return false;
|
|
973
|
+
const fd = import_fs.default.openSync(filePath, "r");
|
|
974
|
+
const buf = Buffer.alloc(512);
|
|
975
|
+
const read = import_fs.default.readSync(fd, buf, 0, buf.length, 0);
|
|
976
|
+
import_fs.default.closeSync(fd);
|
|
977
|
+
for (let i = 0; i < read; i++) {
|
|
978
|
+
const c = buf[i];
|
|
979
|
+
if (c === 0) return false;
|
|
980
|
+
}
|
|
981
|
+
return true;
|
|
982
|
+
} catch {
|
|
983
|
+
return false;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// tools/warp_grep/utils/files.ts
|
|
988
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
989
|
+
async function readAllLines(filePath) {
|
|
990
|
+
const content = await import_promises.default.readFile(filePath, "utf8");
|
|
991
|
+
return content.split(/\r?\n/);
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
// tools/warp_grep/providers/local.ts
|
|
995
|
+
var LocalRipgrepProvider = class {
|
|
996
|
+
constructor(repoRoot, excludes = DEFAULT_EXCLUDES) {
|
|
997
|
+
this.repoRoot = repoRoot;
|
|
998
|
+
this.excludes = excludes;
|
|
999
|
+
}
|
|
1000
|
+
async grep(params) {
|
|
1001
|
+
let abs;
|
|
1002
|
+
try {
|
|
1003
|
+
abs = resolveUnderRepo(this.repoRoot, params.path);
|
|
1004
|
+
} catch (err) {
|
|
1005
|
+
return {
|
|
1006
|
+
lines: [],
|
|
1007
|
+
error: `[PATH ERROR] ${err instanceof Error ? err.message : String(err)}`
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
const stat = await import_promises2.default.stat(abs).catch(() => null);
|
|
1011
|
+
if (!stat) return { lines: [] };
|
|
1012
|
+
const targetArg = abs === import_path3.default.resolve(this.repoRoot) ? "." : toRepoRelative(this.repoRoot, abs);
|
|
1013
|
+
const args = [
|
|
1014
|
+
"--no-config",
|
|
1015
|
+
"--no-heading",
|
|
1016
|
+
"--with-filename",
|
|
1017
|
+
"--line-number",
|
|
1018
|
+
"--color=never",
|
|
1019
|
+
"--trim",
|
|
1020
|
+
"--max-columns=400",
|
|
1021
|
+
"-C",
|
|
1022
|
+
"1",
|
|
1023
|
+
...params.glob ? ["--glob", params.glob] : [],
|
|
1024
|
+
...this.excludes.flatMap((e) => ["-g", `!${e}`]),
|
|
1025
|
+
params.pattern,
|
|
1026
|
+
targetArg || "."
|
|
1027
|
+
];
|
|
1028
|
+
const res = await runRipgrep(args, { cwd: this.repoRoot });
|
|
1029
|
+
if (res.exitCode === -1) {
|
|
1030
|
+
return {
|
|
1031
|
+
lines: [],
|
|
1032
|
+
error: `[RIPGREP NOT AVAILABLE] ripgrep (rg) is required but failed to execute. Please install it:
|
|
1033
|
+
\u2022 macOS: brew install ripgrep
|
|
1034
|
+
\u2022 Ubuntu/Debian: apt install ripgrep
|
|
1035
|
+
\u2022 Windows: choco install ripgrep
|
|
1036
|
+
\u2022 Or visit: https://github.com/BurntSushi/ripgrep#installation
|
|
1037
|
+
Exit code: ${res.exitCode}${res.stderr ? `
|
|
1038
|
+
Details: ${res.stderr}` : ""}`
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
if (res.exitCode !== 0 && res.exitCode !== 1) {
|
|
1042
|
+
return {
|
|
1043
|
+
lines: [],
|
|
1044
|
+
error: `[RIPGREP ERROR] grep failed with exit code ${res.exitCode}${res.stderr ? `: ${res.stderr}` : ""}`
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
const lines = (res.stdout || "").trim().split(/\r?\n/).filter((l) => l.length > 0);
|
|
1048
|
+
if (lines.length > AGENT_CONFIG.MAX_OUTPUT_LINES) {
|
|
1049
|
+
return {
|
|
1050
|
+
lines: [],
|
|
1051
|
+
error: "query not specific enough, tool tried to return too much context and failed"
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
return { lines };
|
|
1055
|
+
}
|
|
1056
|
+
async read(params) {
|
|
1057
|
+
let abs;
|
|
1058
|
+
try {
|
|
1059
|
+
abs = resolveUnderRepo(this.repoRoot, params.path);
|
|
1060
|
+
} catch (err) {
|
|
1061
|
+
return {
|
|
1062
|
+
lines: [],
|
|
1063
|
+
error: `[PATH ERROR] ${err instanceof Error ? err.message : String(err)}`
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
const stat = await import_promises2.default.stat(abs).catch(() => null);
|
|
1067
|
+
if (!stat || !stat.isFile()) {
|
|
1068
|
+
return {
|
|
1069
|
+
lines: [],
|
|
1070
|
+
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.`
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
if (isSymlink(abs)) {
|
|
1074
|
+
return {
|
|
1075
|
+
lines: [],
|
|
1076
|
+
error: `[SYMLINK] You tried to read "${params.path}" but this is a symlink. Try reading the actual file it points to instead.`
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
if (!isTextualFile(abs)) {
|
|
1080
|
+
return {
|
|
1081
|
+
lines: [],
|
|
1082
|
+
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.`
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
let lines;
|
|
1086
|
+
try {
|
|
1087
|
+
lines = await readAllLines(abs);
|
|
1088
|
+
} catch (err) {
|
|
1089
|
+
return {
|
|
1090
|
+
lines: [],
|
|
1091
|
+
error: `[READ ERROR] Failed to read "${params.path}": ${err instanceof Error ? err.message : String(err)}`
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
const total = lines.length;
|
|
1095
|
+
let s = params.start ?? 1;
|
|
1096
|
+
let e = Math.min(params.end ?? total, total);
|
|
1097
|
+
if (s > total && total > 0) {
|
|
1098
|
+
s = 1;
|
|
1099
|
+
e = total;
|
|
1100
|
+
}
|
|
1101
|
+
const out = [];
|
|
1102
|
+
for (let i = s; i <= e; i += 1) {
|
|
1103
|
+
const content = lines[i - 1] ?? "";
|
|
1104
|
+
out.push(`${i}|${content}`);
|
|
1105
|
+
}
|
|
1106
|
+
if (out.length > AGENT_CONFIG.MAX_READ_LINES) {
|
|
1107
|
+
const truncated = out.slice(0, AGENT_CONFIG.MAX_READ_LINES);
|
|
1108
|
+
truncated.push(`... [truncated: showing ${AGENT_CONFIG.MAX_READ_LINES} of ${out.length} lines]`);
|
|
1109
|
+
return { lines: truncated };
|
|
1110
|
+
}
|
|
1111
|
+
return { lines: out };
|
|
1112
|
+
}
|
|
1113
|
+
async listDirectory(params) {
|
|
1114
|
+
let abs;
|
|
1115
|
+
try {
|
|
1116
|
+
abs = resolveUnderRepo(this.repoRoot, params.path);
|
|
1117
|
+
} catch {
|
|
1118
|
+
return [];
|
|
1119
|
+
}
|
|
1120
|
+
const stat = await import_promises2.default.stat(abs).catch(() => null);
|
|
1121
|
+
if (!stat || !stat.isDirectory()) {
|
|
1122
|
+
return [];
|
|
1123
|
+
}
|
|
1124
|
+
const maxResults = params.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES;
|
|
1125
|
+
const maxDepth = params.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
1126
|
+
const regex = params.pattern ? new RegExp(params.pattern) : null;
|
|
1127
|
+
const results = [];
|
|
1128
|
+
let timedOut = false;
|
|
1129
|
+
const startTime = Date.now();
|
|
1130
|
+
async function walk(dir, depth) {
|
|
1131
|
+
if (Date.now() - startTime > AGENT_CONFIG.LIST_TIMEOUT_MS) {
|
|
1132
|
+
timedOut = true;
|
|
1133
|
+
return;
|
|
1134
|
+
}
|
|
1135
|
+
if (depth > maxDepth || results.length >= maxResults) return;
|
|
1136
|
+
const entries = await import_promises2.default.readdir(dir, { withFileTypes: true });
|
|
1137
|
+
for (const entry of entries) {
|
|
1138
|
+
if (timedOut || results.length >= maxResults) break;
|
|
1139
|
+
const full = import_path3.default.join(dir, entry.name);
|
|
1140
|
+
const rel = toRepoRelative(abs, full).replace(/^[.][/\\]?/, "");
|
|
1141
|
+
if (DEFAULT_EXCLUDES.some((ex) => rel.split(import_path3.default.sep).includes(ex))) continue;
|
|
1142
|
+
if (regex && !regex.test(entry.name)) continue;
|
|
1143
|
+
results.push({
|
|
1144
|
+
name: entry.name,
|
|
1145
|
+
path: toRepoRelative(import_path3.default.resolve(""), full),
|
|
1146
|
+
// relative display
|
|
1147
|
+
type: entry.isDirectory() ? "dir" : "file",
|
|
1148
|
+
depth
|
|
1149
|
+
});
|
|
1150
|
+
if (entry.isDirectory()) {
|
|
1151
|
+
await walk(full, depth + 1);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
await walk(abs, 0);
|
|
1156
|
+
return results;
|
|
1157
|
+
}
|
|
1158
|
+
};
|
|
1159
|
+
|
|
1160
|
+
// tools/warp_grep/harness.ts
|
|
1161
|
+
var parser = new LLMResponseParser();
|
|
1162
|
+
function parseToolCalls(text) {
|
|
1163
|
+
return parser.parse(text);
|
|
1164
|
+
}
|
|
1165
|
+
async function resolveFinishFiles(provider, files) {
|
|
1166
|
+
return readFinishFiles("", files, async (p, s, e) => {
|
|
1167
|
+
const r = await provider.read({ path: p, start: s, end: e });
|
|
1168
|
+
return r.lines.map((l) => {
|
|
1169
|
+
const idx = l.indexOf("|");
|
|
1170
|
+
return idx >= 0 ? l.slice(idx + 1) : l;
|
|
1171
|
+
});
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
1174
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1175
|
+
0 && (module.exports = {
|
|
1176
|
+
AGENT_CONFIG,
|
|
1177
|
+
DEFAULT_EXCLUDES,
|
|
1178
|
+
LLMResponseParser,
|
|
1179
|
+
LocalRipgrepProvider,
|
|
1180
|
+
SYSTEM_PROMPT,
|
|
1181
|
+
buildInitialState,
|
|
1182
|
+
calculateContextBudget,
|
|
1183
|
+
formatListDirectoryTree,
|
|
1184
|
+
formatToolResult,
|
|
1185
|
+
formatTurnMessage,
|
|
1186
|
+
getSystemPrompt,
|
|
1187
|
+
normalizeFinishFiles,
|
|
1188
|
+
parseToolCalls,
|
|
1189
|
+
readFinishFiles,
|
|
1190
|
+
resolveFinishFiles,
|
|
1191
|
+
toolGrep,
|
|
1192
|
+
toolListDirectory,
|
|
1193
|
+
toolRead
|
|
1194
|
+
});
|
|
1195
|
+
//# sourceMappingURL=harness.cjs.map
|