Private
Public Access
0
0

progress on context composition

This commit is contained in:
2026-05-17 07:27:55 -04:00
parent c1487d32bb
commit a5c0569417
4 changed files with 194 additions and 119 deletions
+6 -13
View File
@@ -22,7 +22,6 @@ For each file, extracts structural information:
Returns a compact markdown string per file, suitable for use as a low-token
context block that replaces full file contents in the initial <context> send.
"""
import ast
import re
from pathlib import Path
@@ -42,7 +41,6 @@ def _summarise_python(path: Path, content: str) -> str:
except SyntaxError as e:
parts.append(f"_Parse error: {e}_")
return "\n".join(parts)
# Imports
imports = []
for node in ast.walk(tree):
if isinstance(node, ast.Import):
@@ -54,7 +52,6 @@ def _summarise_python(path: Path, content: str) -> str:
if imports:
unique_imports = sorted(set(imports))
parts.append(f"imports: {', '.join(unique_imports)}")
# Top-level constants (ALL_CAPS assignments)
constants = []
for node in ast.iter_child_nodes(tree):
if isinstance(node, ast.Assign):
@@ -66,7 +63,6 @@ def _summarise_python(path: Path, content: str) -> str:
constants.append(node.target.id)
if constants:
parts.append(f"constants: {', '.join(constants)}")
# Classes + their methods
for node in ast.iter_child_nodes(tree):
if isinstance(node, ast.ClassDef):
methods = [
@@ -77,7 +73,6 @@ def _summarise_python(path: Path, content: str) -> str:
parts.append(f"class {node.name}: {', '.join(methods)}")
else:
parts.append(f"class {node.name}")
# Top-level functions
top_fns = [
node.name for node in ast.iter_child_nodes(tree)
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef))
@@ -90,7 +85,6 @@ def _summarise_toml(path: Path, content: str) -> str:
lines = content.splitlines()
line_count = len(lines)
parts = [f"**TOML** — {line_count} lines"]
# Extract top-level table headers [key] and [[key]]
table_pat = re.compile(r"^\s*\[{1,2}([^\[\]]+)\]{1,2}")
tables = []
for line in lines:
@@ -99,7 +93,6 @@ def _summarise_toml(path: Path, content: str) -> str:
tables.append(m.group(1).strip())
if tables:
parts.append(f"tables: {', '.join(tables)}")
# Top-level key = value (not inside a [table])
kv_pat = re.compile(r"^([a-zA-Z_][a-zA-Z0-9_]*)\s*=")
in_table = False
top_keys = []
@@ -140,7 +133,6 @@ def _summarise_generic(path: Path, content: str) -> str:
if preview:
parts.append("preview:\n```\n" + "\n".join(preview) + "\n```")
return "\n".join(parts)
# ------------------------------------------------------------------ dispatch
_SUMMARISERS: dict[str, Callable[[Path, str], str]] = {
".py": _summarise_python,
@@ -148,6 +140,10 @@ _SUMMARISERS: dict[str, Callable[[Path, str], str]] = {
".md": _summarise_markdown,
".ini": _summarise_generic,
".txt": _summarise_generic,
".c": _summarise_generic,
".h": _summarise_generic,
".cpp": _summarise_generic,
".hpp": _summarise_generic,
".ps1": _summarise_generic,
}
@@ -163,19 +159,17 @@ def summarise_file(path: Path, content: str) -> str:
cached = _summary_cache.get_summary(str(path), content_hash)
if cached:
return cached
suffix = path.suffix.lower() if hasattr(path, "suffix") else ""
fn = _SUMMARISERS.get(suffix, _summarise_generic)
try:
heuristic_outline = fn(path, content)
# Smart AI Summarization
is_code = suffix in [".py", ".ps1", ".js", ".ts", ".cpp", ".c", ".h", ".cs", ".go", ".rs", ".lua"]
try:
from src import ai_client
smart_summary = ai_client.run_subagent_summarization(
file_path=str(path),
content=content[:10000], # Cap content to 10k chars for summarization
content=content[:10000],
is_code=is_code,
outline=heuristic_outline
)
@@ -184,8 +178,7 @@ def summarise_file(path: Path, content: str) -> str:
else:
summary = heuristic_outline
except Exception:
summary = heuristic_outline # Fallback
summary = heuristic_outline
_summary_cache.set_summary(str(path), content_hash, summary)
return summary
except Exception as e: