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,33 @@
|
|
|
1
|
+
"""Describe the local Git revisions used at the first project handoff."""
|
|
2
|
+
|
|
3
|
+
import subprocess
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from orca_agent_workflow import task_scope
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def revisions(root: Path) -> dict[str, str]:
|
|
10
|
+
def git_text(*args: str) -> str:
|
|
11
|
+
try:
|
|
12
|
+
return task_scope.git_bytes(root, *args).decode().strip()
|
|
13
|
+
except (subprocess.CalledProcessError, FileNotFoundError):
|
|
14
|
+
return ""
|
|
15
|
+
|
|
16
|
+
def policy(commit: str) -> str:
|
|
17
|
+
if not commit:
|
|
18
|
+
return "unresolved"
|
|
19
|
+
entry = git_text("ls-tree", commit, "--", task_scope.CONFIG)
|
|
20
|
+
return f"{commit} (policy {'present' if entry else 'unavailable'})"
|
|
21
|
+
|
|
22
|
+
head = gate = worker = default_ref = ""
|
|
23
|
+
if (root / ".git").exists():
|
|
24
|
+
head = git_text("rev-parse", "--verify", "HEAD^{commit}")
|
|
25
|
+
default_ref = git_text("symbolic-ref", "--quiet", "refs/remotes/origin/HEAD")
|
|
26
|
+
if default_ref:
|
|
27
|
+
gate = git_text("rev-parse", "--verify", default_ref + "^{commit}")
|
|
28
|
+
worker = git_text("merge-base", "HEAD", "origin/HEAD")
|
|
29
|
+
return {
|
|
30
|
+
"workspace (committed HEAD)": policy(head),
|
|
31
|
+
"gate (origin default branch)": policy(gate) if default_ref else "origin/HEAD unavailable",
|
|
32
|
+
"worker (merge base with origin/HEAD)": policy(worker) if default_ref else "origin/HEAD unavailable",
|
|
33
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Check the project's workflow contract without calling a model or changing settings."""
|
|
3
|
+
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from orca_agent_workflow import __version__, review_gate, task_scope
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def check(root: Path) -> list[str]:
|
|
11
|
+
problems = []
|
|
12
|
+
try:
|
|
13
|
+
config = task_scope.load_config((root / task_scope.CONFIG).read_bytes())
|
|
14
|
+
policy = task_scope.roles_policy(config)
|
|
15
|
+
pinned = config["runtime"].get("version")
|
|
16
|
+
if config["runtime"].get("package") != "orca-agent-workflow" or not pinned:
|
|
17
|
+
problems.append("runtime must pin an orca-agent-workflow version")
|
|
18
|
+
elif pinned != __version__:
|
|
19
|
+
problems.append(f"Runtime {__version__} differs from the pinned {pinned}")
|
|
20
|
+
if not isinstance(config["project"].get("checks", []), list):
|
|
21
|
+
problems.append("project.checks must be a list of commands")
|
|
22
|
+
if policy.get("reviewer_provider_differs_from_planner") != "preferred":
|
|
23
|
+
problems.append('reviewer_provider_differs_from_planner must be "preferred"')
|
|
24
|
+
for role in ("planner", "implementer", "reviewer"):
|
|
25
|
+
profiles = policy.get("roles", {}).get(role)
|
|
26
|
+
if not isinstance(profiles, list):
|
|
27
|
+
problems.append(f"Missing role: {role}")
|
|
28
|
+
continue
|
|
29
|
+
for profile in profiles:
|
|
30
|
+
if profile.get("enabled") is True and not review_gate.exact_model(
|
|
31
|
+
profile.get("agent"), profile.get("model")
|
|
32
|
+
):
|
|
33
|
+
problems.append(f"Enabled {role} requires an exact model ID")
|
|
34
|
+
if (
|
|
35
|
+
role == "implementer"
|
|
36
|
+
and profile.get("agent") != "claude"
|
|
37
|
+
and profile.get("enabled")
|
|
38
|
+
):
|
|
39
|
+
problems.append("Only the qualified Claude file-only implementer is supported")
|
|
40
|
+
skills = (
|
|
41
|
+
"start-task",
|
|
42
|
+
"spec-and-delegate",
|
|
43
|
+
"review-pr",
|
|
44
|
+
"project-handoff",
|
|
45
|
+
"session-recover",
|
|
46
|
+
)
|
|
47
|
+
for skill in skills:
|
|
48
|
+
canonical = root / f".agents/skills/{skill}/SKILL.md"
|
|
49
|
+
adapter = root / f".claude/skills/{skill}/SKILL.md"
|
|
50
|
+
command = root / f".opencode/commands/{skill}.md"
|
|
51
|
+
if not canonical.is_file():
|
|
52
|
+
problems.append(f"Missing shared skill: {skill}")
|
|
53
|
+
if (
|
|
54
|
+
not adapter.is_file()
|
|
55
|
+
or f".agents/skills/{skill}/SKILL.md" not in adapter.read_text(encoding="utf-8")
|
|
56
|
+
):
|
|
57
|
+
problems.append(f"Claude adapter drift: {skill}")
|
|
58
|
+
# OpenCode commands are optional; once installed they must stay thin.
|
|
59
|
+
if (root / ".opencode/commands").is_dir() and (
|
|
60
|
+
not command.is_file()
|
|
61
|
+
or f".agents/skills/{skill}/SKILL.md" not in command.read_text(encoding="utf-8")
|
|
62
|
+
):
|
|
63
|
+
problems.append(f"OpenCode command drift: {skill}")
|
|
64
|
+
if ".agents/skills/start-task/SKILL.md" not in (root / "AGENTS.md").read_text(encoding="utf-8"):
|
|
65
|
+
problems.append(
|
|
66
|
+
"AGENTS.md must route substantive tasks to the shared start-task skill"
|
|
67
|
+
)
|
|
68
|
+
if "@AGENTS.md" not in (root / "CLAUDE.md").read_text(encoding="utf-8"):
|
|
69
|
+
problems.append("CLAUDE.md must import the shared contract")
|
|
70
|
+
for path in (
|
|
71
|
+
".agents/workflow.py",
|
|
72
|
+
".agents/WORKFLOW.md",
|
|
73
|
+
".agents/docs/roles/implementer.md",
|
|
74
|
+
".agents/skills/spec-and-delegate/references/spec-template.md",
|
|
75
|
+
):
|
|
76
|
+
if not (root / path).is_file():
|
|
77
|
+
problems.append(f"Missing workflow file: {path}")
|
|
78
|
+
except (OSError, ValueError, KeyError, TypeError) as exc:
|
|
79
|
+
problems.append(f"Invalid workflow configuration: {exc}")
|
|
80
|
+
return problems
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def main() -> int:
|
|
84
|
+
problems = check(task_scope.project_folder())
|
|
85
|
+
for problem in problems:
|
|
86
|
+
print("workflow-check: " + problem, file=sys.stderr)
|
|
87
|
+
if not problems:
|
|
88
|
+
print("workflow-check: OK (shared contract, roles, and thin adapters)")
|
|
89
|
+
return int(bool(problems))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
if __name__ == "__main__":
|
|
93
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""One command for the workflow runtime; each subcommand keeps its module's own options."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import importlib
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from orca_agent_workflow import __version__
|
|
10
|
+
|
|
11
|
+
COMMANDS = {
|
|
12
|
+
"init": ("install", "Install the project files (preview; --apply writes)"),
|
|
13
|
+
"migrate": ("migrate", "Convert a v1 project to the pinned runtime (preview first)"),
|
|
14
|
+
"start": ("start", "Open a planning task in a fresh Orca worktree"),
|
|
15
|
+
"status": ("start", "Show what is needed before a task can start"),
|
|
16
|
+
"check": ("check_sync", "Check the project's workflow contract"),
|
|
17
|
+
"doctor": ("doctor", "Inspect local prerequisites"),
|
|
18
|
+
"plan": ("task_plan", "Generate a worker or reviewer manifest and brief"),
|
|
19
|
+
"scope": ("task_scope", "Prepare, probe, launch or serve a scoped client"),
|
|
20
|
+
"resume-dispatch": ("resume_dispatch", "Wait for Claude trust and dispatch a prepared brief"),
|
|
21
|
+
"gate": ("run_gates", "Run project checks in the isolated gate container"),
|
|
22
|
+
"native-check": ("native", "Run reviewed Xcode tests on the coordinator host"),
|
|
23
|
+
"review-gate": ("review_gate", "Validate revision-bound review evidence"),
|
|
24
|
+
"codex-review": ("codex_review", "Qualify or run the Codex reviewer adapter"),
|
|
25
|
+
}
|
|
26
|
+
# init and migrate run before a project pins a version; review-gate checks itself against
|
|
27
|
+
# the reviewed base's pin, not the branch's working tree.
|
|
28
|
+
UNPINNED = {"init", "migrate", "review-gate"}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def usage() -> str:
|
|
32
|
+
lines = [f"usage: orca-agent-workflow <command> [options] (version {__version__})", ""]
|
|
33
|
+
lines += [f" {name:<14}{summary}" for name, (_, summary) in COMMANDS.items()]
|
|
34
|
+
return "\n".join(lines)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def pin_problem() -> str | None:
|
|
38
|
+
"""A project pins one runtime version; any other version refuses to act on it."""
|
|
39
|
+
from orca_agent_workflow import task_scope
|
|
40
|
+
|
|
41
|
+
try:
|
|
42
|
+
data = (task_scope.project_folder() / task_scope.CONFIG).read_bytes()
|
|
43
|
+
except (OSError, ValueError):
|
|
44
|
+
return None # outside a configured project; the command reports what it needs
|
|
45
|
+
try:
|
|
46
|
+
pinned = json.loads(data)["runtime"]["version"]
|
|
47
|
+
except (ValueError, KeyError, TypeError):
|
|
48
|
+
return f"{task_scope.CONFIG} has no runtime version pin"
|
|
49
|
+
if pinned != __version__:
|
|
50
|
+
return (
|
|
51
|
+
f"this is orca-agent-workflow {__version__}, but the project pins {pinned}; "
|
|
52
|
+
"run it through python3 .agents/workflow.py"
|
|
53
|
+
)
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def main(argv: list[str] | None = None) -> int:
|
|
58
|
+
for stream in (sys.stdout, sys.stderr):
|
|
59
|
+
# Windows pipes use the ANSI code page; printing must never fail a finished launch.
|
|
60
|
+
if hasattr(stream, "reconfigure"):
|
|
61
|
+
stream.reconfigure(errors="replace")
|
|
62
|
+
argv = sys.argv[1:] if argv is None else argv
|
|
63
|
+
if not argv or argv[0] in ("-h", "--help"):
|
|
64
|
+
print(usage())
|
|
65
|
+
return 0 if argv else 2
|
|
66
|
+
if argv[0] == "--version":
|
|
67
|
+
print(__version__)
|
|
68
|
+
return 0
|
|
69
|
+
if argv[0] not in COMMANDS:
|
|
70
|
+
print(usage(), file=sys.stderr)
|
|
71
|
+
return 2
|
|
72
|
+
if argv[0] not in UNPINNED:
|
|
73
|
+
problem = pin_problem()
|
|
74
|
+
if problem:
|
|
75
|
+
print(f"orca-agent-workflow: {problem}", file=sys.stderr)
|
|
76
|
+
return 1
|
|
77
|
+
module = importlib.import_module("orca_agent_workflow." + COMMANDS[argv[0]][0])
|
|
78
|
+
if module.__name__.endswith(".start"):
|
|
79
|
+
sys.argv = ["orca-agent-workflow", *argv] # start and status share one parser
|
|
80
|
+
else:
|
|
81
|
+
sys.argv = [f"orca-agent-workflow {argv[0]}", *argv[1:]]
|
|
82
|
+
result = module.main()
|
|
83
|
+
return result if isinstance(result, int) else 0
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Read-only Codex reviewer: qualification probe and confined review runs.
|
|
3
|
+
|
|
4
|
+
``qualify`` proves, on the installed Codex CLI, that the review permission profile
|
|
5
|
+
denies reads outside the review folder (home, the checkout, /tmp, $TMPDIR), denies
|
|
6
|
+
all writes and denies network. ``run`` refuses unless a passing qualification
|
|
7
|
+
matches the current Codex binary, then reviews frozen copies of exactly the inputs a
|
|
8
|
+
reviewer manifest lists. Evidence is local and operator-controlled.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
import re
|
|
17
|
+
import shutil
|
|
18
|
+
import shlex
|
|
19
|
+
import subprocess
|
|
20
|
+
import tempfile
|
|
21
|
+
import time
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import Any
|
|
24
|
+
|
|
25
|
+
from orca_agent_workflow import task_scope
|
|
26
|
+
|
|
27
|
+
CACHE = Path.home() / ".cache/orca-agent-workflow/codex-review"
|
|
28
|
+
QUALIFICATION = Path(".tmp/agent-qualification/codex-reviewer.json")
|
|
29
|
+
WINDOWS_UNSUPPORTED = (
|
|
30
|
+
"Codex review qualification is not supported on Windows yet: its probes target the "
|
|
31
|
+
"macOS/Linux sandbox. Use the Claude reviewer profile on Windows."
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def require_posix() -> None:
|
|
36
|
+
if task_scope.WINDOWS:
|
|
37
|
+
raise ValueError(WINDOWS_UNSUPPORTED)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def codex_binary() -> Path:
|
|
41
|
+
found = shutil.which("codex")
|
|
42
|
+
if not found:
|
|
43
|
+
raise ValueError("Codex CLI is not installed")
|
|
44
|
+
return Path(found).resolve(strict=True)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def install_root(binary: Path) -> Path:
|
|
48
|
+
"""The Codex version folder (for example .../Caskroom/codex/0.166.0), never a whole prefix."""
|
|
49
|
+
root = binary.parent.parent if binary.parent.name == "bin" else binary.parent
|
|
50
|
+
if not re.fullmatch(r"\d+(?:\.\d+)+", root.name):
|
|
51
|
+
raise ValueError(
|
|
52
|
+
f"Unsupported Codex install layout ({binary}); the read grant would be {root}, "
|
|
53
|
+
"not a versioned install folder"
|
|
54
|
+
)
|
|
55
|
+
return root
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def profile_args(review: Path, binary: Path) -> list[str]:
|
|
59
|
+
"""Named Codex permission profile: system basics, the Codex install and one review folder."""
|
|
60
|
+
filesystem = {
|
|
61
|
+
":minimal": "read",
|
|
62
|
+
install_root(binary).as_posix(): "read",
|
|
63
|
+
review.as_posix(): "read",
|
|
64
|
+
"/tmp": "none",
|
|
65
|
+
"/private/tmp": "none",
|
|
66
|
+
"/var/folders": "none",
|
|
67
|
+
"/private/var/folders": "none",
|
|
68
|
+
}
|
|
69
|
+
entries = ", ".join(f"{json.dumps(k)}={json.dumps(v)}" for k, v in filesystem.items())
|
|
70
|
+
return [
|
|
71
|
+
"-c",
|
|
72
|
+
'default_permissions="review"',
|
|
73
|
+
"-c",
|
|
74
|
+
f"permissions.review.filesystem={{{entries}}}",
|
|
75
|
+
"-c",
|
|
76
|
+
"permissions.review.network={enabled=false}",
|
|
77
|
+
"-c",
|
|
78
|
+
'web_search="disabled"',
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def profile_digest(binary: Path) -> str:
|
|
83
|
+
"""Binds a qualification to the exact profile shape (review folder abstracted)."""
|
|
84
|
+
return task_scope.sha(json.dumps(profile_args(Path("/REVIEW"), binary)).encode())
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def sandboxed(review: Path, binary: Path, *command: str) -> subprocess.CompletedProcess[str]:
|
|
88
|
+
return subprocess.run(
|
|
89
|
+
[str(binary), "sandbox", *profile_args(review, binary), "--", *command],
|
|
90
|
+
cwd=review,
|
|
91
|
+
capture_output=True,
|
|
92
|
+
text=True,
|
|
93
|
+
timeout=60,
|
|
94
|
+
check=False,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def denied(result: subprocess.CompletedProcess[str]) -> bool:
|
|
99
|
+
return result.returncode != 0 and "CANARY" not in result.stdout
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def qualify(checkout: Path) -> dict[str, Any]:
|
|
103
|
+
"""Probe the profile with canaries; outputs of real-secret probes are never kept."""
|
|
104
|
+
require_posix()
|
|
105
|
+
binary = codex_binary()
|
|
106
|
+
CACHE.mkdir(parents=True, exist_ok=True)
|
|
107
|
+
review = Path(tempfile.mkdtemp(prefix="qual-", dir=CACHE)).resolve()
|
|
108
|
+
canaries = {
|
|
109
|
+
"home": CACHE / f"canary-{os.getpid()}.txt",
|
|
110
|
+
"tmp": Path(tempfile.mkstemp(prefix="codex-canary-", dir="/tmp")[1]),
|
|
111
|
+
"tmpdir": Path(tempfile.mkstemp(prefix="codex-canary-")[1]),
|
|
112
|
+
}
|
|
113
|
+
outside_write = CACHE / f"written-{os.getpid()}.txt"
|
|
114
|
+
results: dict[str, bool] = {}
|
|
115
|
+
absent: list[str] = []
|
|
116
|
+
try:
|
|
117
|
+
(review / "in.txt").write_text("REVIEW-INPUT", encoding="utf-8", newline="\n")
|
|
118
|
+
for path in canaries.values():
|
|
119
|
+
path.write_text("CANARY", encoding="utf-8", newline="\n")
|
|
120
|
+
inside = sandboxed(review, binary, "/bin/cat", str(review / "in.txt"))
|
|
121
|
+
results["reads_review_folder"] = inside.returncode == 0 and "REVIEW-INPUT" in inside.stdout
|
|
122
|
+
for name, path in canaries.items():
|
|
123
|
+
results[f"denies_{name}_read"] = denied(
|
|
124
|
+
sandboxed(review, binary, "/bin/cat", str(path))
|
|
125
|
+
)
|
|
126
|
+
for name, path in (
|
|
127
|
+
("checkout", checkout / "AGENTS.md"),
|
|
128
|
+
("codex_auth", Path.home() / ".codex"),
|
|
129
|
+
("ssh", Path.home() / ".ssh"),
|
|
130
|
+
("homebrew_var", Path("/opt/homebrew/var")),
|
|
131
|
+
):
|
|
132
|
+
if not path.exists():
|
|
133
|
+
absent.append(name) # a probe of a missing path would pass vacuously
|
|
134
|
+
continue
|
|
135
|
+
probe = (
|
|
136
|
+
["/bin/ls", str(path)]
|
|
137
|
+
if path.is_dir()
|
|
138
|
+
else ["/usr/bin/head", "-c", "1", str(path)]
|
|
139
|
+
)
|
|
140
|
+
results[f"denies_{name}_read"] = sandboxed(review, binary, *probe).returncode != 0
|
|
141
|
+
inner = sandboxed(review, binary, "/bin/sh", "-c", "echo x > written.txt")
|
|
142
|
+
outer = sandboxed(
|
|
143
|
+
review, binary, "/bin/sh", "-c", f"echo x > {shlex.quote(str(outside_write))}"
|
|
144
|
+
)
|
|
145
|
+
results["denies_write"] = (
|
|
146
|
+
inner.returncode != 0
|
|
147
|
+
and outer.returncode != 0
|
|
148
|
+
and not (review / "written.txt").exists()
|
|
149
|
+
and not outside_write.exists()
|
|
150
|
+
)
|
|
151
|
+
net = sandboxed(review, binary, "/usr/bin/curl", "-sS", "-m", "5", "https://example.com")
|
|
152
|
+
# 6: cannot resolve, 7: cannot connect, 28: timed out; anything else proves nothing.
|
|
153
|
+
results["denies_network"] = net.returncode in (6, 7, 28)
|
|
154
|
+
finally:
|
|
155
|
+
shutil.rmtree(review, ignore_errors=True)
|
|
156
|
+
outside_write.unlink(missing_ok=True)
|
|
157
|
+
for path in canaries.values():
|
|
158
|
+
path.unlink(missing_ok=True)
|
|
159
|
+
version = subprocess.run(
|
|
160
|
+
[str(binary), "--version"], capture_output=True, text=True, check=False
|
|
161
|
+
).stdout.strip()
|
|
162
|
+
return {
|
|
163
|
+
"passed": all(results.values()) and "checkout" not in absent,
|
|
164
|
+
"results": results,
|
|
165
|
+
"not_present": absent,
|
|
166
|
+
"install_root": str(install_root(binary)),
|
|
167
|
+
"codex_path": str(binary),
|
|
168
|
+
"codex_sha256": task_scope.digest(binary),
|
|
169
|
+
"codex_version": version,
|
|
170
|
+
"profile_sha256": profile_digest(binary),
|
|
171
|
+
"adapter_sha256": task_scope.digest(Path(__file__).resolve()),
|
|
172
|
+
"checked_at": time.time(),
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def session_models(thread: str | None) -> set[str]:
|
|
177
|
+
"""Models Codex recorded for the thread (client-side turn context, not a server echo)."""
|
|
178
|
+
if not thread:
|
|
179
|
+
return set()
|
|
180
|
+
models = set()
|
|
181
|
+
for path in (Path.home() / ".codex/sessions").glob(f"*/*/*/*{thread}*.jsonl"):
|
|
182
|
+
for line in path.read_text(encoding="utf-8").splitlines():
|
|
183
|
+
try:
|
|
184
|
+
event = json.loads(line)
|
|
185
|
+
except ValueError:
|
|
186
|
+
continue
|
|
187
|
+
if event.get("type") == "turn_context":
|
|
188
|
+
model = event.get("payload", {}).get("model")
|
|
189
|
+
if isinstance(model, str):
|
|
190
|
+
models.add(model)
|
|
191
|
+
return models
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def run(
|
|
195
|
+
manifest: Path,
|
|
196
|
+
brief: Path,
|
|
197
|
+
policy: Path | None,
|
|
198
|
+
model: str,
|
|
199
|
+
out: Path,
|
|
200
|
+
qualification: Path,
|
|
201
|
+
) -> dict[str, Any]:
|
|
202
|
+
manifest, brief, out, qualification = (
|
|
203
|
+
path.resolve() for path in (manifest, brief, out, qualification)
|
|
204
|
+
)
|
|
205
|
+
policy = policy.resolve() if policy else None
|
|
206
|
+
require_posix()
|
|
207
|
+
binary = codex_binary()
|
|
208
|
+
qual = json.loads(qualification.read_text(encoding="utf-8"))
|
|
209
|
+
if (
|
|
210
|
+
qual.get("passed") is not True
|
|
211
|
+
or qual.get("codex_sha256") != task_scope.digest(binary)
|
|
212
|
+
or qual.get("profile_sha256") != profile_digest(binary)
|
|
213
|
+
or qual.get("adapter_sha256") != task_scope.digest(Path(__file__).resolve())
|
|
214
|
+
):
|
|
215
|
+
raise ValueError(
|
|
216
|
+
"No passing qualification for this Codex binary, profile and adapter; run qualify"
|
|
217
|
+
)
|
|
218
|
+
# Refuse a disabled profile before touching the manifest, when a policy copy is given.
|
|
219
|
+
config = task_scope.load_config(policy.read_bytes()) if policy else None
|
|
220
|
+
scope = None
|
|
221
|
+
if config is None:
|
|
222
|
+
scope = task_scope.Scope(manifest)
|
|
223
|
+
_, config = task_scope.base_config(scope.root, scope.data["policy_base"])
|
|
224
|
+
if not task_scope.enabled_profile(task_scope.roles_policy(config), "reviewer", "codex", model):
|
|
225
|
+
raise ValueError("Codex reviewer profile is not enabled in the trusted policy")
|
|
226
|
+
scope = scope or task_scope.Scope(manifest)
|
|
227
|
+
if scope.data["role"] != "reviewer":
|
|
228
|
+
raise ValueError("A reviewer manifest is required")
|
|
229
|
+
out.mkdir(parents=True, exist_ok=False)
|
|
230
|
+
CACHE.mkdir(parents=True, exist_ok=True)
|
|
231
|
+
review = Path(tempfile.mkdtemp(prefix=scope.data["head"][:12] + "-", dir=CACHE)).resolve()
|
|
232
|
+
inputs = {}
|
|
233
|
+
try:
|
|
234
|
+
for path in sorted(scope.read):
|
|
235
|
+
if path.startswith(".tmp/"):
|
|
236
|
+
with os.fdopen(scope.open_file(path), "rb") as f:
|
|
237
|
+
data = f.read()
|
|
238
|
+
else:
|
|
239
|
+
data = task_scope.git_bytes(
|
|
240
|
+
scope.root, "cat-file", "blob", scope.data["head"] + ":" + path
|
|
241
|
+
)
|
|
242
|
+
target = review / path
|
|
243
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
244
|
+
target.write_bytes(data)
|
|
245
|
+
inputs[path] = task_scope.sha(data)
|
|
246
|
+
prompt = (
|
|
247
|
+
brief.read_text(encoding="utf-8")
|
|
248
|
+
+ "\n\nEvery readable path is copied into your current directory under the same"
|
|
249
|
+
" relative path. Other paths are blocked by the sandbox. Reply with only the"
|
|
250
|
+
" complete review report.\n"
|
|
251
|
+
)
|
|
252
|
+
argv = [
|
|
253
|
+
str(binary),
|
|
254
|
+
"exec",
|
|
255
|
+
"-m",
|
|
256
|
+
model,
|
|
257
|
+
"--skip-git-repo-check",
|
|
258
|
+
"--ignore-user-config",
|
|
259
|
+
"--ignore-rules",
|
|
260
|
+
"--json",
|
|
261
|
+
*profile_args(review, binary),
|
|
262
|
+
"-C",
|
|
263
|
+
str(review),
|
|
264
|
+
"-o",
|
|
265
|
+
str(out / "report.md"),
|
|
266
|
+
"-",
|
|
267
|
+
]
|
|
268
|
+
ended = None
|
|
269
|
+
with (out / "events.jsonl").open("w", encoding="utf-8", newline="\n") as events:
|
|
270
|
+
# Own exactly this child and stop it when the grant ends, as the Claude launcher does.
|
|
271
|
+
process = subprocess.Popen(
|
|
272
|
+
argv, stdin=subprocess.PIPE, stdout=events, stderr=subprocess.STDOUT, text=True
|
|
273
|
+
)
|
|
274
|
+
try:
|
|
275
|
+
assert process.stdin is not None
|
|
276
|
+
process.stdin.write(prompt)
|
|
277
|
+
process.stdin.close()
|
|
278
|
+
while process.poll() is None:
|
|
279
|
+
try:
|
|
280
|
+
scope.live()
|
|
281
|
+
except task_scope.ScopeEnded as exc:
|
|
282
|
+
ended = str(exc)
|
|
283
|
+
break
|
|
284
|
+
time.sleep(1)
|
|
285
|
+
finally:
|
|
286
|
+
# Never leave the child running, whatever ended the loop.
|
|
287
|
+
if process.poll() is None:
|
|
288
|
+
process.terminate()
|
|
289
|
+
try:
|
|
290
|
+
process.wait(timeout=5)
|
|
291
|
+
except subprocess.TimeoutExpired:
|
|
292
|
+
process.kill()
|
|
293
|
+
returncode = process.wait()
|
|
294
|
+
thread = None
|
|
295
|
+
for line in (out / "events.jsonl").read_text(encoding="utf-8").splitlines():
|
|
296
|
+
try:
|
|
297
|
+
event = json.loads(line)
|
|
298
|
+
except ValueError:
|
|
299
|
+
continue
|
|
300
|
+
if event.get("type") == "thread.started":
|
|
301
|
+
thread = event.get("thread_id")
|
|
302
|
+
changed = [p for p, h in inputs.items() if task_scope.digest(review / p) != h]
|
|
303
|
+
finally:
|
|
304
|
+
shutil.rmtree(review, ignore_errors=True)
|
|
305
|
+
models = session_models(thread)
|
|
306
|
+
receipt = {
|
|
307
|
+
"agent": "codex",
|
|
308
|
+
"requested_model": model,
|
|
309
|
+
"session_models": sorted(models),
|
|
310
|
+
"model_evidence": "codex-session-turn-context",
|
|
311
|
+
"returncode": returncode,
|
|
312
|
+
"grant_ended": ended,
|
|
313
|
+
"thread_id": thread,
|
|
314
|
+
"codex_sha256": qual["codex_sha256"],
|
|
315
|
+
"codex_version": qual["codex_version"],
|
|
316
|
+
"qualification_sha256": task_scope.digest(qualification),
|
|
317
|
+
"manifest_sha256": scope.sha,
|
|
318
|
+
"head": scope.data["head"],
|
|
319
|
+
"inputs": inputs,
|
|
320
|
+
"inputs_changed": changed,
|
|
321
|
+
"argv": argv[:-1],
|
|
322
|
+
}
|
|
323
|
+
task_scope.atomic_json(out / "launch.json", receipt)
|
|
324
|
+
if ended or returncode or changed or not (out / "report.md").is_file():
|
|
325
|
+
raise ValueError("Codex review did not complete cleanly; see events.jsonl and launch.json")
|
|
326
|
+
if models != {model}:
|
|
327
|
+
raise ValueError("Codex session did not record exactly the requested model")
|
|
328
|
+
scope.live()
|
|
329
|
+
return receipt
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def main() -> int:
|
|
333
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
334
|
+
parser.add_argument("action", choices=["qualify", "run"])
|
|
335
|
+
parser.add_argument("--manifest", type=Path)
|
|
336
|
+
parser.add_argument("--brief", type=Path)
|
|
337
|
+
parser.add_argument(
|
|
338
|
+
"--policy",
|
|
339
|
+
type=Path,
|
|
340
|
+
help="A saved copy of the base's .agents/workflow.json; default: the manifest's policy_base",
|
|
341
|
+
)
|
|
342
|
+
parser.add_argument("--model", default="gpt-6.1-sol")
|
|
343
|
+
parser.add_argument("--out", type=Path)
|
|
344
|
+
parser.add_argument("--qualification", type=Path, default=QUALIFICATION)
|
|
345
|
+
args = parser.parse_args()
|
|
346
|
+
if args.action == "qualify":
|
|
347
|
+
checkout = task_scope.project_root()
|
|
348
|
+
record = qualify(checkout)
|
|
349
|
+
args.qualification.parent.mkdir(parents=True, exist_ok=True)
|
|
350
|
+
task_scope.atomic_json(args.qualification, record)
|
|
351
|
+
print(json.dumps(record, indent=2))
|
|
352
|
+
return 0 if record["passed"] else 1
|
|
353
|
+
if not (args.manifest and args.brief and args.out):
|
|
354
|
+
parser.error("run needs --manifest, --brief and --out")
|
|
355
|
+
print(
|
|
356
|
+
json.dumps(
|
|
357
|
+
run(args.manifest, args.brief, args.policy, args.model, args.out, args.qualification)
|
|
358
|
+
)
|
|
359
|
+
)
|
|
360
|
+
return 0
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
if __name__ == "__main__":
|
|
364
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Inspect local prerequisites. Never launches a model or changes client settings."""
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import shutil
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from orca_agent_workflow import check_sync, task_scope
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main() -> int:
|
|
12
|
+
root = task_scope.project_folder()
|
|
13
|
+
project = task_scope.load_config((root / task_scope.CONFIG).read_bytes())["project"]
|
|
14
|
+
executables = {
|
|
15
|
+
name: bool(shutil.which(name)) for name in ("git", "orca", "claude", "codex", "docker")
|
|
16
|
+
}
|
|
17
|
+
problems = check_sync.check(root)
|
|
18
|
+
record = {
|
|
19
|
+
"python_supported": sys.version_info >= (3, 11),
|
|
20
|
+
"executables": executables,
|
|
21
|
+
"contract_valid": not problems,
|
|
22
|
+
"project_checks_configured": bool(project.get("checks")),
|
|
23
|
+
"model_calls": 0,
|
|
24
|
+
"note": "Executable presence is not qualification. Review model IDs, run local probes, and prepare the trusted gate image before real dispatch.",
|
|
25
|
+
}
|
|
26
|
+
print(json.dumps(record, indent=2))
|
|
27
|
+
return (
|
|
28
|
+
0 if record["python_supported"] and executables["git"] and record["contract_valid"] else 1
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
if __name__ == "__main__":
|
|
33
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Starter image: standard-library Python checks. Add project dependencies to this
|
|
2
|
+
# trusted image before using it for application checks. Runtime network stays off.
|
|
3
|
+
FROM python:3.11-slim-bookworm@sha256:94a8fee35252d06ab75856f15f12c7bae67b10e8a6da93c7fded82b2610926cd
|
|
4
|
+
RUN apt-get update && apt-get install -y --no-install-recommends make git \
|
|
5
|
+
&& rm -rf /var/lib/apt/lists/* \
|
|
6
|
+
&& useradd --uid 10001 --create-home gate && mkdir /work && chown gate /work
|
|
7
|
+
ENV PYTHONSAFEPATH=1 PYTHONDONTWRITEBYTECODE=1 PIP_NO_INDEX=1
|
|
8
|
+
USER gate
|
|
9
|
+
WORKDIR /work
|