You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enhance risk analysis features and documentation (#14)
- Updated the risk scoring system to include detailed per-file risk tiers (SAFE, REVIEW, TEST, CRITICAL) and narratives.
- Introduced new slash commands `/pr-risk` and `/pr-fix` for AI-assisted PR reviews, providing actionable insights based on risk assessments.
- Enhanced documentation to reflect changes in risk triage, scoring formulas, and command usage.
- Added tests for risk triage formatting and evidence gating logic to ensure accurate risk reporting.
This update improves the clarity and usability of the risk analysis tools within the project.
-**Per-file risk scoring:** every changed file gets a risk score (0–100) and tier (SAFE/REVIEW/TEST/CRITICAL)
176
+
-**Risk triage:** files grouped by tier with human-readable risk narratives explaining why each file is flagged
175
177
-**Test gaps:** changed files with no test coverage, flagged before merge
178
+
-**Test suggestions:** auto-generated recommendations for high-risk untested files (which test file to create, what to test)
176
179
-**Coupling detection:** pairs of changed files that depend on each other
177
180
-**Hidden coupling:** co-change partners *not in your diff* that may need updating
178
-
-**Per-file blast radius:**which specific changes carry the most risk
181
+
-**Aggregate risk:**overall PR risk score with percentile ranking against historical baselines (after 10+ analyses)
179
182
-**Aggregated must_read:** merged context across all changed files
180
183
181
-
Use `--ci --fail-on high` to gate PRs automatically. Results are stored in a local history database, enabling trend tracking with `contextception history`:
184
+
### Risk Tiers
185
+
186
+
| Tier | Score | Meaning |
187
+
|------|-------|---------|
188
+
|**SAFE**| 0–20 | New files, well-tested utilities, low coupling |
189
+
|**REVIEW**| 21–50 | Moderate risk, standard code review sufficient |
190
+
|**TEST**| 51–75 | High risk, targeted testing recommended |
191
+
|**CRITICAL**| 76–100 | Maximum risk, regressions likely without careful review |
192
+
193
+
Risk scores combine change status, structural factors (importer count, co-change frequency, fragility, mutual dependencies), and test coverage adjustments.
194
+
195
+
### Token-optimized output
196
+
197
+
Use `--compact` for a text summary optimized for LLM consumption (~60–75% fewer tokens than JSON):
198
+
199
+
```bash
200
+
$ contextception analyze-change --compact
201
+
```
202
+
203
+
### CI integration
204
+
205
+
Use `--ci --fail-on` to gate PRs automatically. A risk badge is printed to stderr:
Results are stored in a local history database, enabling trend tracking with `contextception history`:
182
216
183
217
```bash
184
218
$ contextception history hotspots # Files that repeatedly appear as hotspots
@@ -249,7 +283,20 @@ Contextception averages ~1,000 tokens per analysis vs. Repomix's full-repo outpu
249
283
250
284
## MCP Setup (30 seconds)
251
285
252
-
Make your AI agent smarter. Add to your `~/.claude.json` (Claude Code) or equivalent MCP config:
286
+
Make your AI agent smarter. The `setup` command auto-detects your editor and configures everything:
287
+
288
+
```bash
289
+
# Claude Code (MCP server + hooks + slash commands)
290
+
contextception setup
291
+
292
+
# Cursor or Windsurf
293
+
contextception setup --editor cursor
294
+
contextception setup --editor windsurf
295
+
```
296
+
297
+
Use `--dry-run` to preview changes, or `--uninstall` to reverse.
298
+
299
+
Or configure manually — add to your `~/.claude.json` (Claude Code) or equivalent MCP config:
253
300
254
301
```json
255
302
{
@@ -273,11 +320,22 @@ This exposes nine tools to the AI agent:
273
320
|`get_entrypoints`| Return entrypoint and foundation files for project orientation |
274
321
|`get_structure`| Return directory structure with file counts and language distribution |
275
322
|`get_archetypes`| Detect representative files across architectural layers |
276
-
|`analyze_change`| Analyze the impact of a git diff / PR (blast radius, test gaps, coupling) |
323
+
|`analyze_change`| Analyze the impact of a git diff / PR (risk scoring, triage, test gaps, coupling) |
277
324
|`rate_context`| Rate how useful a previous `get_context` result was (feedback for accuracy tracking) |
278
325
279
326
Works with **Claude Code**, **Cursor**, **Windsurf**, and any MCP-compatible tool.
280
327
328
+
### Slash Commands
329
+
330
+
Two built-in slash commands for AI-assisted PR review (installed automatically by `contextception setup`):
331
+
332
+
| Command | Description |
333
+
|---------|-------------|
334
+
|`/pr-risk`| Run risk analysis on the current branch and present an actionable, human-friendly review |
335
+
|`/pr-fix`| Analyze risk, then build an ordered plan to fix every issue found (test gaps, coupling, fragility) |
336
+
337
+
These work by combining contextception's deterministic risk analysis with the LLM's ability to explain and translate — contextception computes the scores, the LLM presents them in plain language. See [`integrations/`](integrations/) for setup details.
338
+
281
339
---
282
340
283
341
## Language Support
@@ -320,7 +378,7 @@ contextception session Show contextception adoption across Clau
320
378
|`--mode plan\|implement\|review`| Shape output for AI workflow stage |
321
379
|`--token-budget N`| Cap output to fit token limits |
322
380
|`--compact`| Token-optimized text summary (~60-75% fewer tokens than JSON) |
323
-
|`--ci --fail-on high\|medium`| Exit codes for CI pipelines |
381
+
|`--ci --fail-on high\|medium\|critical`| Exit codes for CI pipelines |
324
382
|`--cap N`| Limit must_read entries (overflow to related) |
325
383
|`--no-external`| Exclude external dependencies |
326
384
|`--no-update-check`| Disable automatic update version check |
Use `--dry-run` to preview changes, or `--uninstall` to reverse. For Claude Code, this also installs hooks that remind the AI to call `get_context` before editing files.
41
+
Use `--dry-run` to preview changes, or `--uninstall` to reverse. For Claude Code, this installs:
42
+
- MCP server configuration
43
+
- PreToolUse hooks that remind the AI to call `get_context` before editing files
44
+
-`/pr-risk` and `/pr-fix` slash commands for AI-assisted PR review
42
45
43
46
## Manual Configuration
44
47
@@ -151,6 +154,17 @@ All integrations expose the same nine tools:
Two slash commands are included for AI-assisted PR review. These are installed automatically by `contextception setup` for Claude Code.
160
+
161
+
| Command | File | Description |
162
+
|---------|------|-------------|
163
+
|`/pr-risk`|[`claude-code/pr-risk.md`](claude-code/pr-risk.md)| Run risk analysis and present a human-friendly review with verdicts, test coverage, and next steps |
164
+
|`/pr-fix`|[`claude-code/pr-fix.md`](claude-code/pr-fix.md)| Analyze risk, then build an ordered fix plan for every issue (test gaps, coupling, fragility) |
165
+
166
+
For Cursor/Windsurf, place the command files in `.cursor/rules/` or `.windsurf/rules/` respectively. For other agents, see [`pr-risk-review.md`](pr-risk-review.md) for the full prompt template.
167
+
154
168
## Further Reading
155
169
156
170
-[MCP Tutorial](../docs/mcp-tutorial.md) — step-by-step guide to adding context intelligence to any AI agent
0 commit comments