-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai_devtool.py
More file actions
195 lines (164 loc) · 6.31 KB
/
ai_devtool.py
File metadata and controls
195 lines (164 loc) · 6.31 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env python3
"""
AI Developer Toolkit -- Unified workspace health check.
Auto-discovers AI config files and MCP tool definitions in your project,
runs all relevant checks, and produces a unified health report.
Usage:
py ai_devtool.py check # Check current directory
py ai_devtool.py check /path/to/project # Check specific project
py ai_devtool.py check --mcp tools.json # Also audit MCP tools
py ai_devtool.py select tools.json "query" # Select relevant MCP tools
"""
import argparse
import sys
import json
from pathlib import Path
# Import sibling tools
from claude_config_linter import lint_config, format_report as format_lint_report
from mcp_schema_auditor import audit_tools, format_report as format_audit_report, load_tools_from_file
from mcp_tool_selector import ToolSelector, load_tools, format_results, format_savings
CONFIG_FILENAMES = [
"CLAUDE.md", "claude.md",
"GEMINI.md", "gemini.md",
".cursorrules",
"copilot-instructions.md",
"AGENTS.md", "agents.md",
]
MCP_CONFIG_FILENAMES = [
"mcp.json",
".mcp.json",
"mcp-config.json",
"claude_desktop_config.json",
]
def discover_configs(project_dir: Path) -> list[Path]:
"""Find AI config files in a project directory."""
found = []
for name in CONFIG_FILENAMES:
path = project_dir / name
if path.exists():
found.append(path)
# Also check .claude/ subdirectory
sub = project_dir / ".claude" / name
if sub.exists():
found.append(sub)
return found
def discover_mcp_configs(project_dir: Path) -> list[Path]:
"""Find MCP config files in a project directory."""
found = []
for name in MCP_CONFIG_FILENAMES:
path = project_dir / name
if path.exists():
found.append(path)
sub = project_dir / ".claude" / name
if sub.exists():
found.append(sub)
return found
def run_check(project_dir: Path, mcp_file: str = None, verbose: bool = False):
"""Run unified health check on a project directory."""
print("=" * 60)
print(" AI WORKSPACE HEALTH CHECK")
print("=" * 60)
print(f"\n Project: {project_dir.resolve()}\n")
checks_run = 0
issues_total = 0
# 1. Check AI config files
configs = discover_configs(project_dir)
if configs:
for cfg in configs:
print(f" Found: {cfg.name}")
print()
for cfg in configs:
text = cfg.read_text(encoding="utf-8")
name = cfg.name.lower()
if "claude" in name:
fmt = "claude"
elif "gemini" in name:
fmt = "gemini"
elif "cursor" in name:
fmt = "cursorrules"
elif "copilot" in name:
fmt = "copilot"
elif "agent" in name:
fmt = "agents"
else:
fmt = "claude"
result = lint_config(text, str(cfg), fmt)
print(format_lint_report(result, verbose=verbose))
checks_run += 1
issues_total += len(result.get("issues", []))
print()
else:
print(" No AI config files found (CLAUDE.md, GEMINI.md, .cursorrules, etc.)")
print(" Tip: Add a CLAUDE.md to help AI assistants understand your project.\n")
# 2. Check MCP tools if provided
if mcp_file:
mcp_path = Path(mcp_file)
if mcp_path.exists():
try:
tools = load_tools_from_file(str(mcp_path))
audit = audit_tools(tools)
print(format_audit_report(audit, verbose=verbose))
checks_run += 1
issues_total += audit["summary"]["total_issues"]
except Exception as e:
print(f" Error auditing MCP tools: {e}")
else:
print(f" MCP file not found: {mcp_file}")
else:
# Try to auto-discover MCP configs
mcp_configs = discover_mcp_configs(project_dir)
if mcp_configs:
for mc in mcp_configs:
print(f" Found MCP config: {mc.name}")
print(" Tip: Export tool definitions and run: py ai_devtool.py check --mcp tools.json\n")
# 3. Summary
print("=" * 60)
print(" SUMMARY")
print("=" * 60)
print(f" Checks run: {checks_run}")
print(f" Total issues: {issues_total}")
if checks_run == 0:
print("\n No checkable files found. This tool checks:")
print(" - CLAUDE.md, GEMINI.md, .cursorrules, copilot-instructions.md, AGENTS.md")
print(" - MCP tool definition JSON files (with --mcp flag)")
print()
print("=" * 60)
def run_select(tools_file: str, query: str, top_k: int = 5, optimize: bool = False):
"""Run MCP tool selection."""
tools = load_tools(tools_file)
selector = ToolSelector(tools)
results = selector.select(query, top_k)
if optimize:
try:
from mcp_schema_auditor import optimize_tool
for r in results:
r["tool"] = optimize_tool(r["tool"])
except ImportError:
pass
print(format_results(results, query, len(tools)))
print(format_savings(results, len(tools), tools))
def main():
parser = argparse.ArgumentParser(
description="AI Developer Toolkit -- unified workspace health check"
)
sub = parser.add_subparsers(dest="command")
# check command
check_p = sub.add_parser("check", help="Run health check on a project")
check_p.add_argument("project", nargs="?", default=".", help="Project directory (default: current)")
check_p.add_argument("--mcp", help="Path to MCP tools JSON file")
check_p.add_argument("--verbose", "-v", action="store_true")
# select command
sel_p = sub.add_parser("select", help="Select relevant MCP tools for a query")
sel_p.add_argument("tools", help="Path to MCP tools JSON file")
sel_p.add_argument("query", help="Query to select tools for")
sel_p.add_argument("--top-k", "-k", type=int, default=5)
sel_p.add_argument("--optimize", action="store_true")
args = parser.parse_args()
if args.command == "check":
run_check(Path(args.project), mcp_file=args.mcp, verbose=args.verbose)
elif args.command == "select":
run_select(args.tools, args.query, args.top_k, args.optimize)
else:
parser.print_help()
if __name__ == "__main__":
main()