Feature: Context Manager for CLI Sessions As a user of CleverAgents I want to save and restore conversation contexts So that I can have stateful interactions across CLI runs Background: Given I have a temporary test directory for contexts Scenario: Create a new context manager When I create a context manager with name "test-session" Then the context manager should be initialized And the context directory should exist And the context files should be created Scenario: Save and load messages Given I have a context manager with name "chat-session" When I add a user message "Hello, how are you?" And I add an assistant message "I'm doing well, thank you!" And I save the context Then the messages should be persisted to disk When I create a new context manager with the same name "chat-session" Then the loaded messages should match the saved messages Scenario: Save and restore global context Given I have a context manager with name "stateful-session" When I save global context with key "writing_stage" and value "planning" And I save global context with key "document_type" and value "research_paper" Then the global context should be persisted to disk When I reload the context manager Then the global context should contain "writing_stage" with value "planning" And the global context should contain "document_type" with value "research_paper" Scenario: Update existing context state Given I have a context manager with name "update-session" And the context has state "current_task" with value "writing" When I update the state "current_task" to "reviewing" And I add metadata "last_update" with current timestamp Then the state should be updated And the metadata should contain the timestamp Scenario: Get last N messages from history Given I have a context manager with name "history-session" And I have added 10 messages to the conversation When I request the last 5 messages Then I should receive exactly 5 messages And the messages should be the most recent ones Scenario: Clear conversation history Given I have a context manager with name "clear-session" And the context has 5 messages in history When I clear the context Then the message history should be empty But the context directory should still exist Scenario: Delete entire context Given I have a context manager with name "delete-session" And the context has messages and state data When I delete the context Then the context directory should not exist And attempting to load the context should indicate it doesn't exist Scenario: List available contexts Given I have created contexts named "context1", "context2", "context3" When I list all contexts Then the list should contain "context1", "context2", "context3" And the list should be sorted alphabetically Scenario: Export and import context Given I have a context manager with name "export-session" And the context has messages, state, and global context data When I export the context to a file Then the export file should contain all context data When I import the context as "import-session" Then the imported context should match the original Scenario: Get formatted conversation history Given I have a context manager with name "format-session" And I have added messages with timestamps When I get formatted history without metadata Then the output should show timestamps, roles, and content When I get formatted history with metadata Then the output should include metadata information Scenario: Handle non-existent context gracefully When I create a context manager with name "new-session" And I check if the context exists Then it should indicate the context doesn't exist When I try to get messages from the empty context Then it should return an empty list Scenario: Tool agent context updates are captured Given I have a context manager tool agent with Python code that updates context When the tool executes code that sets context["writing_stage"] to "drafting" Then the global context updates should be captured And the context should persist after execution Scenario: Context updates through stream routing Given I have a reactive stream router with context-aware agents When a message flows through the stream with context metadata And agents modify the context during processing Then all context modifications should be preserved And the final context should reflect all changes Scenario: Run with context and conversation history Given an application with simple config for context When running with 15 message conversation history Then only last 10 messages are used And prompt is formatted with history Scenario: Run with context and long assistant response Given an application with simple config for context When running with 600 character assistant response Then response is truncated to 500 characters Scenario: Run with context without history Given an application with simple config for context When running with no conversation history Then prompt is used without modification Scenario: Temperature override in global context Given a config file path for context When creating app with temperature override 0.8 Then global context contains temperature value 0.8