@fish-under-sea/dsh-agent-teams-fish 1.0.2 → 2.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.
Files changed (179) hide show
  1. package/NOTICE.md +13 -7
  2. package/README.en.md +20 -12
  3. package/README.md +20 -12
  4. package/compatibility.json +82 -46
  5. package/icon.png +0 -0
  6. package/lib/artifacts.js +148 -25
  7. package/lib/client/ActivityPanel.js +26 -5
  8. package/lib/client/WorkspaceActivity.js +6 -4
  9. package/lib/client/activity-monitor.js +113 -41
  10. package/lib/client/locales.js +14 -0
  11. package/lib/client.js +433 -199
  12. package/lib/client.js.map +1 -1
  13. package/lib/command.js +7 -4
  14. package/lib/git-artifact-stamp.json +2 -2
  15. package/lib/harness-compat.js +120 -62
  16. package/lib/index.js +7 -10
  17. package/lib/mailbox.js +15 -5
  18. package/lib/members.js +221 -154
  19. package/lib/snapshot.js +15 -10
  20. package/lib/state.js +41 -8
  21. package/lib/tools.js +123 -64
  22. package/lib/types/artifacts.d.ts +6 -3
  23. package/lib/types/client/activity-monitor.d.ts +13 -4
  24. package/lib/types/client/locales.d.ts +14 -0
  25. package/lib/types/harness-compat.d.ts +63 -16
  26. package/lib/types/mailbox.d.ts +2 -0
  27. package/lib/types/members.d.ts +5 -17
  28. package/lib/types/snapshot.d.ts +12 -7
  29. package/lib/types/state.d.ts +10 -3
  30. package/lib/types/types.d.ts +5 -0
  31. package/lib/types/web-routes.d.ts +2 -0
  32. package/lib/types/workspace-audit-service.d.ts +35 -0
  33. package/lib/types/workspace-audit-worker.d.ts +1 -0
  34. package/lib/web-routes.js +31 -0
  35. package/lib/workspace-audit-service.js +165 -0
  36. package/lib/workspace-audit-worker.js +11 -0
  37. package/lib/workspace-audit.js +6 -5
  38. package/locale/en.json +6 -0
  39. package/locale/zh.json +6 -0
  40. package/package.json +69 -64
  41. package/pnpm-workspace.yaml +306 -273
  42. package/release-notes/v0.1.25.md +16 -0
  43. package/release-notes/v0.1.26.md +19 -0
  44. package/release-notes/v0.1.27.md +42 -0
  45. package/release-notes/v0.1.28.md +45 -0
  46. package/release-notes/v0.1.29.md +23 -0
  47. package/release-notes/v1.1.0.md +42 -0
  48. package/release-notes/v2.0.0.md +17 -0
  49. package/scripts/artwork-role-match.test.mjs +517 -0
  50. package/scripts/capabilities.test.mjs +301 -0
  51. package/scripts/check-install-channel.mjs +55 -0
  52. package/scripts/check-install-channel.test.mjs +39 -0
  53. package/scripts/clean-build.mjs +14 -0
  54. package/scripts/client-harness-migration.test.mjs +46 -0
  55. package/scripts/compatibility.mjs +20 -0
  56. package/scripts/compatibility.test.mjs +187 -0
  57. package/scripts/corrupt-teamjson.test.mjs +180 -0
  58. package/scripts/custom-artwork.test.mjs +273 -0
  59. package/scripts/fallback-tdd.mjs +61 -0
  60. package/scripts/fixtures/harness-benchmark-scope.mjs +16 -0
  61. package/scripts/fixtures/harness-benchmark-scope.test.mjs +18 -0
  62. package/scripts/fixtures/harness-complex-case.mjs +201 -0
  63. package/scripts/fixtures/harness-complex-case.test.mjs +21 -0
  64. package/scripts/fixtures/harness-complex-oracle.mjs +63 -0
  65. package/scripts/fixtures/harness-issue-case.mjs +51 -0
  66. package/scripts/fixtures/harness-issue159-case.mjs +28 -0
  67. package/scripts/fixtures/harness-model-case.mjs +127 -0
  68. package/scripts/fixtures/harness-model-case.test.mjs +37 -0
  69. package/scripts/fixtures/harness-model-driver.mjs +100 -0
  70. package/scripts/fixtures/harness-runtime-credentials.mjs +23 -0
  71. package/scripts/fixtures/harness-runtime-entry.mjs +171 -0
  72. package/scripts/fixtures/harness-runtime-idle.mjs +42 -0
  73. package/scripts/fixtures/harness-runtime-llm.mjs +193 -0
  74. package/scripts/fixtures/harness-runtime-protocol.mjs +187 -0
  75. package/scripts/fixtures/harness-runtime-resume.mjs +24 -0
  76. package/scripts/fixtures/harness-runtime-stability.mjs +282 -0
  77. package/scripts/fixtures/harness-runtime-tools.mjs +13 -0
  78. package/scripts/fixtures/harness-runtime-web-approval.mjs +341 -0
  79. package/scripts/fixtures/issue-336-audit-worker.mjs +18 -0
  80. package/scripts/git-artifacts.mjs +64 -0
  81. package/scripts/git-artifacts.test.mjs +32 -0
  82. package/scripts/harness-compat-tdd.mjs +492 -0
  83. package/scripts/harness-issue-verify.mjs +26 -0
  84. package/scripts/harness-model-benchmark.mjs +163 -0
  85. package/scripts/harness-runtime-platform.test.mjs +31 -0
  86. package/scripts/harness-runtime-scenarios.mjs +297 -0
  87. package/scripts/harness-runtime-verify.mjs +169 -0
  88. package/scripts/harness-source-verify.mjs +211 -0
  89. package/scripts/harness-source-verify.test.mjs +97 -0
  90. package/scripts/harness-validation.mjs +68 -0
  91. package/scripts/harness-validation.test.mjs +95 -0
  92. package/scripts/http-body.test.mjs +72 -0
  93. package/scripts/import-vendor-artwork.mjs +78 -0
  94. package/scripts/inline-plan-blank-optional-tdd.mjs +121 -0
  95. package/scripts/issue-159.test.mjs +78 -0
  96. package/scripts/issue-188.test.mjs +148 -0
  97. package/scripts/issue-189.test.mjs +100 -0
  98. package/scripts/issue-203-card.test.mjs +181 -0
  99. package/scripts/issue-205.test.mjs +163 -0
  100. package/scripts/issue-234.test.mjs +424 -0
  101. package/scripts/issue-236-stale-module.test.mjs +63 -0
  102. package/scripts/issue-236.test.mjs +59 -0
  103. package/scripts/issue-262.test.mjs +98 -0
  104. package/scripts/issue-336.test.mjs +404 -0
  105. package/scripts/legacy-session-source-repair.test.mjs +201 -0
  106. package/scripts/lifecycle-verify.mjs +1573 -0
  107. package/scripts/lineage-identity.test.mjs +77 -0
  108. package/scripts/member-failure-tdd.mjs +451 -0
  109. package/scripts/member-spawn-recovery.test.mjs +92 -0
  110. package/scripts/quality-gates-amend.test.mjs +161 -0
  111. package/scripts/quality-gates-content-bound.test.mjs +572 -0
  112. package/scripts/quality-gates-cross-binding.test.mjs +184 -0
  113. package/scripts/quality-gates-excluded-scope.test.mjs +163 -0
  114. package/scripts/quality-gates-repair-scope.test.mjs +143 -0
  115. package/scripts/quality-gates-repair-wiring.test.mjs +189 -0
  116. package/scripts/quality-gates-tdd.mjs +1238 -0
  117. package/scripts/quality-gates-work-order.test.mjs +494 -0
  118. package/scripts/readme-version.mjs +89 -0
  119. package/scripts/readme-version.test.mjs +77 -0
  120. package/scripts/release-metadata.mjs +45 -0
  121. package/scripts/release-metadata.test.mjs +66 -0
  122. package/scripts/scoped-release.test.mjs +52 -0
  123. package/scripts/stability-tdd.mjs +144 -0
  124. package/scripts/stress-verify.mjs +548 -0
  125. package/scripts/symlink-support.mjs +46 -0
  126. package/scripts/sync-skill.mjs +103 -0
  127. package/scripts/tool-policies.test.mjs +280 -0
  128. package/scripts/update-skills.mjs +105 -0
  129. package/scripts/update-skills.test.mjs +79 -0
  130. package/scripts/upgrade-status.mjs +66 -0
  131. package/scripts/upgrade-status.test.mjs +83 -0
  132. package/scripts/verify-package.mjs +73 -0
  133. package/scripts/verify.mjs +2199 -0
  134. package/scripts/web-routes-verify.mjs +142 -0
  135. package/scripts/workspace-activity.test.mjs +346 -0
  136. package/scripts/workspace-summary.test.mjs +49 -0
  137. package/src/artifacts.ts +487 -0
  138. package/src/artwork-source.ts +262 -0
  139. package/src/capabilities.ts +113 -0
  140. package/src/client/ActivityPanel.module.css +2390 -0
  141. package/src/client/ActivityPanel.tsx +1507 -0
  142. package/src/client/AgentTeamsCard.module.css +148 -0
  143. package/src/client/AgentTeamsCard.tsx +155 -0
  144. package/src/client/StagingPlanEditor.tsx +829 -0
  145. package/src/client/TeamChatEntry.tsx +27 -0
  146. package/src/client/WorkspaceActivity.module.css +41 -0
  147. package/src/client/WorkspaceActivity.tsx +137 -0
  148. package/src/client/activity-model.ts +372 -0
  149. package/src/client/activity-monitor.ts +440 -0
  150. package/src/client/agent-teams-card-definition.ts +250 -0
  151. package/src/client/artwork.ts +374 -0
  152. package/src/client/icons.tsx +17 -0
  153. package/src/client/index.tsx +140 -0
  154. package/src/client/locales.ts +481 -0
  155. package/src/client/panel-geometry.ts +194 -0
  156. package/src/client/session-navigation.ts +73 -0
  157. package/src/client/workspace-state.ts +52 -0
  158. package/src/command.ts +145 -0
  159. package/src/css-modules.d.ts +4 -0
  160. package/src/event-types.ts +177 -0
  161. package/src/events.ts +78 -0
  162. package/src/harness-compat.ts +570 -0
  163. package/src/index.ts +599 -0
  164. package/src/lineage.ts +248 -0
  165. package/src/mailbox.ts +185 -0
  166. package/src/members.ts +1230 -0
  167. package/src/profiles.ts +765 -0
  168. package/src/quality-gates.ts +2124 -0
  169. package/src/scheduler.ts +554 -0
  170. package/src/snapshot.ts +333 -0
  171. package/src/state.ts +1317 -0
  172. package/src/tool-names.ts +14 -0
  173. package/src/tool-policies.ts +219 -0
  174. package/src/tools.ts +2939 -0
  175. package/src/types.ts +414 -0
  176. package/src/web-routes.ts +128 -0
  177. package/src/workspace-audit-service.ts +182 -0
  178. package/src/workspace-audit-worker.ts +12 -0
  179. package/src/workspace-audit.ts +57 -0
package/lib/command.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createUserMessage } from '@deepseek-ai/dsh-llm';
2
- import { agentTeamsSource } from "./harness-compat.js";
2
+ import { agentTeamsSource, observedSessionFormatVersion } from "./harness-compat.js";
3
3
  import { parseProfileInvocation, resolveProfileTaskPlanning } from "./profiles.js";
4
4
  export const AGENT_TEAMS_COMMAND = 'agent-teams';
5
5
  const PROFILE_COMMAND_PREFIX = `${AGENT_TEAMS_COMMAND}-`;
@@ -117,16 +117,19 @@ export function registerAgentTeamsCommand(ctx, getProfiles = () => ({})) {
117
117
  }, 'agent-teams: slash commands');
118
118
  }
119
119
  export function installAgentTeamsGestureBoundary(ctx, getProfiles = () => ({})) {
120
- ctx.on('agent/pre-step', async ({ messages, signal }, next) => {
120
+ ctx.on('agent/pre-step', async ({ agent, messages, signal }, next) => {
121
121
  const decision = await next();
122
122
  if (decision.kind === 'reject')
123
123
  return decision;
124
+ // The live session header carries the format this host actually stores; the
125
+ // resolved module constant can name another DSH line in the same profile (#236).
126
+ const observed = observedSessionFormatVersion(agent);
124
127
  let invocation;
125
128
  try {
126
129
  invocation = invokedAgentTeamsInvocation(messages, getProfiles);
127
130
  }
128
131
  catch (error) {
129
- return { kind: 'enter', messages: [...decision.messages, createUserMessage({ content: [{ type: 'text', text: `AgentTeams profile parsing failed: ${String(error)}` }], source: agentTeamsSource({ kind: 'agent-teams-command' }) })] };
132
+ return { kind: 'enter', messages: [...decision.messages, createUserMessage({ content: [{ type: 'text', text: `AgentTeams profile parsing failed: ${String(error)}` }], source: agentTeamsSource({ kind: 'agent-teams-command' }, observed) })] };
130
133
  }
131
134
  if (invocation === undefined)
132
135
  return decision;
@@ -139,6 +142,6 @@ export function installAgentTeamsGestureBoundary(ctx, getProfiles = () => ({}))
139
142
  const text = !known
140
143
  ? `AgentTeams profile "${invocation.profile}" does not exist. Available profiles: ${Object.keys(profiles).join(', ') || '(none)'}. Do not create a team.`
141
144
  : buildActivationDirective(invocation.goal, invocation.profile, resolveProfileTaskPlanning(matched?.[1]));
142
- return { kind: 'enter', messages: [...decision.messages, createUserMessage({ content: [{ type: 'text', text }], source: agentTeamsSource({ kind: 'agent-teams-command', ...invocation.goal === '' ? {} : { goal: invocation.goal }, ...invocation.profile === undefined ? {} : { profile: invocation.profile } }) })] };
145
+ return { kind: 'enter', messages: [...decision.messages, createUserMessage({ content: [{ type: 'text', text }], source: agentTeamsSource({ kind: 'agent-teams-command', ...invocation.goal === '' ? {} : { goal: invocation.goal }, ...invocation.profile === undefined ? {} : { profile: invocation.profile } }, observed) })] };
143
146
  });
144
147
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "schema": 1,
3
- "source": "b60bf1707cc13d40c03cd6079932311a4af15c3235b9097ff9a1805a129c49bc",
4
- "output": "af3bbe736aa425356b9200ea58dabd2a40eee8a6a636f70532763b208517e8bb"
3
+ "source": "decb660bc1cd9b5e7b9c877d0dab69af26c93adad43c1a32e0f536b1fba266bc",
4
+ "output": "6454b5157475a1c3316d5132fd4615f636793e062f96d4c24af9876530540ac4"
5
5
  }
@@ -1,3 +1,4 @@
1
+ import { installModelSelection } from '@deepseek-ai/dsh-agent';
1
2
  import { createUserMessage } from '@deepseek-ai/dsh-llm';
2
3
  import * as dshSession from '@deepseek-ai/dsh-session';
3
4
  import { SubagentError } from '@deepseek-ai/dsh-subagent';
@@ -13,74 +14,74 @@ const hostPromptQueue = Symbol.for('dsh.subagent.queuePrompt');
13
14
  // 0.1.5 keeps queueHostSubagentPrompt but replaces its symbol with this
14
15
  // delivery-mode-aware implementation (packages/subagent/subagent/src/internal.ts).
15
16
  const hostPromptDeliver = Symbol.for('dsh.subagent.deliverPrompt');
16
- function boundary(runtime) {
17
- return runtime;
18
- }
19
- function unsupported(detail) {
20
- throw new Error(`agent-teams: unsupported Harness subagent contract (${detail}); use an explicitly tested Harness version and a coherent dependency installation`);
17
+ export function usesManagedActivations(runtime) {
18
+ return typeof runtime.startActivation === 'function';
21
19
  }
22
- /** 在 0.2.1 的 activation 契约上保留旧版持久子会话与父级通知语义。 */
23
20
  export async function startMember(runtime, spec) {
24
- const host = boundary(runtime);
21
+ const host = runtime;
25
22
  if (typeof host.startActivation === 'function') {
26
- return host.startActivation.call(runtime, { ...spec, delivery: 'parent' });
23
+ const { persona: _persona, toolFilter: _filter, ...request } = spec.request;
24
+ const activation = await host.startActivation.call(runtime, { ...spec, request, delivery: 'parent' });
25
+ // Preserve native settlement as the missing-report/error fallback on both
26
+ // fresh and resumed activations. mailbox.ts deduplicates successful reports.
27
+ void activation.result.catch(() => undefined);
28
+ return activation;
27
29
  }
28
- if (typeof host.startContinuable === 'function')
29
- return host.startContinuable.call(runtime, spec);
30
- return unsupported('missing member creation API');
30
+ if (typeof host.startContinuable !== 'function')
31
+ return unsupported('missing member creation API');
32
+ return host.startContinuable.call(runtime, spec);
31
33
  }
32
- /** 新旧宿主均只停止指定成员子树,保留原生接收者与停止失败。 */
33
- export async function drainMemberChildren(runtime, parent, childIds) {
34
- const host = boundary(runtime);
35
- if (typeof host.drainChildren === 'function')
36
- return host.drainChildren.call(runtime, parent, childIds);
37
- if (typeof host.drainContinuableChildren === 'function')
38
- return host.drainContinuableChildren.call(runtime, parent, childIds);
39
- return unsupported('missing member drain API');
40
- }
41
- /** 只包装真实存在的接口,避免把缺失的旧方法伪装成可调用方法。 */
34
+ /** Wrap every available creation API, restoring only this plugin's own methods. */
42
35
  export function guardSubagentCreation(ctx, check) {
43
36
  const runtime = ctx.subagents;
44
- const host = boundary(runtime);
45
- if (typeof host.start !== 'function' && typeof host.startContinuable !== 'function' && typeof host.startActivation !== 'function') {
46
- return unsupported('missing subagent creation API');
47
- }
48
37
  ctx.effect(() => {
49
- let active = true;
50
- const restorations = [];
51
- const admit = (parent) => { if (active)
52
- check(parent); };
53
- const replace = (key, wrapped) => {
54
- const descriptor = Object.getOwnPropertyDescriptor(host, key);
55
- host[key] = wrapped;
56
- restorations.push(() => {
57
- if (Object.getOwnPropertyDescriptor(host, key)?.value !== wrapped)
38
+ const disposers = [];
39
+ for (const key of ['start', 'startContinuable', 'startActivation']) {
40
+ const original = runtime[key];
41
+ if (typeof original !== 'function')
42
+ continue;
43
+ const descriptor = Object.getOwnPropertyDescriptor(runtime, key);
44
+ const guarded = async (...args) => {
45
+ const request = key === 'start' ? args[1] : args[0].request;
46
+ check(request.parent);
47
+ return Reflect.apply(original, ctx.subagents, args);
48
+ };
49
+ Object.defineProperty(runtime, key, { value: guarded, writable: true, configurable: true });
50
+ disposers.push(() => {
51
+ if (Object.getOwnPropertyDescriptor(runtime, key)?.value !== guarded)
58
52
  return;
59
53
  if (descriptor === undefined)
60
- Reflect.deleteProperty(host, key);
54
+ Reflect.deleteProperty(runtime, key);
61
55
  else
62
- Object.defineProperty(host, key, descriptor);
56
+ Object.defineProperty(runtime, key, descriptor);
63
57
  });
64
- };
65
- const start = host.start;
66
- const continuable = host.startContinuable;
67
- const activation = host.startActivation;
68
- if (typeof start === 'function') {
69
- replace('start', async (name, request) => { admit(request.parent); return start.call(runtime, name, request); });
70
- }
71
- if (typeof continuable === 'function') {
72
- replace('startContinuable', async (spec) => { admit(spec.request.parent); return continuable.call(runtime, spec); });
73
- }
74
- if (typeof activation === 'function') {
75
- replace('startActivation', async (spec) => { admit(spec.request.parent); return activation.call(runtime, spec); });
76
58
  }
77
- return () => {
78
- active = false;
79
- for (const restore of restorations.reverse())
80
- restore();
81
- };
59
+ return () => { for (const dispose of disposers)
60
+ dispose(); };
82
61
  }, 'agent-teams: member delegation budget');
83
62
  }
63
+ /**
64
+ * Install the member's next-step model selection hook on a child context.
65
+ *
66
+ * 0.2.1 hosts take a caller-owned selection ref here; 0.2.2 moved the selected
67
+ * route into the Agent's own durable model API, so the hook contributes switch
68
+ * notices only and takes the child context alone. Dispatch on the function's
69
+ * own arity so one build serves both declared host lines instead of binding to
70
+ * whichever signature the development host happens to ship.
71
+ * @param childCtx - the member child context the hook belongs to.
72
+ * @param ref - the resolved selection the member is running on.
73
+ * @returns the disposal for the installed hook.
74
+ */
75
+ export function installMemberModelSelection(childCtx, ref) {
76
+ const install = installModelSelection;
77
+ return install.length >= 2 ? install(childCtx, ref) : install(childCtx);
78
+ }
79
+ function boundary(runtime) {
80
+ return runtime;
81
+ }
82
+ function unsupported(detail) {
83
+ throw new Error(`agent-teams: unsupported Harness subagent contract (${detail}); use an explicitly tested Harness version and a coherent dependency installation`);
84
+ }
84
85
  /** Package identity a released plugin-wrapper source names on older hosts. */
85
86
  export const AGENT_TEAMS_PLUGIN_NAME = '@nanmicoder/dsh-agent-teams';
86
87
  /**
@@ -91,8 +92,30 @@ export const AGENT_TEAMS_PLUGIN_NAME = '@nanmicoder/dsh-agent-teams';
91
92
  * newer host opens it (#160).
92
93
  */
93
94
  export const RELEASED_SOURCE_VOCABULARY_VERSION = 3;
94
- /** Stored session format generation of the running host; 0 when it exposes none. */
95
- export function hostSessionFormatVersion() {
95
+ /**
96
+ * Stored format generation observed on a live session, when the host exposes it.
97
+ *
98
+ * The module constant is only a fallback: a plugin can resolve a *nested*
99
+ * `@deepseek-ai/dsh-session` copy that belongs to a different host generation
100
+ * than the process loading it (a profile whose lockfile pins the DSH package
101
+ * line, a Desktop shell with an embedded core, a duplicated store). That copy
102
+ * then reports the wrong generation — 0 on a v4 host — which selects the
103
+ * retired `plugin` wrapper and makes every durable AgentTeams message fail the
104
+ * host's own admission check (#236). The live session header belongs to the
105
+ * host that persists the message, so it outranks the resolved module.
106
+ */
107
+ export function observedSessionFormatVersion(subject) {
108
+ const version = subject?.session?.header?.version;
109
+ return typeof version === 'number' && Number.isSafeInteger(version) && version >= 0 ? version : undefined;
110
+ }
111
+ /**
112
+ * Stored session format generation of the running host; 0 when neither the live
113
+ * session nor the resolved module exposes one.
114
+ * @param observed - a live session observation; preferred over the module constant.
115
+ */
116
+ export function hostSessionFormatVersion(observed) {
117
+ if (typeof observed === 'number' && Number.isSafeInteger(observed) && observed >= 0)
118
+ return observed;
96
119
  const version = dshSession.SESSION_FORMAT_VERSION;
97
120
  return typeof version === 'number' && Number.isSafeInteger(version) && version >= 0 ? version : 0;
98
121
  }
@@ -108,10 +131,14 @@ export function hostSessionFormatVersion() {
108
131
  * the released plugin wrapper is used instead; the goal and profile already
109
132
  * travel in the message text.
110
133
  * @param modern - the producer-owned source to use where the host admits it.
134
+ * @param observed - the live session's stored format generation, when callers
135
+ * have the owning agent at hand. Never trust the resolved module alone: on a
136
+ * host whose profile pins another DSH line it reports a retired generation and
137
+ * the v4 writer rejects the wrapper (#236).
111
138
  * @returns a source accepted by the running host and by its migration chain.
112
139
  */
113
- export function agentTeamsSource(modern) {
114
- if (hostSessionFormatVersion() >= RELEASED_SOURCE_VOCABULARY_VERSION)
140
+ export function agentTeamsSource(modern, observed) {
141
+ if (hostSessionFormatVersion(observed) >= RELEASED_SOURCE_VOCABULARY_VERSION)
115
142
  return modern;
116
143
  // Released-format hosts persist plugin-authored messages as this wrapper; the
117
144
  // current vocabulary retired it, so the cast stays confined to this branch
@@ -143,6 +170,17 @@ export function sessionOwnEvents(session) {
143
170
  return unsupported('missing ownEvents/legacy session log');
144
171
  return legacy.events.slice(legacy.header.seedLength ?? 0);
145
172
  }
173
+ /** Legacy hosts log each chunk separately; current hosts embed the committed stream. */
174
+ export function outputLimitTurn(event) {
175
+ const record = event;
176
+ if (record.type === 'assistant/chunk') {
177
+ const { chunk, turn } = record.data;
178
+ return chunk.type === 'finish' && chunk.reason.kind === 'max-tokens' ? turn : undefined;
179
+ }
180
+ if (record.type === 'assistant/message' && record.data.stream?.some(item => item.type === 'chunk' && item.chunk.type === 'finish' && item.chunk.reason.kind === 'max-tokens')) {
181
+ return record.data.turn;
182
+ }
183
+ }
146
184
  /** 读取宿主冻结的会话策略,旧版没有投影服务时检查本会话日志。 */
147
185
  export function assertMemberModelSelection(ctx, captain, route) {
148
186
  const projections = ctx.get?.('sessionProjections');
@@ -186,7 +224,7 @@ export function installContinuableMemberSetup(ctx, setup) {
186
224
  const installed = new WeakSet();
187
225
  const active = new Set();
188
226
  ctx.effect(() => {
189
- const stop = onAgentReady(ctx, (agent, vetoable) => {
227
+ const attach = (agent, vetoable) => {
190
228
  if (installed.has(agent))
191
229
  return;
192
230
  // Deliberately synchronous: awaiting here loses the first-request race.
@@ -224,18 +262,30 @@ export function installContinuableMemberSetup(ctx, setup) {
224
262
  dispose();
225
263
  throw error;
226
264
  }
227
- });
228
- return () => {
265
+ };
266
+ const stop = onAgentReady(ctx, attach);
267
+ const cleanup = () => {
229
268
  stop();
230
269
  for (const dispose of [...active])
231
270
  dispose();
232
271
  };
272
+ try {
273
+ // Reloads keep Agents alive but dispose the previous plugin's setup.
274
+ // Subscribe first, then hydrate the live registry; attach is idempotent.
275
+ for (const agent of ctx.agents.list())
276
+ attach(agent, false);
277
+ }
278
+ catch (error) {
279
+ cleanup();
280
+ throw error;
281
+ }
282
+ return cleanup;
233
283
  }, 'agent-teams: member lifecycle compatibility');
234
284
  }
235
285
  /** Queue a distinct host-authored turn; never substitute model-message steer. */
236
286
  export async function queueMemberPrompt(runtime, parent, childId, content, signal) {
237
287
  const host = boundary(runtime);
238
- const source = agentTeamsSource({ kind: 'agent-teams' });
288
+ const source = agentTeamsSource({ kind: 'agent-teams' }, observedSessionFormatVersion(parent));
239
289
  if (typeof host.followup === 'function') {
240
290
  return host.followup.call(runtime, parent, childId, content, { source, signal });
241
291
  }
@@ -250,7 +300,7 @@ export async function queueMemberPrompt(runtime, parent, childId, content, signa
250
300
  /** Coordination joins the nearest step, including waking an idle/cold child. */
251
301
  export async function steerMemberPrompt(runtime, parent, childId, content, signal, live) {
252
302
  const host = boundary(runtime);
253
- const source = agentTeamsSource({ kind: 'agent-teams' });
303
+ const source = agentTeamsSource({ kind: 'agent-teams' }, observedSessionFormatVersion(live ?? parent));
254
304
  const deliver = host[hostPromptDeliver];
255
305
  if (typeof deliver === 'function')
256
306
  return deliver.call(runtime, parent, childId, content, source, signal, 'steer');
@@ -434,3 +484,11 @@ export async function startMemberWithLenientFilter(start, filter, relaxableDeny
434
484
  }
435
485
  }
436
486
  }
487
+ /** Targeted recursive cancellation renamed with the unified activation manager. */
488
+ export async function drainMemberChildren(runtime, parent, ids) {
489
+ const host = runtime;
490
+ const drain = host.drainChildren ?? host.drainContinuableChildren;
491
+ if (typeof drain !== 'function')
492
+ return unsupported('missing targeted child drain');
493
+ await drain.call(runtime, parent, ids);
494
+ }
package/lib/index.js CHANGED
@@ -30,9 +30,10 @@ import { leadIdentityOfAsync } from "./lineage.js";
30
30
  import { formatProfilesForPrompt } from "./profiles.js";
31
31
  import { parseToolPolicies } from "./tool-policies.js";
32
32
  import { installTeamCapabilities } from "./capabilities.js";
33
+ import { agentTeamsSource, observedSessionFormatVersion } from "./harness-compat.js";
33
34
  import { TEAM_TOOL_NAMES } from "./tool-names.js";
34
35
  import { artworkCandidates, findCustomArtwork, findPackagedArtwork } from "./artwork-source.js";
35
- import { authenticatedWebRoutes, readJsonRequest, RequestBodyError } from "./web-routes.js";
36
+ import { authenticatedWebRoutes, readJsonRequest, RequestBodyError, writeJsonWithEtag } from "./web-routes.js";
36
37
  /** Web-server service key candidates, newest first. */
37
38
  const WEB_SERVER_KEYS = ['webServer', 'httpServer'];
38
39
  /** Workspace registry service key candidates, newest first. */
@@ -242,6 +243,7 @@ export function apply(ctx, config) {
242
243
  path: '/plugins/dsh-agent-teams/state',
243
244
  handler: async (req, res) => {
244
245
  const url = new URL(req.url ?? '/', 'http://x');
246
+ const captainSessionId = url.searchParams.get('session')?.trim() || undefined;
245
247
  const roots = workspaceRegistry.list().map((workspace) => ({
246
248
  workspace: workspace.title,
247
249
  // The panel audits the same current bytes as agent_teams_status, so it
@@ -251,14 +253,9 @@ export function apply(ctx, config) {
251
253
  }));
252
254
  // ?archived=1 serves teams moved to archive/ (post-delete review).
253
255
  const snapshots = url.searchParams.get('archived') === '1'
254
- ? await collectArchivedTeamsActivity(ctx, roots)
255
- : await collectTeamsActivity(ctx, roots);
256
- const body = JSON.stringify({ teams: snapshots });
257
- res.writeHead(200, {
258
- 'content-type': 'application/json; charset=utf-8',
259
- 'cache-control': 'no-store',
260
- });
261
- res.end(body);
256
+ ? await collectArchivedTeamsActivity(ctx, roots, captainSessionId)
257
+ : await collectTeamsActivity(ctx, roots, captainSessionId, url.searchParams.get('summary') === '1');
258
+ writeJsonWithEtag(req, res, JSON.stringify({ teams: snapshots }));
262
259
  },
263
260
  }), 'agent-teams: activity route');
264
261
  ctx.effect(() => webServer.register({
@@ -366,7 +363,7 @@ export function apply(ctx, config) {
366
363
  try {
367
364
  captain.steer(createUserMessage({
368
365
  content: [{ type: 'text', text: stagedPlanApprovedContext(team.name) }],
369
- source: { kind: 'agent-teams' },
366
+ source: agentTeamsSource({ kind: 'agent-teams' }, observedSessionFormatVersion(captain)),
370
367
  }));
371
368
  }
372
369
  catch (error) {
package/lib/mailbox.js CHANGED
@@ -25,15 +25,25 @@ function mailboxBody(recipient, messages) {
25
25
  ? `AgentTeams message from member ${message.from}:\n\n${mailboxContent(message)}`
26
26
  : `AgentTeams message from ${message.from}${message.attemptId === undefined ? '' : ` for task ${message.taskId}, attempt_id ${message.attemptId}`}:\n\n${mailboxContent(message)}`).join('\n\n');
27
27
  }
28
+ /** Read current mail while the caller holds the lock and has verified the team. */
29
+ export async function readCurrentMailboxLocked(root, team, recipient, onMalformed) {
30
+ const messages = await readUnreadMailbox(root, team.id, recipient, onMalformed);
31
+ const current = [];
32
+ const staleIds = [];
33
+ for (const message of messages) {
34
+ if (isCurrentMail(team, message))
35
+ current.push(message);
36
+ else
37
+ staleIds.push(message.id);
38
+ }
39
+ await discardMailboxMessages(root, team.id, recipient, staleIds);
40
+ return current;
41
+ }
28
42
  /** Fallback reads must enforce the same current-generation rule as live admission. */
29
43
  export async function readCurrentMailbox(root, teamId, recipient, onMalformed) {
30
44
  return withTeamLock(`team:${root}:${teamId}`, async () => {
31
45
  const team = await readTeam(root, teamId);
32
- if (team === undefined)
33
- return [];
34
- const messages = await readUnreadMailbox(root, teamId, recipient, onMalformed);
35
- await discardMailboxMessages(root, teamId, recipient, messages.filter(message => !isCurrentMail(team, message)).map(message => message.id));
36
- return messages.filter(message => isCurrentMail(team, message));
46
+ return team === undefined ? [] : readCurrentMailboxLocked(root, team, recipient, onMalformed);
37
47
  });
38
48
  }
39
49
  export function mailboxPrompt(teamId, recipient, messages) {