Skip to content

Commit a31974d

Browse files
lpcoxCopilot
andauthored
Update src/cli.ts
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 4c19151 commit a31974d

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/cli.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,13 +1951,35 @@ program
19511951
emitCliProxyStatusLogs(config, logger.info.bind(logger), logger.warn.bind(logger));
19521952

19531953
// Warn if a classic PAT is combined with COPILOT_MODEL (Copilot CLI 1.0.21+ incompatibility)
1954-
// Check if COPILOT_MODEL is set via --env/-e flags or host env (when --env-all is active)
1955-
const copilotModelFromFlags = Object.prototype.hasOwnProperty.call(additionalEnv, 'COPILOT_MODEL');
1956-
const copilotModelInHostEnv =
1957-
config.envAll && Object.prototype.hasOwnProperty.call(process.env, 'COPILOT_MODEL');
1954+
const hasCopilotModelInEnvFiles = (envFile: unknown): boolean => {
1955+
const envFiles = Array.isArray(envFile) ? envFile : envFile ? [envFile] : [];
1956+
for (const candidate of envFiles) {
1957+
if (typeof candidate !== 'string' || candidate.trim() === '') continue;
1958+
try {
1959+
const envFilePath = path.isAbsolute(candidate) ? candidate : path.resolve(process.cwd(), candidate);
1960+
const envFileContents = fs.readFileSync(envFilePath, 'utf8');
1961+
for (const line of envFileContents.split(/\r?\n/)) {
1962+
const trimmedLine = line.trim();
1963+
if (!trimmedLine || trimmedLine.startsWith('#')) continue;
1964+
if (/^(?:export\s+)?COPILOT_MODEL\s*=/.test(trimmedLine)) {
1965+
return true;
1966+
}
1967+
}
1968+
} catch {
1969+
// Ignore unreadable env files here; this check is only for a pre-flight warning.
1970+
}
1971+
}
1972+
return false;
1973+
};
1974+
1975+
// Warn if a classic PAT is combined with COPILOT_MODEL (Copilot CLI 1.0.21+ incompatibility)
1976+
// Check if COPILOT_MODEL is set via --env/-e flags, host env (when --env-all is active), or --env-file
1977+
const copilotModelFromFlags = !!(additionalEnv['COPILOT_MODEL']);
1978+
const copilotModelInHostEnv = !!(config.envAll && process.env.COPILOT_MODEL);
1979+
const copilotModelInEnvFile = hasCopilotModelInEnvFiles((config as { envFile?: unknown }).envFile);
19581980
warnClassicPATWithCopilotModel(
19591981
config.copilotGithubToken?.startsWith('ghp_') ?? false,
1960-
copilotModelFromFlags || copilotModelInHostEnv,
1982+
copilotModelFromFlags || copilotModelInHostEnv || copilotModelInEnvFile,
19611983
logger.warn.bind(logger)
19621984
);
19631985

0 commit comments

Comments
 (0)