2026-11-21 22:59:46 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
|
2026-11-22 03:32:31 +00:00
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
2026-11-21 22:59:46 +00:00
|
|
|
"go.maximumdirect.net/ckconfig"
|
2026-11-21 23:02:57 +00:00
|
|
|
"go.maximumdirect.net/ckprompt"
|
2026-11-21 22:59:46 +00:00
|
|
|
"go.maximumdirect.net/commandkit"
|
|
|
|
|
"go.maximumdirect.net/configkit"
|
2026-11-21 23:02:57 +00:00
|
|
|
"go.maximumdirect.net/promptkit"
|
2026-11-21 22:59:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 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) {
|
2026-11-21 23:02:57 +00:00
|
|
|
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
|
|
|
|
|
}
|
2026-11-21 22:59:46 +00:00
|
|
|
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
|
2026-11-21 23:02:57 +00:00
|
|
|
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{
|
2026-11-21 22:59:46 +00:00
|
|
|
commandkit.Completion("notarius"),
|
2026-11-22 03:32:31 +00:00
|
|
|
pipelineCommands(newState, func() (pipeline.ModuleCatalog, error) { return effectiveCatalog(options) }),
|
2026-11-21 22:59:46 +00:00
|
|
|
ckconfig.Command(ckconfig.Suite[struct{}, *nativeLoaders]{
|
|
|
|
|
NewState: newState,
|
|
|
|
|
CheckInput: func(_ string, selection ckconfig.Selection, _ struct{}) error {
|
2026-11-21 23:02:57 +00:00
|
|
|
return checkConfigSelection(selection)
|
2026-11-21 22:59:46 +00:00
|
|
|
},
|
|
|
|
|
Scopes: []ckconfig.Scope[struct{}, *nativeLoaders]{appScope, promptScope},
|
|
|
|
|
}),
|
2026-11-21 23:02:57 +00:00
|
|
|
}
|
|
|
|
|
declarations = append(declarations, ckprompt.Declarations(definitions)...)
|
|
|
|
|
return commandkit.New(commandkit.Identity{Name: "notarius", Version: version}, declarations...)
|
|
|
|
|
}
|