Move the modules rank_todo.py shares into bin/file_io/, inside reload's fingerprint

This commit is contained in:
2026-10-03 17:52:02 +02:00
parent 848e25a36e
commit 9f75fe8c51
23 changed files with 37 additions and 33 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ import pathlib
import shutil
import uuid
from loop_claude.failure import Failure
from file_io.failure import Failure
from loop_claude.paths import Paths
NAMESPACE = uuid.UUID("64fb586b-d926-4bb3-a44c-c903e86d3eec")
+1 -1
View File
@@ -1,7 +1,7 @@
import json
from loop_claude.claude_code.entries import assistant_parts, human_text, loop_text, parse_entry, part_text, tool_call
from loop_claude.failure import Failure
from file_io.failure import Failure
JUDGED_TOOL_INPUT = 400
+2 -2
View File
@@ -2,8 +2,8 @@ import json
import pathlib
import sys
from loop_claude.failure import Failure
from loop_claude.file_writes import replace_json
from file_io.failure import Failure
from file_io.writes import replace_json
# A failure only warns: the interrupt still runs, and the human answers Claude Code's trust dialog.
+2 -2
View File
@@ -3,9 +3,9 @@ import os
import pathlib
import sys
from loop_claude.failure import Failure
from file_io.failure import Failure
from loop_claude.claude_code.transcript import first_timestamped_line
from loop_claude.file_writes import make_private, replace_file
from file_io.writes import make_private, replace_file
from loop_claude.paths import Paths
from loop_claude.claude_code.session import session_files
+1 -1
View File
@@ -2,7 +2,7 @@ import sys
import uuid
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from file_io.failure import Failure
from loop_claude.claude_code.transcript import human_turns, read_transcript
from loop_claude.stop import needs_human, needs_terminal, Stop
from loop_claude.paths import Paths
+1 -1
View File
@@ -4,7 +4,7 @@ import re
import typing
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from file_io.failure import Failure
from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict
from loop_claude.claude_code.entries import hit_limit, limit_said, parse_entry, structured_output
from loop_claude.cycle.limited import Limited
+1 -1
View File
@@ -2,7 +2,7 @@ import sys
import typing
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from file_io.failure import Failure
from loop_claude.cycle.limited import Limited
from loop_claude.stop import Stop
+1 -1
View File
@@ -5,7 +5,7 @@ from loop_claude.cycle.states import Active, Archived, Closing, Ended, Event, Hu
from loop_claude.cycle.archive import archive
from loop_claude.claude_code.session import delete_session, Session, session_open, transcript_file
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from file_io.failure import Failure
from loop_claude.cycle.verdicts import Finished, QuotedAnswer, Unfinished
from loop_claude.cycle.interrupt import interrupt
from loop_claude.cycle.judge import judge
+1 -1
View File
@@ -1,6 +1,6 @@
from loop_claude.claude_code.entries import assistant_parts, ends_stream, hit_limit, limit_said, parse_entry, rejected_until
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from file_io.failure import Failure
from loop_claude.cycle.limited import Limited
from loop_claude.claude_code.transcript import part_line
from loop_claude.project.records import QUOTE_SOURCES
-7
View File
@@ -1,7 +0,0 @@
import dataclasses
@dataclasses.dataclass(frozen=True)
class Failure:
"""A step failed, and reason says why; its caller decides what follows."""
reason: str
-33
View File
@@ -1,33 +0,0 @@
import json
import os
import pathlib
import typing
from loop_claude.failure import Failure
def make_private(folder: pathlib.Path) -> None:
mask = os.umask(0o077)
try:
os.makedirs(folder, exist_ok=True)
finally:
os.umask(mask)
def replace_json(path: pathlib.Path, data: object, **dump: typing.Any) -> Failure | None:
return replace_file(path, json.dumps(data, **dump).encode())
def replace_file(path: pathlib.Path, data: bytes) -> Failure | None:
staged = f"{path}.{os.getpid()}"
try:
mode = os.stat(path).st_mode & 0o7777 if os.path.exists(path) else 0o600
with open(os.open(staged, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600), "wb") as handle:
os.fchmod(handle.fileno(), mode)
handle.write(data)
os.replace(staged, path)
except OSError as failure:
if os.path.exists(staged):
os.remove(staged)
return Failure(failure.strerror or str(failure))
return None
+2 -2
View File
@@ -33,8 +33,8 @@ Every claude loop-claude starts runs the project's model, saved per <key> in
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 bin/loop-claude or bin/loop_claude/**/*.py takes effect at the next cycle boundary, once
loop-claude --help succeeds: the loop reloads into the edited script.
A change to bin/loop-claude, bin/file_io/**/*.py or bin/loop_claude/**/*.py takes effect at the next
cycle boundary, once loop-claude --help succeeds: the loop reloads into the edited script.
Exit 1, saying why, when:
- no task is given
+2 -1
View File
@@ -8,6 +8,7 @@ import typing
from loop_claude.effects import Effects
from loop_claude.stop import Stop
PACKAGES = ("file_io", "loop_claude")
RELOAD_FLAG = "--reloaded"
T = typing.TypeVar("T")
@@ -36,7 +37,7 @@ def decode_handed(handed: str, kind: type[T]) -> T | None:
def fingerprint(launcher: pathlib.Path) -> str:
digest = hashlib.sha256()
for path in [launcher, *sorted((launcher.parent / "loop_claude").rglob("*.py"))]:
for path in [launcher, *sorted(path for package in PACKAGES for path in (launcher.parent / package).rglob("*.py"))]:
try:
content = path.read_bytes()
except OSError as failure:
-27
View File
@@ -1,27 +0,0 @@
import re
FENCE = re.compile(r"^ {0,3}(`{3,}|~{3,})", re.M)
def sections(text: str) -> dict[str, list[str]]:
blocks: list[tuple[str | None, list[str]]] = []
opener = ""
for line in text.splitlines():
if fence := FENCE.match(line):
marker = fence.group(1)
if not opener:
opener = marker
elif marker[0] == opener[0] and len(marker) >= len(opener) and not line[fence.end():].strip():
opener = ""
fenced = bool(opener or fence)
if not fenced and line.startswith("## "):
blocks.append((line.strip()[3:], []))
elif not fenced and line.startswith("# "):
blocks.append((None, []))
elif blocks and line.strip():
blocks[-1][1].append(line)
found: dict[str, list[str]] = {}
for name, body in blocks:
if name is not None:
found.setdefault(name, []).append("\n".join(body))
return found
+2 -2
View File
@@ -6,10 +6,10 @@ import typing
from loop_claude.claude_code.model_catalog import catalog_models
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from file_io.failure import Failure
from loop_claude.stop import needs_human, needs_terminal, Stop
from loop_claude.paths import Paths
from loop_claude.file_writes import replace_json
from file_io.writes import replace_json
@dataclasses.dataclass(frozen=True)
+1 -1
View File
@@ -1,5 +1,5 @@
from loop_claude.project.checkout import read_checkout_file
from loop_claude.markdown_sections import sections
from file_io.markdown import sections
from loop_claude.stop import Stop