Use prepared glossaries for transcript polishing
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
)
|
||||
|
||||
@@ -57,33 +58,25 @@ func (polishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*St
|
||||
return nil, fmt.Errorf("polish: merged transcript %q invalid: %w", mergedPath, err)
|
||||
}
|
||||
|
||||
glossaryPath := filepath.Join(paths.InputsDir, "glossary.yml")
|
||||
if err := requireFile(glossaryPath, "glossary.yml"); err != nil {
|
||||
return nil, fmt.Errorf("polish: %w", err)
|
||||
}
|
||||
|
||||
canonicalProcessedPath := filepath.Join(paths.TranscriptsDir, "polished.json")
|
||||
processedPath, err := runLocalPathForCanonical(runLayout, paths, canonicalProcessedPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("polish: resolve run-local processed transcript path: %w", err)
|
||||
return nil, fmt.Errorf("polish: resolve output: %w", err)
|
||||
}
|
||||
stdoutPath := filepath.Join(paths.LogsDir, "audita.stdout.log")
|
||||
stderrPath := filepath.Join(paths.LogsDir, "audita.stderr.log")
|
||||
generatedConfigPath := filepath.Join(paths.ConfigDir, "audita.generated.yml")
|
||||
if !runLayout.Enabled {
|
||||
processedPath = filepath.Join(paths.Root, "scratch", "polish", "polished.json")
|
||||
}
|
||||
logs := paths.LogsDir
|
||||
debug := filepath.Join(paths.Root, "debug", "polish")
|
||||
if runLayout.Enabled {
|
||||
stdoutPath = filepath.Join(runLayout.LogsDir, "audita.stdout.log")
|
||||
stderrPath = filepath.Join(runLayout.LogsDir, "audita.stderr.log")
|
||||
generatedConfigPath = filepath.Join(runLayout.ConfigDir, "audita.generated.yml")
|
||||
logs = runLayout.LogsDir
|
||||
debug = filepath.Join(runLayout.Root, "debug")
|
||||
}
|
||||
|
||||
req := audita.PolishRequest{
|
||||
GeneratedConfigPath: generatedConfigPath,
|
||||
MergedTranscriptPath: mergedPath,
|
||||
OutputProcessedPath: processedPath,
|
||||
GlossaryFiles: []string{glossaryPath},
|
||||
StdoutLogPath: stdoutPath,
|
||||
StderrLogPath: stderrPath,
|
||||
req, evidence, err := BuildPolishRequest(paths, m, mergedPath, processedPath, logs, debug)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("polish: %w", err)
|
||||
}
|
||||
stdoutPath, stderrPath, generatedConfigPath := req.StdoutLogPath, req.StderrLogPath, req.GeneratedConfigPath
|
||||
|
||||
res, err := env.Audita.Run(ctx, req)
|
||||
if err != nil {
|
||||
@@ -91,6 +84,9 @@ func (polishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*St
|
||||
filepath.Dir(processedPath), stdoutPath, stderrPath, err)
|
||||
}
|
||||
|
||||
if res.ExitCode != 0 {
|
||||
return nil, fmt.Errorf("polish: audita exited with status %d", res.ExitCode)
|
||||
}
|
||||
finalProcessedPath, err := authoritativeOutputPath(processedPath, res.ProcessedTranscriptPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("polish: %w", err)
|
||||
@@ -108,7 +104,7 @@ func (polishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*St
|
||||
if report.returned == "" {
|
||||
continue
|
||||
}
|
||||
expected := filepath.Join(filepath.Dir(processedPath), report.name)
|
||||
expected := filepath.Join(req.ReportDir, report.name)
|
||||
path, err := authoritativeOutputPath(expected, report.returned)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("polish: report %s: %w", report.name, err)
|
||||
@@ -116,6 +112,9 @@ func (polishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*St
|
||||
if err := requireRegularReadableFile(path, "audita report"); err != nil {
|
||||
return nil, fmt.Errorf("polish: %w", err)
|
||||
}
|
||||
if _, err := fileops.ReadFileBounded(path, audita.MaxReportOutputBytes); err != nil {
|
||||
return nil, fmt.Errorf("polish: read audita report %q: %w", path, err)
|
||||
}
|
||||
reportPaths = append(reportPaths, path)
|
||||
reportMetadata[report.name] = path
|
||||
}
|
||||
@@ -133,7 +132,8 @@ func (polishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*St
|
||||
"stage": "polish",
|
||||
"merged_transcript_path": mergedPath,
|
||||
"merged_transcript_source": source,
|
||||
"glossary_path": glossaryPath,
|
||||
"glossary_files": req.GlossaryFiles,
|
||||
"glossary_evidence": evidence,
|
||||
"run_output_path": finalProcessedPath,
|
||||
"output_path": canonicalProcessedPath,
|
||||
"overlay": env.Config.Pipeline.Audita.Overlay,
|
||||
|
||||
Reference in New Issue
Block a user