Wire native PromptKit sources into CLI commands
This commit is contained in:
@@ -218,7 +218,16 @@ outside the deliberate field removals.
|
|||||||
|
|
||||||
## Stage 3: Wire Native Sources Through All Existing CLI Engine Paths
|
## Stage 3: Wire Native Sources Through All Existing CLI Engine Paths
|
||||||
|
|
||||||
Status: Pending. Depends on Stage 2.
|
Status: Complete. Existing CLI engine paths now use the ordered native source
|
||||||
|
selectors, explicit repeated source flags, ConfigKit file inputs and PromptKit
|
||||||
|
directory inputs; profile/prompt inspection shares the same captured sources.
|
||||||
|
Retired directory/backend wiring and the empty-prompt filesystem are removed,
|
||||||
|
and captured diagnostics use the existing safe writer. `go build -o
|
||||||
|
/tmp/scriptorium-promptkit-native ./cmd/scriptorium`, `go test
|
||||||
|
./internal/config`, `gofmt`, and `git diff --check` pass. Full test/race/vet
|
||||||
|
checks reach only the stale CLI fields/fixtures assigned to Stages 5–6 and
|
||||||
|
removed PromptKit test constructors assigned to Stage 7; those are not
|
||||||
|
migrated here.
|
||||||
|
|
||||||
Files: `internal/adapter/cli/application_config.go`, `run.go`, `inspect.go`,
|
Files: `internal/adapter/cli/application_config.go`, `run.go`, `inspect.go`,
|
||||||
`config.go`; add a small `framework_sources.go` if useful within this package.
|
`config.go`; add a small `framework_sources.go` if useful within this package.
|
||||||
|
|||||||
@@ -16,10 +16,8 @@ func applicationOverrides(fs *flag.FlagSet) []configkit.Override {
|
|||||||
fs.Visit(func(selected *flag.Flag) {
|
fs.Visit(func(selected *flag.Flag) {
|
||||||
var path configkit.Path
|
var path configkit.Path
|
||||||
switch selected.Name {
|
switch selected.Name {
|
||||||
case "prompt-dir":
|
case "promptkit-source":
|
||||||
path = configkit.Keys("prompt_dir")
|
path = configkit.Keys("promptkit_sources")
|
||||||
case "profile-dir":
|
|
||||||
path = configkit.Keys("profile_dir")
|
|
||||||
case "schema-dir":
|
case "schema-dir":
|
||||||
path = configkit.Keys("schema_dir")
|
path = configkit.Keys("schema_dir")
|
||||||
case "addr":
|
case "addr":
|
||||||
|
|||||||
@@ -93,8 +93,6 @@ func configCommand(args []string, stdout, stderr io.Writer) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func registerConfigurationOverrides(fs *flag.FlagSet) {
|
func registerConfigurationOverrides(fs *flag.FlagSet) {
|
||||||
fs.String("prompt-dir", "", "prompt-definition directory override")
|
|
||||||
fs.String("profile-dir", "", "profile directory override")
|
|
||||||
fs.String("schema-dir", "", "schema directory override")
|
fs.String("schema-dir", "", "schema directory override")
|
||||||
fs.String("addr", "", "HTTP listen address override")
|
fs.String("addr", "", "HTTP listen address override")
|
||||||
fs.String("artifact-root", "", "HTTP artifact root override")
|
fs.String("artifact-root", "", "HTTP artifact root override")
|
||||||
|
|||||||
74
internal/adapter/cli/framework_sources.go
Normal file
74
internal/adapter/cli/framework_sources.go
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/promptkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
type promptKitSourceFlagEntry struct {
|
||||||
|
selector string
|
||||||
|
path string
|
||||||
|
}
|
||||||
|
|
||||||
|
// promptKitSourceFlagValue treats each occurrence as one selected source path.
|
||||||
|
type promptKitSourceFlagValue struct {
|
||||||
|
entries []promptKitSourceFlagEntry
|
||||||
|
}
|
||||||
|
|
||||||
|
func (value *promptKitSourceFlagValue) Set(path string) error {
|
||||||
|
trimmed := strings.TrimSpace(path)
|
||||||
|
if trimmed == "" {
|
||||||
|
return errors.New("--promptkit-source requires a nonblank path")
|
||||||
|
}
|
||||||
|
|
||||||
|
info, err := os.Stat(filepath.Clean(trimmed))
|
||||||
|
if err != nil {
|
||||||
|
reason := "unavailable"
|
||||||
|
if errors.Is(err, os.ErrPermission) {
|
||||||
|
reason = "permission denied"
|
||||||
|
}
|
||||||
|
return fmt.Errorf("--promptkit-source %q: %s", path, reason)
|
||||||
|
}
|
||||||
|
|
||||||
|
selector := ""
|
||||||
|
switch {
|
||||||
|
case info.IsDir():
|
||||||
|
selector = "directory"
|
||||||
|
case info.Mode().IsRegular():
|
||||||
|
selector = "file"
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("--promptkit-source %q must be a regular file or directory", path)
|
||||||
|
}
|
||||||
|
value.entries = append(value.entries, promptKitSourceFlagEntry{selector: selector, path: path})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (value *promptKitSourceFlagValue) Get() any {
|
||||||
|
selections := make([]any, 0, len(value.entries))
|
||||||
|
for _, entry := range value.entries {
|
||||||
|
selections = append(selections, map[string]any{entry.selector: entry.path})
|
||||||
|
}
|
||||||
|
return selections
|
||||||
|
}
|
||||||
|
|
||||||
|
func (value *promptKitSourceFlagValue) String() string {
|
||||||
|
paths := make([]string, 0, len(value.entries))
|
||||||
|
for _, entry := range value.entries {
|
||||||
|
paths = append(paths, entry.path)
|
||||||
|
}
|
||||||
|
return fmt.Sprint(paths)
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeFrameworkDiagnostics(output io.Writer, engine *promptkit.Engine) error {
|
||||||
|
view, err := engine.InspectConfiguration()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("inspect captured PromptKit diagnostics: %w", err)
|
||||||
|
}
|
||||||
|
return writeApplicationWarnings(output, view.Diagnostics())
|
||||||
|
}
|
||||||
@@ -6,17 +6,15 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||||
"gitea.maximumdirect.net/eric/promptkit"
|
|
||||||
appformat "gitea.maximumdirect.net/eric/scriptorium/internal/format"
|
appformat "gitea.maximumdirect.net/eric/scriptorium/internal/format"
|
||||||
)
|
)
|
||||||
|
|
||||||
type promptInspectionConfig struct {
|
type promptInspectionConfig struct {
|
||||||
configPath, promptDir, promptID, promptVersion, outputPath string
|
configPath, promptID, promptVersion, schemaDir, outputPath string
|
||||||
configOverlay string
|
configOverlay string
|
||||||
configExplicit bool
|
configExplicit bool
|
||||||
outputFormat appformat.OutputFormat
|
outputFormat appformat.OutputFormat
|
||||||
@@ -25,7 +23,7 @@ type promptInspectionConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type profileInspectionConfig struct {
|
type profileInspectionConfig struct {
|
||||||
configPath, profileDir, profileID, outputPath string
|
configPath, profileID, schemaDir, outputPath string
|
||||||
configOverlay string
|
configOverlay string
|
||||||
configExplicit bool
|
configExplicit bool
|
||||||
outputFormat appformat.OutputFormat
|
outputFormat appformat.OutputFormat
|
||||||
@@ -33,15 +31,6 @@ type profileInspectionConfig struct {
|
|||||||
diagnostics []configkit.Diagnostic
|
diagnostics []configkit.Diagnostic
|
||||||
}
|
}
|
||||||
|
|
||||||
// emptyPromptDefinitionFS satisfies Promptkit's engine-level prompt-source
|
|
||||||
// requirement without exposing the caller's working directory. Profile
|
|
||||||
// inspection never reads this source.
|
|
||||||
type emptyPromptDefinitionFS struct{}
|
|
||||||
|
|
||||||
func (emptyPromptDefinitionFS) Open(name string) (fs.File, error) {
|
|
||||||
return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrNotExist}
|
|
||||||
}
|
|
||||||
|
|
||||||
func inspectCommand(args []string, stdout, stderr io.Writer) int {
|
func inspectCommand(args []string, stdout, stderr io.Writer) int {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
fmt.Fprintln(stderr, "inspect parse error: inspection mode is required")
|
fmt.Fprintln(stderr, "inspect parse error: inspection mode is required")
|
||||||
@@ -69,7 +58,11 @@ func inspectCommand(args []string, stdout, stderr io.Writer) int {
|
|||||||
}
|
}
|
||||||
engine, err := newEngine(settings)
|
engine, err := newEngine(settings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(stderr, "engine error: %v\n", err)
|
writeApplicationError(stderr, "engine", err)
|
||||||
|
return ExitRuntimeError
|
||||||
|
}
|
||||||
|
if err := writeFrameworkDiagnostics(stderr, engine); err != nil {
|
||||||
|
fmt.Fprintf(stderr, "engine diagnostic write error: %v\n", err)
|
||||||
return ExitRuntimeError
|
return ExitRuntimeError
|
||||||
}
|
}
|
||||||
inspection, err := engine.InspectPrompt(context.Background(), cfg.promptID, cfg.promptVersion)
|
inspection, err := engine.InspectPrompt(context.Background(), cfg.promptID, cfg.promptVersion)
|
||||||
@@ -103,9 +96,13 @@ func inspectProfileCommand(args []string, stdout, stderr io.Writer) int {
|
|||||||
if err := writeApplicationWarnings(stderr, cfg.diagnostics); err != nil {
|
if err := writeApplicationWarnings(stderr, cfg.diagnostics); err != nil {
|
||||||
return ExitRuntimeError
|
return ExitRuntimeError
|
||||||
}
|
}
|
||||||
engine, err := newEngine(settings, promptkit.WithPromptFS(emptyPromptDefinitionFS{}, "."))
|
engine, err := newEngine(settings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(stderr, "engine error: %v\n", err)
|
writeApplicationError(stderr, "engine", err)
|
||||||
|
return ExitRuntimeError
|
||||||
|
}
|
||||||
|
if err := writeFrameworkDiagnostics(stderr, engine); err != nil {
|
||||||
|
fmt.Fprintf(stderr, "engine diagnostic write error: %v\n", err)
|
||||||
return ExitRuntimeError
|
return ExitRuntimeError
|
||||||
}
|
}
|
||||||
inspection, err := engine.InspectProfile(context.Background(), cfg.profileID)
|
inspection, err := engine.InspectProfile(context.Background(), cfg.profileID)
|
||||||
@@ -130,7 +127,9 @@ func parseProfileInspectionArgs(args []string) (*profileInspectionConfig, error)
|
|||||||
fs := flag.NewFlagSet("inspect profile", flag.ContinueOnError)
|
fs := flag.NewFlagSet("inspect profile", flag.ContinueOnError)
|
||||||
fs.SetOutput(io.Discard)
|
fs.SetOutput(io.Discard)
|
||||||
registerConfigSelectionFlags(fs, &cfg.configPath, &cfg.configOverlay)
|
registerConfigSelectionFlags(fs, &cfg.configPath, &cfg.configOverlay)
|
||||||
fs.StringVar(&cfg.profileDir, "profile-dir", "", "directory containing execution profiles")
|
var promptkitSources promptKitSourceFlagValue
|
||||||
|
fs.Var(&promptkitSources, "promptkit-source", "selected PromptKit source path (repeatable)")
|
||||||
|
fs.StringVar(&cfg.schemaDir, "schema-dir", "", "base directory for validation schemas")
|
||||||
fs.StringVar(&cfg.profileID, "profile", "", "profile ID to inspect")
|
fs.StringVar(&cfg.profileID, "profile", "", "profile ID to inspect")
|
||||||
rawFormat := ""
|
rawFormat := ""
|
||||||
fs.StringVar(&rawFormat, "format", "", "output format: text or json")
|
fs.StringVar(&rawFormat, "format", "", "output format: text or json")
|
||||||
@@ -163,7 +162,7 @@ func resolveAppSettingsForProfileInspection(cfg *profileInspectionConfig) (engin
|
|||||||
return engineSettings{}, err
|
return engineSettings{}, err
|
||||||
}
|
}
|
||||||
cfg.diagnostics = diagnostics
|
cfg.diagnostics = diagnostics
|
||||||
return engineSettings{profileDir: settings.ProfileDir, backends: settings.Backends, transientRetries: settings.TransientRetries}, nil
|
return engineSettings{promptkitSources: settings.PromptKitSources, schemaDir: settings.SchemaDir, transientRetries: settings.TransientRetries}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parsePromptInspectionArgs(args []string) (*promptInspectionConfig, error) {
|
func parsePromptInspectionArgs(args []string) (*promptInspectionConfig, error) {
|
||||||
@@ -171,7 +170,9 @@ func parsePromptInspectionArgs(args []string) (*promptInspectionConfig, error) {
|
|||||||
fs := flag.NewFlagSet("inspect prompt", flag.ContinueOnError)
|
fs := flag.NewFlagSet("inspect prompt", flag.ContinueOnError)
|
||||||
fs.SetOutput(io.Discard)
|
fs.SetOutput(io.Discard)
|
||||||
registerConfigSelectionFlags(fs, &cfg.configPath, &cfg.configOverlay)
|
registerConfigSelectionFlags(fs, &cfg.configPath, &cfg.configOverlay)
|
||||||
fs.StringVar(&cfg.promptDir, "prompt-dir", "", "directory containing prompt definitions")
|
var promptkitSources promptKitSourceFlagValue
|
||||||
|
fs.Var(&promptkitSources, "promptkit-source", "selected PromptKit source path (repeatable)")
|
||||||
|
fs.StringVar(&cfg.schemaDir, "schema-dir", "", "base directory for validation schemas")
|
||||||
fs.StringVar(&cfg.promptID, "prompt", "", "prompt ID to inspect")
|
fs.StringVar(&cfg.promptID, "prompt", "", "prompt ID to inspect")
|
||||||
fs.StringVar(&cfg.promptVersion, "prompt-version", "", "optional prompt version")
|
fs.StringVar(&cfg.promptVersion, "prompt-version", "", "optional prompt version")
|
||||||
rawFormat := ""
|
rawFormat := ""
|
||||||
@@ -205,8 +206,5 @@ func resolveAppSettingsForPromptInspection(cfg *promptInspectionConfig) (engineS
|
|||||||
return engineSettings{}, err
|
return engineSettings{}, err
|
||||||
}
|
}
|
||||||
cfg.diagnostics = diagnostics
|
cfg.diagnostics = diagnostics
|
||||||
if strings.TrimSpace(settings.PromptDir) == "" {
|
return engineSettings{promptkitSources: settings.PromptKitSources, schemaDir: settings.SchemaDir, transientRetries: settings.TransientRetries}, nil
|
||||||
return engineSettings{}, errors.New(errPromptDirRequired)
|
|
||||||
}
|
|
||||||
return engineSettings{promptDir: settings.PromptDir, backends: settings.Backends, transientRetries: settings.TransientRetries}, nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,15 +28,10 @@ const (
|
|||||||
ExitValidationFailed = 2
|
ExitValidationFailed = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
errPromptDirRequired = "prompt directory is required; provide --prompt-dir or config.yml prompt_dir"
|
|
||||||
)
|
|
||||||
|
|
||||||
type runConfig struct {
|
type runConfig struct {
|
||||||
configPath string
|
configPath string
|
||||||
|
|
||||||
promptDir string
|
promptkitSources []appconfig.SourceSelection
|
||||||
profileDir string
|
|
||||||
promptID string
|
promptID string
|
||||||
promptVersion string
|
promptVersion string
|
||||||
profileID string
|
profileID string
|
||||||
@@ -53,7 +48,6 @@ type runConfig struct {
|
|||||||
topP float64
|
topP float64
|
||||||
reasoningEffort string
|
reasoningEffort string
|
||||||
schemaDir string
|
schemaDir string
|
||||||
backends []appconfig.BackendSettings
|
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
runTimeout time.Duration
|
runTimeout time.Duration
|
||||||
transientRetries int
|
transientRetries int
|
||||||
@@ -83,22 +77,19 @@ type serveConfig struct {
|
|||||||
configPath string
|
configPath string
|
||||||
|
|
||||||
addr string
|
addr string
|
||||||
promptDir string
|
promptkitSources []appconfig.SourceSelection
|
||||||
profileDir string
|
|
||||||
schemaDir string
|
schemaDir string
|
||||||
artifactRoot string
|
artifactRoot string
|
||||||
maxRequestBytes int64
|
maxRequestBytes int64
|
||||||
maxArtifactBytes int64
|
maxArtifactBytes int64
|
||||||
maxResponseBytes int64
|
maxResponseBytes int64
|
||||||
backends []appconfig.BackendSettings
|
|
||||||
transientRetries *int
|
transientRetries *int
|
||||||
diagnostics []configkit.Diagnostic
|
diagnostics []configkit.Diagnostic
|
||||||
configOverlay string
|
configOverlay string
|
||||||
}
|
}
|
||||||
|
|
||||||
type commonCommandSettings struct {
|
type commonCommandSettings struct {
|
||||||
promptDir string
|
promptkitSources []appconfig.SourceSelection
|
||||||
profileDir string
|
|
||||||
schemaDir string
|
schemaDir string
|
||||||
serverAddr string
|
serverAddr string
|
||||||
artifactRoot string
|
artifactRoot string
|
||||||
@@ -106,7 +97,6 @@ type commonCommandSettings struct {
|
|||||||
maxArtifactBytes int64
|
maxArtifactBytes int64
|
||||||
maxResponseBytes int64
|
maxResponseBytes int64
|
||||||
defaultRenderFormat renderformat.PreparedRunOutputFormat
|
defaultRenderFormat renderformat.PreparedRunOutputFormat
|
||||||
backends []appconfig.BackendSettings
|
|
||||||
transientRetries *int
|
transientRetries *int
|
||||||
diagnostics []configkit.Diagnostic
|
diagnostics []configkit.Diagnostic
|
||||||
}
|
}
|
||||||
@@ -164,7 +154,11 @@ func runCommand(args []string, stdout, stderr io.Writer) int {
|
|||||||
|
|
||||||
engine, err := newEngine(cfg.engineSettings())
|
engine, err := newEngine(cfg.engineSettings())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(stderr, "engine error: %v\n", err)
|
writeApplicationError(stderr, "engine", err)
|
||||||
|
return ExitRuntimeError
|
||||||
|
}
|
||||||
|
if err := writeFrameworkDiagnostics(stderr, engine); err != nil {
|
||||||
|
fmt.Fprintf(stderr, "engine diagnostic write error: %v\n", err)
|
||||||
return ExitRuntimeError
|
return ExitRuntimeError
|
||||||
}
|
}
|
||||||
return executeRun(cfg, req, engine.Run, stdout, stderr)
|
return executeRun(cfg, req, engine.Run, stdout, stderr)
|
||||||
@@ -242,7 +236,11 @@ func renderCommand(args []string, stdout, stderr io.Writer) int {
|
|||||||
|
|
||||||
engine, err := newEngine(cfg.runConfig.engineSettings())
|
engine, err := newEngine(cfg.runConfig.engineSettings())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(stderr, "engine error: %v\n", err)
|
writeApplicationError(stderr, "engine", err)
|
||||||
|
return ExitRuntimeError
|
||||||
|
}
|
||||||
|
if err := writeFrameworkDiagnostics(stderr, engine); err != nil {
|
||||||
|
fmt.Fprintf(stderr, "engine diagnostic write error: %v\n", err)
|
||||||
return ExitRuntimeError
|
return ExitRuntimeError
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,7 +281,11 @@ func serveCommand(args []string, stderr io.Writer) int {
|
|||||||
|
|
||||||
engine, err := newEngine(cfg.engineSettings(), promptkit.WithArtifactReader(artifactReader))
|
engine, err := newEngine(cfg.engineSettings(), promptkit.WithArtifactReader(artifactReader))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(stderr, "engine error: %v\n", err)
|
writeApplicationError(stderr, "engine", err)
|
||||||
|
return ExitRuntimeError
|
||||||
|
}
|
||||||
|
if err := writeFrameworkDiagnostics(stderr, engine); err != nil {
|
||||||
|
fmt.Fprintf(stderr, "engine diagnostic write error: %v\n", err)
|
||||||
return ExitRuntimeError
|
return ExitRuntimeError
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,8 +402,8 @@ func parseServeArgs(args []string) (*serveConfig, error) {
|
|||||||
|
|
||||||
registerConfigSelectionFlags(fs, &cfg.configPath, &cfg.configOverlay)
|
registerConfigSelectionFlags(fs, &cfg.configPath, &cfg.configOverlay)
|
||||||
fs.StringVar(&cfg.addr, "addr", "", "HTTP listen address")
|
fs.StringVar(&cfg.addr, "addr", "", "HTTP listen address")
|
||||||
fs.StringVar(&cfg.promptDir, "prompt-dir", "", "directory containing prompt definition YAML files")
|
var promptkitSources promptKitSourceFlagValue
|
||||||
fs.StringVar(&cfg.profileDir, "profile-dir", "", "directory containing execution profile YAML files")
|
fs.Var(&promptkitSources, "promptkit-source", "selected PromptKit source path (repeatable)")
|
||||||
fs.StringVar(&cfg.schemaDir, "schema-dir", "", "base directory for validation schemas")
|
fs.StringVar(&cfg.schemaDir, "schema-dir", "", "base directory for validation schemas")
|
||||||
fs.StringVar(&cfg.artifactRoot, "artifact-root", "", "base directory for HTTP file input artifacts")
|
fs.StringVar(&cfg.artifactRoot, "artifact-root", "", "base directory for HTTP file input artifacts")
|
||||||
fs.Int64Var(&cfg.maxRequestBytes, "max-request-bytes", 0, "maximum HTTP request body bytes; 0 disables the limit")
|
fs.Int64Var(&cfg.maxRequestBytes, "max-request-bytes", 0, "maximum HTTP request body bytes; 0 disables the limit")
|
||||||
@@ -420,28 +422,22 @@ func parseServeArgs(args []string) (*serveConfig, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.promptDir = settings.promptDir
|
cfg.promptkitSources = settings.promptkitSources
|
||||||
cfg.profileDir = settings.profileDir
|
|
||||||
cfg.schemaDir = settings.schemaDir
|
cfg.schemaDir = settings.schemaDir
|
||||||
cfg.addr = settings.serverAddr
|
cfg.addr = settings.serverAddr
|
||||||
cfg.artifactRoot = settings.artifactRoot
|
cfg.artifactRoot = settings.artifactRoot
|
||||||
cfg.maxRequestBytes = settings.maxRequestBytes
|
cfg.maxRequestBytes = settings.maxRequestBytes
|
||||||
cfg.maxArtifactBytes = settings.maxArtifactBytes
|
cfg.maxArtifactBytes = settings.maxArtifactBytes
|
||||||
cfg.maxResponseBytes = settings.maxResponseBytes
|
cfg.maxResponseBytes = settings.maxResponseBytes
|
||||||
cfg.backends = settings.backends
|
|
||||||
cfg.transientRetries = settings.transientRetries
|
cfg.transientRetries = settings.transientRetries
|
||||||
cfg.diagnostics = settings.diagnostics
|
cfg.diagnostics = settings.diagnostics
|
||||||
|
|
||||||
if err := validateRequiredLibraryDirs(cfg.promptDir); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerExecutionRequestFlags(fs *flag.FlagSet, cfg *runConfig) {
|
func registerExecutionRequestFlags(fs *flag.FlagSet, cfg *runConfig) {
|
||||||
fs.StringVar(&cfg.promptDir, "prompt-dir", "", "directory containing prompt definition YAML files")
|
var promptkitSources promptKitSourceFlagValue
|
||||||
fs.StringVar(&cfg.profileDir, "profile-dir", "", "directory containing execution profile YAML files")
|
fs.Var(&promptkitSources, "promptkit-source", "selected PromptKit source path (repeatable)")
|
||||||
fs.StringVar(&cfg.promptID, "prompt", "", "prompt ID to run")
|
fs.StringVar(&cfg.promptID, "prompt", "", "prompt ID to run")
|
||||||
fs.StringVar(&cfg.promptVersion, "prompt-version", "", "optional prompt definition version")
|
fs.StringVar(&cfg.promptVersion, "prompt-version", "", "optional prompt definition version")
|
||||||
fs.StringVar(&cfg.profileID, "profile", "", "optional execution profile ID; if omitted, prompt default_profile is used")
|
fs.StringVar(&cfg.profileID, "profile", "", "optional execution profile ID; if omitted, prompt default_profile is used")
|
||||||
@@ -472,17 +468,12 @@ func finalizeExecutionRequestConfig(fs *flag.FlagSet, cfg *runConfig) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.promptDir = settings.promptDir
|
cfg.promptkitSources = settings.promptkitSources
|
||||||
cfg.profileDir = settings.profileDir
|
|
||||||
cfg.schemaDir = settings.schemaDir
|
cfg.schemaDir = settings.schemaDir
|
||||||
cfg.defaultRenderFormat = settings.defaultRenderFormat
|
cfg.defaultRenderFormat = settings.defaultRenderFormat
|
||||||
cfg.backends = settings.backends
|
|
||||||
cfg.configuredTransientRetries = settings.transientRetries
|
cfg.configuredTransientRetries = settings.transientRetries
|
||||||
cfg.diagnostics = settings.diagnostics
|
cfg.diagnostics = settings.diagnostics
|
||||||
|
|
||||||
if err := validateRequiredLibraryDirs(cfg.promptDir); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if strings.TrimSpace(cfg.promptID) == "" {
|
if strings.TrimSpace(cfg.promptID) == "" {
|
||||||
return errors.New("--prompt is required")
|
return errors.New("--prompt is required")
|
||||||
}
|
}
|
||||||
@@ -524,8 +515,7 @@ func resolveCommonSettings(fs *flag.FlagSet, configPath, overlay string) (common
|
|||||||
return commonCommandSettings{}, err
|
return commonCommandSettings{}, err
|
||||||
}
|
}
|
||||||
return commonCommandSettings{
|
return commonCommandSettings{
|
||||||
promptDir: settings.PromptDir,
|
promptkitSources: settings.PromptKitSources,
|
||||||
profileDir: settings.ProfileDir,
|
|
||||||
schemaDir: settings.SchemaDir,
|
schemaDir: settings.SchemaDir,
|
||||||
serverAddr: settings.ServerAddr,
|
serverAddr: settings.ServerAddr,
|
||||||
artifactRoot: settings.ArtifactRoot,
|
artifactRoot: settings.ArtifactRoot,
|
||||||
@@ -533,54 +523,50 @@ func resolveCommonSettings(fs *flag.FlagSet, configPath, overlay string) (common
|
|||||||
maxArtifactBytes: settings.MaxArtifactBytes,
|
maxArtifactBytes: settings.MaxArtifactBytes,
|
||||||
maxResponseBytes: settings.MaxResponseBytes,
|
maxResponseBytes: settings.MaxResponseBytes,
|
||||||
defaultRenderFormat: settings.DefaultRenderFormat,
|
defaultRenderFormat: settings.DefaultRenderFormat,
|
||||||
backends: settings.Backends,
|
|
||||||
transientRetries: settings.TransientRetries,
|
transientRetries: settings.TransientRetries,
|
||||||
diagnostics: diagnostics,
|
diagnostics: diagnostics,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateRequiredLibraryDirs(promptDir string) error {
|
|
||||||
if strings.TrimSpace(promptDir) == "" {
|
|
||||||
return errors.New(errPromptDirRequired)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type engineSettings struct {
|
type engineSettings struct {
|
||||||
promptDir string
|
promptkitSources []appconfig.SourceSelection
|
||||||
profileDir string
|
|
||||||
schemaDir string
|
schemaDir string
|
||||||
backends []appconfig.BackendSettings
|
|
||||||
transientRetries *int
|
transientRetries *int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c runConfig) engineSettings() engineSettings {
|
func (c runConfig) engineSettings() engineSettings {
|
||||||
return engineSettings{promptDir: c.promptDir, profileDir: c.profileDir, schemaDir: c.schemaDir, backends: c.backends, transientRetries: c.configuredTransientRetries}
|
return engineSettings{promptkitSources: c.promptkitSources, schemaDir: c.schemaDir, transientRetries: c.configuredTransientRetries}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c serveConfig) engineSettings() engineSettings {
|
func (c serveConfig) engineSettings() engineSettings {
|
||||||
return engineSettings{promptDir: c.promptDir, profileDir: c.profileDir, schemaDir: c.schemaDir, backends: c.backends, transientRetries: c.transientRetries}
|
return engineSettings{promptkitSources: c.promptkitSources, schemaDir: c.schemaDir, transientRetries: c.transientRetries}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newEngine(settings engineSettings, options ...promptkit.Option) (*promptkit.Engine, error) {
|
func newEngine(settings engineSettings, options ...promptkit.Option) (*promptkit.Engine, error) {
|
||||||
engineOptions := make([]promptkit.Option, 0, len(settings.backends)+len(options))
|
underlays := make([]configkit.Underlay, 0, len(settings.promptkitSources))
|
||||||
for _, configured := range settings.backends {
|
for index, selection := range settings.promptkitSources {
|
||||||
engineOptions = append(engineOptions, promptkit.WithBackend(promptkit.Backend{
|
var inputs []configkit.Input
|
||||||
ID: configured.ID,
|
switch {
|
||||||
Endpoint: configured.Endpoint,
|
case selection.File != "" && selection.Directory == "":
|
||||||
APIKeyEnv: configured.APIKeyEnv,
|
inputs = []configkit.Input{{Source: configkit.File(selection.File), Imports: true}}
|
||||||
ExtraParams: configured.ExtraParams,
|
case selection.Directory != "" && selection.File == "":
|
||||||
ConcurrencyLimit: configured.ConcurrencyLimit,
|
var err error
|
||||||
QueueCapacity: configured.QueueCapacity,
|
inputs, err = promptkit.DirectoryInputs(selection.Directory)
|
||||||
}))
|
if err != nil {
|
||||||
|
cause := fmt.Errorf("PromptKit source %d directory %q: %w", index+1, selection.Directory, err)
|
||||||
|
return nil, fmt.Errorf("engine initialization from application configuration: %w", errors.Join(promptkit.ErrInvalidConfig, cause))
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
cause := fmt.Errorf("PromptKit source %d must select exactly one file or directory", index+1)
|
||||||
|
return nil, fmt.Errorf("engine initialization from application configuration: %w", errors.Join(promptkit.ErrInvalidConfig, cause))
|
||||||
|
}
|
||||||
|
underlays = append(underlays, configkit.Underlay{Inputs: inputs})
|
||||||
}
|
}
|
||||||
engineOptions = append(engineOptions, options...)
|
|
||||||
engine, err := promptkit.NewEngine(promptkit.Config{
|
engine, err := promptkit.NewEngine(promptkit.Config{
|
||||||
PromptDir: settings.promptDir,
|
Sources: promptkit.ConfigurationSources{Underlays: underlays},
|
||||||
ProfileDir: settings.profileDir,
|
|
||||||
SchemaDir: settings.schemaDir,
|
SchemaDir: settings.schemaDir,
|
||||||
TransientRetries: settings.transientRetries,
|
TransientRetries: settings.transientRetries,
|
||||||
}, engineOptions...)
|
}, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("engine initialization from application configuration: %w", err)
|
return nil, fmt.Errorf("engine initialization from application configuration: %w", err)
|
||||||
}
|
}
|
||||||
@@ -755,10 +741,10 @@ func runErrorMessage(err error) string {
|
|||||||
|
|
||||||
func printUsage(w io.Writer) {
|
func printUsage(w io.Writer) {
|
||||||
fmt.Fprintln(w, "usage: scriptorium <run|render|serve|inspect|config> ...")
|
fmt.Fprintln(w, "usage: scriptorium <run|render|serve|inspect|config> ...")
|
||||||
fmt.Fprintln(w, " run: scriptorium run [--config PATH] [--config-overlay NAME] [--prompt-dir DIR] [--profile-dir DIR] [--schema-dir DIR] --prompt ID [--prompt-version VERSION] [--input name=path] [--profile ID] [--session-id ID] [--llm-base-url URL] [--model NAME] [--api-key-env ENV] [--temperature N] [--max-tokens N] [--top-p N] [--reasoning-effort VALUE] [--var k=v] [--out path] [--execution-report path] [--timeout 10m] [--run-timeout 10m] [--transient-retries N]")
|
fmt.Fprintln(w, " run: scriptorium run [--config PATH] [--config-overlay NAME] [--promptkit-source PATH ...] [--schema-dir DIR] --prompt ID [--prompt-version VERSION] [--input name=path] [--profile ID] [--session-id ID] [--llm-base-url URL] [--model NAME] [--api-key-env ENV] [--temperature N] [--max-tokens N] [--top-p N] [--reasoning-effort VALUE] [--var k=v] [--out path] [--execution-report path] [--timeout 10m] [--run-timeout 10m] [--transient-retries N]")
|
||||||
fmt.Fprintln(w, " render: scriptorium render [--config PATH] [--config-overlay NAME] [--prompt-dir DIR] [--profile-dir DIR] [--schema-dir DIR] --prompt ID [--prompt-version VERSION] [--input name=path] [--profile ID] [--session-id ID] [--llm-base-url URL] [--model NAME] [--api-key-env ENV] [--temperature N] [--max-tokens N] [--top-p N] [--reasoning-effort VALUE] [--var k=v] [--format text|json] [--out path] [--timeout 10m] [--transient-retries N]")
|
fmt.Fprintln(w, " render: scriptorium render [--config PATH] [--config-overlay NAME] [--promptkit-source PATH ...] [--schema-dir DIR] --prompt ID [--prompt-version VERSION] [--input name=path] [--profile ID] [--session-id ID] [--llm-base-url URL] [--model NAME] [--api-key-env ENV] [--temperature N] [--max-tokens N] [--top-p N] [--reasoning-effort VALUE] [--var k=v] [--format text|json] [--out path] [--timeout 10m] [--transient-retries N]")
|
||||||
fmt.Fprintf(w, " serve: scriptorium serve [--config PATH] [--config-overlay NAME] [--addr %s] [--prompt-dir DIR] [--profile-dir DIR] [--schema-dir DIR] [--artifact-root DIR] [--max-request-bytes N] [--max-artifact-bytes N] [--max-response-bytes N]\n", defaults.HTTPAddrDefault)
|
fmt.Fprintf(w, " serve: scriptorium serve [--config PATH] [--config-overlay NAME] [--promptkit-source PATH ...] [--addr %s] [--schema-dir DIR] [--artifact-root DIR] [--max-request-bytes N] [--max-artifact-bytes N] [--max-response-bytes N]\n", defaults.HTTPAddrDefault)
|
||||||
fmt.Fprintln(w, " inspect prompt: scriptorium inspect prompt --prompt ID [--prompt-version VERSION] [--config PATH] [--config-overlay NAME] [--prompt-dir DIR] [--format text|json] [--out path]")
|
fmt.Fprintln(w, " inspect prompt: scriptorium inspect prompt --prompt ID [--prompt-version VERSION] [--config PATH] [--config-overlay NAME] [--promptkit-source PATH ...] [--schema-dir DIR] [--format text|json] [--out path]")
|
||||||
fmt.Fprintln(w, " inspect profile: scriptorium inspect profile --profile ID [--config PATH] [--config-overlay NAME] [--profile-dir DIR] [--format text|json] [--out path]")
|
fmt.Fprintln(w, " inspect profile: scriptorium inspect profile --profile ID [--config PATH] [--config-overlay NAME] [--promptkit-source PATH ...] [--schema-dir DIR] [--format text|json] [--out path]")
|
||||||
fmt.Fprintln(w, " config: scriptorium config <validate|show|sources|explain> [--config PATH] [--config-overlay NAME] [application overrides] [--path /pointer for explain]")
|
fmt.Fprintln(w, " config: scriptorium config <validate|show|sources|explain> [--config PATH] [--config-overlay NAME] [application overrides] [--path /pointer for explain]")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user