feat: standardize skill data management and actions
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -11,6 +11,19 @@ from pathlib import Path
|
||||
EXCLUDE_DIR_NAMES = {".git", ".pytest_cache", "__pycache__"}
|
||||
EXCLUDE_FILE_NAMES = {".env", ".env.local"}
|
||||
KEBAB_SLUG = re.compile(r"^[a-z0-9]+(-[a-z0-9]+)*$")
|
||||
TEMPLATE_PLACEHOLDER_SLUG = "your-skill-slug"
|
||||
TEXT_FILE_SUFFIXES = {
|
||||
".md",
|
||||
".py",
|
||||
".json",
|
||||
".yaml",
|
||||
".yml",
|
||||
".txt",
|
||||
".ini",
|
||||
".ps1",
|
||||
".sample",
|
||||
".env.example",
|
||||
}
|
||||
|
||||
|
||||
def _ignore_copy(_dir: str, names: list[str]) -> set[str]:
|
||||
@@ -23,6 +36,34 @@ def _ignore_copy(_dir: str, names: list[str]) -> set[str]:
|
||||
return ignored
|
||||
|
||||
|
||||
def _should_replace_placeholders(path: Path) -> bool:
|
||||
if path.name in EXCLUDE_FILE_NAMES:
|
||||
return False
|
||||
if path.suffix.lower() in TEXT_FILE_SUFFIXES:
|
||||
return True
|
||||
if path.name == ".env.example":
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def _replace_template_placeholders(target: Path, slug: str) -> None:
|
||||
"""将模板占位 slug 替换为新技能 slug(不修改 action 业务命令结构)。"""
|
||||
for path in target.rglob("*"):
|
||||
if not path.is_file():
|
||||
continue
|
||||
if path.name in EXCLUDE_FILE_NAMES:
|
||||
continue
|
||||
if path.suffix.lower() not in TEXT_FILE_SUFFIXES and path.name != ".env.example":
|
||||
continue
|
||||
try:
|
||||
text = path.read_text(encoding="utf-8")
|
||||
except UnicodeDecodeError:
|
||||
continue
|
||||
if TEMPLATE_PLACEHOLDER_SLUG not in text:
|
||||
continue
|
||||
path.write_text(text.replace(TEMPLATE_PLACEHOLDER_SLUG, slug), encoding="utf-8")
|
||||
|
||||
|
||||
def _print_next_steps(target: Path) -> None:
|
||||
print()
|
||||
print("=== 脚手架复制完成 ===")
|
||||
@@ -34,6 +75,7 @@ def _print_next_steps(target: Path) -> None:
|
||||
print(" git init")
|
||||
print(" git remote add origin <你的新技能仓库 URL>")
|
||||
print(" git remote -v # 确认 remote 不是 skill-template")
|
||||
print(" # 确认 assets/actions.json 中 skill 已替换为新 slug;不需要 Action 时可删除该文件")
|
||||
print(" python tests/run_tests.py -v")
|
||||
print()
|
||||
|
||||
@@ -98,6 +140,8 @@ def main(argv: list[str] | None = None) -> int:
|
||||
if marker.is_file():
|
||||
marker.unlink()
|
||||
|
||||
_replace_template_placeholders(target, slug)
|
||||
|
||||
_print_next_steps(target)
|
||||
return 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user