The world's first agentic reverse engineer.
wire export into supervisor _run_export()
Amruth4a2aa779fda8
diff --git a/kong/agent/supervisor.py b/kong/agent/supervisor.pyindex 34fb7f1..8c5b93e 100644--- a/kong/agent/supervisor.py+++ b/kong/agent/supervisor.py@@ -341,6 +341,7 @@ class Supervisor:def _pick_model(self, item: WorkItem, decompilation: str) -> str:"""Choose Haiku for small/simple functions, Sonnet for complex ones."""line_count = decompilation.count("\n")+ # TODO: calibrate — thresholds are initial guesses, need eval data to tune.if item.function.size <= 200 and len(item.callees) <= 2 and line_count <= 30:return HAIKU_MODELreturn SONNET_MODEL@@ -657,16 +658,64 @@ class Supervisor:def _run_export(self) -> None:"""Generate output files."""+ from kong.export.source import ExportData, export_source+ from kong.export.structured import export_json+ from kong.llm.client import TokenUsage+self._emit(Event(type=EventType.PHASE_START,phase=Phase.EXPORT,message="Starting export...",))- # TODO: export logic.output_dir = self.config.output.directoryoutput_dir.mkdir(parents=True, exist_ok=True)+ exportable_addrs = [+ addr for addr, r in self.results.items()+ if not r.skipped and not r.error+ ]+ decompilations: dict[int, str] = {}+ for addr in exportable_addrs:+ decomp = self.client.get_decompilation(addr)+ if decomp:+ decompilations[addr] = decomp++ raw_usage = getattr(self.llm_client, "usage", None) if self.llm_client else None+ token_usage = raw_usage if isinstance(raw_usage, TokenUsage) else TokenUsage()++ export_data = ExportData(+ binary_info=self.binary_info or BinaryInfo(+ arch="unknown", format="unknown", endianness="unknown",+ word_size=0, compiler="unknown", name="unknown",+ ),+ stats=self.stats,+ results=self.results,+ decompilations=decompilations,+ token_usage=token_usage,+ duration_seconds=self.stats.duration_seconds,+ )++ formats = self.config.output.formats++ if "source" in formats:+ path = export_source(export_data, output_dir / "decompiled.c")+ self._emit(Event(+ type=EventType.EXPORT_FILE,+ phase=Phase.EXPORT,+ message=f"Exported {path}",+ data={"path": str(path), "format": "source"},+ ))++ if "json" in formats:+ path = export_json(export_data, output_dir / "analysis.json")+ self._emit(Event(+ type=EventType.EXPORT_FILE,+ phase=Phase.EXPORT,+ message=f"Exported {path}",+ data={"path": str(path), "format": "json"},+ ))+self._emit(Event(type=EventType.PHASE_COMPLETE,phase=Phase.EXPORT,diff --git a/tests/test_agent_supervisor.py b/tests/test_agent_supervisor.pyindex 3290428..5d91e4b 100644--- a/tests/test_agent_supervisor.py+++ b/tests/test_agent_supervisor.py@@ -22,6 +22,7 @@ def _make_client(functions=None, binary_info=None):client.get_strings.return_value = []client.get_callers.return_value = []client.get_callees.return_value = []+ client.get_decompilation.return_value = "void stub(void) { return; }"return client@@ -240,3 +241,59 @@ class TestAnalysisStats:def test_name_rate_zero_functions(self):stats = AnalysisStats(total_functions=0)assert stats.name_rate == 0.0+++class TestSupervisorExport:+ def test_export_creates_source_file(self, tmp_path):+ funcs = [_func(0x1000, "a")]+ client = _make_client(functions=funcs)+ client.get_decompilation.return_value = "void a(void) { return; }"+ config = KongConfig(output=OutputConfig(+ directory=tmp_path / "out",+ formats=["source"],+ ))+ sup = Supervisor(client, config)+ sup.run()++ assert (tmp_path / "out" / "decompiled.c").exists()++ def test_export_creates_json_file(self, tmp_path):+ funcs = [_func(0x1000, "a")]+ client = _make_client(functions=funcs)+ client.get_decompilation.return_value = "void a(void) { return; }"+ config = KongConfig(output=OutputConfig(+ directory=tmp_path / "out",+ formats=["json"],+ ))+ sup = Supervisor(client, config)+ sup.run()++ assert (tmp_path / "out" / "analysis.json").exists()++ def test_export_emits_export_file_events(self, tmp_path):+ funcs = [_func(0x1000, "a")]+ client = _make_client(functions=funcs)+ client.get_decompilation.return_value = "void a(void) { return; }"+ config = KongConfig(output=OutputConfig(+ directory=tmp_path / "out",+ formats=["source", "json"],+ ))+ sup = Supervisor(client, config)++ events = []+ sup.on_event(events.append)+ sup.run()++ export_events = [e for e in events if e.type == EventType.EXPORT_FILE]+ assert len(export_events) == 2+ formats_emitted = {e.data["format"] for e in export_events}+ assert formats_emitted == {"source", "json"}++ def test_export_skips_ghidra_format(self, tmp_path):+ client = _make_client()+ config = KongConfig(output=OutputConfig(+ directory=tmp_path / "out",+ formats=["ghidra"],+ ))+ sup = Supervisor(client, config)+ sup.run()