#!/usr/bin/env python3 r"""Filesystem-safety and input-validation guard. One script, six check types. Emits a STATUS=INVALID_INPUT RESULT block on failure + tees to $ERROR_TEE on disk + exits 1. Guiding principle: the agent MUST suffix every call with `|| exit 1` — Python `sys.exit(1)` only terminates this subprocess, not the parent bash. A bare call without `|| exit 1` silently continues past a failed guard, which is the worst possible failure mode for a security check. Check types: symlink — path must NOT be a symlink (rejects pre-planted attacker bait) owned — path must be owned by current UID (rejects foreign-owned dirs) uuid — value must match ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ org_id_15 — value must match ^[A-Za-z0-9]{15}$ (Salesforce org ID slice) api_name — value must match ^[A-Za-z0-9_]+$ (Salesforce API identifier) api_version — value must match ^v[0-9]+\.[0-9]+$ (e.g. v60.0) agent_version — value must match ^v[0-9]+$ (e.g. v5 — Agentforce agent version, no dot-minor) not_empty — value must be non-empty string Python-importable API: validate_api_name(value, label="...") — raises ValidationError on bad input validate_api_version(value, label="...") — raises ValidationError on bad input validate_agent_version(value, label="...") — raises ValidationError on bad input validate_org_id_15(value, label="...") — raises ValidationError on bad input ValidationError — carries (label, reason) The Python API is used by in-process callers (SOQL loader, path builders in config.py) that need a raise-based boundary rather than the process-exit CLI behavior. Regex is shared — do NOT duplicate API_NAME_RE / API_VERSION_RE. Usage: python3 fs_guard.py