Skip to content

Add caller-aware discovery and explicit startup#99

Open
tony wants to merge 6 commits into
mainfrom
feat/caller-context-discovery
Open

Add caller-aware discovery and explicit startup#99
tony wants to merge 6 commits into
mainfrom
feat/caller-context-discovery

Conversation

@tony

@tony tony commented Jul 13, 2026

Copy link
Copy Markdown
Member

Summary

  • Follow the frozen caller socket by default and make the advertised
    is_caller pane filter executable.
  • Add the zero-input where_am_i discovery tool plus explicit
    scope="caller_session" routing for window and pane lists.
  • Return bounded, deterministic page envelopes from all four hierarchy list
    tools, with compact window and pane summaries by default.
  • Deny implicit tmux daemon startup unless create_session receives explicit
    permission or the server-wide startup setting enables it.

Contract changes

  • Effective target precedence is explicit selector, configured socket path,
    configured socket name, frozen caller socket, then tmux default.
  • list_servers, list_sessions, list_windows, and list_panes now return
    page objects. Read rows from .items; the envelope also reports total,
    offset, limit, and truncated.
  • Window and pane lists default to detail="summary"; callers can request
    detail="full". Their default scope remains server-wide for compatibility,
    while scope="caller_session" fails closed when caller identity is absent,
    stale, or on another effective target.
  • create_session no longer starts a stopped tmux target by default. The
    server_started field records the observable startup-enabled fallback after
    a no-start attempt proved the target absent; it does not claim process
    ownership across an external-client race.

Verification

  • uv run ruff format . --check
  • uv run ruff check .
  • uv run mypy
  • uv run pytest — 826 passed in each of two complete runs
  • uv run pytest tests/test_server_tools.py -ra — 48 passed
  • just build-docs
  • uv build
  • git diff --check main..HEAD

Closes #92.
Closes #93.
Closes #94.
Closes #95.
Closes #96.

tony added 6 commits July 12, 2026 23:35
why: Keep MCP tools on the invoking tmux server and preserve caller
identity across transient environment changes.

what:
- Freeze the invocation environment and normalize selector precedence
- Follow the caller socket path through libtmux Server.from_env
- Share normalized cache targets and cover comma-bearing paths
why: Let agents execute the documented caller-pane discovery filter
without forwarding synthetic model fields to libtmux's QueryList.

what:
- Split native filters from registered synthetic filters
- Apply exact boolean synthetic matches after one serialization pass
- Cover dict, JSON, exact, false, and invalid caller filters
why: Let agents resolve caller-relative tmux requests without a list and
filter round trip or an error when invocation context is unavailable.

what:
- Add frozen typed caller and effective-target discovery
- Keep routine outside, dead, stale, and mismatch states structured
- Move the bounded discovery preload and document relational use
why: Let callers opt into session-local discovery without changing
the server-wide default or widening when caller identity is unavailable.

what:
- Add fail-closed caller-session resolution to pane and window lists
- Reject conflicting selectors and invalid direct-call scopes
- Cover the contract in tests, tool docs, and the changelog
why: Bound hierarchy discovery so large tmux installations do not
flood callers while preserving honest filtered totals.

what:
- Return typed page envelopes from all four hierarchy list tools
- Add compact summary/full projections for windows and panes
- Verify ordering, bounds, schemas, middleware exclusions, and docs
why: Starting a session on a dead target could silently launch a long-lived
tmux daemon and load user configuration.

what:
- Gate dead-server session creation behind an explicit configurable opt-in
- Report the startup-enabled fallback and improve dead-server recovery errors
- Document and test the startup contract
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.92308% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.49%. Comparing base (10db1ea) to head (2528aa8).

Files with missing lines Patch % Lines
src/libtmux_mcp/_utils.py 93.69% 7 Missing ⚠️
src/libtmux_mcp/_server_start.py 95.91% 1 Missing and 1 partial ⚠️
src/libtmux_mcp/tools/server_tools.py 97.72% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #99      +/-   ##
==========================================
+ Coverage   85.30%   86.49%   +1.18%     
==========================================
  Files          44       45       +1     
  Lines        3274     3547     +273     
  Branches      454      487      +33     
==========================================
+ Hits         2793     3068     +275     
- Misses        351      353       +2     
+ Partials      130      126       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment