@saturn-universe/runtime 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/run-loop.d.ts +2 -4
- package/dist/run-loop.js +5 -13
- package/dist/team-loop.d.ts +2 -4
- package/dist/team-loop.js +10 -15
- package/package.json +2 -2
package/dist/run-loop.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HostCommand, AgentSessionId, RunLoop, RunId, CommandId, AgentLoop, AgentInput, RuntimeJournal, RuntimeStateReader, ExecutionEnvironmentReader, RunCompletionPolicy, ToolExecutionReader, SurfaceReader, RunConfig, TeamConfig, TeamMemberActionResult, ToolContext, RunCheckpoint, WorkerSandboxProfile } from '@saturn-universe/core';
|
|
1
|
+
import type { HostCommand, AgentSessionId, RunLoop, RunId, CommandId, AgentLoop, AgentInput, RuntimeJournal, RuntimeStateReader, ExecutionEnvironmentReader, RunCompletionPolicy, ToolExecutionReader, SurfaceReader, RunConfig, TeamConfig, TeamMemberConfig, TeamMemberActionResult, ToolContext, RunCheckpoint, WorkerSandboxProfile } from '@saturn-universe/core';
|
|
2
2
|
import type { CommandDependencies } from './command-dependencies.js';
|
|
3
3
|
type MemberToolCaller = Pick<ToolContext, 'runId' | 'agentSessionId' | 'executionKey'>;
|
|
4
4
|
type PrepareRun = (signal: AbortSignal) => Promise<void>;
|
|
@@ -10,9 +10,7 @@ export declare function createRunLoop(d: CommandDependencies & {
|
|
|
10
10
|
agent: AgentLoop & Partial<Pick<ReturnType<typeof import('./agent-loop.js').createAgentLoop>, 'steer' | 'clearSteering'>>;
|
|
11
11
|
tools: ToolExecutionReader;
|
|
12
12
|
surface?: SurfaceReader;
|
|
13
|
-
freezeWorkerConfig?: (mainConfig: RunConfig, team: TeamConfig, id: AgentSessionId,
|
|
14
|
-
readonly depth?: number;
|
|
15
|
-
}) => Promise<RunConfig>;
|
|
13
|
+
freezeWorkerConfig?: (runId: RunId, mainConfig: RunConfig, team: TeamConfig, id: AgentSessionId, member: TeamMemberConfig) => Promise<RunConfig>;
|
|
16
14
|
verifyPluginVersions?: (runId: RunId) => Promise<void>;
|
|
17
15
|
completionPolicy?: RunCompletionPolicy;
|
|
18
16
|
createCheckpoint?: (input: AgentInput, prior?: RunCheckpoint) => Promise<RunCheckpoint | undefined>;
|
package/dist/run-loop.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BACKGROUND_CONTEXT_PREFIX,
|
|
1
|
+
import { BACKGROUND_CONTEXT_PREFIX, isTerminalRunStatus, maxRunTeamWorkers, RuntimeError, teamMemberIdPattern, teamRootId, validateStartedRun, validateTeamConfig, maxTeamDepth, isAsyncCoordinatorConfig, } from '@saturn-universe/core';
|
|
2
2
|
import { createCommandHandler } from './command-handler.js';
|
|
3
3
|
import { approvalResumeDeadline, driveTeam, extractSpawnTeamCall, workerStopReason, } from './team-loop.js';
|
|
4
4
|
import { driveSelectiveSearch, formatSearchResultMessage, hasSearchBudget, searchTokenUsage, } from './search-loop.js';
|
|
@@ -414,20 +414,12 @@ export function createRunLoop(d) {
|
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
|
-
const
|
|
418
|
-
const rawConcurrency = spawnReq.team.concurrency ??
|
|
419
|
-
(teamState ? teamState.concurrency : env.config.teamHint?.concurrency);
|
|
420
|
-
const mergedConcurrency = asyncCoordinator && teamState && rawConcurrency !== undefined
|
|
421
|
-
? Math.max(teamState.concurrency, rawConcurrency)
|
|
422
|
-
: rawConcurrency;
|
|
423
|
-
const clampedConcurrency = mergedConcurrency !== undefined && env.config.teamMaxConcurrency !== undefined
|
|
424
|
-
? Math.min(mergedConcurrency, env.config.teamMaxConcurrency)
|
|
425
|
-
: mergedConcurrency;
|
|
417
|
+
const concurrency = spawnReq.team.concurrency ?? env.config.teamHint?.concurrency;
|
|
426
418
|
const candidate = {
|
|
427
419
|
members: normalizedMembers,
|
|
428
|
-
...(
|
|
420
|
+
...(concurrency !== undefined ? { concurrency } : {}),
|
|
429
421
|
};
|
|
430
|
-
validateTeamConfig(candidate);
|
|
422
|
+
validateTeamConfig(candidate, { maxDepth: env.config.teamMaxDepth ?? maxTeamDepth });
|
|
431
423
|
const historicalIds = new Set(teamState?.tasks.map(({ memberId }) => memberId));
|
|
432
424
|
const duplicate = candidate.members.find(({ id }) => historicalIds.has(id));
|
|
433
425
|
if (duplicate)
|
|
@@ -469,7 +461,7 @@ export function createRunLoop(d) {
|
|
|
469
461
|
const workerAgentId = d.id();
|
|
470
462
|
const workerAgentSessionId = d.id();
|
|
471
463
|
const workerConfig = d.freezeWorkerConfig
|
|
472
|
-
? await d.freezeWorkerConfig(env.config, spawnedTeam, workerAgentSessionId,
|
|
464
|
+
? await d.freezeWorkerConfig(runId, env.config, spawnedTeam, workerAgentSessionId, member)
|
|
473
465
|
: { ...baseConfig, team: spawnedTeam, agentDepth: 1 };
|
|
474
466
|
spawnEvents.push(d.journal.event('agent.created', { kind: 'workspace', workspaceId: route.workspaceId }, {
|
|
475
467
|
agent: {
|
package/dist/team-loop.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentLoop, AgentResult, AgentSessionId, CommandId, ExecutionEnvironmentReader, RunConfig, RunId, RunScope, RunState, RuntimeJournal, RuntimeStateReader, SessionSurface, SurfaceReader, TeamConfig, Turn, TurnId, WorkerSandboxProfile } from '@saturn-universe/core';
|
|
1
|
+
import type { AgentLoop, AgentResult, AgentSessionId, CommandId, ExecutionEnvironmentReader, RunConfig, RunId, RunScope, RunState, RuntimeJournal, RuntimeStateReader, SessionSurface, SurfaceReader, TeamConfig, TeamMemberConfig, Turn, TurnId, WorkerSandboxProfile } from '@saturn-universe/core';
|
|
2
2
|
interface Dependencies {
|
|
3
3
|
agent: AgentLoop;
|
|
4
4
|
environment: ExecutionEnvironmentReader;
|
|
@@ -6,9 +6,7 @@ interface Dependencies {
|
|
|
6
6
|
journal: RuntimeJournal;
|
|
7
7
|
surface?: SurfaceReader;
|
|
8
8
|
resumeAutomatically(runId: RunState['runId'], commandId: CommandId): Promise<boolean>;
|
|
9
|
-
freezeWorkerConfig?: (mainConfig: RunConfig, team: TeamConfig, id: AgentSessionId,
|
|
10
|
-
readonly depth?: number;
|
|
11
|
-
}) => Promise<RunConfig>;
|
|
9
|
+
freezeWorkerConfig?: (runId: RunId, mainConfig: RunConfig, team: TeamConfig, id: AgentSessionId, member: TeamMemberConfig) => Promise<RunConfig>;
|
|
12
10
|
pendingSteers?: Map<CommandId, {
|
|
13
11
|
readonly commandId: CommandId;
|
|
14
12
|
readonly content: string;
|
package/dist/team-loop.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BACKGROUND_CONTEXT_PREFIX, coordinatorPollIntervalMs, earlierDeadline, isAsyncCoordinatorConfig, isTeamNotifyMessageId, isTerminalRunStatus, maxRunTeamWorkers, resolveEffectiveTeamConcurrency, RuntimeError, teamRootId, validateStartedRun, validateTeamConfig, } from '@saturn-universe/core';
|
|
1
|
+
import { BACKGROUND_CONTEXT_PREFIX, coordinatorPollIntervalMs, earlierDeadline, isAsyncCoordinatorConfig, isTeamNotifyMessageId, isTerminalRunStatus, maxRunTeamWorkers, maxTeamDepth, resolveEffectiveTeamConcurrency, RuntimeError, teamRootId, validateStartedRun, validateTeamConfig, } from '@saturn-universe/core';
|
|
2
2
|
export const workerStopReason = Symbol('Worker stopped by main');
|
|
3
3
|
export async function driveTeam(d, scope, parentSignal, wake) {
|
|
4
4
|
const { runId } = scope;
|
|
@@ -222,7 +222,7 @@ export async function driveTeam(d, scope, parentSignal, wake) {
|
|
|
222
222
|
const blocked = team.members.filter(({ status }) => status === 'paused');
|
|
223
223
|
const running = team.members.filter(({ status }) => status === 'running');
|
|
224
224
|
const occupied = new Set([...inFlight.keys(), ...running.map(({ id }) => id)].filter((id) => !asyncCoordinator || id !== teamRootId));
|
|
225
|
-
const effectiveConcurrency = resolveEffectiveTeamConcurrency(team.concurrency, mainEnv.config
|
|
225
|
+
const effectiveConcurrency = resolveEffectiveTeamConcurrency(team.concurrency, mainEnv.config);
|
|
226
226
|
let slots = Math.max(0, effectiveConcurrency - occupied.size);
|
|
227
227
|
const resumeEvents = [];
|
|
228
228
|
for (const member of blocked) {
|
|
@@ -310,18 +310,13 @@ export async function driveTeam(d, scope, parentSignal, wake) {
|
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
|
-
const rawConcurrency = spawnReq.team.concurrency ?? team.concurrency;
|
|
314
|
-
const mergedConcurrency = asyncCoordinator
|
|
315
|
-
? Math.max(team.concurrency, rawConcurrency)
|
|
316
|
-
: rawConcurrency;
|
|
317
|
-
const clampedConcurrency = mainEnv.config.teamMaxConcurrency !== undefined
|
|
318
|
-
? Math.min(mergedConcurrency, mainEnv.config.teamMaxConcurrency)
|
|
319
|
-
: mergedConcurrency;
|
|
320
313
|
const candidate = {
|
|
321
314
|
members: normalizedMembers,
|
|
322
|
-
concurrency
|
|
315
|
+
...(spawnReq.team.concurrency !== undefined
|
|
316
|
+
? { concurrency: spawnReq.team.concurrency }
|
|
317
|
+
: {}),
|
|
323
318
|
};
|
|
324
|
-
validateTeamConfig(candidate);
|
|
319
|
+
validateTeamConfig(candidate, { maxDepth: mainEnv.config.teamMaxDepth ?? maxTeamDepth });
|
|
325
320
|
const duplicate = candidate.members.find(({ id }) => historicalIds.has(id));
|
|
326
321
|
if (duplicate) {
|
|
327
322
|
throw new RuntimeError('INVALID_TEAM_CONFIG', `spawn_team reused member ID "${duplicate.id}"`);
|
|
@@ -363,7 +358,7 @@ export async function driveTeam(d, scope, parentSignal, wake) {
|
|
|
363
358
|
const workerAgentId = d.id();
|
|
364
359
|
const workerAgentSessionId = d.id();
|
|
365
360
|
const workerConfig = d.freezeWorkerConfig
|
|
366
|
-
? await d.freezeWorkerConfig(mainEnv.config, spawnedTeam, workerAgentSessionId,
|
|
361
|
+
? await d.freezeWorkerConfig(runId, mainEnv.config, spawnedTeam, workerAgentSessionId, member)
|
|
367
362
|
: { ...baseConfig, team: spawnedTeam, agentDepth: 1 };
|
|
368
363
|
spawnEvents.push(d.journal.event('agent.created', { kind: 'workspace', workspaceId: scope.workspaceId }, {
|
|
369
364
|
agent: {
|
|
@@ -480,9 +475,7 @@ export async function driveTeam(d, scope, parentSignal, wake) {
|
|
|
480
475
|
const childAgentId = d.id();
|
|
481
476
|
const childAgentSessionId = d.id();
|
|
482
477
|
const childConfig = d.freezeWorkerConfig
|
|
483
|
-
? await d.freezeWorkerConfig(memberEnv.config, subTeam, childAgentSessionId,
|
|
484
|
-
depth: depth + 1,
|
|
485
|
-
})
|
|
478
|
+
? await d.freezeWorkerConfig(runId, memberEnv.config, subTeam, childAgentSessionId, child)
|
|
486
479
|
: { ...baseWorkerConfig, team: subTeam, agentDepth: depth + 1 };
|
|
487
480
|
subEvents.push(d.journal.event('agent.created', { kind: 'workspace', workspaceId: scope.workspaceId }, {
|
|
488
481
|
agent: {
|
|
@@ -550,6 +543,7 @@ export async function driveTeam(d, scope, parentSignal, wake) {
|
|
|
550
543
|
})));
|
|
551
544
|
}
|
|
552
545
|
if (member.parent && ['completed', 'failed', 'interrupted'].includes(member.status)) {
|
|
546
|
+
await inFlight.get(member.id);
|
|
553
547
|
await finishWorker(member, member.status);
|
|
554
548
|
}
|
|
555
549
|
const failure = degraded.get(member.id);
|
|
@@ -646,6 +640,7 @@ export async function driveTeam(d, scope, parentSignal, wake) {
|
|
|
646
640
|
latestMain.status !== 'paused' &&
|
|
647
641
|
Date.now() - lastMainActivityAt >= pollIntervalMs;
|
|
648
642
|
const readyWorkers = latestTeam.members.filter((member) => (!asyncCoordinator || member.id !== teamRootId) &&
|
|
643
|
+
!inFlight.has(member.id) &&
|
|
649
644
|
['queued', 'waiting'].includes(member.status) &&
|
|
650
645
|
latestTeam.members
|
|
651
646
|
.filter((child) => child.parent === member.id)
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saturn-universe/runtime",
|
|
3
|
-
"version": "0.1.2-dev.
|
|
3
|
+
"version": "0.1.2-dev.8",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
8
8
|
],
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@saturn-universe/core": "0.1.2-dev.
|
|
10
|
+
"@saturn-universe/core": "0.1.2-dev.8"
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|