(opts)
| 591 | // --------------------------------------------------------------------------- |
| 592 | |
| 593 | function startServer(opts) { |
| 594 | const { port: requestedPort, host, noBrowser, repair } = opts; |
| 595 | |
| 596 | // Step 1: Find Python |
| 597 | const fastPath = !repair && existsSync(venvPython()) && readMarker()?.requirements_hash === requirementsHash(); |
| 598 | |
| 599 | let python; |
| 600 | if (fastPath) { |
| 601 | // Skip the Python search header on fast path -- we already have a working venv |
| 602 | python = null; |
| 603 | } else { |
| 604 | log(`[1/3] Checking Python...`); |
| 605 | python = findPython(); |
| 606 | log(` Found Python ${python.version.raw} at ${python.exe}`); |
| 607 | } |
| 608 | |
| 609 | // Step 2: Ensure venv and deps |
| 610 | if (!python) { |
| 611 | // Fast path still needs a python reference for potential repair |
| 612 | python = findPython(); |
| 613 | } |
| 614 | const wasAlreadyReady = ensureVenv(python, repair); |
| 615 | |
| 616 | // Step 3: Config file |
| 617 | const configCreated = ensureEnvFile(); |
| 618 | |
| 619 | // Load .env into process.env for the spawned server |
| 620 | const dotenvVars = parseEnvFile(ENV_FILE); |
| 621 | |
| 622 | // Determine port |
| 623 | const port = requestedPort || findAvailablePort(); |
| 624 | |
| 625 | // Check for already-running instance |
| 626 | const existingPid = readPid(); |
| 627 | if (existingPid && isProcessAlive(existingPid)) { |
| 628 | log(`AutoForge is already running at http://${host}:${port}`); |
| 629 | log('Opening browser...'); |
| 630 | if (!noBrowser && !isHeadless()) { |
| 631 | openBrowser(`http://${host}:${port}`); |
| 632 | } |
| 633 | return; |
| 634 | } |
| 635 | |
| 636 | // Clean up stale PID file |
| 637 | if (existingPid) { |
| 638 | removePid(); |
| 639 | } |
| 640 | |
| 641 | // Show server startup step only on slow path |
| 642 | if (!wasAlreadyReady) { |
| 643 | log('[3/3] Starting server...'); |
| 644 | } |
| 645 | |
| 646 | if (configCreated) { |
| 647 | log(` Created config file: ~/.autoforge/.env`); |
| 648 | log(' Edit this file to configure API providers (Ollama, Vertex AI, z.ai)'); |
| 649 | log(''); |
| 650 | } |
no test coverage detected