"""Touched-paths handoff between post-tool-use-write and session-end (deep module).

Encapsulates the /tmp/claude-vault-touched-<session_id> temp-file contract. The
file still exists by necessity — the two hooks are separate process invocations
with no shared memory; the win is an explicit, named, testable contract.
One path per line. Fail-open throughout.
"""
from __future__ import annotations

import os


def _touch_file(session_id: str) -> str:
    return f"/tmp/claude-vault-touched-{session_id}"


def record_touch(session_id: str, path: str) -> None:
    try:
        with open(_touch_file(session_id), "a") as f:
            f.write(path + "\n")
    except Exception:
        pass


def read_touches(session_id: str) -> list:
    try:
        with open(_touch_file(session_id)) as f:
            content = f.read()
    except Exception:
        return []
    return [line for line in content.splitlines() if line]


def clear_touches(session_id: str) -> None:
    try:
        os.remove(_touch_file(session_id))
    except Exception:
        pass
