Files
waggle-os/apps/web/src/providers/ShellContext.tsx
shumeiko.it fe2eb0f648 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.
2026-10-15 19:31:50 +02:00

136 lines
6.4 KiB
TypeScript

/**
* UX Refactor v2.1 P1a — ShellContext (conversion plan §5.1).
*
* Relocates Desktop.tsx's cross-cutting integrator state (Desktop.tsx:119-230)
* into a provider so AppShell (StatusBar + nav + overlays) and the route
* wrappers consume ONE instance of each hook. The SHAPE is Desktop's, moved —
* no new state is invented here:
* - useWorkspaces bundle (Desktop.tsx:119, flattened exactly as Desktop
* destructures it, incl. the `refresh` → `refreshWorkspaces` rename)
* - UI-complexity tier (Desktop.tsx:129)
* - P4 default autonomy (Desktop.tsx:160-167 — consumed by the Stage-B
* ChatHost / useChatWidgetState, §4.2)
* - useNotifications / useOnboarding / useOfflineStatus / useAgentStatus
* (Desktop.tsx:122-125)
* - useOverlayState bundle (Desktop.tsx:214 — overlays mount in AppShell,
* wrappers trigger them, e.g. HomeCockpit's onCreateWorkspace)
* - Context Rail target (Desktop.tsx:226 — rail mounts in AppShell,
* surfaces feed it via onContextRail)
*
* Surface-local hooks (useMemory / useKnowledgeGraph / useEvents) deliberately
* do NOT live here — they move into their route wrappers (§5.1 table).
*
* Desktop.tsx itself is untouched at this stage; it keeps hosting its own
* copies until the Stage-C flip mounts AppShell.
*/
import { createContext, useContext, useEffect, useState, type ReactNode } from 'react';
import { adapter } from '@/lib/adapter';
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';
import { useNotifications } from '@/hooks/useNotifications';
import { useOnboarding } from '@/hooks/useOnboarding';
import { useOfflineStatus } from '@/hooks/useOfflineStatus';
import { useOverlayState } from '@/hooks/useOverlayState';
type WorkspacesBundle = ReturnType<typeof useWorkspaces>;
type AgentStatusBundle = ReturnType<typeof useAgentStatus>;
type NotificationsBundle = ReturnType<typeof useNotifications>;
type OnboardingBundle = ReturnType<typeof useOnboarding>;
type OverlayBundle = ReturnType<typeof useOverlayState>;
export interface ShellContextValue {
// ── Workspaces (Desktop.tsx:119) ──
workspaces: WorkspacesBundle['workspaces'];
activeWorkspace: WorkspacesBundle['activeWorkspace'];
activeWorkspaceId: WorkspacesBundle['activeWorkspaceId'];
selectWorkspace: WorkspacesBundle['selectWorkspace'];
createWorkspace: WorkspacesBundle['createWorkspace'];
patchWorkspace: WorkspacesBundle['patchWorkspace'];
/** G3 (UX-Northstar 2026-06-13): existed in useWorkspaces but was never
* forwarded by the P1a provider extraction — workspace delete was
* unreachable from any UI. */
deleteWorkspace: WorkspacesBundle['deleteWorkspace'];
refreshWorkspaces: WorkspacesBundle['refresh'];
/** P1b D3: load-failure surface — an errored empty list must not render as "no workspaces". */
workspacesError: WorkspacesBundle['error'];
/** R15-V3 s03 fix: existed in useWorkspaces but was never forwarded, so the
* 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'];
// ── UI-complexity tier (Desktop.tsx:129) ──
currentTier: UserTier;
// ── P4 default autonomy (Desktop.tsx:160-167) ──
defaultAutonomy: 'normal' | 'trusted' | 'yolo';
// ── Notifications (Desktop.tsx:123) ──
notifications: NotificationsBundle['notifications'];
unreadCount: NotificationsBundle['unreadCount'];
markRead: NotificationsBundle['markRead'];
markAllRead: NotificationsBundle['markAllRead'];
// ── Onboarding (Desktop.tsx:124) ──
onboardingState: OnboardingBundle['state'];
updateOnboarding: OnboardingBundle['update'];
completeOnboarding: OnboardingBundle['complete'];
// ── Offline / agent status (Desktop.tsx:122, 125) ──
offline: boolean;
agentStatus: AgentStatusBundle;
// ── Overlay open/close state (Desktop.tsx:214) ──
overlays: OverlayBundle;
// ── Context Rail (Desktop.tsx:226) ──
contextRailTarget: ContextRailTarget | null;
setContextRailTarget: (target: ContextRailTarget | null) => void;
}
const ShellContext = createContext<ShellContextValue | null>(null);
export const useShell = () => {
const ctx = useContext(ShellContext);
if (!ctx) throw new Error('useShell must be used within ShellProvider');
return ctx;
};
export const ShellProvider = ({ children }: { children: ReactNode }) => {
const {
workspaces, activeWorkspace, activeWorkspaceId,
selectWorkspace, createWorkspace, patchWorkspace, deleteWorkspace, refresh: refreshWorkspaces,
error: workspacesError, loading: workspacesLoading,
} = useWorkspaces();
const agentStatus = useAgentStatus();
const { notifications, unreadCount, markRead, markAllRead } = useNotifications();
const { state: onboardingState, update: updateOnboarding, complete: completeOnboarding } = useOnboarding();
const offline = useOfflineStatus();
const currentTier: UserTier = onboardingState.tier || 'simple';
// 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
// fresh chat widget. Existing widgets keep their own state.
const [defaultAutonomy, setDefaultAutonomy] = useState<'normal' | 'trusted' | 'yolo'>('normal');
useEffect(() => {
adapter.getPermissions().then(p => setDefaultAutonomy(p.defaultAutonomy)).catch(() => {});
}, []);
// Overlay state (relocated from Desktop.tsx:214)
const overlays = useOverlayState();
// Phase C.1 Context Rail target (relocated from Desktop.tsx:226)
const [contextRailTarget, setContextRailTarget] = useState<ContextRailTarget | null>(null);
return (
<ShellContext.Provider value={{
workspaces, activeWorkspace, activeWorkspaceId,
selectWorkspace, createWorkspace, patchWorkspace, deleteWorkspace, refreshWorkspaces, workspacesError, workspacesLoading,
currentTier,
defaultAutonomy,
notifications, unreadCount, markRead, markAllRead,
onboardingState, updateOnboarding, completeOnboarding,
offline, agentStatus,
overlays,
contextRailTarget, setContextRailTarget,
}}>
{children}
</ShellContext.Provider>
);
};