package cmd import ( "fmt" "path/filepath" "time" "github.com/spf13/cobra" "github.com/warrenronsiek/ctask/internal/config" "github.com/warrenronsiek/ctask/internal/session" "github.com/warrenronsiek/ctask/internal/workspace" ) var openCmd = &cobra.Command{ Use: "open ", Short: "Open a workspace directory without launching the agent", Args: cobra.ExactArgs(1), SilenceUsage: true, RunE: runOpen, } var ( openAll bool openForce bool ) func init() { openCmd.Flags().BoolVarP(&openAll, "all", "a", false, "Include archived workspaces in query resolution") openCmd.Flags().BoolVar(&openForce, "force", false, "Skip active-session and stale-workspace warnings") rootCmd.AddCommand(openCmd) } func runOpen(cmd *cobra.Command, args []string) error { root := config.ResolveRoot() ws := resolveOne(root, args[0], openAll) // Update updated_at 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) } envVars := config.EnvVars(ws.Meta.Slug, ws.Meta.Mode, root, ws.Path, ws.Meta.Category, workspace.EffectiveType(ws.Meta)) return session.Run(session.LaunchOpts{ WsDir: ws.Path, EnvVars: envVars, Agent: ws.Meta.Agent, Mode: ws.Meta.Mode, Slug: ws.Meta.Slug, Shell: true, // open always launches shell Force: openForce, }) }