feat: HC-110 hypercode explain — full cascade trace#21
Conversation
…osers - `hypercode explain <file.hc> --hcs <file.hcs> [--ctx ...] <selector> [property]` prints the winning rule, losing rules with specificity/order/file/line; exits 1 on no match (message to stderr) - `Explainer` struct in `Sources/Hypercode/Explain/` walks Command + ResolvedNode trees in parallel; uses existing `selectorSpec()` for matching and `losers: [Match]` from PR-1 for the trace - `CascadeSheetReader.parseSelector(fromString:)` exposes selector parsing for CLI use - 6 tests covering: dev/production property trace, child selector, no-match, all-properties, text rendering Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a9402b0708
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Adds an explain subcommand and expands the resolution/IR pipeline to retain full cascade traces (winner + losers), typed scalar values, and a v2 IR format (including node/document hashing) so users can introspect why each property resolved the way it did.
Changes:
- Introduce
hypercode explain <file.hc> --hcs <file.hcs> [--ctx ...] <selector> [property]and anExplainertree-walker that renders cascade traces. - Add typed
.hcsproperty parsing (TypedValue) and propagate file/line provenance into rule matches, resolved values, and IR v2. - Extend emitter with
--ir-version 1|2(default v2) and add IR v2 JSON schema + SHA-256 hashing support.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/HypercodeTests/WhiteLabelTests.swift | Update expectations to compare against TypedValue values. |
| Tests/HypercodeTests/SHA256Tests.swift | Add SHA-256 test vectors for the hashing helper. |
| Tests/HypercodeTests/HCSReaderTests.swift | Update .hcs parsing tests for typed inference (string/int/bool). |
| Tests/HypercodeTests/ExplainTests.swift | Add unit tests covering Explainer traces and text rendering. |
| Tests/HypercodeTests/EmitterTests.swift | Add v2 IR structure + hash determinism assertions. |
| Tests/HypercodeTests/CascadeResolverTests.swift | Update expectations to typed values; add loser-retention coverage. |
| Sources/HypercodeCLI/main.swift | Add explain command; add --ir-version for emit; pass .hcs file paths into the reader. |
| Sources/Hypercode/HCS/Resolver.swift | Change resolved values to typed + retain winner/losers with provenance including file. |
| Sources/Hypercode/HCS/CascadeSheetReader.swift | Add read(_:file:), typed scalar inference, and public selector parsing for CLI use. |
| Sources/Hypercode/HCS/CascadeSheet.swift | Introduce TypedValue, add Rule.file, and add Match for cascade trace entries. |
| Sources/Hypercode/Explain/Explainer.swift | New explain engine + text rendering of winner/losers with provenance/specificity/order. |
| Sources/Hypercode/Emit/Emitter.swift | Add IR v2 emission (typed values, winner/losers, hashes, context echo) + legacy v1 path. |
| Sources/Hypercode/Crypto/SHA256.swift | Add SHA-256 helper used for v2 hashes. |
| Schema/hypercode-ir-v2.schema.json | Add JSON schema for the new hypercode.ir/v2 format. |
| DOCS/Workplan.md | Add workplan for HC-110..112; needs alignment with current implementation details. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
# Conflicts: # Sources/Hypercode/HCS/CascadeSheetReader.swift
- Explainer.walk asserts command/resolved arrays stay parallel instead of silently truncating via zip if a caller ever breaks the resolver invariant - runExplain rejects extra positional arguments (was silently ignoring them, hiding user mistakes), consistent with other subcommands Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
hypercode explain <file.hc> --hcs <file.hcs> [--ctx ...] <selector> [property]subcommandExplainerinSources/Hypercode/Explain/Explainer.swiftwalks theCommand+ResolvedNodetrees in parallel, reusesselectorSpec()for selector matching, and readsResolvedValue.losers(added in PR-1) for the traceCascadeSheetReader.parseSelector(fromString:)added as a public entry point for CLI useDepends on PR-1 (
feat/hc-112-substrate) for loser retention; depends on PR-2 (feat/hc-112-ir-v2) for branch ordering.Test plan
APIServer > Listenport: winner=.int(8080)Explainer.explainExample usage:
Output:
🤖 Generated with Claude Code