@saturn-universe/runtime-host 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.
Files changed (40) 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 +2 -1
  4. package/dist/composition.d.ts +20 -56
  5. package/dist/composition.js +316 -89
  6. package/dist/context-extensions.d.ts +132 -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/plugin-loader.d.ts +1 -1
  11. package/dist/cordis/plugin-loader.js +45 -10
  12. package/dist/cordis/sandbox-plugin.d.ts +1 -0
  13. package/dist/cordis/sandbox-plugin.js +1 -0
  14. package/dist/cordis/tools/builtin-agent-tools-plugin.d.ts +2 -2
  15. package/dist/cordis/tools/builtin-agent-tools-plugin.js +27 -3
  16. package/dist/cordis/tools/index.d.ts +5 -1
  17. package/dist/cordis/tools/index.js +3 -3
  18. package/dist/cordis/tools/process-manager-plugin.d.ts +1 -1
  19. package/dist/cordis/tools/process-manager-plugin.js +8 -8
  20. package/dist/cordis/tools/tools-core-plugin.js +54 -11
  21. package/dist/env-probe.js +33 -20
  22. package/dist/host-configuration.d.ts +4 -0
  23. package/dist/host-configuration.js +25 -1
  24. package/dist/index.js +9 -2
  25. package/dist/mode-configuration.d.ts +197 -0
  26. package/dist/mode-configuration.js +109 -0
  27. package/dist/modes.js +52 -10
  28. package/dist/provider-catalog.d.ts +83 -12
  29. package/dist/provider-catalog.js +30 -46
  30. package/dist/run-budget.d.ts +30 -7
  31. package/dist/run-budget.js +49 -5
  32. package/dist/runtime-tuning.d.ts +23 -0
  33. package/dist/runtime-tuning.js +68 -0
  34. package/dist/sandbox-manager.d.ts +2 -0
  35. package/dist/sandbox-manager.js +18 -12
  36. package/dist/session-mode-runtime.d.ts +99 -0
  37. package/dist/session-mode-runtime.js +306 -0
  38. package/dist/skills-runtime.d.ts +5 -2
  39. package/dist/skills-runtime.js +8 -5
  40. package/package.json +9 -9
package/dist/modes.js CHANGED
@@ -4,6 +4,7 @@ import { fileURLToPath } from 'node:url';
4
4
  import { DEFAULT_MODE_REF, resolveModeSelector, RuntimeError } from '@saturn-universe/core';
5
5
  import { readConfiguredPluginGrant } from './plugin-tool-grants.js';
6
6
  import { readConfiguredRunBudget } from './run-budget.js';
7
+ import { readModeCompaction, readModeRetry, resolveRetryPolicy } from './runtime-tuning.js';
7
8
  const CTF_READ_TOOLS = ['ctf_board_status', 'ctf_query_ledger'];
8
9
  const CTF_WRITE_TOOLS = [
9
10
  'ctf_scan_workspace',
@@ -224,12 +225,25 @@ function mergeTools(base, raw) {
224
225
  ? [...baseDenied]
225
226
  : undefined;
226
227
  const permissionMode = raw.tools?.permission_mode ?? base?.permissionMode;
228
+ const roles = { ...base?.roles };
229
+ for (const role of ['main', 'worker']) {
230
+ const filter = raw.tools?.roles?.[role];
231
+ if (!filter)
232
+ continue;
233
+ roles[role] = {
234
+ ...roles[role],
235
+ ...(filter.allowed_tools !== undefined ? { allowedTools: [...filter.allowed_tools] } : {}),
236
+ ...(filter.denied_tools !== undefined ? { deniedTools: [...filter.denied_tools] } : {}),
237
+ };
238
+ }
239
+ const hasRoles = Object.keys(roles).length > 0;
227
240
  if (workspaceTools === undefined &&
228
241
  processManager === undefined &&
229
242
  builtinAgentTools === undefined &&
230
243
  allowedTools === undefined &&
231
244
  deniedTools === undefined &&
232
- permissionMode === undefined)
245
+ permissionMode === undefined &&
246
+ !hasRoles)
233
247
  return undefined;
234
248
  return {
235
249
  ...(workspaceTools !== undefined ? { workspaceTools } : {}),
@@ -238,6 +252,7 @@ function mergeTools(base, raw) {
238
252
  ...(allowedTools !== undefined ? { allowedTools: [...allowedTools] } : {}),
239
253
  ...(deniedTools !== undefined ? { deniedTools: [...deniedTools] } : {}),
240
254
  ...(permissionMode !== undefined ? { permissionMode } : {}),
255
+ ...(hasRoles ? { roles } : {}),
241
256
  };
242
257
  }
243
258
  function mergePlugins(base, raw) {
@@ -345,13 +360,14 @@ function configureMode(ref, raw, builtin) {
345
360
  const base = builtin?.definition;
346
361
  const prompts = mergePrompts(base?.prompts, raw);
347
362
  const tools = mergeTools(base?.tools, raw);
363
+ const mainEffort = raw.reasoning?.main_effort ?? base?.reasoning?.mainEffort;
364
+ const workerEffort = raw.reasoning?.worker_effort ?? base?.reasoning?.workerEffort;
348
365
  const { bindings, toolGrantOverrides } = mergePlugins(base?.plugins, raw.plugins);
349
366
  let plugins = bindings;
350
367
  const ctfOptions = Object.fromEntries([
351
368
  'max_active_challenges',
352
369
  'max_helpers_per_challenge',
353
370
  'per_challenge_wall_time_ms',
354
- 'worker_soft_checkpoint_ms',
355
371
  'board_port',
356
372
  'board_token',
357
373
  'board_public_host',
@@ -363,6 +379,8 @@ function configureMode(ref, raw, builtin) {
363
379
  ]
364
380
  .filter((key) => raw[key] !== undefined)
365
381
  .map((key) => [key, raw[key]]));
382
+ if (ref === 'ctf@1' && raw.worker_soft_checkpoint_ms !== undefined)
383
+ ctfOptions.worker_soft_checkpoint_ms = raw.worker_soft_checkpoint_ms;
366
384
  if (Object.keys(ctfOptions).length) {
367
385
  if (ref !== 'ctf@1')
368
386
  throw new RuntimeError('INVALID_CONFIG', 'CTF settings require ctf@1');
@@ -374,35 +392,54 @@ function configureMode(ref, raw, builtin) {
374
392
  const coordinatorPollIntervalMs = raw.coordinator_poll_interval_ms ??
375
393
  raw.team?.coordinator_poll_interval_ms ??
376
394
  base?.team?.coordinatorPollIntervalMs;
377
- const workerSoftCheckpointMs = raw.worker_soft_checkpoint_ms ?? base?.team?.workerSoftCheckpointMs;
395
+ const workerSoftCheckpointMs = raw.team?.worker_soft_checkpoint_ms ??
396
+ raw.worker_soft_checkpoint_ms ??
397
+ base?.team?.workerSoftCheckpointMs;
378
398
  const ctfPlugin = ref === 'ctf@1' ? plugins?.find((plugin) => plugin.builtin === 'ctf' || plugin.id === 'ctf') : undefined;
379
399
  const rawMaxActive = ctfPlugin?.config?.max_active_challenges;
380
- const maxActiveDepth1 = typeof rawMaxActive === 'number' && Number.isSafeInteger(rawMaxActive) && rawMaxActive >= 1
381
- ? rawMaxActive
382
- : base?.team?.maxActiveDepth1;
400
+ const maxActiveDepth1 = raw.team?.max_active_depth1 ??
401
+ (typeof rawMaxActive === 'number' && Number.isSafeInteger(rawMaxActive) && rawMaxActive >= 1
402
+ ? rawMaxActive
403
+ : base?.team?.maxActiveDepth1);
383
404
  const isContainerSandbox = Boolean(sandbox && sandbox.backend !== 'host' && sandbox.scope !== 'none');
384
- const maxConcurrency = isContainerSandbox
405
+ const sandboxConcurrency = isContainerSandbox
385
406
  ? sandbox?.maxConcurrentContainers !== undefined
386
407
  ? Math.max(1, sandbox.maxConcurrentContainers - 1)
387
408
  : base?.team?.maxConcurrency
388
409
  : undefined;
389
- const team = maxDepth !== undefined ||
410
+ const maxConcurrency = raw.team?.max_concurrency ?? (isContainerSandbox ? base?.team?.maxConcurrency : undefined);
411
+ const defaultConcurrency = raw.team?.default_concurrency ?? base?.team?.defaultConcurrency;
412
+ if (defaultConcurrency !== undefined && maxConcurrency !== undefined && defaultConcurrency > maxConcurrency)
413
+ throw new RuntimeError('INVALID_CONFIG', `Mode ${ref}: team.default_concurrency exceeds team.max_concurrency`);
414
+ const effectiveMaxConcurrency = sandboxConcurrency === undefined
415
+ ? maxConcurrency
416
+ : Math.min(sandboxConcurrency, raw.team?.max_concurrency ?? sandboxConcurrency);
417
+ const defaultPreset = raw.team?.default_preset ?? base?.team?.defaultPreset;
418
+ const team = defaultPreset !== undefined ||
419
+ maxDepth !== undefined ||
390
420
  asyncCoordinator !== undefined ||
391
421
  coordinatorPollIntervalMs !== undefined ||
392
422
  workerSoftCheckpointMs !== undefined ||
393
423
  maxActiveDepth1 !== undefined ||
394
- maxConcurrency !== undefined
424
+ defaultConcurrency !== undefined ||
425
+ effectiveMaxConcurrency !== undefined
395
426
  ? {
396
427
  ...(maxDepth !== undefined ? { maxDepth } : {}),
428
+ ...(defaultPreset !== undefined ? { defaultPreset } : {}),
397
429
  ...(asyncCoordinator !== undefined ? { asyncCoordinator } : {}),
398
430
  ...(coordinatorPollIntervalMs !== undefined ? { coordinatorPollIntervalMs } : {}),
399
431
  ...(workerSoftCheckpointMs !== undefined ? { workerSoftCheckpointMs } : {}),
400
432
  ...(maxActiveDepth1 !== undefined ? { maxActiveDepth1 } : {}),
401
- ...(maxConcurrency !== undefined ? { maxConcurrency } : {}),
433
+ ...(defaultConcurrency !== undefined ? { defaultConcurrency } : {}),
434
+ ...(effectiveMaxConcurrency !== undefined ? { maxConcurrency: effectiveMaxConcurrency } : {}),
402
435
  }
403
436
  : undefined;
404
437
  const budget = { ...builtin?.budget, overrides: readConfiguredRunBudget(raw.limits) };
405
438
  const limits = { ...budget.defaults, ...budget.overrides };
439
+ const retry = raw.retry ? readModeRetry(raw.retry) : base?.retry;
440
+ if (retry)
441
+ resolveRetryPolicy(retry);
442
+ const compaction = raw.compaction ? readModeCompaction(raw.compaction) : base?.compaction;
406
443
  const definition = {
407
444
  ref,
408
445
  displayName: raw.display_name ?? base?.displayName ?? ref,
@@ -414,10 +451,15 @@ function configureMode(ref, raw, builtin) {
414
451
  ...(base?.builtin ? { builtin: true } : {}),
415
452
  ...(prompts ? { prompts } : {}),
416
453
  ...(tools ? { tools } : {}),
454
+ ...(mainEffort || workerEffort
455
+ ? { reasoning: { ...(mainEffort ? { mainEffort } : {}), ...(workerEffort ? { workerEffort } : {}) } }
456
+ : {}),
417
457
  ...(plugins ? { plugins } : {}),
418
458
  ...(sandbox ? { sandbox } : {}),
419
459
  ...(team ? { team } : {}),
420
460
  ...(Object.keys(limits).length ? { limits } : {}),
461
+ ...(retry ? { retry } : {}),
462
+ ...(compaction ? { compaction } : {}),
421
463
  };
422
464
  return { definition, budget, ...(toolGrantOverrides?.size ? { toolGrantOverrides } : {}) };
423
465
  }
@@ -1,16 +1,19 @@
1
1
  import { z } from 'zod';
2
2
  import type { WebSearchConfig } from './user-config.js';
3
- import type { ModelCapabilities, ModelPricing, ModelRef, ProviderProfile, ProviderProtocol, RunConfig, RuntimeLimits } from '@saturn-universe/core';
3
+ import type { HostSubmitInput, ModeDefinition, ModelCapabilities, ModelPricing, ModelRef, ProviderProfile, ProviderProtocol, RunConfig } from '@saturn-universe/core';
4
4
  import { mcpServersSchema } from './mcp-configuration.js';
5
5
  import { modeDefinitionsSchema, skillDefinitionsSchema } from './context-extensions.js';
6
6
  import { type ModeBudgetLayers } from './run-budget.js';
7
+ export { hardLimits } from './run-budget.js';
7
8
  export type ModelPricingConfig = ModelPricing;
8
- export declare const hardLimits: Required<RuntimeLimits>;
9
9
  declare const runDefaults: z.ZodObject<{
10
- model_timeout_ms: z.ZodOptional<z.ZodNumber>;
11
10
  model_idle_timeout_ms: z.ZodOptional<z.ZodNumber>;
12
11
  model_total_timeout_ms: z.ZodOptional<z.ZodNumber>;
12
+ model_timeout_ms: z.ZodOptional<z.ZodNumber>;
13
+ stream_idle_timeout_ms: z.ZodOptional<z.ZodNumber>;
14
+ request_total_timeout_ms: z.ZodOptional<z.ZodNumber>;
13
15
  tool_timeout_ms: z.ZodOptional<z.ZodNumber>;
16
+ shell_timeout_ms: z.ZodOptional<z.ZodNumber>;
14
17
  max_parallel_tools: z.ZodOptional<z.ZodNumber>;
15
18
  max_model_attempts: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
16
19
  max_tool_calls: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
@@ -28,8 +31,8 @@ declare const runDefaults: z.ZodObject<{
28
31
  policy_version: z.ZodOptional<z.ZodString>;
29
32
  tool_set_version: z.ZodOptional<z.ZodString>;
30
33
  planner: z.ZodOptional<z.ZodEnum<{
31
- auto: "auto";
32
34
  off: "off";
35
+ auto: "auto";
33
36
  }>>;
34
37
  search: z.ZodOptional<z.ZodEnum<{
35
38
  off: "off";
@@ -490,10 +493,13 @@ declare const catalogSchema: z.ZodObject<{
490
493
  }][]>>, unknown>>;
491
494
  task_profiles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
492
495
  run_defaults: z.ZodOptional<z.ZodObject<{
493
- model_timeout_ms: z.ZodOptional<z.ZodNumber>;
494
496
  model_idle_timeout_ms: z.ZodOptional<z.ZodNumber>;
495
497
  model_total_timeout_ms: z.ZodOptional<z.ZodNumber>;
498
+ model_timeout_ms: z.ZodOptional<z.ZodNumber>;
499
+ stream_idle_timeout_ms: z.ZodOptional<z.ZodNumber>;
500
+ request_total_timeout_ms: z.ZodOptional<z.ZodNumber>;
496
501
  tool_timeout_ms: z.ZodOptional<z.ZodNumber>;
502
+ shell_timeout_ms: z.ZodOptional<z.ZodNumber>;
497
503
  max_parallel_tools: z.ZodOptional<z.ZodNumber>;
498
504
  max_model_attempts: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
499
505
  max_tool_calls: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
@@ -511,8 +517,8 @@ declare const catalogSchema: z.ZodObject<{
511
517
  policy_version: z.ZodOptional<z.ZodString>;
512
518
  tool_set_version: z.ZodOptional<z.ZodString>;
513
519
  planner: z.ZodOptional<z.ZodEnum<{
514
- auto: "auto";
515
520
  off: "off";
521
+ auto: "auto";
516
522
  }>>;
517
523
  search: z.ZodOptional<z.ZodEnum<{
518
524
  off: "off";
@@ -617,16 +623,48 @@ declare const catalogSchema: z.ZodObject<{
617
623
  }, z.core.$strict>>;
618
624
  }, z.core.$strict>>;
619
625
  tools: z.ZodOptional<z.ZodObject<{
620
- workspace_tools: z.ZodOptional<z.ZodBoolean>;
621
- process_manager: z.ZodOptional<z.ZodBoolean>;
622
- builtin_agent_tools: z.ZodOptional<z.ZodBoolean>;
623
- allowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
624
- denied_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
626
+ roles: z.ZodOptional<z.ZodObject<{
627
+ main: z.ZodOptional<z.ZodObject<{
628
+ allowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
629
+ denied_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
630
+ }, z.core.$strict>>;
631
+ worker: z.ZodOptional<z.ZodObject<{
632
+ allowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
633
+ denied_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
634
+ }, z.core.$strict>>;
635
+ }, z.core.$strict>>;
625
636
  permission_mode: z.ZodOptional<z.ZodEnum<{
626
637
  default: "default";
627
638
  strict: "strict";
628
639
  full: "full";
629
640
  }>>;
641
+ allowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
642
+ denied_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
643
+ workspace_tools: z.ZodOptional<z.ZodBoolean>;
644
+ process_manager: z.ZodOptional<z.ZodBoolean>;
645
+ builtin_agent_tools: z.ZodOptional<z.ZodBoolean>;
646
+ }, z.core.$strict>>;
647
+ reasoning: z.ZodOptional<z.ZodObject<{
648
+ main_effort: z.ZodOptional<z.ZodEnum<{
649
+ low: "low";
650
+ off: "off";
651
+ none: "none";
652
+ minimal: "minimal";
653
+ medium: "medium";
654
+ high: "high";
655
+ xhigh: "xhigh";
656
+ max: "max";
657
+ }>>;
658
+ worker_effort: z.ZodOptional<z.ZodEnum<{
659
+ low: "low";
660
+ off: "off";
661
+ none: "none";
662
+ minimal: "minimal";
663
+ medium: "medium";
664
+ high: "high";
665
+ xhigh: "xhigh";
666
+ max: "max";
667
+ }>>;
630
668
  }, z.core.$strict>>;
631
669
  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<{
632
670
  allowed_tools: z.ZodOptional<z.ZodType<string[], unknown, z.core.$ZodTypeInternals<string[], unknown>>>;
@@ -847,10 +885,21 @@ declare const catalogSchema: z.ZodObject<{
847
885
  }, z.core.$strict>>;
848
886
  team: z.ZodOptional<z.ZodObject<{
849
887
  max_depth: z.ZodOptional<z.ZodNumber>;
888
+ default_concurrency: z.ZodOptional<z.ZodNumber>;
889
+ default_preset: z.ZodOptional<z.ZodString>;
890
+ max_concurrency: z.ZodOptional<z.ZodNumber>;
891
+ max_active_depth1: z.ZodOptional<z.ZodNumber>;
892
+ worker_soft_checkpoint_ms: z.ZodOptional<z.ZodNumber>;
850
893
  async_coordinator: z.ZodOptional<z.ZodBoolean>;
851
894
  coordinator_poll_interval_ms: z.ZodOptional<z.ZodNumber>;
852
895
  }, z.core.$strict>>;
853
896
  limits: z.ZodOptional<z.ZodObject<{
897
+ model_timeout_ms: z.ZodOptional<z.ZodNumber>;
898
+ stream_idle_timeout_ms: z.ZodOptional<z.ZodNumber>;
899
+ request_total_timeout_ms: z.ZodOptional<z.ZodNumber>;
900
+ tool_timeout_ms: z.ZodOptional<z.ZodNumber>;
901
+ shell_timeout_ms: z.ZodOptional<z.ZodNumber>;
902
+ max_parallel_tools: z.ZodOptional<z.ZodNumber>;
854
903
  max_model_attempts: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
855
904
  max_tool_calls: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
856
905
  max_steps: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
@@ -859,6 +908,24 @@ declare const catalogSchema: z.ZodObject<{
859
908
  wall_time_ms: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
860
909
  subagent_wall_time_ms: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
861
910
  }, z.core.$strict>>;
911
+ retry: z.ZodOptional<z.ZodObject<{
912
+ model_max_attempts_per_call: z.ZodOptional<z.ZodNumber>;
913
+ tool_max_attempts_per_call: z.ZodOptional<z.ZodNumber>;
914
+ base_delay_ms: z.ZodOptional<z.ZodNumber>;
915
+ max_delay_ms: z.ZodOptional<z.ZodNumber>;
916
+ }, z.core.$strict>>;
917
+ compaction: z.ZodOptional<z.ZodObject<{
918
+ enabled: z.ZodOptional<z.ZodBoolean>;
919
+ threshold_ratio: z.ZodOptional<z.ZodNumber>;
920
+ max_headroom_tokens: z.ZodOptional<z.ZodNumber>;
921
+ headroom_ratio: z.ZodOptional<z.ZodNumber>;
922
+ min_recent_steps: z.ZodOptional<z.ZodNumber>;
923
+ tail_window_ratio: z.ZodOptional<z.ZodNumber>;
924
+ preflight_window_ratio: z.ZodOptional<z.ZodNumber>;
925
+ max_halvings: z.ZodOptional<z.ZodNumber>;
926
+ min_prefix_chars: z.ZodOptional<z.ZodNumber>;
927
+ summary_timeout_ms: z.ZodOptional<z.ZodNumber>;
928
+ }, z.core.$strict>>;
862
929
  max_active_challenges: z.ZodOptional<z.ZodNumber>;
863
930
  max_helpers_per_challenge: z.ZodOptional<z.ZodNumber>;
864
931
  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>>>;
@@ -944,7 +1011,11 @@ export interface ResolveRunDefaultsOptions {
944
1011
  readonly capabilities?: ModelCapabilities;
945
1012
  readonly profileReasoningEffort?: string;
946
1013
  readonly modeBudget?: ModeBudgetLayers;
1014
+ readonly modeRuntime?: Pick<ModeDefinition, 'retry' | 'compaction'>;
1015
+ readonly overrides?: Pick<NonNullable<HostSubmitInput['config']>, 'limits' | 'retry' | 'compaction'>;
947
1016
  }
948
1017
  export declare function resolveRunDefaults(model: ModelRef, defaults?: ProviderCatalog['runDefaults'], options?: ResolveRunDefaultsOptions): RunConfig;
949
1018
  export declare function resolveWorkerReasoning(config: RunConfig, capabilities?: ModelCapabilities): RunConfig;
950
- export {};
1019
+ export declare function resolveDefaultReasoning(defaults?: ProviderCatalog['runDefaults'], options?: Pick<ResolveRunDefaultsOptions, 'capabilities' | 'profileReasoningEffort'> & {
1020
+ readonly modeMainReasoningEffort?: string;
1021
+ }): RunConfig['responses']['reasoning'] | undefined;
@@ -3,12 +3,13 @@ import { webSearchConfig } from './user-config.js';
3
3
  import { parse, stringify } from 'smol-toml';
4
4
  import { DEFAULT_MODE_REF, RuntimeError, lookupModelMetadata, openCodeClientHeaders, providerPresets, validateTeamConfig, validateWorkSubpath, } from '@saturn-universe/core';
5
5
  import { credentialRefSchema, providerBaseUrlSchema, providerIdSchema, providerModelIdSchema, providerModelRouteSchema, } from '@saturn-universe/protocol';
6
- import { maxShellTimeoutMs } from '@saturn-universe/tools';
7
6
  import { capabilities, defaultCapabilities } from './configuration.js';
8
7
  import { mcpServersSchema } from './mcp-configuration.js';
9
8
  import { modeDefinitionsSchema, skillDefinitionsSchema } from './context-extensions.js';
10
9
  import { configurationTable } from './plugin-configuration.js';
11
- import { configuredRunBudgetShape, resolveRunBudget } from './run-budget.js';
10
+ import { configuredRunBudgetShape, hardLimits, resolveRunBudget, } from './run-budget.js';
11
+ import { resolveRetryPolicy } from './runtime-tuning.js';
12
+ export { hardLimits } from './run-budget.js';
12
13
  const id = z.string().trim().min(1).max(200);
13
14
  const positive = z.number().int().positive().safe();
14
15
  const nonnegativeNumber = z.number().nonnegative().finite();
@@ -32,21 +33,6 @@ const profile = z
32
33
  pricing: pricingSchema.optional(),
33
34
  })
34
35
  .refine((value) => value.codec_version !== 2 || value.revision !== '1');
35
- export const hardLimits = {
36
- maxModelAttempts: 10000,
37
- maxToolCalls: 10000,
38
- maxSteps: 20000,
39
- maxTotalTokens: 10000000,
40
- subagentMaxModelAttempts: 10000,
41
- wallTimeMs: 86400000,
42
- subagentWallTimeMs: 86400000,
43
- modelTimeoutMs: 600000,
44
- streamIdleTimeoutMs: 600000,
45
- requestTotalTimeoutMs: 600000,
46
- toolTimeoutMs: 600000,
47
- shellTimeoutMs: maxShellTimeoutMs,
48
- maxParallelTools: 64,
49
- };
50
36
  const runDefaults = z.strictObject({
51
37
  mode_ref: id.optional(),
52
38
  permission_mode: z.enum(['strict', 'default', 'full']).optional(),
@@ -58,11 +44,8 @@ const runDefaults = z.strictObject({
58
44
  worker_reasoning_effort: id.optional(),
59
45
  reasoning_summary: z.enum(['auto', 'concise', 'detailed']).optional(),
60
46
  ...configuredRunBudgetShape(hardLimits),
61
- model_timeout_ms: positive.max(hardLimits.modelTimeoutMs).optional(),
62
47
  model_idle_timeout_ms: positive.max(hardLimits.streamIdleTimeoutMs).optional(),
63
48
  model_total_timeout_ms: positive.max(hardLimits.requestTotalTimeoutMs).optional(),
64
- tool_timeout_ms: positive.max(hardLimits.toolTimeoutMs).optional(),
65
- max_parallel_tools: positive.max(hardLimits.maxParallelTools).optional(),
66
49
  });
67
50
  const teamPresetSchema = z.strictObject({
68
51
  concurrency: positive.max(16).optional(),
@@ -177,7 +160,7 @@ export function parseProviderCatalog(value) {
177
160
  for (const modelId of models)
178
161
  profiles.push(expandProfile(providerId, modelId, value));
179
162
  }
180
- if (!data.providers && !data.profiles)
163
+ if (!data.providers && !data.profiles && !data.modes)
181
164
  throw invalid();
182
165
  const names = new Set();
183
166
  const identities = new Set();
@@ -415,6 +398,13 @@ export function selectProfile(catalog, selection) {
415
398
  }
416
399
  export function resolveRunDefaults(model, defaults, options) {
417
400
  const reasoning = resolveDefaultReasoning(defaults, options);
401
+ const limits = resolveRunBudget(defaults && {
402
+ ...defaults,
403
+ stream_idle_timeout_ms: defaults.stream_idle_timeout_ms ?? defaults.model_idle_timeout_ms,
404
+ request_total_timeout_ms: defaults.request_total_timeout_ms ?? defaults.model_total_timeout_ms,
405
+ }, options?.modeBudget, options?.overrides?.limits);
406
+ const modeCompaction = options?.modeRuntime?.compaction;
407
+ const explicitCompaction = options?.overrides?.compaction;
418
408
  return {
419
409
  model,
420
410
  modeRef: defaults?.mode_ref ?? DEFAULT_MODE_REF,
@@ -426,45 +416,39 @@ export function resolveRunDefaults(model, defaults, options) {
426
416
  storage: 'local_stateless',
427
417
  ...(reasoning ? { reasoning } : {}),
428
418
  },
429
- retry: { modelMaxAttemptsPerCall: 3, toolMaxAttemptsPerCall: 1, baseDelayMs: 2000, maxDelayMs: 5000 },
430
- limits: {
431
- ...resolveRunBudget(defaults, options?.modeBudget),
432
- modelTimeoutMs: defaults?.model_timeout_ms ?? 300000,
433
- ...(defaults?.model_idle_timeout_ms !== undefined
434
- ? { streamIdleTimeoutMs: defaults.model_idle_timeout_ms }
435
- : {}),
436
- ...(defaults?.model_total_timeout_ms !== undefined
437
- ? { requestTotalTimeoutMs: defaults.model_total_timeout_ms }
438
- : {}),
439
- toolTimeoutMs: defaults?.tool_timeout_ms ?? 30000,
440
- ...(defaults?.tool_timeout_ms === undefined ? { shellTimeoutMs: maxShellTimeoutMs } : {}),
441
- maxParallelTools: defaults?.max_parallel_tools ?? 4,
442
- },
419
+ limits,
420
+ retry: resolveRetryPolicy(options?.modeRuntime?.retry, options?.overrides?.retry),
421
+ ...(modeCompaction || explicitCompaction
422
+ ? { compaction: { ...modeCompaction, ...explicitCompaction } }
423
+ : {}),
443
424
  };
444
425
  }
445
426
  export function resolveWorkerReasoning(config, capabilities) {
446
- const effort = config.workerReasoningEffort;
447
- const responses = capabilities?.responses;
448
- if (!effort)
427
+ const defaults = config.workerReasoningDefaults;
428
+ const effort = (defaults?.explicitEffort ? undefined : defaults?.modeEffort) ?? config.workerReasoningEffort;
429
+ if (!effort && !defaults)
449
430
  return config;
450
- if (effort === 'off' || effort === 'none') {
451
- const { reasoning: _removed, ...restResponses } = config.responses;
431
+ const { reasoning, ...restResponses } = config.responses;
432
+ const fallback = defaults ? defaults.reasoning : reasoning;
433
+ const baseResponses = { ...restResponses, ...(fallback ? { reasoning: fallback } : {}) };
434
+ const responses = capabilities?.responses;
435
+ if (effort === 'off' || effort === 'none')
452
436
  return { ...config, responses: restResponses };
453
- }
454
- if (!responses?.reasoningModel ||
437
+ if (!effort ||
438
+ !responses?.reasoningModel ||
455
439
  (responses.reasoningEfforts.length > 0 && !responses.reasoningEfforts.includes(effort)))
456
- return config;
440
+ return { ...config, responses: baseResponses };
457
441
  return {
458
442
  ...config,
459
- responses: { ...config.responses, reasoning: { ...config.responses.reasoning, effort } },
443
+ responses: { ...baseResponses, reasoning: { ...fallback, effort } },
460
444
  };
461
445
  }
462
- function resolveDefaultReasoning(defaults, options) {
446
+ export function resolveDefaultReasoning(defaults, options) {
463
447
  const caps = options?.capabilities?.responses;
464
448
  if (!caps?.reasoningModel)
465
449
  return undefined;
466
450
  const supportedEfforts = caps.reasoningEfforts;
467
- const requestedEffort = defaults?.reasoning_effort ?? options?.profileReasoningEffort;
451
+ const requestedEffort = options?.modeMainReasoningEffort ?? defaults?.reasoning_effort ?? options?.profileReasoningEffort;
468
452
  if (requestedEffort === 'off' || requestedEffort === 'none')
469
453
  return undefined;
470
454
  const effort = requestedEffort && (!supportedEfforts.length || supportedEfforts.includes(requestedEffort))
@@ -1,5 +1,6 @@
1
- import type { ModeLimitsConfig, RuntimeLimits } from '@saturn-universe/core';
1
+ import type { ModeLimitsConfig, RuntimeLimits, RuntimeTimingLimits } from '@saturn-universe/core';
2
2
  import { z } from 'zod';
3
+ export declare const hardLimits: Required<RuntimeLimits>;
3
4
  declare const budgetFields: {
4
5
  readonly maxModelAttempts: "max_model_attempts";
5
6
  readonly maxToolCalls: "max_tool_calls";
@@ -9,16 +10,38 @@ declare const budgetFields: {
9
10
  readonly wallTimeMs: "wall_time_ms";
10
11
  readonly subagentWallTimeMs: "subagent_wall_time_ms";
11
12
  };
12
- type BudgetField = keyof typeof budgetFields;
13
- type ConfiguredBudgetField = (typeof budgetFields)[BudgetField];
14
- type ConfiguredRunBudget = Partial<Record<ConfiguredBudgetField, number | undefined>>;
15
- type ConfiguredBudgetShape = Record<ConfiguredBudgetField, z.ZodOptional<ReturnType<typeof unlimitedInt>>>;
13
+ declare const timingFields: {
14
+ readonly modelTimeoutMs: "model_timeout_ms";
15
+ readonly streamIdleTimeoutMs: "stream_idle_timeout_ms";
16
+ readonly requestTotalTimeoutMs: "request_total_timeout_ms";
17
+ readonly toolTimeoutMs: "tool_timeout_ms";
18
+ readonly shellTimeoutMs: "shell_timeout_ms";
19
+ readonly maxParallelTools: "max_parallel_tools";
20
+ };
21
+ type ConfiguredBudgetField = (typeof budgetFields)[keyof typeof budgetFields];
22
+ type ConfiguredTimingField = (typeof timingFields)[keyof typeof timingFields];
23
+ type ConfiguredRunBudget = Partial<Record<ConfiguredBudgetField | ConfiguredTimingField, number | undefined>>;
16
24
  export declare function unlimitedInt(max?: number): z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>;
17
- export declare function configuredRunBudgetShape(maximums?: Required<ModeLimitsConfig>): ConfiguredBudgetShape;
25
+ export declare function configuredRunBudgetShape(maximums?: Required<RuntimeLimits>): {
26
+ model_timeout_ms: z.ZodOptional<z.ZodNumber>;
27
+ stream_idle_timeout_ms: z.ZodOptional<z.ZodNumber>;
28
+ request_total_timeout_ms: z.ZodOptional<z.ZodNumber>;
29
+ tool_timeout_ms: z.ZodOptional<z.ZodNumber>;
30
+ shell_timeout_ms: z.ZodOptional<z.ZodNumber>;
31
+ max_parallel_tools: z.ZodOptional<z.ZodNumber>;
32
+ max_model_attempts: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
33
+ max_tool_calls: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
34
+ max_steps: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
35
+ max_total_tokens: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
36
+ subagent_max_model_attempts: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
37
+ wall_time_ms: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
38
+ subagent_wall_time_ms: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>>;
39
+ };
18
40
  export interface ModeBudgetLayers {
19
41
  readonly defaults?: ModeLimitsConfig;
20
42
  readonly overrides?: ModeLimitsConfig;
21
43
  }
22
44
  export declare function readConfiguredRunBudget(raw: ConfiguredRunBudget | undefined): ModeLimitsConfig;
23
- export declare function resolveRunBudget(rawDefaults: ConfiguredRunBudget | undefined, modeBudget?: ModeBudgetLayers): Pick<RuntimeLimits, keyof ModeLimitsConfig>;
45
+ export declare function explicitTimingLimits(limits: Partial<RuntimeLimits> | undefined): Partial<RuntimeTimingLimits> | undefined;
46
+ export declare function resolveRunBudget(rawDefaults: ConfiguredRunBudget | undefined, modeBudget?: ModeBudgetLayers, explicitLimits?: Partial<RuntimeLimits>): RuntimeLimits;
24
47
  export {};
@@ -1,5 +1,21 @@
1
1
  import { DEFAULT_SUBAGENT_MAX_MODEL_ATTEMPTS, DEFAULT_SUBAGENT_WALL_TIME_MS, isLimited, } from '@saturn-universe/core';
2
+ import { maxPluginTimeoutMs, maxShellTimeoutMs } from '@saturn-universe/tools';
2
3
  import { z } from 'zod';
4
+ export const hardLimits = {
5
+ maxModelAttempts: 10000,
6
+ maxToolCalls: 10000,
7
+ maxSteps: 20000,
8
+ maxTotalTokens: 10000000,
9
+ subagentMaxModelAttempts: 10000,
10
+ wallTimeMs: 86400000,
11
+ subagentWallTimeMs: 86400000,
12
+ modelTimeoutMs: 600000,
13
+ streamIdleTimeoutMs: 600000,
14
+ requestTotalTimeoutMs: 600000,
15
+ toolTimeoutMs: maxPluginTimeoutMs,
16
+ shellTimeoutMs: maxShellTimeoutMs,
17
+ maxParallelTools: 64,
18
+ };
3
19
  const budgetFields = {
4
20
  maxModelAttempts: 'max_model_attempts',
5
21
  maxToolCalls: 'max_tool_calls',
@@ -9,7 +25,16 @@ const budgetFields = {
9
25
  wallTimeMs: 'wall_time_ms',
10
26
  subagentWallTimeMs: 'subagent_wall_time_ms',
11
27
  };
28
+ const timingFields = {
29
+ modelTimeoutMs: 'model_timeout_ms',
30
+ streamIdleTimeoutMs: 'stream_idle_timeout_ms',
31
+ requestTotalTimeoutMs: 'request_total_timeout_ms',
32
+ toolTimeoutMs: 'tool_timeout_ms',
33
+ shellTimeoutMs: 'shell_timeout_ms',
34
+ maxParallelTools: 'max_parallel_tools',
35
+ };
12
36
  const budgetKeys = Object.keys(budgetFields);
37
+ const timingKeys = Object.keys(timingFields);
13
38
  export function unlimitedInt(max) {
14
39
  const integer = z.number().int().min(0).safe();
15
40
  return z
@@ -17,24 +42,37 @@ export function unlimitedInt(max) {
17
42
  .transform((value) => (value === 'unlimited' || value === null ? 0 : value));
18
43
  }
19
44
  export function configuredRunBudgetShape(maximums) {
20
- return Object.fromEntries(budgetKeys.map((field) => [budgetFields[field], unlimitedInt(maximums?.[field]).optional()]));
45
+ const unlimitedFields = Object.fromEntries(budgetKeys.map((field) => [budgetFields[field], unlimitedInt(maximums?.[field]).optional()]));
46
+ const positive = z.number().int().positive().safe();
47
+ const timedFields = Object.fromEntries(timingKeys.map((field) => [timingFields[field], positive.max(hardLimits[field]).optional()]));
48
+ return { ...unlimitedFields, ...timedFields };
21
49
  }
22
50
  export function readConfiguredRunBudget(raw) {
51
+ const fields = { ...budgetFields, ...timingFields };
23
52
  const budget = {};
24
- for (const field of budgetKeys) {
25
- const value = raw?.[budgetFields[field]];
53
+ for (const field of [...budgetKeys, ...timingKeys]) {
54
+ const value = raw?.[fields[field]];
26
55
  if (value !== undefined)
27
56
  budget[field] = value;
28
57
  }
29
58
  return budget;
30
59
  }
31
- export function resolveRunBudget(rawDefaults, modeBudget) {
60
+ export function explicitTimingLimits(limits) {
61
+ const entries = timingKeys.flatMap((key) => {
62
+ const value = limits?.[key];
63
+ return value === undefined ? [] : [[key, value]];
64
+ });
65
+ return entries.length ? Object.fromEntries(entries) : undefined;
66
+ }
67
+ export function resolveRunBudget(rawDefaults, modeBudget, explicitLimits) {
32
68
  const budget = {
33
69
  ...modeBudget?.defaults,
34
70
  ...readConfiguredRunBudget(rawDefaults),
35
71
  ...modeBudget?.overrides,
72
+ ...explicitLimits,
36
73
  };
37
- const { wallTimeMs } = budget;
74
+ const { wallTimeMs, toolTimeoutMs, streamIdleTimeoutMs, requestTotalTimeoutMs } = budget;
75
+ const shellTimeoutMs = budget.shellTimeoutMs ?? (toolTimeoutMs === undefined ? maxShellTimeoutMs : undefined);
38
76
  return {
39
77
  maxModelAttempts: budget.maxModelAttempts ?? 0,
40
78
  maxToolCalls: budget.maxToolCalls ?? 0,
@@ -43,5 +81,11 @@ export function resolveRunBudget(rawDefaults, modeBudget) {
43
81
  subagentMaxModelAttempts: budget.subagentMaxModelAttempts ?? DEFAULT_SUBAGENT_MAX_MODEL_ATTEMPTS,
44
82
  ...(isLimited(wallTimeMs) ? { wallTimeMs } : {}),
45
83
  subagentWallTimeMs: budget.subagentWallTimeMs ?? DEFAULT_SUBAGENT_WALL_TIME_MS,
84
+ modelTimeoutMs: budget.modelTimeoutMs ?? 300000,
85
+ ...(streamIdleTimeoutMs !== undefined ? { streamIdleTimeoutMs } : {}),
86
+ ...(requestTotalTimeoutMs !== undefined ? { requestTotalTimeoutMs } : {}),
87
+ toolTimeoutMs: toolTimeoutMs ?? 30000,
88
+ ...(shellTimeoutMs !== undefined ? { shellTimeoutMs } : {}),
89
+ maxParallelTools: budget.maxParallelTools ?? 4,
46
90
  };
47
91
  }
@@ -0,0 +1,23 @@
1
+ import type { AutoCompactionOptions, RetryPolicy } from '@saturn-universe/core';
2
+ import { z } from 'zod';
3
+ export declare const modeRetrySchema: z.ZodObject<{
4
+ model_max_attempts_per_call: z.ZodOptional<z.ZodNumber>;
5
+ tool_max_attempts_per_call: z.ZodOptional<z.ZodNumber>;
6
+ base_delay_ms: z.ZodOptional<z.ZodNumber>;
7
+ max_delay_ms: z.ZodOptional<z.ZodNumber>;
8
+ }, z.core.$strict>;
9
+ export declare const modeCompactionSchema: z.ZodObject<{
10
+ enabled: z.ZodOptional<z.ZodBoolean>;
11
+ threshold_ratio: z.ZodOptional<z.ZodNumber>;
12
+ max_headroom_tokens: z.ZodOptional<z.ZodNumber>;
13
+ headroom_ratio: z.ZodOptional<z.ZodNumber>;
14
+ min_recent_steps: z.ZodOptional<z.ZodNumber>;
15
+ tail_window_ratio: z.ZodOptional<z.ZodNumber>;
16
+ preflight_window_ratio: z.ZodOptional<z.ZodNumber>;
17
+ max_halvings: z.ZodOptional<z.ZodNumber>;
18
+ min_prefix_chars: z.ZodOptional<z.ZodNumber>;
19
+ summary_timeout_ms: z.ZodOptional<z.ZodNumber>;
20
+ }, z.core.$strict>;
21
+ export declare function readModeRetry(raw: z.output<typeof modeRetrySchema>): Partial<RetryPolicy>;
22
+ export declare function resolveRetryPolicy(mode?: Partial<RetryPolicy>, explicit?: Partial<RetryPolicy>): RetryPolicy;
23
+ export declare function readModeCompaction(raw: z.output<typeof modeCompactionSchema>): AutoCompactionOptions;