@zhuifengqug/dsh-ant 0.1.29 → 0.2.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/README.md CHANGED
@@ -6,7 +6,7 @@ DeepSeek Harness 的多智能体团队插件。一句话把当前会话变成队
6
6
 
7
7
  ## 与上游的关系
8
8
 
9
- 本仓库是 [NanmiCoder/dsh-agent-teams](https://github.com/NanmiCoder/dsh-agent-teams) 的分支(fork),基线 `0.1.29`。上游的功能照单全收,本分支只叠加四件事,全部有测试兜底:
9
+ 本仓库是 [NanmiCoder/dsh-agent-teams](https://github.com/NanmiCoder/dsh-agent-teams) 的分支(fork),基线为上游 [0.1.30](./release-notes/v0.1.30.md)(该版适配 Harness `0.2.2-rc.2` 的子代理树契约)。上游的功能照单全收,本分支只叠加四件事,全部有测试兜底:
10
10
 
11
11
  - **中文语言约束**:团队提示词与全部工具参数描述要求队名、成员名、任务标题与描述、计划摘要一律用当前对话语言书写,工具名、id、路径、代码标识符保留原文。
12
12
  - **归档团队永久删除**:归档列表里可以真正删掉一个团队(先精确匹配 id,再绑定归属会话,两击确认),不再只能堆积。
@@ -17,6 +17,12 @@ DeepSeek Harness 的多智能体团队插件。一句话把当前会话变成队
17
17
 
18
18
  ## 安装
19
19
 
20
+ 从 npm 安装(桌面端「插件 → 添加插件」里填版本号即可):
21
+
22
+ ```powershell
23
+ dsh plugin --profile desktop add @zhuifengqug/dsh-ant@0.2.0
24
+ ```
25
+
20
26
  本地开发目录安装(`link:` 指向本仓库):
21
27
 
22
28
  ```powershell
@@ -60,11 +66,11 @@ npx pnpm run build
60
66
  npx pnpm run verify
61
67
  ```
62
68
 
63
- `verify` 串起契约、质量门禁、兼容性、客户端与 fork 自有四处改动的全部用例,末段会校验 `lib/` 与源码一致(`git-artifacts`)。
69
+ `verify` 串起契约、质量门禁、兼容性、客户端与 fork 自有四处改动的全部用例,末段会校验 `lib/` 与源码一致(`git-artifacts`)。只想跑本分支那四件事,用 `npx pnpm run verify:fork`;只跑宿主契约兼容,用 `npx pnpm run verify:harness-contract`。
64
70
 
65
71
  ## 兼容性
66
72
 
67
- 宿主最低版本由 [`compatibility.json`](./compatibility.json) 里最旧的兼容项派生:推荐 `0.2.1-rc.2`,已在 `0.2.2-rc.1`(preview)上验证。当前开发的宿主是 `0.2.2-rc.1`。
73
+ 宿主最低版本由 [`compatibility.json`](./compatibility.json) 里最旧的兼容项派生,推荐宿主仍是 `0.2.1-rc.2`;`0.2.2-rc.1` 与 `0.2.2-rc.2` 属 preview 通道,上游已在该两版上跑过真实宿主矩阵(证据见 [docs/harness-0.2.2-rc.2](./docs/harness-0.2.2-rc.2/README.md))。本分支当前的开发宿主是 `0.2.2-rc.3`:其子代理运行时仍保留 `rootOf` / `prompt` / `startActivation` / `manager.resident` / `deliverToMember` 这套树契约,与 rc.2 一致。
68
74
 
69
75
  ## 许可
70
76
 
@@ -3,6 +3,10 @@
3
3
  "recommendedHost": "0.2.1-rc.2",
4
4
  "previewTag": "next",
5
5
  "supportedHosts": [
6
+ {
7
+ "version": "0.2.2-rc.2",
8
+ "track": "preview"
9
+ },
6
10
  {
7
11
  "version": "0.2.2-rc.1",
8
12
  "track": "preview"
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "schema": 1,
3
- "source": "47365906bf4270c718af7382a1728a969792ec827e94216f669c79e3be4714a5",
4
- "output": "e4b72213fe421e350cd599aa0d29e20f1d35f7597a3d9bc46709d3db1c5dc6fa"
3
+ "source": "f05cb43946428b050cedf1241a5812599d7a4f6b4a7bb65de6419bbc191bd982",
4
+ "output": "1b4fd9e68a595d920452181d53a35a9311e45bc6601b0494f7acb941b2db4130"
5
5
  }
@@ -13,6 +13,45 @@ const hostPromptQueue = Symbol.for('dsh.subagent.queuePrompt');
13
13
  // 0.1.5 keeps queueHostSubagentPrompt but replaces its symbol with this
14
14
  // delivery-mode-aware implementation (packages/subagent/subagent/src/internal.ts).
15
15
  const hostPromptDeliver = Symbol.for('dsh.subagent.deliverPrompt');
16
+ const treeWork = new WeakMap();
17
+ function treeBoundary(runtime) {
18
+ const tree = runtime;
19
+ if (typeof tree.rootOf !== 'function' || typeof tree.prompt !== 'function')
20
+ return undefined;
21
+ if (typeof tree.manager?.deliverToMember !== 'function' || typeof tree.manager.dispose !== 'function'
22
+ || !(tree.manager.resident instanceof Map))
23
+ return unsupported('missing audited tree delivery manager');
24
+ return tree;
25
+ }
26
+ /** Track exact branch work before its first await so a targeted stop can join it. */
27
+ function trackTreeWork(manager, root, branch, signal, operation) {
28
+ const pending = treeWork.get(manager) ?? new Set();
29
+ treeWork.set(manager, pending);
30
+ const controller = new AbortController();
31
+ let finish;
32
+ const settled = new Promise(resolve => { finish = resolve; });
33
+ const work = { root, branch, controller, settled };
34
+ pending.add(work);
35
+ try {
36
+ return operation(AbortSignal.any([signal, controller.signal])).finally(() => { pending.delete(work); finish(); });
37
+ }
38
+ catch (error) {
39
+ pending.delete(work);
40
+ finish();
41
+ throw error;
42
+ }
43
+ }
44
+ function deliverTreePrompt(runtime, tree, parent, childId, content, source, signal, delivery) {
45
+ const root = tree.rootOf.call(runtime, parent);
46
+ return tree.manager.deliverToMember.call(tree.manager, root, childId, content, {
47
+ source, signal, delivery,
48
+ // Recheck the exact live caller immediately before native inbox acceptance.
49
+ authorize: () => {
50
+ if (tree.rootOf.call(runtime, parent) !== root)
51
+ throw new SubagentError('AgentTeams caller left its subagent tree', 'UNAUTHORIZED');
52
+ },
53
+ });
54
+ }
16
55
  export function usesManagedActivations(runtime) {
17
56
  return typeof runtime.startActivation === 'function';
18
57
  }
@@ -20,7 +59,9 @@ export async function startMember(runtime, spec) {
20
59
  const host = runtime;
21
60
  if (typeof host.startActivation === 'function') {
22
61
  const { persona: _persona, toolFilter: _filter, ...request } = spec.request;
23
- const activation = await host.startActivation.call(runtime, { ...spec, request, delivery: 'parent' });
62
+ const activation = await Reflect.apply(host.startActivation, runtime, [treeBoundary(runtime) === undefined
63
+ ? { ...spec, request, delivery: 'parent' }
64
+ : { provider: spec.provider, label: spec.label, ...request, signal: spec.signal, delivery: 'parent' }]);
24
65
  // Preserve native settlement as the missing-report/error fallback on both
25
66
  // fresh and resumed activations. mailbox.ts deduplicates successful reports.
26
67
  void activation.result.catch(() => undefined);
@@ -33,6 +74,7 @@ export async function startMember(runtime, spec) {
33
74
  /** Wrap every available creation API, restoring only this plugin's own methods. */
34
75
  export function guardSubagentCreation(ctx, check) {
35
76
  const runtime = ctx.subagents;
77
+ const tree = treeBoundary(ctx.subagents);
36
78
  ctx.effect(() => {
37
79
  const disposers = [];
38
80
  for (const key of ['start', 'startContinuable', 'startActivation']) {
@@ -41,8 +83,16 @@ export function guardSubagentCreation(ctx, check) {
41
83
  continue;
42
84
  const descriptor = Object.getOwnPropertyDescriptor(runtime, key);
43
85
  const guarded = async (...args) => {
44
- const request = key === 'start' ? args[1] : args[0].request;
45
- check(request.parent);
86
+ const request = key === 'start' ? args[1] : key === 'startActivation' && tree !== undefined
87
+ ? args[0] : args[0].request;
88
+ const parent = request.parent;
89
+ check(parent);
90
+ if (key === 'startActivation' && tree !== undefined) {
91
+ const spec = args[0];
92
+ const root = tree.rootOf.call(ctx.subagents, parent);
93
+ const branch = [parent.id, ...tree.manager.resident.get(parent.id)?.ancestors ?? []];
94
+ return trackTreeWork(tree.manager, root, branch, spec.signal, signal => Reflect.apply(original, ctx.subagents, [{ ...spec, signal }]));
95
+ }
46
96
  return Reflect.apply(original, ctx.subagents, args);
47
97
  };
48
98
  Object.defineProperty(runtime, key, { value: guarded, writable: true, configurable: true });
@@ -164,6 +214,15 @@ export function outputLimitTurn(event) {
164
214
  return record.data.turn;
165
215
  }
166
216
  }
217
+ /** rc.2 summaries use tree names; the new structured reason owns the outcome. */
218
+ export function successfulSubagentSettlement(source) {
219
+ if (source?.kind !== 'subagent-settled')
220
+ return false;
221
+ const current = source;
222
+ return current.stopReason === undefined
223
+ ? source.summary === `Background subagent ${source.senderSessionId} finished and will do no further work unless you send it more.`
224
+ : current.stopReason === 'completed';
225
+ }
167
226
  /** Install before the first request, including cold resume, with HMR cleanup. */
168
227
  export function installContinuableMemberSetup(ctx, setup) {
169
228
  const runtime = boundary(ctx.subagents);
@@ -178,7 +237,7 @@ export function installContinuableMemberSetup(ctx, setup) {
178
237
  });
179
238
  return;
180
239
  }
181
- if ((typeof runtime[hostPromptQueue] !== 'function' && typeof runtime[hostPromptDeliver] !== 'function') || typeof runtime.sendMessage !== 'function') {
240
+ if (treeBoundary(ctx.subagents) === undefined && ((typeof runtime[hostPromptQueue] !== 'function' && typeof runtime[hostPromptDeliver] !== 'function') || typeof runtime.sendMessage !== 'function')) {
182
241
  return unsupported('missing continuable setup and modern host queue');
183
242
  }
184
243
  const installed = new WeakSet();
@@ -246,6 +305,9 @@ export function installContinuableMemberSetup(ctx, setup) {
246
305
  export async function queueMemberPrompt(runtime, parent, childId, content, signal) {
247
306
  const host = boundary(runtime);
248
307
  const source = agentTeamsSource({ kind: 'agent-teams' }, observedSessionFormatVersion(parent));
308
+ const tree = treeBoundary(runtime);
309
+ if (tree !== undefined)
310
+ return deliverTreePrompt(runtime, tree, parent, childId, content, source, signal, 'queue');
249
311
  if (typeof host.followup === 'function') {
250
312
  return host.followup.call(runtime, parent, childId, content, { source, signal });
251
313
  }
@@ -261,6 +323,9 @@ export async function queueMemberPrompt(runtime, parent, childId, content, signa
261
323
  export async function steerMemberPrompt(runtime, parent, childId, content, signal, live) {
262
324
  const host = boundary(runtime);
263
325
  const source = agentTeamsSource({ kind: 'agent-teams' }, observedSessionFormatVersion(live ?? parent));
326
+ const tree = treeBoundary(runtime);
327
+ if (tree !== undefined)
328
+ return deliverTreePrompt(runtime, tree, parent, childId, content, source, signal, 'steer');
264
329
  const deliver = host[hostPromptDeliver];
265
330
  if (typeof deliver === 'function')
266
331
  return deliver.call(runtime, parent, childId, content, source, signal, 'steer');
@@ -281,6 +346,39 @@ export async function steerMemberPrompt(runtime, parent, childId, content, signa
281
346
  /** Guard all resumable delivery paths, preserving the native service receiver. */
282
347
  export function guardSubagentDelivery(ctx, isRetired) {
283
348
  const runtime = ctx.subagents;
349
+ const tree = treeBoundary(runtime);
350
+ if (tree !== undefined) {
351
+ const manager = tree.manager;
352
+ ctx.effect(() => {
353
+ const original = manager.deliverToMember;
354
+ const descriptor = Object.getOwnPropertyDescriptor(manager, 'deliverToMember');
355
+ let active = true;
356
+ const guarded = async (root, childId, content, options) => {
357
+ if (!active)
358
+ return original.call(manager, root, childId, content, options);
359
+ const branch = [childId, ...manager.resident.get(childId)?.ancestors ?? []];
360
+ return trackTreeWork(manager, root, branch, options.signal, async (signal) => {
361
+ signal.throwIfAborted();
362
+ if (await isRetired(root, childId)) {
363
+ throw new SubagentError(`AgentTeams member "${childId}" was retired and cannot be resumed`, 'NOT_RESUMABLE');
364
+ }
365
+ signal.throwIfAborted();
366
+ return original.call(manager, root, childId, content, { ...options, signal });
367
+ });
368
+ };
369
+ manager.deliverToMember = guarded;
370
+ return () => {
371
+ active = false;
372
+ if (Object.getOwnPropertyDescriptor(manager, 'deliverToMember')?.value !== guarded)
373
+ return;
374
+ if (descriptor === undefined)
375
+ Reflect.deleteProperty(manager, 'deliverToMember');
376
+ else
377
+ Object.defineProperty(manager, 'deliverToMember', descriptor);
378
+ };
379
+ }, 'agent-teams: tree retired member guard');
380
+ return;
381
+ }
284
382
  const host = boundary(runtime);
285
383
  const legacy = host.followup;
286
384
  const queue = host[hostPromptQueue];
@@ -446,6 +544,24 @@ export async function startMemberWithLenientFilter(start, filter, relaxableDeny
446
544
  }
447
545
  /** Targeted recursive cancellation renamed with the unified activation manager. */
448
546
  export async function drainMemberChildren(runtime, parent, ids) {
547
+ const tree = treeBoundary(runtime);
548
+ if (tree !== undefined) {
549
+ const root = tree.rootOf.call(runtime, parent);
550
+ const selected = new Set(ids);
551
+ // The native tree-wide drain also stops unrelated siblings and permanently
552
+ // closes the captain. Join only work in the selected creation branches.
553
+ const pending = [...treeWork.get(tree.manager) ?? []].filter(work => work.root === root && work.branch.some(id => selected.has(id)));
554
+ for (const work of pending)
555
+ work.controller.abort();
556
+ await Promise.all(pending.map(work => work.settled));
557
+ const targets = [...tree.manager.resident.values()].filter(item => item.root === root
558
+ && item.ancestors.includes(parent.id) && (selected.has(item.childId) || item.ancestors.some(id => selected.has(id))));
559
+ const results = await Promise.allSettled(targets.map(item => tree.manager.dispose.call(tree.manager, item)));
560
+ const failures = results.flatMap(result => result.status === 'rejected' ? [result.reason] : []);
561
+ if (failures.length)
562
+ throw new AggregateError(failures, 'AgentTeams member teardown failed');
563
+ return;
564
+ }
449
565
  const host = runtime;
450
566
  const drain = host.drainChildren ?? host.drainContinuableChildren;
451
567
  if (typeof drain !== 'function')
package/lib/mailbox.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { join } from 'node:path';
2
2
  import { acknowledgeMailbox, CAPTAIN_KEY, discardMailboxMessages, findTeamByCaptain, readMailbox, readUnreadMailbox, readTeam, sanitizeKey, withTeamLock } from "./state.js";
3
- import { sessionOwnEvents } from "./harness-compat.js";
3
+ import { sessionOwnEvents, successfulSubagentSettlement } from "./harness-compat.js";
4
4
  import { leadIdentityOfAsync, sessionLeadsTeamAsync } from "./lineage.js";
5
5
  const PREFIX = 'AgentTeams inbox receipt: ';
6
6
  export function isCurrentMail(team, message) {
@@ -80,8 +80,7 @@ export function installMailboxAdmission(ctx, stateDir) {
80
80
  // result. Keep abnormal endings and missing reports as fallback signals.
81
81
  const successfulSettlements = new Set(decision.messages.flatMap(input => {
82
82
  const source = input.source;
83
- return source?.kind === 'subagent-settled'
84
- && source.summary === `Background subagent ${source.senderSessionId} finished and will do no further work unless you send it more.`
83
+ return successfulSubagentSettlement(source)
85
84
  ? [source.senderSessionId] : [];
86
85
  }));
87
86
  const redundantSettlements = new Set();
@@ -168,8 +167,7 @@ export function installMailboxAdmission(ctx, stateDir) {
168
167
  }
169
168
  const admitted = [];
170
169
  for (const { input, receipt, batch } of inputs) {
171
- if (input.source?.kind === 'subagent-settled' && redundantSettlements.has(input.source.senderSessionId)
172
- && input.source.summary === `Background subagent ${input.source.senderSessionId} finished and will do no further work unless you send it more.`)
170
+ if (successfulSubagentSettlement(input.source) && redundantSettlements.has(input.source.senderSessionId))
173
171
  continue;
174
172
  if (receipt === undefined || batch === undefined || batch.failed === true) {
175
173
  admitted.push(input);
@@ -113,6 +113,10 @@ export declare function onAgentReady(ctx: Context, listener: (agent: Agent, veto
113
113
  export declare function sessionOwnEvents(session: Session): readonly SessionEvent[];
114
114
  /** Legacy hosts log each chunk separately; current hosts embed the committed stream. */
115
115
  export declare function outputLimitTurn(event: SessionEvent): number | undefined;
116
+ /** rc.2 summaries use tree names; the new structured reason owns the outcome. */
117
+ export declare function successfulSubagentSettlement(source: MessageSource | undefined): source is Extract<MessageSource, {
118
+ kind: 'subagent-settled';
119
+ }>;
116
120
  /** Install before the first request, including cold resume, with HMR cleanup. */
117
121
  export declare function installContinuableMemberSetup(ctx: Context, setup: Setup): void;
118
122
  /** Queue a distinct host-authored turn; never substitute model-message steer. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhuifengqug/dsh-ant",
3
- "version": "0.1.29",
3
+ "version": "0.2.0",
4
4
  "description": "\u7384\u9a79\uff1aDeepSeek Harness \u7684\u591a\u667a\u80fd\u4f53\u56e2\u961f\u63d2\u4ef6\uff08AgentTeams \u5206\u652f\u7248\uff09\u3002\u4e00\u53e5\u8bdd\u7ec4\u961f\uff0c\u961f\u957f\u6d3e\u6d3b\u3001\u961f\u5458\u5e76\u884c\u3001\u4f9d\u8d56\u81ea\u52a8\u8c03\u5ea6\uff0c\u5168\u4e2d\u6587\u4efb\u52a1\u4e0e\u5168\u4e2d\u6587\u534f\u8bae\u3002",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -0,0 +1,23 @@
1
+ # v0.1.30 — Harness 0.2.2-rc.2 compatibility
2
+
3
+ - Restore plugin activation on Harness `0.2.2-rc.2` after the subagent runtime removed its previous host delivery entry point.
4
+ - Adapt member creation, queued assignments, step-boundary messages and cold recovery to the new subagent tree contract, preserving model selection, reasoning effort and tool restrictions.
5
+ - Stop selected members and their descendants without stopping unrelated siblings or closing the captain's tree. Retired members remain blocked through both model and browser messages.
6
+ - Avoid waking the captain twice after a member has already reported a completed task. Structured stop reasons preserve failure and missing-report notifications.
7
+
8
+ ## 中文
9
+
10
+ - 修复 Harness `0.2.2-rc.2` 升级后插件无法启用的问题。
11
+ - 适配新版子代理的创建、任务排队、消息与冷恢复,保留成员的模型、推理力度和工具范围。
12
+ - 停止成员时清理选定分支及其后代,保留无关队员与队长;已退役成员不能通过模型或网页消息重新启动。
13
+ - 成员已回报完成结果后,不再因新版结算通知重复唤醒队长;失败或缺失回报仍会通知。
14
+
15
+ ## Install
16
+
17
+ In **Plugins → Add plugin**, enter `@nanmicoder/dsh-agent-teams@0.1.30`. For a CLI-managed profile, run:
18
+
19
+ ```sh
20
+ dsh plugin --profile web add --save-exact @nanmicoder/dsh-agent-teams@0.1.30
21
+ ```
22
+
23
+ The recommended host remains Harness `0.2.1-rc.2`. Harness `0.2.2-rc.2` joins the Ubuntu and Windows preview matrix. See the [tested matrix](../compatibility.json) and [migration evidence](../docs/harness-0.2.2-rc.2/README.md).
@@ -0,0 +1,28 @@
1
+ # v0.2.0 — 玄驹:吸收上游 0.1.30,适配 Harness 0.2.2-rc.3
2
+
3
+ ## 中文
4
+
5
+ - 全量吸收上游 0.1.30:适配 Harness `0.2.2-rc.2` 的子代理树契约(`manager.deliverToMember` + `rootOf` + `resident`),修复该版把旧的宿主投递入口拆掉后插件无法启用的问题。
6
+ - 成员创建、任务排队、步边界消息与冷恢复改走树契约,成员模型、推理力度与工具范围保持不变;定向停止只清理选中成员及其后代,退役成员在模型与网页两路都被拦。
7
+ - 成员已回报完成后不再重复唤醒队长:`subagent-settled` 的结构化 `stopReason` 成为结算判据,失败与缺失回报仍会通知。
8
+ - 开发宿主切到 Harness `0.2.2-rc.3`:核验其子代理运行时仍保留 `rootOf` / `prompt` / `startActivation` / `manager.resident` / `deliverToMember` 这套形状,与 rc.2 同构。
9
+ - 本分支四件定制随之上移:中文语言约束(团队提示词与全部工具参数描述)、归档团队永久删除(绑定归属会话 + 两击确认)、无进展滑动窗口标记、质量门禁只重跑失败命令并把验收证据绑定到当前 attempt。
10
+ - 测试:新增上游三条树 ABI 用例(激活 / 退役守卫三路投递 / 定向 drain)与运行期平台用例;`verify:fork` 四套本分支用例照旧复用。
11
+
12
+ ## English
13
+
14
+ - Absorbs upstream 0.1.30 in full: adapts to the Harness `0.2.2-rc.2` subagent tree contract (`manager.deliverToMember` + `rootOf` + `resident`), restoring plugin activation after that release removed the previous host delivery entry point.
15
+ - Member creation, queued assignments, step-boundary messages and cold recovery now flow through the tree contract while model, reasoning effort and tool restrictions stay intact; a targeted stop clears only the selected branch, and retired members stay blocked on both model and browser paths.
16
+ - No duplicate captain wakeup once a member has already reported completion: the structured `stopReason` of `subagent-settled` decides settlement, while failures and missing reports still notify.
17
+ - Development host moves to Harness `0.2.2-rc.3`, whose subagent runtime keeps the same `rootOf` / `prompt` / `startActivation` / `manager.resident` / `deliverToMember` shape as rc.2.
18
+ - The fork's four customizations carry over: mandatory Chinese language rule in team prompts and tool descriptions, permanent deletion of archived teams (session-bound, two-step confirm), sliding no-progress markers, and verification that re-runs only failed commands with evidence bound to the current attempt.
19
+
20
+ ## Install
21
+
22
+ In **Plugins → Add plugin**, enter `@zhuifengqug/dsh-ant@0.2.0`. For a CLI-managed profile, run:
23
+
24
+ ```sh
25
+ dsh plugin --profile desktop add --save-exact @zhuifengqug/dsh-ant@0.2.0
26
+ ```
27
+
28
+ The recommended host remains Harness `0.2.1-rc.2`; `0.2.2-rc.1` and `0.2.2-rc.2` are the preview targets covered by upstream's runtime matrix, and this fork develops against `0.2.2-rc.3`. See the [tested matrix](../compatibility.json) and the [rc.2 migration evidence](../docs/harness-0.2.2-rc.2/README.md).