1
0

Update API endpoint to use localhost for all network requests

This commit is contained in:
2025-06-01 23:26:25 +02:00
parent e16d45c64f
commit 66346d56b3

112
main.js Normal file → Executable file
View File

@@ -174,7 +174,7 @@ function killOllamaOnPort() {
async function ensureOllamaRunning() { async function ensureOllamaRunning() {
function pingOllama() { function pingOllama() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const req = http.request({ hostname: 'localhost', port: 11434, path: '/', method: 'GET', timeout: 500 }, res => { const req = http.request({ hostname: '127.0.0.1', port: 11434, path: '/', method: 'GET', timeout: 500 }, res => {
res.destroy(); resolve(true); res.destroy(); resolve(true);
}); });
req.on('error', reject); req.on('error', reject);
@@ -810,7 +810,7 @@ ${JSON.stringify(commits, null, 2)}
async function streamLLMCommitMessages(prompt, onDataChunk, win) { async function streamLLMCommitMessages(prompt, onDataChunk, win) {
await ensureOllamaRunning(); await ensureOllamaRunning();
const selectedModel = store.get('commitModel') || 'qwen2.5-coder:7b'; const selectedModel = store.get('commitModel') || 'qwen2.5-coder:7b';
const response = await fetch('http://localhost:11434/api/generate', { const response = await fetch('http://127.0.0.1:11434/api/generate', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ body: JSON.stringify({
@@ -863,7 +863,7 @@ async function streamLLMCommitMessages(prompt, onDataChunk, win) {
async function streamLLMREADME(prompt, onDataChunk, win) { async function streamLLMREADME(prompt, onDataChunk, win) {
await ensureOllamaRunning(); await ensureOllamaRunning();
const selectedModel = store.get('readmeModel') || 'qwen2.5-coder:32b'; const selectedModel = store.get('readmeModel') || 'qwen2.5-coder:32b';
const response = await fetch('http://localhost:11434/api/generate', { const response = await fetch('http://127.0.0.1:11434/api/generate', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ body: JSON.stringify({
@@ -951,77 +951,93 @@ function parseLLMCommitMessages(rawOutput) {
// --- Hauptfunktion --- // --- Hauptfunktion ---
/** /**
* Rewords commit messages for each hash (oldest to newest) using git rebase -i in a loop. * Plattformübergreifendes Rewording von Commit-Nachrichten.
* @param {string} repoPath - Path to your repo *
* @param {object} commitMessageMap - { fullHash: newMessage } * @param {string} repoPath Pfad zum Git-Repo
* @param {string[]} hashes - array of full commit hashes (oldest first!) * @param {object} commitMessageMap Objekt { "<shortOderFullHash>": "<neue Nachricht>" }
* @param {string[]} hashes Array mit kurzen/vollen Hashes (älteste zuerst)
*/ */
async function rewordCommitsSequentially(repoPath, commitMessageMap, hashes) { async function rewordCommitsSequentially(repoPath, commitMessageMap, hashes) {
const git = simpleGit(repoPath); const git = simpleGit(repoPath);
// Sort hashes... // --- Schritt 1: Alle Commits holen und die übergebenen Hashes chronologisch sortieren ---
const allCommits = (await git.log()).all; const allCommits = (await git.log()).all;
const hashesOrdered = hashes const hashesOrdered = hashes
.map(h => allCommits.find(c => c.hash.startsWith(h))) .map(h => allCommits.find(c => c.hash.startsWith(h)))
.filter(Boolean) .filter(Boolean)
.sort((a, b) => .sort((a, b) =>
allCommits.findIndex(c => c.hash === a.hash) - allCommits.findIndex(c => c.hash === b.hash) allCommits.findIndex(c => c.hash === a.hash)
- allCommits.findIndex(c => c.hash === b.hash)
) )
.map(c => c.hash); .map(c => c.hash);
// EIN Loop! for (const fullHash of hashesOrdered) {
for (const hash of hashesOrdered) { // --- Schritt 2: Neue Nachricht für den Commit suchen ---
// --- Lookup: full hash oder short hash let newMsg = commitMessageMap[fullHash]
let msg = commitMessageMap[hash]; || commitMessageMap[fullHash.substring(0, 7)];
if (!msg) msg = commitMessageMap[hash.substring(0, 7)]; if (!newMsg) {
if (!msg) { console.warn('[AutoGit] Kein neue Nachricht gefunden für Hash:', fullHash);
console.warn('No commit message found for hash', hash, 'or', hash.substring(0, 7));
continue; continue;
} }
const commitMsg = msg.replace(/(["$`\\])/g, '\\$1'); // Escape für Zeichen wie ", $, `, \
const sequenceEditor = `sed -i '' '1s/pick/reword/'`; const commitMsgEscaped = newMsg.replace(/(["$`\\])/g, '\\$1');
try { // --- Schritt 3: Vorherigen Rebase abbrechen, falls offen (Fehler ignorieren) ---
await new Promise((resolve, reject) => { await new Promise(resolve => {
const abortProc = spawn('git', ['rebase', '--abort'], { const abortProc = spawn('git', ['rebase', '--abort'], {
cwd: repoPath, cwd: repoPath,
env: process.env, stdio: 'ignore'
stdio: 'inherit'
});
abortProc.on('exit', code => {
if (code === 0) {
console.log('[AutoGit] Vorheriger Rebase-Prozess wurde abgebrochen.');
} else {
console.log('[AutoGit] Kein laufender Rebase-Prozess zum Abbrechen (vermutlich).');
}
resolve(); // Selbst bei Fehler einfach weiter
});
}); });
} catch (err) { abortProc.on('exit', () => resolve());
console.warn('[AutoGit] Fehler beim Abbrechen des Rebase-Prozesses:', err.message); }).catch(() => {
/* Ignoriere, falls kein Rebase läuft */
});
// --- Schritt 4: GIT_SEQUENCE_EDITOR plattformspezifisch setzen ---
let sequenceEditor;
if (process.platform === 'win32') {
// Windows: Nutze unser kleines Node-Skript, das in rebase-sequence-windows.js liegt.
// Git ruft später automatisch „node rebase-sequence-windows.js <todoFile>“ auf.
sequenceEditor = `node "${path.join(__dirname, 'rebase-sequence-windows.js')}"`;
} else {
// macOS / Linux: Der gewohnte sed-Aufruf („-i ''“ für macOS-kompatibel)
sequenceEditor = `sed -i '' '1s/^pick /reword /'`;
} }
// --- Schritt 5: GIT_EDITOR-Befehl erzeugen (schreibt die neue Commit-Nachricht) ---
// Beispiel: echo "Mein neuer Message-Text" >
const gitEditor = `echo "${commitMsgEscaped}" >`;
// await auf Promise aber OHNE zweiten for! // --- Schritt 6: Interaktives Rebase starten ---
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
const proc = spawn('git', [ const env = {
'rebase', '-i', `${hash}^` ...process.env,
], { GIT_SEQUENCE_EDITOR: sequenceEditor,
GIT_EDITOR: gitEditor
};
const proc = spawn('git', ['rebase', '-i', `${fullHash}^`], {
cwd: repoPath, cwd: repoPath,
env: { env: env,
...process.env,
GIT_SEQUENCE_EDITOR: sequenceEditor,
GIT_EDITOR: `echo "${commitMsg}" >`
},
stdio: 'inherit' stdio: 'inherit'
}); });
proc.on('exit', code => code === 0 ? resolve() : reject(new Error(`Failed to reword ${hash}`)));
proc.on('exit', code => {
if (code === 0) {
console.log(`[AutoGit] Commit ${fullHash.substring(0,7)} erfolgreich reworded.`);
resolve();
} else {
reject(new Error(`Rewording für ${fullHash.substring(0,7)} fehlgeschlagen (ExitCode=${code})`));
}
});
}); });
console.log(`[AutoGit] Reworded commit ${hash}`);
} }
console.log('[AutoGit] All specified commit messages updated!');
console.log('[AutoGit] Alle Commit-Nachrichten wurden aktualisiert.');
} }
module.exports = { rewordCommitsSequentially };
//---- 6. Workflow ---- //---- 6. Workflow ----
async function runLLMCommitRewrite(folderObj, win) { async function runLLMCommitRewrite(folderObj, win) {
if(!folderObj.needsRelocation){ if(!folderObj.needsRelocation){
@@ -1498,7 +1514,7 @@ function buildTrayMenu() {
// 3) Stream it through Ollama (same model as README) // 3) Stream it through Ollama (same model as README)
await ensureOllamaRunning(); await ensureOllamaRunning();
const response = await fetch('http://localhost:11434/api/generate', { const response = await fetch('http://127.0.0.1:11434/api/generate', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ body: JSON.stringify({