@saturn-universe/runtime-host 0.1.2-dev.5 → 0.1.2-dev.9

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.
Files changed (37) hide show
  1. package/dist/builtin-plugins/saturn-plugin-ctf/index.mjs +2 -2
  2. package/dist/builtin-plugins/saturn-plugin-ctf/package.json +1 -1
  3. package/dist/command-dispatch.js +1 -0
  4. package/dist/composition.d.ts +20 -56
  5. package/dist/composition.js +316 -89
  6. package/dist/context-extensions.d.ts +130 -10
  7. package/dist/context-extensions.js +30 -4
  8. package/dist/cordis/plugin-lifecycle.d.ts +1 -0
  9. package/dist/cordis/plugin-lifecycle.js +3 -0
  10. package/dist/cordis/sandbox-plugin.d.ts +1 -0
  11. package/dist/cordis/sandbox-plugin.js +1 -0
  12. package/dist/cordis/tools/builtin-agent-tools-plugin.d.ts +2 -2
  13. package/dist/cordis/tools/builtin-agent-tools-plugin.js +27 -3
  14. package/dist/cordis/tools/index.d.ts +5 -1
  15. package/dist/cordis/tools/index.js +3 -3
  16. package/dist/cordis/tools/process-manager-plugin.d.ts +1 -1
  17. package/dist/cordis/tools/process-manager-plugin.js +8 -8
  18. package/dist/cordis/tools/tools-core-plugin.js +54 -11
  19. package/dist/host-configuration.d.ts +1 -0
  20. package/dist/host-configuration.js +2 -1
  21. package/dist/index.js +1 -1
  22. package/dist/mode-configuration.d.ts +46 -3
  23. package/dist/mode-configuration.js +3 -0
  24. package/dist/modes.js +52 -10
  25. package/dist/provider-catalog.d.ts +84 -14
  26. package/dist/provider-catalog.js +29 -45
  27. package/dist/run-budget.d.ts +21 -6
  28. package/dist/run-budget.js +48 -12
  29. package/dist/runtime-tuning.d.ts +23 -0
  30. package/dist/runtime-tuning.js +68 -0
  31. package/dist/sandbox-manager.d.ts +2 -0
  32. package/dist/sandbox-manager.js +18 -12
  33. package/dist/session-mode-runtime.d.ts +99 -0
  34. package/dist/session-mode-runtime.js +306 -0
  35. package/dist/skills-runtime.d.ts +5 -2
  36. package/dist/skills-runtime.js +8 -5
  37. package/package.json +9 -9
@@ -107,16 +107,48 @@ export declare const modeDefinitionSchema: z.ZodObject<{
107
107
  }, z.core.$strict>>;
108
108
  }, z.core.$strict>>;
109
109
  tools: z.ZodOptional<z.ZodObject<{
110
- workspace_tools: z.ZodOptional<z.ZodBoolean>;
111
- process_manager: z.ZodOptional<z.ZodBoolean>;
112
- builtin_agent_tools: z.ZodOptional<z.ZodBoolean>;
113
- allowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
114
- denied_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
110
+ roles: z.ZodOptional<z.ZodObject<{
111
+ main: z.ZodOptional<z.ZodObject<{
112
+ allowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
113
+ denied_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
114
+ }, z.core.$strict>>;
115
+ worker: z.ZodOptional<z.ZodObject<{
116
+ allowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
117
+ denied_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
118
+ }, z.core.$strict>>;
119
+ }, z.core.$strict>>;
115
120
  permission_mode: z.ZodOptional<z.ZodEnum<{
116
121
  default: "default";
117
122
  strict: "strict";
118
123
  full: "full";
119
124
  }>>;
125
+ allowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
126
+ denied_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
127
+ workspace_tools: z.ZodOptional<z.ZodBoolean>;
128
+ process_manager: z.ZodOptional<z.ZodBoolean>;
129
+ builtin_agent_tools: z.ZodOptional<z.ZodBoolean>;
130
+ }, z.core.$strict>>;
131
+ reasoning: z.ZodOptional<z.ZodObject<{
132
+ main_effort: z.ZodOptional<z.ZodEnum<{
133
+ low: "low";
134
+ off: "off";
135
+ none: "none";
136
+ minimal: "minimal";
137
+ medium: "medium";
138
+ high: "high";
139
+ xhigh: "xhigh";
140
+ max: "max";
141
+ }>>;
142
+ worker_effort: z.ZodOptional<z.ZodEnum<{
143
+ low: "low";
144
+ off: "off";
145
+ none: "none";
146
+ minimal: "minimal";
147
+ medium: "medium";
148
+ high: "high";
149
+ xhigh: "xhigh";
150
+ max: "max";
151
+ }>>;
120
152
  }, z.core.$strict>>;
121
153
  plugins: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodPreprocess<z.ZodPipe<z.ZodArray<z.ZodTuple<[z.ZodType<string, unknown, z.core.$ZodTypeInternals<string, unknown>>, z.ZodObject<{
122
154
  allowed_tools: z.ZodOptional<z.ZodType<string[], unknown, z.core.$ZodTypeInternals<string[], unknown>>>;
@@ -337,11 +369,21 @@ export declare const modeDefinitionSchema: z.ZodObject<{
337
369
  }, z.core.$strict>>;
338
370
  team: z.ZodOptional<z.ZodObject<{
339
371
  max_depth: z.ZodOptional<z.ZodNumber>;
372
+ default_concurrency: z.ZodOptional<z.ZodNumber>;
373
+ default_preset: z.ZodOptional<z.ZodString>;
374
+ max_concurrency: z.ZodOptional<z.ZodNumber>;
375
+ max_active_depth1: z.ZodOptional<z.ZodNumber>;
376
+ worker_soft_checkpoint_ms: z.ZodOptional<z.ZodNumber>;
340
377
  async_coordinator: z.ZodOptional<z.ZodBoolean>;
341
378
  coordinator_poll_interval_ms: z.ZodOptional<z.ZodNumber>;
342
379
  }, z.core.$strict>>;
343
380
  limits: z.ZodOptional<z.ZodObject<{
381
+ model_timeout_ms: z.ZodOptional<z.ZodNumber>;
382
+ stream_idle_timeout_ms: z.ZodOptional<z.ZodNumber>;
383
+ request_total_timeout_ms: z.ZodOptional<z.ZodNumber>;
344
384
  tool_timeout_ms: z.ZodOptional<z.ZodNumber>;
385
+ shell_timeout_ms: z.ZodOptional<z.ZodNumber>;
386
+ max_parallel_tools: z.ZodOptional<z.ZodNumber>;
345
387
  max_model_attempts: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
346
388
  max_tool_calls: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
347
389
  max_steps: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
@@ -350,6 +392,24 @@ export declare const modeDefinitionSchema: z.ZodObject<{
350
392
  wall_time_ms: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
351
393
  subagent_wall_time_ms: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
352
394
  }, z.core.$strict>>;
395
+ retry: z.ZodOptional<z.ZodObject<{
396
+ model_max_attempts_per_call: z.ZodOptional<z.ZodNumber>;
397
+ tool_max_attempts_per_call: z.ZodOptional<z.ZodNumber>;
398
+ base_delay_ms: z.ZodOptional<z.ZodNumber>;
399
+ max_delay_ms: z.ZodOptional<z.ZodNumber>;
400
+ }, z.core.$strict>>;
401
+ compaction: z.ZodOptional<z.ZodObject<{
402
+ enabled: z.ZodOptional<z.ZodBoolean>;
403
+ threshold_ratio: z.ZodOptional<z.ZodNumber>;
404
+ max_headroom_tokens: z.ZodOptional<z.ZodNumber>;
405
+ headroom_ratio: z.ZodOptional<z.ZodNumber>;
406
+ min_recent_steps: z.ZodOptional<z.ZodNumber>;
407
+ tail_window_ratio: z.ZodOptional<z.ZodNumber>;
408
+ preflight_window_ratio: z.ZodOptional<z.ZodNumber>;
409
+ max_halvings: z.ZodOptional<z.ZodNumber>;
410
+ min_prefix_chars: z.ZodOptional<z.ZodNumber>;
411
+ summary_timeout_ms: z.ZodOptional<z.ZodNumber>;
412
+ }, z.core.$strict>>;
353
413
  max_active_challenges: z.ZodOptional<z.ZodNumber>;
354
414
  max_helpers_per_challenge: z.ZodOptional<z.ZodNumber>;
355
415
  per_challenge_wall_time_ms: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
@@ -420,16 +480,48 @@ export declare const modeDefinitionsSchema: z.ZodRecord<z.ZodString, z.ZodObject
420
480
  }, z.core.$strict>>;
421
481
  }, z.core.$strict>>;
422
482
  tools: z.ZodOptional<z.ZodObject<{
423
- workspace_tools: z.ZodOptional<z.ZodBoolean>;
424
- process_manager: z.ZodOptional<z.ZodBoolean>;
425
- builtin_agent_tools: z.ZodOptional<z.ZodBoolean>;
426
- allowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
427
- denied_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
483
+ roles: z.ZodOptional<z.ZodObject<{
484
+ main: z.ZodOptional<z.ZodObject<{
485
+ allowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
486
+ denied_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
487
+ }, z.core.$strict>>;
488
+ worker: z.ZodOptional<z.ZodObject<{
489
+ allowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
490
+ denied_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
491
+ }, z.core.$strict>>;
492
+ }, z.core.$strict>>;
428
493
  permission_mode: z.ZodOptional<z.ZodEnum<{
429
494
  default: "default";
430
495
  strict: "strict";
431
496
  full: "full";
432
497
  }>>;
498
+ allowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
499
+ denied_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
500
+ workspace_tools: z.ZodOptional<z.ZodBoolean>;
501
+ process_manager: z.ZodOptional<z.ZodBoolean>;
502
+ builtin_agent_tools: z.ZodOptional<z.ZodBoolean>;
503
+ }, z.core.$strict>>;
504
+ reasoning: z.ZodOptional<z.ZodObject<{
505
+ main_effort: z.ZodOptional<z.ZodEnum<{
506
+ low: "low";
507
+ off: "off";
508
+ none: "none";
509
+ minimal: "minimal";
510
+ medium: "medium";
511
+ high: "high";
512
+ xhigh: "xhigh";
513
+ max: "max";
514
+ }>>;
515
+ worker_effort: z.ZodOptional<z.ZodEnum<{
516
+ low: "low";
517
+ off: "off";
518
+ none: "none";
519
+ minimal: "minimal";
520
+ medium: "medium";
521
+ high: "high";
522
+ xhigh: "xhigh";
523
+ max: "max";
524
+ }>>;
433
525
  }, z.core.$strict>>;
434
526
  plugins: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodPreprocess<z.ZodPipe<z.ZodArray<z.ZodTuple<[z.ZodType<string, unknown, z.core.$ZodTypeInternals<string, unknown>>, z.ZodObject<{
435
527
  allowed_tools: z.ZodOptional<z.ZodType<string[], unknown, z.core.$ZodTypeInternals<string[], unknown>>>;
@@ -650,11 +742,21 @@ export declare const modeDefinitionsSchema: z.ZodRecord<z.ZodString, z.ZodObject
650
742
  }, z.core.$strict>>;
651
743
  team: z.ZodOptional<z.ZodObject<{
652
744
  max_depth: z.ZodOptional<z.ZodNumber>;
745
+ default_concurrency: z.ZodOptional<z.ZodNumber>;
746
+ default_preset: z.ZodOptional<z.ZodString>;
747
+ max_concurrency: z.ZodOptional<z.ZodNumber>;
748
+ max_active_depth1: z.ZodOptional<z.ZodNumber>;
749
+ worker_soft_checkpoint_ms: z.ZodOptional<z.ZodNumber>;
653
750
  async_coordinator: z.ZodOptional<z.ZodBoolean>;
654
751
  coordinator_poll_interval_ms: z.ZodOptional<z.ZodNumber>;
655
752
  }, z.core.$strict>>;
656
753
  limits: z.ZodOptional<z.ZodObject<{
754
+ model_timeout_ms: z.ZodOptional<z.ZodNumber>;
755
+ stream_idle_timeout_ms: z.ZodOptional<z.ZodNumber>;
756
+ request_total_timeout_ms: z.ZodOptional<z.ZodNumber>;
657
757
  tool_timeout_ms: z.ZodOptional<z.ZodNumber>;
758
+ shell_timeout_ms: z.ZodOptional<z.ZodNumber>;
759
+ max_parallel_tools: z.ZodOptional<z.ZodNumber>;
658
760
  max_model_attempts: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
659
761
  max_tool_calls: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
660
762
  max_steps: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
@@ -663,6 +765,24 @@ export declare const modeDefinitionsSchema: z.ZodRecord<z.ZodString, z.ZodObject
663
765
  wall_time_ms: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
664
766
  subagent_wall_time_ms: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
665
767
  }, z.core.$strict>>;
768
+ retry: z.ZodOptional<z.ZodObject<{
769
+ model_max_attempts_per_call: z.ZodOptional<z.ZodNumber>;
770
+ tool_max_attempts_per_call: z.ZodOptional<z.ZodNumber>;
771
+ base_delay_ms: z.ZodOptional<z.ZodNumber>;
772
+ max_delay_ms: z.ZodOptional<z.ZodNumber>;
773
+ }, z.core.$strict>>;
774
+ compaction: z.ZodOptional<z.ZodObject<{
775
+ enabled: z.ZodOptional<z.ZodBoolean>;
776
+ threshold_ratio: z.ZodOptional<z.ZodNumber>;
777
+ max_headroom_tokens: z.ZodOptional<z.ZodNumber>;
778
+ headroom_ratio: z.ZodOptional<z.ZodNumber>;
779
+ min_recent_steps: z.ZodOptional<z.ZodNumber>;
780
+ tail_window_ratio: z.ZodOptional<z.ZodNumber>;
781
+ preflight_window_ratio: z.ZodOptional<z.ZodNumber>;
782
+ max_halvings: z.ZodOptional<z.ZodNumber>;
783
+ min_prefix_chars: z.ZodOptional<z.ZodNumber>;
784
+ summary_timeout_ms: z.ZodOptional<z.ZodNumber>;
785
+ }, z.core.$strict>>;
666
786
  max_active_challenges: z.ZodOptional<z.ZodNumber>;
667
787
  max_helpers_per_challenge: z.ZodOptional<z.ZodNumber>;
668
788
  per_challenge_wall_time_ms: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
@@ -6,6 +6,7 @@ import { readFileWindow, relativePathWithin } from '@saturn-universe/tools';
6
6
  import { configurationTable, pluginConfigSchema, pluginEntrySchema, pluginIdSchema, } from './plugin-configuration.js';
7
7
  import { configuredPluginGrantFields, validConfiguredPluginGrant } from './plugin-tool-grants.js';
8
8
  import { configuredRunBudgetShape, unlimitedInt } from './run-budget.js';
9
+ import { modeCompactionSchema, modeRetrySchema } from './runtime-tuning.js';
9
10
  const maxFileBytes = 64 * 1024;
10
11
  const maxSnapshotBytes = 256 * 1024;
11
12
  const ref = z.string().regex(contextExtensionRefPattern);
@@ -42,12 +43,20 @@ const modePromptsSchema = z.strictObject({
42
43
  })
43
44
  .optional(),
44
45
  });
46
+ const modeToolFilterShape = {
47
+ allowed_tools: toolNames.optional(),
48
+ denied_tools: toolNames.optional(),
49
+ };
50
+ const modeRoleToolFilter = z.strictObject(modeToolFilterShape);
51
+ const modeReasoningEffort = z.enum(['off', 'none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max']);
45
52
  const modeToolsSchema = z.strictObject({
46
53
  workspace_tools: z.boolean().optional(),
47
54
  process_manager: z.boolean().optional(),
48
55
  builtin_agent_tools: z.boolean().optional(),
49
- allowed_tools: toolNames.optional(),
50
- denied_tools: toolNames.optional(),
56
+ ...modeToolFilterShape,
57
+ roles: z
58
+ .strictObject({ main: modeRoleToolFilter.optional(), worker: modeRoleToolFilter.optional() })
59
+ .optional(),
51
60
  permission_mode: z.enum(['strict', 'default', 'full']).optional(),
52
61
  });
53
62
  const modePluginEntrySchema = z
@@ -132,6 +141,11 @@ export const modeSandboxSchema = z.strictObject({
132
141
  });
133
142
  const modeTeamSchema = z.strictObject({
134
143
  max_depth: z.number().int().min(1).max(2).optional(),
144
+ default_concurrency: z.number().int().positive().optional(),
145
+ default_preset: identifier.optional(),
146
+ max_concurrency: z.number().int().positive().optional(),
147
+ max_active_depth1: z.number().int().positive().optional(),
148
+ worker_soft_checkpoint_ms: z.number().int().nonnegative().optional(),
135
149
  async_coordinator: z.boolean().optional(),
136
150
  coordinator_poll_interval_ms: z.number().int().min(0).optional(),
137
151
  });
@@ -145,10 +159,18 @@ export const modeDefinitionSchema = z
145
159
  denied_tools: toolNames.optional(),
146
160
  prompts: modePromptsSchema.optional(),
147
161
  tools: modeToolsSchema.optional(),
162
+ reasoning: z
163
+ .strictObject({
164
+ main_effort: modeReasoningEffort.optional(),
165
+ worker_effort: modeReasoningEffort.optional(),
166
+ })
167
+ .optional(),
148
168
  plugins: modePluginsSchema.optional(),
149
169
  sandbox: modeSandboxSchema.optional(),
150
170
  team: modeTeamSchema.optional(),
151
171
  limits: modeLimitsSchema.optional(),
172
+ retry: modeRetrySchema.optional(),
173
+ compaction: modeCompactionSchema.optional(),
152
174
  max_active_challenges: z.number().int().min(1).optional(),
153
175
  max_helpers_per_challenge: z.number().int().min(0).optional(),
154
176
  per_challenge_wall_time_ms: unlimitedInt().optional(),
@@ -171,8 +193,11 @@ export async function freezeContextExtensions(root, mode, availableSkills, skill
171
193
  if (skillRefs.length > 16)
172
194
  throw invalid();
173
195
  const modeInstructions = mode.prompts?.instructions ?? '';
174
- const { allowedTools, deniedTools } = mode.tools ?? {};
175
- const hasFrozenMode = Boolean(modeInstructions.trim()) || allowedTools !== undefined || deniedTools !== undefined;
196
+ const { allowedTools, deniedTools, roles } = mode.tools ?? {};
197
+ const hasFrozenMode = Boolean(modeInstructions.trim()) ||
198
+ allowedTools !== undefined ||
199
+ deniedTools !== undefined ||
200
+ roles !== undefined;
176
201
  if (!hasFrozenMode && !skillRefs.length)
177
202
  return {};
178
203
  if (new Set(skillRefs.map((value) => value.split('@')[0])).size !== skillRefs.length)
@@ -210,6 +235,7 @@ export async function freezeContextExtensions(root, mode, availableSkills, skill
210
235
  instructions: modeInstructions,
211
236
  ...(allowedTools !== undefined ? { allowedTools: [...allowedTools] } : {}),
212
237
  ...(deniedTools !== undefined ? { deniedTools: [...deniedTools] } : {}),
238
+ ...(roles !== undefined ? { toolRoles: structuredClone(roles) } : {}),
213
239
  },
214
240
  }
215
241
  : {}),
@@ -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 () => {
@@ -1,10 +1,10 @@
1
1
  import type { Context } from '@deepseek-ai/cordis';
2
2
  import type { PromptSection, RunConfig, RunId, ToolBinding, ToolSpec } from '@saturn-universe/core';
3
- import { type TeamNotifyParentDelivery } from '@saturn-universe/tools';
3
+ import { type TeamMemberAction, type TeamNotifyParentDelivery } from '@saturn-universe/tools';
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>): {
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>;
@@ -1,6 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import { buildTeamHintPrompt } from '@saturn-universe/context';
3
- import { createCounterTool, createDataReviewTool, createPlannerTool, createSpawnTeamTool, createTeamNotifyParentTool, createTodoWriteTool, dataReviewToolSet, teamNotifyParentToolName, } from '@saturn-universe/tools';
3
+ import { createCounterTool, createDataReviewTool, createPlannerTool, createSpawnTeamTool, createTeamNotifyParentTool, createTeamSteerMemberTool, createTeamStopMemberTool, createTodoWriteTool, dataReviewToolSet, teamNotifyParentToolName, } from '@saturn-universe/tools';
4
4
  import { sharedToolPriority } from './tools-core-plugin.js';
5
5
  import { registerToolGuidance } from './tool-guidance.js';
6
6
  import { createNativeSkillTool, skillToolName } from '../../skills-runtime.js';
@@ -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) {
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'],
@@ -52,7 +52,7 @@ export function createBuiltinAgentToolsPlugin(root, settings, resultReader, prev
52
52
  if (depth === 0 && env.config.teamMaxActiveDepth1 !== undefined) {
53
53
  const team = await store.stateReader.team?.(toolCtx.runId);
54
54
  activeDepth1Count = (team?.members ?? []).filter((member) => member.parent === 'main' &&
55
- !['completed', 'failed', 'interrupted'].includes(member.status)).length;
55
+ !['completed', 'failed', 'interrupted', 'stopped'].includes(member.status)).length;
56
56
  }
57
57
  return {
58
58
  memberId,
@@ -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],
@@ -127,6 +141,16 @@ export function createBuiltinAgentToolsPlugin(root, settings, resultReader, prev
127
141
  scope: { kind: 'role', roles: ['worker'] },
128
142
  order: { tier: 'tail', priority: 5 },
129
143
  }));
144
+ const memberControls = [
145
+ ...(steerMember ? [createTeamSteerMemberTool(steerMember)] : []),
146
+ ...(stopMember ? [createTeamStopMemberTool(stopMember)] : []),
147
+ ];
148
+ for (const { definition, handler } of memberControls) {
149
+ ctx.effect(() => tools.registerTool(definition, handler, sets.defaultVersions, {
150
+ scope: { kind: 'role', roles: ['main'] },
151
+ order: { tier: 'tail', priority: 6 },
152
+ }));
153
+ }
130
154
  registerToolGuidance(ctx, 'agent-tool-guidance', -30, (visible, config) => {
131
155
  const lines = [];
132
156
  if (visible.has('read_tool_result'))
@@ -1,5 +1,5 @@
1
1
  import type { RunId, ToolBinding } from '@saturn-universe/core';
2
- import type { ProcessManagerOptions, 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,9 +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;
16
+ steerMember?: TeamMemberAction;
17
+ stopMember?: TeamMemberAction;
15
18
  notifyParent?: (delivery: TeamNotifyParentDelivery) => Promise<void>;
19
+ resolveWorkerModeRef?: (selector: string) => string | undefined;
16
20
  }
17
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, } = 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)),
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 = createProcessManager({
29
- ...options,
30
- directory: path.join(root, '.saturn', 'processes'),
31
- });
32
- ctx.effect(() => async () => {
33
- await manager.close();
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
  },
@@ -1,11 +1,34 @@
1
- import { configForDerivedAgent, RuntimeError } from '@saturn-universe/core';
2
- import { Registry, dataReviewToolName, dataReviewToolSet, outsideWorkspacePrefix, plannerToolName, spawnTeamToolName, teamNotifyParentToolName, todoWriteToolName, } from '@saturn-universe/tools';
1
+ import { configForDerivedAgent, isAsyncCoordinatorConfig, RuntimeError } from '@saturn-universe/core';
2
+ import { Registry, dataReviewToolName, dataReviewToolSet, outsideWorkspacePrefix, plannerToolName, spawnTeamToolName, teamNotifyParentToolName, isTeamMemberControlTool, todoWriteToolName, } from '@saturn-universe/tools';
3
3
  import { resolveWorkerReasoning } from '../../provider-catalog.js';
4
4
  import { skillToolName } from '../../skills-runtime.js';
5
5
  import { contributionScopeKey, globalScope, matchesScope, primaryRole, ScopedLayers, validateContributionScope, } from '../scoped-layers.js';
6
6
  import { contributionIdentity, registerPluginContribution, trackPluginTool, } from '../plugin-contributions.js';
7
7
  import { sandboxTargetToolNames } from './sandbox-target-tools-plugin.js';
8
8
  import { webToolNames } from './web-search-tools-plugin.js';
9
+ function configForToolRole(config, role) {
10
+ const context = config.contextExtensions;
11
+ const mode = context?.mode;
12
+ const filter = role === 'main' || role === 'worker' ? mode?.toolRoles?.[role] : undefined;
13
+ if (!context || !mode || !filter)
14
+ return config;
15
+ const { allowedTools: globalAllowed, deniedTools: globalDenied } = mode;
16
+ const { allowedTools: roleAllowed, deniedTools: roleDenied } = filter;
17
+ const allowedTools = globalAllowed && roleAllowed
18
+ ? globalAllowed.filter((name) => roleAllowed.includes(name))
19
+ : (globalAllowed ?? roleAllowed);
20
+ return {
21
+ ...config,
22
+ contextExtensions: {
23
+ ...context,
24
+ mode: {
25
+ ...mode,
26
+ ...(allowedTools !== undefined ? { allowedTools } : {}),
27
+ deniedTools: [...(globalDenied ?? []), ...(roleDenied ?? [])],
28
+ },
29
+ },
30
+ };
31
+ }
9
32
  export const interactiveToolPolicies = {
10
33
  strict: 'interactive-strict-v1',
11
34
  default: 'interactive-default-v2',
@@ -280,7 +303,8 @@ function createToolsService(config, trustedConfig, hash) {
280
303
  return { decision: 'allow' };
281
304
  if (definition.name === spawnTeamToolName ||
282
305
  definition.name === todoWriteToolName ||
283
- definition.name === teamNotifyParentToolName)
306
+ definition.name === teamNotifyParentToolName ||
307
+ isTeamMemberControlTool(definition.name))
284
308
  return { decision: 'allow' };
285
309
  if (definition.name === skillToolName)
286
310
  return { decision: 'allow' };
@@ -342,7 +366,21 @@ function createToolsService(config, trustedConfig, hash) {
342
366
  const overrides = new Map(scoped
343
367
  .resolve(target, ({ scopeKey, toolSets }) => scopeKey !== undefined && toolSets.includes(runConfig.toolSetVersion))
344
368
  .map((entry) => [entry.name, entry]));
345
- const snapshot = registry.snapshotForAdmission(runConfig, overrides, ({ name, version, scopeKey }) => knownPluginTools.has(contributionIdentity({
369
+ if (runConfig.teamDefaultConcurrency !== undefined &&
370
+ (runConfig.toolSetVersion === '4' ||
371
+ mcp ||
372
+ [
373
+ previousWorkspaceToolSetVersion,
374
+ patchWorkspaceToolSetVersion,
375
+ phaseOneToolSetVersion,
376
+ workspaceToolSetVersion,
377
+ ].includes(runConfig.toolSetVersion)) &&
378
+ registry.isActive(spawnTeamToolName, '3') &&
379
+ !overrides.has(spawnTeamToolName)) {
380
+ overrides.set(spawnTeamToolName, { name: spawnTeamToolName, version: '3', toolSets: [] });
381
+ }
382
+ const filtered = configForToolRole(runConfig, target.role);
383
+ const snapshot = registry.snapshotForAdmission(filtered, overrides, ({ name, version, scopeKey }) => knownPluginTools.has(contributionIdentity({
346
384
  kind: 'tool',
347
385
  id: name,
348
386
  version,
@@ -351,11 +389,11 @@ function createToolsService(config, trustedConfig, hash) {
351
389
  const rawDefinitions = runConfig.team
352
390
  ? snapshot.definitions.map((definition) => teamVariant(definition, runConfig.toolSetVersion))
353
391
  : snapshot.definitions;
354
- const definitions = target.role === 'worker' && !config.workerAllowTargetServices
355
- ? rawDefinitions.filter(({ name }) => !sandboxTargetToolNames.has(name))
356
- : rawDefinitions;
357
- const allowed = runConfig.contextExtensions?.mode?.allowedTools;
358
- const denied = runConfig.contextExtensions?.mode?.deniedTools;
392
+ const allowMemberControl = target.role === 'main' && isAsyncCoordinatorConfig(runConfig);
393
+ const definitions = rawDefinitions.filter(({ name }) => (allowMemberControl || !isTeamMemberControlTool(name)) &&
394
+ (target.role !== 'worker' || config.workerAllowTargetServices || !sandboxTargetToolNames.has(name)));
395
+ const allowed = filtered.contextExtensions?.mode?.allowedTools;
396
+ const denied = filtered.contextExtensions?.mode?.deniedTools;
359
397
  if (allowed) {
360
398
  const selected = new Set(definitions.map(({ name }) => name));
361
399
  const inactive = [...knownPluginTools.values()].find(({ name, version, scopeKey, scope, toolSets }) => allowed.includes(name) &&
@@ -446,9 +484,14 @@ function createToolsService(config, trustedConfig, hash) {
446
484
  const allowSpawnTeam = agentDepth < teamMaxDepth;
447
485
  const allowNotifyParent = agentDepth === 1;
448
486
  const allowTargetServices = Boolean(config.workerAllowTargetServices);
449
- const snapshot = await registry.snapshot(workerBase);
487
+ const filtered = configForToolRole(workerBase, 'worker');
488
+ const { allowedTools, deniedTools } = filtered.contextExtensions?.mode ?? {};
489
+ const snapshot = await registry.snapshot(filtered);
450
490
  const definitions = snapshot.definitions
451
- .filter(({ name }) => name !== todoWriteToolName &&
491
+ .filter(({ name }) => (!allowedTools || allowedTools.includes(name)) &&
492
+ !deniedTools?.includes(name) &&
493
+ name !== todoWriteToolName &&
494
+ !isTeamMemberControlTool(name) &&
452
495
  (allowSpawnTeam || name !== spawnTeamToolName) &&
453
496
  (allowNotifyParent || name !== teamNotifyParentToolName) &&
454
497
  (allowTargetServices || !sandboxTargetToolNames.has(name)))
@@ -23,6 +23,7 @@ export declare function loadHostConfiguration(root: string, explicitFile?: strin
23
23
  trustedMcp: boolean;
24
24
  trustedPlugins: boolean;
25
25
  modePluginSources?: Awaited<ReturnType<typeof loadModeConfiguration>>['modePluginSources'];
26
+ modePackageDirectories: ReadonlyMap<string, string>;
26
27
  webSearch?: ProviderCatalog['webSearch'];
27
28
  mcpServers?: ProviderCatalog['mcpServers'];
28
29
  mcpServerMeta?: Readonly<Record<string, McpServerMeta>>;
@@ -129,7 +129,7 @@ export async function loadHostConfiguration(root, explicitFile, env = process.en
129
129
  break;
130
130
  }
131
131
  const userCatalog = configSource === 'user' ? resolvedCatalog : await readOptionalUserCatalog(env);
132
- const { modes, modePluginSources } = await loadModeConfiguration(env, [
132
+ const { modes, modePluginSources, modePackageDirectories } = await loadModeConfiguration(env, [
133
133
  ...(configSource !== 'user' && userCatalog?.modes
134
134
  ? [
135
135
  {
@@ -198,6 +198,7 @@ export async function loadHostConfiguration(root, explicitFile, env = process.en
198
198
  trustedMcp: trusted,
199
199
  trustedPlugins: trusted,
200
200
  modePluginSources,
201
+ modePackageDirectories,
201
202
  ...(webSearch ? { webSearch } : {}),
202
203
  ...(hasMergedMcp ? { mcpServers: mergedMcpServers, mcpServerMeta } : {}),
203
204
  ...(projectMcp.error ? { mcpJsonError: projectMcp.error } : {}),
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
  }