From 5e84736672f1094ab0bab69a43a4eef676eaf9d5 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 29 Sep 2026 11:47:23 +0200 Subject: [PATCH] Keep formats.py to Claude Code's shapes, with paths and file reads at their callers --- bin/loop_claude/claude_code/formats.py | 29 ++++---------------------- bin/loop_claude/claude_code/session.py | 10 +++++---- bin/loop_claude/paths.py | 9 +++----- bin/loop_claude/project/models.py | 11 +++++++++- todo.md | 1 - 5 files changed, 23 insertions(+), 37 deletions(-) diff --git a/bin/loop_claude/claude_code/formats.py b/bin/loop_claude/claude_code/formats.py index 50138367..a1417da7 100644 --- a/bin/loop_claude/claude_code/formats.py +++ b/bin/loop_claude/claude_code/formats.py @@ -1,26 +1,9 @@ -"""Every Claude Code format loop-claude reads, each under a sample of it, as Claude Code 2.1.284 writes it.""" -import glob +"""Every Claude Code shape loop-claude reads, each under a sample of it, as Claude Code 2.1.284 writes it.""" import json -import os from loop_claude.outcome import Failure -def locations(home): - return home / ".claude.json", home / ".claude" / "cache" / "model-catalog", home / ".claude" / "projects" - - -# /-home-me-code-log/.jsonl -def transcript_path(claude_code_transcripts, session_id): - hit = glob.glob(os.path.join(glob.escape(str(claude_code_transcripts)), "*", f"{session_id}.jsonl")) - return hit[0] if hit else "" - - -# .jsonl, /subagents/, and from older versions .superseded-1789290815002/ and .orphaned-*.jsonl -def session_files(transcript): - return glob.glob(glob.escape(transcript.removesuffix(".jsonl")) + "*") - - def parse(raw): try: entry = json.loads(raw) @@ -114,14 +97,10 @@ def mark_trusted(config, roots): # /*.json: {"fetchedAt": 1790618085238, "catalog": {"config": {"models": [{"id": "claude-opus-5-5", "name": "Opus 5.5", ...}]}}} -def catalog(folder): +def catalog(files): + """The (id, name) of each model in the newest of the parsed catalog files.""" newest = {} - for path in folder.glob("*.json"): - try: - with open(path, encoding="utf-8") as handle: - data = json.load(handle) - except (OSError, ValueError): - continue + for data in files: if isinstance(data, dict) and isinstance(data.get("fetchedAt"), (int, float)) and data["fetchedAt"] > newest.get("fetchedAt", -1): newest = data models = newest diff --git a/bin/loop_claude/claude_code/session.py b/bin/loop_claude/claude_code/session.py index 2ffe5d8b..659267f6 100644 --- a/bin/loop_claude/claude_code/session.py +++ b/bin/loop_claude/claude_code/session.py @@ -1,12 +1,11 @@ import dataclasses +import glob import os import pathlib import shutil import sys import uuid -from loop_claude.claude_code.formats import session_files, transcript_path - NAMESPACE = uuid.UUID("64fb586b-d926-4bb3-a44c-c903e86d3eec") @@ -24,15 +23,18 @@ def session_for(project, paths): return Session(id=uuid.uuid5(NAMESPACE, name), claude_code_transcripts=paths.claude_code_transcripts, name=name) +# /-home-me-code-log/.jsonl def transcript_file(session): - return transcript_path(session.claude_code_transcripts, session.id) + hit = glob.glob(os.path.join(glob.escape(str(session.claude_code_transcripts)), "*", f"{session.id}.jsonl")) + return hit[0] if hit else "" def delete_session(session): path = transcript_file(session) if not path: return - for sibling in session_files(path): + # .jsonl, /subagents/, and from older versions .superseded-1789290815002/ and .orphaned-*.jsonl + for sibling in glob.glob(glob.escape(path.removesuffix(".jsonl")) + "*"): try: shutil.rmtree(sibling) if os.path.isdir(sibling) else os.remove(sibling) except OSError as failure: diff --git a/bin/loop_claude/paths.py b/bin/loop_claude/paths.py index 6f670603..e93065b8 100644 --- a/bin/loop_claude/paths.py +++ b/bin/loop_claude/paths.py @@ -1,8 +1,6 @@ import dataclasses import pathlib -from loop_claude.claude_code.formats import locations - @dataclasses.dataclass(frozen=True) class Paths: @@ -16,12 +14,11 @@ class Paths: def paths_from(home, env): claude = home / ".claude" - claude_json, model_catalog, claude_code_transcripts = locations(home) return Paths( archive=pathlib.Path(env["LOOP_CLAUDE_TRANSCRIPTS"]).expanduser() if env.get("LOOP_CLAUDE_TRANSCRIPTS") else claude / "loop-claude-transcripts", - claude_code_transcripts=claude_code_transcripts, - claude_json=claude_json, + claude_code_transcripts=claude / "projects", + claude_json=home / ".claude.json", code=home / "code", - model_catalog=model_catalog, + model_catalog=claude / "cache" / "model-catalog", models_file=claude / "loop-claude-models.json", ) diff --git a/bin/loop_claude/project/models.py b/bin/loop_claude/project/models.py index 127c0392..0225210e 100644 --- a/bin/loop_claude/project/models.py +++ b/bin/loop_claude/project/models.py @@ -57,10 +57,19 @@ def read_models(saved): return models +def read_catalog(folder): + for path in folder.glob("*.json"): + try: + with open(path, encoding="utf-8") as handle: + yield json.load(handle) + except (OSError, ValueError): + continue + + def ask_model(name, saved, folder): if stop := human_needed.off_terminal(f"pick {name}'s model, or merge {{\"{name}\": \"\"}} into {saved}"): return stop - offered = catalog(folder) + offered = catalog(read_catalog(folder)) 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) diff --git a/todo.md b/todo.md index 2087f0a2..df4c920f 100644 --- a/todo.md +++ b/todo.md @@ -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 2f9ab2f named (`docs/decisions.md`), capping dimension first: -- **Keep `formats.py` to Claude Code's shapes: `locations` into `paths.py`, `catalog`'s file reads out.** Three seats found paths and I/O in a file named for formats. - **Group `bin/loop_claude/`'s top-level modules, and name `claude_runs` apart from `claude_code`.** Two seats: eleven modules of mixed altitude side by side. - **Say at `written_by_human` why a `<` prefix marks Claude Code's own entry, and at `trust` why a failure only warns.** Three seats found either only in `CHANGELOG.md`. - **Say in the README why the tests run on the host and need `uv`.** Two seats: `CLAUDE.md` says never run a runtime on the host, and only `test_python_floor.py` says what `uv` is for.