/**
 * Extension resource discovery helpers.
 *
 * Pure functions for building extension resource paths and labels,
 * extracted from AgentSession to keep the orchestration file focused.
 */
// Hand-rolled rather than `node:path` so this module stays import-safe in
// non-Node bundles. Inputs are always posix-shaped paths from extension
// discovery; the `\\` normalization is defense-in-depth.
function getBasename(input) {
    const normalized = input.replace(/\\/g, '/');
    const segments = normalized.split('/');
    return segments[segments.length - 1] ?? normalized;
}
function getDirname(input) {
    const normalized = input.replace(/\\/g, '/');
    const separatorIndex = normalized.lastIndexOf('/');
    return separatorIndex === -1 ? '' : normalized.slice(0, separatorIndex);
}
/**
 * Build extension resource path entries from raw discovery results.
 */
export function buildExtensionResourcePaths(entries) {
    return entries.map((entry) => {
        const source = getExtensionSourceLabel(entry.extensionPath);
        const baseDir = entry.extensionPath.startsWith('<')
            ? undefined
            : getDirname(entry.extensionPath);
        return {
            path: entry.path,
            metadata: {
                source,
                scope: 'temporary',
                origin: 'top-level',
                baseDir
            }
        };
    });
}
/**
 * Derive a human-readable source label from an extension path.
 */
export function getExtensionSourceLabel(extensionPath) {
    if (extensionPath.startsWith('<')) {
        return `extension:${extensionPath.replace(/[<>]/g, '')}`;
    }
    const base = getBasename(extensionPath);
    const name = base.replace(/\.(ts|js)$/, '');
    return `extension:${name}`;
}
//# sourceMappingURL=extension-resources.js.map