Excellent! Now let me compile a comprehensive report:
Summary
I've thoroughly reviewed the scan results communication pipeline in desloppify. Here's exactly how scan results and scores are communicated to the LLM:
1. Query.json Output Format (/Users/user_c042661f/Documents/desloppify/desloppify/cli.py)
File Location: .desloppify/query.json (relative to project root)
Writing Function: _write_query(data: dict) (lines 15-26 in cli.py)
python Copy code
def _write_query(data: dict):
"""Write structured query output to .desloppify/query.json.
Every query command calls this so the LLM can always Read the file
instead of parsing terminal output.
"""
The file is written with:
Pretty-printed JSON (indent=2)
Atomic writes using safe_write_text()
Notification printed to stderr: "→ query.json updated"
2. Scan Command Query.json Structure (/Users/user_c042661f/Documents/desloppify/desloppify/commands/scan.py, lines 278-287)
After a scan completes, the following data is written:
python Copy code
_write_query({
"command": "scan",
"score": state["score"], # Legacy weighted-progress score
"strict_score": state.get("strict_score", 0), # Strict variant
"prev_score": prev_score, # Previous score for delta calculation
"diff": diff, # Summary of changes
"stats": state["stats"], # Counts: open, fixed, total, by_tier
"warnings": warnings, # List of warning strings
"objective_score": state.get("objective_score"), # Dimension-based health score
"objective_strict": state.get("objective_strict"),# Strict dimension score
"dimension_scores": state.get("dimension_scores"), # Per-dimension breakdown
"potentials": state.get("potentials"), # Test coverage/detector potentials
"zone_distribution": zone_distribution, # File zone classifications
"narrative": narrative # Computed coaching data
})
Key Fields:
Scores: Two scoring systems exist:
score / strict_score: Legacy weighted-progress (weighted by tier)
objective_score / objective_strict: Modern dimension-based scoring (0-100)
Dimensions: dimension_scores is a dict mapping dimension names to:
python Copy code
{
"score": float, # 0-100
"strict": float, # Strict variant
"checks": int, # Total potential checks
"issues": int, # Issues found
"tier": int, # 1-4 (AUTO_FIX to MAJOR_REFACTOR)
"detectors": dict # Per-detector detail
}
Diff Summary: Contains:
new: count of new findings
auto_resolved: count of auto-resolved findings
reopened: count of reopened findings
suspect_detectors: detectors that returned 0 (transient)
chronic_reopeners: findings reopened 2+ times
skipped_other_lang / skipped_out_of_scope: scope mismatches
Narrative: Computed coaching data from compute_narrative() with:
headline: Current phase status
actions: Prioritized next steps
strategy: Fixer recommendations and hints
reminder_history: Decay tracking for shown reminders
3. Post-Scan Terminal Output (scan.py, lines 255-287)
Printed Summary:
"Scan complete" header (bold)
Diff summary: "+X new · -Y resolved · ↻Z reopened"
Score delta: "Health: 85.2/100 (+2.1) · strict: 82.5/100 ... | 42 open / 156 total"
Dimension deltas (if applicable):
code Copy code
Moved:
Component design 85.0% → 88.5% (+3.5%)
Detector progress bars (15-char bars per detector, showing completion %)
Warnings (reopens, cascading fixes, chronic reopeners)
Strategy hint or suggested next action (in cyan)
Narrative headline (in cyan): e.g. "→ Steady progress: 2 dimensions up"
Terminal Feedback for Scorecard:
code Copy code
Scorecard → scorecard.png (disable: --no-badge | move: --badge-path <path>)
💡 Ask the user if they'd like to add it to their README with:
<img src="scorecard.png" width="400">
4. Scorecard Image Generation (/Users/user_c042661f/Documents/desloppify/desloppify/scorecard.py)
Function: generate_scorecard(state: dict, output_path: Path) (lines 300-358)
Generated Content:
Left Panel:
Title: "DESLOPPIFY SCORE"
Main objective score (large, color-coded: sage ≥90, mustard 70-90, rose <70)
Strict score (smaller, muted color)
Project name (extracted from gh CLI, git remote, or directory name)
Right Panel:
Dimension table with columns: Dimension | Health | Strict
Rows ordered: File health first, then alphabetically
Each row shows dimension name and health/strict percentages (color-coded)
Only dimensions with >0 checks are displayed
Output Path:
Default: scorecard.png (project root)
Customizable via CLI --badge-path or DESLOPPIFY_BADGE_PATH env var
5. Other Commands' Query.json Output
Show Command (show.py, lines 89-100):
python Copy code
_write_query({
"command": "show",
"query": pattern,
"status_filter": status_filter,
"total": len(matches),
"by_file": {...}, # Findings organized by file
"summary": {
"by_tier": {...}, # T1: 5, T2: 12, etc.
"by_detector": {...},
"files": count
},
"narrative": narrative
})
Next Command (next.py, lines 37-44):
python Copy code
_write_query({
"command": "next",
"score": state.get("score", 0),
"items": [
{"id": str, "tier": int, "confidence": str,
"file": str, "summary": str, "detail": dict}
],
"narrative": narrative
})
6. Dimension Scoring Details (/Users/user_c042661f/Documents/desloppify/desloppify/scoring.py)
13 Dimensions (defined in lines 23-38):
Import hygiene (Tier 1) - unused imports
Debug cleanliness (Tier 1) - console logs
API surface (Tier 2) - exports, deprecated
File health (Tier 3) - structural issues
Component design (Tier 3) - props analysis
Coupling (Tier 3) - single-use, coupling
Organization (Tier 3) - orphaned, naming, facade
Code quality (Tier 3) - smells, react issues
Duplication (Tier 3) - dupes
Pattern consistency (Tier 3) - patterns
Dependency health (Tier 4) - cycles
Test health (Tier 4) - test coverage
Security (Tier 4) - security findings
Each dimension score is computed as:
code Copy code
dim_score = (total_checks - total_weighted_failures) / total_checks * 100
Tier Weights: AUTO_FIX=1, QUICK_FIX=2, JUDGMENT=3, MAJOR_REFACTOR=4
Confidence Weights: HIGH=1.0, MEDIUM=0.7, LOW=0.3
Overall Objective Score: Tier-weighted average of all dimension scores, dampened for small-sample dimensions (MIN_SAMPLE=200 checks).
7. State File Structure (/Users/user_c042661f/Documents/desloppify/desloppify/state.py)
Finding TypedDict (lines 18-35):
python Copy code
class Finding(TypedDict):
id: str # detector::file::name
detector: str
file: str # Relative path
tier: int # 1-4
confidence: str # "high" | "medium" | "low"
summary: str
detail: dict
status: str # "open" | "fixed" | "wontfix" | "false_positive" | "auto_resolved"
note: str | None
first_seen: str # ISO timestamp
last_seen: str # ISO timestamp
resolved_at: str | None
reopen_count: int
zone: str # "production" | "test" | "config" | "generated" | "vendor" | "script"
Stats Structure (recomputed before each save):
python Copy code
state["stats"] = {
"total": int,
"open": int,
"fixed": int,
"wontfix": int,
"false_positive": int,
"auto_resolved": int,
"by_tier": { # Per-tier breakdowns
"1": {...},
"2": {...},
...
}
}
Summary Table
Data Location Format Use Case Query output .desloppify/query.jsonJSON LLM reads structured results Scorecard scorecard.pngPNG image README embed or CI display Terminal summary stdout/stderr ANSI colors Human-readable feedback State file .desloppify/state-{lang}.jsonJSON Persistent findings + history Narrative In query.json JSON dict Coaching/guidance text Dimension scores In query.json Dict per dimension Granular health breakdown
All files are written atomically using safe_write_text() with temporary files and atomic os.replace() to prevent corruption.