Pr Review Canvas

cursor/plugins/cursor-team-kit/skills/pr-review-canvas

作者 cursorccb5507cec1546dc88135c1139c811e6c59115ba無授權條款10K 個星標收錄於 2026年10月9日更新於 2026年10月9日儲存庫昨天更新

Generate an interactive PR review walkthrough as an HTML page. Fetches PR data via gh API, categorizes files into core vs mechanical changes, adds reviewer annotations, and renders diffs with moved-code detection. Use when the user pastes a GitHub PR URL and asks for a review, walkthrough, or summary, or says "review this PR".

AI 產生的概覽

產生用於程式碼審查的 GitHub PR 互動式 HTML 導覽頁面。

功能
透過 gh API 取得拉取請求的中繼資料、檔案差異與審查留言,再由代理撰寫帶註解的內文 HTML,將核心變更與機械性變更區分開來。它把該 HTML 連同技能內附的 CSS 與渲染指令碼注入範本,並以 JSON 形式安全嵌入差異補丁。最終產出一個深色主題的 HTML 頁面,包含可收合的檔案卡片、審查者註解,以及能過濾匯入、合併純空白變更並辨識搬移程式碼的差異檢視,透過本機 HTTP 伺服器提供瀏覽。
適用情境
當使用者貼上 GitHub PR 網址並要求審查、導覽或摘要,或直接說「審查這個 PR」時使用。適合想要有引導、有註解的拉取請求閱讀體驗,而非原始差異的審查者。
執行需求
需要可存取目標儲存庫 API 的 GitHub CLI(gh)、Python 3、jq,以及固定連接埠(預設 8432)的本機 HTTP 伺服器。此技能附有可執行指令碼(renderer.js)以及 styles.css 和 template.html,這些檔案會從技能目錄讀取並注入輸出。

PR Review Canvas

Generate an interactive HTML review of a GitHub PR that reads like a peer walking you through what matters.

Workflow

1. Fetch PR data

Run these gh api calls in parallel:

bash
gh api repos/{owner}/{repo}/pulls/{number} --jq '{title, body, user: .user.login, state, additions, deletions, changed_files, base: .base.ref, head: .head.ref}'gh api repos/{owner}/{repo}/pulls/{number}/files --paginate --jq '.[] | {filename, status, additions, deletions, patch}'gh api repos/{owner}/{repo}/pulls/{number}/comments --jq '.[] | {user: .user.login, body, path, line}'

2. Analyze the PR and write the body HTML

Read the diffs, understand the PR, and write the <body> content directly as HTML. You have full creative freedom -- the goal is to explain the PR clearly to a reviewer. Use whatever structure best fits the PR.

Typical structure (adapt as needed):

  • Header with title, PR number, author, stats
  • Summary box explaining what the PR does in plain English
  • Core file sections with annotations and diffs
  • Mechanical/boilerplate files collapsed by default
  • Review checklist at the bottom

But you can also add:

  • Pseudocode summaries for verbose code -- show the algorithm in plain English or short pseudocode, with the real diff collapsed below (use a .bp-section card labeled "Show full implementation"). Great when 150 lines of retry/backoff/error-handling code is really just "fetch with exponential backoff and circuit breaker."
  • Diagrams (inline SVG, mermaid via CDN, ASCII art in <pre>)
  • Flowcharts showing before/after control flow
  • Tables comparing old vs new behavior
  • Callout boxes for warnings, questions, or gotchas
  • Interactive widgets if they help
  • Anything else that makes the review clearer

Pseudocode pattern example:

html
<div class="file-card">  <div class="file-hdr" onclick="toggle(this)">    <span class="fname">retryClient.ts</span>    <div class="fstats"><span class="pill add">+173</span><span class="pill del">&minus;11</span><span class="chev open">&#9654;</span></div>  </div>  <div class="file-body open">    <div class="file-note">      <strong>What this does in plain English:</strong>      <pre style="margin-top:8px;color:var(--text);font-size:12px;line-height:1.6;">fetch(url):  if circuit breaker is open → fail fast  retry up to N times:    try fetch with timeout    on success → close circuit breaker, return    on retryable error → wait (exponential backoff + jitter)    on non-retryable error → throw  circuit breaker records failure</pre>    </div>    <div class="bp-section" style="margin:0;border:0;border-radius:0;">      <div class="bp-hdr" onclick="toggleBP(this)">        <span>Show full implementation (+173 lines)</span><span class="chev">&#9654;</span>      </div>      <div class="bp-body"><div data-diff="retryClient"></div></div>    </div>  </div></div>

3. Available CSS classes and JS utilities

Read styles.css [blocked] and renderer.js [blocked] from this skill directory. These give you a prebuilt dark-themed toolkit. Inject them into template.html [blocked] verbatim.

CSS classes you can use:

ClassPurpose
.header, .header h1, .header-metaPage header
.pill.add, .pill.del, .pill.filesStat badges (+N, -N, N files)
.contentCentered content wrapper (max 900px)
.summarySummary/TL;DR box
.section-titleSection heading with bottom border
.icInline code reference (mono, blue, dark bg)
.file-card, .file-hdr, .file-bodyCollapsible file card (use onclick="toggle(this)" on .file-hdr)
.file-noteSticky reviewer annotation inside a file card
.bp-section, .bp-hdr, .bp-bodyCollapsed boilerplate card (use onclick="toggleBP(this)")
.bp-noteNote inside a boilerplate card
.verdictReview checklist box

JS functions available:

FunctionUsage
toggle(hdrElement)Toggle a .file-body open/closed
toggleBP(hdrElement)Toggle a .bp-body open/closed
renderDiff(target, diffInput)Render a unified diff. target can be a DOM element, string ID, or CSS selector. diffInput can be a raw patch string OR an array of lines -- both work. Automatically filters imports, collapses whitespace-only changes, detects moved code (blue/purple tint).
esc(string)HTML-escape a string

Rendering diffs -- use data-diff attributes with auto-discovery. Put <div data-diff="KEY"></div> placeholders in your body HTML wherever you want a diff rendered. The renderer finds them automatically after DOM load and fills them from the <script id="pr-diffs-json" type="application/json"> element in template.html.

CRITICAL: Patch strings can contain </script> in addition to newlines, backslashes, and quotes. Even json.dumps(...) is not enough if you paste raw output into executable <script> because HTML parsing can terminate the tag early. Never manually embed patch strings in JS/JSON. Instead, use this safe approach:

  1. During the fetch step, save patches to a JSON file using jq (which handles escaping correctly):
bash
gh api repos/{owner}/{repo}/pulls/{number}/files --paginate \  --jq '[.[] | {key: (.filename | gsub("[^a-zA-Z0-9]"; "_")), value: (.patch // "")}] | from_entries' \  > /tmp/pr-patches-{number}.json
  1. During assembly, use Python to safely inject the JSON into template.html:
bash
python3 <<'PY'import jsonfrom pathlib import Path
patches = json.loads(Path('/tmp/pr-patches-{number}.json').read_text())html = Path('/tmp/pr-review-{number}-body.html').read_text()css = Path('styles.css').read_text()js = Path('renderer.js').read_text()tmpl = Path('template.html').read_text()
# Prevent literal </script> from terminating HTML script tags early.safe_json = json.dumps(patches).replace('<', '\\u003c').replace('>', '\\u003e').replace('&', '\\u0026')
out = (  tmpl.replace('/* INJECT_CSS */', css)      .replace('/* INJECT_JS */', js)      .replace('<!-- INJECT_BODY -->', html)      .replace('{"__PR_DIFFS_PLACEHOLDER__":true}', safe_json))
Path('/tmp/pr-review-{number}.html').write_text(out)PY

This guarantees valid JSON and script-safe HTML embedding. The agent writes body HTML to a temp file, then Python assembles everything safely.

The diff data keys should match the data-diff attribute values in the HTML:

html
<div data-diff="path_to_file_ts"></div>

Since renderer.js loads in <head>, you can also call renderDiff(target, lines) directly from inline <script> tags if needed for custom use cases. The function accepts a DOM element, ID string, or CSS selector as target, and a string or array as lines.

You're not limited to these. Add your own inline <style> blocks, <script> blocks, SVGs, diagrams, or anything else. The prebuilt pieces save time but don't constrain you.

4. Assemble and serve

  1. Write your body HTML (everything that goes inside <body>) to /tmp/pr-review-{number}-body.html

  2. Save patches to /tmp/pr-patches-{number}.json using the jq command from step 3 above

  3. Run the Python assembly script from step 3 above (reads styles.css, renderer.js, template.html from this skill directory, injects body + patches safely, writes final HTML)

  4. Start a local server on a fixed port:

    bash
    cd /tmp && python3 -m http.server 8432 --bind 127.0.0.1

    Run this backgrounded, then navigate the in-app browser to http://127.0.0.1:8432/pr-review-{number}.html.

    Why a fixed port and cd /tmp: Background shells have no TTY, so Python buffers its startup message ("Serving HTTP on...") indefinitely — using port 0 means you can never read which port was chosen. And --directory /tmp works but cd /tmp is more robust across Python versions. If port 8432 is taken, try 8433, 8434, etc.

Diff features (handled automatically by renderer.js)

  • Filters out import-only lines
  • Collapses whitespace-only changes into context lines
  • Detects moved code blocks (3+ consecutive lines deleted in one place and added identically elsewhere) -- renders in blue/purple instead of red/green
  • Near-matches (moved + small edit) get a different purple tint

Style notes

  • Dark theme: #1a1a1a background, Inter body font, IBM Plex Mono for code
  • Use var(--warning) for orange, var(--success) for green, var(--danger) for red, var(--accent) for blue
  • Sticky file headers (position: sticky; top: 0) and notes (top: 35px) pin while scrolling
  • Core files expanded by default (.file-body.open), mechanical files collapsed

來源與署名

來源:cursor/plugins位於cursor-team-kit/skills/pr-review-canvas提交ccb5507

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架