wip
This commit is contained in:
20
aggregate.py
20
aggregate.py
@@ -3,6 +3,7 @@ import tomllib
|
||||
import re
|
||||
import glob
|
||||
from pathlib import Path, PureWindowsPath
|
||||
import summarize
|
||||
|
||||
def find_next_increment(output_dir: Path, namespace: str) -> int:
|
||||
pattern = re.compile(rf"^{re.escape(namespace)}_(\d+)\.md$")
|
||||
@@ -104,12 +105,24 @@ def build_file_items(base_dir: Path, files: list[str]) -> list[dict]:
|
||||
error = True
|
||||
items.append({"path": path, "entry": entry, "content": content, "error": error})
|
||||
return items
|
||||
def build_markdown(base_dir: Path, files: list[str], screenshot_base_dir: Path, screenshots: list[str], history: list[str]) -> str:
|
||||
|
||||
def build_summary_section(base_dir: Path, files: list[str]) -> str:
|
||||
"""
|
||||
Build a compact summary section using summarize.py — one short block per file.
|
||||
Used as the initial <context> block instead of full file contents.
|
||||
"""
|
||||
items = build_file_items(base_dir, files)
|
||||
return summarize.build_summary_markdown(items)
|
||||
|
||||
def build_markdown(base_dir: Path, files: list[str], screenshot_base_dir: Path, screenshots: list[str], history: list[str], summary_only: bool = False) -> str:
|
||||
parts = []
|
||||
if history:
|
||||
parts.append("## Discussion History\n\n" + build_discussion_section(history))
|
||||
if files:
|
||||
parts.append("## Files\n\n" + build_files_section(base_dir, files))
|
||||
if summary_only:
|
||||
parts.append("## Files (Summary)\n\n" + build_summary_section(base_dir, files))
|
||||
else:
|
||||
parts.append("## Files\n\n" + build_files_section(base_dir, files))
|
||||
if screenshots:
|
||||
parts.append("## Screenshots\n\n" + build_screenshots_section(screenshot_base_dir, screenshots))
|
||||
return "\n\n---\n\n".join(parts)
|
||||
@@ -126,7 +139,8 @@ def run(config: dict) -> tuple[str, Path]:
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
increment = find_next_increment(output_dir, namespace)
|
||||
output_file = output_dir / f"{namespace}_{increment:03d}.md"
|
||||
markdown = build_markdown(base_dir, files, screenshot_base_dir, screenshots, history)
|
||||
markdown = build_markdown(base_dir, files, screenshot_base_dir, screenshots, history,
|
||||
summary_only=True)
|
||||
output_file.write_text(markdown, encoding="utf-8")
|
||||
file_items = build_file_items(base_dir, files)
|
||||
return markdown, output_file, file_items
|
||||
|
||||
Reference in New Issue
Block a user