2026-09-26 18:00:50 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2026-11-17 22:00:43 +00:00
|
|
|
"go.maximumdirect.net/configkit"
|
2026-11-23 03:25:05 +00:00
|
|
|
"go.maximumdirect.net/promptkit"
|
2026-09-26 18:00:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// LoadOptions selects one application source and explicit configuration values.
|
|
|
|
|
type LoadOptions struct {
|
|
|
|
|
Path string
|
|
|
|
|
Explicit bool
|
|
|
|
|
Overlay string
|
|
|
|
|
Overrides []configkit.Override
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-20 04:26:17 +00:00
|
|
|
var applicationSearch = configkit.Searches(
|
|
|
|
|
configkit.WorkingDirectory(), configkit.UserConfigDirectory(),
|
|
|
|
|
configkit.HomeDirectory(), configkit.UnixSystemDirectories(),
|
|
|
|
|
)
|
|
|
|
|
|
2026-09-26 18:08:36 +00:00
|
|
|
// Load resolves one ConfigKit document and retains its inspection snapshot.
|
2026-11-23 03:25:05 +00:00
|
|
|
func Load(options LoadOptions) (*configkit.Result[Document], *configkit.SecretsReport, error) {
|
2026-09-26 18:00:50 +00:00
|
|
|
var source configkit.Source
|
|
|
|
|
if options.Explicit {
|
|
|
|
|
source = configkit.File(options.Path)
|
|
|
|
|
} else {
|
2026-11-20 04:26:17 +00:00
|
|
|
source = configkit.SearchConfig("scriptorium", applicationSearch)
|
2026-09-26 18:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
2026-11-23 03:25:05 +00:00
|
|
|
report, captured, err := configkit.LoadSecretsIntoEnvironmentFromConfig(source)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, report, fmt.Errorf("bootstrap application secrets: %w", err)
|
|
|
|
|
}
|
|
|
|
|
result, err := configkit.LoadLayered(configkit.Input{Source: captured, Imports: true}, configkit.LayeredOptions[Document]{
|
2026-09-26 18:00:50 +00:00
|
|
|
Definition: documentDefinition(),
|
2026-11-23 03:25:05 +00:00
|
|
|
Underlays: []configkit.Underlay{promptkit.BundledOpenRouterUnderlay()},
|
2026-09-26 18:12:27 +00:00
|
|
|
Overlay: options.Overlay,
|
2026-09-26 18:00:50 +00:00
|
|
|
Overrides: options.Overrides,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
2026-11-23 03:25:05 +00:00
|
|
|
return nil, report, fmt.Errorf("load application configuration: %w", err)
|
2026-09-26 18:00:50 +00:00
|
|
|
}
|
2026-11-23 03:25:05 +00:00
|
|
|
return result, report, nil
|
2026-09-26 18:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Settings converts a validated document without another merge or normalization.
|
|
|
|
|
func Settings(document Document) AppSettings {
|
|
|
|
|
settings := AppSettings{
|
2026-11-23 03:25:05 +00:00
|
|
|
ServerAddr: document.Server.Addr,
|
|
|
|
|
ArtifactRoot: document.Server.ArtifactRoot,
|
|
|
|
|
MaxRequestBytes: document.Server.MaxRequestBytes,
|
|
|
|
|
MaxArtifactBytes: document.Server.MaxArtifactBytes,
|
|
|
|
|
MaxResponseBytes: document.Server.MaxResponseBytes,
|
|
|
|
|
TransientRetries: document.TransientRetries,
|
2026-09-26 18:00:50 +00:00
|
|
|
}
|
|
|
|
|
return settings
|
|
|
|
|
}
|