"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_map_set = require('../../primordials/map-set.js');
const require_external_tools_skillspector_from_dlx = require('./from-dlx.js');
const require_external_tools_skillspector_from_path = require('./from-path.js');
const require_external_tools_skillspector_from_vfs = require('./from-vfs.js');

//#region src/external-tools/skillspector/resolve.ts
/**
* @file `resolveSkillSpector()` — SkillSpector resolution entry point. Tries
*   each source in order:
*
*   1. VFS — smol binary's embedded skillspector (if packed)
*   2. PATH — `which skillspector` (pipx-installed binaries land here too; the
*      source field distinguishes `'pipx'` vs `'path'`)
*   3. DLX-venv — `~/.socket/_dlx/skillspector/<sha>/` with the pinned SHA Returns
*      `undefined` when all enabled sources miss. Memoized per
*      sha+cacheDir+localOnly tuple.
*/
const resolutionCache = new require_primordials_map_set.MapCtor();
function cacheKey(opts) {
	return `${opts.sha ?? ""}|${opts.cacheDir ?? ""}|${opts.localOnly ? "local" : "full"}`;
}
async function doResolveSkillSpector(opts) {
	const fromVfs = await require_external_tools_skillspector_from_vfs.skillspectorFromVfs();
	/* c8 ignore start - smol Node binary only. */
	if (fromVfs) return fromVfs;
	/* c8 ignore stop */
	const fromPath = await require_external_tools_skillspector_from_path.skillspectorFromPath();
	if (fromPath) return fromPath;
	if (opts.localOnly || !opts.sha) return;
	return require_external_tools_skillspector_from_dlx.skillspectorFromDlx({
		sha: opts.sha,
		cacheDir: opts.cacheDir
	});
}
/**
* Memoizing wrapper around {@link doResolveSkillSpector}.
*/
async function resolveSkillSpector(opts = {}) {
	const key = cacheKey(opts);
	const existing = resolutionCache.get(key);
	if (existing) return existing;
	const promise = doResolveSkillSpector(opts);
	resolutionCache.set(key, promise);
	return promise;
}

//#endregion
exports.cacheKey = cacheKey;
exports.doResolveSkillSpector = doResolveSkillSpector;
exports.resolveSkillSpector = resolveSkillSpector;