@wipcomputer/wip-ldm-os 0.4.73-alpha.20 → 0.4.73-alpha.21
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/dist/bridge/mcp-server.js +22 -3
- package/package.json +1 -1
- package/src/bridge/mcp-server.ts +42 -4
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
22
22
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
23
23
|
import { createServer } from "http";
|
|
24
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
24
|
+
import { appendFileSync, mkdirSync, readFileSync } from "fs";
|
|
25
25
|
import { join } from "path";
|
|
26
26
|
import { homedir } from "os";
|
|
27
27
|
import { z } from "zod";
|
|
@@ -322,11 +322,30 @@ ${lines.join("\n")}` }] };
|
|
|
322
322
|
);
|
|
323
323
|
console.error(`wip-bridge: registered ${executableSkills.length} skill tools + oc_skills_list (${skills.length} total skills)`);
|
|
324
324
|
}
|
|
325
|
+
function resolveSessionName() {
|
|
326
|
+
try {
|
|
327
|
+
const ccSessionPath = join(
|
|
328
|
+
process.env.HOME || homedir(),
|
|
329
|
+
".claude",
|
|
330
|
+
"sessions",
|
|
331
|
+
`${process.ppid}.json`
|
|
332
|
+
);
|
|
333
|
+
const data = JSON.parse(readFileSync(ccSessionPath, "utf-8"));
|
|
334
|
+
if (data.name && typeof data.name === "string") {
|
|
335
|
+
return data.name;
|
|
336
|
+
}
|
|
337
|
+
} catch {
|
|
338
|
+
}
|
|
339
|
+
if (process.env.LDM_SESSION_NAME) {
|
|
340
|
+
return process.env.LDM_SESSION_NAME;
|
|
341
|
+
}
|
|
342
|
+
return "default";
|
|
343
|
+
}
|
|
325
344
|
async function main() {
|
|
326
345
|
const agentId = process.env.LDM_AGENT_ID || "cc-mini";
|
|
327
|
-
const sessionName =
|
|
346
|
+
const sessionName = resolveSessionName();
|
|
328
347
|
setSessionIdentity(agentId, sessionName);
|
|
329
|
-
console.error(`wip-bridge: session identity: ${agentId}:${sessionName}`);
|
|
348
|
+
console.error(`wip-bridge: session identity: ${agentId}:${sessionName} (resolved from ${sessionName !== "default" ? "CC session file or env" : "default"})`);
|
|
330
349
|
const session = registerBridgeSession();
|
|
331
350
|
if (session) {
|
|
332
351
|
console.error(`wip-bridge: registered session ${agentId}--${sessionName} (pid ${session.pid})`);
|
package/package.json
CHANGED
package/src/bridge/mcp-server.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
5
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
6
|
import { createServer, IncomingMessage, ServerResponse } from "node:http";
|
|
7
|
-
import { appendFileSync, mkdirSync } from "node:fs";
|
|
7
|
+
import { appendFileSync, mkdirSync, readFileSync } from "node:fs";
|
|
8
8
|
import { join } from "node:path";
|
|
9
9
|
import { homedir } from "node:os";
|
|
10
10
|
import { z } from "zod";
|
|
@@ -441,12 +441,50 @@ function registerSkillTools(skills: SkillInfo[]): void {
|
|
|
441
441
|
|
|
442
442
|
// ── Start ────────────────────────────────────────────────────────────
|
|
443
443
|
|
|
444
|
+
/**
|
|
445
|
+
* Resolve session name from Claude Code's session metadata.
|
|
446
|
+
*
|
|
447
|
+
* CC writes session files to ~/.claude/sessions/<pid>.json with the
|
|
448
|
+
* /rename label as the "name" field. The bridge MCP server is a child
|
|
449
|
+
* process of CC, so process.ppid gives the CC PID. Reading the parent's
|
|
450
|
+
* session file gives us the label automatically, no env var needed.
|
|
451
|
+
*
|
|
452
|
+
* Fallback chain: CC session file -> LDM_SESSION_NAME env -> "default"
|
|
453
|
+
*/
|
|
454
|
+
function resolveSessionName(): string {
|
|
455
|
+
// 1. Try CC session file for parent PID
|
|
456
|
+
try {
|
|
457
|
+
const ccSessionPath = join(
|
|
458
|
+
process.env.HOME || homedir(),
|
|
459
|
+
".claude",
|
|
460
|
+
"sessions",
|
|
461
|
+
`${process.ppid}.json`
|
|
462
|
+
);
|
|
463
|
+
const data = JSON.parse(readFileSync(ccSessionPath, "utf-8"));
|
|
464
|
+
if (data.name && typeof data.name === "string") {
|
|
465
|
+
return data.name;
|
|
466
|
+
}
|
|
467
|
+
} catch {
|
|
468
|
+
// No session file for parent PID. Normal for non-CC harnesses.
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// 2. Try env var (explicit override)
|
|
472
|
+
if (process.env.LDM_SESSION_NAME) {
|
|
473
|
+
return process.env.LDM_SESSION_NAME;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// 3. Default
|
|
477
|
+
return "default";
|
|
478
|
+
}
|
|
479
|
+
|
|
444
480
|
async function main() {
|
|
445
|
-
//
|
|
481
|
+
// Set session identity: auto-detect from CC session metadata, env, or default
|
|
446
482
|
const agentId = process.env.LDM_AGENT_ID || "cc-mini";
|
|
447
|
-
const sessionName =
|
|
483
|
+
const sessionName = resolveSessionName();
|
|
448
484
|
setSessionIdentity(agentId, sessionName);
|
|
449
|
-
console.error(`wip-bridge: session identity: ${agentId}:${sessionName}
|
|
485
|
+
console.error(`wip-bridge: session identity: ${agentId}:${sessionName} (resolved from ${
|
|
486
|
+
sessionName !== "default" ? "CC session file or env" : "default"
|
|
487
|
+
})`);
|
|
450
488
|
|
|
451
489
|
// Phase 2: Register session in ~/.ldm/sessions/
|
|
452
490
|
const session = registerBridgeSession();
|