← 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 { agentShadowStore, type AgentShadowRow } from './store.ts'
export type AgentEventsReport = {
events: number
compared: number
matched: number
mismatched: AgentShadowRow[]
/** Events for runs with no factory card (other sessions the runner watches). */
noCard: number
recent: AgentShadowRow[]
}
export function buildAgentEventsReport(rows: AgentShadowRow[]): AgentEventsReport {
const r: AgentEventsReport = { events: rows.length, compared: 0, matched: 0, mismatched: [], noCard: 0, recent: rows.slice(0, 20) }
for (const row of rows) {
if (row.itemState === 'no-card') r.noCard++
if (row.directState === 'not-checked') continue
r.compared++
if (row.match) r.matched++
else r.mismatched.push(row)
}
r.mismatched = r.mismatched.slice(0, 50)
return r
}
/**
* Shadow comparison of runner session events against the built-in runner's
* own status for the same runs.
*
* @param input - `{ limit? }` rows to read (default 400, max 2000)
* @returns `{ events, compared, matched, mismatched[], noCard, recent[] }`
*
* @example
* import report from 'kody:@kody/kody-factory/agent-events/report'
* await report({})
* // => { events: 9, compared: 4, matched: 4, mismatched: [], noCard: 5, recent: [...] }
*/
export default async function agentEventsReport(input: { limit?: number } = {}): Promise<AgentEventsReport> {
const limit = Math.min(Math.max(Math.floor(Number(input?.limit) || 400), 1), 2000)
return buildAgentEventsReport(await agentShadowStore().recent(limit))
}