@saturn-universe/runtime-host 0.0.0-stage → 0.1.0
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 +472 -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 +471 -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,486 @@
|
|
|
1
|
+
import { configForDerivedAgent, RuntimeError } from '@saturn-universe/core';
|
|
2
|
+
import { Registry, dataReviewToolName, dataReviewToolSet, outsideWorkspacePrefix, plannerToolName, spawnTeamToolName, teamNotifyParentToolName, todoWriteToolName, } from '@saturn-universe/tools';
|
|
3
|
+
import { resolveWorkerReasoning } from '../../provider-catalog.js';
|
|
4
|
+
import { skillToolName } from '../../skills-runtime.js';
|
|
5
|
+
import { contributionScopeKey, globalScope, matchesScope, primaryRole, ScopedLayers, validateContributionScope, } from '../scoped-layers.js';
|
|
6
|
+
import { contributionIdentity, registerPluginContribution, trackPluginTool, } from '../plugin-contributions.js';
|
|
7
|
+
import { sandboxTargetToolNames } from './sandbox-target-tools-plugin.js';
|
|
8
|
+
import { webToolNames } from './web-search-tools-plugin.js';
|
|
9
|
+
export const interactiveToolPolicies = {
|
|
10
|
+
strict: 'interactive-strict-v1',
|
|
11
|
+
default: 'interactive-default-v2',
|
|
12
|
+
full: 'interactive-full-v2',
|
|
13
|
+
};
|
|
14
|
+
export const legacyInteractiveToolPolicies = ['interactive-default-v1', 'interactive-full-v1'];
|
|
15
|
+
export function isInteractiveToolPolicy(policyVersion) {
|
|
16
|
+
return (Object.values(interactiveToolPolicies).includes(policyVersion) ||
|
|
17
|
+
legacyInteractiveToolPolicies.includes(policyVersion));
|
|
18
|
+
}
|
|
19
|
+
const workspaceToolSetVersion = '8';
|
|
20
|
+
const phaseOneToolSetVersion = '7';
|
|
21
|
+
const patchWorkspaceToolSetVersion = '6';
|
|
22
|
+
const previousWorkspaceToolSetVersion = '5';
|
|
23
|
+
const managedProcessTools = new Set(['start_process', 'read_process', 'write_process', 'stop_process']);
|
|
24
|
+
export const synchronousProcessTools = new Set(['run_process', 'run_readonly_command']);
|
|
25
|
+
export const plannerWorkspaceTools = ['list_dir', 'read_file', 'search_files', 'run_readonly_command'];
|
|
26
|
+
// Shared registration blocks preserve the model-visible order of every historical tool set.
|
|
27
|
+
export const sharedToolPriority = {
|
|
28
|
+
applyPatch: 0,
|
|
29
|
+
counter: 10,
|
|
30
|
+
legacyProcess: 20,
|
|
31
|
+
workspace: 30,
|
|
32
|
+
resultReader: 40,
|
|
33
|
+
discovery: 42,
|
|
34
|
+
mcp: 50,
|
|
35
|
+
};
|
|
36
|
+
function readiness() {
|
|
37
|
+
let resolve;
|
|
38
|
+
const promise = new Promise((ready) => {
|
|
39
|
+
resolve = ready;
|
|
40
|
+
});
|
|
41
|
+
return { promise, resolve };
|
|
42
|
+
}
|
|
43
|
+
function createToolsService(config, trustedConfig, hash) {
|
|
44
|
+
const workspaceVersions = config.workspaceTools
|
|
45
|
+
? [
|
|
46
|
+
'2',
|
|
47
|
+
'3',
|
|
48
|
+
previousWorkspaceToolSetVersion,
|
|
49
|
+
patchWorkspaceToolSetVersion,
|
|
50
|
+
phaseOneToolSetVersion,
|
|
51
|
+
workspaceToolSetVersion,
|
|
52
|
+
]
|
|
53
|
+
: [];
|
|
54
|
+
const supportedVersions = ['1', '4', ...workspaceVersions, 'planner', dataReviewToolSet];
|
|
55
|
+
const registry = new Registry('1', supportedVersions, hash);
|
|
56
|
+
const registerRaw = registry.register.bind(registry);
|
|
57
|
+
const scoped = new ScopedLayers();
|
|
58
|
+
const knownPluginTools = new Map();
|
|
59
|
+
function registerTool(definition, handler, versions, options, scope) {
|
|
60
|
+
const { name, version, scopeKey } = definition;
|
|
61
|
+
const identity = { name, version, ...(scopeKey === undefined ? {} : { scopeKey }) };
|
|
62
|
+
const key = { kind: 'tool', id: name, version, ...(scopeKey === undefined ? {} : { scopeKey }) };
|
|
63
|
+
const toolSets = scope && scope.kind !== 'global' ? [...versions, 'planner'] : [...versions];
|
|
64
|
+
return registerPluginContribution(key, (managed) => {
|
|
65
|
+
const addScope = () => (scope ? scoped.register(scope, name, { ...identity, toolSets }) : undefined);
|
|
66
|
+
let stopScope = addScope();
|
|
67
|
+
let stopTool;
|
|
68
|
+
try {
|
|
69
|
+
stopTool = registerRaw(definition, trackPluginTool(handler), scopeKey === undefined || !scope ? toolSets : [], options);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
stopScope?.();
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
const ref = contributionIdentity(key);
|
|
76
|
+
const previous = knownPluginTools.get(ref);
|
|
77
|
+
if (managed)
|
|
78
|
+
knownPluginTools.set(ref, { ...identity, toolSets, scope: scope ?? globalScope });
|
|
79
|
+
return {
|
|
80
|
+
deactivate() {
|
|
81
|
+
stopScope?.();
|
|
82
|
+
stopScope = undefined;
|
|
83
|
+
stopTool();
|
|
84
|
+
},
|
|
85
|
+
activate() {
|
|
86
|
+
stopScope = addScope();
|
|
87
|
+
registry.activate(name, version, scopeKey);
|
|
88
|
+
},
|
|
89
|
+
release(retired) {
|
|
90
|
+
registry.release(name, version, scopeKey);
|
|
91
|
+
if (!retired) {
|
|
92
|
+
if (previous)
|
|
93
|
+
knownPluginTools.set(ref, previous);
|
|
94
|
+
else
|
|
95
|
+
knownPluginTools.delete(ref);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
registry.register = (definition, handler, versions = supportedVersions, options = {}) => registerTool(definition, handler, versions, options);
|
|
102
|
+
const mcpConfig = new Map(Object.entries(config.mcpServers ?? {}));
|
|
103
|
+
const isMcpServerTrusted = (id) => config.mcpServerMeta?.[id]?.trusted ?? trustedConfig;
|
|
104
|
+
const activeMcpServers = Object.fromEntries([...mcpConfig].filter(([id]) => isMcpServerTrusted(id)));
|
|
105
|
+
const hasActiveMcp = Object.keys(activeMcpServers).length > 0;
|
|
106
|
+
const pluginTools = new Map(Object.entries({
|
|
107
|
+
...(config.builtinPluginTools ?? {}),
|
|
108
|
+
...(trustedConfig ? (config.pluginTools ?? {}) : {}),
|
|
109
|
+
}));
|
|
110
|
+
let workspaceDefinitions = {
|
|
111
|
+
workspace: [],
|
|
112
|
+
legacyProcesses: [],
|
|
113
|
+
phaseOne: [],
|
|
114
|
+
phaseTwo: [],
|
|
115
|
+
patchTools: [],
|
|
116
|
+
teamFiles: [],
|
|
117
|
+
patchTeamFiles: [],
|
|
118
|
+
};
|
|
119
|
+
let agentDefinitions = { counter: undefined, reader: undefined };
|
|
120
|
+
let mcpServers = [];
|
|
121
|
+
let mcpVersions = [];
|
|
122
|
+
let currentMcpVersion;
|
|
123
|
+
const workspaceNames = new Set();
|
|
124
|
+
const workspaceReady = readiness();
|
|
125
|
+
const agentReady = readiness();
|
|
126
|
+
const mcpReady = readiness();
|
|
127
|
+
if (!config.workspaceTools)
|
|
128
|
+
workspaceReady.resolve();
|
|
129
|
+
if (config.builtinAgentTools === false)
|
|
130
|
+
agentReady.resolve();
|
|
131
|
+
if (!mcpConfig.size)
|
|
132
|
+
mcpReady.resolve([]);
|
|
133
|
+
// All contributors publish definitions before any of them registers version membership.
|
|
134
|
+
// The version digest uses the historical hash input, independently of Registry display order.
|
|
135
|
+
const toolSets = Promise.all([workspaceReady.promise, agentReady.promise, mcpReady.promise]).then(([, , remote]) => {
|
|
136
|
+
const { workspace, legacyProcesses, phaseOne, phaseTwo } = workspaceDefinitions;
|
|
137
|
+
const { counter, reader } = agentDefinitions;
|
|
138
|
+
const definitionsFor = (local) => [
|
|
139
|
+
...(counter ? [counter] : []),
|
|
140
|
+
...local,
|
|
141
|
+
...remote,
|
|
142
|
+
];
|
|
143
|
+
const definitions = definitionsFor(workspace);
|
|
144
|
+
const legacyDefinitions = definitions
|
|
145
|
+
.filter(({ name }) => !managedProcessTools.has(name))
|
|
146
|
+
.map((definition) => legacyProcesses.find(({ name }) => name === definition.name) ?? definition);
|
|
147
|
+
const mcpVersion = (definitions) => 'mcp-' + hash({ servers: activeMcpServers, definitions });
|
|
148
|
+
const legacyVersion = hasActiveMcp ? mcpVersion(legacyDefinitions) : undefined;
|
|
149
|
+
const legacyReaderVersion = legacyVersion && reader ? mcpVersion([...legacyDefinitions, reader]) : legacyVersion;
|
|
150
|
+
const withReader = (items) => (reader ? [...items, reader] : items);
|
|
151
|
+
const modernMcpVersion = hasActiveMcp ? mcpVersion(withReader(definitions)) : undefined;
|
|
152
|
+
const phaseOneByName = new Map(phaseOne.map((definition) => [definition.name, definition]));
|
|
153
|
+
const phaseTwoByName = new Map(phaseTwo.map((definition) => [definition.name, definition]));
|
|
154
|
+
const upgrade = (local, replacements) => [
|
|
155
|
+
...local.map((definition) => replacements.get(definition.name) ?? definition),
|
|
156
|
+
...[...replacements.values()].filter(({ name }) => !local.some((definition) => definition.name === name)),
|
|
157
|
+
];
|
|
158
|
+
let phaseOneMcpVersion = modernMcpVersion;
|
|
159
|
+
if (modernMcpVersion && phaseOne.length) {
|
|
160
|
+
const upgraded = upgrade(workspace, phaseOneByName);
|
|
161
|
+
phaseOneMcpVersion = mcpVersion(withReader(definitionsFor(upgraded)));
|
|
162
|
+
currentMcpVersion = mcpVersion(withReader(definitionsFor(upgrade(upgraded, phaseTwoByName))));
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
currentMcpVersion = modernMcpVersion;
|
|
166
|
+
}
|
|
167
|
+
const legacyMcpVersions = [
|
|
168
|
+
...new Set([legacyVersion, legacyReaderVersion].filter((value) => Boolean(value))),
|
|
169
|
+
];
|
|
170
|
+
mcpVersions = [
|
|
171
|
+
...new Set([
|
|
172
|
+
...legacyMcpVersions,
|
|
173
|
+
...[modernMcpVersion, phaseOneMcpVersion, currentMcpVersion].filter((value) => value !== undefined),
|
|
174
|
+
]),
|
|
175
|
+
];
|
|
176
|
+
supportedVersions.push(...mcpVersions);
|
|
177
|
+
const legacyProcessVersions = ['2', '3', '4', ...legacyMcpVersions];
|
|
178
|
+
const patchEditVersions = [patchWorkspaceToolSetVersion, phaseOneToolSetVersion];
|
|
179
|
+
const patchVersions = [...patchEditVersions, workspaceToolSetVersion];
|
|
180
|
+
const phaseTwoVersions = [
|
|
181
|
+
workspaceToolSetVersion,
|
|
182
|
+
...(currentMcpVersion && phaseTwo.length ? [currentMcpVersion] : []),
|
|
183
|
+
];
|
|
184
|
+
const phaseOneVersions = [
|
|
185
|
+
phaseOneToolSetVersion,
|
|
186
|
+
workspaceToolSetVersion,
|
|
187
|
+
...(phaseOneMcpVersion && phaseOneMcpVersion !== modernMcpVersion ? [phaseOneMcpVersion] : []),
|
|
188
|
+
...(currentMcpVersion && currentMcpVersion !== phaseOneMcpVersion ? [currentMcpVersion] : []),
|
|
189
|
+
];
|
|
190
|
+
const defaultVersions = [
|
|
191
|
+
'4',
|
|
192
|
+
...(config.workspaceTools ? [previousWorkspaceToolSetVersion, ...patchVersions] : []),
|
|
193
|
+
...mcpVersions,
|
|
194
|
+
];
|
|
195
|
+
return {
|
|
196
|
+
mcpVersions,
|
|
197
|
+
legacyProcessVersions,
|
|
198
|
+
patchVersions,
|
|
199
|
+
patchEditVersions,
|
|
200
|
+
expandedProcessVersions: [patchWorkspaceToolSetVersion],
|
|
201
|
+
phaseOneVersions: (name) => phaseOneVersions.filter((version) => !phaseTwoVersions.includes(version) || !phaseTwoByName.has(name)),
|
|
202
|
+
phaseTwoVersions,
|
|
203
|
+
defaultVersions,
|
|
204
|
+
spawnTeamV2Versions: defaultVersions.filter((version) => version === '4' || version === workspaceToolSetVersion || version === currentMcpVersion),
|
|
205
|
+
counterVersions: supportedVersions.filter((version) => version !== 'planner' && version !== dataReviewToolSet),
|
|
206
|
+
readerVersions: [
|
|
207
|
+
...new Set([
|
|
208
|
+
'4',
|
|
209
|
+
previousWorkspaceToolSetVersion,
|
|
210
|
+
...patchVersions,
|
|
211
|
+
'planner',
|
|
212
|
+
...(legacyReaderVersion ? [legacyReaderVersion] : []),
|
|
213
|
+
...(modernMcpVersion ? [modernMcpVersion] : []),
|
|
214
|
+
...(phaseOneMcpVersion ? [phaseOneMcpVersion] : []),
|
|
215
|
+
...(currentMcpVersion ? [currentMcpVersion] : []),
|
|
216
|
+
]),
|
|
217
|
+
],
|
|
218
|
+
workspaceVersions: (name) => supportedVersions.filter((version) => version !== '1' &&
|
|
219
|
+
version !== dataReviewToolSet &&
|
|
220
|
+
(!patchVersions.includes(version) || name !== 'edit_file') &&
|
|
221
|
+
(!synchronousProcessTools.has(name) || !legacyProcessVersions.includes(version)) &&
|
|
222
|
+
(version !== patchWorkspaceToolSetVersion ||
|
|
223
|
+
(!synchronousProcessTools.has(name) && name !== 'start_process')) &&
|
|
224
|
+
(!phaseOneVersions.includes(version) || !phaseOneByName.has(name)) &&
|
|
225
|
+
(!phaseTwoVersions.includes(version) || !phaseTwoByName.has(name)) &&
|
|
226
|
+
(!managedProcessTools.has(name) ||
|
|
227
|
+
version === previousWorkspaceToolSetVersion ||
|
|
228
|
+
patchVersions.includes(version) ||
|
|
229
|
+
version === modernMcpVersion ||
|
|
230
|
+
version === phaseOneMcpVersion ||
|
|
231
|
+
version === currentMcpVersion) &&
|
|
232
|
+
(version !== '2' || name !== 'list_dir') &&
|
|
233
|
+
(version !== 'planner' || plannerWorkspaceTools.includes(name))),
|
|
234
|
+
};
|
|
235
|
+
});
|
|
236
|
+
const policy = {
|
|
237
|
+
async evaluate({ definition, policyVersion, resources }) {
|
|
238
|
+
const deny = { decision: 'deny', reason: 'Tool permission denied' };
|
|
239
|
+
const legacy = policyVersion === '1';
|
|
240
|
+
const strict = policyVersion === interactiveToolPolicies.strict || policyVersion === 'interactive-default-v1';
|
|
241
|
+
const standard = policyVersion === interactiveToolPolicies.default;
|
|
242
|
+
const legacyFull = policyVersion === 'interactive-full-v1';
|
|
243
|
+
const full = policyVersion === interactiveToolPolicies.full;
|
|
244
|
+
if (!legacy && !strict && !standard && !legacyFull && !full)
|
|
245
|
+
return deny;
|
|
246
|
+
const { source } = definition;
|
|
247
|
+
if (source.kind === 'mcp') {
|
|
248
|
+
const server = mcpConfig.get(source.serverId);
|
|
249
|
+
if (!isMcpServerTrusted(source.serverId) ||
|
|
250
|
+
!server ||
|
|
251
|
+
(server.tools && !server.tools.includes(source.remoteName)))
|
|
252
|
+
return deny;
|
|
253
|
+
const readOnly = definition.effects === 'read' &&
|
|
254
|
+
(Boolean(server.read_only_tools?.includes(source.remoteName)) ||
|
|
255
|
+
config.mcpServerMeta?.[source.serverId]?.scope === 'user');
|
|
256
|
+
if (full || legacyFull || ((legacy || standard) && readOnly))
|
|
257
|
+
return { decision: 'allow' };
|
|
258
|
+
return { decision: 'ask', reason: 'Approve the configured MCP operation' };
|
|
259
|
+
}
|
|
260
|
+
if (source.kind === 'plugin') {
|
|
261
|
+
const grant = pluginTools.get(source.sourceId);
|
|
262
|
+
if (!grant?.allowedTools.includes(definition.name))
|
|
263
|
+
return deny;
|
|
264
|
+
const reason = 'Approve the configured plugin operation';
|
|
265
|
+
const readOnly = definition.effects === 'read' && Boolean(grant.readOnlyTools?.includes(definition.name));
|
|
266
|
+
const autoApproved = Boolean(grant.autoApproveTools?.includes(definition.name));
|
|
267
|
+
if (full)
|
|
268
|
+
return { decision: 'allow' };
|
|
269
|
+
if (legacyFull)
|
|
270
|
+
return readOnly ? { decision: 'allow' } : { decision: 'ask', reason };
|
|
271
|
+
if (standard)
|
|
272
|
+
return readOnly || autoApproved ? { decision: 'allow' } : { decision: 'ask', reason };
|
|
273
|
+
return readOnly ? { decision: 'allow' } : { decision: 'ask', reason };
|
|
274
|
+
}
|
|
275
|
+
if (source.kind !== 'builtin')
|
|
276
|
+
return deny;
|
|
277
|
+
if (definition.name === dataReviewToolName)
|
|
278
|
+
return { decision: 'allow' };
|
|
279
|
+
if (definition.name === plannerToolName)
|
|
280
|
+
return { decision: 'allow' };
|
|
281
|
+
if (definition.name === spawnTeamToolName ||
|
|
282
|
+
definition.name === todoWriteToolName ||
|
|
283
|
+
definition.name === teamNotifyParentToolName)
|
|
284
|
+
return { decision: 'allow' };
|
|
285
|
+
if (definition.name === skillToolName)
|
|
286
|
+
return { decision: 'allow' };
|
|
287
|
+
if (webToolNames.has(definition.name))
|
|
288
|
+
return { decision: 'allow' };
|
|
289
|
+
if (definition.name === agentDefinitions.reader?.name)
|
|
290
|
+
return { decision: 'allow' };
|
|
291
|
+
if (sandboxTargetToolNames.has(definition.name)) {
|
|
292
|
+
if (full || legacyFull || standard || ((legacy || strict) && definition.effects === 'read'))
|
|
293
|
+
return { decision: 'allow' };
|
|
294
|
+
return { decision: 'ask', reason: 'Approve the sandbox target container operation' };
|
|
295
|
+
}
|
|
296
|
+
if (workspaceNames.has(definition.name)) {
|
|
297
|
+
const outside = resources
|
|
298
|
+
.filter((resource) => resource.startsWith(outsideWorkspacePrefix))
|
|
299
|
+
.map((resource) => resource.slice(outsideWorkspacePrefix.length));
|
|
300
|
+
if (outside.length) {
|
|
301
|
+
if (full)
|
|
302
|
+
return { decision: 'allow' };
|
|
303
|
+
return legacy
|
|
304
|
+
? { decision: 'deny', reason: 'Path is unavailable or outside the permitted workspace' }
|
|
305
|
+
: { decision: 'ask', reason: `Approve access outside the workspace: ${outside.join(', ')}` };
|
|
306
|
+
}
|
|
307
|
+
if (full || legacyFull || standard || ((legacy || strict) && definition.effects === 'read'))
|
|
308
|
+
return { decision: 'allow' };
|
|
309
|
+
return { decision: 'ask', reason: 'Approve the resolved local operation' };
|
|
310
|
+
}
|
|
311
|
+
if (definition.name !== agentDefinitions.counter?.name)
|
|
312
|
+
return deny;
|
|
313
|
+
const counterApproval = config.counter?.approval;
|
|
314
|
+
if (counterApproval !== 'allow' && counterApproval !== 'ask')
|
|
315
|
+
return deny;
|
|
316
|
+
if (full || legacyFull || ((legacy || standard) && counterApproval === 'allow'))
|
|
317
|
+
return { decision: 'allow' };
|
|
318
|
+
return { decision: 'ask', reason: 'Approve the controlled local counter write' };
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
const teamVariant = (definition, toolSetVersion) => {
|
|
322
|
+
if (definition.source.kind !== 'builtin')
|
|
323
|
+
return definition;
|
|
324
|
+
const { workspace, patchTools, legacyProcesses, patchTeamFiles, teamFiles, phaseOne, phaseOneTeamRead } = workspaceDefinitions;
|
|
325
|
+
if (definition.name === 'read_file' &&
|
|
326
|
+
phaseOne.some((original) => original.name === definition.name && original.version === definition.version))
|
|
327
|
+
return phaseOneTeamRead ?? definition;
|
|
328
|
+
const current = [...workspace, ...patchTools, ...legacyProcesses].some((original) => original.name === definition.name && original.version === definition.version);
|
|
329
|
+
const variants = [patchWorkspaceToolSetVersion, phaseOneToolSetVersion, workspaceToolSetVersion].includes(toolSetVersion)
|
|
330
|
+
? patchTeamFiles
|
|
331
|
+
: teamFiles;
|
|
332
|
+
return current ? (variants.find(({ name }) => name === definition.name) ?? definition) : definition;
|
|
333
|
+
};
|
|
334
|
+
function checkToolSet(runConfig) {
|
|
335
|
+
const mcp = mcpVersions.includes(runConfig.toolSetVersion);
|
|
336
|
+
if (!mcp && runConfig.toolSetVersion.startsWith('mcp-'))
|
|
337
|
+
throw new RuntimeError('TOOL_CONFIG', 'Requested MCP tool set is unavailable');
|
|
338
|
+
return mcp;
|
|
339
|
+
}
|
|
340
|
+
const freeze = (runConfig, target = { role: primaryRole(runConfig) }) => {
|
|
341
|
+
const mcp = checkToolSet(runConfig);
|
|
342
|
+
const overrides = new Map(scoped
|
|
343
|
+
.resolve(target, ({ scopeKey, toolSets }) => scopeKey !== undefined && toolSets.includes(runConfig.toolSetVersion))
|
|
344
|
+
.map((entry) => [entry.name, entry]));
|
|
345
|
+
const snapshot = registry.snapshotForAdmission(runConfig, overrides, ({ name, version, scopeKey }) => knownPluginTools.has(contributionIdentity({
|
|
346
|
+
kind: 'tool',
|
|
347
|
+
id: name,
|
|
348
|
+
version,
|
|
349
|
+
...(scopeKey === undefined ? {} : { scopeKey }),
|
|
350
|
+
})));
|
|
351
|
+
const rawDefinitions = runConfig.team
|
|
352
|
+
? snapshot.definitions.map((definition) => teamVariant(definition, runConfig.toolSetVersion))
|
|
353
|
+
: snapshot.definitions;
|
|
354
|
+
const definitions = target.role === 'worker' && !config.workerAllowTargetServices
|
|
355
|
+
? rawDefinitions.filter(({ name }) => !sandboxTargetToolNames.has(name))
|
|
356
|
+
: rawDefinitions;
|
|
357
|
+
const allowed = runConfig.contextExtensions?.mode?.allowedTools;
|
|
358
|
+
const denied = runConfig.contextExtensions?.mode?.deniedTools;
|
|
359
|
+
if (allowed) {
|
|
360
|
+
const selected = new Set(definitions.map(({ name }) => name));
|
|
361
|
+
const inactive = [...knownPluginTools.values()].find(({ name, version, scopeKey, scope, toolSets }) => allowed.includes(name) &&
|
|
362
|
+
!denied?.includes(name) &&
|
|
363
|
+
!selected.has(name) &&
|
|
364
|
+
matchesScope(scope, target) &&
|
|
365
|
+
toolSets.includes(runConfig.toolSetVersion) &&
|
|
366
|
+
!registry.isActive(name, version, scopeKey));
|
|
367
|
+
if (inactive)
|
|
368
|
+
throw new RuntimeError('PLUGIN_INACTIVE', `Tool ${inactive.name} is inactive`);
|
|
369
|
+
}
|
|
370
|
+
for (const { name, version, scopeKey } of definitions)
|
|
371
|
+
if (!registry.isActive(name, version, scopeKey))
|
|
372
|
+
throw new RuntimeError('PLUGIN_INACTIVE', `Tool ${name}@${version} is inactive`);
|
|
373
|
+
const needsSnapshot = runConfig.team ||
|
|
374
|
+
runConfig.toolSetVersion === 'planner' ||
|
|
375
|
+
runConfig.toolSetVersion === dataReviewToolSet ||
|
|
376
|
+
runConfig.search?.mode === 'selective' ||
|
|
377
|
+
mcp ||
|
|
378
|
+
definitions.some(({ source }) => source.kind !== 'builtin');
|
|
379
|
+
return {
|
|
380
|
+
...(needsSnapshot ? { toolSnapshot: { ...snapshot, definitions } } : {}),
|
|
381
|
+
pluginBindings: {
|
|
382
|
+
contextProviders: [],
|
|
383
|
+
hooks: [],
|
|
384
|
+
...runConfig.pluginBindings,
|
|
385
|
+
tools: definitions.map((definition) => registry.pin(definition)),
|
|
386
|
+
},
|
|
387
|
+
};
|
|
388
|
+
};
|
|
389
|
+
return {
|
|
390
|
+
registry,
|
|
391
|
+
policy,
|
|
392
|
+
registerTool(definition, handler, versions, { scope = globalScope, ...options } = {}) {
|
|
393
|
+
const validated = validateContributionScope(scope);
|
|
394
|
+
const { scopeKey: _providedScopeKey, ...definitionFields } = definition;
|
|
395
|
+
const scopeKey = contributionScopeKey(validated);
|
|
396
|
+
return registerTool(scopeKey === undefined ? definitionFields : { ...definitionFields, scopeKey }, handler, versions, scopeKey === undefined ? options : { ...options, order: options.order ?? { tier: 'tail' } }, validated);
|
|
397
|
+
},
|
|
398
|
+
agentSessionIds: () => scoped.agentSessionIds(),
|
|
399
|
+
async pluginToolVersions() {
|
|
400
|
+
return (await toolSets).defaultVersions;
|
|
401
|
+
},
|
|
402
|
+
get mcpServers() {
|
|
403
|
+
return mcpServers;
|
|
404
|
+
},
|
|
405
|
+
setWorkspaceDefinitions(definitions) {
|
|
406
|
+
workspaceDefinitions = definitions;
|
|
407
|
+
for (const { name } of [
|
|
408
|
+
...definitions.workspace,
|
|
409
|
+
...definitions.patchTools,
|
|
410
|
+
...definitions.phaseOne,
|
|
411
|
+
...definitions.phaseTwo,
|
|
412
|
+
])
|
|
413
|
+
workspaceNames.add(name);
|
|
414
|
+
workspaceReady.resolve();
|
|
415
|
+
return toolSets;
|
|
416
|
+
},
|
|
417
|
+
setAgentDefinitions(counter, reader) {
|
|
418
|
+
agentDefinitions = { counter, reader };
|
|
419
|
+
agentReady.resolve();
|
|
420
|
+
return toolSets;
|
|
421
|
+
},
|
|
422
|
+
setMcpDefinitions(definitions, discovery) {
|
|
423
|
+
mcpServers = discovery;
|
|
424
|
+
mcpReady.resolve(definitions);
|
|
425
|
+
return toolSets;
|
|
426
|
+
},
|
|
427
|
+
defaultVersion(capabilities) {
|
|
428
|
+
return capabilities.tools
|
|
429
|
+
? (currentMcpVersion ?? (config.workspaceTools ? workspaceToolSetVersion : '4'))
|
|
430
|
+
: '1';
|
|
431
|
+
},
|
|
432
|
+
plannerVersion(capabilities) {
|
|
433
|
+
return capabilities.tools ? 'planner' : '1';
|
|
434
|
+
},
|
|
435
|
+
freeze,
|
|
436
|
+
async freezeWorker(runConfig, team, agentSessionId, capabilities, options) {
|
|
437
|
+
const selected = configForDerivedAgent(runConfig, 'worker', agentSessionId);
|
|
438
|
+
const { planner: _planner, teamHint: _teamHint, toolSnapshot: _toolSnapshot, ...rest } = selected;
|
|
439
|
+
const workerBase = resolveWorkerReasoning({ ...rest, team }, capabilities);
|
|
440
|
+
const { pluginBindings } = workerBase;
|
|
441
|
+
// Historical parents follow the previous active-set selection and team mapping.
|
|
442
|
+
if (!pluginBindings)
|
|
443
|
+
checkToolSet(workerBase);
|
|
444
|
+
const teamMaxDepth = runConfig.teamMaxDepth ?? 1;
|
|
445
|
+
const agentDepth = options?.depth ?? (runConfig.agentDepth ?? 0) + 1;
|
|
446
|
+
const allowSpawnTeam = agentDepth < teamMaxDepth;
|
|
447
|
+
const allowNotifyParent = agentDepth === 1;
|
|
448
|
+
const allowTargetServices = Boolean(config.workerAllowTargetServices);
|
|
449
|
+
const snapshot = await registry.snapshot(workerBase);
|
|
450
|
+
const definitions = snapshot.definitions
|
|
451
|
+
.filter(({ name }) => name !== todoWriteToolName &&
|
|
452
|
+
(allowSpawnTeam || name !== spawnTeamToolName) &&
|
|
453
|
+
(allowNotifyParent || name !== teamNotifyParentToolName) &&
|
|
454
|
+
(allowTargetServices || !sandboxTargetToolNames.has(name)))
|
|
455
|
+
.map((definition) => teamVariant(definition, runConfig.toolSetVersion));
|
|
456
|
+
const parentBindings = new Map(pluginBindings?.tools.map((binding) => [binding.name, binding]));
|
|
457
|
+
for (const definition of definitions)
|
|
458
|
+
await registry.resolveFrozen(definition);
|
|
459
|
+
return {
|
|
460
|
+
...workerBase,
|
|
461
|
+
teamMaxDepth,
|
|
462
|
+
agentDepth,
|
|
463
|
+
toolSnapshot: { ...snapshot, definitions },
|
|
464
|
+
...(pluginBindings
|
|
465
|
+
? {
|
|
466
|
+
pluginBindings: {
|
|
467
|
+
...pluginBindings,
|
|
468
|
+
tools: definitions.map((definition) => {
|
|
469
|
+
const parent = parentBindings.get(definition.name);
|
|
470
|
+
return parent && parent.version === definition.version ? parent : registry.pin(definition);
|
|
471
|
+
}),
|
|
472
|
+
},
|
|
473
|
+
}
|
|
474
|
+
: {}),
|
|
475
|
+
};
|
|
476
|
+
},
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
export function createToolsCorePlugin(config, trustedConfig, hash) {
|
|
480
|
+
return {
|
|
481
|
+
name: 'tools-core',
|
|
482
|
+
apply(ctx) {
|
|
483
|
+
ctx.provide('saturnTools', createToolsService(config, trustedConfig, hash));
|
|
484
|
+
},
|
|
485
|
+
};
|
|
486
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class WebFetchError extends Error {
|
|
2
|
+
}
|
|
3
|
+
export declare function readWebResponse(response: Response, maxBytes: number): Promise<string>;
|
|
4
|
+
export declare function matchesNoProxy(url: URL, noProxy?: string): boolean;
|
|
5
|
+
export interface ResolvedEnvProxy {
|
|
6
|
+
readonly proxyUrl: string;
|
|
7
|
+
readonly httpProxy: string;
|
|
8
|
+
readonly httpsProxy: string;
|
|
9
|
+
readonly noProxy: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function resolveEnvProxy(url: URL, env?: NodeJS.ProcessEnv): ResolvedEnvProxy | undefined;
|
|
12
|
+
export declare function describeWebFetchError(error: unknown, redact?: (text: string) => string, env?: NodeJS.ProcessEnv): string;
|
|
13
|
+
export declare function truncateWebText(text: string, limit: number): string;
|
|
14
|
+
export declare function fetchPublicPage(input: string, maxChars: number, signal: AbortSignal, redact: (text: string) => string, options?: {
|
|
15
|
+
allowFakeIp?: boolean;
|
|
16
|
+
env?: NodeJS.ProcessEnv;
|
|
17
|
+
}): Promise<string>;
|