opencode-snippets 1.0.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +113 -30
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,29 +1,107 @@
1
1
  # opencode-snippets
2
2
 
3
- **Instant inline text expansion for OpenCode** - Type `#snippet` anywhere in your message and watch it transform.
3
+ **Instant inline text expansion for OpenCode** - Type `#snippet` anywhere in your message and watch it transform.
4
4
 
5
5
  ## Why Snippets?
6
6
 
7
- OpenCode has powerful `/slash` commands, but they must come first in your message. What if you want to inject context *mid-thought*?
7
+ As developers, we DRY (Don't Repeat Yourself) our code. We extract functions, create libraries, compose modules. Why should our prompts be any different?
8
+
9
+ Stop copy-pasting the same instructions into every message. Snippets bring software engineering principles to prompt engineering:
10
+
11
+ - 🔄 **DRY** - Write once, reuse everywhere
12
+ - 🧩 **Composability** - Build complex prompts from simple pieces
13
+ - 🔧 **Maintainability** - Update once, apply everywhere
14
+ - 🔍 **Discoverability** - Your team's best practices, always a `#hashtag` away
15
+
16
+ OpenCode's `/slash` commands must come first. Snippets work anywhere:
8
17
 
9
18
  ```
10
- # With slash commands (must be first):
19
+ # Slash commands (must be first):
11
20
  /git-status Please review my changes
12
21
 
13
- # With snippets (anywhere!):
22
+ # Snippets (anywhere!):
14
23
  Please review my changes #git-status and suggest improvements #code-style
15
24
  ```
16
25
 
17
- **Snippets work like `@file` mentions** - natural, inline, composable. Build complex prompts from reusable pieces without breaking your flow.
26
+ Snippets work like `@file` mentions - natural, inline, composable.
27
+
28
+ ### 🎯 Composable by Design
29
+
30
+ Snippets compose with each other and with slash commands. Reference `#snippets` anywhere - in your messages, in slash commands, even inside other snippets:
31
+
32
+ **Example: Slash commands as snippet proxies**
33
+
34
+ `~/.config/opencode/snippet/ralph.md`:
35
+ ```markdown
36
+ Start a ralph loop for this. Automatically guess how many iterations it will require if not specified.
37
+ #todofile
38
+ Give the path of the status/todo file to the ralph task and tell to continuously update it.
39
+ ```
40
+
41
+ `~/.config/opencode/command/ralph.md`:
42
+ ```markdown
43
+ ---
44
+ description: "Initiates a Ralph loop"
45
+ ---
46
+ #ralph
47
+
48
+ $ARGUMENTS
49
+ ```
50
+
51
+ The `/ralph` slash command simply expands the `#ralph` snippet and passes through arguments. Minimal boilerplate, maximum reuse.
52
+
53
+ **Example: Extending snippets with logic**
54
+
55
+ `~/.config/opencode/command/commit-and-push.md`:
56
+ ```markdown
57
+ ---
58
+ description: Create a git commit and push to remote
59
+ agent: fast
60
+ ---
61
+ Please create a git commit with the current changes and push to the remote repository.
62
+
63
+ Here is the current git status:
64
+ !`git status`
65
+
66
+ Here are the staged changes:
67
+ !`git diff --cached`
68
+
69
+ #conventional-commits
70
+ #project-context
71
+ ```
72
+
73
+ The slash command provides workflow logic (git status, diffs, push) while reusing shared snippets for commit conventions and project context.
74
+
75
+ **Example: Snippets composing snippets**
76
+
77
+ `~/.config/opencode/snippet/code-standards.md`:
78
+ ```markdown
79
+ #style-guide
80
+ #error-handling
81
+ #testing-requirements
82
+ ```
83
+
84
+ `~/.config/opencode/snippet/full-review.md`:
85
+ ```markdown
86
+ #code-standards
87
+ #security-checklist
88
+ #performance-tips
89
+ ```
90
+
91
+ Compose base snippets into higher-level ones. Type `#full-review` to inject all standards at once, keeping each concern in its own maintainable file.
92
+
93
+ **The power:** Mix and match. Type `#tdd #careful` for test-driven development with extra caution. Build `/commit #conventional-commits #project-context` for context-aware commits. Create layered prompts from small, reusable pieces.
18
94
 
19
95
  ## Installation
20
96
 
21
- ```bash
22
- # Add to your opencode.json plugins array:
23
- "plugins": ["opencode-snippets"]
97
+ Add to your `opencode.json` plugins array:
24
98
 
25
- # Then install:
26
- bun install
99
+ ```json
100
+ {
101
+ "plugins": [
102
+ "opencode-snippets"
103
+ ]
104
+ }
27
105
  ```
28
106
 
29
107
  ## Quick Start
@@ -39,7 +117,7 @@ mkdir -p ~/.config/opencode/snippet
39
117
  `~/.config/opencode/snippet/careful.md`:
40
118
  ```markdown
41
119
  ---
42
- aliases: ["safe", "cautious"]
120
+ aliases: safe
43
121
  ---
44
122
  Think step by step. Double-check your work before making changes.
45
123
  Ask clarifying questions if anything is ambiguous.
@@ -73,7 +151,9 @@ Define multiple triggers for the same snippet:
73
151
 
74
152
  ```markdown
75
153
  ---
76
- aliases: ["cp", "pick"]
154
+ aliases:
155
+ - cp
156
+ - pick
77
157
  description: "Git cherry-pick helper"
78
158
  ---
79
159
  Always pick parent 1 for merge commits.
@@ -81,9 +161,18 @@ Always pick parent 1 for merge commits.
81
161
 
82
162
  Now `#cherry-pick`, `#cp`, and `#pick` all expand to the same content.
83
163
 
164
+ Single alias doesn't need array syntax:
165
+ ```markdown
166
+ ---
167
+ aliases: safe
168
+ ---
169
+ ```
170
+
171
+ You can also use JSON array style: `aliases: ["cp", "pick"]`
172
+
84
173
  ### Shell Command Substitution
85
174
 
86
- Inject live system data with `!`backtick\`` syntax:
175
+ Snippets support the same `!`backtick\`` syntax as [OpenCode slash commands](https://opencode.ai/docs/commands/#shell-output) for injecting live command output:
87
176
 
88
177
  ```markdown
89
178
  Current branch: !`git branch --show-current`
@@ -91,16 +180,6 @@ Last commit: !`git log -1 --oneline`
91
180
  Working directory: !`pwd`
92
181
  ```
93
182
 
94
- Output:
95
- ```
96
- Current branch: $ git branch --show-current
97
- --> main
98
- Last commit: $ git log -1 --oneline
99
- --> abc123f feat: add new feature
100
- Working directory: $ pwd
101
- --> /home/user/project
102
- ```
103
-
104
183
  ### Recursive Includes
105
184
 
106
185
  Snippets can include other snippets:
@@ -119,7 +198,7 @@ Loop detection prevents infinite recursion.
119
198
  ### `~/.config/opencode/snippet/context.md`
120
199
  ```markdown
121
200
  ---
122
- aliases: ["ctx"]
201
+ aliases: ctx
123
202
  ---
124
203
  Project: !`basename $(pwd)`
125
204
  Branch: !`git branch --show-current`
@@ -129,7 +208,9 @@ Recent changes: !`git diff --stat HEAD~3 | tail -5`
129
208
  ### `~/.config/opencode/snippet/review.md`
130
209
  ```markdown
131
210
  ---
132
- aliases: ["pr", "check"]
211
+ aliases:
212
+ - pr
213
+ - check
133
214
  ---
134
215
  Review this code for:
135
216
  - Security vulnerabilities
@@ -142,7 +223,9 @@ Review this code for:
142
223
  ### `~/.config/opencode/snippet/minimal.md`
143
224
  ```markdown
144
225
  ---
145
- aliases: ["min", "terse"]
226
+ aliases:
227
+ - min
228
+ - terse
146
229
  ---
147
230
  Be extremely concise. No explanations unless asked.
148
231
  ```
@@ -151,10 +234,10 @@ Be extremely concise. No explanations unless asked.
151
234
 
152
235
  | Feature | `/commands` | `#snippets` |
153
236
  |---------|-------------|-------------|
154
- | Position | Must be first | Anywhere |
237
+ | Position | Must come first | Anywhere |
155
238
  | Multiple per message | No | Yes |
156
- | Live shell data | Via implementation | Built-in `!\`cmd\`` |
157
- | Best for | Actions & workflows | Context injection |
239
+ | Live shell data | Yes | Yes |
240
+ | Best for | Triggering actions & workflows | Context injection |
158
241
 
159
242
  **Use both together:**
160
243
  ```
@@ -182,7 +265,7 @@ Logs are written to `~/.config/opencode/logs/snippets/daily/`.
182
265
  - Snippets are loaded once at plugin startup
183
266
  - Hashtag matching is **case-insensitive** (`#Hello` = `#hello`)
184
267
  - Unknown hashtags are left unchanged
185
- - Failed shell commands preserve the `!\`cmd\`` syntax
268
+ - Failed shell commands preserve the original syntax in output
186
269
  - Frontmatter is stripped from expanded content
187
270
  - Only user messages are processed (not assistant responses)
188
271
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-snippets",
3
- "version": "1.0.0",
3
+ "version": "1.1.2",
4
4
  "description": "Hashtag-based snippet expansion plugin for OpenCode - instant inline text shortcuts",
5
5
  "main": "index.ts",
6
6
  "type": "module",