कमांड
दोहराए जाने वाले कार्यों के लिए कस्टम कमांड बनाएं।
कस्टम कमांड आपको एक प्रॉम्प्ट निर्दिष्ट करने की अनुमति देते हैं जो TUI में उस कमांड को एक्ज़ीक्यूट करने पर चलाया जाएगा।
/my-commandकस्टम कमांड बिल्ट-इन कमांड जैसे /init, /undo, /redo, /share, /help के अतिरिक्त हैं। और जानें।
कमांड फाइलें बनाएं
कस्टम कमांड परिभाषित करने के लिए commands/ डायरेक्टरी में 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.frontmatter कमांड प्रॉपर्टीज़ को परिभाषित करता है। कंटेंट टेम्पलेट बन जाता है।
/ के बाद कमांड नाम टाइप करके कमांड का उपयोग करें।
/testकॉन्फ़िगर करें
आप OpenCode कॉन्फ़िग के माध्यम से या commands/ डायरेक्टरी में markdown फाइलें बनाकर कस्टम कमांड जोड़ सकते हैं।
JSON
अपने OpenCode कॉन्फ़िग में command विकल्प का उपयोग करें:
{
"$schema": "https://opencode.ai/config.json",
"command": {
// This becomes the name of the command
"test": {
// This is the prompt that will be sent to the LLM
"template": "Run the full test suite with coverage report and show any failures.\nFocus on the failing tests and suggest fixes.",
// This is shown as the description in the TUI
"description": "Run tests with coverage",
"agent": "build",
"model": "anthropic/claude-3-5-sonnet-20241022"
}
}
}अब आप TUI में यह कमांड चला सकते हैं:
/testMarkdown
आप markdown फाइलों का उपयोग करके भी कमांड परिभाषित कर सकते हैं। उन्हें यहां रखें:
- ग्लोबल:
~/.config/opencode/commands/ - प्रति-प्रोजेक्ट:
.opencode/commands/
---
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.markdown फाइल का नाम कमांड का नाम बन जाता है। उदाहरण के लिए, test.md आपको चलाने देता है:
/testप्रॉम्प्ट कॉन्फ़िग
कस्टम कमांड के प्रॉम्प्ट कई विशेष प्लेसहोल्डर और सिंटैक्स को सपोर्ट करते हैं।
आर्गुमेंट्स
$ARGUMENTS प्लेसहोल्डर का उपयोग करके कमांड को आर्गुमेंट्स पास करें।
---
description: Create a new component
---
Create a new React component named $ARGUMENTS with TypeScript support.
Include proper typing and basic structure.आर्गुमेंट्स के साथ कमांड चलाएं:
/component Buttonऔर $ARGUMENTS को Button से बदल दिया जाएगा।
आप पोजिशनल पैरामीटर्स का उपयोग करके व्यक्तिगत आर्गुमेंट्स भी एक्सेस कर सकते हैं:
$1- पहला आर्गुमेंट$2- दूसरा आर्गुमेंट$3- तीसरा आर्गुमेंट- और इसी तरह...
उदाहरण के लिए:
---
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\" }"यह बदलता है:
$1कोconfig.jsonसे$2कोsrcसे$3को{ "key": "value" }से
Shell आउटपुट
अपने प्रॉम्प्ट में bash कमांड आउटपुट इंजेक्ट करने के लिए !command का उपयोग करें।
उदाहरण के लिए, टेस्ट कवरेज का विश्लेषण करने वाला कस्टम कमांड बनाने के लिए:
---
description: Analyze test coverage
---
Here are the current test results:
!`npm test`
Based on these results, suggest improvements to increase coverage.या हाल के बदलावों की समीक्षा करने के लिए:
---
description: Review recent changes
---
Recent git commits:
!`git log --oneline -10`
Review these changes and suggest any improvements.कमांड आपके प्रोजेक्ट की रूट डायरेक्टरी में चलते हैं और उनका आउटपुट प्रॉम्प्ट का हिस्सा बन जाता है।
फाइल रेफरेंस
@ के बाद फाइलनाम का उपयोग करके अपने कमांड में फाइलें शामिल करें।
---
description: Review component
---
Review the component in @src/components/Button.tsx.
Check for performance issues and suggest improvements.फाइल कंटेंट स्वचालित रूप से प्रॉम्प्ट में शामिल हो जाता है।
विकल्प
आइए कॉन्फ़िगरेशन विकल्पों को विस्तार से देखें।
Template
template विकल्प उस प्रॉम्प्ट को परिभाषित करता है जो कमांड एक्ज़ीक्यूट होने पर LLM को भेजा जाएगा।
{
"command": {
"test": {
"template": "Run the full test suite with coverage report and show any failures.\nFocus on the failing tests and suggest fixes."
}
}
}यह एक आवश्यक कॉन्फ़िग विकल्प है।
Description
कमांड क्या करता है इसका संक्षिप्त विवरण प्रदान करने के लिए description विकल्प का उपयोग करें।
{
"command": {
"test": {
"description": "Run tests with coverage"
}
}
}जब आप TUI में कमांड टाइप करते हैं तो यह विवरण के रूप में दिखाया जाता है।
Agent
वैकल्पिक रूप से निर्दिष्ट करने के लिए agent कॉन्फ़िग का उपयोग करें कि कौन सा agent इस कमांड को एक्ज़ीक्यूट करेगा। यदि यह एक subagent है, तो कमांड डिफ़ॉल्ट रूप से subagent इनवोकेशन ट्रिगर करेगा। इस व्यवहार को अक्षम करने के लिए, subtask को false पर सेट करें।
{
"command": {
"review": {
"agent": "plan"
}
}
}यह एक वैकल्पिक कॉन्फ़िग विकल्प है। यदि निर्दिष्ट नहीं है, तो आपके वर्तमान agent पर डिफ़ॉल्ट होता है।
Subtask
कमांड को subagent इनवोकेशन ट्रिगर करने के लिए मजबूर करने के लिए subtask बूलियन का उपयोग करें। यह उपयोगी है यदि आप चाहते हैं कि कमांड आपके प्राइमरी कॉन्टेक्स्ट को प्रदूषित न करे और agent को subagent के रूप में कार्य करने के लिए मजबूर करेगा, भले ही agent कॉन्फ़िगरेशन में mode primary पर सेट हो।
{
"command": {
"analyze": {
"subtask": true
}
}
}यह एक वैकल्पिक कॉन्फ़िग विकल्प है।
Model
इस कमांड के लिए डिफ़ॉल्ट मॉडल को ओवरराइड करने के लिए model कॉन्फ़िग का उपयोग करें।
{
"command": {
"analyze": {
"model": "anthropic/claude-3-5-sonnet-20241022"
}
}
}यह एक वैकल्पिक कॉन्फ़िग विकल्प है।
बिल्ट-इन कमांड
OpenCode में /init, /undo, /redo, /share, /help जैसे कई बिल्ट-इन कमांड शामिल हैं; और जानें।
नोट
कस्टम कमांड बिल्ट-इन कमांड को ओवरराइड कर सकते हैं।
यदि आप समान नाम के साथ कस्टम कमांड परिभाषित करते हैं, तो यह बिल्ट-इन कमांड को ओवरराइड कर देगा।