@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
@@ -0,0 +1,424 @@
1
+ // Issue #234 regression: a gateway-materialized empty `plan` shell must count
2
+ // as "not provided".
3
+ //
4
+ // Some model gateways materialize optional object parameters instead of
5
+ // omitting them, so a call that only passed `profile: "dev-team"` arrives
6
+ // carrying `plan: { members: [], tasks: [] }`, or one placeholder member whose
7
+ // every field is blank — both shapes were observed on one installation with
8
+ // such a gateway. `agent_teams_create` used to treat that shell as an inline
9
+ // plan, so every profile-only call died on `choose either a configured profile
10
+ // or an inline plan`.
11
+ //
12
+ // These cases drive the REAL tool execution path: a real Cordis Context +
13
+ // `ToolRuntime` dispatch the registered `agent_teams_create`, so the declared
14
+ // parameter schema validates every call exactly like production, while the
15
+ // surrounding host services (llm routing, subagent runtime) stay minimal fakes.
16
+ // Positive cases assert the staged `team.json` really landed with the profile
17
+ // roster; the mutual-exclusion guard and the inline-plan branch are pinned too,
18
+ // so the normalization cannot silently widen the "not provided" bucket.
19
+ //
20
+ // Semantic choice (deliberate): this mirrors issue #99's "a materialized blank
21
+ // equals not provided" invariant. A blank profile plus an empty shell therefore
22
+ // falls into the existing plain empty-team branch instead of gaining a new
23
+ // error message.
24
+ import test from 'node:test'
25
+ import assert from 'node:assert/strict'
26
+ import { createRequire } from 'node:module'
27
+ import { pathToFileURL } from 'node:url'
28
+ import { mkdtemp, readFile, rm } from 'node:fs/promises'
29
+ import { tmpdir } from 'node:os'
30
+ import { join } from 'node:path'
31
+ import { Context } from '@deepseek-ai/cordis'
32
+ import { SystemPrompt } from '@deepseek-ai/dsh-system-prompt'
33
+ import { ToolRuntime } from '@deepseek-ai/dsh-tools'
34
+ import { registerAgentTeamsTools } from '../lib/tools.js'
35
+ import { readTeam, sanitizeKey, writeTeam } from '../lib/state.js'
36
+
37
+ const requireTools = createRequire(import.meta.resolve('@deepseek-ai/dsh-tools'))
38
+ const { createScope } = await import(pathToFileURL(requireTools.resolve('@deepseek-ai/dsh-scope')).href)
39
+
40
+ const PROFILE = 'issue-234-team'
41
+ const PROFILES = {
42
+ [PROFILE]: {
43
+ members: [{ name: 'fixer', role: 'engineer' }],
44
+ tasks: [{ id: 'seed-1', subject: 'apply the fix', assignee: 'fixer' }],
45
+ },
46
+ }
47
+
48
+ /** The two shells real gateways produced, plus a genuine inline plan. */
49
+ const EMPTY_ARRAY_SHELL = { members: [], tasks: [] }
50
+ const PLACEHOLDER_MEMBER_SHELL = {
51
+ members: [{ name: '', role: '', provider: '', model: '', reasoning_effort: '' }],
52
+ tasks: [],
53
+ }
54
+ const REAL_PLAN = {
55
+ members: [{ name: 'scout', role: 'analyst' }],
56
+ tasks: [{ id: 't1', subject: 'survey the roster', assignee: 'scout' }],
57
+ }
58
+
59
+ /**
60
+ * Mount the real tool runtime over the shipped `agent_teams_create`.
61
+ * @returns the dispatch helper plus real on-disk team readers.
62
+ */
63
+ async function mount() {
64
+ const workspace = await mkdtemp(join(tmpdir(), 'agentteams-234-'))
65
+ const host = new Context()
66
+ const prompt = host.plugin(SystemPrompt, { includeHarnessIdentity: false })
67
+ await prompt.await()
68
+ const runtime = host.plugin(ToolRuntime, { mode: 'native' })
69
+ await runtime.await()
70
+ const definitions = []
71
+ const agents = []
72
+ const noop = () => {}
73
+ registerAgentTeamsTools({
74
+ on: () => noop,
75
+ effect: setup => setup(),
76
+ logger: { warn: noop, debug: noop },
77
+ tools: { register: definition => definitions.push(definition) },
78
+ agents: { get: id => agents.find(agent => agent.id === id) },
79
+ llm: { async resolveCallConfig(config) { return config }, async listModels() { return [] } },
80
+ subagents: { followup: async () => {}, registerContinuableSetup: () => noop },
81
+ }, { stateDir: '.agent-teams', memberProvider: 'spawn', memberMaxDepth: 1, maxMembers: 8, profiles: PROFILES })
82
+ let owned
83
+ const business = host.plugin({
84
+ inject: ['tools'],
85
+ apply(ctx) {
86
+ owned = ctx
87
+ for (const definition of definitions) ctx.tools.register(definition)
88
+ ctx.provide('agents', { list: () => agents })
89
+ },
90
+ })
91
+ await business.await()
92
+ let seq = 0
93
+ const createCaptain = id => {
94
+ const events = []
95
+ const agent = {
96
+ id,
97
+ status: 'idle',
98
+ options: { provider: 'fake', model: 'fake-model' },
99
+ session: {
100
+ id,
101
+ header: { cwd: workspace, seedLength: 0 },
102
+ events,
103
+ inheritedEventCount: 0,
104
+ get seq() { return events.length },
105
+ snapshotEvents: () => events.slice(),
106
+ eventAt: index => events[index],
107
+ requestHeader: () => ({ config: { provider: 'fake', model: 'fake-model' } }),
108
+ append(type, data) { const event = { seq: events.length, type, data }; events.push(event); return event },
109
+ },
110
+ }
111
+ const scope = createScope(owned, agent)
112
+ agent.ctx = scope.ctx
113
+ agents.push(agent)
114
+ return agent
115
+ }
116
+ const execute = (agent, args) => host.tools.execute({
117
+ name: 'agent_teams_create',
118
+ arguments: args,
119
+ callId: `issue-234-${++seq}`,
120
+ agent,
121
+ signal: new AbortController().signal,
122
+ })
123
+ /** Dispatch any registered tool through the same real runtime path. */
124
+ const executeTool = (agent, name, args) => host.tools.execute({
125
+ name,
126
+ arguments: args,
127
+ callId: `issue-234-${name}-${++seq}`,
128
+ agent,
129
+ signal: new AbortController().signal,
130
+ })
131
+ const stateRoot = join(workspace, '.agent-teams')
132
+ const loadTeam = teamId => readTeam(stateRoot, teamId)
133
+ const saveTeam = team => writeTeam(stateRoot, team)
134
+ const teamPath = teamId => join(workspace, '.agent-teams', teamId, 'team.json')
135
+ const readCreated = async teamId => JSON.parse(await readFile(teamPath(teamId), 'utf8'))
136
+ const exists = async teamId => {
137
+ try {
138
+ await readFile(teamPath(teamId), 'utf8')
139
+ return true
140
+ } catch {
141
+ return false
142
+ }
143
+ }
144
+ return {
145
+ createCaptain,
146
+ execute,
147
+ executeTool,
148
+ loadTeam,
149
+ saveTeam,
150
+ readCreated,
151
+ exists,
152
+ dispose: () => rm(workspace, { recursive: true, force: true }),
153
+ }
154
+ }
155
+
156
+ for (const [label, plan] of [['an empty-array shell', EMPTY_ARRAY_SHELL], ['a placeholder-member shell', PLACEHOLDER_MEMBER_SHELL]]) {
157
+ await test(`a profile with ${label} creates the configured profile team (issue #234)`, async () => {
158
+ const fixture = await mount()
159
+ try {
160
+ const captain = fixture.createCaptain(`captain-shell-${sanitizeKey(label)}`)
161
+ const result = await fixture.execute(captain, {
162
+ name: `Shell ${sanitizeKey(label)}`,
163
+ description: 'gateway materialized an optional plan parameter',
164
+ approval: 'required',
165
+ profile: PROFILE,
166
+ plan,
167
+ })
168
+ assert.equal(result.isError, false, JSON.stringify(result))
169
+ assert.doesNotMatch(JSON.stringify(result), /choose either a configured profile or an inline plan/)
170
+ assert.equal(result.value.profile, PROFILE)
171
+ // The profile branch really ran: the configured roster is on disk, staged.
172
+ const team = await fixture.readCreated(result.value.team_id)
173
+ assert.equal(team.phase, 'staged')
174
+ assert.equal(team.profile.name, PROFILE)
175
+ assert.deepEqual(team.members.map(member => member.name), ['fixer'])
176
+ assert.deepEqual(team.tasks.map(task => task.profileSeedId), ['seed-1'])
177
+ } finally {
178
+ await fixture.dispose()
179
+ }
180
+ })
181
+ }
182
+
183
+ await test('a profile with a real inline plan still trips the mutual-exclusion guard (issue #234)', async () => {
184
+ const fixture = await mount()
185
+ try {
186
+ const captain = fixture.createCaptain('captain-real-plan-with-profile')
187
+ const result = await fixture.execute(captain, {
188
+ name: 'Real Plan With Profile',
189
+ approval: 'required',
190
+ profile: PROFILE,
191
+ plan: REAL_PLAN,
192
+ })
193
+ assert.equal(result.isError, true, JSON.stringify(result))
194
+ assert.match(JSON.stringify(result), /choose either a configured profile or an inline plan/)
195
+ assert.equal(await fixture.exists(sanitizeKey('Real Plan With Profile')), false)
196
+ } finally {
197
+ await fixture.dispose()
198
+ }
199
+ })
200
+
201
+ await test('a substantive member plus empty tasks is a real plan, not a shell (issue #234)', async () => {
202
+ const fixture = await mount()
203
+ try {
204
+ const captain = fixture.createCaptain('captain-member-with-empty-tasks')
205
+ const result = await fixture.execute(captain, {
206
+ name: 'Member Without Tasks',
207
+ approval: 'required',
208
+ profile: PROFILE,
209
+ plan: { members: REAL_PLAN.members, tasks: [] },
210
+ })
211
+ assert.equal(result.isError, true, JSON.stringify(result))
212
+ assert.match(JSON.stringify(result), /choose either a configured profile or an inline plan/)
213
+ } finally {
214
+ await fixture.dispose()
215
+ }
216
+ })
217
+
218
+ await test('a real inline plan without a profile still builds the inline roster (issue #234)', async () => {
219
+ const fixture = await mount()
220
+ try {
221
+ const captain = fixture.createCaptain('captain-inline-plan')
222
+ const result = await fixture.execute(captain, {
223
+ name: 'Inline Plan',
224
+ approval: 'required',
225
+ plan: REAL_PLAN,
226
+ })
227
+ assert.equal(result.isError, false, JSON.stringify(result))
228
+ assert.equal(result.value.profile, undefined)
229
+ const team = await fixture.readCreated(result.value.team_id)
230
+ assert.equal(team.profile, undefined)
231
+ assert.deepEqual(team.members.map(member => member.name), ['scout'])
232
+ assert.deepEqual(team.tasks.map(task => task.profileSeedId), ['t1'])
233
+ } finally {
234
+ await fixture.dispose()
235
+ }
236
+ })
237
+
238
+ await test('a blank profile plus an empty shell equals "neither provided" (issue #234)', async () => {
239
+ const fixture = await mount()
240
+ try {
241
+ const captain = fixture.createCaptain('captain-blank-profile-shell')
242
+ const result = await fixture.execute(captain, {
243
+ name: 'Blank Profile Shell',
244
+ approval: 'required',
245
+ profile: '',
246
+ plan: EMPTY_ARRAY_SHELL,
247
+ })
248
+ // Same invariant as issue #99: the materialized blank counts as omitted, so
249
+ // the existing plain empty-team branch handles it — no new error text.
250
+ assert.equal(result.isError, false, JSON.stringify(result))
251
+ assert.doesNotMatch(JSON.stringify(result), /choose either a configured profile or an inline plan/)
252
+ const team = await fixture.readCreated(result.value.team_id)
253
+ assert.equal(team.profile, undefined)
254
+ assert.deepEqual(team.members, [])
255
+ assert.deepEqual(team.tasks, [])
256
+ } finally {
257
+ await fixture.dispose()
258
+ }
259
+ })
260
+
261
+ /**
262
+ * Mount a running team with one spawned member ("fixer"), a sibling member
263
+ * ("scout") and the tasks the claim_task cases below need. Real gateways
264
+ * materialize the deprecated `assignee` argument, so the claim path is driven
265
+ * with the exact shapes a model sends.
266
+ * @param extraTasks - additional tasks appended to the fixture roster.
267
+ * @returns the fixture plus the captain / member / sibling agents.
268
+ */
269
+ async function mountRunningTeam(extraTasks = []) {
270
+ const fixture = await mount()
271
+ const captain = fixture.createCaptain('captain-claim')
272
+ const fixer = fixture.createCaptain('member-fixer')
273
+ const scout = fixture.createCaptain('member-scout')
274
+ const created = await fixture.execute(captain, { name: 'Claim Team', approval: 'required', profile: PROFILE })
275
+ assert.equal(created.isError, false, JSON.stringify(created))
276
+ const team = await fixture.loadTeam(created.value.team_id)
277
+ const now = Date.now()
278
+ const task = (id, subject, assignee, status, extra = {}) => ({
279
+ id,
280
+ subject,
281
+ status,
282
+ assignee,
283
+ dependencies: [],
284
+ attempt: 0,
285
+ createdAt: now,
286
+ updatedAt: now,
287
+ ...extra,
288
+ })
289
+ team.phase = 'running'
290
+ delete team.planReviewState
291
+ team.members = [
292
+ { ...team.members[0], id: fixer.id },
293
+ { id: scout.id, name: 'scout', role: 'analyst', provider: 'fake', model: 'fake-model', joinedAt: now, status: 'idle' },
294
+ ]
295
+ team.tasks = [
296
+ task('t1', 'member task', 'fixer', 'pending'),
297
+ task('t2', 'other member task', 'scout', 'pending'),
298
+ task('t3', 'captain takeover', 'captain', 'claimed', { attempt: 1, attemptId: 'captain-attempt-1' }),
299
+ ...extraTasks,
300
+ ]
301
+ team.taskSeq = team.tasks.length
302
+ await fixture.saveTeam(team)
303
+ return { fixture, captain, fixer, scout, teamId: team.id }
304
+ }
305
+
306
+ await test('a member claim ignores a blank or self-named materialized assignee (issue #234 follow-up)', async () => {
307
+ const { fixture, fixer, teamId } = await mountRunningTeam()
308
+ try {
309
+ const blank = await fixture.executeTool(fixer, 'agent_teams_claim_task', { task_id: 't1', assignee: '' })
310
+ assert.equal(blank.isError, false, JSON.stringify(blank))
311
+ assert.doesNotMatch(JSON.stringify(blank), /members cannot set assignee when claiming a task/)
312
+ assert.equal(blank.value.assignee, 'fixer')
313
+ assert.equal(blank.value.status, 'claimed')
314
+ assert.equal(typeof blank.value.attempt_id, 'string')
315
+ let team = await fixture.loadTeam(teamId)
316
+ assert.equal(team.tasks.find(entry => entry.id === 't1').status, 'claimed')
317
+ assert.equal(team.tasks.find(entry => entry.id === 't1').attemptId, blank.value.attempt_id)
318
+
319
+ // Restating the caller's own member name asks for exactly what a claim does;
320
+ // the retry the gateway produced must return the same attempt, not an error.
321
+ const selfNamed = await fixture.executeTool(fixer, 'agent_teams_claim_task', { task_id: 't1', assignee: 'fixer' })
322
+ assert.equal(selfNamed.isError, false, JSON.stringify(selfNamed))
323
+ assert.doesNotMatch(JSON.stringify(selfNamed), /members cannot set assignee when claiming a task/)
324
+ assert.equal(selfNamed.value.assignee, 'fixer')
325
+ assert.equal(selfNamed.value.attempt_id, blank.value.attempt_id)
326
+
327
+ const padded = await fixture.executeTool(fixer, 'agent_teams_claim_task', { task_id: 't1', assignee: ' fixer ' })
328
+ assert.equal(padded.isError, false, JSON.stringify(padded))
329
+ assert.equal(padded.value.attempt_id, blank.value.attempt_id)
330
+
331
+ team = await fixture.loadTeam(teamId)
332
+ assert.equal(team.tasks.find(entry => entry.id === 't1').assignee, 'fixer')
333
+ } finally {
334
+ await fixture.dispose()
335
+ }
336
+ })
337
+
338
+ await test('a member claim still rejects redirecting the assignee at another member (issue #234 follow-up)', async () => {
339
+ const { fixture, fixer, teamId } = await mountRunningTeam()
340
+ try {
341
+ const result = await fixture.executeTool(fixer, 'agent_teams_claim_task', { task_id: 't2', assignee: 'scout' })
342
+ assert.equal(result.isError, true, JSON.stringify(result))
343
+ assert.match(JSON.stringify(result), /members cannot set assignee when claiming a task/)
344
+ const team = await fixture.loadTeam(teamId)
345
+ const task = team.tasks.find(entry => entry.id === 't2')
346
+ assert.equal(task.status, 'pending')
347
+ assert.equal(task.assignee, 'scout')
348
+ assert.equal(task.attemptId, undefined)
349
+ } finally {
350
+ await fixture.dispose()
351
+ }
352
+ })
353
+
354
+ await test('a captain claim ignores a blank materialized assignee (issue #234 follow-up)', async () => {
355
+ const { fixture, captain, teamId } = await mountRunningTeam()
356
+ try {
357
+ const result = await fixture.executeTool(captain, 'agent_teams_claim_task', { task_id: 't3', assignee: ' ' })
358
+ assert.equal(result.isError, false, JSON.stringify(result))
359
+ assert.doesNotMatch(JSON.stringify(result), /captains must use agent_teams_reassign_task/)
360
+ assert.equal(result.value.assignee, 'captain')
361
+ assert.equal(result.value.attempt_id, 'captain-attempt-1')
362
+ const team = await fixture.loadTeam(teamId)
363
+ assert.equal(team.tasks.find(entry => entry.id === 't3').assignee, 'captain')
364
+ } finally {
365
+ await fixture.dispose()
366
+ }
367
+ })
368
+
369
+ await test('a captain claim still rejects a non-empty assignee (issue #234 follow-up)', async () => {
370
+ const { fixture, captain } = await mountRunningTeam()
371
+ try {
372
+ const result = await fixture.executeTool(captain, 'agent_teams_claim_task', { task_id: 't1', assignee: 'fixer' })
373
+ assert.equal(result.isError, true, JSON.stringify(result))
374
+ assert.match(JSON.stringify(result), /captains must use agent_teams_reassign_task/)
375
+ } finally {
376
+ await fixture.dispose()
377
+ }
378
+ })
379
+
380
+ await test('a member cannot claim a task assigned to another member (issue #234 follow-up)', async () => {
381
+ const { fixture, fixer, teamId } = await mountRunningTeam()
382
+ try {
383
+ // Both gateway shapes must hit the ownership guard: a materialized blank and
384
+ // the caller restating its own name. Neither may take scout's task.
385
+ for (const assignee of ['', 'fixer']) {
386
+ const before = (await fixture.loadTeam(teamId)).tasks.find(entry => entry.id === 't2')
387
+ assert.equal(before.assignee, 'scout')
388
+ assert.equal(before.status, 'pending')
389
+ const result = await fixture.executeTool(fixer, 'agent_teams_claim_task', { task_id: 't2', assignee })
390
+ assert.equal(result.isError, true, JSON.stringify(result))
391
+ // The ownership guard names the actual owner, so the rejection is diagnosable.
392
+ assert.match(result.error.message, /^task t2 is assigned to "scout", not you$/)
393
+ const after = (await fixture.loadTeam(teamId)).tasks.find(entry => entry.id === 't2')
394
+ assert.equal(after.assignee, 'scout')
395
+ assert.equal(after.status, 'pending')
396
+ assert.equal(after.attempt, 0)
397
+ assert.equal(after.attemptId, undefined)
398
+ assert.notEqual(after.assignee, 'fixer')
399
+ }
400
+ } finally {
401
+ await fixture.dispose()
402
+ }
403
+ })
404
+
405
+ await test('a captain cannot read a member attempt through a blank assignee (issue #234 follow-up)', async () => {
406
+ // scout already holds this task, so the attempt id belongs to a member (#125).
407
+ const { fixture, captain, teamId } = await mountRunningTeam([
408
+ { id: 't4', subject: 'member claimed task', status: 'claimed', assignee: 'scout', dependencies: [], attempt: 1, attemptId: 'member-attempt-1', createdAt: Date.now(), updatedAt: Date.now() },
409
+ ])
410
+ try {
411
+ const result = await fixture.executeTool(captain, 'agent_teams_claim_task', { task_id: 't4', assignee: '' })
412
+ assert.equal(result.isError, true, JSON.stringify(result))
413
+ assert.match(result.error.message, /captains must use agent_teams_reassign_task/)
414
+ // The member's capability must not leak through the captain's read.
415
+ assert.doesNotMatch(JSON.stringify(result), /member-attempt-1/)
416
+ const task = (await fixture.loadTeam(teamId)).tasks.find(entry => entry.id === 't4')
417
+ assert.equal(task.assignee, 'scout')
418
+ assert.equal(task.status, 'claimed')
419
+ assert.equal(task.attempt, 1)
420
+ assert.equal(task.attemptId, 'member-attempt-1')
421
+ } finally {
422
+ await fixture.dispose()
423
+ }
424
+ })
@@ -0,0 +1,63 @@
1
+ // Direct-module regression for #236. Only the plugin's imported format constant
2
+ // is fault-injected; this is not a mixed-install or CLI Loader end-to-end test.
3
+ import test from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import { spawnSync } from 'node:child_process';
6
+ import { resolve } from 'node:path';
7
+
8
+ await test('live format 4 survives a resolved module reporting format 0', () => {
9
+ const root = resolve(import.meta.dirname, '..');
10
+ const probe = String.raw`
11
+ import assert from 'node:assert/strict';
12
+ import { createRequire, registerHooks } from 'node:module';
13
+ import { pathToFileURL } from 'node:url';
14
+ import { join } from 'node:path';
15
+ const root = process.argv[1];
16
+ const url = name => pathToFileURL(join(root, 'lib', name + '.js')).href;
17
+ const compatUrl = url('harness-compat');
18
+ let injected = 0;
19
+ const hook = registerHooks({resolve(specifier, context, nextResolve) {
20
+ const actual = nextResolve(specifier, context);
21
+ if (specifier !== '@deepseek-ai/dsh-session' || context.parentURL !== compatUrl) return actual;
22
+ injected++;
23
+ return {url: 'data:text/javascript,' + encodeURIComponent(
24
+ 'export * from ' + JSON.stringify(actual.url) + '; export const SESSION_FORMAT_VERSION = 0;'
25
+ ), shortCircuit: true};
26
+ }});
27
+ try {
28
+ const compat = await import(compatUrl);
29
+ assert.equal(injected, 1, 'the stale-constant seam must actually be exercised');
30
+ assert.equal(compat.hostSessionFormatVersion(), 0);
31
+ assert.equal(compat.hostSessionFormatVersion(4), 4, 'the live format must outrank the stale module');
32
+ const modern = {kind:'agent-teams'};
33
+ const legacy = {kind:'plugin',plugin:'@nanmicoder/dsh-agent-teams'};
34
+ const agent = {session:{header:{version:4}}};
35
+ assert.equal(compat.observedSessionFormatVersion(agent), 4);
36
+ assert.deepEqual(compat.agentTeamsSource(modern, 4), modern);
37
+ assert.deepEqual(compat.agentTeamsSource(modern, 2), legacy);
38
+ assert.deepEqual(compat.agentTeamsSource(modern), legacy);
39
+
40
+ const {installAgentTeamsGestureBoundary} = await import(url('command'));
41
+ const require = createRequire(pathToFileURL(join(root, 'package.json')));
42
+ const {createUserMessage} = await import(pathToFileURL(require.resolve('@deepseek-ai/dsh-llm')).href);
43
+ let listener;
44
+ installAgentTeamsGestureBoundary({on(event, callback) {
45
+ assert.equal(event, 'agent/pre-step'); listener = callback;
46
+ }});
47
+ const messages = [createUserMessage({content:[{type:'text',text:'/agent-teams inspect this task'}],source:{kind:'user'}})];
48
+ const result = await listener({agent,messages,signal:new AbortController().signal}, async()=>({kind:'enter',messages}));
49
+ assert.equal(result.kind, 'enter');
50
+ assert.equal(result.messages.at(-1).source.kind, 'agent-teams-command', 'gesture must pass the live observation');
51
+
52
+ const queued = [];
53
+ const runtime = {[Symbol.for('dsh.subagent.deliverPrompt')](_parent,_child,_content,source) {queued.push(source);return 'message-id'}};
54
+ await compat.queueMemberPrompt(runtime,agent,'child',[{type:'text',text:'job'}],new AbortController().signal);
55
+ await compat.steerMemberPrompt(runtime,agent,'child',[{type:'text',text:'coordination'}],new AbortController().signal,agent);
56
+ assert.deepEqual(queued,[modern,modern], 'both member delivery paths must observe the live session');
57
+ console.log('ISSUE_236_STALE_MODULE_OK');
58
+ } finally { hook.deregister(); }
59
+ `;
60
+ const result = spawnSync(process.execPath, ['--input-type=module', '-e', probe, root], {encoding:'utf8',timeout:30000});
61
+ assert.equal(result.status, 0, result.error?.message ?? result.stderr);
62
+ assert.match(result.stdout, /ISSUE_236_STALE_MODULE_OK/);
63
+ });
@@ -0,0 +1,59 @@
1
+ // Issue #236 regression: the stored session format must be observed on the
2
+ // running host, not read back from a nested `@deepseek-ai/dsh-session` copy.
3
+ //
4
+ // A profile can resolve the plugin's own DSH package line while the process
5
+ // loading it runs another generation (pinned lockfile, Desktop shell with an
6
+ // embedded core, duplicated store). That copy reported SESSION_FORMAT_VERSION 0
7
+ // on a v4 host, so `agentTeamsSource()` selected the retired `plugin` wrapper
8
+ // and the host's writer rejected every durable AgentTeams message:
9
+ //
10
+ // format v4 message requires a producer-owned source kind
11
+ //
12
+ // These cases pin the contract in both directions: a live v4 header outranks
13
+ // the resolved module, a pre-v3 header still gets the released wrapper, and a
14
+ // host that exposes no header version keeps the old fallback.
15
+ import { test } from 'node:test'
16
+ import assert from 'node:assert/strict'
17
+ import { agentTeamsSource, hostSessionFormatVersion, observedSessionFormatVersion } from '../lib/harness-compat.js'
18
+ import { steerCaptainReport } from '../lib/members.js'
19
+
20
+ const releasedWrapper = { kind: 'plugin', plugin: '@nanmicoder/dsh-agent-teams' }
21
+ const modern = { kind: 'agent-teams' }
22
+ const command = { kind: 'agent-teams-command', goal: 'report on the plugin' }
23
+ const captain = version => ({ session: { header: { version } }, steer() {} })
24
+
25
+ await test('a live v4 session outranks a stale resolved module constant', () => {
26
+ const agent = captain(4)
27
+ assert.equal(observedSessionFormatVersion(agent), 4)
28
+ assert.equal(hostSessionFormatVersion(observedSessionFormatVersion(agent)), 4)
29
+ assert.deepEqual(agentTeamsSource(modern, observedSessionFormatVersion(agent)), modern)
30
+ assert.deepEqual(agentTeamsSource(command, observedSessionFormatVersion(agent)), command)
31
+ })
32
+
33
+ await test('a pre-v3 session keeps the released plugin wrapper', () => {
34
+ assert.deepEqual(agentTeamsSource(modern, observedSessionFormatVersion(captain(2))), releasedWrapper)
35
+ })
36
+
37
+ await test('an absent observation falls back to the resolved module, unchanged', () => {
38
+ assert.equal(observedSessionFormatVersion(undefined), undefined)
39
+ assert.equal(observedSessionFormatVersion({}), undefined)
40
+ assert.equal(observedSessionFormatVersion({ session: {} }), undefined)
41
+ assert.equal(observedSessionFormatVersion({ session: { header: {} } }), undefined)
42
+ assert.equal(observedSessionFormatVersion({ session: { header: { version: 'v4' } } }), undefined)
43
+ const fallback = hostSessionFormatVersion()
44
+ assert.deepEqual(
45
+ agentTeamsSource(modern, undefined),
46
+ fallback >= 3 ? modern : releasedWrapper,
47
+ )
48
+ })
49
+
50
+ await test('a captain report through a real call site uses the live header', () => {
51
+ const steered = []
52
+ const live = {
53
+ session: { header: { version: 4 } },
54
+ steer(message) { steered.push(message) },
55
+ }
56
+ assert.equal(steerCaptainReport(live, 'member-1', 'done'), true)
57
+ assert.equal(steered.length, 1)
58
+ assert.deepEqual(steered[0].source, modern)
59
+ })
@@ -0,0 +1,98 @@
1
+ // #262: preserve claimed as a lifecycle fact, across snapshot and actual panel rendering.
2
+ // SSR stubs only unrelated host UI imports and CSS modules. It is not a browser/Windows test.
3
+ import test from 'node:test'
4
+ import assert from 'node:assert/strict'
5
+ import { registerHooks } from 'node:module'
6
+ import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises'
7
+ import { tmpdir } from 'node:os'
8
+ import { join } from 'node:path'
9
+ import React from 'react'
10
+ import { renderToStaticMarkup } from 'react-dom/server'
11
+ import { assembleTeamSnapshot } from '../lib/snapshot.js'
12
+ import { beginTaskAttempt, taskVisualState, writeTeam, readTeam } from '../lib/state.js'
13
+ import { zh, en } from '../lib/client/locales.js'
14
+
15
+ const hook = registerHooks({ resolve(specifier, context, next) {
16
+ let source
17
+ if (specifier.endsWith('.module.css')) source = 'export default new Proxy({}, {get: (_, key) => key})'
18
+ if (context.parentURL?.endsWith('/client/ActivityPanel.js')) {
19
+ if (specifier === '@deepseek-ai/dsh-client-ui-primitives') source = 'export const Modal = () => null'
20
+ if (specifier === './AgentTeamsCard.js') source = 'export const OPEN_PANEL_EVENT = "test-open"'
21
+ if (specifier === './StagingPlanEditor.js') source = 'export const StagingPlanEditor = () => null'
22
+ }
23
+ return source === undefined ? next(specifier, context) : { url: `data:text/javascript,${encodeURIComponent(source)}`, shortCircuit: true }
24
+ }})
25
+ const { TeamSection } = await import('../lib/client/ActivityPanel.js')
26
+ hook.deregister()
27
+ const translate = dict => (key, values = {}) => dict[key].replace(/\{(\w+)\}/g, (_, name) => String(values[name]))
28
+ const render = (team, dict = en, extra = {}) => renderToStaticMarkup(React.createElement(TeamSection, {
29
+ team, t: translate(dict), onNavigate() {}, ...extra,
30
+ }))
31
+ const baseTask = (id, status = 'pending', dependencies = []) => ({ id, subject: `Task ${id}`, status, dependencies, createdAt: 1, updatedAt: 1 })
32
+
33
+ async function snapshot(t, liveStatus = 'running') {
34
+ const root = await mkdtemp(join(tmpdir(), 'issue262-'))
35
+ t.after(() => rm(root, { recursive: true, force: true }))
36
+ const state = { id: 'test', name: 'Test', captainSessionId: 'captain', createdAt: 1, taskSeq: 3,
37
+ members: [{ id: 'member', name: 'worker', status: 'working', joinedAt: 1 }],
38
+ tasks: [baseTask('t1'), baseTask('t2'), baseTask('t3', 'pending', ['t1'])] }
39
+ beginTaskAttempt(state.tasks[0], 'worker')
40
+ await mkdir(join(root, 'test', 'inbox'), { recursive: true })
41
+ await writeTeam(root, state)
42
+ const ctx = { agents: { get: () => liveStatus === 'absent' ? undefined : { status: liveStatus } }, logger: { warn() {} } }
43
+ const before = await readTeam(root, 'test')
44
+ const projected = await assembleTeamSnapshot(ctx, root, root, before)
45
+ assert.deepEqual(await readTeam(root, 'test'), before, 'projection must not mutate durable status/attempt')
46
+ return { projected, root, ctx, state: before }
47
+ }
48
+
49
+ for (const status of ['running', 'idle', 'absent']) test(`claimed remains distinct with a ${status} owner`, async t => {
50
+ const { projected } = await snapshot(t, status)
51
+ assert.deepEqual(projected.tasks.map(task => [task.status, task.state]), [
52
+ ['claimed', 'claimed'], ['pending', 'open'], ['pending', 'blocked'],
53
+ ])
54
+ })
55
+
56
+ test('snapshot reaches sidebar and workspace legends, summary, DAG and assignment chips', async t => {
57
+ const { projected } = await snapshot(t)
58
+ for (const dict of [en, zh]) for (const workspace of [false, true]) {
59
+ const html = render(projected, dict, { workspace })
60
+ if (process.env.ISSUE262_CAPTURE_DIR && dict === en && workspace) await writeFile(join(process.env.ISSUE262_CAPTURE_DIR, 'panel.html'), html)
61
+ assert.match(html, /data-task-id="t1" data-state="claimed"/)
62
+ assert.match(html, new RegExp(`<span data-state="claimed">■ ${dict === en ? 'Claimed 1' : '已认领 1'}</span>`))
63
+ assert.match(html, new RegExp(dict === en ? 'Claimed: t1' : '已认领:t1'))
64
+ assert.doesNotMatch(html, new RegExp(dict === en ? 'Ready: t1' : 't1.*等待领取'))
65
+ assert.match(html, new RegExp(`<span class="dagClaimedState">${dict['task.status.claimed']}</span>`))
66
+ assert.match(html, /data-task-id="t2" data-state="open"/)
67
+ assert.match(html, /data-task-id="t3" data-state="blocked"/)
68
+ assert.match(html, /class="assignmentChip"[^>]*data-state="claimed"/)
69
+ }
70
+ })
71
+
72
+ test('in_progress and terminal states keep their meanings', async t => {
73
+ const { projected } = await snapshot(t)
74
+ for (const [status, visual] of [['in_progress', 'running'], ['completed', 'completed'], ['failed', 'failed'], ['cancelled', 'cancelled']]) {
75
+ assert.equal(taskVisualState(status, ['t3'], []), visual)
76
+ const team = { ...projected, tasks: [{ ...projected.tasks[0], status, state: visual, dependencies: [] }] }
77
+ const html = render(team)
78
+ assert.match(html, new RegExp(`data-task-id="t1" data-state="${visual}"`))
79
+ assert.match(html, new RegExp(`In progress ${status === 'in_progress' ? 1 : 0}`))
80
+ assert.doesNotMatch(html, /Claimed 1|Claimed: t1/)
81
+ }
82
+ })
83
+
84
+ test('discarded staged plans never claim an active task', async t => {
85
+ const { projected } = await snapshot(t)
86
+ const html = render({ ...projected, phase: 'staged' }, en, { historic: true })
87
+ assert.match(html, /data-task-id="t1" data-state="cancelled"/)
88
+ assert.doesNotMatch(html, /Claimed 1|Claimed: t1/)
89
+ })
90
+
91
+ test('claimed precedence and mixed failed work do not masquerade as blocked or settled', async t => {
92
+ assert.equal(taskVisualState('claimed', ['waiting'], [baseTask('waiting')]), 'claimed')
93
+ const { projected } = await snapshot(t)
94
+ const team = { ...projected, tasks: [projected.tasks[0], { ...projected.tasks[1], status: 'failed', state: 'failed' }] }
95
+ const html = render(team)
96
+ assert.match(html, /Claimed: t1/)
97
+ assert.doesNotMatch(html, /automatic loop has stopped/)
98
+ })