skills/reverse-workflow/SKILL.md
Orchestrate the full reverse engineering pipeline: Extract provisional spec from existing code, refine through dialogue to uncover the true spec, then reconcile code with the confirmed spec. Optionally connects to the forward pipeline (verify → prove → generate → test). Triggered by: "reverse workflow", "extract and refine spec from code", "formalize existing code", "reverse engineer the specification", 「リバースワークフローで」「既存コードから仕様を起こして」「コードの仕様を明確にしたい」 「このプロジェクトを形式仕様で整理したい」「既存コードをリバースエンジニアリングして」
npx skillsauth add kotaroyamame/formal-agent-contracts reverse-workflowInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill orchestrates the full reverse engineering pipeline for formalizing existing code: Extract → Refine → Reconcile → (optionally) Verify → Prove → Generate → Test
Each phase invokes an existing skill, with automated handoff, error recovery, and a final session report summarizing all results.
この skill は既存コードを形式化するためのリバースエンジニアリング pipeline 全体をオーケストレートする。 各フェーズは既存スキルを呼び出し、フェーズ間の自動ハンドオフ、エラー回復、 最終セッションレポートの生成を行う。
┌─────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ 1. EXTRACT │────>│ 2. REFINE │────>│ 3. RECONCILE │────>│ 4. VERIFY │
│ 仮仕様抽出 │ │ 対話的磨き上げ │ │ コード照合 │ │ (既存スキル) │
└─────────────┘ └──────────────┘ └──────────────┘ └──────────────┘
▲ │ │
│ ▼ ▼
収束するまで 既存フォワード
サイクルを回す パイプラインへ接続
(verify/prove/generate/test)
Activate this skill when the user says any of:
┌──────────┐ ┌──────────┐ ┌────────────┐ ┌──────────┐ ┌──────────┐
│ 1.EXTRACT│───>│ 2.REFINE │───>│ 3.RECONCILE│───>│ 4.VERIFY │───>│ 5.PROVE │
│ 抽出 │ │ 磨き上げ │ │ 照合 │ │ 検証 │ │ 証明 │
└──────────┘ └──────────┘ └────────────┘ └──────────┘ └──────────┘
▲ │
└─┘
収束ループ
(forward pipeline
に接続可能)
Greet the user and explain the reverse workflow:
「リバースワークフロー」では、既存のコードから形式仕様を起こし、 対話を通じて真の仕様を明確にして、最後にコードと仕様を照合します。 4~7つのフェーズを順番に実行します。途中でスキップや中断も可能です。
Emphasize the core principle:
「コードから抽出した仕様は『仮の仕様』です。本当の仕様はあなたの頭の中にあります。」
Gather session parameters:
Initialize session state (track mentally, no files needed):
project_name: <name>
source_paths: [<paths>]
source_lang: ts | py | java | go | auto
provisional_spec_path: <to be determined>
confirmed_spec_path: <to be determined>
target_lang: ts | py | both
forward_pipeline: true | false
smt_enabled: true | false
phases_completed: []
セッションパラメータを収集し、内部状態を初期化する。
Invoke: extract-spec skill
.provisional.vdmsl file with all items tagged [PROVISIONAL]extract-specスキルの対話フローに従い、コード分析を実施する。
Handoff criteria → Phase 2:
.provisional.vdmsl file generatedError recovery:
Phase report:
📋 Phase 1 Complete: Provisional Spec Extraction
- File: <project_name>.provisional.vdmsl
- Types extracted: <count>
- Functions/Operations: <count>
- State variables: <count>
- Questions for user: <count>
- Confidence level: <High|Medium|Low>
Invoke: refine-spec skill
.vdmsl (no [PROVISIONAL] tags)refine-specスキルの対話フローに従い、仕様の明確化を実施する。
Convergence cycles: This phase may loop multiple times until:
[PROVISIONAL] items are classified (Confirmed/Modified/Removed/Unresolved)収束するまで複数回ループする場合がある。
Handoff criteria → Phase 3:
[PROVISIONAL] items classified.vdmsl file generated (no [PROVISIONAL] tags)Error recovery:
[UNRESOLVED] and continue with restPhase report:
📋 Phase 2 Complete: Specification Refinement
- Confirmed items: <count>
- Modified items: <count>
- Removed items: <count>
- Unresolved items: <count> (marked [UNRESOLVED])
- Convergence rounds: <count>
- Findings Report:
- Bugs: <count>
- Spec gaps: <count>
- Refinements: <count>
- Intentional: <count>
- Technical debt: <count>
Invoke: reconcile-code skill
.vdmsl specificationreconcile-codeスキルの対話フローに従い、コード照合を実施する。
Handoff criteria → Phase 4 (Forward Pipeline):
Error recovery:
Phase report:
📋 Phase 3 Complete: Code Reconciliation
- Diff report: ✅ Generated
- Code fixes: <count> issues identified
- Type mismatches: <count>
- Missing contracts: <count>
- Logic bugs: <count>
- Auto-generated tests: <count>
- Tests status: ✅ All passing (or ⚠️ <N> failing)
Invoke: verify-spec skill (from integrated-workflow)
Skip condition: User chose forward_pipeline: false in Phase 0, or user says "stop here".
If skipped, proceed directly to Session Report.
.vdmsl file (syntax check → type check → PO generation)既存のverify-specスキルを使用して、確認済み仕様を検証する。
Handoff criteria → Phase 5:
Error recovery:
Phase report:
📋 Phase 4 Complete: Specification Verification
- Syntax check: ✅ PASSED
- Type check: ✅ PASSED
- Proof Obligations: <total_count>
- Critical: <count>
- Standard: <count>
- Info: <count>
Invoke: smt-verify skill (from integrated-workflow)
Skip condition: User chose smt_enabled: false in Phase 0, or Z3 is not available.
If skipped, proceed directly to Phase 6 or Session Report.
.smt2 file既存のsmt-verifyスキルを使用して、PO を Z3 で証明する。
Handoff criteria → Phase 6:
Error recovery:
Phase report:
📋 Phase 5 Complete: SMT Automated Proving
- Total POs: <count>
- ✅ Proved: <count>
- ⚠️ Counterexample: <count>
- ℹ️ Unknown/Timeout: <count>
Invoke: generate-code skill (from integrated-workflow)
Skip condition: User chose not to generate new code in Phase 0. If skipped, proceed directly to Session Report.
既存のgenerate-codeスキルを使用して、確認済み仕様からコードを生成する。
Completion criteria:
Phase report:
📋 Phase 6 Complete: Code Generation & Testing
- Target: <language(s)>
- Files generated: <count>
- Types: <count>
- Functions: <count>
- Operations: <count>
- Smoke tests: <count>
- ✅ All tests passed
After all phases complete (or when the user stops), generate a comprehensive session report.
See references/reverse-session-report-template.md for the full template.
全フェーズ完了後(またはユーザーが中断した時点で)、包括的なセッションレポートを生成する。
Summary format:
═══════════════════════════════════════════════════
Reverse Workflow — Session Report
Project: <project_name>
Date: <date>
═══════════════════════════════════════════════════
Phase 1 — Extract: ✅ <N> types, <M> operations extracted
Phase 2 — Refine: ✅ <N> Findings (<bugs> bugs, <gaps> gaps)
Convergence: <rounds> rounds
Phase 3 — Reconcile: ✅ <N> fixes, <M> tests generated
Phase 4 — Verify: ✅ Syntax/Type OK, <N> POs (or ⏭ Skipped)
Phase 5 — Prove: ✅ <N>/<M> POs proved (or ⏭ Skipped)
Phase 6 — Generate: ✅ <lang> code generated (<N> files) (or ⏭ Skipped)
Findings Summary:
Bug: <count> → Code fixes generated
Spec Gap: <count> → New code generated
Spec Refinement: <count> → Conditions tightened
Intentional: <count> → Confirmed as-is
Debt: <count> → Recorded for future
Output files:
- Provisional spec: <path>.provisional.vdmsl
- Confirmed spec: <path>.vdmsl
- Findings report: <path>-findings.md
- Code fixes: <list of files>
- Generated tests: <path>
- Generated code: <path> (if Phase 6 run)
═══════════════════════════════════════════════════
Users can control the workflow at any point:
| Command | Action | |---------|--------| | 「次へ」/ "next" | Proceed to next phase | | 「戻る」/ "back" | Return to previous phase | | 「もう一周」/ "another round" | Re-run refine-spec cycle (Phase 2 only) | | 「ここまで」/ "stop here" | Generate partial report, stop | | 「フォワードに接続」/ "connect to forward" | Proceed to verify/prove/generate (if not already) | | 「状態を見せて」/ "status" | Show current phase and progress |
ユーザーはいつでもワークフローを制御できる。
Users may enter the workflow at any phase:
.provisional.vdmsl file.vdmsl file (confirmed)Detect the entry point from the user's request and available files.
ユーザーは任意のフェーズからワークフローに参加できる。
This skill acts as an orchestrator — it does not duplicate logic from other skills. Instead, it:
このスキルはオーケストレーターとして機能し、各フェーズの詳細は個別スキルに委譲する。
Reference the individual skill SKILL.md files for phase-specific details:
skills/extract-spec/SKILL.mdskills/refine-spec/SKILL.md (to be created)skills/reconcile-code/SKILL.md (to be created)skills/integrated-workflow/skills/formal-methods-guide/SKILL.mdskills/export-human-spec/SKILL.mdskills/import-natural-spec/SKILL.mdAfter the reverse workflow completes, offer the user the option to generate a
human-readable specification document using export-human-spec.
If the user's starting point is a natural language MD file rather than source code,
recommend import-natural-spec instead of this reverse workflow.
testing
VDM-SL仕様の型チェック、構文検証、証明責務生成を実行するスキル
testing
Convert VDM-SL proof obligations (POs) to SMT-LIB and verify them with the Z3 solver. Triggered by "prove POs", "verify with SMT", "check with Z3", "auto-verify proof obligations", "prove the spec is correct", or "find counterexamples". Also responds to Japanese: 「POを証明して」「SMTで検証して」「Z3で確認して」等。 Used as the next step after PO generation with verify-spec, or for end-to-end PO generation + SMT verification.
testing
Refine a provisional VDM-SL specification through dialogue with the user, uncovering the true specification that exists in the user's mind. The provisional spec (from extract-spec) serves as a scaffold for questions. Triggered by: "refine the spec", "review the provisional spec", 「仕様を磨きたい」「仮仕様をレビューして」「コードの意図を確認したい」「仕様を確認して」
development
Reconcile existing code with the confirmed VDM-SL specification. Compare spec vs code item-by-item, generate a diff report, produce code fixes prioritized by Finding category, and auto-generate tests. Triggered by: "reconcile code with spec", "fix code to match spec", 「仕様とコードを照合して」「コードを仕様に合わせて」「差分を出して」「コードを直して」