feat: journal reviewed multi-file changes and recover interrupted batches
This commit is contained in:
+19
-1
@@ -3,6 +3,7 @@ import path from 'node:path';
|
||||
import { listFiles, readText, proposeFile, proposePatch, applyChange } from './files.mjs';
|
||||
import { APP_VERSION, executionEnvironment, sessionSnapshot } from './diagnostics.mjs';
|
||||
import { inspectProject } from '../core/project-inspector.mjs';
|
||||
import { assertProposalUnsealed } from '../shared/contracts/change-sets.mjs';
|
||||
|
||||
export function createSessionPublisher(clients) {
|
||||
return session => {
|
||||
@@ -141,6 +142,22 @@ return async (request, response) => {
|
||||
const session = store.session(id);
|
||||
if (method === 'GET' && !action) return json(response, store.publicSession(session));
|
||||
if (method === 'GET' && action === 'execution') return json(response, store.executionSnapshot(session));
|
||||
if (method === 'POST' && action === 'change-sets') {
|
||||
const input = await body(request); await runtime.changeSetManager().prepare(session, input.changeIds);
|
||||
return json(response, store.publicSession(session), 201);
|
||||
}
|
||||
const changeSet = action.match(/^change-sets\/([a-f0-9-]+)(?:\/(apply|reconcile|rollback|discard|acknowledge|stop))?$/);
|
||||
if (changeSet && method === 'GET' && !changeSet[2]) return json(response, store.owned('change_set', changeSet[1], id));
|
||||
if (changeSet && method === 'POST' && changeSet[2]) {
|
||||
const input = await body(request), manager = runtime.changeSetManager();
|
||||
if (changeSet[2] === 'apply') await manager.start(session, changeSet[1], input.fingerprint);
|
||||
else if (changeSet[2] === 'reconcile') await manager.reconcile(session, changeSet[1]);
|
||||
else if (changeSet[2] === 'rollback') await manager.rollback(session, changeSet[1], input.fingerprint);
|
||||
else if (changeSet[2] === 'discard') manager.discard(session, changeSet[1], input.fingerprint);
|
||||
else if (changeSet[2] === 'acknowledge') manager.acknowledge(session, changeSet[1], input.fingerprint, input.observationFingerprint);
|
||||
else { store.owned('change_set', changeSet[1], id); await manager.stop(id); }
|
||||
return json(response, store.publicSession(session), changeSet[2] === 'apply' ? 202 : 200);
|
||||
}
|
||||
if (method === 'POST' && action === 'delivery-plans') {
|
||||
const input = await body(request);
|
||||
await runtime.gitDelivery().plan(session, input);
|
||||
@@ -226,6 +243,7 @@ return async (request, response) => {
|
||||
else {
|
||||
const item = session.changes.find(candidate => candidate.id === change[1]);
|
||||
if (!item || !['pending', 'conflict'].includes(item.status)) throw new Error('改动无法撤回。');
|
||||
assertProposalUnsealed(store, item);
|
||||
item.status = 'rejected';
|
||||
if (session.status === 'needs_review' && !session.changes.some(candidate => ['pending', 'conflict'].includes(candidate.status))) session.status = 'completed';
|
||||
store.save(session);
|
||||
@@ -234,7 +252,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)) throw Object.assign(new Error('工程检查或Git交付正在执行,请等待结束后再编辑文件。'), { status: 409 });
|
||||
if (runtime.checks?.projectActive(session.projectId) || runtime.deliveries?.projectActive(session.projectId) || runtime.changeSets?.projectActive(session.projectId)) throw Object.assign(new Error('工程检查、Git交付或文件批次正在执行,请等待结束后再编辑文件。'), { status: 409 });
|
||||
if (action === 'patch-proposals') proposePatch(store, session, input);
|
||||
else proposeFile(store, session, input);
|
||||
return json(response, store.publicSession(session), 201);
|
||||
|
||||
Reference in New Issue
Block a user