opencode-commit-guard 1.1.2 → 1.3.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/README.md +20 -38
- package/dist/index.js +1344 -325
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
# opencode-commit-guard
|
|
2
2
|
|
|
3
3
|
This OpenCode V2 plugin checks Git commit messages before an agent runs `git commit`.
|
|
4
|
-
It requires `@opencode/plugin` 2.4.1 or newer.
|
|
4
|
+
It requires `@opencode/plugin` 2.4.1 or newer and `effect` 4.1.0 or newer.
|
|
5
5
|
|
|
6
6
|
## Overview
|
|
7
7
|
|
|
8
|
-
The plugin inspects every `shell` and `bash` tool call before it runs.
|
|
8
|
+
The plugin inspects every `shell` and `bash` tool call before it runs, across POSIX shells and PowerShell 7 (`pwsh`).
|
|
9
9
|
If a `git commit` breaks a formatting rule, the plugin rejects the tool call with an error.
|
|
10
10
|
The error lists each violation and shows a conforming example, so the agent can fix the message and retry.
|
|
11
11
|
|
|
12
12
|
Before the first commit in each session and checkout, the agent captures a Git baseline with the `commit_context` tool.
|
|
13
13
|
The baseline records the effective `commit.gpgsign` setting, which determines whether a commit needs a signoff.
|
|
14
|
+
On Windows, context capture and command inspection target PowerShell 7 (`pwsh`).
|
|
14
15
|
|
|
15
16
|
The plugin does not change Git hooks or repository configuration.
|
|
16
17
|
|
|
@@ -54,33 +55,18 @@ Set options on the plugin entry:
|
|
|
54
55
|
|
|
55
56
|
The plugin rejects unknown options, including `requireSignoff`.
|
|
56
57
|
|
|
57
|
-
##
|
|
58
|
+
## Usage
|
|
58
59
|
|
|
59
|
-
1.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
That report also lists the commit rules for the checkout.
|
|
65
|
-
If the report is missing, call `commit_context` again with the same workdir for status and next steps.
|
|
60
|
+
1. Ask your agent to commit changes in your repository.
|
|
61
|
+
2. Before the first commit in a session and checkout, your agent calls `commit_context` and runs the returned capture command in the foreground shell.
|
|
62
|
+
Approve that shell command when OpenCode prompts you.
|
|
63
|
+
3. Wait for `Frozen commit baseline` in the shell output.
|
|
64
|
+
That report confirms the active baseline and lists the commit rules for the checkout.
|
|
66
65
|
|
|
67
|
-
`RECEIPT_OK`
|
|
66
|
+
`RECEIPT_OK` confirms only that the shell wrote the capture file.
|
|
68
67
|
It does not authorize a commit.
|
|
69
68
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
In `full_codemode`, call both tools from one `execute` script:
|
|
73
|
-
|
|
74
|
-
```js
|
|
75
|
-
const text = await tools.commit_context({ workdir: "my-repo" });
|
|
76
|
-
if (!text.includes("Run this shell command")) return text;
|
|
77
|
-
const command = text.split("\n").slice(1).join("\n");
|
|
78
|
-
const result = await tools.shell({ command, workdir: "my-repo" });
|
|
79
|
-
return result.output;
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
If `commit_context` returns status or baseline guidance without a command, the script returns that text.
|
|
83
|
-
Otherwise, the returned `result.output` text includes the `Frozen commit baseline` report.
|
|
69
|
+
Ask your agent to refresh the baseline (`commit_context` with `refresh: true`) after you switch branches, change signing settings, or change commit instructions.
|
|
84
70
|
|
|
85
71
|
## Formatting rules
|
|
86
72
|
|
|
@@ -89,29 +75,25 @@ Otherwise, the returned `result.output` text includes the `Frozen commit baselin
|
|
|
89
75
|
- **Line length**: No subject or body line exceeds `maxLineLength`.
|
|
90
76
|
- **Signoff**: If the captured `commit.gpgsign` is `true`, add `-s` or a `Signed-off-by:` trailer.
|
|
91
77
|
Signoff is not a cryptographic signature.
|
|
92
|
-
- **Literal messages**: Supply messages with `-m`, `--message`,
|
|
78
|
+
- **Literal messages**: Supply messages with `-m`, `--message`, one quoted heredoc on POSIX standard input, or a single literal here-string pipeline in PowerShell 7.
|
|
93
79
|
The plugin rejects message files, shell expansion in messages, and `--trailer`.
|
|
94
80
|
- **Direct target**: Run `git commit` directly in the captured checkout.
|
|
95
81
|
The plugin rejects `git -C`, Git directory flags, Git environment overrides, and directory-changing wrappers.
|
|
96
82
|
|
|
97
|
-
|
|
83
|
+
In POSIX shells, use real newlines inside `$'...'` for a message body:
|
|
98
84
|
|
|
99
85
|
```bash
|
|
100
86
|
git commit -s -m $'kernel: Fix race in thermal driver\n\nHold the lock while the sensor list changes.'
|
|
101
87
|
```
|
|
102
88
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
## Development
|
|
89
|
+
In PowerShell 7 (`pwsh`), use single quotes or pipe a literal here-string to `git commit -F -`:
|
|
106
90
|
|
|
107
|
-
|
|
91
|
+
```powershell
|
|
92
|
+
@'
|
|
93
|
+
kernel: Fix race in thermal driver
|
|
108
94
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
bun test # unit tests and real OpenCode host tests
|
|
112
|
-
bun run typecheck # TypeScript type checking
|
|
113
|
-
bun run check # lint and format check
|
|
114
|
-
bun run build # build dist/
|
|
95
|
+
Hold the lock while the sensor list changes.
|
|
96
|
+
'@ | git commit -s -F -
|
|
115
97
|
```
|
|
116
98
|
|
|
117
|
-
|
|
99
|
+
`git commit --help` and `git commit -h` do not need a baseline.
|