Skip to content

feat(github): expand built-in github package from 19 to 86 REST tools - #1147

Open
3316891527 wants to merge 5 commits into
AAswordman:devfrom
3316891527:feat/github-tools-ci-pr-workflow
Open

feat(github): expand built-in github package from 19 to 86 REST tools#1147
3316891527 wants to merge 5 commits into
AAswordman:devfrom
3316891527:feat/github-tools-ci-pr-workflow

Conversation

@3316891527

@3316891527 3316891527 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

feat(github): expand built-in github package from 19 to 86 REST tools

把内置 github 沙盒包从现有日常接口扩成更完整的 GitHub REST 工具集。包名仍是 github,不依赖 GitHub MCP。

原先可调用工具是 19 个(metadata 里还多了一个不会当工具暴露的 main)。这次扩到 86 个。

原先 19 个工具

search_repositories、get_repository、list_issues、create_issue、comment_issue、list_issue_comments、list_pull_requests、create_pull_request、get_pull_request、merge_pull_request、get_file_content、create_or_update_file、patch_file_in_repo、delete_file、create_branch、apply_local_replace、apply_local_delete、overwrite_local_file、terminal_exec

现在覆盖的能力

Issues / PR

补齐 get/update issue,以及 PR 文件、diff、commits、reviews、行内评论、提交 review、请求 reviewer。

Actions / CI

list/get/trigger/rerun/cancel workflow,获取 jobs 和 check runs。

Git / 分支 / 搜索 / fork

list_branches、list_commits、get_commit、compare_refs、get_compare_diff、search_code、search_issues、get_authenticated_user、get_rate_limit、fork_repository、sync_fork。
create_branch 可以从已有分支或 from_sha 建 ref(用于从某个 commit 恢复已删分支)。delete_branch 删除非默认分支,不会删仓库默认分支。

Releases

list/get/latest/by_tag/create/update/delete,以及 upload_release_asset、delete_release_asset。

Webhooks

list/get/create/update/delete/ping。

Collaborators / Labels / Milestones

协作者 list/check/add/remove/permission;Label CRUD;Milestone CRUD。

分支保护 / 仓库统计

get/update/delete branch protection;contributors、commit_activity、code_frequency。统计接口会处理 202(计算中)和 204(空数据)。

这次没加

  • Projects v2:走组织级 /orgs/{org}/projectsV2,看板/字段/卡片是另一套 API
  • 组织 teams/members:组织管理员能力,不是仓库日常协作
  • Git Blob/Tag:底层 git 对象,日常发版用 Releases 即可
  • 删仓库、转让仓库、改公开/私有、删仓库级密钥/部署密钥:账号/仓库管理权限,不算开发工具

产物

  • 源码:examples/github/src/
  • bundle:examples/github.jsnode build.js
  • assets 副本:app/src/main/assets/packages/github.js
  • 两份 JS 是同一份 bundle 的副本,所以 diff 会看起来偏大

手写新逻辑主要在:

  • actions.ts / git.ts / search.ts / forks.ts / users.ts / branches.ts
  • releases.ts / webhooks.ts / collaborators.ts / labels.ts / milestones.ts / protection.ts / stats.ts
  • index.ts 的双语 METADATA 和入口映射

Checklist

  • 只改了内置 github 包
  • 包名是 github
  • node build.js 已编译
  • assets 副本已同步
  • 86 个工具的 metadata / 实现 / 导出对齐
  • diff 无无关/临时/敏感内容

…ork tools

Add 30 new tools to the github sandbox script, bringing total to 49:
- Actions: list_workflows, list_workflow_runs, get_workflow_run, trigger_workflow,
  get_workflow_jobs (with log fetch), rerun_workflow_run, cancel_workflow_run,
  list_check_runs
- PR: get_issue, update_issue, update_pull_request, list_pull_request_files,
  get_pull_request_diff, list_pull_request_commits, list_pull_request_reviews,
  list_review_comments, create_review, reply_review_comment, request_reviewers
- Git: list_branches, list_commits, get_commit, compare_refs, get_compare_diff
- Search: search_code, search_issues
- Users/rate: get_authenticated_user, get_rate_limit
- Fork: fork_repository, sync_fork

Implementation notes:
- Non-GET requests always include a JSON body to satisfy OkHttp requirements
- reply_review_comment uses correct path: /pulls/{pull_number}/comments/{id}/replies
- get_workflow_jobs supports include_logs/failed_only/max_log_chars with head+tail
  truncation for large logs
- User-Agent set to Operit-GitHub
- sync_fork returns 409 when upstream has merge conflicts (GitHub business limit,
  not a tool bug); request_reviewers returns 422 when requesting the PR author;
  create_issue returns 410 on forks with Issues disabled — all expected behavior

Build: esbuild CJS bundle at examples/github.js (134.5 KB)
Assets: synced to app/src/main/assets/packages/github.js
…ms with impl

Two bugs found by verifying the freshly generated metadata against the implementations:

1. get_repository was mapped to searchRepositories instead of getRepository, so it hit /search/repositories rather than /repos/{owner}/{repo}. Now imports and uses getRepository.

2. Metadata for 5 tools declared parameter names that the implementations never read, which would make them fail host schema validation or silently receive nothing:

   - patch_file_in_repo: declared search/replace, impl takes patch (block format with [START-REPLACE]/[OLD]/[NEW])

   - apply_local_replace: declared search/replace, impl takes old/new plus environment

   - apply_local_delete: declared only path, impl requires old (snippet to delete) plus environment

   - overwrite_local_file: missing environment

   - terminal_exec: declared cwd/timeout_ms, impl takes session_name/close

Verified after rebuild: metadata JSON parses, 49 declared tools match 49 exported functions (no missing/extra), 243 params all have valid name/type/required/bilingual description.
create_branch implementation reads params.new_branch, but metadata declared branch. Passing branch produced a refs/heads/undefined ref (now deleted). Metadata now declares new_branch/from_branch, matching CreateBranchParams. Also advertise optional content_encoding on create_or_update_file.
…rotection/stats tools

Expand the built-in github package from 49 to 85 tools. High-priority REST coverage for releases, webhooks, collaborators and labels; medium-priority milestones, branch protection and repository stats. Skip Projects v2, org admin and git blob/tag APIs.
@3316891527 3316891527 changed the title feat(github): expand built-in github package with Actions/PR/search/fork tools feat(github): expand built-in github package with Actions/PR/releases/webhooks/labels tools Sep 9, 2026
@3316891527
3316891527 marked this pull request as ready for review September 9, 2026 00:07
@3316891527 3316891527 changed the title feat(github): expand built-in github package with Actions/PR/releases/webhooks/labels tools feat(github): expand built-in github package from 19 to 85 REST tools Sep 9, 2026
Add DELETE /git/refs/heads/{branch} as delete_branch, refusing the
repository default branch. Restore a deleted branch by passing from_sha
to create_branch instead of a separate restore_branch tool.
@3316891527 3316891527 changed the title feat(github): expand built-in github package from 19 to 85 REST tools feat(github): expand built-in github package from 19 to 86 REST tools Sep 9, 2026
@luojiaping

Copy link
Copy Markdown
Collaborator

这个建议直接 close,不是改改的问题。

核心问题:内置终端本来就是完整 Ubuntu(proot),git、gh 都是现成的,shell 工具的 environment: "linux" 就是暴露给模型用的。模型对 gh 的熟悉度和 git 本身一个级别,这不是需要包一层的 API。token 隔离也站不住——gh auth 的凭证留在环境里,模型照样摸不到 token,隔离等价,能力差一截。

平铺 86 个工具这条路 GitHub 自己踩过:官方 MCP server 100+ 工具上线后上下文污染,被迫加 toolsets 和 X-MCP-Tools 过滤收场。这版连过滤都没有,启用即全量注入,粗算 1.2w token 的 schema。app 自带工具已经快 200 个了,再叠 86 个,选工具的准确率只会往下掉,本地小模型基本没法用。

业界没人这么干。Claude Code 对 GitHub 的处理就一句话:全走 bash 里的 gh。Codex CLI 更干脆,只有 shell 一个工具。端点级包装没有先例,有反例。

还有个自相矛盾的地方:包里自带 terminal_exec,调的就是 Tools.System.terminal。一边转发终端,一边在旁边搭 REST 壳,说不通。

destructive 那批也要拦一下:delete_webhook、remove_collaborator、branch protection 这些,每个都是注入点,而注入源(issue 正文)就是同一个包 fetch 回来的。67 个新端点零测试,19k 行 bundle 存两份,就不展开了。

真想补 GitHub 能力,路子是 Ubuntu 环境预装 gh + 引导一次 gh auth + 短文档,十几行脚本,覆盖面比这 86 个加起来还大,上下文成本为零。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants