@xagent-ai/cli 1.3.6 → 1.4.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 (69) hide show
  1. package/README.md +9 -0
  2. package/README_CN.md +9 -0
  3. package/dist/cli.js +26 -0
  4. package/dist/cli.js.map +1 -1
  5. package/dist/mcp.d.ts +8 -1
  6. package/dist/mcp.d.ts.map +1 -1
  7. package/dist/mcp.js +53 -20
  8. package/dist/mcp.js.map +1 -1
  9. package/dist/sdk-output-adapter.d.ts +79 -0
  10. package/dist/sdk-output-adapter.d.ts.map +1 -1
  11. package/dist/sdk-output-adapter.js +118 -0
  12. package/dist/sdk-output-adapter.js.map +1 -1
  13. package/dist/session.d.ts +88 -1
  14. package/dist/session.d.ts.map +1 -1
  15. package/dist/session.js +351 -5
  16. package/dist/session.js.map +1 -1
  17. package/dist/slash-commands.d.ts.map +1 -1
  18. package/dist/slash-commands.js +3 -5
  19. package/dist/slash-commands.js.map +1 -1
  20. package/dist/smart-approval.d.ts.map +1 -1
  21. package/dist/smart-approval.js +1 -0
  22. package/dist/smart-approval.js.map +1 -1
  23. package/dist/system-prompt-generator.d.ts +15 -1
  24. package/dist/system-prompt-generator.d.ts.map +1 -1
  25. package/dist/system-prompt-generator.js +36 -27
  26. package/dist/system-prompt-generator.js.map +1 -1
  27. package/dist/team-manager/index.d.ts +6 -0
  28. package/dist/team-manager/index.d.ts.map +1 -0
  29. package/dist/team-manager/index.js +6 -0
  30. package/dist/team-manager/index.js.map +1 -0
  31. package/dist/team-manager/message-broker.d.ts +128 -0
  32. package/dist/team-manager/message-broker.d.ts.map +1 -0
  33. package/dist/team-manager/message-broker.js +638 -0
  34. package/dist/team-manager/message-broker.js.map +1 -0
  35. package/dist/team-manager/team-coordinator.d.ts +45 -0
  36. package/dist/team-manager/team-coordinator.d.ts.map +1 -0
  37. package/dist/team-manager/team-coordinator.js +887 -0
  38. package/dist/team-manager/team-coordinator.js.map +1 -0
  39. package/dist/team-manager/team-store.d.ts +49 -0
  40. package/dist/team-manager/team-store.d.ts.map +1 -0
  41. package/dist/team-manager/team-store.js +436 -0
  42. package/dist/team-manager/team-store.js.map +1 -0
  43. package/dist/team-manager/teammate-spawner.d.ts +86 -0
  44. package/dist/team-manager/teammate-spawner.d.ts.map +1 -0
  45. package/dist/team-manager/teammate-spawner.js +605 -0
  46. package/dist/team-manager/teammate-spawner.js.map +1 -0
  47. package/dist/team-manager/types.d.ts +164 -0
  48. package/dist/team-manager/types.d.ts.map +1 -0
  49. package/dist/team-manager/types.js +27 -0
  50. package/dist/team-manager/types.js.map +1 -0
  51. package/dist/tools.d.ts +41 -1
  52. package/dist/tools.d.ts.map +1 -1
  53. package/dist/tools.js +288 -32
  54. package/dist/tools.js.map +1 -1
  55. package/package.json +1 -1
  56. package/src/cli.ts +20 -0
  57. package/src/mcp.ts +64 -25
  58. package/src/sdk-output-adapter.ts +177 -0
  59. package/src/session.ts +423 -15
  60. package/src/slash-commands.ts +3 -7
  61. package/src/smart-approval.ts +1 -0
  62. package/src/system-prompt-generator.ts +59 -26
  63. package/src/team-manager/index.ts +5 -0
  64. package/src/team-manager/message-broker.ts +751 -0
  65. package/src/team-manager/team-coordinator.ts +1117 -0
  66. package/src/team-manager/team-store.ts +558 -0
  67. package/src/team-manager/teammate-spawner.ts +800 -0
  68. package/src/team-manager/types.ts +206 -0
  69. package/src/tools.ts +316 -33
@@ -0,0 +1,206 @@
1
+ export type DisplayMode = 'auto' | 'tmux' | 'iterm2' | 'in-process';
2
+
3
+ export type TeamStatus = 'active' | 'completed' | 'cancelled';
4
+ export type MemberStatus = 'spawning' | 'active' | 'idle' | 'shutdown';
5
+ export type TaskStatus = 'pending' | 'in_progress' | 'completed';
6
+ export type TaskPriority = 'high' | 'medium' | 'low';
7
+ export type MessageType = 'direct' | 'broadcast' | 'task_update' | 'shutdown_request' | 'shutdown_response';
8
+ export type MessageDeliveryStatus = 'pending' | 'sent' | 'delivered' | 'acknowledged' | 'failed';
9
+ export type AckStatus = 'received' | 'processed';
10
+
11
+ export type MemberRole = 'lead' | 'teammate';
12
+
13
+ export interface MemberPermissions {
14
+ canCreateTask: boolean;
15
+ canAssignTask: boolean;
16
+ canClaimTask: boolean;
17
+ canCompleteTask: boolean;
18
+ canDeleteTask: boolean;
19
+ canMessageAll: boolean;
20
+ canMessageDirect: boolean;
21
+ canShutdownTeam: boolean;
22
+ canShutdownMember: boolean;
23
+ canInviteMembers: boolean;
24
+ canAccessSharedFiles: boolean;
25
+ }
26
+
27
+ export const LEAD_PERMISSIONS: MemberPermissions = {
28
+ canCreateTask: true,
29
+ canAssignTask: true,
30
+ canClaimTask: true,
31
+ canCompleteTask: true,
32
+ canDeleteTask: true,
33
+ canMessageAll: true,
34
+ canMessageDirect: true,
35
+ canShutdownTeam: true,
36
+ canShutdownMember: true,
37
+ canInviteMembers: true,
38
+ canAccessSharedFiles: true,
39
+ };
40
+
41
+ export const TEAMMATE_PERMISSIONS: MemberPermissions = {
42
+ canCreateTask: false,
43
+ canAssignTask: false,
44
+ canClaimTask: true,
45
+ canCompleteTask: true,
46
+ canDeleteTask: false,
47
+ canMessageAll: true,
48
+ canMessageDirect: true,
49
+ canShutdownTeam: false,
50
+ canShutdownMember: false,
51
+ canInviteMembers: false,
52
+ canAccessSharedFiles: false,
53
+ };
54
+
55
+ export interface Team {
56
+ teamId: string;
57
+ teamName: string;
58
+ createdAt: number;
59
+ leadSessionId: string;
60
+ leadMemberId: string;
61
+ members: TeamMember[];
62
+ status: TeamStatus;
63
+ workDir: string;
64
+ sharedTaskList: TeamTask[];
65
+ }
66
+
67
+ export interface TeamMember {
68
+ memberId: string;
69
+ name: string;
70
+ role: MemberRole;
71
+ memberRole?: string;
72
+ model?: string;
73
+ status: MemberStatus;
74
+ processId?: number;
75
+ lastActivity?: number;
76
+ displayMode?: 'tmux' | 'iterm2' | 'in-process';
77
+ permissions: MemberPermissions;
78
+ }
79
+
80
+ export interface TeamTask {
81
+ taskId: string;
82
+ teamId: string;
83
+ title: string;
84
+ description: string;
85
+ status: TaskStatus;
86
+ assignee?: string;
87
+ dependencies: string[];
88
+ priority: TaskPriority;
89
+ createdAt: number;
90
+ updatedAt: number;
91
+ createdBy: string;
92
+ result?: string;
93
+ version: number;
94
+ }
95
+
96
+ export interface TeamMessage {
97
+ messageId: string;
98
+ teamId: string;
99
+ fromMemberId: string;
100
+ fromMemberName?: string;
101
+ toMemberId: string | 'broadcast';
102
+ content: string;
103
+ timestamp: number;
104
+ type: MessageType;
105
+ read: boolean;
106
+ requiresAck?: boolean;
107
+ }
108
+
109
+ export interface MessageAck {
110
+ messageId: string;
111
+ fromMemberId: string;
112
+ status: AckStatus;
113
+ timestamp: number;
114
+ error?: string;
115
+ }
116
+
117
+ export interface MessageDeliveryInfo {
118
+ messageId: string;
119
+ status: MessageDeliveryStatus;
120
+ sentAt: number;
121
+ acknowledgedAt?: number;
122
+ acknowledgedBy?: string[];
123
+ failedReason?: string;
124
+ }
125
+
126
+ export interface TeammateConfig {
127
+ name: string;
128
+ role: string;
129
+ prompt: string;
130
+ model?: string;
131
+ allowedTools?: string[];
132
+ }
133
+
134
+ export interface TeamMessagePayload {
135
+ to_member_id?: string | 'broadcast';
136
+ content: string;
137
+ }
138
+
139
+ export interface TaskCreateConfig {
140
+ title: string;
141
+ description: string;
142
+ assignee?: string;
143
+ dependencies?: string[];
144
+ priority?: TaskPriority;
145
+ }
146
+
147
+ export interface TaskUpdateConfig {
148
+ task_id: string;
149
+ action: 'claim' | 'complete' | 'release';
150
+ result?: string;
151
+ }
152
+
153
+ export interface TeamToolParams {
154
+ team_name?: string;
155
+ teammates?: TeammateConfig[];
156
+ team_action?: 'create' | 'spawn' | 'message' | 'task_create' | 'task_update' | 'task_list' | 'task_delete' | 'shutdown' | 'cleanup' | 'list_teams' | 'get_status';
157
+ team_id?: string;
158
+ member_id?: string;
159
+ message?: TeamMessagePayload;
160
+ task_config?: TaskCreateConfig;
161
+ task_update?: TaskUpdateConfig;
162
+ task_filter?: 'all' | 'pending' | 'available' | 'in_progress' | 'completed';
163
+ }
164
+
165
+ export interface TeamModeConfig {
166
+ teamId: string;
167
+ memberId: string;
168
+ memberName: string;
169
+ memberRole: MemberRole;
170
+ specificRole?: string;
171
+ teamDir: string;
172
+ tasksDir: string;
173
+ spawnPrompt?: string;
174
+ permissions: MemberPermissions;
175
+ }
176
+
177
+ export interface TeamCreateResult {
178
+ team_id: string;
179
+ team_name: string;
180
+ display_mode: DisplayMode;
181
+ lead_id: string;
182
+ members: Array<{
183
+ id: string;
184
+ name: string;
185
+ role: string;
186
+ display_mode: string;
187
+ }>;
188
+ }
189
+
190
+ export interface TaskListResult {
191
+ team_id: string;
192
+ filter: string;
193
+ total_count: number;
194
+ tasks: Array<{
195
+ task_id: string;
196
+ title: string;
197
+ description: string;
198
+ status: TaskStatus;
199
+ priority: TaskPriority;
200
+ assignee?: string;
201
+ dependencies: string[];
202
+ created_at: number;
203
+ updated_at: number;
204
+ result?: string;
205
+ }>;
206
+ }
package/src/tools.ts CHANGED
@@ -1434,43 +1434,46 @@ export interface ToolCallOptions {
1434
1434
 
1435
1435
  export class TaskTool implements Tool {
1436
1436
  name = 'task';
1437
- description = `Launch specialized AI subagents to handle complex, multi-step tasks. Subagents are expert agents designed for specific domains like planning, code exploration, frontend testing, and more.
1438
1437
 
1439
- # When to Use
1440
- - Complex tasks requiring specialized expertise (planning, analysis, testing)
1441
- - Multi-step workflows that benefit from dedicated focus
1442
- - When you need to delegate work to avoid context overload
1443
- - Parallel execution of independent tasks across different domains
1444
- - User explicitly requests a specific type of agent (e.g., "use the frontend tester")
1445
-
1446
- # Available SubAgents
1447
- 1. **plan-agent** - Task planning and breakdown, risk analysis, implementation roadmaps
1448
- 2. **explore-agent** - Codebase exploration, architecture analysis, finding specific code
1449
- 3. **frontend-tester** - Writing and running frontend tests, UI validation
1450
- 4. **code-reviewer** - Code review, security checks, bug detection
1451
- 5. **frontend-developer** - Frontend development (React, TypeScript, modern web)
1452
- 6. **backend-developer** - Backend development (Node.js, APIs, databases)
1453
- 7. **gui-subagent** - Browser automation, visual web interactions, desktop application automation
1438
+ get description(): string {
1439
+ return `Launch specialized AI subagents to handle complex tasks autonomously.
1454
1440
 
1455
- # When NOT to Use
1456
- - Simple, straightforward tasks you can handle directly
1457
- - Tasks that don't require specialized expertise
1458
- - Single-step operations (use other tools instead)
1441
+ # SubAgent Types
1442
+ | Type | Use Case |
1443
+ |------|----------|
1444
+ | **plan-agent** | Task planning, risk analysis, roadmaps |
1445
+ | **explore-agent** | Codebase exploration, architecture analysis |
1446
+ | **code-reviewer** | Code review, security checks, bug detection |
1447
+ | **frontend-tester** | Frontend tests, UI validation |
1448
+ | **frontend-developer** | React, TypeScript, web development |
1449
+ | **backend-developer** | Node.js, APIs, databases |
1450
+ | **gui-subagent** | Browser automation, visual interactions |
1459
1451
 
1460
- # Examples
1461
- - "Analyze the authentication module and create a security report" → explore-agent
1462
- - "Create a detailed implementation plan for feature X" → plan-agent
1463
- - "Write unit tests for this React component" → frontend-tester
1464
- - "Review my changes for potential bugs" → code-reviewer
1465
- - "Automatically fill out this form and navigate the website" → gui-subagent
1466
- - "Test the login process on the desktop application" → gui-subagent
1467
- - "send a message to the my mom on the desktop application wechat" → gui-subagent
1452
+ # SubAgent Modes
1453
+
1454
+ ## Single Agent
1455
+ Launch a single specialized agent:
1456
+ task(description="Explore auth flow", subagent_type="explore-agent")
1457
+
1458
+ ## Parallel Agents
1459
+ Launch multiple agents to work in parallel:
1460
+ task(description="Review code", agents=[{subagent_type:"code-reviewer", prompt:"Check security"}, {subagent_type:"frontend-tester", prompt:"Test forms"}])
1461
+
1462
+ # When to Use SubAgents
1463
+ - Complex tasks needing specialized expertise
1464
+ - Independent tasks that can run in parallel
1465
+ - One-time exploratory or research tasks
1466
+
1467
+ # When NOT to Use SubAgents
1468
+ - Tasks requiring context continuity
1469
+ - Multi-step workflows with dependencies
1468
1470
 
1469
1471
  # Best Practices
1470
- - Provide clear, specific prompts to subagents
1471
- - Include relevant context (file paths, requirements, constraints)
1472
- - Set appropriate executionMode if needed
1473
- - For parallel execution, ensure tasks are truly independent`;
1472
+ - **Clear Prompts**: Provide detailed context and specific goals
1473
+ - **Parallel Mode**: Use for independent tasks to save time
1474
+ - **Type Selection**: Choose appropriate subagent type for the task`;
1475
+ }
1476
+
1474
1477
  allowedModes = [
1475
1478
  ExecutionMode.YOLO,
1476
1479
  ExecutionMode.ACCEPT_EDITS,
@@ -1482,7 +1485,7 @@ export class TaskTool implements Tool {
1482
1485
  params: {
1483
1486
  description: string;
1484
1487
  prompt?: string;
1485
- query?: string; // Support both prompt and query (tool definition uses query)
1488
+ query?: string;
1486
1489
  subagent_type?:
1487
1490
  | 'general-purpose'
1488
1491
  | 'plan-agent'
@@ -2819,6 +2822,200 @@ export class TaskTool implements Tool {
2819
2822
  }
2820
2823
  }
2821
2824
 
2825
+ export class TeamTool implements Tool {
2826
+ name = 'Team';
2827
+
2828
+ get description(): string {
2829
+ return `Manage AI agent teams with shared tasks and real-time messaging.
2830
+
2831
+ # When to Use
2832
+ - **Complex multi-step projects**: Tasks requiring different expertise (frontend, backend, testing)
2833
+ - **Parallel execution**: Multiple independent subtasks that can run simultaneously
2834
+ - **Long-running operations**: Tasks that benefit from persistent agent instances
2835
+ - **Cross-layer coordination**: Work spanning multiple system layers or components
2836
+ - **Collaborative problem-solving**: Tasks needing different perspectives or skill sets
2837
+
2838
+ # When NOT to Use
2839
+ - **Simple single-step tasks**: Use direct tool calls or Task tool instead
2840
+ - **Sequential dependencies**: When each step must complete before the next starts
2841
+ - **Quick one-off queries**: Team setup has overhead, not worth it for simple tasks
2842
+ - **Single expertise required**: When one agent can handle the entire task efficiently
2843
+ - **Tight resource constraints**: Each teammate consumes additional API calls and memory
2844
+
2845
+ # Best Practices
2846
+
2847
+ ## For Lead
2848
+ - **Clear role definitions**: Give each teammate a specific role and focused prompt
2849
+ - **Small teams first**: Start with 2-3 teammates; add more only if needed
2850
+ - **Monitor progress**: Check task status before assigning new work
2851
+ - **Coordinate via messages**: Send message only necessary. Use broadcast for team-wide updates, direct messages for specific teammates
2852
+ - **After completing work**: Always check message queue before complete the tasks
2853
+ - **Clean shutdown**: Always call cleanup when team work is complete
2854
+
2855
+ ## For Teammate
2856
+ - **Complete assigned tasks**: Execute the task described in your initial prompt or assigned via messages
2857
+ - **Send result to lead**: After completing a task, use message to send your result directly to lead
2858
+ - **Update task status**: Call task_update with action="complete" to mark the task done
2859
+ - **Coordinate via messages**: Send message only necessary. Use broadcast for team-wide updates, direct messages for specific teammates
2860
+ - **After completing work**: Always check message queue before becoming idle
2861
+
2862
+ # Your Role
2863
+ - \`your_role: "lead"\` - You can create teams, manage members, assign tasks
2864
+ - \`your_role: "teammate"\` - You execute assigned tasks, communicate with lead and teammate
2865
+
2866
+ # Team Actions
2867
+
2868
+ ## Team Management (Lead Only)
2869
+ - **create**: Create team and spawn teammates
2870
+ - team(action="create", team_name="My Team", teammates=[{name: "coder", role: "developer", prompt: "You are a code reviewer"}, {name: "reviewer", role: "QA", prompt: "You are a QA engineer"}])
2871
+ - **spawn**: Add new teammates to existing team
2872
+ - team(action="spawn", team_id="xxx", teammates=[{name: "new-member", role: "developer", prompt: "..."}])
2873
+ - **shutdown**: Stop a teammate
2874
+ - team(action="shutdown", team_id="xxx", member_id="xxx")
2875
+ - **cleanup**: Delete team
2876
+ - team(action="cleanup", team_id="xxx")
2877
+
2878
+ ## Communication
2879
+ - **broadcast**: Send message to all teammates
2880
+ - team(action="message", team_id="xxx", message={to_member_id: "broadcast", content: "..."})
2881
+ - **message**: Send direct message to specific teammate
2882
+ - team(action="message", team_id="xxx", message={to_member_id: "target-id", content: "..."})
2883
+ - **message_queue**: Get teammate message queue status or retrieve messages
2884
+ - team(action="message_queue") // Returns: { length }
2885
+ - team(action="message_queue", pop=true) // Returns and clears all messages: { count, messages }
2886
+
2887
+ ## Task Management
2888
+ - **task_create**: Create a new task (Lead)
2889
+ - team(action="task_create", team_id="xxx", task_config={title: "...", description: "...", priority: "high"})
2890
+ - **task_delete**: Delete a task (Lead)
2891
+ - team(action="task_delete", team_id="xxx", task_id="xxx")
2892
+ - **task_list**: List all tasks
2893
+ - team(action="task_list", team_id="xxx", task_filter="all"|"pending"|"available"|"in_progress"|"completed")
2894
+ - **task_update**: Update task status (claim/complete/release)
2895
+ - team(action="task_update", team_id="xxx", task_update={task_id: "xxx", action: "claim"|"complete"|"release", result?: "..."})
2896
+
2897
+ ## View Info
2898
+ - **get_status**: Get team status (includes your_role)
2899
+ - team(action="get_status", team_id="xxx")
2900
+ - **list_teams**: List all teams
2901
+ - team(action="list_teams")
2902
+ `;
2903
+ }
2904
+
2905
+ allowedModes = [
2906
+ ExecutionMode.YOLO,
2907
+ ExecutionMode.ACCEPT_EDITS,
2908
+ ExecutionMode.PLAN,
2909
+ ExecutionMode.SMART,
2910
+ ];
2911
+
2912
+ async execute(params: {
2913
+ action: 'create' | 'spawn' | 'message' | 'shutdown' | 'cleanup' | 'task_create' | 'task_update' | 'task_delete' | 'task_list' | 'get_status' | 'list_teams' | 'message_queue';
2914
+ team_name?: string;
2915
+ team_id?: string;
2916
+ member_id?: string;
2917
+ teammates?: Array<{ name: string; role: string; prompt: string; model?: string }>;
2918
+ message?: { to_member_id?: string | 'broadcast'; content: string };
2919
+ task_config?: { title: string; description: string; assignee?: string; dependencies?: string[]; priority?: 'high' | 'medium' | 'low' };
2920
+ task_update?: { task_id: string; action: 'claim' | 'complete' | 'release'; result?: string };
2921
+ task_id?: string;
2922
+ task_filter?: 'all' | 'pending' | 'available' | 'in_progress' | 'completed';
2923
+ pop?: boolean;
2924
+ }): Promise<{ success: boolean; message: string; result?: any }> {
2925
+ // Handle message_queue action separately (doesn't need coordinator)
2926
+ if (params.action === 'message_queue') {
2927
+ const session = getSingletonSession();
2928
+ if (!session) {
2929
+ return { success: false, message: 'No active session found' };
2930
+ }
2931
+
2932
+ if (params.pop) {
2933
+ // Pop and return all messages, clearing the queue
2934
+ const messages = session.popTeammateMessages();
2935
+ return {
2936
+ success: true,
2937
+ message: `Retrieved ${messages.length} messages from queue`,
2938
+ result: {
2939
+ count: messages.length,
2940
+ messages: messages.map(m => ({
2941
+ role: m.role,
2942
+ content: m.content,
2943
+ timestamp: m.timestamp,
2944
+ })),
2945
+ },
2946
+ };
2947
+ }
2948
+
2949
+ // Just return queue info
2950
+ const queueInfo = session.getTeammateMessageQueueInfo();
2951
+ return {
2952
+ success: true,
2953
+ message: `Message queue: ${queueInfo.length} messages`,
2954
+ result: queueInfo,
2955
+ };
2956
+ }
2957
+
2958
+ const { getTeamCoordinator } = await import('./team-manager/index.js');
2959
+ const coordinator = getTeamCoordinator();
2960
+
2961
+ // Check message queue before cleanup
2962
+ if (params.action === 'cleanup') {
2963
+ const session = getSingletonSession();
2964
+ if (session) {
2965
+ const queueInfo = session.getTeammateMessageQueueInfo();
2966
+ if (queueInfo.length > 0) {
2967
+ return {
2968
+ success: false,
2969
+ message: `Cannot cleanup: message queue has ${queueInfo.length} unprocessed messages. Process them first with team(action="message_queue", pop=true)`,
2970
+ result: { queue_length: queueInfo.length },
2971
+ };
2972
+ }
2973
+ }
2974
+ }
2975
+
2976
+ // Map team tool params to TeamToolParams
2977
+ const teamParams = {
2978
+ team_action: params.action,
2979
+ team_name: params.team_name,
2980
+ team_id: params.team_id,
2981
+ member_id: params.member_id,
2982
+ teammates: params.teammates,
2983
+ message: params.message,
2984
+ task_config: params.task_config,
2985
+ task_update: params.task_update,
2986
+ task_id: params.task_id,
2987
+ task_filter: params.task_filter,
2988
+ };
2989
+
2990
+ const result = await coordinator.execute(teamParams);
2991
+
2992
+ // After successful team creation, connect lead agent to broker
2993
+ if (params.action === 'create' && result.success && result.result) {
2994
+ const { team_id, your_member_id, broker_port } = result.result;
2995
+ if (team_id && your_member_id && broker_port) {
2996
+ const session = getSingletonSession();
2997
+ if (session) {
2998
+ try {
2999
+ await session.connectToTeamBroker(team_id, your_member_id, broker_port);
3000
+ } catch (err) {
3001
+ console.error('[Team] Failed to connect to message broker:', err);
3002
+ }
3003
+ }
3004
+ }
3005
+ }
3006
+
3007
+ // After successful team cleanup, disconnect lead agent from broker
3008
+ if (params.action === 'cleanup' && result.success) {
3009
+ const session = getSingletonSession();
3010
+ if (session) {
3011
+ await session.cleanupTeamMode();
3012
+ }
3013
+ }
3014
+
3015
+ return result;
3016
+ }
3017
+ }
3018
+
2822
3019
  export class ReadBashOutputTool implements Tool {
2823
3020
  name = 'ReadBashOutput';
2824
3021
  description = `Retrieve output from a background task that was started with Bash(run_in_bg=true).
@@ -3705,6 +3902,7 @@ export class ToolRegistry {
3705
3902
  this.register(this.todoWriteTool);
3706
3903
  this.register(new TodoReadTool(this.todoWriteTool));
3707
3904
  this.register(new TaskTool());
3905
+ this.register(new TeamTool());
3708
3906
  this.register(new ReadBashOutputTool());
3709
3907
  this.register(new WebFetchTool());
3710
3908
  this.register(new AskUserQuestionTool());
@@ -4367,6 +4565,91 @@ export class ToolRegistry {
4367
4565
  };
4368
4566
  break;
4369
4567
 
4568
+ case 'Team':
4569
+ parameters = {
4570
+ type: 'object',
4571
+ properties: {
4572
+ action: {
4573
+ type: 'string',
4574
+ enum: ['create', 'spawn', 'message', 'shutdown', 'cleanup', 'task_create', 'task_update', 'task_delete', 'task_list', 'get_status', 'list_teams', 'message_queue'],
4575
+ description: 'The team action to perform',
4576
+ },
4577
+ team_name: {
4578
+ type: 'string',
4579
+ description: 'Team name (required for create action)',
4580
+ },
4581
+ team_id: {
4582
+ type: 'string',
4583
+ description: 'Team ID (required for most actions)',
4584
+ },
4585
+ member_id: {
4586
+ type: 'string',
4587
+ description: 'Member ID (required for shutdown action)',
4588
+ },
4589
+ teammates: {
4590
+ type: 'array',
4591
+ description: 'Array of teammate configs (required for create/spawn)',
4592
+ items: {
4593
+ type: 'object',
4594
+ properties: {
4595
+ name: { type: 'string', description: 'Teammate name' },
4596
+ role: { type: 'string', description: 'Teammate role' },
4597
+ prompt: { type: 'string', description: 'Teammate system prompt' },
4598
+ model: { type: 'string', description: 'Optional model override' },
4599
+ },
4600
+ required: ['name', 'role', 'prompt'],
4601
+ },
4602
+ },
4603
+ message: {
4604
+ type: 'object',
4605
+ description: 'Message payload (required for message action)',
4606
+ properties: {
4607
+ to_member_id: {
4608
+ type: 'string',
4609
+ description: 'Target member ID or "broadcast"',
4610
+ },
4611
+ content: {
4612
+ type: 'string',
4613
+ description: 'Message content',
4614
+ },
4615
+ },
4616
+ },
4617
+ task_config: {
4618
+ type: 'object',
4619
+ description: 'Task creation config (for task_create)',
4620
+ properties: {
4621
+ title: { type: 'string', description: 'Task title' },
4622
+ description: { type: 'string', description: 'Task description' },
4623
+ priority: { type: 'string', enum: ['high', 'medium', 'low'], description: 'Task priority' },
4624
+ },
4625
+ },
4626
+ task_update: {
4627
+ type: 'object',
4628
+ description: 'Task update config (for task_update)',
4629
+ properties: {
4630
+ task_id: { type: 'string', description: 'Task ID' },
4631
+ action: { type: 'string', enum: ['claim', 'complete', 'release'], description: 'Update action' },
4632
+ result: { type: 'string', description: 'Task result (optional)' },
4633
+ },
4634
+ },
4635
+ task_id: {
4636
+ type: 'string',
4637
+ description: 'Task ID (required for task_delete)',
4638
+ },
4639
+ task_filter: {
4640
+ type: 'string',
4641
+ enum: ['all', 'pending', 'available', 'in_progress', 'completed'],
4642
+ description: 'Task filter (for task_list)',
4643
+ },
4644
+ pop: {
4645
+ type: 'boolean',
4646
+ description: 'For message_queue: if true, retrieve and clear all messages from queue',
4647
+ },
4648
+ },
4649
+ required: ['action'],
4650
+ };
4651
+ break;
4652
+
4370
4653
  default: {
4371
4654
  // For MCP tools, use their inputSchema; for other unknown tools, keep empty schema
4372
4655
  const mcpTool = tool as any;