@morphllm/morphsdk 0.2.83 → 0.2.85
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-HRK53IKL.js → chunk-37SJ3IOY.js} +63 -42
- package/dist/chunk-37SJ3IOY.js.map +1 -0
- package/dist/{chunk-S27A4NQM.js → chunk-5X7IJXKA.js} +2 -2
- package/dist/{chunk-RL4JBZ3T.js → chunk-AJEE5RRB.js} +2 -2
- package/dist/{chunk-QOYI77CN.js → chunk-HJOMBO2A.js} +154 -3
- package/dist/chunk-HJOMBO2A.js.map +1 -0
- package/dist/{chunk-LXG37353.js → chunk-IXNX4HMC.js} +2 -2
- package/dist/{chunk-P2O5JKE5.js → chunk-KRDIR7GG.js} +17 -8
- package/dist/chunk-KRDIR7GG.js.map +1 -0
- package/dist/{chunk-FY32COVL.js → chunk-L5C6E32T.js} +1 -1
- package/dist/{chunk-FY32COVL.js.map → chunk-L5C6E32T.js.map} +1 -1
- package/dist/{chunk-HPR6BJA7.js → chunk-SQF3OG24.js} +5 -5
- package/dist/{client-CsO9LifG.d.ts → client-Drz3OGq-.d.ts} +1 -1
- package/dist/client.cjs +220 -44
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +3 -2
- package/dist/client.js +7 -7
- package/dist/index.cjs +220 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +8 -8
- package/dist/tools/warp_grep/agent/runner.cjs +170 -9
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.d.ts +9 -2
- package/dist/tools/warp_grep/agent/runner.js +6 -4
- package/dist/tools/warp_grep/agent/types.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/types.d.ts +12 -1
- package/dist/tools/warp_grep/anthropic.cjs +16 -7
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.d.ts +3 -2
- package/dist/tools/warp_grep/anthropic.js +4 -4
- package/dist/tools/warp_grep/client.cjs +225 -46
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.d.ts +39 -6
- package/dist/tools/warp_grep/client.js +3 -3
- package/dist/tools/warp_grep/gemini.cjs +16 -7
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.d.ts +3 -2
- 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 +227 -46
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.d.ts +3 -3
- package/dist/tools/warp_grep/index.js +7 -5
- package/dist/tools/warp_grep/openai.cjs +16 -7
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.d.ts +3 -2
- package/dist/tools/warp_grep/openai.js +4 -4
- package/dist/tools/warp_grep/providers/remote.d.ts +1 -1
- package/dist/tools/warp_grep/vercel.cjs +16 -7
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.d.ts +2 -1
- package/dist/tools/warp_grep/vercel.js +4 -4
- package/dist/{types-Cv4LpqVl.d.ts → types-BMowL9iZ.d.ts} +5 -0
- package/package.json +1 -1
- package/dist/chunk-HRK53IKL.js.map +0 -1
- package/dist/chunk-P2O5JKE5.js.map +0 -1
- package/dist/chunk-QOYI77CN.js.map +0 -1
- /package/dist/{chunk-S27A4NQM.js.map → chunk-5X7IJXKA.js.map} +0 -0
- /package/dist/{chunk-RL4JBZ3T.js.map → chunk-AJEE5RRB.js.map} +0 -0
- /package/dist/{chunk-LXG37353.js.map → chunk-IXNX4HMC.js.map} +0 -0
- /package/dist/{chunk-HPR6BJA7.js.map → chunk-SQF3OG24.js.map} +0 -0
|
@@ -44,6 +44,7 @@ __export(warp_grep_exports, {
|
|
|
44
44
|
normalizeFinishFiles: () => normalizeFinishFiles,
|
|
45
45
|
readFinishFiles: () => readFinishFiles,
|
|
46
46
|
runWarpGrep: () => runWarpGrep,
|
|
47
|
+
runWarpGrepStreaming: () => runWarpGrepStreaming,
|
|
47
48
|
toolGrep: () => toolGrep,
|
|
48
49
|
toolListDirectory: () => toolListDirectory,
|
|
49
50
|
toolRead: () => toolRead,
|
|
@@ -663,14 +664,23 @@ async function toolRead(provider, args) {
|
|
|
663
664
|
|
|
664
665
|
// tools/warp_grep/agent/tools/list_directory.ts
|
|
665
666
|
async function toolListDirectory(provider, args) {
|
|
666
|
-
const
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
667
|
+
const maxResults = args.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES;
|
|
668
|
+
const initialDepth = args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
669
|
+
async function getListRecursive(currentDepth) {
|
|
670
|
+
const entries = await provider.listDirectory({
|
|
671
|
+
path: args.path,
|
|
672
|
+
pattern: args.pattern ?? null,
|
|
673
|
+
maxResults,
|
|
674
|
+
maxDepth: currentDepth
|
|
675
|
+
});
|
|
676
|
+
if (entries.length >= maxResults && currentDepth > 0) {
|
|
677
|
+
return getListRecursive(currentDepth - 1);
|
|
678
|
+
}
|
|
679
|
+
return { entries };
|
|
680
|
+
}
|
|
681
|
+
const { entries: list } = await getListRecursive(initialDepth);
|
|
672
682
|
if (!list.length) return "empty";
|
|
673
|
-
if (list.length >=
|
|
683
|
+
if (list.length >= maxResults) {
|
|
674
684
|
return "query not specific enough, tool called tried to return too much context and failed";
|
|
675
685
|
}
|
|
676
686
|
return list.map((e) => {
|
|
@@ -1172,6 +1182,156 @@ async function runWarpGrep(config) {
|
|
|
1172
1182
|
timings
|
|
1173
1183
|
};
|
|
1174
1184
|
}
|
|
1185
|
+
async function* runWarpGrepStreaming(config) {
|
|
1186
|
+
const totalStart = Date.now();
|
|
1187
|
+
const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
1188
|
+
const timings = { turns: [], timeout_ms: timeoutMs };
|
|
1189
|
+
const repoRoot = import_path2.default.resolve(config.repoRoot || process.cwd());
|
|
1190
|
+
const messages = [];
|
|
1191
|
+
messages.push({ role: "system", content: getSystemPrompt() });
|
|
1192
|
+
const initialStateStart = Date.now();
|
|
1193
|
+
const initialState = await buildInitialState(repoRoot, config.query, config.provider);
|
|
1194
|
+
timings.initial_state_ms = Date.now() - initialStateStart;
|
|
1195
|
+
messages.push({ role: "user", content: initialState });
|
|
1196
|
+
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
1197
|
+
const model = config.model || DEFAULT_MODEL;
|
|
1198
|
+
const provider = config.provider;
|
|
1199
|
+
const errors = [];
|
|
1200
|
+
let finishMeta;
|
|
1201
|
+
let terminationReason = "terminated";
|
|
1202
|
+
for (let turn = 1; turn <= maxTurns; turn += 1) {
|
|
1203
|
+
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
1204
|
+
enforceContextLimit(messages);
|
|
1205
|
+
const modelCallStart = Date.now();
|
|
1206
|
+
const assistantContent = await callModel(messages, model, {
|
|
1207
|
+
morphApiKey: config.morphApiKey,
|
|
1208
|
+
morphApiUrl: config.morphApiUrl,
|
|
1209
|
+
retryConfig: config.retryConfig,
|
|
1210
|
+
timeout: timeoutMs
|
|
1211
|
+
}).catch((e) => {
|
|
1212
|
+
errors.push({ message: e instanceof Error ? e.message : String(e) });
|
|
1213
|
+
return "";
|
|
1214
|
+
});
|
|
1215
|
+
turnMetrics.morph_api_ms = Date.now() - modelCallStart;
|
|
1216
|
+
if (!assistantContent) {
|
|
1217
|
+
timings.turns.push(turnMetrics);
|
|
1218
|
+
break;
|
|
1219
|
+
}
|
|
1220
|
+
messages.push({ role: "assistant", content: assistantContent });
|
|
1221
|
+
const toolCalls = parser.parse(assistantContent);
|
|
1222
|
+
if (toolCalls.length === 0) {
|
|
1223
|
+
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" });
|
|
1224
|
+
terminationReason = "terminated";
|
|
1225
|
+
timings.turns.push(turnMetrics);
|
|
1226
|
+
break;
|
|
1227
|
+
}
|
|
1228
|
+
yield {
|
|
1229
|
+
turn,
|
|
1230
|
+
toolCalls: toolCalls.map((c) => ({
|
|
1231
|
+
name: c.name,
|
|
1232
|
+
arguments: c.arguments ?? {}
|
|
1233
|
+
}))
|
|
1234
|
+
};
|
|
1235
|
+
const finishCalls = toolCalls.filter((c) => c.name === "finish");
|
|
1236
|
+
const grepCalls = toolCalls.filter((c) => c.name === "grep");
|
|
1237
|
+
const listDirCalls = toolCalls.filter((c) => c.name === "list_directory");
|
|
1238
|
+
const readCalls = toolCalls.filter((c) => c.name === "read");
|
|
1239
|
+
const skipCalls = toolCalls.filter((c) => c.name === "_skip");
|
|
1240
|
+
const formatted = [];
|
|
1241
|
+
for (const c of skipCalls) {
|
|
1242
|
+
const msg = c.arguments?.message || "Command skipped due to parsing error";
|
|
1243
|
+
formatted.push(msg);
|
|
1244
|
+
}
|
|
1245
|
+
const allPromises = [];
|
|
1246
|
+
for (const c of grepCalls) {
|
|
1247
|
+
const args = c.arguments ?? {};
|
|
1248
|
+
allPromises.push(
|
|
1249
|
+
toolGrep(provider, args).then(
|
|
1250
|
+
({ output }) => formatAgentToolOutput("grep", args, output, { isError: false }),
|
|
1251
|
+
(err) => formatAgentToolOutput("grep", args, String(err), { isError: true })
|
|
1252
|
+
)
|
|
1253
|
+
);
|
|
1254
|
+
}
|
|
1255
|
+
for (const c of listDirCalls) {
|
|
1256
|
+
const args = c.arguments ?? {};
|
|
1257
|
+
allPromises.push(
|
|
1258
|
+
toolListDirectory(provider, args).then(
|
|
1259
|
+
(p) => formatAgentToolOutput("list_directory", args, p, { isError: false }),
|
|
1260
|
+
(err) => formatAgentToolOutput("list_directory", args, String(err), { isError: true })
|
|
1261
|
+
)
|
|
1262
|
+
);
|
|
1263
|
+
}
|
|
1264
|
+
for (const c of readCalls) {
|
|
1265
|
+
const args = c.arguments ?? {};
|
|
1266
|
+
allPromises.push(
|
|
1267
|
+
toolRead(provider, args).then(
|
|
1268
|
+
(p) => formatAgentToolOutput("read", args, p, { isError: false }),
|
|
1269
|
+
(err) => formatAgentToolOutput("read", args, String(err), { isError: true })
|
|
1270
|
+
)
|
|
1271
|
+
);
|
|
1272
|
+
}
|
|
1273
|
+
const toolExecStart = Date.now();
|
|
1274
|
+
const allResults = await Promise.all(allPromises);
|
|
1275
|
+
turnMetrics.local_tools_ms = Date.now() - toolExecStart;
|
|
1276
|
+
for (const result of allResults) {
|
|
1277
|
+
formatted.push(result);
|
|
1278
|
+
}
|
|
1279
|
+
if (formatted.length > 0) {
|
|
1280
|
+
const turnMessage = formatTurnMessage(turn, maxTurns);
|
|
1281
|
+
const contextBudget = calculateContextBudget(messages);
|
|
1282
|
+
messages.push({ role: "user", content: formatted.join("\n") + turnMessage + "\n" + contextBudget });
|
|
1283
|
+
}
|
|
1284
|
+
timings.turns.push(turnMetrics);
|
|
1285
|
+
if (finishCalls.length) {
|
|
1286
|
+
const fc = finishCalls[0];
|
|
1287
|
+
const files = fc.arguments?.files ?? [];
|
|
1288
|
+
finishMeta = { files };
|
|
1289
|
+
terminationReason = "completed";
|
|
1290
|
+
break;
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
if (terminationReason !== "completed" || !finishMeta) {
|
|
1294
|
+
timings.total_ms = Date.now() - totalStart;
|
|
1295
|
+
return { terminationReason, messages, errors, timings };
|
|
1296
|
+
}
|
|
1297
|
+
const parts = ["Relevant context found:"];
|
|
1298
|
+
for (const f of finishMeta.files) {
|
|
1299
|
+
const ranges = f.lines === "*" ? "*" : Array.isArray(f.lines) ? f.lines.map(([s, e]) => `${s}-${e}`).join(", ") : "*";
|
|
1300
|
+
parts.push(`- ${f.path}: ${ranges}`);
|
|
1301
|
+
}
|
|
1302
|
+
const payload = parts.join("\n");
|
|
1303
|
+
const finishResolutionStart = Date.now();
|
|
1304
|
+
const fileReadErrors = [];
|
|
1305
|
+
const resolved = await readFinishFiles(
|
|
1306
|
+
repoRoot,
|
|
1307
|
+
finishMeta.files,
|
|
1308
|
+
async (p, s, e) => {
|
|
1309
|
+
try {
|
|
1310
|
+
const rr = await provider.read({ path: p, start: s, end: e });
|
|
1311
|
+
return rr.lines.map((l) => {
|
|
1312
|
+
const idx = l.indexOf("|");
|
|
1313
|
+
return idx >= 0 ? l.slice(idx + 1) : l;
|
|
1314
|
+
});
|
|
1315
|
+
} catch (err) {
|
|
1316
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
1317
|
+
fileReadErrors.push({ path: p, error: errorMsg });
|
|
1318
|
+
console.error(`[warp_grep] Failed to read file: ${p} - ${errorMsg}`);
|
|
1319
|
+
return [`[couldn't find: ${p}]`];
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
);
|
|
1323
|
+
timings.finish_resolution_ms = Date.now() - finishResolutionStart;
|
|
1324
|
+
if (fileReadErrors.length > 0) {
|
|
1325
|
+
errors.push(...fileReadErrors.map((e) => ({ message: `File read error: ${e.path} - ${e.error}` })));
|
|
1326
|
+
}
|
|
1327
|
+
timings.total_ms = Date.now() - totalStart;
|
|
1328
|
+
return {
|
|
1329
|
+
terminationReason: "completed",
|
|
1330
|
+
messages,
|
|
1331
|
+
finish: { payload, metadata: finishMeta, resolved },
|
|
1332
|
+
timings
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1175
1335
|
|
|
1176
1336
|
// tools/warp_grep/providers/local.ts
|
|
1177
1337
|
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
@@ -1765,48 +1925,31 @@ var WarpGrepClient = class {
|
|
|
1765
1925
|
retryConfig: config.retryConfig
|
|
1766
1926
|
};
|
|
1767
1927
|
}
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
* }
|
|
1786
|
-
* }
|
|
1787
|
-
* ```
|
|
1788
|
-
*/
|
|
1789
|
-
async execute(input) {
|
|
1790
|
-
return executeToolCall(
|
|
1791
|
-
{ query: input.query },
|
|
1792
|
-
{
|
|
1793
|
-
repoRoot: input.repoRoot,
|
|
1794
|
-
remoteCommands: input.remoteCommands,
|
|
1795
|
-
provider: input.provider,
|
|
1796
|
-
excludes: input.excludes,
|
|
1797
|
-
includes: input.includes,
|
|
1798
|
-
debug: input.debug ?? this.config.debug,
|
|
1799
|
-
morphApiKey: this.config.morphApiKey,
|
|
1800
|
-
morphApiUrl: this.config.morphApiUrl,
|
|
1801
|
-
retryConfig: this.config.retryConfig,
|
|
1802
|
-
timeout: this.config.timeout
|
|
1803
|
-
}
|
|
1804
|
-
);
|
|
1928
|
+
execute(input) {
|
|
1929
|
+
const toolConfig = {
|
|
1930
|
+
repoRoot: input.repoRoot,
|
|
1931
|
+
remoteCommands: input.remoteCommands,
|
|
1932
|
+
provider: input.provider,
|
|
1933
|
+
excludes: input.excludes,
|
|
1934
|
+
includes: input.includes,
|
|
1935
|
+
debug: input.debug ?? this.config.debug,
|
|
1936
|
+
morphApiKey: this.config.morphApiKey,
|
|
1937
|
+
morphApiUrl: this.config.morphApiUrl,
|
|
1938
|
+
retryConfig: this.config.retryConfig,
|
|
1939
|
+
timeout: this.config.timeout
|
|
1940
|
+
};
|
|
1941
|
+
if (input.streamSteps) {
|
|
1942
|
+
return executeToolCallStreaming({ query: input.query }, toolConfig);
|
|
1943
|
+
}
|
|
1944
|
+
return executeToolCall({ query: input.query }, toolConfig);
|
|
1805
1945
|
}
|
|
1806
1946
|
};
|
|
1807
|
-
|
|
1947
|
+
function executeWarpGrep(input, config) {
|
|
1808
1948
|
const client = new WarpGrepClient(config);
|
|
1809
|
-
|
|
1949
|
+
if (input.streamSteps) {
|
|
1950
|
+
return client.execute({ ...input, streamSteps: true });
|
|
1951
|
+
}
|
|
1952
|
+
return client.execute({ ...input, streamSteps: false });
|
|
1810
1953
|
}
|
|
1811
1954
|
async function executeToolCall(input, config) {
|
|
1812
1955
|
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
@@ -1833,6 +1976,43 @@ async function executeToolCall(input, config) {
|
|
|
1833
1976
|
}));
|
|
1834
1977
|
return { success: true, contexts, summary: finish.payload };
|
|
1835
1978
|
}
|
|
1979
|
+
function processAgentResult(result) {
|
|
1980
|
+
const finish = result.finish;
|
|
1981
|
+
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
1982
|
+
return { success: false, error: "Search did not complete" };
|
|
1983
|
+
}
|
|
1984
|
+
const contexts = (finish.resolved ?? []).map((r) => ({
|
|
1985
|
+
file: r.path,
|
|
1986
|
+
content: r.content
|
|
1987
|
+
}));
|
|
1988
|
+
return { success: true, contexts, summary: finish.payload };
|
|
1989
|
+
}
|
|
1990
|
+
async function* executeToolCallStreaming(input, config) {
|
|
1991
|
+
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
1992
|
+
const provider = config.remoteCommands ? new RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ?? new LocalRipgrepProvider(config.repoRoot, config.excludes);
|
|
1993
|
+
const generator = runWarpGrepStreaming({
|
|
1994
|
+
query: parsed.query,
|
|
1995
|
+
repoRoot: config.repoRoot,
|
|
1996
|
+
provider,
|
|
1997
|
+
excludes: config.excludes,
|
|
1998
|
+
includes: config.includes,
|
|
1999
|
+
debug: config.debug ?? false,
|
|
2000
|
+
morphApiKey: config.morphApiKey,
|
|
2001
|
+
morphApiUrl: config.morphApiUrl,
|
|
2002
|
+
retryConfig: config.retryConfig,
|
|
2003
|
+
timeout: config.timeout
|
|
2004
|
+
});
|
|
2005
|
+
let agentResult;
|
|
2006
|
+
for (; ; ) {
|
|
2007
|
+
const { value, done } = await generator.next();
|
|
2008
|
+
if (done) {
|
|
2009
|
+
agentResult = value;
|
|
2010
|
+
break;
|
|
2011
|
+
}
|
|
2012
|
+
yield value;
|
|
2013
|
+
}
|
|
2014
|
+
return processAgentResult(agentResult);
|
|
2015
|
+
}
|
|
1836
2016
|
function formatResult(result) {
|
|
1837
2017
|
if (!result.success) {
|
|
1838
2018
|
return `Search failed: ${result.error}`;
|
|
@@ -1880,6 +2060,7 @@ var warpGrepInputSchema = import_zod.z.object({
|
|
|
1880
2060
|
normalizeFinishFiles,
|
|
1881
2061
|
readFinishFiles,
|
|
1882
2062
|
runWarpGrep,
|
|
2063
|
+
runWarpGrepStreaming,
|
|
1883
2064
|
toolGrep,
|
|
1884
2065
|
toolListDirectory,
|
|
1885
2066
|
toolRead,
|