@morphllm/morphsdk 0.2.202 → 0.2.203
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2PPYWRMZ.js +3 -4
- package/dist/{chunk-SIFDK4AA.js → chunk-2UIOCSVJ.js} +3 -24
- package/dist/chunk-44OIEPIO.js +4 -23
- package/dist/chunk-4EQQGUZ7.cjs +104 -0
- package/dist/chunk-4OUGA3KS.js +1 -5
- package/dist/chunk-4R5MDGL6.cjs +280 -0
- package/dist/chunk-65W4I66Q.cjs +103 -0
- package/dist/{chunk-3CPI6ZIC.js → chunk-66THRMD7.js} +10 -35
- package/dist/chunk-6TZCVTW5.js +3 -4
- package/dist/chunk-6WP7EA4F.js +2 -4
- package/dist/chunk-74A4HLIO.cjs +42 -0
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/chunk-7NA7X7W2.cjs +77 -0
- package/dist/chunk-7PJYY46L.cjs +2 -0
- package/dist/chunk-AFF6XYKL.cjs +71 -0
- package/dist/{chunk-2XU3XXUE.js → chunk-AJBZA23L.js} +3 -25
- package/dist/chunk-AWFZKS27.cjs +11 -0
- package/dist/{chunk-LVKKICOB.js → chunk-AXEKIRRY.js} +22 -62
- package/dist/chunk-B3FD67F2.cjs +256 -0
- package/dist/chunk-BJBWWIZV.cjs +2 -0
- package/dist/{chunk-UAZKHSEU.js → chunk-E3XNKAMI.js} +5 -15
- package/dist/{chunk-VQDDL3UH.js → chunk-E7FLETFO.js} +2 -8
- package/dist/{chunk-YAM6P5OQ.js → chunk-EI2M567U.js} +2 -6
- package/dist/chunk-EJTL2BOZ.cjs +42 -0
- package/dist/chunk-ETBRAKVV.js +1 -5
- package/dist/{chunk-6OYJC4TZ.js → chunk-EZ2OFDBJ.js} +5 -19
- package/dist/chunk-FBOZIVVQ.js +1 -0
- package/dist/{chunk-CAWQEHKP.js → chunk-GDFPZ3NJ.js} +4 -19
- package/dist/{chunk-UKXCGQPS.js → chunk-GIQAIHUI.js} +8 -33
- package/dist/chunk-GSUQGDCL.cjs +235 -0
- package/dist/{chunk-D6YJ5X3C.js → chunk-H3HRSRR5.js} +4 -12
- package/dist/chunk-HDP4QAZL.js +1 -4
- package/dist/chunk-HMLYJVZM.cjs +410 -0
- package/dist/chunk-IPJA3ZS6.cjs +10 -0
- package/dist/{chunk-XPHNS7NW.js → chunk-IUM6CQYX.js} +3 -12
- package/dist/{chunk-26K5EJD3.js → chunk-J56Q6C4Y.js} +4 -18
- package/dist/chunk-JBTR3FQD.cjs +135 -0
- package/dist/chunk-JNQKQKHS.cjs +81 -0
- package/dist/chunk-JOZC4T6C.cjs +168 -0
- package/dist/{chunk-JEVLCA5C.js → chunk-JUGNTIVU.js} +6 -19
- package/dist/{chunk-NFPRKZQ5.js → chunk-JY6COF3X.js} +5 -22
- package/dist/{chunk-ICCGLO6V.js → chunk-KLVJIC2O.js} +5 -17
- package/dist/chunk-KSZYOX6S.cjs +91 -0
- package/dist/chunk-KVGZ2TSG.cjs +274 -0
- package/dist/chunk-LDM7RNNN.js +1 -0
- package/dist/{chunk-65TUD7JV.js → chunk-LLQH6CCB.js} +10 -28
- package/dist/chunk-M34E2AMK.js +1 -5
- package/dist/chunk-MF56KEI4.js +1 -4
- package/dist/chunk-MLKGABMK.js +1 -3
- package/dist/chunk-MLPZKUCO.js +4 -5
- package/dist/chunk-MWXJ6DZ2.cjs +21 -0
- package/dist/{chunk-IBRBSDLT.js → chunk-N7UKZ5X7.js} +2 -6
- package/dist/chunk-NDUC7OV6.cjs +74 -0
- package/dist/{chunk-PDSIWL7I.js → chunk-NLACTMZT.js} +6 -19
- package/dist/chunk-NNKBKENK.cjs +15 -0
- package/dist/chunk-NRG6QX3L.js +1 -3
- package/dist/chunk-OCCGJ4S6.js +8 -0
- package/dist/chunk-ODY2NKQU.cjs +50 -0
- package/dist/chunk-OM5ZSXQW.cjs +91 -0
- package/dist/chunk-OOEORM7H.cjs +334 -0
- package/dist/chunk-OPDWMD4Q.js +1 -3
- package/dist/chunk-OSL4CNSO.js +7 -23
- package/dist/chunk-OXXMTDOY.cjs +86 -0
- package/dist/chunk-PA3UTI4A.js +1 -4
- package/dist/chunk-QEEAIXL5.cjs +74 -0
- package/dist/chunk-RYVW7RUM.js +2 -6
- package/dist/chunk-S6QBPXBI.cjs +107 -0
- package/dist/chunk-TL34BLQD.cjs +10 -0
- package/dist/chunk-TPZHMD7J.cjs +72 -0
- package/dist/chunk-UAPK3AIJ.js +1 -10
- package/dist/chunk-UF5IKELS.cjs +26 -0
- package/dist/chunk-UNX7V6P6.cjs +60 -0
- package/dist/chunk-UUCRWJJR.cjs +313 -0
- package/dist/chunk-VDFLPO7B.cjs +396 -0
- package/dist/chunk-VHD7CW5O.cjs +43 -0
- package/dist/chunk-VL4QNALG.cjs +50 -0
- package/dist/chunk-WR7LSUIR.cjs +213 -0
- package/dist/chunk-XE6D4J63.cjs +72 -0
- package/dist/chunk-ZLG2M2I4.cjs +21 -0
- package/dist/chunk-ZSHVXDA2.js +4 -10
- package/dist/client.cjs +40 -4360
- package/dist/client.js +32 -37
- package/dist/core/client.cjs +10 -476
- package/dist/core/client.js +6 -11
- package/dist/core/error.cjs +8 -251
- package/dist/core/error.js +4 -9
- package/dist/core/index.cjs +20 -488
- package/dist/core/index.js +8 -19
- package/dist/core/resource.cjs +9 -33
- package/dist/core/resource.js +2 -7
- package/dist/edge.cjs +62 -1111
- package/dist/edge.js +10 -42
- package/dist/index.cjs +115 -4431
- package/dist/index.js +39 -87
- package/dist/modelrouter/core.cjs +28 -648
- package/dist/modelrouter/core.js +8 -21
- package/dist/modelrouter/index.cjs +28 -648
- package/dist/modelrouter/index.js +8 -21
- package/dist/modelrouter/types.cjs +1 -17
- package/dist/modelrouter/types.js +1 -0
- package/dist/subagents/anthropic.cjs +27 -2784
- package/dist/subagents/anthropic.js +19 -24
- package/dist/subagents/index.cjs +14 -95
- package/dist/subagents/index.js +2 -11
- package/dist/subagents/prompts.cjs +14 -93
- package/dist/subagents/prompts.js +2 -11
- package/dist/subagents/types.cjs +1 -17
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/vercel.cjs +27 -2761
- package/dist/subagents/vercel.js +19 -24
- package/dist/tools/compact/core.cjs +12 -548
- package/dist/tools/compact/core.js +8 -13
- package/dist/tools/compact/index.cjs +17 -595
- package/dist/tools/compact/index.js +9 -17
- package/dist/tools/compact/types.cjs +1 -17
- package/dist/tools/compact/types.js +1 -0
- package/dist/tools/fastapply/anthropic.cjs +27 -891
- package/dist/tools/fastapply/anthropic.js +11 -24
- package/dist/tools/fastapply/apply.cjs +28 -672
- package/dist/tools/fastapply/apply.js +4 -19
- package/dist/tools/fastapply/core.cjs +37 -1061
- package/dist/tools/fastapply/core.js +9 -29
- package/dist/tools/fastapply/index.cjs +62 -1062
- package/dist/tools/fastapply/index.js +14 -44
- package/dist/tools/fastapply/openai.cjs +32 -901
- package/dist/tools/fastapply/openai.js +11 -26
- package/dist/tools/fastapply/prompts.cjs +10 -62
- package/dist/tools/fastapply/prompts.js +2 -9
- package/dist/tools/fastapply/types.cjs +1 -17
- package/dist/tools/fastapply/types.js +1 -0
- package/dist/tools/fastapply/vercel.cjs +25 -897
- package/dist/tools/fastapply/vercel.js +11 -22
- package/dist/tools/index.cjs +62 -1062
- package/dist/tools/index.js +14 -44
- package/dist/tools/utils/resilience.cjs +15 -312
- package/dist/tools/utils/resilience.js +3 -12
- package/dist/tools/warp_grep/agent/config.cjs +16 -127
- package/dist/tools/warp_grep/agent/config.js +2 -11
- package/dist/tools/warp_grep/agent/formatter.cjs +12 -48
- package/dist/tools/warp_grep/agent/formatter.js +2 -9
- package/dist/tools/warp_grep/agent/parser.cjs +16 -83
- package/dist/tools/warp_grep/agent/parser.js +2 -11
- package/dist/tools/warp_grep/agent/runner.cjs +15 -1081
- package/dist/tools/warp_grep/agent/runner.js +7 -14
- package/dist/tools/warp_grep/agent/types.cjs +1 -17
- package/dist/tools/warp_grep/agent/types.js +1 -0
- package/dist/tools/warp_grep/anthropic.cjs +47 -2561
- package/dist/tools/warp_grep/anthropic.js +19 -35
- package/dist/tools/warp_grep/client.cjs +49 -2471
- package/dist/tools/warp_grep/client.js +17 -34
- package/dist/tools/warp_grep/gemini.cjs +48 -2490
- package/dist/tools/warp_grep/gemini.js +21 -41
- package/dist/tools/warp_grep/harness.cjs +81 -936
- package/dist/tools/warp_grep/harness.js +12 -51
- package/dist/tools/warp_grep/index.cjs +124 -2575
- package/dist/tools/warp_grep/index.js +24 -87
- package/dist/tools/warp_grep/openai.cjs +53 -2575
- package/dist/tools/warp_grep/openai.js +19 -37
- package/dist/tools/warp_grep/providers/code_storage_http.cjs +12 -65
- package/dist/tools/warp_grep/providers/code_storage_http.js +2 -9
- package/dist/tools/warp_grep/providers/local.cjs +10 -589
- package/dist/tools/warp_grep/providers/local.js +6 -11
- package/dist/tools/warp_grep/providers/remote.cjs +8 -331
- package/dist/tools/warp_grep/providers/remote.js +3 -8
- package/dist/tools/warp_grep/providers/types.cjs +1 -17
- package/dist/tools/warp_grep/providers/types.js +1 -0
- package/dist/tools/warp_grep/utils/files.cjs +9 -42
- package/dist/tools/warp_grep/utils/files.js +2 -7
- package/dist/tools/warp_grep/utils/github.cjs +9 -43
- package/dist/tools/warp_grep/utils/github.js +2 -7
- package/dist/tools/warp_grep/utils/paths.cjs +28 -104
- package/dist/tools/warp_grep/utils/paths.js +2 -17
- package/dist/tools/warp_grep/utils/ripgrep.cjs +9 -103
- package/dist/tools/warp_grep/utils/ripgrep.js +2 -7
- package/dist/tools/warp_grep/vercel.cjs +53 -2557
- package/dist/tools/warp_grep/vercel.js +19 -37
- package/dist/version.cjs +7 -225
- package/dist/version.js +2 -7
- package/package.json +2 -2
- package/dist/chunk-E6TL6MIH.js +0 -203
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// subagents/prompts.ts
|
|
4
|
+
var THOROUGHNESS_INSTRUCTIONS = {
|
|
5
|
+
quick: `Do 1-2 targeted searches. Find the most relevant file/function quickly and summarize. Don't go deep.`,
|
|
6
|
+
medium: `Do 2-4 searches. Start broad, then follow up on the most promising leads. Cover the main aspects.`,
|
|
7
|
+
thorough: `Do 4-8 searches. Explore systematically: start broad, then drill into each relevant area. Cover edge cases, related files, and the full call chain. Leave no stone unturned.`
|
|
8
|
+
};
|
|
9
|
+
function getSystemPrompt(thoroughness = "medium") {
|
|
10
|
+
return `You are a codebase exploration specialist. Your job is to search a codebase and return a concise, accurate summary of what you find.
|
|
11
|
+
|
|
12
|
+
## Mode
|
|
13
|
+
READ-ONLY. You cannot modify files. You can only search and read code.
|
|
14
|
+
|
|
15
|
+
## Strategy
|
|
16
|
+
${THOROUGHNESS_INSTRUCTIONS[thoroughness]}
|
|
17
|
+
|
|
18
|
+
- Use multiple focused searches rather than one vague search
|
|
19
|
+
- Follow imports, function calls, and type references to build complete understanding
|
|
20
|
+
- If a search returns no results, try alternative terms (e.g., "auth" vs "authentication" vs "login")
|
|
21
|
+
- Look at both implementation and tests when relevant
|
|
22
|
+
|
|
23
|
+
## Communication
|
|
24
|
+
You have a \`send_message\` tool. Use it when:
|
|
25
|
+
- You hit a fork in the road and need guidance ("Found auth in both src/middleware/ and legacy/auth/. Which should I focus on?")
|
|
26
|
+
- You need clarification on ambiguous requests ("There are 3 auth strategies: JWT, session, OAuth. Which one?")
|
|
27
|
+
- You want to share a key finding before continuing ("The main auth handler is in src/auth/index.ts. It delegates to strategy-specific modules. Continuing to trace JWT flow.")
|
|
28
|
+
|
|
29
|
+
Do NOT use send_message for routine status updates. Only use it when you genuinely need input or have a significant finding worth sharing before you're done.
|
|
30
|
+
|
|
31
|
+
## Output
|
|
32
|
+
When you have enough information, output your final summary. Structure it as:
|
|
33
|
+
1. Direct answer to the question
|
|
34
|
+
2. Key files and their roles
|
|
35
|
+
3. How the pieces connect
|
|
36
|
+
|
|
37
|
+
Be concise. The summary should be useful to another AI model that will use your findings to complete a task.`;
|
|
38
|
+
}
|
|
39
|
+
var CODEBASE_SEARCH_TOOL = {
|
|
40
|
+
name: "codebase_search",
|
|
41
|
+
description: "Search the codebase for relevant code. Takes a natural language search request describing what you want to find. Returns matching file contents with line numbers.",
|
|
42
|
+
input_schema: {
|
|
43
|
+
type: "object",
|
|
44
|
+
properties: {
|
|
45
|
+
searchRequest: {
|
|
46
|
+
type: "string",
|
|
47
|
+
description: "Natural language description of what to search for in the codebase"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
required: ["searchRequest"],
|
|
51
|
+
additionalProperties: false
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var SEND_MESSAGE_TOOL = {
|
|
55
|
+
name: "send_message",
|
|
56
|
+
description: "Send a message to the orchestrating agent. Use this to ask questions, request clarification, or share important findings. The orchestrator may reply with additional context. Use sparingly \u2014 only when you genuinely need input or have a significant finding.",
|
|
57
|
+
input_schema: {
|
|
58
|
+
type: "object",
|
|
59
|
+
properties: {
|
|
60
|
+
message: {
|
|
61
|
+
type: "string",
|
|
62
|
+
description: "The message to send to the orchestrator"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
required: ["message"],
|
|
66
|
+
additionalProperties: false
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
exports.CODEBASE_SEARCH_TOOL = CODEBASE_SEARCH_TOOL;
|
|
71
|
+
exports.SEND_MESSAGE_TOOL = SEND_MESSAGE_TOOL;
|
|
72
|
+
exports.getSystemPrompt = getSystemPrompt;
|
package/dist/chunk-UAPK3AIJ.js
CHANGED
|
@@ -30,13 +30,4 @@ var GITHUB_READ_FILE_INPUT_SCHEMA = {
|
|
|
30
30
|
required: ["github", "path"]
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
export {
|
|
34
|
-
WARP_GREP_TOOL_NAME,
|
|
35
|
-
WARP_GREP_DESCRIPTION,
|
|
36
|
-
GITHUB_SEARCH_TOOL_NAME,
|
|
37
|
-
GITHUB_SEARCH_DESCRIPTION,
|
|
38
|
-
GITHUB_SEARCH_INPUT_SCHEMA,
|
|
39
|
-
GITHUB_READ_FILE_TOOL_NAME,
|
|
40
|
-
GITHUB_READ_FILE_DESCRIPTION,
|
|
41
|
-
GITHUB_READ_FILE_INPUT_SCHEMA
|
|
42
|
-
};
|
|
33
|
+
export { GITHUB_READ_FILE_DESCRIPTION, GITHUB_READ_FILE_INPUT_SCHEMA, GITHUB_READ_FILE_TOOL_NAME, GITHUB_SEARCH_DESCRIPTION, GITHUB_SEARCH_INPUT_SCHEMA, GITHUB_SEARCH_TOOL_NAME, WARP_GREP_DESCRIPTION, WARP_GREP_TOOL_NAME };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// tools/warp_grep/agent/formatter.ts
|
|
4
|
+
var ToolOutputFormatter = class {
|
|
5
|
+
format(toolName, _args, output, options = {}) {
|
|
6
|
+
const name = (toolName ?? "").trim();
|
|
7
|
+
if (!name) {
|
|
8
|
+
return "";
|
|
9
|
+
}
|
|
10
|
+
const payload = output?.toString?.()?.trim?.() ?? "";
|
|
11
|
+
const isError = Boolean(options.isError);
|
|
12
|
+
if (!payload && !isError) {
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
return `<tool_response>
|
|
16
|
+
${payload}
|
|
17
|
+
</tool_response>`;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var sharedFormatter = new ToolOutputFormatter();
|
|
21
|
+
function formatAgentToolOutput(toolName, args, output, options = {}) {
|
|
22
|
+
return sharedFormatter.format(toolName, args, output, options);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.ToolOutputFormatter = ToolOutputFormatter;
|
|
26
|
+
exports.formatAgentToolOutput = formatAgentToolOutput;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// tools/warp_grep/agent/parser.ts
|
|
4
|
+
function parseReadLines(linesStr) {
|
|
5
|
+
const ranges = [];
|
|
6
|
+
for (const rangeStr of linesStr.split(",")) {
|
|
7
|
+
const trimmed = rangeStr.trim();
|
|
8
|
+
if (!trimmed) continue;
|
|
9
|
+
const parts = trimmed.split("-").map((v) => parseInt(v.trim(), 10));
|
|
10
|
+
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
11
|
+
ranges.push([parts[0], parts[1]]);
|
|
12
|
+
} else if (Number.isFinite(parts[0])) {
|
|
13
|
+
ranges.push([parts[0], parts[0]]);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (ranges.length === 1) return { start: ranges[0][0], end: ranges[0][1] };
|
|
17
|
+
if (ranges.length > 1) return { lines: ranges };
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
function parseFinishFiles(filesStr) {
|
|
21
|
+
const files = [];
|
|
22
|
+
for (const line of filesStr.trim().split(/\s+/)) {
|
|
23
|
+
const trimmed = line.trim();
|
|
24
|
+
if (!trimmed) continue;
|
|
25
|
+
const searchFrom = /^[A-Za-z]:/.test(trimmed) ? 2 : 0;
|
|
26
|
+
const colonIdx = trimmed.indexOf(":", searchFrom);
|
|
27
|
+
if (colonIdx === -1) {
|
|
28
|
+
files.push({ path: trimmed, lines: "*" });
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const filePath = trimmed.slice(0, colonIdx);
|
|
32
|
+
const rangesPart = trimmed.slice(colonIdx + 1);
|
|
33
|
+
if (!rangesPart.trim() || rangesPart.trim() === "*") {
|
|
34
|
+
files.push({ path: filePath, lines: "*" });
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const ranges = [];
|
|
38
|
+
for (const rangeStr of rangesPart.split(",")) {
|
|
39
|
+
const rt = rangeStr.trim();
|
|
40
|
+
if (!rt) continue;
|
|
41
|
+
const parts = rt.split("-").map((v) => parseInt(v.trim(), 10));
|
|
42
|
+
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
43
|
+
ranges.push([parts[0], parts[1]]);
|
|
44
|
+
} else if (Number.isFinite(parts[0])) {
|
|
45
|
+
ranges.push([parts[0], parts[0]]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
files.push({ path: filePath, lines: ranges.length > 0 ? ranges : "*" });
|
|
49
|
+
}
|
|
50
|
+
return files;
|
|
51
|
+
}
|
|
52
|
+
function extractPathFromCommand(command) {
|
|
53
|
+
const tokens = command.trim().split(/\s+/);
|
|
54
|
+
const pathTokens = tokens.slice(1).filter((t) => !t.startsWith("-") && !t.startsWith("|") && !t.startsWith("\\("));
|
|
55
|
+
return pathTokens[0] || ".";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.extractPathFromCommand = extractPathFromCommand;
|
|
59
|
+
exports.parseFinishFiles = parseFinishFiles;
|
|
60
|
+
exports.parseReadLines = parseReadLines;
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVHD7CW5O_cjs = require('./chunk-VHD7CW5O.cjs');
|
|
4
|
+
var chunkWR7LSUIR_cjs = require('./chunk-WR7LSUIR.cjs');
|
|
5
|
+
var chunkMWXJ6DZ2_cjs = require('./chunk-MWXJ6DZ2.cjs');
|
|
6
|
+
var chunkHMLYJVZM_cjs = require('./chunk-HMLYJVZM.cjs');
|
|
7
|
+
var chunkODY2NKQU_cjs = require('./chunk-ODY2NKQU.cjs');
|
|
8
|
+
var chunk65W4I66Q_cjs = require('./chunk-65W4I66Q.cjs');
|
|
9
|
+
var chunkVL4QNALG_cjs = require('./chunk-VL4QNALG.cjs');
|
|
10
|
+
var chunkAWFZKS27_cjs = require('./chunk-AWFZKS27.cjs');
|
|
11
|
+
|
|
12
|
+
// tools/warp_grep/client.ts
|
|
13
|
+
var DEFAULT_CODE_SEARCH_URL = "https://api.morphllm.com";
|
|
14
|
+
async function getLocalProvider(repoRoot, excludes, allowNames) {
|
|
15
|
+
const { LocalRipgrepProvider } = await import('./tools/warp_grep/providers/local.cjs');
|
|
16
|
+
const opts = allowNames?.length ? { allowNames } : void 0;
|
|
17
|
+
return new LocalRipgrepProvider(repoRoot, excludes, opts);
|
|
18
|
+
}
|
|
19
|
+
var WarpGrepClient = class extends chunkAWFZKS27_cjs.APIResource {
|
|
20
|
+
config;
|
|
21
|
+
constructor(clientOrConfig = {}) {
|
|
22
|
+
const isClient = clientOrConfig instanceof chunk65W4I66Q_cjs.MorphAPIClient;
|
|
23
|
+
super(
|
|
24
|
+
isClient ? clientOrConfig : new chunk65W4I66Q_cjs.MorphAPIClient({
|
|
25
|
+
apiKey: clientOrConfig.morphApiKey,
|
|
26
|
+
baseURL: clientOrConfig.morphApiUrl,
|
|
27
|
+
timeout: clientOrConfig.timeout,
|
|
28
|
+
retryConfig: clientOrConfig.retryConfig,
|
|
29
|
+
debug: clientOrConfig.debug
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
const cfg = isClient ? {} : clientOrConfig;
|
|
33
|
+
this.config = {
|
|
34
|
+
...cfg,
|
|
35
|
+
morphApiKey: this._client.resolveApiKey(),
|
|
36
|
+
morphApiUrl: this._client.baseURL,
|
|
37
|
+
timeout: this._client.timeout,
|
|
38
|
+
retryConfig: this._client.retryConfig,
|
|
39
|
+
debug: this._client.debug
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
execute(input) {
|
|
43
|
+
const toolConfig = {
|
|
44
|
+
repoRoot: input.repoRoot,
|
|
45
|
+
remoteCommands: input.remoteCommands,
|
|
46
|
+
provider: input.provider,
|
|
47
|
+
excludes: input.excludes,
|
|
48
|
+
includes: input.includes,
|
|
49
|
+
debug: input.debug ?? this.config.debug,
|
|
50
|
+
morphApiKey: this.config.morphApiKey,
|
|
51
|
+
morphApiUrl: this.config.morphApiUrl,
|
|
52
|
+
retryConfig: this.config.retryConfig,
|
|
53
|
+
timeout: this.config.timeout,
|
|
54
|
+
search_type: input.search_type
|
|
55
|
+
};
|
|
56
|
+
if (input.streamSteps) {
|
|
57
|
+
return executeToolCallStreaming({ search_term: input.searchTerm }, toolConfig);
|
|
58
|
+
}
|
|
59
|
+
return executeToolCall({ search_term: input.searchTerm }, toolConfig);
|
|
60
|
+
}
|
|
61
|
+
searchGitHub(input) {
|
|
62
|
+
if (input.streamSteps) {
|
|
63
|
+
return this._searchGitHubStreaming(input);
|
|
64
|
+
}
|
|
65
|
+
return this._searchGitHubAsync(input);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Read a single file from a public GitHub repository
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const result = await client.readGitHubFile({
|
|
73
|
+
* github: 'vercel/next.js',
|
|
74
|
+
* path: 'src/server/app-render/index.tsx',
|
|
75
|
+
* startLine: 1,
|
|
76
|
+
* endLine: 50,
|
|
77
|
+
* });
|
|
78
|
+
* if (result.success) console.log(result.content);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
async readGitHubFile(input) {
|
|
82
|
+
return executeGitHubReadFile(input, { timeout: this.config.timeout });
|
|
83
|
+
}
|
|
84
|
+
async _resolveGitHubRepo(input) {
|
|
85
|
+
const { owner, repo } = chunkMWXJ6DZ2_cjs.parseGitHubUrl(input.github);
|
|
86
|
+
const baseUrl = this.config.codeSearchUrl || DEFAULT_CODE_SEARCH_URL;
|
|
87
|
+
chunkVL4QNALG_cjs.logger.debug("WarpGrep", "github_resolve", { owner_repo: `${owner}/${repo}`, branch: input.branch });
|
|
88
|
+
const resolveStart = Date.now();
|
|
89
|
+
const importRes = await fetch(`${baseUrl}/api/code-search/get-or-create?url=${encodeURIComponent(`${owner}/${repo}`)}`, {
|
|
90
|
+
headers: this.config.morphApiKey ? { Authorization: `Bearer ${this.config.morphApiKey}` } : void 0
|
|
91
|
+
});
|
|
92
|
+
if (!importRes.ok) {
|
|
93
|
+
const text = await importRes.text().catch(() => importRes.statusText);
|
|
94
|
+
chunkVL4QNALG_cjs.logger.error("WarpGrep", "github_resolve_failed", { owner_repo: `${owner}/${repo}`, status: importRes.status, error: text });
|
|
95
|
+
throw new Error(`Failed to import repo ${owner}/${repo}: ${text}`);
|
|
96
|
+
}
|
|
97
|
+
const { repoId, defaultBranch } = await importRes.json();
|
|
98
|
+
chunkVL4QNALG_cjs.logger.debug("WarpGrep", "github_repo_fetched", { repo_id: repoId, default_branch: defaultBranch, latency_ms: Date.now() - resolveStart });
|
|
99
|
+
return {
|
|
100
|
+
repo,
|
|
101
|
+
remoteCommands: chunkVHD7CW5O_cjs.createCodeStorageHttpCommands({
|
|
102
|
+
baseUrl,
|
|
103
|
+
repoId,
|
|
104
|
+
branch: input.branch || defaultBranch,
|
|
105
|
+
apiKey: this.config.morphApiKey
|
|
106
|
+
})
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async _searchGitHubAsync(input) {
|
|
110
|
+
try {
|
|
111
|
+
const { remoteCommands } = await this._resolveGitHubRepo(input);
|
|
112
|
+
return this.execute({
|
|
113
|
+
searchTerm: input.searchTerm,
|
|
114
|
+
repoRoot: ".",
|
|
115
|
+
remoteCommands
|
|
116
|
+
});
|
|
117
|
+
} catch (error) {
|
|
118
|
+
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async *_searchGitHubStreaming(input) {
|
|
122
|
+
let remoteCommands;
|
|
123
|
+
try {
|
|
124
|
+
({ remoteCommands } = await this._resolveGitHubRepo(input));
|
|
125
|
+
} catch (error) {
|
|
126
|
+
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
127
|
+
}
|
|
128
|
+
const generator = this.execute({
|
|
129
|
+
searchTerm: input.searchTerm,
|
|
130
|
+
repoRoot: ".",
|
|
131
|
+
remoteCommands,
|
|
132
|
+
streamSteps: true
|
|
133
|
+
});
|
|
134
|
+
let result;
|
|
135
|
+
for (; ; ) {
|
|
136
|
+
const { value, done } = await generator.next();
|
|
137
|
+
if (done) {
|
|
138
|
+
result = value;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
yield value;
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
function executeWarpGrep(input, config) {
|
|
147
|
+
const client = new WarpGrepClient(config);
|
|
148
|
+
if (input.streamSteps) {
|
|
149
|
+
return client.execute({ ...input, streamSteps: true });
|
|
150
|
+
}
|
|
151
|
+
return client.execute({ ...input, streamSteps: false });
|
|
152
|
+
}
|
|
153
|
+
async function executeToolCall(input, config) {
|
|
154
|
+
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
155
|
+
const allowNames = config.search_type === "node_modules" ? ["node_modules"] : void 0;
|
|
156
|
+
const provider = config.remoteCommands ? new chunkWR7LSUIR_cjs.RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ?? await getLocalProvider(config.repoRoot, config.excludes, allowNames);
|
|
157
|
+
const result = await chunkHMLYJVZM_cjs.runWarpGrep({
|
|
158
|
+
searchTerm: parsed.search_term,
|
|
159
|
+
repoRoot: config.repoRoot,
|
|
160
|
+
provider,
|
|
161
|
+
excludes: config.excludes,
|
|
162
|
+
includes: config.includes,
|
|
163
|
+
debug: config.debug ?? false,
|
|
164
|
+
morphApiKey: config.morphApiKey,
|
|
165
|
+
morphApiUrl: config.morphApiUrl,
|
|
166
|
+
retryConfig: config.retryConfig,
|
|
167
|
+
timeout: config.timeout,
|
|
168
|
+
search_type: config.search_type
|
|
169
|
+
});
|
|
170
|
+
return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
171
|
+
}
|
|
172
|
+
async function processAgentResult(result, searchTerm, apiKey, apiUrl) {
|
|
173
|
+
const finish = result.finish;
|
|
174
|
+
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
175
|
+
const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
|
|
176
|
+
console.error(`[warp_grep] processAgentResult failed. Reason: ${result.terminationReason}. Errors: ${errorDetails}. Turns: ${result.timings?.turns?.length ?? 0}`);
|
|
177
|
+
return { success: false, error: `Search did not complete: ${errorDetails}` };
|
|
178
|
+
}
|
|
179
|
+
const contexts = (finish.resolved ?? []).map((r) => ({
|
|
180
|
+
file: r.path,
|
|
181
|
+
content: r.content,
|
|
182
|
+
lines: r.ranges
|
|
183
|
+
}));
|
|
184
|
+
try {
|
|
185
|
+
const compactable = contexts.map((c) => ({ path: c.file, content: c.content }));
|
|
186
|
+
const compacted = await chunkODY2NKQU_cjs.compactFileContexts(compactable, searchTerm, apiKey, apiUrl);
|
|
187
|
+
for (let i = 0; i < contexts.length; i++) {
|
|
188
|
+
contexts[i].content = compacted[i].content;
|
|
189
|
+
}
|
|
190
|
+
} catch (error) {
|
|
191
|
+
console.error(`[warp_grep] Failed to compact result contexts:`, error);
|
|
192
|
+
}
|
|
193
|
+
return { success: true, contexts, summary: finish.payload };
|
|
194
|
+
}
|
|
195
|
+
async function* executeToolCallStreaming(input, config) {
|
|
196
|
+
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
197
|
+
const allowNames = config.search_type === "node_modules" ? ["node_modules"] : void 0;
|
|
198
|
+
const provider = config.remoteCommands ? new chunkWR7LSUIR_cjs.RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ?? await getLocalProvider(config.repoRoot, config.excludes, allowNames);
|
|
199
|
+
const generator = chunkHMLYJVZM_cjs.runWarpGrepStreaming({
|
|
200
|
+
searchTerm: parsed.search_term,
|
|
201
|
+
repoRoot: config.repoRoot,
|
|
202
|
+
provider,
|
|
203
|
+
excludes: config.excludes,
|
|
204
|
+
includes: config.includes,
|
|
205
|
+
debug: config.debug ?? false,
|
|
206
|
+
morphApiKey: config.morphApiKey,
|
|
207
|
+
morphApiUrl: config.morphApiUrl,
|
|
208
|
+
retryConfig: config.retryConfig,
|
|
209
|
+
timeout: config.timeout,
|
|
210
|
+
search_type: config.search_type
|
|
211
|
+
});
|
|
212
|
+
let agentResult;
|
|
213
|
+
for (; ; ) {
|
|
214
|
+
const { value, done } = await generator.next();
|
|
215
|
+
if (done) {
|
|
216
|
+
agentResult = value;
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
yield value;
|
|
220
|
+
}
|
|
221
|
+
return await processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
222
|
+
}
|
|
223
|
+
async function fetchRawGitHubFile(owner, repo, filePath, branch, timeout) {
|
|
224
|
+
const branches = branch ? [branch] : ["HEAD"];
|
|
225
|
+
const fallbacks = ["main", "master", "develop"];
|
|
226
|
+
const fetchWithTimeout = (url) => timeout ? fetch(url, { signal: AbortSignal.timeout(timeout) }) : fetch(url);
|
|
227
|
+
for (const b of branches) {
|
|
228
|
+
const url = `https://raw.githubusercontent.com/${owner}/${repo}/${b}/${filePath}`;
|
|
229
|
+
const res = await fetchWithTimeout(url);
|
|
230
|
+
if (res.ok) return { content: await res.text(), branch: b };
|
|
231
|
+
}
|
|
232
|
+
for (const fb of fallbacks) {
|
|
233
|
+
if (branch && fb === branch) continue;
|
|
234
|
+
const url = `https://raw.githubusercontent.com/${owner}/${repo}/${fb}/${filePath}`;
|
|
235
|
+
const res = await fetchWithTimeout(url);
|
|
236
|
+
if (res.ok) return { content: await res.text(), branch: fb };
|
|
237
|
+
}
|
|
238
|
+
throw new Error(`File not found: ${owner}/${repo}/${filePath}`);
|
|
239
|
+
}
|
|
240
|
+
async function executeGitHubReadFile(input, config) {
|
|
241
|
+
try {
|
|
242
|
+
const { owner, repo } = chunkMWXJ6DZ2_cjs.parseGitHubUrl(input.github);
|
|
243
|
+
const { content: raw, branch } = await fetchRawGitHubFile(
|
|
244
|
+
owner,
|
|
245
|
+
repo,
|
|
246
|
+
input.path,
|
|
247
|
+
input.branch,
|
|
248
|
+
config?.timeout
|
|
249
|
+
);
|
|
250
|
+
const allLines = raw.split("\n");
|
|
251
|
+
const totalLines = allLines.length;
|
|
252
|
+
const start = Math.max(1, input.startLine ?? 1);
|
|
253
|
+
const end = Math.min(totalLines, input.endLine ?? totalLines);
|
|
254
|
+
const selected = allLines.slice(start - 1, end);
|
|
255
|
+
const padWidth = String(end).length;
|
|
256
|
+
const numbered = selected.map((line, i) => `${String(start + i).padStart(padWidth)}|${line}`).join("\n");
|
|
257
|
+
return {
|
|
258
|
+
success: true,
|
|
259
|
+
content: numbered,
|
|
260
|
+
path: input.path,
|
|
261
|
+
github: `${owner}/${repo}`,
|
|
262
|
+
branch,
|
|
263
|
+
lineRange: [start, end],
|
|
264
|
+
totalLines
|
|
265
|
+
};
|
|
266
|
+
} catch (error) {
|
|
267
|
+
return {
|
|
268
|
+
success: false,
|
|
269
|
+
error: error instanceof Error ? error.message : String(error)
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function formatGitHubReadFileResult(result) {
|
|
274
|
+
if (!result.success) {
|
|
275
|
+
return `Failed to read file: ${result.error}`;
|
|
276
|
+
}
|
|
277
|
+
const rangeStr = result.lineRange ? ` (lines ${result.lineRange[0]}-${result.lineRange[1]} of ${result.totalLines})` : "";
|
|
278
|
+
return `File: ${result.github}/${result.path}${rangeStr}
|
|
279
|
+
|
|
280
|
+
${result.content}`;
|
|
281
|
+
}
|
|
282
|
+
function formatResult(result) {
|
|
283
|
+
if (!result.success) {
|
|
284
|
+
return `Search failed: ${result.error}`;
|
|
285
|
+
}
|
|
286
|
+
if (!result.contexts || result.contexts.length === 0) {
|
|
287
|
+
return "No relevant code found. Try rephrasing your search term.";
|
|
288
|
+
}
|
|
289
|
+
const parts = [];
|
|
290
|
+
parts.push(`Morph Fast Context subagent performed search on repository:
|
|
291
|
+
`);
|
|
292
|
+
parts.push("Relevant context found:");
|
|
293
|
+
for (const ctx of result.contexts) {
|
|
294
|
+
const rangeStr = !ctx.lines || ctx.lines === "*" ? "*" : ctx.lines.map(([s, e]) => `${s}-${e}`).join(",");
|
|
295
|
+
parts.push(`- ${ctx.file}:${rangeStr}`);
|
|
296
|
+
}
|
|
297
|
+
parts.push("\nHere is the content of files:\n");
|
|
298
|
+
for (const ctx of result.contexts) {
|
|
299
|
+
const rangeStr = !ctx.lines || ctx.lines === "*" ? "" : ` lines="${ctx.lines.map(([s, e]) => `${s}-${e}`).join(",")}"`;
|
|
300
|
+
parts.push(`<file path="${ctx.file}"${rangeStr}>`);
|
|
301
|
+
parts.push(ctx.content);
|
|
302
|
+
parts.push("</file>\n");
|
|
303
|
+
}
|
|
304
|
+
return parts.join("\n");
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
exports.WarpGrepClient = WarpGrepClient;
|
|
308
|
+
exports.executeGitHubReadFile = executeGitHubReadFile;
|
|
309
|
+
exports.executeToolCall = executeToolCall;
|
|
310
|
+
exports.executeToolCallStreaming = executeToolCallStreaming;
|
|
311
|
+
exports.executeWarpGrep = executeWarpGrep;
|
|
312
|
+
exports.formatGitHubReadFileResult = formatGitHubReadFileResult;
|
|
313
|
+
exports.formatResult = formatResult;
|