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
robert_agent/usage.py ADDED
@@ -0,0 +1,192 @@
1
+ """Usage and acceptance metrics helpers for Robert worker runs."""
2
+
3
+ import json
4
+ from pathlib import Path
5
+
6
+
7
+ def _as_number(value, default=0):
8
+ if isinstance(value, bool):
9
+ return default
10
+ if isinstance(value, (int, float)):
11
+ return value
12
+ try:
13
+ return int(value)
14
+ except (TypeError, ValueError):
15
+ return default
16
+
17
+
18
+ def _usage_value(usage, *keys):
19
+ for key in keys:
20
+ value = usage.get(key)
21
+ if value is not None:
22
+ return _as_number(value)
23
+ return 0
24
+
25
+
26
+ def _first_usage_block(usage_payload):
27
+ for key in ["usage", "provider_usage", "provider_raw_usage"]:
28
+ block = usage_payload.get(key)
29
+ if isinstance(block, dict) and block:
30
+ return block
31
+ return {}
32
+
33
+
34
+ def parse_cbc_stream_json_lines(lines):
35
+ final_result = None
36
+ for line in lines:
37
+ text = line.strip()
38
+ if not text:
39
+ continue
40
+ try:
41
+ event = json.loads(text)
42
+ except ValueError:
43
+ continue
44
+ if isinstance(event, dict) and event.get("type") == "result":
45
+ final_result = event
46
+ if not final_result:
47
+ return {"usage_available": False, "source": "no_result_event"}
48
+ provider_data = final_result.get("providerData") or {}
49
+ usage = final_result.get("usage") or {}
50
+ provider_usage = provider_data.get("usage") if isinstance(provider_data, dict) else {}
51
+ provider_raw_usage = provider_data.get("rawUsage") if isinstance(provider_data, dict) else {}
52
+ total_cost = final_result.get("total_cost_usd")
53
+ available = any(
54
+ [
55
+ isinstance(usage, dict) and bool(usage),
56
+ isinstance(provider_usage, dict) and bool(provider_usage),
57
+ isinstance(provider_raw_usage, dict) and bool(provider_raw_usage),
58
+ total_cost is not None,
59
+ ]
60
+ )
61
+ return {
62
+ "usage_available": bool(available),
63
+ "source": "cbc_stream_json",
64
+ "usage": usage if isinstance(usage, dict) else {},
65
+ "provider_usage": provider_usage if isinstance(provider_usage, dict) else {},
66
+ "provider_raw_usage": provider_raw_usage if isinstance(provider_raw_usage, dict) else {},
67
+ "total_cost_usd": total_cost,
68
+ "duration_ms": final_result.get("duration_ms"),
69
+ "num_turns": final_result.get("num_turns"),
70
+ "model": final_result.get("model"),
71
+ "subtype": final_result.get("subtype"),
72
+ }
73
+
74
+
75
+ def parse_cbc_stream_json(text):
76
+ return parse_cbc_stream_json_lines(text.splitlines())
77
+
78
+
79
+ def load_usage_from_log(path):
80
+ if not path:
81
+ return {"usage_available": False, "source": "missing"}
82
+ path_obj = Path(path)
83
+ try:
84
+ text = path_obj.read_text(encoding="utf-8")
85
+ except OSError:
86
+ return {"usage_available": False, "source": "missing", "path": str(path_obj)}
87
+ result = parse_cbc_stream_json(text)
88
+ result["path"] = str(path_obj)
89
+ return result
90
+
91
+
92
+ def extract_attempt_usage(attempt_metadata):
93
+ if not isinstance(attempt_metadata, dict):
94
+ return {"usage_available": False, "source": "missing_metadata"}
95
+ usage_payload = attempt_metadata.get("usage")
96
+ if isinstance(usage_payload, dict):
97
+ return usage_payload
98
+ dispatch = attempt_metadata.get("dispatch") or {}
99
+ return load_usage_from_log(dispatch.get("stdout_path"))
100
+
101
+
102
+ def _result_counts(conn):
103
+ accepted = conn.execute(
104
+ """
105
+ SELECT COUNT(*)
106
+ FROM worker_results
107
+ WHERE json_extract(metadata_json, '$.audit.status') = 'accepted'
108
+ """
109
+ ).fetchone()[0]
110
+ rejected = conn.execute(
111
+ """
112
+ SELECT COUNT(*)
113
+ FROM worker_results
114
+ WHERE json_extract(metadata_json, '$.audit.status') IN ('failed', 'policy_violation')
115
+ """
116
+ ).fetchone()[0]
117
+ return accepted, rejected
118
+
119
+
120
+ def _action_counts(conn):
121
+ published = conn.execute(
122
+ "SELECT COUNT(*) FROM github_actions WHERE publish_status = 'published'"
123
+ ).fetchone()[0]
124
+ failed = conn.execute(
125
+ """
126
+ SELECT COUNT(*)
127
+ FROM github_actions
128
+ WHERE json_extract(metadata_json, '$.publish.status') = 'publish_failed'
129
+ """
130
+ ).fetchone()[0]
131
+ deduplicated = conn.execute(
132
+ """
133
+ SELECT COUNT(*)
134
+ FROM github_actions
135
+ WHERE json_extract(metadata_json, '$.publish.deduplicated') = 1
136
+ """
137
+ ).fetchone()[0]
138
+ return published, failed, deduplicated
139
+
140
+
141
+ def _add_usage_totals(totals, usage_payload):
142
+ if not isinstance(usage_payload, dict) or not usage_payload.get("usage_available"):
143
+ return False
144
+ block = _first_usage_block(usage_payload)
145
+ totals["total_input_tokens"] += _usage_value(block, "input_tokens", "inputTokens")
146
+ totals["total_output_tokens"] += _usage_value(block, "output_tokens", "outputTokens")
147
+ totals["total_cache_creation_input_tokens"] += _usage_value(
148
+ block,
149
+ "cache_creation_input_tokens",
150
+ "cacheCreationInputTokens",
151
+ )
152
+ totals["total_cache_read_input_tokens"] += _usage_value(
153
+ block,
154
+ "cache_read_input_tokens",
155
+ "cacheReadInputTokens",
156
+ )
157
+ cost = usage_payload.get("total_cost_usd")
158
+ if isinstance(cost, (int, float)):
159
+ totals["total_cost_usd"] += float(cost)
160
+ return True
161
+
162
+
163
+ def summarize_acceptance_metrics(conn):
164
+ accepted_results, rejected_results = _result_counts(conn)
165
+ published_actions, publish_failed_actions, deduplicated_actions = _action_counts(conn)
166
+ totals = {
167
+ "total_input_tokens": 0,
168
+ "total_output_tokens": 0,
169
+ "total_cache_creation_input_tokens": 0,
170
+ "total_cache_read_input_tokens": 0,
171
+ "total_cost_usd": 0.0,
172
+ }
173
+ usage_available = False
174
+ for row in conn.execute("SELECT metadata_json FROM worker_results"):
175
+ try:
176
+ metadata = json.loads(row[0] or "{}")
177
+ except ValueError:
178
+ metadata = {}
179
+ usage_available = _add_usage_totals(totals, metadata.get("usage")) or usage_available
180
+ result_total = accepted_results + rejected_results
181
+ publish_total = published_actions + publish_failed_actions
182
+ return {
183
+ "accepted_results": accepted_results,
184
+ "rejected_results": rejected_results,
185
+ "published_actions": published_actions,
186
+ "publish_failed_actions": publish_failed_actions,
187
+ "deduplicated_actions": deduplicated_actions,
188
+ "accepted_result_rate": accepted_results / result_total if result_total else 0.0,
189
+ "publish_success_rate": published_actions / publish_total if publish_total else 0.0,
190
+ "usage_available": usage_available,
191
+ **totals,
192
+ }