@morphllm/morphsdk 0.2.82 → 0.2.84
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-ZLJAODDJ.js → chunk-262WRPS5.js} +2 -2
- package/dist/{chunk-FJKPMMNQ.js → chunk-D4EQYM6O.js} +2 -2
- package/dist/{chunk-P2O5JKE5.js → chunk-KRDIR7GG.js} +17 -8
- package/dist/chunk-KRDIR7GG.js.map +1 -0
- package/dist/{chunk-WIAYUEJK.js → chunk-LF2X6YNP.js} +26 -6
- package/dist/chunk-LF2X6YNP.js.map +1 -0
- package/dist/{chunk-24EYSWME.js → chunk-LX2WNS3L.js} +2 -2
- package/dist/{chunk-3ONNAQZU.js → chunk-MJ7JODAY.js} +2 -2
- package/dist/{chunk-EK5ZEOI3.js → chunk-N3RNM4A4.js} +5 -5
- package/dist/client.cjs +40 -11
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +7 -7
- package/dist/index.cjs +40 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -7
- package/dist/tools/warp_grep/agent/runner.cjs +40 -11
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +2 -2
- package/dist/tools/warp_grep/agent/types.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/types.d.ts +14 -1
- package/dist/tools/warp_grep/anthropic.cjs +40 -11
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.js +4 -4
- package/dist/tools/warp_grep/client.cjs +40 -11
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.js +3 -3
- package/dist/tools/warp_grep/gemini.cjs +40 -11
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.js +3 -3
- package/dist/tools/warp_grep/harness.cjs +16 -7
- package/dist/tools/warp_grep/harness.cjs.map +1 -1
- package/dist/tools/warp_grep/harness.js +1 -1
- package/dist/tools/warp_grep/index.cjs +40 -11
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.js +3 -3
- package/dist/tools/warp_grep/openai.cjs +40 -11
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.js +4 -4
- package/dist/tools/warp_grep/vercel.cjs +40 -11
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.js +4 -4
- package/package.json +1 -1
- package/dist/chunk-P2O5JKE5.js.map +0 -1
- package/dist/chunk-WIAYUEJK.js.map +0 -1
- /package/dist/{chunk-ZLJAODDJ.js.map → chunk-262WRPS5.js.map} +0 -0
- /package/dist/{chunk-FJKPMMNQ.js.map → chunk-D4EQYM6O.js.map} +0 -0
- /package/dist/{chunk-24EYSWME.js.map → chunk-LX2WNS3L.js.map} +0 -0
- /package/dist/{chunk-3ONNAQZU.js.map → chunk-MJ7JODAY.js.map} +0 -0
- /package/dist/{chunk-EK5ZEOI3.js.map → chunk-N3RNM4A4.js.map} +0 -0
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
executeToolCall,
|
|
7
7
|
formatResult
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-D4EQYM6O.js";
|
|
9
9
|
import {
|
|
10
10
|
getSystemPrompt
|
|
11
11
|
} from "./chunk-FMLHRJDF.js";
|
|
@@ -50,4 +50,4 @@ export {
|
|
|
50
50
|
execute,
|
|
51
51
|
createWarpGrepTool
|
|
52
52
|
};
|
|
53
|
-
//# sourceMappingURL=chunk-
|
|
53
|
+
//# sourceMappingURL=chunk-262WRPS5.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runWarpGrep
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LF2X6YNP.js";
|
|
4
4
|
import {
|
|
5
5
|
RemoteCommandsProvider
|
|
6
6
|
} from "./chunk-PUGSTXLO.js";
|
|
@@ -117,4 +117,4 @@ export {
|
|
|
117
117
|
executeToolCall,
|
|
118
118
|
formatResult
|
|
119
119
|
};
|
|
120
|
-
//# sourceMappingURL=chunk-
|
|
120
|
+
//# sourceMappingURL=chunk-D4EQYM6O.js.map
|
|
@@ -51,14 +51,23 @@ async function toolRead(provider, args) {
|
|
|
51
51
|
|
|
52
52
|
// tools/warp_grep/agent/tools/list_directory.ts
|
|
53
53
|
async function toolListDirectory(provider, args) {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
const maxResults = args.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES;
|
|
55
|
+
const initialDepth = args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
56
|
+
async function getListRecursive(currentDepth) {
|
|
57
|
+
const entries = await provider.listDirectory({
|
|
58
|
+
path: args.path,
|
|
59
|
+
pattern: args.pattern ?? null,
|
|
60
|
+
maxResults,
|
|
61
|
+
maxDepth: currentDepth
|
|
62
|
+
});
|
|
63
|
+
if (entries.length >= maxResults && currentDepth > 0) {
|
|
64
|
+
return getListRecursive(currentDepth - 1);
|
|
65
|
+
}
|
|
66
|
+
return { entries };
|
|
67
|
+
}
|
|
68
|
+
const { entries: list } = await getListRecursive(initialDepth);
|
|
60
69
|
if (!list.length) return "empty";
|
|
61
|
-
if (list.length >=
|
|
70
|
+
if (list.length >= maxResults) {
|
|
62
71
|
return "query not specific enough, tool called tried to return too much context and failed";
|
|
63
72
|
}
|
|
64
73
|
return list.map((e) => {
|
|
@@ -228,4 +237,4 @@ export {
|
|
|
228
237
|
formatListDirectoryTree,
|
|
229
238
|
enforceContextLimit
|
|
230
239
|
};
|
|
231
|
-
//# sourceMappingURL=chunk-
|
|
240
|
+
//# sourceMappingURL=chunk-KRDIR7GG.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\nfunction isValidRange(start: unknown, end: unknown): boolean {\n return (\n typeof start === 'number' &&\n typeof end === 'number' &&\n Number.isFinite(start) &&\n Number.isFinite(end) &&\n start > 0 &&\n end >= start\n );\n}\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 && Array.isArray(args.lines) && args.lines.length > 0) {\n const validRanges: Array<[number, number]> = [];\n for (const range of args.lines) {\n if (Array.isArray(range) && range.length >= 2 && isValidRange(range[0], range[1])) {\n validRanges.push([range[0], range[1]]);\n }\n }\n \n if (validRanges.length === 0) {\n const res = await provider.read({ path: args.path });\n if (res.error) return res.error;\n if (!res.lines.length) return '(empty file)';\n return res.lines.join('\\n');\n }\n \n const chunks: string[] = [];\n for (const [start, end] of validRanges) {\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\n const maxResults = args.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES;\n const initialDepth = args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;\n\n type DirectoryEntries = Awaited<ReturnType<typeof provider.listDirectory>>;\n async function getListRecursive(currentDepth: number): Promise<{ entries: DirectoryEntries; }> {\n const entries = await provider.listDirectory({\n path: args.path,\n pattern: args.pattern ?? null,\n maxResults,\n maxDepth: currentDepth,\n });\n\n if (entries.length >= maxResults && currentDepth > 0) {\n return getListRecursive(currentDepth - 1);\n }\n\n return { entries };\n }\n const { entries: list } = await getListRecursive(initialDepth);\n\n if (!list.length) return 'empty';\n if (list.length >= maxResults) {\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}","import type { FinishFileSpec } from '../types.js';\n\nfunction isValidRange(range: unknown): range is [number, number] {\n return (\n Array.isArray(range) &&\n range.length >= 2 &&\n typeof range[0] === 'number' &&\n typeof range[1] === 'number' &&\n Number.isFinite(range[0]) &&\n Number.isFinite(range[1]) &&\n range[0] > 0 &&\n range[1] >= range[0]\n );\n}\n\nfunction extractValidRanges(lines: unknown): Array<[number, number]> | null {\n if (!Array.isArray(lines)) return null;\n const valid: Array<[number, number]> = [];\n for (const range of lines) {\n if (isValidRange(range)) {\n valid.push([range[0], range[1]]);\n }\n }\n return valid.length > 0 ? valid : null;\n}\n\nexport function normalizeFinishFiles(files: FinishFileSpec[]): FinishFileSpec[] {\n return files.map((f) => {\n if (f.lines === '*') return { path: f.path, lines: '*' };\n const validRanges = extractValidRanges(f.lines);\n if (!validRanges) return { path: f.path, lines: '*' };\n return { path: f.path, lines: mergeRanges(validRanges) };\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 validRanges = f.lines === '*' ? null : extractValidRanges(f.lines);\n if (f.lines === '*' || !validRanges) {\n const lines = await reader(f.path);\n out.push({ path: f.path, ranges: '*', content: lines.join('\\n') });\n } else {\n const ranges = mergeRanges(validRanges);\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 }\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] = { role: 'user', content: TRUNCATED_MARKER };\n }\n }\n\n return messages;\n}\n\n"],"mappings":";;;;;AAEA,eAAsB,SACpB,UACA,MAC6B;AAC7B,QAAM,MAAM,MAAM,SAAS,KAAK,IAAI;AAGpC,MAAI,IAAI,OAAO;AACb,WAAO,EAAE,QAAQ,IAAI,MAAM;AAAA,EAC7B;AAEA,MAAI,CAAC,IAAI,MAAM,QAAQ;AACrB,WAAO,EAAE,QAAQ,aAAa;AAAA,EAChC;AAEA,SAAO,EAAE,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE;AACxC;;;AChBA,SAAS,aAAa,OAAgB,KAAuB;AAC3D,SACE,OAAO,UAAU,YACjB,OAAO,QAAQ,YACf,OAAO,SAAS,KAAK,KACrB,OAAO,SAAS,GAAG,KACnB,QAAQ,KACR,OAAO;AAEX;AAEA,eAAsB,SACpB,UACA,MACiB;AACjB,MAAI,KAAK,SAAS,MAAM,QAAQ,KAAK,KAAK,KAAK,KAAK,MAAM,SAAS,GAAG;AACpE,UAAM,cAAuC,CAAC;AAC9C,eAAW,SAAS,KAAK,OAAO;AAC9B,UAAI,MAAM,QAAQ,KAAK,KAAK,M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|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
toolGrep,
|
|
8
8
|
toolListDirectory,
|
|
9
9
|
toolRead
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-KRDIR7GG.js";
|
|
11
11
|
import {
|
|
12
12
|
formatAgentToolOutput
|
|
13
13
|
} from "./chunk-APP75CBN.js";
|
|
@@ -69,10 +69,15 @@ async function callModel(messages, model, options = {}) {
|
|
|
69
69
|
return content;
|
|
70
70
|
}
|
|
71
71
|
async function runWarpGrep(config) {
|
|
72
|
+
const totalStart = Date.now();
|
|
73
|
+
const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
74
|
+
const timings = { turns: [], timeout_ms: timeoutMs };
|
|
72
75
|
const repoRoot = path.resolve(config.repoRoot || process.cwd());
|
|
73
76
|
const messages = [];
|
|
74
77
|
messages.push({ role: "system", content: getSystemPrompt() });
|
|
78
|
+
const initialStateStart = Date.now();
|
|
75
79
|
const initialState = await buildInitialState(repoRoot, config.query, config.provider);
|
|
80
|
+
timings.initial_state_ms = Date.now() - initialStateStart;
|
|
76
81
|
messages.push({ role: "user", content: initialState });
|
|
77
82
|
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
78
83
|
const model = config.model || DEFAULT_MODEL;
|
|
@@ -81,22 +86,29 @@ async function runWarpGrep(config) {
|
|
|
81
86
|
let finishMeta;
|
|
82
87
|
let terminationReason = "terminated";
|
|
83
88
|
for (let turn = 1; turn <= maxTurns; turn += 1) {
|
|
89
|
+
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
84
90
|
enforceContextLimit(messages);
|
|
91
|
+
const modelCallStart = Date.now();
|
|
85
92
|
const assistantContent = await callModel(messages, model, {
|
|
86
93
|
morphApiKey: config.morphApiKey,
|
|
87
94
|
morphApiUrl: config.morphApiUrl,
|
|
88
95
|
retryConfig: config.retryConfig,
|
|
89
|
-
timeout:
|
|
96
|
+
timeout: timeoutMs
|
|
90
97
|
}).catch((e) => {
|
|
91
98
|
errors.push({ message: e instanceof Error ? e.message : String(e) });
|
|
92
99
|
return "";
|
|
93
100
|
});
|
|
94
|
-
|
|
101
|
+
turnMetrics.morph_api_ms = Date.now() - modelCallStart;
|
|
102
|
+
if (!assistantContent) {
|
|
103
|
+
timings.turns.push(turnMetrics);
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
95
106
|
messages.push({ role: "assistant", content: assistantContent });
|
|
96
107
|
const toolCalls = parser.parse(assistantContent);
|
|
97
108
|
if (toolCalls.length === 0) {
|
|
98
109
|
errors.push({ message: "No tool calls produced by the model. Your MCP is likely out of date! Update it by running: rm -rf ~/.npm/_npx && npm cache clean --force && npx -y @morphllm/morphmcp@latest" });
|
|
99
110
|
terminationReason = "terminated";
|
|
111
|
+
timings.turns.push(turnMetrics);
|
|
100
112
|
break;
|
|
101
113
|
}
|
|
102
114
|
const finishCalls = toolCalls.filter((c) => c.name === "finish");
|
|
@@ -137,7 +149,9 @@ async function runWarpGrep(config) {
|
|
|
137
149
|
)
|
|
138
150
|
);
|
|
139
151
|
}
|
|
152
|
+
const toolExecStart = Date.now();
|
|
140
153
|
const allResults = await Promise.all(allPromises);
|
|
154
|
+
turnMetrics.local_tools_ms = Date.now() - toolExecStart;
|
|
141
155
|
for (const result of allResults) {
|
|
142
156
|
formatted.push(result);
|
|
143
157
|
}
|
|
@@ -146,6 +160,7 @@ async function runWarpGrep(config) {
|
|
|
146
160
|
const contextBudget = calculateContextBudget(messages);
|
|
147
161
|
messages.push({ role: "user", content: formatted.join("\n") + turnMessage + "\n" + contextBudget });
|
|
148
162
|
}
|
|
163
|
+
timings.turns.push(turnMetrics);
|
|
149
164
|
if (finishCalls.length) {
|
|
150
165
|
const fc = finishCalls[0];
|
|
151
166
|
const files = fc.arguments?.files ?? [];
|
|
@@ -155,7 +170,8 @@ async function runWarpGrep(config) {
|
|
|
155
170
|
}
|
|
156
171
|
}
|
|
157
172
|
if (terminationReason !== "completed" || !finishMeta) {
|
|
158
|
-
|
|
173
|
+
timings.total_ms = Date.now() - totalStart;
|
|
174
|
+
return { terminationReason, messages, errors, timings };
|
|
159
175
|
}
|
|
160
176
|
const parts = ["Relevant context found:"];
|
|
161
177
|
for (const f of finishMeta.files) {
|
|
@@ -163,6 +179,7 @@ async function runWarpGrep(config) {
|
|
|
163
179
|
parts.push(`- ${f.path}: ${ranges}`);
|
|
164
180
|
}
|
|
165
181
|
const payload = parts.join("\n");
|
|
182
|
+
const finishResolutionStart = Date.now();
|
|
166
183
|
const fileReadErrors = [];
|
|
167
184
|
const resolved = await readFinishFiles(
|
|
168
185
|
repoRoot,
|
|
@@ -182,17 +199,20 @@ async function runWarpGrep(config) {
|
|
|
182
199
|
}
|
|
183
200
|
}
|
|
184
201
|
);
|
|
202
|
+
timings.finish_resolution_ms = Date.now() - finishResolutionStart;
|
|
185
203
|
if (fileReadErrors.length > 0) {
|
|
186
204
|
errors.push(...fileReadErrors.map((e) => ({ message: `File read error: ${e.path} - ${e.error}` })));
|
|
187
205
|
}
|
|
206
|
+
timings.total_ms = Date.now() - totalStart;
|
|
188
207
|
return {
|
|
189
208
|
terminationReason: "completed",
|
|
190
209
|
messages,
|
|
191
|
-
finish: { payload, metadata: finishMeta, resolved }
|
|
210
|
+
finish: { payload, metadata: finishMeta, resolved },
|
|
211
|
+
timings
|
|
192
212
|
};
|
|
193
213
|
}
|
|
194
214
|
|
|
195
215
|
export {
|
|
196
216
|
runWarpGrep
|
|
197
217
|
};
|
|
198
|
-
//# sourceMappingURL=chunk-
|
|
218
|
+
//# sourceMappingURL=chunk-LF2X6YNP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../tools/warp_grep/agent/runner.ts"],"sourcesContent":["import { AGENT_CONFIG, DEFAULT_MODEL } from './config.js';\nimport { getSystemPrompt } from './prompt.js';\nimport type { AgentRunResult, ChatMessage, SessionConfig, AgentFinish, WarpGrepExecutionMetrics, WarpGrepTurnMetrics } from './types.js';\nimport { LLMResponseParser } from './parser.js';\nimport type { WarpGrepProvider } from '../providers/types.js';\nimport { toolGrep } from './tools/grep.js';\nimport { toolRead } from './tools/read.js';\nimport { toolListDirectory } from './tools/list_directory.js';\nimport { readFinishFiles } from './tools/finish.js';\nimport { fetchWithRetry, withTimeout, type RetryConfig } from '../../utils/resilience.js';\nimport { formatAgentToolOutput } from './formatter.js';\nimport { formatTurnMessage, calculateContextBudget, buildInitialState, enforceContextLimit } from './helpers.js';\nimport path from 'path';\n\ntype EventName =\n | 'initial_state'\n | 'round_start'\n | 'round_end'\n | 'finish'\n | 'error';\n\nexport type EventCallback = (name: EventName, payload: Record<string, unknown>) => void;\n\nconst parser = new LLMResponseParser();\n\nconst DEFAULT_API_URL = 'https://api.morphllm.com';\n\ninterface CallModelOptions {\n morphApiKey?: string;\n morphApiUrl?: string;\n retryConfig?: RetryConfig;\n timeout?: number;\n}\n\nasync function callModel(\n messages: ChatMessage[],\n model: string,\n options: CallModelOptions = {}\n): Promise<string> {\n const baseUrl = options.morphApiUrl || DEFAULT_API_URL;\n const apiKey = options.morphApiKey || process.env.MORPH_API_KEY || '';\n \n const fetchPromise = fetchWithRetry(\n `${baseUrl}/v1/chat/completions`,\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey}`,\n },\n body: JSON.stringify({\n model,\n temperature: 0.0,\n max_tokens: 1024,\n messages,\n }),\n },\n options.retryConfig\n );\n const timeoutMs = options.timeout ?? AGENT_CONFIG.TIMEOUT_MS;\n const resp = await withTimeout(fetchPromise, timeoutMs, 'morph-warp-grep request timed out');\n if (!resp.ok) {\n if (resp.status === 404) {\n throw new Error(\n 'The endpoint you are trying to call is likely deprecated. Please update with: npm cache clean --force && npx -y @morphllm/morphmcp@latest or visit: https://morphllm.com/mcp'\n );\n }\n // keeping these cases are real throws, if this happens retry will likely not help, so best we just throw here, notice the error and fix\n const t = await resp.text();\n throw new Error(`morph-warp-grep error ${resp.status}: ${t}`);\n }\n const data = await resp.json();\n const content = data?.choices?.[0]?.message?.content;\n if (!content || typeof content !== 'string') {\n throw new Error('Invalid response from model');\n }\n return content;\n}\n\nexport async function runWarpGrep(config: SessionConfig & { provider: WarpGrepProvider }): Promise<AgentRunResult> {\n const totalStart = Date.now();\n const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;\n const timings: Partial<WarpGrepExecutionMetrics> = { turns: [], timeout_ms: timeoutMs };\n \n const repoRoot = path.resolve(config.repoRoot || process.cwd());\n const messages: ChatMessage[] = [];\n\n messages.push({ role: 'system' as const, content: getSystemPrompt() });\n \n const initialStateStart = Date.now();\n const initialState = await buildInitialState(repoRoot, config.query, config.provider);\n timings.initial_state_ms = Date.now() - initialStateStart;\n \n messages.push({ role: 'user', content: initialState });\n\n const maxTurns = AGENT_CONFIG.MAX_TURNS;\n const model = config.model || DEFAULT_MODEL;\n const provider = config.provider;\n const errors: Array<{ message: string }> = [];\n\n let finishMeta: AgentFinish | undefined;\n let terminationReason: AgentRunResult['terminationReason'] = 'terminated';\n\n for (let turn = 1; turn <= maxTurns; turn += 1) {\n const turnMetrics: WarpGrepTurnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };\n \n // Enforce hard context limit before calling model\n enforceContextLimit(messages);\n \n // call model\n const modelCallStart = Date.now();\n const assistantContent = await callModel(messages, model, {\n morphApiKey: config.morphApiKey,\n morphApiUrl: config.morphApiUrl,\n retryConfig: config.retryConfig,\n timeout: timeoutMs,\n }).catch((e: unknown) => {\n errors.push({ message: e instanceof Error ? e.message : String(e) });\n return '';\n });\n turnMetrics.morph_api_ms = Date.now() - modelCallStart;\n \n if (!assistantContent) {\n timings.turns!.push(turnMetrics);\n break;\n }\n messages.push({ role: 'assistant', content: assistantContent });\n\n // parse tool calls (no longer throws - returns _skip calls for malformed commands)\n const toolCalls = parser.parse(assistantContent);\n if (toolCalls.length === 0) {\n errors.push({ message: 'No tool calls produced by the model. Your MCP is likely out of date! Update it by running: rm -rf ~/.npm/_npx && npm cache clean --force && npx -y @morphllm/morphmcp@latest' });\n terminationReason = 'terminated';\n timings.turns!.push(turnMetrics);\n break;\n }\n\n const finishCalls = toolCalls.filter(c => c.name === 'finish');\n const grepCalls = toolCalls.filter(c => c.name === 'grep');\n const listDirCalls = toolCalls.filter(c => c.name === 'list_directory');\n const readCalls = toolCalls.filter(c => c.name === 'read');\n const skipCalls = toolCalls.filter(c => c.name === '_skip');\n\n const formatted: string[] = [];\n\n // Surface any skipped commands as feedback to the LLM\n for (const c of skipCalls) {\n const msg = (c.arguments as { message?: string })?.message || 'Command skipped due to parsing error';\n formatted.push(msg);\n }\n\n const allPromises: Array<Promise<string>> = [];\n \n for (const c of grepCalls) {\n const args = (c.arguments ?? {}) as { pattern: string; path: string; glob?: string };\n allPromises.push(\n toolGrep(provider, args).then(\n ({ output }) => formatAgentToolOutput('grep', args, output, { isError: false }),\n err => formatAgentToolOutput('grep', args, String(err), { isError: true })\n )\n );\n }\n \n for (const c of listDirCalls) {\n const args = (c.arguments ?? {}) as { path: string; pattern?: string | null };\n allPromises.push(\n toolListDirectory(provider, args).then(\n p => formatAgentToolOutput('list_directory', args, p, { isError: false }),\n err => formatAgentToolOutput('list_directory', args, String(err), { isError: true })\n )\n );\n }\n \n for (const c of readCalls) {\n const args = (c.arguments ?? {}) as { path: string; start?: number; end?: number; lines?: Array<[number, number]> };\n allPromises.push(\n toolRead(provider, args).then(\n p => formatAgentToolOutput('read', args, p, { isError: false }),\n err => formatAgentToolOutput('read', args, String(err), { isError: true })\n )\n );\n }\n \n const toolExecStart = Date.now();\n const allResults = await Promise.all(allPromises);\n turnMetrics.local_tools_ms = Date.now() - toolExecStart;\n \n for (const result of allResults) {\n formatted.push(result);\n }\n\n if (formatted.length > 0) {\n const turnMessage = formatTurnMessage(turn, maxTurns);\n const contextBudget = calculateContextBudget(messages);\n messages.push({ role: 'user', content: formatted.join('\\n') + turnMessage + '\\n' + contextBudget });\n }\n\n timings.turns!.push(turnMetrics);\n\n if (finishCalls.length) {\n const fc = finishCalls[0];\n const files = ((fc.arguments as any)?.files ?? []) as AgentFinish['files'];\n finishMeta = { files };\n terminationReason = 'completed';\n break;\n }\n }\n\n if (terminationReason !== 'completed' || !finishMeta) {\n timings.total_ms = Date.now() - totalStart;\n return { terminationReason, messages, errors, timings: timings as WarpGrepExecutionMetrics };\n }\n\n // Build finish payload\n const parts: string[] = ['Relevant context found:'];\n for (const f of finishMeta.files) {\n const ranges = f.lines === '*' ? '*' \n : Array.isArray(f.lines) ? f.lines.map(([s, e]) => `${s}-${e}`).join(', ') \n : '*';\n parts.push(`- ${f.path}: ${ranges}`);\n }\n const payload = parts.join('\\n');\n\n // Resolve file contents for returned ranges\n // Wrap reader in try-catch to handle non-existent or unreadable files gracefully\n // Track files that couldn't be read for error reporting\n const finishResolutionStart = Date.now();\n const fileReadErrors: Array<{ path: string; error: string }> = [];\n const resolved = await readFinishFiles(\n repoRoot,\n finishMeta.files,\n async (p: string, s?: number, e?: number) => {\n try {\n const rr = await provider.read({ path: p, start: s, end: e });\n // rr.lines are \"line|content\" → strip the \"line|\" prefix\n return rr.lines.map(l => {\n const idx = l.indexOf('|');\n return idx >= 0 ? l.slice(idx + 1) : l;\n });\n } catch (err) {\n // File doesn't exist or can't be read - log error but don't throw\n // This handles cases where the agent hallucinated a path or the file was deleted\n const errorMsg = err instanceof Error ? err.message : String(err);\n fileReadErrors.push({ path: p, error: errorMsg });\n console.error(`[warp_grep] Failed to read file: ${p} - ${errorMsg}`);\n return [`[couldn't find: ${p}]`];\n }\n }\n );\n\n timings.finish_resolution_ms = Date.now() - finishResolutionStart;\n\n // Add file read errors to the result so MCP can report them\n if (fileReadErrors.length > 0) {\n errors.push(...fileReadErrors.map(e => ({ message: `File read error: ${e.path} - ${e.error}` })));\n }\n\n timings.total_ms = Date.now() - totalStart;\n return {\n terminationReason: 'completed',\n messages,\n finish: { payload, metadata: finishMeta, resolved },\n timings: timings as WarpGrepExecutionMetrics,\n };\n}\n"],"mappings":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BAAyD,CAAC;AAChE,QAAM,WAAW,MAAM;AAAA,IACrB;AAAA,IACA,WAAW;AAAA,IACX,OAAO,GAAW,GAAY,MAAe;AAC3C,UAAI;AACF,cAAM,KAAK,MAAM,SAAS,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,EAAE,CAAC;AAE5D,eAAO,GAAG,MAAM,IAAI,OAAK;AACvB,gBAAM,MAAM,EAAE,QAAQ,GAAG;AACzB,iBAAO,OAAO,IAAI,EAAE,MAAM,MAAM,CAAC,IAAI;AAAA,QACvC,CAAC;AAAA,MACH,SAAS,KAAK;AAGZ,cAAM,WAAW,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAChE,uBAAe,KAAK,EAAE,MAAM,GAAG,OAAO,SAAS,CAAC;AAChD,gBAAQ,MAAM,oCAAoC,CAAC,MAAM,QAAQ,EAAE;AACnE,eAAO,CAAC,mBAAmB,CAAC,GAAG;AAAA,MACjC;AAAA,IACF;AAAA,EACF;AAEA,UAAQ,uBAAuB,KAAK,IAAI,IAAI;AAG5C,MAAI,eAAe,SAAS,GAAG;AAC7B,WAAO,KAAK,GAAG,eAAe,IAAI,QAAM,EAAE,SAAS,oBAAoB,EAAE,IAAI,MAAM,EAAE,KAAK,GAAG,EAAE,CAAC;AAAA,EAClG;AAEA,UAAQ,WAAW,KAAK,IAAI,IAAI;AAChC,SAAO;AAAA,IACL,mBAAmB;AAAA,IACnB;AAAA,IACA,QAAQ,EAAE,SAAS,UAAU,YAAY,SAAS;AAAA,IAClD;AAAA,EACF;AACF;","names":[]}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
executeToolCall,
|
|
7
7
|
formatResult
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-D4EQYM6O.js";
|
|
9
9
|
import {
|
|
10
10
|
getSystemPrompt
|
|
11
11
|
} from "./chunk-FMLHRJDF.js";
|
|
@@ -58,4 +58,4 @@ export {
|
|
|
58
58
|
createWarpGrepTool,
|
|
59
59
|
openai_default
|
|
60
60
|
};
|
|
61
|
-
//# sourceMappingURL=chunk-
|
|
61
|
+
//# sourceMappingURL=chunk-LX2WNS3L.js.map
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-KW7OEGZK.js";
|
|
4
4
|
import {
|
|
5
5
|
executeToolCall
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-D4EQYM6O.js";
|
|
7
7
|
|
|
8
8
|
// tools/warp_grep/vercel.ts
|
|
9
9
|
import { tool } from "ai";
|
|
@@ -38,4 +38,4 @@ export {
|
|
|
38
38
|
createWarpGrepTool,
|
|
39
39
|
vercel_default
|
|
40
40
|
};
|
|
41
|
-
//# sourceMappingURL=chunk-
|
|
41
|
+
//# sourceMappingURL=chunk-MJ7JODAY.js.map
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createWarpGrepTool as createWarpGrepTool2
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-262WRPS5.js";
|
|
4
4
|
import {
|
|
5
5
|
createWarpGrepTool
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-LX2WNS3L.js";
|
|
7
7
|
import {
|
|
8
8
|
createWarpGrepTool as createWarpGrepTool3
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-MJ7JODAY.js";
|
|
10
10
|
import {
|
|
11
11
|
WarpGrepClient
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-D4EQYM6O.js";
|
|
13
13
|
import {
|
|
14
14
|
createCodebaseSearchTool as createCodebaseSearchTool3
|
|
15
15
|
} from "./chunk-UBX7QYBD.js";
|
|
@@ -280,4 +280,4 @@ export {
|
|
|
280
280
|
VercelToolFactory,
|
|
281
281
|
MorphClient
|
|
282
282
|
};
|
|
283
|
-
//# sourceMappingURL=chunk-
|
|
283
|
+
//# sourceMappingURL=chunk-N3RNM4A4.js.map
|
package/dist/client.cjs
CHANGED
|
@@ -1597,14 +1597,23 @@ async function toolRead(provider, args) {
|
|
|
1597
1597
|
|
|
1598
1598
|
// tools/warp_grep/agent/tools/list_directory.ts
|
|
1599
1599
|
async function toolListDirectory(provider, args) {
|
|
1600
|
-
const
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1600
|
+
const maxResults = args.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES;
|
|
1601
|
+
const initialDepth = args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
1602
|
+
async function getListRecursive(currentDepth) {
|
|
1603
|
+
const entries = await provider.listDirectory({
|
|
1604
|
+
path: args.path,
|
|
1605
|
+
pattern: args.pattern ?? null,
|
|
1606
|
+
maxResults,
|
|
1607
|
+
maxDepth: currentDepth
|
|
1608
|
+
});
|
|
1609
|
+
if (entries.length >= maxResults && currentDepth > 0) {
|
|
1610
|
+
return getListRecursive(currentDepth - 1);
|
|
1611
|
+
}
|
|
1612
|
+
return { entries };
|
|
1613
|
+
}
|
|
1614
|
+
const { entries: list } = await getListRecursive(initialDepth);
|
|
1606
1615
|
if (!list.length) return "empty";
|
|
1607
|
-
if (list.length >=
|
|
1616
|
+
if (list.length >= maxResults) {
|
|
1608
1617
|
return "query not specific enough, tool called tried to return too much context and failed";
|
|
1609
1618
|
}
|
|
1610
1619
|
return list.map((e) => {
|
|
@@ -1882,10 +1891,15 @@ async function callModel(messages, model, options = {}) {
|
|
|
1882
1891
|
return content;
|
|
1883
1892
|
}
|
|
1884
1893
|
async function runWarpGrep(config) {
|
|
1894
|
+
const totalStart = Date.now();
|
|
1895
|
+
const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
1896
|
+
const timings = { turns: [], timeout_ms: timeoutMs };
|
|
1885
1897
|
const repoRoot = import_path3.default.resolve(config.repoRoot || process.cwd());
|
|
1886
1898
|
const messages = [];
|
|
1887
1899
|
messages.push({ role: "system", content: getSystemPrompt() });
|
|
1900
|
+
const initialStateStart = Date.now();
|
|
1888
1901
|
const initialState = await buildInitialState(repoRoot, config.query, config.provider);
|
|
1902
|
+
timings.initial_state_ms = Date.now() - initialStateStart;
|
|
1889
1903
|
messages.push({ role: "user", content: initialState });
|
|
1890
1904
|
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
1891
1905
|
const model = config.model || DEFAULT_MODEL;
|
|
@@ -1894,22 +1908,29 @@ async function runWarpGrep(config) {
|
|
|
1894
1908
|
let finishMeta;
|
|
1895
1909
|
let terminationReason = "terminated";
|
|
1896
1910
|
for (let turn = 1; turn <= maxTurns; turn += 1) {
|
|
1911
|
+
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
1897
1912
|
enforceContextLimit(messages);
|
|
1913
|
+
const modelCallStart = Date.now();
|
|
1898
1914
|
const assistantContent = await callModel(messages, model, {
|
|
1899
1915
|
morphApiKey: config.morphApiKey,
|
|
1900
1916
|
morphApiUrl: config.morphApiUrl,
|
|
1901
1917
|
retryConfig: config.retryConfig,
|
|
1902
|
-
timeout:
|
|
1918
|
+
timeout: timeoutMs
|
|
1903
1919
|
}).catch((e) => {
|
|
1904
1920
|
errors.push({ message: e instanceof Error ? e.message : String(e) });
|
|
1905
1921
|
return "";
|
|
1906
1922
|
});
|
|
1907
|
-
|
|
1923
|
+
turnMetrics.morph_api_ms = Date.now() - modelCallStart;
|
|
1924
|
+
if (!assistantContent) {
|
|
1925
|
+
timings.turns.push(turnMetrics);
|
|
1926
|
+
break;
|
|
1927
|
+
}
|
|
1908
1928
|
messages.push({ role: "assistant", content: assistantContent });
|
|
1909
1929
|
const toolCalls = parser.parse(assistantContent);
|
|
1910
1930
|
if (toolCalls.length === 0) {
|
|
1911
1931
|
errors.push({ message: "No tool calls produced by the model. Your MCP is likely out of date! Update it by running: rm -rf ~/.npm/_npx && npm cache clean --force && npx -y @morphllm/morphmcp@latest" });
|
|
1912
1932
|
terminationReason = "terminated";
|
|
1933
|
+
timings.turns.push(turnMetrics);
|
|
1913
1934
|
break;
|
|
1914
1935
|
}
|
|
1915
1936
|
const finishCalls = toolCalls.filter((c) => c.name === "finish");
|
|
@@ -1950,7 +1971,9 @@ async function runWarpGrep(config) {
|
|
|
1950
1971
|
)
|
|
1951
1972
|
);
|
|
1952
1973
|
}
|
|
1974
|
+
const toolExecStart = Date.now();
|
|
1953
1975
|
const allResults = await Promise.all(allPromises);
|
|
1976
|
+
turnMetrics.local_tools_ms = Date.now() - toolExecStart;
|
|
1954
1977
|
for (const result of allResults) {
|
|
1955
1978
|
formatted.push(result);
|
|
1956
1979
|
}
|
|
@@ -1959,6 +1982,7 @@ async function runWarpGrep(config) {
|
|
|
1959
1982
|
const contextBudget = calculateContextBudget(messages);
|
|
1960
1983
|
messages.push({ role: "user", content: formatted.join("\n") + turnMessage + "\n" + contextBudget });
|
|
1961
1984
|
}
|
|
1985
|
+
timings.turns.push(turnMetrics);
|
|
1962
1986
|
if (finishCalls.length) {
|
|
1963
1987
|
const fc = finishCalls[0];
|
|
1964
1988
|
const files = fc.arguments?.files ?? [];
|
|
@@ -1968,7 +1992,8 @@ async function runWarpGrep(config) {
|
|
|
1968
1992
|
}
|
|
1969
1993
|
}
|
|
1970
1994
|
if (terminationReason !== "completed" || !finishMeta) {
|
|
1971
|
-
|
|
1995
|
+
timings.total_ms = Date.now() - totalStart;
|
|
1996
|
+
return { terminationReason, messages, errors, timings };
|
|
1972
1997
|
}
|
|
1973
1998
|
const parts = ["Relevant context found:"];
|
|
1974
1999
|
for (const f of finishMeta.files) {
|
|
@@ -1976,6 +2001,7 @@ async function runWarpGrep(config) {
|
|
|
1976
2001
|
parts.push(`- ${f.path}: ${ranges}`);
|
|
1977
2002
|
}
|
|
1978
2003
|
const payload = parts.join("\n");
|
|
2004
|
+
const finishResolutionStart = Date.now();
|
|
1979
2005
|
const fileReadErrors = [];
|
|
1980
2006
|
const resolved = await readFinishFiles(
|
|
1981
2007
|
repoRoot,
|
|
@@ -1995,13 +2021,16 @@ async function runWarpGrep(config) {
|
|
|
1995
2021
|
}
|
|
1996
2022
|
}
|
|
1997
2023
|
);
|
|
2024
|
+
timings.finish_resolution_ms = Date.now() - finishResolutionStart;
|
|
1998
2025
|
if (fileReadErrors.length > 0) {
|
|
1999
2026
|
errors.push(...fileReadErrors.map((e) => ({ message: `File read error: ${e.path} - ${e.error}` })));
|
|
2000
2027
|
}
|
|
2028
|
+
timings.total_ms = Date.now() - totalStart;
|
|
2001
2029
|
return {
|
|
2002
2030
|
terminationReason: "completed",
|
|
2003
2031
|
messages,
|
|
2004
|
-
finish: { payload, metadata: finishMeta, resolved }
|
|
2032
|
+
finish: { payload, metadata: finishMeta, resolved },
|
|
2033
|
+
timings
|
|
2005
2034
|
};
|
|
2006
2035
|
}
|
|
2007
2036
|
|