@unieai/rabi-tool-agent-team 0.0.0-stage → 0.2.2-rc.5

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeepSeek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,8 @@
1
- # Temporary Holding Version
1
+ # @unieai/rabi-tool-agent-team
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Scoped model-facing Agent Teams tools over ctx.agentTeams
4
+
5
+ Part of Rabi, the agent harness UnieAI Code runs on. Installed as a dependency of `@unieai/rabi`;
6
+ not meant to be used on its own.
7
+
8
+ See LICENSE for the license and copyright of this package.
package/lib/index.js ADDED
@@ -0,0 +1,317 @@
1
+ import z from "@unieai/schemastery";
2
+ import { SubagentError } from "@unieai/rabi-subagent";
3
+ import { TeamTaskId } from "@unieai/rabi-agent-team";
4
+ import { defineTool } from "@unieai/rabi-tools";
5
+ //#region lib/types/index.js
6
+ /** Conditionally available task-board tools and guidance for Agent Teams. */
7
+ /** Cordis plugin name. */
8
+ const name = "tool-agent-team";
9
+ /** Services required by the Team tool plugin. */
10
+ const inject = [
11
+ "agentTeams",
12
+ "subagents",
13
+ "tools",
14
+ "systemPrompt"
15
+ ];
16
+ /** Loader schema for the opt-in Team tool plugin. */
17
+ const Config = z.object({});
18
+ /** Configuration keys removed when Team reused subagent creation and messaging. */
19
+ const REMOVED_CONFIG_KEYS = [
20
+ "interrupt",
21
+ "freshProvider",
22
+ "forkProvider"
23
+ ];
24
+ /** Model-facing collaboration guidance shared by Lead and teammates. */
25
+ const TEAM_POLICY = `Agent Teams is available in this session.
26
+
27
+ The Team Lead and all teammates share the same working directory and filesystem. Edits are immediately visible to every member. Split write work into disjoint scopes, record expected write scopes on shared tasks, and use task dependencies when work must be ordered. Write-scope overlap is advisory, not a lock.
28
+
29
+ Use the names returned by subagent, subagent_fork, or list_agents as owner when assigning or filtering shared tasks. The root can reassign tasks to itself or any continuable descendant; other agents claim ready tasks themselves. Shared-task workflow is list, get, claim with the current revision, perform the work, then complete. Task readiness never starts an owner. The root agent must wait for required teammates before giving the final answer.
30
+
31
+ Task changes do not end wait_agent calls, add inbox messages, or start idle agents. Use send_message when another agent needs to act on a task.`;
32
+ /** One shared task, matching the public `TeamTaskView`. */
33
+ const TASK_VIEW_SCHEMA = {
34
+ type: "object",
35
+ additionalProperties: false,
36
+ properties: {
37
+ id: {
38
+ type: "string",
39
+ required: true
40
+ },
41
+ revision: {
42
+ type: "integer",
43
+ required: true
44
+ },
45
+ subject: {
46
+ type: "string",
47
+ required: true
48
+ },
49
+ description: {
50
+ type: "string",
51
+ required: true
52
+ },
53
+ status: {
54
+ type: "string",
55
+ required: true,
56
+ enum: [
57
+ "pending",
58
+ "in_progress",
59
+ "completed",
60
+ "deleted"
61
+ ]
62
+ },
63
+ owner: { type: "string" },
64
+ blockedBy: {
65
+ type: "array",
66
+ required: true,
67
+ items: { type: "string" }
68
+ },
69
+ writeScopes: {
70
+ type: "array",
71
+ required: true,
72
+ items: { type: "string" }
73
+ },
74
+ ready: {
75
+ type: "boolean",
76
+ required: true
77
+ },
78
+ writeScopeWarnings: {
79
+ type: "array",
80
+ required: true,
81
+ items: { type: "string" }
82
+ }
83
+ }
84
+ };
85
+ const TASK_LIST_VALUE_SCHEMA = {
86
+ type: "object",
87
+ additionalProperties: false,
88
+ properties: {
89
+ tasks: {
90
+ type: "array",
91
+ required: true,
92
+ items: TASK_VIEW_SCHEMA
93
+ },
94
+ nextCursor: { type: "integer" }
95
+ }
96
+ };
97
+ /**
98
+ * Declare one canonical output schema with compact model-facing JSON. Every
99
+ * Team result is a fixed record, so the declared schema is what makes the
100
+ * compiler check `execute` against the value the model is promised.
101
+ * @param schema - canonical value schema for one tool.
102
+ * @returns the `output` declaration accepted by {@link defineTool}.
103
+ */
104
+ function jsonOutput(schema) {
105
+ return {
106
+ schema,
107
+ render: (_args, value) => [{
108
+ type: "text",
109
+ text: JSON.stringify(value)
110
+ }]
111
+ };
112
+ }
113
+ /** Recover the exact caller guaranteed by conditional Team-tool discovery. */
114
+ function callingAgent(agent, toolName) {
115
+ /* v8 ignore next 2 -- The Team condition rejects callers without an Agent before execution. */
116
+ if (agent === void 0) throw new Error(`${toolName} requires a calling Agent`);
117
+ return agent;
118
+ }
119
+ /**
120
+ * Register Team tools and guidance selected by each caller's root Session mode.
121
+ * @param ctx - context carrying Team, subagent, tool, and system prompt services.
122
+ * @param config - the empty plugin configuration; removed keys fail at load.
123
+ */
124
+ function apply(ctx, config = {}) {
125
+ for (const key of REMOVED_CONFIG_KEYS) if (Object.hasOwn(config, key)) throw new Error(`tool-agent-team: ${key} is no longer supported; create teammates with a subagent tool`);
126
+ const withOwnerName = ({ ownerId, ownerName, ...task }) => ownerId === void 0 ? task : {
127
+ ...task,
128
+ owner: ownerName ?? ownerId
129
+ };
130
+ const enabled = (agent) => {
131
+ if (agent === void 0) return false;
132
+ try {
133
+ return ctx.agentTeams.isEnabled(agent);
134
+ } catch (error) {
135
+ if (!(error instanceof SubagentError) || error.code !== "UNAUTHORIZED") throw error;
136
+ return false;
137
+ }
138
+ };
139
+ ctx.systemPrompt.section({
140
+ name: "team:policy",
141
+ order: ctx.systemPrompt.getSectionOrder("TEAM_POLICY"),
142
+ text: ({ agent }) => enabled(agent) ? TEAM_POLICY : ""
143
+ });
144
+ ctx.tools.register(defineTool({
145
+ name: "team_task_create",
146
+ description: "Create one unowned pending task on the shared Team task board.",
147
+ parameters: {
148
+ subject: {
149
+ type: "string",
150
+ required: true,
151
+ description: "Concise task title."
152
+ },
153
+ description: {
154
+ type: "string",
155
+ required: true,
156
+ description: "Complete task details and acceptance criteria."
157
+ },
158
+ blocked_by: {
159
+ type: "array",
160
+ items: { type: "string" },
161
+ description: "Task ids that must complete first."
162
+ },
163
+ write_scopes: {
164
+ type: "array",
165
+ items: { type: "string" },
166
+ description: "Advisory workspace-relative file or directory prefixes this task expects to modify."
167
+ }
168
+ },
169
+ output: jsonOutput(TASK_VIEW_SCHEMA),
170
+ async execute(args, exec) {
171
+ const caller = callingAgent(exec.agent, "team_task_create");
172
+ return withOwnerName(await ctx.agentTeams.createTask(caller, {
173
+ subject: args.subject,
174
+ description: args.description,
175
+ ...args.blocked_by === void 0 ? {} : { blockedBy: args.blocked_by.map(TeamTaskId) },
176
+ ...args.write_scopes === void 0 ? {} : { writeScopes: args.write_scopes }
177
+ }, exec.signal));
178
+ }
179
+ }), { when: ({ agent }) => enabled(agent) });
180
+ ctx.tools.register(defineTool({
181
+ name: "team_task_list",
182
+ description: "List shared tasks, including readiness, owner, revision, blockers, and write-scope warnings.",
183
+ parameters: {
184
+ status: {
185
+ type: "string",
186
+ enum: [
187
+ "pending",
188
+ "in_progress",
189
+ "completed"
190
+ ],
191
+ description: "Optional exact status filter."
192
+ },
193
+ owner: {
194
+ type: "string",
195
+ description: "Optional owner agent name filter; cannot be combined with unowned."
196
+ },
197
+ unowned: {
198
+ type: "boolean",
199
+ description: "Filter tasks by whether they have no owner; cannot be combined with owner."
200
+ },
201
+ ready: {
202
+ type: "boolean",
203
+ description: "Optional readiness filter."
204
+ },
205
+ cursor: {
206
+ type: "integer",
207
+ description: "Zero-based result offset. Defaults to 0."
208
+ },
209
+ limit: {
210
+ type: "integer",
211
+ description: "Number of rows, 1 through 100. Defaults to 50."
212
+ }
213
+ },
214
+ output: jsonOutput(TASK_LIST_VALUE_SCHEMA),
215
+ isConcurrencySafe: () => true,
216
+ async execute(args, exec) {
217
+ const cursor = args.cursor ?? 0;
218
+ const limit = args.limit ?? 50;
219
+ if (!Number.isSafeInteger(cursor) || cursor < 0) throw new Error("cursor must be a non-negative safe integer");
220
+ if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100) throw new Error("limit must be an integer from 1 through 100");
221
+ const caller = callingAgent(exec.agent, "team_task_list");
222
+ if (args.owner !== void 0 && args.unowned !== void 0) throw new Error("owner and unowned filters cannot be combined");
223
+ const owner = args.owner === void 0 ? void 0 : await ctx.subagents.resolveName(caller, args.owner, exec.signal);
224
+ const filtered = ctx.agentTeams.listTasks(caller).filter((task) => (args.status === void 0 || task.status === args.status) && (owner === void 0 || task.ownerId === owner) && (args.unowned === void 0 || task.ownerId === void 0 === args.unowned) && (args.ready === void 0 || task.ready === args.ready));
225
+ return {
226
+ tasks: filtered.slice(cursor, cursor + limit).map(withOwnerName),
227
+ ...cursor + limit < filtered.length ? { nextCursor: cursor + limit } : {}
228
+ };
229
+ }
230
+ }), { when: ({ agent }) => enabled(agent) });
231
+ ctx.tools.register(defineTool({
232
+ name: "team_task_get",
233
+ description: "Read the complete latest value of one shared task before changing or executing it.",
234
+ parameters: { task_id: {
235
+ type: "string",
236
+ required: true,
237
+ description: "Shared task id."
238
+ } },
239
+ output: jsonOutput(TASK_VIEW_SCHEMA),
240
+ isConcurrencySafe: () => true,
241
+ execute(args, exec) {
242
+ const caller = callingAgent(exec.agent, "team_task_get");
243
+ const task = ctx.agentTeams.getTask(caller, TeamTaskId(args.task_id));
244
+ return Promise.resolve(withOwnerName(task));
245
+ }
246
+ }), { when: ({ agent }) => enabled(agent) });
247
+ ctx.tools.register(defineTool({
248
+ name: "team_task_update",
249
+ description: "Compare-and-set a shared task action using the latest revision from team_task_get or team_task_list.",
250
+ parameters: {
251
+ task_id: {
252
+ type: "string",
253
+ required: true,
254
+ description: "Shared task id."
255
+ },
256
+ expected_revision: {
257
+ type: "integer",
258
+ required: true,
259
+ description: "Current task revision used as the CAS precondition."
260
+ },
261
+ action: {
262
+ type: "string",
263
+ required: true,
264
+ enum: [
265
+ "claim",
266
+ "release",
267
+ "edit",
268
+ "set_dependencies",
269
+ "complete",
270
+ "reopen",
271
+ "reassign",
272
+ "delete"
273
+ ],
274
+ description: "Task transition to apply."
275
+ },
276
+ subject: {
277
+ type: "string",
278
+ description: "Replacement title for edit."
279
+ },
280
+ description: {
281
+ type: "string",
282
+ description: "Replacement details for edit."
283
+ },
284
+ blocked_by: {
285
+ type: "array",
286
+ items: { type: "string" },
287
+ description: "Complete blocker list for set_dependencies."
288
+ },
289
+ write_scopes: {
290
+ type: "array",
291
+ items: { type: "string" },
292
+ description: "Replacement advisory write scopes for edit."
293
+ },
294
+ owner: {
295
+ type: "string",
296
+ description: "Agent name of the root or any continuable descendant for root-only reassign; omit to unassign."
297
+ }
298
+ },
299
+ output: jsonOutput(TASK_VIEW_SCHEMA),
300
+ async execute(args, exec) {
301
+ const caller = callingAgent(exec.agent, "team_task_update");
302
+ const taskId = TeamTaskId(args.task_id);
303
+ return withOwnerName(await ctx.agentTeams.updateTask(caller, {
304
+ taskId,
305
+ expectedRevision: args.expected_revision,
306
+ action: args.action,
307
+ ...args.subject === void 0 ? {} : { subject: args.subject },
308
+ ...args.description === void 0 ? {} : { description: args.description },
309
+ ...args.blocked_by === void 0 ? {} : { blockedBy: args.blocked_by.map(TeamTaskId) },
310
+ ...args.write_scopes === void 0 ? {} : { writeScopes: args.write_scopes },
311
+ ...args.owner === void 0 ? {} : { owner: await ctx.subagents.resolveName(caller, args.owner, exec.signal) }
312
+ }, exec.signal));
313
+ }
314
+ }), { when: ({ agent }) => enabled(agent) });
315
+ }
316
+ //#endregion
317
+ export { Config, apply, inject, name };
@@ -0,0 +1,18 @@
1
+ /** Conditionally available task-board tools and guidance for Agent Teams. */
2
+ import type { Context } from '@unieai/cordis';
3
+ import z from '@unieai/schemastery';
4
+ /** Cordis plugin name. */
5
+ export declare const name = "tool-agent-team";
6
+ /** Services required by the Team tool plugin. */
7
+ export declare const inject: string[];
8
+ /** The Team tool plugin takes no configuration. */
9
+ export type Config = Record<never, never>;
10
+ /** Loader schema for the opt-in Team tool plugin. */
11
+ export declare const Config: z<Config>;
12
+ /**
13
+ * Register Team tools and guidance selected by each caller's root Session mode.
14
+ * @param ctx - context carrying Team, subagent, tool, and system prompt services.
15
+ * @param config - the empty plugin configuration; removed keys fail at load.
16
+ */
17
+ export declare function apply(ctx: Context, config?: Config): void;
18
+ //# sourceMappingURL=index.d.ts.map
package/locale/de.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Team-Tools",
4
+ "description": "Geben Sie Agenten Tools an die Hand, mit denen sie Mitglieder koordinieren, Nachrichten austauschen und gemeinsame Aufgaben verwalten können."
5
+ }
6
+ }
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Team tools",
4
+ "description": "Give agents tools to manage their shared task board."
5
+ }
6
+ }
package/locale/es.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Herramientas de equipo",
4
+ "description": "Ofrezca a los agentes herramientas para coordinar miembros, intercambiar mensajes y gestionar tareas compartidas."
5
+ }
6
+ }
package/locale/fr.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Outils d'équipe",
4
+ "description": "Donnez aux agents des outils pour coordonner les membres, échanger des messages et gérer les tâches partagées."
5
+ }
6
+ }
package/locale/ja.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "チームツール",
4
+ "description": "共有タスクボードを管理するツールをエージェントに提供します。"
5
+ }
6
+ }
package/locale/pt.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Ferramentas de equipe",
4
+ "description": "Dê aos agentes ferramentas para coordenar membros, trocar mensagens e gerenciar tarefas compartilhadas."
5
+ }
6
+ }
package/locale/ru.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Командные инструменты",
4
+ "description": "Предоставьте агентам инструменты для координации участников, обмена сообщениями и управления общими задачами."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "团队工具",
4
+ "description": "为智能体提供共享任务板管理工具。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@unieai/rabi-tool-agent-team",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "description": "Scoped model-facing Agent Teams tools over ctx.agentTeams",
4
+ "version": "0.2.2-rc.5",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "main": "lib/index.js",
10
+ "types": "lib/types/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./lib/types/index.d.ts",
14
+ "default": "./lib/index.js"
15
+ },
16
+ "./locale/*.json": "./locale/*.json",
17
+ "./src/*": "./src/*",
18
+ "./package.json": "./package.json"
19
+ },
20
+ "files": [
21
+ "locale/*.json",
22
+ "lib/index.js",
23
+ "lib/types/**/*.d.ts",
24
+ "lib/types/**/*.d.ts.map",
25
+ "lib/**/*.js.map",
26
+ "src",
27
+ "README.md"
28
+ ],
29
+ "license": "MIT",
30
+ "dependencies": {
31
+ "@unieai/schemastery": "3.19.0"
32
+ },
33
+ "peerDependencies": {
34
+ "@unieai/rabi-agent": "0.2.2-rc.5",
35
+ "@unieai/rabi-session": "0.2.2-rc.5",
36
+ "@unieai/rabi-subagent": "0.2.2-rc.5",
37
+ "@unieai/rabi-system-prompt": "0.2.2-rc.5",
38
+ "@unieai/rabi-agent-team": "0.2.2-rc.5",
39
+ "@unieai/rabi-tools": "0.2.2-rc.5",
40
+ "@unieai/cordis": "4.1.0"
41
+ }
42
+ }
package/src/index.ts ADDED
@@ -0,0 +1,235 @@
1
+ /** Conditionally available task-board tools and guidance for Agent Teams. */
2
+
3
+ import type { Context } from '@unieai/cordis'
4
+ import z from '@unieai/schemastery'
5
+ import type { Agent } from '@unieai/rabi-agent'
6
+ import { SubagentError } from '@unieai/rabi-subagent'
7
+ import { TeamTaskId } from '@unieai/rabi-agent-team'
8
+ import type { TeamTaskView } from '@unieai/rabi-agent-team'
9
+ import { defineTool } from '@unieai/rabi-tools'
10
+ import type { InferValue, ValueSchemaSpec } from '@unieai/rabi-tools'
11
+
12
+ /** Cordis plugin name. */
13
+ export const name = 'tool-agent-team'
14
+ /** Services required by the Team tool plugin. */
15
+ export const inject = ['agentTeams', 'subagents', 'tools', 'systemPrompt']
16
+
17
+ /** The Team tool plugin takes no configuration. */
18
+ export type Config = Record<never, never>
19
+
20
+ /** Loader schema for the opt-in Team tool plugin. */
21
+ export const Config: z<Config> = z.object({})
22
+
23
+ /** Configuration keys removed when Team reused subagent creation and messaging. */
24
+ const REMOVED_CONFIG_KEYS = ['interrupt', 'freshProvider', 'forkProvider'] as const
25
+
26
+ /** Model-facing collaboration guidance shared by Lead and teammates. */
27
+ const TEAM_POLICY = `Agent Teams is available in this session.
28
+
29
+ The Team Lead and all teammates share the same working directory and filesystem. Edits are immediately visible to every member. Split write work into disjoint scopes, record expected write scopes on shared tasks, and use task dependencies when work must be ordered. Write-scope overlap is advisory, not a lock.
30
+
31
+ Use the names returned by subagent, subagent_fork, or list_agents as owner when assigning or filtering shared tasks. The root can reassign tasks to itself or any continuable descendant; other agents claim ready tasks themselves. Shared-task workflow is list, get, claim with the current revision, perform the work, then complete. Task readiness never starts an owner. The root agent must wait for required teammates before giving the final answer.
32
+
33
+ Task changes do not end wait_agent calls, add inbox messages, or start idle agents. Use send_message when another agent needs to act on a task.`
34
+
35
+ /** One shared task, matching the public `TeamTaskView`. */
36
+ const TASK_VIEW_SCHEMA = {
37
+ type: 'object',
38
+ additionalProperties: false,
39
+ properties: {
40
+ id: { type: 'string', required: true },
41
+ revision: { type: 'integer', required: true },
42
+ subject: { type: 'string', required: true },
43
+ description: { type: 'string', required: true },
44
+ status: { type: 'string', required: true, enum: ['pending', 'in_progress', 'completed', 'deleted'] },
45
+ owner: { type: 'string' },
46
+ blockedBy: { type: 'array', required: true, items: { type: 'string' } },
47
+ writeScopes: { type: 'array', required: true, items: { type: 'string' } },
48
+ ready: { type: 'boolean', required: true },
49
+ writeScopeWarnings: { type: 'array', required: true, items: { type: 'string' } },
50
+ },
51
+ } as const
52
+
53
+ const TASK_LIST_VALUE_SCHEMA = {
54
+ type: 'object',
55
+ additionalProperties: false,
56
+ properties: {
57
+ tasks: { type: 'array', required: true, items: TASK_VIEW_SCHEMA },
58
+ nextCursor: { type: 'integer' },
59
+ },
60
+ } as const
61
+
62
+ /**
63
+ * Declare one canonical output schema with compact model-facing JSON. Every
64
+ * Team result is a fixed record, so the declared schema is what makes the
65
+ * compiler check `execute` against the value the model is promised.
66
+ * @param schema - canonical value schema for one tool.
67
+ * @returns the `output` declaration accepted by {@link defineTool}.
68
+ */
69
+ function jsonOutput<const S extends ValueSchemaSpec>(schema: S): {
70
+ schema: S
71
+ render: (args: unknown, value: InferValue<S>) => [{ type: 'text'; text: string }]
72
+ } {
73
+ return {
74
+ schema,
75
+ render: (_args: unknown, value: InferValue<S>) => [{ type: 'text', text: JSON.stringify(value) }],
76
+ }
77
+ }
78
+
79
+ /** One task as the model sees it: the owner's Session id is replaced by its agent name. */
80
+ type NamedTaskView = Omit<TeamTaskView, 'ownerId' | 'ownerName'> & { readonly owner?: string }
81
+
82
+ /** Recover the exact caller guaranteed by conditional Team-tool discovery. */
83
+ function callingAgent(agent: Agent | undefined, toolName: string): Agent {
84
+ /* v8 ignore next 2 -- The Team condition rejects callers without an Agent before execution. */
85
+ if (agent === undefined) throw new Error(`${toolName} requires a calling Agent`)
86
+ return agent
87
+ }
88
+
89
+ /**
90
+ * Register Team tools and guidance selected by each caller's root Session mode.
91
+ * @param ctx - context carrying Team, subagent, tool, and system prompt services.
92
+ * @param config - the empty plugin configuration; removed keys fail at load.
93
+ */
94
+ export function apply(ctx: Context, config: Config = {}): void {
95
+ for (const key of REMOVED_CONFIG_KEYS) {
96
+ if (Object.hasOwn(config, key)) {
97
+ throw new Error(`tool-agent-team: ${key} is no longer supported; create teammates with a subagent tool`)
98
+ }
99
+ }
100
+ const withOwnerName = ({ ownerId, ownerName, ...task }: TeamTaskView): NamedTaskView =>
101
+ ownerId === undefined ? task : { ...task, owner: ownerName ?? ownerId }
102
+ const enabled = (agent: Agent | undefined): boolean => {
103
+ if (agent === undefined) return false
104
+ try {
105
+ return ctx.agentTeams.isEnabled(agent)
106
+ } catch (error: unknown) {
107
+ if (!(error instanceof SubagentError) || error.code !== 'UNAUTHORIZED') throw error
108
+ // An independently resumed child has no active root to supply Team mode.
109
+ return false
110
+ }
111
+ }
112
+ ctx.systemPrompt.section({
113
+ name: 'team:policy',
114
+ order: ctx.systemPrompt.getSectionOrder('TEAM_POLICY'),
115
+ text: ({ agent }) => enabled(agent) ? TEAM_POLICY : '',
116
+ })
117
+ ctx.tools.register(defineTool({
118
+ name: 'team_task_create',
119
+ description: 'Create one unowned pending task on the shared Team task board.',
120
+ parameters: {
121
+ subject: { type: 'string', required: true, description: 'Concise task title.' },
122
+ description: { type: 'string', required: true, description: 'Complete task details and acceptance criteria.' },
123
+ blocked_by: { type: 'array', items: { type: 'string' }, description: 'Task ids that must complete first.' },
124
+ write_scopes: {
125
+ type: 'array',
126
+ items: { type: 'string' },
127
+ description: 'Advisory workspace-relative file or directory prefixes this task expects to modify.',
128
+ },
129
+ },
130
+ output: jsonOutput(TASK_VIEW_SCHEMA),
131
+ async execute(args, exec) {
132
+ const caller = callingAgent(exec.agent, 'team_task_create')
133
+ const task = await ctx.agentTeams.createTask(caller, {
134
+ subject: args.subject,
135
+ description: args.description,
136
+ ...args.blocked_by === undefined ? {} : { blockedBy: args.blocked_by.map(TeamTaskId) },
137
+ ...args.write_scopes === undefined ? {} : { writeScopes: args.write_scopes },
138
+ }, exec.signal)
139
+ return withOwnerName(task)
140
+ },
141
+ }), { when: ({ agent }) => enabled(agent) })
142
+
143
+ ctx.tools.register(defineTool({
144
+ name: 'team_task_list',
145
+ description: 'List shared tasks, including readiness, owner, revision, blockers, and write-scope warnings.',
146
+ parameters: {
147
+ status: {
148
+ type: 'string',
149
+ enum: ['pending', 'in_progress', 'completed'],
150
+ description: 'Optional exact status filter.',
151
+ },
152
+ owner: { type: 'string', description: 'Optional owner agent name filter; cannot be combined with unowned.' },
153
+ unowned: { type: 'boolean', description: 'Filter tasks by whether they have no owner; cannot be combined with owner.' },
154
+ ready: { type: 'boolean', description: 'Optional readiness filter.' },
155
+ cursor: { type: 'integer', description: 'Zero-based result offset. Defaults to 0.' },
156
+ limit: { type: 'integer', description: 'Number of rows, 1 through 100. Defaults to 50.' },
157
+ },
158
+ output: jsonOutput(TASK_LIST_VALUE_SCHEMA),
159
+ // Board reads project the Team Lead journal without appending to it.
160
+ isConcurrencySafe: () => true,
161
+ async execute(args, exec) {
162
+ const cursor = args.cursor ?? 0
163
+ const limit = args.limit ?? 50
164
+ if (!Number.isSafeInteger(cursor) || cursor < 0) throw new Error('cursor must be a non-negative safe integer')
165
+ if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100) throw new Error('limit must be an integer from 1 through 100')
166
+ const caller = callingAgent(exec.agent, 'team_task_list')
167
+ if (args.owner !== undefined && args.unowned !== undefined) throw new Error('owner and unowned filters cannot be combined')
168
+ const owner = args.owner === undefined
169
+ ? undefined
170
+ : await ctx.subagents.resolveName(caller, args.owner, exec.signal)
171
+ const filtered = ctx.agentTeams.listTasks(caller).filter(task =>
172
+ (args.status === undefined || task.status === args.status)
173
+ && (owner === undefined || task.ownerId === owner)
174
+ && (args.unowned === undefined || (task.ownerId === undefined) === args.unowned)
175
+ && (args.ready === undefined || task.ready === args.ready))
176
+ const page = filtered.slice(cursor, cursor + limit)
177
+ return {
178
+ tasks: page.map(withOwnerName),
179
+ ...(cursor + limit < filtered.length ? { nextCursor: cursor + limit } : {}),
180
+ }
181
+ },
182
+ }), { when: ({ agent }) => enabled(agent) })
183
+
184
+ ctx.tools.register(defineTool({
185
+ name: 'team_task_get',
186
+ description: 'Read the complete latest value of one shared task before changing or executing it.',
187
+ parameters: {
188
+ task_id: { type: 'string', required: true, description: 'Shared task id.' },
189
+ },
190
+ output: jsonOutput(TASK_VIEW_SCHEMA),
191
+ // Board reads project the Team Lead journal without appending to it.
192
+ isConcurrencySafe: () => true,
193
+ execute(args, exec) {
194
+ const caller = callingAgent(exec.agent, 'team_task_get')
195
+ const task = ctx.agentTeams.getTask(caller, TeamTaskId(args.task_id))
196
+ return Promise.resolve(withOwnerName(task))
197
+ },
198
+ }), { when: ({ agent }) => enabled(agent) })
199
+
200
+ ctx.tools.register(defineTool({
201
+ name: 'team_task_update',
202
+ description: 'Compare-and-set a shared task action using the latest revision from team_task_get or team_task_list.',
203
+ parameters: {
204
+ task_id: { type: 'string', required: true, description: 'Shared task id.' },
205
+ expected_revision: { type: 'integer', required: true, description: 'Current task revision used as the CAS precondition.' },
206
+ action: {
207
+ type: 'string',
208
+ required: true,
209
+ enum: ['claim', 'release', 'edit', 'set_dependencies', 'complete', 'reopen', 'reassign', 'delete'],
210
+ description: 'Task transition to apply.',
211
+ },
212
+ subject: { type: 'string', description: 'Replacement title for edit.' },
213
+ description: { type: 'string', description: 'Replacement details for edit.' },
214
+ blocked_by: { type: 'array', items: { type: 'string' }, description: 'Complete blocker list for set_dependencies.' },
215
+ write_scopes: { type: 'array', items: { type: 'string' }, description: 'Replacement advisory write scopes for edit.' },
216
+ owner: { type: 'string', description: 'Agent name of the root or any continuable descendant for root-only reassign; omit to unassign.' },
217
+ },
218
+ output: jsonOutput(TASK_VIEW_SCHEMA),
219
+ async execute(args, exec) {
220
+ const caller = callingAgent(exec.agent, 'team_task_update')
221
+ const taskId = TeamTaskId(args.task_id)
222
+ const task = await ctx.agentTeams.updateTask(caller, {
223
+ taskId,
224
+ expectedRevision: args.expected_revision,
225
+ action: args.action,
226
+ ...args.subject === undefined ? {} : { subject: args.subject },
227
+ ...args.description === undefined ? {} : { description: args.description },
228
+ ...args.blocked_by === undefined ? {} : { blockedBy: args.blocked_by.map(TeamTaskId) },
229
+ ...args.write_scopes === undefined ? {} : { writeScopes: args.write_scopes },
230
+ ...args.owner === undefined ? {} : { owner: await ctx.subagents.resolveName(caller, args.owner, exec.signal) },
231
+ }, exec.signal)
232
+ return withOwnerName(task)
233
+ },
234
+ }), { when: ({ agent }) => enabled(agent) })
235
+ }