Feat/context tags delta first#587
Open
mick-gsk wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds delta-first trend context (ADR-005) and inline context tagging with dampening (ADR-006) to make drift scores interpretable over time and reduce false positives during intentional variance.
Changes:
- Persist and load score history, compute
TrendContext, and surface it in Rich/JSON/SARIF outputs. - Implement
drift:contextpragmas to tag findings, dampen their scores, and emit per-finding metadata plus aggregate counts. - Add extensive tests and ADR/docs updates for the new behaviors.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
src/drift/analyzer.py |
Applies context-tag dampening, computes trend context from persisted history, and appends new snapshots. |
src/drift/context_tags.py |
New scanner + applicator for drift:context tags and score dampening. |
src/drift/models.py |
Adds TrendContext and new RepoAnalysis fields (trend, context_tagged_count). |
src/drift/output/json_output.py |
Emits trend and context_tagged_count in JSON; adds SARIF properties for context + trend. |
src/drift/output/rich_output.py |
Renders trend delta/sparkline and context tag annotations in terminal output. |
src/drift/config.py |
Adds config knobs for context dampening and delta gating. |
tests/test_delta_first.py |
New tests for trend computation, history persistence, and JSON/SARIF trend output. |
tests/test_context_tags.py |
New tests for scanning/applying context tags, config integration, and output metadata. |
tests/test_output_golden.py |
Updates golden key expectations for new JSON output fields. |
drift.example.yaml |
Documents new config options for context dampening and delta gating. |
docs/adr/005-delta-first-score-interpretation.md |
Adds ADR-005 documenting delta-first interpretation and output contracts. |
docs/adr/006-context-tagging.md |
Adds ADR-006 documenting context-tagging semantics and output. |
benchmark_results/drift_self.json |
Updates benchmark artifact values/shape. |
EPISTEMICS.md |
Adds background rationale for intentional variance + delta interpretation. |
Comment on lines
+49
to
+56
| "trend": { | ||
| "previous_score": analysis.trend.previous_score, | ||
| "delta": analysis.trend.delta, | ||
| "direction": analysis.trend.direction, | ||
| "recent_scores": analysis.trend.recent_scores, | ||
| "history_depth": analysis.trend.history_depth, | ||
| "transition_ratio": analysis.trend.transition_ratio, | ||
| } if analysis.trend else None, |
Comment on lines
+302
to
+303
| prev = snapshots[-1]["drift_score"] | ||
| delta = round(current_score - prev, 4) |
| else: | ||
| direction = "degrading" | ||
|
|
||
| recent = [s["drift_score"] for s in snapshots[-5:]] |
Comment on lines
+288
to
+290
| def _build_trend_context( | ||
| current_score: float, snapshots: list[dict], | ||
| ) -> TrendContext: |
Comment on lines
+312
to
321
| recent = [s["drift_score"] for s in snapshots[-5:]] | ||
|
|
||
| return TrendContext( | ||
| previous_score=prev, | ||
| delta=delta, | ||
| direction=direction, | ||
| recent_scores=recent, | ||
| history_depth=len(snapshots), | ||
| transition_ratio=0.0, | ||
| ) |
Comment on lines
+223
to
+228
| ctx_tags = scan_context_tags(files, repo_path) | ||
| all_findings, context_tagged_count = apply_context_tags( | ||
| all_findings, ctx_tags, dampening=config.context_dampening, | ||
| ) | ||
| # Re-compute impact after dampening so downstream scoring uses adjusted values | ||
| assign_impact_scores(all_findings, config.weights) |
Comment on lines
+97
to
+102
| merged_tags: set[str] = set() | ||
| for line_no in range(start_line, end_line + 1): | ||
| key = (f.file_path.as_posix(), line_no) | ||
| entry = context_tags.get(key) | ||
| if entry is not None: | ||
| merged_tags |= entry |
Comment on lines
+110
to
+112
| context_dampening: float = 0.5 | ||
| fail_on_delta: float | None = None | ||
| fail_on_delta_window: int = 5 |
Comment on lines
+93
to
+96
| trend_parts: tuple = ( | ||
| (" ", ""), | ||
| (f"Δ {trend.delta:+.3f} {arrow} {trend.direction}", delta_color), | ||
| ) |
Comment on lines
+135
to
+137
| # Trend sparkline (ADR-005) | ||
| if trend and trend.recent_scores and trend.direction != "baseline": | ||
| scores_str = " → ".join(f"{s:.3f}" for s in trend.recent_scores) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Related issue
Policy criterion served
First contribution?
Type of change
Release notes label (required)
release:featurerelease:fixrelease:maintenancerelease:docsrelease:skip(internal-only, should not appear in release notes)Validation
pytestpasses locallyruff check src/ tests/passes locallymypy src/driftpasses locallydrift selfdelta checked (target: <= +0.010)Empirical evidence (required for new features)
benchmark_results/oraudit_results/Evidence summary (required when feature is introduced):
Checklist
Risk Audit (POLICY §18 — required for signal/architecture changes)
src/drift/signals/,src/drift/ingestion/, orsrc/drift/output/(skip section)audit_results/fmea_matrix.mdupdated (FP + FN entry for affected signal)audit_results/stride_threat_model.mdupdated (new/changed trust boundary)audit_results/fault_trees.mdreviewed (FT-1/FT-2/FT-3 paths checked)audit_results/risk_register.mdupdated (new risk entry or metric update)Notes for reviewers