fix: support flat .txt transcripts on Windows (Cursor >= 0.47)#1
fix: support flat .txt transcripts on Windows (Cursor >= 0.47)#1bertheto wants to merge 2 commits intoofershap:mainfrom
Conversation
On Windows with recent versions of Cursor, agent transcripts are stored as plain-text .txt files directly inside agent-transcripts/ rather than the <uuid>/<uuid>.jsonl sub-directory structure used on Linux/Mac. Changes: - cursorWatcher.ts: scanAll() now detects both formats: - Format A (existing): sub-directory with <uuid>/<uuid>.jsonl - Format B (new): flat <uuid>.txt file at root of agent-transcripts/ watchFile() and readNewContent() accept an isFlatTxt flag so each format uses the appropriate parser. - transcriptParser.ts: adds parseFlatTxtChunk(chunk) which parses the plain-text block format (user: / assistant: / [Tool call] / [Thinking] sections) and maps tool names to activity types (Read->reading, Shell->running, StrReplace->editing, Task->phoning).
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a compatibility issue where the agent activity watcher failed to process transcripts generated by recent versions of Cursor on Windows. The changes introduce support for a new flat .txt transcript format, ensuring that the system can now correctly monitor and react to agent activities across different operating systems and Cursor versions. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for flat .txt agent transcripts, which is a great improvement for Windows users on recent Cursor versions. The changes look solid, introducing new logic to handle both the existing .jsonl format and the new .txt format. I've identified a few areas for improvement to enhance code quality and maintainability. Specifically, I've suggested refactoring to reduce code duplication in cursorWatcher.ts, improving the file scanning logic to be more efficient, and making the new parsing logic in transcriptParser.ts more readable. Overall, great work on identifying and fixing this platform-specific issue.
| if (entry.isDirectory()) { | ||
| const jsonlPath = path.join(this.transcriptsDir, entry.name, entry.name + '.jsonl'); | ||
| if (fs.existsSync(jsonlPath) && !this.filePositions.has(jsonlPath)) { | ||
| this.log.appendLine(`[scan] New JSONL transcript: ${entry.name}`); | ||
| this.watchFile(jsonlPath); | ||
| } | ||
| if (this.filePositions.has(jsonlPath)) { | ||
| this.readNewContent(jsonlPath); | ||
| } | ||
| continue; |
There was a problem hiding this comment.
The logic for handling existing JSONL transcripts (Format A) can be improved to avoid a redundant call to readNewContent for new files and to align with the more robust if/else structure you've used for new TXT transcripts (Format B). This change will prevent readNewContent from being called twice when a new transcript is detected.
| if (entry.isDirectory()) { | |
| const jsonlPath = path.join(this.transcriptsDir, entry.name, entry.name + '.jsonl'); | |
| if (fs.existsSync(jsonlPath) && !this.filePositions.has(jsonlPath)) { | |
| this.log.appendLine(`[scan] New JSONL transcript: ${entry.name}`); | |
| this.watchFile(jsonlPath); | |
| } | |
| if (this.filePositions.has(jsonlPath)) { | |
| this.readNewContent(jsonlPath); | |
| } | |
| continue; | |
| if (entry.isDirectory()) { | |
| const jsonlPath = path.join(this.transcriptsDir, entry.name, entry.name + '.jsonl'); | |
| if (fs.existsSync(jsonlPath)) { | |
| if (!this.filePositions.has(jsonlPath)) { | |
| this.log.appendLine(`[scan] New JSONL transcript: ${entry.name}`); | |
| this.watchFile(jsonlPath); | |
| } else { | |
| this.readNewContent(jsonlPath); | |
| } | |
| } | |
| continue; | |
| } |
| if (isFlatTxt) { | ||
| const status = parseFlatTxtChunk(text); | ||
| if (status) { | ||
| this.log.appendLine(`[activity] ${status.activity}: ${status.statusText}`); | ||
| this.onStatusChange(status); | ||
| if (status.activity !== 'idle') { | ||
| this.resetIdleTimer(); | ||
| } | ||
| } | ||
| } else { | ||
| const lines = text.split('\n').filter(l => l.trim()); | ||
| for (const line of lines) { | ||
| const status = parseTranscriptLine(line); | ||
| if (status) { | ||
| this.log.appendLine(`[activity] ${status.activity}: ${status.statusText}`); | ||
| this.onStatusChange(status); | ||
| if (status.activity !== 'idle') { | ||
| this.resetIdleTimer(); | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
There's significant code duplication in how the parsed status is handled for both flat text and JSONL files. To improve maintainability and reduce redundancy, you can extract the status processing logic into a private helper method, for example processStatus(status: ParsedStatus | null).
private processStatus(status: ParsedStatus | null) {
if (!status) return;
this.log.appendLine(`[activity] ${status.activity}: ${status.statusText}`);
this.onStatusChange(status);
if (status.activity !== 'idle') {
this.resetIdleTimer();
}
}Then you can simplify this block.
if (isFlatTxt) {
this.processStatus(parseFlatTxtChunk(text));
} else {
const lines = text.split('\n').filter(l => l.trim());
for (const line of lines) {
this.processStatus(parseTranscriptLine(line));
}
}
src/transcriptParser.ts
Outdated
| const tool = toolCallMatch[1]!.toLowerCase(); | ||
| if (/^(read|glob|grep|semanticsearch)$/.test(tool)) { | ||
| return { activity: 'reading', statusText: 'Working...' }; | ||
| } | ||
| if (/^(shell|bash)$/.test(tool)) { | ||
| return { activity: 'running', statusText: 'Working...' }; | ||
| } | ||
| if (/^(strreplace|write|editnotebook|delete)$/.test(tool)) { | ||
| return { activity: 'editing', statusText: 'Working...' }; | ||
| } | ||
| if (/^(task)$/.test(tool)) { | ||
| return { activity: 'phoning', statusText: 'Delegating...' }; | ||
| } | ||
| return { activity: 'typing', statusText: 'Working...' }; |
There was a problem hiding this comment.
Using a series of if statements with regular expressions for exact string matching can be less efficient and harder to read than a simple switch statement. Refactoring this to a switch on the tool variable would make the code cleaner and more performant.
| const tool = toolCallMatch[1]!.toLowerCase(); | |
| if (/^(read|glob|grep|semanticsearch)$/.test(tool)) { | |
| return { activity: 'reading', statusText: 'Working...' }; | |
| } | |
| if (/^(shell|bash)$/.test(tool)) { | |
| return { activity: 'running', statusText: 'Working...' }; | |
| } | |
| if (/^(strreplace|write|editnotebook|delete)$/.test(tool)) { | |
| return { activity: 'editing', statusText: 'Working...' }; | |
| } | |
| if (/^(task)$/.test(tool)) { | |
| return { activity: 'phoning', statusText: 'Delegating...' }; | |
| } | |
| return { activity: 'typing', statusText: 'Working...' }; | |
| const tool = toolCallMatch[1]!.toLowerCase(); | |
| switch (tool) { | |
| case 'read': | |
| case 'glob': | |
| case 'grep': | |
| case 'semanticsearch': | |
| return { activity: 'reading', statusText: 'Working...' }; | |
| case 'shell': | |
| case 'bash': | |
| return { activity: 'running', statusText: 'Working...' }; | |
| case 'strreplace': | |
| case 'write': | |
| case 'editnotebook': | |
| case 'delete': | |
| return { activity: 'editing', statusText: 'Working...' }; | |
| case 'task': | |
| return { activity: 'phoning', statusText: 'Delegating...' }; | |
| default: | |
| return { activity: 'typing', statusText: 'Working...' }; | |
| } |
- cursorWatcher.ts: fix double readNewContent call in Format A (JSONL) by using if/else instead of two separate if blocks - cursorWatcher.ts: extract processStatus() helper to eliminate duplicated status-handling logic in readNewContent() - transcriptParser.ts: replace regex if-chain with switch statement for tool-to-activity mapping in parseFlatTxtChunk()
|
Thanks for the review @gemini-code-assist! All three suggestions have been addressed in 3f5f83f:
|
|
Thanks for the update, @bertheto! I've reviewed the changes in
Great work on these improvements! |
Problem
On Windows with recent versions of Cursor (>= 0.47), agent transcripts are stored as plain-text
.txtfiles placed directly insideagent-transcripts/:The existing
scanAll()only handles the<uuid>/<uuid>.jsonlsub-directory format used on Linux/Mac, so the watcher finds the transcripts directory correctly but silently skips all.txtfiles — the office character never reacts to agent activity.Reproduction
[start] Watching: ...agent-transcriptsis logged but no[scan]or[activity]entries followSolution
cursorWatcher.tsscanAll()now handles both formats:<uuid>/sub-directory containing<uuid>.jsonl<uuid>.txtfile at the root ofagent-transcripts/watchFile()andreadNewContent()receive anisFlatTxtflag to route each file to the correct parser.transcriptParser.tsNew
parseFlatTxtChunk(chunk)function parses the plain-text block format:Tool names are mapped directly to activity types:
Read,Glob,Grep,SemanticSearch->readingShell->runningStrReplace,Write,EditNotebook,Delete->editingTask->phoning(subagent delegation)typing[Thinking]blocks and plain assistant text fall back to the existinginferActivityFromText()heuristics.Testing
Tested on Windows 10 (22H2) with Cursor 0.47. After reload, the office character correctly reacts to agent tool calls in real time.