mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-03 20:21:54 +00:00
fix(copilot): refine ownership checks and command error handling
This commit is contained in:
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user