oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1# Native chat Markdown
2
3Branch: `native/markdown`. This includes the 2026-11-23 implementation and the
4review follow-ups to `506fafca` and `5a1fe0d1`. The web's Render and RenderDraft remain the
5contract, including absolute HTTP/HTTPS and mailto links.
6
7## What a person sees
8
9On iPhone and Mac, Paul's complete reply has three paragraphs, a bold
10“Why they look different:” lead-in, and a blue task title which opens the
11native task screen. Lists, emphasis, code spans and hard breaks follow the
12web. Headings have its paragraph treatment and rules have no output. HTML is
13text. Unsupported links keep their words. Relative project links open at the
14account's origin because there is no native project detail screen. Absolute
15web links use the browser; mailto uses the system mail handler.
16
17Draft markers wait, partial links show their words, and unmatched delimiters
18follow RenderDraft. An open fence has its final paste-box layout with Copy
19disabled. Closing it enables Copy without changing its anchor or size. Prompt
20and Text wrap; other code scrolls horizontally in a system monospaced font.
21Copy removes exactly one final newline. Paste boxes have VoiceOver labels.
22
23Replies up to 16 KiB, including small drafts, parse synchronously before the
24first layout. A bounded cache holds trees by account, message ID and revision
25(the exact source plus draft/completed state), so scrolling does not reparse.
26Larger inputs parse on a concurrent executor while the previous revision or a
27multiline plain-text fallback stays visible. A cancelled task cannot publish
28its old result. Mac height changes resize only that reply and shift following
29rows, preserving host identity and scroll position. Mac reply text remains 14 points,
30matching the existing `MacType.line`; iPhone text uses Dynamic Type's body font.
31Deep lists use flat layout rows with indentation capped at four levels.
32
33## Parser choice and parity
34
35Equipo still uses swift-cmark's core CommonMark parser, without GFM extensions
36or smart punctuation, pinned by revision to
37`08ddb528923cc1a6527e02b7a1aee9e516ca749a` in both package files. The core exposes
38list tightness, block buffers and parser transitions needed here. The higher
39level swift-markdown wrapper does not expose all of these. A separate hand
40parser would duplicate the block and reference grammar.
41
42The projection walks iteratively. Inline coordinates are mapped through the
43retained original block buffer and cached line offsets, so continuation
44indentation does not select another span or URL. Unicode classification is
45adapted only in the parser's private buffer; displayed text and destinations
46come from the retained original. Text and link entities have separate decoders
47because the web uses different rules for them. Reference definitions are
48compiled and scanned once per message. Explicit fence transitions, including
49longer-than-255-character fences, determine Copy availability.
50
51`internal/chatmarkdown/native_test.go` projects the actual Render/RenderDraft
52HTML into canonical JSON, only in tests. There are **3,510 checked-in fixtures**,
53plus **32,000 distinct fixed-seed generated inputs** written at check time. The native
54gate gives Swift that same generated file. Every block, inline, target, label
55and Copy state is compared. The corpus includes Paul's full reply, streaming
56cuts, whitespace and lazy continuations, nested formatting, raw HTML, entities,
57Unicode symbols, CRLF and CR-only input, 300-character fences and code spans,
58rejected URL schemes, angle destinations with edge whitespace, EOF labels,
59soft-break whitespace, HTML after paragraphs, reference definitions, and every
60character cut through escaped and open spans.
61
62The one production web change fixes destination entity decoding. A complete,
63known entity decodes once; `&timestamp`, `&region`, and unknown names remain
64literal. This preserves query parameters instead of corrupting them. The
65`golang.org/x/net` test import is now a direct module dependency.
66
67The complete swift-cmark copyright and licence notices remain bundled and are
68now reachable from the Account screen on both platforms, under swift-cmark.
69
70## First review findings and regression evidence
71
72| Finding | Change and regression |
73| --- | --- |
74| P1.1, stack overflow | Iterative projection; 200, 1,000 and 5,000 quotes run on a 1 MB stack. |
75| P1.2, draft regex | Linear marker scanner; 800, 1,600 and 3,200 spaces stay below one second. Large inputs parse off the main actor. |
76| P1.3, continuation ranges | Retained block buffers and cached coordinate mapping; code spans and good/evil URL continuation fixtures. |
77| P2.4, open-fence Copy | Parser transitions distinguish an explicit closer from EOF or leaving a list/quote. Indented false closers remain content. |
78| P2.5, schemes | Fixtures and action tests reject file, ftp, tel, sms, blob, vbscript, custom schemes and protocol-relative URLs. |
79| P2.6, URL rules | ASCII destination trimming and Go-compatible host/userinfo/escape validation. Odd web-allowed hosts remain actionable through validated original targets. |
80| P2.7, web entities | Complete entities only, decoded once; query-name, unknown-name and nested-entity Go tests. |
81| P2.8, list layout | Flat layout with bounded indentation; a 60-level list renders at 390 points within three seconds. |
82| P3, Unicode emphasis | Symbol and whitespace classification matches Goldmark, including emoji, currency, NEL and line separators. |
83| P3, small tree differences | HTML EOF newlines, EOF fence labels, escaped entities, CRLF, code spans and angle destinations are in the goldens. |
84| P3, reference cost | One reference scan and one coordinate map per block; 2,000 references parse within two seconds. |
85| P3, dependency pin | Both package files use the immutable cmark revision. |
86| P3, licence | A source guard keeps the bundled notice reachable from Account. |
87| P3, module tidy | `x/net` is direct; `check-fixtures.py` runs `go mod tidy -diff`, including in the native gate. |
88| P3, accessibility/copy | Paste labels are reused for VoiceOver; the unused coordinator spoken-format key is removed. |
89| P3, Mac typography | A regression fixes the reply font at the previous 14-point size. |
90
91Tests were added before each implementation. The original small-stack test
92crashed. The original marker, reference and layout tests exceeded their bounds
93and were terminated by the harness. The generated corpus exposed additional
94entity and fence-label differences, which were retained and fixed.
95
96Focused commands:
97
98```sh
99EQUIPO_MARKDOWN_DIFFERENTIAL="$PWD/native/build/markdown-differential.json" \
100 swift test --package-path native/apple --filter 'ChatMarkdownTests|MarkdownLayoutTests'
101GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/chatmarkdown -count=1
102native/scripts/check-native.sh
103```
104
105All **28 deliberate mutations were caught**, then restored. This includes
106restoring recursive walking/layout and the backtracking regex, moving parsing
107onto the main actor, breaking source mapping, enabling open-fence Copy, adding
108ftp, loosening URL/userinfo/zone checks, restoring legacy web entities, breaking
109Unicode/CRLF/HTML/EOF/escape handling, restoring per-link reference scanning,
110removing the revision pin/licence/accessibility wiring, restoring the unused
111spoken key, changing Mac text to 13 points, truncating long fence lengths,
112breaking odd-host actions, changing entity-pass order, and trusting a source
113candidate without checking the parser-selected target.
114
115The first review follow-up passed with **zero mismatches across 26,724 trees**. The
1162,000-reference case takes about 0.14 seconds; the 60-level phone-width list
117renders in under 0.5 seconds. The marker scan takes about a millisecond and
1185,000 quotes take under 0.05 seconds on the 1 MB stack. Timings are local Mac
119measurements; the tests enforce wider explicit bounds.
120
121That revision’s full native gate passed: **152 Swift tests** (one existing marked Oficina
122ID issue), 2,724 checked-in trees plus 24,000 distinct generated inputs with
123zero mismatches, 173 strings, 28 web/native copy pairs, reference inventory,
124Mac build and unsigned iOS Simulator build.
125
126Go gates passed with Go 1.26.11 and CGO disabled: all chatmarkdown tests,
127`go vet ./internal/chatmarkdown`, staticcheck v0.7.0 for that package,
128`make fmt-check` with the pinned GOROOT on PATH, and `go mod tidy -diff`.
129The post-commit reference scan and branch CI verdict are recorded in the
130controller handoff.
131Local evidence is under `native/build/logs/review-*` and `mutation-*`.
132
133## Re-review at 5a1fe0d1
134
135| Finding | Fix and regression |
136| --- | --- |
137| P2.1, byte leak and restoration cost | Each physical LF line, including an empty one, maps to its original line. Restoration never searches later blocks. A 3,000-block test checks every copied body and a two-second bound (about 0.2 seconds locally). Every golden and generated tree also checks that introduced control bytes do not leak; legitimate entity-decoded controls must equal the web. |
138| P2.2, blank first frame | Small replies parse before layout. A live host asserts nonzero height immediately. Cache tests verify exact revision reuse, draft/completion identity, previous-tree retention and a nonempty multiline fallback for large replies. The Mac callback resizes the affected row instead of rebuilding the transcript. |
139| P3.1, angle whitespace | Retain the original angle destination even when cmark trims it. Apply the web URL policy to that original, including its fragment rules. |
140| P3.2, EOF labels | The web drops a single byte immediately after the EOF fence, before whitespace trimming; surrounding whitespace and longer labels survive. A 120-case whitespace/label cross-product pins this distinction. |
141| P3.3, soft breaks | Trim trailing spaces and tabs before soft breaks as well as hard breaks. |
142| P3.4, HTML separator | The test-only Go projection removes the formatting newline after a block element. Render/RenderDraft HTML is unchanged. |
143| P3.5, scheme property | The allowed set is exactly http, https and mailto. Property checks apply case variants and generated valid scheme names to opaque, hierarchical and mail-style destinations. Adding webcal fails. |
144| P3.6, draft spans | A parsed delimiter ends the watched fallback backtick span. A backslash escapes one delimiter byte, not its whole run. Cross-product streaming cuts cover quotes, list prefixes, escapes, backticks, emphasis and links. |
145| P3.7, tidy gate | The fixture gate now executes `go mod tidy -diff` with Go 1.26.11 and CGO disabled. Marking the direct x/net import indirect makes that gate fail. |
146
147The deterministic differential corpus now has **32,000 unique sources**, plus
148**3,510 checked-in cases**, with **zero mismatches across all 35,510 trees**.
149CR-only generation also exposed a parser line-count crash, now prevented by
150width-preserving CR adaptation in both block and inline buffers. Long inline
151backtick runs are adapted to cmark’s 80-byte limit while preserving original
152code bytes and coordinates. These cases stay in the corpus.
153
154Tests were added before the fixes. The first-frame test failed with zero
155height; the original byte-restoration test failed both content and time checks;
156the expanded parity run initially failed and crashed on CR-only input. Extra
157escaped-span cuts then caught five more draft mismatches before their fix.
158Commands and outcomes are under `native/build/logs/review2-*`.
159
160All **19 new mutations were caught and restored**. They broke blank-line
161mapping, first-frame content, revision caching, large-input background parsing,
162large-input fallback content and line layout, completion revision identity,
163Mac row resizing, angle whitespace, EOF labels (both length rules), soft-break
164trimming, HTML separators, the scheme allowlist, backtick fallback boundaries,
165escaped delimiter runs, CR-only adaptation, long code spans and module tidiness.
166The harness log records each command, failure and restoration in
167`native/build/logs/review2-mutations.json`.
168
169Final gates passed: **157 Swift tests in 18 suites** (one existing marked
170Oficina ID issue), **35,510 comparisons with zero mismatches**, 173 strings,
17128 web/native copy pairs, the reference inventory, the Mac build and unsigned
172iOS Simulator build. Go tests, vet and staticcheck for chatmarkdown, repository
173fmt-check and module tidy all passed with Go 1.26.11 and CGO disabled.
174The post-commit reference scan and branch CI verdict are in the handoff.
175
176## Visual and platform checks
177
178Layout tests render the screenshot reply, a wrapping prompt, nested lists and
179long scrollable commands at 390 and 760 points. Open and closed code boxes
180have the same measured size and source anchor. A live NSHostingView test
181verifies the first layout already contains content and subsequent revisions report their new height.
182The new captures were inspected: the full task title wraps cleanly, the bold
183lead-in has no delimiter marks, the prompt wraps inside its box, and the long
184command clips horizontally without widening the transcript. Captures are in
185`native/build/markdown-screenshots-review2/`.
186These are Mac renders at phone and desktop widths, not physical iPhone
187screenshots. The native gate builds the unsigned iOS Simulator app.
188
189The existing marked Oficina ID test issue remains outside this change: a
190permission refusal during a Home outage can discard the kit session. No
191signed build, production account, merge, deployment or upload is involved.
192
193## Strings for Luna
194
195No new product strings in this follow-up. The five existing native keys still
196reuse web copy exactly: `chat.paste.copy` (Copy), `chat.paste.copied` (Copied),
197`chat.paste.prompt` (Prompt), `chat.paste.text` (Text), and
198`chat.paste.command` (Command). These also supply paste-box accessibility labels.
199
200Removed the unused native key `message.coordinator_spoken %@ %@` from the
201source strings and both catalogs. The dependency's proper name and verbatim
202copyright/licence text are displayed in its disclosure.
203