@zhin.js/adapter-github 3.0.2 → 3.0.3
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/CHANGELOG.md +624 -0
- package/README.md +38 -201
- package/adapters/github.ts +51 -0
- package/agent/skills/github.md +2 -2
- package/agent/tools/bind.ts +2 -2
- package/agent/tools/create_pr.ts +2 -2
- package/agent/tools/install.ts +2 -2
- package/agent/tools/patch_file.ts +2 -2
- package/agent/tools/prepare_workspace.ts +2 -2
- package/agent/tools/push_branch.ts +2 -2
- package/agent/tools/star.ts +2 -2
- package/agent/tools/subscribe.ts +2 -2
- package/agent/tools/subscriptions.ts +2 -2
- package/agent/tools/unbind.ts +2 -2
- package/agent/tools/unsubscribe.ts +2 -2
- package/agent/tools/whoami.ts +2 -2
- package/lib/agent-prompt.d.ts +2 -0
- package/lib/{src/agent-prompt.js → agent-prompt.js} +0 -1
- package/lib/endpoint.d.ts +48 -0
- package/lib/endpoint.js +165 -0
- package/lib/gh-client.d.ts +300 -0
- package/lib/{src/gh-client.js → gh-client.js} +1 -2
- package/lib/github-agent-deps.d.ts +47 -0
- package/lib/github-agent-deps.js +43 -0
- package/lib/github-bot-handlers.d.ts +26 -0
- package/lib/{src/github-bot-handlers.js → github-bot-handlers.js} +0 -1
- package/lib/github-channel-context.d.ts +16 -0
- package/lib/{src/github-channel-context.js → github-channel-context.js} +0 -1
- package/lib/github-tool-handlers.d.ts +17 -0
- package/lib/{src/github-tool-handlers.js → github-tool-handlers.js} +14 -8
- package/lib/index.d.ts +9 -0
- package/lib/index.js +9 -0
- package/lib/oauth-users.d.ts +33 -0
- package/lib/oauth-users.js +38 -0
- package/lib/protocol.d.ts +87 -0
- package/lib/protocol.js +241 -0
- package/lib/types.d.ts +149 -0
- package/lib/{src/types.js → types.js} +0 -1
- package/lib/webhook.d.ts +13 -0
- package/lib/webhook.js +87 -0
- package/lib/workspace-manager.d.ts +21 -0
- package/lib/{src/workspace-manager.js → workspace-manager.js} +37 -1
- package/package.json +53 -26
- package/plugin.ts +52 -0
- package/schema.json +65 -0
- package/src/endpoint.ts +166 -175
- package/src/gh-client.ts +1 -1
- package/src/github-agent-deps.ts +66 -11
- package/src/github-tool-handlers.ts +20 -7
- package/src/index.ts +55 -137
- package/src/oauth-users.ts +47 -0
- package/src/protocol.ts +367 -0
- package/src/webhook.ts +125 -0
- package/src/workspace-manager.ts +44 -0
- package/lib/agent/tools/bind.js +0 -12
- package/lib/agent/tools/bind.js.map +0 -1
- package/lib/agent/tools/create_pr.js +0 -19
- package/lib/agent/tools/create_pr.js.map +0 -1
- package/lib/agent/tools/install.js +0 -12
- package/lib/agent/tools/install.js.map +0 -1
- package/lib/agent/tools/patch_file.js +0 -18
- package/lib/agent/tools/patch_file.js.map +0 -1
- package/lib/agent/tools/prepare_workspace.js +0 -14
- package/lib/agent/tools/prepare_workspace.js.map +0 -1
- package/lib/agent/tools/push_branch.js +0 -17
- package/lib/agent/tools/push_branch.js.map +0 -1
- package/lib/agent/tools/star.js +0 -15
- package/lib/agent/tools/star.js.map +0 -1
- package/lib/agent/tools/subscribe.js +0 -16
- package/lib/agent/tools/subscribe.js.map +0 -1
- package/lib/agent/tools/subscriptions.js +0 -13
- package/lib/agent/tools/subscriptions.js.map +0 -1
- package/lib/agent/tools/unbind.js +0 -12
- package/lib/agent/tools/unbind.js.map +0 -1
- package/lib/agent/tools/unsubscribe.js +0 -15
- package/lib/agent/tools/unsubscribe.js.map +0 -1
- package/lib/agent/tools/whoami.js +0 -12
- package/lib/agent/tools/whoami.js.map +0 -1
- package/lib/src/adapter.js +0 -423
- package/lib/src/adapter.js.map +0 -1
- package/lib/src/agent-prompt.js.map +0 -1
- package/lib/src/endpoint.js +0 -189
- package/lib/src/endpoint.js.map +0 -1
- package/lib/src/gh-client.js.map +0 -1
- package/lib/src/github-agent-deps.js +0 -13
- package/lib/src/github-agent-deps.js.map +0 -1
- package/lib/src/github-bot-handlers.js.map +0 -1
- package/lib/src/github-channel-context.js.map +0 -1
- package/lib/src/github-tool-handlers.js.map +0 -1
- package/lib/src/index.js +0 -104
- package/lib/src/index.js.map +0 -1
- package/lib/src/register-github-mcp.js +0 -41
- package/lib/src/register-github-mcp.js.map +0 -1
- package/lib/src/segment-mapper.js +0 -2
- package/lib/src/segment-mapper.js.map +0 -1
- package/lib/src/types.js.map +0 -1
- package/lib/src/workspace-manager.js.map +0 -1
- package/plugin.yml +0 -3
- package/src/adapter.ts +0 -454
- package/src/register-github-mcp.ts +0 -67
- package/src/segment-mapper.ts +0 -1
package/README.md
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
# @zhin.js/adapter-github
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
查询 · 管理 · 通知 · OAuth 用户绑定 四合一。
|
|
3
|
+
GitHub Plugin Runtime 适配器 — Issue/PR 评论区即聊天通道,GitHub App 认证,Webhook 入站经 `httpHostToken`。
|
|
6
4
|
|
|
7
5
|
## 功能特性
|
|
8
6
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
- ✅ **OAuth 用户绑定**:用户可绑定自己的 GitHub 账号,star/fork 以个人身份执行
|
|
15
|
-
- ✅ **Bot 开发工作流**:托管 git 工作区 + App 身份 push/开 PR(HITL 确认)
|
|
16
|
-
- ✅ **无 router 也能运行**:核心功能不依赖 HTTP 服务,有 router 时自动注册 Webhook 和 OAuth 路由
|
|
7
|
+
- **聊天通道**:Issue/PR 评论区映射为群聊,支持收发消息
|
|
8
|
+
- **Webhook 入站**:HMAC-SHA256 验签 → `messageGatewayToken`
|
|
9
|
+
- **出站**:`send({ target, payload })` → Issue/PR comment(target 为 channel ID)
|
|
10
|
+
- **GitHub App 认证**:JWT → Installation Token
|
|
11
|
+
- **Agent 工具**:`agent/` 下 star/bind/subscribe/workspace 等保留
|
|
17
12
|
|
|
18
13
|
## 安装
|
|
19
14
|
|
|
@@ -21,67 +16,37 @@
|
|
|
21
16
|
pnpm add @zhin.js/adapter-github
|
|
22
17
|
```
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
## GitHub App 创建
|
|
29
|
-
|
|
30
|
-
1. 访问 [GitHub Developer Settings](https://github.com/settings/apps)
|
|
31
|
-
2. 点击 **New GitHub App**
|
|
32
|
-
3. 填写基本信息:
|
|
33
|
-
- **App name**: 你的 bot 名称
|
|
34
|
-
- **Homepage URL**: 任意
|
|
35
|
-
- **Webhook URL**: `http://your-server:port/pub/github/webhook`(有 HTTP 服务时)
|
|
36
|
-
- **Webhook secret**: 自定义密钥
|
|
37
|
-
4. 权限设置(Permissions):
|
|
38
|
-
- **Repository → Issues**: Read & Write
|
|
39
|
-
- **Repository → Pull requests**: Read & Write
|
|
40
|
-
- **Repository → Contents**: Read & Write(Bot 提交代码)
|
|
41
|
-
- **Repository → Metadata**: Read
|
|
42
|
-
- **Repository → Actions**: Read(查看 CI)
|
|
43
|
-
5. 订阅事件(Subscribe to events):
|
|
44
|
-
- Issue comment、Pull request、Pull request review、Pull request review comment
|
|
45
|
-
- Push、Star、Fork(用于通知)
|
|
46
|
-
6. 创建后记录 **App ID**,点击 **Generate a private key** 下载 `.pem` 文件
|
|
47
|
-
7. 安装 App 到目标仓库/组织
|
|
48
|
-
|
|
49
|
-
## 配置
|
|
19
|
+
Webhook 需要 Root 提供 `@zhin.js/host-http`(`zhin runtime start` 默认装配)。
|
|
20
|
+
|
|
21
|
+
## 配置(Plugin Runtime)
|
|
50
22
|
|
|
51
23
|
```yaml
|
|
52
24
|
# zhin.config.yml
|
|
53
|
-
|
|
54
|
-
|
|
25
|
+
plugins:
|
|
26
|
+
github:
|
|
55
27
|
name: my-github-bot
|
|
56
28
|
app_id: 123456
|
|
57
|
-
private_key: ./data/github-app.pem
|
|
58
|
-
webhook_secret: your-secret
|
|
59
|
-
webhook_path: /
|
|
60
|
-
auto_reply_repos:
|
|
29
|
+
private_key: ./data/github-app.pem
|
|
30
|
+
webhook_secret: your-secret
|
|
31
|
+
webhook_path: /github/webhook
|
|
32
|
+
auto_reply_repos:
|
|
61
33
|
- zhinjs/zhin
|
|
62
|
-
workspace_root: ./data/github-workspaces
|
|
63
|
-
|
|
64
|
-
plugins:
|
|
65
|
-
- database
|
|
66
|
-
- "@zhin.js/adapter-github"
|
|
67
|
-
- "@zhin.js/host-router" # Webhook 需要
|
|
34
|
+
workspace_root: ./data/github-workspaces
|
|
68
35
|
```
|
|
69
36
|
|
|
70
37
|
```env
|
|
71
38
|
GITHUB_APP_ID=123456
|
|
72
39
|
GITHUB_WEBHOOK_SECRET=your-secret
|
|
73
|
-
# MCP server-github(可选;PAT = 人身份,默认关闭)
|
|
74
|
-
# ai.githubMcp.enabled: true
|
|
75
|
-
# GITHUB_PERSONAL_ACCESS_TOKEN=ghp_xxxxxxxxxxxx
|
|
76
40
|
```
|
|
77
41
|
|
|
78
|
-
`private_key`
|
|
79
|
-
|
|
80
|
-
|
|
42
|
+
`private_key` 支持文件路径或 PEM 内容。未配置 `webhook_secret` 时仅 API 出站 / agent 工具可用(无入站)。
|
|
43
|
+
|
|
44
|
+
## 已移除的配置
|
|
81
45
|
|
|
82
|
-
|
|
46
|
+
- **`ai.githubMcp.enabled` / `ai.githubMcp.token`**:Plugin Runtime 迁移后 `register-github-mcp`(stdio `@modelcontextprotocol/server-github`,PAT 人身份)已移除,该配置不再生效。如需 MCP 工具,请按新运行时 `mcp/<name>.ts`(`@zhin.js/mcp-feature`)约定自行装配。
|
|
47
|
+
- **`poll_interval`**:轮询降级已删除,仅 webhook 入站;该字段目前解析但不生效(deferred)。
|
|
83
48
|
|
|
84
|
-
|
|
49
|
+
## Channel ID
|
|
85
50
|
|
|
86
51
|
| 类型 | Channel ID | 示例 |
|
|
87
52
|
|------|-----------|------|
|
|
@@ -90,151 +55,23 @@ GitHub adapter 将 Issue/PR 映射为聊天频道:
|
|
|
90
55
|
|
|
91
56
|
## AI 工具
|
|
92
57
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
| 工具 | 说明 |
|
|
96
|
-
|------|------|
|
|
97
|
-
| `github_star` | Star / Unstar / 检查(per-user OAuth 或 Endpoint 默认) |
|
|
98
|
-
| `github_bind` / `github_unbind` / `github_whoami` | 用户 GitHub 账号绑定 |
|
|
99
|
-
| `github_install` | GitHub App 安装链接 |
|
|
100
|
-
| `github_subscribe` / `github_unsubscribe` / `github_subscriptions` | 频道级 Webhook 订阅 |
|
|
101
|
-
| `github_prepare_workspace` | Clone/fetch 托管工作区并 checkout 分支 |
|
|
102
|
-
| `github_patch_file` | Contents API 单文件更新(Bot 身份) |
|
|
103
|
-
| `github_push_branch` | git commit + push(**需 HITL**) |
|
|
104
|
-
| `github_create_pr` | 创建 PR(**需 HITL**) |
|
|
105
|
-
|
|
106
|
-
### Bot 工作流(App 身份)
|
|
107
|
-
|
|
108
|
-
- 评论回复:Webhook → `$reply`,Installation Token,UI 显示 `{slug}[bot]` + **Bot** 徽章
|
|
109
|
-
- 开发提交:`github_prepare_workspace` → bash 改代码 → `github_push_branch`(确认)→ Issue 场景 `github_create_pr`
|
|
110
|
-
- PR 线程:push 到现有 PR head 分支,不新开 PR
|
|
111
|
-
- 工作区默认:`data/github-workspaces/{owner}/{repo}`
|
|
112
|
-
|
|
113
|
-
### MCP(`@modelcontextprotocol/server-github`,可选)
|
|
114
|
-
|
|
115
|
-
仅当 `ai.githubMcp.enabled: true` 且配置 PAT 时注册。`mcp_github_*` 以**用户 PAT** 操作,**不能**作为 Bot 写仓库。Bot 写操作请用上方 `github_*` 工具。
|
|
116
|
-
|
|
117
|
-
### 使用示例
|
|
118
|
-
|
|
119
|
-
```
|
|
120
|
-
AI: 列出 zhinjs/zhin 的 PR
|
|
121
|
-
AI: 合并 zhinjs/zhin 的 PR #108
|
|
122
|
-
AI: 查看 zhinjs/zhin 的 star 数
|
|
123
|
-
AI: 订阅 zhinjs/zhin 的 push 和 pr 事件
|
|
124
|
-
AI: 搜索 zhinjs 相关的仓库
|
|
125
|
-
AI: 给 zhinjs/zhin 的 issue #42 加上 bug 标签
|
|
126
|
-
AI: 查看 zhinjs/zhin 的 README.md 文件
|
|
127
|
-
AI: 对比 zhinjs/zhin 的 main 和 dev 分支
|
|
128
|
-
AI: 编辑 zhinjs/zhin 的 issue #42 标题
|
|
129
|
-
AI: 绑定我的 GitHub 账号
|
|
130
|
-
AI: star zhinjs/zhin
|
|
131
|
-
AI: fork zhinjs/zhin # 使用 mcp_github_fork_repository
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
## Webhook 事件通知
|
|
135
|
-
|
|
136
|
-
配置好 Webhook 后,支持以下事件的跨平台推送:
|
|
137
|
-
|
|
138
|
-
| 事件 | 参数 | 说明 |
|
|
139
|
-
|------|------|------|
|
|
140
|
-
| Push | `push` | 代码推送 |
|
|
141
|
-
| Issue | `issue` | Issue 创建/更新/关闭 |
|
|
142
|
-
| Star | `star` | 仓库被 star |
|
|
143
|
-
| Unstar | `unstar` | 仓库被 unstar |
|
|
144
|
-
| Fork | `fork` | 仓库被 fork |
|
|
145
|
-
| Pull Request | `pr` / `pull_request` | PR 创建/更新/合并 |
|
|
146
|
-
|
|
147
|
-
### Webhook 端点
|
|
148
|
-
|
|
149
|
-
```
|
|
150
|
-
POST /pub/github/webhook
|
|
151
|
-
```
|
|
58
|
+
见 `agent/tools/`:`github_star`、`github_bind`、`github_subscribe`、`github_prepare_workspace` 等。
|
|
152
59
|
|
|
153
|
-
|
|
154
|
-
- `X-GitHub-Event`: 事件类型
|
|
155
|
-
- `X-Hub-Signature-256`: 签名(配置了 secret 时)
|
|
60
|
+
## 架构
|
|
156
61
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
|
164
|
-
|
|
165
|
-
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
### 绑定流程
|
|
172
|
-
|
|
173
|
-
1. 用户在聊天中触发 `github_bind`(或说「绑定 GitHub」)
|
|
174
|
-
2. Endpoint 返回 **verification URI** 与 **user code**(GitHub Device Flow)
|
|
175
|
-
3. 用户在浏览器打开链接并输入 code 完成授权
|
|
176
|
-
4. Token 写入 `github_oauth_users` 表;可用 `github_whoami` / `github_unbind` 管理
|
|
177
|
-
|
|
178
|
-
**Client ID**:从 GitHub App 的 `/app` API 自动获取(`GhClient.getClientId()`),**无需**在 Endpoint 配置里写 `client_id` / `client_secret`。
|
|
179
|
-
|
|
180
|
-
### 前置条件
|
|
181
|
-
|
|
182
|
-
- 需要 **`database`** 插件(`github_oauth_users` 模型)
|
|
183
|
-
- Device Flow 在 IM 内完成,**不依赖** `/pub/github/oauth` HTTP 路由
|
|
184
|
-
|
|
185
|
-
## 数据库表
|
|
186
|
-
|
|
187
|
-
### github_subscriptions
|
|
188
|
-
|
|
189
|
-
| 字段 | 类型 | 说明 |
|
|
190
|
-
|------|------|------|
|
|
191
|
-
| id | integer | 主键 |
|
|
192
|
-
| repo | text | 仓库名 (owner/repo) |
|
|
193
|
-
| events | json | 订阅的事件列表 |
|
|
194
|
-
| target_id | text | 目标频道 ID |
|
|
195
|
-
| target_type | text | 类型 (private/group/channel) |
|
|
196
|
-
| adapter | text | 适配器名称 |
|
|
197
|
-
| endpoint | text | 机器人名称 |
|
|
198
|
-
|
|
199
|
-
### github_events
|
|
200
|
-
|
|
201
|
-
| 字段 | 类型 | 说明 |
|
|
202
|
-
|------|------|------|
|
|
203
|
-
| id | integer | 主键 |
|
|
204
|
-
| repo | text | 仓库名 |
|
|
205
|
-
| event_type | text | 事件类型 |
|
|
206
|
-
| payload | json | 事件载荷 |
|
|
207
|
-
|
|
208
|
-
### github_oauth_users
|
|
209
|
-
|
|
210
|
-
| 字段 | 类型 | 说明 |
|
|
211
|
-
|------|------|------|
|
|
212
|
-
| id | integer | 主键 |
|
|
213
|
-
| platform | text | 聊天平台 |
|
|
214
|
-
| platform_uid | text | 平台用户 ID |
|
|
215
|
-
| github_login | text | GitHub 用户名 |
|
|
216
|
-
| access_token | text | Device Flow 获得的 token |
|
|
217
|
-
| created_at | integer | 创建时间戳 |
|
|
218
|
-
|
|
219
|
-
## 架构说明
|
|
220
|
-
|
|
221
|
-
```
|
|
222
|
-
adapter-github/
|
|
223
|
-
├── src/
|
|
224
|
-
│ ├── index.ts # 插件入口:provide、useContext、模型表
|
|
225
|
-
│ ├── adapter.ts # GitHubAdapter
|
|
226
|
-
│ ├── endpoint.ts # GitHubEndpoint(Issue/PR 频道)
|
|
227
|
-
│ ├── gh-client.ts # GitHub REST(App JWT / Installation Token)
|
|
228
|
-
│ ├── register-github-mcp.ts # orchestrator.addMcp(server-github)
|
|
229
|
-
│ ├── agent-prompt.ts # 平台 prompt / deferred 工具筛选
|
|
230
|
-
│ └── types.ts # EndpointConfig、Webhook payload、Channel ID
|
|
231
|
-
├── package.json
|
|
232
|
-
└── README.md
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
- **无 `@zhin.js/host-router` 时**:REST 工具与轮询仍可用,但无法注册 Webhook
|
|
236
|
-
- **有 `@zhin.js/host-router` 时**:注册 Webhook;MCP 通过 `orchestrator.addMcp`(需 PAT 或 `ai.githubMcp.token`)
|
|
237
|
-
|
|
238
|
-
## 许可证
|
|
62
|
+
| 路径 | 职责 |
|
|
63
|
+
|------|------|
|
|
64
|
+
| `plugin.ts` | 插件元数据;有 DatabaseHost 时定义 `github_oauth_users` |
|
|
65
|
+
| `adapters/github.ts` | 薄 `defineAdapter` 入口(发现约定) |
|
|
66
|
+
| `src/endpoint.ts` | Endpoint 生命周期、出站、admit |
|
|
67
|
+
| `src/webhook.ts` | HMAC 验签与事件分发 |
|
|
68
|
+
| `src/oauth-users.ts` | OAuth 表 SSOT + token 查找 |
|
|
69
|
+
| `src/protocol.ts` | 协议纯函数(channel / payload) |
|
|
70
|
+
| `src/gh-client.ts` | GitHub API 客户端 |
|
|
71
|
+
|
|
72
|
+
- 入站:`httpHostToken` POST → `messageGatewayToken.receive`
|
|
73
|
+
- 出站:`send({ target, payload })`
|
|
74
|
+
|
|
75
|
+
## License
|
|
239
76
|
|
|
240
77
|
MIT
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convention entry: discover `adapters/github.ts` → defineAdapter.
|
|
3
|
+
* Implementation lives under `src/` (endpoint / webhook / oauth / protocol).
|
|
4
|
+
*/
|
|
5
|
+
import { defineAdapter, type AdapterContext } from '@zhin.js/adapter';
|
|
6
|
+
import { messageGatewayToken } from '@zhin.js/core/runtime';
|
|
7
|
+
import { httpHostToken } from '@zhin.js/host-http';
|
|
8
|
+
import {
|
|
9
|
+
databaseHostToken,
|
|
10
|
+
type DatabaseHost,
|
|
11
|
+
} from '@zhin.js/plugin-runtime';
|
|
12
|
+
import { GithubEndpoint } from '../src/endpoint.js';
|
|
13
|
+
import {
|
|
14
|
+
resolveGithubConfig,
|
|
15
|
+
type GithubAdapterConfig,
|
|
16
|
+
} from '../src/protocol.js';
|
|
17
|
+
|
|
18
|
+
export { GithubEndpoint } from '../src/endpoint.js';
|
|
19
|
+
export type { GithubEndpointOptions } from '../src/endpoint.js';
|
|
20
|
+
|
|
21
|
+
function optionalDatabase(context: AdapterContext): DatabaseHost | undefined {
|
|
22
|
+
try {
|
|
23
|
+
return context.use(databaseHostToken);
|
|
24
|
+
} catch {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default defineAdapter<GithubAdapterConfig>({
|
|
30
|
+
capabilities: ['inbound', 'outbound'],
|
|
31
|
+
create(context) {
|
|
32
|
+
const config = resolveGithubConfig(context.config);
|
|
33
|
+
const database = optionalDatabase(context);
|
|
34
|
+
if (config.webhookSecret) {
|
|
35
|
+
return new GithubEndpoint({
|
|
36
|
+
id: context.id,
|
|
37
|
+
gateway: context.use(messageGatewayToken),
|
|
38
|
+
http: context.use(httpHostToken),
|
|
39
|
+
database,
|
|
40
|
+
config,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// API-only: Issue/PR send + agent tools without webhook.
|
|
44
|
+
return new GithubEndpoint({
|
|
45
|
+
id: context.id,
|
|
46
|
+
gateway: context.use(messageGatewayToken),
|
|
47
|
+
database,
|
|
48
|
+
config,
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
});
|
package/agent/skills/github.md
CHANGED
|
@@ -77,7 +77,7 @@ requires:
|
|
|
77
77
|
本技能提供三种操作方式:
|
|
78
78
|
- **适配器内置工具**(`github_*`):用户交互类操作,具备账号绑定、Device Flow 授权、频道级订阅等适配器专有逻辑
|
|
79
79
|
- **Bot 写仓库工具**(`github_prepare_workspace` / `github_patch_file` / `github_push_branch` / `github_create_pr`):Installation Token,UI 显示 **Bot** 身份;push/开 PR 需 HITL
|
|
80
|
-
- **MCP server-github**(`mcp_github_
|
|
80
|
+
- **MCP server-github**(`mcp_github_*`,可选):`ai.githubMcp.*` 配置已随 Plugin Runtime 迁移移除;如需 MCP 工具,按 `mcp/<name>.ts` 约定自行装配(PAT 为**人身份**,勿用于 Bot 写仓库)
|
|
81
81
|
- **bash + gh CLI**:仓库自动化操作,灵活覆盖 GitHub API 全场景
|
|
82
82
|
|
|
83
83
|
## 一、适配器内置工具
|
|
@@ -129,7 +129,7 @@ Issue 线程:新分支 → 开发 → push → 开 PR。PR 线程:push 到
|
|
|
129
129
|
|
|
130
130
|
1. `github_star` 优先使用用户绑定的 GitHub 账号,未绑定则降级为 Endpoint 默认账号
|
|
131
131
|
2. Bot 写仓库用 `github_*` 工具,不用 `mcp_github_*` 写操作
|
|
132
|
-
3. MCP
|
|
132
|
+
3. MCP(`mcp_github_*`)仅在你按 `mcp/<name>.ts` 约定装配后可用(旧 `ai.githubMcp.enabled` 已移除),PAT 为人身份
|
|
133
133
|
4. 当用户想操作自己的 GitHub 账号进行 Star 时,先引导用户使用 `github_bind` 绑定
|
|
134
134
|
5. Webhook 订阅关联到当前聊天通道,仅在该通道接收事件通知
|
|
135
135
|
|
package/agent/tools/bind.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { executeGithubBind } from '../../src/github-tool-handlers.js';
|
|
4
4
|
|
|
5
|
-
export default
|
|
5
|
+
export default defineAgentTool({
|
|
6
6
|
description: '绑定你的 GitHub 账号 — 使用 Device Flow 授权,无需输入密码',
|
|
7
7
|
inputSchema: z.object({}),
|
|
8
8
|
tags: ['github'],
|
package/agent/tools/create_pr.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { executeGithubCreatePr } from '../../src/github-bot-handlers.js';
|
|
4
4
|
|
|
5
|
-
export default
|
|
5
|
+
export default defineAgentTool<{ repo?: string; title: string; body?: string; head?: string; base?: string }>({
|
|
6
6
|
description: '以 GitHub App Bot 身份创建 Pull Request(需 HITL 确认;Issue 场景常用)',
|
|
7
7
|
inputSchema: z.object({
|
|
8
8
|
repo: z.string().optional().describe('owner/repo'),
|
package/agent/tools/install.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { executeGithubInstall } from '../../src/github-tool-handlers.js';
|
|
4
4
|
|
|
5
|
-
export default
|
|
5
|
+
export default defineAgentTool({
|
|
6
6
|
description: '获取安装 GitHub App 的链接 — 安装后 Endpoint 可以访问你的仓库,你也可以使用更多功能',
|
|
7
7
|
inputSchema: z.object({}),
|
|
8
8
|
tags: ['github'],
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { executeGithubPatchFile } from '../../src/github-bot-handlers.js';
|
|
4
4
|
|
|
5
|
-
export default
|
|
5
|
+
export default defineAgentTool<{ repo?: string; path: string; content: string; message: string; branch?: string }>({
|
|
6
6
|
description: '通过 Contents API 单文件更新(小改;Bot Installation Token 身份)',
|
|
7
7
|
inputSchema: z.object({
|
|
8
8
|
repo: z.string().optional().describe('owner/repo'),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { executeGithubPrepareWorkspace } from '../../src/github-bot-handlers.js';
|
|
4
4
|
|
|
5
|
-
export default
|
|
5
|
+
export default defineAgentTool<{ repo?: string }>({
|
|
6
6
|
description: 'Clone/fetch 托管工作区并 checkout 到 Issue/PR 对应分支(GitHub App Bot 身份)',
|
|
7
7
|
inputSchema: z.object({
|
|
8
8
|
repo: z.string().optional().describe('owner/repo,缺省从当前 Issue/PR 频道推断'),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { executeGithubPushBranch } from '../../src/github-bot-handlers.js';
|
|
4
4
|
|
|
5
|
-
export default
|
|
5
|
+
export default defineAgentTool<{ repo?: string; branch?: string; message: string }>({
|
|
6
6
|
description: '在托管工作区 git commit 并 push 到远程分支(需 HITL 确认;Bot 身份)',
|
|
7
7
|
inputSchema: z.object({
|
|
8
8
|
repo: z.string().optional().describe('owner/repo'),
|
package/agent/tools/star.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { executeGithubStar } from '../../src/github-tool-handlers.js';
|
|
4
4
|
|
|
5
|
-
export default
|
|
5
|
+
export default defineAgentTool<{ action: 'star' | 'unstar' | 'check'; repo: string }>({
|
|
6
6
|
description: 'Star 或取消 Star 一个 GitHub 仓库(使用你绑定的 GitHub 账号,未绑定则用 Endpoint 默认账号)',
|
|
7
7
|
inputSchema: z.object({
|
|
8
8
|
action: z.enum(['star', 'unstar', 'check']),
|
package/agent/tools/subscribe.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { executeGithubSubscribe } from '../../src/github-tool-handlers.js';
|
|
4
4
|
|
|
5
|
-
export default
|
|
5
|
+
export default defineAgentTool<{ repo: string; events?: string }>({
|
|
6
6
|
description: '订阅 GitHub 仓库的 Webhook 事件,事件将推送到当前聊天通道',
|
|
7
7
|
inputSchema: z.object({
|
|
8
8
|
repo: z.string().min(1),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { executeGithubSubscriptions } from '../../src/github-tool-handlers.js';
|
|
4
4
|
|
|
5
|
-
export default
|
|
5
|
+
export default defineAgentTool({
|
|
6
6
|
description: '查看当前聊天通道的 GitHub 仓库订阅列表',
|
|
7
7
|
inputSchema: z.object({}),
|
|
8
8
|
platforms: ['github'],
|
package/agent/tools/unbind.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { executeGithubUnbind } from '../../src/github-tool-handlers.js';
|
|
4
4
|
|
|
5
|
-
export default
|
|
5
|
+
export default defineAgentTool({
|
|
6
6
|
description: '解除你绑定的 GitHub 账号',
|
|
7
7
|
inputSchema: z.object({}),
|
|
8
8
|
tags: ['github'],
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { executeGithubUnsubscribe } from '../../src/github-tool-handlers.js';
|
|
4
4
|
|
|
5
|
-
export default
|
|
5
|
+
export default defineAgentTool<{ repo: string }>({
|
|
6
6
|
description: '取消订阅 GitHub 仓库的 Webhook 事件',
|
|
7
7
|
inputSchema: z.object({
|
|
8
8
|
repo: z.string().min(1),
|
package/agent/tools/whoami.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { executeGithubWhoami } from '../../src/github-tool-handlers.js';
|
|
4
4
|
|
|
5
|
-
export default
|
|
5
|
+
export default defineAgentTool({
|
|
6
6
|
description: '查看你绑定的 GitHub 账号信息',
|
|
7
7
|
inputSchema: z.object({}),
|
|
8
8
|
tags: ['github'],
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { EndpointInstance } from '@zhin.js/adapter';
|
|
2
|
+
import type { MessageGateway } from '@zhin.js/core/runtime';
|
|
3
|
+
import type { HttpHost } from '@zhin.js/host-http';
|
|
4
|
+
import type { CapabilityId, DatabaseHost } from '@zhin.js/plugin-runtime';
|
|
5
|
+
import { GhClient } from './gh-client.js';
|
|
6
|
+
import { type GithubInboundComment, type ResolvedGithubConfig } from './protocol.js';
|
|
7
|
+
import { WorkspaceManager } from './workspace-manager.js';
|
|
8
|
+
export interface GithubEndpointOptions {
|
|
9
|
+
readonly id: CapabilityId;
|
|
10
|
+
readonly gateway: MessageGateway;
|
|
11
|
+
readonly http?: HttpHost;
|
|
12
|
+
readonly database?: DatabaseHost;
|
|
13
|
+
readonly config: ResolvedGithubConfig;
|
|
14
|
+
readonly createClient?: (config: ResolvedGithubConfig) => GhClient;
|
|
15
|
+
}
|
|
16
|
+
export declare class GithubEndpoint implements EndpointInstance {
|
|
17
|
+
#private;
|
|
18
|
+
readonly gh: GhClient;
|
|
19
|
+
readonly config: ResolvedGithubConfig;
|
|
20
|
+
readonly name: string;
|
|
21
|
+
constructor(options: GithubEndpointOptions);
|
|
22
|
+
getAPI(): GhClient;
|
|
23
|
+
getUserOrDefaultAPI(platform?: string, platformUid?: string): Promise<GhClient | null>;
|
|
24
|
+
getClientId(): string | null;
|
|
25
|
+
getHost(): string | undefined;
|
|
26
|
+
getAppSlug(): string | null;
|
|
27
|
+
getInstallations(): {
|
|
28
|
+
id: number;
|
|
29
|
+
account: {
|
|
30
|
+
login: string;
|
|
31
|
+
type: string;
|
|
32
|
+
};
|
|
33
|
+
target_type: string;
|
|
34
|
+
}[];
|
|
35
|
+
getWorkspaceManager(): WorkspaceManager;
|
|
36
|
+
getDatabase(): DatabaseHost | undefined;
|
|
37
|
+
start(): Promise<void>;
|
|
38
|
+
open(): void;
|
|
39
|
+
close(): void;
|
|
40
|
+
stop(): Promise<void>;
|
|
41
|
+
send({ target, payload }: {
|
|
42
|
+
readonly target: string;
|
|
43
|
+
readonly payload: unknown;
|
|
44
|
+
}): Promise<string>;
|
|
45
|
+
/** Test / internal: admit a parsed comment when open. */
|
|
46
|
+
admit(comment: GithubInboundComment): void;
|
|
47
|
+
}
|
|
48
|
+
export declare function defaultCreateClient(config: ResolvedGithubConfig): GhClient;
|