@lightupai/polaris 0.0.24 → 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.24",
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
 
@@ -346,43 +348,26 @@ export function startDaemon(port = Number(process.env.POLARIS_DAEMON_PORT ?? 432
346
348
  let mapping = sessions.get(ccSessionId);
347
349
  if (!mapping || !mapping.project) {
348
350
  // CC session_id doesn't match any registered MCP client.
349
- // This CC session hasn't been /polaris join'd yet.
350
- // Auto-create a new Polaris session in the same project as an existing session.
351
- const connectedSessions = Array.from(sessions.values()).filter((m) => m.project);
352
- if (connectedSessions.length === 0) {
353
- return json({ status: "not_connected" });
354
- }
355
-
356
- // Use the first connected session as a template for project/user/agent
357
- const template = connectedSessions[0];
358
- const newSession = generateSessionName();
359
-
360
- // Create the session on the API
361
- const serviceUrl = getServiceUrl();
362
- try {
363
- const createRes = await fetch(`${serviceUrl}/projects/${template.project}/sessions`, {
364
- method: "POST",
365
- headers: await authHeaders(),
366
- body: JSON.stringify({ name: newSession, driver: template.user }),
367
- });
368
- if (!createRes.ok && createRes.status !== 409) {
369
- return json({ status: "session_create_failed" });
351
+ // The MCP server uses a different UUID than CC's session_id.
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
359
+ sessions.set(ccSessionId, { ...mapping, ccSessionId });
360
+ console.error(`[daemon] Mapped CC session ${ccSessionId.slice(0, 8)} → ${mapping.project}/${mapping.session}`);
361
+ } else {
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" });
370
369
  }
371
- } catch {
372
- return json({ status: "api_unreachable" });
373
370
  }
374
-
375
- mapping = {
376
- ccSessionId,
377
- project: template.project,
378
- session: newSession,
379
- user: template.user,
380
- agent: template.agent,
381
- slackChannel: template.slackChannel,
382
- ws: null,
383
- };
384
- sessions.set(ccSessionId, mapping);
385
- console.error(`[daemon] Auto-created session ${template.project}/${newSession} for CC session ${ccSessionId.slice(0, 8)}`);
386
371
  }
387
372
 
388
373
  // Determine sender: human for prompts, agent for everything else