feat(server): add conversation mtime tracking for real-time updates
Add conversation_mtime_ns field to session state that tracks the actual
modification time of conversation files. This enables more responsive
dashboard updates by detecting changes that occur between hook events
(e.g., during streaming tool execution).
Changes:
- state.py: Add _get_conversation_mtime() to stat conversation files
and include mtime_ns in session payloads when available
- conversation.py: Add stable message IDs (claude-{session}-{n} format)
for React key stability and message deduplication
- control.py: Fix FIFO eviction for dismissed_codex_ids - set.pop()
removes arbitrary element, now uses dict with insertion-order iteration
- context.py: Update dismissed_codex_ids type from set to dict
The mtime approach complements existing last_event_at tracking:
- last_event_at: Changes on hook events (session boundaries)
- conversation_mtime_ns: Changes on every file write (real-time)
Dashboard can now detect mid-session conversation updates without
waiting for the next hook event.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,7 @@ class ConversationMixin:
|
||||
def _parse_claude_conversation(self, session_id, project_dir):
|
||||
"""Parse Claude Code JSONL conversation format."""
|
||||
messages = []
|
||||
msg_id = 0
|
||||
|
||||
conv_file = self._get_claude_conversation_file(session_id, project_dir)
|
||||
|
||||
@@ -58,10 +59,12 @@ class ConversationMixin:
|
||||
# Only include actual human messages (strings), not tool results (arrays)
|
||||
if content and isinstance(content, str):
|
||||
messages.append({
|
||||
"id": f"claude-{session_id[:8]}-{msg_id}",
|
||||
"role": "user",
|
||||
"content": content,
|
||||
"timestamp": entry.get("timestamp", ""),
|
||||
})
|
||||
msg_id += 1
|
||||
|
||||
elif msg_type == "assistant":
|
||||
# Assistant messages have structured content
|
||||
@@ -90,6 +93,7 @@ class ConversationMixin:
|
||||
text_parts.append(part)
|
||||
if text_parts or tool_calls or thinking_parts:
|
||||
msg = {
|
||||
"id": f"claude-{session_id[:8]}-{msg_id}",
|
||||
"role": "assistant",
|
||||
"content": "\n".join(text_parts) if text_parts else "",
|
||||
"timestamp": entry.get("timestamp", ""),
|
||||
@@ -99,6 +103,7 @@ class ConversationMixin:
|
||||
if thinking_parts:
|
||||
msg["thinking"] = "\n\n".join(thinking_parts)
|
||||
messages.append(msg)
|
||||
msg_id += 1
|
||||
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
@@ -117,6 +122,7 @@ class ConversationMixin:
|
||||
"""
|
||||
messages = []
|
||||
pending_tool_calls = [] # Accumulate tool calls to attach to next assistant message
|
||||
msg_id = 0
|
||||
|
||||
conv_file = self._find_codex_transcript_file(session_id)
|
||||
|
||||
@@ -161,19 +167,23 @@ class ConversationMixin:
|
||||
# Flush any pending tool calls first
|
||||
if pending_tool_calls:
|
||||
messages.append({
|
||||
"id": f"codex-{session_id[:8]}-{msg_id}",
|
||||
"role": "assistant",
|
||||
"content": "",
|
||||
"tool_calls": pending_tool_calls,
|
||||
"timestamp": timestamp,
|
||||
})
|
||||
msg_id += 1
|
||||
pending_tool_calls = []
|
||||
# Add thinking as assistant message
|
||||
messages.append({
|
||||
"id": f"codex-{session_id[:8]}-{msg_id}",
|
||||
"role": "assistant",
|
||||
"content": "",
|
||||
"thinking": "\n".join(thinking_text),
|
||||
"timestamp": timestamp,
|
||||
})
|
||||
msg_id += 1
|
||||
continue
|
||||
|
||||
# Handle message (user/assistant text)
|
||||
@@ -208,19 +218,24 @@ class ConversationMixin:
|
||||
# Flush any pending tool calls before user message
|
||||
if pending_tool_calls:
|
||||
messages.append({
|
||||
"id": f"codex-{session_id[:8]}-{msg_id}",
|
||||
"role": "assistant",
|
||||
"content": "",
|
||||
"tool_calls": pending_tool_calls,
|
||||
"timestamp": timestamp,
|
||||
})
|
||||
msg_id += 1
|
||||
pending_tool_calls = []
|
||||
messages.append({
|
||||
"id": f"codex-{session_id[:8]}-{msg_id}",
|
||||
"role": "user",
|
||||
"content": "\n".join(text_parts),
|
||||
"timestamp": timestamp,
|
||||
})
|
||||
msg_id += 1
|
||||
elif role == "assistant":
|
||||
msg = {
|
||||
"id": f"codex-{session_id[:8]}-{msg_id}",
|
||||
"role": "assistant",
|
||||
"content": "\n".join(text_parts) if text_parts else "",
|
||||
"timestamp": timestamp,
|
||||
@@ -231,6 +246,7 @@ class ConversationMixin:
|
||||
pending_tool_calls = []
|
||||
if text_parts or msg.get("tool_calls"):
|
||||
messages.append(msg)
|
||||
msg_id += 1
|
||||
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
@@ -238,6 +254,7 @@ class ConversationMixin:
|
||||
# Flush any remaining pending tool calls
|
||||
if pending_tool_calls:
|
||||
messages.append({
|
||||
"id": f"codex-{session_id[:8]}-{msg_id}",
|
||||
"role": "assistant",
|
||||
"content": "",
|
||||
"tool_calls": pending_tool_calls,
|
||||
|
||||
Reference in New Issue
Block a user