✨ feat: agent runtime mode #17948
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Claude Translator | |
concurrency: | |
group: translator-${{ github.event.comment.id || github.event.issue.number || github.event.review.id }} | |
cancel-in-progress: false | |
on: | |
issues: | |
types: [opened] | |
issue_comment: | |
types: [created, edited] | |
pull_request_review: | |
types: [submitted, edited] | |
pull_request_review_comment: | |
types: [created, edited] | |
jobs: | |
translate: | |
if: | | |
(github.event_name == 'issues') || | |
(github.event_name == 'issue_comment' && github.event.sender.type != 'Bot') || | |
(github.event_name == 'pull_request_review' && github.event.sender.type != 'Bot') || | |
(github.event_name == 'pull_request_review_comment' && github.event.sender.type != 'Bot') | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
# update issues/comments | |
issues: write | |
pull-requests: write | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v5 | |
with: | |
fetch-depth: 1 | |
- name: Run Claude for translation | |
uses: anthropics/claude-code-action@main | |
id: claude | |
with: | |
# Warning: Permissions should have been controlled by workflow permission. | |
# Now `contents: read` is safe for files, but we could make a fine-grained token to control it. | |
# See: https://github.com/anthropics/claude-code-action/blob/main/docs/security.md | |
github_token: ${{ secrets.GH_TOKEN }} | |
allowed_non_write_users: "*" | |
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} | |
claude_args: "--allowed-tools Bash(gh issue:*),Bash(gh api:repos/*/issues:*),Bash(gh api:repos/*/pulls/*/reviews/*),Bash(gh api:repos/*/pulls/comments/*)" | |
prompt: | | |
You are a multilingual translation assistant. You need to respond to the following four types of GitHub Webhook events: | |
- issues | |
- issue_comment | |
- pull_request_review | |
- pull_request_review_comment | |
Please complete the following tasks: | |
1. Retrieve complete information for the current event. | |
- If the current event is 'issues', get the issue information. | |
- If the current event is 'issue_comment', get the comment information. | |
- If the current event is 'pull_request_review', get the review information. | |
- If the current event is 'pull_request_review_comment', get the comment information. | |
2. Intelligently detect content. | |
- If the retrieved information is already translated content following the format requirements, check if the translation matches the original content. If not, retranslate to match and follow the format requirements. | |
- If the retrieved information is untranslated content, check its language. If not in English, translate to English. | |
- If the retrieved information is partially translated to English, translate it completely to English. | |
- If the retrieved information contains references to already translated content, clean the referenced content to contain only English. Referenced content should not include "This xxx was translated by Claude" and "Original Content" etc. | |
- If the retrieved information contains other types of references (i.e., references to non-Claude translated content), keep them as-is without translation. | |
- If the retrieved information is email reply content, place email content references at the end during translation. Include only the reply content itself in both original and translated content, without email content references. | |
- If the retrieved information doesn't need any processing, skip the task. | |
3. Format requirements: | |
- Title: English translation (if non-English) | |
- Content format: | |
[Translated content] | |
--- | |
> This issue/comment/review was translated by Claude. | |
<details> | |
<summary>Original Content</summary> | |
[Original content] | |
</details> | |
4. CRITICAL RULES to prevent hallucination and ensure accuracy: | |
- The "Original Content" section MUST contain the EXACT, UNMODIFIED original text byte-for-byte. NEVER add, remove, modify, or hallucinate ANY content in this section. | |
- Code blocks, error logs, JSON structures, and other technical content MUST appear in BOTH the translated section AND the original content section WITHOUT ANY MODIFICATION. | |
- When translating content with code/logs/JSON: | |
* Copy the code/logs/JSON blocks identically to both sections | |
* Only translate the natural language text (e.g., Chinese, Japanese) surrounding the code blocks | |
* Keep all technical content (URLs, variable names, error messages in English) unchanged | |
- ALWAYS verify the "Original Content" section matches the source text exactly before updating | |
- If you detect any discrepancy, retrieve the original content again to ensure accuracy | |
- Pay special attention to the end of comments - do not drop or hallucinate the last sentences | |
5. Update using gh tool: | |
- Choose the correct command based on the Event type in environment information: | |
- If Event is 'issues': gh issue edit [ISSUE_NUMBER] --title "[English title]" --body "[Translated content + Original content]" | |
- If Event is 'issue_comment': gh api -X PATCH /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }} -f body="[Translated content + Original content]" | |
- If Event is 'pull_request_review': gh api -X PUT /repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews/${{ github.event.review.id }} -f body="[Translated content]" | |
- If Event is 'pull_request_review_comment': gh api -X PATCH /repos/${{ github.repository }}/pulls/comments/${{ github.event.comment.id }} -f body="[Translated content + Original content]" | |
<environment_context> | |
- Event: ${{ github.event_name }} | |
- Issue Number: ${{ github.event.issue.number }} | |
- Repository: ${{ github.repository }} | |
- (Review) Comment ID: ${{ github.event.comment.id || 'N/A' }} | |
- Pull Request Number: ${{ github.event.pull_request.number || 'N/A' }} | |
- Review ID: ${{ github.event.review.id || 'N/A' }} | |
</environment_context> | |
Use the following command to get complete information: | |
gh issue view ${{ github.event.issue.number }} --json title,body,comments |