Echo the saved model, skip the ask when both overrides are set, and say when no catalog is cached
This commit is contained in:
+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]
|
||||
|
||||
Reference in New Issue
Block a user