* Run the improvement loop for a just-written or patched file. * * @param {string} filePath * @param {string} userMessage * @param {Array} conversationHistory — mutated in place AND returned * @param {object} config * @param {object} context * context.improvementAttempts — shared attem
(filePath, userMessage, conversationHistory, config, context)
| 32 | * @returns {Promise<{ handled: boolean, newHistory: Array, shouldBreak: boolean }>} |
| 33 | */ |
| 34 | async function verifyAndFixCompiled(filePath, userMessage, conversationHistory, config, context) { |
| 35 | const { |
| 36 | improvementAttempts, |
| 37 | MAX_IMPROVE_ITERATIONS, |
| 38 | escalationEngine, |
| 39 | ALL_TOOLS, |
| 40 | _fullscreenRef, |
| 41 | _testRunnerDetector, |
| 42 | executeTool, |
| 43 | runValidation, |
| 44 | tui, |
| 45 | validateEditFn, |
| 46 | } = context; |
| 47 | |
| 48 | // ── Self-critique (validate_edit) ──────────────────────────────────────── |
| 49 | try { |
| 50 | if (validateEditFn && filePath) { |
| 51 | const fullPath = path.resolve(process.cwd(), filePath); |
| 52 | const written = fs.existsSync(fullPath) |
| 53 | ? fs.readFileSync(fullPath, 'utf-8') |
| 54 | : ''; |
| 55 | const critique = await validateEditFn(filePath, written, userMessage); |
| 56 | if (!critique.ok && critique.issues && critique.issues.length > 0) { |
| 57 | if (_fullscreenRef) _fullscreenRef.addTool('critique', 'err', critique.issues[0].slice(0, 80)); |
| 58 | conversationHistory.push({ |
| 59 | role: 'user', |
| 60 | content: `[SEMANTIC-REVIEW] Potential issue in ${filePath}: ${critique.issues[0]}`, |
| 61 | }); |
| 62 | } |
| 63 | } |
| 64 | } catch {} // never block on self-critique |
| 65 | |
| 66 | // ── Syntax / compile validation ────────────────────────────────────────── |
| 67 | const validation = runValidation(filePath); |
| 68 | |
| 69 | if (!validation || validation.passed) { |
| 70 | // Passed — reset counter if we had been retrying |
| 71 | if (improvementAttempts[filePath] > 0) { |
| 72 | try { tui && console.log(tui.improvementFixed(filePath, improvementAttempts[filePath])); } catch {} |
| 73 | improvementAttempts[filePath] = 0; |
| 74 | } |
| 75 | return { handled: false, newHistory: conversationHistory, shouldBreak: false }; |
| 76 | } |
| 77 | |
| 78 | // Validation failed |
| 79 | if (!improvementAttempts[filePath]) improvementAttempts[filePath] = 0; |
| 80 | improvementAttempts[filePath]++; |
| 81 | |
| 82 | const attempt = improvementAttempts[filePath]; |
| 83 | |
| 84 | // Track attempt history |
| 85 | const historyKey = `__history:${filePath}`; |
| 86 | if (!improvementAttempts[historyKey]) improvementAttempts[historyKey] = []; |
| 87 | improvementAttempts[historyKey].push({ attempt, errors: validation.errors.slice(0, 3) }); |
| 88 | |
| 89 | if (attempt <= MAX_IMPROVE_ITERATIONS) { |
| 90 | try { tui && console.log(tui.improvementLoop(validation.errors, attempt, MAX_IMPROVE_ITERATIONS)); } catch {} |
| 91 |
nothing calls this directly
no test coverage detected