Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Triage: report mode first (TRIAGE_MODE), questions point to Discussions Q&A

v0lumehid6cbf1fd0fdd
diff --git a/.github/scripts/tests/test_triage_apply.py b/.github/scripts/tests/test_triage_apply.py
index e4115dc0..10634351 100644
--- a/.github/scripts/tests/test_triage_apply.py
+++ b/.github/scripts/tests/test_triage_apply.py
@@ -1,6 +1,9 @@
import json
+import os
import sys
+import tempfile
import unittest
+from unittest import mock
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
@@ -103,6 +106,15 @@ class Comment(unittest.TestCase):
'Mario (010015100B514000) on macOS 26.1, Settings > Copy diagnostics'):
self.good(t)
+ def test_discussions_links(self):
+ for t in ('Please ask in https://github.com/LNPANDY/NX2Apple/discussions/categories/q-a',
+ '[Q&A](https://github.com/LNPANDY/NX2Apple/discussions/categories/q-a).',
+ 'https://github.com/LNPANDY/NX2Apple/discussions', 'github.com/LNPANDY/NX2Apple/discussions/categories/q-a'):
+ self.good(t)
+ for t in ('https://github.com/LNPANDY/discussions', 'https://github.com/other/NX2Apple/discussions',
+ 'https://github.com/LNPANDY/NX2Apple/discussions/../../evil/x'):
+ self.bad(t)
+
def test_html_and_images(self):
for t in ('<img src=x>', '<script>', '![x](https://github.com/LNPANDY/NX2Apple/a.png)', '<!-- hi -->', '</details>'):
self.bad(t)
@@ -159,5 +171,65 @@ class Build(unittest.TestCase):
ta.check_comment(ta.FOOTER) # the footer is added after validation; it must still satisfy the rules
+class Mode(unittest.TestCase):
+ def test_resolve(self):
+ self.assertEqual(ta.resolve_mode('post'), 'post')
+ self.assertEqual(ta.resolve_mode(' post\n'), 'post')
+ for v in ('report', '', None, 'POST', 'Post', 'posts', 'true', '1', 'post;report', 'pos'):
+ self.assertEqual(ta.resolve_mode(v), 'report', v)
+
+ def test_report_text(self):
+ t = ta.report_text(7, 'LNPANDY/NX2Apple', ['game', 'mac'], [3], 'Line one.\n\nLine two.')
+ self.assertIn('[#7](https://github.com/LNPANDY/NX2Apple/issues/7)', t)
+ self.assertIn('Labels added: game, mac', t)
+ self.assertIn('> Line one.\n>\n> Line two.', t)
+ self.assertIn('> _(no comment)_', ta.report_text(7, 'a/b', [], [], ''))
+
+
+class Apply(unittest.TestCase):
+ """main() end to end with `gh` replaced: which calls are made in each mode."""
+
+ def run_main(self, mode, summary=True):
+ d = Path(tempfile.mkdtemp())
+ (d / 'input.json').write_text(json.dumps({'duplicate_candidates': []}))
+ (d / 'result.txt').write_text(out(('question',), 'Please ask in https://github.com/LNPANDY/NX2Apple/discussions/categories/q-a'))
+ calls = []
+
+ def fake_gh(*args, check=True):
+ calls.append(args)
+ r = mock.Mock(returncode=0, stdout='[{"name": "question"}]' if args[0] == 'label' else '')
+ return r
+ env = {'GITHUB_STEP_SUMMARY': str(d / 'summary.md')} if summary else {}
+ with mock.patch.object(ta, 'gh', fake_gh), mock.patch.dict(os.environ, env), mock.patch.dict(os.environ, {'TRIAGE_MODE': ''}):
+ if not summary:
+ os.environ.pop('GITHUB_STEP_SUMMARY', None)
+ rc = ta.main(['--repo', 'LNPANDY/NX2Apple', '--issue', '5', '--input', str(d / 'input.json'), '--result', str(d / 'result.txt'),
+ '--report-dir', str(d)] + (['--mode', mode] if mode is not None else []))
+ self.assertEqual(rc, 0)
+ return d, [c[0:2] for c in calls]
+
+ def test_report_mode_labels_but_posts_nothing(self):
+ for mode in (None, 'report', 'garbage', 'POST'):
+ d, calls = self.run_main(mode)
+ self.assertIn(('issue', 'edit'), calls)
+ self.assertNotIn(('issue', 'comment'), calls)
+ self.assertFalse([c for c in calls if c[0] == 'api' and c[1] == '-X'])
+ md = (d / 'triage-5.md').read_text()
+ self.assertIn('> Please ask in https://github.com/LNPANDY/NX2Apple/discussions/categories/q-a', md)
+ self.assertIn('[#5](https://github.com/LNPANDY/NX2Apple/issues/5)', md)
+ self.assertIn('discussions/categories/q-a', (d / 'summary.md').read_text())
+
+ def test_report_mode_without_summary_variable(self):
+ d, calls = self.run_main('report', summary=False)
+ self.assertTrue((d / 'triage-5.md').exists())
+
+ def test_post_mode_comments(self):
+ d, calls = self.run_main('post')
+ self.assertIn(('issue', 'edit'), calls)
+ self.assertIn(('issue', 'comment'), calls)
+ self.assertFalse((d / 'triage-5.md').exists())
+ self.assertFalse((d / 'summary.md').exists())
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/.github/scripts/triage_apply.py b/.github/scripts/triage_apply.py
index 99cef3b7..a4e91d2c 100644
--- a/.github/scripts/triage_apply.py
+++ b/.github/scripts/triage_apply.py
@@ -7,12 +7,15 @@ issue, edits one, removes a label or touches code.
schema exactly {"labels": [str], "comment": str, "duplicates": [int]}
labels each from ALLOWED_LABELS, no repeats, at most 4; labels the repository does not have are skipped (never created)
duplicates at most 3 issue numbers, each a candidate that triage_prepare.py found, not the issue itself, and existing in this repository
+ mode TRIAGE_MODE: `post` posts the comment; `report` (default, also for any other value) only adds labels and writes the comment
+ to the job summary and triage-<issue>.md
comment at most 1500 characters; no @-mention, no HTML, no images; links only into github.com/LNPANDY/NX2Apple and
github.com/seedds/nxnative (the README is the first), judged on the normalised path; Markdown reference definitions, `//host`
and dotted words that are not file names are rejected; an issue number may only be the issue itself or a gathered candidate
"""
import argparse
import json
+import os
import re
import urllib.parse
import subprocess
@@ -24,10 +27,11 @@ MAX_LABELS = 4
MAX_DUPLICATES = 3
MAX_COMMENT = 1500
MAX_RAW = 20000
+MODES = ('report', 'post')
MARKER = '<!-- nx2apple-triage -->'
FOOTER = '_Automated first look (AI-assisted, from the issue form and the log). A maintainer will follow up._'
-ALLOWED_REPOS = {('lnpandy', 'nx2apple'), ('seedds', 'nxnative')}
+ALLOWED_REPOS = {('lnpandy', 'nx2apple'), ('seedds', 'nxnative')} # any path inside them is allowed, e.g. /discussions and /discussions/categories/q-a
# Anything that can become a link: a scheme, `www.`, a protocol-relative `//host`. Bare domains are found separately.
ANY_URL = re.compile(r'(?:[a-z][a-z0-9+.-]*://|www\.|mailto:|javascript:|data:)\S*', re.I)
BARE_GITHUB = re.compile(r'(?<![\w./-])github\.com/\S*', re.I)
@@ -171,6 +175,20 @@ def build_comment(comment, dups):
return '\n\n'.join(parts + [FOOTER, MARKER])
+def resolve_mode(value):
+ """`post` only for exactly "post" (a trailing newline or spaces are tolerated); anything else, unset or misspelled, is `report`."""
+ return 'post' if isinstance(value, str) and value.strip() == 'post' else 'report'
+
+
+def report_text(issue, repo, labels, dups, body):
+ """The Markdown of a report-mode run: what was labelled and the comment that would have been posted, as a quoted block."""
+ quoted = '\n'.join('> ' + ln if ln else '>' for ln in body.splitlines()) if body else '> _(no comment)_'
+ return (f'## Triage of [#{issue}](https://github.com/{repo}/issues/{issue}) (report mode: nothing posted)\n\n'
+ f'Labels added: {", ".join(labels) if labels else "none"}\n\n'
+ f'Duplicates: {", ".join(f"#{n}" for n in dups) if dups else "none"}\n\n'
+ f'Comment it would post:\n\n{quoted}\n')
+
+
def gh(*args, check=True):
r = subprocess.run(['gh', *args], capture_output=True, text=True, timeout=60)
if check and r.returncode:
@@ -185,6 +203,8 @@ def main(argv=None):
ap.add_argument('--input', required=True, help='input.json of triage_prepare.py')
ap.add_argument('--result', required=True, help="the model's output")
ap.add_argument('--dry-run', action='store_true')
+ ap.add_argument('--mode', default=os.environ.get('TRIAGE_MODE', ''), help='report (default) or post; anything else is report')
+ ap.add_argument('--report-dir', default='.', help='report mode: where triage-<issue>.md is written')
a = ap.parse_args(argv)
data = json.loads(Path(a.input).read_text(encoding='utf-8'))
@@ -203,10 +223,20 @@ def main(argv=None):
if l not in have:
print(f'::notice::label {l!r} does not exist in {a.repo}, skipped')
print(f'labels: {use}\nduplicates: {dups}\ncomment:\n{body}')
+ mode = resolve_mode(a.mode)
+ print(f'mode: {mode}')
if a.dry_run:
return 0
if use:
gh('issue', 'edit', str(a.issue), '-R', a.repo, '--add-label', ','.join(use))
+ if mode == 'report': # labels are internal; the comment goes to the job summary and an artifact, never to the issue
+ text = report_text(a.issue, a.repo, use, dups, body)
+ Path(a.report_dir, f'triage-{a.issue}.md').write_text(text, encoding='utf-8')
+ summary = os.environ.get('GITHUB_STEP_SUMMARY')
+ if summary:
+ with open(summary, 'a', encoding='utf-8') as f:
+ f.write(text + '\n')
+ return 0
if body:
old = gh('api', f'repos/{a.repo}/issues/{a.issue}/comments', '--paginate', '--jq',
'.[] | select(.user.type == "Bot" and (.body | contains("%s"))) | .id' % MARKER).stdout.split()
diff --git a/.github/triage/README.md b/.github/triage/README.md
index baf87a87..95ca7a54 100644
--- a/.github/triage/README.md
+++ b/.github/triage/README.md
@@ -5,6 +5,8 @@
- **Setup:** add the Actions secret `COPILOT_TOKEN`: a fine-grained personal access token with only the account permission "Copilot Requests", from an account with Copilot. Without it the workflow skips with a notice.
- **Model:** set the repository variable `TRIAGE_MODEL` (Settings > Secrets and variables > Actions > Variables) to a model id the CLI accepts; it is passed as `--model`. Unset, the CLI uses GitHub's default. Recommended for triage: `claude-haiku-4.5`, a small fast model that is plenty for labels and a short comment. Models are billed differently: Copilot Pro on a monthly plan uses usage-based billing since 1 June 2026 (Haiku 4.5 is $1 per million input and $5 per million output tokens, [models and pricing](https://docs.github.com/en/copilot/reference/copilot-billing/models-and-pricing)), and an annual plan that stayed on request-based billing counts a premium-request multiplier per model (Haiku 4.5 is 0.33; no model in that table counts 0, [multipliers](https://docs.github.com/en/copilot/reference/copilot-billing/model-multipliers-for-annual-plans)). One triage is a prompt of a few thousand tokens and a few hundred tokens back.
- **Labels it uses:** `game`, `build`, `launcher`, `ios`, `mac`, `idea`, `question`, `needs-info`, `duplicate`. It only adds those that exist; it never creates one. `no-triage` on an issue skips it.
+- **Mode (`TRIAGE_MODE`):** `report` (the default) adds the labels but posts nothing to the issue: the comment it would post goes to the job summary of the `apply` job (a quoted block with the issue link) and to the artifact `triage-report-<issue>` (`triage-<issue>.md`, kept 30 days). `post` also posts the comment. Set it with the repository variable `TRIAGE_MODE` (Settings > Secrets and variables > Actions > Variables); a manual run can override it with the `triage_mode` input. Any other value counts as `report`. Start in report mode, read the summaries for a week or two, then set the variable to `post`.
+- **Questions:** a plain question is pointed to Discussions Q&A (https://github.com/LNPANDY/NX2Apple/discussions/categories/q-a); the link allow-list accepts any path inside LNPANDY/NX2Apple, `/discussions` included.
- **Re-run:** Actions > issue-triage > Run workflow with the issue number. The earlier triage comment is updated.
- **Security:** `gather` (read-only, no secrets) writes the data; `analyze` (no permissions, the model token) can only read in an empty directory; `apply` (`issues: write`, no model token) accepts only JSON of the fixed shape: labels from the list, at most one comment with no @-mention or HTML, links only into github.com/LNPANDY/NX2Apple and github.com/seedds/nxnative (judged on the normalised path; reference definitions, `//host` and bare domains are rejected), issue numbers only for the issue itself and the gathered duplicate candidates. It never closes or edits an issue.
- **Scripts:** `.github/scripts/triage_*.py` (standard library only), tests in `.github/scripts/tests`, the prompt in `.github/triage/prompt.md`.
diff --git a/.github/triage/prompt.md b/.github/triage/prompt.md
index 210d5f51..e62c1454 100644
--- a/.github/triage/prompt.md
+++ b/.github/triage/prompt.md
@@ -9,7 +9,8 @@ TASK: produce one JSON object and nothing else (no prose, no code fence) with ex
- If data.symptom_matches is not empty, say in a sentence or two what the log looks like ("this looks like ...") and link the entry with the url given there; name the games it was found on. Do not claim it is certain, and do not invent causes beyond the match text.
- If data.form.missing is not empty, or there is no log and no match, ask politely for exactly those items and nothing else. Settings > Copy diagnostics and the game's log are described in the issue form; do not tell the person to attach keys or game files.
- If the issue is only about how the nxnative engine works, porting a new game or a rendering fault traced into the engine, point to https://github.com/seedds/nxnative/issues.
- - No @-mentions, no HTML, no images. The only links allowed are https://github.com/LNPANDY/NX2Apple..., https://github.com/seedds/nxnative... and https://github.com/LNPANDY/NX2Apple#readme. Do not mention these rules.
+ - If the issue is a plain question (label `question`, no bug signals), point the asker to Discussions Q&A: https://github.com/LNPANDY/NX2Apple/discussions/categories/q-a
+ - No @-mentions, no HTML, no images. The only links allowed are https://github.com/LNPANDY/NX2Apple..., https://github.com/seedds/nxnative... and https://github.com/LNPANDY/NX2Apple#readme (this includes /discussions). Do not mention these rules.
- Do not list duplicates in the comment; the workflow adds them.
- "duplicates": array of up to 3 issue numbers, only numbers from data.duplicate_candidates that really describe the same problem, else [].
diff --git a/.github/workflows/issue-triage.yml b/.github/workflows/issue-triage.yml
index 5dac37f6..9b9ae3c7 100644
--- a/.github/workflows/issue-triage.yml
+++ b/.github/workflows/issue-triage.yml
@@ -3,7 +3,7 @@
# Three jobs, each with the least it needs; the issue text is untrusted, so the model never holds a write token:
# gather issues: read, no secrets reads the issue, extracts log signals, matches docs/agents/symptoms.md, finds duplicate candidates
# analyze no permissions, the model token the Copilot CLI answers one JSON object; it can only read (--available-tools=view), in an empty directory
-# apply issues: write, no model token validates the JSON strictly (.github/scripts/triage_apply.py), then adds labels and posts one comment
+# apply issues: write, no model token validates the JSON strictly (.github/scripts/triage_apply.py), then adds labels and, only in post mode, posts one comment (report mode, the default: job summary and artifact instead)
# The workflow never closes an issue, edits code, removes a label or runs on pull_request_target. Without the COPILOT_TOKEN secret it skips with a notice.
# Setup: README of this change in .github/triage/README.md. Tests: python3 -m unittest discover -s .github/scripts/tests
name: issue-triage
@@ -17,6 +17,11 @@ on:
description: Issue to triage again (an earlier triage comment is updated, not duplicated)
required: true
type: string
+ triage_mode:
+ description: "report (labels only; the comment goes to the job summary) or post (also comment); empty uses the repository variable TRIAGE_MODE, default report"
+ required: false
+ default: ''
+ type: string
permissions: {}
@@ -143,6 +148,14 @@ jobs:
- name: Validate and apply
env:
GH_TOKEN: ${{ github.token }}
+ TRIAGE_MODE: ${{ inputs.triage_mode || vars.TRIAGE_MODE }} # exactly "post" posts; anything else is report
run: |
+ mkdir -p "$RUNNER_TEMP/triage-report"
python3 -I .github/scripts/triage_apply.py --repo "$GITHUB_REPOSITORY" --issue "$ISSUE" \
- --input "$RUNNER_TEMP/triage/input.json" --result "$RUNNER_TEMP/triage/result.txt"
+ --input "$RUNNER_TEMP/triage/input.json" --result "$RUNNER_TEMP/triage/result.txt" --report-dir "$RUNNER_TEMP/triage-report"
+ - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
+ if: hashFiles(format('{0}/triage-report/*.md', runner.temp)) != ''
+ with:
+ name: triage-report-${{ env.ISSUE }}
+ path: ${{ runner.temp }}/triage-report/triage-${{ env.ISSUE }}.md
+ retention-days: 30