Skip to content

Conversation

@BagToad
Copy link
Member

@BagToad BagToad commented Sep 23, 2025

This introduces the foundational implementation for the new agent-task command group in the GitHub CLI, enabling users to interact with coding agent tasks.

The changes include the creation of the core command, authentication checks, unit tests, and the initial implementation of a Copilot API client for agent tasks. Additionally, there are minor enhancements to internal API types and updates to dependencies.

gh agent-task is in preview and is subject to change without notice.

The agent-task commandset also ships with the following aliases for convenience:

  • gh agent-tasks
  • gh agent
  • gh agents

489623192-0565e1ea-b4e5-4fbe-a4e1-5f54c6ef0404

BagToad and others added 30 commits August 27, 2025 12:23
Introduces a new `agent-task` command under pkg/cmd/agent with strict OAuth (device flow) token validation. Includes comprehensive tests for token source and host validation, and registers the command in the root command set.
Changed the RunE function of the agent-task command to display help output instead of returning nil, improving user guidance when the command is run without arguments.
Replaces require.Equal with require.Empty in TestOAuthTokenAccepted for improved clarity when checking for empty output.
Consolidates multiple individual test functions into a single table-driven test, improving maintainability and readability. This change makes it easier to add new test cases and ensures consistent test structure for agent task command authentication scenarios.
…exits-if-user-not-authenticated-with-oauth

Introduce `gh agent-task`
Introduces a new 'list' subcommand under agent-task for listing agent tasks. Implements a Copilot API client for fetching agent sessions and hydrating them with pull request data. Updates PullRequest and PRRepository types to support new fields. Adds dependencies for msgpack and tagparser.

Co-Authored-By: Babak K. Shandiz <babakks@github.com>
Renames the import of the shared package to 'prShared' and updates its usage in list.go to avoid naming conflicts and improve code clarity.
Simplifies logic for filtering sessions to only include those with valid pull request and repository data. This reduces nested conditionals and improves code readability.
Moves CAPI client initialization to a deferred function in ListOptions, simplifying command setup and improving testability. Updates tests to use the new client initialization pattern and adds more comprehensive test cases for session listing.
Cleaned up the sessionPullRequest struct by deleting unused commented-out fields related to Author and MergedBy.
Renamed 'Sessions' to 'result' for clarity and consistency in the ListSessionsForViewer method when hydrating session pull requests.
Changed the API query from 'FetchPRs' to 'FetchPRsForAgentTaskSessions' in hydrateSessionPullRequests to match updated backend endpoint.
Simplified error handling by inlining the encoder.Encode call and removing redundant comments for improved code clarity.
Replaces linear search with a map for associating sessions with pull requests, improving performance and simplifying code in hydrateSessionPullRequests.
Moved the session state color selection logic from list.go to a new shared/display.go file as ColorFuncForSessionState. This improves code reuse and maintainability by centralizing the color mapping for session states.
…s-with-table-of-the-users-agent-sessions

Introduce `gh agent-task list`
Introduces ListSessionsForRepo to CapiClient and CAPIClient, enabling listing agent sessions for a specific repository. Updates the list command and tests to support repo override and repo-scoped session queries, including error handling and test coverage for repo resolution.
Introduces a --limit flag to control the maximum number of agent tasks fetched. Validates that the limit is greater than zero and updates tests to cover custom and invalid limit scenarios.
Updates the help text for the --limit flag in the agent-task list command to display the default value, improving clarity for users.
Introduces a --web flag to the agent-task list command, allowing users to open the agent tasks page in their browser. Updates tests to cover the new flag and browser interaction.
Updated listRun to ignore errors from BaseRepo resolution and proceed when possible. Adjusted tests to reflect that repo resolution errors no longer surface, improving robustness when repo information is ambiguous.
…-flag' into kw/1003-gh-agent-task-list-respects--l--limit
Removes unnecessary nil check for Factory before assigning BaseRepo in the agent-task list command. This streamlines the code since Factory is always expected to be non-nil.
Replaces explicit duration parsing with direct multiplication for calculating a timestamp 6 hours ago in Test_listRun, improving code clarity.
Added a comment to clarify why the error from opts.BaseRepo() is ignored in listRun. This provides context for handling cases when the current working directory is not a repo and --repo is not set.
Replaces plain output with a NoResultsError in listRun when no agent tasks are found. Updates related tests to expect the error instead of output, improving error handling consistency.
Introduces a test to verify that passing a negative value to the --limit flag in the agent-task list command returns the expected error message.
Added a comment explaining that the web GUI does not currently support filtering by repo, so the agents dashboard is opened without arguments. Notes future improvement if repo filtering becomes available.
Added a test case to ensure that web mode in listRun uses the global URL even when the --repo flag is set. This improves coverage for scenarios where both web mode and repo are specified.
Signed-off-by: Babak K. Shandiz <babakks@github.com>
…dAt`

Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
`gh agent-task view`: display session error if any
…JSON

Signed-off-by: Babak K. Shandiz <babakks@github.com>
…ent-task-create

`gh agent-task create`: return proper error message when resp is not a JSON
Copilot AI review requested due to automatic review settings September 23, 2025 15:05
@BagToad BagToad requested a review from a team as a code owner September 23, 2025 15:05
@BagToad BagToad requested a review from babakks September 23, 2025 15:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a comprehensive gh agent-task command set, adding functionality to create, list, and view GitHub Copilot agent tasks through the CLI. The main purpose is to provide users with command-line access to manage agent tasks that were previously only available through the web interface.

Key changes include:

  • Complete agent-task command infrastructure with create, list, and view subcommands
  • CAPI client for communicating with GitHub's Copilot Agent API
  • Log rendering system for displaying agent session logs with proper formatting
  • Comprehensive test coverage and mock implementations

Reviewed Changes

Copilot reviewed 34 out of 35 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/cmd/root/root.go Registers the new agent-task command in the CLI root
pkg/cmd/pr/shared/finder.go Enhances PR URL parsing to support additional path components and adds full reference parsing
pkg/cmd/pr/shared/finder_test.go Adds comprehensive tests for new PR parsing functionality
pkg/cmd/pr/edit/edit.go Updates PR URL parsing call signature
pkg/cmd/agent-task/ Complete agent-task command implementation with subcommands, CAPI client, and supporting utilities

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

babakks and others added 3 commits September 23, 2025 16:15
Copy link
Member

@babakks babakks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

@BagToad BagToad merged commit 7ff84cf into trunk Sep 23, 2025
11 checks passed
@BagToad BagToad deleted the github-cli-epic-990 branch September 23, 2025 15:46
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Sep 26, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | minor | `v2.79.0` -> `v2.80.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>cli/cli (cli/cli)</summary>

### [`v2.80.0`](https://github.com/cli/cli/releases/tag/v2.80.0): GitHub CLI 2.80.0

[Compare Source](cli/cli@v2.79.0...v2.80.0)

#### :copilot: Manage GitHub Copilot Coding Agent From the GitHub CLI

This GitHub CLI release introduces the `agent-task` commandset for managing [coding agent tasks](https://docs.github.com/en/copilot/concepts/agents/coding-agent/about-coding-agent) in `gh`:

- Create tasks: `gh agent-task create "refactor the codebase"`
- List all your tasks: `gh agent-task list`
- View task details: `gh agent-task view 1234`
- View the task log in real-time: `gh agent-task view 1234 --log --follow`

For more information about command line flags and arguments, run `gh agent-task <command> --help`.

The `agent-task` commandset also ships with the following aliases for convenience:

- `gh agent-tasks`
- `gh agent`
- `gh agents`

ℹ️ *The `agent-task` commandset is in preview and is subject to change without notice*.

Got feedback? Let us know what you like or don't like [in an issue](https://github.com/cli/cli/issues/new?template=feedback.md) ❤️

#### What's Changed

##### ✨ Features

- `gh agent-task` commandset by [@&#8203;BagToad](https://github.com/BagToad) and [@&#8203;babakks](https://github.com/babakks) in [#&#8203;11797](cli/cli#11797)

##### 🐛 Fixes

- Pin release runner image to Windows 2022 by [@&#8203;babakks](https://github.com/babakks) in [#&#8203;11799](cli/cli#11799)

**Full Changelog**: <cli/cli@v2.79.0...v2.80.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMjcuMiIsInVwZGF0ZWRJblZlciI6IjQxLjEyNy4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
@liskin
Copy link

liskin commented Oct 2, 2025

Do I need any additional OAuth scopes to use this?

$ gh agent-task list
failed to list sessions: 403 Forbidden

@babakks
Copy link
Member

babakks commented Oct 3, 2025

@liskin Can you please create a separate issue for your problem?

Also please make sure to include the scopes of your token (you can use gh auth status to see your scopes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants