Add color and improve rendering in chat_sessions.py tool#233
Add color and improve rendering in chat_sessions.py tool#233gvanrossum wants to merge 15 commits intomicrosoft:mainfrom
Conversation
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)
bmerkle
left a comment
There was a problem hiding this comment.
@gvanrossum here is a first review.
currently the tools in Unix only unfortunately
tools/chat_sessions.py
Outdated
| from collections.abc import Iterator | ||
| import contextlib | ||
| import datetime | ||
| import fcntl |
There was a problem hiding this comment.
I am also testing on Windows and currently chat_session.py is Unix only unfortunately.
import fcntl, import termios are Unix-only modules
tools/chat_sessions.py
Outdated
| import subprocess | ||
| import sys | ||
| import textwrap | ||
| import termios |
There was a problem hiding this comment.
I am also testing on Windows and currently chat_session.py is Unix only unfortunately.
import fcntl, import termios are Unix-only modules
tools/chat_sessions.py
Outdated
| from typing import Any | ||
|
|
||
| from colorama import Fore, init, Style | ||
| import re |
There was a problem hiding this comment.
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 | ||
|
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
pads gaps with None, which means raw_requests can contain None entries
tools/chat_sessions.py
Outdated
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
only searches user and assistant text, skipping thinking and tool call content.
May be intentional but worth noting
tools/chat_sessions.py
Outdated
There was a problem hiding this comment.
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,
)
tools/chat_sessions.py
Outdated
| 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))) |
There was a problem hiding this comment.
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.
|
Thanks Bernhard! I will get the agent working on this. |
… more (which doesn't understand ANSI escapes)
|
@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!) |
@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.)