tessl install tessl/pypi-crosshair-tool@0.0.0Analyze Python code for correctness using symbolic execution and SMT solving to automatically find counterexamples for functions with type annotations and contracts.
Agent Success
Agent success rate when using this tile
86%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.25x
Baseline
Agent success rate without this tile
69%
Build a Python service that continuously monitors Python source files for contract violations using automated analysis. The service should watch a directory for file changes and automatically re-analyze files when they are modified.
The service must monitor a specified directory for Python files and detect when files are modified. When a change is detected, the service should automatically trigger analysis of the modified file.
The service must analyze Python files to check for violations of preconditions and postconditions defined in function docstrings. The analysis should identify any inputs that would violate the specified contracts.
The service must collect and report analysis results, including:
The service should output results in a structured format that can be easily consumed by other tools.
The service must support graceful shutdown when interrupted, ensuring that any ongoing analysis completes before the service stops.
@generates
The main implementation should include:
"""
Contract monitoring service for Python source files.
"""
from typing import Dict, List, Any
def start_monitoring(directory: str, output_file: str = "analysis_results.json") -> None:
"""
Start monitoring a directory for Python file changes and analyze them for contract violations.
Args:
directory: Path to the directory to monitor
output_file: Path to the file where analysis results will be written
The function runs until interrupted (Ctrl+C), continuously monitoring for file changes.
Results are written to the output file as JSON after each analysis run.
"""
pass
def parse_analysis_results(output_file: str) -> List[Dict[str, Any]]:
"""
Parse the analysis results from the output file.
Args:
output_file: Path to the results file
Returns:
List of analysis result dictionaries, each containing:
- 'file': str - the file that was analyzed
- 'violations': List[Dict] - list of violations found, each with 'line' and 'message'
- 'timestamp': str - when the analysis was performed (ISO format)
"""
passGiven a directory with a Python file containing a function with a failing precondition contract in its docstring, when the monitoring service is started and the file is modified, then the service detects the violation and reports it with the correct file path and line number @test
Given a directory with a Python file containing a function with a failing postcondition contract in its docstring, when the file is created after the monitoring service starts, then the service analyzes the new file and reports the postcondition violation @test
Given an empty directory being monitored, when a Python file with valid contracts is added, then the service analyzes it and reports no violations @test
Provides symbolic execution and contract verification for Python code, including file watching capabilities.
@satisfied-by