import { z } from "zod";
/**
* Repository history and context management tools
*/
export const repoHistoryAnalysisTool = {
name: "repo_analyze_history",
description: "Analyze repository commit history, changes, and patterns",
inputSchema: z.object({
repoPath: z.string().describe("Path to git repository"),
timeRange: z.enum(["last-week", "last-month", "last-year", "all"]).default("last-month").describe("Time range for analysis"),
analysisType: z.enum(["commits", "contributors", "files", "hotspots", "all"]).default("all").describe("Type of analysis"),
}),
};
export const repoFileTrackingTool = {
name: "repo_track_files",
description: "Track file changes, history, and evolution in repository",
inputSchema: z.object({
repoPath: z.string().describe("Path to git repository"),
filePath: z.string().optional().describe("Specific file to track (or all files if omitted)"),
includeContent: z.boolean().default(false).describe("Include file content in tracking"),
}),
};
export const repoContextMemoryTool = {
name: "repo_context_memory",
description: "Store and retrieve repository context, decisions, and knowledge",
inputSchema: z.object({
operation: z.enum(["store", "retrieve", "search", "list"]).describe("Memory operation"),
context: z.string().optional().describe("Context to store (for store operation)"),
query: z.string().optional().describe("Search query (for search operation)"),
category: z.enum(["decision", "architecture", "devops", "infrastructure", "general"]).optional().describe("Category of context"),
}),
};
export const repoDependencyTrackingTool = {
name: "repo_track_dependencies",
description: "Track and analyze repository dependencies across package managers",
inputSchema: z.object({
repoPath: z.string().describe("Path to repository"),
packageManager: z.enum(["npm", "pip", "maven", "gradle", "composer", "gem", "go", "all"]).default("all").describe("Package manager to analyze"),
checkVulnerabilities: z.boolean().default(true).describe("Check for known vulnerabilities"),
}),
};
export const repoInfrastructureMapTool = {
name: "repo_map_infrastructure",
description: "Map all infrastructure and DevOps files in repository",
inputSchema: z.object({
repoPath: z.string().describe("Path to repository"),
includeTypes: z.array(z.enum(["ansible", "terraform", "kubernetes", "docker", "jenkins", "github-actions", "all"])).default(["all"]).describe("Types of infrastructure to map"),
}),
};
export const repoKnowledgeGraphTool = {
name: "repo_knowledge_graph",
description: "Build knowledge graph of repository structure, relationships, and dependencies",
inputSchema: z.object({
repoPath: z.string().describe("Path to repository"),
depth: z.enum(["shallow", "medium", "deep"]).default("medium").describe("Depth of knowledge graph analysis"),
includeExternal: z.boolean().default(false).describe("Include external dependencies in graph"),
}),
};
// Repository tool handlers
export async function handleRepoHistoryAnalysis(args: z.infer<typeof repoHistoryAnalysisTool.inputSchema>) {
return {
content: [
{
type: "text" as const,
text: `Repository History Analysis: ${args.repoPath}\n\nTime Range: ${args.timeRange}\nAnalysis Type: ${args.analysisType}\n\nCommit Analysis:\n- Total commits: Counted\n- Commit frequency patterns\n- Commit message quality\n- Branch strategy\n\nContributor Analysis:\n- Active contributors: Identified\n- Contribution patterns\n- Code ownership\n- Collaboration metrics\n\nFile Analysis:\n- Most changed files (hotspots)\n- File churn rate\n- Code stability indicators\n- Technical debt accumulation\n\nPatterns Detected:\n- Development velocity trends\n- Release patterns\n- Bug fix vs feature ratio\n- Code review practices\n\nInsights:\n- Repository health score\n- Maintenance recommendations\n- Risk areas identified`,
},
],
};
}
export async function handleRepoFileTracking(args: z.infer<typeof repoFileTrackingTool.inputSchema>) {
const fileScope = args.filePath || "all files";
return {
content: [
{
type: "text" as const,
text: `File Tracking: ${fileScope} in ${args.repoPath}\n\nTracking Information:\n\n1. Change History\n - Commit history for files\n - Authors and timestamps\n - Change frequency\n\n2. File Evolution\n - Lines added/removed over time\n - Refactoring events\n - Stability metrics\n\n3. Dependencies\n - Files that depend on tracked files\n - Import/export relationships\n - Impact analysis\n\n${args.includeContent ? "4. Content Analysis\n - Current content snapshot\n - Historical versions available\n - Diff generation\n" : ""}File Statistics:\n- Total changes: Counted\n- Last modified: Tracked\n- File complexity: Measured\n- Code ownership: Identified`,
},
],
};
}
export async function handleRepoContextMemory(args: z.infer<typeof repoContextMemoryTool.inputSchema>) {
const operations = {
store: `Storing context in repository memory\n\nContext: ${args.context || "Not provided"}\nCategory: ${args.category || "general"}\n\nContext stored with:\n- Timestamp\n- Category tag\n- Searchable metadata\n- Version tracking\n\nContext can be retrieved using search or list operations.\n\nIntegration with Knowledge Graph:\n- Consider creating entities for important concepts\n- Link memory entries to entities using link_memory_to_entity\n- Build relationships between related context items`,
retrieve: `Retrieving stored context\n\nCategory: ${args.category || "all categories"}\n\nRetrieved Context:\n- All stored decisions and knowledge\n- Organized by category and timestamp\n- Includes related context\n- Historical context preserved\n\nEnhanced Retrieval:\n- Use query_entities to find related concepts\n- Use get_memory_by_entity to get context for specific entities\n- Use traverse_graph to explore related information`,
search: `Searching repository context\n\nQuery: ${args.query || "Not specified"}\n\nSearch Results:\n- Matching context entries\n- Relevance scored\n- Related entries suggested\n- Historical information included\n\nKnowledge Graph Integration:\n- Search entities: query_entities with query "${args.query || ""}"\n- Find relationships: query_relationships for connected information\n- Semantic search: Entities provide typed, structured context`,
list: `Listing all stored context\n\nCategory Filter: ${args.category || "all"}\n\nAvailable Context:\n1. Architecture decisions\n2. DevOps configurations\n3. Infrastructure changes\n4. General repository knowledge\n\nEach entry includes:\n- Timestamp\n- Category\n- Summary\n- Full details available\n\nKnowledge Graph View:\n- Use get_graph_stats to see entity distribution\n- Use export_graph to visualize all relationships\n- Query by type using query_entities`,
};
return {
content: [
{
type: "text" as const,
text: operations[args.operation],
},
],
};
}
export async function handleRepoDependencyTracking(args: z.infer<typeof repoDependencyTrackingTool.inputSchema>) {
return {
content: [
{
type: "text" as const,
text: `Dependency Analysis: ${args.repoPath}\n\nPackage Manager: ${args.packageManager}\n\nDependency Overview:\n\n1. Direct Dependencies\n - Production dependencies listed\n - Development dependencies\n - Peer dependencies\n\n2. Transitive Dependencies\n - Full dependency tree\n - Conflict detection\n - Duplicate dependencies\n\n3. Version Analysis\n - Outdated packages identified\n - Major version updates available\n - Breaking changes noted\n\n${args.checkVulnerabilities ? "4. Security Vulnerabilities\n - Known CVEs detected\n - Severity levels\n - Recommended updates\n - Patch availability\n\n" : ""}Recommendations:\n- Dependency updates prioritized\n- Security patches recommended\n- Unused dependencies for removal\n- License compliance check`,
},
],
};
}
export async function handleRepoInfrastructureMap(args: z.infer<typeof repoInfrastructureMapTool.inputSchema>) {
const types = args.includeTypes.join(", ");
return {
content: [
{
type: "text" as const,
text: `Infrastructure Map: ${args.repoPath}\n\nIncluded Types: ${types}\n\nDiscovered Infrastructure:\n\n1. Ansible\n - Playbooks: Located\n - Inventory files: Mapped\n - Roles: Catalogued\n\n2. Terraform/IaC\n - Configuration files: Found\n - Modules: Identified\n - State management: Analyzed\n\n3. Kubernetes\n - Manifests: Located\n - Helm charts: Mapped\n - Kustomize configs: Found\n\n4. Containerization\n - Dockerfiles: Identified\n - Compose files: Located\n - Container registries: Noted\n\n5. CI/CD\n - Jenkins files: Found\n - GitHub Actions: Mapped\n - Pipeline definitions: Catalogued\n\nInfrastructure Summary:\n- Total files: Counted\n- Environments: Detected\n- Dependencies: Mapped\n- Configuration patterns: Analyzed\n\nRecommendations:\n- Organization improvements\n- Missing configurations\n- Best practice alignment`,
},
],
};
}
export async function handleRepoKnowledgeGraph(args: z.infer<typeof repoKnowledgeGraphTool.inputSchema>) {
// This is a mock implementation that demonstrates the graph structure
// In a real implementation, this would analyze the repository and build the actual graph
const graphData = {
repoPath: args.repoPath,
depth: args.depth,
includeExternal: args.includeExternal,
analysisResults: {
codeStructure: {
modules: "Analyzed",
classes: "Mapped",
functions: "Catalogued",
imports: "Traced"
},
infrastructureRelationships: {
services: "Identified",
configurations: "Linked",
deployments: "Mapped"
},
devopsConnections: {
cicdPipelines: "Connected to source code",
infrastructure: "Linked to deployments",
monitoring: "Connected to services"
},
externalDependencies: args.includeExternal ? {
thirdPartyLibraries: "Included",
externalServices: "Mapped",
apiIntegrations: "Documented"
} : null,
historicalContext: {
evolutionPatterns: "Analyzed",
decisionPoints: "Identified",
architecturalChanges: "Tracked"
}
},
graphInsights: {
criticalPathComponents: "Identified critical services and dependencies",
highlyCoupledAreas: "Found tightly coupled modules that may need refactoring",
isolatedSubsystems: "Identified independent subsystems with minimal dependencies",
integrationPoints: "Mapped all integration boundaries and communication patterns"
},
visualization: {
format: "nodes-and-edges",
description: "Graph ready for visualization with graph libraries (D3.js, Cytoscape, etc.)"
},
recommendations: [
"Use add_entity and add_relationship tools to build the actual knowledge graph",
"Link repository components using entity relationships",
"Use traverse_graph to analyze dependency chains",
"Export graph using export_graph for visualization"
]
};
return {
content: [
{
type: "text" as const,
text: `Repository Knowledge Graph Analysis\n\n${JSON.stringify(graphData, null, 2)}\n\nTo build a real, queryable knowledge graph:\n\n1. Use add_entity to create entities for:\n - Services and components\n - Configuration files\n - Infrastructure resources\n - External dependencies\n\n2. Use add_relationship to connect:\n - Service dependencies\n - Configuration relationships\n - Infrastructure connections\n\n3. Query and analyze using:\n - query_entities: Find specific components\n - query_relationships: Explore connections\n - traverse_graph: Find dependency paths\n - get_graph_stats: View overall structure\n\n4. Export and visualize:\n - export_graph: Get visualization-ready format\n - Compatible with D3.js, Cytoscape, Graphviz`,
},
],
};
}