ln-512-tech-debt-cleaner

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Paths: File paths (
shared/
,
references/
,
../ln-*
) are relative to skills repo root. If not found at CWD, locate this SKILL.md directory and go up one level for repo root.
路径: 文件路径(
shared/
references/
../ln-*
)是相对于技能仓库根目录的。如果在当前工作目录(CWD)中未找到,请定位到SKILL.md所在目录,然后向上一级即为仓库根目录。

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
    docs/project/codebase_audit.md
    (ln-620 output) or ln-511 code quality output
  • 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
  • 读取
    docs/project/codebase_audit.md
    (ln-620输出)或ln-511代码质量输出中的审计结果
  • 筛选出置信度≥90%的可自动修复问题
  • 应用安全修复:移除未使用的导入、删除死代码、清理注释掉的代码块、移除已弃用的别名
  • 绝不修改业务逻辑、复杂重构或架构变更
  • 创建包含所有变更结构化摘要的单个提交
  • 可通过ln-510质量协调器流水线调用,也可独立运行

Auto-Fixable Categories

可自动修复的问题类别

CategorySource PrefixRiskAuto-Fix Action
Unused importsMNT-DC-LOWDelete import line
Unused variablesMNT-DC-LOWDelete declaration
Unused functions (unexported)MNT-DC-LOWDelete function block
Commented-out code (>5 lines)MNT-DC-LOWDelete comment block
Backward-compat shims (>6 months)MNT-DC-MEDIUMDelete shim + update re-exports
Deprecated aliasesMNT-DC-LOWDelete alias line
Trailing whitespace / empty linesMNT-LOWTrim / collapse
类别来源前缀风险等级自动修复操作
未使用的导入MNT-DC-删除导入行
未使用的变量MNT-DC-删除变量声明
未使用的函数(未导出)MNT-DC-删除函数块
注释掉的代码(超过5行)MNT-DC-删除注释块
向后兼容垫片(超过6个月)MNT-DC-删除垫片并更新重导出
已弃用的别名MNT-DC-删除别名行
尾随空格/空行MNT-修剪/合并

NOT Auto-Fixable (skip always)

不可自动修复(始终跳过)

CategoryReason
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 LToo 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
    ln-620
    codebase audit completes (user triggers manually)
  • 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:
    docs/project/codebase_audit.md
    (ln-620 output)
  • 流水线模式(ln-510):通过协调器上下文传递的ln-511代码质量输出结果
  • 独立模式
    docs/project/codebase_audit.md
    (ln-620输出)

Workflow

工作流程

  1. Load findings: Read
    docs/project/codebase_audit.md
    . Parse findings from Dead Code section (ln-626 results) and Code Quality section (ln-624 results).
  2. 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/
      ,
      *.min.*
      , generated code, test fixtures
  3. Verify each finding (confidence check): MANDATORY READ:
    shared/references/clean_code_checklist.md
    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:
    • 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
  4. 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
  5. Verify build integrity: Per
    shared/references/ci_tool_detection.md
    discovery hierarchy: detect and run lint + typecheck commands.
    • If ANY check fails: revert ALL changes (
      git checkout .
      ), report failure
    • If no lint/type commands detected: skip verification with warning
  6. Create commit:
    • Stage only modified files (explicit
      git add
      per file, not
      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%
  7. Update audit report:
    • Add "Last Cleanup" section to
      docs/project/codebase_audit.md
      :
      markdown
      ## 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
  1. 加载审计结果:读取
    docs/project/codebase_audit.md
    。解析死代码章节(ln-626结果)和代码质量章节(ln-624结果)中的问题。
  2. 筛选可自动修复的问题
    • 类别必须在上述可自动修复表格中
    • 严重程度必须为低或中(不处理高/严重等级)
    • 工作量必须为小(S)
    • 跳过以下目录中的文件:
      node_modules/
      vendor/
      dist/
      build/
      *.min.*
      、生成的代码、测试夹具
  3. 验证每个问题(置信度检查)必读文档
    shared/references/clean_code_checklist.md
    对每个候选修复项: a) 读取指定位置的目标文件 b) 确认问题仍然存在(审计后文件可能已变更) c) 确认移除操作是安全的:
    • 对于未使用的导入:在代码库中搜索引用(必须为0次引用)
    • 对于未使用的函数:搜索函数名(必须为0次调用)
    • 对于注释掉的代码:验证块是代码而非文档
    • 对于已弃用的别名:验证没有剩余的使用者 d) 分配置信度分数(0-100)。仅当置信度≥90时才继续执行
  4. 应用修复(按文件从下到上)
    • 按行号降序排序修复项(从下到上避免行号偏移问题)
    • 使用编辑工具应用每个修复
    • 跟踪:文件、移除的行、类别、原始问题ID
  5. 验证构建完整性: 根据
    shared/references/ci_tool_detection.md
    中的发现优先级:检测并运行lint和类型检查命令。
    • 如果任何检查失败:回滚所有变更(
      git checkout .
      ),报告失败
    • 如果未检测到lint/类型检查命令:跳过验证并发出警告
  6. 创建提交
    • 仅暂存修改过的文件(明确为每个文件执行
      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%
  7. 更新审计报告
    • docs/project/codebase_audit.md
      中添加“上次清理记录”章节:
      markdown
      ## 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" | null
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" | null

Critical 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
    git add .
    or
    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