mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-03 05:59:43 +02:00
fix(web): show the whole last turn in the Claude response viewer's brief view
The eye button rendered `data.text`, which is one row: the last assistant
row of the transcript. A Claude answer is a median of 3 model messages
(p90 11) split around tool calls, so the brief view usually showed the tail
of an answer ("Done.", "Let me look.") and the substance appeared only after
More. The full view was fine, which is why the brief one read as broken by
comparison.
The brief view now asks `?context=turn`. The reader answers with the
assistant messages of the last ANSWERED turn (`selectLastAnsweredTurn`: the
highest `turn` that has an assistant row, so a prompt queued after the
answer does not blank the view) and the frontend renders them exactly as
the full view renders that turn: one badge, then continuation segments,
gated on the numeric `turn` as before.
`data.text` is unchanged in every context — still the last assistant row,
never `messages.at(-1)` — because agent pollers hash it. Readers that emit
no turns (Codex, the pane parser, DeepSeek, an older server) return `text`
only for `context=turn`, and the brief view keeps its single card for them.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01McLWqCWBuQYGuPMScb4Aou
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
5b667264b4
commit
bd61735393
+25
-3
@@ -2325,10 +2325,19 @@ class CodemanApp {
|
||||
|
||||
if (!this.activeSessionId) return;
|
||||
try {
|
||||
// Source 1: Transcript JSONL (best quality — clean structured text from Claude)
|
||||
const res = await fetch(`/api/sessions/${this.activeSessionId}/last-response`);
|
||||
// Source 1: Transcript JSONL (best quality — clean structured text from Claude).
|
||||
// `context=turn` asks for the last ANSWERED turn as messages: a Claude
|
||||
// answer is a median of 3 model messages (p90 11), and `text` alone is
|
||||
// only the final one — usually a "Done." tail with the substance in the
|
||||
// rows before it. Readers that know no `turn` context (Codex, the pane
|
||||
// parser, an older server) answer with `text` only, and that path is
|
||||
// unchanged below.
|
||||
const res = await fetch(`/api/sessions/${this.activeSessionId}/last-response?context=turn`);
|
||||
const data = (await res.json())?.data ?? {};
|
||||
let lastResponse = data.text || '';
|
||||
const turnMessages = (Array.isArray(data.messages) ? data.messages : []).filter(
|
||||
(msg) => msg && msg.role === 'assistant' && typeof msg.text === 'string' && msg.text.trim()
|
||||
);
|
||||
|
||||
// Source 2: Terminal buffer fallback — strip ANSI, drop Claude CLI chrome.
|
||||
// Claude + shell only: _cleanTerminalBuffer knows Claude CLI's output, and
|
||||
@@ -2345,7 +2354,20 @@ class CodemanApp {
|
||||
}
|
||||
|
||||
const body = document.getElementById('responseViewerBody');
|
||||
if (lastResponse) {
|
||||
if (turnMessages.length > 0) {
|
||||
// The whole last turn, rendered exactly as the full view renders that
|
||||
// turn: one badge, then badge-less continuation segments. The same
|
||||
// numeric-`turn` gate as loadFullContext, never same-role adjacency.
|
||||
const agentLabel = this._getResponseViewerAgentLabel();
|
||||
body.innerHTML = '';
|
||||
let previous = null;
|
||||
for (const msg of turnMessages) {
|
||||
const continuation = !!previous && typeof msg.turn === 'number' && previous.turn === msg.turn;
|
||||
body.appendChild(this._buildResponseViewerMessage(msg.text, 'assistant', agentLabel, { ...msg, continuation }));
|
||||
previous = msg;
|
||||
}
|
||||
this._bindResponseViewerInteractions(body);
|
||||
} else if (lastResponse) {
|
||||
// Keep the brief view inside the same message wrapper as the full
|
||||
// conversation view. The wrapper supplies the card, role badge and
|
||||
// descendant markdown styles that direct body children do not get.
|
||||
|
||||
@@ -359,3 +359,30 @@ export function getLastTranscriptResponse(blocks: ResponseViewerTranscriptBlock[
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* The messages of the most recent turn that has an answer: every assistant
|
||||
* message whose `turn` matches the highest turn any assistant message carries.
|
||||
*
|
||||
* This is what the viewer's brief ("Last Response") view renders for Claude.
|
||||
* The brief `text` is one row — the last assistant row — and a Claude turn is
|
||||
* a median of 3 rows (p90 11), so that row alone was usually the tail of the
|
||||
* answer ("Done.") with the substance in the rows before it. Reading the whole
|
||||
* turn gives the same cards the full view shows for it, and no more.
|
||||
*
|
||||
* Deliberately NOT "everything after the last user message": a prompt queued
|
||||
* while the agent works opens a new, still-unanswered turn, and the honest
|
||||
* brief view is then the previous, answered one — exactly the row `text`
|
||||
* already points at. Messages without a numeric `turn` (Codex, the pane
|
||||
* parser, an older reader) yield an empty list so callers fall back to `text`.
|
||||
*/
|
||||
export function selectLastAnsweredTurn<T extends { role: string; turn?: number }>(messages: T[]): T[] {
|
||||
let latest = -1;
|
||||
for (const message of messages) {
|
||||
if (message.role === 'assistant' && typeof message.turn === 'number' && message.turn > latest) {
|
||||
latest = message.turn;
|
||||
}
|
||||
}
|
||||
if (latest < 0) return [];
|
||||
return messages.filter((message) => message.role === 'assistant' && message.turn === latest);
|
||||
}
|
||||
|
||||
@@ -153,6 +153,7 @@ import {
|
||||
getLastTranscriptResponse,
|
||||
isExternalCliTranscriptMode,
|
||||
parseExternalCliTranscript,
|
||||
selectLastAnsweredTurn,
|
||||
} from '../response-viewer-transcript.js';
|
||||
import { readDeepSeekLastResponse } from '../../deepseek-transcript.js';
|
||||
|
||||
@@ -2214,10 +2215,14 @@ export function registerSessionRoutes(
|
||||
}
|
||||
|
||||
const query = req.query as { context?: string };
|
||||
// `turn` is the brief view's context: the last ANSWERED turn's assistant
|
||||
// messages, so a multi-row answer is not reduced to its final row. `text`
|
||||
// stays the last assistant row in every mode (agent pollers hash it).
|
||||
const wantsMessages = query.context === 'full' || query.context === 'turn';
|
||||
const claudeSessionId = session.claudeSessionId || session.id;
|
||||
const transcript = await findClaudeTranscript(projectsDir, claudeSessionId, session.id);
|
||||
if (!transcript) {
|
||||
return query.context === 'full' ? { text: '', timestamp: '', messages: [] } : { text: '', timestamp: '' };
|
||||
return wantsMessages ? { text: '', timestamp: '', messages: [] } : { text: '', timestamp: '' };
|
||||
}
|
||||
|
||||
if (transcript.sessionId !== session.claudeSessionId && transcript.sessionId !== session.id) {
|
||||
@@ -2233,9 +2238,17 @@ export function registerSessionRoutes(
|
||||
|
||||
try {
|
||||
const content = await fs.readFile(transcript.path, 'utf8');
|
||||
return parseClaudeResponseTranscript(content, query.context === 'full');
|
||||
const parsed = parseClaudeResponseTranscript(content, wantsMessages);
|
||||
if (query.context === 'turn') {
|
||||
return {
|
||||
text: parsed.text,
|
||||
timestamp: parsed.timestamp,
|
||||
messages: selectLastAnsweredTurn(parsed.messages ?? []),
|
||||
};
|
||||
}
|
||||
return parsed;
|
||||
} catch {
|
||||
return query.context === 'full' ? { text: '', timestamp: '', messages: [] } : { text: '', timestamp: '' };
|
||||
return wantsMessages ? { text: '', timestamp: '', messages: [] } : { text: '', timestamp: '' };
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user