2026-11-10 17:18:30 +00:00
|
|
|
package config
|
|
|
|
|
|
2026-11-10 20:39:00 +00:00
|
|
|
import (
|
|
|
|
|
"slices"
|
|
|
|
|
|
|
|
|
|
ck "go.maximumdirect.net/configkit"
|
|
|
|
|
)
|
2026-11-10 17:18:30 +00:00
|
|
|
|
|
|
|
|
func cloneSelection(value *string) *string {
|
|
|
|
|
if value == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
copied := *value
|
|
|
|
|
return &copied
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-10 20:39:00 +00:00
|
|
|
func defaultNames(r *ck.Resolution, path ck.Path, target *[]string, inherited []string, reason string, source ck.Path) {
|
|
|
|
|
if !r.IsExplicit(path) {
|
|
|
|
|
ck.Default(r, path, target, slices.Clone(inherited), reason, source)
|
2026-11-10 17:18:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-16 14:18:38 +00:00
|
|
|
// resolveRoleProfile inherits only an explicitly selected root role. An
|
|
|
|
|
// explicit null clears inheritance and derives the role from its own proposal.
|
|
|
|
|
func resolveRoleProfile(r *ck.Resolution, role, proposal ck.Path, target **string, proposalValue *string, name string, inheritedPath ck.Path, inherited *string) {
|
|
|
|
|
info, _ := r.EntryInfo(role)
|
|
|
|
|
reason := name + " defaults to proposal profile"
|
|
|
|
|
if r.IsExplicit(role) && info.Null {
|
|
|
|
|
*target = cloneSelection(proposalValue)
|
|
|
|
|
r.RecordDerivedDefault(role, reason, proposal)
|
|
|
|
|
} else if inherited != nil {
|
|
|
|
|
ck.Default(r, role, target, cloneSelection(inherited), "inherit "+name+" profile", inheritedPath)
|
|
|
|
|
} else {
|
|
|
|
|
ck.Default(r, role, target, cloneSelection(proposalValue), reason, proposal)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func explicitProfile(r *ck.Resolution, path ck.Path, value *string) *string {
|
|
|
|
|
info, _ := r.EntryInfo(path)
|
|
|
|
|
if r.IsExplicit(path) && !info.Null {
|
|
|
|
|
return value
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-10 17:18:30 +00:00
|
|
|
// resolveSettings records root-derived defaults after all explicit assignments.
|
|
|
|
|
func resolveSettings(c *Config, r *ck.Resolution) error {
|
|
|
|
|
glossaries := ck.Keys("glossaries")
|
|
|
|
|
protection := ck.Keys("protected_terms")
|
2026-11-10 20:39:00 +00:00
|
|
|
defaultNames(r, protection, &c.ProtectedTerms, c.Glossaries, "protection defaults to selected glossaries", glossaries)
|
2026-11-16 14:18:38 +00:00
|
|
|
rootLLM := ck.Keys("llm")
|
|
|
|
|
rootProposal := rootLLM.Key("proposal_profile")
|
|
|
|
|
rootValidation := rootLLM.Key("validation_profile")
|
|
|
|
|
rootRepair := rootLLM.Key("correction_repair_profile")
|
|
|
|
|
inheritedValidation := explicitProfile(r, rootValidation, c.LLM.ValidationProfile)
|
|
|
|
|
inheritedRepair := explicitProfile(r, rootRepair, c.LLM.CorrectionRepairProfile)
|
2026-11-10 17:18:30 +00:00
|
|
|
for i := range c.Pipeline.Stages {
|
|
|
|
|
item := &c.Pipeline.Stages[i]
|
|
|
|
|
base := ck.Keys("pipeline", "stages").Index(i)
|
2026-11-10 20:39:00 +00:00
|
|
|
defaultNames(r, base.Key("glossaries"), &item.Glossaries, c.Glossaries, "inherit root glossaries", glossaries)
|
|
|
|
|
defaultNames(r, base.Key("protected_terms"), &item.ProtectedTerms, c.ProtectedTerms, "inherit root protection", protection)
|
2026-11-10 17:18:30 +00:00
|
|
|
llm := base.Key("llm")
|
|
|
|
|
proposal := llm.Key("proposal_profile")
|
|
|
|
|
ck.Default(r, proposal, &item.LLM.ProposalProfile, cloneSelection(c.LLM.ProposalProfile), "inherit proposal profile", rootLLM.Key("proposal_profile"))
|
|
|
|
|
ck.Default(r, llm.Key("transient_retries"), &item.LLM.TransientRetries, c.LLM.TransientRetries, "inherit retry budget", rootLLM.Key("transient_retries"))
|
|
|
|
|
ck.Default(r, llm.Key("repair_attempts"), &item.LLM.RepairAttempts, c.LLM.RepairAttempts, "inherit repair budget", rootLLM.Key("repair_attempts"))
|
2026-11-11 04:20:23 +00:00
|
|
|
ck.Default(r, llm.Key("correction_repair_attempts"), &item.LLM.CorrectionRepairAttempts, c.LLM.CorrectionRepairAttempts, "inherit correction repair budget", rootLLM.Key("correction_repair_attempts"))
|
2026-11-10 17:18:30 +00:00
|
|
|
ck.Default(r, llm.Key("operation_timeout"), &item.LLM.OperationTimeout, c.LLM.OperationTimeout, "inherit operation timeout", rootLLM.Key("operation_timeout"))
|
|
|
|
|
ck.Default(r, base.Key("validation").Key("max_prompt_tokens"), &item.Validation.MaxPromptTokens, c.Validation.MaxPromptTokens, "inherit validation budget", ck.Keys("validation", "max_prompt_tokens"))
|
|
|
|
|
ck.Default(r, base.Key("context").Key("description"), &item.Context.Description, c.Context.Description, "inherit description", ck.Keys("context", "description"))
|
2026-11-16 14:18:38 +00:00
|
|
|
resolveRoleProfile(r, llm.Key("correction_repair_profile"), proposal, &item.LLM.CorrectionRepairProfile, item.LLM.ProposalProfile, "correction repair", rootRepair, inheritedRepair)
|
|
|
|
|
resolveRoleProfile(r, llm.Key("validation_profile"), proposal, &item.LLM.ValidationProfile, item.LLM.ProposalProfile, "validation", rootValidation, inheritedValidation)
|
2026-11-10 17:18:30 +00:00
|
|
|
}
|
2026-11-16 14:18:38 +00:00
|
|
|
resolveRoleProfile(r, rootRepair, rootProposal, &c.LLM.CorrectionRepairProfile, c.LLM.ProposalProfile, "correction repair", rootRepair, nil)
|
|
|
|
|
resolveRoleProfile(r, rootValidation, rootProposal, &c.LLM.ValidationProfile, c.LLM.ProposalProfile, "validation", rootValidation, nil)
|
2026-11-10 17:18:30 +00:00
|
|
|
return nil
|
|
|
|
|
}
|