Skip to content

Comments

Normalize iTerm2 session ID alias handling#33

Merged
mkusaka merged 4 commits intomainfrom
fix/normalize-session-id-input
Feb 8, 2026
Merged

Normalize iTerm2 session ID alias handling#33
mkusaka merged 4 commits intomainfrom
fix/normalize-session-id-input

Conversation

@mkusaka
Copy link
Owner

@mkusaka mkusaka commented Feb 8, 2026

Summary

Normalize iTerm2 session ID aliases before session lookup so CLI commands accept both shell-facing IDs and canonical API IDs.

Changes

  • Add normalize_session_id in src/it2/core/session_handler.py to convert w<window>t<tab>p<pane>:<GUID> and w<window>t<tab>p<pane>.<GUID> into canonical GUIDs.
  • Add get_session_by_id helper in src/it2/core/session_handler.py and route session resolution through this helper.
  • Update session focus in src/it2/commands/session.py to use normalized lookup.
  • Update profile apply in src/it2/commands/profile.py to use normalized lookup.
  • Update app broadcast add in src/it2/commands/app.py to use normalized lookup.
  • Add/extend tests in tests/test_session_handler.py, tests/test_session_commands.py, tests/test_profile_commands.py, and tests/test_app_commands.py to cover alias formats.
  • Add detailed helper comments/docstrings with iTerm2 implementation context (shell/env alias format vs API exact-match behavior).

Why

iTerm2 often exposes session IDs via shell integration values (e.g. ITERM_SESSION_ID and session.termid) that include window/tab/pane prefixes. The Python API lookup uses exact Session.session_id GUID matching, so alias IDs can fail even when the session exists.

Notes

  • Special selectors active and all remain unchanged.
  • A fallback lookup with the original input is kept to reduce risk if iTerm2 introduces additional ID shapes.
  • CI formatting failure was addressed by applying black formatting to tests/test_session_commands.py.

Testing

  • uv run --with ruff ruff check src tests
  • uv run --with mypy --with types-PyYAML mypy src
  • uv run --with black black --check .
  • uv run --with pytest-asyncio pytest -q tests/test_session_handler.py tests/test_session_commands.py tests/test_profile_commands.py tests/test_app_commands.py
  • GitHub Actions run passed: https://github.com/mkusaka/it2/actions/runs/21803781233

@mkusaka mkusaka merged commit 30fadb9 into main Feb 8, 2026
8 checks passed
@mkusaka mkusaka deleted the fix/normalize-session-id-input branch February 8, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant