@zhin.js/adapter-github 3.0.3 → 4.0.0
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 +22 -0
- package/README.md +19 -4
- package/lib/workspace-manager.js +11 -2
- package/package.json +13 -13
- package/schema.json +59 -30
- package/src/workspace-manager.ts +12 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @zhin.js/adapter-github
|
|
2
2
|
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7db69c1: 命令前缀改为适配器配置项:`MessageDispatcher` 不再硬编码 `/`,默认按消息所属适配器实例 config 的 `commandPrefix` 解析(默认 `''` 无前缀,任意文本按命令匹配),`endpoints[i].commandPrefix` 逐项覆盖;`ImRuntime({ commandPrefix })` 仍可设全局静态前缀。全部 20 个平台适配器 schema 新增 `commandPrefix` 属性。
|
|
8
|
+
|
|
9
|
+
BREAKING(行为变化):未配置时命令不再需要 `/` 前缀——原 `/zt` 写法不再命中,直接发 `zt` 即可;需要斜杠风格的适配器请在配置里显式设 `commandPrefix: '/'`。
|
|
10
|
+
|
|
11
|
+
- 713445c: 适配器配置格式定稿(不兼容旧格式):`plugins.<adapter>` 顶层仅共享字段 + `commandPrefix`,`endpoints[i]` 携带 endpoint 级字段(`name` + 凭据,各 schema 已类型化),`endpoints` 为必填(icqq 另需顶层 `master`);icqq 新增 `trusted` 列表(顶层/逐项均可)。scaffold-wizard 全部字段式与自定义 configure() 产出改为新格式,examples(full-bot / qq-games-bot)与 20 个适配器 README 同步迁移。
|
|
12
|
+
- f32c424: 适配器配置统一为 endpoints 数组格式:`plugins.<adapter>` 为该 adapter 所有 endpoint 的通用配置,`plugins.<adapter>.endpoints[i]` 为单个 endpoint 的特殊配置(逐项覆盖,`name` 必填)。slack / github schema 新增 `endpoints` 属性;icqq / qq / slack 顶层必填改为 `anyOf`(单 endpoint 字段或 `endpoints` 数组二选一,兼容 Ajv strictRequired)。
|
|
13
|
+
- Updated dependencies [7db69c1]
|
|
14
|
+
- Updated dependencies [e5c84ed]
|
|
15
|
+
- Updated dependencies [3ea84a0]
|
|
16
|
+
- Updated dependencies [1ddcd70]
|
|
17
|
+
- Updated dependencies [ac9da66]
|
|
18
|
+
- @zhin.js/core@1.4.0
|
|
19
|
+
- @zhin.js/adapter@1.1.0
|
|
20
|
+
- @zhin.js/plugin-runtime@1.1.0
|
|
21
|
+
- @zhin.js/agent@1.0.5
|
|
22
|
+
- @zhin.js/host-http@1.0.2
|
|
23
|
+
- zhin.js@5.0.0
|
|
24
|
+
|
|
3
25
|
## 3.0.3
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -24,14 +24,15 @@ Webhook 需要 Root 提供 `@zhin.js/host-http`(`zhin runtime start` 默认装
|
|
|
24
24
|
# zhin.config.yml
|
|
25
25
|
plugins:
|
|
26
26
|
github:
|
|
27
|
-
name: my-github-bot
|
|
28
|
-
app_id: 123456
|
|
29
|
-
private_key: ./data/github-app.pem
|
|
30
|
-
webhook_secret: your-secret
|
|
31
27
|
webhook_path: /github/webhook
|
|
32
28
|
auto_reply_repos:
|
|
33
29
|
- zhinjs/zhin
|
|
34
30
|
workspace_root: ./data/github-workspaces
|
|
31
|
+
endpoints:
|
|
32
|
+
- name: my-github-bot
|
|
33
|
+
app_id: 123456
|
|
34
|
+
private_key: ./data/github-app.pem
|
|
35
|
+
webhook_secret: your-secret
|
|
35
36
|
```
|
|
36
37
|
|
|
37
38
|
```env
|
|
@@ -41,6 +42,20 @@ GITHUB_WEBHOOK_SECRET=your-secret
|
|
|
41
42
|
|
|
42
43
|
`private_key` 支持文件路径或 PEM 内容。未配置 `webhook_secret` 时仅 API 出站 / agent 工具可用(无入站)。
|
|
43
44
|
|
|
45
|
+
多 App:一个插件实例挂多个 endpoint(`endpoints` 数组逐项覆盖顶层字段,`name` 必填):
|
|
46
|
+
|
|
47
|
+
```yaml
|
|
48
|
+
plugins:
|
|
49
|
+
github:
|
|
50
|
+
endpoints:
|
|
51
|
+
- name: app-a
|
|
52
|
+
app_id: 123456
|
|
53
|
+
private_key: ./data/app-a.pem
|
|
54
|
+
- name: app-b
|
|
55
|
+
app_id: 234567
|
|
56
|
+
private_key: ./data/app-b.pem
|
|
57
|
+
```
|
|
58
|
+
|
|
44
59
|
## 已移除的配置
|
|
45
60
|
|
|
46
61
|
- **`ai.githubMcp.enabled` / `ai.githubMcp.token`**:Plugin Runtime 迁移后 `register-github-mcp`(stdio `@modelcontextprotocol/server-github`,PAT 人身份)已移除,该配置不再生效。如需 MCP 工具,请按新运行时 `mcp/<name>.ts`(`@zhin.js/mcp-feature`)约定自行装配。
|
package/lib/workspace-manager.js
CHANGED
|
@@ -5,7 +5,16 @@ import { spawn } from 'node:child_process';
|
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
const REPO_FULL_NAME_RE = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
8
|
-
const
|
|
8
|
+
const GIT_REF_ILLEGAL_CHARS = new Set('~^:?*[\\`;');
|
|
9
|
+
function containsIllegalGitRefCharacter(ref) {
|
|
10
|
+
return [...ref].some((character) => {
|
|
11
|
+
const code = character.charCodeAt(0);
|
|
12
|
+
return code <= 31
|
|
13
|
+
|| code === 127
|
|
14
|
+
|| /\s/u.test(character)
|
|
15
|
+
|| GIT_REF_ILLEGAL_CHARS.has(character);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
9
18
|
/**
|
|
10
19
|
* 校验 GitHub "owner/name" 全名,防止路径穿越与 git 选项注入。
|
|
11
20
|
* 返回通过校验的原值,便于调用方直接使用「已消毒」的变量。
|
|
@@ -27,7 +36,7 @@ export function assertGitRefName(ref) {
|
|
|
27
36
|
}
|
|
28
37
|
if (ref.startsWith('-') ||
|
|
29
38
|
ref.includes('..') ||
|
|
30
|
-
|
|
39
|
+
containsIllegalGitRefCharacter(ref) ||
|
|
31
40
|
ref.endsWith('/') ||
|
|
32
41
|
ref.endsWith('.')) {
|
|
33
42
|
throw new TypeError(`非法的 git ref: ${JSON.stringify(ref)}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-github",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Zhin.js GitHub adapter for Plugin Runtime (App auth + webhook)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -41,20 +41,20 @@
|
|
|
41
41
|
"directory": "plugins/adapters/github"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@zhin.js/adapter": "1.0
|
|
45
|
-
"@zhin.js/core": "1.
|
|
46
|
-
"@zhin.js/host-http": "1.0.
|
|
44
|
+
"@zhin.js/adapter": "1.1.0",
|
|
45
|
+
"@zhin.js/core": "1.4.0",
|
|
46
|
+
"@zhin.js/host-http": "1.0.2",
|
|
47
47
|
"@zhin.js/logger": "1.0.75",
|
|
48
|
-
"@zhin.js/plugin-runtime": "1.0
|
|
48
|
+
"@zhin.js/plugin-runtime": "1.1.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"zod": "^4.0.0",
|
|
52
|
-
"@zhin.js/adapter": "1.0
|
|
53
|
-
"@zhin.js/agent": "1.0.
|
|
54
|
-
"@zhin.js/core": "1.
|
|
55
|
-
"@zhin.js/host-http": "1.0.
|
|
56
|
-
"@zhin.js/plugin-runtime": "1.0
|
|
57
|
-
"zhin.js": "
|
|
52
|
+
"@zhin.js/adapter": "1.1.0",
|
|
53
|
+
"@zhin.js/agent": "1.0.5",
|
|
54
|
+
"@zhin.js/core": "1.4.0",
|
|
55
|
+
"@zhin.js/host-http": "1.0.2",
|
|
56
|
+
"@zhin.js/plugin-runtime": "1.1.0",
|
|
57
|
+
"zhin.js": "5.0.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependenciesMeta": {
|
|
60
60
|
"zhin.js": {
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"typescript": "^6.0.3",
|
|
73
73
|
"vitest": "^4.1.10",
|
|
74
74
|
"zod": "^4.4.3",
|
|
75
|
-
"@zhin.js/agent": "1.0.
|
|
76
|
-
"zhin.js": "
|
|
75
|
+
"@zhin.js/agent": "1.0.5",
|
|
76
|
+
"zhin.js": "5.0.0"
|
|
77
77
|
},
|
|
78
78
|
"files": [
|
|
79
79
|
"adapters",
|
package/schema.json
CHANGED
|
@@ -3,38 +3,10 @@
|
|
|
3
3
|
"type": "object",
|
|
4
4
|
"additionalProperties": false,
|
|
5
5
|
"properties": {
|
|
6
|
-
"name": {
|
|
7
|
-
"type": "string",
|
|
8
|
-
"default": "github-bot"
|
|
9
|
-
},
|
|
10
6
|
"host": {
|
|
11
7
|
"type": "string",
|
|
12
8
|
"description": "GitHub Enterprise hostname (default github.com)"
|
|
13
9
|
},
|
|
14
|
-
"app_id": {
|
|
15
|
-
"type": ["string", "number"],
|
|
16
|
-
"description": "GitHub App ID"
|
|
17
|
-
},
|
|
18
|
-
"appId": {
|
|
19
|
-
"type": ["string", "number"],
|
|
20
|
-
"description": "GitHub App ID (camelCase alias)"
|
|
21
|
-
},
|
|
22
|
-
"private_key": {
|
|
23
|
-
"type": "string",
|
|
24
|
-
"description": "GitHub App private key (PEM content or file path)"
|
|
25
|
-
},
|
|
26
|
-
"privateKey": {
|
|
27
|
-
"type": "string",
|
|
28
|
-
"description": "GitHub App private key (camelCase alias)"
|
|
29
|
-
},
|
|
30
|
-
"webhook_secret": {
|
|
31
|
-
"type": "string",
|
|
32
|
-
"description": "Webhook HMAC secret; enables httpHostToken POST route"
|
|
33
|
-
},
|
|
34
|
-
"webhookSecret": {
|
|
35
|
-
"type": "string",
|
|
36
|
-
"description": "Webhook HMAC secret (camelCase alias)"
|
|
37
|
-
},
|
|
38
10
|
"webhook_path": {
|
|
39
11
|
"type": "string",
|
|
40
12
|
"default": "/github/webhook"
|
|
@@ -50,7 +22,9 @@
|
|
|
50
22
|
},
|
|
51
23
|
"auto_reply_repos": {
|
|
52
24
|
"type": "array",
|
|
53
|
-
"items": {
|
|
25
|
+
"items": {
|
|
26
|
+
"type": "string"
|
|
27
|
+
},
|
|
54
28
|
"description": "Repos whose Issue/PR comments auto-trigger AI without @bot"
|
|
55
29
|
},
|
|
56
30
|
"bot_login": {
|
|
@@ -60,6 +34,61 @@
|
|
|
60
34
|
"workspace_root": {
|
|
61
35
|
"type": "string",
|
|
62
36
|
"description": "Managed git workspace root"
|
|
37
|
+
},
|
|
38
|
+
"endpoints": {
|
|
39
|
+
"type": "array",
|
|
40
|
+
"description": "多账号:一个插件实例挂多个 endpoint",
|
|
41
|
+
"items": {
|
|
42
|
+
"type": "object",
|
|
43
|
+
"additionalProperties": true,
|
|
44
|
+
"properties": {
|
|
45
|
+
"name": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"description": "GitHub App bot name"
|
|
48
|
+
},
|
|
49
|
+
"app_id": {
|
|
50
|
+
"type": [
|
|
51
|
+
"string",
|
|
52
|
+
"number"
|
|
53
|
+
],
|
|
54
|
+
"description": "GitHub App ID"
|
|
55
|
+
},
|
|
56
|
+
"appId": {
|
|
57
|
+
"type": [
|
|
58
|
+
"string",
|
|
59
|
+
"number"
|
|
60
|
+
],
|
|
61
|
+
"description": "GitHub App ID (camelCase alias)"
|
|
62
|
+
},
|
|
63
|
+
"private_key": {
|
|
64
|
+
"type": "string",
|
|
65
|
+
"description": "GitHub App private key (PEM content or file path)"
|
|
66
|
+
},
|
|
67
|
+
"privateKey": {
|
|
68
|
+
"type": "string",
|
|
69
|
+
"description": "GitHub App private key (camelCase alias)"
|
|
70
|
+
},
|
|
71
|
+
"webhook_secret": {
|
|
72
|
+
"type": "string",
|
|
73
|
+
"description": "Webhook HMAC secret; enables httpHostToken POST route"
|
|
74
|
+
},
|
|
75
|
+
"webhookSecret": {
|
|
76
|
+
"type": "string",
|
|
77
|
+
"description": "Webhook HMAC secret (camelCase alias)"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"required": [
|
|
81
|
+
"name"
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"commandPrefix": {
|
|
86
|
+
"type": "string",
|
|
87
|
+
"default": "",
|
|
88
|
+
"description": "命令前缀(默认 '' 无前缀,任意文本按命令匹配;如 '/' 要求 / 开头)。endpoints[i] 可逐项覆盖"
|
|
63
89
|
}
|
|
64
|
-
}
|
|
90
|
+
},
|
|
91
|
+
"required": [
|
|
92
|
+
"endpoints"
|
|
93
|
+
]
|
|
65
94
|
}
|
package/src/workspace-manager.ts
CHANGED
|
@@ -7,7 +7,17 @@ import path from 'node:path';
|
|
|
7
7
|
import type { GhClient, GitHubBotIdentity } from './gh-client.js';
|
|
8
8
|
|
|
9
9
|
const REPO_FULL_NAME_RE = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
10
|
-
const
|
|
10
|
+
const GIT_REF_ILLEGAL_CHARS = new Set('~^:?*[\\`;');
|
|
11
|
+
|
|
12
|
+
function containsIllegalGitRefCharacter(ref: string): boolean {
|
|
13
|
+
return [...ref].some((character) => {
|
|
14
|
+
const code = character.charCodeAt(0);
|
|
15
|
+
return code <= 31
|
|
16
|
+
|| code === 127
|
|
17
|
+
|| /\s/u.test(character)
|
|
18
|
+
|| GIT_REF_ILLEGAL_CHARS.has(character);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
11
21
|
|
|
12
22
|
/**
|
|
13
23
|
* 校验 GitHub "owner/name" 全名,防止路径穿越与 git 选项注入。
|
|
@@ -34,7 +44,7 @@ export function assertGitRefName(ref: string): string {
|
|
|
34
44
|
if (
|
|
35
45
|
ref.startsWith('-') ||
|
|
36
46
|
ref.includes('..') ||
|
|
37
|
-
|
|
47
|
+
containsIllegalGitRefCharacter(ref) ||
|
|
38
48
|
ref.endsWith('/') ||
|
|
39
49
|
ref.endsWith('.')
|
|
40
50
|
) {
|