/** * Nightly run groups: list open group sessions (with whether each still * holds its issues or cards), or close one that is stuck. * * @example * import groups from 'kody:@kody/kody-factory/friction/groups' * await groups({ action: 'list' }) * await groups({ action: 'close', groupKey: '...', reason: 'stuck session' }) */ import { loadInFlight } from '../friction/in-flight.ts' import { closeGroupSession, getGroupSession } from '../friction/storage.ts' export default async function groups(input: { action?: 'list' | 'close'; groupKey?: string; reason?: string } = {}) { if ((input.action ?? 'list') === 'list') { const inFlight = await loadInFlight({ dryRun: true }) return { ok: true, count: inFlight.count, sessions: inFlight.sessions.map((s) => ({ groupKey: s.groupKey, repo: s.repo, groupName: s.groupName, items: s.issueNumbers.length, holds: s.holds, reason: s.reason, prUrls: s.prUrls })) } } const key = String(input.groupKey ?? '') if (!(await getGroupSession(key))) throw new Error(`friction/groups: no open group ${key.slice(0, 120)}`) await closeGroupSession(key, `closed by hand: ${String(input.reason ?? 'stuck').slice(0, 200)}`) return { ok: true, closed: key } }