@eduardo191labs/opencode-actions 0.1.1 → 0.1.2
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 +67 -0
- package/action.yml +53 -9
- package/dist/actions.d.ts +74 -0
- package/dist/actions.js +137 -3
- package/dist/cli.js +1 -1
- package/dist/compile.js +15 -11
- package/dist/detect.js +62 -0
- package/dist/format.d.ts +1 -0
- package/dist/review-thread.d.ts +63 -0
- package/dist/review-thread.js +70 -0
- package/dist/runner.js +1 -1
- package/package.json +4 -2
- package/scripts/check-marketplace.js +111 -0
- package/scripts/install-opencode.sh +74 -0
package/README.md
CHANGED
|
@@ -17,6 +17,8 @@ click; the bot never pushes during a review.
|
|
|
17
17
|
| Capability | Trigger | What happens |
|
|
18
18
|
|---|---|---|
|
|
19
19
|
| **PR review** | `pull_request` opened / updated / ready | Inline comments with `suggestion` blocks. Never edits, approves or pushes by default. |
|
|
20
|
+
| **Review replies** | comment on a diff line | Answered in its own thread with the hunk GitHub sends. `/bot fix` commits to the head branch. |
|
|
21
|
+
| **Commit review** | `push` to a tracked branch | Reviews the change and posts it as a commit comment. |
|
|
20
22
|
| **Issue triage** | `issues` opened | Severity, labels, a reproduction verdict and a plan. |
|
|
21
23
|
| **Issue answer** | `/bot answer` | A grounded answer citing `file:line`. |
|
|
22
24
|
| **Issue implementation** | `/bot implement` | Makes the change, commits it, opens a PR. |
|
|
@@ -307,6 +309,71 @@ opencode-actions --mode capabilities # what the bot may do on GitHub
|
|
|
307
309
|
| `/bot close` / `/bot reopen` | Change issue or PR state. |
|
|
308
310
|
| `/bot help` | List commands. |
|
|
309
311
|
|
|
312
|
+
Commands also work in a **line comment on the diff**: GitHub sends the file, the line
|
|
313
|
+
and the hunk, so the answer is posted in that same thread. A plain comment there is
|
|
314
|
+
ignored unless the bot is mentioned, and `/bot fix` commits the change to the head
|
|
315
|
+
branch instead of replying with a diff.
|
|
316
|
+
|
|
317
|
+
## Events
|
|
318
|
+
|
|
319
|
+
Each event is handled by its own workflow, so a repository only pays for the ones it
|
|
320
|
+
installs.
|
|
321
|
+
|
|
322
|
+
| Event | Handler | Installed as |
|
|
323
|
+
|---|---|---|
|
|
324
|
+
| `pull_request` | review with inline suggestions | `opencode-review.yml` |
|
|
325
|
+
| `pull_request_review_comment` | in-thread reply, optional fix | `opencode-comments.yml` |
|
|
326
|
+
| `issue_comment` | `/bot` commands | `opencode-commands.yml` |
|
|
327
|
+
| `issues` | triage | `opencode-issues.yml` |
|
|
328
|
+
| `push` | commit review | `opencode-commits.yml` |
|
|
329
|
+
| `workflow_run` | autofix a failing run | added on demand |
|
|
330
|
+
|
|
331
|
+
## GitHub Marketplace
|
|
332
|
+
|
|
333
|
+
The Marketplace checkbox has **no API**: GitHub only offers it in the release form,
|
|
334
|
+
and the listing is a property of the first release of each major line. The `Marketplace`
|
|
335
|
+
workflow therefore automates everything around it:
|
|
336
|
+
|
|
337
|
+
1. verifies the public repository, the single root `action.yml`, the metadata rules and
|
|
338
|
+
the existence of the major tag;
|
|
339
|
+
2. fetches the public listing page to decide whether the action is already listed;
|
|
340
|
+
3. opens a tracking issue with the exact click-path when it is not.
|
|
341
|
+
|
|
342
|
+
`scripts/check-marketplace.js` enforces the rules that only surface at publish time:
|
|
343
|
+
|
|
344
|
+
| Rule | Check |
|
|
345
|
+
|---|---|
|
|
346
|
+
| `name` present, ≤ 65 characters, not reserved | ✓ |
|
|
347
|
+
| `description` < 125 characters | ✓ |
|
|
348
|
+
| `branding.icon` is a Feather icon name | ✓ |
|
|
349
|
+
| `branding.color` ∈ 8 accepted values | ✓ |
|
|
350
|
+
| public repository, one root metadata file | ✓ |
|
|
351
|
+
| global name uniqueness | reported, cannot be checked offline |
|
|
352
|
+
|
|
353
|
+
To list the action: open the release for the major tag → **Edit** → tick
|
|
354
|
+
**Publish this Action to the GitHub Marketplace** → accept the Developer Agreement if
|
|
355
|
+
prompted → choose a category → **Update release**. Later releases in that major line
|
|
356
|
+
update the listing automatically.
|
|
357
|
+
|
|
358
|
+
## Release process
|
|
359
|
+
|
|
360
|
+
Nothing is built or published from a developer machine. A release is a tag:
|
|
361
|
+
|
|
362
|
+
```bash
|
|
363
|
+
git tag -a v0.1.2 -m "opencode-actions 0.1.2"
|
|
364
|
+
git push origin v0.1.2
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
The `Release` workflow then:
|
|
368
|
+
|
|
369
|
+
1. builds and runs the tests;
|
|
370
|
+
2. fails if the committed JSON schema differs from the generated one;
|
|
371
|
+
3. validates `action.yml` against the Marketplace rules;
|
|
372
|
+
4. publishes to npm **only if the registry does not already have that version**;
|
|
373
|
+
5. creates the GitHub Release with the tarball;
|
|
374
|
+
6. force-moves the floating major tag (`v0`).
|
|
375
|
+
|
|
310
376
|
## License
|
|
311
377
|
|
|
378
|
+
|
|
312
379
|
MIT
|
package/action.yml
CHANGED
|
@@ -82,6 +82,14 @@ inputs:
|
|
|
82
82
|
description: "Print the compiled configuration and exit without acting."
|
|
83
83
|
required: false
|
|
84
84
|
default: "false"
|
|
85
|
+
version:
|
|
86
|
+
description: "Exact npm version of the bot to install. Defaults to latest."
|
|
87
|
+
required: false
|
|
88
|
+
default: "latest"
|
|
89
|
+
opencode-version:
|
|
90
|
+
description: "OpenCode CLI version or 'stable'. The bot requires V2."
|
|
91
|
+
required: false
|
|
92
|
+
default: "stable"
|
|
85
93
|
|
|
86
94
|
outputs:
|
|
87
95
|
result:
|
|
@@ -98,23 +106,56 @@ outputs:
|
|
|
98
106
|
runs:
|
|
99
107
|
using: "composite"
|
|
100
108
|
steps:
|
|
101
|
-
- name: Install OpenCode
|
|
109
|
+
- name: Install OpenCode V2
|
|
110
|
+
shell: bash
|
|
111
|
+
env:
|
|
112
|
+
OPENCODE_CHANNEL: ${{ inputs.opencode-version }}
|
|
113
|
+
run: bash "${{ github.action_path }}/scripts/install-opencode.sh"
|
|
114
|
+
|
|
115
|
+
- name: Verify the runtime is V2
|
|
102
116
|
shell: bash
|
|
103
117
|
run: |
|
|
104
118
|
set -euo pipefail
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
"$HOME/.opencode/bin/opencode" --version 2>/dev/null || opencode --version
|
|
119
|
+
echo "opencode2: $("${OPENCODE_BIN}" --version)"
|
|
120
|
+
# Guard against a silently wrong install: the generated configuration
|
|
121
|
+
# uses the V2 permissions ruleset, which a V1 runtime rejects.
|
|
122
|
+
"${OPENCODE_BIN}" --version | grep -Eq 'v?2\.' \
|
|
123
|
+
|| { echo "::error::expected OpenCode V2, got $("${OPENCODE_BIN}" --version)"; exit 1; }
|
|
111
124
|
|
|
112
125
|
- name: Install the bot package
|
|
113
126
|
shell: bash
|
|
127
|
+
env:
|
|
128
|
+
ACTION_REF: ${{ github.action_ref }}
|
|
129
|
+
INPUT_VERSION: ${{ inputs.version }}
|
|
114
130
|
run: |
|
|
115
131
|
set -euo pipefail
|
|
116
|
-
npm
|
|
117
|
-
|
|
132
|
+
# `github.action_ref` is a git ref (v0), not an npm version, so it must
|
|
133
|
+
# not be passed to npm. Only an exact semver ref is meaningful here.
|
|
134
|
+
VERSION="${INPUT_VERSION:-latest}"
|
|
135
|
+
if [ "${VERSION}" = "latest" ] && [[ "${ACTION_REF:-}" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
|
136
|
+
VERSION="${ACTION_REF#v}"
|
|
137
|
+
fi
|
|
138
|
+
|
|
139
|
+
echo "→ installing @eduardo191labs/opencode-actions@$VERSION (ref ${ACTION_REF:-none})"
|
|
140
|
+
|
|
141
|
+
# npm needs a moment before a freshly published version is resolvable.
|
|
142
|
+
# Retry rather than failing the whole run on propagation lag.
|
|
143
|
+
ATTEMPT=1
|
|
144
|
+
until npm install --prefix "$RUNNER_TEMP/opencode-actions" \
|
|
145
|
+
"@eduardo191labs/opencode-actions@$VERSION" --no-audit --no-fund; do
|
|
146
|
+
if [ "$ATTEMPT" -ge 5 ]; then
|
|
147
|
+
echo "::error::could not install @eduardo191labs/opencode-actions@$VERSION after $ATTEMPT attempts"
|
|
148
|
+
exit 1
|
|
149
|
+
fi
|
|
150
|
+
echo " attempt $ATTEMPT failed; retrying in 15s"
|
|
151
|
+
ATTEMPT=$((ATTEMPT + 1))
|
|
152
|
+
sleep 15
|
|
153
|
+
done
|
|
154
|
+
|
|
155
|
+
node -e '
|
|
156
|
+
const pkg = require(process.env.RUNNER_TEMP + "/opencode-actions/node_modules/@eduardo191labs/opencode-actions/package.json");
|
|
157
|
+
console.log("installed", pkg.name, pkg.version);
|
|
158
|
+
'
|
|
118
159
|
|
|
119
160
|
- name: Install and register plugins
|
|
120
161
|
if: inputs.plugins != ''
|
|
@@ -193,6 +234,7 @@ runs:
|
|
|
193
234
|
OPENCODE_ACTIONS_CONFIG_TOKEN: ${{ inputs.config-token }}
|
|
194
235
|
OPENCODE_BOT_MODEL: ${{ inputs.model }}
|
|
195
236
|
OPENCODE_ACTIONS_EVENT: ${{ inputs.event }}
|
|
237
|
+
OPENCODE_BIN: ${{ env.OPENCODE_BIN }}
|
|
196
238
|
INPUT_CONFIG: ${{ inputs.config }}
|
|
197
239
|
INPUT_MODE: ${{ inputs.mode }}
|
|
198
240
|
INPUT_PR: ${{ inputs.pr }}
|
|
@@ -202,6 +244,8 @@ runs:
|
|
|
202
244
|
INPUT_SUMMARY: ${{ inputs.summary }}
|
|
203
245
|
INPUT_DRY_RUN: ${{ inputs.dry-run }}
|
|
204
246
|
OPENCODE_LOG_STYLE: github
|
|
247
|
+
# The configuration uses the V2 permissions ruleset; there is no V1 path.
|
|
248
|
+
OPENCODE_CONFIG_PROTOCOL: v2
|
|
205
249
|
run: |
|
|
206
250
|
set -euo pipefail
|
|
207
251
|
|
package/dist/actions.d.ts
CHANGED
|
@@ -212,6 +212,52 @@ export declare function describePull(ctx: Context, number: number): Promise<{
|
|
|
212
212
|
described: boolean;
|
|
213
213
|
rejected?: undefined;
|
|
214
214
|
}>;
|
|
215
|
+
/**
|
|
216
|
+
* Answer a comment left on a specific line of a pull request.
|
|
217
|
+
*
|
|
218
|
+
* This is the interaction Copilot users reach for most: a comment on a diff
|
|
219
|
+
* line, answered where it was written. The payload already carries the file,
|
|
220
|
+
* the line and the hunk, so no checkout reconstruction is needed.
|
|
221
|
+
*/
|
|
222
|
+
export declare function handleReviewComment(ctx: Context, payload: any): Promise<{
|
|
223
|
+
skipped: boolean;
|
|
224
|
+
reason: string;
|
|
225
|
+
rejected?: undefined;
|
|
226
|
+
replied?: undefined;
|
|
227
|
+
fixed?: undefined;
|
|
228
|
+
} | {
|
|
229
|
+
rejected: string;
|
|
230
|
+
skipped?: undefined;
|
|
231
|
+
reason?: undefined;
|
|
232
|
+
replied?: undefined;
|
|
233
|
+
fixed?: undefined;
|
|
234
|
+
} | {
|
|
235
|
+
replied: boolean;
|
|
236
|
+
fixed: boolean;
|
|
237
|
+
skipped?: undefined;
|
|
238
|
+
reason?: undefined;
|
|
239
|
+
rejected?: undefined;
|
|
240
|
+
}>;
|
|
241
|
+
/** True when the comment names the bot, e.g. "@opencode" or "/bot". */
|
|
242
|
+
export declare function botMentioned(body: string, config: BotConfig): boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Review a push directly on the commits.
|
|
245
|
+
*
|
|
246
|
+
* `commit_review` exists for repositories where changes do not always come
|
|
247
|
+
* through a pull request: a direct push still gets a review posted as a commit
|
|
248
|
+
* comment, with the same finding schema and the same suggestion blocks.
|
|
249
|
+
*/
|
|
250
|
+
export declare function reviewPush(ctx: Context, payload: any): Promise<{
|
|
251
|
+
skipped: boolean;
|
|
252
|
+
reason: string;
|
|
253
|
+
reviewed?: undefined;
|
|
254
|
+
findings?: undefined;
|
|
255
|
+
} | {
|
|
256
|
+
reviewed: boolean;
|
|
257
|
+
findings: number;
|
|
258
|
+
skipped?: undefined;
|
|
259
|
+
reason?: undefined;
|
|
260
|
+
}>;
|
|
215
261
|
export type EventName = "pull_request" | "issue_comment" | "pull_request_review_comment" | "workflow_run" | "push" | "workflow_dispatch" | "issues";
|
|
216
262
|
/** Route a decoded GitHub event to the matching handler. */
|
|
217
263
|
export declare function dispatch(ctx: Context, event: EventName, payload: any): Promise<{
|
|
@@ -348,4 +394,32 @@ export declare function dispatch(ctx: Context, event: EventName, payload: any):
|
|
|
348
394
|
state?: undefined;
|
|
349
395
|
labels?: undefined;
|
|
350
396
|
assigned?: undefined;
|
|
397
|
+
} | {
|
|
398
|
+
skipped: boolean;
|
|
399
|
+
reason: string;
|
|
400
|
+
rejected?: undefined;
|
|
401
|
+
replied?: undefined;
|
|
402
|
+
fixed?: undefined;
|
|
403
|
+
} | {
|
|
404
|
+
rejected: string;
|
|
405
|
+
skipped?: undefined;
|
|
406
|
+
reason?: undefined;
|
|
407
|
+
replied?: undefined;
|
|
408
|
+
fixed?: undefined;
|
|
409
|
+
} | {
|
|
410
|
+
replied: boolean;
|
|
411
|
+
fixed: boolean;
|
|
412
|
+
skipped?: undefined;
|
|
413
|
+
reason?: undefined;
|
|
414
|
+
rejected?: undefined;
|
|
415
|
+
} | {
|
|
416
|
+
skipped: boolean;
|
|
417
|
+
reason: string;
|
|
418
|
+
reviewed?: undefined;
|
|
419
|
+
findings?: undefined;
|
|
420
|
+
} | {
|
|
421
|
+
reviewed: boolean;
|
|
422
|
+
findings: number;
|
|
423
|
+
skipped?: undefined;
|
|
424
|
+
reason?: undefined;
|
|
351
425
|
}>;
|
package/dist/actions.js
CHANGED
|
@@ -8,6 +8,7 @@ import { autofixPrompt, commandPrompt, describePrompt, issuePrompt, reviewPrompt
|
|
|
8
8
|
import { autofixBody, commandReplyBody, diffDigest, filesSummary, findingBody, issueTriageBody, reviewSummaryBody, severityRank, } from "./format.js";
|
|
9
9
|
import { assertBranchWrites, assertWorkflowWrites, commitAll, git, push, state } from "./git.js";
|
|
10
10
|
import { helpText, canRun } from "./commands.js";
|
|
11
|
+
import { reviewThreadPrompt, replyToReviewThread, threadContext, wantsFix } from "./review-thread.js";
|
|
11
12
|
export async function reviewPullRequest(ctx, options) {
|
|
12
13
|
const { github, repo, config } = ctx;
|
|
13
14
|
const pull = await github.getPull(repo, options.prNumber);
|
|
@@ -443,7 +444,7 @@ async function runWithPrompt(ctx, mode, prompt, content) {
|
|
|
443
444
|
const env = { ...process.env, OPENCODE_RESULT_FILE: resultPath };
|
|
444
445
|
const model = typeof content.model === "string" ? content.model : undefined;
|
|
445
446
|
ctx.log(`opencode run (${mode})${model ? ` with ${model}` : ""}`);
|
|
446
|
-
|
|
447
|
+
let result = await runOpencode({
|
|
447
448
|
message: `${prompt}\n\nThe result file is: ${resultPath}`,
|
|
448
449
|
cwd: ctx.workspace,
|
|
449
450
|
config: content,
|
|
@@ -453,6 +454,9 @@ async function runWithPrompt(ctx, mode, prompt, content) {
|
|
|
453
454
|
env,
|
|
454
455
|
live: feature(ctx.config, "live_log"),
|
|
455
456
|
});
|
|
457
|
+
return attachResult(result, resultPath);
|
|
458
|
+
}
|
|
459
|
+
async function attachResult(result, resultPath) {
|
|
456
460
|
let resultJson = null;
|
|
457
461
|
try {
|
|
458
462
|
resultJson = await readResult(resultPath);
|
|
@@ -462,7 +466,7 @@ async function runWithPrompt(ctx, mode, prompt, content) {
|
|
|
462
466
|
/* the agent may not have written it */
|
|
463
467
|
}
|
|
464
468
|
if (!result.ok) {
|
|
465
|
-
|
|
469
|
+
process.stderr.write(`[opencode-actions] run failed (exit ${result.exitCode}): ${result.error ?? ""}\n`);
|
|
466
470
|
}
|
|
467
471
|
return Object.assign(result, { resultJson });
|
|
468
472
|
}
|
|
@@ -508,6 +512,126 @@ async function listRootFiles(ctx) {
|
|
|
508
512
|
return [];
|
|
509
513
|
}
|
|
510
514
|
}
|
|
515
|
+
// ------------------------------------------------------- review comments
|
|
516
|
+
/**
|
|
517
|
+
* Answer a comment left on a specific line of a pull request.
|
|
518
|
+
*
|
|
519
|
+
* This is the interaction Copilot users reach for most: a comment on a diff
|
|
520
|
+
* line, answered where it was written. The payload already carries the file,
|
|
521
|
+
* the line and the hunk, so no checkout reconstruction is needed.
|
|
522
|
+
*/
|
|
523
|
+
export async function handleReviewComment(ctx, payload) {
|
|
524
|
+
const { github, repo, config } = ctx;
|
|
525
|
+
const comment = payload.comment;
|
|
526
|
+
const pullNumber = payload.pull_request.number;
|
|
527
|
+
// Never answer the bot's own reply, or a thread would grow by itself.
|
|
528
|
+
const self = (process.env.GITHUB_ACTOR ?? "github-actions[bot]").toLowerCase();
|
|
529
|
+
if (String(comment.user?.login ?? "").toLowerCase() === self)
|
|
530
|
+
return { skipped: true, reason: "own comment" };
|
|
531
|
+
const invocation = parseCommandBody(config, comment.body ?? "");
|
|
532
|
+
const fix = wantsFix(comment.body ?? "");
|
|
533
|
+
if (!invocation && !fix && !botMentioned(comment.body ?? "", config)) {
|
|
534
|
+
// A plain comment on a line is not necessarily addressed to the bot.
|
|
535
|
+
return { skipped: true, reason: "not addressed to the bot" };
|
|
536
|
+
}
|
|
537
|
+
if (permission(config, "comment") !== "allow")
|
|
538
|
+
return { rejected: "comment permission denied" };
|
|
539
|
+
const thread = await threadContext({
|
|
540
|
+
github,
|
|
541
|
+
repo,
|
|
542
|
+
pullNumber,
|
|
543
|
+
commentId: comment.id,
|
|
544
|
+
inReplyToId: comment.in_reply_to_id,
|
|
545
|
+
}).catch(() => "");
|
|
546
|
+
const compiled = compileConfig(config, { mode: fix ? "commands" : "review" });
|
|
547
|
+
const prompt = reviewThreadPrompt({
|
|
548
|
+
github,
|
|
549
|
+
repo,
|
|
550
|
+
path: comment.path,
|
|
551
|
+
line: comment.line ?? comment.original_line ?? 0,
|
|
552
|
+
diffHunk: comment.diff_hunk ?? "",
|
|
553
|
+
body: comment.body ?? "",
|
|
554
|
+
threadBody: thread,
|
|
555
|
+
author: comment.user.login,
|
|
556
|
+
pullNumber,
|
|
557
|
+
commentId: comment.id,
|
|
558
|
+
});
|
|
559
|
+
const result = await runWithPrompt(ctx, fix ? "commands" : "review", prompt, compiled.content);
|
|
560
|
+
let pushed = null;
|
|
561
|
+
if (fix) {
|
|
562
|
+
pushed = await pushChanges(ctx, compiled.content, {
|
|
563
|
+
branch: payload.pull_request.head.ref,
|
|
564
|
+
openPr: false,
|
|
565
|
+
base: payload.pull_request.base.ref,
|
|
566
|
+
title: `fix: address review comment on ${comment.path}`,
|
|
567
|
+
body: `Addresses the review comment on \`${comment.path}:${comment.line ?? "?"}\`.`,
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
const body = pushed
|
|
571
|
+
? `${result.text.trim()}
|
|
572
|
+
|
|
573
|
+
---
|
|
574
|
+
Pushed as a commit on \`${payload.pull_request.head.ref}\`.`
|
|
575
|
+
: result.text.trim() || "I could not produce an answer for this comment.";
|
|
576
|
+
await replyToReviewThread({ github, repo, pullNumber, commentId: comment.id, body });
|
|
577
|
+
ctx.log(`replied to review comment ${comment.id}${pushed ? " and pushed a fix" : ""}`);
|
|
578
|
+
return { replied: true, fixed: Boolean(pushed) };
|
|
579
|
+
}
|
|
580
|
+
/** True when the comment names the bot, e.g. "@opencode" or "/bot". */
|
|
581
|
+
export function botMentioned(body, config) {
|
|
582
|
+
const name = (bot(config).name ?? "opencode").toLowerCase();
|
|
583
|
+
const prefix = (bot(config).commands?.prefix ?? "/bot").toLowerCase();
|
|
584
|
+
const lower = body.toLowerCase();
|
|
585
|
+
return lower.includes(`@${name}`) || lower.includes(prefix);
|
|
586
|
+
}
|
|
587
|
+
// ------------------------------------------------------------- push review
|
|
588
|
+
/**
|
|
589
|
+
* Review a push directly on the commits.
|
|
590
|
+
*
|
|
591
|
+
* `commit_review` exists for repositories where changes do not always come
|
|
592
|
+
* through a pull request: a direct push still gets a review posted as a commit
|
|
593
|
+
* comment, with the same finding schema and the same suggestion blocks.
|
|
594
|
+
*/
|
|
595
|
+
export async function reviewPush(ctx, payload) {
|
|
596
|
+
const { github, repo, config } = ctx;
|
|
597
|
+
const before = payload.before;
|
|
598
|
+
const after = payload.after;
|
|
599
|
+
if (!after || /^0+$/.test(after))
|
|
600
|
+
return { skipped: true, reason: "branch deleted" };
|
|
601
|
+
const base = after === before ? `${after}^` : before;
|
|
602
|
+
const comparison = await github.compare(repo, base, after).catch(() => null);
|
|
603
|
+
if (!comparison?.files?.length)
|
|
604
|
+
return { skipped: true, reason: "no changed files" };
|
|
605
|
+
const files = comparison.files.slice(0, 100);
|
|
606
|
+
const compiled = compileConfig(config, { mode: "review" });
|
|
607
|
+
const prompt = reviewPrompt({
|
|
608
|
+
config,
|
|
609
|
+
repo: `${repo.owner}/${repo.repo}`,
|
|
610
|
+
prNumber: 0,
|
|
611
|
+
title: comparison.commits?.[0]?.commit?.message?.split("\n")[0] ?? "direct push",
|
|
612
|
+
author: payload.pusher?.name ?? "unknown",
|
|
613
|
+
base,
|
|
614
|
+
head: after,
|
|
615
|
+
filesSummary: filesSummary(files),
|
|
616
|
+
diffDigest: diffDigest(files, (bot(config).review?.max_diff_kb ?? 256) * 1024),
|
|
617
|
+
facts: repoFacts(await listRootFiles(ctx)),
|
|
618
|
+
extraInstructions: bot(config).review?.instructions,
|
|
619
|
+
});
|
|
620
|
+
const result = await runWithPrompt(ctx, "review", prompt, compiled.content);
|
|
621
|
+
const review = parseReview(result, ctx);
|
|
622
|
+
if (!review.findings.length)
|
|
623
|
+
return { reviewed: true, findings: 0 };
|
|
624
|
+
const body = reviewSummaryBody(config, review, {
|
|
625
|
+
model: compiled.model,
|
|
626
|
+
cost: result.cost,
|
|
627
|
+
durationMs: result.durationMs,
|
|
628
|
+
});
|
|
629
|
+
if (permission(config, "comment") === "allow") {
|
|
630
|
+
// A commit comment has its own endpoint; the issues endpoint wants a number.
|
|
631
|
+
await github.post(`/repos/${repo.owner}/${repo.repo}/commits/${after}/comments`, { body });
|
|
632
|
+
}
|
|
633
|
+
return { reviewed: true, findings: review.findings.length };
|
|
634
|
+
}
|
|
511
635
|
/** Route a decoded GitHub event to the matching handler. */
|
|
512
636
|
export async function dispatch(ctx, event, payload) {
|
|
513
637
|
switch (event) {
|
|
@@ -535,6 +659,13 @@ export async function dispatch(ctx, event, payload) {
|
|
|
535
659
|
return { skipped: true };
|
|
536
660
|
return handleIssue(ctx, payload.issue.number, "triage");
|
|
537
661
|
}
|
|
662
|
+
case "pull_request_review_comment": {
|
|
663
|
+
if (payload.action !== "created")
|
|
664
|
+
return { skipped: true };
|
|
665
|
+
if (!feature(ctx.config, "review_comments"))
|
|
666
|
+
return { skipped: true };
|
|
667
|
+
return handleReviewComment(ctx, payload);
|
|
668
|
+
}
|
|
538
669
|
case "workflow_run": {
|
|
539
670
|
if (payload.action !== "completed")
|
|
540
671
|
return { skipped: true };
|
|
@@ -543,7 +674,10 @@ export async function dispatch(ctx, event, payload) {
|
|
|
543
674
|
case "push": {
|
|
544
675
|
if (!feature(ctx.config, "commit_review"))
|
|
545
676
|
return { skipped: true };
|
|
546
|
-
|
|
677
|
+
// A push with no commits (a tag or a branch delete) has nothing to review.
|
|
678
|
+
if (!payload.commits?.length)
|
|
679
|
+
return { skipped: true, reason: "no commits in the push" };
|
|
680
|
+
return reviewPush(ctx, payload);
|
|
547
681
|
}
|
|
548
682
|
case "workflow_dispatch": {
|
|
549
683
|
const command = payload.inputs?.command ?? "review";
|
package/dist/cli.js
CHANGED
|
@@ -154,7 +154,7 @@ function usage() {
|
|
|
154
154
|
Usage:
|
|
155
155
|
opencode-actions --event <event> [flags]
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
pull_request, pull_request_review_comment, issue_comment, issues, workflow_run, push, workflow_dispatch
|
|
158
158
|
|
|
159
159
|
Flags:
|
|
160
160
|
--payload <file> Event payload (default: $GITHUB_EVENT_PATH)
|
package/dist/compile.js
CHANGED
|
@@ -25,17 +25,23 @@ export function compileConfig(config, options = { mode: "review" }) {
|
|
|
25
25
|
warnings.push("No model configured; OpenCode will use its default.");
|
|
26
26
|
// ------------------------------------------------------- permissions rules
|
|
27
27
|
const rules = buildPermissionRules(config, options.mode);
|
|
28
|
-
//
|
|
29
|
-
const
|
|
30
|
-
oc.permissions = [...
|
|
28
|
+
// The ruleset is the V2 shape. User rules come first so their denies win.
|
|
29
|
+
const existingRules = Array.isArray(oc.permissions) ? oc.permissions : [];
|
|
30
|
+
oc.permissions = [...existingRules, ...rules];
|
|
31
|
+
// A `permission` key belongs to V1 and V2 rejects it, so drop a leftover.
|
|
32
|
+
if ("permission" in oc) {
|
|
33
|
+
delete oc.permission;
|
|
34
|
+
warnings.push("removed the V1 `permission` key; V2 uses the `permissions` ruleset.");
|
|
35
|
+
}
|
|
31
36
|
// ---------------------------------------------------------------- the agent
|
|
32
37
|
const agents = { ...(oc.agents ?? {}) };
|
|
33
38
|
const agentName = "opencode-bot";
|
|
34
39
|
const existingAgent = agents[agentName] ?? {};
|
|
40
|
+
const { permissions: _ignored, ...agentRest } = existingAgent;
|
|
35
41
|
agents[agentName] = {
|
|
36
42
|
description: "Autonomous GitHub Actions agent for opencode-actions.",
|
|
37
43
|
mode: "primary",
|
|
38
|
-
...
|
|
44
|
+
...agentRest,
|
|
39
45
|
permissions: [
|
|
40
46
|
...(Array.isArray(existingAgent.permissions) ? existingAgent.permissions : []),
|
|
41
47
|
...rules,
|
|
@@ -57,13 +63,15 @@ export function compileConfig(config, options = { mode: "review" }) {
|
|
|
57
63
|
oc.websearch = false;
|
|
58
64
|
// A CI run has nobody to answer a permission prompt; anything left as "ask"
|
|
59
65
|
// is a bug in the configuration, so make it explicit instead of hanging.
|
|
60
|
-
const asks =
|
|
66
|
+
const asks = rules.filter((rule) => rule.effect === "ask");
|
|
61
67
|
for (const rule of asks) {
|
|
62
|
-
|
|
63
|
-
warnings.push(`permission "${rule.action}" is "ask"; the run will reject it in CI.`);
|
|
68
|
+
warnings.push(`permission "${rule.action}" is "ask"; the run will reject it in CI.`);
|
|
64
69
|
}
|
|
65
70
|
return { content: oc, warnings, model };
|
|
66
71
|
}
|
|
72
|
+
function isPlainObject(value) {
|
|
73
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
74
|
+
}
|
|
67
75
|
function pickTaskModel(config, mode) {
|
|
68
76
|
const tasks = config.bot?.model?.tasks;
|
|
69
77
|
if (!tasks)
|
|
@@ -89,10 +97,6 @@ function isMcpShape(value) {
|
|
|
89
97
|
const record = value;
|
|
90
98
|
return "servers" in record || "timeout" in record;
|
|
91
99
|
}
|
|
92
|
-
function isInteractiveCapable(_rule) {
|
|
93
|
-
// In CI nothing can be asked; a run that hits "ask" is rejected by the runner.
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
100
|
/**
|
|
97
101
|
* Map GitHub capabilities onto OpenCode tool rules.
|
|
98
102
|
*
|
package/dist/detect.js
CHANGED
|
@@ -176,6 +176,68 @@ jobs:
|
|
|
176
176
|
${common}
|
|
177
177
|
env:
|
|
178
178
|
FREEPI_JWT: \${{ secrets.FREEPI_JWT }}
|
|
179
|
+
`,
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
path: ".github/workflows/opencode-commits.yml",
|
|
183
|
+
content: `name: OpenCode Commits
|
|
184
|
+
on:
|
|
185
|
+
push:
|
|
186
|
+
branches: [main, master]
|
|
187
|
+
|
|
188
|
+
permissions:
|
|
189
|
+
contents: read
|
|
190
|
+
issues: write
|
|
191
|
+
|
|
192
|
+
jobs:
|
|
193
|
+
commits:
|
|
194
|
+
if: github.event.deleted == false
|
|
195
|
+
runs-on: ubuntu-latest
|
|
196
|
+
steps:
|
|
197
|
+
- uses: actions/checkout@v4
|
|
198
|
+
with:
|
|
199
|
+
fetch-depth: 0
|
|
200
|
+
- uses: eduardo191-star/opencode-actions@${actionRef}
|
|
201
|
+
with:
|
|
202
|
+
event: push
|
|
203
|
+
github-token: \${{ secrets.GITHUB_TOKEN }}
|
|
204
|
+
${common}
|
|
205
|
+
env:
|
|
206
|
+
FREEPI_JWT: \${{ secrets.FREEPI_JWT }}
|
|
207
|
+
`,
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
path: ".github/workflows/opencode-comments.yml",
|
|
211
|
+
content: `name: OpenCode Comments
|
|
212
|
+
on:
|
|
213
|
+
pull_request_review_comment:
|
|
214
|
+
types: [created]
|
|
215
|
+
|
|
216
|
+
permissions:
|
|
217
|
+
contents: write
|
|
218
|
+
pull-requests: write
|
|
219
|
+
issues: write
|
|
220
|
+
|
|
221
|
+
${watchdog}
|
|
222
|
+
jobs:
|
|
223
|
+
comment:
|
|
224
|
+
if: |
|
|
225
|
+
contains(github.event.comment.body, '/bot') ||
|
|
226
|
+
contains(github.event.comment.body, '/oc') ||
|
|
227
|
+
contains(github.event.comment.body, '@opencode')
|
|
228
|
+
runs-on: ubuntu-latest
|
|
229
|
+
steps:
|
|
230
|
+
- uses: actions/checkout@v4
|
|
231
|
+
with:
|
|
232
|
+
ref: \${{ github.event.pull_request.head.sha }}
|
|
233
|
+
fetch-depth: 0
|
|
234
|
+
- uses: eduardo191-star/opencode-actions@${actionRef}
|
|
235
|
+
with:
|
|
236
|
+
event: pull_request_review_comment
|
|
237
|
+
github-token: \${{ secrets.GITHUB_TOKEN }}
|
|
238
|
+
${common}
|
|
239
|
+
env:
|
|
240
|
+
FREEPI_JWT: \${{ secrets.FREEPI_JWT }}
|
|
179
241
|
`,
|
|
180
242
|
},
|
|
181
243
|
{
|
package/dist/format.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare function verdictLine(verdict: ReviewResult["verdict"]): "✅ **Ap
|
|
|
22
22
|
export declare function reviewSummaryBody(config: BotConfig, review: ReviewResult, meta: {
|
|
23
23
|
model?: string;
|
|
24
24
|
cost?: number;
|
|
25
|
+
durationMs?: number;
|
|
25
26
|
}): string;
|
|
26
27
|
export declare function footer(config: BotConfig, meta: {
|
|
27
28
|
model?: string;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { GitHub, type RepoRef } from "./github.js";
|
|
2
|
+
/**
|
|
3
|
+
* Review-thread handling.
|
|
4
|
+
*
|
|
5
|
+
* GitHub Copilot's most used behaviour is not the initial review: it is
|
|
6
|
+
* answering on the line the author is already looking at. That happens on
|
|
7
|
+
* `pull_request_review_comment`, where the payload carries the diff hunk, the
|
|
8
|
+
* file and the line, so the agent needs none of it reconstructed.
|
|
9
|
+
*
|
|
10
|
+
* Two modes:
|
|
11
|
+
* - a bare reply (no command) is answered in the thread with context;
|
|
12
|
+
* - `/bot fix` applies the change and commits it to the head branch.
|
|
13
|
+
*/
|
|
14
|
+
export interface ReviewCommentContext {
|
|
15
|
+
github: GitHub;
|
|
16
|
+
repo: RepoRef;
|
|
17
|
+
/** Repository-relative file the comment is attached to. */
|
|
18
|
+
path: string;
|
|
19
|
+
/** Line on the side GitHub reports. */
|
|
20
|
+
line: number;
|
|
21
|
+
/** The hunk GitHub includes, which is enough to reason without a checkout. */
|
|
22
|
+
diffHunk: string;
|
|
23
|
+
/** Body of the comment that started the thread. */
|
|
24
|
+
body: string;
|
|
25
|
+
/** Body of the root comment when this is a reply. */
|
|
26
|
+
threadBody?: string;
|
|
27
|
+
author: string;
|
|
28
|
+
pullNumber: number;
|
|
29
|
+
/** Comment id, used to reply in the same thread. */
|
|
30
|
+
commentId: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Build the prompt for a review-thread reply. The hunk is the whole point: it
|
|
34
|
+
* pins the model to the exact lines instead of letting it re-read the file and
|
|
35
|
+
* answer about a different revision.
|
|
36
|
+
*/
|
|
37
|
+
export declare function reviewThreadPrompt(input: ReviewCommentContext): string;
|
|
38
|
+
/**
|
|
39
|
+
* Reply inside a review-comment thread.
|
|
40
|
+
*
|
|
41
|
+
* Using `in_reply_to` keeps the answer attached to the line instead of opening
|
|
42
|
+
* a detached issue comment the author will never associate with the diff.
|
|
43
|
+
*/
|
|
44
|
+
export declare function replyToReviewThread(input: {
|
|
45
|
+
github: GitHub;
|
|
46
|
+
repo: RepoRef;
|
|
47
|
+
pullNumber: number;
|
|
48
|
+
commentId: number;
|
|
49
|
+
body: string;
|
|
50
|
+
}): Promise<unknown>;
|
|
51
|
+
/** True when a review comment asks the bot to change the code rather than explain it. */
|
|
52
|
+
export declare function wantsFix(body: string, configured?: string[]): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Collect the conversation above a review comment so a reply has context.
|
|
55
|
+
* GitHub returns comments in creation order per pull request.
|
|
56
|
+
*/
|
|
57
|
+
export declare function threadContext(input: {
|
|
58
|
+
github: GitHub;
|
|
59
|
+
repo: RepoRef;
|
|
60
|
+
pullNumber: number;
|
|
61
|
+
commentId: number;
|
|
62
|
+
inReplyToId?: number | null;
|
|
63
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { parseInvocation } from "./commands.js";
|
|
2
|
+
/**
|
|
3
|
+
* Build the prompt for a review-thread reply. The hunk is the whole point: it
|
|
4
|
+
* pins the model to the exact lines instead of letting it re-read the file and
|
|
5
|
+
* answer about a different revision.
|
|
6
|
+
*/
|
|
7
|
+
export function reviewThreadPrompt(input) {
|
|
8
|
+
return `# Task: answer a review comment
|
|
9
|
+
|
|
10
|
+
Repository: ${input.repo.owner}/${input.repo.repo}
|
|
11
|
+
Pull request: #${input.pullNumber}
|
|
12
|
+
File: \`${input.path}\`
|
|
13
|
+
Line: ${input.line}
|
|
14
|
+
Commented by: @${input.author}
|
|
15
|
+
|
|
16
|
+
## The comment
|
|
17
|
+
|
|
18
|
+
${input.body}
|
|
19
|
+
|
|
20
|
+
${input.threadBody && input.threadBody !== input.body ? `## Earlier in this thread\n\n${input.threadBody}\n` : ""}
|
|
21
|
+
|
|
22
|
+
## The exact lines GitHub reports
|
|
23
|
+
|
|
24
|
+
\`\`\`diff
|
|
25
|
+
${input.diffHunk}
|
|
26
|
+
\`\`\`
|
|
27
|
+
|
|
28
|
+
## Goal
|
|
29
|
+
|
|
30
|
+
Answer the question about these lines. If the comment asserts a bug, check the
|
|
31
|
+
surrounding code in the checkout before agreeing or disagreeing: the hunk alone
|
|
32
|
+
does not prove the surrounding behaviour.
|
|
33
|
+
|
|
34
|
+
- If a change is needed, say precisely what and where.
|
|
35
|
+
- If the comment is wrong, say why, with the code that shows it.
|
|
36
|
+
- If a \`\`\`suggestion block would express the fix exactly, include one; it
|
|
37
|
+
becomes a one-click button.
|
|
38
|
+
- Do not restate the comment. Do not pad.
|
|
39
|
+
|
|
40
|
+
Keep it under 200 words unless the change genuinely needs more.`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Reply inside a review-comment thread.
|
|
44
|
+
*
|
|
45
|
+
* Using `in_reply_to` keeps the answer attached to the line instead of opening
|
|
46
|
+
* a detached issue comment the author will never associate with the diff.
|
|
47
|
+
*/
|
|
48
|
+
export async function replyToReviewThread(input) {
|
|
49
|
+
return input.github.post(`/repos/${input.repo.owner}/${input.repo.repo}/pulls/${input.pullNumber}/comments/${input.commentId}/replies`, { body: input.body });
|
|
50
|
+
}
|
|
51
|
+
/** True when a review comment asks the bot to change the code rather than explain it. */
|
|
52
|
+
export function wantsFix(body, configured = ["fix", "change", "apply", "implement"]) {
|
|
53
|
+
const invocation = parseInvocation(body, { version: 1 });
|
|
54
|
+
if (invocation && ["fix", "implement"].includes(invocation.command))
|
|
55
|
+
return true;
|
|
56
|
+
const lower = body.toLowerCase();
|
|
57
|
+
return configured.some((word) => new RegExp(`\\b${word}\\b`, "i").test(lower));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Collect the conversation above a review comment so a reply has context.
|
|
61
|
+
* GitHub returns comments in creation order per pull request.
|
|
62
|
+
*/
|
|
63
|
+
export async function threadContext(input) {
|
|
64
|
+
const all = await input.github.paginate(`/repos/${input.repo.owner}/${input.repo.repo}/pulls/${input.pullNumber}/comments?per_page=100`, 3);
|
|
65
|
+
const root = input.inReplyToId ?? input.commentId;
|
|
66
|
+
return all
|
|
67
|
+
.filter((comment) => comment.id === root || comment.in_reply_to_id === root)
|
|
68
|
+
.map((comment) => `@${comment.user.login}: ${comment.body}`)
|
|
69
|
+
.join("\n\n");
|
|
70
|
+
}
|
package/dist/runner.js
CHANGED
|
@@ -136,7 +136,7 @@ export async function runOpencode(options) {
|
|
|
136
136
|
args.push("--file", file);
|
|
137
137
|
args.push("--", options.message);
|
|
138
138
|
args.push(...(options.extraArgs ?? []));
|
|
139
|
-
const executable = options.executable ?? env.OPENCODE_BIN ?? "
|
|
139
|
+
const executable = options.executable ?? env.OPENCODE_BIN ?? "opencode2";
|
|
140
140
|
const renderer = options.live ? createRenderer(env.OPENCODE_LOG_STYLE ?? "github") : null;
|
|
141
141
|
const result = {
|
|
142
142
|
ok: false,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@eduardo191labs/opencode-actions",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"description": "GitHub Copilot-equivalent bot for OpenCode: PRs, reviews, issues, workflow autofix, MCP tools and comment commands.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -39,7 +39,9 @@
|
|
|
39
39
|
"action.yml",
|
|
40
40
|
"schemas",
|
|
41
41
|
"README.md",
|
|
42
|
-
"LICENSE"
|
|
42
|
+
"LICENSE",
|
|
43
|
+
"scripts/install-opencode.sh",
|
|
44
|
+
"scripts/check-marketplace.js"
|
|
43
45
|
],
|
|
44
46
|
"engines": {
|
|
45
47
|
"node": ">=20"
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Checks action.yml against the rules GitHub Marketplace applies at publish
|
|
4
|
+
* time. A violation there fails the listing with a vague message, so catching
|
|
5
|
+
* it in CI is the only way to find out before a release is tagged.
|
|
6
|
+
*
|
|
7
|
+
* Rules enforced (docs.github.com, "Publishing actions in GitHub Marketplace"):
|
|
8
|
+
* - action.yml must exist at the repository root and be named exactly that;
|
|
9
|
+
* - `name` is present, unique in spirit, and is not a reserved Marketplace name;
|
|
10
|
+
* - `description` is present and shorter than 125 characters;
|
|
11
|
+
* - `branding.icon` is a Feather icon name and `branding.color` is one of the
|
|
12
|
+
* eight accepted colours;
|
|
13
|
+
* - the repository is public.
|
|
14
|
+
*
|
|
15
|
+
* What cannot be checked offline is reported instead of implied: global name
|
|
16
|
+
* uniqueness, and whether the icon exists in the current Feather set.
|
|
17
|
+
*/
|
|
18
|
+
import { readFileSync, existsSync } from "node:fs"
|
|
19
|
+
|
|
20
|
+
const LIMITS = { description: 125, name: 65 }
|
|
21
|
+
const COLORS = ["white", "yellow", "blue", "green", "orange", "red", "purple", "gray-dark"]
|
|
22
|
+
const RESERVED = [
|
|
23
|
+
"actions",
|
|
24
|
+
"marketplace",
|
|
25
|
+
"github",
|
|
26
|
+
"github actions",
|
|
27
|
+
"workflow",
|
|
28
|
+
"apps",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
const errors = []
|
|
32
|
+
const warnings = []
|
|
33
|
+
|
|
34
|
+
if (!existsSync("action.yml")) {
|
|
35
|
+
console.error("action.yml is missing from the repository root")
|
|
36
|
+
process.exit(1)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// A minimal parser keeps this dependency-free; the file is small and the fields
|
|
40
|
+
// are flat, so an indentation-aware reader is enough and does not risk pulling
|
|
41
|
+
// a YAML engine into the release path.
|
|
42
|
+
const lines = readFileSync("action.yml", "utf8").replace(/\r\n/g, "\n").split("\n")
|
|
43
|
+
const fields = {}
|
|
44
|
+
let section = null
|
|
45
|
+
for (const line of lines) {
|
|
46
|
+
if (/^[a-z]/.test(line)) {
|
|
47
|
+
const [key, ...rest] = line.split(":")
|
|
48
|
+
section = key.trim()
|
|
49
|
+
const value = rest.join(":").trim()
|
|
50
|
+
if (value) fields[section] = unquote(value)
|
|
51
|
+
continue
|
|
52
|
+
}
|
|
53
|
+
const match = /^\s{2}([a-z-]+):\s*(.*)$/.exec(line)
|
|
54
|
+
if (match && section) {
|
|
55
|
+
const key = `${section}.${match[1]}`
|
|
56
|
+
if (match[2].trim()) fields[key] = unquote(match[2].trim())
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function unquote(value) {
|
|
61
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
62
|
+
return value.slice(1, -1)
|
|
63
|
+
}
|
|
64
|
+
return value
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const name = fields.name
|
|
68
|
+
const description = fields.description
|
|
69
|
+
const icon = fields["branding.icon"]
|
|
70
|
+
const color = fields["branding.color"]
|
|
71
|
+
|
|
72
|
+
if (!name) errors.push("`name` is missing")
|
|
73
|
+
else {
|
|
74
|
+
if (name.length > LIMITS.name) errors.push(`\`name\` is ${name.length} characters (limit ${LIMITS.name})`)
|
|
75
|
+
if (RESERVED.includes(name.toLowerCase())) errors.push(`\`name\` "${name}" is reserved by GitHub`)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!description) errors.push("`description` is missing")
|
|
79
|
+
else if (description.length >= LIMITS.description) {
|
|
80
|
+
errors.push(`\`description\` is ${description.length} characters; Marketplace requires fewer than ${LIMITS.description}`)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!icon) errors.push("`branding.icon` is missing")
|
|
84
|
+
else if (!/^[a-z][a-z0-9-]*$/.test(icon)) errors.push(`\`branding.icon\` "${icon}" is not shaped like a Feather icon name`)
|
|
85
|
+
|
|
86
|
+
if (!color) errors.push("`branding.color` is missing")
|
|
87
|
+
else if (!COLORS.includes(color)) errors.push(`\`branding.color\` "${color}" must be one of ${COLORS.join(", ")}`)
|
|
88
|
+
|
|
89
|
+
if (fields.runs && !existsSync("action.yml")) errors.push("action metadata disappeared during the check")
|
|
90
|
+
|
|
91
|
+
if (!/^composite$|^node\d*$|^docker$/m.test(fields["runs.using"] ?? "")) {
|
|
92
|
+
errors.push("`runs.using` must be composite, node20/node22, or docker")
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!fields["runs.using"]) errors.push("`runs.using` is missing")
|
|
96
|
+
|
|
97
|
+
warnings.push("global name uniqueness cannot be verified offline")
|
|
98
|
+
warnings.push(`icon "${icon ?? "?"}" shape is checked, not membership in the current Feather set`)
|
|
99
|
+
|
|
100
|
+
for (const warning of warnings) console.log(`· ${warning}`)
|
|
101
|
+
|
|
102
|
+
if (errors.length) {
|
|
103
|
+
for (const error of errors) console.error(`✗ ${error}`)
|
|
104
|
+
console.error(`\n${errors.length} Marketplace rule(s) violated`)
|
|
105
|
+
process.exit(1)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
console.log(`✓ action.yml satisfies the checkable Marketplace rules`)
|
|
109
|
+
console.log(` name: ${name} (${name.length}/${LIMITS.name})`)
|
|
110
|
+
console.log(` description: ${description.length}/${LIMITS.description - 1} characters`)
|
|
111
|
+
console.log(` branding: ${icon} / ${color}`)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# install-opencode.sh — installs the official OpenCode CLI and guarantees that
|
|
3
|
+
# `opencode2` (the V2 runtime) is available.
|
|
4
|
+
#
|
|
5
|
+
# Why npm and not the curl installer:
|
|
6
|
+
# - @opencode/cli ships both `opencode` and `opencode2` as bin entries pointing
|
|
7
|
+
# at the native binary, so installing the package gives us both names for the
|
|
8
|
+
# same runtime without guessing a release URL.
|
|
9
|
+
# - The version is pinned so a CI run is reproducible, and a floating channel
|
|
10
|
+
# can be requested when that is what we want.
|
|
11
|
+
#
|
|
12
|
+
# Environment:
|
|
13
|
+
# OPENCODE_CHANNEL "stable" (default) or an exact version such as 2.4.2
|
|
14
|
+
# OPENCODE_BIN output: the resolved binary path
|
|
15
|
+
set -euo pipefail
|
|
16
|
+
|
|
17
|
+
CHANNEL="${OPENCODE_CHANNEL:-stable}"
|
|
18
|
+
|
|
19
|
+
if [ "${CHANNEL}" = "stable" ]; then
|
|
20
|
+
SPEC="@opencode/cli@latest"
|
|
21
|
+
else
|
|
22
|
+
SPEC="@opencode/cli@${CHANNEL}"
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
echo "→ installing ${SPEC} from npm"
|
|
26
|
+
npm install -g "${SPEC}" --no-audit --no-fund
|
|
27
|
+
|
|
28
|
+
PREFIX="$(npm prefix -g)"
|
|
29
|
+
BIN_DIR="${PREFIX}/bin"
|
|
30
|
+
|
|
31
|
+
# Prefer the V2 entry point: everything this bot emits targets the V2 config
|
|
32
|
+
# schema (the `permissions` ruleset), which V1 rejects outright.
|
|
33
|
+
CANDIDATES=(
|
|
34
|
+
"${BIN_DIR}/opencode2"
|
|
35
|
+
"${BIN_DIR}/opencode"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
RESOLVED=""
|
|
39
|
+
for candidate in "${CANDIDATES[@]}"; do
|
|
40
|
+
if [ -x "${candidate}" ]; then
|
|
41
|
+
RESOLVED="${candidate}"
|
|
42
|
+
break
|
|
43
|
+
fi
|
|
44
|
+
done
|
|
45
|
+
|
|
46
|
+
if [ -z "${RESOLVED}" ]; then
|
|
47
|
+
echo "::error::could not find an opencode binary under ${BIN_DIR}"
|
|
48
|
+
ls -la "${BIN_DIR}" >&2 || true
|
|
49
|
+
exit 1
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
# The native package may expose the binary under a different name; a symlink
|
|
53
|
+
# keeps `opencode2` working for callers that expect the V2 name.
|
|
54
|
+
if [ ! -x "${BIN_DIR}/opencode2" ]; then
|
|
55
|
+
ln -sf "${RESOLVED}" "${BIN_DIR}/opencode2"
|
|
56
|
+
echo "→ linked opencode2 -> ${RESOLVED}"
|
|
57
|
+
fi
|
|
58
|
+
|
|
59
|
+
echo "→ resolved ${RESOLVED}"
|
|
60
|
+
"${BIN_DIR}/opencode2" --version
|
|
61
|
+
|
|
62
|
+
# Fail loudly rather than letting the bot run on a V1 runtime, because a V1
|
|
63
|
+
# runtime rejects the configuration this bot generates.
|
|
64
|
+
VERSION_OUTPUT="$("${BIN_DIR}/opencode2" --version 2>&1 || true)"
|
|
65
|
+
if [[ "${VERSION_OUTPUT}" =~ ^opencode\ v?([0-9]+) ]]; then
|
|
66
|
+
MAJOR="${BASH_REMATCH[1]}"
|
|
67
|
+
if [ "${MAJOR}" -lt 2 ]; then
|
|
68
|
+
echo "::error::opencode2 reports v${MAJOR}; this bot requires the V2 runtime"
|
|
69
|
+
exit 1
|
|
70
|
+
fi
|
|
71
|
+
fi
|
|
72
|
+
|
|
73
|
+
echo "OPENCODE_BIN=${BIN_DIR}/opencode2" >> "${GITHUB_ENV:-/dev/null}"
|
|
74
|
+
echo "${BIN_DIR}" >> "${GITHUB_PATH:-/dev/null}"
|