@eduardo191labs/opencode-actions 0.0.0-stage → 0.1.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 +22 -0
- package/README.md +311 -2
- package/action.yml +251 -0
- package/dist/actions.d.ts +351 -0
- package/dist/actions.js +561 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +180 -0
- package/dist/commands.d.ts +23 -0
- package/dist/commands.js +120 -0
- package/dist/compile.d.ts +49 -0
- package/dist/compile.js +217 -0
- package/dist/config.d.ts +306 -0
- package/dist/config.js +133 -0
- package/dist/detect.d.ts +55 -0
- package/dist/detect.js +215 -0
- package/dist/format.d.ts +79 -0
- package/dist/format.js +168 -0
- package/dist/git.d.ts +38 -0
- package/dist/git.js +125 -0
- package/dist/github.d.ts +213 -0
- package/dist/github.js +227 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/install.d.ts +2 -0
- package/dist/install.js +299 -0
- package/dist/loader.d.ts +54 -0
- package/dist/loader.js +306 -0
- package/dist/mcp-server.d.ts +16 -0
- package/dist/mcp-server.js +402 -0
- package/dist/prompts.d.ts +70 -0
- package/dist/prompts.js +260 -0
- package/dist/runner.d.ts +108 -0
- package/dist/runner.js +318 -0
- package/dist/summary.d.ts +2 -0
- package/dist/summary.js +99 -0
- package/package.json +57 -4
- package/schemas/opencode-actions.schema.json +527 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Eduardo (eduardo191-star)
|
|
4
|
+
Copyright (c) 2026 bd-loser (Termux/Android port, patches, CI, installer)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,312 @@
|
|
|
1
|
-
#
|
|
1
|
+
# opencode-actions
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A GitHub bot built on [OpenCode](https://opencode.ai). It reviews pull requests, triages and
|
|
4
|
+
implements issues, fixes failing workflows, answers comment commands and exposes GitHub as
|
|
5
|
+
MCP tools to the agent. Reviews post inline `suggestion` blocks the author applies with one
|
|
6
|
+
click; the bot never pushes during a review.
|
|
7
|
+
|
|
8
|
+
```yaml
|
|
9
|
+
- uses: eduardo191-star/opencode-actions@v1
|
|
10
|
+
with:
|
|
11
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
12
|
+
config-repo: my-org/bot-config
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## What it does
|
|
16
|
+
|
|
17
|
+
| Capability | Trigger | What happens |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| **PR review** | `pull_request` opened / updated / ready | Inline comments with `suggestion` blocks. Never edits, approves or pushes by default. |
|
|
20
|
+
| **Issue triage** | `issues` opened | Severity, labels, a reproduction verdict and a plan. |
|
|
21
|
+
| **Issue answer** | `/bot answer` | A grounded answer citing `file:line`. |
|
|
22
|
+
| **Issue implementation** | `/bot implement` | Makes the change, commits it, opens a PR. |
|
|
23
|
+
| **Workflow autofix** | `workflow_run` failed | Diagnoses the failure and opens a fix PR. |
|
|
24
|
+
| **Comment commands** | `issue_comment` | `/bot review`, `fix`, `explain`, `test`, `docs`, `describe`, `triage`, `answer`, `merge`, `close`, `reopen`, `label`, `assign`, `implement`, `help`. |
|
|
25
|
+
| **PR description** | `/bot describe` | Rewrites the body from the real diff. |
|
|
26
|
+
| **MCP tools** | while running | The agent can read PRs, comment, open issues, create branches and merge, all permission-gated. |
|
|
27
|
+
|
|
28
|
+
## Configuration
|
|
29
|
+
|
|
30
|
+
The bot reads `opencode-actions.yml` from a **configuration repository**, so prompts,
|
|
31
|
+
permissions and models are versioned apart from the code being reviewed. Point at it with
|
|
32
|
+
`config-repo`; the file is also discovered in the checked-out repository.
|
|
33
|
+
|
|
34
|
+
The schema has two layers:
|
|
35
|
+
|
|
36
|
+
- **`bot`** — GitHub behaviour: features, permissions, models, review rules, commands, secrets.
|
|
37
|
+
- **`opencode`** — forwarded verbatim to OpenCode. Every upstream field works: `model`,
|
|
38
|
+
`agents`, `permissions` (the tool ruleset), `policies`, `mcp`, `plugins`, `providers`,
|
|
39
|
+
`skills`, `commands`, `instructions`, `formatter`, `lsp`, `compaction`, `watcher`,
|
|
40
|
+
`tool_output`, `media`, `websearch`, `worktree`, `warming`, `experimental`, and the rest.
|
|
41
|
+
|
|
42
|
+
Validation: [`schemas/opencode-actions.schema.json`](schemas/opencode-actions.schema.json).
|
|
43
|
+
|
|
44
|
+
```yaml
|
|
45
|
+
version: 1
|
|
46
|
+
|
|
47
|
+
bot:
|
|
48
|
+
name: reviewer
|
|
49
|
+
base_branch: main
|
|
50
|
+
write: true
|
|
51
|
+
|
|
52
|
+
features:
|
|
53
|
+
pull_request_review: true
|
|
54
|
+
issues: true
|
|
55
|
+
comment_commands: true
|
|
56
|
+
workflow_autofix: true
|
|
57
|
+
|
|
58
|
+
# GitHub capabilities. Separate from OpenCode's tool permission ruleset.
|
|
59
|
+
permissions:
|
|
60
|
+
push_pr_branch: allow
|
|
61
|
+
push_default_branch: deny
|
|
62
|
+
manage_issues: allow
|
|
63
|
+
manage_pull_requests: allow
|
|
64
|
+
merge_pull_requests: ask
|
|
65
|
+
merge_protected: deny
|
|
66
|
+
edit_workflows: deny
|
|
67
|
+
run_commands: allow
|
|
68
|
+
read_secrets: deny
|
|
69
|
+
|
|
70
|
+
model:
|
|
71
|
+
id: anthropic/claude-sonnet-4
|
|
72
|
+
reasoning: high
|
|
73
|
+
tasks:
|
|
74
|
+
review: openai/gpt-5
|
|
75
|
+
autofix: anthropic/claude-sonnet-4
|
|
76
|
+
|
|
77
|
+
review:
|
|
78
|
+
on_findings: comment # comment | request_changes | approve | off
|
|
79
|
+
approve_when_clean: false
|
|
80
|
+
min_severity: low
|
|
81
|
+
max_comments: 25
|
|
82
|
+
suggestions: true
|
|
83
|
+
exclude: [dist/**, "**/*.lock", "**/*.snap"]
|
|
84
|
+
instructions: |
|
|
85
|
+
This repository targets Node 20. Flag any API that requires 22.
|
|
86
|
+
|
|
87
|
+
commands:
|
|
88
|
+
prefix: /bot
|
|
89
|
+
min_permission: write
|
|
90
|
+
admins: [eduardo191-star]
|
|
91
|
+
|
|
92
|
+
secrets:
|
|
93
|
+
env:
|
|
94
|
+
ANTHROPIC_API_KEY: ANTHROPIC_API_KEY
|
|
95
|
+
providers:
|
|
96
|
+
anthropic:
|
|
97
|
+
token_env: ANTHROPIC_API_KEY
|
|
98
|
+
|
|
99
|
+
opencode:
|
|
100
|
+
permissions:
|
|
101
|
+
- action: read
|
|
102
|
+
resource: "**"
|
|
103
|
+
effect: allow
|
|
104
|
+
- action: edit
|
|
105
|
+
resource: "docs/**"
|
|
106
|
+
effect: deny
|
|
107
|
+
mcp:
|
|
108
|
+
servers:
|
|
109
|
+
github:
|
|
110
|
+
type: local
|
|
111
|
+
command: ["npx", "-y", "@eduardo191labs/opencode-actions-mcp"]
|
|
112
|
+
environment:
|
|
113
|
+
GITHUB_TOKEN: "${GITHUB_TOKEN}"
|
|
114
|
+
plugins:
|
|
115
|
+
- "@my-org/opencode-plugin@1.2.0"
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### How `bot.permissions` maps to OpenCode
|
|
119
|
+
|
|
120
|
+
The bot translates its GitHub capabilities into OpenCode tool rules, then adds hard limits
|
|
121
|
+
of its own:
|
|
122
|
+
|
|
123
|
+
| Bot permission | OpenCode rule |
|
|
124
|
+
|---|---|
|
|
125
|
+
| `push_pr_branch: allow` | `edit` / `write` / `patch` allowed **in write modes only** |
|
|
126
|
+
| `push_pr_branch: deny` | `edit` denied everywhere |
|
|
127
|
+
| `edit_workflows: allow` | `edit` on `.github/workflows/**` |
|
|
128
|
+
| `run_commands: allow` | `shell` allowed |
|
|
129
|
+
| `read_secrets: allow` | `.env`, `.pem`, `.key`, `id_rsa` readable |
|
|
130
|
+
|
|
131
|
+
A review always runs with `edit`, `write` and `patch` denied, even when the bot may push to
|
|
132
|
+
PR branches. If anything still touches the tree, the review reverts it before exiting.
|
|
133
|
+
|
|
134
|
+
## Workflows
|
|
135
|
+
|
|
136
|
+
```yaml
|
|
137
|
+
# .github/workflows/opencode-review.yml
|
|
138
|
+
name: opencode review
|
|
139
|
+
on:
|
|
140
|
+
pull_request:
|
|
141
|
+
types: [opened, synchronize, reopened, ready_for_review]
|
|
142
|
+
|
|
143
|
+
permissions:
|
|
144
|
+
contents: read
|
|
145
|
+
pull-requests: write
|
|
146
|
+
issues: write
|
|
147
|
+
|
|
148
|
+
concurrency:
|
|
149
|
+
group: opencode-review-${{ github.event.pull_request.number }}
|
|
150
|
+
cancel-in-progress: true
|
|
151
|
+
|
|
152
|
+
jobs:
|
|
153
|
+
review:
|
|
154
|
+
runs-on: ubuntu-latest
|
|
155
|
+
steps:
|
|
156
|
+
- uses: actions/checkout@v4
|
|
157
|
+
with: { fetch-depth: 0 }
|
|
158
|
+
- uses: eduardo191-star/opencode-actions@v1
|
|
159
|
+
with:
|
|
160
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
161
|
+
config-repo: my-org/bot-config
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```yaml
|
|
165
|
+
# .github/workflows/opencode-commands.yml
|
|
166
|
+
name: opencode commands
|
|
167
|
+
on:
|
|
168
|
+
issue_comment:
|
|
169
|
+
types: [created]
|
|
170
|
+
|
|
171
|
+
permissions:
|
|
172
|
+
contents: write
|
|
173
|
+
pull-requests: write
|
|
174
|
+
issues: write
|
|
175
|
+
|
|
176
|
+
jobs:
|
|
177
|
+
command:
|
|
178
|
+
# Only comments that actually address the bot.
|
|
179
|
+
if: startsWith(github.event.comment.body, '/bot') || contains(github.event.comment.body, '/bot ')
|
|
180
|
+
runs-on: ubuntu-latest
|
|
181
|
+
steps:
|
|
182
|
+
- uses: actions/checkout@v4
|
|
183
|
+
with:
|
|
184
|
+
ref: ${{ github.event.issue.pull_request && format('refs/pull/{0}/head', github.event.issue.number) || github.event.repository.default_branch }}
|
|
185
|
+
fetch-depth: 0
|
|
186
|
+
- uses: eduardo191-star/opencode-actions@v1
|
|
187
|
+
with:
|
|
188
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
189
|
+
config-repo: my-org/bot-config
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
```yaml
|
|
193
|
+
# .github/workflows/opencode-autofix.yml
|
|
194
|
+
name: opencode autofix
|
|
195
|
+
on:
|
|
196
|
+
workflow_run:
|
|
197
|
+
workflows: [CI]
|
|
198
|
+
types: [completed]
|
|
199
|
+
|
|
200
|
+
permissions:
|
|
201
|
+
contents: write
|
|
202
|
+
pull-requests: write
|
|
203
|
+
actions: read
|
|
204
|
+
|
|
205
|
+
jobs:
|
|
206
|
+
autofix:
|
|
207
|
+
if: github.event.workflow_run.conclusion == 'failure'
|
|
208
|
+
runs-on: ubuntu-latest
|
|
209
|
+
steps:
|
|
210
|
+
- uses: actions/checkout@v4
|
|
211
|
+
with:
|
|
212
|
+
ref: ${{ github.event.workflow_run.head_branch }}
|
|
213
|
+
fetch-depth: 0
|
|
214
|
+
- uses: eduardo191-star/opencode-actions@v1
|
|
215
|
+
with:
|
|
216
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
217
|
+
config-repo: my-org/bot-config
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Permissions the bot needs
|
|
221
|
+
|
|
222
|
+
`GITHUB_TOKEN` scopes, per workflow:
|
|
223
|
+
|
|
224
|
+
| Workflow | `contents` | `pull-requests` | `issues` | `actions` |
|
|
225
|
+
|---|---|---|---|---|
|
|
226
|
+
| review | read | write | — | — |
|
|
227
|
+
| commands | write | write | write | — |
|
|
228
|
+
| issues | write | write | write | — |
|
|
229
|
+
| autofix | write | write | — | read |
|
|
230
|
+
|
|
231
|
+
When `config-repo` is **private**, pass `config-token` with a token that can read it.
|
|
232
|
+
|
|
233
|
+
## Install
|
|
234
|
+
|
|
235
|
+
### One repository
|
|
236
|
+
|
|
237
|
+
```yaml
|
|
238
|
+
- uses: eduardo191-star/opencode-actions@v1
|
|
239
|
+
with:
|
|
240
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
241
|
+
config-repo: my-org/bot-config
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Every repository of an account
|
|
245
|
+
|
|
246
|
+
The installer detects the stack in each repository (Node, Rust, Go, Python, JVM,
|
|
247
|
+
Ruby, PHP, C/C++, .NET, Swift, Dart), skips archived, disabled and forked ones, and
|
|
248
|
+
writes three narrow workflows that only touch files it owns. Re-running is safe: a
|
|
249
|
+
workflow file without the bot marker is never overwritten.
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
# Preview
|
|
253
|
+
opencode-actions-install --owner my-login --config-repo my-org/bot-config --dry-run
|
|
254
|
+
|
|
255
|
+
# Install
|
|
256
|
+
opencode-actions-install --owner my-login --config-repo my-org/bot-config
|
|
257
|
+
|
|
258
|
+
# One repository only
|
|
259
|
+
opencode-actions-install --owner my-login --repo my-project --config-repo my-org/bot-config
|
|
260
|
+
|
|
261
|
+
# An organisation
|
|
262
|
+
opencode-actions-install --owner org:my-org --config-repo my-org/bot-config
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
For a repository that already has workflows with the same names, the installer
|
|
266
|
+
leaves them alone and reports them. Use `--exclude name` (repeatable) to skip a
|
|
267
|
+
repository entirely.
|
|
268
|
+
|
|
269
|
+
The same thing runs from Actions, which is what the `Install` workflow does:
|
|
270
|
+
|
|
271
|
+
```yaml
|
|
272
|
+
on:
|
|
273
|
+
workflow_dispatch:
|
|
274
|
+
inputs:
|
|
275
|
+
dry_run: { type: boolean, default: true }
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
It needs `OPENCODE_INSTALL_TOKEN`, a fine-grained token with **Administration:
|
|
279
|
+
write** on the target repositories, because writing workflows and secrets through
|
|
280
|
+
the API requires it. `GITHUB_TOKEN` cannot install into other repositories.
|
|
281
|
+
|
|
282
|
+
### Detecting a repository
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
opencode-actions --mode detect # stack, workflows, install state
|
|
286
|
+
opencode-actions --mode plan # the workflows that would be written
|
|
287
|
+
opencode-actions --mode config # the compiled OpenCode configuration
|
|
288
|
+
opencode-actions --mode capabilities # what the bot may do on GitHub
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Commands
|
|
292
|
+
|
|
293
|
+
| Command | Effect |
|
|
294
|
+
|---|---|
|
|
295
|
+
| `/bot review` | Review the PR (comment only). |
|
|
296
|
+
| `/bot fix <what>` | Change the code and push a commit. |
|
|
297
|
+
| `/bot explain <what>` | Explain code, a diff or an error. |
|
|
298
|
+
| `/bot test <what>` | Write or run tests. |
|
|
299
|
+
| `/bot docs` | Update documentation. |
|
|
300
|
+
| `/bot describe` | Rewrite the PR description from the diff. |
|
|
301
|
+
| `/bot triage` | Classify an issue. |
|
|
302
|
+
| `/bot answer` | Answer an issue with evidence. |
|
|
303
|
+
| `/bot implement` | Implement the issue and open a PR. |
|
|
304
|
+
| `/bot merge` | Merge a PR (needs `merge_pull_requests: allow`). |
|
|
305
|
+
| `/bot label +bug -docs` | Add and remove labels. |
|
|
306
|
+
| `/bot assign @user` | Assign users. |
|
|
307
|
+
| `/bot close` / `/bot reopen` | Change issue or PR state. |
|
|
308
|
+
| `/bot help` | List commands. |
|
|
309
|
+
|
|
310
|
+
## License
|
|
311
|
+
|
|
312
|
+
MIT
|
package/action.yml
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
name: "OpenCode Actions"
|
|
2
|
+
description: "Autonomous GitHub bot built on OpenCode: PR review, issues, workflow autofix, comment commands and MCP tools."
|
|
3
|
+
author: "eduardo191-star"
|
|
4
|
+
|
|
5
|
+
branding:
|
|
6
|
+
icon: "cpu"
|
|
7
|
+
color: "purple"
|
|
8
|
+
|
|
9
|
+
inputs:
|
|
10
|
+
event:
|
|
11
|
+
description: "Event to handle: pull_request, issue_comment, workflow_run, push, workflow_dispatch."
|
|
12
|
+
required: false
|
|
13
|
+
default: ""
|
|
14
|
+
config:
|
|
15
|
+
description: "Inline configuration (JSON or YAML). Overrides the config repository."
|
|
16
|
+
required: false
|
|
17
|
+
default: ""
|
|
18
|
+
config-repo:
|
|
19
|
+
description: "Repository holding opencode-actions.yml, e.g. my-org/bot-config."
|
|
20
|
+
required: false
|
|
21
|
+
default: ""
|
|
22
|
+
config-ref:
|
|
23
|
+
description: "Ref of the configuration repository."
|
|
24
|
+
required: false
|
|
25
|
+
default: "main"
|
|
26
|
+
config-token:
|
|
27
|
+
description: "Token for a private configuration repository. Defaults to github-token."
|
|
28
|
+
required: false
|
|
29
|
+
default: ""
|
|
30
|
+
github-token:
|
|
31
|
+
description: "Token used for GitHub operations. Needs contents, pull-requests, issues and actions scope."
|
|
32
|
+
required: true
|
|
33
|
+
opencode-token:
|
|
34
|
+
description: "Token for the OpenCode service, if you use a managed provider."
|
|
35
|
+
required: false
|
|
36
|
+
default: ""
|
|
37
|
+
plugins:
|
|
38
|
+
description: "Space-separated npm packages installed and registered with OpenCode, e.g. '@eduardo191labs/opencode-free-pi@latest'."
|
|
39
|
+
required: false
|
|
40
|
+
default: ""
|
|
41
|
+
model:
|
|
42
|
+
description: "Override the model, 'provider/model#variant'."
|
|
43
|
+
required: false
|
|
44
|
+
default: ""
|
|
45
|
+
mode:
|
|
46
|
+
description: "review | issues | autofix | config | capabilities"
|
|
47
|
+
required: false
|
|
48
|
+
default: ""
|
|
49
|
+
pr:
|
|
50
|
+
description: "Pull request number, for workflow_dispatch runs."
|
|
51
|
+
required: false
|
|
52
|
+
default: ""
|
|
53
|
+
issue:
|
|
54
|
+
description: "Issue number, for workflow_dispatch runs."
|
|
55
|
+
required: false
|
|
56
|
+
default: ""
|
|
57
|
+
run-id:
|
|
58
|
+
description: "Workflow run id, for autofix runs."
|
|
59
|
+
required: false
|
|
60
|
+
default: ""
|
|
61
|
+
workspace:
|
|
62
|
+
description: "Checkout directory."
|
|
63
|
+
required: false
|
|
64
|
+
default: ""
|
|
65
|
+
commit:
|
|
66
|
+
description: "Commit and push changes the agent makes (true/false)."
|
|
67
|
+
required: false
|
|
68
|
+
default: "true"
|
|
69
|
+
approve:
|
|
70
|
+
description: "Approve permissions that are not explicitly denied (true/false)."
|
|
71
|
+
required: false
|
|
72
|
+
default: "true"
|
|
73
|
+
live:
|
|
74
|
+
description: "Stream the agent transcript into the Actions log (true/false)."
|
|
75
|
+
required: false
|
|
76
|
+
default: "true"
|
|
77
|
+
summary:
|
|
78
|
+
description: "Write a job summary with model, cost and token usage (true/false)."
|
|
79
|
+
required: false
|
|
80
|
+
default: "true"
|
|
81
|
+
dry-run:
|
|
82
|
+
description: "Print the compiled configuration and exit without acting."
|
|
83
|
+
required: false
|
|
84
|
+
default: "false"
|
|
85
|
+
|
|
86
|
+
outputs:
|
|
87
|
+
result:
|
|
88
|
+
description: "JSON result of the handler."
|
|
89
|
+
verdict:
|
|
90
|
+
description: "Review verdict: COMMENT, APPROVE or REQUEST_CHANGES."
|
|
91
|
+
findings:
|
|
92
|
+
description: "Number of findings reported."
|
|
93
|
+
pr:
|
|
94
|
+
description: "Pull request number opened by the run, if any."
|
|
95
|
+
cost:
|
|
96
|
+
description: "Model cost of the run."
|
|
97
|
+
|
|
98
|
+
runs:
|
|
99
|
+
using: "composite"
|
|
100
|
+
steps:
|
|
101
|
+
- name: Install OpenCode CLI
|
|
102
|
+
shell: bash
|
|
103
|
+
run: |
|
|
104
|
+
set -euo pipefail
|
|
105
|
+
if ! command -v opencode >/dev/null 2>&1; then
|
|
106
|
+
curl -fsSL https://opencode.ai/install | bash
|
|
107
|
+
echo "$HOME/.opencode/bin" >> "$GITHUB_PATH"
|
|
108
|
+
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
|
109
|
+
fi
|
|
110
|
+
"$HOME/.opencode/bin/opencode" --version 2>/dev/null || opencode --version
|
|
111
|
+
|
|
112
|
+
- name: Install the bot package
|
|
113
|
+
shell: bash
|
|
114
|
+
run: |
|
|
115
|
+
set -euo pipefail
|
|
116
|
+
npm install --prefix "$RUNNER_TEMP/opencode-actions" \
|
|
117
|
+
@eduardo191labs/opencode-actions@${{ github.action_ref || 'latest' }} --no-audit --no-fund
|
|
118
|
+
|
|
119
|
+
- name: Install and register plugins
|
|
120
|
+
if: inputs.plugins != ''
|
|
121
|
+
shell: bash
|
|
122
|
+
env:
|
|
123
|
+
PLUGINS: ${{ inputs.plugins }}
|
|
124
|
+
run: |
|
|
125
|
+
set -euo pipefail
|
|
126
|
+
# Install globally so OpenCode resolves the package from node_modules,
|
|
127
|
+
# which is the only location the plugin runtime supports.
|
|
128
|
+
for pkg in $PLUGINS; do
|
|
129
|
+
echo "→ installing $pkg"
|
|
130
|
+
npm install -g "$pkg" --no-audit --no-fund
|
|
131
|
+
done
|
|
132
|
+
|
|
133
|
+
# Register each plugin in the OpenCode config without clobbering an
|
|
134
|
+
# existing file. The package postinstall normally does this, but npm
|
|
135
|
+
# blocks lifecycle scripts unless they are approved, so do it here.
|
|
136
|
+
node - <<'NODE'
|
|
137
|
+
const { readFileSync, writeFileSync, existsSync, mkdirSync } = require("node:fs")
|
|
138
|
+
const { join } = require("node:path")
|
|
139
|
+
const dir = join(process.env.HOME, ".config", "opencode")
|
|
140
|
+
const file = join(dir, "opencode.json")
|
|
141
|
+
mkdirSync(dir, { recursive: true })
|
|
142
|
+
|
|
143
|
+
let config = {}
|
|
144
|
+
if (existsSync(file)) {
|
|
145
|
+
try {
|
|
146
|
+
config = JSON.parse(readFileSync(file, "utf8"))
|
|
147
|
+
} catch (error) {
|
|
148
|
+
throw new Error(`${file} is not valid JSON: ${error.message}`)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const plugins = new Set(Array.isArray(config.plugins) ? config.plugins : [])
|
|
152
|
+
for (const pkg of (process.env.PLUGINS || "").split(/\s+/).filter(Boolean)) plugins.add(pkg)
|
|
153
|
+
config.plugins = [...plugins]
|
|
154
|
+
writeFileSync(file, JSON.stringify(config, null, 2) + "\n")
|
|
155
|
+
console.log("registered plugins:", config.plugins.join(", "))
|
|
156
|
+
NODE
|
|
157
|
+
|
|
158
|
+
# The plugin imports @opencode/plugin at runtime, so it can only be
|
|
159
|
+
# loaded from inside an OpenCode install. Verify the package and its
|
|
160
|
+
# entry point exist, then let OpenCode resolve it.
|
|
161
|
+
node - <<'NODE'
|
|
162
|
+
const { execSync } = require("node:child_process")
|
|
163
|
+
const { existsSync } = require("node:fs")
|
|
164
|
+
const { join } = require("node:path")
|
|
165
|
+
const root = execSync("npm root -g").toString().trim()
|
|
166
|
+
for (const pkg of (process.env.PLUGINS || "").split(/\s+/).filter(Boolean)) {
|
|
167
|
+
const dir = join(root, pkg.replace(/@latest$/, ""))
|
|
168
|
+
if (!existsSync(dir)) throw new Error(`plugin not installed: ${pkg}`)
|
|
169
|
+
const entry = join(dir, "dist", "index.js")
|
|
170
|
+
if (!existsSync(entry)) throw new Error(`plugin entry point missing: ${entry}`)
|
|
171
|
+
console.log("verified", pkg)
|
|
172
|
+
}
|
|
173
|
+
NODE
|
|
174
|
+
|
|
175
|
+
- name: Configure provider credentials
|
|
176
|
+
if: inputs.plugins != ''
|
|
177
|
+
shell: bash
|
|
178
|
+
run: |
|
|
179
|
+
set -euo pipefail
|
|
180
|
+
# Report which known provider variables are present without printing values.
|
|
181
|
+
for name in FREEPI_JWT ANTHROPIC_API_KEY OPENAI_API_KEY OPENROUTER_API_KEY; do
|
|
182
|
+
if [ -n "${!name:-}" ]; then echo "✓ $name is set"; else echo "· $name is not set"; fi
|
|
183
|
+
done
|
|
184
|
+
|
|
185
|
+
- name: Run OpenCode Actions
|
|
186
|
+
id: run
|
|
187
|
+
shell: bash
|
|
188
|
+
env:
|
|
189
|
+
GITHUB_TOKEN: ${{ inputs.github-token }}
|
|
190
|
+
OPENCODE_TOKEN: ${{ inputs.opencode-token }}
|
|
191
|
+
OPENCODE_ACTIONS_CONFIG_REPO: ${{ inputs.config-repo }}
|
|
192
|
+
OPENCODE_ACTIONS_CONFIG_REF: ${{ inputs.config-ref }}
|
|
193
|
+
OPENCODE_ACTIONS_CONFIG_TOKEN: ${{ inputs.config-token }}
|
|
194
|
+
OPENCODE_BOT_MODEL: ${{ inputs.model }}
|
|
195
|
+
OPENCODE_ACTIONS_EVENT: ${{ inputs.event }}
|
|
196
|
+
INPUT_CONFIG: ${{ inputs.config }}
|
|
197
|
+
INPUT_MODE: ${{ inputs.mode }}
|
|
198
|
+
INPUT_PR: ${{ inputs.pr }}
|
|
199
|
+
INPUT_ISSUE: ${{ inputs.issue }}
|
|
200
|
+
INPUT_RUN_ID: ${{ inputs.run-id }}
|
|
201
|
+
INPUT_LIVE: ${{ inputs.live }}
|
|
202
|
+
INPUT_SUMMARY: ${{ inputs.summary }}
|
|
203
|
+
INPUT_DRY_RUN: ${{ inputs.dry-run }}
|
|
204
|
+
OPENCODE_LOG_STYLE: github
|
|
205
|
+
run: |
|
|
206
|
+
set -euo pipefail
|
|
207
|
+
|
|
208
|
+
ARGS=()
|
|
209
|
+
if [ -n "${OPENCODE_ACTIONS_EVENT:-}" ]; then ARGS+=(--event "$OPENCODE_ACTIONS_EVENT"); fi
|
|
210
|
+
if [ -n "${INPUT_CONFIG:-}" ]; then ARGS+=(--config "$INPUT_CONFIG"); fi
|
|
211
|
+
if [ -n "${OPENCODE_ACTIONS_CONFIG_REPO:-}" ]; then ARGS+=(--config-repo "$OPENCODE_ACTIONS_CONFIG_REPO"); fi
|
|
212
|
+
if [ -n "${OPENCODE_ACTIONS_CONFIG_REF:-}" ]; then ARGS+=(--config-ref "$OPENCODE_ACTIONS_CONFIG_REF"); fi
|
|
213
|
+
if [ -n "${INPUT_MODE:-}" ]; then ARGS+=(--mode "$INPUT_MODE"); fi
|
|
214
|
+
if [ -n "${INPUT_PR:-}" ]; then ARGS+=(--pr "$INPUT_PR"); fi
|
|
215
|
+
if [ -n "${INPUT_ISSUE:-}" ]; then ARGS+=(--issue "$INPUT_ISSUE"); fi
|
|
216
|
+
if [ -n "${INPUT_RUN_ID:-}" ]; then ARGS+=(--run-id "$INPUT_RUN_ID"); fi
|
|
217
|
+
if [ "${INPUT_DRY_RUN:-false}" = "true" ]; then ARGS+=(--dry-run); fi
|
|
218
|
+
|
|
219
|
+
BIN="$RUNNER_TEMP/opencode-actions/node_modules/@eduardo191labs/opencode-actions/dist/cli.js"
|
|
220
|
+
|
|
221
|
+
set +e
|
|
222
|
+
OUTPUT=$(node "$BIN" "${ARGS[@]}" 2> "$RUNNER_TEMP/opencode-actions.log")
|
|
223
|
+
STATUS=$?
|
|
224
|
+
set -e
|
|
225
|
+
|
|
226
|
+
cat "$RUNNER_TEMP/opencode-actions.log" >&2
|
|
227
|
+
|
|
228
|
+
echo "result<<__EOF__" >> "$GITHUB_OUTPUT"
|
|
229
|
+
echo "$OUTPUT" >> "$GITHUB_OUTPUT"
|
|
230
|
+
echo "__EOF__" >> "$GITHUB_OUTPUT"
|
|
231
|
+
|
|
232
|
+
echo "$OUTPUT" | node -e '
|
|
233
|
+
let data = "";
|
|
234
|
+
process.stdin.on("data", (chunk) => (data += chunk));
|
|
235
|
+
process.stdin.on("end", () => {
|
|
236
|
+
try {
|
|
237
|
+
const parsed = JSON.parse(data);
|
|
238
|
+
const out = [];
|
|
239
|
+
if (parsed.posted) out.push("verdict=" + parsed.posted);
|
|
240
|
+
if (parsed.review?.findings) out.push("findings=" + parsed.review.findings.length);
|
|
241
|
+
if (parsed.pr) out.push("pr=" + parsed.pr);
|
|
242
|
+
if (out.length) process.stdout.write(out.join("\n") + "\n");
|
|
243
|
+
} catch {}
|
|
244
|
+
});
|
|
245
|
+
' >> "$GITHUB_OUTPUT"
|
|
246
|
+
|
|
247
|
+
if [ "${INPUT_SUMMARY:-true}" = "true" ]; then
|
|
248
|
+
node "$RUNNER_TEMP/opencode-actions/node_modules/@eduardo191labs/opencode-actions/dist/summary.js" "$OUTPUT" || true
|
|
249
|
+
fi
|
|
250
|
+
|
|
251
|
+
exit $STATUS
|