Files
notarius/internal/cli/application.go

58 lines
2.8 KiB
Go
Raw Normal View History

package cli
import (
"context"
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
"go.maximumdirect.net/ckconfig"
"go.maximumdirect.net/ckprompt"
"go.maximumdirect.net/commandkit"
"go.maximumdirect.net/configkit"
"go.maximumdirect.net/promptkit"
)
// NewApplication declares the native command surface. Acquisition is deferred to
// the selected handler; construction performs no configuration or engine work.
func NewApplication(version string, options Options) (*commandkit.App, error) {
options = defaultOptions(options)
newState := func() *nativeLoaders {
state := &nativeLoaders{lookupEnv: options.LookupEnv, runtime: options.LLMRuntime}
if options.LLMClient != nil {
state.engineOptions = []promptkit.Option{promptkit.WithLLMClient(options.LLMClient)}
}
return state
}
load := func(ctx context.Context, selection ckconfig.Selection, _ struct{}, state *nativeLoaders) (*configkit.Result[config.Document], error) {
return state.application(ctx, selection)
}
appScope := ckconfig.FromConfigKit("app", "Notarius application configuration.", load)
appScope.Features.Overrides = true
promptScope := ckconfig.FromConfigKitSubtree("promptkit", "Native PromptKit configuration.", configkit.Keys("promptkit"), load)
promptScope.Features.Overrides = true
loadEngine := func(ctx context.Context, selection ckconfig.Selection, _ struct{}, state *nativeLoaders) (*promptkit.Engine, error) {
return state.engine(ctx, selection)
}
definitions := ckprompt.FromEngine(loadEngine)
definitions.NewState = newState
definitions.CheckInput = func(selection ckconfig.Selection, _ struct{}) error { return checkConfigSelection(selection) }
definitions = ckprompt.WithRequestValidation(definitions, loadEngine, nil)
definitions = ckprompt.WithRequestPreparation(definitions, loadEngine, nil)
definitions = ckprompt.WithSmokeTesting(definitions, loadEngine, nil)
definitions = ckprompt.WithNamespaces(definitions, promptkit.Namespaces{})
declarations := []commandkit.Declaration{
commandkit.Completion("notarius"),
pipelineCommands(newState, func() (pipeline.ModuleCatalog, error) { return effectiveCatalog(options) }, pipelineRunCommand(version, newState, func() (pipeline.Registries, error) { return effectiveRegistries(options) }, options)),
commandkit.Alias("run", "pipeline run"),
ckconfig.Command(ckconfig.Suite[struct{}, *nativeLoaders]{
NewState: newState,
CheckInput: func(_ string, selection ckconfig.Selection, _ struct{}) error {
return checkConfigSelection(selection)
},
Scopes: []ckconfig.Scope[struct{}, *nativeLoaders]{appScope, promptScope},
}),
}
declarations = append(declarations, ckprompt.Declarations(definitions)...)
return commandkit.New(commandkit.Identity{Name: "notarius", Version: version}, declarations...)
}