Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (self): widen the local-reviewer diff fence so the diff can't close it early
[._.]/ Adam Eivye919de9116f1
diff --git a/server/services/codeReview.js b/server/services/codeReview.jsindex f561da9f4c..a9577d5a0e 100644--- a/server/services/codeReview.js+++ b/server/services/codeReview.js@@ -202,11 +202,19 @@ export async function runLocalCodeReview({ backend, model, diff, timeoutMs = 120}const baseUrl = BACKEND_BASE_URLS[backend]()+ // The diff is untrusted content flowing into a fenced code block — a diff+ // touching a file that itself contains a ``` sequence (e.g. editing this+ // very prompt-fence, or a markdown/doc file) would close the fence early,+ // turning the remainder of the diff into free text the model can read as+ // instructions. A fence longer than any backtick run already in the diff+ // can't be closed by the diff's own content (the same technique GitHub uses+ // to nest a fenced block inside a fenced block).+ const fence = '`'.repeat(Math.max(3, ...(trimmedDiff.match(/`+/g) || ['']).map((run) => run.length + 1)))const body = {model,messages: [{ role: 'system', content: CODE_REVIEW_SYSTEM_PROMPT },- { role: 'user', content: `Review this PR diff:\n\n\`\`\`diff\n${trimmedDiff}\n\`\`\`` },+ { role: 'user', content: `Review this PR diff:\n\n${fence}diff\n${trimmedDiff}\n${fence}` },],temperature: 0.2,stream: false,diff --git a/server/services/codeReview.test.js b/server/services/codeReview.test.jsindex 30f35e5161..4039fcb7d0 100644--- a/server/services/codeReview.test.js+++ b/server/services/codeReview.test.js@@ -280,6 +280,29 @@ describe('codeReview helpers', () => {expect(body.messages[1].content).toContain('diff --git a b')})+ it('widens the fence so a diff containing ``` cannot close it early', async () => {+ // A diff touching a markdown file can legitimately contain a fenced+ // code block of its own. A hardcoded ``` wrapper would let that content+ // close the outer fence, turning the rest of the diff into free text+ // the model reads as instructions rather than diff content.+ const diff = 'diff --git a/README.md b/README.md\n+```js\n+const x = 1\n+```\n'+ await runLocalCodeReview({ backend: 'ollama', model: 'm', diff })+ const body = JSON.parse(global.fetch.mock.calls[0][1].body)+ const content = body.messages[1].content+ const fenceMatch = content.match(/^Review this PR diff:\n\n(`{3,})diff\n/)+ expect(fenceMatch).not.toBeNull()+ const [, fence] = fenceMatch+ // The chosen fence must be longer than every backtick run in the diff.+ expect(fence.length).toBeGreaterThan(3)+ expect(content).toContain(diff)+ // Only the trailing closing fence line may equal the chosen fence — no+ // line WITHIN the diff itself (its own ``` fences) may match or exceed+ // it, which is what would let the diff's content close the block early.+ const lines = content.split('\n')+ expect(lines.at(-1)).toBe(fence)+ expect(lines.slice(0, -1)).not.toContain(fence)+ })+it('surfaces a non-2xx HTTP error with the status code', async () => {global.fetch = vi.fn().mockResolvedValue(mockTextResponse('boom', { ok: false, status: 500 }))const r = await runLocalCodeReview({ backend: 'lmstudio', model: 'm', diff: 'x' })