fix(copilot): refine ownership checks and command error handling

This commit is contained in:
Tam Nhu Tran
2026-03-04 17:18:44 +07:00
parent 1fd128e50f
commit 930d66fc0d
6 changed files with 27 additions and 39 deletions
-20
View File
@@ -45,23 +45,3 @@ export function normalizeCopilotSubcommand(token?: string): string | undefined {
export function isCopilotSubcommandToken(token?: string): boolean {
return Boolean(token) && COPILOT_SUBCOMMAND_TOKENS.includes(token as string);
}
/**
* Detect likely mistyped copilot flag aliases (e.g. `--statu`).
* This helps entrypoint routing show command help instead of falling through
* to profile execution for obvious copilot-command typos.
*/
export function isLikelyCopilotFlagAlias(token?: string): boolean {
if (!token || !token.startsWith('--') || token === '--') {
return false;
}
const alias = token.slice(2).toLowerCase();
if (!/^[a-z][a-z0-9-]*$/.test(alias)) {
return false;
}
return COPILOT_SUBCOMMANDS.some(
(subcommand) => subcommand.startsWith(alias) || alias.startsWith(subcommand)
);
}
+3 -4
View File
@@ -289,12 +289,11 @@ export async function stopDaemon(): Promise<{ success: boolean; error?: string }
try {
const ownership = verifyProcessOwnership(pid, (commandLine) => {
const lower = commandLine.toLowerCase();
const hasCopilotApiBinary = /(^|[\\/\s])copilot-api(\.cmd|\.exe)?(\s|$)/.test(lower);
const hasCopilotApiBinary = /copilot-api(\.cmd|\.exe)?/.test(lower);
const hasStartCommand = /\bstart\b/.test(lower);
const hasExpectedPort =
lower.includes(`--port ${configuredPort}`) || lower.includes(`--port=${configuredPort}`);
const hasPortArgument = /--port(?:\s+|=)\d+\b/.test(lower);
// copilot-api is launched as `... copilot-api start --port <n>`
return hasCopilotApiBinary && hasStartCommand && hasExpectedPort;
return hasCopilotApiBinary && hasStartCommand && hasPortArgument;
});
if (ownership === 'not-running') {
removePidFile();