code-clean
Skill787 starsChanged 3 months agoMITView on GitHub
Cut dead code and over-long comments from termio's Swift, verifying every deletion against a build. Knows this repo's real failure mode (essay-length doc comments, not restated-code slop) and periphery's four known false-positive shapes. Invoke when the user says 'clean dead code', 'clean up the comments', 'the comments are too long', 'remove unused code', 'tighten this file', '清理死代码', '注释太啰嗦', '精简一下注释'.
In this repository29 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- animation-vocabularySkill
- apple-designSkill
- app-screenshot-debugSkill
- ascSkill
- bump-versionSkill
- check-ghostty-updateSkill
- conventional-commitSkill
- dia-source-analysisSkill
- docSkill
- emil-design-engSkill
- find-animation-opportunitiesSkill
- improve-animationsSkill
- ios-app-analysisSkill
- ios-rebuild-devSkill
- issue-creatorSkill
- macos-rebuild-devSkill
- native-app-profilingSkill
- og-generationSkill
- pick-ui-librarySkill
- prototypeSkill
- review-animationsSkill
- review-copySkill
- Swift Performance Optimization SkillSkill
- performance-auditSkill
- termio-bug-reportSkill
- termioSkill
- testflight-releaseSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 20
Default to the current branch's diff against origin/main.
- Very specific: line 46
Equatable/Hashablekey-struct fields: Read only through the synthesized == / hash(into:), which periphery cannot see. - Very specific: line 62
utilities orphaned when their UI was removed: Before deleting, grep the symbol across Sources, Shared, ios/Sources, Tests, and scripts/.
- Very specific: line 111
Delete that. But /// Whether the machine answered at all.
- Distinctive: line 149
Do not report a line count as the result.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Code Clean
Two passes over termio's Swift: dead code (symbols nothing reaches) and over-long comments (prose that outgrew what it explains). Both end in a build. Neither is a refactor.
This is not a generic AI-slop sweep. Run one on this repo and it finds nothing:
a 2026-08 survey of all 69k tracked Swift lines turned up 1 TODO (a false
match on an mktemp template), 0 commented-out code blocks, and 1
deliberate debug print. Don't spend the pass hunting those. The bloat here is
shaped differently, and §2 is where it lives.
Scope
Default to the current branch's diff against origin/main. A whole-tree pass is
a standing request only — say so, and expect it to take real time.
Never touch:
Sources/termio/Editor/Highlightr/— vendored; upstream API surface is kept intact on purpose (AGENTS.md).- Anything under
skills/recorded inskills-lock.json— re-pull from upstream instead of hand-editing. ios/build/,ios/build-sim/— Xcode artifacts, not tracked source. They hold ~100k lines of SPM checkouts that will swamp any tree-wide grep. Scope greps withgit ls-files, never barefind ios.
1. Dead code
periphery scan --targets termio (SPM; no config file needed). It is installed
at /opt/homebrew/bin/periphery.
Roughly three of every four hits are false. Four shapes account for nearly all of them — clear each before deleting anything:
- Retain-holders.
private var toolbarDelegate / menuBar / hookListener / linkClickMonitor / scanTask / stream / source / window. FlaggedassignOnlyProperty, but holding the reference is the job — drop the property and the object deallocates and the feature dies.App.swiftsays so in comments ("must be retained"). Equatable/Hashablekey-struct fields. Read only through the synthesized==/hash(into:), which periphery cannot see.BranchModel'sGitStatespells out why its field exists: so a same-HEAD refresh is recognized as a no-op.@objcselector-targetsender:parameters. The AppKit selector signature requires them.- Vendored code. See Scope.
Two more that are unused and must stay:
- Documented extension points — the
IssueProviderprotocol is unused as a type but is the seam for Linear (docs/design/issue-tracker-integration.md). - Persisted fields —
Session.createdAtis unread but lives in the state file. Deleting it is a schema change, not a cleanup.
Real finds cluster in fetch-and-cache paths whose views were never wired and
utilities orphaned when their UI was removed. Before deleting, grep the
symbol across Sources, Shared, ios/Sources, Tests, and scripts/. If
only a test references it, the test is holding a corpse upright — delete both.
2. Over-long comments
The repo's actual bloat. Of 3,293 doc-comment blocks in Sources + Shared,
81% are 1–5 lines and healthy. The tail is not: 636 blocks run 6+ lines, 151
run 12+, and the longest is 44 lines — a design doc wearing a function header.
Find them:
git ls-files 'Sources/*.swift' 'Shared/*.swift' 'ios/Sources/*.swift' | xargs awk '
/^[[:space:]]*\/\/\//{if(n==0)start=FNR; n++; next}
{if(n>=12){print n" "FILENAME":"start}; n=0}
END{if(n>=12)print n" "FILENAME":"start}' | sort -rnThe test that matters
AGENTS.md says comments explain why, not what. These comments already do — that is exactly the trap. Length is not the defect; misfiling is. A 20-line block is wrong not because it is long but because a field's doc comment is the wrong home for a design argument.
Sort every long block into three piles:
- Keep, verbatim. A foot-gun, an invariant, or a past bug that will be
reintroduced without it.
Workspace.isAutoCreated's note on whyBool?has three states, not two, is load-bearing: collapsing it tofalseis what made an earlier version wrong. Length is irrelevant here. Leave it. - Move to
docs/design/, leave a one-line pointer. Architecture, alternatives considered, upstream asks, competitor comparisons. The 44-line block onmakeStatusTapis three paragraphs of model plus a caveat with an upstream ask — that is a design doc. Use thedocskill to create or extend it, then leave/// … see docs/design/<file>.md. Move, never delete. - Cut. Restating the signature, narrating the body line by line, hedging ("this should probably"), and prose that repeats the paragraph above it.
Tautological one-liners
~130 docs open /// Whether the … and many just respell the property name:
/// Whether the "Projects" section is folded shut.
var isProjectsCollapsed: BoolDelete that. But /// Whether the machine answered at all. false is what turns
every agent row … earns its line — it says what the value causes. Read each
one; do not pattern-match the opener.
Ceilings, once a block is in the "cut" pile
One line is the target. Three is the ceiling for a field or inline comment, five
for a type or function. A block that cannot fit belongs in docs/design/.
Leave alone
// MARK:— all 602 of them. They are navigation, not narration, and they are spread thin (12 in the heaviest file). AGENTS.md's ban on "organizational comments" is about prose headers that summarize what the next block does.- Comments on code this branch did not touch, in a diff-scoped run.
- An outdated comment: fix it, don't reword it to match wrong code. If the code is what's wrong, report that separately — it is a bug, not a comment.
3. Verify
swift build # required, every time
swift test # if anything under a covered unit movedCovered units: split-tree layout, OSC parsing, stall probing, Markdown/HTML rendering, git service, editor text, install feedback.
A comment pass that changes no code still needs swift build — a deleted line
inside a multi-line string or a stray /// before an attribute breaks the
parse.
Report
Per file: what was cut, what moved to docs/design/, and what was flagged but
kept and why. Name the periphery hits you rejected and which of the four shapes
each was — that list is how the next run gets faster.
Do not report a line count as the result. "Cut 400 lines" says nothing about whether the right 400 went.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

