@saturn-universe/runtime-host 0.0.0-stage → 0.1.1
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/LICENSE +661 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/README.md +13 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/index.mjs +1473 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/package.json +10 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/board.mjs +321 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/ledger.mjs +1143 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/ctfd.mjs +154 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/ctfplus.mjs +769 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/gzctf.mjs +130 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/http.mjs +336 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/index.mjs +133 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/lease.mjs +153 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/server.mjs +336 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/view.mjs +714 -0
- package/dist/command-dispatch.d.ts +10 -0
- package/dist/command-dispatch.js +65 -0
- package/dist/completion-judge.d.ts +10 -0
- package/dist/completion-judge.js +156 -0
- package/dist/composition.d.ts +108 -0
- package/dist/composition.js +1180 -0
- package/dist/configuration.d.ts +49 -0
- package/dist/configuration.js +51 -0
- package/dist/context-extensions.d.ts +681 -0
- package/dist/context-extensions.js +289 -0
- package/dist/cordis/context-core-plugin.d.ts +35 -0
- package/dist/cordis/context-core-plugin.js +296 -0
- package/dist/cordis/env-probe-plugin.d.ts +27 -0
- package/dist/cordis/env-probe-plugin.js +114 -0
- package/dist/cordis/host-context.d.ts +65 -0
- package/dist/cordis/host-context.js +199 -0
- package/dist/cordis/model-responses-plugin.d.ts +81 -0
- package/dist/cordis/model-responses-plugin.js +209 -0
- package/dist/cordis/plugin-contributions.d.ts +47 -0
- package/dist/cordis/plugin-contributions.js +119 -0
- package/dist/cordis/plugin-lifecycle.d.ts +57 -0
- package/dist/cordis/plugin-lifecycle.js +222 -0
- package/dist/cordis/plugin-loader.d.ts +18 -0
- package/dist/cordis/plugin-loader.js +310 -0
- package/dist/cordis/plugin-sdk-adapter.d.ts +17 -0
- package/dist/cordis/plugin-sdk-adapter.js +283 -0
- package/dist/cordis/required-host-plugin.d.ts +6 -0
- package/dist/cordis/required-host-plugin.js +1 -0
- package/dist/cordis/runtime-hooks-plugin.d.ts +23 -0
- package/dist/cordis/runtime-hooks-plugin.js +103 -0
- package/dist/cordis/sandbox-plugin.d.ts +18 -0
- package/dist/cordis/sandbox-plugin.js +21 -0
- package/dist/cordis/scoped-layers.d.ts +63 -0
- package/dist/cordis/scoped-layers.js +170 -0
- package/dist/cordis/tools/builtin-agent-tools-plugin.d.ts +11 -0
- package/dist/cordis/tools/builtin-agent-tools-plugin.js +171 -0
- package/dist/cordis/tools/index.d.ts +17 -0
- package/dist/cordis/tools/index.js +40 -0
- package/dist/cordis/tools/mcp-tools-plugin.d.ts +7 -0
- package/dist/cordis/tools/mcp-tools-plugin.js +116 -0
- package/dist/cordis/tools/process-manager-plugin.d.ts +11 -0
- package/dist/cordis/tools/process-manager-plugin.js +39 -0
- package/dist/cordis/tools/sandbox-target-tools-plugin.d.ts +13 -0
- package/dist/cordis/tools/sandbox-target-tools-plugin.js +255 -0
- package/dist/cordis/tools/tool-guidance.d.ts +4 -0
- package/dist/cordis/tools/tool-guidance.js +30 -0
- package/dist/cordis/tools/tools-core-plugin.d.ts +128 -0
- package/dist/cordis/tools/tools-core-plugin.js +486 -0
- package/dist/cordis/tools/web-fetch.d.ts +17 -0
- package/dist/cordis/tools/web-fetch.js +529 -0
- package/dist/cordis/tools/web-search-tools-plugin.d.ts +10 -0
- package/dist/cordis/tools/web-search-tools-plugin.js +191 -0
- package/dist/cordis/tools/workspace-tools-plugin.d.ts +8 -0
- package/dist/cordis/tools/workspace-tools-plugin.js +145 -0
- package/dist/env-probe.d.ts +8 -0
- package/dist/env-probe.js +172 -0
- package/dist/host-configuration.d.ts +27 -0
- package/dist/host-configuration.js +185 -0
- package/dist/host-tools.d.ts +19 -0
- package/dist/host-tools.js +30 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +140 -0
- package/dist/ipc.d.ts +24 -0
- package/dist/ipc.js +162 -0
- package/dist/logger.d.ts +11 -0
- package/dist/logger.js +84 -0
- package/dist/mcp-configuration.d.ts +17 -0
- package/dist/mcp-configuration.js +50 -0
- package/dist/modes.d.ts +27 -0
- package/dist/modes.js +478 -0
- package/dist/ownership.d.ts +7 -0
- package/dist/ownership.js +100 -0
- package/dist/plugin-configuration.d.ts +9 -0
- package/dist/plugin-configuration.js +21 -0
- package/dist/plugin-tool-grants.d.ts +18 -0
- package/dist/plugin-tool-grants.js +21 -0
- package/dist/process-workspaces.d.ts +4 -0
- package/dist/process-workspaces.js +28 -0
- package/dist/progress.d.ts +30 -0
- package/dist/progress.js +699 -0
- package/dist/provider-catalog.d.ts +754 -0
- package/dist/provider-catalog.js +472 -0
- package/dist/run-budget.d.ts +24 -0
- package/dist/run-budget.js +47 -0
- package/dist/run-checkpoint.d.ts +2 -0
- package/dist/run-checkpoint.js +52 -0
- package/dist/sandbox-manager.d.ts +111 -0
- package/dist/sandbox-manager.js +1519 -0
- package/dist/session-paths.d.ts +15 -0
- package/dist/session-paths.js +40 -0
- package/dist/side-question.d.ts +14 -0
- package/dist/side-question.js +89 -0
- package/dist/skills-runtime.d.ts +13 -0
- package/dist/skills-runtime.js +243 -0
- package/dist/token-estimator.d.ts +3 -0
- package/dist/token-estimator.js +73 -0
- package/dist/tool-result.d.ts +2 -0
- package/dist/tool-result.js +91 -0
- package/dist/user-config.d.ts +23 -0
- package/dist/user-config.js +36 -0
- package/package.json +28 -3
- package/README.md +0 -3
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { expandMcpServerConfig } from '@saturn-universe/protocol';
|
|
2
|
+
import { McpError, openMcpServer } from '@saturn-universe/tools';
|
|
3
|
+
import { sharedToolPriority } from './tools-core-plugin.js';
|
|
4
|
+
function adapterConfiguration(server) {
|
|
5
|
+
return {
|
|
6
|
+
...(server.transport === 'stdio'
|
|
7
|
+
? {
|
|
8
|
+
transport: server.transport,
|
|
9
|
+
command: server.command,
|
|
10
|
+
...(server.args ? { args: server.args } : {}),
|
|
11
|
+
...(server.env ? { env: server.env } : {}),
|
|
12
|
+
}
|
|
13
|
+
: {
|
|
14
|
+
transport: server.transport,
|
|
15
|
+
url: server.url,
|
|
16
|
+
...(server.headers ? { headers: server.headers } : {}),
|
|
17
|
+
}),
|
|
18
|
+
...(server.tools ? { tools: server.tools } : {}),
|
|
19
|
+
...(server.read_only_tools ? { readOnlyTools: server.read_only_tools } : {}),
|
|
20
|
+
...(server.timeout_ms === undefined ? {} : { timeoutMs: server.timeout_ms }),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function sanitizeMcpError(error, secrets) {
|
|
24
|
+
const raw = error instanceof McpError ? error.message : 'MCP connection failed';
|
|
25
|
+
let cleaned = raw
|
|
26
|
+
.replace(/[\u0000-\u001f\u007f-\u009f]+/g, ' ')
|
|
27
|
+
.replace(/\s+/g, ' ')
|
|
28
|
+
.trim();
|
|
29
|
+
for (const secret of secrets) {
|
|
30
|
+
if (secret)
|
|
31
|
+
cleaned = cleaned.replaceAll(secret, '[redacted]');
|
|
32
|
+
}
|
|
33
|
+
if (!cleaned)
|
|
34
|
+
return 'MCP connection failed';
|
|
35
|
+
return cleaned.length > 200 ? `${cleaned.slice(0, 199)}…` : cleaned;
|
|
36
|
+
}
|
|
37
|
+
export function createMcpToolsPlugin(root, config, trustedConfig) {
|
|
38
|
+
return {
|
|
39
|
+
name: 'mcp-tools',
|
|
40
|
+
// Cordis unloads siblings concurrently. Keep the manager alive until the MCP effect has drained.
|
|
41
|
+
inject: ['saturnTools', ...(config.workspaceTools ? ['saturnProcessManager'] : [])],
|
|
42
|
+
async apply(ctx, startupSignal) {
|
|
43
|
+
const tools = ctx.saturnTools;
|
|
44
|
+
const servers = Object.entries(config.mcpServers ?? {}).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
45
|
+
const envLookup = config.mcpEnvLookup ?? ((name) => process.env[name]);
|
|
46
|
+
const discovery = Promise.all(servers.map(async ([id, server]) => {
|
|
47
|
+
const meta = config.mcpServerMeta?.[id];
|
|
48
|
+
const trusted = meta?.trusted ?? trustedConfig;
|
|
49
|
+
const base = {
|
|
50
|
+
id,
|
|
51
|
+
...(meta ? { scope: meta.scope, transport: server.transport } : {}),
|
|
52
|
+
};
|
|
53
|
+
if (!trusted) {
|
|
54
|
+
if (meta?.fromProjectMcpJson) {
|
|
55
|
+
return {
|
|
56
|
+
...base,
|
|
57
|
+
discovery: 'pending_trust',
|
|
58
|
+
toolCount: 0,
|
|
59
|
+
error: 'Project .mcp.json server disabled until workspace is trusted (/mcp trust)',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return { ...base, discovery: 'trust_required', toolCount: 0 };
|
|
63
|
+
}
|
|
64
|
+
const expanded = expandMcpServerConfig(server, envLookup);
|
|
65
|
+
if (expanded.missingVars.length > 0) {
|
|
66
|
+
return {
|
|
67
|
+
...base,
|
|
68
|
+
discovery: 'unavailable',
|
|
69
|
+
toolCount: 0,
|
|
70
|
+
error: `Missing environment variable(s): ${expanded.missingVars.join(', ')}`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const connection = await openMcpServer(id, adapterConfiguration(expanded.config), root, startupSignal);
|
|
75
|
+
return {
|
|
76
|
+
...base,
|
|
77
|
+
discovery: 'ready',
|
|
78
|
+
toolCount: connection.bindings.length,
|
|
79
|
+
connection,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
const needsAuth = error instanceof McpError && error.kind === 'auth_required';
|
|
84
|
+
return {
|
|
85
|
+
...base,
|
|
86
|
+
discovery: needsAuth ? 'auth_required' : 'unavailable',
|
|
87
|
+
toolCount: 0,
|
|
88
|
+
...(meta || (error instanceof McpError && error.kind !== 'protocol_error')
|
|
89
|
+
? {
|
|
90
|
+
error: sanitizeMcpError(error, [
|
|
91
|
+
...(config.mcpSecrets ?? []),
|
|
92
|
+
...expanded.expandedSecrets,
|
|
93
|
+
]),
|
|
94
|
+
}
|
|
95
|
+
: {}),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}));
|
|
99
|
+
ctx.effect(() => async () => {
|
|
100
|
+
const clients = await discovery;
|
|
101
|
+
await Promise.allSettled(clients.map(async ({ connection }) => connection?.close()));
|
|
102
|
+
});
|
|
103
|
+
const clients = await discovery;
|
|
104
|
+
startupSignal.throwIfAborted();
|
|
105
|
+
const remote = clients
|
|
106
|
+
.flatMap(({ connection }) => connection?.bindings ?? [])
|
|
107
|
+
.sort((a, b) => a.definition.name < b.definition.name ? -1 : a.definition.name > b.definition.name ? 1 : 0);
|
|
108
|
+
const sets = await tools.setMcpDefinitions(remote.map(({ definition }) => definition), clients.map(({ connection: _connection, ...summary }) => summary));
|
|
109
|
+
startupSignal.throwIfAborted();
|
|
110
|
+
for (const { definition, handler } of remote)
|
|
111
|
+
ctx.effect(() => tools.registry.register(definition, handler, sets.mcpVersions, {
|
|
112
|
+
order: { tier: 'shared', priority: sharedToolPriority.mcp },
|
|
113
|
+
}));
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { ProcessManager, ProcessManagerOptions } from '@saturn-universe/tools';
|
|
3
|
+
declare module '@deepseek-ai/cordis' {
|
|
4
|
+
interface Context {
|
|
5
|
+
saturnProcessManager?: ProcessManager;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export declare function createProcessManagerPlugin(root: string, options: Omit<ProcessManagerOptions, 'directory'>): {
|
|
9
|
+
name: string;
|
|
10
|
+
apply(ctx: Context): void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { createProcessManager } from '@saturn-universe/tools';
|
|
3
|
+
import { registerToolGuidance } from './tool-guidance.js';
|
|
4
|
+
function processGuidance(visible) {
|
|
5
|
+
const handles = ['read_process', 'write_process', 'stop_process'].filter((tool) => visible.has(tool));
|
|
6
|
+
const commands = [];
|
|
7
|
+
if (visible.has('run_process'))
|
|
8
|
+
commands.push('Use run_process only for synchronous commands of 30 seconds or less.');
|
|
9
|
+
if (visible.has('start_process'))
|
|
10
|
+
commands.push('Use start_process to obtain a handle for long-running commands, services, or interactive processes.');
|
|
11
|
+
if (handles.length)
|
|
12
|
+
commands.push(`Manage process handles with ${handles.join(', ')}.`);
|
|
13
|
+
if (!commands.length)
|
|
14
|
+
return '';
|
|
15
|
+
if (visible.has('stop_process'))
|
|
16
|
+
commands.push('Clean up processes when finished using stop_process.');
|
|
17
|
+
else if (visible.has('start_process'))
|
|
18
|
+
commands.push('Start only processes you can clean up when finished.');
|
|
19
|
+
return [
|
|
20
|
+
`Process lifecycle: ${commands.join(' ')}`,
|
|
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
|
+
].join('\n');
|
|
23
|
+
}
|
|
24
|
+
export function createProcessManagerPlugin(root, options) {
|
|
25
|
+
return {
|
|
26
|
+
name: 'process-manager',
|
|
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
|
+
});
|
|
35
|
+
ctx.provide('saturnProcessManager', manager);
|
|
36
|
+
registerToolGuidance(ctx, 'process-tool-guidance', -20, processGuidance);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { ToolBinding } from '@saturn-universe/core';
|
|
3
|
+
import type { SandboxManager } from '../../sandbox-manager.js';
|
|
4
|
+
export declare const sandboxTargetUpToolName = "sandbox_target_up";
|
|
5
|
+
export declare const sandboxTargetDownToolName = "sandbox_target_down";
|
|
6
|
+
export declare const sandboxTargetLogsToolName = "sandbox_target_logs";
|
|
7
|
+
export declare const sandboxTargetToolNames: Set<string>;
|
|
8
|
+
export declare function createSandboxTargetToolBindings(sandbox: SandboxManager): readonly ToolBinding[];
|
|
9
|
+
export declare function createSandboxTargetToolsPlugin(): {
|
|
10
|
+
name: string;
|
|
11
|
+
inject: string[];
|
|
12
|
+
apply(ctx: Context, startupSignal: AbortSignal): Promise<void>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { RuntimeError } from '@saturn-universe/core';
|
|
2
|
+
export const sandboxTargetUpToolName = 'sandbox_target_up';
|
|
3
|
+
export const sandboxTargetDownToolName = 'sandbox_target_down';
|
|
4
|
+
export const sandboxTargetLogsToolName = 'sandbox_target_logs';
|
|
5
|
+
export const sandboxTargetToolNames = new Set([
|
|
6
|
+
sandboxTargetUpToolName,
|
|
7
|
+
sandboxTargetDownToolName,
|
|
8
|
+
sandboxTargetLogsToolName,
|
|
9
|
+
]);
|
|
10
|
+
function toTargetToolError(error) {
|
|
11
|
+
if (error instanceof RuntimeError) {
|
|
12
|
+
return {
|
|
13
|
+
effect: 'none',
|
|
14
|
+
outcome: {
|
|
15
|
+
status: 'error',
|
|
16
|
+
error: {
|
|
17
|
+
code: error.code,
|
|
18
|
+
message: error.message,
|
|
19
|
+
retryable: false,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
effect: 'none',
|
|
26
|
+
outcome: {
|
|
27
|
+
status: 'error',
|
|
28
|
+
error: {
|
|
29
|
+
code: 'SANDBOX_TARGET_FAILED',
|
|
30
|
+
message: error instanceof Error ? error.message : String(error),
|
|
31
|
+
retryable: false,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function createSandboxTargetToolBindings(sandbox) {
|
|
37
|
+
const targetUp = {
|
|
38
|
+
definition: {
|
|
39
|
+
name: sandboxTargetUpToolName,
|
|
40
|
+
version: '1',
|
|
41
|
+
description: 'Start an isolated target service container on a per-run --internal Docker network (no external internet access) with a snapshot of the current /workspace, optional read-only seed files (such as /flag), and allowlisted capabilities (e.g. SYS_CHROOT). Returns { targetId, name, host, port, network, status, initialLogs } so the main sandbox can connect to host:port.',
|
|
42
|
+
inputSchema: {
|
|
43
|
+
type: 'object',
|
|
44
|
+
properties: {
|
|
45
|
+
name: {
|
|
46
|
+
type: 'string',
|
|
47
|
+
minLength: 1,
|
|
48
|
+
maxLength: 48,
|
|
49
|
+
description: 'Optional target alias / hostname on the internal network (default: "target").',
|
|
50
|
+
},
|
|
51
|
+
command: {
|
|
52
|
+
type: 'string',
|
|
53
|
+
minLength: 1,
|
|
54
|
+
maxLength: 4096,
|
|
55
|
+
description: 'Shell command executed inside the target container /workspace.',
|
|
56
|
+
},
|
|
57
|
+
port: {
|
|
58
|
+
type: 'integer',
|
|
59
|
+
minimum: 1024,
|
|
60
|
+
maximum: 65535,
|
|
61
|
+
description: 'TCP port the target service listens on (1024..65535).',
|
|
62
|
+
},
|
|
63
|
+
capabilities: {
|
|
64
|
+
type: 'array',
|
|
65
|
+
maxItems: 8,
|
|
66
|
+
items: { type: 'string', minLength: 1, maxLength: 64 },
|
|
67
|
+
description: 'Optional allowlisted Linux capabilities for the target (e.g. ["SYS_CHROOT"]).',
|
|
68
|
+
},
|
|
69
|
+
seedFiles: {
|
|
70
|
+
type: 'object',
|
|
71
|
+
additionalProperties: { type: 'string' },
|
|
72
|
+
description: 'Optional map of absolute container paths (e.g. "/flag") to read-only file contents.',
|
|
73
|
+
},
|
|
74
|
+
readyTimeoutMs: {
|
|
75
|
+
type: 'integer',
|
|
76
|
+
minimum: 500,
|
|
77
|
+
maximum: 60000,
|
|
78
|
+
description: 'Milliseconds to wait for container running readiness (default: 10000).',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
required: ['command', 'port'],
|
|
82
|
+
additionalProperties: false,
|
|
83
|
+
},
|
|
84
|
+
source: { kind: 'builtin' },
|
|
85
|
+
effects: 'non_idempotent_write',
|
|
86
|
+
supportsIdempotencyKey: false,
|
|
87
|
+
supportsReconcile: false,
|
|
88
|
+
concurrency: 'serial_per_run',
|
|
89
|
+
timeoutMs: 90_000,
|
|
90
|
+
},
|
|
91
|
+
handler: {
|
|
92
|
+
async invoke(input, ctx) {
|
|
93
|
+
const parsed = input;
|
|
94
|
+
try {
|
|
95
|
+
const result = await sandbox.startTarget({
|
|
96
|
+
runId: ctx.runId,
|
|
97
|
+
agentSessionId: ctx.agentSessionId,
|
|
98
|
+
...(parsed.name !== undefined ? { name: parsed.name } : {}),
|
|
99
|
+
command: parsed.command,
|
|
100
|
+
port: parsed.port,
|
|
101
|
+
...(parsed.capabilities !== undefined ? { capabilities: parsed.capabilities } : {}),
|
|
102
|
+
...(parsed.seedFiles !== undefined ? { seedFiles: parsed.seedFiles } : {}),
|
|
103
|
+
...(parsed.readyTimeoutMs !== undefined ? { readyTimeoutMs: parsed.readyTimeoutMs } : {}),
|
|
104
|
+
});
|
|
105
|
+
const data = {
|
|
106
|
+
targetId: result.targetId,
|
|
107
|
+
name: result.name,
|
|
108
|
+
host: result.host,
|
|
109
|
+
port: result.port,
|
|
110
|
+
network: result.network,
|
|
111
|
+
status: result.status,
|
|
112
|
+
initialLogs: result.initialLogs,
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
effect: 'applied',
|
|
116
|
+
outcome: {
|
|
117
|
+
status: 'success',
|
|
118
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
119
|
+
data,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
return toTargetToolError(error);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
const targetDown = {
|
|
130
|
+
definition: {
|
|
131
|
+
name: sandboxTargetDownToolName,
|
|
132
|
+
version: '1',
|
|
133
|
+
description: 'Stop and remove an isolated target service container started by sandbox_target_up.',
|
|
134
|
+
inputSchema: {
|
|
135
|
+
type: 'object',
|
|
136
|
+
properties: {
|
|
137
|
+
name: {
|
|
138
|
+
type: 'string',
|
|
139
|
+
minLength: 1,
|
|
140
|
+
maxLength: 48,
|
|
141
|
+
description: 'Target name to stop (default: "target").',
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
additionalProperties: false,
|
|
145
|
+
},
|
|
146
|
+
source: { kind: 'builtin' },
|
|
147
|
+
effects: 'non_idempotent_write',
|
|
148
|
+
supportsIdempotencyKey: false,
|
|
149
|
+
supportsReconcile: false,
|
|
150
|
+
concurrency: 'serial_per_run',
|
|
151
|
+
timeoutMs: 30_000,
|
|
152
|
+
},
|
|
153
|
+
handler: {
|
|
154
|
+
async invoke(input, ctx) {
|
|
155
|
+
const parsed = (input ?? {});
|
|
156
|
+
try {
|
|
157
|
+
const result = await sandbox.stopTarget(ctx.runId, parsed.name, ctx.agentSessionId);
|
|
158
|
+
const data = {
|
|
159
|
+
targetId: result.targetId,
|
|
160
|
+
name: result.name,
|
|
161
|
+
status: result.status,
|
|
162
|
+
};
|
|
163
|
+
return {
|
|
164
|
+
effect: 'applied',
|
|
165
|
+
outcome: {
|
|
166
|
+
status: 'success',
|
|
167
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
168
|
+
data,
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
return toTargetToolError(error);
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
const targetLogs = {
|
|
179
|
+
definition: {
|
|
180
|
+
name: sandboxTargetLogsToolName,
|
|
181
|
+
version: '1',
|
|
182
|
+
description: 'Read recent stdout/stderr logs from a running target container started by sandbox_target_up.',
|
|
183
|
+
inputSchema: {
|
|
184
|
+
type: 'object',
|
|
185
|
+
properties: {
|
|
186
|
+
name: {
|
|
187
|
+
type: 'string',
|
|
188
|
+
minLength: 1,
|
|
189
|
+
maxLength: 48,
|
|
190
|
+
description: 'Target name to inspect (default: "target").',
|
|
191
|
+
},
|
|
192
|
+
tailLines: {
|
|
193
|
+
type: 'integer',
|
|
194
|
+
minimum: 1,
|
|
195
|
+
maximum: 500,
|
|
196
|
+
description: 'Number of trailing log lines to fetch (default: 80).',
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
additionalProperties: false,
|
|
200
|
+
},
|
|
201
|
+
source: { kind: 'builtin' },
|
|
202
|
+
effects: 'read',
|
|
203
|
+
supportsIdempotencyKey: false,
|
|
204
|
+
supportsReconcile: false,
|
|
205
|
+
concurrency: 'parallel',
|
|
206
|
+
timeoutMs: 15_000,
|
|
207
|
+
},
|
|
208
|
+
handler: {
|
|
209
|
+
async invoke(input, ctx) {
|
|
210
|
+
const parsed = (input ?? {});
|
|
211
|
+
try {
|
|
212
|
+
const result = await sandbox.getTargetLogs(ctx.runId, parsed.name, parsed.tailLines, ctx.agentSessionId);
|
|
213
|
+
const data = {
|
|
214
|
+
targetId: result.targetId,
|
|
215
|
+
name: result.name,
|
|
216
|
+
logs: result.logs,
|
|
217
|
+
truncated: result.truncated,
|
|
218
|
+
};
|
|
219
|
+
return {
|
|
220
|
+
effect: 'none',
|
|
221
|
+
outcome: {
|
|
222
|
+
status: 'success',
|
|
223
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
224
|
+
data,
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
return toTargetToolError(error);
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
return [targetUp, targetDown, targetLogs];
|
|
235
|
+
}
|
|
236
|
+
export function createSandboxTargetToolsPlugin() {
|
|
237
|
+
return {
|
|
238
|
+
name: 'sandbox-target-tools',
|
|
239
|
+
inject: ['saturnTools', 'saturnSandbox'],
|
|
240
|
+
async apply(ctx, startupSignal) {
|
|
241
|
+
const sandbox = ctx.get('saturnSandbox');
|
|
242
|
+
if (!sandbox?.isTargetServicesEnabled()) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const versions = await ctx.saturnTools.pluginToolVersions();
|
|
246
|
+
startupSignal.throwIfAborted();
|
|
247
|
+
const bindings = createSandboxTargetToolBindings(sandbox);
|
|
248
|
+
for (const [index, binding] of bindings.entries()) {
|
|
249
|
+
ctx.effect(() => ctx.saturnTools.registry.register(binding.definition, binding.handler, versions, {
|
|
250
|
+
order: { tier: 'tail', priority: 5 + index },
|
|
251
|
+
}));
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { RunConfig } from '@saturn-universe/core';
|
|
3
|
+
import type { ContributionScope } from '../scoped-layers.js';
|
|
4
|
+
export declare function registerToolGuidance(ctx: Context, id: string, priority: number, guidance: (visible: ReadonlySet<string>, config: RunConfig) => string, scope?: ContributionScope): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function registerToolGuidance(ctx, id, priority, guidance, scope) {
|
|
2
|
+
// Tools can also run in a standalone Host without a context composer.
|
|
3
|
+
const context = ctx.get('saturnContext');
|
|
4
|
+
if (!context)
|
|
5
|
+
return;
|
|
6
|
+
const { registry } = ctx.saturnTools;
|
|
7
|
+
const version = '1';
|
|
8
|
+
ctx.effect(() => context.registerProvider({
|
|
9
|
+
id,
|
|
10
|
+
version,
|
|
11
|
+
phase: 'tools',
|
|
12
|
+
priority,
|
|
13
|
+
required: false,
|
|
14
|
+
timeoutMs: 15_000,
|
|
15
|
+
async collect({ config }) {
|
|
16
|
+
const specs = await registry.specs(config);
|
|
17
|
+
const text = guidance(new Set(specs.map(({ canonicalName }) => canonicalName)), config);
|
|
18
|
+
return {
|
|
19
|
+
providerId: id,
|
|
20
|
+
version,
|
|
21
|
+
prompt: text
|
|
22
|
+
? [{ id, source: id, priority, authority: 'configured_instruction', required: false, text }]
|
|
23
|
+
: [],
|
|
24
|
+
background: [],
|
|
25
|
+
tools: [],
|
|
26
|
+
relevantTurnIds: [],
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
}, scope ? { scope } : {}));
|
|
30
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { AgentSessionId, ModelCapabilities, RunConfig, TeamConfig, ToolDefinition, ToolHandler, ToolRegistrationOptions, ToolPermissionPolicy } from '@saturn-universe/core';
|
|
3
|
+
import type { HostMcpServerSummary } from '@saturn-universe/protocol';
|
|
4
|
+
import { Registry } from '@saturn-universe/tools';
|
|
5
|
+
import type { ProviderCatalog } from '../../provider-catalog.js';
|
|
6
|
+
import type { PluginToolGrants } from '../../plugin-tool-grants.js';
|
|
7
|
+
import type { ContributionScope, ContributionTarget } from '../scoped-layers.js';
|
|
8
|
+
export interface McpServerConfigurationMeta {
|
|
9
|
+
readonly scope: 'user' | 'project' | 'workspace' | 'explicit';
|
|
10
|
+
readonly source: string;
|
|
11
|
+
readonly trusted: boolean;
|
|
12
|
+
readonly fromProjectMcpJson?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface ToolConfiguration {
|
|
15
|
+
workspaceTools?: ProviderCatalog['workspaceTools'];
|
|
16
|
+
processManager?: boolean;
|
|
17
|
+
builtinAgentTools?: boolean;
|
|
18
|
+
counter?: ProviderCatalog['counter'];
|
|
19
|
+
mcpServers?: ProviderCatalog['mcpServers'];
|
|
20
|
+
mcpServerMeta?: Readonly<Record<string, McpServerConfigurationMeta>>;
|
|
21
|
+
mcpEnvLookup?: (name: string) => string | undefined;
|
|
22
|
+
mcpSecrets?: readonly string[];
|
|
23
|
+
pluginTools?: PluginToolGrants;
|
|
24
|
+
builtinPluginTools?: PluginToolGrants;
|
|
25
|
+
allowedTools?: readonly string[];
|
|
26
|
+
deniedTools?: readonly string[];
|
|
27
|
+
workerAllowTargetServices?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export type McpServer = NonNullable<ToolConfiguration['mcpServers']>[string];
|
|
30
|
+
interface WorkspaceDefinitions {
|
|
31
|
+
workspace: ToolDefinition[];
|
|
32
|
+
legacyProcesses: ToolDefinition[];
|
|
33
|
+
phaseOne: ToolDefinition[];
|
|
34
|
+
phaseOneTeamRead: ToolDefinition;
|
|
35
|
+
phaseTwo: ToolDefinition[];
|
|
36
|
+
patchTools: ToolDefinition[];
|
|
37
|
+
teamFiles: ToolDefinition[];
|
|
38
|
+
patchTeamFiles: ToolDefinition[];
|
|
39
|
+
}
|
|
40
|
+
export type McpDiscovery = HostMcpServerSummary;
|
|
41
|
+
declare module '@deepseek-ai/cordis' {
|
|
42
|
+
interface Context {
|
|
43
|
+
saturnTools: ReturnType<typeof createToolsService>;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export declare const interactiveToolPolicies: {
|
|
47
|
+
strict: string;
|
|
48
|
+
default: string;
|
|
49
|
+
full: string;
|
|
50
|
+
};
|
|
51
|
+
export declare const legacyInteractiveToolPolicies: readonly ["interactive-default-v1", "interactive-full-v1"];
|
|
52
|
+
export declare function isInteractiveToolPolicy(policyVersion: string): boolean;
|
|
53
|
+
export declare const synchronousProcessTools: Set<string>;
|
|
54
|
+
export declare const plannerWorkspaceTools: string[];
|
|
55
|
+
export declare const sharedToolPriority: {
|
|
56
|
+
readonly applyPatch: 0;
|
|
57
|
+
readonly counter: 10;
|
|
58
|
+
readonly legacyProcess: 20;
|
|
59
|
+
readonly workspace: 30;
|
|
60
|
+
readonly resultReader: 40;
|
|
61
|
+
readonly discovery: 42;
|
|
62
|
+
readonly mcp: 50;
|
|
63
|
+
};
|
|
64
|
+
declare function createToolsService(config: ToolConfiguration, trustedConfig: boolean, hash: (value: unknown) => string): {
|
|
65
|
+
registry: Registry;
|
|
66
|
+
policy: ToolPermissionPolicy;
|
|
67
|
+
registerTool(definition: ToolDefinition, handler: ToolHandler, versions: readonly string[], { scope, ...options }?: ToolRegistrationOptions & {
|
|
68
|
+
scope?: ContributionScope;
|
|
69
|
+
}): () => void;
|
|
70
|
+
agentSessionIds: () => readonly AgentSessionId[];
|
|
71
|
+
pluginToolVersions(): Promise<string[]>;
|
|
72
|
+
readonly mcpServers: HostMcpServerSummary[];
|
|
73
|
+
setWorkspaceDefinitions(definitions: WorkspaceDefinitions): Promise<{
|
|
74
|
+
mcpVersions: string[];
|
|
75
|
+
legacyProcessVersions: string[];
|
|
76
|
+
patchVersions: string[];
|
|
77
|
+
patchEditVersions: string[];
|
|
78
|
+
expandedProcessVersions: string[];
|
|
79
|
+
phaseOneVersions: (name: string) => string[];
|
|
80
|
+
phaseTwoVersions: string[];
|
|
81
|
+
defaultVersions: string[];
|
|
82
|
+
spawnTeamV2Versions: string[];
|
|
83
|
+
counterVersions: string[];
|
|
84
|
+
readerVersions: string[];
|
|
85
|
+
workspaceVersions: (name: string) => string[];
|
|
86
|
+
}>;
|
|
87
|
+
setAgentDefinitions(counter: ToolDefinition | undefined, reader: ToolDefinition | undefined): Promise<{
|
|
88
|
+
mcpVersions: string[];
|
|
89
|
+
legacyProcessVersions: string[];
|
|
90
|
+
patchVersions: string[];
|
|
91
|
+
patchEditVersions: string[];
|
|
92
|
+
expandedProcessVersions: string[];
|
|
93
|
+
phaseOneVersions: (name: string) => string[];
|
|
94
|
+
phaseTwoVersions: string[];
|
|
95
|
+
defaultVersions: string[];
|
|
96
|
+
spawnTeamV2Versions: string[];
|
|
97
|
+
counterVersions: string[];
|
|
98
|
+
readerVersions: string[];
|
|
99
|
+
workspaceVersions: (name: string) => string[];
|
|
100
|
+
}>;
|
|
101
|
+
setMcpDefinitions(definitions: ToolDefinition[], discovery: McpDiscovery[]): Promise<{
|
|
102
|
+
mcpVersions: string[];
|
|
103
|
+
legacyProcessVersions: string[];
|
|
104
|
+
patchVersions: string[];
|
|
105
|
+
patchEditVersions: string[];
|
|
106
|
+
expandedProcessVersions: string[];
|
|
107
|
+
phaseOneVersions: (name: string) => string[];
|
|
108
|
+
phaseTwoVersions: string[];
|
|
109
|
+
defaultVersions: string[];
|
|
110
|
+
spawnTeamV2Versions: string[];
|
|
111
|
+
counterVersions: string[];
|
|
112
|
+
readerVersions: string[];
|
|
113
|
+
workspaceVersions: (name: string) => string[];
|
|
114
|
+
}>;
|
|
115
|
+
defaultVersion(capabilities: ModelCapabilities): string;
|
|
116
|
+
plannerVersion(capabilities: ModelCapabilities): "1" | "planner";
|
|
117
|
+
freeze: (runConfig: RunConfig, target?: ContributionTarget) => Pick<RunConfig, "toolSnapshot"> & {
|
|
118
|
+
pluginBindings: NonNullable<RunConfig["pluginBindings"]>;
|
|
119
|
+
};
|
|
120
|
+
freezeWorker(runConfig: RunConfig, team: TeamConfig, agentSessionId?: AgentSessionId, capabilities?: ModelCapabilities, options?: {
|
|
121
|
+
readonly depth?: number;
|
|
122
|
+
}): Promise<RunConfig>;
|
|
123
|
+
};
|
|
124
|
+
export declare function createToolsCorePlugin(config: ToolConfiguration, trustedConfig: boolean, hash: (value: unknown) => string): {
|
|
125
|
+
name: string;
|
|
126
|
+
apply(ctx: Context): void;
|
|
127
|
+
};
|
|
128
|
+
export {};
|