@morphllm/morphsdk 0.2.56 → 0.2.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/anthropic-CaFUHxBW.d.ts +89 -0
- package/dist/{chunk-SALJ2K6S.js → chunk-2CASO3ZO.js} +60 -98
- package/dist/chunk-2CASO3ZO.js.map +1 -0
- package/dist/chunk-374N3GIA.js +118 -0
- package/dist/chunk-374N3GIA.js.map +1 -0
- package/dist/chunk-3IQIT6MC.js +65 -0
- package/dist/chunk-3IQIT6MC.js.map +1 -0
- package/dist/chunk-4VGOBA2J.js +57 -0
- package/dist/chunk-4VGOBA2J.js.map +1 -0
- package/dist/chunk-527P5X2E.js +98 -0
- package/dist/chunk-527P5X2E.js.map +1 -0
- package/dist/chunk-6N6ZYZYD.js +74 -0
- package/dist/chunk-6N6ZYZYD.js.map +1 -0
- package/dist/chunk-6Y5JB4JC.js +195 -0
- package/dist/chunk-6Y5JB4JC.js.map +1 -0
- package/dist/{chunk-WSSSSBWU.js → chunk-7EIHYJSG.js} +18 -18
- package/dist/chunk-7EIHYJSG.js.map +1 -0
- package/dist/{chunk-TICMYDII.js → chunk-APP75CBN.js} +33 -16
- package/dist/chunk-APP75CBN.js.map +1 -0
- package/dist/chunk-ILJ3J5IA.js +72 -0
- package/dist/chunk-ILJ3J5IA.js.map +1 -0
- package/dist/chunk-ISWL67SF.js +1 -0
- package/dist/chunk-KW7OEGZK.js +9 -0
- package/dist/chunk-KW7OEGZK.js.map +1 -0
- package/dist/chunk-Q5AHGIQO.js +205 -0
- package/dist/chunk-Q5AHGIQO.js.map +1 -0
- package/dist/{chunk-TJIUA27P.js → chunk-XT5ZO6ES.js} +9 -5
- package/dist/chunk-XT5ZO6ES.js.map +1 -0
- package/dist/{chunk-LVPVVLTI.js → chunk-YV75OQTE.js} +105 -17
- package/dist/chunk-YV75OQTE.js.map +1 -0
- package/dist/{chunk-ZJIIICRA.js → chunk-ZO4PPFCZ.js} +60 -29
- package/dist/chunk-ZO4PPFCZ.js.map +1 -0
- package/dist/{client-CFoR--IU.d.ts → client-CextMMm9.d.ts} +10 -15
- package/dist/client.cjs +698 -466
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +3 -2
- package/dist/client.js +14 -15
- package/dist/finish-kXAcUJyB.d.ts +33 -0
- package/dist/gemini-CE80Pbdy.d.ts +117 -0
- package/dist/index.cjs +711 -466
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +16 -16
- package/dist/openai-Fvpqln7F.d.ts +89 -0
- package/dist/tools/warp_grep/agent/config.cjs +8 -4
- package/dist/tools/warp_grep/agent/config.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/config.d.ts +7 -2
- package/dist/tools/warp_grep/agent/config.js +1 -1
- package/dist/tools/warp_grep/agent/formatter.cjs +32 -15
- package/dist/tools/warp_grep/agent/formatter.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/formatter.d.ts +1 -1
- package/dist/tools/warp_grep/agent/formatter.js +1 -1
- package/dist/tools/warp_grep/agent/parser.cjs +104 -17
- package/dist/tools/warp_grep/agent/parser.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/parser.d.ts +3 -5
- package/dist/tools/warp_grep/agent/parser.js +1 -3
- package/dist/tools/warp_grep/agent/prompt.cjs +132 -56
- package/dist/tools/warp_grep/agent/prompt.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/prompt.d.ts +1 -1
- package/dist/tools/warp_grep/agent/prompt.js +1 -1
- package/dist/tools/warp_grep/agent/runner.cjs +466 -313
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.d.ts +1 -0
- package/dist/tools/warp_grep/agent/runner.js +6 -9
- package/dist/tools/warp_grep/agent/types.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/types.d.ts +9 -2
- package/dist/tools/warp_grep/anthropic.cjs +656 -380
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.d.ts +4 -74
- package/dist/tools/warp_grep/anthropic.js +13 -16
- package/dist/tools/warp_grep/client.cjs +1593 -0
- package/dist/tools/warp_grep/client.cjs.map +1 -0
- package/dist/tools/warp_grep/client.d.ts +87 -0
- package/dist/tools/warp_grep/client.js +26 -0
- package/dist/tools/warp_grep/gemini.cjs +1587 -0
- package/dist/tools/warp_grep/gemini.cjs.map +1 -0
- package/dist/tools/warp_grep/gemini.d.ts +7 -0
- package/dist/tools/warp_grep/gemini.js +34 -0
- package/dist/tools/warp_grep/harness.cjs +1195 -0
- package/dist/tools/warp_grep/harness.cjs.map +1 -0
- package/dist/tools/warp_grep/harness.d.ts +107 -0
- package/dist/tools/warp_grep/harness.js +68 -0
- package/dist/tools/warp_grep/harness.js.map +1 -0
- package/dist/tools/warp_grep/index.cjs +818 -466
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.d.ts +11 -6
- package/dist/tools/warp_grep/index.js +43 -23
- package/dist/tools/warp_grep/openai.cjs +656 -378
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.d.ts +4 -74
- package/dist/tools/warp_grep/openai.js +13 -14
- package/dist/tools/warp_grep/providers/local.cjs +66 -27
- package/dist/tools/warp_grep/providers/local.cjs.map +1 -1
- package/dist/tools/warp_grep/providers/local.d.ts +4 -9
- package/dist/tools/warp_grep/providers/local.js +2 -2
- package/dist/tools/warp_grep/providers/remote.cjs +211 -0
- package/dist/tools/warp_grep/providers/remote.cjs.map +1 -0
- package/dist/tools/warp_grep/providers/remote.d.ts +67 -0
- package/dist/tools/warp_grep/providers/remote.js +9 -0
- package/dist/tools/warp_grep/providers/types.cjs.map +1 -1
- package/dist/tools/warp_grep/providers/types.d.ts +7 -15
- package/dist/tools/warp_grep/vercel.cjs +668 -397
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.d.ts +4 -51
- package/dist/tools/warp_grep/vercel.js +16 -15
- package/dist/types-a_hxdPI6.d.ts +144 -0
- package/dist/vercel-3yjvfmVB.d.ts +66 -0
- package/package.json +17 -2
- package/dist/chunk-4ZHDBKBY.js +0 -83
- package/dist/chunk-4ZHDBKBY.js.map +0 -1
- package/dist/chunk-73RQWOQC.js +0 -16
- package/dist/chunk-73RQWOQC.js.map +0 -1
- package/dist/chunk-7OQOOB3R.js +0 -1
- package/dist/chunk-EK7OQPWD.js +0 -44
- package/dist/chunk-EK7OQPWD.js.map +0 -1
- package/dist/chunk-GJURLQ3L.js +0 -77
- package/dist/chunk-GJURLQ3L.js.map +0 -1
- package/dist/chunk-HQO45BAJ.js +0 -14
- package/dist/chunk-HQO45BAJ.js.map +0 -1
- package/dist/chunk-LVPVVLTI.js.map +0 -1
- package/dist/chunk-NDZO5IPV.js +0 -121
- package/dist/chunk-NDZO5IPV.js.map +0 -1
- package/dist/chunk-QVRXBAMM.js +0 -107
- package/dist/chunk-QVRXBAMM.js.map +0 -1
- package/dist/chunk-SALJ2K6S.js.map +0 -1
- package/dist/chunk-TICMYDII.js.map +0 -1
- package/dist/chunk-TJIUA27P.js.map +0 -1
- package/dist/chunk-UIRJE422.js +0 -70
- package/dist/chunk-UIRJE422.js.map +0 -1
- package/dist/chunk-WETRQJGU.js +0 -129
- package/dist/chunk-WETRQJGU.js.map +0 -1
- package/dist/chunk-WSSSSBWU.js.map +0 -1
- package/dist/chunk-ZJIIICRA.js.map +0 -1
- package/dist/core-CpkYEi_T.d.ts +0 -158
- package/dist/tools/warp_grep/agent/grep_helpers.cjs +0 -148
- package/dist/tools/warp_grep/agent/grep_helpers.cjs.map +0 -1
- package/dist/tools/warp_grep/agent/grep_helpers.d.ts +0 -16
- package/dist/tools/warp_grep/agent/grep_helpers.js +0 -14
- package/dist/tools/warp_grep/tools/analyse.cjs +0 -40
- package/dist/tools/warp_grep/tools/analyse.cjs.map +0 -1
- package/dist/tools/warp_grep/tools/analyse.d.ts +0 -10
- package/dist/tools/warp_grep/tools/analyse.js +0 -8
- package/dist/tools/warp_grep/tools/finish.cjs +0 -69
- package/dist/tools/warp_grep/tools/finish.cjs.map +0 -1
- package/dist/tools/warp_grep/tools/finish.d.ts +0 -10
- package/dist/tools/warp_grep/tools/finish.js +0 -10
- package/dist/tools/warp_grep/tools/grep.cjs +0 -38
- package/dist/tools/warp_grep/tools/grep.cjs.map +0 -1
- package/dist/tools/warp_grep/tools/grep.d.ts +0 -8
- package/dist/tools/warp_grep/tools/grep.js +0 -15
- package/dist/tools/warp_grep/tools/grep.js.map +0 -1
- package/dist/tools/warp_grep/tools/read.cjs +0 -38
- package/dist/tools/warp_grep/tools/read.cjs.map +0 -1
- package/dist/tools/warp_grep/tools/read.d.ts +0 -9
- package/dist/tools/warp_grep/tools/read.js +0 -8
- package/dist/tools/warp_grep/tools/read.js.map +0 -1
- package/dist/tools/warp_grep/utils/format.cjs +0 -42
- package/dist/tools/warp_grep/utils/format.cjs.map +0 -1
- package/dist/tools/warp_grep/utils/format.d.ts +0 -4
- package/dist/tools/warp_grep/utils/format.js +0 -18
- package/dist/tools/warp_grep/utils/format.js.map +0 -1
- /package/dist/{chunk-7OQOOB3R.js.map → chunk-ISWL67SF.js.map} +0 -0
- /package/dist/tools/warp_grep/{agent/grep_helpers.js.map → client.js.map} +0 -0
- /package/dist/tools/warp_grep/{tools/analyse.js.map → gemini.js.map} +0 -0
- /package/dist/tools/warp_grep/{tools/finish.js.map → providers/remote.js.map} +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AGENT_CONFIG
|
|
3
|
+
} from "./chunk-XT5ZO6ES.js";
|
|
4
|
+
|
|
5
|
+
// tools/warp_grep/providers/remote.ts
|
|
6
|
+
var RemoteCommandsProvider = class {
|
|
7
|
+
constructor(repoRoot, commands) {
|
|
8
|
+
this.repoRoot = repoRoot;
|
|
9
|
+
this.commands = commands;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Run grep command and parse ripgrep output
|
|
13
|
+
*/
|
|
14
|
+
async grep(params) {
|
|
15
|
+
try {
|
|
16
|
+
const stdout = await this.commands.grep(params.pattern, params.path, params.glob);
|
|
17
|
+
const lines = (stdout || "").trim().split(/\r?\n/).filter((l) => l.length > 0);
|
|
18
|
+
if (lines.length > AGENT_CONFIG.MAX_OUTPUT_LINES) {
|
|
19
|
+
return {
|
|
20
|
+
lines: [],
|
|
21
|
+
error: "Query not specific enough - too many results returned. Try a more specific pattern."
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return { lines };
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return {
|
|
27
|
+
lines: [],
|
|
28
|
+
error: `[GREP ERROR] ${error instanceof Error ? error.message : String(error)}`
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Read file and add line numbers
|
|
34
|
+
*/
|
|
35
|
+
async read(params) {
|
|
36
|
+
const start = params.start ?? 1;
|
|
37
|
+
const end = params.end ?? 1e6;
|
|
38
|
+
try {
|
|
39
|
+
const stdout = await this.commands.read(params.path, start, end);
|
|
40
|
+
const contentLines = (stdout || "").split("\n");
|
|
41
|
+
if (contentLines.length > 0 && contentLines[contentLines.length - 1] === "") {
|
|
42
|
+
contentLines.pop();
|
|
43
|
+
}
|
|
44
|
+
const lines = contentLines.map((content, idx) => `${start + idx}|${content}`);
|
|
45
|
+
if (lines.length > AGENT_CONFIG.MAX_READ_LINES) {
|
|
46
|
+
const truncated = lines.slice(0, AGENT_CONFIG.MAX_READ_LINES);
|
|
47
|
+
truncated.push(`... [truncated: showing ${AGENT_CONFIG.MAX_READ_LINES} of ${lines.length} lines]`);
|
|
48
|
+
return { lines: truncated };
|
|
49
|
+
}
|
|
50
|
+
return { lines };
|
|
51
|
+
} catch (error) {
|
|
52
|
+
return {
|
|
53
|
+
lines: [],
|
|
54
|
+
error: `[READ ERROR] ${error instanceof Error ? error.message : String(error)}`
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* List directory and parse find output
|
|
60
|
+
*/
|
|
61
|
+
async listDirectory(params) {
|
|
62
|
+
const maxDepth = params.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
63
|
+
const maxResults = params.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES;
|
|
64
|
+
try {
|
|
65
|
+
const stdout = await this.commands.listDir(params.path, maxDepth);
|
|
66
|
+
const paths = (stdout || "").trim().split(/\r?\n/).filter((p) => p.length > 0);
|
|
67
|
+
const regex = params.pattern ? new RegExp(params.pattern) : null;
|
|
68
|
+
const entries = [];
|
|
69
|
+
for (const fullPath of paths) {
|
|
70
|
+
if (fullPath === params.path || fullPath === this.repoRoot) continue;
|
|
71
|
+
const name = fullPath.split("/").pop() || "";
|
|
72
|
+
if (regex && !regex.test(name)) continue;
|
|
73
|
+
let relativePath = fullPath;
|
|
74
|
+
if (fullPath.startsWith(this.repoRoot)) {
|
|
75
|
+
relativePath = fullPath.slice(this.repoRoot.length).replace(/^\//, "");
|
|
76
|
+
}
|
|
77
|
+
const depth = relativePath.split("/").filter(Boolean).length - 1;
|
|
78
|
+
const hasExtension = name.includes(".") && !name.startsWith(".");
|
|
79
|
+
const type = hasExtension ? "file" : "dir";
|
|
80
|
+
entries.push({
|
|
81
|
+
name,
|
|
82
|
+
path: relativePath,
|
|
83
|
+
type,
|
|
84
|
+
depth: Math.max(0, depth)
|
|
85
|
+
});
|
|
86
|
+
if (entries.length >= maxResults) break;
|
|
87
|
+
}
|
|
88
|
+
return entries;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export {
|
|
96
|
+
RemoteCommandsProvider
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=chunk-527P5X2E.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../tools/warp_grep/providers/remote.ts"],"sourcesContent":["/**\n * RemoteCommandsProvider - wraps simple RemoteCommands into WarpGrepProvider\n * \n * Handles parsing of raw stdout from grep/read/listDir commands.\n * Users just return stdout, SDK handles all format conversion.\n */\n\nimport type { WarpGrepProvider, GrepResult, ReadResult, ListDirectoryEntry } from './types.js';\nimport type { RemoteCommands } from '../types.js';\nimport { AGENT_CONFIG } from '../agent/config.js';\n\n/**\n * Wraps simple RemoteCommands functions into a full WarpGrepProvider.\n * \n * This allows users to provide three simple functions that return raw stdout,\n * and the SDK handles all parsing internally.\n * \n * @example\n * ```typescript\n * const provider = new RemoteCommandsProvider('/home/repo', {\n * grep: async (pattern, path) => {\n * const r = await sandbox.run(`rg '${pattern}' '${path}'`);\n * return r.stdout;\n * },\n * read: async (path, start, end) => {\n * const r = await sandbox.run(`sed -n '${start},${end}p' '${path}'`);\n * return r.stdout;\n * },\n * listDir: async (path, maxDepth) => {\n * const r = await sandbox.run(`find '${path}' -maxdepth ${maxDepth}`);\n * return r.stdout;\n * },\n * });\n * ```\n */\nexport class RemoteCommandsProvider implements WarpGrepProvider {\n constructor(\n private readonly repoRoot: string,\n private readonly commands: RemoteCommands\n ) {}\n\n /**\n * Run grep command and parse ripgrep output\n */\n async grep(params: { pattern: string; path: string; glob?: string }): Promise<GrepResult> {\n try {\n const stdout = await this.commands.grep(params.pattern, params.path, params.glob);\n \n // Parse ripgrep output: each line is \"path:line:content\" or \"path-line-content\" for context\n const lines = (stdout || '')\n .trim()\n .split(/\\r?\\n/)\n .filter((l) => l.length > 0);\n \n // Check if output is too large\n if (lines.length > AGENT_CONFIG.MAX_OUTPUT_LINES) {\n return {\n lines: [],\n error: 'Query not specific enough - too many results returned. Try a more specific pattern.',\n };\n }\n \n return { lines };\n } catch (error) {\n return {\n lines: [],\n error: `[GREP ERROR] ${error instanceof Error ? error.message : String(error)}`,\n };\n }\n }\n\n /**\n * Read file and add line numbers\n */\n async read(params: { path: string; start?: number; end?: number }): Promise<ReadResult> {\n const start = params.start ?? 1;\n const end = params.end ?? 1_000_000;\n \n try {\n const stdout = await this.commands.read(params.path, start, end);\n \n // Split content into lines and add line numbers\n const contentLines = (stdout || '').split('\\n');\n \n // Remove trailing empty line if present (common with sed output)\n if (contentLines.length > 0 && contentLines[contentLines.length - 1] === '') {\n contentLines.pop();\n }\n \n // Format as \"lineNumber|content\"\n const lines = contentLines.map((content, idx) => `${start + idx}|${content}`);\n \n // Check if output is too large\n if (lines.length > AGENT_CONFIG.MAX_READ_LINES) {\n const truncated = lines.slice(0, AGENT_CONFIG.MAX_READ_LINES);\n truncated.push(`... [truncated: showing ${AGENT_CONFIG.MAX_READ_LINES} of ${lines.length} lines]`);\n return { lines: truncated };\n }\n \n return { lines };\n } catch (error) {\n return {\n lines: [],\n error: `[READ ERROR] ${error instanceof Error ? error.message : String(error)}`,\n };\n }\n }\n\n /**\n * List directory and parse find output\n */\n async listDirectory(params: { \n path: string; \n pattern?: string | null; \n maxResults?: number; \n maxDepth?: number;\n }): Promise<ListDirectoryEntry[]> {\n const maxDepth = params.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;\n const maxResults = params.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES;\n \n try {\n const stdout = await this.commands.listDir(params.path, maxDepth);\n \n // Parse find output: one path per line\n const paths = (stdout || '')\n .trim()\n .split(/\\r?\\n/)\n .filter((p) => p.length > 0);\n \n const regex = params.pattern ? new RegExp(params.pattern) : null;\n const entries: ListDirectoryEntry[] = [];\n \n for (const fullPath of paths) {\n // Skip the root path itself\n if (fullPath === params.path || fullPath === this.repoRoot) continue;\n \n const name = fullPath.split('/').pop() || '';\n \n // Apply pattern filter if provided\n if (regex && !regex.test(name)) continue;\n \n // Determine relative path\n let relativePath = fullPath;\n if (fullPath.startsWith(this.repoRoot)) {\n relativePath = fullPath.slice(this.repoRoot.length).replace(/^\\//, '');\n }\n \n // Calculate depth based on path separators\n const depth = relativePath.split('/').filter(Boolean).length - 1;\n \n // Determine if it's a directory (ends with / or infer from path structure)\n // Note: Most sandbox find commands don't indicate type, so we guess based on extension\n const hasExtension = name.includes('.') && !name.startsWith('.');\n const type: 'file' | 'dir' = hasExtension ? 'file' : 'dir';\n \n entries.push({\n name,\n path: relativePath,\n type,\n depth: Math.max(0, depth),\n });\n \n if (entries.length >= maxResults) break;\n }\n \n return entries;\n } catch (error) {\n // Return empty array on error (consistent with LocalRipgrepProvider)\n return [];\n }\n }\n}\n\n"],"mappings":";;;;;AAmCO,IAAM,yBAAN,MAAyD;AAAA,EAC9D,YACmB,UACA,UACjB;AAFiB;AACA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAKH,MAAM,KAAK,QAA+E;AACxF,QAAI;AACF,YAAM,SAAS,MAAM,KAAK,SAAS,KAAK,OAAO,SAAS,OAAO,MAAM,OAAO,IAAI;AAGhF,YAAM,SAAS,UAAU,IACtB,KAAK,EACL,MAAM,OAAO,EACb,OAAO,CAAC,MAAM,EAAE,SAAS,CAAC;AAG7B,UAAI,MAAM,SAAS,aAAa,kBAAkB;AAChD,eAAO;AAAA,UACL,OAAO,CAAC;AAAA,UACR,OAAO;AAAA,QACT;AAAA,MACF;AAEA,aAAO,EAAE,MAAM;AAAA,IACjB,SAAS,OAAO;AACd,aAAO;AAAA,QACL,OAAO,CAAC;AAAA,QACR,OAAO,gBAAgB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,MAC/E;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,QAA6E;AACtF,UAAM,QAAQ,OAAO,SAAS;AAC9B,UAAM,MAAM,OAAO,OAAO;AAE1B,QAAI;AACF,YAAM,SAAS,MAAM,KAAK,SAAS,KAAK,OAAO,MAAM,OAAO,GAAG;AAG/D,YAAM,gBAAgB,UAAU,IAAI,MAAM,IAAI;AAG9C,UAAI,aAAa,SAAS,KAAK,aAAa,aAAa,SAAS,CAAC,MAAM,IAAI;AAC3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M,GAAG,EAAE,OAAO,OAAO,EAAE,SAAS;AAI/D,cAAM,eAAe,KAAK,SAAS,GAAG,KAAK,CAAC,KAAK,WAAW,GAAG;AAC/D,cAAM,OAAuB,eAAe,SAAS;AAErD,gBAAQ,KAAK;AAAA,UACX;AAAA,UACA,MAAM;AAAA,UACN;AAAA,UACA,OAAO,KAAK,IAAI,GAAG,KAAK;AAAA,QAC1B,CAAC;AAED,YAAI,QAAQ,UAAU,WAAY;AAAA,MACpC;AAEA,aAAO;AAAA,IACT,SAAS,OAAO;AAEd,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WARP_GREP_DESCRIPTION,
|
|
3
|
+
WARP_GREP_TOOL_NAME
|
|
4
|
+
} from "./chunk-KW7OEGZK.js";
|
|
5
|
+
import {
|
|
6
|
+
executeToolCall,
|
|
7
|
+
formatResult
|
|
8
|
+
} from "./chunk-374N3GIA.js";
|
|
9
|
+
import {
|
|
10
|
+
getSystemPrompt
|
|
11
|
+
} from "./chunk-Q5AHGIQO.js";
|
|
12
|
+
import {
|
|
13
|
+
__export
|
|
14
|
+
} from "./chunk-PZ5AY32C.js";
|
|
15
|
+
|
|
16
|
+
// tools/warp_grep/openai.ts
|
|
17
|
+
var openai_exports = {};
|
|
18
|
+
__export(openai_exports, {
|
|
19
|
+
createWarpGrepTool: () => createWarpGrepTool,
|
|
20
|
+
default: () => openai_default,
|
|
21
|
+
execute: () => execute,
|
|
22
|
+
formatResult: () => formatResult,
|
|
23
|
+
getSystemPrompt: () => getSystemPrompt,
|
|
24
|
+
warpGrepTool: () => warpGrepTool
|
|
25
|
+
});
|
|
26
|
+
var TOOL_PARAMETERS = {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
query: { type: "string", description: "Free-form repository question" }
|
|
30
|
+
},
|
|
31
|
+
required: ["query"]
|
|
32
|
+
};
|
|
33
|
+
var warpGrepTool = {
|
|
34
|
+
type: "function",
|
|
35
|
+
function: {
|
|
36
|
+
name: WARP_GREP_TOOL_NAME,
|
|
37
|
+
description: WARP_GREP_DESCRIPTION,
|
|
38
|
+
parameters: TOOL_PARAMETERS
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
async function execute(input, config) {
|
|
42
|
+
return executeToolCall(input, config);
|
|
43
|
+
}
|
|
44
|
+
function createWarpGrepTool(config) {
|
|
45
|
+
const tool = {
|
|
46
|
+
type: "function",
|
|
47
|
+
function: {
|
|
48
|
+
name: config.name ?? WARP_GREP_TOOL_NAME,
|
|
49
|
+
description: config.description ?? WARP_GREP_DESCRIPTION,
|
|
50
|
+
parameters: TOOL_PARAMETERS
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
return Object.assign(tool, {
|
|
54
|
+
execute: async (input) => {
|
|
55
|
+
return executeToolCall(input, config);
|
|
56
|
+
},
|
|
57
|
+
formatResult: (result) => {
|
|
58
|
+
return formatResult(result);
|
|
59
|
+
},
|
|
60
|
+
getSystemPrompt: () => {
|
|
61
|
+
return getSystemPrompt();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
var openai_default = warpGrepTool;
|
|
66
|
+
|
|
67
|
+
export {
|
|
68
|
+
warpGrepTool,
|
|
69
|
+
execute,
|
|
70
|
+
createWarpGrepTool,
|
|
71
|
+
openai_default,
|
|
72
|
+
openai_exports
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=chunk-6N6ZYZYD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../tools/warp_grep/openai.ts"],"sourcesContent":["/**\n * OpenAI SDK adapter for morph-warp-grep tool\n */\n\nimport type { ChatCompletionTool } from 'openai/resources/chat/completions';\nimport { executeToolCall, formatResult } from './client.js';\nimport { WARP_GREP_DESCRIPTION, WARP_GREP_TOOL_NAME, getSystemPrompt } from './prompts.js';\nimport type { WarpGrepToolConfig, WarpGrepResult } from './types.js';\n\n/**\n * Input schema for the warp grep tool\n */\nconst TOOL_PARAMETERS = {\n type: 'object',\n properties: {\n query: { type: 'string', description: 'Free-form repository question' },\n },\n required: ['query'],\n} as const;\n\n/**\n * OpenAI-native warp grep tool definition\n * \n * @example\n * ```typescript\n * import OpenAI from 'openai';\n * import { warpGrepTool, execute } from '@morphllm/morphsdk/tools/warp-grep/openai';\n * \n * const client = new OpenAI();\n * const response = await client.chat.completions.create({\n * model: 'gpt-4o',\n * tools: [warpGrepTool],\n * messages: [{ role: 'user', content: 'Find authentication middleware' }]\n * });\n * \n * // Execute the tool call\n * const result = await execute({ query: '...' }, { repoRoot: '.' });\n * ```\n */\nexport const warpGrepTool: ChatCompletionTool = {\n type: 'function',\n function: {\n name: WARP_GREP_TOOL_NAME,\n description: WARP_GREP_DESCRIPTION,\n parameters: TOOL_PARAMETERS,\n },\n};\n\n/**\n * Execute warp grep search\n * \n * @param input - Tool input with query\n * @param config - Configuration with repoRoot and optional provider\n * @returns Search results\n */\nexport async function execute(\n input: { query: string } | string,\n config: WarpGrepToolConfig\n): Promise<WarpGrepResult> {\n return executeToolCall(input, config);\n}\n\n// Re-export formatResult and getSystemPrompt for convenience\nexport { formatResult, getSystemPrompt };\n\n/**\n * Create a custom warp grep tool with configuration and methods\n * \n * @param config - Configuration options\n * @returns Tool definition with execute and formatResult methods\n * \n * @example Local usage\n * ```typescript\n * import OpenAI from 'openai';\n * import { createWarpGrepTool } from '@morphllm/morphsdk/tools/warp-grep/openai';\n * \n * const tool = createWarpGrepTool({ repoRoot: '.' });\n * \n * const client = new OpenAI();\n * const response = await client.chat.completions.create({\n * model: 'gpt-4o',\n * tools: [tool],\n * messages: [{ role: 'user', content: 'Find authentication middleware' }]\n * });\n * ```\n * \n * @example Remote sandbox (E2B, Modal, etc.)\n * ```typescript\n * const tool = createMorphWarpGrepTool({\n * repoRoot: '/home/repo',\n * remoteCommands: {\n * grep: async (pattern, path) => (await sandbox.run(`rg '${pattern}' '${path}'`)).stdout,\n * read: async (path, start, end) => (await sandbox.run(`sed -n '${start},${end}p' '${path}'`)).stdout,\n * listDir: async (path, maxDepth) => (await sandbox.run(`find '${path}' -maxdepth ${maxDepth}`)).stdout,\n * },\n * });\n * ```\n */\nexport function createWarpGrepTool(config: WarpGrepToolConfig) {\n const tool: ChatCompletionTool = {\n type: 'function',\n function: {\n name: config.name ?? WARP_GREP_TOOL_NAME,\n description: config.description ?? WARP_GREP_DESCRIPTION,\n parameters: TOOL_PARAMETERS,\n },\n };\n\n return Object.assign(tool, {\n execute: async (input: unknown): Promise<WarpGrepResult> => {\n return executeToolCall(input as { query: string } | string, config);\n },\n formatResult: (result: WarpGrepResult): string => {\n return formatResult(result);\n },\n getSystemPrompt: (): string => {\n return getSystemPrompt();\n },\n });\n}\n\nexport default warpGrepTool;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,IAAM,kBAAkB;AAAA,EACtB,MAAM;AAAA,EACN,YAAY;AAAA,IACV,OAAO,EAAE,MAAM,UAAU,aAAa,gCAAgC;AAAA,EACxE;AAAA,EACA,UAAU,CAAC,OAAO;AACpB;AAqBO,IAAM,eAAmC;AAAA,EAC9C,MAAM;AAAA,EACN,UAAU;AAAA,IACR,MAAM;AAAA,IACN,aAAa;AAAA,IACb,YAAY;AAAA,EACd;AACF;AASA,eAAsB,QACpB,OACA,QACyB;AACzB,SAAO,gBAAgB,OAAO,MAAM;AACtC;AAsCO,SAAS,mBAAmB,QAA4B;AAC7D,QAAM,OAA2B;AAAA,IAC/B,MAAM;AAAA,IACN,UAAU;AAAA,MACR,MAAM,OAAO,QAAQ;AAAA,MACrB,aAAa,OAAO,eAAe;AAAA,MACnC,YAAY;AAAA,IACd;AAAA,EACF;AAEA,SAAO,OAAO,OAAO,MAAM;AAAA,IACzB,SAAS,OAAO,UAA4C;AAC1D,aAAO,gBAAgB,OAAqC,MAAM;AAAA,IACpE;AAAA,IACA,cAAc,CAAC,WAAmC;AAChD,aAAO,aAAa,MAAM;AAAA,IAC5B;AAAA,IACA,iBAAiB,MAAc;AAC7B,aAAO,gBAAgB;AAAA,IACzB;AAAA,EACF,CAAC;AACH;AAEA,IAAO,iBAAQ;","names":[]}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AGENT_CONFIG
|
|
3
|
+
} from "./chunk-XT5ZO6ES.js";
|
|
4
|
+
|
|
5
|
+
// tools/warp_grep/agent/tools/grep.ts
|
|
6
|
+
async function toolGrep(provider, args) {
|
|
7
|
+
const res = await provider.grep(args);
|
|
8
|
+
if (res.error) {
|
|
9
|
+
return { output: res.error };
|
|
10
|
+
}
|
|
11
|
+
if (!res.lines.length) {
|
|
12
|
+
return { output: "no matches" };
|
|
13
|
+
}
|
|
14
|
+
return { output: res.lines.join("\n") };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// tools/warp_grep/agent/tools/read.ts
|
|
18
|
+
async function toolRead(provider, args) {
|
|
19
|
+
if (args.lines && args.lines.length > 0) {
|
|
20
|
+
const chunks = [];
|
|
21
|
+
for (const [start, end] of args.lines) {
|
|
22
|
+
const res2 = await provider.read({ path: args.path, start, end });
|
|
23
|
+
if (res2.error) return res2.error;
|
|
24
|
+
chunks.push(res2.lines.join("\n"));
|
|
25
|
+
}
|
|
26
|
+
if (chunks.every((c) => c === "")) return "(empty file)";
|
|
27
|
+
return chunks.join("\n...\n");
|
|
28
|
+
}
|
|
29
|
+
const res = await provider.read({ path: args.path, start: args.start, end: args.end });
|
|
30
|
+
if (res.error) {
|
|
31
|
+
return res.error;
|
|
32
|
+
}
|
|
33
|
+
if (!res.lines.length) return "(empty file)";
|
|
34
|
+
return res.lines.join("\n");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// tools/warp_grep/agent/tools/list_directory.ts
|
|
38
|
+
async function toolListDirectory(provider, args) {
|
|
39
|
+
const list = await provider.listDirectory({
|
|
40
|
+
path: args.path,
|
|
41
|
+
pattern: args.pattern ?? null,
|
|
42
|
+
maxResults: args.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES,
|
|
43
|
+
maxDepth: args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH
|
|
44
|
+
});
|
|
45
|
+
if (!list.length) return "empty";
|
|
46
|
+
if (list.length >= AGENT_CONFIG.MAX_OUTPUT_LINES) {
|
|
47
|
+
return "query not specific enough, tool called tried to return too much context and failed";
|
|
48
|
+
}
|
|
49
|
+
return list.map((e) => {
|
|
50
|
+
const indent = " ".repeat(e.depth);
|
|
51
|
+
const name = e.type === "dir" ? `${e.name}/` : e.name;
|
|
52
|
+
return `${indent}${name}`;
|
|
53
|
+
}).join("\n");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// tools/warp_grep/agent/tools/finish.ts
|
|
57
|
+
function normalizeFinishFiles(files) {
|
|
58
|
+
return files.map((f) => {
|
|
59
|
+
const merged = mergeRanges(f.lines);
|
|
60
|
+
return { path: f.path, lines: merged };
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async function readFinishFiles(repoRoot, files, reader) {
|
|
64
|
+
const out = [];
|
|
65
|
+
for (const f of files) {
|
|
66
|
+
const ranges = mergeRanges(f.lines);
|
|
67
|
+
const chunks = [];
|
|
68
|
+
for (const [s, e] of ranges) {
|
|
69
|
+
const lines = await reader(f.path, s, e);
|
|
70
|
+
chunks.push(lines.join("\n"));
|
|
71
|
+
}
|
|
72
|
+
out.push({ path: f.path, ranges, content: chunks.join("\n") });
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
function mergeRanges(ranges) {
|
|
77
|
+
if (!ranges.length) return [];
|
|
78
|
+
const sorted = [...ranges].sort((a, b) => a[0] - b[0]);
|
|
79
|
+
const merged = [];
|
|
80
|
+
let [cs, ce] = sorted[0];
|
|
81
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
82
|
+
const [s, e] = sorted[i];
|
|
83
|
+
if (s <= ce + 1) {
|
|
84
|
+
ce = Math.max(ce, e);
|
|
85
|
+
} else {
|
|
86
|
+
merged.push([cs, ce]);
|
|
87
|
+
cs = s;
|
|
88
|
+
ce = e;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
merged.push([cs, ce]);
|
|
92
|
+
return merged;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// tools/warp_grep/agent/helpers.ts
|
|
96
|
+
import path from "path";
|
|
97
|
+
var TRUNCATED_MARKER = "[truncated for context limit]";
|
|
98
|
+
function formatTurnMessage(turnsUsed, maxTurns) {
|
|
99
|
+
const turnsRemaining = maxTurns - turnsUsed;
|
|
100
|
+
if (turnsRemaining === 1) {
|
|
101
|
+
return `
|
|
102
|
+
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`;
|
|
103
|
+
}
|
|
104
|
+
return `
|
|
105
|
+
You have used ${turnsUsed} turn${turnsUsed === 1 ? "" : "s"} and have ${turnsRemaining} remaining`;
|
|
106
|
+
}
|
|
107
|
+
function calculateContextBudget(messages) {
|
|
108
|
+
const totalChars = messages.reduce((sum, m) => sum + m.content.length, 0);
|
|
109
|
+
const maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS;
|
|
110
|
+
const percent = Math.round(totalChars / maxChars * 100);
|
|
111
|
+
const usedK = Math.round(totalChars / 1e3);
|
|
112
|
+
const maxK = Math.round(maxChars / 1e3);
|
|
113
|
+
return `<context_budget>${percent}% (${usedK}K/${maxK}K chars)</context_budget>`;
|
|
114
|
+
}
|
|
115
|
+
async function buildInitialState(repoRoot, query, provider) {
|
|
116
|
+
try {
|
|
117
|
+
const entries = await provider.listDirectory({
|
|
118
|
+
path: ".",
|
|
119
|
+
maxResults: AGENT_CONFIG.MAX_OUTPUT_LINES,
|
|
120
|
+
maxDepth: 2
|
|
121
|
+
});
|
|
122
|
+
const treeLines = entries.map((e) => {
|
|
123
|
+
const indent = " ".repeat(e.depth);
|
|
124
|
+
const name = e.type === "dir" ? `${e.name}/` : e.name;
|
|
125
|
+
return `${indent}${name}`;
|
|
126
|
+
});
|
|
127
|
+
const repoName = path.basename(repoRoot);
|
|
128
|
+
const treeOutput = treeLines.length > 0 ? `${repoName}/
|
|
129
|
+
${treeLines.join("\n")}` : `${repoName}/`;
|
|
130
|
+
return `<repo_structure>
|
|
131
|
+
${treeOutput}
|
|
132
|
+
</repo_structure>
|
|
133
|
+
|
|
134
|
+
<search_string>
|
|
135
|
+
${query}
|
|
136
|
+
</search_string>`;
|
|
137
|
+
} catch {
|
|
138
|
+
const repoName = path.basename(repoRoot);
|
|
139
|
+
return `<repo_structure>
|
|
140
|
+
${repoName}/
|
|
141
|
+
</repo_structure>
|
|
142
|
+
|
|
143
|
+
<search_string>
|
|
144
|
+
${query}
|
|
145
|
+
</search_string>`;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function formatListDirectoryTree(entries) {
|
|
149
|
+
if (!entries.length) return "empty";
|
|
150
|
+
return entries.map((e) => {
|
|
151
|
+
const indent = " ".repeat(e.depth);
|
|
152
|
+
const name = e.type === "dir" ? `${e.name}/` : e.name;
|
|
153
|
+
return `${indent}${name}`;
|
|
154
|
+
}).join("\n");
|
|
155
|
+
}
|
|
156
|
+
function enforceContextLimit(messages, maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS) {
|
|
157
|
+
const getTotalChars = () => messages.reduce((sum, m) => sum + m.content.length, 0);
|
|
158
|
+
if (getTotalChars() <= maxChars) {
|
|
159
|
+
return messages;
|
|
160
|
+
}
|
|
161
|
+
const userIndices = [];
|
|
162
|
+
let firstUserSkipped = false;
|
|
163
|
+
for (let i = 0; i < messages.length; i++) {
|
|
164
|
+
if (messages[i].role === "user") {
|
|
165
|
+
if (!firstUserSkipped) {
|
|
166
|
+
firstUserSkipped = true;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
userIndices.push(i);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
for (const idx of userIndices) {
|
|
173
|
+
if (getTotalChars() <= maxChars) {
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
if (messages[idx].content !== TRUNCATED_MARKER) {
|
|
177
|
+
messages[idx] = { role: "user", content: TRUNCATED_MARKER };
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return messages;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export {
|
|
184
|
+
toolGrep,
|
|
185
|
+
toolRead,
|
|
186
|
+
toolListDirectory,
|
|
187
|
+
normalizeFinishFiles,
|
|
188
|
+
readFinishFiles,
|
|
189
|
+
formatTurnMessage,
|
|
190
|
+
calculateContextBudget,
|
|
191
|
+
buildInitialState,
|
|
192
|
+
formatListDirectoryTree,
|
|
193
|
+
enforceContextLimit
|
|
194
|
+
};
|
|
195
|
+
//# sourceMappingURL=chunk-6Y5JB4JC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../tools/warp_grep/agent/tools/grep.ts","../tools/warp_grep/agent/tools/read.ts","../tools/warp_grep/agent/tools/list_directory.ts","../tools/warp_grep/agent/tools/finish.ts","../tools/warp_grep/agent/helpers.ts"],"sourcesContent":["import type { WarpGrepProvider } from '../../providers/types.js';\n\nexport async function toolGrep(\n provider: WarpGrepProvider,\n args: { pattern: string; path: string; glob?: string }\n): Promise<{ output: string }> {\n const res = await provider.grep(args);\n \n // Return errors as output - let the model see and handle them\n if (res.error) {\n return { output: res.error };\n }\n \n if (!res.lines.length) {\n return { output: 'no matches' };\n }\n \n return { output: res.lines.join('\\n') };\n}\n\n","import type { WarpGrepProvider } from '../../providers/types.js';\n\nexport async function toolRead(\n provider: WarpGrepProvider,\n args: { path: string; start?: number; end?: number; lines?: Array<[number, number]> }\n): Promise<string> {\n if (args.lines && args.lines.length > 0) {\n const chunks: string[] = [];\n for (const [start, end] of args.lines) {\n const res = await provider.read({ path: args.path, start, end });\n if (res.error) return res.error;\n chunks.push(res.lines.join('\\n'));\n }\n if (chunks.every(c => c === '')) return '(empty file)';\n return chunks.join('\\n...\\n');\n }\n\n const res = await provider.read({ path: args.path, start: args.start, end: args.end });\n if (res.error) {\n return res.error;\n }\n if (!res.lines.length) return '(empty file)';\n return res.lines.join('\\n');\n}\n\n","import type { WarpGrepProvider } from '../../providers/types.js';\nimport { AGENT_CONFIG } from '../config.js';\n\nexport async function toolListDirectory(\n provider: WarpGrepProvider,\n args: { path: string; pattern?: string | null; maxResults?: number; maxDepth?: number }\n): Promise<string> {\n const list = await provider.listDirectory({\n path: args.path,\n pattern: args.pattern ?? null,\n maxResults: args.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES,\n maxDepth: args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH,\n });\n \n if (!list.length) return 'empty';\n if (list.length >= AGENT_CONFIG.MAX_OUTPUT_LINES) {\n return 'query not specific enough, tool called tried to return too much context and failed';\n }\n return list\n .map((e) => {\n const indent = ' '.repeat(e.depth);\n const name = e.type === 'dir' ? `${e.name}/` : e.name;\n return `${indent}${name}`;\n })\n .join('\\n');\n}\n\n","import type { FinishFileSpec } from '../types.js';\n\nexport function normalizeFinishFiles(files: FinishFileSpec[]): FinishFileSpec[] {\n return files.map((f) => {\n const merged = mergeRanges(f.lines);\n return { path: f.path, lines: merged };\n });\n}\n\nexport async function readFinishFiles(\n repoRoot: string,\n files: FinishFileSpec[],\n reader: (path: string, start: number, end: number) => Promise<string[]>\n): Promise<{ path: string; ranges: Array<[number, number]>; content: string }[]> {\n const out: { path: string; ranges: Array<[number, number]>; content: string }[] = [];\n for (const f of files) {\n const ranges = mergeRanges(f.lines);\n const chunks: string[] = [];\n for (const [s, e] of ranges) {\n const lines = await reader(f.path, s, e);\n chunks.push(lines.join('\\n'));\n }\n out.push({ path: f.path, ranges, content: chunks.join('\\n') });\n }\n return out;\n}\n\nfunction mergeRanges(ranges: Array<[number, number]>): Array<[number, number]> {\n if (!ranges.length) return [];\n const sorted = [...ranges].sort((a, b) => a[0] - b[0]);\n const merged: Array<[number, number]> = [];\n let [cs, ce] = sorted[0];\n for (let i = 1; i < sorted.length; i++) {\n const [s, e] = sorted[i];\n if (s <= ce + 1) {\n ce = Math.max(ce, e);\n } else {\n merged.push([cs, ce]);\n cs = s;\n ce = e;\n }\n }\n merged.push([cs, ce]);\n return merged;\n}\n\n","/**\n * Shared helper functions for warp-grep agent loop.\n * Used by both the internal runner and exported for harness users.\n */\n\nimport path from 'path';\nimport { AGENT_CONFIG } from './config.js';\nimport type { ChatMessage } from './types.js';\nimport type { WarpGrepProvider, ListDirectoryEntry } from '../providers/types.js';\n\nconst TRUNCATED_MARKER = '[truncated for context limit]';\n\n/**\n * Format the turn counter message shown to the model.\n */\nexport function formatTurnMessage(turnsUsed: number, maxTurns: number): string {\n const turnsRemaining = maxTurns - turnsUsed;\n if (turnsRemaining === 1) {\n return `\\nYou 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`;\n }\n return `\\nYou have used ${turnsUsed} turn${turnsUsed === 1 ? '' : 's'} and have ${turnsRemaining} remaining`;\n}\n\n/**\n * Calculate and format the context budget indicator.\n */\nexport function calculateContextBudget(messages: ChatMessage[]): string {\n const totalChars = messages.reduce((sum, m) => sum + m.content.length, 0);\n const maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS;\n const percent = Math.round((totalChars / maxChars) * 100);\n const usedK = Math.round(totalChars / 1000);\n const maxK = Math.round(maxChars / 1000);\n return `<context_budget>${percent}% (${usedK}K/${maxK}K chars)</context_budget>`;\n}\n\n/**\n * Build the initial state message containing repo structure and query.\n */\nexport async function buildInitialState(\n repoRoot: string,\n query: string,\n provider: WarpGrepProvider\n): Promise<string> {\n try {\n const entries = await provider.listDirectory({\n path: '.',\n maxResults: AGENT_CONFIG.MAX_OUTPUT_LINES,\n maxDepth: 2,\n });\n const treeLines = entries.map((e) => {\n const indent = ' '.repeat(e.depth);\n const name = e.type === 'dir' ? `${e.name}/` : e.name;\n return `${indent}${name}`;\n });\n\n const repoName = path.basename(repoRoot);\n const treeOutput =\n treeLines.length > 0 ? `${repoName}/\\n${treeLines.join('\\n')}` : `${repoName}/`;\n\n return `<repo_structure>\\n${treeOutput}\\n</repo_structure>\\n\\n<search_string>\\n${query}\\n</search_string>`;\n } catch {\n const repoName = path.basename(repoRoot);\n return `<repo_structure>\\n${repoName}/\\n</repo_structure>\\n\\n<search_string>\\n${query}\\n</search_string>`;\n }\n}\n\n/**\n * Format directory entries as an indented tree string.\n */\nexport function formatListDirectoryTree(entries: ListDirectoryEntry[]): string {\n if (!entries.length) return 'empty';\n return entries\n .map((e) => {\n const indent = ' '.repeat(e.depth);\n const name = e.type === 'dir' ? `${e.name}/` : e.name;\n return `${indent}${name}`;\n })\n .join('\\n');\n}\n\n/**\n * Enforce hard context limit by truncating user messages.\n * Preserves system prompt, first user message (initial query), and all assistant messages.\n * Removes tool result user messages from oldest to newest until under the threshold.\n * \n * @param messages - The conversation messages array (mutated in place)\n * @param maxChars - Maximum total character count (defaults to AGENT_CONFIG.MAX_CONTEXT_CHARS)\n * @returns The same messages array, truncated if necessary\n */\nexport function enforceContextLimit(\n messages: ChatMessage[],\n maxChars: number = AGENT_CONFIG.MAX_CONTEXT_CHARS\n): ChatMessage[] {\n const getTotalChars = () => messages.reduce((sum, m) => sum + m.content.length, 0);\n \n if (getTotalChars() <= maxChars) {\n return messages;\n }\n\n // Find indices of user messages, skipping the first one (initial query with repo structure)\n // We truncate tool result messages from oldest to newest\n const userIndices: number[] = [];\n let firstUserSkipped = false;\n for (let i = 0; i < messages.length; i++) {\n if (messages[i].role === 'user') {\n if (!firstUserSkipped) {\n firstUserSkipped = true;\n continue; // Skip first user message (contains the search query)\n }\n userIndices.push(i);\n }\n }\n\n // Truncate user messages from oldest to newest until under limit\n for (const idx of userIndices) {\n if (getTotalChars() <= maxChars) {\n break;\n }\n // Only truncate if not already truncated\n if (messages[idx].content !== TRUNCATED_MARKER) {\n messages[idx] =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AAS,iBAAiB;AAAA,IAC5D;AAAA,EACF;AAEA,SAAO;AACT;","names":["res"]}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
createWarpGrepTool as createWarpGrepTool2
|
|
3
|
+
} from "./chunk-3IQIT6MC.js";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
} from "./chunk-
|
|
5
|
+
createWarpGrepTool
|
|
6
|
+
} from "./chunk-6N6ZYZYD.js";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
} from "./chunk-
|
|
8
|
+
createWarpGrepTool as createWarpGrepTool3
|
|
9
|
+
} from "./chunk-4VGOBA2J.js";
|
|
10
10
|
import {
|
|
11
11
|
WarpGrepClient
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-374N3GIA.js";
|
|
13
13
|
import {
|
|
14
14
|
createCodebaseSearchTool as createCodebaseSearchTool3
|
|
15
15
|
} from "./chunk-UBX7QYBD.js";
|
|
@@ -55,13 +55,13 @@ var OpenAIToolFactory = class {
|
|
|
55
55
|
/**
|
|
56
56
|
* Create an OpenAI-compatible warp grep tool
|
|
57
57
|
*
|
|
58
|
-
* @param toolConfig - Tool configuration (
|
|
58
|
+
* @param toolConfig - Tool configuration (morphApiKey inherited from MorphClient)
|
|
59
59
|
* @returns OpenAI ChatCompletionTool with execute and formatResult methods
|
|
60
60
|
*/
|
|
61
61
|
createWarpGrepTool(toolConfig) {
|
|
62
|
-
return
|
|
62
|
+
return createWarpGrepTool({
|
|
63
63
|
...toolConfig,
|
|
64
|
-
|
|
64
|
+
morphApiKey: this.config.apiKey
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
@@ -98,13 +98,13 @@ var AnthropicToolFactory = class {
|
|
|
98
98
|
/**
|
|
99
99
|
* Create an Anthropic-compatible warp grep tool
|
|
100
100
|
*
|
|
101
|
-
* @param toolConfig - Tool configuration (
|
|
101
|
+
* @param toolConfig - Tool configuration (morphApiKey inherited from MorphClient)
|
|
102
102
|
* @returns Anthropic Tool with execute and formatResult methods
|
|
103
103
|
*/
|
|
104
104
|
createWarpGrepTool(toolConfig) {
|
|
105
|
-
return
|
|
105
|
+
return createWarpGrepTool2({
|
|
106
106
|
...toolConfig,
|
|
107
|
-
|
|
107
|
+
morphApiKey: this.config.apiKey
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
@@ -141,13 +141,13 @@ var VercelToolFactory = class {
|
|
|
141
141
|
/**
|
|
142
142
|
* Create a Vercel AI SDK-compatible warp grep tool
|
|
143
143
|
*
|
|
144
|
-
* @param toolConfig - Tool configuration (
|
|
144
|
+
* @param toolConfig - Tool configuration (morphApiKey inherited from MorphClient)
|
|
145
145
|
* @returns Vercel AI SDK tool
|
|
146
146
|
*/
|
|
147
147
|
createWarpGrepTool(toolConfig) {
|
|
148
|
-
return
|
|
148
|
+
return createWarpGrepTool3({
|
|
149
149
|
...toolConfig,
|
|
150
|
-
|
|
150
|
+
morphApiKey: this.config.apiKey
|
|
151
151
|
});
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
@@ -227,7 +227,7 @@ var MorphClient = class {
|
|
|
227
227
|
retryConfig: config.retryConfig
|
|
228
228
|
});
|
|
229
229
|
this.warpGrep = new WarpGrepClient({
|
|
230
|
-
|
|
230
|
+
morphApiKey: config.apiKey,
|
|
231
231
|
debug: config.debug,
|
|
232
232
|
timeout: config.timeout,
|
|
233
233
|
retryConfig: config.retryConfig
|
|
@@ -280,4 +280,4 @@ export {
|
|
|
280
280
|
VercelToolFactory,
|
|
281
281
|
MorphClient
|
|
282
282
|
};
|
|
283
|
-
//# sourceMappingURL=chunk-
|
|
283
|
+
//# sourceMappingURL=chunk-7EIHYJSG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../factories/openai.ts","../factories/anthropic.ts","../factories/vercel.ts","../client.ts"],"sourcesContent":["/**\n * OpenAI Tool Factory for MorphClient\n * \n * Creates OpenAI-compatible tools that inherit the API key from MorphClient.\n */\n\nimport type { MorphClientConfig } from '../client.js';\nimport { createWarpGrepTool } from '../tools/warp_grep/openai.js';\nimport { createCodebaseSearchTool } from '../tools/codebase_search/openai.js';\nimport { createEditFileTool } from '../tools/fastapply/openai.js';\nimport type { WarpGrepToolConfig } from '../tools/warp_grep/types.js';\nimport type { CodebaseSearchConfig } from '../tools/codebase_search/types.js';\nimport type { EditFileConfig } from '../tools/fastapply/types.js';\n\n/**\n * Factory for creating OpenAI-compatible tools with inherited API key\n * \n * @example\n * ```typescript\n * const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });\n * \n * const grepTool = morph.openai.createWarpGrepTool({ repoRoot: '.' });\n * const searchTool = morph.openai.createCodebaseSearchTool({ repoId: 'my-project' });\n * const editTool = morph.openai.createEditFileTool({ baseDir: './src' });\n * \n * // Use with OpenAI client\n * const response = await openai.chat.completions.create({\n * model: 'gpt-4o',\n * tools: [grepTool, searchTool, editTool],\n * messages: [{ role: 'user', content: 'Find and fix the bug' }]\n * });\n * ```\n */\nexport class OpenAIToolFactory {\n constructor(private config: MorphClientConfig) {}\n\n /**\n * Create an OpenAI-compatible warp grep tool\n * \n * @param toolConfig - Tool configuration (morphApiKey inherited from MorphClient)\n * @returns OpenAI ChatCompletionTool with execute and formatResult methods\n */\n createWarpGrepTool(toolConfig: Omit<WarpGrepToolConfig, 'morphApiKey'>) {\n return createWarpGrepTool({ \n ...toolConfig, \n morphApiKey: this.config.apiKey,\n });\n }\n\n /**\n * Create an OpenAI-compatible codebase search tool\n * \n * @param toolConfig - Tool configuration with repoId (apiKey inherited from MorphClient)\n * @returns OpenAI ChatCompletionTool with execute and formatResult methods\n */\n createCodebaseSearchTool(toolConfig: Omit<CodebaseSearchConfig, 'apiKey'>) {\n return createCodebaseSearchTool({ \n ...toolConfig, \n apiKey: this.config.apiKey,\n });\n }\n\n /**\n * Create an OpenAI-compatible edit file tool\n * \n * @param toolConfig - Tool configuration (morphApiKey inherited from MorphClient)\n * @returns OpenAI ChatCompletionTool with execute and formatResult methods\n */\n createEditFileTool(toolConfig: Omit<EditFileConfig, 'morphApiKey'> = {}) {\n return createEditFileTool({ \n ...toolConfig, \n morphApiKey: this.config.apiKey,\n });\n }\n}\n\n","/**\n * Anthropic Tool Factory for MorphClient\n * \n * Creates Anthropic-compatible tools that inherit the API key from MorphClient.\n */\n\nimport type { MorphClientConfig } from '../client.js';\nimport { createWarpGrepTool } from '../tools/warp_grep/anthropic.js';\nimport { createCodebaseSearchTool } from '../tools/codebase_search/anthropic.js';\nimport { createEditFileTool } from '../tools/fastapply/anthropic.js';\nimport type { WarpGrepToolConfig } from '../tools/warp_grep/types.js';\nimport type { CodebaseSearchConfig } from '../tools/codebase_search/types.js';\nimport type { EditFileConfig } from '../tools/fastapply/types.js';\n\n/**\n * Factory for creating Anthropic-compatible tools with inherited API key\n * \n * @example\n * ```typescript\n * const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });\n * \n * const grepTool = morph.anthropic.createWarpGrepTool({ repoRoot: '.' });\n * const searchTool = morph.anthropic.createCodebaseSearchTool({ repoId: 'my-project' });\n * const editTool = morph.anthropic.createEditFileTool({ baseDir: './src' });\n * \n * // Use with Anthropic client\n * const response = await anthropic.messages.create({\n * model: 'claude-sonnet-4-5-20250929',\n * tools: [grepTool, searchTool, editTool],\n * messages: [{ role: 'user', content: 'Find and fix the bug' }]\n * });\n * ```\n */\nexport class AnthropicToolFactory {\n constructor(private config: MorphClientConfig) {}\n\n /**\n * Create an Anthropic-compatible warp grep tool\n * \n * @param toolConfig - Tool configuration (morphApiKey inherited from MorphClient)\n * @returns Anthropic Tool with execute and formatResult methods\n */\n createWarpGrepTool(toolConfig: Omit<WarpGrepToolConfig, 'morphApiKey'>) {\n return createWarpGrepTool({ \n ...toolConfig, \n morphApiKey: this.config.apiKey,\n });\n }\n\n /**\n * Create an Anthropic-compatible codebase search tool\n * \n * @param toolConfig - Tool configuration with repoId (apiKey inherited from MorphClient)\n * @returns Anthropic Tool with execute and formatResult methods\n */\n createCodebaseSearchTool(toolConfig: Omit<CodebaseSearchConfig, 'apiKey'>) {\n return createCodebaseSearchTool({ \n ...toolConfig, \n apiKey: this.config.apiKey,\n });\n }\n\n /**\n * Create an Anthropic-compatible edit file tool\n * \n * @param toolConfig - Tool configuration (morphApiKey inherited from MorphClient)\n * @returns Anthropic Tool with execute and formatResult methods\n */\n createEditFileTool(toolConfig: Omit<EditFileConfig, 'morphApiKey'> = {}) {\n return createEditFileTool({ \n ...toolConfig, \n morphApiKey: this.config.apiKey,\n });\n }\n}\n\n","/**\n * Vercel AI SDK Tool Factory for MorphClient\n * \n * Creates Vercel AI SDK-compatible tools that inherit the API key from MorphClient.\n */\n\nimport type { MorphClientConfig } from '../client.js';\nimport { createWarpGrepTool } from '../tools/warp_grep/vercel.js';\nimport { createCodebaseSearchTool } from '../tools/codebase_search/vercel.js';\nimport { createEditFileTool } from '../tools/fastapply/vercel.js';\nimport type { WarpGrepToolConfig } from '../tools/warp_grep/types.js';\nimport type { CodebaseSearchConfig } from '../tools/codebase_search/types.js';\nimport type { EditFileConfig } from '../tools/fastapply/types.js';\n\n/**\n * Factory for creating Vercel AI SDK-compatible tools with inherited API key\n * \n * @example\n * ```typescript\n * const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });\n * \n * const grepTool = morph.vercel.createWarpGrepTool({ repoRoot: '.' });\n * const searchTool = morph.vercel.createCodebaseSearchTool({ repoId: 'my-project' });\n * const editTool = morph.vercel.createEditFileTool({ baseDir: './src' });\n * \n * // Use with Vercel AI SDK\n * const result = await generateText({\n * model: anthropic('claude-sonnet-4-5-20250929'),\n * tools: { grep: grepTool, search: searchTool, edit: editTool },\n * prompt: 'Find and fix the bug'\n * });\n * ```\n */\nexport class VercelToolFactory {\n constructor(private config: MorphClientConfig) {}\n\n /**\n * Create a Vercel AI SDK-compatible warp grep tool\n * \n * @param toolConfig - Tool configuration (morphApiKey inherited from MorphClient)\n * @returns Vercel AI SDK tool\n */\n createWarpGrepTool(toolConfig: Omit<WarpGrepToolConfig, 'morphApiKey'>) {\n return createWarpGrepTool({ \n ...toolConfig, \n morphApiKey: this.config.apiKey,\n });\n }\n\n /**\n * Create a Vercel AI SDK-compatible codebase search tool\n * \n * @param toolConfig - Tool configuration with repoId (apiKey inherited from MorphClient)\n * @returns Vercel AI SDK tool\n */\n createCodebaseSearchTool(toolConfig: Omit<CodebaseSearchConfig, 'apiKey'>) {\n return createCodebaseSearchTool({ \n ...toolConfig, \n apiKey: this.config.apiKey,\n });\n }\n\n /**\n * Create a Vercel AI SDK-compatible edit file tool\n * \n * @param toolConfig - Tool configuration (morphApiKey inherited from MorphClient)\n * @returns Vercel AI SDK tool\n */\n createEditFileTool(toolConfig: Omit<EditFileConfig, 'morphApiKey'> = {}) {\n return createEditFileTool({ \n ...toolConfig, \n morphApiKey: this.config.apiKey,\n });\n }\n}\n\n","/**\n * Unified Morph SDK Client\n * \n * Provides access to all Morph tools through a single interface\n * \n * @example\n * ```typescript\n * import { MorphClient } from '@morphllm/morphsdk';\n * \n * const morph = new MorphClient({ \n * apiKey: process.env.MORPH_API_KEY,\n * debug: true,\n * timeout: 60000\n * });\n * \n * // Direct execution\n * await morph.fastApply.execute({ target_filepath: 'src/index.ts', ... });\n * await morph.warpGrep.execute({ query: 'Find auth', repoRoot: '.' });\n * await morph.codebaseSearch.search({ query: 'auth logic', repoId: 'x' });\n * \n * // Tool creation for AI agents (API key inherited)\n * const grepTool = morph.openai.createWarpGrepTool({ repoRoot: '.' });\n * const searchTool = morph.anthropic.createCodebaseSearchTool({ repoId: 'x' });\n * const editTool = morph.vercel.createEditFileTool({ baseDir: './src' });\n * \n * // Use tools with OpenAI\n * const response = await openai.chat.completions.create({\n * model: 'gpt-4o',\n * tools: [grepTool],\n * messages: [{ role: 'user', content: 'Find the bug' }]\n * });\n * ```\n */\n\nimport type { RetryConfig } from './tools/utils/resilience.js';\nimport { FastApplyClient } from './tools/fastapply/core.js';\nimport { CodebaseSearchClient } from './tools/codebase_search/core.js';\nimport { BrowserClient } from './tools/browser/core.js';\nimport { WarpGrepClient } from './tools/warp_grep/client.js';\nimport { MorphGit } from './git/index.js';\nimport { OpenAIRouter, AnthropicRouter, GeminiRouter, RawRouter } from './modelrouter/core.js';\nimport { OpenAIToolFactory, AnthropicToolFactory, VercelToolFactory } from './factories/index.js';\n\n/**\n * Configuration for the MorphClient\n */\nexport interface MorphClientConfig {\n /** Morph API key for authentication (defaults to MORPH_API_KEY env var) */\n apiKey?: string;\n /** Enable debug logging across all tools */\n debug?: boolean;\n /** Default timeout in milliseconds for API requests */\n timeout?: number;\n /** Retry configuration for failed requests */\n retryConfig?: RetryConfig;\n}\n\n/**\n * Unified Morph SDK Client\n * \n * Provides access to all Morph tools through a single interface:\n * - fastApply: AI-powered file editing with intelligent merging\n * - codebaseSearch: Semantic code search\n * - warpGrep: Fast code search with ripgrep\n * - browser: AI-powered browser automation\n * - git: Version control operations\n * - routers: Intelligent model selection (OpenAI, Anthropic, Gemini)\n * - openai/anthropic/vercel: Tool factories for agent frameworks\n */\nexport class MorphClient {\n /** Client configuration */\n public config: MorphClientConfig;\n\n /** FastApply tool for editing files with AI-powered merge */\n public fastApply: FastApplyClient;\n\n /** CodebaseSearch tool for semantic code search */\n public codebaseSearch: CodebaseSearchClient;\n\n /** WarpGrep tool for fast code search using ripgrep */\n public warpGrep: WarpGrepClient;\n\n /** Browser tool for AI-powered browser automation */\n public browser: BrowserClient;\n\n /** Git tool for version control operations */\n public git: MorphGit;\n\n /** Model routers for intelligent model selection */\n public routers: {\n openai: OpenAIRouter;\n anthropic: AnthropicRouter;\n gemini: GeminiRouter;\n raw: RawRouter;\n };\n\n /** OpenAI-compatible tool factories */\n public openai: OpenAIToolFactory;\n\n /** Anthropic-compatible tool factories */\n public anthropic: AnthropicToolFactory;\n\n /** Vercel AI SDK tool factories */\n public vercel: VercelToolFactory;\n\n /**\n * Create a new Morph SDK client\n * \n * @param config - Client configuration (apiKey, debug, timeout, retryConfig)\n * \n * @example\n * ```typescript\n * const morph = new MorphClient({ \n * apiKey: process.env.MORPH_API_KEY,\n * debug: true,\n * timeout: 60000\n * });\n * ```\n */\n constructor(config: MorphClientConfig = {}) {\n this.config = config;\n\n // Initialize all sub-clients with shared config\n this.fastApply = new FastApplyClient({\n apiKey: config.apiKey,\n debug: config.debug,\n timeout: config.timeout,\n retryConfig: config.retryConfig,\n });\n\n this.codebaseSearch = new CodebaseSearchClient({\n apiKey: config.apiKey,\n debug: config.debug,\n timeout: config.timeout,\n retryConfig: config.retryConfig,\n });\n\n this.warpGrep = new WarpGrepClient({\n morphApiKey: config.apiKey,\n debug: config.debug,\n timeout: config.timeout,\n retryConfig: config.retryConfig,\n });\n\n this.browser = new BrowserClient({\n apiKey: config.apiKey,\n debug: config.debug,\n timeout: config.timeout,\n retryConfig: config.retryConfig,\n });\n\n this.git = new MorphGit({\n apiKey: config.apiKey,\n retryConfig: config.retryConfig,\n });\n\n this.routers = {\n openai: new OpenAIRouter({\n apiKey: config.apiKey,\n debug: config.debug,\n timeout: config.timeout,\n retryConfig: config.retryConfig,\n }),\n anthropic: new AnthropicRouter({\n apiKey: config.apiKey,\n debug: config.debug,\n timeout: config.timeout,\n retryConfig: config.retryConfig,\n }),\n gemini: new GeminiRouter({\n apiKey: config.apiKey,\n debug: config.debug,\n timeout: config.timeout,\n retryConfig: config.retryConfig,\n }),\n raw: new RawRouter({\n apiKey: config.apiKey,\n debug: config.debug,\n timeout: config.timeout,\n retryConfig: config.retryConfig,\n }),\n };\n\n // Initialize tool factories\n this.openai = new OpenAIToolFactory(config);\n this.anthropic = new AnthropicToolFactory(config);\n this.vercel = new VercelToolFactory(config);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCO,IAAM,oBAAN,MAAwB;AAAA,EAC7B,YAAoB,QAA2B;AAA3B;AAAA,EAA4B;AAAA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UAAU,IAAI,cAAc;AAAA,MAC/B,QAAQ,OAAO;AAAA,MACf,OAAO,OAAO;AAAA,MACd,SAAS,OAAO;AAAA,MAChB,aAAa,OAAO;AAAA,IACtB,CAAC;AAED,SAAK,MAAM,IAAI,SAAS;AAAA,MACtB,QAAQ,OAAO;AAAA,MACf,aAAa,OAAO;AAAA,IACtB,CAAC;AAED,SAAK,UAAU;AAAA,MACb,QAAQ,IAAI,aAAa;AAAA,QACvB,QAAQ,OAAO;AAAA,QACf,OAAO,OAAO;AAAA,QACd,SAAS,OAAO;AAAA,QAChB,aAAa,OAAO;AAAA,MACtB,CAAC;AAAA,MACD,WAAW,IAAI,gBAAgB;AAAA,QAC7B,QAAQ,OAAO;AAAA,QACf,OAAO,OAAO;AAAA,QACd,SAAS,OAAO;AAAA,QAChB,aAAa,OAAO;AAAA,MACtB,CAAC;AAAA,MACD,QAAQ,IAAI,aAAa;AAAA,QACvB,QAAQ,OAAO;AAAA,QACf,OAAO,OAAO;AAAA,QACd,SAAS,OAAO;AAAA,QAChB,aAAa,OAAO;AAAA,MACtB,CAAC;AAAA,MACD,KAAK,IAAI,UAAU;AAAA,QACjB,QAAQ,OAAO;AAAA,QACf,OAAO,OAAO;AAAA,QACd,SAAS,OAAO;AAAA,QAChB,aAAa,OAAO;AAAA,MACtB,CAAC;AAAA,IACH;AAGA,SAAK,SAAS,IAAI,kBAAkB,MAAM;AAC1C,SAAK,YAAY,IAAI,qBAAqB,MAAM;AAChD,SAAK,SAAS,IAAI,kBAAkB,MAAM;AAAA,EAC5C;AACF;","names":["createWarpGrepTool","createCodebaseSearchTool","createEditFileTool","createWarpGrepTool","createCodebaseSearchTool","createEditFileTool"]}
|
|
@@ -14,8 +14,8 @@ var ToolOutputFormatter = class {
|
|
|
14
14
|
switch (name) {
|
|
15
15
|
case "read":
|
|
16
16
|
return this.formatRead(safeArgs, payload, isError);
|
|
17
|
-
case "
|
|
18
|
-
return this.
|
|
17
|
+
case "list_directory":
|
|
18
|
+
return this.formatListDirectory(safeArgs, payload, isError);
|
|
19
19
|
case "grep":
|
|
20
20
|
return this.formatGrep(safeArgs, payload, isError);
|
|
21
21
|
default:
|
|
@@ -29,38 +29,55 @@ ${payload}
|
|
|
29
29
|
return payload;
|
|
30
30
|
}
|
|
31
31
|
const path = this.asString(args.path) || "...";
|
|
32
|
-
|
|
32
|
+
const start = args.start;
|
|
33
|
+
const end = args.end;
|
|
34
|
+
const linesArray = args.lines;
|
|
35
|
+
const attributes = [`path="${path}"`];
|
|
36
|
+
if (linesArray && linesArray.length > 0) {
|
|
37
|
+
const rangeStr = linesArray.map(([s, e]) => `${s}-${e}`).join(",");
|
|
38
|
+
attributes.push(`lines="${rangeStr}"`);
|
|
39
|
+
} else if (start !== void 0 && end !== void 0) {
|
|
40
|
+
attributes.push(`lines="${start}-${end}"`);
|
|
41
|
+
}
|
|
42
|
+
return `<read ${attributes.join(" ")}>
|
|
33
43
|
${payload}
|
|
34
|
-
</
|
|
44
|
+
</read>`;
|
|
35
45
|
}
|
|
36
|
-
|
|
46
|
+
formatListDirectory(args, payload, isError) {
|
|
37
47
|
const path = this.asString(args.path) || ".";
|
|
48
|
+
const pattern = this.asString(args.pattern);
|
|
49
|
+
const attributes = [`path="${path}"`];
|
|
50
|
+
if (pattern) {
|
|
51
|
+
attributes.push(`pattern="${pattern}"`);
|
|
52
|
+
}
|
|
38
53
|
if (isError) {
|
|
39
|
-
|
|
40
|
-
${payload}
|
|
41
|
-
</analyse_results>`;
|
|
54
|
+
attributes.push('status="error"');
|
|
42
55
|
}
|
|
43
|
-
return `<
|
|
56
|
+
return `<list_directory ${attributes.join(" ")}>
|
|
44
57
|
${payload}
|
|
45
|
-
</
|
|
58
|
+
</list_directory>`;
|
|
46
59
|
}
|
|
47
60
|
formatGrep(args, payload, isError) {
|
|
48
61
|
const pattern = this.asString(args.pattern);
|
|
49
|
-
const
|
|
62
|
+
const subDir = this.asString(args.path);
|
|
63
|
+
const glob = this.asString(args.glob);
|
|
50
64
|
const attributes = [];
|
|
51
65
|
if (pattern !== void 0) {
|
|
52
66
|
attributes.push(`pattern="${pattern}"`);
|
|
53
67
|
}
|
|
54
|
-
if (
|
|
55
|
-
attributes.push(`
|
|
68
|
+
if (subDir !== void 0) {
|
|
69
|
+
attributes.push(`sub_dir="${subDir}"`);
|
|
70
|
+
}
|
|
71
|
+
if (glob !== void 0) {
|
|
72
|
+
attributes.push(`glob="${glob}"`);
|
|
56
73
|
}
|
|
57
74
|
if (isError) {
|
|
58
75
|
attributes.push('status="error"');
|
|
59
76
|
}
|
|
60
77
|
const attrText = attributes.length ? ` ${attributes.join(" ")}` : "";
|
|
61
|
-
return `<
|
|
78
|
+
return `<grep${attrText}>
|
|
62
79
|
${payload}
|
|
63
|
-
</
|
|
80
|
+
</grep>`;
|
|
64
81
|
}
|
|
65
82
|
asString(value) {
|
|
66
83
|
if (value === null || value === void 0) {
|
|
@@ -78,4 +95,4 @@ export {
|
|
|
78
95
|
ToolOutputFormatter,
|
|
79
96
|
formatAgentToolOutput
|
|
80
97
|
};
|
|
81
|
-
//# sourceMappingURL=chunk-
|
|
98
|
+
//# sourceMappingURL=chunk-APP75CBN.js.map
|