Skip to content

Add color and improve rendering in chat_sessions.py tool#233

Open
gvanrossum wants to merge 15 commits intomicrosoft:mainfrom
gvanrossum:chats
Open

Add color and improve rendering in chat_sessions.py tool#233
gvanrossum wants to merge 15 commits intomicrosoft:mainfrom
gvanrossum:chats

Conversation

@gvanrossum
Copy link
Copy Markdown
Collaborator

@bmerkle could you review this too? This is really an independent little tool, but super handy -- it can show you all your AI chats used from VS Code. (I suspect it wouldn't be too hard to be able to point it to other frameworks' logs as well.)

gvanrossum and others added 8 commits April 9, 2026 19:47
We now look in:
- VSCode Server environments (.vscode-server/data/User)
- Platform-native installations (.config/Code/User, AppData/Roaming/Code/User, etc.)
- Windows installations via WSL mounts (/mnt/c/Users/.../AppData)

We support two locations and formats for chat sessions:
- chatSessions (old)
- GitHub.copilot-chat (new)
Copy link
Copy Markdown
Collaborator

@bmerkle bmerkle left a comment

Choose a reason for hiding this comment

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

@gvanrossum here is a first review.
currently the tools in Unix only unfortunately

from collections.abc import Iterator
import contextlib
import datetime
import fcntl
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am also testing on Windows and currently chat_session.py is Unix only unfortunately.

import fcntl, import termios are Unix-only modules

import subprocess
import sys
import textwrap
import termios
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am also testing on Windows and currently chat_session.py is Unix only unfortunately.

import fcntl, import termios are Unix-only modules

from typing import Any

from colorama import Fore, init, Style
import re
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

re (stdlib) is imported at chat_sessions.py:33 after the third-party colorama import. It should be grouped with the other stdlib imports above.


from colorama import Fore, init, Style
import re

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

VSCODE_USER_DIR is initialized at module level to the macOS path (line 35), then conditionally overridden in main() (line 671). If any function (e.g. load_all_sessions()) is called outside of main(), it silently uses the wrong path. Consider computing it once based on sys.platform at module level, or passing it as a parameter.

def _splice(target: list[Any], index: int, items: list[Any]) -> None:
"""Splice items into target at index, extending if needed."""
while len(target) < index:
target.append(None)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

pads gaps with None, which means raw_requests can contain None entries

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is catching all Exceptions a good idea ? e.g. JSON errors vs. other Errors like OSError



def search_sessions(sessions: list[SessionInfo], query: str) -> None:
def search_sessions(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

only searches user and assistant text, skipping thinking and tool call content.
May be intentional but worth noting

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Shell=True with a string is a shell injection vector — but the practical risk here is low, because everything is currently in our own control.

maybe prefer shell=False and

import shlex

proc = subprocess.Popen(
shlex.split(pager_cmd),
stdin=subprocess.PIPE,
encoding="utf-8",
errors="replace",
env=env,
)

end = min(len(text), end + (half_avail - idx))
elif end == len(text) and start > 0:
start = max(
0, start - (half_avail - (len(text) - idx - len(query)))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Snippet budget redistribution can go negative. If idx is very large and the match is near the end, the expression half_avail - (len(text) - idx - len(query)) at line 557 can produce a negative value, making start overshoot backward. max(0, ...) guards against going below zero, but the intent is muddled.
A simpler approach: compute start and end once, then expand whichever side has room.

@bmerkle bmerkle self-assigned this Apr 11, 2026
@gvanrossum
Copy link
Copy Markdown
Collaborator Author

Thanks Bernhard! I will get the agent working on this.

@gvanrossum
Copy link
Copy Markdown
Collaborator Author

@bmerkle -- please re-review. I have done some more development and addressed all your concerns (plus some of my own).

It was an interesting journey -- e.g. I discovered that Windows 'more' doesn't understand ANSI escapes and counts them as regular characters, and that totally messes up, notably on narrower terminal windows. (Claude was no help here!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants