musubix 3.4.5 → 3.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/AGENTS.md +949 -0
- package/.github/prompts/sdd-change-apply.prompt.md +283 -0
- package/.github/prompts/sdd-change-archive.prompt.md +241 -0
- package/.github/prompts/sdd-change-init.prompt.md +269 -0
- package/.github/prompts/sdd-design.prompt.md +250 -0
- package/.github/prompts/sdd-implement.prompt.md +387 -0
- package/.github/prompts/sdd-requirements.prompt.md +193 -0
- package/.github/prompts/sdd-review.prompt.md +155 -0
- package/.github/prompts/sdd-security.prompt.md +228 -0
- package/.github/prompts/sdd-steering.prompt.md +269 -0
- package/.github/prompts/sdd-tasks.prompt.md +255 -0
- package/.github/prompts/sdd-test.prompt.md +230 -0
- package/.github/prompts/sdd-validate.prompt.md +304 -0
- package/.github/skills/musubix-adr-generation/SKILL.md +209 -0
- package/.github/skills/musubix-best-practices/SKILL.md +315 -0
- package/.github/skills/musubix-c4-design/SKILL.md +162 -0
- package/.github/skills/musubix-code-generation/SKILL.md +237 -0
- package/.github/skills/musubix-domain-inference/SKILL.md +196 -0
- package/.github/skills/musubix-ears-validation/SKILL.md +161 -0
- package/.github/skills/musubix-sdd-workflow/SKILL.md +217 -0
- package/.github/skills/musubix-technical-writing/SKILL.md +444 -0
- package/.github/skills/musubix-test-generation/SKILL.md +212 -0
- package/.github/skills/musubix-traceability/SKILL.md +141 -0
- package/AGENTS.md +1134 -0
- package/LICENSE +21 -0
- package/README.ja.md +313 -0
- package/README.md +315 -50
- package/bin/musubix-mcp.js +15 -0
- package/bin/musubix.js +9 -1
- package/docs/API-REFERENCE.md +1425 -0
- package/docs/GITHUB-ACTIONS-NPM-SETUP.md +132 -0
- package/docs/INSTALL-GUIDE.ja.md +459 -0
- package/docs/INSTALL-GUIDE.md +459 -0
- package/docs/MIGRATION-v3.0.md +324 -0
- package/docs/MUSUBI-enhancement_roadmap_20260105.md +651 -0
- package/docs/MUSUBIX-v3.0-User-Guide.md +1357 -0
- package/docs/MUSUBIXv2.2.0-Manual-outline.md +136 -0
- package/docs/MUSUBIXv2.2.0-Manual.md +3123 -0
- package/docs/MUSUBIXv2.3.5-Refactering.md +1310 -0
- package/docs/MUSUBIv1.6.1-enhancement_roadmap_20260105.md +291 -0
- package/docs/MUSUBIv2.2.0-USERGUIDE.md +2079 -0
- package/docs/ROADMAP-v1.5.md +116 -0
- package/docs/SwarmCoding.md +1284 -0
- package/docs/Test-prompt.md +105 -0
- package/docs/USER-GUIDE-v1.8.0.md +2371 -0
- package/docs/USER-GUIDE.ja.md +2147 -0
- package/docs/USER-GUIDE.md +3022 -0
- package/docs/YATA-GLOBAL-GUIDE.ja.md +750 -0
- package/docs/YATA-GLOBAL-GUIDE.md +595 -0
- package/docs/YATA-LOCAL-GUIDE.ja.md +989 -0
- package/docs/YATA-LOCAL-GUIDE.md +730 -0
- package/docs/adr/0001-real-time-pattern-learning-architecture-for-v1-5-0.md +75 -0
- package/docs/adr/0002-pattern-sharing-protocol-for-cross-team-collaborat.md +79 -0
- package/docs/adr/0003-owl-2-rl-implementation-strategy-for-advanced-infe.md +90 -0
- package/docs/adr/ADR-v3.4.0-001-deep-research-architecture.md +217 -0
- package/docs/adr/ADR-v3.4.0-002-search-provider-selection.md +308 -0
- package/docs/adr/ADR-v3.4.0-003-lm-api-integration.md +475 -0
- package/docs/enterprise-knowledge-management.md +1737 -0
- package/docs/evolution-from-musubi-to-musubix.md +2170 -0
- package/docs/getting-started-with-sdd.md +1602 -0
- package/docs/moodle-refactering-codegraph-musubix.md +391 -0
- package/docs/moodle-refactering-codegraph.md +278 -0
- package/docs/overview/MUSUBIX-CodeGraph.md +322 -0
- package/docs/overview/MUSUBIX-Core.md +671 -0
- package/docs/overview/MUSUBIX-Decisions.md +494 -0
- package/docs/overview/MUSUBIX-FormalVerify.md +566 -0
- package/docs/overview/MUSUBIX-Knowledge.md +1231 -0
- package/docs/overview/MUSUBIX-Learning.md +837 -0
- package/docs/overview/MUSUBIX-MCP-Server.md +535 -0
- package/docs/overview/MUSUBIX-Overview.md +264 -0
- package/docs/overview/MUSUBIX-Phase1-Complete.md +271 -0
- package/docs/overview/MUSUBIX-Phase2-Complete.md +310 -0
- package/docs/overview/MUSUBIX-Policy.md +477 -0
- package/docs/overview/MUSUBIX-Roadmap-v2.md +399 -0
- package/docs/overview/MUSUBIX-Security-Plan.md +939 -0
- package/docs/overview/MUSUBIX-Security-v2.1.md +668 -0
- package/docs/overview/MUSUBIX-Security.md +891 -0
- package/docs/overview/MUSUBIX-YATA.md +666 -0
- package/docs/overview/MUSUBIX-v2.2.0-Advanced-Learning.md +513 -0
- package/docs/overview/Neuro-SymbolicAI.md +159 -0
- package/docs/packages/knowledge.md +594 -0
- package/docs/qiita-linux-kernel-knowledge-graph.md +596 -0
- package/package.json +58 -51
- package/scripts/generate-quality-gate-report.ts +106 -0
- package/scripts/postinstall.js +94 -0
- package/steering/.musubi-version +1 -0
- package/steering/product.ja.md +572 -0
- package/steering/project.yml +66 -0
- package/steering/rules/constitution.md +491 -0
- package/steering/structure.ja.md +503 -0
- package/steering/tech.ja.md +208 -0
- package/dist/index.d.ts +0 -25
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -74
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
# MUSUBIX 形式検証パッケージ
|
|
2
|
+
|
|
3
|
+
**パッケージ名**: `@nahisaho/musubix-formal-verify`
|
|
4
|
+
**バージョン**: 1.7.5
|
|
5
|
+
**最終更新**: 2026-01-06
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. 概要
|
|
10
|
+
|
|
11
|
+
`@nahisaho/musubix-formal-verify` は、Z3 SMTソルバを使用した形式検証機能を提供するパッケージです。EARS形式の要件をSMT-LIB2形式に変換し、事前条件・事後条件の数学的検証を行います。
|
|
12
|
+
|
|
13
|
+
### 1.1 主要機能
|
|
14
|
+
|
|
15
|
+
| 機能 | 説明 |
|
|
16
|
+
|------|------|
|
|
17
|
+
| **Z3統合** | WebAssembly版とプロセス版の自動切り替え |
|
|
18
|
+
| **事前条件検証** | 関数の入力条件の充足可能性検証 |
|
|
19
|
+
| **事後条件検証** | Hoareトリプル {P} C {Q} の検証 |
|
|
20
|
+
| **EARS→SMT変換** | 5パターンのEARS要件をSMT-LIB2に変換 |
|
|
21
|
+
| **トレーサビリティDB** | 要件・設計・コード間のリンク管理 |
|
|
22
|
+
| **影響分析** | 変更による影響範囲の分析 |
|
|
23
|
+
|
|
24
|
+
### 1.2 モジュール構成
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
packages/formal-verify/src/
|
|
28
|
+
├── z3/ # Z3 SMTソルバ統合
|
|
29
|
+
│ ├── Z3Adapter.ts # メインアダプタ
|
|
30
|
+
│ ├── Z3WasmClient.ts # WebAssembly版
|
|
31
|
+
│ ├── Z3ProcessFallback.ts # プロセス版フォールバック
|
|
32
|
+
│ └── types.ts # 型定義
|
|
33
|
+
├── verifiers/ # 検証器
|
|
34
|
+
│ ├── PreconditionVerifier.ts # 事前条件検証
|
|
35
|
+
│ ├── PostconditionVerifier.ts # 事後条件検証
|
|
36
|
+
│ └── types.ts # 型定義
|
|
37
|
+
├── converters/ # 変換器
|
|
38
|
+
│ ├── EarsToSmtConverter.ts # EARS→SMT変換
|
|
39
|
+
│ └── types.ts # 型定義
|
|
40
|
+
├── traceability/ # トレーサビリティ
|
|
41
|
+
│ ├── TraceabilityDB.ts # データベース
|
|
42
|
+
│ ├── ImpactAnalyzer.ts # 影響分析
|
|
43
|
+
│ └── types.ts # 型定義
|
|
44
|
+
├── tools/ # MCPツール
|
|
45
|
+
│ └── formal-verify-tools.ts
|
|
46
|
+
└── index.ts # エントリポイント
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 2. Z3 SMTソルバ統合
|
|
52
|
+
|
|
53
|
+
### 2.1 概要
|
|
54
|
+
|
|
55
|
+
Z3は、Microsoftが開発した高性能SMT(Satisfiability Modulo Theories)ソルバです。MUSUBIXでは、WebAssembly版を優先使用し、利用できない場合はプロセス版にフォールバックします。
|
|
56
|
+
|
|
57
|
+
### 2.2 Z3Adapter
|
|
58
|
+
|
|
59
|
+
メインのZ3アダプタクラス。
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { Z3Adapter } from '@nahisaho/musubix-formal-verify';
|
|
63
|
+
|
|
64
|
+
const z3 = new Z3Adapter();
|
|
65
|
+
|
|
66
|
+
// 初期化(自動でWASM/プロセスを選択)
|
|
67
|
+
await z3.initialize();
|
|
68
|
+
|
|
69
|
+
// SMT-LIB2スクリプトを検証
|
|
70
|
+
const result = await z3.verify(`
|
|
71
|
+
(declare-const x Int)
|
|
72
|
+
(declare-const y Int)
|
|
73
|
+
(assert (> x 0))
|
|
74
|
+
(assert (> y 0))
|
|
75
|
+
(assert (= (+ x y) 10))
|
|
76
|
+
(check-sat)
|
|
77
|
+
`);
|
|
78
|
+
|
|
79
|
+
console.log(result.status); // 'sat' | 'unsat' | 'unknown'
|
|
80
|
+
console.log(result.model); // 充足可能な場合のモデル
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 2.3 実行モード
|
|
84
|
+
|
|
85
|
+
| モード | 説明 | 優先度 |
|
|
86
|
+
|--------|------|--------|
|
|
87
|
+
| **WASM** | WebAssembly版(z3-solver) | 高 |
|
|
88
|
+
| **Process** | ローカルz3コマンド実行 | 低(フォールバック) |
|
|
89
|
+
|
|
90
|
+
### 2.4 型定義
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
// Z3結果
|
|
94
|
+
interface Z3Result {
|
|
95
|
+
status: 'sat' | 'unsat' | 'unknown' | 'error';
|
|
96
|
+
model?: Record<string, unknown>;
|
|
97
|
+
unsatCore?: string[];
|
|
98
|
+
statistics?: Z3Statistics;
|
|
99
|
+
duration: number;
|
|
100
|
+
error?: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Z3統計情報
|
|
104
|
+
interface Z3Statistics {
|
|
105
|
+
numConflicts: number;
|
|
106
|
+
numDecisions: number;
|
|
107
|
+
memoryUsage: number;
|
|
108
|
+
time: number;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Z3オプション
|
|
112
|
+
interface Z3Options {
|
|
113
|
+
timeout?: number; // タイムアウト(ミリ秒)
|
|
114
|
+
model?: boolean; // モデル生成
|
|
115
|
+
unsatCore?: boolean; // UNSAT時のコア抽出
|
|
116
|
+
proof?: boolean; // 証明生成
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## 3. 事前条件検証(Precondition Verifier)
|
|
123
|
+
|
|
124
|
+
### 3.1 概要
|
|
125
|
+
|
|
126
|
+
関数の入力条件(事前条件)が充足可能かどうかを検証します。
|
|
127
|
+
|
|
128
|
+
### 3.2 使用例
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { PreconditionVerifier } from '@nahisaho/musubix-formal-verify';
|
|
132
|
+
|
|
133
|
+
const verifier = new PreconditionVerifier();
|
|
134
|
+
|
|
135
|
+
// 事前条件を検証
|
|
136
|
+
const result = await verifier.verify({
|
|
137
|
+
condition: {
|
|
138
|
+
expression: 'amount > 0 && amount <= balance',
|
|
139
|
+
format: 'javascript',
|
|
140
|
+
},
|
|
141
|
+
variables: [
|
|
142
|
+
{ name: 'amount', type: 'Int' },
|
|
143
|
+
{ name: 'balance', type: 'Int' },
|
|
144
|
+
],
|
|
145
|
+
options: {
|
|
146
|
+
timeout: 5000,
|
|
147
|
+
generateCounterexample: true,
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
console.log(result.status); // 'valid' | 'invalid' | 'unknown'
|
|
152
|
+
console.log(result.counterexample); // 反例(invalidの場合)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 3.3 対応する変数型
|
|
156
|
+
|
|
157
|
+
| 型 | SMT型 | 説明 |
|
|
158
|
+
|----|-------|------|
|
|
159
|
+
| `Int` | `Int` | 整数 |
|
|
160
|
+
| `Real` | `Real` | 実数 |
|
|
161
|
+
| `Bool` | `Bool` | 真偽値 |
|
|
162
|
+
| `String` | `String` | 文字列 |
|
|
163
|
+
| `Array` | `Array` | 配列 |
|
|
164
|
+
| `BitVec` | `BitVec` | ビットベクトル |
|
|
165
|
+
|
|
166
|
+
### 3.4 対応する演算子
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
// 比較演算子
|
|
170
|
+
'>' | '<' | '>=' | '<=' | '==' | '!='
|
|
171
|
+
|
|
172
|
+
// 論理演算子
|
|
173
|
+
'&&' | '||' | '!'
|
|
174
|
+
|
|
175
|
+
// 算術演算子
|
|
176
|
+
'+' | '-' | '*' | '/' | '%'
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## 4. 事後条件検証(Postcondition Verifier)
|
|
182
|
+
|
|
183
|
+
### 4.1 概要
|
|
184
|
+
|
|
185
|
+
Hoareトリプル `{P} C {Q}`(事前条件P、コマンドC、事後条件Q)の検証を行います。
|
|
186
|
+
|
|
187
|
+
### 4.2 使用例
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
import { PostconditionVerifier } from '@nahisaho/musubix-formal-verify';
|
|
191
|
+
|
|
192
|
+
const verifier = new PostconditionVerifier();
|
|
193
|
+
|
|
194
|
+
// Hoareトリプルを検証
|
|
195
|
+
const result = await verifier.verify({
|
|
196
|
+
precondition: {
|
|
197
|
+
expression: 'balance >= amount && amount > 0',
|
|
198
|
+
format: 'javascript',
|
|
199
|
+
},
|
|
200
|
+
postcondition: {
|
|
201
|
+
expression: 'balance_new == balance - amount',
|
|
202
|
+
format: 'javascript',
|
|
203
|
+
},
|
|
204
|
+
preVariables: [
|
|
205
|
+
{ name: 'balance', type: 'Int' },
|
|
206
|
+
{ name: 'amount', type: 'Int' },
|
|
207
|
+
],
|
|
208
|
+
postVariables: [
|
|
209
|
+
{ name: 'balance_new', type: 'Int' },
|
|
210
|
+
],
|
|
211
|
+
transition: 'balance_new := balance - amount',
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
console.log(result.status); // 'valid' | 'invalid' | 'unknown'
|
|
215
|
+
console.log(result.proof); // 証明(validの場合)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### 4.3 検証フロー
|
|
219
|
+
|
|
220
|
+
```
|
|
221
|
+
┌─────────────────────────────────────────────────────────┐
|
|
222
|
+
│ Hoare Triple {P} C {Q} │
|
|
223
|
+
│ │
|
|
224
|
+
│ 事前条件 P: balance >= amount && amount > 0 │
|
|
225
|
+
│ 遷移 C: balance_new := balance - amount │
|
|
226
|
+
│ 事後条件 Q: balance_new == balance - amount │
|
|
227
|
+
└──────────────────────┬──────────────────────────────────┘
|
|
228
|
+
│
|
|
229
|
+
▼
|
|
230
|
+
┌─────────────────────────────────────────────────────────┐
|
|
231
|
+
│ SMT-LIB2 に変換 │
|
|
232
|
+
│ │
|
|
233
|
+
│ (declare-const balance Int) │
|
|
234
|
+
│ (declare-const amount Int) │
|
|
235
|
+
│ (declare-const balance_new Int) │
|
|
236
|
+
│ (assert (and (>= balance amount) (> amount 0))) ; P │
|
|
237
|
+
│ (assert (= balance_new (- balance amount))) ; C │
|
|
238
|
+
│ (assert (not (= balance_new (- balance amount)))) ; ¬Q │
|
|
239
|
+
│ (check-sat) │
|
|
240
|
+
└──────────────────────┬──────────────────────────────────┘
|
|
241
|
+
│
|
|
242
|
+
▼
|
|
243
|
+
┌─────────────────────────────────────────────────────────┐
|
|
244
|
+
│ Z3 で検証 │
|
|
245
|
+
│ │
|
|
246
|
+
│ 結果: unsat → Hoareトリプルは valid │
|
|
247
|
+
│ 結果: sat → Hoareトリプルは invalid(反例あり) │
|
|
248
|
+
└─────────────────────────────────────────────────────────┘
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## 5. EARS→SMT変換
|
|
254
|
+
|
|
255
|
+
### 5.1 概要
|
|
256
|
+
|
|
257
|
+
EARS形式の要件をSMT-LIB2形式に変換します。5つのEARSパターンすべてに対応しています。
|
|
258
|
+
|
|
259
|
+
### 5.2 使用例
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
import { EarsToSmtConverter } from '@nahisaho/musubix-formal-verify';
|
|
263
|
+
|
|
264
|
+
const converter = new EarsToSmtConverter();
|
|
265
|
+
|
|
266
|
+
// Event-driven パターン
|
|
267
|
+
const result = converter.convert(
|
|
268
|
+
'WHEN a user submits login form, THE system SHALL validate credentials within 2 seconds.'
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
console.log(result.pattern); // 'event-driven'
|
|
272
|
+
console.log(result.smtLib2); // SMT-LIB2 コード
|
|
273
|
+
console.log(result.warnings); // 変換時の警告
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### 5.3 パターン別変換
|
|
277
|
+
|
|
278
|
+
#### Ubiquitous(常時)
|
|
279
|
+
|
|
280
|
+
```
|
|
281
|
+
入力: THE system SHALL encrypt all user data.
|
|
282
|
+
|
|
283
|
+
出力:
|
|
284
|
+
(declare-const system_active Bool)
|
|
285
|
+
(declare-const data_encrypted Bool)
|
|
286
|
+
(assert (=> system_active data_encrypted))
|
|
287
|
+
(check-sat)
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
#### Event-driven(イベント駆動)
|
|
291
|
+
|
|
292
|
+
```
|
|
293
|
+
入力: WHEN user clicks button, THE system SHALL save data.
|
|
294
|
+
|
|
295
|
+
出力:
|
|
296
|
+
(declare-const user_clicks_button Bool)
|
|
297
|
+
(declare-const system_saves_data Bool)
|
|
298
|
+
(assert (=> user_clicks_button system_saves_data))
|
|
299
|
+
(check-sat)
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
#### State-driven(状態駆動)
|
|
303
|
+
|
|
304
|
+
```
|
|
305
|
+
入力: WHILE in maintenance mode, THE system SHALL reject requests.
|
|
306
|
+
|
|
307
|
+
出力:
|
|
308
|
+
(declare-const maintenance_mode Bool)
|
|
309
|
+
(declare-const requests_rejected Bool)
|
|
310
|
+
(assert (=> maintenance_mode requests_rejected))
|
|
311
|
+
(check-sat)
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
#### Unwanted(禁止)
|
|
315
|
+
|
|
316
|
+
```
|
|
317
|
+
入力: THE system SHALL NOT store passwords in plain text.
|
|
318
|
+
|
|
319
|
+
出力:
|
|
320
|
+
(declare-const passwords_plain_text Bool)
|
|
321
|
+
(assert (not passwords_plain_text))
|
|
322
|
+
(check-sat)
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
#### Optional(条件付き)
|
|
326
|
+
|
|
327
|
+
```
|
|
328
|
+
入力: IF user is admin, THEN THE system SHALL show dashboard.
|
|
329
|
+
|
|
330
|
+
出力:
|
|
331
|
+
(declare-const user_is_admin Bool)
|
|
332
|
+
(declare-const dashboard_shown Bool)
|
|
333
|
+
(assert (=> user_is_admin dashboard_shown))
|
|
334
|
+
(check-sat)
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## 6. トレーサビリティDB
|
|
340
|
+
|
|
341
|
+
### 6.1 概要
|
|
342
|
+
|
|
343
|
+
要件・設計・コード・テスト間のトレーサビリティリンクを管理するデータベースです。
|
|
344
|
+
|
|
345
|
+
### 6.2 使用例
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
348
|
+
import { TraceabilityDB } from '@nahisaho/musubix-formal-verify';
|
|
349
|
+
|
|
350
|
+
const db = new TraceabilityDB();
|
|
351
|
+
await db.initialize('./trace.db');
|
|
352
|
+
|
|
353
|
+
// ノード追加
|
|
354
|
+
await db.addNode({
|
|
355
|
+
id: 'REQ-001',
|
|
356
|
+
type: 'requirement',
|
|
357
|
+
title: 'User Authentication',
|
|
358
|
+
content: 'THE system SHALL authenticate users...',
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
await db.addNode({
|
|
362
|
+
id: 'DES-001',
|
|
363
|
+
type: 'design',
|
|
364
|
+
title: 'Auth Module Design',
|
|
365
|
+
content: 'C4 Component diagram...',
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
// リンク追加
|
|
369
|
+
await db.addLink({
|
|
370
|
+
source: 'REQ-001',
|
|
371
|
+
target: 'DES-001',
|
|
372
|
+
type: 'implements',
|
|
373
|
+
confidence: 0.95,
|
|
374
|
+
description: 'Design implements requirement',
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// クエリ
|
|
378
|
+
const related = await db.getRelatedNodes('REQ-001', {
|
|
379
|
+
direction: 'downstream',
|
|
380
|
+
maxDepth: 3,
|
|
381
|
+
});
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### 6.3 ノードタイプ
|
|
385
|
+
|
|
386
|
+
| タイプ | 説明 | ID形式 |
|
|
387
|
+
|--------|------|--------|
|
|
388
|
+
| `requirement` | 要件 | `REQ-XXX` |
|
|
389
|
+
| `design` | 設計 | `DES-XXX` |
|
|
390
|
+
| `code` | コード | `CODE-XXX` |
|
|
391
|
+
| `test` | テスト | `TEST-XXX` |
|
|
392
|
+
| `task` | タスク | `TSK-XXX` |
|
|
393
|
+
| `documentation` | 文書 | `DOC-XXX` |
|
|
394
|
+
|
|
395
|
+
### 6.4 リンクタイプ
|
|
396
|
+
|
|
397
|
+
| タイプ | 説明 | 方向 |
|
|
398
|
+
|--------|------|------|
|
|
399
|
+
| `satisfies` | 充足する | 下流 → 上流 |
|
|
400
|
+
| `implements` | 実装する | 下流 → 上流 |
|
|
401
|
+
| `verifies` | 検証する | テスト → 対象 |
|
|
402
|
+
| `traces-to` | 追跡する | 双方向 |
|
|
403
|
+
| `depends-on` | 依存する | 依存元 → 依存先 |
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
## 7. 影響分析
|
|
408
|
+
|
|
409
|
+
### 7.1 概要
|
|
410
|
+
|
|
411
|
+
ノードの変更による影響範囲を分析します。
|
|
412
|
+
|
|
413
|
+
### 7.2 使用例
|
|
414
|
+
|
|
415
|
+
```typescript
|
|
416
|
+
import { ImpactAnalyzer } from '@nahisaho/musubix-formal-verify';
|
|
417
|
+
|
|
418
|
+
const analyzer = new ImpactAnalyzer(db);
|
|
419
|
+
|
|
420
|
+
// 影響分析
|
|
421
|
+
const impact = await analyzer.analyze('REQ-001', {
|
|
422
|
+
maxDepth: 5,
|
|
423
|
+
decayRate: 0.7,
|
|
424
|
+
minImpactScore: 0.1,
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
console.log(impact.sourceId); // 'REQ-001'
|
|
428
|
+
console.log(impact.impactedNodes); // 影響を受けるノード一覧
|
|
429
|
+
console.log(impact.totalImpacted); // 影響ノード数
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
### 7.3 影響スコア
|
|
433
|
+
|
|
434
|
+
影響スコアは、ソースからの距離に応じて減衰します。
|
|
435
|
+
|
|
436
|
+
```
|
|
437
|
+
影響スコア = decayRate ^ (距離 - 1)
|
|
438
|
+
|
|
439
|
+
例(decayRate = 0.7):
|
|
440
|
+
- 距離1: 1.0
|
|
441
|
+
- 距離2: 0.7
|
|
442
|
+
- 距離3: 0.49
|
|
443
|
+
- 距離4: 0.343
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
---
|
|
447
|
+
|
|
448
|
+
## 8. MCPツール
|
|
449
|
+
|
|
450
|
+
### 8.1 概要
|
|
451
|
+
|
|
452
|
+
Model Context Protocol(MCP)経由で形式検証機能を提供するツールです。
|
|
453
|
+
|
|
454
|
+
### 8.2 利用可能なツール
|
|
455
|
+
|
|
456
|
+
| ツール名 | 説明 |
|
|
457
|
+
|---------|------|
|
|
458
|
+
| `verify_precondition` | 事前条件の検証 |
|
|
459
|
+
| `verify_postcondition` | 事後条件(Hoareトリプル)の検証 |
|
|
460
|
+
| `ears_to_smt` | EARS要件→SMT-LIB2変換 |
|
|
461
|
+
| `trace_add_link` | トレーサビリティリンク追加 |
|
|
462
|
+
| `trace_query` | トレーサビリティクエリ |
|
|
463
|
+
| `trace_impact` | 影響分析 |
|
|
464
|
+
|
|
465
|
+
### 8.3 ツール使用例(MCP経由)
|
|
466
|
+
|
|
467
|
+
```json
|
|
468
|
+
// verify_precondition
|
|
469
|
+
{
|
|
470
|
+
"tool": "verify_precondition",
|
|
471
|
+
"arguments": {
|
|
472
|
+
"condition": {
|
|
473
|
+
"expression": "amount > 0",
|
|
474
|
+
"format": "javascript"
|
|
475
|
+
},
|
|
476
|
+
"variables": [
|
|
477
|
+
{ "name": "amount", "type": "Int" }
|
|
478
|
+
]
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// ears_to_smt
|
|
483
|
+
{
|
|
484
|
+
"tool": "ears_to_smt",
|
|
485
|
+
"arguments": {
|
|
486
|
+
"requirement": "WHEN user logs in, THE system SHALL create session."
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// trace_impact
|
|
491
|
+
{
|
|
492
|
+
"tool": "trace_impact",
|
|
493
|
+
"arguments": {
|
|
494
|
+
"nodeId": "REQ-001",
|
|
495
|
+
"maxDepth": 5
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
---
|
|
501
|
+
|
|
502
|
+
## 9. インストールと使用
|
|
503
|
+
|
|
504
|
+
### 9.1 インストール
|
|
505
|
+
|
|
506
|
+
```bash
|
|
507
|
+
npm install @nahisaho/musubix-formal-verify
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
### 9.2 Z3のセットアップ
|
|
511
|
+
|
|
512
|
+
WebAssembly版は自動的にインストールされます。プロセス版フォールバックを使用する場合は、z3をシステムにインストールしてください。
|
|
513
|
+
|
|
514
|
+
```bash
|
|
515
|
+
# Ubuntu/Debian
|
|
516
|
+
sudo apt-get install z3
|
|
517
|
+
|
|
518
|
+
# macOS
|
|
519
|
+
brew install z3
|
|
520
|
+
|
|
521
|
+
# Windows
|
|
522
|
+
# https://github.com/Z3Prover/z3/releases からダウンロード
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
### 9.3 基本的な使用
|
|
526
|
+
|
|
527
|
+
```typescript
|
|
528
|
+
import {
|
|
529
|
+
Z3Adapter,
|
|
530
|
+
PreconditionVerifier,
|
|
531
|
+
PostconditionVerifier,
|
|
532
|
+
EarsToSmtConverter,
|
|
533
|
+
TraceabilityDB,
|
|
534
|
+
ImpactAnalyzer,
|
|
535
|
+
} from '@nahisaho/musubix-formal-verify';
|
|
536
|
+
|
|
537
|
+
// 初期化
|
|
538
|
+
const z3 = new Z3Adapter();
|
|
539
|
+
await z3.initialize();
|
|
540
|
+
|
|
541
|
+
// 検証器
|
|
542
|
+
const preVerifier = new PreconditionVerifier();
|
|
543
|
+
const postVerifier = new PostconditionVerifier();
|
|
544
|
+
|
|
545
|
+
// 変換器
|
|
546
|
+
const converter = new EarsToSmtConverter();
|
|
547
|
+
|
|
548
|
+
// トレーサビリティ
|
|
549
|
+
const db = new TraceabilityDB();
|
|
550
|
+
const analyzer = new ImpactAnalyzer(db);
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
---
|
|
554
|
+
|
|
555
|
+
## 10. 関連ドキュメント
|
|
556
|
+
|
|
557
|
+
| ドキュメント | 説明 |
|
|
558
|
+
|-------------|------|
|
|
559
|
+
| [MUSUBIX-Overview.md](MUSUBIX-Overview.md) | 全体概要 |
|
|
560
|
+
| [MUSUBIX-Core.md](MUSUBIX-Core.md) | Coreパッケージ |
|
|
561
|
+
| [API-REFERENCE.md](API-REFERENCE.md) | APIリファレンス |
|
|
562
|
+
| [USER-GUIDE.md](USER-GUIDE.md) | ユーザーガイド |
|
|
563
|
+
|
|
564
|
+
---
|
|
565
|
+
|
|
566
|
+
**© 2026 MUSUBIX Project**
|