Run every claude the loop starts in a Claude home generated outside the clone
CI / tests (pull_request) Successful in 4m45s
CI / tests (pull_request) Successful in 4m45s
This commit is contained in:
@@ -3,7 +3,6 @@ import json
|
||||
import pathlib
|
||||
import re
|
||||
|
||||
from loop_state.paths import CLAUDE_HOME
|
||||
from failure import Failure
|
||||
from review_rules.review_passes import REVIEWERS
|
||||
from text_files.markdown_text import section
|
||||
@@ -13,9 +12,9 @@ SECTIONS = ("Shared goal", "Prose", "Vocabulary")
|
||||
|
||||
|
||||
# The text calls the file the setup's, the word that file uses for the release's rules, and names no install folder: a release may be installed anywhere.
|
||||
def reviewer_context(home: pathlib.Path) -> str | Failure:
|
||||
"""SECTIONS of the CLAUDE.md under home, as a reviewer is told them; a Failure where the file or a section is missing."""
|
||||
path = home / CLAUDE_HOME / "CLAUDE.md"
|
||||
def reviewer_context(claude_dir: pathlib.Path) -> str | Failure:
|
||||
"""SECTIONS of the CLAUDE.md in claude_dir, the loop's Claude home, as a reviewer is told them; a Failure where the file or a section is missing."""
|
||||
path = claude_dir / "CLAUDE.md"
|
||||
try:
|
||||
text = path.read_text(encoding="utf-8")
|
||||
except (OSError, UnicodeDecodeError) as failure:
|
||||
@@ -26,27 +25,27 @@ def reviewer_context(home: pathlib.Path) -> str | Failure:
|
||||
return "\n\n".join(["You start without the setup's `CLAUDE.md`. These sections of it hold for you:", *("\n".join([f"## {name}", *lines]).strip() for name, lines in found.items() if lines is not None)])
|
||||
|
||||
|
||||
def starts_bare(agent: str, home: pathlib.Path) -> bool:
|
||||
"""Whether agent is a reviewer whose definition under home starts it without the instruction files."""
|
||||
def starts_bare(agent: str, claude_dir: pathlib.Path) -> bool:
|
||||
"""Whether agent is a reviewer whose definition in claude_dir, the loop's Claude home, starts it without the instruction files."""
|
||||
if agent not in REVIEWERS.values():
|
||||
return False
|
||||
try:
|
||||
text = (home / CLAUDE_HOME / "agents" / f"{agent}.md").read_text(encoding="utf-8")
|
||||
text = (claude_dir / "agents" / f"{agent}.md").read_text(encoding="utf-8")
|
||||
except (OSError, UnicodeDecodeError):
|
||||
return False
|
||||
frontmatter = text.split("---\n")[1] if text.startswith("---\n") else ""
|
||||
return "omitClaudeMd: true" in frontmatter.splitlines()
|
||||
|
||||
|
||||
def hook_reply(given: str, home: pathlib.Path) -> str:
|
||||
def hook_reply(given: str, claude_dir: pathlib.Path) -> str:
|
||||
"""What the SubagentStart hook prints for its input given: the context for a reviewer that starts without the instruction files, and no text for any other agent."""
|
||||
try:
|
||||
read = json.loads(given)
|
||||
except ValueError:
|
||||
return ""
|
||||
if not isinstance(read, dict) or not isinstance(agent := read.get("agent_type"), str) or not starts_bare(agent, home):
|
||||
if not isinstance(read, dict) or not isinstance(agent := read.get("agent_type"), str) or not starts_bare(agent, claude_dir):
|
||||
return ""
|
||||
context = reviewer_context(home)
|
||||
context = reviewer_context(claude_dir)
|
||||
if isinstance(context, Failure):
|
||||
# Claude Code starts the subagent whatever a SubagentStart hook exits with, and shows its stderr to no headless run, so the reviewer's report is where the worker can see the failure.
|
||||
context = f"You start without the setup's `CLAUDE.md`, and the hook that hands you three of its sections failed: {context.reason}. Open your report by saying so."
|
||||
|
||||
Reference in New Issue
Block a user