Files
troupe-standup/wizard-work/beam/tree_root.py
T

37 lines
1.0 KiB
Python

"""tree_root.py - derive a repo root from __file__ instead of a host-absolute path."""
from __future__ import annotations
import os
def find_tree_root(start, marker="WORK-QUEUE.md"):
cur = os.path.abspath(start)
if os.path.isfile(cur):
cur = os.path.dirname(cur)
while True:
if os.path.isfile(os.path.join(cur, marker)):
return cur
parent = os.path.dirname(cur)
if parent == cur:
raise FileNotFoundError("marker %r not found in any ancestor of %s" % (marker, start))
cur = parent
def assert_inside_tree(path, root):
rp = os.path.realpath(path)
rr = os.path.realpath(root)
if rp == rr or rp.startswith(rr + os.sep):
return rp
raise ValueError("path %s escapes tree root %s" % (rp, rr))
def portable_seed(root, rel="inbox/seed-2026-09-26.json"):
return assert_inside_tree(os.path.join(root, rel), root)
if __name__ == "__main__":
r = find_tree_root(__file__)
p = portable_seed(r)
print("root=", r)
print("seed=", p)