Return the updated ~/.claude.json from mark_trusted #121
@@ -122,20 +122,15 @@ def structured_output(stdout):
|
||||
|
||||
|
||||
# ~/.claude.json: {"projects": {"/home/me/code/log": {"hasTrustDialogAccepted": true, ...}}, ...}
|
||||
def trust_records(config):
|
||||
projects = config.setdefault("projects", {}) if isinstance(config, dict) else None
|
||||
def mark_trusted(config, roots):
|
||||
projects = config.get("projects", {}) if isinstance(config, dict) else None
|
||||
if not isinstance(projects, dict):
|
||||
return Failure('not an object whose "projects" is an object')
|
||||
if (wrong := next((path for path, record in projects.items() if not isinstance(record, dict)), None)) is not None:
|
||||
return Failure(f"projects[{json.dumps(wrong)}] is not an object")
|
||||
return projects
|
||||
|
||||
|
||||
def mark_trusted(projects, roots):
|
||||
untrusted = [path for path in roots if not projects.get(path, {}).get("hasTrustDialogAccepted")]
|
||||
for path in untrusted:
|
||||
projects.setdefault(path, {})["hasTrustDialogAccepted"] = True
|
||||
return untrusted
|
||||
marked = {path: {**projects.get(path, {}), "hasTrustDialogAccepted": True} for path in untrusted}
|
||||
return {**config, "projects": {**projects, **marked}}, untrusted
|
||||
|
||||
|
||||
# <model catalog>/*.json: {"fetchedAt": 1790618085238, "catalog": {"config": {"models": [{"id": "claude-opus-5-5", "name": "Opus 5.5", ...}]}}}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import json
|
||||
import sys
|
||||
|
||||
from loop_claude.claude_code.formats import mark_trusted, trust_records
|
||||
from loop_claude.claude_code.formats import mark_trusted
|
||||
from loop_claude.file_writes import replace_json
|
||||
from loop_claude.outcome import Failure
|
||||
|
||||
@@ -13,14 +13,14 @@ def trust(config, roots):
|
||||
except (OSError, ValueError) as failure:
|
||||
print(f"could not read {config}: {getattr(failure, 'strerror', failure)}", file=sys.stderr)
|
||||
return
|
||||
projects = trust_records(data)
|
||||
if isinstance(projects, Failure):
|
||||
print(f"could not read {config}: {projects.reason}", file=sys.stderr)
|
||||
marked = mark_trusted(data, roots)
|
||||
if isinstance(marked, Failure):
|
||||
print(f"could not read {config}: {marked.reason}", file=sys.stderr)
|
||||
return
|
||||
untrusted = mark_trusted(projects, roots)
|
||||
updated, untrusted = marked
|
||||
if not untrusted:
|
||||
return
|
||||
if failure := replace_json(config, data, indent=2):
|
||||
if failure := replace_json(config, updated, indent=2):
|
||||
print(f"could not write {config}: {failure.reason}", file=sys.stderr)
|
||||
return
|
||||
print("trusted for the interrupt: " + ", ".join(untrusted), file=sys.stderr)
|
||||
|
||||
@@ -85,6 +85,15 @@ class Parse(unittest.TestCase):
|
||||
self.assertIsNone(formats.parse("[1, 2]"))
|
||||
|
||||
|
||||
class MarkTrusted(unittest.TestCase):
|
||||
def test_returns_the_updated_config_and_leaves_the_one_it_was_handed(self):
|
||||
config = {"other": 1, "projects": {"/a": {"hasTrustDialogAccepted": True}, "/b": {"kept": True}}}
|
||||
handed = json.dumps(config)
|
||||
self.assertEqual(formats.mark_trusted(config, ["/a", "/b", "/c"]), ({"other": 1, "projects": {"/a": {"hasTrustDialogAccepted": True}, "/b": {"hasTrustDialogAccepted": True, "kept": True}, "/c": {"hasTrustDialogAccepted": True}}}, ["/b", "/c"]))
|
||||
self.assertEqual(json.dumps(config), handed)
|
||||
self.assertEqual(formats.mark_trusted({}, ["/a"]), ({"projects": {"/a": {"hasTrustDialogAccepted": True}}}, ["/a"]))
|
||||
|
||||
|
||||
class Grounded(unittest.TestCase):
|
||||
def test_every_verdict_must_quote_the_transcript(self):
|
||||
def verdict(evidence):
|
||||
|
||||
@@ -8,7 +8,6 @@ The rebuild lifts every dimension, one chunk per item, until the last item opens
|
||||
|
||||
The places the panel on `rebuild` at 7f9de5c named (`docs/decisions.md`), capping dimension first:
|
||||
|
||||
- **Make `mark_trusted` return the updated `~/.claude.json`, so `trust` writes what it was handed and `formats.py` mutates nothing.** Three seats: `trust_records` `setdefault`s into the config and `trust` writes `data` changed through an alias.
|
||||
- **Make `decode_state` check the fields' types without relying on the annotations being runtime types.** Two seats: `from __future__ import annotations` in `main.py` would fail every reload.
|
||||
- **State once, in `outcome.py`, that a `Failure` is retried and a `Stop` exits.** Three seats inferred it from `run_loop`.
|
||||
- **Define a round once, in larv-review's "Round cap", and link it from `review-findings.md` → "Rounds", the Vocabulary and the auto-reviewer's step.** All four seats held §3, "Rounds" and the Vocabulary open together to settle whether a launch counts.
|
||||
|
||||
Reference in New Issue
Block a user