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 } // Diff compares this view's captured effective configuration with other. This // view is the earlier (left) value and other is the later (right) value. The // comparison delegates to ConfigKit's frozen effective-value semantics, so // source or resolution history alone does not create differences. It does not // reread external sources or compare referenced file contents, resolved // credential contents, later execution preparation, or request-specific // overrides. Either zero view returns ErrInvalidConfig and no records; other // ConfigKit errors are returned unchanged. An empty diff is not evidence of // equivalent engine behavior or execution. Records can contain ordinary // application data, so callers choose where and to whom to disclose them. func (v ConfigurationInspection) Diff(other ConfigurationInspection) ([]configkit.Difference, error) { if v.source == nil || other.source == nil { return nil, ErrInvalidConfig } return configuration.Diff(v.source, other.source) } // 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) }