| name | modularize |
| description | Cache-aware task decomposition โ split large coding tasks into independent modules, define interface contracts, schedule execution waves, and execute each module as an isolated Reasonix subagent. Invoke when user needs to break down a complex task, build a multi-module system, or wants structured contract-driven development. |
| argument-hint | <task description or command> |
| allowed-tools | ["Read","Write","Bash","Glob","Grep","Edit","WebFetch"] |
Split large coding tasks into independent modules executed as Reasonix subagents. All modules share a byte-stable SYSTEM prefix (prefix.md) so DeepSeek's prefix cache hits across subagent sessions.
Five phases: analyze โ contracts โ schedule โ execute โ integrate.
On failure: only re-run the broken module + its downstream dependents.
Workflow files in `phases/`, templates in `templates/`, references in `reference/` โ available if more detail is needed, but the core instructions are here.
Phase 1: Task Analysis โ Module Decomposition
Trigger: natural language task description or /decompose
Step 1 โ Scout existing context
- Read
.reasonix/modules/prefix.md and .reasonix/modules/plan.json if they exist (resume or recursive split)
- Run
ls -R src/ to see existing code
Step 2 โ Propose module decomposition
Analyze the user's task and identify functional module boundaries.
Principles:
- Each module = one cohesive feature unit (e.g. "user auth", not "auth.ts file")
- Minimal inter-module dependencies
- Shared infrastructure (db, logging) splits first
- Mark oversized modules as recursive-splittable
Output format:
ๆๅๆไบไฝ ็ไปปๅก๏ผๅปบ่ฎฎๆๆไปฅไธๆจกๅ๏ผ
โโโ database โโโ
โ โโโโบ auth โโโ
โโโโโโโโโโโโโโโโ โโโโบ api โโโบ frontend
โ
โโโ storage โโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโ
| ๆจกๅ | ่่ดฃ | ไพ่ต | ๅคๆๅบฆ |
|------|------|------|--------|
| database | ๆฐๆฎๅบ่ฟๆฅใๆฅ่ฏขๅฐ่ฃ
| ๆ | medium |
| storage | ๆไปถๅญๅจ | ๆ | low |
| auth | ๆณจๅใ็ปๅฝใ้ดๆ | database | medium |
| api | REST ๆฅๅฃๅฑ | auth, storage | high |
| frontend | ๅ็ซฏ้กต้ข | api | high |
็กฎ่ฎค๏ผ
Step 3 โ Write plan.json on confirmation
Path: .reasonix/modules/plan.json
{
"task_id": "<kebab-case>",
"task_description": "<original task>",
"modules": [
{ "name": "database", "depends_on": [], "complexity": "medium" },
{ "name": "auth", "depends_on": ["database"], "complexity": "medium" }
],
"waves": [],
"status": "analyzed",
"created_at": "<ISO timestamp>"
}
If the user's description is too vague โ ask clarifying questions. Do not guess.
Phase 2: Interface Contracts + Shared Prefix
Trigger: user says "OK" after Phase 1, or /contracts
Step 1 โ Load templates
Read templates/contract.template.md and templates/prefix.template.md for the exact format.
Step 2 โ Generate contracts per module
For each module (topological order โ root dependencies first):
Generate contracts/<module>.md containing:
- Type definitions in ```typescript blocks โ machine-parseable
- Interface signatures โ export function signatures exactly as they'll appear in code
- Behavior descriptions โ what each function does, inputs, outputs, errors, edge cases
- Upstream dependency interfaces โ copy-pasted from upstream module contracts (not from memory)
- npm Dependencies โ list every npm package this module needs. Prefer pure-JS packages (no native addons). If native is unavoidable, prefer
sql.js over better-sqlite3. Node.js built-ins (fs, path, crypto) do NOT count as dependencies.
Show each contract to the user for review. Allow batch approval if user prefers.
Step 3 โ Generate prefix.md
After all contracts are approved, generate prefix.md:
CRITICAL: prefix.md contains ONLY project overview + conventions. No module-specific content.
- Project description, tech stack, directory structure
- Coding conventions (indentation, naming, imports, error handling)
- Module list (just names + status, no contract details)
- NO timestamps, NO session IDs, NO dynamic content
Why: prefix.md is the byte-stable SYSTEM prompt shared across all subagent sessions. It must be identical everywhere. Module contracts go in USER messages.
Step 4 โ Update plan.json
status โ contracted
Phase 3: Dependency Graph โ Wave Scheduling
Trigger: user says "OK" after Phase 2, or /schedule
Kahn algorithm:
- Compute in-degree for each module (how many dependencies)
- Modules with in-degree == 0 โ Wave 0
- Remove Wave 0 modules, decrement in-degrees of dependents
- New in-degree == 0 โ Wave 1
- Repeat until all assigned
- If modules remain โ cycle detected โ report error
Output:
ๆง่ก่ฎกๅ๏ผๅ
ฑ 4 ๆณข๏ผ๏ผ
Wave 0 (ๅฏๅนถ่ก): database, storage
Wave 1: auth
Wave 2: api
Wave 3: frontend
็กฎ่ฎค๏ผ
On confirmation: write waves to plan.json, status โ ready.
Pre-flight: Dependency Installation
Trigger: immediately after Phase 3 is confirmed, before Phase 4 starts.
No user interaction required โ this step is automatic.
Step 1 โ Collect all dependencies
Read every contracts/<module>.md, extract the ## npm ไพ่ต section from each. Merge into a single dependency list (deduplicate, take highest version).
Step 2 โ Install once
Run npm install <merged-packages> (or update package.json first, then npm install). This installs ALL module dependencies in ONE shot. Subagents will NOT run npm install themselves.
Step 3 โ Verify
npm ls to confirm all packages are installed. If any native addon fails to compile โ switch to pure-JS alternative and update the relevant contract.
Phase 4: Subagent Execution (CORE)
Trigger: user says "OK" after Phase 3, or /execute [module] or /execute-all
/execute-all โ Auto wave execution
For each wave in order:
For each module in wave:
1. Check upstream deps are completed (outputs/<dep>/result.md exists)
2. Generate subagent skill: .reasonix/modules/skills/modularize-<module>.md (see template below)
3. Invoke run_skill modularize-<module>
4. Subagent contract goes into SYSTEM prompt โ first subagent caches it, rest hit cache
5. Verify output: outputs/<module>/result.md exists + contract compliance
6. Update plan.json module status
7. Report progress
CRITICAL: Subagents must NOT run npm install. Dependencies already installed in Pre-flight. If a subagent needs a missing package, abort and report it โ the contract must be updated.
/execute โ Single module
Same flow. Check upstream deps first.
/revise โ Recovery
- Identify failed module
- Check if contract or deps need fixing
- If new deps needed โ run Pre-flight again
- Regenerate subagent skill, re-execute
- Then /execute-all to pick up downstream
Subagent skill template
When generating .reasonix/modules/skills/modularize-<module>.md:
---
description: "Implement the <module> module for <task_id>. Only write code, do not run npm install."
runAs: subagent
---
# Implement <module>
## Contract (MUST follow exactly)
```typescript
<copy ONLY the interface signatures + type definitions from contracts/<module>.md>
Upstream Outputs
<for each upstream dep: copy its result.md "Interface Summary" section verbatim>
Hard Rules
- Write ONLY the files listed in the contract
- Use ONLY the upstream interfaces declared above โ no private imports
- NEVER run
npm install โ all deps already installed
- NEVER run
npm test โ typecheck only: npx tsc --noEmit
- After implementation: write outputs//result.md per templates/result.template.md
- Write key decisions to project memory via /remember
### Progress reporting format
โ
auth ๅฎๆ โ ๆฅๅฃๅ
จ้จ็ฌฆๅๅฅ็บฆ
่ฟๅบฆ: Wave 1/3 โ 2/5 ๆจกๅ
ไธไธไธช: api
ๅๅค OK ็ปง็ปญ๏ผๆ /execute
## Phase 5: Integration Verification
**Trigger:** all modules completed, or `/integrate`
### Step 1 โ Per-module contract verification
For each module, compare:
- `contracts/<module>.md` โ what was promised
- `outputs/<module>/result.md` โ what was delivered
Output mismatch report:
้ๆ้ช่ฏๆฅๅ
โโโโโโโโโโโโโโโโโโโโ
โ
database โ ๅ
จ้จๅน้
โ
storage โ ๅ
จ้จๅน้
โ ๏ธ auth โ register ็ญพๅๅคไบๅฏ้ๅๆฐ name
โ
api โ ๅ
จ้จๅน้
็ปๆ: 4/5 ้่ฟ๏ผ1 ้ไฟฎๅค โ /revise auth
### Step 2 โ Upstream/downstream chain check
Verify that downstream module imports match upstream module exports.
### Step 3 โ Finalize
All pass โ `plan.json` status โ `done`.
Partial failures โ mark failed modules, prompt `/revise`.
## /status โ Check progress
Read `plan.json`, display:
- Task name + status
- Per-module status (pending โ in_progress โ completed โ failed)
- Current wave / total waves
- Suggested next action
</process>
<success_criteria>
- Task decomposed into functional modules with clear dependency graph
- All contracts defined with TypeScript signatures + behavior descriptions
- prefix.md is byte-stable (no timestamps, no dynamic content, no module details)
- Execution runs in waves via isolated subagents
- Cache hits sustained across subagent sessions (prefix.md unchanged)
- Integration verification passes all contracts
- On failure: only broken module + downstream re-run
</success_criteria>