polish(v0.5.3): v0.4 lease-prompt hint, invocation-name in user-facing commands, smoke-checklist fixes

Three independent v0.5.3 polish items surfaced during manual WSL smoke testing,
bundled into one commit since they're all string/UX touches with no behavior change.

1. v0.4 lease-prompt tightening (`internal/session/{lease,run,run_preflight}.go`,
   `cmd/entry.go`): when ctask is about to enter direct mode on a workspace that
   already has a live tmux session, the "Continue anyway?" prompt now suggests
   `ctask attach <slug>` as the reattach path. Threaded via
   `PreflightOpts.ActiveLeaseHint` / `LaunchOpts.ActiveLeaseHint`; computed in
   `cmd/entry.go::directModeTmuxHint` (best-effort: silent when no tmux on PATH
   or no session for the workspace). Closes the footgun where a user forgot to
   `export CTASK_SESSION_MODE=persistent` in a second terminal and hit the v0.4
   coexistence prompt without realizing tmux passive-reattach was the intended
   path.

2. Invocation-name in user-facing command hints (`cmd/invocation.go` new,
   `cmd/{persistent,entry,resume,doctor}.go`): the binary name printed in
   bypass / restore / "create one with" suggestions now reflects
   `filepath.Base(os.Args[0])` instead of a hard-coded "ctask". Local-build
   PowerShell users running `.\ctask.exe` see `ctask.exe new <ws> --direct`,
   matching what they need to type. Installed contexts continue to see `ctask`.
   Test seam (`invocationNameOverride`) pins the name to "ctask" in unit tests
   so substring assertions stay stable across Go test binary names. Descriptive
   prose ("ctask persistent mode requires...") and the ssh-remote hint
   (`ssh -t <host> ctask <subcmd>`) intentionally keep the literal "ctask" —
   they refer to the program identity / remote invocation, not the local
   command form. Affected tests: `cmd/{persistent,resume}_test.go` tightened to
   check the full `"<binary> <subcmd> <workspace> --direct"` form.

3. Smoke-checklist fixes (`docs/.../2026-05-08-v0.5.3-smoke-test-checklist.md`):
   six issues caught during the run -- S2 now exports CTASK_SESSION_MODE in
   both terminals (previously only WSL-A had it, which routed WSL-B's
   secondary resume through direct mode instead of passive reattach); O3/A2
   tmux-ls expectations corrected (tmux doesn't emit a literal "(detached)"
   token); P2 expected behavior rewritten (passive reattach detach returns to
   prompt immediately -- AttachExisting calls only shell.AttachSession with
   no PollSessionEnd, the owner is responsible for finalize); A1 no longer
   asks for Ctrl-C in WSL-B; A6 path now uses a glob (was hardcoded to the
   checklist's authoring date, broke on v0.5.1 local-time directory naming);
   M1 PATH-hide rewritten to `$HOME/.local/bin` only (was `:/bin` which is a
   symlink to /usr/bin on usrmerge systems, did not hide tmux) and uses
   `command -v` instead of `which` (which is itself in /usr/bin, unreachable
   under the minimal PATH); M3/M4 reordered so the no-workspace verification
   runs after PATH is restored (was silently failing under minimal PATH);
   T1 wording made "substring match" explicit; T2 wording made N/A
   unambiguous; section 10 split into 10a-10f, each a separate input, to
   work around PSReadLine multi-line paste parsing.
This commit is contained in:
2026-05-14 18:22:27 -04:00
parent 548e292310
commit c204d87b47
12 changed files with 344 additions and 72 deletions
+19 -1
View File
@@ -159,7 +159,15 @@ func CleanupStaleLease(path string, staleAfter time.Duration) (*Lease, error) {
// FormatActiveWarning renders the human-readable warning printed when a
// fresh active lease is detected on session start.
func FormatActiveWarning(l *Lease, now time.Time) string {
//
// hint, when non-empty, is rendered between the "may cause conflicts" line
// and the "Continue anyway?" prompt. Each non-empty line of hint is
// indented with two spaces to match the rest of the block; callers should
// supply plain text (no leading indent, no trailing newline required).
// Used to surface "a tmux session exists; ctask attach <slug> is the
// reattach path" when ctask is about to enter direct mode on a workspace
// that already has a persistent tmux session.
func FormatActiveWarning(l *Lease, now time.Time, hint string) string {
startedAgo := now.Sub(l.StartedAt)
lastSeenAgo := now.Sub(l.LastHeartbeatAt)
@@ -174,6 +182,16 @@ func FormatActiveWarning(l *Lease, now time.Time) string {
fmt.Fprintf(&b, " Last seen: %s ago\n", FormatAgoShort(lastSeenAgo))
b.WriteString("\n")
b.WriteString(" Opening a second session may cause conflicts.\n")
if hint != "" {
b.WriteString("\n")
for _, line := range strings.Split(strings.TrimRight(hint, "\n"), "\n") {
if line == "" {
b.WriteString("\n")
continue
}
fmt.Fprintf(&b, " %s\n", line)
}
}
b.WriteString(" Continue anyway? [y/N] ")
return b.String()
}
+40 -1
View File
@@ -251,7 +251,7 @@ func TestFormatActiveWarning(t *testing.T) {
LastHeartbeatAt: lastSeen,
}
got := FormatActiveWarning(lease, now)
got := FormatActiveWarning(lease, now, "")
for _, want := range []string{
"[ctask] This workspace has an active session:",
@@ -270,6 +270,45 @@ func TestFormatActiveWarning(t *testing.T) {
t.Errorf("FormatActiveWarning missing %q in:\n%s", want, got)
}
}
if strings.Contains(got, "Tip:") || strings.Contains(got, "ctask attach") {
t.Errorf("FormatActiveWarning should not render a hint when none supplied:\n%s", got)
}
}
func TestFormatActiveWarningWithHint(t *testing.T) {
now := time.Date(2026, 4, 21, 16, 45, 10, 0, time.UTC)
lease := &Lease{
SessionID: "warren-desktop-12345-20260421143022",
Hostname: "warren-desktop",
Agent: "claude",
StartedAt: now.Add(-time.Hour),
LastHeartbeatAt: now.Add(-15 * time.Second),
}
hint := "Tip: a tmux session exists for this workspace.\nTo reattach instead of starting a second direct-mode session, run:\n ctask attach ctask-053-smoke"
got := FormatActiveWarning(lease, now, hint)
for _, want := range []string{
"[ctask] This workspace has an active session:",
"Opening a second session may cause conflicts.",
" Tip: a tmux session exists for this workspace.",
" To reattach instead of starting a second direct-mode session, run:",
" ctask attach ctask-053-smoke",
"Continue anyway? [y/N]",
} {
if !strings.Contains(got, want) {
t.Errorf("FormatActiveWarning with hint missing %q in:\n%s", want, got)
}
}
// Hint must appear between the conflict warning and the y/N prompt.
conflictIdx := strings.Index(got, "Opening a second session may cause conflicts.")
tipIdx := strings.Index(got, "Tip: a tmux session exists")
promptIdx := strings.Index(got, "Continue anyway? [y/N]")
if !(conflictIdx < tipIdx && tipIdx < promptIdx) {
t.Errorf("hint placement wrong: conflict=%d tip=%d prompt=%d\nOutput:\n%s",
conflictIdx, tipIdx, promptIdx, got)
}
}
func TestFormatStaleCleanupNoticeRenders(t *testing.T) {
+11 -4
View File
@@ -60,6 +60,12 @@ type LaunchOpts struct {
// workspace is treated as provisional and removed on exit — see
// handleProvisional. Set to false by resume/open/last.
NewlyCreated bool
// ActiveLeaseHint, when non-empty, is forwarded to PreflightOpts so the
// Layer-1 "Continue anyway?" prompt can render a contextual suggestion.
// Populated by the cmd-layer dispatcher when about to enter direct mode
// on a workspace that already has a live tmux session.
ActiveLeaseHint string
}
// manifestStartPath returns the path to the start manifest file.
@@ -99,10 +105,11 @@ const (
func Run(opts LaunchOpts) error {
// ---- Preflight (Layers 3 + 1) ----
preflight, err := PreflightFull(PreflightOpts{
WsDir: opts.WsDir,
Force: opts.Force,
In: os.Stdin,
Out: os.Stderr,
WsDir: opts.WsDir,
Force: opts.Force,
In: os.Stdin,
Out: os.Stderr,
ActiveLeaseHint: opts.ActiveLeaseHint,
})
if err != nil {
fmt.Fprintf(os.Stderr, "[ctask] Warning: preflight check failed: %v\n", err)
+8 -1
View File
@@ -15,6 +15,13 @@ type PreflightOpts struct {
Force bool
In io.Reader
Out io.Writer
// ActiveLeaseHint, when non-empty, is rendered inside the Layer-1
// "Continue anyway?" prompt — between the conflict warning and the
// y/N line. The cmd-layer dispatcher populates it (e.g., when
// entering direct mode on a workspace that has a live tmux session,
// suggest `ctask attach <slug>` as the reattach path).
ActiveLeaseHint string
}
// PreflightResult reports whether the session should proceed and whether an
@@ -98,7 +105,7 @@ func runActiveLeaseCheck(opts PreflightOpts) (bool, bool, error) {
if opts.Force {
return true, true, nil
}
fmt.Fprint(opts.Out, FormatActiveWarning(existing, time.Now()))
fmt.Fprint(opts.Out, FormatActiveWarning(existing, time.Now(), opts.ActiveLeaseHint))
if !ConfirmYN(opts.In, opts.Out, "", false) {
return false, false, nil
}