Workflow: PR Link → Fetch Review Comments → Understand User Approach → Design Document → Checkout Source Branch → Propose Changes → User Confirm → Apply & Push → Reply Unaddressed Comments
CLI command name:
gitcode — full command name, works on all platforms (recommended on Windows)gc — short alias, works on macOS/Linux (conflicts with PowerShell Get-Content on Windows)gitcode CLI detection (follow this order):
gitcode --version first (recommended, works everywhere)gc --version (macOS/Linux fallback)gitcode CLI authentication check:
After confirming the CLI is installed, try a lightweight command to verify authentication (e.g., gitcode pr view ). If it returns a token-related error, the CLI is not authenticated.
Stop and prompt the user to authenticate first:
gitcode auth login
Or if they have a token, use --with-token (not --token):
echo <your_token> | gitcode auth login --with-token
Windows note: If the CLI outputs emoji characters and throws UnicodeEncodeError: 'gbk' codec can't encode character, set the Python IO encoding before running CLI commands:
$env:PYTHONIOENCODING="utf-8"
gitcode pr view <number> --repo <owner>/<repo>
Do not proceed with the workflow until authentication is successful.
Windows note: On PowerShell, gc is an alias for Get-Content. Always use gitcode on Windows.
Accept a PR URL from the user. The URL format is:
https://gitcode.com/<owner>/<repo>/pulls/<number>
Parse from the URL:
owner: Repository ownerrepo: Repository namenumber: PR numberFetch PR details:
gitcode pr view <number> --repo <owner>/<repo>
Key info to extract:
head): the branch being merged frombase): the branch being merged into⚠️ If the PR is closed or already merged, warn the user and stop.
Fetch comments on the PR to identify review feedback:
gitcode pr view <number> --repo <owner>/<repo> --comments
Or use the GitCode API:
curl.exe -s "https://api.gitcode.com/api/v5/repos/<owner>/<repo>/pulls/<number>/comments?access_token=<token>"
Parse and categorize comments:
Present to user:
Save review comments to temp/pr_review_comments.json for reference:
{
"pr": {
"owner": "<owner>",
"repo": "<repo>",
"number": <number>,
"source_branch": "<head_branch>",
"target_branch": "<base_branch>",
"source_repo": "<fork_owner>/<repo>"
},
"review_comments": [
{
"id": <comment_id>,
"author": "<username>",
"created_at": "<timestamp>",
"path": "<file_path_or_null>",
"line": <line_number_or_null>,
"body": "<comment_text>",
"requires_code_change": true
}
]
}
If no review comments require code changes, summarize the comments and ask whether the user wants any non-code response; do not enter the modification workflow.
If one or more review comments require code changes, must stop here before checkout, file editing, or concrete implementation planning. Ask the user for their intended modification approach, then apply the essence of the understand-me workflow until the user explicitly confirms the approach.
Required conversation flow:
depends on: D1Suggested response shape during this step:
## 我的理解
<PR context + review comment summary + user's approach>
## 设计决策树(当前版本)
- D1: <review intent/scope>
- A: ...
- B: ...
- D2: <implementation direction>
- depends on: D1
- A: ...
- B: ...
## 当前要拷问的问题
<one question only>
**我的推荐答案:** <recommended answer>
**推荐理由:** <brief reason>
Do not move to Step 4 until the approach is confirmed.
Must generate a design document after the user confirms the modification approach and before any code modification.
Create a Markdown design document under temp/ first, for example:
temp/pr-<number>-review-comment-design.md
The design document must include:
After writing the document:
Do not move to Step 5 until the design document is confirmed.
Must confirm with user before proceeding:
cd <repo_path>
git status
git log --oneline -3
# Check if remote already exists
git remote -v
# Add remote for the source fork if needed
git remote add <source_remote_name> <source_repo_url>
# or if it already exists, just fetch
git fetch <source_remote_name>
# Create/check out the local tracking branch
git checkout -b <local_branch_name> <source_remote_name>/<source_branch>
# Or if already exists locally:
git checkout <local_branch_name>
git pull <source_remote_name> <source_branch>
⚠️ Important:
git stash) and warn the usergit log --oneline -3 should show PR-related commitsgit pull <source_remote_name> <source_branch>
For each review comment that requires code changes:
read toolPresent the modification plan to the user:
For each review comment:
## 检视意见 #N
**Reviewer**: <author>
**文件**: <file_path>
**行号**: L<line>
**意见**: <original comment text>
### 修改方案
**修改文件**: <file_path>
**修改位置**: L<start>-L<end>
**修改方式**: <description of the change>
**理由**: <explanation of how this addresses the review comment>
Group related changes if multiple comments affect the same file.
Wait for user confirmation before proceeding. If the user requests adjustments, revise the plan and re-present.
⚠️ External write constraint: All file modifications require explicit user approval. Show the complete plan first, then ask: "是否确认按以上方案进行修改?(yes/no)"
### Step 7: Apply Changes
After user approval:
1. Apply each change using the `edit` tool:
edit
2. **Verify changes:**
cd
git diff
3. Show the complete diff to the user for final confirmation before committing.
### Step 8: Commit & Push to Source Branch
#### 8.1 Commit
Commit message format: `[type]([module]): address review comments`
Use a descriptive type:
- `fix`: Bug fixes from review
- `refactor`: Code structure improvements
- `style`: Formatting/style changes
- `docs`: Documentation updates
git add
git commit -m "
For multiple distinct changes, consider separate commits per logical change.
#### 8.2 Push
**⚠️ Must confirm the push remote with the user.**
git remote -v
git push
**Important:**
- Push to the **same branch** that the PR is based on
- If the user's fork is the source, push to their fork remote
- If the user has write access to the upstream repo, they may push directly
#### 8.3 Confirm & Report
After push, present a summary:
| Item | Value |
|:---|:---|
| PR URL | `https://gitcode.com/<owner>/<repo>/pulls/<number>` |
| PR Number | `#<number>` |
| Source Branch | `<source_branch>` |
| Target Branch | `<target_branch>` |
| Files Changed | `<count>` |
| Review Comments Addressed | `<count>` |
| Status | Changes pushed |
Optionally, post a comment on the PR acknowledging the review and confirming changes:
感谢审查!已根据检视意见修改并推送到源分支。
修改内容:
**⚠️ Posting PR comments requires user confirmation before executing.**
### Step 9: Reply to Unaddressed Review Comments
After pushing code changes, identify review comments that were **not addressed** in this round (skipped, deferred, or out of scope) and reply to them on the PR to close the loop.
#### 9.1 Identify Unaddressed Comments
From the review comments collected in Step 2, identify comments that:
- Were **not modified** in the code changes (Steps 6-7)
- Were **not already resolved/closed** by the reviewer
- Were **not already replied to** by the PR author
Cross-reference with the design document's "Non-goals" section and the user's confirmed modification scope.
#### 9.2 Ask User for Confirmation
Present the list of unaddressed comments to the user:
| # | 严重度 | 文件 | 意见摘要 | 建议回复 | |
|---|---|---|---|---|---|
| --- | -------- | ------ | ---------- | ---------- | |
| 8 | 建议 | interface.ts | status 移除 \ | string | 暂不修改,后续单独处理 |
| 14 | 建议 | KernelE2ETimeTable.tsx | rowClassName 性能优化 | 暂不修改,建议级优化后续单独处理 | |
| ... | ... | ... | ... | ... |
是否需要回复这些检视意见?
**Ask the user:**
1. Whether to reply to unaddressed comments
2. If yes, whether to use the suggested replies or customize them
3. For each comment, the user may provide a different reply text
**⚠️ Must get user confirmation before posting any replies.**
#### 9.3 Reply via GitCode API
Use the Reply to PR Comment API to post replies within each comment's discussion thread.
**Get the access token** from gitcode CLI config:
TOKEN=$(python -c "from gitcode_cli.config import get_token; print(get_token())")
**Reply to a comment** using its `discussion_id` (obtained from Step 2's API response):
echo '{"body": "
curl -s -X POST \
"https://api.gitcode.com/api/v5/repos/
-H "Content-Type: application/json" \
-d @/tmp/reply_body.json
**Batch reply example** (same reply for multiple comments):
TOKEN=$(python -c "from gitcode_cli.config import get_token; print(get_token())")
echo '{"body": "暂不修改,建议级优化后续单独处理。"}' > /tmp/reply_body.json
for did in "
curl -s -X POST \
"https://api.gitcode.com/api/v5/repos/
-H "Content-Type: application/json" \
-d @/tmp/reply_body.json
done
**⚠️ Notes:**
- The `discussion_id` comes from the `GET /repos/{owner}/{repo}/pulls/{number}/comments` API response's `discussion_id` field
- On Windows, always write JSON body to a file first and use `-d @file.json` to avoid encoding issues with non-ASCII characters
- Each reply is posted within the existing discussion thread, keeping the conversation context
- Clean up temp files after replying: `rm -f /tmp/reply_body.json`
#### 9.4 Confirm & Report
After replying, present a summary:
| # | 检视意见 | discussion_id | 回复内容 | note_id |
|---|----------|---------------|----------|---------|
| 8 | status \| string | `92909e71...` | 暂不修改,后续单独处理 | 173582636 |
| ... | ... | ... | ... | ... |
Total: **N** unaddressed comments replied.
## Key Constraints
### Safety Rules
1. **Never push to the wrong branch** — always verify the source branch before pushing
2. **Never modify files without user approval** — always show proposed changes first
3. **Never assume repository paths** — always confirm with user
4. **Never assume push remote** — always list remotes and ask user to choose
5. **All external write operations require explicit user confirmation**
### Git Workflow Rules
1. Always pull latest from source branch before making changes
2. Stash dirty working trees before checking out
3. Commit messages must be descriptive and reference the PR number
4. Always verify changes with `git diff` before committing
### Asking vs Doing
| Action | Ask First? |
|:---|:---|
| Parse PR URL, fetch PR info | ❌ Just do it |
| Fetch review comments | ❌ Just do it |
| Confirm local repo path | ✅ Must confirm |
| Checkout source branch | ✅ Confirm branch name |
| Ask/challenge modification approach | ✅ Required if comments need code changes |
| Generate design document | ✅ Required before code modification |
| Confirm design document | ✅ Required before code modification |
| Read files, analyze code | ❌ Just do it after design confirmation |
| Propose changes | ❌ Present plan |
| Modify files | ✅ Wait for approval |
| Commit changes | ✅ Show commit message |
| Push to remote | ✅ Confirm remote and branch |
| Post PR comment | ✅ Always confirm |
| Reply to unaddressed review comments | ✅ Always confirm |
## Temp File Management
All temporary files generated during the workflow must be stored in `temp/` directory under the workspace:
workspace/temp/
├── pr_review_comments.json # Downloaded review comments
├── pr-
├── *.md # Review notes
└── * # Other temp files
**⚠️ Clean up `temp/` directory after workflow completion:**
Remove-Item -Recurse -Force temp/ # Windows
rm -rf temp/ # Linux/macOS
## GitCode API Reference (PR Comments)
See [references/gitcode-api.md](references/gitcode-api.md) for full API reference.
### Get PR Comments
GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/pulls/{number}/comments?access_token=
### Post PR Comment
POST https://api.gitcode.com/api/v5/repos/{owner}/{repo}/pulls/{number}/comments?access_token=
Body:
{
"body": "
"commit_id": "
"path": "
"position":
}
### Get PR Diff
GET https://gitcode.com/api/v5/repos/{owner}/{repo}/pulls/{number}/diff
Headers:
Authorization: Bearer
Note: Diff endpoint uses `gitcode.com` not `api.gitcode.com`.
### Reply to PR Comment
Reply to an existing PR review comment within its discussion thread.
POST https://api.gitcode.com/api/v5/repos/{owner}/{repo}/pulls/{number}/discussions/{discussion_id}/comments?access_token=
Body:
{
"body": "
}
The `discussion_id` is obtained from the `GET /repos/{owner}/{repo}/pulls/{number}/comments` response's `discussion_id` field.
## PowerShell Notes
- Use `;` to chain commands (not `&&`)
- Use `curl.exe` (not `curl` which aliases to `Invoke-WebRequest`)
- For JSON payloads, write to file first then use `-d @file.json` to avoid escaping issues
- Remove temp files: `Remove-Item -Recurse -Force temp/`
共 2 个版本