@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,194 @@
1
+ /** Pure persisted geometry rules for the AgentTeams shell-overlay panel. */
2
+
3
+ export type PanelMode = 'docked' | 'floating'
4
+ export type PanelHeightMode = 'auto' | 'manual'
5
+ export type PanelResizeEdge = 'left' | 'bottom' | 'corner'
6
+
7
+ /** User-owned panel state persisted between browser sessions. */
8
+ export interface PanelLayout {
9
+ readonly mode: PanelMode
10
+ readonly x: number
11
+ readonly y: number
12
+ readonly width: number
13
+ readonly height: number
14
+ readonly heightMode: PanelHeightMode
15
+ }
16
+
17
+ /** The shell-overlay box and the right edge of its current conversation. */
18
+ export interface PanelBounds {
19
+ readonly width: number
20
+ readonly height: number
21
+ readonly anchorRight: number
22
+ }
23
+
24
+ export const PANEL_LAYOUT_STORAGE_KEY = 'dsh-agent-teams:activity-panel:v1'
25
+ export const PANEL_COMPACT_BREAKPOINT = 960
26
+ export const PANEL_DEFAULT_WIDTH = 388
27
+ export const PANEL_DEFAULT_HEIGHT = 640
28
+ export const PANEL_MIN_WIDTH = 320
29
+ export const PANEL_MAX_WIDTH = 640
30
+ export const PANEL_MIN_HEIGHT = 360
31
+ export const PANEL_DOCK_TOP = 64
32
+ export const PANEL_DOCK_RIGHT = 18
33
+ export const PANEL_DOCK_BOTTOM = 48
34
+ export const PANEL_FLOAT_MARGIN = 12
35
+
36
+ export const DEFAULT_PANEL_LAYOUT: PanelLayout = Object.freeze({
37
+ mode: 'docked',
38
+ x: 0,
39
+ y: PANEL_DOCK_TOP,
40
+ width: PANEL_DEFAULT_WIDTH,
41
+ height: PANEL_DEFAULT_HEIGHT,
42
+ heightMode: 'auto',
43
+ })
44
+
45
+ function clamp(value: number, minimum: number, maximum: number): number {
46
+ return Math.min(Math.max(value, minimum), maximum)
47
+ }
48
+
49
+ function finite(value: unknown): value is number {
50
+ return typeof value === 'number' && Number.isFinite(value)
51
+ }
52
+
53
+ /** Decode one versioned localStorage value, rejecting partial/corrupt state. */
54
+ export function parsePanelLayout(value: string | null): PanelLayout {
55
+ if (value === null) return DEFAULT_PANEL_LAYOUT
56
+ try {
57
+ const parsed: unknown = JSON.parse(value)
58
+ if (typeof parsed !== 'object' || parsed === null) return DEFAULT_PANEL_LAYOUT
59
+ const record = parsed as Record<string, unknown>
60
+ if ((record.mode !== 'docked' && record.mode !== 'floating')
61
+ || !finite(record.x) || !finite(record.y)
62
+ || !finite(record.width) || !finite(record.height)) {
63
+ return DEFAULT_PANEL_LAYOUT
64
+ }
65
+ return {
66
+ mode: record.mode,
67
+ x: record.x,
68
+ y: record.y,
69
+ width: record.width,
70
+ height: record.height,
71
+ // v1 values written before content-fit height existed have no mode.
72
+ // Treat them as automatic so the upgrade removes legacy blank space.
73
+ heightMode: record.mode === 'floating' && record.heightMode === 'manual' ? 'manual' : 'auto',
74
+ }
75
+ } catch {
76
+ return DEFAULT_PANEL_LAYOUT
77
+ }
78
+ }
79
+
80
+ /** Whether the panel should become a simple inset overlay with no gestures. */
81
+ export function compactPanelForBounds(bounds: PanelBounds): boolean {
82
+ return bounds.width <= PANEL_COMPACT_BREAKPOINT
83
+ }
84
+
85
+ /** Docked and compact panels always fit content; floating panels may be user-sized. */
86
+ export function panelUsesAutoHeight(layout: PanelLayout, bounds: PanelBounds): boolean {
87
+ return compactPanelForBounds(bounds) || layout.mode === 'docked' || layout.heightMode === 'auto'
88
+ }
89
+
90
+ /** CSS max-height ceiling that keeps an auto-height panel inside its shell. */
91
+ export function panelMaximumHeight(layout: PanelLayout, bounds: PanelBounds): number {
92
+ const bottomInset = compactPanelForBounds(bounds) || layout.mode === 'floating'
93
+ ? PANEL_FLOAT_MARGIN
94
+ : PANEL_DOCK_BOTTOM
95
+ return Math.max(1, bounds.height - layout.y - bottomInset)
96
+ }
97
+
98
+ /** Resolve persisted state into a visible rectangle inside the current shell. */
99
+ export function resolvePanelGeometry(layout: PanelLayout, bounds: PanelBounds): PanelLayout {
100
+ const boundsWidth = Math.max(1, bounds.width)
101
+ const boundsHeight = Math.max(1, bounds.height)
102
+
103
+ if (compactPanelForBounds(bounds)) {
104
+ return {
105
+ ...layout,
106
+ x: PANEL_FLOAT_MARGIN,
107
+ y: PANEL_FLOAT_MARGIN,
108
+ width: Math.max(1, boundsWidth - PANEL_FLOAT_MARGIN * 2),
109
+ height: Math.max(1, boundsHeight - PANEL_FLOAT_MARGIN * 2),
110
+ }
111
+ }
112
+
113
+ const maximumWidth = Math.max(1, Math.min(PANEL_MAX_WIDTH, boundsWidth - PANEL_FLOAT_MARGIN * 2))
114
+ const minimumWidth = Math.min(PANEL_MIN_WIDTH, maximumWidth)
115
+ const width = clamp(layout.width, minimumWidth, maximumWidth)
116
+ const maximumHeight = Math.max(1, boundsHeight - PANEL_FLOAT_MARGIN * 2)
117
+ const minimumHeight = Math.min(PANEL_MIN_HEIGHT, maximumHeight)
118
+
119
+ if (layout.mode === 'docked') {
120
+ const y = clamp(PANEL_DOCK_TOP, PANEL_FLOAT_MARGIN, Math.max(PANEL_FLOAT_MARGIN, boundsHeight - minimumHeight - PANEL_FLOAT_MARGIN))
121
+ const availableHeight = Math.max(1, boundsHeight - y - PANEL_DOCK_BOTTOM)
122
+ const height = clamp(availableHeight, Math.min(minimumHeight, availableHeight), maximumHeight)
123
+ const anchorRight = clamp(bounds.anchorRight, 0, boundsWidth)
124
+ const maximumX = Math.max(PANEL_FLOAT_MARGIN, boundsWidth - width - PANEL_FLOAT_MARGIN)
125
+ const x = clamp(anchorRight - PANEL_DOCK_RIGHT - width, PANEL_FLOAT_MARGIN, maximumX)
126
+ return { mode: 'docked', x, y, width, height, heightMode: layout.heightMode }
127
+ }
128
+
129
+ const height = clamp(layout.height, minimumHeight, maximumHeight)
130
+ return {
131
+ mode: 'floating',
132
+ x: clamp(layout.x, PANEL_FLOAT_MARGIN, Math.max(PANEL_FLOAT_MARGIN, boundsWidth - width - PANEL_FLOAT_MARGIN)),
133
+ y: clamp(layout.y, PANEL_FLOAT_MARGIN, Math.max(PANEL_FLOAT_MARGIN, boundsHeight - height - PANEL_FLOAT_MARGIN)),
134
+ width,
135
+ height,
136
+ heightMode: layout.heightMode,
137
+ }
138
+ }
139
+
140
+ /** Undock without a visual jump by adopting the panel's resolved rectangle. */
141
+ export function floatPanelLayout(geometry: PanelLayout, bounds: PanelBounds): PanelLayout {
142
+ return resolvePanelGeometry({ ...geometry, mode: 'floating' }, bounds)
143
+ }
144
+
145
+ /** Return to the right dock, preserving width and restoring content-fit height. */
146
+ export function dockPanelLayout(layout: PanelLayout, bounds: PanelBounds): PanelLayout {
147
+ return resolvePanelGeometry({ ...layout, mode: 'docked', heightMode: 'auto' }, bounds)
148
+ }
149
+
150
+ /** Translate a floating panel and clamp it back into the visible shell. */
151
+ export function movePanelLayout(
152
+ start: PanelLayout,
153
+ dx: number,
154
+ dy: number,
155
+ bounds: PanelBounds,
156
+ ): PanelLayout {
157
+ return resolvePanelGeometry({ ...start, mode: 'floating', x: start.x + dx, y: start.y + dy }, bounds)
158
+ }
159
+
160
+ /** Resize while keeping the edge opposite the active handle stationary. */
161
+ export function resizePanelLayout(
162
+ start: PanelLayout,
163
+ edge: PanelResizeEdge,
164
+ dx: number,
165
+ dy: number,
166
+ bounds: PanelBounds,
167
+ ): PanelLayout {
168
+ if (start.mode === 'docked') {
169
+ if (edge !== 'left') return resolvePanelGeometry(start, bounds)
170
+ return resolvePanelGeometry({ ...start, width: start.width - dx }, bounds)
171
+ }
172
+
173
+ const resolved = resolvePanelGeometry(start, bounds)
174
+ const minimumWidth = Math.min(PANEL_MIN_WIDTH, resolved.x + resolved.width - PANEL_FLOAT_MARGIN)
175
+ const minimumHeight = Math.min(PANEL_MIN_HEIGHT, bounds.height - resolved.y - PANEL_FLOAT_MARGIN)
176
+
177
+ if (edge === 'left') {
178
+ const right = resolved.x + resolved.width
179
+ const maximumWidth = Math.max(1, Math.min(PANEL_MAX_WIDTH, right - PANEL_FLOAT_MARGIN))
180
+ const width = clamp(resolved.width - dx, Math.min(minimumWidth, maximumWidth), maximumWidth)
181
+ return { ...resolved, x: right - width, width }
182
+ }
183
+
184
+ const maximumHeight = Math.max(1, bounds.height - resolved.y - PANEL_FLOAT_MARGIN)
185
+ const height = clamp(resolved.height + dy, Math.min(minimumHeight, maximumHeight), maximumHeight)
186
+ if (edge === 'bottom') return { ...resolved, height, heightMode: 'manual' }
187
+
188
+ const maximumWidth = Math.max(1, Math.min(
189
+ PANEL_MAX_WIDTH,
190
+ bounds.width - resolved.x - PANEL_FLOAT_MARGIN,
191
+ ))
192
+ const width = clamp(resolved.width + dx, Math.min(minimumWidth, maximumWidth), maximumWidth)
193
+ return { ...resolved, width, height, heightMode: 'manual' }
194
+ }
@@ -0,0 +1,73 @@
1
+ /** Version-tolerant navigation into durable AgentTeams member transcripts. */
2
+
3
+ import type { SessionId } from '@deepseek-ai/dsh-session/types'
4
+ import type { SubagentAddress } from '@deepseek-ai/dsh-subagent/client'
5
+
6
+ /** Narrow sessions-service face used by the activity panel and team card. */
7
+ export interface AgentTeamsSessionNavigator {
8
+ /** Legacy/ordinary session navigation. */
9
+ open?(id: SessionId): void
10
+ /** rc.8 addressed subagent navigation. */
11
+ openSubagent?(address: SubagentAddress): void
12
+ /** Refresh the exact parent's durable direct-child catalog. */
13
+ refreshSubagents?(parentSessionId: SessionId): Promise<void>
14
+ /** Reuse an address already retained by the client runtime when available. */
15
+ subagentAddress?(id: SessionId): SubagentAddress | undefined
16
+ }
17
+
18
+ /** Newer sessions retain view ownership instead of publishing list.current. */
19
+ export function currentSessionId(state: {
20
+ readonly current?: SessionId
21
+ readonly byId: Readonly<Record<string, { readonly id: SessionId; readonly retainedBy?: Readonly<Record<string, number>> }>>
22
+ }): SessionId | undefined {
23
+ if ('current' in state) return state.current
24
+ return Object.values(state.byId).find(row => (row.retainedBy?.mainView ?? 0) > 0)?.id
25
+ }
26
+
27
+ export interface AgentTeamsWorkspaceNavigator {
28
+ openSession(target: SessionId | SubagentAddress): void
29
+ }
30
+
31
+ /** Main-panel navigation added in Harness 0.1.5; older layouts omit these actions. */
32
+ export interface AgentTeamsLayoutNavigator {
33
+ selectPanel?(panelId: null): void
34
+ beginNavigation?(): AbortSignal
35
+ }
36
+
37
+ /**
38
+ * Open one member's persisted transcript.
39
+ *
40
+ * Harness rc.8 intentionally removed cold subagents from the ordinary session
41
+ * list. They must first be rediscovered in their parent's catalog, then opened
42
+ * with the exact parent/child/mode address. Older runtimes have only `open()`;
43
+ * the fallback preserves ordinary-session navigation. New layouts also select
44
+ * the Conversation panel and cancel catalog refreshes superseded by navigation.
45
+ */
46
+ export async function openAgentTeamMember(
47
+ sessions: AgentTeamsSessionNavigator,
48
+ parentSessionId: SessionId,
49
+ childSessionId: SessionId,
50
+ layout?: AgentTeamsLayoutNavigator,
51
+ workspace?: AgentTeamsWorkspaceNavigator,
52
+ ): Promise<'subagent' | 'session' | 'cancelled'> {
53
+ if (sessions.open === undefined && workspace !== undefined) {
54
+ workspace.openSession({ parentSessionId, childSessionId, mode: 'continuable' })
55
+ return 'subagent'
56
+ }
57
+ const navigation = layout?.beginNavigation?.()
58
+ if (sessions.openSubagent === undefined || sessions.refreshSubagents === undefined) {
59
+ if (sessions.open === undefined) throw new Error('Harness does not expose session navigation')
60
+ sessions.open(childSessionId)
61
+ layout?.selectPanel?.(null)
62
+ return 'session'
63
+ }
64
+
65
+ await sessions.refreshSubagents(parentSessionId)
66
+ if (navigation?.aborted) return 'cancelled'
67
+ const retained = sessions.subagentAddress?.(childSessionId)
68
+ sessions.openSubagent(retained?.parentSessionId === parentSessionId
69
+ ? retained
70
+ : { parentSessionId, childSessionId, mode: 'continuable' })
71
+ layout?.selectPanel?.(null)
72
+ return 'subagent'
73
+ }
@@ -0,0 +1,52 @@
1
+ /** Plugin-instance state shared by the monitor and any number of native tabs. */
2
+ import type { AgentTeamsCardData } from './agent-teams-card-definition.ts'
3
+ import type { ActivityTeam } from './activity-monitor.ts'
4
+
5
+ export type ConnectionStatus = 'loading' | 'ready' | 'error'
6
+ export interface WorkspaceSnapshot {
7
+ readonly statuses: ReadonlyMap<string, ConnectionStatus>
8
+ readonly history: ReadonlyMap<string, AgentTeamsCardData>
9
+ readonly selected: ReadonlyMap<string, string>
10
+ }
11
+
12
+ export function createWorkspaceState() {
13
+ let snapshot: WorkspaceSnapshot = { statuses: new Map(), history: new Map(), selected: new Map() }
14
+ const listeners = new Set<() => void>()
15
+ const publish = (next: WorkspaceSnapshot): void => {
16
+ snapshot = next
17
+ for (const listener of listeners) listener()
18
+ }
19
+ return {
20
+ getSnapshot: () => snapshot,
21
+ subscribe: (listener: () => void) => { listeners.add(listener); return () => { listeners.delete(listener) } },
22
+ status(session: string, status: ConnectionStatus) {
23
+ if (snapshot.statuses.get(session) === status) return
24
+ publish({ ...snapshot, statuses: new Map(snapshot.statuses).set(session, status) })
25
+ },
26
+ select(session: string, team: string) {
27
+ if (snapshot.selected.get(session) === team) return
28
+ publish({ ...snapshot, selected: new Map(snapshot.selected).set(session, team) })
29
+ },
30
+ remember(session: string, data: AgentTeamsCardData) {
31
+ const owner = data.captainSessionId || session
32
+ if (owner !== session) return
33
+ publish({ ...snapshot,
34
+ history: new Map(snapshot.history).set(`${owner}:${data.teamId}`, { ...data, captainSessionId: owner }),
35
+ selected: new Map(snapshot.selected).set(owner, data.teamId),
36
+ })
37
+ },
38
+ }
39
+ }
40
+ export type WorkspaceActivityState = ReturnType<typeof createWorkspaceState>
41
+
42
+ /** Records restored at mount never reopen a closed tab; new teams are announced once. */
43
+ export function createTeamDiscovery() {
44
+ let restored = false
45
+ let known = new Set<string>()
46
+ return (teams: readonly ActivityTeam[]): string | undefined => {
47
+ const added = restored ? teams.find(team => !known.has(team.teamId))?.teamId : undefined
48
+ known = new Set(teams.map(team => team.teamId))
49
+ restored = true
50
+ return added
51
+ }
52
+ }
package/src/command.ts ADDED
@@ -0,0 +1,145 @@
1
+ import type { Context } from '@deepseek-ai/cordis'
2
+ import type { PreStepDecision } from '@deepseek-ai/dsh-agent'
3
+ import type { CommandInvocation, CommandResult } from '@deepseek-ai/dsh-commands'
4
+ import { createUserMessage, type UserMessage } from '@deepseek-ai/dsh-llm'
5
+ import { agentTeamsSource, observedSessionFormatVersion } from './harness-compat.ts'
6
+ import { parseProfileInvocation, resolveProfileTaskPlanning, type TeamProfileConfig, type AgentTeamsInvocation } from './profiles.ts'
7
+
8
+ export const AGENT_TEAMS_COMMAND = 'agent-teams'
9
+ const PROFILE_COMMAND_PREFIX = `${AGENT_TEAMS_COMMAND}-`
10
+
11
+ declare module '@deepseek-ai/dsh-llm' {
12
+ interface MessageSourceMap {
13
+ 'agent-teams-command': { readonly kind: 'agent-teams-command'; readonly goal?: string; readonly profile?: string }
14
+ }
15
+ }
16
+
17
+ const GESTURE = /^\/agent-teams(?=$|[\t\n\r ])/u
18
+
19
+ /**
20
+ * Convert a configured profile key into a stable, closed-namespace command
21
+ * suffix. Only lowercase ASCII letters, digits and dashes are representable;
22
+ * this deliberately prevents accidental command aliases for ambiguous profile
23
+ * names such as `foo bar`, `foo_bar`, or non-ASCII keys.
24
+ */
25
+ export function profileCommandName(profileName: string): string | undefined {
26
+ const normalized = profileName.trim().toLowerCase()
27
+ if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(normalized)) return undefined
28
+ return `${PROFILE_COMMAND_PREFIX}${normalized}`
29
+ }
30
+
31
+ /** Resolve a profile command only when it maps uniquely to a live profile. */
32
+ function profileForCommand(commandName: string, profiles: Record<string, TeamProfileConfig>): string | undefined {
33
+ const matches = Object.keys(profiles).filter((profileName) => profileCommandName(profileName) === commandName)
34
+ return matches.length === 1 ? matches[0] : undefined
35
+ }
36
+
37
+ /** Parse either the generic command or one generated profile alias. */
38
+ function parseCommandText(text: string, profiles: Record<string, TeamProfileConfig>): AgentTeamsInvocation | undefined {
39
+ const trimmed = text.trimStart()
40
+ if (GESTURE.test(trimmed)) return parseProfileInvocation(trimmed.slice(AGENT_TEAMS_COMMAND.length + 1).trim())
41
+ if (!trimmed.startsWith(`/${PROFILE_COMMAND_PREFIX}`)) return undefined
42
+ const tokenEnd = trimmed.search(/[\t\n\r ]/u)
43
+ const commandName = trimmed.slice(1, tokenEnd === -1 ? undefined : tokenEnd)
44
+ const profile = profileForCommand(commandName, profiles)
45
+ if (profile === undefined) return undefined
46
+ return { profile, goal: (tokenEnd === -1 ? '' : trimmed.slice(tokenEnd)).trim() }
47
+ }
48
+
49
+ export function invokedAgentTeamsInvocation(messages: readonly UserMessage[], getProfiles: () => Record<string, TeamProfileConfig> = () => ({})): AgentTeamsInvocation | undefined {
50
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
51
+ const message = messages[index]
52
+ if (message === undefined || message.source.kind !== 'user') continue
53
+ for (const block of message.content) {
54
+ if (block.type !== 'text') continue
55
+ const invocation = parseCommandText(block.text, getProfiles())
56
+ if (invocation !== undefined) return invocation
57
+ }
58
+ }
59
+ return undefined
60
+ }
61
+
62
+ export function invokedAgentTeamsGoal(messages: readonly UserMessage[]): string | undefined {
63
+ return invokedAgentTeamsInvocation(messages)?.goal
64
+ }
65
+
66
+ export function buildActivationDirective(goal: string, profile?: string, taskPlanning: 'captain' | 'seed' = 'seed'): string {
67
+ const lines = [
68
+ 'The user invoked an AgentTeams slash command. Follow the AgentTeams protocol already in your system instructions. Inspect existing team state with agent_teams_status when needed.',
69
+ 'Respect the current team state. Continue an existing plan or team without recreating it. Only when no current team exists, call agent_teams_create with approval="required". Build the complete staged roster and DAG, then stop and ask the user to review the Web plan. Do not approve or start it in this same turn.',
70
+ ]
71
+ if (profile !== undefined) {
72
+ lines.push(`Use profile="${profile}" when creating a new team.`)
73
+ if (taskPlanning === 'captain') {
74
+ lines.push(
75
+ 'This profile supplies the roster and guardrails. After create, do not recreate members.',
76
+ 'Derive the smallest useful task graph from the goal while the team is staged; do not ask the user whether to split, merge, serialize, or parallelize.',
77
+ 'Independent supplemental work must become separate ready tasks so idle members can run in parallel. Add dependencies only for genuine prerequisites and later synthesis.',
78
+ )
79
+ } else {
80
+ lines.push('Do not recreate the same members or seed tasks manually.')
81
+ }
82
+ }
83
+ lines.push(goal === '' ? 'The goal was not given — ask the user what the team should accomplish.' : `Goal: ${goal}`)
84
+ return lines.join('\n')
85
+ }
86
+
87
+ export function registerAgentTeamsCommand(ctx: Context, getProfiles: () => Record<string, TeamProfileConfig> = () => ({})): void {
88
+ ctx.effect(() => {
89
+ const dispose: Array<() => void> = []
90
+ dispose.push(ctx.commands.register({
91
+ name: AGENT_TEAMS_COMMAND,
92
+ description: '智能体团队 · 用多智能体团队执行目标(你成为队长)',
93
+ input: { hint: '[--profile <name>] <goal>' },
94
+ handler(invocation: CommandInvocation): CommandResult {
95
+ let parsed: AgentTeamsInvocation
96
+ try { parsed = parseProfileInvocation(invocation.rawInput.trim()) } catch (error: unknown) { return { kind: 'error', text: String(error) } }
97
+ if (parsed.profile !== undefined && !Object.keys(getProfiles()).some(key => key.trim() === parsed.profile)) return { kind: 'error', text: `unknown AgentTeams profile "${parsed.profile}"` }
98
+ if (parsed.profile === undefined && parsed.goal === '') return { kind: 'error', text: `Usage: /${AGENT_TEAMS_COMMAND} [--profile <name>] <goal>` }
99
+ invocation.agent.followup(createUserMessage({ content: [{ type: 'text', text: `/${AGENT_TEAMS_COMMAND}${invocation.rawInput}` }], source: { kind: 'user' } }))
100
+ return { kind: 'success', text: `AgentTeams 已激活${parsed.profile === undefined ? '' : `(profile ${parsed.profile})`} —— 队长会开始组建团队。` }
101
+ },
102
+ }))
103
+ for (const profileName of Object.keys(getProfiles())) {
104
+ const commandName = profileCommandName(profileName)
105
+ if (commandName === undefined) continue
106
+ dispose.push(ctx.commands.register({
107
+ name: commandName,
108
+ description: `智能体团队 · 用 AgentTeams 的 ${profileName} profile 执行目标`,
109
+ input: { hint: '<goal>' },
110
+ handler(invocation: CommandInvocation): CommandResult {
111
+ const profile = profileForCommand(commandName, getProfiles())
112
+ if (profile === undefined) return { kind: 'error', text: `AgentTeams profile command "/${commandName}" is unavailable` }
113
+ invocation.agent.followup(createUserMessage({ content: [{ type: 'text', text: `/${commandName}${invocation.rawInput}` }], source: { kind: 'user' } }))
114
+ return { kind: 'success', text: `AgentTeams 已激活(profile ${profile})—— 队长会开始组建团队。` }
115
+ },
116
+ }))
117
+ }
118
+ return () => {
119
+ for (const unregister of dispose.reverse()) unregister()
120
+ }
121
+ }, 'agent-teams: slash commands')
122
+ }
123
+
124
+ export function installAgentTeamsGestureBoundary(ctx: Context, getProfiles: () => Record<string, TeamProfileConfig> = () => ({})): void {
125
+ ctx.on('agent/pre-step', async ({ agent, messages, signal }, next): Promise<PreStepDecision> => {
126
+ const decision = await next()
127
+ if (decision.kind === 'reject') return decision
128
+ // The live session header carries the format this host actually stores; the
129
+ // resolved module constant can name another DSH line in the same profile (#236).
130
+ const observed = observedSessionFormatVersion(agent)
131
+ let invocation: AgentTeamsInvocation | undefined
132
+ try { invocation = invokedAgentTeamsInvocation(messages, getProfiles) } catch (error: unknown) { return { kind: 'enter', messages: [...decision.messages, createUserMessage({ content: [{ type: 'text', text: `AgentTeams profile parsing failed: ${String(error)}` }], source: agentTeamsSource({ kind: 'agent-teams-command' }, observed) })] } }
133
+ if (invocation === undefined) return decision
134
+ signal.throwIfAborted()
135
+ const profiles = getProfiles()
136
+ const matched = invocation.profile === undefined
137
+ ? undefined
138
+ : Object.entries(profiles).find(([key]) => key.trim() === invocation.profile)
139
+ const known = invocation.profile === undefined || matched !== undefined
140
+ const text = !known
141
+ ? `AgentTeams profile "${invocation.profile}" does not exist. Available profiles: ${Object.keys(profiles).join(', ') || '(none)'}. Do not create a team.`
142
+ : buildActivationDirective(invocation.goal, invocation.profile, resolveProfileTaskPlanning(matched?.[1]))
143
+ return { kind: 'enter', messages: [...decision.messages, createUserMessage({ content: [{ type: 'text', text }], source: agentTeamsSource({ kind: 'agent-teams-command', ...invocation.goal === '' ? {} : { goal: invocation.goal }, ...invocation.profile === undefined ? {} : { profile: invocation.profile } }, observed) })] }
144
+ })
145
+ }
@@ -0,0 +1,4 @@
1
+ declare module '*.module.css' {
2
+ const classes: Record<string, string>
3
+ export default classes
4
+ }
@@ -0,0 +1,177 @@
1
+ /**
2
+ * AgentTeams session event types — pure types only, zero imports.
3
+ *
4
+ * This file intentionally imports nothing: both the host program (the
5
+ * emitter in `events.ts`) and the browser program (the Conversation Node
6
+ * definition) must be able to load these types and the `SessionEventMap`
7
+ * declaration merge without pulling in host-side `Context` augmentations
8
+ * (dsh-session's index declares `Context.sessions: SessionStore`, which
9
+ * collides with the browser runtime's `ISessions` under the same name).
10
+ * @module dsh-agent-teams/event-types
11
+ */
12
+
13
+ /** Opens one team record: the captain created the team. */
14
+ export interface AgentTeamsTeamCreatedData {
15
+ readonly teamId: string
16
+ /** The captain session that owns this team (UI follows it). */
17
+ readonly captainSessionId: string
18
+ readonly name: string
19
+ readonly description?: string
20
+ readonly profile?: string
21
+ }
22
+
23
+ /** Records one member after its continuable subagent is spawned. */
24
+ export interface AgentTeamsMemberAddedData {
25
+ readonly teamId: string
26
+ readonly memberId: string
27
+ readonly name: string
28
+ readonly role?: string
29
+ }
30
+
31
+ /** Marks one member removed. */
32
+ export interface AgentTeamsMemberRemovedData {
33
+ readonly teamId: string
34
+ readonly memberId: string
35
+ }
36
+
37
+ /** Records one task in the team's task list. */
38
+ export interface AgentTeamsTaskCreatedData {
39
+ readonly teamId: string
40
+ readonly taskId: string
41
+ readonly subject: string
42
+ readonly dependencies: readonly string[]
43
+ readonly assignee?: string
44
+ readonly kind?: string
45
+ readonly round?: number
46
+ }
47
+
48
+ /** Records one task status/assignee/output transition. */
49
+ export interface AgentTeamsTaskUpdatedData {
50
+ readonly teamId: string
51
+ readonly taskId: string
52
+ readonly status: string
53
+ readonly assignee?: string
54
+ readonly output?: string
55
+ readonly attempt?: number
56
+ readonly attemptId?: string
57
+ readonly verdict?: string
58
+ readonly round?: number
59
+ }
60
+
61
+ /** Records one captain-only contract amendment on a task. */
62
+ export interface AgentTeamsTaskAmendedData {
63
+ readonly teamId: string
64
+ readonly taskId: string
65
+ /** Amended contract field names (`objective`, `inScope`, …). */
66
+ readonly fields: readonly string[]
67
+ /** Why the previous contract was wrong. */
68
+ readonly reason: string
69
+ }
70
+
71
+ /** Records a human halt from the captain chat. */
72
+ export interface AgentTeamsTeamHaltedData {
73
+ readonly teamId: string
74
+ readonly cancelledTasks: number
75
+ }
76
+
77
+ /** Records an explicit captain resume of a halted team. */
78
+ export interface AgentTeamsTeamResumedData {
79
+ readonly teamId: string
80
+ readonly reason: string
81
+ }
82
+
83
+ /** Closes one team record: the team was deleted. */
84
+ export interface AgentTeamsTeamDeletedData {
85
+ readonly teamId: string
86
+ }
87
+
88
+ /** Records a staged plan that the user rejected before any member was spawned. */
89
+ export interface AgentTeamsPlanDiscardedData {
90
+ readonly teamId: string
91
+ }
92
+
93
+ /** Records one mailbox message sent between team agents. */
94
+ export interface AgentTeamsMessageSentData {
95
+ readonly teamId: string
96
+ readonly messageId: string
97
+ /** `captain` or a member name. */
98
+ readonly from: string
99
+ /** `captain` or a member name. */
100
+ readonly to: string
101
+ readonly content: string
102
+ readonly ts: number
103
+ }
104
+
105
+ declare module '@deepseek-ai/dsh-session/types' {
106
+ interface SessionEventMap {
107
+ /**
108
+ * Opens one team record.
109
+ * @param data - stable team identity and display name.
110
+ */
111
+ 'agent-teams/team-created': AgentTeamsTeamCreatedData
112
+ /**
113
+ * Records one team member.
114
+ * @param data - team identity, member child session, and display identity.
115
+ */
116
+ 'agent-teams/member-added': AgentTeamsMemberAddedData
117
+ /**
118
+ * Records one member removal.
119
+ * @param data - team identity and the member's child session id.
120
+ */
121
+ 'agent-teams/member-removed': AgentTeamsMemberRemovedData
122
+ /**
123
+ * Records one task creation.
124
+ * @param data - team identity, task id, subject, dependencies, assignee.
125
+ */
126
+ 'agent-teams/task-created': AgentTeamsTaskCreatedData
127
+ /**
128
+ * Records one task transition.
129
+ * @param data - team identity, task id, and the new status/assignee/output.
130
+ */
131
+ 'agent-teams/task-updated': AgentTeamsTaskUpdatedData
132
+ /**
133
+ * Records one captain-only contract amendment.
134
+ * @param data - team identity, task id, amended field names, and reason.
135
+ */
136
+ 'agent-teams/task-amended': AgentTeamsTaskAmendedData
137
+ /**
138
+ * Records one mailbox message.
139
+ * @param data - team identity, sender, recipient, and content.
140
+ */
141
+ 'agent-teams/message-sent': AgentTeamsMessageSentData
142
+ /**
143
+ * Records a human halt from the captain chat.
144
+ * @param data - team identity and how many unfinished tasks were cancelled.
145
+ */
146
+ 'agent-teams/team-halted': AgentTeamsTeamHaltedData
147
+ /**
148
+ * Records an explicit captain resume.
149
+ * @param data - team identity and the resume reason.
150
+ */
151
+ 'agent-teams/team-resumed': AgentTeamsTeamResumedData
152
+ /**
153
+ * Closes one team record after deletion.
154
+ * @param data - stable team identity.
155
+ */
156
+ 'agent-teams/team-deleted': AgentTeamsTeamDeletedData
157
+ /**
158
+ * Closes a staged plan rejected during pre-run review.
159
+ * @param data - stable team identity.
160
+ */
161
+ 'agent-teams/plan-discarded': AgentTeamsPlanDiscardedData
162
+ }
163
+ }
164
+
165
+ /** The full set of `agent-teams/*` event names. */
166
+ export type AgentTeamsEventType =
167
+ | 'agent-teams/team-created'
168
+ | 'agent-teams/member-added'
169
+ | 'agent-teams/member-removed'
170
+ | 'agent-teams/task-created'
171
+ | 'agent-teams/task-updated'
172
+ | 'agent-teams/task-amended'
173
+ | 'agent-teams/message-sent'
174
+ | 'agent-teams/team-halted'
175
+ | 'agent-teams/team-resumed'
176
+ | 'agent-teams/team-deleted'
177
+ | 'agent-teams/plan-discarded'