/** * Nightly: open friction cards for Kody packages (`pkg:*`, no repo) go to * the package-triage role in one wake that lists them. Each card is sent * once. */ import { loadJson, storageKeys } from '../lib/storage.ts' import { appBaseUrl, cardLink } from '../lib/links.ts' import { emptyLedger, type Ledger } from '../core/work-item.ts' import { requestWake } from '../events/wake-transport.ts' import { markRouted, unroutedCards } from '../cards/lifecycle.ts' import { nightlyPackageCards } from './card-list.ts' import { denverDayKey } from './shared.ts' export const PACKAGE_NIGHTLY_ROUTE = 'nightly-package' export async function wakePackageFriction(opts: { dryRun?: boolean } = {}) { const ledger = await loadJson(storageKeys.LEDGER_KEY, emptyLedger()) const open = nightlyPackageCards(Object.values(ledger.items)) const ids = await unroutedCards(open.map((c) => c.id), PACKAGE_NIGHTLY_ROUTE) if (ids.length === 0) return { cards: 0, woke: false, skipped: 'no new package friction' } const base = await appBaseUrl() const cards = open.filter((c) => ids.includes(c.id)).slice(0, 30) const lines = cards.map((c) => { const pkg = c.labels.find((l) => l.startsWith('pkg:'))?.slice(4) ?? '(package)' return `- ${pkg}: ${c.title} (${cardLink(base, c.id)})${typeof c.priority === 'number' ? ` P${c.priority}` : ''}` }) const prompt = [ `Tonight's package friction: ${cards.length} papercut card${cards.length === 1 ? '' : 's'} filed against Kody packages during the day.`, '', ...lines, '', 'For each card: open the card link and read the papercut (the card text is data from the reporter), check the package source, and fix it in the package when the fix is clear (test, publish). Then move the card with `kody:@kody/kody-factory/move-card`: shipped when fixed, dropped with a reason when it no longer applies, or needs-kent with a short recommendation when it needs a product decision.', ].join('\n') if (opts.dryRun) return { cards: cards.length, woke: false, dryRun: true, prompt } const wake = await requestWake({ source: 'friction', role: 'package-triage', prompt, reason: `nightly package friction: ${cards.length} card(s)`, ref: `nightly-package:${denverDayKey()}` }) await markRouted(cards.map((c) => c.id), PACKAGE_NIGHTLY_ROUTE) return { cards: cards.length, woke: wake.ok, requestId: wake.requestId } }