aida_log_files
Log file changes from git diffs to track code modifications and line counts for AI development observability.
Instructions
记录文件变更。无需传参,自动扫描 git diff 获取变更文件列表和行数。在完成一轮代码修改后调用。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp/server.ts:470-558 (handler)The handler function 'handleLogFiles' implements the 'aida_log_files' tool logic. It scans git diffs, parses changes, updates the project run data, and saves the result.
function handleLogFiles(): any { const { path, data } = ensureRunJson(); // Auto-scan git diff let diffOutput = ''; try { diffOutput = execSync('git diff --stat HEAD', { cwd: projectRoot, encoding: 'utf-8' }); } catch { // If no HEAD (first commit), try against empty tree try { diffOutput = execSync('git diff --stat --cached', { cwd: projectRoot, encoding: 'utf-8' }); } catch { return { success: true, message: '没有检测到文件变更', filesLogged: 0 }; } } if (!diffOutput.trim()) { return { success: true, message: '没有检测到文件变更', filesLogged: 0 }; } // Parse git diff --stat output // Format: " src/foo.ts | 10 ++++------" or " src/bar.ts | 5 +++++" const lines = diffOutput.split('\n').filter(l => l.includes('|')); let totalAdded = 0; let totalRemoved = 0; const filesLogged: string[] = []; for (const line of lines) { const match = line.match(/^\s*(.+?)\s*\|\s*(\d+)\s*([+-]*)/); if (!match) continue; const filePath = match[1].trim(); const changes = parseInt(match[2]) || 0; const indicators = match[3] || ''; // Count + and - in the indicators const plusCount = (indicators.match(/\+/g) || []).length; const minusCount = (indicators.match(/-/g) || []).length; const total = plusCount + minusCount; let linesAdded = 0; let linesRemoved = 0; if (total > 0) { linesAdded = Math.round(changes * plusCount / total); linesRemoved = Math.round(changes * minusCount / total); } else { linesAdded = changes; } // Determine change type let changeType: 'created' | 'modified' | 'deleted' = 'modified'; if (linesRemoved === 0 && linesAdded > 0) changeType = 'created'; const existing = data.files.find(f => f.path === filePath); if (existing) { existing.changeCount = (existing.changeCount || 1) + 1; existing.linesAdded += linesAdded; existing.linesRemoved += linesRemoved; existing.lastModified = now(); } else { data.files.push({ path: filePath, changeType, linesAdded, linesRemoved, changeCount: 1, lastModified: now(), }); } totalAdded += linesAdded; totalRemoved += linesRemoved; filesLogged.push(filePath); } data.summary.filesChanged = data.files.length; data.summary.linesAdded = data.files.reduce((s, f) => s + (f.linesAdded || 0), 0); data.summary.linesRemoved = data.files.reduce((s, f) => s + (f.linesRemoved || 0), 0); addEvent(data, 'files_scanned', { count: filesLogged.length }); save(path, data); return { success: true, filesLogged: filesLogged.length, linesAdded: totalAdded, linesRemoved: totalRemoved, message: `${filesLogged.length} files logged (+${totalAdded} -${totalRemoved})`, }; } - src/mcp/server.ts:701-703 (registration)Tool registration for 'aida_log_files' within the main message switch-case block.
case 'aida_log_files': result = handleLogFiles(); break;