ln-512-tech-debt-cleaner
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePaths: File paths (,shared/,references/) are relative to skills repo root. If not found at CWD, locate this SKILL.md directory and go up one level for repo root.../ln-*
路径: 文件路径(、shared/、references/)是相对于技能仓库根目录的。如果在当前工作目录(CWD)中未找到,请定位到SKILL.md所在目录,然后向上一级即为仓库根目录。../ln-*
Tech Debt Cleaner (L3 Worker)
技术债务清理工具(L3 Worker)
Automated cleanup of safe, low-risk tech debt findings from codebase audits.
自动清理代码库审计中发现的安全、低风险技术债务问题。
Purpose & Scope
用途与范围
- Consume audit findings from (ln-620 output) or ln-511 code quality output
docs/project/codebase_audit.md - Filter to auto-fixable findings with confidence >=90%
- Apply safe fixes: remove unused imports, delete dead code, clean commented-out blocks, remove deprecated aliases
- Never touch business logic, complex refactoring, or architectural changes
- Create single commit with structured summary of all changes
- Invocable from ln-510 quality coordinator pipeline or standalone
- 读取 (ln-620输出)或ln-511代码质量输出中的审计结果
docs/project/codebase_audit.md - 筛选出置信度≥90%的可自动修复问题
- 应用安全修复:移除未使用的导入、删除死代码、清理注释掉的代码块、移除已弃用的别名
- 绝不修改业务逻辑、复杂重构或架构变更
- 创建包含所有变更结构化摘要的单个提交
- 可通过ln-510质量协调器流水线调用,也可独立运行
Auto-Fixable Categories
可自动修复的问题类别
| Category | Source Prefix | Risk | Auto-Fix Action |
|---|---|---|---|
| Unused imports | MNT-DC- | LOW | Delete import line |
| Unused variables | MNT-DC- | LOW | Delete declaration |
| Unused functions (unexported) | MNT-DC- | LOW | Delete function block |
| Commented-out code (>5 lines) | MNT-DC- | LOW | Delete comment block |
| Backward-compat shims (>6 months) | MNT-DC- | MEDIUM | Delete shim + update re-exports |
| Deprecated aliases | MNT-DC- | LOW | Delete alias line |
| Trailing whitespace / empty lines | MNT- | LOW | Trim / collapse |
| 类别 | 来源前缀 | 风险等级 | 自动修复操作 |
|---|---|---|---|
| 未使用的导入 | MNT-DC- | 低 | 删除导入行 |
| 未使用的变量 | MNT-DC- | 低 | 删除变量声明 |
| 未使用的函数(未导出) | MNT-DC- | 低 | 删除函数块 |
| 注释掉的代码(超过5行) | MNT-DC- | 低 | 删除注释块 |
| 向后兼容垫片(超过6个月) | MNT-DC- | 中 | 删除垫片并更新重导出 |
| 已弃用的别名 | MNT-DC- | 低 | 删除别名行 |
| 尾随空格/空行 | MNT- | 低 | 修剪/合并 |
NOT Auto-Fixable (skip always)
不可自动修复(始终跳过)
| Category | Reason |
|---|---|
| DRY violations (MNT-DRY-) | Requires architectural decision on where to extract |
| God classes (MNT-GOD-) | Requires domain knowledge for splitting |
| Security issues (SEC-) | Requires context-specific fix |
| Architecture violations (ARCH-*) | Requires design decision |
| Performance issues (PERF-*) | Requires benchmarking |
| Any finding with effort M or L | Too complex for auto-fix |
| 类别 | 原因 |
|---|---|
| DRY原则违反(MNT-DRY-) | 需要决定提取逻辑的位置,属于架构决策 |
| 上帝类(MNT-GOD-) | 需要领域知识来拆分类 |
| 安全问题(SEC-) | 需要结合具体上下文修复 |
| 架构违反(ARCH-*) | 需要进行设计决策 |
| 性能问题(PERF-*) | 需要基准测试验证 |
| 任何标注为中等(M)或大型(L)工作量的问题 | 过于复杂,无法自动修复 |
When to Use
使用场景
- Invoked by ln-510-quality-coordinator Phase 3 (after ln-511 code quality check)
- Standalone: After codebase audit completes (user triggers manually)
ln-620 - Scheduled: As periodic "garbage collection" for codebase hygiene
- 由ln-510-quality-coordinator调用:第3阶段(在ln-511代码质量检查完成后)
- 独立运行:ln-620代码库审计完成后(由用户手动触发)
- 定时执行:作为定期的代码库“垃圾回收”,维护代码卫生
Inputs
输入
- Pipeline mode (ln-510): findings from ln-511 code quality output (passed via coordinator context)
- Standalone mode: (ln-620 output)
docs/project/codebase_audit.md
- 流水线模式(ln-510):通过协调器上下文传递的ln-511代码质量输出结果
- 独立模式:(ln-620输出)
docs/project/codebase_audit.md
Workflow
工作流程
-
Load findings: Read. Parse findings from Dead Code section (ln-626 results) and Code Quality section (ln-624 results).
docs/project/codebase_audit.md -
Filter to auto-fixable:
- Category must be in Auto-Fixable table above
- Severity must be LOW or MEDIUM (no HIGH/CRITICAL)
- Effort must be S (small)
- Skip files in: ,
node_modules/,vendor/,dist/,build/, generated code, test fixtures*.min.*
-
Verify each finding (confidence check): MANDATORY READ:For each candidate fix: a) Read the target file at specified location b) Confirm the finding still exists (file may have changed since audit) c) Confirm removal is safe:
shared/references/clean_code_checklist.md- For unused imports: grep codebase for usage (must have 0 references)
- For unused functions: grep for function name (must have 0 call sites)
- For commented-out code: verify block is code, not documentation
- For deprecated aliases: verify no consumers remain d) Assign confidence score (0-100). Only proceed if confidence >=90
-
Apply fixes (bottom-up within each file):
- Sort fixes by line number descending (bottom-up prevents line shift issues)
- Apply each fix using Edit tool
- Track: file, lines removed, category, original finding ID
-
Verify build integrity: Perdiscovery hierarchy: detect and run lint + typecheck commands.
shared/references/ci_tool_detection.md- If ANY check fails: revert ALL changes (), report failure
git checkout . - If no lint/type commands detected: skip verification with warning
- If ANY check fails: revert ALL changes (
-
Create commit:
- Stage only modified files (explicit per file, not
git add)git add . - Commit message format:
chore: automated tech debt cleanup Removed {N} auto-fixable findings from codebase audit: - {count} unused imports - {count} dead functions - {count} commented-out code blocks - {count} deprecated aliases Source: docs/project/codebase_audit.md Confidence threshold: >=90%
- Stage only modified files (explicit
-
Update audit report:
- Add "Last Cleanup" section to :
docs/project/codebase_audit.mdmarkdown## Last Automated Cleanup **Date:** YYYY-MM-DD **Findings fixed:** N of M auto-fixable **Skipped:** K (confidence <90% or verification failed) **Build check:** PASSED / SKIPPED
- Add "Last Cleanup" section to
-
加载审计结果:读取。解析死代码章节(ln-626结果)和代码质量章节(ln-624结果)中的问题。
docs/project/codebase_audit.md -
筛选可自动修复的问题:
- 类别必须在上述可自动修复表格中
- 严重程度必须为低或中(不处理高/严重等级)
- 工作量必须为小(S)
- 跳过以下目录中的文件:、
node_modules/、vendor/、dist/、build/、生成的代码、测试夹具*.min.*
-
验证每个问题(置信度检查): 必读文档:对每个候选修复项: a) 读取指定位置的目标文件 b) 确认问题仍然存在(审计后文件可能已变更) c) 确认移除操作是安全的:
shared/references/clean_code_checklist.md- 对于未使用的导入:在代码库中搜索引用(必须为0次引用)
- 对于未使用的函数:搜索函数名(必须为0次调用)
- 对于注释掉的代码:验证块是代码而非文档
- 对于已弃用的别名:验证没有剩余的使用者 d) 分配置信度分数(0-100)。仅当置信度≥90时才继续执行
-
应用修复(按文件从下到上):
- 按行号降序排序修复项(从下到上避免行号偏移问题)
- 使用编辑工具应用每个修复
- 跟踪:文件、移除的行、类别、原始问题ID
-
验证构建完整性: 根据中的发现优先级:检测并运行lint和类型检查命令。
shared/references/ci_tool_detection.md- 如果任何检查失败:回滚所有变更(),报告失败
git checkout . - 如果未检测到lint/类型检查命令:跳过验证并发出警告
- 如果任何检查失败:回滚所有变更(
-
创建提交:
- 仅暂存修改过的文件(明确为每个文件执行,而非
git add)git add . - 提交信息格式:
chore: automated tech debt cleanup Removed {N} auto-fixable findings from codebase audit: - {count} unused imports - {count} dead functions - {count} commented-out code blocks - {count} deprecated aliases Source: docs/project/codebase_audit.md Confidence threshold: >=90%
- 仅暂存修改过的文件(明确为每个文件执行
-
更新审计报告:
- 在中添加“上次清理记录”章节:
docs/project/codebase_audit.mdmarkdown## Last Automated Cleanup **Date:** YYYY-MM-DD **Findings fixed:** N of M auto-fixable **Skipped:** K (confidence <90% or verification failed) **Build check:** PASSED / SKIPPED
- 在
Output Format
输出格式
yaml
verdict: CLEANED | NOTHING_TO_CLEAN | BUILD_FAILED
stats:
total_findings: {from audit}
auto_fixable: {filtered count}
applied: {actually fixed}
skipped: {confidence <90 or stale}
reverted: {if build failed, all}
fixes:
- file: "src/utils/helpers.ts"
line: 45
category: "unused_function"
removed: "formatDate()"
finding_id: "MNT-DC-003"
- file: "src/api/v1/auth.ts"
line: 12
category: "deprecated_alias"
removed: "export { newAuth as oldAuth }"
finding_id: "MNT-DC-007"
build_check: PASSED | SKIPPED | FAILED
commit_sha: "abc1234" | nullyaml
verdict: CLEANED | NOTHING_TO_CLEAN | BUILD_FAILED
stats:
total_findings: {from audit}
auto_fixable: {filtered count}
applied: {actually fixed}
skipped: {confidence <90 or stale}
reverted: {if build failed, all}
fixes:
- file: "src/utils/helpers.ts"
line: 45
category: "unused_function"
removed: "formatDate()"
finding_id: "MNT-DC-003"
- file: "src/api/v1/auth.ts"
line: 12
category: "deprecated_alias"
removed: "export { newAuth as oldAuth }"
finding_id: "MNT-DC-007"
build_check: PASSED | SKIPPED | FAILED
commit_sha: "abc1234" | nullCritical Rules
核心规则
- Safety first: Never fix if confidence <90%. When in doubt, skip.
- Bottom-up editing: Always apply fixes from bottom to top of file to avoid line number shifts.
- Build verification: If linter/type-checker fails after fixes, revert ALL changes immediately.
- No business logic: Never modify function bodies, conditionals, or control flow.
- Explicit staging: Stage files by name, never or
git add ..git add -A - Idempotent: Running twice produces no changes if audit report unchanged.
- Git-aware: Only operate on tracked files. Skip untracked or ignored files.
- Exclusions: Skip generated code, vendor directories, minified files, test fixtures.
- 安全优先:如果置信度<90%,绝不修复。存疑时直接跳过。
- 从下到上编辑:始终按文件从下到上的顺序应用修复,避免行号偏移问题。
- 构建验证:如果修复后linter/类型检查器失败,立即回滚所有变更。
- 不碰业务逻辑:绝不修改函数体、条件判断或控制流。
- 明确暂存:按文件名暂存文件,绝不使用或
git add .。git add -A - 幂等性:如果审计报告未变更,重复运行不会产生任何变更。
- Git感知:仅操作已跟踪的文件。跳过未跟踪或被忽略的文件。
- 排除规则:跳过生成的代码、供应商目录、压缩文件、测试夹具。
Definition of Done
完成标准
- Audit report loaded and parsed
- Findings filtered to auto-fixable categories
- Each finding verified with confidence >=90%
- Fixes applied bottom-up per file
- Build integrity verified (lint + type check) or skipped with warning
- Single commit created with structured message (or all reverted on build failure)
- Audit report updated with "Last Automated Cleanup" section
- Output YAML returned to caller
- 审计报告已加载并解析
- 已筛选出可自动修复类别的问题
- 每个问题均经过验证且置信度≥90%
- 已按文件从下到上应用修复
- 已验证构建完整性(lint + 类型检查)或已跳过验证并发出警告
- 已创建包含结构化信息的单个提交(或在构建失败时回滚所有变更)
- 审计报告已更新“上次自动清理记录”章节
- 已向调用方返回输出YAML
Reference Files
参考文件
- Clean code checklist:
shared/references/clean_code_checklist.md - Audit output schema:
shared/references/audit_output_schema.md - Audit report template:
shared/templates/codebase_audit_template.md
Version: 1.0.0
Last Updated: 2026-02-15
- 整洁代码检查清单:
shared/references/clean_code_checklist.md - 审计输出 schema:
shared/references/audit_output_schema.md - 审计报告模板:
shared/templates/codebase_audit_template.md
版本: 1.0.0
最后更新: 2026-02-15