Repository navigation
feat(meditations): a transcript collection, word list and normaliser - #957
Conversation
A `meditation-transcripts` collection, one row per meditation, holding timed phrases. Lifted from the unmerged `claude/feat-881-meditation-transcripts` branch (PR #882, closed) with the four corrections #952 requires: - `words` is gone from the stored schema. Word timings were 85% of the proposal's bytes and have no consumer — the player reports whole seconds. `z.strictObject` makes them unrepresentable rather than merely unused. - `TRANSCRIPT_PROVIDERS` loses `sample`. A transcript that cannot be produced is a `failed` row with an `error`, never placeholder text wearing a provider's name (#897, success line 13). - `outdated` is a stored column. The mark belongs to the moment the recording is replaced, and the render-time filename comparison it replaces is meaningless across environments, where a preview key prefixes them. - `language` is a `select` over `LOCALES`. The glossary pass keys on it, and free text could hold a code no entry matches — disabling the pass silently. `meditation` stays `unique` and not `required`: a required relationship is NOT NULL, and hard-deleting a meditation nulls this column through its foreign key, which would leave the row unsaveable. The slug is named in `RESTRICTED_COLLECTIONS`. "In no project" means shared, so without the entry the Atlas widget's browser key reads every transcript — what happened to `managers` (#821) and `clients` (#822). The integration case asserts it by reading back through `overrideAccess: false`, with `idOnlySelect()` so a client read is refused by access control rather than by the query-validation gate. The Lemonfox normaliser ships beside the collection, so a live transcription and the import of the existing library can share one. The HTTP client stays with child 2. One line is deleted from the generated migration's `down`: `DROP CONSTRAINT "payload_locked_documents_rels_meditation_transcripts_fk"`, which `DROP TABLE "meditation_transcripts" CASCADE` has already removed two statements earlier. `tests/unit/migration-down-cascade.spec.ts` rejects that generator shape — it aborts the whole batch rollback (#682). Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XC1CTQ5ZA82KL7FsUJHsAV
`glossary.json` is the list — plain data beside the collection, so a change needs a GitHub account and no code review of logic (#897's 2026-10-13 Decision replaced the CMS global #883 proposed). `applyGlossary` is the pure pass, and a collection `beforeChange` hook applies it to every `segments[].text` on write, so the live transcription and the library import both get corrected spellings without either calling it. Three properties make the pass checkable, and each has a spec that goes red when it is removed: - Entries are filtered to the segment's own language first, so one language's spellings never reach another's transcript (success line 8). A language with no entries returns the text byte-identical. - Matching is whole-word, which is what keeps `fontanel` from rewriting inside `fontanelle` — and that is what makes the pass idempotent. - One alternation, longest `heard` first, so no replacement's output feeds another's input and the answer does not depend on row order. The list is seeded from the repo's own `SUBTLE_SYSTEM_NODE_OPTIONS` and the goal's measured-facts table. Two deliberate omissions, both because the match is case-insensitive and a lower-case `written` would rewrite a sentence-initial capital away: - No entry for a word already written lower-case — `chakra`, `nadi`, `bandhan`, `puja`, `vibrations` need no correction, and an entry for each would lowercase every sentence opening with one. - No entry for `void`, the one node label that is also an ordinary English word. Capitalisation and endings only, never transliteration: `Anahat` and `Anahata` are both accepted and both appear, so the list fixes each one's capital rather than choosing between them. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XC1CTQ5ZA82KL7FsUJHsAV
Findings from /simplify's four lenses and /security-review. Behaviour is
unchanged except where noted.
- The int spec's access case built its callers as object literals with
invented ids. A caller the access layer cannot interpret is refused for
the wrong reason, which reads exactly like a working restriction — the
same trap the `select` note already guards. It now uses
`testData.createManager` and `testData.createClient`, and the case was
re-confirmed red with the `RESTRICTED_COLLECTIONS` entry removed.
- `escapeRegExp` was a byte-identical copy of the exported one in
`@/lib/eventQuality/heuristics`, which two specs already import for
unrelated regexes. Import it.
- The word boundary is now `(?<!\p{L})…(?!\p{L})`, not `\b`. JavaScript's
`\b` is ASCII-only, so an entry in a Cyrillic or Greek language would
silently never match — the failure `containsPhrase` documents next door.
The list is English-only today, so nothing changes yet.
- The glossary's per-language pass is built once at module load instead of
memoised lazily. The static import means every language is known then,
which removes the three-state map and the `passFor` indirection.
- The hook returns `data` untouched when no phrase changed, which is every
write in the 18 locales the list has no entry for. It also moves to
`hooks/applyGlossaryToSegments.ts`, matching the ten other collections
that split hooks into a folder.
- `getLocaleOptions()` replaces a third hand-rolled spelling of the same
locale mapping.
- A spread before `.filter().sort()` guarded against a mutation `filter`
already prevents.
- Comments: cut a consumer list that was a moving target, a sentence that
contradicted the schema below it, and four that narrated their own code.
Dismissed, with reasons:
- Delete `TranscriptView`, `TranscriptStatus`, `TranscriptProvider` and
`TRANSCRIPTION_STALL_MS` as unconsumed. #952's `## Interfaces` block
defines them as the contract children 2, 3 and 4 build against, and says
none of it may change without updating them.
- Move `src/lib/meditations/transcript.ts` into the collection folder.
#952 §7 decides this explicitly, counts the consumers, and says to move
it only if the implementation collapses to one importer. It has two.
- Parse `glossary.json` with zod at import instead of casting. A malformed
list would then crash the CMS at boot, and the file is meant to take
edits from non-technical contributors. CI's unit lane refuses a bad edit
before it can merge, which is the cheaper place for that failure.
- Drop the integration validator case as duplicating the unit one. #952 §8
asks for both.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XC1CTQ5ZA82KL7FsUJHsAV
`docs/architecture.md`'s collection list and `tests/COVERAGE.md`'s behaviour map are both read as complete, so a collection absent from either reads as one that does not exist. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XC1CTQ5ZA82KL7FsUJHsAV
|
🚅 Deployed to the SahajCloud-pr-957 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
left a comment
There was a problem hiding this comment.
1 question for the reviewer, one per thread.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
Holistic assessment
This PR is the size of its ticket. Six modules, each placement #952 §7 decides, nothing the ticket did not ask for.
One thing is worth seeing, and it is the ticket's call rather than this PR's: src/lib/meditations/transcript.ts sits in src/lib/ partly because lib-boundary refuses a one-consumer module, two of its three consumers import it for one type alias, and TranscriptView and TRANSCRIPTION_STALL_MS have no consumer until child 4. Children 2–4 earn it. Today it is structure a test rule chose.
The contracts hold. src/payload-types.ts gains two interfaces and one collections key, all additive, and no consumer enumerates collections exhaustively. The restriction is asserted by reading rows back through overrideAccess: false, the only shape that proves anything here.
Findings
should-fix—languageis optional, so the glossary pass can be skipped silently (MeditationTranscripts.ts:63).consider—escapeRegExpreaches a transcripts glossary from an event-quality module (glossary.ts:18).consider— theRESTRICTED_COLLECTIONSdocblock still opens on "personal data or credentials" (projects.ts:186).
What was checked
Read whole: the collection, glossary.{ts,json}, the hook, lemonfox.ts, transcript.ts, projects.ts, all three new specs. The glossary carries all 12 node labels but void, and every row of §5's table. Meditations.locale is required: true, unlike language. On the access case: createManager and createClient both tag collection, so no caller is refused for the wrong reason, and the manager is the one that goes red without the entry. WeMeditateWeb's getDocumentById narrows on its own union; SahajAtlasWeb enumerates nothing. Both preview links answer 200.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
An absent `language` disabled the glossary pass as silently as the unmatchable free-text value correction (d) removed: the hook returns `data` untouched and nothing marks the row. A meditation's own `locale` is required, so every writer has one to pass. Stacked rather than folded into the table's own migration: the branch has already deployed to its Railway preview, where regenerating leaves the columns without a `payload_migrations` row and crash-loops the boot (src/migrations/AGENTS.md). Three existing cases created a row with no language. Left alone, two of them would have been refused for that reason instead of the one under test. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UDgXhmw8WvWNsN3RFehsqD
`meditation-transcripts` is neither personal data nor credentials, so the opening sentence no longer described its own list. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UDgXhmw8WvWNsN3RFehsqD
|
Review round addressed: three threads closed, the glossary question still waits on you.
Gate green: lint, both typechecks, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
@Ardnived could you review this one when you have a moment? CI is green and the bot's review has been addressed. Only an approval is missing. It's the first piece of #897 (meditation transcripts). The next piece, #953, builds the shared Lemonfox connection and can't start until this merges. #941 (intro subtitles for Path Steps, in the International App Admins milestone) plans to reuse that connection, so this PR unblocks both goals. |
`en` covers every `en-*` and `pt` covers `pt-BR`, so a regional entry held for one variant and left its siblings uncorrected. Entries now name 12 base languages, and `applyGlossary` reduces the transcript's locale before it looks up — an `en-AU` transcript takes English's pass rather than none. `BaseLanguage` makes the regional code unrepresentable rather than merely discouraged, derived from `LOCALES` so it cannot drift from it. The reduction is `baseLanguage`, which `buildPayloadLocales` already needed for its ISO label, so there is one spelling of it. Two cases pin the new behaviour and one pins the file: `en-AU` and `pt-BR` correct through their base, and no entry may spell a region. Each was watched red first. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01PZGPtEhcE71EjUFhoxMhnB
Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01PZGPtEhcE71EjUFhoxMhnB
|
Round four: one adopted, one pushed back. Pushed
Three assertions, each watched red first: the two reduction cases, and the file's refusal of a region. Lean gate green, 2402 cases. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Three conflicts, each one both sides adding an entry of their own, so each keeps both. `RESTRICTED_COLLECTIONS` now names six collections: this branch's `event-imports` and main's `meditation-transcripts` (#957). Both reasons stay in the docblock, and the count prose that said "exactly five" and "a sixth" moves to six and a seventh — in `config/projects.ts` and in `docs/rules/access.md`, which states the same set. `src/lib/locales/index.ts` had no textual conflict at the real problem and git merged a file that could not compile: both sides added a `baseLanguage`, with different contracts. Main's is total over `LocaleCode` and typed to `BaseLanguage`, which the glossary needs to key a word list by language. This branch's accepts request-supplied input, where `?locale=all` must not reach a language field. Main's keeps the name and its two callers; the lenient one is `baseLanguageOrDefault` and delegates to it, so there is one split and one validation. Its only caller is the `defaultLanguages` default on `event-imports`. `pnpm generate:types` leaves the merged `src/payload-types.ts` unchanged, so the two generated halves composed correctly. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GChzoT89sR8wGLVoTNoUi7
#957 added a glossary.ts importer of the old heuristics export after this branch was cut, so the merge queue failed typecheck on every attempt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
meditation-transcriptsrow per meditation, holding timed phrases in the same cue shapesubtitlesuses, readable by nobody but an admin.glossary.json, decides Sahaja Yoga spellings, applied by a collection hook so no writer can store an uncorrected one. An entry names the base languages it holds for —encoversen-AU.Nothing transcribes, imports or displays anything yet — children 2, 3 and 4 build on what this defines.
Change outline
Contract — the stored column
New collection, slug
meditation-transcripts, hidden from the admin sidebar. Generated asMeditationTranscriptandTranscriptSegmentsinsrc/payload-types.ts.meditationisuniquebut notrequiredon purpose: Payload makes a required relationshipNOT NULL, and the FK isON DELETE SET NULL, so hard-deleting a meditation would leave the row unsaveable.languageis the opposite case — nothing nulls it, and a meditation's ownlocaleisrequired: true, so every writer has one to pass.Contract — one cue shape, not two
SubtitlesandTranscriptSegmentsdescribed the same thing in two shapes, which review round three settled on one. The cue literal lives insrc/lib/utilities/subtitles.tsand is read in two modes:Closed here is what keeps word timings out. The cost: the cue takes any number where the old schema took
nonnegative(), so the Lemonfox normaliser's clamp is the only guard left on a negative offset, and a case pins it.Contract — four corrections against the reference branch
claude/feat-881-meditation-transcripts(PR #882, closed unmerged) is where the storage came from. Paraphrased, one rule per line:Behaviour — the glossary pass
An entry's
languageis a list of base languages, seeded with the 12 written in Latin script: these are Sanskrit words, so French and Dutch want the spelling English wants. A region is unrepresentable —BaseLanguageis derived fromLOCALES— soenservesen-AUandptservespt-BRrather than one variant being corrected while its sibling takes no pass at all. The six languages written in another script name none, which leaves room for a Cyrillic entry beside the Latin one rather than against it.Six properties, each with a spec that goes red when it is removed: entries are filtered to the languages they name, a regional locale is corrected through its base, a Latin-script transcript is corrected like English, matching is whole-word, the single pass is order-independent, and a capital the heard word already carries survives.
Flow — how a phrase gets corrected
On the hook rather than at each writer, so children 2 and 3 both get corrected spellings without either remembering the call.
Files — where each module lives, and why
The split is #952 §7's:
transcript.tshas two consumers undersrc/so it clearslib-boundary's one-consumer gate, while the glossary's single consumer meanssrc/lib/is not available to it. Nothing lives underseeds/, which the production build does not trace.Preview
The collection is hidden and this PR ships no writer, so there is nothing to open on data — these two links are what a reviewer can confirm.
Data: not seeded.
previewUrl.seedis unset for this repo, and no writer exists until child 2 — the empty list is the expected state, not a failed seed.Migration
Two, applied in order. Neither the cue-shape change nor the base-language one adds a third:
segmentsis ajsonbcolumn, so its shape lives in the Ajv schema and the generated type rather than in the DDL, andglossary.jsonis a committed file the database never sees.src/migrations/20261015_061054_meditation_transcripts.ts— createsmeditation_transcriptsand three enums, addspayload_locked_documents_rels.meditation_transcripts_id. No existing table is touched and no data is transformed. Reversible:downdrops the table, the column and the three enums.src/migrations/20261015_070852_require_transcript_language.ts—ALTER COLUMN "language" SET NOT NULL, from the first review round. Reversible:downdrops the constraint.Why the second one is stacked rather than folded into the first. A migration is applied the moment its branch is pushed, because Railway boots
prodMigrationson every preview — and this branch has deployed. Regenerating the first migration would leave the preview holding its columns with nopayload_migrationsrow naming the replacement, which crash-loops the boot (src/migrations/AGENTS.md, #633). The add-then-change churn is what that file prescribes instead.One line was deleted from the first migration's generated
down:DROP CONSTRAINT "payload_locked_documents_rels_meditation_transcripts_fk", which theDROP TABLE … CASCADEtwo statements above has already removed.tests/unit/migration-down-cascade.spec.tsrejects that generator shape, because it aborts the whole batch rollback (#682). Nothing else is hand-edited in either file.Contract impact
src/payload-types.tsgainsMeditationTranscriptandTranscriptSegments, the latter as{ content, startTimeMs, endTimeMs, durationMs? }[] | null— the same cue the threesubtitlescolumns carry, so a consumer reading both reads one shape.MeditationTranscript['language']is a required closed union rather than an optional one; this push regenerates that, which the round that made the field required did not. The base-language round changes no generated type:languageis still the fullLOCALESunion on the column, andBaseLanguageis internal.contractSyncre-syncs the file to WeMeditateWeb and SahajAtlasWeb in a bot PR after this merges — no consumer work here, and no re-sync child.Test results
pnpm lint,pnpm typecheck,pnpm typecheck:tests,pnpm test:unit(183 files, 2402 cases)meditation-transcripts.int.spec.ts7 passedpnpm generate:typesrun and committed; no migration owed (see above)/security-review: run on the round that touched the collection'shooks/path. No finding — the alternation is still built from a committed file throughescapeRegExp, and the replacement is a function, so a$1in awrittenvalue stays inert. The base-language round touchesglossary.{ts,json},src/lib/locales/, two specs and one doc, none of them asecurityReview.triggerPatternpath, so none was owed.Every new assertion was watched failing before it was kept. This round: the two reduction cases (
applyGlossarykeyed on the raw locale again, both red) and the file's refusal of a region (en-AUput back in one entry, red).Manual verification
Notes for reviewer
encovers everyen-*andptcoverspt-BR, so no entry spells a region andapplyGlossaryreduces the transcript's locale before it looks up. Without that reduction anen-AUtranscript took no pass at all — the silent skip a requiredlanguageexists to prevent, by another route.{text,start,end}is answered on its thread, not built. It would re-split the one cue shape you settled on, and pin the column to a body Lemonfox publishes no schema for. That thread is open for your call.glossary.jsonis the part worth a content owner's eye, especiallyfentanyl → fontanelle, which rewrites a real English word. It is in feat(meditations): a transcript collection, word list and normaliser #952's measured-facts table (1 occurrence against 10 correct spellings), and a meditation transcript is an unlikely place for the drug — but it is the one entry whose cost is not obvious. It applies in the 12 Latin-script base languages rather than one.chakra,nadi,bandhan,pujaandvibrationsare in the list as the vocabulary record, not as corrections. They are inert passes today, and the capital-preserving rule is what makes a lower-casewrittensafe to carry at all.voidis still out: that rule answers an entry that strips a capital, never one that adds one, andvoidis the one subtle-system node label that is also an ordinary English word.RESTRICTED_COLLECTIONSnow holds an entry that is neither personal data nor credentials, and this PR widens its docblock's opening sentence to say so. The rest of that docblock stands: the set still fails open the day a sixth collection in no project is added, and it still records the real fix (invert step 4a) as deferred, not blocked. Not widened here./simplify(four lenses) plus/security-review, notpr-review-toolkit— no routine has that plugin.refactor:commit body. The four: deleting the unconsumedTranscriptViewcluster (feat(meditations): a transcript collection, word list and normaliser #952## Interfacesnames it as children 2–4's contract), movingtranscript.tsinto the collection folder (feat(meditations): a transcript collection, word list and normaliser #952 §7 decides it and counts the consumers), parsingglossary.jsonwith zod at import (a malformed list would crash the CMS at boot; CI refuses the bad edit first), and dropping the integration validator case as duplicating the unit one (feat(meditations): a transcript collection, word list and normaliser #952 §8 asks for both).escapeRegExpreaching this glossary from an event-quality module is refactor(utilities): move escapeRegExp out of the event-quality module #958, because the move touches five files across two unrelated areas.## Interfacesis now out of date in two places — the segment shape, and the glossary entry'slanguage, which is a list of base languages. Children 2–4 read it, so it wants both edits before the next one starts.Detail
Why the normaliser ships in this PR at all. #952 §6 assigns it here, and it is also what gives
src/lib/meditations/transcript.tsits second consumer undersrc/. With only the collection importing it,tests/unit/lib-boundary.spec.tsfails — the check isconsumers.length !== 1, so zero consumers passes and two pass, and exactly one does not.Both word layouts reduce to the same answer. Lemonfox's
verbose_jsoncarries word timings either on each segment (WhisperX) or in one top-level list (OpenAI). Nothing stores them now, so the normaliser reads neither and both layouts produce identical cues. The spec asserts that equality rather than assuming it.baseLanguagelives insrc/lib/locales/, not beside the glossary.buildPayloadLocalesalready split a code to get its ISO 639-1 label, so putting the reduction there leaves one spelling of "the language a locale is a variant of" rather than two.BaseLanguageis a distributive conditional type overLocaleCode, so the set is exactly whatLOCALESreduces to and cannot drift from it.Fixture pre-mortem. The Lemonfox fixtures claim to be that
verbose_jsonbody; verified against the shape the normaliser declares insrc/collections/MeditationTranscripts/lemonfox.ts, whose input is still seconds. The glossary spec assumesglossary.jsonis a flat array whoselanguagelists are base languages —en, neveren-AU— that every entry namesen, and that none namesru; verified againstsrc/lib/locales/index.ts, and the spec's last block asserts the shape rather than trusting it, in both directions.The access case was rewritten mid-review. It first built its callers as object literals with invented ids. A caller the access layer cannot interpret is refused for the wrong reason, which is indistinguishable from a working restriction — the same vacuity the
select/idOnlySelect()note guards against, one level up. It now usestestData.createManagerandtestData.createClient, and the removal of theRESTRICTED_COLLECTIONSentry was re-confirmed to turn it red afterwards.Making
languagerequired rewrote three existing cases, and two of them needed it. They created a row carrying no language. The duplicate-meditationcase and the segment-validator case would then have been refused for the missing language instead of the constraint under test — a pass for the wrong reason, which is the same vacuity as above. Each now passeslanguage: 'en', and the refusal itself has its own case.The word boundary is
(?<!\p{L})…(?!\p{L}), not\b. JavaScript's\bis ASCII-only, so an entry in a Cyrillic or Greek language would silently never match — the failurecontainsPhrasedocuments insrc/lib/eventQuality/heuristics.ts. It is load-bearing the day such an entry is filed, which the entry's language list is what makes possible.The capital rule changes two existing entries' output, and that is the point.
Fontanelnow givesFontanellerather thanfontanelle, andBandhanasgivesBandhans. A sentence opening on a corrected word kept its capital by luck before only wherewrittenalready carried one.Closes #952
🤖 Generated with Claude Code
https://claude.ai/code/session_01PZGPtEhcE71EjUFhoxMhnB