Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions scripts/diagnostics-viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ class FileViewer(Vertical):
def __init__(self):
super().__init__()
self.current_session = None
self.current_filename = None
self.current_part = None

def compose(self) -> ComposeResult:
"""Create child widgets."""
Expand All @@ -305,6 +307,8 @@ def update_content(self, session: DiagnosticsSession, filename: str, part: str =
part: For JSONL files, either "request" or "responses"
"""
self.current_session = session
self.current_filename = filename
self.current_part = part

content = session.read_file(filename)
if content is None:
Expand Down Expand Up @@ -419,6 +423,7 @@ class SessionViewer(Vertical):

BINDINGS = [
Binding("ctrl+f,cmd+f", "search", "Search", show=True),
Binding("c", "copy_file", "Copy file", show=True),
]

def __init__(self, session: DiagnosticsSession):
Expand Down Expand Up @@ -513,6 +518,47 @@ def action_search(self):
viewer = self.query_one(FileViewer)
viewer.action_search()

def action_copy_file(self):
"""Copy the current file content to clipboard."""
viewer = self.query_one(FileViewer)
if not viewer.current_session or not viewer.current_filename:
self.app.notify("No file selected")
return

content = viewer.current_session.read_file(viewer.current_filename)
if content is None:
self.app.notify("Could not read file")
return

# For JSONL files with a part, extract just that part and pretty-format
if viewer.current_filename.endswith('.jsonl') and viewer.current_part:
lines = [line.strip() for line in content.strip().split('\n') if line.strip()]
if viewer.current_part == "request" and lines:
try:
data = json.loads(lines[0])
content = json.dumps(data, indent=2)
except json.JSONDecodeError:
content = lines[0]
elif viewer.current_part == "responses" and len(lines) > 1:
try:
responses = [json.loads(line) for line in lines[1:]]
if len(responses) == 1:
content = json.dumps(responses[0], indent=2)
else:
content = json.dumps(responses, indent=2)
except json.JSONDecodeError:
Comment on lines +543 to +549
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list comprehension will fail if any response line has invalid JSON, causing the entire operation to fall back to copying raw text. This is inconsistent with _show_jsonl (lines 344-349) which parses responses individually and skips malformed lines. Consider using a similar approach: iterate through lines[1:] with individual try-except blocks to collect only valid responses, matching the viewing behavior.

Suggested change
try:
responses = [json.loads(line) for line in lines[1:]]
if len(responses) == 1:
content = json.dumps(responses[0], indent=2)
else:
content = json.dumps(responses, indent=2)
except json.JSONDecodeError:
responses = []
for line in lines[1:]:
try:
responses.append(json.loads(line))
except json.JSONDecodeError:
# Skip malformed JSON lines to match _show_jsonl behavior
continue
if responses:
if len(responses) == 1:
content = json.dumps(responses[0], indent=2)
else:
content = json.dumps(responses, indent=2)
else:

Copilot uses AI. Check for mistakes.
content = '\n'.join(lines[1:])
# Pretty-format regular JSON files too
elif viewer.current_filename.endswith('.json'):
try:
data = json.loads(content)
content = json.dumps(data, indent=2)
except json.JSONDecodeError:
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Suggested change
except json.JSONDecodeError:
except json.JSONDecodeError:
# If content is not valid JSON, fall back to copying it as-is.

Copilot uses AI. Check for mistakes.
pass

pyperclip.copy(content)
self.app.notify("Copied to clipboard")

def on_key(self, event):
"""Handle left/right navigation between panels."""
if event.key == "left":
Expand Down
Loading