Feature: TUI Session Persistence
  As a user
  I want my TUI session state to be persisted to SQLite
  So that I can resume my work when I restart the TUI

  Background:
    Given a clean TUI session database

  Scenario: Database is created on first launch
    When the TUI session store is initialized
    Then the SQLite database file exists at ~/.local/state/cleveragents/tui.db
    And the database has sessions and active_session tables

  Scenario: Save and load a session
    Given a session with id "test-session" and transcript ["hello", "world"]
    When I save the session to the database
    Then the session can be loaded from the database
    And the loaded session has the same id and transcript

  Scenario: Set and get active session
    Given a session with id "session-1"
    When I set it as the active session
    Then the active session id is "session-1"

  Scenario: List all sessions
    Given sessions with ids ["session-1", "session-2", "session-3"]
    When I save all sessions to the database
    Then listing sessions returns all three session ids

  Scenario: Delete a session
    Given a session with id "to-delete" in the database
    When I delete the session
    Then the session can no longer be loaded from the database

  Scenario: Clear all sessions
    Given sessions with ids ["session-1", "session-2"]
    When I save all sessions to the database
    And I clear all sessions
    Then the database has no sessions
    And there is no active session

  Scenario: Restore last active session on startup
    Given a session with id "last-session" and transcript ["msg1", "msg2"]
    When I save the session and set it as active
    And I create a new session store instance
    Then the active session is "last-session"
    And the session data is restored correctly

  Scenario: Store uses default database path when none is specified
    Given the TUI session store is created with default database path
    Then the SQLite database file exists at ~/.local/state/cleveragents/tui.db
