File size: 5,737 Bytes
cf05092
 
 
 
 
 
 
 
 
 
 
899a7c7
 
 
cf05092
 
 
 
 
 
 
 
 
 
 
 
 
 
babc153
 
 
 
 
 
 
 
cf05092
 
 
 
899a7c7
cf05092
 
899a7c7
 
 
 
cf05092
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86c3e08
cf05092
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b196357
cf05092
 
 
b196357
 
 
cf05092
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
899a7c7
 
 
 
 
babc153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
902cd29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
from __future__ import annotations

from datetime import UTC, datetime
from enum import StrEnum
from typing import Optional

from sqlmodel import Field, SQLModel


class EdgeType(StrEnum):
    EXPLICIT_IMPORT = "explicit_import"
    IMPLICIT_DEPENDENCY = "implicit_dependency"
    INTRA_FILE = "intra_file"
    CIRCULAR = "circular"


class ReviewStatus(StrEnum):
    PENDING = "pending"
    IN_PROGRESS = "in_progress"
    REVIEWED = "reviewed"


class Severity(StrEnum):
    LOW = "low"
    MEDIUM = "medium"
    HIGH = "high"


class AnalyzerStatus(StrEnum):
    OK = "ok"
    TIMEOUT = "timeout"
    MISSING = "missing"
    PARSE_ERROR = "parse-error"
    NO_OUTPUT = "no-output"


class ModuleNode(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    source_root: str = Field(index=True)
    module_id: str = Field(index=True)
    name: Optional[str] = None
    raw_code: str
    ast_summary: str
    summary: Optional[str] = None
    linter_flags: str = "[]"
    parent_module_id: Optional[str] = Field(default=None, index=True)
    is_chunk: bool = False
    dependency_reason: str = ""
    review_annotation: Optional[str] = None
    review_status: ReviewStatus = Field(default=ReviewStatus.PENDING)
    review_summary: Optional[str] = None
    created_at: datetime = Field(default_factory=lambda: datetime.now(UTC))
    updated_at: datetime = Field(default_factory=lambda: datetime.now(UTC))


class ModuleEdge(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    source_root: str = Field(index=True)
    source_module_id: str = Field(index=True)
    target_module_id: str = Field(index=True)
    edge_type: EdgeType = Field(default=EdgeType.EXPLICIT_IMPORT)
    import_line: str
    weight: float = 1.0
    connection_summary: str = ""


class LinterFinding(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    source_root: str = Field(index=True)
    module_id: str = Field(index=True)
    tool: str = Field(index=True)
    line: int
    severity: Severity
    code: str
    message: str


class ReviewAnnotation(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    source_root: str = Field(index=True)
    module_id: str = Field(index=True)
    episode_id: str = Field(index=True)
    task_id: Optional[str] = Field(default=None, index=True)
    step_number: int
    action_type: str
    note: str
    reward_given: float = 0.0
    attributed_to: Optional[str] = Field(default=None, index=True)
    is_amendment: bool = False
    created_at: datetime = Field(default_factory=lambda: datetime.now(UTC))


class EpisodeRecord(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    source_root: str = Field(index=True)
    episode_id: str = Field(index=True)
    task_id: str = Field(index=True)
    module_id: str = Field(index=True)
    total_steps: int
    cumulative_reward: float = 0.0
    created_at: datetime = Field(default_factory=lambda: datetime.now(UTC))


class TaskDefinition(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    source_root: str = Field(index=True)
    task_id: str = Field(index=True)
    task_level: str = Field(index=True)
    target_module_id: str = Field(index=True)
    description: str
    ground_truth_ref: str


class SeedMeta(SQLModel, table=True):
    key: str = Field(primary_key=True)
    value: str


class AnalyzerRun(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    source_root: str = Field(index=True)
    analyzer: str = Field(index=True)
    analyzer_version: str = ""
    status: AnalyzerStatus = Field(default=AnalyzerStatus.OK)
    findings_count: int = 0
    command: str = ""
    command_hash: str = ""
    error_message: Optional[str] = None
    started_at: datetime = Field(default_factory=lambda: datetime.now(UTC))
    finished_at: datetime = Field(default_factory=lambda: datetime.now(UTC))


class AnalyzerFinding(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    source_root: str = Field(index=True)
    analyzer_run_id: int = Field(index=True)
    analyzer: str = Field(index=True)
    module_id: str = Field(index=True)
    line: int
    severity: Severity = Field(default=Severity.MEDIUM)
    rule_id: str = Field(index=True)
    message: str
    evidence: str = ""
    created_at: datetime = Field(default_factory=lambda: datetime.now(UTC))


class TrainingRun(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    source_root: str = Field(index=True)
    run_id: str = Field(index=True)
    model_name: str = Field(index=True)
    model_sha256: str = ""
    deterministic_findings: int = 0
    agent_findings: int = 0
    true_positives: int = 0
    false_positives: int = 0
    false_negatives: int = 0
    precision: float = 0.0
    recall: float = 0.0
    passed_non_regression: bool = True
    output_path: str = ""
    run_config_json: str = "{}"
    created_at: datetime = Field(default_factory=lambda: datetime.now(UTC))


class TrainingAnnotation(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    source_root: str = Field(index=True)
    run_id: str = Field(index=True)
    module_id: str = Field(index=True)
    task_id: str = Field(index=True)
    judge_verdict: str = ""
    avg_reward: float = 0.0
    correct_attributions_json: str = "[]"
    wrong_attributions_json: str = "[]"
    action_counts_json: str = "{}"
    action_type: str = ""
    action_payload: str = "{}"
    thinking_quality: float = 0.0
    created_at: datetime = Field(default_factory=lambda: datetime.now(UTC))