@debugmcp/mcp-debugger
Version:
Step-through debugging MCP server for LLMs
71 lines • 2.59 kB
JavaScript
/**
* Simple file existence checker - Centralized path resolution approach
*
* POLICY:
* 1. Use centralized path resolution from container-path-utils
* 2. Only check file existence for immediate UX feedback
* 3. Log both original and resolved paths for debugging
* 4. Clear error messages for path issues
*/
import { resolvePathForRuntime, getPathDescription } from './container-path-utils.js';
/**
* Simple file checker that follows hands-off path policy
*/
export class SimpleFileChecker {
fileSystem;
environment;
logger;
constructor(fileSystem, environment, logger) {
this.fileSystem = fileSystem;
this.environment = environment;
this.logger = logger;
}
/**
* Check if file exists - using centralized path resolution
*/
async checkExists(path) {
let effectivePath;
try {
// Use centralized path resolution
effectivePath = resolvePathForRuntime(path, this.environment);
const pathDesc = getPathDescription(path, effectivePath, this.environment);
this.logger?.debug(`[SimpleFileChecker] Checking existence: ${pathDesc}`);
}
catch (error) {
// Path resolution failed - return with error
const errorMessage = error instanceof Error ? error.message : String(error);
this.logger?.debug(`[SimpleFileChecker] Path resolution failed: ${errorMessage}`);
return {
exists: false,
originalPath: path,
effectivePath: path, // Use original since resolution failed
errorMessage
};
}
try {
const exists = await this.fileSystem.pathExists(effectivePath);
return {
exists,
originalPath: path,
effectivePath
};
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
this.logger?.debug(`[SimpleFileChecker] Check failed for ${effectivePath}: ${errorMessage}`);
return {
exists: false,
originalPath: path,
effectivePath,
errorMessage: `Cannot check file existence: ${errorMessage}`
};
}
}
}
/**
* Factory function to create a SimpleFileChecker instance
*/
export function createSimpleFileChecker(fileSystem, environment, logger) {
return new SimpleFileChecker(fileSystem, environment, logger);
}
//# sourceMappingURL=simple-file-checker.js.map