skills/reconcile-code/SKILL.md
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", 「仕様とコードを照合して」「コードを仕様に合わせて」「差分を出して」「コードを直して」
npx skillsauth add kotaroyamame/formal-agent-contracts reconcile-codeInstall 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 reconciles existing code with a confirmed VDM-SL specification through systematic comparison, generates diff reports, produces prioritized code fixes, and auto-generates comprehensive tests.
このスキルは、確認済みのVDM-SL仕様との間で既存コードを体系的に比較し、差分レポートを生成し、優先度付きコード修正を生成し、包括的なテストを自動生成します。
EN: For each VDM-SL type definition in the confirmed spec, locate the corresponding code type (TypeScript interface/type, Python dataclass, etc.):
JP: 確認済み仕様のVDM-SL型定義ごとに、対応するコード型(TypeScriptインターフェース/型、Pythonデータクラスなど)を見つけます:
Status Codes:
EN: For each VDM-SL pre-condition (guards in the function specification), find the corresponding code implementation:
JP: VDM-SL仕様の各前提条件(関数仕様のガード)について、対応するコード実装を見つけます:
Status Codes:
EN: For each VDM-SL post-condition (expected behavior after operation), verify the code implements it:
JP: VDM-SL仕様の各後提条件(操作後の期待される動作)について、コードがそれを実装していることを確認します:
Status Codes:
EN: For each VDM-SL class invariant, identify where validation must occur:
JP: VDM-SLクラス不変式ごとに、検証が必要な場所を特定します:
Status Codes:
Present results in a formatted table:
┌─────────────────────┬──────────┬─────────────────────┬─────────────┐
│ Spec Item │ Status │ Code Location │ Note │
├─────────────────────┼──────────┼─────────────────────┼─────────────┤
│ User (Type) │ ✅ Match │ src/User.ts:10-25 │ - │
│ createUser (Pre) │ ❌ Mis │ src/User.ts:30 │ Missing null│
│ createUser (Post) │ ⚠️ Part │ src/User.ts:30-40 │ Partial ID │
│ UserInvariant │ 🔍 Found │ - │ No check │
└─────────────────────┴──────────┴─────────────────────┴─────────────┘
EN: Code behavior differs from confirmed spec, causing runtime failures or incorrect results:
For each Bug Finding:
Example structure:
Bug Fix #1: createUser() pre-condition validation missing
Finding: BUG-001 [Confidence: High]
Spec requirement: User email must be non-empty string
Code issue: No email validation before DB insert
Location: src/User.ts:35-45
Before:
```typescript
function createUser(user: any) {
return db.insert(user);
}
After:
function createUser(user: User) {
if (!user.email || user.email.trim() === '') {
throw new ValidationError('Email is required and must be non-empty');
}
return db.insert(user);
}
JP: コード動作が確認済み仕様と異なり、実行時エラーまたは不正な結果を引き起こす:
EN: Spec defines behavior but code lacks implementation:
For each Spec Gap Finding:
JP: 仕様は動作を定義していますが、コードは実装を欠いています:
EN: Strengthen types to prevent potential issues:
JP: 潜在的な問題を防ぐための型の強化:
Each fix must include:
finding_id: BUG-001 or SPEC-GAP-002 or TYPE-SAFE-003
spec_reference: "User :: createUser pre-condition"
affected_file: src/User.ts
line_range: 35-45
severity: High | Medium | Low
confidence: High | Medium | Low
before_code: |
function createUser(user: any) { ... }
after_code: |
function createUser(user: User) { ... }
explanation: "Added email validation guard missing from pre-condition"
EN: For each pre-condition, generate tests covering:
Valid input test — Operation succeeds without throwing
test_<operationName>_with_valid_inputs_succeedsPre-condition violation tests — Each condition creates a separate test
test_<operationName>_violates_<conditionName>_throws_<ErrorType>Boundary value tests — Test limits of pre-condition
test_<operationName>_<conditionName>_boundary_<value>Example (Jest):
describe('User.createUser pre-conditions', () => {
test('valid input succeeds', () => {
const user = { email: '[email protected]', name: 'Test' };
expect(() => User.createUser(user)).not.toThrow();
});
test('empty email throws ValidationError', () => {
const user = { email: '', name: 'Test' };
expect(() => User.createUser(user))
.toThrow(ValidationError);
expect(() => User.createUser(user))
.toThrow('Email is required');
});
test('null email throws ValidationError', () => {
const user = { email: null, name: 'Test' };
expect(() => User.createUser(user))
.toThrow(ValidationError);
});
});
JP: 各前提条件について、以下をカバーするテストを生成:
EN: For each post-condition, generate tests:
Valid input verification — Return value matches post-condition
test_<operationName>_returns_correct_<property>State change verification — State mutations match post-condition
test_<operationName>_state_mutation_<stateName>Example (Jest):
describe('User.createUser post-conditions', () => {
test('returns user with assigned ID', () => {
const user = { email: '[email protected]', name: 'Test' };
const result = User.createUser(user);
expect(result).toHaveProperty('id');
expect(typeof result.id).toBe('string');
});
test('persists user to database', () => {
const user = { email: '[email protected]', name: 'Test' };
const result = User.createUser(user);
const retrieved = User.findById(result.id);
expect(retrieved).toEqual(result);
});
});
JP: 各後提条件について:
EN: For each invariant, generate:
Valid construction test — Object created with valid state
test_<className>_valid_construction_succeedsInvariant violation at construction — Invalid construction fails
test_<className>_violates_<invariantName>_at_construction_failsInvariant violation at mutation — Attempted mutation rejected
test_<className>_mutation_violates_<invariantName>_rejectedExample (Jest):
describe('User invariants', () => {
test('valid user construction succeeds', () => {
const user = new User('[email protected]', 'Test', 18);
expect(user.email).toBe('[email protected]');
expect(user.age).toBeGreaterThanOrEqual(0);
});
test('negative age at construction fails', () => {
expect(() => new User('[email protected]', 'Test', -1))
.toThrow('Age must be non-negative');
});
test('setting negative age rejected', () => {
const user = new User('[email protected]', 'Test', 18);
expect(() => { user.age = -1; })
.toThrow('Age must be non-negative');
});
});
JP: 各不変式について:
EN: For each Bug or Spec Gap Finding:
Regression test — Tests that the bug fix works
New behavior test — Tests the newly implemented feature
Example:
describe('Bug Fix: BUG-001 - Email validation missing', () => {
test('regression: empty email now properly rejected', () => {
const user = { email: '', name: 'Test' };
expect(() => User.createUser(user))
.toThrow(ValidationError);
});
test('regression: whitespace-only email rejected', () => {
const user = { email: ' ', name: 'Test' };
expect(() => User.createUser(user))
.toThrow(ValidationError);
});
});
describe('Spec Gap Fill: SPEC-GAP-001 - User password validation', () => {
test('password must be at least 8 characters', () => {
const user = { email: '[email protected]', password: 'short' };
expect(() => User.createUser(user))
.toThrow(/at least 8 characters/);
});
});
JP: 各Bug または Spec Gap Finding について:
Detect the test framework from:
Generate tests using the detected framework's syntax and conventions.
Generate a comprehensive summary:
EN:
# Reconciliation Report: [Project Name]
## Executive Summary
- Total spec items analyzed: N
- Matched: N (X%)
- Partial matches: N (X%)
- Mismatches: N (X%)
- Not found: N (X%)
## Finding Summary
- Bug Fixes (High priority): N
- Spec Gap Fills (Medium priority): N
- Type Safety Improvements (Low priority): N
## Test Generation Summary
- Pre-condition tests generated: N
- Post-condition tests generated: N
- Invariant tests generated: N
- Finding-specific tests generated: N
- Total tests generated: N
## Files Modified
- src/File1.ts (N fixes)
- src/File2.ts (N fixes)
- test/File1.test.ts (new file, N tests)
## Detailed Findings
[List each finding with details]
## Remaining Manual Work
[Identify any items that require manual review]
JP:
# 照合レポート: [プロジェクト名]
## エグゼクティブサマリー
- 分析された仕様項目の合計: N
- 一致: N (X%)
- 部分一致: N (X%)
- 不一致: N (X%)
- 見つからない: N (X%)
## 調査結果の要約
- バグ修正(高優先度): N
- 仕様ギャップ埋め(中優先度): N
- 型安全性改善(低優先度): N
## テスト生成の要約
- 生成された前提条件テスト: N
- 生成された後提条件テスト: N
- 生成された不変式テスト: N
- 生成された調査結果特定テスト: N
- 生成されたテスト合計: N
## 修正されたファイル
- src/File1.ts (N修正)
- src/File2.ts (N修正)
- test/File1.test.ts (新規ファイル、Nテスト)
## 詳細な調査結果
[各調査結果の詳細をリスト]
## 残りの手動作業
[手動レビューが必要な項目を特定]
EN:
JP:
EN:
JP:
This skill is designed to work with:
formal-agent-contracts/plugin.json — loads confirmed spec findingsv1.3.0 (Current)
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", 「仕様を磨きたい」「仮仕様をレビューして」「コードの意図を確認したい」「仕様を確認して」