ln-831-oss-replacer

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所在目录,然后向上一级即可到达仓库根目录。

ln-831-oss-replacer

ln-831-oss-replacer

Type: L3 Worker Category: 8XX Optimization Parent: ln-830-code-modernization-coordinator
Executes OSS replacement plans from ln-645-open-source-replacer auditor. For each custom module with an OSS alternative: install package, rewrite imports, run tests, keep or discard atomically.

类型: L3 Worker 分类: 8XX 代码优化 父级模块: ln-830-code-modernization-coordinator
执行来自ln-645-open-source-replacer审计工具的OSS替换计划。对于每个有OSS替代方案的自定义模块:安装包、重写导入语句、运行测试,并以原子化方式保留或丢弃更改。

Overview

概述

AspectDetails
InputMigration plan from
docs/project/codebase_audit.md
(ln-645 section) OR target module
OutputReplaced modules, migration report
Companionln-645-open-source-replacer (finds candidates) → ln-831 (executes replacement)

维度详情
输入来自
docs/project/codebase_audit.md
(ln-645章节)的迁移计划,或指定的目标模块
输出已替换的模块、迁移报告
配套工具ln-645-open-source-replacer(寻找候选替换模块)→ ln-831(执行替换操作)

Workflow

工作流

Phases: Pre-flight → Load Plan → Prioritize → Replace Loop → Report

阶段: 预检 → 加载计划 → 优先级排序 → 替换循环 → 生成报告

Phase 0: Pre-flight Checks

阶段0:预检检查

CheckRequiredAction if Missing
Migration plan OR target moduleYesBlock replacement
Test infrastructureYesBlock (need tests for verification)
Package manager availableYesBlock (need to install OSS packages)
Git clean stateYesBlock (need clean baseline for revert)
MANDATORY READ: Load
shared/references/ci_tool_detection.md
— use Test Frameworks section for test detection.
检查项是否必填缺失时操作
迁移计划或目标模块阻止替换操作
测试基础设施阻止(需要测试来验证更改)
包管理器可用阻止(需要安装OSS包)
Git干净状态阻止(需要干净的基线用于回滚)
必读文档: 加载
shared/references/ci_tool_detection.md
—— 使用测试框架章节进行测试检测。

Worktree & Branch Isolation

工作区与分支隔离

MANDATORY READ: Load
shared/references/git_worktree_fallback.md
— use ln-831 row.

必读文档: 加载
shared/references/git_worktree_fallback.md
—— 使用ln-831对应的行。

Phase 1: Load Migration Plan

阶段1:加载迁移计划

From Audit Report

从审计报告加载

Read
docs/project/codebase_audit.md
, extract ln-645 findings:
FieldDescription
custom_modulePath to custom implementation
locLines of code in custom module
oss_packageRecommended OSS replacement
confidenceHow well OSS covers functionality (HIGH/MEDIUM/LOW)
api_mappingCustom function → OSS equivalent
读取
docs/project/codebase_audit.md
,提取ln-645的检测结果:
字段描述
custom_module自定义实现的路径
loc自定义模块的代码行数
oss_package推荐的OSS替代包
confidenceOSS包对原有功能的覆盖程度(高/中/低)
api_mapping自定义函数 → OSS等效函数的映射

From Target Module

从目标模块加载

If no audit report: analyze target module, search Context7/Ref for OSS alternatives.
MANDATORY READ: Load
shared/references/research_tool_fallback.md
for MCP tool chain.

如果没有审计报告:分析目标模块,在Context7/Ref中搜索OSS替代方案。
必读文档: 加载
shared/references/research_tool_fallback.md
以获取MCP工具链相关信息。

Phase 2: Prioritize Replacements

阶段2:替换优先级排序

PriorityCriteria
1 (highest)HIGH confidence + >200 LOC (max code reduction)
2HIGH confidence + 100-200 LOC
3MEDIUM confidence + >200 LOC
4MEDIUM confidence + 100-200 LOC
SkipLOW confidence (too risky for automated replacement)

优先级判定标准
1(最高)高置信度 + 代码行数>200(最大程度减少代码量)
2高置信度 + 代码行数100-200
3中置信度 + 代码行数>200
4中置信度 + 代码行数100-200
跳过低置信度(自动化替换风险过高)

Phase 3: Replace Loop (Keep/Discard)

阶段3:替换循环(保留/丢弃)

Per-Module Cycle

单模块循环

FOR each replacement candidate (R1..RN):
  1. INSTALL: Add OSS package
     npm install {package} / dotnet add package / pip install
  2. REWRITE: Update imports + call sites using api_mapping
  3. VERIFY: Run tests
     IF tests FAIL → DISCARD (revert ALL: uninstall package, restore files) → next
  4. TESTS PASS → KEEP
  5. DELETE: Remove old custom module (only after keep)
  6. LOG: Record replacement for report
FOR each replacement candidate (R1..RN):
  1. INSTALL: Add OSS package
     npm install {package} / dotnet add package / pip install
  2. REWRITE: Update imports + call sites using api_mapping
  3. VERIFY: Run tests
     IF tests FAIL → DISCARD (revert ALL: uninstall package, restore files) → next
  4. TESTS PASS → KEEP
  5. DELETE: Remove old custom module (only after keep)
  6. LOG: Record replacement for report

Atomic Revert on Discard

丢弃时的原子化回滚

StepRevert Action
Package installedUninstall:
npm uninstall
/
dotnet remove package
/
pip uninstall
Files modified
git checkout -- {modified_files}
Lock file changed
git checkout -- {lock_file}
步骤回滚操作
已安装包卸载:
npm uninstall
/
dotnet remove package
/
pip uninstall
文件已修改
git checkout -- {modified_files}
锁文件已更改
git checkout -- {lock_file}

Safety Rules

安全规则

RuleDescription
One module at a timeNever replace multiple modules simultaneously
No API signature changesPublic API of replaced module must stay compatible
Tests requiredSkip module if no tests cover it (too risky)
Confidence gateSkip LOW confidence replacements

规则描述
一次处理一个模块禁止同时替换多个模块
不修改API签名被替换模块的公共API必须保持兼容
必须有测试覆盖如果模块没有测试覆盖则跳过(风险过高)
置信度门槛跳过低置信度的替换候选

Phase 4: Report Results

阶段4:生成结果报告

Report Schema

报告结构

FieldDescription
sourceAudit report path or target module
candidates_totalTotal replacement candidates
replacements_appliedSuccessfully replaced modules
replacements_discardedFailed replacements with reasons
replacements_skippedLOW confidence / no test coverage
loc_removedTotal lines of custom code removed
packages_addedNew OSS packages installed
details[]Per-replacement: module, package, LOC removed

字段描述
source审计报告路径或目标模块
candidates_total替换候选模块总数
replacements_applied成功替换的模块数量
replacements_discarded替换失败的模块及原因
replacements_skipped因低置信度/无测试覆盖而跳过的模块
loc_removed移除的自定义代码总行数
packages_added新增的OSS包数量
details[]每个替换的详情:模块、包、移除的代码行数

Configuration

配置

yaml
Options:
  # Source
  audit_report: "docs/project/codebase_audit.md"
  target_module: ""

  # Confidence
  min_confidence: "MEDIUM"      # MEDIUM | HIGH

  # Verification
  run_tests: true

  # Safety
  require_test_coverage: true   # Skip modules with no tests
  delete_old_module: true       # Delete custom module after successful replacement

yaml
Options:
  # Source
  audit_report: "docs/project/codebase_audit.md"
  target_module: ""

  # Confidence
  min_confidence: "MEDIUM"      # MEDIUM | HIGH

  # Verification
  run_tests: true

  # Safety
  require_test_coverage: true   # Skip modules with no tests
  delete_old_module: true       # Delete custom module after successful replacement

Error Handling

错误处理

ErrorCauseSolution
Package not foundOSS package name changedSearch Context7/Ref for current name
API mismatchOSS API differs from mappingQuery docs for correct API, attempt fix
Circular dependencyNew package conflictsSkip replacement, log as manual
No test coverageCustom module untestedSkip (too risky for automated replacement)

错误原因解决方案
包未找到OSS包名称已更改在Context7/Ref中搜索当前名称
API不匹配OSS API与映射不符查询文档获取正确API,尝试修复
循环依赖新包存在冲突跳过该替换,记录为需手动处理
无测试覆盖自定义模块未被测试覆盖跳过(自动化替换风险过高)

References

参考资料

  • ../ln-645-open-source-replacer/SKILL.md
    (companion: finds candidates)
  • shared/references/ci_tool_detection.md
    (test detection)
  • shared/references/research_tool_fallback.md
    (MCP tool chain)

  • ../ln-645-open-source-replacer/SKILL.md
    (配套工具:寻找候选替换模块)
  • shared/references/ci_tool_detection.md
    (测试检测)
  • shared/references/research_tool_fallback.md
    (MCP工具链)

Definition of Done

完成标准

  • Migration plan loaded from audit report or target module analyzed
  • Candidates prioritized by confidence + LOC
  • Each replacement applied atomically: install → rewrite → test → keep/discard
  • Discarded replacements fully reverted (package + files + lock)
  • Kept replacements: old custom module deleted
  • Report returned with candidates total, applied, discarded, LOC removed

Version: 1.0.0 Last Updated: 2026-03-08
  • 已从审计报告加载迁移计划,或已分析目标模块
  • 已根据置信度和代码行数对候选模块进行优先级排序
  • 每个替换均以原子化方式执行:安装→重写→测试→保留/丢弃
  • 已丢弃的替换操作已完全回滚(包+文件+锁文件)
  • 已保留的替换操作:旧自定义模块已删除
  • 已生成包含候选总数、成功替换数、失败替换数、移除代码行数的报告

版本: 1.0.0 最后更新时间: 2026-03-08