diff --git a/apps/api/src/domain/control-plane.ts b/apps/api/src/domain/control-plane.ts index 6787068..0bfdf1e 100644 --- a/apps/api/src/domain/control-plane.ts +++ b/apps/api/src/domain/control-plane.ts @@ -472,9 +472,15 @@ export class ControlPlane { return this.store.transaction(actor.tenantId, async tx => { const run = await must(tx, 'run', id); const project = await projectAccess(tx, actor, run.projectId); - return idempotent(tx, `command:${actor.userId}:${id}:${key}`, data, () => - this.applyCommand(tx, run, project, data), - ); + return idempotent(tx, `command:${actor.userId}:${id}:${key}`, data, async () => { + const result = await this.applyCommand(tx, run, project, data); + if (data.allowBackend) + await tx.event(id, 'run.scope', 'The wish may change backend code from now on.', { + frontendOnly: false, + changedBy: actor.userId, + }); + return result; + }); }); } /** @@ -485,10 +491,21 @@ export class ControlPlane { tx: Transaction, run: Run, project: Project, - data: { action: 'pause' | 'resume' | 'cancel' | 'answer'; message?: string; acceptanceCriteria?: string[] }, + data: { + action: 'pause' | 'resume' | 'cancel' | 'answer'; + message?: string; + acceptanceCriteria?: string[]; + allowBackend?: true; + }, ): Promise { const id = run.id; if (terminal(run)) throw new DomainError('TERMINAL_RUN', 'Submit a new wish to change a completed task'); + if (data.allowBackend && (data.action !== 'answer' || !run.frontendOnly)) + throw new DomainError( + 'SCOPE_UNCHANGED', + 'Only an answer to a frontend-only wish can let it change backend code', + 400, + ); const executing = run.status === 'running' && run.lease && Date.parse(run.lease.expiresAt) > Date.now(); if (data.action === 'resume' && (run.status === 'queued' || executing)) { if (run.pauseRequestedAt) @@ -514,7 +531,11 @@ export class ControlPlane { run = touch(run); run.pauseRequestedAt = undefined; run.lease = run.lease ? { ...run.lease, token: run.lease.token + 1, expiresAt: now() } : undefined; - let message = data.message ? redact(data.message) : `Run ${data.action} requested.`; + // Letting a frontend-only wish change backend code is part of the answer the agent reads. + const answer = [data.allowBackend ? '代码范围改为前端和后端:这个愿望可以修改后端代码。' : '', data.message ?? ''] + .filter(Boolean) + .join('\n'); + let message = answer ? redact(answer) : `Run ${data.action} requested.`; if (data.action === 'cancel') { run.status = 'canceled'; if (!run.providerProxyActiveRequest) run.reservedTokens = 0; @@ -524,10 +545,11 @@ export class ControlPlane { clearWaiting(run); } else { if (data.action === 'answer') { - if (!data.message) throw new DomainError('ANSWER_REQUIRED', 'Provide the additional requirement', 400); + if (!answer) throw new DomainError('ANSWER_REQUIRED', 'Provide the additional requirement', 400); const wish = touch(await must(tx, 'wish', run.wishId)); wish.revision += 1; - wish.goal = `${wish.goal}\n\n${data.message}`; + wish.goal = `${wish.goal}\n\n${answer}`; + if (data.allowBackend) run.frontendOnly = false; if (data.acceptanceCriteria) wish.acceptanceCriteria = data.acceptanceCriteria; await tx.put('wish', wish); run.revision = wish.revision; diff --git a/apps/web/src/app/globals.css b/apps/web/src/app/globals.css index 09d51c8..721cc8b 100644 --- a/apps/web/src/app/globals.css +++ b/apps/web/src/app/globals.css @@ -2982,3 +2982,16 @@ ul.criteria-choices { line-height: 1.6; color: var(--muted); } +.scope-unlock { + margin: 0 22px 15px; + padding: 12px 14px; + border: 1px solid var(--border); + border-radius: var(--radius); + background: #f6f9fb; +} +.scope-unlock p { + margin: 0 0 10px; + font-size: 12px; + line-height: 1.7; + color: var(--muted); +} diff --git a/apps/web/src/features/runs.tsx b/apps/web/src/features/runs.tsx index 1a3c502..cfad482 100644 --- a/apps/web/src/features/runs.tsx +++ b/apps/web/src/features/runs.tsx @@ -9,6 +9,7 @@ import { ChevronRight, FileCheck2, GitBranch, + LockOpen, Pause, Play, Plus, @@ -753,6 +754,7 @@ export function RunDetailView({ id }: { id: string }) { const [error, setError] = useState(''); const [answer, setAnswer] = useState(''); const [confirmCancel, setConfirmCancel] = useState(false); + const [confirmScope, setConfirmScope] = useState(false); const run = runResource.data; useEffect(() => { if (!run || !['running', 'queued', 'waiting'].includes(run.status)) return; @@ -765,13 +767,14 @@ export function RunDetailView({ id }: { id: string }) { source.addEventListener('run', update); return () => source.close(); }, [id, run?.status]); - async function command(action: string, message?: string) { + async function command(action: string, message?: string, extra: { allowBackend?: true } = {}) { setBusy(true); setError(''); try { - await mutateApi(`/runs/${id}/commands`, { action, message }); + await mutateApi(`/runs/${id}/commands`, { action, ...(message?.trim() ? { message } : {}), ...extra }); setAnswer(''); setConfirmCancel(false); + setConfirmScope(false); await Promise.all([runResource.mutate(), events.mutate()]); } catch (error) { setError(messageOf(error)); @@ -791,6 +794,14 @@ export function RunDetailView({ id }: { id: string }) { const budgetExhausted = (run.usedTokens ?? 0) >= (run.budget.maxTokens ?? 0) || (run.activeMilliseconds ?? 0) >= (run.budget.maxMinutes ?? 0) * 60_000; + // A frontend-only wish whose agent asked to change backend code, or kept changing it. + const backendWanted = + run.status === 'waiting' && + run.frontendOnly === true && + (run.waitingReason === 'clarification' || + (run.waitingReason === 'repair_exhausted' && run.lastFailure?.kind === 'scope')) && + identity.data?.kind === 'human' && + ['owner', 'admin', 'developer'].includes(identity.data.role); const canUpdateBudget = identity.data?.kind === 'human' && ['owner', 'admin'].includes(identity.data.role) && @@ -887,6 +898,17 @@ export function RunDetailView({ id }: { id: string }) { {waitingLink.label}

) : null} + {backendWanted ? ( +
+

+ 这个愿望只能改前端。确实要改后端时,可以放开代码范围:之后可以改后端代码,运行从规划重新开始;改到后端时要不要审核,仍按提交人的后端权限决定。 +

+ +
+ ) : null}

如需修改目标,可在下面补充需求;补充会创建新的需求版本并重新验证。

补充或修改需求 @@ -1113,6 +1135,37 @@ export function RunDetailView({ id }: { id: string }) { ) : null} + {confirmScope ? ( + setConfirmScope(false)} + > +
+ {run.waitingReason === 'clarification' && run.waitingDetail ? ( +

{run.waitingDetail}

+ ) : null} + +