@saturn-universe/runtime-host 0.1.2-dev.2 → 0.1.2-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builtin-plugins/saturn-plugin-ctf/index.mjs +2 -2
- package/dist/builtin-plugins/saturn-plugin-ctf/package.json +1 -1
- package/dist/cordis/plugin-loader.d.ts +1 -1
- package/dist/cordis/plugin-loader.js +45 -10
- package/dist/host-configuration.d.ts +3 -0
- package/dist/host-configuration.js +24 -1
- package/dist/index.js +8 -1
- package/dist/mode-configuration.d.ts +153 -0
- package/dist/mode-configuration.js +106 -0
- package/dist/provider-catalog.js +1 -1
- package/package.json +9 -9
|
@@ -171,10 +171,10 @@ function matchesScopeFilters(item, categorySet, idSet) {
|
|
|
171
171
|
|
|
172
172
|
export default {
|
|
173
173
|
id: 'ctf',
|
|
174
|
-
version: '0.1.2-dev.
|
|
174
|
+
version: '0.1.2-dev.3',
|
|
175
175
|
kind: 'saturn-registrar',
|
|
176
176
|
apiVersion: 1,
|
|
177
|
-
sdkVersion: '0.1.2-dev.
|
|
177
|
+
sdkVersion: '0.1.2-dev.3',
|
|
178
178
|
async setup(api, config = {}) {
|
|
179
179
|
const { boardToken, boardPublicHost, ...boardSettings } = settingsFor(config);
|
|
180
180
|
if (boardToken) api.registerSecret?.(boardToken);
|
|
@@ -9,7 +9,7 @@ export interface LoadedHostPlugin {
|
|
|
9
9
|
readonly entryUrl?: string;
|
|
10
10
|
readonly files?: ReadonlyMap<string, string>;
|
|
11
11
|
}
|
|
12
|
-
type PluginConfiguration = Pick<Awaited<ReturnType<typeof loadHostConfiguration>>, 'configSource' | 'configPath' | 'trustedPlugins'>;
|
|
12
|
+
type PluginConfiguration = Pick<Awaited<ReturnType<typeof loadHostConfiguration>>, 'configSource' | 'configPath' | 'trustedPlugins' | 'modePluginSources'>;
|
|
13
13
|
export declare function loadModePlugins(activeMode: ModeDefinition, configuration: PluginConfiguration, logger: LoggerPort, reload?: {
|
|
14
14
|
readonly active: ReadonlyMap<string, LoadedHostPlugin>;
|
|
15
15
|
readonly pluginId?: string;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import { readFile, realpath, stat } from 'node:fs/promises';
|
|
2
|
+
import { lstat, readFile, realpath, stat } from 'node:fs/promises';
|
|
3
3
|
import { createRequire, findPackageJSON, registerHooks } from 'node:module';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
6
|
import { Context } from '@deepseek-ai/cordis';
|
|
7
7
|
import { canonicalJson, RuntimeError } from '@saturn-universe/core';
|
|
8
|
+
import { isInsideSkillDir } from '@saturn-universe/protocol';
|
|
8
9
|
import { SATURN_PLUGIN_SDK_VERSION, SUPPORTED_CORDIS_VERSION, validatePluginCompatibility, } from '@saturn-universe/plugin-sdk';
|
|
9
10
|
import { resolve } from 'import-meta-resolve';
|
|
10
11
|
import semver from 'semver';
|
|
@@ -16,13 +17,24 @@ const hostRequire = createRequire(import.meta.url);
|
|
|
16
17
|
// External plugin imports must go through Node's loader, including under the test module runner.
|
|
17
18
|
const nativeImportModule = 'data:text/javascript,export const load = (url) => import(url)';
|
|
18
19
|
export async function loadModePlugins(activeMode, configuration, logger, reload) {
|
|
19
|
-
const { configPath, configSource, trustedPlugins } = configuration;
|
|
20
|
+
const { configPath, configSource, trustedPlugins, modePluginSources } = configuration;
|
|
20
21
|
const isTrusted = Boolean(trustedPlugins && (configSource === 'user' || configSource === 'explicit'));
|
|
22
|
+
const sources = modePluginSources?.get(activeMode.ref);
|
|
21
23
|
const bindings = [...(activeMode.plugins ?? [])].sort((a, b) => a.id.localeCompare(b.id));
|
|
24
|
+
const resolveBinding = (id, entry) => {
|
|
25
|
+
const source = sources?.get(id);
|
|
26
|
+
if (source)
|
|
27
|
+
return resolveEntry(id, source.directory, entry, source.bundled);
|
|
28
|
+
if (!configPath)
|
|
29
|
+
throw new RuntimeError('INVALID_CONFIG', 'Plugin configuration requires a file path');
|
|
30
|
+
return resolveEntry(id, path.dirname(configPath), entry);
|
|
31
|
+
};
|
|
22
32
|
if (!isTrusted) {
|
|
23
33
|
let hasEnabledUntrusted = false;
|
|
24
34
|
for (const binding of bindings) {
|
|
25
35
|
const id = binding.id;
|
|
36
|
+
if (sources?.has(id))
|
|
37
|
+
continue;
|
|
26
38
|
if (binding.builtin) {
|
|
27
39
|
if (binding.enabled === false)
|
|
28
40
|
continue;
|
|
@@ -52,9 +64,7 @@ export async function loadModePlugins(activeMode, configuration, logger, reload)
|
|
|
52
64
|
let filename;
|
|
53
65
|
let directoryManifest;
|
|
54
66
|
if (binding.entry) {
|
|
55
|
-
|
|
56
|
-
throw new RuntimeError('INVALID_CONFIG', 'Plugin configuration requires a file path');
|
|
57
|
-
const resolved = await resolveEntry(id, path.dirname(configPath), binding.entry);
|
|
67
|
+
const resolved = await resolveBinding(id, binding.entry);
|
|
58
68
|
filename = resolved.filename;
|
|
59
69
|
directoryManifest = resolved.directoryManifest;
|
|
60
70
|
}
|
|
@@ -73,9 +83,7 @@ export async function loadModePlugins(activeMode, configuration, logger, reload)
|
|
|
73
83
|
if (!entry) {
|
|
74
84
|
throw new RuntimeError('INVALID_CONFIG', `Mode ${activeMode.ref} plugin ${id} is missing an entry`);
|
|
75
85
|
}
|
|
76
|
-
|
|
77
|
-
throw new RuntimeError('INVALID_CONFIG', 'Plugin configuration requires a file path');
|
|
78
|
-
const resolved = await resolveEntry(id, path.dirname(configPath), entry);
|
|
86
|
+
const resolved = await resolveBinding(id, entry);
|
|
79
87
|
const mergedConfig = binding.config ? { ...binding.config } : undefined;
|
|
80
88
|
loaded.push(await loadPluginFromEntry(id, resolved.filename, resolved.directoryManifest, mergedConfig, reload));
|
|
81
89
|
}
|
|
@@ -170,21 +178,48 @@ async function importPlugin(id, entryUrl, timeoutMs) {
|
|
|
170
178
|
hooks.deregister();
|
|
171
179
|
}
|
|
172
180
|
}
|
|
173
|
-
async function
|
|
181
|
+
async function bundledEntry(directory, entry) {
|
|
182
|
+
const local = path.resolve(directory, entry);
|
|
183
|
+
if (!isInsideSkillDir(directory, local))
|
|
184
|
+
throw new Error('Entry is outside the Mode directory');
|
|
185
|
+
try {
|
|
186
|
+
await lstat(local);
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
if (error.code !== 'ENOENT' || !entry.startsWith('./modes/'))
|
|
190
|
+
throw error;
|
|
191
|
+
const modes = path.dirname(directory);
|
|
192
|
+
const legacy = path.resolve(path.dirname(modes), entry);
|
|
193
|
+
if (!isInsideSkillDir(modes, legacy))
|
|
194
|
+
throw new Error('Entry is outside the user modes directory');
|
|
195
|
+
return { supplied: legacy, boundary: modes };
|
|
196
|
+
}
|
|
197
|
+
return { supplied: local, boundary: directory };
|
|
198
|
+
}
|
|
199
|
+
async function resolveEntry(id, directory, entry, bundled = false) {
|
|
174
200
|
try {
|
|
175
201
|
// Drive-relative paths would otherwise fall back to that drive's working directory on Windows.
|
|
176
202
|
const root = path.parse(entry).root;
|
|
177
203
|
if (process.platform === 'win32' && root && (!path.isAbsolute(entry) || root.length === 1))
|
|
178
204
|
throw new Error('A Windows absolute path requires a drive or network share');
|
|
179
|
-
const
|
|
205
|
+
const { supplied, boundary } = bundled
|
|
206
|
+
? await bundledEntry(directory, entry)
|
|
207
|
+
: { supplied: path.resolve(directory, entry), boundary: undefined };
|
|
208
|
+
const target = await realpath(supplied);
|
|
209
|
+
if (boundary && !isInsideSkillDir(boundary, target))
|
|
210
|
+
throw new Error('Entry resolves outside its directory');
|
|
180
211
|
if ((await stat(target)).isFile())
|
|
181
212
|
return { filename: target };
|
|
182
213
|
const directoryManifest = path.join(target, 'package.json');
|
|
214
|
+
if (boundary && !isInsideSkillDir(boundary, await realpath(directoryManifest)))
|
|
215
|
+
throw new Error('Package manifest resolves outside its directory');
|
|
183
216
|
const manifest = await readManifest(directoryManifest);
|
|
184
217
|
const entryFile = typeof manifest?.name === 'string' && manifest.exports !== undefined && manifest.exports !== null
|
|
185
218
|
? fileURLToPath(resolve(manifest.name, pathToFileURL(directoryManifest).href))
|
|
186
219
|
: hostRequire.resolve(target);
|
|
187
220
|
const filename = await realpath(entryFile);
|
|
221
|
+
if (boundary && !isInsideSkillDir(boundary, filename))
|
|
222
|
+
throw new Error('Entry resolves outside its directory');
|
|
188
223
|
if ((await stat(filename)).isFile())
|
|
189
224
|
return { filename, directoryManifest };
|
|
190
225
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ProviderCatalog } from './provider-catalog.js';
|
|
2
|
+
import { loadModeConfiguration } from './mode-configuration.js';
|
|
2
3
|
export type ConfigSource = 'explicit' | 'workspace' | 'user' | 'none';
|
|
3
4
|
export interface McpServerMeta {
|
|
4
5
|
readonly scope: Exclude<ConfigSource, 'none'> | 'project';
|
|
@@ -8,6 +9,7 @@ export interface McpServerMeta {
|
|
|
8
9
|
}
|
|
9
10
|
export declare function parseHostArguments(args: readonly string[]): {
|
|
10
11
|
allowUnsafeSandboxFallback?: boolean;
|
|
12
|
+
inspectModes?: boolean;
|
|
11
13
|
mode?: string;
|
|
12
14
|
taskProfile?: string;
|
|
13
15
|
profile?: string;
|
|
@@ -20,6 +22,7 @@ export declare function loadHostConfiguration(root: string, explicitFile?: strin
|
|
|
20
22
|
configPath: string | undefined;
|
|
21
23
|
trustedMcp: boolean;
|
|
22
24
|
trustedPlugins: boolean;
|
|
25
|
+
modePluginSources?: Awaited<ReturnType<typeof loadModeConfiguration>>['modePluginSources'];
|
|
23
26
|
webSearch?: ProviderCatalog['webSearch'];
|
|
24
27
|
mcpServers?: ProviderCatalog['mcpServers'];
|
|
25
28
|
mcpServerMeta?: Readonly<Record<string, McpServerMeta>>;
|
|
@@ -3,18 +3,23 @@ import { readFile } from 'node:fs/promises';
|
|
|
3
3
|
import { RuntimeError } from '@saturn-universe/core';
|
|
4
4
|
import { normalizeWorkspaceTrustPath, parseProjectMcpJson, projectMcpConfigPath, userConfigPath, workspaceConfigPath, } from '@saturn-universe/protocol';
|
|
5
5
|
import { parseProviderToml } from './provider-catalog.js';
|
|
6
|
+
import { loadModeConfiguration } from './mode-configuration.js';
|
|
6
7
|
export function parseHostArguments(args) {
|
|
7
8
|
let root;
|
|
8
9
|
let configFile;
|
|
9
10
|
let profile;
|
|
10
11
|
let taskProfile;
|
|
11
12
|
let mode;
|
|
13
|
+
let inspectModes = false;
|
|
12
14
|
let allowUnsafeSandboxFallback = false;
|
|
13
15
|
for (let i = 0; i < args.length; i++) {
|
|
14
16
|
const arg = args[i];
|
|
15
17
|
if (arg === '--allow-unsafe-sandbox-fallback') {
|
|
16
18
|
allowUnsafeSandboxFallback = true;
|
|
17
19
|
}
|
|
20
|
+
else if (arg === '--inspect-modes') {
|
|
21
|
+
inspectModes = true;
|
|
22
|
+
}
|
|
18
23
|
else if (['--config', '--profile', '--task-profile', '--mode'].includes(arg)) {
|
|
19
24
|
const value = args[++i];
|
|
20
25
|
if (!value || value.startsWith('--'))
|
|
@@ -55,6 +60,7 @@ export function parseHostArguments(args) {
|
|
|
55
60
|
...(profile ? { profile } : {}),
|
|
56
61
|
...(taskProfile ? { taskProfile } : {}),
|
|
57
62
|
...(mode ? { mode } : {}),
|
|
63
|
+
...(inspectModes ? { inspectModes: true } : {}),
|
|
58
64
|
...(allowUnsafeSandboxFallback ? { allowUnsafeSandboxFallback: true } : {}),
|
|
59
65
|
};
|
|
60
66
|
}
|
|
@@ -123,6 +129,22 @@ export async function loadHostConfiguration(root, explicitFile, env = process.en
|
|
|
123
129
|
break;
|
|
124
130
|
}
|
|
125
131
|
const userCatalog = configSource === 'user' ? resolvedCatalog : await readOptionalUserCatalog(env);
|
|
132
|
+
const { modes, modePluginSources } = await loadModeConfiguration(env, [
|
|
133
|
+
...(configSource !== 'user' && userCatalog?.modes
|
|
134
|
+
? [
|
|
135
|
+
{
|
|
136
|
+
modes: userCatalog.modes,
|
|
137
|
+
pluginSource: { directory: path.dirname(userConfigPath(env)), bundled: false },
|
|
138
|
+
},
|
|
139
|
+
]
|
|
140
|
+
: []),
|
|
141
|
+
{
|
|
142
|
+
modes: resolvedCatalog?.modes,
|
|
143
|
+
...(trusted && configPath
|
|
144
|
+
? { pluginSource: { directory: path.dirname(configPath), bundled: false } }
|
|
145
|
+
: {}),
|
|
146
|
+
},
|
|
147
|
+
]);
|
|
126
148
|
const trustedWorkspaces = new Set((userCatalog?.trustedMcpWorkspaces ?? []).map((entry) => normalizeWorkspaceTrustPath(entry)));
|
|
127
149
|
const workspaceTrustedForMcp = trustedWorkspaces.has(normalizeWorkspaceTrustPath(root));
|
|
128
150
|
const mcpJsonPath = projectMcpConfigPath(root);
|
|
@@ -170,11 +192,12 @@ export async function loadHostConfiguration(root, explicitFile, env = process.en
|
|
|
170
192
|
// A workspace-controlled TOML cannot select which Host secret to send to a remote endpoint.
|
|
171
193
|
const webSearch = trusted ? resolvedCatalog?.webSearch : userCatalog?.webSearch;
|
|
172
194
|
return {
|
|
173
|
-
catalog: resolvedCatalog,
|
|
195
|
+
catalog: modes ? { ...(resolvedCatalog ?? { profiles: [], taskProfiles: {} }), modes } : resolvedCatalog,
|
|
174
196
|
configSource,
|
|
175
197
|
configPath,
|
|
176
198
|
trustedMcp: trusted,
|
|
177
199
|
trustedPlugins: trusted,
|
|
200
|
+
modePluginSources,
|
|
178
201
|
...(webSearch ? { webSearch } : {}),
|
|
179
202
|
...(hasMergedMcp ? { mcpServers: mergedMcpServers, mcpServerMeta } : {}),
|
|
180
203
|
...(projectMcp.error ? { mcpJsonError: projectMcp.error } : {}),
|
package/dist/index.js
CHANGED
|
@@ -11,12 +11,19 @@ import { acquireOwnership } from './ownership.js';
|
|
|
11
11
|
import { composeRuntime } from './composition.js';
|
|
12
12
|
import { ReplyWriter, receiveCommands } from './ipc.js';
|
|
13
13
|
import { createCommandDispatch } from './command-dispatch.js';
|
|
14
|
-
import { parseHostArguments } from './host-configuration.js';
|
|
14
|
+
import { loadHostConfiguration, parseHostArguments } from './host-configuration.js';
|
|
15
15
|
import { createHostLogger, openHostDiagnostics } from './logger.js';
|
|
16
|
+
import { resolveActiveMode } from './modes.js';
|
|
16
17
|
async function main() {
|
|
17
18
|
const startup = performance.now();
|
|
18
19
|
const args = parseHostArguments(process.argv.slice(2));
|
|
19
20
|
const root = await realpath(path.resolve(args.root));
|
|
21
|
+
if (args.inspectModes) {
|
|
22
|
+
const { catalog } = await loadHostConfiguration(root, args.configFile);
|
|
23
|
+
const { availableModes } = resolveActiveMode(catalog, args.mode);
|
|
24
|
+
process.stdout.write(JSON.stringify(availableModes.map(({ ref, displayName, description }) => ({ ref, displayName, description }))) + '\n');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
20
27
|
const dataDir = path.join(root, '.saturn');
|
|
21
28
|
await mkdir(dataDir, { recursive: true });
|
|
22
29
|
const { key, endpoint } = resolveHostEndpoint(root);
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { ProviderCatalog } from './provider-catalog.js';
|
|
2
|
+
interface ModePluginSource {
|
|
3
|
+
readonly directory: string;
|
|
4
|
+
readonly bundled: boolean;
|
|
5
|
+
}
|
|
6
|
+
type ModeLayer = {
|
|
7
|
+
readonly modes: ProviderCatalog['modes'];
|
|
8
|
+
readonly pluginSource?: ModePluginSource;
|
|
9
|
+
};
|
|
10
|
+
export declare function loadModeConfiguration(env: NodeJS.ProcessEnv, configured: readonly ModeLayer[]): Promise<{
|
|
11
|
+
modes: {
|
|
12
|
+
[k: string]: {
|
|
13
|
+
display_name?: string | undefined;
|
|
14
|
+
description?: string | undefined;
|
|
15
|
+
instructions?: string | undefined;
|
|
16
|
+
allowed_tools?: string[] | undefined;
|
|
17
|
+
denied_tools?: string[] | undefined;
|
|
18
|
+
prompts?: {
|
|
19
|
+
instructions?: string | undefined;
|
|
20
|
+
core?: {
|
|
21
|
+
mode: "append" | "replace";
|
|
22
|
+
text: string;
|
|
23
|
+
} | undefined;
|
|
24
|
+
execution_policy?: {
|
|
25
|
+
mode: "append" | "replace";
|
|
26
|
+
text: string;
|
|
27
|
+
} | undefined;
|
|
28
|
+
roles?: {
|
|
29
|
+
main?: {
|
|
30
|
+
text: string;
|
|
31
|
+
id?: string | undefined;
|
|
32
|
+
priority?: number | undefined;
|
|
33
|
+
required?: boolean | undefined;
|
|
34
|
+
mode?: "append" | "replace" | undefined;
|
|
35
|
+
}[] | undefined;
|
|
36
|
+
planner?: {
|
|
37
|
+
text: string;
|
|
38
|
+
id?: string | undefined;
|
|
39
|
+
priority?: number | undefined;
|
|
40
|
+
required?: boolean | undefined;
|
|
41
|
+
mode?: "append" | "replace" | undefined;
|
|
42
|
+
}[] | undefined;
|
|
43
|
+
worker?: {
|
|
44
|
+
text: string;
|
|
45
|
+
id?: string | undefined;
|
|
46
|
+
priority?: number | undefined;
|
|
47
|
+
required?: boolean | undefined;
|
|
48
|
+
mode?: "append" | "replace" | undefined;
|
|
49
|
+
}[] | undefined;
|
|
50
|
+
} | undefined;
|
|
51
|
+
} | undefined;
|
|
52
|
+
tools?: {
|
|
53
|
+
workspace_tools?: boolean | undefined;
|
|
54
|
+
process_manager?: boolean | undefined;
|
|
55
|
+
builtin_agent_tools?: boolean | undefined;
|
|
56
|
+
allowed_tools?: string[] | undefined;
|
|
57
|
+
denied_tools?: string[] | undefined;
|
|
58
|
+
permission_mode?: "default" | "strict" | "full" | undefined;
|
|
59
|
+
} | undefined;
|
|
60
|
+
plugins?: string[] | Record<string, {
|
|
61
|
+
allowed_tools?: string[] | undefined;
|
|
62
|
+
read_only_tools?: string[] | undefined;
|
|
63
|
+
auto_approve_tools?: string[] | undefined;
|
|
64
|
+
enabled?: boolean | undefined;
|
|
65
|
+
entry?: string | undefined;
|
|
66
|
+
config?: Record<string, string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | {
|
|
67
|
+
[key: string]: string | number | boolean | /*elided*/ any | /*elided*/ any;
|
|
68
|
+
})[] | {
|
|
69
|
+
[key: string]: string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any)[] | /*elided*/ any;
|
|
70
|
+
})[] | {
|
|
71
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any;
|
|
72
|
+
})[] | {
|
|
73
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any;
|
|
74
|
+
})[] | {
|
|
75
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any;
|
|
76
|
+
})[] | {
|
|
77
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any;
|
|
78
|
+
})[] | {
|
|
79
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any;
|
|
80
|
+
})[] | {
|
|
81
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any;
|
|
82
|
+
})[] | {
|
|
83
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any;
|
|
84
|
+
})[] | {
|
|
85
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any;
|
|
86
|
+
})[] | {
|
|
87
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any;
|
|
88
|
+
})[] | {
|
|
89
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any)[] | /*elided*/ any;
|
|
90
|
+
}> | undefined;
|
|
91
|
+
}> | undefined;
|
|
92
|
+
sandbox?: {
|
|
93
|
+
backend?: "host" | "docker" | "gvisor" | "sysbox" | undefined;
|
|
94
|
+
scope?: "none" | "per_run_and_worker" | undefined;
|
|
95
|
+
image?: string | undefined;
|
|
96
|
+
network?: "none" | "internal" | "proxy" | "bridge" | undefined;
|
|
97
|
+
network_name?: string | undefined;
|
|
98
|
+
proxy_url?: string | undefined;
|
|
99
|
+
cap_add?: string[] | undefined;
|
|
100
|
+
readonly_mounts?: {
|
|
101
|
+
host_path: string;
|
|
102
|
+
container_path: string;
|
|
103
|
+
}[] | undefined;
|
|
104
|
+
kvm?: boolean | undefined;
|
|
105
|
+
tmpfs_size_mb?: number | undefined;
|
|
106
|
+
resources?: {
|
|
107
|
+
cpus?: number | undefined;
|
|
108
|
+
memory_mb?: number | undefined;
|
|
109
|
+
pids_limit?: number | undefined;
|
|
110
|
+
disk_soft_limit_mb?: number | undefined;
|
|
111
|
+
} | undefined;
|
|
112
|
+
retention?: {
|
|
113
|
+
mode: "always" | "on_success" | "ttl";
|
|
114
|
+
ttl_hours?: number | undefined;
|
|
115
|
+
} | undefined;
|
|
116
|
+
fallback_policy?: "fail_closed" | "allow_host_fallback" | undefined;
|
|
117
|
+
allow_target_services?: boolean | undefined;
|
|
118
|
+
worker_allow_target_services?: boolean | undefined;
|
|
119
|
+
max_targets_per_run?: number | undefined;
|
|
120
|
+
max_concurrent_containers?: number | undefined;
|
|
121
|
+
allowed_target_capabilities?: string[] | undefined;
|
|
122
|
+
} | undefined;
|
|
123
|
+
team?: {
|
|
124
|
+
max_depth?: number | undefined;
|
|
125
|
+
async_coordinator?: boolean | undefined;
|
|
126
|
+
coordinator_poll_interval_ms?: number | undefined;
|
|
127
|
+
} | undefined;
|
|
128
|
+
limits?: {
|
|
129
|
+
max_model_attempts?: number | undefined;
|
|
130
|
+
max_tool_calls?: number | undefined;
|
|
131
|
+
max_steps?: number | undefined;
|
|
132
|
+
max_total_tokens?: number | undefined;
|
|
133
|
+
subagent_max_model_attempts?: number | undefined;
|
|
134
|
+
wall_time_ms?: number | undefined;
|
|
135
|
+
subagent_wall_time_ms?: number | undefined;
|
|
136
|
+
} | undefined;
|
|
137
|
+
max_active_challenges?: number | undefined;
|
|
138
|
+
max_helpers_per_challenge?: number | undefined;
|
|
139
|
+
per_challenge_wall_time_ms?: number | undefined;
|
|
140
|
+
worker_soft_checkpoint_ms?: number | undefined;
|
|
141
|
+
board_port?: number | undefined;
|
|
142
|
+
board_token?: string | undefined;
|
|
143
|
+
board_public_host?: string | undefined;
|
|
144
|
+
coordinator_poll_interval_ms?: number | undefined;
|
|
145
|
+
auto_submit?: boolean | undefined;
|
|
146
|
+
max_remote_instances?: number | undefined;
|
|
147
|
+
instance_cooldown_ms?: number | undefined;
|
|
148
|
+
auto_stop_on_solve?: boolean | undefined;
|
|
149
|
+
};
|
|
150
|
+
} | undefined;
|
|
151
|
+
modePluginSources: Map<string, Map<string, ModePluginSource>>;
|
|
152
|
+
}>;
|
|
153
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { lstat, readFile, realpath } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parse } from 'smol-toml';
|
|
4
|
+
import { RuntimeError } from '@saturn-universe/core';
|
|
5
|
+
import { userModeDirectories } from '@saturn-universe/protocol';
|
|
6
|
+
import { modeDefinitionsSchema } from './context-extensions.js';
|
|
7
|
+
export async function loadModeConfiguration(env, configured) {
|
|
8
|
+
const discovered = new Map();
|
|
9
|
+
for (const directory of await userModeDirectories(env)) {
|
|
10
|
+
const filename = path.join(directory, 'mode.toml');
|
|
11
|
+
try {
|
|
12
|
+
if (path.relative(directory, await realpath(directory)) !== '')
|
|
13
|
+
continue;
|
|
14
|
+
const stat = await lstat(filename);
|
|
15
|
+
if (!stat.isFile() || stat.nlink !== 1)
|
|
16
|
+
continue;
|
|
17
|
+
const modes = modeDefinitionsSchema.parse(parse(await readFile(filename, 'utf8')).modes);
|
|
18
|
+
for (const [ref, mode] of Object.entries(modes)) {
|
|
19
|
+
discovered.set(ref, { modes: { [ref]: mode }, pluginSource: { directory, bundled: true } });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (error.code === 'ENOENT')
|
|
24
|
+
continue;
|
|
25
|
+
throw new RuntimeError('INVALID_CONFIG', `Invalid mode.toml in Mode directory ${path.basename(directory)}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const modes = new Map();
|
|
29
|
+
const modePluginSources = new Map();
|
|
30
|
+
for (const layer of [...discovered.values(), ...configured]) {
|
|
31
|
+
for (const [ref, mode] of Object.entries(layer.modes ?? {})) {
|
|
32
|
+
const base = modes.get(ref);
|
|
33
|
+
modes.set(ref, base ? mergeModes(base, mode) : mode);
|
|
34
|
+
const sources = modePluginSources.get(ref) ?? new Map();
|
|
35
|
+
modePluginSources.set(ref, sources);
|
|
36
|
+
if (Array.isArray(mode.plugins)) {
|
|
37
|
+
for (const id of sources.keys())
|
|
38
|
+
if (!mode.plugins.includes(id))
|
|
39
|
+
sources.delete(id);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
for (const [id, plugin] of Object.entries(mode.plugins ?? {})) {
|
|
43
|
+
// A workspace declaration must never gain trust from an inherited entry.
|
|
44
|
+
if (!layer.pluginSource)
|
|
45
|
+
sources.delete(id);
|
|
46
|
+
else if (plugin.entry !== undefined)
|
|
47
|
+
sources.set(id, layer.pluginSource);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
modes: modes.size ? Object.fromEntries(modes) : undefined,
|
|
54
|
+
modePluginSources,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function mergeModes(base, override) {
|
|
58
|
+
const { instructions, allowed_tools, denied_tools, ...rest } = override;
|
|
59
|
+
const normalized = {
|
|
60
|
+
...rest,
|
|
61
|
+
prompts: { ...override.prompts, ...(instructions === undefined ? {} : { instructions }) },
|
|
62
|
+
tools: {
|
|
63
|
+
...override.tools,
|
|
64
|
+
...(allowed_tools === undefined ? {} : { allowed_tools }),
|
|
65
|
+
...(denied_tools === undefined ? {} : { denied_tools }),
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
const { instructions: baseInstructions, allowed_tools: baseAllowed, denied_tools: baseDenied, ...baseRest } = base;
|
|
69
|
+
const merged = mergeTables({
|
|
70
|
+
...baseRest,
|
|
71
|
+
prompts: { instructions: baseInstructions, ...base.prompts },
|
|
72
|
+
tools: { allowed_tools: baseAllowed, denied_tools: baseDenied, ...base.tools },
|
|
73
|
+
}, normalized);
|
|
74
|
+
if (Array.isArray(base.plugins) && !Array.isArray(override.plugins) && override.plugins) {
|
|
75
|
+
merged.plugins = { ...Object.fromEntries(base.plugins.map((id) => [id, {}])), ...override.plugins };
|
|
76
|
+
}
|
|
77
|
+
else if (Array.isArray(override.plugins) && base.plugins && !Array.isArray(base.plugins)) {
|
|
78
|
+
const basePlugins = base.plugins;
|
|
79
|
+
merged.plugins = Object.fromEntries(override.plugins.map((id) => [id, Object.hasOwn(basePlugins, id) ? basePlugins[id] : {}]));
|
|
80
|
+
}
|
|
81
|
+
else if (isTable(merged.plugins) && override.plugins && !Array.isArray(override.plugins)) {
|
|
82
|
+
for (const [id, plugin] of Object.entries(override.plugins)) {
|
|
83
|
+
if (plugin.allowed_tools === undefined)
|
|
84
|
+
continue;
|
|
85
|
+
const binding = merged.plugins[id];
|
|
86
|
+
if (!isTable(binding))
|
|
87
|
+
continue;
|
|
88
|
+
if (plugin.read_only_tools === undefined)
|
|
89
|
+
delete binding.read_only_tools;
|
|
90
|
+
if (plugin.auto_approve_tools === undefined)
|
|
91
|
+
delete binding.auto_approve_tools;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return merged;
|
|
95
|
+
}
|
|
96
|
+
function isTable(value) {
|
|
97
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
98
|
+
}
|
|
99
|
+
function mergeTables(base, override) {
|
|
100
|
+
const fields = new Map(Object.entries(base));
|
|
101
|
+
for (const [key, value] of Object.entries(override)) {
|
|
102
|
+
const previous = fields.get(key);
|
|
103
|
+
fields.set(key, isTable(previous) && isTable(value) ? mergeTables(previous, value) : value);
|
|
104
|
+
}
|
|
105
|
+
return Object.fromEntries(fields);
|
|
106
|
+
}
|
package/dist/provider-catalog.js
CHANGED
|
@@ -177,7 +177,7 @@ export function parseProviderCatalog(value) {
|
|
|
177
177
|
for (const modelId of models)
|
|
178
178
|
profiles.push(expandProfile(providerId, modelId, value));
|
|
179
179
|
}
|
|
180
|
-
if (!data.providers && !data.profiles)
|
|
180
|
+
if (!data.providers && !data.profiles && !data.modes)
|
|
181
181
|
throw invalid();
|
|
182
182
|
const names = new Set();
|
|
183
183
|
const identities = new Set();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saturn-universe/runtime-host",
|
|
3
|
-
"version": "0.1.2-dev.
|
|
3
|
+
"version": "0.1.2-dev.3",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
],
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@deepseek-ai/cordis": "4.1.0",
|
|
11
|
-
"@saturn-universe/context": "0.1.2-dev.
|
|
12
|
-
"@saturn-universe/core": "0.1.2-dev.
|
|
13
|
-
"@saturn-universe/model": "0.1.2-dev.
|
|
14
|
-
"@saturn-universe/plugin-sdk": "0.1.2-dev.
|
|
15
|
-
"@saturn-universe/protocol": "0.1.2-dev.
|
|
16
|
-
"@saturn-universe/runtime": "0.1.2-dev.
|
|
17
|
-
"@saturn-universe/storage": "0.1.2-dev.
|
|
18
|
-
"@saturn-universe/tools": "0.1.2-dev.
|
|
11
|
+
"@saturn-universe/context": "0.1.2-dev.3",
|
|
12
|
+
"@saturn-universe/core": "0.1.2-dev.3",
|
|
13
|
+
"@saturn-universe/model": "0.1.2-dev.3",
|
|
14
|
+
"@saturn-universe/plugin-sdk": "0.1.2-dev.3",
|
|
15
|
+
"@saturn-universe/protocol": "0.1.2-dev.3",
|
|
16
|
+
"@saturn-universe/runtime": "0.1.2-dev.3",
|
|
17
|
+
"@saturn-universe/storage": "0.1.2-dev.3",
|
|
18
|
+
"@saturn-universe/tools": "0.1.2-dev.3",
|
|
19
19
|
"import-meta-resolve": "4.2.0",
|
|
20
20
|
"pino": "10.4.0",
|
|
21
21
|
"semver": "7.7.4",
|