feat: ctask last command to resume most recently updated workspace
Scans non-archived workspaces, finds highest updated_at, delegates to resume flow with session hooks. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
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 and find the most recently updated
|
||||
results, err := workspace.ListWorkspaces(root, workspace.ListOpts{
|
||||
IncludeArchived: false,
|
||||
Limit: 0,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user