Repository navigation
Expand file tree
/
Copy pathprogress.py
More file actions
155 lines (121 loc) · 4.95 KB
/
Copy pathprogress.py
File metadata and controls
155 lines (121 loc) · 4.95 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
"""
Progress Tracking Utilities
===========================
Functions for tracking and displaying progress of the autonomous coding agent.
"""
import json
from pathlib import Path
from typing import Dict, Any
def count_passing_tests(project_dir: Path) -> tuple[int, int]:
"""
Count passing and total tests in feature_list.json.
Args:
project_dir: Root project directory (looks in .harness/ for feature_list.json)
Returns:
(passing_count, total_count)
"""
# Check .harness/ first (new structure), fall back to root (legacy)
harness_dir = project_dir / ".harness"
tests_file = harness_dir / "feature_list.json"
if not tests_file.exists():
tests_file = project_dir / "feature_list.json" # Legacy fallback
if not tests_file.exists():
return 0, 0
try:
with open(tests_file, "r") as f:
data = json.load(f)
# Handle both formats: flat array or {"features": [...]}
if isinstance(data, dict) and "features" in data:
tests = data["features"]
elif isinstance(data, list):
tests = data
else:
return 0, 0
total = len(tests)
passing = sum(1 for test in tests if isinstance(test, dict) and test.get("passes", False))
return passing, total
except (json.JSONDecodeError, IOError):
return 0, 0
def get_test_stats(project_dir: Path) -> Dict[str, Any]:
"""
Get detailed statistics about tests in feature_list.json.
Args:
project_dir: Root project directory (looks in .harness/ for feature_list.json)
Returns:
Dictionary with stats by category and overall
"""
# Check .harness/ first (new structure), fall back to root (legacy)
harness_dir = project_dir / ".harness"
tests_file = harness_dir / "feature_list.json"
if not tests_file.exists():
tests_file = project_dir / "feature_list.json" # Legacy fallback
if not tests_file.exists():
return {"total": 0, "passing": 0, "categories": {}}
try:
with open(tests_file, "r") as f:
data = json.load(f)
# Handle both formats: flat array or {"features": [...]}
if isinstance(data, dict) and "features" in data:
tests = data["features"]
elif isinstance(data, list):
tests = data
else:
return {"total": 0, "passing": 0, "categories": {}}
# Count by category
categories: Dict[str, Dict[str, int]] = {}
for test in tests:
if not isinstance(test, dict):
continue
cat = test.get("category", "unknown")
if cat not in categories:
categories[cat] = {"total": 0, "passing": 0}
categories[cat]["total"] += 1
if test.get("passes", False):
categories[cat]["passing"] += 1
total = len(tests)
passing = sum(1 for test in tests if isinstance(test, dict) and test.get("passes", False))
return {
"total": total,
"passing": passing,
"categories": categories,
}
except (json.JSONDecodeError, IOError):
return {"total": 0, "passing": 0, "categories": {}}
def print_detailed_progress(project_dir: Path) -> None:
"""Print detailed progress by category."""
stats = get_test_stats(project_dir)
if stats["total"] == 0:
print("\n📊 Progress: feature_list.json not yet created")
return
total = stats["total"]
passing = stats["passing"]
pct = (passing / total * 100) if total > 0 else 0
# Progress bar
bar_width = 30
filled = int(bar_width * passing / total) if total > 0 else 0
bar = "█" * filled + "░" * (bar_width - filled)
print(f"\n📊 Overall Progress: [{bar}] {passing}/{total} ({pct:.1f}%)")
# By category
if stats["categories"]:
print("\n By Category:")
for cat, cat_stats in sorted(stats["categories"].items()):
cat_total = cat_stats["total"]
cat_passing = cat_stats["passing"]
cat_pct = (cat_passing / cat_total * 100) if cat_total > 0 else 0
status = "✅" if cat_passing == cat_total else "🔄"
print(f" {status} {cat}: {cat_passing}/{cat_total} ({cat_pct:.0f}%)")
def print_session_header(session_num: int, is_initializer: bool) -> None:
"""Print a formatted header for the session."""
session_type = "INITIALIZER" if is_initializer else "CODING AGENT"
print("\n" + "=" * 70)
print(f" SESSION {session_num}: {session_type}")
print("=" * 70)
print()
def print_progress_summary(project_dir: Path) -> None:
"""Print a summary of current progress."""
passing, total = count_passing_tests(project_dir)
if total > 0:
percentage = (passing / total) * 100
print(f"\nProgress: {passing}/{total} tests passing ({percentage:.1f}%)")
else:
print("\nProgress: feature_list.json not yet created")