opencode-command-hooks 0.1.3 → 0.1.4
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 +19 -0
- package/README.md +15 -28
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# 🪝 OpenCode Command Hooks
|
|
2
2
|
|
|
3
|
-
Use simple configs to
|
|
4
|
-
|
|
5
|
-
Example use cases: run tests after a subagent finishes a task, auto-lint after writes, etc. You can also configure the hooks to run only when specified arguments are passed to a given tool. The plugin will handle sequential execution with failure recovery, output truncation, exit code capture, template interpolation, session context injection, toast notifications, toolArgs filtering, and non-blocking error handling.
|
|
3
|
+
Use simple configs to declaratively define shell command hooks on tool/subagent invocations. With a single line of configuration, you can inject a hook's output directly into context for your agent to read.
|
|
6
4
|
|
|
7
5
|
## Markdown Frontmatter Hooks
|
|
8
6
|
|
|
@@ -19,6 +17,14 @@ hooks:
|
|
|
19
17
|
---
|
|
20
18
|
````
|
|
21
19
|
|
|
20
|
+
## Table of Contents
|
|
21
|
+
|
|
22
|
+
- [Features](#features)
|
|
23
|
+
- [Installation](#installation)
|
|
24
|
+
- [Configuration](#configuration)
|
|
25
|
+
- [Examples](#examples)
|
|
26
|
+
- [Template Placeholders](#template-placeholders)
|
|
27
|
+
|
|
22
28
|
### How It Works
|
|
23
29
|
|
|
24
30
|
1. **Runs automatically** on the configured event
|
|
@@ -143,14 +149,14 @@ You can set up tool hooks to only trigger on specific arguments via `when.toolAr
|
|
|
143
149
|
|
|
144
150
|
## Features
|
|
145
151
|
|
|
146
|
-
- Tool hooks (`before`/`after`) and session hooks (`start`/`idle`)
|
|
152
|
+
- Tool hooks (`before`/`after`) and session hooks (`start`/`idle`) via simple JSON/YAML frontmatter config
|
|
147
153
|
- Hooks are **non-blocking**: failures don’t crash the session/tool.
|
|
148
154
|
- Commands run **sequentially**, even if earlier ones fail.
|
|
155
|
+
- Inject bash output into context with `inject` and notify user with `toast`
|
|
149
156
|
- `inject`/`toast` interpolate using the **last command’s** output if `run` is an array.
|
|
150
|
-
- Match by tool name
|
|
157
|
+
- Match by tool name and (optionally) arguments
|
|
151
158
|
- Optional session injection and toast notifications
|
|
152
|
-
-
|
|
153
|
-
- Debug logging via `OPENCODE_HOOKS_DEBUG=1`
|
|
159
|
+
- Automatic output truncation (30,000 by default)
|
|
154
160
|
|
|
155
161
|
---
|
|
156
162
|
|
|
@@ -221,7 +227,7 @@ hooks:
|
|
|
221
227
|
|
|
222
228
|
## Examples
|
|
223
229
|
|
|
224
|
-
###
|
|
230
|
+
### Automatically run typecheck, lint, and test (after `task`)
|
|
225
231
|
|
|
226
232
|
Run validation after certain subagents complete, inject results back into the session, and show a small toast.
|
|
227
233
|
|
|
@@ -304,25 +310,6 @@ Tool-arg matching is exact. This example runs only when the tool arg `path` equa
|
|
|
304
310
|
}
|
|
305
311
|
```
|
|
306
312
|
|
|
307
|
-
### Handle Async Tool Completion (`tool.result`)
|
|
308
|
-
|
|
309
|
-
```jsonc
|
|
310
|
-
{
|
|
311
|
-
"tool": [
|
|
312
|
-
{
|
|
313
|
-
"id": "task-result-hook",
|
|
314
|
-
"when": {
|
|
315
|
-
"phase": "after",
|
|
316
|
-
"tool": "task",
|
|
317
|
-
"toolArgs": { "subagent_type": "code-writer" },
|
|
318
|
-
},
|
|
319
|
-
"run": ["npm run validate-changes"],
|
|
320
|
-
"toast": { "title": "Code Writer", "message": "exit {exitCode}" },
|
|
321
|
-
},
|
|
322
|
-
],
|
|
323
|
-
}
|
|
324
|
-
```
|
|
325
|
-
|
|
326
313
|
### Session Lifecycle Hooks
|
|
327
314
|
|
|
328
315
|
```jsonc
|
|
@@ -436,4 +423,4 @@ export const MyHooks: Plugin = async ({ $, client }) => {
|
|
|
436
423
|
},
|
|
437
424
|
};
|
|
438
425
|
};
|
|
439
|
-
```
|
|
426
|
+
```
|
package/package.json
CHANGED