Move the Claude Code internals from --help beside the modules relying on them #100
@@ -40,6 +40,7 @@ JUDGE_SCHEMA = {
|
||||
|
||||
def judge(root, task, premises, transcript, model):
|
||||
# No tools, so the verdict rests on the transcript grounded() checks it against; no persistence, so its runs stay out of the session picker.
|
||||
# Without --bare, Claude Code 2.1.282's claude -p loads the project's and ~/.claude's CLAUDE.md.
|
||||
args = [
|
||||
"-p",
|
||||
"--json-schema", json.dumps(JUDGE_SCHEMA),
|
||||
@@ -71,6 +72,7 @@ def run_judge(root, args, prompt):
|
||||
return Failure(f"could not start claude: {failure.strerror}")
|
||||
if proc.returncode != 0:
|
||||
return Failure(proc.stderr.strip() or f"the judge exited {proc.returncode}")
|
||||
# Where Claude Code 2.1.282 puts the --json-schema output.
|
||||
return (parse(proc.stdout) or {}).get("structured_output")
|
||||
|
||||
|
||||
|
||||
@@ -32,19 +32,6 @@ 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.
|
||||
|
||||
Claude Code internals this rests on, observed on 2.1.282, the model catalog on 2.1.283:
|
||||
- The transcript is ~/.claude/projects/*/<session-id>.jsonl, one JSON object per line. A <session-id>/
|
||||
folder and <session-id>.superseded-*/ and .orphaned-*.jsonl siblings belong to the same session.
|
||||
- Claude Code writes "user" entries of its own into the transcript, and a `claude -p` prompt lands as one
|
||||
with promptSource "sdk"; UserEntryKind in transcript.py tells a human's from them.
|
||||
- An "assistant" entry, in the transcript and in --output-format stream-json, carries message.content
|
||||
parts of type "text" (text) and "tool_use" (name, input); stream-json ends with a "result" event.
|
||||
- `claude -p --output-format json --json-schema` returns the verdict under "structured_output".
|
||||
- `claude -p` without --bare loads the project's and ~/.claude's CLAUDE.md, so the judge reads the words.
|
||||
- ~/.claude.json holds projects.<path>.hasTrustDialogAccepted per checkout.
|
||||
- ~/.claude/cache/model-catalog/*.json holds catalog.config.models, each with an id and a name; the newest
|
||||
file has the highest fetchedAt.
|
||||
"""
|
||||
import dataclasses
|
||||
import sys
|
||||
|
||||
@@ -81,6 +81,7 @@ def ask_model(name, saved, folder):
|
||||
print(f"pick 1 to {len(offered)}", file=sys.stderr)
|
||||
|
||||
|
||||
# Claude Code 2.1.283's model cache; the newest file has the highest fetchedAt.
|
||||
def catalog(folder):
|
||||
newest = {}
|
||||
for path in folder.glob("*.json"):
|
||||
|
||||
@@ -27,6 +27,7 @@ def session_for(root, paths):
|
||||
|
||||
|
||||
def transcript_file(session):
|
||||
# Where Claude Code 2.1.282 writes a session's transcript.
|
||||
hit = glob.glob(os.path.join(glob.escape(str(session.projects)), "*", f"{session.id}.jsonl"))
|
||||
return hit[0] if hit else ""
|
||||
|
||||
@@ -35,6 +36,7 @@ def delete_session(session):
|
||||
path = transcript_file(session)
|
||||
if not path:
|
||||
return
|
||||
# Claude Code 2.1.282 also keeps a <id>/ folder and <id>.superseded-*/ and <id>.orphaned-*.jsonl siblings.
|
||||
for sibling in glob.glob(glob.escape(path.removesuffix(".jsonl")) + "*"):
|
||||
try:
|
||||
shutil.rmtree(sibling) if os.path.isdir(sibling) else os.remove(sibling)
|
||||
|
||||
@@ -42,6 +42,7 @@ def parts(entry):
|
||||
return found if isinstance(found, list) else []
|
||||
|
||||
|
||||
# Claude Code 2.1.282 writes "user" entries of its own, a claude -p prompt among them.
|
||||
def user_entry_kind(entry):
|
||||
if entry.get("isMeta"):
|
||||
return UserEntryKind.META
|
||||
@@ -77,6 +78,7 @@ def render(entries):
|
||||
return "\n\n".join(lines)
|
||||
|
||||
|
||||
# An "assistant" entry's parts, alike in the transcript and in stream-json on Claude Code 2.1.282.
|
||||
def said(part, limit=400):
|
||||
kind = part.get("type") if isinstance(part, dict) else None
|
||||
if kind == "text" and isinstance(part.get("text"), str) and part["text"].strip():
|
||||
|
||||
@@ -18,6 +18,7 @@ def trust(config, roots):
|
||||
if (wrong := next((path for path, record in projects.items() if not isinstance(record, dict)), None)) is not None:
|
||||
print(f"could not read {config}: projects[{json.dumps(wrong)}] is not an object", file=sys.stderr)
|
||||
return
|
||||
# Where Claude Code 2.1.282 keeps a checkout's trust.
|
||||
untrusted = [path for path in roots if not projects.get(path, {}).get("hasTrustDialogAccepted")]
|
||||
if not untrusted:
|
||||
return
|
||||
|
||||
@@ -13,6 +13,7 @@ def run_worker(root, args):
|
||||
done = False
|
||||
for raw in proc.stdout:
|
||||
event = parse(raw) or {}
|
||||
# Claude Code 2.1.282's stream-json ends with a "result" event.
|
||||
if event.get("type") == "result":
|
||||
done = True
|
||||
elif event.get("type") == "assistant":
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
The rebuild lifts every dimension: each item below is one chunk on a worktree based on `origin/rebuild`, its PR into `rebuild`, until the last item merges `rebuild` into main. The sketches, the judges' verdicts and what to take from each: `~/code/claude-handoffs/claude-config_2026-09-28.md`.
|
||||
|
||||
- **Move each Claude Code internal `--help` lists beside the module relying on it.** Or `docs/decisions.md` says why `--help` keeps it.
|
||||
- **Archive the raw transcript, deduplicated by content hash, with the verdict beside it, and stop on a failed archive.** Tests first; the changelog line says what the archive now holds.
|
||||
- **Replace `bin/test_loop_claude.py`'s internal-function tests with the black-box tests plus unit tests of the pure parsers.**
|
||||
- **Hold every reviewer to one findings document, `principles/review-findings.md`.** Severity, verdict, rounds with round 2 verifying each earlier finding, the per-chunk round cap, declining, and `/security-review`'s HIGH/MEDIUM/LOW mapped onto the scale; it replaces `principles/review-protocol.md`.
|
||||
|
||||
Reference in New Issue
Block a user