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

Code before:
			// directly.
			if repo, num, err := prShared.ParseFullReference(opts.SelectorArg); err == nil {
				// Since the selector was a reference (i.e. without hostname data), we need to
				// check the base repo to get the hostname.
				baseRepo, err := opts.BaseRepo()
				if err != nil {
					return err
				}

				hostname := baseRepo.RepoHost()
				if hostname != ghinstance.Default() {
					return fmt.Errorf("agent tasks are not supported on this host: %s", hostname)
				}

				resourceID, err = capiClient.GetPullRequestDatabaseID(ctx, hostname, repo.RepoOwner(), repo.RepoName(), num)
				if err != nil {
					return fmt.Errorf("failed to fetch pull request: %w", err)
				}
			}
		}

		if resourceID == 0 {
			findOptions := prShared.FindOptions{
				Selector: opts.SelectorArg,
				Fields:   []string{"id", "url", "fullDatabaseId"},
			}

			pr, repo, err := opts.Finder.Find(findOptions)
			if err != nil {
				return err
			}

			if repo.RepoHost() != ghinstance.Default() {
				return fmt.Errorf("agent tasks are not supported on this host: %s", repo.RepoHost())
			}

			databaseID, err := strconv.ParseInt(pr.FullDatabaseID, 10, 64)
			if err != nil {
				return fmt.Errorf("failed to parse pull request: %w", err)
			}

			resourceID = databaseID
		}

		// TODO(babakks): currently we just fetch a pre-defined number of
		// matching sessions to avoid hitting the API too many times, but it's
		// technically possible for a PR to be associated with lots of sessions
		// (i.e. above our selected limit).
		sessions, err := capiClient.ListSessionsByResourceID(ctx, "pull", resourceID, defaultLimit)
		if err != nil {
			return fmt.Errorf("failed to list sessions for pull request: %w", err)

Review comment (suggestion):
💭 I think something like this is what you meant to describe here, since there is indeed a web page for a specific session: 

```suggestion
				// Currently, there is no Agents web UI that supports focusing
				// on a repository. Since we do not have the PR URL required navigate
				// to a specific session, we must navigate to the Agent's home page instead.
				webURL = capi.AgentsHomeURL
```

Code after:

	opts.IO.StartProgressIndicatorWithLabel("Fetching agent session...")
	defer opts.IO.StopProgressIndicator()

	var session *capi.Session

	if opts.SessionID != "" {
		sess, err := capiClient.GetSession(ctx, opts.SessionID)
		if err != nil {
			if errors.Is(err, capi.ErrSessionNotFound) {
				fmt.Fprintln(opts.IO.ErrOut, "session not found")
				return cmdutil.SilentError
			}
			return err
		}

		opts.IO.StopProgressIndicator()

		if opts.Web {
			var webURL string
			if sess.PullRequest != nil {
				webURL = fmt.Sprintf("%s/agent-sessions/%s", sess.PullRequest.URL, url.PathEscape(sess.ID))
			} else {
				// Currently the web Copilot Agents home GUI does not support focusing
				// on a given session, so we should just navigate to the home page.
				webURL = capi.AgentsHomeURL
			}

			if opts.IO.IsStdoutTTY() {
				fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(webURL))
			}
			return opts.Browser.Browse(webURL)
		}

		session = sess
	} else {
		var resourceID int64
		var prURL string

		if opts.SelectorArg != "" {
			// Finder does not support the PR/issue reference format (e.g. owner/repo#123)
			// so we need to check if the selector arg is a reference and fetch the PR
			// directly.
			if repo, num, err := prShared.ParseFullReference(opts.SelectorArg); err == nil {
				// Since the selector was a reference (i.e. without hostname data), we need to
				// check the base repo to get the hostname.
				baseRepo, err := opts.BaseRepo()
				if err != nil {
					return err
				}