safe-extraction

Coordinate code extraction from monolithic files while preserving APIs, DI seams, and CI validity.

437|45|Updated Jan 27, 2026
One-click install
npx skills add https://github.com/ZaxbyHub/opencode-swarm --skill safe-extraction
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: safe-extraction
Source: https://github.com/ZaxbyHub/opencode-swarm/tree/main/.opencode/skills/generated/safe-extraction
Command: npx skills add https://github.com/ZaxbyHub/opencode-swarm --skill safe-extraction

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Extracting code from large monolith files frequently causes CI invariant check failures, broken dependency injection seams used for test mocking, and cross-file test regressions. This Skill provides a step-by-step safety-first protocol to eliminate these common refactoring risks.

Core Features & Use Cases

  • Barrel re-export management: Preserves existing public API import paths so no downstream consumer code requires updates.
  • _internals DI seam preservation: Maintains test mockability for extracted functions via getter/setter proxy patterns.
  • CI and test verification: Automates updates to CI path allowlists and validates full cross-file test compatibility post-extraction.
  • Use Case: When splitting a 2000+ line guardrails module into dedicated submodules for a TypeScript OpenCode plugin, this Skill ensures all existing imports resolve, test mocks continue to work, and CI quality gates pass without manual intervention.

Quick Start

Use the safe-extraction skill to split the oversized src/hooks/guardrails.ts file into modular subfiles while preserving all existing functionality and test coverage.

Frequently Asked Questions about safe-extraction

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I split monolith files into submodules without breaking existing imports?

To split monolith files safely, you preserve existing public API import paths via explicit barrel re-exports. This approach ensures downstream consumer code resolves imports correctly without requiring manual updates across the codebase.

Why do my test mocks break when extracting code into separate modules?

Test mocks break during code extraction when dependency injection seams are not preserved. Maintaining test mockability requires implementing getter/setter proxy patterns, such as an _internals proxy, to keep test mocking functional across the newly separated submodules.

How do I update CI path allowlists when relocating code between modules?

When relocating code between modules, CI path allowlists must be updated to recognize the new submodule locations. Automating these CI quality gate updates prevents invariant check failures and ensures the continuous integration build passes.

What is the best way to refactor oversized TypeScript files without causing test regressions?

The best way to refactor oversized TypeScript files without test regressions is to validate full cross-file test compatibility post-extraction. This involves verifying that dependency injection seams and barrel exports function identically before and after the split.

Does code extraction alter runtime behavior when splitting large monolith files?

Proper code extraction does not alter runtime behavior when splitting large monolith files. By preserving public APIs via barrel re-exports and maintaining dependency injection seams, the refactoring process safely relocates code without changing execution logic.