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,301 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Turn an approved spec's agent-task block into a scoped manifest and brief.
|
|
3
|
+
|
|
4
|
+
The coordinator runs this from the task checkout. It writes only under ignored
|
|
5
|
+
``.tmp/``: ``.tmp/agent-tasks/<head>-<role>/`` for the manifest and brief, and for
|
|
6
|
+
reviewers ``.tmp/agent-reviews/<head>/`` for the evidence. Every readable path is
|
|
7
|
+
listed in the brief, because scoped clients cannot list directories.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import json
|
|
14
|
+
import re
|
|
15
|
+
import subprocess
|
|
16
|
+
import time
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from orca_agent_workflow import task_scope
|
|
21
|
+
|
|
22
|
+
BLOCK = re.compile(r"^```agent-task\n(.*?)\n```$", re.MULTILINE | re.DOTALL)
|
|
23
|
+
STANDARDS = ["AGENTS.md"]
|
|
24
|
+
IMPLEMENTER_CONTEXT = [".agents/docs/roles/implementer.md"]
|
|
25
|
+
REVIEWER_CONTEXT = [
|
|
26
|
+
"CLAUDE.md",
|
|
27
|
+
".agents/skills/review-pr/SKILL.md",
|
|
28
|
+
".agents/skills/review-pr/references/reviewer.md",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def git(root: Path, *args: str) -> str:
|
|
33
|
+
return task_scope.git_bytes(root, *args).decode()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def strings(value: Any, where: str) -> list[str]:
|
|
37
|
+
if not isinstance(value, list) or not all(isinstance(v, str) and v for v in value):
|
|
38
|
+
raise ValueError(f"agent-task {where} must be a list of paths")
|
|
39
|
+
return value
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def load_block(spec: Path) -> dict[str, Any]:
|
|
43
|
+
"""Parse the single agent-task block strictly; unknown or misspelled keys are refused."""
|
|
44
|
+
text = spec.read_text(encoding="utf-8")
|
|
45
|
+
found = BLOCK.findall(text)
|
|
46
|
+
if len(found) != 1:
|
|
47
|
+
raise ValueError("The spec needs exactly one ```agent-task block")
|
|
48
|
+
block = json.loads(found[0])
|
|
49
|
+
if not isinstance(block, dict) or set(block) - {"tier", "implementer", "review"}:
|
|
50
|
+
raise ValueError("agent-task keys are tier, implementer and review")
|
|
51
|
+
if block.get("tier") not in ("light", "full"):
|
|
52
|
+
raise ValueError("agent-task needs tier light or full")
|
|
53
|
+
worker = block.get("implementer")
|
|
54
|
+
review = block.get("review", {"read": []})
|
|
55
|
+
if not isinstance(worker, dict) or set(worker) != {"read", "write", "sensitive"}:
|
|
56
|
+
raise ValueError("agent-task implementer needs exactly read, write and sensitive")
|
|
57
|
+
if not isinstance(review, dict) or set(review) != {"read"}:
|
|
58
|
+
raise ValueError("agent-task review needs exactly read")
|
|
59
|
+
for key in ("read", "write", "sensitive"):
|
|
60
|
+
strings(worker[key], f"implementer.{key}")
|
|
61
|
+
strings(review["read"], "review.read")
|
|
62
|
+
block["review"] = review
|
|
63
|
+
if worker["sensitive"]:
|
|
64
|
+
if block["tier"] != "full":
|
|
65
|
+
raise ValueError("Sensitive files require tier full")
|
|
66
|
+
lines = sensitive_section(text)
|
|
67
|
+
missing = [
|
|
68
|
+
s
|
|
69
|
+
for s in worker["sensitive"]
|
|
70
|
+
if not any(re.search(rf"`{re.escape(s)}`\W+\w+\W+\w+", line) for line in lines)
|
|
71
|
+
]
|
|
72
|
+
if missing:
|
|
73
|
+
raise ValueError("Name each sensitive file with its reason: " + ", ".join(missing))
|
|
74
|
+
return block
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def sensitive_section(text: str) -> list[str]:
|
|
78
|
+
"""Lines of the '## Sensitive files' section, up to the next heading."""
|
|
79
|
+
lines, inside = [], False
|
|
80
|
+
for line in text.splitlines():
|
|
81
|
+
if line.startswith("#"):
|
|
82
|
+
inside = bool(re.match(r"#+\s+Sensitive files\b", line))
|
|
83
|
+
continue
|
|
84
|
+
if inside:
|
|
85
|
+
lines.append(line)
|
|
86
|
+
return lines
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def require_approved(root: Path, spec: str) -> None:
|
|
90
|
+
"""The spec must be approved and committed unchanged at HEAD before it grants anything."""
|
|
91
|
+
status = re.search(r"^status:\s*(\w+)", (root / spec).read_text(encoding="utf-8"), re.MULTILINE)
|
|
92
|
+
if not status or status.group(1) not in ("approved", "implemented"):
|
|
93
|
+
raise ValueError("The spec must have status approved before planning")
|
|
94
|
+
try:
|
|
95
|
+
task_scope.git_bytes(root, "diff", "--quiet", "HEAD", "--", spec)
|
|
96
|
+
task_scope.git_bytes(root, "cat-file", "-e", f"HEAD:{spec}")
|
|
97
|
+
except subprocess.CalledProcessError as exc:
|
|
98
|
+
raise ValueError("Commit the approved spec unchanged before planning") from exc
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def unique(values: list[str]) -> list[str]:
|
|
102
|
+
return list(dict.fromkeys(values))
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def write_manifest(out: Path, data: dict[str, Any]) -> Path:
|
|
106
|
+
out.mkdir(parents=True, exist_ok=True)
|
|
107
|
+
manifest = out / "scope.json"
|
|
108
|
+
task_scope.atomic_json(manifest, data)
|
|
109
|
+
task_scope.Scope(manifest) # validate with the broker's own rules before use
|
|
110
|
+
return manifest
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def path_list(paths: list[str]) -> str:
|
|
114
|
+
return "\n".join(f"- `{p}`" for p in paths) if paths else "- (none)"
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def default_base(root: Path) -> str:
|
|
118
|
+
"""Where the implementer's trusted policy comes from: the reviewed default branch."""
|
|
119
|
+
try:
|
|
120
|
+
return git(root, "merge-base", "HEAD", "origin/HEAD").strip()
|
|
121
|
+
except subprocess.CalledProcessError:
|
|
122
|
+
raise ValueError("No origin/HEAD to trust; pass --base with a reviewed commit")
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def trusted(root: Path, base: str) -> dict[str, Any]:
|
|
126
|
+
"""Manifest fields that pin the policy to a reviewed commit."""
|
|
127
|
+
_, config = task_scope.base_config(root, base)
|
|
128
|
+
return {"policy_base": base, "sensitive_extra": config.get("sensitive_patterns", [])}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def plan_implementer(
|
|
132
|
+
root: Path, spec: str, block: dict[str, Any], hours: float, base: str | None = None
|
|
133
|
+
) -> Path:
|
|
134
|
+
head = git(root, "rev-parse", "HEAD").strip()
|
|
135
|
+
require_approved(root, spec)
|
|
136
|
+
base = base or default_base(root)
|
|
137
|
+
if not re.fullmatch(r"[0-9a-f]{40}", base):
|
|
138
|
+
raise ValueError("--base must be a full commit SHA")
|
|
139
|
+
worker = block["implementer"]
|
|
140
|
+
policy = trusted(root, base)
|
|
141
|
+
read = unique(STANDARDS + [spec] + IMPLEMENTER_CONTEXT + worker["read"])
|
|
142
|
+
data = {
|
|
143
|
+
"version": 3,
|
|
144
|
+
"root": str(root),
|
|
145
|
+
"head": head,
|
|
146
|
+
"role": "implementer",
|
|
147
|
+
"approval_reference": f"Approved spec {spec} at {head} (tier {block['tier']})",
|
|
148
|
+
"expires_at": time.time() + hours * 3600,
|
|
149
|
+
"read": read,
|
|
150
|
+
"write": worker["write"],
|
|
151
|
+
"sensitive": worker["sensitive"],
|
|
152
|
+
"commands": {},
|
|
153
|
+
"runtime_read": [],
|
|
154
|
+
"infrastructure": [],
|
|
155
|
+
**policy,
|
|
156
|
+
}
|
|
157
|
+
out = root / ".tmp/agent-tasks" / f"{head}-implementer"
|
|
158
|
+
write_manifest(out, data)
|
|
159
|
+
(out / "brief.md").write_text(
|
|
160
|
+
f"""Implement the approved spec `{spec}` at head `{head}`. Follow `AGENTS.md` and
|
|
161
|
+
`.agents/docs/roles/implementer.md`. Tier: {block['tier']}.
|
|
162
|
+
|
|
163
|
+
Your client exposes only task-scoped file tools, a scope-question tool and report. It
|
|
164
|
+
cannot list directories, so every path you may read is listed below. Read responses are
|
|
165
|
+
paged: follow next_offset until null. Read the spec completely before writing.
|
|
166
|
+
|
|
167
|
+
Readable paths:
|
|
168
|
+
{path_list(read)}
|
|
169
|
+
|
|
170
|
+
Writable paths (create or overwrite only these; existing ones are readable too):
|
|
171
|
+
{path_list(data["write"])}
|
|
172
|
+
|
|
173
|
+
Sensitive paths (gate, build or deploy inputs; change them only as the spec says, and
|
|
174
|
+
explain each change in your report):
|
|
175
|
+
{path_list(data["sensitive"])}
|
|
176
|
+
|
|
177
|
+
You cannot run commands. Report checks as not run; the coordinator runs gates. If
|
|
178
|
+
something is ambiguous, ask with task.request_scope and end your turn; on an Orca wake,
|
|
179
|
+
read replies with task.mailbox. When done, call task.report with the exact Task and
|
|
180
|
+
Dispatch IDs injected by Orca and: changed files and purpose, verification (not run),
|
|
181
|
+
and deviations, assumptions and risks.
|
|
182
|
+
""", encoding="utf-8", newline="\n"
|
|
183
|
+
)
|
|
184
|
+
return out
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def plan_reviewer(root: Path, spec: str, block: dict[str, Any], hours: float, base: str) -> Path:
|
|
188
|
+
head = git(root, "rev-parse", "HEAD").strip()
|
|
189
|
+
if not re.fullmatch(r"[0-9a-f]{40}", base):
|
|
190
|
+
raise ValueError("--base must be a full commit SHA")
|
|
191
|
+
require_approved(root, spec)
|
|
192
|
+
policy = trusted(root, base)
|
|
193
|
+
evidence = root / ".tmp/agent-reviews" / head
|
|
194
|
+
evidence.mkdir(parents=True, exist_ok=True)
|
|
195
|
+
(evidence / "base-AGENTS.md").write_text(git(root, "show", f"{base}:AGENTS.md"), encoding="utf-8", newline="\n")
|
|
196
|
+
flags = ("--no-renames", "--no-ext-diff", "--no-textconv", "--text")
|
|
197
|
+
(evidence / "full.diff").write_text(git(root, "diff", *flags, base, head), encoding="utf-8", newline="\n")
|
|
198
|
+
deleted = [
|
|
199
|
+
p
|
|
200
|
+
for p in git(
|
|
201
|
+
root, "diff", "--name-only", "-z", *flags, "--diff-filter=D", base, head
|
|
202
|
+
).split("\0")
|
|
203
|
+
if p
|
|
204
|
+
]
|
|
205
|
+
changed = [
|
|
206
|
+
p
|
|
207
|
+
for p in git(
|
|
208
|
+
root, "diff", "--name-only", "-z", *flags, "--diff-filter=d", base, head
|
|
209
|
+
).split("\0")
|
|
210
|
+
if p
|
|
211
|
+
]
|
|
212
|
+
(evidence / "changed-paths.txt").write_text("\n".join(changed + deleted) + "\n", encoding="utf-8", newline="\n")
|
|
213
|
+
patterns = task_scope.sensitive_patterns(policy["sensitive_extra"])
|
|
214
|
+
sensitive = [p for p in changed if task_scope.is_sensitive(p, patterns)] + [
|
|
215
|
+
f"{p} (deleted)" for p in deleted if task_scope.is_sensitive(p, patterns)
|
|
216
|
+
]
|
|
217
|
+
(evidence / "sensitive-paths.txt").write_text("\n".join(sensitive) + "\n", encoding="utf-8", newline="\n")
|
|
218
|
+
readable = []
|
|
219
|
+
for path in changed:
|
|
220
|
+
try:
|
|
221
|
+
task_scope.relative(path)
|
|
222
|
+
except ValueError:
|
|
223
|
+
continue # credential-pattern paths stay unreadable; the diff still shows them
|
|
224
|
+
readable.append(path)
|
|
225
|
+
rel = evidence.relative_to(root).as_posix()
|
|
226
|
+
files = sorted(f"{rel}/{p.name}" for p in evidence.iterdir() if p.is_file())
|
|
227
|
+
read = unique(
|
|
228
|
+
STANDARDS + REVIEWER_CONTEXT + [spec] + readable + block["review"]["read"] + files
|
|
229
|
+
)
|
|
230
|
+
data = {
|
|
231
|
+
"version": 3,
|
|
232
|
+
"root": str(root),
|
|
233
|
+
"head": head,
|
|
234
|
+
"role": "reviewer",
|
|
235
|
+
"approval_reference": f"Fresh review of {base}..{head} for approved spec {spec}",
|
|
236
|
+
"expires_at": time.time() + hours * 3600,
|
|
237
|
+
"read": read,
|
|
238
|
+
"write": [],
|
|
239
|
+
"sensitive": [],
|
|
240
|
+
"commands": {},
|
|
241
|
+
"runtime_read": [],
|
|
242
|
+
"infrastructure": [],
|
|
243
|
+
**policy,
|
|
244
|
+
}
|
|
245
|
+
out = root / ".tmp/agent-tasks" / f"{head}-reviewer"
|
|
246
|
+
write_manifest(out, data)
|
|
247
|
+
(out / "brief.md").write_text(
|
|
248
|
+
f"""Independently review the complete change {base}..{head} for the approved spec
|
|
249
|
+
`{spec}` (tier {block['tier']}). Do not implement changes. You are a fresh session,
|
|
250
|
+
independent of the planner and implementer.
|
|
251
|
+
|
|
252
|
+
Your client exposes only task-scoped read tools, a scope-question tool and report. It
|
|
253
|
+
cannot list directories, so every path you may read is listed below. Read responses are
|
|
254
|
+
paged: follow next_offset until null. Read `{rel}/full.diff` completely.
|
|
255
|
+
|
|
256
|
+
Sensitive files changed (examine each one's diff explicitly and name it in your report):
|
|
257
|
+
{path_list(sensitive)}
|
|
258
|
+
|
|
259
|
+
Readable paths:
|
|
260
|
+
{path_list(read)}
|
|
261
|
+
|
|
262
|
+
Return a complete report: base and head; verdict pass, changes_requested or blocked,
|
|
263
|
+
stated at the top; coverage and gaps; each finding with an ID, severity, path and line,
|
|
264
|
+
the concrete problem and whether it blocks; remaining limitations. Never certify
|
|
265
|
+
coverage you did not achieve.
|
|
266
|
+
|
|
267
|
+
If your client has `task.report`, finish with it, using the exact Task and Dispatch IDs
|
|
268
|
+
injected by Orca; ask questions with `task.request_scope`, end your turn, and read replies
|
|
269
|
+
with `task.mailbox`. Otherwise reply with the complete report as your final message.
|
|
270
|
+
""", encoding="utf-8", newline="\n"
|
|
271
|
+
)
|
|
272
|
+
return out
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def main() -> int:
|
|
276
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
277
|
+
parser.add_argument("--spec", required=True)
|
|
278
|
+
parser.add_argument("--role", required=True, choices=["implementer", "reviewer"])
|
|
279
|
+
parser.add_argument(
|
|
280
|
+
"--base",
|
|
281
|
+
help="Full reviewed base SHA; its .agents/workflow.json is the trusted policy "
|
|
282
|
+
"(required for reviewers; implementers default to the merge base with origin/HEAD)",
|
|
283
|
+
)
|
|
284
|
+
parser.add_argument("--hours", type=float, default=3.0)
|
|
285
|
+
args = parser.parse_args()
|
|
286
|
+
root = task_scope.project_root().resolve()
|
|
287
|
+
spec = args.spec
|
|
288
|
+
task_scope.relative(spec)
|
|
289
|
+
block = load_block(root / spec)
|
|
290
|
+
if args.role == "implementer":
|
|
291
|
+
out = plan_implementer(root, spec, block, args.hours, args.base)
|
|
292
|
+
else:
|
|
293
|
+
if not args.base:
|
|
294
|
+
parser.error("--base is required for reviewers")
|
|
295
|
+
out = plan_reviewer(root, spec, block, args.hours, args.base)
|
|
296
|
+
print(json.dumps({"manifest": str(out / "scope.json"), "brief": str(out / "brief.md")}))
|
|
297
|
+
return 0
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
if __name__ == "__main__":
|
|
301
|
+
raise SystemExit(main())
|