Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 4, 2025

Implements a new /ai <prompt> command that creates GitHub Copilot Agent tasks directly from issue and PR comments.

Overview

This PR adds support for the /ai command which allows users with write access to create GitHub Copilot Agent tasks on the repository. The command intelligently handles context based on where it's invoked:

  • On Pull Requests: Automatically includes the PR URL as context and, when both source and target branches are in the same repository, targets the source branch for changes
  • On Issues: Creates an agent task with the provided prompt

Usage Examples

/ai fix the failing tests in this PR
/ai add documentation for the authentication module

Implementation Details

For PR comments, the command:

  1. Fetches PR information to get the URL
  2. Prepends the prompt with Related: <PR_URL> for context
  3. Determines if both branches are in the same repo
  4. Calls github.createAgent(prompt, sourceBranch) to create the task on the appropriate branch

For issue comments, it simply creates an agent task with the provided prompt.

For example, if a user runs /ai fix the errors in the pr on PR #33 that's merging branch bump into master, the command calls:

createAgent(
  "Related: https://github.com/PrismarineJS/prismarine-repo-actions/pull/33.\nfix the errors in the pr",
  "bump"
)

Changes

  • Updated gh-helpers dependency from ^0.3.1 to ^1.1.0 to access the new createAgent API
  • Added src/commands/ai.js implementing the command handler
  • Registered the command in src/index.js
  • Added comprehensive tests covering various scenarios (valid prompt, missing prompt, permission checks)
  • Updated README.md with command documentation and configuration options

Testing

All tests pass (11/11), including 3 new tests specifically for the /ai command:

  • ✅ Command works with valid prompt and permissions
  • ✅ Command fails gracefully when no prompt is provided
  • ✅ Command is properly restricted by permissions

Closes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>Add an /ai command to run GH Agents</issue_title>
<issue_description>Create an /ai <prompt> command runnable by WRITE_ROLES (comment.authorHasWrite) that calls gh-helpers's new api:

The new API allows users to programmatically create Copilot Agent tasks with a single function call:

```javascript
const github = require('gh-helpers')()

// Create an agent task on the default branch
github.createAgent('Fix the bug in the authentication module')

// Create an agent task on a specific branch
github.createAgent('Add new feature X', 'feature-branch')
```

try to pass in the current PR (or issue) URL as context.

if the comment was made in a PR and both the target and the source branch are inside the current repo, pass the source branch as the 2nd param to createAgent(prompt, branch?).

for example:
if you have a 'master' branch and a PR #33 has been open, it's trying to merge 'bump' into 'master', and user runs /ai fix the errors in the pr, you pass

createAgent(
  "Related: https://github.com/PrismarineJS/prismarine-repo-actions/pull/33.\nfix the errors in the pr",
  "bump"
)
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

Fixes #35

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link

socket-security bot commented Oct 4, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedgh-helpers@​0.3.5 ⏵ 1.1.0100 +26100100 +22100 +24100

View full report

Copilot AI and others added 2 commits October 4, 2025 14:53
@Copilot Copilot AI changed the title [WIP] Add an /ai command to run GH Agents Add /ai command to run GitHub Copilot Agents Oct 4, 2025
@Copilot Copilot AI requested a review from extremeheat October 4, 2025 14:56
Copilot finished work on behalf of extremeheat October 4, 2025 14:56
@extremeheat extremeheat marked this pull request as ready for review October 4, 2025 14:56
Updated token secret from PAT_TOKEN to PAT_PASSWORD in workflow.
@extremeheat extremeheat merged commit 3e4d079 into master Oct 5, 2025
3 checks passed
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.

Add an /ai command to run GH Agents

2 participants