@saturn-universe/tools 0.1.2-dev.7 → 0.1.2-dev.8

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/dist/team.d.ts CHANGED
@@ -14,6 +14,7 @@ export interface CreateSpawnTeamToolOptions {
14
14
  readonly includeSandboxProfile?: boolean;
15
15
  readonly includeWorkSubpath?: boolean;
16
16
  readonly resolveCaller?: (ctx: ToolContext) => Promise<SpawnTeamCallerContext>;
17
+ readonly resolveModeRef?: (selector: string) => string | undefined;
17
18
  }
18
19
  export declare function createSpawnTeamTool(options?: CreateSpawnTeamToolOptions): ToolBinding;
19
20
  export interface TeamNotifyParentCallerContext {
package/dist/team.js CHANGED
@@ -1,4 +1,4 @@
1
- import { maxTeamMembers, RuntimeError, teamNotifyMessagePrefix, validateTeamConfig, teamMemberIdPattern, teamRootId, } from '@saturn-universe/core';
1
+ import { RuntimeError, resolveEffectiveTeamConcurrency, teamNotifyMessagePrefix, validateTeamConfig, teamMemberIdPattern, teamModeSelectorPattern, teamRootId, } from '@saturn-universe/core';
2
2
  export const spawnTeamToolName = 'spawn_team';
3
3
  export const teamNotifyParentToolName = 'team_notify_parent';
4
4
  const MAIN_PARENT_ALIASES = new Set(['coordinator', 'root', 'self']);
@@ -8,11 +8,12 @@ function isCtfModeRef(modeRef) {
8
8
  export function createSpawnTeamTool(options) {
9
9
  const includeSandboxProfile = options?.includeSandboxProfile === true;
10
10
  const includeWorkSubpath = options?.includeWorkSubpath === true;
11
+ const resolveModeRef = options?.resolveModeRef;
11
12
  const isV2 = includeSandboxProfile || includeWorkSubpath;
12
13
  return {
13
14
  definition: {
14
15
  name: spawnTeamToolName,
15
- version: isV2 ? '2' : '1',
16
+ version: resolveModeRef ? '3' : isV2 ? '2' : '1',
16
17
  description: isV2
17
18
  ? "Default to handling single-file, single-binary, simple linear verification, or short-command tasks directly as a single agent; do NOT spawn workers for simple static checks, a single debugging session, or short validation scripts. Call spawn_team only when the task genuinely contains 2+ time-consuming, independent modules or subsystems (e.g., separate services, frontend/backend splits, or parallel multi-module analysis in a large codebase) where you need parallel coverage while occupied elsewhere. Give each worker a strictly non-overlapping scope and concrete deliverable so teammates do not repeat identical baseline checks. members[].parent is optional and defaults to the current caller ('main' for the main session, or your own member ID for a Depth-1 worker; main-session aliases 'coordinator', 'root', and 'self' automatically normalize to 'main'). End your turn immediately with NO further tool calls after calling this tool so the runtime executes the team workers and returns their reports in the next turn."
18
19
  : 'Default to handling single-file, single-binary, simple linear verification, or short-command tasks directly as a single agent; do NOT spawn workers for simple static checks, a single debugging session, or short validation scripts. Call spawn_team only when the task genuinely contains 2+ time-consuming, independent modules or subsystems (e.g., separate services, frontend/backend splits, or parallel multi-module analysis in a large codebase) where you need parallel coverage while occupied elsewhere. Give each worker a strictly non-overlapping scope and concrete deliverable so teammates do not repeat identical baseline checks. End your turn immediately with NO further tool calls after calling this tool so the runtime executes the team workers and returns their reports in the next turn.',
@@ -38,6 +39,15 @@ export function createSpawnTeamTool(options) {
38
39
  }
39
40
  : { type: 'string', minLength: 1, maxLength: 64 },
40
41
  task: { type: 'string', minLength: 1, maxLength: isV2 ? 8000 : 4000 },
42
+ ...(resolveModeRef
43
+ ? {
44
+ modeRef: {
45
+ type: 'string',
46
+ pattern: teamModeSelectorPattern.source,
47
+ description: 'Optional Mode name or versioned reference. Defaults to the parent Mode.',
48
+ },
49
+ }
50
+ : {}),
41
51
  ...(includeSandboxProfile
42
52
  ? { sandboxProfile: { type: 'string', enum: ['default', 'readonly', 'build'] } }
43
53
  : {}),
@@ -95,7 +105,8 @@ export function createSpawnTeamTool(options) {
95
105
  const declaredIds = new Set(parsed.members
96
106
  .map((member) => (typeof member?.id === 'string' ? member.id.trim() : ''))
97
107
  .filter(Boolean));
98
- const members = parsed.members.map((member) => {
108
+ const members = [];
109
+ for (const member of parsed.members) {
99
110
  const rawParent = typeof member.parent === 'string' ? member.parent.trim() : '';
100
111
  let resolvedParent = rawParent || caller.memberId;
101
112
  if (caller.memberId === 'main' &&
@@ -103,14 +114,20 @@ export function createSpawnTeamTool(options) {
103
114
  !declaredIds.has(resolvedParent)) {
104
115
  resolvedParent = 'main';
105
116
  }
106
- return {
117
+ const modeRef = typeof member.modeRef === 'string' && teamModeSelectorPattern.test(member.modeRef)
118
+ ? resolveModeRef?.(member.modeRef)
119
+ : undefined;
120
+ if (member.modeRef !== undefined && !modeRef)
121
+ return invalidTeam(`Invalid or unknown modeRef for team member ${member.id}: ${member.modeRef}`);
122
+ members.push({
107
123
  id: member.id,
108
124
  parent: resolvedParent,
109
125
  task: member.task,
110
126
  ...(member.sandboxProfile !== undefined ? { sandboxProfile: member.sandboxProfile } : {}),
111
127
  ...(member.workSubpath !== undefined ? { workSubpath: member.workSubpath } : {}),
112
- };
113
- });
128
+ ...(modeRef !== undefined ? { modeRef } : {}),
129
+ });
130
+ }
114
131
  if (includeWorkSubpath && isCtfModeRef(caller.modeRef) && caller.depth === 0) {
115
132
  for (const member of members) {
116
133
  if (member.parent !== 'main')
@@ -125,24 +142,25 @@ export function createSpawnTeamTool(options) {
125
142
  const activeDepth1 = caller.activeDepth1Count ?? 0;
126
143
  const availableSlots = Math.max(0, caller.maxActiveDepth1 - activeDepth1);
127
144
  if (requestedDepth1 > availableSlots) {
128
- return invalidTeam(`Cannot spawn ${requestedDepth1} Depth-1 worker(s): max_active_challenges is ${caller.maxActiveDepth1}, currently ${activeDepth1} active Depth-1 worker(s) (${availableSlots} slot(s) available). Spawn at most ${availableSlots} Depth-1 worker(s) now and backfill incrementally as active workers complete.`);
145
+ const limit = isCtfModeRef(caller.modeRef) ? 'max_active_challenges' : 'max_active_depth1';
146
+ return invalidTeam(`Cannot spawn ${requestedDepth1} Depth-1 worker(s): ${limit} is ${caller.maxActiveDepth1}, currently ${activeDepth1} active Depth-1 worker(s) (${availableSlots} slot(s) available). Spawn at most ${availableSlots} Depth-1 worker(s) now and backfill incrementally as active workers complete.`);
129
147
  }
130
148
  }
131
- const concurrencyCap = caller.maxConcurrentWorkers ?? maxTeamMembers;
132
- const effectiveConcurrency = parsed.concurrency !== undefined
133
- ? Math.min(parsed.concurrency, concurrencyCap)
134
- : caller.depth === 0 && caller.maxActiveDepth1 !== undefined
135
- ? Math.max(1, Math.min(caller.maxActiveDepth1, concurrencyCap))
136
- : undefined;
149
+ const concurrency = parsed.concurrency === undefined || caller.maxConcurrentWorkers === undefined
150
+ ? parsed.concurrency
151
+ : resolveEffectiveTeamConcurrency(parsed.concurrency, {
152
+ teamMaxConcurrency: caller.maxConcurrentWorkers,
153
+ });
137
154
  const team = {
138
155
  members,
139
- ...(effectiveConcurrency !== undefined ? { concurrency: effectiveConcurrency } : {}),
156
+ ...(concurrency !== undefined ? { concurrency } : {}),
140
157
  ...(caller.memberId !== 'main' ? { rootId: caller.memberId } : {}),
141
158
  };
142
159
  try {
143
- validateTeamConfig(team, caller.memberId === 'main'
144
- ? undefined
145
- : { rootId: caller.memberId, maxDepth: Math.max(1, caller.maxDepth - caller.depth) });
160
+ validateTeamConfig(team, {
161
+ rootId: caller.memberId,
162
+ maxDepth: caller.maxDepth - caller.depth,
163
+ });
146
164
  }
147
165
  catch (err) {
148
166
  if (err instanceof RuntimeError) {
@@ -158,7 +176,7 @@ export function createSpawnTeamTool(options) {
158
176
  }
159
177
  const teamData = {
160
178
  members: members.map((member) => ({ ...member })),
161
- ...(effectiveConcurrency !== undefined ? { concurrency: effectiveConcurrency } : {}),
179
+ ...(concurrency !== undefined ? { concurrency } : {}),
162
180
  ...(caller.memberId !== 'main' ? { rootId: caller.memberId } : {}),
163
181
  };
164
182
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saturn-universe/tools",
3
- "version": "0.1.2-dev.7",
3
+ "version": "0.1.2-dev.8",
4
4
  "license": "AGPL-3.0-only",
5
5
  "type": "module",
6
6
  "files": [
@@ -13,7 +13,7 @@
13
13
  }
14
14
  },
15
15
  "dependencies": {
16
- "@saturn-universe/core": "0.1.2-dev.7",
16
+ "@saturn-universe/core": "0.1.2-dev.8",
17
17
  "zod": "4.6.0"
18
18
  }
19
19
  }