Files
ctask/cmd/last.go
T
typebasedio 0c1f03ba3a fix(v0.4.1): route all workspace commands through SearchRoots
Every resolver, lister, and most-recent caller now passes
config.SearchRoots() so CTASK_PROJECT_ROOT is searched alongside
CTASK_ROOT. Commands use ws.Root when rendering relative paths or
session env vars so displays and CTASK_ROOT exports are correct for
workspaces living under CTASK_PROJECT_ROOT.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 17:54:58 -04:00

47 lines
1.1 KiB
Go

package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/warrenronsiek/ctask/internal/config"
"github.com/warrenronsiek/ctask/internal/workspace"
)
var lastCmd = &cobra.Command{
Use: "last",
Short: "Resume the most recently updated workspace (task or project)",
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: runLast,
}
var (
lastShell bool
lastAgent string
lastForce bool
)
func init() {
lastCmd.Flags().BoolVar(&lastShell, "shell", false, "Open shell instead of agent")
lastCmd.Flags().StringVarP(&lastAgent, "agent", "a", "", "Override agent command")
lastCmd.Flags().BoolVar(&lastForce, "force", false, "Skip active-session and stale-workspace warnings")
rootCmd.AddCommand(lastCmd)
}
func runLast(cmd *cobra.Command, args []string) error {
roots := config.SearchRoots()
best, err := workspace.MostRecentActive(roots)
if err != nil {
return err
}
if best == nil {
fmt.Fprintln(os.Stderr, "No active workspaces found.")
os.Exit(1)
}
return doResume(best.Meta.Slug, false, lastShell, lastForce, lastAgent)
}