User Story:
As a user, I want to be able to scroll up to review previous messages
while the AI is streaming or adding new content, without being
constantly dragged back to the bottom.
Implementation:
- Replaced position-based threshold detection with user-intent tracking
- Detects when user scrolls UP and disables auto-scroll completely
- Auto-scroll only re-enables when user manually returns to bottom (<5px)
- Uses refs to track scroll position and direction for smooth operation
- Works seamlessly during rapid token streaming and tool execution
Technical Details:
- lastScrollTopRef: Tracks previous scroll position to detect direction
- userScrolledUpRef: Flag set when upward scrolling is detected
- Direct scrollTop manipulation for instant, non-fighting scroll behavior
- Threshold of 5px from absolute bottom to re-enable auto-scroll
Spec Updates:
- Added comprehensive Smart Auto-Scroll section to UI_UX.md
- Documented the problem, solution, requirements, and implementation
- Includes code examples and edge case handling
Acceptance Criteria Met:
✅ Auto-scroll disabled when scrolling up
✅ Auto-scroll resumes when returning to bottom
✅ Works normally when already at bottom
✅ Smooth detection without flickering
✅ Works during streaming and tool execution
Files Changed:
- src/components/Chat.tsx: Implemented user-intent tracking
- .living_spec/specs/functional/UI_UX.md: Added Smart Auto-Scroll spec
- .living_spec/stories/22_smart_autoscroll.md: Marked complete
- Call cancel_chat before clearing session state
- Prevents tools from executing silently in background
- Prevents streaming from leaking into new session
- Uses same cancellation infrastructure as Story 13
- Clean session start with no side effects
Closes Story 15
- Added 'New Session' button in header with confirmation dialog
- Clears frontend messages, streaming content, and loading state
- Button has subtle styling with hover effects
- Preserves project path, model selection, and tool settings
- Backend context automatically cleared (no server-side history)
- Fixed build errors by removing unused tokio watch channel
- All quality checks passing (TypeScript, Biome, Clippy, builds)
Tested and verified:
- Button appears in header near model controls
- Confirmation dialog prevents accidental clearing
- Messages clear immediately after confirmation
- Input remains ready for new conversation
- Settings preserved across session clears
- Backend: Added OllamaProvider::chat_stream() with newline-delimited JSON parsing
- Backend: Emit chat:token events for each token received from Ollama
- Backend: Added futures dependency and stream feature for reqwest
- Frontend: Added streamingContent state and chat:token event listener
- Frontend: Real-time token display with auto-scroll
- Frontend: Markdown and syntax highlighting support for streaming content
- Fixed all TypeScript errors (tsc --noEmit)
- Fixed all Biome warnings and errors
- Fixed all Clippy warnings
- Added comprehensive code quality documentation
- Added tsc --noEmit to verification checklist
Tested and verified:
- Tokens stream in real-time
- Auto-scroll works during streaming
- Tool calls interrupt streaming correctly
- Multi-turn conversations work
- Smooth performance with no lag
Merged from feature/interrupt-on-type branch.
Backend cancellation infrastructure:
- Added tokio watch channel to SessionState for cancellation signaling
- Implemented cancel_chat command
- Modified chat command to use tokio::select! for racing requests vs cancellation
- When cancelled, HTTP request to Ollama is dropped and returns early
- Added tokio dependency with sync feature
Story updates:
- Story 13: Updated to use Stop button pattern (industry standard)
- Story 18: Created placeholder for streaming responses
- Stories 15-17: Placeholders for future features
Frontend changes:
- Removed auto-interrupt on typing behavior (too confusing)
- Backend infrastructure ready for Stop button implementation
Note: Story 13 UI (Stop button) not yet implemented - backend ready
Implemented Story 14: Auto-focus Chat Input
- Added inputRef using useRef<HTMLInputElement>
- Added useEffect to focus input on component mount
- Input now automatically receives focus when chat loads
- Cursor is visible and blinking immediately
- Users can start typing without clicking into the field
Updated Specs
- Added Input Focus Management section to UI_UX.md
- Specified auto-focus behavior and requirements
- Provided implementation example
Implemented Story 11: Text Alignment and Syntax Highlighting
- Removed center-alignment from chat container (text-align: center)
- Added left-alignment to markdown body and code blocks
- Integrated react-syntax-highlighter with react-markdown
- Added syntax highlighting for code blocks using oneDark theme
- Supports JavaScript, TypeScript, Rust, Python, JSON, Markdown, Shell, and more
- Inline code maintains simple styling without full highlighting
- All code blocks are now left-aligned for better readability
Fixed: Agent over-aggressive file writing behavior
- Refined system prompt to distinguish between:
* 'show/example/how does' → respond with code in chat
* 'create/add/implement/fix' → use write_file tool
- Removed aggressive AGENT DIRECTIVE prefix from user messages
- Softened reminder message to reflect nuanced behavior
- Agent can now both teach (show examples) and implement (write files)
Updated Specs
- Added Text Alignment and Readability section to UI_UX.md
- Added Syntax Highlighting section with implementation details
- Updated SDSW workflow: acceptance criteria marked complete only after user acceptance
Dependencies
- Added react-syntax-highlighter and @types/react-syntax-highlighter