refactor: deduplicate the three tmux opencode launchers #455

Open
opened 2026-07-25 23:33:33 +02:00 by dries · 0 comments
Owner

Code-quality audit (P2). Three near-identical opencode launchers in internal/tmux/sessions.go:

  • :391 LaunchOpencodeCmdEnvWith
  • :447 LaunchOpencodeWith
  • :514 LaunchOpencodeEnvWith

All three do the same sequence: derive the session name, run the ValidComponent check, call ListSessions, match by cleaned ResolvedPath, short-circuit when idempotent, then NewSession* / NewWindow*. The matching block is repeated verbatim at :397-411, :466-480, and :520-534.

Why it matters

The matching block encodes the tmux dot/underscore quirk documented in AGENTS.md (~/src/github.com/foo becomes ~/src/github_com/foo in tmux output). Any fix to that logic must be made in three places, and a fix applied to two of three produces a launcher that silently targets the wrong pane — the exact failure mode ValidComponent exists to prevent.

Suggested fix

Keep LaunchOpencodeCmdEnvWith as the core implementation. Make the other two thin wrappers:

func LaunchOpencodeWith(r Runner, directory string, idempotent bool) (string, bool, error) {
	return LaunchOpencodeCmdEnvWith(r, directory, "opencode", idempotent, nil)
}

func LaunchOpencodeEnvWith(r Runner, directory string, idempotent bool, env map[string]string) (string, bool, error) {
	return LaunchOpencodeCmdEnvWith(r, directory, "opencode", idempotent, env)
}

(exact default command per current behaviour — verify the three paths really do build the same command before collapsing).

Acceptance criteria

  • The session-matching block exists once.
  • All existing launcher tests pass unchanged, including the dot/underscore matching cases.
  • Public signatures of all three functions are unchanged.

Effort: S.

Code-quality audit (P2). Three near-identical opencode launchers in `internal/tmux/sessions.go`: - `:391` `LaunchOpencodeCmdEnvWith` - `:447` `LaunchOpencodeWith` - `:514` `LaunchOpencodeEnvWith` All three do the same sequence: derive the session name, run the `ValidComponent` check, call `ListSessions`, match by cleaned `ResolvedPath`, short-circuit when idempotent, then `NewSession*` / `NewWindow*`. The matching block is repeated **verbatim** at `:397-411`, `:466-480`, and `:520-534`. ## Why it matters The matching block encodes the tmux dot/underscore quirk documented in AGENTS.md (`~/src/github.com/foo` becomes `~/src/github_com/foo` in tmux output). Any fix to that logic must be made in three places, and a fix applied to two of three produces a launcher that silently targets the wrong pane — the exact failure mode `ValidComponent` exists to prevent. ## Suggested fix Keep `LaunchOpencodeCmdEnvWith` as the core implementation. Make the other two thin wrappers: ```go func LaunchOpencodeWith(r Runner, directory string, idempotent bool) (string, bool, error) { return LaunchOpencodeCmdEnvWith(r, directory, "opencode", idempotent, nil) } func LaunchOpencodeEnvWith(r Runner, directory string, idempotent bool, env map[string]string) (string, bool, error) { return LaunchOpencodeCmdEnvWith(r, directory, "opencode", idempotent, env) } ``` (exact default command per current behaviour — verify the three paths really do build the same command before collapsing). ## Acceptance criteria - [ ] The session-matching block exists once. - [ ] All existing launcher tests pass unchanged, including the dot/underscore matching cases. - [ ] Public signatures of all three functions are unchanged. Effort: S.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dries/ocman#455
No description provided.