orca-agent-workflow 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- orca_agent_workflow/__init__.py +3 -0
- orca_agent_workflow/__main__.py +3 -0
- orca_agent_workflow/adoption.py +33 -0
- orca_agent_workflow/check_sync.py +93 -0
- orca_agent_workflow/cli.py +83 -0
- orca_agent_workflow/codex_review.py +364 -0
- orca_agent_workflow/doctor.py +33 -0
- orca_agent_workflow/gate.Dockerfile +9 -0
- orca_agent_workflow/install.py +313 -0
- orca_agent_workflow/migrate.py +178 -0
- orca_agent_workflow/native.py +142 -0
- orca_agent_workflow/resume_dispatch.py +160 -0
- orca_agent_workflow/review_gate.py +291 -0
- orca_agent_workflow/run_gates.py +263 -0
- orca_agent_workflow/sensitive.json +19 -0
- orca_agent_workflow/start.py +293 -0
- orca_agent_workflow/task_plan.py +301 -0
- orca_agent_workflow/task_scope.py +1256 -0
- orca_agent_workflow/template/AGENTS.md +49 -0
- orca_agent_workflow/template/CLAUDE.md +4 -0
- orca_agent_workflow/template/agents/LICENSE +21 -0
- orca_agent_workflow/template/agents/README.md +78 -0
- orca_agent_workflow/template/agents/WORKFLOW.md +65 -0
- orca_agent_workflow/template/agents/docs/cross-provider.md +79 -0
- orca_agent_workflow/template/agents/docs/roles/implementer.md +15 -0
- orca_agent_workflow/template/agents/docs/task-permissions.md +124 -0
- orca_agent_workflow/template/agents/skills/project-handoff/SKILL.md +23 -0
- orca_agent_workflow/template/agents/skills/review-pr/SKILL.md +41 -0
- orca_agent_workflow/template/agents/skills/review-pr/references/record.example.json +31 -0
- orca_agent_workflow/template/agents/skills/review-pr/references/reviewer.md +20 -0
- orca_agent_workflow/template/agents/skills/session-recover/SKILL.md +17 -0
- orca_agent_workflow/template/agents/skills/session-recover/references/recovery.md +38 -0
- orca_agent_workflow/template/agents/skills/session-recover/scripts/session_context.py +239 -0
- orca_agent_workflow/template/agents/skills/spec-and-delegate/SKILL.md +37 -0
- orca_agent_workflow/template/agents/skills/spec-and-delegate/references/spec-template.md +46 -0
- orca_agent_workflow/template/agents/skills/start-task/SKILL.md +72 -0
- orca_agent_workflow/template/agents/workflow.json +64 -0
- orca_agent_workflow/template/agents/workflow.py +82 -0
- orca_agent_workflow/template/claude/skills/project-handoff/SKILL.md +12 -0
- orca_agent_workflow/template/claude/skills/review-pr/SKILL.md +12 -0
- orca_agent_workflow/template/claude/skills/session-recover/SKILL.md +12 -0
- orca_agent_workflow/template/claude/skills/spec-and-delegate/SKILL.md +12 -0
- orca_agent_workflow/template/claude/skills/start-task/SKILL.md +12 -0
- orca_agent_workflow/template/gitattributes +5 -0
- orca_agent_workflow/template/githooks/pre-push +11 -0
- orca_agent_workflow/template/gitignore +3 -0
- orca_agent_workflow/template/opencode/commands/project-handoff.md +7 -0
- orca_agent_workflow/template/opencode/commands/review-pr.md +7 -0
- orca_agent_workflow/template/opencode/commands/session-recover.md +7 -0
- orca_agent_workflow/template/opencode/commands/spec-and-delegate.md +7 -0
- orca_agent_workflow/template/opencode/commands/start-task.md +9 -0
- orca_agent_workflow-0.2.0.dist-info/METADATA +214 -0
- orca_agent_workflow-0.2.0.dist-info/RECORD +57 -0
- orca_agent_workflow-0.2.0.dist-info/WHEEL +5 -0
- orca_agent_workflow-0.2.0.dist-info/entry_points.txt +2 -0
- orca_agent_workflow-0.2.0.dist-info/licenses/LICENSE +21 -0
- orca_agent_workflow-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""Wait for a prepared local Claude client and dispatch its brief once."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import shutil
|
|
9
|
+
import subprocess
|
|
10
|
+
import sys
|
|
11
|
+
import time
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
from orca_agent_workflow import task_scope
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def orca(cli: str, *args: str, timeout: float = 30) -> tuple[int, dict]:
|
|
18
|
+
result = subprocess.run(
|
|
19
|
+
[cli, *args, "--environment", "local", "--json"],
|
|
20
|
+
capture_output=True, text=True, timeout=timeout,
|
|
21
|
+
)
|
|
22
|
+
try:
|
|
23
|
+
return result.returncode, json.loads(result.stdout)
|
|
24
|
+
except ValueError as exc:
|
|
25
|
+
raise ValueError("Orca did not return a JSON receipt.") from exc
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def exact_client(bundle: Path, scope: task_scope.Scope, args: argparse.Namespace, cli: str) -> dict:
|
|
29
|
+
scope.live()
|
|
30
|
+
controller = task_scope.controller_status(bundle)
|
|
31
|
+
if (
|
|
32
|
+
controller.get("state") != "running"
|
|
33
|
+
or controller.get("terminal") != args.terminal
|
|
34
|
+
or controller.get("manifest_sha256") != scope.sha
|
|
35
|
+
or controller.get("head") != scope.data["head"]
|
|
36
|
+
or controller.get("bundle") != str(bundle)
|
|
37
|
+
):
|
|
38
|
+
raise ValueError("The intended scoped client has exited or its launch record no longer matches.")
|
|
39
|
+
pid = controller.get("pid")
|
|
40
|
+
if type(pid) is not int or pid <= 0:
|
|
41
|
+
raise ValueError("Missing scoped client PID.")
|
|
42
|
+
os.kill(pid, 0)
|
|
43
|
+
code, reply = orca(cli, "terminal", "show", "--terminal", args.terminal)
|
|
44
|
+
terminal = reply.get("result", {}).get("terminal", {})
|
|
45
|
+
if (
|
|
46
|
+
code or reply.get("ok") is not True
|
|
47
|
+
or terminal.get("handle") != args.terminal
|
|
48
|
+
or terminal.get("agentIdentity") != "claude"
|
|
49
|
+
or terminal.get("connected") is not True
|
|
50
|
+
or terminal.get("writable") is not True
|
|
51
|
+
or not terminal.get("incarnationId")
|
|
52
|
+
or Path(terminal.get("worktreePath") or "/").resolve() != scope.root
|
|
53
|
+
):
|
|
54
|
+
raise ValueError("Orca cannot identify the expected live Claude terminal. Inspect the original tab.")
|
|
55
|
+
return {
|
|
56
|
+
"terminal": args.terminal,
|
|
57
|
+
"incarnation": terminal["incarnationId"],
|
|
58
|
+
"started_at": controller["started_at"],
|
|
59
|
+
"pid": pid,
|
|
60
|
+
"manifest_sha256": scope.sha,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def exclusive_json(path: Path, data: dict) -> None:
|
|
65
|
+
with path.open("x", encoding="utf-8") as stream:
|
|
66
|
+
json.dump(data, stream, indent=2)
|
|
67
|
+
stream.flush()
|
|
68
|
+
os.fsync(stream.fileno())
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def dispatch(args: argparse.Namespace) -> None:
|
|
72
|
+
if sys.platform != "darwin":
|
|
73
|
+
raise ValueError("This helper currently supports local macOS Claude terminals.")
|
|
74
|
+
cli = shutil.which("orca")
|
|
75
|
+
if not cli:
|
|
76
|
+
raise ValueError("Install the local Orca CLI.")
|
|
77
|
+
coordinator = os.environ.get("ORCA_TERMINAL_HANDLE")
|
|
78
|
+
if not coordinator or coordinator == args.terminal:
|
|
79
|
+
raise ValueError("Run from the owning Orca coordinator terminal.")
|
|
80
|
+
bundle = args.bundle.resolve(strict=True)
|
|
81
|
+
scope = task_scope.Scope(bundle / "manifest.json")
|
|
82
|
+
if scope.root != task_scope.project_root():
|
|
83
|
+
raise ValueError("Run from the scoped task checkout.")
|
|
84
|
+
brief = args.brief.resolve(strict=True)
|
|
85
|
+
state = bundle / "dispatch-intent.json"
|
|
86
|
+
attempted = bundle / "dispatch-attempt.json"
|
|
87
|
+
receipt = bundle / "dispatch-receipt.json"
|
|
88
|
+
if attempted.exists():
|
|
89
|
+
raise ValueError(f"A dispatch already started. Inspect {receipt} and the original Orca run before recovery.")
|
|
90
|
+
identity = exact_client(bundle, scope, args, cli)
|
|
91
|
+
intent = {
|
|
92
|
+
**identity, "run": args.run, "coordinator": coordinator,
|
|
93
|
+
"brief": str(brief), "brief_sha256": task_scope.digest(brief),
|
|
94
|
+
"title": args.title,
|
|
95
|
+
}
|
|
96
|
+
try:
|
|
97
|
+
exclusive_json(state, intent)
|
|
98
|
+
except FileExistsError:
|
|
99
|
+
if json.loads(state.read_text(encoding="utf-8")) != intent:
|
|
100
|
+
raise ValueError("The original dispatch intent differs. Check the exact client and brief.")
|
|
101
|
+
deadline = time.monotonic() + args.timeout
|
|
102
|
+
print(f"Waiting for Claude readiness in {args.terminal}. Confirm trust in that tab if prompted.", file=sys.stderr)
|
|
103
|
+
while time.monotonic() < deadline:
|
|
104
|
+
if exact_client(bundle, scope, args, cli) != identity:
|
|
105
|
+
raise ValueError("The scoped terminal changed while waiting.")
|
|
106
|
+
remaining = deadline - time.monotonic()
|
|
107
|
+
if remaining <= 0:
|
|
108
|
+
raise ValueError("Timed out before dispatch. Inspect the original tab.")
|
|
109
|
+
code, reply = orca(
|
|
110
|
+
cli, "terminal", "wait", "--terminal", args.terminal, "--for", "tui-idle",
|
|
111
|
+
"--timeout-ms", str(max(1, min(int(remaining * 1000), 2000))),
|
|
112
|
+
)
|
|
113
|
+
wait = reply.get("result", {}).get("wait", {})
|
|
114
|
+
if wait.get("satisfied") is True and reply.get("ok") is True and code == 0:
|
|
115
|
+
if wait.get("handle") != args.terminal or wait.get("blockedReason"):
|
|
116
|
+
raise ValueError("Orca returned a readiness receipt for a different or blocked terminal.")
|
|
117
|
+
break
|
|
118
|
+
if wait.get("blockedReason") not in (None, "agent-trust-workspace"):
|
|
119
|
+
raise ValueError(f"Claude is waiting for {wait['blockedReason']}. Inspect the original tab.")
|
|
120
|
+
if not wait and reply.get("error", {}).get("code") != "timeout":
|
|
121
|
+
raise ValueError(f"Orca readiness could not be verified: {reply.get('error')}")
|
|
122
|
+
else:
|
|
123
|
+
raise ValueError("Timed out before dispatch. Inspect the original tab and rerun this command if it is still live.")
|
|
124
|
+
if exact_client(bundle, scope, args, cli) != identity or task_scope.digest(brief) != intent["brief_sha256"]:
|
|
125
|
+
raise ValueError("The terminal or brief changed while waiting.")
|
|
126
|
+
# Reserve the one attempt before contacting Orca. Keep it even on an interrupted reply.
|
|
127
|
+
try:
|
|
128
|
+
exclusive_json(attempted, intent)
|
|
129
|
+
except FileExistsError as exc:
|
|
130
|
+
raise ValueError("Another invocation reserved the dispatch. Inspect the original Orca run.") from exc
|
|
131
|
+
try:
|
|
132
|
+
code, reply = orca(
|
|
133
|
+
cli, "orchestration", "worker-start", "--run", args.run, "--from", coordinator,
|
|
134
|
+
"--terminal", args.terminal, "--spec-file", str(brief), "--task-title", args.title,
|
|
135
|
+
timeout=90,
|
|
136
|
+
)
|
|
137
|
+
task_scope.atomic_json(receipt, reply)
|
|
138
|
+
except (OSError, ValueError, subprocess.SubprocessError) as exc:
|
|
139
|
+
raise ValueError(f"Dispatch outcome uncertain. Inspect the original Orca run before retrying: {exc}") from exc
|
|
140
|
+
print(json.dumps(reply))
|
|
141
|
+
if code or reply.get("ok") is not True:
|
|
142
|
+
raise ValueError(f"Orca did not confirm the dispatch. Follow the recovery steps in {receipt}.")
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def main() -> int:
|
|
146
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
147
|
+
parser.add_argument("--bundle", type=Path, required=True)
|
|
148
|
+
parser.add_argument("--terminal", required=True)
|
|
149
|
+
parser.add_argument("--run", required=True)
|
|
150
|
+
parser.add_argument("--brief", type=Path, required=True)
|
|
151
|
+
parser.add_argument("--title", required=True)
|
|
152
|
+
parser.add_argument("--timeout", type=int, default=300)
|
|
153
|
+
args = parser.parse_args()
|
|
154
|
+
if args.timeout < 1:
|
|
155
|
+
parser.error("--timeout must be positive")
|
|
156
|
+
try:
|
|
157
|
+
dispatch(args)
|
|
158
|
+
except (OSError, ValueError, subprocess.SubprocessError) as exc:
|
|
159
|
+
parser.exit(1, f"resume-dispatch: {exc}\n")
|
|
160
|
+
return 0
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Validate local, head/base-bound review evidence; never launch or merge anything.
|
|
3
|
+
|
|
4
|
+
This validates coordinator-recorded evidence, not a signed model attestation or
|
|
5
|
+
GitHub branch protection. The coordinator must corroborate model/session identity
|
|
6
|
+
against the saved Orca receipt and provider transcript before writing the record.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import hashlib
|
|
13
|
+
import json
|
|
14
|
+
import re
|
|
15
|
+
import sys
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
from orca_agent_workflow import __version__, task_scope
|
|
20
|
+
|
|
21
|
+
# Exact, versioned model IDs only; aliases such as "opus" or "latest" never qualify.
|
|
22
|
+
MODEL_ID = {
|
|
23
|
+
"claude": re.compile(r"claude-[a-z]+-\d+(?:-\d+)*"),
|
|
24
|
+
"codex": re.compile(r"gpt-\d+(?:\.\d+)*(?:-[a-z]+)?"),
|
|
25
|
+
}
|
|
26
|
+
# Why the planner's provider may also review: the other provider genuinely could not run.
|
|
27
|
+
FALLBACK_REASONS = {"quota_exhausted", "launch_failed", "unqualified", "model_unavailable"}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def exact_model(agent: Any, model: Any) -> bool:
|
|
31
|
+
pattern = MODEL_ID.get(agent) if isinstance(agent, str) else None
|
|
32
|
+
return bool(pattern and isinstance(model, str) and pattern.fullmatch(model))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def enabled_reviewers(policy: dict[str, Any]) -> list[dict[str, Any]]:
|
|
36
|
+
"""Exact, enabled reviewer profiles from the trusted (reviewed-base) policy."""
|
|
37
|
+
return enabled_profiles(policy, "reviewer")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def enabled_profiles(policy: dict[str, Any], role: str) -> list[dict[str, Any]]:
|
|
41
|
+
"""Exact, enabled profiles for one role from the trusted (reviewed-base) policy."""
|
|
42
|
+
profiles = policy.get("roles", {}).get(role) if policy.get("version") == 2 else None
|
|
43
|
+
if not isinstance(profiles, list):
|
|
44
|
+
return []
|
|
45
|
+
return [
|
|
46
|
+
p
|
|
47
|
+
for p in profiles
|
|
48
|
+
if isinstance(p, dict)
|
|
49
|
+
and p.get("enabled") is True
|
|
50
|
+
and exact_model(p.get("agent"), p.get("model"))
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def digest(path: Path) -> str:
|
|
55
|
+
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def provider_preference_errors(
|
|
59
|
+
record: dict[str, Any],
|
|
60
|
+
policy: dict[str, Any],
|
|
61
|
+
reviewer: dict[str, Any],
|
|
62
|
+
allowed: list[dict[str, Any]],
|
|
63
|
+
) -> list[str]:
|
|
64
|
+
"""The planner's provider reviews only as a disclosed fallback.
|
|
65
|
+
|
|
66
|
+
The fallback applies only while the trusted policy enables a reviewer from another
|
|
67
|
+
provider; a single-provider policy has nothing to fall back from. A human-planned
|
|
68
|
+
change has no planner provider to avoid.
|
|
69
|
+
"""
|
|
70
|
+
errors: list[str] = []
|
|
71
|
+
planner = record.get("planner")
|
|
72
|
+
if not isinstance(planner, dict):
|
|
73
|
+
planner = {}
|
|
74
|
+
same_provider = False
|
|
75
|
+
if planner.get("agent") != "human":
|
|
76
|
+
if not any(
|
|
77
|
+
p["agent"] == planner.get("agent") and p["model"] == planner.get("model")
|
|
78
|
+
for p in enabled_profiles(policy, "planner")
|
|
79
|
+
):
|
|
80
|
+
errors.append("planner is not an enabled exact policy profile")
|
|
81
|
+
other_provider = any(p["agent"] != planner.get("agent") for p in allowed)
|
|
82
|
+
same_provider = other_provider and planner.get("agent") == reviewer.get("agent")
|
|
83
|
+
fallback = record.get("cross_provider_fallback")
|
|
84
|
+
if same_provider:
|
|
85
|
+
reason = fallback.get("reason") if isinstance(fallback, dict) else None
|
|
86
|
+
if not isinstance(reason, str) or reason not in FALLBACK_REASONS:
|
|
87
|
+
errors.append("same-provider review needs a cross_provider_fallback reason")
|
|
88
|
+
elif fallback is not None:
|
|
89
|
+
errors.append("cross_provider_fallback is only valid for a same-provider review")
|
|
90
|
+
return errors
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def validate_review(
|
|
94
|
+
record: Any, policy: dict[str, Any], *, head: str, base: str, policy_digest: str
|
|
95
|
+
) -> list[str]:
|
|
96
|
+
"""Return all defects; missing, stale, incomplete, or malformed records fail."""
|
|
97
|
+
if not isinstance(record, dict):
|
|
98
|
+
return ["review record must be an object"]
|
|
99
|
+
errors: list[str] = []
|
|
100
|
+
if record.get("version") != 1 or isinstance(record.get("version"), bool):
|
|
101
|
+
errors.append("unsupported record version")
|
|
102
|
+
for key, expected in (("head_sha", head), ("base_sha", base)):
|
|
103
|
+
if not re.fullmatch(r"[0-9a-f]{40}", expected):
|
|
104
|
+
errors.append(f"expected {key} must be a full commit SHA")
|
|
105
|
+
if record.get(key) != expected:
|
|
106
|
+
errors.append(f"stale or missing {key}")
|
|
107
|
+
if record.get("repository") != policy["repository"]:
|
|
108
|
+
errors.append("wrong repository")
|
|
109
|
+
if record.get("policy_sha256") != policy_digest:
|
|
110
|
+
errors.append("review policy changed")
|
|
111
|
+
if record.get("verdict") != "pass":
|
|
112
|
+
errors.append("review has not passed")
|
|
113
|
+
reviewer = record.get("reviewer")
|
|
114
|
+
if not isinstance(reviewer, dict):
|
|
115
|
+
reviewer = {}
|
|
116
|
+
allowed = enabled_reviewers(policy)
|
|
117
|
+
if not allowed:
|
|
118
|
+
errors.append("trusted policy has no enabled reviewer profile")
|
|
119
|
+
profile = {"agent": reviewer.get("agent"), "model": reviewer.get("requested_model")}
|
|
120
|
+
if not any(p["agent"] == profile["agent"] and p["model"] == profile["model"] for p in allowed):
|
|
121
|
+
errors.append("reviewer is not an enabled exact policy profile")
|
|
122
|
+
if policy.get("reviewer_provider_differs_from_planner") == "preferred":
|
|
123
|
+
errors.extend(provider_preference_errors(record, policy, reviewer, allowed))
|
|
124
|
+
if reviewer.get("effective_model") != reviewer.get("requested_model"):
|
|
125
|
+
errors.append("wrong or unverified effective_model; model fallback is not accepted")
|
|
126
|
+
for field in ("session_id", "dispatch_id"):
|
|
127
|
+
if not isinstance(reviewer.get(field), str) or not reviewer[field].strip():
|
|
128
|
+
errors.append(f"missing reviewer {field}")
|
|
129
|
+
if reviewer.get("fresh_session") is not True:
|
|
130
|
+
errors.append("reviewer must be a fresh session")
|
|
131
|
+
if reviewer.get("agent") == "codex":
|
|
132
|
+
# Codex reports no served model; its session file records the client-side turn
|
|
133
|
+
# model. Weaker than a response-level model and documented as such.
|
|
134
|
+
if reviewer.get("model_evidence") != "codex-session-turn-context":
|
|
135
|
+
errors.append("Codex reviewer needs codex-session-turn-context model evidence")
|
|
136
|
+
if not re.fullmatch(r"[0-9a-f]{64}", str(reviewer.get("qualification_sha256", ""))):
|
|
137
|
+
errors.append("Codex reviewer needs the qualification digest")
|
|
138
|
+
sensitive = record.get("sensitive_files_reviewed")
|
|
139
|
+
if not isinstance(sensitive, list) or not all(isinstance(s, str) for s in sensitive):
|
|
140
|
+
errors.append("sensitive_files_reviewed must be an explicit list, including when empty")
|
|
141
|
+
author = record.get("implementer_session_id")
|
|
142
|
+
authorship = record.get("implementation_authorship")
|
|
143
|
+
if authorship == "agent":
|
|
144
|
+
if not isinstance(author, str) or not author.strip():
|
|
145
|
+
errors.append("unknown implementer session; independence is unverified")
|
|
146
|
+
elif authorship == "human":
|
|
147
|
+
if author is not None:
|
|
148
|
+
errors.append("human authorship must not hide an agent session")
|
|
149
|
+
else:
|
|
150
|
+
errors.append("implementation authorship is unknown")
|
|
151
|
+
if isinstance(author, str) and author == reviewer.get("session_id"):
|
|
152
|
+
errors.append("implementer cannot review its own work")
|
|
153
|
+
coverage = record.get("coverage")
|
|
154
|
+
if not isinstance(coverage, dict):
|
|
155
|
+
coverage = {}
|
|
156
|
+
for field in ("complete_diff", "acceptance_criteria", "test_evidence"):
|
|
157
|
+
if coverage.get(field) is not True:
|
|
158
|
+
errors.append(f"review coverage incomplete: {field}")
|
|
159
|
+
findings = record.get("findings")
|
|
160
|
+
if not isinstance(findings, list):
|
|
161
|
+
errors.append("findings must be an explicit list, including when empty")
|
|
162
|
+
else:
|
|
163
|
+
for finding in findings:
|
|
164
|
+
if not isinstance(finding, dict) or not isinstance(finding.get("blocking"), bool):
|
|
165
|
+
errors.append("malformed finding")
|
|
166
|
+
elif finding["blocking"] and finding.get("status") != "resolved":
|
|
167
|
+
errors.append("unresolved blocking finding")
|
|
168
|
+
if not isinstance(record.get("summary"), str) or not record["summary"].strip():
|
|
169
|
+
errors.append("missing review summary")
|
|
170
|
+
for field in ("launch_receipt_sha256", "review_report_sha256"):
|
|
171
|
+
if not isinstance(record.get(field), str) or not re.fullmatch(
|
|
172
|
+
r"[0-9a-f]{64}", record[field]
|
|
173
|
+
):
|
|
174
|
+
errors.append(f"missing evidence digest: {field}")
|
|
175
|
+
return errors
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def validator_problem(base: str) -> str | None:
|
|
179
|
+
"""A runtime inside the checkout (the kit's source, a vendored copy) is the branch's
|
|
180
|
+
own code: it may validate only if every file matches the reviewed base's copy."""
|
|
181
|
+
package = Path(__file__).resolve().parent
|
|
182
|
+
try:
|
|
183
|
+
root = task_scope.project_root()
|
|
184
|
+
except (ValueError, OSError):
|
|
185
|
+
return None # an installed runtime outside any checkout
|
|
186
|
+
if not package.is_relative_to(root):
|
|
187
|
+
return None
|
|
188
|
+
for path in sorted(package.rglob("*")):
|
|
189
|
+
if not path.is_file() or "__pycache__" in path.parts:
|
|
190
|
+
continue
|
|
191
|
+
relative = path.relative_to(root).as_posix()
|
|
192
|
+
try:
|
|
193
|
+
committed = task_scope.git_bytes(root, "show", f"{base}:{relative}")
|
|
194
|
+
except Exception:
|
|
195
|
+
committed = None
|
|
196
|
+
if committed != path.read_bytes():
|
|
197
|
+
return f"{relative} differs from the reviewed base; run the base's copy"
|
|
198
|
+
return None
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def main() -> int:
|
|
202
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
203
|
+
parser.add_argument(
|
|
204
|
+
"--policy",
|
|
205
|
+
type=Path,
|
|
206
|
+
help="A saved copy of the base's .agents/workflow.json; default: read it from --base",
|
|
207
|
+
)
|
|
208
|
+
parser.add_argument("--record", required=True, type=Path)
|
|
209
|
+
parser.add_argument("--head", required=True)
|
|
210
|
+
parser.add_argument("--base", required=True)
|
|
211
|
+
parser.add_argument("--launch-receipt", required=True, type=Path)
|
|
212
|
+
parser.add_argument("--review-report", required=True, type=Path)
|
|
213
|
+
parser.add_argument(
|
|
214
|
+
"--sensitive-paths",
|
|
215
|
+
required=True,
|
|
216
|
+
type=Path,
|
|
217
|
+
help="The reviewer brief's sensitive-paths.txt; each must be in sensitive_files_reviewed",
|
|
218
|
+
)
|
|
219
|
+
args = parser.parse_args()
|
|
220
|
+
try:
|
|
221
|
+
if args.policy:
|
|
222
|
+
data = args.policy.read_bytes()
|
|
223
|
+
else:
|
|
224
|
+
data, _ = task_scope.base_config(task_scope.project_root(), args.base)
|
|
225
|
+
config = task_scope.load_config(data)
|
|
226
|
+
pinned = config["runtime"].get("version")
|
|
227
|
+
if pinned != __version__:
|
|
228
|
+
print(
|
|
229
|
+
f"review-gate: BLOCKED (this is version {__version__}; the reviewed base pins "
|
|
230
|
+
f"{pinned}; run the pinned version)",
|
|
231
|
+
file=sys.stderr,
|
|
232
|
+
)
|
|
233
|
+
return 1
|
|
234
|
+
problem = validator_problem(args.base)
|
|
235
|
+
if problem:
|
|
236
|
+
print(f"review-gate: BLOCKED (validator: {problem})", file=sys.stderr)
|
|
237
|
+
return 1
|
|
238
|
+
policy = task_scope.roles_policy(config)
|
|
239
|
+
record = json.loads(args.record.read_text(encoding="utf-8"))
|
|
240
|
+
errors = validate_review(
|
|
241
|
+
record,
|
|
242
|
+
policy,
|
|
243
|
+
head=args.head,
|
|
244
|
+
base=args.base,
|
|
245
|
+
policy_digest=hashlib.sha256(data).hexdigest(),
|
|
246
|
+
)
|
|
247
|
+
if isinstance(record, dict):
|
|
248
|
+
for field, path in (
|
|
249
|
+
("launch_receipt_sha256", args.launch_receipt),
|
|
250
|
+
("review_report_sha256", args.review_report),
|
|
251
|
+
):
|
|
252
|
+
if (
|
|
253
|
+
not path.is_file()
|
|
254
|
+
or not path.stat().st_size
|
|
255
|
+
or record.get(field) != digest(path)
|
|
256
|
+
):
|
|
257
|
+
errors.append(f"missing or changed evidence: {field}")
|
|
258
|
+
expected = {s for s in args.sensitive_paths.read_text(encoding="utf-8").splitlines() if s}
|
|
259
|
+
missing = expected - set(record.get("sensitive_files_reviewed") or [])
|
|
260
|
+
if missing:
|
|
261
|
+
errors.append("sensitive files not reviewed: " + ", ".join(sorted(missing)))
|
|
262
|
+
reviewer = record.get("reviewer") or {}
|
|
263
|
+
if reviewer.get("agent") == "codex":
|
|
264
|
+
receipt = json.loads(args.launch_receipt.read_text(encoding="utf-8"))
|
|
265
|
+
if (
|
|
266
|
+
not isinstance(receipt, dict)
|
|
267
|
+
or receipt.get("qualification_sha256") != reviewer.get("qualification_sha256")
|
|
268
|
+
or receipt.get("thread_id") != reviewer.get("session_id")
|
|
269
|
+
or receipt.get("thread_id") != reviewer.get("dispatch_id")
|
|
270
|
+
or receipt.get("session_models") != [reviewer.get("requested_model")]
|
|
271
|
+
or receipt.get("head") != args.head
|
|
272
|
+
or type(receipt.get("returncode")) is not int
|
|
273
|
+
or receipt.get("returncode") != 0
|
|
274
|
+
or "grant_ended" not in receipt
|
|
275
|
+
or receipt["grant_ended"] is not None
|
|
276
|
+
or receipt.get("inputs_changed") != []
|
|
277
|
+
):
|
|
278
|
+
errors.append("Codex record does not match its launch receipt")
|
|
279
|
+
except (OSError, ValueError, KeyError, TypeError):
|
|
280
|
+
print("review-gate: BLOCKED (missing or invalid local evidence/policy)", file=sys.stderr)
|
|
281
|
+
return 1
|
|
282
|
+
if errors:
|
|
283
|
+
for error in errors:
|
|
284
|
+
print(f"review-gate: BLOCKED ({error})", file=sys.stderr)
|
|
285
|
+
return 1
|
|
286
|
+
print("review-gate: PASS (local workflow evidence; human merge remains required)")
|
|
287
|
+
return 0
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
if __name__ == "__main__":
|
|
291
|
+
raise SystemExit(main())
|