SwiftButler
Use butler to reduce Swift source into a more manageable working surface.
Setup
Install via Homebrew:
CODEBLOCK0
Verify:
CODEBLOCK1
For local development from a checkout:
CODEBLOCK2
Core Rules
- - Prefer
analyze when an agent needs API shape, not full implementation details. - Prefer
--format yaml or --format json when the result will be parsed or reused. - Prefer
check for fast validation loops before swift build. - Use
reindent to normalize indentation in place; choose exactly one of --spaces <n> or --tabs. - Use
distribute before targeted edits when a generated file has become too large or noisy.
Fast Command Map
Analyze Swift APIs
CODEBLOCK3
Supported formats:
- - INLINECODE10
- INLINECODE11
- INLINECODE12
- INLINECODE13
Syntax-check Swift quickly
CODEBLOCK4
Reindent with spaces or tabs
CODEBLOCK5
Notes:
- -
--spaces <n> accepts values from 1 to 16. - INLINECODE17 and
--spaces <n> are mutually exclusive. - Without
--tabs, the default is --spaces 3.
Distribute large files into smaller ones
CODEBLOCK6
When to Use Which Command
- - Use
analyze to hand an LLM a compact view of types, functions, properties, and docs. - Use
check inside generation or repair loops for immediate syntax feedback. - Use
reindent after generated or patched code has inconsistent indentation. - Use
distribute when one large Swift file should become declaration-sized files that are easier to inspect and edit.
SwiftButler
使用 butler 将 Swift 源码缩减为更易于管理的操作面。
设置
通过 Homebrew 安装:
bash
brew install cocoanetics/tap/swiftbutler
验证安装:
bash
butler --version
从代码仓库进行本地开发:
bash
swift build
.build/debug/butler --version
核心规则
- - 当代理需要 API 结构而非完整实现细节时,优先使用 analyze。
- 当结果需要被解析或复用时,优先使用 --format yaml 或 --format json。
- 在 swift build 之前,优先使用 check 进行快速验证循环。
- 使用 reindent 原地规范化缩进;从 --spaces 或 --tabs 中二选一。
- 当生成的文件变得过大或杂乱时,在针对性编辑前使用 distribute。
快速命令映射
分析 Swift API
bash
默认接口样式输出
butler analyze Sources/MyModule
仅公开 API
butler analyze Sources/MyModule --visibility public
递归 YAML 输出,便于工具处理
butler analyze Sources --recursive --format yaml
将结构化输出写入文件
butler analyze Sources --recursive --format yaml --output api.yaml
支持的格式:
- - interface
- json
- yaml
- markdown
快速语法检查 Swift 代码
bash
butler check Sources --recursive
butler check Sources --recursive --json
butler check Sources --recursive --json --pretty
butler check Sources --recursive --format markdown --show-fixits
使用空格或制表符重新缩进
bash
默认:3 个空格
butler reindent Sources --recursive
显式指定空格数
butler reindent Sources --recursive --spaces 2
butler reindent Sources --recursive --spaces 4
使用制表符代替空格
butler reindent Sources --recursive --tabs
预览而不修改文件
butler reindent Sources --recursive --tabs --dry-run
注意:
- - --spaces 接受 1 到 16 的值。
- --tabs 和 --spaces 互斥。
- 未指定 --tabs 时,默认使用 --spaces 3。
将大文件拆分为小文件
bash
拆分一个大型生成文件
butler distribute Generated.swift
预览递归分发
butler distribute Sources/Generated --recursive --dry-run
将分发后的文件写入单独目录
butler distribute Sources/Generated --recursive --output SplitSources
何时使用哪个命令
- - 使用 analyze 向 LLM 提供类型、函数、属性和文档的紧凑视图。
- 在生成或修复循环中使用 check 获取即时语法反馈。
- 在生成或修补的代码缩进不一致后使用 reindent。
- 当单个大型 Swift 文件应拆分为更易于检查和编辑的声明级文件时,使用 distribute。