@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,100 @@
1
+ // Issue #189 regression: member route composition.
2
+ //
3
+ // These are pure-function assertions over `composeMemberRoute`, the single
4
+ // place where the request/config/captain precedence is decided. They are
5
+ // deliberately NOT the acceptance evidence for #189 — the real Loader +
6
+ // DeepSeek Flash acceptance lives in the group's real-host run. This file only
7
+ // pins the composition policy that a previous attempt got wrong.
8
+ //
9
+ // Guarded cases:
10
+ // - a "/" inside a model id is part of that id and is never a separator
11
+ // - an explicitly requested model keeps the caller's provider (no silent
12
+ // owner discovery), while a model-only *configuration* default may be
13
+ // resolved by catalog
14
+ // - a named provider is never derived, so it can never be re-pointed
15
+ import { test } from 'node:test'
16
+ import assert from 'node:assert/strict'
17
+ import { composeMemberRoute } from '../lib/members.js'
18
+
19
+ const captain = { provider: 'aihub', model: 'gpt-5.6-sol' }
20
+
21
+ test('a slash inside a model id is preserved verbatim', () => {
22
+ const composed = composeMemberRoute(
23
+ { provider: 'openrouter', model: 'google/gemini-x' },
24
+ captain,
25
+ )
26
+ assert.deepEqual(composed, {
27
+ provider: { value: 'openrouter', source: 'request' },
28
+ model: { value: 'google/gemini-x', source: 'request' },
29
+ derivedProvider: false,
30
+ })
31
+ })
32
+
33
+ test('an explicitly requested model is never re-routed by owner discovery', () => {
34
+ const composed = composeMemberRoute({ model: 'deepseek-v4.1-flash' }, captain)
35
+ assert.deepEqual(composed, {
36
+ provider: { value: 'aihub', source: 'captain' },
37
+ model: { value: 'deepseek-v4.1-flash', source: 'request' },
38
+ derivedProvider: false,
39
+ })
40
+ })
41
+
42
+ test('a model-only configuration default is the only derived-provider shape', () => {
43
+ const composed = composeMemberRoute({ defaultModel: 'deepseek-v4.1-flash' }, captain)
44
+ assert.deepEqual(composed, {
45
+ provider: { value: 'aihub', source: 'captain' },
46
+ model: { value: 'deepseek-v4.1-flash', source: 'config' },
47
+ derivedProvider: true,
48
+ })
49
+ })
50
+
51
+ test('a configured provider is authoritative and never derived', () => {
52
+ const composed = composeMemberRoute(
53
+ { defaultModel: 'deepseek-v4.1-flash', defaultProvider: 'ollama-cloud' },
54
+ captain,
55
+ )
56
+ assert.deepEqual(composed, {
57
+ provider: { value: 'ollama-cloud', source: 'config' },
58
+ model: { value: 'deepseek-v4.1-flash', source: 'config' },
59
+ derivedProvider: false,
60
+ })
61
+ })
62
+
63
+ test('an explicit request pair wins over the configuration default', () => {
64
+ const composed = composeMemberRoute(
65
+ { provider: 'openrouter', model: 'google/gemini-x', defaultModel: 'deepseek-v4.1-flash', defaultProvider: 'ollama-cloud' },
66
+ captain,
67
+ )
68
+ assert.deepEqual(composed, {
69
+ provider: { value: 'openrouter', source: 'request' },
70
+ model: { value: 'google/gemini-x', source: 'request' },
71
+ derivedProvider: false,
72
+ })
73
+ })
74
+
75
+ test('a request model wins over the configuration default but keeps the captain provider', () => {
76
+ const composed = composeMemberRoute({ model: 'gpt-5.6-sol', defaultModel: 'deepseek-v4.1-flash' }, captain)
77
+ assert.deepEqual(composed, {
78
+ provider: { value: 'aihub', source: 'captain' },
79
+ model: { value: 'gpt-5.6-sol', source: 'request' },
80
+ derivedProvider: false,
81
+ })
82
+ })
83
+
84
+ test('pure captain inheritance stays the captain route', () => {
85
+ const composed = composeMemberRoute({}, captain)
86
+ assert.deepEqual(composed, {
87
+ provider: { value: 'aihub', source: 'captain' },
88
+ model: { value: 'gpt-5.6-sol', source: 'captain' },
89
+ derivedProvider: false,
90
+ })
91
+ })
92
+
93
+ test('a provider without a model cannot be composed', () => {
94
+ assert.equal(composeMemberRoute({ provider: 'openrouter' }, captain), undefined)
95
+ })
96
+
97
+ test('blank configured values are rejected instead of silently ignored', () => {
98
+ assert.equal(composeMemberRoute({ defaultProvider: ' ' }, captain), undefined)
99
+ assert.equal(composeMemberRoute({ defaultModel: '' }, captain), undefined)
100
+ })
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Issue #203 regression: a team card must resolve the host's canonical team id
3
+ * instead of re-deriving it from the display name.
4
+ *
5
+ * The client used to clean names with an ASCII-only whitelist while the host
6
+ * keeps Unicode letters and digits, so `数据团队` became `team` on the card and
7
+ * never matched its live team (empty roster, never-satisfied monitor target, and
8
+ * a bogus historic entry beside the real team in the activity panel).
9
+ *
10
+ * These tests import the BUILT client helper the browser bundle is generated
11
+ * from. The fixtures are the values recorded by the real runs documented in
12
+ * docs/issue-maintenance-2026-10-10/card/REPORT.md (dsh 0.2.0-rc.2 +
13
+ * deepseek-account/deepseek-flash); the canonical ids are re-checked against
14
+ * the real host key function rather than hard-coded twice.
15
+ */
16
+ import test from 'node:test'
17
+ import assert from 'node:assert/strict'
18
+ import {
19
+ agentTeamsCardDefinition,
20
+ parseAgentTeamsCreateArgs,
21
+ parseAgentTeamsCreateResult,
22
+ resultText,
23
+ teamIdFromCreateResultText,
24
+ teamKeyFromName,
25
+ } from '../lib/client/agent-teams-card-definition.js'
26
+ import { sanitizeKey } from '../lib/state.js'
27
+
28
+ // Real recorded runs (see REPORT.md section 5).
29
+ const REAL_CANDIDATE_SESSION = 'session-5b9c59ae-7b18-47ae-8b56-2cb4fe66b13c'
30
+ const REAL_MEMBERS = [
31
+ { id: '', name: '阿明', role: '工程师' },
32
+ { id: '', name: 'Léa', role: 'reviewer' },
33
+ ]
34
+ const LONG_NAME = '跨区域研发效能平台数据治理跨区域研发效能平台数据治理跨区域研发效能平台数据治理跨区域研发效能平台数据治理专项验证小组'
35
+ const EMOJI_NAME = '🚀🎯'
36
+
37
+ /** The exact renderings the create tool has produced since they were introduced. */
38
+ const runningText = (name, id, stateDir) => `Team "${name}" created (id ${id}) under ${stateDir}. You are the captain.`
39
+ const stagedText = (name, stateDir) => `Team "${name}" plan created under ${stateDir}. It is staged: finish the roster and DAG, then wait for the user to edit and approve it. Do not start or approve it yourself.`
40
+
41
+ /** Run one real create call plus its result through the card definition. */
42
+ function fold(createArguments, resultData = {}) {
43
+ const call = { type: 'tool/call', seq: 17, data: { callId: 'call_1', name: 'agent_teams_create', arguments: createArguments } }
44
+ const result = {
45
+ type: 'tool/result',
46
+ seq: 18,
47
+ data: {
48
+ turn: 1,
49
+ step: 1,
50
+ message: { role: 'tool', source: { kind: 'tool', callId: 'call_1' }, toolCallId: 'call_1', content: [], isError: false },
51
+ ...resultData,
52
+ },
53
+ }
54
+ const location = { kind: 'session' }
55
+ const startMatch = { event: call, role: 'start', location }
56
+ const base = { key: 'agent-teams:call_1', kind: 'agent-teams', id: 'call_1', target: 'chat' }
57
+ assert.equal(agentTeamsCardDefinition.match(call)?.role, 'start')
58
+ let context = { ...base, start: startMatch, state: agentTeamsCardDefinition.start({ ...base, start: startMatch }, startMatch) }
59
+ context = { ...context, state: agentTeamsCardDefinition.update(context, { event: result, role: 'update', location }) }
60
+ return { state: context.state, node: agentTeamsCardDefinition.buildViewNode(context) }
61
+ }
62
+
63
+ test('the client key mirrors the host key for names the host cleans without a digest', () => {
64
+ for (const name of ['数据团队', 'Équipe A', 'チーム1', 'Repo Review 2W!', ' Mixed Name ']) {
65
+ assert.equal(teamKeyFromName(name), sanitizeKey(name), `key parity for ${name}`)
66
+ }
67
+ assert.equal(teamKeyFromName('数据团队'), '数据团队')
68
+ assert.equal(teamKeyFromName('Équipe A'), 'équipe-a')
69
+ })
70
+
71
+ test('names needing the host digest or truncation stay divergent, so the canonical id is required', () => {
72
+ // Long names: the host truncates and appends a digest; the client cannot.
73
+ assert.equal([...LONG_NAME].length > 48, true)
74
+ assert.notEqual(teamKeyFromName(LONG_NAME), sanitizeKey(LONG_NAME))
75
+ assert.match(sanitizeKey(LONG_NAME), /-[\da-f]{8}$/u)
76
+ // Names with no letters or digits: the host digests the raw name; the client
77
+ // has no synchronous digest and keeps its legacy fallback.
78
+ assert.equal(teamKeyFromName(EMOJI_NAME), 'team')
79
+ assert.equal(sanitizeKey(EMOJI_NAME), 'k-28f98294')
80
+ })
81
+
82
+ test('create arguments keep the display name and use the host-shaped key', () => {
83
+ assert.deepEqual(parseAgentTeamsCreateArgs('{"name":" 数据团队 "}'), { teamId: '数据团队', name: '数据团队' })
84
+ assert.deepEqual(parseAgentTeamsCreateArgs('{"name":" Repo Review 2W! "}'), { teamId: 'repo-review-2w', name: 'Repo Review 2W!' })
85
+ assert.equal(parseAgentTeamsCreateArgs('{bad'), undefined)
86
+ assert.equal(parseAgentTeamsCreateArgs('{"name":" "}'), undefined)
87
+ })
88
+
89
+ test('the canonical identity is read from the create result metadata', () => {
90
+ const identity = parseAgentTeamsCreateResult({
91
+ team_id: '数据团队',
92
+ team_name: '数据团队',
93
+ captain_session_id: REAL_CANDIDATE_SESSION,
94
+ phase: 'running',
95
+ members: [{ id: '', name: '阿明', role: '工程师', status: 'idle' }, { id: '', name: 'Léa', role: 'reviewer', status: 'idle' }],
96
+ })
97
+ assert.deepEqual(identity, { teamId: '数据团队', captainSessionId: REAL_CANDIDATE_SESSION, members: REAL_MEMBERS })
98
+ for (const meta of [undefined, null, {}, { team_id: '' }, { team_id: 42 }, 'text']) {
99
+ assert.equal(parseAgentTeamsCreateResult(meta), undefined)
100
+ }
101
+ })
102
+
103
+ test('a pre-metadata record still yields the canonical id from the running result text', () => {
104
+ const stateDir = `.agent-teams/数据团队`
105
+ assert.equal(teamIdFromCreateResultText(runningText('数据团队', '数据团队', stateDir)), '数据团队')
106
+ assert.equal(teamIdFromCreateResultText(runningText(LONG_NAME, sanitizeKey(LONG_NAME), `.agent-teams/${sanitizeKey(LONG_NAME)}`)), sanitizeKey(LONG_NAME))
107
+ assert.equal(teamIdFromCreateResultText(runningText(EMOJI_NAME, sanitizeKey(EMOJI_NAME), `.agent-teams/${sanitizeKey(EMOJI_NAME)}`)), 'k-28f98294')
108
+ })
109
+
110
+ test('a pre-metadata staged plan yields the canonical id from its state directory', () => {
111
+ const id = sanitizeKey('数据团队审核组')
112
+ assert.equal(teamIdFromCreateResultText(stagedText('数据团队审核组', `/workspace/.agent-teams/${id}`)), id)
113
+ assert.equal(teamIdFromCreateResultText('Team "x" created. You are the captain.'), undefined)
114
+ })
115
+
116
+ test('a team name carrying a look-alike segment cannot override the canonical id', () => {
117
+ const text = 'Team "A" created (id injected) under B" created (id real-team) under /x/.agent-teams/real-team. You are the captain.'
118
+ assert.equal(teamIdFromCreateResultText(text), 'real-team')
119
+ })
120
+
121
+ test('resultText concatenates text blocks only', () => {
122
+ assert.equal(resultText({ content: [{ type: 'text', text: 'a' }, { type: 'image', data: 'x' }, { type: 'text', text: 'b' }] }), 'a\nb')
123
+ assert.equal(resultText({ content: [] }), '')
124
+ })
125
+
126
+ test('the card folds the canonical id, captain and roster from metadata', () => {
127
+ const { state, node } = fold(JSON.stringify({ name: '数据团队', approval: 'automatic' }), {
128
+ meta: {
129
+ team_id: '数据团队',
130
+ team_name: '数据团队',
131
+ captain_session_id: REAL_CANDIDATE_SESSION,
132
+ phase: 'running',
133
+ members: [{ id: '', name: '阿明', role: '工程师' }, { id: '', name: 'Léa', role: 'reviewer' }],
134
+ },
135
+ message: { role: 'tool', source: { kind: 'tool', callId: 'call_1' }, toolCallId: 'call_1', isError: false, content: [{ type: 'text', text: runningText('数据团队', '数据团队', '.agent-teams/数据团队') }] },
136
+ })
137
+ assert.equal(state.teamId, '数据团队')
138
+ assert.equal(state.captainSessionId, REAL_CANDIDATE_SESSION)
139
+ assert.deepEqual(state.members, REAL_MEMBERS)
140
+ assert.deepEqual(node?.data, {
141
+ teamId: '数据团队',
142
+ captainSessionId: REAL_CANDIDATE_SESSION,
143
+ teamName: '数据团队',
144
+ members: REAL_MEMBERS,
145
+ })
146
+ })
147
+
148
+ test('metadata cannot replace the display name taken from the create call', () => {
149
+ const { node } = fold(JSON.stringify({ name: '数据团队' }), {
150
+ meta: { team_id: 'canonical-key', team_name: 'renamed-by-host', captain_session_id: 's', members: [] },
151
+ })
152
+ assert.equal(node?.data.teamId, 'canonical-key')
153
+ assert.equal(node?.data.teamName, '数据团队')
154
+ })
155
+
156
+ test('a pre-metadata record folds the canonical id without inventing a roster', () => {
157
+ const { state, node } = fold(JSON.stringify({ name: LONG_NAME }), {
158
+ message: { role: 'tool', source: { kind: 'tool', callId: 'call_1' }, toolCallId: 'call_1', isError: false, content: [{ type: 'text', text: runningText(LONG_NAME, sanitizeKey(LONG_NAME), `.agent-teams/${sanitizeKey(LONG_NAME)}`) }] },
159
+ })
160
+ assert.equal(state.teamId, sanitizeKey(LONG_NAME))
161
+ assert.equal(state.captainSessionId, '')
162
+ assert.deepEqual(state.members, [])
163
+ assert.equal(node?.data.teamId, sanitizeKey(LONG_NAME))
164
+ })
165
+
166
+ test('a failed create result renders no card', () => {
167
+ const { state, node } = fold(JSON.stringify({ name: '数据团队' }), {
168
+ message: { role: 'tool', source: { kind: 'tool', callId: 'call_1' }, toolCallId: 'call_1', isError: true, content: [{ type: 'text', text: 'team id "数据团队" is taken by another captain' }] },
169
+ })
170
+ assert.equal(state.accepted, false)
171
+ assert.equal(node, null)
172
+ })
173
+
174
+ test('a result without metadata or canonical text keeps the derived key', () => {
175
+ const { state, node } = fold(JSON.stringify({ name: '数据团队' }), {
176
+ message: { role: 'tool', source: { kind: 'tool', callId: 'call_1' }, toolCallId: 'call_1', isError: false, content: [{ type: 'text', text: 'ok' }] },
177
+ })
178
+ assert.equal(state.accepted, true)
179
+ assert.equal(state.teamId, '数据团队')
180
+ assert.equal(node?.data.teamId, '数据团队')
181
+ })
@@ -0,0 +1,163 @@
1
+ // Issue #205 regression: the disposition policy for a final member turn failure.
2
+ //
3
+ // These are pure-function assertions over `classifyMemberFailure`. They are a
4
+ // supplement to — not a substitute for — the real-host acceptance, which drives
5
+ // a real member Agent through real DeepSeek Flash turns.
6
+ //
7
+ // The case this file exists to pin: a member with NO open attempt must always be
8
+ // recorded, whatever its durable `status` says. `syncMemberStatus` writes
9
+ // `working` as soon as a turn runs, while a task completed earlier in that same
10
+ // turn leaves no open attempt behind — treating that `working` as "moved on to
11
+ // newer work" silently dropped the reporter's run A failure.
12
+ import { test } from 'node:test'
13
+ import assert from 'node:assert/strict'
14
+ import { classifyMemberFailure, memberFailureMessage, settledTaskRecord } from '../lib/members.js'
15
+
16
+ const observed = (task) => ({ captainSessionId: 'captain', memberId: 'member-1', task })
17
+ const current = (member, task, observedRecord) => ({ member, task, observedRecord })
18
+
19
+ test('run A: a working member with no open attempt is recorded', () => {
20
+ // The reporter's run A: the task completed earlier in the turn, so nothing is
21
+ // open, while the member's own record already says it is working. Treating
22
+ // that `working` as "moved on to newer work" silently dropped the failure.
23
+ assert.equal(
24
+ classifyMemberFailure(
25
+ observed({ id: 't1', attempt: 1, attemptId: 'a1' }),
26
+ current({ id: 'member-1', status: 'working' }, undefined, { id: 't1', status: 'completed', subject: 'work' }),
27
+ ),
28
+ 'noted_settled',
29
+ )
30
+ })
31
+
32
+ test('a working member with no open attempt and no observed task is recorded too', () => {
33
+ assert.equal(
34
+ classifyMemberFailure(observed(undefined), current({ id: 'member-1', status: 'working' }, undefined, undefined)),
35
+ 'noted_settled',
36
+ )
37
+ })
38
+
39
+ test('no open task is recorded when the member is idle or explicitly retired', () => {
40
+ for (const status of ['idle', 'removed']) {
41
+ assert.equal(
42
+ classifyMemberFailure(
43
+ observed({ id: 't1', attempt: 1, attemptId: 'a1' }),
44
+ current({ id: 'member-1', status }, undefined, { id: 't1', status: 'completed', subject: 'work' }),
45
+ ),
46
+ 'noted_settled',
47
+ `status ${status}`,
48
+ )
49
+ }
50
+ })
51
+
52
+
53
+
54
+ test('a replaced member generation stays silent', () => {
55
+ assert.equal(
56
+ classifyMemberFailure(
57
+ observed({ id: 't1', attempt: 1, attemptId: 'a1' }),
58
+ current({ id: 'member-2', status: 'working' }, undefined, undefined),
59
+ ),
60
+ 'ignored',
61
+ )
62
+ assert.equal(
63
+ classifyMemberFailure(observed(undefined), current(undefined, undefined, undefined)),
64
+ 'ignored',
65
+ )
66
+ })
67
+
68
+ test('a concrete superseded open attempt stays silent', () => {
69
+ // the same task was reassigned to a newer attempt
70
+ assert.equal(
71
+ classifyMemberFailure(
72
+ observed({ id: 't1', attempt: 1, attemptId: 'a1' }),
73
+ current({ id: 'member-1', status: 'working' }, { id: 't1', attempt: 3, attemptId: 'a3' }),
74
+ ),
75
+ 'ignored',
76
+ )
77
+ // the member is working on a different task than the one observed
78
+ assert.equal(
79
+ classifyMemberFailure(
80
+ observed({ id: 't1', attempt: 1, attemptId: 'a1' }),
81
+ current({ id: 'member-1', status: 'working' }, { id: 't9', attempt: 1, attemptId: 'a9' }),
82
+ ),
83
+ 'ignored',
84
+ )
85
+ })
86
+
87
+ test('the exact observed open attempt is the only mutable case', () => {
88
+ assert.equal(
89
+ classifyMemberFailure(
90
+ observed({ id: 't1', attempt: 2, attemptId: 'a2' }),
91
+ current({ id: 'member-1', status: 'working' }, { id: 't1', attempt: 2, attemptId: 'a2' }),
92
+ ),
93
+ 'failed_attempt',
94
+ )
95
+ // an observed attempt with no attemptId must not match a live one
96
+ assert.equal(
97
+ classifyMemberFailure(
98
+ observed({ id: 't1', attempt: 2, attemptId: undefined }),
99
+ current({ id: 'member-1', status: 'working' }, { id: 't1', attempt: 2, attemptId: 'a2' }),
100
+ ),
101
+ 'ignored',
102
+ )
103
+ })
104
+
105
+ // --- message wording boundaries -------------------------------------------
106
+ //
107
+ // A non-terminal record (pending/claimed/in_progress) must never be described as
108
+ // settled, and a failed/cancelled record must not claim that work landed.
109
+
110
+ const record = (id, status, subject = 'work') => ({ id, status, subject })
111
+
112
+ test('only terminal statuses are accepted as a settled record', () => {
113
+ const tasks = [
114
+ record('t1', 'completed'),
115
+ record('t2', 'failed'),
116
+ record('t3', 'cancelled'),
117
+ record('t4', 'pending'),
118
+ record('t5', 'claimed'),
119
+ record('t6', 'in_progress'),
120
+ ]
121
+ assert.equal(settledTaskRecord({ id: 't1' }, tasks).status, 'completed')
122
+ assert.equal(settledTaskRecord({ id: 't2' }, tasks).status, 'failed')
123
+ assert.equal(settledTaskRecord({ id: 't3' }, tasks).status, 'cancelled')
124
+ for (const id of ['t4', 't5', 't6']) {
125
+ assert.equal(settledTaskRecord({ id }, tasks), undefined, `${id} must not be treated as settled`)
126
+ }
127
+ assert.equal(settledTaskRecord({ id: 'missing' }, tasks), undefined)
128
+ assert.equal(settledTaskRecord(undefined, tasks), undefined)
129
+ })
130
+
131
+ test('a completed record is the only one that may claim the work landed', () => {
132
+ const message = memberFailureMessage('policy', 'boom (code UNKNOWN)', 'noted_settled', undefined, record('t1', 'completed'))
133
+ assert.match(message, /had already completed/)
134
+ assert.match(message, /work landed/)
135
+ assert.match(message, /No|unchanged/)
136
+ })
137
+
138
+ test('failed and cancelled records are described by their closed state, not as delivered', () => {
139
+ for (const status of ['failed', 'cancelled']) {
140
+ const message = memberFailureMessage('policy', 'boom (code UNKNOWN)', 'noted_settled', undefined, record('t2', status))
141
+ assert.match(message, new RegExp(`was already closed as ${status}`))
142
+ assert.doesNotMatch(message, /work landed/)
143
+ assert.doesNotMatch(message, /had already completed/)
144
+ }
145
+ })
146
+
147
+ test('without a terminal record the message only says no open attempt', () => {
148
+ for (const disposition of ['noted_settled', 'failed_attempt']) {
149
+ const message = memberFailureMessage('policy', 'boom (code UNKNOWN)', disposition, undefined, undefined)
150
+ assert.match(message, /No open attempt was owned/)
151
+ assert.doesNotMatch(message, /already (completed|closed|settled)/)
152
+ assert.doesNotMatch(message, /work landed/)
153
+ }
154
+ assert.match(
155
+ memberFailureMessage('policy', 'boom (code UNKNOWN)', 'noted_settled', undefined, undefined),
156
+ /no task state was changed/,
157
+ )
158
+ })
159
+
160
+ test('a failed open attempt still names the task that was failed', () => {
161
+ const message = memberFailureMessage('policy', 'boom (code UNKNOWN)', 'failed_attempt', { id: 't9', subject: 'work' }, undefined)
162
+ assert.match(message, /Task t9 \("work"\) was marked failed/)
163
+ })