GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing www.runoob.com — OpenCode 自定义命令 | 菜鸟教程
OpenCode 教程
OpenCode 教程
OpenCode 简介
OpenCode 安装
OpenCode API 设置
OpenCode DeepSeek
OpenCode 配置文件
OpenCode 第一次使用
OpenCode VSCode
OpenCode TUI
OpenCode CLI 使用
OpenCode Web 使用
OpenCode GitHub
OpenCode GitLab
OpenCode 工具
OpenCode 规则
OpenCode 代理
OpenCode 主题
OpenCode 快捷键
OpenCode 自定义命令
OpenCode 格式化工具
OpenCode 权限配置
OpenCode LSP 服务器配置
OpenCode MCP 服务器配置
OpenCode Skills
OpenCode skills 使用
OpenCode 自定义工具
OpenCode oh-my-openagent
OpenCode 生态系统
OpenCode 配置文件
OpenCode 自定义命令自定义命令允许你将常用的提示词封装成一个短命令,在 TUI 中通过 例如,将"运行测试并分析失败原因"这个复杂提示词封装为 自定义命令是
两种定义方式自定义命令支持两种定义方式,效果完全相同,可以按照个人习惯选择:
方式一:JSON 配置在 实例
{ "$schema": "https://opencode.ai/config.json", "command": { "test": { // 命令名称,在 TUI 中通过 /test 调用 "template": "Run the full test suite with coverage report and show any failures.\nFocus on the failing tests and suggest fixes.", // template:发送给 LLM 的提示词内容(必填) "description": "Run tests with coverage", // description:在 TUI 命令列表中显示的说明(可选) "agent": "build", // agent:指定执行此命令的代理(可选) "model": "anthropic/claude-3-5-sonnet-20241022" // model:覆盖此命令使用的模型(可选) } } } 配置完成后,在 TUI 输入框中输入 方式二:Markdown 文件在
Markdown 文件支持两个存放位置:
<!-- 文件路径:.opencode/commands/test.md --> --- description: Run tests with coverage agent: build model: anthropic/claude-3-5-sonnet-20241022 --- Run the full test suite with coverage report and show any failures. Focus on the failing tests and suggest fixes. 该文件名为 提示词模板语法命令的提示词( 1、传入参数($ARGUMENTS)使用 <!-- 文件路径:.opencode/commands/component.md --> --- description: Create a new React component --- Create a new React component named $ARGUMENTS with TypeScript support. Include proper typing and basic structure. 调用时在命令名后附加参数: /component Button
Create a new React component named Button with TypeScript support. Include proper typing and basic structure. 2、位置参数($1、$2、$3…)当需要传入多个独立参数时,可以使用位置参数 <!-- 文件路径:.opencode/commands/create-file.md --> --- description: Create a new file with content --- Create a file named $1 in the directory $2 with the following content: $3 调用示例(含空格的参数用引号包裹): /create-file config.json src "{ \"key\": \"value\" }"
各占位符的替换结果:
3、注入 Shell 命令输出(!`command`)使用 <!-- 文件路径:.opencode/commands/analyze-coverage.md --> --- description: Analyze test coverage --- Here are the current test results: !`npm test` Based on these results, suggest improvements to increase coverage. <!-- 文件路径:.opencode/commands/review-changes.md --> --- description: Review recent git changes --- Recent git commits: !`git log --oneline -10` Review these changes and suggest any improvements or potential issues. 执行命令时, 4、引用文件内容(@文件路径)使用 <!-- 文件路径:.opencode/commands/review-component.md --> --- description: Review a component for performance issues --- Review the component in @src/components/Button.tsx. Check for performance issues and suggest improvements. 执行命令时, 配置选项详解以下是自定义命令支持的所有配置选项,Markdown 文件中写在 frontmatter 里,JSON 配置中写在命令对象下:
agent 与 subtask 的关系
实例
{ "$schema": "https://opencode.ai/config.json", "command": { "analyze": { "template": "Analyze the codebase for potential security vulnerabilities.", "description": "Security analysis(独立运行,不污染主会话)", "subtask": true, // 强制以子代理方式运行,分析结果不占用主会话上下文 "model": "anthropic/claude-3-5-sonnet-20241022" }, "review": { "template": "Review the current code changes.", "description": "Code review(在当前代理中运行)", "agent": "plan", // 使用 plan 代理执行 "subtask": false // 禁止子代理调用,在主会话中运行 } } } 综合使用示例示例一:多参数代码生成命令<!-- 文件路径:.opencode/commands/gen-api.md --> --- description: Generate a REST API endpoint agent: build --- Generate a $1 REST API endpoint for the resource "$2". Place the file in the $3 directory. Include input validation, error handling, and JSDoc comments. <!-- 调用示例:/gen-api POST user src/api --> <!-- $1 = POST,$2 = user,$3 = src/api --> 示例二:结合 Shell 输出和文件引用的代码审查命令<!-- 文件路径:.opencode/commands/pr-review.md --> --- description: Review changes in current branch against main agent: plan subtask: true --- Please review the following changes for code quality, potential bugs, and security issues. ## Recent commits !`git log main..HEAD --oneline` ## Changed files !`git diff main --name-only` ## Diff content !`git diff main` ## Project coding guidelines @.opencode/AGENTS.md Provide structured feedback with severity levels (critical / warning / suggestion). 示例三:定时数据快照命令(JSON 方式){
"$schema": "https://opencode.ai/config.json",
"command": {
"healthcheck": {
"description": "Check project health status",
"template": "Analyze the project health based on the following data:\n\nDependency vulnerabilities:\n!`npm audit --json`\n\nOutdated packages:\n!`npm outdated`\n\nTest results:\n!`npm test -- --passWithNoTests 2>&1 | tail -20`\n\nSummarize the issues by severity and suggest a prioritized action plan.",
"model": "anthropic/claude-3-5-sonnet-20241022",
"subtask": true
}
}
}
AI 思考中...
点我分享笔记取消
分类导航
Advertisement
| |||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |