mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-05-11 15:31:50 +00:00
fix(claude): preserve local command artifacts in session history
Claude writes slash-command metadata, local stdout, and compaction summaries into the same JSONL stream as normal chat messages. The existing normalization path treated those rows as internal content and dropped them entirely. That made the web UI diverge from the CLI transcript and removed important context. Commands like /compact appeared to have never happened, the stdout status line disappeared, and the continuation summary after compaction was filtered out even though it best describes the post-boundary session state. This change keeps the distinction between truly internal transcript rows and user-visible local command artifacts. Command wrapper tags are parsed into structured metadata without exposing the raw tags, local command stdout is remapped to assistant text, and compact summaries are preserved as assistant-authored content instead of being mislabeled as user input. Search and session-summary parsing are updated for the same reason. If history normalization preserved these rows but search still ignored them, rendered conversation state and searchable conversation state would continue to disagree, and session summaries would fall back to stale user text instead of Claude's actual compaction summary. The shared message and store typings are extended so this metadata survives the full backend-to-frontend pipeline. That avoids reconstructing meaning later and keeps the transcript faithful to Claude's persisted history while still hiding genuinely internal control content.
This commit is contained in:
@@ -11,8 +11,9 @@ import { decodeHtmlEntities, unescapeWithMathProtection, formatUsageLimitText }
|
||||
* Convert NormalizedMessage[] from the session store into ChatMessage[]
|
||||
* that the existing UI components expect.
|
||||
*
|
||||
* Internal/system content (e.g. <system-reminder>, <command-name>) is already
|
||||
* filtered server-side by the Claude provider module.
|
||||
* Truly internal/system content is already filtered server-side. Some Claude
|
||||
* transcript artifacts such as local slash commands and compact summaries are
|
||||
* intentionally preserved and annotated so they can render like normal chat.
|
||||
*/
|
||||
export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMessage[] {
|
||||
const converted: ChatMessage[] = [];
|
||||
@@ -26,6 +27,16 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
||||
}
|
||||
|
||||
for (const msg of messages) {
|
||||
const sharedMetadata = {
|
||||
displayText: msg.displayText,
|
||||
commandName: msg.commandName,
|
||||
commandMessage: msg.commandMessage,
|
||||
commandArgs: msg.commandArgs,
|
||||
isLocalCommand: msg.isLocalCommand,
|
||||
isLocalCommandStdout: msg.isLocalCommandStdout,
|
||||
isCompactSummary: msg.isCompactSummary,
|
||||
};
|
||||
|
||||
switch (msg.kind) {
|
||||
case 'text': {
|
||||
const content = msg.content || '';
|
||||
@@ -42,12 +53,14 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
||||
timestamp: msg.timestamp,
|
||||
isTaskNotification: true,
|
||||
taskStatus: taskNotifMatch[1]?.trim() || 'completed',
|
||||
...sharedMetadata,
|
||||
});
|
||||
} else {
|
||||
converted.push({
|
||||
type: 'user',
|
||||
content: unescapeWithMathProtection(decodeHtmlEntities(content)),
|
||||
timestamp: msg.timestamp,
|
||||
...sharedMetadata,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@@ -58,6 +71,7 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
||||
type: 'assistant',
|
||||
content: text,
|
||||
timestamp: msg.timestamp,
|
||||
...sharedMetadata,
|
||||
});
|
||||
}
|
||||
break;
|
||||
@@ -106,6 +120,7 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
||||
isComplete: Boolean(toolResult),
|
||||
}
|
||||
: undefined,
|
||||
...sharedMetadata,
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -117,6 +132,7 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
||||
content: unescapeWithMathProtection(msg.content),
|
||||
timestamp: msg.timestamp,
|
||||
isThinking: true,
|
||||
...sharedMetadata,
|
||||
});
|
||||
}
|
||||
break;
|
||||
@@ -126,6 +142,7 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
||||
type: 'error',
|
||||
content: msg.content || 'Unknown error',
|
||||
timestamp: msg.timestamp,
|
||||
...sharedMetadata,
|
||||
});
|
||||
break;
|
||||
|
||||
@@ -135,6 +152,7 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
||||
content: msg.content || '',
|
||||
timestamp: msg.timestamp,
|
||||
isInteractivePrompt: true,
|
||||
...sharedMetadata,
|
||||
});
|
||||
break;
|
||||
|
||||
@@ -145,6 +163,7 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
||||
timestamp: msg.timestamp,
|
||||
isTaskNotification: true,
|
||||
taskStatus: msg.status || 'completed',
|
||||
...sharedMetadata,
|
||||
});
|
||||
break;
|
||||
|
||||
@@ -155,6 +174,7 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
||||
content: msg.content,
|
||||
timestamp: msg.timestamp,
|
||||
isStreaming: true,
|
||||
...sharedMetadata,
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -28,6 +28,7 @@ export interface SubagentChildTool {
|
||||
export interface ChatMessage {
|
||||
type: string;
|
||||
content?: string;
|
||||
displayText?: string;
|
||||
timestamp: string | number | Date;
|
||||
images?: ChatImage[];
|
||||
reasoning?: string;
|
||||
@@ -40,6 +41,12 @@ export interface ChatMessage {
|
||||
toolResult?: ToolResult | null;
|
||||
toolId?: string;
|
||||
toolCallId?: string;
|
||||
commandName?: string;
|
||||
commandMessage?: string;
|
||||
commandArgs?: string;
|
||||
isLocalCommand?: boolean;
|
||||
isLocalCommandStdout?: boolean;
|
||||
isCompactSummary?: boolean;
|
||||
isSubagentContainer?: boolean;
|
||||
subagentState?: {
|
||||
childTools: SubagentChildTool[];
|
||||
|
||||
@@ -40,6 +40,20 @@ export interface NormalizedMessage {
|
||||
// kind-specific fields (flat for simplicity)
|
||||
role?: 'user' | 'assistant';
|
||||
content?: string;
|
||||
/**
|
||||
* Mirrors optional transcript metadata from the server.
|
||||
*
|
||||
* These fields are currently used by Claude history normalization so local
|
||||
* slash commands, local stdout, and compact summaries do not disappear when
|
||||
* the session store hydrates from REST history.
|
||||
*/
|
||||
displayText?: string;
|
||||
commandName?: string;
|
||||
commandMessage?: string;
|
||||
commandArgs?: string;
|
||||
isLocalCommand?: boolean;
|
||||
isLocalCommandStdout?: boolean;
|
||||
isCompactSummary?: boolean;
|
||||
images?: string[];
|
||||
toolName?: string;
|
||||
toolInput?: unknown;
|
||||
|
||||
Reference in New Issue
Block a user