Skip to content

fix: paste detection and UI overflow issues - #4

Merged
MartianGreed merged 2 commits into
mainfrom
push-rtostttwsxmo
Jan 26, 2026
Merged

MartianGreed merged 2 commits into
mainfrom
push-rtostttwsxmo

Conversation

@MartianGreed

Copy link
Copy Markdown
Owner

Summary

  • Send double Enter to signal paste completion to Claude Code (fixes prompt not submitting)
  • Fix mainHeight calculation to prevent UI extending beyond screen boundaries
  • Improve thinking state detection with additional patterns
  • Add global usage overlay (press u key)
  • Persist Claude session ID for usage tracking across restarts

Test plan

  • make build passes
  • make test passes
  • make lint passes
  • Manual test: verify prompts submit correctly via ccmanager
  • Manual test: verify UI fits within terminal bounds

@greptile-apps

greptile-apps Bot commented Jan 22, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes paste detection and UI overflow issues in the ccmanager TUI. Changes include sending double Enter to signal paste completion to Claude Code, fixing mainHeight calculation to prevent the UI from extending beyond terminal bounds, improving thinking state detection with additional patterns, and adding a global usage overlay (press u key). The PR also persists Claude session IDs across restarts for accurate usage tracking.

Key improvements:

  • Fixed paste detection by sending double Enter to Claude Code
  • Corrected UI height calculation (subtracted additional 4 for proper frame fitting)
  • Enhanced thinking state detection with more comprehensive patterns
  • Removed overly generic (?m)>\s*$ idle pattern that could false-match
  • Added global usage tracking overlay with async loading
  • Implemented persistent Claude session ID storage for usage continuity across restarts
  • Changed header to display total usage across all sessions instead of selected session only

Issue Found:

  • Race condition in internal/tui/model.go:572-577 where m.globalUsage is written from a goroutine without synchronization

Confidence Score: 4/5

  • This PR is safe to merge with one data race issue that should be addressed
  • Score reflects solid implementation of paste detection, UI fixes, and persistence features, but reduced by 1 point due to the goroutine race condition in the usage overlay feature that could cause crashes or data corruption under concurrent access
  • Pay close attention to internal/tui/model.go - the race condition on line 572-577 should be fixed before merge by using a channel or mutex for the globalUsage update

Important Files Changed

Filename Overview
internal/tmux/client.go Added double Enter key press to signal paste completion for Claude Code
internal/tui/view.go Fixed mainHeight calculation to prevent UI overflow, added usage overlay, changed header to show total usage
internal/tui/model.go Added global usage overlay state and async loading of global usage data
internal/daemon/monitor.go Implemented persistent Claude session ID storage for usage tracking across restarts

Sequence Diagram

sequenceDiagram
    participant User
    participant TUI as TUI (model.go)
    participant Tmux as Tmux Client
    participant Claude as Claude Code
    participant Monitor as Monitor
    participant Store as SQLite Store
    participant Usage as Usage Parser

    Note over User,Usage: Paste Detection Flow
    User->>TUI: Press 'i' and paste prompt
    TUI->>Tmux: SendKeys(session, keys)
    Tmux->>Tmux: send-keys with "Enter" "Enter"
    Tmux->>Claude: Double Enter signals paste end
    Claude->>Claude: Submit prompt

    Note over User,Usage: Usage Tracking Persistence
    Monitor->>Store: GetClaudeSessionID(tmuxSession)
    alt Session ID exists in DB
        Store-->>Monitor: Return persisted UUID
    else No persisted ID
        Monitor->>Usage: FindActiveSessionID(workingDir)
        Usage-->>Monitor: Return latest session UUID
        Monitor->>Store: SetClaudeSessionID(tmuxSession, UUID)
    end
    Monitor->>Usage: GetSessionByID(workingDir, UUID)
    Usage-->>Monitor: SessionUsage data

    Note over User,Usage: Global Usage Overlay
    User->>TUI: Press 'u' key
    TUI->>TUI: showUsage = true
    TUI->>Usage: GetGlobalUsage() (async)
    Usage->>Usage: Scan all project dirs
    Usage-->>TUI: GlobalUsage data
    TUI->>User: Render usage overlay

    Note over User,Usage: UI Height Calculation Fix
    TUI->>TUI: Calculate mainHeight
    TUI->>TUI: height - header - groups - prompt - helpBar - 4 dividers - 4
    TUI->>User: Render within terminal bounds
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

10 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread internal/tui/model.go
Comment on lines +572 to +577
case "u":
m.showUsage = true
go func() {
global, _ := usage.GetGlobalUsage()
m.globalUsage = global
}()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

logic: race condition - goroutine writes to m.globalUsage without synchronization

m.globalUsage is accessed by the main render thread but updated from this goroutine without mutex protection, causing a data race.

Suggested change
case "u":
m.showUsage = true
go func() {
global, _ := usage.GetGlobalUsage()
m.globalUsage = global
}()
case "u":
m.showUsage = true
go func() {
global, _ := usage.GetGlobalUsage()
// TODO: Send result via channel to avoid race
_ = global // temporarily unused to avoid race
}()
Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/tui/model.go
Line: 572:577

Comment:
**logic:** race condition - goroutine writes to `m.globalUsage` without synchronization

`m.globalUsage` is accessed by the main render thread but updated from this goroutine without mutex protection, causing a data race.

```suggestion
	case "u":
		m.showUsage = true
		go func() {
			global, _ := usage.GetGlobalUsage()
			// TODO: Send result via channel to avoid race
			_ = global // temporarily unused to avoid race
		}()
```

How can I resolve this? If you propose a fix, please make it concise.

@MartianGreed
MartianGreed force-pushed the push-rtostttwsxmo branch 3 times, most recently from 6b448ee to 4cb7f91 Compare January 26, 2026 13:55
@MartianGreed
MartianGreed merged commit 1eddd8f into main Jan 26, 2026
3 checks passed
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.

1 participant