5.4 快捷命令
💡 一句话总结:创建快捷命令,一键触发常用任务。
学完你能做什么
- 理解快捷命令的作用
- 能创建自定义快捷命令
- 能配置命令参数
- 能管理快捷命令
🎒 开始前的准备
确保你已经完成以下事项:
- [ ] 完成必修课程
- [ ] 了解 AGENTS.md 的基本结构
核心思路
什么是快捷命令
快捷命令 是用简短命令触发复杂任务的机制。
输入: /build → 执行: npm run build
输入: /test → 执行: npm test
输入: /deploy → 执行: 构建并部署配置结构
yaml
shortcuts:
build:
name: "构建项目"
description: "快速构建当前项目"
command: "npm run build"
icon: "🚀"
category: "development"
test:
name: "运行测试"
description: "执行项目测试"
command: "npm test"
icon: "🧪"
category: "development"
lint:
name: "代码检查"
description: "检查代码质量"
command: "npm run lint"
icon: "🔍"
category: "development"高级配置
带参数的命令
yaml
shortcuts:
git-commit:
name: "Git 提交"
description: "提交代码更改"
command: |
git add .
git commit -m "{{message}}"
git push
parameters:
- name: "message"
type: "text"
required: true
placeholder: "提交信息"
confirm: true
icon: "📝"条件执行
yaml
shortcuts:
smart-deploy:
name: "智能部署"
description: "根据环境智能部署"
command: |
{{#if_eq env "production"}}
echo "部署到生产环境..."
npm run build && ./deploy.sh production
{{else}}
echo "部署到测试环境..."
npm run build && ./deploy.sh staging
{{/if_eq}}
conditions:
- name: "git_clean"
check: "git status --porcelain"
error: "请先提交你的更改"
icon: "🚀"组合命令
yaml
shortcuts:
daily-routine:
name: "每日例程"
description: "执行每日开发准备任务"
commands:
- name: "拉取最新代码"
command: "git pull"
- name: "安装依赖"
command: "npm install"
- name: "运行测试"
command: "npm test"
- name: "检查状态"
command: "git status"
parallel: false
continue_on_error: true
icon: "📅"跟我做
实战:创建常用快捷命令
yaml
shortcuts:
# 开发相关
dev:
name: "启动开发"
description: "启动开发服务器"
command: "npm run dev"
icon: "⚡"
category: "development"
build:
name: "构建项目"
description: "构建生产版本"
command: "npm run build"
icon: "📦"
category: "development"
test:
name: "运行测试"
description: "执行所有测试"
command: "npm test"
icon: "🧪"
category: "development"
lint:
name: "代码检查"
description: "检查并修复代码"
command: "npm run lint"
icon: "🔍"
category: "development"
# Git 相关
gc:
name: "快速提交"
description: "添加并提交更改"
command: |
git add -A && git commit -m "{{message}}"
parameters:
- name: "message"
type: "text"
required: true
confirm: true
icon: "📝"
gp:
name: "推送代码"
description: "提交并推送到远程"
command: "git add -A && git commit -m '{{message}}' && git push"
parameters:
- name: "message"
type: "text"
required: true
confirm: true
icon: "⬆️"
# 文档相关
docs:
name: "生成文档"
description: "生成 API 文档"
command: "npm run docs"
icon: "📚"
category: "documentation"检查点 ✅
全部通过才能继续
- [ ] 理解快捷命令
- [ ] 能创建基本命令
- [ ] 能配置参数
- [ ] 能创建组合命令
本课小结
你学会了:
- 快捷命令的概念
- 基本配置方法
- 带参数的命令
- 条件执行
- 组合命令
下一课预告
下一课我们将学习权限管控,掌握细粒度的访问控制。
📚 更多完整模板:Prompt 模板库

