musubi-sdd 3.0.0 → 3.0.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.
- package/bin/musubi-browser.js +0 -0
- package/bin/musubi-convert.js +0 -0
- package/bin/musubi-gui.js +0 -0
- package/bin/musubi-validate.js +0 -10
- package/package.json +1 -1
- package/src/templates/agents/claude-code/skills/ai-ml-engineer/mlops-guide.md +350 -0
- package/src/templates/agents/claude-code/skills/ai-ml-engineer/model-card-template.md +246 -0
- package/src/templates/agents/claude-code/skills/api-designer/api-patterns.md +336 -0
- package/src/templates/agents/claude-code/skills/api-designer/openapi-template.md +376 -0
- package/src/templates/agents/claude-code/skills/bug-hunter/root-cause-analysis.md +177 -0
- package/src/templates/agents/claude-code/skills/change-impact-analyzer/dependency-graph-patterns.md +348 -0
- package/src/templates/agents/claude-code/skills/change-impact-analyzer/impact-analysis-template.md +246 -0
- package/src/templates/agents/claude-code/skills/cloud-architect/aws-patterns.md +239 -0
- package/src/templates/agents/claude-code/skills/cloud-architect/azure-patterns.md +300 -0
- package/src/templates/agents/claude-code/skills/cloud-architect/terraform-templates/azure-webapp.tf +337 -0
- package/src/templates/agents/claude-code/skills/code-reviewer/best-practices.md +155 -0
- package/src/templates/agents/claude-code/skills/code-reviewer/review-checklist.md +184 -0
- package/src/templates/agents/claude-code/skills/code-reviewer/review-standards.md +272 -0
- package/src/templates/agents/claude-code/skills/constitution-enforcer/constitutional-articles.md +449 -0
- package/src/templates/agents/claude-code/skills/constitution-enforcer/phase-minus-one-gates.md +375 -0
- package/src/templates/agents/claude-code/skills/database-administrator/backup-recovery.md +331 -0
- package/src/templates/agents/claude-code/skills/database-administrator/tuning-guide.md +314 -0
- package/src/templates/agents/claude-code/skills/database-schema-designer/schema-patterns.md +335 -0
- package/src/templates/agents/claude-code/skills/devops-engineer/ci-cd-templates.md +443 -0
- package/src/templates/agents/claude-code/skills/devops-engineer/pipeline-templates/github-actions.yml +311 -0
- package/src/templates/agents/claude-code/skills/devops-engineer/pipeline-templates/gitlab-ci.yml +255 -0
- package/src/templates/agents/claude-code/skills/orchestrator/patterns.md +266 -0
- package/src/templates/agents/claude-code/skills/orchestrator/selection-matrix.md +185 -0
- package/src/templates/agents/claude-code/skills/performance-engineer/optimization-playbook.md +306 -0
- package/src/templates/agents/claude-code/skills/performance-optimizer/benchmark-template.md +272 -0
- package/src/templates/agents/claude-code/skills/performance-optimizer/optimization-patterns.md +273 -0
- package/src/templates/agents/claude-code/skills/project-manager/agile-ceremonies.md +283 -0
- package/src/templates/agents/claude-code/skills/project-manager/project-templates.md +345 -0
- package/src/templates/agents/claude-code/skills/quality-assurance/qa-plan-template.md +219 -0
- package/src/templates/agents/claude-code/skills/release-coordinator/feature-flag-guide.md +312 -0
- package/src/templates/agents/claude-code/skills/release-coordinator/release-plan-template.md +230 -0
- package/src/templates/agents/claude-code/skills/requirements-analyst/ears-format.md +259 -0
- package/src/templates/agents/claude-code/skills/requirements-analyst/validation-rules.md +359 -0
- package/src/templates/agents/claude-code/skills/security-auditor/audit-checklists.md +243 -0
- package/src/templates/agents/claude-code/skills/security-auditor/owasp-top-10.md +349 -0
- package/src/templates/agents/claude-code/skills/security-auditor/vulnerability-patterns.md +295 -0
- package/src/templates/agents/claude-code/skills/site-reliability-engineer/incident-response-template.md +286 -0
- package/src/templates/agents/claude-code/skills/site-reliability-engineer/observability-patterns.md +359 -0
- package/src/templates/agents/claude-code/skills/site-reliability-engineer/slo-sli-guide.md +302 -0
- package/src/templates/agents/claude-code/skills/software-developer/solid-principles.md +348 -0
- package/src/templates/agents/claude-code/skills/software-developer/test-first-workflow.md +370 -0
- package/src/templates/agents/claude-code/skills/steering/auto-update-rules.md +328 -0
- package/src/templates/agents/claude-code/skills/system-architect/adr-template.md +295 -0
- package/src/templates/agents/claude-code/skills/system-architect/c4-model-guide.md +328 -0
- package/src/templates/agents/claude-code/skills/technical-writer/doc-templates/documentation-templates.md +436 -0
- package/src/templates/agents/claude-code/skills/test-engineer/ears-test-mapping.md +444 -0
- package/src/templates/agents/claude-code/skills/test-engineer/test-types.md +425 -0
- package/src/templates/agents/claude-code/skills/traceability-auditor/coverage-matrix-template.md +131 -0
- package/src/templates/agents/claude-code/skills/traceability-auditor/gap-detection-rules.md +227 -0
- package/src/templates/agents/claude-code/skills/ui-ux-designer/accessibility-guidelines.md +318 -0
- package/src/templates/agents/claude-code/skills/ui-ux-designer/design-system-components.md +345 -0
- package/src/validators/constitutional-validator.js +494 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Root Cause Analysis Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
A systematic approach to identifying the underlying causes of bugs and issues.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 5 Whys Technique
|
|
10
|
+
|
|
11
|
+
Ask "Why?" five times to get to the root cause.
|
|
12
|
+
|
|
13
|
+
### Example
|
|
14
|
+
|
|
15
|
+
**Problem**: Users are seeing 500 errors on checkout.
|
|
16
|
+
|
|
17
|
+
1. **Why?** The payment service is throwing exceptions.
|
|
18
|
+
2. **Why?** The API is timing out.
|
|
19
|
+
3. **Why?** Database queries are taking too long.
|
|
20
|
+
4. **Why?** A missing index on the orders table.
|
|
21
|
+
5. **Why?** The index was dropped during a migration.
|
|
22
|
+
|
|
23
|
+
**Root Cause**: Migration removed necessary index.
|
|
24
|
+
|
|
25
|
+
**Fix**: Add index back, add migration tests.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Investigation Workflow
|
|
30
|
+
|
|
31
|
+
### Phase 1: Reproduce
|
|
32
|
+
|
|
33
|
+
```markdown
|
|
34
|
+
## Reproduction Steps
|
|
35
|
+
1. [Step to reproduce]
|
|
36
|
+
2. [Step to reproduce]
|
|
37
|
+
3. [Observe behavior]
|
|
38
|
+
|
|
39
|
+
## Environment
|
|
40
|
+
- OS: [OS version]
|
|
41
|
+
- Browser: [Browser version]
|
|
42
|
+
- Version: [App version]
|
|
43
|
+
- User role: [Role]
|
|
44
|
+
|
|
45
|
+
## Expected vs Actual
|
|
46
|
+
- Expected: [Expected behavior]
|
|
47
|
+
- Actual: [Actual behavior]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Phase 2: Gather Evidence
|
|
51
|
+
|
|
52
|
+
```markdown
|
|
53
|
+
## Error Information
|
|
54
|
+
- Error message: [message]
|
|
55
|
+
- Stack trace: [trace]
|
|
56
|
+
- Error code: [code]
|
|
57
|
+
|
|
58
|
+
## Logs
|
|
59
|
+
- Timestamp: [time]
|
|
60
|
+
- Relevant logs: [logs]
|
|
61
|
+
|
|
62
|
+
## Metrics
|
|
63
|
+
- CPU/Memory: [values]
|
|
64
|
+
- Request rate: [rate]
|
|
65
|
+
- Error rate: [rate]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Phase 3: Analyze
|
|
69
|
+
|
|
70
|
+
1. **Timeline**: What changed recently?
|
|
71
|
+
2. **Pattern**: Is it consistent or intermittent?
|
|
72
|
+
3. **Scope**: Affects all users or specific subset?
|
|
73
|
+
4. **Correlation**: What else happens at the same time?
|
|
74
|
+
|
|
75
|
+
### Phase 4: Identify Root Cause
|
|
76
|
+
|
|
77
|
+
```markdown
|
|
78
|
+
## Root Cause Analysis
|
|
79
|
+
|
|
80
|
+
### Direct Cause
|
|
81
|
+
[What directly caused the symptom]
|
|
82
|
+
|
|
83
|
+
### Contributing Factors
|
|
84
|
+
- [Factor 1]
|
|
85
|
+
- [Factor 2]
|
|
86
|
+
|
|
87
|
+
### Root Cause
|
|
88
|
+
[The underlying issue that should be fixed]
|
|
89
|
+
|
|
90
|
+
### Evidence
|
|
91
|
+
[How we know this is the root cause]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Phase 5: Fix and Prevent
|
|
95
|
+
|
|
96
|
+
```markdown
|
|
97
|
+
## Resolution
|
|
98
|
+
|
|
99
|
+
### Immediate Fix
|
|
100
|
+
[What was done to resolve the issue]
|
|
101
|
+
|
|
102
|
+
### Prevention
|
|
103
|
+
[What will prevent recurrence]
|
|
104
|
+
|
|
105
|
+
### Verification
|
|
106
|
+
[How we verified the fix works]
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Bug Report Template
|
|
112
|
+
|
|
113
|
+
```markdown
|
|
114
|
+
# Bug Report: [Title]
|
|
115
|
+
|
|
116
|
+
## Summary
|
|
117
|
+
[Brief description]
|
|
118
|
+
|
|
119
|
+
## Severity
|
|
120
|
+
- [ ] Critical (system down)
|
|
121
|
+
- [ ] High (major feature broken)
|
|
122
|
+
- [ ] Medium (feature degraded)
|
|
123
|
+
- [ ] Low (minor issue)
|
|
124
|
+
|
|
125
|
+
## Steps to Reproduce
|
|
126
|
+
1.
|
|
127
|
+
2.
|
|
128
|
+
3.
|
|
129
|
+
|
|
130
|
+
## Expected Behavior
|
|
131
|
+
[What should happen]
|
|
132
|
+
|
|
133
|
+
## Actual Behavior
|
|
134
|
+
[What actually happens]
|
|
135
|
+
|
|
136
|
+
## Environment
|
|
137
|
+
- Version:
|
|
138
|
+
- Browser:
|
|
139
|
+
- OS:
|
|
140
|
+
|
|
141
|
+
## Logs/Screenshots
|
|
142
|
+
[Attach relevant evidence]
|
|
143
|
+
|
|
144
|
+
## Root Cause (after investigation)
|
|
145
|
+
[The identified root cause]
|
|
146
|
+
|
|
147
|
+
## Fix
|
|
148
|
+
[The solution implemented]
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Common Bug Categories
|
|
154
|
+
|
|
155
|
+
| Category | Symptoms | Typical Causes |
|
|
156
|
+
|----------|----------|----------------|
|
|
157
|
+
| Logic Error | Wrong output | Incorrect algorithm, edge case |
|
|
158
|
+
| Null Reference | Crash | Missing null check |
|
|
159
|
+
| Race Condition | Intermittent | Concurrency issue |
|
|
160
|
+
| Memory Leak | Slow degradation | Uncleaned resources |
|
|
161
|
+
| Timeout | Slow/hang | Network, long query |
|
|
162
|
+
| Security | Unauthorized access | Missing validation |
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Debugging Checklist
|
|
167
|
+
|
|
168
|
+
- [ ] Can I reproduce the issue?
|
|
169
|
+
- [ ] What is the exact error message?
|
|
170
|
+
- [ ] When did this start happening?
|
|
171
|
+
- [ ] What changed recently?
|
|
172
|
+
- [ ] Does it happen in other environments?
|
|
173
|
+
- [ ] Does it affect all users?
|
|
174
|
+
- [ ] Are there patterns (time, load, etc.)?
|
|
175
|
+
- [ ] What do the logs show?
|
|
176
|
+
- [ ] Can I isolate the component?
|
|
177
|
+
- [ ] Have I verified my fix?
|
package/src/templates/agents/claude-code/skills/change-impact-analyzer/dependency-graph-patterns.md
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
# Dependency Graph Patterns
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Patterns for building and analyzing dependency graphs in software systems.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Types of Dependencies
|
|
10
|
+
|
|
11
|
+
### Direct Dependencies
|
|
12
|
+
```
|
|
13
|
+
A → B: A directly uses B
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Transitive Dependencies
|
|
17
|
+
```
|
|
18
|
+
A → B → C: A depends on C through B
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Circular Dependencies
|
|
22
|
+
```
|
|
23
|
+
A → B → C → A: Problematic cycle
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Dependency Graph Representation
|
|
29
|
+
|
|
30
|
+
### Adjacency List
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
interface DependencyGraph {
|
|
34
|
+
nodes: Map<string, Node>;
|
|
35
|
+
edges: Map<string, Set<string>>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const graph: DependencyGraph = {
|
|
39
|
+
nodes: new Map([
|
|
40
|
+
['auth.ts', { type: 'module', path: 'src/auth.ts' }],
|
|
41
|
+
['user.ts', { type: 'module', path: 'src/user.ts' }],
|
|
42
|
+
]),
|
|
43
|
+
edges: new Map([
|
|
44
|
+
['auth.ts', new Set(['user.ts', 'db.ts'])],
|
|
45
|
+
['user.ts', new Set(['db.ts'])],
|
|
46
|
+
])
|
|
47
|
+
};
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### DOT Format (Graphviz)
|
|
51
|
+
|
|
52
|
+
```dot
|
|
53
|
+
digraph Dependencies {
|
|
54
|
+
rankdir=TB;
|
|
55
|
+
|
|
56
|
+
// Nodes
|
|
57
|
+
auth [label="auth.ts"];
|
|
58
|
+
user [label="user.ts"];
|
|
59
|
+
db [label="db.ts"];
|
|
60
|
+
|
|
61
|
+
// Edges
|
|
62
|
+
auth -> user;
|
|
63
|
+
auth -> db;
|
|
64
|
+
user -> db;
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Analysis Algorithms
|
|
71
|
+
|
|
72
|
+
### Find All Dependencies (DFS)
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
function getAllDependencies(
|
|
76
|
+
graph: DependencyGraph,
|
|
77
|
+
node: string,
|
|
78
|
+
visited = new Set<string>()
|
|
79
|
+
): Set<string> {
|
|
80
|
+
if (visited.has(node)) return visited;
|
|
81
|
+
|
|
82
|
+
visited.add(node);
|
|
83
|
+
|
|
84
|
+
const deps = graph.edges.get(node) || new Set();
|
|
85
|
+
for (const dep of deps) {
|
|
86
|
+
getAllDependencies(graph, dep, visited);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return visited;
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Find Circular Dependencies
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
function findCircularDependencies(
|
|
97
|
+
graph: DependencyGraph
|
|
98
|
+
): string[][] {
|
|
99
|
+
const cycles: string[][] = [];
|
|
100
|
+
const visited = new Set<string>();
|
|
101
|
+
const recursionStack = new Set<string>();
|
|
102
|
+
|
|
103
|
+
function dfs(node: string, path: string[]): void {
|
|
104
|
+
visited.add(node);
|
|
105
|
+
recursionStack.add(node);
|
|
106
|
+
path.push(node);
|
|
107
|
+
|
|
108
|
+
const deps = graph.edges.get(node) || new Set();
|
|
109
|
+
for (const dep of deps) {
|
|
110
|
+
if (!visited.has(dep)) {
|
|
111
|
+
dfs(dep, [...path]);
|
|
112
|
+
} else if (recursionStack.has(dep)) {
|
|
113
|
+
// Cycle found
|
|
114
|
+
const cycleStart = path.indexOf(dep);
|
|
115
|
+
cycles.push(path.slice(cycleStart));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
path.pop();
|
|
120
|
+
recursionStack.delete(node);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
for (const node of graph.nodes.keys()) {
|
|
124
|
+
if (!visited.has(node)) {
|
|
125
|
+
dfs(node, []);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return cycles;
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Topological Sort
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
function topologicalSort(graph: DependencyGraph): string[] {
|
|
137
|
+
const inDegree = new Map<string, number>();
|
|
138
|
+
const result: string[] = [];
|
|
139
|
+
const queue: string[] = [];
|
|
140
|
+
|
|
141
|
+
// Initialize in-degrees
|
|
142
|
+
for (const node of graph.nodes.keys()) {
|
|
143
|
+
inDegree.set(node, 0);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
for (const deps of graph.edges.values()) {
|
|
147
|
+
for (const dep of deps) {
|
|
148
|
+
inDegree.set(dep, (inDegree.get(dep) || 0) + 1);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Start with nodes that have no dependencies
|
|
153
|
+
for (const [node, degree] of inDegree) {
|
|
154
|
+
if (degree === 0) {
|
|
155
|
+
queue.push(node);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
while (queue.length > 0) {
|
|
160
|
+
const node = queue.shift()!;
|
|
161
|
+
result.push(node);
|
|
162
|
+
|
|
163
|
+
const deps = graph.edges.get(node) || new Set();
|
|
164
|
+
for (const dep of deps) {
|
|
165
|
+
inDegree.set(dep, inDegree.get(dep)! - 1);
|
|
166
|
+
if (inDegree.get(dep) === 0) {
|
|
167
|
+
queue.push(dep);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Impact Scoring
|
|
179
|
+
|
|
180
|
+
### Afferent Coupling (Ca)
|
|
181
|
+
Number of modules that depend on this module.
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
function getAfferentCoupling(
|
|
185
|
+
graph: DependencyGraph,
|
|
186
|
+
node: string
|
|
187
|
+
): number {
|
|
188
|
+
let count = 0;
|
|
189
|
+
for (const [source, deps] of graph.edges) {
|
|
190
|
+
if (deps.has(node)) {
|
|
191
|
+
count++;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return count;
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Efferent Coupling (Ce)
|
|
199
|
+
Number of modules this module depends on.
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
function getEfferentCoupling(
|
|
203
|
+
graph: DependencyGraph,
|
|
204
|
+
node: string
|
|
205
|
+
): number {
|
|
206
|
+
return graph.edges.get(node)?.size || 0;
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Instability Metric
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
I = Ce / (Ca + Ce)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
- I = 0: Completely stable (many dependents)
|
|
217
|
+
- I = 1: Completely unstable (many dependencies)
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## Visualization
|
|
222
|
+
|
|
223
|
+
### Mermaid Diagram
|
|
224
|
+
|
|
225
|
+
```mermaid
|
|
226
|
+
graph TD
|
|
227
|
+
A[auth.ts] --> B[user.ts]
|
|
228
|
+
A --> C[db.ts]
|
|
229
|
+
B --> C
|
|
230
|
+
D[api.ts] --> A
|
|
231
|
+
D --> E[router.ts]
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### ASCII Art
|
|
235
|
+
|
|
236
|
+
```
|
|
237
|
+
┌─────────┐
|
|
238
|
+
│ api.ts │
|
|
239
|
+
└────┬────┘
|
|
240
|
+
│
|
|
241
|
+
├─────────────┐
|
|
242
|
+
▼ ▼
|
|
243
|
+
┌─────────┐ ┌──────────┐
|
|
244
|
+
│ auth.ts │ │ router.ts │
|
|
245
|
+
└────┬────┘ └──────────┘
|
|
246
|
+
│
|
|
247
|
+
├─────────────┐
|
|
248
|
+
▼ ▼
|
|
249
|
+
┌─────────┐ ┌─────────┐
|
|
250
|
+
│ user.ts │ │ db.ts │
|
|
251
|
+
└────┬────┘ └─────────┘
|
|
252
|
+
│ ▲
|
|
253
|
+
└─────────────┘
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## Building Dependency Graphs
|
|
259
|
+
|
|
260
|
+
### From TypeScript
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
import * as ts from 'typescript';
|
|
264
|
+
|
|
265
|
+
function extractImports(filePath: string): string[] {
|
|
266
|
+
const sourceFile = ts.createSourceFile(
|
|
267
|
+
filePath,
|
|
268
|
+
fs.readFileSync(filePath, 'utf8'),
|
|
269
|
+
ts.ScriptTarget.Latest,
|
|
270
|
+
true
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
const imports: string[] = [];
|
|
274
|
+
|
|
275
|
+
ts.forEachChild(sourceFile, (node) => {
|
|
276
|
+
if (ts.isImportDeclaration(node)) {
|
|
277
|
+
const moduleSpecifier = node.moduleSpecifier;
|
|
278
|
+
if (ts.isStringLiteral(moduleSpecifier)) {
|
|
279
|
+
imports.push(moduleSpecifier.text);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
return imports;
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### From package.json
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
function getDependencies(packagePath: string): string[] {
|
|
292
|
+
const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
|
293
|
+
return [
|
|
294
|
+
...Object.keys(pkg.dependencies || {}),
|
|
295
|
+
...Object.keys(pkg.devDependencies || {})
|
|
296
|
+
];
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## Change Impact from Graph
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
function getImpactedModules(
|
|
306
|
+
graph: DependencyGraph,
|
|
307
|
+
changedModules: string[]
|
|
308
|
+
): Set<string> {
|
|
309
|
+
const impacted = new Set<string>();
|
|
310
|
+
|
|
311
|
+
// Find all modules that depend on changed modules
|
|
312
|
+
for (const changed of changedModules) {
|
|
313
|
+
// Reverse DFS to find dependents
|
|
314
|
+
for (const [source, deps] of graph.edges) {
|
|
315
|
+
if (deps.has(changed)) {
|
|
316
|
+
impacted.add(source);
|
|
317
|
+
// Recursively find dependents of dependents
|
|
318
|
+
for (const dep of getImpactedModules(graph, [source])) {
|
|
319
|
+
impacted.add(dep);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return impacted;
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
## Dependency Analysis Checklist
|
|
332
|
+
|
|
333
|
+
### Build Graph
|
|
334
|
+
- [ ] Parse source files
|
|
335
|
+
- [ ] Extract import statements
|
|
336
|
+
- [ ] Resolve module paths
|
|
337
|
+
- [ ] Store in graph structure
|
|
338
|
+
|
|
339
|
+
### Analyze
|
|
340
|
+
- [ ] Find circular dependencies
|
|
341
|
+
- [ ] Calculate coupling metrics
|
|
342
|
+
- [ ] Identify hotspots
|
|
343
|
+
- [ ] Generate reports
|
|
344
|
+
|
|
345
|
+
### Visualize
|
|
346
|
+
- [ ] Create diagrams
|
|
347
|
+
- [ ] Highlight problem areas
|
|
348
|
+
- [ ] Show change impact
|