Earlier than I found out learn how to use macros to allow SwiftMCP, I experimented loads with SwiftSyntax and constructed a mission that I referred to as SAAE – Swift AST Abstractor & Editor. Such it lay forgotten on a public GitHub repo. So I figured, it will deserve a brand new coat of paint and a greater title.
The CLI of the mission has 4 most important capabilities right now:
- analyze – Makes you might be minimize down interface description for any variety of information. This manner you may hand the general public interface for a framework to your LLM with out it having to learn plenty of superfluous textual content.
- test – Does a super-fast native syntax test throughout the scope of 1 file. This manner you may catch “apparent” syntax error in generated code earlier than you waste time on a protracted construct.
- reindent – Generated code often doesn’t care about how you want your code reindented. This perform primarily what CMD+I does in Xcode.
- distribute – Generated code tends to wish to put all new code right into a single file ensuing an tons of declarations in big information. This perform splits all declarations into separate information. If protocol extensions it places them parallel to the declaration file with +Protocol added to the title.
That is all some form of housekeeping work, so at first I needed to go along with maid. However my AI satisfied me that this can be a unhealthy title for a lot of causes, together with the truth that the time period “maid” is supposedly sexist. So I let myself be satisfied that butler is manner higher. So we went with that.
SAAE turns into SwiftButler
So for model 1, I polished up the CLI a bit, gave it a --version command, and renamed it to butler. I added a SKILL.md file to help with it getting used as an OpenClaw ability and in addition added it to my homebrew faucet with the intention to simply set up it.
brew set up cocoanetics/faucet/swiftbutler
Then to make use of it simply do one thing like:
butler analyze Sources/MyModule --visibility public
The entire documentation for the CLI will be discovered on GitHub. Or simply set up it from ClawHub.
Granted, you could possibly additionally ask your coding agent to do this sort of refactoring. However coding brokers would do this by producing all of the extracted code from scratch and in addition to generated the code to be deleted as nicely. With this device it’s primarily free.
This was the principle realization why I felt that butler can be fairly helpful in any Swift developer’s device belt.
And whereas watching my coding brokers at work I preserve seeing that they nonetheless have occasional bother with syntax and even get tripped up by their very own file modifying instruments. Cursor (and by extension VS Code) has a bonus over Codex and Claude by getting access to a Swift Linter which tells the LLM proper then and there that there’s some syntax downside.
I’ve but to strive it in observe, however I feel the butler test perform ought to be capable of act as a primary line of defence linter for Codex or Claude Code. This emits all of the sorts of syntax errors you’d get from the syntax checker of the Swift compiler. It received’t be capable of let you know if you’re calling a non-existing perform from one other file, however there are lots of syntax issues it CAN let you know about. To a level there are even repair its offered.
Conclusion
LLMs may be getting higher and higher at writing appropriate code from the beginning, however even when they write good code there stay some refactoring operations that you just’d be higher off doing deterministically by using instruments that may assist you confirm and modify the summary syntax tree of your supply code.
When constructing SwiftButler I had a number of extra concepts for what it might/ought to do:
- be sure all public capabilities have DocC feedback
- be sure all file headers adhere to a sure normal
- extra formidable: have some form of lookup perform that enables discovering declarations or capabilities by title or semantically
- most formidable: emulate cross-file syntax checking by verifying that declarations or capabilities exist within the native mission
What do you suppose? What ought to be add subsequent?
Associated
Classes: Updates

