From prd-pilot
PRD-to-code conflict detection. Activate when: (1) user asks to audit/check/validate a PRD against existing code, (2) user says "prd:audit", "审 PRD", "需求冲突检测", "PRD 审查", (3) user provides a PRD document and asks if it conflicts with current implementation, (4) before Spec Coding to validate requirements feasibility. Output: structured audit report with CONFLICT/WARNING/GAP/PASS findings, each backed by code evidence (file path + line numbers). NOT for: plan generation, code review, writing PRDs, or tasks better handled by spec-kit / Superpowers.
How this skill is triggered — by the user, by Claude, or both
Slash command
/prd-pilot:prd-pilotThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Analyze a PRD document against a project codebase to detect conflicts, gaps, and implementation risks
CHANGES.mdDIFF_MODE_SUMMARY.mdREADME.mdreferences/audit-output-format.mdreferences/diff-mode-guide.mdreferences/diff-mode-quick-ref.mdreferences/diff-mode-scenarios.mdreferences/feishu-mcp-integration.mdreferences/infrastructure.mdreferences/plan-output-format.mdreferences/requirement-taxonomy.mdreferences/review-output-format.mdAnalyze a PRD document against a project codebase to detect conflicts, gaps, and implementation risks before coding begins. Output a structured audit report with evidence-backed findings.
Use Diff Mode when:
prd:audit --diff <old.md> <new.md> commandWhy Diff Mode matters: PRD audits are expensive. Diff Mode detects content changes (via fingerprinting), then re-scans only modified requirements, inheriting PASS/GAP findings from unchanged sections. On typical 5-10% PRD changes, this reduces audit time by 85-90%.
After reading PRD in Stage 1, immediately check for cached audit:
For Feishu documents (with MCP):
doc_id from the PRD URL (format: https://xxx.feishu.cn/docx/{doc_id})mcp__feishu-docs__search-doc with empty query to retrieve document metadatadoc_id and extract update_time and create_time.prd-pilot/prd/ for cache file with matching doc_id in frontmatter.prd-pilot/prd/user-login-v1.md has doc_id: xxxxxx + feishu_update_time: 2026-04-10 → cache foundFor local markdown files:
{filename}-cached.md in .prd-pilot/prd/audit_prd.md → look for audit_prd-cached.mdIf no cache found → skip Diff Mode, execute full Phase 1, then run Step C4 (cache write)
Note: Feishu MCP integration provides authoritative update_time from the server, enabling precise version tracking without relying on content inspection alone.
Cache Staleness Pre-Check (before fingerprint comparison):
Even if fingerprint matches, verify cache is still valid:
**Cache Staleness Check (Executable Commands):**
```bash
# Rule 1: Check cache age
CACHE_FILE=".prd-pilot/audit-YYYY-MM-DD.md"
CACHE_AGE_DAYS=$(( ($(date +%s) - $(stat -f%m "$CACHE_FILE" 2>/dev/null)) / 86400 ))
if [ "$CACHE_AGE_DAYS" -gt 30 ]; then
# Rule 2: Check if >20% of code files changed since cache
TOTAL_CODE_FILES=$(find {project_dir} -type f \( -name "*.go" -o -name "*.ts" -o -name "*.py" -o -name "*.java" -o -name "*.js" \) | wc -l)
CHANGED_FILES=$(find {project_dir} -type f \( -name "*.go" -o -name "*.ts" -o -name "*.py" -o -name "*.java" -o -name "*.js" \) -newer "$CACHE_FILE" | wc -l)
CHANGE_PERCENTAGE=$(( (CHANGED_FILES * 100) / TOTAL_CODE_FILES ))
if [ "$CHANGE_PERCENTAGE" -gt 20 ]; then
echo "⚠️ Cache is $CACHE_AGE_DAYS days old and $CHANGE_PERCENTAGE% of code changed."
echo "Consider running full audit for accuracy."
# Show user prompt: "Run full audit" or "Use cache anyway"
fi
fi
Logic:
-newer than cache file
**SKIP fingerprint comparison if:**
- Cache is > 30 days old AND > 20% code files changed since cache date
- User chooses "Run full audit" (bypass Diff Mode entirely)
**PROCEED to fingerprint comparison if:**
- Cache is fresh (< 30 days old), OR
- Code changes < 20%, OR
- User chooses "Use cache anyway"
---
**For Feishu documents (preferred):**
Use authoritative server-side metadata for fingerprinting:
```python
# Feishu API provides precise update_time
feishu_fingerprint = f"{feishu_metadata.update_time}_{doc_id}"
# Example: "2026-04-10T15:30:00+08:00_GSYawcl6jiKe0skYjxvcrt9qnbh"
For local files (fallback):
Compute client-side content fingerprint with Unicode normalization (for Chinese/multi-byte support):
import unicodedata
def compute_fingerprint(content: str) -> str:
"""
Content fingerprint with three-segment sampling for comprehensive change detection.
Takes prefix, middle, and suffix to detect changes anywhere in the document,
not just at head/tail.
"""
import unicodedata
# Normalize to NFD (Compatibility Decomposed) for stable hashing
normalized = unicodedata.normalize('NFD', content)
# Strip whitespace fluctuations (extra newlines, indentation)
normalized = '\n'.join(line.strip() for line in normalized.split('\n') if line.strip())
# Three-segment fingerprinting for better coverage
# prefix + middle + suffix ensures changes anywhere in document are detected
mid = len(normalized) // 2
fingerprint = (
f"{len(normalized)}_"
f"{normalized[:80]}_"
f"{normalized[mid:mid+80]}_"
f"{normalized[-80:]}"
)
return fingerprint
# Example:
# content = "用户登录功能 —— 用户需要能通过手机号和密码登录系统..."
# fingerprint = compute_fingerprint(content)
# Result: "156_用户登录功能 —— 用户需要能通过手机号和密码登录系统_...登录失败则提示错误信息"
Comparison logic:
Compare computed fingerprint with cached content_fingerprint:
Fingerprinting precision: Feishu API timestamps are 100% accurate vs. content-based hashing (~85% reliable for small changes).
Ask user which audit path to take:
Detected update in "{title}" (last cached: {cached_at}).
Options:
1. "Yes, audit changes only (faster)" → Run Steps D1-D3 (Diff Mode)
2. "No, re-scan everything" → Run full Phase 1, then Step C4
Wait for user selection before proceeding.
Execution timing: After every full Phase 1 audit (not after Diff Mode audits)
Cache file structure:
Create or update .prd-pilot/prd/{title}-v{n}.md:
---
source_type: feishu_doc | local_file
source_url: https://xxx.feishu.cn/docx/xxxxxx # (only for Feishu)
doc_id: xxxxxx # (only for Feishu; used for matching)
title: User Login Feature PRD
version: 1 # Increment on each full audit
cached_at: 2026-04-11
# Feishu API metadata (populated only when source_type=feishu_doc)
feishu_update_time: "2026-04-10T15:30:00+08:00" # Server timestamp (used for C2 comparison)
feishu_created_time: "2026-04-10T10:00:00+08:00" # Document creation time
feishu_owner: "露娜-macbook" # Document owner
feishu_doc_type: "DOCX" # Document type
# Content fingerprint (used for local files in C2 comparison)
# Format: len_prefix80_middle80_suffix80 (three-segment for comprehensive change detection)
content_fingerprint: "15234_用户登录功能。用户需要能够通过手机号和密码登录系统_...登录失败则返回错误信息"
last_audit: ../.prd-pilot/audit-2026-04-10.md # Path to previous Stage 5 audit report
---
{full PRD content here}
Cache Field Meanings:
feishu_update_time is compared in Step C2content_fingerprint is compared in Step C2cached_at used for staleness check (> 30 days)Version increment logic:
version: 1version += 1Users can trigger Diff Mode explicitly without waiting for auto-detection:
Command syntax:
prd:audit --diff <old.md> <new.md>
User phrases:
Compare current PRD content with cached content. Classify each requirement:
| Classification | Definition | Action |
|---|---|---|
| REVALIDATE | New requirement or modified text | Must re-scan code in Stage 3 |
| INHERIT | Unchanged requirement text | Reuse finding from last_audit report; skip code scan |
| RETIRE | Requirement deleted from PRD | Check for DANGLING_CODE; mark as historical |
Diff extraction approach:
text_changed → REVALIDATEtext_identical → INHERITno_match_in_current → RETIRERETIRE handling: Dangling Code Detection
For each RETIRE requirement:
timeout 60s rg -l "{keywords}" {project_dir}Load the last_audit report (from cache frontmatter). For each requirement:
Example:
Previous audit: R1 "User login by email" → PASS (finding: session.ts:45-60)
Current PRD: R1 text unchanged → INHERIT → Copy PASS to new report
Previous audit: R2 "Rate limit 3/min" → CONFLICT (finding: no rate limit code)
Current PRD: R2 text modified to "Rate limit 5/min" → REVALIDATE → Re-scan code
Execute Stage 3 & 4 only for REVALIDATE requirements. For INHERIT requirements, skip Stage 3 scanning entirely.
Scan budget for Diff Mode:
- Unchanged requirements (INHERIT): 0 scans (reuse findings)
- Modified requirements (REVALIDATE): Standard Stage 3 scan per requirement
- RETIRE requirements: 0 scans (archived)
Example savings:
Full PRD: 10 requirements, ~300 LOC to scan per req = 3000 LOC total
Diff (10% change): 1 REVALIDATE req + 9 INHERIT
~300 LOC to scan + 0 (reused)
= 90% reduction
Output: Incremental Audit Report
Generate Stage 5 report with:
[inherited]).prd-pilot/
├── prd/ # Cache directory
│ ├── user-login-v1.md # Cached: Feishu doc
│ ├── user-login-v2.md # Cached: v2 (newer)
│ ├── feature-spec-cached.md # Cached: local file
│ └── README.md # (optional) cache guide
├── audit-2026-04-10.md # Full audit report
├── audit-2026-04-11.md # Full audit report (newer)
└── code-map-2026-04-10.md # Generated code map (Stage 2.8)
| Scenario | Audit Time | vs. Full Scan | Cache Hit Rate |
|---|---|---|---|
| First audit (no cache) | Full scan | — | 0% |
| Cache hit + no changes | ~30ms | ↓98% | 100% |
| Cache hit + 10% PRD changed | ~15-20% of full scan | ↓80-85% | 90% INHERIT |
Manual --diff specified | Only changed sections | ↓70-90% | N/A |
| Large project (>10k LOC) + 5% change | ~2-3 min | ↓87% | 95% INHERIT |
Diff Mode auto-activates when ALL conditions true:
Cache found (Step C1 success)
PRD content changed (Step C2):
feishu_update_time in cached file differs from current update_time (from MCP search-doc API)content_fingerprint mismatch (three-segment fingerprinting)User confirms "audit changes only" (Step C3)
Fallback conditions:
prd:audit --diff → Force Diff Mode regardlessTwo required inputs:
./docs/prd-v1.md) or Feishu doc URLIf user provides a Feishu doc URL, follow this confirmation protocol before extracting content:
mcp__feishu-docs__fetch-doc (Feishu MCP) with the document ID extracted from the URL,
but only read the first ~200 characters to obtain the document title / opening line.CRITICAL TIMING: Execute Diff Mode immediately after PRD content is confirmed (Inputs protocol), before entering Stage 1.
Why this order matters: If Diff Mode matches cache, we skip Stage 1 entirely (no need to re-extract requirements). If we do Stage 1 first and then discover cache, the extraction work is wasted.
Execution flow:
1. User provides PRD URL/path
2. Inputs protocol: confirm Feishu title (if URL)
3. Extract full PRD content ← Content ready
4. ↓
5. ✨ EXECUTE DIFF MODE NOW (Steps C1-C3)
├─ C1: Locate cache by doc_id or filename
├─ C2: Check fingerprint (server-time or text-based)
└─ C3: Ask user "audit changes only or full audit?"
If cache hit + no changes → Exit, output cached report
If cache hit + changes → Enter Diff Mode (Steps D1-D3)
If no cache found → Continue to Stage 1
6. ↓
7. [Stage 1 — Requirement Extraction] (only if no cache or Diff Mode decision)
Key decision: After C1-C3, make a binary choice:
Execute these stages sequentially. Do not skip stages.
Note: Phase 1 is only entered if Diff Mode check (above) determines a full audit is needed.
Read the PRD document. Extract a structured requirement list:
For each requirement, extract:
- req_id: Sequential identifier (R1, R2, R3...)
- summary: One-line description
- keywords: 3-8 search terms for locating related code
- type: FEATURE_NEW | FEATURE_MODIFY | FEATURE_REMOVE | CONSTRAINT | NON_FUNCTIONAL
For keyword extraction guidance, read references/requirement-taxonomy.md if it exists.
After outputting the table, use AskUserQuestion:
Command Timeout Convention:
All external commands (rg, find, grep) use timeout {T} where T adapts to project scale:
find <dir> -maxdepth 2 -type f | wc -l and set T accordingly.Path Safety Check (execute first):
<dir> to an absolute path/, /etc, /usr, C:\, C:\Windows, etc.)❌ 项目目录路径异常:{path}。请提供项目根目录的绝对路径。timeout {T} find <dir> -maxdepth 3 -type f | head -80timeout {T} find <src> -maxdepth 4 -type f | head -120Produce a ≤300-word Project Profile (language, framework, main dirs, DB, API layer).
⚠️ This stage is best-effort. Results inform but do not gate subsequent stages.
Scale-Adaptive Skip:
Estimate project size: timeout {T} find <src_dir> -type f \( -name "*.go" -o -name "*.ts" -o -name "*.py" -o -name "*.java" \) | wc -l
Existence check:
timeout {T} find <project_dir> -maxdepth 2 -name "*.md" -not -path "*/node_modules/*" | head -20⚠️ DOC_MISSINGFreshness check:
⚠️ DOC_STALE: {filename} last updated {date}Accuracy verification (best-effort): Spot-check a few key claims in docs against actual code (paths exist? imports match?). Record: ✅ VERIFIED / ❌ CONTRADICTED / ⚠️ UNVERIFIABLE
Output: Documentation Trust Score
📋 Documentation Health
- Trust Level: HIGH (>80% verified) / MEDIUM (50-80%) / LOW (<50%) / NONE (no docs)
Impact on subsequent stages:
rg/find discoveryTrigger: Documentation Trust Level is MEDIUM, LOW, or NONE. Skip if HIGH.
Generate a structured code map by reading the actual codebase:
# Find entry points, routers, handlers
timeout {T} rg -l "func main\b|app\.listen|router\.|@Controller|func.*Handler" <project> -t code | head -30
# Find model/entity definitions
timeout {T} rg -l "type.*struct|class.*Model|@Entity|schema\.|CREATE TABLE" <project> -t code | head -30
# Find API route definitions
timeout {T} rg -n "GET\|POST\|PUT\|DELETE\|@Get\|@Post\|router\.\|HandleFunc" <project> -t code | head -50
Write to {project_dir}/.prd-pilot/code-map-{date}.md. Mark uncertain entries with (?).
This code map becomes the primary reference for Stage 3 and Stage 4.
Estimate scan cost and confirm with user:
timeout {T} find <src_dir> -type f \( -name "*.go" -o -name "*.ts" -o -name "*.py" -o -name "*.java" -o -name "*.js" \) | xargs wc -l 2>/dev/null | tail -1
Use AskUserQuestion:
For each requirement from Stage 1:
timeout {T} rg -l "<keyword>" <project_dir> --type-add 'code:*.{ts,tsx,js,jsx,py,go,rs,java,rb,vue,svelte}' -t codeUNLOCATEDtimeout {T} rg -n -C 5 "<keyword>" <file>references/infrastructure.md context management)This stage is tool-driven (rg/grep/find). Do not rely on LLM memory of the codebase.
For each requirement, classify into:
| Verdict | Meaning | Action Required |
|---|---|---|
| CONFLICT | PRD demands X, code does Y | Must resolve before coding |
| WARNING | Possible mismatch, could be indirect implementation | Human review needed |
| PASS | Requirement satisfied or compatible | No action |
| GAP | No existing code found (new feature needed) | Expected for new features |
| UNKNOWN | Cannot determine | Human review needed |
Evidence rules:
prd_excerpt, code_file, code_lines, reasoningFalse positive prevention:
Classification Decision Tree (boundary examples):
| Scenario | Verdict | Reasoning |
|---|---|---|
PRD: "显示成功提示", code returns {code: 200} without message | PASS | Frontend maps status codes to display text |
| PRD: "限制每人每天3次", no rate limiting code found | CONFLICT | Core constraint with no implementation evidence |
| PRD: "支持 Excel 导出", code has CSV export only | WARNING | Similar but not identical — context-dependent |
| PRD: "使用 Redis 缓存", code uses in-memory cache | WARNING | Different approach, may be intentional |
| PRD: "删除用户时同步删除关联数据", code soft-deletes only | CONFLICT | Data integrity requirement not met |
First-time write permission check:
Before writing to {project_dir}/.prd-pilot/ for the first time in a session, use AskUserQuestion:
Read references/audit-output-format.md if it exists; otherwise use standardized format:
---
report_type: prd_audit
date: {YYYY-MM-DD}
prd_source: {source}
project_name: {name}
commit_hash: {hash}
summary:
conflict: {n}
warning: {n}
gap: {n}
pass: {n}
unknown: {n}
---
# PRD Audit Report — {YYYY-MM-DD}
## Executive Summary
- Total requirements: {n}
- Status distribution: CONFLICT {n} | WARNING {n} | GAP {n} | PASS {n} | UNKNOWN {n}
- Blockers: {brief description of CONFLICTs requiring resolution}
## Findings by Category
### CONFLICT Findings
#### [{req_id}] {summary}
- **PRD Excerpt**: "{text}"
- **Code Location**: `{file}:{lines}`
- **Reasoning**: {2-3 sentences explaining mismatch}
- **Resolution**: [suggest action]
### WARNING Findings
#### [{req_id}] {summary}
- **PRD Excerpt**: "{text}"
- **Code Location**: `{file}:{lines}`
- **Reasoning**: {2-3 sentences explaining ambiguity}
- **Recommendation**: [human review suggestion]
### GAP Findings
#### [{req_id}] {summary}
- **PRD Excerpt**: "{text}"
- **Search Result**: [no code found for keywords: ...]
- **Implication**: New feature required or indirect implementation
### PASS Findings
#### [{req_id}] {summary}
- **Status**: Requirement satisfied in codebase
### UNKNOWN Findings
#### [{req_id}] {summary}
- **Reason**: [insufficient evidence to determine status]
- **Recommendation**: [suggest manual inspection or code context]
## Integration Notes
**For spec-kit:** CONFLICTs and WARNINGs become spec review items.
**For Superpowers:** Use findings to inform `superpowers:writing-plans` workflow.
**For taskforce_plan:** Neko consumes this report to refine specification and identify implementation blockers.
Write to: {project_dir}/.prd-pilot/audit-{YYYY-MM-DD}.md
If within taskforce, also copy to blackboard/active/{task_id}_prd_audit.md
If .prd-pilot/ is not in .gitignore, display (do NOT auto-modify):
💡 建议将 .prd-pilot/ 加入 .gitignore 以避免提交审计报告和缓存文件。
prd-pilot works best as part of a multi-tool pipeline. Use this chart to choose companion tools:
| Scenario | Primary Tool | Companion | Purpose |
|---|---|---|---|
| Audit existing PRD | prd-pilot | — | Detect conflicts, gaps, risks |
| From audit → spec | prd-pilot | spec-kit | Convert audit findings to spec |
| From audit → plan | prd-pilot | Superpowers:writing-plans | Generate implementation roadmap |
| From audit → code | prd-pilot | taskforce_plan | Neko consumes audit for spec refinement |
| Review PR against PRD | Superpowers (verification-before-completion) | — | Check if changes match audit scope |
| Incremental PRD changes | prd-pilot (Diff Mode) | — | Re-audit only changed sections |
Recommended Workflow:
1. Run prd-pilot to audit PRD against code
↓
2. Review audit report (CONFLICT/WARNING/GAP/PASS)
↓
3. Choose path:
a) Use spec-kit to convert findings → formal spec
b) Use Superpowers:writing-plans to generate implementation roadmap
c) Feed audit to taskforce_plan for automated planning
↓
4. Execute plan
↓
5. Use Superpowers `verification-before-completion` or spec-kit review to validate PR coverage
💡 spec-kit and Superpowers are recommended companion tools — not required. Install them independently when needed; prd-pilot works standalone without them.
When used as a pre-step before taskforce_act:
blackboard/active/{task_id}_prd_audit.mdtaskforce_plan, Neko reads this file to inform Spec generationSee README.md for planned features and timeline.
Provides behavioral guidelines to reduce common LLM coding mistakes, focusing on simplicity, surgical changes, assumption surfacing, and verifiable success criteria.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub gopherlinzy/skill-hub --plugin prd-pilot