MCPcopy Create free account
hub / github.com/bearlyai/OpenADE / handleResolvePath

Function handleResolvePath

projects/electron/src/modules/code/git.ts:1496–1545  ·  view source on GitHub ↗

* Resolve a path, expanding ~ and environment variables

(params: ResolvePathParams)

Source from the content-addressed store, hash-verified

1494 * Resolve a path, expanding ~ and environment variables
1495 */
1496async function handleResolvePath(params: ResolvePathParams): Promise<ResolvePathResponse> {
1497 const startTime = Date.now()
1498 logger.info("[Git:resolvePath] Resolving path", JSON.stringify({ path: params.path }))
1499
1500 try {
1501 let resolvedPath = params.path.trim()
1502
1503 // Expand ~ to home directory
1504 if (resolvedPath.startsWith("~")) {
1505 resolvedPath = path.join(os.homedir(), resolvedPath.slice(1))
1506 }
1507
1508 // Expand $HOME or ${HOME} (Unix-style)
1509 resolvedPath = resolvedPath.replace(/\$HOME|\$\{HOME\}/g, os.homedir())
1510
1511 // Expand %USERPROFILE% or %HOME% (Windows-style)
1512 resolvedPath = resolvedPath.replace(/%USERPROFILE%|%HOME%/gi, os.homedir())
1513
1514 // Normalize the path
1515 resolvedPath = path.normalize(resolvedPath)
1516
1517 // Check if path exists
1518 let exists = false
1519 let isDirectory = false
1520
1521 try {
1522 const stats = fs.statSync(resolvedPath)
1523 exists = true
1524 isDirectory = stats.isDirectory()
1525 } catch (err) {
1526 // Path doesn't exist
1527 logger.debug('[Git] Path does not exist:', err)
1528 exists = false
1529 isDirectory = false
1530 }
1531
1532 logger.info("[Git:resolvePath] Path resolved", JSON.stringify({
1533 original: params.path,
1534 resolved: resolvedPath,
1535 exists,
1536 isDirectory,
1537 duration: Date.now() - startTime,
1538 }))
1539
1540 return { resolvedPath, exists, isDirectory }
1541 } catch (error: any) {
1542 logger.error("[Git:resolvePath] Error:", JSON.stringify({ error: error.message, stack: error.stack, duration: Date.now() - startTime }))
1543 throw error
1544 }
1545}
1546
1547// Default .gitignore contents for new repositories
1548const DEFAULT_GITIGNORE = `# Dependencies

Callers 1

resolveRuntimeGitPathFunction · 0.85

Calls 3

replaceMethod · 0.80
isDirectoryMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected