package processreport import ( "time" "gitea.maximumdirect.net/eric/audita/v4/internal/framework/llm" "gitea.maximumdirect.net/eric/audita/v4/internal/framework/runner" "gitea.maximumdirect.net/eric/audita/v4/internal/framework/structuredoutput" pk "go.maximumdirect.net/promptkit" ) type executionCall struct { RequestedPromptID string `json:"requested_prompt_id,omitempty"` CallID uint64 `json:"call_id"` Context structuredoutput.DiagnosticContext `json:"context"` Prompt structuredoutput.PromptMetadata `json:"prompt"` Started time.Time `json:"started"` Finished *time.Time `json:"finished,omitempty"` ElapsedMS int64 `json:"elapsed_ms"` Failure structuredoutput.FailureKind `json:"failure,omitempty"` PromptKit pk.ExecutionGroupSummary `json:"promptkit"` } // BuildLLMExecution preserves native evidence with Audita's logical-call context. func BuildLLMExecution(snapshot llm.ObservationSnapshot) any { calls := make([]executionCall, 0, len(snapshot.Calls)) events := make([]llm.ExecutionObservation, len(snapshot.Events)) copy(events, snapshot.Events) groups := make(map[uint64]*pk.ExecutionGroup, len(snapshot.Calls)) for _, event := range events { group := groups[event.CallID] if group == nil { group = &pk.ExecutionGroup{} groups[event.CallID] = group } group.Observe(event.PromptKit) } for _, call := range snapshot.Calls { group := groups[call.CallID] if group == nil { group = &pk.ExecutionGroup{} } var finished *time.Time if !call.Finished.IsZero() { value := call.Finished finished = &value } calls = append(calls, executionCall{ RequestedPromptID: call.RequestedPromptID, CallID: call.CallID, Context: call.Context, Prompt: call.Prompt, Started: call.Started, Finished: finished, ElapsedMS: call.WallDuration.Milliseconds(), Failure: call.Failure, PromptKit: group.Snapshot(), }) } return struct { Summary llm.ExecutionSummary `json:"summary"` Calls []executionCall `json:"calls"` Events []llm.ExecutionObservation `json:"events"` }{llm.Summarize(snapshot), calls, events} } // IndexLLMObservations assigns the same proposal identities used by the ledger. func IndexLLMObservations(snapshot llm.ObservationSnapshot, units []runner.WorkUnitOutcome) llm.ObservationSnapshot { type sectionKey struct { module string section int } offsets := make(map[sectionKey]int) for _, unit := range units { if unit.ProposalIndexOffset != 0 { offsets[sectionKey{unit.ModuleInstance, unit.Section.Index}] = unit.ProposalIndexOffset } } index := func(context *structuredoutput.DiagnosticContext) { if context.SectionIndex != nil && context.ProposalIndex != nil { offset := offsets[sectionKey{context.ModuleInstance, *context.SectionIndex}] context.ProposalIndex = structuredoutput.OffsetProposalIndex(context.ProposalIndex, offset) } } for i := range snapshot.Calls { index(&snapshot.Calls[i].Context) } for i := range snapshot.Events { index(&snapshot.Events[i].Context) } return snapshot }