Rename .js to .mjs, extract helpers module

Move resolvePath and exec out of index.mjs into server/helpers.mjs so
actions can import them directly rather than receiving them as arguments.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 20:06:29 +00:00
parent 5a557a642a
commit f02e2a746d
7 changed files with 43 additions and 42 deletions

25
server/helpers.mjs Normal file
View File

@@ -0,0 +1,25 @@
import { spawnSync } from "child_process";
import path from "path";
const WORKSPACE_ROOT = process.env.CONDUIT_ROOT || "/workspace";
// Resolve a path param relative to WORKSPACE_ROOT, preventing traversal.
export function resolvePath(userPath) {
const resolved = path.resolve(WORKSPACE_ROOT, userPath.replace(/^\//, ""));
if (!resolved.startsWith(WORKSPACE_ROOT)) {
throw new Error(`Path escapes workspace root: ${userPath}`);
}
return resolved;
}
// 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);
}
});
}