modularize
One focused, repeatable pass that retires the code-quality scorecard's `architecture` debt — the god-files (>1500 lines) and god-functions (>200 lines) that…
от anthony-chaudhary★ 50 звёзд на GitHub
Установить modularize в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
/modularize — split the monoliths, provably, without changing behavior
What this does.
/quality-scoremeasures ten KPIs and retires the safe ones, but it marksarchitectureRISKY and defers it: "do it in ONE lane, keep behavior identical… if you can't do it safely this pass, leave it for a focused pass — do NOT half-do a refactor." This is that focused pass. It takes the god-files and god-functions that drag thearchitectureKPI to the floor and splits them along real concern seams — as behavior-preserving code motion, verified by the toolchain, proven by the scorecard, committed by explicit path on the shared trunk. In one run it took fak from code-debt 12 → 0, score 86.2 (B) → 95.9 (A).
The shape: find the heaviest architecture defect → plan the cut (boundaries + hazards) → split (file = code motion, function = extract) → verify (build/vet/test + behaviour review) → prove the drop → commit ONLY your packages by explicit path.
The one insight that makes this safe
Moving a top-level declaration to another file in the same package is a semantic
no-op in Go — package, not file, is the scope. So a god-file split can't change
behavior, and go build + go vet + go test is a near-complete gate. The residual
go build cannot cover — a top-level decl dropped by an incomplete cut that happens
to be unreferenced in-module (so no undefined:) — is closed by comparing the package's
top-level declaration list (git show HEAD:<file> vs working tree) before finishing (Step 4).
There are exactly three exceptions that make code motion NOT a no-op; check all three
before cutting:
- per-file build tags (
//go:build …) — moving a decl changes which file carries the constraint; func init()— init order is filename-alphabetical across a package, so moving aninit()between files can silently reorder initialization;- aliased imports (
x "path") —goimports -wre-derives plain imports after a move but does NOT re-infer a local alias; you must copy it to the new file by hand.
If a file has a build tag or an init(), keep those decls where they are (or in a file
whose name preserves init order) — don't move them blind.
Step 1 — Find the target (the scorecard builds the work-list)
python tools/code_quality_scorecard.py --no-toolchain --json # fast; corpus.kpis architecture.defects = your work-list
Read architecture's defects: each is god-file <path> (N lines > 1500) or
god-function <path>:<fn> (N lines > 200). Attack the heaviest first, and bias to
the most critical packages (the kernel — adjudicator, gateway, model,
ggufload — and cmd/fak, the entry point — over demos/benchmarks). Record the
baseline: architecture defects = K, code_debt = N, score = S.
Step 2 — Plan the cut (boundaries + hazards, computed not guessed)
The error-prone part of a clean split is cutting at the right line: a decl's doc comment
sits ABOVE its keyword, so a naive cut at func/type orphans the comment. Inspect the
file's declarations and check the three hazards (//go:build tags, func init(), and
aliased imports) plus multi-line backtick strings before slicing:
grep -nE '^(func|type|var|const) ' internal/model/kv.go
Group adjacent declarations (including their preceding doc comments) into cohesive concerns
(e.g. kv.go → kvcache.go for the KVCache type + eviction, rope.go for rotary embedding,
leaving the Session/forward core). Splitting on real seams is the whole point — see the
anti-gaming laws. Check the declaration count before and after the split:
grep -cE '^(func|type|var|const) ' <file> # before vs sum across split files
goimports is the engine of the file split and is not preinstalled — install it and
confirm it resolved before you cut anything:
go install golang.org/x/tools/cmd/goimports@latest
command -v goimports || { echo "goimports missing — $(go env GOPATH)/bin not on PATH"; exit 1; }
Step 3 — Split
Run the snippets below with the Bash tool — they are POSIX sh (sed, the mk()
function, goimports/gofmt), not PowerShell. Precondition: gofmt -w <file> BEFORE you
plan, so the package clause and import block are blank-separated and no extract range can
start at the package line.
A. God-FILE → concern files (pure code motion)
Create each new file from its block range, then delete the moved ranges bottom-up (so
earlier deletes don't shift later line numbers), then let goimports fix every import. The
package name and target dir are read from the file so the snippet is copy-paste-safe in any
package:
F=internal/model/kv.go
D=$(dirname "$F")
PKG=$(grep -m1 '^package ' "$F" | awk '{print $2}')
mk(){ { echo "package $PKG"; echo; sed -n "$2,$3p" "$F"; } > "$D/$1"; }
mk kvcache.go 10 272 # doc-comment-inclusive line ranges
mk rope.go 389 577
sed -i '389,577d' "$F"; s
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
- 01
Read - 02
Bash - 03
Write - 04
Edit - 05
Grep - 06
Glob
FAQ
Что делает скилл modularize?
One focused, repeatable pass that retires the code-quality scorecard's `architecture` debt — the god-files (>1500 lines) and god-functions (>200 lines) that /quality-score flags as RISKY and explicitly defers to "a focused pass". Splits a monolith along REAL concern seams via behavior-preserving code motion (hazard-check → plan → extract → goimports/gofmt → verify with go build/vet/test and git diff decl checks → commit by explicit path), and extracts long functions into named helpers. Use when this named workflow matches the task.
Как установить скилл modularize?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл modularize запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…