Skip to content

armgit / kong

Public Imported from GitHub
0

The world's first agentic reverse engineer.

feat: add cost_tracking field to JSON export

Amruthedac7176496d
diff --git a/kong/agent/supervisor.py b/kong/agent/supervisor.py
index 6bd7663..274c888 100644
--- a/kong/agent/supervisor.py
+++ b/kong/agent/supervisor.py
@@ -766,6 +766,7 @@ class Supervisor:
decompilations=decompilations,
token_usage=token_usage,
duration_seconds=self.stats.duration_seconds,
+ provider=self.config.llm.provider,
)
formats = self.config.output.formats
diff --git a/kong/export/source.py b/kong/export/source.py
index b428c87..854b291 100644
--- a/kong/export/source.py
+++ b/kong/export/source.py
@@ -4,6 +4,7 @@ from dataclasses import dataclass
from pathlib import Path
from typing import TYPE_CHECKING
+from kong.config import LLMProvider
from kong.ghidra.types import BinaryInfo
from kong.llm.usage import TokenUsage
@@ -37,6 +38,7 @@ class ExportData:
decompilations: dict[int, str]
token_usage: TokenUsage
duration_seconds: float
+ provider: LLMProvider | None = None
def _format_header(data: ExportData) -> str:
diff --git a/kong/export/structured.py b/kong/export/structured.py
index a31114c..25e912e 100644
--- a/kong/export/structured.py
+++ b/kong/export/structured.py
@@ -4,6 +4,7 @@ import json
from pathlib import Path
from kong.agent.models import FunctionResult
+from kong.config import LLMProvider
from kong.export.source import ExportData
@@ -20,8 +21,9 @@ def _build_binary_section(data: ExportData) -> dict[str, str | int]:
}
-def _build_stats_section(data: ExportData) -> dict[str, int | float]:
+def _build_stats_section(data: ExportData) -> dict[str, int | float | bool]:
s = data.stats
+ cost_tracking = data.provider is not LLMProvider.CUSTOM if data.provider else True
return {
"total_functions": s.total_functions,
"analyzed": s.analyzed,
@@ -36,6 +38,7 @@ def _build_stats_section(data: ExportData) -> dict[str, int | float]:
"llm_calls": s.llm_calls,
"duration_seconds": data.duration_seconds,
"cost_usd": data.token_usage.total_cost_usd,
+ "cost_tracking": cost_tracking,
}
diff --git a/tests/test_export_structured.py b/tests/test_export_structured.py
index dd00d9a..f35f4df 100644
--- a/tests/test_export_structured.py
+++ b/tests/test_export_structured.py
@@ -5,8 +5,8 @@ from pathlib import Path
import pytest
-from kong.agent.models import FunctionResult
-from kong.agent.models import AnalysisStats
+from kong.agent.models import AnalysisStats, FunctionResult
+from kong.config import LLMProvider
from kong.export.source import ExportData
from kong.export.structured import export_json
from kong.ghidra.types import BinaryInfo
@@ -262,3 +262,20 @@ def test_functions_sorted_by_address(
parsed = _export_and_load(data, tmp_path)
addresses = [f["address"] for f in parsed["functions"]]
assert addresses == ["0x00001000", "0x00003000", "0x00005000"]
+
+
+class TestCostTrackingField:
+ def test_json_export_includes_cost_tracking_true(
+ self, tmp_path, binary_info, stats, token_usage, sample_results,
+ ):
+ data = _make_data(binary_info, stats, token_usage, sample_results)
+ parsed = _export_and_load(data, tmp_path)
+ assert parsed["stats"]["cost_tracking"] is True
+
+ def test_json_export_cost_tracking_false_for_custom(
+ self, tmp_path, binary_info, stats, token_usage, sample_results,
+ ):
+ data = _make_data(binary_info, stats, token_usage, sample_results)
+ data.provider = LLMProvider.CUSTOM
+ parsed = _export_and_load(data, tmp_path)
+ assert parsed["stats"]["cost_tracking"] is False