@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 +1 -1
- package/src/daemon/daemon.ts +18 -10
package/package.json
CHANGED
package/src/daemon/daemon.ts
CHANGED
|
@@ -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
|
-
//
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
mapping =
|
|
356
|
-
//
|
|
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
|
-
//
|
|
360
|
-
|
|
361
|
-
|
|
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
|
|