commands.mdx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. ---
  2. title: Comandi
  3. description: Crea comandi personalizzati per task ripetitivi.
  4. ---
  5. I comandi personalizzati ti permettono di definire un prompt da eseguire quando quel comando viene lanciato nella TUI.
  6. ```bash frame="none"
  7. /my-command
  8. ```
  9. I comandi personalizzati si aggiungono a quelli integrati come `/init`, `/undo`, `/redo`, `/share`, `/help`. [Scopri di piu](/docs/tui#commands).
  10. ---
  11. ## Creazione file di comando
  12. Crea file markdown nella directory `commands/` per definire comandi personalizzati.
  13. Crea `.opencode/commands/test.md`:
  14. ```md title=".opencode/commands/test.md"
  15. ---
  16. description: Run tests with coverage
  17. agent: build
  18. model: anthropic/claude-3-5-sonnet-20241022
  19. ---
  20. Run the full test suite with coverage report and show any failures.
  21. Focus on the failing tests and suggest fixes.
  22. ```
  23. Il frontmatter definisce le proprieta del comando. Il contenuto diventa il template.
  24. Usa il comando digitando `/` seguito dal nome del comando.
  25. ```bash frame="none"
  26. "/test"
  27. ```
  28. ---
  29. ## Configurazione
  30. Puoi aggiungere comandi personalizzati tramite la config di OpenCode o creando file markdown nella directory `commands/`.
  31. ---
  32. ### JSON
  33. Usa l'opzione `command` nella [config](/docs/config) di OpenCode:
  34. ```json title="opencode.jsonc" {4-12}
  35. {
  36. "$schema": "https://opencode.ai/config.json",
  37. "command": {
  38. // This becomes the name of the command
  39. "test": {
  40. // This is the prompt that will be sent to the LLM
  41. "template": "Run the full test suite with coverage report and show any failures.\nFocus on the failing tests and suggest fixes.",
  42. // This is shown as the description in the TUI
  43. "description": "Run tests with coverage",
  44. "agent": "build",
  45. "model": "anthropic/claude-3-5-sonnet-20241022"
  46. }
  47. }
  48. }
  49. ```
  50. Ora puoi eseguire questo comando nella TUI:
  51. ```bash frame="none"
  52. /test
  53. ```
  54. ---
  55. ### Markdown
  56. Puoi anche definire comandi usando file markdown. Mettili in:
  57. - Globale: `~/.config/opencode/commands/`
  58. - Per progetto: `.opencode/commands/`
  59. ```markdown title="~/.config/opencode/commands/test.md"
  60. ---
  61. description: Run tests with coverage
  62. agent: build
  63. model: anthropic/claude-3-5-sonnet-20241022
  64. ---
  65. Run the full test suite with coverage report and show any failures.
  66. Focus on the failing tests and suggest fixes.
  67. ```
  68. Il nome del file markdown diventa il nome del comando. Per esempio, `test.md` ti permette di eseguire:
  69. ```bash frame="none"
  70. /test
  71. ```
  72. ---
  73. ## Configurazione del prompt
  74. I prompt dei comandi personalizzati supportano diversi placeholder e sintassi speciali.
  75. ---
  76. ### Argomenti
  77. Passa argomenti ai comandi usando il placeholder `$ARGUMENTS`.
  78. ```md title=".opencode/commands/component.md"
  79. ---
  80. description: Create a new component
  81. ---
  82. Create a new React component named $ARGUMENTS with TypeScript support.
  83. Include proper typing and basic structure.
  84. ```
  85. Esegui il comando con argomenti:
  86. ```bash frame="none"
  87. /component Button
  88. ```
  89. E `$ARGUMENTS` verra sostituito con `Button`.
  90. Puoi anche accedere ai singoli argomenti usando parametri posizionali:
  91. - `$1` - Primo argomento
  92. - `$2` - Secondo argomento
  93. - `$3` - Terzo argomento
  94. - E cosi via...
  95. Per esempio:
  96. ```md title=".opencode/commands/create-file.md"
  97. ---
  98. description: Create a new file with content
  99. ---
  100. Create a file named $1 in the directory $2
  101. with the following content: $3
  102. ```
  103. Esegui il comando:
  104. ```bash frame="none"
  105. /create-file config.json src "{ \"key\": \"value\" }"
  106. ```
  107. Questo sostituisce:
  108. - `$1` con `config.json`
  109. - `$2` con `src`
  110. - `$3` con `{ "key": "value" }`
  111. ---
  112. ### Output della shell
  113. Usa _!`command`_ per inserire nel prompt l'output di un [comando bash](/docs/tui#bash-commands).
  114. Per esempio, per creare un comando personalizzato che analizzi la copertura dei test:
  115. ```md title=".opencode/commands/analyze-coverage.md"
  116. ---
  117. description: Analyze test coverage
  118. ---
  119. Here are the current test results:
  120. !`npm test`
  121. Based on these results, suggest improvements to increase coverage.
  122. ```
  123. Oppure per rivedere modifiche recenti:
  124. ```md title=".opencode/commands/review-changes.md"
  125. ---
  126. description: Review recent changes
  127. ---
  128. Recent git commits:
  129. !`git log --oneline -10`
  130. Review these changes and suggest any improvements.
  131. ```
  132. I comandi vengono eseguiti nella root del progetto e il loro output diventa parte del prompt.
  133. ---
  134. ### Riferimenti ai file
  135. Includi file nel comando usando `@` seguito dal nome del file.
  136. ```md title=".opencode/commands/review-component.md"
  137. ---
  138. description: Review component
  139. ---
  140. Review the component in @src/components/Button.tsx.
  141. Check for performance issues and suggest improvements.
  142. ```
  143. Il contenuto del file viene incluso automaticamente nel prompt.
  144. ---
  145. ## Opzioni
  146. Vediamo le opzioni di configurazione nel dettaglio.
  147. ---
  148. ### Template del prompt
  149. L'opzione `template` definisce il prompt che verra inviato all'LLM quando il comando viene eseguito.
  150. ```json title="opencode.json"
  151. {
  152. "command": {
  153. "test": {
  154. "template": "Run the full test suite with coverage report and show any failures.\nFocus on the failing tests and suggest fixes."
  155. }
  156. }
  157. }
  158. ```
  159. Questa e un'opzione di config **obbligatoria**.
  160. ---
  161. ### Descrizione
  162. Usa l'opzione `description` per fornire una breve descrizione di cosa fa il comando.
  163. ```json title="opencode.json"
  164. {
  165. "command": {
  166. "test": {
  167. "description": "Run tests with coverage"
  168. }
  169. }
  170. }
  171. ```
  172. Questo viene mostrato come descrizione nella TUI quando digiti il comando.
  173. ---
  174. ### Agente
  175. Usa la config `agent` per specificare opzionalmente quale [agente](/docs/agents) deve eseguire il comando.
  176. Se e un [subagent](/docs/agents/#subagents), il comando attiva per default l'invocazione di un subagent.
  177. Per disabilitare questo comportamento, imposta `subtask` a `false`.
  178. ```json title="opencode.json"
  179. {
  180. "command": {
  181. "review": {
  182. "agent": "plan"
  183. }
  184. }
  185. }
  186. ```
  187. Questa e un'opzione di config **opzionale**. Se non specificata, usa l'agente corrente.
  188. ---
  189. ### Sottotask
  190. Usa il booleano `subtask` per forzare il comando ad attivare l'invocazione di un [subagent](/docs/agents/#subagents).
  191. E utile se vuoi evitare che il comando inquini il contesto principale e **forza** l'agente ad agire come subagent,
  192. anche se `mode` e impostato su `primary` nella configurazione dell'[agente](/docs/agents).
  193. ```json title="opencode.json"
  194. {
  195. "command": {
  196. "analyze": {
  197. "subtask": true
  198. }
  199. }
  200. }
  201. ```
  202. Questa e un'opzione di config **opzionale**.
  203. ---
  204. ### Modello
  205. Usa la config `model` per sovrascrivere il modello predefinito per questo comando.
  206. ```json title="opencode.json"
  207. {
  208. "command": {
  209. "analyze": {
  210. "model": "anthropic/claude-3-5-sonnet-20241022"
  211. }
  212. }
  213. }
  214. ```
  215. Questa e un'opzione di config **opzionale**.
  216. ---
  217. ## Comandi integrati
  218. opencode include diversi comandi integrati come `/init`, `/undo`, `/redo`, `/share`, `/help`; [scopri di piu](/docs/tui#commands).
  219. :::note
  220. I comandi personalizzati possono sovrascrivere quelli integrati.
  221. :::
  222. Se definisci un comando personalizzato con lo stesso nome, sovrascrivera il comando integrato.