* Determines the configuration source using the specification's precedence rules: * 1. CLI --config flag (highest priority) * 2. Saved config URI (if no CLI flag) * 3. Default resolution (if no flag and no saved URI)
( authConfig: AuthConfig, cliConfigPath: string | undefined, _isHeadless: boolean | undefined, )
| 82 | * 3. Default resolution (if no flag and no saved URI) |
| 83 | */ |
| 84 | function determineConfigSource( |
| 85 | authConfig: AuthConfig, |
| 86 | cliConfigPath: string | undefined, |
| 87 | _isHeadless: boolean | undefined, |
| 88 | ): ConfigSource { |
| 89 | // Priority 1: CLI --config flag |
| 90 | if (cliConfigPath) { |
| 91 | return { type: "cli-flag", path: cliConfigPath }; |
| 92 | } |
| 93 | |
| 94 | // Priority 2: Check for default config.yaml, then fallback to default config |
| 95 | const defaultConfigPath = path.join(env.continueHome, "config.yaml"); |
| 96 | if (fs.existsSync(defaultConfigPath)) { |
| 97 | return { type: "local-config-yaml" }; |
| 98 | } |
| 99 | return { type: "remote-default-config" }; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Loads configuration from the determined source with appropriate error handling |