musubix 3.6.1 → 3.7.3
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/skills/build-fix/SKILL.md +124 -0
- package/.github/skills/checkpoint/SKILL.md +131 -0
- package/.github/skills/codemap/SKILL.md +120 -0
- package/.github/skills/codemap/templates/codemap-index.md +142 -0
- package/.github/skills/codemap/templates/package-codemap.md +160 -0
- package/.github/skills/context-optimizer/SKILL.md +109 -0
- package/.github/skills/context-optimizer/contexts/dev.md +40 -0
- package/.github/skills/context-optimizer/contexts/research.md +55 -0
- package/.github/skills/context-optimizer/contexts/review.md +49 -0
- package/.github/skills/e2e-runner/SKILL.md +145 -0
- package/.github/skills/eval-harness/SKILL.md +111 -0
- package/.github/skills/eval-harness/examples/capability-eval.md +158 -0
- package/.github/skills/eval-harness/examples/human-grader-template.md +326 -0
- package/.github/skills/eval-harness/examples/regression-eval.md +228 -0
- package/.github/skills/learning-hooks/SKILL.md +101 -0
- package/.github/skills/learning-hooks/templates/learned-skill-template.md +79 -0
- package/.github/skills/musubix-adr-generation/SKILL.md +33 -168
- package/.github/skills/musubix-best-practices/SKILL.md +46 -276
- package/.github/skills/musubix-c4-design/SKILL.md +48 -124
- package/.github/skills/musubix-code-generation/SKILL.md +46 -193
- package/.github/skills/musubix-domain-inference/SKILL.md +54 -168
- package/.github/skills/musubix-ears-validation/SKILL.md +49 -136
- package/.github/skills/musubix-sdd-workflow/SKILL.md +56 -178
- package/.github/skills/musubix-technical-writing/SKILL.md +45 -381
- package/.github/skills/musubix-test-generation/SKILL.md +52 -176
- package/.github/skills/musubix-traceability/SKILL.md +52 -99
- package/.github/skills/refactor-cleaner/SKILL.md +105 -0
- package/.github/skills/session-manager/SKILL.md +119 -0
- package/.github/skills/session-manager/scripts/session-end.sh +175 -0
- package/.github/skills/session-manager/scripts/session-start.sh +87 -0
- package/.github/skills/verification-loop/SKILL.md +111 -0
- package/.github/skills/verification-loop/scripts/verify.sh +305 -0
- package/AGENTS.md +231 -1034
- package/docs/CODEMAPS/CODEMAP.md +1 -0
- package/docs/adr/ADR-v3.7.0-001-everything-claude-code-integration.md +102 -0
- package/package.json +2 -2
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: musubix-adr-generation
|
|
3
|
-
description:
|
|
3
|
+
description: Architecture Decision Records作成ガイド。技術選定・設計判断のドキュメント化に使用。
|
|
4
4
|
license: MIT
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
#
|
|
7
|
+
# ADR Generation Skill
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
**Article VIII - Decision Records**に基づきADRを作成。
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## WHEN → DO
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
| WHEN | DO |
|
|
14
|
+
|------|-----|
|
|
15
|
+
| 技術選定を記録したい | Technology Selection ADRを作成 |
|
|
16
|
+
| 設計パターンを決定 | Architecture Pattern ADRを作成 |
|
|
17
|
+
| トレードオフを文書化 | 選択肢の比較表を作成 |
|
|
14
18
|
|
|
15
19
|
## ADR Template
|
|
16
20
|
|
|
@@ -21,189 +25,50 @@ An **ADR (Architecture Decision Record)** documents significant architectural de
|
|
|
21
25
|
[Proposed | Accepted | Deprecated | Superseded by ADR-XXX]
|
|
22
26
|
|
|
23
27
|
## コンテキスト
|
|
24
|
-
[
|
|
28
|
+
[決定の背景・動機]
|
|
25
29
|
|
|
26
30
|
## 決定
|
|
27
|
-
[
|
|
31
|
+
[採用する解決策]
|
|
28
32
|
|
|
29
33
|
## 選択肢
|
|
30
34
|
|
|
31
35
|
### Option 1: [Name]
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
**デメリット:**
|
|
37
|
-
- [Disadvantage 1]
|
|
38
|
-
- [Disadvantage 2]
|
|
39
|
-
|
|
40
|
-
### Option 2: [Name]
|
|
41
|
-
**メリット:**
|
|
42
|
-
- [Advantage 1]
|
|
43
|
-
|
|
44
|
-
**デメリット:**
|
|
45
|
-
- [Disadvantage 1]
|
|
36
|
+
| メリット | デメリット |
|
|
37
|
+
|---------|-----------|
|
|
38
|
+
| [Advantage] | [Disadvantage] |
|
|
46
39
|
|
|
47
40
|
## 結果
|
|
48
|
-
[
|
|
41
|
+
[この決定による影響]
|
|
49
42
|
|
|
50
43
|
## トレーサビリティ
|
|
51
44
|
- 関連要件: REQ-XXX-NNN
|
|
52
45
|
- 関連設計: DES-XXX-NNN
|
|
53
46
|
```
|
|
54
47
|
|
|
55
|
-
##
|
|
56
|
-
|
|
57
|
-
### 1. Technology Selection
|
|
58
|
-
|
|
59
|
-
```markdown
|
|
60
|
-
# ADR-001: Use TypeScript for Backend
|
|
61
|
-
|
|
62
|
-
## コンテキスト
|
|
63
|
-
We need to choose a programming language for the backend API.
|
|
64
|
-
|
|
65
|
-
## 決定
|
|
66
|
-
We will use TypeScript with Node.js.
|
|
67
|
-
|
|
68
|
-
## 選択肢
|
|
69
|
-
|
|
70
|
-
### Option 1: TypeScript + Node.js
|
|
71
|
-
**メリット:**
|
|
72
|
-
- Type safety reduces runtime errors
|
|
73
|
-
- Same language as frontend (code sharing)
|
|
74
|
-
- Large ecosystem (npm)
|
|
75
|
-
- Strong async/await support
|
|
76
|
-
|
|
77
|
-
**デメリット:**
|
|
78
|
-
- Slower than compiled languages
|
|
79
|
-
- Type definitions not always available
|
|
48
|
+
## 典型的ADRトピック
|
|
80
49
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
50
|
+
| カテゴリ | 例 | 決定ポイント |
|
|
51
|
+
|---------|-----|-------------|
|
|
52
|
+
| **言語選定** | TypeScript vs Go | 型安全性, エコシステム, 学習曲線 |
|
|
53
|
+
| **アーキテクチャ** | Layered vs Hexagonal | チームスキル, 複雑度, テスト容易性 |
|
|
54
|
+
| **DB選定** | PostgreSQL vs MongoDB | ACID要件, スキーマ柔軟性 |
|
|
55
|
+
| **認証方式** | JWT vs Session | ステートレス要件, セキュリティ |
|
|
85
56
|
|
|
86
|
-
|
|
87
|
-
- Different language from frontend
|
|
88
|
-
- Smaller ecosystem for web
|
|
89
|
-
|
|
90
|
-
## 結果
|
|
91
|
-
- Frontend/backend code sharing enabled
|
|
92
|
-
- Need to maintain TypeScript configuration
|
|
93
|
-
- Team can use consistent tooling
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### 2. Architecture Pattern
|
|
97
|
-
|
|
98
|
-
```markdown
|
|
99
|
-
# ADR-002: Layered Architecture with DDD
|
|
100
|
-
|
|
101
|
-
## コンテキスト
|
|
102
|
-
We need to define the overall architecture pattern.
|
|
103
|
-
|
|
104
|
-
## 決定
|
|
105
|
-
We will use Layered Architecture with Domain-Driven Design principles.
|
|
106
|
-
|
|
107
|
-
## 選択肢
|
|
108
|
-
|
|
109
|
-
### Option 1: Layered Architecture
|
|
110
|
-
- Presentation → Application → Domain → Infrastructure
|
|
111
|
-
|
|
112
|
-
### Option 2: Hexagonal Architecture
|
|
113
|
-
- Ports and Adapters pattern
|
|
114
|
-
|
|
115
|
-
## 結果
|
|
116
|
-
- Clear separation of concerns
|
|
117
|
-
- Domain logic isolated from infrastructure
|
|
118
|
-
- Easier testing with dependency injection
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### 3. Database Selection
|
|
122
|
-
|
|
123
|
-
```markdown
|
|
124
|
-
# ADR-003: Use PostgreSQL for Primary Database
|
|
125
|
-
|
|
126
|
-
## コンテキスト
|
|
127
|
-
We need a primary data store for the application.
|
|
128
|
-
|
|
129
|
-
## 決定
|
|
130
|
-
PostgreSQL will be our primary database.
|
|
131
|
-
|
|
132
|
-
## 選択肢
|
|
133
|
-
|
|
134
|
-
### Option 1: PostgreSQL
|
|
135
|
-
**メリット:**
|
|
136
|
-
- ACID compliance
|
|
137
|
-
- JSON support
|
|
138
|
-
- Strong ecosystem
|
|
139
|
-
- Free and open source
|
|
140
|
-
|
|
141
|
-
### Option 2: MongoDB
|
|
142
|
-
**メリット:**
|
|
143
|
-
- Schema flexibility
|
|
144
|
-
- Horizontal scaling
|
|
145
|
-
|
|
146
|
-
**デメリット:**
|
|
147
|
-
- Eventual consistency concerns
|
|
148
|
-
- Complex transactions
|
|
149
|
-
|
|
150
|
-
## 結果
|
|
151
|
-
- Reliable transactional data storage
|
|
152
|
-
- Need to manage schema migrations
|
|
153
|
-
- Can use JSON columns for flexibility
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
## CLI Commands
|
|
57
|
+
## CLI
|
|
157
58
|
|
|
158
59
|
```bash
|
|
159
|
-
|
|
160
|
-
npx musubix design adr "Use React for frontend"
|
|
161
|
-
|
|
162
|
-
# List all ADRs
|
|
163
|
-
ls storage/design/adr/
|
|
164
|
-
|
|
165
|
-
# Generate ADR interactively
|
|
166
|
-
npx musubix design adr --interactive
|
|
60
|
+
npx musubix design adr <decision> # ADR生成
|
|
167
61
|
```
|
|
168
62
|
|
|
169
|
-
##
|
|
170
|
-
|
|
171
|
-
ADRs are numbered sequentially:
|
|
172
|
-
- ADR-001, ADR-002, ADR-003...
|
|
173
|
-
|
|
174
|
-
Never renumber existing ADRs. If an ADR is superseded, mark it as such and reference the new ADR.
|
|
175
|
-
|
|
176
|
-
## Storage Location
|
|
63
|
+
## 出力例
|
|
177
64
|
|
|
178
65
|
```
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
66
|
+
┌─────────────────────────────────────────┐
|
|
67
|
+
│ ADR Generated │
|
|
68
|
+
├─────────────────────────────────────────┤
|
|
69
|
+
│ ID: ADR-001 │
|
|
70
|
+
│ Title: Use TypeScript for Backend │
|
|
71
|
+
│ Status: Proposed │
|
|
72
|
+
│ Path: docs/adr/ADR-001.md │
|
|
73
|
+
└─────────────────────────────────────────┘
|
|
184
74
|
```
|
|
185
|
-
|
|
186
|
-
## ADR Index Template
|
|
187
|
-
|
|
188
|
-
```markdown
|
|
189
|
-
# Architecture Decision Records
|
|
190
|
-
|
|
191
|
-
| ADR | Title | Status | Date |
|
|
192
|
-
|-----|-------|--------|------|
|
|
193
|
-
| [ADR-001](./ADR-001-typescript-backend.md) | Use TypeScript for Backend | Accepted | 2026-01-04 |
|
|
194
|
-
| [ADR-002](./ADR-002-layered-architecture.md) | Layered Architecture | Accepted | 2026-01-04 |
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
## When to Write an ADR
|
|
198
|
-
|
|
199
|
-
- Technology selection (language, framework, database)
|
|
200
|
-
- Architecture patterns (layered, hexagonal, microservices)
|
|
201
|
-
- External integrations (APIs, services)
|
|
202
|
-
- Security decisions (authentication, authorization)
|
|
203
|
-
- Performance trade-offs (caching, scaling)
|
|
204
|
-
|
|
205
|
-
## Related Skills
|
|
206
|
-
|
|
207
|
-
- `musubix-c4-design` - Architecture diagrams
|
|
208
|
-
- `musubix-sdd-workflow` - Full development workflow
|
|
209
|
-
- `musubix-traceability` - Link ADRs to requirements
|
|
@@ -1,315 +1,85 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: musubix-best-practices
|
|
3
|
-
description:
|
|
3
|
+
description: MUSUBIX学習済み17ベストプラクティスガイド。コード・設計・テストパターンの適用に使用。
|
|
4
4
|
license: MIT
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
#
|
|
7
|
+
# Best Practices Skill
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## Overview
|
|
12
|
-
|
|
13
|
-
MUSUBIX has learned these best practices from implementing 14+ virtual projects. Apply them consistently for high-quality code.
|
|
9
|
+
14以上のプロジェクトから学習した17のベストプラクティス。
|
|
14
10
|
|
|
15
11
|
## Code Patterns (5)
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
name: string;
|
|
25
|
-
species: string;
|
|
26
|
-
ownerId: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function createPet(input: CreatePetInput): Pet {
|
|
30
|
-
return new Pet(input);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// ❌ Avoid: Multiple parameters
|
|
34
|
-
function createPet(name: string, species: string, ownerId: string): Pet {
|
|
35
|
-
// Hard to extend, easy to mix up parameter order
|
|
36
|
-
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### BP-CODE-002: Date-based ID Format
|
|
40
|
-
|
|
41
|
-
Generate IDs with PREFIX-YYYYMMDD-NNN format for sortability.
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
// ✅ Recommended: Date-based ID
|
|
45
|
-
const id = `PET-20260104-001`; // Sortable, traceable
|
|
46
|
-
|
|
47
|
-
// ❌ Avoid: UUID only
|
|
48
|
-
const id = crypto.randomUUID(); // Not human-readable
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### BP-CODE-003: Value Objects
|
|
52
|
-
|
|
53
|
-
Use Value Objects for domain concepts.
|
|
54
|
-
|
|
55
|
-
```typescript
|
|
56
|
-
// ✅ Recommended: Value Object
|
|
57
|
-
interface Price {
|
|
58
|
-
readonly amount: number;
|
|
59
|
-
readonly currency: 'JPY';
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// ❌ Avoid: Primitive types
|
|
63
|
-
const price: number = 1000; // No currency context
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### BP-CODE-004: Function-based Value Objects
|
|
13
|
+
| ID | パターン | 概要 |
|
|
14
|
+
|----|---------|------|
|
|
15
|
+
| BP-CODE-001 | Entity Input DTO | 複数パラメータ→DTOオブジェクト |
|
|
16
|
+
| BP-CODE-002 | Date-based ID | `PREFIX-YYYYMMDD-NNN`形式 |
|
|
17
|
+
| BP-CODE-003 | Value Objects | ドメイン概念にVO使用 |
|
|
18
|
+
| BP-CODE-004 | Function-based VO | interface + factory関数(classは非推奨) |
|
|
19
|
+
| BP-CODE-005 | Result Type | `Result<T, E>`で失敗を表現 |
|
|
67
20
|
|
|
68
|
-
|
|
21
|
+
### BP-CODE-004: Function-based VO
|
|
69
22
|
|
|
70
23
|
```typescript
|
|
71
|
-
// ✅
|
|
72
|
-
interface Price {
|
|
73
|
-
readonly amount: number;
|
|
74
|
-
readonly currency: 'JPY';
|
|
75
|
-
}
|
|
76
|
-
|
|
24
|
+
// ✅ 推奨
|
|
25
|
+
interface Price { readonly amount: number; readonly currency: 'JPY'; }
|
|
77
26
|
function createPrice(amount: number): Result<Price, ValidationError> {
|
|
78
|
-
if (amount < 100
|
|
79
|
-
return err(new ValidationError('Price must be between 100 and 1,000,000 JPY'));
|
|
80
|
-
}
|
|
27
|
+
if (amount < 100) return err(new ValidationError('...'));
|
|
81
28
|
return ok({ amount, currency: 'JPY' });
|
|
82
29
|
}
|
|
83
30
|
|
|
84
|
-
// ❌
|
|
85
|
-
class Price {
|
|
86
|
-
private constructor(readonly amount: number) {}
|
|
87
|
-
static create(amount: number): Price { ... }
|
|
88
|
-
}
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### BP-CODE-005: Result Type
|
|
92
|
-
|
|
93
|
-
Use Result<T, E> for operations that can fail.
|
|
94
|
-
|
|
95
|
-
```typescript
|
|
96
|
-
// ✅ Recommended: Result type
|
|
97
|
-
type Result<T, E> = { ok: true; value: T } | { ok: false; error: E };
|
|
98
|
-
|
|
99
|
-
function divide(a: number, b: number): Result<number, Error> {
|
|
100
|
-
if (b === 0) return { ok: false, error: new Error('Division by zero') };
|
|
101
|
-
return { ok: true, value: a / b };
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// ❌ Avoid: Throwing exceptions for expected errors
|
|
105
|
-
function divide(a: number, b: number): number {
|
|
106
|
-
if (b === 0) throw new Error('Division by zero');
|
|
107
|
-
return a / b;
|
|
108
|
-
}
|
|
31
|
+
// ❌ 非推奨: class-based
|
|
109
32
|
```
|
|
110
33
|
|
|
111
34
|
## Design Patterns (7)
|
|
112
35
|
|
|
113
|
-
|
|
36
|
+
| ID | パターン | 概要 |
|
|
37
|
+
|----|---------|------|
|
|
38
|
+
| BP-DESIGN-001 | Status Transition Map | `Record<Status, Status[]>`で遷移定義 |
|
|
39
|
+
| BP-DESIGN-002 | Repository Async | 将来DB移行に備えてasync化 |
|
|
40
|
+
| BP-DESIGN-003 | Service Layer DI | リポジトリをDI |
|
|
41
|
+
| BP-DESIGN-004 | Optimistic Locking | versionフィールドで同時編集検出 |
|
|
42
|
+
| BP-DESIGN-005 | AuditService | データ変更の監査ログ |
|
|
43
|
+
| BP-DESIGN-006 | Entity Counter Reset | テスト用resetXxxCounter() |
|
|
44
|
+
| BP-DESIGN-007 | Expiry Time Logic | expiresAtで有効期限管理 |
|
|
114
45
|
|
|
115
|
-
|
|
46
|
+
### BP-DESIGN-001: Status Transition Map
|
|
116
47
|
|
|
117
48
|
```typescript
|
|
118
|
-
// ✅ Recommended: Transition map
|
|
119
49
|
const validTransitions: Record<Status, Status[]> = {
|
|
120
50
|
draft: ['active', 'cancelled'],
|
|
121
51
|
active: ['completed', 'cancelled'],
|
|
122
|
-
completed: [],
|
|
123
|
-
cancelled: [],
|
|
52
|
+
completed: [], cancelled: [],
|
|
124
53
|
};
|
|
125
|
-
|
|
126
|
-
function canTransition(from: Status, to: Status): boolean {
|
|
127
|
-
return validTransitions[from].includes(to);
|
|
128
|
-
}
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
### BP-DESIGN-002: Repository Async Pattern
|
|
132
|
-
|
|
133
|
-
Make repositories async for future DB migration.
|
|
134
|
-
|
|
135
|
-
```typescript
|
|
136
|
-
// ✅ Recommended: Async repository
|
|
137
|
-
interface PetRepository {
|
|
138
|
-
findById(id: PetId): Promise<Pet | null>;
|
|
139
|
-
save(pet: Pet): Promise<void>;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// ❌ Avoid: Sync repository (hard to migrate later)
|
|
143
|
-
interface PetRepository {
|
|
144
|
-
findById(id: PetId): Pet | null;
|
|
145
|
-
}
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
### BP-DESIGN-003: Service Layer with DI
|
|
149
|
-
|
|
150
|
-
Use dependency injection for services.
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
// ✅ Recommended: Constructor DI
|
|
154
|
-
class PetService {
|
|
155
|
-
constructor(
|
|
156
|
-
private readonly petRepository: PetRepository,
|
|
157
|
-
private readonly auditService: AuditService
|
|
158
|
-
) {}
|
|
159
|
-
}
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
### BP-DESIGN-004: Optimistic Locking
|
|
163
|
-
|
|
164
|
-
Use version field for concurrent edit detection.
|
|
165
|
-
|
|
166
|
-
```typescript
|
|
167
|
-
// ✅ Recommended: Version field
|
|
168
|
-
interface Entity {
|
|
169
|
-
id: string;
|
|
170
|
-
version: number;
|
|
171
|
-
updatedAt: Date;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function update(entity: Entity, currentVersion: number): Result<Entity, ConcurrencyError> {
|
|
175
|
-
if (entity.version !== currentVersion) {
|
|
176
|
-
return err(new ConcurrencyError('Entity was modified'));
|
|
177
|
-
}
|
|
178
|
-
return ok({ ...entity, version: entity.version + 1 });
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
### BP-DESIGN-005: AuditService
|
|
183
|
-
|
|
184
|
-
Record data changes in audit logs.
|
|
185
|
-
|
|
186
|
-
```typescript
|
|
187
|
-
// ✅ Recommended: Audit logging
|
|
188
|
-
interface AuditEntry {
|
|
189
|
-
id: string;
|
|
190
|
-
entityType: string;
|
|
191
|
-
entityId: string;
|
|
192
|
-
action: 'CREATE' | 'UPDATE' | 'DELETE';
|
|
193
|
-
changes: object;
|
|
194
|
-
userId: string;
|
|
195
|
-
timestamp: Date;
|
|
196
|
-
}
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### BP-DESIGN-006: Entity Counter Reset
|
|
200
|
-
|
|
201
|
-
Provide reset functions for test isolation.
|
|
202
|
-
|
|
203
|
-
```typescript
|
|
204
|
-
// ✅ Recommended: Resettable counter
|
|
205
|
-
let petCounter = 0;
|
|
206
|
-
|
|
207
|
-
export function generatePetId(): string {
|
|
208
|
-
return `PET-${Date.now()}-${++petCounter}`;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export function resetPetCounter(): void {
|
|
212
|
-
petCounter = 0; // For tests
|
|
213
|
-
}
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
### BP-DESIGN-007: Expiry Time Logic
|
|
217
|
-
|
|
218
|
-
Use expiresAt field for time-limited entities.
|
|
219
|
-
|
|
220
|
-
```typescript
|
|
221
|
-
// ✅ Recommended: Explicit expiry
|
|
222
|
-
interface Reservation {
|
|
223
|
-
id: string;
|
|
224
|
-
createdAt: Date;
|
|
225
|
-
expiresAt: Date; // Explicit expiry time
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function isExpired(reservation: Reservation): boolean {
|
|
229
|
-
return new Date() > reservation.expiresAt;
|
|
230
|
-
}
|
|
231
54
|
```
|
|
232
55
|
|
|
233
56
|
## Test Patterns (5)
|
|
234
57
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
resetReservationCounter();
|
|
243
|
-
});
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
### BP-TEST-002: Verify API Before Test
|
|
247
|
-
|
|
248
|
-
Check method signatures before writing tests.
|
|
249
|
-
|
|
250
|
-
### BP-TEST-003: Vitest ESM Configuration
|
|
251
|
-
|
|
252
|
-
Use proper ESM setup for Vitest.
|
|
253
|
-
|
|
254
|
-
```typescript
|
|
255
|
-
// vitest.config.ts
|
|
256
|
-
export default defineConfig({
|
|
257
|
-
test: {
|
|
258
|
-
globals: true,
|
|
259
|
-
environment: 'node',
|
|
260
|
-
},
|
|
261
|
-
});
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
### BP-TEST-004: Result Type Test Pattern
|
|
58
|
+
| ID | パターン | 概要 |
|
|
59
|
+
|----|---------|------|
|
|
60
|
+
| BP-TEST-001 | Counter Reset | beforeEachでIDカウンターリセット |
|
|
61
|
+
| BP-TEST-002 | Verify API | テスト前にAPIシグネチャ確認 |
|
|
62
|
+
| BP-TEST-003 | Vitest ESM | Vitest + TypeScript ESM構成 |
|
|
63
|
+
| BP-TEST-004 | Result Type Test | isOk()/isErr()で両ケーステスト |
|
|
64
|
+
| BP-TEST-005 | Status Transition | 有効・無効遷移を網羅テスト |
|
|
265
65
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
```typescript
|
|
269
|
-
it('should succeed with valid input', () => {
|
|
270
|
-
const result = createPrice(1000);
|
|
271
|
-
expect(result.isOk()).toBe(true);
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
it('should fail with invalid input', () => {
|
|
275
|
-
const result = createPrice(-1);
|
|
276
|
-
expect(result.isErr()).toBe(true);
|
|
277
|
-
});
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
### BP-TEST-005: Status Transition Testing
|
|
281
|
-
|
|
282
|
-
Test all valid and invalid transitions.
|
|
283
|
-
|
|
284
|
-
```typescript
|
|
285
|
-
describe('status transitions', () => {
|
|
286
|
-
it.each([
|
|
287
|
-
['draft', 'active', true],
|
|
288
|
-
['draft', 'completed', false],
|
|
289
|
-
['active', 'completed', true],
|
|
290
|
-
])('%s -> %s should be %s', (from, to, valid) => {
|
|
291
|
-
expect(canTransition(from, to)).toBe(valid);
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
## CLI Commands
|
|
66
|
+
## CLI
|
|
297
67
|
|
|
298
68
|
```bash
|
|
299
|
-
|
|
300
|
-
npx musubix learn best-practices
|
|
301
|
-
|
|
302
|
-
# Filter by category
|
|
69
|
+
npx musubix learn best-practices # 全パターン表示
|
|
303
70
|
npx musubix learn best-practices --category code
|
|
304
|
-
npx musubix learn best-practices --category design
|
|
305
|
-
npx musubix learn best-practices --category test
|
|
306
|
-
|
|
307
|
-
# High confidence only
|
|
308
71
|
npx musubix learn best-practices --high-confidence
|
|
309
72
|
```
|
|
310
73
|
|
|
311
|
-
##
|
|
74
|
+
## 出力例
|
|
312
75
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
76
|
+
```
|
|
77
|
+
┌────────────────────────────────────────────────┐
|
|
78
|
+
│ Best Practices Applied │
|
|
79
|
+
├────────────────────────────────────────────────┤
|
|
80
|
+
│ Code Patterns: 5 applied │
|
|
81
|
+
│ Design Patterns: 7 applied │
|
|
82
|
+
│ Test Patterns: 5 applied │
|
|
83
|
+
│ Confidence: 95% average │
|
|
84
|
+
└────────────────────────────────────────────────┘
|
|
85
|
+
```
|