Align dashboard room progress with Discord messages

This commit is contained in:
ejclaw
2026-04-28 22:33:12 +09:00
parent 1417c37042
commit b83de973f8
4 changed files with 174 additions and 26 deletions

View File

@@ -211,6 +211,77 @@ describe('RoomCardV2', () => {
expect(html).toContain('<code>pnpm openapi:sync</code>'); expect(html).toContain('<code>pnpm openapi:sync</code>');
expect(html).not.toContain('`origin/dev`'); expect(html).not.toContain('`origin/dev`');
}); });
});
describe('RoomCardV2 room thread details', () => {
it('does not render site-only active turn placeholders without visible progress', () => {
const pairedTask: NonNullable<DashboardRoomActivity['pairedTask']> = {
id: 'task-1',
title: 'OpenAPI sync',
status: 'running',
roundTripCount: 1,
updatedAt: '2026-04-28T02:01:00.000Z',
currentTurn: {
turnId: 'turn-1',
role: 'owner',
intentKind: 'implementation',
state: 'running',
attemptNo: 1,
executorServiceId: 'svc-1',
executorAgentType: 'codex',
activeRunId: 'run-site-only',
createdAt: '2026-04-28T02:00:00.000Z',
updatedAt: '2026-04-28T02:01:00.000Z',
completedAt: null,
lastError: null,
progressText: null,
progressUpdatedAt: null,
},
outputs: [],
};
const collapsed = renderToStaticMarkup(
createElement(RoomCardV2, {
activity: activity({ pairedTask }),
activityLoading: false,
busy: false,
draft: '',
entry: { ...entry, status: 'processing' },
expanded: false,
inboxItems: [],
locale: 'ko',
onDraftChange: () => {},
onSendMessage: () => {},
onToggle: () => {},
pinned: false,
t,
...formatters,
}),
);
const expanded = renderToStaticMarkup(
createElement(RoomCardV2, {
activity: activity({ pairedTask }),
activityLoading: false,
busy: false,
draft: '',
entry: { ...entry, status: 'processing' },
expanded: true,
inboxItems: [],
locale: 'ko',
onDraftChange: () => {},
onSendMessage: () => {},
onToggle: () => {},
pinned: false,
t,
...formatters,
}),
);
expect(collapsed).not.toContain('class="room-live"');
expect(expanded).not.toContain('room-timeline-live');
expect(expanded).not.toContain(t.rooms.loadingActivity);
expect(expanded).toContain(t.rooms.noActivity);
});
it('renders message attachments as dashboard images', () => { it('renders message attachments as dashboard images', () => {
const html = renderToStaticMarkup( const html = renderToStaticMarkup(

View File

@@ -227,6 +227,7 @@ export function RoomCardV2({
expanded={expanded} expanded={expanded}
formatDate={formatDate} formatDate={formatDate}
isProcessing={isProcessing} isProcessing={isProcessing}
liveProgressDisplay={liveProgressDisplay}
locale={locale} locale={locale}
senderRoleClass={senderRoleClass} senderRoleClass={senderRoleClass}
t={t} t={t}
@@ -488,6 +489,7 @@ function CollapsedLiveTurn({
expanded, expanded,
formatDate, formatDate,
isProcessing, isProcessing,
liveProgressDisplay,
locale, locale,
senderRoleClass, senderRoleClass,
t, t,
@@ -496,12 +498,13 @@ function CollapsedLiveTurn({
expanded: boolean; expanded: boolean;
formatDate: RoomCardFormatters['formatDate']; formatDate: RoomCardFormatters['formatDate'];
isProcessing: boolean; isProcessing: boolean;
liveProgressDisplay: string | null;
locale: Locale; locale: Locale;
senderRoleClass: RoomCardFormatters['senderRoleClass']; senderRoleClass: RoomCardFormatters['senderRoleClass'];
t: Messages; t: Messages;
turn: RoomTurn | null; turn: RoomTurn | null;
}) { }) {
if (expanded || !isProcessing || !turn) return null; if (expanded || !isProcessing || !turn || !liveProgressDisplay) return null;
return ( return (
<div className="room-live"> <div className="room-live">
<header> <header>
@@ -524,11 +527,7 @@ function CollapsedLiveTurn({
{formatDate(turn.progressUpdatedAt ?? turn.updatedAt, locale)} {formatDate(turn.progressUpdatedAt ?? turn.updatedAt, locale)}
</time> </time>
</header> </header>
{turn.progressText && turn.progressText.trim() ? ( <LiveProgressBody text={liveProgressDisplay} />
<LiveProgressBody text={turn.progressText} />
) : turn.activeRunId ? (
<code className="live-run">{turn.activeRunId}</code>
) : null}
</div> </div>
); );
} }
@@ -702,15 +701,18 @@ function RoomThreadSection({
t: Messages; t: Messages;
turn: RoomTurn | null; turn: RoomTurn | null;
}) { }) {
const showLiveItem = const showLiveItem = !!(
turn && turn.completedAt === null && (isProcessing || liveProgressDisplay); turn &&
turn.completedAt === null &&
liveProgressDisplay
);
return ( return (
<section className="room-section room-thread-section"> <section className="room-section room-thread-section">
<header> <header>
<h4>{t.rooms.activity}</h4> <h4>{t.rooms.activity}</h4>
<small>{agentMessages.length}</small> <small>{agentMessages.length}</small>
</header> </header>
{agentMessages.length === 0 && !(isProcessing && turn) ? ( {agentMessages.length === 0 && !showLiveItem ? (
<p className="room-empty">{t.rooms.noActivity}</p> <p className="room-empty">{t.rooms.noActivity}</p>
) : ( ) : (
<ol className="room-timeline"> <ol className="room-timeline">

View File

@@ -236,7 +236,9 @@ describe('web dashboard data', () => {
); );
expect(sanitized.promptPreview).not.toContain('plain-secret-value'); expect(sanitized.promptPreview).not.toContain('plain-secret-value');
}); });
});
describe('web dashboard room activity data', () => {
it('builds redacted room activity from messages and paired turn output', () => { it('builds redacted room activity from messages and paired turn output', () => {
const longMessageTail = 'TAIL_MESSAGE_VISIBLE'; const longMessageTail = 'TAIL_MESSAGE_VISIBLE';
const longOutputTail = 'TAIL_OUTPUT_VISIBLE'; const longOutputTail = 'TAIL_OUTPUT_VISIBLE';
@@ -375,6 +377,8 @@ describe('web dashboard data', () => {
updated_at: '2026-04-26T06:10:00.000Z', updated_at: '2026-04-26T06:10:00.000Z',
completed_at: null, completed_at: null,
last_error: null, last_error: null,
progress_text: 'internal progress that Discord never showed',
progress_updated_at: '2026-04-26T06:07:00.000Z',
}; };
const statusPrefix = ''; const statusPrefix = '';
const messages: NewMessage[] = [ const messages: NewMessage[] = [
@@ -406,7 +410,7 @@ describe('web dashboard data', () => {
id: 'msg-live-progress', id: 'msg-live-progress',
chat_jid: 'dc:ops', chat_jid: 'dc:ops',
sender: 'bot-1', sender: 'bot-1',
sender_name: '오너', sender_name: 'clone-코덱스',
content: `${statusPrefix}building mobile parity\n\n12s`, content: `${statusPrefix}building mobile parity\n\n12s`,
timestamp: '2026-04-26T06:08:00.000Z', timestamp: '2026-04-26T06:08:00.000Z',
is_from_me: true, is_from_me: true,
@@ -447,6 +451,71 @@ describe('web dashboard data', () => {
]); ]);
}); });
it('does not show internal turn progress without a Discord-visible status message', () => {
const task = makePairedTask({
id: 'paired-progress-internal',
chat_jid: 'dc:ops',
status: 'active',
updated_at: '2026-04-26T06:10:00.000Z',
});
const turn: PairedTurnRecord = {
turn_id: 'turn-progress-internal',
task_id: task.id,
task_updated_at: task.updated_at,
role: 'owner',
intent_kind: 'owner-turn',
state: 'running',
executor_service_id: 'codex-main',
executor_agent_type: 'codex',
attempt_no: 1,
created_at: '2026-04-26T06:00:00.000Z',
updated_at: '2026-04-26T06:10:00.000Z',
completed_at: null,
last_error: null,
progress_text: 'site-only internal progress',
progress_updated_at: '2026-04-26T06:09:00.000Z',
};
const activity = buildWebDashboardRoomActivity({
serviceId: 'codex-main',
entry: {
jid: 'dc:ops',
name: '#ops',
folder: 'ops',
agentType: 'codex',
status: 'processing',
elapsedMs: 20_000,
pendingMessages: false,
pendingTasks: 0,
},
pairedTask: task,
turns: [turn],
attempts: [],
outputs: [],
messages: [],
progressMessages: [
{
id: 'spoofed-progress',
chat_jid: 'dc:ops',
sender: 'user-1',
sender_name: '눈쟁이',
content: 'human spoofed progress',
timestamp: '2026-04-26T06:09:30.000Z',
is_from_me: false,
is_bot_message: false,
message_source_kind: 'human',
},
],
});
expect(activity.pairedTask?.currentTurn).toMatchObject({
progressText: null,
progressUpdatedAt: null,
});
});
});
describe('web dashboard inbox data', () => {
it('builds typed inbox items from pending rooms, paired tasks, and CI failures', () => { it('builds typed inbox items from pending rooms, paired tasks, and CI failures', () => {
const snapshots: StatusSnapshot[] = [ const snapshots: StatusSnapshot[] = [
{ {

View File

@@ -514,6 +514,16 @@ function turnRoleFromSenderName(name: string | null | undefined): string {
return 'human'; return 'human';
} }
function isBotProgressSource(message: NewMessage): boolean {
return (
!!message.is_bot_message ||
!!message.is_from_me ||
message.message_source_kind === 'bot' ||
message.message_source_kind === 'ipc_injected_bot' ||
message.message_source_kind === 'trusted_external_bot'
);
}
function deriveLiveProgress( function deriveLiveProgress(
turnRole: string, turnRole: string,
turnCreatedAt: string, turnCreatedAt: string,
@@ -528,7 +538,9 @@ function deriveLiveProgress(
const ts = m.timestamp ? new Date(m.timestamp).getTime() : 0; const ts = m.timestamp ? new Date(m.timestamp).getTime() : 0;
if (Number.isFinite(startMs) && ts < startMs) continue; if (Number.isFinite(startMs) && ts < startMs) continue;
const role = turnRoleFromSenderName(m.sender_name); const role = turnRoleFromSenderName(m.sender_name);
if (role !== targetRole) continue; if (role !== targetRole && (role !== 'human' || !isBotProgressSource(m))) {
continue;
}
const body = content.slice(TASK_STATUS_PREFIX.length); const body = content.slice(TASK_STATUS_PREFIX.length);
const stripped = body.replace(/\n\n\d+[초smhMSH]?$/, '').trim(); const stripped = body.replace(/\n\n\d+[초smhMSH]?$/, '').trim();
if (!stripped) continue; if (!stripped) continue;
@@ -546,19 +558,13 @@ function sanitizeRoomTurn(
const createdAt = attempt?.created_at ?? turn.created_at; const createdAt = attempt?.created_at ?? turn.created_at;
const completedAt = attempt?.completed_at ?? turn.completed_at; const completedAt = attempt?.completed_at ?? turn.completed_at;
// Read paired_turns.progress_text first (written by recordTurnProgress // Dashboard progress must match Discord-visible progress. The legacy
// when the controller is in the loop). If that's empty AND the turn is // paired_turns.progress_text column is written before Discord delivery, so
// active, fall back to scanning the messages table for the most recent // using it here can create site-only progress that never appeared in Discord.
// TASK_STATUS-prefixed message — same content the Discord bridge ingests. const live =
let progressText = turn.progress_text ?? null; completedAt === null
let progressUpdatedAt = turn.progress_updated_at ?? null; ? deriveLiveProgress(role, createdAt, messages)
if ((!progressText || !progressText.trim()) && completedAt === null) { : { progressText: null, progressUpdatedAt: null };
const live = deriveLiveProgress(role, createdAt, messages);
if (live.progressText) {
progressText = live.progressText;
progressUpdatedAt = live.progressUpdatedAt;
}
}
return { return {
turnId: turn.turn_id, turnId: turn.turn_id,
@@ -576,8 +582,8 @@ function sanitizeRoomTurn(
(attempt?.last_error ?? turn.last_error) (attempt?.last_error ?? turn.last_error)
? buildRoomBody(attempt?.last_error ?? turn.last_error ?? '') ? buildRoomBody(attempt?.last_error ?? turn.last_error ?? '')
: null, : null,
progressText, progressText: live.progressText,
progressUpdatedAt, progressUpdatedAt: live.progressUpdatedAt,
}; };
} }