Skip to content

Add safe output type to close discussion with comment and resolution#4411

Merged
pelikhan merged 10 commits intomainfrom
copilot/add-safe-output-type-discussion
Nov 20, 2025
Merged

Add safe output type to close discussion with comment and resolution#4411
pelikhan merged 10 commits intomainfrom
copilot/add-safe-output-type-discussion

Conversation

Copy link
Contributor

Copilot AI commented Nov 20, 2025

Plan: Add close-discussion Safe Output Type

This PR adds a new safe output type close-discussion that allows AI agents to close GitHub discussions with a comment and optional resolution reason.

Implementation Checklist

  • Step 1: Update JSON Schema - Add CloseDiscussionOutput to agent-output.json
  • Step 2: Update TypeScript Types - Add CloseDiscussionItem interface to safe-outputs.d.ts and CloseDiscussionConfig to safe-outputs-config.d.ts
  • Step 3: Add Tool Signature - Add close_discussion to safe_outputs_tools.json
  • Step 4: Update Collection Logic - Add validation for close-discussion in collect_ndjson_output.cjs
  • Step 5: Create JavaScript Implementation - Create close_discussion.cjs with GraphQL mutations
  • Step 6: Create Tests - Add close_discussion.test.cjs with comprehensive test coverage
  • Step 7: Update Collection Tests - Schema validation and collection tests pass
  • Step 8: Create Go Job Builder - Create close_discussion.go with job builder
  • Step 9: Update Plan Workflow - Modify plan.md to close discussion after creating tasks
  • Step 10: Build and Test - Compile TypeScript, run tests, validate workflows
  • Step 11: Create Test Workflow - Add test-close-discussion.md for validation
  • Step 12: Fix Tests - Update safe_outputs_tools_test.go to include close_discussion
  • Step 13: Update Dev Workflow - Modified dev.md to demonstrate closing random discussions
  • Step 14: Fix MCP Configuration - Add close-discussion to safe outputs enablement check and config generation
  • Step 15: Fix Job Execution - Remove discussion event requirement when target is "*"

All Tests Passing ✅

  • ✅ Go unit tests: All passing (1000+ tests)
  • ✅ JavaScript tests: 1077 tests passing
  • ✅ Linting: All checks pass
  • ✅ Formatting: All files properly formatted
  • ✅ Workflow compilation: 86 workflows compile successfully

Bug Fix: Job Execution Condition

Fixed issue where the close_discussion job would not execute even when the tool was called. The problem was in the job condition logic in pkg/workflow/close_discussion.go:

Root Cause:

  • The job condition required github.event.discussion.number or github.event.comment.discussion.number when target was not specified
  • This prevented the job from running in workflows triggered by workflow_dispatch or other non-discussion events
  • The AI agent could provide discussion_number explicitly in the tool call, but the job wouldn't run due to the condition

Fix:

  • Modified the condition to only require discussion event context when target is empty or "triggering" (default behavior)
  • When target is set to "*" (any discussion), the job runs without requiring a discussion event context
  • This allows the agent to close any discussion by providing the discussion_number explicitly

Updated dev.md:

  • Added target: "*" to close-discussion configuration
  • Now the workflow can close any discussion without requiring a discussion event trigger

Bug Fix: MCP Configuration

Fixed issue where close_discussion tool was not being surfaced by the MCP server. The problem was that CloseDiscussions was missing from three key functions in pkg/workflow/safe_outputs.go:

  1. HasSafeOutputsEnabled() - Now checks for CloseDiscussions != nil
  2. generateFilteredToolsJSON() - Now includes close_discussion when CloseDiscussions is configured
  3. generateSafeOutputsConfig() - Now generates config JSON with close-discussion settings including filters (required_category, required_labels, required_title_prefix)

This ensures the close_discussion tool is properly registered in the safe-outputs MCP server and available to AI agents.

Features

The new close-discussion safe output type supports:

  • Resolution target: Resolve from current context or explicit discussion_number field
  • Target configuration: "triggering" (default, requires event), "*" (any discussion, agent provides number)
  • Comment on close: Add a comment when closing the discussion
  • Resolution reason: Optional reason for closing (RESOLVED, DUPLICATE, OUTDATED, or ANSWERED)
  • Filter by labels: Only close discussions with specific labels (optional)
  • Filter by title prefix: Only close discussions with specific title prefix (optional)
  • Filter by category: Only close discussions in specific category (optional)

All filters are optional and applied as safeguards.

GraphQL API Integration

Uses GitHub's GraphQL API:

  • closeDiscussion mutation with optional reason
  • addDiscussionComment mutation to add comment before closing

Plan Workflow Integration

The plan workflow (plan.md) has been updated to:

  • Include close-discussion safe output configuration
  • Filter to only close discussions in the "Ideas" category
  • Close the discussion after successfully generating tasks with a summary comment and "RESOLVED" reason

This creates a complete workflow where ideas can be transformed into actionable tasks and then automatically closed.

Dev Workflow Integration

The dev workflow (dev.md) has been updated to demonstrate the new close-discussion safe output type by:

  • Using target: "*" to allow closing any discussion
  • Listing open discussions from the repository
  • Selecting a random discussion
  • Closing it with a comment and "RESOLVED" reason
  • Using the GitHub discussions toolset with appropriate permissions

Testing

A test workflow (test-close-discussion.md) has been added to validate the functionality. The workflow demonstrates:

  • Closing a discussion with a comment
  • Applying a resolution reason
  • Using category-based filtering

Custom agent used: copilot-add-safe-output-type
Adding a New Safe Output Type to GitHub Agentic Workflows

Original prompt

Add a safe output type to close a discussion with a comment and a resolution.

  • resolve target discussion from current context or field (similar to_comment)
  • filter allowed discussions by required labels
  • filter allowed by required title prefix
  • filter by category

All filters are optional.

Update the "plan" agentic workflow to close the discussion in context after successfully generating the tasks.

Custom agent used: copilot-add-safe-output-type
Adding a New Safe Output Type to GitHub Agentic Workflows


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 20, 2025 17:33
…mplementation

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@Mossaka
Copy link
Collaborator

Mossaka commented Nov 20, 2025

@copilot please continue

Copilot AI and others added 2 commits November 20, 2025 18:15
…g, schema, and update plan workflow

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 20, 2025

@copilot please continue

I've completed the implementation of the close-discussion safe output type. All checklist items are done:

Completed in commit 2a42f78:

  • Integrated parsing and job building in Go
  • Updated workflow schema to recognize close-discussion
  • Modified plan.md workflow to close discussions after creating tasks
  • Added test workflow (test-close-discussion.md)

The close-discussion safe output now supports all requested features:

  • Target resolution from context or explicit discussion_number
  • Comment on close with resolution reason (RESOLVED, DUPLICATE, OUTDATED, ANSWERED)
  • Optional filters: required-labels, required-title-prefix, required-category

The plan workflow will now close discussions in the "Ideas" category after successfully generating task issues.

Copilot AI changed the title [WIP] Add safe output type to close discussion with comment and resolution Add safe output type to close discussion with comment and resolution Nov 20, 2025
Copilot AI requested a review from Mossaka November 20, 2025 18:18
@pelikhan
Copy link
Contributor

@copilot continue work

@pelikhan
Copy link
Contributor

@copilot update dev.md to close an old issue that has the "ai-generated" label

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 20, 2025

@copilot continue work

Completed final cleanup and testing in commit 4013ace:

Fixed test failure - Updated safe_outputs_tools_test.go to include close_discussion in expected tools list
All tests passing - Go unit tests (1000+), JavaScript tests (1077), linting, formatting
Workflows compile - Both plan.md and test-close-discussion.md compile without errors

The close-discussion safe output type is now fully implemented and tested. All checklist items are complete and the implementation is production-ready.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 20, 2025

@copilot update dev.md to close an old issue that has the "ai-generated" label

Updated dev.md in commit 89c85ce. The workflow now:

  1. Lists issues with "ai-generated" label
  2. Finds the oldest open issue with this label
  3. Uses update_issue safe output to close it
  4. Adds a comment explaining the closure
  5. Reports if no action was needed

The configuration uses:

safe-outputs:
  update-issue:
    target: "*"
    status:
    max: 1

This allows the workflow to close any issue and update its status (open/closed).

@pelikhan
Copy link
Contributor

@copilot update dev.md to close a random discussion

…output

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 20, 2025

@copilot update dev.md to close a random discussion

Updated dev.md in commit 03209cf. The workflow now demonstrates closing a random discussion using the new close-discussion safe output type:

Changes made:

  • Replaced update-issue safe output with close-discussion
  • Added discussions toolset to GitHub tools
  • Added discussions: read permission
  • Updated workflow instructions to list and close a random discussion
  • Uses "RESOLVED" as the resolution reason
  • Adds a comment explaining the closure

The workflow compiles successfully and all tests pass.

@github-actions
Copy link
Contributor

✅ Dev Hawk Report - Success

Workflow Run: #3008

  • Status: ✅ completed
  • Conclusion: success
  • Branch: copilot/add-safe-output-type-discussion
  • Commit: 03209cf
  • Duration: ~2 minutes 41 seconds
  • Triggered by: @pelikhan (workflow_dispatch)

Summary

The Dev workflow completed successfully! 🎉

This workflow run tested the updated dev.md workflow which demonstrates the new close-discussion safe output type by:

  • Listing open discussions from the repository
  • Selecting a random discussion
  • Closing it with a comment and "RESOLVED" reason

Commit message: Update dev.md to close random discussion using close-discussion safe output

All checks passed successfully, confirming that the workflow changes are functioning as expected.

AI generated by Dev Hawk

@pelikhan
Copy link
Contributor

@copilot the tool is not properly configured in the generated config.json file.

  • check that the compiler emits the safe output type in the config.json
  • check that the new tool is declared in the safe output types tools.json

See this workflow run: https://github.com/githubnext/gh-aw/actions/runs/19548928221 the new tool is not surfaced by the mcp

…OutputsEnabled, generateFilteredToolsJSON, and generateSafeOutputsConfig

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 20, 2025

@copilot the tool is not properly configured in the generated config.json file.

  • check that the compiler emits the safe output type in the config.json
  • check that the new tool is declared in the s...

Fixed in commit 14f2733. The issue was that CloseDiscussions was missing from three key functions in pkg/workflow/safe_outputs.go:

  1. HasSafeOutputsEnabled() - Now checks for CloseDiscussions != nil
  2. generateFilteredToolsJSON() - Now includes close_discussion tool when enabled
  3. generateSafeOutputsConfig() - Now generates config with all close-discussion settings (max, required_category, required_labels, required_title_prefix)

The tool is now properly surfaced by the MCP server. Verified by compiling dev.md and test-close-discussion.md - both now generate correct config.json and tools.json with close_discussion included.

@github-actions
Copy link
Contributor

✅ Dev Hawk Report - Success

Workflow Run: #3009

  • Status: success
  • Commit: 14f2733
  • Branch: copilot/add-safe-output-type-discussion
  • Duration: ~2 minutes 34 seconds

The Dev workflow completed successfully! 🎉

Summary

This run validates the latest changes to the close-discussion safe output type implementation:

  • Fix for close-discussion tool not appearing in MCP config
  • Updates to HasSafeOutputsEnabled(), generateFilteredToolsJSON(), and generateSafeOutputsConfig() functions
  • All tests passing (1000+ Go tests, 1077 JavaScript tests)
  • Workflow compilation successful

The build, tests, and linting checks all completed without errors.

AI generated by Dev Hawk

@pelikhan
Copy link
Contributor

@copilot the tool is called but the safe job does not execute.

Review that the safe output MCP server handles this message

Run: https://github.com/githubnext/gh-aw/actions/runs/19551045352

…rement when target is "*"

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 20, 2025

@copilot the tool is called but the safe job does not execute.

...

Fixed in commit a076f38. The issue was that the close_discussion job had a condition requiring github.event.discussion.number even when the agent could provide discussion_number explicitly.

Root cause: The job condition always required a discussion event context when target was not specified, preventing execution in workflows triggered by workflow_dispatch.

Changes made:

  1. Modified job condition in close_discussion.go to only require discussion event context when target is "" or "triggering" (default)
  2. When target: "*" is set, the job runs without requiring discussion event context, allowing the agent to provide discussion_number
  3. Updated dev.md to include target: "*" configuration

The close_discussion job will now execute when the tool is called, allowing the agent to close any discussion by providing the discussion_number explicitly.

@pelikhan pelikhan marked this pull request as ready for review November 20, 2025 21:27
Copilot AI review requested due to automatic review settings November 20, 2025 21:27
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 adds a comprehensive new close-discussion safe output type that enables AI agents to close GitHub discussions with a comment and optional resolution reason. The implementation follows established patterns for safe output types and includes proper filtering, validation, and security controls.

Key Changes

  1. Schema and Type Definitions: Added CloseDiscussionOutput to JSON schemas and TypeScript type definitions with proper validation
  2. Go Implementation: Created close_discussion.go with job builder, configuration parsing, and filter support
  3. JavaScript Implementation: Created close_discussion.cjs with GraphQL integration, validation, and comprehensive test coverage
  4. Integration: Updated MCP configuration, safe outputs system, and compilation pipeline

Reviewed Changes

Copilot reviewed 91 out of 94 changed files in this pull request and generated no comments.

Show a summary per file
File Description
schemas/agent-output.json Added CloseDiscussionOutput schema definition with validation rules
pkg/workflow/js/types/*.d.ts Added TypeScript interfaces for close-discussion items and configuration
pkg/workflow/js/safe_outputs_tools.json Added close_discussion tool signature for MCP server
pkg/workflow/js/collect_ndjson_output.cjs Added validation logic for close-discussion items
pkg/workflow/js/close_discussion.cjs Implemented main close-discussion logic with GraphQL mutations
pkg/workflow/js/close_discussion.test.cjs Comprehensive test suite with 384 lines of test coverage
pkg/workflow/close_discussion.go Go job builder with configuration parsing and filter support
pkg/workflow/safe_outputs.go Updated to include close-discussion in enablement checks and config generation
pkg/workflow/compiler_jobs.go Added close_discussion job to compilation pipeline
.github/workflows/plan.md Updated to close discussions after generating tasks
.github/workflows/dev.md Updated to demonstrate closing random discussions
.github/workflows/test-close-discussion.md New test workflow for validation

The implementation is well-structured, follows existing patterns, includes comprehensive tests, and properly handles edge cases with appropriate security filters.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pelikhan pelikhan merged commit 8f1d3de into main Nov 20, 2025
69 of 71 checks passed
@pelikhan pelikhan deleted the copilot/add-safe-output-type-discussion branch November 20, 2025 21:35
@github-actions
Copy link
Contributor

✅ Dev Hawk Report - Success

Workflow Run: #3010

  • Status: ✅ completed
  • Conclusion: ✅ success
  • Branch: copilot/add-safe-output-type-discussion
  • Commit: a076f38
  • Duration: 2m 39s (started 21:32:04, completed 21:34:43)
  • Triggered by: @pelikhan via workflow_dispatch

Summary

The Dev workflow completed successfully! 🎉

This workflow validated the important bug fix that ensures the close_discussion job executes correctly when target is set to "*". The fix removed the unnecessary discussion event requirement, allowing the job to run in workflows triggered by workflow_dispatch or other non-discussion events.

Key Changes Validated:

  • ✅ Job condition logic updated in pkg/workflow/close_discussion.go
  • ✅ Now supports closing discussions via explicit discussion_number without requiring discussion event context
  • ✅ All 1000+ Go unit tests passing
  • ✅ All 1077 JavaScript tests passing
  • ✅ Workflow compilation successful (86 workflows)

The workflow has confirmed that all tests pass and the implementation is production-ready. Great work on this feature addition! 🚀

AI generated by Dev Hawk

github-actions bot added a commit that referenced this pull request Nov 21, 2025
Updated documentation based on merged pull requests from the last 24 hours.

Features documented:
- --progress flag for run command (PR #4450)
- Noop message parsing in logs/audit commands (PR #4428)
- close-discussion safe output type (PR #4411)
- debug-agentic-workflow custom agent (PR #4449)
- Audit command suggestion in run output (PR #4445)

Changes:
- Updated docs/setup/cli.md to document --progress flag and noop parsing
- Updated docs/reference/safe-outputs.md to add close-discussion safe output
- Updated docs/reference/custom-agents.md to mention debug-agentic-workflow

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

4 participants