Repository navigation
feat: walkthrough Schema Health section (schema drift 3/5) - #85
Conversation
Renders unused concepts/properties with classification and reason, reverse drift, staleness detection via schema fingerprint, and the prune-schema preview hint. Also re-records drift before prune-schema's refresh so the regenerated walkthrough is not stale. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Reviewer's GuideThe PR adds a resilient, conditionally rendered Schema Health walkthrough section with fingerprint-based freshness checks and coverage for fresh, stale, corrupt, and unverifiable records. It also moves post-prune drift recording ahead of output refresh so regenerated walkthroughs remain consistent with the pruned schema, while renumbering later sections dynamically. Sequence diagram for freshness verification in Schema HealthsequenceDiagram
participant W as Walkthrough
participant D as DriftReport
participant F as Fingerprint logic
participant S as schema.json
participant G as Graph output
W->>D: model_validate_json()
D-->>W: report.timestamp and schema_fingerprint
W->>F: _current_drift_fingerprint()
F->>S: _load_json()
F->>G: stream_jsonl(nodes.jsonl)
F->>G: stream_jsonl(edges.jsonl)
F-->>W: current fingerprint
alt fingerprints match
W->>D: unused_concepts()
W->>D: unused_properties()
W-->>W: Render counts, classifications, and reasons
else fingerprint differs
W-->>W: Render stale status and withhold counts
else verification unavailable
W-->>W: Render unverified warning and figures
end
Sequence diagram for consistent post-prune drift recordingsequenceDiagram
participant User as User
participant CLI as prune_schema
participant Drift as _run_drift_analysis
participant Refresh as _refresh_after_prune
participant Walkthrough as Walkthrough output
User->>CLI: prune-schema
CLI->>Drift: _run_drift_analysis(intermediate_dir, output_dir)
Drift-->>CLI: schema_drift.json for pruned schema
CLI->>Refresh: _refresh_after_prune(session_root, intermediate_dir, output_dir)
Refresh-->>CLI: regenerated outputs and walkthrough
Walkthrough-->>User: Schema Health matches pruned schema
Flow diagram for conditional Schema Health walkthrough renderingflowchart TD
A[Generate walkthrough] --> B{schema_drift.json exists?}
B -- No --> C[Render existing sections]
B -- Yes --> D[Read and validate DriftReport]
D --> E{Record readable?}
E -- No --> F[Show unreadable record message]
E -- Yes --> G[Compute current schema and graph fingerprint]
G --> H{Fingerprint verifiable and matches?}
H -- No --> I[Show unverified or stale status]
H -- Yes --> J[Show declared, used, and unused counts]
J --> K[Show unused items and undeclared types]
K --> L{Prunable items exist?}
L -- Yes --> M[Show prune-schema preview hint]
L -- No --> N[Finish Schema Health]
F --> O[Renumber later sections]
I --> O
M --> O
N --> O
C --> P[Render walkthrough]
O --> P
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/mykg/walkthrough.py" line_range="342" />
<code_context>
"flattened_schema.json refreshed; nodes.json/edge_metadata.json missing, "
f"so run: {follow_up}"
)
- # Re-record so schema_drift.json describes the pruned schema, not the old one.
- _run_drift_analysis(intermediate_dir, output_dir, quiet=True)
</code_context>
<issue_to_address>
**Suggested command runs attacker code**
When an attacker can place or rename a session directory to a name containing shell syntax and a user copies and runs a suggested command from its walkthrough, the session directory name is interpolated unquoted into shell commands. When a reader copies and runs either hint, shell metacharacters in that name execute as shell syntax, so the user runs attacker-controlled commands.
Shell-quote the session name when building suggested commands, for example with `shlex.quote`.
Also at `src/mykg/walkthrough.py:370`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and if the fingerprint or drift summary is wrong, the generated walkthrough and drift record can show inaccurate schema-health figures. Re-running drift analysis and regenerating the walkthrough can repair them; reverting the code would not remove artifacts already generated.
Blocking findings: src/mykg/walkthrough.py:342
…clude locks in staleness check Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Adds a Schema Health section to walkthrough.md, rendered only when intermediate/schema_drift.json exists. Shows declared vs used counts, unused concepts/properties with classification and reason, undeclared types, and the prune-schema preview hint. A record whose fingerprint no longer matches the current schema + output counts is shown as stale (counts withheld); unreadable/unverifiable records degrade without raising. Later sections renumber by one only when present.
Also moves the post-prune drift re-record in prune-schema before the output refresh (cli.py, 3 lines) so the regenerated walkthrough is not stale.
🤖 Generated with Claude Code
Summary by Sourcery
Add verified Schema Health reporting to walkthroughs and keep generated drift information current after schema pruning.
New Features:
Bug Fixes:
Enhancements:
Tests: