Merge pull request #86 from phj1081/codex/owner/ejclaw
Extract handoff helpers and canonicalize room progress
This commit is contained in:
@@ -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(
|
||||||
|
|||||||
@@ -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">
|
||||||
|
|||||||
@@ -141,10 +141,6 @@
|
|||||||
"maxFunctionLines": 239,
|
"maxFunctionLines": 239,
|
||||||
"owner": "message executor hotspot"
|
"owner": "message executor hotspot"
|
||||||
},
|
},
|
||||||
"src/message-runtime-handoffs.ts": {
|
|
||||||
"maxFunctionLines": 207,
|
|
||||||
"owner": "message runtime handoffs hotspot"
|
|
||||||
},
|
|
||||||
"src/message-runtime-queue.test.ts": {
|
"src/message-runtime-queue.test.ts": {
|
||||||
"maxFunctionLines": 366,
|
"maxFunctionLines": 366,
|
||||||
"owner": "message runtime queue test hotspot"
|
"owner": "message runtime queue test hotspot"
|
||||||
|
|||||||
@@ -19,7 +19,12 @@ import {
|
|||||||
import { buildPairedTurnIdentity } from './paired-turn-identity.js';
|
import { buildPairedTurnIdentity } from './paired-turn-identity.js';
|
||||||
import type { ScheduledPairedFollowUpIntentKind } from './paired-follow-up-scheduler.js';
|
import type { ScheduledPairedFollowUpIntentKind } from './paired-follow-up-scheduler.js';
|
||||||
import type { ExecuteTurnFn } from './message-runtime-types.js';
|
import type { ExecuteTurnFn } from './message-runtime-types.js';
|
||||||
import type { Channel, PairedTask, RegisteredGroup } from './types.js';
|
import type {
|
||||||
|
Channel,
|
||||||
|
PairedRoomRole,
|
||||||
|
PairedTask,
|
||||||
|
RegisteredGroup,
|
||||||
|
} from './types.js';
|
||||||
|
|
||||||
export function enqueuePendingHandoffs(args: {
|
export function enqueuePendingHandoffs(args: {
|
||||||
enqueueTask: (
|
enqueueTask: (
|
||||||
@@ -158,6 +163,61 @@ function failClaimedHandoff(args: {
|
|||||||
requeueFailedClaimedPairedTurn(args);
|
requeueFailedClaimedPairedTurn(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveHandoffDeliveryChannel(args: {
|
||||||
|
handoff: ServiceHandoff;
|
||||||
|
handoffRole: PairedRoomRole;
|
||||||
|
fallbackChannel: Channel;
|
||||||
|
channels: Channel[];
|
||||||
|
getPairedTaskById?:
|
||||||
|
| ((
|
||||||
|
id: string,
|
||||||
|
) =>
|
||||||
|
| Pick<PairedTask, 'id' | 'status' | 'round_trip_count' | 'updated_at'>
|
||||||
|
| undefined)
|
||||||
|
| undefined;
|
||||||
|
enqueueMessageCheck?: ((chatJid: string) => void) | undefined;
|
||||||
|
}): Channel | undefined {
|
||||||
|
const { handoff, handoffRole } = args;
|
||||||
|
if (handoffRole === 'owner') {
|
||||||
|
return args.fallbackChannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
const roleChannel = findChannelByName(
|
||||||
|
args.channels,
|
||||||
|
getFixedRoleChannelName(handoffRole),
|
||||||
|
);
|
||||||
|
if (!roleChannel) {
|
||||||
|
failClaimedHandoff({
|
||||||
|
handoff,
|
||||||
|
error: getMissingRoleChannelMessage(handoffRole),
|
||||||
|
getPairedTaskById: args.getPairedTaskById,
|
||||||
|
enqueueMessageCheck: args.enqueueMessageCheck,
|
||||||
|
});
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return roleChannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildHandoffPairedTurnIdentity(
|
||||||
|
handoff: ServiceHandoff,
|
||||||
|
handoffRole: PairedRoomRole,
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
!handoff.paired_task_id ||
|
||||||
|
!handoff.paired_task_updated_at ||
|
||||||
|
!handoff.turn_intent_kind
|
||||||
|
) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return buildPairedTurnIdentity({
|
||||||
|
taskId: handoff.paired_task_id,
|
||||||
|
taskUpdatedAt: handoff.paired_task_updated_at,
|
||||||
|
intentKind: handoff.turn_intent_kind,
|
||||||
|
role: handoff.turn_role ?? handoffRole,
|
||||||
|
turnId: handoff.turn_id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export async function processClaimedHandoff(args: {
|
export async function processClaimedHandoff(args: {
|
||||||
handoff: ServiceHandoff;
|
handoff: ServiceHandoff;
|
||||||
getRoomBindings: () => Record<string, RegisteredGroup>;
|
getRoomBindings: () => Record<string, RegisteredGroup>;
|
||||||
@@ -239,52 +299,23 @@ export async function processClaimedHandoff(args: {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let handoffChannel = channel;
|
const handoffChannel = resolveHandoffDeliveryChannel({
|
||||||
if (handoffRole === 'reviewer') {
|
handoff,
|
||||||
const reviewerChannel = findChannelByName(
|
handoffRole,
|
||||||
args.channels,
|
fallbackChannel: channel,
|
||||||
getFixedRoleChannelName('reviewer'),
|
channels: args.channels,
|
||||||
);
|
getPairedTaskById: args.getPairedTaskById,
|
||||||
if (!reviewerChannel) {
|
enqueueMessageCheck: args.enqueueMessageCheck,
|
||||||
failClaimedHandoff({
|
});
|
||||||
handoff,
|
if (!handoffChannel) {
|
||||||
error: getMissingRoleChannelMessage('reviewer'),
|
return;
|
||||||
getPairedTaskById: args.getPairedTaskById,
|
|
||||||
enqueueMessageCheck: args.enqueueMessageCheck,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
handoffChannel = reviewerChannel;
|
|
||||||
} else if (handoffRole === 'arbiter') {
|
|
||||||
const arbiterChannel = findChannelByName(
|
|
||||||
args.channels,
|
|
||||||
getFixedRoleChannelName('arbiter'),
|
|
||||||
);
|
|
||||||
if (!arbiterChannel) {
|
|
||||||
failClaimedHandoff({
|
|
||||||
handoff,
|
|
||||||
error: getMissingRoleChannelMessage('arbiter'),
|
|
||||||
getPairedTaskById: args.getPairedTaskById,
|
|
||||||
enqueueMessageCheck: args.enqueueMessageCheck,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
handoffChannel = arbiterChannel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const runId = `handoff-${handoff.id}`;
|
const runId = `handoff-${handoff.id}`;
|
||||||
const pairedTurnIdentity =
|
const pairedTurnIdentity = buildHandoffPairedTurnIdentity(
|
||||||
handoff.paired_task_id &&
|
handoff,
|
||||||
handoff.paired_task_updated_at &&
|
handoffRole,
|
||||||
handoff.turn_intent_kind
|
);
|
||||||
? buildPairedTurnIdentity({
|
|
||||||
taskId: handoff.paired_task_id,
|
|
||||||
taskUpdatedAt: handoff.paired_task_updated_at,
|
|
||||||
intentKind: handoff.turn_intent_kind,
|
|
||||||
role: handoff.turn_role ?? handoffRole,
|
|
||||||
turnId: handoff.turn_id,
|
|
||||||
})
|
|
||||||
: undefined;
|
|
||||||
try {
|
try {
|
||||||
logger.info(
|
logger.info(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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';
|
||||||
@@ -354,7 +356,7 @@ describe('web dashboard data', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses Discord live progress messages without exposing them as recent chat', () => {
|
it('uses canonical turn progress without exposing status messages as recent chat', () => {
|
||||||
const task = makePairedTask({
|
const task = makePairedTask({
|
||||||
id: 'paired-room-progress',
|
id: 'paired-room-progress',
|
||||||
chat_jid: 'dc:ops',
|
chat_jid: 'dc:ops',
|
||||||
@@ -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: 'building mobile parity',
|
||||||
|
progress_updated_at: '2026-04-26T06:07:00.000Z',
|
||||||
};
|
};
|
||||||
const statusPrefix = '';
|
const statusPrefix = '';
|
||||||
const messages: NewMessage[] = [
|
const messages: NewMessage[] = [
|
||||||
@@ -389,25 +393,12 @@ describe('web dashboard data', () => {
|
|||||||
is_bot_message: false,
|
is_bot_message: false,
|
||||||
message_source_kind: 'human',
|
message_source_kind: 'human',
|
||||||
},
|
},
|
||||||
];
|
|
||||||
const progressMessages: NewMessage[] = [
|
|
||||||
{
|
{
|
||||||
id: 'msg-stale-progress',
|
id: 'msg-status-progress',
|
||||||
chat_jid: 'dc:ops',
|
chat_jid: 'dc:ops',
|
||||||
sender: 'bot-1',
|
sender: 'bot-1',
|
||||||
sender_name: '오너',
|
sender_name: '오너',
|
||||||
content: `${statusPrefix}stale progress`,
|
content: `${statusPrefix}status noise that belongs to display only\n\n12s`,
|
||||||
timestamp: '2026-04-26T05:59:00.000Z',
|
|
||||||
is_from_me: true,
|
|
||||||
is_bot_message: true,
|
|
||||||
message_source_kind: 'bot',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'msg-live-progress',
|
|
||||||
chat_jid: 'dc:ops',
|
|
||||||
sender: 'bot-1',
|
|
||||||
sender_name: '오너',
|
|
||||||
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,
|
||||||
is_bot_message: true,
|
is_bot_message: true,
|
||||||
@@ -432,12 +423,11 @@ describe('web dashboard data', () => {
|
|||||||
attempts: [],
|
attempts: [],
|
||||||
outputs: [],
|
outputs: [],
|
||||||
messages,
|
messages,
|
||||||
progressMessages,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(activity.pairedTask?.currentTurn).toMatchObject({
|
expect(activity.pairedTask?.currentTurn).toMatchObject({
|
||||||
progressText: 'building mobile parity',
|
progressText: 'building mobile parity',
|
||||||
progressUpdatedAt: '2026-04-26T06:08:00.000Z',
|
progressUpdatedAt: '2026-04-26T06:07:00.000Z',
|
||||||
});
|
});
|
||||||
expect(activity.messages).toEqual([
|
expect(activity.messages).toEqual([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
@@ -447,6 +437,58 @@ describe('web dashboard data', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not show active turn placeholders when canonical progress is absent', () => {
|
||||||
|
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: null,
|
||||||
|
progress_updated_at: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
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: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
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[] = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -492,73 +492,26 @@ function sanitizeRoomMessage(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* SSOT for live progress: scan the `messages` table for the most recent
|
|
||||||
* TASK_STATUS_MESSAGE_PREFIX-prefixed message that belongs to the current
|
|
||||||
* turn (sender role match + timestamp >= turn.created_at). The Discord
|
|
||||||
* bridge ingests every edit of the bot's live message back into messages,
|
|
||||||
* so this single source replaces the legacy paired_turns.progress_text
|
|
||||||
* column for derivation.
|
|
||||||
*/
|
|
||||||
const TASK_STATUS_PREFIX = '';
|
const TASK_STATUS_PREFIX = '';
|
||||||
|
|
||||||
function isTaskStatusMessage(message: NewMessage): boolean {
|
function isTaskStatusMessage(message: NewMessage): boolean {
|
||||||
return (message.content ?? '').startsWith(TASK_STATUS_PREFIX);
|
return (message.content ?? '').startsWith(TASK_STATUS_PREFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
function turnRoleFromSenderName(name: string | null | undefined): string {
|
|
||||||
const v = (name ?? '').toLowerCase();
|
|
||||||
if (v.includes('오너') || v.includes('owner')) return 'owner';
|
|
||||||
if (v.includes('리뷰어') || v.includes('reviewer')) return 'reviewer';
|
|
||||||
if (v.includes('중재자') || v.includes('arbiter')) return 'arbiter';
|
|
||||||
return 'human';
|
|
||||||
}
|
|
||||||
|
|
||||||
function deriveLiveProgress(
|
|
||||||
turnRole: string,
|
|
||||||
turnCreatedAt: string,
|
|
||||||
messages: NewMessage[],
|
|
||||||
): { progressText: string | null; progressUpdatedAt: string | null } {
|
|
||||||
const startMs = new Date(turnCreatedAt).getTime();
|
|
||||||
const targetRole = turnRoleFromSenderName(turnRole);
|
|
||||||
for (let i = messages.length - 1; i >= 0; i--) {
|
|
||||||
const m = messages[i];
|
|
||||||
const content = m.content ?? '';
|
|
||||||
if (!content.startsWith(TASK_STATUS_PREFIX)) continue;
|
|
||||||
const ts = m.timestamp ? new Date(m.timestamp).getTime() : 0;
|
|
||||||
if (Number.isFinite(startMs) && ts < startMs) continue;
|
|
||||||
const role = turnRoleFromSenderName(m.sender_name);
|
|
||||||
if (role !== targetRole) continue;
|
|
||||||
const body = content.slice(TASK_STATUS_PREFIX.length);
|
|
||||||
const stripped = body.replace(/\n\n\d+[초smhMSH]?$/, '').trim();
|
|
||||||
if (!stripped) continue;
|
|
||||||
return { progressText: stripped, progressUpdatedAt: m.timestamp };
|
|
||||||
}
|
|
||||||
return { progressText: null, progressUpdatedAt: null };
|
|
||||||
}
|
|
||||||
|
|
||||||
function sanitizeRoomTurn(
|
function sanitizeRoomTurn(
|
||||||
turn: PairedTurnRecord,
|
turn: PairedTurnRecord,
|
||||||
attempt: PairedTurnAttemptRecord | null,
|
attempt: PairedTurnAttemptRecord | null,
|
||||||
messages: NewMessage[] = [],
|
|
||||||
): WebDashboardRoomTurn {
|
): WebDashboardRoomTurn {
|
||||||
const role = attempt?.role ?? turn.role;
|
const role = attempt?.role ?? turn.role;
|
||||||
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;
|
||||||
|
const canonicalProgress =
|
||||||
// Read paired_turns.progress_text first (written by recordTurnProgress
|
completedAt === null && turn.progress_text?.trim()
|
||||||
// when the controller is in the loop). If that's empty AND the turn is
|
? {
|
||||||
// active, fall back to scanning the messages table for the most recent
|
progressText: buildRoomBody(turn.progress_text),
|
||||||
// TASK_STATUS-prefixed message — same content the Discord bridge ingests.
|
progressUpdatedAt: turn.progress_updated_at ?? turn.updated_at,
|
||||||
let progressText = turn.progress_text ?? null;
|
}
|
||||||
let progressUpdatedAt = turn.progress_updated_at ?? null;
|
: { progressText: null, progressUpdatedAt: null };
|
||||||
if ((!progressText || !progressText.trim()) && completedAt === 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 +529,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: canonicalProgress.progressText,
|
||||||
progressUpdatedAt,
|
progressUpdatedAt: canonicalProgress.progressUpdatedAt,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -606,7 +559,6 @@ export function buildWebDashboardRoomActivity(args: {
|
|||||||
attempts: PairedTurnAttemptRecord[];
|
attempts: PairedTurnAttemptRecord[];
|
||||||
outputs: PairedTurnOutput[];
|
outputs: PairedTurnOutput[];
|
||||||
messages: NewMessage[];
|
messages: NewMessage[];
|
||||||
progressMessages?: NewMessage[];
|
|
||||||
outputLimit?: number;
|
outputLimit?: number;
|
||||||
}): WebDashboardRoomActivity {
|
}): WebDashboardRoomActivity {
|
||||||
const latestAttemptByTurnId = new Map<string, PairedTurnAttemptRecord>();
|
const latestAttemptByTurnId = new Map<string, PairedTurnAttemptRecord>();
|
||||||
@@ -649,11 +601,7 @@ export function buildWebDashboardRoomActivity(args: {
|
|||||||
roundTripCount: args.pairedTask.round_trip_count,
|
roundTripCount: args.pairedTask.round_trip_count,
|
||||||
updatedAt: args.pairedTask.updated_at,
|
updatedAt: args.pairedTask.updated_at,
|
||||||
currentTurn: currentTurn
|
currentTurn: currentTurn
|
||||||
? sanitizeRoomTurn(
|
? sanitizeRoomTurn(currentTurn, currentAttempt)
|
||||||
currentTurn,
|
|
||||||
currentAttempt,
|
|
||||||
args.progressMessages ?? args.messages,
|
|
||||||
)
|
|
||||||
: null,
|
: null,
|
||||||
outputs: args.outputs
|
outputs: args.outputs
|
||||||
.slice(-outputLimit)
|
.slice(-outputLimit)
|
||||||
|
|||||||
@@ -106,6 +106,8 @@ describe('web dashboard room routes', () => {
|
|||||||
updated_at: '2026-04-26T05:21:00.000Z',
|
updated_at: '2026-04-26T05:21:00.000Z',
|
||||||
completed_at: null,
|
completed_at: null,
|
||||||
last_error: null,
|
last_error: null,
|
||||||
|
progress_text: 'checking current output',
|
||||||
|
progress_updated_at: '2026-04-26T05:20:00.000Z',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const attempts: PairedTurnAttemptRecord[] = [
|
const attempts: PairedTurnAttemptRecord[] = [
|
||||||
@@ -154,20 +156,6 @@ describe('web dashboard room routes', () => {
|
|||||||
message_source_kind: 'human',
|
message_source_kind: 'human',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const progressMessages: NewMessage[] = [
|
|
||||||
...messages,
|
|
||||||
{
|
|
||||||
id: 'msg-progress',
|
|
||||||
chat_jid: 'dc:ops',
|
|
||||||
sender: 'reviewer-bot',
|
|
||||||
sender_name: '리뷰어',
|
|
||||||
content: 'checking current output\n\n9s',
|
|
||||||
timestamp: '2026-04-26T05:20:00.000Z',
|
|
||||||
is_from_me: true,
|
|
||||||
is_bot_message: true,
|
|
||||||
message_source_kind: 'bot',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
const requestedMessageLimits: number[] = [];
|
const requestedMessageLimits: number[] = [];
|
||||||
const response = handleRoomTimelineRoute({
|
const response = handleRoomTimelineRoute({
|
||||||
url: new URL(
|
url: new URL(
|
||||||
@@ -182,7 +170,7 @@ describe('web dashboard room routes', () => {
|
|||||||
loadPairedTurnOutputs: () => outputs,
|
loadPairedTurnOutputs: () => outputs,
|
||||||
loadRecentChatMessages: (_jid, limit) => {
|
loadRecentChatMessages: (_jid, limit) => {
|
||||||
requestedMessageLimits.push(limit ?? 20);
|
requestedMessageLimits.push(limit ?? 20);
|
||||||
return limit && limit > 8 ? progressMessages : messages;
|
return messages;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
@@ -202,7 +190,7 @@ describe('web dashboard room routes', () => {
|
|||||||
expect(body.pairedTask.outputs).toMatchObject([
|
expect(body.pairedTask.outputs).toMatchObject([
|
||||||
{ outputText: 'owner final output' },
|
{ outputText: 'owner final output' },
|
||||||
]);
|
]);
|
||||||
expect(requestedMessageLimits).toEqual([8, 40]);
|
expect(requestedMessageLimits).toEqual([8]);
|
||||||
expect(body.messages[0]).toMatchObject({
|
expect(body.messages[0]).toMatchObject({
|
||||||
content: expect.stringContaining('BOT_TOKEN=<redacted>'),
|
content: expect.stringContaining('BOT_TOKEN=<redacted>'),
|
||||||
senderName: '눈쟁이',
|
senderName: '눈쟁이',
|
||||||
|
|||||||
@@ -98,7 +98,6 @@ function buildRoomActivity(
|
|||||||
attempts,
|
attempts,
|
||||||
outputs: pairedTask ? deps.loadPairedTurnOutputs(pairedTask.id) : [],
|
outputs: pairedTask ? deps.loadPairedTurnOutputs(pairedTask.id) : [],
|
||||||
messages: deps.loadRecentChatMessages(entry.jid, 8),
|
messages: deps.loadRecentChatMessages(entry.jid, 8),
|
||||||
progressMessages: deps.loadRecentChatMessages(entry.jid, 40),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,9 +128,6 @@ export function buildRoomsTimelineResult(
|
|||||||
for (const [jid, { snapshot, entry }] of uniqueByJid) {
|
for (const [jid, { snapshot, entry }] of uniqueByJid) {
|
||||||
const pairedTask = deps.loadLatestPairedTaskForChat(jid) ?? null;
|
const pairedTask = deps.loadLatestPairedTaskForChat(jid) ?? null;
|
||||||
const messages = deps.loadRecentChatMessages(jid, 8);
|
const messages = deps.loadRecentChatMessages(jid, 8);
|
||||||
const progressMessages = pairedTask
|
|
||||||
? deps.loadRecentChatMessages(jid, 40)
|
|
||||||
: messages;
|
|
||||||
const outputs = deps.loadRecentPairedTurnOutputsForChat(jid, 8);
|
const outputs = deps.loadRecentPairedTurnOutputsForChat(jid, 8);
|
||||||
if (!pairedTask && messages.length === 0 && outputs.length === 0) continue;
|
if (!pairedTask && messages.length === 0 && outputs.length === 0) continue;
|
||||||
|
|
||||||
@@ -147,7 +143,6 @@ export function buildRoomsTimelineResult(
|
|||||||
attempts: [],
|
attempts: [],
|
||||||
outputs,
|
outputs,
|
||||||
messages,
|
messages,
|
||||||
progressMessages,
|
|
||||||
outputLimit: 8,
|
outputLimit: 8,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ describe('web dashboard server handler', () => {
|
|||||||
id: 'paired-room-1',
|
id: 'paired-room-1',
|
||||||
roundTripCount: 2,
|
roundTripCount: 2,
|
||||||
});
|
});
|
||||||
expect(requestedMessageLimits).toEqual([8, 40]);
|
expect(requestedMessageLimits).toEqual([8]);
|
||||||
expect(body.messages).toMatchObject([
|
expect(body.messages).toMatchObject([
|
||||||
{ content: '진행 어디까지야?', senderName: '눈쟁이' },
|
{ content: '진행 어디까지야?', senderName: '눈쟁이' },
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user