feat(v0.5.3): AttachExisting passive reattach helper

This commit is contained in:
2026-05-08 13:51:57 -04:00
parent 08b0f1a6a7
commit 7697ec0507
2 changed files with 72 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
package session
import (
"github.com/warrenronsiek/ctask/internal/shell"
)
// attacher is the test seam used by AttachExisting. Production code calls
// shell.AttachSession directly; tests override this variable to capture
// invocations or simulate failures. Do not run tests that override this
// variable in parallel — it is a package global.
var attacher = shell.AttachSession
// AttachExisting is the passive-reattach path. It is invoked when a tmux
// session for the workspace already exists and the lease is fresh and local
// (the original ctask owner is alive and heartbeating).
//
// AttachExisting performs no Preflight, writes no lease, captures no
// manifest, starts no heartbeat, prints no banner, and runs no finalize.
// It connects the user's terminal to the existing tmux session via
// shell.AttachSession and returns when the user detaches or the session
// ends. shell.AttachSession's contract handles failure-mode classification:
// nil on clean exit, wrapped error on non-zero exit.
//
// If the session disappeared between the dispatcher's HasSession check
// and this call, AttachSession returns an error and the user can retry —
// the next invocation will hit the owner-create path.
func AttachExisting(tmuxPath, name string) error {
return attacher(tmuxPath, name)
}