-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwhat-changed.ts
More file actions
50 lines (44 loc) · 1.58 KB
/
what-changed.ts
File metadata and controls
50 lines (44 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { z } from "zod";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { run, getBranch, getDiffStat } from "../lib/git.js";
export function registerWhatChanged(server: McpServer): void {
server.tool(
"what_changed",
`Summarize what changed recently. Useful after sub-agents finish, after a break, when context was compacted, or at the start of a new session. Returns diff summary with commit messages.`,
{
since: z.string().optional().describe("Git ref: 'HEAD~5', 'HEAD~3', etc. Default: HEAD~5"),
},
async ({ since }) => {
const ref = since || "HEAD~5";
const diffStat = getDiffStat(ref);
const diffFilesResult = run(["diff", "--name-only", ref]);
const diffFiles = diffFilesResult.startsWith("[") ? run(["diff", "--name-only", "HEAD~3"]) : diffFilesResult;
const logResult = run(["log", `${ref}..HEAD`, "--oneline"]);
const log = logResult.startsWith("[") ? run(["log", "-5", "--oneline"]) : logResult;
const branch = getBranch();
const fileList = diffFiles.split("\n").filter(Boolean);
const fileCount = fileList.length;
const commitCount = log.split("\n").filter(Boolean).length;
return {
content: [{
type: "text" as const,
text: `## What Changed (since ${ref})
Branch: ${branch}
**${commitCount} commits**, **${fileCount} files** changed
### Commits
\`\`\`
${log || "no commits in range"}
\`\`\`
### Files Changed (${fileCount})
\`\`\`
${diffFiles || "none"}
\`\`\`
### Stats
\`\`\`
${diffStat || "no changes"}
\`\`\``,
}],
};
}
);
}