-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwhat-changed.ts
More file actions
54 lines (45 loc) · 1.6 KB
/
what-changed.ts
File metadata and controls
54 lines (45 loc) · 1.6 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
51
52
53
54
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);
// Use array args — run() uses execFileSync, shell operators don't work
let diffFiles = run(["diff", "--name-only", ref]);
if (diffFiles.startsWith("[")) diffFiles = run(["diff", "--name-only", "HEAD~3"]);
let log = run(["log", `${ref}..HEAD`, "--oneline"]);
if (log.startsWith("[")) log = run(["log", "-5", "--oneline"]);
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"}
\`\`\``,
}],
};
}
);
}