opencode-commit-guard 1.0.2 → 1.0.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/README.md +43 -12
- package/dist/index.js +499 -154
- package/package.json +7 -7
- package/src/capture.ts +250 -0
- package/src/config.ts +3 -10
- package/src/plugin.ts +177 -22
- package/src/shell.ts +155 -57
- package/src/types.ts +6 -5
- package/src/validator.ts +11 -105
package/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# opencode-commit-guard
|
|
2
2
|
|
|
3
3
|
OpenCode V2 plugin that enforces git commit message format rules during agent sessions.
|
|
4
|
+
Capture Git context before your first commit in each session and checkout.
|
|
4
5
|
|
|
5
6
|
## Overview
|
|
6
7
|
|
|
7
8
|
`opencode-commit-guard` intercepts `shell` and `bash` tool execution before it runs.
|
|
8
9
|
When an agent attempts a `git commit`, the plugin inspects the command line and inline message content.
|
|
9
10
|
If the commit violates configured formatting standards, the plugin rejects the tool call through OpenCode's typed tool-error channel.
|
|
11
|
+
The plugin requires a valid Git signing baseline for the exact checkout before it allows a commit.
|
|
10
12
|
|
|
11
13
|
### Why this approach fits
|
|
12
14
|
|
|
@@ -39,8 +41,7 @@ You can also specify custom configuration options:
|
|
|
39
41
|
"options": {
|
|
40
42
|
"requireScope": true,
|
|
41
43
|
"allowedScopes": ["kernel", "releasetools", "build", "ui"],
|
|
42
|
-
"maxLineLength": 72
|
|
43
|
-
"requireSignoff": true
|
|
44
|
+
"maxLineLength": 72
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
]
|
|
@@ -54,7 +55,22 @@ You can also specify custom configuration options:
|
|
|
54
55
|
| `requireScope` | `boolean` | `true` | Requires the first line to match `<scope>: <subject>`. |
|
|
55
56
|
| `allowedScopes` | `string[]` | `undefined` | Restricts allowed scope identifiers to a specified list. |
|
|
56
57
|
| `maxLineLength` | `number` | `72` | Limits every line in the subject and body to this length. Set to `0` to disable. |
|
|
57
|
-
|
|
58
|
+
|
|
59
|
+
## Capture commit context
|
|
60
|
+
|
|
61
|
+
Call `commit_context` before your first commit in each session and worktree.
|
|
62
|
+
Run the returned command through the foreground `shell` tool with the indicated workdir.
|
|
63
|
+
Call `commit_context` again to read concise guidance.
|
|
64
|
+
If the shell result lacks a verified successful process exit, capture again instead of using a partial baseline.
|
|
65
|
+
The command writes full historical messages to a private file and prints only a fixed receipt.
|
|
66
|
+
The plugin does not put complete historical messages into tool results or model context.
|
|
67
|
+
Set `refresh: true` after a branch switch, a signing setting change, or a change to commit instructions.
|
|
68
|
+
A failed refresh does not restore the previous baseline.
|
|
69
|
+
An external Git configuration change or checkout replacement at the same path is not detected until you refresh.
|
|
70
|
+
Remote workspaces are unsupported.
|
|
71
|
+
Historical scopes are observations, not allowed scopes or policy.
|
|
72
|
+
The guard enforces configured scope syntax, allowed scopes, line length, inline message input, and conditional signoff.
|
|
73
|
+
It does not enforce every writing convention in `AGENTS.md` or verify a cryptographic signature.
|
|
58
74
|
|
|
59
75
|
## Formatting rules
|
|
60
76
|
|
|
@@ -84,26 +100,41 @@ For conventional commits such as `feat(parser): ...`, the plugin accepts either
|
|
|
84
100
|
No line in the commit subject or body may exceed the configured character limit (default 72 characters).
|
|
85
101
|
When a line exceeds this limit, the error identifies the exact line number, current character length, and offending text.
|
|
86
102
|
|
|
87
|
-
### 4. Signoff
|
|
103
|
+
### 4. Signoff
|
|
88
104
|
|
|
89
|
-
|
|
105
|
+
When the captured effective `commit.gpgsign` is `true`, every commit with a supplied message must include a signoff indicator.
|
|
106
|
+
When it is `false` or unset, signoff is not required.
|
|
107
|
+
An invalid or missing signing snapshot blocks the commit until you capture context again.
|
|
90
108
|
You can provide this either via flags or directly in the message body:
|
|
91
109
|
|
|
92
110
|
- Pass `-s` or `--signoff` in the git command.
|
|
93
111
|
- Or include a trailer matching `Signed-off-by: Full Name <email@example.com>` in the message body.
|
|
94
112
|
|
|
113
|
+
Signoff identifies the author of a contribution.
|
|
114
|
+
It does not cryptographically sign the commit.
|
|
115
|
+
Git signing settings and your signing key remain separate from signoff.
|
|
116
|
+
|
|
95
117
|
### 5. Amend commits (`--amend`)
|
|
96
118
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
119
|
+
Use `git commit --amend --no-edit` to keep the existing message unchanged.
|
|
120
|
+
The plugin does not read or revalidate that message, so a message created outside this guard may not meet its format rules.
|
|
121
|
+
Provide `-m` when you change the message; the plugin validates the supplied text in the captured checkout.
|
|
122
|
+
Use a direct Git command in that checkout.
|
|
123
|
+
The guard rejects `git -C`, Git directory and worktree flags, Git environment overrides, and directory-changing wrappers because they can select another target.
|
|
124
|
+
The guard also rejects earlier shell environment mutations such as `export`, `typeset`, `declare`, `source`, `.`, `eval`, `set`, and assignment-only commands before a commit.
|
|
102
125
|
|
|
103
126
|
### Message input
|
|
104
127
|
|
|
105
|
-
Provide commit messages inline with `-m` or `--message
|
|
106
|
-
|
|
128
|
+
Provide commit messages inline with `-m` or `--message`, or use one quoted heredoc directly on standard input:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
git commit -s -F - <<'EOF'
|
|
132
|
+
kernel: fix race
|
|
133
|
+
EOF
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The plugin rejects file-backed `-F` or `--file` messages without reading the files.
|
|
137
|
+
It also rejects unquoted or ambiguous standard-input sources.
|
|
107
138
|
|
|
108
139
|
## Development
|
|
109
140
|
|