musubix 1.1.15 → 1.3.1

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.
@@ -0,0 +1,155 @@
1
+ # MUSUBIX Code Review Command
2
+
3
+ Perform comprehensive code review with SOLID principles and quality checks.
4
+
5
+ ---
6
+
7
+ ## Instructions for AI Agent
8
+
9
+ You are executing the `musubix review [feature-name]` command to perform code review.
10
+
11
+ ### Command Format
12
+
13
+ ```bash
14
+ npx musubix codegen analyze <file>
15
+ npx musubix trace validate
16
+ ```
17
+
18
+ ### Your Task
19
+
20
+ Perform comprehensive code review focusing on:
21
+
22
+ 1. SOLID Principles Compliance
23
+ 2. Code Quality Metrics
24
+ 3. Design Pattern Usage
25
+ 4. Traceability Verification
26
+ 5. Best Practices Adherence
27
+
28
+ ---
29
+
30
+ ## Process
31
+
32
+ ### 1. Read Source Code and Context
33
+
34
+ ```bash
35
+ # Source Code
36
+ packages/core/src/{{feature}}/**/*.ts
37
+ packages/mcp-server/src/tools/**/*.ts
38
+
39
+ # Design Documentation
40
+ storage/specs/DES-{{FEATURE}}-001.md
41
+
42
+ # Steering Context
43
+ steering/structure.ja.md
44
+ steering/tech.ja.md
45
+ steering/rules/constitution.md
46
+ ```
47
+
48
+ ### 2. SOLID Principles Check
49
+
50
+ Review each file for:
51
+
52
+ | Principle | Check |
53
+ |-----------|-------|
54
+ | **S**ingle Responsibility | 1つのクラス/関数は1つの責務のみ |
55
+ | **O**pen/Closed | 拡張に開き、修正に閉じている |
56
+ | **L**iskov Substitution | 派生クラスは基底クラスと置換可能 |
57
+ | **I**nterface Segregation | クライアント固有のインターフェース |
58
+ | **D**ependency Inversion | 抽象に依存、具象に依存しない |
59
+
60
+ ### 3. Code Quality Metrics
61
+
62
+ Analyze:
63
+
64
+ - **Cyclomatic Complexity**: 関数あたり10以下
65
+ - **Lines per Function**: 50行以下
66
+ - **Lines per File**: 300行以下
67
+ - **Nesting Depth**: 3レベル以下
68
+ - **Parameter Count**: 5個以下
69
+
70
+ ### 4. Design Pattern Review
71
+
72
+ Check for:
73
+
74
+ - [ ] Repository Pattern (データアクセス)
75
+ - [ ] Service Layer (ビジネスロジック)
76
+ - [ ] Factory Pattern (オブジェクト生成)
77
+ - [ ] Value Objects (ドメイン概念)
78
+ - [ ] Result Type (エラーハンドリング)
79
+
80
+ ### 5. Best Practices Check
81
+
82
+ | カテゴリ | チェック項目 |
83
+ |---------|-------------|
84
+ | 命名規則 | PascalCase (型), camelCase (変数/関数), UPPER_CASE (定数) |
85
+ | TypeScript | strict mode, 明示的な型定義, any禁止 |
86
+ | エラー処理 | Result<T, E>パターン, 適切なエラーメッセージ |
87
+ | コメント | JSDoc形式, 複雑なロジックの説明 |
88
+ | インポート | 絶対パス, 循環参照なし |
89
+
90
+ ---
91
+
92
+ ## Output Format
93
+
94
+ ```markdown
95
+ # Code Review Report: {{FEATURE}}
96
+
97
+ ## Summary
98
+ - **Overall Score**: A/B/C/D/F
99
+ - **Files Reviewed**: X files
100
+ - **Issues Found**: X critical, X warnings, X suggestions
101
+
102
+ ## SOLID Compliance
103
+ | Principle | Status | Notes |
104
+ |-----------|--------|-------|
105
+ | SRP | ✅/⚠️/❌ | ... |
106
+ | OCP | ✅/⚠️/❌ | ... |
107
+ | LSP | ✅/⚠️/❌ | ... |
108
+ | ISP | ✅/⚠️/❌ | ... |
109
+ | DIP | ✅/⚠️/❌ | ... |
110
+
111
+ ## Quality Metrics
112
+ | Metric | Value | Status |
113
+ |--------|-------|--------|
114
+ | Avg Cyclomatic Complexity | X | ✅/⚠️/❌ |
115
+ | Max Lines per Function | X | ✅/⚠️/❌ |
116
+ | Max Nesting Depth | X | ✅/⚠️/❌ |
117
+
118
+ ## Issues
119
+
120
+ ### Critical (Must Fix)
121
+ 1. [FILE:LINE] Description
122
+
123
+ ### Warnings (Should Fix)
124
+ 1. [FILE:LINE] Description
125
+
126
+ ### Suggestions (Nice to Have)
127
+ 1. [FILE:LINE] Description
128
+
129
+ ## Recommendations
130
+ 1. ...
131
+ 2. ...
132
+ ```
133
+
134
+ ---
135
+
136
+ ## Traceability
137
+
138
+ This skill implements:
139
+ - **Article III**: Test-First Imperative (コードレビューによる品質確保)
140
+ - **Article VII**: Simplicity Gate (コードの複雑性チェック)
141
+
142
+ ---
143
+
144
+ ## Related Commands
145
+
146
+ ```bash
147
+ # Static analysis
148
+ npx musubix codegen analyze <file>
149
+
150
+ # Traceability validation
151
+ npx musubix trace validate
152
+
153
+ # Security scanning
154
+ npx musubix codegen security <path>
155
+ ```
@@ -0,0 +1,228 @@
1
+ # MUSUBIX Security Scan Command
2
+
3
+ Perform comprehensive security scanning and vulnerability detection.
4
+
5
+ ---
6
+
7
+ ## Instructions for AI Agent
8
+
9
+ You are executing the `musubix security [feature-name]` command to perform security analysis.
10
+
11
+ ### Command Format
12
+
13
+ ```bash
14
+ npx musubix codegen security <path>
15
+ ```
16
+
17
+ ### Your Task
18
+
19
+ Perform comprehensive security analysis covering:
20
+
21
+ 1. OWASP Top 10 vulnerabilities
22
+ 2. Dependency vulnerabilities
23
+ 3. Authentication/Authorization issues
24
+ 4. Data validation gaps
25
+ 5. Sensitive data exposure
26
+
27
+ ---
28
+
29
+ ## Process
30
+
31
+ ### 1. Read Source Code and Dependencies
32
+
33
+ ```bash
34
+ # Source Code
35
+ packages/core/src/{{feature}}/**/*.ts
36
+ packages/mcp-server/src/tools/**/*.ts
37
+
38
+ # Dependencies
39
+ package.json
40
+ package-lock.json
41
+
42
+ # Auth module
43
+ packages/core/src/auth/**/*.ts
44
+ ```
45
+
46
+ ### 2. OWASP Top 10 Checks
47
+
48
+ | # | Vulnerability | Check |
49
+ |---|--------------|-------|
50
+ | A01 | Broken Access Control | 認可チェックの実装確認 |
51
+ | A02 | Cryptographic Failures | 暗号化の適切な使用 |
52
+ | A03 | Injection | SQL/NoSQL/コマンドインジェクション |
53
+ | A04 | Insecure Design | セキュリティパターンの適用 |
54
+ | A05 | Security Misconfiguration | 設定の安全性 |
55
+ | A06 | Vulnerable Components | 依存関係の脆弱性 |
56
+ | A07 | Authentication Failures | 認証の実装不備 |
57
+ | A08 | Software/Data Integrity | データ整合性の検証 |
58
+ | A09 | Security Logging | ログと監視 |
59
+ | A10 | SSRF | サーバーサイドリクエストフォージェリ |
60
+
61
+ ### 3. Code Pattern Analysis
62
+
63
+ #### ❌ Dangerous Patterns
64
+
65
+ ```typescript
66
+ // SQL Injection - 危険
67
+ const query = `SELECT * FROM users WHERE id = ${userId}`;
68
+
69
+ // Command Injection - 危険
70
+ exec(`ls ${userInput}`);
71
+
72
+ // Path Traversal - 危険
73
+ const file = fs.readFileSync(`./uploads/${filename}`);
74
+
75
+ // Hardcoded Secrets - 危険
76
+ const apiKey = 'sk-1234567890abcdef';
77
+
78
+ // eval() - 危険
79
+ eval(userInput);
80
+ ```
81
+
82
+ #### ✅ Safe Patterns
83
+
84
+ ```typescript
85
+ // Parameterized Query - 安全
86
+ const query = db.query('SELECT * FROM users WHERE id = ?', [userId]);
87
+
88
+ // Input Validation - 安全
89
+ const sanitized = sanitize(userInput);
90
+
91
+ // Path Validation - 安全
92
+ const safePath = path.resolve('./uploads', path.basename(filename));
93
+
94
+ // Environment Variables - 安全
95
+ const apiKey = process.env.API_KEY;
96
+
97
+ // No eval - 安全
98
+ const result = JSON.parse(jsonString);
99
+ ```
100
+
101
+ ### 4. Authentication & Authorization
102
+
103
+ Check for:
104
+
105
+ - [ ] JWT/Session token validation
106
+ - [ ] Password hashing (bcrypt, argon2)
107
+ - [ ] Role-based access control (RBAC)
108
+ - [ ] Rate limiting
109
+ - [ ] CSRF protection
110
+ - [ ] Secure cookie flags
111
+
112
+ ### 5. Data Validation
113
+
114
+ ```typescript
115
+ // ✅ Recommended: Zod schema validation
116
+ import { z } from 'zod';
117
+
118
+ const UserInputSchema = z.object({
119
+ email: z.string().email(),
120
+ password: z.string().min(8).max(100),
121
+ age: z.number().int().positive().max(150),
122
+ });
123
+
124
+ // Validate all user inputs
125
+ const result = UserInputSchema.safeParse(userInput);
126
+ if (!result.success) {
127
+ return err(new ValidationError(result.error));
128
+ }
129
+ ```
130
+
131
+ ### 6. Dependency Audit
132
+
133
+ ```bash
134
+ # Check for known vulnerabilities
135
+ npm audit
136
+ npm audit --audit-level=moderate
137
+
138
+ # Update vulnerable packages
139
+ npm audit fix
140
+ ```
141
+
142
+ ---
143
+
144
+ ## Output Format
145
+
146
+ ```markdown
147
+ # Security Scan Report: {{FEATURE}}
148
+
149
+ ## Summary
150
+ - **Risk Level**: Critical/High/Medium/Low
151
+ - **Vulnerabilities Found**: X critical, X high, X medium, X low
152
+ - **Dependencies Audited**: X packages
153
+
154
+ ## OWASP Top 10 Assessment
155
+
156
+ | Category | Status | Findings |
157
+ |----------|--------|----------|
158
+ | A01: Access Control | ✅/⚠️/❌ | ... |
159
+ | A02: Cryptographic | ✅/⚠️/❌ | ... |
160
+ | A03: Injection | ✅/⚠️/❌ | ... |
161
+ | A04: Insecure Design | ✅/⚠️/❌ | ... |
162
+ | A05: Misconfiguration | ✅/⚠️/❌ | ... |
163
+ | A06: Vulnerable Deps | ✅/⚠️/❌ | ... |
164
+ | A07: Auth Failures | ✅/⚠️/❌ | ... |
165
+ | A08: Integrity | ✅/⚠️/❌ | ... |
166
+ | A09: Logging | ✅/⚠️/❌ | ... |
167
+ | A10: SSRF | ✅/⚠️/❌ | ... |
168
+
169
+ ## Critical Vulnerabilities
170
+
171
+ ### 1. [CRITICAL] SQL Injection in user-service.ts
172
+ - **Location**: packages/core/src/user/user-service.ts:45
173
+ - **Description**: User input directly concatenated in SQL query
174
+ - **Remediation**: Use parameterized queries
175
+ - **Reference**: CWE-89
176
+
177
+ ### 2. [HIGH] Hardcoded API Key
178
+ - **Location**: packages/core/src/auth/config.ts:12
179
+ - **Description**: API key stored in source code
180
+ - **Remediation**: Use environment variables
181
+ - **Reference**: CWE-798
182
+
183
+ ## Dependency Vulnerabilities
184
+
185
+ | Package | Severity | Version | Fixed In |
186
+ |---------|----------|---------|----------|
187
+ | lodash | High | 4.17.20 | 4.17.21 |
188
+
189
+ ## Recommendations
190
+
191
+ 1. **Immediate**: Fix all critical vulnerabilities
192
+ 2. **Short-term**: Update vulnerable dependencies
193
+ 3. **Long-term**: Implement security testing in CI/CD
194
+
195
+ ## Compliance Checklist
196
+
197
+ - [ ] Input validation on all user inputs
198
+ - [ ] Output encoding for XSS prevention
199
+ - [ ] Parameterized queries for database access
200
+ - [ ] Secrets in environment variables
201
+ - [ ] HTTPS enforced
202
+ - [ ] Security headers configured
203
+ - [ ] Rate limiting implemented
204
+ - [ ] Audit logging enabled
205
+ ```
206
+
207
+ ---
208
+
209
+ ## Traceability
210
+
211
+ This skill implements:
212
+ - **Article IX**: Integration-First Testing (セキュリティテスト)
213
+ - Security requirements validation
214
+
215
+ ---
216
+
217
+ ## Related Commands
218
+
219
+ ```bash
220
+ # Security scan
221
+ npx musubix codegen security <path>
222
+
223
+ # Dependency audit
224
+ npm audit
225
+
226
+ # Static analysis
227
+ npx musubix codegen analyze <file>
228
+ ```
@@ -0,0 +1,230 @@
1
+ # MUSUBIX Test Generation Command
2
+
3
+ Generate comprehensive tests following Test-First (Red-Green-Blue) methodology.
4
+
5
+ ---
6
+
7
+ ## Instructions for AI Agent
8
+
9
+ You are executing the `musubix test [feature-name]` command to generate tests.
10
+
11
+ ### Command Format
12
+
13
+ ```bash
14
+ npx musubix test generate <file>
15
+ npx musubix test coverage <dir>
16
+ ```
17
+
18
+ ### Your Task
19
+
20
+ Generate comprehensive tests following:
21
+
22
+ 1. Test-First (Red-Green-Blue) methodology
23
+ 2. EARS requirements coverage
24
+ 3. Result Type testing patterns
25
+ 4. Status transition testing
26
+
27
+ ---
28
+
29
+ ## Process
30
+
31
+ ### 1. Read Requirements and Design
32
+
33
+ ```bash
34
+ # Requirements (for test cases)
35
+ storage/specs/REQ-{{FEATURE}}-001.md
36
+
37
+ # Design (for component structure)
38
+ storage/specs/DES-{{FEATURE}}-001.md
39
+
40
+ # Existing implementation
41
+ packages/core/src/{{feature}}/**/*.ts
42
+ ```
43
+
44
+ ### 2. Test Categories
45
+
46
+ Generate tests for each category:
47
+
48
+ | Category | Coverage Target | Priority |
49
+ |----------|-----------------|----------|
50
+ | Unit Tests | Functions, Value Objects | P0 |
51
+ | Integration Tests | Services, Repositories | P0 |
52
+ | E2E Tests | Full workflows | P1 |
53
+ | Edge Cases | Boundary conditions | P0 |
54
+ | Error Cases | Error handling | P0 |
55
+
56
+ ### 3. Test Structure
57
+
58
+ ```typescript
59
+ import { describe, it, expect, beforeEach } from 'vitest';
60
+
61
+ describe('FeatureName', () => {
62
+ beforeEach(() => {
63
+ // Reset counters for deterministic IDs
64
+ resetFeatureCounter();
65
+ });
66
+
67
+ describe('creation', () => {
68
+ it('should create valid entity', () => {
69
+ // Arrange
70
+ const input = { ... };
71
+
72
+ // Act
73
+ const result = createEntity(input);
74
+
75
+ // Assert
76
+ expect(result.isOk()).toBe(true);
77
+ if (result.isOk()) {
78
+ expect(result.value.id).toMatch(/^ENT-\d{8}-001$/);
79
+ }
80
+ });
81
+
82
+ it('should reject invalid input', () => {
83
+ // Arrange
84
+ const input = { invalid: true };
85
+
86
+ // Act
87
+ const result = createEntity(input);
88
+
89
+ // Assert
90
+ expect(result.isErr()).toBe(true);
91
+ if (result.isErr()) {
92
+ expect(result.error.message).toContain('validation');
93
+ }
94
+ });
95
+ });
96
+ });
97
+ ```
98
+
99
+ ### 4. EARS Requirements Mapping
100
+
101
+ Each requirement must have corresponding tests:
102
+
103
+ ```typescript
104
+ /**
105
+ * REQ-AUTH-001: WHEN user provides valid credentials,
106
+ * THEN the system SHALL authenticate the user.
107
+ */
108
+ describe('REQ-AUTH-001: User Authentication', () => {
109
+ it('should authenticate user with valid credentials', async () => {
110
+ // Test implementation
111
+ });
112
+ });
113
+ ```
114
+
115
+ ### 5. Result Type Test Patterns
116
+
117
+ ```typescript
118
+ // ✅ Test both success and failure cases
119
+ describe('createPrice', () => {
120
+ it('should create valid price', () => {
121
+ const result = createPrice(1000);
122
+ expect(result.isOk()).toBe(true);
123
+ if (result.isOk()) {
124
+ expect(result.value.amount).toBe(1000);
125
+ }
126
+ });
127
+
128
+ it('should reject price below minimum', () => {
129
+ const result = createPrice(50);
130
+ expect(result.isErr()).toBe(true);
131
+ if (result.isErr()) {
132
+ expect(result.error.message).toContain('100');
133
+ }
134
+ });
135
+ });
136
+ ```
137
+
138
+ ### 6. Status Transition Testing
139
+
140
+ ```typescript
141
+ describe('Status Transitions', () => {
142
+ const validTransitions: [Status, Status][] = [
143
+ ['draft', 'active'],
144
+ ['active', 'completed'],
145
+ ['active', 'cancelled'],
146
+ ];
147
+
148
+ const invalidTransitions: [Status, Status][] = [
149
+ ['completed', 'active'],
150
+ ['cancelled', 'draft'],
151
+ ];
152
+
153
+ validTransitions.forEach(([from, to]) => {
154
+ it(`should allow transition from ${from} to ${to}`, () => {
155
+ const entity = createEntityWithStatus(from);
156
+ const result = entity.transitionTo(to);
157
+ expect(result.isOk()).toBe(true);
158
+ });
159
+ });
160
+
161
+ invalidTransitions.forEach(([from, to]) => {
162
+ it(`should reject transition from ${from} to ${to}`, () => {
163
+ const entity = createEntityWithStatus(from);
164
+ const result = entity.transitionTo(to);
165
+ expect(result.isErr()).toBe(true);
166
+ });
167
+ });
168
+ });
169
+ ```
170
+
171
+ ---
172
+
173
+ ## Output Format
174
+
175
+ ```markdown
176
+ # Test Generation Report: {{FEATURE}}
177
+
178
+ ## Summary
179
+ - **Test Files Created**: X
180
+ - **Test Cases**: X total (X unit, X integration, X e2e)
181
+ - **Requirements Covered**: X/Y (Z%)
182
+
183
+ ## Generated Test Files
184
+
185
+ ### packages/core/__tests__/{{feature}}/entity.test.ts
186
+ - X test cases
187
+ - Covers: REQ-XXX-001, REQ-XXX-002
188
+
189
+ ### packages/core/__tests__/{{feature}}/service.test.ts
190
+ - X test cases
191
+ - Covers: REQ-XXX-003, REQ-XXX-004
192
+
193
+ ## Requirements Coverage Matrix
194
+
195
+ | Requirement | Test File | Test Cases | Status |
196
+ |-------------|-----------|------------|--------|
197
+ | REQ-XXX-001 | entity.test.ts | 3 | ✅ |
198
+ | REQ-XXX-002 | entity.test.ts | 2 | ✅ |
199
+ | REQ-XXX-003 | service.test.ts | 4 | ✅ |
200
+
201
+ ## Run Tests
202
+
203
+ \`\`\`bash
204
+ npm run test -- packages/core/__tests__/{{feature}}/
205
+ npm run test:coverage
206
+ \`\`\`
207
+ ```
208
+
209
+ ---
210
+
211
+ ## Traceability
212
+
213
+ This skill implements:
214
+ - **Article III**: Test-First Imperative (テスト先行開発)
215
+ - **Article V**: Traceability Mandate (要件↔テストの追跡)
216
+
217
+ ---
218
+
219
+ ## Related Commands
220
+
221
+ ```bash
222
+ # Generate tests
223
+ npx musubix test generate <file>
224
+
225
+ # Run tests with coverage
226
+ npm run test:coverage
227
+
228
+ # Validate traceability
229
+ npx musubix trace validate
230
+ ```