ln-831-oss-replacer
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-*
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
概述
| Aspect | Details |
|---|---|
| Input | Migration plan from |
| Output | Replaced modules, migration report |
| Companion | ln-645-open-source-replacer (finds candidates) → ln-831 (executes replacement) |
| 维度 | 详情 |
|---|---|
| 输入 | 来自 |
| 输出 | 已替换的模块、迁移报告 |
| 配套工具 | ln-645-open-source-replacer(寻找候选替换模块)→ ln-831(执行替换操作) |
Workflow
工作流
Phases: Pre-flight → Load Plan → Prioritize → Replace Loop → Report
阶段: 预检 → 加载计划 → 优先级排序 → 替换循环 → 生成报告
Phase 0: Pre-flight Checks
阶段0:预检检查
| Check | Required | Action if Missing |
|---|---|---|
| Migration plan OR target module | Yes | Block replacement |
| Test infrastructure | Yes | Block (need tests for verification) |
| Package manager available | Yes | Block (need to install OSS packages) |
| Git clean state | Yes | Block (need clean baseline for revert) |
MANDATORY READ: Load — use Test Frameworks section for test detection.
shared/references/ci_tool_detection.md| 检查项 | 是否必填 | 缺失时操作 |
|---|---|---|
| 迁移计划或目标模块 | 是 | 阻止替换操作 |
| 测试基础设施 | 是 | 阻止(需要测试来验证更改) |
| 包管理器可用 | 是 | 阻止(需要安装OSS包) |
| Git干净状态 | 是 | 阻止(需要干净的基线用于回滚) |
必读文档: 加载 —— 使用测试框架章节进行测试检测。
shared/references/ci_tool_detection.mdWorktree & Branch Isolation
工作区与分支隔离
MANDATORY READ: Load — use ln-831 row.
shared/references/git_worktree_fallback.md必读文档: 加载 —— 使用ln-831对应的行。
shared/references/git_worktree_fallback.mdPhase 1: Load Migration Plan
阶段1:加载迁移计划
From Audit Report
从审计报告加载
Read , extract ln-645 findings:
docs/project/codebase_audit.md| Field | Description |
|---|---|
| custom_module | Path to custom implementation |
| loc | Lines of code in custom module |
| oss_package | Recommended OSS replacement |
| confidence | How well OSS covers functionality (HIGH/MEDIUM/LOW) |
| api_mapping | Custom function → OSS equivalent |
读取,提取ln-645的检测结果:
docs/project/codebase_audit.md| 字段 | 描述 |
|---|---|
| custom_module | 自定义实现的路径 |
| loc | 自定义模块的代码行数 |
| oss_package | 推荐的OSS替代包 |
| confidence | OSS包对原有功能的覆盖程度(高/中/低) |
| api_mapping | 自定义函数 → OSS等效函数的映射 |
From Target Module
从目标模块加载
If no audit report: analyze target module, search Context7/Ref for OSS alternatives.
MANDATORY READ: Load for MCP tool chain.
shared/references/research_tool_fallback.md如果没有审计报告:分析目标模块,在Context7/Ref中搜索OSS替代方案。
必读文档: 加载以获取MCP工具链相关信息。
shared/references/research_tool_fallback.mdPhase 2: Prioritize Replacements
阶段2:替换优先级排序
| Priority | Criteria |
|---|---|
| 1 (highest) | HIGH confidence + >200 LOC (max code reduction) |
| 2 | HIGH confidence + 100-200 LOC |
| 3 | MEDIUM confidence + >200 LOC |
| 4 | MEDIUM confidence + 100-200 LOC |
| Skip | LOW 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 reportFOR 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 reportAtomic Revert on Discard
丢弃时的原子化回滚
| Step | Revert Action |
|---|---|
| Package installed | Uninstall: |
| Files modified | |
| Lock file changed | |
| 步骤 | 回滚操作 |
|---|---|
| 已安装包 | 卸载: |
| 文件已修改 | |
| 锁文件已更改 | |
Safety Rules
安全规则
| Rule | Description |
|---|---|
| One module at a time | Never replace multiple modules simultaneously |
| No API signature changes | Public API of replaced module must stay compatible |
| Tests required | Skip module if no tests cover it (too risky) |
| Confidence gate | Skip LOW confidence replacements |
| 规则 | 描述 |
|---|---|
| 一次处理一个模块 | 禁止同时替换多个模块 |
| 不修改API签名 | 被替换模块的公共API必须保持兼容 |
| 必须有测试覆盖 | 如果模块没有测试覆盖则跳过(风险过高) |
| 置信度门槛 | 跳过低置信度的替换候选 |
Phase 4: Report Results
阶段4:生成结果报告
Report Schema
报告结构
| Field | Description |
|---|---|
| source | Audit report path or target module |
| candidates_total | Total replacement candidates |
| replacements_applied | Successfully replaced modules |
| replacements_discarded | Failed replacements with reasons |
| replacements_skipped | LOW confidence / no test coverage |
| loc_removed | Total lines of custom code removed |
| packages_added | New 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 replacementyaml
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 replacementError Handling
错误处理
| Error | Cause | Solution |
|---|---|---|
| Package not found | OSS package name changed | Search Context7/Ref for current name |
| API mismatch | OSS API differs from mapping | Query docs for correct API, attempt fix |
| Circular dependency | New package conflicts | Skip replacement, log as manual |
| No test coverage | Custom module untested | Skip (too risky for automated replacement) |
| 错误 | 原因 | 解决方案 |
|---|---|---|
| 包未找到 | OSS包名称已更改 | 在Context7/Ref中搜索当前名称 |
| API不匹配 | OSS API与映射不符 | 查询文档获取正确API,尝试修复 |
| 循环依赖 | 新包存在冲突 | 跳过该替换,记录为需手动处理 |
| 无测试覆盖 | 自定义模块未被测试覆盖 | 跳过(自动化替换风险过高) |
References
参考资料
- (companion: finds candidates)
../ln-645-open-source-replacer/SKILL.md - (test detection)
shared/references/ci_tool_detection.md - (MCP tool chain)
shared/references/research_tool_fallback.md
- (配套工具:寻找候选替换模块)
../ln-645-open-source-replacer/SKILL.md - (测试检测)
shared/references/ci_tool_detection.md - (MCP工具链)
shared/references/research_tool_fallback.md
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