@saturn-universe/runtime-host 0.1.2-dev.6 → 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/builtin-plugins/saturn-plugin-ctf/index.mjs +2 -2
- package/dist/builtin-plugins/saturn-plugin-ctf/package.json +1 -1
- package/dist/command-dispatch.js +1 -0
- package/dist/composition.d.ts +20 -56
- package/dist/composition.js +232 -75
- package/dist/context-extensions.d.ts +10 -0
- package/dist/context-extensions.js +5 -0
- package/dist/cordis/plugin-lifecycle.d.ts +1 -0
- package/dist/cordis/plugin-lifecycle.js +3 -0
- package/dist/cordis/sandbox-plugin.d.ts +1 -0
- package/dist/cordis/sandbox-plugin.js +1 -0
- package/dist/cordis/tools/builtin-agent-tools-plugin.d.ts +1 -1
- package/dist/cordis/tools/builtin-agent-tools-plugin.js +15 -1
- package/dist/cordis/tools/index.d.ts +3 -1
- package/dist/cordis/tools/index.js +3 -3
- package/dist/cordis/tools/process-manager-plugin.d.ts +1 -1
- package/dist/cordis/tools/process-manager-plugin.js +8 -8
- package/dist/cordis/tools/tools-core-plugin.js +13 -0
- package/dist/index.js +1 -1
- package/dist/mode-configuration.d.ts +5 -0
- package/dist/modes.js +25 -9
- package/dist/provider-catalog.d.ts +5 -0
- package/dist/sandbox-manager.d.ts +2 -0
- package/dist/sandbox-manager.js +18 -12
- package/dist/session-mode-runtime.d.ts +99 -0
- package/dist/session-mode-runtime.js +306 -0
- package/package.json +9 -9
|
@@ -337,6 +337,11 @@ export declare const modeDefinitionSchema: z.ZodObject<{
|
|
|
337
337
|
}, z.core.$strict>>;
|
|
338
338
|
team: z.ZodOptional<z.ZodObject<{
|
|
339
339
|
max_depth: z.ZodOptional<z.ZodNumber>;
|
|
340
|
+
default_concurrency: z.ZodOptional<z.ZodNumber>;
|
|
341
|
+
default_preset: z.ZodOptional<z.ZodString>;
|
|
342
|
+
max_concurrency: z.ZodOptional<z.ZodNumber>;
|
|
343
|
+
max_active_depth1: z.ZodOptional<z.ZodNumber>;
|
|
344
|
+
worker_soft_checkpoint_ms: z.ZodOptional<z.ZodNumber>;
|
|
340
345
|
async_coordinator: z.ZodOptional<z.ZodBoolean>;
|
|
341
346
|
coordinator_poll_interval_ms: z.ZodOptional<z.ZodNumber>;
|
|
342
347
|
}, z.core.$strict>>;
|
|
@@ -650,6 +655,11 @@ export declare const modeDefinitionsSchema: z.ZodRecord<z.ZodString, z.ZodObject
|
|
|
650
655
|
}, z.core.$strict>>;
|
|
651
656
|
team: z.ZodOptional<z.ZodObject<{
|
|
652
657
|
max_depth: z.ZodOptional<z.ZodNumber>;
|
|
658
|
+
default_concurrency: z.ZodOptional<z.ZodNumber>;
|
|
659
|
+
default_preset: z.ZodOptional<z.ZodString>;
|
|
660
|
+
max_concurrency: z.ZodOptional<z.ZodNumber>;
|
|
661
|
+
max_active_depth1: z.ZodOptional<z.ZodNumber>;
|
|
662
|
+
worker_soft_checkpoint_ms: z.ZodOptional<z.ZodNumber>;
|
|
653
663
|
async_coordinator: z.ZodOptional<z.ZodBoolean>;
|
|
654
664
|
coordinator_poll_interval_ms: z.ZodOptional<z.ZodNumber>;
|
|
655
665
|
}, z.core.$strict>>;
|
|
@@ -132,6 +132,11 @@ export const modeSandboxSchema = z.strictObject({
|
|
|
132
132
|
});
|
|
133
133
|
const modeTeamSchema = z.strictObject({
|
|
134
134
|
max_depth: z.number().int().min(1).max(2).optional(),
|
|
135
|
+
default_concurrency: z.number().int().positive().optional(),
|
|
136
|
+
default_preset: identifier.optional(),
|
|
137
|
+
max_concurrency: z.number().int().positive().optional(),
|
|
138
|
+
max_active_depth1: z.number().int().positive().optional(),
|
|
139
|
+
worker_soft_checkpoint_ms: z.number().int().nonnegative().optional(),
|
|
135
140
|
async_coordinator: z.boolean().optional(),
|
|
136
141
|
coordinator_poll_interval_ms: z.number().int().min(0).optional(),
|
|
137
142
|
});
|
|
@@ -25,6 +25,7 @@ export declare class PluginLifecycle {
|
|
|
25
25
|
kind: "saturn-registrar" | "cordis";
|
|
26
26
|
status: "active" | "draining";
|
|
27
27
|
}[];
|
|
28
|
+
activePlugins(): LoadedHostPlugin[];
|
|
28
29
|
withAdmission<T>(work: () => Promise<T>): Promise<T>;
|
|
29
30
|
trackRun(runId: RunId): () => void;
|
|
30
31
|
replace(load: (active: ReadonlyMap<string, LoadedHostPlugin>) => Promise<readonly LoadedHostPlugin[]>, pluginId?: string): Promise<{
|
|
@@ -51,6 +51,9 @@ export class PluginLifecycle {
|
|
|
51
51
|
...[...this.draining].map((generation) => summary(generation, 'draining')),
|
|
52
52
|
].sort((a, b) => a.id.localeCompare(b.id));
|
|
53
53
|
}
|
|
54
|
+
activePlugins() {
|
|
55
|
+
return [...this.active.values()].map(({ plugin }) => plugin);
|
|
56
|
+
}
|
|
54
57
|
withAdmission(work) {
|
|
55
58
|
return this.enqueue(work);
|
|
56
59
|
}
|
|
@@ -10,6 +10,7 @@ declare module '@deepseek-ai/cordis' {
|
|
|
10
10
|
export interface SandboxPluginOptions {
|
|
11
11
|
readonly allowUnsafeFallback?: boolean;
|
|
12
12
|
readonly runner?: ContainerRunner;
|
|
13
|
+
readonly cleanupOrphans?: (cleanup: () => Promise<void>) => Promise<void>;
|
|
13
14
|
}
|
|
14
15
|
export declare function createSandboxPlugin(root: string, activeMode: ModeDefinition, options?: SandboxPluginOptions): {
|
|
15
16
|
name: string;
|
|
@@ -10,6 +10,7 @@ export function createSandboxPlugin(root, activeMode, options = {}) {
|
|
|
10
10
|
logger: ctx.saturnPluginHost.logger,
|
|
11
11
|
...(options.allowUnsafeFallback ? { allowUnsafeFallback: true } : {}),
|
|
12
12
|
...(options.runner ? { runner: options.runner } : {}),
|
|
13
|
+
...(options.cleanupOrphans ? { cleanupOrphans: options.cleanupOrphans } : {}),
|
|
13
14
|
});
|
|
14
15
|
await manager.activate(startupSignal);
|
|
15
16
|
ctx.effect(() => async () => {
|
|
@@ -4,7 +4,7 @@ import { type TeamMemberAction, type TeamNotifyParentDelivery } from '@saturn-un
|
|
|
4
4
|
import type { ToolConfiguration } from './tools-core-plugin.js';
|
|
5
5
|
import { type SkillRegistryService } from '../../skills-runtime.js';
|
|
6
6
|
export declare function teamHintSections(hint: RunConfig['teamHint'], tools: readonly ToolSpec[]): PromptSection[];
|
|
7
|
-
export declare function createBuiltinAgentToolsPlugin(root: string, settings: ToolConfiguration['counter'], resultReader?: ToolBinding, previousDataReview?: (runId: RunId) => Promise<boolean>, suppressedGuidanceRoles?: ReadonlySet<'main' | 'worker'>, skillService?: SkillRegistryService, notifyParent?: (delivery: TeamNotifyParentDelivery) => Promise<void>, steerMember?: TeamMemberAction, stopMember?: TeamMemberAction): {
|
|
7
|
+
export declare function createBuiltinAgentToolsPlugin(root: string, settings: ToolConfiguration['counter'], resultReader?: ToolBinding, previousDataReview?: (runId: RunId) => Promise<boolean>, suppressedGuidanceRoles?: ReadonlySet<'main' | 'worker'>, skillService?: SkillRegistryService, notifyParent?: (delivery: TeamNotifyParentDelivery) => Promise<void>, steerMember?: TeamMemberAction, stopMember?: TeamMemberAction, resolveWorkerModeRef?: (selector: string) => string | undefined): {
|
|
8
8
|
name: string;
|
|
9
9
|
inject: string[];
|
|
10
10
|
apply(ctx: Context, startupSignal: AbortSignal): Promise<void>;
|
|
@@ -19,7 +19,7 @@ export function teamHintSections(hint, tools) {
|
|
|
19
19
|
},
|
|
20
20
|
];
|
|
21
21
|
}
|
|
22
|
-
export function createBuiltinAgentToolsPlugin(root, settings, resultReader, previousDataReview, suppressedGuidanceRoles, skillService, notifyParent, steerMember, stopMember) {
|
|
22
|
+
export function createBuiltinAgentToolsPlugin(root, settings, resultReader, previousDataReview, suppressedGuidanceRoles, skillService, notifyParent, steerMember, stopMember, resolveWorkerModeRef) {
|
|
23
23
|
return {
|
|
24
24
|
name: 'builtin-agent-tools',
|
|
25
25
|
inject: ['saturnTools'],
|
|
@@ -90,6 +90,20 @@ export function createBuiltinAgentToolsPlugin(root, settings, resultReader, prev
|
|
|
90
90
|
versions: sets.spawnTeamV2Versions,
|
|
91
91
|
priority: 0,
|
|
92
92
|
},
|
|
93
|
+
...(resolveWorkerModeRef
|
|
94
|
+
? [
|
|
95
|
+
{
|
|
96
|
+
binding: createSpawnTeamTool({
|
|
97
|
+
includeSandboxProfile: true,
|
|
98
|
+
includeWorkSubpath: true,
|
|
99
|
+
resolveModeRef: resolveWorkerModeRef,
|
|
100
|
+
...(resolveCaller ? { resolveCaller } : {}),
|
|
101
|
+
}),
|
|
102
|
+
versions: [],
|
|
103
|
+
priority: 0,
|
|
104
|
+
},
|
|
105
|
+
]
|
|
106
|
+
: []),
|
|
93
107
|
{
|
|
94
108
|
binding: createTodoWriteTool(),
|
|
95
109
|
versions: [...sets.defaultVersions, dataReviewToolSet],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RunId, ToolBinding } from '@saturn-universe/core';
|
|
2
|
-
import type { ProcessManagerOptions, TeamMemberAction, TeamNotifyParentDelivery } from '@saturn-universe/tools';
|
|
2
|
+
import type { ProcessManager, ProcessManagerOptions, TeamMemberAction, TeamNotifyParentDelivery } from '@saturn-universe/tools';
|
|
3
3
|
import type { SkillRegistryService } from '../../skills-runtime.js';
|
|
4
4
|
import type { RequiredHostPlugin } from '../required-host-plugin.js';
|
|
5
5
|
import type { ToolConfiguration } from './tools-core-plugin.js';
|
|
@@ -9,11 +9,13 @@ export interface HostToolOptions {
|
|
|
9
9
|
hash: (value: unknown) => string;
|
|
10
10
|
resultReader?: ToolBinding;
|
|
11
11
|
processManager?: Omit<ProcessManagerOptions, 'directory'>;
|
|
12
|
+
sharedProcessManager?: ProcessManager;
|
|
12
13
|
previousDataReview?: (runId: RunId) => Promise<boolean>;
|
|
13
14
|
suppressedGuidanceRoles?: ReadonlySet<'main' | 'worker'>;
|
|
14
15
|
skillService?: SkillRegistryService;
|
|
15
16
|
steerMember?: TeamMemberAction;
|
|
16
17
|
stopMember?: TeamMemberAction;
|
|
17
18
|
notifyParent?: (delivery: TeamNotifyParentDelivery) => Promise<void>;
|
|
19
|
+
resolveWorkerModeRef?: (selector: string) => string | undefined;
|
|
18
20
|
}
|
|
19
21
|
export declare function createToolPlugins(root: string, options: HostToolOptions, startupDependencies?: string[], withContext?: boolean): RequiredHostPlugin[];
|
|
@@ -4,7 +4,7 @@ import { createProcessManagerPlugin } from './process-manager-plugin.js';
|
|
|
4
4
|
import { createToolsCorePlugin } from './tools-core-plugin.js';
|
|
5
5
|
import { createWorkspaceToolsPlugin } from './workspace-tools-plugin.js';
|
|
6
6
|
export function createToolPlugins(root, options, startupDependencies = [], withContext = false) {
|
|
7
|
-
const { config, trustedConfig, hash, resultReader, processManager, previousDataReview, suppressedGuidanceRoles, skillService, notifyParent, steerMember, stopMember, } = options;
|
|
7
|
+
const { config, trustedConfig, hash, resultReader, processManager, sharedProcessManager, previousDataReview, suppressedGuidanceRoles, skillService, notifyParent, steerMember, stopMember, resolveWorkerModeRef, } = options;
|
|
8
8
|
const effectiveWorkspaceTools = Boolean(config.workspaceTools);
|
|
9
9
|
const effectiveProcessManager = config.processManager ?? effectiveWorkspaceTools;
|
|
10
10
|
const effectiveBuiltinAgentTools = config.builtinAgentTools !== false;
|
|
@@ -16,7 +16,7 @@ export function createToolPlugins(root, options, startupDependencies = [], withC
|
|
|
16
16
|
...(effectiveProcessManager
|
|
17
17
|
? [
|
|
18
18
|
guidanceOwner({
|
|
19
|
-
...createProcessManagerPlugin(root, processManager ?? {}),
|
|
19
|
+
...createProcessManagerPlugin(root, processManager ?? {}, sharedProcessManager),
|
|
20
20
|
inject: [...startupDependencies, 'saturnTools'],
|
|
21
21
|
}),
|
|
22
22
|
]
|
|
@@ -30,7 +30,7 @@ export function createToolPlugins(root, options, startupDependencies = [], withC
|
|
|
30
30
|
: []),
|
|
31
31
|
...(effectiveBuiltinAgentTools
|
|
32
32
|
? [
|
|
33
|
-
guidanceOwner(createBuiltinAgentToolsPlugin(root, config.counter, resultReader, previousDataReview, suppressedGuidanceRoles, skillService, notifyParent, steerMember, stopMember)),
|
|
33
|
+
guidanceOwner(createBuiltinAgentToolsPlugin(root, config.counter, resultReader, previousDataReview, suppressedGuidanceRoles, skillService, notifyParent, steerMember, stopMember, resolveWorkerModeRef)),
|
|
34
34
|
]
|
|
35
35
|
: []),
|
|
36
36
|
...(Object.keys(config.mcpServers ?? {}).length
|
|
@@ -5,7 +5,7 @@ declare module '@deepseek-ai/cordis' {
|
|
|
5
5
|
saturnProcessManager?: ProcessManager;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
export declare function createProcessManagerPlugin(root: string, options: Omit<ProcessManagerOptions, 'directory'
|
|
8
|
+
export declare function createProcessManagerPlugin(root: string, options: Omit<ProcessManagerOptions, 'directory'>, shared?: ProcessManager): {
|
|
9
9
|
name: string;
|
|
10
10
|
apply(ctx: Context): void;
|
|
11
11
|
};
|
|
@@ -21,17 +21,17 @@ function processGuidance(visible) {
|
|
|
21
21
|
'A timeout or unknown result does not prove the process stopped. Check any existing handle and actual side effects before retrying. Never launch a blind duplicate.',
|
|
22
22
|
].join('\n');
|
|
23
23
|
}
|
|
24
|
-
export function createProcessManagerPlugin(root, options) {
|
|
24
|
+
export function createProcessManagerPlugin(root, options, shared) {
|
|
25
25
|
return {
|
|
26
26
|
name: 'process-manager',
|
|
27
27
|
apply(ctx) {
|
|
28
|
-
const manager =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
const manager = shared ??
|
|
29
|
+
createProcessManager({
|
|
30
|
+
...options,
|
|
31
|
+
directory: path.join(root, '.saturn', 'processes'),
|
|
32
|
+
});
|
|
33
|
+
if (!shared)
|
|
34
|
+
ctx.effect(() => () => manager.close());
|
|
35
35
|
ctx.provide('saturnProcessManager', manager);
|
|
36
36
|
registerToolGuidance(ctx, 'process-tool-guidance', -20, processGuidance);
|
|
37
37
|
},
|
|
@@ -343,6 +343,19 @@ function createToolsService(config, trustedConfig, hash) {
|
|
|
343
343
|
const overrides = new Map(scoped
|
|
344
344
|
.resolve(target, ({ scopeKey, toolSets }) => scopeKey !== undefined && toolSets.includes(runConfig.toolSetVersion))
|
|
345
345
|
.map((entry) => [entry.name, entry]));
|
|
346
|
+
if (runConfig.teamDefaultConcurrency !== undefined &&
|
|
347
|
+
(runConfig.toolSetVersion === '4' ||
|
|
348
|
+
mcp ||
|
|
349
|
+
[
|
|
350
|
+
previousWorkspaceToolSetVersion,
|
|
351
|
+
patchWorkspaceToolSetVersion,
|
|
352
|
+
phaseOneToolSetVersion,
|
|
353
|
+
workspaceToolSetVersion,
|
|
354
|
+
].includes(runConfig.toolSetVersion)) &&
|
|
355
|
+
registry.isActive(spawnTeamToolName, '3') &&
|
|
356
|
+
!overrides.has(spawnTeamToolName)) {
|
|
357
|
+
overrides.set(spawnTeamToolName, { name: spawnTeamToolName, version: '3', toolSets: [] });
|
|
358
|
+
}
|
|
346
359
|
const snapshot = registry.snapshotForAdmission(runConfig, overrides, ({ name, version, scopeKey }) => knownPluginTools.has(contributionIdentity({
|
|
347
360
|
kind: 'tool',
|
|
348
361
|
id: name,
|
package/dist/index.js
CHANGED
|
@@ -133,7 +133,7 @@ function failure(requestId, error) {
|
|
|
133
133
|
code: error instanceof RuntimeError ? error.code : 'INTERNAL',
|
|
134
134
|
message: `Command failed [diagnosticId: ${randomUUID()}]`,
|
|
135
135
|
retryable: error instanceof RuntimeError &&
|
|
136
|
-
['VERSION_CONFLICT', 'STORAGE_BUSY', 'HOST_BUSY'].includes(error.code),
|
|
136
|
+
['VERSION_CONFLICT', 'STORAGE_BUSY', 'HOST_BUSY', 'SESSION_BUSY'].includes(error.code),
|
|
137
137
|
},
|
|
138
138
|
};
|
|
139
139
|
}
|
|
@@ -122,6 +122,11 @@ export declare function loadModeConfiguration(env: NodeJS.ProcessEnv, configured
|
|
|
122
122
|
} | undefined;
|
|
123
123
|
team?: {
|
|
124
124
|
max_depth?: number | undefined;
|
|
125
|
+
default_concurrency?: number | undefined;
|
|
126
|
+
default_preset?: string | undefined;
|
|
127
|
+
max_concurrency?: number | undefined;
|
|
128
|
+
max_active_depth1?: number | undefined;
|
|
129
|
+
worker_soft_checkpoint_ms?: number | undefined;
|
|
125
130
|
async_coordinator?: boolean | undefined;
|
|
126
131
|
coordinator_poll_interval_ms?: number | undefined;
|
|
127
132
|
} | undefined;
|
package/dist/modes.js
CHANGED
|
@@ -351,7 +351,6 @@ function configureMode(ref, raw, builtin) {
|
|
|
351
351
|
'max_active_challenges',
|
|
352
352
|
'max_helpers_per_challenge',
|
|
353
353
|
'per_challenge_wall_time_ms',
|
|
354
|
-
'worker_soft_checkpoint_ms',
|
|
355
354
|
'board_port',
|
|
356
355
|
'board_token',
|
|
357
356
|
'board_public_host',
|
|
@@ -363,6 +362,8 @@ function configureMode(ref, raw, builtin) {
|
|
|
363
362
|
]
|
|
364
363
|
.filter((key) => raw[key] !== undefined)
|
|
365
364
|
.map((key) => [key, raw[key]]));
|
|
365
|
+
if (ref === 'ctf@1' && raw.worker_soft_checkpoint_ms !== undefined)
|
|
366
|
+
ctfOptions.worker_soft_checkpoint_ms = raw.worker_soft_checkpoint_ms;
|
|
366
367
|
if (Object.keys(ctfOptions).length) {
|
|
367
368
|
if (ref !== 'ctf@1')
|
|
368
369
|
throw new RuntimeError('INVALID_CONFIG', 'CTF settings require ctf@1');
|
|
@@ -374,31 +375,46 @@ function configureMode(ref, raw, builtin) {
|
|
|
374
375
|
const coordinatorPollIntervalMs = raw.coordinator_poll_interval_ms ??
|
|
375
376
|
raw.team?.coordinator_poll_interval_ms ??
|
|
376
377
|
base?.team?.coordinatorPollIntervalMs;
|
|
377
|
-
const workerSoftCheckpointMs = raw.worker_soft_checkpoint_ms ??
|
|
378
|
+
const workerSoftCheckpointMs = raw.team?.worker_soft_checkpoint_ms ??
|
|
379
|
+
raw.worker_soft_checkpoint_ms ??
|
|
380
|
+
base?.team?.workerSoftCheckpointMs;
|
|
378
381
|
const ctfPlugin = ref === 'ctf@1' ? plugins?.find((plugin) => plugin.builtin === 'ctf' || plugin.id === 'ctf') : undefined;
|
|
379
382
|
const rawMaxActive = ctfPlugin?.config?.max_active_challenges;
|
|
380
|
-
const maxActiveDepth1 =
|
|
381
|
-
|
|
382
|
-
|
|
383
|
+
const maxActiveDepth1 = raw.team?.max_active_depth1 ??
|
|
384
|
+
(typeof rawMaxActive === 'number' && Number.isSafeInteger(rawMaxActive) && rawMaxActive >= 1
|
|
385
|
+
? rawMaxActive
|
|
386
|
+
: base?.team?.maxActiveDepth1);
|
|
383
387
|
const isContainerSandbox = Boolean(sandbox && sandbox.backend !== 'host' && sandbox.scope !== 'none');
|
|
384
|
-
const
|
|
388
|
+
const sandboxConcurrency = isContainerSandbox
|
|
385
389
|
? sandbox?.maxConcurrentContainers !== undefined
|
|
386
390
|
? Math.max(1, sandbox.maxConcurrentContainers - 1)
|
|
387
391
|
: base?.team?.maxConcurrency
|
|
388
392
|
: undefined;
|
|
389
|
-
const
|
|
393
|
+
const maxConcurrency = raw.team?.max_concurrency ?? (isContainerSandbox ? base?.team?.maxConcurrency : undefined);
|
|
394
|
+
const defaultConcurrency = raw.team?.default_concurrency ?? base?.team?.defaultConcurrency;
|
|
395
|
+
if (defaultConcurrency !== undefined && maxConcurrency !== undefined && defaultConcurrency > maxConcurrency)
|
|
396
|
+
throw new RuntimeError('INVALID_CONFIG', `Mode ${ref}: team.default_concurrency exceeds team.max_concurrency`);
|
|
397
|
+
const effectiveMaxConcurrency = sandboxConcurrency === undefined
|
|
398
|
+
? maxConcurrency
|
|
399
|
+
: Math.min(sandboxConcurrency, raw.team?.max_concurrency ?? sandboxConcurrency);
|
|
400
|
+
const defaultPreset = raw.team?.default_preset ?? base?.team?.defaultPreset;
|
|
401
|
+
const team = defaultPreset !== undefined ||
|
|
402
|
+
maxDepth !== undefined ||
|
|
390
403
|
asyncCoordinator !== undefined ||
|
|
391
404
|
coordinatorPollIntervalMs !== undefined ||
|
|
392
405
|
workerSoftCheckpointMs !== undefined ||
|
|
393
406
|
maxActiveDepth1 !== undefined ||
|
|
394
|
-
|
|
407
|
+
defaultConcurrency !== undefined ||
|
|
408
|
+
effectiveMaxConcurrency !== undefined
|
|
395
409
|
? {
|
|
396
410
|
...(maxDepth !== undefined ? { maxDepth } : {}),
|
|
411
|
+
...(defaultPreset !== undefined ? { defaultPreset } : {}),
|
|
397
412
|
...(asyncCoordinator !== undefined ? { asyncCoordinator } : {}),
|
|
398
413
|
...(coordinatorPollIntervalMs !== undefined ? { coordinatorPollIntervalMs } : {}),
|
|
399
414
|
...(workerSoftCheckpointMs !== undefined ? { workerSoftCheckpointMs } : {}),
|
|
400
415
|
...(maxActiveDepth1 !== undefined ? { maxActiveDepth1 } : {}),
|
|
401
|
-
...(
|
|
416
|
+
...(defaultConcurrency !== undefined ? { defaultConcurrency } : {}),
|
|
417
|
+
...(effectiveMaxConcurrency !== undefined ? { maxConcurrency: effectiveMaxConcurrency } : {}),
|
|
402
418
|
}
|
|
403
419
|
: undefined;
|
|
404
420
|
const budget = { ...builtin?.budget, overrides: readConfiguredRunBudget(raw.limits) };
|
|
@@ -847,6 +847,11 @@ declare const catalogSchema: z.ZodObject<{
|
|
|
847
847
|
}, z.core.$strict>>;
|
|
848
848
|
team: z.ZodOptional<z.ZodObject<{
|
|
849
849
|
max_depth: z.ZodOptional<z.ZodNumber>;
|
|
850
|
+
default_concurrency: z.ZodOptional<z.ZodNumber>;
|
|
851
|
+
default_preset: z.ZodOptional<z.ZodString>;
|
|
852
|
+
max_concurrency: z.ZodOptional<z.ZodNumber>;
|
|
853
|
+
max_active_depth1: z.ZodOptional<z.ZodNumber>;
|
|
854
|
+
worker_soft_checkpoint_ms: z.ZodOptional<z.ZodNumber>;
|
|
850
855
|
async_coordinator: z.ZodOptional<z.ZodBoolean>;
|
|
851
856
|
coordinator_poll_interval_ms: z.ZodOptional<z.ZodNumber>;
|
|
852
857
|
}, z.core.$strict>>;
|
|
@@ -4,6 +4,7 @@ export interface SandboxMetaRecord {
|
|
|
4
4
|
readonly version: 1;
|
|
5
5
|
readonly workspaceRoot: string;
|
|
6
6
|
readonly workspaceHash: string;
|
|
7
|
+
readonly modeRef?: string;
|
|
7
8
|
readonly sessionId?: string;
|
|
8
9
|
readonly runId: string;
|
|
9
10
|
readonly role: 'main' | 'worker' | 'target';
|
|
@@ -44,6 +45,7 @@ export interface SandboxManagerOptions {
|
|
|
44
45
|
readonly allowUnsafeFallback?: boolean;
|
|
45
46
|
readonly runner?: ContainerRunner;
|
|
46
47
|
readonly checkKvmAvailable?: () => boolean;
|
|
48
|
+
readonly cleanupOrphans?: (cleanup: () => Promise<void>) => Promise<void>;
|
|
47
49
|
}
|
|
48
50
|
export interface SandboxTargetStartInput {
|
|
49
51
|
readonly runId: RunId;
|
package/dist/sandbox-manager.js
CHANGED
|
@@ -565,6 +565,10 @@ export function createSandboxManager(options) {
|
|
|
565
565
|
for (const metaPath of metas) {
|
|
566
566
|
try {
|
|
567
567
|
const parsed = JSON.parse(await readFile(metaPath, 'utf8'));
|
|
568
|
+
if (parsed.modeRef ? parsed.modeRef !== mode.ref : !parsed.expiresAt) {
|
|
569
|
+
anyRunning = true;
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
568
572
|
hasMeta = true;
|
|
569
573
|
if (parsed.status === 'running' ||
|
|
570
574
|
(parsed.runId && runMemberSessions.get(parsed.runId)?.size)) {
|
|
@@ -712,6 +716,7 @@ export function createSandboxManager(options) {
|
|
|
712
716
|
version: 1,
|
|
713
717
|
workspaceRoot: root,
|
|
714
718
|
workspaceHash,
|
|
719
|
+
modeRef: mode.ref,
|
|
715
720
|
...(effectiveSessionId !== undefined ? { sessionId: effectiveSessionId } : {}),
|
|
716
721
|
runId: params.runId,
|
|
717
722
|
role: params.role,
|
|
@@ -1055,18 +1060,18 @@ export function createSandboxManager(options) {
|
|
|
1055
1060
|
return;
|
|
1056
1061
|
}
|
|
1057
1062
|
signal?.throwIfAborted();
|
|
1058
|
-
const
|
|
1059
|
-
|
|
1060
|
-
.catch(() => []);
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1063
|
+
const cleanup = async () => {
|
|
1064
|
+
const labels = { 'saturn.managed': 'true', 'saturn.workspace': workspaceHash };
|
|
1065
|
+
const orphans = await runner.listManagedContainers(labels).catch(() => []);
|
|
1066
|
+
for (const orphan of orphans) {
|
|
1067
|
+
await runner.removeContainer(orphan.id).catch(() => { });
|
|
1068
|
+
}
|
|
1069
|
+
const orphanNetworks = await runner.listManagedNetworks?.(labels).catch(() => []);
|
|
1070
|
+
for (const orphanNet of orphanNetworks ?? []) {
|
|
1071
|
+
await runner.removeNetwork?.(orphanNet.name).catch(() => { });
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
await (options.cleanupOrphans ? options.cleanupOrphans(cleanup) : cleanup());
|
|
1070
1075
|
signal?.throwIfAborted();
|
|
1071
1076
|
if (!resolvedImage || !(await runner.hasImage(resolvedImage))) {
|
|
1072
1077
|
applyFallbackOrThrow('SANDBOX_IMAGE_MISSING', `Sandbox image "${resolvedImage ?? '(unspecified)'}" is missing locally`);
|
|
@@ -1364,6 +1369,7 @@ export function createSandboxManager(options) {
|
|
|
1364
1369
|
version: 1,
|
|
1365
1370
|
workspaceRoot: root,
|
|
1366
1371
|
workspaceHash,
|
|
1372
|
+
modeRef: mode.ref,
|
|
1367
1373
|
runId: input.runId,
|
|
1368
1374
|
role: 'target',
|
|
1369
1375
|
memberId: `target:${targetName}`,
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { AgentSessionId, RunConfig, TeamConfig, ToolDefinition, HostProtocolRequest, JsonValue, LoggerPort, ModeDefinition, RunId, SessionId } from '@saturn-universe/core';
|
|
2
|
+
import type { HostStatusFields } from '@saturn-universe/protocol';
|
|
3
|
+
import type { SqliteStore } from '@saturn-universe/storage';
|
|
4
|
+
import type { ProcessManager, createToolExecutor } from '@saturn-universe/tools';
|
|
5
|
+
import type { createAgentLoop, createRunLoop } from '@saturn-universe/runtime';
|
|
6
|
+
import type { PluginLifecycle } from './cordis/plugin-lifecycle.js';
|
|
7
|
+
import type { LoadedHostPlugin } from './cordis/plugin-loader.js';
|
|
8
|
+
type PluginStatus = ReturnType<PluginLifecycle['status']>;
|
|
9
|
+
type RunDependencies = Parameters<typeof createRunLoop>[0];
|
|
10
|
+
export interface WorkerModeRuntime {
|
|
11
|
+
readonly agent: ReturnType<typeof createAgentLoop>;
|
|
12
|
+
readonly executor: ReturnType<typeof createToolExecutor>;
|
|
13
|
+
readonly freeze: (parent: RunConfig, team: TeamConfig, agentSessionId: AgentSessionId, depth: number) => Promise<RunConfig>;
|
|
14
|
+
readonly verify: (config: RunConfig) => Promise<void>;
|
|
15
|
+
readonly verifyTool: (definition: ToolDefinition) => Promise<unknown>;
|
|
16
|
+
readonly start: NonNullable<RunDependencies['onWorkerStart']>;
|
|
17
|
+
readonly complete: NonNullable<RunDependencies['onWorkerComplete']>;
|
|
18
|
+
}
|
|
19
|
+
export interface WorkerModeMounts {
|
|
20
|
+
acquire(modeRef: string, runId: RunId, agentSessionId: AgentSessionId): Promise<WorkerModeRuntime>;
|
|
21
|
+
find(runId: RunId, agentSessionId: AgentSessionId): WorkerModeRuntime | undefined;
|
|
22
|
+
release(runId: RunId, agentSessionId?: AgentSessionId): Promise<void>;
|
|
23
|
+
wake(runId: RunId): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
interface ModeRuntime {
|
|
26
|
+
readonly status: Omit<HostStatusFields, 'epoch' | 'cursor'> & {
|
|
27
|
+
readonly configuredProfiles: number;
|
|
28
|
+
readonly plugins: PluginStatus;
|
|
29
|
+
readonly driverFailures: readonly {
|
|
30
|
+
runId: string;
|
|
31
|
+
code: string;
|
|
32
|
+
diagnosticId: string;
|
|
33
|
+
}[];
|
|
34
|
+
};
|
|
35
|
+
handle(request: HostProtocolRequest, signal?: AbortSignal): Promise<JsonValue>;
|
|
36
|
+
recoverRuns(runIds: readonly RunId[]): Promise<void>;
|
|
37
|
+
activePlugins(): readonly LoadedHostPlugin[];
|
|
38
|
+
reloadPlugins(): Promise<PluginStatus>;
|
|
39
|
+
reloadPlugin(id: string): Promise<PluginStatus>;
|
|
40
|
+
deactivatePlugin(id: string): Promise<PluginStatus>;
|
|
41
|
+
pluginGenerations(): PluginStatus;
|
|
42
|
+
drainPlugins(): Promise<PluginStatus>;
|
|
43
|
+
close(): Promise<void>;
|
|
44
|
+
stopRuns(): Promise<void>;
|
|
45
|
+
wakeTeam(runId: RunId): Promise<void> | undefined;
|
|
46
|
+
readonly worker: WorkerModeRuntime;
|
|
47
|
+
}
|
|
48
|
+
export declare function createSessionModeRuntime({ store, activeMode, availableModes, processManager, logger, mount, }: {
|
|
49
|
+
store: SqliteStore;
|
|
50
|
+
activeMode: ModeDefinition;
|
|
51
|
+
availableModes: readonly ModeDefinition[];
|
|
52
|
+
processManager: ProcessManager;
|
|
53
|
+
logger: LoggerPort;
|
|
54
|
+
mount: (modeRef: string, workers: WorkerModeMounts, plugins?: readonly LoadedHostPlugin[]) => Promise<ModeRuntime>;
|
|
55
|
+
}): Promise<{
|
|
56
|
+
readonly status: ModeRuntime["status"];
|
|
57
|
+
recover: () => Promise<void>;
|
|
58
|
+
handle: (request: HostProtocolRequest, signal?: AbortSignal) => Promise<JsonValue> | Promise<Readonly<{
|
|
59
|
+
sessionId: SessionId;
|
|
60
|
+
mode: {
|
|
61
|
+
ref: string;
|
|
62
|
+
displayName: string;
|
|
63
|
+
description: string;
|
|
64
|
+
};
|
|
65
|
+
cursor: import("@saturn-universe/core").EventPosition;
|
|
66
|
+
}>>;
|
|
67
|
+
reloadPlugins: () => Promise<{
|
|
68
|
+
id: string;
|
|
69
|
+
version: string;
|
|
70
|
+
kind: "saturn-registrar" | "cordis";
|
|
71
|
+
status: "active" | "draining";
|
|
72
|
+
}[]>;
|
|
73
|
+
reloadPlugin: (id: string) => Promise<{
|
|
74
|
+
id: string;
|
|
75
|
+
version: string;
|
|
76
|
+
kind: "saturn-registrar" | "cordis";
|
|
77
|
+
status: "active" | "draining";
|
|
78
|
+
}[]>;
|
|
79
|
+
deactivatePlugin: (id: string) => Promise<{
|
|
80
|
+
id: string;
|
|
81
|
+
version: string;
|
|
82
|
+
kind: "saturn-registrar" | "cordis";
|
|
83
|
+
status: "active" | "draining";
|
|
84
|
+
}[]>;
|
|
85
|
+
pluginGenerations: () => {
|
|
86
|
+
id: string;
|
|
87
|
+
version: string;
|
|
88
|
+
kind: "saturn-registrar" | "cordis";
|
|
89
|
+
status: "active" | "draining";
|
|
90
|
+
}[];
|
|
91
|
+
drainPlugins: () => Promise<{
|
|
92
|
+
id: string;
|
|
93
|
+
version: string;
|
|
94
|
+
kind: "saturn-registrar" | "cordis";
|
|
95
|
+
status: "active" | "draining";
|
|
96
|
+
}[]>;
|
|
97
|
+
close(): Promise<void>;
|
|
98
|
+
}>;
|
|
99
|
+
export {};
|