@zhin.js/adapter-github 1.1.0 → 1.1.2
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 +94 -0
- package/README.md +16 -17
- package/adapters/{github.js → github/index.js} +6 -6
- package/adapters/{github.ts → github/index.ts} +9 -9
- package/agents/github/agent.json +20 -0
- package/agents/github/boundaries.md +3 -0
- package/agents/github/conventions.md +3 -0
- package/agents/github/skills/github-account/SKILL.md +20 -0
- package/{lib/github-tool-handlers.js → agents/github/skills/github-account/handlers.js} +2 -100
- package/{src/github-tool-handlers.ts → agents/github/skills/github-account/handlers.ts} +2 -118
- package/agents/github/skills/github-account/tools/bind/index.js +13 -0
- package/{agent/tools/bind.ts → agents/github/skills/github-account/tools/bind/index.ts} +3 -3
- package/agents/github/skills/github-account/tools/install/index.js +13 -0
- package/{agent/tools/install.ts → agents/github/skills/github-account/tools/install/index.ts} +2 -2
- package/agents/github/skills/github-account/tools/unbind/index.js +13 -0
- package/{agent/tools/unbind.ts → agents/github/skills/github-account/tools/unbind/index.ts} +3 -3
- package/agents/github/skills/github-account/tools/whoami/index.js +13 -0
- package/{agent/tools/whoami.ts → agents/github/skills/github-account/tools/whoami/index.ts} +3 -3
- package/agents/github/skills/github-cli/SKILL.md +47 -0
- package/agents/github/skills/github-repository/SKILL.md +21 -0
- package/{lib/github-bot-handlers.js → agents/github/skills/github-repository/handlers.js} +2 -1
- package/{src/github-bot-handlers.ts → agents/github/skills/github-repository/handlers.ts} +3 -3
- package/agents/github/skills/github-repository/tools/create_pr/index.js +20 -0
- package/{agent/tools/create_pr.ts → agents/github/skills/github-repository/tools/create_pr/index.ts} +4 -4
- package/agents/github/skills/github-repository/tools/patch_file/index.js +19 -0
- package/{agent/tools/patch_file.ts → agents/github/skills/github-repository/tools/patch_file/index.ts} +3 -3
- package/agents/github/skills/github-repository/tools/prepare_workspace/index.js +15 -0
- package/{agent/tools/prepare_workspace.ts → agents/github/skills/github-repository/tools/prepare_workspace/index.ts} +3 -3
- package/agents/github/skills/github-repository/tools/push_branch/index.js +18 -0
- package/{agent/tools/push_branch.ts → agents/github/skills/github-repository/tools/push_branch/index.ts} +4 -4
- package/agents/github/skills/github-subscriptions/SKILL.md +20 -0
- package/agents/github/skills/github-subscriptions/handlers.js +101 -0
- package/agents/github/skills/github-subscriptions/handlers.ts +119 -0
- package/agents/github/skills/github-subscriptions/tools/star/index.js +16 -0
- package/{agent/tools/star.ts → agents/github/skills/github-subscriptions/tools/star/index.ts} +3 -3
- package/agents/github/skills/github-subscriptions/tools/subscribe/index.js +16 -0
- package/{agent/tools/subscribe.ts → agents/github/skills/github-subscriptions/tools/subscribe/index.ts} +3 -3
- package/agents/github/skills/github-subscriptions/tools/subscriptions/index.js +13 -0
- package/{agent/tools/subscriptions.ts → agents/github/skills/github-subscriptions/tools/subscriptions/index.ts} +3 -3
- package/agents/github/skills/github-subscriptions/tools/unsubscribe/index.js +15 -0
- package/{agent/tools/unsubscribe.ts → agents/github/skills/github-subscriptions/tools/unsubscribe/index.ts} +3 -3
- package/agents/github/system.md +3 -0
- package/commands/{endpoint/add/[id].js → github/endpoint/add/[id]/index.js} +1 -1
- package/commands/github/endpoint/add/[id]/index.ts +3 -0
- package/{lib/github-endpoint-commands.js → commands/github/endpoint/definition.js} +6 -5
- package/{src/github-endpoint-commands.ts → commands/github/endpoint/definition.ts} +5 -5
- package/commands/{endpoint/list.js → github/endpoint/list/index.js} +1 -1
- package/commands/github/endpoint/list/index.ts +3 -0
- package/commands/{endpoint/remove/[id].js → github/endpoint/remove/[id]/index.js} +1 -1
- package/commands/github/endpoint/remove/[id]/index.ts +3 -0
- package/lib/client.js +1 -4
- package/lib/endpoint.js +4 -4
- package/lib/github-runtime-state.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/protocol.d.ts +11 -33
- package/lib/protocol.js +19 -30
- package/lib/types.d.ts +0 -23
- package/lib/types.js +2 -3
- package/package.json +35 -19
- package/plugin.js +3 -3
- package/prompt-sections/platform/index.js +16 -0
- package/schema.json +33 -26
- package/src/client.ts +1 -4
- package/src/endpoint.ts +4 -4
- package/src/github-runtime-state.ts +1 -1
- package/src/index.ts +1 -1
- package/src/protocol.ts +26 -79
- package/src/types.ts +0 -28
- package/agent/skills/github.md +0 -283
- package/commands/endpoint/add/[id].ts +0 -3
- package/commands/endpoint/list.ts +0 -3
- package/commands/endpoint/remove/[id].ts +0 -3
- package/lib/github-bot-handlers.d.ts +0 -27
- package/lib/github-endpoint-commands.d.ts +0 -1
- package/lib/github-tool-handlers.d.ts +0 -18
- /package/{agent/prompt-sections/platform.ts → prompt-sections/platform/index.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defineAgentTool } from '@zhin.js/
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { executeGithubUnsubscribe } from '../../
|
|
3
|
+
import { executeGithubUnsubscribe } from '../../handlers.js';
|
|
4
4
|
|
|
5
5
|
export default defineAgentTool<{ repo: string }>({
|
|
6
6
|
description: '取消订阅 GitHub 仓库的 Webhook 事件',
|
|
@@ -10,6 +10,6 @@ export default defineAgentTool<{ repo: string }>({
|
|
|
10
10
|
adapter: 'github',
|
|
11
11
|
tags: ['github'],
|
|
12
12
|
async execute(input, context) {
|
|
13
|
-
return executeGithubUnsubscribe(input, context.$client
|
|
13
|
+
return executeGithubUnsubscribe(input, context.$client);
|
|
14
14
|
},
|
|
15
15
|
});
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
1
2
|
/**
|
|
2
|
-
* `github
|
|
3
|
-
* commands/endpoint/ 下的 list / add / remove 直接默认导出这三项。
|
|
3
|
+
* `github endpoint` 命令族:由 @zhin.js/adapter 的 createEndpointCommands 套件生成。
|
|
4
|
+
* commands/github/endpoint/ 下的 list / add / remove 直接默认导出这三项。
|
|
4
5
|
*
|
|
5
6
|
* 字段说明:private_key 内容长且含换行,不适合 kv 直传——运行时(gh-client
|
|
6
7
|
* resolvePrivateKey)本就支持 PEM 内容或文件路径,故 add 采用**内联路径**形式:
|
|
7
|
-
* `github
|
|
8
|
+
* `github endpoint add mybot app_id=123456 private_key=./data/mybot.pem`。
|
|
8
9
|
*/
|
|
9
10
|
import { createEndpointCommands } from 'zhin.js/adapter';
|
|
10
11
|
import { defineCommand } from 'zhin.js/command';
|
|
11
|
-
import { githubRuntimeStateToken } from
|
|
12
|
+
import { githubRuntimeStateToken } from "../../../lib/github-runtime-state.js";
|
|
12
13
|
export const githubEndpointCommands = createEndpointCommands({
|
|
13
14
|
adapterKey: 'github',
|
|
14
15
|
adapterDisplayName: 'GitHub',
|
|
@@ -18,5 +19,5 @@ export const githubEndpointCommands = createEndpointCommands({
|
|
|
18
19
|
{ key: 'webhook_secret', env: true, description: 'webhook 签名密钥(不配则 API-only)' },
|
|
19
20
|
],
|
|
20
21
|
running: (use) => use(githubRuntimeStateToken).endpoints.values(),
|
|
21
|
-
describeEntry: (entry) => `app_id: ${String(entry.app_id
|
|
22
|
+
describeEntry: (entry) => `app_id: ${String(entry.app_id)}`,
|
|
22
23
|
}, defineCommand);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `github
|
|
3
|
-
* commands/endpoint/ 下的 list / add / remove 直接默认导出这三项。
|
|
2
|
+
* `github endpoint` 命令族:由 @zhin.js/adapter 的 createEndpointCommands 套件生成。
|
|
3
|
+
* commands/github/endpoint/ 下的 list / add / remove 直接默认导出这三项。
|
|
4
4
|
*
|
|
5
5
|
* 字段说明:private_key 内容长且含换行,不适合 kv 直传——运行时(gh-client
|
|
6
6
|
* resolvePrivateKey)本就支持 PEM 内容或文件路径,故 add 采用**内联路径**形式:
|
|
7
|
-
* `github
|
|
7
|
+
* `github endpoint add mybot app_id=123456 private_key=./data/mybot.pem`。
|
|
8
8
|
*/
|
|
9
9
|
import { createEndpointCommands } from 'zhin.js/adapter';
|
|
10
10
|
import { defineCommand } from 'zhin.js/command';
|
|
11
|
-
import { githubRuntimeStateToken } from '
|
|
11
|
+
import { githubRuntimeStateToken } from '../../../src/github-runtime-state.js';
|
|
12
12
|
|
|
13
13
|
export const githubEndpointCommands = createEndpointCommands({
|
|
14
14
|
adapterKey: 'github',
|
|
@@ -19,5 +19,5 @@ export const githubEndpointCommands = createEndpointCommands({
|
|
|
19
19
|
{ key: 'webhook_secret', env: true, description: 'webhook 签名密钥(不配则 API-only)' },
|
|
20
20
|
],
|
|
21
21
|
running: (use) => use(githubRuntimeStateToken).endpoints.values(),
|
|
22
|
-
describeEntry: (entry) => `app_id: ${String(entry.app_id
|
|
22
|
+
describeEntry: (entry) => `app_id: ${String(entry.app_id)}`,
|
|
23
23
|
}, defineCommand);
|
package/lib/client.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
1
|
import { defineEndpointClient } from 'zhin.js/adapter';
|
|
3
2
|
import { lookupGithubOauthAccessToken } from './oauth-users.js';
|
|
4
3
|
import { WorkspaceManager } from './workspace-manager.js';
|
|
@@ -37,9 +36,7 @@ export class GithubClient {
|
|
|
37
36
|
}
|
|
38
37
|
get workspaceManager() {
|
|
39
38
|
if (!this.#workspaceManager) {
|
|
40
|
-
|
|
41
|
-
?? path.join(process.cwd(), 'data', 'github-workspaces');
|
|
42
|
-
this.#workspaceManager = new WorkspaceManager(this.api, root);
|
|
39
|
+
this.#workspaceManager = new WorkspaceManager(this.api, this.config.workspaceRoot);
|
|
43
40
|
}
|
|
44
41
|
return this.#workspaceManager;
|
|
45
42
|
}
|
package/lib/endpoint.js
CHANGED
|
@@ -133,8 +133,8 @@ export class GithubEndpoint extends Endpoint {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
export function defaultCreateClient(config) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
:
|
|
139
|
-
|
|
136
|
+
return new GhClient({
|
|
137
|
+
host: config.host,
|
|
138
|
+
appAuth: { appId: config.appId, privateKey: config.privateKey },
|
|
139
|
+
});
|
|
140
140
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* GitHub 插件实例的运行时状态:adapter create() 注册的 endpoint 列表。
|
|
3
|
-
* 由 plugin.ts setup() provide,adapter create 与 `github
|
|
3
|
+
* 由 plugin.ts setup() provide,adapter create 与 `github endpoint` 命令共享(同一 owner generation)。
|
|
4
4
|
*/
|
|
5
5
|
import { defineEndpointRuntimeStateToken } from 'zhin.js/adapter';
|
|
6
6
|
export const githubRuntimeStateToken = defineEndpointRuntimeStateToken('github');
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { buildChannelId, enrichInboundContent, formatInboundContent, formatNotification, formatOutboundBody, normalizeWebhookPath, parseChannelId, parseIssueCommentInbound, parsePrReviewCommentInbound, parsePrReviewInbound, resolveGithubConfig, shouldAutoReplyRepo, verifyWebhookSignature, type
|
|
1
|
+
export { buildChannelId, enrichInboundContent, formatInboundContent, formatNotification, formatOutboundBody, normalizeWebhookPath, parseChannelId, parseIssueCommentInbound, parsePrReviewCommentInbound, parsePrReviewInbound, resolveGithubConfig, shouldAutoReplyRepo, verifyWebhookSignature, type GithubEndpointConfig, type GithubInboundComment, type GithubWireSegment, type ResolvedGithubConfig, } from './protocol.js';
|
|
2
2
|
export * from './types.js';
|
|
3
3
|
export { GhClient } from './gh-client.js';
|
|
4
4
|
export { GithubClient, githubClient, type GithubClientEventMap } from './client.js';
|
package/lib/protocol.d.ts
CHANGED
|
@@ -3,55 +3,33 @@
|
|
|
3
3
|
* Canonicalization is owned by gateway/core before endpoint.send.
|
|
4
4
|
*/
|
|
5
5
|
import type { IncomingMessage } from 'node:http';
|
|
6
|
-
import type
|
|
6
|
+
import { type ConversationRef } from '@zhin.js/im-contract';
|
|
7
7
|
import { type GenericWebhookPayload, type IssueCommentPayload, type PRReviewCommentPayload, type PRReviewPayload } from './types.js';
|
|
8
|
-
export type { EventType, GenericWebhookPayload, GitHubComment,
|
|
8
|
+
export type { EventType, GenericWebhookPayload, GitHubComment, GitHubIssue, GitHubOAuthUser, GitHubPR, GitHubRepo, GitHubUser, IssueCommentPayload, ParsedChannel, PRReviewCommentPayload, PRReviewPayload, Subscription, } from './types.js';
|
|
9
9
|
export { buildChannelId, parseChannelId } from './types.js';
|
|
10
|
-
/**
|
|
11
|
-
export interface
|
|
12
|
-
readonly id
|
|
10
|
+
/** One expanded GitHub endpoint configuration produced by AdapterIndex. */
|
|
11
|
+
export interface GithubEndpointConfig {
|
|
12
|
+
readonly id: string;
|
|
13
13
|
readonly host?: string;
|
|
14
|
-
readonly app_id
|
|
15
|
-
readonly
|
|
16
|
-
readonly private_key?: string;
|
|
17
|
-
readonly privateKey?: string;
|
|
14
|
+
readonly app_id: string | number;
|
|
15
|
+
readonly private_key: string;
|
|
18
16
|
readonly webhook_secret?: string;
|
|
19
|
-
readonly webhookSecret?: string;
|
|
20
17
|
readonly webhook_path?: string;
|
|
21
|
-
readonly webhookPath?: string;
|
|
22
|
-
readonly poll_interval?: number;
|
|
23
|
-
readonly pollInterval?: number;
|
|
24
18
|
readonly auto_reply_repos?: readonly string[];
|
|
25
|
-
readonly autoReplyRepos?: readonly string[];
|
|
26
19
|
readonly bot_login?: string;
|
|
27
|
-
readonly botLogin?: string;
|
|
28
20
|
readonly workspace_root?: string;
|
|
29
|
-
readonly workspaceRoot?: string;
|
|
30
|
-
/** Transitional: legacy root `endpoints[]` with `context: github`. */
|
|
31
|
-
readonly endpoints?: ReadonlyArray<Partial<ResolvedGithubConfig> & {
|
|
32
|
-
readonly context?: string;
|
|
33
|
-
readonly app_id?: string | number;
|
|
34
|
-
readonly private_key?: string;
|
|
35
|
-
readonly webhook_secret?: string;
|
|
36
|
-
readonly webhook_path?: string;
|
|
37
|
-
readonly poll_interval?: number;
|
|
38
|
-
readonly auto_reply_repos?: readonly string[];
|
|
39
|
-
readonly bot_login?: string;
|
|
40
|
-
readonly workspace_root?: string;
|
|
41
|
-
}>;
|
|
42
21
|
}
|
|
43
22
|
export interface ResolvedGithubConfig {
|
|
44
23
|
readonly context: 'github';
|
|
45
24
|
readonly id: string;
|
|
46
25
|
readonly host?: string;
|
|
47
|
-
readonly appId
|
|
48
|
-
readonly privateKey
|
|
26
|
+
readonly appId: string | number;
|
|
27
|
+
readonly privateKey: string;
|
|
49
28
|
readonly webhookSecret?: string;
|
|
50
29
|
readonly webhookPath: string;
|
|
51
|
-
readonly pollInterval: number;
|
|
52
30
|
readonly autoReplyRepos: readonly string[];
|
|
53
31
|
readonly botLogin?: string;
|
|
54
|
-
readonly workspaceRoot
|
|
32
|
+
readonly workspaceRoot: string;
|
|
55
33
|
}
|
|
56
34
|
export interface GithubWireSegment {
|
|
57
35
|
readonly type: string;
|
|
@@ -72,7 +50,7 @@ export interface GithubInboundComment {
|
|
|
72
50
|
* 在平台边界还原 repo/type/number。
|
|
73
51
|
*/
|
|
74
52
|
export declare function githubInboundConversation(endpointKey: string, comment: GithubInboundComment): ConversationRef;
|
|
75
|
-
export declare function resolveGithubConfig(config
|
|
53
|
+
export declare function resolveGithubConfig(config: GithubEndpointConfig): ResolvedGithubConfig;
|
|
76
54
|
export declare function normalizeWebhookPath(path: string): string;
|
|
77
55
|
export declare function shouldAutoReplyRepo(config: Pick<ResolvedGithubConfig, 'autoReplyRepos'>, repo: string): boolean;
|
|
78
56
|
/** Prepend synthetic @bot for auto_reply repos (gateway text path). */
|
package/lib/protocol.js
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
* Canonicalization is owned by gateway/core before endpoint.send.
|
|
4
4
|
*/
|
|
5
5
|
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
6
|
-
import {
|
|
7
|
-
import { isMediaRef } from '@zhin.js/core';
|
|
6
|
+
import { isMediaRef } from '@zhin.js/im-contract';
|
|
8
7
|
import { formatCompact, getLogger } from '@zhin.js/logger';
|
|
9
8
|
const logger = getLogger('github');
|
|
10
9
|
import { buildChannelId, } from './types.js';
|
|
@@ -22,45 +21,35 @@ export function githubInboundConversation(endpointKey, comment) {
|
|
|
22
21
|
parent: { kind: 'channel', id: comment.repo },
|
|
23
22
|
};
|
|
24
23
|
}
|
|
25
|
-
export function resolveGithubConfig(config
|
|
26
|
-
const
|
|
27
|
-
|
|
24
|
+
export function resolveGithubConfig(config) {
|
|
25
|
+
const id = typeof config.id === 'string' ? config.id.trim() : '';
|
|
26
|
+
if (!id)
|
|
27
|
+
throw new TypeError('GitHub endpoint requires a non-empty id');
|
|
28
|
+
const appIdRaw = config.app_id != null ? String(config.app_id).trim() : '';
|
|
28
29
|
const appId = appIdRaw ? (Number(appIdRaw) || appIdRaw) : undefined;
|
|
29
|
-
const privateKey =
|
|
30
|
+
const privateKey = typeof config.private_key === 'string'
|
|
31
|
+
? config.private_key.trim()
|
|
32
|
+
: '';
|
|
30
33
|
if (!appId || !privateKey) {
|
|
31
|
-
throw new TypeError('GitHub
|
|
34
|
+
throw new TypeError('GitHub endpoint requires app_id and private_key');
|
|
32
35
|
}
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
?? process.env.GITHUB_WEBHOOK_SECRET
|
|
40
|
-
?? undefined;
|
|
41
|
-
const host = config.host ?? entry?.host;
|
|
42
|
-
const webhookPath = normalizeWebhookPath(config.webhookPath ?? config.webhook_path ?? entry?.webhookPath ?? entry?.webhook_path
|
|
43
|
-
?? '/github/webhook');
|
|
44
|
-
const pollInterval = Number(config.pollInterval ?? config.poll_interval ?? entry?.pollInterval ?? entry?.poll_interval ?? 60) || 60;
|
|
45
|
-
const autoReplyRepos = [
|
|
46
|
-
...(config.autoReplyRepos ?? config.auto_reply_repos
|
|
47
|
-
?? entry?.autoReplyRepos ?? entry?.auto_reply_repos ?? []),
|
|
48
|
-
];
|
|
49
|
-
const botLogin = config.botLogin ?? config.bot_login ?? entry?.botLogin ?? entry?.bot_login;
|
|
50
|
-
const workspaceRoot = config.workspaceRoot ?? config.workspace_root
|
|
51
|
-
?? entry?.workspaceRoot ?? entry?.workspace_root;
|
|
36
|
+
const webhookSecret = config.webhook_secret;
|
|
37
|
+
const host = config.host;
|
|
38
|
+
const webhookPath = normalizeWebhookPath(config.webhook_path ?? '/github/webhook');
|
|
39
|
+
const autoReplyRepos = [...(config.auto_reply_repos ?? [])];
|
|
40
|
+
const botLogin = config.bot_login;
|
|
41
|
+
const workspaceRoot = config.workspace_root ?? 'data/github-workspaces';
|
|
52
42
|
return {
|
|
53
43
|
context: 'github',
|
|
54
44
|
id,
|
|
55
45
|
...(host ? { host } : {}),
|
|
56
|
-
|
|
57
|
-
|
|
46
|
+
appId,
|
|
47
|
+
privateKey,
|
|
58
48
|
...(webhookSecret ? { webhookSecret } : {}),
|
|
59
49
|
webhookPath,
|
|
60
|
-
pollInterval,
|
|
61
50
|
autoReplyRepos,
|
|
62
51
|
...(botLogin ? { botLogin } : {}),
|
|
63
|
-
|
|
52
|
+
workspaceRoot,
|
|
64
53
|
};
|
|
65
54
|
}
|
|
66
55
|
export function normalizeWebhookPath(path) {
|
package/lib/types.d.ts
CHANGED
|
@@ -1,26 +1,3 @@
|
|
|
1
|
-
export interface GitHubEndpointConfig {
|
|
2
|
-
context: 'github';
|
|
3
|
-
/** Endpoint 标识名称 */
|
|
4
|
-
name: string;
|
|
5
|
-
/** GitHub Enterprise 主机名(默认 github.com) */
|
|
6
|
-
host?: string;
|
|
7
|
-
/** GitHub App ID */
|
|
8
|
-
app_id?: string | number;
|
|
9
|
-
/** GitHub App 私钥(PEM 内容或文件路径) */
|
|
10
|
-
private_key?: string;
|
|
11
|
-
/** Webhook Secret(配置后启用 Webhook 接收事件,不配置则使用轮询) */
|
|
12
|
-
webhook_secret?: string;
|
|
13
|
-
/** Webhook 路由路径(默认 /github/webhook) */
|
|
14
|
-
webhook_path?: string;
|
|
15
|
-
/** 事件轮询间隔(秒,默认 60,Webhook 模式下作为降级备选) */
|
|
16
|
-
poll_interval?: number;
|
|
17
|
-
/** 这些仓库的人类 Issue/PR 评论自动触发 AI(无需 @bot) */
|
|
18
|
-
auto_reply_repos?: string[];
|
|
19
|
-
/** 覆盖 App bot 登录名(默认 {slug}[bot]) */
|
|
20
|
-
bot_login?: string;
|
|
21
|
-
/** 托管 git 工作区根目录(默认 {cwd}/data/github-workspaces) */
|
|
22
|
-
workspace_root?: string;
|
|
23
|
-
}
|
|
24
1
|
export interface ParsedChannel {
|
|
25
2
|
repo: string;
|
|
26
3
|
type: 'issue' | 'pr';
|
package/lib/types.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// ──
|
|
2
|
-
//
|
|
3
|
-
// 认证方式:gh auth login
|
|
1
|
+
// ── Channel ID ───────────────────────────────────────────────────────
|
|
2
|
+
// 格式: {owner}/{repo}/issues/{number} 或 {owner}/{repo}/pull/{number}
|
|
4
3
|
export function parseChannelId(channelId) {
|
|
5
4
|
const issueMatch = channelId.match(/^(.+?\/.+?)\/issues\/(\d+)$/);
|
|
6
5
|
if (issueMatch)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-github",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Zhin.js GitHub adapter for Plugin Runtime (App auth + webhook)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -41,22 +41,25 @@
|
|
|
41
41
|
"directory": "plugins/adapters/github"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@zhin.js/adapter": "1.1.
|
|
45
|
-
"@zhin.js/
|
|
46
|
-
"@zhin.js/
|
|
47
|
-
"@zhin.js/
|
|
48
|
-
"@zhin.js/
|
|
49
|
-
"@zhin.js/
|
|
44
|
+
"@zhin.js/adapter": "1.1.14",
|
|
45
|
+
"@zhin.js/agent-feature": "1.1.1",
|
|
46
|
+
"@zhin.js/core": "1.1.37",
|
|
47
|
+
"@zhin.js/feature-kit": "1.1.1",
|
|
48
|
+
"@zhin.js/host-http": "1.1.1",
|
|
49
|
+
"@zhin.js/im-contract": "1.1.1",
|
|
50
|
+
"@zhin.js/logger": "1.1.1",
|
|
51
|
+
"@zhin.js/skill": "1.1.1",
|
|
52
|
+
"@zhin.js/tool": "1.1.1"
|
|
50
53
|
},
|
|
51
54
|
"peerDependencies": {
|
|
52
55
|
"zod": "^4.0.0",
|
|
53
|
-
"@zhin.js/adapter": "^1.1.
|
|
54
|
-
"@zhin.js/agent": "^1.1.
|
|
55
|
-
"@zhin.js/command": "^1.1.
|
|
56
|
-
"@zhin.js/core": "^1.1.
|
|
57
|
-
"@zhin.js/host-http": "^1.1.
|
|
58
|
-
"@zhin.js/prompt-section": "^1.1.
|
|
59
|
-
"zhin.js": "^1.1.
|
|
56
|
+
"@zhin.js/adapter": "^1.1.14",
|
|
57
|
+
"@zhin.js/agent": "^1.1.26",
|
|
58
|
+
"@zhin.js/command": "^1.1.1",
|
|
59
|
+
"@zhin.js/core": "^1.1.37",
|
|
60
|
+
"@zhin.js/host-http": "^1.1.1",
|
|
61
|
+
"@zhin.js/prompt-section": "^1.1.1",
|
|
62
|
+
"zhin.js": "^1.1.2"
|
|
60
63
|
},
|
|
61
64
|
"peerDependenciesMeta": {
|
|
62
65
|
"@zhin.js/agent": {
|
|
@@ -80,9 +83,9 @@
|
|
|
80
83
|
"typescript": "^6.0.3",
|
|
81
84
|
"vitest": "^4.1.10",
|
|
82
85
|
"zod": "^4.4.3",
|
|
83
|
-
"@zhin.js/agent": "1.1.
|
|
84
|
-
"@zhin.js/prompt-section": "1.1.
|
|
85
|
-
"zhin.js": "1.1.
|
|
86
|
+
"@zhin.js/agent": "1.1.26",
|
|
87
|
+
"@zhin.js/prompt-section": "1.1.1",
|
|
88
|
+
"zhin.js": "1.1.2"
|
|
86
89
|
},
|
|
87
90
|
"files": [
|
|
88
91
|
"adapters",
|
|
@@ -91,9 +94,10 @@
|
|
|
91
94
|
"schema.json",
|
|
92
95
|
"src",
|
|
93
96
|
"lib",
|
|
94
|
-
"
|
|
97
|
+
"agents",
|
|
95
98
|
"README.md",
|
|
96
|
-
"CHANGELOG.md"
|
|
99
|
+
"CHANGELOG.md",
|
|
100
|
+
"prompt-sections"
|
|
97
101
|
],
|
|
98
102
|
"publishConfig": {
|
|
99
103
|
"access": "public",
|
|
@@ -116,6 +120,18 @@
|
|
|
116
120
|
{
|
|
117
121
|
"package": "@zhin.js/command",
|
|
118
122
|
"api": "^1.0.0"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"package": "@zhin.js/tool",
|
|
126
|
+
"api": "^1.0.0"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"package": "@zhin.js/skill",
|
|
130
|
+
"api": "^1.0.0"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"package": "@zhin.js/agent-feature",
|
|
134
|
+
"api": "^1.0.0"
|
|
119
135
|
}
|
|
120
136
|
],
|
|
121
137
|
"plugins": []
|
package/plugin.js
CHANGED
|
@@ -5,7 +5,7 @@ import { githubRuntimeStateToken } from "./lib/github-runtime-state.js";
|
|
|
5
5
|
import { defineGithubOauthUsersTable } from "./lib/oauth-users.js";
|
|
6
6
|
/**
|
|
7
7
|
* github_subscriptions — repo event subscriptions per chat channel
|
|
8
|
-
* (used by github_subscriptions agent tool; schema
|
|
8
|
+
* (used by github_subscriptions agent tool; schema is registered through DatabaseHost).
|
|
9
9
|
*/
|
|
10
10
|
const GITHUB_SUBSCRIPTIONS_SCHEMA = {
|
|
11
11
|
id: { type: 'integer', primary: true },
|
|
@@ -18,7 +18,7 @@ const GITHUB_SUBSCRIPTIONS_SCHEMA = {
|
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
20
|
* Plugin Runtime GitHub adapter.
|
|
21
|
-
* - Endpoint: `adapters/github.ts`
|
|
21
|
+
* - Endpoint: `adapters/github/index.ts`
|
|
22
22
|
* - OAuth user tokens: define `github_oauth_users` when DatabaseHost is present
|
|
23
23
|
*/
|
|
24
24
|
export default definePlugin({
|
|
@@ -27,7 +27,7 @@ export default definePlugin({
|
|
|
27
27
|
displayName: 'GitHub Adapter',
|
|
28
28
|
},
|
|
29
29
|
setup(context) {
|
|
30
|
-
// 运行中 endpoint 注册表(github
|
|
30
|
+
// 运行中 endpoint 注册表(github endpoint list 的"运行中"数据源)
|
|
31
31
|
context.resources.provide(githubRuntimeStateToken, createEndpointRuntimeState());
|
|
32
32
|
if (context.resources.has(databaseHostToken)) {
|
|
33
33
|
const host = context.resources.use(databaseHostToken);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentPromptSection } from '@zhin.js/prompt-section';
|
|
3
|
+
export default defineAgentPromptSection({
|
|
4
|
+
title: 'GitHub',
|
|
5
|
+
content: [
|
|
6
|
+
'On GitHub, discuss Issues and Pull Requests in their current conversation context.',
|
|
7
|
+
'Use github_* tools for Bot write operations; do not use mcp_github_* writes that act as a human PAT.',
|
|
8
|
+
'Use a workspace and branch for multi-file changes, then report the resulting Pull Request or branch.',
|
|
9
|
+
].join('\n'),
|
|
10
|
+
layer: 'tools',
|
|
11
|
+
order: 70,
|
|
12
|
+
retention: 'preferred',
|
|
13
|
+
maxChars: 1200,
|
|
14
|
+
profiles: ['interactive'],
|
|
15
|
+
platforms: ['github'],
|
|
16
|
+
});
|
package/schema.json
CHANGED
|
@@ -11,15 +11,6 @@
|
|
|
11
11
|
"type": "string",
|
|
12
12
|
"default": "/github/webhook"
|
|
13
13
|
},
|
|
14
|
-
"webhookPath": {
|
|
15
|
-
"type": "string",
|
|
16
|
-
"default": "/github/webhook"
|
|
17
|
-
},
|
|
18
|
-
"poll_interval": {
|
|
19
|
-
"type": "number",
|
|
20
|
-
"default": 60,
|
|
21
|
-
"description": "Deferred: polling fallback was removed in the Plugin Runtime migration; currently parsed but unused"
|
|
22
|
-
},
|
|
23
14
|
"auto_reply_repos": {
|
|
24
15
|
"type": "array",
|
|
25
16
|
"items": {
|
|
@@ -55,10 +46,11 @@
|
|
|
55
46
|
},
|
|
56
47
|
"endpoints": {
|
|
57
48
|
"type": "array",
|
|
49
|
+
"minItems": 1,
|
|
58
50
|
"description": "多账号:一个插件实例挂多个 endpoint",
|
|
59
51
|
"items": {
|
|
60
52
|
"type": "object",
|
|
61
|
-
"additionalProperties":
|
|
53
|
+
"additionalProperties": false,
|
|
62
54
|
"properties": {
|
|
63
55
|
"master": {
|
|
64
56
|
"type": [
|
|
@@ -85,36 +77,51 @@
|
|
|
85
77
|
],
|
|
86
78
|
"description": "GitHub App ID"
|
|
87
79
|
},
|
|
88
|
-
"appId": {
|
|
89
|
-
"type": [
|
|
90
|
-
"string",
|
|
91
|
-
"number"
|
|
92
|
-
],
|
|
93
|
-
"description": "GitHub App ID (camelCase alias)"
|
|
94
|
-
},
|
|
95
80
|
"private_key": {
|
|
96
81
|
"type": "string",
|
|
97
82
|
"description": "GitHub App private key (PEM content or file path)"
|
|
98
83
|
},
|
|
99
|
-
"privateKey": {
|
|
100
|
-
"type": "string",
|
|
101
|
-
"description": "GitHub App private key (camelCase alias)"
|
|
102
|
-
},
|
|
103
84
|
"webhook_secret": {
|
|
104
85
|
"type": "string",
|
|
105
86
|
"description": "Webhook HMAC secret; enables httpHostToken POST route"
|
|
106
87
|
},
|
|
107
|
-
"webhookSecret": {
|
|
108
|
-
"type": "string",
|
|
109
|
-
"description": "Webhook HMAC secret (camelCase alias)"
|
|
110
|
-
},
|
|
111
88
|
"id": {
|
|
112
89
|
"type": "string",
|
|
90
|
+
"minLength": 1,
|
|
113
91
|
"description": "GitHub App bot name"
|
|
92
|
+
},
|
|
93
|
+
"host": {
|
|
94
|
+
"type": "string",
|
|
95
|
+
"description": "GitHub Enterprise hostname"
|
|
96
|
+
},
|
|
97
|
+
"webhook_path": {
|
|
98
|
+
"type": "string",
|
|
99
|
+
"description": "Webhook route path"
|
|
100
|
+
},
|
|
101
|
+
"auto_reply_repos": {
|
|
102
|
+
"type": "array",
|
|
103
|
+
"items": {
|
|
104
|
+
"type": "string"
|
|
105
|
+
},
|
|
106
|
+
"description": "Repos whose comments auto-trigger AI"
|
|
107
|
+
},
|
|
108
|
+
"bot_login": {
|
|
109
|
+
"type": "string",
|
|
110
|
+
"description": "Override App bot login"
|
|
111
|
+
},
|
|
112
|
+
"workspace_root": {
|
|
113
|
+
"type": "string",
|
|
114
|
+
"description": "Managed git workspace root"
|
|
115
|
+
},
|
|
116
|
+
"commandPrefix": {
|
|
117
|
+
"type": "string",
|
|
118
|
+
"description": "本 endpoint 的命令前缀"
|
|
114
119
|
}
|
|
115
120
|
},
|
|
116
121
|
"required": [
|
|
117
|
-
"id"
|
|
122
|
+
"id",
|
|
123
|
+
"app_id",
|
|
124
|
+
"private_key"
|
|
118
125
|
]
|
|
119
126
|
}
|
|
120
127
|
},
|
package/src/client.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
1
|
import type { PluginDatabaseHost } from 'zhin.js';
|
|
3
2
|
import { defineEndpointClient } from 'zhin.js/adapter';
|
|
4
3
|
import { GhClient } from './gh-client.js';
|
|
@@ -43,9 +42,7 @@ export class GithubClient {
|
|
|
43
42
|
|
|
44
43
|
get workspaceManager(): WorkspaceManager {
|
|
45
44
|
if (!this.#workspaceManager) {
|
|
46
|
-
|
|
47
|
-
?? path.join(process.cwd(), 'data', 'github-workspaces');
|
|
48
|
-
this.#workspaceManager = new WorkspaceManager(this.api, root);
|
|
45
|
+
this.#workspaceManager = new WorkspaceManager(this.api, this.config.workspaceRoot);
|
|
49
46
|
}
|
|
50
47
|
return this.#workspaceManager;
|
|
51
48
|
}
|
package/src/endpoint.ts
CHANGED
|
@@ -162,8 +162,8 @@ export class GithubEndpoint extends Endpoint<GithubClient> {
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
export function defaultCreateClient(config: ResolvedGithubConfig): GhClient {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
:
|
|
168
|
-
|
|
165
|
+
return new GhClient({
|
|
166
|
+
host: config.host,
|
|
167
|
+
appAuth: { appId: config.appId, privateKey: config.privateKey },
|
|
168
|
+
});
|
|
169
169
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* GitHub 插件实例的运行时状态:adapter create() 注册的 endpoint 列表。
|
|
3
|
-
* 由 plugin.ts setup() provide,adapter create 与 `github
|
|
3
|
+
* 由 plugin.ts setup() provide,adapter create 与 `github endpoint` 命令共享(同一 owner generation)。
|
|
4
4
|
*/
|
|
5
5
|
import { defineEndpointRuntimeStateToken } from 'zhin.js/adapter';
|
|
6
6
|
|