Prepare normalized processing plans and fixed chunks
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"sync"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/appconfig"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/normalization"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/outputschema"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/reporting"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/schema"
|
||||
@@ -74,13 +73,8 @@ func runProcess(inv commandkit.Invocation, input processInput) commandkit.Outcom
|
||||
}
|
||||
loaded.RawTranscript = nil
|
||||
cfg := &loaded.Configuration.Config.Application
|
||||
normalizer := normalization.NewNormalizer(normalization.NormalizationConfig{
|
||||
MaxSegmentGap: cfg.Normalization.MaxSegmentGap, EllipsisGap: cfg.Normalization.EllipsisGap,
|
||||
MaxSegmentDuration: cfg.Normalization.MaxSegmentDuration, MaxSegmentTokens: cfg.Normalization.MaxSegmentTokens,
|
||||
})
|
||||
transcript := loaded.Source.Canonical()
|
||||
normalized, summary := prepared.Prepared.Plan.Transcript, prepared.Prepared.Plan.Summary
|
||||
loaded.Source = nil
|
||||
normalized, summary := normalizer.Normalize(transcript)
|
||||
if debug != nil {
|
||||
warn(debug.WriteNormalizedTranscript(normalized))
|
||||
warn(debug.WriteNormalizationSummary(summary))
|
||||
|
||||
@@ -81,7 +81,7 @@ func loadProcessInputs(ctx context.Context, input processInput, mode commandkit.
|
||||
|
||||
// preparedProcess groups the output resources and the facts needed for reports.
|
||||
type preparedProcess struct {
|
||||
Prepared *preflight.Prepared
|
||||
Prepared *preparedOutput
|
||||
RunID string
|
||||
Started time.Time
|
||||
}
|
||||
@@ -127,17 +127,17 @@ func prepareProcess(ctx context.Context, input processInput, loaded *processInpu
|
||||
return renderReportBundle(processreport.Failed(failedSnapshot, primary, "initialization", failures))
|
||||
}
|
||||
}
|
||||
var debug *preflight.DebugInput
|
||||
var debug *debugInput
|
||||
var warnings []error
|
||||
if input.Debug.Value {
|
||||
var effective bytes.Buffer
|
||||
if err := loaded.Configuration.WriteEffective(&effective); err != nil {
|
||||
warnings = append(warnings, err)
|
||||
}
|
||||
debug = &preflight.DebugInput{WorkDir: cfg.Diagnostics.WorkDir, RunID: runID, EffectiveConfig: effective.Bytes(), Metadata: diagnostics.InvocationMetadata{Operation: "process", TranscriptPath: input.Transcript, OutputPath: input.Output.Value, Overlay: input.Overlay.Value, ConfigVersion: &cfg.Version, RunID: runID, StartedAt: started}}
|
||||
debug = &debugInput{WorkDir: cfg.Diagnostics.WorkDir, RunID: runID, EffectiveConfig: effective.Bytes(), Metadata: diagnostics.InvocationMetadata{Operation: "process", TranscriptPath: input.Transcript, OutputPath: input.Output.Value, Overlay: input.Overlay.Value, ConfigVersion: &cfg.Version, RunID: runID, StartedAt: started}}
|
||||
}
|
||||
checkedBackends := make(map[string]struct{})
|
||||
prepared, err := preflight.Prepare(ctx, preflight.Input{InspectProfile: func(ctx context.Context, id string) error {
|
||||
inspectProfile := func(ctx context.Context, id string) error {
|
||||
profile, err := loaded.Runtime.Engine.InspectProfile(ctx, id)
|
||||
if errors.Is(err, pk.ErrProfileNotFound) {
|
||||
return &preflight.SelectionError{Cause: err}
|
||||
@@ -157,7 +157,12 @@ func prepareProcess(ctx context.Context, input processInput, loaded *processInpu
|
||||
checkedBackends[backend] = struct{}{}
|
||||
}
|
||||
return err
|
||||
}, Config: cfg, Transcript: loaded.Source, Output: diagnostics.OutputSelection{InputTranscriptPath: input.Transcript, TranscriptPath: input.Output.Value, ReportDir: reportDir, ReportingEnabled: cfg.Reporting.Enabled, ProtectedPaths: loaded.ProtectedPaths, Stdout: stdout}, InitialReports: initial, FailedReports: failed, Debug: debug})
|
||||
}
|
||||
plan, err := preflight.BuildPlan(ctx, cfg, loaded.Source, inspectProfile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
prepared, err := prepareOutput(ctx, plan, diagnostics.OutputSelection{InputTranscriptPath: input.Transcript, TranscriptPath: input.Output.Value, ReportDir: reportDir, ReportingEnabled: cfg.Reporting.Enabled, ProtectedPaths: loaded.ProtectedPaths, Stdout: stdout}, initial, failed, debug)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
func executePipeline(ctx context.Context, loaded *processInputs, prepared *preparedProcess, normalized *schema.Transcript, warn func(error), progress func(string)) (processResult, error) {
|
||||
cfg := &loaded.Configuration.Config.Application
|
||||
specs := prepared.Prepared.Specs
|
||||
specs := prepared.Prepared.Plan.Specs
|
||||
debug := prepared.Prepared.Debug
|
||||
evidence := runner.EvidenceSelection{Reports: cfg.Reporting.Enabled, Debug: debug != nil}
|
||||
var observer *llm.ObservationCollector
|
||||
@@ -62,7 +62,7 @@ func executePipeline(ctx context.Context, loaded *processInputs, prepared *prepa
|
||||
interactions = writer
|
||||
}
|
||||
output, runErr := runner.New(modules.NewFactory()).Run(ctx, runner.RunInput{
|
||||
Config: cfg, Transcript: normalized, ModuleSpecs: specs,
|
||||
Sections: prepared.Prepared.Plan.Sections, Transcript: normalized, ModuleSpecs: specs,
|
||||
Interactions: interactions, Evidence: &evidence, Progress: runnerProgress(progress),
|
||||
})
|
||||
if debug != nil {
|
||||
|
||||
55
internal/cli/process_prepare_output.go
Normal file
55
internal/cli/process_prepare_output.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/diagnostics"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/preflight"
|
||||
)
|
||||
|
||||
type debugInput struct {
|
||||
WorkDir string
|
||||
RunID string
|
||||
Metadata diagnostics.InvocationMetadata
|
||||
EffectiveConfig []byte
|
||||
}
|
||||
|
||||
type preparedOutput struct {
|
||||
Plan *preflight.Plan
|
||||
Output *diagnostics.OutputSession
|
||||
Debug *diagnostics.RunDirectory
|
||||
Warnings []error
|
||||
}
|
||||
|
||||
func prepareOutput(ctx context.Context, plan *preflight.Plan, selection diagnostics.OutputSelection, initial diagnostics.ReportBundle, failed diagnostics.ReportRenderer, debug *debugInput) (*preparedOutput, error) {
|
||||
checked, err := diagnostics.CheckOutput(selection)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
session := diagnostics.NewOutputSession(checked)
|
||||
if err := session.Prepare(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, errors.Join(err, session.Close())
|
||||
}
|
||||
if err := session.Initialize(ctx, initial, failed); err != nil {
|
||||
return nil, errors.Join(err, session.Close())
|
||||
}
|
||||
cancelOutput := func(err error) error { return session.Finish(ctx, err, nil, failed) }
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, cancelOutput(err)
|
||||
}
|
||||
result := &preparedOutput{Plan: plan, Output: session}
|
||||
if debug != nil {
|
||||
result.Debug, result.Warnings = diagnostics.PrepareDebug(debug.WorkDir, debug.RunID, debug.Metadata, debug.EffectiveConfig)
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, cancelOutput(err)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user