@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 +1 -1
- package/src/daemon/daemon.ts +20 -35
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
|
|
|
@@ -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
|
-
//
|
|
350
|
-
//
|
|
351
|
-
const
|
|
352
|
-
if (
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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
|