@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.
Files changed (64) hide show
  1. package/dist/{chunk-HRK53IKL.js → chunk-37SJ3IOY.js} +63 -42
  2. package/dist/chunk-37SJ3IOY.js.map +1 -0
  3. package/dist/{chunk-S27A4NQM.js → chunk-5X7IJXKA.js} +2 -2
  4. package/dist/{chunk-RL4JBZ3T.js → chunk-AJEE5RRB.js} +2 -2
  5. package/dist/{chunk-QOYI77CN.js → chunk-HJOMBO2A.js} +154 -3
  6. package/dist/chunk-HJOMBO2A.js.map +1 -0
  7. package/dist/{chunk-LXG37353.js → chunk-IXNX4HMC.js} +2 -2
  8. package/dist/{chunk-P2O5JKE5.js → chunk-KRDIR7GG.js} +17 -8
  9. package/dist/chunk-KRDIR7GG.js.map +1 -0
  10. package/dist/{chunk-FY32COVL.js → chunk-L5C6E32T.js} +1 -1
  11. package/dist/{chunk-FY32COVL.js.map → chunk-L5C6E32T.js.map} +1 -1
  12. package/dist/{chunk-HPR6BJA7.js → chunk-SQF3OG24.js} +5 -5
  13. package/dist/{client-CsO9LifG.d.ts → client-Drz3OGq-.d.ts} +1 -1
  14. package/dist/client.cjs +220 -44
  15. package/dist/client.cjs.map +1 -1
  16. package/dist/client.d.ts +3 -2
  17. package/dist/client.js +7 -7
  18. package/dist/index.cjs +220 -44
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +3 -3
  21. package/dist/index.js +8 -8
  22. package/dist/tools/warp_grep/agent/runner.cjs +170 -9
  23. package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
  24. package/dist/tools/warp_grep/agent/runner.d.ts +9 -2
  25. package/dist/tools/warp_grep/agent/runner.js +6 -4
  26. package/dist/tools/warp_grep/agent/types.cjs.map +1 -1
  27. package/dist/tools/warp_grep/agent/types.d.ts +12 -1
  28. package/dist/tools/warp_grep/anthropic.cjs +16 -7
  29. package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
  30. package/dist/tools/warp_grep/anthropic.d.ts +3 -2
  31. package/dist/tools/warp_grep/anthropic.js +4 -4
  32. package/dist/tools/warp_grep/client.cjs +225 -46
  33. package/dist/tools/warp_grep/client.cjs.map +1 -1
  34. package/dist/tools/warp_grep/client.d.ts +39 -6
  35. package/dist/tools/warp_grep/client.js +3 -3
  36. package/dist/tools/warp_grep/gemini.cjs +16 -7
  37. package/dist/tools/warp_grep/gemini.cjs.map +1 -1
  38. package/dist/tools/warp_grep/gemini.d.ts +3 -2
  39. package/dist/tools/warp_grep/gemini.js +3 -3
  40. package/dist/tools/warp_grep/harness.cjs +16 -7
  41. package/dist/tools/warp_grep/harness.cjs.map +1 -1
  42. package/dist/tools/warp_grep/harness.js +1 -1
  43. package/dist/tools/warp_grep/index.cjs +227 -46
  44. package/dist/tools/warp_grep/index.cjs.map +1 -1
  45. package/dist/tools/warp_grep/index.d.ts +3 -3
  46. package/dist/tools/warp_grep/index.js +7 -5
  47. package/dist/tools/warp_grep/openai.cjs +16 -7
  48. package/dist/tools/warp_grep/openai.cjs.map +1 -1
  49. package/dist/tools/warp_grep/openai.d.ts +3 -2
  50. package/dist/tools/warp_grep/openai.js +4 -4
  51. package/dist/tools/warp_grep/providers/remote.d.ts +1 -1
  52. package/dist/tools/warp_grep/vercel.cjs +16 -7
  53. package/dist/tools/warp_grep/vercel.cjs.map +1 -1
  54. package/dist/tools/warp_grep/vercel.d.ts +2 -1
  55. package/dist/tools/warp_grep/vercel.js +4 -4
  56. package/dist/{types-Cv4LpqVl.d.ts → types-BMowL9iZ.d.ts} +5 -0
  57. package/package.json +1 -1
  58. package/dist/chunk-HRK53IKL.js.map +0 -1
  59. package/dist/chunk-P2O5JKE5.js.map +0 -1
  60. package/dist/chunk-QOYI77CN.js.map +0 -1
  61. /package/dist/{chunk-S27A4NQM.js.map → chunk-5X7IJXKA.js.map} +0 -0
  62. /package/dist/{chunk-RL4JBZ3T.js.map → chunk-AJEE5RRB.js.map} +0 -0
  63. /package/dist/{chunk-LXG37353.js.map → chunk-IXNX4HMC.js.map} +0 -0
  64. /package/dist/{chunk-HPR6BJA7.js.map → chunk-SQF3OG24.js.map} +0 -0
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 list = await provider.listDirectory({
1601
- path: args.path,
1602
- pattern: args.pattern ?? null,
1603
- maxResults: args.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES,
1604
- maxDepth: args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH
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 >= AGENT_CONFIG.MAX_OUTPUT_LINES) {
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) => {
@@ -2024,6 +2033,156 @@ async function runWarpGrep(config) {
2024
2033
  timings
2025
2034
  };
2026
2035
  }
2036
+ async function* runWarpGrepStreaming(config) {
2037
+ const totalStart = Date.now();
2038
+ const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
2039
+ const timings = { turns: [], timeout_ms: timeoutMs };
2040
+ const repoRoot = import_path3.default.resolve(config.repoRoot || process.cwd());
2041
+ const messages = [];
2042
+ messages.push({ role: "system", content: getSystemPrompt() });
2043
+ const initialStateStart = Date.now();
2044
+ const initialState = await buildInitialState(repoRoot, config.query, config.provider);
2045
+ timings.initial_state_ms = Date.now() - initialStateStart;
2046
+ messages.push({ role: "user", content: initialState });
2047
+ const maxTurns = AGENT_CONFIG.MAX_TURNS;
2048
+ const model = config.model || DEFAULT_MODEL;
2049
+ const provider = config.provider;
2050
+ const errors = [];
2051
+ let finishMeta;
2052
+ let terminationReason = "terminated";
2053
+ for (let turn = 1; turn <= maxTurns; turn += 1) {
2054
+ const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
2055
+ enforceContextLimit(messages);
2056
+ const modelCallStart = Date.now();
2057
+ const assistantContent = await callModel(messages, model, {
2058
+ morphApiKey: config.morphApiKey,
2059
+ morphApiUrl: config.morphApiUrl,
2060
+ retryConfig: config.retryConfig,
2061
+ timeout: timeoutMs
2062
+ }).catch((e) => {
2063
+ errors.push({ message: e instanceof Error ? e.message : String(e) });
2064
+ return "";
2065
+ });
2066
+ turnMetrics.morph_api_ms = Date.now() - modelCallStart;
2067
+ if (!assistantContent) {
2068
+ timings.turns.push(turnMetrics);
2069
+ break;
2070
+ }
2071
+ messages.push({ role: "assistant", content: assistantContent });
2072
+ const toolCalls = parser.parse(assistantContent);
2073
+ if (toolCalls.length === 0) {
2074
+ 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" });
2075
+ terminationReason = "terminated";
2076
+ timings.turns.push(turnMetrics);
2077
+ break;
2078
+ }
2079
+ yield {
2080
+ turn,
2081
+ toolCalls: toolCalls.map((c) => ({
2082
+ name: c.name,
2083
+ arguments: c.arguments ?? {}
2084
+ }))
2085
+ };
2086
+ const finishCalls = toolCalls.filter((c) => c.name === "finish");
2087
+ const grepCalls = toolCalls.filter((c) => c.name === "grep");
2088
+ const listDirCalls = toolCalls.filter((c) => c.name === "list_directory");
2089
+ const readCalls = toolCalls.filter((c) => c.name === "read");
2090
+ const skipCalls = toolCalls.filter((c) => c.name === "_skip");
2091
+ const formatted = [];
2092
+ for (const c of skipCalls) {
2093
+ const msg = c.arguments?.message || "Command skipped due to parsing error";
2094
+ formatted.push(msg);
2095
+ }
2096
+ const allPromises = [];
2097
+ for (const c of grepCalls) {
2098
+ const args = c.arguments ?? {};
2099
+ allPromises.push(
2100
+ toolGrep(provider, args).then(
2101
+ ({ output }) => formatAgentToolOutput("grep", args, output, { isError: false }),
2102
+ (err) => formatAgentToolOutput("grep", args, String(err), { isError: true })
2103
+ )
2104
+ );
2105
+ }
2106
+ for (const c of listDirCalls) {
2107
+ const args = c.arguments ?? {};
2108
+ allPromises.push(
2109
+ toolListDirectory(provider, args).then(
2110
+ (p) => formatAgentToolOutput("list_directory", args, p, { isError: false }),
2111
+ (err) => formatAgentToolOutput("list_directory", args, String(err), { isError: true })
2112
+ )
2113
+ );
2114
+ }
2115
+ for (const c of readCalls) {
2116
+ const args = c.arguments ?? {};
2117
+ allPromises.push(
2118
+ toolRead(provider, args).then(
2119
+ (p) => formatAgentToolOutput("read", args, p, { isError: false }),
2120
+ (err) => formatAgentToolOutput("read", args, String(err), { isError: true })
2121
+ )
2122
+ );
2123
+ }
2124
+ const toolExecStart = Date.now();
2125
+ const allResults = await Promise.all(allPromises);
2126
+ turnMetrics.local_tools_ms = Date.now() - toolExecStart;
2127
+ for (const result of allResults) {
2128
+ formatted.push(result);
2129
+ }
2130
+ if (formatted.length > 0) {
2131
+ const turnMessage = formatTurnMessage(turn, maxTurns);
2132
+ const contextBudget = calculateContextBudget(messages);
2133
+ messages.push({ role: "user", content: formatted.join("\n") + turnMessage + "\n" + contextBudget });
2134
+ }
2135
+ timings.turns.push(turnMetrics);
2136
+ if (finishCalls.length) {
2137
+ const fc = finishCalls[0];
2138
+ const files = fc.arguments?.files ?? [];
2139
+ finishMeta = { files };
2140
+ terminationReason = "completed";
2141
+ break;
2142
+ }
2143
+ }
2144
+ if (terminationReason !== "completed" || !finishMeta) {
2145
+ timings.total_ms = Date.now() - totalStart;
2146
+ return { terminationReason, messages, errors, timings };
2147
+ }
2148
+ const parts = ["Relevant context found:"];
2149
+ for (const f of finishMeta.files) {
2150
+ const ranges = f.lines === "*" ? "*" : Array.isArray(f.lines) ? f.lines.map(([s, e]) => `${s}-${e}`).join(", ") : "*";
2151
+ parts.push(`- ${f.path}: ${ranges}`);
2152
+ }
2153
+ const payload = parts.join("\n");
2154
+ const finishResolutionStart = Date.now();
2155
+ const fileReadErrors = [];
2156
+ const resolved = await readFinishFiles(
2157
+ repoRoot,
2158
+ finishMeta.files,
2159
+ async (p, s, e) => {
2160
+ try {
2161
+ const rr = await provider.read({ path: p, start: s, end: e });
2162
+ return rr.lines.map((l) => {
2163
+ const idx = l.indexOf("|");
2164
+ return idx >= 0 ? l.slice(idx + 1) : l;
2165
+ });
2166
+ } catch (err) {
2167
+ const errorMsg = err instanceof Error ? err.message : String(err);
2168
+ fileReadErrors.push({ path: p, error: errorMsg });
2169
+ console.error(`[warp_grep] Failed to read file: ${p} - ${errorMsg}`);
2170
+ return [`[couldn't find: ${p}]`];
2171
+ }
2172
+ }
2173
+ );
2174
+ timings.finish_resolution_ms = Date.now() - finishResolutionStart;
2175
+ if (fileReadErrors.length > 0) {
2176
+ errors.push(...fileReadErrors.map((e) => ({ message: `File read error: ${e.path} - ${e.error}` })));
2177
+ }
2178
+ timings.total_ms = Date.now() - totalStart;
2179
+ return {
2180
+ terminationReason: "completed",
2181
+ messages,
2182
+ finish: { payload, metadata: finishMeta, resolved },
2183
+ timings
2184
+ };
2185
+ }
2027
2186
 
2028
2187
  // tools/warp_grep/providers/local.ts
2029
2188
  var import_promises3 = __toESM(require("fs/promises"), 1);
@@ -2617,43 +2776,23 @@ var WarpGrepClient = class {
2617
2776
  retryConfig: config.retryConfig
2618
2777
  };
2619
2778
  }
2620
- /**
2621
- * Execute a code search query
2622
- *
2623
- * @param input - Search parameters including query, repoRoot, and optional provider
2624
- * @returns Search results with relevant code contexts
2625
- *
2626
- * @example
2627
- * ```typescript
2628
- * const result = await client.execute({
2629
- * query: 'Find authentication middleware',
2630
- * repoRoot: '.'
2631
- * });
2632
- *
2633
- * if (result.success) {
2634
- * for (const ctx of result.contexts) {
2635
- * console.log(`File: ${ctx.file}`);
2636
- * console.log(ctx.content);
2637
- * }
2638
- * }
2639
- * ```
2640
- */
2641
- async execute(input) {
2642
- return executeToolCall(
2643
- { query: input.query },
2644
- {
2645
- repoRoot: input.repoRoot,
2646
- remoteCommands: input.remoteCommands,
2647
- provider: input.provider,
2648
- excludes: input.excludes,
2649
- includes: input.includes,
2650
- debug: input.debug ?? this.config.debug,
2651
- morphApiKey: this.config.morphApiKey,
2652
- morphApiUrl: this.config.morphApiUrl,
2653
- retryConfig: this.config.retryConfig,
2654
- timeout: this.config.timeout
2655
- }
2656
- );
2779
+ execute(input) {
2780
+ const toolConfig = {
2781
+ repoRoot: input.repoRoot,
2782
+ remoteCommands: input.remoteCommands,
2783
+ provider: input.provider,
2784
+ excludes: input.excludes,
2785
+ includes: input.includes,
2786
+ debug: input.debug ?? this.config.debug,
2787
+ morphApiKey: this.config.morphApiKey,
2788
+ morphApiUrl: this.config.morphApiUrl,
2789
+ retryConfig: this.config.retryConfig,
2790
+ timeout: this.config.timeout
2791
+ };
2792
+ if (input.streamSteps) {
2793
+ return executeToolCallStreaming({ query: input.query }, toolConfig);
2794
+ }
2795
+ return executeToolCall({ query: input.query }, toolConfig);
2657
2796
  }
2658
2797
  };
2659
2798
  async function executeToolCall(input, config) {
@@ -2681,6 +2820,43 @@ async function executeToolCall(input, config) {
2681
2820
  }));
2682
2821
  return { success: true, contexts, summary: finish.payload };
2683
2822
  }
2823
+ function processAgentResult(result) {
2824
+ const finish = result.finish;
2825
+ if (result.terminationReason !== "completed" || !finish?.metadata) {
2826
+ return { success: false, error: "Search did not complete" };
2827
+ }
2828
+ const contexts = (finish.resolved ?? []).map((r) => ({
2829
+ file: r.path,
2830
+ content: r.content
2831
+ }));
2832
+ return { success: true, contexts, summary: finish.payload };
2833
+ }
2834
+ async function* executeToolCallStreaming(input, config) {
2835
+ const parsed = typeof input === "string" ? JSON.parse(input) : input;
2836
+ const provider = config.remoteCommands ? new RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ?? new LocalRipgrepProvider(config.repoRoot, config.excludes);
2837
+ const generator = runWarpGrepStreaming({
2838
+ query: parsed.query,
2839
+ repoRoot: config.repoRoot,
2840
+ provider,
2841
+ excludes: config.excludes,
2842
+ includes: config.includes,
2843
+ debug: config.debug ?? false,
2844
+ morphApiKey: config.morphApiKey,
2845
+ morphApiUrl: config.morphApiUrl,
2846
+ retryConfig: config.retryConfig,
2847
+ timeout: config.timeout
2848
+ });
2849
+ let agentResult;
2850
+ for (; ; ) {
2851
+ const { value, done } = await generator.next();
2852
+ if (done) {
2853
+ agentResult = value;
2854
+ break;
2855
+ }
2856
+ yield value;
2857
+ }
2858
+ return processAgentResult(agentResult);
2859
+ }
2684
2860
  function formatResult(result) {
2685
2861
  if (!result.success) {
2686
2862
  return `Search failed: ${result.error}`;