ワンクリックで
recipe-reverse-engineer
Generate PRD and Design Docs from existing codebase through discovery, generation, verification, and review.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Generate PRD and Design Docs from existing codebase through discovery, generation, verification, and review.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Anti-pattern detection, root-cause discipline, quality check workflow, and implementation completeness assurance. Use when: fixing bugs, reviewing code quality, refactoring, making technical decisions, or performing quality assurance.
Language-agnostic coding standards for maintainability, readability, and quality. Use when: implementing features, refactoring code, reviewing code quality, or writing functions.
Documentation creation criteria for PRD, ADR, Design Doc, UI Spec, and Work Plan with templates. Use when: creating or reviewing technical documents, determining which documents are required, or following document templates.
Implementation strategy selection framework with meta-cognitive approach. Use when: planning implementation strategy, selecting between vertical/horizontal slicing, or defining verification criteria for tasks.
Integration and E2E test design principles, value-based selection, test skeleton specification, and review criteria. Use when: designing integration tests, E2E tests, generating test skeletons, or reviewing test quality.
Guides subagent coordination through implementation workflows. Use when: orchestrating multiple agents, managing workflow phases, determining autonomous execution mode, or coordinating recipe execution.
| name | recipe-reverse-engineer |
| description | Generate PRD and Design Docs from existing codebase through discovery, generation, verification, and review. |
documentation-criteria — document creation rules and templatesai-development-guide — AI development patternssubagents-orchestration-guide — agent coordination and workflow flowsllm-friendly-context — clear prompts, handoffs, and generated artifactsSpawn rule: every spawn_agent call uses fork_turns="none" so the subagent receives only the task message and explicitly provided context.
Context: Reverse engineering workflow to create documentation from existing code
Target: $ARGUMENTS
Core Identity: "I am not a worker. I am an orchestrator."
Execution Protocol:
$STEP_N_OUTPUT as-is to sub-agents -- the orchestrator bridges data without processing or filtering it, except for steps that explicitly define a deterministic transformation with an input schema, output schema, and mapping rulesTask Registration: Register phases first, then steps within each phase as you enter it. Track status for each step.
Ask the user to confirm:
docs/prd/ or existing PRD directorydocs/design/ or existing design directoryPhase 1: PRD Generation
Step 1: Scope Discovery (unified, single pass -> group into PRD units -> human review)
Step 2-5: Per-unit loop (Generation -> Verification -> Review -> Revision)
Phase 2: Design Doc Generation (if requested)
Step 6: Design Doc Scope Mapping (reuse Step 1 results, no re-discovery)
Step 7-10: Per-unit loop (Generation -> Verification -> Review -> Revision)
Register tasks:
Spawn scope-discoverer agent: "Discover functional scope targets in the codebase. target_path: $USER_TARGET_PATH. reference_architecture: $USER_RA_CHOICE. focus_area: $USER_FOCUS_AREA (if specified)."
Store output as: $STEP_1_OUTPUT
Quality Gate:
$STEP_1_OUTPUT.prdUnits existssourceUnits across prdUnits (flattened, deduplicated) match the set of discoveredUnits IDs — no unit missing, no unit duplicatedunitInventory has at least one non-empty category. If all categories are empty, re-run discovery with focus on that unit[STOP — BLOCKING] If human review enabled: Present $STEP_1_OUTPUT.prdUnits with their source unit mapping to user for confirmation.
CANNOT proceed until user explicitly confirms.
FOR each unit in $STEP_1_OUTPUT.prdUnits (sequential, one unit at a time):
Spawn prd-creator agent: "Create reverse-engineered PRD for the following feature. Operation Mode: reverse-engineer. External Scope Provided: true. Feature: $PRD_UNIT_NAME. Description: $PRD_UNIT_DESCRIPTION. Related Files: $PRD_UNIT_COMBINED_RELATED_FILES. Entry Points: $PRD_UNIT_COMBINED_ENTRY_POINTS. Source Units: $PRD_UNIT_SOURCE_UNITS. Use provided scope as an investigation starting point. If tracing entry points reveals directly connected files outside this scope, include them. Create final version PRD based on thorough code investigation."
Store output as: $STEP_2_OUTPUT (PRD path)
Prerequisite: $STEP_2_OUTPUT (PRD path from Step 2)
Spawn code-verifier agent: "Verify consistency between PRD and code implementation. doc_type: prd. document_path: $STEP_2_OUTPUT. verbose: false."
Store output as: $STEP_3_OUTPUT
Quality Gate:
Required Input: $STEP_3_OUTPUT (verification data from Step 3)
Spawn document-reviewer agent: "Review the following PRD considering code verification findings. doc_type: PRD. target: $STEP_2_OUTPUT. mode: composite. code_verification: $STEP_3_OUTPUT. Additional Review Focus: Alignment between PRD claims and verification evidence, resolution recommendations for each discrepancy, completeness of undocumented feature coverage."
Store output as: $STEP_4_OUTPUT
Trigger Conditions (any one of the following):
$STEP_3_OUTPUTSpawn prd-creator agent: "Update PRD based on review feedback and code verification results. Operation Mode: update. Existing PRD: $STEP_2_OUTPUT. Review Feedback: $STEP_4_OUTPUT. Code Verification Results: $STEP_3_OUTPUT. Address discrepancies by severity. Critical and major items require correction. Minor items: correct if straightforward, otherwise leave as-is with rationale."
Loop Control: Maximum 2 revision cycles. After 2 cycles, flag for human review regardless of status. ENFORCEMENT: Exceeding 2 revision cycles without flagging produces unreviewed output.
Next: Proceed to next unit. After all units -> Phase 2.
Execute only if Design Docs were requested in Step 0
Register tasks:
Step type: Deterministic transformation step executed by the orchestrator.
No additional discovery required. Use $STEP_1_OUTPUT.discoveredUnits (implementation-granularity units) for technical profiles. Use $STEP_1_OUTPUT.prdUnits[].sourceUnits to trace which discovered units belong to each PRD unit.
Default mapping rule: Each PRD unit maps to exactly 1 Design Doc unit.
Only split one PRD unit into multiple Design Doc units when BOTH are true:
If the split conditions are not clearly met, keep 1 PRD unit -> 1 Design Doc unit.
Transform $STEP_1_OUTPUT into $STEP_6_OUTPUT using only the mapping rules in this step.
Map PRD units to Design Doc generation targets by resolving each PRD unit's sourceUnits back to $STEP_1_OUTPUT.discoveredUnits, carrying forward:
technicalProfile.primaryModules -> Primary FilestechnicalProfile.publicInterfaces -> Public Interfacesdependencies -> DependenciesrelatedFiles -> Scope boundaryunitInventory -> Unit InventoryStore output as: $STEP_6_OUTPUT
$STEP_6_OUTPUT MUST be a JSON array of Design Doc generation targets in the following shape:
[
{
"unitId": "DD-001",
"parentPrdUnitId": "PRD-001",
"unitName": "Authentication",
"unitDescription": "Current implementation for sign-in and session management",
"sourceUnits": ["UNIT-001", "UNIT-002"],
"primaryModules": ["src/auth/service.ts", "src/auth/controller.ts"],
"publicInterfaces": ["AuthService.login()", "AuthController.handleLogin()"],
"dependencies": ["UNIT-003"],
"scopeBoundary": ["src/auth/*"],
"unitInventory": {
"routes": [],
"testFiles": [],
"publicExports": []
},
"mappingRationale": "Default 1:1 mapping from PRD unit because technical scope is cohesive"
}
]
Quality Gate:
$STEP_6_OUTPUT item$STEP_6_OUTPUT item references only discovered units from its parent PRD unitmappingRationale explicitly states whether the mapping is default 1:1 or an intentional splitFOR each unit in $STEP_6_OUTPUT (sequential, one unit at a time):
Scope: Document current architecture as-is. This is a documentation task, not a design improvement task.
Spawn technical-designer agent: "Create Design Doc for the following feature based on existing code. Operation Mode: reverse-engineer. Feature: $UNIT_NAME. Description: $UNIT_DESCRIPTION. Primary Files: $UNIT_PRIMARY_MODULES. Public Interfaces: $UNIT_PUBLIC_INTERFACES. Dependencies: $UNIT_DEPENDENCIES. Unit Inventory: $UNIT_INVENTORY. Parent PRD: $APPROVED_PRD_PATH. Document current architecture as-is. Use Unit Inventory as the completeness baseline."
Store output as: $STEP_7_OUTPUT
Spawn code-verifier agent: "Verify consistency between Design Doc and code implementation. doc_type: design-doc. document_path: $STEP_7_OUTPUT. verbose: false."
Store output as: $STEP_8_OUTPUT
Required Input: $STEP_8_OUTPUT (verification data from Step 8)
Spawn document-reviewer agent: "Review the following Design Doc considering code verification findings. doc_type: DesignDoc. target: $STEP_7_OUTPUT. mode: composite. code_verification: $STEP_8_OUTPUT. Parent PRD: $APPROVED_PRD_PATH. Additional Review Focus: Technical accuracy of documented interfaces, consistency with parent PRD scope, completeness of unit boundary definitions."
Store output as: $STEP_9_OUTPUT
Trigger Conditions (same as Step 5):
$STEP_8_OUTPUTSpawn technical-designer agent: "Update Design Doc based on review feedback and code verification results. Operation Mode: update. Existing Design Doc: $STEP_7_OUTPUT. Review Feedback: $STEP_9_OUTPUT. Code Verification Results: $STEP_8_OUTPUT. Address discrepancies by severity. Critical and major items require correction. Minor items: correct if straightforward, otherwise leave as-is with rationale."
Loop Control: Maximum 2 revision cycles. After 2 cycles, flag for human review regardless of status.
Next: Proceed to next unit. After all units -> Final Report.
Output summary including:
| Error | Action |
|---|---|
| Discovery finds nothing | Ask user for project structure hints |
| Generation fails | Log failure, continue with other units, report in summary |
| consistencyScore < 50 | [STOP — BLOCKING] Flag for mandatory human review. CANNOT proceed until user explicitly confirms. |
| Review rejects after 2 revisions | Stop loop, flag for human intervention |