Repository: microsoft/playwright
File: packages/playwright/src/mcp/terminal/program.ts (TypeScript)

Code before:
}

function configToFormattedArgs(config: SessionConfig['cli']): string[] {
  const args: string[] = [];
  const add = (flag: string, value: string | boolean | undefined) => {
    if (typeof value === 'boolean' && value)
      args.push(`--${flag}`);
    else if (typeof value === 'string')
      args.push(`--${flag}=${value}`);
  };
  add('browser', config.browser);
  add('config', config.config ? path.relative(process.cwd(), config.config) : undefined);
  add('extension', config.extension);
  add('headed', config.headed);
  add('in-memory', config.isolated);
  return args;
}

async function killAllDaemons(): Promise<void> {
  const platform = os.platform();
  let killed = 0;

  try {
    if (platform === 'win32') {
      // Windows: use wmic to find and taskkill to kill node processes with run-mcp-server
      const result = execSync('wmic process where "commandline like \'%run-mcp-server%\' and commandline like \'%--daemon-session%\'" get processid', { encoding: 'utf-8' });
      const pids = result.split('\n')
          .map(line => line.trim())
          .filter(line => /^\d+$/.test(line));
      for (const pid of pids) {
        try {
          execSync(`taskkill /F /PID ${pid}`, { stdio: 'ignore' });
          console.log(`Killed daemon process ${pid}`);
          killed++;
        } catch {
          // Process may have already exited
        }
      }
    } else {
      // Unix (Linux/macOS): use ps to find PIDs and kill them
      const result = execSync('ps aux', { encoding: 'utf-8' });
      const lines = result.split('\n');
      for (const line of lines) {
        if (line.includes('run-mcp-server') && line.includes('--daemon-session')) {
          const parts = line.trim().split(/\s+/);
          const pid = parts[1];
          if (pid && /^\d+$/.test(pid)) {
            try {
              process.kill(parseInt(pid, 10), 'SIGKILL');
              console.log(`Killed daemon process ${pid}`);
              killed++;

Review comment (suggestion):
According to the assistant, `wmic` is
```
Deprecated since Windows 10 21H1

Removed by default on newer Windows 11 builds

Replaced by PowerShell + CIM/WMI cmdlets
```

Code after:

const globalArgs = ['browser', 'config', 'extension', 'headed', 'help', 'in-memory', 'version', 'session'];

function hasGlobalArgs(args: MinimistArgs): boolean {
  return globalArgs.some(option => args[option] !== undefined);
}

function configToFormattedArgs(config: SessionConfig['cli']): string[] {
  const args: string[] = [];
  const add = (flag: string, value: string | boolean | undefined) => {
    if (typeof value === 'boolean' && value)
      args.push(`--${flag}`);
    else if (typeof value === 'string')
      args.push(`--${flag}=${value}`);
  };
  add('browser', config.browser);
  add('config', config.config ? path.relative(process.cwd(), config.config) : undefined);
  add('extension', config.extension);
  add('headed', config.headed);
  add('in-memory', config.isolated);
  return args;
}

async function killAllDaemons(): Promise<void> {
  const platform = os.platform();
  let killed = 0;

  try {
    if (platform === 'win32') {
      const result = execSync(
          `powershell -NoProfile -NonInteractive -Command `
          + `"Get-CimInstance Win32_Process `
          + `| Where-Object { $_.CommandLine -like '*run-mcp-server*' -and $_.CommandLine -like '*--daemon-session*' } `
          + `| ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue; $_.ProcessId }"`,
          { encoding: 'utf-8' }
      );
      const pids = result.split('\n')
          .map(line => line.trim())
          .filter(line => /^\d+$/.test(line));
      for (const pid of pids)
        console.log(`Killed daemon process ${pid}`);
      killed = pids.length;
    } else {
      const result = execSync('ps aux', { encoding: 'utf-8' });
      const lines = result.split('\n');
      for (const line of lines) {
        if (line.includes('run-mcp-server') && line.includes('--daemon-session')) {
          const parts = line.trim().split(/\s+/);
          const pid = parts[1];
          if (pid && /^\d+$/.test(pid)) {
            try {