update_last_editor
Updates the last editor field in files using Git author data to maintain accurate contributor records for project tracking.
Instructions
Update @last-editor field in a file with Git author information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Path to the file to update |
Implementation Reference
- src/index.ts:914-922 (handler)MCP server tool handler for 'update_last_editor' that delegates to GitUtils.updateLastEditorInFile and returns success/error responsecase 'update_last_editor': { const filePath = args.filePath as string; const result = await this.gitUtils.updateLastEditorInFile(filePath); if (result.success) { return { content: [{ type: 'text', text: `Last editor updated successfully for: ${filePath}. New editor: ${result.newEditor}` }] }; } else { return { content: [{ type: 'text', text: `Failed to update last editor for: ${filePath}. Reason: ${result.reason}` }] }; } }
- src/git-utils.ts:131-156 (handler)Core implementation of updateLastEditorInFile: gets last editor from Git, updates @last-editor metadata comment in file, writes if changedasync updateLastEditorInFile(filePath: string): Promise<{success: boolean, newEditor?: string, reason?: string}> { try { const relativePath = path.relative(this.projectRoot, filePath); const lastEditor = await this.getFileLastEditor(relativePath); if (lastEditor === 'unknown') { return { success: false, reason: 'Could not determine last editor from Git' }; } const content = await fs.readFile(filePath, 'utf8'); const updatedContent = content.replace( /^(\s*\*\s*@last-editor:\s*).*$/m, `$1${lastEditor}` ); if (content !== updatedContent) { await fs.writeFile(filePath, updatedContent, 'utf8'); return { success: true, newEditor: lastEditor }; } return { success: false, reason: 'File already up to date' }; } catch (error) { console.error(`Error updating last editor in ${filePath}:`, error); return { success: false, reason: `Error: ${error}` }; } }
- src/index.ts:746-756 (registration)Tool registration in ListTools response, including name, description, and input schema{ name: 'update_last_editor', description: 'Update @last-editor field in a file with Git author information', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the file to update' } }, required: ['filePath'] } },
- src/git-utils.ts:34-52 (helper)Helper method getLastEditor that runs 'git log -1 --pretty=format:%an' to get the last commit author name for a fileasync getLastEditor(filePath: string): Promise<string> { try { const absolutePath = path.resolve(this.projectRoot, filePath); const relativePath = path.relative(this.projectRoot, absolutePath); // Use git log to get the last author who modified the file const command = `git log -1 --pretty=format:"%an" -- "${relativePath}"`; const result = execSync(command, { cwd: this.projectRoot, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim(); return result || 'unknown'; } catch (error) { console.warn(`Could not get git information for ${filePath}:`, error); return 'unknown'; } }