@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
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Tool } from '@anthropic-ai/sdk/resources/messages';
|
|
2
2
|
export { formatResult } from './client.js';
|
|
3
3
|
export { getSystemPrompt } from './agent/prompt.js';
|
|
4
|
-
import { d as WarpGrepToolConfig, b as WarpGrepResult } from '../../types-
|
|
5
|
-
import './
|
|
4
|
+
import { d as WarpGrepToolConfig, b as WarpGrepResult } from '../../types-BMowL9iZ.js';
|
|
5
|
+
import './agent/types.js';
|
|
6
6
|
import '../utils/resilience.js';
|
|
7
|
+
import './providers/types.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Anthropic SDK adapter for morph-warp-grep tool
|
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
createWarpGrepTool,
|
|
3
3
|
execute,
|
|
4
4
|
warpGrepTool
|
|
5
|
-
} from "../../chunk-
|
|
5
|
+
} from "../../chunk-AJEE5RRB.js";
|
|
6
6
|
import "../../chunk-KW7OEGZK.js";
|
|
7
7
|
import {
|
|
8
8
|
formatResult
|
|
9
|
-
} from "../../chunk-
|
|
10
|
-
import "../../chunk-
|
|
9
|
+
} from "../../chunk-37SJ3IOY.js";
|
|
10
|
+
import "../../chunk-HJOMBO2A.js";
|
|
11
11
|
import "../../chunk-PUGSTXLO.js";
|
|
12
|
-
import "../../chunk-
|
|
12
|
+
import "../../chunk-KRDIR7GG.js";
|
|
13
13
|
import "../../chunk-APP75CBN.js";
|
|
14
14
|
import "../../chunk-5QRN3JNB.js";
|
|
15
15
|
import {
|
|
@@ -648,14 +648,23 @@ async function toolRead(provider, args) {
|
|
|
648
648
|
|
|
649
649
|
// tools/warp_grep/agent/tools/list_directory.ts
|
|
650
650
|
async function toolListDirectory(provider, args) {
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
651
|
+
const maxResults = args.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES;
|
|
652
|
+
const initialDepth = args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
653
|
+
async function getListRecursive(currentDepth) {
|
|
654
|
+
const entries = await provider.listDirectory({
|
|
655
|
+
path: args.path,
|
|
656
|
+
pattern: args.pattern ?? null,
|
|
657
|
+
maxResults,
|
|
658
|
+
maxDepth: currentDepth
|
|
659
|
+
});
|
|
660
|
+
if (entries.length >= maxResults && currentDepth > 0) {
|
|
661
|
+
return getListRecursive(currentDepth - 1);
|
|
662
|
+
}
|
|
663
|
+
return { entries };
|
|
664
|
+
}
|
|
665
|
+
const { entries: list } = await getListRecursive(initialDepth);
|
|
657
666
|
if (!list.length) return "empty";
|
|
658
|
-
if (list.length >=
|
|
667
|
+
if (list.length >= maxResults) {
|
|
659
668
|
return "query not specific enough, tool called tried to return too much context and failed";
|
|
660
669
|
}
|
|
661
670
|
return list.map((e) => {
|
|
@@ -1149,6 +1158,156 @@ async function runWarpGrep(config) {
|
|
|
1149
1158
|
timings
|
|
1150
1159
|
};
|
|
1151
1160
|
}
|
|
1161
|
+
async function* runWarpGrepStreaming(config) {
|
|
1162
|
+
const totalStart = Date.now();
|
|
1163
|
+
const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
1164
|
+
const timings = { turns: [], timeout_ms: timeoutMs };
|
|
1165
|
+
const repoRoot = import_path2.default.resolve(config.repoRoot || process.cwd());
|
|
1166
|
+
const messages = [];
|
|
1167
|
+
messages.push({ role: "system", content: getSystemPrompt() });
|
|
1168
|
+
const initialStateStart = Date.now();
|
|
1169
|
+
const initialState = await buildInitialState(repoRoot, config.query, config.provider);
|
|
1170
|
+
timings.initial_state_ms = Date.now() - initialStateStart;
|
|
1171
|
+
messages.push({ role: "user", content: initialState });
|
|
1172
|
+
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
1173
|
+
const model = config.model || DEFAULT_MODEL;
|
|
1174
|
+
const provider = config.provider;
|
|
1175
|
+
const errors = [];
|
|
1176
|
+
let finishMeta;
|
|
1177
|
+
let terminationReason = "terminated";
|
|
1178
|
+
for (let turn = 1; turn <= maxTurns; turn += 1) {
|
|
1179
|
+
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
1180
|
+
enforceContextLimit(messages);
|
|
1181
|
+
const modelCallStart = Date.now();
|
|
1182
|
+
const assistantContent = await callModel(messages, model, {
|
|
1183
|
+
morphApiKey: config.morphApiKey,
|
|
1184
|
+
morphApiUrl: config.morphApiUrl,
|
|
1185
|
+
retryConfig: config.retryConfig,
|
|
1186
|
+
timeout: timeoutMs
|
|
1187
|
+
}).catch((e) => {
|
|
1188
|
+
errors.push({ message: e instanceof Error ? e.message : String(e) });
|
|
1189
|
+
return "";
|
|
1190
|
+
});
|
|
1191
|
+
turnMetrics.morph_api_ms = Date.now() - modelCallStart;
|
|
1192
|
+
if (!assistantContent) {
|
|
1193
|
+
timings.turns.push(turnMetrics);
|
|
1194
|
+
break;
|
|
1195
|
+
}
|
|
1196
|
+
messages.push({ role: "assistant", content: assistantContent });
|
|
1197
|
+
const toolCalls = parser.parse(assistantContent);
|
|
1198
|
+
if (toolCalls.length === 0) {
|
|
1199
|
+
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" });
|
|
1200
|
+
terminationReason = "terminated";
|
|
1201
|
+
timings.turns.push(turnMetrics);
|
|
1202
|
+
break;
|
|
1203
|
+
}
|
|
1204
|
+
yield {
|
|
1205
|
+
turn,
|
|
1206
|
+
toolCalls: toolCalls.map((c) => ({
|
|
1207
|
+
name: c.name,
|
|
1208
|
+
arguments: c.arguments ?? {}
|
|
1209
|
+
}))
|
|
1210
|
+
};
|
|
1211
|
+
const finishCalls = toolCalls.filter((c) => c.name === "finish");
|
|
1212
|
+
const grepCalls = toolCalls.filter((c) => c.name === "grep");
|
|
1213
|
+
const listDirCalls = toolCalls.filter((c) => c.name === "list_directory");
|
|
1214
|
+
const readCalls = toolCalls.filter((c) => c.name === "read");
|
|
1215
|
+
const skipCalls = toolCalls.filter((c) => c.name === "_skip");
|
|
1216
|
+
const formatted = [];
|
|
1217
|
+
for (const c of skipCalls) {
|
|
1218
|
+
const msg = c.arguments?.message || "Command skipped due to parsing error";
|
|
1219
|
+
formatted.push(msg);
|
|
1220
|
+
}
|
|
1221
|
+
const allPromises = [];
|
|
1222
|
+
for (const c of grepCalls) {
|
|
1223
|
+
const args = c.arguments ?? {};
|
|
1224
|
+
allPromises.push(
|
|
1225
|
+
toolGrep(provider, args).then(
|
|
1226
|
+
({ output }) => formatAgentToolOutput("grep", args, output, { isError: false }),
|
|
1227
|
+
(err) => formatAgentToolOutput("grep", args, String(err), { isError: true })
|
|
1228
|
+
)
|
|
1229
|
+
);
|
|
1230
|
+
}
|
|
1231
|
+
for (const c of listDirCalls) {
|
|
1232
|
+
const args = c.arguments ?? {};
|
|
1233
|
+
allPromises.push(
|
|
1234
|
+
toolListDirectory(provider, args).then(
|
|
1235
|
+
(p) => formatAgentToolOutput("list_directory", args, p, { isError: false }),
|
|
1236
|
+
(err) => formatAgentToolOutput("list_directory", args, String(err), { isError: true })
|
|
1237
|
+
)
|
|
1238
|
+
);
|
|
1239
|
+
}
|
|
1240
|
+
for (const c of readCalls) {
|
|
1241
|
+
const args = c.arguments ?? {};
|
|
1242
|
+
allPromises.push(
|
|
1243
|
+
toolRead(provider, args).then(
|
|
1244
|
+
(p) => formatAgentToolOutput("read", args, p, { isError: false }),
|
|
1245
|
+
(err) => formatAgentToolOutput("read", args, String(err), { isError: true })
|
|
1246
|
+
)
|
|
1247
|
+
);
|
|
1248
|
+
}
|
|
1249
|
+
const toolExecStart = Date.now();
|
|
1250
|
+
const allResults = await Promise.all(allPromises);
|
|
1251
|
+
turnMetrics.local_tools_ms = Date.now() - toolExecStart;
|
|
1252
|
+
for (const result of allResults) {
|
|
1253
|
+
formatted.push(result);
|
|
1254
|
+
}
|
|
1255
|
+
if (formatted.length > 0) {
|
|
1256
|
+
const turnMessage = formatTurnMessage(turn, maxTurns);
|
|
1257
|
+
const contextBudget = calculateContextBudget(messages);
|
|
1258
|
+
messages.push({ role: "user", content: formatted.join("\n") + turnMessage + "\n" + contextBudget });
|
|
1259
|
+
}
|
|
1260
|
+
timings.turns.push(turnMetrics);
|
|
1261
|
+
if (finishCalls.length) {
|
|
1262
|
+
const fc = finishCalls[0];
|
|
1263
|
+
const files = fc.arguments?.files ?? [];
|
|
1264
|
+
finishMeta = { files };
|
|
1265
|
+
terminationReason = "completed";
|
|
1266
|
+
break;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
if (terminationReason !== "completed" || !finishMeta) {
|
|
1270
|
+
timings.total_ms = Date.now() - totalStart;
|
|
1271
|
+
return { terminationReason, messages, errors, timings };
|
|
1272
|
+
}
|
|
1273
|
+
const parts = ["Relevant context found:"];
|
|
1274
|
+
for (const f of finishMeta.files) {
|
|
1275
|
+
const ranges = f.lines === "*" ? "*" : Array.isArray(f.lines) ? f.lines.map(([s, e]) => `${s}-${e}`).join(", ") : "*";
|
|
1276
|
+
parts.push(`- ${f.path}: ${ranges}`);
|
|
1277
|
+
}
|
|
1278
|
+
const payload = parts.join("\n");
|
|
1279
|
+
const finishResolutionStart = Date.now();
|
|
1280
|
+
const fileReadErrors = [];
|
|
1281
|
+
const resolved = await readFinishFiles(
|
|
1282
|
+
repoRoot,
|
|
1283
|
+
finishMeta.files,
|
|
1284
|
+
async (p, s, e) => {
|
|
1285
|
+
try {
|
|
1286
|
+
const rr = await provider.read({ path: p, start: s, end: e });
|
|
1287
|
+
return rr.lines.map((l) => {
|
|
1288
|
+
const idx = l.indexOf("|");
|
|
1289
|
+
return idx >= 0 ? l.slice(idx + 1) : l;
|
|
1290
|
+
});
|
|
1291
|
+
} catch (err) {
|
|
1292
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
1293
|
+
fileReadErrors.push({ path: p, error: errorMsg });
|
|
1294
|
+
console.error(`[warp_grep] Failed to read file: ${p} - ${errorMsg}`);
|
|
1295
|
+
return [`[couldn't find: ${p}]`];
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
);
|
|
1299
|
+
timings.finish_resolution_ms = Date.now() - finishResolutionStart;
|
|
1300
|
+
if (fileReadErrors.length > 0) {
|
|
1301
|
+
errors.push(...fileReadErrors.map((e) => ({ message: `File read error: ${e.path} - ${e.error}` })));
|
|
1302
|
+
}
|
|
1303
|
+
timings.total_ms = Date.now() - totalStart;
|
|
1304
|
+
return {
|
|
1305
|
+
terminationReason: "completed",
|
|
1306
|
+
messages,
|
|
1307
|
+
finish: { payload, metadata: finishMeta, resolved },
|
|
1308
|
+
timings
|
|
1309
|
+
};
|
|
1310
|
+
}
|
|
1152
1311
|
|
|
1153
1312
|
// tools/warp_grep/providers/local.ts
|
|
1154
1313
|
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
@@ -1742,48 +1901,31 @@ var WarpGrepClient = class {
|
|
|
1742
1901
|
retryConfig: config.retryConfig
|
|
1743
1902
|
};
|
|
1744
1903
|
}
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
* }
|
|
1763
|
-
* }
|
|
1764
|
-
* ```
|
|
1765
|
-
*/
|
|
1766
|
-
async execute(input) {
|
|
1767
|
-
return executeToolCall(
|
|
1768
|
-
{ query: input.query },
|
|
1769
|
-
{
|
|
1770
|
-
repoRoot: input.repoRoot,
|
|
1771
|
-
remoteCommands: input.remoteCommands,
|
|
1772
|
-
provider: input.provider,
|
|
1773
|
-
excludes: input.excludes,
|
|
1774
|
-
includes: input.includes,
|
|
1775
|
-
debug: input.debug ?? this.config.debug,
|
|
1776
|
-
morphApiKey: this.config.morphApiKey,
|
|
1777
|
-
morphApiUrl: this.config.morphApiUrl,
|
|
1778
|
-
retryConfig: this.config.retryConfig,
|
|
1779
|
-
timeout: this.config.timeout
|
|
1780
|
-
}
|
|
1781
|
-
);
|
|
1904
|
+
execute(input) {
|
|
1905
|
+
const toolConfig = {
|
|
1906
|
+
repoRoot: input.repoRoot,
|
|
1907
|
+
remoteCommands: input.remoteCommands,
|
|
1908
|
+
provider: input.provider,
|
|
1909
|
+
excludes: input.excludes,
|
|
1910
|
+
includes: input.includes,
|
|
1911
|
+
debug: input.debug ?? this.config.debug,
|
|
1912
|
+
morphApiKey: this.config.morphApiKey,
|
|
1913
|
+
morphApiUrl: this.config.morphApiUrl,
|
|
1914
|
+
retryConfig: this.config.retryConfig,
|
|
1915
|
+
timeout: this.config.timeout
|
|
1916
|
+
};
|
|
1917
|
+
if (input.streamSteps) {
|
|
1918
|
+
return executeToolCallStreaming({ query: input.query }, toolConfig);
|
|
1919
|
+
}
|
|
1920
|
+
return executeToolCall({ query: input.query }, toolConfig);
|
|
1782
1921
|
}
|
|
1783
1922
|
};
|
|
1784
|
-
|
|
1923
|
+
function executeWarpGrep(input, config) {
|
|
1785
1924
|
const client = new WarpGrepClient(config);
|
|
1786
|
-
|
|
1925
|
+
if (input.streamSteps) {
|
|
1926
|
+
return client.execute({ ...input, streamSteps: true });
|
|
1927
|
+
}
|
|
1928
|
+
return client.execute({ ...input, streamSteps: false });
|
|
1787
1929
|
}
|
|
1788
1930
|
async function executeToolCall(input, config) {
|
|
1789
1931
|
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
@@ -1810,6 +1952,43 @@ async function executeToolCall(input, config) {
|
|
|
1810
1952
|
}));
|
|
1811
1953
|
return { success: true, contexts, summary: finish.payload };
|
|
1812
1954
|
}
|
|
1955
|
+
function processAgentResult(result) {
|
|
1956
|
+
const finish = result.finish;
|
|
1957
|
+
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
1958
|
+
return { success: false, error: "Search did not complete" };
|
|
1959
|
+
}
|
|
1960
|
+
const contexts = (finish.resolved ?? []).map((r) => ({
|
|
1961
|
+
file: r.path,
|
|
1962
|
+
content: r.content
|
|
1963
|
+
}));
|
|
1964
|
+
return { success: true, contexts, summary: finish.payload };
|
|
1965
|
+
}
|
|
1966
|
+
async function* executeToolCallStreaming(input, config) {
|
|
1967
|
+
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
1968
|
+
const provider = config.remoteCommands ? new RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ?? new LocalRipgrepProvider(config.repoRoot, config.excludes);
|
|
1969
|
+
const generator = runWarpGrepStreaming({
|
|
1970
|
+
query: parsed.query,
|
|
1971
|
+
repoRoot: config.repoRoot,
|
|
1972
|
+
provider,
|
|
1973
|
+
excludes: config.excludes,
|
|
1974
|
+
includes: config.includes,
|
|
1975
|
+
debug: config.debug ?? false,
|
|
1976
|
+
morphApiKey: config.morphApiKey,
|
|
1977
|
+
morphApiUrl: config.morphApiUrl,
|
|
1978
|
+
retryConfig: config.retryConfig,
|
|
1979
|
+
timeout: config.timeout
|
|
1980
|
+
});
|
|
1981
|
+
let agentResult;
|
|
1982
|
+
for (; ; ) {
|
|
1983
|
+
const { value, done } = await generator.next();
|
|
1984
|
+
if (done) {
|
|
1985
|
+
agentResult = value;
|
|
1986
|
+
break;
|
|
1987
|
+
}
|
|
1988
|
+
yield value;
|
|
1989
|
+
}
|
|
1990
|
+
return processAgentResult(agentResult);
|
|
1991
|
+
}
|
|
1813
1992
|
function formatResult(result) {
|
|
1814
1993
|
if (!result.success) {
|
|
1815
1994
|
return `Search failed: ${result.error}`;
|