opencode-commit-guard 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Omkar Chandorkar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # opencode-commit-guard
2
+
3
+ OpenCode V2 plugin that enforces git commit message format rules during agent sessions.
4
+
5
+ ## Overview
6
+
7
+ `opencode-commit-guard` intercepts `shell` and `bash` tool execution before it runs.
8
+ When an agent attempts a `git commit`, the plugin inspects the command line, message flags, and message content.
9
+ If the commit violates configured formatting standards, the plugin rejects the tool call immediately by throwing a descriptive error.
10
+
11
+ ### Why this approach fits
12
+
13
+ - Operates strictly inside OpenCode agent sessions.
14
+ - Leaves system git hooks, Gerrit Change-Id hooks, and repository configuration untouched.
15
+ - Gives the agent an immediate error explaining the rule violation and providing a conforming example.
16
+ - Allows the agent to correct the message and retry without corrupting repository state.
17
+
18
+ ## Installation
19
+
20
+ Add the plugin to your `opencode.json` configuration file:
21
+
22
+ ```json
23
+ {
24
+ "plugins": [
25
+ {
26
+ "package": "opencode-commit-guard"
27
+ }
28
+ ]
29
+ }
30
+ ```
31
+
32
+ You can also specify custom configuration options:
33
+
34
+ ```json
35
+ {
36
+ "plugins": [
37
+ {
38
+ "package": "opencode-commit-guard",
39
+ "options": {
40
+ "requireScope": true,
41
+ "allowedScopes": ["kernel", "releasetools", "build", "ui"],
42
+ "maxLineLength": 72,
43
+ "requireSignoff": true
44
+ }
45
+ }
46
+ ]
47
+ }
48
+ ```
49
+
50
+ ## Configuration options
51
+
52
+ | Option | Type | Default | Description |
53
+ |---|---|---|---|
54
+ | `requireScope` | `boolean` | `true` | Requires the first line to match `<scope>: <subject>`. |
55
+ | `allowedScopes` | `string[]` | `undefined` | Restricts allowed scope identifiers to a specified list. |
56
+ | `maxLineLength` | `number` | `72` | Limits every line in the subject and body to this length. Set to `0` to disable. |
57
+ | `requireSignoff` | `boolean` | `true` | Requires `-s`/`--signoff` or a `Signed-off-by:` trailer. |
58
+
59
+ ## Formatting rules
60
+
61
+ ### 1. Scope prefix (`requireScope`)
62
+
63
+ The first line of the commit message must follow the `<scope>: <subject>` pattern.
64
+ Both standard lowercase scopes and conventional commit formats are valid:
65
+
66
+ - `kernel: add support for new thermal sensor`
67
+ - `releasetools: fix ota package generation`
68
+ - `feat(parser): add subshell tokenization`
69
+ - `fix(ui): resolve button alignment issue`
70
+
71
+ The plugin rejects subject lines that omit the colon, leave the scope empty, or omit the space after the colon:
72
+
73
+ - Invalid: `Add support for new thermal sensor`
74
+ - Invalid: `: add support for new thermal sensor`
75
+ - Invalid: `kernel:add support for new thermal sensor`
76
+
77
+ ### 2. Allowed scopes (`allowedScopes`)
78
+
79
+ When `allowedScopes` contains values, the extracted scope must match an entry in the list.
80
+ For conventional commits such as `feat(parser): ...`, the plugin accepts either the inner scope (`parser`), the full scope token (`feat(parser)`), or the type prefix (`feat`).
81
+
82
+ ### 3. Maximum line length (`maxLineLength`)
83
+
84
+ No line in the commit subject or body may exceed the configured character limit (default 72 characters).
85
+ When a line exceeds this limit, the error identifies the exact line number, current character length, and offending text.
86
+
87
+ ### 4. Signoff (`requireSignoff`)
88
+
89
+ Every commit must include a signoff indicator.
90
+ You can provide this either via flags or directly in the message body:
91
+
92
+ - Pass `-s` or `--signoff` in the git command.
93
+ - Or include a trailer matching `Signed-off-by: Full Name <email@example.com>` in the message body.
94
+
95
+ ### 5. Amend commits (`--amend`)
96
+
97
+ If an agent runs `git commit --amend --no-edit` without supplying a new message, the plugin permits execution.
98
+ If the agent provides a new message with `-m`, the plugin validates the new message.
99
+
100
+ ## Development
101
+
102
+ Use Bun for all repository operations.
103
+
104
+ ```bash
105
+ bun install
106
+ bun test
107
+ bun run typecheck
108
+ bun run lint
109
+ bun run build
110
+ ```