fix: commit semantic repair changes

This commit is contained in:
2026-03-21 11:22:25 +03:00
parent 0900208c1a
commit abee05558f
272 changed files with 4603 additions and 1668 deletions

View File

@@ -36,6 +36,7 @@ class belief_scope:
# [DEF:__enter__:Function]
# @TIER: TRIVIAL
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Mock enter.
# @PRE: Instance initialized.
# @POST: Returns self.
@@ -45,6 +46,7 @@ class belief_scope:
# [DEF:__exit__:Function]
# @TIER: TRIVIAL
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Mock exit.
# @PRE: Context entered.
# @POST: Context exited.
@@ -59,6 +61,7 @@ class belief_scope:
class Tier(Enum):
# [DEF:Tier:Class]
# @TIER: TRIVIAL
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Legacy tier buckets retained for backward-compatible reporting.
CRITICAL = "CRITICAL"
STANDARD = "STANDARD"
@@ -68,6 +71,7 @@ class Tier(Enum):
class Complexity(IntEnum):
# [DEF:Complexity:Class]
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Adaptive semantic complexity scale used for validation strictness.
ONE = 1
TWO = 2
@@ -80,6 +84,7 @@ class Complexity(IntEnum):
class Severity(Enum):
# [DEF:Severity:Class]
# @TIER: TRIVIAL
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Severity levels for compliance issues.
ERROR = "ERROR"
WARNING = "WARNING"
@@ -173,7 +178,8 @@ COMPLEXITY_BELIEF_REQUIRED = {
# [DEF:ComplianceIssue:Class]
# @TIER: TRIVIAL
# @PURPOSE: Represents a single compliance issue with severity.
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Represents a single compliance issue with severity.
@dataclass
class ComplianceIssue:
message: str
@@ -191,11 +197,13 @@ class ComplianceIssue:
# [DEF:SemanticEntity:Class]
# @TIER: CRITICAL
# @PURPOSE: Represents a code entity (Module, Function, Component) found during parsing.
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Represents a code entity (Module, Function, Component) found during parsing.
# @INVARIANT: start_line is always set; end_line is set upon closure; complexity defaults to 1 unless explicitly raised.
class SemanticEntity:
# [DEF:__init__:Function]
# @TIER: STANDARD
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Initializes a new SemanticEntity instance.
# @PRE: name, type_, start_line, file_path are provided.
# @POST: Instance is initialized with default values.
@@ -223,11 +231,13 @@ class SemanticEntity:
# [/DEF:__init__:Function]
# [DEF:has_explicit_complexity:Function]
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Returns whether the entity explicitly declares complexity metadata.
def has_explicit_complexity(self) -> bool:
return any(tag.upper() in {"COMPLEXITY", "C", "TIER"} for tag in self.tags)
# [DEF:get_complexity:Function]
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Returns effective complexity with backward compatibility for legacy tiers.
# @PRE: tags dictionary is accessible.
# @POST: Returns Complexity enum value.
@@ -277,6 +287,7 @@ class SemanticEntity:
# [DEF:get_tier:Function]
# @TIER: STANDARD
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Returns legacy tier bucket derived from effective complexity.
# @PRE: tags dictionary is accessible.
# @POST: Returns Tier enum value.
@@ -292,6 +303,7 @@ class SemanticEntity:
# [DEF:to_dict:Function]
# @TIER: STANDARD
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Serializes the entity to a dictionary for JSON output.
# @PRE: Entity is fully populated.
# @POST: Returns a dictionary representation.
@@ -431,6 +443,7 @@ class SemanticEntity:
# [DEF:get_score:Function]
# @TIER: STANDARD
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Calculates a compliance score (0.0 to 1.0) based on complexity requirements.
# @PRE: validate() has been called.
# @POST: Returns a float score.
@@ -520,7 +533,8 @@ def get_patterns(lang: str) -> Dict[str, Pattern]:
# [DEF:extract_svelte_props:Function]
# @TIER: STANDARD
# @PURPOSE: Extracts props from Svelte component script section.
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Extracts props from Svelte component script section.
# @PRE: lines is a list of file lines, start_idx is the starting line index.
# @POST: Returns list of prop definitions.
def extract_svelte_props(lines: List[str], start_idx: int) -> List[Dict[str, Any]]:
@@ -549,7 +563,8 @@ def extract_svelte_props(lines: List[str], start_idx: int) -> List[Dict[str, Any
# [DEF:extract_svelte_events:Function]
# @TIER: STANDARD
# @PURPOSE: Extracts dispatched events from Svelte component.
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Extracts dispatched events from Svelte component.
# @PRE: lines is a list of file lines.
# @POST: Returns list of event names.
def extract_svelte_events(lines: List[str]) -> List[str]:
@@ -586,7 +601,8 @@ def extract_svelte_events(lines: List[str]) -> List[str]:
# [DEF:extract_data_flow:Function]
# @TIER: STANDARD
# @PURPOSE: Extracts store subscriptions and data flow from Svelte component.
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Extracts store subscriptions and data flow from Svelte component.
# @PRE: lines is a list of file lines.
# @POST: Returns list of data flow descriptors.
def extract_data_flow(lines: List[str]) -> List[Dict[str, str]]:
@@ -639,7 +655,8 @@ def extract_data_flow(lines: List[str]) -> List[Dict[str, str]]:
# [DEF:parse_file:Function]
# @TIER: CRITICAL
# @PURPOSE: Parses a single file to extract semantic entities with tier awareness and enhanced Svelte analysis.
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Parses a single file to extract semantic entities with tier awareness and enhanced Svelte analysis.
# @PRE: full_path, rel_path, lang are valid strings.
# @POST: Returns extracted entities and list of issues.
# @INVARIANT: Every opened anchor must have a matching closing anchor for valid compliance.
@@ -838,11 +855,13 @@ def parse_file(full_path: str, rel_path: str, lang: str) -> Tuple[List[SemanticE
# [DEF:SemanticMapGenerator:Class]
# @TIER: CRITICAL
# @PURPOSE: Orchestrates the mapping process with tier-based validation.
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Orchestrates the mapping process with tier-based validation.
# @INVARIANT: All entities are validated according to their TIER requirements.
class SemanticMapGenerator:
# [DEF:__init__:Function]
# @TIER: STANDARD
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Initializes the generator with a root directory.
# @PRE: root_dir is a valid path string.
# @POST: Generator instance is ready.
@@ -857,6 +876,7 @@ class SemanticMapGenerator:
# [DEF:_load_gitignore:Function]
# @TIER: STANDARD
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Loads patterns from .gitignore file.
# @PRE: .gitignore exists in root_dir.
# @POST: Returns set of ignore patterns.
@@ -875,6 +895,7 @@ class SemanticMapGenerator:
# [DEF:_is_ignored:Function]
# @TIER: STANDARD
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Checks if a path should be ignored based on .gitignore or hardcoded defaults.
# @PRE: rel_path is a valid relative path string.
# @POST: Returns True if the path should be ignored.
@@ -933,6 +954,7 @@ class SemanticMapGenerator:
# [DEF:_walk_and_parse:Function]
# @TIER: CRITICAL
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Recursively walks directories and triggers parsing.
# @PRE: root_dir exists.
# @POST: All files are scanned and entities extracted.
@@ -964,6 +986,7 @@ class SemanticMapGenerator:
# [DEF:_process_file_results:Function]
# @TIER: STANDARD
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Validates entities and calculates file scores with tier awareness.
# @PRE: Entities have been parsed from the file.
# @POST: File score is calculated and issues collected.
@@ -975,7 +998,8 @@ class SemanticMapGenerator:
# [DEF:validate_recursive:Function]
# @TIER: STANDARD
# @PURPOSE: Calculate score and determine module's max tier for weighted global score
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Calculate score and determine module's max tier for weighted global score
# @PRE: Entities exist
# @POST: Entities are validated
def validate_recursive(ent_list):
@@ -1008,6 +1032,7 @@ class SemanticMapGenerator:
# [DEF:_generate_artifacts:Function]
# @TIER: CRITICAL
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Writes output files with tier-based compliance data.
# @PRE: Parsing and validation are complete.
# @POST: JSON and Markdown artifacts are written to disk.
@@ -1131,6 +1156,7 @@ class SemanticMapGenerator:
# [DEF:_generate_report:Function]
# @TIER: CRITICAL
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Generates the Markdown compliance report with severity levels.
# @PRE: File scores and issues are available.
# @POST: Markdown report is created in reports directory.
@@ -1205,6 +1231,7 @@ class SemanticMapGenerator:
# [DEF:_collect_issues:Function]
# @TIER: STANDARD
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Helper to collect issues for a specific file from the entity tree.
# @PRE: entities list and file_path are valid.
# @POST: issues list is populated with compliance issues.
@@ -1219,6 +1246,7 @@ class SemanticMapGenerator:
# [DEF:_generate_compressed_map:Function]
# @TIER: CRITICAL
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Generates the token-optimized project map with enhanced Svelte details.
# @PRE: Entities have been processed.
# @POST: Markdown project map is written.
@@ -1238,6 +1266,7 @@ class SemanticMapGenerator:
# [DEF:_write_entity_md:Function]
# @TIER: CRITICAL
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Recursive helper to write entity tree to Markdown with tier badges and enhanced details.
# @PRE: f is an open file handle, entity is valid.
# @POST: Entity details are written to the file.
@@ -1309,6 +1338,7 @@ class SemanticMapGenerator:
# [DEF:_generate_module_map:Function]
# @TIER: CRITICAL
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Generates a module-centric map grouping entities by directory structure.
# @PRE: Entities have been processed.
# @POST: Markdown module map is written to .ai/MODULE_MAP.md.
@@ -1321,7 +1351,8 @@ class SemanticMapGenerator:
# [DEF:_get_module_path:Function]
# @TIER: STANDARD
# @PURPOSE: Extracts the module path from a file path.
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Extracts the module path from a file path.
# @PRE: file_path is a valid relative path.
# @POST: Returns a module path string.
def _get_module_path(file_path: str) -> str:
@@ -1336,7 +1367,8 @@ class SemanticMapGenerator:
# [DEF:_collect_all_entities:Function]
# @TIER: STANDARD
# @PURPOSE: Flattens entity tree for easier grouping.
# @RELATION: [DEPENDS_ON] builtin
# @PURPOSE: Flattens entity tree for easier grouping.
# @PRE: entity list is valid.
# @POST: Returns flat list of all entities with their hierarchy.
def _collect_all_entities(entities: List[SemanticEntity], result: List[Tuple[str, SemanticEntity]]):