Context
runDriveSession in src/cli/commands/drive.ts is doing too many CLI session-controller jobs at once and currently trips the complexity rule (23, max 15). The SDK should own broker primitives, but the remaining complexity is mostly terminal UX/state-machine work that belongs in the CLI.
This follows the SDK session-primitives work in PR #896: once the CLI calls SDK primitives for broker routes, the next cleanup is to split the CLI-only orchestration into smaller helpers without expanding the SDK with interactive session verbs.
Scope
Keep this as a minimal refactor with no intended behavior change. Candidate extractions:
- Prepare and validate the drive attach target.
- Switch session mode and reliably restore it during teardown.
- Capture initial snapshot and pending-message state.
- Wire stdin/raw-mode input handling and drive keybindings.
- Wire terminal resize forwarding.
- Share any common interactive attach plumbing with passthrough only where it reduces duplication cleanly.
Non-goals
- Do not add
drive, view, or passthrough as SDK methods. Those are terminal-interactive surfaces, not programmatic primitives.
- Do not change broker routes or protocol behavior.
- Do not rework unrelated CLI commands.
Acceptance criteria
runDriveSession is at or below the configured complexity limit.
- Existing drive/passthrough behavior is preserved.
- CLI tests for
drive, passthrough, and attach plumbing pass.
- Any new helper tests are focused on extracted behavior rather than duplicating end-to-end terminal coverage.
Context
runDriveSessioninsrc/cli/commands/drive.tsis doing too many CLI session-controller jobs at once and currently trips the complexity rule (23, max15). The SDK should own broker primitives, but the remaining complexity is mostly terminal UX/state-machine work that belongs in the CLI.This follows the SDK session-primitives work in PR #896: once the CLI calls SDK primitives for broker routes, the next cleanup is to split the CLI-only orchestration into smaller helpers without expanding the SDK with interactive session verbs.
Scope
Keep this as a minimal refactor with no intended behavior change. Candidate extractions:
Non-goals
drive,view, orpassthroughas SDK methods. Those are terminal-interactive surfaces, not programmatic primitives.Acceptance criteria
runDriveSessionis at or below the configured complexity limit.drive,passthrough, and attach plumbing pass.