Separate readiness checks from report presentation
This commit is contained in:
@@ -91,47 +91,12 @@ func inspectConfiguredSessionReadiness(ctx context.Context, cfg *config.Config,
|
||||
}
|
||||
|
||||
func assessSessionReadiness(runtime *invocationRuntime, report *sessionReadinessReport, deps commandDependencies) error {
|
||||
prepareErr := executeSelectedStages(runtime)
|
||||
prepared := false
|
||||
if len(runtime.stageResults) > 0 {
|
||||
item := runtime.stageResults[0]
|
||||
report.Preparation = preparationAssessment{Outcome: item.Outcome, Reason: item.Reason}
|
||||
prepared = prepareErr == nil && (item.Outcome == "completed" || item.Outcome == "reused")
|
||||
}
|
||||
if !prepared && prepareErr == nil {
|
||||
prepareErr = fmt.Errorf("preparation did not produce reusable input evidence")
|
||||
report.Preparation.Outcome = "failed"
|
||||
report.Preparation.Reason = prepareErr.Error()
|
||||
}
|
||||
if prepareErr != nil {
|
||||
report.Findings = append(report.Findings, errorFinding("preparation", prepareErr.Error()))
|
||||
}
|
||||
outcome, message := "succeeded", ""
|
||||
if !prepared {
|
||||
outcome = "failed"
|
||||
if prepareErr != nil {
|
||||
message = prepareErr.Error()
|
||||
}
|
||||
}
|
||||
report.Checks = append(report.Checks, readinessCheck{Group: "preparation", Outcome: outcome, Message: message})
|
||||
if prepared {
|
||||
message := "prepared session inputs and audio are current"
|
||||
if record := runtime.manifest.Stages["prepare"]; record != nil && record.Metadata["audio_prepared"] == false {
|
||||
message = "prepared session references are current"
|
||||
}
|
||||
report.Findings = append(report.Findings, okFinding("inputs", message))
|
||||
if record := runtime.manifest.Stages["prepare"]; record != nil {
|
||||
if hydrated := previousArtifactNames(record.Metadata["previous_artifacts_hydrated"]); len(hydrated) > 0 {
|
||||
report.Findings = append(report.Findings, okFinding("previous", fmt.Sprintf("prepared previous artifacts: %v", hydrated)))
|
||||
}
|
||||
if missing := previousArtifactNames(record.Metadata["previous_artifacts_missing_optional"]); len(missing) > 0 {
|
||||
report.Findings = append(report.Findings, infoFinding("previous", fmt.Sprintf("optional previous artifacts unavailable: %v", missing)))
|
||||
}
|
||||
if _, required := record.Metadata["previous_requirements_count"]; !required {
|
||||
report.Findings = append(report.Findings, infoFinding("previous", "no previous-session artifacts required"))
|
||||
}
|
||||
}
|
||||
}
|
||||
preparation := assessPreparation(runtime, executeSelectedStages(runtime))
|
||||
report.Preparation = preparation.preparation
|
||||
report.Findings = append(report.Findings, preparation.findings...)
|
||||
report.Checks = append(report.Checks, preparation.check)
|
||||
prepared, prepareErr := preparation.prepared, preparation.err
|
||||
|
||||
var failures []error
|
||||
failures = append(failures, prepareErr)
|
||||
if runtime.ctx.Err() != nil {
|
||||
@@ -143,45 +108,14 @@ func assessSessionReadiness(runtime *invocationRuntime, report *sessionReadiness
|
||||
report.Checks = append(report.Checks, readinessCheck{Group: "prompt requirements", Outcome: "failed", Message: err.Error()})
|
||||
report.Findings = append(report.Findings, errorFinding("preflight", err.Error()))
|
||||
} else {
|
||||
useCurrent := false
|
||||
if prepared && targets.Notarius {
|
||||
plan, planErr := BuildBoundedPlan("transcribe", "trim")
|
||||
if planErr == nil {
|
||||
var projection *workProjection
|
||||
projection, planErr = projectSelectedWork(runtime.ctx, runtime.cfg, plan, false, nil, runtime.effectiveArtifacts, runtime.artifactStore, runtime.env.ObjectStore, runtime.manifest)
|
||||
if planErr == nil {
|
||||
useCurrent = currentTranscriptUsableForNotarius(projection)
|
||||
}
|
||||
}
|
||||
if planErr != nil {
|
||||
failures = append(failures, fmt.Errorf("project transcript readiness: %w", planErr))
|
||||
report.Findings = append(report.Findings, errorFinding("notarius", planErr.Error()))
|
||||
}
|
||||
useCurrent, planErr := projectNotariusTranscriptReadiness(runtime, prepared && targets.Notarius)
|
||||
if planErr != nil {
|
||||
failures = append(failures, fmt.Errorf("project transcript readiness: %w", planErr))
|
||||
report.Findings = append(report.Findings, errorFinding("notarius", planErr.Error()))
|
||||
}
|
||||
checked, checkErr := checkDownstreamReadiness(runtime, targets, prepared, useCurrent, false)
|
||||
report.Checks = append(report.Checks, checked.Checks...)
|
||||
projectDownstreamReadiness(report, checked)
|
||||
failures = append(failures, checkErr)
|
||||
for _, check := range checked.Checks {
|
||||
if check.Outcome == "failed" && check.Message != "" {
|
||||
report.Findings = append(report.Findings, errorFinding(check.Group, check.Message))
|
||||
}
|
||||
}
|
||||
for _, item := range checked.Findings {
|
||||
category, text := "scriptorium", formatPromptFinding(item)
|
||||
if item.Stage == "polish" {
|
||||
category, text = "audita", item.Message
|
||||
} else if item.Stage == "extract" {
|
||||
category, text = "notarius", item.Message
|
||||
}
|
||||
switch item.Severity {
|
||||
case preflight.SeverityError:
|
||||
report.Findings = append(report.Findings, errorFinding(category, text))
|
||||
case preflight.SeverityWarning:
|
||||
report.Findings = append(report.Findings, warnFinding(category, text))
|
||||
default:
|
||||
report.Findings = append(report.Findings, infoFinding(category, text))
|
||||
}
|
||||
}
|
||||
}
|
||||
if runtime.ctx.Err() == nil {
|
||||
store := runtime.env.ObjectStore
|
||||
@@ -211,6 +145,101 @@ func assessSessionReadiness(runtime *invocationRuntime, report *sessionReadiness
|
||||
return errors.Join(append(failures, runtime.ctx.Err())...)
|
||||
}
|
||||
|
||||
func projectNotariusTranscriptReadiness(runtime *invocationRuntime, needed bool) (bool, error) {
|
||||
if !needed {
|
||||
return false, nil
|
||||
}
|
||||
plan, err := BuildBoundedPlan("transcribe", "trim")
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
projection, err := projectSelectedWork(runtime.ctx, runtime.cfg, plan, false, nil, runtime.effectiveArtifacts, runtime.artifactStore, runtime.env.ObjectStore, runtime.manifest)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return currentTranscriptUsableForNotarius(projection), nil
|
||||
}
|
||||
|
||||
func projectDownstreamReadiness(report *sessionReadinessReport, checked downstreamReadiness) {
|
||||
report.Checks = append(report.Checks, checked.Checks...)
|
||||
for _, check := range checked.Checks {
|
||||
if check.Outcome == "failed" && check.Message != "" {
|
||||
report.Findings = append(report.Findings, errorFinding(check.Group, check.Message))
|
||||
}
|
||||
}
|
||||
for _, item := range checked.Findings {
|
||||
category, text := "scriptorium", formatPromptFinding(item)
|
||||
if item.Stage == "polish" {
|
||||
category, text = "audita", item.Message
|
||||
} else if item.Stage == "extract" {
|
||||
category, text = "notarius", item.Message
|
||||
}
|
||||
switch item.Severity {
|
||||
case preflight.SeverityError:
|
||||
report.Findings = append(report.Findings, errorFinding(category, text))
|
||||
case preflight.SeverityWarning:
|
||||
report.Findings = append(report.Findings, warnFinding(category, text))
|
||||
default:
|
||||
report.Findings = append(report.Findings, infoFinding(category, text))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type preparationReadiness struct {
|
||||
preparation preparationAssessment
|
||||
prepared bool
|
||||
check readinessCheck
|
||||
findings []finding
|
||||
err error
|
||||
}
|
||||
|
||||
func assessPreparation(runtime *invocationRuntime, executionErr error) preparationReadiness {
|
||||
assessment := preparationReadiness{preparation: preparationAssessment{Outcome: "not_attempted"}}
|
||||
prepareErr := executionErr
|
||||
prepared := false
|
||||
if len(runtime.stageResults) > 0 {
|
||||
item := runtime.stageResults[0]
|
||||
assessment.preparation = preparationAssessment{Outcome: item.Outcome, Reason: item.Reason}
|
||||
prepared = prepareErr == nil && (item.Outcome == "completed" || item.Outcome == "reused")
|
||||
}
|
||||
if !prepared && prepareErr == nil {
|
||||
prepareErr = fmt.Errorf("preparation did not produce reusable input evidence")
|
||||
assessment.preparation.Outcome = "failed"
|
||||
assessment.preparation.Reason = prepareErr.Error()
|
||||
}
|
||||
if prepareErr != nil {
|
||||
assessment.findings = append(assessment.findings, errorFinding("preparation", prepareErr.Error()))
|
||||
}
|
||||
outcome, message := "succeeded", ""
|
||||
if !prepared {
|
||||
outcome = "failed"
|
||||
if prepareErr != nil {
|
||||
message = prepareErr.Error()
|
||||
}
|
||||
}
|
||||
assessment.check = readinessCheck{Group: "preparation", Outcome: outcome, Message: message}
|
||||
if prepared {
|
||||
message := "prepared session inputs and audio are current"
|
||||
if record := runtime.manifest.Stages["prepare"]; record != nil && record.Metadata["audio_prepared"] == false {
|
||||
message = "prepared session references are current"
|
||||
}
|
||||
assessment.findings = append(assessment.findings, okFinding("inputs", message))
|
||||
if record := runtime.manifest.Stages["prepare"]; record != nil {
|
||||
if hydrated := previousArtifactNames(record.Metadata["previous_artifacts_hydrated"]); len(hydrated) > 0 {
|
||||
assessment.findings = append(assessment.findings, okFinding("previous", fmt.Sprintf("prepared previous artifacts: %v", hydrated)))
|
||||
}
|
||||
if missing := previousArtifactNames(record.Metadata["previous_artifacts_missing_optional"]); len(missing) > 0 {
|
||||
assessment.findings = append(assessment.findings, infoFinding("previous", fmt.Sprintf("optional previous artifacts unavailable: %v", missing)))
|
||||
}
|
||||
if _, required := record.Metadata["previous_requirements_count"]; !required {
|
||||
assessment.findings = append(assessment.findings, infoFinding("previous", "no previous-session artifacts required"))
|
||||
}
|
||||
}
|
||||
}
|
||||
assessment.prepared, assessment.err = prepared, prepareErr
|
||||
return assessment
|
||||
}
|
||||
|
||||
func previousArtifactNames(value any) []string {
|
||||
switch items := value.(type) {
|
||||
case []string:
|
||||
|
||||
Reference in New Issue
Block a user