Files
sisi/sisi/trust.py
T
swaitsandClaude Fable 5.2 2fc1fe9c2d
ci / tests (macos-latest, python 3.11) (push) Canceled after 0s
ci / tests (macos-latest, python 3.13) (push) Canceled after 0s
ci / tests (macos-latest, python 3.9) (push) Canceled after 0s
ci / tests (ubuntu-latest, python 3.11) (push) Canceled after 0s
ci / tests (ubuntu-latest, python 3.13) (push) Canceled after 0s
ci / tests (ubuntu-latest, python 3.9) (push) Canceled after 0s
sisi 0.1.0: a shared rulebook and verification tool for AI coding agents
Contracts with a ladder of checks, an end-of-turn gate, retrospectives and
shared lessons, time-to-delivery measurement, a library of 140 verification
techniques and 20 recipes, personal data kept outside the clone, and
releases with rollback. Standard library only.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 22:29:02 -07:00

47 lines
1.1 KiB
Python

"""Trusted project roots. A contract runs shell commands, so only contracts in trusted roots are executed."""
import json, os
from . import paths
def _file():
return paths.personal("trusted.json")
def norm(p):
return os.path.realpath(p)
def load():
try:
with open(_file(), encoding="utf-8") as f:
d = json.load(f)
return [x for x in d if isinstance(x, str)] if isinstance(d, list) else []
except (OSError, ValueError):
return []
def _save(items):
os.makedirs(os.path.dirname(_file()), exist_ok=True)
tmp = _file() + ".tmp%d" % os.getpid()
with open(tmp, "w", encoding="utf-8") as f:
json.dump(sorted(set(items)), f, indent=1)
os.replace(tmp, _file())
def is_trusted(project):
return norm(project) in load()
def add(project):
_save(load() + [norm(project)])
def remove(project):
_save([x for x in load() if x != norm(project)])
def hint(project):
return "the contract in %s is untrusted (its commands have not been approved on this machine). " \
"Read .sisi/contract.json, then run `sisi contract trust` in that project to allow it." % project