import { normalizeStringList } from "./skill-tool-gating.js";
//#region src/agent/skills/required-env-vars.ts
/**
* Parse Hermes-style `required_environment_variables` and legacy / xopc `requires.env` into a deduped name list.
*/
/** POSIX-style env var names we allow for passthrough registration. */
const SKILL_ENV_VAR_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
function isValidSkillEnvVarName(name) {
	const t = name.trim();
	return t.length > 0 && SKILL_ENV_VAR_NAME_RE.test(t);
}
function parseRequiredEnvVarNames(frontmatter) {
	const out = /* @__PURE__ */ new Set();
	const fromHermes = frontmatter.required_environment_variables;
	if (Array.isArray(fromHermes)) {
		for (const item of fromHermes) if (item && typeof item === "object" && item !== null && "name" in item) {
			const n = String(item.name).trim();
			if (n && isValidSkillEnvVarName(n)) out.add(n);
		}
	}
	const prereq = frontmatter.prerequisites;
	if (prereq?.env_vars !== void 0) {
		for (const s of normalizeStringList(prereq.env_vars)) if (isValidSkillEnvVarName(s)) out.add(s);
	}
	const req = frontmatter.requires;
	if (req?.env !== void 0) {
		for (const s of normalizeStringList(req.env)) if (isValidSkillEnvVarName(s)) out.add(s);
	}
	const xo = frontmatter.metadata?.xopc;
	if (xo?.requires?.env !== void 0) {
		for (const s of normalizeStringList(xo.requires.env)) if (isValidSkillEnvVarName(s)) out.add(s);
	}
	return [...out];
}
//#endregion
export { SKILL_ENV_VAR_NAME_RE, isValidSkillEnvVarName, parseRequiredEnvVarNames };

//# sourceMappingURL=required-env-vars.js.map