Repository navigation
fix(core): Fix Github Bot so it is supported in v2 - #58297
zzz-creator wants to merge 41 commits into
Conversation
…ll; add PR description
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
There was a problem hiding this comment.
I'd hold this one: it isn't ready to merge. opencode github install works: run from source in a scratch repo, it wrote .github/workflows/opencode.yml. bun run typecheck:tsc passes in packages/cli. I couldn't run github run end to end because the standalone server doesn't start in this sandbox (plain opencode run --standalone fails the same way), so I checked it by reading the code.
Public API: it adds the opencode github install and opencode github run commands, with --event, --token and --standalone on run. That's backwards compatible. It also changes the run step in github/action.yml, which every existing workflow using anomalyco/opencode/github depends on (see the inline comment).
Main problems (details inline):
- The action stops calling the CLI and runs
bun run index.tsinstead, so the new command is never used and the action would break. github runnever reads the/occomment, issue or PR. It runsPROMPTor a hard-coded "Summarize this repository", and posts only "opencode run completed." instead of the model's answer.- There's no OIDC/app-token exchange, so with the generated workflow there's no token for the permission check or for pushing changes.
- The fork PR branch name goes unescaped into a shell command, which is a command-injection risk.
- The fork and same-repo PR flows are wrong.
- Please remove the stray
PULL_REQUEST.mdand the unused@actions/coredependency, and revert the re-sorting ofpackages/cli/package.json. - The description says
installlists models from models.dev, but it's a free-text prompt.
The docs are currently dropping opencode github because v2 doesn't have it (#58209 and its English counterpart #58016), so it's worth confirming with maintainers that v2 should have this command. Some proof of a real end-to-end /oc run (an issue comment that gets answered) would also help.
There was a problem hiding this comment.
The new commits only merge dev; none of this PR's own files changed. So the earlier points about the action step, the ignored comment prompt, the token exchange, and the fork PR flow and shell injection are still open, along with the stray PULL_REQUEST.md and the unused dependencies. The description now says it closes #57911. opencode github install does exist now, but the action still runs bun run index.ts instead of opencode github run, so the GitHub bot that issue is about would still not work.
Public API impact is unchanged since the last review: it adds the opencode github install and opencode github run commands (--event, --token, --standalone), which is backwards compatible, and it changes the GitHub Action's run step.
… into v2-github-fix
There was a problem hiding this comment.
The latest commit fixes the earlier points:
- For comments on a PR, the PR is now fetched with
pulls.get, so the right branch is checked out and pushed. - Git credentials and a commit identity are set up before committing.
- The
forkremote is reused instead of being added twice. - The
process.stdout.writepatch is gone.
I checked this by reading the commit; bun run typecheck:tsc passes in packages/cli. github run still can't be run end to end here.
New (inline):
- Removing the stdout capture means the run's answer is no longer posted; the reply is back to "opencode run completed.".
- The git identity is now written globally and unconditionally.
- Also, the access token written to
.git/configis never removed after the run, which matters on self-hosted runners.
Public API: unchanged since the last review. It adds opencode github install and opencode github run (--event, --token, --standalone), which is backwards compatible.
|
@anomalyco Fix done. |
There was a problem hiding this comment.
The latest commits fix the earlier points: the reply is now read from the session's messages, and the git identity is set only when missing, with --local. I checked this by reading the commits; bun run typecheck:tsc passes in packages/cli. github run still can't be run end to end here.
New problems (inline):
@actions/coreand@actions/githubwere switched tocatalog:, but the root catalog only has@octokit/rest. I suggestedcatalog:earlier, but that only fits@octokit/rest;github/package.jsonpins the two@actions/*packages, so they should stay pinned.- The step that removes the token after the push restores the token itself, so it stays in
.git/config. - The answer lookup picks the oldest assistant message, not the last one.
Public API: unchanged since the last review. It adds opencode github install and opencode github run (--event, --token, --standalone), which is backwards compatible.
|
@adamdotdevin, Please approve the workflows |
… revert catalog deps
|
Fixing a few issues. |
|
Fix done. |
There was a problem hiding this comment.
The latest commits fix the earlier points:
- The original
extraheaderis now saved before the token is written, so it's restored correctly. @actions/coreand@actions/githubare pinned again, matchingbun.lock.- The answer is now the newest assistant message.
The other new changes look fine: reactions on review comments, splitting a #variant off MODEL, the default-branch fallback for a detached HEAD, and catching git failures. I checked this by reading the commits; bun run typecheck:tsc passes in packages/cli. github run still can't be run end to end here.
New problems:
- The fork remote can now be created with the token in its URL (inline).
- The root
package.jsonloses its trailing newline, which is unrelated and worth reverting.
Public API: unchanged since the last review. It adds opencode github install and opencode github run (--event, --token, --standalone), which is backwards compatible; MODEL now also accepts a provider/model#variant form.
|
Running github run end to end now on https://github.com/zzz-creator/audio-troubleshooting-lab |
|
Result: The opencode github run command now runs end-to-end locally (it reaches model execution; the remaining failure is OpenCode's free-tier restriction on opencode/big-pickle when invoked via CLI, which is a provider policy, not a code issue). |
There was a problem hiding this comment.
Both points from the last review are fixed: the fork remote is now added without the token in its URL, and the root package.json has its trailing newline back. The new local-run fallback (building the event context from origin and skipping OIDC outside Actions) looks reasonable. I checked this by reading the commits; bun run typecheck:tsc passes in packages/cli. github run still can't be run end to end here.
One small gap (inline): the local fallback crashes with an unhandled git error when the folder has no origin remote.
Public API: unchanged since the last review. It adds opencode github install and opencode github run (--event, --token, --standalone), which is backwards compatible.
There was a problem hiding this comment.
The latest commit fixes the last point: a local github run without an origin remote now falls back to an empty context instead of crashing with a git error. Nothing new to raise. I checked this by reading the commit. github run still can't be run end to end in this sandbox, so a real /oc run on an issue and on a PR would be good evidence before merging.
Public API: unchanged since the last review. It adds opencode github install and opencode github run (--event, --token, --standalone), which is backwards compatible.
There was a problem hiding this comment.
This push only merges dev; none of this PR's files changed, so there's nothing new to raise. github run still can't be run end to end in this sandbox, so a real /oc run on an issue and on a PR would be good evidence before merging.
Public API: unchanged since the last review. It adds opencode github install and opencode github run (--event, --token, --standalone), which is backwards compatible.
|
New issue: need to fix reactions |
There was a problem hiding this comment.
This push only merges dev; the PR's own code is unchanged, so there's nothing new to raise. github run still can't be run end to end in this sandbox, so a real /oc run on an issue and on a PR would be good evidence before merging.
Public API: unchanged since the last review. It adds opencode github install and opencode github run (--event, --token, --standalone), which is backwards compatible.
There was a problem hiding this comment.
This push only merges dev; none of this PR's files changed, so there's nothing new to raise. github run still can't be run end to end in this sandbox, so a real /oc run on an issue and on a PR would be good evidence before merging.
Public API: unchanged since the last review. It adds opencode github install and opencode github run (--event, --token, --standalone), which is backwards compatible.
There was a problem hiding this comment.
This push only merges dev; none of this PR's files changed, so there's nothing new to raise. github run still can't be run end to end in this sandbox, so a real /oc run on an issue and on a PR would be good evidence before merging.
Public API: unchanged since the last review. It adds opencode github install and opencode github run (--event, --token, --standalone), which is backwards compatible.
There was a problem hiding this comment.
This push only merges dev; none of the PR's own lines changed. After the merge, bun run typecheck:tsc passes in packages/cli, and opencode github run --help still works from source.
One thing from the merge: #58505 moved --server and --standalone to shared global flags (globalFlags: ServerFlags), and handlers now call ServerConnection.resolve() with no arguments. github run still declares its own standalone flag and passes { standalone: input.standalone }. That still works, but github run doesn't accept --server, and because it always passes false, a global --standalone setting would be ignored. Using globalFlags: ServerFlags on the run spec and a plain ServerConnection.resolve() would match the rest of the CLI.
github run still can't be run end to end in this sandbox, so a real /oc run on an issue and on a PR would be good evidence before merging.
Public API: unchanged since the last review. It adds opencode github install and opencode github run (--event, --token, --standalone), which is backwards compatible.
Issue for this PR
Closes #57911, possibly #58129
Type of change
What does this PR do?
Ports the GitHub integration (
opencode github installandopencode github run) from v1 to v2.opencode githubCLI command withinstallandrunsubcommands.github installinteractively prompts for a model (any provider from models.dev) and generates.github/workflows/opencode.yml, including the appropriate provider API key secret (supportsOPENCODE_API_KEY).github runresolves a standalone/shared server, runs a prompt via the v2 non-interactive runner, performs permission checks and reactions, supports mock events (--event/--token), handles fork PRs, schedule/workflow_dispatch routing, and opens a PR when the working tree changes.@octokit/resttopackages/cli.How did you verify your code works?
bun run typecheck:tscpasses inpackages/cli.opencode github installandopencode github run --standaloneexecute successfully (model execution blocked by free-tier guard in this environment).Screenshots / recordings
N/A
Checklist
Added by the opencode bot (AI-generated).
Related: #58129
Public API: adds the
opencode github installandopencode github runCLI commands (--event,--token,--standalone);github runreads the action'sMODEL(with optional#variant),USE_GITHUB_TOKENandOIDC_BASE_URLenv vars (backwards compatible)