agent: Fix terminal_init commands race condition with PTY startup (#59613)

Summary:
- Add a shell-level startup handshake owned by the terminal.
- Send a split startup marker through the shell and run the configured
init command after the marker is observed, preventing local echo from
satisfying the handshake.
- Keep display-only/restored terminal behavior unchanged while
preserving startup output when shells fail or users type first.

Tests:
- `cargo test -p terminal test_init_command_startup_marker --
--nocapture`
- `cargo test -p terminal write_init_command_after_startup --
--nocapture`
- `cargo test -p agent_ui init_command -- --nocapture`
- `./script/clippy -p terminal -p agent_ui`

Closes AI-426

Release Notes:

- Fixed terminal init commands sometimes appearing or running
incorrectly when using custom shells

---------

Co-authored-by: Anant Goel <anant@zed.dev>
a2fee92e30MartinYe1234 committed on 6/23/2026, 6:44:42 PM· committed by GitHubparent42a2eff
2 files changedLine totals unavailable