@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,45 @@
1
+ import { execFileSync } from 'node:child_process'
2
+ import { readFileSync } from 'node:fs'
3
+ import { pathToFileURL } from 'node:url'
4
+ import { policy, validatePackageCompatibility } from './compatibility.mjs'
5
+
6
+ // Keep prereleases away from npm's default channel, including manual publishes.
7
+ export function releaseMetadata(pkg, support = policy, workspace) {
8
+ const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(alpha|beta|rc)\.(0|[1-9]\d*))?$/.exec(pkg.version)
9
+ if (!match || match[0] !== pkg.version) throw new Error(`Unsupported release version: ${pkg.version}`)
10
+ validatePackageCompatibility(pkg, support, workspace)
11
+ const distTag = match[4] ? support.previewTag : 'latest'
12
+ if (pkg.publishConfig?.tag !== distTag) {
13
+ throw new Error(`publishConfig.tag must be "${distTag}" for ${pkg.version}`)
14
+ }
15
+ if (!match[4] && pkg.devDependencies['@deepseek-ai/dsh'] !== support.recommendedHost) {
16
+ throw new Error('latest must use the recommended host as its development baseline')
17
+ }
18
+ return { value: pkg.version, dist_tag: distTag, prerelease: Boolean(match[4]) }
19
+ }
20
+
21
+ export function assertReleaseTagTarget(version, refs, commit) {
22
+ if (!/^[a-f0-9]{40}$/.test(commit)) throw new Error('Expected the full release commit SHA')
23
+ const tag = `refs/tags/v${version}`
24
+ const targets = new Map(refs.trim().split('\n').filter(Boolean).map(line => {
25
+ const [sha, ref] = line.split('\t')
26
+ return [ref, sha]
27
+ }))
28
+ const actual = targets.get(`${tag}^{}`) ?? targets.get(tag)
29
+ if (actual !== undefined && actual !== commit) {
30
+ throw new Error(`Release tag v${version} points to ${actual}, expected ${commit}`)
31
+ }
32
+ }
33
+
34
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
35
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
36
+ const metadata = releaseMetadata(pkg)
37
+ if (process.argv[2] === '--verify-tag-target') {
38
+ const tag = `refs/tags/v${metadata.value}`
39
+ const commit = execFileSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf8' }).trim()
40
+ const refs = execFileSync('git', ['ls-remote', 'origin', tag, `${tag}^{}`], { encoding: 'utf8' })
41
+ assertReleaseTagTarget(metadata.value, refs, commit)
42
+ } else {
43
+ for (const [key, value] of Object.entries(metadata)) console.log(`${key}=${value}`)
44
+ }
45
+ }
@@ -0,0 +1,66 @@
1
+ import assert from 'node:assert/strict'
2
+ import { readFileSync } from 'node:fs'
3
+ import test from 'node:test'
4
+ import { assertReleaseTagTarget, releaseMetadata } from './release-metadata.mjs'
5
+ import { policy, workspacePolicy } from './compatibility.mjs'
6
+
7
+ const fixture = (version, tag) => ({
8
+ ...JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')),
9
+ version, publishConfig: { tag },
10
+ })
11
+
12
+ test('stable latest requires the recommended host and bounded compatibility', () => {
13
+ assert.deepEqual(releaseMetadata(fixture('0.1.16', 'latest')), {
14
+ value: '0.1.16', dist_tag: 'latest', prerelease: false,
15
+ })
16
+ const alphaOnly = fixture('0.1.16', 'latest')
17
+ for (const name of Object.keys(alphaOnly.devDependencies)) {
18
+ if (name === '@deepseek-ai/dsh' || name.startsWith('@deepseek-ai/dsh-')) alphaOnly.devDependencies[name] = '0.1.2-alpha.2'
19
+ }
20
+ const workspace = structuredClone(workspacePolicy)
21
+ for (const name of Object.keys(workspace.overrides)) {
22
+ if (name === '@deepseek-ai/dsh' || name.startsWith('@deepseek-ai/dsh-')) workspace.overrides[name] = '0.1.2-alpha.2'
23
+ }
24
+ assert.throws(() => releaseMetadata(alphaOnly, policy, workspace), /recommended host/)
25
+ assert.throws(() => releaseMetadata(fixture('0.1.16', 'latest'), {
26
+ ...policy, recommendedHost: '0.1.2-alpha.2',
27
+ supportedHosts: [{ version: '0.1.2-alpha.2', track: 'recommended' }],
28
+ }), /Alpha\/beta/)
29
+ })
30
+
31
+ for (const suffix of ['alpha', 'beta', 'rc']) {
32
+ test(`${suffix} candidates use next and never replace latest`, () => {
33
+ const version = `0.1.16-${suffix}.1`
34
+ assert.equal(releaseMetadata(fixture(version, 'next')).prerelease, true)
35
+ for (const tag of [undefined, 'latest', suffix]) {
36
+ assert.throws(() => releaseMetadata(fixture(version, tag)), /publishConfig.tag/)
37
+ }
38
+ })
39
+ }
40
+
41
+ test('reject unsupported versions and bounded or listed peers', () => {
42
+ for (const version of ['0.1.16-dev.1', '0.1.16-alpha.01', '0.1.16-alpha.1\n', 'v0.1.16', '0.1']) {
43
+ assert.throws(() => releaseMetadata(fixture(version, 'next')))
44
+ }
45
+ const mixed = fixture('0.1.16-rc.1', 'next')
46
+ mixed.peerDependencies['@deepseek-ai/dsh-agent'] = '^0.1.2-alpha.2'
47
+ assert.throws(() => releaseMetadata(mixed), /peer range must enumerate/)
48
+ })
49
+
50
+ test('checked-in candidate has consistent dependency and release metadata', () => {
51
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
52
+ assert.equal(releaseMetadata(pkg).dist_tag, pkg.publishConfig.tag)
53
+ })
54
+
55
+ test('a release can create its tag or reuse a tag at the verified commit', () => {
56
+ const version = '0.1.29'
57
+ const tag = `refs/tags/v${version}`
58
+ const commit = 'a'.repeat(40)
59
+ const other = 'b'.repeat(40)
60
+ const annotation = 'c'.repeat(40)
61
+ assertReleaseTagTarget(version, '', commit)
62
+ assertReleaseTagTarget(version, `${commit}\t${tag}\n`, commit)
63
+ assertReleaseTagTarget(version, `${annotation}\t${tag}\n${commit}\t${tag}^{}\n`, commit)
64
+ assert.throws(() => assertReleaseTagTarget(version, `${other}\t${tag}\n`, commit), /points to/)
65
+ assert.throws(() => assertReleaseTagTarget(version, `${annotation}\t${tag}\n${other}\t${tag}^{}\n`, commit), /points to/)
66
+ })
@@ -0,0 +1,52 @@
1
+ import assert from 'node:assert/strict'
2
+ import { existsSync, readFileSync } from 'node:fs'
3
+ import test from 'node:test'
4
+
5
+ const text = path => readFileSync(new URL(`../${path}`, import.meta.url), 'utf8')
6
+ const pkg = JSON.parse(text('package.json'))
7
+ // Vendored as a dsh-fish workspace member: CI workflows are not part of the
8
+ // package (the monorepo owns its own release flow), so workflow assertions
9
+ // only run in a standalone checkout that ships its own .github directory.
10
+ const hasWorkflows = existsSync(new URL('../.github/workflows/publish.yml', import.meta.url))
11
+ && existsSync(new URL('../.github/workflows/verify.yml', import.meta.url))
12
+
13
+ test('2.0.0 release uses the Fish scope throughout the install contract', () => {
14
+ assert.equal(pkg.name, '@fish-under-sea/dsh-agent-teams-fish')
15
+ assert.equal(pkg.version, '2.0.0')
16
+ assert.ok(text('cordis.patch.yml').includes("name: '@fish-under-sea/dsh-agent-teams-fish'"))
17
+ assert.ok(text('scripts/doctor.mjs').includes("locatePackage('@fish-under-sea/dsh-agent-teams-fish'"))
18
+ })
19
+
20
+ test('both public READMEs document the scoped 2.0.0 install', () => {
21
+ for (const file of ['README.md', 'README.en.md']) {
22
+ assert.ok(text(file).includes('@fish-under-sea/dsh-agent-teams-fish@2.0.0'), file)
23
+ }
24
+ })
25
+
26
+ test('runtime verification and benchmarks resolve the scoped installation path', () => {
27
+ for (const file of ['scripts/harness-runtime-verify.mjs', 'scripts/harness-runtime-scenarios.mjs', 'scripts/harness-model-benchmark.mjs']) {
28
+ assert.ok(!text(file).includes('node_modules/dsh-agent-teams-fish'), file)
29
+ assert.ok(text(file).includes('node_modules/@fish-under-sea/dsh-agent-teams-fish'), file)
30
+ }
31
+ })
32
+
33
+ test('publish workflow checks the current package identity before publishing', t => {
34
+ if (!hasWorkflows) return t.skip('no .github workflows in the vendored workspace member')
35
+ const workflow = text('.github/workflows/publish.yml')
36
+ assert.ok(workflow.includes('PACKAGE_NAME: ${{ steps.version.outputs.package_name }}'))
37
+ assert.ok(workflow.includes('npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}"'))
38
+ assert.ok(workflow.includes('npm view "${PACKAGE_NAME}" dist-tags.latest'))
39
+ })
40
+
41
+ test('verification is manual-only and tag publishing has no verification dependency', t => {
42
+ if (hasWorkflows) {
43
+ const verify = text('.github/workflows/verify.yml')
44
+ assert.ok(verify.includes('workflow_dispatch:'))
45
+ for (const trigger of ['pull_request:', 'branches: [main]', 'workflow_call:']) assert.ok(!verify.includes(trigger), trigger)
46
+ const publish = text('.github/workflows/publish.yml')
47
+ assert.ok(!publish.includes('uses: ./.github/workflows/verify.yml'))
48
+ assert.ok(!publish.includes('needs: verify'))
49
+ assert.ok(!publish.includes('scripts/release-metadata.mjs'))
50
+ }
51
+ assert.equal(JSON.parse(text('package.json')).scripts.prepublishOnly, undefined)
52
+ })
@@ -0,0 +1,144 @@
1
+ import assert from 'node:assert/strict'
2
+ import { test } from 'node:test'
3
+ import { mkdtemp, rm } from 'node:fs/promises'
4
+ import { tmpdir } from 'node:os'
5
+ import { join } from 'node:path'
6
+ import { createTeamDir, createMessage, appendMailbox, readMailbox, readUnreadMailbox, readPendingMailbox, markMailboxDelivered, writeTeam } from '../lib/state.js'
7
+ import { canDeclareDelivery } from '../lib/quality-gates.js'
8
+ import { installMailboxAdmission, mailboxPrompt } from '../lib/mailbox.js'
9
+ import { installMemberSelectionRuntime, installMemberDelegationGuard } from '../lib/members.js'
10
+ import { steerMemberPrompt } from '../lib/harness-compat.js'
11
+
12
+ function team() { return { id: 'team', name: 'Team', captainSessionId: 'captain', createdAt: 1, taskSeq: 1,
13
+ members: [{ id: 'worker', name: 'worker', joinedAt: 1, status: 'working' }],
14
+ tasks: [{ id: 't1', subject: 'Work', assignee: 'worker', status: 'in_progress', attempt: 1, attemptId: 'a1', dependencies: [], createdAt: 1, updatedAt: 1 }],
15
+ } }
16
+ async function fixture(t) {
17
+ const workspace = await mkdtemp(join(tmpdir(), 'teams-stability-'))
18
+ t.after(() => rm(workspace, { recursive: true, force: true }))
19
+ const root = join(workspace, '.agent-teams'), state = team()
20
+ await createTeamDir(root, state)
21
+ const handlers = new Map()
22
+ const ctx = { on(name, fn) { handlers.set(name, fn); return () => handlers.delete(name) }, effect(fn) { return fn() }, logger: { warn() {} } }
23
+ return { root, workspace, state, ctx, handlers }
24
+ }
25
+
26
+ await test('work, empty, staged, halted and escalated teams cannot falsely declare delivery', () => {
27
+ const state = team()
28
+ for (const status of ['pending', 'claimed', 'in_progress', 'failed']) {
29
+ state.tasks[0].status = status
30
+ assert.equal(canDeclareDelivery(state).ok, false, status)
31
+ }
32
+ state.tasks[0].status = 'completed'
33
+ assert.equal(canDeclareDelivery(state).ok, true)
34
+ for (const extra of [{ phase: 'staged' }, { halted: true }, { escalated: true }, { tasks: [] }]) assert.equal(canDeclareDelivery({ ...state, ...extra }).ok, false)
35
+ })
36
+
37
+ await test('inbox acceptance leaves 32 messages unread; one admitted step consumes them exactly once', async t => {
38
+ const h = await fixture(t)
39
+ installMailboxAdmission(h.ctx, '.agent-teams')
40
+ const messages = Array.from({ length: 32 }, (_, n) => ({ ...createMessage('captain', 'worker', `guidance-${n}`), taskId: 't1', attemptId: 'a1' }))
41
+ for (const message of messages) await appendMailbox(h.root, 'team', 'worker', message)
42
+ await markMailboxDelivered(h.root, 'team', 'worker', messages.map(m => m.id))
43
+ assert.equal((await readUnreadMailbox(h.root, 'team', 'worker')).length, 32)
44
+ assert.equal((await readPendingMailbox(h.root, 'team', 'worker')).length, 0, 'delivered input must not be redelivered by fallback')
45
+ const input = { id: 'host-message', content: [{ type: 'text', text: mailboxPrompt('team', 'worker', messages) }] }
46
+ const payload = { agent: { id: 'worker', session: { header: { cwd: h.workspace }, ownEvents: () => [] } } }
47
+ const admit = () => h.handlers.get('agent/pre-step')(payload, async () => ({ kind: 'enter', messages: [input] }))
48
+ await h.handlers.get('agent/pre-step')(payload, async () => ({ kind: 'reject' }))
49
+ assert.equal((await readUnreadMailbox(h.root, 'team', 'worker')).length, 32, 'rejected step is not consumption')
50
+ assert.equal((await admit()).messages.length, 1)
51
+ assert.equal((await readUnreadMailbox(h.root, 'team', 'worker')).length, 0)
52
+ assert.equal((await admit()).kind, 'reject', 'duplicate wake spends no model call')
53
+ payload.turn = 7
54
+ payload.agent.session.ownEvents = () => [{ type: 'turn/start', data: { turn: 7 } }, { type: 'step/start', data: { turn: 7, step: 1 } }]
55
+ assert.deepEqual(await admit(), { kind: 'enter', messages: [] }, 'already-read mail must not interrupt a pending tool-result continuation')
56
+ })
57
+
58
+ await test('old-generation guidance is discarded while current mail survives the same batch', async t => {
59
+ const h = await fixture(t)
60
+ installMailboxAdmission(h.ctx, '.agent-teams')
61
+ const stale = { ...createMessage('captain', 'worker', 'STALE'), taskId: 't1', attemptId: 'old' }
62
+ const current = { ...createMessage('captain', 'worker', 'CURRENT'), taskId: 't1', attemptId: 'a1' }
63
+ for (const message of [stale, current]) await appendMailbox(h.root, 'team', 'worker', message)
64
+ const decision = await h.handlers.get('agent/pre-step')({ agent: { id: 'worker', session: { header: { cwd: h.workspace }, ownEvents: () => [] } } }, async () => ({ kind: 'enter', messages: [{ content: [{ type: 'text', text: 'Agent captain sent a message:' }, { type: 'text', text: mailboxPrompt('team', 'worker', [stale, current]) }] }] }))
65
+ assert.match(decision.messages[0].content[0].text, /CURRENT/)
66
+ assert.doesNotMatch(decision.messages[0].content[0].text, /STALE/)
67
+ const rows = await readMailbox(h.root, 'team', 'worker')
68
+ assert.ok(rows[0].discardedAt); assert.equal(rows[0].readAt, undefined); assert.ok(rows[1].readAt)
69
+ })
70
+
71
+ await test('reported completion suppresses only redundant native success settlements', async t => {
72
+ const h = await fixture(t)
73
+ installMailboxAdmission(h.ctx, '.agent-teams')
74
+ h.state.tasks[0].status = 'completed'
75
+ await writeTeam(h.root, h.state)
76
+ const summary = 'Background subagent worker finished and will do no further work unless you send it more.'
77
+ const notice = { source: { kind: 'subagent-settled', senderSessionId: 'worker', summary }, content: [{ type: 'text', text: summary }] }
78
+ const payload = { agent: { id: 'captain', session: { header: { cwd: h.workspace }, ownEvents: () => [] } } }
79
+ const admit = messages => h.handlers.get('agent/pre-step')(payload, async () => ({ kind: 'enter', messages }))
80
+ assert.equal((await admit([notice])).messages.length, 1, 'unreported completion must still reach the captain')
81
+ const report = createMessage('worker', 'captain', 'Task t1 completed; concrete result.')
82
+ await appendMailbox(h.root, 'team', 'captain', report)
83
+ assert.equal((await admit([notice])).messages.length, 1, 'unaccepted mailbox report must not hide the fallback')
84
+ await markMailboxDelivered(h.root, 'team', 'captain', [report.id])
85
+ assert.equal((await admit([notice])).kind, 'reject', 'duplicate settlement must spend no model request')
86
+ const user = { source: { kind: 'user' }, content: [{ type: 'text', text: 'Continue with new work' }] }
87
+ assert.deepEqual((await admit([notice, user])).messages, [user], 'unrelated input must survive deduplication')
88
+ for (const altered of [
89
+ { ...notice, source: { ...notice.source, summary: 'Background subagent worker failed before it finished.' } },
90
+ { ...notice, source: { ...notice.source, senderSessionId: 'unrelated' } },
91
+ { ...notice, source: { kind: 'user' } },
92
+ ]) assert.equal((await admit([altered])).messages.length, 1)
93
+ h.state.tasks.push({ ...h.state.tasks[0], id: 't2', status: 'failed', updatedAt: Date.now() + 1 })
94
+ h.state.taskSeq = 2
95
+ await writeTeam(h.root, h.state)
96
+ assert.equal((await admit([notice])).messages.length, 1, 'an older report cannot hide a newer unsuccessful task')
97
+ h.state.tasks.pop()
98
+ h.state.tasks[0].status = 'in_progress'
99
+ await writeTeam(h.root, h.state)
100
+ assert.equal((await admit([notice])).messages.length, 1, 'unfinished work still needs settlement attention')
101
+ })
102
+
103
+ await test('next-step steering preserves the native delivery modes across all three contracts', async () => {
104
+ const signal = new AbortController().signal, calls = [], captain = { id: 'captain' }, content = [{ type: 'text', text: 'guidance' }]
105
+ const modern = { [Symbol.for('dsh.subagent.deliverPrompt')](...args) { assert.equal(this, modern); calls.push(args.at(-1)); return 'id' } }
106
+ await steerMemberPrompt(modern, captain, 'worker', content, signal)
107
+ assert.deepEqual(calls, ['steer'])
108
+ await steerMemberPrompt({ sendMessage() { calls.push('public-steer'); return 'id' } }, captain, 'worker', content, signal)
109
+ const legacy = { followup() { calls.push('cold'); return 'id' } }
110
+ await steerMemberPrompt(legacy, captain, 'worker', content, signal, { id: 'worker', session: { header: { parentSession: 'captain' } }, steer() { calls.push('live-steer') } })
111
+ await steerMemberPrompt(legacy, captain, 'worker', content, signal)
112
+ assert.deepEqual(calls, ['steer', 'public-steer', 'live-steer', 'cold'])
113
+ })
114
+
115
+ await test('internal wakeups and cold admission are rejected for stopped or retired members', async t => {
116
+ const h = await fixture(t), hooks = new Map()
117
+ const child = { id: 'worker', session: { header: { cwd: h.workspace, parentSession: 'captain' }, ownEvents: () => [{ type: 'subagent/descriptor', data: { version: 3, mode: 'continuable', provider: 'spawn', label: 'agent-teams:team:worker' } }] } }
118
+ let setup
119
+ h.ctx.subagents = { registerContinuableSetup(fn) { setup = fn } }
120
+ installMemberSelectionRuntime(h.ctx, '.agent-teams')
121
+ setup({ agent: child, on(name, fn) { hooks.set(name, fn); return () => hooks.delete(name) } })
122
+ const admit = () => hooks.get('agent/pre-step')({ agent: child }, async () => ({ kind: 'enter', messages: [] }))
123
+ assert.equal((await admit()).kind, 'enter')
124
+ h.state.members[0].stopping = true; await writeTeam(h.root, h.state)
125
+ assert.equal((await admit()).kind, 'reject')
126
+ h.state.members[0].stopping = false; h.state.members[0].status = 'removed'; await writeTeam(h.root, h.state)
127
+ assert.equal((await admit()).kind, 'reject')
128
+ await rm(join(h.root, 'team'), { recursive: true })
129
+ assert.equal((await admit()).kind, 'reject')
130
+ })
131
+
132
+ await test('member-relative delegation limit covers raw runtime calls and preserves unrelated siblings', async t => {
133
+ const h = await fixture(t), handles = new Map(), created = []
134
+ const captain = { id: 'captain', session: { header: { cwd: h.workspace }, ownEvents: () => [] } }
135
+ const worker = { id: 'worker', session: { header: { cwd: h.workspace, parentSession: 'captain' }, ownEvents: () => [{ type: 'subagent/descriptor', data: { version: 3, mode: 'continuable', provider: 'spawn', label: 'agent-teams:team:worker' } }] } }
136
+ handles.set('captain', captain); handles.set('worker', worker)
137
+ h.ctx.agents = { get: id => handles.get(id) }
138
+ h.ctx.subagents = { async start(_name, request) { created.push(request.parent.id) }, async startContinuable(spec) { created.push(spec.request.parent.id) } }
139
+ installMemberDelegationGuard(h.ctx, '.agent-teams', 0)
140
+ await assert.rejects(h.ctx.subagents.start('spawn', { parent: worker }), /delegation limit/)
141
+ await assert.rejects(h.ctx.subagents.startContinuable({ request: { parent: worker } }), /delegation limit/)
142
+ await h.ctx.subagents.start('spawn', { parent: captain })
143
+ assert.deepEqual(created, ['captain'])
144
+ })