@lightupai/polaris 0.0.25 → 0.0.26

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightupai/polaris",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "polaris": "bin/polaris",
@@ -13,6 +13,7 @@ interface SessionMapping {
13
13
  agent: string;
14
14
  slackChannel?: string;
15
15
  ws: WebSocket | null;
16
+ pendingMapping?: boolean; // true until a hook event maps the real CC session ID
16
17
  }
17
18
 
18
19
  function generateSessionName(): string {
@@ -232,6 +233,7 @@ export function startDaemon(port = Number(process.env.POLARIS_DAEMON_PORT ?? 432
232
233
  user: body.user,
233
234
  agent: agentId,
234
235
  ws: null,
236
+ pendingMapping: true, // waiting for hook event to map the real CC session ID
235
237
  };
236
238
  sessions.set(body.ccSessionId, mapping);
237
239
 
@@ -347,18 +349,24 @@ export function startDaemon(port = Number(process.env.POLARIS_DAEMON_PORT ?? 432
347
349
  if (!mapping || !mapping.project) {
348
350
  // CC session_id doesn't match any registered MCP client.
349
351
  // The MCP server uses a different UUID than CC's session_id.
350
- // Try to find the MCP session that this CC session belongs to.
351
- // Heuristic: if only one connected session exists, route to it.
352
- // Otherwise, drop the event — the user needs to /polaris join first.
353
- const connectedSessions = Array.from(sessions.values()).filter((m) => m.project);
354
- if (connectedSessions.length === 1) {
355
- mapping = connectedSessions[0];
356
- // Remember this mapping for future events from this CC session
352
+ // Match to a session with pendingMapping (most recent first).
353
+ const pending = Array.from(sessions.values()).filter((m) => m.project && m.pendingMapping);
354
+ if (pending.length > 0) {
355
+ // Map the CC session ID to the most recently connected pending session
356
+ mapping = pending[pending.length - 1];
357
+ mapping.pendingMapping = false;
358
+ // Register under the real CC session ID for future events
357
359
  sessions.set(ccSessionId, { ...mapping, ccSessionId });
360
+ console.error(`[daemon] Mapped CC session ${ccSessionId.slice(0, 8)} → ${mapping.project}/${mapping.session}`);
358
361
  } else {
359
- // Multiple or zero sessions — can't determine which one.
360
- // Drop silently; events will flow once /polaris join maps the session.
361
- return json({ status: connectedSessions.length > 0 ? "ambiguous" : "not_connected" });
362
+ // No pending sessions — try single-session fallback
363
+ const connectedSessions = Array.from(sessions.values()).filter((m) => m.project);
364
+ if (connectedSessions.length === 1) {
365
+ mapping = connectedSessions[0];
366
+ sessions.set(ccSessionId, { ...mapping, ccSessionId });
367
+ } else {
368
+ return json({ status: connectedSessions.length > 0 ? "ambiguous" : "not_connected" });
369
+ }
362
370
  }
363
371
  }
364
372