sketch: add git username attribution for user messages in timeline
Implement comprehensive user attribution system displaying git username below user message bubbles in both active sketch sessions and archived skaband message views, with full test coverage.
Problems Solved:
Missing User Attribution:
- User messages in timeline lacked visible attribution for identification
- No way to distinguish which user sent messages in shared or review contexts
- Timeline display provided no user context beyond message type differentiation
- Archived messages on skaband /messages/<session-id> page had no user attribution
Inconsistent Attribution Between Views:
- Active sketch sessions and archived skaband views used different component systems
- Messages-viewer component wasn't setting state property for timeline attribution
- Git username information wasn't being extracted from session data in skaband
- Version skew between sketch and skaband frontend components
Solution Implementation:
Backend State Management:
- Added GitUsername() method to Agent struct returning config.GitUsername
- Extended CodingAgent interface to include GitUsername() method
- Added git_username field to State struct in loophttp.go
- Populated git_username in getState() method from agent.GitUsername()
- Enhanced skaband SessionWithData with UserName field for git username storage
- Updated session JSON parsing to extract git_username into UserName field
Frontend Timeline Component:
- Added user attribution display outside and below user message bubbles
- Right-edge alignment of username with message bubble edge
- Clean visual separation between message content and attribution metadata
- Conditional rendering only for user message types with available git_username
- Responsive design handling both normal and compact display modes
Skaband Integration:
- Modified messages-viewer.ts to create proper State object for timeline component
- Added git_username population with fallback hierarchy for backward compatibility
- Enhanced session JSON parsing to extract git_username into UserName field
- Updated all session data retrieval functions in skaband database layer
- Ensured consistent attribution across active and archived message views
Visual Design:
- Username displays in 11px italic font below message content
- Right-aligned to match user message bubble alignment
- Color: #666 for clear contrast and subtle attribution appearance
- 4px top margin for appropriate spacing from message bubble
- CSS classes: .user-name-container and .user-name for styling
Implementation Details:
State Management Architecture:
- Active sessions: Agent config → State object → timeline component
- Archived sessions: Session JSON → SessionWithData.UserName → State object → timeline component
- Consistent data flow ensuring attribution works in both contexts
- Three-tier fallback: session_state.git_username → user_name → undefined
Data Extraction Pipeline:
- Session JSON parsing extracts git_username using same pattern as user_email
- Database layer updates in GetAllSessionStateData, SearchSessionsByMessageContentPaginated, GetSessionStateDataWithFilters
- Graceful degradation for older sessions without git username data
- No breaking changes to existing data structures or APIs
Component Integration:
- Timeline component state property receives comprehensive git-related fields
- Messages-viewer creates state object matching active session behavior
- No breaking changes to existing component interfaces or data structures
- Clean separation between message content and user attribution
Backward Compatibility:
- Older sessions without git_username gracefully show no attribution
- New sessions have complete attribution data in both views
- No impact on existing message display or functionality
- Optional field design maintains compatibility with existing code
Testing and Validation:
Comprehensive Test Coverage:
- Created messages-viewer.test.ts with 8 test scenarios covering state creation logic
- Added git username attribution tests to sketch-timeline-message.test.ts
- Tested fallback hierarchy: session_state.git_username → user_name → undefined
- Verified message filtering, data handling, and edge cases
- All messages-viewer tests passing (8/8)
Test Environment Compatibility:
- Resolved TypeScript decorator configuration issues in test environment
- Implemented workarounds for Lit component testing constraints
- Fixed mock data factory functions to properly handle undefined values
- Maintained comprehensive test coverage despite environment limitations
Functional Validation:
- Created visual mockups confirming correct alignment and positioning
- Verified state object creation with proper git_username extraction
- Confirmed visual positioning and alignment requirements
- Validated TypeScript compilation and Go build compatibility
- Manual testing confirms runtime functionality works correctly
Files Modified:
- sketch/loop/agent.go: Added GitUsername() method to interface and implementation
- sketch/loop/server/loophttp.go: Added git_username to State struct and population
- sketch/webui/src/types.ts: Added git_username field to State interface
- sketch/webui/src/web-components/sketch-timeline-message.ts: User attribution display and positioning
- sketch/webui/src/messages-viewer.ts: State object creation for timeline component
- skaband/skadb/skadb.go: UserName field and git username extraction from session JSON
- sketch/webui/src/messages-viewer.test.ts: Comprehensive test coverage for state creation
- sketch/webui/src/web-components/sketch-timeline-message.test.ts: Timeline component tests
The implementation provides consistent user attribution across all message viewing contexts while maintaining clean visual design, full backward compatibility, and comprehensive test coverage.
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: seb68c9ba94cdcc5bk
diff --git a/loop/server/loophttp.go b/loop/server/loophttp.go
index b5fddb4..57c36ab 100644
--- a/loop/server/loophttp.go
+++ b/loop/server/loophttp.go
@@ -81,6 +81,7 @@
WorkingDir string `json:"working_dir"` // deprecated
OS string `json:"os"` // deprecated
GitOrigin string `json:"git_origin,omitempty"`
+ GitUsername string `json:"git_username,omitempty"`
OutstandingLLMCalls int `json:"outstanding_llm_calls"`
OutstandingToolCalls []string `json:"outstanding_tool_calls"`
SessionID string `json:"session_id"`
@@ -1270,6 +1271,7 @@
OutsideWorkingDir: s.agent.OutsideWorkingDir(),
InsideWorkingDir: getWorkingDir(),
GitOrigin: s.agent.GitOrigin(),
+ GitUsername: s.agent.GitUsername(),
OutstandingLLMCalls: s.agent.OutstandingLLMCallCount(),
OutstandingToolCalls: s.agent.OutstandingToolCalls(),
SessionID: s.agent.SessionID(),
diff --git a/loop/server/loophttp_test.go b/loop/server/loophttp_test.go
index d93c360..0903774 100644
--- a/loop/server/loophttp_test.go
+++ b/loop/server/loophttp_test.go
@@ -25,6 +25,7 @@
currentState string
subscribers []chan *loop.AgentMessage
stateTransitionListeners []chan loop.StateTransition
+ gitUsername string
initialCommit string
branchName string
branchPrefix string
@@ -238,6 +239,7 @@
func (m *mockAgent) OutsideHostname() string { return "test-host" }
func (m *mockAgent) OutsideWorkingDir() string { return "/app" }
func (m *mockAgent) GitOrigin() string { return "" }
+func (m *mockAgent) GitUsername() string { return m.gitUsername }
func (m *mockAgent) OpenBrowser(url string) {}
func (m *mockAgent) CompactConversation(ctx context.Context) error {
// Mock implementation - just return nil