feat: migrate all session_state usage to capabilities#149
Open
feat: migrate all session_state usage to capabilities#149
Conversation
Replace all session_state.get('mode_discovery') and
session_state.get('mode_hooks') reads in app-cli with
self.session.coordinator.get_capability('modes.discovery') and
self.session.coordinator.get_capability('modes.hooks').
Production code changes in main.py:
- _populate_mode_shortcuts (line 329): mode_discovery
- _handle_mode (lines 486, 504, 519, 528, 536, 542): mode_discovery + mode_hooks
- _list_modes (line 552): mode_discovery
- _format_help (line 850): mode_discovery
Test helper in test_mode_trailing_prompt.py:
- _make_command_processor: uses capabilities dict with modes.discovery,
modes.hooks, modes.active_mode via get_capability.side_effect
All 550 tests pass.
Task-12: Replace all session_state["active_mode"] accesses with
get_capability/register_capability("modes.active_mode", ...).
Changes in amplifier_app_cli/main.py:
- __init__: register_capability("modes.active_mode", None) on init
- process_input: get_capability for active_mode read (line ~377)
- _handle_mode: remove session_state local var; all 5 writes now use
register_capability; current_mode read uses get_capability
- _list_modes: remove session_state local var; current_mode read uses
get_capability
- _get_config_display: active_mode read uses get_capability (line ~670)
- Lambda in _create_prompt_session call: uses get_capability (lines ~1471-1473)
Zero session_state["active_mode"] references remain in production code.
Test: tests/test_active_mode_capabilities_migration.py - 14 new tests
covering reads, writes, list_modes, and session_state-free behaviour.
All 563 tests pass.
task-13: Delete the 'if not hasattr(coordinator, session_state)' block
from CommandProcessor.__init__ in app-cli.
The block initialized coordinator.session_state = {} when it was absent.
This is now handled by the coordinator itself; CommandProcessor should
not be responsible for bootstrapping session_state.
Verified:
- hooks-mode has no session_state init block (confirmed via grep)
- app-cli main.py no longer contains the init block
- All 565 app-cli tests pass
Co-authored-by: Amplifier <amplifier@example.com>
…t helper
test_mode_trailing_prompt.py's _make_command_processor() was setting
session_state = {'active_mode': active_mode} for a key that has been
migrated to capabilities (modes.active_mode).
The mock already provided active_mode via get_capability() on line 33;
the session_state entry was dead. Update to session_state = {} per the
task-14 requirement: no test should read from session_state for migrated
keys. The empty dict is retained for backward compatibility only.
Task: task-14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrates ~20 session_state read/write sites in CommandProcessor to get_capability/register_capability.
Changes
Testing