Skip to content

Commit 925c7db

Browse files
authored
feat(workbench): collapse preview-then-apply ceremonies into single-interaction flows across approval, task, monitor, report, and lifecycle controls (#10281)
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
1 parent 69b326c commit 925c7db

15 files changed

Lines changed: 595 additions & 447 deletions

‎apps/workbench/packages/web/src/components/GoalLifecycle.tsx‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,33 @@ export function GoalLifecycle({ token, goal, onChanged }: {
3535
setError(null);
3636
setPreviewing(operation);
3737
try {
38-
const proposal = await previewLifecycle(token, goal.goalId, operation, {
39-
summary: t('loopx.lifecycle.summary', operationWord(operation), goal.title),
40-
});
38+
const summary = t('loopx.lifecycle.summary', operationWord(operation), goal.title);
39+
if (operation !== 'delete') {
40+
// Stop and resume are reversible; apply directly in one menu click (retrying once on 409 stale).
41+
for (let attempt = 0; attempt < 2; attempt++) {
42+
const proposal = await previewLifecycle(token, goal.goalId, operation, { summary });
43+
if (proposal.status !== 'preview_ready') {
44+
setError(t('loopx.lifecycle.notReady', proposal.error ?? proposal.status));
45+
return;
46+
}
47+
try {
48+
const applied = await applyLifecycle(token, proposal.proposalId);
49+
if (applied.stale && attempt === 0) continue;
50+
if (applied.status !== 'applied') {
51+
setError(t('loopx.lifecycle.notReady', applied.error ?? applied.status));
52+
return;
53+
}
54+
onChanged();
55+
return;
56+
} catch (cause) {
57+
if (attempt === 0 && cause instanceof ActionError && cause.isStale) continue;
58+
throw cause;
59+
}
60+
}
61+
return;
62+
}
63+
// Delete is irreversible: keep explicit danger confirmation dialog.
64+
const proposal = await previewLifecycle(token, goal.goalId, operation, { summary });
4165
if (proposal.status !== 'preview_ready') {
4266
setError(t('loopx.lifecycle.notReady', proposal.error ?? proposal.status));
4367
return;

‎apps/workbench/packages/web/src/components/GoalReports.tsx‎

Lines changed: 24 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,10 @@ import {
1515
type ReportReviewPage,
1616
type ReportReviewRow,
1717
} from '../loopx/report-reviews';
18-
import { applyTodoMutation, previewTodoMutation, type TodoActionProposal } from '../loopx/tasks';
18+
import { executeTodoMutationOneClick } from '../loopx/tasks';
1919

2020
type ViewMode = 'html' | 'markdown';
2121

22-
interface PendingDecision {
23-
kind: 'accept' | 'reject';
24-
note?: string;
25-
proposal: TodoActionProposal;
26-
}
27-
2822
function reportStatusLabel(status: string): string {
2923
return status === 'done' ? t('loopx.reports.status.accepted') : t('loopx.reports.status.pending');
3024
}
@@ -67,7 +61,6 @@ export function GoalReports({
6761
const [error, setError] = useState<string | null>(null);
6862

6963
const [feedbackByKey, setFeedbackByKey] = useState<Record<string, string>>({});
70-
const [pending, setPending] = useState<PendingDecision | null>(null);
7164
const [actionBusy, setActionBusy] = useState(false);
7265
const [actionError, setActionError] = useState<string | null>(null);
7366

@@ -83,7 +76,6 @@ export function GoalReports({
8376
setBusy(true);
8477
setError(null);
8578
setActionError(null);
86-
setPending(null);
8779
setPreviewUrl(null);
8880
setPreviewFallbackNotice(false);
8981
try {
@@ -159,7 +151,6 @@ export function GoalReports({
159151
autoOpenedId.current = null;
160152
setPage(null);
161153
setDetail(null);
162-
setPending(null);
163154
setActionError(null);
164155
let active = true;
165156
void (async () => {
@@ -194,7 +185,6 @@ export function GoalReports({
194185
setDetail(null);
195186
setPreviewUrl(null);
196187
setPreviewFallbackNotice(false);
197-
setPending(null);
198188
setActionError(null);
199189
onSelectReport?.(null);
200190
};
@@ -215,10 +205,9 @@ export function GoalReports({
215205
}
216206
};
217207

218-
const startDecision = async (kind: 'accept' | 'reject') => {
208+
const submitDecision = async (kind: 'accept' | 'reject') => {
219209
if (!detail || readOnly) return;
220210
setActionError(null);
221-
setPending(null);
222211
const actor = selectReportActorAgent(detail.row, availableAgents);
223212
if (!actor) {
224213
setActionError(t('loopx.reports.actorMissing'));
@@ -237,7 +226,7 @@ export function GoalReports({
237226
const summary = kind === 'accept'
238227
? `${t('loopx.reports.summary.accept')}: ${detail.row.title}`
239228
: `${t('loopx.reports.summary.reject')}: ${detail.row.title}`;
240-
const proposal = await previewTodoMutation(token, {
229+
const applied = await executeTodoMutationOneClick(token, {
241230
goalId,
242231
todoId: detail.row.todoId,
243232
role: 'user',
@@ -247,35 +236,14 @@ export function GoalReports({
247236
agentId: actor,
248237
...(note ? { note } : {}),
249238
});
250-
if (proposal.error || proposal.status === 'failed') {
251-
setActionError(proposal.error ?? t('loopx.reports.editionChanged'));
252-
return;
253-
}
254-
setPending({ kind, note, proposal });
255-
} catch (cause) {
256-
setActionError(cause instanceof Error ? cause.message : String(cause));
257-
} finally {
258-
setActionBusy(false);
259-
}
260-
};
261-
262-
const confirmDecision = async () => {
263-
if (!detail || !pending) return;
264-
setActionBusy(true);
265-
setActionError(null);
266-
try {
267-
const applied = await applyTodoMutation(token, pending.proposal.proposalId);
268-
if (applied.error || applied.status === 'failed' || applied.status === 'stale') {
239+
if (applied.error || applied.status === 'failed' || applied.status === 'stale' || applied.status === 'gated') {
269240
setActionError(applied.error ?? t('loopx.reports.editionChanged'));
270-
setPending(null);
271241
return;
272242
}
273-
const completedKey = reportDraftKey(goalId, detail.row);
274-
setPending(null);
275-
if (pending.kind === 'reject') {
243+
if (kind === 'reject') {
276244
setFeedbackByKey(prev => {
277245
const next = { ...prev };
278-
delete next[completedKey];
246+
delete next[draftKey];
279247
return next;
280248
});
281249
}
@@ -424,58 +392,24 @@ export function GoalReports({
424392

425393
{actionError ? <p className="goal-failure" role="alert">{actionError}</p> : null}
426394

427-
{pending ? (
428-
<div className="goal-task-preview-box goal-report-confirm" data-report-confirm={pending.kind}>
429-
<p>
430-
{pending.kind === 'accept'
431-
? t('loopx.reports.confirmAccept')
432-
: t('loopx.reports.confirmReject')}
433-
</p>
434-
{pending.note ? <p className="goal-report-confirm-note">{pending.note}</p> : null}
435-
{pending.proposal.evidence.map((line, idx) => <p key={idx}>{line}</p>)}
436-
<div className="goal-task-action-row">
437-
<button
438-
type="button"
439-
className="goal-task-btn is-primary"
440-
disabled={actionBusy}
441-
onClick={() => void confirmDecision()}
442-
>
443-
{actionBusy
444-
? t('loopx.reports.applying')
445-
: pending.kind === 'accept'
446-
? t('loopx.reports.confirmAcceptBtn')
447-
: t('loopx.reports.confirmRejectBtn')}
448-
</button>
449-
<button
450-
type="button"
451-
className="goal-task-btn"
452-
disabled={actionBusy}
453-
onClick={() => setPending(null)}
454-
>
455-
{t('loopx.reports.cancel')}
456-
</button>
457-
</div>
458-
</div>
459-
) : (
460-
<div className="goal-task-action-row">
461-
<button
462-
type="button"
463-
className="goal-task-btn is-primary"
464-
disabled={actionBusy}
465-
onClick={() => void startDecision('accept')}
466-
>
467-
{t('loopx.reports.action.accept')}
468-
</button>
469-
<button
470-
type="button"
471-
className="goal-task-btn"
472-
disabled={actionBusy}
473-
onClick={() => void startDecision('reject')}
474-
>
475-
{t('loopx.reports.action.reject')}
476-
</button>
477-
</div>
478-
)}
395+
<div className="goal-task-action-row">
396+
<button
397+
type="button"
398+
className="goal-task-btn is-primary"
399+
disabled={actionBusy}
400+
onClick={() => void submitDecision('accept')}
401+
>
402+
{actionBusy ? t('loopx.reports.applying') : t('loopx.reports.action.accept')}
403+
</button>
404+
<button
405+
type="button"
406+
className="goal-task-btn"
407+
disabled={actionBusy}
408+
onClick={() => void submitDecision('reject')}
409+
>
410+
{actionBusy ? t('loopx.reports.applying') : t('loopx.reports.action.reject')}
411+
</button>
412+
</div>
479413
</div>
480414
)}
481415
</div>

0 commit comments

Comments
 (0)