Implement resolve_path using VOLUME_MAPPING array
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,30 +1,23 @@
|
||||
import { spawnSync } from "child_process";
|
||||
import path from "path";
|
||||
|
||||
const CONTAINER_PATH = "/workspace";
|
||||
const CONTAINER_PATH = "/home/devilholk/Projekt/claude-docker/";
|
||||
|
||||
// Maps container path prefixes to host paths.
|
||||
// Derived from docker-compose.yml volumes:
|
||||
// ./workspace -> /workspace
|
||||
// ./claude-home -> /home/claude
|
||||
// Override host paths via env vars when running outside the default layout.
|
||||
const VOLUME_MAP = {
|
||||
"/workspace": process.env.CONDUIT_HOST_WORKSPACE || CONTAINER_PATH,
|
||||
"/home/claude": process.env.CONDUIT_HOST_HOME || "/home/claude",
|
||||
};
|
||||
|
||||
// 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.
|
||||
// Relative paths are resolved against CONTAINER_PATH first.
|
||||
// Throws if the path escapes all known volumes.
|
||||
export function resolve_path(user_path) {
|
||||
const abs = path.isAbsolute(user_path)
|
||||
? user_path
|
||||
: path.join(CONTAINER_PATH, user_path);
|
||||
const abs = path.resolve(user_path);
|
||||
|
||||
for (const [container_prefix, host_prefix] of Object.entries(VOLUME_MAP)) {
|
||||
for (const [container_prefix, host_prefix] of VOLUME_MAPPING) {
|
||||
if (abs === container_prefix || abs.startsWith(container_prefix + "/")) {
|
||||
const relative = abs.slice(container_prefix.length);
|
||||
return host_prefix + relative;
|
||||
return host_prefix + abs.slice(container_prefix.length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user