Prepare scene extraction and deterministic normalization in core
This commit is contained in:
@@ -77,6 +77,9 @@ type NativeOperation[T any] struct {
|
||||
Correction CorrectionBuilder
|
||||
Fallback Fallback[T]
|
||||
Diagnostics TerminalDiagnostics[T]
|
||||
// Reuse checks and, when needed, adapts a decoded accepted value to this
|
||||
// operation's current domain inputs. An error makes the cache entry unusable.
|
||||
Reuse func(T) (T, error)
|
||||
// Evidence is optional, lazy preparation evidence for this operation.
|
||||
Evidence func() (any, error)
|
||||
}
|
||||
|
||||
@@ -100,6 +100,18 @@ func executeNative[T any](ctx context.Context, execution ExecutionContext[T], op
|
||||
var err error
|
||||
var cacheKey string
|
||||
cache := execution.Cache
|
||||
if cache != nil && cache.Decode != nil && operation.Reuse != nil {
|
||||
copy := *cache
|
||||
decode := cache.Decode
|
||||
copy.Decode = func(content []byte) (T, error) {
|
||||
value, err := decode(content)
|
||||
if err != nil {
|
||||
return value, err
|
||||
}
|
||||
return operation.Reuse(value)
|
||||
}
|
||||
cache = ©
|
||||
}
|
||||
if execution.Execution.Capture != nil {
|
||||
if err := execution.Execution.RecordEvidence("cache/selection.json", map[string]any{"mode": execution.Controls.Cache, "reuse_eligible": execution.ReuseEligible, "store_available": cache != nil && cache.Store != nil}); err != nil {
|
||||
return empty, captureFailure(err, capture.Finish(nil, err, false, false))
|
||||
|
||||
Reference in New Issue
Block a user