Skip to content

Commit 67047b3

Browse files
committed
feat: add environment variable expansion for pages_file path
1 parent a418f61 commit 67047b3

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/orchestration/strategies/doc_review.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,19 +215,30 @@ async def _review_then_validate(
215215
def _load_pages_file(p: Path, repo_path: Path) -> List[Dict[str, Any]]:
216216
"""Load pages from YAML or JSON file.
217217
218+
Expands '~' and environment variables in the pages_file path. If the path is
219+
relative and the file exists under the repository root, that location is used.
220+
218221
Returns a list of dicts with at least {title, path}. Relative paths are
219-
normalized relative to the repo root.
222+
expected to be repo-relative.
220223
"""
224+
# Resolve user/env expansions and prefer repo-relative when applicable
221225
try:
222-
raw = p.read_text(encoding="utf-8")
226+
import os
227+
228+
p_expanded = Path(os.path.expanduser(os.path.expandvars(str(p))))
229+
if not p_expanded.is_absolute():
230+
candidate = (repo_path / p_expanded).resolve()
231+
if candidate.exists():
232+
p_expanded = candidate
233+
raw = p_expanded.read_text(encoding="utf-8")
223234
except Exception as e:
224235
raise ValueError(f"Could not read pages_file: {p}: {e}")
225236

226237
pages: List[Dict[str, Any]] = []
227238
try:
228-
if p.suffix.lower() in (".yaml", ".yml"):
239+
if p_expanded.suffix.lower() in (".yaml", ".yml"):
229240
data = yaml.safe_load(raw)
230-
elif p.suffix.lower() == ".json":
241+
elif p_expanded.suffix.lower() == ".json":
231242
data = json.loads(raw)
232243
else:
233244
# Try YAML first, then JSON

0 commit comments

Comments
 (0)