Skip to content

Conversation

@newhook
Copy link
Owner

@newhook newhook commented Jan 13, 2026

Summary

This PR extracts all zellij terminal multiplexer code from internal/claude/runner.go into a dedicated internal/zellij/ package. The new package provides clean abstractions for session, tab, and pane management with proper typing and error handling.

Key changes:

  • Created internal/zellij/zellij.go with a type-safe Client struct and comprehensive API
  • Refactored internal/claude/runner.go to use the new zellij package
  • Removed ~165 lines of duplicated zellij command code from runner.go
  • Added unit tests for the new package

New Package API

The internal/zellij package provides:

Session Management

  • ListSessions() - List all zellij sessions
  • SessionExists() - Check if a session exists
  • CreateSession() - Create a new session (detached)
  • EnsureSession() - Create session if it doesn't exist

Tab Management

  • CreateTab() - Create a new tab with name and working directory
  • SwitchToTab() - Switch to a tab by name
  • QueryTabNames() - List all tab names in a session
  • TabExists() - Check if a tab exists
  • CloseTab() - Close the current tab

Pane Input Control

  • WriteASCII() - Write ASCII codes (Ctrl+C, Enter, etc.)
  • WriteChars() - Write text to the pane
  • SendCtrlC() - Convenience method for interrupt
  • SendEnter() - Convenience method for enter key
  • ExecuteCommand() - Write command and send Enter

High-Level Operations

  • TerminateProcess() - Send Ctrl+C twice with delay for reliable termination
  • ClearAndExecute() - Clear line and run a command
  • TerminateAndCloseTab() - Terminate process and close tab

Benefits

  • Single source of truth for all zellij interactions
  • Type-safe API instead of raw exec.Command calls scattered throughout the codebase
  • Testable - The client can be mocked for unit testing
  • Consistent error handling with wrapped errors
  • Configurable timeouts via the Client struct
  • Reusable across the codebase

Issues Resolved

  • ac-8qe: Create internal/zellij package (Epic)
    • ac-gn0: Create zellij package structure with Client struct and core types
    • ac-8hf: Implement zellij session management functions
    • ac-t6g: Implement zellij tab management functions
    • ac-4fu: Implement zellij pane input control functions
    • ac-ql4: Implement high-level zellij operations
    • ac-8ev: Refactor claude/runner.go to use zellij package
    • ac-0by: Add unit tests for zellij package

Test Plan

  • Unit tests pass: go test ./internal/zellij/...
  • Full test suite passes: go test ./...
  • Build succeeds: go build -o co .
  • Manual testing: Create and run work units with zellij integration

🤖 Generated with Claude Code

Extract zellij-related code from internal/claude/runner.go into a
dedicated internal/zellij package with type-safe API:

- Client struct with configurable timeouts
- Session management: ListSessions, SessionExists, CreateSession, EnsureSession
- Tab management: CreateTab, SwitchToTab, QueryTabNames, TabExists, CloseTab
- Pane input: WriteASCII, WriteChars, SendCtrlC, SendEnter, ExecuteCommand
- High-level operations: TerminateProcess, ClearAndExecute, TerminateAndCloseTab

Refactored runner.go to use the new package, removing ~120 lines of
duplicated exec.Command calls.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@newhook newhook merged commit bb7df94 into main Jan 13, 2026
@newhook newhook deleted the feat/create-internalzellij-package branch January 14, 2026 14:18
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.

2 participants