Files
openwork/ee/apps/den-web/components/admin/admin-shell.tsx
T
ben 94359f1439 feat(features): roll out features by deployment and organization, with a kill switch (#5702)
* feat(den): declare features once in a registry stored per organization

Adds packages/types/src/den/features.ts as the single place a feature is
declared. Each entry decides, separately for OpenWork Cloud and self-hosted,
whether the feature exists (unavailable / off / on) or is controlled per
organization by platform admins, with a default.

- Storage moves from organization.metadata.capabilities to a new
  organization_feature table (migration 0129 copies existing overrides and
  the old Connect aliases). Better Auth never writes it, so creating an
  organization can no longer turn features on; metadata.capabilities is
  stripped at creation and no longer sent to members. Writes are mirrored
  into metadata for one release so a rollback keeps working.
- den-api reads features only through features.ts (getOrganizationFeatures,
  organizationFeatureEnabled, requireFeature). The three hand-written
  capability helper modules are deleted.
- DEN_DEPLOYMENT (default self_hosted) and DEN_FEATURE_* locks, rendered
  from a generated Helm config.features block with a values schema. A lock
  outranks a stored override.
- /admin schemas and the Den admin panel are generated from the registry,
  with Default / override / locked states and "Use default".
- GET /v1/org adds features; capabilities stays frozen for published clients.
- pnpm features:sync / features:check plus a CI job keep the chart in step
  and reject new DEN_*_ENABLED switches or metadata.capabilities reads.
- add-a-feature skill and an AGENTS.md line: flag first, before feature code.

No behavior change: every existing feature keeps its current default and
stays platform-controlled on both deployments.

* refactor(features): move the registry into its own @openwork/features package

The registry and resolver were runtime logic living in @openwork/types.
They now live in packages/features:

- src/registry.ts: the one file you edit to declare a feature
- src/resolve.ts: precedence rules, env parsing, key schema (pure, no I/O)
- src/resolve.test.ts: node:test coverage of the precedence rules, env
  parsing, key schema and DEN_FEATURE_* names, run in features-check CI

Files import each other through package self-references, so the TypeScript
source runs as-is under Node (verified in the node:22 production image) and
typechecks in every consumer without a build step.

Also adds the package to the den, gateway and den-web Docker images and to
the den-contract CI path filters, and pins azure/setup-helm to a commit SHA
(Warden finding).

* ci(features): check that Dockerfiles copy every workspace package they need

The den, gateway, den-web and den-gateway images copy workspace packages one
by one for layer caching, and only publish-ee-images builds them, so a missed
COPY line surfaced at release time. scripts/check-docker-workspace-packages.mjs
reads the manifests and Dockerfiles (about 10 ms) and fails when a copied
package.json depends on a workspace package whose package.json is not copied
(pnpm install fails) or a copied source folder imports one at runtime that is
not copied. It runs inside pnpm features:check, and the workflow now also
triggers on Dockerfile, workspace and package.json changes.

* ci(features): name the exact setup-helm version in its pin comment

* feat(features): roll features out by deployment, percentage, organization and kill switch

A feature is no longer "per organization". Each registry entry declares only
what is fixed in code: its subject (organization, or person so signed-out
desktop users are included), the deployments it exists on, and its starting
percentage. Everything else is runtime state, resolved by one function in
@openwork/features, in this order: not part of this deployment, kill switch,
operator lock (DEN_FEATURE_*), organization override, percentage of the
subject (stable FNV-1a bucket; raising it only adds subjects).

- feature_rollout table (migration 0129 now creates it alongside
  organization_feature) holds percentage and kill switch per feature.
- /admin › Features page and GET/PUT /v1/admin/features change them without
  a deploy; organization rows show why a feature is on or off.
- Admin MCP tools den_list_features and den_set_feature_rollout.
- Public GET /v1/features/rollouts for clients that resolve person features
  themselves, including signed-out desktops.
- /v1/org resolves person features for the signed-in member.
- The nine existing features keep today's behaviour: organization subject,
  starting at 100% (install links, Connect) or 0% (the rest).
- Skill, AGENTS.md, Helm comments and README describe the one model;
  features:check asks for a decision on rollouts older than six months
  unless marked permanent.

* refactor(features): drop percentage rollouts; on or off for everyone, per organization, or killed

Removes percentage rollouts and the organization/person subject they needed.
A feature is now rolled out by deployment (fixed in code), on or off for
everyone (/admin, starting from the registry default), per-organization
overrides, operator locks, and the kill switch. feature_rollout stores
enabled and killed; GET /v1/features gives people without an organization
the deployment-wide answer.
2026-10-06 07:38:34 -07:00

47 lines
2.1 KiB
TypeScript

import Link from "next/link";
import type { ReactNode } from "react";
export type AdminSection = "overview" | "features" | "free-auto";
const SECTIONS: Array<{ id: AdminSection; label: string; href: string }> = [
{ id: "overview", label: "Overview", href: "/admin" },
{ id: "features", label: "Features", href: "/admin/features" },
{ id: "free-auto", label: "Free Auto usage", href: "/admin/free-auto" },
];
/**
* Frame for internal backoffice pages: product mark, section tabs and a way
* back to the cloud panel. New admin pages add a section here and render their
* content as children.
*/
export function AdminShell({ active, children }: { active: AdminSection; children: ReactNode }) {
return (
<div className="min-h-screen bg-slate-50">
<header className="border-b border-gray-200 bg-white">
<div className="mx-auto flex w-full max-w-6xl flex-wrap items-center justify-between gap-4 px-4 pt-5 sm:px-6 lg:px-8">
<div>
<p className="text-[0.7rem] font-semibold uppercase tracking-[0.18em] text-slate-500">OpenWork</p>
<p className="mt-1 text-sm text-slate-600">Internal Den backoffice</p>
</div>
<Link href="/" className="inline-flex items-center justify-center rounded-full border border-slate-200 bg-white px-4 py-2 text-sm font-semibold text-slate-700 hover:bg-slate-50">
Back to cloud panel
</Link>
<nav aria-label="Backoffice sections" className="-mb-px flex w-full gap-6">
{SECTIONS.map((section) => (
<Link
key={section.id}
href={section.href}
aria-current={section.id === active ? "page" : undefined}
className={`border-b-2 pb-3 text-sm font-medium transition-colors ${section.id === active ? "border-gray-900 text-gray-900" : "border-transparent text-gray-500 hover:text-gray-800"}`}
>
{section.label}
</Link>
))}
</nav>
</div>
</header>
<main className="mx-auto w-full max-w-6xl px-4 py-8 sm:px-6 lg:px-8">{children}</main>
</div>
);
}