| 38 | }; |
| 39 | |
| 40 | export function classifyTerminalRuntimeLedger( |
| 41 | run: AgentRunHeader, |
| 42 | events: readonly RuntimeEvent[], |
| 43 | ): TerminalRuntimeLedgerClassification { |
| 44 | const terminalEvents = matchingTerminalRuntimeEvents(run, events); |
| 45 | if (terminalEvents.length === 0) { |
| 46 | return { kind: 'none', terminalEvents }; |
| 47 | } |
| 48 | if (terminalEvents.length > 1) { |
| 49 | return { kind: 'ambiguous', terminalEvents }; |
| 50 | } |
| 51 | |
| 52 | const fact = classifyRuntimeEventTerminalFact(run, events).fact; |
| 53 | if (fact) { |
| 54 | return { kind: 'fact', fact, terminalEvents }; |
| 55 | } |
| 56 | return { |
| 57 | kind: 'incomplete_single_terminal', |
| 58 | terminalEvent: terminalEvents[0]!, |
| 59 | terminalEvents, |
| 60 | }; |
| 61 | } |
| 62 | |
| 63 | export interface CommitTerminalRunWithRuntimeFactInput { |
| 64 | runStore: AgentRunStore; |