diff --git a/.env b/.env index 6ba6fa22..1a5dbe8c 100644 --- a/.env +++ b/.env @@ -1,7 +1,11 @@ DATABASE_URL=file:./data/wwv.db +# Default plugins enabled on boot for demo edition +# Comma-separated list of plugin IDs +NEXT_PUBLIC_DEMO_DEFAULT_PLUGINS=iranwarlive,satellite,gps_jamming + # Edition: "local" | "cloud" | "demo" -NEXT_PUBLIC_WWV_EDITION=local +NEXT_PUBLIC_WWV_EDITION=demo # Auth Secret (REQUIRED for Docker — generate with: openssl rand -hex 32) # Must be stable across container restarts to preserve sessions. diff --git a/.env.example b/.env.example index 31cc3ac9..e0f888f7 100644 --- a/.env.example +++ b/.env.example @@ -48,6 +48,10 @@ ACLED_PASSWORD= # Generate any random string, then set the same value in the marketplace instance config. WWV_BRIDGE_TOKEN= +# Default plugins enabled on boot for demo edition +# Comma-separated list of plugin IDs +NEXT_PUBLIC_DEMO_DEFAULT_PLUGINS= + # Edition: "local" | "cloud" | "demo" NEXT_PUBLIC_WWV_EDITION=local diff --git a/docs/superpowers/plans/2026-04-16-demo-default-plugins.md b/docs/superpowers/plans/2026-04-16-demo-default-plugins.md new file mode 100644 index 00000000..6acda12d --- /dev/null +++ b/docs/superpowers/plans/2026-04-16-demo-default-plugins.md @@ -0,0 +1,124 @@ +# Demo Default Plugins Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Enable specific plugins by default on the demo edition via environment variables so the user is immediately impressed. + +**Architecture:** Update `layersSlice.ts` to accept an optional `defaultEnabled` parameter in `initLayer`. In `AppShell.tsx`, look up `NEXT_PUBLIC_DEMO_DEFAULT_PLUGINS` when the edition is `demo`, and pass the flag true to `initLayer` for matching plugins during registration. Document the variable in `.env.example`. + +**Tech Stack:** Next.js, Zustand, TypeScript. + +--- + +### Task 1: Update layer slice definition + +**Files:** +- Modify: `src/core/state/layersSlice.ts` + +- [ ] **Step 1: Write the implementation** + +Update `initLayer` in `src/core/state/layersSlice.ts` to accept a second parameter: + +```typescript +// Add defaultEnabled parameter to the interface +export interface LayersSlice { +// ... + initLayer: (pluginId: string, defaultEnabled?: boolean) => void; +} + +// ... + +// Use the parameter in the state updater + initLayer: (pluginId, defaultEnabled = false) => + set((state) => ({ + layers: { + ...state.layers, + [pluginId]: state.layers[pluginId] || { enabled: defaultEnabled, entityCount: 0, loading: false }, + }, + })), +``` + +- [ ] **Step 2: Commit** + +```bash +git add src/core/state/layersSlice.ts +npm run commit -- "feat: add defaultEnabled param to initLayer in layers slice" +``` + +### Task 2: Apply default configuration in AppShell + +**Files:** +- Modify: `src/components/layout/AppShell.tsx` + +- [ ] **Step 1: Write the implementation** + +Add `isDemo` import at the top of `src/components/layout/AppShell.tsx`: + +```typescript +import { isDemo } from "@/core/edition"; +``` + +In `AppShell.tsx`, around line 71, inside `startPlatform()`, fetch the value from the environment if the instance is demo: + +```typescript + // Fetch disabled built-in plugins before registration + let disabledIds = new Set(); + // ... (keep existing try/catch block) + + // Setup demo defaults + const demoDefaultPlugins = new Set(); + if (isDemo) { + const envVar = process.env.NEXT_PUBLIC_DEMO_DEFAULT_PLUGINS || ""; + envVar.split(",").forEach(s => { + const clean = s.trim(); + if (clean) demoDefaultPlugins.add(clean); + }); + } +``` + +Then update the `pluginManager` registration loop to inject the boolean for `initLayer`: + +```typescript + for (const plugin of pluginRegistry.getAll()) { + await pluginManager.registerPlugin(plugin); + initLayer(plugin.id, demoDefaultPlugins.has(plugin.id)); + } +``` + +- [ ] **Step 2: Run test to verify it passes** + +Run type checks to verify no compilation issues: +`npx tsc --noEmit` + +- [ ] **Step 3: Commit** + +```bash +git add src/components/layout/AppShell.tsx +npm run commit -- "feat: parse and apply default demo plugins via NEXT_PUBLIC_DEMO_DEFAULT_PLUGINS" +``` + +### Task 3: Document environment definitions + +**Files:** +- Modify: `.env.example` +- Modify: `.env` + +- [ ] **Step 1: Write the implementation** + +Update `.env.example` and `.env` around the `NEXT_PUBLIC_WWV_EDITION=local` definition: + +```dotenv +# Default plugins enabled on boot for demo edition +# Comma-separated list of plugin IDs (e.g. aviation,maritime,iranwarlive) +NEXT_PUBLIC_DEMO_DEFAULT_PLUGINS= + +# Edition: "local" | "cloud" | "demo" +NEXT_PUBLIC_WWV_EDITION=local +``` + +- [ ] **Step 2: Commit** + +```bash +git add .env.example .env +npm run commit -- "docs: add NEXT_PUBLIC_DEMO_DEFAULT_PLUGINS to env templates" +``` diff --git a/package.json b/package.json index 22b0a683..ce092d12 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "worldwideview", - "version": "1.8.3", + "version": "1.9.0", "private": true, "scripts": { "setup": "node scripts/setup.mjs", diff --git a/src/components/layout/AppShell.tsx b/src/components/layout/AppShell.tsx index 90849deb..2c01064c 100644 --- a/src/components/layout/AppShell.tsx +++ b/src/components/layout/AppShell.tsx @@ -45,6 +45,7 @@ import ReloadToast from "@/components/ui/ReloadToast"; import ErrorToast from "@/components/ui/ErrorToast"; import UnverifiedPluginBatchDialog from "@/components/marketplace/UnverifiedPluginBatchDialog"; import { FeedbackDialog } from "@/components/common/FeedbackDialog"; +import { isDemo } from "@/core/edition"; import { injectHostGlobals } from "@/core/plugins/hostGlobals"; import { initLogCatcher } from "@/lib/logCatcher"; @@ -80,6 +81,16 @@ export function AppShell() { // Non-critical — load all built-ins if endpoint fails } + // Setup demo defaults + const demoDefaultPlugins = new Set(); + if (isDemo) { + const envVar = process.env.NEXT_PUBLIC_DEMO_DEFAULT_PLUGINS || ""; + envVar.split(",").forEach(s => { + const clean = s.trim(); + if (clean) demoDefaultPlugins.add(clean); + }); + } + const builtIns = [ new AviationPlugin(), new MaritimePlugin(), @@ -113,7 +124,11 @@ export function AppShell() { for (const plugin of pluginRegistry.getAll()) { await pluginManager.registerPlugin(plugin); - initLayer(plugin.id); + const shouldEnable = demoDefaultPlugins.has(plugin.id); + initLayer(plugin.id, shouldEnable); + if (shouldEnable) { + await pluginManager.enablePlugin(plugin.id); + } } console.log("[AppShell] Platform Ready. Waiting for globe tiles..."); diff --git a/src/core/state/layersSlice.ts b/src/core/state/layersSlice.ts index e1d71baa..9f7f6851 100644 --- a/src/core/state/layersSlice.ts +++ b/src/core/state/layersSlice.ts @@ -14,7 +14,7 @@ export interface LayersSlice { setLayerEnabled: (pluginId: string, enabled: boolean) => void; setEntityCount: (pluginId: string, count: number) => void; setLayerLoading: (pluginId: string, loading: boolean) => void; - initLayer: (pluginId: string) => void; + initLayer: (pluginId: string, defaultEnabled?: boolean) => void; } export const createLayersSlice: StateCreator = (set) => ({ @@ -50,11 +50,11 @@ export const createLayersSlice: StateCreator = (s [pluginId]: { ...state.layers[pluginId], loading }, }, })), - initLayer: (pluginId) => + initLayer: (pluginId, defaultEnabled = false) => set((state) => ({ layers: { ...state.layers, - [pluginId]: state.layers[pluginId] || { enabled: false, entityCount: 0, loading: false }, + [pluginId]: state.layers[pluginId] || { enabled: defaultEnabled, entityCount: 0, loading: false }, }, })), });