Auto-Discovery Resolution Chain#
Overview#
When no -f flag is provided, scafctl automatically searches for solution files
using a unified resolution chain. This design introduces risk-based ambiguity
handling and adds taskfile.yaml/taskfile.yml as discoverable file names.
Problem Statement#
- Inconsistent discovery – Each CLI command implemented its own discovery logic with slightly different behavior, making it hard to predict which file would be used.
- Silent ambiguity – When multiple solution files existed in a project
(e.g.,
solution.yamlandactions.yaml), the first match was used with no feedback to the user. - Destructive command risk – Commands like
buildthat publish artifacts should not silently pick an ambiguous file – the consequences of choosing wrong are harder to reverse. - Missing taskfile support – Projects using
taskfile.yamlas their solution filename had to always specify-f.
Design#
Unified Resolution Chain#
All commands pick the solution source with Router.Select() from
pkg/solution/load, which implements this chain:
- Explicit flag – If
-fis provided, use it directly (no discovery). - Unambiguous positional argument – If the first positional arg is a URL,
registry reference, or versioned name (
app@1.2.3), or – underArgsAreNamesOrCatalogwhen--catalogor--versionis explicitly passed – a bare name, use it. Malformed reference syntax (my-app@,oci://, unsupported schemes) fails immediately withsource.ErrInvalidRef. - Auto-discovery – Search configured folders and file names in priority order, returning all matches.
- Catalog fallback – With
ArgsAreNamesOrCatalog, a valid catalog bare name (catalog.IsValidName) in the first positional argument is used as a catalog reference when nothing is discovered. CamelCase or underscore resolver names (wifToken,git_version) are not valid catalog names and surfaceErrNoSolutionFounddirectly.
router := load.NewRouterFromContext(ctx, lgr,
load.CLIRouterOptions(stdin, noCache, settings.DiscoveryModeDefault)...)
sel, err := router.Select(ctx, file, args, load.ArgsAreNamesOrCatalog)
if err != nil {
return err
}
ms, err := router.SelectionLoader(sel).Load(ctx, sel.Source)SelectionLoader reuses the matches found by Select, so discovery runs once.
Discovery Risk Levels#
The DiscoveryRisk type (set with load.WithDiscoveryRisk, or passed to
Selection.DiscoveredPath) controls how multi-match ambiguity is handled:
| Risk Level | Behavior | Commands |
|---|---|---|
DiscoveryRiskLow | Use first match, emit warning about others to stderr | run, lint, test, render |
DiscoveryRiskHigh | Return load.ErrAmbiguousSolution listing all matches, require -f | build |
This ensures read-only or easily-reversible commands remain convenient while destructive operations require explicit intent.
File Name Search Order#
The search combines folder prefixes with file names in this order:
Folder prefixes (checked in order):
scafctl/– conventional project subfolder.scafctl/– hidden project subfolder- (current directory) – root
File names (checked in order per folder):
solution.yamlsolution.ymlscafctl.yamlscafctl.ymlsolution.jsonscafctl.jsontaskfile.yamltaskfile.yml
This produces 24 candidate paths checked in priority order (3 folders x 8 names).
Action file names (actions.yaml, actions.yml, or embedder-configured
ActionDiscoveryFileNames) are not included in the default 24-path list:
DiscoveryModeDefault/DiscoveryModeSolution(e.g.,lint,render,run solution) – Searches only the 24 solution/taskfile candidate paths.DiscoveryModeAction(run action,run resolver --action,validate resolver --action) – Searches action files first across all folders, with solution files as fallback (taskfiles excluded).DiscoveryModeResolver(run resolver,validate resolver) – Searches the 24 solution/taskfile candidate paths first across all folders; only when zero solution files exist does it fall back to searching action files across the 3 folders. Coexistingsolution.yamlandactions.yamlfiles therefore never trigger multi-match ambiguity warnings.
Taskfile Content Check#
taskfile.yaml/taskfile.yml are also the default file names of other task
runners (go-task), so discovery reads each taskfile candidate and skips it when
it parses as YAML but carries none of the recognized solution headers:
apiVersion: scafctl.io/v1, kind: Solution, or a non-null spec. Files
that fail to parse, or that carry a recognized header (even only
kind: Solution or a non-null spec), are kept so a broken solution still
loads and reports its real validation error. The skip is reported under
--verbose. An explicit -f skips discovery entirely and keeps the strict
error.
Discover vs Load#
| Method | Behavior |
|---|---|
DiscoverLoader.Discover() | Returns all matches in priority order, or ErrNoSolutionFound |
DiscoverLoader.Load() | Discovers and loads one match, applying the risk level |
Candidate paths are resolved against the context working directory (--cwd).
MCP Server Integration#
The MCP server’s discoverSolutionFiles() calls findSolutionFiles(), which
runs DiscoverLoader.Discover() in the working directory and in each MCP client
workspace root and deduplicates the results. This reports all discoverable
solutions to AI clients, enabling them to present the full set of available
solutions in a workspace.
Behavior Examples#
The Using ... and multi-match messages below are emitted via writer.Verbosef
and only appear when --verbose is enabled.
Single match (common case)#
$ scafctl lint --verbose
Using solution.yaml
...Multiple matches, low-risk command#
$ scafctl lint --verbose
Using solution.yaml
WARNING: Multiple solution files found (also: taskfile.yaml); using first match
...Multiple matches, high-risk command#
$ scafctl package solution
Error: multiple solution files found: solution.yaml, taskfile.yaml; use -f/--file to specify which oneAPI#
package load
type DiscoveryRisk int
const (
DiscoveryRiskLow DiscoveryRisk = iota // warn on ambiguity
DiscoveryRiskHigh // error on ambiguity
)
type Discovery struct {
Path string
IsActionFile bool
AlternatePath string
}
func NewDiscoverLoader(files *FileLoader, binaryName string, opts ...DiscoverOption) *DiscoverLoader
func WithDiscoveryMode(mode settings.DiscoveryMode) DiscoverOption
func WithCustomActionFiles(names []string) DiscoverOption
func WithDiscoveryRisk(risk DiscoveryRisk) DiscoverOption
func DiscoverPath(ctx context.Context, risk DiscoveryRisk, opts ...DiscoverOption) (string, error)
func (l *DiscoverLoader) Discover(ctx context.Context) ([]Discovery, error)
func (l *DiscoverLoader) Load(ctx context.Context, c source.Classification) (*MaterializedSolution, error)
func (r *Router) Select(ctx context.Context, explicit string, args []string, policy ArgPolicy, opts ...source.Option) (Selection, error)
func (r *Router) SelectionLoader(s Selection) Loader
func (s Selection) DiscoveredPath(risk DiscoveryRisk) (string, error)Testing#
- Unit tests in
pkg/solution/load/discover_test.goandpkg/solution/load/select_test.gocover the resolution chain, risk levels, and edge cases (no files, single match, multi-match). - Integration tests in
tests/integration/cli_test.goverify end-to-end discovery oftaskfile.yamland multi-match warning output.