All checks were successful
ci/woodpecker/tag/release Pipeline was successful
73 lines
2.7 KiB
Go
73 lines
2.7 KiB
Go
package artifacts
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/v4/internal/fileops"
|
|
"gitea.maximumdirect.net/eric/narratio/v4/internal/manifest"
|
|
)
|
|
|
|
const extractionMetadataInput = "direct_input"
|
|
|
|
// ExtractionInputIdentity identifies the exact trimmed transcript used for extraction.
|
|
type ExtractionInputIdentity struct {
|
|
Path string `json:"-"`
|
|
Checksum string `json:"checksum"`
|
|
SourceID string `json:"source_id"`
|
|
ProducerStage string `json:"producer_stage"`
|
|
OutputKind string `json:"output_kind"`
|
|
ProducerRunID string `json:"producer_run_id"`
|
|
Provenance string `json:"provenance"`
|
|
}
|
|
|
|
// ResolveExtractionInputIdentity resolves and hashes the direct transcript input.
|
|
func ResolveExtractionInputIdentity(paths SessionPaths, m *manifest.Manifest) (ExtractionInputIdentity, error) {
|
|
resolved, err := ResolveSessionArtifact(paths, m, ArtifactTranscriptFinalTrimmed)
|
|
if err != nil {
|
|
return ExtractionInputIdentity{}, err
|
|
}
|
|
path, err := filepath.Abs(resolved.Path)
|
|
if err != nil {
|
|
return ExtractionInputIdentity{}, fmt.Errorf("resolve trimmed transcript path: %w", err)
|
|
}
|
|
bytes, err := fileops.ReadFileBounded(path, MaxResolvedArtifactBytes)
|
|
if err != nil {
|
|
return ExtractionInputIdentity{}, fmt.Errorf("read trimmed transcript: %w", err)
|
|
}
|
|
digest := sha256.Sum256(bytes)
|
|
return ExtractionInputIdentity{
|
|
Path: filepath.Clean(path),
|
|
Checksum: hex.EncodeToString(digest[:]),
|
|
SourceID: resolved.ID,
|
|
ProducerStage: resolved.ProducerStage,
|
|
OutputKind: resolved.OutputKind,
|
|
ProducerRunID: resolved.ProducerRunID,
|
|
Provenance: resolved.Provenance,
|
|
}, nil
|
|
}
|
|
|
|
// Metadata returns the durable fields needed to compare this identity on reuse.
|
|
func (identity ExtractionInputIdentity) Metadata() map[string]any {
|
|
return map[string]any{
|
|
"checksum": identity.Checksum,
|
|
"source_id": identity.SourceID,
|
|
"producer_stage": identity.ProducerStage,
|
|
"output_kind": identity.OutputKind,
|
|
"producer_run_id": identity.ProducerRunID,
|
|
"provenance": identity.Provenance,
|
|
}
|
|
}
|
|
|
|
func extractionInputMatchesMetadata(metadata map[string]any, current ExtractionInputIdentity) bool {
|
|
decoded := DecodeExtractionMetadata(metadata)
|
|
if !decoded.InputPresent || strings.TrimSpace(current.Checksum) == "" || strings.TrimSpace(current.SourceID) == "" {
|
|
return false
|
|
}
|
|
stored := decoded.Input
|
|
return stored.Checksum == current.Checksum && stored.SourceID == current.SourceID && stored.ProducerStage == current.ProducerStage && stored.OutputKind == current.OutputKind && stored.ProducerRunID == current.ProducerRunID && stored.Provenance == current.Provenance
|
|
}
|