2026-10-04 00:56:14 +00:00
|
|
|
package llm
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"sort"
|
|
|
|
|
|
2026-11-23 04:23:59 +00:00
|
|
|
"gitea.maximumdirect.net/eric/audita/v4/internal/appconfig"
|
2026-11-10 16:13:53 +00:00
|
|
|
ck "go.maximumdirect.net/configkit"
|
|
|
|
|
pk "go.maximumdirect.net/promptkit"
|
2026-10-04 00:56:14 +00:00
|
|
|
)
|
|
|
|
|
|
2026-11-23 04:23:59 +00:00
|
|
|
func capturedSourcePaths(loaded *ck.Result[appconfig.Config]) ([]string, error) {
|
|
|
|
|
sources := loaded.Sources()
|
2026-11-10 20:35:35 +00:00
|
|
|
hostByID := make(map[string]string, len(sources))
|
2026-10-04 00:56:14 +00:00
|
|
|
paths := make(map[string]struct{}, len(sources))
|
|
|
|
|
for _, source := range sources {
|
2026-11-10 20:35:35 +00:00
|
|
|
if source.Kind == ck.SourceKindFile && source.Path != "" {
|
|
|
|
|
hostByID[source.ID] = source.Path
|
|
|
|
|
paths[source.Path] = struct{}{}
|
2026-10-04 00:56:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-11-23 04:23:59 +00:00
|
|
|
metadata := loaded.Metadata()
|
|
|
|
|
capture := func(base ck.Path, prompts []pk.PromptSettings) {
|
2026-11-10 20:35:35 +00:00
|
|
|
for i, prompt := range prompts {
|
|
|
|
|
messages := base.Index(i).Key("messages")
|
|
|
|
|
for j, message := range prompt.Messages {
|
|
|
|
|
if message.ContentFile == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
field, ok := metadata.Lookup(messages.Index(j).Key("content_file"))
|
2026-11-23 04:23:59 +00:00
|
|
|
if !ok {
|
2026-11-10 20:35:35 +00:00
|
|
|
continue
|
|
|
|
|
}
|
2026-11-23 04:23:59 +00:00
|
|
|
for _, location := range field.Origin.Locations {
|
|
|
|
|
if host := hostByID[location.SourceID]; host != "" {
|
|
|
|
|
paths[filepath.Join(filepath.Dir(host), filepath.FromSlash(*message.ContentFile))] = struct{}{}
|
|
|
|
|
}
|
2026-11-10 20:35:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-11-10 16:13:53 +00:00
|
|
|
}
|
2026-11-10 20:35:35 +00:00
|
|
|
}
|
2026-11-23 04:23:59 +00:00
|
|
|
capture(ck.Keys("promptkit", "prompts"), loaded.Config.PromptKit.Prompts)
|
|
|
|
|
for name, collection := range loaded.Config.PromptKit.Collections {
|
|
|
|
|
capture(ck.Keys("promptkit", "collections", name, "prompts"), collection.Prompts)
|
2026-10-04 00:56:14 +00:00
|
|
|
}
|
|
|
|
|
result := make([]string, 0, len(paths))
|
|
|
|
|
for path := range paths {
|
|
|
|
|
result = append(result, path)
|
|
|
|
|
}
|
|
|
|
|
sort.Strings(result)
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|