| 132 | } |
| 133 | |
| 134 | func viewRun(opts *ViewOptions) error { |
| 135 | capiClient, err := opts.CapiClient() |
| 136 | if err != nil { |
| 137 | return err |
| 138 | } |
| 139 | |
| 140 | ctx := context.Background() |
| 141 | cs := opts.IO.ColorScheme() |
| 142 | |
| 143 | opts.IO.StartProgressIndicatorWithLabel("Fetching agent session...") |
| 144 | defer opts.IO.StopProgressIndicator() |
| 145 | |
| 146 | var session *capi.Session |
| 147 | |
| 148 | if opts.SessionID != "" { |
| 149 | sess, err := capiClient.GetSession(ctx, opts.SessionID) |
| 150 | if err != nil { |
| 151 | if errors.Is(err, capi.ErrSessionNotFound) { |
| 152 | fmt.Fprintln(opts.IO.ErrOut, "session not found") |
| 153 | return cmdutil.SilentError |
| 154 | } |
| 155 | return err |
| 156 | } |
| 157 | |
| 158 | opts.IO.StopProgressIndicator() |
| 159 | |
| 160 | if opts.Web { |
| 161 | var webURL string |
| 162 | if sess.PullRequest != nil { |
| 163 | webURL = fmt.Sprintf("%s/agent-sessions/%s", sess.PullRequest.URL, url.PathEscape(sess.ID)) |
| 164 | } else { |
| 165 | // Currently the web Copilot Agents home GUI does not support focusing |
| 166 | // on a given session, so we should just navigate to the home page. |
| 167 | webURL = capi.AgentsHomeURL |
| 168 | } |
| 169 | |
| 170 | if opts.IO.IsStdoutTTY() { |
| 171 | fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(webURL)) |
| 172 | } |
| 173 | return opts.Browser.Browse(webURL) |
| 174 | } |
| 175 | |
| 176 | session = sess |
| 177 | } else { |
| 178 | var prID int64 |
| 179 | var prURL string |
| 180 | |
| 181 | if opts.SelectorArg != "" { |
| 182 | // Finder does not support the PR/issue reference format (e.g. owner/repo#123) |
| 183 | // so we need to check if the selector arg is a reference and fetch the PR |
| 184 | // directly. |
| 185 | if repo, num, err := prShared.ParseFullReference(opts.SelectorArg); err == nil { |
| 186 | // Since the selector was a reference (i.e. without hostname data), we need to |
| 187 | // check the base repo to get the hostname. |
| 188 | baseRepo, err := opts.BaseRepo() |
| 189 | if err != nil { |
| 190 | return err |
| 191 | } |