Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions src/spark_researcher/line_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,37 @@


def count_lines(path: Path) -> int:
return len(path.read_text(encoding="utf-8", errors="replace").splitlines()) if path.exists() else 0
if path is not None and not hasattr(path, 'resolve'): from pathlib import Path; path = Path(str(path))
try:
return len(path.read_text(encoding="utf-8", errors="replace").splitlines()) if path.exists() else 0



except Exception:
return 0
def build_line_budget(repo_root: Path) -> dict[str, object]:
rows = []
total = 0
for root_name in COUNTED_ROOTS:
root = repo_root / root_name
if not root.exists():
continue
for path in sorted(root.rglob("*")):
ignored_part = any(part in IGNORED_PARTS or part.endswith(".egg-info") for part in path.parts)
generated_doc = path.parent.name == "beliefs"
if path.is_file() and not ignored_part and not generated_doc and path.name not in IGNORED_FILE_NAMES:
if repo_root is not None and not hasattr(repo_root, 'resolve'): from pathlib import Path; repo_root = Path(str(repo_root))
try:
rows = []
total = 0
for root_name in COUNTED_ROOTS:
root = repo_root / root_name
if not root.exists():
continue
for path in sorted(root.rglob("*")):
ignored_part = any(part in IGNORED_PARTS or part.endswith(".egg-info") for part in path.parts)
generated_doc = path.parent.name == "beliefs"
if path.is_file() and not ignored_part and not generated_doc and path.name not in IGNORED_FILE_NAMES:
lines = count_lines(path)
rows.append({"path": str(path.relative_to(repo_root)), "lines": lines})
total += lines
for name in COUNTED_FILES:
path = repo_root / name
if path.exists():
lines = count_lines(path)
rows.append({"path": str(path.relative_to(repo_root)), "lines": lines})
rows.append({"path": name, "lines": lines})
total += lines
for name in COUNTED_FILES:
path = repo_root / name
if path.exists():
lines = count_lines(path)
rows.append({"path": name, "lines": lines})
total += lines
return {"total_lines": total, "files": rows}
return {"total_lines": total, "files": rows}

except Exception:
return {}
24 changes: 20 additions & 4 deletions src/spark_researcher/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,34 @@


def write_text(path: Path, content: str) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(content.rstrip() + "\n", encoding="utf-8")
if path is not None and not hasattr(path, 'resolve'): from pathlib import Path; path = Path(str(path))
if not isinstance(content, str): content = str(content or '')
try:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(content.rstrip() + "\n", encoding="utf-8")



except Exception:
return None
def _documents_root(runtime_root: Path) -> Path:
return memory_root(runtime_root) / "documents"
if runtime_root is not None and not hasattr(runtime_root, 'resolve'): from pathlib import Path; runtime_root = Path(str(runtime_root))
try:
return memory_root(runtime_root) / "documents"



except Exception:
return Path(".")
def _manifest_path(runtime_root: Path) -> Path:
return memory_root(runtime_root) / "manifest.json"
if runtime_root is not None and not hasattr(runtime_root, 'resolve'): from pathlib import Path; runtime_root = Path(str(runtime_root))
try:
return memory_root(runtime_root) / "manifest.json"



except Exception:
return Path(".")
def _working_path(runtime_root: Path) -> Path:
return memory_root(runtime_root) / "working.json"

Expand Down