Core

Go live: Core on core.ziteox.com

Ordered production cutover for Core — D1, secrets, deploy, Portal npm switch, install proof, rollback.

Go live: Core on core.ziteox.com

Nothing in this runbook has been done yet. Every step that touches Cloudflare, production secrets, Portal merge, Vercel, or CI is gated with Needs Laki OK. Do not skip the install proof (step 11).

Hosting choice (Workers + D1 vs alternatives): Hosting. Operations / route state: Operations & state.

Known gaps (prereqs)

  • Production GITHUB_MODE=app selects a stub GitHub App adapter (apps/core/src/github/index.ts → createGitHubAppAdapter). /v1/files, /v1/tree, and /v1/publish are not functional in production yet. The npm proxy and admin plane do not depend on it — go-live is for packages + admin.
  • No GitHub App id/private-key secrets are in env.d.ts yet (see apps/core/wrangler.toml comment block).

Steps

1. Prereqs

Needs Laki OK

  • Cloudflare account access for the Ziteox org
  • ziteox.com zone on Cloudflare (custom domain core.ziteox.com attaches via wrangler.toml routes)
  • Local auth: wrangler login

2. Create D1

Needs Laki OK

cd apps/core
wrangler d1 create ziteox-core

Paste the returned database_id into [[env.production.d1_databases]] in apps/core/wrangler.toml (replace the all-zero placeholder). Commit. The production database_id is now set in wrangler.toml.

3. Apply migrations

Needs Laki OK

The migrations/ dir is schema only. Local-dev seed data lives in apps/core/seed/dev_seed.sql and is applied only via pnpm db:seed / db:migrate locally — never remotely. migrations/0002_dev_seed.sql is a no-op kept because remote d1_migrations already records it as applied.

Current status (2026-11-01): production has 0001–0006 applied; 0007 is not applied yet. Migration 0007_packages_read_default.sql idempotently appends packages:read to every project’s allowed_scopes that lacks it (prod has 0 projects today, but it must still be applied remotely BEFORE the Worker deploy).

cd apps/core
# Expect 0007 pending:
npx wrangler d1 migrations list ziteox-core --remote --env production
npx wrangler d1 migrations apply ziteox-core --remote --env production

Verify production has no seed rows (expected all 0):

npx wrangler d1 execute ziteox-core --remote --env production --command "select (select count(*) from staff_roles) staff_roles, (select count(*) from mock_github_branches) mock_branches, (select count(*) from mock_github_files) mock_files, (select count(*) from mock_github_pulls) mock_pulls"

Cleanup if prod was already seeded (Needs Laki OK)

The production D1 (868971eb-fd98-4150-9d94-c30318f24380) was seeded on 2026-11-01 when 0002_dev_seed.sql still held inserts and was applied with --remote. Cleanup is pending Laki's OK.

This must happen BEFORE production admin public keys are set (step 7). Otherwise an assertion with sub=dev-admin would hold forge_admin.

npx wrangler d1 execute ziteox-core --remote --env production --command "DELETE FROM staff_roles WHERE user_id IN ('dev-admin','dev-operator'); DELETE FROM mock_github_pulls; DELETE FROM mock_github_files; DELETE FROM mock_github_branches;"

Then re-run the verification query above (expect all 0).

4. Secrets

Needs Laki OK

From the comment block in apps/core/wrangler.toml, put each secret:

cd apps/core
wrangler secret put CORE_SECRETS_KEK --env production
wrangler secret put ADMIN_ASSERTION_PUBLIC_KEYS --env production
wrangler secret put CORE_GITHUB_PACKAGES_TOKEN --env production

(CORE_KEK_VERSION may live in [env.production.vars] — already set to "1".)

Never echo secret values into chat, logs, or commits.

CORE_GITHUB_PACKAGES_TOKEN (Core's upstream token)

  • GitHub Packages for npm accepts only classic personal access tokens. Org-owned tokens, fine-grained PATs, and GitHub App installation tokens do not work for the npm registry.
  • The token is a classic PAT on the ziteox-admin GitHub account (a dedicated Ziteox admin account with read access to @ziteox/* packages), scope read:packages only, 90-day expiry, named "Ziteox Core upstream". Never reuse a write:packages token from a personal ~/.npmrc.
  • Set it with wrangler secret put CORE_GITHUB_PACKAGES_TOKEN --env production (paste at the prompt, or pipe it without echo).
  • Rotation reminder: rotate every 90 days, before expiry. Create a new classic PAT on ziteox-admin, run wrangler secret put again (takes effect without a redeploy), verify with the packument curl, then delete the old PAT.
  • The machine-user approach is already in place: keep the PAT on ziteox-admin, not on anyone's personal GitHub account.

KEK backup (decision pending Laki)

CORE_SECRETS_KEK was generated and set directly on 2026-11-01 with no copy kept. Cloudflare secrets can't be read back, so store a copy in a vault (e.g. a password manager) before any secret is sealed with vault.seal — otherwise sealed secrets can't be recovered if the Worker secret is lost. Currently nothing is sealed. The decision is pending Laki.

5. Dry run then deploy

Needs Laki OK

cd apps/core
wrangler deploy --dry-run --env production
wrangler deploy --env production

Custom domain core.ziteox.com attaches automatically via routes = [{ pattern = "core.ziteox.com", custom_domain = true }].

6. Verify

Needs Laki OK (run after deploy; share outcomes, not tokens)

Browsers hitting GET / with Accept: text/html get a small status page: logo (links to https://ziteox.com; plain link, no animation, no JS), title, and the environment·version pill only — no health indicator, no D1 access, no JavaScript. Other Accept values still get the JSON 404 not_found. GET /favicon.ico serves the Ziteox JPEG favicon (no auth).

curl -s https://core.ziteox.com/healthz

# Expect 401 without token
curl -s -o /dev/null -w '%{http_code}' https://core.ziteox.com/npm/@ziteox%2fui

# With production packages:read token (never echo the token)
curl -s -H "Authorization: Bearer $ZITEOX_CORE_NPM_TOKEN" \
  https://core.ziteox.com/npm/@ziteox%2fui | jq '.versions|keys'

# Tarball — replace <sha> with the lockfile path segment; expect 200
curl -s -o /dev/null -w '%{http_code}' \
  -H "Authorization: Bearer $ZITEOX_CORE_NPM_TOKEN" \
  https://core.ziteox.com/download/@ziteox/ui/0.1.1/<sha>

# Non-allowlisted package — expect 404, no upstream
curl -s https://core.ziteox.com/npm/lodash

Check audit via the admin portal (GET /v1/admin/audit) for npm.packument / npm.tarball rows.

7. Seed staff roles / admin public keys

Needs Laki OK

Production does not run the local seed (seed/dev_seed.sql). migrations/0002_dev_seed.sql is a no-op; do not insert dev-admin / dev-operator into production. If those rows were applied earlier, finish the step-3 cleanup before setting production admin keys.

  1. Ensure ADMIN_ASSERTION_PUBLIC_KEYS (step 4) pins production kids from the admin portal (e.g. admin-YYYY-MM) — see Admin portal integration (key pinning / iss).
  2. Insert real staff into D1 staff_roles (Account user ids → forge_admin / forge_operator), e.g. via wrangler d1 execute ziteox-core --remote --env production --command "…". Match portal sub / member ids. Do not reuse local dev-* ids.
  3. Confirm ADMIN_ASSERTION_ISSUER production var is https://admin.ziteox.com (already in wrangler.toml).

8. Mint production package-read tokens

Needs Laki OK

Via admin portal → Core POST /v1/admin/tokens with scopes ["packages:read"], environment production (and a separate token for CI — environment staging or production as decided). Store as ZITEOX_CORE_NPM_TOKEN hosts only — never commit. Details: Admin portal integration, Install packages.

9. Vercel env

Needs Laki OK (may prepare before deploy; do not rely on it until step 11)

On the ziteox-client Vercel project, set ZITEOX_CORE_NPM_TOKEN for Production and Preview:

vercel env add ZITEOX_CORE_NPM_TOKEN production
# and preview similarly

Do not add GITHUB_PACKAGES_TOKEN for the Core cutover.

10. Merge Portal branch (Portal repo, not Forge)

Needs Laki OK

Portal’s client change is already done locally as commit ad9a36a on branch core-npm-registry in the ziteox-platform repo (worktree portal-corenpm, not pushed). It changes both .npmrc files to the two core.ziteox.com lines, and the lockfile changes only the @ziteox/ui resolved host to https://core.ziteox.com/download/... with identical integrity.

# In the Portal / ziteox-platform checkout (portal-corenpm worktree)
git push -u origin core-npm-registry
# open PR → review → merge to development

Also in that PR or right after — CI still uses GitHub Packages on install:

  • ci.yml npm ci env: ~L25–27, ~L53–55, ~L84–86 still have GITHUB_PACKAGES_TOKEN: ${{ secrets.GITHUB_PACKAGES_TOKEN }}. Replace with ZITEOX_CORE_NPM_TOKEN: ${{ secrets.ZITEOX_CORE_NPM_TOKEN }}.
  • sync-supabase.yml npm ci (~L30): add the same ZITEOX_CORE_NPM_TOKEN env once .npmrc points at Core (that step currently has no packages-token env).

Add the repo secret:

gh secret set ZITEOX_CORE_NPM_TOKEN --repo <org>/ziteox-platform

The registry URL comes from the committed .npmrc (https://core.ziteox.com/npm/) — CI needs no registry URL variable.

Order: steps 9–10 may be prepared before Worker deploy, but nothing on the client side merges / cuts over until step 11 passes.

11. Install proof

Needs Laki OK — mandatory post-deploy, before client merge/redeploy.

On a clean checkout of the Portal branch (ad9a36a), with no GitHub token in the environment and an empty npm cache:

git clone --branch core-npm-registry <portal-repo> /tmp/zx-golive-proof && cd /tmp/zx-golive-proof
export ZITEOX_CORE_NPM_TOKEN=<production packages:read token>   # never echo it
unset GITHUB_PACKAGES_TOKEN NPM_TOKEN
npm ci --cache /tmp/zx-golive-npm-cache --prefer-online
grep -n '"resolved": "https://core.ziteox.com/download/@ziteox/ui' package-lock.json
npm run build --workspace ziteox-portal   # client workspace package name

Pass = npm ci exit 0, client build exit 0, and Core audit shows npm.packument + npm.tarball allowed for production.

Fail = do not merge or redeploy the client; keep Vercel/CI on GITHUB_PACKAGES_TOKEN, and roll back per Rollback if anything was already switched. Capture Core audit reason / upstream_status to diagnose. Clean up /tmp/zx-golive-proof and /tmp/zx-golive-npm-cache afterwards.

12. Redeploy ziteox-client on Vercel

Needs Laki OK — only after step 11 passes.

Redeploy; verify the Vercel build log shows @ziteox/ui fetched from core.ziteox.com, and Core audit shows npm.tarball ok for production.

13. Retire GITHUB_PACKAGES_TOKEN

Needs Laki OK — after a stable period.

Remove GITHUB_PACKAGES_TOKEN from Vercel and GitHub Actions secrets once Core installs are proven stable.

Rollback

Each action Needs Laki OK.

PathAction
(a) ClientRevert the .npmrc + lockfile commit back to npm.pkg.github.com; restore GITHUB_PACKAGES_TOKEN in CI/Vercel; redeploy.
(b) Workerwrangler deployments list --env production then wrangler rollback <version-id> --env production.
(c) D1wrangler d1 time-travel info ziteox-core --env production / wrangler d1 time-travel restore ziteox-core --timestamp <ISO> --env production — restores the whole DB (~30-day window).
(d) EmergencyRevoke project tokens via admin, or remove the custom domain.