हिन्दी
दस्तावेज़
कमांड

कमांड

दोहराव वाले कार्यों के लिए कस्टम कमांड बनाएँ।

कस्टम कमांड आपको एक ऐसा प्रॉम्प्ट निर्दिष्ट करने देते हैं जिसे आप TUI में उस कमांड के निष्पादित होने पर चलाना चाहते हैं।

/my-command

कस्टम कमांड /init, /undo, /redo, /share, /help जैसी बिल्ट-इन कमांड के अतिरिक्त हैं। और जानें


कमांड फ़ाइलें बनाएँ

कस्टम कमांड परिभाषित करने के लिए commands/ डायरेक्टरी में markdown फ़ाइलें बनाएँ।

.opencode/commands/test.md बनाएँ:

.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 config में command विकल्प का उपयोग करें:

opencode.jsonc
{
  "$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 में चला सकते हैं:

/test

Markdown

आप markdown फ़ाइलों का उपयोग करके भी कमांड परिभाषित कर सकते हैं। उन्हें यहाँ रखें:

  • ग्लोबल: ~/.config/opencode/commands/
  • प्रति-प्रोजेक्ट: .opencode/commands/
~/.config/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.

markdown फ़ाइल का नाम कमांड नाम बन जाता है। उदाहरण के लिए, test.md आपको यह चलाने देता है:

/test

प्रॉम्प्ट कॉन्फ़िग

कस्टम कमांड के प्रॉम्प्ट कई विशेष प्लेसहोल्डर और सिंटैक्स को सपोर्ट करते हैं।


तर्क (Arguments)

$ARGUMENTS प्लेसहोल्डर का उपयोग करके कमांड को तर्क पास करें।

.opencode/commands/component.md
---
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 - तीसरा तर्क
  • और इसी तरह...

उदाहरण के लिए:

.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\" }"

यह बदलता है:

  • $1 को config.json से
  • $2 को src से
  • $3 को { "key": "value" } से

शेल आउटपुट

अपने प्रॉम्प्ट में bash command आउटपुट इंजेक्ट करने के लिए !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 changes
---
 
Recent git commits:
!`git log --oneline -10`
 
Review these changes and suggest any improvements.

कमांड आपके प्रोजेक्ट की रूट डायरेक्टरी में चलती हैं और उनका आउटपुट प्रॉम्प्ट का हिस्सा बन जाता है।


फ़ाइल संदर्भ

फ़ाइल नाम के बाद @ का उपयोग करके अपने कमांड में फ़ाइलें शामिल करें।

.opencode/commands/review-component.md
---
description: Review component
---
 
Review the component in @src/components/Button.tsx.
Check for performance issues and suggest improvements.

फ़ाइल सामग्री स्वचालित रूप से प्रॉम्प्ट में शामिल हो जाती है।


विकल्प

आइए कॉन्फ़िगरेशन विकल्पों को विस्तार से देखें।


Template

template विकल्प उस प्रॉम्प्ट को परिभाषित करता है जो कमांड निष्पादित होने पर LLM को भेजा जाएगा।

opencode.json
{
  "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 विकल्प का उपयोग करें।

opencode.json
{
  "command": {
    "test": {
      "description": "Run tests with coverage"
    }
  }
}

जब आप कमांड टाइप करते हैं तो यह TUI में विवरण के रूप में दिखाया जाता है।


Agent

इस कमांड को कौन सा agent निष्पादित करना चाहिए, इसे वैकल्पिक रूप से निर्दिष्ट करने हेतु agent कॉन्फ़िग का उपयोग करें। यदि यह एक subagent है तो कमांड डिफ़ॉल्ट रूप से एक सबएजेंट इन्वोकेशन ट्रिगर करेगी। इस व्यवहार को अक्षम करने के लिए, subtask को false पर सेट करें।

opencode.json
{
  "command": {
    "review": {
      "agent": "plan"
    }
  }
}

यह एक वैकल्पिक कॉन्फ़िग विकल्प है। यदि निर्दिष्ट नहीं है, तो यह आपके वर्तमान एजेंट पर डिफ़ॉल्ट हो जाता है।


Subtask

कमांड को एक subagent इन्वोकेशन ट्रिगर करने के लिए बाध्य करने हेतु subtask बूलियन का उपयोग करें। यह तब उपयोगी है जब आप चाहते हैं कि कमांड आपके प्राथमिक संदर्भ को प्रदूषित न करे और यह एजेंट को सबएजेंट के रूप में कार्य करने के लिए बाध्य करेगा, भले ही agent कॉन्फ़िगरेशन पर mode primary पर सेट हो।

opencode.json
{
  "command": {
    "analyze": {
      "subtask": true
    }
  }
}

यह एक वैकल्पिक कॉन्फ़िग विकल्प है।


Model

इस कमांड के लिए डिफ़ॉल्ट मॉडल को ओवरराइड करने हेतु model कॉन्फ़िग का उपयोग करें।

opencode.json
{
  "command": {
    "analyze": {
      "model": "anthropic/claude-3-5-sonnet-20241022"
    }
  }
}

यह एक वैकल्पिक कॉन्फ़िग विकल्प है।


बिल्ट-इन

opencode में /init, /undo, /redo, /share, /help जैसी कई बिल्ट-इन कमांड शामिल हैं; और जानें

Note: कस्टम कमांड बिल्ट-इन कमांड को ओवरराइड कर सकती हैं।

यदि आप समान नाम वाली एक कस्टम कमांड परिभाषित करते हैं, तो यह बिल्ट-इन कमांड को ओवरराइड कर देगी।