import re
from pathlib import Path
def fix_daemon_braces():
file_path = Path("server/src/agent/daemon.rs")
with open(file_path, 'r') as f:
content = f.read()
original_content = content
lines = content.split('\n')
fixed_lines = []
i = 0
brace_count = 0
in_function = False
function_start_line = 0
while i < len(lines):
line = lines[i]
open_braces = line.count('{')
close_braces = line.count('}')
brace_count += open_braces - close_braces
if re.match(r'\s*(pub\s+)?(async\s+)?fn\s+\w+', line) and line.endswith('{'):
in_function = True
function_start_line = i
function_brace_count = 1 elif in_function:
function_brace_count += open_braces - close_braces
if function_brace_count == 0:
in_function = False
if (i < len(lines) - 1 and
in_function and
function_brace_count > 0 and
(re.match(r'\s*(pub\s+)?(async\s+)?fn\s+\w+', lines[i + 1]) or
re.match(r'\s*impl\s+', lines[i + 1]) or
re.match(r'\s*#\[', lines[i + 1]) or
lines[i + 1].strip() == '}' or
re.match(r'\s*mod\s+', lines[i + 1]))):
missing_braces = function_brace_count
fixed_lines.append(line)
for _ in range(missing_braces):
fixed_lines.append(' }')
in_function = False
else:
fixed_lines.append(line)
i += 1
fixed_content = '\n'.join(fixed_lines)
impl_pattern = r'impl\s+(?:\w+\s+for\s+)?\w+'
impl_matches = list(re.finditer(impl_pattern, fixed_content))
if impl_matches:
lines = fixed_content.split('\n')
final_lines = []
impl_brace_count = 0
for line in lines:
final_lines.append(line)
if re.match(r'\s*impl\s+', line):
impl_brace_count = 1
elif impl_brace_count > 0:
impl_brace_count += line.count('{') - line.count('}')
if impl_brace_count > 0:
final_lines.append('}')
fixed_content = '\n'.join(final_lines)
if fixed_content != original_content:
with open(file_path, 'w') as f:
f.write(fixed_content)
return True
return False
def main():
print("๐ง Fixing daemon.rs braces...")
if fix_daemon_braces():
print("โ
Fixed daemon.rs braces")
else:
print("โน๏ธ No changes needed for daemon.rs")
import os
print("\n๐งช Testing compilation...")
result = os.system("cargo build --package pmat --tests --quiet")
if result == 0:
print("โ
All tests compile successfully!")
print("๐ฏ Sprint 89: Property test compilation COMPLETE")
else:
print("โ Compilation issues remain")
os.system("cargo build --package pmat --tests 2>&1 | grep -A3 'unclosed delimiter' | head -10")
if __name__ == "__main__":
main()