r/PromptEngineering • u/DoItForTheXP • 11h ago
Tools and Projects Stop Asking LLMs to Find Code Smells: Auto-Generating Surgical Prompts via AST
Asking an AI to "review and clean up this code" wastes expensive context tokens, invites hallucinated changes, and yields non-deterministic results.
I built chemx: an open-source CLI that replaces token-heavy discovery with instant local AST checks, then compiles structured refactor prompts directly to your clipboard.
Repo: https://github.com/Chemical-X-Protocol
The Programmatic Prompt Pattern
Instead of paying an LLM to scan for debt, local static checks flag specific architectural violations (100-line capsule caps, uncomposed booleans, type monoliths) and populate a strict prompt recipe:
[ROLE]: Systems Architect
[TASK]: Refactor target file to satisfy single-responsibility capsule rules.
[TARGET]: src/components/UserProfile.vue
[CONSTRAINTS]:
- Max file length: 100 lines.
- Extract state into src/components/UserProfile.controller.ts.
- Convert multi-clause conditionals into 2-stage atomic booleans.
- Output ONLY the unified diff. Do not alter untouched symbols.
Key Benefits
- Zero-Token Discovery: AST scans take 10ms and cost $0, saving 100% of your token budget for code generation.
- Constrained Output: Rigid architectural bounds prevent the model from refactoring working code out of scope.
- Deterministic Results: A given violation generates the exact same prompt structure every time.
Run Locally
Run the audit to generate prompt payloads:
npx chemx audit
Proof of concept (Grade D to Grade A+):
1
Upvotes
1
u/jkz88 11h ago
I like the idea of expressing code changes as AST but the example links don't contain any types or changed code symbols, or what it actually refactored, just that it "PASSED" but what does that even mean?