//#region src/cognitive/evolution/skill-draft-generator.ts
function toKebabCase(input) {
	return input.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/-+/g, "-");
}
function sanitizeSkillName(name) {
	return toKebabCase(name).replace(/^-+|-+$/g, "");
}
function generateName(candidate) {
	const domain = sanitizeSkillName(candidate.domain);
	if (candidate.toolCalls.length === 0) return `${domain}-workflow`;
	return `${domain}-${sanitizeSkillName(candidate.toolCalls[0])}`;
}
const MAX_DESCRIPTION_LENGTH = 200;
function generateDescription(candidate) {
	const raw = `${candidate.taskSummary}. Use when user needs similar ${candidate.domain} operations.`;
	if (raw.length <= MAX_DESCRIPTION_LENGTH) return raw;
	return raw.slice(0, MAX_DESCRIPTION_LENGTH - 1) + "…";
}
function generateTriggerPhrases(candidate) {
	const phrases = [];
	const domain = candidate.domain;
	const tools = candidate.toolCalls;
	if (tools.length > 0) {
		phrases.push(`${tools[0]} 操作`);
		phrases.push(`${tools[0]} task`);
	}
	phrases.push(`${domain} 流程`);
	phrases.push(`${domain} workflow`);
	phrases.push(`${domain} operations`);
	return phrases.slice(0, 5);
}
function deduplicate(items) {
	const seen = /* @__PURE__ */ new Set();
	const result = [];
	for (const item of items) if (!seen.has(item)) {
		seen.add(item);
		result.push(item);
	}
	return result;
}
function generateBodyMarkdown(candidate) {
	const lines = [];
	lines.push("## When to use");
	lines.push("");
	lines.push(`Use when the user requests ${candidate.domain} operations similar to: ${candidate.taskSummary}.`);
	lines.push("");
	lines.push("## Workflow");
	lines.push("");
	const uniqueTools = deduplicate(candidate.toolCalls);
	if (uniqueTools.length === 0) lines.push("1. Follow the standard workflow for the task.");
	else uniqueTools.forEach((tool, i) => {
		lines.push(`${i + 1}. Use \`${tool}\` to accomplish the relevant sub-task.`);
	});
	lines.push("");
	lines.push("## Notes");
	lines.push("");
	lines.push("This skill was auto-generated by the self-evolution engine. Review and verify before relying on it.");
	lines.push("");
	return lines.join("\n");
}
function generateSkillDraft(candidate) {
	return {
		name: generateName(candidate),
		description: generateDescription(candidate),
		triggerPhrases: generateTriggerPhrases(candidate),
		bodyMarkdown: generateBodyMarkdown(candidate)
	};
}
//#endregion
export { sanitizeSkillName as n, generateSkillDraft as t };
