MCPcopy Create free account
hub / github.com/Noumena-Network/code / extractReviewFromLog

Function extractReviewFromLog

src/tasks/RemoteAgentTask/RemoteAgentTask.tsx:257–286  ·  view source on GitHub ↗

* Extract review content from the remote session log. * * Two producers, two event shapes: * - bughunter mode: run_hunt.sh is a SessionStart hook; its echo lands as * {type:'system', subtype:'hook_progress', stdout:'...'}. NCode never * takes a turn so there are zero assistant messages. *

(log: SDKMessage[])

Source from the content-addressed store, hash-verified

255 * appears once at the end of the run so reverse iteration short-circuits.
256 */
257function extractReviewFromLog(log: SDKMessage[]): string | null {
258 for (let i = log.length - 1; i >= 0; i--) {
259 const msg = log[i];
260 // The final echo before hook exit may land in either the last
261 // hook_progress or the terminal hook_response depending on buffering;
262 // both have flat stdout.
263 if (msg?.type === 'system' && (msg.subtype === 'hook_progress' || msg.subtype === 'hook_response')) {
264 const tagged = extractTag(msg.stdout, REMOTE_REVIEW_TAG);
265 if (tagged?.trim()) return tagged.trim();
266 }
267 }
268 for (let i = log.length - 1; i >= 0; i--) {
269 const msg = log[i];
270 if (msg?.type !== 'assistant') continue;
271 const fullText = extractTextContent(msg.message.content, '\n');
272 const tagged = extractTag(fullText, REMOTE_REVIEW_TAG);
273 if (tagged?.trim()) return tagged.trim();
274 }
275
276 // Hook-stdout concat fallback: a single echo should land in one event, but
277 // large JSON payloads can flush across two if the pipe buffer fills
278 // mid-write. Per-message scan above misses a tag split across events.
279 const hookStdout = log.filter(msg => msg.type === 'system' && (msg.subtype === 'hook_progress' || msg.subtype === 'hook_response')).map(msg => msg.stdout).join('');
280 const hookTagged = extractTag(hookStdout, REMOTE_REVIEW_TAG);
281 if (hookTagged?.trim()) return hookTagged.trim();
282
283 // Fallback: concatenate all assistant text in chronological order.
284 const allText = log.filter((msg): msg is SDKAssistantMessage => msg.type === 'assistant').map(msg => extractTextContent(msg.message.content, '\n')).join('\n').trim();
285 return allText || null;
286}
287
288/**
289 * Tag-only variant of extractReviewFromLog for delta scanning.

Callers 1

pollFunction · 0.85

Calls 2

extractTagFunction · 0.85
extractTextContentFunction · 0.85

Tested by

no test coverage detected