opencode-commit-guard 1.0.3 → 1.0.5
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 +37 -8
- package/dist/index.js +532 -42
- package/package.json +5 -5
- package/src/capture.ts +374 -0
- package/src/config.ts +3 -10
- package/src/plugin.ts +284 -22
- package/src/shell.ts +32 -4
- package/src/types.ts +3 -2
- package/src/validator.ts +5 -12
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,26 @@ 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
|
+
If the Git repository is in a subdirectory or differs from the project root, specify `workdir` (e.g., `commit_context({ workdir: "my-repo" })`).
|
|
63
|
+
If `workdir` is omitted and the project root is not a Git repository, the plugin automatically selects the repository if exactly one exists, or lists available repositories if multiple are present.
|
|
64
|
+
Run the returned command through the foreground `shell` tool with the indicated workdir.
|
|
65
|
+
Call `commit_context` again to read concise guidance.
|
|
66
|
+
Repeat the same `workdir` on each call when you select a repository explicitly.
|
|
67
|
+
An argument-free call selects the session directory when it is inside a Git repository, even after an explicit selection.
|
|
68
|
+
If the shell result lacks a verified successful process exit, capture again instead of using a partial baseline.
|
|
69
|
+
The command writes full historical messages to a private file and prints only a fixed receipt.
|
|
70
|
+
The plugin does not put complete historical messages into tool results or model context.
|
|
71
|
+
Set `refresh: true` after a branch switch, a signing setting change, or a change to commit instructions.
|
|
72
|
+
A failed refresh does not restore the previous baseline.
|
|
73
|
+
An external Git configuration change or checkout replacement at the same path is not detected until you refresh.
|
|
74
|
+
Remote workspaces are unsupported.
|
|
75
|
+
Historical scopes are observations, not allowed scopes or policy.
|
|
76
|
+
The guard enforces configured scope syntax, allowed scopes, line length, inline message input, and conditional signoff.
|
|
77
|
+
It does not enforce every writing convention in `AGENTS.md` or verify a cryptographic signature.
|
|
58
78
|
|
|
59
79
|
## Formatting rules
|
|
60
80
|
|
|
@@ -84,19 +104,28 @@ For conventional commits such as `feat(parser): ...`, the plugin accepts either
|
|
|
84
104
|
No line in the commit subject or body may exceed the configured character limit (default 72 characters).
|
|
85
105
|
When a line exceeds this limit, the error identifies the exact line number, current character length, and offending text.
|
|
86
106
|
|
|
87
|
-
### 4. Signoff
|
|
107
|
+
### 4. Signoff
|
|
88
108
|
|
|
89
|
-
|
|
109
|
+
When the captured effective `commit.gpgsign` is `true`, every commit with a supplied message must include a signoff indicator.
|
|
110
|
+
When it is `false` or unset, signoff is not required.
|
|
111
|
+
An invalid or missing signing snapshot blocks the commit until you capture context again.
|
|
90
112
|
You can provide this either via flags or directly in the message body:
|
|
91
113
|
|
|
92
114
|
- Pass `-s` or `--signoff` in the git command.
|
|
93
115
|
- Or include a trailer matching `Signed-off-by: Full Name <email@example.com>` in the message body.
|
|
94
116
|
|
|
117
|
+
Signoff identifies the author of a contribution.
|
|
118
|
+
It does not cryptographically sign the commit.
|
|
119
|
+
Git signing settings and your signing key remain separate from signoff.
|
|
120
|
+
|
|
95
121
|
### 5. Amend commits (`--amend`)
|
|
96
122
|
|
|
97
|
-
|
|
98
|
-
The plugin
|
|
99
|
-
|
|
123
|
+
Use `git commit --amend --no-edit` to keep the existing message unchanged.
|
|
124
|
+
The plugin does not read or revalidate that message, so a message created outside this guard may not meet its format rules.
|
|
125
|
+
Provide `-m` when you change the message; the plugin validates the supplied text in the captured checkout.
|
|
126
|
+
Use a direct Git command in that checkout.
|
|
127
|
+
The guard rejects `git -C`, Git directory and worktree flags, Git environment overrides, and directory-changing wrappers because they can select another target.
|
|
128
|
+
The guard also rejects earlier shell environment mutations such as `export`, `typeset`, `declare`, `source`, `.`, `eval`, `set`, and assignment-only commands before a commit.
|
|
100
129
|
|
|
101
130
|
### Message input
|
|
102
131
|
|