Skip to content

Refactor CLI drive session controller complexity #897

@willwashburn

Description

@willwashburn

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions