-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Diagnostic files copying #7209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Diagnostic files copying #7209
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -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.""" | ||||||||
|
|
@@ -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: | ||||||||
|
|
@@ -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): | ||||||||
|
|
@@ -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: | ||||||||
| 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: | ||||||||
|
||||||||
| except json.JSONDecodeError: | |
| except json.JSONDecodeError: | |
| # If content is not valid JSON, fall back to copying it as-is. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.