Skip to content

feat(server): legacy redirect map and lookup for the wemeditate.com cutover - #276

Open
Ardnived wants to merge 14 commits into
mainfrom
claude/feat-160-legacy-redirect-map
Open

Ardnived wants to merge 14 commits into
mainfrom
claude/feat-160-legacy-redirect-map

Conversation

@Ardnived

@Ardnived Ardnived commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What

The legacy redirect map for the wemeditate.com cutover: where an address on the old Rails site lands on this site. It is data, its generator, a pure lookup function, and the middleware that consults it on a 404.

  • lib/legacy-redirects/lookup.ts: lookupLegacyRedirect(pathname): string | null, over map.generated.json (40 KB). Rules live in core.ts.
  • server/legacy-redirects.ts: a Hono middleware registered before the routes, acting after next(), so only a request this site already refused reaches the map.
  • data/legacy-redirects/: the committed snapshots, README.md (re-export steps), and COVERAGE.md (full report).
  • scripts/legacy-redirects/: export, fetch and generate scripts, run with tsx. No new dependencies.

Preview

Each old address below should answer 301 to the page named, in one hop. curl -sI shows the Location; a browser just lands there.

How the map was generated

  1. legacy-inventory.json: SELECT-only exports from the old database (heroku pg:psql -a wemeditate) of articles, static pages, meditations, techniques, subtle-system nodes, categories, streams, promo pages and friendly_id_slugs. A row is exported only if it was ever published (state 2, 3 or 4), so a draft's address and title never reach the repo. No user tables are read.
  2. legacy-routes.json: the routes: block of each config/locales/<l>.yml in the old app (translated path words), plus its locale list and PUBLISHED_LOCALES.
  3. new-site.json: the 66 pages and 121 meditations SahajCloud production serves, with each page's published languages.
  4. pnpm redirects:generate matches each old record to a new page by English slug, then English slug history, then normalised English title; a non-English record goes through its id to its English row. More than one page matching is reported, never guessed. The generator then looks up every address it enumerated and fails if one does not return its expected target, or if a target is itself redirected.

The map is shape rules (translated section words per language, locale normalisation, unsupported-language fallback) plus 828 exact slugs, not the cross product. build.test.ts fails when map.generated.json or COVERAGE.md is not what the snapshots generate.

A rename agreed upstream but not yet served is a PENDING_SLUG_MOVES entry in build.ts, applied over new-site.json rather than written into it, so the snapshot stays what pnpm redirects:fetch-new-site produces and a re-fetch cannot revert the rename. Page 10 carries the one entry: meditate-now → meditations (#272). An entry whose page moved to a third spelling throws rather than pinning the wrong slug.

Coverage

1,247 old addresses enumerated from the records; 1,240 redirect and 7 are already live pages.

Outcome Addresses
Matching page, in the old address's language 185
Matching page, English (launch language, page not published in it) 115
Matching page, English (language not launching) 155
No matching page, nearest section 390
Fixed routes (own page / nearest section / home) 333 / 20 / 42
Already a live page, no redirect 7

The full per-kind and per-language tables, every section fallback, and every judgement match are in data/legacy-redirects/COVERAGE.md.

Verification

  • All 122 distinct generated targets checked: 48 of the 49 English targets answer 200 on https://wemeditate-web.contact-c66.workers.dev; the 73 non-English targets 404 there today (locale gate closed, as expected) and were instead confirmed published, with a title, in that language by a per-locale SahajCloud read.
  • /meditations is the one target that does not answer yet. It 404s on the deployed site and /meditate-now still 200s, because production has not taken Visitors find a meditation that fits how they feel #272's rename. The map now leads that rename by a deploy, so Visitors find a meditation that fits how they feel #272 ships first or the 263 addresses that now target it land on a 404.
  • 53 reconstructed old addresses checked against live wemeditate.com: 42 answered 200, 10 answered 301 (slug history, events), 1 answered 500 (/uk/about, an error on the old site itself).
  • server/legacy-redirects.test.ts drives the middleware over the committed map: a refused request 301s to its target, a 200 is untouched, an address neither site had stays a 404, the query string survives, and /en/privacy reaches /privacy-notice in one hop.

Not in this PR

  • Catching /meditate-now itself. It is a new-site address the rename retires, not an old Rails one, so no record enumerates it; the map answers null for it.
  • The unpublished-locale 302. A read at a locale a page is not published in still renders 404, not the English page.
  • Opening the locale gate, the language dropdown, and the apex domain binding — the rest of Switch wemeditate.com over to the new site #160's share for this repo.

Part of #160

🤖 Generated with Claude Code

…utover

Add a snapshot of the old Rails site's public URL inventory (SELECT-only
export), the old locale path words, and the pages the new site serves, with
a deterministic generator that builds a compact redirect map from them and a
pure lookupLegacyRedirect over it. The 404-path wiring is a separate change.

Part of #160

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 18, 2026
@sydevs-bot

sydevs-bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🤖 no session running
CI fix 1

recent dispatches
  • 00:11Z address-review · attempt 1 · session · done
  • 00:11Z address-review · attempt 1 · session
  • 17:47Z resolve-conflicts · attempt 1 · session · done
  • 17:47Z resolve-conflicts · attempt 1 · session
  • 22:39Z resolve-conflicts · attempt 1 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 18, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 Adversarial review

This PR matches its ticket. #160's 2026-11-18 decision puts the redirects in the site's own code, and the build plan orders the map and its generator first, built attended from the old database — which is this diff. Most of the 5,503 lines are data and the generator; the lookup is 280 lines. Its verification — 1,247 addresses round-tripped in a test, 122 targets checked live — is stronger evidence than this review could produce, so I went after rent, not correctness.

Findings

  • should-fix core.ts:138 — pageHref restates localePath, which CLAUDE.md makes a repo-wide rule, and LAUNCH_LOCALES is untyped.
  • should-fix map-format.ts:4 — two hand-rolled JSON formatters arrive in one diff.
  • consider lookup.ts:28 — nothing imports the lookup, so none of it runs yet.
  • consider queries.test.ts:13 — the ten SELECTs live twice, with a test policing the copy.
  • consider package.json:22 — four scripts for three once-ever runs.

What was checked

Read whole on the branch: core.ts, lookup.ts, both test files, queries.ts, json.ts, map-format.ts, generate.ts, fetch-new-site.ts, README, plus lib/urls.ts and server/sahajcloud-types.ts as the owners this code sits beside. Ladder, named answers only: localePath, Locale/KNOWN_LOCALES and JSON.stringify, all three flagged; nothing in the repo or a package answers the generator. package.json is the one pre-existing file the diff grows. JSON.stringify(map, null, 2) measures 1,331 lines against the committed 1,043. git grep confirms nothing outside scripts/ and the tests imports lib/legacy-redirects. All 121 meditations in new-site.json carry locale: en, so the always-English meditation target is upstream data, not a defect. No preview link: .claude/workflow.json declares no previewUrl or fixture.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread lib/legacy-redirects/core.ts Resolved
Comment thread scripts/legacy-redirects/map-format.ts Resolved
Comment thread lib/legacy-redirects/lookup.ts Resolved
Comment thread package.json Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Nov 18, 2026
sydevs-bot and others added 6 commits November 18, 2026 23:13
`pageHref` restated `localePath`'s rule, bare `/fr` case included, which
CLAUDE.md makes repo-wide: how a URL is spelled lives in `lib/urls.ts`,
never in a consumer. The published-there test is all that stays here.

`LAUNCH_LOCALES` values are now `Locale`, so a locale renamed upstream is
a compile error rather than a silent miss — `KNOWN_LOCALES` exists for
that. The visitor locale it feeds is typed through to `pageHref`.

`build.test.ts` reads the map byte-for-byte against the generator, so the
unchanged `map.generated.json` is the evidence this is a pure refactor.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWYeFVeG7kjXwXtUxy
Two hand-rolled formatters arrived in one diff. `JSON.stringify(map, null,
2)` already puts one slug per line, which is the whole property the
70-line walker existed for, so the walker and its module go and `json.ts`
keeps the one-line spelling the generator and `build.test.ts` share.

The map grows from 1,043 lines to 1,331 and from 39 KB to 40 KB — the
`pages` and `words` members expand instead of sitting inline. It stays
well under the 300 KB the test bounds it by, and still diffs per address.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWYeFVeG7kjXwXtUxy
The ten SELECTs lived twice, in `queries.ts` and verbatim in the README,
with a test case policing the copy. The README's "The queries" section now
points at `queries.ts`, and the reader who needs a statement runs the
script that carries it.

`only read` and `never select a user column` stay: those two check the
statements themselves, not a transcription.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWYeFVeG7kjXwXtUxy
Nothing imported the lookup, so the rules and the 40 KB map were
unreachable until the cutover. A Hono middleware registered before the
routes and acting after `next()` answers the 404 this site would otherwise
return, which is the first real request the map ever sees.

Under the `/en` prefix the lookup runs before the routes instead.
`+onBeforeRoute` 301s `/en/x` to `/x` ahead of any 404, so a legacy address
spelled that way would cost two hops; the lookup reads `/en` as the old
site's own prefix and answers with the same target in one. No enumerated
address is one this site already serves 200 at, measured over all 1,247, so
this cannot divert a live page.

The query string is the visitor's and goes back on untouched.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWYeFVeG7kjXwXtUxy
A target is spelled from a SahajCloud page slug, and the 404 middleware now
puts that answer in a `Location` header. A slug spelled `/evil.com` would
reach a visitor as `//evil.com`, which is a host despite the leading slash.

`isSitePath` is the gate `lib/urls.ts` already owns for exactly this, so
`lookupIn` applies it to every answer and no caller repeats it. No slug in
the committed map needs it today; all 45 are plain.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWYeFVeG7kjXwXtUxy
`data/legacy-redirects/README.md` and `lookup.ts` both said the wiring was
a separate ticket. It is in this branch, so both name
`server/legacy-redirects.ts`.

`AGENTS.md`'s URL-spelling rule listed two destinations a URL the site did
not author must be gated for. A `Location` header is the third, and
`isSitePath` is its gate.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWYeFVeG7kjXwXtUxy
@sydevs-bot

Copy link
Copy Markdown
Contributor

Four adopted, one rebutted. Pushed 408bf79. Each thread carries the detail.

Base was current, no merge. Security review over server/ and scripts/: no finding. Full gate green, pnpm build included.

Yours to call: isSitePath admits /\host, which browsers fold to //host. lib/urls.ts documents that limit and 54474d3 now rests on it, so a slug spelled \evil.com would still leave our origin. Every slug in the map is [a-z0-9_-], and tightening the gate changes Link too.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Nov 18, 2026
`Smoke (web)` failed on `canonicalizes the default (en) locale away via a
301 redirect` with `TypeError: Invalid URL`. The test reads the `Location`
header with `new URL`, and the new middleware answered `/en` with a bare
path, which that constructor refuses with no base.

`pages/+onBeforeRoute.ts` spells every other redirect this site issues over
the request's own URL, so the legacy map's targets are spelled that way too
rather than making this the one relative `Location` a client resolves itself.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjXZJx8AQgubkZU7iX9
@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 18, 2026
@sydevs-bot sydevs-bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 18, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor

The newest commit, 6a091db, is sydevs-bot's own, so it is not approved on your behalf. Read it, then say @sydevs-bot approve.

🤖 sydevs dispatcher

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wemeditate-web 8cbbf04 Commit Preview URL

Branch Preview URL
Nov 23 2026, 12:21 AM

foot-soak, ice-on-liver and candle-flame map to their new technique pages,
and about-us to about-meditation, as explicit documented matches in the
generator, applied in every language the old record exists in.

Part of #160

Co-Authored-By: Claude Fable 5.2 <[email protected]>
sydevs-bot
sydevs-bot previously approved these changes Nov 19, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved for Ardnived, who wrote it: GitHub refuses an author's own approval. CI is green and the automated review has run. Enable auto-merge when you want it merged: the queue tests it against its base. 🤖 Written by the sydevs autonomous loop — see what this is

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wemeditate-design 8cbbf04 Commit Preview URL

Branch Preview URL
Nov 23 2026, 12:21 AM

@sydevs-bot

Copy link
Copy Markdown
Contributor

The newest commit, 73f1f06, is sydevs-bot's own, so it is not approved on your behalf. Read it, then say @sydevs-bot approve, or enable auto-merge.

🤖 sydevs dispatcher

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 20, 2026
@sydevs-bot sydevs-bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 20, 2026
AGENTS.md conflicted on the URL-spelling rule. main (#323) condensed the
gate prose to point at each gate's own header; this branch had added the
`Location` header as a third destination. Took main's condensed wording
and kept the new destination as one line, because `isSitePath` is not an
`isSafe*` gate and its header says nothing about a redirect target.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjXN8FfQA4e1MdjMn3K
@sydevs-bot

Copy link
Copy Markdown
Contributor

Merged main in. One conflict, in AGENTS.md, on the URL-spelling rule.

main (#323) replaced the enumeration of the gates with a pointer to each gate's own header. This branch had added the Location header as a third destination. The resolution takes main's condensed wording and keeps that destination as one line, because isSitePath is not an isSafe* gate and its header says nothing about a redirect target — so main's pointer does not reach it.

server/AGENTS.md auto-merged. The merge result differs from the already-green head only in those two Markdown files.

Lean gate green: lint, tsc --noEmit, 1685 tests.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 20, 2026
@sydevs-bot sydevs-bot moved this from Working to Pending in SYDevelopers Technical Roadmap Nov 20, 2026
sydevs-bot
sydevs-bot previously approved these changes Nov 20, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved for Ardnived, who wrote it: GitHub refuses an author's own approval. CI is green and the automated review has run. Enable auto-merge when you want it merged: the queue tests it against its base. 🤖 Written by the sydevs autonomous loop — see what this is

@sydevs-bot sydevs-bot moved this from Pending to Awaiting in SYDevelopers Technical Roadmap Nov 20, 2026
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 22, 2026
@sydevs-bot sydevs-bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 22, 2026
main (#327) reorganised the tree by topic, so both conflicts and the
breakage underneath them are that refactor meeting this branch's new
files.

`package.json`: took main's `types:cms`, which now writes
`types/payload/payload-types.ts`, and kept this branch's four
`redirects:*` scripts beside it. Both sides wanted both.

`server/entry.ts`: took main's single `registerRoutes(app)` and kept
`registerLegacyRedirects(app)` ahead of it. The middleware is not a
route at a path — it acts after `next()` on whatever the site refused —
so it stays out of `server/routes/` and keeps its own registration.

The refactor also moved what this branch's added files import, which no
hunk reports because main never touched those files. `Locale` now comes
from `types/sahajcloud`, `DEFAULT_LOCALE` from `lib/i18n/locales`, and
the URL helpers from `lib/urls/urls`, each through `@/`. That also puts
`lib/legacy-redirects/core.ts` on the right side of the server-only
boundary main now lints: it read both names out of `server/` before.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjVF8mac9oL3ufMsMW4
@sydevs-bot

Copy link
Copy Markdown
Contributor

Merged main in. #327's reorganisation is what conflicted.

server/entry.ts: registerLegacyRedirects(app) stays ahead of main's single registerRoutes(app), and out of server/routes/. That folder is one route per path; this is middleware over whatever the site refused, so it has no path to be named for.

package.json: main's types:cms writes types/payload/payload-types.ts now, and the four redirects:* scripts sit beside it.

The part no hunk reported: the refactor moved what this branch's own files import, and main never touched those files, so git merged them clean and broken. Locale now comes from types/sahajcloud, DEFAULT_LOCALE from lib/i18n/locales, the URL helpers from lib/urls/urls. That also moves lib/legacy-redirects/core.ts off server/, which main's new ESLint boundary refuses — it read both names out of there before.

Gate green, plus pnpm build.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@Ardnived

Copy link
Copy Markdown
Contributor Author

@sydevs-bot Page 10 ("Meditate Now") is moving from slug meditate-now to meditations in production (#272, decided 2026-11-22), so /meditate-now will stop answering. Please retarget every map entry that points at /meditate-now to /meditations, in every locale, including the old "all meditations" addresses such as /meditations/all. Drop any entry whose source is now exactly /meditations (or /<locale>/meditations), because the page answers there itself, and update COVERAGE.md to match. Nested page addresses (#332) will regenerate the map again later through #333. This ask is only the slug move.

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 23, 2026
@sydevs-bot sydevs-bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 23, 2026
sydevs-bot and others added 2 commits November 23, 2026 00:16
Page 10 moves from `meditate-now` to `meditations` (#272), so every address
the map sent to `/meditate-now` now lands on `/meditations`, and `/meditations`
itself stops redirecting — the lookup already refuses a target equal to the
request, which makes it the seventh live address rather than a loop.

Production still serves `meditate-now`, so the move is a `PENDING_SLUG_MOVES`
override applied over `new-site.json` rather than an edit to it: the snapshot
stays what a re-fetch produces, and a re-fetch cannot revert the rename. The
entry throws if the snapshot carries a third spelling.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZ5B6SSLgtWfZi63ek
@sydevs-bot

Copy link
Copy Markdown
Contributor

Retargeted in 8cbbf04: the 263 addresses that pointed at /meditate-now now point at /meditations, in every locale, /meditations/all and the other index routes included. /meditations itself stops redirecting — the lookup already refuses a target equal to the request — so it is the seventh live address.

Production still serves meditate-now, so the rename is a PENDING_SLUG_MOVES entry applied over new-site.json, not an edit to it. A re-fetch cannot revert it.

I did not drop /<locale>/meditations. Page 10 is published in en only, so the new site answers no locale-prefixed address for it, and dropping those 8 (cs, es, hi, hy, nl, pt-br, ru, sv) turns working English fallbacks into 404s. Say the word and they go.

/meditations 404s on the deployed site today, and /meditate-now 200s, so #272 ships first.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 23, 2026
@sydevs-dispatcher
sydevs-dispatcher Bot dismissed sydevs-bot’s stale review November 23, 2026 00:23

A commit of sydevs-bot's own is now the head, and this approval did not cover it.

@sydevs-dispatcher

Copy link
Copy Markdown
Contributor

The newest commit, 8cbbf04, is sydevs-bot's own, so it is not approved on your behalf. Read it, then say @sydevs-bot approve, or enable auto-merge.

🤖 sydevs dispatcher

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants