Skip to content

Commit b59a127

Browse files
refactor(docs): code analysis engine
changes: - file: mermaid_exporter.py area: core added: [_sanitize_identifier] modified: [MermaidExporter, _readable_id, _safe_module] - file: test_analyzer.py area: analyzer new_tests: 1 modified: [TestExporters] testing: new_tests: 1 scenarios: - mermaid_export_sanitizes_unsafe_identifiers stats: lines: "+263/-238 (net +25)" files: 13 complexity: "Large structural change (normalized)"
1 parent f5ad596 commit b59a127

19 files changed

+294
-248
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
## [Unreleased]
22

3+
## [0.5.97] - 2026-03-26
4+
5+
### Docs
6+
- Update project/context.md
7+
8+
### Test
9+
- Update tests/test_analyzer.py
10+
11+
### Other
12+
- Update code2llm/exporters/mermaid_exporter.py
13+
- Update project/analysis.toon.yaml
14+
- Update project/calls.mmd
15+
- Update project/calls.png
16+
- Update project/compact_flow.mmd
17+
- Update project/compact_flow.png
18+
- Update project/flow.mmd
19+
- Update project/flow.png
20+
- Update project/index.html
21+
- Update project/map.toon.yaml
22+
323
## [0.5.96] - 2026-03-26
424

525
### Docs

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ When you run `code2llm ./ -f all`, the following files are created:
2626
# Quick health check (TOON format only)
2727
code2llm ./ -f toon
2828

29-
# Generate all formats + project.toon.yaml + prompt.txt (single-project mode)
30-
code2llm ./ -f all -o ./project --no-chunk
29+
# Generate all formats (what created these files)
30+
code2llm ./ -f all
3131

3232
# LLM-ready context only
3333
code2llm ./ -f context
@@ -142,12 +142,13 @@ grep -E "^ .*[0-9]{3,}$" project.toon.yaml | sort -t',' -k2 -n -r | head -10
142142

143143
### `prompt.txt` - Ready-to-Send LLM Prompt
144144
**Purpose**: Pre-formatted prompt listing all generated files for LLM conversation
145-
**Generation**: Written when `code2llm` runs with a source path and requests `-f all` (including `--no-chunk`) or `code2logic`; `-f all` also writes `project.toon.yaml`
145+
**Generation**: Written when `code2llm` runs with a source path and requests `-f all` (including `--no-chunk`) or `code2logic`
146146
**Contents**:
147-
- **Files section**: Lists all existing generated files with descriptions
147+
- **Files section**: Lists all existing generated files with descriptions, including `project.toon.yaml` when generated by `-f all`
148148
- **Source files section**: Highlights important source files such as `cli_exports/orchestrator.py`
149149
- **Missing section**: Shows which files weren't generated (if any)
150-
- **Task section**: Instructions for LLM analysis
150+
- **Task section**: Refactoring brief with concrete execution instructions, not just analysis
151+
- **Priority Order section**: State-dependent refactoring priorities, starting with blockers and then architecture cleanup
151152
- **Requirements section**: Guidelines for suggested changes
152153

153154
**Example usage**:
@@ -322,7 +323,7 @@ code2llm ./ -f yaml --separate-orphans
322323

323324
**Generated by**: `code2llm ./ -f all --readme`
324325
**Analysis Date**: 2026-03-26
325-
**Total Functions**: 931
326+
**Total Functions**: 934
326327
**Total Classes**: 106
327328
**Modules**: 122
328329

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.96
1+
0.5.97

code2llm/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
and entity resolution with multilingual support.
99
"""
1010

11-
__version__ = "0.5.96"
11+
__version__ = "0.5.97"
1212
__author__ = "STTS Project"
1313

1414
# Core analysis components (lightweight, always needed)

code2llm/exporters/mermaid_exporter.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"""
1313

1414
from collections import defaultdict
15+
import re
1516
from pathlib import Path
1617
from typing import Dict, List, Set, Tuple, Optional
1718
from .base import Exporter
@@ -581,32 +582,22 @@ def _readable_id(self, name: str) -> str:
581582
code2llm.core.analyze → code2llm__core__analyze
582583
code2llm.core.PipelineDetector.__init__ → code2llm__core__PipelineDetector____init__
583584
"""
584-
# Convert dots to double underscores to preserve hierarchy
585-
safe = name.replace('.', '__')
586-
# Replace other unsafe chars
587-
safe = safe.replace('-', '_').replace(':', '_').replace(' ', '_')
588-
# Keep reasonable length but preserve class+method uniqueness
589-
if len(safe) > 60:
590-
parts = name.split('.')
591-
if len(parts) >= 3:
592-
# module__Class__method or module__subpackage__Class__method
593-
module = parts[0]
594-
method = parts[-1]
595-
# Include class name if present (parts[-2] is usually class or subpackage)
596-
if len(parts) >= 4 and parts[-2][0].isupper():
597-
# Definitely a class: module.sub.Class.method
598-
class_name = parts[-2]
599-
safe = f"{module}__{class_name}__{method}"
600-
else:
601-
# Might be module.subpackage.function
602-
middle = '__'.join(parts[1:-1])
603-
safe = f"{module}__{middle}__{method}"
604-
safe = safe[:60]
605-
return safe
585+
return self._sanitize_identifier(name, prefix="N")
606586

607587
def _safe_module(self, name: str) -> str:
608588
"""Create safe subgraph name."""
609-
return name.replace('.', '_').replace('-', '_').replace('/', '_').replace(' ', '_')
589+
return self._sanitize_identifier(name, prefix="M")
590+
591+
@staticmethod
592+
def _sanitize_identifier(name: str, prefix: str) -> str:
593+
"""Convert an arbitrary string into a Mermaid-safe identifier."""
594+
safe = (name or "").replace('.', '__')
595+
safe = re.sub(r'[^A-Za-z0-9_]+', '_', safe)
596+
if not safe:
597+
return prefix
598+
if not safe[0].isalpha():
599+
safe = f"{prefix}_{safe}"
600+
return safe
610601

611602
def _module_of(self, func_name: str) -> str:
612603
"""Extract module from qualified name.

code2llm/nlp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
with multilingual support and fuzzy matching.
55
"""
66

7-
__version__ = "0.5.96"
7+
__version__ = "0.5.97"
88

99
from .pipeline import NLPPipeline
1010
from .normalization import QueryNormalizer

project/analysis.toon.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ REFACTOR[1]:
2020
PIPELINES[637]:
2121
[1] Src [read_readme]: read_readme
2222
PURITY: 100% pure
23-
[2] Src [run_benchmark]: run_benchmark → load_previous
23+
[2] Src [save_report]: save_report
2424
PURITY: 100% pure
25-
[3] Src [save_report]: save_report
25+
[3] Src [run_benchmark]: run_benchmark → load_previous
2626
PURITY: 100% pure
2727
[4] Src [main]: main → load_file → is_toon_file
2828
PURITY: 100% pure

0 commit comments

Comments
 (0)