Repository navigation
design(id): #3455 shared Cf contract for plain output #3861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,269 @@ | ||
| # Design: a value cannot act on the terminal — one Cf contract for `pkgs/id` plain output | ||
|
|
||
| - Date: 2026-11-01 | ||
| - Status: **design — recommendation recorded; implementation is tracked by #2839, #3111, #3456; #3089 is closed**. | ||
| - Issue: [#3455](https://github.com/developing-today/code/issues/3455). | ||
| - Scope: the format-character (Unicode general category Cf) contract for plain-text output in `pkgs/id`. This note does not change implementation code or close the issue. | ||
|
|
||
| ## Decision to make | ||
|
|
||
| Should `pkgs/id` make every plain-text renderer account for Unicode format | ||
| characters (Cf) through one shared character set, or should each output site | ||
| continue to define its own local guard? | ||
|
|
||
| **Recommendation: one shared Cf set, with a surface-specific disposition.** | ||
| Reuse the existing Unicode 16 Cf ranges, but move their predicate from the | ||
| world-gated `petname` module into an unconditional crate-private module such as | ||
| `src/unicode.rs`. Have petname, invite validation, and both plain renderers use | ||
| that one definition. Row renderers escape Cf so a value cannot act on row | ||
| structure or terminal presentation; sanitizers strip only where their output | ||
| contract calls for stripping; validators refuse only where their validation | ||
| contract calls for refusal. Keep the existing renderer-specific quoting rules, | ||
| leave stored/raw values unchanged, and leave `--json` output unchanged. | ||
|
|
||
| ## 1. Context and current state | ||
|
|
||
| The issue identifies three plain-output paths with the same Cf gap but | ||
| different formatting contracts: | ||
|
|
||
| - **Peer rows:** `breaks_row` recognizes Cc controls and U+2028/U+2029, but | ||
| not Cf. `plain_field` returns untriggered values unchanged; in its quoted | ||
| path it escapes quotes, backslashes, and row-breaking characters while | ||
| passing other characters through. Thus Cf-only values are raw, and Cf in a | ||
| value quoted for another reason is also raw | ||
| (`pkgs/id/src/commands/text.rs:38-90`; #2839). | ||
| - **Group, document, and claim rows:** `group::text()` selects quoted output | ||
| for whitespace or Cc controls, then serializes that quoted value with | ||
| `serde_json`; Cf-only values do not trigger quoting, and Cf is not escaped | ||
| if another character triggers the quoted path. `tokens()` uses this for | ||
| each `key=value` field. Claim values are remote signed tag-event data, so | ||
| changing ingest policy is not a universal rendering fix | ||
| (`pkgs/id/src/commands/group.rs:54-80`; #3111). | ||
| - **World-list rows:** Phase 3a is already implemented in this checkout: the | ||
| plain branch calls `world_list_plain_row`, which compares the raw name to | ||
| the default marker and then renders the name through `plain_field`. Existing | ||
| tests cover newline/tab row safety and raw-name marker equality | ||
| (`pkgs/id/src/commands/world.rs:66-84,676-703,1895-1945`; #3089, now closed). | ||
| The world client copies names from the host reply without character | ||
| validation (`pkgs/id/src/world_net.rs:670-698`). | ||
| The remaining gap for this path is Cf coverage when the shared predicate is | ||
| integrated into `plain_field`. | ||
|
|
||
| The existing `text.rs` module doc records the #1613 rule that the printer is | ||
| the total safety boundary, describes quoting for Cc and U+2028/U+2029, and | ||
| preserves the distinction between tab-separated and `key=value` output | ||
| (`pkgs/id/src/commands/text.rs:1-34`). This design extends that ruling to Cf; | ||
| it does not replace the existing format-specific triggers. | ||
|
|
||
| The crate already has a complete Cf predicate in the petname code. The | ||
| function is `pub(crate)` and its documented range set is Unicode 16; its | ||
| rationale is that these characters are invisible or reorder surrounding text | ||
| (`pkgs/id/src/petname.rs:236-266`). The related world display-name and chat | ||
| sanitizers currently filter Cc controls (chat preserves LF/TAB), not Cf | ||
| (`pkgs/id/src/world/util.rs:69-84`). Some validation sites already use the | ||
| shared Cf predicate (for example, invite validation at | ||
| `pkgs/id/src/invite.rs:39-45`); the closing inventory in #3456 must refresh its | ||
| starting list against current code and disposition each remaining site rather | ||
| than assume every `is_control` call has the same job. | ||
|
|
||
| The current visibility is not sufficient for all builds: `commands`, | ||
| `commands::text`, and `commands::group` compile unconditionally, but `petname` | ||
| and `directory` are gated on the `world` feature | ||
| (`pkgs/id/src/lib.rs:163,166-167,197-199`; | ||
| `pkgs/id/src/commands/mod.rs:58-73`). The | ||
| unconditional `invite` module also calls `petname::is_format_char` | ||
| (`pkgs/id/src/lib.rs:190`; `pkgs/id/src/invite.rs:39-45`), so static cfg | ||
| inspection predicts a name-resolution failure in a world-disabled build. The | ||
| default feature set includes `world` (`pkgs/id/Cargo.toml:16-20`), which masks | ||
| that boundary in ordinary builds. The classification helper—not the whole | ||
| `petname` module—belongs in an unconditional shared module; `petname.rs` also | ||
| refers to the world-gated `directory::Refusal` | ||
| (`pkgs/id/src/petname.rs:15`), so making that entire module unconditional | ||
| would pull in its world dependency. Confirm the default build, | ||
| `--no-default-features --features world`, and `--no-default-features` builds | ||
| in Phase 1. | ||
|
|
||
| The current source audit's starting population is broader than plain-row | ||
| renderers and is **not pre-dispositioned**: display/chat sanitizers | ||
| (`pkgs/id/src/world/util.rs:69-84`); names/descriptions, mail subjects, record | ||
| keys, request IDs, paste text, document names, and terminal text | ||
| (`pkgs/id/src/directory.rs:1846-1870`, `pkgs/id/src/directory_mail.rs:149-160`, | ||
| `pkgs/id/src/world/mod.rs:845-858`, `pkgs/id/src/world_caps.rs:265-280`, | ||
| `pkgs/id/src/world_session/mod.rs:2093-2102`, | ||
| `pkgs/id/src/world_ssh.rs:1475-1481,1773-1780`); presentation-row graphemes and | ||
| cell-width checks (`pkgs/id/src/world_presentation.rs:322-326,538-543`); and | ||
| link-destination parsing (`pkgs/id/src/web/markdown.rs:1568-1579`). The audit | ||
| must decide per contract whether each site should escape, strip, refuse Cf, or | ||
| remain deliberately local. The presentation cell-width mechanism is separate | ||
| from the Cf/plain-row contract and should not be replaced by it. | ||
|
|
||
| The latest recorded issue decision is to use that existing petname set as the | ||
| shared set, escape at row renderers rather than strip, and treat printing—not | ||
| new ingest validation—as the total gate for peer/host-provided values. Current | ||
| source and merge history refine two details in the earlier audit: | ||
| `is_format_char` was made `pub(crate)` for invite validation by | ||
| [commit `0f31e2b`](https://github.com/developing-today/code/commit/0f31e2bf2eac3dbec5183ce40d0d7febf9797908), | ||
| but remains inside the world-gated module; and [PR #3718](https://github.com/developing-today/code/pull/3718) | ||
| has already landed the world-list structural fix and closed #3089. Phase 1 | ||
| therefore relocates the existing predicate to an | ||
| unconditional shared module rather than creating/promoting the set, and Phase | ||
| 3a is recorded as complete. Phase 3b remains the closing inventory (#3456). | ||
|
|
||
| ## 2. Viable options | ||
|
|
||
| | Option | Meaning | Benefits | Costs / risks | | ||
| | --- | --- | --- | --- | | ||
| | **A. Shared set, per-surface disposition (recommended)** | Move the existing predicate to an unconditional crate-private module; escape at row renderers, strip in sanitizers where appropriate, and refuse at validators where their contract requires it. | One definition prevents renderer-specific drift and works in builds with and without `world`; preserves distinct `plain_field` and `key=value` formats; keeps row values recoverable and output safety independent of input source. | A small ownership/import change is needed; escaping can make join-control-containing names less natural to read. Each non-row surface still needs an explicit, evidence-based disposition. | | ||
| | **B. Local fixes at each filed renderer** | Add a Cf check separately to `plain_field`, `group::text()`, and world listing. | Small local patches; minimal module changes. | Repeats the pattern that created the family; new sites can miss the character set or use inconsistent subsets. It also leaves the existing feature boundary awkward for unconditional renderers. | | ||
| | **C. One unified renderer for every plain surface** | Replace the existing renderer-specific formatters with one general renderer. | Could centralize more formatting behavior. | The surfaces have intentionally different delimiters and quoting triggers. A renderer rewrite is broader than the character-set contract and risks changing ordinary output unnecessarily. | | ||
| | **D. Strip at render time or reject at ingest** | Remove Cf before display, or make input validation the principal defense. | Stripping is simple to reason about at a display boundary; validation can reduce accepted values. | Stripping makes distinct stored values print identically and loses the full printed value; ingest cannot repair already stored values or non-conforming hosts, and rejecting remote signed claims is a federation policy change. Neither replaces a total output boundary. | | ||
|
|
||
| ## 3. Recommended contract | ||
|
|
||
| > A plain-text field is row-safe only when it contains no structure character | ||
| > (Cc controls and U+2028/U+2029) or format character (Cf) that can alter how | ||
| > the terminal presents the row. Every plain renderer accounts for both | ||
| > classes. The disposition follows the surface: row renderers escape, stripping | ||
| > sanitizers strip, and validators refuse. The full Cf set has one shared | ||
| > definition. Any surface-specific exception must be explicit and must not | ||
| > copy or re-derive Unicode ranges at the call site. | ||
|
|
||
| Apply the contract without collapsing the existing renderer boundaries: | ||
|
|
||
| 1. Move the existing Cf classification to one unconditional, crate-private | ||
| module (recommended name: `unicode.rs`), retaining its Unicode 16 ranges. | ||
| Update petname and invite to call the shared helper, then use it in both | ||
| renderers. Do not make the whole `petname` module unconditional: it depends | ||
| on world-gated directory code (`pkgs/id/src/petname.rs:15`, | ||
| `pkgs/id/src/lib.rs:166-167`). Do not copy or introduce a renderer-specific | ||
| bidi-only set. | ||
| 2. In `plain_field`, treat Cf as a reason to use the existing quoted/escaped | ||
| representation. This preserves the value in printable form rather than | ||
| deleting it. | ||
| 3. In `group::text()`, include Cf in the quoting trigger and explicitly escape | ||
| Cf in the quoted path; JSON string serialization alone does not escape these | ||
| format characters. Keep its `key=value` quoting semantics distinct from | ||
| TSV-style `plain_field`. | ||
| 4. Route world-list names through the row-safe renderer while keeping | ||
| comparisons/marker decisions against the original name, not the rendered | ||
| spelling. | ||
| 5. Do not add new input rejection as the primary fix. A later defense-in-depth | ||
| ingest policy requires its own compatibility/federation evidence. | ||
| 6. Keep `--json` unchanged. Ordinary printable values should remain | ||
| byte-identical on plain output. | ||
|
|
||
| The shared set deliberately includes zero-width and join-control characters | ||
| such as U+200B–U+200D, U+FEFF, U+00AD, and U+2060, not only bidi overrides and | ||
| isolates. This is the recorded trade-off: a ZWJ/ZWNJ-containing name may render | ||
| with visible escapes in row output, but its original bytes remain represented | ||
| and the decision can be reversed centrally if real-name evidence warrants it. | ||
|
|
||
| ## 4. Invariants and implementation acceptance criteria | ||
|
|
||
| Implementation is accepted when all of the following hold: | ||
|
|
||
| - [ ] There is one shared Cf definition based on the existing Unicode 16 | ||
| petname set in an unconditional crate-private module; petname, invite, | ||
| and renderers call it rather than maintaining local subsets. | ||
| - [ ] Default, `--no-default-features --features world`, and | ||
| `--no-default-features` builds compile. In particular, the unconditional | ||
| invite module no longer names a helper absent when `world` is disabled. | ||
| - [ ] `plain_field` does not emit Cf raw in either quoted or unquoted values; | ||
| a value containing Cf uses the renderer's established escaped form. | ||
| - [ ] `group::text()` handles Cf in both unquoted and quoted paths. Its quoted | ||
| path explicitly escapes Cf rather than relying on `serde_json` to do so. | ||
| - [ ] The world-list plain branch continues to use `plain_field`; it cannot | ||
| let a supplied name create/visually reorder rows or columns after Cf is | ||
| handled, and matching/marker logic still uses the raw name. Existing | ||
| newline/tab coverage remains passing. | ||
| - [ ] Representative tests cover bidi overrides/isolates (including U+202E), | ||
| zero-width/join controls, and ordinary whitespace/control cases in each | ||
| renderer's distinct format. | ||
| - [ ] Ordinary printable output remains byte-identical; `--json` output is | ||
| unchanged; no new peer, host-name, or claim ingest validation is added | ||
| under this design. | ||
| - [ ] The `text.rs` module documentation states the two character classes, | ||
| the disposition-by-surface rule, the shared set's home, and Unicode | ||
| version. The #3456 closing inventory refreshes the grep basis against | ||
| current source and records each remaining control-only site as escape, | ||
| strip, refuse, deliberately local (with reason), or a linked follow-up. | ||
|
|
||
| ## 5. Phased implementation plan | ||
|
|
||
| Each implementation step is a separate reviewable/mergeable PR. The phase | ||
| numbers and dependencies follow the latest #3455 issue record; Phase 3a is | ||
| already closed, and Phase 3b is not gated on it. | ||
|
|
||
| 1. **Phase 1 — feature-independent set and `plain_field` (#2839).** Move the | ||
| existing Unicode 16 Cf predicate into an unconditional crate-private module | ||
| (recommended `src/unicode.rs`); update petname and invite to use it; wire | ||
| `plain_field` to it; update the nearby `text.rs` contract and add focused | ||
| tests. Check default, world-only, and world-disabled builds. **Depends on:** | ||
| none. **Done when:** peer values containing Cf are escaped, ordinary output | ||
| is unchanged, and all three feature configurations compile. | ||
| 2. **Phase 2 — `key=value` renderer (#3111).** Reuse the shared set in | ||
| `group::text()`, including explicit Cf escaping after/beside its quoted JSON | ||
| string construction; cover both quoted and unquoted paths with tests. | ||
| **Depends on:** Phase 1 for the shared definition only. **Done when:** claim, | ||
| group, and document values cannot present Cf raw in either path. | ||
| 3. **Phase 3a — world-list plain output (#3089; closed, already landed).** | ||
| Preserve the landed `world_list_plain_row` behavior: compare the raw name, | ||
| then render through `plain_field`. This independently mergeable step covers | ||
| structural newline/tab handling; Cf escaping follows Phase 1. No new PR is | ||
| needed for 3a. **Depends on:** none for the structural-character fix. | ||
| **Done when:** satisfied by the current implementation and its row-safety | ||
| tests; #3089 is closed. | ||
| 4. **Phase 3b — closing inventory and contract (#3456).** After Phases 1–2, | ||
| refresh the control-only-site inventory against current source. Expected | ||
| starting dispositions are: strip Cf from `sanitize_display_name`; decide | ||
| `sanitize_chat` from its downstream rendering (with the issue's bidi-only | ||
| fallback if full-Cf stripping corrupts legitimate joined text); and refuse | ||
| Cf at validators or document why a protocol/payload site is deliberately | ||
| local. Treat presentation grapheme/cell-width rules as separate mechanisms. | ||
| Write the final contract/set home/version into the `text.rs` module doc. Fix | ||
| sites in this phase or link named follow-up issues for remaining required | ||
| work. **Depends on:** Phases 1–2; not Phase 3a. **Done when:** the complete | ||
| grep basis and site-by-site disposition/evidence are posted on #3455 and | ||
| every required fix is landed or tracked. | ||
|
|
||
| ## 6. Open implementation questions and non-goals | ||
|
|
||
| These do not block the chosen renderer contract and do not require a Drew | ||
| decision for the filed phases: | ||
|
|
||
| - **`sanitize_chat` disposition:** decide from its downstream rendering | ||
| contract whether stripping all Cf would corrupt legitimate ZWJ/ZWNJ chat | ||
| text. If so, #3456 records the fallback of stripping the bidi subset with a | ||
| stated reason. This is a source-usage check, not a reason to redefine the | ||
| shared set. | ||
| - **Ingest-side defense in depth:** the recommendation remains no new | ||
| validation in these phases. Reconsider only with compatibility/federation | ||
| evidence and a separately recorded policy decision; output sanitization | ||
| remains necessary either way. | ||
| - **Set placement:** resolved in this design: the predicate needs to be | ||
| unconditional because renderers compile without `world`, while `petname` | ||
| does not. The recommended `unicode.rs` module is only a placement name; keep | ||
| the single range definition and all existing semantics. | ||
| - **ANSI/OSC terminal sequences:** no filed instance is established by #3455; | ||
| do not expand this Cf/structure-character design into a general terminal | ||
| escape-sequence policy without a separate decision and evidence. | ||
|
|
||
| There are **no Drew questions** for this design: the issue's latest recorded | ||
| decision already selects the shared set, surface-specific escaping, and no new | ||
| ingest validation as the primary fix. The remaining items above have a | ||
| recommended default and can be resolved during the implementation audit. | ||
|
|
||
| ## References | ||
|
|
||
| - [Issue #3455](https://github.com/developing-today/code/issues/3455): current | ||
| contract, recommendation, and phase relationships. | ||
| - [Phase 1 #2839](https://github.com/developing-today/code/issues/2839), | ||
| [Phase 2 #3111](https://github.com/developing-today/code/issues/3111), | ||
| [Phase 3a #3089](https://github.com/developing-today/code/issues/3089), and | ||
| [Phase 3b #3456](https://github.com/developing-today/code/issues/3456): filed | ||
| probes, current status, dependencies, and closing inventory criteria. | ||
| - [Commit `0f31e2b`](https://github.com/developing-today/code/commit/0f31e2bf2eac3dbec5183ce40d0d7febf9797908) | ||
| records the existing helper's crate visibility; [PR #3718](https://github.com/developing-today/code/pull/3718) | ||
| records the already-landed Phase 3a world-list change. | ||
| - Current code evidence cited inline from `pkgs/id/src` at this checkout; | ||
| source claims above are intentionally limited to those cited paths and lines. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For supplementary-plane Cf characters such as U+110BD and U+E0001, extending
plain_fieldto use its existing escape branch would silently corrupt the represented value. That branch inpkgs/id/src/commands/text.rsuseswrite!(rendered, "\\u{:04x}", u32::from(c)), so U+110BD becomes\u110bd, which a JSON parser reads as U+110B followed byd, rather than the original character. The shared set includes these characters, but the proposed test criteria cover only BMP examples. Explicitly require surrogate-pair escaping and supplementary-plane JSON round-trip tests rather than prescribing the existing escaped form unchanged.Useful? React with 👍 / 👎.