Add scoped PromptKit configuration reports
This commit is contained in:
@@ -3,6 +3,7 @@ package cli
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
|
||||
frameworkllm "gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
|
||||
)
|
||||
|
||||
func runConfigEffective(args []string, stdout, stderr io.Writer, opts Options) int {
|
||||
@@ -17,6 +19,7 @@ func runConfigEffective(args []string, stdout, stderr io.Writer, opts Options) i
|
||||
fs.SetOutput(io.Discard)
|
||||
configPath := fs.String("config", "", "config file path")
|
||||
overlay := fs.String("config-overlay", "", "configuration overlay")
|
||||
scope := fs.String("scope", "notarius", "configuration scope: notarius or promptkit")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
fmt.Fprintf(stderr, "notarius: %v\n", err)
|
||||
return 2
|
||||
@@ -25,12 +28,28 @@ func runConfigEffective(args []string, stdout, stderr io.Writer, opts Options) i
|
||||
fmt.Fprintf(stderr, "notarius: unexpected argument %q\n", fs.Arg(0))
|
||||
return 2
|
||||
}
|
||||
if *scope != "notarius" && *scope != "promptkit" {
|
||||
fmt.Fprintf(stderr, "notarius: invalid configuration scope %q (want notarius or promptkit)\n", *scope)
|
||||
return 2
|
||||
}
|
||||
loaded, _, err := loadConfigKit(*configPath, *overlay, nil, opts)
|
||||
if err != nil {
|
||||
writeConfigLoadError(stderr, err)
|
||||
return 1
|
||||
}
|
||||
if err := loaded.WriteEffective(stdout); err != nil {
|
||||
if *scope == "notarius" {
|
||||
if err := loaded.WriteEffective(stdout); err != nil {
|
||||
fmt.Fprintf(stderr, "notarius: write effective configuration: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
inspector, err := newPromptKitInspection(loaded.Config, opts)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "notarius: inspect PromptKit configuration: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
if err := inspector.WriteEffectiveConfiguration(stdout); err != nil {
|
||||
fmt.Fprintf(stderr, "notarius: write effective configuration: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
@@ -42,6 +61,7 @@ func runConfigExplain(args []string, stdout, stderr io.Writer, opts Options) int
|
||||
fs.SetOutput(io.Discard)
|
||||
configPath := fs.String("config", "", "config file path")
|
||||
overlay := fs.String("config-overlay", "", "configuration overlay")
|
||||
scope := fs.String("scope", "notarius", "configuration scope: notarius or promptkit")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
fmt.Fprintf(stderr, "notarius: %v\n", err)
|
||||
return 2
|
||||
@@ -50,7 +70,37 @@ func runConfigExplain(args []string, stdout, stderr io.Writer, opts Options) int
|
||||
fmt.Fprintln(stderr, "notarius: config explain requires exactly one JSON Pointer")
|
||||
return 2
|
||||
}
|
||||
if *scope != "notarius" && *scope != "promptkit" {
|
||||
fmt.Fprintf(stderr, "notarius: invalid configuration scope %q (want notarius or promptkit)\n", *scope)
|
||||
return 2
|
||||
}
|
||||
pointer := fs.Arg(0)
|
||||
if *scope == "promptkit" {
|
||||
loaded, _, err := loadConfigKit(*configPath, *overlay, nil, opts)
|
||||
if err != nil {
|
||||
writeConfigLoadError(stderr, err)
|
||||
return 1
|
||||
}
|
||||
inspector, err := newPromptKitInspection(loaded.Config, opts)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "notarius: inspect PromptKit configuration: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
found, err := inspector.WriteConfigurationExplanation(stdout, pointer)
|
||||
if err != nil {
|
||||
if errors.Is(err, frameworkllm.ErrInvalidPromptKitConfigurationPointer) {
|
||||
fmt.Fprintf(stderr, "notarius: %q is not a canonical JSON Pointer\n", pointer)
|
||||
return 2
|
||||
}
|
||||
fmt.Fprintf(stderr, "notarius: write PromptKit configuration explanation: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
if !found {
|
||||
fmt.Fprintf(stderr, "notarius: PromptKit configuration pointer %q is unknown\n", pointer)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
parsed, err := configkit.ParsePath(pointer)
|
||||
if err != nil || parsed.String() != pointer {
|
||||
fmt.Fprintf(stderr, "notarius: %q is not a canonical JSON Pointer\n", pointer)
|
||||
@@ -68,6 +118,13 @@ func runConfigExplain(args []string, stdout, stderr io.Writer, opts Options) int
|
||||
return 0
|
||||
}
|
||||
|
||||
func newPromptKitInspection(cfg config.Config, opts Options) (*frameworkllm.PromptKitProfileInspector, error) {
|
||||
return frameworkllm.NewPromptKitProfileInspector(frameworkllm.PromptKitProfileInspectorConfig{
|
||||
Source: promptKitProfileSourceConfig(cfg),
|
||||
Assets: opts.promptKitAssets,
|
||||
})
|
||||
}
|
||||
|
||||
func runConfigValidate(args []string, stdout, stderr io.Writer, opts Options) int {
|
||||
fs := flag.NewFlagSet("config validate", flag.ContinueOnError)
|
||||
fs.SetOutput(io.Discard)
|
||||
|
||||
Reference in New Issue
Block a user