feat: seal isolated worker recovery, parent integration and review console
This commit is contained in:
+38
-2
@@ -10,6 +10,7 @@ import { publicEngineJob } from '../shared/contracts/engines.mjs';
|
||||
import { verifyBrowserJob } from '../core/browser/browser-manager.mjs';
|
||||
import { ConfigImporter } from '../core/models/config-import.mjs';
|
||||
import { ProjectMemoryManager } from '../core/memory/project-memory.mjs';
|
||||
import { workerForProject, workerConflict, assertWorkersResolved } from '../shared/contracts/workers.mjs';
|
||||
|
||||
export function createSessionPublisher(clients) {
|
||||
return session => {
|
||||
@@ -85,6 +86,7 @@ return async (request, response) => {
|
||||
if (method === 'GET' && !action) return json(response, registry.view(projectId));
|
||||
if (method === 'GET' && action === 'content') return json(response, registry.content(projectId, url.searchParams.get('id'), Number(url.searchParams.get('revision'))));
|
||||
if (method === 'POST') {
|
||||
if (workerForProject(store, projectId)) throw workerConflict('受限子项目不能修改Skills登记,请返回父项目。');
|
||||
const input = await body(request);
|
||||
if (!action) return json(response, registry.register(projectId, input), 201);
|
||||
if (action === 'toggle') return json(response, registry.toggle(projectId, input));
|
||||
@@ -95,7 +97,7 @@ return async (request, response) => {
|
||||
if (mcpMatch) {
|
||||
const registry = runtime.mcpRegistry(), projectId = mcpMatch[1];
|
||||
if (method === 'GET' && !mcpMatch[2]) return json(response, registry.view(projectId));
|
||||
if (method === 'POST') { const input = await body(request);
|
||||
if (method === 'POST') { if (workerForProject(store, projectId)) throw workerConflict('受限子项目不能修改MCP登记,请返回父项目。'); const input = await body(request);
|
||||
return json(response, mcpMatch[2] ? registry.configure(projectId, input) : registry.register(projectId, input), mcpMatch[2] ? 200 : 201); }
|
||||
}
|
||||
const projectMemoryMatch = route.match(/^\/api\/projects\/([a-f0-9-]+)\/memories$/i);
|
||||
@@ -112,11 +114,13 @@ return async (request, response) => {
|
||||
const sessionMemoryArchiveMatch = route.match(/^\/api\/sessions\/([a-f0-9-]+)\/memories\/([a-f0-9-]+)\/archive$/i);
|
||||
if (sessionMemoryArchiveMatch && method === 'POST') {
|
||||
const session = store.session(sessionMemoryArchiveMatch[1]);
|
||||
if (workerForProject(store, session.projectId)) throw workerConflict('受限子任务不能修改项目记忆,请返回父项目。');
|
||||
await body(request);
|
||||
return json(response, memories.archive(session, sessionMemoryArchiveMatch[2]));
|
||||
}
|
||||
if (sessionMemoryMatch && method === 'POST') {
|
||||
const session = store.session(sessionMemoryMatch[1]);
|
||||
if (workerForProject(store, session.projectId)) throw workerConflict('受限子任务不能修改项目记忆,请返回父项目。');
|
||||
const input = await body(request);
|
||||
return json(response, await memories.create(session, input), 201);
|
||||
}
|
||||
@@ -232,6 +236,7 @@ return async (request, response) => {
|
||||
if (method === 'GET' && route === '/api/sessions') return json(response, store.listSessions());
|
||||
if (method === 'POST' && route === '/api/sessions') {
|
||||
const input = await body(request);
|
||||
if (workerForProject(store, input.projectId)) throw workerConflict('隔离项目使用原受限子会话,请从父协作打开。');
|
||||
await verifyWorkspaceProject(store, store.project(input.projectId));
|
||||
return json(response, store.publicSession(store.createSession(input.projectId)), 201);
|
||||
}
|
||||
@@ -239,6 +244,37 @@ return async (request, response) => {
|
||||
if (sessionMatch) {
|
||||
const id = sessionMatch[1], action = sessionMatch[2] ?? '';
|
||||
const session = store.session(id);
|
||||
if (method === 'POST' && workerForProject(store, session.projectId)
|
||||
&& /^(?:mcp|engines|research|workspaces|delivery|browser|task-plans|task-proofs|task-checkpoints|collaborations)(?:\/|-|$)/.test(action)) throw workerConflict('受限子任务只开放原目标的读取、范围内改动和已审批检查;此操作请返回父项目。');
|
||||
if (method === 'GET' && action === 'collaborations') return json(response, runtime.workerManager().view(session));
|
||||
if (method === 'POST' && action === 'collaborations') {
|
||||
const group = await runtime.workerManager().plan(session, await body(request));
|
||||
return json(response, { group, session: store.publicSession(session) }, 201);
|
||||
}
|
||||
const collaboration = action.match(/^collaborations\/([a-f0-9-]+)\/(prepare|start|stop|collect|merge|finalize|discard|reconcile|acknowledge|collection|evidence)$/);
|
||||
if (collaboration) {
|
||||
const manager = runtime.workerManager();
|
||||
if (method === 'GET' && ['collection', 'evidence'].includes(collaboration[2])) {
|
||||
const group = manager.own(session, collaboration[1], null, { current: false });
|
||||
return json(response, collaboration[2] === 'collection' ? await manager.readCollection(session, group) : manager.readEvidence(session, group));
|
||||
}
|
||||
if (method === 'POST' && !['collection', 'evidence'].includes(collaboration[2])) {
|
||||
const input = await body(request);
|
||||
if (Object.keys(input).some(key => !['fingerprint', 'workerId', 'evidenceSha256', 'retain'].includes(key))) throw workerConflict('协作操作字段无效,不能添加命令或模型配置。');
|
||||
const group = manager.own(session, collaboration[1], input.fingerprint);
|
||||
let result;
|
||||
if (collaboration[2] === 'prepare') result = manager.prepare(session, group.id, input.fingerprint);
|
||||
else if (collaboration[2] === 'start') result = manager.start(session, group.id, input.fingerprint, input.workerId ?? null);
|
||||
else if (collaboration[2] === 'stop') { await runtime.stop(session.id); result = group; }
|
||||
else if (collaboration[2] === 'collect') result = manager.collect(session, group.id, input.fingerprint);
|
||||
else if (collaboration[2] === 'merge') result = manager.prepareMerge(session, group.id, input.fingerprint);
|
||||
else if (collaboration[2] === 'finalize') result = await manager.finalize(session, group.id, input.fingerprint);
|
||||
else if (collaboration[2] === 'discard') result = manager.discard(session, group.id, input.fingerprint);
|
||||
else if (collaboration[2] === 'reconcile') result = manager.reconcile(session, group.id, input.fingerprint);
|
||||
else result = await manager.acknowledge(session, group.id, input.fingerprint, input.evidenceSha256, input.retain === true);
|
||||
return json(response, { group: result.group ?? result, session: store.publicSession(session) }, result.promise ? 202 : 200);
|
||||
}
|
||||
}
|
||||
if (method === 'GET' && !action) return json(response, store.publicSession(session));
|
||||
if (method === 'GET' && action === 'execution') return json(response, store.executionSnapshot(session));
|
||||
if (method === 'GET' && action === 'mcp/jobs') return json(response, runtime.mcpRegistry().jobs(session));
|
||||
@@ -545,7 +581,7 @@ return async (request, response) => {
|
||||
}
|
||||
if (method === 'POST' && ['proposals', 'patch-proposals'].includes(action)) {
|
||||
const input = await body(request);
|
||||
if (runtime.checks?.projectActive(session.projectId) || runtime.deliveries?.projectActive(session.projectId) || runtime.changeSets?.projectActive(session.projectId) || runtime.workspaces?.projectActive(session.projectId)) throw Object.assign(new Error('工程检查、Git交付、文件批次或工作区正在执行,请等待结束后再编辑文件。'), { status: 409 });
|
||||
if (runtime.workers?.projectActive(session.projectId) || runtime.checks?.projectActive(session.projectId) || runtime.deliveries?.projectActive(session.projectId) || runtime.changeSets?.projectActive(session.projectId) || runtime.workspaces?.projectActive(session.projectId)) throw Object.assign(new Error('协作、工程检查、Git交付、文件批次或工作区正在执行,请等待结束后再编辑文件。'), { status: 409 });
|
||||
assertWorkspacesResolved(store, session.projectId, { includePrepared: true });
|
||||
await verifyWorkspaceProject(store, store.project(session.projectId));
|
||||
if (action === 'patch-proposals') proposePatch(store, session, input);
|
||||
|
||||
Reference in New Issue
Block a user