feat(runtime): default to passthrough and persist execution permissions

This commit is contained in:
Agent Workbench Dev
2026-11-06 04:58:57 +08:00
parent 67c034f4b6
commit 2fa220735d
113 changed files with 1866 additions and 631 deletions
+8 -7
View File
@@ -1,3 +1,4 @@
import { unrestricted, ceiling } from './execution-policy.mjs';
import { createHash } from 'node:crypto';
import { isId, accountedTokens, emptyUsage } from './execution.mjs';
import { selectedEngineInput } from './engine-execution.mjs';
@@ -32,11 +33,11 @@ const text = (value, maximum, label) => {
export function collaborationInput(input, config) {
if (!input || Array.isArray(input) || Object.keys(input).some(key => !['goal', 'budget', 'children', 'engine'].includes(key))) throw workerConflict('协作只接受父目标、预算、子任务和已检测的引擎。');
const engine = input.engine === undefined ? null : selectedEngineInput(input.engine);
if (!Array.isArray(input.children) || input.children.length !== (engine ? 1 : 2)) throw workerConflict(engine ? '受控引擎计划需要一个所属子工程。' : '本阶段需要两个受限子任务。');
if (!Array.isArray(input.children) || (unrestricted(config) ? input.children.length < 1 : input.children.length !== (engine ? 1 : 2))) throw workerConflict(engine ? '受控引擎计划需要一个所属子工程。' : '本阶段需要两个受限子任务。');
const raw = input.budget ?? {};
if (!raw || typeof raw !== 'object' || Array.isArray(raw) || Object.keys(raw).some(key => !['maxTokens', 'maxSteps', 'maxToolCalls', 'maxDurationMs'].includes(key))) throw workerConflict('协作预算字段无效。');
const tokenMaximum = Math.min(config.maxTaskTokens ?? 1000000, config.maxRunTokens ?? 200000);
const budget = {
const budget = unrestricted(config) ? { maxTokens: 0, maxSteps: 0, maxToolCalls: 0, maxDurationMs: 0 } : {
maxTokens: bounded(raw.maxTokens, tokenMaximum, 1000, tokenMaximum, '总token预算'),
maxSteps: bounded(raw.maxSteps, Math.min(200, (config.maxSteps ?? 12) * 2), 2, 200, '总请求步数'),
maxToolCalls: bounded(raw.maxToolCalls, 96, 2, 512, '总工具次数'),
@@ -44,17 +45,17 @@ export function collaborationInput(input, config) {
};
const children = input.children.map((item, index) => {
if (!item || typeof item !== 'object' || Array.isArray(item) || Object.keys(item).some(key => !['label', 'goal', 'paths', 'budget'].includes(key))) throw workerConflict('子任务字段无效。');
if (!Array.isArray(item.paths) || !item.paths.length || item.paths.length > 16) throw workerConflict('每个子任务需要1到16个修改范围。');
if (!Array.isArray(item.paths) || !item.paths.length || !unrestricted(config) && item.paths.length > 16) throw workerConflict('每个子任务需要1到16个修改范围。');
const paths = item.paths.map(workerPath).sort();
if (new Set(paths.map(workerPathKey)).size !== paths.length) throw workerConflict('子任务范围不能重复。');
const part = item.budget ?? {};
if (!part || Array.isArray(part) || Object.keys(part).some(key => !['maxTokens', 'maxSteps', 'maxToolCalls'].includes(key))) throw workerConflict('子预算字段无效。');
const allocate = key => engine ? budget[key] : index === 0 ? Math.floor(budget[key] / 2) : budget[key] - Math.floor(budget[key] / 2);
return { label: text(item.label, 64, '子任务名称'), goal: text(item.goal, 8000, '子目标'), paths,
budget: Object.fromEntries(['maxTokens', 'maxSteps', 'maxToolCalls'].map(key => [key, bounded(part[key], allocate(key), key === 'maxTokens' ? 500 : 1, budget[key], key)])) };
return { label: text(item.label, ceiling(config, 64), '子任务名称'), goal: text(item.goal, ceiling(config, 8000), '子目标'), paths,
budget: Object.fromEntries(['maxTokens', 'maxSteps', 'maxToolCalls'].map(key => [key, unrestricted(config) ? 0 : bounded(part[key], allocate(key), key === 'maxTokens' ? 500 : 1, budget[key], key)])) };
});
for (const key of ['maxTokens', 'maxSteps', 'maxToolCalls']) if (children.reduce((sum, child) => sum + child.budget[key], 0) > budget[key]) throw workerConflict('子任务预算之和不能超过父预算:' + key);
return { goal: text(input.goal, 20000, '父目标'), budget, children, ...(engine ? { engine } : {}) };
return { goal: text(input.goal, ceiling(config, 20000), '父目标'), budget, children, ...(engine ? { engine } : {}) };
}
export function collaborationSeal(group) {
@@ -108,7 +109,7 @@ export function assertWorkerWriteScope(store, session, value, { readOnly = false
export function assertWorkerTool(store, session, tool, args) {
const worker = workerForSession(store, session);
if (!worker) return;
if (!WORKER_TOOLS.has(tool)) throw workerConflict('受限子任务不开放这个工具:' + tool);
if (!unrestricted(store) && !WORKER_TOOLS.has(tool)) throw workerConflict('受限子任务不开放这个工具:' + tool);
if (tool === 'propose_file' || tool === 'propose_patch' || tool === 'propose_file_chunk') assertWorkerWriteScope(store, session, args.path);
}
export function assertWorkersResolved(store, projectId, { recoveryTaskId = null } = {}) {