28 lines
958 B
Python
28 lines
958 B
Python
import json
|
|
import sys
|
|
|
|
from loop_claude.claude_code.formats import mark_trusted
|
|
from loop_claude.file_writes import replace_json
|
|
from loop_claude.outcome import Failure
|
|
|
|
|
|
# A failure only warns: the interrupt still runs, and the human answers Claude Code's trust dialog.
|
|
def trust(config, roots) -> None:
|
|
try:
|
|
with open(config, encoding="utf-8") as handle:
|
|
data = json.load(handle)
|
|
except (OSError, ValueError) as failure:
|
|
print(f"could not read {config}: {getattr(failure, 'strerror', failure)}", file=sys.stderr)
|
|
return
|
|
marked = mark_trusted(data, roots)
|
|
if isinstance(marked, Failure):
|
|
print(f"could not read {config}: {marked.reason}", file=sys.stderr)
|
|
return
|
|
updated, untrusted = marked
|
|
if not untrusted:
|
|
return
|
|
if unwritten := replace_json(config, updated, indent=2):
|
|
print(f"could not write {config}: {unwritten.reason}", file=sys.stderr)
|
|
return
|
|
print("trusted for the interrupt: " + ", ".join(untrusted), file=sys.stderr)
|