()
| 620 | // ═══════════════════════════════════════════════════════════════════════════ |
| 621 | |
| 622 | async function main() { |
| 623 | const args = parseArgs(); |
| 624 | const config = await buildConfig(args); |
| 625 | |
| 626 | console.log(""); |
| 627 | console.log( |
| 628 | `${c.cyan}${c.bold}Agent Canvas Static-frontend Development Stack${c.reset}`, |
| 629 | ); |
| 630 | console.log(""); |
| 631 | |
| 632 | // Setup phase (1/3) |
| 633 | checkPrerequisites(); |
| 634 | |
| 635 | // Ensure isolated state dirs (same as dev-with-automation). |
| 636 | const { mkdirSync } = await import("node:fs"); |
| 637 | for (const dir of [ |
| 638 | config.stateDir, |
| 639 | join(config.stateDir, "dev_conversations"), |
| 640 | join(config.stateDir, "workspaces"), |
| 641 | join(config.stateDir, "bash_events"), |
| 642 | join(config.stateDir, "storage"), |
| 643 | config.tmuxTmpDir, |
| 644 | ]) { |
| 645 | mkdirSync(dir, { recursive: true }); |
| 646 | } |
| 647 | |
| 648 | // Build phase (2/3): block until the SPA is ready to serve. |
| 649 | buildFrontend(config, args); |
| 650 | |
| 651 | // Service phase (3/3) |
| 652 | logStep("3/3", "Starting services..."); |
| 653 | |
| 654 | // The agent-server skip-loads any conversation whose `owner_lease.json` |
| 655 | // is held by a different `owner_instance_id` and not yet expired (45 s |
| 656 | // TTL). If a previous agent-server (e.g. from `npm run dev`) was killed |
| 657 | // ungracefully — or we restart faster than the lease TTL — every |
| 658 | // conversation gets hidden until those stale leases age out, which |
| 659 | // looks like "the new agent-server doesn't inherit my conversations". |
| 660 | // Bail out if a live agent-server is already bound to our port (we'd |
| 661 | // collide anyway), otherwise unlink the stale leases so the new server |
| 662 | // can claim ownership immediately. |
| 663 | if (await isPortBusy(config.agentServerPort)) { |
| 664 | logError( |
| 665 | `Port ${config.agentServerPort} is already in use — another ` + |
| 666 | `agent-server is running. Stop it (e.g. quit \`npm run dev\`) ` + |
| 667 | `before running dev:static.`, |
| 668 | ); |
| 669 | process.exit(1); |
| 670 | } |
| 671 | const conversationsPath = join(config.stateDir, "dev_conversations"); |
| 672 | const cleared = releaseStaleConversationLeases(conversationsPath); |
| 673 | if (cleared > 0) { |
| 674 | logService( |
| 675 | "agent-server", |
| 676 | `Released ${cleared} stale conversation lease(s) so the new ` + |
| 677 | `agent-server can resume ownership.`, |
| 678 | c.dim, |
| 679 | ); |
no test coverage detected