Extend native catalog adapters

This commit is contained in:
2026-10-17 18:44:10 +00:00
parent c1fa18629d
commit dc4261a1ca
5 changed files with 182 additions and 49 deletions

View File

@@ -29,6 +29,28 @@ type ProfileRequest struct {
ID string
}
// CatalogRequest selects the configuration and native namespace filter for a
// prompt, profile, or backend catalog operation. A zero Filter preserves
// PromptKit's native default selection.
type CatalogRequest struct {
// Selection carries the configuration and overlay supplied to the command.
Selection ckconfig.Selection
// Filter is forwarded unchanged to each filterable native catalog. Its zero
// value preserves PromptKit's default namespace selection.
Filter promptkit.NamespaceFilter
}
// NamespaceRequest selects the configuration and native resource kinds for a
// namespace catalog operation. An empty Kinds slice preserves PromptKit's
// native default selection.
type NamespaceRequest struct {
// Selection carries the configuration and overlay supplied to the command.
Selection ckconfig.Selection
// Kinds is forwarded unchanged to the native namespace catalog. An empty
// slice preserves PromptKit's default kind selection.
Kinds []promptkit.ResourceKind
}
// RequirementsRequest selects a prompt context for native requirements
// inspection.
type RequirementsRequest struct {
@@ -81,11 +103,25 @@ type Suite[I, S any] struct {
// success; PromptKit errors are returned unchanged where supported.
ValidateRequest func(context.Context, ValidationRequest, I, S) (commandkit.Acquired[struct{}], error)
// ListPrompts lists prompt identities after input and state preparation.
// It is optional; a nil callback does not install a prompt catalog command.
ListPrompts func(context.Context, ckconfig.Selection, I, S) (commandkit.Acquired[[]promptkit.PromptIdentity], error)
// ListProfiles lists profile IDs after input and state preparation.
// It is optional; a nil callback does not install a profile catalog command.
ListProfiles func(context.Context, ckconfig.Selection, I, S) (commandkit.Acquired[[]string], error)
// It is optional independently of the other catalogs; nil omits only this
// catalog command.
ListPrompts func(context.Context, CatalogRequest, I, S) (commandkit.Acquired[[]promptkit.PromptIdentity], error)
// ListProfiles lists profile IDs after input and state preparation. It is
// optional independently of the other catalogs; nil omits only this catalog
// command.
ListProfiles func(context.Context, CatalogRequest, I, S) (commandkit.Acquired[[]string], error)
// ListBackends lists backend IDs after input and state preparation. It is
// optional independently of the other catalogs; nil omits only this catalog
// command.
ListBackends func(context.Context, CatalogRequest, I, S) (commandkit.Acquired[[]string], error)
// ListNamespaces lists native namespace names after input and state
// preparation. It is optional independently of the other catalogs; nil omits
// only this catalog command.
ListNamespaces func(context.Context, NamespaceRequest, I, S) (commandkit.Acquired[[]string], error)
// ListCollections lists collection information after input and state
// preparation. It is optional independently of the other catalogs; nil
// omits only this catalog command.
ListCollections func(context.Context, ckconfig.Selection, I, S) (commandkit.Acquired[[]promptkit.CollectionInfo], error)
issues []error
}
@@ -225,11 +261,13 @@ func promptKitContextError(ctx context.Context) error {
return ctx.Err()
}
// FromEngine supplies five PromptKit-backed callbacks: prompt and profile
// catalogs, named prompt and profile inspection, and requirements discovery.
// FromEngine supplies eight PromptKit-backed callbacks: prompt, profile,
// backend, namespace, and collection catalogs, plus named prompt and profile
// inspection and requirements discovery.
// The requirements callback forwards RequirementsRequest.Inspection to
// Engine.InspectRequirements. Concrete request validation is an independent
// capability and can be composed explicitly with WithRequestValidation.
// capability and can be composed explicitly with WithRequestValidation. Smoke
// testing is also an explicit capability installed by its helper.
// FromEngine does not call the loader during construction. Each selected
// operation passes its context, supplied selection, initialized input, and
// shared invocation state to the loader before calling PromptKit's public
@@ -242,22 +280,46 @@ func FromEngine[I, S any](load func(context.Context, ckconfig.Selection, I, S) (
}
return Suite[I, S]{
ListPrompts: func(ctx context.Context, selection ckconfig.Selection, input I, state S) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
engine, _, diagnostics, err := loadPromptKitEngine(ctx, selection, input, state, "", load)
ListPrompts: func(ctx context.Context, request CatalogRequest, input I, state S) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
engine, _, diagnostics, err := loadPromptKitEngine(ctx, request.Selection, input, state, "", load)
if err != nil {
return commandkit.Acquired[[]promptkit.PromptIdentity]{Diagnostics: diagnostics}, err
}
prompts, err := engine.ListPrompts(ctx)
prompts, err := engine.ListPrompts(ctx, request.Filter)
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: prompts, Diagnostics: diagnostics}, err
},
ListProfiles: func(ctx context.Context, selection ckconfig.Selection, input I, state S) (commandkit.Acquired[[]string], error) {
engine, _, diagnostics, err := loadPromptKitEngine(ctx, selection, input, state, "", load)
ListProfiles: func(ctx context.Context, request CatalogRequest, input I, state S) (commandkit.Acquired[[]string], error) {
engine, _, diagnostics, err := loadPromptKitEngine(ctx, request.Selection, input, state, "", load)
if err != nil {
return commandkit.Acquired[[]string]{Diagnostics: diagnostics}, err
}
profiles, err := engine.ListProfiles(ctx)
profiles, err := engine.ListProfiles(ctx, request.Filter)
return commandkit.Acquired[[]string]{Value: profiles, Diagnostics: diagnostics}, err
},
ListBackends: func(ctx context.Context, request CatalogRequest, input I, state S) (commandkit.Acquired[[]string], error) {
engine, _, diagnostics, err := loadPromptKitEngine(ctx, request.Selection, input, state, "", load)
if err != nil {
return commandkit.Acquired[[]string]{Diagnostics: diagnostics}, err
}
backends, err := engine.ListBackends(ctx, request.Filter)
return commandkit.Acquired[[]string]{Value: backends, Diagnostics: diagnostics}, err
},
ListNamespaces: func(ctx context.Context, request NamespaceRequest, input I, state S) (commandkit.Acquired[[]string], error) {
engine, _, diagnostics, err := loadPromptKitEngine(ctx, request.Selection, input, state, "", load)
if err != nil {
return commandkit.Acquired[[]string]{Diagnostics: diagnostics}, err
}
namespaces, err := engine.ListNamespaces(ctx, request.Kinds...)
return commandkit.Acquired[[]string]{Value: namespaces, Diagnostics: diagnostics}, err
},
ListCollections: func(ctx context.Context, selection ckconfig.Selection, input I, state S) (commandkit.Acquired[[]promptkit.CollectionInfo], error) {
engine, _, diagnostics, err := loadPromptKitEngine(ctx, selection, input, state, "", load)
if err != nil {
return commandkit.Acquired[[]promptkit.CollectionInfo]{Diagnostics: diagnostics}, err
}
collections, err := engine.ListCollections(ctx)
return commandkit.Acquired[[]promptkit.CollectionInfo]{Value: collections, Diagnostics: diagnostics}, err
},
InspectPrompt: func(ctx context.Context, request PromptRequest, input I, state S) (commandkit.Acquired[*promptkit.PromptInspection], error) {
engine, _, diagnostics, err := loadPromptKitEngine(ctx, request.Selection, input, state, "", load)
if err != nil {