46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { parametersSchema as z, defineCustomTool } from "@roo-code/types"
|
|
import { spawnSync } from "child_process"
|
|
|
|
export default defineCustomTool({
|
|
name: "git_recent_changes",
|
|
description: "Get recent git commits across all branches as structured JSON. Shows hash, branch, author, date, and message. Useful at session start for situational awareness.",
|
|
parameters: z.object({
|
|
repoPath: z.string().optional().describe("Path to git repo (required)"),
|
|
count: z.number().optional().describe("Number of commits to return. Default: 15"),
|
|
branch: z.string().optional().describe("Specific branch to query. Default: --all (all branches)"),
|
|
}),
|
|
async execute({ repoPath, count = 15, branch }) {
|
|
const repo = repoPath
|
|
const args = ["-C", repo, "log", "--oneline", `--max-count=${count}`, "--format=%H|%h|%an|%ai|%D|%s"]
|
|
|
|
if (branch) {
|
|
args.push(branch)
|
|
} else {
|
|
args.push("--all")
|
|
}
|
|
|
|
const result = spawnSync("git", args, {
|
|
encoding: "utf-8",
|
|
timeout: 10000,
|
|
})
|
|
|
|
if (result.status !== 0) {
|
|
return `Error: ${result.stderr || "git log failed"}`
|
|
}
|
|
|
|
const commits = result.stdout.trim().split("\n").filter(Boolean).map(line => {
|
|
const [hash, shortHash, author, date, refs, ...msgParts] = line.split("|")
|
|
return {
|
|
hash,
|
|
shortHash,
|
|
author,
|
|
date,
|
|
refs: refs || null,
|
|
message: msgParts.join("|"),
|
|
}
|
|
})
|
|
|
|
return JSON.stringify(commits, null, 2)
|
|
},
|
|
})
|