@arcote.tech/arc-cli 0.7.6 → 0.7.8

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.
@@ -600,7 +600,25 @@ export async function startPlatformServer(
600
600
  // Context available — use createArcServer with platform handlers on top.
601
601
  // `resolveDbAdapterFactory` picks SQLite or Postgres based on DATABASE_URL.
602
602
  const dbPath = opts.dbPath || join(ws.arcDir, "data", "arc.db");
603
- const dbAdapterFactory = await resolveDbAdapterFactory(dbPath);
603
+ const baseDbFactory = await resolveDbAdapterFactory(dbPath);
604
+
605
+ // Wrap the DB adapter for per-transaction spans when telemetry is on.
606
+ // Done here (not in arc-host) so arc-host stays free of arc-otel runtime
607
+ // imports — duplicate @opentelemetry/api copies silently drop spans.
608
+ let dbAdapterFactory = baseDbFactory;
609
+ if (telemetry) {
610
+ // Pull wrapDbAdapter from `/server` (not the root export) so Bun
611
+ // doesn't double-bundle arc-otel for the CLI bundle. Both /server
612
+ // and / share telemetry.ts but split bundling otherwise.
613
+ const { wrapDbAdapter } = await import("@arcote.tech/arc-otel/server");
614
+ const dbSystem: "postgresql" | "sqlite" = process.env.DATABASE_URL
615
+ ? "postgresql"
616
+ : "sqlite";
617
+ dbAdapterFactory = async (ctx: any) => {
618
+ const a = await baseDbFactory(ctx);
619
+ return wrapDbAdapter(a, telemetry, dbSystem);
620
+ };
621
+ }
604
622
 
605
623
  const arcServer = await createArcServer({
606
624
  context,
@@ -74,17 +74,39 @@ export async function startPlatform(
74
74
 
75
75
  // 3. Start the platform server. Cache headers + SSE behaviour are
76
76
  // controlled inside the server by `devMode`; we just pass the flag.
77
- const platform = await startPlatformServer({
78
- ws,
79
- port,
80
- manifest,
81
- context,
82
- moduleAccess,
83
- dbPath,
84
- devMode,
85
- });
77
+ // In dev mode, if the port is busy, try incrementing up to 20 times.
78
+ const MAX_PORT_ATTEMPTS = devMode ? 20 : 1;
79
+ let platform: PlatformServer | null = null;
80
+ let actualPort = port;
81
+ for (let i = 0; i < MAX_PORT_ATTEMPTS; i++) {
82
+ try {
83
+ platform = await startPlatformServer({
84
+ ws,
85
+ port: actualPort,
86
+ manifest,
87
+ context,
88
+ moduleAccess,
89
+ dbPath,
90
+ devMode,
91
+ });
92
+ break;
93
+ } catch (e) {
94
+ const msg = (e as Error).message || "";
95
+ const inUse =
96
+ msg.includes("EADDRINUSE") ||
97
+ msg.includes("address already in use") ||
98
+ msg.includes("in use");
99
+ if (!inUse || i === MAX_PORT_ATTEMPTS - 1) throw e;
100
+ log(`Port ${actualPort} in use, trying ${actualPort + 1}...`);
101
+ actualPort++;
102
+ }
103
+ }
104
+ if (!platform) {
105
+ err(`Failed to bind a free port starting from ${port}`);
106
+ process.exit(1);
107
+ }
86
108
 
87
- ok(`Server on http://localhost:${port}`);
109
+ ok(`Server on http://localhost:${actualPort}`);
88
110
  if (platform.contextHandler) {
89
111
  ok("Commands, queries, WebSocket — all on same port");
90
112
  }