add file cache

This commit is contained in:
2026-02-21 16:31:33 -05:00
parent 9272fd42d6
commit d0d8f3e145
6 changed files with 1495 additions and 56 deletions

View File

@@ -1,4 +1,4 @@
# aggregate.py
# aggregate.py
import tomllib
import re
import glob
@@ -74,6 +74,36 @@ def build_screenshots_section(base_dir: Path, screenshots: list[str]) -> str:
sections.append(f"### `{original}`\n\n![{path.name}]({path.as_posix()})")
return "\n\n---\n\n".join(sections)
def build_file_items(base_dir: Path, files: list[str]) -> list[dict]:
"""
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.
Each dict has:
path : Path (resolved absolute path)
entry : str (original config entry string)
content : str (file text, or error string)
error : bool
"""
items = []
for entry in files:
paths = resolve_paths(base_dir, entry)
if not paths:
items.append({"path": None, "entry": entry, "content": f"ERROR: no files matched: {entry}", "error": True})
continue
for path in paths:
try:
content = path.read_text(encoding="utf-8")
error = False
except FileNotFoundError:
content = f"ERROR: file not found: {path}"
error = True
except Exception as e:
content = f"ERROR: {e}"
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:
parts = []
if history:
@@ -98,7 +128,8 @@ def run(config: dict) -> tuple[str, Path]:
output_file = output_dir / f"{namespace}_{increment:03d}.md"
markdown = build_markdown(base_dir, files, screenshot_base_dir, screenshots, history)
output_file.write_text(markdown, encoding="utf-8")
return markdown, output_file
file_items = build_file_items(base_dir, files)
return markdown, output_file, file_items
def main():
with open("config.toml", "rb") as f:
@@ -109,3 +140,5 @@ def main():
if __name__ == "__main__":
main()