83 lines
2.7 KiB
Go
83 lines
2.7 KiB
Go
package promptkit
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
|
|
"gitea.maximumdirect.net/eric/ConfigKit"
|
|
"gitea.maximumdirect.net/eric/promptkit/internal/configuration"
|
|
)
|
|
|
|
// ConfigurationInspection is a read-only view of one Engine's captured
|
|
// effective configuration and source history. It does not expose typed
|
|
// configuration values, filesystem contexts, or runtime credentials.
|
|
// Report content may include application prompt and provider data, so callers
|
|
// choose where and to whom to disclose it.
|
|
type ConfigurationInspection struct {
|
|
source configuration.Inspection
|
|
}
|
|
|
|
// InspectConfiguration returns the ConfigKit inspection view captured by this
|
|
// Engine. It does not reload sources, resolve credentials, or contact a model.
|
|
// A nil Engine returns ErrInvalidConfig.
|
|
func (e *Engine) InspectConfiguration() (ConfigurationInspection, error) {
|
|
if e == nil || e.internal == nil {
|
|
return ConfigurationInspection{}, fmt.Errorf("%w: engine is nil", ErrInvalidConfig)
|
|
}
|
|
return ConfigurationInspection{source: e.internal.InspectConfiguration()}, nil
|
|
}
|
|
|
|
// Metadata returns detached effective presence and history records.
|
|
func (v ConfigurationInspection) Metadata() configkit.Metadata {
|
|
if v.source == nil {
|
|
return configkit.Metadata{}
|
|
}
|
|
return v.source.Metadata()
|
|
}
|
|
|
|
// Sources returns a detached list of loaded source descriptions.
|
|
func (v ConfigurationInspection) Sources() []configkit.SourceInfo {
|
|
if v.source == nil {
|
|
return nil
|
|
}
|
|
return v.source.Sources()
|
|
}
|
|
|
|
// Diagnostics returns detached nonfatal load diagnostics.
|
|
func (v ConfigurationInspection) Diagnostics() []configkit.Diagnostic {
|
|
if v.source == nil {
|
|
return nil
|
|
}
|
|
return v.source.Diagnostics()
|
|
}
|
|
|
|
// Explain returns detached effective and historical values for a known path.
|
|
// Dynamic credential-shaped provider keys are redacted by ConfigKit; ordinary
|
|
// prompt and provider content is not automatically safe to disclose.
|
|
func (v ConfigurationInspection) Explain(path configkit.Path) (configkit.Explanation, bool) {
|
|
if v.source == nil {
|
|
return configkit.Explanation{}, false
|
|
}
|
|
return v.source.Explain(path)
|
|
}
|
|
|
|
// WriteEffective writes ConfigKit's redacted effective YAML. Writer errors
|
|
// remain available through errors.Is and errors.As. The zero view returns
|
|
// ErrInvalidConfig.
|
|
func (v ConfigurationInspection) WriteEffective(w io.Writer) error {
|
|
if v.source == nil {
|
|
return ErrInvalidConfig
|
|
}
|
|
return v.source.WriteEffective(w)
|
|
}
|
|
|
|
// WriteExplanation writes ConfigKit's redacted history for path. Unknown paths
|
|
// produce no output; writer errors remain inspectable. The zero view returns
|
|
// ErrInvalidConfig.
|
|
func (v ConfigurationInspection) WriteExplanation(w io.Writer, path configkit.Path) error {
|
|
if v.source == nil {
|
|
return ErrInvalidConfig
|
|
}
|
|
return v.source.WriteExplanation(w, path)
|
|
}
|