diff --git a/README.en.md b/README.en.md index 6c688f9..df98a99 100644 --- a/README.en.md +++ b/README.en.md @@ -22,7 +22,7 @@ X-Code CLI supports the major LLM providers (Claude, GPT, DeepSeek, Gemini, Qwen - **File attachments** — `@path` mentions or bare absolute paths in the prompt auto-ingest text / code / PDF / docx / xlsx / pptx / images - **Vision sub-agent** — text-only providers such as DeepSeek can borrow another configured vision model to generate image descriptions - **Theme switching** — `/theme` cycles through UI themes, controlling diff colors and syntax-highlight palette -- **Slash commands** — quick controls including `/help`, `/model`, `/thinking`, `/theme`, `/plan`, `/resume`, `/usage`, `/usage-history`, `/memory`, and more +- **Slash commands** — quick controls including `/help`, `/model`, `/thinking`, `/theme`, `/plan`, `/resume`, `/usage`, `/usage-history`, `/memory`, `/review`, and more - **Unified thinking-mode toggle** — `/thinking on|off` consolidates each provider's bespoke thinking/reasoning parameters into a single switch - **Multiline input** — `Alt+Enter` (or `Option+Enter` on macOS) or a trailing `\` followed by Enter inserts a newline; plain Enter still submits - **Cross-platform** — runs on Windows, macOS, and Linux @@ -192,6 +192,7 @@ xc [options] [prompt] | `/compact` | Manually compress context | | `/resume` | Pick a past session in this project to resume | | `/init` | Analyze the codebase and create or update `AGENTS.md` at the project root | +| `/review [PR#]` | Review a GitHub PR (no argument lists open PRs); requires `gh` to be installed locally | | `/memory` | List auto-memory entries (project + global, grouped by category) | | `/exit` | Save the session and exit | diff --git a/README.md b/README.md index 0835004..362c0ed 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ X-Code CLI 支持主流大模型(Claude、GPT、DeepSeek、Gemini、Qwen、Gro - **文件附件**:在提示词中以 `@path` 或裸绝对路径引用文件,自动识别 text / code / PDF / docx / xlsx / pptx / 图片 - **视觉子 agent**:DeepSeek 等纯文本模型可借用其他多模态厂商生成图片描述 - **主题切换**:`/theme` 切换 UI 主题,控制 diff 配色和语法高亮风格 -- **斜杠命令**:`/help`、`/model`、`/thinking`、`/theme`、`/plan`、`/resume`、`/usage`、`/usage-history`、`/memory` 等 +- **斜杠命令**:`/help`、`/model`、`/thinking`、`/theme`、`/plan`、`/resume`、`/usage`、`/usage-history`、`/memory`、`/review` 等 - **统一思考模式开关**:`/thinking on|off` 将不同厂商各异的 thinking/reasoning 参数统一为单一开关 - **多行输入**:`Alt+Enter`(macOS 为 `Option+Enter`)或行尾 `\` 后 Enter 插入换行;普通 Enter 直接发送 - **跨平台**:支持 Windows、macOS、Linux @@ -192,6 +192,7 @@ xc [options] [prompt] | `/compact` | 手动压缩上下文 | | `/resume` | 从当前项目的历史会话中选择一个恢复 | | `/init` | 分析代码库后在项目根创建或更新 `AGENTS.md` | +| `/review [PR号]` | 评审 GitHub PR(无参数列出开放 PR;需本地装好 `gh`) | | `/memory` | 查看当前自动记忆条目(project + global,按类目分组) | | `/exit` | 保存会话并退出 | diff --git a/packages/cli/src/ui/components/App.tsx b/packages/cli/src/ui/components/App.tsx index 4471350..8863e2a 100644 --- a/packages/cli/src/ui/components/App.tsx +++ b/packages/cli/src/ui/components/App.tsx @@ -62,6 +62,7 @@ export const SLASH_COMMANDS = [ { name: '/compact', description: 'Manually compress context' }, { name: '/resume', description: 'Pick a past session in this project to resume' }, { name: '/init', description: 'Initialize project knowledge' }, + { name: '/review', description: 'Review a pull request (no-arg = list open PRs)' }, { name: '/usage', description: 'Show current-session token usage (input/output/cache)' }, { name: '/usage-history', description: 'List past sessions in this project' }, { name: '/memory', description: 'Show auto-memory entries (project + global)' }, @@ -186,6 +187,38 @@ This file is loaded into the agent's context at the start of every session. Keep When you finish, summarize what you wrote (or what you changed if updating an existing file) in a few bullets so the user can review.` +// Prompt body for `/review`. Mirrors Claude Code's local /review: a static +// template that points the agent at `gh` and asks for a structured review. +// `args` is the raw arg string after the command (PR number, or empty). +// +// The no-arg branch is intentionally locked down: empty `gh pr list` output = +// no open PRs, full stop. We've seen the model otherwise spend 8+ tool calls +// checking `gh auth`, branches, uncommitted diffs, etc. before pivoting to +// review whatever it found — wasteful and unrequested. The "use `gh` +// directly — no wrappers" line is there because models occasionally +// hallucinate generic wrappers (rtk, gh-aux, …) on the first call. +const REVIEW_PROMPT = (args: string) => `You are an expert code reviewer. Use \`gh\` directly — no wrappers. + +If no PR number is provided in the args: +1. Run \`gh pr list\` to show open PRs. +2. If the output is empty, reply with exactly: "No open PRs in this repository — re-run \`/review \` to review a specific PR." and stop. +3. Otherwise, list the open PRs and ask the user which to review. Stop and wait. +4. Do NOT investigate further — no \`gh auth\`, no branch / diff / status checks, no reviewing uncommitted changes. The user will re-invoke /review. + +If a PR number is provided: +1. Run \`gh pr view \` to get PR details. +2. Run \`gh pr diff \` to get the diff. +3. Write a concise but thorough review with clear sections and bullet points covering: + - Overview of what the PR does + - Code correctness + - Project conventions + - Performance implications + - Test coverage + - Security considerations + - Specific suggestions and risks + +PR number: ${args}` + export function App({ model, options, @@ -520,6 +553,11 @@ export function App({ await submit(INIT_PROMPT, { silent: true }) return + case 'review': + echoCommand(text) + await submit(REVIEW_PROMPT(arg), { silent: true }) + return + case 'usage': echoCommand(text) await handleUsage()