minor cleanup aggregae.py

This commit is contained in:
2026-05-14 00:23:02 -04:00
parent 292b021174
commit ef91c64a65
+5 -21
View File
@@ -12,15 +12,15 @@ Instead of sending every file to the AI raw (which blows up tokens), this uses a
This is essential for keeping prompt tokens low while giving the AI enough structural info This is essential for keeping prompt tokens low while giving the AI enough structural info
to use the MCP tools to fetch only what it needs. to use the MCP tools to fetch only what it needs.
""" """
import tomllib
import re
import glob import glob
import os import os
import re
import tomllib
from pathlib import Path, PureWindowsPath from pathlib import Path, PureWindowsPath
from typing import Any, cast from typing import Any, cast
from src import summarize
from src import project_manager
from src import beads_client from src import beads_client
from src import project_manager
from src import summarize
from src.file_cache import ASTParser from src.file_cache import ASTParser
from src.performance_monitor import get_monitor from src.performance_monitor import get_monitor
@@ -101,9 +101,6 @@ def compute_file_stats(abs_path: str) -> dict[str, int]:
def build_discussion_section(history: list[Any]) -> str: def build_discussion_section(history: list[Any]) -> str:
""" """
Builds a markdown section for discussion history. Builds a markdown section for discussion history.
Handles both legacy list[str] and new list[dict]. Handles both legacy list[str] and new list[dict].
""" """
@@ -118,7 +115,6 @@ def build_discussion_section(history: list[Any]) -> str:
sections.append(f"### Discussion Excerpt {i}\n\n{text}") sections.append(f"### Discussion Excerpt {i}\n\n{text}")
return "\n\n---\n\n".join(sections) return "\n\n---\n\n".join(sections)
def build_screenshots_section(base_dir: Path, screenshots: list[str]) -> str: def build_screenshots_section(base_dir: Path, screenshots: list[str]) -> str:
sections = [] sections = []
for entry in screenshots: for entry in screenshots:
@@ -138,9 +134,6 @@ def build_screenshots_section(base_dir: Path, screenshots: list[str]) -> str:
def build_file_items(base_dir: Path, files: list[str | dict[str, Any]]) -> list[dict[str, Any]]: def build_file_items(base_dir: Path, files: list[str | dict[str, Any]]) -> list[dict[str, Any]]:
""" """
Return a list of dicts describing each file, for use by ai_client when it Return a list of dicts describing each file, for use by ai_client when it
wants to upload individual files rather than inline everything as markdown. wants to upload individual files rather than inline everything as markdown.
@@ -249,11 +242,8 @@ def build_file_items(base_dir: Path, files: list[str | dict[str, Any]]) -> list[
items.append({"path": path, "entry": entry, "content": content, "error": error, "mtime": mtime, "tier": tier, "auto_aggregate": auto_aggregate, "force_full": force_full, "view_mode": view_mode, "ast_signatures": ast_signatures, "ast_definitions": ast_definitions, "ast_mask": ast_mask, "custom_slices": custom_slices}) items.append({"path": path, "entry": entry, "content": content, "error": error, "mtime": mtime, "tier": tier, "auto_aggregate": auto_aggregate, "force_full": force_full, "view_mode": view_mode, "ast_signatures": ast_signatures, "ast_definitions": ast_definitions, "ast_mask": ast_mask, "custom_slices": custom_slices})
return items return items
def _build_files_section_from_items(file_items: list[dict[str, Any]]) -> str: def _build_files_section_from_items(file_items: list[dict[str, Any]]) -> str:
""" """
Build the files markdown section from pre-read file items (avoids double I/O). Build the files markdown section from pre-read file items (avoids double I/O).
[C: tests/test_aggregate_flags.py:test_auto_aggregate_skip, tests/test_context_composition_phase6.py:test_files_section_rendering, tests/test_tiered_context.py:test_build_files_section_with_dicts, tests/test_ui_summary_only_removal.py:test_aggregate_from_items_respects_auto_aggregate] [C: tests/test_aggregate_flags.py:test_auto_aggregate_skip, tests/test_context_composition_phase6.py:test_files_section_rendering, tests/test_tiered_context.py:test_build_files_section_with_dicts, tests/test_ui_summary_only_removal.py:test_aggregate_from_items_respects_auto_aggregate]
""" """
@@ -331,8 +321,6 @@ def build_markdown_from_items(file_items: list[dict[str, Any]], screenshot_base_
def build_markdown_no_history(file_items: list[dict[str, Any]], screenshot_base_dir: Path, screenshots: list[str], summary_only: bool = False, aggregation_strategy: str = "auto") -> str: def build_markdown_no_history(file_items: list[dict[str, Any]], screenshot_base_dir: Path, screenshots: list[str], summary_only: bool = False, aggregation_strategy: str = "auto") -> str:
""" """
Build markdown with only files + screenshots (no history). Used for stable caching. Build markdown with only files + screenshots (no history). Used for stable caching.
[C: src/app_controller.py:AppController._do_generate, tests/test_history_management.py:test_aggregate_blacklist] [C: src/app_controller.py:AppController._do_generate, tests/test_history_management.py:test_aggregate_blacklist]
""" """
@@ -340,8 +328,6 @@ def build_markdown_no_history(file_items: list[dict[str, Any]], screenshot_base_
def build_discussion_text(history: list[str]) -> str: def build_discussion_text(history: list[str]) -> str:
""" """
Build just the discussion history section text. Returns empty string if no history. Build just the discussion history section text. Returns empty string if no history.
[C: src/app_controller.py:AppController._do_generate, tests/test_history_management.py:test_aggregate_includes_segregated_history] [C: src/app_controller.py:AppController._do_generate, tests/test_history_management.py:test_aggregate_includes_segregated_history]
""" """
@@ -351,9 +337,6 @@ def build_discussion_text(history: list[str]) -> str:
def build_tier3_context(file_items: list[dict[str, Any]], screenshot_base_dir: Path, screenshots: list[str], history: list[str], focus_files: list[str]) -> str: def build_tier3_context(file_items: list[dict[str, Any]], screenshot_base_dir: Path, screenshots: list[str], history: list[str], focus_files: list[str]) -> str:
""" """
Tier 3 Context: Execution/Worker. Tier 3 Context: Execution/Worker.
Full content for focus_files and files with tier=3, summaries/skeletons for others. Full content for focus_files and files with tier=3, summaries/skeletons for others.
[C: tests/test_aggregate_flags.py:test_auto_aggregate_skip, tests/test_aggregate_flags.py:test_force_full, tests/test_ast_masking_core.py:test_ast_masking_gencpp_samples, tests/test_gencpp_full_suite.py:test_gencpp_full_suite, tests/test_perf_aggregate.py:test_build_tier3_context_scaling, tests/test_tiered_context.py:test_build_tier3_context_ast_skeleton, tests/test_tiered_context.py:test_build_tier3_context_exists, tests/test_tiered_context.py:test_tiered_context_by_tier_field] [C: tests/test_aggregate_flags.py:test_auto_aggregate_skip, tests/test_aggregate_flags.py:test_force_full, tests/test_ast_masking_core.py:test_ast_masking_gencpp_samples, tests/test_gencpp_full_suite.py:test_gencpp_full_suite, tests/test_perf_aggregate.py:test_build_tier3_context_scaling, tests/test_tiered_context.py:test_build_tier3_context_ast_skeleton, tests/test_tiered_context.py:test_build_tier3_context_exists, tests/test_tiered_context.py:test_tiered_context_by_tier_field]
@@ -507,3 +490,4 @@ def main() -> None:
if __name__ == "__main__": if __name__ == "__main__":
main() main()