Skip to content

Expose compiled selectors as a public selection tree - #2

Merged
rsheldiii merged 4 commits into
mainfrom
public-selection-tree
Sep 4, 2026
Merged

rsheldiii merged 4 commits into
mainfrom
public-selection-tree

Conversation

@rsheldiii

@rsheldiii rsheldiii commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds a read-only way to inspect a compiled selector, so an application that has a response schema can reject selectors naming fields the schema does not declare. The projector alone cannot do that: it only ever sees response data, and a field absent from one response is not the same as a field that does not exist.

  • JsonMask::CompiledMask#selection_tree returns the root JsonMask::SelectionTree (nil for a blank selector, which passes values through).
  • JsonMask::SelectionTree and JsonMask::Selection are now public constants. Public readers: SelectionTree#named (unescaped name → Selection), #wildcard, and #selection_for(key) (what the projector applies, wildcard merged); Selection#leaf? and #children.
  • Construction and merging (SelectionTree.empty / .single / #merge, Selection.leaf / #merge) remain internal to the parser; the class comments say so. The gem does not use YARD, so the pre-existing @param/@return/@raise tags in json_mask.rb and compiled_mask.rb are replaced with plain comments as well.
  • Version bumped to 0.2.0. CHANGELOG and README updated, including a schema-validation example. The 0.1.0 changelog heading now carries its release date.

No behavior change to parsing or projection.

Motivation

The Wistia MCP server's fields argument is backed by this gem. Agents sometimes guess field names that do not exist and get silently empty responses. Strict validation against each tool's OpenAPI output schema will live in the wistia repo; this PR gives it the traversal API it needs without teaching the gem JSON Schema.

Testing

  • bundle exec rake (Minitest + RuboCop) passes locally on Ruby 3.4.9: 41 runs, 0 failures, no offenses.
  • New tests cover tree shape for names, parenthesized and slash paths, wildcards, merge and leaf-wins semantics, unescaped names, frozenness, selection_for with String and Symbol keys, blank selectors, and a schema-validation walk mirroring the README example.
  • bundle exec rake build produces json-mask-0.2.0.gem.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ALGXui8ksphAfb5D7ifG55

rsheldiii and others added 4 commits September 3, 2026 15:52
CompiledMask#selection_tree returns the root SelectionTree, and
SelectionTree and Selection are public constants. Their readers (named,
wildcard, selection_for, leaf?, children) let an application walk a
selector against a response schema and reject fields it does not
declare, which the projector alone cannot do because it only ever sees
data. Construction and merging stay internal (@api private).

Bump to 0.2.0.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALGXui8ksphAfb5D7ifG55
The gem does not use YARD; keep the prose that explains behavior and
remove the @param/@return/@raise/@api markup, including the tags that
predate the selection tree API.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALGXui8ksphAfb5D7ifG55
Drop class summaries and comments that restate the code; condense the
ones that explain a non-obvious decision (null passthrough, leaf-wins
merging, wildcard folding, the LimitError hierarchy, the dashed entry
file, nil selection trees). Disable Style/Documentation to match.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALGXui8ksphAfb5D7ifG55
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALGXui8ksphAfb5D7ifG55
@rsheldiii
rsheldiii merged commit 4d5702c into main Sep 4, 2026
10 checks passed
@rsheldiii
rsheldiii deleted the public-selection-tree branch September 4, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant