SuperAPI AI 工具集

rhdh-templates

编程与开发

查看项目

更新于 10-16 10:48

技能介绍

用途

rhdh-templates 用于在 Red Hat Developer Hub(RHDH)环境中编写和校验 Software Templates(Scaffolder 模板)。它适合需要创建软件模板、将现有代码库模板化、为模板增加表单参数或流水线步骤、处理 Nunjucks 相关问题,以及在提交前做本地校验的场景。技能以 AI 引导的工作流方式组织,命令包括 init、templatize、create、add-parameter、add-step、add-skeleton、create-location、fix-gotchas、validate、list-actions、dry-run、explain-action、examples。

主要能力

  • 项目初始化与布局确认:通过 init 完成确定性工具检查与项目脚手架,或在用户已有模板仓库时确认路径。
  • 代码库模板化:通过 templatize 将现有代码库转换为模板,交互式提出参数化方案,用户逐项确认字面量到参数的映射。
  • 从零创建模板:通过 create 新建模板,可用 list_examples 对上游参考模板进行排序与挑选。
  • 增量编辑:add-parameter 添加表单字段/参数,add-step 添加 scaffolder action 或流水线步骤,add-skeleton 添加骨架文件(含 Nunjucks)。
  • 注册与修复:create-location 生成 location.yaml 以注册所有 template.yaml 供目录导入,fix-gotchas 处理常见问题(如 raw/endraw)。
  • 校验与检查:validate 执行本地检查,可通过 --lint-skeleton 启用 Nunjucks/djLint 检查;list-actions、dry-run、explain-action 可列出 scaffolder actions、远程测试模板、解释 action/参数 schema。
  • 示例参考:examples 与 list_examples.py 用于查看或挑选模板示例(数据源为 assets/example-catalog.json,示例模板位于 assets/examples/)。

使用方式

所有 scripts/ 与 references/ 路径相对于 SKILL.md 所在目录,调用前需先解析。示例命令:

SKILL_DIR="<path-to>/skills/rhdh-templates"
python "$SKILL_DIR/scripts/init.py" --help
python "$SKILL_DIR/scripts/analyze.py" --help
python "$SKILL_DIR/scripts/create_location.py" --help
python "$SKILL_DIR/scripts/fix_gotchas.py" --help
python "$SKILL_DIR/scripts/validate.py" --help
python "$SKILL_DIR/scripts/list_actions.py" --help
python "$SKILL_DIR/scripts/dry_run.py" --help
python "$SKILL_DIR/scripts/explain_action.py" --help
python "$SKILL_DIR/scripts/list_examples.py" --help

执行编辑前需满足 setup gates:加载匹配的 references/<command>.md(examples 对应 example-catalog.md);确认模板项目已初始化或路径已知;编写类命令前先阅读 references/conventions.md。若用户已给出明确任务(例如带输出路径的 proposal-only templatize 请求,或已指明模板文件、步骤 id、action 与输入的 add-step 请求),可跳过菜单直接路由到对应参考并执行。

常用命令与参考映射:init/setup/scaffold → references/init.md;templatize/convert/parameterize repo → references/templatize.md;create/from scratch → references/create.md;add-parameter/form field → references/add-parameter.md;add-step/scaffolder action → references/add-step.md;add-skeleton/nunjucks → references/add-skeleton.md;create-location/location.yaml → references/create-location.md;fix-gotchas/raw endraw → references/fix-gotchas.md;validate/lint template → references/validate.md;list-actions → references/list-actions.md;dry-run → references/dry-run.md;explain-action/action schema → references/explain-action.md;examples/reference templates → references/example-catalog.md。首词不匹配时可从上下文推断意图。

适用场景

适用于 RHDH 模板作者与维护者:将已有 Spring Boot 等应用转为模板、为模板增加 owner 选择器或其他表单字段、添加流水线步骤、生成 location.yaml 注册模板、排查 raw/endraw 等 Nunjucks 问题、在合并前跑本地校验、查询可用 scaffolder actions 或解释某个 action 参数 schema、查找可参考的示例模板。

限制与约束

该技能为交互式而非完全自动。参数化采取保守策略,宁可少暴露参数,由用户逐步增加。templatize 的确认是硬性关口:需先把候选映射写入指定 proposal 产物并停止,用户确认前不得编辑源文件。凭证不得进入模板:发布步骤应接入已有参数或文档化的密钥引用,不得发明、复制或持久化字面量 token、密码或凭证。编辑应保持克制,当用户指定单个模板文件与单处改动时,只改该文件,不添加未请求的参数、步骤或文件。生成物应在合并前通过本地 validate 且无 critical 发现。validate.py 用于本地检查;list_actions.py、dry_run.py、explain_action.py 需要可达的 RHDH --rhdh-url 以及可选 bearer token(RHDH_TOKEN 环境变量或 --token)。references/schemas/template-v1beta3.schema.json 提供深度校验用的 JSON Schema。