Skip to content

feat: 支持 opencode agent 行内 PR 评论 #197

Description

@Svtter

背景

目前 multi-review action 的评论是 PR 级普通评论(POST /issues/{n}/comments),review 结果以纯文本形式发在 PR 上,虽然有文件路径和行号信息,但不是真正的 GitHub 行内 review comment。

opencode 官方的 review workflow(anomalyco/opencode)通过给 agent 开放 gh 权限,让模型直接调用 gh api POST /repos/{repo}/pulls/{n}/comments 在具体行号上留评论,体验好很多。

需求

1. 支持配置 OPENCODE_PERMISSION 开放 gh 权限

目前 extra-envOPENCODE_PERMISSION 被列为敏感 key,需要 extra-env-allow-sensitive: "true" 才能设置。建议:

  • 新增一个 action 输入参数 permission(或 openencode-permission),直接支持配置 agent 权限
  • 默认值为 { "bash": { "*": "deny" } }(保持当前行为)
  • 用户可以设置为 { "bash": { "*": "deny", "gh*": "allow", "gh pr review*": "deny" } } 来启用行内评论
  • 或新增一个 enable-inline-comments bool 参数,action 内部自动设置对应的 permission

2. 确保 gh CLI 在 agent 环境中可用

Action 自身的 platform.ts 已经在用 gh(postPRComment、fetchPRDiff 等),说明 runner 上有 gh。但需要确认这个 gh 在 opencode agent 进程内也可用。

如果是 self-hosted runner,gh 可能不在 PATH 上。建议在启动 agent 前做 which gh 检查,如果不可用则在日志中 warn。

3. Reviewer prompt 支持 gh 调用指令

当 permission 允许 gh 时,在 reviewer prompt 中追加行内评论的指令和 gh api 格式示例:

gh api \
  --method POST \
  -H "Accept: application/vnd.github+json" \
  /repos/{owner}/{repo}/pulls/{number}/comments \
  -f 'body=[问题说明]' \
  -f 'commit_id={sha}' \
  -f 'path=[文件路径]' \
  -F 'line=[行号]' \
  -f 'side=RIGHT'

参考

期望效果

  • PR review 评论出现在具体代码行上,而非 PR 底部的普通评论
  • 保持安全性:默认不开 gh 权限,用户显式启用
  • 禁止 gh pr review(防止自动 approve)

Metadata

Metadata

Assignees

No one assigned

    Labels

    agentOpenCode agent SDK integrationenhancementNew feature or requesttoolInternal tooling and utilitiestriagedIssue has been triaged

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions