You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- This repository is a small single-file Python desktop app: `main.py` implements a Tkinter GUI and the token-optimization logic in the `AITokenCrusher` class.
10
-
- Primary goal: conservative, offline token minimization for text/code using deterministic string and regex transforms.
11
-
12
-
Where to look
13
-
- Core app and logic: `main.py` (UI, options, `apply_optimizations`).
- Single-process GUI: `AITokenCrusher` constructs the UI and stores state in `self.options` (a dict of `tk.BooleanVar`) and `self.ui_elements`.
20
-
- The optimization pipeline is implemented in `apply_optimizations(self, text)` and applied from `optimize()`.
21
-
- UI <-> logic boundary: do not embed heavy business logic in widget callbacks; extend or refactor `apply_optimizations` when adding new transforms.
22
-
23
-
Project-specific patterns & conventions
24
-
- Option keys are snake_case strings in `self.options` (e.g. `remove_comments`, `single_line_mode`). Follow this pattern when adding flags.
25
-
- Checkbuttons are created by iterating `self.options`; adding a new option requires:
26
-
1) add a `tk.BooleanVar` entry to `self.options` in `__init__`,
27
-
2) reference it in `apply_optimizations`, and
28
-
3) let the existing loop auto-create the checkbox.
29
-
- UI state containers: use `self.ui_elements` to store references (avoid creating loose globals).
30
-
- Theme handling: themes live in `self.themes` and switching occurs via `toggle_theme()` + `apply_theme()` — prefer updating these maps rather than hardcoding colors.
31
-
32
-
Optimization details agents must preserve
33
-
-`apply_optimizations` mixes regex and string replacements. Important examples to preserve exactly:
34
-
- Newline single-line mode uses the literal character `⏎` (replaces `\n`).
- Operator replacements: `==`→`≡`, `!=`→`≠`, ` and `→`∧`, ` or `→`∨`.
38
-
- Short print: `print(` → `p(` (note the removed whitespace pattern).
39
-
- These substitutions are intentionally non-standard/unicode; preserve their literal characters and avoid accidentally normalizing or escaping them.
40
-
41
-
Run / build / debug
42
-
- Run locally: `python main.py` (uses system Python with Tkinter). On Windows PowerShell:
7
+
- Small, single-process Tkinter desktop app. Primary logic lives in `main.py` (`AITokenCrusher`) and an identical copy in `src/app.py`.
8
+
- Purpose: deterministic, offline token minimization for text/code via string + regex transforms (keep substitutions literal).
9
+
Where to look (high-value files)
10
+
-`main.py` — canonical UI + optimization logic. Edit here for behavior changes.
11
+
-`src/app.py` — duplicate of `main.py` (check both when refactoring).
12
+
-`README.md` — user-facing description and release link.
13
+
-`assets/` — screenshots and static images used in README.
14
+
Big-picture architecture (quick)
15
+
- UI and logic are co-located in `AITokenCrusher`:
16
+
-`self.options` (dict of `tk.BooleanVar`) drives which transforms run.
17
+
-`apply_optimizations(self, text)` contains the pipeline of regex/string transforms.
18
+
-`optimize()` reads input, calls `apply_optimizations`, updates output and stats.
19
+
- The UI auto-creates checkboxes by iterating `self.options` — adding an option is three small steps (see below).
20
+
Project-specific conventions (do these exactly)
21
+
- Option lifecycle: add a `tk.BooleanVar` key in `self.options` (snake_case), implement the transform in `apply_optimizations`, and the checkbox appears automatically.
22
+
- Keep UI references in `self.ui_elements` (avoid top-level globals).
23
+
- Theme configuration lives in `self.themes` and is applied with `toggle_theme()` / `apply_theme()`; prefer updating theme maps over hardcoding colors.
24
+
Critical transforms and literals to preserve
25
+
-`single_line_mode` replaces newlines with the literal character `⏎` (not a word). Do not normalize or escape it.
26
+
- Exact mappings (examples taken from `apply_optimizations`):
- Operators: `==` → `≡`, `!=` → `≠`, ` and ` → `∧`, ` or ` → `∨`
30
+
- Print: `print(` → `p(`
31
+
- Regex-based removals (comments, docstrings, type hints) are implemented with `re.sub` — preserve the intent and the approximate patterns when editing.
32
+
Developer workflows / commands
33
+
- Run app locally (PowerShell):
43
34
```pwsh
44
35
python .\main.py
45
36
```
46
-
-Packaging (not present in repo): releases show a Windows `.exe`. If creating builds, use a one-file GUI build (example):
37
+
-Build a one-file Windows executable (only if requested):
47
38
```pwsh
48
39
pyinstaller --onefile --windowed main.py
49
40
```
50
-
Only add packaging config if requested; keep runtime behaviour deterministic.
51
-
52
41
Testing and verification
53
-
- There are no automated tests. Changes that affect behavior require manual testing: launch the GUI, paste sample code, toggle options, and verify `apply_optimizations` output.
54
-
- When adding new transforms, include small unit-testable helper functions and a minimal manual verification harness that calls `apply_optimizations(text)`.
55
-
56
-
Safe editing guidance for agents
57
-
- Be conservative: prefer adding small helper functions over large refactors.
58
-
- Keep public names and option keys stable (changing keys requires UI and saved-state updates).
59
-
- When introducing new dependencies, document why and prefer pure-Python stdlib solutions (this repo intentionally targets offline usage).
60
-
42
+
- There are no automated tests. When changing transforms: add a small, importable helper function and unit tests under `tests/`.
43
+
- Manual verification: run the GUI, paste input, toggle the relevant option(s), press *CRUSH TOKENS →*, and confirm output and the saved `%` metric.
44
+
Small-change checklist for agents (use before committing)
45
+
1. Add or rename an option: update `self.options` (tk.BooleanVar), add logic in `apply_optimizations`, keep key stable.
3. For UI changes, reuse `self.ui_elements` and the checkbox auto-creation loop.
48
+
4. When refactoring, update both `main.py` and `src/app.py` (one is a copy).
61
49
Files to reference in PRs
62
-
-`main.py` — implementation and starting point for most changes.
63
-
-`README.md` — user-facing description, check for mismatch with behaviour.
64
-
-`assets/` — update assets if UI text or screenshots change.
65
-
66
-
If something is unclear
67
-
- Ask the maintainer which transforms are allowed to change semantics; otherwise assume existing substitutions must remain literal and reversible for humans.
68
-
69
-
— End —
50
+
-`main.py`, `src/app.py`, `README.md`, and `assets/`.
51
+
If unclear
52
+
- Ask the maintainer whether a transform may change semantics. Default: preserve existing mappings and prefer small, testable helpers.
0 commit comments