AST Transformations for Deterministic Refactoring
What variant of Codex are you using?
GPT-5.3-Codex
What feature would you like to see?
I propose deterministic refactoring (and, more generally, code editing) where the model never edits source text directly. Instead, it selects from a predefined set of semantics-preserving AST transformations, guaranteeing semantic equivalence.
- LLM input: user prompt, abstract syntax tree, library of allowed transformations.
- LLM output: a sequence of transformations selected from this library.
- Then, a deterministic refactoring engine applies these transformations to the AST and prints the updated source.
Example:
# Input:
print("/".join(["https://example.com", "subdirectory", "index.html"]))
# LLM outputs a refactoring instruction:
# {"type": "extract_variable", "destination": "url_segments", ...}
# A deterministic refactoring engine executes this instruction, outputting:
url_segments = ["https://example.com", "subdirectory", "index.html"]
print("/".join(url_segments))
Similarly, we could allow more general transformations (e.g., "move this block of code here"). Even if they are not guaranteed to be semantics-preserving, representing "move code" as a deterministic instruction is still easier to verify (and likely faster) than relying purely on next-token generation (though one could also delegate such copy-paste operations to a specialized expert that is only activated via routing).
Additional information
Possibly (or possibly not) related:
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗