Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion sumd/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ def _map_module_count(text: str) -> int:
return int(m.group(1)) if m else -1


def _is_code2llm_owned_map(text: str) -> bool:
"""Return whether the canonical map declares code2llm ownership."""
return "# producer: code2llm | artifact: map.toon.yaml" in text[:2048]


def _refresh_map_toon(proj_dir: Path) -> None:
"""Regenerate project/map.toon.yaml and project/logic.pl from current source before embedding.

Expand All @@ -82,7 +87,9 @@ def _refresh_map_toon(proj_dir: Path) -> None:
regresses = False
if map_path.exists():
existing = map_path.read_text(encoding="utf-8", errors="ignore")
regresses = _map_module_count(existing) > _map_module_count(content)
regresses = _is_code2llm_owned_map(existing) or (
_map_module_count(existing) > _map_module_count(content)
)
if not regresses:
map_path.parent.mkdir(parents=True, exist_ok=True)
map_path.write_text(content, encoding="utf-8")
Expand Down
16 changes: 16 additions & 0 deletions tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ def test_refresh_map_toon_writes_file(tmp_path: Path):
assert True # no exception = pass


def test_refresh_map_toon_preserves_code2llm_owned_artifact(tmp_path: Path):
project_dir = tmp_path / "project"
project_dir.mkdir()
map_path = project_dir / "map.toon.yaml"
canonical = (
"# demo | 2f 10L | python:2 | 2026-07-18\n"
"# producer: code2llm | artifact: map.toon.yaml | schema: 1\n"
"M[2]:\n app.py,5\n lib.py,5\nD:\n app.py:\n main()\n"
)
map_path.write_text(canonical, encoding="utf-8")

_refresh_map_toon(tmp_path)

assert map_path.read_text(encoding="utf-8") == canonical


def test_refresh_analysis_files_noop_without_tools(tmp_path: Path):
# No .sumd-tools/venv → must complete without raising
_refresh_analysis_files(tmp_path, "refactor")
Loading