A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Update tests and docs for the connector engine
Fei24114057e853a456
diff --git a/docs/plans/2026-11-04-connectors.md b/docs/plans/2026-11-04-connectors.mdnew file mode 100644index 00000000..ae704826--- /dev/null+++ b/docs/plans/2026-11-04-connectors.md@@ -0,0 +1,25 @@+# 连接器(Connectors)++日期:2026-11-04。代码:`ds-bot/src/host/connectors/`(`catalog.js` 目录、`oauth.js` 登录、`gateway.js` 本地网关、`mail/` 邮箱、`index.js` 引擎),客户端 `src/client/connectors.js`,端点在 `src/host/channel.js` 的 `connector-*` / `mail-*`。++## 行为++- 设置 → Connectors 一页:已连接列表、目录(搜索 + 分类)、添加菜单(粘贴地址、命令、从 Claude Desktop / Cursor / VS Code 导入)。+- 每个连接器一行:图标(GitHub 用原标,其他用首字母色块)、名称、状态、操作(Connect / Disconnect / Try again / Sign in again)、展开面板(浏览器登录、设备码、密钥/令牌、client 表单)、只读开关、工具数。+- 登录方式:免登录直连;MCP OAuth(WWW-Authenticate → 受保护资源元数据 → AS 元数据,旧服务器退回 MCP 源站;CIMD 仅在固定回环端口 38517 可用时;否则 DCR;都不行给 client 表单);GitHub 设备码(`DS_BOT_GITHUB_OAUTH_CLIENT_ID` 或常量为空时只给令牌粘贴);密钥(header / query);令牌粘贴。+- 令牌全部存 DS Bot 密钥(`GITHUB_TOKEN` 不变;其他 `CONNECTOR_<ID>_TOKEN/REFRESH/CLIENT_SECRET/KEY`),`scope: []` 不进 Bot shell;非密状态在 `state.connectors[id]`。+- 本地网关:mcp-client 只拿到 `http://127.0.0.1:<port>/c/<id>` 加随机 nonce;网关注入真实凭据、转发 `Mcp-Session-Id` 等头、透传 SSE、401 先刷新一次再重试一次(并发 401 共享一次刷新;`invalid_grant` → needs-sign-in);只读开关过滤 `tools/list` 非 readOnlyHint 工具并拒绝写 `tools/call`。+- Bot 默认都能用已连接的连接器;Bot 详情 → Connectors 逐项关(`offFor`,按 `mcp__<id>__*` / `mail_` 前缀在 per-agent mask 里 deny,随 `tools/change` 重挂)。+- Bot 工具:`list_connectors`、`request_connector`(自己会话出卡片,连接或忽略后回话)。+- 邮箱:QQ / 163 / 126 / Gmail / iCloud / 其他(IMAP+SMTP 应用密码;163/126 登录后发 ID;QQ 复用连接);Google 登录走 Gmail API(`DS_BOT_GOOGLE_OAUTH_CLIENT_ID/SECRET` 缺一则按钮隐藏)。`mail_search / mail_read / mail_draft / mail_send / mail_update`;发送必须经发送卡用户确认;草稿不出卡;附件存 Bot 工作文件夹。+- 导入:只读扫描 Claude Desktop / Cursor / VS Code 的 MCP 配置,env 值进密钥、配置里留 `$DSH_SECRET_` 引用;自定义 id 唯一且不占目录 id;能力名校验拒绝连接器 id。++## 不做++- 不加 Google 系 MCP(开发者预览条款)、不存 Google client secret 进仓、不引入厂商 logo、不在 Bot shell 暴露凭据、连接器不改 DSH。++## 已知限制++- OAuth 仅在本进程内生效;无图形验证时部分服务仍要手动贴 client。+- 只读过滤依赖服务的 `readOnlyHint`;没标注的按写处理。+- 邮箱线程按 References/In-Reply-To 关联;Gmail 「移动」按标签实现。diff --git a/docs/plans/README.md b/docs/plans/README.mdindex 309b7762..808c63b9 100644--- a/docs/plans/README.md+++ b/docs/plans/README.md@@ -41,7 +41,7 @@| [隐私 Bot](2026-10-27-private-bots.md) | 只有用户能开关;其他 Bot 读不到它的文件夹、记忆和会话,外发由用户批准;独立文件夹、删除后的保护和隔离边界 || [群聊](2026-10-07-group-chat.md) | 谁来回答、同时开工与按顺序发言、@ 提及、派活批次、干活中的进度和迟到的回复、审批与全部停止 || [群聊 Goal](2026-11-01-group-goal.md) | 管理员先对齐再写 Goal;分阶段派给成员、每阶段带证据验收;每轮带 Goal 账本防跑偏;空闲时自动推进;暂停、纠偏、终止;会话头胶囊和吊舱显示进度与分工 |-| [浏览器、搜索、密钥和连接器](2026-10-08-browser-and-secrets.md) | 每个 Bot 的浏览器和 `read_browser`、`auto` 联网搜索、密钥卡和替换规则、GitHub 连接器 |+| [浏览器、搜索、密钥和连接器](2026-10-08-browser-and-secrets.md) | 每个 Bot 的浏览器和 `read_browser`、`auto` 联网搜索、密钥卡和替换规则、GitHub 连接器(已被 2026-11-04 通用连接器取代) || [浏览器插件](2026-10-21-browser-plugins.md) | 全团队一个浏览器后端,每个 Bot 一份 profile;`refs` / `script` / `task` || [上下文与记忆](2026-10-09-context-and-memory.md) | 对话分段、上下文管家(压缩还是换段)、交接包、`read_own_chat`;记忆的存放、格式、权限、整理和冻结 || [记忆撤销与更改记录](2026-11-01-memory-restore.md) | 记忆窗口「更改记录」列出 `journal.jsonl` 的改动;按记录 id 对单条添加、修改或删除做逆操作撤销 |@@ -60,3 +60,4 @@| [启动页文案](2026-10-29-start-copy.md) | 启动页和壳里系统对话框的字:按页面位置分层,每层一条写法规则;`text.mjs` 一张表、旧键到新键的对照、扫全表的测试 || [手机 App](2026-10-24-mobile-app.md) | iOS 和 Android 远程操控电脑上的 Bot 团队:手机不跑 Agent;扫码配对、端到端加密、电脑只往外连;完整功能,高权限操作要解锁手机 || [Office 文档](2026-10-27-office-documents.md) | Bot 离线处理 .docx/.pptx/.xlsx:应用带的 payload、`office.js` 命令行、office 路由换成带 `office-tools` 的版本 |+| [连接器](2026-11-04-connectors.md) | 通用连接器引擎、OAuth、网关、邮箱 |diff --git a/ds-bot/test/capabilities.test.js b/ds-bot/test/capabilities.test.jsindex 828a165a..f776dd8c 100644--- a/ds-bot/test/capabilities.test.js+++ b/ds-bot/test/capabilities.test.js@@ -483,11 +483,11 @@ async function mountUrlCapability(t, { value, url, bots = ['chief'], awaitMountconst env = await setup({ secret: exaSecret(value) })t.after(() => env.dispose())const { ctx, rt, mounts, skills } = env- await rt.capabilitySave({ name: 'exa', kind: 'mcp', description: '', transport: 'streamable-http', url, headers: {} }, { botId: 'chief' })- for (const bot of bots) await rt.changeCapabilityAttachment('attach', { name: 'exa', bot: rt.state.bots[bot].name }, 'chief')+ await rt.capabilitySave({ name: 'exa-cap', kind: 'mcp', description: '', transport: 'streamable-http', url, headers: {} }, { botId: 'chief' })+ for (const bot of bots) await rt.changeCapabilityAttachment('attach', { name: 'exa-cap', bot: rt.state.bots[bot].name }, 'chief')for (const bot of bots) ctx.emit('agent/created', { agent: testAgent(bot, mounts, skills, { awaitMount }) })await rt.scheduleCapabilitiesReconcile()- const mountFor = bot => mounts.find(mount => mount.sessionId === bot && mount.config?.serverName === 'exa')+ const mountFor = bot => mounts.find(mount => mount.sessionId === bot && mount.config?.serverName === 'exa-cap')return { ...env, mountFor }}@@ -495,11 +495,11 @@ test('secret references in an HTTP MCP URL are resolved, and an unavailable oneconst env = await mountUrlCapability(t, { value: 'fake-exa-key', url: 'https://mcp.exa.test/mcp?apiKey=$DSH_SECRET_EXA_API_KEY', bots: ['chief', 'worker'] })const { rt, mountFor } = envassert.equal(mountFor('chief').config.url, 'https://mcp.exa.test/mcp?apiKey=fake-exa-key')- assert.equal(rt.capabilityStatusesView().chief.exa.state, 'ready')+ assert.equal(rt.capabilityStatusesView().chief['exa-cap'].state, 'ready')assert.equal(JSON.stringify(rt.state.capabilities).includes('fake-exa-key'), false)assert.equal(mountFor('worker'), undefined)- assert.equal(rt.capabilityStatusesView().worker.exa.state, 'error')- assert.match(rt.capabilityStatusesView().worker.exa.error, /EXA_API_KEY/)+ assert.equal(rt.capabilityStatusesView().worker['exa-cap'].state, 'error')+ assert.match(rt.capabilityStatusesView().worker['exa-cap'].error, /EXA_API_KEY/)})test('a secret in an HTTP MCP URL query is encoded as one parameter value', async t => {@@ -521,7 +521,7 @@ test('a failed HTTP MCP mount does not show the encoded secret from its URL', asurl: 'https://mcp.exa.test/mcp?apiKey=$DSH_SECRET_EXA_API_KEY',awaitMount: async mount => { throw new Error('Connection failed', { cause: new Error(`fetch ${mount.config.url}`) }) },})- const status = env.rt.capabilityStatusesView().chief.exa+ const status = env.rt.capabilityStatusesView().chief['exa-cap']assert.equal(status.state, 'error')assert.equal(status.error, 'Connection failed: fetch https://mcp.exa.test/mcp?apiKey=[secret:EXA_API_KEY]')})diff --git a/ds-bot/test/connectors.test.js b/ds-bot/test/connectors.test.jsindex 75d82540..a5978872 100644--- a/ds-bot/test/connectors.test.js+++ b/ds-bot/test/connectors.test.js@@ -5,7 +5,7 @@ import { tmpdir } from 'node:os'import { join } from 'node:path'import { test } from 'node:test'import { apply } from '../index.js'-import { signIn } from '../src/host/connectors.js'+import { signIn } from '../src/host/connectors/index.js'import { fakeContext } from './fake-ctx.js'const fresh = () => `ghp_${randomBytes(16).toString('hex')}`@@ -84,26 +84,26 @@ test('connecting saves the token, kept out of every Bot shell, and mounts GitHubconst token = fresh()const before = await call(ctx, 'state', {})- assert.deepEqual(before.value.connectors, [{ id: 'github', name: 'GitHub', state: 'off', account: null }])+ assert.equal(before.value.connectors.connectors.find(r => r.id === 'github').state, 'off')const connected = await call(ctx, 'connector-connect', { id: 'github', token: ` ${token} ` })assert.equal(connected.ok, true, JSON.stringify(connected))- assert.deepEqual(connected.value, [{ id: 'github', name: 'GitHub', state: 'ready', account: 'octo' }])+ const gh = connected.value.connectors.find(r => r.id === 'github'); assert.equal(gh.state, 'ready'); assert.equal(gh.account, 'octo')assert.equal(mounts.length, 1)- assert.deepEqual(mounts[0].config, {- transport: 'streamable-http',- serverName: 'github',- url: 'https://api.githubcopilot.com/mcp/',- headers: { Authorization: `Bearer ${token}`, 'X-MCP-Toolsets': 'context,repos,issues,pull_requests' },- failOnStartupError: true,- })+ // The mount points at the local gateway; the token never reaches its config.+ assert.equal(mounts[0].config.transport, 'streamable-http')+ assert.equal(mounts[0].config.serverName, 'github')+ assert.match(mounts[0].config.url, /^http:\/\/127\.0\.0\.1:\d+\/c\/github$/)+ assert.ok(!JSON.stringify(mounts[0].config).includes(token))+ assert.match(mounts[0].config.headers.Authorization, /^Bearer /)+ assert.ok(!mounts[0].config.headers.Authorization.includes(token))const state = await call(ctx, 'state', {})assert.deepEqual(state.value.secrets.map(secret => [secret.name, secret.scope]), [['GITHUB_TOKEN', []]])assert.ok(!JSON.stringify(state).includes(token))assert.ok(!readFileSync(join(home, 'state.json'), 'utf8').includes(token))const off = await call(ctx, 'connector-disconnect', { id: 'github' })- assert.deepEqual(off.value, [{ id: 'github', name: 'GitHub', state: 'off', account: null }])+ assert.equal(off.value.connectors.find(r => r.id === 'github').state, 'off')assert.equal(mounts[0].disposed, true)assert.deepEqual((await call(ctx, 'state', {})).value.secrets, [])})@@ -129,10 +129,11 @@ test('a failed MCP connection shows the error without the token, and Try again mt.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })const token = fresh()const result = await call(ctx, 'connector-connect', { id: 'github', token })- const [github] = result.value+ const github = result.value.connectors.find(r => r.id === 'github')assert.equal(github.state, 'error')assert.ok(!github.error.includes(token), github.error)- assert.match(github.error, /\[secret:GITHUB_TOKEN\]/)+ // The mount authenticates to the gateway with a nonce, so no secret is in the error.+ assert.match(github.error, /refused/)await call(ctx, 'connector-retry', { id: 'github' })assert.equal(mounts.length, 2)})@@ -147,16 +148,18 @@ test('deleting GITHUB_TOKEN on the Secrets page unmounts GitHub', async (t) => {await call(ctx, 'secret-delete', { name: 'GITHUB_TOKEN' })const state = await call(ctx, 'state', {})assert.equal(mounts[0].disposed, true)- assert.equal(state.value.connectors[0].state, 'off')+ assert.equal(state.value.connectors.connectors.find(r => r.id === 'github').state, 'off')})-test('github: false hides the connector', async (t) => {+test('github: false hides only the GitHub connector', async (t) => {const home = teamHome()const ctx = fakeContext()capture(ctx)apply(ctx, { home, github: false })t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })- assert.deepEqual((await call(ctx, 'state', {})).value.connectors, [])+ const rows = (await call(ctx, 'state', {})).value.connectors.connectors+ assert.equal(rows.find(row => row.id === 'github'), undefined)+ assert.ok(rows.length > 0)})test('a GitHub address without https refuses to send the token', async (t) => {diff --git a/ds-bot/test/install.test.js b/ds-bot/test/install.test.jsindex fbdbba29..3b75c35c 100644--- a/ds-bot/test/install.test.js+++ b/ds-bot/test/install.test.js@@ -54,6 +54,7 @@ test('apply registers listeners and effects in a fixed order', (t) => {'on agent/pre-step (prepend)','on tools/execute','effect ds-bot: scoped team tools',+ 'on tools/change','tools guard','on agent/created','on system-prompt/assemble',@@ -85,6 +86,7 @@ test('apply registers listeners and effects in a fixed order', (t) => {'on tools/execute','on llm/stream','effect ds-bot: load secrets',+ 'on tools/change','effect ds-bot: connectors','on agent/created','effect ds-bot: capabilities',