2026-11-20 03:35:49 +00:00
package cli
import (
"context"
"io"
"go.maximumdirect.net/ckconfig"
"go.maximumdirect.net/ckprompt"
"go.maximumdirect.net/commandkit"
)
// Execute composes the native CLI and returns its finalized outcome. The caller
// owns the context, streams, and process exit.
func Execute ( ctx context . Context , identity commandkit . Identity , args [ ] string , stdout , stderr io . Writer ) commandkit . Outcome {
app , err := newApp ( identity )
if err != nil {
return commandkit . Failure ( "Could not compose application commands." ) . WithCause ( err )
}
return app . Execute ( ctx , args , commandkit . Streams { Out : stdout , Err : stderr } )
}
func newApp ( identity commandkit . Identity ) ( * commandkit . App , error ) {
application := ckconfig . FromConfigKit ( "app" , "Scriptorium application configuration." , loadApplication )
framework := ckprompt . ConfigScope ( loadEngine )
2026-11-20 04:26:17 +00:00
configuration := ckconfig . Command ( ckconfig . Suite [ applicationInput , struct { } ] {
NewInput : func ( ) applicationInput { return applicationInput { } } ,
Scopes : [ ] ckconfig . Scope [ applicationInput , struct { } ] { application , framework } ,
2026-11-20 03:35:49 +00:00
} )
definitions := ckprompt . FromEngine ( loadEngine )
declarations := [ ] commandkit . Declaration {
commandkit . NewCommand ( commandkit . CommandSpec [ struct { } ] { Name : "run" , Summary : "Run a stored prompt." , Run : commandNotImplemented } ) ,
2026-11-20 04:26:17 +00:00
commandkit . NewCommand ( commandkit . CommandSpec [ serveInput ] { Name : "serve" , Summary : "Serve the HTTP API." , Flags : serveFlags ( ) , Run : func ( commandkit . Invocation , serveInput ) commandkit . Outcome {
return commandkit . Failure ( "Server startup is not implemented." )
} } ) ,
2026-11-20 03:35:49 +00:00
configuration ,
commandkit . Completion ( "scriptorium" ) ,
}
declarations = append ( declarations , ckprompt . Declarations ( definitions ) ... )
return commandkit . New ( identity , declarations ... )
}
2026-11-20 04:26:17 +00:00
type serveInput struct {
Selection ckconfig . Selection
Application applicationInput
2026-11-20 03:35:49 +00:00
}
2026-11-20 04:26:17 +00:00
func serveFlags ( ) [ ] commandkit . Flag [ serveInput ] {
flags := configurationSelectors ( func ( input * serveInput ) * ckconfig . Selection { return & input . Selection } )
return append ( flags , serverSelectors ( func ( input * serveInput ) * applicationInput { return & input . Application } ) ... )
2026-11-20 03:35:49 +00:00
}
func commandNotImplemented ( commandkit . Invocation , struct { } ) commandkit . Outcome {
return commandkit . Failure ( "Application command is not implemented." )
}