Deduplicate session environment exports
ci / test (push) Canceled after 0s

Append each session export once under the file lock, refusing links and unsafe files. Keep the product at 1948 lines.
This commit is contained in:
swaits committed 2026-11-25 11:46:13 -07:00
1 parent 712cc75c12
commit 8fe62f6ad9
3 files changed
+36 -8

No files matched your search

+1 -1
View File
@@ -119,7 +119,7 @@ def tick(p):
worker, free = worker or bool(s.get("worker")), s.get("free_bytes")
env = os.environ.get("CLAUDE_ENV_FILE")
if env and re.fullmatch(r"[A-Za-z0-9_-]+", str(sid)):
store.append(env, "export SISI_SESSION_ID=%s" % sid) # so `sisi retro` knows its session
store.append(env, "export SISI_SESSION_ID=%s" % sid, once=True) # so `sisi retro` knows its session
if not os.path.exists(os.path.join(store.DATA, "generated", "core.md")):
rules.build_rulebook()
text = "\n".join(x for x in (rules.project_text(cwd), rules.due(cwd, claim=True), models.stale(), "" if worker else _faults(cwd, False, free)) if x)
+7 -7
View File
@@ -17,7 +17,6 @@ def _where(own, xdg, fallback):
base = os.environ.get(xdg)
return os.environ.get(own) or (os.path.join(base, "sisi") if base else os.path.join(HOME, *fallback, "sisi"))
DATA = _where("SISI_DATA", "XDG_DATA_HOME", (".local", "share"))
STATE = _where("SISI_STATE", "XDG_STATE_HOME", (".local", "state"))
LIB = os.environ.get("SISI_LIB") or os.path.join(HOME, ".local", "lib", "sisi")
@@ -27,7 +26,6 @@ DEFAULTS = {"gate": True, "meter": True, "direct_calls": 8, "direct_extension":
"rules_lines": 30, "rules_chars": 4000, "organize_after": 8, "research_days": 7, "shell_workers": False,
"worker_minutes": 15, "retro_minutes": 5, "disk_free_percent": 20, "disk_drop_percent": 5, "checkouts": 8}
def config():
cfg = dict(DEFAULTS)
try:
@@ -79,11 +77,13 @@ def write(path, text):
raise
def append(path, line):
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "a", encoding="utf-8") as f:
fcntl.flock(f, fcntl.LOCK_EX)
f.write(line.rstrip("\n") + "\n")
def append(path, line, once=False):
line = line.rstrip("\n").encode() + b"\n"
with contextlib.suppress(OSError) if once else contextlib.nullcontext():
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "a+b", opener=lambda p, f: os.open(p, f | os.O_NOFOLLOW)) as f:
fcntl.flock(f, fcntl.LOCK_EX); f.seek(0); raw = f.read(64001)
(not once or len(raw) <= 64000 and b"\0" not in raw and line[:-1] not in raw.splitlines()) and f.write(line)
def git(args, cwd, timeout=15):