Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 78 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,50 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- **`helpbase context` renamed to `helpbase ingest`.** `context` described
a domain concept, not an action — `ingest` names what the command does
(walk your code + markdown, synthesize cited how-tos, wire MCP). The
old name continues to work as a deprecation shim: same flags, same
behavior, one-line stderr warning, suppressed under `--json`/`--quiet`.
Help text + README Quick Start + scaffolder next-steps output now lead
with `ingest`. CI scripts pinned to `helpbase context` keep working
until v0.7, which is when the shim is removed. Flag surface is shared
via `applyIngestOptions()` so the two commands can't drift. First PR
of the CLI DX v2 plan.

### Added
- **`helpbase login` reserves a subdomain instantly.** After successful
authentication, the CLI calls `POST /api/v1/tenants/auto-provision`
which mints a product-neutral `docs-<6hex>.helpbase.dev` reservation
for the caller. The reserved URL prints in the login outro so users
see a concrete destination before they've written a single article.
TTHW for the first-deploy happy path drops from ~3-4 min (slug
prompt + confirmation) to ~90s (login + deploy, zero prompts). If
the auto-provision call 503s, login still succeeds — the reservation
is best-effort, and `helpbase whoami` / `helpbase deploy` both lazy-
provision as a fallback for users who were logged in before this
feature existed or who Ctrl-C'd between session save and the first
auto-provision call.
- **New command: `helpbase rename <new-slug>`.** Pre-deploy slug rename
for the auto-provisioned reservation. Server gates on `deployed_at
IS NULL`, so post-deploy renames are cleanly rejected with
`E_RESERVATION_LOCKED`. Update + local cache write is atomic from
the user's perspective; subsequent `whoami` reflects the new slug
without an extra round-trip.
- **Branded "coming soon" landing page** at reserved-tenant subdomains.
Reserved tenants now render a helpbase-branded placeholder at `/`
explaining that the help center hasn't been published yet, and
return 404 for every other path so article deep-links don't leak
the empty category grid. Every reserved-tenant response carries
`X-Robots-Tag: noindex, nofollow` so Google doesn't index `docs-*.
helpbase.dev` placeholders.
- **`helpbase whoami` surfaces the reservation.** Users with no
deployed tenants but an active reservation see a `reserved:
<slug>.helpbase.dev` line and a hint to run `helpbase deploy` or
`helpbase rename`. `helpbase open` falls back to the reservation
URL when no deployed tenant exists.
- **`deploy_tenant` RPC flips `deployed_at` atomically.** First publish
transitions a reservation to "live" inside the same transaction as
the content INSERT, so the reservation-vs-deployed boundary is
never racy. `COALESCE` preserves the ORIGINAL `deployed_at` on
re-deploys — per-deploy history continues to live in
`tenant_deploys.created_at`.
- **Vercel Cron: `/api/cron/cleanup-reservations`.** Nightly (03:00
UTC) job that prunes reservations older than 30 days that never
deployed. Guarded by a `NOT EXISTS (SELECT 1 FROM tenant_deploys
WHERE tenant_id = tenants.id)` predicate so a row with ghost
deploy history can never be deleted even if `deployed_at` somehow
failed to update. Supports `?dry=true` for a no-op count. Bearer
auth via `CRON_SECRET` env var.
- **Unit tests for the device-authorize state machine.** Extracted the
8-phase `Phase` union from `AuthorizeDeviceClient` into a pure
`phaseReducer` function so every transition can be verified without
Expand All @@ -41,6 +72,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
magic-link path always remains available as a fallback. Cold-path
TTHW drops from ~60s (email round-trip) to ~20s (one-click OAuth).

### Changed
- **`helpbase context` renamed to `helpbase ingest`.** `context` described
a domain concept, not an action — `ingest` names what the command does
(walk your code + markdown, synthesize cited how-tos, wire MCP). The
old name continues to work as a deprecation shim: same flags, same
behavior, one-line stderr warning, suppressed under `--json`/`--quiet`.
Help text + README Quick Start + scaffolder next-steps output now lead
with `ingest`. CI scripts pinned to `helpbase context` keep working
until v0.7, which is when the shim is removed. Flag surface is shared
via `applyIngestOptions()` so the two commands can't drift. First PR
of the CLI DX v2 plan.
- **`/api/v1/tenants/mine` hides reservations.** Reservations are
pre-first-deploy placeholders and shouldn't pollute the tenant
picker for multi-tenant users. The new filter is
`.not("deployed_at", "is", null)`. Callers that specifically want
the reservation (login, whoami, open) hit
`GET /api/v1/tenants/reservation` instead.
- **`tenants_public` view now exposes `deployed_at`.** The subdomain
middleware needs this to distinguish reserved tenants from live
ones without granting anon read access to the full tenants table.
`mcp_public_token` still never appears in the view.

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
### Schema
- New columns on `public.tenants`: `deployed_at timestamptz` +
`auto_provisioned_at timestamptz` (both nullable). Backfilled
existing rows with `deployed_at = created_at`.
- New UNIQUE partial index `idx_tenants_owner_one_reservation`
on `owner_id WHERE auto_provisioned_at IS NOT NULL AND
deployed_at IS NULL` — race-safe idempotency for the
auto-provision endpoint.
- New lookup index `idx_tenants_owner_auto_provisioned` on the same
partial predicate minus the `deployed_at` clause — small and
sargable for the reservation lookup path.
- Migration: `slug_reservation_columns_and_first_deploy_timestamp`.

## [helpbase 0.5.0] — 2026-04-17

### Added
Expand Down
25 changes: 23 additions & 2 deletions apps/web/app/(tenant)/t/[tenant]/mcp/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type TenantForMcp = {
slug: string
mcp_public_token: string
active: boolean
deployed_at: string | null
}

async function loadTenant(
Expand All @@ -55,7 +56,7 @@ async function loadTenant(
): Promise<TenantForMcp | null> {
const { data } = await client
.from("tenants")
.select("id, slug, mcp_public_token, active")
.select("id, slug, mcp_public_token, active, deployed_at")
.eq("slug", slug)
.eq("active", true)
.maybeSingle()
Expand Down Expand Up @@ -237,7 +238,12 @@ async function handle(request: NextRequest, tenantSlug: string): Promise<Respons
return NextResponse.json({ error: "tenant not found" }, { status: 404 })
}

// Auth: bearer token must match the per-tenant public token.
// Auth: bearer token must match the per-tenant public token. Runs
// BEFORE the deployed_at check so unauthenticated callers can't use
// the response shape to distinguish a reserved tenant from any other
// slug (the 403 `tenant_not_deployed` body vs 401 would otherwise
// confirm "yes this slug exists AND is reserved" to a scanner).
// CodeRabbit flagged this on PR #10 2026-04-18.
const provided = extractBearer(request.headers.get("authorization") ?? undefined)
if (!provided) {
return NextResponse.json({ error: "missing bearer token" }, { status: 401 })
Expand All @@ -246,6 +252,21 @@ async function handle(request: NextRequest, tenantSlug: string): Promise<Respons
return NextResponse.json({ error: "invalid token" }, { status: 401 })
}

// Reserved tenants (auto_provisioned_at set, deployed_at still null) have
// no content to serve. Return 403 with a structured error so authenticated
// MCP clients polling a reservation URL during a user's first-deploy window
// get a clean signal instead of empty search results that look like bugs.
if (tenant.deployed_at === null) {
return NextResponse.json(
{
error: "tenant_not_deployed",
message:
"This tenant is reserved but hasn't published content yet. The owner needs to run `helpbase deploy`.",
},
{ status: 403 },
)
}

// Rate limits: per-IP burst (Vercel KV) + per-tenant daily cap (Supabase).
// Fail-open on KV errors; per-tenant check reads current count before
// incrementing async so this adds one DB round-trip per request.
Expand Down
38 changes: 20 additions & 18 deletions apps/web/app/(tenant)/t/_not-found/page.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import Link from "next/link"
import { notFound } from "next/navigation"

export default function TenantNotFound() {
return (
<div className="flex min-h-svh flex-col items-center justify-center px-4">
<h1 className="text-2xl font-bold tracking-tight">
Help center not found
</h1>
<p className="mt-3 text-muted-foreground">
This subdomain hasn't been set up yet.
</p>
<a
href="https://helpbase.dev"
className="mt-6 rounded-lg bg-foreground px-4 py-2 text-sm font-medium text-background transition-opacity hover:opacity-90"
>
Create your help center
</a>
</div>
)
/**
* Tenant "not found" page. Rendered by the subdomain middleware for:
* - unknown subdomains (never-existed tenants)
* - reserved tenants at deep-link paths (articles/search/etc. — root
* `/` still routes to the branded "coming soon" landing)
*
* Calling `notFound()` is the load-bearing bit: Next.js converts it into
* a true HTTP 404 response (not a 200 with "not found" copy). That
* matters because middleware-level rewrites preserve the destination's
* status, and we want crawlers + MCP clients + monitoring tools hitting
* unknown or reserved subdomain paths to see "nope, nothing here" at
* the protocol level, not "here's a page that claims nothing is here."
* The previous implementation rendered a 200 HTML page with a "Create
* your help center" CTA; that CTA can come back as a proper
* `not-found.tsx` route later. Ship correctness first.
* Caught by /review codex on 2026-04-18.
*/
export default function TenantNotFound(): never {
notFound()
}
82 changes: 82 additions & 0 deletions apps/web/app/(tenant)/t/_reserved/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import type { Metadata } from "next"

/**
* Reserved-tenant landing page.
*
* Rendered by the subdomain middleware (proxy.ts) when a subdomain
* matches a tenant row whose `deployed_at` is still null — meaning the
* owner logged in and got an auto-provisioned reservation but hasn't
* published content yet. Anyone visiting the URL sees this page instead
* of an empty category grid, and the response carries X-Robots-Tag:
* noindex so Google doesn't index placeholder subdomains.
*
* Intentionally minimal: no Supabase lookup (the middleware already
* confirmed the slug exists), no owner email leakage, no admin info.
* The slug in the URL is the only identifier shown.
*/

export const metadata: Metadata = {
robots: { index: false, follow: false },
title: "Coming soon",
}

// Static — no per-slug data is fetched, everything the page needs lives
// in the URL segment. `revalidate` can be any value since nothing varies.
export const revalidate = 3600

export default async function ReservedTenantPage({
params,
}: {
params: Promise<{ slug: string }>
}) {
const { slug } = await params
// Keep in sync with proxy.ts. The apex stays configurable so staging
// (e.g. helpbase-dev.vercel.app) and self-hosted setups don't render
// a page advertising the wrong hostname. CodeRabbit flagged the hard
// coded "helpbase.dev" string on PR #10.
const rootDomain = (process.env.NEXT_PUBLIC_ROOT_DOMAIN ?? "helpbase.dev").trim()
const displayHost = `${slug}.${rootDomain}`

return (
<div className="mx-auto flex min-h-svh w-full max-w-xl flex-col items-center justify-center px-6 py-16">
<div className="w-full text-center">
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-muted-foreground">
helpbase
</p>
<h1 className="mt-6 text-3xl font-semibold tracking-tight">
This help center isn&apos;t live yet
</h1>
<p className="mt-4 text-base text-muted-foreground">
<span className="font-mono text-foreground">{displayHost}</span>{" "}
has been reserved. The owner needs to publish content before visitors
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
see anything here.
</p>

<div className="mt-10 rounded-xl border border-border bg-muted/30 p-5 text-left">
<p className="text-sm font-medium">If this is your help center</p>
<p className="mt-2 text-sm text-muted-foreground">
Run the helpbase CLI from your project root to publish:
</p>
<pre className="mt-3 overflow-x-auto rounded-lg bg-background px-4 py-3 text-xs">
<code>{`helpbase deploy`}</code>
</pre>
<p className="mt-3 text-xs text-muted-foreground">
Prefer a different subdomain? Run{" "}
<code className="font-mono">helpbase rename &lt;new-slug&gt;</code>{" "}
before your first deploy.
</p>
</div>

<p className="mt-10 text-sm text-muted-foreground">
Learn more at{" "}
<a
href="https://helpbase.dev"
className="underline underline-offset-4 hover:text-foreground"
>
helpbase.dev
</a>
</p>
</div>
</div>
)
}
Loading
Loading