repo-wrapped 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateExecutiveSummary = generateExecutiveSummary;
4
+ exports.formatExecutiveSummary = formatExecutiveSummary;
5
+ const date_fns_1 = require("date-fns");
6
+ /**
7
+ * Generates an executive summary with KPIs, insights, and risks
8
+ */
9
+ function generateExecutiveSummary(input) {
10
+ const { commits, startDate, endDate, repoName, streakData, timePattern, commitQuality, knowledgeDistribution, velocityAnalysis, gapAnalysis, } = input;
11
+ const kpis = generateKPIs(commits, startDate, endDate, streakData, commitQuality, velocityAnalysis);
12
+ const keyInsights = generateKeyInsights(commits, streakData, timePattern, commitQuality, velocityAnalysis, gapAnalysis);
13
+ const risks = assessRisks(knowledgeDistribution, gapAnalysis, commitQuality, timePattern);
14
+ const recommendations = generateRecommendations(risks, keyInsights, commitQuality);
15
+ return {
16
+ generatedAt: new Date(),
17
+ period: { start: startDate, end: endDate },
18
+ repoName,
19
+ kpis,
20
+ keyInsights,
21
+ risks,
22
+ recommendations,
23
+ };
24
+ }
25
+ function generateKPIs(commits, startDate, endDate, streakData, commitQuality, velocityAnalysis) {
26
+ const kpis = [];
27
+ const totalDays = Math.ceil((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24)) + 1;
28
+ const totalWeeks = Math.max(1, Math.ceil(totalDays / 7));
29
+ // 1. Velocity KPI
30
+ const commitsPerWeek = Math.round((commits.length / totalWeeks) * 10) / 10;
31
+ const velocityTrend = velocityAnalysis?.overallTrend || 'stable';
32
+ const velocityTrendPct = velocityAnalysis?.trendPercentage || 0;
33
+ kpis.push({
34
+ name: 'Velocity',
35
+ value: `${commitsPerWeek}/week`,
36
+ trend: velocityTrend === 'increasing' ? 'up' : velocityTrend === 'decreasing' ? 'down' : 'stable',
37
+ trendValue: `${velocityTrendPct >= 0 ? '+' : ''}${velocityTrendPct}%`,
38
+ status: commitsPerWeek >= 10 ? 'green' : commitsPerWeek >= 5 ? 'yellow' : 'red',
39
+ benchmark: 'vs start of period',
40
+ });
41
+ // 2. Quality Score KPI
42
+ const qualityScore = Math.round(commitQuality.overallScore * 10) / 10;
43
+ kpis.push({
44
+ name: 'Quality Score',
45
+ value: `${qualityScore}/10`,
46
+ trend: qualityScore >= 7 ? 'up' : qualityScore >= 5 ? 'stable' : 'down',
47
+ trendValue: qualityScore >= 7 ? 'Good' : qualityScore >= 5 ? 'Fair' : 'Needs work',
48
+ status: qualityScore >= 7 ? 'green' : qualityScore >= 5 ? 'yellow' : 'red',
49
+ });
50
+ // 3. Active Contributors
51
+ const uniqueAuthors = new Set(commits.map(c => c.author)).size;
52
+ kpis.push({
53
+ name: 'Active Contributors',
54
+ value: uniqueAuthors,
55
+ trend: 'stable',
56
+ trendValue: `${uniqueAuthors} developer${uniqueAuthors !== 1 ? 's' : ''}`,
57
+ status: uniqueAuthors >= 3 ? 'green' : uniqueAuthors >= 2 ? 'yellow' : 'red',
58
+ });
59
+ // 4. Consistency
60
+ const consistencyPct = Math.round(streakData.activeDayPercentage);
61
+ kpis.push({
62
+ name: 'Consistency',
63
+ value: `${consistencyPct}%`,
64
+ trend: consistencyPct >= 50 ? 'up' : consistencyPct >= 30 ? 'stable' : 'down',
65
+ trendValue: `${streakData.totalActiveDays}/${totalDays} days active`,
66
+ status: consistencyPct >= 50 ? 'green' : consistencyPct >= 30 ? 'yellow' : 'red',
67
+ });
68
+ // 5. Longest Streak
69
+ kpis.push({
70
+ name: 'Best Streak',
71
+ value: `${streakData.longestStreak.days} days`,
72
+ trend: streakData.longestStreak.days >= 7 ? 'up' : 'stable',
73
+ trendValue: streakData.currentStreak.isActive ? 'Current active' : 'Historical',
74
+ status: streakData.longestStreak.days >= 14 ? 'green' : streakData.longestStreak.days >= 7 ? 'yellow' : 'red',
75
+ });
76
+ return kpis;
77
+ }
78
+ function generateKeyInsights(commits, streakData, timePattern, commitQuality, velocityAnalysis, gapAnalysis) {
79
+ const insights = [];
80
+ // Velocity insight
81
+ if (velocityAnalysis) {
82
+ if (velocityAnalysis.overallTrend === 'decreasing' && velocityAnalysis.trendPercentage <= -20) {
83
+ insights.push({
84
+ type: 'negative',
85
+ insight: `Velocity has decreased ${Math.abs(velocityAnalysis.trendPercentage)}% over this period`,
86
+ });
87
+ }
88
+ else if (velocityAnalysis.overallTrend === 'increasing' && velocityAnalysis.trendPercentage >= 20) {
89
+ insights.push({
90
+ type: 'positive',
91
+ insight: `Velocity has increased ${velocityAnalysis.trendPercentage}% over this period`,
92
+ });
93
+ }
94
+ // Anomalies
95
+ const criticalAnomalies = velocityAnalysis.anomalies.filter(a => a.severity === 'critical');
96
+ if (criticalAnomalies.length >= 2) {
97
+ insights.push({
98
+ type: 'negative',
99
+ insight: `${criticalAnomalies.length} critical productivity drops detected - potential blockers or disruptions`,
100
+ });
101
+ }
102
+ }
103
+ // Gap insight
104
+ if (gapAnalysis && gapAnalysis.gaps.length > 0) {
105
+ if (gapAnalysis.riskLevel === 'critical' || gapAnalysis.riskLevel === 'high') {
106
+ insights.push({
107
+ type: 'negative',
108
+ insight: `${gapAnalysis.totalGapDays} days lost to activity gaps (${gapAnalysis.percentageOfPeriodInGaps}% of period)`,
109
+ });
110
+ }
111
+ }
112
+ // Quality insight
113
+ if (commitQuality.overallScore >= 8) {
114
+ insights.push({
115
+ type: 'positive',
116
+ insight: 'Excellent commit quality with clear, well-structured messages',
117
+ });
118
+ }
119
+ else if (commitQuality.overallScore < 5) {
120
+ insights.push({
121
+ type: 'negative',
122
+ insight: `Commit quality score of ${Math.round(commitQuality.overallScore * 10) / 10}/10 indicates room for improvement`,
123
+ });
124
+ }
125
+ // Burnout insight
126
+ if (timePattern.burnoutRisk.level === 'high') {
127
+ insights.push({
128
+ type: 'negative',
129
+ insight: 'High burnout risk indicators detected (late nights, irregular hours)',
130
+ });
131
+ }
132
+ // Consistency insight
133
+ if (streakData.activeDayPercentage >= 60) {
134
+ insights.push({
135
+ type: 'positive',
136
+ insight: `Strong consistency with ${Math.round(streakData.activeDayPercentage)}% of days active`,
137
+ });
138
+ }
139
+ // Conventional commits
140
+ if (commitQuality.conventionalCommits.adherence >= 80) {
141
+ insights.push({
142
+ type: 'positive',
143
+ insight: `${Math.round(commitQuality.conventionalCommits.adherence)}% conventional commit adherence enables better automation`,
144
+ });
145
+ }
146
+ // Ensure we have at least 3 insights
147
+ if (insights.length < 3) {
148
+ insights.push({
149
+ type: 'neutral',
150
+ insight: `${commits.length} commits analyzed across ${streakData.totalActiveDays} active days`,
151
+ });
152
+ }
153
+ return insights.slice(0, 5);
154
+ }
155
+ function assessRisks(knowledgeDistribution, gapAnalysis, commitQuality, timePattern) {
156
+ const risks = [];
157
+ // Bus factor risk
158
+ if (knowledgeDistribution) {
159
+ const busFactorLevel = knowledgeDistribution.busFactorRisk.level;
160
+ if (busFactorLevel === 'critical' || busFactorLevel === 'high') {
161
+ risks.push({
162
+ category: 'Knowledge Distribution',
163
+ level: busFactorLevel === 'critical' ? 'high' : 'medium',
164
+ description: `Bus factor risk: ${knowledgeDistribution.knowledgeSilos.length} areas have single-owner knowledge`,
165
+ });
166
+ }
167
+ }
168
+ // Gap/blocker risk
169
+ if (gapAnalysis && gapAnalysis.riskLevel !== 'low') {
170
+ risks.push({
171
+ category: 'Productivity',
172
+ level: gapAnalysis.riskLevel === 'critical' ? 'high' : gapAnalysis.riskLevel,
173
+ description: `${gapAnalysis.gaps.length} activity gaps totaling ${gapAnalysis.totalGapDays} days of lost productivity`,
174
+ });
175
+ }
176
+ // Quality risk
177
+ if (commitQuality && commitQuality.overallScore < 5) {
178
+ risks.push({
179
+ category: 'Code Quality',
180
+ level: commitQuality.overallScore < 3 ? 'high' : 'medium',
181
+ description: 'Low commit quality may indicate rushed work or unclear requirements',
182
+ });
183
+ }
184
+ // Burnout risk
185
+ if (timePattern && timePattern.burnoutRisk.level === 'high') {
186
+ risks.push({
187
+ category: 'Team Health',
188
+ level: 'medium',
189
+ description: `Burnout indicators: ${timePattern.burnoutRisk.indicators.slice(0, 2).join(', ')}`,
190
+ });
191
+ }
192
+ // Sort by level
193
+ const levelOrder = { high: 0, medium: 1, low: 2 };
194
+ risks.sort((a, b) => levelOrder[a.level] - levelOrder[b.level]);
195
+ return risks;
196
+ }
197
+ function generateRecommendations(risks, insights, commitQuality) {
198
+ const recommendations = [];
199
+ // Based on risks
200
+ for (const risk of risks) {
201
+ if (risk.category === 'Knowledge Distribution') {
202
+ recommendations.push('Schedule knowledge sharing sessions to reduce bus factor risk');
203
+ }
204
+ else if (risk.category === 'Productivity') {
205
+ recommendations.push('Investigate root causes of activity gaps - potential blockers or process issues');
206
+ }
207
+ else if (risk.category === 'Code Quality') {
208
+ recommendations.push('Implement commit message guidelines and consider pre-commit hooks');
209
+ }
210
+ else if (risk.category === 'Team Health') {
211
+ recommendations.push('Review workload distribution and consider work-life balance initiatives');
212
+ }
213
+ }
214
+ // Quality-based recommendations
215
+ if (commitQuality.conventionalCommits.adherence < 50) {
216
+ recommendations.push('Adopt conventional commits standard for better changelog generation');
217
+ }
218
+ if (commitQuality.codeHygiene.workInProgress > commitQuality.totalCommits * 0.1) {
219
+ recommendations.push('Reduce WIP commits by encouraging atomic, complete changes');
220
+ }
221
+ // Ensure we have at least one recommendation
222
+ if (recommendations.length === 0) {
223
+ recommendations.push('Continue current practices - metrics are within healthy ranges');
224
+ }
225
+ return [...new Set(recommendations)].slice(0, 4);
226
+ }
227
+ /**
228
+ * Format executive summary for terminal display
229
+ */
230
+ function formatExecutiveSummary(summary) {
231
+ const lines = [];
232
+ lines.push('═══════════════════════════════════════════════════════════════');
233
+ lines.push(` 📊 EXECUTIVE SUMMARY: ${summary.repoName}`);
234
+ lines.push(` Period: ${(0, date_fns_1.format)(summary.period.start, 'MMM d, yyyy')} - ${(0, date_fns_1.format)(summary.period.end, 'MMM d, yyyy')}`);
235
+ lines.push('═══════════════════════════════════════════════════════════════');
236
+ lines.push('');
237
+ // KPIs
238
+ lines.push('📈 KEY PERFORMANCE INDICATORS');
239
+ lines.push('───────────────────────────────────────────────────────────────');
240
+ for (const kpi of summary.kpis) {
241
+ const statusEmoji = kpi.status === 'green' ? '🟢' : kpi.status === 'yellow' ? '🟡' : '🔴';
242
+ const trendEmoji = kpi.trend === 'up' ? '↑' : kpi.trend === 'down' ? '↓' : '→';
243
+ lines.push(` ${statusEmoji} ${kpi.name}: ${kpi.value} ${trendEmoji} ${kpi.trendValue}`);
244
+ }
245
+ lines.push('');
246
+ // Key Insights
247
+ lines.push('💡 KEY INSIGHTS');
248
+ lines.push('───────────────────────────────────────────────────────────────');
249
+ for (const insight of summary.keyInsights) {
250
+ const emoji = insight.type === 'positive' ? '✅' : insight.type === 'negative' ? '⚠️' : 'ℹ️';
251
+ lines.push(` ${emoji} ${insight.insight}`);
252
+ }
253
+ lines.push('');
254
+ // Risks
255
+ if (summary.risks.length > 0) {
256
+ lines.push('🚨 RISK ASSESSMENT');
257
+ lines.push('───────────────────────────────────────────────────────────────');
258
+ for (const risk of summary.risks) {
259
+ const levelEmoji = risk.level === 'high' ? '🔴' : risk.level === 'medium' ? '🟡' : '🟢';
260
+ lines.push(` ${levelEmoji} [${risk.level.toUpperCase()}] ${risk.category}: ${risk.description}`);
261
+ }
262
+ lines.push('');
263
+ }
264
+ // Recommendations
265
+ lines.push('📋 RECOMMENDATIONS');
266
+ lines.push('───────────────────────────────────────────────────────────────');
267
+ for (let i = 0; i < summary.recommendations.length; i++) {
268
+ lines.push(` ${i + 1}. ${summary.recommendations[i]}`);
269
+ }
270
+ lines.push('');
271
+ lines.push('═══════════════════════════════════════════════════════════════');
272
+ lines.push(` Generated: ${(0, date_fns_1.format)(summary.generatedAt, 'MMM d, yyyy HH:mm')}`);
273
+ lines.push('═══════════════════════════════════════════════════════════════');
274
+ return lines;
275
+ }
@@ -0,0 +1,300 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.analyzeGaps = analyzeGaps;
4
+ exports.formatGapInsights = formatGapInsights;
5
+ const date_fns_1 = require("date-fns");
6
+ /**
7
+ * Analyzes gaps in activity to identify blockers and disruptions
8
+ */
9
+ function analyzeGaps(commits, startDate, endDate, thresholdDays = 3, excludeWeekends = false) {
10
+ if (commits.length === 0) {
11
+ return getEmptyGapAnalysis(startDate, endDate);
12
+ }
13
+ // Sort commits by date
14
+ const sortedCommits = [...commits].sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime());
15
+ // Find all gaps
16
+ const gaps = findGaps(sortedCommits, startDate, endDate, thresholdDays, excludeWeekends);
17
+ // Calculate statistics
18
+ const totalGapDays = gaps.reduce((sum, gap) => sum + gap.durationDays, 0);
19
+ const totalPeriodDays = (0, date_fns_1.differenceInDays)(endDate, startDate) + 1;
20
+ const percentageOfPeriodInGaps = totalPeriodDays > 0
21
+ ? Math.round((totalGapDays / totalPeriodDays) * 1000) / 10
22
+ : 0;
23
+ const longestGap = gaps.length > 0
24
+ ? gaps.reduce((max, gap) => gap.durationDays > max.durationDays ? gap : max, gaps[0])
25
+ : null;
26
+ const averageGapLength = gaps.length > 0
27
+ ? Math.round((totalGapDays / gaps.length) * 10) / 10
28
+ : 0;
29
+ // Calculate gap frequency (gaps per month)
30
+ const months = totalPeriodDays / 30;
31
+ const gapFrequency = months > 0 ? Math.round((gaps.length / months) * 10) / 10 : 0;
32
+ // Detect patterns
33
+ const patterns = detectGapPatterns(gaps);
34
+ // Assess risk
35
+ const { riskLevel, riskFactors } = assessGapRisk(gaps, percentageOfPeriodInGaps, longestGap);
36
+ return {
37
+ gaps,
38
+ totalGapDays,
39
+ percentageOfPeriodInGaps,
40
+ longestGap,
41
+ averageGapLength,
42
+ gapFrequency,
43
+ patterns,
44
+ riskLevel,
45
+ riskFactors,
46
+ };
47
+ }
48
+ function findGaps(sortedCommits, startDate, endDate, thresholdDays, excludeWeekends) {
49
+ const gaps = [];
50
+ // Check gap from startDate to first commit
51
+ const firstCommitDate = new Date(sortedCommits[0].date);
52
+ const daysToFirstCommit = calculateDaysBetween(startDate, firstCommitDate, excludeWeekends);
53
+ if (daysToFirstCommit >= thresholdDays) {
54
+ gaps.push({
55
+ start: startDate,
56
+ end: (0, date_fns_1.addDays)(firstCommitDate, -1),
57
+ durationDays: daysToFirstCommit,
58
+ commitBefore: null,
59
+ commitAfter: {
60
+ date: firstCommitDate,
61
+ message: sortedCommits[0].message,
62
+ author: sortedCommits[0].author,
63
+ },
64
+ possibleType: classifyGap(startDate, (0, date_fns_1.addDays)(firstCommitDate, -1), daysToFirstCommit),
65
+ });
66
+ }
67
+ // Check gaps between commits
68
+ for (let i = 0; i < sortedCommits.length - 1; i++) {
69
+ const currentCommit = sortedCommits[i];
70
+ const nextCommit = sortedCommits[i + 1];
71
+ const currentDate = new Date(currentCommit.date);
72
+ const nextDate = new Date(nextCommit.date);
73
+ const daysBetween = calculateDaysBetween(currentDate, nextDate, excludeWeekends);
74
+ if (daysBetween >= thresholdDays) {
75
+ const gapStart = (0, date_fns_1.addDays)(currentDate, 1);
76
+ const gapEnd = (0, date_fns_1.addDays)(nextDate, -1);
77
+ gaps.push({
78
+ start: gapStart,
79
+ end: gapEnd,
80
+ durationDays: daysBetween,
81
+ commitBefore: {
82
+ date: currentDate,
83
+ message: currentCommit.message,
84
+ author: currentCommit.author,
85
+ },
86
+ commitAfter: {
87
+ date: nextDate,
88
+ message: nextCommit.message,
89
+ author: nextCommit.author,
90
+ },
91
+ possibleType: classifyGap(gapStart, gapEnd, daysBetween),
92
+ });
93
+ }
94
+ }
95
+ // Check gap from last commit to endDate
96
+ const lastCommit = sortedCommits[sortedCommits.length - 1];
97
+ const lastCommitDate = new Date(lastCommit.date);
98
+ const daysAfterLast = calculateDaysBetween(lastCommitDate, endDate, excludeWeekends);
99
+ if (daysAfterLast >= thresholdDays) {
100
+ gaps.push({
101
+ start: (0, date_fns_1.addDays)(lastCommitDate, 1),
102
+ end: endDate,
103
+ durationDays: daysAfterLast,
104
+ commitBefore: {
105
+ date: lastCommitDate,
106
+ message: lastCommit.message,
107
+ author: lastCommit.author,
108
+ },
109
+ commitAfter: null,
110
+ possibleType: classifyGap((0, date_fns_1.addDays)(lastCommitDate, 1), endDate, daysAfterLast),
111
+ });
112
+ }
113
+ return gaps;
114
+ }
115
+ function calculateDaysBetween(start, end, excludeWeekends) {
116
+ if (!excludeWeekends) {
117
+ return (0, date_fns_1.differenceInDays)(end, start);
118
+ }
119
+ let days = 0;
120
+ let current = new Date(start);
121
+ while (current < end) {
122
+ if (!(0, date_fns_1.isWeekend)(current)) {
123
+ days++;
124
+ }
125
+ current = (0, date_fns_1.addDays)(current, 1);
126
+ }
127
+ return days;
128
+ }
129
+ function classifyGap(start, end, durationDays) {
130
+ // Check if it's just a weekend
131
+ if (durationDays <= 2) {
132
+ const startIsWeekend = (0, date_fns_1.isWeekend)(start);
133
+ const endIsWeekend = (0, date_fns_1.isWeekend)(end);
134
+ if (startIsWeekend || endIsWeekend) {
135
+ return 'weekend';
136
+ }
137
+ }
138
+ // Check for common holiday periods (rough heuristics)
139
+ const startMonth = start.getMonth();
140
+ const startDay = start.getDate();
141
+ // Christmas/New Year period
142
+ if ((startMonth === 11 && startDay >= 20) || (startMonth === 0 && startDay <= 5)) {
143
+ return 'holiday';
144
+ }
145
+ // Summer vacation period (July-August) with longer gaps
146
+ if ((startMonth === 6 || startMonth === 7) && durationDays >= 5) {
147
+ return 'vacation';
148
+ }
149
+ // Longer gaps are more likely blockers
150
+ if (durationDays >= 7) {
151
+ return 'blocker';
152
+ }
153
+ return 'unknown';
154
+ }
155
+ function detectGapPatterns(gaps) {
156
+ const patterns = [];
157
+ if (gaps.length < 2) {
158
+ return patterns;
159
+ }
160
+ // Check for recurring patterns
161
+ const gapsByDayOfWeek = new Map();
162
+ for (const gap of gaps) {
163
+ const dayOfWeek = gap.start.getDay();
164
+ gapsByDayOfWeek.set(dayOfWeek, (gapsByDayOfWeek.get(dayOfWeek) || 0) + 1);
165
+ }
166
+ // Check if gaps tend to start on specific days (e.g., Mondays = after weekend extension)
167
+ for (const [day, count] of gapsByDayOfWeek) {
168
+ if (count >= 3 && count >= gaps.length * 0.4) {
169
+ const dayName = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][day];
170
+ patterns.push({
171
+ type: 'recurring-weekly',
172
+ description: `Gaps frequently start on ${dayName}s`,
173
+ occurrences: count,
174
+ });
175
+ }
176
+ }
177
+ // Check for blocker pattern (multiple unknown/blocker gaps)
178
+ const blockerGaps = gaps.filter(g => g.possibleType === 'blocker' || g.possibleType === 'unknown');
179
+ if (blockerGaps.length >= 3) {
180
+ patterns.push({
181
+ type: 'random',
182
+ description: `${blockerGaps.length} unexplained gaps detected - potential recurring blockers`,
183
+ occurrences: blockerGaps.length,
184
+ });
185
+ }
186
+ return patterns;
187
+ }
188
+ function assessGapRisk(gaps, percentageInGaps, longestGap) {
189
+ const riskFactors = [];
190
+ let riskScore = 0;
191
+ // Factor 1: Percentage of time in gaps
192
+ if (percentageInGaps >= 30) {
193
+ riskScore += 3;
194
+ riskFactors.push(`${percentageInGaps}% of time spent in activity gaps`);
195
+ }
196
+ else if (percentageInGaps >= 20) {
197
+ riskScore += 2;
198
+ riskFactors.push(`${percentageInGaps}% of time spent in activity gaps`);
199
+ }
200
+ else if (percentageInGaps >= 10) {
201
+ riskScore += 1;
202
+ riskFactors.push(`${percentageInGaps}% of time spent in activity gaps`);
203
+ }
204
+ // Factor 2: Longest gap duration
205
+ if (longestGap) {
206
+ if (longestGap.durationDays >= 21) {
207
+ riskScore += 3;
208
+ riskFactors.push(`Longest gap: ${longestGap.durationDays} days (3+ weeks)`);
209
+ }
210
+ else if (longestGap.durationDays >= 14) {
211
+ riskScore += 2;
212
+ riskFactors.push(`Longest gap: ${longestGap.durationDays} days (2+ weeks)`);
213
+ }
214
+ else if (longestGap.durationDays >= 7) {
215
+ riskScore += 1;
216
+ riskFactors.push(`Longest gap: ${longestGap.durationDays} days (1+ week)`);
217
+ }
218
+ }
219
+ // Factor 3: Number of blocker-type gaps
220
+ const blockerGaps = gaps.filter(g => g.possibleType === 'blocker');
221
+ if (blockerGaps.length >= 5) {
222
+ riskScore += 2;
223
+ riskFactors.push(`${blockerGaps.length} potential blocker gaps identified`);
224
+ }
225
+ else if (blockerGaps.length >= 2) {
226
+ riskScore += 1;
227
+ riskFactors.push(`${blockerGaps.length} potential blocker gaps identified`);
228
+ }
229
+ // Determine risk level
230
+ let riskLevel;
231
+ if (riskScore >= 6) {
232
+ riskLevel = 'critical';
233
+ }
234
+ else if (riskScore >= 4) {
235
+ riskLevel = 'high';
236
+ }
237
+ else if (riskScore >= 2) {
238
+ riskLevel = 'medium';
239
+ }
240
+ else {
241
+ riskLevel = 'low';
242
+ }
243
+ if (riskFactors.length === 0) {
244
+ riskFactors.push('No significant gap patterns detected');
245
+ }
246
+ return { riskLevel, riskFactors };
247
+ }
248
+ function getEmptyGapAnalysis(startDate, endDate) {
249
+ const totalDays = (0, date_fns_1.differenceInDays)(endDate, startDate) + 1;
250
+ return {
251
+ gaps: [{
252
+ start: startDate,
253
+ end: endDate,
254
+ durationDays: totalDays,
255
+ commitBefore: null,
256
+ commitAfter: null,
257
+ possibleType: 'blocker',
258
+ }],
259
+ totalGapDays: totalDays,
260
+ percentageOfPeriodInGaps: 100,
261
+ longestGap: null,
262
+ averageGapLength: totalDays,
263
+ gapFrequency: 0,
264
+ patterns: [],
265
+ riskLevel: 'critical',
266
+ riskFactors: ['No commits found in the analysis period'],
267
+ };
268
+ }
269
+ /**
270
+ * Format gap analysis for display
271
+ */
272
+ function formatGapInsights(analysis) {
273
+ const insights = [];
274
+ if (analysis.gaps.length === 0) {
275
+ insights.push('✅ No significant activity gaps detected');
276
+ return insights;
277
+ }
278
+ // Summary
279
+ insights.push(`🕳️ ${analysis.gaps.length} activity gap(s) detected`);
280
+ insights.push(`📅 ${analysis.totalGapDays} total gap days (${analysis.percentageOfPeriodInGaps}% of period)`);
281
+ // Longest gap
282
+ if (analysis.longestGap) {
283
+ const startStr = (0, date_fns_1.format)(analysis.longestGap.start, 'MMM d');
284
+ const endStr = (0, date_fns_1.format)(analysis.longestGap.end, 'MMM d, yyyy');
285
+ insights.push(`⏱️ Longest gap: ${analysis.longestGap.durationDays} days (${startStr} - ${endStr})`);
286
+ }
287
+ // Risk assessment
288
+ const riskEmoji = {
289
+ low: '🟢',
290
+ medium: '🟡',
291
+ high: '🟠',
292
+ critical: '🔴',
293
+ }[analysis.riskLevel];
294
+ insights.push(`${riskEmoji} Risk level: ${analysis.riskLevel.toUpperCase()}`);
295
+ // Top risk factors
296
+ for (const factor of analysis.riskFactors.slice(0, 3)) {
297
+ insights.push(` • ${factor}`);
298
+ }
299
+ return insights;
300
+ }