MCPcopy
hub / github.com/coder/mux / RemotePathMappedRuntime

Class RemotePathMappedRuntime

src/node/services/tools/testHelpers.ts:136–276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136export class RemotePathMappedRuntime extends LocalRuntime {
137 private readonly localBase: string;
138 private readonly remoteBase: string;
139 private readonly localHomeForTildeRoot: string | null;
140 private readonly muxHomeOverride: string | null;
141 private readonly resolveToRemotePath: boolean;
142 public resolvePathCallCount = 0;
143
144 constructor(localBase: string, remoteBase: string, options?: RemotePathMappedRuntimeOptions) {
145 super(localBase);
146 this.localBase = path.resolve(localBase);
147 this.remoteBase = remoteBase === "/" ? remoteBase : remoteBase.replace(/\/+$/u, "");
148 this.muxHomeOverride = options?.muxHome ?? null;
149 this.resolveToRemotePath = options?.resolveToRemotePath ?? true;
150
151 if (this.remoteBase === "~") {
152 this.localHomeForTildeRoot = this.localBase;
153 } else if (this.remoteBase.startsWith("~/")) {
154 const homeRelativeSuffix = this.remoteBase.slice(1);
155 const normalizedLocalRoot = this.localBase.replaceAll("\\", "/");
156 if (normalizedLocalRoot.endsWith(homeRelativeSuffix)) {
157 const derivedHome = normalizedLocalRoot.slice(
158 0,
159 normalizedLocalRoot.length - homeRelativeSuffix.length
160 );
161 this.localHomeForTildeRoot = derivedHome.length > 0 ? derivedHome : "/";
162 } else {
163 this.localHomeForTildeRoot = null;
164 }
165 } else {
166 this.localHomeForTildeRoot = null;
167 }
168 }
169
170 private usesTildeWorkspaceRoot(): boolean {
171 return this.remoteBase === "~" || this.remoteBase.startsWith("~/");
172 }
173
174 protected toLocalPath(runtimePath: string): string {
175 const normalizedRuntimePath = runtimePath.replaceAll("\\", "/");
176
177 if (normalizedRuntimePath === this.remoteBase) {
178 return this.localBase;
179 }
180
181 if (normalizedRuntimePath.startsWith(`${this.remoteBase}/`)) {
182 const suffix = normalizedRuntimePath.slice(this.remoteBase.length + 1);
183 return path.join(this.localBase, ...suffix.split("/"));
184 }
185
186 return runtimePath;
187 }
188
189 private toRemotePath(localPath: string): string {
190 const resolvedLocalPath = path.resolve(localPath);
191
192 if (resolvedLocalPath === this.localBase) {
193 return this.remoteBase;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected