@morphllm/morphsdk 0.2.201 → 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-DBNSOYQ3.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-WBTXEJOC.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-P2KW2O5R.js → chunk-AJBZA23L.js} +3 -25
- package/dist/chunk-AWFZKS27.cjs +11 -0
- package/dist/{chunk-FVT4PU4I.js → chunk-AXEKIRRY.js} +22 -62
- package/dist/chunk-B3FD67F2.cjs +256 -0
- package/dist/chunk-BJBWWIZV.cjs +2 -0
- package/dist/{chunk-M6AVXUM4.js → chunk-E3XNKAMI.js} +5 -15
- package/dist/{chunk-TS3OJ4LA.js → chunk-E7FLETFO.js} +2 -8
- package/dist/{chunk-EQAWWVKV.js → chunk-EI2M567U.js} +2 -6
- package/dist/chunk-EJTL2BOZ.cjs +42 -0
- package/dist/chunk-ETBRAKVV.js +1 -5
- package/dist/{chunk-VOXUA5ZH.js → chunk-EZ2OFDBJ.js} +5 -19
- package/dist/chunk-FBOZIVVQ.js +1 -0
- package/dist/{chunk-TZC3EOZS.js → chunk-GDFPZ3NJ.js} +4 -19
- package/dist/{chunk-LISSWRUD.js → chunk-GIQAIHUI.js} +8 -33
- package/dist/chunk-GSUQGDCL.cjs +235 -0
- package/dist/{chunk-5NSYDT36.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-B376VMIH.js → chunk-IUM6CQYX.js} +3 -12
- package/dist/{chunk-OVLUL5AC.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-ILY5N5NJ.js → chunk-JUGNTIVU.js} +6 -19
- package/dist/{chunk-SU7AAS3O.js → chunk-JY6COF3X.js} +5 -22
- package/dist/{chunk-JBAY3PRV.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-RZOJ4GSY.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-I26FQELI.js → chunk-MLPZKUCO.js} +11 -5
- package/dist/chunk-MWXJ6DZ2.cjs +21 -0
- package/dist/{chunk-NWGRW4V7.js → chunk-N7UKZ5X7.js} +2 -6
- package/dist/chunk-NDUC7OV6.cjs +74 -0
- package/dist/{chunk-RJXAXR7Q.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-BZXOAC2R.js → 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 -4353
- 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 -4424
- 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 -2777
- 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 -2754
- 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 -2554
- package/dist/tools/warp_grep/anthropic.js +19 -35
- package/dist/tools/warp_grep/client.cjs +49 -2464
- package/dist/tools/warp_grep/client.js +17 -34
- package/dist/tools/warp_grep/gemini.cjs +48 -2483
- package/dist/tools/warp_grep/gemini.js +21 -41
- package/dist/tools/warp_grep/harness.cjs +81 -929
- package/dist/tools/warp_grep/harness.js +12 -51
- package/dist/tools/warp_grep/index.cjs +124 -2568
- package/dist/tools/warp_grep/index.js +24 -87
- package/dist/tools/warp_grep/openai.cjs +53 -2568
- 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 -582
- 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 -86
- package/dist/tools/warp_grep/utils/ripgrep.js +2 -7
- package/dist/tools/warp_grep/vercel.cjs +53 -2550
- 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-UZCXOOZO.js +0 -203
|
@@ -1,1086 +1,20 @@
|
|
|
1
|
-
|
|
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);
|
|
1
|
+
'use strict';
|
|
29
2
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// tools/warp_grep/agent/config.ts
|
|
39
|
-
var parseEnvTimeout = (envValue, defaultMs) => {
|
|
40
|
-
if (!envValue) return defaultMs;
|
|
41
|
-
const parsed = parseInt(envValue, 10);
|
|
42
|
-
return isNaN(parsed) || parsed <= 0 ? defaultMs : parsed;
|
|
43
|
-
};
|
|
44
|
-
var AGENT_CONFIG = {
|
|
45
|
-
MAX_TURNS: 6,
|
|
46
|
-
/** Default timeout for model calls. Can be overridden via MORPH_WARP_GREP_TIMEOUT env var (in ms) */
|
|
47
|
-
TIMEOUT_MS: parseEnvTimeout(process.env.MORPH_WARP_GREP_TIMEOUT, 6e4),
|
|
48
|
-
MAX_CONTEXT_CHARS: 321600,
|
|
49
|
-
MAX_OUTPUT_LINES: 200,
|
|
50
|
-
MAX_LIST_RESULTS: 500,
|
|
51
|
-
MAX_READ_LINES: 800,
|
|
52
|
-
MAX_LIST_DEPTH: 3,
|
|
53
|
-
LIST_TIMEOUT_MS: 2e3
|
|
54
|
-
};
|
|
55
|
-
var BUILTIN_EXCLUDES = [
|
|
56
|
-
// Version control
|
|
57
|
-
".git",
|
|
58
|
-
".svn",
|
|
59
|
-
".hg",
|
|
60
|
-
".bzr",
|
|
61
|
-
// Dependencies
|
|
62
|
-
"node_modules",
|
|
63
|
-
"bower_components",
|
|
64
|
-
".pnpm",
|
|
65
|
-
".yarn",
|
|
66
|
-
"vendor",
|
|
67
|
-
"packages",
|
|
68
|
-
"Pods",
|
|
69
|
-
".bundle",
|
|
70
|
-
// Python
|
|
71
|
-
"__pycache__",
|
|
72
|
-
".pytest_cache",
|
|
73
|
-
".mypy_cache",
|
|
74
|
-
".ruff_cache",
|
|
75
|
-
".venv",
|
|
76
|
-
"venv",
|
|
77
|
-
".tox",
|
|
78
|
-
".nox",
|
|
79
|
-
".eggs",
|
|
80
|
-
"*.egg-info",
|
|
81
|
-
// Build outputs
|
|
82
|
-
"dist",
|
|
83
|
-
"build",
|
|
84
|
-
"out",
|
|
85
|
-
"output",
|
|
86
|
-
"target",
|
|
87
|
-
"_build",
|
|
88
|
-
".next",
|
|
89
|
-
".nuxt",
|
|
90
|
-
".output",
|
|
91
|
-
".vercel",
|
|
92
|
-
".netlify",
|
|
93
|
-
// Cache directories
|
|
94
|
-
".cache",
|
|
95
|
-
".parcel-cache",
|
|
96
|
-
".turbo",
|
|
97
|
-
".nx",
|
|
98
|
-
".gradle",
|
|
99
|
-
// IDE/Editor
|
|
100
|
-
".idea",
|
|
101
|
-
".vscode",
|
|
102
|
-
".vs",
|
|
103
|
-
// Coverage
|
|
104
|
-
"coverage",
|
|
105
|
-
".coverage",
|
|
106
|
-
"htmlcov",
|
|
107
|
-
".nyc_output",
|
|
108
|
-
// Temporary
|
|
109
|
-
"tmp",
|
|
110
|
-
"temp",
|
|
111
|
-
".tmp",
|
|
112
|
-
".temp",
|
|
113
|
-
// Lock files
|
|
114
|
-
"package-lock.json",
|
|
115
|
-
"yarn.lock",
|
|
116
|
-
"pnpm-lock.yaml",
|
|
117
|
-
"bun.lockb",
|
|
118
|
-
"Cargo.lock",
|
|
119
|
-
"Gemfile.lock",
|
|
120
|
-
"poetry.lock",
|
|
121
|
-
// Binary/minified
|
|
122
|
-
"*.min.js",
|
|
123
|
-
"*.min.css",
|
|
124
|
-
"*.bundle.js",
|
|
125
|
-
"*.wasm",
|
|
126
|
-
"*.so",
|
|
127
|
-
"*.dll",
|
|
128
|
-
"*.pyc",
|
|
129
|
-
"*.map",
|
|
130
|
-
"*.js.map",
|
|
131
|
-
// Hidden directories catch-all
|
|
132
|
-
".*"
|
|
133
|
-
];
|
|
134
|
-
var DEFAULT_EXCLUDES = (process.env.MORPH_WARP_GREP_EXCLUDE || "").split(",").map((s) => s.trim()).filter(Boolean).concat(BUILTIN_EXCLUDES);
|
|
135
|
-
var DEFAULT_MODEL = "morph-warp-grep-v2.1";
|
|
136
|
-
|
|
137
|
-
// tools/warp_grep/agent/parser.ts
|
|
138
|
-
function parseReadLines(linesStr) {
|
|
139
|
-
const ranges = [];
|
|
140
|
-
for (const rangeStr of linesStr.split(",")) {
|
|
141
|
-
const trimmed = rangeStr.trim();
|
|
142
|
-
if (!trimmed) continue;
|
|
143
|
-
const parts = trimmed.split("-").map((v) => parseInt(v.trim(), 10));
|
|
144
|
-
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
145
|
-
ranges.push([parts[0], parts[1]]);
|
|
146
|
-
} else if (Number.isFinite(parts[0])) {
|
|
147
|
-
ranges.push([parts[0], parts[0]]);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (ranges.length === 1) return { start: ranges[0][0], end: ranges[0][1] };
|
|
151
|
-
if (ranges.length > 1) return { lines: ranges };
|
|
152
|
-
return {};
|
|
153
|
-
}
|
|
154
|
-
function parseFinishFiles(filesStr) {
|
|
155
|
-
const files = [];
|
|
156
|
-
for (const line of filesStr.trim().split(/\s+/)) {
|
|
157
|
-
const trimmed = line.trim();
|
|
158
|
-
if (!trimmed) continue;
|
|
159
|
-
const searchFrom = /^[A-Za-z]:/.test(trimmed) ? 2 : 0;
|
|
160
|
-
const colonIdx = trimmed.indexOf(":", searchFrom);
|
|
161
|
-
if (colonIdx === -1) {
|
|
162
|
-
files.push({ path: trimmed, lines: "*" });
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
const filePath = trimmed.slice(0, colonIdx);
|
|
166
|
-
const rangesPart = trimmed.slice(colonIdx + 1);
|
|
167
|
-
if (!rangesPart.trim() || rangesPart.trim() === "*") {
|
|
168
|
-
files.push({ path: filePath, lines: "*" });
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
const ranges = [];
|
|
172
|
-
for (const rangeStr of rangesPart.split(",")) {
|
|
173
|
-
const rt = rangeStr.trim();
|
|
174
|
-
if (!rt) continue;
|
|
175
|
-
const parts = rt.split("-").map((v) => parseInt(v.trim(), 10));
|
|
176
|
-
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
177
|
-
ranges.push([parts[0], parts[1]]);
|
|
178
|
-
} else if (Number.isFinite(parts[0])) {
|
|
179
|
-
ranges.push([parts[0], parts[0]]);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
files.push({ path: filePath, lines: ranges.length > 0 ? ranges : "*" });
|
|
183
|
-
}
|
|
184
|
-
return files;
|
|
185
|
-
}
|
|
186
|
-
function extractPathFromCommand(command) {
|
|
187
|
-
const tokens = command.trim().split(/\s+/);
|
|
188
|
-
const pathTokens = tokens.slice(1).filter((t) => !t.startsWith("-") && !t.startsWith("|") && !t.startsWith("\\("));
|
|
189
|
-
return pathTokens[0] || ".";
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// tools/warp_grep/agent/tools/grep.ts
|
|
193
|
-
async function toolGrep(provider, args) {
|
|
194
|
-
const res = await provider.grep(args);
|
|
195
|
-
if (res.error) {
|
|
196
|
-
return { output: res.error };
|
|
197
|
-
}
|
|
198
|
-
if (!res.lines.length) {
|
|
199
|
-
return { output: "no matches" };
|
|
200
|
-
}
|
|
201
|
-
return { output: res.lines.join("\n") };
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// tools/warp_grep/agent/tools/read.ts
|
|
205
|
-
function isValidRange(start, end) {
|
|
206
|
-
return typeof start === "number" && typeof end === "number" && Number.isFinite(start) && Number.isFinite(end) && start > 0 && end >= start;
|
|
207
|
-
}
|
|
208
|
-
async function toolRead(provider, args) {
|
|
209
|
-
if (args.lines && Array.isArray(args.lines) && args.lines.length > 0) {
|
|
210
|
-
const validRanges = [];
|
|
211
|
-
for (const range of args.lines) {
|
|
212
|
-
if (Array.isArray(range) && range.length >= 2 && isValidRange(range[0], range[1])) {
|
|
213
|
-
validRanges.push([range[0], range[1]]);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if (validRanges.length === 0) {
|
|
217
|
-
const res2 = await provider.read({ path: args.path });
|
|
218
|
-
if (res2.error) return res2.error;
|
|
219
|
-
if (!res2.lines.length) return "(empty file)";
|
|
220
|
-
return res2.lines.join("\n");
|
|
221
|
-
}
|
|
222
|
-
const chunks = [];
|
|
223
|
-
for (const [start, end] of validRanges) {
|
|
224
|
-
const res2 = await provider.read({ path: args.path, start, end });
|
|
225
|
-
if (res2.error) return res2.error;
|
|
226
|
-
chunks.push(res2.lines.join("\n"));
|
|
227
|
-
}
|
|
228
|
-
if (chunks.every((c) => c === "")) return "(empty file)";
|
|
229
|
-
return chunks.join("\n...\n");
|
|
230
|
-
}
|
|
231
|
-
const res = await provider.read({ path: args.path, start: args.start, end: args.end });
|
|
232
|
-
if (res.error) {
|
|
233
|
-
return res.error;
|
|
234
|
-
}
|
|
235
|
-
if (!res.lines.length) return "(empty file)";
|
|
236
|
-
return res.lines.join("\n");
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// tools/warp_grep/agent/tools/list_directory.ts
|
|
240
|
-
var import_path = __toESM(require("path"), 1);
|
|
241
|
-
async function toolListDirectory(provider, args, repoRoot) {
|
|
242
|
-
const maxResults = args.maxResults ?? AGENT_CONFIG.MAX_LIST_RESULTS;
|
|
243
|
-
const maxDepth = args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
244
|
-
const entries = await provider.listDirectory({
|
|
245
|
-
path: args.path,
|
|
246
|
-
pattern: args.pattern ?? null,
|
|
247
|
-
maxResults,
|
|
248
|
-
maxDepth
|
|
249
|
-
});
|
|
250
|
-
if (!entries.length) return "empty";
|
|
251
|
-
if (repoRoot) {
|
|
252
|
-
const absRoot = repoRoot;
|
|
253
|
-
const lines = entries.map((e) => import_path.default.join(absRoot, e.path));
|
|
254
|
-
return lines.join("\n");
|
|
255
|
-
}
|
|
256
|
-
return entries.map((e) => e.path).join("\n");
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// tools/warp_grep/agent/tools/glob.ts
|
|
260
|
-
async function toolGlob(provider, args) {
|
|
261
|
-
const res = await provider.glob(args);
|
|
262
|
-
if (res.error) {
|
|
263
|
-
return res.error;
|
|
264
|
-
}
|
|
265
|
-
if (!res.files.length) {
|
|
266
|
-
return "no matches";
|
|
267
|
-
}
|
|
268
|
-
const header = `Found ${res.totalFound} file(s) matching "${args.pattern}" within ${res.searchDir}, sorted by modification time (newest first):`;
|
|
269
|
-
const body = res.files.join("\n");
|
|
270
|
-
const truncated = res.totalFound > res.files.length ? `
|
|
271
|
-
[${res.totalFound - res.files.length} files truncated]` : "";
|
|
272
|
-
return `${header}
|
|
273
|
-
---
|
|
274
|
-
${body}
|
|
275
|
-
---${truncated}`;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// tools/warp_grep/agent/tools/finish.ts
|
|
279
|
-
function isValidRange2(range) {
|
|
280
|
-
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];
|
|
281
|
-
}
|
|
282
|
-
function extractValidRanges(lines) {
|
|
283
|
-
if (!Array.isArray(lines)) return null;
|
|
284
|
-
const valid = [];
|
|
285
|
-
for (const range of lines) {
|
|
286
|
-
if (isValidRange2(range)) {
|
|
287
|
-
valid.push([range[0], range[1]]);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
return valid.length > 0 ? valid : null;
|
|
291
|
-
}
|
|
292
|
-
async function readFinishFiles(repoRoot, files, reader) {
|
|
293
|
-
const out = [];
|
|
294
|
-
for (const f of files) {
|
|
295
|
-
const validRanges = f.lines === "*" ? null : extractValidRanges(f.lines);
|
|
296
|
-
if (f.lines === "*" || !validRanges) {
|
|
297
|
-
const lines = await reader(f.path);
|
|
298
|
-
out.push({ path: f.path, ranges: "*", content: lines.join("\n") });
|
|
299
|
-
} else {
|
|
300
|
-
const ranges = mergeRanges(validRanges);
|
|
301
|
-
const chunks = [];
|
|
302
|
-
for (let i = 0; i < ranges.length; i++) {
|
|
303
|
-
const [s, e] = ranges[i];
|
|
304
|
-
if (i === 0 && s > 1) {
|
|
305
|
-
chunks.push(`// ... existing code, block starting at line ${s} ...`);
|
|
306
|
-
} else if (i > 0) {
|
|
307
|
-
chunks.push(`// ... existing code, block starting at line ${s} ...`);
|
|
308
|
-
}
|
|
309
|
-
const lines = await reader(f.path, s, e);
|
|
310
|
-
chunks.push(lines.join("\n"));
|
|
311
|
-
}
|
|
312
|
-
out.push({ path: f.path, ranges, content: chunks.join("\n") });
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return out;
|
|
316
|
-
}
|
|
317
|
-
function mergeRanges(ranges) {
|
|
318
|
-
if (!ranges.length) return [];
|
|
319
|
-
const sorted = [...ranges].sort((a, b) => a[0] - b[0]);
|
|
320
|
-
const merged = [];
|
|
321
|
-
let [cs, ce] = sorted[0];
|
|
322
|
-
for (let i = 1; i < sorted.length; i++) {
|
|
323
|
-
const [s, e] = sorted[i];
|
|
324
|
-
if (s <= ce + 1) {
|
|
325
|
-
ce = Math.max(ce, e);
|
|
326
|
-
} else {
|
|
327
|
-
merged.push([cs, ce]);
|
|
328
|
-
cs = s;
|
|
329
|
-
ce = e;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
merged.push([cs, ce]);
|
|
333
|
-
return merged;
|
|
334
|
-
}
|
|
3
|
+
var chunkHMLYJVZM_cjs = require('../../../chunk-HMLYJVZM.cjs');
|
|
4
|
+
require('../../../chunk-KVGZ2TSG.cjs');
|
|
5
|
+
require('../../../chunk-4EQQGUZ7.cjs');
|
|
6
|
+
require('../../../chunk-UNX7V6P6.cjs');
|
|
7
|
+
require('../../../chunk-VL4QNALG.cjs');
|
|
8
|
+
require('../../../chunk-TL34BLQD.cjs');
|
|
9
|
+
require('../../../chunk-75ZPJI57.cjs');
|
|
335
10
|
|
|
336
|
-
// tools/warp_grep/agent/helpers.ts
|
|
337
|
-
var import_path2 = __toESM(require("path"), 1);
|
|
338
|
-
var TRUNCATED_MARKER = "[truncated for context limit]";
|
|
339
|
-
function getMessageSize(m) {
|
|
340
|
-
if (m.role === "tool") return m.content.length;
|
|
341
|
-
if (m.role === "assistant") {
|
|
342
|
-
let size = typeof m.content === "string" ? m.content.length : 0;
|
|
343
|
-
if (m.tool_calls) {
|
|
344
|
-
size += m.tool_calls.reduce((s, tc) => s + tc.function.name.length + tc.function.arguments.length, 0);
|
|
345
|
-
}
|
|
346
|
-
return size;
|
|
347
|
-
}
|
|
348
|
-
return m.content.length;
|
|
349
|
-
}
|
|
350
|
-
function formatTurnMessage(turnsUsed, maxTurns) {
|
|
351
|
-
const turnsRemaining = maxTurns - turnsUsed;
|
|
352
|
-
if (turnsRemaining === 1) {
|
|
353
|
-
return `
|
|
354
|
-
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`;
|
|
355
|
-
}
|
|
356
|
-
return `
|
|
357
|
-
You have used ${turnsUsed} turn${turnsUsed === 1 ? "" : "s"} and have ${turnsRemaining} remaining`;
|
|
358
|
-
}
|
|
359
|
-
function calculateContextBudget(messages) {
|
|
360
|
-
const totalChars = messages.reduce((sum, m) => sum + getMessageSize(m), 0);
|
|
361
|
-
const maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS;
|
|
362
|
-
const percent = Math.floor(totalChars / maxChars * 100);
|
|
363
|
-
const usedK = Math.floor(totalChars / 1e3);
|
|
364
|
-
const maxK = Math.floor(maxChars / 1e3);
|
|
365
|
-
return `<context_budget>${percent}% (${usedK}K/${maxK}K chars)</context_budget>`;
|
|
366
|
-
}
|
|
367
|
-
async function buildInitialState(repoRoot, searchTerm, provider, options) {
|
|
368
|
-
const budget = calculateContextBudget([]);
|
|
369
|
-
const turnTag = `You have used 0 turns and have ${AGENT_CONFIG.MAX_TURNS} remaining`;
|
|
370
|
-
const treeDepth = options?.search_type === "node_modules" ? 1 : 2;
|
|
371
|
-
const absRoot = repoRoot;
|
|
372
|
-
try {
|
|
373
|
-
const entries = await provider.listDirectory({
|
|
374
|
-
path: ".",
|
|
375
|
-
maxResults: AGENT_CONFIG.MAX_OUTPUT_LINES,
|
|
376
|
-
maxDepth: treeDepth
|
|
377
|
-
});
|
|
378
|
-
const lines = [absRoot];
|
|
379
|
-
for (const e of entries) {
|
|
380
|
-
lines.push(import_path2.default.join(absRoot, e.path));
|
|
381
|
-
}
|
|
382
|
-
return `<repo_structure>
|
|
383
|
-
${lines.join("\n")}
|
|
384
|
-
</repo_structure>
|
|
385
11
|
|
|
386
|
-
<search_string>
|
|
387
|
-
${searchTerm}
|
|
388
|
-
</search_string>
|
|
389
|
-
${budget}
|
|
390
|
-
${turnTag}`;
|
|
391
|
-
} catch {
|
|
392
|
-
return `<repo_structure>
|
|
393
|
-
${absRoot}
|
|
394
|
-
</repo_structure>
|
|
395
12
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
function enforceContextLimit(messages, maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS) {
|
|
404
|
-
const getTotalChars = () => messages.reduce((sum, m) => sum + getMessageSize(m), 0);
|
|
405
|
-
if (getTotalChars() <= maxChars) {
|
|
406
|
-
return messages;
|
|
407
|
-
}
|
|
408
|
-
const truncatableIndices = [];
|
|
409
|
-
let firstUserSkipped = false;
|
|
410
|
-
for (let i = 0; i < messages.length; i++) {
|
|
411
|
-
const m = messages[i];
|
|
412
|
-
if (m.role === "tool") {
|
|
413
|
-
truncatableIndices.push(i);
|
|
414
|
-
} else if (m.role === "user") {
|
|
415
|
-
if (!firstUserSkipped) {
|
|
416
|
-
firstUserSkipped = true;
|
|
417
|
-
continue;
|
|
418
|
-
}
|
|
419
|
-
truncatableIndices.push(i);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
for (const idx of truncatableIndices) {
|
|
423
|
-
if (getTotalChars() <= maxChars) {
|
|
424
|
-
break;
|
|
425
|
-
}
|
|
426
|
-
const m = messages[idx];
|
|
427
|
-
if (m.role === "tool" && m.content !== TRUNCATED_MARKER) {
|
|
428
|
-
messages[idx] = { role: "tool", tool_call_id: m.tool_call_id, content: TRUNCATED_MARKER };
|
|
429
|
-
} else if (m.role === "user" && m.content !== TRUNCATED_MARKER) {
|
|
430
|
-
messages[idx] = { role: "user", content: TRUNCATED_MARKER };
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
return messages;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// tools/warp_grep/agent/runner.ts
|
|
437
|
-
var import_openai = __toESM(require("openai"), 1);
|
|
438
|
-
|
|
439
|
-
// package.json
|
|
440
|
-
var package_default = {
|
|
441
|
-
name: "@morphllm/morphsdk",
|
|
442
|
-
version: "0.2.201",
|
|
443
|
-
description: "TypeScript SDK and CLI for Morph Fast Apply integration",
|
|
444
|
-
type: "module",
|
|
445
|
-
main: "./dist/index.cjs",
|
|
446
|
-
module: "./dist/index.js",
|
|
447
|
-
types: "./dist/index.d.ts",
|
|
448
|
-
exports: {
|
|
449
|
-
".": {
|
|
450
|
-
types: "./dist/index.d.ts",
|
|
451
|
-
import: "./dist/index.js",
|
|
452
|
-
require: "./dist/index.cjs"
|
|
453
|
-
},
|
|
454
|
-
"./logger": {
|
|
455
|
-
types: "./dist/logger.d.ts",
|
|
456
|
-
import: "./dist/logger.js",
|
|
457
|
-
require: "./dist/logger.cjs"
|
|
458
|
-
},
|
|
459
|
-
"./edge": {
|
|
460
|
-
types: "./dist/edge.d.ts",
|
|
461
|
-
import: "./dist/edge.js",
|
|
462
|
-
require: "./dist/edge.cjs"
|
|
463
|
-
},
|
|
464
|
-
"./tools/warp-grep": {
|
|
465
|
-
types: "./dist/tools/warp_grep/index.d.ts",
|
|
466
|
-
import: "./dist/tools/warp_grep/index.js",
|
|
467
|
-
require: "./dist/tools/warp_grep/index.cjs"
|
|
468
|
-
},
|
|
469
|
-
"./tools/warp-grep/openai": {
|
|
470
|
-
types: "./dist/tools/warp_grep/openai.d.ts",
|
|
471
|
-
import: "./dist/tools/warp_grep/openai.js",
|
|
472
|
-
require: "./dist/tools/warp_grep/openai.cjs"
|
|
473
|
-
},
|
|
474
|
-
"./tools/warp-grep/anthropic": {
|
|
475
|
-
types: "./dist/tools/warp_grep/anthropic.d.ts",
|
|
476
|
-
import: "./dist/tools/warp_grep/anthropic.js",
|
|
477
|
-
require: "./dist/tools/warp_grep/anthropic.cjs"
|
|
478
|
-
},
|
|
479
|
-
"./tools/warp-grep/vercel": {
|
|
480
|
-
types: "./dist/tools/warp_grep/vercel.d.ts",
|
|
481
|
-
import: "./dist/tools/warp_grep/vercel.js",
|
|
482
|
-
require: "./dist/tools/warp_grep/vercel.cjs"
|
|
483
|
-
},
|
|
484
|
-
"./tools/warp-grep/client": {
|
|
485
|
-
types: "./dist/tools/warp_grep/client.d.ts",
|
|
486
|
-
import: "./dist/tools/warp_grep/client.js",
|
|
487
|
-
require: "./dist/tools/warp_grep/client.cjs"
|
|
488
|
-
},
|
|
489
|
-
"./tools/warp-grep/gemini": {
|
|
490
|
-
types: "./dist/tools/warp_grep/gemini.d.ts",
|
|
491
|
-
import: "./dist/tools/warp_grep/gemini.js",
|
|
492
|
-
require: "./dist/tools/warp_grep/gemini.cjs"
|
|
493
|
-
},
|
|
494
|
-
"./tools/warp-grep/harness": {
|
|
495
|
-
types: "./dist/tools/warp_grep/harness.d.ts",
|
|
496
|
-
import: "./dist/tools/warp_grep/harness.js",
|
|
497
|
-
require: "./dist/tools/warp_grep/harness.cjs"
|
|
498
|
-
},
|
|
499
|
-
"./tools/fastapply": {
|
|
500
|
-
types: "./dist/tools/fastapply/index.d.ts",
|
|
501
|
-
import: "./dist/tools/fastapply/index.js",
|
|
502
|
-
require: "./dist/tools/fastapply/index.cjs"
|
|
503
|
-
},
|
|
504
|
-
"./tools/fastapply/anthropic": {
|
|
505
|
-
types: "./dist/tools/fastapply/anthropic.d.ts",
|
|
506
|
-
import: "./dist/tools/fastapply/anthropic.js",
|
|
507
|
-
require: "./dist/tools/fastapply/anthropic.cjs"
|
|
508
|
-
},
|
|
509
|
-
"./tools/fastapply/openai": {
|
|
510
|
-
types: "./dist/tools/fastapply/openai.d.ts",
|
|
511
|
-
import: "./dist/tools/fastapply/openai.js",
|
|
512
|
-
require: "./dist/tools/fastapply/openai.cjs"
|
|
513
|
-
},
|
|
514
|
-
"./tools/fastapply/vercel": {
|
|
515
|
-
types: "./dist/tools/fastapply/vercel.d.ts",
|
|
516
|
-
import: "./dist/tools/fastapply/vercel.js",
|
|
517
|
-
require: "./dist/tools/fastapply/vercel.cjs"
|
|
518
|
-
},
|
|
519
|
-
"./modelrouter": {
|
|
520
|
-
types: "./dist/modelrouter/index.d.ts",
|
|
521
|
-
import: "./dist/modelrouter/index.js",
|
|
522
|
-
require: "./dist/modelrouter/index.cjs"
|
|
523
|
-
},
|
|
524
|
-
"./tools/compact": {
|
|
525
|
-
types: "./dist/tools/compact/index.d.ts",
|
|
526
|
-
import: "./dist/tools/compact/index.js",
|
|
527
|
-
require: "./dist/tools/compact/index.cjs"
|
|
528
|
-
},
|
|
529
|
-
"./subagents": {
|
|
530
|
-
types: "./dist/subagents/index.d.ts",
|
|
531
|
-
import: "./dist/subagents/index.js",
|
|
532
|
-
require: "./dist/subagents/index.cjs"
|
|
533
|
-
},
|
|
534
|
-
"./subagents/vercel": {
|
|
535
|
-
types: "./dist/subagents/vercel.d.ts",
|
|
536
|
-
import: "./dist/subagents/vercel.js",
|
|
537
|
-
require: "./dist/subagents/vercel.cjs"
|
|
538
|
-
},
|
|
539
|
-
"./subagents/anthropic": {
|
|
540
|
-
types: "./dist/subagents/anthropic.d.ts",
|
|
541
|
-
import: "./dist/subagents/anthropic.js",
|
|
542
|
-
require: "./dist/subagents/anthropic.cjs"
|
|
543
|
-
},
|
|
544
|
-
"./ai-sdk": {
|
|
545
|
-
types: "./dist/ai-sdk/index.d.ts",
|
|
546
|
-
import: "./dist/ai-sdk/index.js",
|
|
547
|
-
require: "./dist/ai-sdk/index.cjs"
|
|
548
|
-
}
|
|
549
|
-
},
|
|
550
|
-
files: [
|
|
551
|
-
"dist/**/*.js",
|
|
552
|
-
"dist/**/*.cjs",
|
|
553
|
-
"dist/**/*.d.ts",
|
|
554
|
-
"!dist/**/__tests__/**",
|
|
555
|
-
"!dist/**/*.test.*"
|
|
556
|
-
],
|
|
557
|
-
scripts: {
|
|
558
|
-
build: "tsup version.ts index.ts edge.ts client.ts core/index.ts core/client.ts core/resource.ts core/error.ts tools/index.ts tools/fastapply/index.ts tools/fastapply/core.ts tools/fastapply/apply.ts tools/fastapply/types.ts tools/fastapply/prompts.ts tools/fastapply/anthropic.ts tools/fastapply/openai.ts tools/fastapply/vercel.ts tools/warp_grep/index.ts tools/warp_grep/client.ts tools/warp_grep/openai.ts tools/warp_grep/anthropic.ts tools/warp_grep/vercel.ts tools/warp_grep/gemini.ts tools/warp_grep/harness.ts tools/warp_grep/agent/config.ts tools/warp_grep/agent/parser.ts tools/warp_grep/agent/runner.ts tools/warp_grep/agent/types.ts tools/warp_grep/agent/formatter.ts tools/warp_grep/providers/types.ts tools/warp_grep/providers/local.ts tools/warp_grep/providers/remote.ts tools/warp_grep/providers/code_storage_http.ts tools/warp_grep/tools/grep.ts tools/warp_grep/tools/analyse.ts tools/warp_grep/tools/read.ts tools/warp_grep/tools/finish.ts tools/warp_grep/utils/paths.ts tools/warp_grep/utils/github.ts tools/warp_grep/utils/ripgrep.ts tools/warp_grep/utils/format.ts tools/warp_grep/utils/files.ts modelrouter/index.ts modelrouter/core.ts modelrouter/types.ts tools/compact/index.ts tools/compact/core.ts tools/compact/types.ts tools/utils/resilience.ts subagents/index.ts subagents/types.ts subagents/prompts.ts subagents/vercel.ts subagents/anthropic.ts --format esm,cjs --clean --dts --dts-resolve && tsup ai-sdk/index.ts --format esm,cjs --dts --no-clean --out-dir dist/ai-sdk",
|
|
559
|
-
prepare: "npm run build",
|
|
560
|
-
typecheck: "tsc --noEmit && tsc --noEmit -p ai-sdk/tsconfig.json",
|
|
561
|
-
lint: "eslint .",
|
|
562
|
-
test: "vitest run",
|
|
563
|
-
"test:watch": "vitest watch",
|
|
564
|
-
"test:anthropic": "vitest run anthropic",
|
|
565
|
-
"test:openai": "vitest run openai",
|
|
566
|
-
"test:vercel": "vitest run vercel",
|
|
567
|
-
"test:git": "vitest run git",
|
|
568
|
-
"test:agent": "npx tsx tests/fullAgentTest.ts",
|
|
569
|
-
"test:integration": "npx tsx tests/fullIntegrationTest.ts",
|
|
570
|
-
"test:e2e": "vitest run --config vitest.e2e.config.ts",
|
|
571
|
-
"release:patch": "npm version patch && npm publish",
|
|
572
|
-
"release:minor": "npm version minor && npm publish",
|
|
573
|
-
"release:major": "npm version major && npm publish"
|
|
574
|
-
},
|
|
575
|
-
keywords: [
|
|
576
|
-
"morph",
|
|
577
|
-
"fast-apply",
|
|
578
|
-
"cli",
|
|
579
|
-
"sdk",
|
|
580
|
-
"edit-file"
|
|
581
|
-
],
|
|
582
|
-
engines: {
|
|
583
|
-
node: ">=18"
|
|
584
|
-
},
|
|
585
|
-
license: "MIT",
|
|
586
|
-
dependencies: {
|
|
587
|
-
"@vscode/ripgrep": "^1.17.0",
|
|
588
|
-
ai: ">=5.0.0",
|
|
589
|
-
diff: "^7.0.0",
|
|
590
|
-
openai: "^4.52.7",
|
|
591
|
-
zod: ">=3.23.0"
|
|
592
|
-
},
|
|
593
|
-
devDependencies: {
|
|
594
|
-
"@ai-sdk/anthropic": "^2.0.70",
|
|
595
|
-
"@ai-sdk/openai": "^2.0.35",
|
|
596
|
-
"@anthropic-ai/sdk": "^0.30.1",
|
|
597
|
-
"@google/generative-ai": "^0.24.1",
|
|
598
|
-
"@types/diff": "^7.0.2",
|
|
599
|
-
"@types/node": "^20.14.10",
|
|
600
|
-
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
601
|
-
"@typescript-eslint/parser": "^7.18.0",
|
|
602
|
-
dotenv: "^16.4.5",
|
|
603
|
-
eslint: "^8.57.0",
|
|
604
|
-
shx: "^0.3.4",
|
|
605
|
-
tsup: "^8.5.0",
|
|
606
|
-
tsx: "^4.16.2",
|
|
607
|
-
typescript: "^5.5.4",
|
|
608
|
-
vitest: "^2.1.6"
|
|
609
|
-
},
|
|
610
|
-
peerDependencies: {
|
|
611
|
-
"@ai-sdk/openai-compatible": ">=2.0.74 <4",
|
|
612
|
-
"@anthropic-ai/sdk": ">=0.25.0",
|
|
613
|
-
"@google/generative-ai": ">=0.21.0",
|
|
614
|
-
ai: ">=5.0.0",
|
|
615
|
-
zod: ">=3.23.0"
|
|
616
|
-
},
|
|
617
|
-
peerDependenciesMeta: {
|
|
618
|
-
"@anthropic-ai/sdk": {
|
|
619
|
-
optional: true
|
|
620
|
-
},
|
|
621
|
-
"@google/generative-ai": {
|
|
622
|
-
optional: true
|
|
623
|
-
},
|
|
624
|
-
ai: {
|
|
625
|
-
optional: true
|
|
626
|
-
},
|
|
627
|
-
zod: {
|
|
628
|
-
optional: true
|
|
629
|
-
}
|
|
630
|
-
},
|
|
631
|
-
publishConfig: {
|
|
632
|
-
access: "public"
|
|
633
|
-
}
|
|
634
|
-
};
|
|
635
|
-
|
|
636
|
-
// version.ts
|
|
637
|
-
var SDK_VERSION = package_default.version;
|
|
638
|
-
|
|
639
|
-
// tools/warp_grep/agent/runner.ts
|
|
640
|
-
var import_path3 = __toESM(require("path"), 1);
|
|
641
|
-
|
|
642
|
-
// logger.ts
|
|
643
|
-
var MorphLogger = class {
|
|
644
|
-
enabled;
|
|
645
|
-
fileStream;
|
|
646
|
-
/** Resolves once the file stream is initialized (or immediately if no file logging). */
|
|
647
|
-
ready;
|
|
648
|
-
constructor() {
|
|
649
|
-
this.enabled = typeof process !== "undefined" && (process.env.MORPH_DEBUG === "1" || !!process.env.MORPH_LOG_FILE);
|
|
650
|
-
this.fileStream = null;
|
|
651
|
-
const f = typeof process !== "undefined" ? process.env.MORPH_LOG_FILE : void 0;
|
|
652
|
-
if (f) {
|
|
653
|
-
this.ready = import("fs").then((fs) => {
|
|
654
|
-
this.fileStream = fs.createWriteStream(f, { flags: "a" });
|
|
655
|
-
}).catch(() => {
|
|
656
|
-
});
|
|
657
|
-
} else {
|
|
658
|
-
this.ready = Promise.resolve();
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
debug(component, msg, data) {
|
|
662
|
-
this._log("debug", component, msg, data);
|
|
663
|
-
}
|
|
664
|
-
info(component, msg, data) {
|
|
665
|
-
this._log("info", component, msg, data);
|
|
666
|
-
}
|
|
667
|
-
warn(component, msg, data) {
|
|
668
|
-
this._log("warn", component, msg, data);
|
|
669
|
-
}
|
|
670
|
-
error(component, msg, data) {
|
|
671
|
-
this._log("error", component, msg, data);
|
|
672
|
-
}
|
|
673
|
-
enable() {
|
|
674
|
-
this.enabled = true;
|
|
675
|
-
}
|
|
676
|
-
get isEnabled() {
|
|
677
|
-
return this.enabled;
|
|
678
|
-
}
|
|
679
|
-
_log(level, component, msg, data) {
|
|
680
|
-
if (level !== "error" && !this.enabled) return;
|
|
681
|
-
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
682
|
-
const prefix = `[${ts}] [${level.toUpperCase()}] [${component}]`;
|
|
683
|
-
console.error(data ? `${prefix} ${msg} ${JSON.stringify(data)}` : `${prefix} ${msg}`);
|
|
684
|
-
this.fileStream?.write(JSON.stringify({ ts, level, component, msg, ...data && { data } }) + "\n");
|
|
685
|
-
}
|
|
686
|
-
};
|
|
687
|
-
var logger = new MorphLogger();
|
|
688
|
-
|
|
689
|
-
// tools/warp_grep/agent/runner.ts
|
|
690
|
-
var DEFAULT_API_URL = "https://api.morphllm.com";
|
|
691
|
-
var TOOL_SPECS = [
|
|
692
|
-
{
|
|
693
|
-
type: "function",
|
|
694
|
-
function: {
|
|
695
|
-
name: "list_directory",
|
|
696
|
-
description: "Execute ls or find commands to explore directory structure. Max 500 results. Common junk directories are excluded automatically.",
|
|
697
|
-
parameters: {
|
|
698
|
-
type: "object",
|
|
699
|
-
properties: {
|
|
700
|
-
command: {
|
|
701
|
-
type: "string",
|
|
702
|
-
description: "Full ls or find command (e.g. ls -la src/, find . -maxdepth 2 -type f -name '*.py', find . -type d, ls -d */)."
|
|
703
|
-
}
|
|
704
|
-
},
|
|
705
|
-
required: ["command"]
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
},
|
|
709
|
-
{
|
|
710
|
-
type: "function",
|
|
711
|
-
function: {
|
|
712
|
-
name: "grep_search",
|
|
713
|
-
description: "Search for a regex pattern in file contents. Returns matching lines with file paths and line numbers. Case-insensitive. Respects .gitignore.",
|
|
714
|
-
parameters: {
|
|
715
|
-
type: "object",
|
|
716
|
-
properties: {
|
|
717
|
-
pattern: {
|
|
718
|
-
type: "string",
|
|
719
|
-
description: "Regex pattern to search for in file contents (e.g. 'class\\s+\\w+Error', 'import|require|from', 'def (get|set|update)_user')."
|
|
720
|
-
},
|
|
721
|
-
path: {
|
|
722
|
-
type: "string",
|
|
723
|
-
description: "File or directory to search in. Defaults to current working directory."
|
|
724
|
-
},
|
|
725
|
-
glob: {
|
|
726
|
-
type: "string",
|
|
727
|
-
description: "Glob pattern to filter files (e.g. '*.py', '*.{ts,tsx,js,jsx,py,go}', 'src/**/*.go', '!*.test.*')."
|
|
728
|
-
},
|
|
729
|
-
limit: {
|
|
730
|
-
type: "integer",
|
|
731
|
-
description: "Limit output to first N matching lines. Shows all matches if not specified."
|
|
732
|
-
}
|
|
733
|
-
},
|
|
734
|
-
required: ["pattern"]
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
},
|
|
738
|
-
{
|
|
739
|
-
type: "function",
|
|
740
|
-
function: {
|
|
741
|
-
name: "glob",
|
|
742
|
-
description: "Find files by name/extension using glob patterns. Returns absolute paths sorted by modification time (newest first). Respects .gitignore. Max 100 results.",
|
|
743
|
-
parameters: {
|
|
744
|
-
type: "object",
|
|
745
|
-
properties: {
|
|
746
|
-
pattern: {
|
|
747
|
-
type: "string",
|
|
748
|
-
description: "Glob pattern to match files (e.g. '*.py', 'src/**/*.js', '*.{ts,tsx}', 'test_*.py')."
|
|
749
|
-
},
|
|
750
|
-
path: {
|
|
751
|
-
type: "string",
|
|
752
|
-
description: "Directory to search in. Defaults to repository root."
|
|
753
|
-
}
|
|
754
|
-
},
|
|
755
|
-
required: ["pattern"]
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
},
|
|
759
|
-
{
|
|
760
|
-
type: "function",
|
|
761
|
-
function: {
|
|
762
|
-
name: "read",
|
|
763
|
-
description: "Read entire files or specific line ranges using absolute paths.",
|
|
764
|
-
parameters: {
|
|
765
|
-
type: "object",
|
|
766
|
-
properties: {
|
|
767
|
-
path: {
|
|
768
|
-
type: "string",
|
|
769
|
-
description: "File path to read, using absolute path (e.g. '/home/ubuntu/repo/src/main.py' or windows path)."
|
|
770
|
-
},
|
|
771
|
-
lines: {
|
|
772
|
-
type: "string",
|
|
773
|
-
description: "Optional line range (e.g. '1-50' or '1-20,45-80'). Omit to read entire file."
|
|
774
|
-
}
|
|
775
|
-
},
|
|
776
|
-
required: ["path"]
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
},
|
|
780
|
-
{
|
|
781
|
-
type: "function",
|
|
782
|
-
function: {
|
|
783
|
-
name: "finish",
|
|
784
|
-
description: "Submit final answer with all relevant code locations. Include imports and over-include rather than miss context.",
|
|
785
|
-
parameters: {
|
|
786
|
-
type: "object",
|
|
787
|
-
properties: {
|
|
788
|
-
files: {
|
|
789
|
-
type: "string",
|
|
790
|
-
description: "One file per line as path:lines (e.g. 'src/auth.py:1-15,25-50\\nsrc/user.py'). Omit line range to include entire file."
|
|
791
|
-
}
|
|
792
|
-
},
|
|
793
|
-
required: ["files"]
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
];
|
|
798
|
-
async function callModel(messages, model, options = {}) {
|
|
799
|
-
const baseUrl = options.morphApiUrl || DEFAULT_API_URL;
|
|
800
|
-
const apiKey = options.morphApiKey || process.env.MORPH_API_KEY || "";
|
|
801
|
-
const timeoutMs = options.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
802
|
-
const parsedUrl = new URL(baseUrl);
|
|
803
|
-
const baseURL = parsedUrl.pathname === "/" ? `${baseUrl}/v1` : baseUrl;
|
|
804
|
-
const client = new import_openai.default({
|
|
805
|
-
apiKey,
|
|
806
|
-
baseURL,
|
|
807
|
-
maxRetries: 0,
|
|
808
|
-
timeout: timeoutMs,
|
|
809
|
-
defaultHeaders: { "X-Morph-SDK-Version": SDK_VERSION }
|
|
810
|
-
});
|
|
811
|
-
const MAX_EMPTY_RETRIES = 1;
|
|
812
|
-
logger.debug("WarpGrep", "model_call", { url: baseURL, model, message_count: messages.length });
|
|
813
|
-
const callStartTime = Date.now();
|
|
814
|
-
for (let attempt = 0; attempt <= MAX_EMPTY_RETRIES; attempt++) {
|
|
815
|
-
let data;
|
|
816
|
-
try {
|
|
817
|
-
data = await client.chat.completions.create({
|
|
818
|
-
model,
|
|
819
|
-
temperature: 0,
|
|
820
|
-
max_tokens: 2048,
|
|
821
|
-
messages,
|
|
822
|
-
tools: TOOL_SPECS,
|
|
823
|
-
...options.search_type ? { search_type: options.search_type } : {}
|
|
824
|
-
});
|
|
825
|
-
} catch (error) {
|
|
826
|
-
const callLatencyMs = Date.now() - callStartTime;
|
|
827
|
-
if (error instanceof import_openai.default.APIError) {
|
|
828
|
-
logger.error("WarpGrep", "model_call_error", { status: error.status, error: error.message, latency_ms: callLatencyMs });
|
|
829
|
-
if (error.status === 404) {
|
|
830
|
-
const defaultMsg = "The endpoint you are trying to call is likely deprecated. Please update with: npm cache clean --force && npx -y @morphllm/morphmcp@latest or visit: https://morphllm.com/mcp";
|
|
831
|
-
const errorText = error.message?.trim();
|
|
832
|
-
throw new Error(errorText || defaultMsg);
|
|
833
|
-
}
|
|
834
|
-
} else {
|
|
835
|
-
logger.error("WarpGrep", "model_call_error", { status: void 0, error: error instanceof Error ? error.message : String(error), latency_ms: callLatencyMs });
|
|
836
|
-
}
|
|
837
|
-
throw error;
|
|
838
|
-
}
|
|
839
|
-
const choice = data?.choices?.[0];
|
|
840
|
-
const message = choice?.message;
|
|
841
|
-
if (!message) {
|
|
842
|
-
if (attempt === MAX_EMPTY_RETRIES) {
|
|
843
|
-
throw new Error("Invalid response from model: no message in response");
|
|
844
|
-
}
|
|
845
|
-
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
846
|
-
continue;
|
|
847
|
-
}
|
|
848
|
-
const toolCalls = (message.tool_calls || []).map((tc) => ({
|
|
849
|
-
id: tc.id,
|
|
850
|
-
type: "function",
|
|
851
|
-
function: { name: tc.function.name, arguments: tc.function.arguments }
|
|
852
|
-
}));
|
|
853
|
-
if (message.content || toolCalls.length > 0) {
|
|
854
|
-
logger.debug("WarpGrep", "model_call_complete", { latency_ms: Date.now() - callStartTime, tool_calls_count: toolCalls.length, finish_reason: choice?.finish_reason ?? "unknown" });
|
|
855
|
-
return { content: message.content ?? null, tool_calls: toolCalls };
|
|
856
|
-
}
|
|
857
|
-
if (attempt === MAX_EMPTY_RETRIES) {
|
|
858
|
-
const finishReason = choice?.finish_reason ?? "unknown";
|
|
859
|
-
throw new Error(
|
|
860
|
-
`Invalid response from model: no content and no tool_calls, finish_reason=${finishReason}`
|
|
861
|
-
);
|
|
862
|
-
}
|
|
863
|
-
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
864
|
-
}
|
|
865
|
-
throw new Error("Invalid response from model");
|
|
866
|
-
}
|
|
867
|
-
function safeParseJSON(s) {
|
|
868
|
-
try {
|
|
869
|
-
return JSON.parse(s);
|
|
870
|
-
} catch {
|
|
871
|
-
return {};
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
async function executeTool(provider, name, args, repoRoot) {
|
|
875
|
-
switch (name) {
|
|
876
|
-
case "grep_search": {
|
|
877
|
-
const grepArgs = {
|
|
878
|
-
pattern: args.pattern,
|
|
879
|
-
path: args.path || "."
|
|
880
|
-
};
|
|
881
|
-
if (args.glob) grepArgs.glob = args.glob;
|
|
882
|
-
if (args.case_sensitive !== void 0) grepArgs.case_sensitive = args.case_sensitive;
|
|
883
|
-
const result = await toolGrep(provider, grepArgs);
|
|
884
|
-
let output = result.output;
|
|
885
|
-
if (args.limit && typeof args.limit === "number") {
|
|
886
|
-
const lines = output.split("\n");
|
|
887
|
-
if (lines.length > args.limit) {
|
|
888
|
-
output = lines.slice(0, args.limit).join("\n") + `
|
|
889
|
-
... (truncated at ${args.limit} lines)`;
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
return output;
|
|
893
|
-
}
|
|
894
|
-
case "glob": {
|
|
895
|
-
return toolGlob(provider, {
|
|
896
|
-
pattern: args.pattern,
|
|
897
|
-
path: args.path
|
|
898
|
-
});
|
|
899
|
-
}
|
|
900
|
-
case "list_directory": {
|
|
901
|
-
const dirPath = extractPathFromCommand(args.command || ".");
|
|
902
|
-
return toolListDirectory(provider, { path: dirPath }, repoRoot);
|
|
903
|
-
}
|
|
904
|
-
case "read": {
|
|
905
|
-
const readArgs = {
|
|
906
|
-
path: args.path
|
|
907
|
-
};
|
|
908
|
-
if (args.lines && typeof args.lines === "string") {
|
|
909
|
-
Object.assign(readArgs, parseReadLines(args.lines));
|
|
910
|
-
}
|
|
911
|
-
return toolRead(provider, readArgs);
|
|
912
|
-
}
|
|
913
|
-
default:
|
|
914
|
-
return `Unknown tool: ${name}`;
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
async function* runWarpGrepStreaming(config) {
|
|
918
|
-
const totalStart = Date.now();
|
|
919
|
-
const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
920
|
-
const timings = { turns: [], timeout_ms: timeoutMs };
|
|
921
|
-
const repoRoot = config.repoRoot || process.cwd();
|
|
922
|
-
const model = config.model || DEFAULT_MODEL;
|
|
923
|
-
const messages = [];
|
|
924
|
-
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
925
|
-
logger.debug("WarpGrep", "session_start", { search_term: config.searchTerm, model, max_turns: maxTurns });
|
|
926
|
-
const initialStateStart = Date.now();
|
|
927
|
-
const initialState = await buildInitialState(repoRoot, config.searchTerm, config.provider, { search_type: config.search_type });
|
|
928
|
-
timings.initial_state_ms = Date.now() - initialStateStart;
|
|
929
|
-
logger.debug("WarpGrep", "initial_state", { system_prompt_len: initialState.length, user_message_len: initialState.length });
|
|
930
|
-
messages.push({ role: "user", content: initialState });
|
|
931
|
-
const provider = config.provider;
|
|
932
|
-
const errors = [];
|
|
933
|
-
let finishMeta;
|
|
934
|
-
let terminationReason = "terminated";
|
|
935
|
-
for (let turn = 1; turn <= maxTurns; turn += 1) {
|
|
936
|
-
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
937
|
-
logger.debug("WarpGrep", "turn_start", { turn, message_count: messages.length });
|
|
938
|
-
const beforeChars = messages.reduce((sum, m) => sum + (typeof m.content === "string" ? m.content.length : 0), 0);
|
|
939
|
-
enforceContextLimit(messages);
|
|
940
|
-
const afterChars = messages.reduce((sum, m) => sum + (typeof m.content === "string" ? m.content.length : 0), 0);
|
|
941
|
-
if (afterChars < beforeChars) {
|
|
942
|
-
logger.debug("WarpGrep", "context_truncated", { before_chars: beforeChars, after_chars: afterChars });
|
|
943
|
-
}
|
|
944
|
-
const modelCallStart = Date.now();
|
|
945
|
-
const response = await callModel(messages, model, {
|
|
946
|
-
morphApiKey: config.morphApiKey,
|
|
947
|
-
morphApiUrl: config.morphApiUrl,
|
|
948
|
-
retryConfig: config.retryConfig,
|
|
949
|
-
timeout: timeoutMs,
|
|
950
|
-
search_type: config.search_type
|
|
951
|
-
}).catch((e) => {
|
|
952
|
-
const errMsg = e instanceof Error ? e.message : String(e);
|
|
953
|
-
console.error(`[warp_grep] Morph API call failed on turn ${turn}:`, errMsg);
|
|
954
|
-
logger.error("WarpGrep", "error", { turn, error: errMsg, phase: "model_call" });
|
|
955
|
-
errors.push({ message: errMsg });
|
|
956
|
-
return null;
|
|
957
|
-
});
|
|
958
|
-
turnMetrics.morph_api_ms = Date.now() - modelCallStart;
|
|
959
|
-
if (!response) {
|
|
960
|
-
timings.turns.push(turnMetrics);
|
|
961
|
-
break;
|
|
962
|
-
}
|
|
963
|
-
const toolCalls = response.tool_calls;
|
|
964
|
-
logger.debug("WarpGrep", "model_response", { turn, tool_calls: toolCalls.map((tc) => tc.function.name), latency_ms: turnMetrics.morph_api_ms });
|
|
965
|
-
messages.push({
|
|
966
|
-
role: "assistant",
|
|
967
|
-
content: response.content,
|
|
968
|
-
...toolCalls.length > 0 ? { tool_calls: toolCalls } : {}
|
|
969
|
-
});
|
|
970
|
-
if (toolCalls.length === 0) {
|
|
971
|
-
console.error(`[warp_grep] No tool calls on turn ${turn}. Content: ${(response.content || "").slice(0, 500)}`);
|
|
972
|
-
errors.push({ message: "No tool calls produced by the model." });
|
|
973
|
-
terminationReason = "terminated";
|
|
974
|
-
timings.turns.push(turnMetrics);
|
|
975
|
-
break;
|
|
976
|
-
}
|
|
977
|
-
yield {
|
|
978
|
-
turn,
|
|
979
|
-
toolCalls: toolCalls.map((tc) => ({
|
|
980
|
-
name: tc.function.name,
|
|
981
|
-
arguments: safeParseJSON(tc.function.arguments)
|
|
982
|
-
}))
|
|
983
|
-
};
|
|
984
|
-
const finishCall = toolCalls.find((tc) => tc.function.name === "finish");
|
|
985
|
-
if (finishCall) {
|
|
986
|
-
const args = safeParseJSON(finishCall.function.arguments);
|
|
987
|
-
const filesStr = args.files || "";
|
|
988
|
-
const files = parseFinishFiles(filesStr);
|
|
989
|
-
finishMeta = { files };
|
|
990
|
-
terminationReason = "completed";
|
|
991
|
-
logger.debug("WarpGrep", "finish", { turns: turn, files: files.map((f) => f.path) });
|
|
992
|
-
if (files.length === 0) {
|
|
993
|
-
const payload2 = filesStr || "No relevant code found.";
|
|
994
|
-
timings.turns.push(turnMetrics);
|
|
995
|
-
timings.total_ms = Date.now() - totalStart;
|
|
996
|
-
return {
|
|
997
|
-
terminationReason: "completed",
|
|
998
|
-
messages,
|
|
999
|
-
finish: { payload: payload2, metadata: finishMeta },
|
|
1000
|
-
timings
|
|
1001
|
-
};
|
|
1002
|
-
}
|
|
1003
|
-
timings.turns.push(turnMetrics);
|
|
1004
|
-
break;
|
|
1005
|
-
}
|
|
1006
|
-
const toolExecStart = Date.now();
|
|
1007
|
-
const results = await Promise.all(
|
|
1008
|
-
toolCalls.map(async (tc) => {
|
|
1009
|
-
const args = safeParseJSON(tc.function.arguments);
|
|
1010
|
-
const argsSummary = Object.fromEntries(Object.entries(args).map(([k, v]) => [k, typeof v === "string" && v.length > 100 ? v.slice(0, 100) + "..." : v]));
|
|
1011
|
-
logger.debug("WarpGrep", "tool_exec", { turn, tool: tc.function.name, args_summary: argsSummary });
|
|
1012
|
-
const toolStart = Date.now();
|
|
1013
|
-
const output = await executeTool(provider, tc.function.name, args, repoRoot).catch((err) => String(err));
|
|
1014
|
-
logger.debug("WarpGrep", "tool_result", { turn, tool: tc.function.name, result_len: output.length, latency_ms: Date.now() - toolStart });
|
|
1015
|
-
return { tool_call_id: tc.id, content: output };
|
|
1016
|
-
})
|
|
1017
|
-
);
|
|
1018
|
-
turnMetrics.local_tools_ms = Date.now() - toolExecStart;
|
|
1019
|
-
for (const result of results) {
|
|
1020
|
-
messages.push({ role: "tool", tool_call_id: result.tool_call_id, content: result.content });
|
|
1021
|
-
}
|
|
1022
|
-
const turnMsg = formatTurnMessage(turn, maxTurns);
|
|
1023
|
-
const budget = calculateContextBudget(messages);
|
|
1024
|
-
messages.push({ role: "user", content: turnMsg + "\n" + budget });
|
|
1025
|
-
timings.turns.push(turnMetrics);
|
|
1026
|
-
}
|
|
1027
|
-
if (terminationReason !== "completed" || !finishMeta) {
|
|
1028
|
-
timings.total_ms = Date.now() - totalStart;
|
|
1029
|
-
return { terminationReason, messages, errors, timings };
|
|
1030
|
-
}
|
|
1031
|
-
const parts = ["Relevant context found:"];
|
|
1032
|
-
for (const f of finishMeta.files) {
|
|
1033
|
-
const ranges = f.lines === "*" ? "*" : Array.isArray(f.lines) ? f.lines.map(([s, e]) => `${s}-${e}`).join(", ") : "*";
|
|
1034
|
-
parts.push(`- ${f.path}: ${ranges}`);
|
|
1035
|
-
}
|
|
1036
|
-
const payload = parts.join("\n");
|
|
1037
|
-
const finishResolutionStart = Date.now();
|
|
1038
|
-
const fileReadErrors = [];
|
|
1039
|
-
const resolved = await readFinishFiles(
|
|
1040
|
-
repoRoot,
|
|
1041
|
-
finishMeta.files,
|
|
1042
|
-
async (p, s, e) => {
|
|
1043
|
-
let resolvedPath = p;
|
|
1044
|
-
if (!p.startsWith(repoRoot)) {
|
|
1045
|
-
const relative = p.startsWith("/") ? p.slice(1) : p;
|
|
1046
|
-
resolvedPath = import_path3.default.join(repoRoot, relative);
|
|
1047
|
-
}
|
|
1048
|
-
try {
|
|
1049
|
-
const rr = await provider.read({ path: resolvedPath, start: s, end: e });
|
|
1050
|
-
return rr.lines.map((l) => {
|
|
1051
|
-
const idx = l.indexOf("|");
|
|
1052
|
-
return idx >= 0 ? l.slice(idx + 1) : l;
|
|
1053
|
-
});
|
|
1054
|
-
} catch (err) {
|
|
1055
|
-
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
1056
|
-
fileReadErrors.push({ path: resolvedPath, error: errorMsg });
|
|
1057
|
-
console.error(`[warp_grep] Failed to read file: ${resolvedPath} - ${errorMsg}`);
|
|
1058
|
-
return [`[couldn't find: ${resolvedPath}]`];
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
);
|
|
1062
|
-
timings.finish_resolution_ms = Date.now() - finishResolutionStart;
|
|
1063
|
-
if (fileReadErrors.length > 0) {
|
|
1064
|
-
errors.push(...fileReadErrors.map((e) => ({ message: `File read error: ${e.path} - ${e.error}` })));
|
|
1065
|
-
}
|
|
1066
|
-
timings.total_ms = Date.now() - totalStart;
|
|
1067
|
-
return {
|
|
1068
|
-
terminationReason: "completed",
|
|
1069
|
-
messages,
|
|
1070
|
-
finish: { payload, metadata: finishMeta, resolved },
|
|
1071
|
-
timings
|
|
1072
|
-
};
|
|
1073
|
-
}
|
|
1074
|
-
async function runWarpGrep(config) {
|
|
1075
|
-
const gen = runWarpGrepStreaming(config);
|
|
1076
|
-
let result = await gen.next();
|
|
1077
|
-
while (!result.done) {
|
|
1078
|
-
result = await gen.next();
|
|
1079
|
-
}
|
|
1080
|
-
return result.value;
|
|
1081
|
-
}
|
|
1082
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1083
|
-
0 && (module.exports = {
|
|
1084
|
-
runWarpGrep,
|
|
1085
|
-
runWarpGrepStreaming
|
|
13
|
+
Object.defineProperty(exports, "runWarpGrep", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return chunkHMLYJVZM_cjs.runWarpGrep; }
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "runWarpGrepStreaming", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return chunkHMLYJVZM_cjs.runWarpGrepStreaming; }
|
|
1086
20
|
});
|