← Public packages
@kody/kody-factory
Forkable multi-project software factory: signals, priority queue, project UI, sweep job. Agent runners and Sentry reach it by events.
Files
import {
needsKentLabel,
ownerDecisionLabelPattern,
skippedLabel,
type Eligibility,
type FrictionIssue,
type SweepMode,
} from './shared.ts'
type Labeled = Pick<FrictionIssue, 'labels'>
export function hasSkippedLabel(issue: Labeled) {
return issue.labels.includes(skippedLabel)
}
/** `needs-kent` or any equivalent owner-decision label. */
export function hasNeedsKentLabel(issue: Labeled) {
return issue.labels.some((label) => label === needsKentLabel || ownerDecisionLabelPattern.test(label.trim()))
}
/**
* Eligibility for one open issue.
*
* - `daily` (default): not `needs-kent` and not `friction-skipped`.
* - `backlog`: not `needs-kent`; previously skipped issues are eligible again.
* - `all-issues`: not `needs-kent` and not `friction-skipped`.
* - `reevaluate`: labeled `needs-kent` (or an equivalent label).
*
* Extra-care areas never affect eligibility; they only tag issues for the
* prompt.
*
* Comments are never parsed for eligibility.
*/
export function isEligibleIssue(
issue: Labeled & Partial<Pick<FrictionIssue, 'title'>>,
mode: SweepMode = 'daily',
): Eligibility {
if (mode === 'reevaluate') {
if (!hasNeedsKentLabel(issue)) return { eligible: false, reason: 'not-needs-kent' }
return { eligible: true, reason: 'needs-kent' }
}
if (hasNeedsKentLabel(issue)) return { eligible: false, reason: 'needs-kent' }
if (hasSkippedLabel(issue)) {
return mode === 'backlog'
? { eligible: true, reason: 'skipped' }
: { eligible: false, reason: 'skipped' }
}
return { eligible: true, reason: 'open' }
}
export function eligibleIssues<T extends Labeled & Partial<Pick<FrictionIssue, 'title'>>>(issues: Array<T>, mode: SweepMode = 'daily') {
return issues.filter((issue) => isEligibleIssue(issue, mode).eligible)
}
export type EligibilityCounts = {
open: number
eligibleDaily: number
eligibleBacklog: number
skippedOnly: number
needsKent: number
}
export function countEligibility(issues: Array<Labeled>): EligibilityCounts {
let eligibleDaily = 0
let skippedOnly = 0
let needsKent = 0
for (const issue of issues) {
if (hasNeedsKentLabel(issue)) needsKent += 1
else if (hasSkippedLabel(issue)) skippedOnly += 1
else eligibleDaily += 1
}
return {
open: issues.length,
eligibleDaily,
eligibleBacklog: eligibleDaily + skippedOnly,
skippedOnly,
needsKent,
}
}