Skip to content

feat(github): auto-extract issue prompt on assignment and opened events#19934

Closed
dzianisv wants to merge 2 commits intoanomalyco:devfrom
dzianisv:feat/github-issue-assignment
Closed

feat(github): auto-extract issue prompt on assignment and opened events#19934
dzianisv wants to merge 2 commits intoanomalyco:devfrom
dzianisv:feat/github-issue-assignment

Conversation

@dzianisv
Copy link
Copy Markdown

Summary

  • Auto-extract issue title, body, and labels as the prompt when issues events fire with assigned or opened actions
  • Removes the hard requirement for PROMPT env var on these issue actions
  • Enables a "assign to bot → it works on it" workflow

Changes

packages/opencode/src/cli/cmd/github.ts

The getUserPrompt() function previously required the PROMPT environment variable for all issues events. Now:

  1. If PROMPT is set, it's used as an override (backward compatible)
  2. For assigned and opened actions: auto-constructs prompt from issue.title, issue.body, and issue.labels
  3. For other actions (e.g. labeled, closed): still requires PROMPT

The downstream issue handling flow (branch creation, work, PR/comment) is unchanged.

Testing

  • The change is self-contained in getUserPrompt() and doesn't affect any other code paths
  • PROMPT env var override still works for all event types (backward compatible)
  • The assigned and opened paths construct the same prompt format that PROMPT users would provide manually

Refs #19926

When an issues event fires with action 'assigned' or 'opened', the
handler now automatically constructs the prompt from the issue title,
body, and labels instead of requiring the PROMPT env var.

This enables a natural workflow: assign an issue to the opencode bot
and it picks up the work automatically without needing a /opencode
comment.

The PROMPT env var is still respected as an override, and is still
required for other issue actions (e.g. labeled, closed).

Refs: anomalyco#19926
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

Extract the issue prompt building logic into an exported pure function
buildIssuePrompt() and add 11 unit tests covering:
- title + body formatting
- null/undefined/empty body fallback
- string labels, object labels, mixed label types
- empty/undefined/partial labels handling
- markdown body preservation

Refactor getUserPrompt() to delegate to buildIssuePrompt().
@dzianisv
Copy link
Copy Markdown
Author

Test Results

Extracted the issue prompt building logic into a pure, exported buildIssuePrompt() function and added 11 unit tests covering:

Test Case Status
Title + body formatting
Null body fallback
Undefined body fallback
Empty string body fallback
String labels array
Object labels array ({ name })
Mixed label types (string + object)
Empty labels array (omit label line)
Undefined labels (omit label line)
Partial/invalid labels filtered out
Markdown body preservation

Run output

bun test v1.3.11 (af24e281)

 28 pass
 0 fail
 36 expect() calls
Ran 28 tests across 1 file. [3.86s]

All 28 tests pass (17 existing extractResponseText/formatPromptTooLargeError + 11 new buildIssuePrompt).

Typecheck also passes across all 13 packages in the monorepo (confirmed by pre-push hook).

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 29, 2026
@github-actions github-actions bot closed this Mar 29, 2026
@dzianisv
Copy link
Copy Markdown
Author

E2E Test Results — Issue Assignment Trigger

Summary

The issue assignment trigger works end-to-end. When an issue is assigned in a repo with the opencode workflow, opencode automatically picks up the issue, extracts the prompt from the issue title/body (via buildIssuePrompt()), sends it to the LLM, and posts a response comment.

Test Setup

  • Test repo: dzianisv/codebridge-test
  • Workflow: .github/workflows/opencode.yml — triggers on issues: [assigned, opened]
  • Model: opencode/gpt-5-nano (free tier, no API key required)
  • Branch tested: feat/github-issue-assignment from dzianisv/opencode fork (runs opencode from source via bun run --cwd packages/opencode --conditions=browser ./src/index.ts github run)

Test Issue

Workflow Run

  • Run: 23722794041SUCCESS
  • Duration: 51 seconds total

Key Log Lines (from the successful run)

Configuring git...
Asserting permissions for user dzianisv...
  permission: admin
Adding reaction...
opencode session ses_2c3dad884ffetyy7cCiVvERWqt
Checking out new branch...
Fetching prompt data for issue...
Sending message to opencode...

Implemented the simple greeting script as requested.
...
Creating comment...
Removing reaction...

Result

The opencode-agent GitHub App posted a comment on issue #683 with:

What This Proves

  1. buildIssuePrompt() correctly extracts issue title + body into a prompt
  2. getUserPrompt() no longer requires the PROMPT env var for issues.assigned / issues.opened events
  3. The full pipeline works: issue assignment → workflow trigger → prompt extraction → LLM response → comment posted
  4. No OPENCODE_API_KEY or other secrets are needed (uses free model with public API key)

Previous Failure (for comparison)

  • Run: 23718780671 — failed with ProviderModelNotFoundError because opencode/claude-sonnet is not a valid model ID (correct ID: opencode/claude-sonnet-4)

@dzianisv
Copy link
Copy Markdown
Author

E2E Test Results — ALL CHECKS PASS ✅

Test Setup

Fix Applied

  • Commit 68abd7556: GithubRunCommand.handler() now uses process.env.GITHUB_WORKSPACE || process.cwd() to determine the target repository directory
  • This ensures opencode operates on the correct repository checkout in GitHub Actions, regardless of where bun is invoked from

Full Flow Evidence (run 23723123435)

  1. Workflow triggered on issues.assigned event
  2. Prompt extracted from issue title+body automatically (no /opencode comment needed)
  3. LLM processed the prompt: generated calculator.py with add/subtract/multiply/divide
  4. Branch pushed: opencode/issue685-20260330004524 to test repo
  5. PR created: #686 — "Added calculator.py CLI tool" (57 lines added)
  6. Comment posted on issue conversation hangs if a large file is in the directory context #685 with PR link
  7. No API key required — used free opencode/gpt-5-nano model

Acceptance Criteria

# Check Status
1 Workflow triggers on issues.assigned ✅ PASS
2 buildIssuePrompt() extracts title+body ✅ PASS
3 LLM processes the prompt ✅ PASS
4 Comment posted on issue ✅ PASS
5 Branch created and pushed ✅ PASS
6 PR created ✅ PASS
7 No API key required ✅ PASS

All 7/7 acceptance criteria passed in the same evaluation run.

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.

1 participant