@saturn-universe/core 0.1.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.
@@ -39,6 +39,7 @@ export interface Session {
39
39
  readonly title: string;
40
40
  readonly status: 'open' | 'archived';
41
41
  readonly createdAt: ISODateTime;
42
+ readonly modeRef?: string;
42
43
  }
43
44
  export type AgentSessionScope = 'run' | 'session' | 'project';
44
45
  export type AgentSessionOwner = {
@@ -119,14 +120,21 @@ export interface ModePromptsConfig {
119
120
  readonly worker?: readonly ModeRolePromptSection[];
120
121
  }>;
121
122
  }
122
- export interface ModeToolsConfig {
123
+ export interface ModeToolFilter {
124
+ readonly allowedTools?: readonly string[];
125
+ readonly deniedTools?: readonly string[];
126
+ }
127
+ export interface ModeToolsConfig extends ModeToolFilter {
123
128
  readonly workspaceTools?: boolean;
124
129
  readonly processManager?: boolean;
125
130
  readonly builtinAgentTools?: boolean;
126
- readonly allowedTools?: readonly string[];
127
- readonly deniedTools?: readonly string[];
131
+ readonly roles?: Readonly<Partial<Record<'main' | 'worker', ModeToolFilter>>>;
128
132
  readonly permissionMode?: PermissionMode;
129
133
  }
134
+ export interface ModeReasoningConfig {
135
+ readonly mainEffort?: string;
136
+ readonly workerEffort?: string;
137
+ }
130
138
  export interface ModePluginToolsGrant {
131
139
  readonly allowedTools: readonly string[];
132
140
  readonly readOnlyTools?: readonly string[];
@@ -195,17 +203,11 @@ export interface ModeTeamConfig {
195
203
  readonly coordinatorPollIntervalMs?: number;
196
204
  readonly workerSoftCheckpointMs?: number;
197
205
  readonly maxActiveDepth1?: number;
206
+ readonly defaultConcurrency?: number;
198
207
  readonly maxConcurrency?: number;
208
+ readonly defaultPreset?: string;
199
209
  }
200
- export interface ModeLimitsConfig {
201
- readonly maxModelAttempts?: number;
202
- readonly maxToolCalls?: number;
203
- readonly maxSteps?: number;
204
- readonly maxTotalTokens?: number;
205
- readonly subagentMaxModelAttempts?: number;
206
- readonly wallTimeMs?: number;
207
- readonly subagentWallTimeMs?: number;
208
- }
210
+ export type ModeLimitsConfig = Partial<RuntimeLimits>;
209
211
  export interface ModeDefinition {
210
212
  readonly ref: string;
211
213
  readonly displayName: string;
@@ -213,10 +215,13 @@ export interface ModeDefinition {
213
215
  readonly builtin?: boolean;
214
216
  readonly prompts?: ModePromptsConfig;
215
217
  readonly tools?: ModeToolsConfig;
218
+ readonly reasoning?: ModeReasoningConfig;
216
219
  readonly plugins?: readonly ModePluginBinding[];
217
220
  readonly sandbox?: SandboxConfig;
218
221
  readonly team?: ModeTeamConfig;
219
222
  readonly limits?: ModeLimitsConfig;
223
+ readonly retry?: Partial<RetryPolicy>;
224
+ readonly compaction?: AutoCompactionOptions;
220
225
  }
221
226
  export interface ModeSummary {
222
227
  readonly ref: string;
@@ -232,15 +237,15 @@ export interface RunConfig {
232
237
  readonly coordinatorPollIntervalMs?: number;
233
238
  readonly workerSoftCheckpointMs?: number;
234
239
  readonly teamMaxActiveDepth1?: number;
240
+ readonly teamDefaultConcurrency?: number;
235
241
  readonly teamMaxConcurrency?: number;
236
242
  readonly teamHint?: TeamHintConfig;
237
243
  readonly planner?: PlannerConfig;
238
244
  readonly contextExtensions?: {
239
- readonly mode?: {
245
+ readonly mode?: ModeToolFilter & {
240
246
  readonly ref: string;
241
247
  readonly instructions: string;
242
- readonly allowedTools?: readonly string[];
243
- readonly deniedTools?: readonly string[];
248
+ readonly toolRoles?: ModeToolsConfig['roles'];
244
249
  };
245
250
  readonly skills: readonly FrozenSkill[];
246
251
  };
@@ -252,9 +257,20 @@ export interface RunConfig {
252
257
  readonly toolSetVersion: string;
253
258
  readonly streamText?: boolean;
254
259
  readonly workerReasoningEffort?: string;
260
+ readonly workerReasoningDefaults?: {
261
+ readonly reasoning: NonNullable<ResponsesRequestOptions['reasoning']> | null;
262
+ readonly modeEffort?: string;
263
+ readonly explicitEffort?: true;
264
+ };
255
265
  readonly disabledSkills?: readonly string[];
256
266
  readonly limits: RuntimeLimits;
257
267
  readonly retry: RetryPolicy;
268
+ readonly compaction?: AutoCompactionOptions;
269
+ readonly runtimeOverrides?: {
270
+ readonly limits?: Partial<RuntimeTimingLimits>;
271
+ readonly retry?: Partial<RetryPolicy>;
272
+ readonly compaction?: AutoCompactionOptions;
273
+ };
258
274
  readonly responses: ResponsesRequestOptions;
259
275
  readonly continuation?: RunContinuationConfig;
260
276
  readonly search?: TreeSearchConfig;
@@ -412,6 +428,7 @@ export interface TeamMemberConfig {
412
428
  readonly task: string;
413
429
  readonly sandboxProfile?: WorkerSandboxProfile;
414
430
  readonly workSubpath?: string;
431
+ readonly modeRef?: string;
415
432
  }
416
433
  export interface TeamState {
417
434
  readonly runId: RunId;
@@ -426,13 +443,18 @@ export interface TeamMemberState {
426
443
  readonly parent: string | null;
427
444
  readonly agentSessionId: AgentSessionId;
428
445
  readonly turnId?: TurnId;
429
- readonly status: 'waiting' | TurnStatus;
446
+ readonly status: TeamMemberStatus;
447
+ readonly stopRequest?: {
448
+ readonly requestedBy: 'main';
449
+ readonly reason: string;
450
+ };
430
451
  }
452
+ export type TeamMemberStatus = 'waiting' | 'stopped' | TurnStatus;
431
453
  export interface TeamTaskState {
432
454
  readonly memberId: string;
433
455
  readonly task: string;
434
456
  readonly turnId?: TurnId;
435
- readonly status: 'waiting' | TurnStatus;
457
+ readonly status: TeamMemberStatus;
436
458
  readonly resultMessageId?: MessageId;
437
459
  }
438
460
  export interface TeamInboxMessage {
@@ -457,6 +479,18 @@ export interface RetryPolicy {
457
479
  readonly baseDelayMs: number;
458
480
  readonly maxDelayMs: number;
459
481
  }
482
+ export interface AutoCompactionOptions {
483
+ readonly enabled?: boolean;
484
+ readonly thresholdRatio?: number;
485
+ readonly maxHeadroomTokens?: number;
486
+ readonly headroomRatio?: number;
487
+ readonly minRecentSteps?: number;
488
+ readonly tailWindowRatio?: number;
489
+ readonly preflightWindowRatio?: number;
490
+ readonly maxHalvings?: number;
491
+ readonly minPrefixChars?: number;
492
+ readonly summaryTimeoutMs?: number;
493
+ }
460
494
  export interface RuntimeLimits {
461
495
  readonly maxModelAttempts: number;
462
496
  readonly maxToolCalls: number;
@@ -469,10 +503,11 @@ export interface RuntimeLimits {
469
503
  readonly streamIdleTimeoutMs?: number;
470
504
  readonly requestTotalTimeoutMs?: number;
471
505
  readonly toolTimeoutMs: number;
472
- /** Host limit for built-in shell when no global tool timeout was configured. */
506
+ /** Built-in shell timeout. Falls back to the tool timeout if omitted. */
473
507
  readonly shellTimeoutMs?: number;
474
508
  readonly maxParallelTools: number;
475
509
  }
510
+ export type RuntimeTimingLimits = Pick<RuntimeLimits, 'modelTimeoutMs' | 'streamIdleTimeoutMs' | 'requestTotalTimeoutMs' | 'toolTimeoutMs' | 'shellTimeoutMs' | 'maxParallelTools'>;
476
511
  export declare const turnStatuses: readonly ["queued", "running", "paused", "completed", "failed", "interrupted"];
477
512
  export type TurnStatus = (typeof turnStatuses)[number];
478
513
  export interface Turn {
@@ -635,12 +670,12 @@ export interface StreamRef {
635
670
  readonly id: string;
636
671
  }
637
672
  export type WorkspaceEventType = 'workspace.created' | 'workspace.archived' | 'agent.created';
638
- export type SessionEventType = 'session.created' | 'session.archived' | 'session.agent.bound';
673
+ export type SessionEventType = 'session.created' | 'session.archived' | 'session.agent.bound' | 'session.mode.selected';
639
674
  export declare const terminalRunEventTypes: readonly ("run.completed" | "run.failed" | "run.cancelled")[];
640
675
  export type TerminalRunEventType = (typeof terminalRunEventTypes)[number];
641
676
  export declare function isTerminalRunEventType(value: unknown): value is TerminalRunEventType;
642
677
  export type RunTransition = 'run.started' | 'run.paused' | 'run.resumed' | 'run.cancel_requested' | TerminalRunEventType;
643
- export type RunEventType = 'run.created' | 'run.agent.attached' | 'run.team.planned' | 'run.team.message.sent' | 'run.team.message.read' | 'run.search.started' | 'run.search.branch.created' | 'run.search.branch.evaluated' | 'run.search.converged' | 'run.plugin.availability' | RunTransition;
678
+ export type RunEventType = 'run.created' | 'run.agent.attached' | 'run.team.planned' | 'run.team.member.stop_requested' | 'run.team.message.sent' | 'run.team.message.read' | 'run.search.started' | 'run.search.branch.created' | 'run.search.branch.evaluated' | 'run.search.converged' | 'run.plugin.availability' | RunTransition;
644
679
  export type ScopeFor<K> = K extends WorkspaceEventType ? WorkspaceScope : K extends SessionEventType ? SessionScope : K extends RunEventType ? RunScope : K extends 'agent_session.created' | 'agent_session.archived' | 'surface.compacted' ? AgentSessionEventScope : AgentExecutionScope;
645
680
  export interface EventMetadata {
646
681
  readonly actor: {
@@ -693,6 +728,9 @@ export interface EventDataMap {
693
728
  'session.archived': {
694
729
  readonly reason: string;
695
730
  };
731
+ 'session.mode.selected': {
732
+ readonly modeRef: string;
733
+ };
696
734
  'agent_session.created': {
697
735
  readonly agentSession: AgentSession;
698
736
  };
@@ -719,6 +757,13 @@ export interface EventDataMap {
719
757
  readonly verificationCriteria?: readonly string[];
720
758
  readonly team?: TeamConfig;
721
759
  };
760
+ 'run.team.member.stop_requested': {
761
+ readonly memberId: string;
762
+ readonly turnId: TurnId;
763
+ readonly requesterAgentSessionId: AgentSessionId;
764
+ readonly requestedBy: 'main';
765
+ readonly reason: string;
766
+ };
722
767
  'run.team.message.sent': {
723
768
  readonly messageId: string;
724
769
  readonly from: string;
@@ -828,6 +873,7 @@ export interface EventDataMap {
828
873
  };
829
874
  'turn.interrupted': {
830
875
  readonly turnId: TurnId;
876
+ readonly stoppedByMain?: true;
831
877
  readonly reason: 'cancelled' | 'timeout' | 'limit';
832
878
  readonly usage: Usage;
833
879
  readonly unresolvedCallIds: readonly ToolCallId[];
@@ -850,6 +896,7 @@ export interface EventDataMap {
850
896
  'message.user.added': {
851
897
  readonly message: UserMessage;
852
898
  readonly steering?: true;
899
+ readonly steeringSource?: 'main';
853
900
  };
854
901
  'message.assistant.added': {
855
902
  readonly message: AssistantMessage;
@@ -1156,6 +1203,7 @@ export interface PersistedResponsesHistoryPlan {
1156
1203
  readonly initialSystemPrompt?: string;
1157
1204
  readonly initialBackground?: readonly BackgroundHistoryMessage[];
1158
1205
  readonly prunedToolResults?: boolean;
1206
+ readonly projectedToolHistory?: true;
1159
1207
  readonly fullInputDigest: string;
1160
1208
  readonly configurationDigest: string;
1161
1209
  readonly backgroundDigest?: string;
@@ -1198,6 +1246,8 @@ export interface HistorySelection {
1198
1246
  }
1199
1247
  export interface HistoryBuildInput {
1200
1248
  readonly surface: SessionSurface;
1249
+ readonly modeRef?: string;
1250
+ readonly historicalRunModes?: Readonly<Record<string, string>>;
1201
1251
  readonly model: ModelRef;
1202
1252
  readonly binding: ProviderBinding;
1203
1253
  readonly capabilities: ModelCapabilities;
@@ -1250,6 +1300,7 @@ export interface ProviderProfile {
1250
1300
  readonly codecId: string;
1251
1301
  readonly codecVersion: number;
1252
1302
  readonly models: Readonly<Record<string, ModelCapabilities>>;
1303
+ readonly modelRoutes?: Readonly<Record<string, Partial<Pick<ProviderProfile, 'protocol' | 'baseURL'>>>>;
1253
1304
  }
1254
1305
  export interface ProviderBinding {
1255
1306
  readonly profileId: string;
@@ -1820,6 +1871,7 @@ export interface ContextStateSnapshot {
1820
1871
  readonly surface: SessionSurface;
1821
1872
  readonly runState: RunState;
1822
1873
  readonly activeRequest?: PersistedModelRequest;
1874
+ readonly historicalRunModes?: Readonly<Record<string, string>>;
1823
1875
  readonly teamReports?: readonly {
1824
1876
  readonly from: string;
1825
1877
  readonly text: string;
@@ -2094,7 +2146,10 @@ export interface ProtocolRequest {
2094
2146
  readonly command: RuntimeCommand;
2095
2147
  }
2096
2148
  export type HostSubmitInput = Omit<SubmitTask, 'commandId' | 'config' | 'plannerConfig'> & {
2097
- readonly config?: Partial<Omit<RunConfig, 'providerBinding' | 'contextExtensions' | 'toolSnapshot' | 'pluginBindings' | 'checkpoint'>>;
2149
+ readonly config?: Partial<Omit<RunConfig, 'providerBinding' | 'contextExtensions' | 'toolSnapshot' | 'pluginBindings' | 'checkpoint' | 'workerReasoningDefaults' | 'limits' | 'retry' | 'runtimeOverrides'>> & {
2150
+ readonly limits?: Partial<RuntimeLimits>;
2151
+ readonly retry?: Partial<RetryPolicy>;
2152
+ };
2098
2153
  readonly skillRefs?: readonly string[];
2099
2154
  readonly model?: ModelRef;
2100
2155
  readonly profile?: string;
@@ -2107,6 +2162,10 @@ export type HostSubmitInput = Omit<SubmitTask, 'commandId' | 'config' | 'planner
2107
2162
  export type HostCommand = Exclude<RuntimeCommand, {
2108
2163
  readonly type: 'run.submit' | 'tool.approval.resolve';
2109
2164
  }> | {
2165
+ readonly type: 'session.mode.select';
2166
+ readonly sessionId: SessionId;
2167
+ readonly modeRef: string;
2168
+ } | {
2110
2169
  readonly type: 'run.steer';
2111
2170
  readonly runId: RunId;
2112
2171
  readonly content: string;
@@ -27,6 +27,10 @@ export interface ProviderPreset {
27
27
  readonly defaultBaseUrl?: string;
28
28
  readonly defaultProtocol: ProviderProtocol;
29
29
  readonly defaultEnvKey: string;
30
+ readonly openCodeModelsUrl?: string;
30
31
  }
32
+ export declare const openCodeClientHeaders: {
33
+ readonly 'x-opencode-client': "saturn";
34
+ };
31
35
  export declare const providerPresets: readonly ProviderPreset[];
32
36
  export declare function normalizeProviderBaseUrl(value: string): string | undefined;
@@ -112,6 +112,7 @@ export const providerIdPattern = /^[A-Za-z0-9]+(?:[-_][A-Za-z0-9]+)*$/;
112
112
  export function providerCredentialKey(id) {
113
113
  return `SATURN_PROVIDER_${id.toUpperCase().replaceAll('-', '_')}_API_KEY`;
114
114
  }
115
+ export const openCodeClientHeaders = { 'x-opencode-client': 'saturn' };
115
116
  export const providerPresets = [
116
117
  {
117
118
  id: 'openai',
@@ -143,8 +144,27 @@ export const providerPresets = [
143
144
  defaultBaseUrl: 'https://openrouter.ai/api/v1',
144
145
  defaultProtocol: 'openai-responses',
145
146
  },
146
- { id: 'custom', label: 'Custom', defaultProtocol: 'openai-responses' },
147
- ].map((preset) => ({ ...preset, defaultEnvKey: providerCredentialKey(preset.id) }));
147
+ {
148
+ id: 'opencode-go',
149
+ label: 'OpenCode Go Subscription',
150
+ defaultBaseUrl: 'https://opencode.ai/inference/go/openai/v1',
151
+ defaultProtocol: 'openai-chat',
152
+ defaultEnvKey: 'OPENCODE_API_KEY',
153
+ openCodeModelsUrl: 'https://opencode.ai/zen/go/v1/models',
154
+ },
155
+ {
156
+ id: 'opencode-zen',
157
+ label: 'OpenCode Zen',
158
+ defaultBaseUrl: 'https://opencode.ai/inference/openai/v1',
159
+ defaultProtocol: 'openai-chat',
160
+ defaultEnvKey: 'OPENCODE_API_KEY',
161
+ openCodeModelsUrl: 'https://opencode.ai/zen/v1/models',
162
+ },
163
+ { id: 'custom', label: 'Custom', defaultProtocol: 'openai-chat' },
164
+ ].map((preset) => ({
165
+ ...preset,
166
+ defaultEnvKey: 'defaultEnvKey' in preset ? preset.defaultEnvKey : providerCredentialKey(preset.id),
167
+ }));
148
168
  export function normalizeProviderBaseUrl(value) {
149
169
  try {
150
170
  const url = new URL(value);
package/dist/team.d.ts CHANGED
@@ -1,10 +1,15 @@
1
1
  import type { PlannerConfig, RunConfig, TeamConfig, TeamHintConfig } from './contracts.js';
2
+ export interface TeamMemberActionResult {
3
+ readonly status: 'accepted' | 'ended' | 'inactive' | 'invalid_target' | 'forbidden';
4
+ readonly message: string;
5
+ }
2
6
  export declare const teamRootId = "main";
3
7
  export declare const plannerMemberId = "planner";
4
8
  export declare const defaultTeamConcurrency = 4;
5
9
  export declare const maxTeamDepth = 2;
6
10
  export declare const maxTeamMembers = 16;
7
11
  export declare const maxAsyncTeamMembers = 256;
12
+ export declare const teamModeSelectorPattern: RegExp;
8
13
  export declare const teamMemberIdPattern: RegExp;
9
14
  export declare const teamNotifyMessagePrefix = "notify:";
10
15
  export declare const defaultCoordinatorPollIntervalMs = 600000;
@@ -12,7 +17,7 @@ export declare function teamConcurrency(team: TeamConfig): number;
12
17
  export declare function isTeamNotifyMessageId(messageId: string): boolean;
13
18
  export declare function isAsyncCoordinatorConfig(config: Pick<RunConfig, 'modeRef' | 'teamAsyncCoordinator'>): boolean;
14
19
  /** Resolve the total concurrent non-root worker limit consistently across scheduler and projection. */
15
- export declare function resolveEffectiveTeamConcurrency(teamConcurrencyValue: number, config: Pick<RunConfig, 'teamMaxConcurrency'> | undefined, asyncCoordinator: boolean): number;
20
+ export declare function resolveEffectiveTeamConcurrency(requested: number | undefined, config?: Pick<RunConfig, 'teamDefaultConcurrency' | 'teamMaxConcurrency'>): number;
16
21
  export declare function maxRunTeamWorkers(config: Pick<RunConfig, 'modeRef' | 'teamAsyncCoordinator' | 'teamHint'>): number;
17
22
  export declare function coordinatorPollIntervalMs(config: Pick<RunConfig, 'coordinatorPollIntervalMs'>): number;
18
23
  export declare function validateWorkSubpath(raw: string): string;
package/dist/team.js CHANGED
@@ -5,6 +5,7 @@ export const defaultTeamConcurrency = 4;
5
5
  export const maxTeamDepth = 2;
6
6
  export const maxTeamMembers = 16;
7
7
  export const maxAsyncTeamMembers = 256;
8
+ export const teamModeSelectorPattern = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}(?:@[A-Za-z0-9][A-Za-z0-9._-]{0,63})?$/;
8
9
  export const teamMemberIdPattern = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
9
10
  export const teamNotifyMessagePrefix = 'notify:';
10
11
  export const defaultCoordinatorPollIntervalMs = 600_000;
@@ -20,11 +21,9 @@ export function isAsyncCoordinatorConfig(config) {
20
21
  return config.modeRef === 'ctf@1' || config.modeRef.startsWith('ctf@');
21
22
  }
22
23
  /** Resolve the total concurrent non-root worker limit consistently across scheduler and projection. */
23
- export function resolveEffectiveTeamConcurrency(teamConcurrencyValue, config, asyncCoordinator) {
24
- if (asyncCoordinator && config?.teamMaxConcurrency !== undefined) {
25
- return Math.max(1, config.teamMaxConcurrency);
26
- }
27
- return Math.max(1, Math.min(teamConcurrencyValue, config?.teamMaxConcurrency ?? teamConcurrencyValue));
24
+ export function resolveEffectiveTeamConcurrency(requested, config) {
25
+ const concurrency = requested ?? config?.teamDefaultConcurrency ?? defaultTeamConcurrency;
26
+ return Math.max(1, Math.min(concurrency, config?.teamMaxConcurrency ?? concurrency));
28
27
  }
29
28
  export function maxRunTeamWorkers(config) {
30
29
  if (config.teamHint?.maxMembers !== undefined)
@@ -90,6 +89,9 @@ export function validateTeamConfig(value, options) {
90
89
  member.sandboxProfile !== 'readonly' &&
91
90
  member.sandboxProfile !== 'build')
92
91
  invalid(`invalid sandboxProfile for team member ${member.id}`);
92
+ if (member.modeRef !== undefined &&
93
+ (typeof member.modeRef !== 'string' || !teamModeSelectorPattern.test(member.modeRef)))
94
+ invalid(`invalid modeRef for team member ${member.id}`);
93
95
  if (member.workSubpath !== undefined) {
94
96
  validateWorkSubpath(member.workSubpath);
95
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saturn-universe/core",
3
- "version": "0.1.1",
3
+ "version": "0.1.2-dev.10",
4
4
  "license": "AGPL-3.0-only",
5
5
  "type": "module",
6
6
  "files": [