NewViewCommand creates the view command.
()
| 31 | |
| 32 | // NewViewCommand creates the view command. |
| 33 | func NewViewCommand() *cobra.Command { |
| 34 | cmd := &cobra.Command{ |
| 35 | Use: "view <run-id-or-url>", |
| 36 | Short: "Render unified timeline and safe outputs for a workflow run", |
| 37 | Long: `Download artifacts for a workflow run and render a unified, chronologically |
| 38 | ordered activity timeline together with any safe outputs in the console. |
| 39 | |
| 40 | The timeline merges events from three sources: |
| 41 | - MCP Gateway logs (gateway.jsonl / rpc-messages.jsonl) |
| 42 | - AWF Firewall logs (audit.jsonl) |
| 43 | - Agent session logs (events.jsonl) |
| 44 | |
| 45 | The result simulates what you would see when watching a Copilot CLI session |
| 46 | live, providing a readable, complete log of all agentic activity, followed |
| 47 | by any safe outputs created during the run (e.g., issues, pull requests, |
| 48 | comments) and a link to the GitHub Actions workflow run page. |
| 49 | |
| 50 | The run argument accepts the same formats as the "audit" command: |
| 51 | - A numeric run ID (e.g., 1234567890) |
| 52 | - A GitHub Actions run URL (e.g., https://github.com/owner/repo/actions/runs/1234567890) |
| 53 | - A GitHub Enterprise run URL |
| 54 | |
| 55 | Artifacts are downloaded to the default logs directory and cached; repeated |
| 56 | invocations for the same run ID will read from the local cache without |
| 57 | re-downloading.`, |
| 58 | Example: ` ` + string(constants.CLIExtensionPrefix) + ` view 1234567890 |
| 59 | ` + string(constants.CLIExtensionPrefix) + ` view https://github.com/owner/repo/actions/runs/1234567890 |
| 60 | ` + string(constants.CLIExtensionPrefix) + ` view 1234567890 --repo owner/repo |
| 61 | ` + string(constants.CLIExtensionPrefix) + ` view 1234567890 -o ./my-logs |
| 62 | ` + string(constants.CLIExtensionPrefix) + ` view 1234567890 -v`, |
| 63 | Args: cobra.ExactArgs(1), |
| 64 | Hidden: true, |
| 65 | RunE: func(cmd *cobra.Command, args []string) error { |
| 66 | verbose, _ := cmd.Flags().GetBool("verbose") |
| 67 | outputDir, _ := cmd.Flags().GetString("output") |
| 68 | repoFlag, _ := cmd.Flags().GetString("repo") |
| 69 | |
| 70 | runIDOrURL := args[0] |
| 71 | |
| 72 | components, err := parser.ParseRunURLExtended(runIDOrURL) |
| 73 | if err != nil { |
| 74 | return err |
| 75 | } |
| 76 | |
| 77 | // Apply --repo flag when owner/repo were not inferred from a URL. |
| 78 | if repoFlag != "" && components.Owner == "" { |
| 79 | parts := strings.SplitN(repoFlag, "/", 2) |
| 80 | if len(parts) != 2 || parts[0] == "" || parts[1] == "" { |
| 81 | return fmt.Errorf("invalid repository format %q: expected 'owner/repo'", repoFlag) |
| 82 | } |
| 83 | components.Owner = parts[0] |
| 84 | components.Repo = parts[1] |
| 85 | } |
| 86 | |
| 87 | if outputDir == "" { |
| 88 | outputDir = defaultLogsOutputDir |
| 89 | } |
| 90 |