feat(aggregate): support dictionary-based file entries with optional tiers

This commit is contained in:
2026-02-27 22:21:18 -05:00
parent 4c744f2c8e
commit 2ece9e1141
2 changed files with 62 additions and 8 deletions

View File

@@ -64,9 +64,14 @@ def build_discussion_section(history: list[str]) -> str:
sections.append(f"### Discussion Excerpt {i}\n\n{paste.strip()}")
return "\n\n---\n\n".join(sections)
def build_files_section(base_dir: Path, files: list[str]) -> str:
def build_files_section(base_dir: Path, files: list[str | dict]) -> str:
sections = []
for entry in files:
for entry_raw in files:
if isinstance(entry_raw, dict):
entry = entry_raw.get("path")
else:
entry = entry_raw
paths = resolve_paths(base_dir, entry)
if not paths:
sections.append(f"### `{entry}`\n\n```text\nERROR: no files matched: {entry}\n```")
@@ -100,7 +105,7 @@ def build_screenshots_section(base_dir: Path, screenshots: list[str]) -> str:
return "\n\n---\n\n".join(sections)
def build_file_items(base_dir: Path, files: list[str]) -> list[dict]:
def build_file_items(base_dir: Path, files: list[str | dict]) -> 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.
@@ -111,12 +116,20 @@ def build_file_items(base_dir: Path, files: list[str]) -> list[dict]:
content : str (file text, or error string)
error : bool
mtime : float (last modification time, for skip-if-unchanged optimization)
tier : int | None (optional tier for context management)
"""
items = []
for entry in files:
for entry_raw in files:
if isinstance(entry_raw, dict):
entry = entry_raw.get("path")
tier = entry_raw.get("tier")
else:
entry = entry_raw
tier = None
paths = resolve_paths(base_dir, entry)
if not paths:
items.append({"path": None, "entry": entry, "content": f"ERROR: no files matched: {entry}", "error": True, "mtime": 0.0})
items.append({"path": None, "entry": entry, "content": f"ERROR: no files matched: {entry}", "error": True, "mtime": 0.0, "tier": tier})
continue
for path in paths:
try:
@@ -131,10 +144,10 @@ def build_file_items(base_dir: Path, files: list[str]) -> list[dict]:
content = f"ERROR: {e}"
mtime = 0.0
error = True
items.append({"path": path, "entry": entry, "content": content, "error": error, "mtime": mtime})
items.append({"path": path, "entry": entry, "content": content, "error": error, "mtime": mtime, "tier": tier})
return items
def build_summary_section(base_dir: Path, files: list[str]) -> str:
def build_summary_section(base_dir: Path, files: list[str | dict]) -> 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.
@@ -279,7 +292,7 @@ def build_tier3_context(file_items: list[dict], screenshot_base_dir: Path, scree
return "\n\n---\n\n".join(parts)
def build_markdown(base_dir: Path, files: list[str], screenshot_base_dir: Path, screenshots: list[str], history: list[str], summary_only: bool = False) -> str:
def build_markdown(base_dir: Path, files: list[str | dict], 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
if files: