# Continuity ledger (per-branch)

## Human intent (must not be overwritten)

<!--
Write 1–5 bullets capturing the human goal and motivation.
This section is intentionally stable: do not overwrite it when updating the ledger.
-->

- Replace Studio’s `apiPublishingFlag` gating with team plan gating (`internal` only) so API keys UI is not controlled by a deploy-time flag.

## Goal (incl. success criteria)

- All `apps/studio.giselles.ai` branches on `apiPublishingFlag` are replaced with `team.plan === "internal"`.
- `apiPublishingFlag` and `apiPublishing` feature-flag plumbing are removed (no dangling references; build/types remain clean).

## Constraints/Assumptions

- Non-internal plans should behave as before: hide the sidebar link and return `notFound()` (404).
- Keep changes minimal and obvious (no new abstractions beyond a small helper).

## Key decisions

- Introduced `isInternalPlan(team)` in `services/teams/utils.ts` and reused it across server components for clarity and consistency.

## State

- Before: access was controlled by Edge Config / env (`apiPublishingFlag`).
- After: access is controlled by persisted team plan in DB (`teams.plan`).

## Done

- Added `isInternalPlan(team)` helper.
- Updated `/settings/team/api-keys` and `/manage/api-keys` to gate by internal plan (404 otherwise).
- Updated sidebar to show the “API keys” link only for internal plan.
- Removed `apiPublishingFlag` from `apps/studio.giselles.ai/flags.ts`.
- Removed `apiPublishing` field from `packages/react` feature-flag context/provider wiring.
- Removed `apiPublishing` from Studio workspace loader `featureFlags`.
- Removed `stageFlag` (always enabled) and simplified all call sites to treat Stage as always enabled.

## Now

- Ready to commit.

## Next

- Optional: update `CONTINUITY.md` batched snapshot to reflect that `apiPublishingFlag` is removed and the gate is plan-based.

## Open questions (UNCONFIRMED if needed)

- None.

## Working set (files/ids/commands)

- `apps/studio.giselles.ai/services/teams/utils.ts`
- `apps/studio.giselles.ai/app/(main)/settings/team/api-keys/page.tsx`
- `apps/studio.giselles.ai/app/(main)/manage/api-keys/page.tsx`
- `apps/studio.giselles.ai/app/(main)/ui/sidebar/sidebar.tsx`
- `apps/studio.giselles.ai/app/workspaces/[workspaceId]/data-loader.ts`
- `apps/studio.giselles.ai/flags.ts`
- `packages/react/src/feature-flags/context.ts`
- `packages/react/src/workspace/provider.tsx`
- `apps/studio.giselles.ai/app/(main)/ui/sidebar/sidebar.tsx`
- `apps/studio.giselles.ai/app/(auth)/login/login.ts`
- `apps/studio.giselles.ai/app/(auth)/join/success/page.tsx`
- `apps/studio.giselles.ai/app/api/stage/acts/route.ts`

