( runs: MaintainRun[], stats: MaintainStats, allScopes: readonly string[], )
| 60 | /** Auto-recommend the next scope to run, with a reason. Prefers a never-run scope; else the scope |
| 61 | * blocking most often (a backlog it can't currently clear); else the least-used. PURE. */ |
| 62 | export function recommendNextScope( |
| 63 | runs: MaintainRun[], |
| 64 | stats: MaintainStats, |
| 65 | allScopes: readonly string[], |
| 66 | ): { scope: string; why: string } | null { |
| 67 | const never = suggestNextScopes(stats, allScopes); |
| 68 | if (never.length) return { scope: never[0]!, why: 'never run here yet — try it' }; |
| 69 | // count blocks per scope (a scope that keeps blocking has a backlog worth a look) |
| 70 | const blocks = new Map<string, number>(); |
| 71 | for (const r of runs) if (r.status === 'blocked') blocks.set(r.scope, (blocks.get(r.scope) ?? 0) + 1); |
| 72 | const topBlock = [...blocks.entries()].sort((a, b) => b[1] - a[1])[0]; |
| 73 | if (topBlock && topBlock[1] >= 2) return { scope: topBlock[0], why: `blocked ${topBlock[1]}× recently — review the backlog` }; |
| 74 | const leastUsed = [...stats.byScope].sort((a, b) => a.runs - b.runs)[0]; |
| 75 | return leastUsed ? { scope: leastUsed.scope, why: 'least-exercised scope' } : null; |
| 76 | } |
| 77 | |
| 78 | export interface MaintainWeekly { |
| 79 | opened: number; blocked: number; filesCleaned: number; minutesSaved: number; |
no test coverage detected