MCPcopy Index your code
hub / github.com/anomalyco/opencode / createPathHelpers

Function createPathHelpers

packages/app/src/context/file/path.ts:104–151  ·  view source on GitHub ↗
(scope: () => string)

Source from the content-addressed store, hash-verified

102}
103
104export function createPathHelpers(scope: () => string) {
105 const normalize = (input: string) => {
106 const root = scope()
107
108 let path = unquoteGitPath(decodeFilePath(stripQueryAndHash(stripFileProtocol(input))))
109
110 // Separator-agnostic prefix stripping for Cygwin/native Windows compatibility
111 // Only case-insensitive on Windows (drive letter or UNC paths)
112 const windows = /^[A-Za-z]:/.test(root) || root.startsWith("\\\\")
113 const canonRoot = windows ? root.replace(/\\/g, "/").toLowerCase() : root.replace(/\\/g, "/")
114 const canonPath = windows ? path.replace(/\\/g, "/").toLowerCase() : path.replace(/\\/g, "/")
115 if (
116 canonPath.startsWith(canonRoot) &&
117 (canonRoot.endsWith("/") || canonPath === canonRoot || canonPath[canonRoot.length] === "/")
118 ) {
119 // Slice from original path to preserve native separators
120 path = path.slice(root.length)
121 }
122
123 if (path.startsWith("./") || path.startsWith(".\\")) {
124 path = path.slice(2)
125 }
126
127 if (path.startsWith("/") || path.startsWith("\\")) {
128 path = path.slice(1)
129 }
130 return path
131 }
132
133 const tab = (input: string) => {
134 const path = normalize(input)
135 return `file://${encodeFilePath(path)}`
136 }
137
138 const pathFromTab = (tabValue: string) => {
139 if (!tabValue.startsWith("file://")) return
140 return normalize(tabValue)
141 }
142
143 const normalizeDir = (input: string) => normalize(input).replace(/\/+$/, "")
144
145 return {
146 normalize,
147 tab,
148 pathFromTab,
149 normalizeDir,
150 }
151}

Callers 3

file.tsxFile · 0.90
sessionPathFunction · 0.90
path.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected