@morphllm/morphsdk 0.2.44 → 0.2.46
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/README.md +1 -1
- package/dist/{chunk-TVFGHXPE.js → chunk-3FTAIJBH.js} +4 -4
- package/dist/chunk-5JTJOQUX.js +283 -0
- package/dist/chunk-5JTJOQUX.js.map +1 -0
- package/dist/{chunk-ZRLEAPZV.js → chunk-76DJEQEP.js} +4 -4
- package/dist/{chunk-W3XLPMV3.js → chunk-7HS6YXA3.js} +21 -5
- package/dist/{chunk-W3XLPMV3.js.map → chunk-7HS6YXA3.js.map} +1 -1
- package/dist/chunk-7T7YOPJV.js +82 -0
- package/dist/chunk-7T7YOPJV.js.map +1 -0
- package/dist/chunk-CL45IWIU.js +105 -0
- package/dist/chunk-CL45IWIU.js.map +1 -0
- package/dist/chunk-D6OD3IST.js +70 -0
- package/dist/chunk-D6OD3IST.js.map +1 -0
- package/dist/{chunk-PEGZVGG4.js → chunk-G4AWE5A2.js} +4 -4
- package/dist/{chunk-OUEJ6XEO.js → chunk-GJU7UOFL.js} +4 -4
- package/dist/{chunk-Q7PDN7TS.js → chunk-GZMUGMOZ.js} +1 -1
- package/dist/{chunk-Q7PDN7TS.js.map → chunk-GZMUGMOZ.js.map} +1 -1
- package/dist/chunk-JYBVRF72.js +1 -0
- package/dist/{chunk-EYHXBQQX.js → chunk-LVY5LPEX.js} +70 -10
- package/dist/chunk-LVY5LPEX.js.map +1 -0
- package/dist/{chunk-GDR65N2J.js → chunk-OXHGFHEU.js} +53 -26
- package/dist/chunk-OXHGFHEU.js.map +1 -0
- package/dist/{chunk-VBBJGWHY.js → chunk-P2XKFWFD.js} +2 -2
- package/dist/chunk-PABIV7X6.js +76 -0
- package/dist/chunk-PABIV7X6.js.map +1 -0
- package/dist/{chunk-GTOXMAF2.js → chunk-SWQPIKPY.js} +44 -3
- package/dist/chunk-SWQPIKPY.js.map +1 -0
- package/dist/chunk-TJIUA27P.js +94 -0
- package/dist/chunk-TJIUA27P.js.map +1 -0
- package/dist/{chunk-O5DA5V5S.js → chunk-UBX7QYBD.js} +4 -4
- package/dist/{chunk-X4CQ6D3G.js → chunk-UIZT3KVJ.js} +4 -4
- package/dist/{chunk-UYBIKZPM.js → chunk-UXYK7WZX.js} +2 -2
- package/dist/chunk-WETRQJGU.js +129 -0
- package/dist/chunk-WETRQJGU.js.map +1 -0
- package/dist/client-BGctTHu9.d.ts +318 -0
- package/dist/client.cjs +1954 -53
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +14 -110
- package/dist/client.js +29 -4
- package/dist/core-DxiUwyBe.d.ts +156 -0
- package/dist/git/client.cjs +52 -25
- package/dist/git/client.cjs.map +1 -1
- package/dist/git/client.d.ts +17 -8
- package/dist/git/client.js +1 -1
- package/dist/git/index.cjs +52 -25
- package/dist/git/index.cjs.map +1 -1
- package/dist/git/index.d.ts +1 -1
- package/dist/git/index.js +2 -2
- package/dist/git/types.cjs.map +1 -1
- package/dist/git/types.d.ts +20 -2
- package/dist/index.cjs +2033 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +48 -6
- package/dist/tools/browser/anthropic.cjs +1 -0
- package/dist/tools/browser/anthropic.cjs.map +1 -1
- package/dist/tools/browser/anthropic.js +1 -1
- package/dist/tools/browser/core.cjs +69 -9
- package/dist/tools/browser/core.cjs.map +1 -1
- package/dist/tools/browser/core.js +1 -1
- package/dist/tools/browser/index.cjs +69 -9
- package/dist/tools/browser/index.cjs.map +1 -1
- package/dist/tools/browser/index.js +1 -1
- package/dist/tools/browser/openai.cjs +1 -0
- package/dist/tools/browser/openai.cjs.map +1 -1
- package/dist/tools/browser/openai.js +1 -1
- package/dist/tools/browser/types.cjs.map +1 -1
- package/dist/tools/browser/types.d.ts +2 -0
- package/dist/tools/browser/vercel.cjs +1 -0
- package/dist/tools/browser/vercel.cjs.map +1 -1
- package/dist/tools/browser/vercel.js +1 -1
- package/dist/tools/codebase_search/anthropic.js +2 -2
- package/dist/tools/codebase_search/index.js +9 -9
- package/dist/tools/codebase_search/openai.js +2 -2
- package/dist/tools/codebase_search/vercel.js +2 -2
- package/dist/tools/fastapply/anthropic.js +2 -2
- package/dist/tools/fastapply/index.js +7 -7
- package/dist/tools/fastapply/openai.js +2 -2
- package/dist/tools/fastapply/vercel.js +2 -2
- package/dist/tools/index.js +7 -7
- package/dist/tools/warp_grep/agent/config.cjs +80 -1
- package/dist/tools/warp_grep/agent/config.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/config.js +1 -1
- package/dist/tools/warp_grep/agent/parser.cjs +43 -2
- package/dist/tools/warp_grep/agent/parser.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/parser.js +1 -1
- package/dist/tools/warp_grep/agent/prompt.cjs +89 -45
- 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 +229 -49
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +4 -4
- package/dist/tools/warp_grep/agent/types.js +0 -1
- package/dist/tools/warp_grep/anthropic.cjs +311 -83
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.d.ts +75 -12
- package/dist/tools/warp_grep/anthropic.js +21 -8
- package/dist/tools/warp_grep/index.cjs +415 -126
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.d.ts +17 -4
- package/dist/tools/warp_grep/index.js +29 -21
- package/dist/tools/warp_grep/openai.cjs +314 -83
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.d.ts +73 -29
- package/dist/tools/warp_grep/openai.js +21 -8
- package/dist/tools/warp_grep/providers/command.cjs +80 -1
- package/dist/tools/warp_grep/providers/command.cjs.map +1 -1
- package/dist/tools/warp_grep/providers/command.js +2 -2
- package/dist/tools/warp_grep/providers/local.cjs +80 -1
- package/dist/tools/warp_grep/providers/local.cjs.map +1 -1
- package/dist/tools/warp_grep/providers/local.js +2 -2
- package/dist/tools/warp_grep/vercel.cjs +291 -57
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.d.ts +40 -19
- package/dist/tools/warp_grep/vercel.js +17 -8
- package/package.json +1 -1
- package/dist/chunk-AFEPUNAO.js +0 -15
- package/dist/chunk-AFEPUNAO.js.map +0 -1
- package/dist/chunk-EYHXBQQX.js.map +0 -1
- package/dist/chunk-GDR65N2J.js.map +0 -1
- package/dist/chunk-GTOXMAF2.js.map +0 -1
- package/dist/chunk-HKZB23U7.js +0 -85
- package/dist/chunk-HKZB23U7.js.map +0 -1
- package/dist/chunk-IQHKEIQX.js +0 -54
- package/dist/chunk-IQHKEIQX.js.map +0 -1
- package/dist/chunk-JKFVDM62.js +0 -45
- package/dist/chunk-JKFVDM62.js.map +0 -1
- package/dist/chunk-KL4YVZRF.js +0 -57
- package/dist/chunk-KL4YVZRF.js.map +0 -1
- package/dist/chunk-SMR2T5BT.js +0 -104
- package/dist/chunk-SMR2T5BT.js.map +0 -1
- package/dist/chunk-XYPMN4A3.js +0 -1
- /package/dist/{chunk-TVFGHXPE.js.map → chunk-3FTAIJBH.js.map} +0 -0
- /package/dist/{chunk-ZRLEAPZV.js.map → chunk-76DJEQEP.js.map} +0 -0
- /package/dist/{chunk-PEGZVGG4.js.map → chunk-G4AWE5A2.js.map} +0 -0
- /package/dist/{chunk-OUEJ6XEO.js.map → chunk-GJU7UOFL.js.map} +0 -0
- /package/dist/{chunk-XYPMN4A3.js.map → chunk-JYBVRF72.js.map} +0 -0
- /package/dist/{chunk-VBBJGWHY.js.map → chunk-P2XKFWFD.js.map} +0 -0
- /package/dist/{chunk-O5DA5V5S.js.map → chunk-UBX7QYBD.js.map} +0 -0
- /package/dist/{chunk-X4CQ6D3G.js.map → chunk-UIZT3KVJ.js.map} +0 -0
- /package/dist/{chunk-UYBIKZPM.js.map → chunk-UXYK7WZX.js.map} +0 -0
|
@@ -30,7 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// tools/warp_grep/vercel.ts
|
|
31
31
|
var vercel_exports = {};
|
|
32
32
|
__export(vercel_exports, {
|
|
33
|
-
createMorphWarpGrepTool: () => createMorphWarpGrepTool
|
|
33
|
+
createMorphWarpGrepTool: () => createMorphWarpGrepTool,
|
|
34
|
+
execute: () => execute,
|
|
35
|
+
formatResult: () => formatResult,
|
|
36
|
+
getSystemPrompt: () => getSystemPrompt
|
|
34
37
|
});
|
|
35
38
|
module.exports = __toCommonJS(vercel_exports);
|
|
36
39
|
var import_ai = require("ai");
|
|
@@ -42,84 +45,207 @@ var AGENT_CONFIG = {
|
|
|
42
45
|
MAX_ROUNDS: 10,
|
|
43
46
|
TIMEOUT_MS: 3e4
|
|
44
47
|
};
|
|
45
|
-
var
|
|
48
|
+
var BUILTIN_EXCLUDES = [
|
|
49
|
+
// Version control
|
|
50
|
+
".git",
|
|
51
|
+
".svn",
|
|
52
|
+
".hg",
|
|
53
|
+
".bzr",
|
|
54
|
+
// Dependencies
|
|
55
|
+
"node_modules",
|
|
56
|
+
"bower_components",
|
|
57
|
+
".pnpm",
|
|
58
|
+
".yarn",
|
|
59
|
+
"vendor",
|
|
60
|
+
"packages",
|
|
61
|
+
"Pods",
|
|
62
|
+
".bundle",
|
|
63
|
+
// Python
|
|
64
|
+
"__pycache__",
|
|
65
|
+
".pytest_cache",
|
|
66
|
+
".mypy_cache",
|
|
67
|
+
".ruff_cache",
|
|
68
|
+
".venv",
|
|
69
|
+
"venv",
|
|
70
|
+
".tox",
|
|
71
|
+
".nox",
|
|
72
|
+
".eggs",
|
|
73
|
+
"*.egg-info",
|
|
74
|
+
// Build outputs
|
|
75
|
+
"dist",
|
|
76
|
+
"build",
|
|
77
|
+
"out",
|
|
78
|
+
"output",
|
|
79
|
+
"target",
|
|
80
|
+
"_build",
|
|
81
|
+
".next",
|
|
82
|
+
".nuxt",
|
|
83
|
+
".output",
|
|
84
|
+
".vercel",
|
|
85
|
+
".netlify",
|
|
86
|
+
// Cache directories
|
|
87
|
+
".cache",
|
|
88
|
+
".parcel-cache",
|
|
89
|
+
".turbo",
|
|
90
|
+
".nx",
|
|
91
|
+
".gradle",
|
|
92
|
+
// IDE/Editor
|
|
93
|
+
".idea",
|
|
94
|
+
".vscode",
|
|
95
|
+
".vs",
|
|
96
|
+
// Coverage
|
|
97
|
+
"coverage",
|
|
98
|
+
".coverage",
|
|
99
|
+
"htmlcov",
|
|
100
|
+
".nyc_output",
|
|
101
|
+
// Temporary
|
|
102
|
+
"tmp",
|
|
103
|
+
"temp",
|
|
104
|
+
".tmp",
|
|
105
|
+
".temp",
|
|
106
|
+
// Lock files
|
|
107
|
+
"package-lock.json",
|
|
108
|
+
"yarn.lock",
|
|
109
|
+
"pnpm-lock.yaml",
|
|
110
|
+
"bun.lockb",
|
|
111
|
+
"Cargo.lock",
|
|
112
|
+
"Gemfile.lock",
|
|
113
|
+
"poetry.lock",
|
|
114
|
+
// Binary/minified
|
|
115
|
+
"*.min.js",
|
|
116
|
+
"*.min.css",
|
|
117
|
+
"*.bundle.js",
|
|
118
|
+
"*.wasm",
|
|
119
|
+
"*.so",
|
|
120
|
+
"*.dll",
|
|
121
|
+
"*.pyc",
|
|
122
|
+
"*.map",
|
|
123
|
+
"*.js.map",
|
|
124
|
+
// Hidden directories catch-all
|
|
125
|
+
".*"
|
|
126
|
+
];
|
|
127
|
+
var DEFAULT_EXCLUDES = (process.env.MORPH_WARP_GREP_EXCLUDE || "").split(",").map((s) => s.trim()).filter(Boolean).concat(BUILTIN_EXCLUDES);
|
|
46
128
|
var DEFAULT_MODEL = "morph-warp-grep";
|
|
47
129
|
|
|
48
130
|
// tools/warp_grep/agent/prompt.ts
|
|
49
|
-
var SYSTEM_PROMPT = `You are a code search agent. Your task is to find relevant code
|
|
131
|
+
var SYSTEM_PROMPT = `You are a code search agent. Your task is to find all relevant code for a given query.
|
|
50
132
|
|
|
51
133
|
<workflow>
|
|
52
|
-
You
|
|
134
|
+
You have exactly 4 turns. The 4th turn MUST be a \`finish\` call. Each turn allows up to 8 parallel tool calls.
|
|
53
135
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
136
|
+
- Turn 1: Map the territory OR dive deep (based on query specificity)
|
|
137
|
+
- Turn 2-3: Refine based on findings
|
|
138
|
+
- Turn 4: MUST call \`finish\` with all relevant code locations
|
|
139
|
+
- You MAY call \`finish\` early if confident\u2014but never before at least 1 search turn.
|
|
57
140
|
|
|
58
|
-
|
|
59
|
-
|
|
141
|
+
Remember, if the task feels easy to you, it is strongly desirable to call \`finish\` early using fewer turns, but quality over speed.
|
|
142
|
+
</workflow>
|
|
60
143
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
-
|
|
65
|
-
- \`
|
|
144
|
+
<tools>
|
|
145
|
+
### \`analyse <path> [pattern]\`
|
|
146
|
+
Directory tree or file search. Shows structure of a path, optionally filtered by regex pattern.
|
|
147
|
+
- \`path\`: Required. Directory or file path (use \`.\` for repo root)
|
|
148
|
+
- \`pattern\`: Optional regex to filter results
|
|
66
149
|
|
|
67
|
-
|
|
150
|
+
Examples:
|
|
68
151
|
\`\`\`
|
|
152
|
+
analyse .
|
|
69
153
|
analyse src/api
|
|
70
|
-
analyse . "
|
|
154
|
+
analyse . ".*\\.ts$"
|
|
155
|
+
analyse src "test.*"
|
|
71
156
|
\`\`\`
|
|
72
157
|
|
|
73
|
-
###
|
|
74
|
-
Read
|
|
75
|
-
|
|
76
|
-
-
|
|
77
|
-
- \`[:start-end]\`: Optional 1-based, inclusive line range
|
|
158
|
+
### \`read <path>[:start-end]\`
|
|
159
|
+
Read file contents. Line range is 1-based, inclusive.
|
|
160
|
+
- Returns numbered lines for easy reference
|
|
161
|
+
- Omit range to read entire file
|
|
78
162
|
|
|
79
|
-
|
|
163
|
+
Examples:
|
|
80
164
|
\`\`\`
|
|
81
165
|
read src/main.py
|
|
82
|
-
read src/
|
|
166
|
+
read src/db/conn.py:10-50
|
|
167
|
+
read package.json:1-20
|
|
83
168
|
\`\`\`
|
|
84
169
|
|
|
85
|
-
###
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
-
|
|
89
|
-
- \`<path>\`: Directory or file to search (use \`.\` for the repo root)
|
|
170
|
+
### \`grep '<pattern>' <path>\`
|
|
171
|
+
Ripgrep search. Finds pattern matches across files.
|
|
172
|
+
- \`'<pattern>'\`: Required. Regex pattern wrapped in single quotes
|
|
173
|
+
- \`<path>\`: Required. Directory or file to search (use \`.\` for repo root)
|
|
90
174
|
|
|
91
|
-
|
|
175
|
+
Examples:
|
|
92
176
|
\`\`\`
|
|
93
|
-
grep '
|
|
94
|
-
grep '
|
|
95
|
-
grep '
|
|
177
|
+
grep 'class.*Service' src/
|
|
178
|
+
grep 'def authenticate' .
|
|
179
|
+
grep 'import.*from' src/components/
|
|
180
|
+
grep 'TODO' .
|
|
96
181
|
\`\`\`
|
|
97
182
|
|
|
98
|
-
###
|
|
99
|
-
Submit
|
|
100
|
-
|
|
101
|
-
-
|
|
183
|
+
### \`finish <file1:ranges> [file2:ranges ...]\`
|
|
184
|
+
Submit final answer with all relevant code locations.
|
|
185
|
+
- Include generous line ranges\u2014don't be stingy with context
|
|
186
|
+
- Ranges are comma-separated: \`file.py:10-30,50-60\`
|
|
187
|
+
- ALWAYS include import statements at the top of files (usually lines 1-20)
|
|
188
|
+
- If code spans multiple files, include ALL of them
|
|
189
|
+
- Small files can be returned in full
|
|
102
190
|
|
|
103
|
-
|
|
191
|
+
Examples:
|
|
104
192
|
\`\`\`
|
|
105
|
-
finish src/
|
|
193
|
+
finish src/auth.py:1-15,25-50,75-80 src/models/user.py:1-10,20-45
|
|
194
|
+
finish src/index.ts:1-100
|
|
106
195
|
\`\`\`
|
|
107
|
-
</
|
|
196
|
+
</tools>
|
|
108
197
|
|
|
109
198
|
<strategy>
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
199
|
+
**Before your first tool call, classify the query:**
|
|
200
|
+
|
|
201
|
+
| Query Type | Turn 1 Strategy | Early Finish? |
|
|
202
|
+
|------------|-----------------|---------------|
|
|
203
|
+
| **Specific** (function name, error string, unique identifier) | 8 parallel greps on likely paths | Often by turn 2 |
|
|
204
|
+
| **Conceptual** (how does X work, where is Y handled) | analyse + 2-3 broad greps | Rarely early |
|
|
205
|
+
| **Exploratory** (find all tests, list API endpoints) | analyse at multiple depths | Usually needs 3 turns |
|
|
206
|
+
|
|
207
|
+
**Parallel call patterns:**
|
|
208
|
+
- **Shotgun grep**: Same pattern, 8 different directories\u2014fast coverage
|
|
209
|
+
- **Variant grep**: 8 pattern variations (synonyms, naming conventions)\u2014catches inconsistent codebases
|
|
210
|
+
- **Funnel**: 1 analyse + 7 greps\u2014orient and search simultaneously
|
|
211
|
+
- **Deep read**: 8 reads on files you already identified\u2014gather full context fast
|
|
114
212
|
</strategy>
|
|
115
213
|
|
|
116
214
|
<output_format>
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
-
|
|
215
|
+
EVERY response MUST follow this exact format:
|
|
216
|
+
|
|
217
|
+
1. First, wrap your reasoning in \`<think>...</think>\` tags containing:
|
|
218
|
+
- Query classification (specific/conceptual/exploratory)
|
|
219
|
+
- Confidence estimate (can I finish in 1-2 turns?)
|
|
220
|
+
- This turn's parallel strategy
|
|
221
|
+
- What signals would let me finish early?
|
|
222
|
+
|
|
223
|
+
2. Then, output tool calls wrapped in \`<tool_call>...</tool_call>\` tags, one per line.
|
|
224
|
+
|
|
225
|
+
Example:
|
|
226
|
+
\`\`\`
|
|
227
|
+
<think>
|
|
228
|
+
This is a specific query about authentication. I'll grep for auth-related patterns.
|
|
229
|
+
High confidence I can finish in 2 turns if I find the auth module.
|
|
230
|
+
Strategy: Shotgun grep across likely directories.
|
|
231
|
+
</think>
|
|
232
|
+
<tool_call>grep 'authenticate' src/</tool_call>
|
|
233
|
+
<tool_call>grep 'login' src/</tool_call>
|
|
234
|
+
<tool_call>analyse src/auth</tool_call>
|
|
235
|
+
\`\`\`
|
|
236
|
+
|
|
237
|
+
No commentary outside \`<think>\`. No explanations after tool calls.
|
|
121
238
|
</output_format>
|
|
122
239
|
|
|
240
|
+
<finishing_requirements>
|
|
241
|
+
When calling \`finish\`:
|
|
242
|
+
- Include the import section (typically lines 1-20) of each file
|
|
243
|
+
- Include all function/class definitions that are relevant
|
|
244
|
+
- Include any type definitions, interfaces, or constants used
|
|
245
|
+
- Better to over-include than leave the user missing context
|
|
246
|
+
- If unsure about boundaries, include more rather than less
|
|
247
|
+
</finishing_requirements>
|
|
248
|
+
|
|
123
249
|
Begin your exploration now to find code relevant to the query.`;
|
|
124
250
|
function getSystemPrompt() {
|
|
125
251
|
return SYSTEM_PROMPT;
|
|
@@ -132,13 +258,54 @@ var LLMResponseParseError = class extends Error {
|
|
|
132
258
|
this.name = "LLMResponseParseError";
|
|
133
259
|
}
|
|
134
260
|
};
|
|
261
|
+
var VALID_COMMANDS = ["analyse", "grep", "read", "finish"];
|
|
262
|
+
function preprocessText(text) {
|
|
263
|
+
let processed = text.replace(/<think>[\s\S]*?<\/think>/gi, "");
|
|
264
|
+
const openingTagRegex = /<tool_call>|<tool>/gi;
|
|
265
|
+
const closingTagRegex = /<\/tool_call>|<\/tool>/gi;
|
|
266
|
+
const openingMatches = processed.match(openingTagRegex) || [];
|
|
267
|
+
const closingMatches = processed.match(closingTagRegex) || [];
|
|
268
|
+
if (openingMatches.length > closingMatches.length) {
|
|
269
|
+
const lastClosingMatch = /<\/tool_call>|<\/tool>/gi;
|
|
270
|
+
let lastClosingIndex = -1;
|
|
271
|
+
let match;
|
|
272
|
+
while ((match = lastClosingMatch.exec(processed)) !== null) {
|
|
273
|
+
lastClosingIndex = match.index + match[0].length;
|
|
274
|
+
}
|
|
275
|
+
if (lastClosingIndex > 0) {
|
|
276
|
+
processed = processed.slice(0, lastClosingIndex);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const toolCallLines = [];
|
|
280
|
+
const toolTagRegex = /<tool_call>([\s\S]*?)<\/tool_call>|<tool>([\s\S]*?)<\/tool>/gi;
|
|
281
|
+
let tagMatch;
|
|
282
|
+
while ((tagMatch = toolTagRegex.exec(processed)) !== null) {
|
|
283
|
+
const content = (tagMatch[1] || tagMatch[2] || "").trim();
|
|
284
|
+
if (content) {
|
|
285
|
+
const lines = content.split(/\r?\n/).map((l) => l.trim()).filter((l) => l);
|
|
286
|
+
toolCallLines.push(...lines);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const allLines = processed.split(/\r?\n/).map((l) => l.trim());
|
|
290
|
+
for (const line of allLines) {
|
|
291
|
+
if (!line) continue;
|
|
292
|
+
if (line.startsWith("<")) continue;
|
|
293
|
+
const firstWord = line.split(/\s/)[0];
|
|
294
|
+
if (VALID_COMMANDS.includes(firstWord)) {
|
|
295
|
+
if (!toolCallLines.includes(line)) {
|
|
296
|
+
toolCallLines.push(line);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return toolCallLines;
|
|
301
|
+
}
|
|
135
302
|
var LLMResponseParser = class {
|
|
136
303
|
finishSpecSplitRe = /,(?=[^,\s]+:)/;
|
|
137
304
|
parse(text) {
|
|
138
305
|
if (typeof text !== "string") {
|
|
139
306
|
throw new TypeError("Command text must be a string.");
|
|
140
307
|
}
|
|
141
|
-
const lines = text
|
|
308
|
+
const lines = preprocessText(text);
|
|
142
309
|
const commands = [];
|
|
143
310
|
let finishAccumulator = null;
|
|
144
311
|
lines.forEach((line, idx) => {
|
|
@@ -161,7 +328,7 @@ var LLMResponseParser = class {
|
|
|
161
328
|
finishAccumulator = this.handleFinish(parts, ctx, finishAccumulator);
|
|
162
329
|
break;
|
|
163
330
|
default:
|
|
164
|
-
|
|
331
|
+
break;
|
|
165
332
|
}
|
|
166
333
|
});
|
|
167
334
|
if (finishAccumulator) {
|
|
@@ -703,7 +870,23 @@ async function runWarpGrep(config) {
|
|
|
703
870
|
}
|
|
704
871
|
}
|
|
705
872
|
if (formatted.length > 0) {
|
|
706
|
-
|
|
873
|
+
const turnsUsed = round;
|
|
874
|
+
const turnsRemaining = 4 - turnsUsed;
|
|
875
|
+
let turnMessage;
|
|
876
|
+
if (turnsRemaining === 0) {
|
|
877
|
+
turnMessage = `
|
|
878
|
+
|
|
879
|
+
[Turn ${turnsUsed}/4] This is your LAST turn. You MUST call the finish tool now.`;
|
|
880
|
+
} else if (turnsRemaining === 1) {
|
|
881
|
+
turnMessage = `
|
|
882
|
+
|
|
883
|
+
[Turn ${turnsUsed}/4] You have 1 turn remaining. Next turn you MUST call the finish tool.`;
|
|
884
|
+
} else {
|
|
885
|
+
turnMessage = `
|
|
886
|
+
|
|
887
|
+
[Turn ${turnsUsed}/4] You have ${turnsRemaining} turns remaining.`;
|
|
888
|
+
}
|
|
889
|
+
messages.push({ role: "user", content: formatted.join("\n") + turnMessage });
|
|
707
890
|
}
|
|
708
891
|
if (finishCalls.length) {
|
|
709
892
|
const fc = finishCalls[0];
|
|
@@ -931,14 +1114,62 @@ var LocalRipgrepProvider = class {
|
|
|
931
1114
|
}
|
|
932
1115
|
};
|
|
933
1116
|
|
|
1117
|
+
// tools/warp_grep/prompts.ts
|
|
1118
|
+
var WARP_GREP_DESCRIPTION = "A fast and accurate tool that can search for all relevant context in a codebase. You must use this tool to save time and avoid context pollution.";
|
|
1119
|
+
|
|
1120
|
+
// tools/warp_grep/core.ts
|
|
1121
|
+
function formatResult(result) {
|
|
1122
|
+
if (!result.success) {
|
|
1123
|
+
return `Search failed: ${result.error}`;
|
|
1124
|
+
}
|
|
1125
|
+
if (!result.contexts || result.contexts.length === 0) {
|
|
1126
|
+
return "No relevant code found. Try rephrasing your query.";
|
|
1127
|
+
}
|
|
1128
|
+
const lines = [];
|
|
1129
|
+
lines.push(`Found ${result.contexts.length} relevant code sections:
|
|
1130
|
+
`);
|
|
1131
|
+
result.contexts.forEach((ctx, i) => {
|
|
1132
|
+
lines.push(`${i + 1}. ${ctx.file}`);
|
|
1133
|
+
lines.push("```");
|
|
1134
|
+
lines.push(ctx.content);
|
|
1135
|
+
lines.push("```");
|
|
1136
|
+
lines.push("");
|
|
1137
|
+
});
|
|
1138
|
+
if (result.summary) {
|
|
1139
|
+
lines.push(`Summary: ${result.summary}`);
|
|
1140
|
+
}
|
|
1141
|
+
return lines.join("\n");
|
|
1142
|
+
}
|
|
1143
|
+
|
|
934
1144
|
// tools/warp_grep/vercel.ts
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
1145
|
+
var warpGrepSchema = import_zod.z.object({
|
|
1146
|
+
query: import_zod.z.string().describe("Free-form repository question")
|
|
1147
|
+
});
|
|
1148
|
+
async function execute(input, config) {
|
|
1149
|
+
const provider = config.provider ?? new LocalRipgrepProvider(config.repoRoot, config.excludes);
|
|
1150
|
+
const result = await runWarpGrep({
|
|
1151
|
+
query: input.query,
|
|
1152
|
+
repoRoot: config.repoRoot,
|
|
1153
|
+
provider,
|
|
1154
|
+
excludes: config.excludes,
|
|
1155
|
+
includes: config.includes,
|
|
1156
|
+
debug: config.debug ?? false,
|
|
1157
|
+
apiKey: config.apiKey
|
|
938
1158
|
});
|
|
1159
|
+
const finish = result.finish;
|
|
1160
|
+
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
1161
|
+
return { success: false, error: "Search did not complete" };
|
|
1162
|
+
}
|
|
1163
|
+
const contexts = (finish.resolved ?? []).map((r) => ({
|
|
1164
|
+
file: r.path,
|
|
1165
|
+
content: r.content
|
|
1166
|
+
}));
|
|
1167
|
+
return { success: true, contexts, summary: finish.payload };
|
|
1168
|
+
}
|
|
1169
|
+
function createMorphWarpGrepTool(config) {
|
|
939
1170
|
return (0, import_ai.tool)({
|
|
940
|
-
description: config.description ??
|
|
941
|
-
inputSchema:
|
|
1171
|
+
description: config.description ?? WARP_GREP_DESCRIPTION,
|
|
1172
|
+
inputSchema: warpGrepSchema,
|
|
942
1173
|
execute: async (params) => {
|
|
943
1174
|
const provider = config.provider ?? new LocalRipgrepProvider(config.repoRoot, config.excludes);
|
|
944
1175
|
const result = await runWarpGrep({
|
|
@@ -952,7 +1183,7 @@ function createMorphWarpGrepTool(config) {
|
|
|
952
1183
|
});
|
|
953
1184
|
const finish = result.finish;
|
|
954
1185
|
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
955
|
-
return { success: false, error: "Search did not complete"
|
|
1186
|
+
return { success: false, error: "Search did not complete" };
|
|
956
1187
|
}
|
|
957
1188
|
const contexts = (finish.resolved ?? []).map((r) => ({
|
|
958
1189
|
file: r.path,
|
|
@@ -964,6 +1195,9 @@ function createMorphWarpGrepTool(config) {
|
|
|
964
1195
|
}
|
|
965
1196
|
// Annotate the CommonJS export names for ESM import in node:
|
|
966
1197
|
0 && (module.exports = {
|
|
967
|
-
createMorphWarpGrepTool
|
|
1198
|
+
createMorphWarpGrepTool,
|
|
1199
|
+
execute,
|
|
1200
|
+
formatResult,
|
|
1201
|
+
getSystemPrompt
|
|
968
1202
|
});
|
|
969
1203
|
//# sourceMappingURL=vercel.cjs.map
|