musubix 3.3.4 → 3.3.6

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.
Files changed (92) hide show
  1. package/.github/AGENTS.md +949 -0
  2. package/.github/prompts/sdd-change-apply.prompt.md +283 -0
  3. package/.github/prompts/sdd-change-archive.prompt.md +241 -0
  4. package/.github/prompts/sdd-change-init.prompt.md +269 -0
  5. package/.github/prompts/sdd-design.prompt.md +250 -0
  6. package/.github/prompts/sdd-implement.prompt.md +387 -0
  7. package/.github/prompts/sdd-requirements.prompt.md +193 -0
  8. package/.github/prompts/sdd-review.prompt.md +155 -0
  9. package/.github/prompts/sdd-security.prompt.md +228 -0
  10. package/.github/prompts/sdd-steering.prompt.md +269 -0
  11. package/.github/prompts/sdd-tasks.prompt.md +255 -0
  12. package/.github/prompts/sdd-test.prompt.md +230 -0
  13. package/.github/prompts/sdd-validate.prompt.md +304 -0
  14. package/.github/skills/musubix-adr-generation/SKILL.md +209 -0
  15. package/.github/skills/musubix-best-practices/SKILL.md +315 -0
  16. package/.github/skills/musubix-c4-design/SKILL.md +162 -0
  17. package/.github/skills/musubix-code-generation/SKILL.md +237 -0
  18. package/.github/skills/musubix-domain-inference/SKILL.md +196 -0
  19. package/.github/skills/musubix-ears-validation/SKILL.md +161 -0
  20. package/.github/skills/musubix-sdd-workflow/SKILL.md +217 -0
  21. package/.github/skills/musubix-technical-writing/SKILL.md +444 -0
  22. package/.github/skills/musubix-test-generation/SKILL.md +212 -0
  23. package/.github/skills/musubix-traceability/SKILL.md +141 -0
  24. package/AGENTS.md +1065 -0
  25. package/LICENSE +21 -0
  26. package/README.ja.md +296 -0
  27. package/README.md +305 -50
  28. package/bin/musubix-mcp.js +15 -0
  29. package/bin/musubix.js +9 -1
  30. package/docs/API-REFERENCE.md +1425 -0
  31. package/docs/GITHUB-ACTIONS-NPM-SETUP.md +132 -0
  32. package/docs/INSTALL-GUIDE.ja.md +459 -0
  33. package/docs/INSTALL-GUIDE.md +459 -0
  34. package/docs/MIGRATION-v3.0.md +324 -0
  35. package/docs/MUSUBI-enhancement_roadmap_20260105.md +651 -0
  36. package/docs/MUSUBIX-v3.0-User-Guide.md +1357 -0
  37. package/docs/MUSUBIXv2.2.0-Manual-outline.md +136 -0
  38. package/docs/MUSUBIXv2.2.0-Manual.md +3123 -0
  39. package/docs/MUSUBIXv2.3.5-Refactering.md +1310 -0
  40. package/docs/MUSUBIv1.6.1-enhancement_roadmap_20260105.md +291 -0
  41. package/docs/MUSUBIv2.2.0-USERGUIDE.md +2079 -0
  42. package/docs/ROADMAP-v1.5.md +116 -0
  43. package/docs/SwarmCoding.md +1284 -0
  44. package/docs/Test-prompt.md +105 -0
  45. package/docs/USER-GUIDE-v1.8.0.md +2371 -0
  46. package/docs/USER-GUIDE.ja.md +2147 -0
  47. package/docs/USER-GUIDE.md +3022 -0
  48. package/docs/YATA-GLOBAL-GUIDE.ja.md +750 -0
  49. package/docs/YATA-GLOBAL-GUIDE.md +595 -0
  50. package/docs/YATA-LOCAL-GUIDE.ja.md +989 -0
  51. package/docs/YATA-LOCAL-GUIDE.md +730 -0
  52. package/docs/adr/0001-real-time-pattern-learning-architecture-for-v1-5-0.md +75 -0
  53. package/docs/adr/0002-pattern-sharing-protocol-for-cross-team-collaborat.md +79 -0
  54. package/docs/adr/0003-owl-2-rl-implementation-strategy-for-advanced-infe.md +90 -0
  55. package/docs/enterprise-knowledge-management.md +1737 -0
  56. package/docs/evolution-from-musubi-to-musubix.md +2170 -0
  57. package/docs/getting-started-with-sdd.md +1602 -0
  58. package/docs/moodle-refactering-codegraph-musubix.md +391 -0
  59. package/docs/moodle-refactering-codegraph.md +278 -0
  60. package/docs/overview/MUSUBIX-CodeGraph.md +322 -0
  61. package/docs/overview/MUSUBIX-Core.md +671 -0
  62. package/docs/overview/MUSUBIX-Decisions.md +494 -0
  63. package/docs/overview/MUSUBIX-FormalVerify.md +566 -0
  64. package/docs/overview/MUSUBIX-Knowledge.md +1231 -0
  65. package/docs/overview/MUSUBIX-Learning.md +837 -0
  66. package/docs/overview/MUSUBIX-MCP-Server.md +535 -0
  67. package/docs/overview/MUSUBIX-Overview.md +264 -0
  68. package/docs/overview/MUSUBIX-Phase1-Complete.md +271 -0
  69. package/docs/overview/MUSUBIX-Phase2-Complete.md +310 -0
  70. package/docs/overview/MUSUBIX-Policy.md +477 -0
  71. package/docs/overview/MUSUBIX-Roadmap-v2.md +399 -0
  72. package/docs/overview/MUSUBIX-Security-Plan.md +939 -0
  73. package/docs/overview/MUSUBIX-Security-v2.1.md +668 -0
  74. package/docs/overview/MUSUBIX-Security.md +891 -0
  75. package/docs/overview/MUSUBIX-YATA.md +666 -0
  76. package/docs/overview/MUSUBIX-v2.2.0-Advanced-Learning.md +513 -0
  77. package/docs/overview/Neuro-SymbolicAI.md +159 -0
  78. package/docs/packages/knowledge.md +594 -0
  79. package/docs/qiita-linux-kernel-knowledge-graph.md +596 -0
  80. package/package.json +55 -51
  81. package/scripts/generate-quality-gate-report.ts +106 -0
  82. package/scripts/postinstall.js +94 -0
  83. package/steering/.musubi-version +1 -0
  84. package/steering/product.ja.md +572 -0
  85. package/steering/project.yml +66 -0
  86. package/steering/rules/constitution.md +491 -0
  87. package/steering/structure.ja.md +503 -0
  88. package/steering/tech.ja.md +208 -0
  89. package/dist/index.d.ts +0 -25
  90. package/dist/index.d.ts.map +0 -1
  91. package/dist/index.js +0 -74
  92. package/dist/index.js.map +0 -1
@@ -0,0 +1,2079 @@
1
+ # MUSUBIX v2.2.0 ユーザーガイド
2
+
3
+ **バージョン**: 2.2.0
4
+ **最終更新**: 2026-01-09
5
+ **対象**: 開発者、AIコーディングエージェント
6
+
7
+ ---
8
+
9
+ ## 目次
10
+
11
+ 1. [はじめに](#1-はじめに)
12
+ 2. [インストール](#2-インストール)
13
+ 3. [Phase 1: プロジェクト初期化](#3-phase-1-プロジェクト初期化)
14
+ 4. [Phase 2: 要件定義(EARS形式)](#4-phase-2-要件定義ears形式)
15
+ 5. [Phase 3: 設計(C4モデル)](#5-phase-3-設計c4モデル)
16
+ 6. [Phase 4: タスク分解](#6-phase-4-タスク分解)
17
+ 7. [Phase 5: コード生成](#7-phase-5-コード生成)
18
+ 8. [Phase 6: セキュリティ分析](#8-phase-6-セキュリティ分析)
19
+ 9. [Phase 7: 形式検証](#9-phase-7-形式検証)
20
+ 10. [Phase 8: テスト生成](#10-phase-8-テスト生成)
21
+ 11. [Phase 9: トレーサビリティ](#11-phase-9-トレーサビリティ)
22
+ 12. [高度な機能(v2.2.0)](#12-高度な機能v220)
23
+ 13. [プロジェクトサマリー](#13-プロジェクトサマリー)
24
+ 14. [その他の機能](#14-その他の機能)
25
+ - [付録A: 9条憲法](#付録a-9条憲法)
26
+ - [付録B: CLIコマンド一覧](#付録b-cliコマンド一覧)
27
+ - [付録C: ファイル構成](#付録c-ファイル構成)
28
+ - [付録D: EARSパターン早見表](#付録d-earsパターン早見表)
29
+
30
+ ---
31
+
32
+ ## 1. はじめに
33
+
34
+ ### 1.1 MUSUBIXとは
35
+
36
+ **MUSUBIX**(ムスビックス)は、**Neuro-Symbolic AI統合システム**です。LLM(大規模言語モデル)の創造性とシンボリック推論の精密性を融合し、高品質なソフトウェア開発を支援します。
37
+
38
+ ### 1.2 主要な特徴
39
+
40
+ | 特徴 | 説明 |
41
+ |------|------|
42
+ | **EARS形式要件** | 形式的な要件記述(5パターン) |
43
+ | **C4モデル設計** | 4レベルのアーキテクチャ設計 |
44
+ | **9条憲法** | 開発プロセスを統治する不変ルール |
45
+ | **完全トレーサビリティ** | 要件→設計→コード→テストの100%追跡 |
46
+ | **形式検証** | Z3 SMTソルバによる数学的検証 |
47
+ | **セキュリティ分析** | OWASP Top 10/CWE Top 25対応 |
48
+ | **自己学習** | パターン学習と適応的推論 |
49
+
50
+ ### 1.3 このガイドについて
51
+
52
+ このガイドでは、**Medical Appointment System(医療予約管理システム)** を題材に、MUSUBIXの全機能を使った開発プロセスを実演します。
53
+
54
+ ---
55
+
56
+ ## 2. インストール
57
+
58
+ ### 2.1 npmからインストール
59
+
60
+ ```bash
61
+ # 全パッケージを一括インストール
62
+ npm install musubix
63
+
64
+ # または個別パッケージ
65
+ npm install @nahisaho/musubix-core
66
+ ```
67
+
68
+ ### 2.2 システム要件
69
+
70
+ | 項目 | 要件 |
71
+ |------|------|
72
+ | Node.js | >= 20.0.0 |
73
+ | npm | >= 10.0.0 |
74
+ | OS | Windows, macOS, Linux |
75
+
76
+ ### 2.3 インストール確認
77
+
78
+ ```bash
79
+ npx musubix --version
80
+ # 出力: 2.2.0
81
+ ```
82
+
83
+ ---
84
+
85
+ ## 3. Phase 1: プロジェクト初期化
86
+
87
+ ### 3.1 `musubix init` コマンド
88
+
89
+ MUSUBIXプロジェクトを初期化します。
90
+
91
+ ```bash
92
+ npx musubix init medical-appointment-system --name "Medical Appointment System"
93
+ ```
94
+
95
+ ### 3.2 実行結果
96
+
97
+ ```json
98
+ {
99
+ "success": true,
100
+ "projectPath": "/tmp/medical-appointment-system",
101
+ "filesCreated": [
102
+ "steering/",
103
+ "steering/rules/",
104
+ "storage/",
105
+ "storage/specs/",
106
+ "storage/archive/",
107
+ "storage/changes/",
108
+ ".github/",
109
+ ".github/prompts/",
110
+ ".github/skills/",
111
+ "musubix.config.json",
112
+ "steering/rules/constitution.md",
113
+ "steering/product.md",
114
+ "steering/tech.md",
115
+ "steering/structure.md",
116
+ "AGENTS.md"
117
+ ],
118
+ "message": "MUSUBIX project 'Medical Appointment System' initialized successfully!"
119
+ }
120
+ ```
121
+
122
+ ### 3.3 生成されるディレクトリ構造
123
+
124
+ ```
125
+ medical-appointment-system/
126
+ ├── steering/ # プロジェクトメモリ
127
+ │ ├── rules/
128
+ │ │ └── constitution.md # 9条憲法
129
+ │ ├── product.md # プロダクトコンテキスト
130
+ │ ├── tech.md # 技術スタック
131
+ │ └── structure.md # アーキテクチャパターン
132
+ ├── storage/ # 成果物ストレージ
133
+ │ ├── specs/ # 要件・設計・タスク
134
+ │ ├── archive/ # アーカイブ
135
+ │ └── changes/ # 変更履歴
136
+ ├── .github/
137
+ │ ├── prompts/ # AIエージェント用プロンプト
138
+ │ └── skills/ # AIスキル定義
139
+ ├── musubix.config.json # 設定ファイル
140
+ └── AGENTS.md # AIエージェント向けガイド
141
+ ```
142
+
143
+ ### 3.4 MUSUBIXの処理内容
144
+
145
+ `musubix init` は以下の処理を実行します:
146
+
147
+ 1. **ディレクトリ構造の作成** - SDD方法論に準拠したフォルダ構造
148
+ 2. **9条憲法の配置** - 開発ルールを `steering/rules/constitution.md` に生成
149
+ 3. **プロジェクトメモリの初期化** - AIエージェントが参照する設定ファイル
150
+ 4. **AIスキルの配置** - GitHub Copilot/Claude用のスキル定義
151
+
152
+ ---
153
+
154
+ ## 4. Phase 2: 要件定義(EARS形式)
155
+
156
+ ### 4.1 EARS形式とは
157
+
158
+ **EARS (Easy Approach to Requirements Syntax)** は、自然言語の曖昧さを排除した形式的な要件記述方法です。
159
+
160
+ ### 4.2 5つのEARSパターン
161
+
162
+ | パターン | 構文 | 用途 |
163
+ |---------|------|------|
164
+ | **Ubiquitous** | `THE [system] SHALL [requirement]` | 常に満たすべき要件 |
165
+ | **Event-driven** | `WHEN [event], THE [system] SHALL [response]` | イベント発生時の要件 |
166
+ | **State-driven** | `WHILE [state], THE [system] SHALL [response]` | 特定状態での要件 |
167
+ | **Unwanted** | `THE [system] SHALL NOT [behavior]` | 禁止動作 |
168
+ | **Optional** | `IF [condition], THEN THE [system] SHALL [response]` | 条件付き要件 |
169
+
170
+ ### 4.3 要件ドキュメントの作成
171
+
172
+ `storage/specs/REQ-MAS-requirements.md` に EARS形式で要件を記述します。
173
+
174
+ #### 例: 予約作成要件
175
+
176
+ ```markdown
177
+ ### REQ-MAS-008: 予約作成
178
+ **パターン**: Event-driven
179
+ **優先度**: P0
180
+
181
+ WHEN a patient selects an available time slot, THE system SHALL create
182
+ an appointment within 3 seconds, mark the slot as booked, and return
183
+ a unique appointment ID.
184
+
185
+ **事前条件**: Time slot is available, patient has no conflicting appointment
186
+ **事後条件**: Appointment status='confirmed', time slot status='booked'
187
+ **トレース**: DES-MAS-003
188
+ ```
189
+
190
+ ### 4.4 要件検証コマンド
191
+
192
+ ```bash
193
+ npx musubix requirements validate storage/specs/REQ-MAS-requirements.md
194
+ ```
195
+
196
+ ### 4.5 検証結果
197
+
198
+ ```json
199
+ {
200
+ "success": true,
201
+ "valid": true,
202
+ "issues": [],
203
+ "summary": { "errors": 0, "warnings": 0, "info": 0 },
204
+ "message": "✅ All 20 requirements are valid"
205
+ }
206
+ ```
207
+
208
+ ### 4.6 MUSUBIXの処理内容
209
+
210
+ `musubix requirements validate` は以下の処理を実行します:
211
+
212
+ 1. **EARS構文解析** - 5パターンのキーワード(WHEN, WHILE, SHALL, SHALL NOT, IF...THEN)を検出
213
+ 2. **構文検証** - 各パターンの文法ルールに準拠しているか確認
214
+ 3. **優先度チェック** - P0/P1/P2の優先度が設定されているか確認
215
+ 4. **トレーサビリティリンク検出** - DES-*, TSK-* への参照を抽出
216
+ 5. **測定可能性分析** - 具体的な数値・時間制約があるか評価
217
+
218
+ ### 4.7 Medical Appointment System の要件一覧
219
+
220
+ | 要件ID | 名称 | パターン | 優先度 |
221
+ |--------|------|----------|--------|
222
+ | REQ-MAS-001 | 患者新規登録 | Event-driven | P0 |
223
+ | REQ-MAS-002 | 患者プロフィール更新 | Event-driven | P1 |
224
+ | REQ-MAS-003 | 個人情報暗号化 | Ubiquitous | P0 |
225
+ | REQ-MAS-004 | 患者データアクセス制御 | Ubiquitous | P0 |
226
+ | REQ-MAS-005 | 医師専門分野 | Ubiquitous | P0 |
227
+ | REQ-MAS-006 | 医師時間枠設定 | Event-driven | P0 |
228
+ | REQ-MAS-007 | 医師検索 | Event-driven | P1 |
229
+ | REQ-MAS-008 | 予約作成 | Event-driven | P0 |
230
+ | REQ-MAS-009 | 重複予約防止 | Unwanted | P0 |
231
+ | REQ-MAS-010 | 予約キャンセル可能期間 | State-driven | P0 |
232
+ | REQ-MAS-011 | 予約キャンセル不可 | State-driven | P0 |
233
+ | REQ-MAS-012 | 予約変更 | Event-driven | P1 |
234
+ | REQ-MAS-013 | 予約確認メール | Event-driven | P1 |
235
+ | REQ-MAS-014 | 予約アクセス制御 | Ubiquitous | P0 |
236
+ | REQ-MAS-015 | JWT認証 | Ubiquitous | P0 |
237
+ | REQ-MAS-016 | パスワードハッシュ化 | Ubiquitous | P0 |
238
+ | REQ-MAS-017 | 監査ログ | Ubiquitous | P0 |
239
+ | REQ-MAS-018 | 認証失敗ロックアウト | State-driven | P1 |
240
+ | REQ-MAS-019 | API応答時間 | Ubiquitous | P1 |
241
+ | REQ-MAS-020 | 同時ユーザー数 | Ubiquitous | P1 |
242
+
243
+ ### 4.8 レビュープロセス
244
+
245
+ MUSUBIXでは、各フェーズ終了時にセルフレビューを実施します。
246
+
247
+ #### レビュー観点
248
+
249
+ | 観点 | チェック内容 |
250
+ |------|--------------|
251
+ | EARS形式準拠 | 5パターンの構文に準拠しているか |
252
+ | 優先度設定 | P0/P1/P2が適切に設定されているか |
253
+ | 測定可能性 | 具体的な数値・時間制約があるか |
254
+ | 網羅性 | 機能・非機能・セキュリティ要件が揃っているか |
255
+ | 一貫性 | 要件間で矛盾がないか |
256
+ | トレーサビリティ | 設計要素へのリンクがあるか |
257
+
258
+ #### レビュー結果の表示形式
259
+
260
+ ```
261
+ 📋 **レビュー結果**
262
+
263
+ | 観点 | 状態 | 詳細 |
264
+ |------|------|------|
265
+ | EARS形式準拠 | ✅ OK | 全20件がEARS構文に準拠 |
266
+ | 優先度設定 | ✅ OK | P0: 13件, P1: 7件 |
267
+ | 測定可能性 | ✅ OK | 時間制約・エラーコード明示 |
268
+ | ... | ... | ... |
269
+
270
+ 👉 **次のアクション:**
271
+ - 「修正」→ 指摘箇所を修正して再提示
272
+ - 「承認」→ 次フェーズへ進む
273
+ ```
274
+
275
+ ---
276
+
277
+ ## 5. Phase 3: 設計(C4モデル)
278
+
279
+ ### 5.1 C4モデルとは
280
+
281
+ **C4モデル**は、ソフトウェアアーキテクチャを4つのレベルで視覚化する手法です。
282
+
283
+ | レベル | 名称 | 説明 |
284
+ |--------|------|------|
285
+ | Level 1 | **System Context** | システム境界と外部アクター |
286
+ | Level 2 | **Container** | 技術スタックとコンテナ構成 |
287
+ | Level 3 | **Component** | コンテナ内部のコンポーネント |
288
+ | Level 4 | **Code** | 実装詳細(クラス図等) |
289
+
290
+ ### 5.2 `musubix design generate` コマンド
291
+
292
+ 要件ドキュメントからC4モデル設計を自動生成します。
293
+
294
+ ```bash
295
+ npx musubix design generate storage/specs/REQ-MAS-requirements.md
296
+ ```
297
+
298
+ ### 5.3 実行結果
299
+
300
+ ```json
301
+ {
302
+ "success": true,
303
+ "design": {
304
+ "level": "component",
305
+ "title": "Component Diagram",
306
+ "elements": 19,
307
+ "relationships": 34
308
+ },
309
+ "patterns": [
310
+ { "name": "Factory", "category": "creational" },
311
+ { "name": "Singleton", "category": "creational" },
312
+ { "name": "Observer", "category": "behavioral" }
313
+ ],
314
+ "traceability": [
315
+ { "requirement": "REQ-MAS-001", "designElement": "PatientService" },
316
+ { "requirement": "REQ-MAS-008", "designElement": "AppointmentService" },
317
+ ...
318
+ ],
319
+ "message": "Generated component design with 19 elements"
320
+ }
321
+ ```
322
+
323
+ ### 5.4 MUSUBIXの処理内容
324
+
325
+ `musubix design generate` は以下の処理を実行します:
326
+
327
+ 1. **要件解析** - EARS要件からドメイン概念を抽出
328
+ 2. **コンポーネント識別** - 責務に基づいてコンポーネントを分類
329
+ 3. **パターン検出** - 適用可能な設計パターン(GoF)を提案
330
+ 4. **関係性マッピング** - コンポーネント間の依存関係を定義
331
+ 5. **トレーサビリティリンク生成** - REQ-* → DES-* の対応を自動生成
332
+
333
+ ### 5.5 生成される設計要素
334
+
335
+ #### Level 2: Container Diagram
336
+
337
+ ```
338
+ ┌─────────────────────────────────────────────────────────────────────────┐
339
+ │ Medical Appointment System │
340
+ │ │
341
+ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────────┐ │
342
+ │ │ Web Client │ │ Mobile Client │ │ Admin Dashboard │ │
343
+ │ │ (React SPA) │ │ (React Native) │ │ (React) │ │
344
+ │ └────────┬────────┘ └────────┬────────┘ └──────────┬──────────┘ │
345
+ │ │ │ │ │
346
+ │ └─────────────────────┴────────────────────────┘ │
347
+ │ │ │
348
+ │ ▼ │
349
+ │ ┌─────────────────────────────────────────────────────────────────┐ │
350
+ │ │ API Gateway │ │
351
+ │ │ (Node.js/Express) │ │
352
+ │ └─────────────────────────────────────────────────────────────────┘ │
353
+ │ │ │
354
+ │ ┌─────────────────────────┼─────────────────────────┐ │
355
+ │ ▼ ▼ ▼ │
356
+ │ ┌─────────────┐ ┌─────────────────────┐ ┌─────────────────────┐ │
357
+ │ │ Auth Service│ │ Appointment Service │ │ Notification Service│ │
358
+ │ └──────┬──────┘ └──────────┬──────────┘ └──────────┬──────────┘ │
359
+ │ │ │ │ │
360
+ │ └─────────────────────┴─────────────────────────┘ │
361
+ │ │ │
362
+ │ ▼ │
363
+ │ ┌─────────────────────────────────────────────────────────────────┐ │
364
+ │ │ PostgreSQL Database │ │
365
+ │ └─────────────────────────────────────────────────────────────────┘ │
366
+ └─────────────────────────────────────────────────────────────────────────┘
367
+ ```
368
+
369
+ #### Level 3: Component Diagram(一部)
370
+
371
+ ```
372
+ DES-MAS-APPT: Appointment Service
373
+ ├── DES-MAS-APPT-001: AppointmentController
374
+ │ └── トレース: REQ-MAS-008, REQ-MAS-010, REQ-MAS-011, REQ-MAS-012
375
+ ├── DES-MAS-APPT-002: AppointmentService
376
+ │ └── トレース: REQ-MAS-008, REQ-MAS-009, REQ-MAS-010, REQ-MAS-012
377
+ ├── DES-MAS-APPT-005: DuplicateBookingValidator
378
+ │ └── トレース: REQ-MAS-009
379
+ └── DES-MAS-APPT-008: AppointmentFactory (Factory Pattern)
380
+ └── トレース: REQ-MAS-008
381
+ ```
382
+
383
+ ### 5.6 適用設計パターン
384
+
385
+ MUSUBIXは、要件の特性に基づいて適切な設計パターンを自動提案します。
386
+
387
+ | パターン | カテゴリ | 適用箇所 | 目的 |
388
+ |----------|----------|----------|------|
389
+ | **Factory** | 生成 | AppointmentFactory | オブジェクト生成のカプセル化 |
390
+ | **Singleton** | 生成 | AuditLogger | 監査ログの一元管理 |
391
+ | **Observer** | 振る舞い | NotificationObserver | イベント駆動の通知配信 |
392
+
393
+ ### 5.7 設計ドキュメントの構成
394
+
395
+ ```
396
+ storage/design/
397
+ └── DES-MAS-design.md
398
+ ├── 1. 概要
399
+ ├── 2. C4モデル
400
+ │ ├── Level 1: System Context
401
+ │ ├── Level 2: Container Diagram
402
+ │ └── Level 3: Component Diagram
403
+ ├── 3. 適用設計パターン
404
+ ├── 4. データモデル
405
+ │ ├── エンティティ定義
406
+ │ └── Value Objects
407
+ ├── 5. インターフェース設計
408
+ │ ├── REST API エンドポイント
409
+ │ └── エラーコード設計
410
+ ├── 6. セキュリティ設計
411
+ └── 7. トレーサビリティマトリクス
412
+ ```
413
+
414
+ ### 5.8 トレーサビリティマトリクス(抜粋)
415
+
416
+ | 要件 | 設計コンポーネント | パターン |
417
+ |------|-------------------|----------|
418
+ | REQ-MAS-001 | DES-MAS-PATIENT-001, 002, 004 | - |
419
+ | REQ-MAS-008 | DES-MAS-APPT-001, 002, 003, 004, 008 | Factory |
420
+ | REQ-MAS-009 | DES-MAS-APPT-005 | - |
421
+ | REQ-MAS-013 | DES-MAS-NOTIFY-001, 002, 003, 004 | Observer |
422
+ | REQ-MAS-017 | DES-MAS-AUTH-006 | Singleton |
423
+
424
+ ### 5.9 レビュー観点
425
+
426
+ | 観点 | チェック内容 |
427
+ |------|--------------|
428
+ | C4レベル網羅 | Context/Container/Componentが揃っているか |
429
+ | SOLID準拠 | 単一責任・開放閉鎖原則に従っているか |
430
+ | パターン適用 | 設計パターンの適用理由が明確か |
431
+ | トレーサビリティ | 全要件が設計要素にリンクされているか |
432
+ | インターフェース定義 | API・エラーコードが明確か |
433
+ | セキュリティ設計 | 認証・暗号化の設計が適切か |
434
+
435
+ ---
436
+
437
+ ## 6. Phase 4: タスク分解
438
+
439
+ ### 6.1 タスク分解とは
440
+
441
+ 設計ドキュメントから実装可能な単位のタスクに分解するフェーズです。
442
+
443
+ > **重要**: MUSUBIXでは、タスク分解は**自然言語による指示**で実行します。AIエージェントが設計ドキュメントを解析し、適切な粒度のタスクに分解します。
444
+
445
+ ### 6.2 自然言語指示によるタスク分解
446
+
447
+ MUSUBIXのタスク分解は、専用CLIコマンドではなく、**AIエージェントへの自然言語指示**で行います。
448
+
449
+ ```
450
+ ユーザー: 「設計ドキュメントからタスクを分解してください」
451
+
452
+ AIエージェント:
453
+ 1. 設計ドキュメント(DES-MAS-design.md)を解析
454
+ 2. コンポーネントを実装単位に分解
455
+ 3. 依存関係を特定
456
+ 4. 見積もりを算出
457
+ 5. TSK-MAS-tasks.md を生成
458
+ ```
459
+
460
+ **この設計思想の理由:**
461
+ - タスク分解は**コンテキスト依存**が強い(プロジェクト特性、チーム構成、技術スタック)
462
+ - AIエージェントが**設計意図を理解**した上で分解することで、より適切な粒度を実現
463
+ - **対話的な調整**が可能(「もっと細かく分解して」「認証サービスを優先して」など)
464
+
465
+ ### 6.3 タスク分解の原則
466
+
467
+ | 原則 | 説明 |
468
+ |------|------|
469
+ | **粒度** | 1タスク = 2〜4時間の作業量 |
470
+ | **依存関係** | 明確な実行順序を定義 |
471
+ | **テスト先行** | 各タスクにテストタスクを含む |
472
+ | **トレーサビリティ** | DES-* → TSK-* のリンクを維持 |
473
+
474
+ ### 6.3 タスクID命名規則
475
+
476
+ ```
477
+ TSK-{プロジェクト}-{カテゴリ番号}{連番}
478
+
479
+ 例:
480
+ TSK-MAS-001 → 共通基盤タスク#1
481
+ TSK-MAS-101 → 認証サービスタスク#1(100系)
482
+ TSK-MAS-201 → 患者サービスタスク#1(200系)
483
+ TSK-MAS-301 → 医師サービスタスク#1(300系)
484
+ TSK-MAS-401 → 予約サービスタスク#1(400系)
485
+ TSK-MAS-501 → 通知サービスタスク#1(500系)
486
+ TSK-MAS-901 → 統合タスク#1(900系)
487
+ ```
488
+
489
+ ### 6.4 Medical Appointment System のタスク構成
490
+
491
+ | カテゴリ | タスク数 | 合計見積もり |
492
+ |----------|----------|--------------|
493
+ | 共通基盤 | 4 | 9h |
494
+ | 認証サービス | 7 | 17h |
495
+ | 患者サービス | 7 | 18h |
496
+ | 医師サービス | 7 | 18h |
497
+ | 予約サービス | 9 | 27h |
498
+ | 通知サービス | 5 | 11h |
499
+ | 統合・最終 | 6 | 17h |
500
+ | **合計** | **45タスク** | **117h** |
501
+
502
+ ### 6.5 実行順序(クリティカルパス)
503
+
504
+ ```
505
+ Phase A: 基盤構築(Week 1)
506
+ ──────────────────────────
507
+ TSK-MAS-001 → TSK-MAS-002 → TSK-MAS-003
508
+
509
+ TSK-MAS-004
510
+
511
+ Phase B: コアサービス並行開発(Week 2-3)
512
+ ────────────────────────────────────────
513
+ [認証] [患者] [医師]
514
+ TSK-MAS-101 TSK-MAS-201 TSK-MAS-301
515
+ ↓ ↓ ↓
516
+ ... ... ...
517
+ ↓ ↓ ↓
518
+ TSK-MAS-107 TSK-MAS-207 TSK-MAS-307
519
+
520
+ Phase C: 予約・通知サービス(Week 3-4)
521
+ ─────────────────────────────────────
522
+ [予約] [通知]
523
+ TSK-MAS-401 → ... → 409 TSK-MAS-501 → ... → 505
524
+
525
+ Phase D: 統合・検証(Week 5)
526
+ ──────────────────────────
527
+ TSK-MAS-901 → 902 → 903 → 904 → 905 → 906
528
+ ```
529
+
530
+ ### 6.6 タスク詳細の構成要素
531
+
532
+ 各タスクは以下の要素を含みます:
533
+
534
+ ```markdown
535
+ ### TSK-MAS-XXX: タスク名
536
+
537
+ **見積もり**: Xh
538
+ **依存**: TSK-MAS-YYY
539
+ **トレース**: DES-MAS-ZZZ, REQ-MAS-WWW
540
+
541
+ **完了条件**:
542
+ - [ ] 実装項目1
543
+ - [ ] 実装項目2
544
+ - [ ] テスト作成
545
+
546
+ **受け入れ基準**:
547
+ \`\`\`typescript
548
+ // テストコード例
549
+ expect(result.isOk()).toBe(true);
550
+ \`\`\`
551
+ ```
552
+
553
+ ### 6.7 トレーサビリティマトリクス(抜粋)
554
+
555
+ | 要件 | 設計 | タスク |
556
+ |------|------|--------|
557
+ | REQ-MAS-001 | DES-MAS-PATIENT-001,002,004 | TSK-MAS-201,205,206 |
558
+ | REQ-MAS-008 | DES-MAS-APPT-001,002,003,004,008 | TSK-MAS-401,402,405,407,408 |
559
+ | REQ-MAS-009 | DES-MAS-APPT-005 | TSK-MAS-403,904 |
560
+ | REQ-MAS-015 | DES-MAS-AUTH-001,002,003 | TSK-MAS-102,105,106 |
561
+
562
+ ### 6.8 MUSUBIXの処理内容
563
+
564
+ タスク分解では以下の処理を実行します:
565
+
566
+ 1. **コンポーネント分析** - 設計コンポーネントから実装単位を特定
567
+ 2. **依存関係解析** - コンポーネント間の依存関係をタスク順序に変換
568
+ 3. **見積もり算出** - コンポーネントの複雑度に基づいて工数を見積もり
569
+ 4. **テストタスク生成** - 各サービスにテストタスクを自動追加
570
+ 5. **トレーサビリティリンク** - DES-* → TSK-* の対応を生成
571
+
572
+ ### 6.9 レビュー観点
573
+
574
+ | 観点 | チェック内容 |
575
+ |------|--------------|
576
+ | タスク粒度 | 1タスク2〜4時間の範囲内か |
577
+ | 依存関係 | 循環依存がないか、順序が妥当か |
578
+ | 網羅性 | 全設計コンポーネントがタスク化されているか |
579
+ | テスト先行 | 各サービスにテストタスクがあるか |
580
+ | トレーサビリティ | REQ→DES→TSKのリンクが完全か |
581
+ | 見積もり妥当性 | 合計工数が現実的か |
582
+
583
+ ---
584
+
585
+ ## 7. Phase 5: コード生成
586
+
587
+ ### 7.1 コード生成とは
588
+
589
+ 設計ドキュメントからTypeScriptのスケルトンコードを自動生成するフェーズです。
590
+
591
+ ### 7.2 `musubix codegen generate` コマンド
592
+
593
+ ```bash
594
+ npx musubix codegen generate storage/design/DES-MAS-design.md --output src/
595
+ ```
596
+
597
+ ### 7.3 実行結果
598
+
599
+ ```
600
+ ✅ Code generated in /tmp/medical-appointment-system/src
601
+ ```
602
+
603
+ ### 7.4 MUSUBIXの処理内容
604
+
605
+ `musubix codegen generate` は以下の処理を実行します:
606
+
607
+ 1. **設計解析** - C4コンポーネント図からクラス/インターフェースを抽出
608
+ 2. **パターン検出** - Factory, Singleton, Observer等の設計パターンを識別
609
+ 3. **スケルトン生成** - TypeScriptコードの基本構造を生成
610
+ 4. **トレーサビリティ注入** - `@トレース` アノテーションをコメントに追加
611
+ 5. **ベストプラクティス適用** - BP-CODE-*, BP-DESIGN-* パターンを自動適用
612
+
613
+ ### 7.5 生成されるコード構造
614
+
615
+ ```
616
+ src/
617
+ ├── common/ # 共通モジュール
618
+ │ ├── result.ts # Result<T, E> 型定義
619
+ │ ├── errors.ts # エラー型・エラーコード
620
+ │ └── id-generator.ts # ID生成ユーティリティ
621
+ ├── auth/ # 認証サービス
622
+ │ └── audit-logger.ts # 監査ログ(Singleton)
623
+ ├── patient/ # 患者サービス
624
+ ├── doctor/ # 医師サービス
625
+ ├── appointment/ # 予約サービス
626
+ │ ├── appointment.entity.ts # エンティティ定義
627
+ │ ├── appointment.factory.ts # Factory Pattern
628
+ │ ├── duplicate-booking.validator.ts # 重複予約検証
629
+ │ └── cancellation-policy.enforcer.ts # キャンセルポリシー
630
+ └── notification/ # 通知サービス
631
+ └── notification.observer.ts # Observer Pattern
632
+ ```
633
+
634
+ ### 7.6 コード例:Result型(BP-CODE-005)
635
+
636
+ ```typescript
637
+ /**
638
+ * Result型 - 失敗可能な操作の戻り値
639
+ * @トレース BP-CODE-005
640
+ */
641
+
642
+ export type Result<T, E> = Ok<T> | Err<E>;
643
+
644
+ export interface Ok<T> {
645
+ readonly _tag: 'Ok';
646
+ readonly value: T;
647
+ }
648
+
649
+ export interface Err<E> {
650
+ readonly _tag: 'Err';
651
+ readonly error: E;
652
+ }
653
+
654
+ export function ok<T>(value: T): Ok<T> {
655
+ return { _tag: 'Ok', value };
656
+ }
657
+
658
+ export function err<E>(error: E): Err<E> {
659
+ return { _tag: 'Err', error };
660
+ }
661
+ ```
662
+
663
+ ### 7.7 コード例:ID生成(BP-CODE-002)
664
+
665
+ ```typescript
666
+ /**
667
+ * ID生成ユーティリティ
668
+ * @トレース BP-CODE-002
669
+ * 形式: PREFIX-YYYYMMDD-NNN
670
+ */
671
+
672
+ export function createPatientId(): Result<PatientId, ValidationError> {
673
+ return ok({ value: generateId('PAT') });
674
+ // 例: PAT-20260108-001
675
+ }
676
+
677
+ export function createAppointmentId(): Result<AppointmentId, ValidationError> {
678
+ return ok({ value: generateId('APT') });
679
+ // 例: APT-20260108-001
680
+ }
681
+ ```
682
+
683
+ ### 7.8 コード例:ステータス遷移マップ(BP-DESIGN-001)
684
+
685
+ ```typescript
686
+ /**
687
+ * ステータス遷移マップ
688
+ * @トレース BP-DESIGN-001, REQ-MAS-010, REQ-MAS-011
689
+ */
690
+ export const validStatusTransitions: Record<AppointmentStatus, AppointmentStatus[]> = {
691
+ pending: ['confirmed', 'cancelled'],
692
+ confirmed: ['completed', 'cancelled', 'no_show'],
693
+ cancelled: [], // 終端状態
694
+ completed: [], // 終端状態
695
+ no_show: [], // 終端状態
696
+ };
697
+ ```
698
+
699
+ ### 7.9 コード例:Factory Pattern
700
+
701
+ ```typescript
702
+ /**
703
+ * Appointment Factory (Factory Pattern)
704
+ * @トレース DES-MAS-APPT-008, DES-PAT-001, REQ-MAS-008
705
+ */
706
+ export function createAppointmentFactory(): AppointmentFactory {
707
+ return {
708
+ create(input: CreateAppointmentInput): Result<Appointment, ValidationError> {
709
+ // バリデーション
710
+ if (!input.patientId?.value) {
711
+ return err(new ValidationError('Patient ID is required', 'patientId'));
712
+ }
713
+ // ...
714
+ return ok(appointment);
715
+ },
716
+ };
717
+ }
718
+ ```
719
+
720
+ ### 7.10 コード例:Observer Pattern
721
+
722
+ ```typescript
723
+ /**
724
+ * Notification Observer (Observer Pattern)
725
+ * @トレース DES-MAS-NOTIFY-004, DES-PAT-003, REQ-MAS-013
726
+ */
727
+ export interface AppointmentEventObserver {
728
+ onAppointmentCreated(appointment: Appointment): Promise<void>;
729
+ onAppointmentCancelled(appointment: Appointment): Promise<void>;
730
+ onAppointmentRescheduled(old: Appointment, new: Appointment): Promise<void>;
731
+ }
732
+ ```
733
+
734
+ ### 7.11 コード例:形式仕様アノテーション
735
+
736
+ ```typescript
737
+ /**
738
+ * Duplicate Booking Validator
739
+ * @トレース DES-MAS-APPT-005, REQ-MAS-009
740
+ *
741
+ * 形式仕様:
742
+ * ∀ slot ∈ TimeSlots: slot.status = 'booked' → ¬∃ new_appointment(slot)
743
+ */
744
+ export function createDuplicateBookingValidator(
745
+ timeSlotRepo: TimeSlotRepository,
746
+ ): DuplicateBookingValidator {
747
+ return {
748
+ async validate(timeSlotId, patientId): Promise<Result<void, AppError>> {
749
+ const timeSlot = await timeSlotRepo.findById(timeSlotId);
750
+
751
+ // 形式仕様の実装: slot.status = 'booked' → reject
752
+ if (timeSlot.status === 'booked') {
753
+ return err(SLOT_ALREADY_BOOKED);
754
+ }
755
+ return ok(undefined);
756
+ },
757
+ };
758
+ }
759
+ ```
760
+
761
+ ### 7.12 トレーサビリティアノテーション
762
+
763
+ 生成されたすべてのコードには、`@トレース` アノテーションが付与されます:
764
+
765
+ | ファイル | トレース先 |
766
+ |----------|------------|
767
+ | `result.ts` | BP-CODE-005 |
768
+ | `errors.ts` | REQ-MAS-009, REQ-MAS-011, REQ-MAS-018 |
769
+ | `id-generator.ts` | BP-CODE-002 |
770
+ | `appointment.entity.ts` | DES-MAS-APPT-004, REQ-MAS-008 |
771
+ | `appointment.factory.ts` | DES-MAS-APPT-008, DES-PAT-001, REQ-MAS-008 |
772
+ | `duplicate-booking.validator.ts` | DES-MAS-APPT-005, REQ-MAS-009 |
773
+ | `cancellation-policy.enforcer.ts` | DES-MAS-APPT-006, REQ-MAS-010, REQ-MAS-011 |
774
+ | `audit-logger.ts` | DES-MAS-AUTH-006, DES-PAT-002, REQ-MAS-017 |
775
+ | `notification.observer.ts` | DES-MAS-NOTIFY-004, DES-PAT-003, REQ-MAS-013 |
776
+
777
+ ---
778
+
779
+ ## 8. Phase 6: セキュリティ分析
780
+
781
+ ### 8.1 セキュリティ分析とは
782
+
783
+ 生成したコードに対してセキュリティ脆弱性をスキャンするフェーズです。MUSUBIXは**OWASP Top 10**および**CWE Top 25**に対応した検出ルールを提供します。
784
+
785
+ ### 8.2 `musubix codegen security` コマンド
786
+
787
+ ```bash
788
+ npx musubix codegen security src/
789
+ ```
790
+
791
+ ### 8.3 実行結果
792
+
793
+ ```json
794
+ {
795
+ "success": true,
796
+ "vulnerabilities": [],
797
+ "summary": { "critical": 0, "high": 0, "medium": 0, "low": 0 },
798
+ "score": 100,
799
+ "message": "✅ Security score: 100/100 - No critical issues"
800
+ }
801
+ ```
802
+
803
+ ### 8.4 MUSUBIXの処理内容
804
+
805
+ `musubix codegen security` は以下の処理を実行します:
806
+
807
+ 1. **パターンマッチング** - 既知の脆弱性パターンを検出
808
+ 2. **テイント解析** - ユーザー入力のトレース
809
+ 3. **シークレット検出** - ハードコードされた認証情報の検出
810
+ 4. **依存関係チェック** - 既知の脆弱性を持つライブラリの検出
811
+
812
+ ### 8.5 検出対象の脆弱性カテゴリ
813
+
814
+ #### OWASP Top 10 (2021)
815
+
816
+ | ランク | カテゴリ | MUSUBIXの対応 |
817
+ |--------|----------|---------------|
818
+ | A01 | Broken Access Control | アクセス制御パターンの検証 |
819
+ | A02 | Cryptographic Failures | 弱い暗号化アルゴリズムの検出 |
820
+ | A03 | Injection | SQL/NoSQL/コマンドインジェクションの検出 |
821
+ | A04 | Insecure Design | 設計レベルのセキュリティレビュー |
822
+ | A05 | Security Misconfiguration | 設定ミスの検出 |
823
+ | A06 | Vulnerable Components | 脆弱なライブラリの検出 |
824
+ | A07 | Auth Failures | 認証・セッション管理の問題検出 |
825
+ | A08 | Software Integrity | 整合性検証の欠如を検出 |
826
+ | A09 | Logging Failures | ログ・監視の問題検出 |
827
+ | A10 | SSRF | サーバーサイドリクエストフォージェリ検出 |
828
+
829
+ #### CWE Top 25 (抜粋)
830
+
831
+ | CWE ID | 名称 | 検出方法 |
832
+ |--------|------|----------|
833
+ | CWE-79 | XSS | HTMLエスケープの欠如 |
834
+ | CWE-89 | SQLi | パラメータ化クエリの不使用 |
835
+ | CWE-287 | 認証バイパス | 認証チェックの欠如 |
836
+ | CWE-798 | ハードコードされた認証情報 | 正規表現パターンマッチ |
837
+ | CWE-502 | 安全でないデシリアライゼーション | eval/Function使用 |
838
+
839
+ ### 8.6 静的コード解析
840
+
841
+ セキュリティスキャンに加えて、静的コード解析も実行できます。
842
+
843
+ ```bash
844
+ npx musubix codegen analyze src/
845
+ ```
846
+
847
+ #### 解析結果
848
+
849
+ ```json
850
+ {
851
+ "success": true,
852
+ "issues": [
853
+ {
854
+ "file": "src/auth/audit-logger.ts",
855
+ "line": 38,
856
+ "severity": "info",
857
+ "rule": "no-console",
858
+ "message": "Console statements should be removed in production code."
859
+ }
860
+ // ... 他の info レベルの警告
861
+ ],
862
+ "metrics": {
863
+ "files": 11,
864
+ "lines": 742,
865
+ "complexity": 74,
866
+ "maintainabilityIndex": 100
867
+ },
868
+ "summary": { "errors": 0, "warnings": 0, "info": 24 },
869
+ "message": "✅ Analyzed 11 files - No errors found"
870
+ }
871
+ ```
872
+
873
+ ### 8.7 Medical Appointment System のセキュリティ対策
874
+
875
+ #### 認証・認可(REQ-MAS-015, REQ-MAS-016, REQ-MAS-018)
876
+
877
+ ```typescript
878
+ /**
879
+ * Password Hasher
880
+ * @トレース DES-MAS-AUTH-004, REQ-MAS-016
881
+ *
882
+ * セキュリティ要件:
883
+ * - bcryptアルゴリズム使用
884
+ * - cost factor = 12
885
+ */
886
+ export function createPasswordHasher(): PasswordHasher {
887
+ const COST_FACTOR = 12; // OWASP推奨値
888
+ // ...
889
+ }
890
+ ```
891
+
892
+ #### データ暗号化(REQ-MAS-003)
893
+
894
+ ```typescript
895
+ /**
896
+ * Personal Info Encryptor
897
+ * @トレース DES-MAS-PATIENT-005, REQ-MAS-003
898
+ *
899
+ * セキュリティ要件:
900
+ * - AES-256-GCM暗号化(認証付き暗号)
901
+ * - 暗号化キーは環境変数から取得(CWE-798対策)
902
+ */
903
+ const ALGORITHM = 'aes-256-gcm'; // NIST推奨
904
+ ```
905
+
906
+ #### 監査ログ(REQ-MAS-017)
907
+
908
+ ```typescript
909
+ /**
910
+ * Audit Logger
911
+ * @トレース DES-MAS-AUTH-006, REQ-MAS-017
912
+ *
913
+ * 記録対象:
914
+ * - ログイン試行(成功/失敗)
915
+ * - データアクセス
916
+ * - 権限変更
917
+ */
918
+ export interface AuditEntry {
919
+ readonly timestamp: Date;
920
+ readonly userId: string;
921
+ readonly action: string;
922
+ readonly resource: string;
923
+ readonly ip?: string;
924
+ }
925
+ ```
926
+
927
+ ### 8.8 セキュリティスコアの解釈
928
+
929
+ | スコア | 評価 | 説明 |
930
+ |--------|------|------|
931
+ | 90-100 | 優秀 | 重大な脆弱性なし |
932
+ | 70-89 | 良好 | 軽微な問題のみ |
933
+ | 50-69 | 注意 | 中程度の脆弱性あり |
934
+ | 0-49 | 危険 | 重大な脆弱性あり |
935
+
936
+ ### 8.9 レビュー観点
937
+
938
+ | 観点 | チェック内容 |
939
+ |------|--------------|
940
+ | セキュリティスコア | 90点以上であること |
941
+ | Critical/High | 0件であること |
942
+ | 暗号化 | AES-256-GCM/bcrypt使用 |
943
+ | 認証情報 | ハードコードされていないこと |
944
+ | 監査ログ | 必要なイベントが記録されること |
945
+ | アクセス制御 | 適切な認可チェックがあること |
946
+
947
+ ---
948
+
949
+ ## 9. Phase 7: 形式検証
950
+
951
+ ### 9.1 形式検証とは
952
+
953
+ **形式検証**は、ソフトウェアの正しさを数学的に証明する手法です。MUSUBIXは**Z3 SMTソルバ**を使用して、EARS要件の論理的整合性を検証します。
954
+
955
+ ### 9.2 MUSUBIXの形式検証機能
956
+
957
+ | 機能 | 説明 |
958
+ |------|------|
959
+ | **EARS→SMT変換** | EARS要件をSMT-LIB2形式に自動変換 |
960
+ | **事前条件検証** | 関数の入力条件の充足可能性を検証 |
961
+ | **事後条件検証** | Hoareトリプル {P} C {Q} の検証 |
962
+ | **安全性検証** | システムが安全でない状態に到達しないことを証明 |
963
+
964
+ ### 9.3 SMT(Satisfiability Modulo Theories)とは
965
+
966
+ SMTは、命題論理に加えて**整数・実数・配列・ビットベクトル**などの理論を扱える充足可能性判定問題です。
967
+
968
+ ```
969
+ 例: 「x > 0 かつ y > 0 かつ x + y = 10」を満たす x, y は存在するか?
970
+ → sat (充足可能): x=5, y=5 など
971
+ ```
972
+
973
+ ### 9.4 EARS要件からSMT-LIB2への変換
974
+
975
+ #### 例: REQ-MAS-009(重複予約防止)
976
+
977
+ **EARS要件:**
978
+ ```
979
+ THE system SHALL NOT allow booking an already booked time slot.
980
+ ```
981
+
982
+ **形式仕様:**
983
+ ```
984
+ ∀ slot ∈ TimeSlots: slot.status = 'booked' → ¬∃ new_appointment(slot)
985
+ ```
986
+
987
+ **SMT-LIB2変換結果:**
988
+ ```smt2
989
+ ; MUSUBIX Formal Verification
990
+ ; Requirement: REQ-MAS-009 - 重複予約防止
991
+ ; @トレース REQ-MAS-009, DES-MAS-APPT-005
992
+
993
+ (set-logic ALL)
994
+
995
+ ; TimeSlot状態: 0=available, 1=booked, 2=blocked
996
+ (declare-const slot_status Int)
997
+ (declare-const booking_attempted Bool)
998
+ (declare-const booking_success Bool)
999
+
1000
+ ; slot_statusは0, 1, 2のいずれか
1001
+ (assert (and (>= slot_status 0) (<= slot_status 2)))
1002
+
1003
+ ; 安全性: 予約済みスロットへの予約は失敗すべき
1004
+ ; slot.status = 'booked' ∧ booking_attempted → ¬booking_success
1005
+ (assert (=> (and (= slot_status 1) booking_attempted)
1006
+ (not booking_success)))
1007
+
1008
+ (check-sat)
1009
+ ```
1010
+
1011
+ ### 9.5 キャンセルポリシーの形式検証
1012
+
1013
+ #### REQ-MAS-010, REQ-MAS-011
1014
+
1015
+ **EARS要件:**
1016
+ - REQ-MAS-010: 24時間以上前 → キャンセル可能
1017
+ - REQ-MAS-011: 24時間以内 → キャンセル不可
1018
+
1019
+ **SMT-LIB2:**
1020
+ ```smt2
1021
+ (set-logic QF_LRA)
1022
+
1023
+ ; 予約時刻までの残り時間(時間単位)
1024
+ (declare-const hours_until_appointment Real)
1025
+ (declare-const cancel_attempted Bool)
1026
+ (declare-const cancel_success Bool)
1027
+
1028
+ (define-const CANCELLATION_WINDOW Real 24.0)
1029
+
1030
+ ; REQ-MAS-010: 24時間以上前ならキャンセル可能
1031
+ (assert (=> (and cancel_attempted
1032
+ (>= hours_until_appointment CANCELLATION_WINDOW))
1033
+ cancel_success))
1034
+
1035
+ ; REQ-MAS-011: 24時間以内はキャンセル不可
1036
+ (assert (=> (and cancel_attempted
1037
+ (< hours_until_appointment CANCELLATION_WINDOW))
1038
+ (not cancel_success)))
1039
+
1040
+ (check-sat)
1041
+ ```
1042
+
1043
+ ### 9.6 検証結果の解釈
1044
+
1045
+ | 結果 | 意味 |
1046
+ |------|------|
1047
+ | **sat** | 充足可能 - 条件を満たす値が存在 |
1048
+ | **unsat** | 充足不可能 - 条件を満たす値は存在しない |
1049
+ | **unknown** | 判定不能 - タイムアウトまたは複雑すぎる |
1050
+
1051
+ #### 安全性検証の場合
1052
+
1053
+ ```
1054
+ 仕様: 「危険な状態に到達できる」
1055
+ 結果: unsat → 安全性が保証される(危険な状態に到達不可能)
1056
+ 結果: sat → 反例あり(危険な状態に到達可能)
1057
+ ```
1058
+
1059
+ ### 9.7 Hoareトリプル検証
1060
+
1061
+ **Hoareトリプル**: `{P} C {Q}`
1062
+ - **P**: 事前条件(Precondition)
1063
+ - **C**: コマンド(Command)
1064
+ - **Q**: 事後条件(Postcondition)
1065
+
1066
+ ```typescript
1067
+ // 例: 残高からの引き出し
1068
+ // {P} balance >= amount && amount > 0
1069
+ // {C} balance_new := balance - amount
1070
+ // {Q} balance_new == balance - amount && balance_new >= 0
1071
+ ```
1072
+
1073
+ ### 9.8 形式検証ファイルの構成
1074
+
1075
+ ```
1076
+ storage/formal-verify/
1077
+ ├── FV-MAS-009-duplicate-booking.smt2 # 重複予約防止
1078
+ ├── FV-MAS-010-011-cancellation.smt2 # キャンセルポリシー
1079
+ └── verification-report.json # 検証結果レポート
1080
+ ```
1081
+
1082
+ ### 9.9 検証レポート例
1083
+
1084
+ ```json
1085
+ {
1086
+ "requirement": "REQ-MAS-009",
1087
+ "description": "重複予約防止",
1088
+ "formalSpec": "∀ slot ∈ TimeSlots: slot.status = 'booked' → ¬∃ new_appointment(slot)",
1089
+ "verification": {
1090
+ "status": "verified",
1091
+ "result": "unsat",
1092
+ "interpretation": "安全性が数学的に証明された",
1093
+ "duration": 45
1094
+ },
1095
+ "traceability": {
1096
+ "design": "DES-MAS-APPT-005",
1097
+ "code": "src/appointment/duplicate-booking.validator.ts"
1098
+ }
1099
+ }
1100
+ ```
1101
+
1102
+ ### 9.10 レビュー観点
1103
+
1104
+ | 観点 | チェック内容 |
1105
+ |------|--------------|
1106
+ | 変換精度 | EARS要件が正確にSMT-LIB2に変換されているか |
1107
+ | 検証結果 | 安全性要件が unsat(証明済み)か |
1108
+ | カバレッジ | 重要な要件が形式検証されているか |
1109
+ | 反例分析 | sat の場合、反例が妥当か |
1110
+
1111
+ ---
1112
+
1113
+ ## 10. Phase 8: テスト生成
1114
+
1115
+ ### 10.1 テスト生成コマンド
1116
+
1117
+ ```bash
1118
+ # 特定ファイルのテスト生成
1119
+ npx musubix test generate src/appointment/appointment.entity.ts
1120
+
1121
+ # 出力
1122
+ ✅ Tests generated: src/appointment/__tests__/appointment.entity.test.ts (0 test cases)
1123
+ - Framework: vitest
1124
+ - Style: unit
1125
+ ```
1126
+
1127
+ ### 10.2 テストファイル構成
1128
+
1129
+ ```
1130
+ src/
1131
+ ├── appointment/
1132
+ │ ├── appointment.entity.ts
1133
+ │ └── __tests__/
1134
+ │ ├── appointment.entity.test.ts # 158行, 10テスト
1135
+ │ └── appointment.factory.test.ts # Factory Pattern
1136
+ ├── auth/
1137
+ │ └── __tests__/
1138
+ │ └── audit-logger.test.ts # 110行, 9テスト(Singleton)
1139
+ └── notification/
1140
+ └── __tests__/
1141
+ └── notification.observer.test.ts # 138行, 9テスト(Observer)
1142
+ ```
1143
+
1144
+ **合計**: 4ファイル, 406行, 28テストケース
1145
+
1146
+ ### 10.3 テストのベストプラクティス
1147
+
1148
+ #### BP-TEST-001: Test Counter Reset
1149
+
1150
+ ```typescript
1151
+ import { beforeEach } from 'vitest';
1152
+ import { resetAppointmentCounter } from '../appointment.entity';
1153
+
1154
+ beforeEach(() => {
1155
+ resetAppointmentCounter(); // IDカウンターをリセット
1156
+ });
1157
+ ```
1158
+
1159
+ #### BP-TEST-004: Result Type Test Pattern
1160
+
1161
+ ```typescript
1162
+ import { isOk, isErr } from '../../common/result';
1163
+
1164
+ describe('createAppointment', () => {
1165
+ // 成功ケース
1166
+ it('should create a valid appointment', () => {
1167
+ const result = createAppointment({ ... });
1168
+ expect(isOk(result)).toBe(true);
1169
+ if (isOk(result)) {
1170
+ expect(result.value.status).toBe('scheduled');
1171
+ }
1172
+ });
1173
+
1174
+ // 失敗ケース
1175
+ it('should reject invalid duration', () => {
1176
+ const result = createAppointment({ durationMinutes: 0, ... });
1177
+ expect(isErr(result)).toBe(true);
1178
+ });
1179
+ });
1180
+ ```
1181
+
1182
+ #### BP-TEST-005: Status Transition Testing
1183
+
1184
+ ```typescript
1185
+ describe('Status Transitions', () => {
1186
+ it('should only allow valid status transitions', () => {
1187
+ const validTransitions: Record<AppointmentStatus, AppointmentStatus[]> = {
1188
+ scheduled: ['confirmed', 'cancelled'],
1189
+ confirmed: ['completed', 'no_show', 'cancelled'],
1190
+ completed: [],
1191
+ cancelled: [],
1192
+ no_show: [],
1193
+ };
1194
+
1195
+ // 有効な遷移
1196
+ expect(validTransitions['scheduled']).toContain('confirmed');
1197
+ // 無効な遷移
1198
+ expect(validTransitions['scheduled']).not.toContain('completed');
1199
+ });
1200
+ });
1201
+ ```
1202
+
1203
+ ### 10.4 Singleton Patternのテスト
1204
+
1205
+ ```typescript
1206
+ describe('AuditLogger (Singleton)', () => {
1207
+ // 同一インスタンスの確認
1208
+ it('should return the same instance', () => {
1209
+ const instance1 = AuditLogger.getInstance();
1210
+ const instance2 = AuditLogger.getInstance();
1211
+ expect(instance1).toBe(instance2);
1212
+ });
1213
+
1214
+ // 状態の共有確認
1215
+ it('should maintain state across getInstance calls', () => {
1216
+ logger.log({ action: 'CREATE', ... });
1217
+ const sameLogger = AuditLogger.getInstance();
1218
+ expect(sameLogger.getLogs()).toHaveLength(1);
1219
+ });
1220
+ });
1221
+ ```
1222
+
1223
+ ### 10.5 Observer Patternのテスト
1224
+
1225
+ ```typescript
1226
+ describe('Notification Observer Pattern', () => {
1227
+ it('should notify all observers', () => {
1228
+ const emailSpy = vi.spyOn(emailObserver, 'update');
1229
+ const smsSpy = vi.spyOn(smsObserver, 'update');
1230
+
1231
+ subject.attach(emailObserver);
1232
+ subject.attach(smsObserver);
1233
+
1234
+ const event: NotificationEvent = {
1235
+ type: 'APPOINTMENT_CONFIRMED',
1236
+ appointmentId: 'APPT-001',
1237
+ patientId: 'PAT-001',
1238
+ message: 'Your appointment has been confirmed',
1239
+ timestamp: new Date(),
1240
+ };
1241
+
1242
+ subject.notify(event);
1243
+
1244
+ expect(emailSpy).toHaveBeenCalledWith(event);
1245
+ expect(smsSpy).toHaveBeenCalledWith(event);
1246
+ });
1247
+ });
1248
+ ```
1249
+
1250
+ ### 10.6 要件トレーサビリティ
1251
+
1252
+ 各テストファイルにはトレーサビリティコメントを含めます:
1253
+
1254
+ ```typescript
1255
+ /**
1256
+ * Appointment Entity テスト
1257
+ * @トレース REQ-MAS-001, REQ-MAS-009, REQ-MAS-010, REQ-MAS-011
1258
+ */
1259
+ ```
1260
+
1261
+ | テストファイル | トレース先要件 |
1262
+ |---------------|----------------|
1263
+ | appointment.entity.test.ts | REQ-MAS-001, 009, 010, 011 |
1264
+ | audit-logger.test.ts | REQ-MAS-019 |
1265
+ | notification.observer.test.ts | REQ-MAS-006, 007 |
1266
+
1267
+ ### 10.7 テスト実行
1268
+
1269
+ ```bash
1270
+ # 全テスト実行
1271
+ npx vitest run
1272
+
1273
+ # ウォッチモード
1274
+ npx vitest
1275
+
1276
+ # カバレッジ計測
1277
+ npx vitest run --coverage
1278
+ ```
1279
+
1280
+ ---
1281
+
1282
+ ## 11. Phase 9: トレーサビリティ
1283
+
1284
+ ### 11.1 トレーサビリティとは
1285
+
1286
+ **トレーサビリティ**は、要件→設計→実装→テストの全ての成果物間の対応関係を追跡可能にすることです。MUSUBIXは憲法条項V(Traceability)に基づき、100%の追跡可能性を要求します。
1287
+
1288
+ ### 11.2 トレーサビリティコマンド
1289
+
1290
+ ```bash
1291
+ # マトリクス生成
1292
+ npx musubix trace matrix
1293
+
1294
+ # 出力例
1295
+ {
1296
+ success: true,
1297
+ entries: [...],
1298
+ statistics: {
1299
+ requirements: 20,
1300
+ designs: 5,
1301
+ tasks: 0,
1302
+ implementations: 0,
1303
+ tests: 0,
1304
+ coverage: 0
1305
+ },
1306
+ message: 'Generated traceability matrix with 25 entries (0.0% coverage)'
1307
+ }
1308
+ ```
1309
+
1310
+ ### 11.3 トレーサビリティ検証
1311
+
1312
+ ```bash
1313
+ # リンク検証
1314
+ npx musubix trace validate
1315
+
1316
+ # 出力例
1317
+ {
1318
+ success: true,
1319
+ valid: true,
1320
+ issues: [
1321
+ {
1322
+ type: 'orphan',
1323
+ severity: 'warning',
1324
+ source: 'REQ-MAS-001',
1325
+ message: 'Requirement REQ-MAS-001 has no implementation'
1326
+ },
1327
+ ...
1328
+ ],
1329
+ summary: { total: 100, valid: 100, broken: 0, orphans: 20 },
1330
+ message: '⚠️ Found 20 issues (0 broken links, 20 orphans)'
1331
+ }
1332
+ ```
1333
+
1334
+ ### 11.4 影響分析(Impact Analysis)
1335
+
1336
+ ```bash
1337
+ # 特定要件の影響範囲を分析
1338
+ npx musubix trace impact REQ-MAS-009
1339
+
1340
+ # 出力例
1341
+ {
1342
+ success: true,
1343
+ sourceId: 'REQ-MAS-009',
1344
+ impacts: [
1345
+ {
1346
+ id: 'DES-MAS-001',
1347
+ type: 'design',
1348
+ impactLevel: 'direct',
1349
+ description: 'Design element'
1350
+ },
1351
+ ...
1352
+ ],
1353
+ riskLevel: 'medium',
1354
+ message: 'Found 5 impacted items (Risk: medium)'
1355
+ }
1356
+ ```
1357
+
1358
+ ### 11.5 トレーサビリティマトリクス
1359
+
1360
+ #### 要件 → 設計 マッピング
1361
+
1362
+ | 要件ID | 要件名 | 設計ID | 設計コンポーネント |
1363
+ |--------|--------|--------|-------------------|
1364
+ | REQ-MAS-001 | 予約作成 | DES-MAS-APPT-001 | AppointmentService |
1365
+ | REQ-MAS-006 | 予約確認通知 | DES-MAS-NOTIFY-001 | NotificationService |
1366
+ | REQ-MAS-009 | 重複予約防止 | DES-MAS-APPT-005 | DuplicateBookingValidator |
1367
+ | REQ-MAS-010 | 24h前キャンセル可 | DES-MAS-APPT-006 | CancellationPolicyEnforcer |
1368
+ | REQ-MAS-015 | 患者情報暗号化 | DES-MAS-PAT-001 | PersonalInfoEncryptor |
1369
+ | REQ-MAS-019 | 監査ログ | DES-MAS-AUTH-006 | AuditLogger |
1370
+
1371
+ #### 設計 → 実装 マッピング
1372
+
1373
+ | 設計ID | コンポーネント | 実装ファイル |
1374
+ |--------|---------------|--------------|
1375
+ | DES-MAS-APPT-001 | AppointmentEntity | appointment.entity.ts |
1376
+ | DES-MAS-APPT-008 | AppointmentFactory | appointment.factory.ts |
1377
+ | DES-MAS-AUTH-006 | AuditLogger | audit-logger.ts |
1378
+ | DES-MAS-PAT-001 | PersonalInfoEncryptor | personal-info-encryptor.ts |
1379
+ | DES-MAS-NOTIFY-004 | NotificationObserver | notification.observer.ts |
1380
+
1381
+ #### 実装 → テスト マッピング
1382
+
1383
+ | 実装ファイル | テストファイル | テスト数 |
1384
+ |-------------|---------------|----------|
1385
+ | appointment.entity.ts | appointment.entity.test.ts | 10 |
1386
+ | audit-logger.ts | audit-logger.test.ts | 9 |
1387
+ | notification.observer.ts | notification.observer.test.ts | 9 |
1388
+
1389
+ ### 11.6 カバレッジサマリー
1390
+
1391
+ | カテゴリ | 総数 | 設計済み | 実装済み | テスト済み | カバレッジ |
1392
+ |---------|------|---------|---------|-----------|-----------|
1393
+ | 予約管理 | 5 | 5 | 3 | 1 | 60% |
1394
+ | 通知 | 3 | 3 | 1 | 1 | 33% |
1395
+ | セキュリティ | 8 | 8 | 3 | 1 | 37% |
1396
+ | レポート | 1 | 1 | 0 | 0 | 0% |
1397
+ | **合計** | **20** | **20** | **11** | **4** | **55%** |
1398
+
1399
+ ### 11.7 コード内トレーサビリティ
1400
+
1401
+ ソースコード内に `@トレース` コメントを追加して追跡性を確保:
1402
+
1403
+ ```typescript
1404
+ /**
1405
+ * 予約エンティティ
1406
+ * @トレース REQ-MAS-001, REQ-MAS-009
1407
+ * @設計 DES-MAS-APPT-001
1408
+ */
1409
+ export interface Appointment {
1410
+ // ...
1411
+ }
1412
+ ```
1413
+
1414
+ ### 11.8 トレーサビリティファイル
1415
+
1416
+ ```
1417
+ storage/traceability/
1418
+ └── trace-matrix.md # 完全なトレーサビリティマトリクス
1419
+ ```
1420
+
1421
+ ---
1422
+
1423
+ ## 12. 高度な機能(v2.2.0)
1424
+
1425
+ ### 12.1 自己学習システム
1426
+
1427
+ MUSUBIXは開発パターンを学習し、プロジェクト固有の推奨を提供します。
1428
+
1429
+ #### パターン登録
1430
+
1431
+ ```bash
1432
+ # デザインパターンを登録
1433
+ npx musubix learn add-pattern "Factory Pattern" \
1434
+ --category code \
1435
+ --confidence 0.95 \
1436
+ --action prefer \
1437
+ --content "Use Factory pattern for entity creation with validation" \
1438
+ --language typescript
1439
+
1440
+ # 出力
1441
+ ✓ Pattern created: PAT-306D4DBC
1442
+ Name: Factory Pattern
1443
+ Category: code
1444
+ Action: prefer
1445
+ Confidence: 95.0%
1446
+ ```
1447
+
1448
+ #### フィードバック記録
1449
+
1450
+ ```bash
1451
+ # 要件へのフィードバック
1452
+ npx musubix learn feedback REQ-MAS-001 \
1453
+ --type accept \
1454
+ --artifact-type requirement \
1455
+ --reason "Well-defined EARS requirement"
1456
+
1457
+ # 出力
1458
+ ✓ Feedback recorded: FB-84B8AD1F
1459
+ Type: accept
1460
+ Artifact: requirement/REQ-MAS-001
1461
+ ```
1462
+
1463
+ #### パターン一覧表示
1464
+
1465
+ ```bash
1466
+ npx musubix learn patterns
1467
+
1468
+ # 出力
1469
+ Learned Patterns:
1470
+ ────────────────────────────────────────────────────────────────
1471
+ PAT-306D4DBC - Factory Pattern
1472
+ Category: code, Action: prefer
1473
+ Confidence: 95.0%, Occurrences: 1
1474
+
1475
+ PAT-93076A30 - Result Type Error Handling
1476
+ Category: code, Action: prefer
1477
+ Confidence: 95.0%, Occurrences: 1
1478
+
1479
+ PAT-6942ADA5 - Singleton Pattern
1480
+ Category: design, Action: prefer
1481
+ Confidence: 90.0%, Occurrences: 1
1482
+
1483
+ PAT-5910460B - Observer Pattern
1484
+ Category: design, Action: prefer
1485
+ Confidence: 90.0%, Occurrences: 1
1486
+
1487
+ Total: 4 patterns
1488
+ ```
1489
+
1490
+ #### 学習ステータス
1491
+
1492
+ ```bash
1493
+ npx musubix learn status
1494
+
1495
+ # 出力
1496
+ # MUSUBIX Learning Status Report
1497
+
1498
+ ## Summary
1499
+ - Total Feedback: 1
1500
+ - Total Patterns: 4
1501
+ - Average Confidence: 92.5%
1502
+
1503
+ ## Feedback by Type
1504
+ - Accept: 1
1505
+ - Reject: 0
1506
+ - Modify: 0
1507
+
1508
+ ## High Confidence Patterns (≥70%)
1509
+ - Factory Pattern (95.0%)
1510
+ - Result Type Error Handling (95.0%)
1511
+ - Singleton Pattern (90.0%)
1512
+ - Observer Pattern (90.0%)
1513
+ ```
1514
+
1515
+ #### 学習データのエクスポート/インポート
1516
+
1517
+ ```bash
1518
+ # エクスポート
1519
+ npx musubix learn export --output storage/learning/patterns-export.json
1520
+
1521
+ # インポート
1522
+ npx musubix learn import storage/learning/patterns-export.json
1523
+ ```
1524
+
1525
+ **エクスポート形式:**
1526
+ ```json
1527
+ {
1528
+ "feedback": [
1529
+ {
1530
+ "id": "FB-84B8AD1F",
1531
+ "timestamp": "2026-01-08T14:28:56.411Z",
1532
+ "type": "accept",
1533
+ "artifactType": "requirement",
1534
+ "artifactId": "REQ-MAS-001",
1535
+ "reason": "Well-defined EARS requirement"
1536
+ }
1537
+ ],
1538
+ "patterns": [
1539
+ {
1540
+ "id": "PAT-306D4DBC",
1541
+ "name": "Factory Pattern",
1542
+ "category": "code",
1543
+ "action": { "type": "prefer", "content": "..." },
1544
+ "confidence": 0.95,
1545
+ "occurrences": 1
1546
+ }
1547
+ ]
1548
+ }
1549
+ ```
1550
+
1551
+ ### 12.2 Neural Search(プログラムAPI)
1552
+
1553
+ v2.2.0では、コード検索のためのNeural Search APIが追加されました。
1554
+
1555
+ ```typescript
1556
+ import {
1557
+ ContextAwareEmbedder,
1558
+ HybridRanker,
1559
+ EmbeddingCache,
1560
+ createTrajectoryLogger,
1561
+ } from '@nahisaho/musubix-neural-search';
1562
+
1563
+ // 検索軌跡のロギング
1564
+ const logger = createTrajectoryLogger();
1565
+ logger.logBranch({ depth: 1, score: 0.85, action: 'expand' });
1566
+ logger.logBranch({ depth: 2, score: 0.92, action: 'select' });
1567
+
1568
+ // Parquet形式でエクスポート
1569
+ const parquet = logger.export('parquet');
1570
+
1571
+ // ハイブリッドランキング(BM25 + ベクトル類似度)
1572
+ const ranker = new HybridRanker();
1573
+ const results = ranker.rank(query, candidates, {
1574
+ bm25Weight: 0.3,
1575
+ vectorWeight: 0.7,
1576
+ });
1577
+ ```
1578
+
1579
+ ### 12.3 Library Learner(プログラムAPI)
1580
+
1581
+ APIパターンの学習とバージョン管理を提供します。
1582
+
1583
+ ```typescript
1584
+ import {
1585
+ SemanticChunker,
1586
+ PatternVersionManager,
1587
+ createMetricsExporter,
1588
+ } from '@nahisaho/musubix-library-learner';
1589
+
1590
+ // パターンバージョン管理
1591
+ const versionManager = new PatternVersionManager();
1592
+ versionManager.commit(pattern, 'Added validation logic');
1593
+ const history = versionManager.getHistory(patternId);
1594
+
1595
+ // メトリクスエクスポート
1596
+ const exporter = createMetricsExporter(library);
1597
+ const markdown = exporter.export('markdown');
1598
+ const summary = exporter.getSummary();
1599
+ // { healthStatus: 'good', patternCount: 42, avgConfidence: 0.87 }
1600
+ ```
1601
+
1602
+ ### 12.4 Program Synthesis(プログラムAPI)
1603
+
1604
+ 例題からプログラムを合成します。
1605
+
1606
+ ```typescript
1607
+ import {
1608
+ createMetaLearningEngine,
1609
+ createExampleAnalyzer,
1610
+ createExplanationGenerator,
1611
+ } from '@nahisaho/musubix-synthesis';
1612
+
1613
+ // 例題品質分析
1614
+ const analyzer = createExampleAnalyzer();
1615
+ const quality = analyzer.analyze([
1616
+ { input: 'hello', output: 'HELLO' },
1617
+ { input: 'world', output: 'WORLD' },
1618
+ ]);
1619
+ // { coverage: 0.8, diversity: 0.6, complexity: 'low' }
1620
+
1621
+ // プログラム合成
1622
+ const engine = createMetaLearningEngine();
1623
+ const program = await engine.synthesize(examples);
1624
+
1625
+ // 説明生成
1626
+ const explainer = createExplanationGenerator();
1627
+ const explanation = explainer.generate(program);
1628
+ const summary = explainer.summarize(program);
1629
+ // "Converts input string to uppercase"
1630
+ ```
1631
+
1632
+ ### 12.5 学習データファイル
1633
+
1634
+ ```
1635
+ storage/learning/
1636
+ └── patterns-export.json # 学習データエクスポート
1637
+ - feedback: フィードバック履歴
1638
+ - patterns: 学習済みパターン
1639
+ ```
1640
+
1641
+ ---
1642
+
1643
+ ## 13. プロジェクトサマリー
1644
+
1645
+ ### 13.1 Medical Appointment System 完成状況
1646
+
1647
+ 本ガイドで構築した **Medical Appointment System** の最終成果物です。
1648
+
1649
+ #### プロジェクト統計
1650
+
1651
+ | 項目 | 数値 |
1652
+ |------|------|
1653
+ | **EARS要件** | 20件(5カテゴリ) |
1654
+ | **設計コンポーネント** | 19件(C4モデル) |
1655
+ | **実装タスク** | 45件(117時間) |
1656
+ | **TypeScriptファイル** | 11件(742行) |
1657
+ | **テストファイル** | 4件(406行、28テスト) |
1658
+ | **設計パターン** | 3種(Factory, Singleton, Observer) |
1659
+ | **学習パターン** | 4件(92.5%平均信頼度) |
1660
+
1661
+ #### フェーズ別成果物
1662
+
1663
+ | Phase | 成果物 | ファイル |
1664
+ |-------|--------|---------|
1665
+ | 1 | プロジェクト初期化 | `musubix.config.json` |
1666
+ | 2 | EARS要件定義 | `storage/specs/REQ-MAS-requirements.md` |
1667
+ | 3 | C4モデル設計 | `storage/design/DES-MAS-design.md` |
1668
+ | 4 | タスク分解 | `storage/tasks/TSK-MAS-tasks.md` |
1669
+ | 5 | コード生成 | `src/**/*.ts`(11ファイル) |
1670
+ | 6 | セキュリティ分析 | スコア 100/100 |
1671
+ | 7 | 形式検証 | `storage/formal-verify/*.smt2` |
1672
+ | 8 | テスト生成 | `src/**/__tests__/*.test.ts` |
1673
+ | 9 | トレーサビリティ | `storage/traceability/trace-matrix.md` |
1674
+ | 10 | 学習データ | `storage/learning/patterns-export.json` |
1675
+
1676
+ #### ディレクトリ構造
1677
+
1678
+ ```
1679
+ /tmp/medical-appointment-system/
1680
+ ├── musubix.config.json
1681
+ ├── package.json
1682
+ ├── tsconfig.json
1683
+ ├── src/
1684
+ │ ├── common/
1685
+ │ │ ├── result.ts
1686
+ │ │ ├── errors.ts
1687
+ │ │ └── id-generator.ts
1688
+ │ ├── appointment/
1689
+ │ │ ├── appointment.entity.ts
1690
+ │ │ ├── appointment.factory.ts
1691
+ │ │ ├── duplicate-booking.validator.ts
1692
+ │ │ ├── cancellation-policy.enforcer.ts
1693
+ │ │ └── __tests__/
1694
+ │ │ ├── appointment.entity.test.ts
1695
+ │ │ └── appointment.factory.test.ts
1696
+ │ ├── auth/
1697
+ │ │ ├── audit-logger.ts
1698
+ │ │ ├── password-hasher.ts
1699
+ │ │ └── __tests__/
1700
+ │ │ └── audit-logger.test.ts
1701
+ │ ├── patient/
1702
+ │ │ └── personal-info-encryptor.ts
1703
+ │ └── notification/
1704
+ │ ├── notification.observer.ts
1705
+ │ └── __tests__/
1706
+ │ └── notification.observer.test.ts
1707
+ └── storage/
1708
+ ├── specs/
1709
+ │ └── REQ-MAS-requirements.md
1710
+ ├── design/
1711
+ │ └── DES-MAS-design.md
1712
+ ├── tasks/
1713
+ │ └── TSK-MAS-tasks.md
1714
+ ├── formal-verify/
1715
+ │ ├── FV-MAS-009-duplicate-booking.smt2
1716
+ │ └── FV-MAS-010-011-cancellation.smt2
1717
+ ├── traceability/
1718
+ │ └── trace-matrix.md
1719
+ └── learning/
1720
+ └── patterns-export.json
1721
+ ```
1722
+
1723
+ ### 13.2 使用したMUSUBIXコマンド
1724
+
1725
+ ```bash
1726
+ # Phase 1: 初期化
1727
+ npx musubix init /tmp/medical-appointment-system
1728
+
1729
+ # Phase 2: 要件検証
1730
+ npx musubix requirements validate storage/specs/REQ-MAS-requirements.md
1731
+
1732
+ # Phase 5: コード生成
1733
+ npx musubix codegen generate storage/design/DES-MAS-design.md
1734
+
1735
+ # Phase 6: セキュリティ分析
1736
+ npx musubix codegen security src/
1737
+ npx musubix codegen analyze src/
1738
+
1739
+ # Phase 8: テスト生成
1740
+ npx musubix test generate src/appointment/appointment.entity.ts
1741
+
1742
+ # Phase 9: トレーサビリティ
1743
+ npx musubix trace matrix
1744
+ npx musubix trace validate
1745
+ npx musubix trace impact REQ-MAS-009
1746
+
1747
+ # Phase 10: 自己学習
1748
+ npx musubix learn add-pattern "Factory Pattern" --category code --action prefer
1749
+ npx musubix learn feedback REQ-MAS-001 --type accept --artifact-type requirement
1750
+ npx musubix learn patterns
1751
+ npx musubix learn status
1752
+ npx musubix learn export --output storage/learning/patterns-export.json
1753
+ ```
1754
+
1755
+ ### 13.3 品質メトリクス
1756
+
1757
+ | メトリクス | 値 | 基準 |
1758
+ |-----------|-----|------|
1759
+ | セキュリティスコア | 100/100 | ≥80 |
1760
+ | 脆弱性検出 | 0件 | 0 |
1761
+ | EARS準拠率 | 100% | 100% |
1762
+ | トレーサビリティカバレッジ | 55% | ≥80%(目標) |
1763
+ | パターン信頼度 | 92.5% | ≥70% |
1764
+
1765
+ ---
1766
+
1767
+ ## 14. その他の機能
1768
+
1769
+ 本ガイドで使用しなかったMUSUBIXの機能を紹介します。
1770
+
1771
+ ### 14.1 要件分析の自動化
1772
+
1773
+ #### 自然言語からEARS変換
1774
+
1775
+ ```bash
1776
+ # 自然言語の要件をEARS形式に自動変換
1777
+ npx musubix requirements analyze "ユーザーはログインできる必要がある"
1778
+
1779
+ # 出力例
1780
+ THE system SHALL allow users to login with valid credentials.
1781
+ Pattern: Ubiquitous
1782
+ ```
1783
+
1784
+ #### オントロジーマッピング
1785
+
1786
+ ```bash
1787
+ # 要件を知識グラフにマッピング
1788
+ npx musubix requirements map storage/specs/REQ-*.md
1789
+
1790
+ # 関連要件の検索
1791
+ npx musubix requirements search "authentication"
1792
+ ```
1793
+
1794
+ #### 対話的要件作成
1795
+
1796
+ ```bash
1797
+ # 対話形式で要件を作成
1798
+ npx musubix requirements new "user-authentication"
1799
+ ```
1800
+
1801
+ ### 14.2 設計自動生成
1802
+
1803
+ #### 要件から設計を生成
1804
+
1805
+ ```bash
1806
+ # 要件ファイルから設計を自動生成
1807
+ npx musubix design generate storage/specs/REQ-MAS-requirements.md
1808
+
1809
+ # C4ダイアグラム生成
1810
+ npx musubix design c4 storage/design/DES-MAS-design.md
1811
+
1812
+ # SOLID準拠検証
1813
+ npx musubix design validate storage/design/DES-MAS-design.md
1814
+ ```
1815
+
1816
+ #### パターン検出
1817
+
1818
+ ```bash
1819
+ # コンテキストに適したパターンを検出
1820
+ npx musubix design patterns "notification system with multiple channels"
1821
+
1822
+ # 出力例
1823
+ Recommended patterns:
1824
+ - Observer Pattern (confidence: 95%)
1825
+ - Strategy Pattern (confidence: 78%)
1826
+ ```
1827
+
1828
+ #### ADR生成
1829
+
1830
+ ```bash
1831
+ # Architecture Decision Record を生成
1832
+ npx musubix design adr "Use Observer pattern for notifications"
1833
+ ```
1834
+
1835
+ ### 14.3 説明・可視化
1836
+
1837
+ #### 決定理由の説明
1838
+
1839
+ ```bash
1840
+ # なぜその決定がされたかを説明
1841
+ npx musubix explain why DES-MAS-NOTIFY-004
1842
+
1843
+ # 出力例
1844
+ Decision: Use Observer Pattern
1845
+ Reason: Multiple notification channels (Email, SMS, Push) require
1846
+ loose coupling and independent notification delivery.
1847
+ Trace: REQ-MAS-006 → REQ-MAS-007 → REQ-MAS-008
1848
+ ```
1849
+
1850
+ #### 推論グラフ生成
1851
+
1852
+ ```bash
1853
+ # 推論の過程をグラフとして可視化
1854
+ npx musubix explain graph REQ-MAS-009 --output reasoning.svg
1855
+ ```
1856
+
1857
+ ### 14.4 オントロジー操作
1858
+
1859
+ #### 知識グラフ検証
1860
+
1861
+ ```bash
1862
+ # 知識グラフの整合性検証
1863
+ npx musubix ontology validate -f storage/knowledge/kg.ttl
1864
+
1865
+ # 循環依存チェック
1866
+ npx musubix ontology check-circular -f storage/knowledge/kg.ttl
1867
+
1868
+ # 統計表示
1869
+ npx musubix ontology stats -f storage/knowledge/kg.ttl
1870
+ ```
1871
+
1872
+ ### 14.5 KGPR(Knowledge Graph Pull Request)
1873
+
1874
+ 知識を他のプロジェクトと共有するための機能です。
1875
+
1876
+ ```bash
1877
+ # KGPRの作成
1878
+ npx musubix kgpr create -t "Medical Appointment Patterns"
1879
+
1880
+ # 差分プレビュー
1881
+ npx musubix kgpr diff
1882
+
1883
+ # KGPR一覧
1884
+ npx musubix kgpr list
1885
+
1886
+ # 送信
1887
+ npx musubix kgpr submit <id>
1888
+
1889
+ # 詳細表示
1890
+ npx musubix kgpr show <id>
1891
+
1892
+ # クローズ
1893
+ npx musubix kgpr close <id>
1894
+ ```
1895
+
1896
+ ### 14.6 プロジェクトスキャフォールド
1897
+
1898
+ #### DDDプロジェクト生成
1899
+
1900
+ ```bash
1901
+ # ドメイン駆動設計プロジェクトを生成
1902
+ npx musubix scaffold domain-model medical-system \
1903
+ -e "Patient,Appointment,Doctor" \
1904
+ -d MEDICAL
1905
+
1906
+ # 最小構成プロジェクト
1907
+ npx musubix scaffold minimal my-project
1908
+
1909
+ # APIサービス
1910
+ npx musubix scaffold api-service user-service
1911
+ ```
1912
+
1913
+ ### 14.7 プログラム合成
1914
+
1915
+ 例題からプログラムを自動合成します。
1916
+
1917
+ ```bash
1918
+ # 例題ファイルからプログラム合成
1919
+ npx musubix synthesize examples.json
1920
+
1921
+ # examples.json の形式
1922
+ [
1923
+ { "input": "hello", "output": "HELLO" },
1924
+ { "input": "world", "output": "WORLD" }
1925
+ ]
1926
+
1927
+ # 出力: function transform(input) { return input.toUpperCase(); }
1928
+ ```
1929
+
1930
+ ### 14.8 対話的REPL
1931
+
1932
+ ```bash
1933
+ # 対話的シェルを起動
1934
+ npx musubix repl
1935
+
1936
+ # REPLコマンド例
1937
+ musubix> requirements validate REQ-001
1938
+ musubix> trace impact REQ-001
1939
+ musubix> learn status
1940
+ musubix> .exit
1941
+ ```
1942
+
1943
+ ### 14.9 パフォーマンスベンチマーク
1944
+
1945
+ ```bash
1946
+ # パフォーマンス計測
1947
+ npx musubix perf benchmark
1948
+
1949
+ # 出力例
1950
+ Benchmark Results:
1951
+ - Requirements validation: 45ms
1952
+ - Design generation: 230ms
1953
+ - Code analysis: 180ms
1954
+ ```
1955
+
1956
+ ### 14.10 追加の学習コマンド
1957
+
1958
+ ```bash
1959
+ # コンテキストベースの推奨
1960
+ npx musubix learn recommend --artifact-type code --language typescript
1961
+
1962
+ # 未使用パターンの減衰
1963
+ npx musubix learn decay --threshold 30 --factor 0.9
1964
+
1965
+ # 学習データのインポート
1966
+ npx musubix learn import shared-patterns.json --merge-strategy merge
1967
+
1968
+ # パターン削除
1969
+ npx musubix learn remove-pattern PAT-XXXXXX
1970
+ ```
1971
+
1972
+ ### 14.11 タスク管理
1973
+
1974
+ ```bash
1975
+ # タスク一覧
1976
+ npx musubix tasks list
1977
+
1978
+ # タスク検証
1979
+ npx musubix tasks validate storage/tasks/TSK-*.md
1980
+ ```
1981
+
1982
+ ### 14.12 パターンライブラリ
1983
+
1984
+ ```bash
1985
+ # ライブラリ統計
1986
+ npx musubix library stats
1987
+
1988
+ # パターン検索
1989
+ npx musubix library query "error handling"
1990
+
1991
+ # コードからパターン学習
1992
+ npx musubix library learn src/
1993
+ ```
1994
+
1995
+ ### 14.13 GitHub Agent Skills
1996
+
1997
+ ```bash
1998
+ # スキル一覧
1999
+ npx musubix skills list
2000
+
2001
+ # スキル追加
2002
+ npx musubix skills add pattern-recognition
2003
+ ```
2004
+
2005
+ ---
2006
+
2007
+ ## 付録
2008
+
2009
+ ### 付録A: 9条憲法
2010
+
2011
+ | 条項 | 名称 | 概要 |
2012
+ |-----|------|------|
2013
+ | I | Library-First | 機能は独立ライブラリとして開始 |
2014
+ | II | CLI Interface | すべてのライブラリはCLI公開必須 |
2015
+ | III | Test-First | Red-Green-Blueサイクルでテスト先行 |
2016
+ | IV | EARS Format | 要件はEARS形式で記述 |
2017
+ | V | Traceability | 要件↔設計↔コード↔テストの100%追跡 |
2018
+ | VI | Project Memory | steering/を参照してから決定 |
2019
+ | VII | Design Patterns | 設計パターン適用の文書化 |
2020
+ | VIII | Decision Records | すべての決定をADRで記録 |
2021
+ | IX | Quality Gates | フェーズ移行前の品質検証 |
2022
+
2023
+
2024
+ ### 付録B: CLIコマンド一覧
2025
+
2026
+ | コマンド | 説明 |
2027
+ |---------|------|
2028
+ | `musubix init` | プロジェクト初期化 |
2029
+ | `musubix requirements analyze` | 要件分析(自然言語→EARS) |
2030
+ | `musubix requirements validate` | 要件検証 |
2031
+ | `musubix design generate` | 設計生成 |
2032
+ | `musubix design patterns` | パターン検出 |
2033
+ | `musubix codegen generate` | コード生成 |
2034
+ | `musubix codegen analyze` | 静的解析 |
2035
+ | `musubix codegen security` | セキュリティスキャン |
2036
+ | `musubix test generate` | テスト生成 |
2037
+ | `musubix trace matrix` | トレーサビリティマトリクス |
2038
+ | `musubix trace validate` | リンク検証 |
2039
+ | `musubix trace impact` | 影響分析 |
2040
+ | `musubix learn add-pattern` | パターン登録 |
2041
+ | `musubix learn feedback` | フィードバック記録 |
2042
+ | `musubix learn patterns` | パターン一覧 |
2043
+ | `musubix learn status` | 学習ステータス |
2044
+ | `musubix learn export` | 学習データエクスポート |
2045
+
2046
+ ### 付録C: ファイル構成
2047
+
2048
+ ```
2049
+ storage/
2050
+ ├── specs/ # EARS要件定義
2051
+ │ └── REQ-*.md
2052
+ ├── design/ # C4モデル設計
2053
+ │ └── DES-*.md
2054
+ ├── tasks/ # タスク分解
2055
+ │ └── TSK-*.md
2056
+ ├── formal-verify/ # SMT-LIB2形式検証
2057
+ │ └── FV-*.smt2
2058
+ ├── traceability/ # トレーサビリティマトリクス
2059
+ │ └── trace-matrix.md
2060
+ └── learning/ # 学習データ
2061
+ └── patterns-export.json
2062
+ ```
2063
+
2064
+ ### 付録D: EARSパターン早見表
2065
+
2066
+ | パターン | 構文 | 例 |
2067
+ |---------|------|-----|
2068
+ | Ubiquitous | `THE [system] SHALL [action]` | THE system SHALL encrypt all patient data |
2069
+ | Event-driven | `WHEN [event], THE [system] SHALL [action]` | WHEN appointment is confirmed, THE system SHALL send notification |
2070
+ | State-driven | `WHILE [state], THE [system] SHALL [action]` | WHILE user is logged in, THE system SHALL maintain session |
2071
+ | Unwanted | `THE [system] SHALL NOT [action]` | THE system SHALL NOT allow duplicate bookings |
2072
+ | Optional | `IF [condition], THEN THE [system] SHALL [action]` | IF cancellation is within 24h, THEN THE system SHALL reject |
2073
+
2074
+ ---
2075
+
2076
+ **Document Version**: 1.0.0
2077
+ **Generated**: 2026-01-09
2078
+ **MUSUBIX Version**: 2.2.0
2079
+ **Project**: Medical Appointment System