Files
ctask/cmd/last.go
T
typebasedio bfe89d830c feat(v0.3): add Projects filter to ListWorkspaces; fix last/delete
ListOpts gains a Projects bool that filters by EffectiveType.
Default behavior (Projects: false) now returns tasks only --
this is a deliberate semantic change that supports the new
'ctask list' (tasks) vs 'ctask list --projects' (projects)
spec.

The change silently regresses two cmd-level callers that scan
for "the most recently updated workspace": cmd/last.go (used by
'ctask last') and cmd/delete.go (used to print the "this was
your most recent workspace" note). Both are fixed by unioning a
tasks-scan with a projects-scan, so 'last' and 'delete' continue
to consider both types.

Test helper createTestWorkspaceTyped allows setting an explicit
type (or "" to simulate a v0.2 workspace with no type field).
2026-04-10 14:43:28 -04:00

70 lines
1.6 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",
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: runLast,
}
var (
lastShell bool
lastAgent string
)
func init() {
lastCmd.Flags().BoolVar(&lastShell, "shell", false, "Open shell instead of agent")
lastCmd.Flags().StringVarP(&lastAgent, "agent", "a", "", "Override agent command")
rootCmd.AddCommand(lastCmd)
}
func runLast(cmd *cobra.Command, args []string) error {
root := config.ResolveRoot()
// Scan all non-archived workspaces (tasks AND projects) and find the most
// recently updated. v0.3: ListWorkspaces filters by type, so we union the
// two type buckets here so `last` keeps working for both.
tasks, err := workspace.ListWorkspaces(root, workspace.ListOpts{
IncludeArchived: false,
Limit: 0,
})
if err != nil {
return err
}
projects, err := workspace.ListWorkspaces(root, workspace.ListOpts{
IncludeArchived: false,
Projects: true,
Limit: 0,
})
if err != nil {
return err
}
results := append(tasks, projects...)
if len(results) == 0 {
fmt.Fprintln(os.Stderr, "No active workspaces found.")
os.Exit(1)
}
// Find the one with the most recent updated_at
best := results[0]
for _, r := range results[1:] {
if r.Meta.UpdatedAt.After(best.Meta.UpdatedAt) {
best = r
}
}
// Delegate to resume logic using the slug
return doResume(best.Meta.Slug, false, lastShell, lastAgent)
}