final updates
This commit is contained in:
30
aggregate.py
30
aggregate.py
@@ -126,6 +126,24 @@ def build_summary_section(base_dir: Path, files: list[str]) -> str:
|
||||
items = build_file_items(base_dir, files)
|
||||
return summarize.build_summary_markdown(items)
|
||||
|
||||
def build_static_markdown(base_dir: Path, files: list[str], screenshot_base_dir: Path, screenshots: list[str], summary_only: bool = False) -> str:
|
||||
"""Build the static (cacheable) portion of the context: files + screenshots."""
|
||||
parts = []
|
||||
if 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)
|
||||
|
||||
def build_dynamic_markdown(history: list[str]) -> str:
|
||||
"""Build the dynamic (changes every turn) portion: discussion history."""
|
||||
if history:
|
||||
return "## Discussion History\n\n" + build_discussion_section(history)
|
||||
return ""
|
||||
|
||||
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 = []
|
||||
# STATIC PREFIX: Files and Screenshots must go first to maximize Cache Hits
|
||||
@@ -155,18 +173,20 @@ 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"
|
||||
# Provide full files to trigger Gemini's 32k cache threshold and give the AI immediate context
|
||||
markdown = build_markdown(base_dir, files, screenshot_base_dir, screenshots, history,
|
||||
summary_only=False)
|
||||
# Build static (files+screenshots) and dynamic (discussion) portions separately for better caching
|
||||
static_md = build_static_markdown(base_dir, files, screenshot_base_dir, screenshots, summary_only=False)
|
||||
dynamic_md = build_dynamic_markdown(history)
|
||||
# Write combined markdown to disk for archival
|
||||
markdown = f"{static_md}\n\n---\n\n{dynamic_md}" if static_md and dynamic_md else static_md or dynamic_md
|
||||
output_file.write_text(markdown, encoding="utf-8")
|
||||
file_items = build_file_items(base_dir, files)
|
||||
return markdown, output_file, file_items
|
||||
return static_md, dynamic_md, output_file, file_items
|
||||
|
||||
def main():
|
||||
with open("config.toml", "rb") as f:
|
||||
import tomllib
|
||||
config = tomllib.load(f)
|
||||
markdown, output_file, _ = run(config)
|
||||
static_md, dynamic_md, output_file, _ = run(config)
|
||||
print(f"Written: {output_file}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user