@pixelbyte-software/pixcode 1.49.5 → 1.49.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -455,7 +455,39 @@ function scheduleCleanup(job) {
455
455
  }, FINISHED_TTL_MS);
456
456
  }
457
457
 
458
- function spawnLogged(job, command, args, options) {
458
+ function isWindowsEpermSpawnError(error) {
459
+ return process.platform === 'win32' && (
460
+ error?.code === 'EPERM' ||
461
+ /spawn\s+EPERM/i.test(String(error?.message || ''))
462
+ );
463
+ }
464
+
465
+ function isWindowsPowerShellCommand(command) {
466
+ if (process.platform !== 'win32') return false;
467
+ const name = path.basename(String(command || '')).toLowerCase();
468
+ return name === 'powershell.exe' || name === 'powershell' || name === 'pwsh.exe' || name === 'pwsh';
469
+ }
470
+
471
+ function quoteWindowsCmdArg(value) {
472
+ const text = String(value ?? '');
473
+ if (!text) return '""';
474
+ if (!/[\s"&|<>^()]/.test(text)) return text;
475
+ return `"${text.replace(/"/g, '\\"')}"`;
476
+ }
477
+
478
+ function windowsCmdFallbackCommand(command, args) {
479
+ return {
480
+ command: process.env.ComSpec || 'cmd.exe',
481
+ args: [
482
+ '/d',
483
+ '/s',
484
+ '/c',
485
+ [command, ...args].map(quoteWindowsCmdArg).join(' '),
486
+ ],
487
+ };
488
+ }
489
+
490
+ function spawnLoggedOnce(job, command, args, options) {
459
491
  appendLog(job, 'meta', `$ ${command} ${args.join(' ')}\n`);
460
492
  const child = spawn(command, args, {
461
493
  ...options,
@@ -463,8 +495,8 @@ function spawnLogged(job, command, args, options) {
463
495
  windowsHide: true,
464
496
  });
465
497
  job.child = child;
466
- child.stdout.on('data', (buf) => appendLog(job, 'stdout', buf.toString()));
467
- child.stderr.on('data', (buf) => appendLog(job, 'stderr', buf.toString()));
498
+ child.stdout?.on('data', (buf) => appendLog(job, 'stdout', buf.toString()));
499
+ child.stderr?.on('data', (buf) => appendLog(job, 'stderr', buf.toString()));
468
500
  return new Promise((resolve, reject) => {
469
501
  child.on('error', reject);
470
502
  child.on('close', (code, signal) => {
@@ -477,6 +509,20 @@ function spawnLogged(job, command, args, options) {
477
509
  });
478
510
  }
479
511
 
512
+ async function spawnLogged(job, command, args, options) {
513
+ try {
514
+ return await spawnLoggedOnce(job, command, args, options);
515
+ } catch (error) {
516
+ if (!isWindowsEpermSpawnError(error) || !isWindowsPowerShellCommand(command)) {
517
+ throw error;
518
+ }
519
+
520
+ appendLog(job, 'stderr', 'PowerShell direct launch was blocked by Windows (EPERM); retrying through cmd.exe without elevation.\n');
521
+ const fallback = windowsCmdFallbackCommand(command, args);
522
+ return spawnLoggedOnce(job, fallback.command, fallback.args, options);
523
+ }
524
+ }
525
+
480
526
  async function runConfigureScript(job, env, appRoot) {
481
527
  const configureScript = path.join(appRoot, 'scripts', 'hermes', 'configure-pixcode-mcp.mjs');
482
528
  if (!fs.existsSync(configureScript)) {