Avoid inheritance expansion during input presence capture
This commit is contained in:
@@ -25,20 +25,10 @@ type promptMessageConfig = settings.PromptMessageSettings
|
||||
type cacheControlConfig = settings.PromptCacheControlSettings
|
||||
type promptOutputConfig = settings.PromptOutputSettings
|
||||
|
||||
// fieldState distinguishes omission, an explicit value, and an explicit null.
|
||||
// Inherited values are explicit because ConfigKit has already expanded them.
|
||||
type fieldState uint8
|
||||
|
||||
const (
|
||||
fieldAbsent fieldState = iota
|
||||
fieldValue
|
||||
fieldNull
|
||||
)
|
||||
|
||||
type loaded struct {
|
||||
view configkit.Inspection
|
||||
diagnostics []configkit.Diagnostic
|
||||
promptMetadata map[string][]promptInputPresence
|
||||
promptRequired map[string][]bool
|
||||
prompts map[string]*promptEntry
|
||||
registry *backend.Registry
|
||||
backendRecords map[string]backendConfig
|
||||
@@ -168,19 +158,18 @@ func Validate(config *settings.Settings, validation *configkit.Validation) {
|
||||
// Capture builds owned runtime resources from effective settings and native evidence.
|
||||
func Capture(input *settings.Settings, view configkit.Inspection, diagnostics []configkit.Diagnostic) (*loaded, error) {
|
||||
config := ownSettings(input)
|
||||
state := &loaded{view: view, diagnostics: ownDiagnostics(diagnostics), promptMetadata: make(map[string][]promptInputPresence)}
|
||||
state := &loaded{view: view, diagnostics: ownDiagnostics(diagnostics), promptRequired: make(map[string][]bool)}
|
||||
metadata := view.Metadata()
|
||||
for _, resources := range resourceSets(&config) {
|
||||
for index, entry := range resources.prompts {
|
||||
presence := make([]promptInputPresence, len(entry.Inputs))
|
||||
presence := make([]bool, len(entry.Inputs))
|
||||
for i := range entry.Inputs {
|
||||
path := resources.bases.prompts.Index(index).Key("inputs").Index(i)
|
||||
presence[i] = promptInputPresence{required: finalFieldState(metadata, path.Key("required")), contentType: finalFieldState(metadata, path.Key("content_type")), description: finalFieldState(metadata, path.Key("description"))}
|
||||
if entry.Inputs[i].Required {
|
||||
presence[i].required = fieldValue
|
||||
}
|
||||
// Typed values capture defaults; explicitness preserves source false.
|
||||
// IsExplicit avoids projecting inheritance origins for a flag.
|
||||
presence[i] = entry.Inputs[i].Required || metadata.IsExplicit(path.Key("required"))
|
||||
}
|
||||
state.promptMetadata[indexedResourceID(resources.namespace, entry.ID)] = presence
|
||||
state.promptRequired[indexedResourceID(resources.namespace, entry.ID)] = presence
|
||||
}
|
||||
}
|
||||
if err := state.materializePrompts(&config, metadata); err != nil {
|
||||
@@ -208,17 +197,6 @@ func Capture(input *settings.Settings, view configkit.Inspection, diagnostics []
|
||||
return state, nil
|
||||
}
|
||||
|
||||
func finalFieldState(metadata configkit.Metadata, path configkit.Path) fieldState {
|
||||
info, exists := metadata.Lookup(path)
|
||||
if !exists || !info.Explicit {
|
||||
return fieldAbsent
|
||||
}
|
||||
if info.Null {
|
||||
return fieldNull
|
||||
}
|
||||
return fieldValue
|
||||
}
|
||||
|
||||
func ownDiagnostics(values []configkit.Diagnostic) []configkit.Diagnostic {
|
||||
if values == nil {
|
||||
return nil
|
||||
@@ -249,12 +227,6 @@ func promptNamespaces(prompts []domain.PromptIdentity) []string {
|
||||
return resourceNamespaces(ids)
|
||||
}
|
||||
|
||||
type promptInputPresence struct {
|
||||
required fieldState
|
||||
contentType fieldState
|
||||
description fieldState
|
||||
}
|
||||
|
||||
// eligibleResourceList leaves invalid identities to the existing validation
|
||||
// boundaries, without mutating a list that cannot be recorded by identity.
|
||||
func eligibleResourceList[T any](entries []T, identity func(T) string) bool {
|
||||
|
||||
@@ -78,10 +78,10 @@ func (state *loaded) InspectPrompt(ctx context.Context, id string) (*PromptResou
|
||||
result := &PromptResource{ID: id, Hash: entry.hash, DefaultProfile: raw.DefaultProfile, Description: raw.Description, SessionID: raw.SessionID}
|
||||
if raw.Inputs != nil {
|
||||
inputs := make([]PromptInputResource, len(raw.Inputs))
|
||||
presence := state.promptMetadata[id]
|
||||
presence := state.promptRequired[id]
|
||||
for i, input := range raw.Inputs {
|
||||
inputs[i] = PromptInputResource{Name: input.Name, ContentType: input.ContentType, Description: input.Description}
|
||||
if presence[i].required == fieldValue {
|
||||
if presence[i] {
|
||||
required := input.Required
|
||||
inputs[i].Required = &required
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user