Skip to content

feat(scripts): redeem a sign-in link for a remote seed run's ADMIN_TOKEN - #1008

Merged
Ardnived merged 1 commit into
mainfrom
claude/feat-redeem-signin-link
Oct 21, 2026
Merged

Ardnived merged 1 commit into
mainfrom
claude/feat-redeem-signin-link

Conversation

@Ardnived

Copy link
Copy Markdown
Contributor

Summary

  • scripts/redeem-signin-link.ts gets a remote seed run's ADMIN_TOKEN from a sign-in link. Before this, the only way was to sign in with a browser and copy the payload-token cookie out of devtools (managers have no password since feat(auth): cut managers over to passwordless, disabling the local strategy #840).
  • --seed <script> … redeems the link and runs pnpm seed with ADMIN_TOKEN and SAHAJCLOUD_URL taken from the link. Nothing is saved: a session expires within hours, so a copy in .env.local only goes stale. Without --seed, the token is printed to stdout for export ADMIN_TOKEN=$(…).
  • Docs name the script wherever they named the cookie. They also record the 2026-10-21 production load of the meditation transcripts (Every meditation gets an accurate transcript #897).

How it works

redeem-signin-link.ts '<link>' [--seed <script> …]
  parseSignInLink(link)               # origin, token, collection, expiry from the JWT's unverified claims
  expired? → refuse before spending the link
  POST {origin}/api/{collection}/redeem?token=…   (redirect: 'manual')
     302 + Set-Cookie payload-token   → session
     302 → ?error=expired|invalid|…   → describeRefusal()
  GET  {origin}/api/{collection}/me   (Authorization: JWT, DisableAutologin)
     → "Signed in as … (admin)", warns when not an admin
  --seed → spawn pnpm seed …  env: ADMIN_TOKEN=session, SAHAJCLOUD_URL=origin
  else   → token on stdout
  • It grants nothing the link does not. It sends the same public POST the sign-in page's button sends (src/plugins/login/endpoints/redeem.ts). ⚠ It spends the link, so a dry run and the real run need two links.
  • --seed runs pnpm seed and nothing else. An allow rule such as Bash(pnpm tsx scripts/redeem-signin-link.ts *) therefore lets an agent take a pasted link without granting any other command. Without that rule, Claude Code's auto mode refuses to redeem a pasted link at all.
  • The run always targets the link's own server. The token and URL are set in the child process's environment, which seeds/env.ts ranks above .env.local. A stale file cannot replace the token or send it to another server.
  • The /me check sends DisableAutologin. A dev server answers /me with its auto-login admin whatever the token, so without the header a broken session would read as working.

Docs

  • seeds/AGENTS.md describes the script as the way to get ADMIN_TOKEN, with the permission rule for agent sessions. It also corrects the transcript skip list: production lacks 121, 122, 143 and 151. 83 resolved and was imported.
  • Pointers updated in AGENTS.md, scripts/AGENTS.md, .env.example, seeds/env.ts, and the missing-token error in seeds/run.ts.

Testing

  • tests/unit/signin-token.spec.ts covers parsing a link, finding the session cookie, and wording each refusal. The Tier 2 lean gate passes: lint, typecheck, typecheck:tests and the unit lane.
  • Run against a local fake redeem server:
    • a link that is redeemed;
    • a refused link, which gets the plain-words refusal;
    • an unreachable host;
    • wrong usage.
    • --seed: the child seed run sent the redeemed token to the link's server, ignoring a stale ADMIN_TOKEN and a localhost SAHAJCLOUD_URL in .env.local.
  • Not yet run against production with a real link. The production transcript load used a token taken directly from a session.

Production transcript load (#897)

Run 2026-10-21 against cloud.sydevelopers.com:

  • 122 transcripts created, 4 skipped with warnings, 0 errors.
  • Every live meditation now has a completed transcript, and 0 transcription jobs were queued.
  • The word list was applied: no "fentanyl", "fontanel" or lower-case "kundalini" remain.

🤖 Generated with Claude Code

A remote seed run needs a manager session token, and since #840 the only
way to one was signing in with a browser and copying the `payload-token`
cookie out of devtools. `scripts/redeem-signin-link.ts` sends the same
`POST /api/<collection>/redeem` the sign-in page's button sends and reads
the cookie off the 302 instead.

`--seed <script> …` runs `pnpm seed` with `ADMIN_TOKEN` and
`SAHAJCLOUD_URL` taken from the link, so the token is never printed or
saved — a session expires within hours, and a copy in `.env.local` only
goes stale — and the target is always the server the token is valid on.
Without it, the token goes to stdout. `--seed` runs `pnpm seed` and
nothing else, so an allow rule on the script's prefix lets an agent take
a pasted link without granting any other command.

The session is checked against `/me` with `DisableAutologin`, since a dev
server answers with its auto-login admin whatever the token. The pure
parts (`signin-token.ts`) are unit-tested.

Docs now name the script wherever they named the cookie, and record the
2026-10-21 production load of the meditation transcripts (#897): 122
created, 0 errors. The four skips are 121, 122, 143 and 151, not 83 —
83 resolved and imported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Ardnived
Ardnived merged commit a99aae9 into main Oct 21, 2026
6 of 7 checks passed
@Ardnived
Ardnived deleted the claude/feat-redeem-signin-link branch October 21, 2026 01:27
@sydevs-bot sydevs-bot moved this from Revising to Done in SYDevelopers Technical Roadmap Oct 21, 2026
sydevs-bot pushed a commit that referenced this pull request Oct 21, 2026
#1008 added the 217th unit spec on `main`, so `perf-figures-pinned` went red
on the merge: PERF.md still recorded 216 files / 2787 tests. No hunk conflicted
— the counts are a fact about the merged tree, which neither side could state.

Measured on the merged branch: 217 files, 2792 tests. PERF.md and its four
consumer docs move together, as that spec requires. The 77.9 s lane median
stays — it records the slowest measurement, and this container ran 40.3 s.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011G1Sr7nRy5nFcMNQgZ7kkk
sydevs-bot pushed a commit that referenced this pull request Oct 21, 2026
#1008 landed while this branch was open. Both conflicts were the same
shape: this branch's prettier-padded markdown tables against main's
unpadded ones carrying new rows. Each hunk takes main's content, then
prettier re-applies this branch's formatting — scripts/AGENTS.md made no
content change on this side at all, and AGENTS.md's own two changes sit
outside the conflicted table and merged cleanly.

#1008's three new files were written against a main with no format gate,
so prettier reformats them here: this branch adds `pnpm format:check` to
CI, and an unformatted file arriving from main would fail it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QbkFbm5JUVrWVWMgqydNLi
sydevs-bot pushed a commit that referenced this pull request Oct 21, 2026
#1008 added tests/unit/signin-token.spec.ts without repinning tests/PERF.md,
so perf-figures-pinned is red on main: PERF.md says 215 files where the lane
now has 216. Merging main in carries that failure onto this branch.

PERF.md is the single writer of the figure, so the three consumers its
invariant names move with it. Counts only — the lane timing stays at its
recorded slowest measurement, which this run did not re-measure.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QbkFbm5JUVrWVWMgqydNLi
sydevs-bot pushed a commit that referenced this pull request Oct 21, 2026
`perf-figures-pinned.spec.ts` compares PERF.md's recorded file count
against the specs on disk, and it read 215 against 216. The lane is
otherwise green: 2787 of 2788 passed, this pin the only failure.

The extra file came in with `a99aae9` (#1008), which added
`tests/unit/signin-token.spec.ts` without re-measuring. So the same
assertion is red on `main`, and fixing it here is what gets this PR
green — PERF.md's own rule is that the Files / tests row carries "the
current tree's" counts while every timing stays with the session that
measured it, so the counts move and the 77.9 s median does not.

Re-measured on this head, 4 cores: 216 files / 2788 tests, the figure
CI reported on `5394892`. The three consumer docs that quote the counts
move with it, which is the coupling the spec's second and third claims
exist to enforce.

#1009 carries 220 / 2835 for its own tree — it adds four spec files of
its own, so its numbers cannot stand in for this branch's.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WcsBbMS7ZqEP272YZNHXYk
github-merge-queue Bot pushed a commit that referenced this pull request Oct 21, 2026
…sh fallback (#997)

* fix(status): Launch Readiness answers about the locale, not the English fallback

Every non-English locale carries `fallbackLocale: 'en'`, so a section read
that named no `fallbackLocale` resolved the English value and a check
described "for this locale" passed on it. Six of the seven sections read
that way, which made "Meditation assigned" and "Article translated" green
for 18 locales in which no Path Step has been translated at all.

Each section's `prepare` now passes `fallbackLocale: false` wherever one of
its checks reads a localized field, and every read in the global hands the
Local API a `localeIsolatedReq` copy. `createLocalReq` assigns `locale` and
`fallbackLocale` onto the request it is given, so forwarding the shared one
let a section decide what the sections after it resolved — in whichever
order Payload runs the virtual fields' `afterRead` hooks.

Lectures keeps the fallback, and says why: no check there reads a localized
field, so it resolves only the row labels. Pages and User Choices do read
one, so their labels get their own fallback read rather than degrading to
`#42` on a screen an operator acts on.

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

* refactor(status): the request copy moves into runSection, and labels onto the row

Review pass over the locale-scoping fix. Four changes, none of them a
behaviour change to what the report answers:

- `runSection` copies the caller's request once per section. Payload awaits
  every virtual field's `afterRead` in one `Promise.all`, so the sections
  run concurrently on one request, and `find` destructures `locale` and
  `fallbackLocale` off it after its own await — a sibling read can land an
  assignment inside that window. The invariant belongs to the machinery; a
  section's own reads still copy wherever they differ from each other.
- The fallback title is merged onto the row in `prepare` instead of being
  threaded as a second channel. `labelOf` then needs no argument it did not
  already have, and no group evaluator carries a label map it only indexes
  by an id it holds.
- Both label reads select `title` alone and run beside the read they used to
  wait for. The user-choices one dropped a `where` built from its sibling's
  rows, which was the only thing forcing it to wait.
- `getWmAppConfig` uses the shared `memoizeOnRequest` rather than its own
  copy of that logic, including the rationale.

`DocumentReport.label` now owns why a check and a label want opposite
locale policies, so neither section restates it.

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

* docs(status): a concurrent sibling read needs the copy too

The nested-read rule said to skip the `req` copy when the nested call uses
the caller's own locale. That is the case #982 bit: concurrent reads on one
request repoint each other between `createLocalReq` and the operation's own
read of the flags, whatever locale each names.

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

* fix(ci): lessons title and panels are localized now

`main` moved under this branch: #978 made `lessons.title` and `lessons.panels`
localized. The merge therefore turns two of this PR's own assertions false, and
CI failed on `expect(fr['panels-set']).toBe(true)`.

Both changed checks are now right to report red at a locale with no panels and
no title of its own, so the spec says so. The label is the part that needed
code: `labelOf` reads `title`, which the section's `fallbackLocale: false` read
now nulls, so every Path Step row rendered as `#42` at an untranslated locale —
the defect this PR fixes for Pages and User Choices, arriving in a third
section. `lessons` joins `readFallbackTitles`, and the fallback title stays out
of the documents the checks read so `lesson-title-set` keeps answering per
locale.

Watched failing first: with the label taken from the per-locale read, the case
reports `expected '#1' to be 'English-only lesson'`.

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

* fix(status): one request copy, at the read that makes it

`runSection` copied the caller's request per section and every read inside
a section copied again. Only the second is load-bearing: reads within one
section differ from each other, so a single copy at the seam could never
cover them, and no group `evaluate` reads anything for it to guard.

The machinery copy also made the isolation spec vacuous. It asserts the
caller's locale and fallback survive every section in
`WeMeditateAppStatusSpec.sections`, and passed off `runSection`'s copy
whether or not a section's own reads took one. With it gone, dropping
`isolatedReq` from `translations`' read reports `translations repointed
req.fallbackLocale` — watched failing, then restored.

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

* fix(status): the core-pages group stops naming a page count

The group read "All ten required app pages" while `APP_PAGE_FIELDS` holds
14, so the figure it showed an operator was wrong by four. A count in that
sentence drifts with the list and the group already shows one row per page,
so it names none. Its subtle-system sibling keeps "twelve": that set is
closed and a migration seeds exactly those slugs.

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

* fix(ci): re-measure the pinned unit spec count

`perf-figures-pinned.spec.ts` compares PERF.md's recorded file count
against the specs on disk, and it read 215 against 216. The lane is
otherwise green: 2787 of 2788 passed, this pin the only failure.

The extra file came in with `a99aae9` (#1008), which added
`tests/unit/signin-token.spec.ts` without re-measuring. So the same
assertion is red on `main`, and fixing it here is what gets this PR
green — PERF.md's own rule is that the Files / tests row carries "the
current tree's" counts while every timing stays with the session that
measured it, so the counts move and the 77.9 s median does not.

Re-measured on this head, 4 cores: 216 files / 2788 tests, the figure
CI reported on `5394892`. The three consumer docs that quote the counts
move with it, which is the coupling the spec's second and third claims
exist to enforce.

#1009 carries 220 / 2835 for its own tree — it adds four spec files of
its own, so its numbers cannot stand in for this branch's.

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

---------

Co-authored-by: Claude <[email protected]>
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.

1 participant