Files
claude-code-conduit/server/helpers.mjs

38 lines
1.1 KiB
JavaScript

import { spawnSync } from "child_process";
import path from "path";
const CONTAINER_PATH = "/home/devilholk/Projekt/claude-docker/";
// Docker image → host conversation
const VOLUME_MAPPING = [
['/home/claude', path.resolve(CONTAINER_PATH, 'claude-home')],
['/workspace', path.resolve(CONTAINER_PATH, 'workspace')],
];
// Translate a container-side path to its host-side equivalent using VOLUME_MAP.
// Throws if the path escapes all known volumes.
export function resolve_path(user_path) {
const abs = path.resolve(user_path);
for (const [container_prefix, host_prefix] of VOLUME_MAPPING) {
if (abs === container_prefix || abs.startsWith(container_prefix + "/")) {
return host_prefix + abs.slice(container_prefix.length);
}
}
throw new Error(`Path is outside all known volumes: ${user_path}`);
}
// Execute a binary with an argument list — no shell interpolation.
export function exec(bin, args = []) {
return new Promise((resolve, reject) => {
const result = spawnSync(bin, args, { stdio: "inherit" });
if (result.error) {
reject(result.error);
} else {
resolve(result.status);
}
});
}