F3 SLICE-5 review fixes: fence-aware replacement extraction + editSelection guards (#6)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+10
-3
@@ -24,8 +24,15 @@ const SYSTEM_PROMPT = [
|
||||
"unless the instruction says otherwise.",
|
||||
].join(" ");
|
||||
|
||||
/** Strip a wrapping markdown code fence if the model added one anyway. */
|
||||
export function extractReplacement(outputText: string): string {
|
||||
/**
|
||||
* Strip a wrapping markdown code fence if the model added one anyway.
|
||||
* If `selectedText` itself was fence-wrapped (i.e. the user's selection was a
|
||||
* fenced block), the model mirroring that format is correct — return
|
||||
* `outputText` unchanged so the fence is preserved.
|
||||
*/
|
||||
export function extractReplacement(outputText: string, selectedText: string): string {
|
||||
const fencePattern = /^\s*```[^\n]*\n[\s\S]*?\n?```\s*$/;
|
||||
if (fencePattern.test(selectedText)) return outputText;
|
||||
const m = outputText.match(/^\s*```[^\n]*\n([\s\S]*?)\n?```\s*$/);
|
||||
return m ? m[1] : outputText;
|
||||
}
|
||||
@@ -53,5 +60,5 @@ export async function runEditTurn(
|
||||
"(is Claude Code installed and signed in?)",
|
||||
);
|
||||
}
|
||||
return { replacement: extractReplacement(result.outputText), model: modelId, sessionId: result.runId };
|
||||
return { replacement: extractReplacement(result.outputText, selectedText), model: modelId, sessionId: result.runId };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user