<div align="center">

# 👥 dsh-background-agents
- **1024 商店渠道**：先 `npm i -g dsh1024`，再 `dsh1024 plugin --profile web add dsh-background-agents`（计入 [deepseek1024.com](https://deepseek1024.com) 安装排行）。

**为 DeepSeek Harness 提供可交互的长会话后台代理，以及持久化的多代理团队房间 —— 启动一个持久的子代理，它一边持续工作，你一边继续对话。**

*跨会话操控实时对话并协调一个团队；一切都通过 harness 自身的存储跨重启存活。*

[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
[![Gitee](https://img.shields.io/badge/Gitee-mirror-c71d23?logo=gitee)](https://gitee.com/perrylink/dsh-background-agents)
[![DSH plugin](https://img.shields.io/badge/dsh--plugin-✅-green)](https://github.com/topics/dsh-plugin)
[![dsh-doctor](https://raw.githubusercontent.com/PerryLink/dsh-plugin-doctor/main/badges/PerryLink__dsh-background-agents.svg)](https://github.com/PerryLink/dsh-plugin-doctor#verified-徽章)
[![DSH Market](https://raw.githubusercontent.com/2BingLing/dsh-market/master/assets/readme/badge-listed-zh.svg)](https://dsh.market/)
[![Node](https://img.shields.io/badge/node-%5E22.19%20%7C%7C%20%3E%3D24-brightgreen.svg)](#)
[![CI](https://img.shields.io/github/actions/workflow/status/PerryLink/dsh-background-agents/ci.yml?branch=main&label=CI)](https://github.com/PerryLink/dsh-background-agents/actions)
[![Version](https://img.shields.io/github/v/tag/PerryLink/dsh-background-agents?label=version)](https://github.com/PerryLink/dsh-background-agents/releases)
[![npm version](https://img.shields.io/npm/v/dsh-background-agents)](https://www.npmjs.com/package/dsh-background-agents)
[![npm downloads](https://img.shields.io/npm/dm/dsh-background-agents)](https://www.npmjs.com/package/dsh-background-agents)
[![dshfind](https://dshfind.com/api/badge/PerryLink/dsh-background-agents?metric=downloads&lang=zh)](https://dshfind.com/zh/plugins/PerryLink/dsh-background-agents?ref=badge)

[English](README.md) · [简体中文](README-zh.md) · [Español](README-es.md) · [Português](README-pt.md) · [हिन्दी](README-hi.md)

</div>

---


<!-- star-cta -->
## ⭐ 如果它帮到了你

这个插件是 [DSH 插件家族](https://github.com/PerryLink)的一员（40+ 个，全部 Apache-2.0）。如果你在用，**给个 star** —— 它不会解锁任何功能，但会让下一个人在搜索里更容易找到它。

*English:* part of a 40+ plugin family for DeepSeek Harness. If it is useful, **a star helps the next person find it** — nothing is gated behind it.
## 兼容性

宿主 `0.1.2-alpha.2` 及以后对会话事件词汇表采取失败即拒读策略，本插件在这些宿主上不再写入其仅日志事实事件（`background-agents/fact`、`team-room/fact`）：事实改走 logger/面板通道，投影退化为空折叠。更早的 rc 线（截至 `0.1.1-rc.2`）保留 ignorable 标记机制。客户端半面现已使用现行客户端包（`dsh-api-session-controller`、`dsh-client-web`）与现行 subagent 远端（`interruptByParent`、带客户端铸造 `requestId` 的 `prompt`；旧 `history` RPC 已删除——结果窥视改读子会话的 `conversation` 投影）。
0.1.2-rc.1（2026-09-04 已适配）：会话信封保留 ignorable 字段但仅用于存量日志读取兼容——Session.append 仍无法盖章（第三参数是 SurfaceIntent，仅用于表面事件类型，从不接受选项包），事实门行为不变。
0.1.3-alpha.1（2026-09-06 已适配）：CI 宿主钉号移至 master checkout（`d347e7039`）——session-persistence 服务的句柄 seam（`open → read → close`）。已发布的 0.1.2-rc.1 运行时早于 open()，bg_result 冷读会特性探测该 seam 并回退到 load()——两条线上行为一致。2026-09-06 已对照 dsh-v0.1.7-alpha.1 master checkout 核验（全门禁链 + profile 安装冒烟测试）。
0.1.5-alpha.1（2026-09-09 已适配）：`SessionHandleReadResult` 现返回 `{ eventState, events }`，因此 bg_result 冷读的句柄 seam 解构 `.events`（已发布线的 `load()` 回退臂不变）。CI 宿主钉号移至公开 tag commit `5dda764ed3aa`（本地 checkout 领先 13 个 infra commit，公开 CI 拉不到），compat 探针改装 alpha 线。peer 范围放宽为 `>=0.1.2-rc.1 <0.2.0 || >=0.1.5-alpha.1 <0.2.0`（prerelease-tuple 规则：单臂不匹配 `0.1.5-alpha.1`），devDeps 钉 `0.1.5-alpha.1`。2026-09-09 已对照 `dsh-v0.1.7-alpha.1` 核验（全门禁链）。此前的 `0.1.3-alpha.1` 宣称已作废：该预发布版本落在两条 peer 臂之外。
0.1.5-rc.1（2026-09-10 已适配）：依赖钉号移至已发布的 0.1.5-rc.1 线；无 seam 变更影响本插件行为。
0.1.5-rc.2（2026-09-11 已适配）：依赖钉号移至已发布的 0.1.5-rc.2 线；无 seam 变更影响本插件行为。
0.1.6-alpha.2（2026-09-18 已适配）：客户端会话服务移除了子代理导航调用，因此该动作现改为明确报告「导航归会话头部所有」（`ui-subagent` 的 lineage 座位），不再静默失败；房间面板的当前会话改由主视图保留计数推导（`retainedBy.mainView`），因为 `SessionListState.current` 已删除。`agent/created` 追赶监听器在自有 2 秒上限内同步返回，不可读的子会话日志改报 `unavailable` 而非空文本。本线上由会话日志事实通道供给的 dashboard 指标**仍不可用**（非表面事实事件仍无法盖上忽略标记）——持久房间表与面板投影值才是记录。2026-09-18 已核验（两把 typecheck 尺子 + 全量测试）；浏览器可见部分**尚未**实机验证。
0.1.7-alpha.1（2026-09-22 已适配）：宿主完成了「生产者自有的消息归属」迁移——通配的 `{ kind: 'plugin', plugin }` 来源已在类型映射与物理行准入两处同时退役——因此本插件注入的每条通知现在都携带自己的 `kind: 'dsh-background-agents'`（通过模块增强声明）；投影仍会从旧日志中读取 `'plugin'` 来源的通知。工具结果改为 V4 一等 `role: 'tool'` 消息（`toolCallId`/`content`/`isError` 位于顶层，不再有 `{ type: 'tool-result' }` 包裹块）；`listChildren` 恢复为仅含身份的 `SubagentCatalogEntry` 行——没有 `kind` 判别字段、没有诊断行、没有 `activity`——因此每个直接列举的调用点都改为按 `mode === 'continuable'` 分类。客户端方面，`IconBranchOutline16` 更名为 `IconBranchOutlineRegular`，`ISessions.refreshSubagents` 更名为 `refreshProjections(sessionId)`。2026-09-22 已核验（两把 typecheck 尺子 + 全量测试 + build + 产物校验）；浏览器可见部分**尚未**实机验证。

| 方面 | 状态 |
|---|---|
| Harness | DeepSeek Harness `dsh-v0.2.1-alpha.1`（GitHub tag，2026-09-24 已核验；dev 钉号 `0.1.7-rc.2`，peer 依赖 `>=0.1.2-rc.1 <0.2.0 \|\| >=0.1.5-alpha.1 <0.2.0 \|\| >=0.1.6-0 <0.2.0 \|\| >=0.1.7-0 <0.2.0`） |
| Node | `^22.19.0 \|\| >=24.0.0` |
| 平台 | 全部（宿主工具；可选 Web 侧栏面板与团队房间，依赖存储域能力） |
| 模型 | 任意（子代理继承父代理的路由；`childProvider`/`childModel` 可覆盖） |

## 你能获得什么

`dsh-background-agents` 把 DSH 即发即弃的后台 *作业* 升级为两个协同的界面：

1. **五个操控工具** —— `background_agent` 在官方子代理接缝上启动一个持久的、可续聊的子代理（可选 `tool_filter` —— 只移除工具、绝不授予新工具；`persona`；`max_depth`；`childProvider`/`childModel` 路由）。`bg_message` 投递后续轮次；`bg_list` 报告状态（或用 `parentId`/`depth` 报告后代树）；`bg_result` 读取最新的结果文本（回退到推理内容时标记 `textSource: 'reasoning'`）；`bg_stop` 请求中断。
2. **进度与归档** —— `autoReport` 在每个子代理轮次之后注入一条节流的进度行；`reportDelivery: wakeup` 会在父会话空闲时启动一个父轮次。空闲清扫会把安静的代理归档，`bg_message` 再把它们唤醒（`autoArchive: false` 则改为让安静的监视者暂停驻留）。
3. **仪表盘投影 + Web 面板** —— `backgroundAgents` 会话投影把父日志折叠成行；侧栏面板显示实时状态、跳转、消息、停止与结果预览。一切都从持久日志重建 —— 无需独立数据库。
4. **团队房间（v0.5.0+）** —— `/room` 命令族加上八个 `room_*` 工具构建持久化的多代理房间：成员（各自是一个独立会话）、消息总线（定向/广播）、共享任务板与共享时间线 —— 存储在 `team_rooms` 存储域（SQLite 或 JSONL），并在 DSH 重启后恢复。跨成员的任务交接通过官方审批接缝进行路由。

## 快速开始

```sh
# 1. 将 bundle 安装到你的 profile
dsh plugin --profile web add "github:PerryLink/dsh-background-agents#main"

# 或从 npm 安装（已发布版本）
dsh plugin --profile web add dsh-background-agents

# 2. 重启并验证该行
dsh --profile web --dump-config | grep -A4 'id: background-agents'
```

bundle 补丁携带插件行；`provider` 为必填。该仓库提交了它的构建产物（`lib/`），因此 git 安装无需构建步骤。该插件需要子代理脊柱已挂载（任何基于 `@deepseek-ai/dsh-base` 构建的 profile 都具备）。团队房间在存储域被组合的地方挂载（`@deepseek-ai/dsh-storage-domain`）；五个 `bg_*` 工具没有它也能工作。

然后，在任意会话中，直接让模型去做 —— 或者直接调用这些工具：

```
background_agent "watch the repo for test failures and keep me posted" (label: test-watch)
bg_list
bg_message <agentId> "also check the snapshot tests now"
bg_stop <agentId>
```

## 安装与卸载

- **git 渠道**（最新 `main`）：`dsh plugin --profile web add "github:PerryLink/dsh-background-agents#main"` —— 已提交 `lib/`，无需 `prepare` 或 `allowBuilds` 步骤。
- **npm 渠道**（已发布版本）：`dsh plugin --profile web add dsh-background-agents`。
- **tarball 渠道**：在本仓库执行 `pnpm pack`，然后 `dsh plugin --profile web add ./dsh-background-agents-<version>.tgz`。
- **卸载**：`dsh plugin --profile web remove dsh-background-agents`（或从 profile 补丁中删除该行）。

## 配置

每个可调项都是经过校验的 Schemastery `Config` 字段 —— 在 cordis.yml 中修改，绝不在代码中修改。仅 `provider` 为必填。

| 键 | 默认值 | 含义 |
|---|---|---|
| `provider` | *(必填)* | 用于可续聊启动（`spawn`）的 `ctx.subagents` provider 名称 |
| `autoReport` | `true` | 每个子代理轮次后在父会话中注入一条进度行 |
| `reportDelivery` | `quiet` | `quiet` 将该行追加到下一次模型请求；`wakeup` 在父会话空闲时启动一个父轮次 |
| `reportThrottleMs` | `15000` | 同一子代理两次进度注入之间的最小间隔 |
| `reportSummaryMaxChars` | `300` | 注入进度行文本的硬上限（以省略号截断） |
| `resultMaxChars` | `4000` | `bg_result` 文本的硬上限（以省略号截断，标记 `truncated`） |
| `maxBackgroundAgents` | `4` | 每个父会话未归档后台代理的硬上限 |
| `autoArchive` | `true` | 空闲归档开关；为 `false` 时清扫器绝不归档安静的代理 |
| `idleTimeoutMinutes` | `120` | 安静的代理被归档前的空闲窗口（`>= 1`） |
| `idleSweepIntervalMs` | `60000` | 归档清扫周期 |
| `maxLabelChars` | `120` | 显示标签上限（以省略号截断） |
| `childProvider` | *(继承)* | 子代理模型请求的 provider 路由 |
| `childModel` | *(继承)* | 子代理模型请求的模型 id |
| `maxChildDepth` | *(无)* | 某次启动的 `max_depth` 参数的配置上限 |
| `allowedChildTools` | *(无)* | `tool_filter` 名称的允许列表；为空/缺失 = 无限制 |
| `maxRooms` | `16` | 整个 profile 内团队房间的硬上限 |
| `maxMembersPerRoom` | `8` | 每个房间成员的硬上限 |
| `maxRoomsPerMember` | `4` | 一个成员会话可加入的房间数上限 |
| `busRetention` | `200` | 每个房间保留的总线消息数 |
| `timelineRetention` | `500` | 每个房间保留的时间线事件数 |
| `taskRetention` | `50` | 每个房间保留的已完成任务数 |
| `maxMessageChars` | `4000` | 单条房间消息文本的硬上限（超限直接拒绝，绝不截断） |
| `injectRoomBrief` | `true` | 向成员会话注入简短房间简介（加入 + 恢复时） |
| `roomOpenTimeoutMs` | `15000` | `team_rooms` 存储域打开的最长等待时间；超时后所有房间操作以 `store-unavailable` 明确失败，而不是永久挂起 |
| `allowUnmarkedFacts` | `false` | 强制在丢弃 `ignorable` 标记的宿主上写入事实事件（危险：未标记事件会让会话在其他宿主上无法恢复）；默认自动探测并跳过 |
| `observability` | `true` | 每个 agent 的成本/状态可观测开关：每个子回合采集一条 `metrics` 事实（token、回合耗时、错误标志），聚合进每行的 `metrics` 汇总供成本面板使用；设为 `false` 关闭采集（面板将指标显示为不可用） |
| `inbound.enabled` | `false` | 开启面向外部代理运行时（OpenAI Agents SDK / CrewAI）的 stdio JSON-RPC 入站桥接；默认关闭（fail-closed） |
| `inbound.command` | *(无)* | 外部运行时启动命令；开启且存在时插件会 spawn 它并监听换行分隔的 JSON-RPC 通知；缺失/无法 spawn = 桥接保持休眠（记日志） |

## 工具与界面

| 界面 | 类型 | 说明 |
|---|---|---|
| `background_agent` | 工具 | 启动一个持久的、可续聊的子代理（label、`tool_filter`、`persona`、`max_depth`） |
| `bg_message` | 工具 | 按 agent id 向子代理投递后续轮次 |
| `bg_list` | 工具 | 你的代理的状态（或用 `recursive: true` 查看后代树） |
| `bg_result` | 工具 | 读取子代理最新的助手输出文本 |
| `bg_stop` | 工具 | 请求中断当前轮次 |
| `/room` | 命令 | `create\|join\|leave\|list\|send\|tasks\|task add\|assign\|claim\|done\|delete` |
| `room_list_rooms` / `room_post` / `room_read` | 工具 | 消息总线：名册、发帖（广播/定向）、读取历史 |
| `room_list_tasks` / `room_create_task` / `room_claim_task` | 工具 | 共享任务板 |
| `room_transfer_task` / `room_complete_task` | 工具 | 交接（审批门控）与完成 |
| `backgroundAgents` 投影 | 会话投影 | 由父日志折叠出的仪表盘行 |
| `teamRoom` 投影 | 会话投影 | 由 `team-room/fact` 事件折叠出的共享时间线 |
| Web 侧栏面板 | 客户端 | 实时状态、跳转、消息、停止、结果预览 |

## 工作原理 —— 以及它为何能在重启后存活

一切都运行在官方子代理接缝之上：`startContinuable`、`followup`、`interrupt`、`listChildren` —— 该插件不执行任何自己的生命周期路由，从不接触另一个会话的 `Agent`，也从不杀死进程树（停止 = *请求中断*，清理工作属于延续管理器）。

该插件通过**一个结构化通道和一个模型可见通道**写入每一个事实：

- **`background-agents/fact` 结构化事实事件** —— 即注册 / 消息 / 停止 / 进度 / 已归档等事实，以仅日志记录的形式追加到父日志，并带上信封的 `ignorable: true` 标记；不认识该类型的读取器会跳过这些记录，而不是拒绝读取日志。`Session.append` 早于该标记的宿主（迄今发布的所有 rc 版本，至 `0.1.0-rc.8`，`0.1.1-rc` 线至 rc.2，以及 `0.1.2-rc` 线（仅保留信封字段用于存量日志读取兼容，仍无法盖标记）—— 任何发布版都还未盖标记，未标记会话在更严格的构建上无法恢复）会在首次追加前被探测出来（peer 版本预检 + 返回信封探测），事实追加被跳过并发出一次性警告 —— 持久存储、通知与工具照常工作，投影降级为空事实折叠。
- **`tool/result` 回放元数据** —— 在结构化通道出现之前写入日志的相同事实（仅当某行没有结构化来源时才折叠）。
- **注入的 `user/message` 通知**（模型可见），来源为 `{ kind: 'dsh-background-agents', form: 'notice' }` —— 即节流的进度行与归档通知（规范前缀 `[background-agent <id>] …`）。
- **官方的 `subagent-settled` 通知** —— 子代理持久化的 "settled"（已结束）事实。
- 团队房间遵循同样的纪律：每一条投递的房间消息都是成员自身日志中持久化的 `user/message`，共享时间线则以仅日志的 `team-room/fact` 事件镜像到 `team_rooms` 存储域。

`backgroundAgents` 投影折叠结构化通道并保留旧有的折叠结果；仪表盘值与 `bg_list` 事实在每次重新打开时重建，无需解析人类可读的通知文本。当目录本身不可用时，`bg_list` 会返回一个明确的 **`unrecoverable`** 标记 —— 它绝不凭空捏造一个空列表。

## 与内置子代理工具的关系

harness 核心自带它自己的子代理工具（`subagent`、`send_message`、`interrupt_agent`，以及子端的 `report` 工具）。本插件的 `bg_*` 工具是它们的**会话级同伴**；两者可以一起挂载：

| 内置工具 | 本插件 | 差异 |
|---|---|---|
| `subagent` (`backgroundMode: 'continuable'`) | `background_agent` | 相同的 `startContinuable` 接缝；本插件额外提供每个子代理的 tool_filter/persona/max_depth 校验以及每会话上限 |
| `send_message` | `bg_message` | 相同的投递语义；`bg_message` 面向本会话的后台代理，并维护投影事实 |
| `interrupt_agent` | `bg_stop` | 相同的中断语义；`bg_stop` 还会记录一条结构化的停止事实 |
| 子端 `report` 工具 | autoReport | 内置工具由子模型自己调用；本插件在**每个子代理轮次之后自动**注入节流的进度 |

核心工具缺少的是：`bg_list`、`bg_result`、空闲归档，以及按父会话折叠的面板投影。

不在范围内：定时触发（调度接缝已存在）、跨机器/远程代理，以及对官方子代理激活契约的任何改动。

## 这不是本插件

| 项目 | 它的作用 | 边界 |
|---|---|---|
| [titanwings/dsh-automation](https://github.com/titanwings/dsh-automation) | 在新代理会话中定时执行编码任务 | 它负责任务**何时**运行（调度）。本插件负责对单个长会话的**交互式操控** —— 没有调度接缝，没有 cron。 |
| [vlln/dsh-task-status](https://github.com/vlln/dsh-task-status) | 后台 *作业* 的状态栏（进度 + 输出尾部） | 它**显示**工具级的作业。本插件创建并操控**代理会话**；它的仪表盘只是其中的一个面板，而非产品本身。 |
| [YYTbit/dsh-plugin-agent-dashboard](https://github.com/YYTbit/dsh-plugin-agent-dashboard) | 多代理仪表盘技能 | 面向展示。本插件的行是**可操作的**：跳转进子会话、发送消息、停止 —— 全都通过官方控制平面。 |

## 权限与数据

- **权限**：workshop 清单声明 `session:append`、`subagent:spawn` 与 `tools:register`。
- **数据**：团队房间位于 `team_rooms` 存储域（SQLite 或 JSONL —— 零额外服务）；后台代理事实随父会话日志。无独立数据库，无网络。
- **会话日志**：`background-agents/fact` 与 `team-room/fact` 事件在支持标记的宿主上以信封的 `ignorable: true` 标记追加（早于该标记的宿主会被探测出来，事实追加被跳过 —— 见 `allowUnmarkedFacts`）；模型可见的进度行与房间投递是真实的 `user/message` 记录。

## 安全边界

- **仅使用官方接缝。** 启动、消息与停止都是对 `startContinuable` / `followup` / `interrupt` 的薄封装；停止是请求中断，绝不杀死进程。
- **`tool_filter` 只会限制。** 它从子代理的视野中移除工具 —— 绝不授予新工具；名称会按 `allowedChildTools` 进行校验。
- **审批门控的交接。** `room_transfer_task` 通过官方审批接缝路由，当没有 answerer 授权时以失败关闭。
- **模型可见 ⟺ 已落盘。** 每一条投递的房间消息都是成员自身日志中持久化的 `user/message`；共享时间线以仅日志的 `team-room/fact` 事件镜像。
- **无调度，无跨机器代理。** 子代理是该部署的进程内可续聊会话。

## 跨生态入站（P2）

外部代理运行时 —— OpenAI Agents SDK、CrewAI 等 —— 可通过一个极简的 **stdio 上换行分隔的 JSON-RPC 2.0 桥接** 发布到团队房间。这是 JSON-RPC 直连最小集，不是官方 ACP wire 协议：完整的 ACP 兼容需等待上游 seam。

用两个 Config 字段开启，并把 `inbound.command` 指向一个在 stdout 上每行输出一条 JSON 通知的启动器：

```yaml
# cordis.yml（插件行）
inbound:
  enabled: true
  command: "python external_runtime.py --room <room-id>"
```

运行时发出三种通知；`method` 是事件名，`params.name` 是外部代理的显示名：

```json
{"jsonrpc":"2.0","method":"agent_started","params":{"name":"researcher","room":"<room-id>","traceId":"t-1"}}
{"jsonrpc":"2.0","method":"agent_message","params":{"name":"researcher","room":"<room-id>","traceId":"t-1","message":"found the failing test"}}
{"jsonrpc":"2.0","method":"agent_finished","params":{"name":"researcher","room":"<room-id>","traceId":"t-1","status":"ok","usage":{"inputTokens":100,"outputTokens":40}}}
```

三者分别映射到房间既有界面：`agent_started` 在任务板开一张卡，`agent_message` 发到消息总线，`agent_finished` 完成该卡并发布结果。无效消息 fail-closed —— 丢弃并回写一条 JSON-RPC error。外部运行时不是 DSH 会话，因此由房间 owner 成员会话代发；无 owner 成员的房间会丢弃事件。启动/停止都由插件 fiber 通过 disposer 持有；无法 spawn 的 `inbound.command` 降级为一条日志警告（桥接保持休眠，其余不受影响）。

## 与其他 DSH 插件的互操作

已对照 **DSH `0.2.0-rc.2`**（本 README 面向的运行时）与 2026-10-05 实测的高星插件集验证。

本插件**不干扰**其他插件，包括广泛安装的高星插件：

- **无工具名冲突。** 所有工具都带命名空间（`background_agent`、`bg_*`、`room_*`），不占用任何已被内置工具或其他插件持有的裸名，因此从不遮蔽任何东西 —— 而 `dsh-routing-suite`（7000★）正是用遮蔽机制改写了内置的 `get_goal` / `create_goal` / `update_goal`。
- **无服务键冲突。** 只提供 `roomHub` 一个服务；它既不是内置 seam，也没有被任何已调研的高星插件提供。（`dsh-routing-suite` 提供 `shell`，与内置 `@deepseek-ai/dsh-shell` 同名双提供；本插件没有这个问题。）
- **无 slot 冲突。** 不注册任何与高星插件重合的客户端 `slot` key，因此不参与 `main`、`conversation.chat.node`、`plugins.bundle.config`、`tool.call.toolview` 这些 `shadows-shipped-ui` 座位的争抢（争抢者是 `dsh-agent-teams`、`dsh-context`、`dsh-market`、`modlens`）。
- **无 HTTP 路由冲突。** 不注册任何 `webServer` 前缀。（`DSH-better-sidebar` 3993★ 的 patch 注释明确记录：`/sidebar/api` 这类前缀重复会导致**整个插件树启动失败**。）
- **无 patch 层冲突。** 组合包 patch 只 `insert` 自己那一行（`id: background-agents`），从不覆写内置行的 `config` —— 覆写是整段对象替换，`dsh-purge` 与 `dsh-infinite-gen-4` 正是因此在 `system-prompt` 上互相抹掉。
- **无全局改写。** 不改原型、不改写 `process.env`、不替换全局 fetch dispatcher。

**共享事件监听器在构造上就不互相干扰。** 本插件监听了六个高星插件同样使用的事件 —— `agent/pre-step`、`agent/request`、`tools/pre-execute`、`tools/post-execute`、`llm/stream`、`system-prompt/assemble` —— 全部用 `ctx.on()` 注册，即 Cordis 的**广播**语义：每个监听器都会运行，任何一个都无法饿死其他监听器。其中顺序敏感的几个（`agent/pre-step`、`agent/request`、`tools/*` 都是 waterfall）**本插件的每个监听器都通过 `next()` 委托**，因此链条绝不会被短路；改写作用在 `next()` 产出的值上，而不是用它顶替返回。即使某个被调研的同侪确实短路（例如 `dsh-agent-teams` 1923★ 在 `agent/request` 上以 `throw` 直接返回、不调 `next()`），共存依然安全。

运行时已验证：`tests/room-half-guard.spec.ts` 驱动构建产物，断言当同级插件已持有 `roomHub` 时房间半会主动让位，且**没有服务键冲突、没有工具重名冲突**。

## 已知限制

- 团队房间需要存储域被组合；没有 `@deepseek-ai/dsh-storage-domain` 时，`/room` 命令与 `room_*` 工具会被禁用（五个 `bg_*` 工具仍可加载）。
- `provider` 必须指定一个具备可续聊能力的 provider（`prepareContinuable`）；缺失的 provider 会让 `background_agent` 一直失败，直到它出现。
- `maxBackgroundAgents` 是会话**每一个**可续聊直接子代理共享的预算，包括由内置 `subagent` 工具启动的那些。
- 一次性子代理绝不会被列出或接收消息 —— `bg_list` 只保留可续聊的行。
- 子代理是进程内的：调度接缝负责「何时」，本插件负责操控一场活跃的对话。

## 开发

```sh
pnpm install        # 仅工具链；harness 包针对同级 checkout 解析
pnpm run typecheck  # 严格 TS，node + client 程序
pnpm test           # vitest：单元 + 端到端测试（真实子代理接缝、脚本化 LLM、jsdom 面板）
pnpm run build      # lib/index.js（node 半侧）+ lib/client.js（web 客户端 bundle）
pnpm run gen-aliases  # checkout 移动后重新映射 harness 包路径
```

一个无需密钥的端到端演示通过确定性的脚本化 LLM 驱动一个真实的父会话和一个后台子代理（无需 API key；`dev/` 已被 gitignore —— 请根据你的 checkout 调整路径）：

```powershell
$env:DSH_HOME = 'D:/deepseek-harness/Project/Plugins/dsh-background-agents/dev/dsh-home'
pnpm dsh --profile headless --patch dev/cordis.yml "【父会话】驱动后台 agent 演示"
```

## 主题

`dsh`, `dsh-plugin`, `deepseek-harness`, `subagent`, `background-agent`, `background-agents`, `agent-dashboard`, `conversation-steering`, `team-rooms`, `multi-agent`, `message-bus`, `task-board`, `collaboration`

## 贡献者

- [@PerryLink](https://github.com/PerryLink) —— 创建者与维护者：官方子代理接缝上的后台代理运行时、团队房间枢纽、Web UI 侧栏面板、会话投影、文档、CI/CD 与发布。

## PerryLink DSH Plugin Family

This project is one of the **45 DeepSeek Harness plugins** maintained by [PerryLink](https://github.com/PerryLink). If this one helps you, the others likely will too:

| Plugin | One-liner |
|---|---|
| **[dsh-auto-review](https://github.com/PerryLink/dsh-auto-review)** | Second-model auto-review on the approval chain, fail-closed by default | |
| **[dsh-autotier](https://github.com/PerryLink/dsh-autotier)** | Automatic strong/cheap model-tier routing with deterministic risk guards and a `/tier` command | |
| **[dsh-background-agents](https://github.com/PerryLink/dsh-background-agents)** | Durable background child agents with a Web UI sidebar, messaging and interrupt | |
| **[dsh-budget](https://github.com/PerryLink/dsh-budget)** | Cost governance for DeepSeek Harness: budgets, carbon, and latency in one panel. | |
| **[dsh-catalog](https://github.com/PerryLink/dsh-catalog)** | DSH Desktop Market standard catalog source for the PerryLink family | |
| **[dsh-cert-mcp](https://github.com/PerryLink/dsh-cert-mcp)** | Read-only MCP server exposing the certification registry: grades, snapshots and five-dimension evidence | |
| **[dsh-checkpoint-rewind](https://github.com/PerryLink/dsh-checkpoint-rewind)** | Claude Code /rewind-equivalent: snapshots, session forks, one-shot restore | |
| **[dsh-claude-move](https://github.com/PerryLink/dsh-claude-move)** | Migrate Claude Code sessions, memory, skills and CLAUDE.md into DSH | |
| **[dsh-click](https://github.com/PerryLink/dsh-click)** | Cross-platform native desktop control for DeepSeek Harness — Windows first. | |
| **[dsh-composer-history](https://github.com/PerryLink/dsh-composer-history)** | Terminal-style input history for the web composer: arrows, Ctrl+R search | |
| **[dsh-data-quality](https://github.com/PerryLink/dsh-data-quality)** | Dataset quality checks and citation cross-checks (the optional numeric bridge consumed here) | |
| **[dsh-defend](https://github.com/PerryLink/dsh-defend)** | Prompt-injection, jailbreak, and secret-leak defense for DeepSeek Harness. | |
| **[dsh-doublecheck](https://github.com/PerryLink/dsh-doublecheck)** | Engineering-discipline guard: requirements grill, test gates, adversary review | |
| **[dsh-draw](https://github.com/PerryLink/dsh-draw)** | Unified static-image generation routing for DeepSeek Harness. | |
| **[dsh-fast](https://github.com/PerryLink/dsh-fast)** | Read-only performance diagnostics for DeepSeek Harness. | |
| **[dsh-fund-research](https://github.com/PerryLink/dsh-fund-research)** | Deterministic research reports for Chinese public mutual funds | |
| **[dsh-github](https://github.com/PerryLink/dsh-github)** | GitHub PR/issues integration for DSH, every write gated by approval | |
| **[dsh-industry-research](https://github.com/PerryLink/dsh-industry-research)** | Industry research orchestration that seals its deliverables through this plugin's `ctx.researchReport.assemble` | |
| **[dsh-laya](https://github.com/PerryLink/dsh-laya)** | Laya typed decisions (`noul`/`choice`/`score`) as a first-class Cordis service and model-visible tools | |
| **[dsh-library](https://github.com/PerryLink/dsh-library)** | Local document knowledge base for DeepSeek Harness. | |
| **[dsh-local-ai](https://github.com/PerryLink/dsh-local-ai)** | Local-model (Ollama) integration for DeepSeek Harness. | |
| **[dsh-lsp-actions](https://github.com/PerryLink/dsh-lsp-actions)** | LSP diagnostics, formatting, completion, code actions and rename over language servers | |
| **[dsh-mask](https://github.com/PerryLink/dsh-mask)** | PII masking middleware: anonymize at the model boundary, restore at the display layer | |
| **[dsh-mcp-panel](https://github.com/PerryLink/dsh-mcp-panel)** | Read-only MCP runtime panel: /mcp command + Settings tab with status, tools and errors | |
| **[dsh-memento](https://github.com/PerryLink/dsh-memento)** | Approval-gated cross-session memory: ctx.memory seam + SQLite + memory tool | |
| **[dsh-observe](https://github.com/PerryLink/dsh-observe)** | OpenTelemetry and Langfuse observability exporter for DeepSeek Harness. | |
| **[dsh-output-styles](https://github.com/PerryLink/dsh-output-styles)** | Claude Code outputStyles-equivalent runtime style switching | |
| **[dsh-permission-rules](https://github.com/PerryLink/dsh-permission-rules)** | Claude Code-style declarative allow/deny/ask permission rules with audit | |
| **[dsh-plugin-certification](https://github.com/PerryLink/dsh-plugin-certification)** | Community certification registry with repro-checkable grades and badges | |
| **[dsh-plugin-doctor](https://github.com/PerryLink/dsh-plugin-doctor)** | Zero-dependency static + sandbox smoke detector for DSH plugins | |
| **[dsh-plugin-guide](https://github.com/PerryLink/dsh-plugin-guide)** | Plugin-development knowledge base as an on-demand agent skill | |
| **[dsh-plugin-kit](https://github.com/PerryLink/dsh-plugin-kit)** | Shared zero-runtime-dependency toolkit for the PerryLink DSH plugins | |
| **[dsh-plugin-upgrade](https://github.com/PerryLink/dsh-plugin-upgrade)** | One-package, one-corridor-index plugin upgrade skill: routes a repository to the matching closed corridor card | |
| **[dsh-reach](https://github.com/PerryLink/dsh-reach)** | Multi-channel approval/question bridge: WeChat/Telegram/Feishu, session console | |
| **[dsh-research-report](https://github.com/PerryLink/dsh-research-report)** | Verifiable research-report engine: content-addressed evidence ledger and sealed versions | |
| **[dsh-score](https://github.com/PerryLink/dsh-score)** | Multi-dimensional quality scoring for DeepSeek Harness plugins. | |
| **[dsh-session-pin](https://github.com/PerryLink/dsh-session-pin)** | Pin sessions in the Web sidebar with durable ordering | |
| **[dsh-session-sync](https://github.com/PerryLink/dsh-session-sync)** | Cross-device session sync for DeepSeek Harness — a dedicated git mirror of your session store. | |
| **[dsh-skill-pack-security](https://github.com/PerryLink/dsh-skill-pack-security)** | Security-audit skill pack: secret scan, dependency and supply-chain review | |
| **[dsh-talk](https://github.com/PerryLink/dsh-talk)** | Voice-first session loop for DeepSeek Harness: talk to it, hear it answer. | |
| **[dsh-team-rooms](https://github.com/PerryLink/dsh-team-rooms)** | Cross-session team rooms: shared message bus, task board and timeline | |
| **[dsh-test-drive](https://github.com/PerryLink/dsh-test-drive)** | Isolated install-and-smoke test drives for DeepSeek Harness plugins. | |
| **[dsh-ticktick](https://github.com/PerryLink/dsh-ticktick)** | TickTick/Dida365 task bridge: session-header panel + 11 tools | |
| **[dsh-translate](https://github.com/PerryLink/dsh-translate)** | Vendor parameter translation and deterministic JSON repair for DeepSeek Harness. | |


### 从 DSH Desktop 市场安装

所有 PerryLink 插件均可在 DSH Desktop 内置市场中浏览：**市场 → 来源 → 添加来源 → 粘贴** `https://perrylink-dsh-catalog.perrylink.workers.dev/catalog-source.json` **→ 选中**。安装仍需通过市场的 npm 身份校验与你的确认。

## 许可证

[Apache License 2.0](LICENSE) © 2026 dsh-background-agents contributors
