feat(plans): three-plan entitlements, 402 plan_limit task gate, Starter checkout (app#2044 row 3)
Implements row 3 of app#2044. Fulfils the contract in docs#324 (merge the docs PR first).
What changed
lib/plans/(new):Plan=free | starter | pro;getPlanEntitlements(Free 1 task / weekly / $3.33, Starter 3 / daily / $20, Pro uncapped / hourly / $300);resolvePlan(Starter price id => starter, any other active account sub, org sub, or enterprise domain => pro, otherwise free);getMinCadenceMinutes+parseCronField(walk the calendar from a fixed epoch, shortest gap between consecutive fires, standard DOM/DOW OR semantics, no new dependency);findTaskPlanViolation;buildPlanLimitBody;PlanLimitError;assertTaskWithinPlan(the write-path gate);isTaskPlanBlocked+getTaskRunBlock(the run-path gate); No grandfather window — limits apply immediately.getAccountSubscriptionStategainsplan;isProis nowplan === "pro", so Starter keeps the free-tier gates on roster scrape, any-recipient emails, and API keys.- Credits derive the monthly total from the plan:
checkAndResetCredits(refill floor),initializeAccountCredits(seed),buildAccountCreditsResponse(GET /api/accounts/{id}/creditsgainsplan,task_limit,min_cadence_minutes).PRO_CREDITS_USD99.99 -> 300, newSTARTER_CREDITS_USD20. - Task gate:
createTaskcallsassertTaskWithinPlanbefore the insert (covers REST and MCPcreate_task);updateTaskcalls it when a PATCH re-enables a disabled task (takes a slot) or changesschedule(cadence only); title/prompt/model edits never touch it. Both handlers mapPlanLimitErrorto 402 with the documented body. The owner's plan is checked, not the caller's; admins are not exempt. - Run path:
GET /api/tasks?id=(what the Trigger.dev runner reads before every run,tasks/src/recoup/fetchTask.ts) answers 402plan_limitwhen the task is outside its owner's plan. The runner treats any non-200 as "skip this run" today, so no change to thetasksrepo. Limits apply immediately to every enabled task (including ones that existed before the gate); a downgraded account loses its extra / denser tasks at once. Over the cap, the oldest tasks keep their slots (created_at, thenidtie-break). - Starter checkout:
POST /api/subscriptions/sessionsaccepts optionalplan(defaultpro); Starter usesSTRIPE_STARTER_PRICE_IDwith no trial and returns 400{ error: "starter_unavailable" }while the env var is unset.planis stamped on session and subscription metadata.GET /api/accounts/{id}/subscriptionreportsplan: "starter"withisPro: falsefor the Starter price. lib/stripe/config.tsgainsSTRIPE_STARTER_PRICE_ID(env, empty default). The Stripe-first checkout PR (row 8) appends the identical line so the two merge cleanly.
Assumptions (Sweets' "Go" on 2026-08-29; each is one constant)
| Decision | Value | Where |
|---|---|---|
| Pro credit multiple | 3x price = $300 (5x is a one-line change) | PRO_CREDITS_USD |
| Pro minimum cadence | hourly | getPlanEntitlements |
| Grandfathering | none — enforce immediately (Sweets 2026-08-30) | n/a |
| Starter trial | none, $19 charged at checkout | createStripeSession |
| Starter price id | STRIPE_STARTER_PRICE_ID env, set by Sweets after creating the $19/mo price in the Stripe dashboard | Vercel env |
Not included: a separate email warning when existing tasks are blocked. The app's upgrade prompt (rows 1 and 4) is the surface that tells owners; adding a second channel here was left out to keep the gate small.
Tests
Red-first per unit. Domain suite: 485 tests pass across lib/plans lib/tasks lib/credits lib/stripe app/api/{subscriptions,tasks,accounts} after the 2026-08-30 review fixes. tsc --noEmit clean for touched files (repo baseline noise unchanged), eslint + prettier clean.
Preview verification follows in a comment.
🤖 Generated with Claude Code
https://claude.ai/code/session_01GkSubbDhRVoNanCEoKgL6K
Summary by cubic
Implements row 3 of app#2044: three-plan entitlements (free/starter/pro), a 402 plan_limit gate on the task API, and Starter plan checkout.
Plan entitlements and task gate
- Free is 1 weekly task, Starter is 3 daily, Pro is uncapped hourly; monthly credits follow the plan ($3.33/$20/$300).
POST /api/tasksandPATCH /api/tasksreturn 402plan_limitbefore writing when a create, re-enable, or schedule change exceeds the owner's plan; admins are not exempt.GET /api/tasks?id=answers 402 for a task the plan no longer allows, which makes the Trigger.dev runner skip the run; over the cap, the oldest tasks keep their slots.- Limits apply immediately to pre-existing tasks, so a downgrade loses extra tasks at once;
plan_limitresponses pointbillingUrlat/plan. - A Starter account with an active org Pro subscription resolves as Pro, and the org subscription drives credit refills.
- Internal plan state flows as
planeverywhere;is_pro/isProis derived only at API response edges.
Starter checkout
POST /api/subscriptions/sessionsaccepts optionalplan(defaultpro); Starter charges at checkout with no trial and stampsplanon session and subscription metadata.- Starter returns 400
starter_unavailableuntilSTRIPE_STARTER_PRICE_IDis set; until then, every paid price resolves as pro. - Starter keeps the free-tier gates on roster scrape, recipient emails, and API keys.
GET /api/accounts/{id}/creditsnow reportsplan,task_limit, andmin_cadence_minutes.- Set
STRIPE_STARTER_PRICE_IDin the environment to enable Starter checkout.
Summary by CodeRabbit
-
New Features
- Added Free, Starter, and Pro plan support with plan-based credits, task limits, and scheduling cadence rules.
- Added Starter plan checkout at $19/month, with plan selection during subscription setup.
- Added clear upgrade guidance when task limits or scheduling frequency restrictions are reached.
- Added plan details to account credit and subscription information.
-
Bug Fixes
- Correctly identifies Starter subscriptions instead of treating all paid subscriptions as Pro.
- Prevents task creation, updates, or runs that exceed the active plan’s allowances.