get_history
Retrieve git commit history for a file to understand its evolution before editing or restoring. Returns newest-first entries with hash, message, date, and author.
Instructions
Return the git commit history for one file (newest first), each entry with hash, message, date, and author. Reads the file's owning repo: the project's git repo for project files, the KB backup repo for KB files. Read-only; no side effects, auth, or rate limits. Returns {file_id, path, history}; an empty array means the file has not been committed yet. Use to understand a file's evolution before editing or restoring. Pair with get_diff to see exact line changes; use restore_file to roll back.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_id | Yes | ID of the file |
Implementation Reference
- packages/core/src/git/index.ts:100-115 (handler)The core implementation of getHistory. Uses simple-git to get the git log for a file and returns an array of {hash, message, date, author} objects.
export async function getHistory( repoDir: string, filePath: string ): Promise<Array<{ hash: string; message: string; date: string; author: string }>> { const git: SimpleGit = gitFor(repoDir); const relativePath = relative(repoDir, filePath); const log: LogResult = await git.log({ file: relativePath }); return log.all.map((commit) => ({ hash: commit.hash, message: commit.message, date: commit.date, author: commit.author_name, })); } - apps/mcp/src/index.ts:875-893 (schema)The MCP tool registration for get_history. Defines the Zod schema (file_id: number), handler logic calling readFile + getHistory, and the description string.
server.tool( "get_history", "Return the git commit history for one file (newest first), each entry with hash, message, date, and author. Reads the file's owning repo: the project's git repo for project files, the KB backup repo for KB files. Read-only; no side effects, auth, or rate limits. Returns `{file_id, path, history}`; an empty array means the file has not been committed yet. Use to understand a file's evolution before editing or restoring. Pair with `get_diff` to see exact line changes; use `restore_file` to roll back.", { file_id: z.number().describe("ID of the file"), }, async ({ file_id }) => { const file = readFile(file_id); const history = await getHistory(repoDirForFile(file), file.path); return { content: [ { type: "text", text: JSON.stringify({ file_id, path: file.path, history }, null, 2), }, ], }; } ); - packages/core/src/index.ts:11-11 (registration)Re-exports getHistory from the git module in the core package's public API.
export { commitFile, getHistory, getDiff, restoreVersion, syncBackup, syncGlobalVault, getGlobalRemote, setGlobalRemote, isValidGitRemoteUrl, type SyncStage } from "./git/index.js"; - apps/mcp/src/index.ts:865-873 (helper)Helper function repoDirForFile used by the get_history handler to determine the correct git repository directory based on file storage type.
function repoDirForFile(file: { storage_type: string; project_id: number | null }): string { if (file.storage_type === "reference" && file.project_id) { const project = getDatabase() .prepare("SELECT path FROM projects WHERE id = ?") .get(file.project_id) as { path: string | null } | undefined; if (project?.path) return project.path; } return dataDir; } - Categorizes get_history under 'Versioning' in the web UI tool category map.
get_history: "Versioning", get_diff: "Versioning", restore_file: "Versioning", commit_backup: "Versioning", // Discovery stats: "Discovery", whats_new: "Discovery", project_map: "Discovery", diff_against_disk: "Discovery", refresh_index: "Discovery",