Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/test_antigravity.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,26 @@ def test_usage_sums_the_rows_that_report_it_and_skips_the_rest(tp):
None, "no_usage")


def test_usage_records_the_model_and_prices_it(tmp_path):
tp = tmp_path / "transcript.jsonl"
t = Transcript(tp)
t.prompt("test")
t._add(source="MODEL", type="PLANNER_RESPONSE", input_tokens=100, cache_read_tokens=500,
output_tokens=50, model="gemini-3.8-flash-high")
usage = trace.antigravity_session_usage(str(tp))
assert usage["model"] == "gemini-3.8-flash-high"
from tokeneconomizer.plugin import accounting
eff, priced_by = accounting.effective(usage)
assert priced_by == "model"
assert eff == 100 + 500 * 0.10 + 50 * 5.0


def test_tool_mapping_handles_lowercase_path_arguments():
name, args = trace.antigravity_tool("read_file", {"path": "/work/repo/b.py"})
assert name == "Read"
assert args == {"file_path": "/work/repo/b.py"}


def test_the_trace_conversion_feeds_the_mechanisms_and_prompts_are_counted(tp, tmp_path):
t = Transcript(tp)
t.prompt("first")
Expand Down
9 changes: 9 additions & 0 deletions tests/test_live_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,15 @@ def test_the_opencode_side_call_adds_only_the_flags_its_cli_lists(monkeypatch):
("env -u CURSOR_AGENT sed -i 's/a/b/' pkg/mod.py", ["mod.py"]),
("sudo -u bob sed -i 's/a/b/' pkg/mod.py", ["mod.py"]),
("sudo -Eu bob -- perl -pi -e 's/a/b/' src/a.rs", ["a.rs"]),
("sed -i 's/a/b/' src/kernel.cu", ["kernel.cu"]),
("sed -i 's/a/b/' src/ops.cuh", ["ops.cuh"]),
("sed -i 's/a/b/' main.zig", ["main.zig"]),
("sed -i 's/a/b/' schema.proto", ["schema.proto"]),
("sed -i 's/a/b/' query.graphql", ["query.graphql"]),
("sed -i 's/a/b/' lib/app.dart", ["app.dart"]),
("sed -i 's/a/b/' contracts/Token.sol", ["Token.sol"]),
("sed -i 's/a/b/' src/index.astro", ["index.astro"]),
("sed -i 's/a/b/' rules.cmake", ["rules.cmake"]),
("timeout 60 sed -i 's/a/b/' pkg/mod.py", ["mod.py"]),
("timeout -k 5 --signal=KILL 1m git apply fix.diff", ["(patch)"]),
("nice -n 10 sed -i 's/a/b/' x.py", ["x.py"]),
Expand Down
1 change: 1 addition & 0 deletions tokeneconomizer/loopguard/shell_edits.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# `| tee /tmp/run.txt` -- capturing output -- is not mistaken for an edit.
_SOURCE_FILE = re.compile(
r"\.(?:py|pyi|pyx|pxd|js|jsx|mjs|cjs|ts|tsx|rs|go|java|kt|kts|scala|c|cc|cpp|cxx|h|hh|hpp|"
r"cu|cuh|zig|dart|sol|proto|graphql|gql|astro|cmake|"
r"rb|php|cs|swift|m|mm|sh|bash|zsh|lua|jl|ex|exs|erl|hs|ml|clj|sql|toml|ya?ml|json|cfg|ini|"
r"conf|md|rst|html?|css|scss|vue|svelte|xml|gradle|properties|in)$", re.I)
_PYTHON = re.compile(r"(?:^|[\s/;&|(])python\d?(?:\.\d+)?\b")
Expand Down
3 changes: 3 additions & 0 deletions tokeneconomizer/pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ def weights_for(rec):
key = mid.lower()
if key in MODEL_WEIGHTS:
return MODEL_WEIGHTS[key]
base_key = re.sub(r"-(?:high|medium|low|thinking|latest)$", "", key)
if base_key in MODEL_WEIGHTS:
return MODEL_WEIGHTS[base_key]
if "claude" in key:
return _claude_weights(key)
raise ValueError(
Expand Down
5 changes: 3 additions & 2 deletions tokeneconomizer/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
copilot_session_meta, copilot_session_usage, copilot_turns,
mcp_server_of)
from .antigravity import (antigravity_prompt_count, antigravity_read,
antigravity_session_to_claude, antigravity_session_usage)
antigravity_session_to_claude, antigravity_session_usage,
antigravity_tool)
from .cursor import cursor_events_to_claude, cursor_prompt_count
from .droid import (droid_log_head, droid_prompt_count, droid_prompt_turns,
droid_safe_session_id, droid_session_calls, droid_session_header,
Expand Down Expand Up @@ -61,7 +62,7 @@
"copilot_event_calls", "copilot_mcp_servers", "copilot_prompt_count", "copilot_session_meta",
"copilot_session_usage", "copilot_turns", "mcp_server_of",
"antigravity_prompt_count", "antigravity_read", "antigravity_session_to_claude",
"antigravity_session_usage",
"antigravity_session_usage", "antigravity_tool",
"cursor_events_to_claude", "cursor_prompt_count",
"droid_log_head", "droid_prompt_count", "droid_prompt_turns", "droid_safe_session_id",
"droid_session_header", "droid_session_to_claude", "droid_session_usage", "droid_sessions",
Expand Down
22 changes: 13 additions & 9 deletions tokeneconomizer/trace/antigravity.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
_ARG_CAP = 2000 # characters of an unmapped tool's string argument that are kept

# agy tool -> (name the mechanisms read, {their argument: agy's argument names, first found})
_FILE = ("TargetFile", "AbsolutePath", "Path")
_FILE = ("TargetFile", "AbsolutePath", "Path", "file_path", "filePath", "path")
_TOOLS = {
"run_command": ("Bash", {"command": ("CommandLine",)}),
"run_command": ("Bash", {"command": ("CommandLine", "command", "cmd")}),
"view_file": ("Read", {"file_path": _FILE}),
"read_file": ("Read", {"file_path": _FILE}),
"write_file": ("Write", {"file_path": _FILE}),
Expand All @@ -49,9 +49,10 @@
"replace_file_content": ("Edit", {"file_path": _FILE}),
"multi_replace_file_content": ("Edit", {"file_path": _FILE}),
"sed_file": ("Edit", {"file_path": _FILE}),
"grep_search": ("Grep", {"pattern": ("Query",), "path": ("SearchPath",)}),
"find_by_name": ("Glob", {"pattern": ("Pattern",), "path": ("SearchDirectory",)}),
"list_dir": ("Glob", {"path": ("DirectoryPath",)}),
"grep_search": ("Grep", {"pattern": ("Query", "pattern"), "path": ("SearchPath", "path", "directory")}),
"find_by_name": ("Glob", {"pattern": ("Pattern", "pattern"), "path": ("SearchDirectory", "path", "directory")}),
"list_dir": ("Glob", {"path": ("DirectoryPath", "path", "directory")}),
"search_web": ("Grep", {"pattern": ("query", "Query")}),
}
_UI_KEYS = ("toolAction", "toolSummary", "WaitMsBeforeAsync")

Expand Down Expand Up @@ -205,11 +206,10 @@ def antigravity_session_to_claude(path, out_path):
def antigravity_session_usage(path):
"""Token breakdown over the planner rows that report usage; {} when none does. `input_tokens`
is fresh input only, as agy writes it, so cached re-reads are `cache_read_input_tokens`.
The transcript names no model, so `model` is "antigravity": an id no price table has, which
the ledger prices on its labelled fallback curve (with none it would be the Claude curve)."""
`model` is the primary model named in the planner rows (or 'antigravity' fallback when unstated)."""
totals = {"input_tokens": 0, "cache_read_input_tokens": 0, "cache_creation_input_tokens": 0,
"output_tokens": 0}
requests = 0
requests, models = 0, {}
for row in _records(path):
if row.get("type") != "PLANNER_RESPONSE":
continue
Expand All @@ -220,9 +220,13 @@ def antigravity_session_usage(path):
totals[dst] += v
seen = True
requests += seen
m = row.get("model")
if isinstance(m, str) and m.strip():
models[m.strip()] = models.get(m.strip(), 0) + 1
if not requests:
return {}
return dict(totals, requests=requests, model="antigravity")
model = max(models, key=models.get) if models else "antigravity"
return dict(totals, requests=requests, model=model)


def antigravity_prompt_count(path):
Expand Down