@morphllm/morphsdk 0.2.56 → 0.2.57
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-SALJ2K6S.js → chunk-6X5UOY7B.js} +32 -37
- package/dist/chunk-6X5UOY7B.js.map +1 -0
- package/dist/{chunk-UIRJE422.js → chunk-CFF636UC.js} +3 -3
- package/dist/{chunk-QVRXBAMM.js → chunk-GJ5TYNRD.js} +2 -2
- package/dist/{chunk-4ZHDBKBY.js → chunk-IMYQOKFO.js} +3 -3
- package/dist/{chunk-GJURLQ3L.js → chunk-KBQWGT5L.js} +3 -3
- package/dist/{chunk-WSSSSBWU.js → chunk-QFIHUCTF.js} +5 -5
- package/dist/client.cjs +28 -142
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +7 -8
- package/dist/index.cjs +28 -142
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -8
- package/dist/tools/warp_grep/agent/runner.cjs +28 -142
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +2 -3
- package/dist/tools/warp_grep/anthropic.cjs +28 -142
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.js +4 -5
- package/dist/tools/warp_grep/harness.cjs +859 -0
- package/dist/tools/warp_grep/harness.cjs.map +1 -0
- package/dist/tools/warp_grep/harness.d.ts +176 -0
- package/dist/tools/warp_grep/harness.js +76 -0
- package/dist/tools/warp_grep/harness.js.map +1 -0
- package/dist/tools/warp_grep/index.cjs +28 -142
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.js +6 -7
- package/dist/tools/warp_grep/openai.cjs +28 -142
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.js +4 -5
- package/dist/tools/warp_grep/vercel.cjs +28 -142
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.js +4 -5
- package/package.json +7 -2
- package/dist/chunk-NDZO5IPV.js +0 -121
- package/dist/chunk-NDZO5IPV.js.map +0 -1
- package/dist/chunk-SALJ2K6S.js.map +0 -1
- package/dist/tools/warp_grep/agent/grep_helpers.cjs +0 -148
- package/dist/tools/warp_grep/agent/grep_helpers.cjs.map +0 -1
- package/dist/tools/warp_grep/agent/grep_helpers.d.ts +0 -16
- package/dist/tools/warp_grep/agent/grep_helpers.js +0 -14
- package/dist/tools/warp_grep/agent/grep_helpers.js.map +0 -1
- /package/dist/{chunk-UIRJE422.js.map → chunk-CFF636UC.js.map} +0 -0
- /package/dist/{chunk-QVRXBAMM.js.map → chunk-GJ5TYNRD.js.map} +0 -0
- /package/dist/{chunk-4ZHDBKBY.js.map → chunk-IMYQOKFO.js.map} +0 -0
- /package/dist/{chunk-GJURLQ3L.js.map → chunk-KBQWGT5L.js.map} +0 -0
- /package/dist/{chunk-WSSSSBWU.js.map → chunk-QFIHUCTF.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../tools/warp_grep/agent/grep_helpers.ts"],"sourcesContent":["export interface GrepMatch {\n\tpath: string;\n\tlineNumber: number;\n\tcontent: string;\n}\n\nexport class GrepState {\n\tprivate readonly seenLines = new Set<string>();\n\n\tisNew(path: string, lineNumber: number): boolean {\n\t\tconst key = this.makeKey(path, lineNumber);\n\t\treturn !this.seenLines.has(key);\n\t}\n\n\tadd(path: string, lineNumber: number): void {\n\t\tthis.seenLines.add(this.makeKey(path, lineNumber));\n\t}\n\n\tprivate makeKey(path: string, lineNumber: number): string {\n\t\treturn `${path}:${lineNumber}`;\n\t}\n}\n\nexport const MAX_GREP_OUTPUT_CHARS_PER_TURN = 60_000;\n\nfunction extractMatchFields(payload: string): GrepMatch | null {\n\tconst text = payload.replace(/\\r?\\n$/, \"\");\n\tif (!text || text.startsWith(\"[error]\")) {\n\t\treturn null;\n\t}\n\n\tconst firstSep = text.indexOf(\":\");\n\tif (firstSep === -1) {\n\t\treturn null;\n\t}\n\tlet filePath = text.slice(0, firstSep).trim();\n\tif (!filePath) {\n\t\treturn null;\n\t}\n\tif (filePath.startsWith(\"./\") || filePath.startsWith(\".\\\\\")) {\n\t\tfilePath = filePath.slice(2);\n\t}\n\n\tconst remainder = text.slice(firstSep + 1);\n\tconst secondSep = remainder.indexOf(\":\");\n\tif (secondSep === -1) {\n\t\treturn null;\n\t}\n\n\tconst linePart = remainder.slice(0, secondSep);\n\tconst lineNumber = Number.parseInt(linePart, 10);\n\tif (!Number.isInteger(lineNumber) || lineNumber <= 0) {\n\t\treturn null;\n\t}\n\n\tlet contentSegment = remainder.slice(secondSep + 1);\n\tconst columnSep = contentSegment.indexOf(\":\");\n\tif (columnSep !== -1 && /^\\d+$/.test(contentSegment.slice(0, columnSep))) {\n\t\tcontentSegment = contentSegment.slice(columnSep + 1);\n\t}\n\n\tconst content = contentSegment.trim();\n\tif (!content) {\n\t\treturn null;\n\t}\n\n\treturn { path: filePath, lineNumber, content };\n}\n\nexport function parseAndFilterGrepOutput(rawOutput: string, state: GrepState): GrepMatch[] {\n\tconst matches: GrepMatch[] = [];\n\tif (typeof rawOutput !== \"string\" || !rawOutput.trim()) {\n\t\treturn matches;\n\t}\n\n\tfor (const line of rawOutput.split(/\\r?\\n/)) {\n\t\tconst fields = extractMatchFields(line);\n\t\tif (!fields) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (state.isNew(fields.path, fields.lineNumber)) {\n\t\t\tmatches.push(fields);\n\t\t\tstate.add(fields.path, fields.lineNumber);\n\t\t}\n\t}\n\n\treturn matches;\n}\n\nfunction truncateOutput(payload: string, maxChars: number): string {\n\tif (payload.length <= maxChars) {\n\t\treturn payload;\n\t}\n\n\tconst note = \"... (output truncated)\";\n\tconst available = maxChars - note.length - 1;\n\tif (available <= 0) {\n\t\treturn note;\n\t}\n\n\tif (payload.length <= available) {\n\t\treturn `${payload.slice(0, available).replace(/\\n$/, \"\")}\\n${note}`;\n\t}\n\n\tconst core = payload.slice(0, Math.max(0, available - 1));\n\tconst trimmed = core.replace(/\\n$/, \"\").replace(/\\s+$/, \"\");\n\tconst snippet = trimmed ? `${trimmed}…` : \"…\";\n\treturn `${snippet}\\n${note}`;\n}\n\nexport function formatTurnGrepOutput(\n\tmatches: GrepMatch[],\n\tmaxChars: number = MAX_GREP_OUTPUT_CHARS_PER_TURN\n): string {\n\tif (!matches || matches.length === 0) {\n\t\treturn \"No new matches found.\";\n\t}\n\n\tconst matchesByFile = new Map<string, GrepMatch[]>();\n\tfor (const match of matches) {\n\t\tif (!matchesByFile.has(match.path)) {\n\t\t\tmatchesByFile.set(match.path, []);\n\t\t}\n\t\tmatchesByFile.get(match.path)!.push(match);\n\t}\n\n\tconst lines: string[] = [];\n\tconst sortedPaths = Array.from(matchesByFile.keys()).sort();\n\tsortedPaths.forEach((filePath, index) => {\n\t\tif (index > 0) {\n\t\t\tlines.push(\"\");\n\t\t}\n\t\tlines.push(filePath);\n\t\tconst sortedMatches = matchesByFile\n\t\t\t.get(filePath)!\n\t\t\t.slice()\n\t\t\t.sort((a, b) => a.lineNumber - b.lineNumber);\n\t\tfor (const match of sortedMatches) {\n\t\t\tlines.push(`${match.lineNumber}:${match.content}`);\n\t\t}\n\t});\n\n\treturn truncateOutput(lines.join(\"\\n\"), maxChars);\n}\n\n\n"],"mappings":";AAMO,IAAM,YAAN,MAAgB;AAAA,EACL,YAAY,oBAAI,IAAY;AAAA,EAE7C,MAAM,MAAc,YAA6B;AAChD,UAAM,MAAM,KAAK,QAAQ,MAAM,UAAU;AACzC,WAAO,CAAC,KAAK,UAAU,IAAI,GAAG;AAAA,EAC/B;AAAA,EAEA,IAAI,MAAc,YAA0B;AAC3C,SAAK,UAAU,IAAI,KAAK,QAAQ,MAAM,UAAU,CAAC;AAAA,EAClD;AAAA,EAEQ,QAAQ,MAAc,YAA4B;AACzD,WAAO,GAAG,IAAI,IAAI,UAAU;AAAA,EAC7B;AACD;AAEO,IAAM,iCAAi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Y,QAAQ,CAAC,UAAU,UAAU;AACxC,QAAI,QAAQ,GAAG;AACd,YAAM,KAAK,EAAE;AAAA,IACd;AACA,UAAM,KAAK,QAAQ;AACnB,UAAM,gBAAgB,cACpB,IAAI,QAAQ,EACZ,MAAM,EACN,KAAK,CAAC,GAAG,MAAM,EAAE,aAAa,EAAE,UAAU;AAC5C,eAAW,SAAS,eAAe;AAClC,YAAM,KAAK,GAAG,MAAM,UAAU,IAAI,MAAM,OAAO,EAAE;AAAA,IAClD;AAAA,EACD,CAAC;AAED,SAAO,eAAe,MAAM,KAAK,IAAI,GAAG,QAAQ;AACjD;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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, ToolCall, AgentFinish } from './types.js';\nimport { LLMResponseParser } from './parser.js';\nimport type { WarpGrepProvider } from '../providers/types.js';\nimport { toolRead } from '../tools/read.js';\nimport { toolAnalyse } from '../tools/analyse.js';\nimport { fetchWithRetry, withTimeout } from '../../utils/resilience.js';\nimport { formatAgentToolOutput } from './formatter.js';\nimport { GrepState, parseAndFilterGrepOutput, formatTurnGrepOutput } from './grep_helpers.js';\nimport { readFinishFiles } from '../tools/finish.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\nasync function buildInitialState(repoRoot: string, query: string, provider: WarpGrepProvider): Promise<string> {\n // Summarize top-level directories and file counts using the provider\n // This works for both local and remote filesystems (Modal, E2B, etc.)\n try {\n const entries = await provider.analyse({ path: '.', maxResults: 100 });\n const dirs = entries.filter(e => e.type === 'dir').map(d => d.name).slice(0, 50);\n const files = entries.filter(e => e.type === 'file').map(f => f.name).slice(0, 50);\n const parts = [\n `<repo_root>${repoRoot}</repo_root>`,\n `<top_dirs>${dirs.join(', ')}</top_dirs>`,\n `<top_files>${files.join(', ')}</top_files>`,\n ];\n return parts.join('\\n');\n } catch {\n return `<repo_root>${repoRoot}</repo_root>`;\n }\n}\n\nfunction formatAssistantToolBlock(name: string, args: Record<string, unknown>, payload: string, isError = false): string {\n const argStr = Object.entries(args)\n .map(([k, v]) => `${k}=${JSON.stringify(v)}`)\n .join(' ');\n const prefix = isError ? 'error' : 'result';\n return `<${prefix} name=\"${name}\" ${argStr}>\\n${payload}\\n</${prefix}>`;\n}\n\nasync function callModel(messages: ChatMessage[], model: string, apiKey?: string): Promise<string> {\n const api = 'https://api.morphllm.com/v1/chat/completions';\n const fetchPromise = fetchWithRetry(\n api,\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey || process.env.MORPH_API_KEY || ''}`,\n },\n body: JSON.stringify({\n model,\n temperature: 0.0,\n max_tokens: 1024,\n messages,\n }),\n },\n {}\n );\n const resp = await withTimeout(fetchPromise, AGENT_CONFIG.TIMEOUT_MS, 'morph-warp-grep request timed out');\n if (!resp.ok) {\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 repoRoot = path.resolve(config.repoRoot || process.cwd());\n const messages: ChatMessage[] = [];\n\n // system\n const systemMessage = { role: 'system' as const, content: getSystemPrompt() };\n messages.push(systemMessage);\n // user query\n const queryContent = `<query>${config.query}</query>`;\n messages.push({ role: 'user', content: queryContent });\n // initial state\n const initialState = await buildInitialState(repoRoot, config.query, config.provider);\n messages.push({ role: 'user', content: initialState });\n\n const maxRounds = AGENT_CONFIG.MAX_ROUNDS;\n const model = config.model || DEFAULT_MODEL;\n const provider = config.provider;\n const errors: Array<{ message: string }> = [];\n const grepState = new GrepState();\n\n let finishMeta: AgentFinish | undefined;\n let terminationReason: AgentRunResult['terminationReason'] = 'terminated';\n\n for (let round = 1; round <= maxRounds; round += 1) {\n // call model\n const assistantContent = await callModel(messages, model, config.apiKey).catch((e: unknown) => {\n errors.push({ message: e instanceof Error ? e.message : String(e) });\n return '';\n });\n if (!assistantContent) break;\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.' });\n terminationReason = 'terminated';\n break;\n }\n\n const finishCalls = toolCalls.filter(c => c.name === 'finish');\n const grepCalls = toolCalls.filter(c => c.name === 'grep');\n const analyseCalls = toolCalls.filter(c => c.name === 'analyse');\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 // Execute non-grep tools in parallel\n const otherPromises: Array<Promise<string>> = [];\n for (const c of analyseCalls) {\n const args = (c.arguments ?? {}) as { path: string; pattern?: string | null };\n otherPromises.push(\n toolAnalyse(provider, args).then(\n p => formatAgentToolOutput('analyse', args, p, { isError: false }),\n err => formatAgentToolOutput('analyse', args, String(err), { isError: true })\n )\n );\n }\n for (const c of readCalls) {\n const args = (c.arguments ?? {}) as { path: string; start?: number; end?: number };\n otherPromises.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 const otherResults = await Promise.all(otherPromises);\n formatted.push(...otherResults);\n\n // Execute grep calls sequentially like MCP runner to keep outputs compact\n for (const c of grepCalls) {\n const args = (c.arguments ?? {}) as { pattern: string; path: string };\n try {\n const grepRes = await provider.grep({ pattern: args.pattern, path: args.path });\n \n // Check for ripgrep availability error - terminate early with clear message\n if (grepRes.error) {\n errors.push({ message: grepRes.error });\n terminationReason = 'terminated';\n // Return immediately with the error so user knows to install ripgrep\n return {\n terminationReason: 'terminated',\n messages,\n errors,\n };\n }\n \n const rawOutput = Array.isArray(grepRes.lines) ? grepRes.lines.join('\\n') : '';\n const newMatches = parseAndFilterGrepOutput(rawOutput, grepState);\n let formattedPayload = formatTurnGrepOutput(newMatches);\n if (formattedPayload === \"No new matches found.\") {\n formattedPayload = \"no new matches\";\n }\n formatted.push(formatAgentToolOutput('grep', args, formattedPayload, { isError: false }));\n } catch (err) {\n formatted.push(formatAgentToolOutput('grep', args, String(err), { isError: true }));\n }\n }\n\n if (formatted.length > 0) {\n // Add turn counter message\n const turnsUsed = round;\n const turnsRemaining = 4 - turnsUsed;\n let turnMessage: string;\n if (turnsRemaining === 0) {\n turnMessage = `\\n\\n[Turn ${turnsUsed}/4] This is your LAST turn. You MUST call the finish tool now.`;\n } else if (turnsRemaining === 1) {\n turnMessage = `\\n\\n[Turn ${turnsUsed}/4] You have 1 turn remaining. Next turn you MUST call the finish tool.`;\n } else {\n turnMessage = `\\n\\n[Turn ${turnsUsed}/4] You have ${turnsRemaining} turns remaining.`;\n }\n messages.push({ role: 'user', content: formatted.join('\\n') + turnMessage });\n }\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 return { terminationReason, messages, errors };\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.map(([s, e]) => `${s}-${e}`).join(', ');\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 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 // 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 return {\n terminationReason: 'completed',\n messages,\n finish: { payload, metadata: finishMeta, resolved },\n };\n}\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,OAAO,UAAU;AAWjB,IAAM,SAAS,IAAI,kBAAkB;AAErC,eAAe,kBAAkB,UAAkB,OAAe,UAA6C;AAG7G,MAAI;AACF,UAAM,UAAU,MAAM,SAAS,QAAQ,EAAE,MAAM,KAAK,YAAY,IAAI,CAAC;AACrE,UAAM,OAAO,QAAQ,OAAO,OAAK,EAAE,SAAS,KAAK,EAAE,IAAI,OAAK,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE;AAC/E,UAAM,QAAQ,QAAQ,OAAO,OAAK,EAAE,SAAS,MAAM,EAAE,IAAI,OAAK,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE;AACjF,UAAM,QAAQ;AAAA,MACZ,cAAc,QAAQ;AAAA,MACtB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S,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;AAGA,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,SAAO;AAAA,IACL,mBAAmB;AAAA,IACnB;AAAA,IACA,QAAQ,EAAE,SAAS,UAAU,YAAY,SAAS;AAAA,EACpD;AACF;","names":[]}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// tools/warp_grep/agent/grep_helpers.ts
|
|
21
|
-
var grep_helpers_exports = {};
|
|
22
|
-
__export(grep_helpers_exports, {
|
|
23
|
-
GrepState: () => GrepState,
|
|
24
|
-
MAX_GREP_OUTPUT_CHARS_PER_TURN: () => MAX_GREP_OUTPUT_CHARS_PER_TURN,
|
|
25
|
-
formatTurnGrepOutput: () => formatTurnGrepOutput,
|
|
26
|
-
parseAndFilterGrepOutput: () => parseAndFilterGrepOutput
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(grep_helpers_exports);
|
|
29
|
-
var GrepState = class {
|
|
30
|
-
seenLines = /* @__PURE__ */ new Set();
|
|
31
|
-
isNew(path, lineNumber) {
|
|
32
|
-
const key = this.makeKey(path, lineNumber);
|
|
33
|
-
return !this.seenLines.has(key);
|
|
34
|
-
}
|
|
35
|
-
add(path, lineNumber) {
|
|
36
|
-
this.seenLines.add(this.makeKey(path, lineNumber));
|
|
37
|
-
}
|
|
38
|
-
makeKey(path, lineNumber) {
|
|
39
|
-
return `${path}:${lineNumber}`;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
var MAX_GREP_OUTPUT_CHARS_PER_TURN = 6e4;
|
|
43
|
-
function extractMatchFields(payload) {
|
|
44
|
-
const text = payload.replace(/\r?\n$/, "");
|
|
45
|
-
if (!text || text.startsWith("[error]")) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
const firstSep = text.indexOf(":");
|
|
49
|
-
if (firstSep === -1) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
let filePath = text.slice(0, firstSep).trim();
|
|
53
|
-
if (!filePath) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
if (filePath.startsWith("./") || filePath.startsWith(".\\")) {
|
|
57
|
-
filePath = filePath.slice(2);
|
|
58
|
-
}
|
|
59
|
-
const remainder = text.slice(firstSep + 1);
|
|
60
|
-
const secondSep = remainder.indexOf(":");
|
|
61
|
-
if (secondSep === -1) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
const linePart = remainder.slice(0, secondSep);
|
|
65
|
-
const lineNumber = Number.parseInt(linePart, 10);
|
|
66
|
-
if (!Number.isInteger(lineNumber) || lineNumber <= 0) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
let contentSegment = remainder.slice(secondSep + 1);
|
|
70
|
-
const columnSep = contentSegment.indexOf(":");
|
|
71
|
-
if (columnSep !== -1 && /^\d+$/.test(contentSegment.slice(0, columnSep))) {
|
|
72
|
-
contentSegment = contentSegment.slice(columnSep + 1);
|
|
73
|
-
}
|
|
74
|
-
const content = contentSegment.trim();
|
|
75
|
-
if (!content) {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
return { path: filePath, lineNumber, content };
|
|
79
|
-
}
|
|
80
|
-
function parseAndFilterGrepOutput(rawOutput, state) {
|
|
81
|
-
const matches = [];
|
|
82
|
-
if (typeof rawOutput !== "string" || !rawOutput.trim()) {
|
|
83
|
-
return matches;
|
|
84
|
-
}
|
|
85
|
-
for (const line of rawOutput.split(/\r?\n/)) {
|
|
86
|
-
const fields = extractMatchFields(line);
|
|
87
|
-
if (!fields) {
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (state.isNew(fields.path, fields.lineNumber)) {
|
|
91
|
-
matches.push(fields);
|
|
92
|
-
state.add(fields.path, fields.lineNumber);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return matches;
|
|
96
|
-
}
|
|
97
|
-
function truncateOutput(payload, maxChars) {
|
|
98
|
-
if (payload.length <= maxChars) {
|
|
99
|
-
return payload;
|
|
100
|
-
}
|
|
101
|
-
const note = "... (output truncated)";
|
|
102
|
-
const available = maxChars - note.length - 1;
|
|
103
|
-
if (available <= 0) {
|
|
104
|
-
return note;
|
|
105
|
-
}
|
|
106
|
-
if (payload.length <= available) {
|
|
107
|
-
return `${payload.slice(0, available).replace(/\n$/, "")}
|
|
108
|
-
${note}`;
|
|
109
|
-
}
|
|
110
|
-
const core = payload.slice(0, Math.max(0, available - 1));
|
|
111
|
-
const trimmed = core.replace(/\n$/, "").replace(/\s+$/, "");
|
|
112
|
-
const snippet = trimmed ? `${trimmed}\u2026` : "\u2026";
|
|
113
|
-
return `${snippet}
|
|
114
|
-
${note}`;
|
|
115
|
-
}
|
|
116
|
-
function formatTurnGrepOutput(matches, maxChars = MAX_GREP_OUTPUT_CHARS_PER_TURN) {
|
|
117
|
-
if (!matches || matches.length === 0) {
|
|
118
|
-
return "No new matches found.";
|
|
119
|
-
}
|
|
120
|
-
const matchesByFile = /* @__PURE__ */ new Map();
|
|
121
|
-
for (const match of matches) {
|
|
122
|
-
if (!matchesByFile.has(match.path)) {
|
|
123
|
-
matchesByFile.set(match.path, []);
|
|
124
|
-
}
|
|
125
|
-
matchesByFile.get(match.path).push(match);
|
|
126
|
-
}
|
|
127
|
-
const lines = [];
|
|
128
|
-
const sortedPaths = Array.from(matchesByFile.keys()).sort();
|
|
129
|
-
sortedPaths.forEach((filePath, index) => {
|
|
130
|
-
if (index > 0) {
|
|
131
|
-
lines.push("");
|
|
132
|
-
}
|
|
133
|
-
lines.push(filePath);
|
|
134
|
-
const sortedMatches = matchesByFile.get(filePath).slice().sort((a, b) => a.lineNumber - b.lineNumber);
|
|
135
|
-
for (const match of sortedMatches) {
|
|
136
|
-
lines.push(`${match.lineNumber}:${match.content}`);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
return truncateOutput(lines.join("\n"), maxChars);
|
|
140
|
-
}
|
|
141
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
142
|
-
0 && (module.exports = {
|
|
143
|
-
GrepState,
|
|
144
|
-
MAX_GREP_OUTPUT_CHARS_PER_TURN,
|
|
145
|
-
formatTurnGrepOutput,
|
|
146
|
-
parseAndFilterGrepOutput
|
|
147
|
-
});
|
|
148
|
-
//# sourceMappingURL=grep_helpers.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../tools/warp_grep/agent/grep_helpers.ts"],"sourcesContent":["export interface GrepMatch {\n\tpath: string;\n\tlineNumber: number;\n\tcontent: string;\n}\n\nexport class GrepState {\n\tprivate readonly seenLines = new Set<string>();\n\n\tisNew(path: string, lineNumber: number): boolean {\n\t\tconst key = this.makeKey(path, lineNumber);\n\t\treturn !this.seenLines.has(key);\n\t}\n\n\tadd(path: string, lineNumber: number): void {\n\t\tthis.seenLines.add(this.makeKey(path, lineNumber));\n\t}\n\n\tprivate makeKey(path: string, lineNumber: number): string {\n\t\treturn `${path}:${lineNumber}`;\n\t}\n}\n\nexport const MAX_GREP_OUTPUT_CHARS_PER_TURN = 60_000;\n\nfunction extractMatchFields(payload: string): GrepMatch | null {\n\tconst text = payload.replace(/\\r?\\n$/, \"\");\n\tif (!text || text.startsWith(\"[error]\")) {\n\t\treturn null;\n\t}\n\n\tconst firstSep = text.indexOf(\":\");\n\tif (firstSep === -1) {\n\t\treturn null;\n\t}\n\tlet filePath = text.slice(0, firstSep).trim();\n\tif (!filePath) {\n\t\treturn null;\n\t}\n\tif (filePath.startsWith(\"./\") || filePath.startsWith(\".\\\\\")) {\n\t\tfilePath = filePath.slice(2);\n\t}\n\n\tconst remainder = text.slice(firstSep + 1);\n\tconst secondSep = remainder.indexOf(\":\");\n\tif (secondSep === -1) {\n\t\treturn null;\n\t}\n\n\tconst linePart = remainder.slice(0, secondSep);\n\tconst lineNumber = Number.parseInt(linePart, 10);\n\tif (!Number.isInteger(lineNumber) || lineNumber <= 0) {\n\t\treturn null;\n\t}\n\n\tlet contentSegment = remainder.slice(secondSep + 1);\n\tconst columnSep = contentSegment.indexOf(\":\");\n\tif (columnSep !== -1 && /^\\d+$/.test(contentSegment.slice(0, columnSep))) {\n\t\tcontentSegment = contentSegment.slice(columnSep + 1);\n\t}\n\n\tconst content = contentSegment.trim();\n\tif (!content) {\n\t\treturn null;\n\t}\n\n\treturn { path: filePath, lineNumber, content };\n}\n\nexport function parseAndFilterGrepOutput(rawOutput: string, state: GrepState): GrepMatch[] {\n\tconst matches: GrepMatch[] = [];\n\tif (typeof rawOutput !== \"string\" || !rawOutput.trim()) {\n\t\treturn matches;\n\t}\n\n\tfor (const line of rawOutput.split(/\\r?\\n/)) {\n\t\tconst fields = extractMatchFields(line);\n\t\tif (!fields) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (state.isNew(fields.path, fields.lineNumber)) {\n\t\t\tmatches.push(fields);\n\t\t\tstate.add(fields.path, fields.lineNumber);\n\t\t}\n\t}\n\n\treturn matches;\n}\n\nfunction truncateOutput(payload: string, maxChars: number): string {\n\tif (payload.length <= maxChars) {\n\t\treturn payload;\n\t}\n\n\tconst note = \"... (output truncated)\";\n\tconst available = maxChars - note.length - 1;\n\tif (available <= 0) {\n\t\treturn note;\n\t}\n\n\tif (payload.length <= available) {\n\t\treturn `${payload.slice(0, available).replace(/\\n$/, \"\")}\\n${note}`;\n\t}\n\n\tconst core = payload.slice(0, Math.max(0, available - 1));\n\tconst trimmed = core.replace(/\\n$/, \"\").replace(/\\s+$/, \"\");\n\tconst snippet = trimmed ? `${trimmed}…` : \"…\";\n\treturn `${snippet}\\n${note}`;\n}\n\nexport function formatTurnGrepOutput(\n\tmatches: GrepMatch[],\n\tmaxChars: number = MAX_GREP_OUTPUT_CHARS_PER_TURN\n): string {\n\tif (!matches || matches.length === 0) {\n\t\treturn \"No new matches found.\";\n\t}\n\n\tconst matchesByFile = new Map<string, GrepMatch[]>();\n\tfor (const match of matches) {\n\t\tif (!matchesByFile.has(match.path)) {\n\t\t\tmatchesByFile.set(match.path, []);\n\t\t}\n\t\tmatchesByFile.get(match.path)!.push(match);\n\t}\n\n\tconst lines: string[] = [];\n\tconst sortedPaths = Array.from(matchesByFile.keys()).sort();\n\tsortedPaths.forEach((filePath, index) => {\n\t\tif (index > 0) {\n\t\t\tlines.push(\"\");\n\t\t}\n\t\tlines.push(filePath);\n\t\tconst sortedMatches = matchesByFile\n\t\t\t.get(filePath)!\n\t\t\t.slice()\n\t\t\t.sort((a, b) => a.lineNumber - b.lineNumber);\n\t\tfor (const match of sortedMatches) {\n\t\t\tlines.push(`${match.lineNumber}:${match.content}`);\n\t\t}\n\t});\n\n\treturn truncateOutput(lines.join(\"\\n\"), maxChars);\n}\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,IAAM,YAAN,MAAgB;AAAA,EACL,YAAY,oBAAI,IAAY;AAAA,EAE7C,MAAM,MAAc,YAA6B;AAChD,UAAM,MAAM,KAAK,QAAQ,MAAM,UAAU;AACzC,WAAO,CAAC,KAAK,UAAU,IAAI,GAAG;AAAA,EAC/B;AAAA,EAEA,IAAI,MAAc,YAA0B;AAC3C,SAAK,UAAU,IAAI,KAAK,QAAQ,MAAM,UAAU,CAAC;AAAA,EAClD;AAAA,EAEQ,QAAQ,MAAc,YAA4B;AACzD,WAAO,GAAG,IAAI,IAAI,UAAU;AAAA,EAC7B;AACD;AAEO,IAAM,iCAAiC;AAE9C,SAAS,mBAAmB,SAAmC;AAC9D,QAAM,OAAO,QAAQ,QAAQ,UAAU,EAAE;AACzC,MAAI,CAAC,QAAQ,KAAK,WAAW,SAAS,GAAG;AACxC,WAAO;AAAA,EACR;AAEA,QAAM,WAAW,KAAK,QAAQ,GAAG;AACjC,MAAI,aAAa,IAAI;AACpB,WAAO;AAAA,EACR;AACA,MAAI,WAAW,KAAK,MAAM,GAAG,QAAQ,EAAE,KAAK;AAC5C,MAAI,CAAC,UAAU;AACd,WAAO;AAAA,EACR;AACA,MAAI,SAAS,WAAW,IAAI,KAAK,SAAS,WAAW,KAAK,GAAG;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
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
interface GrepMatch {
|
|
2
|
-
path: string;
|
|
3
|
-
lineNumber: number;
|
|
4
|
-
content: string;
|
|
5
|
-
}
|
|
6
|
-
declare class GrepState {
|
|
7
|
-
private readonly seenLines;
|
|
8
|
-
isNew(path: string, lineNumber: number): boolean;
|
|
9
|
-
add(path: string, lineNumber: number): void;
|
|
10
|
-
private makeKey;
|
|
11
|
-
}
|
|
12
|
-
declare const MAX_GREP_OUTPUT_CHARS_PER_TURN = 60000;
|
|
13
|
-
declare function parseAndFilterGrepOutput(rawOutput: string, state: GrepState): GrepMatch[];
|
|
14
|
-
declare function formatTurnGrepOutput(matches: GrepMatch[], maxChars?: number): string;
|
|
15
|
-
|
|
16
|
-
export { type GrepMatch, GrepState, MAX_GREP_OUTPUT_CHARS_PER_TURN, formatTurnGrepOutput, parseAndFilterGrepOutput };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
GrepState,
|
|
3
|
-
MAX_GREP_OUTPUT_CHARS_PER_TURN,
|
|
4
|
-
formatTurnGrepOutput,
|
|
5
|
-
parseAndFilterGrepOutput
|
|
6
|
-
} from "../../../chunk-NDZO5IPV.js";
|
|
7
|
-
import "../../../chunk-PZ5AY32C.js";
|
|
8
|
-
export {
|
|
9
|
-
GrepState,
|
|
10
|
-
MAX_GREP_OUTPUT_CHARS_PER_TURN,
|
|
11
|
-
formatTurnGrepOutput,
|
|
12
|
-
parseAndFilterGrepOutput
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=grep_helpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|