Echo the saved model, skip the ask when both overrides are set, and say when no catalog is cached
This commit is contained in:
+1
-1
@@ -11,6 +11,6 @@
|
||||
- `loop-claude` says why when it cannot read `~/.claude.json` before an interrupt, and the interrupt then lands in Claude Code's trust dialog.
|
||||
- `loop-claude` takes an edit to itself at the next cycle boundary once the edited file answers `--help`, and exits 1 when the edited file cannot read the running loop's state.
|
||||
- `loop-claude --help` names the Claude Code version its transcript, session and trust handling were observed on; check it first when an upgrade breaks a cycle.
|
||||
- `loop-claude` runs every claude it starts, the interrupt included, on the project's model, saved in `~/.claude/loop-claude-models.json` and asked for from Claude Code's model catalog on a project's first run; `LOOP_CLAUDE_WORKER_MODEL` and `LOOP_CLAUDE_JUDGE_MODEL` override it.
|
||||
- `loop-claude` runs every claude it starts, the interrupt included, on the project's model, saved in `~/.claude/loop-claude-models.json`. A project without an entry is asked for one on the terminal, from Claude Code's model catalog, and exits 2 without a terminal; delete the entry to pick again. `LOOP_CLAUDE_WORKER_MODEL` and `LOOP_CLAUDE_JUDGE_MODEL` override it.
|
||||
- `settings.json`, the agents and the status line run on any machine unedited; the status line shows reset times in the machine's own time zone.
|
||||
- `loop-claude`'s no-premises exit names what is wrong: `README.md` unopenable or not UTF-8, a `## Goals` or `## Audience` heading missing or repeated, or nothing under one.
|
||||
|
||||
+11
-5
@@ -23,8 +23,9 @@ $LOOP_CLAUDE_TRANSCRIPTS/<path>/ (default ~/.claude/loop-claude-transcripts) whe
|
||||
asked and when the chunk finishes.
|
||||
|
||||
Every claude it starts runs the project's model, saved per <path> in ~/.claude/loop-claude-models.json
|
||||
and read each cycle; the first run in a project asks for it. LOOP_CLAUDE_JUDGE_MODEL and
|
||||
LOOP_CLAUDE_WORKER_MODEL override it. A change to this file takes effect at the next cycle boundary,
|
||||
and read each cycle; a project without an entry, as on its first run, is asked for one.
|
||||
LOOP_CLAUDE_JUDGE_MODEL overrides it for the judge, LOOP_CLAUDE_WORKER_MODEL for the worker and the
|
||||
interrupt; with both set, nothing is asked. A change to this file takes effect at the next cycle boundary,
|
||||
once the new file answers --help.
|
||||
|
||||
Claude Code internals this rests on, observed on 2.1.282, the model catalog on 2.1.283:
|
||||
@@ -237,6 +238,8 @@ def project(root):
|
||||
|
||||
|
||||
def project_model(root):
|
||||
if os.environ.get("LOOP_CLAUDE_JUDGE_MODEL") and os.environ.get("LOOP_CLAUDE_WORKER_MODEL"):
|
||||
return ""
|
||||
saved = os.path.expanduser("~/.claude/loop-claude-models.json")
|
||||
name = project(root)
|
||||
if chosen := read_models(saved).get(name):
|
||||
@@ -253,6 +256,7 @@ def project_model(root):
|
||||
if os.path.exists(staged):
|
||||
os.remove(staged)
|
||||
sys.exit(f"could not save the model in {saved}: {failure.strerror}")
|
||||
print(f"{name} runs on {chosen}", file=sys.stderr)
|
||||
return chosen
|
||||
|
||||
|
||||
@@ -271,21 +275,23 @@ def read_models(saved):
|
||||
|
||||
def ask_model(name, saved):
|
||||
if not (sys.stdin.isatty() and sys.stdout.isatty()):
|
||||
print(f"{name} has no model in {saved} to run, and stdin or stdout is not a terminal to ask on", file=sys.stderr)
|
||||
print(f"{name} has no model in {saved}, and stdin or stdout is not a terminal to ask on; run it on a terminal or add \"{name}\": \"<model>\" to {saved}", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
offered = catalog()
|
||||
print(f"\nThe model to run {name} on, saved in {saved}:", file=sys.stderr)
|
||||
for number, (model_id, label) in enumerate(offered, 1):
|
||||
print(f" {number}. {label} ({model_id})", file=sys.stderr)
|
||||
if not offered:
|
||||
print(" no model catalog cached; running claude once fills it", file=sys.stderr)
|
||||
while True:
|
||||
try:
|
||||
answer = input("A number, or any name claude --model takes: ").strip()
|
||||
answer = input(f"{'A number, or any' if offered else 'A'} name claude --model takes: ").strip()
|
||||
except EOFError:
|
||||
print("\nno model picked", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
if not answer:
|
||||
continue
|
||||
if not answer.isdecimal():
|
||||
if not (offered and answer.isdecimal()):
|
||||
return answer
|
||||
if 1 <= int(answer) <= len(offered):
|
||||
return offered[int(answer) - 1][0]
|
||||
|
||||
+15
-1
@@ -148,6 +148,8 @@ class WorkerArgs(unittest.TestCase):
|
||||
class ProjectModel(unittest.TestCase):
|
||||
def test_asks_once_per_project_from_the_newest_catalog_and_saves_the_answer(self):
|
||||
with tempfile.TemporaryDirectory() as home, unittest.mock.patch.dict(os.environ, {"HOME": home}), unittest.mock.patch.object(sys, "stderr", io.StringIO()):
|
||||
for variable in ("LOOP_CLAUDE_JUDGE_MODEL", "LOOP_CLAUDE_WORKER_MODEL"):
|
||||
os.environ.pop(variable, None)
|
||||
saved = pathlib.Path(home, ".claude", "loop-claude-models.json")
|
||||
catalog = pathlib.Path(home, ".claude", "cache", "model-catalog")
|
||||
catalog.mkdir(parents=True)
|
||||
@@ -156,7 +158,10 @@ class ProjectModel(unittest.TestCase):
|
||||
with unittest.mock.patch("sys.stdin.isatty", return_value=False), self.assertRaises(SystemExit) as stopped:
|
||||
loop.project_model("/srv/a")
|
||||
self.assertEqual(stopped.exception.code, 2)
|
||||
self.assertIn(f'add "srv/a": "<model>" to {saved}', sys.stderr.getvalue())
|
||||
self.assertFalse(saved.exists())
|
||||
with unittest.mock.patch.dict(os.environ, {"LOOP_CLAUDE_JUDGE_MODEL": "j", "LOOP_CLAUDE_WORKER_MODEL": "w"}), unittest.mock.patch("sys.stdin.isatty", return_value=False):
|
||||
self.assertEqual(loop.project_model("/srv/a"), "")
|
||||
with (
|
||||
unittest.mock.patch("sys.stdin.isatty", return_value=True),
|
||||
unittest.mock.patch("sys.stdout.isatty", return_value=True),
|
||||
@@ -166,6 +171,7 @@ class ProjectModel(unittest.TestCase):
|
||||
self.assertEqual(typed.call_count, 3)
|
||||
self.assertIn("2. CLAUDE-SONNET-5 (claude-sonnet-5)", sys.stderr.getvalue())
|
||||
self.assertIn("pick 1 to 2", sys.stderr.getvalue())
|
||||
self.assertIn("srv/a runs on claude-sonnet-5", sys.stderr.getvalue())
|
||||
self.assertNotIn("claude-opus-5)", sys.stderr.getvalue())
|
||||
def saved_elsewhere_while_asking(prompt):
|
||||
saved.write_text(json.dumps({**json.loads(saved.read_text()), "srv/d": "haiku"}))
|
||||
@@ -184,10 +190,18 @@ class ProjectModel(unittest.TestCase):
|
||||
self.assertEqual(stopped.exception.code, f"could not save the model in {saved}: Permission denied")
|
||||
self.assertEqual(json.loads(saved.read_text()), {"srv/a": "claude-sonnet-5", "srv/b": "opus[1m]", "srv/d": "haiku"})
|
||||
self.assertEqual(sorted(os.listdir(saved.parent)), ["cache", "loop-claude-models.json"])
|
||||
for shape in ({"fetchedAt": 3, "catalog": None}, {"fetchedAt": 3, "catalog": {"config": []}}, {"fetchedAt": 3, "catalog": {"config": {"models": "x"}}}):
|
||||
for shape in ({"fetchedAt": 3, "catalog": {"config": {"models": []}}}, {"fetchedAt": 3, "catalog": None}, {"fetchedAt": 3, "catalog": {"config": []}}, {"fetchedAt": 3, "catalog": {"config": {"models": "x"}}}):
|
||||
catalog.joinpath("new.json").write_text(json.dumps(shape))
|
||||
with self.subTest(shape=shape):
|
||||
self.assertEqual(loop.catalog(), [])
|
||||
with (
|
||||
unittest.mock.patch("sys.stdin.isatty", return_value=True),
|
||||
unittest.mock.patch("sys.stdout.isatty", return_value=True),
|
||||
unittest.mock.patch("builtins.input", side_effect=["1"]) as typed,
|
||||
):
|
||||
self.assertEqual(loop.project_model("/srv/e"), "1")
|
||||
self.assertEqual(typed.call_args.args[0], "A name claude --model takes: ")
|
||||
self.assertIn("no model catalog cached", sys.stderr.getvalue())
|
||||
for broken in ("{", "[]", '{"srv/a": 1}'):
|
||||
saved.write_text(broken)
|
||||
with self.subTest(broken=broken), self.assertRaises(SystemExit) as stopped:
|
||||
|
||||
+1
-1
@@ -46,4 +46,4 @@
|
||||
|
||||
## loop-claude: each project's model lives in loop-claude's own file
|
||||
|
||||
2026-09-26, lilleman. Serves goal 4. Claude Code rewrites the user settings' `model` whenever one is picked inside a session, so a loop reading settings runs whatever was picked last; `~/.claude/loop-claude-models.json` has loop-claude as its one writer, and every claude it starts gets that model as `--model`. Valid while Claude Code keeps rewriting the settings' model from inside a session.
|
||||
2026-09-26, lilleman. Serves goal 4. Claude Code rewrites the user settings' `model` whenever one is picked inside a session, so a loop reading settings runs whatever was picked last; `~/.claude/loop-claude-models.json` has loop-claude as its one writer, and every claude it starts gets that model as `--model`. The file is per machine, outside the synced allowlist, since a tracked file the loop writes would dirty the checkout. Valid while Claude Code keeps rewriting the settings' model from inside a session.
|
||||
|
||||
Reference in New Issue
Block a user