c204d87b47
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.
91 lines
2.8 KiB
Go
91 lines
2.8 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/warrenronsiek/ctask/internal/config"
|
|
"github.com/warrenronsiek/ctask/internal/shell"
|
|
"github.com/warrenronsiek/ctask/internal/workspace"
|
|
)
|
|
|
|
var resumeCmd = &cobra.Command{
|
|
Use: "resume <query>",
|
|
Short: "Reopen an existing workspace and launch the agent",
|
|
Args: cobra.ExactArgs(1),
|
|
SilenceUsage: true,
|
|
RunE: runResume,
|
|
}
|
|
|
|
var (
|
|
resumeContainer bool
|
|
resumeShell bool
|
|
resumeAgent string
|
|
resumeForce bool
|
|
resumeDirect bool
|
|
)
|
|
|
|
func init() {
|
|
resumeCmd.Flags().BoolVar(&resumeContainer, "container", false, "Resume in container mode (deferred)")
|
|
resumeCmd.Flags().BoolVar(&resumeShell, "shell", false, "Open shell instead of agent")
|
|
resumeCmd.Flags().StringVarP(&resumeAgent, "agent", "a", "", "Override agent command")
|
|
resumeCmd.Flags().BoolVar(&resumeForce, "force", false, "Skip active-session and stale-workspace warnings")
|
|
resumeCmd.Flags().BoolVar(&resumeDirect, "direct", false, "Bypass persistent session mode for this command")
|
|
resumeCmd.ValidArgsFunction = completeWorkspaces(completionActive)
|
|
rootCmd.AddCommand(resumeCmd)
|
|
}
|
|
|
|
func runResume(cmd *cobra.Command, args []string) error {
|
|
return doResume(args[0], resumeContainer, resumeShell, resumeForce, resumeAgent, resumeDirect)
|
|
}
|
|
|
|
// doResume is the shared resume logic used by both `resume` and `last`.
|
|
// It preserves resume's existing archive-inclusive resolution and
|
|
// restore-hint behavior, then delegates to runWorkspaceEntry for the
|
|
// persistent-vs-direct decision and tmux dispatch.
|
|
func doResume(query string, container, useShell, force bool, agentOverride string, directFlag bool) error {
|
|
if container {
|
|
fmt.Println(shell.ContainerNotice())
|
|
return nil
|
|
}
|
|
|
|
roots := config.SearchRoots()
|
|
// resume resolves archived-inclusive so we can give a helpful hint when
|
|
// the user resumes an archived workspace (v0.5.2 behavior — preserved).
|
|
ws := resolveOne(roots, query, true)
|
|
|
|
if ws.Meta.Status == "archived" {
|
|
fmt.Fprintf(os.Stderr,
|
|
"[ctask] error: workspace %q is archived\n\nTo restore it:\n %s restore %s\n",
|
|
query, invocationName(), query)
|
|
return fmt.Errorf("workspace archived")
|
|
}
|
|
|
|
// updated_at bump (existing v0.4 behavior).
|
|
now := time.Now().UTC().Truncate(time.Second)
|
|
ws.Meta.UpdatedAt = now
|
|
metaPath := filepath.Join(ws.Path, "task.yaml")
|
|
if err := workspace.WriteMetaLocked(metaPath, ws.Meta); err != nil {
|
|
return fmt.Errorf("updating metadata: %w", err)
|
|
}
|
|
|
|
agent := agentOverride
|
|
if agent == "" {
|
|
agent = ws.Meta.Agent
|
|
}
|
|
|
|
return runWorkspaceEntry(WorkspaceEntryOptions{
|
|
WsPath: ws.Path,
|
|
WsRoot: ws.Root,
|
|
WsMeta: ws.Meta,
|
|
Agent: agent,
|
|
Shell: useShell,
|
|
Force: force,
|
|
Direct: directFlag,
|
|
CommandName: "resume",
|
|
})
|
|
}
|