roller-agent 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.
- roller/__init__.py +31 -0
- roller/__main__.py +6 -0
- roller/actf.py +431 -0
- roller/artifacts.py +124 -0
- roller/assets/deepseek/journal.mjs +44 -0
- roller/assets/deepseek/roller.patch.yml +15 -0
- roller/assets/deepseek/runner.py +149 -0
- roller/assets/hermes/runner.py +322 -0
- roller/assets/openclaw_capture.py +32 -0
- roller/assets/openclaw_drain.mjs +21 -0
- roller/assets/opencode/journal.mjs +42 -0
- roller/assets/opencode/runner.py +203 -0
- roller/assets/pi/runner.mjs +160 -0
- roller/assets/pi/runner.py +93 -0
- roller/benches/__init__.py +73 -0
- roller/benches/base.py +306 -0
- roller/benches/grading.py +553 -0
- roller/benches/pinchbench.py +976 -0
- roller/benches/qwenclaw/__init__.py +49 -0
- roller/benches/qwenclaw/adapter.py +167 -0
- roller/benches/qwenclaw/grader_runtime.py +395 -0
- roller/benches/qwenclaw/report.py +49 -0
- roller/benches/qwenclaw/task_parser.py +181 -0
- roller/benches/qwenclaw/workspace.py +202 -0
- roller/benches/report.py +166 -0
- roller/benches/skillsbench.py +708 -0
- roller/benches/transcripts.py +102 -0
- roller/benches/wildclaw.py +569 -0
- roller/bridge_capture.py +73 -0
- roller/bundles.py +545 -0
- roller/capture.py +385 -0
- roller/capture_protocol.py +301 -0
- roller/capture_runtime.py +48 -0
- roller/capture_states.py +37 -0
- roller/claude_capture.py +185 -0
- roller/claude_code_actf.py +594 -0
- roller/cli.py +1732 -0
- roller/codex_actf.py +584 -0
- roller/codex_capture.py +99 -0
- roller/codex_tools.py +137 -0
- roller/collector.py +818 -0
- roller/compaction_sft.py +672 -0
- roller/conversation.py +432 -0
- roller/deepseek_actf.py +135 -0
- roller/harness_registry.py +61 -0
- roller/harnesses/__init__.py +29 -0
- roller/harnesses/base.py +64 -0
- roller/harnesses/bridge.py +448 -0
- roller/harnesses/claude_code.py +839 -0
- roller/harnesses/codex.py +808 -0
- roller/harnesses/config_overrides.py +100 -0
- roller/harnesses/container.py +206 -0
- roller/harnesses/deepseek.py +104 -0
- roller/harnesses/docker.py +72 -0
- roller/harnesses/gateway_ports.py +155 -0
- roller/harnesses/hermes.py +119 -0
- roller/harnesses/openclaw.py +1605 -0
- roller/harnesses/opencode.py +193 -0
- roller/harnesses/pi.py +111 -0
- roller/hermes_actf.py +147 -0
- roller/image_build.py +206 -0
- roller/integrity.py +332 -0
- roller/model_protocols.py +201 -0
- roller/models.py +169 -0
- roller/openclaw_capture.py +140 -0
- roller/openclaw_delivery.py +211 -0
- roller/openclaw_usage.py +59 -0
- roller/opencode_actf.py +305 -0
- roller/opencode_capture.py +96 -0
- roller/pi_actf.py +172 -0
- roller/response_metadata.py +89 -0
- roller/run_lock.py +297 -0
- roller/sft.py +471 -0
- roller/storage.py +53 -0
- roller/tasks.py +689 -0
- roller/thinking.py +50 -0
- roller/thinking_capabilities.py +152 -0
- roller/trajectory_audit.py +386 -0
- roller/usage.py +168 -0
- roller/version.py +1 -0
- roller/viewer/__init__.py +3 -0
- roller/viewer/app.py +722 -0
- roller/viewer/static/app.js +752 -0
- roller/viewer/static/index.html +105 -0
- roller/viewer/static/style.css +213 -0
- roller/wire_trace.py +650 -0
- roller_agent-0.2.0.dist-info/METADATA +397 -0
- roller_agent-0.2.0.dist-info/RECORD +92 -0
- roller_agent-0.2.0.dist-info/WHEEL +5 -0
- roller_agent-0.2.0.dist-info/entry_points.txt +2 -0
- roller_agent-0.2.0.dist-info/licenses/LICENSE +201 -0
- roller_agent-0.2.0.dist-info/top_level.txt +1 -0
roller/usage.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from roller.openclaw_delivery import OpenClawDeliveryTracker
|
|
8
|
+
from roller.openclaw_usage import OpenClawUsage
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
ZERO_USAGE: dict[str, int | float] = {
|
|
12
|
+
"input_tokens": 0,
|
|
13
|
+
"output_tokens": 0,
|
|
14
|
+
"cache_read_tokens": 0,
|
|
15
|
+
"cache_write_tokens": 0,
|
|
16
|
+
"total_tokens": 0,
|
|
17
|
+
"cost_usd": 0.0,
|
|
18
|
+
"request_count": 0,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _number(value: Any, default: int | float = 0) -> int | float:
|
|
23
|
+
return value if isinstance(value, (int, float)) and not isinstance(value, bool) else default
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def extract_openclaw_usage(trace_path: Path) -> dict[str, int | float]:
|
|
27
|
+
"""Sum usage blocks from raw OpenClaw assistant message events."""
|
|
28
|
+
|
|
29
|
+
totals = dict(ZERO_USAGE)
|
|
30
|
+
delivery_tracker = OpenClawDeliveryTracker()
|
|
31
|
+
if not trace_path.is_file():
|
|
32
|
+
return totals
|
|
33
|
+
with trace_path.open("r", encoding="utf-8", errors="replace") as stream:
|
|
34
|
+
for raw_line in stream:
|
|
35
|
+
try:
|
|
36
|
+
event = json.loads(raw_line)
|
|
37
|
+
except (json.JSONDecodeError, TypeError):
|
|
38
|
+
continue
|
|
39
|
+
if not isinstance(event, dict):
|
|
40
|
+
continue
|
|
41
|
+
delivery = delivery_tracker.observe(event)
|
|
42
|
+
if event.get("type") != "message":
|
|
43
|
+
continue
|
|
44
|
+
message = event.get("message")
|
|
45
|
+
if not isinstance(message, dict) or message.get("role") != "assistant":
|
|
46
|
+
continue
|
|
47
|
+
if delivery.skip_usage:
|
|
48
|
+
# CLI-only replies are counted; verified mirrors and already
|
|
49
|
+
# recorded turn totals are not additional model requests.
|
|
50
|
+
totals["cost_usd"] += delivery.additional_cost_usd
|
|
51
|
+
continue
|
|
52
|
+
usage = OpenClawUsage.parse(message.get("usage"))
|
|
53
|
+
if usage is None:
|
|
54
|
+
continue
|
|
55
|
+
totals["request_count"] += 1
|
|
56
|
+
for key, value in zip((
|
|
57
|
+
"input_tokens", "output_tokens", "cache_read_tokens",
|
|
58
|
+
"cache_write_tokens", "total_tokens",
|
|
59
|
+
), usage.counts):
|
|
60
|
+
totals[key] += value
|
|
61
|
+
totals["cost_usd"] += usage.cost_usd
|
|
62
|
+
totals["cost_usd"] = round(float(totals["cost_usd"]), 6)
|
|
63
|
+
return totals
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def extract_codex_usage(trace_path: Path) -> dict[str, int | float]:
|
|
67
|
+
"""Read cumulative token usage from a Codex native session trace."""
|
|
68
|
+
|
|
69
|
+
totals = dict(ZERO_USAGE)
|
|
70
|
+
latest: dict[str, Any] | None = None
|
|
71
|
+
if not trace_path.is_file():
|
|
72
|
+
return totals
|
|
73
|
+
with trace_path.open("r", encoding="utf-8", errors="replace") as stream:
|
|
74
|
+
for raw_line in stream:
|
|
75
|
+
try:
|
|
76
|
+
event = json.loads(raw_line)
|
|
77
|
+
except (json.JSONDecodeError, TypeError):
|
|
78
|
+
continue
|
|
79
|
+
if not isinstance(event, dict) or event.get("type") != "event_msg":
|
|
80
|
+
continue
|
|
81
|
+
payload = event.get("payload")
|
|
82
|
+
if not isinstance(payload, dict) or payload.get("type") != "token_count":
|
|
83
|
+
continue
|
|
84
|
+
info = payload.get("info")
|
|
85
|
+
if not isinstance(info, dict):
|
|
86
|
+
continue
|
|
87
|
+
last_usage = info.get("last_token_usage")
|
|
88
|
+
if isinstance(last_usage, dict) and last_usage:
|
|
89
|
+
totals["request_count"] += 1
|
|
90
|
+
cumulative = info.get("total_token_usage")
|
|
91
|
+
if isinstance(cumulative, dict):
|
|
92
|
+
latest = cumulative
|
|
93
|
+
if latest is None:
|
|
94
|
+
return totals
|
|
95
|
+
totals["input_tokens"] = _number(latest.get("input_tokens"))
|
|
96
|
+
totals["output_tokens"] = _number(latest.get("output_tokens"))
|
|
97
|
+
totals["cache_read_tokens"] = _number(latest.get("cached_input_tokens"))
|
|
98
|
+
totals["cache_write_tokens"] = _number(latest.get("cache_write_input_tokens"))
|
|
99
|
+
total_tokens = _number(latest.get("total_tokens"), -1)
|
|
100
|
+
if total_tokens == -1:
|
|
101
|
+
total_tokens = totals["input_tokens"] + totals["output_tokens"]
|
|
102
|
+
totals["total_tokens"] = total_tokens
|
|
103
|
+
return totals
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def extract_claude_code_usage(
|
|
107
|
+
trace_path: Path,
|
|
108
|
+
stream_path: Path | None = None,
|
|
109
|
+
) -> dict[str, int | float]:
|
|
110
|
+
"""Sum final per-message usage from a Claude Code native session trace."""
|
|
111
|
+
|
|
112
|
+
totals = dict(ZERO_USAGE)
|
|
113
|
+
if not trace_path.is_file():
|
|
114
|
+
return totals
|
|
115
|
+
|
|
116
|
+
usage_by_message: dict[str, dict[str, Any]] = {}
|
|
117
|
+
anonymous_usage: list[dict[str, Any]] = []
|
|
118
|
+
with trace_path.open("r", encoding="utf-8", errors="replace") as stream:
|
|
119
|
+
for raw_line in stream:
|
|
120
|
+
try:
|
|
121
|
+
event = json.loads(raw_line)
|
|
122
|
+
except (json.JSONDecodeError, TypeError):
|
|
123
|
+
continue
|
|
124
|
+
if not isinstance(event, dict) or event.get("type") != "assistant":
|
|
125
|
+
continue
|
|
126
|
+
message = event.get("message")
|
|
127
|
+
if not isinstance(message, dict):
|
|
128
|
+
continue
|
|
129
|
+
usage = message.get("usage")
|
|
130
|
+
if not isinstance(usage, dict):
|
|
131
|
+
continue
|
|
132
|
+
message_id = message.get("id")
|
|
133
|
+
if isinstance(message_id, str) and message_id:
|
|
134
|
+
usage_by_message[message_id] = usage
|
|
135
|
+
else:
|
|
136
|
+
anonymous_usage.append(usage)
|
|
137
|
+
|
|
138
|
+
usages = [*usage_by_message.values(), *anonymous_usage]
|
|
139
|
+
totals["request_count"] = len(usages)
|
|
140
|
+
for usage in usages:
|
|
141
|
+
input_tokens = _number(usage.get("input_tokens"))
|
|
142
|
+
output_tokens = _number(usage.get("output_tokens"))
|
|
143
|
+
cache_read = _number(usage.get("cache_read_input_tokens"))
|
|
144
|
+
cache_write = _number(usage.get("cache_creation_input_tokens"))
|
|
145
|
+
totals["input_tokens"] += input_tokens
|
|
146
|
+
totals["output_tokens"] += output_tokens
|
|
147
|
+
totals["cache_read_tokens"] += cache_read
|
|
148
|
+
totals["cache_write_tokens"] += cache_write
|
|
149
|
+
totals["total_tokens"] += (
|
|
150
|
+
input_tokens + output_tokens + cache_read + cache_write
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
if stream_path is not None and stream_path.is_file():
|
|
154
|
+
total_cost = 0.0
|
|
155
|
+
with stream_path.open("r", encoding="utf-8", errors="replace") as stream:
|
|
156
|
+
for raw_line in stream:
|
|
157
|
+
try:
|
|
158
|
+
event = json.loads(raw_line)
|
|
159
|
+
except (json.JSONDecodeError, TypeError):
|
|
160
|
+
continue
|
|
161
|
+
if not isinstance(event, dict) or event.get("type") != "result":
|
|
162
|
+
continue
|
|
163
|
+
cost = event.get("total_cost_usd")
|
|
164
|
+
if isinstance(cost, (int, float)) and not isinstance(cost, bool):
|
|
165
|
+
total_cost += float(cost)
|
|
166
|
+
totals["cost_usd"] = total_cost
|
|
167
|
+
totals["cost_usd"] = round(float(totals["cost_usd"]), 6)
|
|
168
|
+
return totals
|
roller/version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.0"
|