code-audit
GitHub用于扫描代码库架构问题、文件行数违规及MVI合规性,并生成可操作的增量重构计划。支持自动化审计脚本执行与四阶段重构流程,确保代码规范与低回归风险。
Trigger Scenarios
Install
npx skills add pass-with-high-score/blockads-android --skill code-audit -g -y
SKILL.md
Frontmatter
{
"name": "code-audit",
"description": "Scan the codebase for architectural issues, files exceeding 500 lines, missing MVI contracts, duplicate code, and gomobile interop risks, and generate actionable refactoring plans. Use when the user asks to \"audit code\", \"check code issues\", \"find files to refactor\", or \"refactor screen\"."
}
Code Audit & Refactoring Skill
This skill diagnoses code smells, architectural violations, and rule non-compliance across the blockads-android project, then guides safe, incremental refactoring according to project standards (GEMINI.md and .agents/rules/).
Capabilities
-
Automated Codebase Audit:
- Detect files exceeding the 500-line limit (both Kotlin and Go).
- Identify UI screen modules missing dedicated
*Contract.ktfiles (MVI compliance). - Identify god-classes and monoliths needing decomposition.
- Verify gomobile interop constraints in
tunnel/.
-
Targeted Refactoring Workflows:
- Splitting large composables (>500 lines) into focused sub-composables in dedicated files.
- Converting legacy screens to standard MVI (
Contract+Screen+ViewModel). - Breaking down monolithic services (e.g.,
AdBlockVpnService.kt,AppPreferences.kt) into delegates.
How to Run an Audit
Execute the built-in audit script from the terminal:
python3 .agents/skills/code-audit/scripts/audit_codebase.py
This generates an instant Markdown report covering:
- File line count violations categorized by severity (🔴 Critical > 750 lines, 🟡 Warning > 500 lines).
- UI modules lacking dedicated MVI Contracts.
- Gomobile compatibility issues.
- Prioritized refactoring roadmap.
4-Phase Refactoring Process
When tasked with refactoring any module or screen identified by the audit:
Phase 1: Diagnosis & Scope Definition
- Run the audit script or inspect the target file.
- Identify the exact responsibilities of the file.
- Define what parts will be extracted (e.g., UI dialogs, card items, state models, helper functions).
Phase 2: Refactoring Plan
Draft a concise plan detailing:
- Target File: File to be decomposed.
- New Extracted Files:
*Contract.kt: ImmutableUiState,UiIntent,UiEffect.components/*Item.ktorcomponents/*Dialog.kt: Extracted stateless composables.*Delegate.ktor*Helper.kt: Extracted business logic or DataStore operations.
- Target line count for each file (all strictly < 500 lines).
Phase 3: Execution (Incremental & Atomic)
- Extract independent contracts/models first.
- Extract reusable UI components into
ui/components/or screen-specific subpackages. - Keep the main Screen or Service as an orchestrator with a flat hierarchy.
- Ensure all dependencies are injected via Koin constructor injection.
Phase 4: Taste Test & Verification
- Compile the project:
./gradlew assembleDebug - Run unit tests:
./gradlew test - If modifying Go tunnel:
./gradlew buildGoTunnel - Verify zero regression in functionality and confirm all new files are under 500 lines.
Version History
-
d0a14c3
Current 2026-09-27 14:55
将文档中所有 .agent 引用标准化为 .agents。
- 4938bb2 2026-09-22 03:58


