MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / getReadablePath

Function getReadablePath

src/utils/path.ts:84–109  ·  view source on GitHub ↗
(cwd: string, relPath?: string)

Source from the content-addressed store, hash-verified

82}
83
84export function getReadablePath(cwd: string, relPath?: string): string {
85 // If relPath is undefined, return empty string instead of allowing path.resolve
86 // to return cwd (which would then show misleading cwd basename in UI)
87 if (relPath === undefined) {
88 return ""
89 }
90
91 // path.resolve is flexible in that it will resolve relative paths like '../../' to the cwd and even ignore the cwd if the relPath is actually an absolute path
92 const absolutePath = path.resolve(cwd, relPath)
93 if (arePathsEqual(cwd, path.join(os.homedir(), "Desktop"))) {
94 // User opened vscode without a workspace, so cwd is the Desktop. Show the full absolute path to keep the user aware of where files are being created
95 return absolutePath.toPosix()
96 }
97 if (arePathsEqual(path.normalize(absolutePath), path.normalize(cwd))) {
98 return path.basename(absolutePath).toPosix()
99 } else {
100 // show the relative path to the cwd
101 const normalizedRelPath = path.relative(cwd, absolutePath)
102 if (absolutePath.includes(cwd)) {
103 return normalizedRelPath.toPosix()
104 } else {
105 // we are outside the cwd, so show the absolute path (useful for when cline passes in '../../' for example)
106 return absolutePath.toPosix()
107 }
108 }
109}
110
111export const toRelativePath = (filePath: string, cwd: string) => {
112 const relativePath = path.relative(cwd, filePath).toPosix()

Callers 15

path.spec.tsFile · 0.90
executeMethod · 0.90
handlePartialMethod · 0.90
executeMethod · 0.90
handlePartialMethod · 0.90
requestApprovalMethod · 0.90
handlePartialMethod · 0.90
executeLegacyMethod · 0.90
executeMethod · 0.90
handlePartialMethod · 0.90
executeMethod · 0.90

Calls 2

arePathsEqualFunction · 0.70
toPosixMethod · 0.65

Tested by

no test coverage detected