Skip to content

HUD plugins: the package format's descriptor table, strict parser and SVG mask checker - #1139

Merged
GLinnik21 merged 13 commits into
mainfrom
hud/pr5-hud-format
Oct 29, 2026
Merged

GLinnik21 merged 13 commits into
mainfrom
hud/pr5-hud-format

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

The first part of PR5 in the player-HUD plugin plan (docs/hud-plugins.md, added here): the package format's descriptor table, its strict parser and the SVG mask checker. Nothing calls the module yet. The compiler, the reachability check, the lint command and the schema emission come next, as their own PR on top of this one.

What changes

  • appkit::hud_format::schema: one static descriptor table. It names every top-level key, layout key, band, cell kind, control-item key, widget, rest and focus style, command with typed parameters, condition and theme token, with the type, the allowed values, the default and the format minor each arrived in. The parser reads it, and the future schema emitter will too, so no name is listed twice.
  • hud_format::parse: a strict parse into typed package values. Unknown or duplicate keys, unknown names and wrong types are findings. So is a format newer than this build ("Made for a newer PlxNative") or of another major ("Uses an older HUD format"). Conditions come from the closed list with ! and AND only, and the palette takes lower-case names with #rrggbb values. Every finding has the lint shape {code, severity, JSON pointer, rule, hint, nearest valid names}.
  • hud_format::svg_subset: a Rust tokenizer for the icon contract (<svg viewBox> + <path d>), run before nanosvg sees any bytes. Assets are masks tinted per state. Any element but svg and path, gradients included, is HUD-E0701. Any other attribute, and any fill that is not mask-white (a colour, url(#g)), is HUD-E0702. Each comes with a hint saying why. Bytes and path count per asset are bounded.
  • ui::rec::strict_json is shared: it becomes pub mod, and the parser calls its order-preserving reader with a 1 MiB cap on the input and a 16 MiB decoded-memory budget. It is still the repository's only duplicate-key reader, and the recorder's decode/decode_with keep their visibility and behaviour.
  • Tests:
    • the reference design from the plan (reference.plxhud.json) and a minimal package parse with zero findings;
    • invalid fixtures for each parse rule and command parameter, asserting the code and the pointer;
    • a drift test that walks the table: every entry is accepted and unlisted names are refused;
    • seeded, deterministic byte and key mutations that never panic;
    • the real mask icons in assets/icons/ pass, and the icons that are not masks are refused.
  • ci/list-caps.ini: classifies the four new bounds (MAX_NEAREST, MAX_PACKAGE_BYTES, MAX_ASSET_BYTES, MAX_PATHS_PER_ASSET).
  • docs/hud-plugins.md: the design record the planner and critic approved.

No Cargo change and no new dependency: appkit reaches serde_json's types through plx_ui::rec::strict_json.

Issue

No issue tracks the HUD-plugin work, and none was opened for this PR.

Gates

Local runs, crate tests only (the full gate is this PR's CI), on head 84430d1e5:

  • make test-crate C=plx_appkit T=hud_format: test result: ok. 121 passed; 0 failed; 0 ignored; 0 measured; 351 filtered out; finished in 5.12s
  • make test-crate C=plx_ui: test result: ok. 1401 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 17.46s
  • ci/check-list-caps.py, ci/check-module-layers.py, ci/check-module-cycle.py and ci/check-deps.sh, run directly: green.

Review

One Opus review, verdict FIX FIRST: one MAJOR, five MINOR. All six are fixed. origin/main moved by six commits; the PR does not conflict with it (git merge-tree), so it was not merged in.

  1. MAJOR, a comment hides elements from the SVG checker that nanosvg then parses. Confirmed: nanosvg ends any <! construct at the first >. Fixed in svg_subset.rs::comment: a comment with a < after a > in its body is HUD-E0704. I did not take the review's "refuse < or >" literally: assets/icons/more.svg has one <path> so in its comment and ships, and a lone > leaves only text for nanosvg, so refusing it would reject a real icon (the_real_mask_icons_pass failed when I tried it). Red first: the review's smuggled asset, a > <b comment and a two-path comment were accepted; they are refused now, and the prose and a < b comments still pass.
  2. MINOR, one hostile package makes the parse do unbounded work. Fixed. A palette name is at most ID_LEN (40) like an id, nearest compares at most 48 characters of a candidate, and the unknown-face hint lists twelve assets and says how many more. Test red before the fix: a 41-letter palette name was accepted. Not done: the palette's entry count and the findings count are still bounded only by the 1 MiB input, so thousands of unknown inks against tens of thousands of palette entries still cost work per ink. A cap there is a format decision for the plan, not a cheap fix.
  3. MINOR, the parser lists the top-level keys a second time. Fixed by correcting the doc (reading Package::from_object is the one place keys are named) and adding the_package_reader_names_only_keys_the_table_has, which fails if schema::ROOT or the app node drops or renames a key the reader uses.
  4. MINOR, an item with a bad command has its other keys skipped. Fixed: walk_unresolved judges the item's own keys (duplicates, ranges, names, missing required keys) and skips a key only the command's parameters could own, and the cross-key rules. Red first: the review's shape reported only E0301; it now reports E0301, E0201, E0101 and E0103.
  5. MINOR, the 64 MiB decode budget and the "decoded recording budget" message. Fixed: the budget is 16 MiB (a full 1 MiB package of SVG text is about 11 MiB of it), and an over-budget package says "the package is too large to read". Red first: 100 000 array nodes decoded fine before. The PR body line is corrected too.
  6. MINOR, lane-coordination text in the module doc. Removed from hud_format.rs; the same "contract freeze" paragraph in schema.rs is reworded.

Also: the two new .take( sites needed ci/list-caps.ini sections (nearest, listed); check-list-caps.py caught it.

🤖 Generated with Claude Code

GLinnik21 and others added 13 commits October 29, 2026 21:34
…rmat, ordered strict_json)

Lands the types and signatures that the parallel hud_format packages compile against.
The format is PR5 part 1 of the player-HUD plugin plan (docs/hud-plugins.md follows).

REAL bodies:
- hud_format.rs: Severity, Code, Finding (lint shape: code, severity, pointer, rule,
  message, hint, nearest), the 32 frozen codes (codes::E0100..E0706, codes::ALL),
  REASON_NEWER / REASON_OLDER, pointer_push / pointer_index (RFC 6901), nearest
  (Levenshtein, at most 3, deterministic), has_error.
- ui rec::strict_json is now a shared `pub mod`. The single visitor is generic over the
  tree it builds (Value output and budget charges unchanged); `Ordered` keeps document
  order AND duplicate keys; `decode_ordered(bytes, cap)`; Error/Map/Number/Value re-exported
  so appkit (which has no serde_json dependency) can hold them.
- hud_format::schema: the descriptor-table TYPES (Since, Field, Node, NodeKind, Ty, Rule,
  Cmd, FaceState, Condition), lookups (all_nodes, node, field, command, condition),
  COMMANDS (the ten) and CONDITIONS (the eleven) complete for 1.0, the theme-tied allow-lists
  and resolvers (ink_token, size_rung with HUD_TITLE 54, space_token, builtin_icon), and
  ROOT (top level) plus APP. HUD_TITLE_PX mirrors player_hud's private HUD_TITLE_SZ; that
  file is left untouched, wave B unifies the two.
- hud_format::parse: Parsed, Package, AppRange, Object, Val, Cond, Keyed, Ctx::v1 and the
  accessors.

STUBS (marked CONTRACT FREEZE in the source):
- schema: every node under ROOT's `layout` (B fills).
- parse: parse() and validate_json() panic with unimplemented! (C fills).
- svg_subset: check_asset() accepts every string (A fills); MAX_ASSET_BYTES and
  MAX_PATHS_PER_ASSET are landed with their ci/list-caps.ini rows.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… items and Up Next

Fills every node of package format 1.0 below the top level: layout and its
scrim union, bands, the cell with its twelve kinds, the playbar grab, the
strip card, control items and Up Next, with required-ness, state-keyable
numbers/inks/gaps/bold, defaults and cross-key rules as data. Adds the
binding catalogue and per-position bind lists, the body-size list tied to
the rungs, close and check as built-in faces, and the module doc's decisions
and open items. Table self-consistency tests pin it.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…re, strict_json budget and nesting tests

check_asset is a Rust tokenizer that enforces the icon contract before nanosvg
sees the bytes: svg and path only, gradient and colour content refused as
HUD-E0701/E0702 with the mask reason, entities and references as HUD-E0703,
malformed documents as HUD-E0704, size and path bounds as HUD-E0705/E0706.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…rser drift test

The valid fixtures parse with no finding. The invalid corpus asserts the frozen code AND the
JSON pointer of every parse rule and every command parameter (the version rows carry the exact
user-facing reasons). Seeded xorshift64* byte and key mutations never panic and always answer in
the lint shape, through parse and through validate_json on the root node. The drift test walks
schema::all_nodes and schema::COMMANDS, matching exhaustively on Ty, Pattern, NodeKind and Rule,
and proves every listed value is accepted and every unlisted name refused.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
hud_format.rs did not declare 'mod tests;', so hud_format/tests.rs was never compiled.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…es, judge an item whose command is unknown

- svg_subset: nanosvg ends any `<!` construct at the first `>`, so a comment that holds a `>` followed
  by a `<` hid elements (gradients, colour, any number of paths) from the checker that nanosvg then
  parsed. Such a comment is HUD-E0704. Prose with a lone `>` (a real icon mentions `<path>`) still passes.
- parse: a palette name is at most ID_LEN like an id, `nearest` compares only the first 48 characters
  of a candidate, and a hint lists at most twelve declared assets, so one hostile package cannot make
  the parse quadratic in a name or a finding hundreds of KB.
- parse: the reader gets a 16 MiB decoded-memory budget instead of the recorder's 64 MiB, and an
  over-budget package says it is too large to read rather than naming a recording.
- parse: an item whose command is unknown or missing still has its own keys judged (duplicates,
  ranges, names, missing required keys), so one round reports every mistake.
- parse: the doc no longer claims the parser names no key; a test fails if the table drops one it reads.
- hud_format, schema: remove the parallel-lane "contract freeze / coordinator" text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 marked this pull request as ready for review October 29, 2026 20:51
@GLinnik21
GLinnik21 merged commit 2623e45 into main Oct 29, 2026
19 checks passed
@GLinnik21
GLinnik21 deleted the hud/pr5-hud-format branch October 29, 2026 20:52
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