Add PromptKit requirements adapter
This commit is contained in:
@@ -31,9 +31,18 @@ type ProfileRequest struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// Suite describes application-owned input, shared state, and optional catalog
|
||||
// and named inspection capabilities. Its private issues retain adapter
|
||||
// construction failures.
|
||||
// RequirementsRequest selects a prompt context for native requirements
|
||||
// inspection.
|
||||
type RequirementsRequest struct {
|
||||
// Selection carries the configuration and overlay values supplied to the command.
|
||||
Selection ckconfig.Selection
|
||||
// Inspection carries PromptKit's discovery context for the selected prompt.
|
||||
Inspection promptkit.RequirementInspectionRequest
|
||||
}
|
||||
|
||||
// Suite describes application-owned input, shared state, and optional catalog,
|
||||
// named inspection, and requirements inspection capabilities. Its private
|
||||
// issues retain adapter construction failures.
|
||||
// Factory results and callback effects remain caller-owned: Command does not
|
||||
// deep-copy arbitrary objects or repair aliases returned by factories.
|
||||
// A reached operation prepares one input, applies its captured selectors, and
|
||||
@@ -41,24 +50,28 @@ type ProfileRequest struct {
|
||||
// Factories are not invoked during construction, installation, help, or version,
|
||||
// and need not run after failure.
|
||||
type Suite[I, S any] struct {
|
||||
// NewInput is called once when definition or catalog input preparation is
|
||||
// reached, before applying selectors and calling CheckInput.
|
||||
// NewInput is called once when definition, requirements, or catalog input
|
||||
// preparation is reached, before applying selectors and calling CheckInput.
|
||||
// If nil, input is the zero value of I, including nil for pointer types.
|
||||
NewInput func() I
|
||||
// NewState is called once when an inspection or catalog callback is reached,
|
||||
// after input checks pass. If nil, state is the zero value of S, including
|
||||
// nil for pointer types.
|
||||
NewState func() S
|
||||
// Selectors declares the original typed flags accepted by definition and
|
||||
// catalog commands.
|
||||
// Selectors declares the original typed flags accepted by definition,
|
||||
// requirements, and catalog commands.
|
||||
Selectors []commandkit.Flag[I]
|
||||
// CheckInput validates selected definition or catalog input before state
|
||||
// creation.
|
||||
// CheckInput validates selected definition, requirements, or catalog input
|
||||
// before state creation.
|
||||
CheckInput func(ckconfig.Selection, I) error
|
||||
// InspectPrompt inspects the selected prompt after input and state preparation.
|
||||
InspectPrompt func(context.Context, PromptRequest, I, S) (commandkit.Acquired[*promptkit.PromptInspection], error)
|
||||
// InspectProfile inspects the selected profile after input and state preparation.
|
||||
InspectProfile func(context.Context, ProfileRequest, I, S) (commandkit.Acquired[*promptkit.ProfileInspection], error)
|
||||
// InspectRequirements inspects native PromptKit requirements after input and
|
||||
// state preparation. It is optional; a nil callback omits the requirements
|
||||
// command without disabling other capabilities.
|
||||
InspectRequirements func(context.Context, RequirementsRequest, I, S) (commandkit.Acquired[*promptkit.RequirementInspection], 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)
|
||||
@@ -143,13 +156,13 @@ func promptKitContextError(ctx context.Context) error {
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
// FromEngine supplies callbacks for prompt and profile catalogs and named
|
||||
// inspections backed by a PromptKit engine loader. It 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 listing or inspection method. The callbacks can be
|
||||
// narrowed before Command captures them. A nil loader is retained as an adapter
|
||||
// issue.
|
||||
// FromEngine supplies callbacks for prompt and profile catalogs, named
|
||||
// inspections, and requirements inspection backed by a PromptKit engine loader.
|
||||
// It 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 listing or
|
||||
// inspection method. Applications can narrow these callbacks before Command
|
||||
// captures them. A nil loader is retained as an adapter issue.
|
||||
func FromEngine[I, S any](load func(context.Context, ckconfig.Selection, I, S) (*promptkit.Engine, error)) Suite[I, S] {
|
||||
if load == nil {
|
||||
return Suite[I, S]{issues: []error{errors.New("PromptKit engine loader is nil")}}
|
||||
@@ -188,6 +201,14 @@ func FromEngine[I, S any](load func(context.Context, ckconfig.Selection, I, S) (
|
||||
inspection, err := engine.InspectProfile(ctx, request.ID)
|
||||
return commandkit.Acquired[*promptkit.ProfileInspection]{Value: inspection, Diagnostics: diagnostics}, err
|
||||
},
|
||||
InspectRequirements: func(ctx context.Context, request RequirementsRequest, input I, state S) (commandkit.Acquired[*promptkit.RequirementInspection], error) {
|
||||
engine, _, diagnostics, err := loadPromptKitEngine(ctx, request.Selection, input, state, "", load)
|
||||
if err != nil {
|
||||
return commandkit.Acquired[*promptkit.RequirementInspection]{Diagnostics: diagnostics}, err
|
||||
}
|
||||
inspection, err := engine.InspectRequirements(ctx, request.Inspection)
|
||||
return commandkit.Acquired[*promptkit.RequirementInspection]{Value: inspection, Diagnostics: diagnostics}, err
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user