algomath-extract 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +260 -0
- package/bin/algo-extract.js +143 -0
- package/bin/algo-generate.js +102 -0
- package/bin/algo-help.js +136 -0
- package/bin/algo-list.js +56 -0
- package/bin/algo-run.js +141 -0
- package/bin/algo-status.js +88 -0
- package/bin/algo-verify.js +189 -0
- package/bin/install.js +349 -0
- package/package.json +57 -0
- package/requirements.txt +20 -0
- package/src/__pycache__/intent.cpython-313.pyc +0 -0
- package/src/cli/__pycache__/commands.cpython-313.pyc +0 -0
- package/src/cli/cli_entry.py +106 -0
- package/src/cli/commands.py +339 -0
- package/src/execution/__init__.py +74 -0
- package/src/execution/__pycache__/__init__.cpython-313.pyc +0 -0
- package/src/execution/__pycache__/display.cpython-313.pyc +0 -0
- package/src/execution/__pycache__/errors.cpython-313.pyc +0 -0
- package/src/execution/__pycache__/executor.cpython-313.pyc +0 -0
- package/src/execution/__pycache__/sandbox.cpython-313.pyc +0 -0
- package/src/execution/display.py +261 -0
- package/src/execution/errors.py +158 -0
- package/src/execution/executor.py +253 -0
- package/src/execution/sandbox.py +333 -0
- package/src/extraction/__init__.py +102 -0
- package/src/extraction/__pycache__/__init__.cpython-313.pyc +0 -0
- package/src/extraction/__pycache__/boundaries.cpython-313.pyc +0 -0
- package/src/extraction/__pycache__/errors.cpython-313.pyc +0 -0
- package/src/extraction/__pycache__/llm_extraction.cpython-313.pyc +0 -0
- package/src/extraction/__pycache__/notation.cpython-313.pyc +0 -0
- package/src/extraction/__pycache__/parser.cpython-313.pyc +0 -0
- package/src/extraction/__pycache__/pdf_processor.cpython-313.pyc +0 -0
- package/src/extraction/__pycache__/prompts.cpython-313.pyc +0 -0
- package/src/extraction/__pycache__/review.cpython-313.pyc +0 -0
- package/src/extraction/__pycache__/schema.cpython-313.pyc +0 -0
- package/src/extraction/__pycache__/validation.cpython-313.pyc +0 -0
- package/src/extraction/boundaries.py +281 -0
- package/src/extraction/errors.py +156 -0
- package/src/extraction/llm_extraction.py +225 -0
- package/src/extraction/notation.py +240 -0
- package/src/extraction/parser.py +402 -0
- package/src/extraction/pdf_processor.py +281 -0
- package/src/extraction/prompts.py +90 -0
- package/src/extraction/review.py +298 -0
- package/src/extraction/schema.py +173 -0
- package/src/extraction/validation.py +202 -0
- package/src/generation/__init__.py +79 -0
- package/src/generation/__pycache__/__init__.cpython-313.pyc +0 -0
- package/src/generation/__pycache__/code_generator.cpython-313.pyc +0 -0
- package/src/generation/__pycache__/errors.cpython-313.pyc +0 -0
- package/src/generation/__pycache__/hybrid.cpython-313.pyc +0 -0
- package/src/generation/__pycache__/llm_generator.cpython-313.pyc +0 -0
- package/src/generation/__pycache__/persistence.cpython-313.pyc +0 -0
- package/src/generation/__pycache__/prompts.cpython-313.pyc +0 -0
- package/src/generation/__pycache__/review.cpython-313.pyc +0 -0
- package/src/generation/__pycache__/templates.cpython-313.pyc +0 -0
- package/src/generation/__pycache__/types.cpython-313.pyc +0 -0
- package/src/generation/__pycache__/validation.cpython-313.pyc +0 -0
- package/src/generation/code_generator.py +375 -0
- package/src/generation/errors.py +84 -0
- package/src/generation/hybrid.py +210 -0
- package/src/generation/llm_generator.py +223 -0
- package/src/generation/persistence.py +221 -0
- package/src/generation/prompts.py +202 -0
- package/src/generation/review.py +254 -0
- package/src/generation/templates.py +208 -0
- package/src/generation/types.py +196 -0
- package/src/generation/validation.py +278 -0
- package/src/intent.py +323 -0
- package/src/verification/__init__.py +63 -0
- package/src/verification/__pycache__/__init__.cpython-313.pyc +0 -0
- package/src/verification/__pycache__/checker.cpython-313.pyc +0 -0
- package/src/verification/__pycache__/comparison.cpython-313.pyc +0 -0
- package/src/verification/__pycache__/explainer.cpython-313.pyc +0 -0
- package/src/verification/__pycache__/static_analysis.cpython-313.pyc +0 -0
- package/src/verification/checker.py +220 -0
- package/src/verification/comparison.py +492 -0
- package/src/verification/explainer.py +414 -0
- package/src/verification/static_analysis.py +540 -0
- package/src/workflows/__init__.py +21 -0
- package/src/workflows/__pycache__/__init__.cpython-313.pyc +0 -0
- package/src/workflows/__pycache__/extract.cpython-313.pyc +0 -0
- package/src/workflows/__pycache__/generate.cpython-313.pyc +0 -0
- package/src/workflows/__pycache__/run.cpython-313.pyc +0 -0
- package/src/workflows/__pycache__/verify.cpython-313.pyc +0 -0
- package/src/workflows/extract.py +181 -0
- package/src/workflows/generate.py +155 -0
- package/src/workflows/run.py +187 -0
- package/src/workflows/verify.py +334 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"""Execution verification checker for AlgoMath.
|
|
2
|
+
|
|
3
|
+
Per VER-01: Verify execution completed without errors.
|
|
4
|
+
Implements decisions D-05 from 05-CONTEXT.md.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
from dataclasses import dataclass, field
|
|
9
|
+
from datetime import datetime
|
|
10
|
+
from enum import Enum
|
|
11
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class VerificationStatus(Enum):
|
|
15
|
+
"""Verification status enumeration.
|
|
16
|
+
|
|
17
|
+
SUCCESS: All checks passed, execution was successful
|
|
18
|
+
FAILED: Execution failed (timeout, error, etc.)
|
|
19
|
+
ERROR: Verification itself encountered an error
|
|
20
|
+
INCOMPLETE: Verification could not be completed
|
|
21
|
+
"""
|
|
22
|
+
SUCCESS = "success"
|
|
23
|
+
FAILED = "failed"
|
|
24
|
+
ERROR = "error"
|
|
25
|
+
INCOMPLETE = "incomplete"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class VerificationResult:
|
|
30
|
+
"""Result of execution verification.
|
|
31
|
+
|
|
32
|
+
Per D-05: Provides brief summary (1-2 sentences) of execution.
|
|
33
|
+
|
|
34
|
+
Attributes:
|
|
35
|
+
status: Overall verification status
|
|
36
|
+
message: Human-readable verification message
|
|
37
|
+
checks_performed: List of verification checks that were run
|
|
38
|
+
execution_summary: 1-2 sentence summary per D-05
|
|
39
|
+
runtime_seconds: Execution runtime in seconds
|
|
40
|
+
output_size: Size of output in characters
|
|
41
|
+
timestamp: ISO timestamp when verification was performed
|
|
42
|
+
"""
|
|
43
|
+
status: VerificationStatus
|
|
44
|
+
message: str
|
|
45
|
+
checks_performed: List[str] = field(default_factory=list)
|
|
46
|
+
execution_summary: str = ""
|
|
47
|
+
runtime_seconds: float = 0.0
|
|
48
|
+
output_size: int = 0
|
|
49
|
+
timestamp: str = field(default_factory=lambda: datetime.utcnow().isoformat() + "Z")
|
|
50
|
+
|
|
51
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
52
|
+
"""Convert result to dictionary for JSON serialization."""
|
|
53
|
+
return {
|
|
54
|
+
'status': self.status.value,
|
|
55
|
+
'message': self.message,
|
|
56
|
+
'checks_performed': self.checks_performed,
|
|
57
|
+
'execution_summary': self.execution_summary,
|
|
58
|
+
'runtime_seconds': self.runtime_seconds,
|
|
59
|
+
'output_size': self.output_size,
|
|
60
|
+
'timestamp': self.timestamp
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
def to_json(self) -> str:
|
|
64
|
+
"""Serialize result to JSON string."""
|
|
65
|
+
return json.dumps(self.to_dict(), indent=2)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class ExecutionChecker:
|
|
69
|
+
"""Checker that verifies execution results.
|
|
70
|
+
|
|
71
|
+
Performs various checks on execution output to verify:
|
|
72
|
+
- No errors occurred during execution
|
|
73
|
+
- Output is present (non-empty)
|
|
74
|
+
- Execution completed within expected parameters
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
def __init__(self, results: Dict[str, Any]):
|
|
78
|
+
"""Initialize checker with execution results.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
results: Dictionary containing execution results with keys:
|
|
82
|
+
- status: 'success', 'timeout', 'error', etc.
|
|
83
|
+
- stdout: Captured standard output
|
|
84
|
+
- stderr: Captured standard error
|
|
85
|
+
- runtime_seconds: Execution time
|
|
86
|
+
- return_value: Optional return value
|
|
87
|
+
- error_type: Optional error type
|
|
88
|
+
- error_message: Optional error message
|
|
89
|
+
"""
|
|
90
|
+
self.results = results
|
|
91
|
+
self._checks_performed: List[str] = []
|
|
92
|
+
|
|
93
|
+
def check(self) -> VerificationResult:
|
|
94
|
+
"""Run all verification checks.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
VerificationResult with status and summary
|
|
98
|
+
"""
|
|
99
|
+
self._checks_performed = []
|
|
100
|
+
|
|
101
|
+
# Check for errors
|
|
102
|
+
no_errors, error_msg = self._check_no_errors()
|
|
103
|
+
self._checks_performed.append("no_errors")
|
|
104
|
+
|
|
105
|
+
# Check output presence
|
|
106
|
+
output_present, output_msg = self._check_output_present()
|
|
107
|
+
self._checks_performed.append("output_present")
|
|
108
|
+
|
|
109
|
+
# Determine overall status
|
|
110
|
+
if not no_errors:
|
|
111
|
+
status = VerificationStatus.ERROR
|
|
112
|
+
if self.results.get('status') == 'timeout':
|
|
113
|
+
status = VerificationStatus.FAILED
|
|
114
|
+
message = error_msg
|
|
115
|
+
elif not output_present:
|
|
116
|
+
status = VerificationStatus.FAILED
|
|
117
|
+
message = output_msg
|
|
118
|
+
else:
|
|
119
|
+
status = VerificationStatus.SUCCESS
|
|
120
|
+
message = "Execution completed successfully with no errors detected."
|
|
121
|
+
|
|
122
|
+
# Generate summary per D-05
|
|
123
|
+
summary = self._generate_summary()
|
|
124
|
+
|
|
125
|
+
# Calculate output size
|
|
126
|
+
stdout = self.results.get('stdout', '')
|
|
127
|
+
stderr = self.results.get('stderr', '')
|
|
128
|
+
output_size = len(stdout) + len(stderr)
|
|
129
|
+
|
|
130
|
+
return VerificationResult(
|
|
131
|
+
status=status,
|
|
132
|
+
message=message,
|
|
133
|
+
checks_performed=self._checks_performed.copy(),
|
|
134
|
+
execution_summary=summary,
|
|
135
|
+
runtime_seconds=self.results.get('runtime_seconds', 0.0),
|
|
136
|
+
output_size=output_size
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
def _check_no_errors(self) -> Tuple[bool, str]:
|
|
140
|
+
"""Check if execution completed without errors.
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
Tuple of (passed, message)
|
|
144
|
+
"""
|
|
145
|
+
status = self.results.get('status', 'unknown')
|
|
146
|
+
|
|
147
|
+
if status == 'success':
|
|
148
|
+
return True, "No errors detected."
|
|
149
|
+
elif status == 'timeout':
|
|
150
|
+
return False, "Execution timed out."
|
|
151
|
+
elif status in ('error', 'runtime_error', 'syntax_error', 'memory_error', 'import_error'):
|
|
152
|
+
return False, f"Execution failed with status: {status}"
|
|
153
|
+
else:
|
|
154
|
+
return False, f"Unknown execution status: {status}"
|
|
155
|
+
|
|
156
|
+
def _check_output_present(self) -> Tuple[bool, str]:
|
|
157
|
+
"""Check if output is present (non-empty).
|
|
158
|
+
|
|
159
|
+
Returns:
|
|
160
|
+
Tuple of (passed, message)
|
|
161
|
+
"""
|
|
162
|
+
stdout = self.results.get('stdout', '')
|
|
163
|
+
|
|
164
|
+
if stdout and len(stdout.strip()) > 0:
|
|
165
|
+
return True, "Output is present."
|
|
166
|
+
else:
|
|
167
|
+
return False, "No output produced."
|
|
168
|
+
|
|
169
|
+
def _generate_summary(self) -> str:
|
|
170
|
+
"""Generate 1-2 sentence summary per D-05.
|
|
171
|
+
|
|
172
|
+
For success: "Algorithm completed successfully, producing [X] lines
|
|
173
|
+
of output in [Y] seconds."
|
|
174
|
+
|
|
175
|
+
For failure: "Execution encountered a [error type] after [Y] seconds."
|
|
176
|
+
|
|
177
|
+
Returns:
|
|
178
|
+
Brief summary string
|
|
179
|
+
"""
|
|
180
|
+
status = self.results.get('status', 'unknown')
|
|
181
|
+
runtime = self.results.get('runtime_seconds', 0.0)
|
|
182
|
+
stdout = self.results.get('stdout', '')
|
|
183
|
+
|
|
184
|
+
if status == 'success':
|
|
185
|
+
line_count = stdout.count('\n') + (1 if stdout and not stdout.endswith('\n') else 0)
|
|
186
|
+
if line_count == 0 and stdout:
|
|
187
|
+
line_count = 1
|
|
188
|
+
return f"Algorithm completed successfully, producing {line_count} lines of output in {runtime:.2f} seconds."
|
|
189
|
+
elif status == 'timeout':
|
|
190
|
+
return f"Execution encountered a timeout after {runtime:.2f} seconds."
|
|
191
|
+
elif status in ('error', 'runtime_error'):
|
|
192
|
+
error_type = self.results.get('error_type', 'error')
|
|
193
|
+
return f"Execution encountered a {error_type} after {runtime:.2f} seconds."
|
|
194
|
+
elif status == 'syntax_error':
|
|
195
|
+
return f"Execution encountered a syntax error after {runtime:.2f} seconds."
|
|
196
|
+
elif status == 'memory_error':
|
|
197
|
+
return f"Execution encountered a memory error after {runtime:.2f} seconds."
|
|
198
|
+
else:
|
|
199
|
+
return f"Execution completed with status '{status}' after {runtime:.2f} seconds."
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def verify_execution(results: Dict[str, Any]) -> VerificationResult:
|
|
203
|
+
"""High-level interface to verify execution results.
|
|
204
|
+
|
|
205
|
+
Args:
|
|
206
|
+
results: Dictionary containing execution results
|
|
207
|
+
|
|
208
|
+
Returns:
|
|
209
|
+
VerificationResult with verification status and summary
|
|
210
|
+
"""
|
|
211
|
+
checker = ExecutionChecker(results)
|
|
212
|
+
return checker.check()
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
__all__ = [
|
|
216
|
+
'VerificationStatus',
|
|
217
|
+
'VerificationResult',
|
|
218
|
+
'ExecutionChecker',
|
|
219
|
+
'verify_execution',
|
|
220
|
+
]
|