@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
44 lines • 1.97 kB
JavaScript
import { basename, dirname, resolve, sep } from "node:path";
export function getExtensionSourceLabel(extensionPath) {
if (extensionPath.startsWith("<")) {
return `extension:${extensionPath.replace(/[<>]/g, "")}`;
}
return `extension:${basename(extensionPath).replace(/\.(ts|js)$/, "")}`;
}
/**
* Turn discover results into loader metadata. A contributed path is `system` when the handler said so,
* or when it comes from a builtin extension, or when a system package contributes a path inside its
* own payload; everything else keeps the `temporary` scope contributed paths always had.
*/
export function resolveDiscoveredResourcePaths(entries, extensions) {
const contributors = new Map(extensions.map((extension) => [extension.path, extension]));
return entries.map((entry) => {
const contributor = contributors.get(entry.extensionPath);
const scope = entry.scope ??
(contributor !== undefined && inheritsSystemScope(contributor, entry.path) ? "system" : "temporary");
return {
path: entry.path,
metadata: {
source: getExtensionSourceLabel(entry.extensionPath),
scope,
origin: "top-level",
baseDir: entry.extensionPath.startsWith("<") ? undefined : dirname(entry.extensionPath),
},
};
});
}
function inheritsSystemScope(contributor, resourcePath) {
if (contributor.sourceInfo.scope !== "system")
return false;
if (contributor.path.startsWith("<builtin:"))
return true;
const packageRoot = contributor.sourceInfo.baseDir;
return packageRoot !== undefined && isUnderPath(resolve(resourcePath), resolve(packageRoot));
}
function isUnderPath(target, root) {
if (target === root)
return true;
const prefix = root.endsWith(sep) ? root : `${root}${sep}`;
return target.startsWith(prefix);
}
//# sourceMappingURL=discovered-resource-scope.js.map