2026-11-10 17:33:30 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/diagnostics"
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/reporting"
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/llm"
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/outcomes"
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/processreport"
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/runner"
|
2026-11-10 20:16:59 +00:00
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/structuredoutput"
|
2026-11-16 14:18:38 +00:00
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/modules"
|
2026-11-16 15:12:06 +00:00
|
|
|
pk "go.maximumdirect.net/promptkit"
|
2026-11-10 17:33:30 +00:00
|
|
|
)
|
|
|
|
|
|
2026-11-16 15:12:06 +00:00
|
|
|
func executePipeline(ctx context.Context, loaded *processInputs, prepared *preparedProcess, normalized *schema.Transcript, warn func(error), progress func(string)) (processResult, error) {
|
2026-11-10 17:33:30 +00:00
|
|
|
cfg := &loaded.Configuration.Config
|
2026-11-16 14:18:38 +00:00
|
|
|
specs := prepared.Prepared.Specs
|
2026-11-10 20:48:32 +00:00
|
|
|
debug := prepared.Prepared.Debug
|
2026-11-16 15:08:02 +00:00
|
|
|
evidence := runner.EvidenceSelection{Reports: cfg.Reporting.Enabled, Debug: debug != nil}
|
2026-11-10 20:48:32 +00:00
|
|
|
var observer *llm.ObservationCollector
|
|
|
|
|
var hooks llm.CallHooks
|
|
|
|
|
if debug != nil {
|
|
|
|
|
observer = llm.NewObservationCollector()
|
|
|
|
|
hooks = observer.Hooks()
|
|
|
|
|
}
|
2026-11-16 15:12:06 +00:00
|
|
|
if progress != nil {
|
|
|
|
|
observe := hooks.OnEventWithCall
|
|
|
|
|
hooks.OnEventWithCall = func(callID uint64, coordinates structuredoutput.DiagnosticContext, event pk.ExecutionEvent) {
|
|
|
|
|
if observe != nil {
|
|
|
|
|
observe(callID, coordinates, event)
|
|
|
|
|
}
|
|
|
|
|
reportModelProgress(progress, coordinates, event)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-10 17:33:30 +00:00
|
|
|
for i := range specs {
|
|
|
|
|
item := &specs[i]
|
2026-11-16 15:00:05 +00:00
|
|
|
setupFailure := func(role string, cause error) error {
|
|
|
|
|
return &runner.ExecutionFailure{Phase: "setup", Origin: &outcomes.Reference{
|
|
|
|
|
StageIndex: &item.Index, StageID: item.ID, ModuleKey: item.ModuleKey, ModuleInstance: item.InstanceName,
|
|
|
|
|
}, Cause: fmt.Errorf("%s %s client: %w", item.InstanceName, role, cause)}
|
|
|
|
|
}
|
2026-11-10 20:48:32 +00:00
|
|
|
proposal, err := loaded.Runtime.NewRoleClient("proposal", *item.Settings.LLM.ProposalProfile, item.Settings.LLM, hooks)
|
2026-11-10 17:33:30 +00:00
|
|
|
if err != nil {
|
2026-11-16 15:00:05 +00:00
|
|
|
return processResult{}, setupFailure("proposal", err)
|
2026-11-10 17:33:30 +00:00
|
|
|
}
|
2026-11-10 20:48:32 +00:00
|
|
|
validation, err := loaded.Runtime.NewRoleClient("validation", *item.Settings.LLM.ValidationProfile, item.Settings.LLM, hooks)
|
2026-11-10 17:33:30 +00:00
|
|
|
if err != nil {
|
2026-11-16 15:00:05 +00:00
|
|
|
return processResult{}, setupFailure("validation", err)
|
2026-11-10 17:33:30 +00:00
|
|
|
}
|
|
|
|
|
item.ProposalClient, item.ValidationClient = proposal, validation
|
2026-11-11 04:20:23 +00:00
|
|
|
if item.Settings.LLM.CorrectionRepairAttempts > 0 {
|
|
|
|
|
repair, err := loaded.Runtime.NewRoleClient("correction_repair", *item.Settings.LLM.CorrectionRepairProfile, item.Settings.LLM, hooks)
|
|
|
|
|
if err != nil {
|
2026-11-16 15:00:05 +00:00
|
|
|
return processResult{}, setupFailure("correction repair", err)
|
2026-11-11 04:20:23 +00:00
|
|
|
}
|
2026-11-16 14:36:07 +00:00
|
|
|
item.RepairCoordinator = repair
|
2026-11-11 04:20:23 +00:00
|
|
|
}
|
2026-11-10 17:33:30 +00:00
|
|
|
}
|
2026-11-16 03:43:29 +00:00
|
|
|
var interactions structuredoutput.InteractionSink
|
|
|
|
|
var writer *llm.DiagnosticsWriter
|
|
|
|
|
if debug != nil {
|
|
|
|
|
writer = llm.NewDiagnosticsWriter(debug.Path())
|
|
|
|
|
interactions = writer
|
|
|
|
|
}
|
2026-11-10 17:33:30 +00:00
|
|
|
output, runErr := runner.New(modules.NewFactory()).Run(ctx, runner.RunInput{
|
|
|
|
|
Config: cfg, Transcript: normalized, ModuleSpecs: specs,
|
2026-11-16 15:12:06 +00:00
|
|
|
Interactions: interactions, Evidence: &evidence, Progress: runnerProgress(progress),
|
2026-11-10 17:33:30 +00:00
|
|
|
})
|
2026-11-10 20:48:32 +00:00
|
|
|
if debug != nil {
|
2026-11-16 03:43:29 +00:00
|
|
|
for _, warning := range writer.Warnings() {
|
|
|
|
|
warn(warning)
|
|
|
|
|
}
|
2026-11-16 14:53:14 +00:00
|
|
|
observations := processreport.IndexLLMObservations(observer.Snapshot(), output.WorkUnits)
|
|
|
|
|
warn(debug.WriteJSONArtifact(diagnostics.ArtifactLLMExecution, processreport.BuildLLMExecution(observations)))
|
2026-11-10 17:33:30 +00:00
|
|
|
warn(debug.WriteJSONArtifact(diagnostics.ArtifactCorrectionLedger, processreport.BuildCorrectionLedger(processreport.CorrectionLedgerInput{RunDirectoryPath: debug.Path(), RunOutput: &output})))
|
|
|
|
|
}
|
2026-11-10 20:48:32 +00:00
|
|
|
snapshot := processreport.Build(processreport.BuildInput{RunID: prepared.RunID, Status: reporting.StatusInProgress, StartedAt: prepared.Started,
|
2026-11-16 15:08:02 +00:00
|
|
|
ModuleSpecs: specs, RunOutput: &output, ProcessingError: runErr, SummaryOnly: !evidence.Reports})
|
2026-11-10 17:33:30 +00:00
|
|
|
return processResult{Transcript: output.FinalTranscript, Snapshot: snapshot}, runErr
|
|
|
|
|
}
|