Skip to content

refactor: encapsulate Attrs/Modifiers raw bits (audit round 3, R5/A5) - #30

Merged
mizu-jun merged 1 commit into
masterfrom
refactor/r5-a5-encapsulate-bitflags
Jul 5, 2026
Merged

refactor: encapsulate Attrs/Modifiers raw bits (audit round 3, R5/A5)#30
mizu-jun merged 1 commit into
masterfrom
refactor/r5-a5-encapsulate-bitflags

Conversation

@mizu-jun

@mizu-jun mizu-jun commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Implements findings R5/A5 from the round 3 audit (docs/plans/audit-round3-2026h2.md).

Change

Attrs and Modifiers exposed their inner byte as pub u8, leaking the bit representation across the crate boundary. The field is now private with a small API:

  • Attrs::new / bits / insert / remove (plus the existing is_bold/… predicates)
  • Modifiers::new / bits (plus is_shift/is_ctrl/is_alt/is_meta)

All external construction (Attrs(x) / Modifiers(x)) → ::new(x), all external .0 reads → .bits(), and the VT parser's in-place SGR toggling uses insert/remove.

No PROTOCOL_VERSION bump

The audit listed this as a "next PROTOCOL bump" candidate, but it is not wire-breaking: a serde newtype serializes as its inner value regardless of field visibility, so the postcard output is byte-for-byte identical. Bumping would create a false incompatibility. Rationale recorded in ADR-0009.

Audit report updates

  • R5/A5: done.
  • P5 dropped. Its premise (WebSocket bandwidth) does not hold: the web terminal already flattens GridDiff to char-only Message::Text (ws.rs::pty_message_to_text), so cell-attribute RLE would not touch the web path at all, and the postcard path it would affect is local IPC where the audit itself rated the gain negligible. Real web-bandwidth work would be WebSocket permessage-deflate.

Tests

cargo test (all crates, 26 suites), cargo clippy --all-targets -- -D warnings, cargo fmt --check all green.

Remaining deferred audit items: P3, P6 (both need GPU profiling / a running app).

… R5/A5)

Attrs and Modifiers exposed their inner byte as `pub u8`, leaking the bit
representation across the crate boundary. Make the field private and add a small
API instead:

- Attrs::new / bits / insert / remove (plus existing is_bold/… predicates)
- Modifiers::new / bits (plus is_shift/is_ctrl/is_alt/is_meta)

All external construction (`Attrs(x)` / `Modifiers(x)`) becomes `::new(x)`, all
external `.0` reads become `.bits()`, and the VT parser's in-place SGR toggling
uses insert/remove.

No PROTOCOL_VERSION bump: a serde newtype serializes identically whether its
field is public or private, so the postcard wire format is byte-for-byte
unchanged. Rationale recorded in ADR-0009.

The audit report is updated: R5/A5 done, and P5 dropped (its WebSocket-bandwidth
premise does not hold — the web terminal already sends char-only text, so
cell-attribute RLE would not affect it).

Tests: cargo test (all crates, 26 suites) / clippy --all-targets -D warnings /
fmt --check green.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

Coverage report


Generated by cargo llvm-cov (workspace minus nexterm-client-gpu and nexterm-i18n).

@mizu-jun
mizu-jun merged commit e34c538 into master Jul 5, 2026
12 checks passed
@mizu-jun
mizu-jun deleted the refactor/r5-a5-encapsulate-bitflags branch July 5, 2026 16:15
mizu-jun added a commit that referenced this pull request Jul 5, 2026
Audit round 3: reliability, performance, and encapsulation improvements
(PRs #26#30). No protocol or snapshot version change — compatible with 1.12.0.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
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