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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user