skills/extract-spec/SKILL.md
Extract a provisional VDM-SL specification from existing source code. This is NOT the true spec — it is a scaffold for dialogue to uncover the user's real intent. Triggered by: "extract spec from code", "reverse engineer the specification", "extract-spec", "code to spec", "formalize the existing code". Japanese: 「既存のコードから仕様を抽出して」「コードの仕様を形式化して」 「コードベースを分析して」「コードをリバースエンジニアリングして」
npx skillsauth add kotaroyamame/formal-agent-contracts extract-specInstall 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.
Extract structural and behavioral information from existing code and generate a PROVISIONAL VDM-SL specification as a starting point for dialogue with the user.
Critical principle: The spec extracted from code is NOT the true spec. It is a provisional
scaffold for dialogue. The true spec exists in the user's head. Every extracted item must be
tagged [PROVISIONAL] and framed as a question, not a statement.
既存のコードから構造情報と動作情報を抽出し、ユーザーとの対話の出発点となる 暫定的なVDM-SL仕様を生成する。
重要な原則: コードから抽出した仕様は「真の仕様」ではない。それはあくまで対話のための
暫定的な足がかりである。真の仕様はユーザーの頭の中に存在する。抽出した全ての項目には
[PROVISIONAL]というタグをつけ、陳述ではなく質問として表現する。
Ask the user which files or directories to analyze.
Questions to guide the scope:
ユーザーに、どのファイルまたはディレクトリを分析するかを質問する。
スコープを確定するための質問:
Read the code and extract candidates for:
Data Types
[T] candidatesFunctions and Operations
Constraints and Validation Logic
コードを読み込み、以下の候補を抽出する:
データ型
[T] の候補関数と操作
制約と検証ロジック
Convert extracted information to VDM-SL using the mapping rules in
references/code-to-vdmsl-mapping.md.
Tagging Requirements: Every extracted line MUST be tagged with one of:
[PROVISIONAL] — mechanically extracted from code, unconfirmed by user[QUESTION] — code behavior is questionable or ambiguous, user must confirm[IMPLICIT] — inferred from tests/comments/patterns, not explicitly in code[MISSING] — no corresponding code found, may need to be defined by userOutput format:
.provisional.vdmslExample:
-- [PROVISIONAL] Extracted from classes/user.ts lines 5-20
-- QUESTION: Is the email validation rule exactly as shown in the code?
types
Email = seq1 of char
inv email == email_valid(email)
<!-- 日本語 -->
references/code-to-vdmsl-mapping.md の変換ルールを使用して、抽出した情報を
VDM-SLに変換する。
タグ付けの要件: 抽出した全ての行には、以下のいずれかをタグとして付ける必要がある:
[PROVISIONAL] — コードから機械的に抽出、ユーザーにより未確認[QUESTION] — コードの動作が疑わしい、またはあいまい。ユーザーが確認する必要がある[IMPLICIT] — テスト/コメント/パターンから推論されたもの。コードに明示的にはない[MISSING] — 対応するコードが見つからない。ユーザーが定義する必要があるかもしれない出力形式:
.provisional.vdmsl例:
-- [PROVISIONAL] classes/user.ts lines 5-20から抽出
-- QUESTION: メール検証ルールはコードに示されているとおりですか?
types
Email = seq1 of char
inv email == email_valid(email)
List all ambiguous or unclear points as "Questions for User".
Categorization:
[UNCLEAR] — Code intent is unclear or ambiguous[AMBIGUOUS] — Multiple interpretations are possible[IMPLICIT] — Specification exists in tests or comments, not code[MISSING] — Feature appears in tests but not in implementationEach question should present:
Example:
[UNCLEAR] Type of `status` field in User class
Code:
class User { status: string }
Question:
- Is `status` constrained to specific values (e.g., "active", "inactive")?
- Should we define an enumeration?
- Or is any string value allowed?
Options:
- Quote union: Status = <ACTIVE> | <INACTIVE> | <PENDING>
- String with invariant: inv s == s in ["active", "inactive", "pending"]
- Unconstrained: seq1 of char
<!-- 日本語 -->
あいまいまたは不明瞭なポイントを全て「ユーザーへの質問」としてリストアップする。
分類:
[UNCLEAR] — コードの意図が不明瞭またはあいまい[AMBIGUOUS] — 複数の解釈が可能[IMPLICIT] — テストまたはコメントに仕様が存在。コードにはない[MISSING] — テストに表れているが実装されていない機能各質問には以下を含める:
例:
[UNCLEAR] Userクラスの `status` フィールドの型
コード:
class User { status: string }
質問:
- `status` は特定の値(例:"active"、"inactive")に制限されているか?
- 列挙型を定義すべきか?
- それとも、任意の文字列値が許容されるのか?
オプション:
- クォート合併型: Status = <ACTIVE> | <INACTIVE> | <PENDING>
- 不変条件を持つ文字列: inv s == s in ["active", "inactive", "pending"]
- 制約なし: seq1 of char
Produce a summary report covering:
What was extracted
What wasn't extracted
Confidence levels
Next steps
以下を含む概要レポートを生成する:
抽出したもの
抽出されなかったもの
信頼水準
次のステップ
Never present extracted specifications as confirmed facts. Always frame them as questions.
WRONG: "The User type has a required email field of type string." RIGHT: "[PROVISIONAL] Does the User type require an email field of type string?"
WRONG: "The updateUser operation takes a user ID and returns a boolean indicating success." RIGHT: "[QUESTION] Does the updateUser operation take a user ID and return a boolean (true=success, false=fail)?"
<!-- 日本語 -->抽出した仕様を確認された事実として提示してはいけない。常に質問として表現する。
悪い例: 「Userタイプには、型stringの必須メールフィールドがある。」 良い例: 「[PROVISIONAL] Userタイプに、型stringのメールフィールドが必須か?」
悪い例: 「updateUser操作は、ユーザーIDを受け取り、成功を示すブール値を返す。」 良い例: 「[QUESTION] updateUser操作は、ユーザーIDを受け取り、ブール値(true=成功、false=失敗)を返すか?」
If the code contains a logic bug, the extracted spec will reflect that bug. Inform the user:
"Note: The provisional spec reflects what the code currently does, not necessarily what it should do. If you notice discrepancies between the spec and intended behavior, those may indicate bugs in the code that should be fixed."
<!-- 日本語 -->コードにロジックバグが含まれている場合、抽出した仕様もそのバグを反映する。 ユーザーに以下を伝える:
「注意: 暫定仕様は、コードが現在やっていることを反映しており、 それがすべきこととは限りません。仕様と意図された動作の間に 矛盾に気づいた場合、それはコードの中のバグを示している可能性があり、 修正すべきです。」
After extraction is complete, strongly recommend proceeding to the refine-spec skill for dialogue with the user. The refine-spec skill is designed to:
抽出が完了したら、ユーザーとの対話のためにrefine-specスキルに進むことを 強く推奨する。refine-specスキルは以下のように設計されている:
For detailed code-to-VDM-SL mapping rules, see references/code-to-vdmsl-mapping.md.
For VDM-SL syntax and formal methods concepts, refer to the formal-methods-guide skill.
<!-- 日本語 -->詳細なコードからVDM-SLへのマッピングルールについては、
references/code-to-vdmsl-mapping.md を参照してください。
VDM-SLの文法と形式手法の概念については、formal-methods-guideスキルを 参照してください。
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.
development
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", 「リバースワークフローで」「既存コードから仕様を起こして」「コードの仕様を明確にしたい」 「このプロジェクトを形式仕様で整理したい」「既存コードをリバースエンジニアリングして」
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", 「仕様を磨きたい」「仮仕様をレビューして」「コードの意図を確認したい」「仕様を確認して」