SuperChat V2 Specification

Overview

V2 adds user registration, advanced channel management, and message editing while maintaining backward compatibility with V1. All V2 features are parallel additions that don't break V1 clients or require V1 data migration.

V2 Feature Status

✅ Completed Features

1. User Registration & Authentication

Status: Complete (commit eabf559)

  • ✅ User table with password hashing (bcrypt cost 10)
  • ✅ User flags system (uint8 bitfield): admin (0x01), moderator (0x02)
  • ✅ Protocol messages: AUTH_REQUEST, AUTH_RESPONSE, REGISTER_USER, REGISTER_RESPONSE
  • ✅ Server-side nickname prefixes: $ (admin), @ (moderator), ~ (anonymous)
  • ✅ Session caching of user flags for efficient display
  • ✅ Normalized database design (user info stored once, looked up per message)

Migration: 002_add_user_table.sql

Key Files:

  • pkg/protocol/messages.go - Auth/register message types
  • pkg/protocol/user_flags.go - UserFlags type with helpers
  • pkg/server/handlers.go - handleAuthRequest, handleRegisterUser
  • pkg/database/database.go - User CRUD operations

2. User-Created Channels

Status: Complete (commit eabf559)

  • ✅ Registered users can create channels (anonymous users cannot)
  • ✅ Protocol messages: CREATE_CHANNEL (0x07), CHANNEL_CREATED (0x87)
  • ✅ Hybrid response+broadcast pattern (matches PROTOCOL.md spec)
  • ✅ Foreign key constraint: Channel.created_by → User.id
  • ✅ Validation: name (3-50 chars), description (max 500), retention (1h-1yr)
  • ✅ V2 supports forum channels only (type 1)
  • ✅ Broadcast to all connected users (except creator who gets response)

Migration: 003_user_created_channels.sql (with @foreign_keys=off header)

Key Files:

  • pkg/protocol/messages.go - CREATE_CHANNEL, CHANNEL_CREATED messages
  • pkg/server/handlers.go - handleCreateChannel, broadcastChannelCreated
  • pkg/database/migrations.go - Migration metadata header support

3. Message Editing

Status: Complete

  • ✅ Users can edit their own messages (identified by author_user_id)
  • ✅ EDIT_MESSAGE request (0x0B), MESSAGE_EDITED broadcast (0x8B)
  • ✅ Track edit history in MessageVersion table
  • ✅ Show "(edited)" indicator in UI
  • ✅ Server-side ownership validation
  • ✅ Anonymous users can edit by session (before disconnect)
  • ✅ Registered users checked by user_id
  • ✅ Broadcast MESSAGE_EDITED to all users in channel

Key Files:

  • pkg/protocol/messages.go - EDIT_MESSAGE, MESSAGE_EDITED messages
  • pkg/server/handlers.go - handleEditMessage with ownership validation
  • pkg/database/database.go - UpdateMessage, CreateMessageVersion
  • pkg/client/ui/ - Edit UI and "(edited)" indicator

4. Chat Channel Type

Status: ✅ Complete

  • ✅ Support both forum (type 1) and chat (type 0) channels
  • ✅ Chat channels: linear chronological view (like IRC/Slack)
  • ✅ Forum channels: threaded discussion view (existing)
  • ✅ Channel type selection during creation
  • ✅ Different UI rendering based on channel type
  • ✅ Server validation: channel_type ∈ {0, 1}

Key Files:

  • pkg/server/handlers.go - Channel type validation (lines 403-407)
  • pkg/client/ui/model.go - Channel type-aware navigation (line 721)
  • pkg/client/ui/view.go - Chronological rendering for chat channels (line 972)

5. SSH Key Authentication

Status: ✅ Complete

  • ✅ All 8 implementation phases complete
  • ✅ SSH server infrastructure (pkg/server/ssh.go)
  • ✅ Public key authentication with auto-registration
  • ✅ SSHKey table (migration 005_add_ssh_keys.sql)
  • ✅ Fingerprint-based identity (SHA256)
  • ✅ SSH key management UI (add/list/delete/rename)
  • ✅ Password change functionality
  • ✅ Server discovery system
  • ✅ Auto-registration rate limiting (10 per hour per IP)

Migration: 005_add_ssh_keys.sql

Key Files:

  • pkg/server/ssh.go - SSH authentication and auto-registration
  • pkg/database/database.go - SSHKey CRUD operations
  • pkg/client/ui/modal/ssh_key_manager.go - SSH key management UI
  • pkg/client/connection.go - SSH client connection

Design Document: See docs/feature_design/ssh_authentication.md for full implementation plan


V2 Status Summary

V2 is COMPLETE! 🎉

All 5 core V2 features are implemented:

  1. ✅ User Registration & Authentication
  2. ✅ User-Created Channels
  3. ✅ Message Editing
  4. ✅ Chat Channel Type (type 0 for linear chat, type 1 for threaded forum)
  5. ✅ SSH Key Authentication

See V3.md for next features:

  • Subchannels (two-level hierarchy)
  • Direct messages (private channels)
  • End-to-end encryption (AES-256-GCM)
  • Message compression (LZ4)

Database Schema Changes (V2)

All V2 migrations are complete:

  • 002_add_user_table.sql - User table with user_flags, password_hash
  • 003_user_created_channels.sql - FK constraint on Channel.created_by
  • 005_add_ssh_keys.sql - SSHKey table for SSH authentication

Testing Requirements

V2 features meet coverage requirements:

  • Protocol package: 90%+ coverage (enforced)
  • Server package: 80-90% coverage
  • Database migrations: Path tests validate data integrity

Client UI Updates (V2)

All V2 UI features are implemented:

  • ✅ Registration prompt: [Ctrl+R] Register
  • ✅ Login prompt: [Ctrl+L] Login
  • ✅ Header shows authenticated user: Connected: alice
  • ✅ Channel creation UI: [Ctrl+N] New Channel (registered users only)
  • ✅ SSH connection support with auto-discovery
  • ✅ Message edit UI: [e] Edit when message selected
  • ✅ Edit indicator: (edited) timestamp in message display
  • ✅ SSH key manager: [Ctrl+K] (add/list/delete/rename keys)
  • ✅ Password change modal: Change password for SSH or password-registered users

References

  • Protocol: See ../PROTOCOL.md for complete message specifications
  • V1 Spec: See V1.md for V1 implementation details
  • V3 Spec: See V3.md for planned V3 features
  • Data Model: See ../DATA_MODEL.md for full database schema
  • Migrations: See ../MIGRATIONS.md for migration system guide