get_collaboration_metrics
Analyze team collaboration patterns in a git repository by specifying a date range to identify contribution distribution and teamwork dynamics.
Instructions
Analyze team collaboration patterns
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes | Path to git repository | |
| since | Yes | Start date (YYYY-MM-DD) | |
| until | No | End date (YYYY-MM-DD), optional |
Implementation Reference
- src/handlers.ts:244-290 (handler)The handler function `handleGetCollaborationMetrics` that executes the tool logic. It runs a git log command to find files modified by multiple authors, then computes pairwise collaboration counts (number of shared files between author pairs). Returns collaborative files count and top 10 collaborations.
export function handleGetCollaborationMetrics(args: any) { const { repo_path, since, until } = args; validateRepoPath(repo_path); validateDate(since, "since"); if (until) validateDate(until, "until"); let cmd = `git log --since="${since}"`; if (until) cmd += ` --until="${until} 23:59:59"`; cmd += ` --pretty=format:"%an <%ae>" --name-only`; const output = runGitCommand(repo_path, cmd); const lines = output.trim().split("\n"); const fileAuthors: Record<string, Set<string>> = {}; let currentAuthor = ""; for (const line of lines) { if (line.includes("<") && line.includes(">")) { currentAuthor = line; } else if (line.trim() && currentAuthor) { if (!fileAuthors[line]) fileAuthors[line] = new Set(); fileAuthors[line].add(currentAuthor); } } const collaborations: Record<string, number> = {}; for (const authors of Object.values(fileAuthors)) { if (authors.size > 1) { const authorList = Array.from(authors).sort(); for (let i = 0; i < authorList.length; i++) { for (let j = i + 1; j < authorList.length; j++) { const pair = `${authorList[i]} <-> ${authorList[j]}`; collaborations[pair] = (collaborations[pair] || 0) + 1; } } } } return { collaborativeFiles: Object.values(fileAuthors).filter(a => a.size > 1).length, topCollaborations: Object.entries(collaborations) .sort(([, a], [, b]) => b - a) .slice(0, 10) .map(([pair, sharedFiles]) => ({ pair, sharedFiles })), }; } - src/git-metrics.ts:189-201 (schema)Tool registration with input schema for `get_collaboration_metrics`. Defines name, description, and input parameters (repo_path, since, until) with required fields.
{ name: "get_collaboration_metrics", description: "Analyze team collaboration patterns", inputSchema: { type: "object", properties: { repo_path: { type: "string", description: "Path to git repository" }, since: { type: "string", description: "Start date (YYYY-MM-DD)" }, until: { type: "string", description: "End date (YYYY-MM-DD), optional" }, }, required: ["repo_path", "since"], }, }, - src/git-metrics.ts:269-270 (registration)Routing of the tool request to the handler. When `get_collaboration_metrics` is called, it invokes `handlers.handleGetCollaborationMetrics(args)`.
} else if (request.params.name === "get_collaboration_metrics") { result = handlers.handleGetCollaborationMetrics(args);