@trashcodermaker/pi-pr-review-handler 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 JI4JUN
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,176 @@
1
+ <!-- prettier-ignore -->
2
+ <div align="center">
3
+
4
+ <!-- No project-specific icon found; skip the header image. -->
5
+
6
+ # PR Review Handler
7
+
8
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/JI4JUN/pr-review-handler/ci.yml?style=flat-square&label=Build)](https://github.com/JI4JUN/pr-review-handler/actions)
9
+ [![npm version](https://img.shields.io/npm/v/@trashcodermaker/pi-pr-review-handler?style=flat-square)](https://www.npmjs.com/package/@trashcodermaker/pi-pr-review-handler)
10
+ [![License](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)](LICENSE)
11
+
12
+ > Systematically process GitHub PR review comments: triage for validity, fix code, and post replies.
13
+ >
14
+ > [中文版](./README.zh.md)
15
+
16
+ ⭐ If you like this project, star it on GitHub — it helps a lot!
17
+
18
+ [Overview](#overview) • [Getting started](#getting-started) • [How it works](#how-it-works) • [Usage](#usage) • [Requirements](#requirements) • [Supported platforms](#supported-platforms)
19
+
20
+ </div>
21
+
22
+ ## Overview
23
+
24
+ Code review is part of every healthy PR workflow, but turning review threads into actual fixes and thoughtful replies can be tedious and error-prone.
25
+
26
+ **PR Review Handler** automates that workflow. It fetches unresolved GitHub PR review threads, evaluates each comment for validity, applies minimal code fixes, drafts replies that match the reviewer's language and tone, and optionally pushes changes and requests re-review.
27
+
28
+ It can be used as an npm package, a Pi package, a Pi skill, or embedded into other agent environments. The project ships agent specifications in `agents/` so each platform can run the pipeline with its own task/dispatch mechanism.
29
+
30
+ ## Getting started
31
+
32
+ ### Install as an npm package
33
+
34
+ ```bash
35
+ npm install @trashcodermaker/pi-pr-review-handler
36
+ ```
37
+
38
+ ### Install as a Pi package
39
+
40
+ ```bash
41
+ pi install @trashcodermaker/pi-pr-review-handler
42
+ ```
43
+
44
+ ### Install from skill.sh
45
+
46
+ ```bash
47
+ npx skills add JI4JUN/pr-review-handler
48
+ ```
49
+
50
+ ### From source
51
+
52
+ ```bash
53
+ git clone https://github.com/JI4JUN/pr-review-handler.git
54
+ cd pr-review-handler
55
+ npm install
56
+ ```
57
+
58
+ > [!IMPORTANT]
59
+ > Ensure GitHub CLI (`gh`) is installed and authenticated before using this skill or package. Most commands depend on it to read PR data and post replies.
60
+
61
+ ## How it works
62
+
63
+ The handler runs a multi-phase pipeline. Each phase has a clear responsibility, and the flow stops at checkpoints where human confirmation is requested.
64
+
65
+ ```
66
+ Phase 0: Setup
67
+ Phase 1: Triage ← parallel, read-only
68
+ Phase 2: Fix ← serial, minimal changes
69
+ Phase 3: Reply ← orchestrator drafts inline
70
+ Phase 4: Post & Push
71
+ Phase 5: Report
72
+ ```
73
+
74
+ ### Phase 0: Setup
75
+
76
+ Identifies the target PR from the current branch or an explicit PR link, fetches unresolved review threads, and fetches review-level feedback. This phase prepares everything needed for triage without modifying code.
77
+
78
+ ### Phase 1: Triage
79
+
80
+ Reads the referenced code and each review thread, then classifies every comment as:
81
+
82
+ - `valid-fix` — a real issue that requires code changes
83
+ - `valid-nofix` — the concern is valid, but no code change is needed
84
+ - `invalid` — the premise doesn't apply to current code, or the suggested fix would be harmful
85
+
86
+ If there are many threads and the platform supports parallel agents, triage runs in parallel for speed.
87
+
88
+ > [!TIP]
89
+ > Triage is intentionally conservative. If a comment is unclear, mark it `invalid` with the reason `unclear — needs human review`.
90
+
91
+ ### Phase 2: Fix
92
+
93
+ For each `valid-fix` thread, a specialized implementation agent applies the smallest possible change that satisfies the review. The agent traces references first, updates callers and tests when signatures change, and avoids unrelated cleanup or refactors.
94
+
95
+ All fixes are committed locally, but **never pushed** during this phase.
96
+
97
+ After all fixes:
98
+
99
+ ```bash
100
+ npx tsc --noEmit
101
+ ```
102
+
103
+ If type checking fails, the pipeline identifies the offending commit, reverts it, fixes the issue, and recommits before continuing.
104
+
105
+ ### Phase 3: Reply
106
+
107
+ The orchestrator drafts one reply per thread based on:
108
+
109
+ - Original thread data
110
+ - Triage verdicts
111
+ - Actual diff: `git diff origin/{branch}...HEAD`
112
+ - Failure records from Phase 2
113
+
114
+ Replies are matched to the reviewer's language and tone, kept concise, and never defensive.
115
+
116
+ ### Phase 4: Post & Push
117
+
118
+ Approved replies are posted to GitHub, and all local review-fix commits are pushed in one step.
119
+
120
+ Optionally, the handler can also:
121
+
122
+ - Request re-review from the original reviewers
123
+ - Dismiss resolved review threads with an "Addressed" message
124
+
125
+ ### Phase 5: Report
126
+
127
+ A concise summary is printed at the end:
128
+
129
+ ```
130
+ ✅ Triage: N/N threads processed
131
+ ✅ Fixes: M/K valid-fix threads applied (committed locally, pushed)
132
+ ❌ Failed: {thread} — {reason}
133
+ ✅ Replies: P/P threads drafted and posted
134
+ ```
135
+
136
+ ## Usage
137
+
138
+ ### In an agent
139
+
140
+ When installed as a skill, invoke it from your agent with natural language. Examples:
141
+
142
+ - "帮我处理这个 PR 的 review:<https://github.com/owner/repo/pull/123>"
143
+ - "回复 reviewer 的评论"
144
+ - "看看 PR 里那些 unresolved threads"
145
+ - "review 提的问题要修一下"
146
+ - "CI 过了,但 review 还没回"
147
+ - "someone left comments on my PR"
148
+ - "帮我看看那些人提的意见"
149
+
150
+ ### From the command line
151
+
152
+ If you want to drive the workflow manually, you can use the GitHub CLI commands directly. The skill and package primarily wrap these operations into an agent-friendly pipeline.
153
+
154
+ ## Requirements
155
+
156
+ - GitHub CLI (`gh`) installed and authenticated
157
+ - A Git working tree clean enough to create review-fix commits
158
+ - Node.js / TypeScript project if you want the final `tsc --noEmit` check
159
+
160
+ ## Supported platforms
161
+
162
+ | Platform | Support |
163
+ | --- | --- |
164
+ | npm / Node.js | ✅ Install as a published package |
165
+ | Pi | ✅ Supported as a package and as a skill |
166
+ | Claude Code | ✅ Task-based agent dispatch |
167
+ | Cursor | ✅ Background agent dispatch |
168
+ | Other agent clients | ✅ Inline fallback using the agent specs in `agents/` |
169
+
170
+ ## Notes
171
+
172
+ - Agent specs are provided in `agents/` for reuse across platforms.
173
+ - When a platform supports parallel agents, triage can run in parallel; otherwise it runs inline.
174
+ - There are two checkpoints where execution pauses for confirmation: after triage verdicts, and before posting replies.
175
+ - Pushes only happen once, after replies are approved.
176
+ - The implementation phase is serial by default to avoid conflicting file changes.
package/README.zh.md ADDED
@@ -0,0 +1,176 @@
1
+ <!-- prettier-ignore -->
2
+ <div align="center">
3
+
4
+ <!-- 项目中未发现专用图标,因此跳过顶部图片。 -->
5
+
6
+ # PR Review Handler
7
+
8
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/JI4JUN/pr-review-handler/ci.yml?style=flat-square&label=Build)](https://github.com/JI4JUN/pr-review-handler/actions)
9
+ [![npm version](https://img.shields.io/npm/v/@trashcodermaker/pi-pr-review-handler?style=flat-square)](https://www.npmjs.com/package/@trashcodermaker/pi-pr-review-handler)
10
+ [![License](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)](LICENSE)
11
+
12
+ > 系统地处理 GitHub PR review 评论:判断有效性、修复代码、发布回复。
13
+ >
14
+ > [English version](./README.md)
15
+
16
+ ⭐ 如果这个项目对你有帮助,欢迎在 GitHub 上点个 star!
17
+
18
+ [项目简介](#项目简介) • [快速开始](#快速开始) • [工作原理](#工作原理) • [使用方法](#使用方法) • [环境要求](#环境要求) • [支持的平台](#支持的平台)
19
+
20
+ </div>
21
+
22
+ ## 项目简介
23
+
24
+ Code Review 是健康 PR 流程的一部分,但把 review 评论转化为实际修复和得体温回复往往既繁琐又容易出错。
25
+
26
+ **PR Review Handler** 用自动化流程解决这个问题。它会抓取 GitHub PR 中未关闭的 review 线程,逐条判断评论是否成立,对有效问题做最小化代码修复,生成与评论者语言、语气一致的回复,并在确认后推送变更、请求 re-review。
27
+
28
+ 它可以作为 npm 包、Pi 包、Pi skill,或嵌入到其他 agent 环境使用。项目在 `agents/` 中提供 agent 规格,因此不同平台可以用自己的任务/调度机制运行同一套流水线。
29
+
30
+ ## 快速开始
31
+
32
+ ### 作为 npm 包安装
33
+
34
+ ```bash
35
+ npm install @trashcodermaker/pi-pr-review-handler
36
+ ```
37
+
38
+ ### 作为 Pi 包安装
39
+
40
+ ```bash
41
+ pi install @trashcodermaker/pi-pr-review-handler
42
+ ```
43
+
44
+ ### 通过 skill.sh 安装
45
+
46
+ ```bash
47
+ npx skills add JI4JUN/pr-review-handler
48
+ ```
49
+
50
+ ### 从源码安装
51
+
52
+ ```bash
53
+ git clone https://github.com/JI4JUN/pr-review-handler.git
54
+ cd pr-review-handler
55
+ npm install
56
+ ```
57
+
58
+ > [!IMPORTANT]
59
+ > 使用本 skill 或包之前,请确保已安装并登录 GitHub CLI(`gh`)。读取 PR 数据、发布回复等核心操作都依赖它。
60
+
61
+ ## 工作原理
62
+
63
+ 整个流程由多个阶段组成,每个阶段职责清晰;在需要人工确认的位置会设置 checkpoint 暂停执行。
64
+
65
+ ```
66
+ Phase 0: Setup
67
+ Phase 1: Triage ← 并行,只读
68
+ Phase 2: Fix ← 串行,最小修改
69
+ Phase 3: Reply ← 由编排器直接起草
70
+ Phase 4: Post & Push
71
+ Phase 5: Report
72
+ ```
73
+
74
+ ### Phase 0: Setup
75
+
76
+ 根据当前分支或显式 PR 链接定位目标 PR,抓取未关闭的 review 线程,并补充抓取 review 级别的整体反馈。本阶段只做数据准备,不修改代码。
77
+
78
+ ### Phase 1: Triage
79
+
80
+ 读取评论所指代码和完整 review 线程后,逐条将评论分类为:
81
+
82
+ - `valid-fix` — 存在真实问题,需要代码修改
83
+ - `valid-nofix` — 问题成立,但不需要改代码
84
+ - `invalid` — 前提不适用于当前代码,或建议的修复反而有害
85
+
86
+ 如果线程很多且平台支持并行 agent,Triage 会并行执行以提高速度。
87
+
88
+ > [!TIP]
89
+ > Triage 默认偏保守。如果某条评论含义不清,可直接标记为 `invalid`,原因写 `unclear — needs human review`。
90
+
91
+ ### Phase 2: Fix
92
+
93
+ 对每条 `valid-fix` 线程,由专门的 implementation agent 施加满足 review 要求的最小改动。修改前先追踪引用关系;如果改动影响函数签名、类型或导出,会同步更新调用方和测试;不顺手做无关的重构或清理。
94
+
95
+ 本阶段所有修复都会提交到本地,但 **不会推送**。
96
+
97
+ 全部修复完成后会执行:
98
+
99
+ ```bash
100
+ npx tsc --noEmit
101
+ ```
102
+
103
+ 如果类型检查失败,流程会自动定位引入错误的提交,回滚、修复后重新提交,再继续后续阶段。
104
+
105
+ ### Phase 3: Reply
106
+
107
+ 编排器基于以下信息逐条起草回复:
108
+
109
+ - 原始线程数据
110
+ - Triage 结论
111
+ - 实际变更:`git diff origin/{branch}...HEAD`
112
+ - Phase 2 中的失败记录
113
+
114
+ 回复会尽量匹配评论者的语言和语气,保持简洁,避免防御性措辞。
115
+
116
+ ### Phase 4: Post & Push
117
+
118
+ 将用户确认后的回复发布到 GitHub,并把本地的 review-fix 提交统一推送。
119
+
120
+ 可选地,流程还可以:
121
+
122
+ - 向原 reviewer 请求 re-review
123
+ - 将已处理的 review 线程标记为“Addressed”并关闭
124
+
125
+ ### Phase 5: Report
126
+
127
+ 最后输出简要总结:
128
+
129
+ ```
130
+ ✅ Triage: N/N 条线程已处理
131
+ ✅ Fixes: M/K 条 valid-fix 已应用(本地提交并推送)
132
+ ❌ Failed: {thread} — {reason}
133
+ ✅ Replies: P/P 条回复已起草并发布
134
+ ```
135
+
136
+ ## 使用方法
137
+
138
+ ### 在 agent 中调用
139
+
140
+ 安装为 skill 后,直接用自然语言发起请求即可。常见触发方式包括:
141
+
142
+ - "帮我处理这个 PR 的 review:<https://github.com/owner/repo/pull/123>"
143
+ - "回复 reviewer 的评论"
144
+ - "看看 PR 里那些 unresolved threads"
145
+ - "review 提的问题要修一下"
146
+ - "CI 过了,但 review 还没回"
147
+ - "someone left comments on my PR"
148
+ - "帮我看看那些人提的意见"
149
+
150
+ ### 命令行手动驱动
151
+
152
+ 如果你希望手动控制流程,也可以直接基于 GitHub CLI 命令执行。本 skill 和包的主要价值,是把这些命令封装成 agent 可理解、可执行的结构化流水线。
153
+
154
+ ## 环境要求
155
+
156
+ - 已安装并登录 GitHub CLI(`gh`)
157
+ - Git 工作区足够干净,可以创建 review-fix 提交
158
+ - 若想执行最后的 `tsc --noEmit` 检查,项目应为 Node.js / TypeScript 项目
159
+
160
+ ## 支持的平台
161
+
162
+ | 平台 | 支持情况 |
163
+ | --- | --- |
164
+ | npm / Node.js | ✅ 可作为已发布包安装 |
165
+ | Pi | ✅ 支持作为 package 和 skill 使用 |
166
+ | Claude Code | ✅ 通过 Task 机制分发 agent |
167
+ | Cursor | ✅ 通过 background agent 分发 |
168
+ | 其他 agent 客户端 | ✅ 使用 `agents/` 中的 agent 规格,以内联方式运行 |
169
+
170
+ ## 备注
171
+
172
+ - 项目在 `agents/` 中提供可复用的 agent 规格。
173
+ - 若平台支持并行 agent,Triage 可并行执行;否则以内联方式运行。
174
+ - 流程中有两处会暂停等待确认:一次在 Triage 结论出来后,一次在发布回复前。
175
+ - 推送仅在回复确认后执行一次。
176
+ - Fix 阶段默认串行执行,以避免并发修改带来的冲突。
package/SKILL.md ADDED
@@ -0,0 +1,320 @@
1
+ ---
2
+ name: pr-review-handler
3
+ description: >
4
+ Systematically process GitHub PR review comments: triage for validity,
5
+ fix code, and post replies. Use whenever the user mentions PR reviews,
6
+ code review feedback, reviewer comments, or wants to respond to review
7
+ threads on a pull request. Triggers include: "handle reviews",
8
+ "respond to PR comments", "fix review feedback", "reply to reviewer",
9
+ "看看 PR 评论", "回一下 review", "处理 review 意见",
10
+ "reviewer 说的那个问题", or any mention of dealing with PR review
11
+ comments. Also triggers when the user pastes a PR link with unresolved
12
+ conversations, mentions a reviewer by name in the context of their PR,
13
+ or describes the situation: "someone left comments on my PR",
14
+ "帮我看看那些人提的意见", "CI 过了但 review 还没回".
15
+ ---
16
+
17
+ # PR Review Handler
18
+
19
+ Orchestrate specialized agents to process PR review comments:
20
+
21
+ ```
22
+ Phase 0: Setup → Phase 1: Triage (parallel) → Phase 2: Fix (serial)
23
+ → Phase 3: Reply → Phase 4: Post & Push → Phase 5: Report
24
+ ```
25
+
26
+ Checkpoints: after Phase 1 (user confirms verdicts) and after Phase 3 (user approves replies).
27
+
28
+ ## Agent Definitions
29
+
30
+ ### Roles
31
+
32
+ | Role | Responsibility | Parallelizable |
33
+ |------|---------------|----------------|
34
+ | Triage Agent | Verify comment validity, classify verdict | ✅ Yes (read-only) |
35
+ | Implementation Agent | Apply minimal code fix for one thread | ❌ No (writes files) |
36
+ | Reply drafting | Orchestrator drafts inline (no separate agent) | N/A |
37
+
38
+ ### Platform mapping
39
+
40
+ Each role maps to a different agent depending on the platform. Agent specs for reference are in `agents/` relative to this skill.
41
+
42
+ | Role | Pi | Claude Code | Cursor | No-agent fallback |
43
+ |------|-----|-------------|--------|-------------------|
44
+ | Triage | `pr-review.triage` | Task tool | background agent | inline (read spec, execute yourself) |
45
+ | Implementation | `pr-review.implementation` | Task tool | background agent | inline (read spec, execute yourself) |
46
+ | Reply | inline (orchestrator) | inline | inline | inline |
47
+
48
+ **Pi users**: runtime agents are registered in `.agents/agents/pr-review/` at the project root. They include full system prompts, tool constraints, and output format — dispatch with task prompt containing only the input data (thread info, verdict data).
49
+
50
+ **Other platforms**: read the agent specs in `agents/` relative to this skill (`agents/triage-agent.md`, `agents/implementation-agent.md`), embed the instructions into the task prompt, and dispatch using your available subtask mechanism. If no subtask mechanism exists, execute inline.
51
+
52
+ ## Phase 0: Setup
53
+
54
+ ### Identify the PR
55
+
56
+ ```bash
57
+ gh pr list --state open --json number,title,url,headRefName
58
+ ```
59
+
60
+ Match against current branch (`git branch --show-current`). Use user-supplied PR if specified. Checkout PR branch if needed.
61
+
62
+ ```bash
63
+ git fetch origin
64
+ ```
65
+
66
+ ### Fetch unresolved review threads
67
+
68
+ **Preferred: GraphQL** (filters resolved threads):
69
+
70
+ ```bash
71
+ gh api graphql -f query='
72
+ query($owner: String!, $repo: String!, $pr: Int!) {
73
+ repository(owner: $owner, name: $repo) {
74
+ pullRequest(number: $pr) {
75
+ reviewThreads(first: 100) {
76
+ nodes {
77
+ isResolved
78
+ comments(first: 10) {
79
+ nodes {
80
+ databaseId
81
+ body
82
+ path
83
+ line
84
+ author { login }
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+ }
91
+ }
92
+ ' -f owner={owner} -f repo={repo} -F pr={pr_number}
93
+ ```
94
+
95
+ Filter `isResolved: false`. Include full thread (not just top-level) — follow-up replies often contain the real concern.
96
+
97
+ **Fallback: REST** (when GraphQL unavailable):
98
+
99
+ ```bash
100
+ gh api repos/{owner}/{repo}/pulls/{pr_number}/comments \
101
+ --jq 'group_by(.path, .original_commit_id) | map({
102
+ thread_id: .[0].id, path: .[0].path,
103
+ comments: [.[] | {id, body, user: .user.login, line, in_reply_to_id}]
104
+ })'
105
+ ```
106
+
107
+ REST cannot detect resolved threads — ask user to confirm which threads need attention.
108
+
109
+ ### Fetch review-level feedback
110
+
111
+ Review-level feedback (summary comments without line references) is separate from thread comments. Always fetch:
112
+
113
+ ```bash
114
+ gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews \
115
+ --jq 'sort_by(.submitted_at) | reverse | .[:5] | .[] | {id, state, user: .user.login, body}'
116
+ ```
117
+
118
+ Include any non-empty review bodies alongside the thread data when presenting to the user in Phase 2.
119
+
120
+ ## Phase 1: Triage (parallel dispatch)
121
+
122
+ ### Dispatch strategy
123
+
124
+ Triage is read-only — safe to parallelize.
125
+
126
+ - **≥3 threads + parallel capability**: spawn one Triage Agent per thread simultaneously
127
+ - **≤2 threads or no parallel capability**: run inline, same logic
128
+
129
+ If unsure about parallel capability, default to inline.
130
+
131
+ ### Dispatch
132
+
133
+ For each unresolved thread, dispatch the Triage Agent with this task data:
134
+
135
+ ```
136
+ thread_id: <comment ID>
137
+ path: <file:line>
138
+ reviewer: <reviewer username>
139
+ comments:
140
+ - <top-level comment text>
141
+ - <reply 1, if any>
142
+ - <reply 2, if any>
143
+ ```
144
+
145
+ The agent already has its role instructions and output format built in. Do not embed role instructions in the task prompt — only pass the thread-specific data above.
146
+
147
+ Collect structured verdicts from all agents.
148
+
149
+ ### Checkpoint 1: User confirmation
150
+
151
+ Present verdicts as a summary table:
152
+
153
+ | # | File:Line | Reviewer | Summary | Verdict | Affected Files |
154
+ |---|-----------|----------|---------|---------|----------------|
155
+ | 1 | src/auth/login.ts:42 | alice | Missing null check | valid-fix | login.ts, types.ts |
156
+ | 2 | src/ui/Button.tsx:18 | bob | Rename for clarity | valid-fix | Button.tsx |
157
+ | 3 | src/api/handler.ts:99 | alice | Add rate limiting | invalid | — |
158
+
159
+ User can adjust verdicts or skip threads. Proceed with confirmed plan.
160
+
161
+ ### Quick exits
162
+
163
+ - **All invalid**: skip Phase 2, go to Phase 3 for reply drafting
164
+ - **All valid-nofix**: skip Phase 2, go to Phase 3
165
+ - **User rejects all**: end workflow
166
+
167
+ ## Phase 2: Implementation (serial dispatch)
168
+
169
+ ### Fix ordering
170
+
171
+ 1. **User-specified order** from Phase 1 confirmation
172
+ 2. **Otherwise dependency-first**: types → implementation → callers → tests
173
+ 3. **Same level**: PR order
174
+
175
+ ### Dispatch
176
+
177
+ For each `valid-fix` thread, dispatch the Implementation Agent with this task data:
178
+
179
+ ```
180
+ thread_id: <comment ID>
181
+ path: <file:line>
182
+ reviewer: <name>
183
+ summary: <what the reviewer wants>
184
+ verdict: valid-fix
185
+ affected_files:
186
+ - <file1>
187
+ - <file2>
188
+ suggested_fix: <what to change>
189
+ prior_changes: <list of previous fixes in this PR, if any>
190
+ ```
191
+
192
+ The agent already has its role instructions and output format built in. Pass only the verdict data above.
193
+
194
+ After each agent completes:
195
+
196
+ ```bash
197
+ git add -A
198
+ git commit -m "fix(review): {thread summary}"
199
+ ```
200
+
201
+ If commit is empty (agent made no changes), skip.
202
+
203
+ ### After all fixes
204
+
205
+ ```bash
206
+ npx tsc --noEmit
207
+ ```
208
+
209
+ If tsc fails:
210
+
211
+ - Identify which commit introduced the error (`git bisect` or check error file paths)
212
+ - `git revert --no-commit {commit}` → fix the error → recommit
213
+ - Re-run tsc until clean
214
+
215
+ Also check:
216
+
217
+ - Orphan references to removed/renamed symbols (`grep -r`)
218
+ - Translation keys in all message files if `t()` calls were added
219
+
220
+ ### Never push during this phase
221
+
222
+ All commits stay local. Push happens once in Phase 4.
223
+
224
+ ## Phase 3: Reply (orchestrator drafts inline)
225
+
226
+ The orchestrator drafts replies directly — no separate agent needed. This phase has full access to all pipeline context.
227
+
228
+ Gather:
229
+
230
+ - **Original thread data**: all comments from Phase 0
231
+ - **Triage verdicts**: all structured verdicts from Phase 1
232
+ - **Actual changes**: `git diff origin/{branch}...HEAD`
233
+ - **Failure records**: which fixes failed and why (from Phase 2)
234
+
235
+ Draft one reply per thread, using `git diff origin/{branch}...HEAD` as ground truth (not planned changes):
236
+
237
+ **valid-fix (succeeded)**: describe what was changed, referencing the reviewer's concern. If the fix differs from what the reviewer suggested, explain why.
238
+
239
+ **valid-fix (failed)**: acknowledge the concern was valid. Explain why the fix couldn't be applied (type conflict, dependency issue). Suggest next steps if possible ("will address in a follow-up PR"). Don't be apologetic — just factual.
240
+
241
+ **valid-nofix**: acknowledge the concern is valid. Explain why no code change is needed. Provide clarification if the reviewer misunderstood the code.
242
+
243
+ **invalid**: explain clearly why the premise doesn't apply. Reference specific code that already handles the concern. Acknowledge the reviewer's intent ("I see why you'd think X, but..."). Be respectful but direct — don't hedge if the concern is genuinely wrong.
244
+
245
+ ### Reply guidelines
246
+
247
+ - Match the reviewer's language (Chinese reviewer → Chinese reply)
248
+ - Match tone (casual → casual, formal → formal)
249
+ - Be concise: 1-3 sentences ideal
250
+ - Don't over-explain — reviewer is a peer, trust they understand code
251
+ - Never be defensive — state facts, acknowledge intent
252
+
253
+ ### Checkpoint 2: User review
254
+
255
+ Present all reply drafts. User can:
256
+
257
+ - Approve all
258
+ - Edit individual replies
259
+ - Reject specific replies
260
+ - Add context to replies
261
+
262
+ ## Phase 4: Post & Push
263
+
264
+ Post approved replies:
265
+
266
+ ```bash
267
+ gh api repos/{owner}/{repo}/pulls/comments/{comment_id}/replies \
268
+ -f body='The response text'
269
+ ```
270
+
271
+ Reply to the top-level comment of each thread (the one with `databaseId`, not a reply).
272
+
273
+ Push all commits:
274
+
275
+ ```bash
276
+ git push origin HEAD
277
+ ```
278
+
279
+ Ask user if they want to:
280
+
281
+ - **Request re-review**: `gh api repos/{owner}/{repo}/pulls/{pr_number}/requested_reviewers -f reviewers='["username"]'`
282
+ - **Dismiss resolved reviews**: `gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews/{review_id}/dismissals -f message='Addressed'`
283
+
284
+ ## Phase 5: Report
285
+
286
+ Output final summary:
287
+
288
+ ```
289
+ ✅ Triage: N/N threads processed
290
+ ✅ Fixes: M/K valid-fix threads applied (committed locally, pushed)
291
+ ❌ Failed: {thread} — {reason}
292
+ ✅ Replies: P/P threads drafted and posted
293
+ ```
294
+
295
+ ## Pipeline Failure Rules
296
+
297
+ | Scenario | Action |
298
+ |----------|--------|
299
+ | Triage: all agents fail | Stop pipeline. Report to user. Cannot proceed without verdicts. |
300
+ | Triage: some agents fail | Skip failed threads. Continue with successful verdicts. Note in final report. |
301
+ | Implementation: all agents fail | Skip Phase 2. Phase 3 only drafts replies for invalid/nofix threads. |
302
+ | Implementation: some agents fail | Skip failed fixes. Mark in failure records for Phase 3. |
303
+ | Reply drafting fails | Should not happen — orchestrator drafts inline. |
304
+
305
+ ## Error Handling
306
+
307
+ | Error | Action |
308
+ |-------|--------|
309
+ | `gh` not installed / not authenticated | Tell user to install GitHub CLI and `gh auth login` |
310
+ | API rate limit | Wait for `X-RateLimit-Reset`, retry |
311
+ | PR closed/merged | Warn user — replies have no effect |
312
+ | GraphQL unsupported | Fall back to REST with resolved-thread caveat |
313
+ | tsc fails after all fixes | Fix before posting replies |
314
+
315
+ ## Key Principles
316
+
317
+ These apply across all agents and phases:
318
+
319
+ - **Trace all references after removals.** Deleting a function, type field, or import creates orphans in callers, tests, and type usages. Search the entire codebase for the symbol. This is the #1 cause of "fixed the review but broke the build."
320
+ - **Don't guess on ambiguous threads.** If a concern is partially valid or unclear, mark for user decision in Checkpoint 1. A wrong reply is worse than no reply.
@@ -0,0 +1,105 @@
1
+ # Implementation Agent
2
+
3
+ You are a code fix specialist for PR review comments. Your job is to apply minimal, surgical fixes that address exactly what the reviewer asked for.
4
+
5
+ ## Role
6
+
7
+ - Read the affected code and understand its context
8
+ - Apply the smallest possible change that satisfies the review comment
9
+ - Report what you changed so the orchestrator can commit
10
+
11
+ You do NOT run type checks. You do NOT commit. You do NOT draft replies. You only fix code.
12
+
13
+ ## Input
14
+
15
+ You receive one review verdict:
16
+
17
+ ```
18
+ thread_id: <comment ID>
19
+ path: <file:line>
20
+ reviewer: <name>
21
+ summary: <what the reviewer wants>
22
+ verdict: valid-fix
23
+ reason: <why this is valid>
24
+ affected_files:
25
+ - <file1>
26
+ - <file2>
27
+ suggested_fix: <what to change>
28
+ ```
29
+
30
+ You may also receive context from prior fixes in the same PR:
31
+
32
+ ```
33
+ prior_changes:
34
+ - <file>: <what was changed and why>
35
+ ```
36
+
37
+ ## Steps
38
+
39
+ ### 1. Read all affected files
40
+
41
+ Open every file in `affected_files`. Understand how they relate to each other — imports, exports, type dependencies, call chains.
42
+
43
+ If `prior_changes` is provided, pay special attention to files that were already modified by previous fixes in this PR. Your changes must be compatible with those prior changes.
44
+
45
+ ### 2. Trace references
46
+
47
+ Before changing anything, search for all usages of the symbols you are about to modify:
48
+
49
+ - Function/method callers
50
+ - Type references
51
+ - Import statements
52
+ - Test assertions
53
+
54
+ This prevents the most common failure mode: fixing the reviewed code but breaking a caller.
55
+
56
+ ### 3. Apply minimal fix
57
+
58
+ Change only what the review asks for. Specifically:
59
+
60
+ - Do NOT refactor surrounding code, even if it looks messy
61
+ - Do NOT improve comments or formatting
62
+ - Do NOT add "while I'm here" improvements
63
+ - Do NOT change variable names unrelated to the review
64
+ - Do NOT add error handling for scenarios the reviewer didn't mention
65
+
66
+ If the review says "add null check", add a null check. Nothing more.
67
+
68
+ ### 4. Handle cascading changes
69
+
70
+ If your fix changes a function signature, type, or export:
71
+
72
+ - Update all callers you found in step 2
73
+ - Update test files that reference the changed symbol
74
+ - Add new translation keys to ALL message files if you add `t()` calls
75
+
76
+ ### 5. Verify locally
77
+
78
+ After making changes:
79
+
80
+ - Re-read the modified files to confirm changes are correct
81
+ - Check that no obvious syntax errors exist
82
+ - Ensure imports are still valid (no removed imports still referenced)
83
+
84
+ Do NOT run `tsc` or `lint` — the orchestrator handles that after all fixes.
85
+
86
+ ## Output
87
+
88
+ Report your changes:
89
+
90
+ ```yaml
91
+ thread_id: <id>
92
+ files_modified:
93
+ - path: <file>
94
+ lines: <line range or description>
95
+ change: <what you changed and why>
96
+ concerns: <any issues you noticed but didn't fix, empty if none>
97
+ ```
98
+
99
+ ## Constraints
100
+
101
+ - **Scope**: only modify files listed in `affected_files`. If you discover a file that needs changes but isn't listed, report it in `concerns` rather than modifying it
102
+ - **No commits**: the orchestrator commits after your changes
103
+ - **No type checks**: the orchestrator runs `tsc` after all fixes are applied
104
+ - **No pushes**: never run `git push`
105
+ - **Minimal changes**: the smallest diff that satisfies the review comment
@@ -0,0 +1,88 @@
1
+ # Triage Agent
2
+
3
+ You are a PR review triage specialist. Your job is to evaluate whether a reviewer's concern is valid and classify it for downstream processing.
4
+
5
+ ## Role
6
+
7
+ - Read code and review comments objectively
8
+ - Verify the reviewer's premise against actual code
9
+ - Produce structured verdicts that drive the fix and reply pipeline
10
+
11
+ You do NOT modify files. You do NOT draft replies. You only analyze and classify.
12
+
13
+ ## Input
14
+
15
+ You receive one review thread:
16
+
17
+ ```
18
+ thread_id: <comment ID>
19
+ path: <file path>
20
+ line: <line number>
21
+ reviewer: <reviewer username>
22
+ comments:
23
+ - [top-level comment]
24
+ - [reply 1, if any]
25
+ - [reply 2, if any]
26
+ ```
27
+
28
+ ## Steps
29
+
30
+ ### 1. Read the referenced code
31
+
32
+ Open `{path}` and examine the code at `{line}` plus surrounding context (±20 lines minimum). Understand what the code does, what it depends on, and what depends on it.
33
+
34
+ ### 2. Read the full thread carefully
35
+
36
+ The top-level comment may be refined, overridden, or clarified by follow-up replies. The actual concern may be in a reply, not the original comment. Weight later comments appropriately — they often represent the reviewer's evolved thinking.
37
+
38
+ ### 3. Verify the premise
39
+
40
+ Check each of these:
41
+
42
+ - **Does the problem exist in current code?** The reviewer may be looking at an older version. The code may have already been changed.
43
+ - **Is the reviewer's logic sound?** Example: "check if count exceeds limit after deletion" is logically impossible if deletion reduces count.
44
+ - **Would their suggested fix introduce new problems?** Sometimes the fix is worse than the problem.
45
+
46
+ ### 4. Classify
47
+
48
+ | Verdict | When to use |
49
+ |---------|-------------|
50
+ | `valid-fix` | Reviewer identified a real problem that requires code changes |
51
+ | `valid-nofix` | Reviewer's concern is valid but no code change needed (e.g., naming is fine as-is, or clarification reply suffices) |
52
+ | `invalid` | Reviewer's premise is wrong — code already handles this, concern doesn't apply to current code, or suggested fix would break things |
53
+
54
+ ### 5. Identify affected files
55
+
56
+ If `valid-fix`, list ALL files that would need changes:
57
+
58
+ - The file being reviewed
59
+ - Callers of any changed function
60
+ - Type definitions if signatures change
61
+ - Test files that test the changed code
62
+ - Import files if exports change
63
+
64
+ This list drives the Implementation Agent's scope — missing a file here means the fix will be incomplete.
65
+
66
+ ## Output
67
+
68
+ Return exactly this structure:
69
+
70
+ ```yaml
71
+ thread_id: <id>
72
+ path: <file:line>
73
+ reviewer: <name>
74
+ summary: <one-line description of the concern>
75
+ verdict: valid-fix | valid-nofix | invalid
76
+ reason: <one sentence explaining why>
77
+ affected_files:
78
+ - <file1>
79
+ - <file2>
80
+ suggested_fix: <brief description of what to change, empty if not valid-fix>
81
+ ```
82
+
83
+ ## Constraints
84
+
85
+ - **Read-only**: do not modify any files
86
+ - **No guesses**: if you cannot determine validity, set verdict to `invalid` with reason "unclear — needs human review"
87
+ - **Be thorough on affected_files**: this list determines what the Implementation Agent is allowed to touch
88
+ - **One thread at a time**: you are dispatched for a single thread, not batch
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@trashcodermaker/pi-pr-review-handler",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "private": false,
7
+ "keywords": [
8
+ "pi-package",
9
+ "pi-skill",
10
+ "pr-review",
11
+ "github",
12
+ "code-review"
13
+ ],
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "files": [
18
+ "SKILL.md",
19
+ "agents",
20
+ "README.md",
21
+ "LICENSE"
22
+ ]
23
+ }