MCPcopy
hub / github.com/Doorman11991/smallcode / semanticMerge

Function semanticMerge

bin/features_adapter.js:352–369  ·  view source on GitHub ↗

* Recover from a patch failure by asking the model to merge the intended * change into the current file content. * MarrowScript Rank 7: called when old_str is not found in patch case. * TTL 1m (content-specific — caching rarely helps). * * @param {string} filePath - File being patched *

(filePath, intendedChange, currentContent)

Source from the content-addressed store, hash-verified

350 * @returns {Promise<string|null>} New complete file content, or null on failure
351 */
352async function semanticMerge(filePath, intendedChange, currentContent) {
353 const prompts = _getPrompts();
354 if (!prompts) return null;
355 try {
356 const traceId = require('crypto').randomUUID();
357 const result = await prompts.callPrompt('semantic_merge', {
358 file: filePath,
359 intended_change: String(intendedChange),
360 current_content: String(currentContent),
361 }, { trace_id: traceId });
362 const text = String(result).trim();
363 // Strip any accidental code fences the model may have added
364 const stripped = text.replace(/^```[^\n]*\n/, '').replace(/\n```$/, '');
365 return stripped.length > 0 ? stripped : null;
366 } catch {
367 return null;
368 }
369}
370
371// ─── Availability check ───────────────────────────────────────────────────────
372

Callers 1

executeToolFunction · 0.85

Calls 1

_getPromptsFunction · 0.85

Tested by

no test coverage detected