🐛 Show the answer once, and keep the wish card from repeating it

Two copies of the same words could appear on screen, and both came from the
panel rather than from the model.

The card that asks the customer to confirm a drafted wish fell back to the
answer text whenever the Copilot wrote no separate goal, then printed it under
「要做的改动」 — the answer above the card already said it. The card now shows
that section only when the goal really is a different sentence.

The streamed answer also stayed on screen after it ended, next to the stored
message it had just become. It is now dropped as soon as the transcript holds
the same text, and the stored session is read back before the stream is cleared.
This commit is contained in:
wishforge 2026-11-09 19:06:16 -08:00
parent 07c772022b
commit 5dd2daee35

View File

@ -47,7 +47,11 @@ function WishDraft({
sessionId: string;
onCreated: () => void;
}) {
const baseGoal = message.goal ?? message.content;
// The card is the confirmation, not a second copy of the answer. When the Copilot did not write a
// separate goal, the answer above already says what will change, so the card must not repeat it.
const statedGoal = message.goal?.trim() ?? '';
const baseGoal = statedGoal || message.content;
const repeatsAnswer = statedGoal === message.content.trim();
const baseCriteria = message.acceptanceCriteria ?? [];
const [selected, setSelected] = useState<Record<number, number>>({});
const [busy, setBusy] = useState(false);
@ -109,10 +113,12 @@ function WishDraft({
<p>{message.contextSummary || '没有额外说明。'}</p>
</div>
) : null}
<div className="copilot-card-goal">
<strong>要做的改动</strong>
<p>{goal}</p>
</div>
{statedGoal && !repeatsAnswer ? (
<div className="copilot-card-goal">
<strong>要做的改动</strong>
<p>{goal}</p>
</div>
) : null}
<div className="copilot-card-goal">
<strong>做完怎么确认</strong>
<ul>{criteria.length ? criteria.map(item => <li key={item}>{item}</li>) : <li>改动完成即可。</li>}</ul>
@ -338,7 +344,12 @@ export function CopilotSidebar({ open, onClose }: { open: boolean; onClose: () =
context: { pathname },
onDone: () => {
setPendingUser('');
void sessionResource.mutate().catch(() => undefined);
// The stored message replaces the streamed one. Read it back first, then clear the stream,
// so the answer is never on screen twice and never blinks away in between.
void sessionResource
.mutate()
.catch(() => undefined)
.then(() => stream.reset());
},
});
} catch (failure) {
@ -348,7 +359,14 @@ export function CopilotSidebar({ open, onClose }: { open: boolean; onClose: () =
}
};
const messages = sessionResource.data?.projectId === projectId ? sessionResource.data.messages : [];
const showStream = streaming || Boolean(stream.state.content) || Boolean(stream.state.error);
// One answer, one place. While it streams the local copy is the only one; once the stored message
// is in the transcript that becomes the answer, so the streamed text steps aside.
const streamedText = stream.state.content.trim();
const answerAlreadyStored =
Boolean(streamedText) &&
messages.some(message => message.role === 'assistant' && message.content.trim() === streamedText);
const showStream =
streaming || Boolean(stream.state.error) || (Boolean(stream.state.content) && !answerAlreadyStored);
return (
<aside
className={`copilot-sidebar ${open ? 'is-open' : ''}`}