Files
Agent-Workbench/src/shared/contracts/delivery-review.mjs
T
2026-10-29 22:28:47 +08:00

20 lines
1.3 KiB
JavaScript

// A saved agent preview is a user decision boundary, including after a restart.
export function pendingDeliveryReview(store, session) {
const run = store.core.run.get(session.runId);
if (!run || run.taskId !== session.taskId) return null;
const plans = [...store.core.delivery_plan.values()].filter(plan => plan.sessionId === session.id
&& plan.taskId === session.taskId && plan.runId === run.id && ['planned', 'accepted'].includes(plan.status));
return plans.find(plan => run.review?.status === 'pending' && run.review.planId === plan.id)
?? plans.filter(plan => plan.status === 'planned' && plan.preparedBy === 'agent').at(-1) ?? null;
}
export function resolveDeliveryReview(store, session, plan, outcome, job = null) {
const pending = pendingDeliveryReview(store, session), run = store.core.run.get(plan.runId);
if (pending?.id !== plan.id || session.taskId !== plan.taskId || session.runId !== plan.runId) return false;
run.review = { ...run.review, kind: 'git_delivery', planId: plan.id, status: outcome,
resolvedAt: new Date().toISOString(), jobId: job?.id ?? null, commit: job?.commit ?? null };
if (outcome === 'committed') { plan.status = 'completed'; session.status = 'completed'; run.status = 'completed'; }
else { session.status = 'paused'; run.status = 'paused'; run.stopReason = 'git_review_declined'; }
return true;
}