robert-github-agent 0.1.0b1__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.
Files changed (111) hide show
  1. robert_agent/__init__.py +1 -0
  2. robert_agent/acceptance.py +394 -0
  3. robert_agent/acceptance_suite.py +287 -0
  4. robert_agent/audit_result.py +501 -0
  5. robert_agent/authorize.py +117 -0
  6. robert_agent/board.py +538 -0
  7. robert_agent/chat_status.py +338 -0
  8. robert_agent/cli/__init__.py +1 -0
  9. robert_agent/cli/exit_codes.py +5 -0
  10. robert_agent/cli/main.py +535 -0
  11. robert_agent/cli/output.py +20 -0
  12. robert_agent/common.py +6 -0
  13. robert_agent/controlled_e2e_acceptance.py +394 -0
  14. robert_agent/daemon.py +607 -0
  15. robert_agent/daemon_state.py +319 -0
  16. robert_agent/diagnostics.py +119 -0
  17. robert_agent/discover.py +775 -0
  18. robert_agent/dispatch.py +217 -0
  19. robert_agent/doctor.py +94 -0
  20. robert_agent/github_api.py +12 -0
  21. robert_agent/init_config.py +126 -0
  22. robert_agent/integrations/__init__.py +1 -0
  23. robert_agent/integrations/openclaw.py +285 -0
  24. robert_agent/live_discovery_acceptance.py +70 -0
  25. robert_agent/live_worker_acceptance.py +363 -0
  26. robert_agent/live_worktree_acceptance.py +344 -0
  27. robert_agent/loop_engine.py +285 -0
  28. robert_agent/memory_curator.py +105 -0
  29. robert_agent/migrate.py +157 -0
  30. robert_agent/notify.py +74 -0
  31. robert_agent/paths.py +16 -0
  32. robert_agent/production_write_canary.py +254 -0
  33. robert_agent/project_memory.py +503 -0
  34. robert_agent/publish.py +743 -0
  35. robert_agent/publish_dedupe_acceptance.py +270 -0
  36. robert_agent/redaction.py +41 -0
  37. robert_agent/render_prompt.py +544 -0
  38. robert_agent/resource_files.py +8 -0
  39. robert_agent/resources/__init__.py +1 -0
  40. robert_agent/resources/acceptance-matrix.md +120 -0
  41. robert_agent/resources/classifier.md +19 -0
  42. robert_agent/resources/command-matrix.md +38 -0
  43. robert_agent/resources/config.example.yml +20 -0
  44. robert_agent/resources/db/migrations/001_legacy_dd_to_robert.sql +14 -0
  45. robert_agent/resources/db/schema.sql +479 -0
  46. robert_agent/resources/failure-modes.md +36 -0
  47. robert_agent/resources/fixtures/actor-permission.json +1 -0
  48. robert_agent/resources/fixtures/discovery.json +1 -0
  49. robert_agent/resources/fixtures/redaction.json +1 -0
  50. robert_agent/resources/fixtures/review-followup.json +1 -0
  51. robert_agent/resources/fixtures/worker-results.json +1 -0
  52. robert_agent/resources/fixtures/workstreams.json +1 -0
  53. robert_agent/resources/github-events.md +77 -0
  54. robert_agent/resources/kanban-control.md +165 -0
  55. robert_agent/resources/redaction.md +29 -0
  56. robert_agent/resources/result-contract.md +56 -0
  57. robert_agent/resources/routes.yml +82 -0
  58. robert_agent/resources/schemas/config.schema.json +123 -0
  59. robert_agent/resources/schemas/event.schema.json +18 -0
  60. robert_agent/resources/schemas/result.schema.json +99 -0
  61. robert_agent/resources/schemas/route.schema.json +23 -0
  62. robert_agent/resources/schemas/snapshot.schema.json +17 -0
  63. robert_agent/resources/schemas/task.schema.json +15 -0
  64. robert_agent/resources/trust-model.md +16 -0
  65. robert_agent/resources/worker-prompt.md +121 -0
  66. robert_agent/resources/worker-protocol.md +47 -0
  67. robert_agent/resources/workflow.yml +50 -0
  68. robert_agent/resources/workstream-model.md +17 -0
  69. robert_agent/route.py +232 -0
  70. robert_agent/route_config.py +64 -0
  71. robert_agent/run_once.py +5375 -0
  72. robert_agent/runtime_knowledge.py +392 -0
  73. robert_agent/service.py +161 -0
  74. robert_agent/skills.py +28 -0
  75. robert_agent/status.py +1051 -0
  76. robert_agent/storage.py +376 -0
  77. robert_agent/summarize.py +100 -0
  78. robert_agent/supervise.py +72 -0
  79. robert_agent/usage.py +192 -0
  80. robert_agent/validate_config.py +616 -0
  81. robert_agent/wakeup.py +261 -0
  82. robert_agent/web.py +2893 -0
  83. robert_agent/web_assets/board.css +255 -0
  84. robert_agent/web_assets/board.html +165 -0
  85. robert_agent/web_assets/board.js +660 -0
  86. robert_agent/web_assets/github-shell.css +122 -0
  87. robert_agent/web_assets/index.html +103 -0
  88. robert_agent/web_assets/operations.css +168 -0
  89. robert_agent/web_assets/workbench.css +131 -0
  90. robert_agent/web_assets/workbench.js +581 -0
  91. robert_agent/work_items.py +1016 -0
  92. robert_agent/workbench.py +701 -0
  93. robert_agent/worker/__init__.py +1 -0
  94. robert_agent/worker/heartbeat.py +190 -0
  95. robert_agent/worker/result.py +321 -0
  96. robert_agent/worker/snapshot.py +98 -0
  97. robert_agent/worker_adapters/__init__.py +138 -0
  98. robert_agent/worker_adapters/cbc.py +68 -0
  99. robert_agent/worker_adapters/codex.py +56 -0
  100. robert_agent/worker_adapters/command.py +33 -0
  101. robert_agent/worker_adapters/tcodex.py +56 -0
  102. robert_agent/worker_heartbeat.py +6 -0
  103. robert_agent/worker_result.py +6 -0
  104. robert_agent/worker_snapshot.py +6 -0
  105. robert_agent/workstream.py +55 -0
  106. robert_agent/worktree.py +297 -0
  107. robert_github_agent-0.1.0b1.dist-info/METADATA +217 -0
  108. robert_github_agent-0.1.0b1.dist-info/RECORD +111 -0
  109. robert_github_agent-0.1.0b1.dist-info/WHEEL +4 -0
  110. robert_github_agent-0.1.0b1.dist-info/entry_points.txt +2 -0
  111. robert_github_agent-0.1.0b1.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0b1"
@@ -0,0 +1,394 @@
1
+ #!/usr/bin/env python3
2
+ import argparse
3
+ import re
4
+ from pathlib import Path
5
+ import shlex
6
+ import shutil
7
+ import sqlite3
8
+ import subprocess
9
+ import sys
10
+
11
+ from robert_agent.common import emit
12
+ from robert_agent import validate_config
13
+ from robert_agent.resource_files import resource
14
+
15
+
16
+ AGENT_ROOT = Path(__file__).resolve().parent
17
+
18
+
19
+ def _gate(gate_id, status, summary, next_action=None, evidence=None):
20
+ gate = {
21
+ "id": gate_id,
22
+ "status": status,
23
+ "summary": summary,
24
+ }
25
+ if next_action:
26
+ gate["next_action"] = next_action
27
+ if evidence is not None:
28
+ gate["evidence"] = evidence
29
+ return gate
30
+
31
+
32
+ def _status(gates):
33
+ statuses = {gate["status"] for gate in gates}
34
+ if "failed" in statuses:
35
+ return "blocked"
36
+ if "skipped" in statuses:
37
+ return "incomplete"
38
+ return "ready"
39
+
40
+
41
+ def _next_actions(gates):
42
+ actions = []
43
+ for gate in gates:
44
+ action = gate.get("next_action")
45
+ if action and action not in actions:
46
+ actions.append(action)
47
+ return actions
48
+
49
+
50
+ def _command_path(command_exists, command):
51
+ value = command_exists(command)
52
+ return str(value) if value else ""
53
+
54
+
55
+ def _config_next_action(config_path, safe_error):
56
+ if "No such file or directory" in safe_error:
57
+ script_path = AGENT_ROOT / "init_config.py"
58
+ config_path = Path(config_path).expanduser().resolve()
59
+ return (
60
+ f"{shlex.quote(sys.executable)} -B "
61
+ f"{shlex.quote(str(script_path))} "
62
+ f"--config {shlex.quote(str(config_path))}"
63
+ )
64
+ if "placeholder values" in safe_error:
65
+ return f"Replace placeholder values in {Path(config_path).expanduser().resolve()}"
66
+ if "data_dir is not a directory" in safe_error:
67
+ return f"Set data_dir to a directory path in {Path(config_path).expanduser().resolve()}"
68
+ if "database must not be empty" in safe_error or "database must be a filename" in safe_error:
69
+ return f"Set database to a SQLite filename in {Path(config_path).expanduser().resolve()}"
70
+ if "python_bin must not be empty" in safe_error:
71
+ return f"Set python_bin to python3 or an absolute Python executable in {Path(config_path).expanduser().resolve()}"
72
+ if (
73
+ "workers" in safe_error
74
+ or "worker_agent must not be empty" in safe_error
75
+ or "unsupported worker_agent" in safe_error
76
+ ):
77
+ return f"Fix the named worker definitions in {Path(config_path).expanduser().resolve()}"
78
+ if "worker_command must not be empty" in safe_error:
79
+ return f"Set the worker command to an agent launcher in {Path(config_path).expanduser().resolve()}"
80
+ if "route_worker_models" in safe_error:
81
+ return (
82
+ "Set each route_worker_models entry to a known worker and optional model/effort overrides in "
83
+ f"{Path(config_path).expanduser().resolve()}"
84
+ )
85
+ for field in [
86
+ "max_concurrency",
87
+ "stale_after_minutes",
88
+ "hard_timeout_minutes",
89
+ "worker_startup_grace_seconds",
90
+ "lease_ttl_minutes",
91
+ ]:
92
+ if f"{field} must be at least 1" in safe_error:
93
+ return f"Set {field} to a positive integer in {Path(config_path).expanduser().resolve()}"
94
+ if "repo_root is not a git checkout" in safe_error:
95
+ repo_match = re.search(r"\brepos\[(\d+)\]\.repo_root\b", safe_error)
96
+ repo_index = repo_match.group(1) if repo_match else "0"
97
+ return (
98
+ f"Set repos[{repo_index}].repo_root to a real local git checkout in "
99
+ f"{Path(config_path).expanduser().resolve()}"
100
+ )
101
+ return "Fix robert config"
102
+
103
+
104
+ def _control_plane_state_gate(db_path):
105
+ db_path = Path(db_path).expanduser()
106
+ if not db_path.exists():
107
+ return _gate(
108
+ "control_plane_state",
109
+ "passed",
110
+ "control plane database has not been created yet",
111
+ evidence=str(db_path),
112
+ )
113
+ with sqlite3.connect(db_path) as conn:
114
+ prepared_attempts = conn.execute(
115
+ """
116
+ SELECT COUNT(*)
117
+ FROM attempts a
118
+ JOIN tasks t ON t.task_id = a.task_id
119
+ WHERE a.status = 'prepared'
120
+ AND t.lifecycle IN ('queued', 'running')
121
+ """
122
+ ).fetchone()[0]
123
+ running_attempts = conn.execute(
124
+ """
125
+ SELECT COUNT(*)
126
+ FROM attempts a
127
+ JOIN tasks t ON t.task_id = a.task_id
128
+ WHERE a.status IN ('running', 'stale')
129
+ AND t.lifecycle IN ('queued', 'running')
130
+ """
131
+ ).fetchone()[0]
132
+ pending_publish_actions = conn.execute(
133
+ """
134
+ SELECT COUNT(*)
135
+ FROM github_actions
136
+ WHERE audit_status = 'accepted'
137
+ AND publish_status = 'not_published'
138
+ """
139
+ ).fetchone()[0]
140
+ evidence = {
141
+ "db_path": str(db_path),
142
+ "prepared_attempts": prepared_attempts,
143
+ "running_attempts": running_attempts,
144
+ "pending_publish_actions": pending_publish_actions,
145
+ }
146
+ if prepared_attempts:
147
+ summary = (
148
+ f"{prepared_attempts} prepared attempt"
149
+ f"{'s' if prepared_attempts != 1 else ''} will be eligible for dispatch "
150
+ "on the next non-dry-run cycle"
151
+ )
152
+ summarize_path = AGENT_ROOT / "summarize.py"
153
+ return _gate(
154
+ "control_plane_state",
155
+ "passed",
156
+ summary,
157
+ (
158
+ f"Review prepared attempts before non-dry-run: {sys.executable} -B "
159
+ f"{summarize_path} --db {db_path}"
160
+ ),
161
+ evidence,
162
+ )
163
+ return _gate(
164
+ "control_plane_state",
165
+ "passed",
166
+ "control plane has no prepared attempts",
167
+ evidence=evidence,
168
+ )
169
+
170
+
171
+ def acceptance_preflight(
172
+ config_path,
173
+ skip_external=False,
174
+ command_exists=shutil.which,
175
+ run_command=subprocess.run,
176
+ ):
177
+ gates = []
178
+ matrix_path = resource("acceptance-matrix.md")
179
+ gates.append(
180
+ _gate(
181
+ "acceptance_matrix",
182
+ "passed" if matrix_path.is_file() else "failed",
183
+ "acceptance matrix is present" if matrix_path.is_file() else "acceptance matrix is missing",
184
+ None if matrix_path.is_file() else "Restore resources/acceptance-matrix.md",
185
+ str(matrix_path),
186
+ )
187
+ )
188
+
189
+ config = validate_config.validate_config(config_path, skip_external=True)
190
+ if not config["ok"]:
191
+ safe_error = config["safe_error"]
192
+ gates.append(
193
+ _gate(
194
+ "config_valid",
195
+ "failed",
196
+ safe_error,
197
+ _config_next_action(config_path, safe_error),
198
+ )
199
+ )
200
+ return {
201
+ "ok": False,
202
+ "status": "failed_config",
203
+ "gates": gates,
204
+ "next_actions": _next_actions(gates),
205
+ }
206
+
207
+ gates.append(
208
+ _gate(
209
+ "config_valid",
210
+ "passed",
211
+ "config parsed and repository entry is valid",
212
+ evidence=config["config_path"],
213
+ )
214
+ )
215
+ gates.append(_control_plane_state_gate(config["db_path"]))
216
+ multi_repo = len(config["repos"]) > 1
217
+ for repo in config["repos"]:
218
+ repo_name = repo["full_name"]
219
+ repo_root = Path(repo["repo_root"])
220
+ worktree_root = Path(repo["worktree_root"])
221
+ worktree_root_is_dir = worktree_root.is_dir()
222
+ worktree_root_exists = worktree_root.exists()
223
+ repo_checkout_gate_id = f"repo_checkout:{repo_name}" if multi_repo else "repo_checkout"
224
+ worktree_root_gate_id = f"worktree_root:{repo_name}" if multi_repo else "worktree_root"
225
+ gates.append(
226
+ _gate(
227
+ repo_checkout_gate_id,
228
+ "passed" if (repo_root / ".git").exists() else "failed",
229
+ "repo_root is a git checkout"
230
+ if (repo_root / ".git").exists()
231
+ else "repo_root is not a git checkout",
232
+ None if (repo_root / ".git").exists() else f"Provide a real local git checkout for {repo_name}",
233
+ str(repo_root),
234
+ )
235
+ )
236
+ gates.append(
237
+ _gate(
238
+ worktree_root_gate_id,
239
+ "passed" if worktree_root_is_dir else "failed",
240
+ (
241
+ "worktree_root exists"
242
+ if worktree_root_is_dir
243
+ else "worktree_root is not a directory"
244
+ if worktree_root_exists
245
+ else "worktree_root is missing"
246
+ ),
247
+ (
248
+ None
249
+ if worktree_root_is_dir
250
+ else (
251
+ f"Remove file or set repo {repo_name} worktree_root to a directory: {worktree_root}"
252
+ if multi_repo
253
+ else f"Remove file or set repos[0].worktree_root to a directory: {worktree_root}"
254
+ )
255
+ if worktree_root_exists
256
+ else f"mkdir -p {shlex.quote(str(worktree_root))}"
257
+ ),
258
+ str(worktree_root),
259
+ )
260
+ )
261
+
262
+ python_bin = config.get("python_bin", "python3")
263
+ python_path = _command_path(command_exists, python_bin)
264
+ gates.append(
265
+ _gate(
266
+ "python_bin",
267
+ "passed" if python_path else "failed",
268
+ (
269
+ f"{python_bin} Python command is available"
270
+ if python_path
271
+ else f"{python_bin} Python command is missing"
272
+ ),
273
+ None if python_path else f"Install or configure python_bin: {python_bin}",
274
+ python_path or None,
275
+ )
276
+ )
277
+
278
+ gh_path = _command_path(command_exists, "gh")
279
+ gates.append(
280
+ _gate(
281
+ "gh_cli",
282
+ "passed" if gh_path else "failed",
283
+ "gh CLI is available" if gh_path else "gh CLI is missing",
284
+ None if gh_path else "Install GitHub CLI gh",
285
+ gh_path or None,
286
+ )
287
+ )
288
+ if skip_external:
289
+ gates.append(
290
+ _gate(
291
+ "gh_auth",
292
+ "skipped",
293
+ "live GitHub auth check skipped",
294
+ "Run without --skip-external for live GitHub auth verification",
295
+ )
296
+ )
297
+ elif not gh_path:
298
+ gates.append(
299
+ _gate(
300
+ "gh_auth",
301
+ "failed",
302
+ "cannot check GitHub auth without gh CLI",
303
+ "Install GitHub CLI gh",
304
+ )
305
+ )
306
+ else:
307
+ auth = run_command(
308
+ ["gh", "auth", "status"],
309
+ stdout=subprocess.PIPE,
310
+ stderr=subprocess.PIPE,
311
+ text=True,
312
+ )
313
+ gates.append(
314
+ _gate(
315
+ "gh_auth",
316
+ "passed" if auth.returncode == 0 else "failed",
317
+ "gh authentication is valid" if auth.returncode == 0 else "gh authentication is not ready",
318
+ None if auth.returncode == 0 else "Run gh auth login",
319
+ getattr(auth, "stderr", ""),
320
+ )
321
+ )
322
+
323
+ workers = config.get("workers") or [
324
+ {
325
+ "name": "default",
326
+ **config.get("worker_agent_config", {}),
327
+ }
328
+ ]
329
+ multiple_workers = len(workers) > 1
330
+ for worker in workers:
331
+ worker_name = worker["name"]
332
+ worker_agent = worker["agent"]
333
+ worker_executable = worker["command_argv"][0]
334
+ worker_path = _command_path(command_exists, worker_executable)
335
+ gate_id = (
336
+ f"worker_command:{worker_name}"
337
+ if multiple_workers
338
+ else "worker_command"
339
+ )
340
+ summary_prefix = (
341
+ f"{worker_name} ({worker_agent}) worker command"
342
+ if multiple_workers
343
+ else f"{worker_agent} worker agent command"
344
+ )
345
+ gates.append(
346
+ _gate(
347
+ gate_id,
348
+ "passed" if worker_path else "failed",
349
+ (
350
+ f"{summary_prefix} is available"
351
+ if worker_path
352
+ else f"{summary_prefix} is missing"
353
+ ),
354
+ None
355
+ if worker_path
356
+ else (
357
+ (
358
+ f"Install or configure {worker_name} ({worker_agent}) "
359
+ f"worker command: {worker_executable}"
360
+ )
361
+ if multiple_workers
362
+ else (
363
+ f"Install or configure {worker_agent} worker agent "
364
+ f"command: {worker_executable}"
365
+ )
366
+ ),
367
+ worker_path or None,
368
+ )
369
+ )
370
+
371
+ status = _status(gates)
372
+ return {
373
+ "ok": status == "ready",
374
+ "status": status,
375
+ "gates": gates,
376
+ "next_actions": _next_actions(gates),
377
+ }
378
+
379
+
380
+ def main(argv=None):
381
+ parser = argparse.ArgumentParser()
382
+ parser.add_argument("--config", required=True)
383
+ parser.add_argument("--skip-external", action="store_true")
384
+ args = parser.parse_args(argv)
385
+ result = acceptance_preflight(args.config, skip_external=args.skip_external)
386
+ if result["status"] == "failed_config":
387
+ code = 3
388
+ else:
389
+ code = 0 if result["ok"] else 2
390
+ return emit(result, code)
391
+
392
+
393
+ if __name__ == "__main__":
394
+ raise SystemExit(main())
@@ -0,0 +1,287 @@
1
+ #!/usr/bin/env python3
2
+ import argparse
3
+ import json
4
+ import re
5
+ import subprocess
6
+ import tempfile
7
+ import time
8
+ from pathlib import Path
9
+ from urllib.parse import urlparse
10
+
11
+ from robert_agent import acceptance
12
+ from robert_agent.common import emit
13
+ from robert_agent import controlled_e2e_acceptance
14
+ from robert_agent import live_discovery_acceptance
15
+ from robert_agent import live_worker_acceptance
16
+ from robert_agent import live_worktree_acceptance
17
+ from robert_agent import production_write_canary
18
+ from robert_agent import publish_dedupe_acceptance
19
+
20
+
21
+ COMMENT_URL_RE = re.compile(r"^/([^/]+)/([^/]+)/(?:issues|pull)/[0-9]+$")
22
+
23
+
24
+ def _workspace_dir(workspace_dir):
25
+ if workspace_dir:
26
+ path = Path(workspace_dir).expanduser().resolve()
27
+ path.mkdir(parents=True, exist_ok=True)
28
+ return path
29
+ return Path(tempfile.mkdtemp(prefix="dd-acceptance-suite-")).resolve()
30
+
31
+
32
+ def _default_checks():
33
+ return {
34
+ "preflight": lambda **kwargs: acceptance.acceptance_preflight(kwargs["config_path"]),
35
+ "live_discovery": lambda **kwargs: live_discovery_acceptance.live_discovery_acceptance(
36
+ kwargs["config_path"],
37
+ limit=kwargs.get("discovery_limit", 30),
38
+ ),
39
+ "controlled_e2e": lambda **kwargs: controlled_e2e_acceptance.controlled_e2e_acceptance(
40
+ kwargs["config_path"],
41
+ workspace_dir=kwargs["workspace_dir"] / "controlled-e2e",
42
+ timeout_seconds=kwargs.get("timeout_seconds", 30),
43
+ poll_interval_seconds=kwargs.get("poll_interval_seconds", 0.2),
44
+ ),
45
+ "live_worktree": lambda **kwargs: live_worktree_acceptance.live_worktree_acceptance(
46
+ kwargs["config_path"],
47
+ workspace_dir=kwargs["workspace_dir"] / "live-worktree",
48
+ ),
49
+ "publish_dedupe": lambda **kwargs: publish_dedupe_acceptance.publish_dedupe_acceptance(
50
+ workspace_dir=kwargs["workspace_dir"] / "publish-dedupe",
51
+ ),
52
+ "live_worker": lambda **kwargs: live_worker_acceptance.live_worker_acceptance(
53
+ kwargs["config_path"],
54
+ workspace_dir=kwargs["workspace_dir"] / "live-worker",
55
+ timeout_seconds=kwargs.get("timeout_seconds", 600),
56
+ poll_interval_seconds=kwargs.get("poll_interval_seconds", 2),
57
+ ),
58
+ }
59
+
60
+
61
+ def _run_check(name, check, kwargs):
62
+ started = time.monotonic()
63
+ try:
64
+ result = check(**kwargs)
65
+ except Exception as exc:
66
+ result = {
67
+ "ok": False,
68
+ "status": "failed_exception",
69
+ "safe_error": f"{type(exc).__name__}: {exc}",
70
+ }
71
+ elapsed = time.monotonic() - started
72
+ return {
73
+ "ok": bool(result.get("ok")),
74
+ "status": result.get("status", "unknown"),
75
+ "elapsed_seconds": round(elapsed, 3),
76
+ "result": result,
77
+ }
78
+
79
+
80
+ def _command_failure(completed, fallback):
81
+ if getattr(completed, "returncode", 0) == 0:
82
+ return ""
83
+ return (getattr(completed, "stderr", "") or fallback).strip()
84
+
85
+
86
+ def _verify_production_canary_evidence(evidence_url, marker_id, run_command=subprocess.run):
87
+ parsed = urlparse(evidence_url or "")
88
+ match = COMMENT_URL_RE.match(parsed.path)
89
+ fragment = parsed.fragment or ""
90
+ if parsed.scheme != "https" or parsed.netloc != "github.com" or not match:
91
+ return {
92
+ "ok": False,
93
+ "status": "invalid_evidence_url",
94
+ "safe_error": "production canary evidence must be a GitHub issue or PR comment URL",
95
+ }
96
+ comment_match = re.fullmatch(r"issuecomment-([0-9]+)", fragment)
97
+ if not comment_match:
98
+ return {
99
+ "ok": False,
100
+ "status": "invalid_evidence_url",
101
+ "safe_error": "production canary evidence URL must include an issuecomment fragment",
102
+ }
103
+ owner, repo = match.groups()
104
+ comment_id = comment_match.group(1)
105
+ command = ["gh", "api", f"repos/{owner}/{repo}/issues/comments/{comment_id}"]
106
+ completed = run_command(command, capture_output=True, text=True)
107
+ safe_error = _command_failure(completed, "gh api comment evidence lookup failed")
108
+ if safe_error:
109
+ return {
110
+ "ok": False,
111
+ "status": "evidence_lookup_failed",
112
+ "safe_error": safe_error,
113
+ "command": command,
114
+ }
115
+ try:
116
+ comment = json.loads(getattr(completed, "stdout", "") or "{}")
117
+ except ValueError:
118
+ comment = {}
119
+ body = comment.get("body") if isinstance(comment.get("body"), str) else ""
120
+ marker = f"production-canary:{marker_id}" if marker_id else "production-canary:"
121
+ if marker not in body:
122
+ return {
123
+ "ok": False,
124
+ "status": "marker_mismatch",
125
+ "safe_error": "production canary comment does not contain the expected marker",
126
+ "command": command,
127
+ }
128
+ return {
129
+ "ok": True,
130
+ "status": "verified",
131
+ "comment_id": str(comment.get("id") or comment_id),
132
+ "comment_url": comment.get("html_url") or evidence_url,
133
+ "marker_id": marker_id,
134
+ "command": command,
135
+ }
136
+
137
+
138
+ def acceptance_suite(
139
+ config_path,
140
+ workspace_dir=None,
141
+ include_live_worker=False,
142
+ checks=None,
143
+ timeout_seconds=600,
144
+ poll_interval_seconds=2,
145
+ discovery_limit=30,
146
+ production_canary_target_url=None,
147
+ production_canary_marker_id=None,
148
+ production_canary_evidence_url=None,
149
+ production_canary_run_command=subprocess.run,
150
+ ):
151
+ workspace = _workspace_dir(workspace_dir)
152
+ checks = checks or _default_checks()
153
+ kwargs = {
154
+ "config_path": Path(config_path),
155
+ "workspace_dir": workspace,
156
+ "timeout_seconds": timeout_seconds,
157
+ "poll_interval_seconds": poll_interval_seconds,
158
+ "discovery_limit": discovery_limit,
159
+ }
160
+ ordered = [
161
+ "preflight",
162
+ "live_discovery",
163
+ "controlled_e2e",
164
+ "live_worktree",
165
+ "publish_dedupe",
166
+ ]
167
+ results = {}
168
+ for name in ordered:
169
+ results[name] = _run_check(name, checks[name], kwargs)
170
+ if include_live_worker:
171
+ results["live_worker"] = _run_check("live_worker", checks["live_worker"], kwargs)
172
+ else:
173
+ results["live_worker"] = {
174
+ "ok": None,
175
+ "status": "skipped",
176
+ "elapsed_seconds": 0,
177
+ "result": {
178
+ "ok": None,
179
+ "status": "skipped",
180
+ "safe_error": "live worker check skipped; rerun with --include-live-worker",
181
+ },
182
+ }
183
+
184
+ required_safe_checks = ordered + (["live_worker"] if include_live_worker else [])
185
+ safe_acceptance_ok = all(results[name]["ok"] for name in required_safe_checks)
186
+ failed_checks = [
187
+ name
188
+ for name in required_safe_checks
189
+ if not results[name]["ok"]
190
+ ]
191
+ production_write = {
192
+ "ok": False,
193
+ "status": "required",
194
+ "safe_error": (
195
+ "Real GitHub publication is intentionally not performed by this safe suite. "
196
+ "Run an explicitly approved production canary before claiming production write readiness."
197
+ ),
198
+ "canary_command": (
199
+ "python3 src/robert_agent/production_write_canary.py "
200
+ "--target-url <github-issue-or-pr-url> --confirm-github-write"
201
+ ),
202
+ }
203
+ if production_canary_target_url:
204
+ canary_plan = production_write_canary.production_write_canary(
205
+ production_canary_target_url,
206
+ workspace_dir=workspace / "production-write-canary",
207
+ marker_id=production_canary_marker_id,
208
+ confirm_github_write=False,
209
+ )
210
+ production_write["canary_plan"] = canary_plan
211
+ if canary_plan.get("ok"):
212
+ production_write["canary_command"] = (
213
+ "python3 src/robert_agent/production_write_canary.py "
214
+ f"--target-url {production_canary_target_url} "
215
+ f"--marker-id {canary_plan['marker_id']} "
216
+ "--confirm-github-write"
217
+ )
218
+ if production_canary_evidence_url:
219
+ canary_evidence = _verify_production_canary_evidence(
220
+ production_canary_evidence_url,
221
+ production_canary_marker_id,
222
+ run_command=production_canary_run_command,
223
+ )
224
+ production_write["evidence"] = canary_evidence
225
+ if canary_evidence.get("ok"):
226
+ production_write.update(
227
+ {
228
+ "ok": True,
229
+ "status": "verified",
230
+ "safe_error": "",
231
+ }
232
+ )
233
+ production_write_ok = bool(production_write.get("ok"))
234
+ if failed_checks:
235
+ status = "blocked"
236
+ ok = False
237
+ next_actions = [f"Fix failed safe checks: {', '.join(failed_checks)}"]
238
+ elif production_write_ok:
239
+ status = "completed"
240
+ ok = True
241
+ next_actions = []
242
+ else:
243
+ status = "incomplete"
244
+ ok = False
245
+ next_actions = ["Run an explicitly approved production GitHub write canary"]
246
+ return {
247
+ "ok": ok,
248
+ "status": status,
249
+ "safe_acceptance_ok": safe_acceptance_ok,
250
+ "workspace_dir": str(workspace),
251
+ "checks": results,
252
+ "failed_checks": failed_checks,
253
+ "production_write": production_write,
254
+ "next_actions": next_actions,
255
+ }
256
+
257
+
258
+ def main(argv=None):
259
+ parser = argparse.ArgumentParser()
260
+ parser.add_argument("--config", required=True)
261
+ parser.add_argument("--workspace-dir")
262
+ parser.add_argument("--include-live-worker", action="store_true")
263
+ parser.add_argument("--timeout-seconds", type=float, default=600)
264
+ parser.add_argument("--poll-interval-seconds", type=float, default=2)
265
+ parser.add_argument("--discovery-limit", type=int, default=30)
266
+ parser.add_argument("--production-canary-target-url")
267
+ parser.add_argument("--production-canary-marker-id")
268
+ parser.add_argument("--production-canary-evidence-url")
269
+ args = parser.parse_args(argv)
270
+ result = acceptance_suite(
271
+ args.config,
272
+ workspace_dir=args.workspace_dir,
273
+ include_live_worker=args.include_live_worker,
274
+ timeout_seconds=args.timeout_seconds,
275
+ poll_interval_seconds=args.poll_interval_seconds,
276
+ discovery_limit=args.discovery_limit,
277
+ production_canary_target_url=args.production_canary_target_url,
278
+ production_canary_marker_id=args.production_canary_marker_id,
279
+ production_canary_evidence_url=args.production_canary_evidence_url,
280
+ )
281
+ if result["status"] == "blocked":
282
+ return emit(result, 2)
283
+ return emit(result, 0)
284
+
285
+
286
+ if __name__ == "__main__":
287
+ raise SystemExit(main())