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,173 @@
|
|
|
1
|
+
"""Schema definitions for algorithm extraction.
|
|
2
|
+
|
|
3
|
+
This module defines the core data structures for representing algorithms
|
|
4
|
+
and their steps in a structured, machine-readable format.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
from enum import Enum
|
|
9
|
+
from typing import Any, Dict, List, Optional
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class StepType(Enum):
|
|
13
|
+
"""Enumeration of step types for algorithm steps."""
|
|
14
|
+
ASSIGNMENT = "assignment"
|
|
15
|
+
LOOP_FOR = "loop_for"
|
|
16
|
+
LOOP_WHILE = "loop_while"
|
|
17
|
+
CONDITIONAL = "conditional"
|
|
18
|
+
RETURN = "return"
|
|
19
|
+
CALL = "call"
|
|
20
|
+
COMMENT = "comment"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class Step:
|
|
25
|
+
"""
|
|
26
|
+
Represents a single step in an algorithm.
|
|
27
|
+
|
|
28
|
+
Attributes:
|
|
29
|
+
id: Unique identifier for the step
|
|
30
|
+
type: Type of step (assignment, loop, conditional, etc.)
|
|
31
|
+
description: Human-readable description of the step
|
|
32
|
+
inputs: List of variable names read by this step
|
|
33
|
+
outputs: List of variable names written by this step
|
|
34
|
+
line_refs: Line numbers in the original source text
|
|
35
|
+
condition: Condition for loops/conditionals
|
|
36
|
+
body: List of step IDs in the body (for loops/conditionals)
|
|
37
|
+
else_body: List of step IDs in the else branch (for conditionals)
|
|
38
|
+
iter_var: Loop variable (for for loops)
|
|
39
|
+
iter_range: Range specification (for for loops)
|
|
40
|
+
expression: Expression (for assignments and returns)
|
|
41
|
+
call_target: Function name (for calls)
|
|
42
|
+
arguments: Arguments (for calls)
|
|
43
|
+
annotation: Comment text (for comments)
|
|
44
|
+
"""
|
|
45
|
+
id: int
|
|
46
|
+
type: StepType
|
|
47
|
+
description: str
|
|
48
|
+
inputs: List[str] = field(default_factory=list)
|
|
49
|
+
outputs: List[str] = field(default_factory=list)
|
|
50
|
+
line_refs: List[int] = field(default_factory=list)
|
|
51
|
+
condition: Optional[str] = None
|
|
52
|
+
body: List[int] = field(default_factory=list)
|
|
53
|
+
else_body: List[int] = field(default_factory=list)
|
|
54
|
+
iter_var: Optional[str] = None
|
|
55
|
+
iter_range: Optional[str] = None
|
|
56
|
+
expression: Optional[str] = None
|
|
57
|
+
call_target: Optional[str] = None
|
|
58
|
+
arguments: List[str] = field(default_factory=list)
|
|
59
|
+
annotation: Optional[str] = None
|
|
60
|
+
|
|
61
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
62
|
+
"""Convert step to dictionary representation."""
|
|
63
|
+
return {
|
|
64
|
+
"id": self.id,
|
|
65
|
+
"type": self.type.value,
|
|
66
|
+
"description": self.description,
|
|
67
|
+
"inputs": self.inputs,
|
|
68
|
+
"outputs": self.outputs,
|
|
69
|
+
"line_refs": self.line_refs,
|
|
70
|
+
"condition": self.condition,
|
|
71
|
+
"body": self.body,
|
|
72
|
+
"else_body": self.else_body,
|
|
73
|
+
"iter_var": self.iter_var,
|
|
74
|
+
"iter_range": self.iter_range,
|
|
75
|
+
"expression": self.expression,
|
|
76
|
+
"call_target": self.call_target,
|
|
77
|
+
"arguments": self.arguments,
|
|
78
|
+
"annotation": self.annotation
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@classmethod
|
|
82
|
+
def from_dict(cls, data: Dict[str, Any]) -> "Step":
|
|
83
|
+
"""Create step from dictionary."""
|
|
84
|
+
return cls(
|
|
85
|
+
id=data["id"],
|
|
86
|
+
type=StepType(data["type"]),
|
|
87
|
+
description=data["description"],
|
|
88
|
+
inputs=data.get("inputs", []),
|
|
89
|
+
outputs=data.get("outputs", []),
|
|
90
|
+
line_refs=data.get("line_refs", []),
|
|
91
|
+
condition=data.get("condition"),
|
|
92
|
+
body=data.get("body", []),
|
|
93
|
+
else_body=data.get("else_body", []),
|
|
94
|
+
iter_var=data.get("iter_var"),
|
|
95
|
+
iter_range=data.get("iter_range"),
|
|
96
|
+
expression=data.get("expression"),
|
|
97
|
+
call_target=data.get("call_target"),
|
|
98
|
+
arguments=data.get("arguments", []),
|
|
99
|
+
annotation=data.get("annotation")
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@dataclass
|
|
104
|
+
class Algorithm:
|
|
105
|
+
"""
|
|
106
|
+
Represents a complete algorithm with its steps.
|
|
107
|
+
|
|
108
|
+
Attributes:
|
|
109
|
+
name: Algorithm name
|
|
110
|
+
description: Brief description
|
|
111
|
+
inputs: List of input variables with types and descriptions
|
|
112
|
+
outputs: List of output variables with types and descriptions
|
|
113
|
+
steps: List of algorithm steps
|
|
114
|
+
source_text: Original source text
|
|
115
|
+
"""
|
|
116
|
+
name: str
|
|
117
|
+
description: str = ""
|
|
118
|
+
inputs: List[Dict[str, Any]] = field(default_factory=list)
|
|
119
|
+
outputs: List[Dict[str, Any]] = field(default_factory=list)
|
|
120
|
+
steps: List[Step] = field(default_factory=list)
|
|
121
|
+
source_text: str = ""
|
|
122
|
+
|
|
123
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
124
|
+
"""Convert algorithm to dictionary representation."""
|
|
125
|
+
return {
|
|
126
|
+
"name": self.name,
|
|
127
|
+
"description": self.description,
|
|
128
|
+
"inputs": self.inputs,
|
|
129
|
+
"outputs": self.outputs,
|
|
130
|
+
"steps": [step.to_dict() for step in self.steps],
|
|
131
|
+
"source_text": self.source_text
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@classmethod
|
|
135
|
+
def from_dict(cls, data: Dict[str, Any]) -> "Algorithm":
|
|
136
|
+
"""Create algorithm from dictionary."""
|
|
137
|
+
return cls(
|
|
138
|
+
name=data.get("name", "unnamed"),
|
|
139
|
+
description=data.get("description", ""),
|
|
140
|
+
inputs=data.get("inputs", []),
|
|
141
|
+
outputs=data.get("outputs", []),
|
|
142
|
+
steps=[Step.from_dict(s) for s in data.get("steps", [])],
|
|
143
|
+
source_text=data.get("source_text", "")
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def algorithm_to_json(algorithm: Algorithm) -> str:
|
|
148
|
+
"""
|
|
149
|
+
Convert an Algorithm object to JSON string.
|
|
150
|
+
|
|
151
|
+
Args:
|
|
152
|
+
algorithm: Algorithm to convert
|
|
153
|
+
|
|
154
|
+
Returns:
|
|
155
|
+
JSON string representation
|
|
156
|
+
"""
|
|
157
|
+
import json
|
|
158
|
+
return json.dumps(algorithm.to_dict(), indent=2)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def algorithm_from_json(json_str: str) -> Algorithm:
|
|
162
|
+
"""
|
|
163
|
+
Convert a JSON string to an Algorithm object.
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
json_str: JSON string to parse
|
|
167
|
+
|
|
168
|
+
Returns:
|
|
169
|
+
Algorithm object
|
|
170
|
+
"""
|
|
171
|
+
import json
|
|
172
|
+
data = json.loads(json_str)
|
|
173
|
+
return Algorithm.from_dict(data)
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""Validation for extracted algorithms."""
|
|
2
|
+
from typing import List, Set, Dict, Tuple
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
|
|
5
|
+
from .schema import Algorithm, Step, StepType
|
|
6
|
+
from .errors import ExtractionError, ParseError, IncompleteError
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class ValidationResult:
|
|
11
|
+
"""Result of algorithm validation."""
|
|
12
|
+
|
|
13
|
+
is_valid: bool
|
|
14
|
+
errors: List[ExtractionError] = field(default_factory=list)
|
|
15
|
+
warnings: List[str] = field(default_factory=list)
|
|
16
|
+
|
|
17
|
+
def add_error(self, error: ExtractionError):
|
|
18
|
+
"""Add an error and mark as invalid."""
|
|
19
|
+
self.errors.append(error)
|
|
20
|
+
self.is_valid = False
|
|
21
|
+
|
|
22
|
+
def add_warning(self, warning: str):
|
|
23
|
+
"""Add a warning (does not invalidate)."""
|
|
24
|
+
self.warnings.append(warning)
|
|
25
|
+
|
|
26
|
+
def __str__(self) -> str:
|
|
27
|
+
if self.is_valid and not self.warnings:
|
|
28
|
+
return "Algorithm is valid"
|
|
29
|
+
|
|
30
|
+
lines = []
|
|
31
|
+
if not self.is_valid:
|
|
32
|
+
lines.append(f"Validation failed with {len(self.errors)} error(s)")
|
|
33
|
+
if self.warnings:
|
|
34
|
+
lines.append(f"{len(self.warnings)} warning(s)")
|
|
35
|
+
return "\n".join(lines)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def validate_algorithm(algorithm: Algorithm) -> ValidationResult:
|
|
39
|
+
"""
|
|
40
|
+
Validate an algorithm for correctness.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
algorithm: Algorithm to validate
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
ValidationResult with errors and warnings
|
|
47
|
+
|
|
48
|
+
Per D-20 from 02-CONTEXT.md.
|
|
49
|
+
"""
|
|
50
|
+
result = ValidationResult(is_valid=True)
|
|
51
|
+
|
|
52
|
+
# Check algorithm has minimum structure
|
|
53
|
+
if not algorithm.name or algorithm.name == "unnamed":
|
|
54
|
+
result.add_warning("Algorithm has no name")
|
|
55
|
+
|
|
56
|
+
if not algorithm.steps:
|
|
57
|
+
result.add_error(IncompleteError(
|
|
58
|
+
message="Algorithm has no steps",
|
|
59
|
+
suggestion="Add at least one algorithm step"
|
|
60
|
+
))
|
|
61
|
+
|
|
62
|
+
# Check for unique step IDs
|
|
63
|
+
step_ids = [step.id for step in algorithm.steps]
|
|
64
|
+
if len(step_ids) != len(set(step_ids)):
|
|
65
|
+
duplicates = set([x for x in step_ids if step_ids.count(x) > 1])
|
|
66
|
+
result.add_error(ParseError(
|
|
67
|
+
message=f"Duplicate step IDs found: {duplicates}",
|
|
68
|
+
suggestion="Ensure each step has a unique identifier"
|
|
69
|
+
))
|
|
70
|
+
|
|
71
|
+
# Check step connectivity
|
|
72
|
+
connectivity = check_step_connectivity(algorithm)
|
|
73
|
+
if not connectivity.is_valid:
|
|
74
|
+
result.errors.extend(connectivity.errors)
|
|
75
|
+
result.is_valid = False
|
|
76
|
+
|
|
77
|
+
# Check variable flow
|
|
78
|
+
var_flow = check_variable_flow(algorithm)
|
|
79
|
+
if not var_flow.is_valid:
|
|
80
|
+
result.errors.extend(var_flow.errors)
|
|
81
|
+
result.is_valid = False
|
|
82
|
+
|
|
83
|
+
# Check each step individually
|
|
84
|
+
for step in algorithm.steps:
|
|
85
|
+
_validate_step(step, result)
|
|
86
|
+
|
|
87
|
+
return result
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def check_step_connectivity(algorithm: Algorithm) -> ValidationResult:
|
|
91
|
+
"""
|
|
92
|
+
Check that all step references are valid.
|
|
93
|
+
|
|
94
|
+
Validates that body/else_body references point to existing steps.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
algorithm: Algorithm to check
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
ValidationResult
|
|
101
|
+
"""
|
|
102
|
+
result = ValidationResult(is_valid=True)
|
|
103
|
+
step_ids = {step.id for step in algorithm.steps}
|
|
104
|
+
|
|
105
|
+
for step in algorithm.steps:
|
|
106
|
+
# Check body references
|
|
107
|
+
for ref_id in step.body:
|
|
108
|
+
if ref_id not in step_ids:
|
|
109
|
+
result.add_error(ParseError(
|
|
110
|
+
message=f"Step {step.id} references non-existent step {ref_id} in body",
|
|
111
|
+
line_number=step.line_refs[0] if step.line_refs else None,
|
|
112
|
+
suggestion="Update reference to point to an existing step"
|
|
113
|
+
))
|
|
114
|
+
|
|
115
|
+
# Check else_body references
|
|
116
|
+
for ref_id in step.else_body:
|
|
117
|
+
if ref_id not in step_ids:
|
|
118
|
+
result.add_error(ParseError(
|
|
119
|
+
message=f"Step {step.id} references non-existent step {ref_id} in else_body",
|
|
120
|
+
line_number=step.line_refs[0] if step.line_refs else None,
|
|
121
|
+
suggestion="Update reference to point to an existing step"
|
|
122
|
+
))
|
|
123
|
+
|
|
124
|
+
return result
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def check_variable_flow(algorithm: Algorithm) -> ValidationResult:
|
|
128
|
+
"""
|
|
129
|
+
Check that variables are defined before use.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
algorithm: Algorithm to check
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
ValidationResult
|
|
136
|
+
"""
|
|
137
|
+
result = ValidationResult(is_valid=True)
|
|
138
|
+
defined_vars: Set[str] = set()
|
|
139
|
+
|
|
140
|
+
# Add input variables as initially defined
|
|
141
|
+
for inp in algorithm.inputs:
|
|
142
|
+
var_name = inp.get("name", "")
|
|
143
|
+
if var_name:
|
|
144
|
+
defined_vars.add(var_name.split('[')[0]) # Handle array notation
|
|
145
|
+
|
|
146
|
+
# Track defined variables through steps
|
|
147
|
+
for step in algorithm.steps:
|
|
148
|
+
# Check inputs are defined
|
|
149
|
+
for var in step.inputs:
|
|
150
|
+
base_var = var.split('[')[0] # Handle array indexing
|
|
151
|
+
if base_var not in defined_vars and not _is_builtin_or_constant(base_var):
|
|
152
|
+
result.add_warning(
|
|
153
|
+
f"Step {step.id}: Variable '{var}' may not be defined before use"
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
# Add outputs to defined set
|
|
157
|
+
for var in step.outputs:
|
|
158
|
+
base_var = var.split('[')[0]
|
|
159
|
+
defined_vars.add(base_var)
|
|
160
|
+
|
|
161
|
+
return result
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _is_builtin_or_constant(var: str) -> bool:
|
|
165
|
+
"""Check if variable is a builtin or constant."""
|
|
166
|
+
builtins = {'True', 'False', 'None', 'len', 'range', 'sum', 'min', 'max'}
|
|
167
|
+
constants = {'n', 'm', 'i', 'j', 'k', 'x', 'y', 'z'}
|
|
168
|
+
return var in builtins or var in constants or var.isdigit()
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _validate_step(step: Step, result: ValidationResult):
|
|
172
|
+
"""Validate a single step."""
|
|
173
|
+
|
|
174
|
+
# Check step has description
|
|
175
|
+
if not step.description or not step.description.strip():
|
|
176
|
+
result.add_error(IncompleteError(
|
|
177
|
+
message=f"Step {step.id} has no description",
|
|
178
|
+
line_number=step.line_refs[0] if step.line_refs else None
|
|
179
|
+
))
|
|
180
|
+
|
|
181
|
+
# Type-specific validation
|
|
182
|
+
if step.type == StepType.ASSIGNMENT:
|
|
183
|
+
if not step.expression and '=' not in step.description:
|
|
184
|
+
result.add_warning(f"Step {step.id}: Assignment without clear expression")
|
|
185
|
+
|
|
186
|
+
elif step.type in (StepType.LOOP_FOR, StepType.LOOP_WHILE):
|
|
187
|
+
if step.type == StepType.LOOP_FOR and not step.iter_var:
|
|
188
|
+
result.add_warning(f"Step {step.id}: For loop without iteration variable")
|
|
189
|
+
if not step.body:
|
|
190
|
+
result.add_warning(f"Step {step.id}: Loop has empty body")
|
|
191
|
+
|
|
192
|
+
elif step.type == StepType.CONDITIONAL:
|
|
193
|
+
if not step.condition and 'if' in step.description.lower():
|
|
194
|
+
result.add_warning(f"Step {step.id}: Conditional without explicit condition")
|
|
195
|
+
|
|
196
|
+
elif step.type == StepType.RETURN:
|
|
197
|
+
if not step.expression:
|
|
198
|
+
result.add_warning(f"Step {step.id}: Return without value")
|
|
199
|
+
|
|
200
|
+
# Check line references exist
|
|
201
|
+
if not step.line_refs:
|
|
202
|
+
result.add_warning(f"Step {step.id}: No line references (traceability reduced)")
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Code generation module for AlgoMath.
|
|
2
|
+
|
|
3
|
+
This module provides tools for converting structured algorithms
|
|
4
|
+
into executable Python code.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from src.generation.types import (
|
|
8
|
+
TypeInferrer,
|
|
9
|
+
PythonType,
|
|
10
|
+
FunctionSignature,
|
|
11
|
+
ValidationResult,
|
|
12
|
+
)
|
|
13
|
+
from src.generation.templates import (
|
|
14
|
+
TemplateRegistry,
|
|
15
|
+
CodeTemplates,
|
|
16
|
+
)
|
|
17
|
+
from src.generation.code_generator import (
|
|
18
|
+
TemplateCodeGenerator,
|
|
19
|
+
GeneratedCode,
|
|
20
|
+
)
|
|
21
|
+
from src.generation.llm_generator import (
|
|
22
|
+
LLMCodeGenerator,
|
|
23
|
+
)
|
|
24
|
+
from src.generation.hybrid import (
|
|
25
|
+
HybridCodeGenerator,
|
|
26
|
+
HybridGenerationResult,
|
|
27
|
+
)
|
|
28
|
+
from src.generation.errors import (
|
|
29
|
+
GenerationError,
|
|
30
|
+
SyntaxGenerationError,
|
|
31
|
+
ImportGenerationError,
|
|
32
|
+
LLMGenerationError,
|
|
33
|
+
ValidationError,
|
|
34
|
+
)
|
|
35
|
+
from src.generation.validation import (
|
|
36
|
+
ValidationResult,
|
|
37
|
+
CodeValidator,
|
|
38
|
+
)
|
|
39
|
+
from src.generation.review import (
|
|
40
|
+
CodeReviewInterface,
|
|
41
|
+
ReviewState,
|
|
42
|
+
create_review,
|
|
43
|
+
)
|
|
44
|
+
from src.generation.persistence import (
|
|
45
|
+
CodePersistence,
|
|
46
|
+
save_to_context,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
__all__ = [
|
|
50
|
+
# Types
|
|
51
|
+
"TypeInferrer",
|
|
52
|
+
"PythonType",
|
|
53
|
+
"FunctionSignature",
|
|
54
|
+
"ValidationResult",
|
|
55
|
+
# Templates
|
|
56
|
+
"TemplateRegistry",
|
|
57
|
+
"CodeTemplates",
|
|
58
|
+
# Generators
|
|
59
|
+
"TemplateCodeGenerator",
|
|
60
|
+
"LLMCodeGenerator",
|
|
61
|
+
"HybridCodeGenerator",
|
|
62
|
+
"HybridGenerationResult",
|
|
63
|
+
"GeneratedCode",
|
|
64
|
+
# Errors
|
|
65
|
+
"GenerationError",
|
|
66
|
+
"SyntaxGenerationError",
|
|
67
|
+
"ImportGenerationError",
|
|
68
|
+
"LLMGenerationError",
|
|
69
|
+
"ValidationError",
|
|
70
|
+
# Validation
|
|
71
|
+
"CodeValidator",
|
|
72
|
+
# Review
|
|
73
|
+
"CodeReviewInterface",
|
|
74
|
+
"ReviewState",
|
|
75
|
+
"create_review",
|
|
76
|
+
# Persistence
|
|
77
|
+
"CodePersistence",
|
|
78
|
+
"save_to_context",
|
|
79
|
+
]
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|