@nanocollective/nanocoder
Version:
A local-first CLI coding agent that brings the power of agentic coding tools like Claude Code and Gemini CLI to local models or controlled APIs like OpenRouter
55 lines • 1.74 kB
JavaScript
import { isValidFilePath, resolveFilePath } from '../utils/path-validation.js';
/**
* Validates a single file path: checks format and project boundary.
*/
export function validatePath(path) {
if (!isValidFilePath(path)) {
return {
valid: false,
error: `⚒ Invalid file path. Path must be relative and within the project directory.`,
};
}
try {
const cwd = process.cwd();
resolveFilePath(path, cwd);
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
return {
valid: false,
error: `⚒ Path validation failed: ${errorMessage}`,
};
}
return { valid: true };
}
/**
* Validates a source + destination path pair: checks format and project boundary for both.
*/
export function validatePathPair(source, destination) {
if (!isValidFilePath(source)) {
return {
valid: false,
error: `⚒ Invalid source path. Path must be relative and within the project directory.`,
};
}
if (!isValidFilePath(destination)) {
return {
valid: false,
error: `⚒ Invalid destination path. Path must be relative and within the project directory.`,
};
}
try {
const cwd = process.cwd();
resolveFilePath(source, cwd);
resolveFilePath(destination, cwd);
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
return {
valid: false,
error: `⚒ Path validation failed: ${errorMessage}`,
};
}
return { valid: true };
}
//# sourceMappingURL=path-validators.js.map