fix(custom-cli): affichage conversation stable au second tour — dédup du prompt et scope de progression par tour, sans reliquats du tour précédent — #251 (QA verte)

This commit is contained in:
2026-08-23 17:51:50 +02:00
parent d5fea391b2
commit 7b7ab5b95a
2 changed files with 151 additions and 35 deletions

View File

@ -236,24 +236,31 @@ function appendUserPrompt(
text: string,
attachments: string[] = [],
receivedAtMs = Date.now(),
): ChatTurn[] {
const last = turns[turns.length - 1];
if (
last?.role === "user" &&
last.text === text &&
JSON.stringify(last.attachments ?? []) === JSON.stringify(attachments)
) {
return turns;
): { turns: ChatTurn[]; appended: boolean } {
for (let index = turns.length - 1; index >= 0; index -= 1) {
const turn = turns[index];
if (turn.role === "final" || turn.role === "error") break;
if (turn.role !== "user") continue;
if (
turn.text === text &&
JSON.stringify(turn.attachments ?? []) === JSON.stringify(attachments)
) {
return { turns, appended: false };
}
break;
}
return [
...turns,
{
role: "user",
text,
receivedAtMs,
...(attachments.length > 0 ? { attachments } : {}),
},
];
return {
turns: [
...turns,
{
role: "user",
text,
receivedAtMs,
...(attachments.length > 0 ? { attachments } : {}),
},
],
appended: true,
};
}
function isReplyProgressSource(value: unknown): value is ReplyProgressSource {
@ -775,14 +782,6 @@ function foldChunk(
if (isRecoverableNoResponseTurn(last) && raw.kind !== "error") {
return foldChunk({ ...state, turns: turns.slice(0, -1) }, raw, receivedAtMs);
}
if (raw.kind === "progress") {
return appendProgress(state, normalizeProgress(raw.progress) ?? {
source: "ideaLocal",
kind: "other",
stage: "info",
label: unknownChunkLabel(raw),
});
}
return state;
}
switch (raw.kind) {
@ -838,17 +837,21 @@ function foldChunk(
return { ...completedState, turns: next };
}
case "userPrompt":
case "UserPrompt":
case "UserPrompt": {
const appended = appendUserPrompt(
turns,
String(raw.text ?? raw.prompt ?? ""),
attachmentLabels(raw.attachments),
receivedAtMs,
);
return {
...state,
turns: appendUserPrompt(
turns,
String(raw.text ?? raw.prompt ?? ""),
attachmentLabels(raw.attachments),
receivedAtMs,
),
progressScope: state.progressScope + 1,
turns: appended.turns,
progressScope: appended.appended
? state.progressScope + 1
: state.progressScope,
};
}
default:
return {
...state,