Repository navigation
feat: add project setup and Python compaction - #1
Merged
Merged
Conversation
luizcodedthat
approved these changes
Oct 7, 2026
Collaborator
There was a problem hiding this comment.
Approving. Some minor adjustments, none blocking:
src.splitlines()splits on more characters than the tokenizer sees (e.g.\x0c), so valid source can get a false "Transformation rejected" warning; split rows the same way the tokenizer reads lines (e.g.io.StringIO(src).readlines()).- Coding header detection uses
"coding" in tk.string, so any comment in the first two lines containing the word (e.g.# coding design patterns is my passion) is kept; use the PEP 263 regex. strip_comments=Truealso removes# type: ignore,# noqaand# fmt:; if the output goes back into the codebase, linters and formatters will be affected. Best to keep them, no?
I also ran my own fuzzing over ~1,000 CPython stdlib files (plus form feed injection): no invalid output, AST changes or unhandled exceptions, and no wrong output was accepted.
Owner
Author
|
Thanks, my camarada! All three points addressed:
Added tests for each point (95 passing now, 36 before). Ruff passes. The new tests fail on the previous code. Also ran a quick fuzz over 400 stdlib files with random form feed injection, in both levels with and without |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: add project setup and Python compaction
This PR establishes the initial Python implementation of LLM Compact. It adds the package configuration, shared data structures, a Python source compactor, automated tests, and a GitHub Actions workflow.
The compactor removes unnecessary formatting while checking that accepted transformations preserve the original Python AST and compile successfully. This provides the foundation for the token-counting service, additional language support, CLI, and interface planned for subsequent PRs.
Files added
pyproject.tomltiktokenas a required dependency and provides optional groups for Streamlit and development tools. Configures pytest discovery and Ruff checks. The CLI entry point is deferred until the CLI implementation is introduced.requirements.txt.[ui]. This prepares the dependency configuration for the later interface implementation.requirements-dev.txt-e .[ui,dev], allowing local source changes to be tested without reinstalling the package.requirements-lock.txtpyproject.toml; it does not automatically enforce this snapshot.llm_compact/core/types.pyCompactOptionsvalidates the selected level and the comment-removal option. The shared size limit will be enforced by the public dispatcher introduced in a later PR.llm_compact/core/python.pytokenizeandastmodules. Reconstructs source text with reduced whitespace, preserves indentation and literal contents, optionally removes comments, and validates the candidate against the original AST. Returns the original source with a warning when parsing or transformation validation fails.tests/test_python.pyexamples/sample.py.github/workflows/ci.ymltiktoken, checks for GCC/G++, and runs Ruff and pytest. Loading the tables directly avoids depending on the future CLI..gitignoreCompaction behavior
fullremoves unnecessary spacing and eligible line breaks, including within bracketed expressions.lightretains line breaks and checks that the newline count remains unchanged.The compaction implementation parses and compiles source for validation; it does not execute the submitted program.
Validation
The local checks reported:
python -m ruff check .: passed.python -m pytest -q: 36 tests passed.The GitHub Actions result should be checked before merging.
Scope and limitations
This PR introduces the Python compaction foundation. Token counting, measured savings, the public language dispatcher, CLI commands, and the Streamlit interface are delivered in subsequent PRs.
AST comparison does not guarantee identical behavior for source introspection, traceback positions, or tools that depend on formatting. Syntax support also depends on the Python interpreter running the compactor.
This PR does not measure the effect of compaction on LLM response quality.