progress on context composition
This commit is contained in:
+71
-40
@@ -199,52 +199,83 @@ def build_file_items(base_dir: Path, files: list[str | dict[str, Any]]) -> list[
|
||||
mtime = path.stat().st_mtime
|
||||
error = False
|
||||
if not error and view_mode != "full":
|
||||
if view_mode == "summary":
|
||||
content = summarize.summarise_file(path, content)
|
||||
elif view_mode == "skeleton":
|
||||
if path.suffix == ".py":
|
||||
if not parser: parser = ASTParser("python")
|
||||
content = parser.get_skeleton(content, path=str(path))
|
||||
elif path.suffix in ['.c', '.h', '.cpp', '.hpp', '.cxx', '.cc']:
|
||||
from src import mcp_client
|
||||
if path.suffix in ['.c', '.h']: content = mcp_client.ts_c_get_skeleton(str(path))
|
||||
else: content = mcp_client.ts_cpp_get_skeleton(str(path))
|
||||
else:
|
||||
content = summarize.summarise_file(path, content)
|
||||
elif view_mode == "outline":
|
||||
if path.suffix == ".py":
|
||||
if not parser: parser = ASTParser("python")
|
||||
content = parser.get_code_outline(content, path=str(path))
|
||||
elif path.suffix in ['.c', '.h', '.cpp', '.hpp', '.cxx', '.cc']:
|
||||
from src import mcp_client
|
||||
if path.suffix in ['.c', '.h']: content = mcp_client.ts_c_get_code_outline(str(path))
|
||||
else: content = mcp_client.ts_cpp_get_code_outline(str(path))
|
||||
else:
|
||||
content = summarize.summarise_file(path, content)
|
||||
elif view_mode == "none":
|
||||
content = "(context excluded)"
|
||||
elif view_mode == "custom":
|
||||
if custom_slices:
|
||||
lines = content.splitlines()
|
||||
slices_text = []
|
||||
for s in custom_slices:
|
||||
start = s.get("start_line", 1)
|
||||
end = s.get("end_line", len(lines))
|
||||
tag = s.get("tag", "unnamed")
|
||||
comment = s.get("comment", "")
|
||||
s_idx = max(0, start - 1)
|
||||
e_idx = min(len(lines), end)
|
||||
chunk = "\n".join(lines[s_idx:e_idx])
|
||||
slices_text.append(f"---\n[Slice: {tag}] ({comment})\nLines {start}-{end}:\n{chunk}")
|
||||
content = "\n\n".join(slices_text)
|
||||
else:
|
||||
try:
|
||||
if view_mode == "summary":
|
||||
content = summarize.summarise_file(path, content)
|
||||
elif view_mode == "skeleton":
|
||||
suffix_lower = path.suffix.lower()
|
||||
if suffix_lower == ".py":
|
||||
if not parser: parser = ASTParser("python")
|
||||
content = parser.get_skeleton(content, path=str(path))
|
||||
elif suffix_lower in ['.c', '.h', '.cpp', '.hpp', '.cxx', '.cc']:
|
||||
from src import mcp_client
|
||||
if suffix_lower in ['.c', '.h']: content = mcp_client.ts_c_get_skeleton(str(path))
|
||||
else: content = mcp_client.ts_cpp_get_skeleton(str(path))
|
||||
else:
|
||||
content = summarize.summarise_file(path, content)
|
||||
elif view_mode == "outline":
|
||||
suffix_lower = path.suffix.lower()
|
||||
if suffix_lower == ".py":
|
||||
if not parser: parser = ASTParser("python")
|
||||
content = parser.get_code_outline(content, path=str(path))
|
||||
elif suffix_lower in ['.c', '.h', '.cpp', '.hpp', '.cxx', '.cc']:
|
||||
from src import mcp_client
|
||||
if suffix_lower in ['.c', '.h']: content = mcp_client.ts_c_get_code_outline(str(path))
|
||||
else: content = mcp_client.ts_cpp_get_code_outline(str(path))
|
||||
else:
|
||||
content = summarize.summarise_file(path, content)
|
||||
elif view_mode == "masked":
|
||||
suffix_lower = path.suffix.lower()
|
||||
if ast_mask:
|
||||
mask_sections = []
|
||||
from src import mcp_client
|
||||
for symbol, mode in ast_mask.items():
|
||||
if mode == "hide": continue
|
||||
res = ""
|
||||
if suffix_lower == ".py":
|
||||
res = mcp_client.py_get_definition(str(path), symbol) if mode == "def" else mcp_client.py_get_signature(str(path), symbol)
|
||||
elif suffix_lower in [".c", ".h", ".cpp", ".hpp", ".cxx", ".cc"]:
|
||||
is_cpp = any(ext in suffix_lower for ext in [".cpp", ".hpp", ".cxx", ".cc"])
|
||||
if mode == "def":
|
||||
res = mcp_client.ts_cpp_get_definition(str(path), symbol) if is_cpp else mcp_client.ts_c_get_definition(str(path), symbol)
|
||||
else:
|
||||
res = mcp_client.ts_cpp_get_signature(str(path), symbol) if is_cpp else mcp_client.ts_c_get_signature(str(path), symbol)
|
||||
if res: mask_sections.append(res)
|
||||
if mask_sections:
|
||||
content = "\n\n".join(mask_sections)
|
||||
else:
|
||||
content = "(no masked sections visible)"
|
||||
else:
|
||||
content = "(no ast mask defined)"
|
||||
elif view_mode == "none":
|
||||
content = "(context excluded)"
|
||||
elif view_mode == "custom":
|
||||
if custom_slices:
|
||||
lines = content.splitlines()
|
||||
slices_text = []
|
||||
for s in custom_slices:
|
||||
start = s.get("start_line", 1)
|
||||
end = s.get("end_line", len(lines))
|
||||
tag = s.get("tag", "unnamed")
|
||||
comment = s.get("comment", "")
|
||||
s_idx = max(0, start - 1)
|
||||
e_idx = min(len(lines), end)
|
||||
chunk = "\n".join(lines[s_idx:e_idx])
|
||||
slices_text.append(f"---\n[Slice: {tag}] ({comment})\nLines {start}-{end}:\n{chunk}")
|
||||
content = "\n\n".join(slices_text)
|
||||
else:
|
||||
content = summarize.summarise_file(path, content)
|
||||
except Exception as e:
|
||||
import traceback
|
||||
content = f"ERROR in {view_mode} view mode for {path}:\n{traceback.format_exc()}"
|
||||
error = True
|
||||
except FileNotFoundError:
|
||||
content = f"ERROR: file not found: {path}"
|
||||
mtime = 0.0
|
||||
error = True
|
||||
except Exception as e:
|
||||
content = f"ERROR: {e}"
|
||||
import traceback
|
||||
content = f"ERROR reading {path}:\n{traceback.format_exc()}"
|
||||
mtime = 0.0
|
||||
error = True
|
||||
items.append({"path": path, "entry": entry, "content": content, "error": error, "mtime": mtime, "tier": tier, "auto_aggregate": auto_aggregate, "force_full": force_full, "view_mode": view_mode, "ast_signatures": ast_signatures, "ast_definitions": ast_definitions, "ast_mask": ast_mask, "custom_slices": custom_slices})
|
||||
|
||||
Reference in New Issue
Block a user