feat(ui): Enhanced context control with per-file flags and Gemini cache awareness
This commit is contained in:
@@ -122,26 +122,32 @@ def build_file_items(base_dir: Path, files: list[str | dict[str, Any]]) -> list[
|
||||
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
|
||||
mtime : float (last modification time, for skip-if-unchanged optimization)
|
||||
tier : int | None (optional tier for context management)
|
||||
path : Path (resolved absolute path)
|
||||
entry : str (original config entry string)
|
||||
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)
|
||||
auto_aggregate : bool
|
||||
force_full : bool
|
||||
"""
|
||||
items: list[dict[str, Any]] = []
|
||||
for entry_raw in files:
|
||||
if isinstance(entry_raw, dict):
|
||||
entry = cast(str, entry_raw.get("path", ""))
|
||||
tier = entry_raw.get("tier")
|
||||
auto_aggregate = entry_raw.get("auto_aggregate", True)
|
||||
force_full = entry_raw.get("force_full", False)
|
||||
else:
|
||||
entry = entry_raw
|
||||
tier = None
|
||||
auto_aggregate = True
|
||||
force_full = False
|
||||
if not entry or not isinstance(entry, str):
|
||||
continue
|
||||
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, "tier": tier})
|
||||
items.append({"path": None, "entry": entry, "content": f"ERROR: no files matched: {entry}", "error": True, "mtime": 0.0, "tier": tier, "auto_aggregate": auto_aggregate, "force_full": force_full})
|
||||
continue
|
||||
for path in paths:
|
||||
try:
|
||||
@@ -156,7 +162,7 @@ def build_file_items(base_dir: Path, files: list[str | dict[str, Any]]) -> list[
|
||||
content = f"ERROR: {e}"
|
||||
mtime = 0.0
|
||||
error = True
|
||||
items.append({"path": path, "entry": entry, "content": content, "error": error, "mtime": mtime, "tier": tier})
|
||||
items.append({"path": path, "entry": entry, "content": content, "error": error, "mtime": mtime, "tier": tier, "auto_aggregate": auto_aggregate, "force_full": force_full})
|
||||
return items
|
||||
|
||||
def build_summary_section(base_dir: Path, files: list[str | dict[str, Any]]) -> str:
|
||||
@@ -171,6 +177,8 @@ 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)."""
|
||||
sections = []
|
||||
for item in file_items:
|
||||
if not item.get("auto_aggregate", True):
|
||||
continue
|
||||
path = item.get("path")
|
||||
entry = cast(str, item.get("entry", "unknown"))
|
||||
content = cast(str, item.get("content", ""))
|
||||
@@ -221,9 +229,11 @@ def build_tier1_context(file_items: list[dict[str, Any]], screenshot_base_dir: P
|
||||
if file_items:
|
||||
sections = []
|
||||
for item in file_items:
|
||||
if not item.get("auto_aggregate", True):
|
||||
continue
|
||||
path = item.get("path")
|
||||
name = path.name if path and isinstance(path, Path) else ""
|
||||
if name in core_files or item.get("tier") == 1:
|
||||
if name in core_files or item.get("tier") == 1 or item.get("force_full"):
|
||||
# Include in full
|
||||
sections.append("### `" + (cast(str, item.get("entry")) or str(path)) + "`\n\n" +
|
||||
f"```{path.suffix.lstrip('.') if path and isinstance(path, Path) and path.suffix else 'text'}\n{item.get('content', '')}\n```")
|
||||
@@ -255,6 +265,8 @@ def build_tier3_context(file_items: list[dict[str, Any]], screenshot_base_dir: P
|
||||
if file_items:
|
||||
sections = []
|
||||
for item in file_items:
|
||||
if not item.get("auto_aggregate", True):
|
||||
continue
|
||||
path = cast(Path, item.get("path"))
|
||||
entry = cast(str, item.get("entry", ""))
|
||||
path_str = str(path) if path else ""
|
||||
@@ -264,7 +276,7 @@ def build_tier3_context(file_items: list[dict[str, Any]], screenshot_base_dir: P
|
||||
if focus == entry or (path and focus == path.name) or (path_str and focus in path_str):
|
||||
is_focus = True
|
||||
break
|
||||
if is_focus or item.get("tier") == 3:
|
||||
if is_focus or item.get("tier") == 3 or item.get("force_full"):
|
||||
sections.append("### `" + (entry or path_str) + "`\n\n" +
|
||||
f"```{path.suffix.lstrip('.') if path and path.suffix else 'text'}\n{item.get('content', '')}\n```")
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user