@juicesharp/rpiv-pi 0.7.0 → 0.8.1

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.
@@ -25,6 +25,7 @@ const THOUGHTS_DIRS = [
25
25
  "thoughts/shared/designs",
26
26
  "thoughts/shared/plans",
27
27
  "thoughts/shared/handoffs",
28
+ "thoughts/shared/reviews",
28
29
  ] as const;
29
30
 
30
31
  const msgAgentsAdded = (n: number) => `Copied ${n} rpiv-pi agent(s) to .pi/agents/`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-pi",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "Skill-based development workflow for Pi Agent — discover, research, design, plan, implement, validate",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -1,184 +1,403 @@
1
1
  ---
2
2
  name: code-review
3
- description: Conduct comprehensive code reviews by analyzing changes in parallel. Produces review documents in thoughts/shared/reviews/. Use when changes are ready for review.
3
+ description: Three-pass parallel reviewer (quality, security, dependencies) with conditional advisor adjudication. Produces review documents in thoughts/shared/reviews/. Use when changes are ready for review.
4
4
  argument-hint: [scope]
5
- allowed-tools: Read, Bash(git *), Glob, Grep, Agent
6
5
  ---
7
6
 
8
- # Code Review System
7
+ ## Scope Source
9
8
 
10
- You are tasked with conducting comprehensive code reviews by invoking parallel skills to analyze changes and synthesize their findings into actionable feedback.
9
+ If the user has not specified what to review, ask them before proceeding. Scope is one of: `commit` (latest commit), `staged`, `working`, a commit hash or `A..B` range, or a PR branch name. Their input will appear as a follow-up paragraph after this skill body.
11
10
 
12
- ## Initial Setup:
11
+ # Code Review
12
+
13
+ You are tasked with reviewing changes across three parallel lenses — **Quality**, **Security**, **Dependencies** — and synthesising their findings with optional stronger-model adjudication into an actionable `thoughts/shared/reviews/` artifact.
14
+
15
+ **How it works**:
16
+ - Resolve scope and assemble the diff (Step 1)
17
+ - Phase-1 Discovery Map (Step 2 — one agent + orchestrator-side git work)
18
+ - Phase-2 three-lens review + precedents + conditional CVE lookup (Step 3 — parallel agents)
19
+ - Reconcile findings via advisor (if present) or inline dimension-sweep (Step 4)
20
+ - Grounded-questions developer checkpoint (Step 5)
21
+ - Write the review artifact (Step 6)
22
+ - Present and handle follow-ups (Steps 7–8)
23
+
24
+ ## Step 1: Resolve Scope and Assemble the Diff
25
+
26
+ 1. **Parse the scope argument** (follow-up paragraph or the skill's argument):
27
+ - `commit` → `git diff HEAD~1 HEAD`
28
+ - `staged` → `git diff --cached`
29
+ - `working` → `git diff`
30
+ - Commit hash `abc1234` → `git show abc1234`
31
+ - Range `A..B` → `git diff A..B`
32
+ - PR branch name → `git diff $(git merge-base main HEAD)..HEAD` (or the branch vs its base)
33
+
34
+ 2. **Read the full diff FIRST** (orchestrator-side, before any agent dispatch):
35
+ - `git diff --name-only [scope]` → `ChangedFiles` list
36
+ - `git diff --stat [scope]` → size summary
37
+ - `git diff -U0 [scope]` → hunk ranges for Phase-2 prompts (inline, don't dump to user)
38
+ - `git log -1 --format="%s%n%n%b" [scope-ref]` → commit-message context when applicable
39
+
40
+ 3. **Bail-out**: if `ChangedFiles` is empty, print `No changes in scope [scope]. Exiting.` and STOP. Do not write an artifact.
41
+
42
+ 4. **Derive flags** (orchestrator-side, used in later steps):
43
+ - `ManifestChanged` = ChangedFiles intersects {`package.json`, `package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`} OR a `peerDependencies` field was touched.
44
+ - `LockstepSelfReview` = repository root contains `scripts/sync-versions.js` AND every `packages/*/package.json` shares the same `version:` AND the diff touches `packages/*/package.json`.
45
+ - `ReviewType` = one of `commit | pr | staged | working`.
46
+
47
+ ## Step 2: Phase-1 Discovery Map (parallel agents)
48
+
49
+ Spawn ONE agent in parallel with orchestrator-side work:
50
+
51
+ **Agent — Integration map:**
52
+ - subagent_type: `integration-scanner`
53
+ - Prompt: "Map inbound references, outbound dependencies, and infrastructure wiring for the following changed files: [ChangedFiles, one per line]. Flag any auth-boundary crossings (middleware, guards, interceptors, authorize-style decorators) and config/DI/event registration touching these paths. Do NOT analyse code quality — connections only, in your standard output format."
54
+
55
+ While the agent runs, the orchestrator produces the rest of the Discovery Map inline from Step 1's data:
56
+ - `ChangedFiles`, `ManifestChanged`, `LockstepSelfReview`, `ReviewType`
57
+ - Hunk ranges per file (from `git diff -U0`)
58
+ - Commit-message context (if applicable)
59
+
60
+ **Wait for ALL agents to complete** before proceeding.
61
+
62
+ **Synthesize the Discovery Map** — a compact text block that Phase-2 agents receive verbatim as `Known Context`:
13
63
 
14
- When this command is invoked, respond with:
15
64
  ```
16
- I'm ready to perform a code review. Please specify what you'd like reviewed:
17
- - Latest commit(s)
18
- - Staged changes (git diff --cached)
19
- - Working directory changes (git diff)
20
- - Specific commit hash or range
21
- - Pull request (provide PR number or branch)
22
-
23
- You can also specify focus areas or review depth.
65
+ ## Discovery Map
66
+
67
+ Review type: [ReviewType]
68
+ Scope: [scope argument]
69
+ Commit/range: [git ref]
70
+ Changed files ([N]):
71
+ path/a.ts (+A -B)
72
+ path/b.ts (+A -B)
73
+ Hunks:
74
+ path/a.ts: L10-23, L45-60
75
+ path/b.ts: L5-8
76
+ Manifest changed: [yes|no]
77
+ Lockstep self-review: [yes|no]
78
+ Auth-boundary crossings: [from integration-scanner output, file:line]
79
+ Inbound refs: [from integration-scanner output]
80
+ Outbound deps: [from integration-scanner output]
81
+ Wiring/config: [from integration-scanner output]
24
82
  ```
25
83
 
26
- Then wait for the user's review request.
27
-
28
- ## Steps to follow after receiving the review request:
29
-
30
- 1. **Read the changes to review:**
31
- - Determine what needs reviewing based on user input
32
- - Use appropriate git commands to get the diff:
33
- - Latest commit: `git diff HEAD~1 HEAD`
34
- - Staged: `git diff --cached`
35
- - Working: `git diff`
36
- - **IMPORTANT**: Read the full diff output FIRST before invoking any skills
37
- - Get list of changed files and understand the scope
38
- - Note commit messages for context
39
-
40
- 2. **Analyze and decompose the review:**
41
- - Break down the changes into reviewable areas
42
- - Take time to ultrathink about patterns, security implications, and architectural impacts
43
- - Identify which components are affected
44
- - Create a review plan using the `todo` tool to track all aspects
45
- - Consider which existing patterns and historical decisions are relevant
46
-
47
- 3. **Spawn parallel agents for comprehensive review:**
48
- - Plan first then spawn multiple agents to review different aspects concurrently using the Agent tool. Those MUST be run simultaneously to boost efficiency.
49
- **For codebase research:**
50
- - Use the **codebase-locator** agent to find WHERE files and components live
51
- - Use the **codebase-analyzer** agent to understand HOW specific code works
52
- - Use the **codebase-pattern-finder** agent if you need examples of similar implementations
53
-
54
- **For thoughts directory:**
55
- - Use the **thoughts-locator** agent to discover what documents exist about the topic
56
- - Use the **thoughts-analyzer** agent to extract key insights from specific documents
57
-
58
- **For web research (only if user explicitly asks):**
59
- - Use the **web-search-researcher** agent for external documentation and resources
60
- - IF you use web-research agents, instruct them to return LINKS with their findings, and please INCLUDE those links in your final report
61
-
62
- The key is to use these agents intelligently:
63
- 1. Start with locator agents to understand scope and find context
64
- 2. Then use analyzer agents on the most critical changes
65
- - Run multiple agents in parallel when reviewing different aspects
66
- - Each agent works in isolation provide complete context in the prompt
67
-
68
- 4. **Wait for all agents to complete and synthesize findings:**
69
- - IMPORTANT: Wait for ALL agent invocations to complete before proceeding
70
- - Compile all findings from agents
71
- - Classify issues by severity:
72
- - 🔴 Critical: Security vulnerabilities, data loss, crashes
73
- - 🟡 Important: Bugs, performance issues, pattern violations
74
- - 🔵 Suggestions: Style improvements, minor optimizations
75
- - 💭 Discussion: Architecture decisions, trade-offs
76
- - Cross-reference patterns found by agents with actual changes
77
- - Check if historical decisions are being respected
78
- - Verify test coverage based on existing patterns
79
-
80
- 5. **Determine metadata and filename:**
81
- - Filename format: `thoughts/shared/reviews/YYYY-MM-DD_HH-MM-SS_[scope].md`
82
- - YYYY-MM-DD_HH-MM-SS: Current date and time (e.g., 2025-10-11_14-30-22)
83
- - [scope]: Brief kebab-case description of what was reviewed
84
- - Repository name: from git root basename, or current directory basename if not a git repo
85
- - Use the git branch and commit from the git context injected at the start of the session (or run `git branch --show-current` / `git rev-parse --short HEAD` directly); falls back to "no-branch" / "no-commit" if not a git repo
86
- - Reviewer: use the User from the git context injected at the start of the session (fallback: "unknown")
87
- - If metadata unavailable: use "unknown" for commit/branch
88
-
89
- 6. **Generate review document:**
90
- - Use the metadata gathered in step 5
91
- - Structure the document with YAML frontmatter followed by content:
92
- ```markdown
93
- ---
94
- date: [Current date and time with timezone]
95
- reviewer: [Reviewer name]
96
- repository: [Repository name]
97
- branch: [Current branch]
98
- commit: [Commit hash]
99
- review_type: [commit|pr|staged|working]
100
- scope: "[What was reviewed]"
101
- files_changed: [Number]
102
- critical_issues: [Count]
103
- important_issues: [Count]
104
- suggestions: [Count]
105
- status: [approved|needs_changes|requesting_changes]
106
- tags: [code-review, relevant-components]
107
- last_updated: [Current date in YYYY-MM-DD format]
108
- last_updated_by: [Reviewer name]
109
- ---
110
-
111
- # Code Review: [Scope Description]
112
-
113
- **Date**: [Current date and time]
114
- **Reviewer**: [Reviewer name]
115
- **Repository**: [Repository]
116
- **Branch**: [Branch name]
117
- **Commit**: [Commit hash]
118
-
119
- ## Review Summary
120
- [Overall assessment of the changes]
121
-
122
- ## Issues Found
123
-
124
- ### Critical Issues (Must Fix)
125
- [None | List of critical issues with file:line references and suggested fixes]
126
-
127
- ### Important Issues (Should Fix)
128
- [List of important issues with evidence from skills]
129
-
130
- ### Suggestions
131
- [Minor improvements and optimizations]
132
-
133
- ## Pattern Analysis
134
- [How changes align with existing patterns found by pattern-finder]
135
-
136
- ## Impact Assessment
137
- [Files and tests affected based on locator findings]
138
-
139
- ## Historical Context
140
- [Relevant decisions and past issues from thoughts/]
141
-
142
- ## Recommendation
143
- [Clear verdict: Approved / Needs Changes / Requesting Changes]
144
- ```
145
-
146
- 7. **Present findings:**
147
- - Present a concise summary to the user
148
- - Include the most critical issues first
149
- - Provide concrete examples from the codebase
150
- - Ask if they need clarification on any findings
151
-
152
- 8. **Handle follow-up questions:**
153
- - If the user has follow-up questions, append to the same review document
154
- - Update the frontmatter fields `last_updated` and `last_updated_by`
155
- - Add a new section: `## Follow-up [timestamp]`
156
- - Spawn new agents as needed for deeper investigation
157
- - Continue updating the document and syncing
158
-
159
- ## Important notes:
160
- - Always use parallel Agent tool calls to maximize efficiency
161
- - Always read the diff FULLY before spawning agents
162
- - Focus on finding concrete issues with evidence from agents
163
- - Review documents should be actionable with specific fixes
164
- - Each agent prompt should be focused on specific analysis
165
- - Consider patterns, security, performance, and maintainability
166
- - Include historical context when relevant
167
- - Keep the main agent focused on synthesis, not deep analysis
168
- - Encourage agents to find examples and patterns, not make judgments
169
- - **Critical ordering**: Follow the numbered steps exactly
170
- - ALWAYS read diff first before spawning agents (step 1)
171
- - ALWAYS wait for all agents to complete before synthesizing (step 4)
172
- - ALWAYS gather metadata before writing the document (step 5 before step 6)
173
- - **Agent roles:**
174
- - **codebase-locator**: WHERE code lives (find files)
175
- - **codebase-analyzer**: HOW code works (implementation details)
176
- - **codebase-pattern-finder**: Examples of similar code
177
- - **thoughts-locator**: Find historical documentation
178
- - **thoughts-analyzer**: Extract insights from documents
179
- - **web-search-researcher**: External sources (sparingly)
84
+ ## Step 3: Phase-2 Three-Lens Review (parallel agents)
85
+
86
+ Spawn these agents in parallel using the Agent tool. Each receives the `## Discovery Map` block inline as `Known Context` above its task.
87
+
88
+ **Always spawn:**
89
+
90
+ **Quality lens:**
91
+ - subagent_type: `codebase-analyzer`
92
+ - Prompt:
93
+ ```
94
+ Known Context:
95
+ [paste Discovery Map verbatim]
96
+
97
+ Task: Trace data flow through each changed hunk. For every hunk, enumerate `file:line` observations in these buckets — do NOT classify severity, the orchestrator does:
98
+ 1. Logic-bug risks: missing validation, dropped error paths, off-by-one, null/undefined misses, incorrect branch ordering, forgotten return/await, state mutations without guards.
99
+ 2. Pattern divergence: where the hunk deviates from the surrounding file's existing style/structure (cite the nearby line the hunk broke from).
100
+ 3. Blast radius: any inbound reference in the Discovery Map that the hunk's behavior change could affect (`consumer.ext:line` + what changes for it).
101
+ 4. Test coverage gaps: any risk-bearing behavior the hunk introduces that has no adjacent test reference.
102
+
103
+ Return evidence only. No recommendations.
104
+ ```
105
+
106
+ **Security lens:**
107
+ - subagent_type: `codebase-analyzer`
108
+ - Prompt:
109
+ ```
110
+ Known Context:
111
+ [paste Discovery Map verbatim]
112
+
113
+ Task: Grep each changed hunk for the following sink patterns and list every match with `file:line` + surrounding 3 lines. Cross-reference the Discovery Map's Auth-boundary crossings.
114
+ For each hit, additionally return `confidence: N/10` reflecting how certain you are that a user-controlled input can reach this sink under current deployment. Do NOT report hits with confidence < 8.
115
+ - Command execution: `exec(`, `execSync(`, `execFile(`, `child_process`, `spawn(`
116
+ - Dynamic evaluation: `eval(`, `new Function(`
117
+ - SQL template-interpolation: multi-line `` `SELECT ... ${ ``, `` `INSERT ... ${ ``, `` `UPDATE ... ${ ``, `` `DELETE ... ${ ``
118
+ - XSS sinks: `innerHTML =`, `dangerouslySetInnerHTML`, `document.write(`
119
+ - Path traversal: string concatenation into `fs.readFile`, `fs.writeFile`, `path.join` with user input
120
+ - SSRF: `fetch(`, `http.request(`, `axios(`, `got(` where HOST or PROTOCOL (not just path) is user-controlled
121
+ - Secrets in diff: `api_key`, `secret`, `password`, `BEGIN PRIVATE KEY`, `.env` content literal
122
+ - Missing auth guard: auth-boundary crossings (from Discovery Map) reaching a traced sink without an upstream guard
123
+
124
+ Hard exclusionsdo NOT report:
125
+ - DOS / resource exhaustion / rate limiting / memory or CPU exhaustion
126
+ - Missing hardening in isolation (no traced sink), lack of audit logs
127
+ - Theoretical race conditions / timing attacks without a concrete reproducer
128
+ - Log spoofing, prototype pollution, tabnabbing, open redirects, XS-Leaks, regex DOS, regex injection
129
+ - Client-side-only authn/authz gaps (server is the authority)
130
+ - XSS in React/Angular/tsx files unless via `dangerouslySetInnerHTML`, `bypassSecurityTrustHtml`, or equivalent
131
+ - Findings whose sole source is an environment variable, CLI flag, or UUID (trusted in our threat model)
132
+ - Findings in test-only files or `.ipynb` notebooks without a concrete untrusted-input path
133
+ - Outdated-dependency CVEs (handled by the dependencies/CVE lens)
134
+
135
+ For each hit, name the pattern and quote the line. Return evidence only. No CVE lookups — that is a separate agent.
136
+ ```
137
+
138
+ **Dependencies lens:**
139
+ - subagent_type: `codebase-analyzer`
140
+ - Prompt (only when `ManifestChanged` is true; otherwise SKIP and set `dependency_issues: 0`, `passes: [quality, security]`):
141
+ ```
142
+ Known Context:
143
+ [paste Discovery Map verbatim]
144
+ Lockstep self-review: [LockstepSelfReview yes|no]
145
+
146
+ Task: Parse the diff of `package.json` / `package-lock.json` / `pnpm-lock.yaml` / `yarn.lock`. List:
147
+ 1. Added dependencies: `name@version` with `file:line`.
148
+ 2. Bumped dependencies: `name: old -> new` with `file:line`.
149
+ 3. Removed dependencies.
150
+ 4. `peerDependencies` changes.
151
+ 5. License field changes or additions in the lockfile.
152
+ 6. When Lockstep self-review is `yes`: flag only intra-monorepo version drift where a sibling pin diverges from the lockstep `version:` in `packages/*/package.json`. Treat `"*"` peer pins as intentional.
153
+ 7. When Lockstep self-review is `no`: flag any version-conflict between direct dep and lockfile resolution.
154
+
155
+ Return evidence only. No CVE lookups — that is a separate agent.
156
+ ```
157
+
158
+ **Precedents lens:**
159
+ - subagent_type: `precedent-locator`
160
+ - Prompt:
161
+ ```
162
+ Planned change: code review of [scope]. Changed files: [ChangedFiles].
163
+ Find the most similar past changes that touched these files or files nearby. For each precedent, report the commit hash, blast radius, any follow-up fixes within 30 days, and the one-sentence takeaway. Distil composite lessons across all precedents.
164
+ ```
165
+
166
+ **Conditional spawn** (only when `ManifestChanged` is true):
167
+
168
+ **CVE/advisory lens:**
169
+ - subagent_type: `web-search-researcher`
170
+ - Prompt:
171
+ ```
172
+ For each of the following dependency changes, look up known CVEs / GitHub Advisories / OSS Index entries in the target version. Return LINKS alongside findings. If a vulnerability exists, summarize severity (Critical / High / Moderate / Low), affected version range, and whether the bumped-to version is fixed.
173
+
174
+ Dependencies to check:
175
+ [name@version, one per line — extracted by orchestrator from the diff]
176
+ ```
177
+
178
+ **Wait for ALL agents to complete** before proceeding.
179
+
180
+ ## Step 4: Reconcile Findings
181
+
182
+ 1. **Compile evidence** from every lens:
183
+ - Quality evidence classify each `file:line` observation into severity:
184
+ - 🔴 Critical: traced flow contradiction (dropped error path, missing validation on a known sink, null-deref).
185
+ - 🟡 Important: blast-radius × complexity-delta (hot path + new allocation, visible ABI change without migration).
186
+ - 🔵 Suggestion: pattern divergence with a concrete nearby template.
187
+ - 💭 Discussion: composite-lesson architecture concerns.
188
+ - Security evidence → classify:
189
+ - 🔴 sink hit with a CONCRETE user-reachable source→sink path traced through Discovery Map auth-boundary crossings. Reject any hit lacking an explicit trace.
190
+ - 🟡 crypto-only concrete issues: weak hash in an auth/integrity role (MD5/SHA1), non-constant-time compare on secrets, hardcoded key material in diff. Do NOT use 🟡 for "missing hardening".
191
+ - 🔵 pattern divergence from a secure example in the SAME file (cite the nearby secure `file:line`).
192
+ - 💭 architectural question.
193
+ - Dependencies evidence → classify:
194
+ - 🔴 Known-exploitable CVE in a touched dep (Critical/High per advisory DB) OR lockstep-contract violation (would trip `scripts/sync-versions.js`).
195
+ - 🟡 Moderate CVE, outdated major with a migration path, license incompatibility with the project license.
196
+ - 🔵 Minor/transitive drift.
197
+ - 💭 Architectural dep question.
198
+ - Precedents compile into a separate `## Precedents & Lessons` section orthogonal to per-lens findings. Composite lessons go at the bottom of that section.
199
+
200
+ 2. **Probe advisor availability** — attempt a probe by checking whether `advisor` is in the active tool set (main-thread visibility). If yes, proceed to advisor path; otherwise take the inline path.
201
+
202
+ 3. **Advisor path** (when advisor is active):
203
+ - Print a main-thread `## Pre-Adjudication Findings` block containing the compiled evidence and tentative severity map. This ensures the findings are persisted into `getBranch()` before the advisor call.
204
+ - Call `advisor()` (zero-param). Wait for the response.
205
+ - On success: paste the advisor's prose verbatim into the artifact's `## Advisor Adjudication` section (Step 6) and note `advisor_used: true` + `advisor_model: [model-id]` in frontmatter.
206
+ - On `"aborted"` or empty text: set `advisor_used: false`, skip the adjudication section, fall through to the inline path.
207
+ - On `"error"`: note the error inline in the adjudication section as `advisor error: <message>`; continue with inline reconciliation alongside.
208
+
209
+ 4. **Inline path** (advisor unavailable or errored):
210
+ - Run a dimension-sweep modeled on `skills/design/SKILL.md:83-116`: Data model / API surface / Integration / Scope / Verification / Performance.
211
+ - For every finding, ask: does another finding contradict this severity given the Discovery Map? If yes, note the tension.
212
+ - Produce a short `## Reconciliation Notes` block inside the artifact capturing any severity moves and the rationale.
213
+
214
+ 5. **Emit the reconciled severity map** — authoritative severity per finding, carrying the advisor's guidance when present. Keep the per-pass grouping (do NOT tag each finding with its originating lens in prose; the H2 it sits under is the tag).
215
+
216
+ ## Step 5: Developer Checkpoint
217
+
218
+ Use the grounded-questions-one-at-a-time pattern. Every question must reference real findings with `file:line` evidence and pull a DECISION from the developer.
219
+
220
+ **Present a compiled scan first** (under 20 lines):
221
+
222
+ ```
223
+ Review: [scope]
224
+ Files: [N]
225
+ Quality: [C🔴/I🟡/S🔵/D💭]
226
+ Security: [C/I/S/D]
227
+ Dependencies: [C/I/S/D | not-applicable]
228
+ Precedents: [N composite lessons, top: "[one-line]"]
229
+ Advisor: [used (model) | unavailable]
230
+ ```
231
+
232
+ Wait for the developer's response. Then ask **one question at a time**, waiting for each answer.
233
+
234
+ **Question patterns:**
235
+
236
+ - **Severity dispute**: Only ask when the advisor re-ranked a finding or when inline reconciliation surfaced a contradiction. Use `ask_user_question` — Options: "Keep [original severity] (Recommended)" / "Downgrade" / "Escalate" — with `file:line` evidence in the description.
237
+ - **Scope ambiguity**: "❓ Question: finding at `file:line` lies in a test helper — does the team count test-only issues? Include in artifact or not?"
238
+ - **False-positive confirmation**: Only ask when a security/dep finding hinges on context the orchestrator cannot see (e.g., `exec()` with a variable that the developer might know is constant).
239
+
240
+ **Critical rules:**
241
+ - Ask ONE question at a time. Wait before asking the next.
242
+ - Lead with the most load-bearing finding.
243
+ - Skip the checkpoint entirely if no disputes surfaced and the developer set `status: approved` in the scan response.
244
+
245
+ ## Step 6: Write the Review Document
246
+
247
+ 1. **Determine metadata**:
248
+ - Filename: `thoughts/shared/reviews/YYYY-MM-DD_HH-MM-SS_[scope-kebab].md`
249
+ - Repository: git root basename (fallback: cwd basename).
250
+ - Branch + commit: from git-context injected at session start, or `git branch --show-current` / `git rev-parse --short HEAD` (fallback: `no-branch` / `no-commit`).
251
+ - Reviewer: user from injected git-context (fallback: `unknown`).
252
+
253
+ 2. **Write the artifact** using the Write tool (no Edit — this skill writes once per run):
254
+
255
+ ```markdown
256
+ ---
257
+ date: [ISO 8601 with timezone]
258
+ reviewer: [User]
259
+ repository: [Repo name]
260
+ branch: [Branch]
261
+ commit: [Short hash]
262
+ review_type: [commit|pr|staged|working]
263
+ scope: "[What was reviewed]"
264
+ files_changed: [N]
265
+ critical_issues: [Count across all lenses]
266
+ important_issues: [Count]
267
+ suggestions: [Count]
268
+ quality_issues: [Count]
269
+ security_issues: [Count]
270
+ dependency_issues: [Count | 0 when not-applicable]
271
+ passes: [quality, security, dependencies] # omit dependencies when not-applicable
272
+ advisor_used: [true|false]
273
+ advisor_model: [provider:id] # only when advisor_used is true
274
+ status: [approved|needs_changes|requesting_changes]
275
+ tags: [code-review, relevant-components]
276
+ last_updated: [YYYY-MM-DD]
277
+ last_updated_by: [User]
278
+ ---
279
+
280
+ # Code Review: [Scope Description]
281
+
282
+ **Date**: [full ISO date]
283
+ **Reviewer**: [User]
284
+ **Repository**: [Repo]
285
+ **Branch**: [Branch]
286
+ **Commit**: [Short hash]
287
+
288
+ ## Review Summary
289
+ [3–5 sentences: overall verdict, highest-severity finding per lens, advisor outcome.]
290
+
291
+ ## Issues Found
292
+
293
+ ### Quality
294
+ #### 🔴 Critical
295
+ - `file:line` — [evidence + one-sentence fix pointer]
296
+ #### 🟡 Important
297
+ - `file:line` — [evidence + fix pointer]
298
+ #### 🔵 Suggestions
299
+ - `file:line` — [nearby template reference + suggested alignment]
300
+ #### 💭 Discussion
301
+ - `file:line` — [open question or trade-off]
302
+
303
+ ### Security
304
+ #### 🔴 Critical
305
+ - `file:line` — [sink quoted + exploitability rationale referencing auth-boundary from Discovery Map]
306
+ #### 🟡 Important
307
+ - `file:line` — [missing hardening + secure precedent]
308
+ #### 🔵 Suggestions
309
+ - `file:line` — [pattern divergence from secure example]
310
+ #### 💭 Discussion
311
+ - `file:line` — [architectural question]
312
+
313
+ ### Dependencies
314
+ (Omit this H3 block entirely when `passes` excludes `dependencies`.)
315
+ #### 🔴 Critical
316
+ - `dep@ver` (`package.json:line`) — [CVE id + link + affected-range + fix version]
317
+ #### 🟡 Important
318
+ - `dep@ver` — [moderate CVE / license / lockstep note with link]
319
+ #### 🔵 Suggestions
320
+ - `dep@ver` — [minor/transitive drift]
321
+ #### 💭 Discussion
322
+ - `dep@ver` — [architectural dep question]
323
+
324
+ ## Precedents & Lessons
325
+ - `commit hash` — [precedent + one-sentence takeaway]
326
+ - Composite lessons (most-recurring first):
327
+ 1. [lesson 1]
328
+ 2. [lesson 2]
329
+
330
+ ## Pattern Analysis
331
+ [How changes align with or diverge from existing patterns in the changed files. Cite `file:line` of the nearest established pattern.]
332
+
333
+ ## Impact Assessment
334
+ [Files and inbound refs affected per the Discovery Map. Enumerate each affected consumer with `file:line` and what changes for it.]
335
+
336
+ ## Historical Context
337
+ [Links to thoughts/ docs referenced by precedent-locator; one line each, no summaries.]
338
+
339
+ ## Advisor Adjudication
340
+ (Omit when `advisor_used: false`.)
341
+ [Advisor model prose pasted VERBATIM. Do not edit or paraphrase. If `advisor error:` prefix is present, leave it as-is.]
342
+
343
+ ## Reconciliation Notes
344
+ (Include only when the inline path ran, OR when developer dispute in Step 5 moved a severity.)
345
+ [Short prose: which findings shifted severity and why.]
346
+
347
+ ## Recommendation
348
+ [Clear verdict: Approved / Needs Changes / Requesting Changes. Cite the top 1–3 items that drove the verdict with `file:line`.]
349
+ ```
350
+
351
+ ## Step 7: Present and Chain
352
+
353
+ ```
354
+ Review written to:
355
+ `thoughts/shared/reviews/[filename].md`
356
+
357
+ [C] critical, [I] important, [S] suggestions across [Q] quality, [Se] security, [D] dependency issues.
358
+ Advisor: [used (model) | unavailable]
359
+ Status: [verdict]
360
+
361
+ Top items:
362
+ 1. `file:line` — [headline]
363
+ 2. `file:line` — [headline]
364
+ 3. `file:line` — [headline]
365
+
366
+ Ask follow-ups, or run `/skill:revise` to address the findings.
367
+ ```
368
+
369
+ ## Step 8: Handle Follow-ups
370
+
371
+ - If the user asks for deeper analysis of a specific finding, spawn a targeted `codebase-analyzer` on that area (1 agent max) and append a `## Follow-up [timestamp]` section using the Edit tool.
372
+ - Update frontmatter: `last_updated`, `last_updated_by`, and `last_updated_note: "Appended follow-up on [area]"`.
373
+ - Never rewrite prior findings; only append.
374
+
375
+ ## Important Notes
376
+
377
+ - **No tool-permission widening**: `allowed-tools` is intentionally omitted — the skill inherits `Agent`, `ask_user_question`, `advisor`, `Write`, `web_search`, `todo` per `.rpiv/guidance/skills/architecture.md:40`. Do NOT re-add the line.
378
+ - **Always use parallel Agent tool calls** in Phase-2 to maximise efficiency.
379
+ - **Always read the full diff FIRST** (Step 1) before spawning any Phase-1 or Phase-2 agent.
380
+ - **Always pass the Discovery Map inline** as `Known Context` to every Phase-2 agent — agents are `isolated: true` and cannot see sibling transcripts.
381
+ - **Security-lens precision stance**: prefer false negatives over false positives. Security evidence must carry `confidence ≥ 8` and 🔴 requires an explicit source→sink trace. Missing hardening without a traced sink is NOT a finding. Keep the Security-lens exclusion list in sync with the reference FP-filter precedents.
382
+ - **Critical ordering**: Follow the numbered steps exactly.
383
+ - ALWAYS resolve scope and bail on empty diff (Step 1) before Phase-1.
384
+ - ALWAYS wait for Phase-1 completion before Phase-2 dispatch.
385
+ - ALWAYS wait for ALL Phase-2 agents to complete before reconciliation (Step 4).
386
+ - ALWAYS probe advisor availability before calling `advisor()` (strip-when-unconfigured at `packages/rpiv-advisor/advisor.ts:463-472`).
387
+ - ALWAYS emit the `## Pre-Adjudication Findings` block to the main branch BEFORE calling `advisor()` — the advisor reads `getBranch()` (main-thread-only at `packages/rpiv-advisor/advisor.ts:336`) and will not see evidence you did not flush.
388
+ - ALWAYS preserve the severity taxonomy emoji + naming (🔴 Critical / 🟡 Important / 🔵 Suggestions / 💭 Discussion) and the existing frontmatter keys verbatim — discovery agents `thoughts-locator` and `thoughts-analyzer` grep these.
389
+ - NEVER call `advisor()` from inside a sub-agent — its branch is invisible to the advisor.
390
+ - NEVER parse advisor prose mechanically — paste verbatim into `## Advisor Adjudication`.
391
+ - NEVER add a new bundled agent to support this skill — zero-new-agents contract per `packages/rpiv-pi/extensions/rpiv-core/agents.ts:148-268` sync cost.
180
392
  - **Severity classification**:
181
- - Use evidence from agents to justify each issue's severity
182
- - Provide specific file:line references for all issues
183
- - Include examples of correct patterns when available
184
- - Suggest concrete fixes, not vague improvements
393
+ - Evidence from agents justifies each issue's severity.
394
+ - Every finding carries a `file:line`.
395
+ - Correct-pattern examples cited where available.
396
+ - Fixes are concrete (pointer, not vague).
397
+ - **Agent roles (for this skill)**:
398
+ - `integration-scanner` (Phase-1): inbound refs, outbound deps, auth-boundary crossings.
399
+ - `codebase-analyzer` × 3 (Phase-2): one per lens — evidence-only, no recommendations (honors the guardrail at `packages/rpiv-pi/agents/codebase-analyzer.md:113-119`).
400
+ - `precedent-locator` (Phase-2, always): git history + thoughts/ for lessons.
401
+ - `web-search-researcher` (Phase-2, conditional on `ManifestChanged`): CVE / GitHub Advisory / OSS Index lookups with LINKS.
402
+ - **File reading**: read the diff FULLY (no limit/offset) via `git` commands before spawning agents. Let agents read their scoped targets; the orchestrator does not need to read source files for non-risk findings.
403
+ - CC auto-loads CLAUDE.md files when agents read files in a directory — no need to scan for them explicitly.