chainFor method
Resolves role's chain for the working directory cwd.
Resolution order (mirroring omp):
- the longest matching pathOverrides pattern that pins
role; - the top-level roles chain for
role; - for non-default roles, the
defaultrole's chain (omp's inherit-default-before-priority behavior); nullwhen nothing applies (the caller falls back to its legacy single-model wiring).
Implementation
List<ModelRef>? chainFor(String role, {String? cwd, String? homeDir}) {
if (!modelRoleIds.contains(role)) {
throw ConfigException(
'unknown model role "$role" — supported roles: '
'${modelRoleIds.join(', ')}',
);
}
if (cwd != null) {
final matching =
pathOverrides
.where(
(override) =>
override.roles.containsKey(role) &&
pathPatternMatches(override.pattern, cwd, homeDir: homeDir),
)
.toList()
..sort((a, b) => b.pattern.length.compareTo(a.pattern.length));
if (matching.isNotEmpty) return matching.first.roles[role];
}
return roles[role] ??
(role == defaultModelRole ? null : roles[defaultModelRole]);
}