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

Function verifyAndFixCompiled

src/compiled/features/verify_and_fix.js:34–236  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

32 * @returns {Promise<{ handled: boolean, newHistory: Array, shouldBreak: boolean }>}
33 */
34async 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

Callers

nothing calls this directly

Calls 12

decomposeTaskFunction · 0.85
pickDecomposeStrategyFunction · 0.85
getSnapshotManagerFunction · 0.85
addToolMethod · 0.80
canEscalateMethod · 0.80
rollbackMethod · 0.80
escalateMethod · 0.65
writeMethod · 0.65
runValidationFunction · 0.50
executeToolFunction · 0.50
detectMethod · 0.45
isActiveMethod · 0.45

Tested by

no test coverage detected