@saturn-universe/tools 0.1.2-dev.1 → 0.1.2-dev.10

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.
@@ -1,5 +1,6 @@
1
1
  import type { AgentSessionId, ArtifactReader, LoggerPort, ToolExecutor, ToolExecutionReader, ToolPermissionPolicy, ExecutionEnvironmentReader, ExecutionEnvironment, RuntimeStateReader, RuntimeJournal, RuntimeClock, Hash, ToolCallId, ToolApprovalDecision, ReconciliationDecision, CommandId, RunId, RunConfig, RuntimeHooks } from '@saturn-universe/core';
2
2
  import type { Registry } from './registry.js';
3
+ export declare const maxPluginTimeoutMs = 7200000;
3
4
  export interface ExecutorDependencies {
4
5
  logger: LoggerPort;
5
6
  registry: Registry;
package/dist/executor.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { canonicalJson, earlierDeadline, isLimited, reportDiagnostic, resolveSubagentWallTimeMs, RuntimeError, tightenToolPermission, validateArtifactRef, validateStartedRun, } from '@saturn-universe/core';
2
2
  import { createHash } from 'node:crypto';
3
3
  import { z } from 'zod';
4
+ import { isTeamMemberControlTool } from './team.js';
4
5
  import { outsideWorkspacePrefix, processTimeoutMs } from './workspace.js';
6
+ export const maxPluginTimeoutMs = 7_200_000;
5
7
  const artifact = z.unknown().refine((value) => value !== undefined, 'artifact is required');
6
8
  const toolContent = z.array(z.discriminatedUnion('type', [
7
9
  z.strictObject({ type: z.literal('text'), text: z.string() }),
@@ -295,8 +297,11 @@ export function createToolExecutor(d) {
295
297
  const workers = Array.from({ length: Math.min(env.config.limits.maxParallelTools, pending.length) }, async () => {
296
298
  while (cursor < pending.length && !blocked) {
297
299
  const call = pending[cursor++];
298
- const serialCall = call.definition.concurrency === 'serial_per_run';
299
- if (env.config.team) {
300
+ const definition = call.definition;
301
+ const serialCall = definition.concurrency === 'serial_per_run';
302
+ // Member controls must remain available while workers hold the team tool permits.
303
+ const coordinatorControl = definition.source.kind === 'builtin' && isTeamMemberControlTool(definition.name);
304
+ if (env.config.team && !coordinatorControl) {
300
305
  let permits = teamPermits.get(permitKey);
301
306
  if (!permits) {
302
307
  permits = new ToolPermits(env.config.limits.maxParallelTools);
@@ -681,6 +686,9 @@ async function invokeObservation(d, env, input, call, value, deadlineAt, handler
681
686
  const shellLimit = typeof requested === 'number' ? Math.max(requested, processTimeoutMs) : processTimeoutMs;
682
687
  invocationLimit = Math.min(shellLimit, shellTimeoutMs ?? toolTimeoutMs);
683
688
  }
689
+ else if (definition.source.kind === 'plugin') {
690
+ invocationLimit = maxPluginTimeoutMs;
691
+ }
684
692
  const timeout = Math.max(1, Math.min(definition.timeoutMs, invocationLimit, remaining));
685
693
  const timeoutController = new AbortController();
686
694
  const timer = setTimeout(() => timeoutController.abort(new DOMException('Tool invocation timed out', 'TimeoutError')), timeout);
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  export { Registry } from './registry.js';
2
- export { createToolExecutor } from './executor.js';
2
+ export { createToolExecutor, maxPluginTimeoutMs } from './executor.js';
3
3
  export type { Executor, ExecutorDependencies } from './executor.js';
4
4
  export { createCounterTool } from './counter.js';
5
5
  export { createPlannerTool, plannerToolName } from './planner.js';
6
6
  export { createExploreHypothesesTool, exploreHypothesesToolName } from './search.js';
7
7
  export type { ExploreHypothesisInput } from './search.js';
8
- export { createSpawnTeamTool, createTeamNotifyParentTool, spawnTeamToolName, teamNotifyParentToolName, } from './team.js';
9
- export type { CreateSpawnTeamToolOptions, CreateTeamNotifyParentToolOptions, SpawnTeamCallerContext, TeamNotifyParentCallerContext, TeamNotifyParentDelivery, } from './team.js';
8
+ export { createSpawnTeamTool, createTeamNotifyParentTool, createTeamSteerMemberTool, createTeamStopMemberTool, isTeamMemberControlTool, teamStopMemberToolName, teamSteerMemberToolName, spawnTeamToolName, teamNotifyParentToolName, } from './team.js';
9
+ export type { CreateSpawnTeamToolOptions, CreateTeamNotifyParentToolOptions, SpawnTeamCallerContext, TeamNotifyParentCallerContext, TeamNotifyParentDelivery, TeamMemberAction, } from './team.js';
10
10
  export { createTodoWriteTool, todoWriteToolName } from './todo.js';
11
11
  export { createDataReviewTool, dataReviewToolName, dataReviewToolSet } from './data-review.js';
12
12
  export type { TodoItem, TodoStatus } from '@saturn-universe/core';
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  export { Registry } from './registry.js';
2
- export { createToolExecutor } from './executor.js';
2
+ export { createToolExecutor, maxPluginTimeoutMs } from './executor.js';
3
3
  export { createCounterTool } from './counter.js';
4
4
  export { createPlannerTool, plannerToolName } from './planner.js';
5
5
  export { createExploreHypothesesTool, exploreHypothesesToolName } from './search.js';
6
- export { createSpawnTeamTool, createTeamNotifyParentTool, spawnTeamToolName, teamNotifyParentToolName, } from './team.js';
6
+ export { createSpawnTeamTool, createTeamNotifyParentTool, createTeamSteerMemberTool, createTeamStopMemberTool, isTeamMemberControlTool, teamStopMemberToolName, teamSteerMemberToolName, spawnTeamToolName, teamNotifyParentToolName, } from './team.js';
7
7
  export { createTodoWriteTool, todoWriteToolName } from './todo.js';
8
8
  export { createDataReviewTool, dataReviewToolName, dataReviewToolSet } from './data-review.js';
9
9
  export { createWorkspaceTools, containerReadonlyPrefix, maxShellTimeoutMs, outsideWorkspacePrefix, readonlyCommandAllowlist, } from './workspace.js';
package/dist/team.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { RunId, ToolBinding, ToolContext } from '@saturn-universe/core';
1
+ import type { RunId, TeamMemberActionResult, ToolBinding, ToolContext } from '@saturn-universe/core';
2
2
  export declare const spawnTeamToolName = "spawn_team";
3
3
  export declare const teamNotifyParentToolName = "team_notify_parent";
4
4
  export interface SpawnTeamCallerContext {
@@ -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 {
@@ -34,3 +35,9 @@ export interface CreateTeamNotifyParentToolOptions {
34
35
  readonly notifyParent?: (delivery: TeamNotifyParentDelivery) => Promise<void>;
35
36
  }
36
37
  export declare function createTeamNotifyParentTool(options?: CreateTeamNotifyParentToolOptions): ToolBinding;
38
+ export declare const teamSteerMemberToolName = "team_steer_member";
39
+ export declare const teamStopMemberToolName = "team_stop_member";
40
+ export declare function isTeamMemberControlTool(name: string): boolean;
41
+ export type TeamMemberAction = (ctx: ToolContext, memberId: string, text: string) => Promise<TeamMemberActionResult>;
42
+ export declare function createTeamSteerMemberTool(steer: TeamMemberAction): ToolBinding;
43
+ export declare function createTeamStopMemberTool(stop: TeamMemberAction): ToolBinding;
package/dist/team.js CHANGED
@@ -1,4 +1,4 @@
1
- import { maxTeamMembers, RuntimeError, teamNotifyMessagePrefix, validateTeamConfig, } 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 {
@@ -273,6 +291,64 @@ export function createTeamNotifyParentTool(options) {
273
291
  },
274
292
  };
275
293
  }
294
+ export const teamSteerMemberToolName = 'team_steer_member';
295
+ export const teamStopMemberToolName = 'team_stop_member';
296
+ export function isTeamMemberControlTool(name) {
297
+ return name === teamSteerMemberToolName || name === teamStopMemberToolName;
298
+ }
299
+ export function createTeamSteerMemberTool(steer) {
300
+ return createTeamMemberTool(teamSteerMemberToolName, 'Send a corrective instruction to one active team worker. Interrupts inference or waits for the current tool batch to finish.', 'message', steer);
301
+ }
302
+ export function createTeamStopMemberTool(stop) {
303
+ return createTeamMemberTool(teamStopMemberToolName, 'Stop one active team worker. Provide the reason. The other workers continue, and you receive a report after cleanup.', 'reason', stop);
304
+ }
305
+ function createTeamMemberTool(name, description, field, action) {
306
+ return {
307
+ definition: {
308
+ name,
309
+ version: '1',
310
+ description,
311
+ inputSchema: {
312
+ type: 'object',
313
+ properties: {
314
+ memberId: { type: 'string', minLength: 1, maxLength: 64 },
315
+ [field]: { type: 'string', minLength: 1, maxLength: 4000 },
316
+ },
317
+ required: ['memberId', field],
318
+ additionalProperties: false,
319
+ },
320
+ source: { kind: 'builtin' },
321
+ effects: 'read',
322
+ supportsIdempotencyKey: false,
323
+ supportsReconcile: false,
324
+ concurrency: 'parallel',
325
+ timeoutMs: 10000,
326
+ },
327
+ handler: {
328
+ async invoke(input, ctx) {
329
+ const parsed = input;
330
+ const memberId = parsed?.memberId;
331
+ if (typeof memberId !== 'string' || !teamMemberIdPattern.test(memberId) || memberId === teamRootId)
332
+ return notifyError('INVALID_INPUT', 'memberId must identify a worker in the current Run');
333
+ const value = parsed?.[field];
334
+ const text = typeof value === 'string' ? value.trim() : '';
335
+ if (!text || text.length > 4000)
336
+ return notifyError('INVALID_INPUT', `${field} must be a non-empty string up to 4000 characters`);
337
+ const result = await action(ctx, memberId, text);
338
+ if (result.status === 'forbidden' || result.status === 'invalid_target')
339
+ return notifyError(result.status.toUpperCase(), result.message);
340
+ return {
341
+ effect: result.status === 'accepted' ? 'applied' : 'none',
342
+ outcome: {
343
+ status: 'success',
344
+ content: [{ type: 'text', text: result.message }],
345
+ data: { kind: name, memberId, ...result },
346
+ },
347
+ };
348
+ },
349
+ },
350
+ };
351
+ }
276
352
  function notifyError(code, message) {
277
353
  return {
278
354
  effect: 'none',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saturn-universe/tools",
3
- "version": "0.1.2-dev.1",
3
+ "version": "0.1.2-dev.10",
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.1",
16
+ "@saturn-universe/core": "0.1.2-dev.10",
17
17
  "zod": "4.6.0"
18
18
  }
19
19
  }