()
| 583 | extraCliArgs: [] |
| 584 | } : undefined; |
| 585 | export async function main() { |
| 586 | profileCheckpoint('main_function_start'); |
| 587 | |
| 588 | // SECURITY: Prevent Windows from executing commands from current directory |
| 589 | // This must be set before ANY command execution to prevent PATH hijacking attacks |
| 590 | // See: https://docs.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-searchpathw |
| 591 | process.env.NoDefaultCurrentDirectoryInExePath = '1'; |
| 592 | |
| 593 | // Initialize warning handler early to catch warnings |
| 594 | initializeWarningHandler(); |
| 595 | process.on('exit', () => { |
| 596 | resetCursor(); |
| 597 | }); |
| 598 | process.on('SIGINT', () => { |
| 599 | // In print mode, print.ts registers its own SIGINT handler that aborts |
| 600 | // the in-flight query and calls gracefulShutdown; skip here to avoid |
| 601 | // preempting it with a synchronous process.exit(). |
| 602 | if (process.argv.includes('-p') || process.argv.includes('--print')) { |
| 603 | return; |
| 604 | } |
| 605 | process.exit(0); |
| 606 | }); |
| 607 | profileCheckpoint('main_warning_handler_initialized'); |
| 608 | |
| 609 | // Check for cc:// or cc+unix:// URL in argv — rewrite so the main command |
| 610 | // handles it, giving the full interactive TUI instead of a stripped-down subcommand. |
| 611 | // For headless (-p), we rewrite to the internal `open` subcommand. |
| 612 | if (feature('DIRECT_CONNECT')) { |
| 613 | const rawCliArgs = process.argv.slice(2); |
| 614 | const ccIdx = rawCliArgs.findIndex(a => a.startsWith('cc://') || a.startsWith('cc+unix://')); |
| 615 | if (ccIdx !== -1 && _pendingConnect) { |
| 616 | const ccUrl = rawCliArgs[ccIdx]!; |
| 617 | const { |
| 618 | parseConnectUrl |
| 619 | } = await import('./server/parseConnectUrl.js'); |
| 620 | const parsed = parseConnectUrl(ccUrl); |
| 621 | _pendingConnect.dangerouslySkipPermissions = rawCliArgs.includes('--dangerously-skip-permissions'); |
| 622 | if (rawCliArgs.includes('-p') || rawCliArgs.includes('--print')) { |
| 623 | // Headless: rewrite to internal `open` subcommand |
| 624 | const stripped = rawCliArgs.filter((_, i) => i !== ccIdx); |
| 625 | const dspIdx = stripped.indexOf('--dangerously-skip-permissions'); |
| 626 | if (dspIdx !== -1) { |
| 627 | stripped.splice(dspIdx, 1); |
| 628 | } |
| 629 | process.argv = [process.argv[0]!, process.argv[1]!, 'open', ccUrl, ...stripped]; |
| 630 | } else { |
| 631 | // Interactive: strip cc:// URL and flags, run main command |
| 632 | _pendingConnect.url = parsed.serverUrl; |
| 633 | _pendingConnect.authToken = parsed.authToken; |
| 634 | const stripped = rawCliArgs.filter((_, i) => i !== ccIdx); |
| 635 | const dspIdx = stripped.indexOf('--dangerously-skip-permissions'); |
| 636 | if (dspIdx !== -1) { |
| 637 | stripped.splice(dspIdx, 1); |
| 638 | } |
| 639 | process.argv = [process.argv[0]!, process.argv[1]!, ...stripped]; |
| 640 | } |
| 641 | } |
| 642 | } |
nothing calls this directly
no test coverage detected