chainFor method

List<ModelRef>? chainFor(
  1. String role, {
  2. String? cwd,
  3. String? homeDir,
})

Resolves role's chain for the working directory cwd.

Resolution order (mirroring omp):

  1. the longest matching pathOverrides pattern that pins role;
  2. the top-level roles chain for role;
  3. for non-default roles, the default role's chain (omp's inherit-default-before-priority behavior);
  4. null when 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]);
}