Resolve linked prompts in their host context

This commit is contained in:
2026-11-10 20:17:54 +00:00
parent af0f9ac960
commit a8eb5aea4d
4 changed files with 53 additions and 14 deletions

View File

@@ -30,7 +30,6 @@ type AssetError struct{ Err error }
func (e *AssetError) Error() string { return e.Err.Error() }
func (e *AssetError) Unwrap() error { return e.Err }
const operatorFilesystem = "Audita operator prompts"
const operatorImports = `config:
imports:
- path: prompts.yml
@@ -57,7 +56,6 @@ func newRuntimeWithPromptFS(ctx context.Context, loaded *ck.Result[config.Config
return nil, &AssetError{Err: fmt.Errorf("discover embedded prompts: %w", err)}
}
sources := pk.ConfigurationSources{Underlays: []ck.Underlay{{Inputs: embedded}}}
var hostRoot string
for _, source := range loaded.Sources() {
if source.Layer != ck.LayerMain || source.ImportedFrom != nil {
continue
@@ -66,19 +64,24 @@ func newRuntimeWithPromptFS(ctx context.Context, loaded *ck.Result[config.Config
if !ok {
break
}
filesystem := ck.NewFilesystem(operatorFilesystem, context.FS)
sources.Underlays = append(sources.Underlays, ck.Underlay{Inputs: []ck.Input{{
Source: ck.Bytes("Audita automatic prompt imports", []byte(operatorImports)), Imports: true,
Filesystem: &ck.FilesystemContext{FS: &filesystem, Root: ".", BaseDir: context.BaseDir},
}}})
var filesystemContext ck.FilesystemContext
if source.Kind == ck.SourceKindFile && source.Path != "" {
hostRoot = filepath.Dir(source.Path)
base := filepath.Dir(source.Path)
root := base
if context.BaseDir != "." {
for range strings.Split(context.BaseDir, "/") {
hostRoot = filepath.Dir(hostRoot)
root = filepath.Dir(root)
}
}
filesystemContext = ck.FilesystemContext{Root: root, BaseDir: base}
} else {
filesystem := ck.NewFilesystem("Audita operator prompts", context.FS)
filesystemContext = ck.FilesystemContext{FS: &filesystem, Root: ".", BaseDir: context.BaseDir}
}
sources.Underlays = append(sources.Underlays, ck.Underlay{Inputs: []ck.Input{{
Source: ck.Bytes("Audita automatic prompt imports", []byte(operatorImports)), Imports: true,
Filesystem: &filesystemContext,
}}})
break
}
engine, err := pk.NewEngine(pk.Config{Sources: sources, HTTPClient: client}, pk.WithSchemaFS(responseschema.Filesystem(), responseschema.AssetRoot))
@@ -90,7 +93,7 @@ func newRuntimeWithPromptFS(ctx context.Context, loaded *ck.Result[config.Config
return nil, embeddedAssetOrInputError(ctx, embedded, fmt.Errorf("inspect prompt %s: %w", meta.PromptID, err))
}
}
paths, err := capturedSourcePaths(engine, hostRoot)
paths, err := capturedSourcePaths(engine)
if err != nil {
return nil, fmt.Errorf("inspect captured LLM sources: %w", err)
}