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,501 @@
1
+ #!/usr/bin/env python3
2
+ import argparse
3
+ import json
4
+ import re
5
+ import sys
6
+
7
+ from robert_agent.common import emit
8
+ from robert_agent import redaction
9
+
10
+
11
+ PUBLIC_TEXT_FIELDS = {
12
+ "body",
13
+ "title",
14
+ "summary",
15
+ "text",
16
+ "comment",
17
+ "pr_body",
18
+ "review_body",
19
+ }
20
+
21
+ EXPECTED_ACTIONS_FOR_OUTPUT = {
22
+ "local_result": set(),
23
+ "comment_analysis": {"comment"},
24
+ "new_pr": {"open_pr", "push_existing_pr"},
25
+ "update_existing_pr": {"push_existing_pr", "comment"},
26
+ "review_comment": {"comment"},
27
+ "pr_review_comment": {"comment"},
28
+ "waiting_for_user": {"comment"},
29
+ }
30
+ VALID_OPERATOR_QUESTION_KINDS = {
31
+ "clarification",
32
+ "scope_decision",
33
+ "completion_acceptance",
34
+ }
35
+ REVIEW_EVALUATION_OUTPUTS = {"update_existing_pr", "review_comment"}
36
+ VALID_REVIEW_VERDICTS = {"correct", "partially_correct", "incorrect", "unverified"}
37
+ VALID_REVIEW_ACTIONS = {"implement", "skip", "comment", "clarify"}
38
+ IMPLEMENTABLE_VERDICTS = {"correct", "partially_correct"}
39
+ VALID_VERIFICATION_STATUSES = {"passed", "failed", "skipped"}
40
+ CLASSIFICATION_RECOMMENDED_ROUTES = {
41
+ "comment-analysis",
42
+ "new-pr",
43
+ "update-existing-pr",
44
+ "review-comment",
45
+ "review-pr",
46
+ "waiting-for-user",
47
+ }
48
+ BRANCH_SLUG_RE = re.compile(r"^[a-z0-9]+(?:-[a-z0-9]+)*$")
49
+ MAX_BRANCH_SLUG_LENGTH = 60
50
+
51
+ COMMENT_MARKER_RE = re.compile(
52
+ r"<!--\s*(?:robert-comment|dd-comment)\b.*?-->",
53
+ re.I | re.S,
54
+ )
55
+ WORKSTREAM_MARKER_RE = re.compile(
56
+ r"<!--\s*(?:robert-workstream|dd-workstream)\b.*?-->",
57
+ re.I | re.S,
58
+ )
59
+
60
+
61
+ def _validate_actions(actions):
62
+ actual_types = []
63
+ for action in actions:
64
+ if not isinstance(action, dict):
65
+ return None, "planned_github_actions entries must be objects"
66
+ action_type = action.get("type")
67
+ if not isinstance(action_type, str) or not action_type:
68
+ return None, "planned_github_actions[*].type must be a non-empty string"
69
+ actual_types.append(action_type)
70
+ return actual_types, None
71
+
72
+
73
+ def _validate_used_skills(used_skills):
74
+ if not isinstance(used_skills, list):
75
+ return None, "used_skills must be a list"
76
+ for skill in used_skills:
77
+ if not isinstance(skill, str) or not skill:
78
+ return None, "used_skills entries must be non-empty strings"
79
+ return used_skills, None
80
+
81
+
82
+ def _audit_required_skills_coverage(used_skills, required_skills):
83
+ if not required_skills:
84
+ return None
85
+ used = set(used_skills or [])
86
+ missing = [skill for skill in required_skills if skill not in used]
87
+ if missing:
88
+ return f"used_skills missing required skills: {sorted(missing)}"
89
+ return None
90
+
91
+
92
+ def _string_value(action, *keys):
93
+ for key in keys:
94
+ value = action.get(key)
95
+ if isinstance(value, str) and value:
96
+ return value
97
+ return ""
98
+
99
+
100
+ def _missing_fields(action, fields):
101
+ return [field for field in fields if not _string_value(action, field)]
102
+
103
+
104
+ def _audit_publisher_requirements(actions):
105
+ for action in actions:
106
+ action_type = action.get("type")
107
+ if action_type == "comment":
108
+ missing = []
109
+ if not _string_value(action, "target_url", "url"):
110
+ missing.append("target_url")
111
+ body = _string_value(action, "body")
112
+ if not body:
113
+ missing.append("body")
114
+ if missing:
115
+ return f"comment action missing fields: {missing}"
116
+ if not COMMENT_MARKER_RE.search(body):
117
+ return "comment action body requires robert-comment idempotency marker"
118
+ continue
119
+ if action_type == "open_pr":
120
+ missing = _missing_fields(action, ["repo", "head", "base", "title", "body"])
121
+ if missing:
122
+ return f"open_pr action missing fields: {missing}"
123
+ if not WORKSTREAM_MARKER_RE.search(action["body"]):
124
+ return "open_pr action body requires robert-workstream metadata"
125
+ continue
126
+ if action_type == "push_existing_pr":
127
+ missing = _missing_fields(action, ["worktree_path", "branch"])
128
+ if missing:
129
+ return f"push_existing_pr action missing fields: {missing}"
130
+ return None
131
+
132
+
133
+ def _audit_expected_actions(output_type, actual_types):
134
+ expected_types = EXPECTED_ACTIONS_FOR_OUTPUT.get(output_type, set())
135
+ if not expected_types:
136
+ return None
137
+ if output_type == "update_existing_pr":
138
+ if "comment" not in actual_types:
139
+ return (
140
+ f"output_type {output_type} requires planned_github_actions "
141
+ "to include comment"
142
+ )
143
+ if "push_existing_pr" in actual_types:
144
+ last_push = max(
145
+ index for index, action_type in enumerate(actual_types) if action_type == "push_existing_pr"
146
+ )
147
+ if not any(
148
+ index > last_push and action_type == "comment"
149
+ for index, action_type in enumerate(actual_types)
150
+ ):
151
+ return f"output_type {output_type} requires comment after push_existing_pr"
152
+ return None
153
+ missing = sorted(expected_types.difference(actual_types))
154
+ if missing:
155
+ return (
156
+ f"output_type {output_type} requires planned_github_actions to include "
157
+ f"{missing}"
158
+ )
159
+ if output_type == "new_pr" and actual_types.index("push_existing_pr") > actual_types.index("open_pr"):
160
+ return "output_type new_pr requires push_existing_pr before open_pr"
161
+ return None
162
+
163
+
164
+ def _audit_pr_review_author_mention(result):
165
+ if result.get("output_type") != "pr_review_comment":
166
+ return None
167
+ comment_actions = [
168
+ action
169
+ for action in result.get("planned_github_actions", [])
170
+ if isinstance(action, dict) and action.get("type") == "comment"
171
+ ]
172
+ for action in comment_actions:
173
+ pr_author_login = _string_value(action, "pr_author_login")
174
+ if not pr_author_login:
175
+ return "pr_review_comment comment action requires pr_author_login"
176
+ required_mention = f"@{pr_author_login}"
177
+ if required_mention not in _string_value(action, "body"):
178
+ return f"pr_review_comment comment body must mention {required_mention}"
179
+ return None
180
+
181
+
182
+ def _audit_review_point_evaluation(result, actual_types):
183
+ output_type = result.get("output_type")
184
+ if output_type not in REVIEW_EVALUATION_OUTPUTS:
185
+ return None
186
+ evaluation = result.get("review_point_evaluation")
187
+ if not isinstance(evaluation, list) or not evaluation:
188
+ return ["missing_review_point_evaluation"]
189
+ for entry in evaluation:
190
+ if not isinstance(entry, dict):
191
+ return ["invalid_review_point_evaluation"]
192
+ for field in ("summary", "verdict", "reasoning", "action"):
193
+ if not isinstance(entry.get(field), str) or not entry.get(field):
194
+ return ["invalid_review_point_evaluation"]
195
+ if entry["verdict"] not in VALID_REVIEW_VERDICTS:
196
+ return ["invalid_review_point_evaluation"]
197
+ if entry["action"] not in VALID_REVIEW_ACTIONS:
198
+ return ["invalid_review_point_evaluation"]
199
+ if entry["action"] == "implement" and entry["verdict"] not in IMPLEMENTABLE_VERDICTS:
200
+ return ["invalid_review_point_evaluation"]
201
+ if output_type == "update_existing_pr" and "push_existing_pr" in actual_types:
202
+ if not any(entry.get("action") == "implement" for entry in evaluation):
203
+ return ["no_implemented_review_points"]
204
+ return None
205
+
206
+
207
+ def _audit_classification_recommendation(result):
208
+ if result.get("output_type") != "classification_result":
209
+ return None
210
+ recommended_route = result.get("recommended_route")
211
+ if recommended_route in (None, ""):
212
+ return None
213
+ if not isinstance(recommended_route, str):
214
+ return "classification_result recommended_route must be a string"
215
+ if recommended_route not in CLASSIFICATION_RECOMMENDED_ROUTES:
216
+ return f"classification_result recommended_route is not supported: {recommended_route}"
217
+ branch_slug = result.get("branch_slug")
218
+ if branch_slug in (None, ""):
219
+ return None
220
+ if not isinstance(branch_slug, str):
221
+ return "classification_result branch_slug must be a string"
222
+ if len(branch_slug) > MAX_BRANCH_SLUG_LENGTH or not BRANCH_SLUG_RE.fullmatch(branch_slug):
223
+ return (
224
+ "classification_result branch_slug must be lowercase ASCII kebab-case "
225
+ f"and at most {MAX_BRANCH_SLUG_LENGTH} characters"
226
+ )
227
+ return None
228
+
229
+
230
+ def _verification_policy_error(message):
231
+ return f"verification policy failed: {message}"
232
+
233
+
234
+ def _verification_required(verification_policy, actual_types):
235
+ mode = (verification_policy or {}).get("mode", "optional")
236
+ if mode == "required":
237
+ return True
238
+ if mode == "required_for_push":
239
+ return "push_existing_pr" in actual_types
240
+ return False
241
+
242
+
243
+ def _audit_verification_entry(entry, allow_skipped):
244
+ if not isinstance(entry, dict):
245
+ return "verification entries must be objects"
246
+ command = entry.get("command")
247
+ if not command:
248
+ return "verification entry command is required"
249
+ if isinstance(command, list):
250
+ if not command or not all(isinstance(item, str) and item for item in command):
251
+ return "verification entry command list must contain non-empty strings"
252
+ elif not isinstance(command, str):
253
+ return "verification entry command must be a string or string list"
254
+ status = entry.get("status")
255
+ if status not in VALID_VERIFICATION_STATUSES:
256
+ return f"verification entry status must be one of {sorted(VALID_VERIFICATION_STATUSES)}"
257
+ purpose = entry.get("purpose")
258
+ if not isinstance(purpose, str) or not purpose.strip():
259
+ return "verification entry purpose is required"
260
+ if status == "skipped" and not entry.get("skipped_reason"):
261
+ return "skipped verification entry requires skipped_reason"
262
+ if entry.get("required") is True and status == "skipped" and not allow_skipped:
263
+ return "required verification cannot be skipped for this route"
264
+ if "exit_code" in entry and not isinstance(entry.get("exit_code"), int):
265
+ return "verification entry exit_code must be an integer"
266
+ if "required" in entry and not isinstance(entry.get("required"), bool):
267
+ return "verification entry required must be a boolean"
268
+ return None
269
+
270
+
271
+ def _audit_verification_contract(result, verification_policy, actual_types):
272
+ if verification_policy is None:
273
+ return None
274
+ mode = verification_policy.get("mode", "optional")
275
+ if mode == "none":
276
+ return None
277
+ verification = result.get("verification", [])
278
+ if not isinstance(verification, list):
279
+ return _verification_policy_error("verification must be a list")
280
+ allow_skipped = bool(verification_policy.get("allow_skipped", False))
281
+ for entry in verification:
282
+ entry_error = _audit_verification_entry(entry, allow_skipped)
283
+ if entry_error:
284
+ return _verification_policy_error(entry_error)
285
+ if not _verification_required(verification_policy, actual_types):
286
+ return None
287
+ required_statuses = set(verification_policy.get("required_statuses") or ["passed"])
288
+ has_required_pass = any(
289
+ entry.get("required") is True and entry.get("status") in required_statuses
290
+ for entry in verification
291
+ )
292
+ if not has_required_pass:
293
+ return _verification_policy_error(
294
+ f"route requires a required verification entry with status in {sorted(required_statuses)}"
295
+ )
296
+ return None
297
+
298
+
299
+ def _audit_public_text(actions):
300
+ needs_redaction = False
301
+ for action in actions:
302
+ for field in PUBLIC_TEXT_FIELDS:
303
+ value = action.get(field)
304
+ if not isinstance(value, str) or not value:
305
+ continue
306
+ result = redaction.redact_text(value)
307
+ if not result["ok"]:
308
+ return "redaction_blocked"
309
+ if result.get("text") != value:
310
+ needs_redaction = True
311
+ if needs_redaction:
312
+ return "redaction_required"
313
+ return None
314
+
315
+
316
+ def _audit_operator_question(result):
317
+ question = result.get("operator_question")
318
+ if not isinstance(question, dict):
319
+ return "waiting_for_user requires operator_question"
320
+ if question.get("kind") not in VALID_OPERATOR_QUESTION_KINDS:
321
+ return "operator_question.kind is invalid"
322
+ summary = question.get("summary")
323
+ if not isinstance(summary, str) or not summary.strip() or len(summary) > 2000:
324
+ return "operator_question.summary is invalid"
325
+ choices = question.get("choices", [])
326
+ if not isinstance(choices, list) or len(choices) > 5:
327
+ return "operator_question.choices is invalid"
328
+ for choice in choices:
329
+ if not isinstance(choice, dict):
330
+ return "operator_question choices must be objects"
331
+ if not isinstance(choice.get("id"), str) or not choice["id"]:
332
+ return "operator_question choice id is required"
333
+ if not isinstance(choice.get("label"), str) or not choice["label"]:
334
+ return "operator_question choice label is required"
335
+ return None
336
+
337
+
338
+ def audit_result(
339
+ result,
340
+ allowed_github_actions,
341
+ recommended_skills=None,
342
+ required_skills=None,
343
+ expected_output=None,
344
+ verification_policy=None,
345
+ origin_type="github",
346
+ ):
347
+ if origin_type == "web":
348
+ if not result.get("consumed_work_item_event_ids"):
349
+ return {
350
+ "ok": False,
351
+ "status": "failed",
352
+ "safe_error": "consumed_work_item_event_ids must list handled events",
353
+ }
354
+ elif not result.get("consumed_event_fingerprints"):
355
+ return {
356
+ "ok": False,
357
+ "status": "failed",
358
+ "safe_error": "consumed_event_fingerprints must list handled events",
359
+ }
360
+ skill_guidance = recommended_skills if recommended_skills is not None else required_skills
361
+ if skill_guidance is not None:
362
+ used_skills, skill_error = _validate_used_skills(result.get("used_skills"))
363
+ if skill_error:
364
+ return {
365
+ "ok": False,
366
+ "status": "failed",
367
+ "safe_error": skill_error,
368
+ }
369
+ coverage_error = _audit_required_skills_coverage(used_skills, required_skills)
370
+ if coverage_error:
371
+ return {
372
+ "ok": False,
373
+ "status": "failed",
374
+ "safe_error": coverage_error,
375
+ }
376
+
377
+ allowed = set(allowed_github_actions)
378
+ actions = result.get("planned_github_actions", [])
379
+ actual_types, action_error = _validate_actions(actions)
380
+ if action_error:
381
+ return {
382
+ "ok": False,
383
+ "status": "failed",
384
+ "safe_error": action_error,
385
+ }
386
+
387
+ violations = sorted({action_type for action_type in actual_types if action_type not in allowed})
388
+ if violations:
389
+ return {
390
+ "ok": False,
391
+ "status": "policy_violation",
392
+ "violations": violations,
393
+ }
394
+ if origin_type == "web" and "comment" in actual_types:
395
+ return {
396
+ "ok": False,
397
+ "status": "policy_violation",
398
+ "violations": ["web_origin_github_action"],
399
+ }
400
+
401
+ output_type = result.get("output_type")
402
+ waiting_alternate = output_type == "waiting_for_user"
403
+ if expected_output and output_type != expected_output and not waiting_alternate:
404
+ return {
405
+ "ok": False,
406
+ "status": "failed",
407
+ "safe_error": f"expected_output {expected_output} does not match result output_type {output_type}",
408
+ }
409
+ if waiting_alternate:
410
+ if origin_type == "web" or result.get("operator_question") is not None:
411
+ question_error = _audit_operator_question(result)
412
+ if question_error:
413
+ return {
414
+ "ok": False,
415
+ "status": "failed",
416
+ "safe_error": question_error,
417
+ }
418
+ if origin_type == "github" and "comment" not in actual_types:
419
+ return {
420
+ "ok": False,
421
+ "status": "failed",
422
+ "safe_error": "GitHub waiting_for_user requires a public comment action",
423
+ }
424
+
425
+ redaction_violation = _audit_public_text(actions)
426
+ if redaction_violation:
427
+ return {
428
+ "ok": False,
429
+ "status": "policy_violation",
430
+ "violations": [redaction_violation],
431
+ }
432
+
433
+ publisher_error = _audit_publisher_requirements(actions)
434
+ if publisher_error:
435
+ return {
436
+ "ok": False,
437
+ "status": "failed",
438
+ "safe_error": publisher_error,
439
+ }
440
+
441
+ expected_action_error = (
442
+ None
443
+ if origin_type == "web" and output_type == "waiting_for_user"
444
+ else _audit_expected_actions(output_type, actual_types)
445
+ )
446
+ if expected_action_error:
447
+ return {
448
+ "ok": False,
449
+ "status": "failed",
450
+ "safe_error": expected_action_error,
451
+ }
452
+
453
+ pr_review_author_error = _audit_pr_review_author_mention(result)
454
+ if pr_review_author_error:
455
+ return {
456
+ "ok": False,
457
+ "status": "failed",
458
+ "safe_error": pr_review_author_error,
459
+ }
460
+
461
+ verification_error = _audit_verification_contract(result, verification_policy, actual_types)
462
+ if verification_error:
463
+ return {
464
+ "ok": False,
465
+ "status": "failed",
466
+ "safe_error": verification_error,
467
+ }
468
+
469
+ review_violation = _audit_review_point_evaluation(result, actual_types)
470
+ if review_violation:
471
+ return {
472
+ "ok": False,
473
+ "status": "policy_violation",
474
+ "violations": review_violation,
475
+ }
476
+
477
+ classification_error = _audit_classification_recommendation(result)
478
+ if classification_error:
479
+ return {
480
+ "ok": False,
481
+ "status": "failed",
482
+ "safe_error": classification_error,
483
+ }
484
+
485
+ return {
486
+ "ok": True,
487
+ "status": "accepted",
488
+ "planned_github_actions": actual_types,
489
+ }
490
+
491
+
492
+ def main(argv=None):
493
+ parser = argparse.ArgumentParser()
494
+ parser.add_argument("--allowed-action", action="append", default=[])
495
+ args = parser.parse_args(argv)
496
+ result = json.load(sys.stdin)
497
+ return emit(audit_result(result, args.allowed_action))
498
+
499
+
500
+ if __name__ == "__main__":
501
+ raise SystemExit(main())
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env python3
2
+ import argparse
3
+ import json
4
+ from pathlib import Path
5
+
6
+ from robert_agent.common import emit
7
+
8
+
9
+ ACCEPTED_CONTEXT_ASSOCIATIONS = {"OWNER", "MEMBER", "COLLABORATOR"}
10
+ ACCEPTED_CONTEXT_PERMISSIONS = {"admin", "maintain", "write", "triage"}
11
+
12
+
13
+ def _decision(event, status, creates_task=False, drives_execution=False):
14
+ return {
15
+ **event,
16
+ "authorization_status": status,
17
+ "creates_task": bool(creates_task),
18
+ "drives_execution": bool(drives_execution),
19
+ }
20
+
21
+
22
+ def authorize_event(event, repo_config, existing_workstreams=None, known_workstreams=None):
23
+ if known_workstreams is None:
24
+ known_workstreams = existing_workstreams
25
+ known_workstreams = set(known_workstreams or [])
26
+ trusted_actors = set(repo_config.get("trusted_actors", []))
27
+ github_account = repo_config["github_account"]
28
+ actor = event.get("actor_login")
29
+ event_type = event.get("event_type")
30
+
31
+ if event_type == "assigned" and event.get("assigned_to") == github_account:
32
+ assignment_actor = event.get("assignment_actor_login")
33
+ if not assignment_actor:
34
+ return _decision(event, "pending_authorization")
35
+ if assignment_actor in trusted_actors:
36
+ return _decision(event, "authorized_trigger", creates_task=True, drives_execution=True)
37
+ return _decision(event, "ignored_untrusted_trigger")
38
+
39
+ if actor == github_account:
40
+ return _decision(event, "context_only")
41
+
42
+ if event.get("workstream_id") in known_workstreams:
43
+ if not event.get("mentions_dd"):
44
+ return _decision(event, "ignored_context")
45
+ if actor in trusted_actors:
46
+ return _decision(event, "accepted_context", drives_execution=True)
47
+ if event.get("source_type") == "pull_request" and actor in set(event.get("review_participants") or []):
48
+ return _decision(event, "accepted_review_participant", drives_execution=True)
49
+ association = event.get("author_association")
50
+ if association in ACCEPTED_CONTEXT_ASSOCIATIONS:
51
+ return _decision(event, "accepted_context", drives_execution=True)
52
+ permission = (event.get("actor_permission") or "").lower()
53
+ if permission in ACCEPTED_CONTEXT_PERMISSIONS:
54
+ return _decision(event, "accepted_context", drives_execution=True)
55
+ if association in {None, "", "UNKNOWN"}:
56
+ return _decision(event, "pending_actor_permission")
57
+ return _decision(event, "ignored_context")
58
+
59
+ if event_type == "notification":
60
+ if event.get("trusted_trigger_found"):
61
+ return _decision(event, "authorized_trigger", creates_task=True, drives_execution=True)
62
+ if not event.get("authorization_lookup_complete"):
63
+ return _decision(event, "pending_authorization")
64
+ return _decision(event, "ignored_untrusted_trigger")
65
+
66
+ requested_review = (
67
+ event.get("requested_review_dd")
68
+ or event.get("requested_reviewer") == github_account
69
+ or event.get("requested_team") == github_account
70
+ )
71
+ if event_type == "review_request" and requested_review:
72
+ requester = event.get("requester_login") or actor
73
+ if requester in trusted_actors:
74
+ return _decision(event, "authorized_trigger", creates_task=True, drives_execution=True)
75
+ return _decision(event, "ignored_untrusted_trigger")
76
+
77
+ if event.get("mentions_dd"):
78
+ if event.get("authorization_lookup_complete") is False:
79
+ return _decision(event, "pending_authorization")
80
+ if actor in trusted_actors:
81
+ return _decision(event, "authorized_trigger", creates_task=True, drives_execution=True)
82
+ return _decision(event, "ignored_untrusted_trigger")
83
+
84
+ return _decision(event, "ignored_context")
85
+
86
+
87
+ def authorize_events(events, repo_config, existing_workstreams=None, known_workstreams=None):
88
+ return [
89
+ authorize_event(
90
+ event,
91
+ repo_config,
92
+ existing_workstreams=existing_workstreams,
93
+ known_workstreams=known_workstreams,
94
+ )
95
+ for event in events
96
+ ]
97
+
98
+
99
+ def main(argv=None):
100
+ parser = argparse.ArgumentParser()
101
+ parser.add_argument("--repo-config", required=True)
102
+ parser.add_argument("--events", required=True)
103
+ parser.add_argument("--existing-workstream", action="append", default=[])
104
+ args = parser.parse_args(argv)
105
+
106
+ repo_config = json.loads(Path(args.repo_config).read_text(encoding="utf-8"))
107
+ events = json.loads(Path(args.events).read_text(encoding="utf-8"))
108
+ decisions = authorize_events(
109
+ events,
110
+ repo_config,
111
+ existing_workstreams=set(args.existing_workstream),
112
+ )
113
+ return emit({"ok": True, "status": "authorized", "decisions": decisions})
114
+
115
+
116
+ if __name__ == "__main__":
117
+ raise SystemExit(main())