Stage 1 flags the living documents a pull request makes stale (no model, nothing sent). Stage 2, on repositories that opt in with drafter: claude, has Claude Code draft the edits in a sandboxed copy of the tree and opens them as a pull request into the feature branch. A monthly pass re-reads the top-level documents against the whole repository. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
ade847ba5b
38 files changed
+4286
No files matched your search
Executable
+57
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Stand-in for the claude binary. Reads the prompt on stdin.
|
||||
|
||||
The drafter gets an allowlisted environment, so settings come from fake_claude.json
|
||||
beside this script (the tests copy both into a temporary directory). Keys:
|
||||
sentinel (file touched when invoked), env_file (file receiving the env var names),
|
||||
cwd_file (file receiving the working directory), argv_file (file receiving argv as
|
||||
JSON), prompt_copy (file receiving the --append-system-prompt-file contents),
|
||||
edit (path to append a line to), write (text to append to `edit` instead),
|
||||
delete (path to remove), fail (print an error result and exit 1).
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.stdin.read()
|
||||
config_path = Path(__file__).resolve().with_name("fake_claude.json")
|
||||
config = json.loads(config_path.read_text()) if config_path.exists() else {}
|
||||
|
||||
if config.get("sentinel"):
|
||||
Path(config["sentinel"]).write_text("invoked\n", encoding="utf-8")
|
||||
if config.get("env_file"):
|
||||
Path(config["env_file"]).write_text("\n".join(sorted(os.environ)), encoding="utf-8")
|
||||
|
||||
if config.get("cwd_file"):
|
||||
Path(config["cwd_file"]).write_text(os.getcwd(), encoding="utf-8")
|
||||
if config.get("argv_file"):
|
||||
Path(config["argv_file"]).write_text(json.dumps(sys.argv), encoding="utf-8")
|
||||
if config.get("prompt_copy") and "--append-system-prompt-file" in sys.argv:
|
||||
source = Path(sys.argv[sys.argv.index("--append-system-prompt-file") + 1])
|
||||
Path(config["prompt_copy"]).write_text(source.read_text(encoding="utf-8"),
|
||||
encoding="utf-8")
|
||||
if config.get("delete"):
|
||||
Path(config["delete"]).unlink()
|
||||
|
||||
if config.get("fail"):
|
||||
print(json.dumps({"type": "result", "subtype": "success", "is_error": True,
|
||||
"result": "credential expired"}))
|
||||
sys.exit(1)
|
||||
|
||||
target = config.get("edit")
|
||||
edits = []
|
||||
if target:
|
||||
path = Path(target)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with path.open("a", encoding="utf-8") as fh:
|
||||
fh.write(config.get("write", "Edited by the drafter.") + "\n")
|
||||
edits.append({"path": target, "why": "updated for the change"})
|
||||
|
||||
summary = {"edits": edits, "declined": []}
|
||||
print(json.dumps({
|
||||
"type": "result", "subtype": "success", "is_error": False,
|
||||
"num_turns": 3, "total_cost_usd": 0.12,
|
||||
"result": "Done.\n\n```json\n" + json.dumps(summary) + "\n```",
|
||||
}))
|
||||
Reference in new issue
Block a user