-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_local.py
More file actions
66 lines (52 loc) · 1.98 KB
/
check_local.py
File metadata and controls
66 lines (52 loc) · 1.98 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
import argparse
import os
import sys
# Add src to path so we can import the analyzer
sys.path.append(os.path.abspath('src'))
from main import analyze_with_gemma, load_profile
def key_masking(key: str) -> str:
if not key:
return "<empty>"
if len(key) <= 8:
return key
return f"{key[:4]}...{key[-4:]}"
def main():
parser = argparse.ArgumentParser(description="Run GitPhysicist on a local file.")
parser.add_argument("file", help="Path to the source code file to check")
parser.add_argument("--profile", default="profiles/stm32_f103.yaml", help="Path to hardware profile YAML")
parser.add_argument("-v", "--verbose", action="store_true", help="Print debug information")
args = parser.parse_args()
# 1. Check API Key
api_key = os.getenv("GOOGLE_API_KEY")
if not api_key:
print("::error::GOOGLE_API_KEY not found in environment variables.")
print("Run: export GOOGLE_API_KEY='your_key'")
sys.exit(1)
if args.verbose:
print(f"Using API key: {key_masking(api_key)}")
# 2. Load Profile
if not os.path.exists(args.profile):
print(f"Error: Profile not found at {args.profile}")
sys.exit(1)
profile = load_profile(args.profile)
# 3. Read Code
if not os.path.exists(args.file):
print(f"Error: File not found at {args.file}")
sys.exit(1)
with open(args.file, 'r') as f:
code_content = f.read()
# Wrap it to look like a diff
diff_context = f"\n--- File: {args.file} (Local Check) ---\n{code_content}\n"
# 4. Analyze
print(f"Checking {args.file} against {profile.get('device', 'Unknown Device')}...")
try:
report = analyze_with_gemma(diff_context, profile, api_key, verbose=args.verbose)
print("\n" + "="*40)
print("REPORT")
print("="*40)
print(report)
print("="*40 + "\n")
except Exception as e:
print(f"Analysis failed: {e}")
if __name__ == "__main__":
main()