Fix dashboard room thread chunk rendering (#65)
* review: harden readonly git checks and lint verification * test: satisfy readonly reviewer sandbox typing * test: fix readonly reviewer sandbox assertions * test: remove impossible readonly sandbox guards * test: relax readonly sandbox assertions * test: cast readonly sandbox expectation shape * test: cast readonly sandbox expectation through unknown * Phase 0 — STEP_DONE/TASK_DONE split + owner-follow-up integration smoke * Add STEP_DONE guards, verdict storage, and stale delivery suppression * style: format paired stepdone telemetry files * Route STEP_DONE through reviewer * Add structured Discord attachments * style: format structured attachment test * Fix room thread bot output parity * Remove duplicate work item attachment migration from owner branch * Remove legacy dashboard rooms renderer * Extract dashboard parsed body renderer * Extract dashboard redaction helpers * Extract dashboard RoomCardV2 component * Include RoomCardV2 test in vitest suite * Extract dashboard RoomBoardV2 component * Extract dashboard EmptyState component * Extract dashboard InboxPanel component * Split dashboard InboxPanel card renderer * Extract dashboard TaskPanel component * Extract dashboard UsagePanel component * Fix dashboard room thread chunk rendering
This commit is contained in:
@@ -81,6 +81,11 @@ function normalizeForDedupe(value: string): string {
|
||||
return value.replace(/\s+/g, ' ').trim();
|
||||
}
|
||||
|
||||
const MIN_SUBSTRING_DEDUPE_LENGTH = 40;
|
||||
const BOT_CHUNK_MERGE_WINDOW_MS = 15_000;
|
||||
const STATUS_OUTPUT_PREFIX_RE =
|
||||
/^(?:STEP_DONE|TASK_DONE|DONE_WITH_CONCERNS|DONE|BLOCKED|NEEDS_CONTEXT)\b/;
|
||||
|
||||
function isDuplicateOutputMessage(
|
||||
message: RoomThreadEntry,
|
||||
outputEntries: RoomThreadEntry[],
|
||||
@@ -96,7 +101,11 @@ function isDuplicateOutputMessage(
|
||||
const contentMatches =
|
||||
outputText === messageText ||
|
||||
outputText.startsWith(messageText) ||
|
||||
messageText.startsWith(outputText);
|
||||
messageText.startsWith(outputText) ||
|
||||
(messageText.length >= MIN_SUBSTRING_DEDUPE_LENGTH &&
|
||||
outputText.includes(messageText)) ||
|
||||
(outputText.length >= MIN_SUBSTRING_DEDUPE_LENGTH &&
|
||||
messageText.includes(outputText));
|
||||
if (!contentMatches) return false;
|
||||
const outputTime = new Date(output.timestamp).getTime();
|
||||
if (!Number.isFinite(messageTime) || !Number.isFinite(outputTime)) {
|
||||
@@ -106,6 +115,57 @@ function isDuplicateOutputMessage(
|
||||
});
|
||||
}
|
||||
|
||||
function entryTimeMs(entry: RoomThreadEntry): number | null {
|
||||
const time = new Date(entry.timestamp).getTime();
|
||||
return Number.isFinite(time) ? time : null;
|
||||
}
|
||||
|
||||
function shouldMergeAdjacentBotChunk(
|
||||
previous: RoomThreadEntry,
|
||||
next: RoomThreadEntry,
|
||||
): boolean {
|
||||
if (
|
||||
previous.sourceKind === 'agent_output' ||
|
||||
next.sourceKind === 'agent_output'
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (previous.senderName !== next.senderName) return false;
|
||||
if (previous.sourceKind !== next.sourceKind) return false;
|
||||
if (!previous.isBotMessage || !next.isBotMessage) return false;
|
||||
if (STATUS_OUTPUT_PREFIX_RE.test(next.content.trimStart())) return false;
|
||||
const previousTime = entryTimeMs(previous);
|
||||
const nextTime = entryTimeMs(next);
|
||||
if (previousTime === null || nextTime === null) {
|
||||
return previous.timestamp === next.timestamp;
|
||||
}
|
||||
return Math.abs(nextTime - previousTime) <= BOT_CHUNK_MERGE_WINDOW_MS;
|
||||
}
|
||||
|
||||
function mergeEntryContent(left: string, right: string): string {
|
||||
const trimmedLeft = left.trimEnd();
|
||||
const trimmedRight = right.trimStart();
|
||||
if (!trimmedLeft) return trimmedRight;
|
||||
if (!trimmedRight) return trimmedLeft;
|
||||
return `${trimmedLeft}\n\n${trimmedRight}`;
|
||||
}
|
||||
|
||||
function mergeAdjacentBotChunks(entries: RoomThreadEntry[]): RoomThreadEntry[] {
|
||||
const merged: RoomThreadEntry[] = [];
|
||||
for (const entry of entries) {
|
||||
const previous = merged.at(-1);
|
||||
if (previous && shouldMergeAdjacentBotChunk(previous, entry)) {
|
||||
previous.id = `${previous.id}+${entry.id}`;
|
||||
previous.content = mergeEntryContent(previous.content, entry.content);
|
||||
previous.verdict ??= entry.verdict;
|
||||
previous.turnNumber ??= entry.turnNumber;
|
||||
continue;
|
||||
}
|
||||
merged.push({ ...entry });
|
||||
}
|
||||
return merged;
|
||||
}
|
||||
|
||||
export function buildRoomThreadEntries({
|
||||
messages,
|
||||
outputs,
|
||||
@@ -128,7 +188,8 @@ export function buildRoomThreadEntries({
|
||||
.filter((message) => !isInternalProtocolPayload(message.content))
|
||||
.map(toMessageEntry);
|
||||
|
||||
return [...chatEntries, ...optimisticPending, ...outputEntries].sort((a, b) =>
|
||||
a.timestamp.localeCompare(b.timestamp),
|
||||
const entries = [...chatEntries, ...optimisticPending, ...outputEntries].sort(
|
||||
(a, b) => a.timestamp.localeCompare(b.timestamp),
|
||||
);
|
||||
return mergeAdjacentBotChunks(entries);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user