@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.d.ts CHANGED
@@ -5,11 +5,12 @@ import './tools/browser/core.js';
5
5
  import './tools/warp_grep/client.js';
6
6
  import './git/client.js';
7
7
  import './modelrouter/core.js';
8
- export { M as MorphClient, a as MorphClientConfig } from './client-CsO9LifG.js';
8
+ export { M as MorphClient, a as MorphClientConfig } from './client-Drz3OGq-.js';
9
9
  import './tools/fastapply/types.js';
10
10
  import './tools/codebase_search/types.js';
11
11
  import './tools/browser/types.js';
12
- import './types-Cv4LpqVl.js';
12
+ import './tools/warp_grep/agent/types.js';
13
+ import './types-BMowL9iZ.js';
13
14
  import './tools/warp_grep/providers/types.js';
14
15
  import './git/types.js';
15
16
  import 'isomorphic-git';
package/dist/client.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  MorphClient
3
- } from "./chunk-HPR6BJA7.js";
4
- import "./chunk-RL4JBZ3T.js";
5
- import "./chunk-LXG37353.js";
6
- import "./chunk-S27A4NQM.js";
3
+ } from "./chunk-SQF3OG24.js";
4
+ import "./chunk-AJEE5RRB.js";
5
+ import "./chunk-IXNX4HMC.js";
6
+ import "./chunk-5X7IJXKA.js";
7
7
  import "./chunk-KW7OEGZK.js";
8
- import "./chunk-HRK53IKL.js";
9
- import "./chunk-QOYI77CN.js";
8
+ import "./chunk-37SJ3IOY.js";
9
+ import "./chunk-HJOMBO2A.js";
10
10
  import "./chunk-PUGSTXLO.js";
11
- import "./chunk-P2O5JKE5.js";
11
+ import "./chunk-KRDIR7GG.js";
12
12
  import "./chunk-APP75CBN.js";
13
13
  import "./chunk-5QRN3JNB.js";
14
14
  import "./chunk-FMLHRJDF.js";
package/dist/index.cjs CHANGED
@@ -1611,14 +1611,23 @@ async function toolRead(provider, args) {
1611
1611
 
1612
1612
  // tools/warp_grep/agent/tools/list_directory.ts
1613
1613
  async function toolListDirectory(provider, args) {
1614
- const list = await provider.listDirectory({
1615
- path: args.path,
1616
- pattern: args.pattern ?? null,
1617
- maxResults: args.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES,
1618
- maxDepth: args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH
1619
- });
1614
+ const maxResults = args.maxResults ?? AGENT_CONFIG.MAX_OUTPUT_LINES;
1615
+ const initialDepth = args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
1616
+ async function getListRecursive(currentDepth) {
1617
+ const entries = await provider.listDirectory({
1618
+ path: args.path,
1619
+ pattern: args.pattern ?? null,
1620
+ maxResults,
1621
+ maxDepth: currentDepth
1622
+ });
1623
+ if (entries.length >= maxResults && currentDepth > 0) {
1624
+ return getListRecursive(currentDepth - 1);
1625
+ }
1626
+ return { entries };
1627
+ }
1628
+ const { entries: list } = await getListRecursive(initialDepth);
1620
1629
  if (!list.length) return "empty";
1621
- if (list.length >= AGENT_CONFIG.MAX_OUTPUT_LINES) {
1630
+ if (list.length >= maxResults) {
1622
1631
  return "query not specific enough, tool called tried to return too much context and failed";
1623
1632
  }
1624
1633
  return list.map((e) => {
@@ -2038,6 +2047,156 @@ async function runWarpGrep(config) {
2038
2047
  timings
2039
2048
  };
2040
2049
  }
2050
+ async function* runWarpGrepStreaming(config) {
2051
+ const totalStart = Date.now();
2052
+ const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
2053
+ const timings = { turns: [], timeout_ms: timeoutMs };
2054
+ const repoRoot = import_path3.default.resolve(config.repoRoot || process.cwd());
2055
+ const messages = [];
2056
+ messages.push({ role: "system", content: getSystemPrompt() });
2057
+ const initialStateStart = Date.now();
2058
+ const initialState = await buildInitialState(repoRoot, config.query, config.provider);
2059
+ timings.initial_state_ms = Date.now() - initialStateStart;
2060
+ messages.push({ role: "user", content: initialState });
2061
+ const maxTurns = AGENT_CONFIG.MAX_TURNS;
2062
+ const model = config.model || DEFAULT_MODEL;
2063
+ const provider = config.provider;
2064
+ const errors = [];
2065
+ let finishMeta;
2066
+ let terminationReason = "terminated";
2067
+ for (let turn = 1; turn <= maxTurns; turn += 1) {
2068
+ const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
2069
+ enforceContextLimit(messages);
2070
+ const modelCallStart = Date.now();
2071
+ const assistantContent = await callModel(messages, model, {
2072
+ morphApiKey: config.morphApiKey,
2073
+ morphApiUrl: config.morphApiUrl,
2074
+ retryConfig: config.retryConfig,
2075
+ timeout: timeoutMs
2076
+ }).catch((e) => {
2077
+ errors.push({ message: e instanceof Error ? e.message : String(e) });
2078
+ return "";
2079
+ });
2080
+ turnMetrics.morph_api_ms = Date.now() - modelCallStart;
2081
+ if (!assistantContent) {
2082
+ timings.turns.push(turnMetrics);
2083
+ break;
2084
+ }
2085
+ messages.push({ role: "assistant", content: assistantContent });
2086
+ const toolCalls = parser.parse(assistantContent);
2087
+ if (toolCalls.length === 0) {
2088
+ 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" });
2089
+ terminationReason = "terminated";
2090
+ timings.turns.push(turnMetrics);
2091
+ break;
2092
+ }
2093
+ yield {
2094
+ turn,
2095
+ toolCalls: toolCalls.map((c) => ({
2096
+ name: c.name,
2097
+ arguments: c.arguments ?? {}
2098
+ }))
2099
+ };
2100
+ const finishCalls = toolCalls.filter((c) => c.name === "finish");
2101
+ const grepCalls = toolCalls.filter((c) => c.name === "grep");
2102
+ const listDirCalls = toolCalls.filter((c) => c.name === "list_directory");
2103
+ const readCalls = toolCalls.filter((c) => c.name === "read");
2104
+ const skipCalls = toolCalls.filter((c) => c.name === "_skip");
2105
+ const formatted = [];
2106
+ for (const c of skipCalls) {
2107
+ const msg = c.arguments?.message || "Command skipped due to parsing error";
2108
+ formatted.push(msg);
2109
+ }
2110
+ const allPromises = [];
2111
+ for (const c of grepCalls) {
2112
+ const args = c.arguments ?? {};
2113
+ allPromises.push(
2114
+ toolGrep(provider, args).then(
2115
+ ({ output }) => formatAgentToolOutput("grep", args, output, { isError: false }),
2116
+ (err) => formatAgentToolOutput("grep", args, String(err), { isError: true })
2117
+ )
2118
+ );
2119
+ }
2120
+ for (const c of listDirCalls) {
2121
+ const args = c.arguments ?? {};
2122
+ allPromises.push(
2123
+ toolListDirectory(provider, args).then(
2124
+ (p) => formatAgentToolOutput("list_directory", args, p, { isError: false }),
2125
+ (err) => formatAgentToolOutput("list_directory", args, String(err), { isError: true })
2126
+ )
2127
+ );
2128
+ }
2129
+ for (const c of readCalls) {
2130
+ const args = c.arguments ?? {};
2131
+ allPromises.push(
2132
+ toolRead(provider, args).then(
2133
+ (p) => formatAgentToolOutput("read", args, p, { isError: false }),
2134
+ (err) => formatAgentToolOutput("read", args, String(err), { isError: true })
2135
+ )
2136
+ );
2137
+ }
2138
+ const toolExecStart = Date.now();
2139
+ const allResults = await Promise.all(allPromises);
2140
+ turnMetrics.local_tools_ms = Date.now() - toolExecStart;
2141
+ for (const result of allResults) {
2142
+ formatted.push(result);
2143
+ }
2144
+ if (formatted.length > 0) {
2145
+ const turnMessage = formatTurnMessage(turn, maxTurns);
2146
+ const contextBudget = calculateContextBudget(messages);
2147
+ messages.push({ role: "user", content: formatted.join("\n") + turnMessage + "\n" + contextBudget });
2148
+ }
2149
+ timings.turns.push(turnMetrics);
2150
+ if (finishCalls.length) {
2151
+ const fc = finishCalls[0];
2152
+ const files = fc.arguments?.files ?? [];
2153
+ finishMeta = { files };
2154
+ terminationReason = "completed";
2155
+ break;
2156
+ }
2157
+ }
2158
+ if (terminationReason !== "completed" || !finishMeta) {
2159
+ timings.total_ms = Date.now() - totalStart;
2160
+ return { terminationReason, messages, errors, timings };
2161
+ }
2162
+ const parts = ["Relevant context found:"];
2163
+ for (const f of finishMeta.files) {
2164
+ const ranges = f.lines === "*" ? "*" : Array.isArray(f.lines) ? f.lines.map(([s, e]) => `${s}-${e}`).join(", ") : "*";
2165
+ parts.push(`- ${f.path}: ${ranges}`);
2166
+ }
2167
+ const payload = parts.join("\n");
2168
+ const finishResolutionStart = Date.now();
2169
+ const fileReadErrors = [];
2170
+ const resolved = await readFinishFiles(
2171
+ repoRoot,
2172
+ finishMeta.files,
2173
+ async (p, s, e) => {
2174
+ try {
2175
+ const rr = await provider.read({ path: p, start: s, end: e });
2176
+ return rr.lines.map((l) => {
2177
+ const idx = l.indexOf("|");
2178
+ return idx >= 0 ? l.slice(idx + 1) : l;
2179
+ });
2180
+ } catch (err) {
2181
+ const errorMsg = err instanceof Error ? err.message : String(err);
2182
+ fileReadErrors.push({ path: p, error: errorMsg });
2183
+ console.error(`[warp_grep] Failed to read file: ${p} - ${errorMsg}`);
2184
+ return [`[couldn't find: ${p}]`];
2185
+ }
2186
+ }
2187
+ );
2188
+ timings.finish_resolution_ms = Date.now() - finishResolutionStart;
2189
+ if (fileReadErrors.length > 0) {
2190
+ errors.push(...fileReadErrors.map((e) => ({ message: `File read error: ${e.path} - ${e.error}` })));
2191
+ }
2192
+ timings.total_ms = Date.now() - totalStart;
2193
+ return {
2194
+ terminationReason: "completed",
2195
+ messages,
2196
+ finish: { payload, metadata: finishMeta, resolved },
2197
+ timings
2198
+ };
2199
+ }
2041
2200
 
2042
2201
  // tools/warp_grep/providers/local.ts
2043
2202
  var import_promises3 = __toESM(require("fs/promises"), 1);
@@ -2631,43 +2790,23 @@ var WarpGrepClient = class {
2631
2790
  retryConfig: config.retryConfig
2632
2791
  };
2633
2792
  }
2634
- /**
2635
- * Execute a code search query
2636
- *
2637
- * @param input - Search parameters including query, repoRoot, and optional provider
2638
- * @returns Search results with relevant code contexts
2639
- *
2640
- * @example
2641
- * ```typescript
2642
- * const result = await client.execute({
2643
- * query: 'Find authentication middleware',
2644
- * repoRoot: '.'
2645
- * });
2646
- *
2647
- * if (result.success) {
2648
- * for (const ctx of result.contexts) {
2649
- * console.log(`File: ${ctx.file}`);
2650
- * console.log(ctx.content);
2651
- * }
2652
- * }
2653
- * ```
2654
- */
2655
- async execute(input) {
2656
- return executeToolCall(
2657
- { query: input.query },
2658
- {
2659
- repoRoot: input.repoRoot,
2660
- remoteCommands: input.remoteCommands,
2661
- provider: input.provider,
2662
- excludes: input.excludes,
2663
- includes: input.includes,
2664
- debug: input.debug ?? this.config.debug,
2665
- morphApiKey: this.config.morphApiKey,
2666
- morphApiUrl: this.config.morphApiUrl,
2667
- retryConfig: this.config.retryConfig,
2668
- timeout: this.config.timeout
2669
- }
2670
- );
2793
+ execute(input) {
2794
+ const toolConfig = {
2795
+ repoRoot: input.repoRoot,
2796
+ remoteCommands: input.remoteCommands,
2797
+ provider: input.provider,
2798
+ excludes: input.excludes,
2799
+ includes: input.includes,
2800
+ debug: input.debug ?? this.config.debug,
2801
+ morphApiKey: this.config.morphApiKey,
2802
+ morphApiUrl: this.config.morphApiUrl,
2803
+ retryConfig: this.config.retryConfig,
2804
+ timeout: this.config.timeout
2805
+ };
2806
+ if (input.streamSteps) {
2807
+ return executeToolCallStreaming({ query: input.query }, toolConfig);
2808
+ }
2809
+ return executeToolCall({ query: input.query }, toolConfig);
2671
2810
  }
2672
2811
  };
2673
2812
  async function executeToolCall(input, config) {
@@ -2695,6 +2834,43 @@ async function executeToolCall(input, config) {
2695
2834
  }));
2696
2835
  return { success: true, contexts, summary: finish.payload };
2697
2836
  }
2837
+ function processAgentResult(result) {
2838
+ const finish = result.finish;
2839
+ if (result.terminationReason !== "completed" || !finish?.metadata) {
2840
+ return { success: false, error: "Search did not complete" };
2841
+ }
2842
+ const contexts = (finish.resolved ?? []).map((r) => ({
2843
+ file: r.path,
2844
+ content: r.content
2845
+ }));
2846
+ return { success: true, contexts, summary: finish.payload };
2847
+ }
2848
+ async function* executeToolCallStreaming(input, config) {
2849
+ const parsed = typeof input === "string" ? JSON.parse(input) : input;
2850
+ const provider = config.remoteCommands ? new RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ?? new LocalRipgrepProvider(config.repoRoot, config.excludes);
2851
+ const generator = runWarpGrepStreaming({
2852
+ query: parsed.query,
2853
+ repoRoot: config.repoRoot,
2854
+ provider,
2855
+ excludes: config.excludes,
2856
+ includes: config.includes,
2857
+ debug: config.debug ?? false,
2858
+ morphApiKey: config.morphApiKey,
2859
+ morphApiUrl: config.morphApiUrl,
2860
+ retryConfig: config.retryConfig,
2861
+ timeout: config.timeout
2862
+ });
2863
+ let agentResult;
2864
+ for (; ; ) {
2865
+ const { value, done } = await generator.next();
2866
+ if (done) {
2867
+ agentResult = value;
2868
+ break;
2869
+ }
2870
+ yield value;
2871
+ }
2872
+ return processAgentResult(agentResult);
2873
+ }
2698
2874
  function formatResult(result) {
2699
2875
  if (!result.success) {
2700
2876
  return `Search failed: ${result.error}`;