Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@ function readJsonSafe(p) {
}
}

function rejectPendingRun(statePath) {
try {
const { getRepoRoot } = require('./src/gep/paths');
const { execSync } = require('child_process');
const repoRoot = getRepoRoot();

execSync('git checkout -- .', { cwd: repoRoot, encoding: 'utf8', timeout: 30000 });
execSync('git clean -fd', { cwd: repoRoot, encoding: 'utf8', timeout: 30000 });
} catch (e) {
console.warn('[Loop] Pending run rollback failed: ' + (e.message || e));
}

try {
const state = readJsonSafe(statePath);
if (state && state.last_run && state.last_run.run_id) {
state.last_solidify = {
run_id: state.last_run.run_id,
rejected: true,
reason: 'loop_bridge_disabled_autoreject',
timestamp: new Date().toISOString(),
};
fs.writeFileSync(statePath, JSON.stringify(state, null, 2) + '\n', 'utf8');
return true;
}
} catch (e) {
console.warn('[Loop] Failed to clear pending run state: ' + (e.message || e));
}

return false;
}

function isPendingSolidify(state) {
const lastRun = state && state.last_run ? state.last_run : null;
const lastSolid = state && state.last_solidify ? state.last_solidify : null;
Expand Down Expand Up @@ -136,6 +167,16 @@ async function main() {
try {
await evolve.run();
ok = true;

if (String(process.env.EVOLVE_BRIDGE || '').toLowerCase() === 'false') {
const stAfterRun = readJsonSafe(solidifyStatePath);
if (isPendingSolidify(stAfterRun)) {
const cleared = rejectPendingRun(solidifyStatePath);
if (cleared) {
console.warn('[Loop] Auto-rejected pending run because bridge is disabled in loop mode.');
}
}
}
} catch (error) {
const msg = error && error.message ? String(error.message) : String(error);
console.error(`Evolution cycle failed: ${msg}`);
Expand Down