Language module Phase 3 — first learner-visible slice — implementation plan
Companion to ADR-0058 (event lane + projector), ADR-0059 (lexeme catalog + dictionary
delivery), ADR-0060 (pursuits), ADR-0050 (surface layout), ADR-0056 (personal
offerings), ADR-0061 (import/content) and
Language Module Migration V1 (Phase plan →
Phase 3). Phase 2 is complete (2a-1…2a-5, 2b-1/2, 2c-1/2). Phase 3 turns that foundation into
the first learner-visible surfaces: the enriched-text renderer + TokenDetails, the dictionary,
paste-enrichment, bulk self-grading, list import, and the first stats widgets. Everything ported
keeps the predecessor’s learner-model vocabulary (transcrobes CONTEXT.md; its ADR-0003 facts +
policies, ADR-0004 no predictive aid withholding) under emergent’s platform rules.
Status: landed 2026-09-07 — every slice except the parked 3c-4 is on develop (ratified the
same day: R1–R10, with R1’s Listrobes sentence clarified, R6 amended to keep the Inferno renderer,
R2 keyed by lexeme, R5a on is-child-of with plain-text list files, R7 on @mantine/charts; R5c
parked with Phase 5). The two pgxsinkit seams the phase needed (rawTransaction, onPoll) were
built upstream the same day and consumed on 2026-09-08: the personal-dictionary upload UI and the
consumer host’s poll-observed liveness closed the phase.
Grounding (verified 2026-08-26)
Section titled “Grounding (verified 2026-08-26)”- The event lane is server-side only.
authoritativeSyncRegistryis the one registry withstreams(lang_token_encounter,lang_aid_interaction,lang_reading_span;packages/db/src/schema/lang-event-streams.ts);learnerSyncRegistryis the bare-map form and carries none. Nothing inapps/learner-weborpackages/offline-datacallsappendEvent. The consumer hostapps/api/src/lang-event-consumer.tsexists and has no Deployment ininfra/— both recorded in that file as Phase-3 work. pgxsinkit’s client half is complete (client.appendEvent/onOutboxStatus/onEventLaneReport, worker-mode included). - Per-word state is projector-only. Superseded by the offline plan R1/R2/R6 (2026-09-12): the
verdict is computed from the CLIENT-written
lang_word_state, and the policy table is gone.lang_node_factandlang_node_policy_output(packages/db/src/schema/lang-node-operational.ts) arereadonlywith SELECT-only RLS. Policy v1 (packages/db/src/lang-projector/policies.ts): independence = three unaided encounters and no aid asked for since;srs_eligibledeliberately absent; learner declarations deliberately absent — the file records that they “arrive as their own owner-writable table with the Phase-3 surfaces that produce them”. The only client-writable module row islang_source_preference. - Dictionary delivery is complete and unwired. Routes
/workflow/lang-dictionary-definitions,/workflow/lang-lexeme-lookups,/workflow/lang-dictionaries,/workflow/lang-personal-dictionaries[/:id]; the clientcreateDefinitionCacheManager+resolveResolutionIndex(packages/offline-data/src/definition-cache.ts,resolution-index.ts) with zero learner-web consumers; prefetch policiesbase-list/list-membershipare recorded seams. Provider content is opaque (CedictEntryContent) — no presentation contract exists.lang_source_preferenceprecedence is a column comment, not code. - Enrichment.
enrichText(packages/db/src/lang-enrichment/pipeline.ts) has no caller outsideenrichDocument; the only route is the operator re-run. The pipeline provisions the per-token best guess (bg) and phones (p) — the predecessor’s current TS path does not. Model schema:packages/domain/src/enriched-content.ts(zod, terse keys, lexeme uuids inid/oids). Text sources: plain text only (epub/pdf are Phase 4). Characterization gatebun run test:lang-enrichmentis byte-for-byte over the predecessor’s captured output. - Learner app. No language feature; nothing writes
person_subject_pursuit, so no language shape ever activates; experience screens supply only{ deliveryMode, structure }(features/experience/components/ExperienceScreenView.tsx), soword-card,streakandlevel-badgenever render; the widget catalog is a closed union (packages/domain/src/surface-layout.ts); viewport hosts dispatch oncontent.kind. - Lists. No list entity exists. A curated set is a node plus
competency_associationrows (is-part-of;sequence_numberexists).ingestNodeInventory(packages/db/src/competency-merge/ingest.ts, withmembership) has no caller. The goal referentlang.v1:word-list:<uuid>is a documented example only. The inventory shape carriesnodeKey+ tier, no title and no rank; the lexeme catalog carries no frequency. - Predecessor (transcrobes) — what is being ported. Product code lives in
packages/wlib. Renderer: Inferno (components/content/etf/Entry.ts,EnrichedTextFragment.ts) — the port’s one framework hazard. TokenDetails/Mouseover: React + MUI (components/content/td/*). Policies:packages/lib/src/learnerPolicies.ts(aidsOff,countsAsKnown,srsEligible,practiceOutcome: success ⇔ grade > unknown). Fact rowwordstate={ excluded, first_revision_date, first_success_date }. Listrobes: click-to-cycle, save per page, HARD-first order, basic two-grade mode below 500 graded, hover-to-peek. Textcrobes:html-to-jsonon every keystroke, 30 000-char cap. List import: importfile + userlist withword_knowledge— import-as-known runs throughpracticeOutcome, sounknownnever sets a success date (the load-bearing behaviour). Stats: known count viacountsAsKnownWhere, list coverage,userdaytallies, first-success cumulative chart; no streaks, no due-cards on home. Not to port: Listrobes emits no grade interaction events; keystroke re-enrichment; document-leveli/vhotkeys; the retiredussynonym field.
Rulings requested (ratify before slicing starts)
Section titled “Rulings requested (ratify before slicing starts)”R1 — Grades are events, on one stream. Bring lang_review_grade forward from Phase 5 as the
shared four-grade vocabulary (unknown | hard | good | known, the predecessor’s
“don’t know / know poorly / know well / know completely”) with source ∈ { content, dictionary, list, list-import }; Phase 5 adds review plus the card reference. The fold adds to
lang_node_fact: grade_count, success_count, first_graded_at, first_success_at,
last_graded_at (success ⇔ grade > unknown — practiceOutcome ported). Policy v2: independence
= first_success_at set or the v1 encounter rule; LANG_MODULE_POLICY_VERSION → 2 with a
policy-only replay. ADR-0004 holds: a later unknown never restores aids (first_success_at is
monotone). The predecessor writes learner state and research events separately, and Listrobes
writes only the state (practiceOutcome → word_knowledge), so bulk grades never reach the
research log. Here a grade has no state-write path at all: the only way any surface records one
is lang_review_grade on the outbox, and the fold derives the facts from the archive. The bulk
self-grading surface (3c-2) therefore cannot reproduce that gap.
R2 — excluded is the one declaration, as a table plus its event. Owner-readwrite
lang_node_declaration (person, lexeme, excluded, audit; background-eager; owner RLS twin;
erasure cascade-by-person) — the ruling lang-node-operational.ts records, amended at ratification
to key by lexeme rather than node: only the projector assigns a lexeme its node, lazily on the
first fact, so a node-keyed row could never be written for a word the learner has not met (the
bulk-grading and list-exclusion cases); the projector resolves lexeme → node at recompute, minting
as it does for facts, and a node is excluded when any of its lexemes is — mirrored by a
lang_declaration event (exclude | unexclude) written in the same client action, so the archive
holds the speech act and the projector recomputes the key (the fold reads the row; the payload is
the fallback when the row lags the event — order-independent either way). Policy v2:
aids_off = independent || excluded; counts_as_known = independent && !excluded; new column
srs_eligible = !excluded. The client composes excluded locally through the overlay:
offline-immediate, and it dominates every policy (CONTEXT.md).
Superseded by the offline plan R1/R2 (2026-09-12): the table is lang_word_state, carrying
first_success_at beside excluded, and policy v3 drops the encounter route.
Rejected: client-authored first_* dates (the predecessor’s wordstate). They would need a
server-side min-merge the apply function has no strategy for, and the grade stream already carries
the fact. Aids-off after a grade therefore arrives with the sync round trip — the posture ADR-0058
decision 12 already accepts.
R3 — Paste-enrichment is a stateless learner endpoint. POST /workflow/lang-enrichments
{ languageTag, glossLanguageTag, text } (text ≤ 30 000 characters, one in-flight request per
person, 429 otherwise) → enrichDocument({ provenance: "personal", withGlosses: true }) (the
DOCUMENT layer — enrichText enriches one block and produces no markup) → { markup, content }.
No Content row, no artifact, nothing persisted. The bounded input and the per-person concurrency
are the recorded answer to the request-path gate at import-service.ts:203 — that gate is about
book-sized imports; a bounded paste is not one.
Client side: an explicit action with a debounce, never per keystroke. Pasted text has no immutable
artefact, so its encounters carry no contentRef/position and no reading span is captured (the
predecessor’s extension rule). Saving pasted text as personal Content is Phase 4’s personal
channel (it needs a text Content kind and the reader).
R4 — A presentation contract for dictionary content, and the preference resolver now.
packages/domain/src/lang-dictionary-presentation.ts: DictionaryEntryPresentation
{ headword, readings[], senses[{ pos?, glosses[] }], sourceLabel } with pure per-provider
adapters (CEDICT first) beside it — pure so the client renders from its cache without a round
trip. The lang_source_preference precedence resolver
((activity, content) > (activity, ∅) > (∅, content) > (∅, ∅)) is a pure client function landing
in Phase 3, not Phase 4: the popup consults sources per lookup from 3b-2 on.
R5 — Lists. (a) Curated lists are list nodes: node_key = "list:<slug>" in the language’s
framework, members via competency_association(from = word node, to = list node, is-child-of, sequence_number = rank) — is-child-of, the ingest default (CASE’s isChildOf: “belongs under”,
the type the schema’s own trees use and the one that round-trips through CASE export; amended
from is-part-of at ratification), titles from the node revision. ingestNodeInventory gains a per-entry
ordinal on membership. Two new per-language lazy read projections with public constant
predicates (the inventory precedent): lang_list_<lang> (list nodes: id, node key, title) and
lang_list_membership_<lang> (from, to, sequence). An operator script imports the launch lists
for zh (HSK 1–6 and the frequency top-10k, which is the base-list prefetch policy’s list)
from plain UTF-8 files, one graph per line, rank by line order, one file per list — emergent holds
no list data and the predecessor’s seed dumps carry only legacy word ids nothing here can bridge,
so the operator exports the files once from the transcrobes database (ruling 2026-09-07). Amended
2026-09-16: a tab-separated line contributes its FIRST cell as the graph, so the hskhsk.com “HSK
Official With Definitions 2012” files — which carry their definitions on the line — import as they
are.
(b) Personal lists are a module table, lang_person_list (owner-readwrite; title,
language_tag, ordered lexeme_ids uuid[] — the lang_source_preference precedent) — never
nodes or associations in the shared framework (ADR-0059’s publication amendment; ADR-0056).
Import = client-side parse (one term per line / first CSV column) → resolution index →
/workflow/lang-lexeme-lookups for never-seen forms (unpublished lexemes, on the own-index
shape) → one row. The predecessor’s word_knowledge import option becomes one
lang_review_grade { source: "list-import" } per word under R1’s semantics. The goal referent
lang.v1:word-list:<id> resolves to a curated list node or a personal list row (Phase 5
consumes it). (c) Upward aggregation into list-level person_competency_state (ADR-0058
decision 5’s Phase-3 seam): the client computes coverage locally for every widget in this phase;
the server-side aggregation is slice 3c-4 — recommendation: park it with Phase 5, whose goal
progress is its only consumer.
R6 — The renderer stays Inferno; its store is replaced at the source. etf/Entry.ts and
EnrichedTextFragment.ts port near-intact into packages/ui/src/lang/enriched-text/ (Inferno
and React coexist there as they do in packages/wlib). The predecessor’s redux-like global
context is what makes cross-object updates cheap — marking a word known clears its gloss on every
occurrence in the chapter, and a gloss-mode change re-renders every token — and a framework-free
rewrite was considered and rejected for exactly that reason. What changes is the store’s feed,
not its shape: a live subscription over the synced verdict rows (lang_node_policy_output ⨝
lang_node_declaration — superseded by the offline plan R1/R2/R6: one query over lang_word_state) plus the learner’s gloss-mode setting hands the renderer the same
lexeme→verdict map it reads today. Phase 4’s sandboxed frame and Phase 8’s extension reuse the
module as transcrobes already does in both contexts. TokenDetails, Mouseover and the dictionary
are React + Mantine in
packages/ui/src/lang/ with data ports and no router/env imports — these are the component
boundaries backlog 0009 freezes. Gloss modes become a named enum
(none | l2-simplified | sounds | l1 | sounds-l1) replacing the sparse magic numbers; the event
schemas are unchanged (aidShown boolean on encounters, the aid kind on interactions).
R7 — Stats v1 and the surface. A projector output lang_day_fact (person, UTC day,
encounters, lookups, grades, successes; owner-read, background-eager) is the day-tally substrate
(userday ported into the fold — progress_snapshot, named in the migration plan, is an
offering-scoped qualification artifact and not this). Widgets on the ordinary route /lang:
known count, words met, curated-list coverage, day activity, and a getting-started prompt below
500 graded. Streak = consecutive active days derived client-side from lang_day_fact, feeding
LearnerFacet.streakDays; level-badge stays dark (no level construct before Phase 5). Charts
use @mantine/charts (ruling 2026-09-07; emergent carried no chart library). Surface
work: the learner app assembles a learner facet from module data on experience screens; one new
widget lang-progress (a domain catalog edit — the catalog is closed by design, and “a pack
registers its widgets” pluggability is recorded as not-v1); and a layout document for the
personal-offering look-alike home that composes the shell (tools grid + stats) while the routes
stay primary.
R8 — Pursuit UI. The module home offers LAUNCH_LANGUAGES (zh); choosing one writes a
person_subject_pursuit row on the sync rail (subject id pinned); activation is
client.ensureSynced(launchLanguageRegistryKeys(language)) on the ensureCatDelivery pattern —
registry keys, not shape names, because ensureSynced names client registry entries
(lexiconNodeInventoryZh) while launchLanguageShapeNames names server shapes
(lexicon_node_inventory_zh), and passing the latter activates nothing at all, silently; ending the
pursuit deactivates (desync per key, in reverse activation order). Nothing server-side gates
activation (ADR-0060 decision 4).
R9 — Consumer Deployment. lang-event-consumer as a chart worker mirroring caliper-worker
(args: [/apps/api/src/lang-event-consumer.ts]), dev values only, ~10 lines under ADR-0054.
Values land in the repo; applying is Anton’s (cluster is never touched from a session).
R10 — Which import UIs are Phase 3. List import (R5b) and dictionary import (personal upload in the learner app; org-licensed upload in the admin console with a generic headword/gloss CSV parser) are Phase 3. The personal document import UI moves with the reader to Phase 4 — without a reader an imported document has no learner surface — superseding the Phase-2 plan’s “learner/org-admin import UI is Phase 3” wording for documents.
Slices
Section titled “Slices”Every slice: implementer → coordinator diff review → adversarial reviewer on
destructive/privacy surfaces → full gates → commit. Schema work follows the migrations
runbook; every person-linked table registers erasure, row filters and RLS twins; every sync entry
declares its tier and read-contract assertion; every enrichment touch keeps
test:lang-enrichment byte-identical; every key lands in en and zh-Hans; UI copy uses the
neutral vocabulary (the tools are “Dictionary”, “Paste text”, “Grade words”, “Lists” — never the
predecessor’s brand names).
Workstream 3a — the event lane reaches the client
Section titled “Workstream 3a — the event lane reaches the client”3a-1 — client outbox wiring. learnerSyncRegistry moves to the { tables, streams } form
(streams stay out of the fingerprint, so no client read cache is wiped). Learner sync boot passes
the event-lane options (flush URL = the mutations endpoint’s sibling via deriveBatchEventUrl,
batch size, backoff), an onEventLaneReport warn log, and onOutboxStatus into the sync monitor;
consent/claims gating hooks per ADR-0058 decision 1. Integration lane: client appendEvent →
POST /api/events → queue → consumeEventBatch → lang_node_fact on the rail (extend
lang-event-lane.integration.test.ts or a new lang-client-outbox-cycle). Read-contract
assertions unchanged.
3a-2 — consumer Deployment (R9). Dev chart values + a runbook line. Anton applies.
3a-3 — grades and declarations (R1, R2). lang_review_grade v1 and lang_declaration
streams (strict zod, anonymization projections, indefinite retention, archive tables);
lang_node_fact grade columns; lang_node_declaration (RLS owner twin, erasure, tier,
read-contract, migration regen); lang_node_policy_output.srs_eligible (retired by the offline plan
R6); policy v2 + version bump +
policy-only replay path exercised; fold/consume/replay/policies tests; integration: a grade cycle
through the outbox, and an exclude/unexclude round trip proving the row and the event converge in
both orders.
Workstream 3b — module client foundation and reading surfaces
Section titled “Workstream 3b — module client foundation and reading surfaces”3b-1 — foundation. apps/learner-web/src/features/lang/; pursuit picker + ensureLanguageShapes
(R8); the definition-cache manager instantiated at boot for pursued languages;
resolveResolutionIndex as the only resolution door; /lang route shell + nav entry; i18n roots
learnerWeb.lang.*.
3b-2 — dictionary and TokenDetails. Presentation contract + CEDICT adapter + preference
resolver (R4). Dictionary page (/lang/dictionary?q=): live search over the local index with the
ported guards (script check, per-language max query length), “search online” through
lookup-or-mint, personal dictionary upload (R10). TokenDetails (header: sound, best guess,
dictionary link, exclude toggle; the four grade buttons; definitions per source in preference
order; substrings for zh) and Mouseover — hotkeys scoped to the open popup. Events:
lang_aid_interaction { aid: "definition", requested: true } on open; grade →
lang_review_grade { source: "dictionary" }; exclude → row + lang_declaration.
3b-3 — enriched-text renderer (R6). Superseded by the offline plan R1/R2 (2026-09-12): the
verdict feed is one live query over lang_word_state, with no join. Inferno port of etf/:
model-level formatting expansion,
doesNeedGloss over local verdicts (lang_node_policy_output ⨝ lang_node_declaration),
best-guess/unsure marking, tone colouring (zh), de flag, the narrow-screen popup rule; the
global-context store fed by a live subscription over those rows. Grounding task before the port:
record how transcrobes populates the store today so the subscription reproduces the same
whole-chapter update semantics on one grade. Encounter capture: on-screen ≥ N s via an IntersectionObserver →
lang_token_encounter { aidShown } batched per fragment; Mouseover dwell →
lang_aid_interaction { aid: "gloss", requested: false }. Aid preference (gloss mode, position,
font) is content-scoped presentation state held in local preferences in v1 — the synced
reader-config table is a Phase-4 ruling. Component tests run the renderer over fixture models from
the characterization corpus.
3b-4 — paste-enrichment (R3). The endpoint + /lang/paste (textarea, explicit action,
30 000-char cap with a visible counter, progress summary: words / counted-as-known %); rendered
through 3b-3 + 3b-2; definition backfill for the models’ lexeme ids (prefetch policy 4).
3b-5 — org-licensed dictionary import (R10). Admin-console page over a generic
headword/gloss CSV parser through runDictionaryIngest; scope + entitlement as ADR-0059 decision 5.
Workstream 3c — lists and grading
Section titled “Workstream 3c — lists and grading”3c-1 — curated lists (R5a). Membership ordinal in ingestNodeInventory; the list-node
convention; two read projections per language + registry + read-contract; operator import script
for the launch lists; base-list prefetch policy activated for the frequency list.
3c-2 — bulk self-grading. /lang/grade: candidates = curated-list members with no grade and
no encounter fact (never touched), ordered by list rank; page size 50 (1–250); click-to-cycle with
a configurable order (HARD first by default); basic two-grade mode below 500 graded with the
default-grade chooser; hover-to-peek through the 3b-2 presentation. Save → one
lang_review_grade { source: "list" } per word (+ lang_aid_interaction for peeked words).
3c-3 — personal lists (R5b). lang_person_list (RLS, erasure, tier, read-contract,
migration); /lang/lists: create from pasted/uploaded text, resolve → mint, import-as grade
option, coverage per list; the goal-referent resolution helper in packages/domain.
3c-4 — list-level aggregation (R5c). Projector seam, threshold-gated. Parked with Phase 5 at ratification; listed so the seam stays named.
Workstream 3d — stats and surface
Section titled “Workstream 3d — stats and surface”3d-1 — day facts + module home (R7). lang_day_fact fold from all streams (UTC days) +
registry/RLS/erasure/read-contract + migration; /lang home: pursuit, tools grid, stats cards,
getting-started prompt.
3d-2 — surface composition (R7). learner facet assembly on experience screens (streak from
day facts); the lang-progress widget (domain catalog + renderer registry + deny under secure,
like streak); a layout-document fixture for the personal-offering home. Attachment stays an
admin act.
Order and dependencies
Section titled “Order and dependencies”3a-1 → 3a-3 → { 3b-3, 3c-2, 3d-1 }. 3b-1 → 3b-2 → 3b-3 → 3b-4. 3c-1 → 3c-2 → 3c-3 (3c-4 parked). 3d-1 → 3d-2. 3a-2 any time after 3a-1; 3b-5 any time after 3b-2. Suggested lane: 3a-1, 3b-1, 3a-3, 3b-2, 3c-1, 3b-3, 3b-4, 3c-2, 3c-3, 3d-1, 3d-2, 3b-5.
Nothing in Phase 3 needs a pgxsinkit change: the client outbox, the worker-mode appendEvent, and
the { tables, streams } registry form all exist.
Verification baseline (every slice)
Section titled “Verification baseline (every slice)”The Phase-2 baseline (migrations runbook; row-filter/RLS tests executed against PGlite;
erasure-registry test; read-contract assertions; bun run validate + affected suites + the db
coverage lane at commit; no local wrapper over the upstream hooks) plus: test:lang-enrichment
byte-identical on every enrichment touch; the three lang integration lanes green plus the new
outbox and grade cycles; the renderer’s fixture-model component tests.
Recorded deferrals
Section titled “Recorded deferrals”- Reader config as a synced table (the presentation half of aid preference): Phase 4.
- Pasted text saved as personal Content; the personal document import UI: Phase 4.
- Level construct /
level-badge; goals UI and list-level state as its input: Phase 5. reviewsource onlang_review_grade; card retirement (“know completely” → never schedule): Phase 5.- Extension host (backlog 0009): Phase 8, contracts frozen after Phase 5.
- Widget-catalog pluggability for subject packs: not v1; revisit with a second pack.
- Offline model advance (pending-outbox best-guess verdicts): backlog (ADR-0058 decision 12).
- cmi5/xAPI → archive mapping: open question, unchanged.