Skip to content

Commit 8777a58

Browse files
authored
Merge pull request #7 from 33Fraise33/fix/use-opencode-app-identity
fix: Last cleanup before going live
2 parents cab3264 + 96d9b69 commit 8777a58

6 files changed

Lines changed: 22 additions & 17 deletions

File tree

.github/scripts/opencode-target.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ export async function inspectTarget(event, mode, options) {
120120
head_ref: "",
121121
head_sha: "",
122122
head_repo: "",
123-
same_repo: "true",
124123
}
125124
}
126125

@@ -136,7 +135,6 @@ export async function inspectTarget(event, mode, options) {
136135
head_ref: pull.head?.ref,
137136
head_sha: pull.head?.sha,
138137
head_repo: pull.head?.repo?.full_name,
139-
same_repo: String(sameRepo),
140138
}
141139
if (Object.values(result).some((value) => typeof value !== "string")) {
142140
throw new Error("GitHub returned incomplete pull request metadata.")

.github/scripts/opencode-target.test.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test("classifies issues, PR conversations, and PR review comments", () => {
4141
assert.deepEqual(classifyTarget({ pull_request: { number: 3 } }), { type: "pull_request", number: 3 })
4242
})
4343

44-
test("issues do not call the API", async () => {
44+
test("captures current issue metadata", async () => {
4545
const result = await inspectTarget({ issue: { number: 4 } }, "build", { ...options, fetchImpl: response() })
4646
assert.equal(result.target_type, "issue")
4747
assert.equal(result.target_number, "4")
@@ -59,7 +59,6 @@ test("captures current pull request metadata", async () => {
5959
head_ref: "feature",
6060
head_sha: "abc123",
6161
head_repo: repository,
62-
same_repo: "true",
6362
})
6463
})
6564

@@ -90,7 +89,7 @@ test("plan permits fork pull requests", async () => {
9089
...options,
9190
fetchImpl: response({ pullValue: { ...pull, head: { ...pull.head, repo: { full_name: "fork/repo" } } } }),
9291
})
93-
assert.equal(result.same_repo, "false")
92+
assert.equal(result.head_repo, "fork/repo")
9493
})
9594

9695
test("rejects oversized thread context before model access", async () => {

.github/workflows/opencode.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ jobs:
4141
head_ref: ${{ steps.target.outputs.head_ref }}
4242
head_sha: ${{ steps.target.outputs.head_sha }}
4343
head_repo: ${{ steps.target.outputs.head_repo }}
44-
same_repo: ${{ steps.target.outputs.same_repo }}
4544
steps:
4645
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
4746
with:
@@ -118,9 +117,9 @@ jobs:
118117
timeout-minutes: 45
119118
environment: opencode-build
120119
permissions:
121-
contents: write
122-
issues: write
123-
pull-requests: write
120+
contents: read
121+
issues: read
122+
pull-requests: read
124123
id-token: write
125124
steps:
126125
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

.github/workflows/workflow-lint.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,18 @@ jobs:
6060
run: |
6161
set -euo pipefail
6262
plan_job="$(awk '/^ plan:/{inside=1} /^ build:/{inside=0} inside' .github/workflows/opencode.yml)"
63+
build_job="$(awk '/^ build:/{inside=1} inside' .github/workflows/opencode.yml)"
6364
grep -q 'id-token: write' <<<"$plan_job"
64-
if grep -qE 'GITHUB_TOKEN:|USE_GITHUB_TOKEN' <<<"$plan_job"; then
65+
grep -q 'id-token: write' <<<"$build_job"
66+
grep -q 'contents: read' <<<"$build_job"
67+
grep -q 'issues: read' <<<"$build_job"
68+
grep -q 'pull-requests: read' <<<"$build_job"
69+
if grep -qE '(contents|issues|pull-requests): write' <<<"$build_job"; then
70+
exit 1
71+
fi
72+
plan_run="$(awk '/^ - name: Run read-only OpenCode plan/{inside=1} inside {print} /run: opencode github run/{if (inside) exit}' .github/workflows/opencode.yml)"
73+
build_run="$(awk '/^ - name: Run constrained OpenCode build/{inside=1} inside {print} /run: opencode github run/{if (inside) exit}' .github/workflows/opencode.yml)"
74+
if grep -qE 'GITHUB_TOKEN:|USE_GITHUB_TOKEN|github\.token' <<<"$plan_run$build_run"; then
6575
exit 1
6676
fi
6777
if grep -qE 'Configure OpenCode commit identity|github-actions\[bot\]' .github/workflows/opencode.yml; then

.opencode/agent/github-build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ permission:
2121
"vault_pass.sh": deny
2222
---
2323

24-
Implement the requested repository changes directly. Stay within the requested scope. Do not execute commands, alter agent or workflow policy, access external resources, commit, push, merge, or claim validation that was not performed. GitHub Actions will commit the resulting worktree and run repository validation for human review.
24+
Implement the requested repository changes directly. Stay within the requested scope. Do not execute commands, alter agent or workflow policy, access external resources, commit, push, merge, or claim validation that was not performed. The native OpenCode GitHub App will publish the resulting worktree and GitHub Actions will run repository validation for human review.

docs/opencode-github.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ OpenCode responds to explicit commands in GitHub issue comments, pull request co
1111
- The build agent statically denies edits. A trusted startup plugin enables edits only for ordinary repository files and retains canonical and symlink path checks. If the plugin or config hook fails, editing stays denied.
1212
- The build agent has no shell, network, subagent, external-directory, or merge access. It cannot edit `.github/`, `.opencode/`, `.git/`, `opencode.json`, `AGENTS.md`, `vault_pass.sh`, `.env`, or `.env.*` files.
1313
- Comment workflows start from the trusted default branch before OpenCode processes PR content.
14-
- Authorization caps all context sent by OpenCode at ten issue/review/review-thread comments, 100 changed files, and 60,000 characters before OAuth is exposed. GitHub attachment URLs are rejected rather than downloaded. It captures current target state, `updated_at`, PR base branch, head branch, head SHA, and head repository. After environment approval, build mode rechecks the commenter's permission and fetches the target again immediately before OpenCode, rejecting any relevant change.
14+
- Authorization bounds the repository-collected issue and pull-request context to ten issue/review/review-thread comments, 100 changed files, and 60,000 characters before OAuth is exposed. Native OpenCode may independently fetch additional GitHub context. GitHub attachment URLs are rejected rather than downloaded. Authorization captures current target state, `updated_at`, PR base branch, head branch, head SHA, and head repository. After environment approval, build mode rechecks the commenter's permission and fetches the target again immediately before OpenCode, rejecting any relevant change.
1515
- Builds may update any same-repository, non-default-branch PR head. A residual race remains: OpenCode v1.18.4 ultimately fetches and pushes by mutable branch name, so a branch can theoretically move after verification and before fetch or push. Execution is not immutable by SHA unless upstream changes this behavior; all such branches need equivalent protection where appropriate, and final human diff review remains mandatory.
1616
- OpenCode sessions are never shared. The workflow downloads OpenCode v1.18.4 and verifies its pinned SHA-256 digest.
1717
- OpenCode can create or update a branch and pull request but has no merge operation in its configured toolset. Protected branch rules provide the final merge boundary.
@@ -32,22 +32,21 @@ Do not use build mode until all settings in this section are active.
3232
Create two GitHub environments:
3333

3434
- `opencode-plan` has no required reviewer and contains only its copy of the four OAuth component secrets.
35-
- `opencode-build` has a required reviewer, prevents self-review, disables administrator bypass, and contains a separate copy of the four OAuth component secrets.
35+
- `opencode-build` has a required reviewer, disables administrator bypass, and contains a separate copy of the four OAuth component secrets.
3636

3737
The installed OpenCode GitHub App must be installed only for this repository and have no branch/ruleset bypass. Both modes use the App through OIDC so App-created changes trigger normal pull-request validation workflows. The official App's installation token has App-defined permissions that cannot be reduced by per-job GitHub Actions permissions; owner-only plans remain read-only through the pinned OpenCode binary and the `github-plan` tool policy.
3838

3939
Create a ruleset or branch protection rule for `main` with:
4040

4141
- Pull requests required before merging.
42-
- At least one human approving review and code owner review required.
42+
- Code owner review enabled. The current zero-approval policy permits the repository owner to merge their own pull requests after required checks pass.
4343
- Stale approvals dismissed when new commits are pushed.
44-
- Approval required for the latest reviewable push.
4544
- All conversations resolved before merging.
46-
- `Ansible validation / validate` and `GitHub workflow validation / actionlint` required.
45+
- `validate` and `actionlint` from GitHub Actions required.
4746
- Force pushes and branch deletion blocked.
4847
- Rule bypass disabled, including for administrators.
4948

50-
Do not enable the repository-wide "Allow GitHub Actions to create and approve pull requests" setting for OpenCode. The installed App creates pull requests instead. Required human approval, stale-review dismissal, latest-push approval, required checks, code ownership, and no bypass remain mandatory. Confirm neither workflows nor the App can satisfy required human review.
49+
Do not enable the repository-wide "Allow GitHub Actions to create and approve pull requests" setting for OpenCode. The installed App creates pull requests instead. Required checks, code-owner settings, and no bypass remain mandatory. Confirm neither workflows nor the App can satisfy required human review when approvals are required.
5150

5251
Issues must be enabled and limited to collaborators. After every environment, secret, Actions, and branch/ruleset control is verified, create the Actions repository variable `OPENCODE_BUILD_ENABLED` with value `true` as the final activation step. Build remains skipped while this variable is absent or has any other value.
5352

0 commit comments

Comments
 (0)