Skip to content

feat: add MCP session reset endpoint with terminal improvements#280

Merged
2mawi2 merged 6 commits into2mawi2:mainfrom
shawnsw:main
Jan 31, 2026
Merged

feat: add MCP session reset endpoint with terminal improvements#280
2mawi2 merged 6 commits into2mawi2:mainfrom
shawnsw:main

Conversation

@shawnsw
Copy link
Copy Markdown
Contributor

@shawnsw shawnsw commented Jan 30, 2026

Summary

This PR adds an MCP API endpoint for resetting sessions and includes several terminal improvements:

New Feature

  • Session Reset API - POST /api/sessions/{name}/reset endpoint to restart session agents from external tooling with optional agent type and prompt overrides

Terminal Improvements

  • Block alternate scroll mode - Prevent xterm from consuming scroll events in alternate screen mode
  • Gate mouse tracking - Disable mouse tracking sequences for agent terminals to avoid garbage output
  • OpenCode scrollback - Keep wheel scroll working in terminal buffer, falling back to PageUp/PageDown
  • Resize after reset - Emit resize requests after session reset to prevent tiny initial terminals

Fixes

  • Persist session agent settings during reset operations
  • Emit sessions refresh after MCP resets so agent labels update in UI
  • Stabilize agent switching during reset flow

Test plan

  • Test MCP reset endpoint: curl -X POST http://localhost:PORT/api/sessions/NAME/reset
  • Verify wheel scroll works in opencode terminals
  • Confirm mouse sequences don't appear in agent output
  • Check terminal resizes correctly after reset

Shawn added 5 commits January 28, 2026 16:56
Expose POST /api/sessions/{name}/reset to force-restart the session
agent from external tooling. Allow optional agent type/skip flags and
propagate a prompt override so the session's initial prompt stays in
sync.
Persist session agent settings during reset and launch orchestrator
with prompt in the command to avoid TUI glitches. Drop mouse tracking
input for agent terminals so control sequences don't pollute output.
Emit sessions refresh after MCP resets so agent labels update. Block TUI
mouse tracking enable in xterm for agent terminals to avoid garbage
sequences while keeping normal mouse interactions.
@shawnsw shawnsw marked this pull request as draft January 30, 2026 04:15
@shawnsw shawnsw changed the title fix: restore opencode scrollback and resize after reset feat: add MCP session reset endpoint with terminal improvements Jan 30, 2026
Add setMouseTrackingAllowed mock method needed after Terminal.tsx
now gates mouse tracking for agent terminals.

Fix wheel scroll test by setting baseY > 0 so the scrollLines path
is taken (with baseY=0, PageUp/PageDown sequences are sent instead).
@shawnsw
Copy link
Copy Markdown
Contributor Author

shawnsw commented Jan 30, 2026

@2mawi2 can you please review this PR? thanks.

@shawnsw shawnsw marked this pull request as ready for review January 31, 2026 00:01
const multiplier = event.deltaMode === 1 ? 1 : 3;
const lines = Math.sign(delta) * Math.max(1, Math.ceil(Math.abs(delta) / 100) * multiplier);
terminal.current.scrollLines(lines);
logScrollChange('wheel');
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to log that?

}
instance.setUiMode(isTuiAgent(agentTypeRef.current) ? 'tui' : 'standard');
instance.setMouseTrackingAllowed(!isAgentTopTerminal);
shouldCaptureWheelRef.current = agentTypeRef.current === 'opencode' && isAgentTopTerminal;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really only opencode specific?

@2mawi2 2mawi2 merged commit 237b789 into 2mawi2:main Jan 31, 2026
10 checks passed
@2mawi2
Copy link
Copy Markdown
Owner

2mawi2 commented Jan 31, 2026

@shawnsw tested this. Looks good, thanks!

2mawi2 added a commit that referenced this pull request Feb 2, 2026
2mawi2 added a commit that referenced this pull request Feb 2, 2026
@2mawi2
Copy link
Copy Markdown
Owner

2mawi2 commented Feb 2, 2026

@shawnsw I had to revert this, the PR broke alternate scrolling. #283 . If you like we can separate each new fix/feature in a dedicated PR, then we don't need to rollback the whole PR for such changes.

@2mawi2
Copy link
Copy Markdown
Owner

2mawi2 commented Feb 2, 2026

To reproduce: Start opencode or any cli with alternate scrolling, then scroll up -> observe no scrolling but last commands changing as if you press arrow up or down.

@shawnsw
Copy link
Copy Markdown
Contributor Author

shawnsw commented Feb 2, 2026

Hmm that's weird. I had the exact issue you described while working on the PR, I thought I had it fixed as the issue was resolved locally. FYI I was using opencode and shell is Zsh.
No issues with the revert. If you have some spare time, feel free to cherry pick the feature changes.

shawnsw pushed a commit to shawnsw/schaltwerk that referenced this pull request Feb 3, 2026
Re-adds the session reset functionality from PR 2mawi2#280 without the
terminal mouse tracking changes that caused wheel scroll issues.

Endpoints:
- POST /api/reset - Reset orchestrator or session with selection
- POST /api/sessions/{name}/reset - Reset specific session

Supports:
- Agent type switching
- Prompt override for fresh starts
- Skip prompt/permissions flags
shawnsw pushed a commit to shawnsw/schaltwerk that referenced this pull request Feb 3, 2026
Re-adds the session reset functionality from PR 2mawi2#280 without the
terminal mouse tracking changes that caused wheel scroll issues.

Endpoints:
- POST /api/reset - Reset orchestrator or session with selection
- POST /api/sessions/{name}/reset - Reset specific session

Supports:
- Agent type switching
- Prompt override for fresh starts
- Skip prompt/permissions flags
2mawi2 added a commit that referenced this pull request Feb 5, 2026
* feat: add MCP session reset endpoint (isolated from terminal changes)

Re-adds the session reset functionality from PR #280 without the
terminal mouse tracking changes that caused wheel scroll issues.

Endpoints:
- POST /api/reset - Reset orchestrator or session with selection
- POST /api/sessions/{name}/reset - Reset specific session

Supports:
- Agent type switching
- Prompt override for fresh starts
- Skip prompt/permissions flags

* fix(ci): remove target-cpu=native from Linux targets

The native flag causes SIGILL on CI runners with different CPU features.
Replace with strip=debuginfo which is CI-safe.

* fix: downgrade tauri to 2.9.5 to match NPM packages (2.9.1)

* ci: add Tauri version sync checks to prevent NPM/Rust mismatch

Dependabot bumped Rust tauri to 2.10.1, but NPM packages are still at 2.9.x,
causing build failures. This adds two safeguards:

1. CI check that fails if Rust tauri and NPM @tauri-apps/api major.minor
   versions don't match
2. Dependabot ignore rules to prevent bumping tauri beyond 2.9.x until
   NPM packages catch up

This prevents the version mismatch from happening again.

* fix: filter -i flag for agent terminals to prevent job control conflicts

Agent terminals (top terminals running Claude, Codex, OpenCode, etc.) call
setRawMode() on the TTY, which conflicts with bash's job control enabled by
the -i (interactive) flag. This resulted in errno 5 (EIO) errors.

Changes:
- Pass terminal_id to resolve_app_program_and_args()
- Add filter_interactive_flag() to remove -i from shell args
- Agent terminals: Remove -i flag even if user has it in settings
- Non-agent terminals: Keep -i flag for interactive behavior

This allows agents to work without requiring users to manually remove -i
from their shell settings.

Also improved CI version check to use cargo tree instead of grep/awk.

* fix: source .zshrc/.bashrc for agents with 'set +m' to disable job control

Previous approach removed -i flag to prevent job control conflicts, but this
prevented .zshrc/.bashrc from being sourced, losing env vars like NVM, PYENV.

New approach:
- Keep -i flag so .zshrc/.bashrc are sourced (provides full environment)
- Add 'set +m;' before agent command to explicitly disable job control
- This prevents conflicts with setRawMode() while keeping full env

Command now looks like:
  /bin/zsh -i -l -c 'set +m; exec claude <args>'

This gives agents:
- .zprofile env (from -l login flag)
- .zshrc env (from -i interactive flag)
- No job control conflicts (from 'set +m')

* fix: bump @tauri-apps/api to 2.10.x to match Rust tauri crate

---------

Co-authored-by: Shawn <[email protected]>
Co-authored-by: 2mawi2 <[email protected]>
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.

3 participants