opencode-froggy 0.1.0 → 0.2.0
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.
- package/LICENSE +21 -0
- package/README.md +383 -246
- package/agent/architect.md +91 -0
- package/agent/partner.md +143 -0
- package/agent/rubber-duck.md +129 -0
- package/command/commit-push.md +21 -0
- package/command/doc-changes.md +45 -0
- package/command/review-changes.md +1 -21
- package/command/review-pr.md +1 -22
- package/command/send-to.md +21 -0
- package/command/simplify-changes.md +2 -20
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -52
- package/dist/index.test.js +29 -8
- package/dist/loaders.d.ts +9 -5
- package/dist/loaders.js +5 -1
- package/dist/tools/diff-summary.d.ts +20 -0
- package/dist/tools/diff-summary.js +111 -0
- package/dist/tools/gitingest.d.ts +26 -0
- package/dist/tools/gitingest.js +41 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.js +4 -0
- package/dist/tools/list-child-sessions.d.ts +9 -0
- package/dist/tools/list-child-sessions.js +24 -0
- package/dist/tools/prompt-session.d.ts +19 -0
- package/dist/tools/prompt-session.js +39 -0
- package/dist/tools/reply-child.d.ts +19 -0
- package/dist/tools/reply-child.js +42 -0
- package/images/logo.png +0 -0
- package/package.json +4 -2
- package/command/commit.md +0 -18
package/README.md
CHANGED
|
@@ -1,51 +1,266 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="images/logo.png" alt="opencode-froggy logo" width="300">
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://github.com/smartfrog/opencode-froggy/actions"><img src="https://github.com/smartfrog/opencode-froggy/workflows/CI/badge.svg" alt="CI"></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/opencode-froggy"><img src="https://badge.fury.io/js/opencode-froggy.svg" alt="npm version"></a>
|
|
8
|
+
</p>
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
It can automatically simplify changes when the session becomes idle, if files were modified
|
|
7
|
-
via `write` or `edit`. Resources are loaded automatically from `agent/`, `command/`, and `skill/`.
|
|
8
|
-
Hooks are loaded from OpenCode configuration directories (global and project-level).
|
|
10
|
+
Plugin providing Claude Code–style hooks, specialized agents (doc-writer, code reviewer, architect, partner, etc.), dedicated commands such as simplify-code and review-pr, and tools such as gitingest.
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
---
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
## Table of Contents
|
|
15
|
+
|
|
16
|
+
- [Installation](#installation)
|
|
17
|
+
- [Commands](#commands)
|
|
18
|
+
- [Agents](#agents)
|
|
19
|
+
- [Tools](#tools)
|
|
20
|
+
- [gitingest](#gitingest)
|
|
21
|
+
- [diff-summary](#diff-summary)
|
|
22
|
+
- [prompt-session](#prompt-session)
|
|
23
|
+
- [list-child-sessions](#list-child-sessions)
|
|
24
|
+
- [Hooks](#hooks)
|
|
25
|
+
- [Configuration Locations](#configuration-locations)
|
|
26
|
+
- [Configuration File Format](#configuration-file-format)
|
|
27
|
+
- [Supported Events](#supported-events)
|
|
28
|
+
- [Conditions](#conditions)
|
|
29
|
+
- [Supported Actions](#supported-actions)
|
|
30
|
+
- [Execution Behavior](#execution-behavior)
|
|
31
|
+
- [Example Hook Configurations](#example-hook-configurations)
|
|
32
|
+
- [Configuration Options](#configuration-options)
|
|
33
|
+
- [License](#license)
|
|
13
34
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
### From npm (recommended)
|
|
40
|
+
|
|
41
|
+
Add the plugin to your OpenCode configuration file (`opencode.json`):
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"$schema": "https://opencode.ai/config.json",
|
|
46
|
+
"plugin": ["opencode-froggy"]
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### From local files
|
|
19
51
|
|
|
20
|
-
|
|
52
|
+
Alternatively, clone or copy the plugin files to one of these directories:
|
|
53
|
+
|
|
54
|
+
- **Project-local**: `.opencode/plugin/opencode-froggy/`
|
|
55
|
+
- **Global**: `~/.config/opencode/plugin/opencode-froggy/`
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Commands
|
|
21
60
|
|
|
22
61
|
| Command | Description | Agent |
|
|
23
62
|
|---------|-------------|-------|
|
|
24
|
-
| `/commit` |
|
|
63
|
+
| `/commit-push` | Stage, commit, and push changes with user confirmation | `build` |
|
|
64
|
+
| `/doc-changes` | Update documentation based on uncommitted changes (new features only) | `doc-writer` |
|
|
25
65
|
| `/review-changes` | Review uncommitted changes (staged + unstaged, including untracked files) | `code-reviewer` |
|
|
26
66
|
| `/review-pr <source> <target>` | Review changes from source branch into target branch | `code-reviewer` |
|
|
67
|
+
| `/send-to [agent] <message>` | Send a message to a child session (subagent) to continue the conversation | - |
|
|
27
68
|
| `/simplify-changes` | Simplify uncommitted changes (staged + unstaged, including untracked files) | `code-simplifier` |
|
|
28
69
|
| `/tests-coverage` | Run the full test suite with coverage report and suggest fixes for failures | `build` |
|
|
29
70
|
|
|
30
|
-
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Agents
|
|
74
|
+
|
|
75
|
+
| Agent | Mode | Description |
|
|
76
|
+
|-------|------|-------------|
|
|
77
|
+
| `architect` | subagent | Strategic technical advisor providing high-leverage guidance on architecture, code structure, and complex engineering trade-offs. Read-only. |
|
|
78
|
+
| `code-reviewer` | subagent | Reviews code for quality, correctness, and security. Read-only with restricted git access. |
|
|
79
|
+
| `code-simplifier` | subagent | Simplifies recently modified code for clarity and maintainability while strictly preserving behavior. |
|
|
80
|
+
| `doc-writer` | subagent | Technical writer that crafts clear, comprehensive documentation (README, API docs, architecture docs, user guides). |
|
|
81
|
+
| `partner` | subagent | Strategic ideation partner that breaks frames, expands solution spaces, and surfaces non-obvious strategic options. Read-only. |
|
|
82
|
+
| `rubber-duck` | subagent | Strategic thinking partner for exploratory dialogue. Challenges assumptions, asks pointed questions, and sharpens thinking through conversational friction. Read-only. |
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Tools
|
|
87
|
+
|
|
88
|
+
### gitingest
|
|
89
|
+
|
|
90
|
+
Fetch a GitHub repository's full content via gitingest.com. Returns summary, directory tree, and file contents optimized for LLM analysis. Use when you need to understand an external repository's structure or code.
|
|
91
|
+
|
|
92
|
+
#### Parameters
|
|
93
|
+
|
|
94
|
+
| Parameter | Type | Required | Default | Description |
|
|
95
|
+
|-----------|------|----------|---------|-------------|
|
|
96
|
+
| `url` | `string` | Yes | - | The GitHub repository URL to fetch |
|
|
97
|
+
| `maxFileSize` | `number` | No | `50000` | Maximum file size in bytes to include |
|
|
98
|
+
| `pattern` | `string` | No | `""` | Glob pattern to filter files (e.g., `*.ts`, `src/**/*.py`) |
|
|
99
|
+
| `patternType` | `"include"` \| `"exclude"` | No | `"exclude"` | Whether to include or exclude files matching the pattern |
|
|
100
|
+
|
|
101
|
+
#### Usage Examples
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
// Fetch entire repository
|
|
105
|
+
gitingest({ url: "https://github.com/user/repo" })
|
|
106
|
+
|
|
107
|
+
// Only TypeScript files
|
|
108
|
+
gitingest({
|
|
109
|
+
url: "https://github.com/user/repo",
|
|
110
|
+
pattern: "*.ts",
|
|
111
|
+
patternType: "include"
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
// Exclude test files
|
|
115
|
+
gitingest({
|
|
116
|
+
url: "https://github.com/user/repo",
|
|
117
|
+
pattern: "*.test.ts",
|
|
118
|
+
patternType: "exclude"
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
// Increase max file size to 100KB
|
|
122
|
+
gitingest({
|
|
123
|
+
url: "https://github.com/user/repo",
|
|
124
|
+
maxFileSize: 100000
|
|
125
|
+
})
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### Limitations
|
|
129
|
+
|
|
130
|
+
- Content is truncated to 300k characters (server-side limit from gitingest.com)
|
|
131
|
+
- For large repositories, use pattern filtering to focus on relevant files
|
|
132
|
+
- The `maxFileSize` parameter controls individual file size, not total output size
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
### diff-summary
|
|
137
|
+
|
|
138
|
+
Generate a structured summary of git diffs. Use for reviewing branch comparisons or working tree changes. Returns stats, commits, files changed, and full diff in a structured markdown format.
|
|
139
|
+
|
|
140
|
+
#### Parameters
|
|
141
|
+
|
|
142
|
+
| Parameter | Type | Required | Default | Description |
|
|
143
|
+
|-----------|------|----------|---------|-------------|
|
|
144
|
+
| `source` | `string` | No | - | Source branch to compare (e.g., `feature-branch`). If omitted, analyzes working tree changes. |
|
|
145
|
+
| `target` | `string` | No | `main` | Target branch to compare against |
|
|
146
|
+
| `remote` | `string` | No | `origin` | Git remote name |
|
|
147
|
+
|
|
148
|
+
#### Usage Examples
|
|
31
149
|
|
|
32
|
-
|
|
150
|
+
```typescript
|
|
151
|
+
// Analyze working tree changes (staged, unstaged, and untracked files)
|
|
152
|
+
diffSummary({})
|
|
33
153
|
|
|
34
|
-
|
|
154
|
+
// Compare feature branch against main
|
|
155
|
+
diffSummary({ source: "feature-branch" })
|
|
35
156
|
|
|
157
|
+
// Compare feature branch against develop
|
|
158
|
+
diffSummary({
|
|
159
|
+
source: "feature-branch",
|
|
160
|
+
target: "develop"
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
// Compare branches on a different remote
|
|
164
|
+
diffSummary({
|
|
165
|
+
source: "feature-branch",
|
|
166
|
+
target: "main",
|
|
167
|
+
remote: "upstream"
|
|
168
|
+
})
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Output Structure
|
|
172
|
+
|
|
173
|
+
**For branch comparisons:**
|
|
174
|
+
- Stats Overview: Summary of changes (insertions, deletions)
|
|
175
|
+
- Commits to Review: List of commits in the range
|
|
176
|
+
- Files Changed: List of modified files
|
|
177
|
+
- Full Diff: Complete diff with context
|
|
178
|
+
|
|
179
|
+
**For working tree changes:**
|
|
180
|
+
- Status Overview: Git status output
|
|
181
|
+
- Staged Changes: Stats, files, and diff for staged changes
|
|
182
|
+
- Unstaged Changes: Stats, files, and diff for unstaged changes
|
|
183
|
+
- Untracked Files: List and diffs for new untracked files
|
|
184
|
+
|
|
185
|
+
#### Notes
|
|
186
|
+
|
|
187
|
+
- When comparing branches, the tool fetches from the remote before generating the diff
|
|
188
|
+
- Diffs include 5 lines of context and function context for better readability
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
### prompt-session
|
|
193
|
+
|
|
194
|
+
Send a message to a child session (subagent) to continue the conversation. Useful for iterating with subagents without creating new sessions.
|
|
195
|
+
|
|
196
|
+
#### Parameters
|
|
197
|
+
|
|
198
|
+
| Parameter | Type | Required | Default | Description |
|
|
199
|
+
|-----------|------|----------|---------|-------------|
|
|
200
|
+
| `message` | `string` | Yes | - | The message to send to the child session |
|
|
201
|
+
| `sessionId` | `string` | No | - | The child session ID to target. If omitted, targets the last child session. |
|
|
202
|
+
|
|
203
|
+
#### Usage Examples
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
// Send a message to the last child session
|
|
207
|
+
promptSession({ message: "Please also add unit tests for the new function" })
|
|
208
|
+
|
|
209
|
+
// Send a message to a specific child session
|
|
210
|
+
promptSession({
|
|
211
|
+
message: "Can you clarify the error handling approach?",
|
|
212
|
+
sessionId: "abc123"
|
|
213
|
+
})
|
|
36
214
|
```
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
215
|
+
|
|
216
|
+
#### Behavior
|
|
217
|
+
|
|
218
|
+
- If `sessionId` is not provided, the tool automatically targets the most recently created child session
|
|
219
|
+
- Returns the text response from the child session
|
|
220
|
+
- Returns an error message if no child session exists for the current session
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
### list-child-sessions
|
|
225
|
+
|
|
226
|
+
List all child sessions (subagents) of the current session. Useful for finding specific sessions to target with `prompt-session`.
|
|
227
|
+
|
|
228
|
+
#### Parameters
|
|
229
|
+
|
|
230
|
+
This tool takes no parameters.
|
|
231
|
+
|
|
232
|
+
#### Usage Examples
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
// List all child sessions
|
|
236
|
+
listChildSessions()
|
|
40
237
|
```
|
|
41
238
|
|
|
42
|
-
|
|
239
|
+
#### Output
|
|
43
240
|
|
|
44
|
-
|
|
241
|
+
Returns a formatted list of child sessions with:
|
|
242
|
+
- Session ID
|
|
243
|
+
- Session title
|
|
244
|
+
- Created and updated timestamps
|
|
245
|
+
|
|
246
|
+
Example output:
|
|
247
|
+
```
|
|
248
|
+
Child sessions (2):
|
|
249
|
+
|
|
250
|
+
1. [abc123] Code Review Session
|
|
251
|
+
Created: 2024-01-15T10:30:00Z | Updated: 2024-01-15T10:35:00Z
|
|
252
|
+
|
|
253
|
+
2. [def456] Architecture Discussion
|
|
254
|
+
Created: 2024-01-15T11:00:00Z | Updated: 2024-01-15T11:15:00Z
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Hooks
|
|
45
260
|
|
|
46
261
|
Hooks run actions on session events. Configuration is loaded from standard OpenCode configuration directories.
|
|
47
262
|
|
|
48
|
-
|
|
263
|
+
### Configuration Locations
|
|
49
264
|
|
|
50
265
|
Hooks are loaded from these locations (in order, merged together):
|
|
51
266
|
|
|
@@ -59,11 +274,11 @@ On Windows, `~/.config` is preferred for cross-platform consistency. If hooks ex
|
|
|
59
274
|
|
|
60
275
|
Global hooks run first, then project hooks are added. Hooks from both sources are combined (not overridden).
|
|
61
276
|
|
|
62
|
-
|
|
277
|
+
### Configuration File Format
|
|
63
278
|
|
|
64
|
-
- YAML frontmatter must include a `hooks` list
|
|
65
|
-
- Each hook defines `event`, `actions`, and optional `conditions
|
|
66
|
-
- Hooks for the same event run in declaration order
|
|
279
|
+
- YAML frontmatter must include a `hooks` list
|
|
280
|
+
- Each hook defines `event`, `actions`, and optional `conditions`
|
|
281
|
+
- Hooks for the same event run in declaration order
|
|
67
282
|
|
|
68
283
|
Example `hooks.md`:
|
|
69
284
|
|
|
@@ -77,7 +292,7 @@ hooks:
|
|
|
77
292
|
---
|
|
78
293
|
```
|
|
79
294
|
|
|
80
|
-
|
|
295
|
+
### Supported Events
|
|
81
296
|
|
|
82
297
|
| Event | Description |
|
|
83
298
|
|-------|-------------|
|
|
@@ -89,17 +304,19 @@ hooks:
|
|
|
89
304
|
| `tool.after.*` | Emitted after any tool executes |
|
|
90
305
|
| `tool.after.<name>` | Emitted after a specific tool (e.g., `tool.after.edit`) |
|
|
91
306
|
|
|
92
|
-
|
|
307
|
+
#### Tool Hook Execution Order
|
|
308
|
+
|
|
93
309
|
1. `tool.before.*` (all tools)
|
|
94
310
|
2. `tool.before.<name>` (specific tool)
|
|
95
311
|
3. *(tool executes)*
|
|
96
312
|
4. `tool.after.*` (all tools)
|
|
97
313
|
5. `tool.after.<name>` (specific tool)
|
|
98
314
|
|
|
99
|
-
|
|
315
|
+
#### Blocking Tools with Exit Code 2
|
|
316
|
+
|
|
100
317
|
For `tool.before.*` and `tool.before.<name>` hooks, a bash action returning exit code 2 will block the tool from executing. The stderr output is displayed to the user as the block reason.
|
|
101
318
|
|
|
102
|
-
|
|
319
|
+
### Conditions
|
|
103
320
|
|
|
104
321
|
| Condition | Description |
|
|
105
322
|
|-----------|-------------|
|
|
@@ -108,115 +325,126 @@ For `tool.before.*` and `tool.before.<name>` hooks, a bash action returning exit
|
|
|
108
325
|
|
|
109
326
|
All listed conditions must pass for the hook to run.
|
|
110
327
|
|
|
111
|
-
Code extensions treated as "code"
|
|
328
|
+
**Code extensions treated as "code":**
|
|
329
|
+
|
|
112
330
|
`ts`, `tsx`, `js`, `jsx`, `mjs`, `cjs`, `json`, `yml`, `yaml`, `toml`, `css`, `scss`, `sass`, `less`, `html`, `vue`, `svelte`, `go`, `rs`, `c`, `h`, `cpp`, `cc`, `cxx`, `hpp`, `java`, `py`, `rb`, `php`, `sh`, `bash`, `kt`, `kts`, `swift`, `m`, `mm`, `cs`, `fs`, `scala`, `clj`, `hs`, `lua`.
|
|
113
331
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
332
|
+
### Supported Actions
|
|
333
|
+
|
|
334
|
+
#### Command Action
|
|
335
|
+
|
|
336
|
+
Execute a plugin command.
|
|
337
|
+
|
|
338
|
+
```yaml
|
|
339
|
+
# Short form
|
|
340
|
+
- command: simplify-changes
|
|
341
|
+
|
|
342
|
+
# With arguments
|
|
343
|
+
- command:
|
|
344
|
+
name: review-pr
|
|
345
|
+
args: "main feature"
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
If the command exists in config, the plugin reuses its `agent` and `model`.
|
|
349
|
+
|
|
350
|
+
#### Tool Action
|
|
351
|
+
|
|
352
|
+
Prompt the session to use a tool with specific arguments.
|
|
353
|
+
|
|
354
|
+
```yaml
|
|
355
|
+
- tool:
|
|
356
|
+
name: bash
|
|
357
|
+
args: { command: "echo done" }
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
#### Bash Action
|
|
361
|
+
|
|
362
|
+
Execute a shell command directly without involving the LLM. Useful for running linters, formatters, build scripts, or custom automation.
|
|
363
|
+
|
|
364
|
+
**Configuration:**
|
|
365
|
+
|
|
366
|
+
```yaml
|
|
367
|
+
# Short form
|
|
368
|
+
- bash: "npm run lint"
|
|
369
|
+
|
|
370
|
+
# Long form with custom timeout
|
|
371
|
+
- bash:
|
|
372
|
+
command: "$OPENCODE_PROJECT_DIR/.opencode/hooks/init.sh"
|
|
373
|
+
timeout: 30000 # milliseconds (default: 60000)
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
**Environment Variables:**
|
|
377
|
+
|
|
378
|
+
The plugin injects these variables into the child process environment:
|
|
379
|
+
|
|
380
|
+
| Variable | Value | Use case |
|
|
381
|
+
|----------|-------|----------|
|
|
382
|
+
| `OPENCODE_PROJECT_DIR` | Absolute path to the project (e.g., `/home/user/project`) | Reference project files from scripts located elsewhere |
|
|
383
|
+
| `OPENCODE_SESSION_ID` | The OpenCode session identifier | Logging, tracing, or conditioning actions based on session |
|
|
384
|
+
|
|
385
|
+
**Stdin JSON Context:**
|
|
386
|
+
|
|
387
|
+
The command receives a JSON object via stdin with session context:
|
|
388
|
+
|
|
389
|
+
```json
|
|
390
|
+
{
|
|
391
|
+
"session_id": "abc123",
|
|
392
|
+
"event": "session.idle",
|
|
393
|
+
"cwd": "/path/to/project",
|
|
394
|
+
"files": ["src/index.ts", "src/utils.ts"]
|
|
395
|
+
}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
The `files` array is only present for `session.idle` events and contains paths modified via `write` or `edit`.
|
|
399
|
+
|
|
400
|
+
For tool hooks (`tool.before.*`, `tool.after.*`), additional fields are provided:
|
|
401
|
+
|
|
402
|
+
```json
|
|
403
|
+
{
|
|
404
|
+
"session_id": "abc123",
|
|
405
|
+
"event": "tool.before.write",
|
|
406
|
+
"cwd": "/path/to/project",
|
|
407
|
+
"tool_name": "write",
|
|
408
|
+
"tool_args": { "filePath": "src/index.ts", "content": "..." }
|
|
409
|
+
}
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
**Environment Variables vs Stdin JSON:**
|
|
413
|
+
|
|
414
|
+
- **Environment variables**: Direct access via `$VAR`, convenient for simple values like paths and IDs
|
|
415
|
+
- **Stdin JSON**: Contains richer context (event type, working directory, modified files), requires parsing with `jq` or similar
|
|
416
|
+
|
|
417
|
+
Both mechanisms are complementary. Use environment variables for quick access to project path and session ID; use stdin JSON when you need event details or the list of modified files.
|
|
418
|
+
|
|
419
|
+
**Exit Codes:**
|
|
420
|
+
|
|
421
|
+
| Code | Behavior |
|
|
422
|
+
|------|----------|
|
|
423
|
+
| `0` | Success, continue to next action |
|
|
424
|
+
| `2` | Blocking error, stop remaining actions in this hook |
|
|
425
|
+
| Other | Non-blocking error, log warning and continue |
|
|
426
|
+
|
|
427
|
+
**Result Feedback:**
|
|
428
|
+
|
|
429
|
+
Bash hook results are automatically sent back to your session:
|
|
430
|
+
|
|
431
|
+
```
|
|
432
|
+
[BASH HOOK ✓] npm run lint
|
|
433
|
+
Exit: 0 | Duration: 1234ms
|
|
434
|
+
Stdout: All files passed linting
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
The feedback includes a status icon (✓ success, ✗ failure), exit code, execution duration, and stdout/stderr output (truncated to 500 characters). This message appears in your session but does not trigger a response from the assistant.
|
|
438
|
+
|
|
439
|
+
### Execution Behavior
|
|
440
|
+
|
|
441
|
+
- Action errors are logged and do not stop later actions
|
|
442
|
+
- `session.idle` only fires if files were modified via `write` or `edit`; the session's modified file list is cleared after the hook runs
|
|
443
|
+
- The main session is set on `session.created` with no parent, or on the first `session.idle` if needed
|
|
444
|
+
|
|
445
|
+
### Example Hook Configurations
|
|
446
|
+
|
|
447
|
+
#### Basic Multi-Hook Setup
|
|
220
448
|
|
|
221
449
|
```markdown
|
|
222
450
|
---
|
|
@@ -238,9 +466,8 @@ hooks:
|
|
|
238
466
|
---
|
|
239
467
|
```
|
|
240
468
|
|
|
241
|
-
####
|
|
469
|
+
#### Simple Lint-on-Idle Hook
|
|
242
470
|
|
|
243
|
-
**Simple lint-on-idle hook:**
|
|
244
471
|
```yaml
|
|
245
472
|
hooks:
|
|
246
473
|
- event: session.idle
|
|
@@ -249,7 +476,10 @@ hooks:
|
|
|
249
476
|
- bash: "npm run lint --fix"
|
|
250
477
|
```
|
|
251
478
|
|
|
252
|
-
|
|
479
|
+
#### Custom Initialization Script
|
|
480
|
+
|
|
481
|
+
`.opencode/hooks/init.sh`:
|
|
482
|
+
|
|
253
483
|
```bash
|
|
254
484
|
#!/bin/bash
|
|
255
485
|
set -e
|
|
@@ -269,7 +499,8 @@ echo "Project: $OPENCODE_PROJECT_DIR"
|
|
|
269
499
|
exit 0
|
|
270
500
|
```
|
|
271
501
|
|
|
272
|
-
|
|
502
|
+
#### Conditional Blocking Based on Lint Errors
|
|
503
|
+
|
|
273
504
|
```bash
|
|
274
505
|
#!/bin/bash
|
|
275
506
|
# Run linter and block if critical errors found
|
|
@@ -281,9 +512,8 @@ else
|
|
|
281
512
|
fi
|
|
282
513
|
```
|
|
283
514
|
|
|
284
|
-
####
|
|
515
|
+
#### Block Modifications to Sensitive Files
|
|
285
516
|
|
|
286
|
-
**Block modifications to sensitive files:**
|
|
287
517
|
```yaml
|
|
288
518
|
hooks:
|
|
289
519
|
- event: tool.before.write
|
|
@@ -305,7 +535,8 @@ hooks:
|
|
|
305
535
|
fi
|
|
306
536
|
```
|
|
307
537
|
|
|
308
|
-
|
|
538
|
+
#### Auto-Format TypeScript Files After Write
|
|
539
|
+
|
|
309
540
|
```yaml
|
|
310
541
|
hooks:
|
|
311
542
|
- event: tool.after.write
|
|
@@ -317,7 +548,8 @@ hooks:
|
|
|
317
548
|
fi
|
|
318
549
|
```
|
|
319
550
|
|
|
320
|
-
|
|
551
|
+
#### Log All Tool Executions
|
|
552
|
+
|
|
321
553
|
```yaml
|
|
322
554
|
hooks:
|
|
323
555
|
- event: tool.before.*
|
|
@@ -328,112 +560,17 @@ hooks:
|
|
|
328
560
|
echo "[$(date)] Tool: $tool" >> /tmp/opencode-tools.log
|
|
329
561
|
```
|
|
330
562
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
Add the plugin to your OpenCode configuration file at `~/.config/opencode/opencode.json`:
|
|
334
|
-
|
|
335
|
-
```json
|
|
336
|
-
{
|
|
337
|
-
"plugin": {
|
|
338
|
-
"froggy": {
|
|
339
|
-
"path": "/path/to/opencode-froggy"
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
Or if published to npm:
|
|
346
|
-
|
|
347
|
-
```json
|
|
348
|
-
{
|
|
349
|
-
"plugin": {
|
|
350
|
-
"froggy": {
|
|
351
|
-
"module": "opencode-froggy"
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
## Usage
|
|
358
|
-
|
|
359
|
-
### Review uncommitted changes
|
|
360
|
-
|
|
361
|
-
```
|
|
362
|
-
/review-changes
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
Reviews all staged, unstaged, and untracked changes in the working tree.
|
|
366
|
-
|
|
367
|
-
### Review a pull request
|
|
368
|
-
|
|
369
|
-
```
|
|
370
|
-
/review-pr feature-branch main
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
Fetches and reviews changes from `origin/feature-branch` into `origin/main`.
|
|
374
|
-
|
|
375
|
-
### Simplify uncommitted changes
|
|
376
|
-
|
|
377
|
-
```
|
|
378
|
-
/simplify-changes
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
Analyzes and simplifies all uncommitted changes while preserving behavior.
|
|
382
|
-
|
|
383
|
-
### Commit and push
|
|
384
|
-
|
|
385
|
-
```
|
|
386
|
-
/commit
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
Creates a branch (if on main/master), commits with an appropriate message, and pushes.
|
|
390
|
-
|
|
391
|
-
### Run tests with coverage
|
|
392
|
-
|
|
393
|
-
```
|
|
394
|
-
/tests-coverage
|
|
395
|
-
```
|
|
396
|
-
|
|
397
|
-
Runs the test suite with coverage and suggests fixes for failures.
|
|
563
|
+
---
|
|
398
564
|
|
|
399
565
|
## Configuration Options
|
|
400
566
|
|
|
401
|
-
The plugin does not require additional configuration. Agents, commands, and skills are loaded automatically from the `agent/`, `command/`, and `skill/` directories within the plugin. Hooks are loaded from the standard OpenCode configuration directories (see Hooks section
|
|
567
|
+
The plugin does not require additional configuration. Agents, commands, and skills are loaded automatically from the `agent/`, `command/`, and `skill/` directories within the plugin. Hooks are loaded from the standard OpenCode configuration directories (see [Hooks](#hooks) section).
|
|
402
568
|
|
|
403
569
|
### Supported Code File Extensions
|
|
404
570
|
|
|
405
|
-
The `hasCodeChange` condition checks file extensions against the default set listed in the
|
|
406
|
-
|
|
407
|
-
## Development
|
|
408
|
-
|
|
409
|
-
### Prerequisites
|
|
410
|
-
|
|
411
|
-
- Node.js 18+
|
|
412
|
-
- npm
|
|
413
|
-
|
|
414
|
-
### Setup
|
|
415
|
-
|
|
416
|
-
```bash
|
|
417
|
-
npm install
|
|
418
|
-
```
|
|
571
|
+
The `hasCodeChange` condition checks file extensions against the default set listed in the [Conditions](#conditions) section. Hooks without any conditions still trigger on any modified file paths tracked via `write` or `edit` in the current session.
|
|
419
572
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
```bash
|
|
423
|
-
npm run build
|
|
424
|
-
```
|
|
425
|
-
|
|
426
|
-
### Run tests
|
|
427
|
-
|
|
428
|
-
```bash
|
|
429
|
-
npm test
|
|
430
|
-
```
|
|
431
|
-
|
|
432
|
-
### Type checking
|
|
433
|
-
|
|
434
|
-
```bash
|
|
435
|
-
npm run typecheck
|
|
436
|
-
```
|
|
573
|
+
---
|
|
437
574
|
|
|
438
575
|
## License
|
|
439
576
|
|