mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-08-27 14:17:10 -04:00
Adds crates/headroom-core/src/transforms/code_compressor.rs (1,882 lines): the AST-aware CodeCompressor ported to Rust on tree-sitter, with grammars for Python, JavaScript, TypeScript, Go, Rust, Java, C and C++. Parity-only, like #1153. Nothing calls it: the only references outside the module are the pub mod / pub use declarations in transforms/mod.rs, and live_zone.rs still routes SourceCode to a no-op. The pyo3 bridge is untouched and no Python source changes, so the engine is unreachable from the shipped package. #1155 wires it into live-zone dispatch. Every grammar is pinned with '=' to the exact version of the corresponding Python tree-sitter-<lang> PyPI wheel. Same version on crates.io and PyPI means the same grammar.js, hence the same generated parser.c, hence node-for-node identical ASTs — the precondition for byte-parity. A canary over 9 samples x 8 languages confirmed identical node-type and line-span trees at these pins; bumping any pin requires re-running it and re-recording the fixtures. Ships 30 recorded parity fixtures, a CodeCompressorComparator in headroom-parity, and scripts/record_code_compressor_fixtures.py. Verified byte-identical to the recorded Python output: [code_aware_compressor] total=30 matched=30 skipped=0 diffed=0 Full harness on the merge result: 227 fixtures, 182 matched, 45 skipped (cache_aligner + ccr stubs), 0 diffed, exit 0 — with kompress at 21/21 under ONNX Runtime 1.24.4 (see #2591). Also verified cargo check -p headroom-core --no-default-features passes, so the static-musl path stays intact.
41 lines
3.3 KiB
JSON
41 lines
3.3 KiB
JSON
{
|
|
"config": {
|
|
"ccr_ttl": 300,
|
|
"compress_comments": true,
|
|
"docstring_mode": "first_line",
|
|
"enable_ccr": false,
|
|
"fallback_to_kompress": false,
|
|
"language_hint": null,
|
|
"max_body_lines": 5,
|
|
"min_tokens_for_compression": 100,
|
|
"preserve_decorators": true,
|
|
"preserve_imports": true,
|
|
"preserve_signatures": true,
|
|
"preserve_type_annotations": true,
|
|
"semantic_analysis": true,
|
|
"target_compression_rate": 0.2
|
|
},
|
|
"input": "package com.example;\n\nimport java.util.List;\nimport java.util.ArrayList;\n\npublic class Processor {\n private String name;\n private int count;\n\n public Processor(String name) {\n this.name = name;\n this.count = 0;\n }\n\n @Override\n public String toString() {\n return \"Processor(\" + name + \")\";\n }\n\n public List<String> process(List<String> items) {\n List<String> results = new ArrayList<>();\n for (String item : items) {\n if (item == null || item.isEmpty()) {\n continue;\n }\n String clean = item.trim().toLowerCase();\n results.add(clean);\n this.count += 1;\n }\n return results;\n }\n}\n\n// variant 1",
|
|
"input_sha256": "5c057f7bfd56af058ab2f8745bf0242d97e3a458ce8efedae8263066c1c709a7",
|
|
"output": {
|
|
"cache_key": null,
|
|
"compressed": "package com.example;\nimport java.util.List;\nimport java.util.ArrayList;\n\npublic class Processor {\n private String name;\n private int count;\n\n public Processor(String name) {\n this.name = name;\n this.count = 0;\n }\n\n @Override\n public String toString() {\n return \"Processor(\" + name + \")\";\n }\n\n public List<String> process(List<String> items) {\n List<String> results = new ArrayList<>();\n for (String item : items) {\n if (item == null || item.isEmpty()) {\n continue;\n }\n String clean = item.trim().toLowerCase();\n results.add(clean);\n this.count += 1;\n }\n return results;\n }\n}\n\n// variant 1",
|
|
"compressed_bodies": 0,
|
|
"compressed_tokens": 183,
|
|
"compression_ratio": 1.0,
|
|
"language": "java",
|
|
"language_confidence": 1.0,
|
|
"original": "package com.example;\n\nimport java.util.List;\nimport java.util.ArrayList;\n\npublic class Processor {\n private String name;\n private int count;\n\n public Processor(String name) {\n this.name = name;\n this.count = 0;\n }\n\n @Override\n public String toString() {\n return \"Processor(\" + name + \")\";\n }\n\n public List<String> process(List<String> items) {\n List<String> results = new ArrayList<>();\n for (String item : items) {\n if (item == null || item.isEmpty()) {\n continue;\n }\n String clean = item.trim().toLowerCase();\n results.add(clean);\n this.count += 1;\n }\n return results;\n }\n}\n\n// variant 1",
|
|
"original_tokens": 183,
|
|
"preserved_imports": 3,
|
|
"preserved_signatures": 0,
|
|
"symbol_scores": {
|
|
"Processor": 0.071,
|
|
"String": 1.0,
|
|
"process": 0.0
|
|
},
|
|
"syntax_valid": true
|
|
},
|
|
"recorded_at": "2026-06-19T00:15:16.346983+00:00",
|
|
"transform": "code_aware_compressor"
|
|
}
|