fix: clean up progress tracking, fix subagent summary field handling
- Use system/task_progress subtype (not top-level type) for subagent events - Extract intermediate assistant text between tool calls as progress - Only show SDK-generated summaries for subagent progress (skip noisy per-tool updates) - Truncate progress messages to Discord 2000 char limit - Remove verbose debug logging from production
This commit is contained in:
@@ -551,11 +551,11 @@ async function runQuery(
|
|||||||
log(`Task notification: task=${tn.task_id} status=${tn.status} summary=${tn.summary}`);
|
log(`Task notification: task=${tn.task_id} status=${tn.status} summary=${tn.summary}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((message as { type: string }).type === 'task_progress') {
|
if (message.type === 'system' && (message as { subtype?: string }).subtype === 'task_progress') {
|
||||||
const tp = message as { task_id: string; summary?: string };
|
const tp = message as Record<string, unknown>;
|
||||||
const summary = tp.summary || '';
|
const summary = typeof tp.summary === 'string' ? tp.summary : '';
|
||||||
log(`Subagent progress: task=${tp.task_id} summary=${summary.slice(0, 200)}`);
|
|
||||||
if (summary) {
|
if (summary) {
|
||||||
|
log(`Subagent progress: ${summary.slice(0, 200)}`);
|
||||||
writeOutput({
|
writeOutput({
|
||||||
status: 'success',
|
status: 'success',
|
||||||
phase: 'progress',
|
phase: 'progress',
|
||||||
@@ -565,7 +565,7 @@ async function runQuery(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((message as { type: string }).type === 'task_started') {
|
if (message.type === 'system' && (message as { subtype?: string }).subtype === 'task_started') {
|
||||||
const ts = message as { task_id: string; teammate_name?: string };
|
const ts = message as { task_id: string; teammate_name?: string };
|
||||||
log(`Subagent started: task=${ts.task_id} name=${ts.teammate_name || 'unknown'}`);
|
log(`Subagent started: task=${ts.task_id} name=${ts.teammate_name || 'unknown'}`);
|
||||||
}
|
}
|
||||||
@@ -644,6 +644,10 @@ async function runQuery(
|
|||||||
if (message.type === 'assistant') {
|
if (message.type === 'assistant') {
|
||||||
const stopReason = (message as { stop_reason?: string }).stop_reason;
|
const stopReason = (message as { stop_reason?: string }).stop_reason;
|
||||||
const textResult = extractAssistantText(message);
|
const textResult = extractAssistantText(message);
|
||||||
|
// Only log when there's something interesting (text or terminal)
|
||||||
|
if (textResult || stopReason === 'end_turn') {
|
||||||
|
log(`Assistant: stop=${stopReason} text=${textResult ? textResult.length + ' chars' : 'null'}`);
|
||||||
|
}
|
||||||
if (stopReason === 'end_turn' && textResult) {
|
if (stopReason === 'end_turn' && textResult) {
|
||||||
resultCount++;
|
resultCount++;
|
||||||
log(
|
log(
|
||||||
@@ -659,6 +663,16 @@ async function runQuery(
|
|||||||
stream.end();
|
stream.end();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// Intermediate assistant text between tool calls → progress
|
||||||
|
if (stopReason !== 'end_turn' && textResult) {
|
||||||
|
log(`Intermediate assistant text (${textResult.length} chars, stop=${stopReason})`);
|
||||||
|
writeOutput({
|
||||||
|
status: 'success',
|
||||||
|
phase: 'progress',
|
||||||
|
result: textResult,
|
||||||
|
newSessionId,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ export async function runAgentProcess(
|
|||||||
const lines = chunk.trim().split('\n');
|
const lines = chunk.trim().split('\n');
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (!line) continue;
|
if (!line) continue;
|
||||||
if (line.includes('Turn in progress')) {
|
if (line.includes('Turn in progress') || line.includes('Subagent') || line.includes('Intermediate assistant')) {
|
||||||
logger.info(
|
logger.info(
|
||||||
{ group: group.name, chatJid: input.chatJid, runId: input.runId },
|
{ group: group.name, chatJid: input.chatJid, runId: input.runId },
|
||||||
line.replace(/^\[.*?\]\s*/, ''),
|
line.replace(/^\[.*?\]\s*/, ''),
|
||||||
|
|||||||
@@ -212,7 +212,10 @@ export class MessageTurnController {
|
|||||||
if (minutes > 0) elapsedParts.push(`${minutes}분`);
|
if (minutes > 0) elapsedParts.push(`${minutes}분`);
|
||||||
elapsedParts.push(`${seconds}초`);
|
elapsedParts.push(`${seconds}초`);
|
||||||
|
|
||||||
return `${TASK_STATUS_MESSAGE_PREFIX}${text}\n\n${elapsedParts.join(' ')}`;
|
const suffix = `\n\n${elapsedParts.join(' ')}`;
|
||||||
|
const maxText = 2000 - TASK_STATUS_MESSAGE_PREFIX.length - suffix.length;
|
||||||
|
const truncated = text.length > maxText ? text.slice(0, maxText - 1) + '…' : text;
|
||||||
|
return `${TASK_STATUS_MESSAGE_PREFIX}${truncated}${suffix}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private clearProgressTicker(): void {
|
private clearProgressTicker(): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user