fix super admin claude: host cwd, host mcp config paths
Capture HOST_HOME before user-instance overrides process.env.HOME so Super Admin spawns claude in /home/pastilhas. Generate separate MCP configs for sandbox (sandbox paths) and host (real filesystem paths), pick based on role at spawn time. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -53,34 +53,54 @@ function refreshClaudeMd(): void {
|
||||
|
||||
// ── MCP config ──
|
||||
|
||||
function generateMcpConfig(): string {
|
||||
type McpPaths = { sandboxPath: string; hostPath: string };
|
||||
|
||||
function generateMcpConfig(): McpPaths {
|
||||
const contextDir = join(DATA_PATH, email!, '.container-context');
|
||||
mkdirSync(contextDir, { recursive: true });
|
||||
const configPath = join(contextDir, 'mcp.json');
|
||||
|
||||
// Inside the sandbox, user data is mounted at SANDBOX_DATA (/data)
|
||||
// Global tools stay at their original paths (mounted read-only at same path)
|
||||
const sandboxUserToolsDir = `${SANDBOX_DATA}/tools`;
|
||||
const toolsDirs = [globalToolsDir, ...(existsSync(userToolsDir) ? [sandboxUserToolsDir] : [])].join(':');
|
||||
const userRoot = join(DATA_PATH, email!);
|
||||
|
||||
const config = {
|
||||
// Sandbox config (paths relative to /data mount)
|
||||
const sandboxToolsDirs = [globalToolsDir, ...(existsSync(userToolsDir) ? [`${SANDBOX_DATA}/tools`] : [])].join(':');
|
||||
const sandboxConfig = {
|
||||
mcpServers: {
|
||||
'officer-tools': {
|
||||
type: 'stdio',
|
||||
command: 'bun',
|
||||
args: ['run', MCP_SERVER_SCRIPT],
|
||||
env: {
|
||||
PI_TOOLS_DIRS: toolsDirs,
|
||||
PI_TOOLS_DIRS: sandboxToolsDirs,
|
||||
OFFICER_EMAIL_DB: `${SANDBOX_DATA}/emails.db`,
|
||||
MCP_TOOLS_LOG: `${SANDBOX_DATA}/logs/mcp-tools.log`,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
writeFileSync(join(contextDir, 'mcp.json'), JSON.stringify(sandboxConfig));
|
||||
|
||||
writeFileSync(configPath, JSON.stringify(config));
|
||||
// Return the sandbox path (config file is inside user data, mounted at /data)
|
||||
return `${SANDBOX_DATA}/.container-context/mcp.json`;
|
||||
// Host config (real filesystem paths, for Super Admin)
|
||||
const hostToolsDirs = [globalToolsDir, ...(existsSync(userToolsDir) ? [userToolsDir] : [])].join(':');
|
||||
const hostConfig = {
|
||||
mcpServers: {
|
||||
'officer-tools': {
|
||||
type: 'stdio',
|
||||
command: 'bun',
|
||||
args: ['run', MCP_SERVER_SCRIPT],
|
||||
env: {
|
||||
PI_TOOLS_DIRS: hostToolsDirs,
|
||||
OFFICER_EMAIL_DB: join(userRoot, 'emails.db'),
|
||||
MCP_TOOLS_LOG: join(userRoot, 'logs', 'mcp-tools.log'),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
writeFileSync(join(contextDir, 'mcp-host.json'), JSON.stringify(hostConfig));
|
||||
|
||||
return {
|
||||
sandboxPath: `${SANDBOX_DATA}/.container-context/mcp.json`,
|
||||
hostPath: join(contextDir, 'mcp-host.json'),
|
||||
};
|
||||
}
|
||||
|
||||
// ── Startup ──
|
||||
@@ -91,8 +111,8 @@ try {
|
||||
console.error(`[claude:${email}] failed to refresh CLAUDE.md:`, err instanceof Error ? err.message : err);
|
||||
}
|
||||
|
||||
const mcpPath = generateMcpConfig();
|
||||
setMcpConfigPath(mcpPath);
|
||||
const mcpPaths = generateMcpConfig();
|
||||
setMcpConfigPath(mcpPaths.sandboxPath, mcpPaths.hostPath);
|
||||
|
||||
console.log(`[claude:${email}] started (HOME=${homeDir})`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user