Merge pull request #692 from AutoMaker-Org/feature/bug-summary-not-updated-when-doing-refine-fdo8

fix: Summary not updated when doing Refine
This commit is contained in:
Shirone
2026-01-25 11:29:34 +00:00
committed by GitHub
2 changed files with 56 additions and 59 deletions

View File

@@ -237,39 +237,34 @@ function cleanFragmentedText(content: string): string {
/** /**
* Extracts a summary from completed feature context * Extracts a summary from completed feature context
* Looks for content between <summary> and </summary> tags * Looks for content between <summary> and </summary> tags
* Returns the LAST summary found to ensure we get the most recent/updated one
*/ */
function extractSummary(content: string): string | undefined { function extractSummary(content: string): string | undefined {
// First, clean up any fragmented text from streaming // First, clean up any fragmented text from streaming
const cleanedContent = cleanFragmentedText(content); const cleanedContent = cleanFragmentedText(content);
// Look for <summary> tags - capture everything between opening and closing tags // Define regex patterns to try in order of priority
const summaryTagMatch = cleanedContent.match(/<summary>([\s\S]*?)<\/summary>/i); // Each pattern specifies which capture group contains the summary content
if (summaryTagMatch) { const regexesToTry = [
// Clean up the extracted summary content as well { regex: /<summary>([\s\S]*?)<\/summary>/gi, group: 1 },
return cleanFragmentedText(summaryTagMatch[1]).trim(); { regex: /## Summary[^\n]*\n([\s\S]*?)(?=\n## [^#]|\n🔧|$)/gi, group: 1 },
} {
regex:
/✓ (?:Feature|Verification|Task) (?:successfully|completed|verified)[^\n]*(?:\n[^\n]{1,200})?/gi,
group: 0,
},
{
regex: /(?:What was done|Changes made|Implemented)[^\n]*\n([\s\S]*?)(?=\n## [^#]|\n🔧|$)/gi,
group: 1,
},
];
// Fallback: Look for summary sections - capture everything including subsections (###) for (const { regex, group } of regexesToTry) {
// Stop at same-level ## sections (but not ###), or tool markers, or end const matches = [...cleanedContent.matchAll(regex)];
const summaryMatch = cleanedContent.match(/## Summary[^\n]*\n([\s\S]*?)(?=\n## [^#]|\n🔧|$)/i); if (matches.length > 0) {
if (summaryMatch) { const lastMatch = matches[matches.length - 1];
return cleanFragmentedText(summaryMatch[1]).trim(); return cleanFragmentedText(lastMatch[group]).trim();
} }
// Look for completion markers and extract surrounding text
const completionMatch = cleanedContent.match(
/✓ (?:Feature|Verification|Task) (?:successfully|completed|verified)[^\n]*(?:\n[^\n]{1,200})?/i
);
if (completionMatch) {
return cleanFragmentedText(completionMatch[0]).trim();
}
// Look for "What was done" type sections
const whatWasDoneMatch = cleanedContent.match(
/(?:What was done|Changes made|Implemented)[^\n]*\n([\s\S]*?)(?=\n## [^#]|\n🔧|$)/i
);
if (whatWasDoneMatch) {
return cleanFragmentedText(whatWasDoneMatch[1]).trim();
} }
return undefined; return undefined;

View File

@@ -1198,46 +1198,48 @@ function mergeConsecutiveEntries(entries: LogEntry[]): LogEntry[] {
/** /**
* Extracts summary content from raw log output * Extracts summary content from raw log output
* Returns the summary text if found, or null if no summary exists * Returns the LAST summary text if found, or null if no summary exists
* This ensures we get the most recent/updated summary when multiple exist
*/ */
export function extractSummary(rawOutput: string): string | null { export function extractSummary(rawOutput: string): string | null {
if (!rawOutput || !rawOutput.trim()) { if (!rawOutput || !rawOutput.trim()) {
return null; return null;
} }
// Try to find <summary> tags first (preferred format) // First, clean up any fragmented text from streaming
const summaryTagMatch = rawOutput.match(/<summary>([\s\S]*?)<\/summary>/); // This handles cases where streaming providers send partial text chunks
if (summaryTagMatch) { // that got separated by newlines during accumulation (e.g., "<sum\n\nmary>")
return summaryTagMatch[1].trim(); const cleanedOutput = cleanFragmentedText(rawOutput);
}
// Try to find markdown ## Summary section // Define regex patterns to try in order of priority
const summaryHeaderMatch = rawOutput.match(/^##\s+Summary\s*\n([\s\S]*?)(?=\n##\s+|$)/m); // Each pattern specifies a processor function to extract the summary from the match
if (summaryHeaderMatch) { const regexesToTry: Array<{
return summaryHeaderMatch[1].trim(); regex: RegExp;
} processor: (m: RegExpMatchArray) => string;
}> = [
{ regex: /<summary>([\s\S]*?)<\/summary>/gi, processor: (m) => m[1] },
{ regex: /^##\s+Summary[^\n]*\n([\s\S]*?)(?=\n##\s+[^#]|\n🔧|$)/gm, processor: (m) => m[1] },
{
regex: /^##\s+(Feature|Changes|Implementation)[^\n]*\n([\s\S]*?)(?=\n##\s+[^#]|\n🔧|$)/gm,
processor: (m) => `## ${m[1]}\n${m[2]}`,
},
{
regex: /(^|\n)(All tasks completed[\s\S]*?)(?=\n🔧|\n📋|\n⚡|\n❌|$)/g,
processor: (m) => m[2],
},
{
regex:
/(^|\n)((I've|I have) (successfully |now )?(completed|finished|implemented)[\s\S]*?)(?=\n🔧|\n📋|\n⚡|\n❌|$)/g,
processor: (m) => m[2],
},
];
// Try other summary formats (Feature, Changes, Implementation) for (const { regex, processor } of regexesToTry) {
const otherHeaderMatch = rawOutput.match( const matches = [...cleanedOutput.matchAll(regex)];
/^##\s+(Feature|Changes|Implementation)\s*\n([\s\S]*?)(?=\n##\s+|$)/m if (matches.length > 0) {
); const lastMatch = matches[matches.length - 1];
if (otherHeaderMatch) { return cleanFragmentedText(processor(lastMatch)).trim();
return `## ${otherHeaderMatch[1]}\n${otherHeaderMatch[2].trim()}`; }
}
// Try to find summary introduction lines
const introMatch = rawOutput.match(
/(^|\n)(All tasks completed[\s\S]*?)(?=\n🔧|\n📋|\n⚡|\n❌|$)/
);
if (introMatch) {
return introMatch[2].trim();
}
const completionMatch = rawOutput.match(
/(^|\n)((I've|I have) (successfully |now )?(completed|finished|implemented)[\s\S]*?)(?=\n🔧|\n📋|\n⚡|\n❌|$)/
);
if (completionMatch) {
return completionMatch[2].trim();
} }
return null; return null;