Ferrell Synthetic Intelligence commited on
Commit ·
ef15e72
1
Parent(s): 8e0c3e6
Add bounded model patch repair loop
Browse files
app.js
CHANGED
|
@@ -43,6 +43,7 @@ export interface ModelManifest {
|
|
| 43 |
|
| 44 |
const $ = selector => document.querySelector(selector);
|
| 45 |
const esc = value => String(value).replace(/[&<>"']/g, char => ({ '&':'&', '<':'<', '>':'>', '"':'"', "'":''' }[char]));
|
|
|
|
| 46 |
|
| 47 |
function openFile(name) {
|
| 48 |
const text = state.files[name] || state.files['agent.ts'];
|
|
@@ -150,7 +151,12 @@ async function runReview() {
|
|
| 150 |
const findings = await requestLocal(research, [{ role: 'system', content: research.system_prompt }, { role: 'user', content: task }]);
|
| 151 |
appendLog('RESEARCH', findings);
|
| 152 |
if (builder.status === 'pending') throw new Error('Coding lane is not configured. Install a coding checkpoint before applying patches.');
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
appendLog('BUILD', patch, 'patch');
|
| 155 |
if (verifier.status === 'pending') throw new Error('Verifier lane is not configured.');
|
| 156 |
const verdict = await requestLocal(verifier, [{ role: 'system', content: verifier.system_prompt }, { role: 'user', content: `Task: ${task}\nProposed patch:\n${patch}\nReturn APPROVE, REJECT, or NEEDS-EVIDENCE with reasons.` }]);
|
|
|
|
| 43 |
|
| 44 |
const $ = selector => document.querySelector(selector);
|
| 45 |
const esc = value => String(value).replace(/[&<>"']/g, char => ({ '&':'&', '<':'<', '>':'>', '"':'"', "'":''' }[char]));
|
| 46 |
+
const patchValid = value => /^diff --git\s+\S+\s+\S+/m.test(value) && /^---\s+/m.test(value) && /^\+\+\+\s+/m.test(value) && !/^```/m.test(value);
|
| 47 |
|
| 48 |
function openFile(name) {
|
| 49 |
const text = state.files[name] || state.files['agent.ts'];
|
|
|
|
| 151 |
const findings = await requestLocal(research, [{ role: 'system', content: research.system_prompt }, { role: 'user', content: task }]);
|
| 152 |
appendLog('RESEARCH', findings);
|
| 153 |
if (builder.status === 'pending') throw new Error('Coding lane is not configured. Install a coding checkpoint before applying patches.');
|
| 154 |
+
let patch = await requestLocal(builder, [{ role: 'system', content: builder.system_prompt }, { role: 'user', content: `Task: ${task}\nResearch findings:\n${findings}\nReturn a unified diff only.` }]);
|
| 155 |
+
if (!patchValid(patch)) {
|
| 156 |
+
appendLog('REPAIR', 'Builder output was not a valid unified diff. Requesting one bounded repair.', 'warning');
|
| 157 |
+
patch = await requestLocal(builder, [{ role: 'system', content: 'Convert the raw response into one valid unfenced unified diff. Preserve intent. Return only the diff. Do not invent files or claim tests passed.' }, { role: 'user', content: `Task: ${task}\nRaw response:\n${patch}` }]);
|
| 158 |
+
}
|
| 159 |
+
if (!patchValid(patch)) throw new Error('Patch repair failed structural validation; no files changed.');
|
| 160 |
appendLog('BUILD', patch, 'patch');
|
| 161 |
if (verifier.status === 'pending') throw new Error('Verifier lane is not configured.');
|
| 162 |
const verdict = await requestLocal(verifier, [{ role: 'system', content: verifier.system_prompt }, { role: 'user', content: `Task: ${task}\nProposed patch:\n${patch}\nReturn APPROVE, REJECT, or NEEDS-EVIDENCE with reasons.` }]);
|