refactor: remove the billing tier model (P0.1)

The community edition has no monetization (ADR-0001). Remove the tier
model (packages/shared/src/tiers.ts), the requireTier middleware and every
tier gate, GET/PATCH /api/tier and the trial start, and the Stripe
integration, which depends on the tier model.

Personal features a tier used to limit are open to everyone: unlimited
workspaces and connectors, every embedding provider including LiteLLM,
per-workspace costs, Approvals. The workspace session cap is one constant
(100). Team and enterprise surfaces are hidden instead of unlocked (team
dock zone, Settings Team/Enterprise/Plan tabs, workspace Team tab);
cloud sync reports unavailable, as it did for free users.

The sidecar ignores the tier keys in config.json but does not delete them:
both editions may still share ~/.waggle.

Web billing UI is deleted: plan cards, upgrade and trial modals, payment
success route, the KVARK sales block, tier 403 handling.
This commit is contained in:
shumeiko.it
2026-10-15 19:31:50 +02:00
parent 369d8269c1
commit fe2eb0f648
117 changed files with 342 additions and 6424 deletions

View File

@@ -12,8 +12,6 @@
* - Confirmed-success flip: an id enters `installed` only after the server
* confirms; it stays in `installing` (spinner) during the flight. A
* gate-rejected install therefore never appears in the count (PR4 §6).
* - The adapter's request() already dispatches waggle:tier-insufficient on a
* 403 TIER, so this store classifies tier but never re-fires the event.
*/
import {
createContext, useCallback, useContext, useEffect, useMemo, useRef, useState,
@@ -25,7 +23,7 @@ import { useToast } from '@/hooks/use-toast';
import { CONNECT_SETTLED_EVENT } from '@/hooks/useRevalidateOnError';
import type { MarketplacePackageRow } from '@/lib/extension-catalog';
import {
describeError, isTierError, isTogglable, rawId,
describeError, isTogglable, rawId,
type InstallCredentials, type InstallOutcome, type InstallTarget,
} from '@/lib/install-store';
@@ -188,9 +186,6 @@ export const InstallProvider = ({ children }: { children: ReactNode }) => {
toast({ title: 'Connected', description: `${target.name} is connected.` });
return { ok: true };
} catch (e) {
// A 403 tier rejection — the adapter already dispatched the upgrade
// event; classify as tier and don't toast over it.
if (isTierError(e)) return { ok: false, reason: 'tier' };
toast({ title: 'Connection failed', description: describeError(e), variant: 'destructive' });
return { ok: false, reason: 'error' };
} finally {
@@ -198,7 +193,7 @@ export const InstallProvider = ({ children }: { children: ReactNode }) => {
}
}
// CATALOG MCP — enable (PRO-gated; SecurityGate). Body envelope is load-bearing.
// CATALOG MCP — enable (SecurityGate). Body envelope is load-bearing.
if (target.kind === 'federated' && target.type === 'mcp') {
addInstalling(id);
try {
@@ -211,7 +206,6 @@ export const InstallProvider = ({ children }: { children: ReactNode }) => {
toast({ title: 'Enabled', description: `${target.name} is enabled.` });
return { ok: true };
}
if (result.error === 'TIER_INSUFFICIENT') return { ok: false, reason: 'tier' };
if (result.requiresApproval || result.blocked) {
toast({ title: 'Enable blocked', description: securityMessage(result), variant: 'destructive' });
return { ok: false, reason: 'security' };
@@ -226,7 +220,7 @@ export const InstallProvider = ({ children }: { children: ReactNode }) => {
}
}
// PACKAGE — marketplace install (PRO-gated; SecurityGate). RAW Response.
// PACKAGE — marketplace install (SecurityGate). RAW Response.
if (target.kind === 'package') {
if (target.packageId == null) return { ok: false, reason: 'unsupported' };
addInstalling(id);
@@ -240,9 +234,6 @@ export const InstallProvider = ({ children }: { children: ReactNode }) => {
const err = (await res.json().catch(() => ({}))) as {
error?: string; blocked?: boolean; severity?: string; message?: string;
};
// Only a real tier rejection is a tier outcome — the adapter already
// dispatched the upgrade event, so do not re-fire or toast it.
if (res.status === 403 && err.error === 'TIER_INSUFFICIENT') return { ok: false, reason: 'tier' };
if (err.blocked) {
toast({ title: 'Install blocked', description: securityMessage(err), variant: 'destructive' });
return { ok: false, reason: 'security' };

View File

@@ -35,7 +35,7 @@ export const ServiceProvider = ({ children }: { children: ReactNode }) => {
const mounted = useRef(true);
// P1b D3: every settlement (success or failure) is broadcast so errored
// Stage-B surfaces (tier, workspaces, briefing, …) revalidate without
// Stage-B surfaces (workspaces, briefing, …) revalidate without
// waiting for a focus event that never fires on an already-focused window.
// `force` bypasses the adapter's retained settled-success memo — without it
// a user-initiated reconnect after a sidecar death would silently no-op.

View File

@@ -8,7 +8,6 @@
* - useWorkspaces bundle (Desktop.tsx:119, flattened exactly as Desktop
* destructures it, incl. the `refresh` → `refreshWorkspaces` rename)
* - UI-complexity tier (Desktop.tsx:129)
* - billing tier + trial info + refreshTier (Desktop.tsx:141-158)
* - P4 default autonomy (Desktop.tsx:160-167 — consumed by the Stage-B
* ChatHost / useChatWidgetState, §4.2)
* - useNotifications / useOnboarding / useOfflineStatus / useAgentStatus
@@ -24,21 +23,9 @@
* Desktop.tsx itself is untouched at this stage; it keeps hosting its own
* copies until the Stage-C flip mounts AppShell.
*/
import { createContext, useCallback, useContext, useEffect, useRef, useState, type ReactNode } from 'react';
import { createContext, useContext, useEffect, useState, type ReactNode } from 'react';
import { adapter } from '@/lib/adapter';
import {
shouldAutoOpenTrialModal,
readOnboardingCompletionSnapshot,
readTrialModalLastAutoOpenedAt,
writeTrialModalLastAutoOpenedAt,
} from '@/lib/trial-expired-gate';
import {
shouldShowLoginBriefing,
readLoginBriefingDismissed,
readMinutesSinceLastDismiss,
readSkipBriefingParam,
} from '@/lib/login-briefing';
import type { BillingTier, UserTier } from '@/lib/dock-tiers';
import type { UserTier } from '@/lib/dock-tiers';
import type { ContextRailTarget } from '@/components/os/overlays/ContextRail';
import { useWorkspaces } from '@/hooks/useWorkspaces';
import { useAgentStatus } from '@/hooks/useAgentStatus';
@@ -46,7 +33,6 @@ import { useNotifications } from '@/hooks/useNotifications';
import { useOnboarding } from '@/hooks/useOnboarding';
import { useOfflineStatus } from '@/hooks/useOfflineStatus';
import { useOverlayState } from '@/hooks/useOverlayState';
import { useRevalidateOnError } from '@/hooks/useRevalidateOnError';
type WorkspacesBundle = ReturnType<typeof useWorkspaces>;
type AgentStatusBundle = ReturnType<typeof useAgentStatus>;
@@ -54,11 +40,6 @@ type NotificationsBundle = ReturnType<typeof useNotifications>;
type OnboardingBundle = ReturnType<typeof useOnboarding>;
type OverlayBundle = ReturnType<typeof useOverlayState>;
export interface TrialInfo {
trialDaysRemaining?: number;
trialExpired?: boolean;
}
export interface ShellContextValue {
// ── Workspaces (Desktop.tsx:119) ──
workspaces: WorkspacesBundle['workspaces'];
@@ -78,18 +59,8 @@ export interface ShellContextValue {
* shelf stood in a time heuristic for it (Wave U Lane A) and a slow cold
* fetch could still flash the empty state between skeleton and grid. */
workspacesLoading: WorkspacesBundle['loading'];
// ── Tier (Desktop.tsx:129, 141-158) ──
// ── UI-complexity tier (Desktop.tsx:129) ──
currentTier: UserTier;
billingTier: BillingTier;
/** P1b D3-4: false until a getTier() round-trip SUCCEEDS. While false,
* billingTier's 'FREE' default is a fail-closed capability gate (nav
* hiding) — it must never be rendered as the user's actual plan. */
tierResolved: boolean;
tierError: string | null;
trialInfo: TrialInfo;
refreshTier: () => Promise<void>;
showTrialExpired: boolean;
setShowTrialExpired: (open: boolean) => void;
// ── P4 default autonomy (Desktop.tsx:160-167) ──
defaultAutonomy: 'normal' | 'trusted' | 'yolo';
// ── Notifications (Desktop.tsx:123) ──
@@ -131,73 +102,6 @@ export const ShellProvider = ({ children }: { children: ReactNode }) => {
const offline = useOfflineStatus();
const currentTier: UserTier = onboardingState.tier || 'simple';
// Trial info from backend (relocated from Desktop.tsx:141-158)
const [trialInfo, setTrialInfo] = useState<TrialInfo>({});
const [billingTier, setBillingTier] = useState<BillingTier>('FREE');
const [tierResolved, setTierResolved] = useState(false);
const [tierError, setTierError] = useState<string | null>(null);
const [showTrialExpired, setShowTrialExpired] = useState(false);
// F1: auto-open the paywall at most once per page-load session. The gate
// (localStorage-backed 7d snooze + post-onboarding quiet window) plus this
// ref make refreshTier's mount/focus/online/connect-settled re-runs harmless.
const trialModalShownThisSessionRef = useRef(false);
// Extracted so post-action paths (start-trial, post-checkout-redirect)
// can re-pull tier/trial state without duplicating the fetch+parse logic.
// P1b D3-4: getTier now THROWS on HTTP failure (adapter chokepoint), so the
// catch is the single failure path — it must touch NEITHER billingTier NOR
// trialInfo (a failed refresh used to actively reset a paying user to FREE
// and wipe the trial countdown). tierResolved flips true on ANY successful
// round-trip, even an unrecognized tier string — resolution is about the
// server answering, not the value parsing.
const refreshTier = useCallback(async () => {
try {
const data = await adapter.getTier();
setTrialInfo({ trialDaysRemaining: data.trialDaysRemaining, trialExpired: data.trialExpired });
const t = String(data.tier ?? 'FREE').toUpperCase();
// Legacy PRO subscriptions collapse to Solo (FREE) — decision 8: 'PRO'
// must never reach the dock's BillingTier union.
if (t === 'PRO') {
setBillingTier('FREE');
} else if (t === 'FREE' || t === 'TRIAL' || t === 'TEAMS' || t === 'ENTERPRISE') {
setBillingTier(t);
}
setTierResolved(true);
setTierError(null);
// F1: gate the auto-open. Reads flow through localStorage/refs so this
// []-dep callback never closes over stale onboarding state. Stamp at OPEN
// time (not dismiss) so a reload while the modal is up can't re-fire it.
if (data.trialExpired) {
const ob = readOnboardingCompletionSnapshot();
// Same snapshot useOverlayState uses to decide the briefing's initial
// visibility, so the paywall never auto-opens under a showing briefing.
const briefingOpen = shouldShowLoginBriefing({
skipBriefing: readSkipBriefingParam(),
permanentlyDismissed: readLoginBriefingDismissed(),
minutesSinceLastDismiss: readMinutesSinceLastDismiss(),
});
if (shouldAutoOpenTrialModal({
trialExpired: true,
onboardingCompleted: ob.completed,
onboardingCompletedAt: ob.completedAt,
briefingOpen,
lastAutoOpenedAt: readTrialModalLastAutoOpenedAt(),
shownThisSession: trialModalShownThisSessionRef.current,
now: Date.now(),
})) {
trialModalShownThisSessionRef.current = true;
writeTrialModalLastAutoOpenedAt();
setShowTrialExpired(true);
}
}
} catch (e) {
setTierError(e instanceof Error ? e.message : 'Tier lookup failed');
}
}, []);
useEffect(() => { refreshTier(); }, [refreshTier]);
// D3 plus-clause: an errored tier revalidates on focus/visibility/online
// and on connect-settled (the only signal on an already-focused desktop).
useRevalidateOnError(tierError !== null, refreshTier);
// P4: default autonomy inherited by new chat widgets (relocated from
// Desktop.tsx:160-167). Fetched once on mount; SettingsApp writes via
// /api/settings/permissions, so a flipped setting takes effect on the next
@@ -217,7 +121,7 @@ export const ShellProvider = ({ children }: { children: ReactNode }) => {
<ShellContext.Provider value={{
workspaces, activeWorkspace, activeWorkspaceId,
selectWorkspace, createWorkspace, patchWorkspace, deleteWorkspace, refreshWorkspaces, workspacesError, workspacesLoading,
currentTier, billingTier, tierResolved, tierError, trialInfo, refreshTier, showTrialExpired, setShowTrialExpired,
currentTier,
defaultAutonomy,
notifications, unreadCount, markRead, markAllRead,
onboardingState, updateOnboarding, completeOnboarding,