Repository: cli/cli
File: pkg/cmd/agent-task/list/list.go (Go)

Code before:
	cmd.Flags().IntVarP(&opts.Limit, "limit", "L", defaultLimit, fmt.Sprintf("Maximum number of agent tasks to fetch (default %d)", defaultLimit))
	cmd.Flags().BoolVarP(&opts.Web, "web", "w", false, "Open agent tasks in the browser")

	opts.CapiClient = func() (*capi.CAPIClient, error) {
		cfg, err := opts.Config()
		if err != nil {
			return nil, err
		}
		httpClient, err := f.HttpClient()
		if err != nil {
			return nil, err
		}
		authCfg := cfg.Authentication()
		return capi.NewCAPIClient(httpClient, authCfg), nil
	}

	return cmd
}

func listRun(opts *ListOptions) error {
	if opts.Web {
		const webURL = "https://github.com/copilot/agents"
		if opts.IO.IsStdoutTTY() {
			fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(webURL))
		}
		return opts.Browser.Browse(webURL)
	}

	if opts.Limit <= 0 {
		opts.Limit = defaultLimit
	}

	capiClient, err := opts.CapiClient()
	if err != nil {
		return err
	}

	opts.IO.StartProgressIndicatorWithLabel("Fetching agent tasks...")
	defer opts.IO.StopProgressIndicator()
	var sessions []*capi.Session
	ctx := context.Background()

	var repo ghrepo.Interface
	if opts.BaseRepo != nil {
		repo, _ = opts.BaseRepo()
	}

	if repo != nil && repo.RepoOwner() != "" && repo.RepoName() != "" {
		sessions, err = capiClient.ListSessionsForRepo(ctx, repo.RepoOwner(), repo.RepoName(), opts.Limit)
		if err != nil {
			return err

Review comment (suggestion):
Maybe with a comment that says there's no repo-specific URL so we ignore the base repo.

```suggestion
		// Currently the web GUI does not support filtering based on repo, so we
		// just open the agents dashboard with no args.
		const webURL = "https://github.com/copilot/agents"
```

Code after:
	cmd.Flags().IntVarP(&opts.Limit, "limit", "L", defaultLimit, fmt.Sprintf("Maximum number of agent tasks to fetch (default %d)", defaultLimit))
	cmd.Flags().BoolVarP(&opts.Web, "web", "w", false, "Open agent tasks in the browser")

	opts.CapiClient = func() (*capi.CAPIClient, error) {
		cfg, err := opts.Config()
		if err != nil {
			return nil, err
		}
		httpClient, err := f.HttpClient()
		if err != nil {
			return nil, err
		}
		authCfg := cfg.Authentication()
		return capi.NewCAPIClient(httpClient, authCfg), nil
	}

	return cmd
}

func listRun(opts *ListOptions) error {
	if opts.Web {
		// Currently the web GUI does not have a page that supports filtering
		// based on repo, so we just open the agents dashboard with no args.
		// If that page is ever added in the future, we should route to that
		// page instead of the global one when --repo is set.
		const webURL = "https://github.com/copilot/agents"
		if opts.IO.IsStdoutTTY() {
			fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(webURL))
		}
		return opts.Browser.Browse(webURL)
	}

	if opts.Limit <= 0 {
		opts.Limit = defaultLimit
	}

	capiClient, err := opts.CapiClient()
	if err != nil {
		return err
	}

	opts.IO.StartProgressIndicatorWithLabel("Fetching agent tasks...")
	defer opts.IO.StopProgressIndicator()
	var sessions []*capi.Session
	ctx := context.Background()

	var repo ghrepo.Interface
	if opts.BaseRepo != nil {
		// We swallow this error because when CWD is not a repo and
		// the --repo flag is not set, we use the global/user session listing.
		repo, _ = opts.BaseRepo()