From 4205493acea10067510d28872f20f3ba6f45dc76 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sun, 25 May 2025 22:25:01 +0200 Subject: [PATCH] Refactor commit rewrite logic to use folder object --- main.js | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/main.js b/main.js index a9aff9b..4c5a289 100644 --- a/main.js +++ b/main.js @@ -473,7 +473,13 @@ async function rewordCommitsSequentially(repoPath, commitMessageMap, hashes) { } //---- 6. Workflow ---- -async function runLLMCommitRewrite(folderPath, hashes) { +async function runLLMCommitRewrite(folderObj) { + const hashes = folderObj.llmCandidates; + const birthday = folderObj.firstCandidateBirthday; + const folderPath = folderObj.path; + folderObj.llmCandidates = []; + folderObj.firstCandidateBirthday = null; + folders[idx].linesChanged = 0; const prompt = await generateLLMCommitMessages(folderPath, hashes); const llmRaw = await streamLLMCommitMessages(prompt, chunk => process.stdout.write(chunk)); const commitList = parseLLMCommitMessages(llmRaw); @@ -639,7 +645,7 @@ async function autoCommit(folderPath, message) { folders[idx].llmCandidates.push(newHead); if(folders[idx].llmCandidates.length == 1){ folders[idx].firstCandidateBirthday = Date.now(); - debug('[autoCommit] Erster Commit aufgenommen. Automatischer message-rewrite spätestens: '); + debug('[autoCommit] Erster Commit aufgenommen. Automatischer message-rewrite spätestens: ' Date.now() + (store.get('minutesCommitThreshold')*60*1000) ); } folders[idx].lastHeadHash = newHead; console.log(folders[idx].llmCandidates) @@ -648,11 +654,9 @@ async function autoCommit(folderPath, message) { const threshold = store.get('intelligentCommitThreshold') || 10; if (folders[idx].linesChanged >= threshold) { debug('Congratulations! You changed enough lines of code :)'); - folders[idx].linesChanged = 0; - const cands = folders[idx].llmCandidates; - folders[idx].llmCandidates = []; - folders[idx].firstCandidateBirthday = null; - await runLLMCommitRewrite(folderPath, cands); + + //const cands = folders[idx].llmCandidates; + await runLLMCommitRewrite(folders[idx]); //folders[idx].linesChanged = 0; // !!!!!!!!!!!!!!!!!!!! needs logic to handle several llm runs called at the same time //folders[idx].llmCandidates = []; //folders.[idx].firstCandidateBirthday = null @@ -674,7 +678,21 @@ async function main() { let folders = store.get('folders') || []; /* NEXT BLOCK: MONITOR FOLDERS INITIAL CANDIDATE-COMMITS BIRTHDAY FOR AUTOCOMMIT */ - + /* ─── NEXT BLOCK: MONITOR “BIRTHDAY” FOR AUTOCOMMIT ─── */ + const minutesThreshold = store.get('minutesCommitThreshold'); + const now = Date.now(); + + folders = folders.map(folderObj => { + // only if we’re monitoring and have a birthday timestamp + if (folderObj.firstCandidateBirthday != null) { + const elapsedMin = (now - folderObj.firstCandidateBirthday) / 1000 / 60; + if (elapsedMin >= minutesThreshold) { + runLLMCommitRewrite(folderObj); + } + } + }); + + /* ──────────────────────────────────────────────────── */ /* NEXT BLOCK: MONITOR FOLDER MISSING / RELOCATED */ let updatedFolders = [];