refactor(v0.3): consolidate cmd/last and cmd/delete onto MostRecentActive
Both commands now call workspace.MostRecentActive(root) directly
instead of inlining a ListWorkspaces scan + max-by-UpdatedAt loop.
The cross-type behavior is identical to before this commit (it
was already correct after the v0.3 union fix), but it is now
locked down by the focused unit tests added in the previous
commit and there is no duplicated selection logic.
The (nil, nil) "no active workspaces" return is mapped to:
- cmd/last: prints "No active workspaces found." and exits 1
- cmd/delete: silently skips the "most recent" note (the user
is deleting some specific workspace by name; the
note was always best-effort)
This commit is contained in:
+3
-19
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
var lastCmd = &cobra.Command{
|
||||
Use: "last",
|
||||
Short: "Resume the most recently updated workspace",
|
||||
Short: "Resume the most recently updated workspace (task or project)",
|
||||
Args: cobra.NoArgs,
|
||||
SilenceUsage: true,
|
||||
RunE: runLast,
|
||||
@@ -31,30 +31,14 @@ func init() {
|
||||
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.
|
||||
results, err := workspace.ListWorkspaces(root, workspace.ListOpts{
|
||||
IncludeArchived: false,
|
||||
Limit: 0,
|
||||
Type: workspace.TypeAny,
|
||||
})
|
||||
best, err := workspace.MostRecentActive(root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(results) == 0 {
|
||||
if best == nil {
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user